@narumitw/pi-plan-mode 0.1.35 → 0.1.36

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 CHANGED
@@ -13,7 +13,8 @@ Pi core intentionally does not ship a built-in plan mode; this package provides
13
13
  - Enables built-in read-only tools by default while Plan mode is active.
14
14
  - Disables extension and custom tools by default, with a `/plan tools` selector for explicit user-risk opt-in.
15
15
  - Blocks mutating built-in tools and bash commands such as `rm`, `git commit`, dependency installs, redirects, and editor launches.
16
- - Injects Codex-like Plan mode instructions: explore first, ask only non-discoverable questions, do not mutate files, and finish with `<proposed_plan>`.
16
+ - Injects Codex-like Plan mode instructions: explore first, ask decision questions for high-impact ambiguity, do not mutate files, and finish with `<proposed_plan>` only when decision-complete.
17
+ - Adds a required `plan_mode_question` tool so the agent can ask structured Plan-mode questions before finalizing a plan.
17
18
  - Detects proposed plan blocks and prompts you to implement, stay in Plan mode, or exit and discard the plan.
18
19
  - Shows Plan mode state in Pi's statusline as `📝 plan active` or `📝 plan ready`.
19
20
  - Persists Plan mode state in the Pi session so resume restores the mode.
@@ -46,13 +47,15 @@ pi -e ./extensions/pi-plan-mode
46
47
 
47
48
  Use `/plan` to enter Plan mode before writing your planning prompt. Use `/plan <prompt>` to enter Plan mode and immediately submit `<prompt>` as the first Plan-mode user message. Use `/plan tools` to choose which tools are active while Plan mode is enabled; the selector is paginated at 10 tools per page.
48
49
 
49
- When Plan mode is active, ask the agent to design the change. The agent may inspect files and run read-only commands, but it should not edit files or execute the implementation.
50
+ When Plan mode is active, ask the agent to design the change. The agent may inspect files and run read-only commands, but it should not edit files or execute the implementation. It should explore first, then use structured questions when your preference or a tradeoff materially changes the plan.
50
51
 
51
- By default, Plan mode manages only Pi's built-in tools: `read`, limited `bash`, and available read-only built-ins such as `grep`, `find`, and `ls`. Built-in `edit` and `write` are blocked. Extension and custom tools are disabled by default because Pi tools do not expose standardized mutability metadata; enable them from `/plan tools` only when you accept the risk for that session. For example, you can opt into `firecrawl_scrape`, `firecrawl_search`, or `biome_lsp_diagnostics` if those extensions are loaded and you want to use them during planning.
52
+ By default, Plan mode manages only Pi's built-in tools: `read`, limited `bash`, available read-only built-ins such as `grep`, `find`, and `ls`, plus the required `plan_mode_question` tool. Built-in `edit` and `write` are blocked. Extension and custom tools are disabled by default because Pi tools do not expose standardized mutability metadata; enable them from `/plan tools` only when you accept the risk for that session. For example, you can opt into `firecrawl_scrape`, `firecrawl_search`, or `biome_lsp_diagnostics` if those extensions are loaded and you want to use them during planning.
53
+
54
+ `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. If you cancel or no interactive UI is available, the agent should ask a concise plain-text question or proceed only with a clearly stated low-risk assumption instead of prematurely producing a final plan.
52
55
 
53
56
  Pi activates tools by tool name. The `/plan tools` selector stores selections by name and shows each currently effective tool's source from Pi metadata, such as `built-in`, a user extension path, or a project extension path. If an extension overrides a built-in tool with the same name, Pi exposes the effective tool for that name and the selector shows that source.
54
57
 
55
- A complete Plan mode answer should include exactly one block like this:
58
+ A complete Plan mode answer should appear only after the agent has resolved discoverable facts and any high-impact user decisions. It should include exactly one block like this:
56
59
 
57
60
  ```xml
58
61
  <proposed_plan>
