@narumitw/pi-plan-mode 0.53.0 → 0.54.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 +16 -7
- package/dist/chunks/{chunk-D2V3VWND.ts → chunk-U5CQ7RQX.js} +128 -4
- package/dist/chunks/chunk-U5CQ7RQX.js.map +7 -0
- package/dist/chunks/{interactive-ui-VESWS25D.ts → interactive-ui-W3VYAJIQ.js} +3 -3
- package/dist/index.ts +66 -26
- package/dist/index.ts.map +2 -2
- package/package.json +5 -5
- package/src/plan-mode.ts +21 -8
- package/src/presentation.ts +50 -17
- package/src/tool-policy.ts +137 -2
- package/dist/chunks/chunk-D2V3VWND.ts.map +0 -7
- /package/dist/chunks/{interactive-ui-VESWS25D.ts.map → interactive-ui-W3VYAJIQ.js.map} +0 -0
package/README.md
CHANGED
|
@@ -14,12 +14,13 @@ This independently installable extension adds a Codex-like `/plan` collaboration
|
|
|
14
14
|
- Reviews the complete plan before implementation, export, save, continued planning, or discard.
|
|
15
15
|
- Starts implementation in the planning session or a fresh linked session with the exact approved plan.
|
|
16
16
|
- Persists Plan state and one saved plan across resume and compaction.
|
|
17
|
-
- Exposes statusline state and a configurable Plan tool allowlist, export destination, plan reinjection, shortcut, and thinking level.
|
|
17
|
+
- Exposes statusline state and a configurable Plan tool allowlist, including reviewed native PowerShell inspection on Windows, plus export destination, plan reinjection, shortcut, and thinking level.
|
|
18
18
|
- Cooperates anonymously with Workflow Mutex Protocol v1 participants so only one agent workflow starts in a session.
|
|
19
19
|
|
|
20
20
|
## 📦 Install
|
|
21
21
|
|
|
22
22
|
This release requires Pi 0.80.6 or newer.
|
|
23
|
+
Native PowerShell tool support requires Pi 0.84.3 or newer on Windows; earlier Pi versions omit that optional tool and retain the existing Plan policy.
|
|
23
24
|
|
|
24
25
|
```bash
|
|
25
26
|
pi install npm:@narumitw/pi-plan-mode
|
|
@@ -143,18 +144,26 @@ Plan mode registers `plan_mode_question` and `plan_mode_complete` during extensi
|
|
|
143
144
|
With the default **After first plan** visibility, `session_start` leaves both helpers inactive until the first admitted Plan workflow appends them in that order.
|
|
144
145
|
With **Always**, `session_start` appends missing helpers in the same canonical order.
|
|
145
146
|
Once revealed, ordinary Plan transitions never remove them during that extension runtime.
|
|
146
|
-
By default, the Plan policy allows active safe built-ins such as `read`, limited `bash`, `grep`, `find`, and `ls`.
|
|
147
|
+
By default, the Plan policy allows active safe built-ins such as `read`, limited `bash`, limited `powershell`, `grep`, `find`, and `ls`.
|
|
148
|
+
The optional native `powershell` tool must already be active, for example through Pi's Windows `defaultTools` setting, before Plan mode can select it.
|
|
147
149
|
Built-in `edit` and `write`, `update_plan`, inactive tools, and deselected tools are blocked at execution time even though active schemas remain visible.
|
|
148
150
|
Extension and custom tools are denied by default because Pi tools do not expose standardized mutability metadata; allow an already active custom tool before starting only when you accept the risk.
|
|
149
151
|
For example, you can opt into an active `firecrawl_scrape`, `firecrawl_search`, or `lsp_diagnostics` tool when you want to use it during planning.
|
|
150
152
|
After they become visible, the Plan-only helpers remain visible in Normal mode, but their handlers and the `tool_call` policy reject calls unless Plan mode owns the active workflow.
|
|
151
153
|
|
|
152
|
-
Limited `bash` uses a fail-closed policy, including when an extension overrides the canonical `bash` tool name.
|
|
154
|
+
Limited `bash` uses a fail-closed Bash policy, including when an extension overrides the canonical `bash` tool name.
|
|
153
155
|
It accepts common inspection commands, read-only Git and npm queries, pipelines and command lists composed entirely of accepted commands, plus selected checks such as `npm test`, `npm run typecheck`, and `cargo test`.
|
|
154
156
|
It rejects output/input redirects, shell expansion, substitutions, subshells, background jobs, mutating flags, dependency changes, editors, and unknown commands.
|
|
157
|
+
|
|
158
|
+
Limited `powershell` uses a separate fail-closed PowerShell policy, including when an extension overrides the canonical `powershell` tool name.
|
|
159
|
+
It accepts canonical inspection cmdlets such as `Get-ChildItem`, `Get-Content`, `Get-Item`, `Get-Location`, `Resolve-Path`, `Select-String`, `Test-Path`, `Measure-Object`, `Sort-Object`, `Format-List`, `Format-Table`, `Out-String`, and `Write-Output`.
|
|
160
|
+
It also accepts the same reviewed `git` and configured `gh` queries as limited Bash, including pipelines and semicolon-delimited command lists composed entirely of accepted commands.
|
|
161
|
+
It rejects redirects, variables, substitutions, script blocks, call operators, type or method expressions, stop-parsing tokens, multiline input, non-ASCII quotation delimiters, aliases, mutating cmdlets, and unknown commands.
|
|
162
|
+
Use canonical cmdlet names because PowerShell aliases are intentionally outside the reviewed policy.
|
|
163
|
+
|
|
155
164
|
A rejected parsed command list or pipeline identifies its first blocked command segment; malformed or unsupported shell syntax reports the complete submitted input instead.
|
|
156
165
|
Tests and builds may still write ignored caches or build artifacts and may execute project-defined hooks; enable or invoke them only when the repository is trusted.
|
|
157
|
-
|
|
166
|
+
Both limited-shell policies are extension-level risk reduction, not an OS sandbox or confidentiality boundary.
|
|
158
167
|
|
|
159
168
|
`plan_mode_question` follows Codex's `request_user_input` pattern: the agent can ask 1-3 concise questions, each with meaningful options and a free-form Other path.
|
|
160
169
|
In TUI mode, a single question shows its header as plain muted text, submits as soon as its preset or custom answer is confirmed, and does not show tabs, Review, or question-navigation controls.
|
|
@@ -349,7 +358,7 @@ An ordinary tool registered or activated after the startup baseline is outside t
|
|
|
349
358
|
Non-built-in names in this global setting are an explicit user-risk opt-in, just like selecting them in the pre-start workflow selector.
|
|
350
359
|
Plan mode does not interpret a selected custom tool's arguments or actions: allowing one trusts the whole effective tool.
|
|
351
360
|
Pi resolves tools by name, so if an extension overrides a built-in name, the effective extension tool is selected instead.
|
|
352
|
-
An effective active tool named `bash` remains subject to
|
|
361
|
+
An effective active tool named `bash` or `powershell` remains subject to its limited-shell policy regardless of its source metadata.
|
|
353
362
|
|
|
354
363
|
A selection accepted through **Choose tools, then start…** or `/plan tools` is stored in that Pi session and takes precedence over `defaultPlanTools` when the session resumes.
|
|
355
364
|
The global setting remains the policy baseline for fresh sessions and sessions without an explicit selection.
|
|
@@ -392,7 +401,7 @@ Avoid values that conflict with editor shortcuts.
|
|
|
392
401
|
|
|
393
402
|
### Safe shell subcommands
|
|
394
403
|
|
|
395
|
-
`safeSubcommands` adds reviewed command validators to limited `bash`; it is not a raw shell allowlist.
|
|
404
|
+
`safeSubcommands` adds reviewed command validators to limited `bash` and `powershell`; it is not a raw shell allowlist.
|
|
396
405
|
Only the following exact values are accepted:
|
|
397
406
|
|
|
398
407
|
- `git`: `status`, `log`, `diff`, `show`, `branch`, `remote`, `ls-files`, `grep`, `rev-parse`, `blame`, `describe`, `merge-base`, `ls-tree`, and `cat-file`.
|
|
@@ -472,7 +481,7 @@ This extension maps Codex's `ModeKind::Plan` behavior onto Pi's extension API:
|
|
|
472
481
|
- `update_plan` checklist use is blocked while Plan mode is active.
|
|
473
482
|
- The implementation boundary is explicit: Plan mode appends the Normal contract and lifts its runtime allowlist before saving or starting implementation, while revealed helpers remain active.
|
|
474
483
|
- The default `clear-on-start` policy follows Codex by using ordinary conversation history only; `clear-after-first-run` and `keep` add explicit exact-plan guarantees.
|
|
475
|
-
- Pi extension safety is approximated with tool classification and fail-closed filtering for every effective tool named `bash`; other non-built-in tools remain user-selected at user risk because Pi does not expose standardized tool mutability metadata.
|
|
484
|
+
- Pi extension safety is approximated with tool classification and separate fail-closed filtering for every effective tool named `bash` or `powershell`; other non-built-in tools remain user-selected at user risk because Pi does not expose standardized tool mutability metadata.
|
|
476
485
|
- Plan and Normal instructions are append-only conversation contracts; **Always** keeps tool schemas stable from startup, while **After first plan** intentionally changes the helper schema and prompt-metadata prefix once before keeping it stable.
|
|
477
486
|
- Unlike native Codex, this extension uses a terminating Pi tool plus an `agent_settled` ready flow; Pi cannot provide sandbox-level enforcement.
|
|
478
487
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
-
// @ts-nocheck -- generated
|
|
2
|
+
// @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
|
|
4
4
|
// src/completion-tool.ts
|
|
5
5
|
import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
@@ -644,7 +644,14 @@ var SAFE_GIT_SUBCOMMANDS = [
|
|
|
644
644
|
...CONFIGURABLE_SAFE_GIT_SUBCOMMANDS
|
|
645
645
|
];
|
|
646
646
|
var SAFE_GH_SUBCOMMAND_PATHS = ["pr view", "pr list", "issue view", "issue list"];
|
|
647
|
-
var SAFE_BUILTIN_PLAN_TOOLS = /* @__PURE__ */ new Set([
|
|
647
|
+
var SAFE_BUILTIN_PLAN_TOOLS = /* @__PURE__ */ new Set([
|
|
648
|
+
"read",
|
|
649
|
+
"bash",
|
|
650
|
+
"powershell",
|
|
651
|
+
"grep",
|
|
652
|
+
"find",
|
|
653
|
+
"ls"
|
|
654
|
+
]);
|
|
648
655
|
var BLOCKED_BUILTIN_TOOLS = /* @__PURE__ */ new Set(["edit", "write"]);
|
|
649
656
|
var MUTATING_COMMANDS = /* @__PURE__ */ new Set([
|
|
650
657
|
"rm",
|
|
@@ -674,6 +681,21 @@ var MUTATING_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
674
681
|
"code",
|
|
675
682
|
"subl"
|
|
676
683
|
]);
|
|
684
|
+
var READ_ONLY_POWERSHELL_COMMANDS = /* @__PURE__ */ new Set([
|
|
685
|
+
"format-list",
|
|
686
|
+
"format-table",
|
|
687
|
+
"get-childitem",
|
|
688
|
+
"get-content",
|
|
689
|
+
"get-item",
|
|
690
|
+
"get-location",
|
|
691
|
+
"measure-object",
|
|
692
|
+
"out-string",
|
|
693
|
+
"resolve-path",
|
|
694
|
+
"select-string",
|
|
695
|
+
"sort-object",
|
|
696
|
+
"test-path",
|
|
697
|
+
"write-output"
|
|
698
|
+
]);
|
|
677
699
|
var READ_ONLY_COMMANDS = /* @__PURE__ */ new Set([
|
|
678
700
|
"cat",
|
|
679
701
|
"head",
|
|
@@ -715,7 +737,7 @@ function isBuiltinTool(tool) {
|
|
|
715
737
|
function classifyPlanModeTool(tool) {
|
|
716
738
|
if (!isBuiltinTool(tool)) return "user-opt-in";
|
|
717
739
|
if (BLOCKED_BUILTIN_TOOLS.has(tool.name)) return "blocked";
|
|
718
|
-
if (tool.name === "bash") return "limited";
|
|
740
|
+
if (tool.name === "bash" || tool.name === "powershell") return "limited";
|
|
719
741
|
return SAFE_BUILTIN_PLAN_TOOLS.has(tool.name) ? "read-only" : "blocked";
|
|
720
742
|
}
|
|
721
743
|
function canSelectToolInPlanMode(tool) {
|
|
@@ -730,6 +752,107 @@ function findBlockedCommandSegment(command, safeSubcommands = {}) {
|
|
|
730
752
|
if (!segments || segments.length === 0) return command.trim() || "(empty command)";
|
|
731
753
|
return segments.find((segment) => !isSafeSegment(segment, safeSubcommands));
|
|
732
754
|
}
|
|
755
|
+
function findBlockedPowerShellCommandSegment(command, safeSubcommands = {}) {
|
|
756
|
+
const segments = splitPowerShellSegments(command);
|
|
757
|
+
if (!segments || segments.length === 0) return command.trim() || "(empty command)";
|
|
758
|
+
return segments.find((segment) => !isSafePowerShellSegment(segment, safeSubcommands));
|
|
759
|
+
}
|
|
760
|
+
function splitPowerShellSegments(command) {
|
|
761
|
+
const trimmed = command.trim();
|
|
762
|
+
if (!trimmed || /[\n\r`\u2018-\u201e]/.test(trimmed)) return void 0;
|
|
763
|
+
const segments = [];
|
|
764
|
+
let quote;
|
|
765
|
+
let start = 0;
|
|
766
|
+
for (let index = 0; index < trimmed.length; index += 1) {
|
|
767
|
+
const character = trimmed[index];
|
|
768
|
+
if (quote === "'") {
|
|
769
|
+
if (character !== "'") continue;
|
|
770
|
+
if (trimmed[index + 1] === "'") {
|
|
771
|
+
index += 1;
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
quote = void 0;
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
if (quote === '"') {
|
|
778
|
+
if (character === "$" || character === "`") return void 0;
|
|
779
|
+
if (character === '"') quote = void 0;
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
if (character === "'" || character === '"') {
|
|
783
|
+
quote = character;
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
if (["$", "@", "#", "!", "?", "{", "}", "(", ")", "[", "]", ">", "<"].includes(character)) {
|
|
787
|
+
return void 0;
|
|
788
|
+
}
|
|
789
|
+
const next = trimmed[index + 1];
|
|
790
|
+
if (character === "&" || character === "|" && next === "|") return void 0;
|
|
791
|
+
const separatorLength = character === ";" || character === "|" ? 1 : 0;
|
|
792
|
+
if (separatorLength === 0) continue;
|
|
793
|
+
const segment = trimmed.slice(start, index).trim();
|
|
794
|
+
if (!segment) return void 0;
|
|
795
|
+
segments.push(segment);
|
|
796
|
+
index += separatorLength - 1;
|
|
797
|
+
start = index + 1;
|
|
798
|
+
}
|
|
799
|
+
if (quote) return void 0;
|
|
800
|
+
const finalSegment = trimmed.slice(start).trim();
|
|
801
|
+
if (!finalSegment) return void 0;
|
|
802
|
+
segments.push(finalSegment);
|
|
803
|
+
return segments;
|
|
804
|
+
}
|
|
805
|
+
function isSafePowerShellSegment(segment, safeSubcommands) {
|
|
806
|
+
const tokens = powerShellWords(segment);
|
|
807
|
+
if (!tokens || tokens.length === 0 || tokens.includes("--%")) return false;
|
|
808
|
+
const command = tokens[0]?.toLowerCase();
|
|
809
|
+
if (!command) return false;
|
|
810
|
+
const args = tokens.slice(1);
|
|
811
|
+
if (READ_ONLY_POWERSHELL_COMMANDS.has(command)) return true;
|
|
812
|
+
if (command !== "git" && command !== "gh") return false;
|
|
813
|
+
return isSafeStructuredCommand(command, args, safeSubcommands);
|
|
814
|
+
}
|
|
815
|
+
function powerShellWords(segment) {
|
|
816
|
+
const words = [];
|
|
817
|
+
let word = "";
|
|
818
|
+
let hasWord = false;
|
|
819
|
+
let quote;
|
|
820
|
+
for (let index = 0; index < segment.length; index += 1) {
|
|
821
|
+
const character = segment[index];
|
|
822
|
+
if (quote === "'") {
|
|
823
|
+
if (character !== "'") {
|
|
824
|
+
word += character;
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
if (segment[index + 1] === "'") {
|
|
828
|
+
word += "'";
|
|
829
|
+
index += 1;
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
quote = void 0;
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
if (quote === '"') {
|
|
836
|
+
if (character === '"') quote = void 0;
|
|
837
|
+
else word += character;
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
if (character === "'" || character === '"') {
|
|
841
|
+
quote = character;
|
|
842
|
+
hasWord = true;
|
|
843
|
+
} else if (/\s/.test(character)) {
|
|
844
|
+
if (hasWord) words.push(word);
|
|
845
|
+
word = "";
|
|
846
|
+
hasWord = false;
|
|
847
|
+
} else {
|
|
848
|
+
word += character;
|
|
849
|
+
hasWord = true;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
if (quote) return void 0;
|
|
853
|
+
if (hasWord) words.push(word);
|
|
854
|
+
return words;
|
|
855
|
+
}
|
|
733
856
|
function splitShellSegments(command) {
|
|
734
857
|
const trimmed = command.trim();
|
|
735
858
|
if (!trimmed || /[\n\r`]/.test(trimmed)) return void 0;
|
|
@@ -1581,6 +1704,7 @@ export {
|
|
|
1581
1704
|
canSelectToolInPlanMode,
|
|
1582
1705
|
readCommand,
|
|
1583
1706
|
findBlockedCommandSegment,
|
|
1707
|
+
findBlockedPowerShellCommandSegment,
|
|
1584
1708
|
PLAN_MODE_THINKING_LEVELS,
|
|
1585
1709
|
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
1586
1710
|
PLAN_MODE_TOOL_VISIBILITIES,
|
|
@@ -1603,4 +1727,4 @@ export {
|
|
|
1603
1727
|
defaultPlanModeToolNames,
|
|
1604
1728
|
snapshotPlanModeSelectedNames
|
|
1605
1729
|
};
|
|
1606
|
-
//# sourceMappingURL=chunk-
|
|
1730
|
+
//# sourceMappingURL=chunk-U5CQ7RQX.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/completion-tool.ts", "../../src/message-transform.ts", "../../src/question-tool.ts", "../../src/implementation-retention.ts", "../../src/tool-policy.ts", "../../src/settings.ts", "../../src/plan-export.ts", "../../src/tool-selection.ts"],
|
|
4
|
+
"sourcesContent": ["import { getMarkdownTheme } from \"@earendil-works/pi-coding-agent\";\nimport { Markdown } from \"@earendil-works/pi-tui\";\n\nexport const PLAN_MODE_COMPLETE_TOOL_NAME = \"plan_mode_complete\";\nexport const PLAN_MODE_COMPLETE_VERSION = 1;\nexport const PLAN_MODE_MAX_CHARS = 50_000;\n\nexport type PlanModeCompletionDetails = {\n\tversion: typeof PLAN_MODE_COMPLETE_VERSION;\n\tsource: typeof PLAN_MODE_COMPLETE_TOOL_NAME;\n\tplan: string;\n};\n\nexport const PLAN_MODE_COMPLETE_PARAMS = {\n\ttype: \"object\",\n\tadditionalProperties: false,\n\trequired: [\"plan\"],\n\tproperties: {\n\t\tplan: {\n\t\t\ttype: \"string\",\n\t\t\tminLength: 1,\n\t\t\tmaxLength: PLAN_MODE_MAX_CHARS,\n\t\t\tdescription: \"The complete decision-ready implementation plan in Markdown.\",\n\t\t},\n\t},\n} as const;\n\ntype NormalizePlanModeCompletionResult = { ok: true; plan: string } | { ok: false; error: string };\n\nexport function normalizePlanModeCompletion(input: unknown): NormalizePlanModeCompletionResult {\n\tif (!isRecord(input) || typeof input.plan !== \"string\") {\n\t\treturn { ok: false, error: \"plan must be a string\" };\n\t}\n\tconst plan = input.plan.trim();\n\tif (!plan) return { ok: false, error: \"plan must not be empty\" };\n\tif (plan.length > PLAN_MODE_MAX_CHARS) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: `plan must not exceed ${PLAN_MODE_MAX_CHARS} characters`,\n\t\t};\n\t}\n\treturn { ok: true, plan };\n}\n\nexport function planFromCompletionDetails(value: unknown) {\n\tif (!isRecord(value)) return undefined;\n\tif (\n\t\tvalue.version !== PLAN_MODE_COMPLETE_VERSION ||\n\t\tvalue.source !== PLAN_MODE_COMPLETE_TOOL_NAME\n\t) {\n\t\treturn undefined;\n\t}\n\tconst normalized = normalizePlanModeCompletion({ plan: value.plan });\n\treturn normalized.ok ? normalized.plan : undefined;\n}\n\nexport function planModeCompleted(plan: string) {\n\treturn {\n\t\tcontent: [{ type: \"text\" as const, text: `**Proposed Plan**\\n\\n${plan}` }],\n\t\tdetails: {\n\t\t\tversion: PLAN_MODE_COMPLETE_VERSION,\n\t\t\tsource: PLAN_MODE_COMPLETE_TOOL_NAME,\n\t\t\tplan,\n\t\t} satisfies PlanModeCompletionDetails,\n\t\tterminate: true,\n\t};\n}\n\ntype PlanModeCompletionRenderResult = {\n\tcontent: Array<{ type: string; text?: string }>;\n\tdetails?: unknown;\n};\n\nexport function planModeCompletionMarkdown(result: PlanModeCompletionRenderResult) {\n\tconst content = result.content\n\t\t.filter((block) => block.type === \"text\" && typeof block.text === \"string\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\")\n\t\t.trim();\n\tif (content) return content;\n\tconst plan = planFromCompletionDetails(result.details);\n\treturn plan ? `**Proposed Plan**\\n\\n${plan}` : \"\";\n}\n\nexport function renderPlanModeCompletion(result: PlanModeCompletionRenderResult) {\n\treturn new Markdown(planModeCompletionMarkdown(result), 0, 0, getMarkdownTheme());\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n", "import { PLAN_MODE_COMPLETE_TOOL_NAME } from \"./completion-tool.js\";\nimport type { ActiveImplementationPlan } from \"./state.js\";\n\nconst PLAN_CONTEXT_MESSAGE_TYPE = \"plan-mode-context\";\nexport const PLAN_IMPLEMENTATION_CONTEXT_MESSAGE_TYPE = \"plan-mode-implementation-context\";\nconst PROPOSED_PLAN_MESSAGE_TYPE = \"proposed-plan\";\nconst PLAN_IMPLEMENTATION_HANDOFF_PREFIX =\n\t\"Plan mode is now disabled. Full tool access is restored. Implement this proposed plan now:\";\nexport const PLAN_HISTORY_IMPLEMENTATION_PROMPT = \"Implement the plan.\";\nconst PROPOSED_PLAN_PATTERN =\n\t/^<proposed_plan>[\\t ]*\\r?\\n([\\s\\S]*?)\\r?\\n<\\/proposed_plan>[\\t ]*$/gm;\nconst PROPOSED_PLAN_BLOCK_PATTERN =\n\t/^<proposed_plan>[\\t ]*\\r?\\n[\\s\\S]*?\\r?\\n<\\/proposed_plan>[\\t ]*$/gm;\n\nexport type ProposedPlanParseResult =\n\t| { kind: \"absent\" }\n\t| { kind: \"valid\"; plan: string }\n\t| { kind: \"empty\" }\n\t| { kind: \"multiple\" }\n\t| { kind: \"malformed\" }\n\t| { kind: \"unclosed\" };\n\ntype SessionMessage = {\n\trole?: string;\n\tcontent?: unknown;\n\tstopReason?: string;\n};\n\ntype TextBlock = {\n\ttype?: string;\n\ttext?: string;\n};\n\nexport function parseProposedPlan(text: string): ProposedPlanParseResult {\n\tconst openingCount = text.match(/<proposed_plan>/gi)?.length ?? 0;\n\tconst closingCount = text.match(/<\\/proposed_plan>/gi)?.length ?? 0;\n\tif (openingCount === 0 && closingCount === 0) return { kind: \"absent\" };\n\tif (openingCount > 1 || closingCount > 1) return { kind: \"multiple\" };\n\tif (openingCount === 1 && closingCount === 0) return { kind: \"unclosed\" };\n\tif (openingCount !== 1 || closingCount !== 1) return { kind: \"malformed\" };\n\n\tconst matches = Array.from(text.matchAll(PROPOSED_PLAN_PATTERN));\n\tif (matches.length !== 1) return { kind: \"malformed\" };\n\tconst plan = matches[0]?.[1]?.trim() ?? \"\";\n\treturn plan ? { kind: \"valid\", plan } : { kind: \"empty\" };\n}\n\nexport function extractProposedPlan(text: string) {\n\tconst result = parseProposedPlan(text);\n\treturn result.kind === \"valid\" ? result.plan : undefined;\n}\n\nexport function invalidPlanMessage(kind: \"empty\" | \"multiple\" | \"malformed\" | \"unclosed\") {\n\tconst detail = {\n\t\tempty: \"the block is empty\",\n\t\tmultiple: \"more than one plan block was produced\",\n\t\tmalformed: \"the tags must be on their own lines\",\n\t\tunclosed: \"the closing tag is missing\",\n\t}[kind];\n\treturn `Proposed plan is not ready: ${detail}. Continue Plan mode and produce one complete non-empty <proposed_plan> block.`;\n}\n\nexport function latestAssistantText(messages: unknown) {\n\tif (!Array.isArray(messages)) return \"\";\n\tfor (const entry of [...messages].reverse()) {\n\t\tconst message = (entry as { message?: SessionMessage })?.message ?? (entry as SessionMessage);\n\t\tif (message?.role !== \"assistant\") continue;\n\t\tconst text = messageText(message);\n\t\tif (text) return text;\n\t}\n\treturn \"\";\n}\n\nexport function latestAssistantStopReason(messages: unknown) {\n\tif (!Array.isArray(messages)) return undefined;\n\tfor (const entry of [...messages].reverse()) {\n\t\tconst message = (entry as { message?: SessionMessage })?.message ?? (entry as SessionMessage);\n\t\tif (message?.role === \"assistant\") return message.stopReason;\n\t}\n\treturn undefined;\n}\n\nexport function messageTextContent(message: unknown) {\n\treturn messageText(\n\t\t(message as { message?: SessionMessage })?.message ?? (message as SessionMessage),\n\t);\n}\n\nexport function messageContainsLegacyPlanModeContextArtifact(message: unknown) {\n\treturn unwrapSessionMessage(message).customType === PLAN_CONTEXT_MESSAGE_TYPE;\n}\n\nexport function messageContainsPlanModeImplementationContextArtifact(message: unknown) {\n\treturn unwrapSessionMessage(message).customType === PLAN_IMPLEMENTATION_CONTEXT_MESSAGE_TYPE;\n}\n\nexport function injectActiveImplementationContext(\n\tmessages: unknown[],\n\tactiveImplementation: ActiveImplementationPlan,\n) {\n\tlet foundCurrentContext = false;\n\tlet foundCurrentHandoff = false;\n\tconst expectedContext = activeImplementationContextContent(activeImplementation);\n\tconst messagesWithoutStaleContext = messages.filter((message) => {\n\t\tif (messageContainsPlanModeImplementationContextArtifact(message)) {\n\t\t\tconst candidate = unwrapSessionMessage(message);\n\t\t\tif (!foundCurrentContext && candidate.content === expectedContext) {\n\t\t\t\tfoundCurrentContext = true;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (!messageContainsPlanModeImplementationHandoff(message)) return true;\n\t\tif (\n\t\t\t!foundCurrentHandoff &&\n\t\t\tmessageContainsExactPlanModeImplementationHandoff(message, activeImplementation.plan)\n\t\t) {\n\t\t\tfoundCurrentHandoff = true;\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t});\n\tif (foundCurrentHandoff || foundCurrentContext) return messagesWithoutStaleContext;\n\n\tlet insertionIndex = 0;\n\twhile (isSummaryMessage(messagesWithoutStaleContext[insertionIndex])) insertionIndex += 1;\n\tconst contextMessage = {\n\t\trole: \"custom\" as const,\n\t\tcustomType: PLAN_IMPLEMENTATION_CONTEXT_MESSAGE_TYPE,\n\t\tcontent: expectedContext,\n\t\tdisplay: false,\n\t\ttimestamp: activeImplementation.startedAt,\n\t};\n\treturn [\n\t\t...messagesWithoutStaleContext.slice(0, insertionIndex),\n\t\tcontextMessage,\n\t\t...messagesWithoutStaleContext.slice(insertionIndex),\n\t];\n}\n\nfunction activeImplementationContextContent(activeImplementation: ActiveImplementationPlan) {\n\treturn `[ACTIVE IMPLEMENTATION PLAN]\\n\\nThe user approved the exact implementation plan below. Continue following it until the user explicitly clears or supersedes it. The exact plan is the remainder of this message:\\n\\n${activeImplementation.plan}`;\n}\n\nexport function messageContainsInactivePlanModeArtifact(message: unknown) {\n\tconst candidate = unwrapSessionMessage(message);\n\treturn (\n\t\tcandidate.customType === PROPOSED_PLAN_MESSAGE_TYPE ||\n\t\t(candidate.role === \"toolResult\" && candidate.toolName === PLAN_MODE_COMPLETE_TOOL_NAME)\n\t);\n}\n\ninterface HistoryImplementationArtifact {\n\tmessageIndex: number;\n\tkind: \"completion\" | \"legacy\" | \"presentation\";\n\ttoolCallId?: string;\n\ttoolCallMessageIndex?: number;\n}\n\n// The kickoff text is intentionally generic, so only trust a plan artifact in the same\n// uninterrupted user/summary segment and require a complete tool-call/result pair.\nexport function findHistoryImplementationArtifact(\n\tmessages: unknown[],\n): HistoryImplementationArtifact | undefined {\n\tfor (let index = messages.length - 1; index >= 0; index -= 1) {\n\t\tconst candidate = unwrapSessionMessage(messages[index]);\n\t\tif (\n\t\t\tcandidate.role !== \"user\" ||\n\t\t\tcontentText(candidate.content).trim() !== PLAN_HISTORY_IMPLEMENTATION_PROMPT\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst artifact = findHistoryImplementationArtifactBeforeKickoff(messages, index);\n\t\tif (artifact) return artifact;\n\t}\n\treturn undefined;\n}\n\nfunction findHistoryImplementationArtifactBeforeKickoff(\n\tmessages: unknown[],\n\tkickoffIndex: number,\n): HistoryImplementationArtifact | undefined {\n\tfor (let index = kickoffIndex - 1; index >= 0; index -= 1) {\n\t\tconst candidate = unwrapSessionMessage(messages[index]);\n\t\tif (candidate.role === \"user\" || isSummaryMessage(messages[index])) return undefined;\n\t\tif (candidate.role === \"toolResult\" && candidate.toolName === PLAN_MODE_COMPLETE_TOOL_NAME) {\n\t\t\tconst toolCallId = candidate.toolCallId;\n\t\t\tconst toolCallMessageIndex = toolCallId\n\t\t\t\t? findPlanModeCompletionCallMessageIndex(messages, index, toolCallId)\n\t\t\t\t: undefined;\n\t\t\tif (toolCallId && toolCallMessageIndex !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tmessageIndex: index,\n\t\t\t\t\tkind: \"completion\",\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\ttoolCallMessageIndex,\n\t\t\t\t};\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (candidate.customType === PROPOSED_PLAN_MESSAGE_TYPE) {\n\t\t\treturn { messageIndex: index, kind: \"presentation\" };\n\t\t}\n\t\tif (\n\t\t\tcandidate.role === \"assistant\" &&\n\t\t\tcontentText(candidate.content).match(PROPOSED_PLAN_BLOCK_PATTERN)\n\t\t) {\n\t\t\treturn { messageIndex: index, kind: \"legacy\" };\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction findPlanModeCompletionCallMessageIndex(\n\tmessages: unknown[],\n\tendIndex: number,\n\ttoolCallId: string,\n) {\n\tfor (let index = endIndex - 1; index >= 0; index -= 1) {\n\t\tconst candidate = unwrapSessionMessage(messages[index]);\n\t\tif (candidate.role === \"user\" || isSummaryMessage(messages[index])) return undefined;\n\t\tif (!Array.isArray(candidate.content)) continue;\n\t\tif (\n\t\t\tcandidate.content.some((block) => {\n\t\t\t\tconst toolCall = block as { type?: string; id?: string; name?: string };\n\t\t\t\treturn (\n\t\t\t\t\ttoolCall.type === \"toolCall\" &&\n\t\t\t\t\ttoolCall.id === toolCallId &&\n\t\t\t\t\ttoolCall.name === PLAN_MODE_COMPLETE_TOOL_NAME\n\t\t\t\t);\n\t\t\t})\n\t\t) {\n\t\t\treturn index;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nexport function messageContainsPlanModeImplementationHandoff(message: unknown) {\n\tconst candidate = unwrapSessionMessage(message);\n\treturn (\n\t\tcandidate.role === \"user\" &&\n\t\tcontentText(candidate.content).trimStart().startsWith(PLAN_IMPLEMENTATION_HANDOFF_PREFIX)\n\t);\n}\n\nexport function messageContainsExactPlanModeImplementationHandoff(message: unknown, plan: string) {\n\tconst candidate = unwrapSessionMessage(message);\n\tif (candidate.role !== \"user\") return false;\n\treturn (\n\t\tcontentText(candidate.content).trim() ===\n\t\t`${PLAN_IMPLEMENTATION_HANDOFF_PREFIX}\\n\\n${plan}`.trim()\n\t);\n}\n\nfunction isSummaryMessage(message: unknown) {\n\tconst role = unwrapSessionMessage(message)?.role;\n\treturn role === \"compactionSummary\" || role === \"branchSummary\";\n}\n\nexport function stripProposedPlanBlocksFromMessage<T>(message: T): T {\n\treturn replaceAssistantContent(message, stripProposedPlanBlocksFromContent);\n}\n\nexport function stripPlanModeCompletionCallsFromMessage<T>(\n\tmessage: T,\n\tpreservedToolCallId?: string,\n): T {\n\treturn replaceAssistantContent(message, (content) => {\n\t\tif (!Array.isArray(content)) return content;\n\t\tconst nextContent = content.filter((block) => {\n\t\t\tconst candidate = block as { type?: string; id?: string; name?: string };\n\t\t\treturn !(\n\t\t\t\tcandidate.type === \"toolCall\" &&\n\t\t\t\tcandidate.name === PLAN_MODE_COMPLETE_TOOL_NAME &&\n\t\t\t\t(!preservedToolCallId || candidate.id !== preservedToolCallId)\n\t\t\t);\n\t\t});\n\t\treturn nextContent.length === content.length ? content : nextContent;\n\t});\n}\n\nexport function isEmptyAssistantMessage(message: unknown) {\n\tconst candidate = unwrapSessionMessage(message);\n\treturn (\n\t\tcandidate.role === \"assistant\" &&\n\t\tArray.isArray(candidate.content) &&\n\t\tcandidate.content.length === 0\n\t);\n}\n\nfunction replaceAssistantContent<T>(message: T, transform: (content: unknown) => unknown): T {\n\tconst candidate = unwrapSessionMessage(message);\n\tif (candidate.role !== \"assistant\") return message;\n\n\tconst content = transform(candidate.content);\n\tif (content === candidate.content) return message;\n\n\tif (isSessionMessageEntry(message)) {\n\t\treturn { ...message, message: { ...candidate, content } };\n\t}\n\treturn { ...candidate, content } as T;\n}\n\nfunction unwrapSessionMessage(message: unknown) {\n\tconst entry = message as { message?: unknown } | null | undefined;\n\treturn (entry?.message ?? message ?? {}) as {\n\t\trole?: string;\n\t\tcustomType?: string;\n\t\ttoolName?: string;\n\t\ttoolCallId?: string;\n\t\tcontent?: unknown;\n\t};\n}\n\nfunction isSessionMessageEntry<T>(message: T): message is T & { message: SessionMessage } {\n\treturn typeof message === \"object\" && message !== null && \"message\" in message;\n}\n\nfunction stripProposedPlanBlocksFromContent(content: unknown) {\n\tif (typeof content === \"string\") return stripProposedPlanBlocks(content);\n\tif (!Array.isArray(content)) return content;\n\n\tlet changed = false;\n\tconst nextContent = content.map((block) => {\n\t\tconst textBlock = block as TextBlock;\n\t\tif (textBlock.type !== \"text\" || typeof textBlock.text !== \"string\") return block;\n\n\t\tconst text = stripProposedPlanBlocks(textBlock.text);\n\t\tif (text === textBlock.text) return block;\n\n\t\tchanged = true;\n\t\treturn { ...textBlock, text };\n\t});\n\treturn changed ? nextContent : content;\n}\n\nexport function stripProposedPlanBlocks(text: string) {\n\treturn text.replace(PROPOSED_PLAN_BLOCK_PATTERN, \"\");\n}\n\nfunction messageText(message: SessionMessage) {\n\treturn contentText(message.content);\n}\n\nfunction contentText(content: unknown): string {\n\tif (typeof content === \"string\") return content;\n\tif (!Array.isArray(content)) return \"\";\n\treturn content\n\t\t.map((block) => {\n\t\t\tconst textBlock = block as TextBlock;\n\t\t\treturn textBlock.type === \"text\" && typeof textBlock.text === \"string\" ? textBlock.text : \"\";\n\t\t})\n\t\t.filter(Boolean)\n\t\t.join(\"\\n\");\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport type {\n\tQuestionnaireAnswer,\n\tQuestionnaireQuestion,\n\tRunQuestionnaireResult,\n} from \"@narumitw/pi-tui-kit\";\n\nexport const PLAN_MODE_QUESTION_TOOL_NAME = \"plan_mode_question\";\nexport const MAX_PLAN_MODE_RESPONSE_LENGTH = 4_000;\n\nexport type PlanModeQuestionOption = {\n\tlabel: string;\n\tdescription?: string;\n};\n\nexport type PlanModeQuestion = {\n\tid: string;\n\theader: string;\n\tquestion: string;\n\toptions: PlanModeQuestionOption[];\n};\n\nexport type PlanModeQuestionAnswer = {\n\tid: string;\n\theader: string;\n\tquestion: string;\n\tanswer: string;\n\twasCustom: boolean;\n\toptionIndex?: number;\n\tnote?: string;\n};\n\ntype PlanModeQuestionReason =\n\t| \"cancelled\"\n\t| \"ui_unavailable\"\n\t| \"plan_mode_inactive\"\n\t| \"invalid_input\";\n\ntype PlanModeQuestionDetails = {\n\tcancelled: boolean;\n\treason?: PlanModeQuestionReason;\n\tquestions: PlanModeQuestion[];\n\tanswers?: PlanModeQuestionAnswer[];\n};\n\nexport const PLAN_MODE_QUESTION_PARAMS = {\n\ttype: \"object\",\n\tadditionalProperties: false,\n\trequired: [\"questions\"],\n\tproperties: {\n\t\tquestions: {\n\t\t\ttype: \"array\",\n\t\t\tminItems: 1,\n\t\t\tmaxItems: 3,\n\t\t\tdescription: \"Questions to show the user. Prefer 1 and do not exceed 3.\",\n\t\t\titems: {\n\t\t\t\ttype: \"object\",\n\t\t\t\tadditionalProperties: false,\n\t\t\t\trequired: [\"id\", \"header\", \"question\", \"options\"],\n\t\t\t\tproperties: {\n\t\t\t\t\tid: {\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\tdescription: \"Stable identifier for mapping answers (snake_case).\",\n\t\t\t\t\t},\n\t\t\t\t\theader: {\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\tdescription: \"Short header label shown in the UI (12 or fewer chars).\",\n\t\t\t\t\t},\n\t\t\t\t\tquestion: { type: \"string\", description: \"Single-sentence prompt shown to the user.\" },\n\t\t\t\t\toptions: {\n\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\tminItems: 2,\n\t\t\t\t\t\tmaxItems: 4,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Provide 2-4 mutually exclusive choices. Put the recommended option first when there is a clear default.\",\n\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t\t\t\trequired: [\"label\", \"description\"],\n\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\tlabel: { type: \"string\", description: \"User-facing label (1-5 words).\" },\n\t\t\t\t\t\t\t\tdescription: {\n\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\tdescription: \"One short sentence explaining impact/tradeoff if selected.\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n} as const;\n\ntype NormalizePlanModeQuestionParamsResult =\n\t| { ok: true; questions: PlanModeQuestion[] }\n\t| { ok: false; error: string };\n\nexport function normalizePlanModeQuestionParams(\n\tinput: unknown,\n): NormalizePlanModeQuestionParamsResult {\n\tif (!isRecord(input) || !Array.isArray(input.questions)) {\n\t\treturn { ok: false, error: \"questions must be an array\" };\n\t}\n\tif (input.questions.length < 1 || input.questions.length > 3) {\n\t\treturn { ok: false, error: \"questions must contain 1-3 items\" };\n\t}\n\n\tconst questions: PlanModeQuestion[] = [];\n\tfor (const [questionIndex, rawQuestion] of input.questions.entries()) {\n\t\tif (!isRecord(rawQuestion)) {\n\t\t\treturn { ok: false, error: `question ${questionIndex + 1} must be an object` };\n\t\t}\n\t\tconst id = stringField(rawQuestion.id);\n\t\tconst header = stringField(rawQuestion.header);\n\t\tconst question = stringField(rawQuestion.question);\n\t\tif (!id || !header || !question) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror: `question ${questionIndex + 1} requires non-empty id, header, and question`,\n\t\t\t};\n\t\t}\n\t\tif (!Array.isArray(rawQuestion.options)) {\n\t\t\treturn { ok: false, error: `question ${questionIndex + 1} options must be an array` };\n\t\t}\n\t\tif (rawQuestion.options.length < 2 || rawQuestion.options.length > 4) {\n\t\t\treturn { ok: false, error: `question ${questionIndex + 1} options must contain 2-4 items` };\n\t\t}\n\t\tconst options: PlanModeQuestionOption[] = [];\n\t\tfor (const [optionIndex, rawOption] of rawQuestion.options.entries()) {\n\t\t\tif (!isRecord(rawOption)) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: `question ${questionIndex + 1} option ${optionIndex + 1} must be an object`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst label = stringField(rawOption.label);\n\t\t\tif (!label) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: `question ${questionIndex + 1} option ${optionIndex + 1} requires a label`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst description = stringField(rawOption.description);\n\t\t\tif (!description) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: `question ${questionIndex + 1} option ${optionIndex + 1} requires a description`,\n\t\t\t\t};\n\t\t\t}\n\t\t\toptions.push({ label, description });\n\t\t}\n\t\tquestions.push({ id, header, question, options });\n\t}\n\treturn { ok: true, questions };\n}\n\nexport async function answerPlanModeQuestions(\n\tquestions: PlanModeQuestion[],\n\tctx: ExtensionContext,\n\tlifecycle: { isCurrent(): boolean; isEnabled(): boolean },\n) {\n\tconst answers = await askPlanModeQuestions(\n\t\tquestions,\n\t\tctx,\n\t\t() => lifecycle.isCurrent() && lifecycle.isEnabled(),\n\t);\n\tif (!lifecycle.isCurrent()) {\n\t\treturn planModeQuestionCancelled(\n\t\t\tquestions,\n\t\t\t\"cancelled\",\n\t\t\t\"Plan-mode question cancelled because the session changed.\",\n\t\t);\n\t}\n\tif (!lifecycle.isEnabled()) {\n\t\treturn planModeQuestionCancelled(\n\t\t\tquestions,\n\t\t\t\"plan_mode_inactive\",\n\t\t\t\"Plan-mode question cancelled because Plan mode is no longer active.\",\n\t\t);\n\t}\n\tif (!answers) {\n\t\treturn planModeQuestionCancelled(\n\t\t\tquestions,\n\t\t\t\"cancelled\",\n\t\t\t\"User cancelled the Plan-mode question prompt.\",\n\t\t);\n\t}\n\treturn planModeQuestionAnswered(questions, answers);\n}\n\nexport async function askPlanModeQuestions(\n\tquestions: PlanModeQuestion[],\n\tctx: ExtensionContext,\n\tshouldContinue: () => boolean = () => true,\n): Promise<PlanModeQuestionAnswer[] | undefined> {\n\tconst { runQuestionnaire, sanitizeTerminalText } = await import(\"@narumitw/pi-tui-kit\");\n\tif (!shouldContinue()) return undefined;\n\tconst runnerQuestions: QuestionnaireQuestion<string>[] = questions.map((question, index) => ({\n\t\tid: String(index),\n\t\theader: displayText(question.header, `Question ${index + 1}`, sanitizeTerminalText),\n\t\tprompt: displayText(question.question, `Question ${index + 1}`, sanitizeTerminalText),\n\t\toptions: question.options.map((option, optionIndex) => ({\n\t\t\t...option,\n\t\t\tlabel: displayText(option.label, `Option ${optionIndex + 1}`, sanitizeTerminalText),\n\t\t})),\n\t}));\n\tconst result = await runQuestionnaire(ctx, {\n\t\tquestions: runnerQuestions,\n\t\tallowNotes: true,\n\t\tmaxTextLength: MAX_PLAN_MODE_RESPONSE_LENGTH,\n\t\tsignal: ctx.signal,\n\t\tisCurrent: shouldContinue,\n\t});\n\tif (!shouldContinue()) return undefined;\n\treturn mapQuestionnaireResult(questions, result);\n}\n\nfunction mapQuestionnaireResult(\n\tquestions: PlanModeQuestion[],\n\tresult: RunQuestionnaireResult<string>,\n): PlanModeQuestionAnswer[] | undefined {\n\tif (result.kind !== \"submitted\") return undefined;\n\tif (result.answers.length !== questions.length) {\n\t\tthrow new Error(\"Questionnaire returned an incomplete answer set\");\n\t}\n\n\tconst answers = new Map<number, QuestionnaireAnswer<string>>();\n\tfor (const answer of result.answers) {\n\t\tconst index = Number(answer.questionId);\n\t\tif (!Number.isSafeInteger(index) || String(index) !== answer.questionId || !questions[index]) {\n\t\t\tthrow new Error(\"Questionnaire returned an answer for an unknown question\");\n\t\t}\n\t\tif (answers.has(index)) throw new Error(\"Questionnaire returned duplicate answers\");\n\t\tif (answer.wasCustom) {\n\t\t\tif (answer.optionIndex !== undefined) {\n\t\t\t\tthrow new Error(\"Questionnaire returned a custom answer with an option index\");\n\t\t\t}\n\t\t\tif (!answer.answer.trim()) return undefined;\n\t\t} else if (\n\t\t\tanswer.optionIndex === undefined ||\n\t\t\t!questions[index]?.options[answer.optionIndex - 1]\n\t\t) {\n\t\t\tthrow new Error(\"Questionnaire returned an invalid selected option\");\n\t\t}\n\t\tanswers.set(index, answer);\n\t}\n\n\treturn questions.map((question, index) => {\n\t\tconst answer = answers.get(index);\n\t\tif (!answer) throw new Error(\"Questionnaire returned an incomplete answer set\");\n\t\tconst answerText = answer.wasCustom\n\t\t\t? answer.answer\n\t\t\t: (question.options[(answer.optionIndex ?? 0) - 1]?.label ?? answer.answer);\n\t\treturn answerFor(question, answerText, {\n\t\t\twasCustom: answer.wasCustom,\n\t\t\toptionIndex: answer.optionIndex,\n\t\t\tnote: answer.note,\n\t\t});\n\t});\n}\n\nfunction displayText(value: string, fallback: string, sanitize: (value: string) => string): string {\n\tconst sanitized = sanitize(value);\n\treturn sanitized.trim() ? sanitized : fallback;\n}\n\nfunction answerFor(\n\tquestion: PlanModeQuestion,\n\tanswer: string,\n\toptions: { wasCustom: boolean; optionIndex?: number; note?: string },\n): PlanModeQuestionAnswer {\n\tconst result: PlanModeQuestionAnswer = {\n\t\tid: question.id,\n\t\theader: question.header,\n\t\tquestion: question.question,\n\t\tanswer,\n\t\twasCustom: options.wasCustom,\n\t};\n\tif (options.optionIndex !== undefined) result.optionIndex = options.optionIndex;\n\tif (options.note !== undefined) result.note = options.note;\n\treturn result;\n}\n\nexport function planModeQuestionAnswered(\n\tquestions: PlanModeQuestion[],\n\tanswers: PlanModeQuestionAnswer[],\n) {\n\treturn {\n\t\tcontent: [\n\t\t\t{ type: \"text\" as const, text: formatPlanModeQuestionPayload({ cancelled: false, answers }) },\n\t\t],\n\t\tdetails: { cancelled: false, questions, answers } satisfies PlanModeQuestionDetails,\n\t};\n}\n\nexport function planModeQuestionCancelled(\n\tquestions: PlanModeQuestion[],\n\treason: PlanModeQuestionReason,\n\tmessage: string,\n) {\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\" as const,\n\t\t\t\ttext: formatPlanModeQuestionPayload({ cancelled: true, reason, message }),\n\t\t\t},\n\t\t],\n\t\tdetails: { cancelled: true, reason, questions } satisfies PlanModeQuestionDetails,\n\t};\n}\n\nfunction formatPlanModeQuestionPayload(payload: {\n\tcancelled: boolean;\n\treason?: PlanModeQuestionReason;\n\tmessage?: string;\n\tanswers?: PlanModeQuestionAnswer[];\n}) {\n\treturn JSON.stringify(payload, null, 2);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction stringField(value: unknown) {\n\treturn typeof value === \"string\" ? value.trim() : undefined;\n}\n", "import {\n\tfindHistoryImplementationArtifact,\n\tinjectActiveImplementationContext,\n\tisEmptyAssistantMessage,\n\tmessageContainsExactPlanModeImplementationHandoff,\n\tmessageContainsInactivePlanModeArtifact,\n\tmessageContainsLegacyPlanModeContextArtifact,\n\tmessageContainsPlanModeImplementationContextArtifact,\n\tmessageContainsPlanModeImplementationHandoff,\n\tstripPlanModeCompletionCallsFromMessage,\n\tstripProposedPlanBlocksFromMessage,\n} from \"./message-transform.js\";\nimport type { ImplementationPlanRetention } from \"./settings.js\";\nimport type { ActiveImplementationPlan, PlanModeState } from \"./state.js\";\n\nexport function retentionLabel(retention: ImplementationPlanRetention) {\n\treturn {\n\t\t\"clear-on-start\": \"Off \u2014 conversation history only\",\n\t\t\"clear-after-first-run\": \"Through first implementation run\",\n\t\tkeep: \"Until manually cleared\",\n\t}[retention];\n}\n\nexport function implementationRetentionPreview(retention: ImplementationPlanRetention) {\n\treturn {\n\t\t\"clear-on-start\": \"Plan reinjection: Off; use conversation history only.\",\n\t\t\"clear-after-first-run\": \"Plan reinjection: Through the first implementation run.\",\n\t\tkeep: \"Plan reinjection: Until /plan exit.\",\n\t}[retention];\n}\n\nexport interface ImplementationContextResult {\n\tmessages: unknown[];\n\tclearActiveImplementationId?: string;\n}\n\nexport interface ImplementationRetentionCoordinator {\n\trestore(activeImplementation: ActiveImplementationPlan | undefined): void;\n\ttransformContext(messages: unknown[], state: PlanModeState): ImplementationContextResult;\n\timplementationSettled(\n\t\tactiveImplementation: ActiveImplementationPlan | undefined,\n\t): string | undefined;\n\treset(): void;\n}\n\nexport function createImplementationRetentionCoordinator(): ImplementationRetentionCoordinator {\n\tlet implementationWithDeliveredContext: string | undefined;\n\tlet restoredImplementationAwaitingContext: string | undefined;\n\n\treturn {\n\t\trestore(activeImplementation) {\n\t\t\trestoredImplementationAwaitingContext =\n\t\t\t\tactiveImplementation && activeImplementation.retention !== \"keep\"\n\t\t\t\t\t? activeImplementation.id\n\t\t\t\t\t: undefined;\n\t\t},\n\t\ttransformContext(messages, state) {\n\t\t\tconst messagesWithoutLegacyContext = messages.filter(\n\t\t\t\t(message) => !messageContainsLegacyPlanModeContextArtifact(message),\n\t\t\t);\n\t\t\tif (state.enabled) {\n\t\t\t\treturn {\n\t\t\t\t\tmessages: messagesWithoutLegacyContext.filter(\n\t\t\t\t\t\t(message) =>\n\t\t\t\t\t\t\t!messageContainsPlanModeImplementationContextArtifact(message) &&\n\t\t\t\t\t\t\t!messageContainsPlanModeImplementationHandoff(message),\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst activeImplementation = state.activeImplementation;\n\t\t\tconst inactiveMessages = activeImplementation\n\t\t\t\t? messagesWithoutLegacyContext\n\t\t\t\t: messagesWithoutLegacyContext.filter(\n\t\t\t\t\t\t(message) =>\n\t\t\t\t\t\t\t!messageContainsPlanModeImplementationContextArtifact(message) &&\n\t\t\t\t\t\t\t!messageContainsPlanModeImplementationHandoff(message),\n\t\t\t\t\t);\n\t\t\tconst historyArtifact = activeImplementation\n\t\t\t\t? undefined\n\t\t\t\t: findHistoryImplementationArtifact(inactiveMessages);\n\t\t\tconst historyArtifactMessage = historyArtifact\n\t\t\t\t? inactiveMessages[historyArtifact.messageIndex]\n\t\t\t\t: undefined;\n\t\t\tconst historyToolCallMessage =\n\t\t\t\thistoryArtifact?.toolCallMessageIndex !== undefined\n\t\t\t\t\t? inactiveMessages[historyArtifact.toolCallMessageIndex]\n\t\t\t\t\t: undefined;\n\t\t\tconst filteredMessages = inactiveMessages\n\t\t\t\t.filter(\n\t\t\t\t\t(message) =>\n\t\t\t\t\t\tmessage === historyArtifactMessage || !messageContainsInactivePlanModeArtifact(message),\n\t\t\t\t)\n\t\t\t\t.map((message) =>\n\t\t\t\t\tmessage === historyArtifactMessage && historyArtifact?.kind === \"legacy\"\n\t\t\t\t\t\t? message\n\t\t\t\t\t\t: stripProposedPlanBlocksFromMessage(message),\n\t\t\t\t)\n\t\t\t\t.map((message) =>\n\t\t\t\t\tstripPlanModeCompletionCallsFromMessage(\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tmessage === historyToolCallMessage ? historyArtifact?.toolCallId : undefined,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.filter((message) => !isEmptyAssistantMessage(message));\n\t\t\tif (!activeImplementation) return { messages: filteredMessages };\n\n\t\t\tconst contextualMessages = injectActiveImplementationContext(\n\t\t\t\tfilteredMessages,\n\t\t\t\tactiveImplementation,\n\t\t\t);\n\t\t\t// A busy /plan implement queues its handoff behind an older run. Do not arm cleanup\n\t\t\t// until that exact handoff reaches context; a restored session has no older run to drain.\n\t\t\tconst deliveredCurrentHandoff =\n\t\t\t\trestoredImplementationAwaitingContext === activeImplementation.id ||\n\t\t\t\tfilteredMessages.some((message) =>\n\t\t\t\t\tmessageContainsExactPlanModeImplementationHandoff(message, activeImplementation.plan),\n\t\t\t\t);\n\t\t\tif (!deliveredCurrentHandoff) return { messages: contextualMessages };\n\t\t\trestoredImplementationAwaitingContext = undefined;\n\n\t\t\tif (activeImplementation.retention === \"clear-after-first-run\") {\n\t\t\t\timplementationWithDeliveredContext = activeImplementation.id;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tmessages: contextualMessages,\n\t\t\t\tclearActiveImplementationId:\n\t\t\t\t\tactiveImplementation.retention === \"clear-on-start\" ? activeImplementation.id : undefined,\n\t\t\t};\n\t\t},\n\t\timplementationSettled(activeImplementation) {\n\t\t\tif (\n\t\t\t\tactiveImplementation?.retention !== \"clear-after-first-run\" ||\n\t\t\t\timplementationWithDeliveredContext !== activeImplementation.id\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\timplementationWithDeliveredContext = undefined;\n\t\t\treturn activeImplementation.id;\n\t\t},\n\t\treset() {\n\t\t\timplementationWithDeliveredContext = undefined;\n\t\t\trestoredImplementationAwaitingContext = undefined;\n\t\t},\n\t};\n}\n", "import type { ToolInfo } from \"@earendil-works/pi-coding-agent\";\n\nexport const BUILTIN_SAFE_GIT_SUBCOMMANDS = [\n\t\"status\",\n\t\"log\",\n\t\"diff\",\n\t\"show\",\n\t\"branch\",\n\t\"remote\",\n\t\"ls-files\",\n\t\"grep\",\n] as const;\nexport const CONFIGURABLE_SAFE_GIT_SUBCOMMANDS = [\n\t\"rev-parse\",\n\t\"blame\",\n\t\"describe\",\n\t\"merge-base\",\n\t\"ls-tree\",\n\t\"cat-file\",\n] as const;\nexport const SAFE_GIT_SUBCOMMANDS = [\n\t...BUILTIN_SAFE_GIT_SUBCOMMANDS,\n\t...CONFIGURABLE_SAFE_GIT_SUBCOMMANDS,\n] as const;\nexport const SAFE_GH_SUBCOMMAND_PATHS = [\"pr view\", \"pr list\", \"issue view\", \"issue list\"] as const;\n\nexport type BuiltinSafeGitSubcommand = (typeof BUILTIN_SAFE_GIT_SUBCOMMANDS)[number];\nexport type ConfigurableSafeGitSubcommand = (typeof CONFIGURABLE_SAFE_GIT_SUBCOMMANDS)[number];\nexport type SafeGitSubcommand = (typeof SAFE_GIT_SUBCOMMANDS)[number];\nexport type SafeGhSubcommandPath = (typeof SAFE_GH_SUBCOMMAND_PATHS)[number];\nexport interface SafeSubcommands {\n\tgit?: SafeGitSubcommand[];\n\tgh?: SafeGhSubcommandPath[];\n}\n\nexport const SAFE_BUILTIN_PLAN_TOOLS = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"powershell\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n]);\nexport type PlanModeToolPolicy = \"read-only\" | \"limited\" | \"user-opt-in\" | \"blocked\";\n\nconst BLOCKED_BUILTIN_TOOLS = new Set([\"edit\", \"write\"]);\nconst MUTATING_COMMANDS = new Set([\n\t\"rm\",\n\t\"rmdir\",\n\t\"mv\",\n\t\"cp\",\n\t\"mkdir\",\n\t\"touch\",\n\t\"chmod\",\n\t\"chown\",\n\t\"chgrp\",\n\t\"ln\",\n\t\"tee\",\n\t\"truncate\",\n\t\"dd\",\n\t\"sudo\",\n\t\"su\",\n\t\"kill\",\n\t\"pkill\",\n\t\"killall\",\n\t\"reboot\",\n\t\"shutdown\",\n\t\"vim\",\n\t\"vi\",\n\t\"nano\",\n\t\"emacs\",\n\t\"code\",\n\t\"subl\",\n]);\nconst READ_ONLY_POWERSHELL_COMMANDS = new Set([\n\t\"format-list\",\n\t\"format-table\",\n\t\"get-childitem\",\n\t\"get-content\",\n\t\"get-item\",\n\t\"get-location\",\n\t\"measure-object\",\n\t\"out-string\",\n\t\"resolve-path\",\n\t\"select-string\",\n\t\"sort-object\",\n\t\"test-path\",\n\t\"write-output\",\n]);\nconst READ_ONLY_COMMANDS = new Set([\n\t\"cat\",\n\t\"head\",\n\t\"tail\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"pwd\",\n\t\"echo\",\n\t\"printf\",\n\t\"wc\",\n\t\"sort\",\n\t\"uniq\",\n\t\"diff\",\n\t\"file\",\n\t\"stat\",\n\t\"du\",\n\t\"df\",\n\t\"tree\",\n\t\"which\",\n\t\"whereis\",\n\t\"type\",\n\t\"printenv\",\n\t\"uname\",\n\t\"whoami\",\n\t\"id\",\n\t\"date\",\n\t\"uptime\",\n\t\"ps\",\n\t\"jq\",\n\t\"rg\",\n\t\"fd\",\n\t\"bat\",\n\t\"eza\",\n]);\n\nexport function isBuiltinTool(tool: ToolInfo) {\n\treturn tool.sourceInfo.source === \"builtin\";\n}\n\nexport function classifyPlanModeTool(tool: ToolInfo): PlanModeToolPolicy {\n\tif (!isBuiltinTool(tool)) return \"user-opt-in\";\n\tif (BLOCKED_BUILTIN_TOOLS.has(tool.name)) return \"blocked\";\n\tif (tool.name === \"bash\" || tool.name === \"powershell\") return \"limited\";\n\treturn SAFE_BUILTIN_PLAN_TOOLS.has(tool.name) ? \"read-only\" : \"blocked\";\n}\n\nexport function canSelectToolInPlanMode(tool: ToolInfo) {\n\treturn classifyPlanModeTool(tool) !== \"blocked\";\n}\n\nexport function readCommand(input: unknown) {\n\tconst command = input as { command?: unknown } | undefined;\n\treturn typeof command?.command === \"string\" ? command.command : \"\";\n}\n\nexport function findBlockedCommandSegment(\n\tcommand: string,\n\tsafeSubcommands: SafeSubcommands = {},\n): string | undefined {\n\tconst segments = splitShellSegments(command);\n\tif (!segments || segments.length === 0) return command.trim() || \"(empty command)\";\n\treturn segments.find((segment) => !isSafeSegment(segment, safeSubcommands));\n}\n\nexport function isSafeCommand(command: string, safeSubcommands: SafeSubcommands = {}) {\n\treturn findBlockedCommandSegment(command, safeSubcommands) === undefined;\n}\n\nexport function findBlockedPowerShellCommandSegment(\n\tcommand: string,\n\tsafeSubcommands: SafeSubcommands = {},\n): string | undefined {\n\tconst segments = splitPowerShellSegments(command);\n\tif (!segments || segments.length === 0) return command.trim() || \"(empty command)\";\n\treturn segments.find((segment) => !isSafePowerShellSegment(segment, safeSubcommands));\n}\n\nexport function isSafePowerShellCommand(command: string, safeSubcommands: SafeSubcommands = {}) {\n\treturn findBlockedPowerShellCommandSegment(command, safeSubcommands) === undefined;\n}\n\nfunction splitPowerShellSegments(command: string): string[] | undefined {\n\tconst trimmed = command.trim();\n\tif (!trimmed || /[\\n\\r`\\u2018-\\u201e]/.test(trimmed)) return undefined;\n\n\tconst segments: string[] = [];\n\tlet quote: \"'\" | '\"' | undefined;\n\tlet start = 0;\n\tfor (let index = 0; index < trimmed.length; index += 1) {\n\t\tconst character = trimmed[index];\n\t\tif (quote === \"'\") {\n\t\t\tif (character !== \"'\") continue;\n\t\t\tif (trimmed[index + 1] === \"'\") {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tquote = undefined;\n\t\t\tcontinue;\n\t\t}\n\t\tif (quote === '\"') {\n\t\t\tif (character === \"$\" || character === \"`\") return undefined;\n\t\t\tif (character === '\"') quote = undefined;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"'\" || character === '\"') {\n\t\t\tquote = character;\n\t\t\tcontinue;\n\t\t}\n\t\tif ([\"$\", \"@\", \"#\", \"!\", \"?\", \"{\", \"}\", \"(\", \")\", \"[\", \"]\", \">\", \"<\"].includes(character)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst next = trimmed[index + 1];\n\t\tif (character === \"&\" || (character === \"|\" && next === \"|\")) return undefined;\n\t\tconst separatorLength = character === \";\" || character === \"|\" ? 1 : 0;\n\t\tif (separatorLength === 0) continue;\n\t\tconst segment = trimmed.slice(start, index).trim();\n\t\tif (!segment) return undefined;\n\t\tsegments.push(segment);\n\t\tindex += separatorLength - 1;\n\t\tstart = index + 1;\n\t}\n\tif (quote) return undefined;\n\tconst finalSegment = trimmed.slice(start).trim();\n\tif (!finalSegment) return undefined;\n\tsegments.push(finalSegment);\n\treturn segments;\n}\n\nfunction isSafePowerShellSegment(segment: string, safeSubcommands: SafeSubcommands) {\n\tconst tokens = powerShellWords(segment);\n\tif (!tokens || tokens.length === 0 || tokens.includes(\"--%\")) return false;\n\tconst command = tokens[0]?.toLowerCase();\n\tif (!command) return false;\n\tconst args = tokens.slice(1);\n\tif (READ_ONLY_POWERSHELL_COMMANDS.has(command)) return true;\n\tif (command !== \"git\" && command !== \"gh\") return false;\n\treturn isSafeStructuredCommand(command, args, safeSubcommands);\n}\n\nfunction powerShellWords(segment: string): string[] | undefined {\n\tconst words: string[] = [];\n\tlet word = \"\";\n\tlet hasWord = false;\n\tlet quote: \"'\" | '\"' | undefined;\n\tfor (let index = 0; index < segment.length; index += 1) {\n\t\tconst character = segment[index];\n\t\tif (quote === \"'\") {\n\t\t\tif (character !== \"'\") {\n\t\t\t\tword += character;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (segment[index + 1] === \"'\") {\n\t\t\t\tword += \"'\";\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tquote = undefined;\n\t\t\tcontinue;\n\t\t}\n\t\tif (quote === '\"') {\n\t\t\tif (character === '\"') quote = undefined;\n\t\t\telse word += character;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"'\" || character === '\"') {\n\t\t\tquote = character;\n\t\t\thasWord = true;\n\t\t} else if (/\\s/.test(character)) {\n\t\t\tif (hasWord) words.push(word);\n\t\t\tword = \"\";\n\t\t\thasWord = false;\n\t\t} else {\n\t\t\tword += character;\n\t\t\thasWord = true;\n\t\t}\n\t}\n\tif (quote) return undefined;\n\tif (hasWord) words.push(word);\n\treturn words;\n}\n\nfunction splitShellSegments(command: string): string[] | undefined {\n\tconst trimmed = command.trim();\n\tif (!trimmed || /[\\n\\r`]/.test(trimmed)) return undefined;\n\n\tconst segments: string[] = [];\n\tlet quote: \"'\" | '\"' | undefined;\n\tlet escaped = false;\n\tlet start = 0;\n\tfor (let index = 0; index < trimmed.length; index += 1) {\n\t\tconst character = trimmed[index];\n\t\tif (escaped) {\n\t\t\tescaped = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"\\\\\" && quote !== \"'\") {\n\t\t\tescaped = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (quote) {\n\t\t\tif (character === quote) quote = undefined;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"'\" || character === '\"') {\n\t\t\tquote = character;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \">\" || character === \"<\" || character === \"(\" || character === \")\") {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst next = trimmed[index + 1];\n\t\tif (character === \"&\" && next !== \"&\") return undefined;\n\t\tconst separatorLength =\n\t\t\tcharacter === \";\" || character === \"|\"\n\t\t\t\t? next === character\n\t\t\t\t\t? 2\n\t\t\t\t\t: 1\n\t\t\t\t: character === \"&\" && next === \"&\"\n\t\t\t\t\t? 2\n\t\t\t\t\t: 0;\n\t\tif (separatorLength === 0) continue;\n\t\tconst segment = trimmed.slice(start, index).trim();\n\t\tif (!segment) return undefined;\n\t\tsegments.push(segment);\n\t\tindex += separatorLength - 1;\n\t\tstart = index + 1;\n\t}\n\tif (quote || escaped) return undefined;\n\tconst finalSegment = trimmed.slice(start).trim();\n\tif (!finalSegment) return undefined;\n\tsegments.push(finalSegment);\n\treturn segments;\n}\n\nfunction isSafeSegment(segment: string, safeSubcommands: SafeSubcommands) {\n\tif (hasShellExpansion(segment) || /(^|\\s)[A-Za-z_][A-Za-z0-9_]*=/.test(segment)) {\n\t\treturn false;\n\t}\n\tconst tokens = shellWords(segment);\n\tif (!tokens || tokens.length === 0) return false;\n\tconst command = tokens[0]?.toLowerCase();\n\tif (!command || MUTATING_COMMANDS.has(command)) return false;\n\tconst args = tokens.slice(1);\n\tif (!hasSafeArguments(command, args)) return false;\n\tif (READ_ONLY_COMMANDS.has(command)) return true;\n\treturn isSafeStructuredCommand(command, args, safeSubcommands);\n}\n\nfunction hasShellExpansion(segment: string) {\n\tlet quote: \"'\" | '\"' | undefined;\n\tlet escaped = false;\n\tfor (const character of segment) {\n\t\tif (escaped) {\n\t\t\tescaped = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"\\\\\" && quote !== \"'\") {\n\t\t\tescaped = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (quote) {\n\t\t\tif (character === quote) quote = undefined;\n\t\t\telse if (character === \"$\" && quote === '\"') return true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"'\" || character === '\"') {\n\t\t\tquote = character;\n\t\t\tcontinue;\n\t\t}\n\t\tif ([\"$\", \"*\", \"?\", \"[\", \"{\"].includes(character)) return true;\n\t}\n\treturn false;\n}\n\nfunction shellWords(segment: string): string[] | undefined {\n\tconst words: string[] = [];\n\tlet word = \"\";\n\tlet quote: \"'\" | '\"' | undefined;\n\tlet escaped = false;\n\tfor (const character of segment) {\n\t\tif (escaped) {\n\t\t\tword += character;\n\t\t\tescaped = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"\\\\\" && quote !== \"'\") {\n\t\t\tescaped = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (quote) {\n\t\t\tif (character === quote) quote = undefined;\n\t\t\telse word += character;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"'\" || character === '\"') quote = character;\n\t\telse if (/\\s/.test(character)) {\n\t\t\tif (word) words.push(word);\n\t\t\tword = \"\";\n\t\t} else word += character;\n\t}\n\tif (quote || escaped) return undefined;\n\tif (word) words.push(word);\n\treturn words;\n}\n\nfunction hasSafeArguments(command: string, args: string[]) {\n\tconst forbidden = new Set([\"-i\", \"--in-place\", \"--fix\", \"--write\", \"-delete\", \"--delete\"]);\n\tif (args.some((argument) => forbidden.has(argument))) return false;\n\tif (\n\t\tcommand === \"sed\" &&\n\t\targs.some(\n\t\t\t(argument) =>\n\t\t\t\targument.startsWith(\"--in-place=\") ||\n\t\t\t\t(/^-[^-]+/.test(argument) && argument.slice(1).includes(\"i\")),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\tif (\n\t\tcommand === \"find\" &&\n\t\targs.some((argument) =>\n\t\t\t[\"-exec\", \"-execdir\", \"-ok\", \"-okdir\", \"-fprint\", \"-fprint0\", \"-fprintf\", \"-fls\"].includes(\n\t\t\t\targument,\n\t\t\t),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\tif (\n\t\tcommand === \"date\" &&\n\t\targs.some((argument) => argument === \"-s\" || argument.startsWith(\"--set\"))\n\t) {\n\t\treturn false;\n\t}\n\tif (\n\t\t(command === \"sort\" || command === \"tree\") &&\n\t\targs.some(\n\t\t\t(argument) =>\n\t\t\t\targument === \"-o\" ||\n\t\t\t\t(argument.startsWith(\"-o\") && !argument.startsWith(\"--\")) ||\n\t\t\t\targument.startsWith(\"--output\"),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\tif (\n\t\tcommand === \"sort\" &&\n\t\targs.some(\n\t\t\t(argument) =>\n\t\t\t\targument === \"-T\" ||\n\t\t\t\t(argument.startsWith(\"-T\") && argument.length > 2) ||\n\t\t\t\targument.startsWith(\"--temporary-directory\") ||\n\t\t\t\targument.startsWith(\"--compress-program\"),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\tif (\n\t\tcommand === \"diff\" &&\n\t\targs.some((argument) => argument === \"--output\" || argument.startsWith(\"--output=\"))\n\t) {\n\t\treturn false;\n\t}\n\tif (command === \"uniq\" && args.filter((argument) => !argument.startsWith(\"-\")).length > 1) {\n\t\treturn false;\n\t}\n\tif (\n\t\tcommand === \"fd\" &&\n\t\targs.some((argument) =>\n\t\t\t[\"-x\", \"-X\", \"--exec\", \"--exec-batch\"].some(\n\t\t\t\t(flag) => argument === flag || argument.startsWith(`${flag}=`),\n\t\t\t),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\tif (\n\t\tcommand === \"rg\" &&\n\t\targs.some((argument) => argument === \"--pre\" || argument.startsWith(\"--pre=\"))\n\t) {\n\t\treturn false;\n\t}\n\tif (\n\t\tcommand === \"bat\" &&\n\t\targs.some((argument) => argument === \"--pager\" || argument.startsWith(\"--pager=\"))\n\t) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\ntype ArgumentValidator = (args: string[]) => boolean;\nconst allowReadOnlyArguments: ArgumentValidator = () => true;\nconst BUILTIN_GIT_VALIDATORS: Record<BuiltinSafeGitSubcommand, ArgumentValidator> = {\n\tstatus: allowReadOnlyArguments,\n\tlog: allowReadOnlyArguments,\n\tdiff: allowReadOnlyArguments,\n\tshow: allowReadOnlyArguments,\n\tbranch: isSafeGitBranchArguments,\n\tremote: isSafeGitRemoteArguments,\n\t\"ls-files\": allowReadOnlyArguments,\n\tgrep: isSafeGitGrepArguments,\n};\nconst CONFIGURABLE_GIT_VALIDATORS: Record<ConfigurableSafeGitSubcommand, ArgumentValidator> = {\n\t\"rev-parse\": allowReadOnlyArguments,\n\tblame: allowReadOnlyArguments,\n\tdescribe: allowReadOnlyArguments,\n\t\"merge-base\": allowReadOnlyArguments,\n\t\"ls-tree\": allowReadOnlyArguments,\n\t\"cat-file\": isSafeGitCatFileArguments,\n};\nconst GH_VALIDATORS: Record<SafeGhSubcommandPath, ArgumentValidator> = {\n\t\"pr view\": isSafeGhReadArguments,\n\t\"pr list\": isSafeGhReadArguments,\n\t\"issue view\": isSafeGhReadArguments,\n\t\"issue list\": isSafeGhReadArguments,\n};\n\nfunction isSafeStructuredCommand(\n\tcommand: string,\n\targs: string[],\n\tsafeSubcommands: SafeSubcommands,\n) {\n\tif (command === \"git\") return isSafeGitCommand(args, safeSubcommands);\n\tif (command === \"gh\") return isSafeGhCommand(args, safeSubcommands);\n\n\tconst subcommandIndex = args.findIndex((argument) => !argument.startsWith(\"-\"));\n\tconst subcommand = args[subcommandIndex]?.toLowerCase();\n\tconst subcommandArgs = subcommandIndex >= 0 ? args.slice(subcommandIndex + 1) : [];\n\tif (command === \"sed\") {\n\t\tconst script = args.find((argument) => !argument.startsWith(\"-\"));\n\t\treturn (\n\t\t\tBoolean(script) &&\n\t\t\t(args.includes(\"-n\") || args.some((argument) => /^-[^-]*n[^-]*$/.test(argument))) &&\n\t\t\t/^\\d+(,\\d+)?p$/.test(script ?? \"\")\n\t\t);\n\t}\n\tif ([\"node\", \"python\", \"python3\", \"tsc\", \"biome\", \"ruff\", \"ty\"].includes(command)) {\n\t\tif (args.includes(\"--version\")) return true;\n\t\treturn (\n\t\t\tcommand === \"tsc\" &&\n\t\t\targs.includes(\"--noEmit\") &&\n\t\t\t!args.some(\n\t\t\t\t(argument) =>\n\t\t\t\t\targument === \"--incremental\" ||\n\t\t\t\t\targument.startsWith(\"--incremental=\") ||\n\t\t\t\t\targument === \"--tsBuildInfoFile\" ||\n\t\t\t\t\targument.startsWith(\"--tsBuildInfoFile=\") ||\n\t\t\t\t\targument === \"--generateTrace\" ||\n\t\t\t\t\targument.startsWith(\"--generateTrace=\"),\n\t\t\t)\n\t\t);\n\t}\n\tif (command === \"npm\") {\n\t\tif (subcommand === \"audit\" && subcommandArgs.includes(\"fix\")) return false;\n\t\tif (\n\t\t\t[\"list\", \"ls\", \"view\", \"info\", \"search\", \"outdated\", \"audit\", \"test\"].includes(\n\t\t\t\tsubcommand ?? \"\",\n\t\t\t)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\treturn subcommand === \"run\" && [\"test\", \"check\", \"typecheck\", \"lint\"].includes(args[1] ?? \"\");\n\t}\n\tif ([\"cargo\", \"go\", \"pytest\", \"vitest\", \"jest\"].includes(command)) {\n\t\treturn (\n\t\t\t[\"test\", \"check\"].includes(subcommand ?? \"\") || [\"pytest\", \"vitest\", \"jest\"].includes(command)\n\t\t);\n\t}\n\treturn false;\n}\n\nfunction isSafeGitCommand(args: string[], safeSubcommands: SafeSubcommands) {\n\tlet subcommandIndex = 0;\n\twhile (args[subcommandIndex] === \"--no-pager\") subcommandIndex += 1;\n\tconst subcommand = args[subcommandIndex]?.toLowerCase();\n\tif (!subcommand || subcommand.startsWith(\"-\")) return false;\n\tconst subcommandArgs = args.slice(subcommandIndex + 1);\n\tconst builtinValidator = (BUILTIN_GIT_VALIDATORS as Record<string, ArgumentValidator>)[\n\t\tsubcommand\n\t];\n\tconst configuredValidator = (CONFIGURABLE_GIT_VALIDATORS as Record<string, ArgumentValidator>)[\n\t\tsubcommand\n\t];\n\tconst configured = safeSubcommands.git?.includes(subcommand as SafeGitSubcommand) === true;\n\tconst validator = builtinValidator ?? (configured ? configuredValidator : undefined);\n\treturn (\n\t\tvalidator !== undefined &&\n\t\thasSafeGitArguments(subcommand, subcommandArgs) &&\n\t\tvalidator(subcommandArgs)\n\t);\n}\n\nfunction hasSafeGitArguments(subcommand: string, args: string[]) {\n\treturn !args.some(\n\t\t(argument) =>\n\t\t\targument === \"--help\" ||\n\t\t\targument === \"--show-signature\" ||\n\t\t\targument.startsWith(\"--show-signature=\") ||\n\t\t\targument.includes(\"%G\") ||\n\t\t\targument === \"--output\" ||\n\t\t\targument.startsWith(\"--output=\") ||\n\t\t\targument === \"--ext-diff\" ||\n\t\t\targument.startsWith(\"--ext-diff=\") ||\n\t\t\targument === \"--textconv\" ||\n\t\t\targument.startsWith(\"--textconv=\") ||\n\t\t\targument === \"--paginate\" ||\n\t\t\targument === \"--open-files-in-pager\" ||\n\t\t\targument.startsWith(\"--open-files-in-pager=\") ||\n\t\t\t(subcommand === \"grep\" && (argument === \"-O\" || argument.startsWith(\"-O\"))),\n\t);\n}\n\nfunction isSafeGitCatFileArguments(args: string[]) {\n\treturn !args.some(\n\t\t(argument) =>\n\t\t\tmatchesLongOptionPrefix(argument, \"--filters\", \"--fi\") ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--textconv\", \"--t\"),\n\t);\n}\n\nfunction isSafeGitGrepArguments(args: string[]) {\n\treturn !args.some(\n\t\t(argument) =>\n\t\t\tmatchesLongOptionPrefix(argument, \"--textconv\", \"--textc\") ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--open-files-in-pager\", \"--op\") ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--ext-grep\", \"--ext\"),\n\t);\n}\n\nfunction matchesLongOptionPrefix(argument: string, option: string, shortest: string) {\n\tconst optionName = argument.split(\"=\", 1)[0] ?? \"\";\n\treturn optionName.length >= shortest.length && option.startsWith(optionName);\n}\n\nfunction isSafeGitBranchArguments(args: string[]) {\n\tif (args.some((argument) => !argument.startsWith(\"-\"))) return false;\n\treturn !args.some(\n\t\t(argument) =>\n\t\t\t/^-[^-]*[dDmMcCu]/.test(argument) ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--delete\", \"--del\") ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--move\", \"--mov\") ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--copy\", \"--cop\") ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--edit-description\", \"--e\") ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--unset-upstream\", \"--u\") ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--set-upstream-to\", \"--set-u\") ||\n\t\t\tmatchesLongOptionPrefix(argument, \"--create-reflog\", \"--creat\"),\n\t);\n}\n\nfunction isSafeGitRemoteArguments(args: string[]) {\n\tconst actionIndex = args.findIndex((argument) => !argument.startsWith(\"-\"));\n\tif (actionIndex < 0) return true;\n\tconst action = args[actionIndex];\n\tif (action === \"get-url\") return true;\n\tif (action !== \"show\") return false;\n\n\tconst showArgs = args.slice(actionIndex + 1);\n\tif (showArgs.includes(\"--\")) return false;\n\tconst remotes = showArgs.filter((argument) => !argument.startsWith(\"-\"));\n\treturn remotes.length === 0 || (remotes.length === 1 && showArgs.includes(\"-n\"));\n}\n\nfunction isSafeGhCommand(args: string[], safeSubcommands: SafeSubcommands) {\n\tconst group = args[0]?.toLowerCase();\n\tconst action = args[1]?.toLowerCase();\n\tif (!group || !action || group.startsWith(\"-\") || action.startsWith(\"-\")) return false;\n\tconst path = `${group} ${action}` as SafeGhSubcommandPath;\n\tif (!safeSubcommands.gh?.includes(path)) return false;\n\tconst validator = (GH_VALIDATORS as Record<string, ArgumentValidator>)[path];\n\treturn validator?.(args.slice(2)) ?? false;\n}\n\nfunction isSafeGhReadArguments(args: string[]) {\n\treturn !args.some(isUnsafeGhReadArgument) && hasGhJsonOutput(args);\n}\n\nfunction isUnsafeGhReadArgument(argument: string) {\n\treturn (\n\t\targument.startsWith(\"-w\") ||\n\t\targument === \"--web\" ||\n\t\targument.startsWith(\"--web=\") ||\n\t\targument === \"--browser\" ||\n\t\targument.startsWith(\"--browser=\") ||\n\t\targument === \"--paginate\" ||\n\t\targument === \"--pager\" ||\n\t\targument.startsWith(\"--pager=\") ||\n\t\targument === \"--output\" ||\n\t\targument.startsWith(\"--output=\")\n\t);\n}\n\nfunction hasGhJsonOutput(args: string[]) {\n\tlet hasJson = false;\n\tfor (let index = 0; index < args.length; index += 1) {\n\t\tconst argument = args[index];\n\t\tif (argument === \"--json\") {\n\t\t\tconst value = args[index + 1];\n\t\t\tif (!value || value.startsWith(\"-\")) return false;\n\t\t\thasJson = true;\n\t\t\tindex += 1;\n\t\t} else if (argument.startsWith(\"--json=\")) {\n\t\t\tif (argument === \"--json=\") return false;\n\t\t\thasJson = true;\n\t\t}\n\t}\n\treturn hasJson;\n}\n", "import { randomUUID } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport { mkdir, open, rename, rm, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { getAgentDir } from \"@earendil-works/pi-coding-agent\";\nimport type { KeyId } from \"@earendil-works/pi-tui\";\nimport {\n\tSAFE_GH_SUBCOMMAND_PATHS,\n\tSAFE_GIT_SUBCOMMANDS,\n\ttype SafeGhSubcommandPath,\n\ttype SafeGitSubcommand,\n\ttype SafeSubcommands,\n} from \"./tool-policy.js\";\n\nexport const PLAN_MODE_SETTINGS_FILE = \"pi-plan-mode.json\";\nconst LEGACY_PLAN_MODE_SETTINGS_FILE = \"plan-mode.json\";\nconst MAX_SETTINGS_BYTES = 64 * 1024;\nexport const PLAN_MODE_THINKING_LEVELS = [\n\t\"inherit\",\n\t\"off\",\n\t\"minimal\",\n\t\"low\",\n\t\"medium\",\n\t\"high\",\n\t\"xhigh\",\n\t\"max\",\n] as const;\nexport const IMPLEMENTATION_PLAN_RETENTIONS = [\n\t\"clear-on-start\",\n\t\"clear-after-first-run\",\n\t\"keep\",\n] as const;\nexport const PLAN_MODE_TOOL_VISIBILITIES = [\"always\", \"after-first-plan\"] as const;\nexport const DEFAULT_PLAN_MODE_TOOL_VISIBILITY = \"after-first-plan\";\nexport const DEFAULT_PLAN_EXPORT_PATH = \"PLAN.md\";\nconst MODIFIERS = new Set([\"ctrl\", \"shift\", \"alt\", \"super\"]);\nconst BASE_KEYS = new Set([\n\t...\"abcdefghijklmnopqrstuvwxyz0123456789\",\n\t\"`\",\n\t\"-\",\n\t\"=\",\n\t\"[\",\n\t\"]\",\n\t\"\\\\\",\n\t\";\",\n\t\"'\",\n\t\",\",\n\t\".\",\n\t\"/\",\n\t\"!\",\n\t\"@\",\n\t\"#\",\n\t\"$\",\n\t\"%\",\n\t\"^\",\n\t\"&\",\n\t\"*\",\n\t\"(\",\n\t\")\",\n\t\"_\",\n\t\"+\",\n\t\"|\",\n\t\"~\",\n\t\"{\",\n\t\"}\",\n\t\":\",\n\t\"<\",\n\t\">\",\n\t\"?\",\n\t\"escape\",\n\t\"esc\",\n\t\"enter\",\n\t\"return\",\n\t\"tab\",\n\t\"space\",\n\t\"backspace\",\n\t\"delete\",\n\t\"insert\",\n\t\"clear\",\n\t\"home\",\n\t\"end\",\n\t\"pageup\",\n\t\"pagedown\",\n\t\"up\",\n\t\"down\",\n\t\"left\",\n\t\"right\",\n\t...Array.from({ length: 12 }, (_unused, index) => `f${index + 1}`),\n]);\nconst MAX_PLAN_EXPORT_PATH_LENGTH = 4096;\n\nexport type PlanModeThinkingLevel = (typeof PLAN_MODE_THINKING_LEVELS)[number];\nexport type ImplementationPlanRetention = (typeof IMPLEMENTATION_PLAN_RETENTIONS)[number];\nexport type PlanModeToolVisibility = (typeof PLAN_MODE_TOOL_VISIBILITIES)[number];\nexport type PlanModeFixedThinkingLevel = Exclude<PlanModeThinkingLevel, \"inherit\">;\nexport interface PlanModeSettings {\n\tthinkingLevel: PlanModeThinkingLevel;\n\ttoolVisibility?: PlanModeToolVisibility;\n\tdefaultPlanTools?: string[];\n\timplementationPlanRetention?: ImplementationPlanRetention;\n\tdefaultPlanExportPath?: string;\n\tsafeSubcommands?: SafeSubcommands;\n\ttoggleShortcut?: KeyId;\n}\nexport interface PlanModeSettingsPatch {\n\tthinkingLevel?: PlanModeThinkingLevel;\n\ttoolVisibility?: PlanModeToolVisibility;\n\tdefaultPlanTools?: readonly string[] | null;\n\timplementationPlanRetention?: ImplementationPlanRetention;\n\tdefaultPlanExportPath?: string | null;\n\ttoggleShortcut?: KeyId | null;\n}\nexport interface UpdatePlanModeSettingsOptions {\n\tsettingsPath?: string;\n\tlegacySettingsPath?: string;\n\tsignal?: AbortSignal;\n\tbeforeRename?: (temporaryPath: string, settingsPath: string) => Promise<void>;\n}\nexport type PlanModeSettingsLoadResult =\n\t| { kind: \"missing\"; notice?: string }\n\t| { kind: \"invalid\"; reason: string; notice?: string }\n\t| { kind: \"loaded\"; settings: PlanModeSettings; notice?: string };\n\ntype SettingsDocument = Record<string, unknown>;\ntype SettingsSnapshot = {\n\tresult: PlanModeSettingsLoadResult;\n\tdocument?: SettingsDocument;\n};\n\nconst mutationQueues = new Map<string, Promise<void>>();\n\nexport function planModeSettingsPath() {\n\treturn join(getAgentDir(), PLAN_MODE_SETTINGS_FILE);\n}\n\nfunction legacyPlanModeSettingsPath() {\n\treturn join(getAgentDir(), LEGACY_PLAN_MODE_SETTINGS_FILE);\n}\n\nexport function normalizePlanModeSettings(value: unknown): PlanModeSettings | undefined {\n\tif (!isSettingsDocument(value)) return undefined;\n\tconst thinkingLevel = Object.hasOwn(value, \"thinkingLevel\")\n\t\t? Reflect.get(value, \"thinkingLevel\")\n\t\t: \"inherit\";\n\tif (!PLAN_MODE_THINKING_LEVELS.includes(thinkingLevel as PlanModeThinkingLevel)) {\n\t\treturn undefined;\n\t}\n\tconst settings: PlanModeSettings = {\n\t\tthinkingLevel: thinkingLevel as PlanModeThinkingLevel,\n\t};\n\tif (Object.hasOwn(value, \"toolVisibility\")) {\n\t\tconst toolVisibility = Reflect.get(value, \"toolVisibility\");\n\t\tif (!PLAN_MODE_TOOL_VISIBILITIES.includes(toolVisibility as PlanModeToolVisibility)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tsettings.toolVisibility = toolVisibility as PlanModeToolVisibility;\n\t}\n\tif (Object.hasOwn(value, \"defaultPlanTools\")) {\n\t\tconst defaultPlanTools = normalizeToolNames(Reflect.get(value, \"defaultPlanTools\"));\n\t\tif (!defaultPlanTools) return undefined;\n\t\tsettings.defaultPlanTools = defaultPlanTools;\n\t}\n\tif (Object.hasOwn(value, \"implementationPlanRetention\")) {\n\t\tconst implementationPlanRetention = Reflect.get(value, \"implementationPlanRetention\");\n\t\tif (\n\t\t\t!IMPLEMENTATION_PLAN_RETENTIONS.includes(\n\t\t\t\timplementationPlanRetention as ImplementationPlanRetention,\n\t\t\t)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tsettings.implementationPlanRetention =\n\t\t\timplementationPlanRetention as ImplementationPlanRetention;\n\t}\n\tif (Object.hasOwn(value, \"defaultPlanExportPath\")) {\n\t\tconst defaultPlanExportPath = normalizePlanExportPath(\n\t\t\tReflect.get(value, \"defaultPlanExportPath\"),\n\t\t);\n\t\tif (!defaultPlanExportPath) return undefined;\n\t\tsettings.defaultPlanExportPath = defaultPlanExportPath;\n\t}\n\tif (Object.hasOwn(value, \"toggleShortcut\")) {\n\t\tconst toggleShortcut = normalizeKeyId(Reflect.get(value, \"toggleShortcut\"));\n\t\tif (!toggleShortcut) return undefined;\n\t\tsettings.toggleShortcut = toggleShortcut;\n\t}\n\tif (Object.hasOwn(value, \"safeSubcommands\")) {\n\t\tconst safeSubcommands = normalizeSafeSubcommands(Reflect.get(value, \"safeSubcommands\"));\n\t\tif (!safeSubcommands) return undefined;\n\t\tsettings.safeSubcommands = safeSubcommands;\n\t}\n\treturn settings;\n}\n\nfunction normalizeToolNames(value: unknown) {\n\tif (\n\t\t!Array.isArray(value) ||\n\t\t!value.every((item): item is string => typeof item === \"string\" && item.trim().length > 0)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn Array.from(new Set(value));\n}\n\nfunction normalizePlanExportPath(value: unknown) {\n\tif (typeof value !== \"string\") return undefined;\n\tconst normalized = value.trim();\n\tif (\n\t\t!normalized ||\n\t\tnormalized.length > MAX_PLAN_EXPORT_PATH_LENGTH ||\n\t\t!/[^@\\s]/u.test(normalized) ||\n\t\t[...normalized].some((character) => {\n\t\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\t\treturn codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);\n\t\t})\n\t) {\n\t\treturn undefined;\n\t}\n\treturn normalized;\n}\n\nexport function normalizeKeyId(value: unknown): KeyId | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst normalized = value.trim().toLowerCase();\n\tconst base = [...BASE_KEYS]\n\t\t.sort((left, right) => right.length - left.length)\n\t\t.find((candidate) => normalized === candidate || normalized.endsWith(`+${candidate}`));\n\tif (!base) return undefined;\n\tconst prefix = normalized.slice(0, normalized.length - base.length);\n\tif (!prefix) return base as KeyId;\n\tif (/^f(?:[1-9]|1[0-2])$/.test(base) || !prefix.endsWith(\"+\")) return undefined;\n\tconst modifiers = prefix.slice(0, -1).split(\"+\");\n\tif (\n\t\tmodifiers.length === 0 ||\n\t\tmodifiers.some((modifier) => !MODIFIERS.has(modifier)) ||\n\t\tnew Set(modifiers).size !== modifiers.length\n\t) {\n\t\treturn undefined;\n\t}\n\treturn normalized as KeyId;\n}\n\nfunction normalizeSafeSubcommands(value: unknown): SafeSubcommands | undefined {\n\tif (!isSettingsDocument(value)) return undefined;\n\tif (Object.keys(value).some((key) => key !== \"git\" && key !== \"gh\")) return undefined;\n\n\tconst safeSubcommands: SafeSubcommands = {};\n\tif (Object.hasOwn(value, \"git\")) {\n\t\tconst git = normalizeKnownValues(Reflect.get(value, \"git\"), SAFE_GIT_SUBCOMMANDS);\n\t\tif (!git) return undefined;\n\t\tsafeSubcommands.git = git as SafeGitSubcommand[];\n\t}\n\tif (Object.hasOwn(value, \"gh\")) {\n\t\tconst gh = normalizeKnownValues(Reflect.get(value, \"gh\"), SAFE_GH_SUBCOMMAND_PATHS);\n\t\tif (!gh) return undefined;\n\t\tsafeSubcommands.gh = gh as SafeGhSubcommandPath[];\n\t}\n\treturn safeSubcommands;\n}\n\nfunction normalizeKnownValues(value: unknown, supported: readonly string[]) {\n\tif (\n\t\t!Array.isArray(value) ||\n\t\t!value.every((item): item is string => typeof item === \"string\" && supported.includes(item))\n\t) {\n\t\treturn undefined;\n\t}\n\treturn Array.from(new Set(value));\n}\n\nexport async function readPlanModeSettings(\n\tsettingsPath?: string,\n): Promise<PlanModeSettingsLoadResult> {\n\tif (settingsPath) {\n\t\tawait awaitPlanModeSettingsWrites(settingsPath);\n\t\treturn (await readSettingsSnapshot(settingsPath)).result;\n\t}\n\tconst canonicalPath = planModeSettingsPath();\n\tawait awaitPlanModeSettingsWrites(canonicalPath);\n\tconst canonical = await readSettingsSnapshot(canonicalPath);\n\tconst legacyPath = legacyPlanModeSettingsPath();\n\tif (canonical.result.kind !== \"missing\") {\n\t\treturn (await pathExists(legacyPath))\n\t\t\t? {\n\t\t\t\t\t...canonical.result,\n\t\t\t\t\tnotice: `${LEGACY_PLAN_MODE_SETTINGS_FILE} ignored because ${PLAN_MODE_SETTINGS_FILE} takes precedence.`,\n\t\t\t\t}\n\t\t\t: canonical.result;\n\t}\n\n\tconst legacy = await readSettingsSnapshot(legacyPath);\n\tconst raced = await readSettingsSnapshot(canonicalPath);\n\tif (raced.result.kind !== \"missing\") return raced.result;\n\treturn legacy.result.kind === \"loaded\"\n\t\t? {\n\t\t\t\t...legacy.result,\n\t\t\t\tnotice: `Using legacy ${LEGACY_PLAN_MODE_SETTINGS_FILE}; rename it to ${PLAN_MODE_SETTINGS_FILE}. The legacy file was not modified.`,\n\t\t\t}\n\t\t: legacy.result;\n}\n\nexport function updatePlanModeSettings(\n\tpatch: PlanModeSettingsPatch,\n\toptions: UpdatePlanModeSettingsOptions = {},\n): Promise<PlanModeSettings> {\n\tconst settingsPath = options.settingsPath ?? planModeSettingsPath();\n\tconst legacySettingsPath =\n\t\toptions.legacySettingsPath ?? (options.settingsPath ? undefined : legacyPlanModeSettingsPath());\n\treturn enqueueMutation(settingsPath, async () => {\n\t\toptions.signal?.throwIfAborted();\n\t\tconst current = await readSettingsDocumentForUpdate(settingsPath, legacySettingsPath);\n\t\tconst updated: SettingsDocument = { ...current };\n\t\tif (patch.thinkingLevel !== undefined) updated.thinkingLevel = patch.thinkingLevel;\n\t\tif (patch.toolVisibility !== undefined) updated.toolVisibility = patch.toolVisibility;\n\t\tif (patch.defaultPlanTools === null) delete updated.defaultPlanTools;\n\t\telse if (patch.defaultPlanTools !== undefined) {\n\t\t\tupdated.defaultPlanTools = [...patch.defaultPlanTools];\n\t\t}\n\t\tif (patch.implementationPlanRetention !== undefined) {\n\t\t\tupdated.implementationPlanRetention = patch.implementationPlanRetention;\n\t\t}\n\t\tif (patch.defaultPlanExportPath === null) delete updated.defaultPlanExportPath;\n\t\telse if (patch.defaultPlanExportPath !== undefined) {\n\t\t\tupdated.defaultPlanExportPath = patch.defaultPlanExportPath;\n\t\t}\n\t\tif (patch.toggleShortcut === null) delete updated.toggleShortcut;\n\t\telse if (patch.toggleShortcut !== undefined) {\n\t\t\tupdated.toggleShortcut = patch.toggleShortcut;\n\t\t}\n\t\tconst settings = normalizePlanModeSettings(updated);\n\t\tif (!settings) throw invalidSettingsError(settingsPath, \"invalid settings shape\");\n\t\tawait publishSettings(settingsPath, updated, options.signal, options.beforeRename);\n\t\treturn settings;\n\t});\n}\n\nexport async function awaitPlanModeSettingsWrites(\n\tsettingsPath = planModeSettingsPath(),\n): Promise<void> {\n\tawait mutationQueues.get(settingsPath);\n}\n\nfunction enqueueMutation<T>(settingsPath: string, mutation: () => Promise<T>): Promise<T> {\n\tconst previous = mutationQueues.get(settingsPath) ?? Promise.resolve();\n\tconst result = previous.then(mutation, mutation);\n\tconst settled = result.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\tmutationQueues.set(settingsPath, settled);\n\tvoid settled.finally(() => {\n\t\tif (mutationQueues.get(settingsPath) === settled) mutationQueues.delete(settingsPath);\n\t});\n\treturn result;\n}\n\nasync function readSettingsDocumentForUpdate(\n\tsettingsPath: string,\n\tlegacySettingsPath: string | undefined,\n): Promise<SettingsDocument> {\n\tconst canonical = await readSettingsSnapshot(settingsPath);\n\tif (canonical.result.kind === \"loaded\") return canonical.document ?? {};\n\tif (canonical.result.kind === \"invalid\") {\n\t\tthrow invalidSettingsError(settingsPath, canonical.result.reason);\n\t}\n\tif (!legacySettingsPath) return {};\n\n\tconst legacy = await readSettingsSnapshot(legacySettingsPath);\n\tconst raced = await readSettingsSnapshot(settingsPath);\n\tif (raced.result.kind === \"loaded\") return raced.document ?? {};\n\tif (raced.result.kind === \"invalid\") {\n\t\tthrow invalidSettingsError(settingsPath, raced.result.reason);\n\t}\n\tif (legacy.result.kind === \"invalid\") {\n\t\tthrow invalidSettingsError(legacySettingsPath, legacy.result.reason);\n\t}\n\treturn legacy.document ?? {};\n}\n\nasync function readSettingsSnapshot(settingsPath: string): Promise<SettingsSnapshot> {\n\tlet contents: string;\n\ttry {\n\t\tcontents = await readSettingsContents(settingsPath);\n\t} catch (error: unknown) {\n\t\tif (isNodeError(error) && error.code === \"ENOENT\") return { result: { kind: \"missing\" } };\n\t\treturn { result: { kind: \"invalid\", reason: safeReadError(error) } };\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(contents) as unknown;\n\t} catch {\n\t\treturn { result: { kind: \"invalid\", reason: \"invalid JSON\" } };\n\t}\n\tconst settings = normalizePlanModeSettings(parsed);\n\tif (!settings || !isSettingsDocument(parsed)) {\n\t\treturn { result: { kind: \"invalid\", reason: \"invalid settings shape\" } };\n\t}\n\treturn { document: parsed, result: { kind: \"loaded\", settings } };\n}\n\nasync function readSettingsContents(settingsPath: string): Promise<string> {\n\tconst flags = constants.O_RDONLY | (constants.O_NONBLOCK ?? 0) | (constants.O_NOFOLLOW ?? 0);\n\tconst handle = await open(settingsPath, flags);\n\ttry {\n\t\tconst stats = await handle.stat();\n\t\tif (!stats.isFile()) throw new Error(\"settings path is not a regular file\");\n\t\tif (stats.size > MAX_SETTINGS_BYTES) {\n\t\t\tthrow new Error(`settings file exceeds ${MAX_SETTINGS_BYTES} bytes`);\n\t\t}\n\t\tconst buffer = Buffer.alloc(MAX_SETTINGS_BYTES + 1);\n\t\tlet offset = 0;\n\t\twhile (offset < buffer.byteLength) {\n\t\t\tconst { bytesRead } = await handle.read(buffer, offset, buffer.byteLength - offset, offset);\n\t\t\tif (bytesRead === 0) break;\n\t\t\toffset += bytesRead;\n\t\t}\n\t\tif (offset > MAX_SETTINGS_BYTES) {\n\t\t\tthrow new Error(`settings file exceeds ${MAX_SETTINGS_BYTES} bytes`);\n\t\t}\n\t\ttry {\n\t\t\treturn new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(\n\t\t\t\tbuffer.subarray(0, offset),\n\t\t\t);\n\t\t} catch {\n\t\t\tthrow new Error(\"settings file is not valid UTF-8\");\n\t\t}\n\t} finally {\n\t\tawait handle.close();\n\t}\n}\n\nasync function publishSettings(\n\tsettingsPath: string,\n\tdocument: SettingsDocument,\n\tsignal?: AbortSignal,\n\tbeforeRename?: (temporaryPath: string, settingsPath: string) => Promise<void>,\n): Promise<void> {\n\tsignal?.throwIfAborted();\n\tconst contents = `${JSON.stringify(document, null, 2)}\\n`;\n\tif (Buffer.byteLength(contents, \"utf8\") > MAX_SETTINGS_BYTES) {\n\t\tthrow new Error(`settings document exceeds ${MAX_SETTINGS_BYTES} bytes`);\n\t}\n\tconst directory = dirname(settingsPath);\n\tawait mkdir(directory, { recursive: true });\n\tsignal?.throwIfAborted();\n\tconst temporaryPath = join(\n\t\tdirectory,\n\t\t`.${basename(settingsPath)}.${process.pid}.${randomUUID()}.tmp`,\n\t);\n\ttry {\n\t\tawait writeFile(temporaryPath, contents, {\n\t\t\tencoding: \"utf8\",\n\t\t\tflag: \"wx\",\n\t\t\tmode: 0o600,\n\t\t\tsignal,\n\t\t});\n\t\tawait beforeRename?.(temporaryPath, settingsPath);\n\t\tsignal?.throwIfAborted();\n\t\tawait rename(temporaryPath, settingsPath);\n\t} finally {\n\t\tawait rm(temporaryPath, { force: true }).catch(() => undefined);\n\t}\n}\n\nfunction isSettingsDocument(value: unknown): value is SettingsDocument {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nasync function pathExists(path: string) {\n\ttry {\n\t\tconst handle = await open(path, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));\n\t\tawait handle.close();\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn !(isNodeError(error) && error.code === \"ENOENT\");\n\t}\n}\n\nfunction invalidSettingsError(settingsPath: string, reason: string) {\n\treturn new Error(`pi-plan-mode settings at ${settingsPath} are invalid: ${reason}`);\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n\treturn error instanceof Error && \"code\" in error;\n}\n\nfunction safeReadError(error: unknown) {\n\tif (isNodeError(error) && error.code === \"ELOOP\") return \"settings path is not a regular file\";\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nexport function configuredThinkingLevel(\n\tsettings: PlanModeSettings,\n): PlanModeFixedThinkingLevel | undefined {\n\treturn settings.thinkingLevel === \"inherit\" ? undefined : settings.thinkingLevel;\n}\n\nexport function configuredPlanModeToolVisibility(\n\tsettings: PlanModeSettings,\n): PlanModeToolVisibility {\n\treturn settings.toolVisibility ?? DEFAULT_PLAN_MODE_TOOL_VISIBILITY;\n}\n\nexport function configuredImplementationPlanRetention(\n\tsettings: PlanModeSettings,\n): ImplementationPlanRetention {\n\treturn settings.implementationPlanRetention ?? \"clear-on-start\";\n}\n\nexport function configuredPlanExportPath(settings: PlanModeSettings) {\n\treturn settings.defaultPlanExportPath ?? DEFAULT_PLAN_EXPORT_PATH;\n}\n\nexport function configuredPlanModeToggleShortcut(settings: PlanModeSettings): KeyId | undefined {\n\treturn settings.toggleShortcut;\n}\n", "import { mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, resolve } from \"node:path\";\nimport { stripVTControlCharacters } from \"node:util\";\nimport { type ExtensionContext, withFileMutationQueue } from \"@earendil-works/pi-coding-agent\";\nimport { DEFAULT_PLAN_EXPORT_PATH } from \"./settings.js\";\nimport type { PlanModeState } from \"./state.js\";\n\nexport { DEFAULT_PLAN_EXPORT_PATH };\n\nexport interface PlanExportResult {\n\tpath: string;\n}\n\nexport interface PlanExportDestination {\n\tconfiguredPath: string;\n\tresolvedPath: string;\n}\n\nexport interface PlanExportLifecycle {\n\tsignal: AbortSignal;\n\tisCurrent(): boolean;\n\tgetState?(): PlanModeState;\n\tfinishReady?(): void;\n}\n\nexport async function exportStoredPlan(\n\tstate: PlanModeState,\n\trequestedPath: string | undefined,\n\tctx: ExtensionContext,\n\tlifecycle?: PlanExportLifecycle,\n\tdefaultPath = DEFAULT_PLAN_EXPORT_PATH,\n) {\n\tconst plan =\n\t\t(state.enabled ? state.latestPlan : undefined)?.trim() ??\n\t\tstate.savedPlan?.plan.trim() ??\n\t\tstate.activeImplementation?.plan.trim();\n\tif (!plan) {\n\t\tconst error = new Error(\n\t\t\t\"No completed plan is available to export. Use /plan finalize when planning is complete.\",\n\t\t);\n\t\tif (!ctx.hasUI) throw error;\n\t\tctx.ui.notify(error.message, \"warning\");\n\t\treturn false;\n\t}\n\n\tconst isCurrent = () =>\n\t\t!lifecycle ||\n\t\t(lifecycle.isCurrent() && (!lifecycle.getState || lifecycle.getState() === state));\n\tlet result: PlanExportResult;\n\ttry {\n\t\tresult = await exportPlanToFile(\n\t\t\tplan,\n\t\t\trequestedPath,\n\t\t\tctx.cwd,\n\t\t\tlifecycle?.signal,\n\t\t\tisCurrent,\n\t\t\tdefaultPath,\n\t\t);\n\t} catch (error: unknown) {\n\t\tif (lifecycle?.signal.aborted || !isCurrent()) return false;\n\t\tif (!ctx.hasUI) throw error;\n\t\tconst detail = error instanceof Error ? error.message : String(error);\n\t\tctx.ui.notify(safeNotification(`Unable to export plan: ${detail}`), \"error\");\n\t\treturn false;\n\t}\n\n\tif (!isCurrent()) return false;\n\tconst finishedReady =\n\t\tstate.enabled && Boolean(state.latestPlan?.trim()) && lifecycle?.finishReady !== undefined;\n\tif (finishedReady) lifecycle.finishReady?.();\n\tconst detail = finishedReady ? \" Plan mode disabled.\" : \"\";\n\tctx.ui.notify(safeNotification(`Plan exported to ${result.path}.${detail}`), \"info\");\n\treturn true;\n}\n\nexport async function exportPlanToFile(\n\tplan: string,\n\trequestedPath: string | undefined,\n\tcwd: string,\n\tsignal?: AbortSignal,\n\tisCurrent: () => boolean = () => true,\n\tdefaultPath = DEFAULT_PLAN_EXPORT_PATH,\n): Promise<PlanExportResult> {\n\tconst path = resolvePlanExportPath(requestedPath, cwd, defaultPath);\n\tawait withFileMutationQueue(path, async () => {\n\t\tthrowIfCancelled(signal, isCurrent);\n\t\tawait mkdir(dirname(path), { recursive: true });\n\t\tthrowIfCancelled(signal, isCurrent);\n\t\ttry {\n\t\t\tawait writeFile(path, `${plan}\\n`, { encoding: \"utf8\", flag: \"wx\" });\n\t\t} catch (error: unknown) {\n\t\t\tif (isNodeError(error) && error.code === \"EEXIST\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Plan export target already exists: ${path}. Choose another path or remove it first.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t});\n\treturn { path };\n}\n\nexport function planExportDestination(defaultPath: string, cwd: string): PlanExportDestination {\n\treturn {\n\t\tconfiguredPath: safeNotification(defaultPath),\n\t\tresolvedPath: safeNotification(resolvePlanExportPath(undefined, cwd, defaultPath)),\n\t};\n}\n\nexport function resolvePlanExportPath(\n\trequestedPath: string | undefined,\n\tcwd: string,\n\tdefaultPath = DEFAULT_PLAN_EXPORT_PATH,\n) {\n\tconst rawPath = requestedPath?.trim() || defaultPath;\n\tconst normalizedPath = rawPath.startsWith(\"@\") ? rawPath.slice(1) : rawPath;\n\tif (!normalizedPath.trim()) throw new Error(\"Plan export path must not be empty.\");\n\tif (normalizedPath.includes(\"\\0\")) {\n\t\tthrow new Error(\"Plan export path must not contain NUL bytes.\");\n\t}\n\treturn resolve(cwd, normalizedPath);\n}\n\nfunction safeNotification(value: string) {\n\tlet sanitized = \"\";\n\tfor (const character of stripVTControlCharacters(value)) {\n\t\tconst codePoint = character.codePointAt(0);\n\t\tsanitized +=\n\t\t\tcodePoint !== undefined && codePoint > 0x1f && !(codePoint >= 0x7f && codePoint <= 0x9f)\n\t\t\t\t? character\n\t\t\t\t: \" \";\n\t}\n\treturn sanitized;\n}\n\nfunction throwIfCancelled(signal: AbortSignal | undefined, isCurrent: () => boolean) {\n\tif (!signal?.aborted && isCurrent()) return;\n\tthrow signal?.reason instanceof Error\n\t\t? signal.reason\n\t\t: new DOMException(\"Plan export cancelled\", \"AbortError\");\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n\treturn error instanceof Error && \"code\" in error;\n}\n", "import type { ToolInfo } from \"@earendil-works/pi-coding-agent\";\nimport {\n\tcanSelectToolInPlanMode,\n\tclassifyPlanModeTool,\n\tisBuiltinTool,\n\tSAFE_BUILTIN_PLAN_TOOLS,\n} from \"./tool-policy.js\";\n\nexport function toolNameFromLegacyKey(key: string, tools: ToolInfo[]) {\n\tconst directName = tools.find((tool) => tool.name === key)?.name;\n\tif (directName) return directName;\n\tconst [name] = key.split(\"\\u001f\");\n\treturn tools.find((tool) => tool.name === name) ? name : undefined;\n}\n\nexport function compareTools(left: ToolInfo, right: ToolInfo) {\n\tconst leftBuiltin = isBuiltinTool(left);\n\tconst rightBuiltin = isBuiltinTool(right);\n\tif (leftBuiltin !== rightBuiltin) return leftBuiltin ? -1 : 1;\n\treturn left.name.localeCompare(right.name);\n}\n\nexport function toolPolicyLabel(tool: ToolInfo) {\n\tconst policy = classifyPlanModeTool(tool);\n\tif (policy === \"read-only\") return \"built-in read-only\";\n\tif (policy === \"limited\") return \"built-in limited\";\n\tif (policy === \"blocked\") return \"built-in blocked\";\n\treturn `user opt-in: ${toolSourceLabel(tool)}`;\n}\n\nfunction toolSourceLabel(tool: ToolInfo) {\n\tconst sourceInfo = tool.sourceInfo;\n\tconst source = `${sourceInfo.scope}/${sourceInfo.source}`;\n\treturn sourceInfo.path ? `${source} ${sourceInfo.path}` : source;\n}\n\nexport function unique(values: string[]) {\n\treturn Array.from(new Set(values));\n}\n\nexport function filterAvailableSelectedToolNames(names: string[], tools: ToolInfo[]) {\n\tconst availableNames = new Set(tools.filter(canSelectToolInPlanMode).map((tool) => tool.name));\n\treturn unique(names.filter((name) => availableNames.has(name)));\n}\n\nexport function defaultPlanModeToolNames(tools: ToolInfo[], configuredNames: string[] | undefined) {\n\tif (configuredNames !== undefined) {\n\t\treturn filterAvailableSelectedToolNames(configuredNames, tools);\n\t}\n\treturn tools\n\t\t.filter((tool) => isBuiltinTool(tool) && SAFE_BUILTIN_PLAN_TOOLS.has(tool.name))\n\t\t.map((tool) => tool.name);\n}\n\ninterface PlanModeToolSelectionSnapshot {\n\tselectedToolNames?: string[];\n\tselectedToolKeys?: string[];\n\tdefaultPlanTools?: string[];\n}\n\nexport function snapshotPlanModeSelectedNames(\n\ttools: ToolInfo[],\n\tselection: PlanModeToolSelectionSnapshot,\n) {\n\tconst selectedToolNames =\n\t\tselection.selectedToolNames ??\n\t\tselection.selectedToolKeys\n\t\t\t?.map((key) => toolNameFromLegacyKey(key, tools))\n\t\t\t.filter((name): name is string => name !== undefined);\n\treturn new Set(\n\t\tselectedToolNames === undefined\n\t\t\t? defaultPlanModeToolNames(tools, selection.defaultPlanTools)\n\t\t\t: filterAvailableSelectedToolNames(selectedToolNames, tools),\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAAA,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AAElB,IAAM,+BAA+B;AACrC,IAAM,6BAA6B;AACnC,IAAM,sBAAsB;AAQ5B,IAAM,4BAA4B;AAAA,EACxC,MAAM;AAAA,EACN,sBAAsB;AAAA,EACtB,UAAU,CAAC,MAAM;AAAA,EACjB,YAAY;AAAA,IACX,MAAM;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,MACX,aAAa;AAAA,IACd;AAAA,EACD;AACD;AAIO,SAAS,4BAA4B,OAAmD;AAC9F,MAAI,CAAC,SAAS,KAAK,KAAK,OAAO,MAAM,SAAS,UAAU;AACvD,WAAO,EAAE,IAAI,OAAO,OAAO,wBAAwB;AAAA,EACpD;AACA,QAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,MAAI,CAAC,KAAM,QAAO,EAAE,IAAI,OAAO,OAAO,yBAAyB;AAC/D,MAAI,KAAK,SAAS,qBAAqB;AACtC,WAAO;AAAA,MACN,IAAI;AAAA,MACJ,OAAO,wBAAwB,mBAAmB;AAAA,IACnD;AAAA,EACD;AACA,SAAO,EAAE,IAAI,MAAM,KAAK;AACzB;AAEO,SAAS,0BAA0B,OAAgB;AACzD,MAAI,CAAC,SAAS,KAAK,EAAG,QAAO;AAC7B,MACC,MAAM,YAAY,8BAClB,MAAM,WAAW,8BAChB;AACD,WAAO;AAAA,EACR;AACA,QAAM,aAAa,4BAA4B,EAAE,MAAM,MAAM,K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AAClC;AAEO,SAAS,iCAAiC,OAAiB,OAAmB;AACpF,QAAM,iBAAiB,IAAI,IAAI,MAAM,OAAO,uBAAuB,EAAE,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC;AAC7F,SAAO,OAAO,MAAM,OAAO,CAAC,SAAS,eAAe,IAAI,IAAI,CAAC,CAAC;AAC/D;AAEO,SAAS,yBAAyB,OAAmB,iBAAuC;AAClG,MAAI,oBAAoB,QAAW;AAClC,WAAO,iCAAiC,iBAAiB,KAAK;AAAA,EAC/D;AACA,SAAO,MACL,OAAO,CAAC,SAAS,cAAc,IAAI,KAAK,wBAAwB,IAAI,KAAK,IAAI,CAAC,EAC9E,IAAI,CAAC,SAAS,KAAK,IAAI;AAC1B;AAQO,SAAS,8BACf,OACA,WACC;AACD,QAAM,oBACL,UAAU,qBACV,UAAU,kBACP,IAAI,CAAC,QAAQ,sBAAsB,KAAK,KAAK,CAAC,EAC/C,OAAO,CAAC,SAAyB,SAAS,MAAS;AACtD,SAAO,IAAI;AAAA,IACV,sBAAsB,SACnB,yBAAyB,OAAO,UAAU,gBAAgB,IAC1D,iCAAiC,mBAAmB,KAAK;AAAA,EAC7D;AACD;",
|
|
6
|
+
"names": ["isRecord", "mkdir", "writeFile", "dirname", "detail", "mkdir", "dirname", "writeFile", "isNodeError"]
|
|
7
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
-
// @ts-nocheck -- generated
|
|
2
|
+
// @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
import {
|
|
4
4
|
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
5
5
|
PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
retentionLabel,
|
|
20
20
|
toolPolicyLabel,
|
|
21
21
|
updatePlanModeSettings
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-U5CQ7RQX.js";
|
|
23
23
|
|
|
24
24
|
// src/active-implementation-menu.ts
|
|
25
25
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
@@ -748,4 +748,4 @@ export {
|
|
|
748
748
|
showReadyPlanMenu,
|
|
749
749
|
showSavedPlanMenu
|
|
750
750
|
};
|
|
751
|
-
//# sourceMappingURL=interactive-ui-
|
|
751
|
+
//# sourceMappingURL=interactive-ui-W3VYAJIQ.js.map
|