@narumitw/pi-plan-mode 0.58.3 → 0.59.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.
- package/README.md +25 -12
- package/dist/chunks/{chunk-L2CXUWCH.ts → chunk-MJV6WNHK.ts} +76 -7
- package/dist/chunks/{chunk-L2CXUWCH.ts.map → chunk-MJV6WNHK.ts.map} +3 -3
- package/dist/chunks/{interactive-ui-OZA4BHGS.ts → interactive-ui-F7FMN7FT.ts} +25 -27
- package/dist/chunks/interactive-ui-F7FMN7FT.ts.map +7 -0
- package/dist/index.ts +36 -26
- package/dist/index.ts.map +3 -3
- package/docs/command-workflows.md +6 -1
- package/docs/settings.md +78 -15
- package/package.json +3 -3
- package/src/mode-contract.ts +9 -0
- package/src/plan-launch-menu.ts +9 -9
- package/src/plan-mode.ts +43 -35
- package/src/prompt.ts +1 -1
- package/src/settings-menu.ts +16 -24
- package/src/tool-availability.ts +27 -0
- package/src/tool-policy.ts +14 -4
- package/src/tool-selection.ts +55 -3
- package/dist/chunks/interactive-ui-OZA4BHGS.ts.map +0 -7
|
@@ -17,12 +17,13 @@ import {
|
|
|
17
17
|
normalizeKeyId,
|
|
18
18
|
planExportDestination,
|
|
19
19
|
planModeSettingsPath,
|
|
20
|
+
planModeToolAvailability,
|
|
21
|
+
planModeToolSelection,
|
|
20
22
|
readPlanModeSettings,
|
|
21
23
|
retentionLabel,
|
|
22
24
|
snapshotAvailableImplementationModels,
|
|
23
|
-
toolPolicyLabel,
|
|
24
25
|
updatePlanModeSettings
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-MJV6WNHK.ts";
|
|
26
27
|
|
|
27
28
|
// src/active-implementation-menu.ts
|
|
28
29
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
@@ -420,7 +421,7 @@ function safeModelMetadata(value, fallback) {
|
|
|
420
421
|
}
|
|
421
422
|
|
|
422
423
|
// src/plan-launch-menu.ts
|
|
423
|
-
import { defineMenu as defineMenu3, runMenu as runMenu3 } from "@narumitw/pi-tui-kit";
|
|
424
|
+
import { defineMenu as defineMenu3, runMenu as runMenu3, sanitizeTerminalText as sanitizeTerminalText2 } from "@narumitw/pi-tui-kit";
|
|
424
425
|
async function showPlanLaunchMenu(ctx, options) {
|
|
425
426
|
const selectedNames = new Set(options.getSelectedNames());
|
|
426
427
|
const toolItems = options.tools.map((tool, index) => ({
|
|
@@ -435,7 +436,7 @@ async function showPlanLaunchMenu(ctx, options) {
|
|
|
435
436
|
main: () => ({
|
|
436
437
|
kind: "actions",
|
|
437
438
|
title: "Plan mode",
|
|
438
|
-
lines: [options.statusText, options.toolSummary(selectedNames)],
|
|
439
|
+
lines: [options.statusText, options.toolSummary(selectedNames)].map(sanitizeTerminalText2),
|
|
439
440
|
items: [
|
|
440
441
|
{ id: "start", label: "Start Plan mode", action: "start" },
|
|
441
442
|
{ id: "tools", label: "Choose tools, then start\u2026", to: "tools" },
|
|
@@ -450,19 +451,19 @@ async function showPlanLaunchMenu(ctx, options) {
|
|
|
450
451
|
lines: [
|
|
451
452
|
"Policy changes apply only when you start Plan mode; first use may also reveal Plan helpers.",
|
|
452
453
|
options.toolSummary(selectedNames),
|
|
453
|
-
"
|
|
454
|
-
"Plan mode never activates tools
|
|
455
|
-
],
|
|
454
|
+
"Available tools can be chosen now; retained names resolve before the first request.",
|
|
455
|
+
"Plan mode never activates tools; tools outside its reviewed core policy run at user risk."
|
|
456
|
+
].map(sanitizeTerminalText2),
|
|
456
457
|
enableSearch: true,
|
|
457
458
|
viewportSize: 10,
|
|
458
459
|
items: toolItems.map(({ id, tool }) => ({
|
|
459
460
|
id,
|
|
460
|
-
label: tool.label ?? tool.name,
|
|
461
|
-
description: tool.description,
|
|
462
|
-
searchText: tool.searchText,
|
|
461
|
+
label: sanitizeTerminalText2(tool.label ?? tool.name),
|
|
462
|
+
description: sanitizeTerminalText2(tool.description),
|
|
463
|
+
searchText: sanitizeTerminalText2(tool.searchText),
|
|
463
464
|
selected: selectedNames.has(tool.name),
|
|
464
465
|
disabled: tool.disabled,
|
|
465
|
-
disabledReason: tool.disabledReason
|
|
466
|
+
disabledReason: tool.disabledReason ? sanitizeTerminalText2(tool.disabledReason) : void 0
|
|
466
467
|
})),
|
|
467
468
|
action: "toggle-tool",
|
|
468
469
|
actions: [
|
|
@@ -599,7 +600,7 @@ async function showSavedPlanMenu(ctx, options) {
|
|
|
599
600
|
}
|
|
600
601
|
|
|
601
602
|
// src/settings-menu.ts
|
|
602
|
-
import { defineMenu as defineMenu5, runMenu as runMenu5, sanitizeTerminalText as
|
|
603
|
+
import { defineMenu as defineMenu5, runMenu as runMenu5, sanitizeTerminalText as sanitizeTerminalText3 } from "@narumitw/pi-tui-kit";
|
|
603
604
|
async function showPlanModeSettings(ctx, options) {
|
|
604
605
|
const settingsPath = options.settingsPath ?? planModeSettingsPath();
|
|
605
606
|
const readSettings = options.readSettings ?? readPlanModeSettings;
|
|
@@ -648,7 +649,7 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
648
649
|
{
|
|
649
650
|
id: "defaultPlanTools",
|
|
650
651
|
label: "Plan policy tools",
|
|
651
|
-
description: "Choose
|
|
652
|
+
description: "Choose available tools or retain names to resolve before the first request.",
|
|
652
653
|
currentValue: defaultToolsValue(state.settings.defaultPlanTools),
|
|
653
654
|
action: "open-tools"
|
|
654
655
|
},
|
|
@@ -697,7 +698,7 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
697
698
|
lines: [
|
|
698
699
|
"Changes apply when a later Plan workflow starts; model-visible tools stay unchanged.",
|
|
699
700
|
"Retained inactive names resolve before that workflow's first request.",
|
|
700
|
-
"Plan mode never activates tools
|
|
701
|
+
"Plan mode never activates tools; tools outside its reviewed core policy run at user risk."
|
|
701
702
|
],
|
|
702
703
|
enableSearch: true,
|
|
703
704
|
viewportSize: 10,
|
|
@@ -850,7 +851,7 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
850
851
|
},
|
|
851
852
|
"toggle-tool": async ({ ctx: actionCtx, state, itemId, selected, signal }) => {
|
|
852
853
|
const tool = itemId ? toolsByItemId.get(itemId) : void 0;
|
|
853
|
-
if (!tool ||
|
|
854
|
+
if (!tool || planModeToolAvailability(tool, activeToolNames) !== "available" || !canSelectToolInPlanMode(tool)) {
|
|
854
855
|
return { kind: "rejected" };
|
|
855
856
|
}
|
|
856
857
|
const names = explicitToolNames(tools, state.settings.defaultPlanTools);
|
|
@@ -956,7 +957,7 @@ function safeModelReference2(model) {
|
|
|
956
957
|
}
|
|
957
958
|
function safeModelMetadata2(value, fallback) {
|
|
958
959
|
if (typeof value !== "string") return fallback;
|
|
959
|
-
const safe =
|
|
960
|
+
const safe = sanitizeTerminalText3(value).trim() || fallback;
|
|
960
961
|
return [...safe].slice(0, 512).join("");
|
|
961
962
|
}
|
|
962
963
|
function defaultToolsValue(configured) {
|
|
@@ -968,18 +969,15 @@ function defaultToolItems(tools, configured, activeToolNames, toolItemIds) {
|
|
|
968
969
|
const selected = new Set(explicitToolNames(tools, configured));
|
|
969
970
|
const availableNames = new Set(tools.map((tool) => tool.name));
|
|
970
971
|
const items = tools.map((tool) => {
|
|
971
|
-
const
|
|
972
|
-
const selectable = active && canSelectToolInPlanMode(tool);
|
|
973
|
-
const policy = active ? toolPolicyLabel(tool) : selected.has(tool.name) ? "not active yet; retained for first-request resolution" : "not active in this Pi session";
|
|
974
|
-
const description = tool.description ?? "No description available";
|
|
972
|
+
const presentation = planModeToolSelection(tool, activeToolNames, selected.has(tool.name));
|
|
975
973
|
return {
|
|
976
974
|
id: toolItemIds.get(tool.name),
|
|
977
|
-
label: tool.name,
|
|
978
|
-
description: `${policy} \xB7 ${description}`,
|
|
979
|
-
searchText: `${policy} ${description}`,
|
|
980
975
|
selected: selected.has(tool.name),
|
|
981
|
-
|
|
982
|
-
|
|
976
|
+
...presentation,
|
|
977
|
+
label: sanitizeTerminalText3(presentation.label),
|
|
978
|
+
description: sanitizeTerminalText3(presentation.description),
|
|
979
|
+
searchText: sanitizeTerminalText3(presentation.searchText),
|
|
980
|
+
disabledReason: presentation.disabledReason ? sanitizeTerminalText3(presentation.disabledReason) : void 0
|
|
983
981
|
};
|
|
984
982
|
});
|
|
985
983
|
for (const [index, name] of (configured ?? []).entries()) {
|
|
@@ -1001,7 +999,7 @@ function explicitToolNames(tools, configured) {
|
|
|
1001
999
|
return configured === void 0 ? defaultPlanModeToolNames([...tools], void 0) : [...configured];
|
|
1002
1000
|
}
|
|
1003
1001
|
function terminalToolName(value) {
|
|
1004
|
-
const safe =
|
|
1002
|
+
const safe = sanitizeTerminalText3(value).trim() || "(unnamed tool)";
|
|
1005
1003
|
return safe.length > 120 ? `${safe.slice(0, 119)}\u2026` : safe;
|
|
1006
1004
|
}
|
|
1007
1005
|
function safeTerminalText(value) {
|
|
@@ -1021,4 +1019,4 @@ export {
|
|
|
1021
1019
|
showReadyPlanMenu,
|
|
1022
1020
|
showSavedPlanMenu
|
|
1023
1021
|
};
|
|
1024
|
-
//# sourceMappingURL=interactive-ui-
|
|
1022
|
+
//# sourceMappingURL=interactive-ui-F7FMN7FT.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/active-implementation-menu.ts", "../../src/plan-export-screen.ts", "../../src/plan-action-menus.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 statusText: string;\n getExportDestination: PlanExportDestinationProvider;\n signal: AbortSignal;\n isCurrent(): boolean;\n show(): void;\n exportPlan(path: string, signal: AbortSignal): Promise<boolean>;\n settings(signal: AbortSignal): Promise<boolean>;\n startNew(): void;\n clear(): void;\n}\n\nexport async function showActiveImplementationMenu(ctx: ExtensionContext, options: ActiveImplementationMenuOptions) {\n type Screen = \"active\" | \"export\";\n type Action = \"show\" | \"export\" | \"settings\" | \"start-new\" | \"clear\";\n const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({\n start: \"active\",\n screens: {\n active: () => ({\n kind: \"actions\",\n title: \"Active implementation plan\",\n lines: [options.statusText],\n items: [\n { id: \"show\", label: \"Show active implementation plan\", action: \"show\" },\n { id: \"export\", label: \"Export plan\u2026\", to: \"export\" },\n { id: \"settings\", label: \"Settings\", action: \"settings\" },\n { id: \"start-new\", label: \"Start a new plan\", action: \"start-new\" },\n { id: \"clear\", label: \"Clear active implementation plan\", action: \"clear\" },\n ],\n hint: \"close\",\n }),\n export: () => planExportInputScreen(options.getExportDestination),\n },\n actions: {\n show: async () => {\n options.show();\n return { kind: \"close\" };\n },\n export: async ({ value, signal }) =>\n (await options.exportPlan(value ?? \"\", signal)) ? { kind: \"close\" } : { kind: \"rejected\" },\n settings: async ({ signal }) => {\n const close = await options.settings(signal);\n if (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n return close ? { kind: \"close\" } : { kind: \"stay\" };\n },\n \"start-new\": async () => {\n options.startNew();\n return { kind: \"close\" };\n },\n clear: async () => {\n options.clear();\n return { kind: \"close\" };\n },\n },\n });\n await runMenu(ctx, menu, {\n getState: () => undefined,\n signal: options.signal,\n isCurrent: options.isCurrent,\n });\n}\n", "import type { PlanExportDestination } from \"./plan-export.js\";\n\nexport type PlanExportDestinationProvider = () => PlanExportDestination;\n\nexport function planExportInputScreen(getDestination: PlanExportDestinationProvider) {\n const destination = getDestination();\n return {\n kind: \"input\" as const,\n title: \"Export plan\",\n lines: [\n \"Existing paths are never overwritten.\",\n `Default: ${destination.configuredPath}`,\n `Resolves to: ${destination.resolvedPath}`,\n ],\n placeholder: destination.configuredPath,\n action: \"export\" as const,\n hint: \"back\" as const,\n };\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu, sanitizeTerminalText } from \"@narumitw/pi-tui-kit\";\nimport {\n type AvailableImplementationModel,\n findAvailableImplementationModel,\n type ImplementationModelOverride,\n snapshotAvailableImplementationModels,\n} from \"./implementation-models.js\";\nimport { type PlanExportDestinationProvider, planExportInputScreen } from \"./plan-export-screen.js\";\nimport { IMPLEMENTATION_THINKING_LEVELS, type PlanModeFixedThinkingLevel } from \"./settings.js\";\nimport type { ImplementationRuntimeSelection } from \"./state.js\";\n\ninterface MenuLifecycle {\n signal: AbortSignal;\n isCurrent(): boolean;\n}\n\nconst IMPLEMENTATION_CONTEXT_LINES = [\n \"Implement here keeps this planning conversation.\",\n \"Start fresh transfers only the approved plan to a new session.\",\n] as const;\n\nconst THINKING_LEVEL_DESCRIPTIONS: Record<PlanModeFixedThinkingLevel, string> = {\n off: \"No reasoning\",\n minimal: \"Very brief reasoning (~1k tokens)\",\n low: \"Light reasoning (~2k tokens)\",\n medium: \"Moderate reasoning (~8k tokens)\",\n high: \"Deep reasoning (~16k tokens)\",\n xhigh: \"Extra-high reasoning (~32k tokens)\",\n max: \"Maximum reasoning\",\n};\n\ninterface PlanMenuOptions extends MenuLifecycle {\n statusText: string;\n planThinkingLevel: PlanModeFixedThinkingLevel | undefined;\n implementationDefaults?: ImplementationRuntimeSelection;\n hasReadyPlan: boolean;\n implementationOutcome(): string;\n getExportDestination: PlanExportDestinationProvider;\n show(): void;\n finalize(): void;\n implementHere(): void | Promise<void>;\n implementFresh(runtime: ImplementationRuntimeSelection, signal: AbortSignal): void | Promise<void>;\n exportPlan(path: string, signal: AbortSignal): Promise<boolean>;\n save(): void;\n stay(): void;\n exit(): void;\n}\n\nexport async function showPlanModeMenu(ctx: ExtensionContext, options: PlanMenuOptions) {\n type Screen = \"main\" | \"fresh\" | \"models\" | \"thinking\" | \"export\";\n type Action =\n | \"show\"\n | \"finalize\"\n | \"implement-here\"\n | \"select-model\"\n | \"select-thinking\"\n | \"start-fresh\"\n | \"export\"\n | \"save\"\n | \"stay\"\n | \"exit\";\n const freshFlow = createFreshImplementationFlow(\n ctx,\n options.planThinkingLevel,\n options.implementationDefaults,\n options.implementFresh,\n );\n const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({\n start: \"main\",\n screens: {\n main: () => ({\n kind: \"actions\",\n title: \"Plan mode\",\n lines: [\n options.statusText,\n ...(options.hasReadyPlan ? [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()] : []),\n ],\n items: options.hasReadyPlan\n ? [\n { id: \"show\", label: \"Show latest proposed plan\", action: \"show\" },\n {\n id: \"implement-here\",\n label: \"Implement here\",\n description: \"Continue in this session with the planning conversation.\",\n action: \"implement-here\",\n },\n {\n id: \"implement-fresh\",\n label: \"Start fresh and implement\",\n description: \"Configure one-shot model and thinking choices first.\",\n to: \"fresh\",\n },\n { id: \"export\", label: \"Export plan\u2026\", to: \"export\" },\n { id: \"save\", label: \"Save for later\", action: \"save\" },\n { id: \"stay\", label: \"Stay in Plan mode\", action: \"stay\" },\n { id: \"exit\", label: \"Discard plan and exit\", action: \"exit\" },\n ]\n : [\n { id: \"finalize\", label: \"Request final plan\", action: \"finalize\" },\n { id: \"stay\", label: \"Stay in Plan mode\", action: \"stay\" },\n { id: \"exit\", label: \"Exit Plan mode\", action: \"exit\" },\n ],\n hint: \"close\",\n }),\n fresh: freshFlow.settingsScreen,\n models: freshFlow.modelScreen,\n thinking: freshFlow.thinkingScreen,\n export: () => planExportInputScreen(options.getExportDestination),\n },\n actions: {\n show: async () => {\n options.show();\n return { kind: \"close\" };\n },\n finalize: async () => {\n options.finalize();\n return { kind: \"close\" };\n },\n \"implement-here\": async () => {\n await options.implementHere();\n return { kind: \"close\" };\n },\n \"select-model\": async ({ itemId }) => {\n freshFlow.selectModel(itemId);\n return { kind: \"back\" };\n },\n \"select-thinking\": async ({ itemId }) => {\n freshFlow.selectThinking(itemId);\n return { kind: \"back\" };\n },\n \"start-fresh\": async ({ signal }) => {\n await freshFlow.start(signal);\n return { kind: \"close\" };\n },\n export: async ({ value, signal }) =>\n (await options.exportPlan(value ?? \"\", signal)) ? { kind: \"close\" } : { kind: \"rejected\" },\n save: async () => {\n options.save();\n return { kind: \"close\" };\n },\n stay: async () => {\n options.stay();\n return { kind: \"close\" };\n },\n exit: async () => {\n options.exit();\n return { kind: \"close\" };\n },\n },\n });\n await runMenu(ctx, menu, {\n getState: () => undefined,\n signal: options.signal,\n isCurrent: options.isCurrent,\n });\n}\n\ninterface ReadyPlanMenuOptions extends MenuLifecycle {\n planThinkingLevel: PlanModeFixedThinkingLevel | undefined;\n implementationDefaults?: ImplementationRuntimeSelection;\n implementationOutcome(): string;\n getExportDestination: PlanExportDestinationProvider;\n implementHere(): void | Promise<void>;\n implementFresh(runtime: ImplementationRuntimeSelection, signal: AbortSignal): void | Promise<void>;\n exportPlan(path: string, signal: AbortSignal): Promise<boolean>;\n save(): void;\n stay(): void;\n exit(): void;\n}\n\nexport async function showReadyPlanMenu(ctx: ExtensionContext, options: ReadyPlanMenuOptions) {\n type Screen = \"ready\" | \"fresh\" | \"models\" | \"thinking\" | \"export\";\n type Action =\n | \"implement-here\"\n | \"select-model\"\n | \"select-thinking\"\n | \"start-fresh\"\n | \"export\"\n | \"save\"\n | \"stay\"\n | \"exit\";\n const freshFlow = createFreshImplementationFlow(\n ctx,\n options.planThinkingLevel,\n options.implementationDefaults,\n options.implementFresh,\n );\n const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({\n start: \"ready\",\n screens: {\n ready: () => ({\n kind: \"actions\",\n title: \"Proposed plan ready. What next?\",\n lines: [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()],\n items: [\n {\n id: \"implement-here\",\n label: \"Implement here\",\n description: \"Continue in this session with the planning conversation.\",\n action: \"implement-here\",\n },\n {\n id: \"implement-fresh\",\n label: \"Start fresh and implement\",\n description: \"Configure one-shot model and thinking choices first.\",\n to: \"fresh\",\n },\n { id: \"export\", label: \"Export plan\u2026\", to: \"export\" },\n { id: \"save\", label: \"Save for later\", action: \"save\" },\n { id: \"stay\", label: \"Stay in Plan mode\", action: \"stay\" },\n { id: \"exit\", label: \"Discard plan and exit\", action: \"exit\" },\n ],\n hint: \"close\",\n }),\n fresh: freshFlow.settingsScreen,\n models: freshFlow.modelScreen,\n thinking: freshFlow.thinkingScreen,\n export: () => planExportInputScreen(options.getExportDestination),\n },\n actions: {\n \"implement-here\": async () => {\n await options.implementHere();\n return { kind: \"close\" };\n },\n \"select-model\": async ({ itemId }) => {\n freshFlow.selectModel(itemId);\n return { kind: \"back\" };\n },\n \"select-thinking\": async ({ itemId }) => {\n freshFlow.selectThinking(itemId);\n return { kind: \"back\" };\n },\n \"start-fresh\": async ({ signal }) => {\n await freshFlow.start(signal);\n return { kind: \"close\" };\n },\n export: async ({ value, signal }) =>\n (await options.exportPlan(value ?? \"\", signal)) ? { kind: \"close\" } : { kind: \"rejected\" },\n save: async () => {\n options.save();\n return { kind: \"close\" };\n },\n stay: async () => {\n options.stay();\n return { kind: \"close\" };\n },\n exit: async () => {\n options.exit();\n return { kind: \"close\" };\n },\n },\n });\n await runMenu(ctx, menu, {\n getState: () => undefined,\n signal: options.signal,\n isCurrent: options.isCurrent,\n });\n}\n\ninterface ModelChoice {\n itemId: string;\n model: ImplementationModelOverride;\n modelInfo: AvailableImplementationModel;\n label: string;\n summary: string;\n details?: readonly string[];\n searchText: string;\n isPlanModel: boolean;\n}\n\nfunction createFreshImplementationFlow(\n ctx: ExtensionContext,\n planThinkingLevel: PlanModeFixedThinkingLevel | undefined,\n implementationDefaults: ImplementationRuntimeSelection | undefined,\n implementFresh: (runtime: ImplementationRuntimeSelection, signal: AbortSignal) => void | Promise<void>,\n) {\n const models = snapshotAvailableModels(ctx);\n const planModel = ctx.model ? { provider: ctx.model.provider, modelId: ctx.model.id } : undefined;\n const planModelSummary = ctx.model\n ? `${safeModelMetadata(ctx.model.id, \"unknown model\")} [${safeModelMetadata(ctx.model.provider, \"unknown provider\")}]`\n : undefined;\n const configuredModel = implementationDefaults?.model;\n const configuredAvailableModel = findAvailableImplementationModel(\n models.map((choice) => choice.modelInfo),\n configuredModel,\n );\n let unavailableDefaultActive = configuredModel !== undefined && !configuredAvailableModel;\n let selectedModel = configuredAvailableModel\n ? models.find((choice) => choice.modelInfo === configuredAvailableModel)\n : undefined;\n let selectedModelUsesDefault = selectedModel !== undefined;\n let selectedThinkingLevel = implementationDefaults?.thinkingLevel;\n return {\n settingsScreen: () => ({\n kind: \"actions\" as const,\n title: \"Fresh implementation settings\",\n lines: [\n \"These choices apply once to the new implementation session.\",\n ...(unavailableDefaultActive && configuredModel\n ? [`Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`]\n : []),\n ],\n items: [\n {\n id: \"start-fresh\",\n label: \"Start fresh implementation\",\n description: \"Create the linked session and begin implementation.\",\n action: \"start-fresh\" as const,\n busyLabel: \"Starting fresh implementation session\u2026\",\n },\n {\n id: \"implementation-model\",\n label: \"Model\",\n description:\n selectedModel?.summary ?? (planModelSummary ? `${planModelSummary} \u00B7 same as plan` : \"Same as plan\"),\n to: \"models\" as const,\n },\n {\n id: \"implementation-thinking\",\n label: \"Thinking level\",\n description:\n selectedThinkingLevel ?? (planThinkingLevel ? `${planThinkingLevel} \u00B7 same as plan` : \"Same as plan\"),\n to: \"thinking\" as const,\n },\n ],\n }),\n modelScreen: () => ({\n kind: \"choice\" as const,\n title: \"Implementation model\",\n items: [\n {\n id: \"same-as-plan\",\n label: \"Same as plan\",\n ...(planModelSummary ? { description: planModelSummary } : {}),\n },\n ...models.map((choice) => ({\n id: choice.itemId,\n label: choice.label,\n details: choice.details,\n searchText: choice.searchText,\n })),\n ],\n action: \"select-model\" as const,\n initialItemId: selectedModel?.itemId ?? \"same-as-plan\",\n enableSearch: true,\n viewportSize: 10,\n }),\n thinkingScreen: () => ({\n kind: \"choice\" as const,\n title: \"Implementation thinking level\",\n items: [\n {\n id: \"same-as-plan\",\n label: \"Same as plan\",\n },\n ...IMPLEMENTATION_THINKING_LEVELS.map((level) => ({\n id: level,\n label: `${level === planThinkingLevel ? \"\u2713 \" : \"\"}${level}`,\n description: THINKING_LEVEL_DESCRIPTIONS[level],\n })),\n ],\n action: \"select-thinking\" as const,\n initialItemId: selectedThinkingLevel ?? \"same-as-plan\",\n viewportSize: IMPLEMENTATION_THINKING_LEVELS.length + 1,\n }),\n selectModel(itemId: string) {\n const choice = models.find((candidate) => candidate.itemId === itemId);\n selectedModel = itemId === \"same-as-plan\" || choice?.isPlanModel ? undefined : choice;\n selectedModelUsesDefault = false;\n unavailableDefaultActive = false;\n },\n selectThinking(itemId: string) {\n selectedThinkingLevel = IMPLEMENTATION_THINKING_LEVELS.find((level) => level === itemId);\n },\n start(signal: AbortSignal) {\n if (\n selectedModelUsesDefault &&\n selectedModel &&\n !findAvailableImplementationModel(snapshotAvailableImplementationModels(ctx), selectedModel.model)\n ) {\n selectedModel = undefined;\n selectedModelUsesDefault = false;\n unavailableDefaultActive = true;\n ctx.ui.notify(\n `Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`,\n \"warning\",\n );\n }\n const model = selectedModel?.model ?? planModel;\n const thinkingLevel = selectedThinkingLevel ?? planThinkingLevel;\n return implementFresh(\n {\n ...(model ? { model: { ...model } } : {}),\n ...(thinkingLevel ? { thinkingLevel } : {}),\n },\n signal,\n );\n },\n };\n}\n\nfunction snapshotAvailableModels(ctx: ExtensionContext): ModelChoice[] {\n return snapshotAvailableImplementationModels(ctx)\n .map((model, index) => {\n const provider = safeModelMetadata(model.provider, \"unknown provider\");\n const modelId = safeModelMetadata(model.id, \"unknown model\");\n const name = safeModelMetadata(model.name, \"\");\n const isPlanModel = ctx.model?.provider === model.provider && ctx.model.id === model.id;\n const summary = `${modelId} [${provider}]`;\n return {\n itemId: `model-${index}`,\n model: { provider: model.provider, modelId: model.id },\n modelInfo: model,\n label: `${isPlanModel ? \"\u2713 \" : \"\"}${summary}${isPlanModel ? \" \u00B7 default\" : \"\"}`,\n summary,\n ...(name ? { details: [`Model Name: ${name}`] } : {}),\n searchText: [provider, modelId, name].filter(Boolean).join(\" \"),\n isPlanModel,\n };\n })\n .sort((left, right) => Number(right.isPlanModel) - Number(left.isPlanModel));\n}\n\nfunction safeModelReference(model: ImplementationModelOverride | undefined) {\n if (!model) return \"configured model\";\n return `${safeModelMetadata(model.modelId, \"unknown model\")} [${safeModelMetadata(model.provider, \"unknown provider\")}]`;\n}\n\nfunction safeModelMetadata(value: unknown, fallback: string) {\n if (typeof value !== \"string\") return fallback;\n const safe = sanitizeTerminalText(value).trim() || fallback;\n return [...safe].slice(0, 512).join(\"\");\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu, sanitizeTerminalText } from \"@narumitw/pi-tui-kit\";\n\nexport interface PlanLaunchTool {\n name: string;\n label?: string;\n description: string;\n searchText: string;\n disabled: boolean;\n disabledReason?: string;\n}\n\ninterface PlanLaunchMenuOptions {\n statusText: string;\n toolSummary(selectedNames: ReadonlySet<string>): string;\n getSelectedNames(): ReadonlySet<string>;\n tools: readonly PlanLaunchTool[];\n signal: AbortSignal;\n isCurrent(): boolean;\n initialScreen?: \"main\" | \"tools\";\n start(signal: AbortSignal): void;\n startWithTools(toolNames: string[], signal: AbortSignal): void;\n settings(signal: AbortSignal): Promise<boolean>;\n}\n\nexport async function showPlanLaunchMenu(ctx: ExtensionContext, options: PlanLaunchMenuOptions) {\n type Screen = \"main\" | \"tools\" | \"help\";\n type Action = \"start\" | \"toggle-tool\" | \"start-with-tools\" | \"settings\";\n const selectedNames = new Set(options.getSelectedNames());\n const toolItems = options.tools.map((tool, index) => ({\n id: `plan-tool:${index}`,\n tool,\n }));\n const toolsByItemId = new Map(toolItems.map(({ id, tool }) => [id, tool]));\n let draftChanged = false;\n const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({\n start: options.initialScreen ?? \"main\",\n screens: {\n main: () => ({\n kind: \"actions\",\n title: \"Plan mode\",\n lines: [options.statusText, options.toolSummary(selectedNames)].map(sanitizeTerminalText),\n items: [\n { id: \"start\", label: \"Start Plan mode\", action: \"start\" },\n { id: \"tools\", label: \"Choose tools, then start\u2026\", to: \"tools\" },\n { id: \"settings\", label: \"Settings\", action: \"settings\" },\n { id: \"help\", label: \"How Plan mode works\", to: \"help\" },\n ],\n hint: \"close\",\n }),\n tools: () => ({\n kind: \"multiSelect\",\n title: \"Choose Plan policy allowlist\",\n lines: [\n \"Policy changes apply only when you start Plan mode; first use may also reveal Plan helpers.\",\n options.toolSummary(selectedNames),\n \"Available tools can be chosen now; retained names resolve before the first request.\",\n \"Plan mode never activates tools; tools outside its reviewed core policy run at user risk.\",\n ].map(sanitizeTerminalText),\n enableSearch: true,\n viewportSize: 10,\n items: toolItems.map(({ id, tool }) => ({\n id,\n label: sanitizeTerminalText(tool.label ?? tool.name),\n description: sanitizeTerminalText(tool.description),\n searchText: sanitizeTerminalText(tool.searchText),\n selected: selectedNames.has(tool.name),\n disabled: tool.disabled,\n disabledReason: tool.disabledReason ? sanitizeTerminalText(tool.disabledReason) : undefined,\n })),\n action: \"toggle-tool\",\n actions: [\n {\n id: \"start-with-tools\",\n label: \"Done \u2014 start with this policy\",\n action: \"start-with-tools\",\n },\n ],\n hint: \"back\",\n }),\n help: () => ({\n kind: \"detail\",\n title: \"How Plan mode works\",\n lines: [\n \"Plan mode uses read-only exploration to understand the project before implementation.\",\n \"The agent can ask important decision questions, then returns a complete implementation-ready plan.\",\n \"File mutation stays blocked until you explicitly choose to implement the completed plan.\",\n ],\n hint: \"back\",\n }),\n },\n actions: {\n start: async ({ signal }) => {\n if (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n options.start(signal);\n return { kind: \"close\" };\n },\n \"toggle-tool\": async ({ itemId, selected, signal }) => {\n if (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n const tool = itemId ? toolsByItemId.get(itemId) : undefined;\n if (!tool || tool.disabled) return { kind: \"rejected\" };\n if (selected) selectedNames.add(tool.name);\n else selectedNames.delete(tool.name);\n draftChanged = true;\n return { kind: \"stay\" };\n },\n \"start-with-tools\": async ({ signal }) => {\n if (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n options.startWithTools(Array.from(selectedNames), signal);\n return { kind: \"close\" };\n },\n settings: async ({ signal }) => {\n if (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n const close = await options.settings(signal);\n if (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n if (close) return { kind: \"close\" };\n if (!draftChanged) {\n selectedNames.clear();\n for (const name of options.getSelectedNames()) selectedNames.add(name);\n }\n return { kind: \"stay\" };\n },\n },\n });\n await runMenu(ctx, menu, {\n getState: () => undefined,\n signal: options.signal,\n isCurrent: options.isCurrent,\n });\n}\n", "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 SavedPlanMenuOptions {\n statusText: string;\n implementationOutcome(): string;\n getExportDestination: PlanExportDestinationProvider;\n signal: AbortSignal;\n isCurrent(): boolean;\n show(): void;\n implementHere(): void | Promise<void>;\n implementFresh(signal: AbortSignal): void | Promise<void>;\n exportPlan(path: string, signal: AbortSignal): Promise<boolean>;\n settings(signal: AbortSignal): Promise<boolean>;\n clear(): void;\n}\n\nexport async function showSavedPlanMenu(ctx: ExtensionContext, options: SavedPlanMenuOptions) {\n if (!ctx.hasUI) {\n throw new Error(`${options.statusText} Use /plan show, /plan implement, /plan export, or /plan exit.`);\n }\n type Screen = \"saved\" | \"export\";\n type Action = \"show\" | \"implement-here\" | \"implement-fresh\" | \"export\" | \"settings\" | \"clear\";\n const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({\n start: \"saved\",\n screens: {\n saved: () => ({\n kind: \"actions\",\n title: \"Saved plan\",\n lines: [\n options.statusText,\n \"Implement here keeps this planning conversation.\",\n \"Start fresh transfers only the approved plan to a new session.\",\n options.implementationOutcome(),\n ],\n items: [\n { id: \"show\", label: \"Show saved plan\", action: \"show\" },\n {\n id: \"implement-here\",\n label: \"Implement here\",\n description: \"Continue in this session with the planning conversation.\",\n action: \"implement-here\",\n },\n {\n id: \"implement-fresh\",\n label: \"Start fresh and implement\",\n description: \"Open a new linked session; transfer only the approved plan.\",\n action: \"implement-fresh\",\n busyLabel: \"Starting fresh implementation session\u2026\",\n },\n { id: \"export\", label: \"Export plan\u2026\", to: \"export\" },\n { id: \"settings\", label: \"Settings\", action: \"settings\" },\n { id: \"clear\", label: \"Clear saved plan\", action: \"clear\" },\n ],\n hint: \"close\",\n }),\n export: () => planExportInputScreen(options.getExportDestination),\n },\n actions: {\n show: async () => {\n options.show();\n return { kind: \"close\" };\n },\n \"implement-here\": async () => {\n await options.implementHere();\n return { kind: \"close\" };\n },\n \"implement-fresh\": async ({ signal }) => {\n await options.implementFresh(signal);\n return { kind: \"close\" };\n },\n export: async ({ value, signal }) =>\n (await options.exportPlan(value ?? \"\", signal)) ? { kind: \"close\" } : { kind: \"rejected\" },\n settings: async ({ signal }) => {\n const close = await options.settings(signal);\n if (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" };\n return close ? { kind: \"close\" } : { kind: \"stay\" };\n },\n clear: async () => {\n options.clear();\n return { kind: \"close\" };\n },\n },\n });\n await runMenu(ctx, menu, {\n getState: () => undefined,\n signal: options.signal,\n isCurrent: options.isCurrent,\n });\n}\n", "import type { ExtensionContext, ToolInfo } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, type RunMenuResult, runMenu, sanitizeTerminalText } from \"@narumitw/pi-tui-kit\";\nimport { PLAN_MODE_COMPLETE_TOOL_NAME } from \"./completion-tool.js\";\nimport {\n type AvailableImplementationModel,\n findAvailableImplementationModel,\n type ImplementationModelOverride,\n snapshotAvailableImplementationModels,\n} from \"./implementation-models.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 configuredImplementationModel,\n configuredImplementationPlanRetention,\n configuredImplementationThinkingLevel,\n configuredPlanExportPath,\n configuredPlanModeToggleShortcut,\n IMPLEMENTATION_PLAN_RETENTIONS,\n IMPLEMENTATION_THINKING_LEVELS,\n normalizeKeyId,\n PLAN_MODE_THINKING_LEVELS,\n type PlanModeSettings,\n type PlanModeSettingsLoadResult,\n type PlanModeSettingsPatch,\n planModeSettingsPath,\n readPlanModeSettings,\n type UpdatePlanModeSettingsOptions,\n updatePlanModeSettings,\n} from \"./settings.js\";\nimport { planModeToolAvailability } from \"./tool-availability.js\";\nimport { canSelectToolInPlanMode } from \"./tool-policy.js\";\nimport { defaultPlanModeToolNames, planModeToolSelection } from \"./tool-selection.js\";\n\ninterface SettingsMenuState {\n kind: \"valid\" | \"invalid\";\n settings: PlanModeSettings;\n notice?: string;\n reason?: string;\n}\n\nexport interface PlanModeSettingsMenuOptions {\n tools: readonly ToolInfo[];\n activeToolNames?: readonly string[];\n signal: AbortSignal;\n isCurrent(): boolean;\n settingsPath?: string;\n legacySettingsPath?: string;\n startupToggleShortcut?: PlanModeSettings[\"toggleShortcut\"];\n readSettings?: (settingsPath?: string) => Promise<PlanModeSettingsLoadResult>;\n updateSettings?: (patch: PlanModeSettingsPatch, options?: UpdatePlanModeSettingsOptions) => Promise<PlanModeSettings>;\n onSaved(settings: PlanModeSettings): void;\n}\n\ntype Screen = \"settings\" | \"tools\" | \"implementation-model\" | \"export\" | \"shortcut\";\ntype Action =\n | \"set-thinking\"\n | \"open-tools\"\n | \"toggle-tool\"\n | \"reset-tools\"\n | \"set-retention\"\n | \"open-implementation-model\"\n | \"set-implementation-model\"\n | \"set-implementation-thinking\"\n | \"open-export\"\n | \"set-export\"\n | \"open-shortcut\"\n | \"set-shortcut\";\n\nexport async function showPlanModeSettings(\n ctx: ExtensionContext,\n options: PlanModeSettingsMenuOptions,\n): Promise<RunMenuResult> {\n const settingsPath = options.settingsPath ?? planModeSettingsPath();\n const readSettings = options.readSettings ?? readPlanModeSettings;\n const updateSettings = options.updateSettings ?? updatePlanModeSettings;\n const activeToolNames = new Set(options.activeToolNames ?? options.tools.map((tool) => tool.name));\n const tools = options.tools.filter(\n (tool) => tool.name !== PLAN_MODE_QUESTION_TOOL_NAME && tool.name !== PLAN_MODE_COMPLETE_TOOL_NAME,\n );\n const toolItemIds = new Map(tools.map((tool, index) => [tool.name, `plan-settings-tool:${index}`]));\n const toolsByItemId = new Map(tools.map((tool) => [toolItemIds.get(tool.name) as string, tool]));\n const implementationModels = snapshotAvailableImplementationModels(ctx);\n const modelItemIds = new Map(implementationModels.map((model, index) => [model, `plan-settings-model:${index}`]));\n const modelsByItemId = new Map(implementationModels.map((model) => [modelItemIds.get(model) as string, model]));\n\n const loadState = async (): Promise<SettingsMenuState> => {\n const loaded = await readSettings(options.settingsPath);\n if (loaded.kind === \"invalid\") {\n return {\n kind: \"invalid\",\n settings: { thinkingLevel: \"inherit\" },\n notice: loaded.notice,\n reason: loaded.reason,\n };\n }\n return {\n kind: \"valid\",\n settings: loaded.kind === \"loaded\" ? loaded.settings : { thinkingLevel: \"inherit\" },\n notice: loaded.notice,\n };\n };\n\n const menu = defineMenu<SettingsMenuState, Screen, Action, ExtensionContext>({\n start: \"settings\",\n screens: {\n settings: ({ state }) =>\n state.kind === \"invalid\"\n ? invalidScreen(settingsPath, state)\n : {\n kind: \"settings\",\n title: \"Plan Mode Settings\",\n lines: settingsLines(settingsPath, state.notice),\n items: [\n {\n id: \"thinkingLevel\",\n label: \"Plan thinking\",\n description: \"Set the thinking level when the next Plan workflow starts.\",\n currentValue: state.settings.thinkingLevel,\n values: PLAN_MODE_THINKING_LEVELS,\n action: \"set-thinking\",\n },\n {\n id: \"defaultPlanTools\",\n label: \"Plan policy tools\",\n description: \"Choose available tools or retain names to resolve before the first request.\",\n currentValue: defaultToolsValue(state.settings.defaultPlanTools),\n action: \"open-tools\",\n },\n {\n id: \"implementationPlanRetention\",\n label: \"Plan reinjection\",\n description:\n \"Choose how long Plan mode restores the exact plan when ordinary context no longer contains it.\",\n currentValue: retentionLabel(configuredImplementationPlanRetention(state.settings)),\n values: IMPLEMENTATION_PLAN_RETENTIONS.map(retentionLabel),\n action: \"set-retention\",\n },\n {\n id: \"defaultImplementationModel\",\n label: \"Fresh model\",\n description: \"Choose the default model for a fresh implementation session.\",\n currentValue: implementationModelValue(state.settings, implementationModels),\n action: \"open-implementation-model\",\n },\n {\n id: \"defaultImplementationThinkingLevel\",\n label: \"Fresh thinking\",\n description: \"Choose the default thinking level for a fresh implementation session.\",\n currentValue: configuredImplementationThinkingLevel(state.settings) ?? \"same as plan\",\n values: [\"same as plan\", ...IMPLEMENTATION_THINKING_LEVELS],\n action: \"set-implementation-thinking\",\n },\n {\n id: \"defaultPlanExportPath\",\n label: \"Export destination\",\n description: \"Set the destination used when an export omits its path.\",\n currentValue: safeTerminalText(configuredPlanExportPath(state.settings)),\n action: \"open-export\",\n },\n {\n id: \"toggleShortcut\",\n label: \"Plan mode shortcut\",\n description:\n \"Saved TUI shortcut. Changes require /reload or restarting Pi; the current binding stays unchanged.\",\n currentValue: configuredPlanModeToggleShortcut(state.settings) ?? \"none\",\n action: \"open-shortcut\",\n },\n ],\n },\n tools: ({ state }) => ({\n kind: \"multiSelect\",\n title: \"Default Plan policy allowlist\",\n lines: [\n \"Changes apply when a later Plan workflow starts; model-visible tools stay unchanged.\",\n \"Retained inactive names resolve before that workflow's first request.\",\n \"Plan mode never activates tools; tools outside its reviewed core policy run at user risk.\",\n ],\n enableSearch: true,\n viewportSize: 10,\n items: defaultToolItems(tools, state.settings.defaultPlanTools, activeToolNames, toolItemIds),\n action: \"toggle-tool\",\n actions: [\n {\n id: \"reset-tools\",\n label: \"Use automatic safe built-ins\",\n action: \"reset-tools\",\n },\n ],\n hint: \"back\",\n }),\n \"implementation-model\": ({ state }) => ({\n kind: \"choice\",\n title: \"Fresh implementation model\",\n lines: [\"Same as plan is the default and fallback when a configured model is unavailable.\"],\n items: implementationModelItems(implementationModels, modelItemIds),\n action: \"set-implementation-model\",\n initialItemId: implementationModelItemId(\n configuredImplementationModel(state.settings),\n implementationModels,\n modelItemIds,\n ),\n enableSearch: true,\n viewportSize: 10,\n hint: \"back\",\n }),\n export: ({ state }) => {\n const configured = configuredPlanExportPath(state.settings);\n const destination = planExportDestination(configured, ctx.cwd);\n return {\n kind: \"input\",\n title: \"Export destination\",\n lines: [\n `Configured: ${destination.configuredPath}`,\n `Resolves here to: ${destination.resolvedPath}`,\n \"Submit an empty value to reset to PLAN.md. Changes affect the next export.\",\n ],\n placeholder: configured,\n action: \"set-export\",\n hint: \"back\",\n };\n },\n shortcut: ({ state }) => ({\n kind: \"input\",\n title: \"Plan mode shortcut\",\n lines: [\n `Configured: ${configuredPlanModeToggleShortcut(state.settings) ?? \"none\"}`,\n `Loaded at startup: ${safeTerminalText(options.startupToggleShortcut ?? \"none\")}`,\n \"TUI only. Use Pi key identifiers; Pi may reject conflicting shortcuts.\",\n \"Submit an empty value to remove the saved shortcut.\",\n \"Run /reload or restart Pi to apply changes; the current binding stays unchanged until then.\",\n ],\n placeholder: configuredPlanModeToggleShortcut(state.settings) ?? \"\",\n action: \"set-shortcut\",\n hint: \"back\",\n }),\n },\n actions: {\n \"set-thinking\": async ({ ctx: actionCtx, value, signal }) => {\n if (!PLAN_MODE_THINKING_LEVELS.includes(value as (typeof PLAN_MODE_THINKING_LEVELS)[number])) {\n return { kind: \"rejected\" };\n }\n return savePatch(\n actionCtx,\n { thinkingLevel: value as PlanModeSettings[\"thinkingLevel\"] },\n signal,\n `Plan mode thinking level: ${value}. Applies to the next Plan workflow.`,\n );\n },\n \"open-tools\": async () => ({ kind: \"to\", screen: \"tools\" }),\n \"set-retention\": async ({ ctx: actionCtx, value, signal }) => {\n const implementationPlanRetention = retentionFromLabel(value);\n if (!implementationPlanRetention) return { kind: \"rejected\" };\n return savePatch(\n actionCtx,\n { implementationPlanRetention },\n signal,\n `Plan reinjection: ${retentionLabel(implementationPlanRetention)}. Applies to the next Implement action.`,\n );\n },\n \"open-implementation-model\": async () => ({\n kind: \"to\",\n screen: \"implementation-model\",\n }),\n \"set-implementation-model\": async ({ ctx: actionCtx, itemId, signal }) => {\n const model = itemId ? modelsByItemId.get(itemId) : undefined;\n if (itemId !== \"same-as-plan\" && !model) return { kind: \"rejected\" };\n const defaultImplementationModel = model ? { provider: model.provider, modelId: model.id } : null;\n const result = await savePatch(\n actionCtx,\n { defaultImplementationModel },\n signal,\n model\n ? `Fresh implementation model: ${safeModelReference({ provider: model.provider, modelId: model.id })}.`\n : \"Fresh implementation model: same as plan.\",\n );\n return result.kind === \"stay\" ? { kind: \"to\", screen: \"settings\" } : result;\n },\n \"set-implementation-thinking\": async ({ ctx: actionCtx, value, signal }) => {\n if (value === \"same as plan\") {\n return savePatch(\n actionCtx,\n { defaultImplementationThinkingLevel: null },\n signal,\n \"Fresh implementation thinking: same as plan.\",\n );\n }\n if (!IMPLEMENTATION_THINKING_LEVELS.includes(value as (typeof IMPLEMENTATION_THINKING_LEVELS)[number])) {\n return { kind: \"rejected\" };\n }\n return savePatch(\n actionCtx,\n {\n defaultImplementationThinkingLevel: value as PlanModeSettings[\"defaultImplementationThinkingLevel\"],\n },\n signal,\n `Fresh implementation thinking: ${value}.`,\n );\n },\n \"open-export\": async () => ({ kind: \"to\", screen: \"export\" }),\n \"set-export\": async ({ ctx: actionCtx, value, signal }) => {\n const defaultPlanExportPath = value?.trim() || null;\n const result = await savePatch(\n actionCtx,\n { defaultPlanExportPath },\n signal,\n defaultPlanExportPath\n ? `Default Plan export destination: ${safeTerminalText(defaultPlanExportPath)}.`\n : \"Default Plan export destination reset to PLAN.md.\",\n );\n return result.kind === \"stay\" ? { kind: \"to\", screen: \"settings\" } : result;\n },\n \"open-shortcut\": async () => ({ kind: \"to\", screen: \"shortcut\" }),\n \"set-shortcut\": async ({ ctx: actionCtx, value, signal }) => {\n const raw = value?.trim() || null;\n if (raw && !normalizeKeyId(raw)) {\n actionCtx.ui.notify(\n `Invalid key identifier: ${safeTerminalText(raw)}. Use Pi key identifiers like ctrl+alt+p.`,\n \"warning\",\n );\n return { kind: \"stay\" as const };\n }\n const toggleShortcut = raw as PlanModeSettingsPatch[\"toggleShortcut\"];\n const result = await savePatch(\n actionCtx,\n { toggleShortcut },\n signal,\n toggleShortcut\n ? `Plan mode shortcut saved: ${safeTerminalText(toggleShortcut)}. Run /reload or restart Pi to apply; the current binding is unchanged.`\n : \"Plan mode shortcut removal saved. Run /reload or restart Pi to apply; the current binding is unchanged.\",\n );\n return result.kind === \"stay\" ? { kind: \"to\", screen: \"settings\" } : result;\n },\n \"toggle-tool\": async ({ ctx: actionCtx, state, itemId, selected, signal }) => {\n const tool = itemId ? toolsByItemId.get(itemId) : undefined;\n if (\n !tool ||\n planModeToolAvailability(tool, activeToolNames) !== \"available\" ||\n !canSelectToolInPlanMode(tool)\n ) {\n return { kind: \"rejected\" };\n }\n const names = explicitToolNames(tools, state.settings.defaultPlanTools);\n const next = selected ? Array.from(new Set([...names, tool.name])) : names.filter((name) => name !== tool.name);\n return savePatch(\n actionCtx,\n { defaultPlanTools: next },\n signal,\n `Default Plan policy: ${next.length === 0 ? \"no optional tools\" : `${next.length} allowed`}.`,\n );\n },\n \"reset-tools\": async ({ ctx: actionCtx, state, signal }) => {\n if (state.settings.defaultPlanTools === undefined) return { kind: \"stay\" };\n return savePatch(\n actionCtx,\n { defaultPlanTools: null },\n signal,\n \"Default Plan-mode tools: automatic safe built-ins.\",\n );\n },\n },\n });\n\n return runMenu(ctx, menu, {\n getState: loadState,\n signal: options.signal,\n isCurrent: options.isCurrent,\n });\n\n async function savePatch(\n actionCtx: ExtensionContext,\n patch: PlanModeSettingsPatch,\n signal: AbortSignal,\n successMessage: string,\n ) {\n if (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" as const };\n try {\n const saved = await updateSettings(patch, {\n settingsPath: options.settingsPath,\n legacySettingsPath: options.legacySettingsPath,\n signal,\n });\n if (options.isCurrent()) options.onSaved(saved);\n if (signal.aborted || !options.isCurrent()) return { kind: \"rejected\" as const };\n actionCtx.ui.notify(successMessage, \"info\");\n return { kind: \"stay\" as const };\n } catch (error) {\n if (!signal.aborted && options.isCurrent()) {\n actionCtx.ui.notify(\n `Could not save Plan mode settings; the previous value remains: ${safeTerminalText(formatError(error))}`,\n \"error\",\n );\n }\n return { kind: \"rejected\" as const };\n }\n }\n}\n\nfunction settingsLines(settingsPath: string, notice: string | undefined) {\n return [\n `User settings \u00B7 ${safeTerminalText(settingsPath)}`,\n \"Plan defaults apply to the next workflow; reinjection and export choices apply to their next action.\",\n ...(notice ? [safeTerminalText(notice)] : []),\n ];\n}\n\nfunction invalidScreen(settingsPath: string, state: SettingsMenuState) {\n return {\n kind: \"detail\" as const,\n title: \"Plan Mode Settings \u00B7 Read only\",\n lines: [\n `Invalid settings file. Fix ${safeTerminalText(settingsPath)} before saving.`,\n safeTerminalText(state.reason ?? \"The settings file is invalid.\"),\n ...(state.notice ? [safeTerminalText(state.notice)] : []),\n ],\n hint: \"back\" as const,\n };\n}\n\nfunction retentionFromLabel(value: string | undefined) {\n return IMPLEMENTATION_PLAN_RETENTIONS.find((retention) => retentionLabel(retention) === value);\n}\n\nfunction implementationModelValue(settings: PlanModeSettings, models: readonly AvailableImplementationModel[]) {\n const configured = configuredImplementationModel(settings);\n if (!configured) return \"same as plan\";\n return findAvailableImplementationModel(models, configured)\n ? safeModelReference(configured)\n : `same as plan \u00B7 ${safeModelReference(configured)} unavailable`;\n}\n\nfunction implementationModelItems(\n models: readonly AvailableImplementationModel[],\n itemIds: ReadonlyMap<AvailableImplementationModel, string>,\n) {\n return [\n {\n id: \"same-as-plan\",\n label: \"Same as plan\",\n description: \"Use the planning session model.\",\n },\n ...models.map((model) => {\n const reference = safeModelReference({ provider: model.provider, modelId: model.id });\n const name = safeModelMetadata(model.name, \"\");\n return {\n id: itemIds.get(model) as string,\n label: reference,\n ...(name ? { details: [`Model Name: ${name}`] } : {}),\n searchText: [reference, name].filter(Boolean).join(\" \"),\n };\n }),\n ];\n}\n\nfunction implementationModelItemId(\n configured: ImplementationModelOverride | undefined,\n models: readonly AvailableImplementationModel[],\n itemIds: ReadonlyMap<AvailableImplementationModel, string>,\n) {\n const model = findAvailableImplementationModel(models, configured);\n return model ? itemIds.get(model) : \"same-as-plan\";\n}\n\nfunction safeModelReference(model: ImplementationModelOverride) {\n return `${safeModelMetadata(model.modelId, \"unknown model\")} [${safeModelMetadata(model.provider, \"unknown provider\")}]`;\n}\n\nfunction safeModelMetadata(value: unknown, fallback: string) {\n if (typeof value !== \"string\") return fallback;\n const safe = sanitizeTerminalText(value).trim() || fallback;\n return [...safe].slice(0, 512).join(\"\");\n}\n\nfunction defaultToolsValue(configured: string[] | undefined) {\n if (configured === undefined) return \"Automatic safe built-ins\";\n if (configured.length === 0) return \"No optional tools\";\n return `${configured.length} selected`;\n}\n\nfunction defaultToolItems(\n tools: readonly ToolInfo[],\n configured: string[] | undefined,\n activeToolNames: ReadonlySet<string>,\n toolItemIds: ReadonlyMap<string, string>,\n) {\n const selected = new Set(explicitToolNames(tools, configured));\n const availableNames = new Set(tools.map((tool) => tool.name));\n const items = tools.map((tool) => {\n const presentation = planModeToolSelection(tool, activeToolNames, selected.has(tool.name));\n return {\n id: toolItemIds.get(tool.name) as string,\n selected: selected.has(tool.name),\n ...presentation,\n label: sanitizeTerminalText(presentation.label),\n description: sanitizeTerminalText(presentation.description),\n searchText: sanitizeTerminalText(presentation.searchText),\n disabledReason: presentation.disabledReason ? sanitizeTerminalText(presentation.disabledReason) : undefined,\n };\n });\n for (const [index, name] of (configured ?? []).entries()) {\n if (availableNames.has(name)) continue;\n const label = terminalToolName(name);\n items.push({\n id: `plan-settings-pending:${index}`,\n label,\n description: \"pending registration \u00B7 Retained and resolved before the first request\",\n searchText: `${label} pending registration retained settings first request`,\n selected: true,\n disabled: true,\n disabledReason: \"Not registered yet; reset defaults to remove retained names\",\n });\n }\n return items;\n}\n\nfunction explicitToolNames(tools: readonly ToolInfo[], configured: string[] | undefined) {\n return configured === undefined ? defaultPlanModeToolNames([...tools], undefined) : [...configured];\n}\n\nfunction terminalToolName(value: string) {\n const safe = sanitizeTerminalText(value).trim() || \"(unnamed tool)\";\n return safe.length > 120 ? `${safe.slice(0, 119)}\u2026` : safe;\n}\n\nfunction safeTerminalText(value: string) {\n return [...value]\n .map((character) => {\n const codePoint = character.codePointAt(0) ?? 0;\n return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? \" \" : character;\n })\n .join(\"\")\n .trim();\n}\n\nfunction formatError(error: unknown) {\n return error instanceof Error ? error.message : String(error);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,YAAY,eAAe;;;ACG7B,SAAS,sBAAsB,gBAA+C;AACnF,QAAM,cAAc,eAAe;AACnC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,MACL;AAAA,MACA,YAAY,YAAY,cAAc;AAAA,MACtC,gBAAgB,YAAY,YAAY;AAAA,IAC1C;AAAA,IACA,aAAa,YAAY;AAAA,IACzB,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AACF;;;ADFA,eAAsB,6BAA6B,KAAuB,SAA0C;AAGlH,QAAM,OAAO,WAAwD;AAAA,IACnE,OAAO;AAAA,IACP,SAAS;AAAA,MACP,QAAQ,OAAO;AAAA,QACb,MAAM;AAAA,QACN,OAAO;AAAA,QACP,OAAO,CAAC,QAAQ,UAAU;AAAA,QAC1B,OAAO;AAAA,UACL,EAAE,IAAI,QAAQ,OAAO,mCAAmC,QAAQ,OAAO;AAAA,UACvE,EAAE,IAAI,UAAU,OAAO,qBAAgB,IAAI,SAAS;AAAA,UACpD,EAAE,IAAI,YAAY,OAAO,YAAY,QAAQ,WAAW;AAAA,UACxD,EAAE,IAAI,aAAa,OAAO,oBAAoB,QAAQ,YAAY;AAAA,UAClE,EAAE,IAAI,SAAS,OAA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AAG,KAAK,EACb,IAAI,CAAC,cAAc;AAClB,UAAM,YAAY,UAAU,YAAY,CAAC,KAAK;AAC9C,WAAO,aAAa,MAAS,aAAa,OAAQ,aAAa,MAAQ,MAAM;AAAA,EAC/E,CAAC,EACA,KAAK,EAAE,EACP,KAAK;AACV;AAEA,SAAS,YAAY,OAAgB;AACnC,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D;",
|
|
6
|
+
"names": ["defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "sanitizeTerminalText", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "sanitizeTerminalText", "defineMenu", "safeModelReference", "runMenu", "safeModelMetadata", "sanitizeTerminalText"]
|
|
7
|
+
}
|
package/dist/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
configuredThinkingLevel,
|
|
23
23
|
createImplementationRetentionCoordinator,
|
|
24
24
|
exportStoredPlan,
|
|
25
|
+
filterAvailableSelectedToolNames,
|
|
25
26
|
findAvailableImplementationModel,
|
|
26
27
|
findBlockedCommandSegment,
|
|
27
28
|
findBlockedPowerShellCommandSegment,
|
|
@@ -39,14 +40,15 @@ import {
|
|
|
39
40
|
planModeCompleted,
|
|
40
41
|
planModeQuestionCancelled,
|
|
41
42
|
planModeSettingsPath,
|
|
43
|
+
planModeToolAvailability,
|
|
44
|
+
planModeToolSelection,
|
|
42
45
|
readCommand,
|
|
43
46
|
readPlanModeSettings,
|
|
44
47
|
renderPlanModeCompletion,
|
|
45
48
|
snapshotAvailableImplementationModels,
|
|
46
49
|
snapshotPlanModeSelectedNames,
|
|
47
|
-
toolPolicyLabel,
|
|
48
50
|
updatePlanModeSettings
|
|
49
|
-
} from "./chunks/chunk-
|
|
51
|
+
} from "./chunks/chunk-MJV6WNHK.ts";
|
|
50
52
|
|
|
51
53
|
// src/plan-mode.ts
|
|
52
54
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
@@ -165,6 +167,9 @@ function createDeferredFreshHandoffCoordinator(dependencies = defaultDependencie
|
|
|
165
167
|
import { randomUUID } from "node:crypto";
|
|
166
168
|
import { stripVTControlCharacters } from "node:util";
|
|
167
169
|
|
|
170
|
+
// src/mode-contract.ts
|
|
171
|
+
import { createHash } from "node:crypto";
|
|
172
|
+
|
|
168
173
|
// src/prompt.ts
|
|
169
174
|
var PLAN_CONTEXT_MARKER = "[CODEX-LIKE PLAN MODE ACTIVE]";
|
|
170
175
|
function buildPlanModePrompt() {
|
|
@@ -178,7 +183,7 @@ You are in Plan Mode, a Codex-like collaboration mode for producing a decision-c
|
|
|
178
183
|
- Stay in Plan Mode until a developer or extension explicitly exits it.
|
|
179
184
|
- Treat requests to implement as requests to plan the implementation; do not edit files or carry out the plan.
|
|
180
185
|
- Do not use update_plan/TODO tooling in Plan Mode; Plan Mode is conversational planning, not execution progress tracking.
|
|
181
|
-
- Plan Mode keeps the session's model-visible tool schemas unchanged and enforces a runtime policy allowlist.
|
|
186
|
+
- Plan Mode keeps the session's model-visible tool schemas unchanged and enforces a runtime policy allowlist. Tools outside its reviewed core policy, including native MCP tools and orchestration tools, require explicit user opt-in at their own risk. Direct and model-only tools must be active; registered codemode or deferred tools can be selected without direct activation. Every nested call requires its own permission; selecting an orchestrator does not authorize its callees.
|
|
182
187
|
- Do not perform mutating actions: no edit/write tools, no patching, no formatting that rewrites files, no dependency installation, no commits, no migrations.
|
|
183
188
|
|
|
184
189
|
## Phase 1 \u2014 Ground in the environment
|
|
@@ -230,6 +235,7 @@ If the user requests revisions after a completed plan, the next plan_mode_comple
|
|
|
230
235
|
// src/mode-contract.ts
|
|
231
236
|
var MODE_CONTRACT_MESSAGE_TYPE = "plan-mode-transition";
|
|
232
237
|
var MODE_CONTRACT_VERSION = 1;
|
|
238
|
+
var PRE_NATIVE_MCP_PLAN_CONTRACT_SHA256 = "9d1dcbca0a8641ad639e54a843d1938bae14b5dab81c826e21a03fa525355f59";
|
|
233
239
|
var PLAN_CONTRACT_MARKER = `[PI PLAN MODE CONTRACT v${MODE_CONTRACT_VERSION}: PLAN]`;
|
|
234
240
|
var NORMAL_CONTRACT_MARKER = `[PI PLAN MODE CONTRACT v${MODE_CONTRACT_VERSION}: NORMAL]`;
|
|
235
241
|
var NORMAL_CONTRACT = `${NORMAL_CONTRACT_MARKER}
|
|
@@ -256,6 +262,8 @@ function modeContractFromMessage(message) {
|
|
|
256
262
|
if (candidate.customType !== MODE_CONTRACT_MESSAGE_TYPE) return void 0;
|
|
257
263
|
if (candidate.content === modeContractContent("plan")) return "plan";
|
|
258
264
|
if (candidate.content === modeContractContent("normal")) return "normal";
|
|
265
|
+
if (typeof candidate.content === "string" && createHash("sha256").update(candidate.content).digest("hex") === PRE_NATIVE_MCP_PLAN_CONTRACT_SHA256)
|
|
266
|
+
return "plan";
|
|
259
267
|
return void 0;
|
|
260
268
|
}
|
|
261
269
|
function hasModeContractArtifact(messages) {
|
|
@@ -1036,7 +1044,7 @@ function planMode(pi, dependencies = {}) {
|
|
|
1036
1044
|
const loadInteractiveUi = () => {
|
|
1037
1045
|
if (dependencies.loadInteractiveUi) return dependencies.loadInteractiveUi();
|
|
1038
1046
|
if (!interactiveUiPromise) {
|
|
1039
|
-
interactiveUiPromise = import("./chunks/interactive-ui-
|
|
1047
|
+
interactiveUiPromise = import("./chunks/interactive-ui-F7FMN7FT.ts").catch((error) => {
|
|
1040
1048
|
interactiveUiPromise = void 0;
|
|
1041
1049
|
throw error;
|
|
1042
1050
|
});
|
|
@@ -1483,23 +1491,32 @@ function planMode(pi, dependencies = {}) {
|
|
|
1483
1491
|
reason: activeToolNames.has(event.toolName) ? `Plan mode blocks tool '${event.toolName}' because its safe policy metadata is unavailable.` : `Plan mode blocks tool '${event.toolName}' because it is not registered or active. Register and activate it before starting the next Plan workflow.`
|
|
1484
1492
|
};
|
|
1485
1493
|
}
|
|
1486
|
-
if (
|
|
1494
|
+
if (!calledTool.sourceInfo?.source) {
|
|
1487
1495
|
return {
|
|
1488
1496
|
block: true,
|
|
1489
|
-
reason: `Plan mode blocks tool '${event.toolName}' because its
|
|
1497
|
+
reason: `Plan mode blocks tool '${event.toolName}' because its safe policy metadata is unavailable.`
|
|
1490
1498
|
};
|
|
1491
1499
|
}
|
|
1492
|
-
|
|
1493
|
-
if (!activeToolNames.has(event.toolName)) {
|
|
1500
|
+
if (classifyPlanModeTool(calledTool) === "blocked") {
|
|
1494
1501
|
return {
|
|
1495
1502
|
block: true,
|
|
1496
|
-
reason:
|
|
1503
|
+
reason: `Plan mode blocks tool '${event.toolName}' because its built-in policy is blocked and settings cannot enable it.`
|
|
1497
1504
|
};
|
|
1498
1505
|
}
|
|
1506
|
+
const allowedToolNames = new Set(planModePolicyToolNames());
|
|
1507
|
+
const availability = planModeToolAvailability(
|
|
1508
|
+
calledTool,
|
|
1509
|
+
activeToolNames,
|
|
1510
|
+
event.parentToolCallId ? "nested" : "model"
|
|
1511
|
+
);
|
|
1512
|
+
if (availability !== "available") {
|
|
1513
|
+
const reason = availability === "inactive" ? allowedToolNames.has(event.toolName) ? "it was admitted to the active Plan workflow but is currently inactive. Reactivate it to continue without restarting." : "it is registered but inactive. Activate it before starting the next Plan workflow." : availability === "hidden" ? "it is hidden in Pi. Stored selection cannot enable hidden tools." : availability === "model-only" ? "it is model-only and cannot be called by another tool." : "its tool exposure is unsupported.";
|
|
1514
|
+
return { block: true, reason: `Plan mode blocks tool '${event.toolName}' because ${reason}` };
|
|
1515
|
+
}
|
|
1499
1516
|
if (!allowedToolNames.has(event.toolName)) {
|
|
1500
1517
|
return {
|
|
1501
1518
|
block: true,
|
|
1502
|
-
reason: workflowDesiredToolNames().has(event.toolName) ? `Plan mode blocks tool '${event.toolName}' because it was not available when the active Plan workflow froze its tool policy. Exit Plan mode, then start again after the tool is
|
|
1519
|
+
reason: workflowDesiredToolNames().has(event.toolName) ? `Plan mode blocks tool '${event.toolName}' because it was not available when the active Plan workflow froze its tool policy. Exit Plan mode, then start again after the tool is available.` : `Plan mode blocks tool '${event.toolName}' because it is not selected by the Plan policy. Exit Plan mode, then enable it with /plan tools or defaultPlanTools before starting again.`
|
|
1503
1520
|
};
|
|
1504
1521
|
}
|
|
1505
1522
|
if (event.toolName === "bash") {
|
|
@@ -2017,7 +2034,7 @@ ${intent.plan}`,
|
|
|
2017
2034
|
getSelectedNames: () => snapshotPlanModeSelectedNames(tools, toolSelectionSnapshot()),
|
|
2018
2035
|
toolSummary: (selectedNames) => {
|
|
2019
2036
|
const allowed = tools.filter(
|
|
2020
|
-
(tool) =>
|
|
2037
|
+
(tool) => planModeToolAvailability(tool, activeToolNames) === "available" && selectedNames.has(tool.name) && canSelectToolInPlanMode(tool)
|
|
2021
2038
|
).map((tool) => tool.name);
|
|
2022
2039
|
const pending = pendingNames.filter((name) => selectedNames.has(name)).map(terminalToolName);
|
|
2023
2040
|
const visiblePending = pending.slice(0, 3);
|
|
@@ -2029,17 +2046,9 @@ ${intent.plan}`,
|
|
|
2029
2046
|
},
|
|
2030
2047
|
tools: [
|
|
2031
2048
|
...tools.map((tool) => {
|
|
2032
|
-
const selectable = canSelectToolInPlanMode(tool);
|
|
2033
|
-
const active = activeToolNames.has(tool.name);
|
|
2034
|
-
const retained = retainedInactiveNames.has(tool.name);
|
|
2035
|
-
const policy = active ? toolPolicyLabel(tool) : retained ? "not active yet; retained for first-request resolution" : "not active in this Pi session";
|
|
2036
|
-
const description = tool.description ?? "No description available";
|
|
2037
2049
|
return {
|
|
2038
2050
|
name: tool.name,
|
|
2039
|
-
|
|
2040
|
-
searchText: [policy, description].join(" "),
|
|
2041
|
-
disabled: !selectable || !active,
|
|
2042
|
-
disabledReason: !active ? retained ? "Not active yet; retained and resolved before the first request" : "Not active in Pi; Plan mode will not activate it" : selectable ? void 0 : "Blocked by Plan-mode policy"
|
|
2051
|
+
...planModeToolSelection(tool, activeToolNames, retainedInactiveNames.has(tool.name))
|
|
2043
2052
|
};
|
|
2044
2053
|
}),
|
|
2045
2054
|
...pendingNames.map((name) => {
|
|
@@ -2063,8 +2072,9 @@ ${intent.plan}`,
|
|
|
2063
2072
|
},
|
|
2064
2073
|
startWithTools: (names, signal) => {
|
|
2065
2074
|
if (signal.aborted || !lifecycle.isCurrent()) return;
|
|
2075
|
+
const availableNames = new Set(filterAvailableSelectedToolNames(names, tools, activeToolNames));
|
|
2066
2076
|
const selectedToolNames = Array.from(
|
|
2067
|
-
new Set(names.filter((name) =>
|
|
2077
|
+
new Set(names.filter((name) => availableNames.has(name) || retainedInactiveNames.has(name)))
|
|
2068
2078
|
);
|
|
2069
2079
|
if (enterPlanMode(ctx, { selectedToolNames, selectedToolKeys: void 0 })) {
|
|
2070
2080
|
ctx.ui.notify("Plan mode enabled with the selected tools.", "info");
|
|
@@ -2200,11 +2210,11 @@ ${intent.plan}`,
|
|
|
2200
2210
|
return state.selectedToolNames !== void 0 || state.selectedToolKeys !== void 0 || settings.defaultPlanTools !== void 0;
|
|
2201
2211
|
}
|
|
2202
2212
|
function desiredPlanModeToolNames() {
|
|
2203
|
-
const tools =
|
|
2213
|
+
const tools = availablePlanPolicyTools();
|
|
2204
2214
|
return Array.from(snapshotPlanModeSelectedNames(tools, toolSelectionSnapshot()));
|
|
2205
2215
|
}
|
|
2206
2216
|
function automaticPlanModeToolNames() {
|
|
2207
|
-
return Array.from(snapshotPlanModeSelectedNames(
|
|
2217
|
+
return Array.from(snapshotPlanModeSelectedNames(availablePlanPolicyTools(), {}));
|
|
2208
2218
|
}
|
|
2209
2219
|
function resolveWorkflowToolPolicy(policy) {
|
|
2210
2220
|
return resolvePlanModePolicyToolNames(
|
|
@@ -2255,7 +2265,7 @@ ${intent.plan}`,
|
|
|
2255
2265
|
}
|
|
2256
2266
|
function resolvePlanModePolicyToolNames(desiredNames) {
|
|
2257
2267
|
const selectedNames = new Set(desiredNames);
|
|
2258
|
-
return
|
|
2268
|
+
return availablePlanPolicyTools().filter((tool) => selectedNames.has(tool.name) && canSelectToolInPlanMode(tool)).map((tool) => tool.name);
|
|
2259
2269
|
}
|
|
2260
2270
|
function toolSelectionSnapshot() {
|
|
2261
2271
|
return {
|
|
@@ -2267,9 +2277,9 @@ ${intent.plan}`,
|
|
|
2267
2277
|
function selectableTools() {
|
|
2268
2278
|
return safeGetAllTools().filter((tool) => tool.name !== PLAN_MODE_QUESTION_TOOL_NAME && tool.name !== PLAN_MODE_COMPLETE_TOOL_NAME).sort(compareTools);
|
|
2269
2279
|
}
|
|
2270
|
-
function
|
|
2280
|
+
function availablePlanPolicyTools() {
|
|
2271
2281
|
const activeNames = new Set(safeGetActiveTools());
|
|
2272
|
-
return selectableTools().filter((tool) =>
|
|
2282
|
+
return selectableTools().filter((tool) => planModeToolAvailability(tool, activeNames) === "available");
|
|
2273
2283
|
}
|
|
2274
2284
|
function safeGetAllTools() {
|
|
2275
2285
|
try {
|