@narumitw/pi-plan-mode 0.58.0 → 0.58.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/chunks/{chunk-QHHHBTDO.js → chunk-HF7ZEYIC.js} +29 -111
  2. package/dist/chunks/chunk-HF7ZEYIC.js.map +7 -0
  3. package/dist/chunks/{interactive-ui-UNJGC2RQ.js → interactive-ui-UK7IGPOE.js} +13 -41
  4. package/dist/chunks/interactive-ui-UK7IGPOE.js.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
@@ -3,91 +3,89 @@ import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
3
3
  import { type PlanExportDestinationProvider, planExportInputScreen } from "./plan-export-screen.js";
4
4
 
5
5
  interface SavedPlanMenuOptions {
6
- statusText: string;
7
- implementationOutcome(): string;
8
- getExportDestination: PlanExportDestinationProvider;
9
- signal: AbortSignal;
10
- isCurrent(): boolean;
11
- show(): void;
12
- implementHere(): void | Promise<void>;
13
- implementFresh(signal: AbortSignal): void | Promise<void>;
14
- exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
15
- settings(signal: AbortSignal): Promise<boolean>;
16
- clear(): void;
6
+ statusText: string;
7
+ implementationOutcome(): string;
8
+ getExportDestination: PlanExportDestinationProvider;
9
+ signal: AbortSignal;
10
+ isCurrent(): boolean;
11
+ show(): void;
12
+ implementHere(): void | Promise<void>;
13
+ implementFresh(signal: AbortSignal): void | Promise<void>;
14
+ exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
15
+ settings(signal: AbortSignal): Promise<boolean>;
16
+ clear(): void;
17
17
  }
18
18
 
19
19
  export async function showSavedPlanMenu(ctx: ExtensionContext, options: SavedPlanMenuOptions) {
20
- if (!ctx.hasUI) {
21
- throw new Error(
22
- `${options.statusText} Use /plan show, /plan implement, /plan export, or /plan exit.`,
23
- );
24
- }
25
- type Screen = "saved" | "export";
26
- type Action = "show" | "implement-here" | "implement-fresh" | "export" | "settings" | "clear";
27
- const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
28
- start: "saved",
29
- screens: {
30
- saved: () => ({
31
- kind: "actions",
32
- title: "Saved plan",
33
- lines: [
34
- options.statusText,
35
- "Implement here keeps this planning conversation.",
36
- "Start fresh transfers only the approved plan to a new session.",
37
- options.implementationOutcome(),
38
- ],
39
- items: [
40
- { id: "show", label: "Show saved plan", action: "show" },
41
- {
42
- id: "implement-here",
43
- label: "Implement here",
44
- description: "Continue in this session with the planning conversation.",
45
- action: "implement-here",
46
- },
47
- {
48
- id: "implement-fresh",
49
- label: "Start fresh and implement",
50
- description: "Open a new linked session; transfer only the approved plan.",
51
- action: "implement-fresh",
52
- busyLabel: "Starting fresh implementation session…",
53
- },
54
- { id: "export", label: "Export plan…", to: "export" },
55
- { id: "settings", label: "Settings", action: "settings" },
56
- { id: "clear", label: "Clear saved plan", action: "clear" },
57
- ],
58
- hint: "close",
59
- }),
60
- export: () => planExportInputScreen(options.getExportDestination),
61
- },
62
- actions: {
63
- show: async () => {
64
- options.show();
65
- return { kind: "close" };
66
- },
67
- "implement-here": async () => {
68
- await options.implementHere();
69
- return { kind: "close" };
70
- },
71
- "implement-fresh": async ({ signal }) => {
72
- await options.implementFresh(signal);
73
- return { kind: "close" };
74
- },
75
- export: async ({ value, signal }) =>
76
- (await options.exportPlan(value ?? "", signal)) ? { kind: "close" } : { kind: "rejected" },
77
- settings: async ({ signal }) => {
78
- const close = await options.settings(signal);
79
- if (signal.aborted || !options.isCurrent()) return { kind: "rejected" };
80
- return close ? { kind: "close" } : { kind: "stay" };
81
- },
82
- clear: async () => {
83
- options.clear();
84
- return { kind: "close" };
85
- },
86
- },
87
- });
88
- await runMenu(ctx, menu, {
89
- getState: () => undefined,
90
- signal: options.signal,
91
- isCurrent: options.isCurrent,
92
- });
20
+ if (!ctx.hasUI) {
21
+ throw new Error(`${options.statusText} Use /plan show, /plan implement, /plan export, or /plan exit.`);
22
+ }
23
+ type Screen = "saved" | "export";
24
+ type Action = "show" | "implement-here" | "implement-fresh" | "export" | "settings" | "clear";
25
+ const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
26
+ start: "saved",
27
+ screens: {
28
+ saved: () => ({
29
+ kind: "actions",
30
+ title: "Saved plan",
31
+ lines: [
32
+ options.statusText,
33
+ "Implement here keeps this planning conversation.",
34
+ "Start fresh transfers only the approved plan to a new session.",
35
+ options.implementationOutcome(),
36
+ ],
37
+ items: [
38
+ { id: "show", label: "Show saved plan", action: "show" },
39
+ {
40
+ id: "implement-here",
41
+ label: "Implement here",
42
+ description: "Continue in this session with the planning conversation.",
43
+ action: "implement-here",
44
+ },
45
+ {
46
+ id: "implement-fresh",
47
+ label: "Start fresh and implement",
48
+ description: "Open a new linked session; transfer only the approved plan.",
49
+ action: "implement-fresh",
50
+ busyLabel: "Starting fresh implementation session…",
51
+ },
52
+ { id: "export", label: "Export plan…", to: "export" },
53
+ { id: "settings", label: "Settings", action: "settings" },
54
+ { id: "clear", label: "Clear saved plan", action: "clear" },
55
+ ],
56
+ hint: "close",
57
+ }),
58
+ export: () => planExportInputScreen(options.getExportDestination),
59
+ },
60
+ actions: {
61
+ show: async () => {
62
+ options.show();
63
+ return { kind: "close" };
64
+ },
65
+ "implement-here": async () => {
66
+ await options.implementHere();
67
+ return { kind: "close" };
68
+ },
69
+ "implement-fresh": async ({ signal }) => {
70
+ await options.implementFresh(signal);
71
+ return { kind: "close" };
72
+ },
73
+ export: async ({ value, signal }) =>
74
+ (await options.exportPlan(value ?? "", signal)) ? { kind: "close" } : { kind: "rejected" },
75
+ settings: async ({ signal }) => {
76
+ const close = await options.settings(signal);
77
+ if (signal.aborted || !options.isCurrent()) return { kind: "rejected" };
78
+ return close ? { kind: "close" } : { kind: "stay" };
79
+ },
80
+ clear: async () => {
81
+ options.clear();
82
+ return { kind: "close" };
83
+ },
84
+ },
85
+ });
86
+ await runMenu(ctx, menu, {
87
+ getState: () => undefined,
88
+ signal: options.signal,
89
+ isCurrent: options.isCurrent,
90
+ });
93
91
  }
