@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
@@ -2,22 +2,27 @@
2
2
  // @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
3
3
  import {
4
4
  IMPLEMENTATION_PLAN_RETENTIONS,
5
+ IMPLEMENTATION_THINKING_LEVELS,
5
6
  PLAN_MODE_COMPLETE_TOOL_NAME,
6
7
  PLAN_MODE_QUESTION_TOOL_NAME,
7
8
  PLAN_MODE_THINKING_LEVELS,
8
9
  canSelectToolInPlanMode,
10
+ configuredImplementationModel,
9
11
  configuredImplementationPlanRetention,
12
+ configuredImplementationThinkingLevel,
10
13
  configuredPlanExportPath,
11
14
  configuredPlanModeToggleShortcut,
12
15
  defaultPlanModeToolNames,
16
+ findAvailableImplementationModel,
13
17
  normalizeKeyId,
14
18
  planExportDestination,
15
19
  planModeSettingsPath,
16
20
  readPlanModeSettings,
17
21
  retentionLabel,
22
+ snapshotAvailableImplementationModels,
18
23
  toolPolicyLabel,
19
24
  updatePlanModeSettings
20
- } from "./chunk-57OBPS7P.js";
25
+ } from "./chunk-HF7ZEYIC.js";
21
26
 
22
27
  // src/active-implementation-menu.ts
23
28
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
@@ -88,12 +93,27 @@ async function showActiveImplementationMenu(ctx, options) {
88
93
  }
89
94
 
90
95
  // src/plan-action-menus.ts
91
- import { defineMenu as defineMenu2, runMenu as runMenu2 } from "@narumitw/pi-tui-kit";
96
+ import { defineMenu as defineMenu2, runMenu as runMenu2, sanitizeTerminalText } from "@narumitw/pi-tui-kit";
92
97
  var IMPLEMENTATION_CONTEXT_LINES = [
93
98
  "Implement here keeps this planning conversation.",
94
99
  "Start fresh transfers only the approved plan to a new session."
95
100
  ];
