@narumitw/pi-plan-mode 0.58.0 → 0.58.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/chunks/{chunk-QHHHBTDO.js → chunk-L2CXUWCH.ts} +29 -111
  2. package/dist/chunks/chunk-L2CXUWCH.ts.map +7 -0
  3. package/dist/chunks/{interactive-ui-UNJGC2RQ.js → interactive-ui-VHZ5GODE.ts} +13 -41
  4. package/dist/chunks/interactive-ui-VHZ5GODE.ts.map +7 -0
  5. package/dist/index.ts +25 -82
  6. package/dist/index.ts.map +2 -2
  7. package/package.json +50 -51
  8. package/src/active-implementation-menu.ts +57 -60
  9. package/src/command.ts +22 -22
  10. package/src/completion-tool.ts +53 -56
  11. package/src/extension-runtime.ts +5 -5
  12. package/src/finalization-request.ts +40 -44
  13. package/src/fresh-handoff-coordinator.ts +38 -41
  14. package/src/fresh-implementation.ts +293 -310
  15. package/src/implementation-models.ts +25 -30
  16. package/src/implementation-retention.ts +109 -123
  17. package/src/message-transform.ts +218 -252
  18. package/src/mode-contract.ts +46 -49
  19. package/src/plan-action-controller.ts +134 -155
  20. package/src/plan-action-menus.ts +390 -408
  21. package/src/plan-export-controller.ts +23 -28
  22. package/src/plan-export-screen.ts +13 -13
  23. package/src/plan-export.ts +85 -102
  24. package/src/plan-launch-menu.ts +119 -119
  25. package/src/plan-mode.ts +2017 -2098
  26. package/src/presentation.ts +84 -108
  27. package/src/prompt.ts +1 -1
  28. package/src/question-tool.ts +239 -267
  29. package/src/required-tools.ts +15 -19
  30. package/src/saved-plan-menu.ts +82 -84
  31. package/src/saved-plan-preflight.ts +29 -33
  32. package/src/settings-menu.ts +470 -513
  33. package/src/settings.ts +393 -452
  34. package/src/state.ts +167 -198
  35. package/src/tool-policy.ts +634 -699
  36. package/src/tool-selection.ts +39 -44
  37. package/src/workflow-mutex.ts +66 -66
  38. package/dist/chunks/chunk-QHHHBTDO.js.map +0 -7
  39. package/dist/chunks/interactive-ui-UNJGC2RQ.js.map +0 -7
@@ -6,136 +6,112 @@ const STATUS_KEY = "plan-mode";
6
6
  const PLAN_WIDGET_KEY = "plan-mode-plan";
7
7
  const BIDI_CONTROLS = /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/gu;
8
8
 
9
- export function updatePlanModeUi(
10
- ctx: ExtensionContext,
11
- state: PlanModeState,
12
- toolSummary: () => string,
13
- ) {
14
- ctx.ui.setStatus(STATUS_KEY, formatStatus(state));
15
- let lines: string[] | undefined;
16
- if (state.enabled && state.latestPlan) {
17
- lines = ["Proposed plan ready", "Use /plan to implement, save, revise, or exit Plan mode."];
18
- } else if (state.enabled) {
19
- lines = [
20
- "Plan mode: planning",
21
- toolSummary(),
22
- "Finish with plan_mode_complete when decision-ready.",
23
- ];
24
- } else if (state.savedPlan) {
25
- lines = ["Plan saved for later", "Use /plan to show, implement, or clear it."];
26
- } else if (state.activeImplementation) {
27
- lines = ["Implementation plan active", "Use /plan to show, replace, or clear it."];
28
- }
9
+ export function updatePlanModeUi(ctx: ExtensionContext, state: PlanModeState, toolSummary: () => string) {
10
+ ctx.ui.setStatus(STATUS_KEY, formatStatus(state));
11
+ let lines: string[] | undefined;
12
+ if (state.enabled && state.latestPlan) {
13
+ lines = ["Proposed plan ready", "Use /plan to implement, save, revise, or exit Plan mode."];
14
+ } else if (state.enabled) {
15
+ lines = ["Plan mode: planning", toolSummary(), "Finish with plan_mode_complete when decision-ready."];
16
+ } else if (state.savedPlan) {
17
+ lines = ["Plan saved for later", "Use /plan to show, implement, or clear it."];
18
+ } else if (state.activeImplementation) {
19
+ lines = ["Implementation plan active", "Use /plan to show, replace, or clear it."];
20
+ }
29
21
 
30
- publishPlanModeWidget(ctx, lines);
22
+ publishPlanModeWidget(ctx, lines);
31
23
  }
32
24
 
33
- export function renderPlanModeWidget(
34
- lines: readonly string[],
35
- theme: Theme,
36
- width: number,
37
- ): string[] {
38
- const renderWidth = Math.max(0, width);
39
- return [
40
- theme.fg("borderMuted", "─".repeat(renderWidth)),
41
- ...lines.map((line) => truncateToWidth(sanitizePlanModeWidgetLine(line), renderWidth, "")),
42
- ];
25
+ export function renderPlanModeWidget(lines: readonly string[], theme: Theme, width: number): string[] {
26
+ const renderWidth = Math.max(0, width);
27
+ return [
28
+ theme.fg("borderMuted", "─".repeat(renderWidth)),
29
+ ...lines.map((line) => truncateToWidth(sanitizePlanModeWidgetLine(line), renderWidth, "")),
30
+ ];
43
31
  }
44
32
 
45
33
  export function sanitizePlanModeWidgetLine(value: string): string {
46
- let text = "";
47
- for (const character of stripTerminalSequences(value).replace(BIDI_CONTROLS, "")) {
48
- const codePoint = character.codePointAt(0) ?? 0;
49
- const isControl = codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);
50
- text += isControl ? " " : character;
51
- }
52
- return text;
34
+ let text = "";
35
+ for (const character of stripTerminalSequences(value).replace(BIDI_CONTROLS, "")) {
36
+ const codePoint = character.codePointAt(0) ?? 0;
37
+ const isControl = codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);
38
+ text += isControl ? " " : character;
39
+ }
40
+ return text;
53
41
  }
