gsd-pi 2.70.0-dev.55a1c68 → 2.70.0-dev.7ebda5e
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/loader.js +4 -0
- package/dist/resources/extensions/claude-code-cli/stream-adapter.js +150 -2
- package/dist/resources/extensions/gsd/auto-model-selection.js +33 -19
- package/dist/resources/extensions/gsd/auto-prompts.js +7 -3
- package/dist/resources/extensions/gsd/auto-start.js +25 -1
- package/dist/resources/extensions/gsd/auto.js +12 -8
- package/dist/resources/extensions/gsd/commands-handlers.js +22 -8
- package/dist/resources/extensions/gsd/doctor-engine-checks.js +12 -0
- package/dist/resources/extensions/gsd/doctor-format.js +2 -0
- package/dist/resources/extensions/gsd/guided-flow.js +21 -10
- package/dist/resources/extensions/gsd/pre-execution-checks.js +5 -3
- package/dist/resources/extensions/gsd/validate-directory.js +30 -12
- package/dist/resources/extensions/gsd/workflow-mcp.js +11 -0
- package/dist/resources/extensions/slash-commands/audit.js +2 -1
- package/dist/resources/extensions/subagent/isolation.js +4 -2
- package/dist/update-check.d.ts +1 -0
- package/dist/update-check.js +30 -27
- package/dist/update-cmd.js +3 -11
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +13 -13
- 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/required-server-files.json +1 -1
- 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/api/update/route.js +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 +13 -13
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- 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/dist/web/standalone/server.js +1 -1
- package/dist/web-mode.js +4 -0
- package/package.json +11 -11
- package/packages/mcp-server/dist/workflow-tools.d.ts +2 -0
- package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
- package/packages/mcp-server/dist/workflow-tools.js +35 -3
- package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
- package/packages/mcp-server/src/import-candidates.test.ts +48 -0
- package/packages/mcp-server/src/workflow-tools.ts +34 -1
- package/packages/pi-agent-core/dist/agent.d.ts +8 -0
- package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent.js +3 -0
- package/packages/pi-agent-core/dist/agent.js.map +1 -1
- package/packages/pi-agent-core/src/agent.test.ts +82 -0
- package/packages/pi-agent-core/src/agent.ts +12 -0
- package/packages/pi-coding-agent/dist/core/lsp/config.d.ts +1 -0
- package/packages/pi-coding-agent/dist/core/lsp/config.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/config.js +38 -15
- package/packages/pi-coding-agent/dist/core/lsp/config.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 +10 -0
- package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js +3 -1
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js.map +1 -1
- package/packages/pi-coding-agent/src/core/lsp/config.ts +43 -17
- package/packages/pi-coding-agent/src/core/sdk.ts +8 -0
- package/packages/pi-coding-agent/src/modes/interactive/slash-command-handlers.ts +7 -5
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +227 -2
- package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +172 -0
- package/src/resources/extensions/gsd/auto-model-selection.ts +39 -25
- package/src/resources/extensions/gsd/auto-prompts.ts +7 -3
- package/src/resources/extensions/gsd/auto-start.ts +34 -1
- package/src/resources/extensions/gsd/auto.ts +12 -8
- package/src/resources/extensions/gsd/commands-handlers.ts +22 -7
- package/src/resources/extensions/gsd/doctor-engine-checks.ts +14 -0
- package/src/resources/extensions/gsd/doctor-format.ts +1 -0
- package/src/resources/extensions/gsd/doctor-types.ts +1 -0
- package/src/resources/extensions/gsd/guided-flow.ts +24 -8
- package/src/resources/extensions/gsd/pre-execution-checks.ts +6 -3
- package/src/resources/extensions/gsd/tests/doctor-scope-db-unavailable.test.ts +43 -0
- package/src/resources/extensions/gsd/tests/interactive-routing-bypass.test.ts +207 -0
- package/src/resources/extensions/gsd/tests/pre-exec-backtick-strip.test.ts +48 -1
- package/src/resources/extensions/gsd/tests/resource-loader-import-path.test.ts +8 -7
- package/src/resources/extensions/gsd/tests/validate-directory.test.ts +33 -1
- package/src/resources/extensions/gsd/tests/validate-milestone.test.ts +87 -1
- package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +25 -0
- package/src/resources/extensions/gsd/validate-directory.ts +33 -11
- package/src/resources/extensions/gsd/workflow-mcp.ts +15 -0
- package/src/resources/extensions/slash-commands/audit.ts +2 -1
- package/src/resources/extensions/subagent/isolation.ts +4 -3
- /package/dist/web/standalone/.next/static/{0CnmwCBOy-QNRFzdWLB7Q → yvFbuOJuph5517lR7HBt2}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{0CnmwCBOy-QNRFzdWLB7Q → yvFbuOJuph5517lR7HBt2}/_ssgManifest.js +0 -0
|
@@ -16,10 +16,12 @@ import type {
|
|
|
16
16
|
SimpleStreamOptions,
|
|
17
17
|
ToolCall,
|
|
18
18
|
} from "@gsd/pi-ai";
|
|
19
|
+
import type { ExtensionUIContext } from "@gsd/pi-coding-agent";
|
|
19
20
|
import { EventStream } from "@gsd/pi-ai";
|
|
20
21
|
import { execSync } from "node:child_process";
|
|
21
22
|
import { PartialMessageBuilder, ZERO_USAGE, mapUsage } from "./partial-builder.js";
|
|
22
23
|
import { buildWorkflowMcpServers } from "../gsd/workflow-mcp.js";
|
|
24
|
+
import { showInterviewRound, type Question, type RoundResult } from "../shared/tui.js";
|
|
23
25
|
import type {
|
|
24
26
|
SDKAssistantMessage,
|
|
25
27
|
SDKMessage,
|
|
@@ -45,6 +47,46 @@ type ToolCallWithExternalResult = ToolCall & {
|
|
|
45
47
|
externalResult?: ExternalToolResultPayload;
|
|
46
48
|
};
|
|
47
49
|
|
|
50
|
+
interface ClaudeCodeStreamOptions extends SimpleStreamOptions {
|
|
51
|
+
extensionUIContext?: ExtensionUIContext;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface SdkElicitationRequestOption {
|
|
55
|
+
const?: string;
|
|
56
|
+
title?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface SdkElicitationFieldSchema {
|
|
60
|
+
type?: string;
|
|
61
|
+
title?: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
oneOf?: SdkElicitationRequestOption[];
|
|
64
|
+
items?: {
|
|
65
|
+
anyOf?: SdkElicitationRequestOption[];
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface SdkElicitationRequest {
|
|
70
|
+
serverName: string;
|
|
71
|
+
message: string;
|
|
72
|
+
mode?: "form" | "url";
|
|
73
|
+
requestedSchema?: {
|
|
74
|
+
type?: string;
|
|
75
|
+
properties?: Record<string, SdkElicitationFieldSchema>;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface SdkElicitationResult {
|
|
80
|
+
action: "accept" | "decline" | "cancel";
|
|
81
|
+
content?: Record<string, string | string[]>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface ParsedElicitationQuestion extends Question {
|
|
85
|
+
noteFieldId?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const OTHER_OPTION_LABEL = "None of the above";
|
|
89
|
+
|
|
48
90
|
// ---------------------------------------------------------------------------
|
|
49
91
|
// Stream factory
|
|
50
92
|
// ---------------------------------------------------------------------------
|
|
@@ -172,6 +214,174 @@ export function makeStreamExhaustedErrorMessage(model: string, lastTextContent:
|
|
|
172
214
|
return message;
|
|
173
215
|
}
|
|
174
216
|
|
|
217
|
+
function readElicitationChoices(options: SdkElicitationRequestOption[] | undefined): string[] {
|
|
218
|
+
if (!Array.isArray(options)) return [];
|
|
219
|
+
return options
|
|
220
|
+
.map((option) => (typeof option?.const === "string" ? option.const : typeof option?.title === "string" ? option.title : ""))
|
|
221
|
+
.filter((option): option is string => option.length > 0);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function parseAskUserQuestionsElicitation(
|
|
225
|
+
request: Pick<SdkElicitationRequest, "mode" | "requestedSchema">,
|
|
226
|
+
): ParsedElicitationQuestion[] | null {
|
|
227
|
+
if (request.mode && request.mode !== "form") return null;
|
|
228
|
+
const properties = request.requestedSchema?.properties;
|
|
229
|
+
if (!properties || typeof properties !== "object") return null;
|
|
230
|
+
|
|
231
|
+
const questions: ParsedElicitationQuestion[] = [];
|
|
232
|
+
|
|
233
|
+
for (const [fieldId, rawField] of Object.entries(properties)) {
|
|
234
|
+
if (fieldId.endsWith("__note")) continue;
|
|
235
|
+
if (!rawField || typeof rawField !== "object") return null;
|
|
236
|
+
|
|
237
|
+
const header = typeof rawField.title === "string" && rawField.title.length > 0 ? rawField.title : fieldId;
|
|
238
|
+
const question = typeof rawField.description === "string" ? rawField.description : "";
|
|
239
|
+
|
|
240
|
+
if (rawField.type === "array") {
|
|
241
|
+
const options = readElicitationChoices(rawField.items?.anyOf).map((label) => ({ label, description: "" }));
|
|
242
|
+
if (options.length === 0) return null;
|
|
243
|
+
questions.push({
|
|
244
|
+
id: fieldId,
|
|
245
|
+
header,
|
|
246
|
+
question,
|
|
247
|
+
options,
|
|
248
|
+
allowMultiple: true,
|
|
249
|
+
});
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (rawField.type === "string") {
|
|
254
|
+
const noteFieldId = Object.prototype.hasOwnProperty.call(properties, `${fieldId}__note`)
|
|
255
|
+
? `${fieldId}__note`
|
|
256
|
+
: undefined;
|
|
257
|
+
const options = readElicitationChoices(rawField.oneOf)
|
|
258
|
+
.filter((label) => label !== OTHER_OPTION_LABEL)
|
|
259
|
+
.map((label) => ({ label, description: "" }));
|
|
260
|
+
if (options.length === 0) return null;
|
|
261
|
+
questions.push({
|
|
262
|
+
id: fieldId,
|
|
263
|
+
header,
|
|
264
|
+
question,
|
|
265
|
+
options,
|
|
266
|
+
noteFieldId,
|
|
267
|
+
});
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return questions.length > 0 ? questions : null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function roundResultToElicitationContent(
|
|
278
|
+
questions: ParsedElicitationQuestion[],
|
|
279
|
+
result: RoundResult,
|
|
280
|
+
): Record<string, string | string[]> {
|
|
281
|
+
const content: Record<string, string | string[]> = {};
|
|
282
|
+
|
|
283
|
+
for (const question of questions) {
|
|
284
|
+
const answer = result.answers[question.id];
|
|
285
|
+
if (!answer) continue;
|
|
286
|
+
|
|
287
|
+
if (question.allowMultiple) {
|
|
288
|
+
const selected = Array.isArray(answer.selected) ? answer.selected : [answer.selected];
|
|
289
|
+
content[question.id] = selected;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const selected = Array.isArray(answer.selected) ? answer.selected[0] ?? "" : answer.selected;
|
|
294
|
+
content[question.id] = selected;
|
|
295
|
+
if (question.noteFieldId && selected === OTHER_OPTION_LABEL && answer.notes.trim().length > 0) {
|
|
296
|
+
content[question.noteFieldId] = answer.notes.trim();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return content;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function buildElicitationPromptTitle(request: SdkElicitationRequest, question: ParsedElicitationQuestion): string {
|
|
304
|
+
const parts = [
|
|
305
|
+
request.serverName ? `[${request.serverName}]` : "",
|
|
306
|
+
question.header,
|
|
307
|
+
question.question,
|
|
308
|
+
].filter((part) => part && part.trim().length > 0);
|
|
309
|
+
return parts.join("\n\n");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async function promptElicitationWithDialogs(
|
|
313
|
+
request: SdkElicitationRequest,
|
|
314
|
+
questions: ParsedElicitationQuestion[],
|
|
315
|
+
ui: ExtensionUIContext,
|
|
316
|
+
signal: AbortSignal,
|
|
317
|
+
): Promise<SdkElicitationResult> {
|
|
318
|
+
const content: Record<string, string | string[]> = {};
|
|
319
|
+
|
|
320
|
+
for (const question of questions) {
|
|
321
|
+
const title = buildElicitationPromptTitle(request, question);
|
|
322
|
+
|
|
323
|
+
if (question.allowMultiple) {
|
|
324
|
+
const selected = await ui.select(title, question.options.map((option) => option.label), {
|
|
325
|
+
allowMultiple: true,
|
|
326
|
+
signal,
|
|
327
|
+
});
|
|
328
|
+
if (Array.isArray(selected)) {
|
|
329
|
+
if (selected.length === 0) return { action: "cancel" };
|
|
330
|
+
content[question.id] = selected;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (typeof selected === "string" && selected.length > 0) {
|
|
334
|
+
content[question.id] = [selected];
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
return { action: "cancel" };
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const selected = await ui.select(title, [...question.options.map((option) => option.label), OTHER_OPTION_LABEL], { signal });
|
|
341
|
+
if (typeof selected !== "string" || selected.length === 0) {
|
|
342
|
+
return { action: "cancel" };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
content[question.id] = selected;
|
|
346
|
+
if (question.noteFieldId && selected === OTHER_OPTION_LABEL) {
|
|
347
|
+
const note = await ui.input(`${question.header} note`, "Explain your answer", { signal });
|
|
348
|
+
if (note === undefined) return { action: "cancel" };
|
|
349
|
+
if (note.trim().length > 0) {
|
|
350
|
+
content[question.noteFieldId] = note.trim();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return { action: "accept", content };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export function createClaudeCodeElicitationHandler(
|
|
359
|
+
ui: ExtensionUIContext | undefined,
|
|
360
|
+
): ((request: SdkElicitationRequest, options: { signal: AbortSignal }) => Promise<SdkElicitationResult>) | undefined {
|
|
361
|
+
if (!ui) return undefined;
|
|
362
|
+
|
|
363
|
+
return async (request, { signal }) => {
|
|
364
|
+
if (request.mode === "url") {
|
|
365
|
+
return { action: "decline" };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const questions = parseAskUserQuestionsElicitation(request);
|
|
369
|
+
if (!questions) {
|
|
370
|
+
return { action: "decline" };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const interviewResult = await showInterviewRound(questions, { signal }, { ui } as any).catch(() => undefined);
|
|
374
|
+
if (interviewResult && Object.keys(interviewResult.answers).length > 0) {
|
|
375
|
+
return {
|
|
376
|
+
action: "accept",
|
|
377
|
+
content: roundResultToElicitationContent(questions, interviewResult),
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return promptElicitationWithDialogs(request, questions, ui, signal);
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
175
385
|
// ---------------------------------------------------------------------------
|
|
176
386
|
// SDK options builder
|
|
177
387
|
// ---------------------------------------------------------------------------
|
|
@@ -182,7 +392,11 @@ export function makeStreamExhaustedErrorMessage(model: string, lastTextContent:
|
|
|
182
392
|
* Extracted for testability — callers can verify session persistence,
|
|
183
393
|
* beta flags, and other configuration without mocking the full SDK.
|
|
184
394
|
*/
|
|
185
|
-
export function buildSdkOptions(
|
|
395
|
+
export function buildSdkOptions(
|
|
396
|
+
modelId: string,
|
|
397
|
+
prompt: string,
|
|
398
|
+
extraOptions: Record<string, unknown> = {},
|
|
399
|
+
): Record<string, unknown> {
|
|
186
400
|
const mcpServers = buildWorkflowMcpServers();
|
|
187
401
|
return {
|
|
188
402
|
pathToClaudeCodeExecutable: getClaudePath(),
|
|
@@ -196,6 +410,7 @@ export function buildSdkOptions(modelId: string, prompt: string): Record<string,
|
|
|
196
410
|
systemPrompt: { type: "preset", preset: "claude_code" },
|
|
197
411
|
...(mcpServers ? { mcpServers } : {}),
|
|
198
412
|
betas: modelId.includes("sonnet") ? ["context-1m-2025-08-07"] : [],
|
|
413
|
+
...extraOptions,
|
|
199
414
|
};
|
|
200
415
|
}
|
|
201
416
|
|
|
@@ -359,7 +574,17 @@ async function pumpSdkMessages(
|
|
|
359
574
|
}
|
|
360
575
|
|
|
361
576
|
const prompt = buildPromptFromContext(context);
|
|
362
|
-
const sdkOpts = buildSdkOptions(
|
|
577
|
+
const sdkOpts = buildSdkOptions(
|
|
578
|
+
modelId,
|
|
579
|
+
prompt,
|
|
580
|
+
typeof (options as ClaudeCodeStreamOptions | undefined)?.extensionUIContext === "object"
|
|
581
|
+
? {
|
|
582
|
+
onElicitation: createClaudeCodeElicitationHandler(
|
|
583
|
+
(options as ClaudeCodeStreamOptions | undefined)?.extensionUIContext,
|
|
584
|
+
),
|
|
585
|
+
}
|
|
586
|
+
: {},
|
|
587
|
+
);
|
|
363
588
|
|
|
364
589
|
const queryResult = sdk.query({
|
|
365
590
|
prompt,
|
|
@@ -7,9 +7,12 @@ import {
|
|
|
7
7
|
makeStreamExhaustedErrorMessage,
|
|
8
8
|
buildPromptFromContext,
|
|
9
9
|
buildSdkOptions,
|
|
10
|
+
createClaudeCodeElicitationHandler,
|
|
10
11
|
extractToolResultsFromSdkUserMessage,
|
|
11
12
|
getClaudeLookupCommand,
|
|
13
|
+
parseAskUserQuestionsElicitation,
|
|
12
14
|
parseClaudeLookupOutput,
|
|
15
|
+
roundResultToElicitationContent,
|
|
13
16
|
} from "../stream-adapter.ts";
|
|
14
17
|
import type { Context, Message } from "@gsd/pi-ai";
|
|
15
18
|
import type { SDKUserMessage } from "../sdk-types.ts";
|
|
@@ -309,6 +312,175 @@ describe("stream-adapter — session persistence (#2859)", () => {
|
|
|
309
312
|
process.env.GSD_CLI_PATH = prev.GSD_CLI_PATH;
|
|
310
313
|
}
|
|
311
314
|
});
|
|
315
|
+
|
|
316
|
+
test("buildSdkOptions preserves runtime callbacks such as onElicitation", () => {
|
|
317
|
+
const prev = {
|
|
318
|
+
GSD_WORKFLOW_MCP_COMMAND: process.env.GSD_WORKFLOW_MCP_COMMAND,
|
|
319
|
+
GSD_WORKFLOW_MCP_NAME: process.env.GSD_WORKFLOW_MCP_NAME,
|
|
320
|
+
GSD_WORKFLOW_MCP_ARGS: process.env.GSD_WORKFLOW_MCP_ARGS,
|
|
321
|
+
GSD_WORKFLOW_MCP_ENV: process.env.GSD_WORKFLOW_MCP_ENV,
|
|
322
|
+
GSD_WORKFLOW_MCP_CWD: process.env.GSD_WORKFLOW_MCP_CWD,
|
|
323
|
+
};
|
|
324
|
+
const onElicitation = async () => ({ action: "decline" as const });
|
|
325
|
+
try {
|
|
326
|
+
delete process.env.GSD_WORKFLOW_MCP_COMMAND;
|
|
327
|
+
delete process.env.GSD_WORKFLOW_MCP_NAME;
|
|
328
|
+
delete process.env.GSD_WORKFLOW_MCP_ARGS;
|
|
329
|
+
delete process.env.GSD_WORKFLOW_MCP_ENV;
|
|
330
|
+
delete process.env.GSD_WORKFLOW_MCP_CWD;
|
|
331
|
+
const options = buildSdkOptions("claude-sonnet-4-20250514", "test", { onElicitation });
|
|
332
|
+
assert.equal(options.onElicitation, onElicitation);
|
|
333
|
+
} finally {
|
|
334
|
+
process.env.GSD_WORKFLOW_MCP_COMMAND = prev.GSD_WORKFLOW_MCP_COMMAND;
|
|
335
|
+
process.env.GSD_WORKFLOW_MCP_NAME = prev.GSD_WORKFLOW_MCP_NAME;
|
|
336
|
+
process.env.GSD_WORKFLOW_MCP_ARGS = prev.GSD_WORKFLOW_MCP_ARGS;
|
|
337
|
+
process.env.GSD_WORKFLOW_MCP_ENV = prev.GSD_WORKFLOW_MCP_ENV;
|
|
338
|
+
process.env.GSD_WORKFLOW_MCP_CWD = prev.GSD_WORKFLOW_MCP_CWD;
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe("stream-adapter — MCP elicitation bridge", () => {
|
|
344
|
+
const askUserQuestionsRequest = {
|
|
345
|
+
serverName: "gsd-workflow",
|
|
346
|
+
message: "Please answer the following question(s).",
|
|
347
|
+
mode: "form" as const,
|
|
348
|
+
requestedSchema: {
|
|
349
|
+
type: "object" as const,
|
|
350
|
+
properties: {
|
|
351
|
+
storage_scope: {
|
|
352
|
+
type: "string",
|
|
353
|
+
title: "Storage",
|
|
354
|
+
description: "Does this app need to sync across devices?",
|
|
355
|
+
oneOf: [
|
|
356
|
+
{ const: "Local-only (Recommended)", title: "Local-only (Recommended)" },
|
|
357
|
+
{ const: "Cloud-synced", title: "Cloud-synced" },
|
|
358
|
+
{ const: "None of the above", title: "None of the above" },
|
|
359
|
+
],
|
|
360
|
+
},
|
|
361
|
+
storage_scope__note: {
|
|
362
|
+
type: "string",
|
|
363
|
+
title: "Storage Note",
|
|
364
|
+
description: "Optional note for None of the above.",
|
|
365
|
+
},
|
|
366
|
+
platform: {
|
|
367
|
+
type: "array",
|
|
368
|
+
title: "Platform",
|
|
369
|
+
description: "Where should it run?",
|
|
370
|
+
items: {
|
|
371
|
+
anyOf: [
|
|
372
|
+
{ const: "Web", title: "Web" },
|
|
373
|
+
{ const: "Desktop", title: "Desktop" },
|
|
374
|
+
{ const: "Mobile", title: "Mobile" },
|
|
375
|
+
],
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
test("parseAskUserQuestionsElicitation rebuilds interview questions from the MCP schema", () => {
|
|
383
|
+
const questions = parseAskUserQuestionsElicitation(askUserQuestionsRequest);
|
|
384
|
+
assert.deepEqual(questions, [
|
|
385
|
+
{
|
|
386
|
+
id: "storage_scope",
|
|
387
|
+
header: "Storage",
|
|
388
|
+
question: "Does this app need to sync across devices?",
|
|
389
|
+
options: [
|
|
390
|
+
{ label: "Local-only (Recommended)", description: "" },
|
|
391
|
+
{ label: "Cloud-synced", description: "" },
|
|
392
|
+
],
|
|
393
|
+
noteFieldId: "storage_scope__note",
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
id: "platform",
|
|
397
|
+
header: "Platform",
|
|
398
|
+
question: "Where should it run?",
|
|
399
|
+
options: [
|
|
400
|
+
{ label: "Web", description: "" },
|
|
401
|
+
{ label: "Desktop", description: "" },
|
|
402
|
+
{ label: "Mobile", description: "" },
|
|
403
|
+
],
|
|
404
|
+
allowMultiple: true,
|
|
405
|
+
},
|
|
406
|
+
]);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test("roundResultToElicitationContent preserves notes for None of the above", () => {
|
|
410
|
+
const questions = parseAskUserQuestionsElicitation(askUserQuestionsRequest);
|
|
411
|
+
assert.ok(questions);
|
|
412
|
+
|
|
413
|
+
const content = roundResultToElicitationContent(questions, {
|
|
414
|
+
endInterview: false,
|
|
415
|
+
answers: {
|
|
416
|
+
storage_scope: {
|
|
417
|
+
selected: "None of the above",
|
|
418
|
+
notes: "Needs selective sync later",
|
|
419
|
+
},
|
|
420
|
+
platform: {
|
|
421
|
+
selected: ["Web", "Desktop"],
|
|
422
|
+
notes: "",
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
assert.deepEqual(content, {
|
|
428
|
+
storage_scope: "None of the above",
|
|
429
|
+
storage_scope__note: "Needs selective sync later",
|
|
430
|
+
platform: ["Web", "Desktop"],
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("createClaudeCodeElicitationHandler accepts interview-style answers from custom UI", async () => {
|
|
435
|
+
const handler = createClaudeCodeElicitationHandler({
|
|
436
|
+
custom: async (_factory: any) => ({
|
|
437
|
+
endInterview: false,
|
|
438
|
+
answers: {
|
|
439
|
+
storage_scope: {
|
|
440
|
+
selected: "Cloud-synced",
|
|
441
|
+
notes: "",
|
|
442
|
+
},
|
|
443
|
+
platform: {
|
|
444
|
+
selected: ["Web", "Mobile"],
|
|
445
|
+
notes: "",
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
}),
|
|
449
|
+
} as any);
|
|
450
|
+
|
|
451
|
+
assert.ok(handler);
|
|
452
|
+
const result = await handler!(askUserQuestionsRequest, { signal: new AbortController().signal });
|
|
453
|
+
assert.deepEqual(result, {
|
|
454
|
+
action: "accept",
|
|
455
|
+
content: {
|
|
456
|
+
storage_scope: "Cloud-synced",
|
|
457
|
+
platform: ["Web", "Mobile"],
|
|
458
|
+
},
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
test("createClaudeCodeElicitationHandler falls back to dialog prompts when custom UI is unavailable", async () => {
|
|
463
|
+
const ui = {
|
|
464
|
+
custom: async () => undefined,
|
|
465
|
+
select: async (_title: string, options: string[], opts?: { allowMultiple?: boolean }) => {
|
|
466
|
+
if (opts?.allowMultiple) return ["Desktop", "Mobile"];
|
|
467
|
+
return options.includes("None of the above") ? "None of the above" : options[0];
|
|
468
|
+
},
|
|
469
|
+
input: async () => "CLI-only deployment target",
|
|
470
|
+
};
|
|
471
|
+
const handler = createClaudeCodeElicitationHandler(ui as any);
|
|
472
|
+
assert.ok(handler);
|
|
473
|
+
|
|
474
|
+
const result = await handler!(askUserQuestionsRequest, { signal: new AbortController().signal });
|
|
475
|
+
assert.deepEqual(result, {
|
|
476
|
+
action: "accept",
|
|
477
|
+
content: {
|
|
478
|
+
storage_scope: "None of the above",
|
|
479
|
+
storage_scope__note: "CLI-only deployment target",
|
|
480
|
+
platform: ["Desktop", "Mobile"],
|
|
481
|
+
},
|
|
482
|
+
});
|
|
483
|
+
});
|
|
312
484
|
});
|
|
313
485
|
|
|
314
486
|
describe("stream-adapter — Windows Claude path lookup (#3770)", () => {
|
|
@@ -25,10 +25,17 @@ export interface ModelSelectionResult {
|
|
|
25
25
|
export function resolvePreferredModelConfig(
|
|
26
26
|
unitType: string,
|
|
27
27
|
autoModeStartModel: { provider: string; id: string } | null,
|
|
28
|
+
/** When false, only return explicit per-phase model configs — do not
|
|
29
|
+
* synthesize a routing ceiling from dynamic_routing.tier_models (#3962). */
|
|
30
|
+
isAutoMode = true,
|
|
28
31
|
) {
|
|
29
32
|
const explicitConfig = resolveModelWithFallbacksForUnit(unitType);
|
|
30
33
|
if (explicitConfig) return explicitConfig;
|
|
31
34
|
|
|
35
|
+
// In interactive mode, don't synthesize a routing-based model config.
|
|
36
|
+
// The user's session model (/model) should be used as-is (#3962).
|
|
37
|
+
if (!isAutoMode) return undefined;
|
|
38
|
+
|
|
32
39
|
const routingConfig = resolveDynamicRoutingConfig();
|
|
33
40
|
if (!routingConfig.enabled || !routingConfig.tier_models) return undefined;
|
|
34
41
|
|
|
@@ -62,8 +69,11 @@ export async function selectAndApplyModel(
|
|
|
62
69
|
verbose: boolean,
|
|
63
70
|
autoModeStartModel: { provider: string; id: string } | null,
|
|
64
71
|
retryContext?: { isRetry: boolean; previousTier?: string },
|
|
72
|
+
/** When false (interactive/guided-flow), skip dynamic routing and use the session model.
|
|
73
|
+
* Dynamic routing only applies in auto-mode where cost optimization is expected. (#3962) */
|
|
74
|
+
isAutoMode = true,
|
|
65
75
|
): Promise<ModelSelectionResult> {
|
|
66
|
-
const modelConfig = resolvePreferredModelConfig(unitType, autoModeStartModel);
|
|
76
|
+
const modelConfig = resolvePreferredModelConfig(unitType, autoModeStartModel, isAutoMode);
|
|
67
77
|
let routing: { tier: string; modelDowngraded: boolean } | null = null;
|
|
68
78
|
let appliedModel: Model<Api> | null = null;
|
|
69
79
|
|
|
@@ -71,7 +81,13 @@ export async function selectAndApplyModel(
|
|
|
71
81
|
const availableModels = ctx.modelRegistry.getAvailable();
|
|
72
82
|
|
|
73
83
|
// ─── Dynamic Model Routing ─────────────────────────────────────────
|
|
84
|
+
// Dynamic routing (complexity-based downgrading) only applies in auto-mode.
|
|
85
|
+
// Interactive/guided-flow dispatches use the user's session model directly,
|
|
86
|
+
// respecting their /model selection without silent downgrades (#3962).
|
|
74
87
|
const routingConfig = resolveDynamicRoutingConfig();
|
|
88
|
+
if (!isAutoMode) {
|
|
89
|
+
routingConfig.enabled = false;
|
|
90
|
+
}
|
|
75
91
|
let effectiveModelConfig = modelConfig;
|
|
76
92
|
let routingTierLabel = "";
|
|
77
93
|
|
|
@@ -123,12 +139,11 @@ export async function selectAndApplyModel(
|
|
|
123
139
|
const escalated = escalateTier(retryContext.previousTier as ComplexityTier);
|
|
124
140
|
if (escalated) {
|
|
125
141
|
classification = { ...classification, tier: escalated, reason: "escalated after failure" };
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
142
|
+
// Always notify on tier escalation — model changes should be visible (#3962)
|
|
143
|
+
ctx.ui.notify(
|
|
144
|
+
`Tier escalation: ${retryContext.previousTier} → ${escalated} (retry after failure)`,
|
|
145
|
+
"info",
|
|
146
|
+
);
|
|
132
147
|
}
|
|
133
148
|
}
|
|
134
149
|
|
|
@@ -195,24 +210,23 @@ export async function selectAndApplyModel(
|
|
|
195
210
|
primary: routingResult.modelId,
|
|
196
211
|
fallbacks: routingResult.fallbacks,
|
|
197
212
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
213
|
+
// Always notify on model downgrade — users should see when their
|
|
214
|
+
// model selection is overridden, not just in verbose mode (#3962).
|
|
215
|
+
if (routingResult.selectionMethod === "capability-scored" && routingResult.capabilityScores) {
|
|
216
|
+
const tierLbl = tierLabel(classification.tier);
|
|
217
|
+
const scores = Object.entries(routingResult.capabilityScores)
|
|
218
|
+
.sort(([, a], [, b]) => b - a)
|
|
219
|
+
.map(([id, score]) => `${id}: ${score.toFixed(1)}`)
|
|
220
|
+
.join(", ");
|
|
221
|
+
ctx.ui.notify(
|
|
222
|
+
`Dynamic routing [${tierLbl}]: ${routingResult.modelId} (capability-scored) — ${scores}`,
|
|
223
|
+
"info",
|
|
224
|
+
);
|
|
225
|
+
} else {
|
|
226
|
+
ctx.ui.notify(
|
|
227
|
+
`Dynamic routing [${tierLabel(classification.tier)}]: ${routingResult.modelId} (${classification.reason})`,
|
|
228
|
+
"info",
|
|
229
|
+
);
|
|
216
230
|
}
|
|
217
231
|
}
|
|
218
232
|
routingTierLabel = ` [${tierLabel(classification.tier)}]`;
|
|
@@ -997,7 +997,7 @@ export async function buildDiscussMilestonePrompt(mid: string, midTitle: string,
|
|
|
997
997
|
milestoneId: mid,
|
|
998
998
|
milestoneTitle: midTitle,
|
|
999
999
|
inlinedTemplates: discussTemplates,
|
|
1000
|
-
structuredQuestionsAvailable: "
|
|
1000
|
+
structuredQuestionsAvailable: "false",
|
|
1001
1001
|
commitInstruction: "Do not commit planning artifacts — .gsd/ is managed externally.",
|
|
1002
1002
|
fastPathInstruction: "",
|
|
1003
1003
|
});
|
|
@@ -1503,7 +1503,9 @@ export async function buildCompleteMilestonePrompt(
|
|
|
1503
1503
|
try {
|
|
1504
1504
|
const { isDbAvailable, getMilestoneSlices } = await import("./gsd-db.js");
|
|
1505
1505
|
if (isDbAvailable()) {
|
|
1506
|
-
sliceIds = getMilestoneSlices(mid)
|
|
1506
|
+
sliceIds = getMilestoneSlices(mid)
|
|
1507
|
+
.filter(s => s.status !== "skipped")
|
|
1508
|
+
.map(s => s.id);
|
|
1507
1509
|
}
|
|
1508
1510
|
} catch (err) {
|
|
1509
1511
|
logWarning("prompt", `buildCompleteMilestonePrompt DB lookup failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -1597,7 +1599,9 @@ export async function buildValidateMilestonePrompt(
|
|
|
1597
1599
|
try {
|
|
1598
1600
|
const { isDbAvailable, getMilestoneSlices } = await import("./gsd-db.js");
|
|
1599
1601
|
if (isDbAvailable()) {
|
|
1600
|
-
valSliceIds = getMilestoneSlices(mid)
|
|
1602
|
+
valSliceIds = getMilestoneSlices(mid)
|
|
1603
|
+
.filter(s => s.status !== "skipped")
|
|
1604
|
+
.map(s => s.id);
|
|
1601
1605
|
}
|
|
1602
1606
|
} catch (err) {
|
|
1603
1607
|
logWarning("prompt", `buildValidateMilestonePrompt slice IDs lookup failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -83,7 +83,7 @@ import { join } from "node:path";
|
|
|
83
83
|
import { sep as pathSep } from "node:path";
|
|
84
84
|
|
|
85
85
|
import { resolveProjectRootDbPath } from "./bootstrap/dynamic-tools.js";
|
|
86
|
-
import { resolveDefaultSessionModel } from "./preferences-models.js";
|
|
86
|
+
import { resolveDefaultSessionModel, resolveDynamicRoutingConfig } from "./preferences-models.js";
|
|
87
87
|
import type { WorktreeResolver } from "./worktree-resolver.js";
|
|
88
88
|
|
|
89
89
|
export interface BootstrapDeps {
|
|
@@ -778,6 +778,39 @@ export async function bootstrapAutoSession(
|
|
|
778
778
|
: "Will loop until milestone complete.";
|
|
779
779
|
ctx.ui.notify(`${modeLabel} started. ${scopeMsg}`, "info");
|
|
780
780
|
|
|
781
|
+
// Show dynamic routing status so users know upfront if models will be
|
|
782
|
+
// downgraded for simple tasks (#3962).
|
|
783
|
+
// Use the same effective logic as selectAndApplyModel: check flat-rate
|
|
784
|
+
// provider suppression and resolve the actual ceiling model.
|
|
785
|
+
const routingConfig = resolveDynamicRoutingConfig();
|
|
786
|
+
const startModelLabel = s.autoModeStartModel
|
|
787
|
+
? `${s.autoModeStartModel.provider}/${s.autoModeStartModel.id}`
|
|
788
|
+
: ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : "default";
|
|
789
|
+
|
|
790
|
+
// Flat-rate providers (e.g. GitHub Copilot, claude-code) suppress routing
|
|
791
|
+
// at dispatch time (#3453) — reflect that in the banner.
|
|
792
|
+
const { isFlatRateProvider } = await import("./auto-model-selection.js");
|
|
793
|
+
const effectiveProvider = s.autoModeStartModel?.provider ?? ctx.model?.provider;
|
|
794
|
+
const effectivelyEnabled = routingConfig.enabled
|
|
795
|
+
&& !(effectiveProvider && isFlatRateProvider(effectiveProvider));
|
|
796
|
+
|
|
797
|
+
// The actual ceiling may come from tier_models.heavy, not the start model.
|
|
798
|
+
const effectiveCeiling = (routingConfig.enabled && routingConfig.tier_models?.heavy)
|
|
799
|
+
? routingConfig.tier_models.heavy
|
|
800
|
+
: startModelLabel;
|
|
801
|
+
|
|
802
|
+
if (effectivelyEnabled) {
|
|
803
|
+
ctx.ui.notify(
|
|
804
|
+
`Dynamic routing: enabled — simple tasks may use cheaper models (ceiling: ${effectiveCeiling})`,
|
|
805
|
+
"info",
|
|
806
|
+
);
|
|
807
|
+
} else {
|
|
808
|
+
ctx.ui.notify(
|
|
809
|
+
`Dynamic routing: disabled — all tasks will use ${startModelLabel}`,
|
|
810
|
+
"info",
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
|
|
781
814
|
updateSessionLock(
|
|
782
815
|
lockBase(),
|
|
783
816
|
"starting",
|
|
@@ -125,9 +125,9 @@ import {
|
|
|
125
125
|
} from "./metrics.js";
|
|
126
126
|
import { setLogBasePath, logWarning, logError } from "./workflow-logger.js";
|
|
127
127
|
import { homedir } from "node:os";
|
|
128
|
-
import { join
|
|
128
|
+
import { join } from "node:path";
|
|
129
|
+
import { pathToFileURL } from "node:url";
|
|
129
130
|
import { readFileSync, existsSync, mkdirSync, writeFileSync, unlinkSync } from "node:fs";
|
|
130
|
-
import { createRequire } from "node:module";
|
|
131
131
|
import { atomicWriteSync } from "./atomic-write.js";
|
|
132
132
|
import {
|
|
133
133
|
autoCommitCurrentBranch,
|
|
@@ -1334,13 +1334,17 @@ export async function startAuto(
|
|
|
1334
1334
|
restoreHookState(s.basePath);
|
|
1335
1335
|
// Re-sync managed resources on resume so long-lived auto sessions pick up
|
|
1336
1336
|
// bundled extension updates before resume-time verification/state logic runs.
|
|
1337
|
+
// GSD_PKG_ROOT is set by loader.ts and points to the gsd-pi package root.
|
|
1338
|
+
// The relative import ("../../../resource-loader.js") only works from the source
|
|
1339
|
+
// tree; deployed extensions live at ~/.gsd/agent/extensions/gsd/ where the
|
|
1340
|
+
// relative path resolves to ~/.gsd/agent/resource-loader.js which doesn't exist.
|
|
1341
|
+
// Using GSD_PKG_ROOT constructs a correct absolute path in both contexts (#3949).
|
|
1337
1342
|
const agentDir = process.env.GSD_CODING_AGENT_DIR || join(process.env.GSD_HOME || homedir(), ".gsd", "agent");
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
const
|
|
1343
|
-
const { initResources } = await import(join(pkgRoot, "dist", "resource-loader.js"));
|
|
1343
|
+
const pkgRoot = process.env.GSD_PKG_ROOT;
|
|
1344
|
+
const resourceLoaderPath = pkgRoot
|
|
1345
|
+
? pathToFileURL(join(pkgRoot, "dist", "resource-loader.js")).href
|
|
1346
|
+
: new URL("../../../resource-loader.js", import.meta.url).href;
|
|
1347
|
+
const { initResources } = await import(resourceLoaderPath);
|
|
1344
1348
|
initResources(agentDir);
|
|
1345
1349
|
// Open the project DB before rebuild/derive so resume uses DB-backed
|
|
1346
1350
|
// state instead of falling back to stale markdown parsing (#2940).
|