Skip to content

feat: 支持多个前置任务,并丰富相关功能#173

Merged
MistEO merged 3 commits intomainfrom
feat/multi_pretask
Apr 13, 2026
Merged

feat: 支持多个前置任务,并丰富相关功能#173
MistEO merged 3 commits intomainfrom
feat/multi_pretask

Conversation

@MistEO
Copy link
Copy Markdown
Owner

@MistEO MistEO commented Apr 13, 2026

Summary by Sourcery

为每个实例支持多个可配置的预操作,并在连接前按顺序执行,同时改进管理和用户体验。

New Features:

  • 允许为每个实例添加多个预操作程序,并可分别配置启用状态、名称和执行设置。
  • 支持通过共享的可排序列表模式,对预操作和任务进行拖拽排序。
  • 为预操作添加上下文菜单和内联重命名编辑器,使其具备与任务项相同的功能,包括复制、移动和删除操作。

Enhancements:

  • 将任务和预操作的上下文菜单逻辑及内联重命名逻辑重构为共享工具,以提升一致性和复用性。
  • 改进预操作状态日志记录,为每个程序提供单独消息,并在跳过或完成程序时提供更清晰的反馈。
  • 自动将旧的单一预操作配置迁移到新的预操作数组格式,同时保持原有行为不变。
Original summary in English

Summary by Sourcery

Support multiple configurable pre-actions per instance and execute them in order before connecting, with improved management and UX.

New Features:

  • Allow adding multiple pre-action programs per instance with individual enablement, naming, and execution settings.
  • Enable drag-and-drop reordering of pre-actions and tasks using a shared sortable list pattern.
  • Add context menus and inline rename editor for pre-actions, mirroring task item capabilities, including duplicate, move, and delete actions.

Enhancements:

  • Refactor task and pre-action context menu and inline rename logic into shared utilities for consistency and reuse.
  • Improve pre-action status logging with per-program messages and better feedback when skipping or completing programs.
  • Automatically migrate legacy single pre-action configurations to the new pre-actions array format while preserving behavior.

Copilot AI review requested due to automatic review settings April 13, 2026 08:26
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨,我在这里给了一些总体反馈:

  • handlePreActionDragEndreorderPreActions 中,没有对 findIndex 返回 -1 的情况进行保护,因此如果出现异常的拖拽事件(DnD event),可能会在索引 -1 处执行 splice。建议在调用 reorderPreActions 或修改数组之前,当任一索引 < 0 时提前返回。
  • InlineNameEditor 中,你使用了 React.KeyboardEvent,但文件中没有导入 React 的类型;请添加 import type React from 'react';(或者更改事件类型),以避免在更严格的 TS 配置中出现类型错误。
  • updatePreAction/removePreAction/renamePreAction 这几个 store 方法依赖已有的 preActions 数组且没有兜底逻辑。为了更安全,你可能需要显式处理 undefined/空数组的情况(例如通过提前返回),以避免不必要的对象拷贝,或者在这些方法在尚未添加任何 action 之前被调用时出现 undefined.map 之类的问题。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- In `handlePreActionDragEnd` and `reorderPreActions`, there’s no guard for cases where `findIndex` returns `-1`, so a malformed DnD event could splice at `-1`; consider early-returning when either index is `< 0` before calling `reorderPreActions` or mutating the array.
- In `InlineNameEditor` you reference `React.KeyboardEvent` but the file doesn’t import React’s types; add `import type React from 'react';` (or change the event type) to avoid type errors in stricter TS configurations.
- The `updatePreAction`/`removePreAction`/`renamePreAction` store methods rely on existing `preActions` arrays without fallback, so for safety you may want to explicitly handle the `undefined`/empty case (e.g., by early-returning) to avoid unnecessary object copies or accidental `undefined.map` if these are ever called before any actions are added.

Sourcery 对开源项目是免费的——如果你喜欢我们的评审,请考虑帮我们分享一下 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • In handlePreActionDragEnd and reorderPreActions, there’s no guard for cases where findIndex returns -1, so a malformed DnD event could splice at -1; consider early-returning when either index is < 0 before calling reorderPreActions or mutating the array.
  • In InlineNameEditor you reference React.KeyboardEvent but the file doesn’t import React’s types; add import type React from 'react'; (or change the event type) to avoid type errors in stricter TS configurations.
  • The updatePreAction/removePreAction/renamePreAction store methods rely on existing preActions arrays without fallback, so for safety you may want to explicitly handle the undefined/empty case (e.g., by early-returning) to avoid unnecessary object copies or accidental undefined.map if these are ever called before any actions are added.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `handlePreActionDragEnd` and `reorderPreActions`, there’s no guard for cases where `findIndex` returns `-1`, so a malformed DnD event could splice at `-1`; consider early-returning when either index is `< 0` before calling `reorderPreActions` or mutating the array.
