Skip to content

feat: 适配 PI v2.7 协议#207

Open
MistEO wants to merge 1 commit into
mainfrom
feat/pretask
Open

feat: 适配 PI v2.7 协议#207
MistEO wants to merge 1 commit into
mainfrom
feat/pretask

Conversation

@MistEO
Copy link
Copy Markdown
Owner

@MistEO MistEO commented May 7, 2026

Summary by Sourcery

将客户端适配到 PI v2.7 的预任务(pretask)定义,通过把预任务配置接入接口模型、加载器以及 AddTaskPanel UI,包括参数和选项处理。

New Features:

  • 在 ProjectInterface 模式(schema)和接口加载器中新增对 PI v2.7 预任务配置的支持。
  • 在 AddTaskPanel 中暴露预任务,添加专门的预任务区域,以及基于预任务定义添加预操作的按钮。
  • 将所选选项值序列化为精简的 JSON 参数,并附加到预任务命令后,同时使用对 shell 安全的参数拼接方式。

Enhancements:

  • 引入用于规范化预任务配置以及安全地对参数进行 shell 引号包裹/拼接的实用工具。
  • 扩展 i18n 资源,在受支持语言中增加新的预任务区域标签。
Original summary in English

Summary by Sourcery

Adapt the client to PI v2.7 pretask definitions by wiring pretask configs into the interface model, loader, and AddTaskPanel UI, including argument and option handling.

New Features:

  • Add support for PI v2.7 pretask configurations in the ProjectInterface schema and interface loader.
  • Expose pretasks in the AddTaskPanel with a dedicated pretask section and buttons for adding pre-actions based on pretask definitions.
  • Serialize selected option values into a compact JSON argument appended to pretask commands, with shell-safe argument joining.

Enhancements:

  • Introduce utilities for normalizing pretask configs and safely shell-quoting/joining arguments.
  • Extend i18n resources with labels for the new pretask section across supported languages.

Copilot AI review requested due to automatic review settings May 7, 2026 16:57
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.

Hey - 我给出了一些高层次的反馈:

  • pretaskCounts 中,你对每个 pretask 都重复地对 preActions 进行过滤,而且只用 exec 作为键;建议在对 preActions 进行单次遍历时直接构建计数映射,并使用更具体的键(例如 name+exec),以避免 O(n²) 的开销以及当多个 pretasks 共享同一个 exec 时可能出现的键冲突。
  • 新的 PreTaskButton 在布局和行为上与 TaskButton 大量重复;可以考虑抽取一个共享的按钮组件,或者在现有组件上通过增加一些 props 来复用,从而减少重复并保持样式/用户体验的一致性。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- In `pretaskCounts`, you repeatedly filter `preActions` for each pretask and key by `exec` only; consider building the counts map in a single pass over `preActions` and using a more specific key (e.g., `name`+`exec`) to avoid O(n²) cost and accidental collisions when multiple pretasks share the same `exec`.
- The new `PreTaskButton` largely duplicates the layout and behaviors of `TaskButton`; extracting a shared button component or reusing the existing one with a few props would reduce duplication and keep styling/UX consistent.

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

Hey - I've left some high level feedback:

  • In pretaskCounts, you repeatedly filter preActions for each pretask and key by exec only; consider building the counts map in a single pass over preActions and using a more specific key (e.g., name+exec) to avoid O(n²) cost and accidental collisions when multiple pretasks share the same exec.
  • The new PreTaskButton largely duplicates the layout and behaviors of TaskButton; extracting a shared button component or reusing the existing one with a few props would reduce duplication and keep styling/UX consistent.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `pretaskCounts`, you repeatedly filter `preActions` for each pretask and key by `exec` only; consider building the counts map in a single pass over `preActions` and using a more specific key (e.g., `name`+`exec`) to avoid O(n²) cost and accidental collisions when multiple pretasks share the same `exec`.
- The new `PreTaskButton` largely duplicates the layout and behaviors of `TaskButton`; extracting a shared button component or reusing the existing one with a few props would reduce duplication and keep styling/UX consistent.

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 旨在适配 PI v2.7 协议中的 pretask(Controller 启动前预任务)能力:在类型层新增 pretask 定义与标准化工具,并在导入合并与「添加任务」面板中提供 pretask 的展示与一键加入 preActions 的入口。

Changes:

  • 在 PI 类型中新增 PreTaskConfig / pretask 字段,并提供 normalizePreTaskConfigs 标准化工具。
  • interfaceLoader 支持从 import 文件中导入并合并 pretask
  • AddTaskPanel 增加 “Pretasks/前置任务” 区块:展示、搜索、并将选择的 pretask 转换为 ActionConfig 加入实例 preActions
  • 各语言包补充 addTaskPanel.pretasks 文案。

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/types/interface.ts 增加 pretask/PreTaskConfig 类型与标准化函数,支撑 v2.7 协议字段落地
src/services/interfaceLoader.ts import 合并逻辑中追加 pretask 合并支持
src/components/AddTaskPanel.tsx UI 增加 pretask 展示与添加到 preActions 的行为实现
src/i18n/locales/zh-TW.ts 新增 addTaskPanel.pretasks 翻译
src/i18n/locales/zh-CN.ts 新增 addTaskPanel.pretasks 翻译
src/i18n/locales/ko-KR.ts 新增 addTaskPanel.pretasks 翻译
src/i18n/locales/ja-JP.ts 新增 addTaskPanel.pretasks 翻译
src/i18n/locales/en-US.ts 新增 addTaskPanel.pretasks 翻译

Comment on lines +214 to +216
for (const [key, value] of Object.entries(valuesMap)) {
const def = allOptions[key];
if (!def) continue;
Comment on lines +580 to +582
for (const p of allPretasks) {
counts[p.exec] = preActions.filter((a) => a.program === p.exec).length;
}
Comment on lines +740 to +746
const label =
resolveI18nText(pretask.label, langKey) || pretask.name || pretask.exec;
const key = pretask.name || pretask.exec;
return (
<PreTaskButton
key={key}
pretask={pretask}
Comment on lines +240 to +245
// v2.7.1: 合并 pretask(主文件已在 normalizePretask 处理;此处把导入文件的条目按数组顺序追加)
const importedPretasks = normalizePreTaskConfigs(imported.pretask);
if (importedPretasks.length > 0) {
const existing = normalizePreTaskConfigs(pi.pretask);
pi.pretask = [...existing, ...importedPretasks];
log.info(`合并了 ${importedPretasks.length} 个导入的 pretask`);
@zmdyy0318
Copy link
Copy Markdown

image option不显示

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.

3 participants