@andares/pi-toolkits 0.14.0 → 1.0.1

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 (59) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +101 -34
  3. package/README.zh-CN.md +68 -32
  4. package/package.json +10 -3
  5. package/src/features/ask/index.test.ts +15 -0
  6. package/src/features/ask/index.ts +18 -1
  7. package/src/features/init/audit.test.ts +19 -2
  8. package/src/features/init/audit.ts +117 -15
  9. package/src/features/init/index.test.ts +123 -1
  10. package/src/features/init/index.ts +156 -46
  11. package/src/features/init/parity.test.ts +176 -0
  12. package/src/features/init/parity.ts +229 -0
  13. package/src/features/init/plan.ts +25 -3
  14. package/src/features/init/refresh.test.ts +88 -1
  15. package/src/features/init/refresh.ts +43 -64
  16. package/src/features/init/spec.ts +11 -0
  17. package/src/features/init/templates/memory-readme.md +9 -2
  18. package/src/features/init/templates/workflow-block.md +2 -2
  19. package/src/features/init/test-helpers.ts +1 -0
  20. package/src/features/init/workflow.ts +159 -0
  21. package/src/features/permission/index.ts +1 -1
  22. package/src/features/quit-guard/constants.ts +18 -5
  23. package/src/features/quit-guard/index.ts +75 -29
  24. package/src/features/quit-guard/killer.test.ts +77 -0
  25. package/src/features/quit-guard/killer.ts +215 -0
  26. package/src/features/review/index.ts +14 -0
  27. package/src/features/review/review.test.ts +34 -2
  28. package/src/features/spec/assets/index-CdTerMvN.css +1 -0
  29. package/src/features/spec/assets/index-Dv52AIjX.js +1 -0
  30. package/src/features/{plan → spec}/assets/index.html +3 -3
  31. package/src/features/{plan → spec}/assets.test.ts +5 -5
  32. package/src/features/{plan → spec}/blocks.ts +1 -1
  33. package/src/features/{plan → spec}/feedback.test.ts +26 -26
  34. package/src/features/{plan → spec}/feedback.ts +14 -14
  35. package/src/features/{plan → spec}/index.test.ts +148 -63
  36. package/src/features/{plan → spec}/index.ts +136 -105
  37. package/src/features/{plan → spec}/prompt.test.ts +20 -20
  38. package/src/features/{plan → spec}/prompt.ts +25 -25
  39. package/src/features/{plan → spec}/render.test.ts +2 -2
  40. package/src/features/{plan → spec}/server.test.ts +21 -21
  41. package/src/features/{plan → spec}/server.ts +22 -22
  42. package/src/features/{plan → spec}/store.test.ts +77 -35
  43. package/src/features/{plan → spec}/store.ts +80 -52
  44. package/src/features/uat/index.test.ts +20 -5
  45. package/src/features/uat/index.ts +16 -13
  46. package/src/features/uat/record-tool.ts +6 -5
  47. package/src/features/uat/records.test.ts +5 -5
  48. package/src/features/uat/state.ts +13 -5
  49. package/src/index.ts +6 -6
  50. package/src/lib/ask-control.ts +2 -2
  51. package/src/lib/permission-control.ts +4 -4
  52. package/src/lib/phases.ts +50 -0
  53. package/src/lib/web-review.ts +1 -1
  54. package/src/features/plan/assets/index-C1YLIi4I.js +0 -1
  55. package/src/features/plan/assets/index-DMEpYC3V.css +0 -1
  56. /package/src/features/{plan → spec}/blocks.test.ts +0 -0
  57. /package/src/features/{plan → spec}/diff.test.ts +0 -0
  58. /package/src/features/{plan → spec}/diff.ts +0 -0
  59. /package/src/features/{plan → spec}/render.ts +0 -0
@@ -1,11 +1,12 @@
1
1
  /**
2
- * ask-plan wiring: command, tool, gate, prompt, decision round-trip.
2
+ * ask-spec wiring: command, tool, gate, prompt, decision round-trip.
3
3
  *
4
4
  * The server is real here (it is the only way to prove the non-blocking submit
5
5
  * actually resolves into a message), the browser opener and the permission
6
6
  * control are fakes.
7
7
  */
