@narumitw/pi-plan-mode 0.57.1 → 0.58.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +68 -4
  2. package/dist/chunks/{chunk-57OBPS7P.js → chunk-HF7ZEYIC.js} +169 -164
  3. package/dist/chunks/chunk-HF7ZEYIC.js.map +7 -0
  4. package/dist/chunks/{interactive-ui-N2ZKBVNE.js → interactive-ui-UK7IGPOE.js} +312 -32
  5. package/dist/chunks/interactive-ui-UK7IGPOE.js.map +7 -0
  6. package/dist/index.ts +670 -212
  7. package/dist/index.ts.map +4 -4
  8. package/docs/settings.md +26 -2
  9. package/package.json +50 -51
  10. package/src/active-implementation-menu.ts +57 -60
  11. package/src/command.ts +22 -21
  12. package/src/completion-tool.ts +53 -56
  13. package/src/extension-runtime.ts +5 -5
  14. package/src/finalization-request.ts +40 -44
  15. package/src/fresh-handoff-coordinator.ts +52 -0
  16. package/src/fresh-implementation.ts +312 -205
  17. package/src/implementation-models.ts +43 -0
  18. package/src/implementation-retention.ts +109 -123
  19. package/src/message-transform.ts +218 -252
  20. package/src/mode-contract.ts +46 -49
  21. package/src/plan-action-controller.ts +139 -89
  22. package/src/plan-action-menus.ts +414 -177
  23. package/src/plan-export-controller.ts +23 -28
  24. package/src/plan-export-screen.ts +13 -13
  25. package/src/plan-export.ts +85 -102
  26. package/src/plan-launch-menu.ts +119 -119
  27. package/src/plan-mode.ts +2027 -1675
  28. package/src/presentation.ts +84 -108
  29. package/src/prompt.ts +1 -1
  30. package/src/question-tool.ts +239 -267
  31. package/src/required-tools.ts +15 -19
  32. package/src/saved-plan-menu.ts +82 -84
  33. package/src/saved-plan-preflight.ts +29 -33
  34. package/src/settings-menu.ts +489 -377
  35. package/src/settings.ts +403 -382
  36. package/src/state.ts +177 -146
  37. package/src/tool-policy.ts +634 -699
  38. package/src/tool-selection.ts +39 -44
  39. package/src/workflow-mutex.ts +66 -66
  40. package/dist/chunks/chunk-57OBPS7P.js.map +0 -7
  41. package/dist/chunks/interactive-ui-N2ZKBVNE.js.map +0 -7
@@ -1,197 +1,434 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
2
+ import { defineMenu, runMenu, sanitizeTerminalText } from "@narumitw/pi-tui-kit";
3
+ import {
4
+ type AvailableImplementationModel,
5
+ findAvailableImplementationModel,
6
+ type ImplementationModelOverride,
7
+ snapshotAvailableImplementationModels,
8
+ } from "./implementation-models.js";
3
9
  import { type PlanExportDestinationProvider, planExportInputScreen } from "./plan-export-screen.js";
10
+ import { IMPLEMENTATION_THINKING_LEVELS, type PlanModeFixedThinkingLevel } from "./settings.js";
11
+ import type { ImplementationRuntimeSelection } from "./state.js";
4
12
 
5
13
  interface MenuLifecycle {
6
- signal: AbortSignal;
7
- isCurrent(): boolean;
14
+ signal: AbortSignal;
15
+ isCurrent(): boolean;
8
16
  }
9
17
 
10
18
  const IMPLEMENTATION_CONTEXT_LINES = [
11
- "Implement here keeps this planning conversation.",
12
- "Start fresh transfers only the approved plan to a new session.",
19
+ "Implement here keeps this planning conversation.",
20
+ "Start fresh transfers only the approved plan to a new session.",
13
21
  ] as const;
14
22
 
