@andares/pi-toolkits 1.0.0 → 1.0.2

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +26 -25
  3. package/README.zh-CN.md +28 -27
  4. package/package.json +8 -7
  5. package/src/features/ask/index.test.ts +2 -2
  6. package/src/features/ask/index.ts +1 -1
  7. package/src/features/autostart/autostart.ts +1 -1
  8. package/src/features/autostart/index.ts +3 -2
  9. package/src/features/compact/index.ts +1 -1
  10. package/src/features/compact/prompt.ts +3 -3
  11. package/src/features/favorites/patch-selector.ts +5 -1
  12. package/src/features/init/index.test.ts +2 -2
  13. package/src/features/init/templates/workflow-block.md +2 -2
  14. package/src/features/permission/index.ts +1 -1
  15. package/src/features/permission/panel.ts +3 -1
  16. package/src/features/quit-guard/index.ts +4 -3
  17. package/src/features/review/index.ts +3 -3
  18. package/src/features/review/review.test.ts +2 -2
  19. package/src/features/spec/assets/index-CdTerMvN.css +1 -0
  20. package/src/features/spec/assets/index-Dv52AIjX.js +1 -0
  21. package/src/features/{plan → spec}/assets/index.html +3 -3
  22. package/src/features/{plan → spec}/assets.test.ts +5 -5
  23. package/src/features/{plan → spec}/blocks.ts +1 -1
  24. package/src/features/{plan → spec}/feedback.test.ts +26 -26
  25. package/src/features/{plan → spec}/feedback.ts +14 -14
  26. package/src/features/{plan → spec}/index.test.ts +100 -66
  27. package/src/features/{plan → spec}/index.ts +117 -106
  28. package/src/features/{plan → spec}/prompt.test.ts +20 -20
  29. package/src/features/{plan → spec}/prompt.ts +25 -25
  30. package/src/features/{plan → spec}/render.test.ts +2 -2
  31. package/src/features/{plan → spec}/server.test.ts +21 -21
  32. package/src/features/{plan → spec}/server.ts +22 -22
  33. package/src/features/{plan → spec}/store.test.ts +77 -35
  34. package/src/features/{plan → spec}/store.ts +80 -52
  35. package/src/features/uat/index.test.ts +5 -5
  36. package/src/features/uat/index.ts +8 -8
  37. package/src/features/uat/record-tool.ts +3 -3
  38. package/src/features/uat/records.test.ts +5 -5
  39. package/src/index.ts +6 -6
  40. package/src/lib/ask-control.ts +2 -2
  41. package/src/lib/permission-control.ts +4 -4
  42. package/src/lib/phases.ts +20 -7
  43. package/src/lib/web-review.ts +1 -1
  44. package/src/features/plan/assets/index-C1YLIi4I.js +0 -1
  45. package/src/features/plan/assets/index-DMEpYC3V.css +0 -1
  46. /package/src/features/{plan → spec}/blocks.test.ts +0 -0
  47. /package/src/features/{plan → spec}/diff.test.ts +0 -0
  48. /package/src/features/{plan → spec}/diff.ts +0 -0
  49. /package/src/features/{plan → spec}/render.ts +0 -0