54
42
 
55
43
  export function clearPlanModeUi(ctx: ExtensionContext) {
56
- ctx.ui.setStatus(STATUS_KEY, undefined);
57
- ctx.ui.setWidget(PLAN_WIDGET_KEY, undefined);
44
+ ctx.ui.setStatus(STATUS_KEY, undefined);
45
+ ctx.ui.setWidget(PLAN_WIDGET_KEY, undefined);
58
46
  }
59
47
 
60
48
  export function showStoredPlan(pi: ExtensionAPI, ctx: ExtensionContext, state: PlanModeState) {
61
- const readyPlan = state.enabled ? state.latestPlan?.trim() : undefined;
62
- const savedPlan = state.savedPlan?.plan.trim();
63
- if (savedPlan && (ctx.mode === "print" || ctx.mode === "json")) {
64
- throw new Error("Saved plan display is unavailable in print/JSON mode. Use TUI or RPC.");
65
- }
66
- const activePlan = state.activeImplementation?.plan.trim();
67
- const plan = readyPlan ?? savedPlan ?? activePlan;
68
- if (!plan) {
69
- ctx.ui.notify(
70
- "No completed plan is available. Use /plan finalize when planning is complete.",
71
- "info",
72
- );
73
- return;
74
- }
75
- const title = readyPlan
76
- ? "Proposed Plan"
77
- : savedPlan
78
- ? "Saved Plan"
79
- : "Active Implementation Plan";
80
- showPlanModePlan(pi, ctx, title, plan);
49
+ const readyPlan = state.enabled ? state.latestPlan?.trim() : undefined;
50
+ const savedPlan = state.savedPlan?.plan.trim();
51
+ if (savedPlan && (ctx.mode === "print" || ctx.mode === "json")) {
52
+ throw new Error("Saved plan display is unavailable in print/JSON mode. Use TUI or RPC.");
53
+ }
54
+ const activePlan = state.activeImplementation?.plan.trim();
55
+ const plan = readyPlan ?? savedPlan ?? activePlan;
56
+ if (!plan) {
57
+ ctx.ui.notify("No completed plan is available. Use /plan finalize when planning is complete.", "info");
58
+ return;
59
+ }
60
+ const title = readyPlan ? "Proposed Plan" : savedPlan ? "Saved Plan" : "Active Implementation Plan";
61
+ showPlanModePlan(pi, ctx, title, plan);
81
62
  }
82
63
 