23
+ const THINKING_LEVEL_DESCRIPTIONS: Record<PlanModeFixedThinkingLevel, string> = {
24
+ off: "No reasoning",
25
+ minimal: "Very brief reasoning (~1k tokens)",
26
+ low: "Light reasoning (~2k tokens)",
27
+ medium: "Moderate reasoning (~8k tokens)",
28
+ high: "Deep reasoning (~16k tokens)",
29
+ xhigh: "Extra-high reasoning (~32k tokens)",
30
+ max: "Maximum reasoning",
31
+ };
32
+
15
33
  interface PlanMenuOptions extends MenuLifecycle {
16
- statusText: string;
17
- hasReadyPlan: boolean;
18
- implementationOutcome(): string;
19
- getExportDestination: PlanExportDestinationProvider;
20
- show(): void;
21
- finalize(): void;
22
- implementHere(): void | Promise<void>;
23
- implementFresh(signal: AbortSignal): void | Promise<void>;
24
- exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
25
- save(): void;
26
- stay(): void;
27
- exit(): void;
34
+ statusText: string;
35
+ planThinkingLevel: PlanModeFixedThinkingLevel | undefined;
36
+ implementationDefaults?: ImplementationRuntimeSelection;
37
+ hasReadyPlan: boolean;
38
+ implementationOutcome(): string;
39
+ getExportDestination: PlanExportDestinationProvider;
40
+ show(): void;
41
+ finalize(): void;
42
+ implementHere(): void | Promise<void>;
43
+ implementFresh(runtime: ImplementationRuntimeSelection, signal: AbortSignal): void | Promise<void>;
44
+ exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
45
+ save(): void;
46
+ stay(): void;
47
+ exit(): void;
28
48
  }
29
49
 
