@narumitw/pi-plan-mode 0.57.0 → 0.57.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.
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/active-implementation-menu.ts", "../../src/plan-export-screen.ts", "../../src/plan-action-menus.ts", "../../src/implementation-options.ts", "../../src/plan-launch-menu.ts", "../../src/saved-plan-menu.ts", "../../src/settings-menu.ts"],
4
- "sourcesContent": ["import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { type PlanExportDestinationProvider, planExportInputScreen } from \"./plan-export-screen.js\";\n\ninterface ActiveImplementationMenuOptions {\n\tstatusText: string;\n\tgetExportDestination: PlanExportDestinationProvider;\n\tsignal: AbortSignal;\n\tisCurrent(): boolean;\n\tshow(): void;\n\texportPlan(path: string, signal: AbortSignal): Promise<boolean>;\n\tsettings(signal: AbortSignal): Promise<boolean>;\n\tstartNew(): void;\n\tclear(): void;\n}\n\nexport async function showActiveImplementationMenu(\n\tctx: ExtensionContext,\n\toptions: ActiveImplementationMenuOptions,\n) {\n\ttype Screen = \"active\" | \"export\";\n\ttype Action = \"show\" | \"export\" | \"settings\" | \"start-new\" | \"clear\";\n\tconst menu = defineMenu<undefined, Screen, Action, ExtensionContext>({\n\t\tstart: \"active\",\n\t\tscreens: {\n\t\t\tactive: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Active implementation plan\",\n\t\t\t\tlines: [options.statusText],\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"show\", label: \"Show active implementation plan\", action: \"show\" },\n\t\t\t\t\t{ id: \"export\", label: \"Export plan\u2026\", to: \"export\" },\n\t\t\t\t\t{ id: \"settings\", label: \"Settings\", action: \"settings\" },\n\t\t\t\t\t{ id: \"start-new\", label: \"Start a new plan\", action: \"start-new\" },\n\t\t\t\t\t{ id: \"clear\", label: \"Clear active implementation plan\", action: \"clear\" },\n\t\t\t\t],\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t\texport: () => planExportInputScreen(options.getExportDestination),\n\t\t},\n\t\tactions: {\n\t\t\tshow: async () => {\n\t\t\t\toptions.show();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\texport: async ({ value, signal }) =>\n\t\t\t\t(await options.exportPlan(value ?? \"\", signal)) ? { kind: \"close\" } : { kind: \"rejected\" },\n\t\t\tsettings: async ({ signal }) => {\n\t\t\t\tconst close = await options.settings(signal);\n\t\t\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n\t\t\t\treturn close ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t},\n\t\t\t\"start-new\": async () => {\n\t\t\t\toptions.startNew();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tclear: async () => {\n\t\t\t\toptions.clear();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: options.signal,\n\t\tisCurrent: options.isCurrent,\n\t});\n}\n", "import type { PlanExportDestination } from \"./plan-export.js\";\n\nexport type PlanExportDestinationProvider = () => PlanExportDestination;\n\nexport function planExportInputScreen(getDestination: PlanExportDestinationProvider) {\n\tconst destination = getDestination();\n\treturn {\n\t\tkind: \"input\" as const,\n\t\ttitle: \"Export plan\",\n\t\tlines: [\n\t\t\t\"Existing paths are never overwritten.\",\n\t\t\t`Default: ${destination.configuredPath}`,\n\t\t\t`Resolves to: ${destination.resolvedPath}`,\n\t\t],\n\t\tplaceholder: destination.configuredPath,\n\t\taction: \"export\" as const,\n\t\thint: \"back\" as const,\n\t};\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport {\n\tcreateImplementationOptions,\n\ttype ImplementationOptionAction,\n} from \"./implementation-options.js\";\nimport { type PlanExportDestinationProvider, planExportInputScreen } from \"./plan-export-screen.js\";\nimport type { ImplementationPreferences } from \"./settings.js\";\n\ninterface ReadyPlanMenuOptions {\n\tsignal: AbortSignal;\n\tisCurrent(): boolean;\n\timplementationPreferences?: ImplementationPreferences;\n\timplementationOutcome(): string;\n\tgetExportDestination: PlanExportDestinationProvider;\n\timplementHere(\n\t\tpreferences?: ImplementationPreferences,\n\t\tsignal?: AbortSignal,\n\t): void | Promise<void>;\n\timplementFresh(\n\t\tsignal: AbortSignal,\n\t\tpreferences?: ImplementationPreferences,\n\t): void | Promise<void>;\n\texportPlan(path: string, signal: AbortSignal): Promise<boolean>;\n\tsave(): void;\n\tstay(): void;\n\texit(): void;\n}\n\ninterface PlanMenuOptions extends ReadyPlanMenuOptions {\n\tstatusText: string;\n\thasReadyPlan: boolean;\n\tshow(): void;\n\tfinalize(): void;\n}\n\nexport function showPlanModeMenu(ctx: ExtensionContext, options: PlanMenuOptions) {\n\treturn showActions(ctx, options, options);\n}\n\nexport function showReadyPlanMenu(ctx: ExtensionContext, options: ReadyPlanMenuOptions) {\n\treturn showActions(ctx, options);\n}\n\nasync function showActions(\n\tctx: ExtensionContext,\n\toptions: ReadyPlanMenuOptions,\n\tcurrent?: PlanMenuOptions,\n) {\n\tconst implementation = createImplementationOptions(ctx, options.implementationPreferences);\n\tconst ready = current?.hasReadyPlan ?? true;\n\ttype Screen = \"main\" | \"export\" | \"implementation-options\" | \"implementation-model\";\n\ttype Action =\n\t\t| ImplementationOptionAction\n\t\t| \"show\"\n\t\t| \"finalize\"\n\t\t| \"implement-here\"\n\t\t| \"implement-fresh\"\n\t\t| \"export\"\n\t\t| \"save\"\n\t\t| \"stay\"\n\t\t| \"exit\";\n\tconst menu = defineMenu<undefined, Screen, Action, ExtensionContext>({\n\t\tstart: \"main\",\n\t\tscreens: {\n\t\t\t...implementation.screens,\n\t\t\tmain: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: current ? \"Plan mode\" : \"Proposed plan ready. What next?\",\n\t\t\t\tlines: [\n\t\t\t\t\t...(current ? [current.statusText] : []),\n\t\t\t\t\t...(ready\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\"Implement here keeps this planning conversation.\",\n\t\t\t\t\t\t\t\t\"Start fresh transfers only the approved plan to a new session.\",\n\t\t\t\t\t\t\t\toptions.implementationOutcome(),\n\t\t\t\t\t\t\t\timplementation.summary(),\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t\titems: ready\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t...(current\n\t\t\t\t\t\t\t\t? [{ id: \"show\", label: \"Show latest proposed plan\", action: \"show\" as const }]\n\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tid: \"implement-here\",\n\t\t\t\t\t\t\t\tlabel: \"Implement here\",\n\t\t\t\t\t\t\t\tdescription: \"Continue in this session with the planning conversation.\",\n\t\t\t\t\t\t\t\taction: \"implement-here\",\n\t\t\t\t\t\t\t\tbusyLabel: \"Preparing implementation\u2026\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tid: \"implement-fresh\",\n\t\t\t\t\t\t\t\tlabel: \"Start fresh and implement\",\n\t\t\t\t\t\t\t\tdescription: \"Open a new linked session; transfer only the approved plan.\",\n\t\t\t\t\t\t\t\taction: \"implement-fresh\",\n\t\t\t\t\t\t\t\tbusyLabel: \"Starting fresh implementation session\u2026\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tid: \"implementation-options\",\n\t\t\t\t\t\t\t\tlabel: \"Implementation options\u2026\",\n\t\t\t\t\t\t\t\tto: \"implementation-options\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ id: \"export\", label: \"Export plan\u2026\", to: \"export\" },\n\t\t\t\t\t\t\t{ id: \"save\", label: \"Save for later\", action: \"save\" },\n\t\t\t\t\t\t\t{ id: \"stay\", label: \"Stay in Plan mode\", action: \"stay\" },\n\t\t\t\t\t\t\t{ id: \"exit\", label: \"Discard plan and exit\", action: \"exit\" },\n\t\t\t\t\t\t]\n\t\t\t\t\t: [\n\t\t\t\t\t\t\t{ id: \"finalize\", label: \"Request final plan\", action: \"finalize\" },\n\t\t\t\t\t\t\t{ id: \"stay\", label: \"Stay in Plan mode\", action: \"stay\" },\n\t\t\t\t\t\t\t{ id: \"exit\", label: \"Exit Plan mode\", action: \"exit\" },\n\t\t\t\t\t\t],\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t\texport: () => planExportInputScreen(options.getExportDestination),\n\t\t},\n\t\tactions: {\n\t\t\t...implementation.actions,\n\t\t\tshow: async () => {\n\t\t\t\tcurrent?.show();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tfinalize: async () => {\n\t\t\t\tcurrent?.finalize();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"implement-here\": async ({ signal }) => {\n\t\t\t\tawait options.implementHere(implementation.get(), signal);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"implement-fresh\": async ({ signal }) => {\n\t\t\t\tawait options.implementFresh(signal, implementation.get());\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\texport: async ({ value, signal }) =>\n\t\t\t\t(await options.exportPlan(value ?? \"\", signal)) ? { kind: \"close\" } : { kind: \"rejected\" },\n\t\t\tsave: async () => {\n\t\t\t\toptions.save();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tstay: async () => {\n\t\t\t\toptions.stay();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\texit: async () => {\n\t\t\t\toptions.exit();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: options.signal,\n\t\tisCurrent: options.isCurrent,\n\t});\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport type { ChoiceScreen, SettingsScreen } from \"@narumitw/pi-tui-kit\";\nimport { safeImplementationText as terminalText } from \"./implementation-preferences.js\";\nimport { type ImplementationPreferences, PLAN_MODE_THINKING_LEVELS } from \"./settings.js\";\n\nexport function implementationModelLabel(model: ImplementationPreferences[\"implementationModel\"]) {\n\treturn model ? terminalText(`${model.provider} / ${model.id}`) : \"Use current\";\n}\n\nexport function implementationSummary(preferences: ImplementationPreferences) {\n\treturn `Model: ${implementationModelLabel(preferences.implementationModel)} \u00B7 Thinking: ${preferences.implementationThinkingLevel && preferences.implementationThinkingLevel !== \"inherit\" ? preferences.implementationThinkingLevel : \"Use normal behavior\"}`;\n}\n\nexport type ImplementationOptionAction =\n\t| \"open-implementation-model\"\n\t| \"set-implementation-model\"\n\t| \"set-implementation-thinking\";\n\nexport function implementationSettingItems(\n\tpreferences: ImplementationPreferences,\n): SettingsScreen<ImplementationOptionAction>[\"items\"] {\n\treturn [\n\t\t{\n\t\t\tid: \"implementationModel\",\n\t\t\tlabel: \"Implementation model\",\n\t\t\tcurrentValue: implementationModelLabel(preferences.implementationModel),\n\t\t\tdescription:\n\t\t\t\t\"Select the model only when implementation starts; never switch back automatically.\",\n\t\t\taction: \"open-implementation-model\",\n\t\t},\n\t\t{\n\t\t\tid: \"implementationThinkingLevel\",\n\t\t\tlabel: \"Implementation thinking\",\n\t\t\tcurrentValue: preferences.implementationThinkingLevel ?? \"inherit\",\n\t\t\tvalues: PLAN_MODE_THINKING_LEVELS,\n\t\t\tdescription:\n\t\t\t\t\"inherit preserves normal behavior, including restoration of Plan thinking. Explicit levels apply after model selection and are clamped by Pi.\",\n\t\t\taction: \"set-implementation-thinking\",\n\t\t},\n\t];\n}\n\nexport function createImplementationModelPicker(ctx: ExtensionContext) {\n\t// Snapshot Pi's scoped catalogue without network refresh or auth execution.\n\t// Unlike /model, this picker stages a preference and never persists Pi defaults.\n\tconst models = ctx.scopedModels?.length\n\t\t? ctx.scopedModels.map(({ model }) => model)\n\t\t: ctx.modelRegistry.getAvailable();\n\tconst byId = new Map(\n\t\tmodels.map((model, index) => [\n\t\t\t`implementation-model:${index}`,\n\t\t\t{ provider: model.provider, id: model.id },\n\t\t]),\n\t);\n\treturn {\n\t\tselection(itemId: string) {\n\t\t\treturn itemId === \"implementation-current\" ? null : byId.get(itemId);\n\t\t},\n\t\tscreen(preferences: ImplementationPreferences): ChoiceScreen<\"set-implementation-model\"> {\n\t\t\treturn {\n\t\t\t\tkind: \"choice\",\n\t\t\t\ttitle: \"Implementation model\",\n\t\t\t\tenableSearch: true,\n\t\t\t\tviewportSize: 10,\n\t\t\t\thint: \"back\",\n\t\t\t\taction: \"set-implementation-model\",\n\t\t\t\tlines: [\n\t\t\t\t\t\"Use current makes no model change. Reopen this menu to refresh the catalogue.\",\n\t\t\t\t\t\"Implement here sends the planning conversation to the selected provider; fresh transfers only the approved plan and normal destination resources.\",\n\t\t\t\t\t`Selected: ${implementationModelLabel(preferences.implementationModel)}`,\n\t\t\t\t],\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"implementation-current\", label: \"Use current\" },\n\t\t\t\t\t...[...byId].map(([id, model]) => ({ id, label: implementationModelLabel(model) })),\n\t\t\t\t],\n\t\t\t};\n\t\t},\n\t};\n}\n\n/** Local draft lives only as long as the owning action menu. */\nexport function createImplementationOptions(\n\tctx: ExtensionContext,\n\tinitial: ImplementationPreferences = {},\n) {\n\tlet preferences = { ...initial };\n\tlet picker: ReturnType<typeof createImplementationModelPicker> | undefined;\n\treturn {\n\t\tget: () => preferences,\n\t\tsummary: () => implementationSummary(preferences),\n\t\tscreens: {\n\t\t\t\"implementation-options\": (): SettingsScreen<ImplementationOptionAction> => ({\n\t\t\t\tkind: \"settings\",\n\t\t\t\ttitle: \"Implementation options\",\n\t\t\t\tlines: [\n\t\t\t\t\t\"Applies to both implementation actions in this menu only.\",\n\t\t\t\t\t\"Changes take effect only when implementation starts. No automatic restoration afterwards.\",\n\t\t\t\t\t`Current model: ${implementationModelLabel(ctx.model)}`,\n\t\t\t\t\t\"inherit keeps normal thinking behavior, not necessarily the temporary Plan thinking level.\",\n\t\t\t\t],\n\t\t\t\titems: implementationSettingItems(preferences),\n\t\t\t}),\n\t\t\t\"implementation-model\": () => {\n\t\t\t\tpicker ??= createImplementationModelPicker(ctx);\n\t\t\t\treturn picker.screen(preferences);\n\t\t\t},\n\t\t},\n\t\tactions: {\n\t\t\t\"open-implementation-model\": async () => ({\n\t\t\t\tkind: \"to\" as const,\n\t\t\t\tscreen: \"implementation-model\" as const,\n\t\t\t}),\n\t\t\t\"set-implementation-model\": async ({ itemId }: { itemId: string }) => {\n\t\t\t\tconst selected = picker?.selection(itemId);\n\t\t\t\tif (selected === undefined) return { kind: \"rejected\" as const };\n\t\t\t\tpreferences = { ...preferences, implementationModel: selected ?? undefined };\n\t\t\t\treturn { kind: \"back\" as const };\n\t\t\t},\n\t\t\t\"set-implementation-thinking\": async ({ value }: { value?: string }) => {\n\t\t\t\tconst level = PLAN_MODE_THINKING_LEVELS.find((level) => level === value);\n\t\t\t\tif (!level) return { kind: \"rejected\" as const };\n\t\t\t\tpreferences = { ...preferences, implementationThinkingLevel: level };\n\t\t\t\treturn { kind: \"stay\" as const };\n\t\t\t},\n\t\t},\n\t};\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\n\nexport interface PlanLaunchTool {\n\tname: string;\n\tlabel?: string;\n\tdescription: string;\n\tsearchText: string;\n\tdisabled: boolean;\n\tdisabledReason?: string;\n}\n\ninterface PlanLaunchMenuOptions {\n\tstatusText: string;\n\ttoolSummary(selectedNames: ReadonlySet<string>): string;\n\tgetSelectedNames(): ReadonlySet<string>;\n\ttools: readonly PlanLaunchTool[];\n\tsignal: AbortSignal;\n\tisCurrent(): boolean;\n\tinitialScreen?: \"main\" | \"tools\";\n\tstart(signal: AbortSignal): void;\n\tstartWithTools(toolNames: string[], signal: AbortSignal): void;\n\tsettings(signal: AbortSignal): Promise<boolean>;\n}\n\nexport async function showPlanLaunchMenu(ctx: ExtensionContext, options: PlanLaunchMenuOptions) {\n\ttype Screen = \"main\" | \"tools\" | \"help\";\n\ttype Action = \"start\" | \"toggle-tool\" | \"start-with-tools\" | \"settings\";\n\tconst selectedNames = new Set(options.getSelectedNames());\n\tconst toolItems = options.tools.map((tool, index) => ({\n\t\tid: `plan-tool:${index}`,\n\t\ttool,\n\t}));\n\tconst toolsByItemId = new Map(toolItems.map(({ id, tool }) => [id, tool]));\n\tlet draftChanged = false;\n\tconst menu = defineMenu<undefined, Screen, Action, ExtensionContext>({\n\t\tstart: options.initialScreen ?? \"main\",\n\t\tscreens: {\n\t\t\tmain: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Plan mode\",\n\t\t\t\tlines: [options.statusText, options.toolSummary(selectedNames)],\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"start\", label: \"Start Plan mode\", action: \"start\" },\n\t\t\t\t\t{ id: \"tools\", label: \"Choose tools, then start\u2026\", to: \"tools\" },\n\t\t\t\t\t{ id: \"settings\", label: \"Settings\", action: \"settings\" },\n\t\t\t\t\t{ id: \"help\", label: \"How Plan mode works\", to: \"help\" },\n\t\t\t\t],\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t\ttools: () => ({\n\t\t\t\tkind: \"multiSelect\",\n\t\t\t\ttitle: \"Choose Plan policy allowlist\",\n\t\t\t\tlines: [\n\t\t\t\t\t\"Policy changes apply only when you start Plan mode; first use may also reveal Plan helpers.\",\n\t\t\t\t\toptions.toolSummary(selectedNames),\n\t\t\t\t\t\"Active tools can be chosen now; retained names resolve before the first request.\",\n\t\t\t\t\t\"Plan mode never activates tools, and non-built-ins run at user risk.\",\n\t\t\t\t],\n\t\t\t\tenableSearch: true,\n\t\t\t\tviewportSize: 10,\n\t\t\t\titems: toolItems.map(({ id, tool }) => ({\n\t\t\t\t\tid,\n\t\t\t\t\tlabel: tool.label ?? tool.name,\n\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\tsearchText: tool.searchText,\n\t\t\t\t\tselected: selectedNames.has(tool.name),\n\t\t\t\t\tdisabled: tool.disabled,\n\t\t\t\t\tdisabledReason: tool.disabledReason,\n\t\t\t\t})),\n\t\t\t\taction: \"toggle-tool\",\n\t\t\t\tactions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"start-with-tools\",\n\t\t\t\t\t\tlabel: \"Done \u2014 start with this policy\",\n\t\t\t\t\t\taction: \"start-with-tools\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\thelp: () => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"How Plan mode works\",\n\t\t\t\tlines: [\n\t\t\t\t\t\"Plan mode uses read-only exploration to understand the project before implementation.\",\n\t\t\t\t\t\"The agent can ask important decision questions, then returns a complete implementation-ready plan.\",\n\t\t\t\t\t\"File mutation stays blocked until you explicitly choose to implement the completed plan.\",\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tstart: async ({ signal }) => {\n\t\t\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n\t\t\t\toptions.start(signal);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"toggle-tool\": async ({ itemId, selected, signal }) => {\n\t\t\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n\t\t\t\tconst tool = itemId ? toolsByItemId.get(itemId) : undefined;\n\t\t\t\tif (!tool || tool.disabled) return { kind: \"rejected\" };\n\t\t\t\tif (selected) selectedNames.add(tool.name);\n\t\t\t\telse selectedNames.delete(tool.name);\n\t\t\t\tdraftChanged = true;\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\t\"start-with-tools\": async ({ signal }) => {\n\t\t\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n\t\t\t\toptions.startWithTools(Array.from(selectedNames), signal);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tsettings: async ({ signal }) => {\n\t\t\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n\t\t\t\tconst close = await options.settings(signal);\n\t\t\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n\t\t\t\tif (close) return { kind: \"close\" };\n\t\t\t\tif (!draftChanged) {\n\t\t\t\t\tselectedNames.clear();\n\t\t\t\t\tfor (const name of options.getSelectedNames()) selectedNames.add(name);\n\t\t\t\t}\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: options.signal,\n\t\tisCurrent: options.isCurrent,\n\t});\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport {\n\tcreateImplementationOptions,\n\ttype ImplementationOptionAction,\n} from \"./implementation-options.js\";\nimport { type PlanExportDestinationProvider, planExportInputScreen } from \"./plan-export-screen.js\";\nimport type { ImplementationPreferences } from \"./settings.js\";\n\ninterface SavedPlanMenuOptions {\n\tstatusText: string;\n\timplementationOutcome(): string;\n\tgetExportDestination: PlanExportDestinationProvider;\n\tsignal: AbortSignal;\n\tisCurrent(): boolean;\n\tshow(): void;\n\timplementationPreferences?: ImplementationPreferences;\n\timplementHere(\n\t\tpreferences?: ImplementationPreferences,\n\t\tsignal?: AbortSignal,\n\t): void | Promise<void>;\n\timplementFresh(\n\t\tsignal: AbortSignal,\n\t\tpreferences?: ImplementationPreferences,\n\t): void | Promise<void>;\n\texportPlan(path: string, signal: AbortSignal): Promise<boolean>;\n\tsettings(signal: AbortSignal): Promise<boolean>;\n\tclear(): void;\n}\n\nexport async function showSavedPlanMenu(ctx: ExtensionContext, options: SavedPlanMenuOptions) {\n\tif (!ctx.hasUI) {\n\t\tthrow new Error(\n\t\t\t`${options.statusText} Use /plan show, /plan implement, /plan export, or /plan exit.`,\n\t\t);\n\t}\n\tconst implementation = createImplementationOptions(ctx, options.implementationPreferences);\n\ttype Screen = \"saved\" | \"export\" | \"implementation-options\" | \"implementation-model\";\n\ttype Action =\n\t\t| ImplementationOptionAction\n\t\t| \"show\"\n\t\t| \"implement-here\"\n\t\t| \"implement-fresh\"\n\t\t| \"export\"\n\t\t| \"settings\"\n\t\t| \"clear\";\n\tconst menu = defineMenu<undefined, Screen, Action, ExtensionContext>({\n\t\tstart: \"saved\",\n\t\tscreens: {\n\t\t\t...implementation.screens,\n\t\t\tsaved: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Saved plan\",\n\t\t\t\tlines: [\n\t\t\t\t\toptions.statusText,\n\t\t\t\t\t\"Implement here keeps this planning conversation.\",\n\t\t\t\t\t\"Start fresh transfers only the approved plan to a new session.\",\n\t\t\t\t\toptions.implementationOutcome(),\n\t\t\t\t\timplementation.summary(),\n\t\t\t\t],\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"show\", label: \"Show saved plan\", action: \"show\" },\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"implement-here\",\n\t\t\t\t\t\tlabel: \"Implement here\",\n\t\t\t\t\t\tdescription: \"Continue in this session with the planning conversation.\",\n\t\t\t\t\t\taction: \"implement-here\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"implement-fresh\",\n\t\t\t\t\t\tlabel: \"Start fresh and implement\",\n\t\t\t\t\t\tdescription: \"Open a new linked session; transfer only the approved plan.\",\n\t\t\t\t\t\taction: \"implement-fresh\",\n\t\t\t\t\t\tbusyLabel: \"Starting fresh implementation session\u2026\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"implementation-options\",\n\t\t\t\t\t\tlabel: \"Implementation options\u2026\",\n\t\t\t\t\t\tto: \"implementation-options\",\n\t\t\t\t\t},\n\t\t\t\t\t{ id: \"export\", label: \"Export plan\u2026\", to: \"export\" },\n\t\t\t\t\t{ id: \"settings\", label: \"Settings\", action: \"settings\" },\n\t\t\t\t\t{ id: \"clear\", label: \"Clear saved plan\", action: \"clear\" },\n\t\t\t\t],\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t\texport: () => planExportInputScreen(options.getExportDestination),\n\t\t},\n\t\tactions: {\n\t\t\t...implementation.actions,\n\t\t\tshow: async () => {\n\t\t\t\toptions.show();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"implement-here\": async ({ signal }) => {\n\t\t\t\tawait options.implementHere(implementation.get(), signal);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\t\"implement-fresh\": async ({ signal }) => {\n\t\t\t\tawait options.implementFresh(signal, implementation.get());\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\texport: async ({ value, signal }) =>\n\t\t\t\t(await options.exportPlan(value ?? \"\", signal)) ? { kind: \"close\" } : { kind: \"rejected\" },\n\t\t\tsettings: async ({ signal }) => {\n\t\t\t\tconst close = await options.settings(signal);\n\t\t\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n\t\t\t\treturn close ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t},\n\t\t\tclear: async () => {\n\t\t\t\toptions.clear();\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: options.signal,\n\t\tisCurrent: options.isCurrent,\n\t});\n}\n", "import type { ExtensionContext, ToolInfo } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, type RunMenuResult, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { PLAN_MODE_COMPLETE_TOOL_NAME } from \"./completion-tool.js\";\nimport {\n\tcreateImplementationModelPicker,\n\ttype ImplementationOptionAction,\n\timplementationSettingItems,\n} from \"./implementation-options.js\";\nimport { retentionLabel } from \"./implementation-retention.js\";\nimport { planExportDestination } from \"./plan-export.js\";\nimport { PLAN_MODE_QUESTION_TOOL_NAME } from \"./question-tool.js\";\nimport {\n\tconfiguredImplementationPlanRetention,\n\tconfiguredPlanExportPath,\n\tconfiguredPlanModeToggleShortcut,\n\tIMPLEMENTATION_PLAN_RETENTIONS,\n\tnormalizeKeyId,\n\tPLAN_MODE_THINKING_LEVELS,\n\ttype PlanModeSettings,\n\ttype PlanModeSettingsLoadResult,\n\ttype PlanModeSettingsPatch,\n\tplanModeSettingsPath,\n\treadPlanModeSettings,\n\ttype UpdatePlanModeSettingsOptions,\n\tupdatePlanModeSettings,\n} from \"./settings.js\";\nimport { canSelectToolInPlanMode } from \"./tool-policy.js\";\nimport { defaultPlanModeToolNames, toolPolicyLabel } from \"./tool-selection.js\";\n\ninterface SettingsMenuState {\n\tkind: \"valid\" | \"invalid\";\n\tsettings: PlanModeSettings;\n\tnotice?: string;\n\treason?: string;\n}\n\nexport interface PlanModeSettingsMenuOptions {\n\ttools: readonly ToolInfo[];\n\tactiveToolNames?: readonly string[];\n\tsignal: AbortSignal;\n\tisCurrent(): boolean;\n\tsettingsPath?: string;\n\tlegacySettingsPath?: string;\n\treadSettings?: (settingsPath?: string) => Promise<PlanModeSettingsLoadResult>;\n\tupdateSettings?: (\n\t\tpatch: PlanModeSettingsPatch,\n\t\toptions?: UpdatePlanModeSettingsOptions,\n\t) => Promise<PlanModeSettings>;\n\tonSaved(settings: PlanModeSettings): void;\n}\n\ntype Screen = \"settings\" | \"tools\" | \"export\" | \"shortcut\" | \"implementation-model\";\ntype Action =\n\t| ImplementationOptionAction\n\t| \"set-thinking\"\n\t| \"open-tools\"\n\t| \"toggle-tool\"\n\t| \"reset-tools\"\n\t| \"set-retention\"\n\t| \"open-export\"\n\t| \"set-export\"\n\t| \"open-shortcut\"\n\t| \"set-shortcut\";\n\nexport async function showPlanModeSettings(\n\tctx: ExtensionContext,\n\toptions: PlanModeSettingsMenuOptions,\n): Promise<RunMenuResult> {\n\tconst settingsPath = options.settingsPath ?? planModeSettingsPath();\n\tconst readSettings = options.readSettings ?? readPlanModeSettings;\n\tconst updateSettings = options.updateSettings ?? updatePlanModeSettings;\n\tconst activeToolNames = new Set(\n\t\toptions.activeToolNames ?? options.tools.map((tool) => tool.name),\n\t);\n\tconst tools = options.tools.filter(\n\t\t(tool) =>\n\t\t\ttool.name !== PLAN_MODE_QUESTION_TOOL_NAME && tool.name !== PLAN_MODE_COMPLETE_TOOL_NAME,\n\t);\n\tconst toolItemIds = new Map(\n\t\ttools.map((tool, index) => [tool.name, `plan-settings-tool:${index}`]),\n\t);\n\tconst toolsByItemId = new Map(tools.map((tool) => [toolItemIds.get(tool.name) as string, tool]));\n\n\tconst loadState = async (): Promise<SettingsMenuState> => {\n\t\tconst loaded = await readSettings(options.settingsPath);\n\t\tif (loaded.kind === \"invalid\") {\n\t\t\treturn {\n\t\t\t\tkind: \"invalid\",\n\t\t\t\tsettings: { thinkingLevel: \"inherit\" },\n\t\t\t\tnotice: loaded.notice,\n\t\t\t\treason: loaded.reason,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tkind: \"valid\",\n\t\t\tsettings: loaded.kind === \"loaded\" ? loaded.settings : { thinkingLevel: \"inherit\" },\n\t\t\tnotice: loaded.notice,\n\t\t};\n\t};\n\n\tlet implementationPicker: ReturnType<typeof createImplementationModelPicker> | undefined;\n\tconst menu = defineMenu<SettingsMenuState, Screen, Action, ExtensionContext>({\n\t\tstart: \"settings\",\n\t\tscreens: {\n\t\t\tsettings: ({ state }) =>\n\t\t\t\tstate.kind === \"invalid\"\n\t\t\t\t\t? invalidScreen(settingsPath, state)\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tkind: \"settings\",\n\t\t\t\t\t\t\ttitle: \"Plan Mode Settings\",\n\t\t\t\t\t\t\tlines: settingsLines(settingsPath, state.notice),\n\t\t\t\t\t\t\titems: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"thinkingLevel\",\n\t\t\t\t\t\t\t\t\tlabel: \"Plan thinking\",\n\t\t\t\t\t\t\t\t\tdescription: \"Set the thinking level when the next Plan workflow starts.\",\n\t\t\t\t\t\t\t\t\tcurrentValue: state.settings.thinkingLevel,\n\t\t\t\t\t\t\t\t\tvalues: PLAN_MODE_THINKING_LEVELS,\n\t\t\t\t\t\t\t\t\taction: \"set-thinking\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"defaultPlanTools\",\n\t\t\t\t\t\t\t\t\tlabel: \"Plan policy tools\",\n\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\"Choose active tools or retain names to resolve before the first request.\",\n\t\t\t\t\t\t\t\t\tcurrentValue: defaultToolsValue(state.settings.defaultPlanTools),\n\t\t\t\t\t\t\t\t\taction: \"open-tools\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"implementationPlanRetention\",\n\t\t\t\t\t\t\t\t\tlabel: \"Plan reinjection\",\n\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\"Choose how long Plan mode restores the exact plan when ordinary context no longer contains it.\",\n\t\t\t\t\t\t\t\t\tcurrentValue: retentionLabel(\n\t\t\t\t\t\t\t\t\t\tconfiguredImplementationPlanRetention(state.settings),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\tvalues: IMPLEMENTATION_PLAN_RETENTIONS.map(retentionLabel),\n\t\t\t\t\t\t\t\t\taction: \"set-retention\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"defaultPlanExportPath\",\n\t\t\t\t\t\t\t\t\tlabel: \"Export destination\",\n\t\t\t\t\t\t\t\t\tdescription: \"Set the destination used when an export omits its path.\",\n\t\t\t\t\t\t\t\t\tcurrentValue: safeTerminalText(configuredPlanExportPath(state.settings)),\n\t\t\t\t\t\t\t\t\taction: \"open-export\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tid: \"toggleShortcut\",\n\t\t\t\t\t\t\t\t\tlabel: \"Plan mode shortcut\",\n\t\t\t\t\t\t\t\t\tdescription: \"Set the global shortcut used to toggle Plan mode.\",\n\t\t\t\t\t\t\t\t\tcurrentValue: configuredPlanModeToggleShortcut(state.settings) ?? \"none\",\n\t\t\t\t\t\t\t\t\taction: \"open-shortcut\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t...implementationSettingItems(state.settings),\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\"implementation-model\": ({ state }) => {\n\t\t\t\timplementationPicker ??= createImplementationModelPicker(ctx);\n\t\t\t\treturn implementationPicker.screen(state.settings);\n\t\t\t},\n\t\t\ttools: ({ state }) => ({\n\t\t\t\tkind: \"multiSelect\",\n\t\t\t\ttitle: \"Default Plan policy allowlist\",\n\t\t\t\tlines: [\n\t\t\t\t\t\"Changes apply when a later Plan workflow starts; model-visible tools stay unchanged.\",\n\t\t\t\t\t\"Retained inactive names resolve before that workflow's first request.\",\n\t\t\t\t\t\"Plan mode never activates tools, and non-built-ins run at user risk.\",\n\t\t\t\t],\n\t\t\t\tenableSearch: true,\n\t\t\t\tviewportSize: 10,\n\t\t\t\titems: defaultToolItems(\n\t\t\t\t\ttools,\n\t\t\t\t\tstate.settings.defaultPlanTools,\n\t\t\t\t\tactiveToolNames,\n\t\t\t\t\ttoolItemIds,\n\t\t\t\t),\n\t\t\t\taction: \"toggle-tool\",\n\t\t\t\tactions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"reset-tools\",\n\t\t\t\t\t\tlabel: \"Use automatic safe built-ins\",\n\t\t\t\t\t\taction: \"reset-tools\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\texport: ({ state }) => {\n\t\t\t\tconst configured = configuredPlanExportPath(state.settings);\n\t\t\t\tconst destination = planExportDestination(configured, ctx.cwd);\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"input\",\n\t\t\t\t\ttitle: \"Export destination\",\n\t\t\t\t\tlines: [\n\t\t\t\t\t\t`Configured: ${destination.configuredPath}`,\n\t\t\t\t\t\t`Resolves here to: ${destination.resolvedPath}`,\n\t\t\t\t\t\t\"Submit an empty value to reset to PLAN.md. Changes affect the next export.\",\n\t\t\t\t\t],\n\t\t\t\t\tplaceholder: configured,\n\t\t\t\t\taction: \"set-export\",\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tshortcut: ({ state }) => ({\n\t\t\t\tkind: \"input\",\n\t\t\t\ttitle: \"Plan mode shortcut\",\n\t\t\t\tlines: [\n\t\t\t\t\t`Configured: ${configuredPlanModeToggleShortcut(state.settings) ?? \"none\"}`,\n\t\t\t\t\t\"Use Pi key identifiers.\",\n\t\t\t\t\t\"Submit an empty value to clear the shortcut.\",\n\t\t\t\t\t\"When unset, Plan mode has no global shortcut.\",\n\t\t\t\t],\n\t\t\t\tplaceholder: configuredPlanModeToggleShortcut(state.settings) ?? \"\",\n\t\t\t\taction: \"set-shortcut\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\t\"open-implementation-model\": async () => ({ kind: \"to\", screen: \"implementation-model\" }),\n\t\t\t\"set-implementation-model\": async ({ ctx: actionCtx, itemId, signal }) => {\n\t\t\t\tconst model = implementationPicker?.selection(itemId);\n\t\t\t\tif (model === undefined) return { kind: \"rejected\" };\n\t\t\t\tconst result = await savePatch(\n\t\t\t\t\tactionCtx,\n\t\t\t\t\t{ implementationModel: model },\n\t\t\t\t\tsignal,\n\t\t\t\t\t\"Implementation model saved. Applies when implementation starts.\",\n\t\t\t\t);\n\t\t\t\treturn result.kind === \"stay\" ? { kind: \"back\" } : result;\n\t\t\t},\n\t\t\t\"set-implementation-thinking\": async ({ ctx: actionCtx, value, signal }) => {\n\t\t\t\tconst level = PLAN_MODE_THINKING_LEVELS.find((level) => level === value);\n\t\t\t\tif (!level) return { kind: \"rejected\" };\n\t\t\t\treturn savePatch(\n\t\t\t\t\tactionCtx,\n\t\t\t\t\t{ implementationThinkingLevel: level },\n\t\t\t\t\tsignal,\n\t\t\t\t\t\"Implementation thinking saved. Applies when implementation starts.\",\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"set-thinking\": async ({ ctx: actionCtx, value, signal }) => {\n\t\t\t\tif (\n\t\t\t\t\t!PLAN_MODE_THINKING_LEVELS.includes(value as (typeof PLAN_MODE_THINKING_LEVELS)[number])\n\t\t\t\t) {\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t\treturn savePatch(\n\t\t\t\t\tactionCtx,\n\t\t\t\t\t{ thinkingLevel: value as PlanModeSettings[\"thinkingLevel\"] },\n\t\t\t\t\tsignal,\n\t\t\t\t\t`Plan mode thinking level: ${value}. Applies to the next Plan workflow.`,\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"open-tools\": async () => ({ kind: \"to\", screen: \"tools\" }),\n\t\t\t\"set-retention\": async ({ ctx: actionCtx, value, signal }) => {\n\t\t\t\tconst implementationPlanRetention = retentionFromLabel(value);\n\t\t\t\tif (!implementationPlanRetention) return { kind: \"rejected\" };\n\t\t\t\treturn savePatch(\n\t\t\t\t\tactionCtx,\n\t\t\t\t\t{ implementationPlanRetention },\n\t\t\t\t\tsignal,\n\t\t\t\t\t`Plan reinjection: ${retentionLabel(implementationPlanRetention)}. Applies to the next Implement action.`,\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"open-export\": async () => ({ kind: \"to\", screen: \"export\" }),\n\t\t\t\"set-export\": async ({ ctx: actionCtx, value, signal }) => {\n\t\t\t\tconst defaultPlanExportPath = value?.trim() || null;\n\t\t\t\tconst result = await savePatch(\n\t\t\t\t\tactionCtx,\n\t\t\t\t\t{ defaultPlanExportPath },\n\t\t\t\t\tsignal,\n\t\t\t\t\tdefaultPlanExportPath\n\t\t\t\t\t\t? `Default Plan export destination: ${safeTerminalText(defaultPlanExportPath)}.`\n\t\t\t\t\t\t: \"Default Plan export destination reset to PLAN.md.\",\n\t\t\t\t);\n\t\t\t\treturn result.kind === \"stay\" ? { kind: \"to\", screen: \"settings\" } : result;\n\t\t\t},\n\t\t\t\"open-shortcut\": async () => ({ kind: \"to\", screen: \"shortcut\" }),\n\t\t\t\"set-shortcut\": async ({ ctx: actionCtx, value, signal }) => {\n\t\t\t\tconst raw = value?.trim() || null;\n\t\t\t\tif (raw && !normalizeKeyId(raw)) {\n\t\t\t\t\tactionCtx.ui.notify(\n\t\t\t\t\t\t`Invalid key identifier: ${safeTerminalText(raw)}. Use Pi key identifiers like ctrl+alt+p.`,\n\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"stay\" as const };\n\t\t\t\t}\n\t\t\t\tconst toggleShortcut = raw as PlanModeSettingsPatch[\"toggleShortcut\"];\n\t\t\t\tconst result = await savePatch(\n\t\t\t\t\tactionCtx,\n\t\t\t\t\t{ toggleShortcut },\n\t\t\t\t\tsignal,\n\t\t\t\t\ttoggleShortcut\n\t\t\t\t\t\t? `Plan mode shortcut: ${safeTerminalText(toggleShortcut)}.`\n\t\t\t\t\t\t: \"Plan mode shortcut cleared (no global shortcut).\",\n\t\t\t\t);\n\t\t\t\treturn result.kind === \"stay\" ? { kind: \"to\", screen: \"settings\" } : result;\n\t\t\t},\n\t\t\t\"toggle-tool\": async ({ ctx: actionCtx, state, itemId, selected, signal }) => {\n\t\t\t\tconst tool = itemId ? toolsByItemId.get(itemId) : undefined;\n\t\t\t\tif (!tool || !activeToolNames.has(tool.name) || !canSelectToolInPlanMode(tool)) {\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t\tconst names = explicitToolNames(tools, state.settings.defaultPlanTools);\n\t\t\t\tconst next = selected\n\t\t\t\t\t? Array.from(new Set([...names, tool.name]))\n\t\t\t\t\t: names.filter((name) => name !== tool.name);\n\t\t\t\treturn savePatch(\n\t\t\t\t\tactionCtx,\n\t\t\t\t\t{ defaultPlanTools: next },\n\t\t\t\t\tsignal,\n\t\t\t\t\t`Default Plan policy: ${next.length === 0 ? \"no optional tools\" : `${next.length} allowed`}.`,\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"reset-tools\": async ({ ctx: actionCtx, state, signal }) => {\n\t\t\t\tif (state.settings.defaultPlanTools === undefined) return { kind: \"stay\" };\n\t\t\t\treturn savePatch(\n\t\t\t\t\tactionCtx,\n\t\t\t\t\t{ defaultPlanTools: null },\n\t\t\t\t\tsignal,\n\t\t\t\t\t\"Default Plan-mode tools: automatic safe built-ins.\",\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t});\n\n\treturn runMenu(ctx, menu, {\n\t\tgetState: loadState,\n\t\tsignal: options.signal,\n\t\tisCurrent: options.isCurrent,\n\t});\n\n\tasync function savePatch(\n\t\tactionCtx: ExtensionContext,\n\t\tpatch: PlanModeSettingsPatch,\n\t\tsignal: AbortSignal,\n\t\tsuccessMessage: string,\n\t) {\n\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" as const };\n\t\ttry {\n\t\t\tconst saved = await updateSettings(patch, {\n\t\t\t\tsettingsPath: options.settingsPath,\n\t\t\t\tlegacySettingsPath: options.legacySettingsPath,\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tif (options.isCurrent()) options.onSaved(saved);\n\t\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" as const };\n\t\t\tactionCtx.ui.notify(successMessage, \"info\");\n\t\t\treturn { kind: \"stay\" as const };\n\t\t} catch (error) {\n\t\t\tif (!signal.aborted && options.isCurrent()) {\n\t\t\t\tactionCtx.ui.notify(\n\t\t\t\t\t`Could not save Plan mode settings; the previous value remains: ${safeTerminalText(formatError(error))}`,\n\t\t\t\t\t\"error\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { kind: \"rejected\" as const };\n\t\t}\n\t}\n}\n\nfunction settingsLines(settingsPath: string, notice: string | undefined) {\n\treturn [\n\t\t`User settings \u00B7 ${safeTerminalText(settingsPath)}`,\n\t\t\"Plan defaults apply to the next workflow; reinjection and export choices apply to their next action.\",\n\t\t...(notice ? [safeTerminalText(notice)] : []),\n\t];\n}\n\nfunction invalidScreen(settingsPath: string, state: SettingsMenuState) {\n\treturn {\n\t\tkind: \"detail\" as const,\n\t\ttitle: \"Plan Mode Settings \u00B7 Read only\",\n\t\tlines: [\n\t\t\t`Invalid settings file. Fix ${safeTerminalText(settingsPath)} before saving.`,\n\t\t\tsafeTerminalText(state.reason ?? \"The settings file is invalid.\"),\n\t\t\t...(state.notice ? [safeTerminalText(state.notice)] : []),\n\t\t],\n\t\thint: \"back\" as const,\n\t};\n}\n\nfunction retentionFromLabel(value: string | undefined) {\n\treturn IMPLEMENTATION_PLAN_RETENTIONS.find((retention) => retentionLabel(retention) === value);\n}\n\nfunction defaultToolsValue(configured: string[] | undefined) {\n\tif (configured === undefined) return \"Automatic safe built-ins\";\n\tif (configured.length === 0) return \"No optional tools\";\n\treturn `${configured.length} selected`;\n}\n\nfunction defaultToolItems(\n\ttools: readonly ToolInfo[],\n\tconfigured: string[] | undefined,\n\tactiveToolNames: ReadonlySet<string>,\n\ttoolItemIds: ReadonlyMap<string, string>,\n) {\n\tconst selected = new Set(explicitToolNames(tools, configured));\n\tconst availableNames = new Set(tools.map((tool) => tool.name));\n\tconst items = tools.map((tool) => {\n\t\tconst active = activeToolNames.has(tool.name);\n\t\tconst selectable = active && canSelectToolInPlanMode(tool);\n\t\tconst policy = active\n\t\t\t? toolPolicyLabel(tool)\n\t\t\t: selected.has(tool.name)\n\t\t\t\t? \"not active yet; retained for first-request resolution\"\n\t\t\t\t: \"not active in this Pi session\";\n\t\tconst description = tool.description ?? \"No description available\";\n\t\treturn {\n\t\t\tid: toolItemIds.get(tool.name) as string,\n\t\t\tlabel: tool.name,\n\t\t\tdescription: `${policy} \u00B7 ${description}`,\n\t\t\tsearchText: `${policy} ${description}`,\n\t\t\tselected: selected.has(tool.name),\n\t\t\tdisabled: !selectable,\n\t\t\tdisabledReason: !active\n\t\t\t\t? selected.has(tool.name)\n\t\t\t\t\t? \"Not active yet; retained and resolved before the first request\"\n\t\t\t\t\t: \"Not active in Pi; Plan mode will not activate it\"\n\t\t\t\t: selectable\n\t\t\t\t\t? undefined\n\t\t\t\t\t: \"Blocked by Plan-mode policy\",\n\t\t};\n\t});\n\tfor (const [index, name] of (configured ?? []).entries()) {\n\t\tif (availableNames.has(name)) continue;\n\t\tconst label = terminalToolName(name);\n\t\titems.push({\n\t\t\tid: `plan-settings-pending:${index}`,\n\t\t\tlabel,\n\t\t\tdescription: \"pending registration \u00B7 Retained and resolved before the first request\",\n\t\t\tsearchText: `${label} pending registration retained settings first request`,\n\t\t\tselected: true,\n\t\t\tdisabled: true,\n\t\t\tdisabledReason: \"Not registered yet; reset defaults to remove retained names\",\n\t\t});\n\t}\n\treturn items;\n}\n\nfunction explicitToolNames(tools: readonly ToolInfo[], configured: string[] | undefined) {\n\treturn configured === undefined\n\t\t? defaultPlanModeToolNames([...tools], undefined)\n\t\t: [...configured];\n}\n\nfunction terminalToolName(value: string) {\n\tconst safe = safeTerminalText(value) || \"(unnamed tool)\";\n\treturn safe.length > 120 ? `${safe.slice(0, 119)}\u2026` : safe;\n}\n\nfunction safeTerminalText(value: string) {\n\treturn [...value]\n\t\t.map((character) => {\n\t\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\t\treturn codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? \" \" : character;\n\t\t})\n\t\t.join(\"\")\n\t\t.trim();\n}\n\nfunction formatError(error: unknown) {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;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F,SAAO,eAAe,SACnB,yBAAyB,CAAC,GAAG,KAAK,GAAG,MAAS,IAC9C,CAAC,GAAG,UAAU;AAClB;AAEA,SAAS,iBAAiB,OAAe;AACxC,QAAM,OAAO,iBAAiB,KAAK,KAAK;AACxC,SAAO,KAAK,SAAS,MAAM,GAAG,KAAK,MAAM,GAAG,GAAG,CAAC,WAAM;AACvD;AAEA,SAAS,iBAAiB,OAAe;AACxC,SAAO,CAAC,GAAG,KAAK,EACd,IAAI,CAAC,cAAc;AACnB,UAAM,YAAY,UAAU,YAAY,CAAC,KAAK;AAC9C,WAAO,aAAa,MAAS,aAAa,OAAQ,aAAa,MAAQ,MAAM;AAAA,EAC9E,CAAC,EACA,KAAK,EAAE,EACP,KAAK;AACR;AAEA,SAAS,YAAY,OAAgB;AACpC,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC7D;",
6
- "names": ["defineMenu", "runMenu", "level", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "level", "runMenu"]
7
- }
@@ -1,102 +0,0 @@
1
- import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import {
3
- createImplementationPreferenceChange,
4
- hasImplementationPreferences,
5
- type ImplementationSnapshot,
6
- preferenceError,
7
- preflightImplementationPreferences,
8
- sameModel,
9
- } from "./implementation-preferences.js";
10
- import { type ImplementationPreferences, normalizePlanModeSettings } from "./settings.js";
11
-
12
- export const FRESH_PREFERENCES_ENTRY = "plan-mode:fresh-preferences:v1";
13
-
14
- export interface FreshPreferencesRequest {
15
- id: string;
16
- status: "pending";
17
- preferences: ImplementationPreferences;
18
- }
19
-
20
- /** Called only for reason=new, with the destination instance's own API. */
21
- export async function applyFreshImplementationPreferences(
22
- pi: ExtensionAPI,
23
- ctx: ExtensionContext,
24
- isCurrent: () => boolean,
25
- selectionSnapshot?: () => ImplementationSnapshot | undefined,
26
- ) {
27
- if (!isCurrent() || !ctx.isIdle()) return;
28
- const entry = latestPreferenceEntry(ctx);
29
- if (entry?.type !== "custom" || !entry.data || typeof entry.data !== "object") return;
30
- const request = entry.data as Partial<FreshPreferencesRequest>;
31
- if (request.status !== "pending" || typeof request.id !== "string") return;
32
- const preferences = normalizePlanModeSettings(request.preferences);
33
- // Consume before any await. Reload/resume never replays a handoff selection.
34
- pi.appendEntry(FRESH_PREFERENCES_ENTRY, { id: request.id, status: "failed" });
35
- if (!preferences || !hasImplementationPreferences(preferences)) return;
36
- const change = createImplementationPreferenceChange(
37
- pi,
38
- ctx,
39
- isCurrent,
40
- undefined,
41
- selectionSnapshot,
42
- );
43
- try {
44
- const originalModel = ctx.model;
45
- const originalThinking = pi.getThinkingLevel();
46
- const current = () => isCurrent() && ctx.isIdle();
47
- const model = await preflightImplementationPreferences(
48
- ctx,
49
- preferences,
50
- () =>
51
- current() &&
52
- sameModel(ctx.model, originalModel) &&
53
- pi.getThinkingLevel() === originalThinking,
54
- );
55
- if (!model || !current()) return;
56
- if (!(await change.apply(model, preferences, current)) || !current()) {
57
- await change.rollback();
58
- return;
59
- }
60
- pi.appendEntry(FRESH_PREFERENCES_ENTRY, {
61
- id: request.id,
62
- status: "applied",
63
- model: { provider: ctx.model?.provider, id: ctx.model?.id },
64
- thinking: pi.getThinkingLevel(),
65
- });
66
- } catch (error) {
67
- if (!isCurrent()) return;
68
- await change.rollback().catch(() => undefined);
69
- if (!isCurrent()) return;
70
- pi.appendEntry(FRESH_PREFERENCES_ENTRY, {
71
- id: request.id,
72
- status: "failed",
73
- error: preferenceError(error),
74
- });
75
- }
76
- }
77
-
78
- /** No captured source API is usable here; inspect only the replacement context. */
79
- function latestPreferenceEntry(ctx: ExtensionContext) {
80
- return ctx.sessionManager
81
- .getBranch()
82
- .slice()
83
- .reverse()
84
- .find((entry) => entry.type === "custom" && entry.customType === FRESH_PREFERENCES_ENTRY);
85
- }
86
-
87
- export function freshPreferencesApplied(ctx: ExtensionContext, id: string) {
88
- const entry = latestPreferenceEntry(ctx);
89
- if (entry?.type !== "custom" || !entry.data || typeof entry.data !== "object") return false;
90
- const result = entry.data as {
91
- id?: string;
92
- status?: string;
93
- model?: { provider: string; id: string };
94
- thinking?: string;
95
- };
96
- return (
97
- result.id === id &&
98
- result.status === "applied" &&
99
- sameModel(ctx.model, result.model) &&
100
- ctx.thinkingLevel === result.thinking
101
- );
102
- }
@@ -1,127 +0,0 @@
1
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import type { ChoiceScreen, SettingsScreen } from "@narumitw/pi-tui-kit";
3
- import { safeImplementationText as terminalText } from "./implementation-preferences.js";
4
- import { type ImplementationPreferences, PLAN_MODE_THINKING_LEVELS } from "./settings.js";
5
-
6
- export function implementationModelLabel(model: ImplementationPreferences["implementationModel"]) {
7
- return model ? terminalText(`${model.provider} / ${model.id}`) : "Use current";
8
- }
9
-
10
- export function implementationSummary(preferences: ImplementationPreferences) {
11
- return `Model: ${implementationModelLabel(preferences.implementationModel)} · Thinking: ${preferences.implementationThinkingLevel && preferences.implementationThinkingLevel !== "inherit" ? preferences.implementationThinkingLevel : "Use normal behavior"}`;
12
- }
13
-
14
- export type ImplementationOptionAction =
15
- | "open-implementation-model"
16
- | "set-implementation-model"
17
- | "set-implementation-thinking";
18
-
19
- export function implementationSettingItems(
20
- preferences: ImplementationPreferences,
21
- ): SettingsScreen<ImplementationOptionAction>["items"] {
22
- return [
23
- {
24
- id: "implementationModel",
25
- label: "Implementation model",
26
- currentValue: implementationModelLabel(preferences.implementationModel),
27
- description:
28
- "Select the model only when implementation starts; never switch back automatically.",
29
- action: "open-implementation-model",
30
- },
31
- {
32
- id: "implementationThinkingLevel",
33
- label: "Implementation thinking",
34
- currentValue: preferences.implementationThinkingLevel ?? "inherit",
35
- values: PLAN_MODE_THINKING_LEVELS,
36
- description:
37
- "inherit preserves normal behavior, including restoration of Plan thinking. Explicit levels apply after model selection and are clamped by Pi.",
38
- action: "set-implementation-thinking",
39
- },
40
- ];
41
- }
42
-
43
- export function createImplementationModelPicker(ctx: ExtensionContext) {
44
- // Snapshot Pi's scoped catalogue without network refresh or auth execution.
45
- // Unlike /model, this picker stages a preference and never persists Pi defaults.
46
- const models = ctx.scopedModels?.length
47
- ? ctx.scopedModels.map(({ model }) => model)
48
- : ctx.modelRegistry.getAvailable();
49
- const byId = new Map(
50
- models.map((model, index) => [
51
- `implementation-model:${index}`,
52
- { provider: model.provider, id: model.id },
53
- ]),
54
- );
55
- return {
56
- selection(itemId: string) {
57
- return itemId === "implementation-current" ? null : byId.get(itemId);
58
- },
59
- screen(preferences: ImplementationPreferences): ChoiceScreen<"set-implementation-model"> {
60
- return {
61
- kind: "choice",
62
- title: "Implementation model",
63
- enableSearch: true,
64
- viewportSize: 10,
65
- hint: "back",
66
- action: "set-implementation-model",
67
- lines: [
68
- "Use current makes no model change. Reopen this menu to refresh the catalogue.",
69
- "Implement here sends the planning conversation to the selected provider; fresh transfers only the approved plan and normal destination resources.",
70
- `Selected: ${implementationModelLabel(preferences.implementationModel)}`,
71
- ],
72
- items: [
73
- { id: "implementation-current", label: "Use current" },
74
- ...[...byId].map(([id, model]) => ({ id, label: implementationModelLabel(model) })),
75
- ],
76
- };
77
- },
78
- };
79
- }
80
-
81
- /** Local draft lives only as long as the owning action menu. */
82
- export function createImplementationOptions(
83
- ctx: ExtensionContext,
84
- initial: ImplementationPreferences = {},
85
- ) {
86
- let preferences = { ...initial };
87
- let picker: ReturnType<typeof createImplementationModelPicker> | undefined;
88
- return {
89
- get: () => preferences,
90
- summary: () => implementationSummary(preferences),
91
- screens: {
92
- "implementation-options": (): SettingsScreen<ImplementationOptionAction> => ({
93
- kind: "settings",
94
- title: "Implementation options",
95
- lines: [
96
- "Applies to both implementation actions in this menu only.",
97
- "Changes take effect only when implementation starts. No automatic restoration afterwards.",
98
- `Current model: ${implementationModelLabel(ctx.model)}`,
99
- "inherit keeps normal thinking behavior, not necessarily the temporary Plan thinking level.",
100
- ],
101
- items: implementationSettingItems(preferences),
102
- }),
103
- "implementation-model": () => {
104
- picker ??= createImplementationModelPicker(ctx);
105
- return picker.screen(preferences);
106
- },
107
- },
108
- actions: {
109
- "open-implementation-model": async () => ({
110
- kind: "to" as const,
111
- screen: "implementation-model" as const,
112
- }),
113
- "set-implementation-model": async ({ itemId }: { itemId: string }) => {
114
- const selected = picker?.selection(itemId);
115
- if (selected === undefined) return { kind: "rejected" as const };
116
- preferences = { ...preferences, implementationModel: selected ?? undefined };
117
- return { kind: "back" as const };
118
- },
119
- "set-implementation-thinking": async ({ value }: { value?: string }) => {
120
- const level = PLAN_MODE_THINKING_LEVELS.find((level) => level === value);
121
- if (!level) return { kind: "rejected" as const };
122
- preferences = { ...preferences, implementationThinkingLevel: level };
123
- return { kind: "stay" as const };
124
- },
125
- },
126
- };
127
- }
@@ -1,145 +0,0 @@
1
- import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import type { ImplementationPreferences } from "./settings.js";
3
-
4
- type Model = NonNullable<ExtensionContext["model"]>;
5
- type Thinking = ReturnType<ExtensionAPI["getThinkingLevel"]>;
6
- export interface ImplementationSnapshot {
7
- model: Model | undefined;
8
- thinking: Thinking;
9
- }
10
-
11
- export function observeImplementationModelSelections(pi: ExtensionAPI) {
12
- let latest: ImplementationSnapshot | undefined;
13
- pi.on("model_select", (_event, ctx) => {
14
- latest = { model: ctx.model, thinking: pi.getThinkingLevel() };
15
- });
16
- return () => latest;
17
- }
18
-
19
- export function hasImplementationPreferences(preferences: ImplementationPreferences) {
20
- return (
21
- preferences.implementationModel !== undefined ||
22
- (preferences.implementationThinkingLevel !== undefined &&
23
- preferences.implementationThinkingLevel !== "inherit")
24
- );
25
- }
26
-
27
- export function sameModel(
28
- left: { provider: string; id: string } | undefined,
29
- right: { provider: string; id: string } | undefined,
30
- ) {
31
- return left?.provider === right?.provider && left?.id === right?.id;
32
- }
33
-
34
- export function safeImplementationText(value: string) {
35
- return [...value]
36
- .map((character) => {
37
- const code = character.codePointAt(0) ?? 0;
38
- return code <= 0x1f || (code >= 0x7f && code <= 0x9f) ? " " : character;
39
- })
40
- .join("")
41
- .trim();
42
- }
43
-
44
- export function preferenceError(error: unknown) {
45
- return safeImplementationText(error instanceof Error ? error.message : String(error)).slice(
46
- 0,
47
- 500,
48
- );
49
- }
50
-
51
- export async function preflightImplementationPreferences(
52
- ctx: ExtensionContext,
53
- preferences: ImplementationPreferences,
54
- isCurrent: () => boolean,
55
- ): Promise<Model | undefined> {
56
- if (!isCurrent()) return undefined;
57
- const identity = preferences.implementationModel;
58
- const model = identity ? ctx.modelRegistry.find(identity.provider, identity.id) : ctx.model;
59
- if (!model)
60
- throw new Error(
61
- "Implementation model is unavailable. Select a registered model or use current.",
62
- );
63
- // Pi's auth facade has no AbortSignal. Pi owns this operation; drain it and
64
- // revalidate rather than claiming that cancellation stops provider auth work.
65
- const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
66
- if (!isCurrent()) return undefined;
67
- // Composed registries may materialize a new definition on every lookup.
68
- const currentModel = identity ? ctx.modelRegistry.find(identity.provider, identity.id) : model;
69
- if (!currentModel) {
70
- throw new Error(
71
- "Implementation model catalogue changed during preflight. Reopen the menu and retry.",
72
- );
73
- }
74
- if (!auth.ok) throw new Error(auth.error);
75
- return currentModel;
76
- }
77
-
78
- /** A one-shot handoff transaction, never an implementation-run restoration hook. */
79
- export function createImplementationPreferenceChange(
80
- pi: ExtensionAPI,
81
- ctx: ExtensionContext,
82
- isSessionCurrent: () => boolean,
83
- original: ImplementationSnapshot = { model: ctx.model, thinking: pi.getThinkingLevel() },
84
- selectionSnapshot?: () => ImplementationSnapshot | undefined,
85
- ) {
86
- let applied: ImplementationSnapshot | undefined;
87
- const snapshot = (): ImplementationSnapshot => ({
88
- model: ctx.model,
89
- thinking: pi.getThinkingLevel(),
90
- });
91
- const matches = (value: ImplementationSnapshot) =>
92
- sameModel(ctx.model, value.model) && pi.getThinkingLevel() === value.thinking;
93
- return {
94
- async apply(model: Model, preferences: ImplementationPreferences, isCurrent: () => boolean) {
95
- if (!isCurrent()) return false;
96
- // Includes any Plan-thinking restoration performed immediately before apply.
97
- applied = snapshot();
98
- if (preferences.implementationModel && !sameModel(ctx.model, model)) {
99
- const beforeSelection = selectionSnapshot?.();
100
- if (!(await pi.setModel(model)))
101
- throw new Error("Implementation model authentication is unavailable.");
102
- if (!isSessionCurrent()) return false;
103
- if (!sameModel(ctx.model, model)) return false;
104
- const selected = selectionSnapshot?.();
105
- applied = selected && selected !== beforeSelection ? selected : snapshot();
106
- if (!matches(applied)) {
107
- if (ctx.hasUI)
108
- ctx.ui.notify(
109
- "Model or thinking changed during implementation preparation. The plan remains available; retry when ready.",
110
- "warning",
111
- );
112
- return false;
113
- }
114
- if (!isCurrent()) return false;
115
- }
116
- const level = preferences.implementationThinkingLevel;
117
- if (level && level !== "inherit") {
118
- pi.setThinkingLevel(level);
119
- applied = snapshot();
120
- if (applied.thinking !== level && ctx.hasUI)
121
- ctx.ui.notify(
122
- `Implementation thinking: ${applied.thinking} (requested ${level}; adjusted by Pi for this model).`,
123
- "info",
124
- );
125
- }
126
- return isCurrent();
127
- },
128
- async rollback() {
129
- if (!applied || !isSessionCurrent() || !ctx.isIdle() || !matches(applied)) return;
130
- if (!sameModel(ctx.model, original.model)) {
131
- const beforeSelection = selectionSnapshot?.();
132
- if (!original.model || !(await pi.setModel(original.model))) {
133
- throw new Error(
134
- "Could not restore the previous model. The plan remains available; select a model before retrying.",
135
- );
136
- }
137
- if (!isSessionCurrent() || !ctx.isIdle() || !sameModel(ctx.model, original.model)) return;
138
- const selected = selectionSnapshot?.();
139
- if (selected && selected !== beforeSelection && !matches(selected)) return;
140
- }
141
- pi.setThinkingLevel(original.thinking);
142
- applied = undefined;
143
- },
144
- };
145
- }