@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.
- package/CHANGELOG.md +17 -0
- package/README.md +26 -25
- package/README.zh-CN.md +28 -27
- package/package.json +8 -7
- package/src/features/ask/index.test.ts +2 -2
- package/src/features/ask/index.ts +1 -1
- package/src/features/autostart/autostart.ts +1 -1
- package/src/features/autostart/index.ts +3 -2
- package/src/features/compact/index.ts +1 -1
- package/src/features/compact/prompt.ts +3 -3
- package/src/features/favorites/patch-selector.ts +5 -1
- package/src/features/init/index.test.ts +2 -2
- package/src/features/init/templates/workflow-block.md +2 -2
- package/src/features/permission/index.ts +1 -1
- package/src/features/permission/panel.ts +3 -1
- package/src/features/quit-guard/index.ts +4 -3
- package/src/features/review/index.ts +3 -3
- package/src/features/review/review.test.ts +2 -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 +100 -66
- package/src/features/{plan → spec}/index.ts +117 -106
- 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 +5 -5
- package/src/features/uat/index.ts +8 -8
- package/src/features/uat/record-tool.ts +3 -3
- package/src/features/uat/records.test.ts +5 -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 +20 -7
- 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,5 +1,5 @@
|
|
|
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
|
|
@@ -15,7 +15,8 @@ import type { ExtensionAPI, ExtensionContext, ToolCallEvent } from "@earendil-wo
|
|
|
15
15
|
import type { GateHub, GateVerdict } from "../../lib/gates.js";
|
|
16
16
|
import { setPermissionControl, type PermissionControl } from "../../lib/permission-control.js";
|
|
17
17
|
import { setAskControl } from "../../lib/ask-control.js";
|
|
18
|
-
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";
|
|
19
20
|
|
|
20
21
|
let agentDir: string;
|
|
21
22
|
let workDir: string;
|
|
@@ -99,7 +100,7 @@ function harness(): Harness {
|
|
|
99
100
|
disable: vi.fn(),
|
|
100
101
|
};
|
|
101
102
|
setPermissionControl(control as unknown as PermissionControl);
|
|
102
|
-
|
|
103
|
+
registerSpec(pi, { register: (def: never) => gates.push(def as never) } as unknown as GateHub, {
|
|
103
104
|
agentDir,
|
|
104
105
|
openBrowser,
|
|
105
106
|
portStart: 46_000 + Math.floor(Math.random() * 1000),
|
|
@@ -132,35 +133,56 @@ async function decide(url: string, action: "approve" | "deny"): Promise<number>
|
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
describe("ask-
|
|
136
|
-
it("enters
|
|
136
|
+
describe("ask-spec command", () => {
|
|
137
|
+
it("enters spec mode: permission on, submit tool active, kickoff sent", async () => {
|
|
137
138
|
const h = harness();
|
|
138
|
-
const command = h.commands.get(
|
|
139
|
+
const command = h.commands.get(SPEC_COMMAND);
|
|
139
140
|
expect(command).toBeDefined();
|
|
140
|
-
await command!.handler("ask-
|
|
141
|
+
await command!.handler("ask-spec work", h.ctx);
|
|
141
142
|
|
|
142
143
|
expect(h.control.enableDefaults).toHaveBeenCalledWith(h.ctx);
|
|
143
|
-
expect(h.activeTools()).toContain(
|
|
144
|
-
expect(h.sendUserMessage).toHaveBeenCalledWith(expect.stringContaining("Task: ask-
|
|
145
|
-
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");
|
|
146
168
|
});
|
|
147
169
|
|
|
148
170
|
it("refuses to start twice and can be turned off", async () => {
|
|
149
171
|
const h = harness();
|
|
150
|
-
const handler = h.commands.get(
|
|
172
|
+
const handler = h.commands.get(SPEC_COMMAND)!.handler;
|
|
151
173
|
await handler("topic", h.ctx);
|
|
152
174
|
await handler("topic", h.ctx);
|
|
153
|
-
expect(h.notify).toHaveBeenLastCalledWith(expect.stringContaining("already
|
|
175
|
+
expect(h.notify).toHaveBeenLastCalledWith(expect.stringContaining("already reviewing a spec"), "warning");
|
|
154
176
|
|
|
155
177
|
await handler("off", h.ctx);
|
|
156
178
|
expect(h.control.restore).toHaveBeenCalled();
|
|
157
|
-
expect(h.activeTools()).not.toContain(
|
|
179
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
158
180
|
});
|
|
159
181
|
|
|
160
182
|
it("refuses to start while ask-uat is open", async () => {
|
|
161
183
|
const h = harness();
|
|
162
184
|
h.pi.setActiveTools([...h.activeTools(), "uat_item"]);
|
|
163
|
-
await h.commands.get(
|
|
185
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
164
186
|
expect(h.sendUserMessage).not.toHaveBeenCalled();
|
|
165
187
|
expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("ask-uat"), "warning");
|
|
166
188
|
});
|
|
@@ -168,7 +190,7 @@ describe("ask-plan command", () => {
|
|
|
168
190
|
it("refuses to start while the agent is still running", async () => {
|
|
169
191
|
const h = harness();
|
|
170
192
|
const busy = { ...h.ctx, isIdle: () => false } as ExtensionContext;
|
|
171
|
-
await h.commands.get(
|
|
193
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", busy);
|
|
172
194
|
expect(h.sendUserMessage).not.toHaveBeenCalled();
|
|
173
195
|
expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("still running"), "warning");
|
|
174
196
|
});
|
|
@@ -194,7 +216,7 @@ describe("ask-plan command", () => {
|
|
|
194
216
|
|
|
195
217
|
const h = harness();
|
|
196
218
|
const linkedCtx = { ...h.ctx, cwd: linked } as ExtensionContext;
|
|
197
|
-
const handler = h.commands.get(
|
|
219
|
+
const handler = h.commands.get(SPEC_COMMAND)!.handler;
|
|
198
220
|
await handler("topic", linkedCtx);
|
|
199
221
|
expect(h.notify).not.toHaveBeenCalledWith(
|
|
200
222
|
expect.stringContaining("no complete agent framework"),
|
|
@@ -209,16 +231,28 @@ describe("ask-plan command", () => {
|
|
|
209
231
|
});
|
|
210
232
|
|
|
211
233
|
describe("phase integration", () => {
|
|
212
|
-
it("exits ask mode before enabling the broader
|
|
234
|
+
it("exits ask mode before enabling the broader spec-review tool surface", async () => {
|
|
213
235
|
const h = harness();
|
|
214
236
|
const exit = vi.fn();
|
|
215
237
|
setAskControl({ isActive: () => true, exit });
|
|
216
|
-
await h.commands.get(
|
|
238
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
217
239
|
expect(exit).toHaveBeenCalledWith(h.ctx);
|
|
218
|
-
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);
|
|
219
253
|
});
|
|
220
254
|
|
|
221
|
-
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 () => {
|
|
222
256
|
const h = harness();
|
|
223
257
|
const off = { enabled: false, modes: { inRead: "allow", inWrite: "allow", outRead: "allow", outWrite: "ask" } };
|
|
224
258
|
const defaults = { enabled: true, modes: { inRead: "allow", inWrite: "allow", outRead: "allow", outWrite: "ask" } };
|
|
@@ -227,53 +261,53 @@ describe("phase integration", () => {
|
|
|
227
261
|
.mockReturnValueOnce(off as never)
|
|
228
262
|
.mockReturnValueOnce(defaults as never)
|
|
229
263
|
.mockReturnValueOnce(manual as never);
|
|
230
|
-
const handler = h.commands.get(
|
|
264
|
+
const handler = h.commands.get(SPEC_COMMAND)!.handler;
|
|
231
265
|
await handler("topic", h.ctx);
|
|
232
266
|
await handler("off", h.ctx);
|
|
233
267
|
expect(h.control.restore).not.toHaveBeenCalled();
|
|
234
268
|
expect(h.control.disable).not.toHaveBeenCalled();
|
|
235
269
|
});
|
|
236
270
|
|
|
237
|
-
it("starts a fresh review session for the next
|
|
271
|
+
it("starts a fresh review session for the next spec after leaving", async () => {
|
|
238
272
|
const h = harness();
|
|
239
|
-
const handler = h.commands.get(
|
|
273
|
+
const handler = h.commands.get(SPEC_COMMAND)!.handler;
|
|
240
274
|
await handler("first", h.ctx);
|
|
241
275
|
writeSpec("specs/first.md", "# SPEC: first");
|
|
242
|
-
const first = await h.tools.get(
|
|
276
|
+
const first = await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/first.md" });
|
|
243
277
|
expect(first.content[0].text).toContain("Submitted v1 of 1");
|
|
244
278
|
await handler("off", h.ctx);
|
|
245
279
|
await handler("second", h.ctx);
|
|
246
280
|
writeSpec("specs/second.md", "# SPEC: second");
|
|
247
|
-
const second = await h.tools.get(
|
|
281
|
+
const second = await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/second.md" });
|
|
248
282
|
expect(second.content[0].text).toContain("Submitted v1 of 1");
|
|
249
283
|
expect(h.openBrowser).toHaveBeenCalledTimes(2);
|
|
250
284
|
});
|
|
251
285
|
|
|
252
|
-
it("drops
|
|
286
|
+
it("drops spec state and closes the review when the pi session changes", async () => {
|
|
253
287
|
const h = harness();
|
|
254
|
-
await h.commands.get(
|
|
288
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
255
289
|
writeSpec("specs/topic.md", "# SPEC: topic");
|
|
256
|
-
await h.tools.get(
|
|
290
|
+
await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
|
|
257
291
|
const nextCtx = {
|
|
258
292
|
...h.ctx,
|
|
259
293
|
sessionManager: { getSessionId: () => "next-session" },
|
|
260
294
|
} as unknown as ExtensionContext;
|
|
261
295
|
h.handlers.session_start![0]!({ systemPrompt: "" }, nextCtx);
|
|
262
|
-
expect(h.activeTools()).not.toContain(
|
|
296
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
263
297
|
expect(h.control.restore).not.toHaveBeenCalled();
|
|
264
298
|
});
|
|
265
299
|
});
|
|
266
300
|
|
|
267
|
-
describe("
|
|
268
|
-
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");
|
|
269
303
|
|
|
270
|
-
it("blocks writing anything but markdown while
|
|
304
|
+
it("blocks writing anything but markdown while reviewing", async () => {
|
|
271
305
|
const h = harness();
|
|
272
306
|
const evaluate = gate(h)!.evaluate;
|
|
273
307
|
const write = (path: string): ToolCallEvent => ({ toolName: "write", input: { path } }) as unknown as ToolCallEvent;
|
|
274
308
|
|
|
275
309
|
expect(evaluate(write("src/features/x.ts"))).toBeUndefined();
|
|
276
|
-
await h.commands.get(
|
|
310
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
277
311
|
expect(evaluate(write("src/features/x.ts"))).toMatchObject({ kind: "block" });
|
|
278
312
|
expect(evaluate(write("specs/topic.md"))).toBeUndefined();
|
|
279
313
|
expect(evaluate(write("/tmp/outside.md"))).toMatchObject({ kind: "block" });
|
|
@@ -282,19 +316,19 @@ describe("plan gate", () => {
|
|
|
282
316
|
expect(evaluate(write("linked/escape.md"))).toMatchObject({ kind: "block" });
|
|
283
317
|
});
|
|
284
318
|
|
|
285
|
-
it("stays out of the way when
|
|
319
|
+
it("stays out of the way when spec mode is off", () => {
|
|
286
320
|
const h = harness();
|
|
287
321
|
const event = { toolName: "edit", input: { path: "src/a.ts" } } as unknown as ToolCallEvent;
|
|
288
322
|
expect(gate(h)!.evaluate(event)).toBeUndefined();
|
|
289
323
|
});
|
|
290
324
|
});
|
|
291
325
|
|
|
292
|
-
describe("
|
|
326
|
+
describe("spec_submit", () => {
|
|
293
327
|
it("reads the file, snapshots a revision and opens the review once", async () => {
|
|
294
328
|
const h = harness();
|
|
295
|
-
await h.commands.get(
|
|
329
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
296
330
|
writeSpec("specs/topic.md", "# SPEC: topic\n\nfirst step");
|
|
297
|
-
const tool = h.tools.get(
|
|
331
|
+
const tool = h.tools.get(SPEC_SUBMIT_TOOL)!;
|
|
298
332
|
|
|
299
333
|
const first = await tool.execute("id", { path: "specs/topic.md" });
|
|
300
334
|
expect(first.content[0].text).toContain("Submitted v1 of 1");
|
|
@@ -308,53 +342,53 @@ describe("plan_submit", () => {
|
|
|
308
342
|
|
|
309
343
|
it("tells the model to write the file when it does not exist", async () => {
|
|
310
344
|
const h = harness();
|
|
311
|
-
await h.commands.get(
|
|
312
|
-
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" });
|
|
313
347
|
expect(result.content[0].text).toContain("Write the spec file first");
|
|
314
348
|
});
|
|
315
349
|
|
|
316
350
|
it("refuses to submit non-markdown or out-of-workspace files", async () => {
|
|
317
351
|
const h = harness();
|
|
318
|
-
await h.commands.get(
|
|
319
|
-
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)!;
|
|
320
354
|
expect((await tool.execute("id", { path: "src/a.ts" })).content[0].text).toContain("inside the workspace");
|
|
321
355
|
expect((await tool.execute("id", { path: "/tmp/outside.md" })).content[0].text).toContain("inside the workspace");
|
|
322
356
|
});
|
|
323
357
|
|
|
324
|
-
it("refuses to submit outside
|
|
358
|
+
it("refuses to submit outside spec mode", async () => {
|
|
325
359
|
const h = harness();
|
|
326
|
-
const result = await h.tools.get(
|
|
327
|
-
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");
|
|
328
362
|
});
|
|
329
363
|
|
|
330
364
|
it("turns an approval into a message and leaves the phase", async () => {
|
|
331
365
|
const h = harness();
|
|
332
|
-
await h.commands.get(
|
|
366
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
333
367
|
writeSpec("specs/topic.md", "# SPEC: topic\n\nfirst step");
|
|
334
|
-
await h.tools.get(
|
|
368
|
+
await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
|
|
335
369
|
const url = h.openBrowser.mock.calls[0][0] as string;
|
|
336
370
|
|
|
337
371
|
expect(await decide(url, "approve")).toBe(200);
|
|
338
372
|
await vi.waitFor(() => expect(h.sendUserMessage).toHaveBeenCalledTimes(2), { timeout: 5000 });
|
|
339
373
|
const message = h.sendUserMessage.mock.calls[1][0] as string;
|
|
340
|
-
expect(message).toContain("##
|
|
374
|
+
expect(message).toContain("## Spec approved");
|
|
341
375
|
expect(message).toContain("start implementing");
|
|
342
376
|
// The approved revision is quoted back (the file may have changed since
|
|
343
377
|
// the submit), and the model is told to track the work in the todo list.
|
|
344
|
-
expect(message).toContain("### Approved
|
|
378
|
+
expect(message).toContain("### Approved spec (specs/topic.md)");
|
|
345
379
|
expect(message).toContain("# SPEC: topic\n\nfirst step");
|
|
346
380
|
expect(message).toContain("Record the implementation work in the todo list");
|
|
347
381
|
expect(message).not.toContain("call `record_change`");
|
|
348
382
|
expect(h.control.restore).toHaveBeenCalled();
|
|
349
|
-
expect(h.activeTools()).not.toContain(
|
|
383
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
350
384
|
});
|
|
351
385
|
|
|
352
|
-
it("drops a browser decision that arrives after
|
|
386
|
+
it("drops a browser decision that arrives after spec mode was closed", async () => {
|
|
353
387
|
const h = harness();
|
|
354
|
-
const handler = h.commands.get(
|
|
388
|
+
const handler = h.commands.get(SPEC_COMMAND)!.handler;
|
|
355
389
|
await handler("topic", h.ctx);
|
|
356
390
|
writeSpec("specs/topic.md", "# SPEC: topic");
|
|
357
|
-
await h.tools.get(
|
|
391
|
+
await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
|
|
358
392
|
const url = h.openBrowser.mock.calls[0][0] as string;
|
|
359
393
|
expect(await decide(url, "deny")).toBe(200);
|
|
360
394
|
await handler("off", h.ctx);
|
|
@@ -363,19 +397,19 @@ describe("plan_submit", () => {
|
|
|
363
397
|
expect(h.sendUserMessage).toHaveBeenCalledTimes(1);
|
|
364
398
|
});
|
|
365
399
|
|
|
366
|
-
it("turns a denial into feedback but keeps
|
|
400
|
+
it("turns a denial into feedback but keeps reviewing", async () => {
|
|
367
401
|
const h = harness();
|
|
368
|
-
await h.commands.get(
|
|
402
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
369
403
|
writeSpec("specs/topic.md", "# SPEC: topic\n\nfirst step");
|
|
370
|
-
await h.tools.get(
|
|
404
|
+
await h.tools.get(SPEC_SUBMIT_TOOL)!.execute("id", { path: "specs/topic.md" });
|
|
371
405
|
const url = h.openBrowser.mock.calls[0][0] as string;
|
|
372
406
|
|
|
373
407
|
expect(await decide(url, "deny")).toBe(200);
|
|
374
408
|
await vi.waitFor(() => expect(h.sendUserMessage).toHaveBeenCalledTimes(2), { timeout: 5000 });
|
|
375
409
|
const message = h.sendUserMessage.mock.calls[1][0] as string;
|
|
376
|
-
expect(message).toContain("##
|
|
410
|
+
expect(message).toContain("## Spec feedback");
|
|
377
411
|
expect(message).toContain("No specific annotations were left");
|
|
378
|
-
expect(h.activeTools()).toContain(
|
|
412
|
+
expect(h.activeTools()).toContain(SPEC_SUBMIT_TOOL);
|
|
379
413
|
expect(h.control.restore).not.toHaveBeenCalled();
|
|
380
414
|
});
|
|
381
415
|
});
|
|
@@ -387,22 +421,22 @@ describe("prompt injection", () => {
|
|
|
387
421
|
return handler!({ systemPrompt: prompt });
|
|
388
422
|
};
|
|
389
423
|
|
|
390
|
-
it("appends the
|
|
424
|
+
it("appends the spec framework only while reviewing", async () => {
|
|
391
425
|
const h = harness();
|
|
392
426
|
expect(start(h, "base")).toBeUndefined();
|
|
393
|
-
await h.commands.get(
|
|
427
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
394
428
|
const injected = start(h, "base");
|
|
395
429
|
expect(injected?.systemPrompt).toContain("base");
|
|
396
|
-
expect(injected?.systemPrompt).toContain("[ASK-
|
|
397
|
-
expect(injected?.systemPrompt).toContain("
|
|
398
|
-
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]");
|
|
399
433
|
expect(injected?.systemPrompt).toContain("ask in plain text");
|
|
400
434
|
});
|
|
401
435
|
|
|
402
436
|
it("names the question tool only when it is active", async () => {
|
|
403
437
|
const h = harness();
|
|
404
438
|
h.pi.setActiveTools([...h.activeTools(), "ask_user_question"]);
|
|
405
|
-
await h.commands.get(
|
|
439
|
+
await h.commands.get(SPEC_COMMAND)!.handler("topic", h.ctx);
|
|
406
440
|
const injected = start(h, "base");
|
|
407
441
|
expect(injected?.systemPrompt).toContain("`ask_user_question` is available");
|
|
408
442
|
});
|
|
@@ -411,8 +445,8 @@ describe("prompt injection", () => {
|
|
|
411
445
|
describe("plan write boundary", () => {
|
|
412
446
|
it("blocks a bash write to a non-markdown project path", async () => {
|
|
413
447
|
const h = harness();
|
|
414
|
-
await h.commands.get(
|
|
415
|
-
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");
|
|
416
450
|
expect(gate).toBeDefined();
|
|
417
451
|
const evaluate = (command: string) =>
|
|
418
452
|
gate!.evaluate({ toolName: "bash", input: { command } } as ToolCallEvent);
|
|
@@ -427,7 +461,7 @@ describe("plan write boundary", () => {
|
|
|
427
461
|
|
|
428
462
|
describe("model policy", () => {
|
|
429
463
|
it("contains no model-switching call in production code", () => {
|
|
430
|
-
const root = join(process.cwd(), "src", "features", "
|
|
464
|
+
const root = join(process.cwd(), "src", "features", "spec");
|
|
431
465
|
for (const file of readdirSync(root)) {
|
|
432
466
|
if (!file.endsWith(".ts") || file.endsWith(".test.ts")) continue;
|
|
433
467
|
expect(readFileSync(join(root, file), "utf8"), file).not.toContain("setModel");
|