@@ -1,39 +1,35 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
 
3
3
  export function savedPlanBlocksNewWorkflow(ctx: ExtensionContext, hasSavedPlan: boolean) {
4
- if (!hasSavedPlan) return false;
5
- const message =
6
- "A plan is saved for later. Implement or clear it before starting another Plan-mode workflow.";
7
- if (!ctx.hasUI) throw new Error(message);
8
- ctx.ui.notify(message, "warning");
9
- return true;
4
+ if (!hasSavedPlan) return false;
5
+ const message = "A plan is saved for later. Implement or clear it before starting another Plan-mode workflow.";
6
+ if (!ctx.hasUI) throw new Error(message);
7
+ ctx.ui.notify(message, "warning");
8
+ return true;
10
9
  }
11
10
 
12
- export async function preflightSavedPlanImplementation(
13
- ctx: ExtensionContext,
14
- isCurrent: () => boolean,
15
- ) {
16
- if (ctx.mode === "print" || ctx.mode === "json") {
17
- throw new Error("Saved plan implementation is unavailable in print/JSON mode. Use TUI or RPC.");
18
- }
19
- const model = ctx.model;
20
- if (!model) {
21
- ctx.ui.notify("Unable to implement saved plan: no model is selected.", "warning");
22
- return false;
23
- }
24
- let auth: Awaited<ReturnType<ExtensionContext["modelRegistry"]["getApiKeyAndHeaders"]>>;
25
- try {
26
- auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
27
- } catch (error: unknown) {
28
- if (!isCurrent()) return false;
29
- const detail = error instanceof Error ? error.message : String(error);
30
- ctx.ui.notify(`Unable to implement saved plan: ${detail}`, "error");
31
- return false;
32
- }
33
- if (!isCurrent()) return false;
34
- if (!auth.ok) {
35
- ctx.ui.notify(`Unable to implement saved plan: ${auth.error}`, "warning");
36
- return false;
37
- }
38
- return true;
11
+ export async function preflightSavedPlanImplementation(ctx: ExtensionContext, isCurrent: () => boolean) {
12
+ if (ctx.mode === "print" || ctx.mode === "json") {
13
+ throw new Error("Saved plan implementation is unavailable in print/JSON mode. Use TUI or RPC.");
14
+ }
15
+ const model = ctx.model;
16
+ if (!model) {
17
+ ctx.ui.notify("Unable to implement saved plan: no model is selected.", "warning");
18
+ return false;
19
+ }
20
+ let auth: Awaited<ReturnType<ExtensionContext["modelRegistry"]["getApiKeyAndHeaders"]>>;
21
+ try {
22
+ auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
23
+ } catch (error: unknown) {
24
+ if (!isCurrent()) return false;
25
+ const detail = error instanceof Error ? error.message : String(error);
26
+ ctx.ui.notify(`Unable to implement saved plan: ${detail}`, "error");
27
+ return false;
28
+ }
29
+ if (!isCurrent()) return false;
30
+ if (!auth.ok) {
31
+ ctx.ui.notify(`Unable to implement saved plan: ${auth.error}`, "warning");
32
+ return false;
33
+ }
34
+ return true;
39
35
  }