@@ -1,14 +1,14 @@
1
1
  /**
2
- * ask-plan — plan mode with a browser review round.
2
+ * ask-spec — spec mode with a browser review round.
3
3
  *
4
- * The flow: `/ask-plan` opens a planning phase (read tools, questions, markdown
5
- * writes only), the agent writes a spec and calls `plan_submit`, the review
4
+ * The flow: `/ask-spec` opens a spec-review phase (read tools, questions, markdown
5
+ * writes only), the agent writes a spec and calls `spec_submit`, the review
6
6
  * server opens the page in the operator's browser, annotations come back as a
7
- * message, and the loop repeats until the plan is approved — then the phase ends
7
+ * message, and the loop repeats until the spec is approved — then the phase ends
8
8
  * and the agent implements.
9
9
  *
10
10
  * Three properties are load-bearing:
11
- * - `plan_submit` returns immediately. Waiting for the decision inside the
11
+ * - `spec_submit` returns immediately. Waiting for the decision inside the
12
12
  * tool would pin the agent for as long as the operator takes to read; the
13
13
  * decision arrives later as a normal user message instead.
14
14
  * - the decision always carries the annotations. Approve and deny only choose
@@ -26,35 +26,36 @@ import type { ExtensionAPI, ExtensionContext, ToolCallEvent } from "@earendil-wo
26
26
  import type { GateHub } from "../../lib/gates.js";
27
27
  import { getPermissionControl, type PermissionSnapshot } from "../../lib/permission-control.js";
28
28
  import { getAskControl } from "../../lib/ask-control.js";
29
- import { PLAN_PHASE_TOOL, UAT_PHASE_TOOL } from "../../lib/phases.js";
29
+ import { LEGACY_SPEC_PHASE_TOOL, SPEC_PHASE_TOOL, UAT_PHASE_TOOL } from "../../lib/phases.js";
30
30
  import { frameworkReadiness } from "../init/parity.js";
31
31
  import { resolveProjectRoot } from "../uat/state.js";
32
32
  import { canonicalize, isWithin } from "../permission/paths.js";
33
33
  import { parseCommandUnits } from "../permission/units.js";
34
34
  import { buildFeedbackMarkdown } from "./feedback.js";
35
35
  import { openInBrowser } from "../../lib/opener.js";
36
- import { buildPlanKickoff, buildPlanSystemPrompt } from "./prompt.js";
36
+ import { buildSpecKickoff, buildSpecSystemPrompt } from "./prompt.js";
37
37
  import { renderBlockHtml } from "./render.js";
38
- import { buildPlanState, startPlanServer, type PlanServerHandle } from "./server.js";
38
+ import { buildSpecState, startSpecServer, type SpecServerHandle } from "./server.js";
39
39
  import {
40
- appendPlanVersion,
41
- createPlanSession,
40
+ appendSpecVersion,
41
+ createSpecSession,
42
42
  latestVersion,
43
- planSlug,
43
+ specSlug,
44
44
  readVersionText,
45
- type PlanSession,
45
+ type SpecSession,
46
46
  } from "./store.js";
47
47
 
48
- export const PLAN_COMMAND = "ask-plan";
49
- export const PLAN_SUBMIT_TOOL = PLAN_PHASE_TOOL;
48
+ export const SPEC_COMMAND = "ask-spec";
49
+ export const SPEC_COMMAND_ALIAS = "ask-plan";
50
+ export const SPEC_SUBMIT_TOOL = SPEC_PHASE_TOOL;
50
51
 
51
- /** Files the planning phase may write: project markdown, nothing else. */
52
+ /** Files the spec-review phase may write: project markdown, nothing else. */
52
53
  function isMarkdownPath(path: string): boolean {
53
54
  return /\.mdx?$/i.test(path);
54
55
  }
55
56
 
56
57
  /** Resolve a markdown path inside the workspace; anything else is rejected. */