83
- export function showPlanModePlan(
84
- pi: ExtensionAPI,
85
- ctx: ExtensionContext,
86
- title: string,
87
- plan: string,
88
- ) {
89
- try {
90
- pi.sendMessage(
91
- {
92
- customType: "proposed-plan",
93
- content: `**${title}**\n\n${plan}`,
94
- display: true,
95
- },
96
- { triggerTurn: false },
97
- );
98
- } catch (error: unknown) {
99
- const detail = error instanceof Error ? error.message : String(error);
100
- ctx.ui.notify(`Unable to show completed plan: ${detail}`, "error");
101
- }
64
+ export function showPlanModePlan(pi: ExtensionAPI, ctx: ExtensionContext, title: string, plan: string) {
65
+ try {
66
+ pi.sendMessage(
67
+ {
68
+ customType: "proposed-plan",
69
+ content: `**${title}**\n\n${plan}`,
70
+ display: true,
71
+ },
72
+ { triggerTurn: false },
73
+ );
74
+ } catch (error: unknown) {
75
+ const detail = error instanceof Error ? error.message : String(error);
76
+ ctx.ui.notify(`Unable to show completed plan: ${detail}`, "error");
77
+ }
102
78
  }
103
79
 
104
80
  export function planModeStatusText(state: PlanModeState, toolSummary: () => string) {
105
- if (state.enabled) {
106
- if (state.latestPlan) {
107
- return `Plan mode is active and a proposed plan is ready. ${toolSummary()}`;
108
- }
109
- return `Plan mode is active. ${toolSummary()} Explore, ask, and finish with plan_mode_complete when decision-ready.`;
110
- }
111
- if (state.savedPlan) return "A plan is saved for later.";
112
- if (state.activeImplementation) return "An implementation plan is active.";
113
- return "Plan mode is off.";
81
+ if (state.enabled) {
82
+ if (state.latestPlan) {
83
+ return `Plan mode is active and a proposed plan is ready. ${toolSummary()}`;
84
+ }
85
+ return `Plan mode is active. ${toolSummary()} Explore, ask, and finish with plan_mode_complete when decision-ready.`;
86
+ }
87
+ if (state.savedPlan) return "A plan is saved for later.";
88
+ if (state.activeImplementation) return "An implementation plan is active.";
89
+ return "Plan mode is off.";
114
90
  }
115
91
 
116
92
  function publishPlanModeWidget(ctx: ExtensionContext, lines: readonly string[] | undefined) {
117
- if (!lines) {
118
- ctx.ui.setWidget(PLAN_WIDGET_KEY, undefined);
119
- return;
120
- }
121
- if (ctx.mode !== "tui") {
122
- ctx.ui.setWidget(PLAN_WIDGET_KEY, [...lines]);
123
- return;
124
- }
93
+ if (!lines) {
94
+ ctx.ui.setWidget(PLAN_WIDGET_KEY, undefined);
95
+ return;
96
+ }
97
+ if (ctx.mode !== "tui") {
98
+ ctx.ui.setWidget(PLAN_WIDGET_KEY, [...lines]);
99
+ return;
100
+ }
125
101
 
126
- const snapshot = [...lines];
127
- ctx.ui.setWidget(PLAN_WIDGET_KEY, (_tui, theme) => ({
128
- render: (width) => renderPlanModeWidget(snapshot, theme, width),
129
- invalidate: () => {},
130
- }));
102
+ const snapshot = [...lines];
103
+ ctx.ui.setWidget(PLAN_WIDGET_KEY, (_tui, theme) => ({
104
+ render: (width) => renderPlanModeWidget(snapshot, theme, width),
105
+ invalidate: () => {},
106
+ }));
131
107
  }
132
108
 
133
109
  function formatStatus(state: PlanModeState) {
134
- if (state.enabled) {
135
- if (state.awaitingAction || state.latestPlan) return "plan ready";
136
- return "plan active";
137
- }
138
- if (state.savedPlan) return "plan saved";
139
- if (state.activeImplementation) return "plan implementing";
140
- return undefined;
110
+ if (state.enabled) {
111
+ if (state.awaitingAction || state.latestPlan) return "plan ready";
112
+ return "plan active";
113
+ }
114
+ if (state.savedPlan) return "plan saved";
115
+ if (state.activeImplementation) return "plan implementing";
116
+ return undefined;
141
117
  }
package/src/prompt.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  const PLAN_CONTEXT_MARKER = "[CODEX-LIKE PLAN MODE ACTIVE]";
2
2
 
3
3
  export function buildPlanModePrompt() {
4
- return `${PLAN_CONTEXT_MARKER}
4
+ return `${PLAN_CONTEXT_MARKER}
5
5
  # Plan Mode (Conversational)
6
6
 
7
7
  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.