@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.
- package/CHANGELOG.md +23 -0
- package/README.md +101 -34
- package/README.zh-CN.md +68 -32
- package/package.json +10 -3
- package/src/features/ask/index.test.ts +15 -0
- package/src/features/ask/index.ts +18 -1
- package/src/features/init/audit.test.ts +19 -2
- package/src/features/init/audit.ts +117 -15
- package/src/features/init/index.test.ts +123 -1
- package/src/features/init/index.ts +156 -46
- package/src/features/init/parity.test.ts +176 -0
- package/src/features/init/parity.ts +229 -0
- package/src/features/init/plan.ts +25 -3
- package/src/features/init/refresh.test.ts +88 -1
- package/src/features/init/refresh.ts +43 -64
- package/src/features/init/spec.ts +11 -0
- package/src/features/init/templates/memory-readme.md +9 -2
- package/src/features/init/templates/workflow-block.md +2 -2
- package/src/features/init/test-helpers.ts +1 -0
- package/src/features/init/workflow.ts +159 -0
- package/src/features/permission/index.ts +1 -1
- package/src/features/quit-guard/constants.ts +18 -5
- package/src/features/quit-guard/index.ts +75 -29
- package/src/features/quit-guard/killer.test.ts +77 -0
- package/src/features/quit-guard/killer.ts +215 -0
- package/src/features/review/index.ts +14 -0
- package/src/features/review/review.test.ts +34 -2
- package/src/features/spec/assets/index-CdTerMvN.css +1 -0
- package/src/features/spec/assets/index-Dv52AIjX.js +1 -0
- package/src/features/{plan → spec}/assets/index.html +3 -3
- package/src/features/{plan → spec}/assets.test.ts +5 -5
- package/src/features/{plan → spec}/blocks.ts +1 -1
- package/src/features/{plan → spec}/feedback.test.ts +26 -26
- package/src/features/{plan → spec}/feedback.ts +14 -14
- package/src/features/{plan → spec}/index.test.ts +148 -63
- package/src/features/{plan → spec}/index.ts +136 -105
- package/src/features/{plan → spec}/prompt.test.ts +20 -20
- package/src/features/{plan → spec}/prompt.ts +25 -25
- package/src/features/{plan → spec}/render.test.ts +2 -2
- package/src/features/{plan → spec}/server.test.ts +21 -21
- package/src/features/{plan → spec}/server.ts +22 -22
- package/src/features/{plan → spec}/store.test.ts +77 -35
- package/src/features/{plan → spec}/store.ts +80 -52
- package/src/features/uat/index.test.ts +20 -5
- package/src/features/uat/index.ts +16 -13
- package/src/features/uat/record-tool.ts +6 -5
- package/src/features/uat/records.test.ts +5 -5
- package/src/features/uat/state.ts +13 -5
- package/src/index.ts +6 -6
- package/src/lib/ask-control.ts +2 -2
- package/src/lib/permission-control.ts +4 -4
- package/src/lib/phases.ts +50 -0
- package/src/lib/web-review.ts +1 -1
- package/src/features/plan/assets/index-C1YLIi4I.js +0 -1
- package/src/features/plan/assets/index-DMEpYC3V.css +0 -1
- /package/src/features/{plan → spec}/blocks.test.ts +0 -0
- /package/src/features/{plan → spec}/diff.test.ts +0 -0
- /package/src/features/{plan → spec}/diff.ts +0 -0
- /package/src/features/{plan → spec}/render.ts +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ask-
|
|
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 {
|
|
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
|
-
|
|
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-
|
|
135
|
-
it("enters
|
|
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(
|
|
139
|
+
const command = h.commands.get(SPEC_COMMAND);
|
|
138
140
|
expect(command).toBeDefined();
|
|
139
|
-
await command!.handler("ask-
|
|
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(
|
|
143
|
-
expect(h.sendUserMessage).toHaveBeenCalledWith(expect.stringContaining("Task: ask-
|
|
144
|
-
expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("specs/ask-
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
238
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
166
239
|
expect(exit).toHaveBeenCalledWith(h.ctx);
|
|
167
|
-
expect(h.activeTools()).toContain(
|
|
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-
|
|
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(
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
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(
|
|
288
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
204
289
|
writeSpec("specs/topic.md", "# SPEC: topic");
|
|
205
|
-
await h.tools.get(
|
|
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(
|
|
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("
|
|
217
|
-
const gate = (h: Harness) => h.gates.find((entry) => entry.name === "
|
|
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
|
|
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(
|
|
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
|
|
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("
|
|
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(
|
|
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(
|
|
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(
|
|
261
|
-
const result = await h.tools.get(
|
|
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(
|
|
268
|
-
const tool = h.tools.get(
|
|
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
|
|
358
|
+
it("refuses to submit outside spec mode", async () => {
|
|
274
359
|
const h = harness();
|
|
275
|
-
const result = await h.tools.get(
|
|
276
|
-
expect(result.content[0].text).toContain("
|
|
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(
|
|
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(
|
|
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("##
|
|
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
|
|
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(
|
|
383
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
299
384
|
});
|
|
300
385
|
|
|
301
|
-
it("drops a browser decision that arrives after
|
|
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(
|
|
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(
|
|
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
|
|
400
|
+
it("turns a denial into feedback but keeps reviewing", async () => {
|
|
316
401
|
const h = harness();
|
|
317
|
-
await h.commands.get(
|
|
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(
|
|
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("##
|
|
410
|
+
expect(message).toContain("## Spec feedback");
|
|
326
411
|
expect(message).toContain("No specific annotations were left");
|
|
327
|
-
expect(h.activeTools()).toContain(
|
|
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
|
|
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(
|
|
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-
|
|
346
|
-
expect(injected?.systemPrompt).toContain("
|
|
347
|
-
expect(injected?.systemPrompt).toContain("[ASK-
|
|
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(
|
|
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(
|
|
364
|
-
const gate = h.gates.find((entry) => entry.name === "
|
|
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", "
|
|
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");
|