@wbline/pi-plan-build 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/lifecycle.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /**
2
- * 事件接线:session 恢复、tool_call 权限守卫、context 注入、agent_settled 验证问询。
2
+ * 事件接线:session 恢复、tool_call 权限守卫、context 注入、回合结算
3
+ * (agent_settled)与验证问询(input:awaiting_validation 后用户下一次
4
+ * 空闲发消息时确认一次)。
3
5
  * 每个 handler 都保持简短,逻辑下沉到 core 纯函数。
4
6
  */
5
7
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
@@ -11,7 +13,6 @@ import {
11
13
  LIFECYCLE_TOOLS,
12
14
  planTaskPendingInLastAssistant,
13
15
  realpathLike,
14
- SHELL_TOOLS,
15
16
  type ToolAnnotationsLike,
16
17
  } from "./core/guard.ts";
17
18
  import type { PlanEngine } from "./engine.ts";
@@ -70,23 +71,21 @@ export function wireLifecycle(pi: ExtensionAPI, engine: PlanEngine): void {
70
71
  };
71
72
  }
72
73
  if (kind !== "mutation") {
73
- // shell 通道不硬拦(诚实标注),但纳入事后对账:改动计划文件可被发现
74
+ // shell 与执行面通道不硬拦(诚实标注),但纳入事后对账:改动计划文件可被发现
74
75
  if (
75
76
  s.mode === "build" &&
76
77
  engine.config.protectPlanFile &&
77
78
  s.plan?.saved &&
78
- SHELL_TOOLS.has(event.toolName)
79
+ kind === "execution"
79
80
  )
80
81
  engine.armReconciliation(event.toolName);
81
82
  return;
82
83
  }
83
84
  if (s.mode === "build" && !engine.config.protectPlanFile) return; // 用户关闭保护
84
85
  const planPath = s.plan?.path ? realpathLike(s.plan.path) : null;
