@narumitw/pi-plan-mode 0.57.0 → 0.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,6 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
3
- import {
4
- createImplementationOptions,
5
- type ImplementationOptionAction,
6
- } from "./implementation-options.js";
7
3
  import { type PlanExportDestinationProvider, planExportInputScreen } from "./plan-export-screen.js";
8
- import type { ImplementationPreferences } from "./settings.js";
9
4
 
10
5
  interface SavedPlanMenuOptions {
11
6
  statusText: string;
@@ -14,15 +9,8 @@ interface SavedPlanMenuOptions {
14
9
  signal: AbortSignal;
15
10
  isCurrent(): boolean;
16
11
  show(): void;
17
- implementationPreferences?: ImplementationPreferences;
18
- implementHere(
19
- preferences?: ImplementationPreferences,
20
- signal?: AbortSignal,
21
- ): void | Promise<void>;
22
- implementFresh(
23
- signal: AbortSignal,
24
- preferences?: ImplementationPreferences,
25
- ): void | Promise<void>;
12
+ implementHere(): void | Promise<void>;
13
+ implementFresh(signal: AbortSignal): void | Promise<void>;
26
14
  exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
27
15
  settings(signal: AbortSignal): Promise<boolean>;
28
16
  clear(): void;
@@ -34,20 +22,11 @@ export async function showSavedPlanMenu(ctx: ExtensionContext, options: SavedPla
34
22
  `${options.statusText} Use /plan show, /plan implement, /plan export, or /plan exit.`,
35
23
  );
36
24
  }
37
- const implementation = createImplementationOptions(ctx, options.implementationPreferences);
38
- type Screen = "saved" | "export" | "implementation-options" | "implementation-model";
39
- type Action =
40
- | ImplementationOptionAction
41
- | "show"
42
- | "implement-here"
43
- | "implement-fresh"
44
- | "export"
45
- | "settings"
46
- | "clear";
25
+ type Screen = "saved" | "export";
26
+ type Action = "show" | "implement-here" | "implement-fresh" | "export" | "settings" | "clear";
47
27
  const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
48
28
  start: "saved",
49
29
  screens: {
50
- ...implementation.screens,
51
30
  saved: () => ({
52
31
  kind: "actions",
53
32
  title: "Saved plan",
@@ -56,7 +35,6 @@ export async function showSavedPlanMenu(ctx: ExtensionContext, options: SavedPla
56
35
  "Implement here keeps this planning conversation.",
57
36
  "Start fresh transfers only the approved plan to a new session.",
58
37
  options.implementationOutcome(),
59
- implementation.summary(),
60
38
  ],
61
39
  items: [
62
40
  { id: "show", label: "Show saved plan", action: "show" },
@@ -73,11 +51,6 @@ export async function showSavedPlanMenu(ctx: ExtensionContext, options: SavedPla
73
51
  action: "implement-fresh",
74
52
  busyLabel: "Starting fresh implementation session…",
75
53
  },
76
- {
77
- id: "implementation-options",
78
- label: "Implementation options…",
79
- to: "implementation-options",
80
- },
81
54
  { id: "export", label: "Export plan…", to: "export" },
82
55
  { id: "settings", label: "Settings", action: "settings" },
83
56
  { id: "clear", label: "Clear saved plan", action: "clear" },
@@ -87,17 +60,16 @@ export async function showSavedPlanMenu(ctx: ExtensionContext, options: SavedPla
87
60
  export: () => planExportInputScreen(options.getExportDestination),
88
61
  },
89
62
  actions: {
90
- ...implementation.actions,
91
63
  show: async () => {
92
64
  options.show();
93
65
  return { kind: "close" };
94
66
  },
95
- "implement-here": async ({ signal }) => {
96
- await options.implementHere(implementation.get(), signal);
67
+ "implement-here": async () => {
68
+ await options.implementHere();
97
69
  return { kind: "close" };
98
70
  },
99
71
  "implement-fresh": async ({ signal }) => {
100
- await options.implementFresh(signal, implementation.get());
72
+ await options.implementFresh(signal);
101
73
  return { kind: "close" };
102
74
  },
103
75
  export: async ({ value, signal }) =>
@@ -1,19 +1,28 @@
1
1
  import type { ExtensionContext, ToolInfo } from "@earendil-works/pi-coding-agent";
2
- import { defineMenu, type RunMenuResult, runMenu } from "@narumitw/pi-tui-kit";
2
+ import {
3
+ defineMenu,
4
+ type RunMenuResult,
5
+ runMenu,
6
+ sanitizeTerminalText,
7
+ } from "@narumitw/pi-tui-kit";
3
8
  import { PLAN_MODE_COMPLETE_TOOL_NAME } from "./completion-tool.js";
4
9
  import {
5
- createImplementationModelPicker,
6
- type ImplementationOptionAction,
7
- implementationSettingItems,
8
- } from "./implementation-options.js";
10
+ type AvailableImplementationModel,
11
+ findAvailableImplementationModel,
12
+ type ImplementationModelOverride,
13
+ snapshotAvailableImplementationModels,
14
+ } from "./implementation-models.js";
9
15
  import { retentionLabel } from "./implementation-retention.js";
10
16
  import { planExportDestination } from "./plan-export.js";
11
17
  import { PLAN_MODE_QUESTION_TOOL_NAME } from "./question-tool.js";
12
18
  import {
19
+ configuredImplementationModel,
13
20
  configuredImplementationPlanRetention,
21
+ configuredImplementationThinkingLevel,
14
22
  configuredPlanExportPath,
15
23
  configuredPlanModeToggleShortcut,
16
24
  IMPLEMENTATION_PLAN_RETENTIONS,
25
+ IMPLEMENTATION_THINKING_LEVELS,
17
26
  normalizeKeyId,
18
27
  PLAN_MODE_THINKING_LEVELS,
19
28
  type PlanModeSettings,
@@ -49,14 +58,16 @@ export interface PlanModeSettingsMenuOptions {
49
58
  onSaved(settings: PlanModeSettings): void;
50
59
  }
51
60
 
52
- type Screen = "settings" | "tools" | "export" | "shortcut" | "implementation-model";
61
+ type Screen = "settings" | "tools" | "implementation-model" | "export" | "shortcut";
53
62
  type Action =
54
- | ImplementationOptionAction
55
63
  | "set-thinking"
56
64
  | "open-tools"
57
65
  | "toggle-tool"
58
66
  | "reset-tools"
59
67
  | "set-retention"
68
+ | "open-implementation-model"
69
+ | "set-implementation-model"
70
+ | "set-implementation-thinking"
60
71
  | "open-export"
61
72
  | "set-export"
62
73
  | "open-shortcut"
@@ -80,6 +91,13 @@ export async function showPlanModeSettings(
80
91
  tools.map((tool, index) => [tool.name, `plan-settings-tool:${index}`]),
81
92
  );
82
93
  const toolsByItemId = new Map(tools.map((tool) => [toolItemIds.get(tool.name) as string, tool]));
94
+ const implementationModels = snapshotAvailableImplementationModels(ctx);
95
+ const modelItemIds = new Map(
96
+ implementationModels.map((model, index) => [model, `plan-settings-model:${index}`]),
97
+ );
98
+ const modelsByItemId = new Map(
99
+ implementationModels.map((model) => [modelItemIds.get(model) as string, model]),
100
+ );
83
101
 
84
102
  const loadState = async (): Promise<SettingsMenuState> => {
85
103
  const loaded = await readSettings(options.settingsPath);
@@ -98,7 +116,6 @@ export async function showPlanModeSettings(
98
116
  };
99
117
  };
100
118
 
101
- let implementationPicker: ReturnType<typeof createImplementationModelPicker> | undefined;
102
119
  const menu = defineMenu<SettingsMenuState, Screen, Action, ExtensionContext>({
103
120
  start: "settings",
104
121
  screens: {
@@ -137,6 +154,23 @@ export async function showPlanModeSettings(
137
154
  values: IMPLEMENTATION_PLAN_RETENTIONS.map(retentionLabel),
138
155
  action: "set-retention",
139
156
  },
157
+ {
158
+ id: "defaultImplementationModel",
159
+ label: "Fresh model",
160
+ description: "Choose the default model for a fresh implementation session.",
161
+ currentValue: implementationModelValue(state.settings, implementationModels),
162
+ action: "open-implementation-model",
163
+ },
164
+ {
165
+ id: "defaultImplementationThinkingLevel",
166
+ label: "Fresh thinking",
167
+ description:
168
+ "Choose the default thinking level for a fresh implementation session.",
169
+ currentValue:
170
+ configuredImplementationThinkingLevel(state.settings) ?? "same as plan",
171
+ values: ["same as plan", ...IMPLEMENTATION_THINKING_LEVELS],
172
+ action: "set-implementation-thinking",
173
+ },
140
174
  {
141
175
  id: "defaultPlanExportPath",
142
176
  label: "Export destination",
@@ -151,13 +185,8 @@ export async function showPlanModeSettings(
151
185
  currentValue: configuredPlanModeToggleShortcut(state.settings) ?? "none",
152
186
  action: "open-shortcut",
153
187
  },
154
- ...implementationSettingItems(state.settings),
155
188
  ],
156
189
  },
157
- "implementation-model": ({ state }) => {
158
- implementationPicker ??= createImplementationModelPicker(ctx);
159
- return implementationPicker.screen(state.settings);
160
- },
161
190
  tools: ({ state }) => ({
162
191
  kind: "multiSelect",
163
192
  title: "Default Plan policy allowlist",
@@ -184,6 +213,21 @@ export async function showPlanModeSettings(
184
213
  ],
185
214
  hint: "back",
186
215
  }),
216
+ "implementation-model": ({ state }) => ({
217
+ kind: "choice",
218
+ title: "Fresh implementation model",
219
+ lines: ["Same as plan is the default and fallback when a configured model is unavailable."],
220
+ items: implementationModelItems(implementationModels, modelItemIds),
221
+ action: "set-implementation-model",
222
+ initialItemId: implementationModelItemId(
223
+ configuredImplementationModel(state.settings),
224
+ implementationModels,
225
+ modelItemIds,
226
+ ),
227
+ enableSearch: true,
228
+ viewportSize: 10,
229
+ hint: "back",
230
+ }),
187
231
  export: ({ state }) => {
188
232
  const configured = configuredPlanExportPath(state.settings);
189
233
  const destination = planExportDestination(configured, ctx.cwd);
@@ -215,28 +259,6 @@ export async function showPlanModeSettings(
215
259
  }),
216
260
  },
217
261
  actions: {
218
- "open-implementation-model": async () => ({ kind: "to", screen: "implementation-model" }),
219
- "set-implementation-model": async ({ ctx: actionCtx, itemId, signal }) => {
220
- const model = implementationPicker?.selection(itemId);
221
- if (model === undefined) return { kind: "rejected" };
222
- const result = await savePatch(
223
- actionCtx,
224
- { implementationModel: model },
225
- signal,
226
- "Implementation model saved. Applies when implementation starts.",
227
- );
228
- return result.kind === "stay" ? { kind: "back" } : result;
229
- },
230
- "set-implementation-thinking": async ({ ctx: actionCtx, value, signal }) => {
231
- const level = PLAN_MODE_THINKING_LEVELS.find((level) => level === value);
232
- if (!level) return { kind: "rejected" };
233
- return savePatch(
234
- actionCtx,
235
- { implementationThinkingLevel: level },
236
- signal,
237
- "Implementation thinking saved. Applies when implementation starts.",
238
- );
239
- },
240
262
  "set-thinking": async ({ ctx: actionCtx, value, signal }) => {
241
263
  if (
242
264
  !PLAN_MODE_THINKING_LEVELS.includes(value as (typeof PLAN_MODE_THINKING_LEVELS)[number])
@@ -261,6 +283,52 @@ export async function showPlanModeSettings(
261
283
  `Plan reinjection: ${retentionLabel(implementationPlanRetention)}. Applies to the next Implement action.`,
262
284
  );
263
285
  },
286
+ "open-implementation-model": async () => ({
287
+ kind: "to",
288
+ screen: "implementation-model",
289
+ }),
290
+ "set-implementation-model": async ({ ctx: actionCtx, itemId, signal }) => {
291
+ const model = itemId ? modelsByItemId.get(itemId) : undefined;
292
+ if (itemId !== "same-as-plan" && !model) return { kind: "rejected" };
293
+ const defaultImplementationModel = model
294
+ ? { provider: model.provider, modelId: model.id }
295
+ : null;
296
+ const result = await savePatch(
297
+ actionCtx,
298
+ { defaultImplementationModel },
299
+ signal,
300
+ model
301
+ ? `Fresh implementation model: ${safeModelReference({ provider: model.provider, modelId: model.id })}.`
302
+ : "Fresh implementation model: same as plan.",
303
+ );
304
+ return result.kind === "stay" ? { kind: "to", screen: "settings" } : result;
305
+ },
306
+ "set-implementation-thinking": async ({ ctx: actionCtx, value, signal }) => {
307
+ if (value === "same as plan") {
308
+ return savePatch(
309
+ actionCtx,
310
+ { defaultImplementationThinkingLevel: null },
311
+ signal,
312
+ "Fresh implementation thinking: same as plan.",
313
+ );
314
+ }
315
+ if (
316
+ !IMPLEMENTATION_THINKING_LEVELS.includes(
317
+ value as (typeof IMPLEMENTATION_THINKING_LEVELS)[number],
318
+ )
319
+ ) {
320
+ return { kind: "rejected" };
321
+ }
322
+ return savePatch(
323
+ actionCtx,
324
+ {
325
+ defaultImplementationThinkingLevel:
326
+ value as PlanModeSettings["defaultImplementationThinkingLevel"],
327
+ },
328
+ signal,
329
+ `Fresh implementation thinking: ${value}.`,
330
+ );
331
+ },
264
332
  "open-export": async () => ({ kind: "to", screen: "export" }),
265
333
  "set-export": async ({ ctx: actionCtx, value, signal }) => {
266
334
  const defaultPlanExportPath = value?.trim() || null;
@@ -383,6 +451,59 @@ function retentionFromLabel(value: string | undefined) {
383
451
  return IMPLEMENTATION_PLAN_RETENTIONS.find((retention) => retentionLabel(retention) === value);
384
452
  }
385
453
 
454
+ function implementationModelValue(
455
+ settings: PlanModeSettings,
456
+ models: readonly AvailableImplementationModel[],
457
+ ) {
458
+ const configured = configuredImplementationModel(settings);
459
+ if (!configured) return "same as plan";
460
+ return findAvailableImplementationModel(models, configured)
461
+ ? safeModelReference(configured)
462
+ : `same as plan · ${safeModelReference(configured)} unavailable`;
463
+ }
464
+
465
+ function implementationModelItems(
466
+ models: readonly AvailableImplementationModel[],
467
+ itemIds: ReadonlyMap<AvailableImplementationModel, string>,
468
+ ) {
469
+ return [
470
+ {
471
+ id: "same-as-plan",
472
+ label: "Same as plan",
473
+ description: "Use the planning session model.",
474
+ },
475
+ ...models.map((model) => {
476
+ const reference = safeModelReference({ provider: model.provider, modelId: model.id });
477
+ const name = safeModelMetadata(model.name, "");
478
+ return {
479
+ id: itemIds.get(model) as string,
480
+ label: reference,
481
+ ...(name ? { details: [`Model Name: ${name}`] } : {}),
482
+ searchText: [reference, name].filter(Boolean).join(" "),
483
+ };
484
+ }),
485
+ ];
486
+ }
487
+
488
+ function implementationModelItemId(
489
+ configured: ImplementationModelOverride | undefined,
490
+ models: readonly AvailableImplementationModel[],
491
+ itemIds: ReadonlyMap<AvailableImplementationModel, string>,
492
+ ) {
493
+ const model = findAvailableImplementationModel(models, configured);
494
+ return model ? itemIds.get(model) : "same-as-plan";
495
+ }
496
+
497
+ function safeModelReference(model: ImplementationModelOverride) {
498
+ return `${safeModelMetadata(model.modelId, "unknown model")} [${safeModelMetadata(model.provider, "unknown provider")}]`;
499
+ }
500
+
501
+ function safeModelMetadata(value: unknown, fallback: string) {
502
+ if (typeof value !== "string") return fallback;
503
+ const safe = sanitizeTerminalText(value).trim() || fallback;
504
+ return [...safe].slice(0, 512).join("");
505
+ }
506
+
386
507
  function defaultToolsValue(configured: string[] | undefined) {
387
508
  if (configured === undefined) return "Automatic safe built-ins";
388
509
  if (configured.length === 0) return "No optional tools";
package/src/settings.ts CHANGED
@@ -4,6 +4,10 @@ import { mkdir, open, rename, rm, writeFile } from "node:fs/promises";
4
4
  import { basename, dirname, join } from "node:path";
5
5
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
6
6
  import type { KeyId } from "@earendil-works/pi-tui";
7
+ import {
8
+ type ImplementationModelOverride,
9
+ isPendingImplementationModelIdentifier,
10
+ } from "./implementation-models.js";
7
11
  import type { SafeSubcommands } from "./tool-policy.js";
8
12
 
9
13
  export const PLAN_MODE_SETTINGS_FILE = "pi-plan-mode.json";
@@ -19,6 +23,15 @@ export const PLAN_MODE_THINKING_LEVELS = [
19
23
  "xhigh",
20
24
  "max",
21
25
  ] as const;
26
+ export const IMPLEMENTATION_THINKING_LEVELS = [
27
+ "off",
28
+ "minimal",
29
+ "low",
30
+ "medium",
31
+ "high",
32
+ "xhigh",
33
+ "max",
34
+ ] as const;
22
35
  export const IMPLEMENTATION_PLAN_RETENTIONS = [
23
36
  "clear-on-start",
24
37
  "clear-after-first-run",
@@ -83,25 +96,23 @@ const MAX_PLAN_EXPORT_PATH_LENGTH = 4096;
83
96
 
84
97
  export type PlanModeThinkingLevel = (typeof PLAN_MODE_THINKING_LEVELS)[number];
85
98
  export type ImplementationPlanRetention = (typeof IMPLEMENTATION_PLAN_RETENTIONS)[number];
86
- export type PlanModeFixedThinkingLevel = Exclude<PlanModeThinkingLevel, "inherit">;
87
- export interface ImplementationPreferences {
88
- implementationModel?: { provider: string; id: string };
89
- implementationThinkingLevel?: PlanModeThinkingLevel;
90
- }
91
- export interface PlanModeSettings extends ImplementationPreferences {
99
+ export type PlanModeFixedThinkingLevel = (typeof IMPLEMENTATION_THINKING_LEVELS)[number];
100
+ export interface PlanModeSettings {
92
101
  thinkingLevel: PlanModeThinkingLevel;
93
102
  defaultPlanTools?: string[];
94
103
  implementationPlanRetention?: ImplementationPlanRetention;
104
+ defaultImplementationModel?: ImplementationModelOverride;
105
+ defaultImplementationThinkingLevel?: PlanModeFixedThinkingLevel;
95
106
  defaultPlanExportPath?: string;
96
107
  safeSubcommands?: SafeSubcommands;
97
108
  toggleShortcut?: KeyId;
98
109
  }
99
110
  export interface PlanModeSettingsPatch {
100
- implementationModel?: ImplementationPreferences["implementationModel"] | null;
101
- implementationThinkingLevel?: PlanModeThinkingLevel;
102
111
  thinkingLevel?: PlanModeThinkingLevel;
103
112
  defaultPlanTools?: readonly string[] | null;
104
113
  implementationPlanRetention?: ImplementationPlanRetention;
114
+ defaultImplementationModel?: ImplementationModelOverride | null;
115
+ defaultImplementationThinkingLevel?: PlanModeFixedThinkingLevel | null;
105
116
  defaultPlanExportPath?: string | null;
106
117
  toggleShortcut?: KeyId | null;
107
118
  }
@@ -143,21 +154,6 @@ export function normalizePlanModeSettings(value: unknown): PlanModeSettings | un
143
154
  const settings: PlanModeSettings = {
144
155
  thinkingLevel: thinkingLevel as PlanModeThinkingLevel,
145
156
  };
146
- if (Object.hasOwn(value, "implementationModel")) {
147
- const model = Reflect.get(value, "implementationModel");
148
- if (
149
- !isSettingsDocument(model) ||
150
- !validModelIdentity(model.provider) ||
151
- !validModelIdentity(model.id)
152
- )
153
- return undefined;
154
- settings.implementationModel = { provider: model.provider, id: model.id };
155
- }
156
- if (Object.hasOwn(value, "implementationThinkingLevel")) {
157
- const level = Reflect.get(value, "implementationThinkingLevel");
158
- if (!PLAN_MODE_THINKING_LEVELS.includes(level as PlanModeThinkingLevel)) return undefined;
159
- settings.implementationThinkingLevel = level as PlanModeThinkingLevel;
160
- }
161
157
  if (Object.hasOwn(value, "defaultPlanTools")) {
162
158
  const defaultPlanTools = normalizeToolNames(Reflect.get(value, "defaultPlanTools"));
163
159
  if (!defaultPlanTools) return undefined;
@@ -175,6 +171,28 @@ export function normalizePlanModeSettings(value: unknown): PlanModeSettings | un
175
171
  settings.implementationPlanRetention =
176
172
  implementationPlanRetention as ImplementationPlanRetention;
177
173
  }
174
+ if (Object.hasOwn(value, "defaultImplementationModel")) {
175
+ const defaultImplementationModel = normalizeImplementationModel(
176
+ Reflect.get(value, "defaultImplementationModel"),
177
+ );
178
+ if (!defaultImplementationModel) return undefined;
179
+ settings.defaultImplementationModel = defaultImplementationModel;
180
+ }
181
+ if (Object.hasOwn(value, "defaultImplementationThinkingLevel")) {
182
+ const defaultImplementationThinkingLevel = Reflect.get(
183
+ value,
184
+ "defaultImplementationThinkingLevel",
185
+ );
186
+ if (
187
+ !IMPLEMENTATION_THINKING_LEVELS.includes(
188
+ defaultImplementationThinkingLevel as PlanModeFixedThinkingLevel,
189
+ )
190
+ ) {
191
+ return undefined;
192
+ }
193
+ settings.defaultImplementationThinkingLevel =
194
+ defaultImplementationThinkingLevel as PlanModeFixedThinkingLevel;
195
+ }
178
196
  if (Object.hasOwn(value, "defaultPlanExportPath")) {
179
197
  const defaultPlanExportPath = normalizePlanExportPath(
180
198
  Reflect.get(value, "defaultPlanExportPath"),
@@ -195,8 +213,22 @@ export function normalizePlanModeSettings(value: unknown): PlanModeSettings | un
195
213
  return settings;
196
214
  }
197
215
 
198
- function validModelIdentity(value: unknown): value is string {
199
- return typeof value === "string" && value.trim().length > 0 && value.length <= 4096;
216
+ function normalizeImplementationModel(value: unknown): ImplementationModelOverride | undefined {
217
+ if (
218
+ !isSettingsDocument(value) ||
219
+ Object.keys(value).some((key) => key !== "provider" && key !== "modelId")
220
+ ) {
221
+ return undefined;
222
+ }
223
+ const provider = typeof value.provider === "string" ? value.provider.trim() : value.provider;
224
+ const modelId = typeof value.modelId === "string" ? value.modelId.trim() : value.modelId;
225
+ if (
226
+ !isPendingImplementationModelIdentifier(provider) ||
227
+ !isPendingImplementationModelIdentifier(modelId)
228
+ ) {
229
+ return undefined;
230
+ }
231
+ return { provider, modelId };
200
232
  }
201
233
 
202
234
  function normalizeToolNames(value: unknown) {
@@ -314,15 +346,6 @@ export function updatePlanModeSettings(
314
346
  const current = await readSettingsDocumentForUpdate(settingsPath, legacySettingsPath);
315
347
  const updated: SettingsDocument = { ...current };
316
348
  if (patch.thinkingLevel !== undefined) updated.thinkingLevel = patch.thinkingLevel;
317
- if (patch.implementationModel === null) delete updated.implementationModel;
318
- else if (patch.implementationModel !== undefined) {
319
- const previous = isSettingsDocument(updated.implementationModel)
320
- ? updated.implementationModel
321
- : {};
322
- updated.implementationModel = { ...previous, ...patch.implementationModel };
323
- }
324
- if (patch.implementationThinkingLevel !== undefined)
325
- updated.implementationThinkingLevel = patch.implementationThinkingLevel;
326
349
  if (patch.defaultPlanTools === null) delete updated.defaultPlanTools;
327
350
  else if (patch.defaultPlanTools !== undefined) {
328
351
  updated.defaultPlanTools = [...patch.defaultPlanTools];
@@ -330,6 +353,17 @@ export function updatePlanModeSettings(
330
353
  if (patch.implementationPlanRetention !== undefined) {
331
354
  updated.implementationPlanRetention = patch.implementationPlanRetention;
332
355
  }
356
+ if (patch.defaultImplementationModel === null) delete updated.defaultImplementationModel;
357
+ else if (patch.defaultImplementationModel !== undefined) {
358
+ const model = normalizeImplementationModel(patch.defaultImplementationModel);
359
+ if (!model) throw invalidSettingsError(settingsPath, "invalid implementation model");
360
+ updated.defaultImplementationModel = model;
361
+ }
362
+ if (patch.defaultImplementationThinkingLevel === null) {
363
+ delete updated.defaultImplementationThinkingLevel;
364
+ } else if (patch.defaultImplementationThinkingLevel !== undefined) {
365
+ updated.defaultImplementationThinkingLevel = patch.defaultImplementationThinkingLevel;
366
+ }
333
367
  if (patch.defaultPlanExportPath === null) delete updated.defaultPlanExportPath;
334
368
  else if (patch.defaultPlanExportPath !== undefined) {
335
369
  updated.defaultPlanExportPath = patch.defaultPlanExportPath;
@@ -512,6 +546,18 @@ export function configuredImplementationPlanRetention(
512
546
  return settings.implementationPlanRetention ?? "clear-on-start";
513
547
  }
514
548
 
549
+ export function configuredImplementationModel(
550
+ settings: PlanModeSettings,
551
+ ): ImplementationModelOverride | undefined {
552
+ return settings.defaultImplementationModel;
553
+ }
554
+
555
+ export function configuredImplementationThinkingLevel(
556
+ settings: PlanModeSettings,
557
+ ): PlanModeFixedThinkingLevel | undefined {
558
+ return settings.defaultImplementationThinkingLevel;
559
+ }
560
+
515
561
  export function configuredPlanExportPath(settings: PlanModeSettings) {
516
562
  return settings.defaultPlanExportPath ?? DEFAULT_PLAN_EXPORT_PATH;
517
563
  }
package/src/state.ts CHANGED
@@ -3,6 +3,10 @@ import {
3
3
  PLAN_MODE_COMPLETE_TOOL_NAME,
4
4
  planFromCompletionDetails,
5
5
  } from "./completion-tool.js";
6
+ import {
7
+ type ImplementationModelOverride,
8
+ isPendingImplementationModelIdentifier,
9
+ } from "./implementation-models.js";
6
10
  import {
7
11
  IMPLEMENTATION_PLAN_RETENTIONS,
8
12
  type ImplementationPlanRetention,
@@ -10,6 +14,12 @@ import {
10
14
  type PlanModeFixedThinkingLevel,
11
15
  } from "./settings.js";
12
16
 
17
+ export type { ImplementationModelOverride } from "./implementation-models.js";
18
+ export {
19
+ isPendingImplementationModelIdentifier,
20
+ MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH,
21
+ } from "./implementation-models.js";
22
+
13
23
  export type PlanCompletionSource = typeof PLAN_MODE_COMPLETE_TOOL_NAME | "legacy_proposed_plan";
14
24
 
15
25
  export interface ActiveImplementationPlan {
@@ -25,6 +35,15 @@ export interface SavedPlan {
25
35
  source: PlanCompletionSource;
26
36
  }
27
37
 
38
+ export interface ImplementationRuntimeSelection {
39
+ model?: ImplementationModelOverride;
40
+ thinkingLevel?: PlanModeFixedThinkingLevel;
41
+ }
42
+
43
+ export interface PendingImplementationRuntime extends ImplementationRuntimeSelection {
44
+ version: 1;
45
+ }
46
+
28
47
  export interface PlanModeWorkflowToolPolicy {
29
48
  kind: "automatic" | "explicit";
30
49
  desiredNames?: string[];
@@ -39,6 +58,7 @@ export interface PlanModeState {
39
58
  awaitingAction: boolean;
40
59
  savedPlan?: SavedPlan;
41
60
  activeImplementation?: ActiveImplementationPlan;
61
+ pendingImplementationRuntime?: PendingImplementationRuntime;
42
62
  selectedToolNames?: string[];
43
63
  selectedToolKeys?: string[];
44
64
  workflowToolPolicy?: PlanModeWorkflowToolPolicy;
@@ -82,6 +102,9 @@ export function restorePlanModeState(entries: unknown[], stateEntryType: string)
82
102
  : normalizeActiveImplementation(entry.data.activeImplementation);
83
103
  const savedPlan =
84
104
  enabled || activeImplementation ? undefined : normalizeSavedPlan(entry.data.savedPlan);
105
+ const pendingImplementationRuntime = enabled
106
+ ? undefined
107
+ : normalizePendingImplementationRuntime(entry.data.pendingImplementationRuntime);
85
108
  return {
86
109
  enabled,
87
110
  latestPlan,
@@ -92,6 +115,7 @@ export function restorePlanModeState(entries: unknown[], stateEntryType: string)
92
115
  awaitingAction: enabled && latestPlan !== undefined,
93
116
  savedPlan,
94
117
  activeImplementation,
118
+ pendingImplementationRuntime,
95
119
  selectedToolNames: stringArray(entry.data.selectedToolNames),
96
120
  selectedToolKeys: stringArray(entry.data.selectedToolKeys),
97
121
  workflowToolPolicy: enabled
@@ -132,6 +156,44 @@ function normalizeSavedPlan(value: unknown): SavedPlan | undefined {
132
156
  return { plan: normalized.plan, source };
133
157
  }
134
158
 
159
+ function normalizePendingImplementationRuntime(
160
+ value: unknown,
161
+ ): PendingImplementationRuntime | undefined {
162
+ if (!isRecord(value) || value.version !== 1) return undefined;
163
+ if (
164
+ Object.keys(value).some(
165
+ (key) => key !== "version" && key !== "model" && key !== "thinkingLevel",
166
+ )
167
+ ) {
168
+ return undefined;
169
+ }
170
+ let model: ImplementationModelOverride | undefined;
171
+ if (value.model !== undefined) {
172
+ if (
173
+ !isRecord(value.model) ||
174
+ Object.keys(value.model).some((key) => key !== "provider" && key !== "modelId")
175
+ ) {
176
+ return undefined;
177
+ }
178
+ if (
179
+ !isPendingImplementationModelIdentifier(value.model.provider) ||
180
+ !isPendingImplementationModelIdentifier(value.model.modelId)
181
+ ) {
182
+ return undefined;
183
+ }
184
+ model = { provider: value.model.provider, modelId: value.model.modelId };
185
+ }
186
+ const thinkingLevel =
187
+ value.thinkingLevel === undefined ? undefined : fixedThinkingLevel(value.thinkingLevel);
188
+ if (value.thinkingLevel !== undefined && !thinkingLevel) return undefined;
189
+ if (!model && !thinkingLevel) return undefined;
190
+ return {
191
+ version: 1,
192
+ ...(model ? { model } : {}),
193
+ ...(thinkingLevel ? { thinkingLevel } : {}),
194
+ };
195
+ }
196
+
135
197
  function normalizeActiveImplementation(value: unknown): ActiveImplementationPlan | undefined {
136
198
  if (!isRecord(value)) return undefined;
137
199
  const id =