@@ -91,6 +94,7 @@ This extension maps Codex's `ModeKind::Plan` behavior onto Pi's extension API:
91
94
 
92
95
  - Plan mode is a conversational collaboration mode, not TODO/progress tracking.
93
96
  - `/plan <prompt>` follows Codex behavior by switching to Plan mode before submitting the inline prompt.
97
+ - The agent should use `plan_mode_question` for important non-discoverable preferences or tradeoffs before finalizing.
94
98
  - `update_plan`-style checklist use is discouraged while Plan mode is active.
95
99
  - The implementation boundary is explicit: Plan mode restores tools before starting implementation, choosing implementation immediately triggers a normal agent turn with full tool access, and plain exit/off discards the proposed plan.
96
100
  - Pi extension safety is approximated with built-in tool restriction plus bash filtering; non-built-in tools are user-selected at user risk because Plan mode does not classify extension/custom tool behavior.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-plan-mode",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "description": "Pi extension that adds a Codex-like read-only /plan collaboration mode.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/plan-mode.ts CHANGED
@@ -5,6 +5,7 @@ const STATUS_KEY = "plan-mode";
5
5
  const PLAN_WIDGET_KEY = "plan-mode-plan";
6
6
  const PLAN_CONTEXT_MESSAGE_TYPE = "plan-mode-context";
7
7
  const PROPOSED_PLAN_MESSAGE_TYPE = "proposed-plan";
8
+ const PLAN_MODE_QUESTION_TOOL_NAME = "plan_mode_question";
8
9
  const PLAN_CONTEXT_MARKER = "[CODEX-LIKE PLAN MODE ACTIVE]";
9
10
  const SAFE_BUILTIN_PLAN_TOOLS = new Set(["read", "bash", "grep", "find", "ls"]);
10
11
  const BLOCKED_BUILTIN_TOOLS = new Set(["edit", "write"]);
@@ -38,6 +39,95 @@ type TextBlock = {
38
39
  text?: string;
39
40
  };
40
41
 
42
+ type PlanModeQuestionOption = {
43
+ label: string;
44
+ description?: string;
45
+ };
46
+
47
+ type PlanModeQuestion = {
48
+ id: string;
49
+ header: string;
50
+ question: string;
51
+ options: PlanModeQuestionOption[];
52
+ };
53
+
54
+ type PlanModeQuestionParams = {
55
+ questions: PlanModeQuestion[];
56
+ };
57
+
58
+ type PlanModeQuestionAnswer = {
59
+ id: string;
60
+ header: string;
61
+ question: string;
62
+ answer: string;
63
+ wasCustom: boolean;
64
+ optionIndex?: number;
65
+ };
66
+
67
+ type PlanModeQuestionReason = "cancelled" | "ui_unavailable" | "plan_mode_inactive" | "invalid_input";
68
+
69
+ type PlanModeQuestionDetails = {
70
+ cancelled: boolean;
71
+ reason?: PlanModeQuestionReason;
72
+ questions: PlanModeQuestion[];
73
+ answers?: PlanModeQuestionAnswer[];
74
+ };
75
+
76
+ const PLAN_MODE_QUESTION_PARAMS = {
77
+ type: "object",
78
+ additionalProperties: false,
79
+ required: ["questions"],
80
+ properties: {
81
+ questions: {
82
+ type: "array",
83
+ minItems: 1,
84
+ maxItems: 3,
85
+ description: "Questions to show the user. Prefer 1 and do not exceed 3.",
86
+ items: {
87
+ type: "object",
88
+ additionalProperties: false,
89
+ required: ["id", "header", "question", "options"],
90
+ properties: {
91
+ id: {
92
+ type: "string",
93
+ description: "Stable identifier for mapping answers (snake_case).",
94
+ },
95
+ header: {
96
+ type: "string",
97
+ description: "Short header label shown in the UI (12 or fewer chars).",
98
+ },
99
+ question: {
100
+ type: "string",
101
+ description: "Single-sentence prompt shown to the user.",
102
+ },
103
+ options: {
104
+ type: "array",
105
+ minItems: 2,
106
+ maxItems: 4,
107
+ description:
108
+ "Provide 2-4 mutually exclusive choices. Put the recommended option first when there is a clear default.",
109
+ items: {
110
+ type: "object",
111
+ additionalProperties: false,
112
+ required: ["label", "description"],
113
+ properties: {
114
+ label: {
115
+ type: "string",
116
+ description: "User-facing label (1-5 words).",
117
+ },
118
+ description: {
119
+ type: "string",
120
+ description: "One short sentence explaining impact/tradeoff if selected.",
121
+ },
122
+ },
123
+ },
124
+ },
125
+ },
126
+ },
127
+ },
128
+ },
129
+ } as const;
130
+
41
131
  const MUTATING_BASH_PATTERNS = [
42
132
  /\brm\b/i,
43
133
  /\brmdir\b/i,
@@ -91,6 +181,51 @@ export default function planMode(pi: ExtensionAPI) {
91
181
  default: false,
92
182
  });
