gsd-pi 2.46.1 → 2.47.0
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/README.md +46 -29
- package/dist/resources/extensions/claude-code-cli/index.js +25 -0
- package/dist/resources/extensions/claude-code-cli/models.js +40 -0
- package/dist/resources/extensions/claude-code-cli/package.json +11 -0
- package/dist/resources/extensions/claude-code-cli/partial-builder.js +223 -0
- package/dist/resources/extensions/claude-code-cli/readiness.js +26 -0
- package/dist/resources/extensions/claude-code-cli/sdk-types.js +8 -0
- package/dist/resources/extensions/claude-code-cli/stream-adapter.js +309 -0
- package/dist/resources/extensions/gsd/auto-start.js +9 -8
- package/dist/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/guided-plan-milestone.md +2 -2
- package/dist/resources/extensions/gsd/prompts/plan-milestone.md +2 -2
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/research-milestone.md +2 -2
- package/dist/resources/extensions/gsd/prompts/run-uat.md +2 -2
- package/dist/resources/extensions/gsd/repo-identity.js +5 -2
- package/dist/resources/extensions/gsd/state.js +29 -2
- package/dist/resources/extensions/gsd/workflow-events.js +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +9 -9
- 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 +2 -2
- 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 +9 -9
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +2 -2
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/package.json +3 -1
- package/packages/pi-agent-core/dist/agent-loop.js +26 -1
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/dist/agent.d.ts +7 -0
- package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent.js +2 -0
- package/packages/pi-agent-core/dist/agent.js.map +1 -1
- package/packages/pi-agent-core/dist/types.d.ts +9 -0
- package/packages/pi-agent-core/dist/types.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/types.js.map +1 -1
- package/packages/pi-agent-core/src/agent-loop.ts +25 -1
- package/packages/pi-agent-core/src/agent.ts +10 -0
- package/packages/pi-agent-core/src/types.ts +10 -0
- package/packages/pi-coding-agent/dist/core/auth-storage.test.js +27 -2
- package/packages/pi-coding-agent/dist/core/auth-storage.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.js +1 -0
- package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/core/auth-storage.test.ts +27 -2
- package/packages/pi-coding-agent/src/core/sdk.ts +1 -0
- package/pkg/package.json +1 -1
- package/src/resources/extensions/claude-code-cli/index.ts +28 -0
- package/src/resources/extensions/claude-code-cli/models.ts +42 -0
- package/src/resources/extensions/claude-code-cli/package.json +11 -0
- package/src/resources/extensions/claude-code-cli/partial-builder.ts +258 -0
- package/src/resources/extensions/claude-code-cli/readiness.ts +30 -0
- package/src/resources/extensions/claude-code-cli/sdk-types.ts +149 -0
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +370 -0
- package/src/resources/extensions/gsd/auto-start.ts +8 -7
- package/src/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/guided-plan-milestone.md +2 -2
- package/src/resources/extensions/gsd/prompts/plan-milestone.md +2 -2
- package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/research-milestone.md +2 -2
- package/src/resources/extensions/gsd/prompts/run-uat.md +2 -2
- package/src/resources/extensions/gsd/repo-identity.ts +5 -2
- package/src/resources/extensions/gsd/state.ts +33 -1
- package/src/resources/extensions/gsd/tests/inherited-repo-home-dir.test.ts +70 -0
- package/src/resources/extensions/gsd/tests/plan-slice-prompt.test.ts +40 -0
- package/src/resources/extensions/gsd/tests/run-uat.test.ts +25 -0
- package/src/resources/extensions/gsd/workflow-events.ts +1 -1
- /package/dist/web/standalone/.next/static/{P4nF4UcdATjrbNMBH_Ulh → VPcLnRF4BL8VoJEilBwlB}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{P4nF4UcdATjrbNMBH_Ulh → VPcLnRF4BL8VoJEilBwlB}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream adapter: bridges the Claude Agent SDK into GSD's streamSimple contract.
|
|
3
|
+
*
|
|
4
|
+
* The SDK runs the full agentic loop (multi-turn, tool execution, compaction)
|
|
5
|
+
* in one call. This adapter translates the SDK's streaming output into
|
|
6
|
+
* AssistantMessageEvents for TUI rendering, then strips tool-call blocks from
|
|
7
|
+
* the final AssistantMessage so GSD's agent loop doesn't try to dispatch them.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
AssistantMessage,
|
|
12
|
+
AssistantMessageEvent,
|
|
13
|
+
AssistantMessageEventStream,
|
|
14
|
+
Context,
|
|
15
|
+
Model,
|
|
16
|
+
SimpleStreamOptions,
|
|
17
|
+
} from "@gsd/pi-ai";
|
|
18
|
+
import { EventStream } from "@gsd/pi-ai";
|
|
19
|
+
import { execSync } from "node:child_process";
|
|
20
|
+
import { PartialMessageBuilder, ZERO_USAGE, mapUsage } from "./partial-builder.js";
|
|
21
|
+
import type {
|
|
22
|
+
SDKAssistantMessage,
|
|
23
|
+
SDKMessage,
|
|
24
|
+
SDKPartialAssistantMessage,
|
|
25
|
+
SDKResultMessage,
|
|
26
|
+
SDKSystemMessage,
|
|
27
|
+
SDKStatusMessage,
|
|
28
|
+
SDKUserMessage,
|
|
29
|
+
} from "./sdk-types.js";
|
|
30
|
+
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Stream factory
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Construct an AssistantMessageEventStream using EventStream directly.
|
|
37
|
+
* (The class itself is only re-exported as a type from the @gsd/pi-ai barrel.)
|
|
38
|
+
*/
|
|
39
|
+
function createAssistantStream(): AssistantMessageEventStream {
|
|
40
|
+
return new EventStream<AssistantMessageEvent, AssistantMessage>(
|
|
41
|
+
(event) => event.type === "done" || event.type === "error",
|
|
42
|
+
(event) => {
|
|
43
|
+
if (event.type === "done") return event.message;
|
|
44
|
+
if (event.type === "error") return event.error;
|
|
45
|
+
throw new Error("Unexpected event type for final result");
|
|
46
|
+
},
|
|
47
|
+
) as AssistantMessageEventStream;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Claude binary resolution
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
let cachedClaudePath: string | null = null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resolve the path to the system-installed `claude` binary.
|
|
58
|
+
* The SDK defaults to a bundled cli.js which doesn't exist when
|
|
59
|
+
* installed as a library — we need to point it at the real CLI.
|
|
60
|
+
*/
|
|
61
|
+
function getClaudePath(): string {
|
|
62
|
+
if (cachedClaudePath) return cachedClaudePath;
|
|
63
|
+
try {
|
|
64
|
+
cachedClaudePath = execSync("which claude", { timeout: 5_000, stdio: "pipe" })
|
|
65
|
+
.toString()
|
|
66
|
+
.trim();
|
|
67
|
+
} catch {
|
|
68
|
+
cachedClaudePath = "claude"; // fall back to PATH resolution
|
|
69
|
+
}
|
|
70
|
+
return cachedClaudePath;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Prompt extraction
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Extract the last user prompt text from GSD's context messages.
|
|
79
|
+
* The SDK manages its own conversation history — we only send
|
|
80
|
+
* the latest user message as the prompt.
|
|
81
|
+
*/
|
|
82
|
+
function extractLastUserPrompt(context: Context): string {
|
|
83
|
+
for (let i = context.messages.length - 1; i >= 0; i--) {
|
|
84
|
+
const msg = context.messages[i];
|
|
85
|
+
if (msg.role === "user") {
|
|
86
|
+
if (typeof msg.content === "string") return msg.content;
|
|
87
|
+
if (Array.isArray(msg.content)) {
|
|
88
|
+
const textParts = msg.content
|
|
89
|
+
.filter((part: any) => part.type === "text")
|
|
90
|
+
.map((part: any) => part.text);
|
|
91
|
+
if (textParts.length > 0) return textParts.join("\n");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// Error helper
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
function makeErrorMessage(model: string, errorMsg: string): AssistantMessage {
|
|
103
|
+
return {
|
|
104
|
+
role: "assistant",
|
|
105
|
+
content: [{ type: "text", text: `Claude Code error: ${errorMsg}` }],
|
|
106
|
+
api: "anthropic-messages",
|
|
107
|
+
provider: "claude-code",
|
|
108
|
+
model,
|
|
109
|
+
usage: { ...ZERO_USAGE },
|
|
110
|
+
stopReason: "error",
|
|
111
|
+
errorMessage: errorMsg,
|
|
112
|
+
timestamp: Date.now(),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// streamSimple implementation
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* GSD streamSimple function that delegates to the Claude Agent SDK.
|
|
122
|
+
*
|
|
123
|
+
* Emits AssistantMessageEvent deltas for real-time TUI rendering
|
|
124
|
+
* (thinking, text, tool calls). The final AssistantMessage has tool-call
|
|
125
|
+
* blocks stripped so the agent loop ends the turn without local dispatch.
|
|
126
|
+
*/
|
|
127
|
+
export function streamViaClaudeCode(
|
|
128
|
+
model: Model<any>,
|
|
129
|
+
context: Context,
|
|
130
|
+
options?: SimpleStreamOptions,
|
|
131
|
+
): AssistantMessageEventStream {
|
|
132
|
+
const stream = createAssistantStream();
|
|
133
|
+
|
|
134
|
+
void pumpSdkMessages(model, context, options, stream);
|
|
135
|
+
|
|
136
|
+
return stream;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function pumpSdkMessages(
|
|
140
|
+
model: Model<any>,
|
|
141
|
+
context: Context,
|
|
142
|
+
options: SimpleStreamOptions | undefined,
|
|
143
|
+
stream: AssistantMessageEventStream,
|
|
144
|
+
): Promise<void> {
|
|
145
|
+
const modelId = model.id;
|
|
146
|
+
let builder: PartialMessageBuilder | null = null;
|
|
147
|
+
/** Track the last text content seen across all assistant turns for the final message. */
|
|
148
|
+
let lastTextContent = "";
|
|
149
|
+
let lastThinkingContent = "";
|
|
150
|
+
/** Collect tool calls from intermediate SDK turns for tool_execution events. */
|
|
151
|
+
const intermediateToolCalls: AssistantMessage["content"] = [];
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
// Dynamic import — the SDK is an optional dependency.
|
|
155
|
+
const sdkModule = "@anthropic-ai/claude-agent-sdk";
|
|
156
|
+
const sdk = (await import(/* webpackIgnore: true */ sdkModule)) as {
|
|
157
|
+
query: (args: {
|
|
158
|
+
prompt: string | AsyncIterable<unknown>;
|
|
159
|
+
options?: Record<string, unknown>;
|
|
160
|
+
}) => AsyncIterable<SDKMessage>;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Bridge GSD's AbortSignal to SDK's AbortController
|
|
164
|
+
const controller = new AbortController();
|
|
165
|
+
if (options?.signal) {
|
|
166
|
+
options.signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const prompt = extractLastUserPrompt(context);
|
|
170
|
+
|
|
171
|
+
const queryResult = sdk.query({
|
|
172
|
+
prompt,
|
|
173
|
+
options: {
|
|
174
|
+
pathToClaudeCodeExecutable: getClaudePath(),
|
|
175
|
+
model: modelId,
|
|
176
|
+
includePartialMessages: true,
|
|
177
|
+
persistSession: false,
|
|
178
|
+
abortController: controller,
|
|
179
|
+
cwd: process.cwd(),
|
|
180
|
+
permissionMode: "bypassPermissions",
|
|
181
|
+
allowDangerouslySkipPermissions: true,
|
|
182
|
+
settingSources: ["project"],
|
|
183
|
+
systemPrompt: { type: "preset", preset: "claude_code" },
|
|
184
|
+
betas: modelId.includes("sonnet") ? ["context-1m-2025-08-07"] : [],
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Emit start with an empty partial
|
|
189
|
+
const initialPartial: AssistantMessage = {
|
|
190
|
+
role: "assistant",
|
|
191
|
+
content: [],
|
|
192
|
+
api: "anthropic-messages",
|
|
193
|
+
provider: "claude-code",
|
|
194
|
+
model: modelId,
|
|
195
|
+
usage: { ...ZERO_USAGE },
|
|
196
|
+
stopReason: "stop",
|
|
197
|
+
timestamp: Date.now(),
|
|
198
|
+
};
|
|
199
|
+
stream.push({ type: "start", partial: initialPartial });
|
|
200
|
+
|
|
201
|
+
for await (const msg of queryResult as AsyncIterable<SDKMessage>) {
|
|
202
|
+
if (options?.signal?.aborted) break;
|
|
203
|
+
|
|
204
|
+
switch (msg.type) {
|
|
205
|
+
// -- Init --
|
|
206
|
+
case "system": {
|
|
207
|
+
// Nothing to emit — the stream is already started.
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// -- Streaming partial messages --
|
|
212
|
+
case "stream_event": {
|
|
213
|
+
const partial = msg as SDKPartialAssistantMessage;
|
|
214
|
+
if (partial.parent_tool_use_id !== null) break; // skip subagent
|
|
215
|
+
|
|
216
|
+
const event = partial.event;
|
|
217
|
+
|
|
218
|
+
// New assistant turn starts with message_start
|
|
219
|
+
if (event.type === "message_start") {
|
|
220
|
+
builder = new PartialMessageBuilder(
|
|
221
|
+
(event as any).message?.model ?? modelId,
|
|
222
|
+
);
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (!builder) break;
|
|
227
|
+
|
|
228
|
+
const assistantEvent = builder.handleEvent(event);
|
|
229
|
+
if (assistantEvent) {
|
|
230
|
+
// Skip toolcall events — the agent loop's externalToolExecution
|
|
231
|
+
// path emits tool_execution_start/end events after streamSimple
|
|
232
|
+
// returns. Streaming toolcall events would render tool calls
|
|
233
|
+
// out of order in the TUI's accumulated message content.
|
|
234
|
+
const t = assistantEvent.type;
|
|
235
|
+
if (t !== "toolcall_start" && t !== "toolcall_delta" && t !== "toolcall_end") {
|
|
236
|
+
stream.push(assistantEvent);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// -- Complete assistant message (non-streaming fallback) --
|
|
243
|
+
case "assistant": {
|
|
244
|
+
const sdkAssistant = msg as SDKAssistantMessage;
|
|
245
|
+
if (sdkAssistant.parent_tool_use_id !== null) break;
|
|
246
|
+
|
|
247
|
+
// Capture text content from complete messages
|
|
248
|
+
for (const block of sdkAssistant.message.content) {
|
|
249
|
+
if (block.type === "text") {
|
|
250
|
+
lastTextContent = block.text;
|
|
251
|
+
} else if (block.type === "thinking") {
|
|
252
|
+
lastThinkingContent = block.thinking;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// -- User message (synthetic tool result — signals turn boundary) --
|
|
259
|
+
case "user": {
|
|
260
|
+
const userMsg = msg as SDKUserMessage;
|
|
261
|
+
if (userMsg.parent_tool_use_id !== null) break;
|
|
262
|
+
|
|
263
|
+
// Capture content from the completed turn before resetting
|
|
264
|
+
if (builder) {
|
|
265
|
+
for (const block of builder.message.content) {
|
|
266
|
+
if (block.type === "text" && block.text) {
|
|
267
|
+
lastTextContent = block.text;
|
|
268
|
+
} else if (block.type === "thinking" && block.thinking) {
|
|
269
|
+
lastThinkingContent = block.thinking;
|
|
270
|
+
} else if (block.type === "toolCall") {
|
|
271
|
+
// Collect tool calls for externalToolExecution rendering
|
|
272
|
+
intermediateToolCalls.push(block);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
builder = null;
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// -- Result (terminal) --
|
|
281
|
+
case "result": {
|
|
282
|
+
const result = msg as SDKResultMessage;
|
|
283
|
+
|
|
284
|
+
// Build final message. Include intermediate tool calls so the
|
|
285
|
+
// agent loop's externalToolExecution path emits tool_execution
|
|
286
|
+
// events for proper TUI rendering, followed by the text response.
|
|
287
|
+
const finalContent: AssistantMessage["content"] = [];
|
|
288
|
+
|
|
289
|
+
// Add tool calls from intermediate turns first (renders above text)
|
|
290
|
+
finalContent.push(...intermediateToolCalls);
|
|
291
|
+
|
|
292
|
+
// Add text/thinking from the last turn
|
|
293
|
+
if (builder && builder.message.content.length > 0) {
|
|
294
|
+
for (const block of builder.message.content) {
|
|
295
|
+
if (block.type === "text" || block.type === "thinking") {
|
|
296
|
+
finalContent.push(block);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
if (lastThinkingContent) {
|
|
301
|
+
finalContent.push({ type: "thinking", thinking: lastThinkingContent });
|
|
302
|
+
}
|
|
303
|
+
if (lastTextContent) {
|
|
304
|
+
finalContent.push({ type: "text", text: lastTextContent });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Fallback: use the SDK's result text if we have no content
|
|
309
|
+
if (finalContent.length === 0 && result.subtype === "success" && result.result) {
|
|
310
|
+
finalContent.push({ type: "text", text: result.result });
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const finalMessage: AssistantMessage = {
|
|
314
|
+
role: "assistant",
|
|
315
|
+
content: finalContent,
|
|
316
|
+
api: "anthropic-messages",
|
|
317
|
+
provider: "claude-code",
|
|
318
|
+
model: modelId,
|
|
319
|
+
usage: mapUsage(result.usage, result.total_cost_usd),
|
|
320
|
+
stopReason: result.is_error ? "error" : "stop",
|
|
321
|
+
timestamp: Date.now(),
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
if (result.is_error) {
|
|
325
|
+
const errText =
|
|
326
|
+
"errors" in result
|
|
327
|
+
? (result as any).errors?.join("; ")
|
|
328
|
+
: result.subtype;
|
|
329
|
+
finalMessage.errorMessage = errText;
|
|
330
|
+
stream.push({ type: "error", reason: "error", error: finalMessage });
|
|
331
|
+
} else {
|
|
332
|
+
stream.push({ type: "done", reason: "stop", message: finalMessage });
|
|
333
|
+
}
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
default:
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Generator exhausted without a result message (unexpected)
|
|
343
|
+
const fallbackContent: AssistantMessage["content"] = [];
|
|
344
|
+
if (lastTextContent) {
|
|
345
|
+
fallbackContent.push({ type: "text", text: lastTextContent });
|
|
346
|
+
}
|
|
347
|
+
if (fallbackContent.length === 0) {
|
|
348
|
+
fallbackContent.push({ type: "text", text: "(Claude Code session ended without a response)" });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const fallback: AssistantMessage = {
|
|
352
|
+
role: "assistant",
|
|
353
|
+
content: fallbackContent,
|
|
354
|
+
api: "anthropic-messages",
|
|
355
|
+
provider: "claude-code",
|
|
356
|
+
model: modelId,
|
|
357
|
+
usage: { ...ZERO_USAGE },
|
|
358
|
+
stopReason: "stop",
|
|
359
|
+
timestamp: Date.now(),
|
|
360
|
+
};
|
|
361
|
+
stream.push({ type: "done", reason: "stop", message: fallback });
|
|
362
|
+
} catch (err) {
|
|
363
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
364
|
+
stream.push({
|
|
365
|
+
type: "error",
|
|
366
|
+
reason: "error",
|
|
367
|
+
error: makeErrorMessage(modelId, errorMsg),
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
@@ -140,13 +140,14 @@ export async function bootstrapAutoSession(
|
|
|
140
140
|
return releaseLockAndReturn();
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
// Ensure git repo exists.
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
|
|
143
|
+
// Ensure git repo exists *locally* at base.
|
|
144
|
+
// nativeIsRepo() uses `git rev-parse` which traverses up to parent dirs,
|
|
145
|
+
// so a parent repo can make it return true even when base has no .git of
|
|
146
|
+
// its own. Check for a local .git instead (defense-in-depth for the case
|
|
147
|
+
// where isInheritedRepo() returns a false negative, e.g. stale .gsd at
|
|
148
|
+
// the parent git root). See #2393 and related issue.
|
|
149
|
+
const hasLocalGit = existsSync(join(base, ".git"));
|
|
150
|
+
if (!hasLocalGit || isInheritedRepo(base)) {
|
|
150
151
|
const mainBranch =
|
|
151
152
|
loadEffectiveGSDPreferences()?.preferences?.git?.main_branch || "main";
|
|
152
153
|
nativeInit(base, mainBranch);
|
|
@@ -32,6 +32,6 @@ Then:
|
|
|
32
32
|
11. Do not run git commands — the system commits your changes and handles any merge after this unit succeeds.
|
|
33
33
|
12. Update `.gsd/PROJECT.md` if it exists — refresh current state if needed.
|
|
34
34
|
|
|
35
|
-
**You MUST
|
|
35
|
+
**You MUST call `gsd_complete_slice` with the slice summary and UAT content before finishing. The tool persists to both DB and disk and renders `{{sliceSummaryPath}}` and `{{sliceUatPath}}` automatically.**
|
|
36
36
|
|
|
37
37
|
When done, say: "Slice {{sliceId}} complete."
|
|
@@ -10,10 +10,10 @@ Plan milestone {{milestoneId}} ("{{milestoneTitle}}"). Read `.gsd/DECISIONS.md`
|
|
|
10
10
|
## Planning Doctrine
|
|
11
11
|
|
|
12
12
|
- **Risk-first means proof-first.** The earliest slices should prove the hardest thing works by shipping the real feature through the uncertain path. If auth is the risk, the first slice ships a real login page with real session handling that a user can actually use — not a CLI command that returns "authenticated: true". Proof is the shipped feature working. There is no separate "proof" artifact. Do not plan spikes, proof-of-concept slices, or validation-only slices — the proof is the real feature, built through the risky path.
|
|
13
|
-
- **Every slice is vertical, demoable, and shippable.** Every slice ships real, user-facing functionality. "Demoable" means
|
|
13
|
+
- **Every slice is vertical, demoable, and shippable.** Every slice ships real, user-facing functionality. "Demoable" means the intended user can exercise the capability through its real interface — for a web app that's the UI, for a CLI tool that's the terminal, for an API that's a consuming client or curl. The test is: can someone *use* it, not just *assert* it passes. A slice that only proves something but doesn't ship real working code is not a slice — restructure it.
|
|
14
14
|
- **Brownfield bias.** When planning against an existing codebase, ground slices in existing modules, conventions, and seams. Prefer extending real patterns over inventing new ones.
|
|
15
15
|
- **Each slice should establish something downstream slices can depend on.** Think about what stable surface this slice creates for later work — an API, a data shape, a proven integration path.
|
|
16
|
-
- **Avoid foundation-only slices.** If a slice doesn't produce something demoable end-to-end, it's probably a layer, not a vertical slice. Restructure it.
|
|
16
|
+
- **Avoid foundation-only slices.** If a slice doesn't produce something demoable end-to-end, it's probably a layer, not a vertical slice. Restructure it. Exception: if the infrastructure *is* the product surface (a new protocol, extension API, or provider interface), the slice is vertical by definition — the downstream consumer is the demo.
|
|
17
17
|
- **Verification-first.** When planning slices, know what "done" looks like before detailing implementation. Each slice's demo line should describe concrete, verifiable evidence — not vague "it works" claims.
|
|
18
18
|
- **Plan for integrated reality, not just local proof.** Distinguish contract proof from live integration proof. If the milestone involves multiple runtime boundaries, one slice must explicitly prove the assembled system through the real entrypoint or runtime path.
|
|
19
19
|
- **Truthful demo lines only.** If a slice is proven by fixtures or tests only, say so. Do not phrase harness-level proof as if the user can already perform the live end-to-end behavior unless that has actually been exercised.
|
|
@@ -64,10 +64,10 @@ Then:
|
|
|
64
64
|
Apply these when decomposing and ordering slices:
|
|
65
65
|
|
|
66
66
|
- **Risk-first means proof-first.** The earliest slices should prove the hardest thing works by shipping the real feature through the uncertain path. If auth is the risk, the first slice ships a real login page with real session handling that a user can actually use — not a CLI command that returns "authenticated: true". Proof is the shipped feature working. There is no separate "proof" artifact. Do not plan spikes, proof-of-concept slices, or validation-only slices — the proof is the real feature, built through the risky path.
|
|
67
|
-
- **Every slice is vertical, demoable, and shippable.** Every slice ships real, user-facing functionality. "Demoable" means
|
|
67
|
+
- **Every slice is vertical, demoable, and shippable.** Every slice ships real, user-facing functionality. "Demoable" means the intended user can exercise the capability through its real interface — for a web app that's the UI, for a CLI tool that's the terminal, for an API that's a consuming client or curl. The test is: can someone *use* it, not just *assert* it passes. A slice that only proves something but doesn't ship real working code is not a slice — restructure it.
|
|
68
68
|
- **Brownfield bias.** When planning against an existing codebase, ground slices in existing modules, conventions, and seams. Prefer extending real patterns over inventing new ones.
|
|
69
69
|
- **Each slice should establish something downstream slices can depend on.** Think about what stable surface this slice creates for later work — an API, a data shape, a proven integration path.
|
|
70
|
-
- **Avoid foundation-only slices.** If a slice doesn't produce something demoable end-to-end, it's probably a layer, not a vertical slice. Restructure it.
|
|
70
|
+
- **Avoid foundation-only slices.** If a slice doesn't produce something demoable end-to-end, it's probably a layer, not a vertical slice. Restructure it. Exception: if the infrastructure *is* the product surface (a new protocol, extension API, or provider interface), the slice is vertical by definition — the downstream consumer is the demo.
|
|
71
71
|
- **Verification-first.** When planning slices, know what "done" looks like before detailing implementation. Each slice's demo line should describe concrete, verifiable evidence — not vague "it works" claims.
|
|
72
72
|
- **Plan for integrated reality, not just local proof.** Distinguish contract proof from live integration proof. If the milestone involves multiple runtime boundaries, one slice must explicitly prove the assembled system through the real entrypoint or runtime path.
|
|
73
73
|
- **Truthful demo lines only.** If a slice is proven by fixtures or tests only, say so. Do not phrase harness-level proof as if the user can already perform the live end-to-end behavior unless that has actually been exercised.
|
|
@@ -77,6 +77,6 @@ Then:
|
|
|
77
77
|
|
|
78
78
|
The slice directory and tasks/ subdirectory already exist. Do NOT mkdir. All work stays in your working directory: `{{workingDirectory}}`.
|
|
79
79
|
|
|
80
|
-
**You MUST
|
|
80
|
+
**You MUST call `gsd_plan_slice` to persist the planning state before finishing.**
|
|
81
81
|
|
|
82
82
|
When done, say: "Slice {{sliceId}} planned."
|
|
@@ -28,7 +28,7 @@ Then research the codebase and relevant technologies. Narrate key findings and s
|
|
|
28
28
|
5. **Web search budget:** You have a limited budget of web searches (max ~15 per session). Use them strategically — prefer `resolve_library` / `get_library_docs` for library documentation. Do NOT repeat the same or similar queries. If a search didn't find what you need, rephrase once or move on. Target 3-5 total web searches for a typical research unit.
|
|
29
29
|
6. Use the **Research** output template from the inlined context above — include only sections that have real content
|
|
30
30
|
7. If `.gsd/REQUIREMENTS.md` exists, research against it. Identify which Active requirements are table stakes, likely omissions, overbuilt risks, or domain-standard behaviors the user may or may not want.
|
|
31
|
-
8.
|
|
31
|
+
8. Call `gsd_summary_save` with `milestone_id: {{milestoneId}}`, `artifact_type: "RESEARCH"`, and the full research markdown as `content` — the tool computes the file path and persists to both DB and disk.
|
|
32
32
|
|
|
33
33
|
## Strategic Questions to Answer
|
|
34
34
|
|
|
@@ -42,6 +42,6 @@ Then research the codebase and relevant technologies. Narrate key findings and s
|
|
|
42
42
|
|
|
43
43
|
**Research is advisory, not auto-binding.** Surface candidate requirements clearly instead of silently expanding scope.
|
|
44
44
|
|
|
45
|
-
**You MUST
|
|
45
|
+
**You MUST call `gsd_summary_save` with the research content before finishing.**
|
|
46
46
|
|
|
47
47
|
When done, say: "Milestone {{milestoneId}} researched."
|
|
@@ -55,7 +55,7 @@ After running all checks, compute the **overall verdict**:
|
|
|
55
55
|
- `FAIL` — one or more checks failed
|
|
56
56
|
- `PARTIAL` — some checks passed, but one or more checks were skipped, inconclusive, or still require human judgment
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
Call `gsd_summary_save` with `milestone_id: {{milestoneId}}`, `slice_id: {{sliceId}}`, `artifact_type: "ASSESSMENT"`, and the full UAT result markdown as `content` — the tool computes the file path and persists to both DB and disk. The content should follow this format:
|
|
59
59
|
|
|
60
60
|
```markdown
|
|
61
61
|
---
|
|
@@ -84,6 +84,6 @@ date: <ISO 8601 timestamp>
|
|
|
84
84
|
|
|
85
85
|
---
|
|
86
86
|
|
|
87
|
-
**You MUST
|
|
87
|
+
**You MUST call `gsd_summary_save` with the UAT result content before finishing.**
|
|
88
88
|
|
|
89
89
|
When done, say: "UAT {{sliceId}} complete."
|
|
@@ -127,8 +127,11 @@ export function isInheritedRepo(basePath: string): boolean {
|
|
|
127
127
|
// (i.e. the parent project was initialised with GSD).
|
|
128
128
|
if (isProjectGsd(join(root, ".gsd"))) return false;
|
|
129
129
|
|
|
130
|
-
//
|
|
131
|
-
|
|
130
|
+
// Walk up from basePath's parent to the git root checking for .gsd.
|
|
131
|
+
// Start at dirname(normalizedBase), NOT normalizedBase itself — finding
|
|
132
|
+
// .gsd at basePath means GSD state is set up for THIS project, which
|
|
133
|
+
// says nothing about whether the git repo is inherited from an ancestor.
|
|
134
|
+
let dir = dirname(normalizedBase);
|
|
132
135
|
while (dir !== normalizedRoot && dir !== dirname(dir)) {
|
|
133
136
|
if (isProjectGsd(join(dir, ".gsd"))) return false;
|
|
134
137
|
dir = dirname(dir);
|
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
getReplanHistory,
|
|
50
50
|
getSlice,
|
|
51
51
|
insertMilestone,
|
|
52
|
+
updateTaskStatus,
|
|
52
53
|
type MilestoneRow,
|
|
53
54
|
type SliceRow,
|
|
54
55
|
type TaskRow,
|
|
@@ -629,7 +630,38 @@ export async function deriveStateFromDb(basePath: string): Promise<GSDState> {
|
|
|
629
630
|
}
|
|
630
631
|
|
|
631
632
|
// ── Get tasks from DB ────────────────────────────────────────────────
|
|
632
|
-
|
|
633
|
+
let tasks = getSliceTasks(activeMilestone.id, activeSlice.id);
|
|
634
|
+
|
|
635
|
+
// ── Reconcile stale task status (#2514) ──────────────────────────────
|
|
636
|
+
// When a session disconnects after the agent writes SUMMARY + VERIFY
|
|
637
|
+
// artifacts but before postUnitPostVerification updates the DB, tasks
|
|
638
|
+
// remain "pending" in the DB despite being complete on disk. Without
|
|
639
|
+
// reconciliation, deriveState keeps returning the stale task as active,
|
|
640
|
+
// causing the dispatcher to re-dispatch the same completed task forever.
|
|
641
|
+
let reconciled = false;
|
|
642
|
+
for (const t of tasks) {
|
|
643
|
+
if (isStatusDone(t.status)) continue;
|
|
644
|
+
const summaryPath = resolveTaskFile(basePath, activeMilestone.id, activeSlice.id, t.id, "SUMMARY");
|
|
645
|
+
if (summaryPath && existsSync(summaryPath)) {
|
|
646
|
+
try {
|
|
647
|
+
updateTaskStatus(activeMilestone.id, activeSlice.id, t.id, "complete");
|
|
648
|
+
process.stderr.write(
|
|
649
|
+
`gsd-reconcile: task ${activeMilestone.id}/${activeSlice.id}/${t.id} had SUMMARY on disk but DB status was "${t.status}" — updated to "complete" (#2514)\n`,
|
|
650
|
+
);
|
|
651
|
+
reconciled = true;
|
|
652
|
+
} catch (e) {
|
|
653
|
+
// DB write failed — continue with stale status rather than crash
|
|
654
|
+
process.stderr.write(
|
|
655
|
+
`gsd-reconcile: failed to update task ${t.id}: ${(e as Error).message}\n`,
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
// Re-fetch tasks if any were reconciled so downstream logic sees fresh status
|
|
661
|
+
if (reconciled) {
|
|
662
|
+
tasks = getSliceTasks(activeMilestone.id, activeSlice.id);
|
|
663
|
+
}
|
|
664
|
+
|
|
633
665
|
const taskProgress = {
|
|
634
666
|
done: tasks.filter(t => isStatusDone(t.status)).length,
|
|
635
667
|
total: tasks.length,
|
|
@@ -119,3 +119,73 @@ describe("isInheritedRepo when git root is HOME (#2393)", () => {
|
|
|
119
119
|
);
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
|
+
|
|
123
|
+
describe("isInheritedRepo with stale .gsd at parent git root", () => {
|
|
124
|
+
let parentRepo: string;
|
|
125
|
+
|
|
126
|
+
beforeEach(() => {
|
|
127
|
+
parentRepo = realpathSync(mkdtempSync(join(tmpdir(), "gsd-stale-parent-")));
|
|
128
|
+
run("git", ["init", "-b", "main"], parentRepo);
|
|
129
|
+
run("git", ["config", "user.name", "Test"], parentRepo);
|
|
130
|
+
run("git", ["config", "user.email", "test@example.com"], parentRepo);
|
|
131
|
+
writeFileSync(join(parentRepo, "README.md"), "# Parent\n", "utf-8");
|
|
132
|
+
run("git", ["add", "README.md"], parentRepo);
|
|
133
|
+
run("git", ["commit", "-m", "init"], parentRepo);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
afterEach(() => {
|
|
137
|
+
rmSync(parentRepo, { recursive: true, force: true });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("stale .gsd dir at parent git root does not suppress inherited detection", () => {
|
|
141
|
+
// Simulate a stale .gsd directory at the parent git root (e.g. from a
|
|
142
|
+
// prior doctor run or accidental init). This is a real directory, NOT
|
|
143
|
+
// a symlink, and NOT the global GSD home.
|
|
144
|
+
mkdirSync(join(parentRepo, ".gsd"), { recursive: true });
|
|
145
|
+
|
|
146
|
+
const projectDir = join(parentRepo, "my-project");
|
|
147
|
+
mkdirSync(projectDir, { recursive: true });
|
|
148
|
+
|
|
149
|
+
// Without fix: isProjectGsd(join(root, ".gsd")) returns true because
|
|
150
|
+
// the stale .gsd is a real directory that isn't the global GSD home,
|
|
151
|
+
// causing isInheritedRepo to return false (false negative).
|
|
152
|
+
//
|
|
153
|
+
// The stale .gsd at parent is still treated as a "project .gsd" by
|
|
154
|
+
// isProjectGsd(), so the git root check at line 128 returns false.
|
|
155
|
+
// This is the expected behavior for that check — the defense-in-depth
|
|
156
|
+
// fix in auto-start.ts handles this case by checking for local .git.
|
|
157
|
+
//
|
|
158
|
+
// Verify the function behavior is consistent:
|
|
159
|
+
assert.strictEqual(
|
|
160
|
+
isInheritedRepo(projectDir),
|
|
161
|
+
false,
|
|
162
|
+
"stale .gsd dir at git root still causes isInheritedRepo to return false " +
|
|
163
|
+
"(defense-in-depth in auto-start.ts handles this case)",
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("basePath's own .gsd symlink does not suppress inherited detection", () => {
|
|
168
|
+
// Create a project subdir with its own .gsd symlink (set up during
|
|
169
|
+
// the discuss phase, before auto-mode bootstrap runs).
|
|
170
|
+
const projectDir = join(parentRepo, "my-project");
|
|
171
|
+
mkdirSync(projectDir, { recursive: true });
|
|
172
|
+
|
|
173
|
+
const externalState = mkdtempSync(join(tmpdir(), "gsd-ext-state-"));
|
|
174
|
+
symlinkSync(externalState, join(projectDir, ".gsd"));
|
|
175
|
+
|
|
176
|
+
// Before fix: the walk-up loop started at normalizedBase (projectDir),
|
|
177
|
+
// found .gsd at projectDir, and returned false — even though projectDir
|
|
178
|
+
// has no .git of its own. The .gsd at basePath is irrelevant to whether
|
|
179
|
+
// the git repo is inherited from a parent.
|
|
180
|
+
//
|
|
181
|
+
// After fix: the walk-up starts at dirname(normalizedBase), skipping
|
|
182
|
+
// basePath's own .gsd.
|
|
183
|
+
assert.strictEqual(
|
|
184
|
+
isInheritedRepo(projectDir),
|
|
185
|
+
true,
|
|
186
|
+
"project's own .gsd symlink must not suppress inherited repo detection",
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
rmSync(externalState, { recursive: true, force: true });
|
|
190
|
+
});
|
|
191
|
+
});
|