@narumitw/pi-plan-mode 0.47.1 → 0.49.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.
@@ -0,0 +1,122 @@
1
+ import {
2
+ injectActiveImplementationContext,
3
+ isEmptyAssistantMessage,
4
+ messageContainsExactPlanModeImplementationHandoff,
5
+ messageContainsInactivePlanModeArtifact,
6
+ messageContainsLegacyPlanModeContextArtifact,
7
+ messageContainsPlanModeImplementationContextArtifact,
8
+ messageContainsPlanModeImplementationHandoff,
9
+ stripPlanModeCompletionCallsFromMessage,
10
+ stripProposedPlanBlocksFromMessage,
11
+ } from "./message-transform.js";
12
+ import type { ImplementationPlanRetention } from "./settings.js";
13
+ import type { ActiveImplementationPlan, PlanModeState } from "./state.js";
14
+
15
+ export function retentionLabel(retention: ImplementationPlanRetention) {
16
+ return {
17
+ keep: "Keep plan active",
18
+ "clear-on-start": "Use plan for handoff only",
19
+ "clear-after-first-run": "Clear after first implementation run",
20
+ }[retention];
21
+ }
22
+
23
+ export function implementationRetentionPreview(retention: ImplementationPlanRetention) {
24
+ return {
25
+ keep: "After Implement: Keep plan active until /plan exit.",
26
+ "clear-on-start":
27
+ "After Implement: Use the plan for the implementation handoff only, then clear it.",
28
+ "clear-after-first-run": "After Implement: Clear after the first implementation run settles.",
29
+ }[retention];
30
+ }
31
+
32
+ export interface ImplementationContextResult {
33
+ messages: unknown[];
34
+ clearActiveImplementationId?: string;
35
+ }
36
+
37
+ export interface ImplementationRetentionCoordinator {
38
+ restore(activeImplementation: ActiveImplementationPlan | undefined): void;
39
+ transformContext(messages: unknown[], state: PlanModeState): ImplementationContextResult;
40
+ implementationSettled(
41
+ activeImplementation: ActiveImplementationPlan | undefined,
42
+ ): string | undefined;
43
+ reset(): void;
44
+ }
45
+
46
+ export function createImplementationRetentionCoordinator(): ImplementationRetentionCoordinator {
47
+ let implementationWithDeliveredContext: string | undefined;
48
+ let restoredImplementationAwaitingContext: string | undefined;
49
+
50
+ return {
51
+ restore(activeImplementation) {
52
+ restoredImplementationAwaitingContext =
53
+ activeImplementation && activeImplementation.retention !== "keep"
54
+ ? activeImplementation.id
55
+ : undefined;
56
+ },
57
+ transformContext(messages, state) {
58
+ const messagesWithoutPlanContext = messages.filter(
59
+ (message) =>
60
+ !messageContainsLegacyPlanModeContextArtifact(message) &&
61
+ !messageContainsPlanModeImplementationContextArtifact(message),
62
+ );
63
+ if (state.enabled) {
64
+ return {
65
+ messages: messagesWithoutPlanContext.filter(
66
+ (message) => !messageContainsPlanModeImplementationHandoff(message),
67
+ ),
68
+ };
69
+ }
70
+
71
+ const activeImplementation = state.activeImplementation;
72
+ const inactiveMessages = activeImplementation
73
+ ? messagesWithoutPlanContext
74
+ : messagesWithoutPlanContext.filter(
75
+ (message) => !messageContainsPlanModeImplementationHandoff(message),
76
+ );
77
+ const filteredMessages = inactiveMessages
78
+ .filter((message) => !messageContainsInactivePlanModeArtifact(message))
79
+ .map(stripProposedPlanBlocksFromMessage)
80
+ .map(stripPlanModeCompletionCallsFromMessage)
81
+ .filter((message) => !isEmptyAssistantMessage(message));
82
+ if (!activeImplementation) return { messages: filteredMessages };
83
+
84
+ const contextualMessages = injectActiveImplementationContext(
85
+ filteredMessages,
86
+ activeImplementation,
87
+ );
88
+ // A busy /plan implement queues its handoff behind an older run. Do not arm cleanup
89
+ // until that exact handoff reaches context; a restored session has no older run to drain.
90
+ const deliveredCurrentHandoff =
91
+ restoredImplementationAwaitingContext === activeImplementation.id ||
92
+ filteredMessages.some((message) =>
93
+ messageContainsExactPlanModeImplementationHandoff(message, activeImplementation.plan),
94
+ );
95
+ if (!deliveredCurrentHandoff) return { messages: contextualMessages };
96
+ restoredImplementationAwaitingContext = undefined;
97
+
98
+ if (activeImplementation.retention === "clear-after-first-run") {
99
+ implementationWithDeliveredContext = activeImplementation.id;
100
+ }
101
+ return {
102
+ messages: contextualMessages,
103
+ clearActiveImplementationId:
104
+ activeImplementation.retention === "clear-on-start" ? activeImplementation.id : undefined,
105
+ };
106
+ },
107
+ implementationSettled(activeImplementation) {
108
+ if (
109
+ activeImplementation?.retention !== "clear-after-first-run" ||
110
+ implementationWithDeliveredContext !== activeImplementation.id
111
+ ) {
112
+ return undefined;
113
+ }
114
+ implementationWithDeliveredContext = undefined;
115
+ return activeImplementation.id;
116
+ },
117
+ reset() {
118
+ implementationWithDeliveredContext = undefined;
119
+ restoredImplementationAwaitingContext = undefined;
120
+ },
121
+ };
122
+ }
@@ -0,0 +1,5 @@
1
+ export { showActiveImplementationMenu } from "./active-implementation-menu.js";
2
+ export { showPlanModeMenu, showReadyPlanMenu } from "./plan-action-menus.js";
3
+ export { showPlanLaunchMenu } from "./plan-launch-menu.js";
4
+ export { showSavedPlanMenu } from "./saved-plan-menu.js";
5
+ export { showPlanModeSettings } from "./settings-menu.js";
@@ -128,7 +128,7 @@ export function messageContainsPlanModeImplementationHandoff(message: unknown) {
128
128
  );
