gsd-pi 2.74.0-dev.703eabc → 2.74.0-dev.ffbcc03
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/dist/resources/extensions/gsd/auto-recovery.js +24 -10
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +16 -5
- package/dist/resources/extensions/gsd/cache.js +16 -5
- package/dist/resources/extensions/gsd/guided-flow.js +1 -1
- package/dist/resources/extensions/gsd/safety/evidence-collector.js +15 -30
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +14 -14
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +14 -14
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/package.json +1 -1
- package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
- package/packages/mcp-server/dist/workflow-tools.js +88 -6
- package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
- package/packages/mcp-server/src/workflow-tools.ts +95 -10
- package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +8 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +17 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +17 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +17 -0
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +19 -0
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/src/resources/extensions/gsd/auto-recovery.ts +29 -9
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +16 -5
- package/src/resources/extensions/gsd/cache.ts +16 -5
- package/src/resources/extensions/gsd/guided-flow.ts +1 -1
- package/src/resources/extensions/gsd/safety/evidence-collector.ts +15 -31
- package/src/resources/extensions/gsd/tests/artifacts-table-preserved-on-cache-invalidate.test.ts +177 -0
- package/src/resources/extensions/gsd/tests/auto-retry-mcp-churn-fixes.test.ts +272 -0
- /package/dist/web/standalone/.next/static/{3U-oZ5FT59BM7sm2GInic → kn6xzWKYnogsxp2b6RpDD}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{3U-oZ5FT59BM7sm2GInic → kn6xzWKYnogsxp2b6RpDD}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for PR #4288 — auto-retry bug, .mcp.json churn, and MCP
|
|
3
|
+
* worktree routing fixes.
|
|
4
|
+
*
|
|
5
|
+
* Covers four source-file changes:
|
|
6
|
+
* 1. src/resources/extensions/gsd/safety/evidence-collector.ts (functional)
|
|
7
|
+
* 2. src/resources/extensions/gsd/bootstrap/register-hooks.ts (source shape)
|
|
8
|
+
* 3. src/resources/extensions/gsd/auto-recovery.ts (source shape)
|
|
9
|
+
* 4. packages/mcp-server/src/workflow-tools.ts (source shape)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, it, beforeEach } from "node:test";
|
|
15
|
+
import assert from "node:assert/strict";
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
import { resolve } from "node:path";
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
resetEvidence,
|
|
21
|
+
getEvidence,
|
|
22
|
+
recordToolCall,
|
|
23
|
+
recordToolResult,
|
|
24
|
+
type BashEvidence,
|
|
25
|
+
} from "../safety/evidence-collector.js";
|
|
26
|
+
|
|
27
|
+
// ─── 1. evidence-collector: functional ─────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
describe("evidence-collector: toolCallId-based matching (A-3)", () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
resetEvidence();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("records bash calls with their toolCallId at dispatch time", () => {
|
|
35
|
+
recordToolCall("tc-1", "bash", { command: "ls -la" });
|
|
36
|
+
recordToolCall("tc-2", "bash", { command: "git status" });
|
|
37
|
+
|
|
38
|
+
const entries = getEvidence();
|
|
39
|
+
assert.equal(entries.length, 2);
|
|
40
|
+
assert.equal(entries[0].toolCallId, "tc-1");
|
|
41
|
+
assert.equal(entries[1].toolCallId, "tc-2");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("matches results to the correct entry by toolCallId, not insertion order", () => {
|
|
45
|
+
// Simulate two parallel bash calls dispatched in order tc-1, tc-2.
|
|
46
|
+
recordToolCall("tc-1", "bash", { command: "slow-thing" });
|
|
47
|
+
recordToolCall("tc-2", "bash", { command: "fast-thing" });
|
|
48
|
+
|
|
49
|
+
// Results arrive out of order: tc-2 first (fast), then tc-1 (slow).
|
|
50
|
+
// With the old empty-string-matching strategy, tc-2's result would be
|
|
51
|
+
// stapled to tc-1's entry because findLastUnresolved scanned backwards
|
|
52
|
+
// for empty ids. Now we match by id directly.
|
|
53
|
+
recordToolResult("tc-2", "bash", "Command exited with code 0\nfast-output", false);
|
|
54
|
+
recordToolResult("tc-1", "bash", "Command exited with code 1\nslow-failure", true);
|
|
55
|
+
|
|
56
|
+
const entries = getEvidence() as readonly BashEvidence[];
|
|
57
|
+
const tc1 = entries.find(e => e.toolCallId === "tc-1") as BashEvidence | undefined;
|
|
58
|
+
const tc2 = entries.find(e => e.toolCallId === "tc-2") as BashEvidence | undefined;
|
|
59
|
+
|
|
60
|
+
assert.ok(tc1, "tc-1 entry must exist");
|
|
61
|
+
assert.ok(tc2, "tc-2 entry must exist");
|
|
62
|
+
|
|
63
|
+
// The original command stays attached to the entry it was recorded with,
|
|
64
|
+
// and the result matches the id it was reported for.
|
|
65
|
+
assert.equal(tc1.command, "slow-thing");
|
|
66
|
+
assert.equal(tc1.exitCode, 1);
|
|
67
|
+
assert.ok(tc1.outputSnippet.includes("slow-failure"));
|
|
68
|
+
|
|
69
|
+
assert.equal(tc2.command, "fast-thing");
|
|
70
|
+
assert.equal(tc2.exitCode, 0);
|
|
71
|
+
assert.ok(tc2.outputSnippet.includes("fast-output"));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("ignores results with unknown toolCallIds rather than corrupting nearby entries", () => {
|
|
75
|
+
recordToolCall("tc-1", "bash", { command: "real" });
|
|
76
|
+
recordToolResult("tc-UNKNOWN", "bash", "Command exited with code 0\n", false);
|
|
77
|
+
|
|
78
|
+
const entries = getEvidence() as readonly BashEvidence[];
|
|
79
|
+
assert.equal(entries.length, 1);
|
|
80
|
+
assert.equal(entries[0].toolCallId, "tc-1");
|
|
81
|
+
// tc-1 must be untouched — no result was reported for it.
|
|
82
|
+
assert.equal(entries[0].exitCode, -1);
|
|
83
|
+
assert.equal(entries[0].outputSnippet, "");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("records write/edit entries with their toolCallId", () => {
|
|
87
|
+
recordToolCall("tc-write", "write", { file_path: "/tmp/a.md" });
|
|
88
|
+
recordToolCall("tc-edit", "edit", { file_path: "/tmp/b.md" });
|
|
89
|
+
|
|
90
|
+
const entries = getEvidence();
|
|
91
|
+
assert.equal(entries.length, 2);
|
|
92
|
+
assert.equal(entries[0].kind, "write");
|
|
93
|
+
assert.equal(entries[0].toolCallId, "tc-write");
|
|
94
|
+
assert.equal(entries[1].kind, "edit");
|
|
95
|
+
assert.equal(entries[1].toolCallId, "tc-edit");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// ─── 2. register-hooks: MCP auto-prep gated inside auto-worktrees (A-1) ────
|
|
100
|
+
|
|
101
|
+
describe("register-hooks: skip prepareWorkflowMcpForProject inside auto-worktrees (A-1)", () => {
|
|
102
|
+
const src = readFileSync(
|
|
103
|
+
resolve(process.cwd(), "src", "resources", "extensions", "gsd", "bootstrap", "register-hooks.ts"),
|
|
104
|
+
"utf-8",
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
it("session_start hook is gated on isInAutoWorktree", () => {
|
|
108
|
+
const idx = src.indexOf('pi.on("session_start"');
|
|
109
|
+
assert.ok(idx !== -1, "session_start handler must exist");
|
|
110
|
+
const block = src.slice(idx, idx + 2500);
|
|
111
|
+
assert.ok(
|
|
112
|
+
block.includes("isInAutoWorktree"),
|
|
113
|
+
"session_start must consult isInAutoWorktree before preparing MCP",
|
|
114
|
+
);
|
|
115
|
+
assert.ok(
|
|
116
|
+
block.includes("prepareWorkflowMcpForProject"),
|
|
117
|
+
"session_start still prepares MCP for non-worktree paths",
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("session_switch hook is gated on isInAutoWorktree", () => {
|
|
122
|
+
const idx = src.indexOf('pi.on("session_switch"');
|
|
123
|
+
assert.ok(idx !== -1, "session_switch handler must exist");
|
|
124
|
+
const block = src.slice(idx, idx + 2500);
|
|
125
|
+
assert.ok(
|
|
126
|
+
block.includes("isInAutoWorktree"),
|
|
127
|
+
"session_switch must consult isInAutoWorktree before preparing MCP",
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("tool_call hook forwards event.toolCallId into safetyRecordToolCall (A-3)", () => {
|
|
132
|
+
// Find the call site (skip the import line by looking for the opening paren).
|
|
133
|
+
const idx = src.indexOf("safetyRecordToolCall(");
|
|
134
|
+
assert.ok(idx !== -1, "safetyRecordToolCall call must exist");
|
|
135
|
+
const line = src.slice(idx, src.indexOf("\n", idx));
|
|
136
|
+
assert.ok(
|
|
137
|
+
line.includes("event.toolCallId"),
|
|
138
|
+
"safetyRecordToolCall must receive event.toolCallId as the first argument",
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// ─── 3. auto-recovery: verify-fail instrumentation ─────────────────────────
|
|
144
|
+
|
|
145
|
+
describe("verifyExpectedArtifact: verify-fail exit-point logging (Phase B diag)", () => {
|
|
146
|
+
const src = readFileSync(
|
|
147
|
+
resolve(process.cwd(), "src", "resources", "extensions", "gsd", "auto-recovery.ts"),
|
|
148
|
+
"utf-8",
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
it("logs a verify-fail warning on the null-absPath exit", () => {
|
|
152
|
+
assert.ok(
|
|
153
|
+
src.includes('verify-fail ${unitType} ${unitId}: resolveExpectedArtifactPath returned null'),
|
|
154
|
+
"null-absPath branch must emit a diagnostic line",
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("logs a verify-fail warning on the existsSync-false exit", () => {
|
|
159
|
+
assert.ok(
|
|
160
|
+
src.includes("verify-fail ${unitType} ${unitId}: existsSync false"),
|
|
161
|
+
"existsSync-false branch must emit a diagnostic line",
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("logs a verify-fail warning on the plan-slice no-task-entry exit", () => {
|
|
166
|
+
assert.ok(
|
|
167
|
+
src.includes("verify-fail ${unitType} ${unitId}: plan has no task checkbox/heading"),
|
|
168
|
+
"plan-slice no-task branch must emit a diagnostic line",
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("plan-slice task-plan-files check fails fast on missing tasks dir (hardening)", () => {
|
|
173
|
+
// The original check silently passed when resolveTasksDir returned null.
|
|
174
|
+
// The new check returns false with a diagnostic, which is correct — if
|
|
175
|
+
// the tool successfully planned tasks, the tasks/ dir must exist.
|
|
176
|
+
const idx = src.indexOf('verify-fail ${unitType} ${unitId}: resolveTasksDir returned null');
|
|
177
|
+
assert.ok(
|
|
178
|
+
idx !== -1,
|
|
179
|
+
"resolveTasksDir-null branch must emit a diagnostic and return false",
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// ─── 4. workflow-tools (mcp-server): guard + optional projectDir + routing ─
|
|
185
|
+
|
|
186
|
+
describe("mcp-server workflow-tools: projectDir routing (Phase B root cause)", () => {
|
|
187
|
+
const src = readFileSync(
|
|
188
|
+
resolve(process.cwd(), "packages", "mcp-server", "src", "workflow-tools.ts"),
|
|
189
|
+
"utf-8",
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
it("projectDirParam is optional and documents the default", () => {
|
|
193
|
+
const idx = src.indexOf("const projectDirParam");
|
|
194
|
+
assert.ok(idx !== -1, "projectDirParam definition must exist");
|
|
195
|
+
const block = src.slice(idx, idx + 600);
|
|
196
|
+
assert.ok(
|
|
197
|
+
block.includes(".optional()"),
|
|
198
|
+
"projectDirParam must be optional so the agent stops deliberating",
|
|
199
|
+
);
|
|
200
|
+
assert.ok(
|
|
201
|
+
/Omit this field/i.test(block),
|
|
202
|
+
"description must tell the agent to omit the field",
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("parseWorkflowArgs defaults projectDir to process.cwd() when omitted", () => {
|
|
207
|
+
const idx = src.indexOf("function parseWorkflowArgs");
|
|
208
|
+
assert.ok(idx !== -1, "parseWorkflowArgs must exist");
|
|
209
|
+
const block = src.slice(idx, idx + 1500);
|
|
210
|
+
assert.ok(
|
|
211
|
+
block.includes("parsed.projectDir ?? process.cwd()"),
|
|
212
|
+
"parseWorkflowArgs must fall back to process.cwd() when projectDir is omitted",
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("validateProjectDir accepts external-state worktree paths via .gsd symlink target", () => {
|
|
217
|
+
const idx = src.indexOf("function validateProjectDir");
|
|
218
|
+
assert.ok(idx !== -1, "validateProjectDir must exist");
|
|
219
|
+
const block = src.slice(idx, idx + 2500);
|
|
220
|
+
assert.ok(
|
|
221
|
+
block.includes("resolveExternalStateRoot"),
|
|
222
|
+
"validateProjectDir must consult resolveExternalStateRoot for external-state layouts",
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const helperIdx = src.indexOf("function resolveExternalStateRoot");
|
|
226
|
+
assert.ok(helperIdx !== -1, "resolveExternalStateRoot helper must exist");
|
|
227
|
+
const helperBlock = src.slice(helperIdx, helperIdx + 600);
|
|
228
|
+
assert.ok(
|
|
229
|
+
helperBlock.includes("realpathSync"),
|
|
230
|
+
"resolveExternalStateRoot must use realpathSync to follow the symlink",
|
|
231
|
+
);
|
|
232
|
+
assert.ok(
|
|
233
|
+
/join\([^)]*\.gsd/.test(helperBlock),
|
|
234
|
+
"resolveExternalStateRoot must resolve <allowedRoot>/.gsd",
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("parseWorkflowArgs routes tool writes to the active worktree when one exists", () => {
|
|
239
|
+
// This is the Phase B root-cause fix: when the tool call is scoped to a
|
|
240
|
+
// milestone that has an auto-worktree at <projectRoot>/.gsd/worktrees/<MID>/,
|
|
241
|
+
// tool writes must go to the worktree .gsd rather than the shared project .gsd.
|
|
242
|
+
const parseIdx = src.indexOf("function parseWorkflowArgs");
|
|
243
|
+
const parseBlock = src.slice(parseIdx, parseIdx + 2500);
|
|
244
|
+
assert.ok(
|
|
245
|
+
parseBlock.includes("resolveActiveWorktreeBasePath"),
|
|
246
|
+
"parseWorkflowArgs must consult resolveActiveWorktreeBasePath",
|
|
247
|
+
);
|
|
248
|
+
assert.ok(
|
|
249
|
+
parseBlock.includes("extractMilestoneId"),
|
|
250
|
+
"parseWorkflowArgs must extract the milestoneId to locate the worktree",
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("resolveActiveWorktreeBasePath checks .git presence to avoid hijacking stray directories", () => {
|
|
255
|
+
const idx = src.indexOf("function resolveActiveWorktreeBasePath");
|
|
256
|
+
assert.ok(idx !== -1, "resolveActiveWorktreeBasePath helper must exist");
|
|
257
|
+
const block = src.slice(idx, idx + 1200);
|
|
258
|
+
assert.ok(
|
|
259
|
+
block.includes('existsSync(join(wtPath, ".git"))'),
|
|
260
|
+
"resolveActiveWorktreeBasePath must verify a .git file exists in the worktree",
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("extractMilestoneId handles camelCase, snake_case, and short aliases", () => {
|
|
265
|
+
const idx = src.indexOf("function extractMilestoneId");
|
|
266
|
+
assert.ok(idx !== -1, "extractMilestoneId helper must exist");
|
|
267
|
+
const block = src.slice(idx, idx + 600);
|
|
268
|
+
assert.ok(block.includes("milestoneId"), "must check milestoneId");
|
|
269
|
+
assert.ok(block.includes("milestone_id"), "must check milestone_id");
|
|
270
|
+
assert.ok(block.includes("mid"), "must check mid");
|
|
271
|
+
});
|
|
272
|
+
});
|
|
File without changes
|
|
File without changes
|