- In `InlineNameEditor` you reference `React.KeyboardEvent` but the file doesn’t import React’s types; add `import type React from 'react';` (or change the event type) to avoid type errors in stricter TS configurations.
- The `updatePreAction`/`removePreAction`/`renamePreAction` store methods rely on existing `preActions` arrays without fallback, so for safety you may want to explicitly handle the `undefined`/empty case (e.g., by early-returning) to avoid unnecessary object copies or accidental `undefined.map` if these are ever called before any actions are added.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 旨在将“前置程序/前置任务”从单个配置升级为支持多个条目,并补齐排序、复制、重命名等配套能力,同时对配置结构做向后兼容迁移。

Changes:

  • preAction 迁移为 preActions[](含 id/customName),并在 store 中提供增删改/排序/复制/重命名能力及兼容迁移逻辑
  • UI 支持前置程序列表展示与拖拽排序,运行前按顺序依次执行多个前置程序,并增强日志提示(带名称)
  • 抽取 Task/Action 共用的右键菜单与内联重命名组件,减少重复实现

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/types/interface.ts ActionConfig 增加 id/customNameInstance 改为 preActions[]
src/types/config.ts 增加 LegacyActionConfig,并为已保存配置提供 preActions + deprecated preAction 兼容字段
src/stores/types.ts 更新 store API:新增前置程序的增删改/排序/复制/重命名方法签名
src/stores/appStore.ts 实现 preAction -> preActions 迁移与新增的前置程序管理方法,并在加载/保存/复制/恢复流程接入
src/components/Toolbar.tsx 启动任务前按列表顺序执行多个前置程序,新增带名称的日志文案
src/components/TaskList.tsx 前置程序列表渲染与拖拽排序接入
src/components/TaskItem.tsx 复用抽取后的菜单/内联编辑组件以减少重复代码
src/components/listItemShared.tsx 新增共享:右键菜单构建器 + 内联重命名编辑器
src/components/AddTaskPanel.tsx 支持多次添加前置程序(每次生成新 id
src/components/ActionItem.tsx 前置程序条目 UI:支持拖拽、右键菜单、复制/重命名/删除确认等能力
src/i18n/locales/*.ts 增加前置程序命名执行提示与前置程序右键菜单相关文案

Comment on lines +349 to +356
const handlePreActionDragEnd = (event: DragEndEvent) => {
if (isInstanceRunning) return;
const { active, over } = event;
if (over && active.id !== over.id && instance?.preActions) {
const oldIndex = instance.preActions.findIndex((a) => a.id === active.id);
const newIndex = instance.preActions.findIndex((a) => a.id === over.id);
reorderPreActions(instance.id, oldIndex, newIndex);
}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findIndex can return -1 if the dragged id isn't found (e.g. list changed during drag, or stale DnD state). Calling reorderPreActions with -1 will reorder the wrong item (because splice(-1, 1) removes the last element). Add a guard to ensure both indices are >= 0 before reordering (and optionally no-op when oldIndex === newIndex).

Copilot uses AI. Check for mistakes.
Comment thread src/stores/appStore.ts
Comment on lines +1391 to +1392
const [removed] = items.splice(oldIndex, 1);
items.splice(newIndex, 0, removed);
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reorderPreActions assumes oldIndex/newIndex are valid. If either index is out of range (or -1), splice will remove/insert the wrong element and can even insert undefined into the list. Consider validating bounds (0 <= idx < length), clamping newIndex, and early-returning when indices are invalid or equal.

Suggested change
const [removed] = items.splice(oldIndex, 1);
items.splice(newIndex, 0, removed);
const itemCount = items.length;
if (
itemCount < 2 ||
oldIndex < 0 ||
oldIndex >= itemCount ||
oldIndex === newIndex
) {
return i;
}
const clampedNewIndex = Math.max(0, Math.min(newIndex, itemCount - 1));
const [removed] = items.splice(oldIndex, 1);
if (!removed) return i;
items.splice(clampedNewIndex, 0, removed);

Copilot uses AI. Check for mistakes.
Comment thread src/components/ActionItem.tsx Outdated
Comment on lines +379 to +380
title={t('taskItem.removeConfirmTitle')}
message={t('taskItem.removeConfirmMessage')}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delete confirmation dialog reuses taskItem.removeConfirmTitle/message, which currently reads as “Delete task”. When deleting a pre-action, this produces incorrect/misleading UI copy. Add dedicated i18n keys for pre-action deletion (or use a generic delete confirmation string) and reference those here.

Suggested change
title={t('taskItem.removeConfirmTitle')}
message={t('taskItem.removeConfirmMessage')}
title={t('actionItem.removeConfirmTitle', { defaultValue: 'Delete pre-action' })}
message={t('actionItem.removeConfirmMessage', {
defaultValue: 'Are you sure you want to delete this pre-action?',
})}

Copilot uses AI. Check for mistakes.
@MistEO MistEO merged commit b1cc78e into main Apr 13, 2026
15 checks passed
@MistEO MistEO deleted the feat/multi_pretask branch April 13, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants