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