30
50
  export async function showPlanModeMenu(ctx: ExtensionContext, options: PlanMenuOptions) {
31
- type Screen = "main" | "export";
32
- type Action =
33
- | "show"
34
- | "finalize"
35
- | "implement-here"
36
- | "implement-fresh"
37
- | "export"
38
- | "save"
39
- | "stay"
40
- | "exit";
41
- const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
42
- start: "main",
43
- screens: {
44
- main: () => ({
45
- kind: "actions",
46
- title: "Plan mode",
47
- lines: [
48
- options.statusText,
49
- ...(options.hasReadyPlan
50
- ? [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()]
51
- : []),
52
- ],
53
- items: options.hasReadyPlan
54
- ? [
55
- { id: "show", label: "Show latest proposed plan", action: "show" },
56
- {
57
- id: "implement-here",
58
- label: "Implement here",
59
- description: "Continue in this session with the planning conversation.",
60
- action: "implement-here",
61
- },
62
- {
63
- id: "implement-fresh",
64
- label: "Start fresh and implement",
65
- description: "Open a new linked session; transfer only the approved plan.",
66
- action: "implement-fresh",
67
- busyLabel: "Starting fresh implementation session…",
68
- },
69
- { id: "export", label: "Export plan…", to: "export" },
70
- { id: "save", label: "Save for later", action: "save" },
71
- { id: "stay", label: "Stay in Plan mode", action: "stay" },
72
- { id: "exit", label: "Discard plan and exit", action: "exit" },
73
- ]
74
- : [
75
- { id: "finalize", label: "Request final plan", action: "finalize" },
76
- { id: "stay", label: "Stay in Plan mode", action: "stay" },
77
- { id: "exit", label: "Exit Plan mode", action: "exit" },
78
- ],
79
- hint: "close",
80
- }),
81
- export: () => planExportInputScreen(options.getExportDestination),
82
- },
83
- actions: {
84
- show: async () => {
85
- options.show();
86
- return { kind: "close" };
87
- },
88
- finalize: async () => {
89
- options.finalize();
90
- return { kind: "close" };
91
- },
92
- "implement-here": async () => {
93
- await options.implementHere();
94
- return { kind: "close" };
95
- },
96
- "implement-fresh": async ({ signal }) => {
97
- await options.implementFresh(signal);
98
- return { kind: "close" };
99
- },
100
- export: async ({ value, signal }) =>
101
- (await options.exportPlan(value ?? "", signal)) ? { kind: "close" } : { kind: "rejected" },
102
- save: async () => {
103
- options.save();
104
- return { kind: "close" };
105
- },
106
- stay: async () => {
107
- options.stay();
108
- return { kind: "close" };
109
- },
110
- exit: async () => {
111
- options.exit();
112
- return { kind: "close" };
113
- },
114
- },
115
- });
116
- await runMenu(ctx, menu, {
117
- getState: () => undefined,
118
- signal: options.signal,
119
- isCurrent: options.isCurrent,
120
- });
51
+ type Screen = "main" | "fresh" | "models" | "thinking" | "export";
52
+ type Action =
53
+ | "show"
54
+ | "finalize"
55
+ | "implement-here"
56
+ | "select-model"
57
+ | "select-thinking"
58
+ | "start-fresh"
59
+ | "export"
60
+ | "save"
61
+ | "stay"
62
+ | "exit";
63
+ const freshFlow = createFreshImplementationFlow(
64
+ ctx,
65
+ options.planThinkingLevel,
66
+ options.implementationDefaults,
67
+ options.implementFresh,
68
+ );
69
+ const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
70
+ start: "main",
71
+ screens: {
72
+ main: () => ({
73
+ kind: "actions",
74
+ title: "Plan mode",
75
+ lines: [
76
+ options.statusText,
77
+ ...(options.hasReadyPlan ? [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()] : []),
78
+ ],
79
+ items: options.hasReadyPlan
80
+ ? [
81
+ { id: "show", label: "Show latest proposed plan", action: "show" },
82
+ {
83
+ id: "implement-here",
84
+ label: "Implement here",
85
+ description: "Continue in this session with the planning conversation.",
86
+ action: "implement-here",
87
+ },
88
+ {
89
+ id: "implement-fresh",
90
+ label: "Start fresh and implement",
91
+ description: "Configure one-shot model and thinking choices first.",
92
+ to: "fresh",
93
+ },
94
+ { id: "export", label: "Export plan…", to: "export" },
95
+ { id: "save", label: "Save for later", action: "save" },
96
+ { id: "stay", label: "Stay in Plan mode", action: "stay" },
97
+ { id: "exit", label: "Discard plan and exit", action: "exit" },
98
+ ]
99
+ : [
100
+ { id: "finalize", label: "Request final plan", action: "finalize" },
101
+ { id: "stay", label: "Stay in Plan mode", action: "stay" },
102
+ { id: "exit", label: "Exit Plan mode", action: "exit" },
103
+ ],
104
+ hint: "close",
105
+ }),
106
+ fresh: freshFlow.settingsScreen,
107
+ models: freshFlow.modelScreen,
108
+ thinking: freshFlow.thinkingScreen,
109
+ export: () => planExportInputScreen(options.getExportDestination),
110
+ },
111
+ actions: {
112
+ show: async () => {
113
+ options.show();
114
+ return { kind: "close" };
115
+ },
116
+ finalize: async () => {
117
+ options.finalize();
118
+ return { kind: "close" };
119
+ },
120
+ "implement-here": async () => {
121
+ await options.implementHere();
122
+ return { kind: "close" };
123
+ },
124
+ "select-model": async ({ itemId }) => {
125
+ freshFlow.selectModel(itemId);
126
+ return { kind: "back" };
127
+ },
128
+ "select-thinking": async ({ itemId }) => {
129
+ freshFlow.selectThinking(itemId);
130
+ return { kind: "back" };
131
+ },
132
+ "start-fresh": async ({ signal }) => {
133
+ await freshFlow.start(signal);
134
+ return { kind: "close" };
135
+ },
136
+ export: async ({ value, signal }) =>
137
+ (await options.exportPlan(value ?? "", signal)) ? { kind: "close" } : { kind: "rejected" },
138
+ save: async () => {
139
+ options.save();
140
+ return { kind: "close" };
141
+ },
142
+ stay: async () => {
143
+ options.stay();
144
+ return { kind: "close" };
145
+ },
146
+ exit: async () => {
147
+ options.exit();
148
+ return { kind: "close" };
149
+ },
150
+ },
151
+ });
152
+ await runMenu(ctx, menu, {
153
+ getState: () => undefined,
154
+ signal: options.signal,
155
+ isCurrent: options.isCurrent,
156
+ });
121
157
  }
122
158
 
123
159
  interface ReadyPlanMenuOptions extends MenuLifecycle {
124
- implementationOutcome(): string;
125
- getExportDestination: PlanExportDestinationProvider;
126
- implementHere(): void | Promise<void>;
127
- implementFresh(signal: AbortSignal): void | Promise<void>;
128
- exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
129
- save(): void;
130
- stay(): void;
131
- exit(): void;
160
+ planThinkingLevel: PlanModeFixedThinkingLevel | undefined;
161
+ implementationDefaults?: ImplementationRuntimeSelection;
162
+ implementationOutcome(): string;
163
+ getExportDestination: PlanExportDestinationProvider;
164
+ implementHere(): void | Promise<void>;
165
+ implementFresh(runtime: ImplementationRuntimeSelection, signal: AbortSignal): void | Promise<void>;
166
+ exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
167
+ save(): void;
168
+ stay(): void;
169
+ exit(): void;
132
170
  }