57
- function planMarkdownPath(path: string, cwd: string): string | undefined {
58
+ function specMarkdownPath(path: string, cwd: string): string | undefined {
58
59
  if (path === "" || !isMarkdownPath(path)) return undefined;
59
60
  const absolute = canonicalize(isAbsolute(path) ? path : resolve(cwd, path));
60
61
  if (absolute === cwd || !isWithin(cwd, absolute)) return undefined;
@@ -79,17 +80,17 @@ function sessionIdOf(ctx: ExtensionContext): string {
79
80
  }
80
81
  }
81
82
 
82
- const PLAN_SUBMIT_PARAMS = Type.Object({
83
+ const SPEC_SUBMIT_PARAMS = Type.Object({
83
84
  path: Type.Optional(
84
85
  Type.String({
85
86
  description:
86
- 'Spec file to submit, relative to the workspace root (default: the file chosen when plan mode started, e.g. "specs/ask-plan.md"). Write the file first — plan_submit reads it from disk.',
87
+ 'Spec file to submit, relative to the workspace root (default: the file chosen when spec mode started, e.g. "specs/ask-spec.md"). Write the file first — spec_submit reads it from disk.',
87
88
  }),
88
89
  ),
89
90
  });
90
91
 
91
- export interface PlanOptions {
92
- /** `<agent-dir>`: review history lives at `<agentDir>/ask-plan/` (default: the host's). */
92
+ export interface SpecOptions {
93
+ /** `<agent-dir>`: review history lives at `<agentDir>/ask-spec/` (default: the host's). */
93
94
  agentDir?: string;
94
95
  /** Opening the browser is injectable so tests never spawn one. */
95
96
  openBrowser?: (url: string) => unknown;
@@ -99,19 +100,19 @@ export interface PlanOptions {
99
100
  portStart?: number;
100
101
  }
101
102
 
102
- export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOptions = {}): void {
103
+ export function registerSpec(pi: ExtensionAPI, gates: GateHub, options: SpecOptions = {}): void {
103
104
  const open = options.openBrowser ?? openInBrowser;
104
105
  const agentDir = options.agentDir ?? getAgentDir();
105
106
 
106
107
  let active = false;
107
- let session: PlanSession | undefined;
108
- let server: PlanServerHandle | undefined;
108
+ let session: SpecSession | undefined;
109
+ let server: SpecServerHandle | undefined;
109
110
  let permissionBefore: PermissionSnapshot | undefined;
110
111
  let permissionDuring: PermissionSnapshot | undefined;
111
112
  let specPath: string | undefined;
112
113
  let cwd = process.cwd();
113
114
  let ctxRef: ExtensionContext | undefined;
114
- let planSessionId: string | undefined;
115
+ let specSessionId: string | undefined;
115
116
 
116
117
  function closeServer(): void {
117
118
  if (!server) return;
@@ -120,12 +121,16 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
120
121
  }
121
122
 
122
123
  function toolSetWithSubmit(): string[] {
123
- const tools = pi.getActiveTools().filter((name) => name !== PLAN_SUBMIT_TOOL);
124
- return [...tools, PLAN_SUBMIT_TOOL];
124
+ const tools = pi
125
+ .getActiveTools()
126
+ .filter((name) => name !== SPEC_SUBMIT_TOOL && name !== LEGACY_SPEC_PHASE_TOOL);
127
+ return [...tools, SPEC_SUBMIT_TOOL];
125
128
  }
126
129
 
127
130
  function toolSetWithoutSubmit(): string[] {
128
- return pi.getActiveTools().filter((name) => name !== PLAN_SUBMIT_TOOL);
131
+ return pi
132
+ .getActiveTools()
133
+ .filter((name) => name !== SPEC_SUBMIT_TOOL && name !== LEGACY_SPEC_PHASE_TOOL);
129
134
  }
130
135
 
131
136
  function leave(ctx: ExtensionContext, reason: string): void {
@@ -135,8 +140,8 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
135
140
  pi.setActiveTools(toolSetWithoutSubmit());
136
141
  const control = getPermissionControl();
137
142
  const current = control?.snapshot();
138
- // Restore only if the operator has not changed the policy mid-plan. A
139
- // manual `/ask-perm` during planning is newer intent and must win.
143
+ // Restore only if the operator has not changed the policy mid-review. A
144
+ // manual `/ask-perm` during the spec review is newer intent and must win.
140
145
  if (
141
146
  control &&
142
147
  permissionBefore &&
@@ -148,8 +153,8 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
148
153
  }
149
154
  permissionBefore = undefined;
150
155
  permissionDuring = undefined;
151
- planSessionId = undefined;
152
- ctx.ui.notify(`ask-plan: ${reason}`, "info");
156
+ specSessionId = undefined;
157
+ ctx.ui.notify(`ask-spec: ${reason}`, "info");
153
158
  }
154
159
 
155
160
  /** Compose the message the model receives for one decision. */
@@ -170,9 +175,9 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
170
175
  perBlock: current.annotations.blocks,
171
176
  // Approval quotes the reviewed snapshot, not the file's current bytes:
172
177
  // the model may have kept editing after submitting this revision.
173
- planPath: current.source ?? specPath,
174
- planText: readApprovedText(version) ?? current.blocks.map((block) => block.text).join("\n\n"),
175
- // During planning the tool is intentionally inactive. Recommend it on
178
+ specPath: current.source ?? specPath,
179
+ specText: readApprovedText(version) ?? current.blocks.map((block) => block.text).join("\n\n"),
180
+ // During the review the tool is intentionally inactive. Recommend it on
176
181
  // approval only when the project has the framework and the tool exists.
177
182
  recordTool:
178
183
  pi.getAllTools().some((tool) => tool.name === "record_change") &&
@@ -194,26 +199,26 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
194
199
  decision: { action: "approve" | "deny"; version: number },
195
200
  ctx: ExtensionContext,
196
201
  ): Promise<void> {
197
- // The operator may leave plan mode, or switch sessions, during the short
202
+ // The operator may leave spec mode, or switch sessions, during the short
198
203
  // close delay. A stale decision must not resurrect implementation or send
199
204
  // an empty message into the new phase.
200
205
  if (!active) return;
201
206
  const message = decisionMessage(decision.version);
202
207
  if (decision.action === "approve") {
203
208
  // Leave the phase before the message goes out: the implementation
204
- // turn must not run under the planning gates.
205
- leave(ctx, "plan approved — implementing.");
209
+ // turn must not run under the spec-review gates.
210
+ leave(ctx, "spec approved — implementing.");
206
211
  } else {
207
- ctx.ui.notify("ask-plan: feedback sent — the agent will revise the plan.", "info");
212
+ ctx.ui.notify("ask-spec: feedback sent — the agent will revise the spec.", "info");
208
213
  }
209
214
  pi.sendUserMessage(message);
210
215
  }
211
216
 
212
217
  // ── Command ────────────────────────────────────────────────────────────
213
218
 
214
- pi.registerCommand(PLAN_COMMAND, {
219
+ const specCommand = {
215
220
  description:
216
- "Plan first: research, write a spec, review it in the browser with block annotations, then implement after approval. `off` leaves the phase, `open` re-opens the review.",
221
+ "Spec first: research, write a spec, review it in the browser with block annotations, then implement after approval. `off` leaves the phase, `open` re-opens the review.",
217
222
  handler: async (args: string, ctx: ExtensionContext) => {
218
223
  const arg = args.trim();
219
224
  ctxRef = ctx;
@@ -221,90 +226,96 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
221
226
 
222
227
  if (arg === "off") {
223
228
  if (!active) {
224
- ctx.ui.notify("ask-plan: not in plan mode.", "info");
229
+ ctx.ui.notify("ask-spec: not in spec mode.", "info");
225
230
  return;
226
231
  }
227
- leave(ctx, specPath ? `plan mode off — draft left at ${specPath}.` : "plan mode off.");
232
+ leave(ctx, specPath ? `spec mode off — draft left at ${specPath}.` : "spec mode off.");
228
233
  return;
229
234
  }
230
235
 
231
236
  if (arg === "open") {
232
237
  if (!server) {
233
- ctx.ui.notify("ask-plan: no review is open — submit a plan first.", "warning");
238
+ ctx.ui.notify("ask-spec: no review is open — submit a spec first.", "warning");
234
239
  return;
235
240
  }
236
241
  open(server.url);
237
- ctx.ui.notify(`ask-plan: ${server.url}`, "info");
242
+ ctx.ui.notify(`ask-spec: ${server.url}`, "info");
238
243
  return;
239
244
  }
240
245
 
241
246
  if (active) {
242
- ctx.ui.notify("ask-plan: already planning. Use `off` to leave the phase.", "warning");
247
+ ctx.ui.notify("ask-spec: already reviewing a spec. Use `off` to leave the phase.", "warning");
243
248
  return;
244
249
  }
245
250
 
246
251
  if (!ctx.isIdle()) {
247
- ctx.ui.notify("ask-plan: the agent is still running — finish or abort first.", "warning");
252
+ ctx.ui.notify("ask-spec: the agent is still running — finish or abort first.", "warning");
248
253
  return;
249
254
  }
250
255
  if (pi.getActiveTools().includes(UAT_PHASE_TOOL)) {
251
- ctx.ui.notify("ask-plan: ask-uat is open — /ask-uat off first.", "warning");
256
+ ctx.ui.notify("ask-spec: ask-uat is open — /ask-uat off first.", "warning");
252
257
  return;
253
258
  }
254
259
 
255
260
  const readiness = frameworkReadiness(resolveProjectRoot(cwd));
256
261
  if (!readiness.ready) {
257
262
  ctx.ui.notify(
258
- `ask-plan: no complete agent framework (missing: ${readiness.missing.join(", ")}). The spec still works, but record_change and /ask-uat stay unavailable until /ask-init.`,
263
+ `ask-spec: no complete agent framework (missing: ${readiness.missing.join(", ")}). The spec still works, but record_change and /ask-uat stay unavailable until /ask-init.`,
259
264
  "info",
260
265
  );
261
266
  }
262
267
 
263
- const slug = planSlug(arg || "plan");
268
+ const slug = specSlug(arg || "spec");
264
269
  specPath = `specs/${slug}.md`;
265
270
  session = undefined;
266
- planSessionId = sessionIdOf(ctx);
271
+ specSessionId = sessionIdOf(ctx);
267
272
  const permission = getPermissionControl();
268
273
  permissionBefore = permission?.snapshot();
269
274
  permission?.enableDefaults(ctx);
270
275
  permissionDuring = permission?.snapshot();
271
- // Plan mode is intentionally less restrictive than ask mode. Let ask
272
- // restore its own tool snapshot before we add plan_submit.
276
+ // Spec mode is intentionally less restrictive than ask mode. Let ask
277
+ // restore its own tool snapshot before we add spec_submit.
273
278
  if (getAskControl()?.isActive()) getAskControl()?.exit(ctx);
274
279
  active = true;
275
280
  pi.setActiveTools(toolSetWithSubmit());
276
281
  ctx.ui.notify(
277
- `ask-plan: planning. Write the spec to ${specPath}, then call ${PLAN_SUBMIT_TOOL}.`,
282
+ `ask-spec: reviewing. Write the spec to ${specPath}, then call ${SPEC_SUBMIT_TOOL}.`,
278
283
  "info",
279
284
  );
280
- pi.sendUserMessage(buildPlanKickoff(arg || undefined));
285
+ pi.sendUserMessage(buildSpecKickoff(arg || undefined));
281
286
  },
282
- });
287
+ };
288
+
289
+ // `/ask-plan` stays as an alias: the workflow predates the rename, and a
290
+ // half-remembered command must not drop the operator into a plain chat.
291
+ for (const command of [SPEC_COMMAND, SPEC_COMMAND_ALIAS]) {
292
+ pi.registerCommand(command, specCommand);
293
+ }
283
294
 
284
295
  // ── Tool ───────────────────────────────────────────────────────────────
285
296
 
286
- pi.registerTool<typeof PLAN_SUBMIT_PARAMS, { version?: number; url?: string }>({
287
- name: PLAN_SUBMIT_TOOL,
288
- label: "Submit plan for review",
297
+ pi.registerTool<typeof SPEC_SUBMIT_PARAMS, { version?: number; url?: string }>({
298
+ name: SPEC_SUBMIT_TOOL,
299
+ label: "Submit spec for review",
289
300
  description:
290
301
  "Submit the spec file you just wrote so the operator can review and annotate it in the browser. Returns immediately; the decision arrives as a new message.",
291
- promptSnippet: "Submit the plan for browser review (plan mode only)",
302
+ promptSnippet: "Submit the spec for browser review (spec mode only)",
292
303
  promptGuidelines: [
293
- "Call plan_submit only after the spec file on disk is the version you want reviewed.",
304
+ "Call spec_submit only after the spec file on disk is the version you want reviewed.",
294
305
  "After submitting, end your turn: the operator's annotations arrive as a new message.",
295
- "Never submit a file you have not written — plan_submit reads the file from disk.",
306
+ "Never submit a file you have not written — spec_submit reads the file from disk.",
296
307
  ],
297
- parameters: PLAN_SUBMIT_PARAMS,
308
+ parameters: SPEC_SUBMIT_PARAMS,
298
309
  defaultActive: false,
299
310
  async execute(_toolCallId: string, params: { path?: string }) {
300
311
  if (!active) {
301
312
  return {
302
- content: [{ type: "text" as const, text: "Plan mode is off — use /ask-plan first." }],
313
+ content: [{ type: "text" as const, text: "Spec mode is off — use /ask-spec first." }],
303
314
  details: {},
304
315
  };
305
316
  }
306
- const target = params.path ?? specPath ?? "specs/plan.md";
307
- const absolute = planMarkdownPath(target, cwd);
317
+ const target = params.path ?? specPath ?? "specs/spec.md";
318
+ const absolute = specMarkdownPath(target, cwd);
308
319
  if (!absolute) {
309
320
  return {
310
321
  content: [
@@ -324,7 +335,7 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
324
335
  content: [
325
336
  {
326
337
  type: "text" as const,
327
- text: `Cannot read ${target}. Write the spec file first, then call plan_submit again.`,
338
+ text: `Cannot read ${target}. Write the spec file first, then call spec_submit again.`,
328
339
  },
329
340
  ],
330
341
  details: {},
@@ -332,18 +343,18 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
332
343
  }
333
344
  const source = relative(cwd, absolute) || target;
334
345
  if (!session) {
335
- session = createPlanSession({
346
+ session = createSpecSession({
336
347
  agentDir,
337
- slug: planSlug(source.replace(/\.mdx?$/i, "").replace(/^specs\//, "")),
348
+ slug: specSlug(source.replace(/\.mdx?$/i, "").replace(/^specs\//, "")),
338
349
  text,
339
350
  source,
340
351
  });
341
352
  } else {
342
- appendPlanVersion(session, { text, source });
353
+ appendSpecVersion(session, { text, source });
343
354
  }
344
355
  const version = latestVersion(session);
345
356
  if (!server) {
346
- server = await startPlanServer({
357
+ server = await startSpecServer({
347
358
  session,
348
359
  render: renderBlockHtml,
349
360
  portStart: options.portStart,
@@ -354,11 +365,11 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
354
365
  },
355
366
  });
356
367
  open(server.url);
357
- ctxRef?.ui.notify(`ask-plan: review open at ${server.url}`, "info");
368
+ ctxRef?.ui.notify(`ask-spec: review open at ${server.url}`, "info");
358
369
  } else {
359
370
  server.broadcast("revision", { version: version.n });
360
371
  }
361
- const changed = buildPlanState(session, version.n).items.filter(
372
+ const changed = buildSpecState(session, version.n).items.filter(
362
373
  (item) => item.status !== "unchanged",
363
374
  ).length;
364
375
  return {
@@ -375,56 +386,56 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
375
386
  },
376
387
  });
377
388
 
378
- // ── Gate: the planning phase writes markdown only ──────────────────────
389
+ // ── Gate: the spec-review phase writes markdown only ──────────────────────
379
390
 
380
391
  gates.register({
381
- name: "plan",
392
+ name: "spec",
382
393
  order: 5,
383
- evaluate(event: ToolCallEvent) {
384
- if (!active) return undefined;
385
- if (event.toolName === "bash") {
386
- // The promise is "plan mode does not implement", and a redirect is
387
- // implementation just as much as `write` is. Temp paths outside the
388
- // workspace stay allowed; opaque units are left to the permission gate,
389
- // which already fails closed on them (no double prompt here).
390
- const command = typeof event.input.command === "string" ? event.input.command : "";
391
- if (command === "") return undefined;
392
- for (const unit of parseCommandUnits(command, cwd)) {
393
- if (unit.opaque) continue;
394
- for (const target of unit.targets) {
395
- if (target.effect !== "write") continue;
396
- const absolute = canonicalize(target.path);
397
- if (absolute === cwd || !isWithin(cwd, absolute)) continue;
398
- if (/\.mdx?$/i.test(absolute)) continue;
399
- return {
400
- kind: "block" as const,
401
- reason:
402
- `Plan mode only writes markdown while the plan is under review (blocked bash write to ${target.path}). ` +
403
- "Implement the change after the plan is approved; write the spec file instead.",
404
- };
405
- }
394
+ evaluate(event: ToolCallEvent) {
395
+ if (!active) return undefined;
396
+ if (event.toolName === "bash") {
397
+ // The promise is "spec mode does not implement", and a redirect is
398
+ // implementation just as much as `write` is. Temp paths outside the
399
+ // workspace stay allowed; opaque units are left to the permission gate,
400
+ // which already fails closed on them (no double prompt here).
401
+ const command = typeof event.input.command === "string" ? event.input.command : "";
402
+ if (command === "") return undefined;
403
+ for (const unit of parseCommandUnits(command, cwd)) {
404
+ if (unit.opaque) continue;
405
+ for (const target of unit.targets) {
406
+ if (target.effect !== "write") continue;
407
+ const absolute = canonicalize(target.path);
408
+ if (absolute === cwd || !isWithin(cwd, absolute)) continue;
409
+ if (/\.mdx?$/i.test(absolute)) continue;
410
+ return {
411
+ kind: "block" as const,
412
+ reason:
413
+ `Spec mode only writes markdown while the spec is under review (blocked bash write to ${target.path}). ` +
414
+ "Implement the change after the spec is approved; write the spec file instead.",
415
+ };
406
416
  }
407
- return undefined;
408
417
  }
409
- if (event.toolName !== "write" && event.toolName !== "edit") return undefined;
418
+ return undefined;
419
+ }
420
+ if (event.toolName !== "write" && event.toolName !== "edit") return undefined;
410
421
  const path = typeof event.input.path === "string" ? event.input.path : "";
411
- if (planMarkdownPath(path, cwd) !== undefined) return undefined;
422
+ if (specMarkdownPath(path, cwd) !== undefined) return undefined;
412
423
  return {
413
424
  kind: "block" as const,
414
425
  reason:
415
- "Plan mode only writes markdown (.md/.mdx) while the plan is under review. " +
416
- "Implement the change after the plan is approved, or write the spec file instead.",
426
+ "Spec mode only writes markdown (.md/.mdx) while the spec is under review. " +
427
+ "Implement the change after the spec is approved, or write the spec file instead.",
417
428
  };
418
429
  },
419
430
  });
420
431
 
421
- // ── System prompt while planning ───────────────────────────────────────
432
+ // ── System prompt while reviewing ──────────────────────────────────────
422
433
 
423
434
  pi.on("before_agent_start", (event) => {
424
435
  if (!active) return undefined;
425
436
  pi.setActiveTools(toolSetWithSubmit());
426
437
  return {
427
- systemPrompt: `${event.systemPrompt}\n\n${buildPlanSystemPrompt({
438
+ systemPrompt: `${event.systemPrompt}\n\n${buildSpecSystemPrompt({
428
439
  questionTool: pi.getActiveTools().includes("ask_user_question"),
429
440
  })}`,
430
441
  };
@@ -436,7 +447,7 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
436
447
 
437
448
  pi.on("session_start", (_event, ctx) => {
438
449
  const nextSessionId = sessionIdOf(ctx);
439
- if (nextSessionId === planSessionId) return;
450
+ if (nextSessionId === specSessionId) return;
440
451
  // A different session must not inherit this session's gates, review server
441
452
  // or permission snapshot. Permission's own session_start has already reset
442
453
  // its state, so do not restore the old snapshot here.
@@ -444,7 +455,7 @@ export function registerPlan(pi: ExtensionAPI, gates: GateHub, options: PlanOpti
444
455
  session = undefined;
445
456
  permissionBefore = undefined;
446
457
  permissionDuring = undefined;
447
- planSessionId = undefined;
458
+ specSessionId = undefined;
448
459
  specPath = undefined;
449
460
  ctxRef = ctx;
450
461
  closeServer();
@@ -1,26 +1,26 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import {
3
- buildPlanKickoff,
4
- buildPlanSystemPrompt,
3
+ buildSpecKickoff,
4
+ buildSpecSystemPrompt,
5
5
  INTERVIEW_GUIDE,
6
- PLAN_MODE_BANNER,
6
+ SPEC_MODE_BANNER,
7
7
  SPEC_FRAMEWORK_GUIDE,
8
8
  } from "./prompt.js";
9
9
 
10
- describe("plan mode prompt", () => {
10
+ describe("spec review prompt", () => {
11
11
  it("states what the phase allows and how a turn may end", () => {
12
- expect(PLAN_MODE_BANNER).toContain("[ASK-PLAN — PLANNING]");
13
- expect(PLAN_MODE_BANNER).toContain("writing/editing\nmarkdown files");
14
- expect(PLAN_MODE_BANNER).toContain("Not allowed: editing other files");
15
- expect(PLAN_MODE_BANNER).toContain("plan_submit");
16
- expect(PLAN_MODE_BANNER).toContain("End every turn with either a question or a plan_submit call");
12
+ expect(SPEC_MODE_BANNER).toContain("[ASK-SPEC — SPEC REVIEW]");
13
+ expect(SPEC_MODE_BANNER).toContain("writing/editing\nmarkdown files");
14
+ expect(SPEC_MODE_BANNER).toContain("Not allowed: editing other files");
15
+ expect(SPEC_MODE_BANNER).toContain("spec_submit");
16
+ expect(SPEC_MODE_BANNER).toContain("End every turn with either a question or a spec_submit call");
17
17
  });
18
18
 
19
19
  it("asks in rounds instead of guessing, and never names a tool the session lacks", () => {
20
20
  expect(INTERVIEW_GUIDE).toContain("in rounds");
21
21
  expect(INTERVIEW_GUIDE).toContain("Do not ask what you can read");
22
- expect(buildPlanSystemPrompt({ questionTool: false })).toContain("ask in plain text");
23
- expect(buildPlanSystemPrompt({ questionTool: true })).toContain("`ask_user_question` is available");
22
+ expect(buildSpecSystemPrompt({ questionTool: false })).toContain("ask in plain text");
23
+ expect(buildSpecSystemPrompt({ questionTool: true })).toContain("`ask_user_question` is available");
24
24
  });
25
25
 
26
26
  it("gives the spec framework in reading order", () => {
@@ -61,8 +61,8 @@ describe("plan mode prompt", () => {
61
61
  });
62
62
 
63
63
  it("combines banner and guide without dropping either", () => {
64
- const prompt = buildPlanSystemPrompt();
65
- expect(prompt).toContain(PLAN_MODE_BANNER);
64
+ const prompt = buildSpecSystemPrompt();
65
+ expect(prompt).toContain(SPEC_MODE_BANNER);
66
66
  expect(prompt).toContain(SPEC_FRAMEWORK_GUIDE);
67
67
  });
68
68
 
@@ -70,22 +70,22 @@ describe("plan mode prompt", () => {
70
70
  // Framework prompts are authored in English, which is our choice of
71
71
  // language for the prompt — not an instruction about the spec. The spec
72
72
  // follows the operator's own language, so any directive would be a bug.
73
- const prompt = buildPlanSystemPrompt().toLowerCase();
73
+ const prompt = buildSpecSystemPrompt().toLowerCase();
74
74
  for (const banned of ["in english", "in chinese", "language", "write in"]) {
75
75
  expect(prompt, `prompt must not mention "${banned}"`).not.toContain(banned);
76
76
  }
77
77
  });
78
78
  });
79
79
 
80
- describe("buildPlanKickoff", () => {
80
+ describe("buildSpecKickoff", () => {
81
81
  it("names the task when one was given", () => {
82
- const kickoff = buildPlanKickoff("build /ask-plan");
83
- expect(kickoff).toContain("Task: build /ask-plan");
84
- expect(kickoff).toContain("plan_submit");
82
+ const kickoff = buildSpecKickoff("build /ask-spec");
83
+ expect(kickoff).toContain("Task: build /ask-spec");
84
+ expect(kickoff).toContain("spec_submit");
85
85
  });
86
86
 
87
87
  it("falls back to the session discussion", () => {
88
- expect(buildPlanKickoff(undefined)).toContain("the work we have been discussing in this session");
89
- expect(buildPlanKickoff(" ")).toContain("the work we have been discussing in this session");
88
+ expect(buildSpecKickoff(undefined)).toContain("the work we have been discussing in this session");
89
+ expect(buildSpecKickoff(" ")).toContain("the work we have been discussing in this session");
90
90
  });
91
91
  });