8
8
  import { mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
9
+ import { execFileSync } from "node:child_process";
9
10
  import { request } from "node:http";
10
11
  import { tmpdir } from "node:os";
11
12
  import { dirname, join } from "node:path";
@@ -14,7 +15,8 @@ import type { ExtensionAPI, ExtensionContext, ToolCallEvent } from "@earendil-wo
14
15
  import type { GateHub, GateVerdict } from "../../lib/gates.js";
15
16
  import { setPermissionControl, type PermissionControl } from "../../lib/permission-control.js";
16
17
  import { setAskControl } from "../../lib/ask-control.js";
17
- import { registerPlan, PLAN_COMMAND, PLAN_SUBMIT_TOOL } from "./index.js";
18
+ import { LEGACY_SPEC_PHASE_TOOL } from "../../lib/phases.js";
19
+ import { registerSpec, SPEC_COMMAND, SPEC_COMMAND_ALIAS, SPEC_SUBMIT_TOOL } from "./index.js";
18
20
 
19
21
  let agentDir: string;
20
22
  let workDir: string;
@@ -98,7 +100,7 @@ function harness(): Harness {
98
100
  disable: vi.fn(),
99
101
  };
100
102
  setPermissionControl(control as unknown as PermissionControl);
101
- registerPlan(pi, { register: (def: never) => gates.push(def as never) } as unknown as GateHub, {
103
+ registerSpec(pi, { register: (def: never) => gates.push(def as never) } as unknown as GateHub, {
102
104
  agentDir,
103
105
  openBrowser,
104
106
  portStart: 46_000 + Math.floor(Math.random() * 1000),
@@ -131,43 +133,126 @@ async function decide(url: string, action: "approve" | "deny"): Promise<number>
131
133
  });
132
134
  }
133
135
 
134
- describe("ask-plan command", () => {
135
- it("enters plan mode: permission on, submit tool active, kickoff sent", async () => {
136
+ describe("ask-spec command", () => {
137
+ it("enters spec mode: permission on, submit tool active, kickoff sent", async () => {
136
138
  const h = harness();
137
- const command = h.commands.get(PLAN_COMMAND);
139
+ const command = h.commands.get(SPEC_COMMAND);
138
140
  expect(command).toBeDefined();
139
- await command!.handler("ask-plan work", h.ctx);
141
+ await command!.handler("ask-spec work", h.ctx);
140
142
 
141
143
  expect(h.control.enableDefaults).toHaveBeenCalledWith(h.ctx);
142
- expect(h.activeTools()).toContain(PLAN_SUBMIT_TOOL);
143
- expect(h.sendUserMessage).toHaveBeenCalledWith(expect.stringContaining("Task: ask-plan work"));
144
- expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("specs/ask-plan-work.md"), "info");
144
+ expect(h.activeTools()).toContain(SPEC_SUBMIT_TOOL);
145
+ expect(h.sendUserMessage).toHaveBeenCalledWith(expect.stringContaining("Task: ask-spec work"));
146
+ expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("specs/ask-spec-work.md"), "info");
147
+ });
148
+
149
+ it("keeps /ask-plan as an alias for the same handler", () => {
150
+ const h = harness();
151
+ const primary = h.commands.get(SPEC_COMMAND);
152
+ const alias = h.commands.get(SPEC_COMMAND_ALIAS);
153
+ expect(primary).toBeDefined();
154
+ expect(alias).toBeDefined();
155
+ expect(alias!.handler).toBe(primary!.handler);
156
+ });
157
+
158
+ it("runs the same flow through the alias", async () => {
159
+ const h = harness();
160
+ await h.commands.get(SPEC_COMMAND_ALIAS)!.handler("legacy topic", h.ctx);
161
+ expect(h.sendUserMessage).toHaveBeenCalledWith(expect.stringContaining("Task: legacy topic"));
162
+ });
163
+
164
+ it("defaults the spec file to specs/spec.md without a topic", async () => {
165
+ const h = harness();
166
+ await h.commands.get(SPEC_COMMAND)!.handler("", h.ctx);
167
+ expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("specs/spec.md"), "info");
145
168
  });
146
169
 
147
170
  it("refuses to start twice and can be turned off", async () => {
148
171
  const h = harness();
149
- const handler = h.commands.get(PLAN_COMMAND)!.handler;
172
+ const handler = h.commands.get(SPEC_COMMAND)!.handler;
150
173
  await handler("topic", h.ctx);
151
174
  await handler("topic", h.ctx);
152
- expect(h.notify).toHaveBeenLastCalledWith(expect.stringContaining("already planning"), "warning");
175
+ expect(h.notify).toHaveBeenLastCalledWith(expect.stringContaining("already reviewing a spec"), "warning");
153
176
 
154
177
  await handler("off", h.ctx);
155
178
  expect(h.control.restore).toHaveBeenCalled();
156
- expect(h.activeTools()).not.toContain(PLAN_SUBMIT_TOOL);
179
+ expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
180
+ });
181
+
182
+ it("refuses to start while ask-uat is open", async () => {
183
+ const h = harness();
184
+ h.pi.setActiveTools([...h.activeTools(), "uat_item"]);
185
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
186
+ expect(h.sendUserMessage).not.toHaveBeenCalled();
187
+ expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("ask-uat"), "warning");
188
+ });
189
+
190
+ it("refuses to start while the agent is still running", async () => {
191
+ const h = harness();
192
+ const busy = { ...h.ctx, isIdle: () => false } as ExtensionContext;
193
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", busy);
194
+ expect(h.sendUserMessage).not.toHaveBeenCalled();
195
+ expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("still running"), "warning");
196
+ });
197
+
198
+ it("reads framework readiness from the main checkout in a linked worktree", async () => {
199
+ const main = mkdtempSync(join(tmpdir(), "plan-main-"));
200
+ const parent = mkdtempSync(join(tmpdir(), "plan-worktrees-"));
201
+ const linked = join(parent, "linked");
202
+ const git = (cwd: string, args: string[]) =>
203
+ execFileSync("git", ["-C", cwd, ...args], { stdio: "ignore" });
204
+ try {
205
+ git(main, ["init", "-q"]);
206
+ writeFileSync(join(main, "tracked.txt"), "one\n", "utf8");
207
+ git(main, ["add", "tracked.txt"]);
208
+ git(main, ["-c", "user.email=test@example.com", "-c", "user.name=test", "commit", "-qm", "init"]);
209
+ git(main, ["worktree", "add", "-qb", "plan-review", linked]);
210
+ mkdirSync(join(main, ".agents/framework"), { recursive: true });
211
+ writeFileSync(join(main, ".agents/framework/state.toml"), 'version = 1\ntool = "test"\n', "utf8");
212
+ writeFileSync(join(main, "AGENTS.md"), "# demo\n", "utf8");
213
+ mkdirSync(join(main, ".agents/memory"), { recursive: true });
214
+ writeFileSync(join(main, ".agents/memory/README.md"), "# contract\n", "utf8");
215
+ mkdirSync(join(main, ".agents/implementations"), { recursive: true });
216
+
217
+ const h = harness();
218
+ const linkedCtx = { ...h.ctx, cwd: linked } as ExtensionContext;
219
+ const handler = h.commands.get(SPEC_COMMAND)!.handler;
220
+ await handler("topic", linkedCtx);
221
+ expect(h.notify).not.toHaveBeenCalledWith(
222
+ expect.stringContaining("no complete agent framework"),
223
+ "info",
224
+ );
225
+ await handler("off", linkedCtx);
226
+ } finally {
227
+ rmSync(main, { recursive: true, force: true });
228
+ rmSync(parent, { recursive: true, force: true });
229
+ }
157
230
  });
158
231
  });
159
232
 
160
233
  describe("phase integration", () => {
161
- it("exits ask mode before enabling the broader planning tool surface", async () => {
234
+ it("exits ask mode before enabling the broader spec-review tool surface", async () => {
162
235
  const h = harness();
163
236
  const exit = vi.fn();
164
237
  setAskControl({ isActive: () => true, exit });
165
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
238
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
166
239
  expect(exit).toHaveBeenCalledWith(h.ctx);
167
- expect(h.activeTools()).toContain(PLAN_SUBMIT_TOOL);
240
+ expect(h.activeTools()).toContain(SPEC_SUBMIT_TOOL);
241
+ });
242
+
243
+ it("clears both current and pre-rename submit markers", async () => {
244
+ const h = harness();
245
+ h.pi.setActiveTools([...h.activeTools(), LEGACY_SPEC_PHASE_TOOL]);
246
+ const handler = h.commands.get(SPEC_COMMAND)!.handler;
247
+ await handler("topic", h.ctx);
248
+ expect(h.activeTools()).toContain(SPEC_SUBMIT_TOOL);
249
+ expect(h.activeTools()).not.toContain(LEGACY_SPEC_PHASE_TOOL);
250
+ await handler("off", h.ctx);
251
+ expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
252
+ expect(h.activeTools()).not.toContain(LEGACY_SPEC_PHASE_TOOL);
168
253
  });
169
254
 
170
- it("does not overwrite a permission policy the operator changed mid-plan", async () => {
255
+ it("does not overwrite a permission policy the operator changed mid-review", async () => {
171
256
  const h = harness();
172
257
  const off = { enabled: false, modes: { inRead: "allow", inWrite: "allow", outRead: "allow", outWrite: "ask" } };
173
258
  const defaults = { enabled: true, modes: { inRead: "allow", inWrite: "allow", outRead: "allow", outWrite: "ask" } };
@@ -176,53 +261,53 @@ describe("phase integration", () => {
176
261
  .mockReturnValueOnce(off as never)
177
262
  .mockReturnValueOnce(defaults as never)
178
263
  .mockReturnValueOnce(manual as never);
179
- const handler = h.commands.get(PLAN_COMMAND)!.handler;
264
+ const handler = h.commands.get(SPEC_COMMAND)!.handler;
180
265
  await handler("topic", h.ctx);
181
266
  await handler("off", h.ctx);
182
267
  expect(h.control.restore).not.toHaveBeenCalled();
183
268
  expect(h.control.disable).not.toHaveBeenCalled();
184
269
  });
185
270
 
186
- it("starts a fresh review session for the next plan after leaving", async () => {
271
+ it("starts a fresh review session for the next spec after leaving", async () => {
187
272
  const h = harness();
188
- const handler = h.commands.get(PLAN_COMMAND)!.handler;
273
+ const handler = h.commands.get(SPEC_COMMAND)!.handler;
189
274
  await handler("first", h.ctx);
190
275
  writeSpec("specs/first.md", "# SPEC: first");
191
- const first = await h.tools.get(PLAN_SUBMIT_TOOL)!.execute("id", { path: "specs/first.md" });
276
+ const first = await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/first.md" });
192
277
  expect(first.content[0].text).toContain("Submitted v1 of 1");
193
278
  await handler("off", h.ctx);
194
279
  await handler("second", h.ctx);
195
280
  writeSpec("specs/second.md", "# SPEC: second");
196
- const second = await h.tools.get(PLAN_SUBMIT_TOOL)!.execute("id", { path: "specs/second.md" });
281
+ const second = await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/second.md" });
197
282
  expect(second.content[0].text).toContain("Submitted v1 of 1");
198
283
  expect(h.openBrowser).toHaveBeenCalledTimes(2);
199
284
  });
200
285
 
201
- it("drops plan state and closes the review when the pi session changes", async () => {
286
+ it("drops spec state and closes the review when the pi session changes", async () => {
202
287
  const h = harness();
203
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
288
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
204
289
  writeSpec("specs/topic.md", "# SPEC: topic");
205
- await h.tools.get(PLAN_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
290
+ await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
206
291
  const nextCtx = {
207
292
  ...h.ctx,
208
293
  sessionManager: { getSessionId: () => "next-session" },
209
294
  } as unknown as ExtensionContext;
210
295
  h.handlers.session_start![0]!({ systemPrompt: "" }, nextCtx);
211
- expect(h.activeTools()).not.toContain(PLAN_SUBMIT_TOOL);
296
+ expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
212
297
  expect(h.control.restore).not.toHaveBeenCalled();
213
298
  });
214
299
  });
215
300
 
216
- describe("plan gate", () => {
217
- const gate = (h: Harness) => h.gates.find((entry) => entry.name === "plan");
301
+ describe("spec gate", () => {
302
+ const gate = (h: Harness) => h.gates.find((entry) => entry.name === "spec");
218
303
 
219
- it("blocks writing anything but markdown while planning", async () => {
304
+ it("blocks writing anything but markdown while reviewing", async () => {
220
305
  const h = harness();
221
306
  const evaluate = gate(h)!.evaluate;
222
307
  const write = (path: string): ToolCallEvent => ({ toolName: "write", input: { path } }) as unknown as ToolCallEvent;
223
308
 
224
309
  expect(evaluate(write("src/features/x.ts"))).toBeUndefined();
225
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
310
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
226
311
  expect(evaluate(write("src/features/x.ts"))).toMatchObject({ kind: "block" });
227
312
  expect(evaluate(write("specs/topic.md"))).toBeUndefined();
228
313
  expect(evaluate(write("/tmp/outside.md"))).toMatchObject({ kind: "block" });
@@ -231,19 +316,19 @@ describe("plan gate", () => {
231
316
  expect(evaluate(write("linked/escape.md"))).toMatchObject({ kind: "block" });
232
317
  });
233
318
 
234
- it("stays out of the way when plan mode is off", () => {
319
+ it("stays out of the way when spec mode is off", () => {
235
320
  const h = harness();
236
321
  const event = { toolName: "edit", input: { path: "src/a.ts" } } as unknown as ToolCallEvent;
237
322
  expect(gate(h)!.evaluate(event)).toBeUndefined();
238
323
  });
239
324
  });
240
325
 
241
- describe("plan_submit", () => {
326
+ describe("spec_submit", () => {
242
327
  it("reads the file, snapshots a revision and opens the review once", async () => {
243
328
  const h = harness();
244
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
329
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
245
330
  writeSpec("specs/topic.md", "# SPEC: topic\n\nfirst step");
246
- const tool = h.tools.get(PLAN_SUBMIT_TOOL)!;
331
+ const tool = h.tools.get(SPEC_SUBMIT_TOOL)!;
247
332
 
248
333
  const first = await tool.execute("id", { path: "specs/topic.md" });
249
334
  expect(first.content[0].text).toContain("Submitted v1 of 1");
@@ -257,53 +342,53 @@ describe("plan_submit", () => {
257
342
 
258
343
  it("tells the model to write the file when it does not exist", async () => {
259
344
  const h = harness();
260
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
261
- const result = await h.tools.get(PLAN_SUBMIT_TOOL)!.execute("id", { path: "specs/missing.md" });
345
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
346
+ const result = await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/missing.md" });
262
347
  expect(result.content[0].text).toContain("Write the spec file first");
263
348
  });
264
349
 
265
350
  it("refuses to submit non-markdown or out-of-workspace files", async () => {
266
351
  const h = harness();
267
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
268
- const tool = h.tools.get(PLAN_SUBMIT_TOOL)!;
352
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
353
+ const tool = h.tools.get(SPEC_SUBMIT_TOOL)!;
269
354
  expect((await tool.execute("id", { path: "src/a.ts" })).content[0].text).toContain("inside the workspace");
270
355
  expect((await tool.execute("id", { path: "/tmp/outside.md" })).content[0].text).toContain("inside the workspace");
271
356
  });
272
357
 
273
- it("refuses to submit outside plan mode", async () => {
358
+ it("refuses to submit outside spec mode", async () => {
274
359
  const h = harness();
275
- const result = await h.tools.get(PLAN_SUBMIT_TOOL)!.execute("id", { path: "specs/x.md" });
276
- expect(result.content[0].text).toContain("Plan mode is off");
360
+ const result = await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/x.md" });
361
+ expect(result.content[0].text).toContain("Spec mode is off");
277
362
  });
278
363
 
279
364
  it("turns an approval into a message and leaves the phase", async () => {
280
365
  const h = harness();
281
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
366
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
282
367
  writeSpec("specs/topic.md", "# SPEC: topic\n\nfirst step");
283
- await h.tools.get(PLAN_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
368
+ await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
284
369
  const url = h.openBrowser.mock.calls[0][0] as string;
285
370
 
286
371
  expect(await decide(url, "approve")).toBe(200);
287
372
  await vi.waitFor(() => expect(h.sendUserMessage).toHaveBeenCalledTimes(2), { timeout: 5000 });
288
373
  const message = h.sendUserMessage.mock.calls[1][0] as string;
289
- expect(message).toContain("## Plan approved");
374
+ expect(message).toContain("## Spec approved");
290
375
  expect(message).toContain("start implementing");
291
376
  // The approved revision is quoted back (the file may have changed since
292
377
  // the submit), and the model is told to track the work in the todo list.
293
- expect(message).toContain("### Approved plan (specs/topic.md)");
378
+ expect(message).toContain("### Approved spec (specs/topic.md)");
294
379
  expect(message).toContain("# SPEC: topic\n\nfirst step");
295
380
  expect(message).toContain("Record the implementation work in the todo list");
296
381
  expect(message).not.toContain("call `record_change`");
297
382
  expect(h.control.restore).toHaveBeenCalled();
298
- expect(h.activeTools()).not.toContain(PLAN_SUBMIT_TOOL);
383
+ expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
299
384
  });
300
385
 
301
- it("drops a browser decision that arrives after plan mode was closed", async () => {
386
+ it("drops a browser decision that arrives after spec mode was closed", async () => {
302
387
  const h = harness();
303
- const handler = h.commands.get(PLAN_COMMAND)!.handler;
388
+ const handler = h.commands.get(SPEC_COMMAND)!.handler;
304
389
  await handler("topic", h.ctx);
305
390
  writeSpec("specs/topic.md", "# SPEC: topic");
306
- await h.tools.get(PLAN_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
391
+ await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
307
392
  const url = h.openBrowser.mock.calls[0][0] as string;
308
393
  expect(await decide(url, "deny")).toBe(200);
309
394
  await handler("off", h.ctx);
@@ -312,19 +397,19 @@ describe("plan_submit", () => {
312
397
  expect(h.sendUserMessage).toHaveBeenCalledTimes(1);
313
398
  });
314
399
 
315
- it("turns a denial into feedback but keeps planning", async () => {
400
+ it("turns a denial into feedback but keeps reviewing", async () => {
316
401
  const h = harness();
317
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
402
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
318
403
  writeSpec("specs/topic.md", "# SPEC: topic\n\nfirst step");
319
- await h.tools.get(PLAN_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
404
+ await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
320
405
  const url = h.openBrowser.mock.calls[0][0] as string;
321
406
 
322
407
  expect(await decide(url, "deny")).toBe(200);
323
408
  await vi.waitFor(() => expect(h.sendUserMessage).toHaveBeenCalledTimes(2), { timeout: 5000 });
324
409
  const message = h.sendUserMessage.mock.calls[1][0] as string;
325
- expect(message).toContain("## Plan feedback");
410
+ expect(message).toContain("## Spec feedback");
326
411
  expect(message).toContain("No specific annotations were left");
327
- expect(h.activeTools()).toContain(PLAN_SUBMIT_TOOL);
412
+ expect(h.activeTools()).toContain(SPEC_SUBMIT_TOOL);
328
413
  expect(h.control.restore).not.toHaveBeenCalled();
329
414
  });
330
415
  });
@@ -336,22 +421,22 @@ describe("prompt injection", () => {
336
421
  return handler!({ systemPrompt: prompt });
337
422
  };
338
423
 
339
- it("appends the plan framework only while planning", async () => {
424
+ it("appends the spec framework only while reviewing", async () => {
340
425
  const h = harness();
341
426
  expect(start(h, "base")).toBeUndefined();
342
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
427
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
343
428
  const injected = start(h, "base");
344
429
  expect(injected?.systemPrompt).toContain("base");
345
- expect(injected?.systemPrompt).toContain("[ASK-PLAN — PLANNING]");
346
- expect(injected?.systemPrompt).toContain("plan_submit");
347
- expect(injected?.systemPrompt).toContain("[ASK-PLAN — INTERVIEW]");
430
+ expect(injected?.systemPrompt).toContain("[ASK-SPEC — SPEC REVIEW]");
431
+ expect(injected?.systemPrompt).toContain("spec_submit");
432
+ expect(injected?.systemPrompt).toContain("[ASK-SPEC — INTERVIEW]");
348
433
  expect(injected?.systemPrompt).toContain("ask in plain text");
349
434
  });
350
435
 
351
436
  it("names the question tool only when it is active", async () => {
352
437
  const h = harness();
353
438
  h.pi.setActiveTools([...h.activeTools(), "ask_user_question"]);
354
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
439
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
355
440
  const injected = start(h, "base");
356
441
  expect(injected?.systemPrompt).toContain("`ask_user_question` is available");
357
442
  });
@@ -360,8 +445,8 @@ describe("prompt injection", () => {
360
445
  describe("plan write boundary", () => {
361
446
  it("blocks a bash write to a non-markdown project path", async () => {
362
447
  const h = harness();
363
- await h.commands.get(PLAN_COMMAND)!.handler("topic", h.ctx);
364
- const gate = h.gates.find((entry) => entry.name === "plan");
448
+ await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
449
+ const gate = h.gates.find((entry) => entry.name === "spec");
365
450
  expect(gate).toBeDefined();
366
451
  const evaluate = (command: string) =>
367
452
  gate!.evaluate({ toolName: "bash", input: { command } } as ToolCallEvent);
@@ -376,7 +461,7 @@ describe("plan write boundary", () => {
376
461
 
377
462
  describe("model policy", () => {
378
463
  it("contains no model-switching call in production code", () => {
379
- const root = join(process.cwd(), "src", "features", "plan");
464
+ const root = join(process.cwd(), "src", "features", "spec");
380
465
  for (const file of readdirSync(root)) {
381
466
  if (!file.endsWith(".ts") || file.endsWith(".test.ts")) continue;
382
467
  expect(readFileSync(join(root, file), "utf8"), file).not.toContain("setModel");