129
129
  }
130
130
 
131
- function messageContainsExactPlanModeImplementationHandoff(message: unknown, plan: string) {
131
+ export function messageContainsExactPlanModeImplementationHandoff(message: unknown, plan: string) {
132
132
  const candidate = unwrapSessionMessage(message);
133
133
  if (candidate.role !== "user") return false;
134
134
  return (
@@ -0,0 +1,103 @@
1
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import type { PlanExportDestination } from "./plan-export.js";
3
+ import type { PlanModeState } from "./state.js";
4
+
5
+ type InteractiveUi = typeof import("./interactive-ui.js");
6
+
7
+ interface MenuLifecycle {
8
+ signal: AbortSignal;
9
+ isCurrent(): boolean;
10
+ }
11
+
12
+ interface PlanActionControllerOptions {
13
+ loadInteractiveUi(): Promise<InteractiveUi>;
14
+ getState(): PlanModeState;
15
+ captureLifecycle(): MenuLifecycle;
16
+ statusText(): string;
17
+ implementationOutcome(): string;
18
+ getExportDestination(ctx: ExtensionContext): PlanExportDestination;
19
+ show(ctx: ExtensionContext): void;
20
+ finalize(ctx: ExtensionContext): void;
21
+ implementHere(ctx: ExtensionContext): void | Promise<void>;
22
+ implementFresh(ctx: ExtensionContext, isCurrent: () => boolean): void | Promise<void>;
23
+ exportPlan(
24
+ ctx: ExtensionContext,
25
+ path: string,
26
+ signal: AbortSignal,
27
+ isCurrent: () => boolean,
28
+ ): Promise<boolean>;
29
+ settings(ctx: ExtensionContext, signal: AbortSignal, isCurrent: () => boolean): Promise<boolean>;
30
+ save(ctx: ExtensionContext): void;
31
+ stay(ctx: ExtensionContext): void;
32
+ exitReady(ctx: ExtensionContext): void;
33
+ clearSaved(ctx: ExtensionContext): void;
34
+ }
35
+
36
+ export function createPlanActionController(options: PlanActionControllerOptions) {
37
+ const freshAction = (ctx: ExtensionContext, lifecycle: MenuLifecycle, signal: AbortSignal) =>
38
+ options.implementFresh(ctx, () => lifecycle.isCurrent() && !signal.aborted);
39
+
40
+ return {
41
+ async showSaved(ctx: ExtensionContext) {
42
+ const lifecycle = options.captureLifecycle();
43
+ if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
44
+ const ui = await options.loadInteractiveUi();
45
+ if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
46
+ await ui.showSavedPlanMenu(ctx, {
47
+ statusText: options.statusText(),
48
+ implementationOutcome: options.implementationOutcome,
49
+ getExportDestination: () => options.getExportDestination(ctx),
50
+ signal: lifecycle.signal,
51
+ isCurrent: lifecycle.isCurrent,
52
+ show: () => options.show(ctx),
53
+ implementHere: () => options.implementHere(ctx),
54
+ implementFresh: (signal) => freshAction(ctx, lifecycle, signal),
55
+ exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
56
+ settings: (signal) => options.settings(ctx, signal, lifecycle.isCurrent),
57
+ clear: () => options.clearSaved(ctx),
58
+ });
59
+ },
60
+ async showCurrent(ctx: ExtensionContext) {
61
+ if (!ctx.hasUI) {
62
+ ctx.ui.notify(options.statusText(), "info");
63
+ return;
64
+ }
65
+ const lifecycle = options.captureLifecycle();
66
+ if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
67
+ const ui = await options.loadInteractiveUi();
68
+ if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
69
+ await ui.showPlanModeMenu(ctx, {
70
+ statusText: options.statusText(),
71
+ hasReadyPlan: options.getState().latestPlan !== undefined,
72
+ implementationOutcome: options.implementationOutcome,
73
+ getExportDestination: () => options.getExportDestination(ctx),
74
+ ...lifecycle,
75
+ show: () => options.show(ctx),
76
+ finalize: () => options.finalize(ctx),
77
+ implementHere: () => options.implementHere(ctx),
78
+ implementFresh: (signal) => freshAction(ctx, lifecycle, signal),
79
+ exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
80
+ save: () => options.save(ctx),
81
+ stay: () => options.stay(ctx),
82
+ exit: () => options.exitReady(ctx),
83
+ });
84
+ },
85
+ async showReady(ctx: ExtensionContext) {
86
+ const lifecycle = options.captureLifecycle();
87
+ if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
88
+ const ui = await options.loadInteractiveUi();
89
+ if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
90
+ await ui.showReadyPlanMenu(ctx, {
91
+ ...lifecycle,
92
+ implementationOutcome: options.implementationOutcome,
93
+ getExportDestination: () => options.getExportDestination(ctx),
94
+ implementHere: () => options.implementHere(ctx),
95
+ implementFresh: (signal) => freshAction(ctx, lifecycle, signal),
96
+ exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
97
+ save: () => options.save(ctx),
98
+ stay: () => undefined,
99
+ exit: () => options.exitReady(ctx),
100
+ });
101
+ },
102
+ };
103
+ }
@@ -1,60 +1,84 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
3
+ import { type PlanExportDestinationProvider, planExportInputScreen } from "./plan-export-screen.js";
3
4
 
4
5
  interface MenuLifecycle {
5
6
  signal: AbortSignal;
6
7
  isCurrent(): boolean;
7
8
  }
8
9
 
10
+ const IMPLEMENTATION_CONTEXT_LINES = [
11
+ "Implement here keeps this planning conversation.",
12
+ "Start fresh transfers only the approved plan to a new session.",
13
+ ] as const;
14
+
9
15
  interface PlanMenuOptions extends MenuLifecycle {
10
16
  statusText: string;
11
17
  hasReadyPlan: boolean;
18
+ implementationOutcome(): string;
19
+ getExportDestination: PlanExportDestinationProvider;
12
20
  show(): void;
13
21
  finalize(): void;
14
- implement(): void | Promise<void>;
22
+ implementHere(): void | Promise<void>;
23
+ implementFresh(signal: AbortSignal): void | Promise<void>;
15
24
  exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
16
25
  save(): void;
17
- tools(): Promise<void>;
18
26
  stay(): void;
19
27
  exit(): void;
20
28
  }
21
29
 
22
30
  export async function showPlanModeMenu(ctx: ExtensionContext, options: PlanMenuOptions) {
23
31
  type Screen = "main" | "export";
24
- type Action = "show" | "finalize" | "implement" | "export" | "save" | "tools" | "stay" | "exit";
32
+ type Action =
33
+ | "show"
34
+ | "finalize"
35
+ | "implement-here"
36
+ | "implement-fresh"
37
+ | "export"
38
+ | "save"
39
+ | "stay"
40
+ | "exit";
25
41
  const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
26
42
  start: "main",
27
43
  screens: {
28
44
  main: () => ({
29
45
  kind: "actions",
30
46
  title: "Plan mode",
31
- lines: [options.statusText],
47
+ lines: [
48
+ options.statusText,
49
+ ...(options.hasReadyPlan
50
+ ? [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()]
51
+ : []),
52
+ ],
32
53
  items: options.hasReadyPlan
33
54
  ? [
34
55
  { id: "show", label: "Show latest proposed plan", action: "show" },
35
- { id: "implement", label: "Implement this plan", action: "implement" },
56
+ {
57
+ id: "implement-here",
58
+ label: "Implement here",
59
+ description: "Continue in this session with the planning conversation.",
60
+ action: "implement-here",
61
+ },
62
+ {
63
+ id: "implement-fresh",
64
+ label: "Start fresh and implement",
65
+ description: "Open a new linked session; transfer only the approved plan.",
66
+ action: "implement-fresh",
67
+ busyLabel: "Starting fresh implementation session…",
68
+ },
36
69
  { id: "export", label: "Export plan…", to: "export" },
37
70
  { id: "save", label: "Save for later", action: "save" },
38
- { id: "tools", label: "Configure Plan-mode tools", action: "tools" },
39
71
  { id: "stay", label: "Stay in Plan mode", action: "stay" },
40
- { id: "exit", label: "Exit Plan mode", action: "exit" },
72
+ { id: "exit", label: "Discard plan and exit", action: "exit" },
41
73
  ]
42
74
  : [
43
75
  { id: "finalize", label: "Request final plan", action: "finalize" },
44
- { id: "tools", label: "Configure Plan-mode tools", action: "tools" },
45
76
  { id: "stay", label: "Stay in Plan mode", action: "stay" },
46
77
  { id: "exit", label: "Exit Plan mode", action: "exit" },
47
78
  ],
48
79
  hint: "close",
49
80
  }),
50
- export: () => ({
51
- kind: "input",
52
- title: "Export plan",
53
- lines: ["Existing paths are never overwritten."],
54
- placeholder: "PLAN.md",
55
- action: "export",
56
- hint: "back",
57
- }),
81
+ export: () => planExportInputScreen(options.getExportDestination),
58
82
  },
59
83
  actions: {
60
84
  show: async () => {
@@ -65,8 +89,12 @@ export async function showPlanModeMenu(ctx: ExtensionContext, options: PlanMenuO
65
89
  options.finalize();
66
90
  return { kind: "close" };
67
91
  },
68
- implement: async () => {
69
- await options.implement();
92
+ "implement-here": async () => {
93
+ await options.implementHere();
94
+ return { kind: "close" };
95
+ },
96
+ "implement-fresh": async ({ signal }) => {
97
+ await options.implementFresh(signal);
70
98
  return { kind: "close" };
71
99
  },
72
100
  export: async ({ value, signal }) =>
@@ -75,10 +103,6 @@ export async function showPlanModeMenu(ctx: ExtensionContext, options: PlanMenuO
75
103
  options.save();
76
104
  return { kind: "close" };
77
105
  },
78
- tools: async () => {
79
- await options.tools();
80
- return { kind: "stay" };
81
- },
82
106
  stay: async () => {
83
107
  options.stay();
84
108
  return { kind: "close" };
@@ -97,7 +121,10 @@ export async function showPlanModeMenu(ctx: ExtensionContext, options: PlanMenuO
97
121
  }
98
122
 
99
123
  interface ReadyPlanMenuOptions extends MenuLifecycle {
100
- implement(): void | Promise<void>;
124
+ implementationOutcome(): string;
125
+ getExportDestination: PlanExportDestinationProvider;
126
+ implementHere(): void | Promise<void>;
127
+ implementFresh(signal: AbortSignal): void | Promise<void>;
101
128
  exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
102
129
  save(): void;
103
130
  stay(): void;
@@ -106,34 +133,44 @@ interface ReadyPlanMenuOptions extends MenuLifecycle {
106
133
 
107
134
  export async function showReadyPlanMenu(ctx: ExtensionContext, options: ReadyPlanMenuOptions) {
108
135
  type Screen = "ready" | "export";
109
- type Action = "implement" | "export" | "save" | "stay" | "exit";
136
+ type Action = "implement-here" | "implement-fresh" | "export" | "save" | "stay" | "exit";
110
137
  const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
111
138
  start: "ready",
112
139
  screens: {
113
140
  ready: () => ({
114
141
  kind: "actions",
115
142
  title: "Proposed plan ready. What next?",
143
+ lines: [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()],
116
144
  items: [
117
- { id: "implement", label: "Implement this plan", action: "implement" },
145
+ {
146
+ id: "implement-here",
147
+ label: "Implement here",
148
+ description: "Continue in this session with the planning conversation.",
149
+ action: "implement-here",
150
+ },
151
+ {
152
+ id: "implement-fresh",
153
+ label: "Start fresh and implement",
154
+ description: "Open a new linked session; transfer only the approved plan.",
155
+ action: "implement-fresh",
156
+ busyLabel: "Starting fresh implementation session…",
157
+ },
118
158
  { id: "export", label: "Export plan…", to: "export" },
119
159
  { id: "save", label: "Save for later", action: "save" },
120
160
  { id: "stay", label: "Stay in Plan mode", action: "stay" },
121
- { id: "exit", label: "Exit Plan mode", action: "exit" },
161
+ { id: "exit", label: "Discard plan and exit", action: "exit" },
122
162
  ],
123
163
  hint: "close",
124
164
  }),
125
- export: () => ({
126
- kind: "input",
127
- title: "Export plan",
128
- lines: ["Existing paths are never overwritten."],
129
- placeholder: "PLAN.md",
130
- action: "export",
131
- hint: "back",
132
- }),
165
+ export: () => planExportInputScreen(options.getExportDestination),
133
166
  },
134
167
  actions: {
135
- implement: async () => {
136
- await options.implement();
168
+ "implement-here": async () => {
169
+ await options.implementHere();
170
+ return { kind: "close" };
171
+ },
172
+ "implement-fresh": async ({ signal }) => {
173
+ await options.implementFresh(signal);
137
174
  return { kind: "close" };
138
175
  },
139
176
  export: async ({ value, signal }) =>
@@ -0,0 +1,38 @@
1
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import { exportStoredPlan, planExportDestination } from "./plan-export.js";
3
+ import { configuredPlanExportPath, type PlanModeSettings } from "./settings.js";
4
+ import type { PlanModeState } from "./state.js";
5
+
6
+ interface PlanExportControllerOptions {
7
+ getState(): PlanModeState;
8
+ getSettings(): PlanModeSettings;
9
+ finishReady(ctx: ExtensionContext): void;
10
+ }
11
+
12
+ export function createPlanExportController(options: PlanExportControllerOptions) {
13
+ return {
14
+ export(
15
+ path: string | undefined,
16
+ ctx: ExtensionContext,
17
+ signal: AbortSignal,
18
+ isCurrent: () => boolean,
19
+ ) {
20
+ const state = options.getState();
21
+ return exportStoredPlan(
22
+ state,
23
+ path,
24
+ ctx,
25
+ {
26
+ signal,
27
+ isCurrent,
28
+ getState: options.getState,
29
+ finishReady: () => options.finishReady(ctx),
30
+ },
31
+ configuredPlanExportPath(options.getSettings()),
32
+ );
33
+ },
34
+ getDestination(ctx: ExtensionContext) {
35
+ return planExportDestination(configuredPlanExportPath(options.getSettings()), ctx.cwd);
36
+ },
37
+ };
38
+ }
@@ -0,0 +1,19 @@
1
+ import type { PlanExportDestination } from "./plan-export.js";
2
+
3
+ export type PlanExportDestinationProvider = () => PlanExportDestination;
4
+
5
+ export function planExportInputScreen(getDestination: PlanExportDestinationProvider) {
6
+ const destination = getDestination();
7
+ return {
8
+ kind: "input" as const,
9
+ title: "Export plan",
10
+ lines: [
11
+ "Existing paths are never overwritten.",
12
+ `Default: ${destination.configuredPath}`,
13
+ `Resolves to: ${destination.resolvedPath}`,
14
+ ],
15
+ placeholder: destination.configuredPath,
16
+ action: "export" as const,
17
+ hint: "back" as const,
18
+ };
19
+ }
@@ -2,14 +2,20 @@ import { mkdir, writeFile } from "node:fs/promises";
2
2
  import { dirname, resolve } from "node:path";
3
3
  import { stripVTControlCharacters } from "node:util";
4
4
  import { type ExtensionContext, withFileMutationQueue } from "@earendil-works/pi-coding-agent";
5
+ import { DEFAULT_PLAN_EXPORT_PATH } from "./settings.js";
5
6
  import type { PlanModeState } from "./state.js";
6
7
 
7
- export const DEFAULT_PLAN_EXPORT_PATH = "PLAN.md";
8
+ export { DEFAULT_PLAN_EXPORT_PATH };
8
9
 
9
10
  export interface PlanExportResult {
10
11
  path: string;
11
12
  }
12
13
 
14
+ export interface PlanExportDestination {
15
+ configuredPath: string;
16
+ resolvedPath: string;
17
+ }
18
+
13
19
  export interface PlanExportLifecycle {
14
20
  signal: AbortSignal;
15
21
  isCurrent(): boolean;
@@ -22,6 +28,7 @@ export async function exportStoredPlan(
22
28
  requestedPath: string | undefined,
23
29
  ctx: ExtensionContext,
24
30
  lifecycle?: PlanExportLifecycle,
31
+ defaultPath = DEFAULT_PLAN_EXPORT_PATH,
25
32
  ) {
26
33
  const plan =
27
34
  (state.enabled ? state.latestPlan : undefined)?.trim() ??
@@ -41,7 +48,14 @@ export async function exportStoredPlan(
41
48
  (lifecycle.isCurrent() && (!lifecycle.getState || lifecycle.getState() === state));
42
49
  let result: PlanExportResult;
43
50
  try {
44
- result = await exportPlanToFile(plan, requestedPath, ctx.cwd, lifecycle?.signal, isCurrent);
51
+ result = await exportPlanToFile(
52
+ plan,
53
+ requestedPath,
54
+ ctx.cwd,
55
+ lifecycle?.signal,
56
+ isCurrent,
57
+ defaultPath,
58
+ );
45
59
  } catch (error: unknown) {
46
60
  if (lifecycle?.signal.aborted || !isCurrent()) return false;
47
61
  if (!ctx.hasUI) throw error;
@@ -65,8 +79,9 @@ export async function exportPlanToFile(
65
79
  cwd: string,
66
80
  signal?: AbortSignal,
67
81
  isCurrent: () => boolean = () => true,
82
+ defaultPath = DEFAULT_PLAN_EXPORT_PATH,
68
83
  ): Promise<PlanExportResult> {
69
- const path = resolvePlanExportPath(requestedPath, cwd);
84
+ const path = resolvePlanExportPath(requestedPath, cwd, defaultPath);
70
85
  await withFileMutationQueue(path, async () => {
71
86
  throwIfCancelled(signal, isCurrent);
72
87
  await mkdir(dirname(path), { recursive: true });
@@ -85,8 +100,19 @@ export async function exportPlanToFile(
85
100
  return { path };
86
101
  }
87
102
 
88
- export function resolvePlanExportPath(requestedPath: string | undefined, cwd: string) {
89
- const rawPath = requestedPath?.trim() || DEFAULT_PLAN_EXPORT_PATH;
103
+ export function planExportDestination(defaultPath: string, cwd: string): PlanExportDestination {
104
+ return {
105
+ configuredPath: safeNotification(defaultPath),
106
+ resolvedPath: safeNotification(resolvePlanExportPath(undefined, cwd, defaultPath)),
107
+ };
108
+ }
109
+
110
+ export function resolvePlanExportPath(
111
+ requestedPath: string | undefined,
112
+ cwd: string,
113
+ defaultPath = DEFAULT_PLAN_EXPORT_PATH,
114
+ ) {
115
+ const rawPath = requestedPath?.trim() || defaultPath;
90
116
  const normalizedPath = rawPath.startsWith("@") ? rawPath.slice(1) : rawPath;
91
117
  if (!normalizedPath.trim()) throw new Error("Plan export path must not be empty.");
92
118
  if (normalizedPath.includes("\0")) {