85
- const targets = extractMutationTargets(
86
- event.toolName,
87
- event.input,
88
- ctx.cwd,
89
- );
86
+ const raw = extractMutationTargets(event.toolName, event.input, ctx.cwd);
87
+ // targets 与计划路径同过 symlink 解析,避免链接路径被误判为非计划文件
88
+ const targets = raw?.map(realpathLike);
90
89
  const decision = decideFileMutation(
91
90
  event.toolName,
92
91
  s.mode,
@@ -104,7 +103,7 @@ export function wireLifecycle(pi: ExtensionAPI, engine: PlanEngine): void {
104
103
  ) {
105
104
  const okSwitch = await ctx.ui.confirm(
106
105
  "plan 模式只读拦截",
107
- `${decision.reason}\n是否切换到 build 模式并放行本次修改?`,
106
+ `${decision.summary}\n是否切换到 build 模式并放行本次修改?`,
108
107
  );
109
108
  if (okSwitch) {
110
109
  const sw = engine.tryApply({ t: "mode.set", mode: "build" }, ctx);
@@ -136,19 +135,28 @@ export function wireLifecycle(pi: ExtensionAPI, engine: PlanEngine): void {
136
135
  return { messages: injectContext(event.messages, block) };
137
136
  });
138
137
 
139
- // --- 验证问询:awaiting_validation 结算后问一次 ---
138
+ // --- 回合结算:确认门拒绝记忆重置 + 事后对账(验证问询在下方 input) ---
140
139
  pi.on("agent_settled", async (_event, ctx) => {
141
140
  engine.gateDeclined = false; // 新回合重置确认门的拒绝记忆
142
141
  // 事后对账先行:不可验证工具改动了计划文件要立即提示
143
142
  const reconciled = engine.settleReconciliation();
144
143
  if (reconciled) ctx.ui.notify(reconciled, "warning");
145
- const outcome = engine.state.plan?.outcome;
144
+ });
145
+
146
+ // --- 验证问询:awaiting_validation 后,用户下一次空闲发消息时确认一次 ---
147
+ pi.on("input", async (event, ctx) => {
148
+ // 只在用户空闲提交(非流式插话)时询问;斜杠命令与扩展触发不问
149
+ if (event.streamingBehavior !== undefined || event.source === "extension")
150
+ return;
151
+ if (event.text.trim().startsWith("/")) return;
152
+ const plan = engine.state.plan;
153
+ const outcome = plan?.outcome;
146
154
  if (outcome?.kind !== "awaiting_validation" || engine.validationAsked)
147
155
  return;
148
- if (!ctx.hasUI || !ctx.isIdle()) return;
149
- engine.validationAsked = true;
156
+ if (!ctx.hasUI) return;
157
+ engine.validationAsked = true; // 只问一次;重新结算(plan_set_outcome/plan_complete)会重置
150
158
  const passed = await ctx.ui.confirm(
151
- "必需验证是否通过?",
159
+ "上一轮计划的必需验证通过了吗?",
152
160
  outcome.userAction,
153
161
  );
154
162
  if (passed && engine.state.plan?.outcome?.kind === "awaiting_validation") {
@@ -158,7 +166,7 @@ export function wireLifecycle(pi: ExtensionAPI, engine: PlanEngine): void {
158
166
  "error" in r ? "error" : "info",
159
167
  );
160
168
  }
161
- // 未通过/取消:什么都不做,计划保持开放;用户会在对话里说明失败详情。
169
+ // 未通过/取消:计划保持开放,等用户在对话里说明;不再自动重问。
162
170
  });
163
171
 
164
172
  // --- 卸载清理(widget/status 由 reload 重建)---
@@ -0,0 +1,118 @@
1
+ /**
2
+ * 工具描述与参数描述集中层:zh/en 双语,注册时按 config.lang 选用。
3
+ * 压缩原则:工作流规则交给 context 注入(prompts.ts),这里只保留工具自身的
4
+ * 动作语义与硬约束(模式边界 / expectedAttached / 绝不事项)。
5
+ */
6
+ import type { Lang } from "../core/prompts.ts";
7
+
8
+ export interface ToolTexts {
9
+ planTask: string;
10
+ taskTitle: string;
11
+ taskScope: string;
12
+ taskExpected: string;
13
+ taskFromFile: string;
14
+ taskPlanningRequested: string;
15
+ planExit: string;
16
+ stepControl: string;
17
+ stepAckSummary: string;
18
+ stepAdvance: string;
19
+ stepReviseStep: string;
20
+ stepReviseText: string;
21
+ stepComplete: string;
22
+ stepSummary: string;
23
+ planComplete: string;
24
+ completeSummary: string;
25
+ planOutcome: string;
26
+ outcomeUserAction: string;
27
+ outcomeReason: string;
28
+ question: string;
29
+ questionPrompt: string;
30
+ questionHeader: string;
31
+ questionLabel: string;
32
+ questionDescription: string;
33
+ }
34
+
35
+ const ZH: ToolTexts = {
36
+ planTask:
37
+ "任务生命周期。new:建计划,仅 plan 模式(build 下调用先弹窗确认切 plan;用户未明确要求规划时先弹窗选「创建计划 / 直接执行」,选直接执行即切 build 不建计划;fromFile 恢复既有计划文件接着干)。revise:请求切回 plan 模式修订当前计划(弹窗确认)。update 改名;include 追加用户批准的范围(传完整合并后的 scope);exclude 记录排除话题;abandon 显式放弃(须用户指示);list/show 查看状态与历史计划(含归档结局)。除 list/show 外必须带 expectedAttached 做乐观并发(new 传 null,其余传当前 seq);生命周期转移必须先于依赖它的写入/命令单独完成。",
38
+ taskTitle:
39
+ "new 的标题(动作+对象式,不含冒号);update 的新标题;abandon 的原因",
40
+ taskScope: "new 的详细范围;include 的完整合并后范围;exclude 的排除话题",
41
+ taskExpected: "乐观并发:当前计划 seq;new 传 null,其余动作传当前 seq",
42
+ taskFromFile:
43
+ "new 专用:恢复既有计划文件(绝对或 cwd 相对路径),以其一级标题为默认标题;文件已在 plans 目录内则原地接管,否则复制并在原文件标记「已接管」",
44
+ taskPlanningRequested:
45
+ '仅当用户明确要求规划(如"帮我规划""出个方案")时传 true,跳过「创建计划 / 直接执行」入口询问',
46
+ planExit:
47
+ "plan 模式终点:完整计划写盘且讨论收敛后调用。展示计划并请求实现授权(本会话连续 / 分步 / 留在 plan);无交互 UI 时跳过审批门自动选本会话连续实现。文件未写盘或讨论未收敛时不要调用。",
48
+ stepControl:
49
+ '分步执行控制,一次一个转移:start 批准就绪步(advance: "all" 一次授权连跑剩余步骤,遇阻塞才停);acknowledge 指认用户声明的已完成步(无需先 start);skip 跳过;revise 修订未完成步文本(同步计划文件);pause/resume 暂停恢复;cancel 取消分步(计划保留)。',
50
+ stepAckSummary: "acknowledge 的完成摘要",
51
+ stepAdvance:
52
+ 'start 专用:默认只开始当前步;用户明确要求连续执行(如"剩下的都做完""全部继续")时传 "all",一次授权连跑剩余步骤,遇到 plan_set_outcome 记录的阻塞才停。',
53
+ stepReviseStep: "revise 的步骤号(默认当前就绪步)",
54
+ stepReviseText: "revise 的新步骤文本",
55
+ stepComplete:
56
+ "完成当前进行中的分步(仅在本步实现与适用检查完成后调用)。完成立即生效、不等待验收,绝不开始下一步。",
57
+ stepSummary: "本步实现与验证的简明摘要",
58
+ planComplete:
59
+ "标记整个计划完成:仅在全部批准工作与必需检查通过、或用户明确指示时调用(分步执行进行中也允许,会如实收尾)。绝不虚构未执行的检查。",
60
+ completeSummary: "事实性完成摘要(可选),随历史记录保留",
61
+ planOutcome:
62
+ "记录未完成结局并保持计划开放:awaiting_validation(userAction 必填:用户要执行的精确验证步骤)、blocked / waiting_for_input / still_working(reason 必填)。绝不因空闲推断成功。",
63
+ outcomeUserAction:
64
+ "awaiting_validation 必填:用户要执行的精确验证步骤(多项检查每项一个简短要点)",
65
+ outcomeReason: "blocked/waiting_for_input/still_working 必填:原因",
66
+ question:
67
+ "向用户提出结构化选择题,收集决策/澄清歧义;推荐选项放第一个并在 label 尾部加「(推荐)」。无交互 UI 时自动降级为文本提问。",
68
+ questionPrompt: "问题",
69
+ questionHeader: "短标题(≤12 字符)",
70
+ questionLabel: "选项显示文本",
71
+ questionDescription: "选项说明",
72
+ };
73
+
74
+ const EN: ToolTexts = {
75
+ planTask:
76
+ 'Plan task lifecycle. new: create a plan, plan mode only (in build mode a dialog first asks to switch; when the user has not explicitly asked for planning, it first offers "create plan / execute directly" — direct switches to build without creating a plan; fromFile resumes an existing plan file). revise: ask to switch back to plan mode to revise the current plan (confirm dialog). update renames; include appends user-approved scope (pass the full merged scope); exclude records excluded topics; abandon gives up (explicit user instruction required); list/show show status and history (with archived outcomes). Except list/show, every action requires expectedAttached for optimistic concurrency (null for new, current seq otherwise); lifecycle transitions finish before dependent writes or commands.',
77
+ taskTitle:
78
+ "title for new (action-led, no colons); new title for update; reason for abandon",
79
+ taskScope:
80
+ "detailed scope for new; full merged scope for include; excluded topic for exclude",
81
+ taskExpected:
82
+ "optimistic concurrency: current plan seq; null for new, current seq for other actions",
83
+ taskFromFile:
84
+ "new only: existing plan file (absolute or cwd-relative) to resume; title defaults to its first heading; adopted in place when already inside the plans directory, otherwise copied and the source marked superseded",
85
+ taskPlanningRequested:
86
+ 'true only when the user explicitly asked to plan (e.g. "plan this for me"); skips the create/execute question',
87
+ planExit:
88
+ "plan-mode endpoint: call once the full plan is saved and the discussion has converged. Presents the plan and asks for implementation authorization (this session / step-by-step / stay in plan); without interactive UI the gate is skipped and this-session implementation is auto-approved. Never call with an unsaved file or an unsettled discussion.",
89
+ stepControl:
90
+ 'Step execution control, one transition at a time: start approves the ready step (advance: "all" authorizes auto-run of the remaining steps, stopping only on blockers); acknowledge records a step the user declared done (no start needed); skip; revise rewrites an unfinished step (syncs the plan file); pause/resume; cancel (plan retained).',
91
+ stepAckSummary: "completion summary for acknowledge",
92
+ stepAdvance:
93
+ 'start only: defaults to starting just the current step; pass "all" only when the user explicitly asked for continuous execution (e.g. "do the rest"), authorizing the remaining steps in one go; stops only on blockers recorded via plan_set_outcome.',
94
+ stepReviseStep: "step number for revise (defaults to the current ready step)",
95
+ stepReviseText: "new step text for revise",
96
+ stepComplete:
97
+ "Complete the in-progress step (only after implementing it and running its applicable checks). Takes effect immediately without waiting for acceptance; never starts the next step.",
98
+ stepSummary: "concise summary of this step's implementation and verification",
99
+ planComplete:
100
+ "Mark the whole plan complete: only after all approved work and required checks pass, or on explicit user instruction (also allowed during step execution; closes out truthfully). Never invent unperformed checks.",
101
+ completeSummary: "factual completion summary (optional), kept in history",
102
+ planOutcome:
103
+ "Record an unfinished outcome and keep the plan open: awaiting_validation (userAction required: the exact validation the user must run), blocked / waiting_for_input / still_working (reason required). Never infer success from idleness.",
104
+ outcomeUserAction:
105
+ "required for awaiting_validation: the exact validation steps the user must run (one short bullet per check)",
106
+ outcomeReason:
107
+ "required for blocked/waiting_for_input/still_working: the reason",
108
+ question:
109
+ 'Ask the user structured multiple-choice questions to settle decisions or clarify ambiguity; put the recommended option first and append "(recommended)" to its label. Falls back to a text question without interactive UI.',
110
+ questionPrompt: "The question",
111
+ questionHeader: "Short header (≤12 chars)",
112
+ questionLabel: "Option display text",
113
+ questionDescription: "Option description",
114
+ };
115
+
116
+ export function toolTexts(lang: Lang): ToolTexts {
117
+ return lang === "en" ? EN : ZH;
118
+ }
@@ -12,5 +12,5 @@ export function registerAllTools(pi: ExtensionAPI, engine: PlanEngine): void {
12
12
  registerPlanExit(pi, engine);
13
13
  registerPlanStepTools(pi, engine);
14
14
  registerPlanOutcome(pi, engine);
15
- registerQuestion(pi);
15
+ registerQuestion(pi, engine.config.lang);
16
16
  }
@@ -7,6 +7,7 @@ import type {
7
7
  import { Type } from "typebox";
8
8
  import { parseSteps } from "../core/steps.ts";
9
9
  import type { PlanEngine } from "../engine.ts";
10
+ import { toolTexts } from "./descriptions.ts";
10
11
 
11
12
  const Params = Type.Object({});
12
13
 
@@ -18,8 +19,7 @@ export function registerPlanExit(pi: ExtensionAPI, engine: PlanEngine): void {
18
19
  pi.registerTool({
19
20
  name: "plan_exit",
20
21
  label: "plan exit",
21
- description:
22
- "plan 模式专用:完整计划写盘且讨论收敛后调用。展示计划并请求实现授权(本会话/分步/留下)。接受范围不等于开始实现之外的授权;不要在文件未保存或讨论未完成时调用。",
22
+ description: toolTexts(engine.config.lang).planExit,
23
23
  parameters: Params,
24
24
  async execute(_id, _params, _signal, _onUpdate, ctx: ExtensionToolContext) {
25
25
  const s = engine.state;
@@ -30,7 +30,7 @@ export function registerPlanExit(pi: ExtensionAPI, engine: PlanEngine): void {
30
30
  if (!plan) return fail("没有当前计划。先 plan_task new。");
31
31
  if (!fs.existsSync(plan.path)) {
32
32
  return fail(
33
- `计划文件尚未写盘:${plan.path}。请先把完整计划写入该文件(用 write 工具),成功后调用 plan_exit。`,
33
+ `计划文件尚未写盘:${plan.path}。请先用文件写入工具把完整计划写入该文件,成功后调用 plan_exit。`,
34
34
  );
35
35
  }
36
36
  const markdown = fs.readFileSync(plan.path, "utf8");
@@ -46,17 +46,31 @@ export function registerPlanExit(pi: ExtensionAPI, engine: PlanEngine): void {
46
46
  // 审阅渲染:把计划全文作为工具结果回显,模型轮结束后用户在对话里看到(无自定义 entry,减少 UI 接管)。
47
47
  const review = `# 计划审阅:${plan.title}\n\n${markdown}`;
48
48
 
49
+ // 无交互 UI(print/json):与 plan_task new 入口询问一致跳过审批门,
50
+ // 自动批准本会话连续实现(留 plan 会让无 UI 场景永远拿不到实现授权)。
51
+ const headless = !ctx.hasUI;
52
+ const headlessNote =
53
+ "(无交互 UI:审批门已跳过,自动选择本会话连续实现)\n";
49
54
  let choice: string | undefined;
50
- if (ctx.hasUI) {
55
+ if (headless) {
56
+ choice = HERE;
57
+ } else {
51
58
  choice = await ctx.ui.select(`请选择计划的实现方式:${plan.title}`, [
52
59
  HERE,
53
60
  STEPWISE,
54
61
  STAY,
55
62
  ]);
63
+ if (choice === undefined) {
64
+ // 用户关闭/取消审批 ≠ 主动选择「留在 plan」:交回用户,让模型询问意图
65
+ return ok(
66
+ `${review}\n\n---\n审批对话框被取消:未作任何选择,仍处于 plan 模式。请询问用户想如何继续,不要自行开始实现。`,
67
+ );
68
+ }
56
69
  }
57
- if (!choice || choice === STAY) {
70
+
71
+ if (choice === STAY) {
58
72
  return ok(
59
- `${review}\n\n---\n已留在 plan 模式。等待用户进一步指示;不要开始实现。`,
73
+ `${review}\n\n---\n用户选择留在 plan 模式。等待用户进一步指示;不要开始实现。`,
60
74
  );
61
75
  }
62
76
 
@@ -71,14 +85,14 @@ export function registerPlanExit(pi: ExtensionAPI, engine: PlanEngine): void {
71
85
  const r = engine.apply({ t: "exec.start", steps: parsed.steps }, ctx);
72
86
  const n = r.state.execution?.steps.length ?? parsed.steps.length;
73
87
  return ok(
74
- `${review}\n\n---\n用户批准分步实现(共 ${n} 步),已切换到 build 模式。第 1 步就绪但未开始:向用户简述第 1 步并等待其明确批准(如"继续"),批准后调用 plan_step_control start。`,
88
+ `${review}\n\n---\n${headless ? headlessNote : ""}用户批准分步实现(共 ${n} 步),已切换到 build 模式。第 1 步就绪但未开始:向用户简述第 1 步并等待其明确批准(如"继续"),批准后调用 plan_step_control start。`,
75
89
  );
76
90
  }
77
91
 
78
- // 本会话连续实现
92
+ // 本会话连续实现(含无 UI 自动批准)
79
93
  engine.apply({ t: "mode.set", mode: "build" }, ctx);
80
94
  return ok(
81
- `${review}\n\n---\n用户批准在本会话实现,已切换到 build 模式。请在批准的范围内实现全部工作,按计划 ## 验证 小节执行必需检查,完成后调用 plan_complete(或 plan_set_outcome 记录未竟事项)。`,
95
+ `${review}\n\n---\n${headless ? headlessNote : ""}用户批准在本会话实现,已切换到 build 模式。请在批准的范围内实现全部工作,按计划 ## 验证 小节执行必需检查,完成后调用 plan_complete(或 plan_set_outcome 记录未竟事项)。`,
82
96
  );
83
97
  },
84
98
  });
@@ -8,41 +8,34 @@ import type {
8
8
  import { Type } from "typebox";
9
9
  import type { PlanOutcome } from "../core/state.ts";
10
10
  import type { PlanEngine } from "../engine.ts";
11
-
12
- const CompleteParams = Type.Object({
13
- summary: Type.Optional(
14
- Type.String({ description: "事实性完成摘要(可选),随历史记录保留" }),
15
- ),
16
- });
17
-
18
- const FinishParams = Type.Object({
19
- outcome: StringEnum([
20
- "awaiting_validation",
21
- "blocked",
22
- "waiting_for_input",
23
- "still_working",
24
- ]),
25
- userAction: Type.Optional(
26
- Type.String({
27
- description: "awaiting_validation 必填:用户要执行的精确验证步骤",
28
- }),
29
- ),
30
- reason: Type.Optional(
31
- Type.String({
32
- description: "blocked/waiting_for_input/still_working 必填:原因",
33
- }),
34
- ),
35
- });
11
+ import { toolTexts } from "./descriptions.ts";
36
12
 
37
13
  export function registerPlanOutcome(
38
14
  pi: ExtensionAPI,
39
15
  engine: PlanEngine,
40
16
  ): void {
17
+ const T = toolTexts(engine.config.lang);
18
+ const CompleteParams = Type.Object({
19
+ summary: Type.Optional(Type.String({ description: T.completeSummary })),
20
+ });
21
+
22
+ const FinishParams = Type.Object({
23
+ outcome: StringEnum([
24
+ "awaiting_validation",
25
+ "blocked",
26
+ "waiting_for_input",
27
+ "still_working",
28
+ ]),
29
+ userAction: Type.Optional(
30
+ Type.String({ description: T.outcomeUserAction }),
31
+ ),
32
+ reason: Type.Optional(Type.String({ description: T.outcomeReason })),
33
+ });
34
+
41
35
  pi.registerTool({
42
36
  name: "plan_complete",
43
37
  label: "plan complete",
44
- description:
45
- "标记整个计划完成:仅在全部批准工作与必需检查通过后,或用户明确指示整计划完成时调用(分步执行进行中也允许,会如实收尾)。绝不虚构未执行的检查。",
38
+ description: T.planComplete,
46
39
  parameters: CompleteParams,
47
40
  async execute(_id, params, _signal, _onUpdate, ctx: ExtensionToolContext) {
48
41
  if (!engine.state.plan) return fail("当前没有计划。");
@@ -63,8 +56,7 @@ export function registerPlanOutcome(
63
56
  pi.registerTool({
64
57
  name: "plan_set_outcome",
65
58
  label: "plan set outcome",
66
- description:
67
- "记录未完成结局并保持计划开放:awaiting_validation(必需的用户验证,userAction 必填)、blocked / waiting_for_input / still_working(reason 必填)。绝不因空闲推断成功。",
59
+ description: T.planOutcome,
68
60
  parameters: FinishParams,
69
61
  async execute(_id, params, _signal, _onUpdate, ctx: ExtensionToolContext) {
70
62
  if (!engine.state.plan) return fail("当前没有计划。");
@@ -5,29 +5,33 @@ import type {
5
5
  ExtensionToolContext,
6
6
  } from "@earendil-works/pi-coding-agent";
7
7
  import { Type } from "typebox";
8
+ import type { Lang } from "../core/prompts.ts";
9
+ import { toolTexts } from "./descriptions.ts";
8
10
 
9
- const QuestionT = Type.Object({
10
- question: Type.String({ description: "问题" }),
11
- header: Type.String({ description: "短标题(≤12 字符)" }),
12
- options: Type.Array(
13
- Type.Object({
14
- label: Type.String({ description: "选项显示文本" }),
15
- description: Type.Optional(Type.String({ description: "选项说明" })),
16
- }),
17
- { minItems: 2, maxItems: 4 },
18
- ),
19
- });
11
+ export function registerQuestion(pi: ExtensionAPI, lang: Lang): void {
12
+ const T = toolTexts(lang);
13
+ const QuestionT = Type.Object({
14
+ question: Type.String({ description: T.questionPrompt }),
15
+ header: Type.String({ description: T.questionHeader }),
16
+ options: Type.Array(
17
+ Type.Object({
18
+ label: Type.String({ description: T.questionLabel }),
19
+ description: Type.Optional(
20
+ Type.String({ description: T.questionDescription }),
21
+ ),
22
+ }),
23
+ { minItems: 2, maxItems: 4 },
24
+ ),
25
+ });
20
26
 
21
- const Params = Type.Object({
22
- questions: Type.Array(QuestionT, { minItems: 1, maxItems: 4 }),
23
- });
27
+ const Params = Type.Object({
28
+ questions: Type.Array(QuestionT, { minItems: 1, maxItems: 4 }),
29
+ });
24
30
 
25
- export function registerQuestion(pi: ExtensionAPI): void {
26
31
  pi.registerTool({
27
32
  name: "plan_question",
28
33
  label: "plan question",
29
- description:
30
- "向用户提出结构化选择题,收集决策/澄清歧义。推荐选项放第一个并在 label 尾部加“(推荐)”。",
34
+ description: T.question,
31
35
  parameters: Params,
32
36
  async execute(_id, params, _signal, _onUpdate, ctx: ExtensionToolContext) {
33
37
  if (!ctx.hasUI) {
@@ -8,56 +8,43 @@ import type {
8
8
  import { Type } from "typebox";
9
9
  import { reviseStepInMarkdown } from "../core/steps.ts";
10
10
  import type { PlanEngine } from "../engine.ts";
11
-
12
- const ControlParams = Type.Object({
13
- action: StringEnum([
14
- "start",
15
- "acknowledge",
16
- "skip",
17
- "revise",
18
- "pause",
19
- "resume",
20
- "cancel",
21
- ]),
22
- /** acknowledge: 步骤摘要;revise: 新文本;cancel 不需要参数。 */
23
- summary: Type.Optional(
24
- Type.String({ description: "acknowledge 的完成摘要" }),
25
- ),
26
- /** start 专用:默认只开始当前步;用户明确要求连续执行时传 "all" 一次授权连跑。 */
27
- advance: Type.Optional(
28
- Type.Union([Type.Literal("one"), Type.Literal("all")], {
29
- description:
30
- 'start 专用:默认只开始当前步;用户明确要求连续执行(如"剩下的都做完""全部继续")时传 "all",一次授权连跑剩余步骤,遇到 plan_set_outcome 记录的阻塞才停。',
31
- }),
32
- ),
33
- step: Type.Optional(
34
- Type.Integer({
35
- minimum: 1,
36
- description: "revise 的步骤号(默认当前就绪步)",
37
- }),
38
- ),
39
- text: Type.Optional(Type.String({ description: "revise 的新步骤文本" })),
40
- });
41
-
42
- const CompleteParams = Type.Object({
43
- summary: Type.String({ description: "本步实现与验证的简明摘要" }),
44
- });
11
+ import { toolTexts } from "./descriptions.ts";
45
12
 
46
13
  export function registerPlanStepTools(
47
14
  pi: ExtensionAPI,
48
15
  engine: PlanEngine,
49
16
  ): void {
50
- /** 终态归档透出:仅当本次转移收尾了计划(lastArchive 每次 apply 重置)。 */
51
- const archiveSuffix = () =>
52
- engine.lastArchive?.ok
53
- ? `\n状态块已写入计划文件:${engine.lastArchive.path}`
54
- : "";
17
+ const T = toolTexts(engine.config.lang);
18
+ const ControlParams = Type.Object({
19
+ action: StringEnum([
20
+ "start",
21
+ "acknowledge",
22
+ "skip",
23
+ "revise",
24
+ "pause",
25
+ "resume",
26
+ "cancel",
27
+ ]),
28
+ summary: Type.Optional(Type.String({ description: T.stepAckSummary })),
29
+ advance: Type.Optional(
30
+ Type.Union([Type.Literal("one"), Type.Literal("all")], {
31
+ description: T.stepAdvance,
32
+ }),
33
+ ),
34
+ step: Type.Optional(
35
+ Type.Integer({ description: T.stepReviseStep, minimum: 1 }),
36
+ ),
37
+ text: Type.Optional(Type.String({ description: T.stepReviseText })),
38
+ });
39
+
40
+ const CompleteParams = Type.Object({
41
+ summary: Type.String({ description: T.stepSummary }),
42
+ });
55
43
 
56
44
  pi.registerTool({
57
45
  name: "plan_step_control",
58
46
  label: "plan step control",
59
- description:
60
- '分步执行控制:start 批准并开始就绪步(用户明确要求连续执行时可传 advance: "all" 一次授权连跑剩余步骤);acknowledge 指认用户声明的已完成步(当前步无需先 start;记录既有事实,不授权新工作,AI 自己完成当前步用 plan_step_complete);skip 跳过;revise 修订未完成步文本;pause/resume 暂停恢复;cancel 取消分步执行(计划保留)。一次一个转移。',
47
+ description: T.stepControl,
61
48
  parameters: ControlParams,
62
49
  async execute(_id, params, _signal, _onUpdate, ctx: ExtensionToolContext) {
63
50
  switch (params.action) {
@@ -141,8 +128,7 @@ export function registerPlanStepTools(
141
128
  pi.registerTool({
142
129
  name: "plan_step_complete",
143
130
  label: "plan step complete",
144
- description:
145
- "完成当前进行中的分步(仅在本步实现与适用检查完成后调用)。摘要必填。完成立即生效,不等待用户验收;绝不开始下一步。",
131
+ description: T.stepComplete,
146
132
  parameters: CompleteParams,
147
133
  async execute(_id, params, _signal, _onUpdate, ctx: ExtensionToolContext) {
148
134
  const r = engine.tryApply(
@@ -162,6 +148,12 @@ export function registerPlanStepTools(
162
148
  );
163
149
  },
164
150
  });
151
+
152
+ /** 终态归档透出:仅当本次转移收尾了计划(lastArchive 每次 apply 重置)。 */
153
+ function archiveSuffix(): string {
154
+ const a = engine.lastArchive;
155
+ return a?.ok ? `\n状态块已写入计划文件:${a.path}` : "";
156
+ }
165
157
  }
166
158
 
167
159
  function ok(t: string) {