@andares/pi-toolkits 1.0.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 +10 -0
- package/README.md +21 -20
- package/README.zh-CN.md +23 -22
- package/package.json +5 -4
- package/src/features/ask/index.test.ts +2 -2
- package/src/features/ask/index.ts +1 -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/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
|
@@ -22,15 +22,15 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
22
22
|
},
|
|
23
23
|
],
|
|
24
24
|
});
|
|
25
|
-
expect(text).toContain("##
|
|
26
|
-
expect(text).toContain("### Global notes (apply to the whole
|
|
25
|
+
expect(text).toContain("## Spec feedback — v2 of 5 (no block changes)");
|
|
26
|
+
expect(text).toContain("### Global notes (apply to the whole spec)");
|
|
27
27
|
expect(text).toContain("- [change] Keep the permission toggle out of the plan flow.");
|
|
28
28
|
expect(text).toContain("### Block notes (apply to the quoted block only)");
|
|
29
29
|
expect(text).toContain("#### line 3 · 1. blocks (unchanged)");
|
|
30
30
|
expect(text).toContain("> 1. blocks");
|
|
31
31
|
expect(text).toContain("- [question] What stops a third round here?");
|
|
32
32
|
expect(text).toContain(
|
|
33
|
-
"Update the
|
|
33
|
+
"Update the spec file to address every annotation above, then submit it again with spec_submit.",
|
|
34
34
|
);
|
|
35
35
|
});
|
|
36
36
|
|
|
@@ -52,14 +52,14 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
52
52
|
},
|
|
53
53
|
],
|
|
54
54
|
});
|
|
55
|
-
expect(text).toContain("##
|
|
55
|
+
expect(text).toContain("## Spec feedback — v3 of 5 (1 block changed)");
|
|
56
56
|
expect(text).toContain("#### line 3 · 1. blocks, then the server (modified)");
|
|
57
57
|
expect(text).toContain("> 1. blocks, then the server");
|
|
58
58
|
expect(text).toContain("- [change] Split it in two.");
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it("keeps an approval short when there is nothing to say", () => {
|
|
62
|
-
const blocks = parse("##
|
|
62
|
+
const blocks = parse("## Spec");
|
|
63
63
|
const text = buildFeedbackMarkdown({
|
|
64
64
|
decision: "approve",
|
|
65
65
|
version: 3,
|
|
@@ -71,11 +71,11 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
71
71
|
});
|
|
72
72
|
expect(text).toBe(
|
|
73
73
|
[
|
|
74
|
-
"##
|
|
74
|
+
"## Spec approved — v3 of 3 (no block changes)",
|
|
75
75
|
"",
|
|
76
76
|
"No notes were attached.",
|
|
77
77
|
"",
|
|
78
|
-
"The
|
|
78
|
+
"The spec is approved: start implementing it now.",
|
|
79
79
|
'Approval only means "go" — every annotation above still applies while you build.',
|
|
80
80
|
"Record the implementation work in the todo list (`todo` tool) as you go, and update each entry",
|
|
81
81
|
"as it starts, finishes or gets blocked, so progress stays traceable.",
|
|
@@ -84,7 +84,7 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
it("quotes the approved revision and asks for todo tracking on approval", () => {
|
|
87
|
-
const blocks = parse("##
|
|
87
|
+
const blocks = parse("## Spec\n\nstep one");
|
|
88
88
|
const text = buildFeedbackMarkdown({
|
|
89
89
|
decision: "approve",
|
|
90
90
|
version: 2,
|
|
@@ -93,17 +93,17 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
93
93
|
diff: diffBlocks(blocks, blocks),
|
|
94
94
|
global: [{ verdict: "suggest", comment: "Keep commits small." }],
|
|
95
95
|
perBlock: [],
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
specPath: "specs/demo.md",
|
|
97
|
+
specText: "## Spec\n\nstep one\n",
|
|
98
98
|
});
|
|
99
|
-
expect(text).toContain("### Approved
|
|
100
|
-
expect(text).toContain("##
|
|
99
|
+
expect(text).toContain("### Approved spec (specs/demo.md)");
|
|
100
|
+
expect(text).toContain("## Spec\n\nstep one");
|
|
101
101
|
expect(text).toContain("Record the implementation work in the todo list");
|
|
102
102
|
expect(text).toContain("- [suggest] Keep commits small.");
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
it("does not quote a
|
|
106
|
-
const blocks = parse("##
|
|
105
|
+
it("does not quote a spec back on denial", () => {
|
|
106
|
+
const blocks = parse("## Spec");
|
|
107
107
|
const text = buildFeedbackMarkdown({
|
|
108
108
|
decision: "deny",
|
|
109
109
|
version: 1,
|
|
@@ -112,15 +112,15 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
112
112
|
diff: diffBlocks([], blocks),
|
|
113
113
|
global: [],
|
|
114
114
|
perBlock: [],
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
specPath: "specs/demo.md",
|
|
116
|
+
specText: "## Spec",
|
|
117
117
|
});
|
|
118
|
-
expect(text).not.toContain("### Approved
|
|
118
|
+
expect(text).not.toContain("### Approved spec");
|
|
119
119
|
expect(text).not.toContain("todo list");
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
it("keeps notes attached to an approval", () => {
|
|
123
|
-
const blocks = parse("##
|
|
123
|
+
const blocks = parse("## Spec");
|
|
124
124
|
const text = buildFeedbackMarkdown({
|
|
125
125
|
decision: "approve",
|
|
126
126
|
version: 1,
|
|
@@ -130,13 +130,13 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
130
130
|
global: [{ verdict: "suggest", comment: "Commit per milestone." }],
|
|
131
131
|
perBlock: [],
|
|
132
132
|
});
|
|
133
|
-
expect(text).toContain("##
|
|
133
|
+
expect(text).toContain("## Spec approved — v1 of 1 (1 block changed)");
|
|
134
134
|
expect(text).toContain("- [suggest] Commit per milestone.");
|
|
135
135
|
expect(text).toContain("Approval only means");
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
it("asks what should change when a denial carries no annotations", () => {
|
|
139
|
-
const blocks = parse("##
|
|
139
|
+
const blocks = parse("## Spec");
|
|
140
140
|
const text = buildFeedbackMarkdown({
|
|
141
141
|
decision: "deny",
|
|
142
142
|
version: 1,
|
|
@@ -152,7 +152,7 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
it("drops empty comments and annotations pointing at unknown blocks", () => {
|
|
155
|
-
const blocks = parse("##
|
|
155
|
+
const blocks = parse("## Spec");
|
|
156
156
|
const text = buildFeedbackMarkdown({
|
|
157
157
|
decision: "deny",
|
|
158
158
|
version: 1,
|
|
@@ -172,8 +172,8 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
172
172
|
});
|
|
173
173
|
|
|
174
174
|
it("keeps annotations on removed blocks", () => {
|
|
175
|
-
const before = parse("##
|
|
176
|
-
const after = parse("##
|
|
175
|
+
const before = parse("## Spec\n\nremove this step");
|
|
176
|
+
const after = parse("## Spec");
|
|
177
177
|
const text = buildFeedbackMarkdown({
|
|
178
178
|
decision: "deny",
|
|
179
179
|
version: 2,
|
|
@@ -195,8 +195,8 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
195
195
|
});
|
|
196
196
|
|
|
197
197
|
it("resolves an annotation keyed by the previous block id instead of dropping it", () => {
|
|
198
|
-
const before = parse("##
|
|
199
|
-
const after = parse("##
|
|
198
|
+
const before = parse("## Spec\n\nwrite the parser first");
|
|
199
|
+
const after = parse("## Spec\n\nwrite the block parser first");
|
|
200
200
|
const text = buildFeedbackMarkdown({
|
|
201
201
|
decision: "deny",
|
|
202
202
|
version: 2,
|
|
@@ -218,7 +218,7 @@ describe("buildFeedbackMarkdown", () => {
|
|
|
218
218
|
});
|
|
219
219
|
|
|
220
220
|
it("collapses multi-line comments onto one line", () => {
|
|
221
|
-
const blocks = parse("##
|
|
221
|
+
const blocks = parse("## Spec");
|
|
222
222
|
const text = buildFeedbackMarkdown({
|
|
223
223
|
decision: "deny",
|
|
224
224
|
version: 1,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* plan feedback — annotations → the message the agent receives.
|
|
3
3
|
*
|
|
4
4
|
* The template is deliberately fixed (and tested byte for byte): the agent
|
|
5
|
-
* reads it, not a human, so a stable shape is what lets the
|
|
5
|
+
* reads it, not a human, so a stable shape is what lets the spec prompt say
|
|
6
6
|
* "address every block marked (modified)" and have that mean something. It is
|
|
7
7
|
* English like every other runtime string.
|
|
8
8
|
*
|
|
@@ -38,9 +38,9 @@ export interface FeedbackInput {
|
|
|
38
38
|
global: readonly Annotation[];
|
|
39
39
|
perBlock: readonly BlockAnnotations[];
|
|
40
40
|
/** The spec file the operator approved (path shown to the model). */
|
|
41
|
-
|
|
41
|
+
specPath?: string;
|
|
42
42
|
/** Approved revision text, quoted back so the model implements exactly this. */
|
|
43
|
-
|
|
43
|
+
specText?: string;
|
|
44
44
|
/** Whether `record_change` is available in this project (framework installed). */
|
|
45
45
|
recordTool?: boolean;
|
|
46
46
|
}
|
|
@@ -77,7 +77,7 @@ function annotationLines(annotations: readonly Annotation[]): string[] {
|
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
/** Longest block excerpt quoted back — enough to locate it, not a second copy of the
|
|
80
|
+
/** Longest block excerpt quoted back — enough to locate it, not a second copy of the spec. */
|
|
81
81
|
const QUOTE_LIMIT = 600;
|
|
82
82
|
|
|
83
83
|
function quoteBlock(text: string): string {
|
|
@@ -99,7 +99,7 @@ function quoteBlock(text: string): string {
|
|
|
99
99
|
*/
|
|
100
100
|
export function buildFeedbackMarkdown(input: FeedbackInput): string {
|
|
101
101
|
const changed = countChanged(input.diff);
|
|
102
|
-
const header = `##
|
|
102
|
+
const header = `## Spec ${input.decision === "approve" ? "approved" : "feedback"} — v${input.version} of ${input.totalVersions} (${summarizeChanged(changed)})`;
|
|
103
103
|
const byId = new Map(input.blocks.map((block) => [block.id, block]));
|
|
104
104
|
const prevById = new Map((input.previousBlocks ?? []).map((block) => [block.id, block]));
|
|
105
105
|
const diffById = new Map(input.diff.map((entry) => [entry.id, entry]));
|
|
@@ -107,7 +107,7 @@ export function buildFeedbackMarkdown(input: FeedbackInput): string {
|
|
|
107
107
|
const sections: string[] = [];
|
|
108
108
|
const globalLines = annotationLines(input.global);
|
|
109
109
|
if (globalLines.length > 0) {
|
|
110
|
-
sections.push(["### Global notes (apply to the whole
|
|
110
|
+
sections.push(["### Global notes (apply to the whole spec)", ...globalLines].join("\n"));
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
// An annotation may arrive keyed by the block's PREVIOUS id (a tab that has
|
|
@@ -149,7 +149,7 @@ export function buildFeedbackMarkdown(input: FeedbackInput): string {
|
|
|
149
149
|
const instruction =
|
|
150
150
|
input.decision === "approve"
|
|
151
151
|
? [
|
|
152
|
-
"The
|
|
152
|
+
"The spec is approved: start implementing it now.",
|
|
153
153
|
"Approval only means \"go\" — every annotation above still applies while you build.",
|
|
154
154
|
"Record the implementation work in the todo list (`todo` tool) as you go, and update each entry",
|
|
155
155
|
"as it starts, finishes or gets blocked, so progress stays traceable.",
|
|
@@ -161,22 +161,22 @@ export function buildFeedbackMarkdown(input: FeedbackInput): string {
|
|
|
161
161
|
: []),
|
|
162
162
|
]
|
|
163
163
|
.join("\n")
|
|
164
|
-
: "Update the
|
|
164
|
+
: "Update the spec file to address every annotation above, then submit it again with spec_submit.";
|
|
165
165
|
|
|
166
|
-
// On approval the model must implement the
|
|
166
|
+
// On approval the model must implement the spec it was shown, not a stale
|
|
167
167
|
// recollection of it: the file may have been edited after the last submit, so
|
|
168
168
|
// quote the approved bytes back and name the path explicitly.
|
|
169
|
-
const
|
|
170
|
-
input.decision === "approve" && input.
|
|
169
|
+
const approvedSpec =
|
|
170
|
+
input.decision === "approve" && input.specText !== undefined
|
|
171
171
|
? [
|
|
172
|
-
`### Approved
|
|
172
|
+
`### Approved spec (${input.specPath ?? "the spec file"})`,
|
|
173
173
|
"",
|
|
174
|
-
input.
|
|
174
|
+
input.specText.trimEnd(),
|
|
175
175
|
]
|
|
176
176
|
.join("\n")
|
|
177
177
|
: undefined;
|
|
178
178
|
|
|
179
179
|
const parts = [header, "", body, "", instruction];
|
|
180
|
-
if (
|
|
180
|
+
if (approvedSpec) parts.push("", approvedSpec);
|
|
181
181
|
return parts.join("\n");
|
|
182
182
|
}
|
|
@@ -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");
|