93
183
 
184
+ pi.registerTool({
185
+ name: PLAN_MODE_QUESTION_TOOL_NAME,
186
+ label: "Plan question",
187
+ description:
188
+ "Ask the user one to three Plan-mode clarification questions with meaningful options, then wait for the answer. Only available while Plan mode is active.",
189
+ promptSnippet: "Ask user decision questions while Plan mode is active",
190
+ promptGuidelines: [
191
+ "In Plan mode, use plan_mode_question for important preferences, tradeoffs, or assumptions that cannot be discovered from read-only exploration.",
192
+ ],
193
+ parameters: PLAN_MODE_QUESTION_PARAMS,
194
+ async execute(_toolCallId, params: unknown, _signal, _onUpdate, ctx) {
195
+ if (!state.enabled) {
196
+ return planModeQuestionCancelled(
197
+ [],
198
+ "plan_mode_inactive",
199
+ "Error: plan_mode_question is only available while Plan mode is active.",
200
+ );
201
+ }
202
+
203
+ const parsed = normalizePlanModeQuestionParams(params);
204
+ if (!parsed.ok) {
205
+ return planModeQuestionCancelled([], "invalid_input", `Error: ${parsed.error}`);
206
+ }
207
+
208
+ if (!ctx.hasUI) {
209
+ return planModeQuestionCancelled(
210
+ parsed.questions,
211
+ "ui_unavailable",
212
+ "Unable to ask Plan-mode questions because interactive UI is not available.",
213
+ );
214
+ }
215
+
216
+ const answers = await askPlanModeQuestions(parsed.questions, ctx);
217
+ if (!answers) {
218
+ return planModeQuestionCancelled(
219
+ parsed.questions,
220
+ "cancelled",
221
+ "User cancelled the Plan-mode question prompt.",
222
+ );
223
+ }
224
+
225
+ return planModeQuestionAnswered(parsed.questions, answers);
226
+ },
227
+ });
228
+
94
229
  pi.registerCommand("plan", {
95
230
  description: "Enter or manage Codex-like Plan mode",
96
231
  handler: async (args, ctx) => {
@@ -123,6 +258,7 @@ export default function planMode(pi: ExtensionAPI) {
123
258
  restoreState(ctx);
124
259
  if (pi.getFlag("plan") === true) state.enabled = true;
125
260
  if (state.enabled) activatePlanModeTools();
261
+ else deactivatePlanModeQuestionTool();
126
262
  updateUi(ctx);
127
263
  });
128
264
 
@@ -151,15 +287,18 @@ export default function planMode(pi: ExtensionAPI) {
151
287
  });
152
288
 
153
289
  pi.on("context", async (event) => {
154
- if (state.enabled) return;
290
+ const messagesWithoutLegacyPlanContext = event.messages.filter(
291
+ (message: unknown) => !messageContainsLegacyPlanModeContextArtifact(message),
292
+ );
293
+ if (state.enabled) return { messages: messagesWithoutLegacyPlanContext };
155
294
  return {
156
- messages: event.messages
295
+ messages: messagesWithoutLegacyPlanContext
157
296
  .filter((message: unknown) => !messageContainsInactivePlanModeArtifact(message))
158
297
  .map(stripProposedPlanBlocksFromMessage),
159
298
  };
160
299
  });
161
300
 
162
- pi.on("before_agent_start", (_event, ctx) => {
301
+ pi.on("before_agent_start", (event, ctx) => {
163
302
  if (!state.enabled) return;
164
303
  if (state.latestPlan || state.awaitingAction) {
165
304
  state = { ...state, latestPlan: undefined, awaitingAction: false };
@@ -168,11 +307,7 @@ export default function planMode(pi: ExtensionAPI) {
168
307
  }
169
308
  applyPlanModeTools();
170
309
  return {
171
- message: {
172
- customType: PLAN_CONTEXT_MESSAGE_TYPE,
173
- content: buildPlanModePrompt(),
174
- display: false,
175
- },
310
+ systemPrompt: `${event.systemPrompt}\n\n${buildPlanModePrompt()}`,
176
311
  };
177
312
  });
178
313
 
@@ -208,7 +343,7 @@ export default function planMode(pi: ExtensionAPI) {
208
343
  });
209
344
 
210
345
  function enterPlanMode(ctx: ExtensionContext) {
211
- if (!state.enabled) previousTools = safeGetActiveTools();
346
+ if (!state.enabled) previousTools = withoutPlanModeQuestionTool(safeGetActiveTools());
212
347
  state = { ...state, enabled: true, awaitingAction: false };
213
348
  activatePlanModeTools();
214
349
  persistState();
@@ -379,7 +514,7 @@ export default function planMode(pi: ExtensionAPI) {
379
514
  }
380
515
 
381
516
  function activatePlanModeTools() {
382
- previousTools ??= safeGetActiveTools();
517
+ previousTools ??= withoutPlanModeQuestionTool(safeGetActiveTools());
383
518
  applyPlanModeTools();
384
519
  }
385
520
 
@@ -389,12 +524,14 @@ export default function planMode(pi: ExtensionAPI) {
389
524
 
390
525
  function planModeToolNames() {
391
526
  const tools = selectableTools();
392
- if (tools.length === 0) return ["read", "bash"];
527
+ if (tools.length === 0) return ["read", "bash", PLAN_MODE_QUESTION_TOOL_NAME];
393
528
 
394
529
  const selectedNames = planModeSelectedNames(tools);
395
- return tools
396
- .filter((tool) => selectedNames.has(tool.name) && canSelectToolInPlanMode(tool))
397
- .map((tool) => tool.name);
530
+ return withRequiredPlanModeTools(
531
+ tools
532
+ .filter((tool) => selectedNames.has(tool.name) && canSelectToolInPlanMode(tool))
533
+ .map((tool) => tool.name),
534
+ );
398
535
  }
399
536
 
400
537
  function planModeSelectedNames(tools: ToolInfo[]) {
@@ -428,7 +565,9 @@ export default function planMode(pi: ExtensionAPI) {
428
565
  }
429
566
 
430
567
  function selectableTools() {
431
- return safeGetAllTools().sort(compareTools);
568
+ return safeGetAllTools()
569
+ .filter((tool) => tool.name !== PLAN_MODE_QUESTION_TOOL_NAME)
570
+ .sort(compareTools);
432
571
  }
433
572
 
434
573
  function toolSelectorPageCount(tools: ToolInfo[]) {
@@ -444,10 +583,19 @@ export default function planMode(pi: ExtensionAPI) {
444
583
  }
445
584
 
446
585
  function restoreTools() {
447
- pi.setActiveTools(previousTools && previousTools.length > 0 ? previousTools : DEFAULT_TOOLS);
586
+ const restoredTools = previousTools && previousTools.length > 0 ? previousTools : DEFAULT_TOOLS;
587
+ pi.setActiveTools(withoutPlanModeQuestionTool(restoredTools));
448
588
  previousTools = undefined;
449
589
  }
450
590
 
591
+ function deactivatePlanModeQuestionTool() {
592
+ const activeTools = safeGetActiveTools();
593
+ const filteredTools = withoutPlanModeQuestionTool(activeTools);
594
+ if (filteredTools.length !== activeTools.length) {
595
+ pi.setActiveTools(filteredTools);
596
+ }
597
+ }
598
+
451
599
  function safeGetActiveTools() {
452
600
  try {
453
601
  return pi.getActiveTools();
@@ -578,19 +726,194 @@ function unique(values: string[]) {
578
726
  return Array.from(new Set(values));
579
727
  }
580
728
 
729
+ function withRequiredPlanModeTools(toolNames: string[]) {
730
+ return unique([...withoutPlanModeQuestionTool(toolNames), PLAN_MODE_QUESTION_TOOL_NAME]);
731
+ }
732
+
733
+ function withoutPlanModeQuestionTool(toolNames: string[]) {
734
+ return toolNames.filter((toolName) => toolName !== PLAN_MODE_QUESTION_TOOL_NAME);
735
+ }
736
+
737
+ type NormalizePlanModeQuestionParamsResult =
738
+ | { ok: true; questions: PlanModeQuestion[] }
739
+ | { ok: false; error: string };
740
+
741
+ function normalizePlanModeQuestionParams(input: unknown): NormalizePlanModeQuestionParamsResult {
742
+ if (!isRecord(input) || !Array.isArray(input.questions)) {
743
+ return { ok: false, error: "questions must be an array" };
744
+ }
745
+ if (input.questions.length < 1 || input.questions.length > 3) {
746
+ return { ok: false, error: "questions must contain 1-3 items" };
747
+ }
748
+
749
+ const questions: PlanModeQuestion[] = [];
750
+ for (const [questionIndex, rawQuestion] of input.questions.entries()) {
751
+ if (!isRecord(rawQuestion)) {
752
+ return { ok: false, error: `question ${questionIndex + 1} must be an object` };
753
+ }
754
+
755
+ const id = stringField(rawQuestion.id);
756
+ const header = stringField(rawQuestion.header);
757
+ const question = stringField(rawQuestion.question);
758
+ if (!id || !header || !question) {
759
+ return {
760
+ ok: false,
761
+ error: `question ${questionIndex + 1} requires non-empty id, header, and question`,
762
+ };
763
+ }
764
+
765
+ if (!Array.isArray(rawQuestion.options)) {
766
+ return { ok: false, error: `question ${questionIndex + 1} options must be an array` };
767
+ }
768
+ if (rawQuestion.options.length < 2 || rawQuestion.options.length > 4) {
769
+ return { ok: false, error: `question ${questionIndex + 1} options must contain 2-4 items` };
770
+ }
771
+
772
+ const options: PlanModeQuestionOption[] = [];
773
+ for (const [optionIndex, rawOption] of rawQuestion.options.entries()) {
774
+ if (!isRecord(rawOption)) {
775
+ return {
776
+ ok: false,
777
+ error: `question ${questionIndex + 1} option ${optionIndex + 1} must be an object`,
778
+ };
779
+ }
780
+
781
+ const label = stringField(rawOption.label);
782
+ if (!label) {
783
+ return {
784
+ ok: false,
785
+ error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a label`,
786
+ };
787
+ }
788
+ const description = stringField(rawOption.description);
789
+ if (!description) {
790
+ return {
791
+ ok: false,
792
+ error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a description`,
793
+ };
794
+ }
795
+ options.push({ label, description });
796
+ }
797
+
798
+ questions.push({ id, header, question, options });
799
+ }
800
+
801
+ return { ok: true, questions };
802
+ }
803
+
804
+ async function askPlanModeQuestions(
805
+ questions: PlanModeQuestion[],
806
+ ctx: ExtensionContext,
807
+ ): Promise<PlanModeQuestionAnswer[] | undefined> {
808
+ const answers: PlanModeQuestionAnswer[] = [];
809
+ for (const question of questions) {
810
+ const choices = question.options.map(formatPlanModeQuestionChoice);
811
+ const otherChoice = `${question.options.length + 1}. Other (free-form)`;
812
+ const choice = await ctx.ui.select(`${question.header}: ${question.question}`, [...choices, otherChoice]);
813
+ if (!choice) return undefined;
814
+
815
+ if (choice === otherChoice) {
816
+ const customAnswer = (await ctx.ui.editor(question.question, ""))?.trim();
817
+ if (!customAnswer) return undefined;
818
+ answers.push({
819
+ id: question.id,
820
+ header: question.header,
821
+ question: question.question,
822
+ answer: customAnswer,
823
+ wasCustom: true,
824
+ });
825
+ continue;
826
+ }
827
+
828
+ const optionIndex = choices.indexOf(choice);
829
+ const option = question.options[optionIndex];
830
+ if (!option) return undefined;
831
+ answers.push({
832
+ id: question.id,
833
+ header: question.header,
834
+ question: question.question,
835
+ answer: option.label,
836
+ wasCustom: false,
837
+ optionIndex: optionIndex + 1,
838
+ });
839
+ }
840
+ return answers;
841
+ }
842
+
843
+ function formatPlanModeQuestionChoice(option: PlanModeQuestionOption, index: number) {
844
+ return `${index + 1}. ${option.label}${option.description ? ` — ${option.description}` : ""}`;
845
+ }
846
+
847
+ function planModeQuestionAnswered(questions: PlanModeQuestion[], answers: PlanModeQuestionAnswer[]) {
848
+ return {
849
+ content: [{ type: "text" as const, text: formatPlanModeQuestionPayload({ cancelled: false, answers }) }],
850
+ details: { cancelled: false, questions, answers } satisfies PlanModeQuestionDetails,
851
+ };
852
+ }
853
+
854
+ function planModeQuestionCancelled(
855
+ questions: PlanModeQuestion[],
856
+ reason: PlanModeQuestionReason,
857
+ message: string,
858
+ ) {
859
+ return {
860
+ content: [{ type: "text" as const, text: formatPlanModeQuestionPayload({ cancelled: true, reason, message }) }],
861
+ details: { cancelled: true, reason, questions } satisfies PlanModeQuestionDetails,
862
+ };
863
+ }
864
+
865
+ function formatPlanModeQuestionPayload(payload: {
866
+ cancelled: boolean;
867
+ reason?: PlanModeQuestionReason;
868
+ message?: string;
869
+ answers?: PlanModeQuestionAnswer[];
870
+ }) {
871
+ return JSON.stringify(payload, null, 2);
872
+ }
873
+
874
+ function isRecord(value: unknown): value is Record<string, unknown> {
875
+ return typeof value === "object" && value !== null;
876
+ }
877
+
878
+ function stringField(value: unknown) {
879
+ return typeof value === "string" ? value.trim() : undefined;
880
+ }
881
+
581
882
  function buildPlanModePrompt() {
582
883
  return `${PLAN_CONTEXT_MARKER}
583
- You are in Plan Mode, a Codex-like collaboration mode for producing a decision-complete implementation plan.
884
+ # Plan Mode (Conversational)
885
+
886
+ You are in Plan Mode, a Codex-like collaboration mode for producing a decision-complete implementation plan. Chat your way to the plan before finalizing it. A final plan must leave no implementation decisions unresolved.
887
+
888
+ ## Mode rules
584
889
 
585
- Mode rules:
586
890
  - Stay in Plan Mode until a developer or extension explicitly exits it.
587
891
  - Treat requests to implement as requests to plan the implementation; do not edit files or carry out the plan.
588
- - Use non-mutating exploration first: read files, search, inspect configuration, run read-only checks, and resolve discoverable facts before asking the user.
589
- - Ask the user only for preferences or tradeoffs that cannot be discovered from the repository.
590
892
  - Do not use update_plan/TODO tooling in Plan Mode; Plan Mode is conversational planning, not execution progress tracking.
591
893
  - Plan Mode manages built-in tool safety only. Non-built-in tools are disabled by default and may be enabled by the user at their own risk.
592
894
  - Do not perform mutating actions: no edit/write tools, no patching, no formatting that rewrites files, no dependency installation, no commits, no migrations.
593
- - When the plan is decision-complete, output exactly one proposed plan block using:
895
+
896
+ ## Phase 1 — Ground in the environment
897
+
898
+ - Explore first and ask second. Use non-mutating exploration to read files, search, inspect configuration, run read-only checks, and resolve discoverable facts.
899
+ - Before asking the user any question, perform at least one targeted non-mutating exploration pass unless no local environment or repository is available.
900
+ - Do not ask questions that can be answered from repository or system truth. Ask only when multiple plausible choices remain, a needed identifier/context is missing, or the ambiguity is product intent.
901
+
902
+ ## Phase 2 — Intent chat
903
+
904
+ - Keep asking until you can clearly state the goal, success criteria, in/out of scope, constraints, current state, and key preferences/tradeoffs.
905
+ - Bias toward questions over guessing: if a high-impact ambiguity remains, do not produce a proposed plan yet.
906
+
907
+ ## Phase 3 — Implementation chat
908
+
909
+ - Once intent is stable, keep asking until the spec is decision-complete: approach, interfaces, data flow, edge cases/failure modes, testing and acceptance criteria, and any migration or compatibility constraints.
910
+ - Use plan_mode_question for important preferences, tradeoffs, or assumption locks that cannot be discovered by non-mutating exploration. Ask 1-3 concise questions with 2-4 meaningful options. Do not include filler options.
911
+ - If plan_mode_question returns cancelled or ui_unavailable, do not jump straight to a final plan when the missing answer is high impact. Ask one concise plain-text question or proceed only with a clearly stated low-risk assumption.
912
+
913
+ ## Finalization rule
914
+
915
+ Only output the final plan when it is decision-complete and leaves no decisions to the implementer. When presenting the official plan, output exactly one proposed plan block and keep the tags exactly as shown:
916
+
594
917
  <proposed_plan>
595
918
  # Title
596
919
 
@@ -606,7 +929,8 @@ Mode rules:
606
929
  ## Assumptions
607
930
  ...
608
931
  </proposed_plan>
609
- - Keep the proposed plan concise, implementation-ready, and free of open decisions.`;
932
+
933
+ Keep the proposed plan concise, human and agent digestible, and free of open decisions. Do not ask "should I proceed?" in the final output; the Plan-mode ready menu handles implementation, staying in Plan mode, or exit.`;
610
934
  }
611
935
 
612
936
  function readCommand(input: unknown) {
@@ -637,12 +961,14 @@ function latestAssistantText(messages: unknown) {
637
961
  return "";
638
962
  }
639
963
 
964
+ function messageContainsLegacyPlanModeContextArtifact(message: unknown) {
965
+ const candidate = unwrapSessionMessage(message);
966
+ return candidate.customType === PLAN_CONTEXT_MESSAGE_TYPE;
967
+ }
968
+
640
969
  function messageContainsInactivePlanModeArtifact(message: unknown) {
641
970
  const candidate = unwrapSessionMessage(message);
642
- return (
643
- candidate.customType === PLAN_CONTEXT_MESSAGE_TYPE ||
644
- candidate.customType === PROPOSED_PLAN_MESSAGE_TYPE
645
- );
971
+ return candidate.customType === PROPOSED_PLAN_MESSAGE_TYPE;
646
972
  }
647
973
 
648
974
  function stripProposedPlanBlocksFromMessage<T>(message: T): T {