@narumitw/pi-plan-mode 0.57.0 → 0.58.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 +68 -18
- package/dist/chunks/{chunk-YUFPCQVG.js → chunk-QHHHBTDO.js} +315 -362
- package/dist/chunks/chunk-QHHHBTDO.js.map +7 -0
- package/dist/chunks/{interactive-ui-M3GEZN4M.js → interactive-ui-UNJGC2RQ.js} +397 -188
- package/dist/chunks/interactive-ui-UNJGC2RQ.js.map +7 -0
- package/dist/index.ts +669 -322
- package/dist/index.ts.map +4 -4
- package/docs/command-workflows.md +1 -5
- package/docs/settings.md +26 -24
- package/package.json +1 -1
- package/src/command.ts +1 -0
- package/src/fresh-handoff-coordinator.ts +55 -0
- package/src/fresh-implementation.ts +155 -74
- package/src/implementation-models.ts +48 -0
- package/src/plan-action-controller.ts +78 -23
- package/src/plan-action-menus.ts +361 -67
- package/src/plan-mode.ts +450 -117
- package/src/saved-plan-menu.ts +7 -35
- package/src/settings-menu.ts +156 -35
- package/src/settings.ts +80 -34
- package/src/state.ts +62 -0
- package/dist/chunks/chunk-YUFPCQVG.js.map +0 -7
- package/dist/chunks/interactive-ui-M3GEZN4M.js.map +0 -7
- package/src/fresh-implementation-preferences.ts +0 -102
- package/src/implementation-options.ts +0 -127
- package/src/implementation-preferences.ts +0 -145
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
findAvailableImplementationModel,
|
|
4
|
+
snapshotAvailableImplementationModels,
|
|
5
|
+
} from "./implementation-models.js";
|
|
2
6
|
import type { PlanExportDestination } from "./plan-export.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
7
|
+
import {
|
|
8
|
+
configuredImplementationModel,
|
|
9
|
+
configuredImplementationThinkingLevel,
|
|
10
|
+
type PlanModeFixedThinkingLevel,
|
|
11
|
+
type PlanModeSettings,
|
|
12
|
+
} from "./settings.js";
|
|
13
|
+
import type { ImplementationRuntimeSelection, PlanModeState } from "./state.js";
|
|
5
14
|
|
|
6
15
|
type InteractiveUi = typeof import("./interactive-ui.js");
|
|
7
16
|
|
|
@@ -10,25 +19,25 @@ interface MenuLifecycle {
|
|
|
10
19
|
isCurrent(): boolean;
|
|
11
20
|
}
|
|
12
21
|
|
|
22
|
+
export type FreshImplementationTiming = "immediate" | "after-settled";
|
|
23
|
+
|
|
13
24
|
interface PlanActionControllerOptions {
|
|
14
25
|
loadInteractiveUi(): Promise<InteractiveUi>;
|
|
15
26
|
getState(): PlanModeState;
|
|
16
27
|
captureLifecycle(): MenuLifecycle;
|
|
17
28
|
statusText(): string;
|
|
29
|
+
getThinkingLevel(): PlanModeFixedThinkingLevel | undefined;
|
|
30
|
+
getSettings(): PlanModeSettings;
|
|
18
31
|
implementationOutcome(): string;
|
|
19
32
|
getExportDestination(ctx: ExtensionContext): PlanExportDestination;
|
|
20
33
|
show(ctx: ExtensionContext): void;
|
|
21
34
|
finalize(ctx: ExtensionContext): void;
|
|
22
|
-
|
|
23
|
-
implementHere(
|
|
24
|
-
ctx: ExtensionContext,
|
|
25
|
-
preferences?: ImplementationPreferences,
|
|
26
|
-
isCurrent?: () => boolean,
|
|
27
|
-
): void | Promise<void>;
|
|
35
|
+
implementHere(ctx: ExtensionContext): void | Promise<void>;
|
|
28
36
|
implementFresh(
|
|
29
37
|
ctx: ExtensionContext,
|
|
30
38
|
isCurrent: () => boolean,
|
|
31
|
-
|
|
39
|
+
runtime: ImplementationRuntimeSelection | undefined,
|
|
40
|
+
timing: FreshImplementationTiming,
|
|
32
41
|
): void | Promise<void>;
|
|
33
42
|
exportPlan(
|
|
34
43
|
ctx: ExtensionContext,
|
|
@@ -44,17 +53,53 @@ interface PlanActionControllerOptions {
|
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
export function createPlanActionController(options: PlanActionControllerOptions) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const configuredDefaults = (): ImplementationRuntimeSelection => {
|
|
57
|
+
const settings = options.getSettings();
|
|
58
|
+
const model = configuredImplementationModel(settings);
|
|
59
|
+
const thinkingLevel = configuredImplementationThinkingLevel(settings);
|
|
60
|
+
return {
|
|
61
|
+
...(model ? { model: { ...model } } : {}),
|
|
62
|
+
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const effectiveDefaults = (ctx: ExtensionContext): ImplementationRuntimeSelection => {
|
|
66
|
+
const configured = configuredDefaults();
|
|
67
|
+
const availableModel = findAvailableImplementationModel(
|
|
68
|
+
snapshotAvailableImplementationModels(ctx),
|
|
69
|
+
configured.model,
|
|
70
|
+
);
|
|
71
|
+
if (configured.model && !availableModel) {
|
|
72
|
+
ctx.ui.notify(
|
|
73
|
+
"The configured fresh implementation model is unavailable; using the planning model.",
|
|
74
|
+
"warning",
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const planModel = ctx.model
|
|
78
|
+
? { provider: ctx.model.provider, modelId: ctx.model.id }
|
|
79
|
+
: undefined;
|
|
80
|
+
const model = availableModel
|
|
81
|
+
? { provider: availableModel.provider, modelId: availableModel.id }
|
|
82
|
+
: planModel;
|
|
83
|
+
const thinkingLevel = configured.thinkingLevel ?? options.getThinkingLevel();
|
|
84
|
+
return {
|
|
85
|
+
...(model ? { model } : {}),
|
|
86
|
+
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const freshAction = (
|
|
90
|
+
ctx: ExtensionContext,
|
|
91
|
+
lifecycle: MenuLifecycle,
|
|
92
|
+
signal: AbortSignal,
|
|
93
|
+
runtime: ImplementationRuntimeSelection | undefined,
|
|
94
|
+
timing: FreshImplementationTiming,
|
|
95
|
+
) => {
|
|
96
|
+
if (signal.aborted) return;
|
|
97
|
+
const isCurrent =
|
|
98
|
+
timing === "after-settled"
|
|
99
|
+
? lifecycle.isCurrent
|
|
100
|
+
: () => lifecycle.isCurrent() && !signal.aborted;
|
|
101
|
+
return options.implementFresh(ctx, isCurrent, runtime, timing);
|
|
102
|
+
};
|
|
58
103
|
|
|
59
104
|
return {
|
|
60
105
|
async showSaved(ctx: ExtensionContext) {
|
|
@@ -69,7 +114,9 @@ export function createPlanActionController(options: PlanActionControllerOptions)
|
|
|
69
114
|
signal: lifecycle.signal,
|
|
70
115
|
isCurrent: lifecycle.isCurrent,
|
|
71
116
|
show: () => options.show(ctx),
|
|
72
|
-
|
|
117
|
+
implementHere: () => options.implementHere(ctx),
|
|
118
|
+
implementFresh: (signal) =>
|
|
119
|
+
freshAction(ctx, lifecycle, signal, effectiveDefaults(ctx), "immediate"),
|
|
73
120
|
exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
|
|
74
121
|
settings: (signal) => options.settings(ctx, signal, lifecycle.isCurrent),
|
|
75
122
|
clear: () => options.clearSaved(ctx),
|
|
@@ -86,13 +133,17 @@ export function createPlanActionController(options: PlanActionControllerOptions)
|
|
|
86
133
|
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
87
134
|
await ui.showPlanModeMenu(ctx, {
|
|
88
135
|
statusText: options.statusText(),
|
|
136
|
+
planThinkingLevel: options.getThinkingLevel(),
|
|
137
|
+
implementationDefaults: configuredDefaults(),
|
|
89
138
|
hasReadyPlan: options.getState().latestPlan !== undefined,
|
|
90
139
|
implementationOutcome: options.implementationOutcome,
|
|
91
140
|
getExportDestination: () => options.getExportDestination(ctx),
|
|
92
141
|
...lifecycle,
|
|
93
142
|
show: () => options.show(ctx),
|
|
94
143
|
finalize: () => options.finalize(ctx),
|
|
95
|
-
|
|
144
|
+
implementHere: () => options.implementHere(ctx),
|
|
145
|
+
implementFresh: (runtime, signal) =>
|
|
146
|
+
freshAction(ctx, lifecycle, signal, runtime, "immediate"),
|
|
96
147
|
exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
|
|
97
148
|
save: () => options.save(ctx),
|
|
98
149
|
stay: () => options.stay(ctx),
|
|
@@ -106,9 +157,13 @@ export function createPlanActionController(options: PlanActionControllerOptions)
|
|
|
106
157
|
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
107
158
|
await ui.showReadyPlanMenu(ctx, {
|
|
108
159
|
...lifecycle,
|
|
160
|
+
planThinkingLevel: options.getThinkingLevel(),
|
|
161
|
+
implementationDefaults: configuredDefaults(),
|
|
109
162
|
implementationOutcome: options.implementationOutcome,
|
|
110
163
|
getExportDestination: () => options.getExportDestination(ctx),
|
|
111
|
-
|
|
164
|
+
implementHere: () => options.implementHere(ctx),
|
|
165
|
+
implementFresh: (runtime, signal) =>
|
|
166
|
+
freshAction(ctx, lifecycle, signal, runtime, "after-settled"),
|
|
112
167
|
exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
|
|
113
168
|
save: () => options.save(ctx),
|
|
114
169
|
stay: () => undefined,
|
package/src/plan-action-menus.ts
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
2
|
+
import { defineMenu, runMenu, sanitizeTerminalText } from "@narumitw/pi-tui-kit";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type AvailableImplementationModel,
|
|
5
|
+
findAvailableImplementationModel,
|
|
6
|
+
type ImplementationModelOverride,
|
|
7
|
+
snapshotAvailableImplementationModels,
|
|
8
|
+
} from "./implementation-models.js";
|
|
7
9
|
import { type PlanExportDestinationProvider, planExportInputScreen } from "./plan-export-screen.js";
|
|
8
|
-
import type
|
|
10
|
+
import { IMPLEMENTATION_THINKING_LEVELS, type PlanModeFixedThinkingLevel } from "./settings.js";
|
|
11
|
+
import type { ImplementationRuntimeSelection } from "./state.js";
|
|
9
12
|
|
|
10
|
-
interface
|
|
13
|
+
interface MenuLifecycle {
|
|
11
14
|
signal: AbortSignal;
|
|
12
15
|
isCurrent(): boolean;
|
|
13
|
-
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const IMPLEMENTATION_CONTEXT_LINES = [
|
|
19
|
+
"Implement here keeps this planning conversation.",
|
|
20
|
+
"Start fresh transfers only the approved plan to a new session.",
|
|
21
|
+
] as const;
|
|
22
|
+
|
|
23
|
+
const THINKING_LEVEL_DESCRIPTIONS: Record<PlanModeFixedThinkingLevel, string> = {
|
|
24
|
+
off: "No reasoning",
|
|
25
|
+
minimal: "Very brief reasoning (~1k tokens)",
|
|
26
|
+
low: "Light reasoning (~2k tokens)",
|
|
27
|
+
medium: "Moderate reasoning (~8k tokens)",
|
|
28
|
+
high: "Deep reasoning (~16k tokens)",
|
|
29
|
+
xhigh: "Extra-high reasoning (~32k tokens)",
|
|
30
|
+
max: "Maximum reasoning",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
interface PlanMenuOptions extends MenuLifecycle {
|
|
34
|
+
statusText: string;
|
|
35
|
+
planThinkingLevel: PlanModeFixedThinkingLevel | undefined;
|
|
36
|
+
implementationDefaults?: ImplementationRuntimeSelection;
|
|
37
|
+
hasReadyPlan: boolean;
|
|
14
38
|
implementationOutcome(): string;
|
|
15
39
|
getExportDestination: PlanExportDestinationProvider;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
): void | Promise<void>;
|
|
40
|
+
show(): void;
|
|
41
|
+
finalize(): void;
|
|
42
|
+
implementHere(): void | Promise<void>;
|
|
20
43
|
implementFresh(
|
|
44
|
+
runtime: ImplementationRuntimeSelection,
|
|
21
45
|
signal: AbortSignal,
|
|
22
|
-
preferences?: ImplementationPreferences,
|
|
23
46
|
): void | Promise<void>;
|
|
24
47
|
exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
|
|
25
48
|
save(): void;
|
|
@@ -27,80 +50,51 @@ interface ReadyPlanMenuOptions {
|
|
|
27
50
|
exit(): void;
|
|
28
51
|
}
|
|
29
52
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
hasReadyPlan: boolean;
|
|
33
|
-
show(): void;
|
|
34
|
-
finalize(): void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function showPlanModeMenu(ctx: ExtensionContext, options: PlanMenuOptions) {
|
|
38
|
-
return showActions(ctx, options, options);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function showReadyPlanMenu(ctx: ExtensionContext, options: ReadyPlanMenuOptions) {
|
|
42
|
-
return showActions(ctx, options);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function showActions(
|
|
46
|
-
ctx: ExtensionContext,
|
|
47
|
-
options: ReadyPlanMenuOptions,
|
|
48
|
-
current?: PlanMenuOptions,
|
|
49
|
-
) {
|
|
50
|
-
const implementation = createImplementationOptions(ctx, options.implementationPreferences);
|
|
51
|
-
const ready = current?.hasReadyPlan ?? true;
|
|
52
|
-
type Screen = "main" | "export" | "implementation-options" | "implementation-model";
|
|
53
|
+
export async function showPlanModeMenu(ctx: ExtensionContext, options: PlanMenuOptions) {
|
|
54
|
+
type Screen = "main" | "fresh" | "models" | "thinking" | "export";
|
|
53
55
|
type Action =
|
|
54
|
-
| ImplementationOptionAction
|
|
55
56
|
| "show"
|
|
56
57
|
| "finalize"
|
|
57
58
|
| "implement-here"
|
|
58
|
-
| "
|
|
59
|
+
| "select-model"
|
|
60
|
+
| "select-thinking"
|
|
61
|
+
| "start-fresh"
|
|
59
62
|
| "export"
|
|
60
63
|
| "save"
|
|
61
64
|
| "stay"
|
|
62
65
|
| "exit";
|
|
66
|
+
const freshFlow = createFreshImplementationFlow(
|
|
67
|
+
ctx,
|
|
68
|
+
options.planThinkingLevel,
|
|
69
|
+
options.implementationDefaults,
|
|
70
|
+
options.implementFresh,
|
|
71
|
+
);
|
|
63
72
|
const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
|
|
64
73
|
start: "main",
|
|
65
74
|
screens: {
|
|
66
|
-
...implementation.screens,
|
|
67
75
|
main: () => ({
|
|
68
76
|
kind: "actions",
|
|
69
|
-
title:
|
|
77
|
+
title: "Plan mode",
|
|
70
78
|
lines: [
|
|
71
|
-
|
|
72
|
-
...(
|
|
73
|
-
? [
|
|
74
|
-
"Implement here keeps this planning conversation.",
|
|
75
|
-
"Start fresh transfers only the approved plan to a new session.",
|
|
76
|
-
options.implementationOutcome(),
|
|
77
|
-
implementation.summary(),
|
|
78
|
-
]
|
|
79
|
+
options.statusText,
|
|
80
|
+
...(options.hasReadyPlan
|
|
81
|
+
? [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()]
|
|
79
82
|
: []),
|
|
80
83
|
],
|
|
81
|
-
items:
|
|
84
|
+
items: options.hasReadyPlan
|
|
82
85
|
? [
|
|
83
|
-
|
|
84
|
-
? [{ id: "show", label: "Show latest proposed plan", action: "show" as const }]
|
|
85
|
-
: []),
|
|
86
|
+
{ id: "show", label: "Show latest proposed plan", action: "show" },
|
|
86
87
|
{
|
|
87
88
|
id: "implement-here",
|
|
88
89
|
label: "Implement here",
|
|
89
90
|
description: "Continue in this session with the planning conversation.",
|
|
90
91
|
action: "implement-here",
|
|
91
|
-
busyLabel: "Preparing implementation…",
|
|
92
92
|
},
|
|
93
93
|
{
|
|
94
94
|
id: "implement-fresh",
|
|
95
95
|
label: "Start fresh and implement",
|
|
96
|
-
description: "
|
|
97
|
-
|
|
98
|
-
busyLabel: "Starting fresh implementation session…",
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
id: "implementation-options",
|
|
102
|
-
label: "Implementation options…",
|
|
103
|
-
to: "implementation-options",
|
|
96
|
+
description: "Configure one-shot model and thinking choices first.",
|
|
97
|
+
to: "fresh",
|
|
104
98
|
},
|
|
105
99
|
{ id: "export", label: "Export plan…", to: "export" },
|
|
106
100
|
{ id: "save", label: "Save for later", action: "save" },
|
|
@@ -114,24 +108,139 @@ async function showActions(
|
|
|
114
108
|
],
|
|
115
109
|
hint: "close",
|
|
116
110
|
}),
|
|
111
|
+
fresh: freshFlow.settingsScreen,
|
|
112
|
+
models: freshFlow.modelScreen,
|
|
113
|
+
thinking: freshFlow.thinkingScreen,
|
|
117
114
|
export: () => planExportInputScreen(options.getExportDestination),
|
|
118
115
|
},
|
|
119
116
|
actions: {
|
|
120
|
-
...implementation.actions,
|
|
121
117
|
show: async () => {
|
|
122
|
-
|
|
118
|
+
options.show();
|
|
123
119
|
return { kind: "close" };
|
|
124
120
|
},
|
|
125
121
|
finalize: async () => {
|
|
126
|
-
|
|
122
|
+
options.finalize();
|
|
123
|
+
return { kind: "close" };
|
|
124
|
+
},
|
|
125
|
+
"implement-here": async () => {
|
|
126
|
+
await options.implementHere();
|
|
127
127
|
return { kind: "close" };
|
|
128
128
|
},
|
|
129
|
-
"
|
|
130
|
-
|
|
129
|
+
"select-model": async ({ itemId }) => {
|
|
130
|
+
freshFlow.selectModel(itemId);
|
|
131
|
+
return { kind: "back" };
|
|
132
|
+
},
|
|
133
|
+
"select-thinking": async ({ itemId }) => {
|
|
134
|
+
freshFlow.selectThinking(itemId);
|
|
135
|
+
return { kind: "back" };
|
|
136
|
+
},
|
|
137
|
+
"start-fresh": async ({ signal }) => {
|
|
138
|
+
await freshFlow.start(signal);
|
|
139
|
+
return { kind: "close" };
|
|
140
|
+
},
|
|
141
|
+
export: async ({ value, signal }) =>
|
|
142
|
+
(await options.exportPlan(value ?? "", signal)) ? { kind: "close" } : { kind: "rejected" },
|
|
143
|
+
save: async () => {
|
|
144
|
+
options.save();
|
|
145
|
+
return { kind: "close" };
|
|
146
|
+
},
|
|
147
|
+
stay: async () => {
|
|
148
|
+
options.stay();
|
|
149
|
+
return { kind: "close" };
|
|
150
|
+
},
|
|
151
|
+
exit: async () => {
|
|
152
|
+
options.exit();
|
|
153
|
+
return { kind: "close" };
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
await runMenu(ctx, menu, {
|
|
158
|
+
getState: () => undefined,
|
|
159
|
+
signal: options.signal,
|
|
160
|
+
isCurrent: options.isCurrent,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
interface ReadyPlanMenuOptions extends MenuLifecycle {
|
|
165
|
+
planThinkingLevel: PlanModeFixedThinkingLevel | undefined;
|
|
166
|
+
implementationDefaults?: ImplementationRuntimeSelection;
|
|
167
|
+
implementationOutcome(): string;
|
|
168
|
+
getExportDestination: PlanExportDestinationProvider;
|
|
169
|
+
implementHere(): void | Promise<void>;
|
|
170
|
+
implementFresh(
|
|
171
|
+
runtime: ImplementationRuntimeSelection,
|
|
172
|
+
signal: AbortSignal,
|
|
173
|
+
): void | Promise<void>;
|
|
174
|
+
exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
|
|
175
|
+
save(): void;
|
|
176
|
+
stay(): void;
|
|
177
|
+
exit(): void;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export async function showReadyPlanMenu(ctx: ExtensionContext, options: ReadyPlanMenuOptions) {
|
|
181
|
+
type Screen = "ready" | "fresh" | "models" | "thinking" | "export";
|
|
182
|
+
type Action =
|
|
183
|
+
| "implement-here"
|
|
184
|
+
| "select-model"
|
|
185
|
+
| "select-thinking"
|
|
186
|
+
| "start-fresh"
|
|
187
|
+
| "export"
|
|
188
|
+
| "save"
|
|
189
|
+
| "stay"
|
|
190
|
+
| "exit";
|
|
191
|
+
const freshFlow = createFreshImplementationFlow(
|
|
192
|
+
ctx,
|
|
193
|
+
options.planThinkingLevel,
|
|
194
|
+
options.implementationDefaults,
|
|
195
|
+
options.implementFresh,
|
|
196
|
+
);
|
|
197
|
+
const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
|
|
198
|
+
start: "ready",
|
|
199
|
+
screens: {
|
|
200
|
+
ready: () => ({
|
|
201
|
+
kind: "actions",
|
|
202
|
+
title: "Proposed plan ready. What next?",
|
|
203
|
+
lines: [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()],
|
|
204
|
+
items: [
|
|
205
|
+
{
|
|
206
|
+
id: "implement-here",
|
|
207
|
+
label: "Implement here",
|
|
208
|
+
description: "Continue in this session with the planning conversation.",
|
|
209
|
+
action: "implement-here",
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
id: "implement-fresh",
|
|
213
|
+
label: "Start fresh and implement",
|
|
214
|
+
description: "Configure one-shot model and thinking choices first.",
|
|
215
|
+
to: "fresh",
|
|
216
|
+
},
|
|
217
|
+
{ id: "export", label: "Export plan…", to: "export" },
|
|
218
|
+
{ id: "save", label: "Save for later", action: "save" },
|
|
219
|
+
{ id: "stay", label: "Stay in Plan mode", action: "stay" },
|
|
220
|
+
{ id: "exit", label: "Discard plan and exit", action: "exit" },
|
|
221
|
+
],
|
|
222
|
+
hint: "close",
|
|
223
|
+
}),
|
|
224
|
+
fresh: freshFlow.settingsScreen,
|
|
225
|
+
models: freshFlow.modelScreen,
|
|
226
|
+
thinking: freshFlow.thinkingScreen,
|
|
227
|
+
export: () => planExportInputScreen(options.getExportDestination),
|
|
228
|
+
},
|
|
229
|
+
actions: {
|
|
230
|
+
"implement-here": async () => {
|
|
231
|
+
await options.implementHere();
|
|
131
232
|
return { kind: "close" };
|
|
132
233
|
},
|
|
133
|
-
"
|
|
134
|
-
|
|
234
|
+
"select-model": async ({ itemId }) => {
|
|
235
|
+
freshFlow.selectModel(itemId);
|
|
236
|
+
return { kind: "back" };
|
|
237
|
+
},
|
|
238
|
+
"select-thinking": async ({ itemId }) => {
|
|
239
|
+
freshFlow.selectThinking(itemId);
|
|
240
|
+
return { kind: "back" };
|
|
241
|
+
},
|
|
242
|
+
"start-fresh": async ({ signal }) => {
|
|
243
|
+
await freshFlow.start(signal);
|
|
135
244
|
return { kind: "close" };
|
|
136
245
|
},
|
|
137
246
|
export: async ({ value, signal }) =>
|
|
@@ -156,3 +265,188 @@ async function showActions(
|
|
|
156
265
|
isCurrent: options.isCurrent,
|
|
157
266
|
});
|
|
158
267
|
}
|
|
268
|
+
|
|
269
|
+
interface ModelChoice {
|
|
270
|
+
itemId: string;
|
|
271
|
+
model: ImplementationModelOverride;
|
|
272
|
+
modelInfo: AvailableImplementationModel;
|
|
273
|
+
label: string;
|
|
274
|
+
summary: string;
|
|
275
|
+
details?: readonly string[];
|
|
276
|
+
searchText: string;
|
|
277
|
+
isPlanModel: boolean;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function createFreshImplementationFlow(
|
|
281
|
+
ctx: ExtensionContext,
|
|
282
|
+
planThinkingLevel: PlanModeFixedThinkingLevel | undefined,
|
|
283
|
+
implementationDefaults: ImplementationRuntimeSelection | undefined,
|
|
284
|
+
implementFresh: (
|
|
285
|
+
runtime: ImplementationRuntimeSelection,
|
|
286
|
+
signal: AbortSignal,
|
|
287
|
+
) => void | Promise<void>,
|
|
288
|
+
) {
|
|
289
|
+
const models = snapshotAvailableModels(ctx);
|
|
290
|
+
const planModel = ctx.model ? { provider: ctx.model.provider, modelId: ctx.model.id } : undefined;
|
|
291
|
+
const planModelSummary = ctx.model
|
|
292
|
+
? `${safeModelMetadata(ctx.model.id, "unknown model")} [${safeModelMetadata(ctx.model.provider, "unknown provider")}]`
|
|
293
|
+
: undefined;
|
|
294
|
+
const configuredModel = implementationDefaults?.model;
|
|
295
|
+
const configuredAvailableModel = findAvailableImplementationModel(
|
|
296
|
+
models.map((choice) => choice.modelInfo),
|
|
297
|
+
configuredModel,
|
|
298
|
+
);
|
|
299
|
+
let unavailableDefaultActive = configuredModel !== undefined && !configuredAvailableModel;
|
|
300
|
+
let selectedModel = configuredAvailableModel
|
|
301
|
+
? models.find((choice) => choice.modelInfo === configuredAvailableModel)
|
|
302
|
+
: undefined;
|
|
303
|
+
let selectedModelUsesDefault = selectedModel !== undefined;
|
|
304
|
+
let selectedThinkingLevel = implementationDefaults?.thinkingLevel;
|
|
305
|
+
return {
|
|
306
|
+
settingsScreen: () => ({
|
|
307
|
+
kind: "actions" as const,
|
|
308
|
+
title: "Fresh implementation settings",
|
|
309
|
+
lines: [
|
|
310
|
+
"These choices apply once to the new implementation session.",
|
|
311
|
+
...(unavailableDefaultActive && configuredModel
|
|
312
|
+
? [
|
|
313
|
+
`Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`,
|
|
314
|
+
]
|
|
315
|
+
: []),
|
|
316
|
+
],
|
|
317
|
+
items: [
|
|
318
|
+
{
|
|
319
|
+
id: "start-fresh",
|
|
320
|
+
label: "Start fresh implementation",
|
|
321
|
+
description: "Create the linked session and begin implementation.",
|
|
322
|
+
action: "start-fresh" as const,
|
|
323
|
+
busyLabel: "Starting fresh implementation session…",
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
id: "implementation-model",
|
|
327
|
+
label: "Model",
|
|
328
|
+
description:
|
|
329
|
+
selectedModel?.summary ??
|
|
330
|
+
(planModelSummary ? `${planModelSummary} · same as plan` : "Same as plan"),
|
|
331
|
+
to: "models" as const,
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
id: "implementation-thinking",
|
|
335
|
+
label: "Thinking level",
|
|
336
|
+
description:
|
|
337
|
+
selectedThinkingLevel ??
|
|
338
|
+
(planThinkingLevel ? `${planThinkingLevel} · same as plan` : "Same as plan"),
|
|
339
|
+
to: "thinking" as const,
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
}),
|
|
343
|
+
modelScreen: () => ({
|
|
344
|
+
kind: "choice" as const,
|
|
345
|
+
title: "Implementation model",
|
|
346
|
+
items: [
|
|
347
|
+
{
|
|
348
|
+
id: "same-as-plan",
|
|
349
|
+
label: "Same as plan",
|
|
350
|
+
...(planModelSummary ? { description: planModelSummary } : {}),
|
|
351
|
+
},
|
|
352
|
+
...models.map((choice) => ({
|
|
353
|
+
id: choice.itemId,
|
|
354
|
+
label: choice.label,
|
|
355
|
+
details: choice.details,
|
|
356
|
+
searchText: choice.searchText,
|
|
357
|
+
})),
|
|
358
|
+
],
|
|
359
|
+
action: "select-model" as const,
|
|
360
|
+
initialItemId: selectedModel?.itemId ?? "same-as-plan",
|
|
361
|
+
enableSearch: true,
|
|
362
|
+
viewportSize: 10,
|
|
363
|
+
}),
|
|
364
|
+
thinkingScreen: () => ({
|
|
365
|
+
kind: "choice" as const,
|
|
366
|
+
title: "Implementation thinking level",
|
|
367
|
+
items: [
|
|
368
|
+
{
|
|
369
|
+
id: "same-as-plan",
|
|
370
|
+
label: "Same as plan",
|
|
371
|
+
},
|
|
372
|
+
...IMPLEMENTATION_THINKING_LEVELS.map((level) => ({
|
|
373
|
+
id: level,
|
|
374
|
+
label: `${level === planThinkingLevel ? "✓ " : ""}${level}`,
|
|
375
|
+
description: THINKING_LEVEL_DESCRIPTIONS[level],
|
|
376
|
+
})),
|
|
377
|
+
],
|
|
378
|
+
action: "select-thinking" as const,
|
|
379
|
+
initialItemId: selectedThinkingLevel ?? "same-as-plan",
|
|
380
|
+
viewportSize: IMPLEMENTATION_THINKING_LEVELS.length + 1,
|
|
381
|
+
}),
|
|
382
|
+
selectModel(itemId: string) {
|
|
383
|
+
const choice = models.find((candidate) => candidate.itemId === itemId);
|
|
384
|
+
selectedModel = itemId === "same-as-plan" || choice?.isPlanModel ? undefined : choice;
|
|
385
|
+
selectedModelUsesDefault = false;
|
|
386
|
+
unavailableDefaultActive = false;
|
|
387
|
+
},
|
|
388
|
+
selectThinking(itemId: string) {
|
|
389
|
+
selectedThinkingLevel = IMPLEMENTATION_THINKING_LEVELS.find((level) => level === itemId);
|
|
390
|
+
},
|
|
391
|
+
start(signal: AbortSignal) {
|
|
392
|
+
if (
|
|
393
|
+
selectedModelUsesDefault &&
|
|
394
|
+
selectedModel &&
|
|
395
|
+
!findAvailableImplementationModel(
|
|
396
|
+
snapshotAvailableImplementationModels(ctx),
|
|
397
|
+
selectedModel.model,
|
|
398
|
+
)
|
|
399
|
+
) {
|
|
400
|
+
selectedModel = undefined;
|
|
401
|
+
selectedModelUsesDefault = false;
|
|
402
|
+
unavailableDefaultActive = true;
|
|
403
|
+
ctx.ui.notify(
|
|
404
|
+
`Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`,
|
|
405
|
+
"warning",
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
const model = selectedModel?.model ?? planModel;
|
|
409
|
+
const thinkingLevel = selectedThinkingLevel ?? planThinkingLevel;
|
|
410
|
+
return implementFresh(
|
|
411
|
+
{
|
|
412
|
+
...(model ? { model: { ...model } } : {}),
|
|
413
|
+
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
414
|
+
},
|
|
415
|
+
signal,
|
|
416
|
+
);
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function snapshotAvailableModels(ctx: ExtensionContext): ModelChoice[] {
|
|
422
|
+
return snapshotAvailableImplementationModels(ctx)
|
|
423
|
+
.map((model, index) => {
|
|
424
|
+
const provider = safeModelMetadata(model.provider, "unknown provider");
|
|
425
|
+
const modelId = safeModelMetadata(model.id, "unknown model");
|
|
426
|
+
const name = safeModelMetadata(model.name, "");
|
|
427
|
+
const isPlanModel = ctx.model?.provider === model.provider && ctx.model.id === model.id;
|
|
428
|
+
const summary = `${modelId} [${provider}]`;
|
|
429
|
+
return {
|
|
430
|
+
itemId: `model-${index}`,
|
|
431
|
+
model: { provider: model.provider, modelId: model.id },
|
|
432
|
+
modelInfo: model,
|
|
433
|
+
label: `${isPlanModel ? "✓ " : ""}${summary}${isPlanModel ? " · default" : ""}`,
|
|
434
|
+
summary,
|
|
435
|
+
...(name ? { details: [`Model Name: ${name}`] } : {}),
|
|
436
|
+
searchText: [provider, modelId, name].filter(Boolean).join(" "),
|
|
437
|
+
isPlanModel,
|
|
438
|
+
};
|
|
439
|
+
})
|
|
440
|
+
.sort((left, right) => Number(right.isPlanModel) - Number(left.isPlanModel));
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function safeModelReference(model: ImplementationModelOverride | undefined) {
|
|
444
|
+
if (!model) return "configured model";
|
|
445
|
+
return `${safeModelMetadata(model.modelId, "unknown model")} [${safeModelMetadata(model.provider, "unknown provider")}]`;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function safeModelMetadata(value: unknown, fallback: string) {
|
|
449
|
+
if (typeof value !== "string") return fallback;
|
|
450
|
+
const safe = sanitizeTerminalText(value).trim() || fallback;
|
|
451
|
+
return [...safe].slice(0, 512).join("");
|
|
452
|
+
}
|