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