133
171
 
134
172
  export async function showReadyPlanMenu(ctx: ExtensionContext, options: ReadyPlanMenuOptions) {
135
- type Screen = "ready" | "export";
136
- type Action = "implement-here" | "implement-fresh" | "export" | "save" | "stay" | "exit";
137
- const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
138
- start: "ready",
139
- screens: {
140
- ready: () => ({
141
- kind: "actions",
142
- title: "Proposed plan ready. What next?",
143
- lines: [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()],
144
- items: [
145
- {
146
- id: "implement-here",
147
- label: "Implement here",
148
- description: "Continue in this session with the planning conversation.",
149
- action: "implement-here",
150
- },
151
- {
152
- id: "implement-fresh",
153
- label: "Start fresh and implement",
154
- description: "Open a new linked session; transfer only the approved plan.",
155
- action: "implement-fresh",
156
- busyLabel: "Starting fresh implementation session…",
157
- },
158
- { id: "export", label: "Export plan…", to: "export" },
159
- { id: "save", label: "Save for later", action: "save" },
160
- { id: "stay", label: "Stay in Plan mode", action: "stay" },
161
- { id: "exit", label: "Discard plan and exit", action: "exit" },
162
- ],
163
- hint: "close",
164
- }),
165
- export: () => planExportInputScreen(options.getExportDestination),
166
- },
167
- actions: {
168
- "implement-here": async () => {
169
- await options.implementHere();
170
- return { kind: "close" };
171
- },
172
- "implement-fresh": async ({ signal }) => {
173
- await options.implementFresh(signal);
174
- return { kind: "close" };
175
- },
176
- export: async ({ value, signal }) =>
177
- (await options.exportPlan(value ?? "", signal)) ? { kind: "close" } : { kind: "rejected" },
178
- save: async () => {
179
- options.save();
180
- return { kind: "close" };
181
- },
182
- stay: async () => {
183
- options.stay();
184
- return { kind: "close" };
185
- },
186
- exit: async () => {
187
- options.exit();
188
- return { kind: "close" };
189
- },
190
- },
191
- });
192
- await runMenu(ctx, menu, {
193
- getState: () => undefined,
194
- signal: options.signal,
195
- isCurrent: options.isCurrent,
196
- });
173
+ type Screen = "ready" | "fresh" | "models" | "thinking" | "export";
174
+ type Action =
175
+ | "implement-here"
176
+ | "select-model"
177
+ | "select-thinking"
178
+ | "start-fresh"
179
+ | "export"
180
+ | "save"
181
+ | "stay"
182
+ | "exit";
183
+ const freshFlow = createFreshImplementationFlow(
184
+ ctx,
185
+ options.planThinkingLevel,
186
+ options.implementationDefaults,
187
+ options.implementFresh,
188
+ );
189
+ const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
190
+ start: "ready",
191
+ screens: {
192
+ ready: () => ({
193
+ kind: "actions",
194
+ title: "Proposed plan ready. What next?",
195
+ lines: [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()],
196
+ items: [
197
+ {
198
+ id: "implement-here",
199
+ label: "Implement here",
200
+ description: "Continue in this session with the planning conversation.",
201
+ action: "implement-here",
202
+ },
203
+ {
204
+ id: "implement-fresh",
205
+ label: "Start fresh and implement",
206
+ description: "Configure one-shot model and thinking choices first.",
207
+ to: "fresh",
208
+ },
209
+ { id: "export", label: "Export plan…", to: "export" },
210
+ { id: "save", label: "Save for later", action: "save" },
211
+ { id: "stay", label: "Stay in Plan mode", action: "stay" },
212
+ { id: "exit", label: "Discard plan and exit", action: "exit" },
213
+ ],
214
+ hint: "close",
215
+ }),
216
+ fresh: freshFlow.settingsScreen,
217
+ models: freshFlow.modelScreen,
218
+ thinking: freshFlow.thinkingScreen,
219
+ export: () => planExportInputScreen(options.getExportDestination),
220
+ },
221
+ actions: {
222
+ "implement-here": async () => {
223
+ await options.implementHere();
224
+ return { kind: "close" };
225
+ },
226
+ "select-model": async ({ itemId }) => {
227
+ freshFlow.selectModel(itemId);
228
+ return { kind: "back" };
229
+ },
230
+ "select-thinking": async ({ itemId }) => {
231
+ freshFlow.selectThinking(itemId);
232
+ return { kind: "back" };
233
+ },
234
+ "start-fresh": async ({ signal }) => {
235
+ await freshFlow.start(signal);
236
+ return { kind: "close" };
237
+ },
238
+ export: async ({ value, signal }) =>
239
+ (await options.exportPlan(value ?? "", signal)) ? { kind: "close" } : { kind: "rejected" },
240
+ save: async () => {
241
+ options.save();
242
+ return { kind: "close" };
243
+ },
244
+ stay: async () => {
245
+ options.stay();
246
+ return { kind: "close" };
247
+ },
248
+ exit: async () => {
249
+ options.exit();
250
+ return { kind: "close" };
251
+ },
252
+ },
253
+ });
254
+ await runMenu(ctx, menu, {
255
+ getState: () => undefined,
256
+ signal: options.signal,
257
+ isCurrent: options.isCurrent,
258
+ });
259
+ }
260
+
261
+ interface ModelChoice {
262
+ itemId: string;
263
+ model: ImplementationModelOverride;
264
+ modelInfo: AvailableImplementationModel;
265
+ label: string;
266
+ summary: string;
267
+ details?: readonly string[];
268
+ searchText: string;
269
+ isPlanModel: boolean;
270
+ }
271
+
272
+ function createFreshImplementationFlow(
273
+ ctx: ExtensionContext,
274
+ planThinkingLevel: PlanModeFixedThinkingLevel | undefined,
275
+ implementationDefaults: ImplementationRuntimeSelection | undefined,
276
+ implementFresh: (runtime: ImplementationRuntimeSelection, signal: AbortSignal) => void | Promise<void>,
277
+ ) {
278
+ const models = snapshotAvailableModels(ctx);
279
+ const planModel = ctx.model ? { provider: ctx.model.provider, modelId: ctx.model.id } : undefined;
280
+ const planModelSummary = ctx.model
281
+ ? `${safeModelMetadata(ctx.model.id, "unknown model")} [${safeModelMetadata(ctx.model.provider, "unknown provider")}]`
282
+ : undefined;
283
+ const configuredModel = implementationDefaults?.model;
284
+ const configuredAvailableModel = findAvailableImplementationModel(
285
+ models.map((choice) => choice.modelInfo),
286
+ configuredModel,
287
+ );
288
+ let unavailableDefaultActive = configuredModel !== undefined && !configuredAvailableModel;
289
+ let selectedModel = configuredAvailableModel
290
+ ? models.find((choice) => choice.modelInfo === configuredAvailableModel)
291
+ : undefined;
292
+ let selectedModelUsesDefault = selectedModel !== undefined;
293
+ let selectedThinkingLevel = implementationDefaults?.thinkingLevel;
294
+ return {
295
+ settingsScreen: () => ({
296
+ kind: "actions" as const,
297
+ title: "Fresh implementation settings",
298
+ lines: [
299
+ "These choices apply once to the new implementation session.",
300
+ ...(unavailableDefaultActive && configuredModel
301
+ ? [`Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`]
302
+ : []),
303
+ ],
304
+ items: [
305
+ {
306
+ id: "start-fresh",
307
+ label: "Start fresh implementation",
308
+ description: "Create the linked session and begin implementation.",
309
+ action: "start-fresh" as const,
310
+ busyLabel: "Starting fresh implementation session…",
311
+ },
312
+ {
313
+ id: "implementation-model",
314
+ label: "Model",
315
+ description:
316
+ selectedModel?.summary ?? (planModelSummary ? `${planModelSummary} · same as plan` : "Same as plan"),
317
+ to: "models" as const,
318
+ },
319
+ {
320
+ id: "implementation-thinking",
321
+ label: "Thinking level",
322
+ description:
323
+ selectedThinkingLevel ?? (planThinkingLevel ? `${planThinkingLevel} · same as plan` : "Same as plan"),
324
+ to: "thinking" as const,
325
+ },
326
+ ],
327
+ }),
328
+ modelScreen: () => ({
329
+ kind: "choice" as const,
330
+ title: "Implementation model",
331
+ items: [
332
+ {
333
+ id: "same-as-plan",
334
+ label: "Same as plan",
335
+ ...(planModelSummary ? { description: planModelSummary } : {}),
336
+ },
337
+ ...models.map((choice) => ({
338
+ id: choice.itemId,
339
+ label: choice.label,
340
+ details: choice.details,
341
+ searchText: choice.searchText,
342
+ })),
343
+ ],
344
+ action: "select-model" as const,
345
+ initialItemId: selectedModel?.itemId ?? "same-as-plan",
346
+ enableSearch: true,
347
+ viewportSize: 10,
348
+ }),
349
+ thinkingScreen: () => ({
350
+ kind: "choice" as const,
351
+ title: "Implementation thinking level",
352
+ items: [
353
+ {
354
+ id: "same-as-plan",
355
+ label: "Same as plan",
356
+ },
357
+ ...IMPLEMENTATION_THINKING_LEVELS.map((level) => ({
358
+ id: level,
359
+ label: `${level === planThinkingLevel ? "✓ " : ""}${level}`,
360
+ description: THINKING_LEVEL_DESCRIPTIONS[level],
361
+ })),
362
+ ],
363
+ action: "select-thinking" as const,
364
+ initialItemId: selectedThinkingLevel ?? "same-as-plan",
365
+ viewportSize: IMPLEMENTATION_THINKING_LEVELS.length + 1,
366
+ }),
367
+ selectModel(itemId: string) {
368
+ const choice = models.find((candidate) => candidate.itemId === itemId);
369
+ selectedModel = itemId === "same-as-plan" || choice?.isPlanModel ? undefined : choice;
370
+ selectedModelUsesDefault = false;
371
+ unavailableDefaultActive = false;
372
+ },
373
+ selectThinking(itemId: string) {
374
+ selectedThinkingLevel = IMPLEMENTATION_THINKING_LEVELS.find((level) => level === itemId);
375
+ },
376
+ start(signal: AbortSignal) {
377
+ if (
378
+ selectedModelUsesDefault &&
379
+ selectedModel &&
380
+ !findAvailableImplementationModel(snapshotAvailableImplementationModels(ctx), selectedModel.model)
381
+ ) {
382
+ selectedModel = undefined;
383
+ selectedModelUsesDefault = false;
384
+ unavailableDefaultActive = true;
385
+ ctx.ui.notify(
386
+ `Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`,
387
+ "warning",
388
+ );
389
+ }
390
+ const model = selectedModel?.model ?? planModel;
391
+ const thinkingLevel = selectedThinkingLevel ?? planThinkingLevel;
392
+ return implementFresh(
393
+ {
394
+ ...(model ? { model: { ...model } } : {}),
395
+ ...(thinkingLevel ? { thinkingLevel } : {}),
396
+ },
397
+ signal,
398
+ );
399
+ },
400
+ };
401
+ }
402
+
403
+ function snapshotAvailableModels(ctx: ExtensionContext): ModelChoice[] {
404
+ return snapshotAvailableImplementationModels(ctx)
405
+ .map((model, index) => {
406
+ const provider = safeModelMetadata(model.provider, "unknown provider");
407
+ const modelId = safeModelMetadata(model.id, "unknown model");
408
+ const name = safeModelMetadata(model.name, "");
409
+ const isPlanModel = ctx.model?.provider === model.provider && ctx.model.id === model.id;
410
+ const summary = `${modelId} [${provider}]`;
411
+ return {
412
+ itemId: `model-${index}`,
413
+ model: { provider: model.provider, modelId: model.id },
414
+ modelInfo: model,
415
+ label: `${isPlanModel ? "✓ " : ""}${summary}${isPlanModel ? " · default" : ""}`,
416
+ summary,
417
+ ...(name ? { details: [`Model Name: ${name}`] } : {}),
418
+ searchText: [provider, modelId, name].filter(Boolean).join(" "),
419
+ isPlanModel,
420
+ };
421
+ })
422
+ .sort((left, right) => Number(right.isPlanModel) - Number(left.isPlanModel));
423
+ }
424
+
425
+ function safeModelReference(model: ImplementationModelOverride | undefined) {
426
+ if (!model) return "configured model";
427
+ return `${safeModelMetadata(model.modelId, "unknown model")} [${safeModelMetadata(model.provider, "unknown provider")}]`;
428
+ }
429
+
430
+ function safeModelMetadata(value: unknown, fallback: string) {
431
+ if (typeof value !== "string") return fallback;
432
+ const safe = sanitizeTerminalText(value).trim() || fallback;
433
+ return [...safe].slice(0, 512).join("");
197
434
  }