101
+ var THINKING_LEVEL_DESCRIPTIONS = {
102
+ off: "No reasoning",
103
+ minimal: "Very brief reasoning (~1k tokens)",
104
+ low: "Light reasoning (~2k tokens)",
105
+ medium: "Moderate reasoning (~8k tokens)",
106
+ high: "Deep reasoning (~16k tokens)",
107
+ xhigh: "Extra-high reasoning (~32k tokens)",
108
+ max: "Maximum reasoning"
109
+ };
96
110
  async function showPlanModeMenu(ctx, options) {
111
+ const freshFlow = createFreshImplementationFlow(
112
+ ctx,
113
+ options.planThinkingLevel,
114
+ options.implementationDefaults,
115
+ options.implementFresh
116
+ );
97
117
  const menu = defineMenu2({
98
118
  start: "main",
99
119
  screens: {
@@ -115,9 +135,8 @@ async function showPlanModeMenu(ctx, options) {
115
135
  {
116
136
  id: "implement-fresh",
117
137
  label: "Start fresh and implement",
118
- description: "Open a new linked session; transfer only the approved plan.",
119
- action: "implement-fresh",
120
- busyLabel: "Starting fresh implementation session\u2026"
138
+ description: "Configure one-shot model and thinking choices first.",
139
+ to: "fresh"
121
140
  },
122
141
  { id: "export", label: "Export plan\u2026", to: "export" },
123
142
  { id: "save", label: "Save for later", action: "save" },
@@ -130,6 +149,9 @@ async function showPlanModeMenu(ctx, options) {
130
149
  ],
131
150
  hint: "close"
132
151
  }),
152
+ fresh: freshFlow.settingsScreen,
153
+ models: freshFlow.modelScreen,
154
+ thinking: freshFlow.thinkingScreen,
133
155
  export: () => planExportInputScreen(options.getExportDestination)
134
156
  },
135
157
  actions: {
@@ -145,8 +167,16 @@ async function showPlanModeMenu(ctx, options) {
145
167
  await options.implementHere();
146
168
  return { kind: "close" };
147
169
  },
148
- "implement-fresh": async ({ signal }) => {
149
- await options.implementFresh(signal);
170
+ "select-model": async ({ itemId }) => {
171
+ freshFlow.selectModel(itemId);
172
+ return { kind: "back" };
173
+ },
174
+ "select-thinking": async ({ itemId }) => {
175
+ freshFlow.selectThinking(itemId);
176
+ return { kind: "back" };
177
+ },
178
+ "start-fresh": async ({ signal }) => {
179
+ await freshFlow.start(signal);
150
180
  return { kind: "close" };
151
181
  },
152
182
  export: async ({ value, signal }) => await options.exportPlan(value ?? "", signal) ? { kind: "close" } : { kind: "rejected" },
@@ -171,6 +201,12 @@ async function showPlanModeMenu(ctx, options) {
171
201
  });
172
202
  }
173
203
  async function showReadyPlanMenu(ctx, options) {
204
+ const freshFlow = createFreshImplementationFlow(
205
+ ctx,
206
+ options.planThinkingLevel,
207
+ options.implementationDefaults,
208
+ options.implementFresh
209
+ );
174
210
  const menu = defineMenu2({
175
211
  start: "ready",
176
212
  screens: {
@@ -188,9 +224,8 @@ async function showReadyPlanMenu(ctx, options) {
188
224
  {
189
225
  id: "implement-fresh",
190
226
  label: "Start fresh and implement",
191
- description: "Open a new linked session; transfer only the approved plan.",
192
- action: "implement-fresh",
193
- busyLabel: "Starting fresh implementation session\u2026"
227
+ description: "Configure one-shot model and thinking choices first.",
228
+ to: "fresh"
194
229
  },
195
230
  { id: "export", label: "Export plan\u2026", to: "export" },
196
231
  { id: "save", label: "Save for later", action: "save" },
@@ -199,6 +234,9 @@ async function showReadyPlanMenu(ctx, options) {
199
234
  ],
200
235
  hint: "close"
201
236
  }),
237
+ fresh: freshFlow.settingsScreen,
238
+ models: freshFlow.modelScreen,
239
+ thinking: freshFlow.thinkingScreen,
202
240
  export: () => planExportInputScreen(options.getExportDestination)
203
241
  },
204
242
  actions: {
@@ -206,8 +244,16 @@ async function showReadyPlanMenu(ctx, options) {
206
244
  await options.implementHere();
207
245
  return { kind: "close" };
208
246
  },
209
- "implement-fresh": async ({ signal }) => {
210
- await options.implementFresh(signal);
247
+ "select-model": async ({ itemId }) => {
248
+ freshFlow.selectModel(itemId);
249
+ return { kind: "back" };
250
+ },
251
+ "select-thinking": async ({ itemId }) => {
252
+ freshFlow.selectThinking(itemId);
253
+ return { kind: "back" };
254
+ },
255
+ "start-fresh": async ({ signal }) => {
256
+ await freshFlow.start(signal);
211
257
  return { kind: "close" };
212
258
  },
213
259
  export: async ({ value, signal }) => await options.exportPlan(value ?? "", signal) ? { kind: "close" } : { kind: "rejected" },
@@ -231,6 +277,147 @@ async function showReadyPlanMenu(ctx, options) {
231
277
  isCurrent: options.isCurrent
232
278
  });
233
279
  }
280
+ function createFreshImplementationFlow(ctx, planThinkingLevel, implementationDefaults, implementFresh) {
281
+ const models = snapshotAvailableModels(ctx);
282
+ const planModel = ctx.model ? { provider: ctx.model.provider, modelId: ctx.model.id } : void 0;
283
+ const planModelSummary = ctx.model ? `${safeModelMetadata(ctx.model.id, "unknown model")} [${safeModelMetadata(ctx.model.provider, "unknown provider")}]` : void 0;
284
+ const configuredModel = implementationDefaults?.model;
285
+ const configuredAvailableModel = findAvailableImplementationModel(
286
+ models.map((choice) => choice.modelInfo),
287
+ configuredModel
288
+ );
289
+ let unavailableDefaultActive = configuredModel !== void 0 && !configuredAvailableModel;
290
+ let selectedModel = configuredAvailableModel ? models.find((choice) => choice.modelInfo === configuredAvailableModel) : void 0;
291
+ let selectedModelUsesDefault = selectedModel !== void 0;
292
+ let selectedThinkingLevel = implementationDefaults?.thinkingLevel;
293
+ return {
294
+ settingsScreen: () => ({
295
+ kind: "actions",
296
+ title: "Fresh implementation settings",
297
+ lines: [
298
+ "These choices apply once to the new implementation session.",
299
+ ...unavailableDefaultActive && configuredModel ? [`Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`] : []
300
+ ],
301
+ items: [
302
+ {
303
+ id: "start-fresh",
304
+ label: "Start fresh implementation",
305
+ description: "Create the linked session and begin implementation.",
306
+ action: "start-fresh",
307
+ busyLabel: "Starting fresh implementation session\u2026"
308
+ },
309
+ {
310
+ id: "implementation-model",
311
+ label: "Model",
312
+ description: selectedModel?.summary ?? (planModelSummary ? `${planModelSummary} \xB7 same as plan` : "Same as plan"),
313
+ to: "models"
314
+ },
315
+ {
316
+ id: "implementation-thinking",
317
+ label: "Thinking level",
318
+ description: selectedThinkingLevel ?? (planThinkingLevel ? `${planThinkingLevel} \xB7 same as plan` : "Same as plan"),
319
+ to: "thinking"
320
+ }
321
+ ]
322
+ }),
323
+ modelScreen: () => ({
324
+ kind: "choice",
325
+ title: "Implementation model",
326
+ items: [
327
+ {
328
+ id: "same-as-plan",
329
+ label: "Same as plan",
330
+ ...planModelSummary ? { description: planModelSummary } : {}
331
+ },
332
+ ...models.map((choice) => ({
333
+ id: choice.itemId,
334
+ label: choice.label,
335
+ details: choice.details,
336
+ searchText: choice.searchText
337
+ }))
338
+ ],
339
+ action: "select-model",
340
+ initialItemId: selectedModel?.itemId ?? "same-as-plan",
341
+ enableSearch: true,
342
+ viewportSize: 10
343
+ }),
344
+ thinkingScreen: () => ({
345
+ kind: "choice",
346
+ title: "Implementation thinking level",
347
+ items: [
348
+ {
349
+ id: "same-as-plan",
350
+ label: "Same as plan"
351
+ },
352
+ ...IMPLEMENTATION_THINKING_LEVELS.map((level) => ({
353
+ id: level,
354
+ label: `${level === planThinkingLevel ? "\u2713 " : ""}${level}`,
355
+ description: THINKING_LEVEL_DESCRIPTIONS[level]
356
+ }))
357
+ ],
358
+ action: "select-thinking",
359
+ initialItemId: selectedThinkingLevel ?? "same-as-plan",
360
+ viewportSize: IMPLEMENTATION_THINKING_LEVELS.length + 1
361
+ }),
362
+ selectModel(itemId) {
363
+ const choice = models.find((candidate) => candidate.itemId === itemId);
364
+ selectedModel = itemId === "same-as-plan" || choice?.isPlanModel ? void 0 : choice;
365
+ selectedModelUsesDefault = false;
366
+ unavailableDefaultActive = false;
367
+ },
368
+ selectThinking(itemId) {
369
+ selectedThinkingLevel = IMPLEMENTATION_THINKING_LEVELS.find((level) => level === itemId);
370
+ },
371
+ start(signal) {
372
+ if (selectedModelUsesDefault && selectedModel && !findAvailableImplementationModel(snapshotAvailableImplementationModels(ctx), selectedModel.model)) {
373
+ selectedModel = void 0;
374
+ selectedModelUsesDefault = false;
375
+ unavailableDefaultActive = true;
376
+ ctx.ui.notify(
377
+ `Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`,
378
+ "warning"
379
+ );
380
+ }
381
+ const model = selectedModel?.model ?? planModel;
382
+ const thinkingLevel = selectedThinkingLevel ?? planThinkingLevel;
383
+ return implementFresh(
384
+ {
385
+ ...model ? { model: { ...model } } : {},
386
+ ...thinkingLevel ? { thinkingLevel } : {}
387
+ },
388
+ signal
389
+ );
390
+ }
391
+ };
392
+ }
393
+ function snapshotAvailableModels(ctx) {
394
+ return snapshotAvailableImplementationModels(ctx).map((model, index) => {
395
+ const provider = safeModelMetadata(model.provider, "unknown provider");
396
+ const modelId = safeModelMetadata(model.id, "unknown model");
397
+ const name = safeModelMetadata(model.name, "");
398
+ const isPlanModel = ctx.model?.provider === model.provider && ctx.model.id === model.id;
399
+ const summary = `${modelId} [${provider}]`;
400
+ return {
401
+ itemId: `model-${index}`,
402
+ model: { provider: model.provider, modelId: model.id },
403
+ modelInfo: model,
404
+ label: `${isPlanModel ? "\u2713 " : ""}${summary}${isPlanModel ? " \xB7 default" : ""}`,
405
+ summary,
406
+ ...name ? { details: [`Model Name: ${name}`] } : {},
407
+ searchText: [provider, modelId, name].filter(Boolean).join(" "),
408
+ isPlanModel
409
+ };
410
+ }).sort((left, right) => Number(right.isPlanModel) - Number(left.isPlanModel));
411
+ }
412
+ function safeModelReference(model) {
413
+ if (!model) return "configured model";
414
+ return `${safeModelMetadata(model.modelId, "unknown model")} [${safeModelMetadata(model.provider, "unknown provider")}]`;
415
+ }
416
+ function safeModelMetadata(value, fallback) {
417
+ if (typeof value !== "string") return fallback;
418
+ const safe = sanitizeTerminalText(value).trim() || fallback;
419
+ return [...safe].slice(0, 512).join("");
420
+ }
234
421
 
235
422
  // src/plan-launch-menu.ts
236
423
  import { defineMenu as defineMenu3, runMenu as runMenu3 } from "@narumitw/pi-tui-kit";
@@ -342,9 +529,7 @@ async function showPlanLaunchMenu(ctx, options) {
342
529
  import { defineMenu as defineMenu4, runMenu as runMenu4 } from "@narumitw/pi-tui-kit";
343
530
  async function showSavedPlanMenu(ctx, options) {
344
531
  if (!ctx.hasUI) {
345
- throw new Error(
346
- `${options.statusText} Use /plan show, /plan implement, /plan export, or /plan exit.`
347
- );
532
+ throw new Error(`${options.statusText} Use /plan show, /plan implement, /plan export, or /plan exit.`);
348
533
  }
349
534
  const menu = defineMenu4({
350
535
  start: "saved",
@@ -414,21 +599,20 @@ async function showSavedPlanMenu(ctx, options) {
414
599
  }
415
600
 
416
601
  // src/settings-menu.ts
417
- import { defineMenu as defineMenu5, runMenu as runMenu5 } from "@narumitw/pi-tui-kit";
602
+ import { defineMenu as defineMenu5, runMenu as runMenu5, sanitizeTerminalText as sanitizeTerminalText2 } from "@narumitw/pi-tui-kit";
418
603
  async function showPlanModeSettings(ctx, options) {
419
604
  const settingsPath = options.settingsPath ?? planModeSettingsPath();
420
605
  const readSettings = options.readSettings ?? readPlanModeSettings;
421
606
  const updateSettings = options.updateSettings ?? updatePlanModeSettings;
422
- const activeToolNames = new Set(
423
- options.activeToolNames ?? options.tools.map((tool) => tool.name)
424
- );
607
+ const activeToolNames = new Set(options.activeToolNames ?? options.tools.map((tool) => tool.name));
425
608
  const tools = options.tools.filter(
426
609
  (tool) => tool.name !== PLAN_MODE_QUESTION_TOOL_NAME && tool.name !== PLAN_MODE_COMPLETE_TOOL_NAME
427
610
  );
428
- const toolItemIds = new Map(
429
- tools.map((tool, index) => [tool.name, `plan-settings-tool:${index}`])
430
- );
611
+ const toolItemIds = new Map(tools.map((tool, index) => [tool.name, `plan-settings-tool:${index}`]));
431
612
  const toolsByItemId = new Map(tools.map((tool) => [toolItemIds.get(tool.name), tool]));
613
+ const implementationModels = snapshotAvailableImplementationModels(ctx);
614
+ const modelItemIds = new Map(implementationModels.map((model, index) => [model, `plan-settings-model:${index}`]));
615
+ const modelsByItemId = new Map(implementationModels.map((model) => [modelItemIds.get(model), model]));
432
616
  const loadState = async () => {
433
617
  const loaded = await readSettings(options.settingsPath);
434
618
  if (loaded.kind === "invalid") {
@@ -472,12 +656,25 @@ async function showPlanModeSettings(ctx, options) {
472
656
  id: "implementationPlanRetention",
473
657
  label: "Plan reinjection",
474
658
  description: "Choose how long Plan mode restores the exact plan when ordinary context no longer contains it.",
475
- currentValue: retentionLabel(
476
- configuredImplementationPlanRetention(state.settings)
477
- ),
659
+ currentValue: retentionLabel(configuredImplementationPlanRetention(state.settings)),
478
660
  values: IMPLEMENTATION_PLAN_RETENTIONS.map(retentionLabel),
479
661
  action: "set-retention"
480
662
  },
663
+ {
664
+ id: "defaultImplementationModel",
665
+ label: "Fresh model",
666
+ description: "Choose the default model for a fresh implementation session.",
667
+ currentValue: implementationModelValue(state.settings, implementationModels),
668
+ action: "open-implementation-model"
669
+ },
670
+ {
671
+ id: "defaultImplementationThinkingLevel",
672
+ label: "Fresh thinking",
673
+ description: "Choose the default thinking level for a fresh implementation session.",
674
+ currentValue: configuredImplementationThinkingLevel(state.settings) ?? "same as plan",
675
+ values: ["same as plan", ...IMPLEMENTATION_THINKING_LEVELS],
676
+ action: "set-implementation-thinking"
677
+ },
481
678
  {
482
679
  id: "defaultPlanExportPath",
483
680
  label: "Export destination",
@@ -504,12 +701,7 @@ async function showPlanModeSettings(ctx, options) {
504
701
  ],
505
702
  enableSearch: true,
506
703
  viewportSize: 10,
507
- items: defaultToolItems(
508
- tools,
509
- state.settings.defaultPlanTools,
510
- activeToolNames,
511
- toolItemIds
512
- ),
704
+ items: defaultToolItems(tools, state.settings.defaultPlanTools, activeToolNames, toolItemIds),
513
705
  action: "toggle-tool",
514
706
  actions: [
515
707
  {
@@ -520,6 +712,21 @@ async function showPlanModeSettings(ctx, options) {
520
712
  ],
521
713
  hint: "back"
522
714
  }),
715
+ "implementation-model": ({ state }) => ({
716
+ kind: "choice",
717
+ title: "Fresh implementation model",
718
+ lines: ["Same as plan is the default and fallback when a configured model is unavailable."],
719
+ items: implementationModelItems(implementationModels, modelItemIds),
720
+ action: "set-implementation-model",
721
+ initialItemId: implementationModelItemId(
722
+ configuredImplementationModel(state.settings),
723
+ implementationModels,
724
+ modelItemIds
725
+ ),
726
+ enableSearch: true,
727
+ viewportSize: 10,
728
+ hint: "back"
729
+ }),
523
730
  export: ({ state }) => {
524
731
  const configured = configuredPlanExportPath(state.settings);
525
732
  const destination = planExportDestination(configured, ctx.cwd);
@@ -573,6 +780,43 @@ async function showPlanModeSettings(ctx, options) {
573
780
  `Plan reinjection: ${retentionLabel(implementationPlanRetention)}. Applies to the next Implement action.`
574
781
  );
575
782
  },
783
+ "open-implementation-model": async () => ({
784
+ kind: "to",
785
+ screen: "implementation-model"
786
+ }),
787
+ "set-implementation-model": async ({ ctx: actionCtx, itemId, signal }) => {
788
+ const model = itemId ? modelsByItemId.get(itemId) : void 0;
789
+ if (itemId !== "same-as-plan" && !model) return { kind: "rejected" };
790
+ const defaultImplementationModel = model ? { provider: model.provider, modelId: model.id } : null;
791
+ const result = await savePatch(
792
+ actionCtx,
793
+ { defaultImplementationModel },
794
+ signal,
795
+ model ? `Fresh implementation model: ${safeModelReference2({ provider: model.provider, modelId: model.id })}.` : "Fresh implementation model: same as plan."
796
+ );
797
+ return result.kind === "stay" ? { kind: "to", screen: "settings" } : result;
798
+ },
799
+ "set-implementation-thinking": async ({ ctx: actionCtx, value, signal }) => {
800
+ if (value === "same as plan") {
801
+ return savePatch(
802
+ actionCtx,
803
+ { defaultImplementationThinkingLevel: null },
804
+ signal,
805
+ "Fresh implementation thinking: same as plan."
806
+ );
807
+ }
808
+ if (!IMPLEMENTATION_THINKING_LEVELS.includes(value)) {
809
+ return { kind: "rejected" };
810
+ }
811
+ return savePatch(
812
+ actionCtx,
813
+ {
814
+ defaultImplementationThinkingLevel: value
815
+ },
816
+ signal,
817
+ `Fresh implementation thinking: ${value}.`
818
+ );
819
+ },
576
820
  "open-export": async () => ({ kind: "to", screen: "export" }),
577
821
  "set-export": async ({ ctx: actionCtx, value, signal }) => {
578
822
  const defaultPlanExportPath = value?.trim() || null;
@@ -678,6 +922,42 @@ function invalidScreen(settingsPath, state) {
678
922
  function retentionFromLabel(value) {
679
923
  return IMPLEMENTATION_PLAN_RETENTIONS.find((retention) => retentionLabel(retention) === value);
680
924
  }
925
+ function implementationModelValue(settings, models) {
926
+ const configured = configuredImplementationModel(settings);
927
+ if (!configured) return "same as plan";
928
+ return findAvailableImplementationModel(models, configured) ? safeModelReference2(configured) : `same as plan \xB7 ${safeModelReference2(configured)} unavailable`;
929
+ }
930
+ function implementationModelItems(models, itemIds) {
931
+ return [
932
+ {
933
+ id: "same-as-plan",
934
+ label: "Same as plan",
935
+ description: "Use the planning session model."
936
+ },
937
+ ...models.map((model) => {
938
+ const reference = safeModelReference2({ provider: model.provider, modelId: model.id });
939
+ const name = safeModelMetadata2(model.name, "");
940
+ return {
941
+ id: itemIds.get(model),
942
+ label: reference,
943
+ ...name ? { details: [`Model Name: ${name}`] } : {},
944
+ searchText: [reference, name].filter(Boolean).join(" ")
945
+ };
946
+ })
947
+ ];
948
+ }
949
+ function implementationModelItemId(configured, models, itemIds) {
950
+ const model = findAvailableImplementationModel(models, configured);
951
+ return model ? itemIds.get(model) : "same-as-plan";
952
+ }
953
+ function safeModelReference2(model) {
954
+ return `${safeModelMetadata2(model.modelId, "unknown model")} [${safeModelMetadata2(model.provider, "unknown provider")}]`;
955
+ }
956
+ function safeModelMetadata2(value, fallback) {
957
+ if (typeof value !== "string") return fallback;
958
+ const safe = sanitizeTerminalText2(value).trim() || fallback;
959
+ return [...safe].slice(0, 512).join("");
960
+ }
681
961
  function defaultToolsValue(configured) {
682
962
  if (configured === void 0) return "Automatic safe built-ins";
683
963
  if (configured.length === 0) return "No optional tools";
@@ -740,4 +1020,4 @@ export {
740
1020
  showReadyPlanMenu,
741
1021
  showSavedPlanMenu
742
1022
  };
743
- //# sourceMappingURL=interactive-ui-N2ZKBVNE.js.map
1023
+ //# sourceMappingURL=interactive-ui-UK7IGPOE.js.map