@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
|
@@ -2,23 +2,27 @@
|
|
|
2
2
|
// @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
import {
|
|
4
4
|
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
5
|
+
IMPLEMENTATION_THINKING_LEVELS,
|
|
5
6
|
PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
6
7
|
PLAN_MODE_QUESTION_TOOL_NAME,
|
|
7
8
|
PLAN_MODE_THINKING_LEVELS,
|
|
8
9
|
canSelectToolInPlanMode,
|
|
10
|
+
configuredImplementationModel,
|
|
9
11
|
configuredImplementationPlanRetention,
|
|
12
|
+
configuredImplementationThinkingLevel,
|
|
10
13
|
configuredPlanExportPath,
|
|
11
14
|
configuredPlanModeToggleShortcut,
|
|
12
15
|
defaultPlanModeToolNames,
|
|
16
|
+
findAvailableImplementationModel,
|
|
13
17
|
normalizeKeyId,
|
|
14
18
|
planExportDestination,
|
|
15
19
|
planModeSettingsPath,
|
|
16
20
|
readPlanModeSettings,
|
|
17
21
|
retentionLabel,
|
|
18
|
-
|
|
22
|
+
snapshotAvailableImplementationModels,
|
|
19
23
|
toolPolicyLabel,
|
|
20
24
|
updatePlanModeSettings
|
|
21
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-QHHHBTDO.js";
|
|
22
26
|
|
|
23
27
|
// src/active-implementation-menu.ts
|
|
24
28
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
@@ -89,157 +93,50 @@ async function showActiveImplementationMenu(ctx, options) {
|
|
|
89
93
|
}
|
|
90
94
|
|
|
91
95
|
// src/plan-action-menus.ts
|
|
92
|
-
import { defineMenu as defineMenu2, runMenu as runMenu2 } from "@narumitw/pi-tui-kit";
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
label: "Implementation thinking",
|
|
113
|
-
currentValue: preferences.implementationThinkingLevel ?? "inherit",
|
|
114
|
-
values: PLAN_MODE_THINKING_LEVELS,
|
|
115
|
-
description: "inherit preserves normal behavior, including restoration of Plan thinking. Explicit levels apply after model selection and are clamped by Pi.",
|
|
116
|
-
action: "set-implementation-thinking"
|
|
117
|
-
}
|
|
118
|
-
];
|
|
119
|
-
}
|
|
120
|
-
function createImplementationModelPicker(ctx) {
|
|
121
|
-
const models = ctx.scopedModels?.length ? ctx.scopedModels.map(({ model }) => model) : ctx.modelRegistry.getAvailable();
|
|
122
|
-
const byId = new Map(
|
|
123
|
-
models.map((model, index) => [
|
|
124
|
-
`implementation-model:${index}`,
|
|
125
|
-
{ provider: model.provider, id: model.id }
|
|
126
|
-
])
|
|
96
|
+
import { defineMenu as defineMenu2, runMenu as runMenu2, sanitizeTerminalText } from "@narumitw/pi-tui-kit";
|
|
97
|
+
var IMPLEMENTATION_CONTEXT_LINES = [
|
|
98
|
+
"Implement here keeps this planning conversation.",
|
|
99
|
+
"Start fresh transfers only the approved plan to a new session."
|
|
100
|
+
];
|
|
101
|
+
var THINKING_LEVEL_DESCRIPTIONS = {
|
|
102
|
+
off: "No reasoning",
|
|
103
|
+
minimal: "Very brief reasoning (~1k tokens)",
|
|
104
|
+
low: "Light reasoning (~2k tokens)",
|
|
105
|
+
medium: "Moderate reasoning (~8k tokens)",
|
|
106
|
+
high: "Deep reasoning (~16k tokens)",
|
|
107
|
+
xhigh: "Extra-high reasoning (~32k tokens)",
|
|
108
|
+
max: "Maximum reasoning"
|
|
109
|
+
};
|
|
110
|
+
async function showPlanModeMenu(ctx, options) {
|
|
111
|
+
const freshFlow = createFreshImplementationFlow(
|
|
112
|
+
ctx,
|
|
113
|
+
options.planThinkingLevel,
|
|
114
|
+
options.implementationDefaults,
|
|
115
|
+
options.implementFresh
|
|
127
116
|
);
|
|
128
|
-
return {
|
|
129
|
-
selection(itemId) {
|
|
130
|
-
return itemId === "implementation-current" ? null : byId.get(itemId);
|
|
131
|
-
},
|
|
132
|
-
screen(preferences) {
|
|
133
|
-
return {
|
|
134
|
-
kind: "choice",
|
|
135
|
-
title: "Implementation model",
|
|
136
|
-
enableSearch: true,
|
|
137
|
-
viewportSize: 10,
|
|
138
|
-
hint: "back",
|
|
139
|
-
action: "set-implementation-model",
|
|
140
|
-
lines: [
|
|
141
|
-
"Use current makes no model change. Reopen this menu to refresh the catalogue.",
|
|
142
|
-
"Implement here sends the planning conversation to the selected provider; fresh transfers only the approved plan and normal destination resources.",
|
|
143
|
-
`Selected: ${implementationModelLabel(preferences.implementationModel)}`
|
|
144
|
-
],
|
|
145
|
-
items: [
|
|
146
|
-
{ id: "implementation-current", label: "Use current" },
|
|
147
|
-
...[...byId].map(([id, model]) => ({ id, label: implementationModelLabel(model) }))
|
|
148
|
-
]
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function createImplementationOptions(ctx, initial = {}) {
|
|
154
|
-
let preferences = { ...initial };
|
|
155
|
-
let picker;
|
|
156
|
-
return {
|
|
157
|
-
get: () => preferences,
|
|
158
|
-
summary: () => implementationSummary(preferences),
|
|
159
|
-
screens: {
|
|
160
|
-
"implementation-options": () => ({
|
|
161
|
-
kind: "settings",
|
|
162
|
-
title: "Implementation options",
|
|
163
|
-
lines: [
|
|
164
|
-
"Applies to both implementation actions in this menu only.",
|
|
165
|
-
"Changes take effect only when implementation starts. No automatic restoration afterwards.",
|
|
166
|
-
`Current model: ${implementationModelLabel(ctx.model)}`,
|
|
167
|
-
"inherit keeps normal thinking behavior, not necessarily the temporary Plan thinking level."
|
|
168
|
-
],
|
|
169
|
-
items: implementationSettingItems(preferences)
|
|
170
|
-
}),
|
|
171
|
-
"implementation-model": () => {
|
|
172
|
-
picker ??= createImplementationModelPicker(ctx);
|
|
173
|
-
return picker.screen(preferences);
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
actions: {
|
|
177
|
-
"open-implementation-model": async () => ({
|
|
178
|
-
kind: "to",
|
|
179
|
-
screen: "implementation-model"
|
|
180
|
-
}),
|
|
181
|
-
"set-implementation-model": async ({ itemId }) => {
|
|
182
|
-
const selected = picker?.selection(itemId);
|
|
183
|
-
if (selected === void 0) return { kind: "rejected" };
|
|
184
|
-
preferences = { ...preferences, implementationModel: selected ?? void 0 };
|
|
185
|
-
return { kind: "back" };
|
|
186
|
-
},
|
|
187
|
-
"set-implementation-thinking": async ({ value }) => {
|
|
188
|
-
const level = PLAN_MODE_THINKING_LEVELS.find((level2) => level2 === value);
|
|
189
|
-
if (!level) return { kind: "rejected" };
|
|
190
|
-
preferences = { ...preferences, implementationThinkingLevel: level };
|
|
191
|
-
return { kind: "stay" };
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// src/plan-action-menus.ts
|
|
198
|
-
function showPlanModeMenu(ctx, options) {
|
|
199
|
-
return showActions(ctx, options, options);
|
|
200
|
-
}
|
|
201
|
-
function showReadyPlanMenu(ctx, options) {
|
|
202
|
-
return showActions(ctx, options);
|
|
203
|
-
}
|
|
204
|
-
async function showActions(ctx, options, current) {
|
|
205
|
-
const implementation = createImplementationOptions(ctx, options.implementationPreferences);
|
|
206
|
-
const ready = current?.hasReadyPlan ?? true;
|
|
207
117
|
const menu = defineMenu2({
|
|
208
118
|
start: "main",
|
|
209
119
|
screens: {
|
|
210
|
-
...implementation.screens,
|
|
211
120
|
main: () => ({
|
|
212
121
|
kind: "actions",
|
|
213
|
-
title:
|
|
122
|
+
title: "Plan mode",
|
|
214
123
|
lines: [
|
|
215
|
-
|
|
216
|
-
...
|
|
217
|
-
"Implement here keeps this planning conversation.",
|
|
218
|
-
"Start fresh transfers only the approved plan to a new session.",
|
|
219
|
-
options.implementationOutcome(),
|
|
220
|
-
implementation.summary()
|
|
221
|
-
] : []
|
|
124
|
+
options.statusText,
|
|
125
|
+
...options.hasReadyPlan ? [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()] : []
|
|
222
126
|
],
|
|
223
|
-
items:
|
|
224
|
-
|
|
127
|
+
items: options.hasReadyPlan ? [
|
|
128
|
+
{ id: "show", label: "Show latest proposed plan", action: "show" },
|
|
225
129
|
{
|
|
226
130
|
id: "implement-here",
|
|
227
131
|
label: "Implement here",
|
|
228
132
|
description: "Continue in this session with the planning conversation.",
|
|
229
|
-
action: "implement-here"
|
|
230
|
-
busyLabel: "Preparing implementation\u2026"
|
|
133
|
+
action: "implement-here"
|
|
231
134
|
},
|
|
232
135
|
{
|
|
233
136
|
id: "implement-fresh",
|
|
234
137
|
label: "Start fresh and implement",
|
|
235
|
-
description: "
|
|
236
|
-
|
|
237
|
-
busyLabel: "Starting fresh implementation session\u2026"
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
id: "implementation-options",
|
|
241
|
-
label: "Implementation options\u2026",
|
|
242
|
-
to: "implementation-options"
|
|
138
|
+
description: "Configure one-shot model and thinking choices first.",
|
|
139
|
+
to: "fresh"
|
|
243
140
|
},
|
|
244
141
|
{ id: "export", label: "Export plan\u2026", to: "export" },
|
|
245
142
|
{ id: "save", label: "Save for later", action: "save" },
|
|
@@ -252,24 +149,34 @@ async function showActions(ctx, options, current) {
|
|
|
252
149
|
],
|
|
253
150
|
hint: "close"
|
|
254
151
|
}),
|
|
152
|
+
fresh: freshFlow.settingsScreen,
|
|
153
|
+
models: freshFlow.modelScreen,
|
|
154
|
+
thinking: freshFlow.thinkingScreen,
|
|
255
155
|
export: () => planExportInputScreen(options.getExportDestination)
|
|
256
156
|
},
|
|
257
157
|
actions: {
|
|
258
|
-
...implementation.actions,
|
|
259
158
|
show: async () => {
|
|
260
|
-
|
|
159
|
+
options.show();
|
|
261
160
|
return { kind: "close" };
|
|
262
161
|
},
|
|
263
162
|
finalize: async () => {
|
|
264
|
-
|
|
163
|
+
options.finalize();
|
|
265
164
|
return { kind: "close" };
|
|
266
165
|
},
|
|
267
|
-
"implement-here": async (
|
|
268
|
-
await options.implementHere(
|
|
166
|
+
"implement-here": async () => {
|
|
167
|
+
await options.implementHere();
|
|
269
168
|
return { kind: "close" };
|
|
270
169
|
},
|
|
271
|
-
"
|
|
272
|
-
|
|
170
|
+
"select-model": async ({ itemId }) => {
|
|
171
|
+
freshFlow.selectModel(itemId);
|
|
172
|
+
return { kind: "back" };
|
|
173
|
+
},
|
|
174
|
+
"select-thinking": async ({ itemId }) => {
|
|
175
|
+
freshFlow.selectThinking(itemId);
|
|
176
|
+
return { kind: "back" };
|
|
177
|
+
},
|
|
178
|
+
"start-fresh": async ({ signal }) => {
|
|
179
|
+
await freshFlow.start(signal);
|
|
273
180
|
return { kind: "close" };
|
|
274
181
|
},
|
|
275
182
|
export: async ({ value, signal }) => await options.exportPlan(value ?? "", signal) ? { kind: "close" } : { kind: "rejected" },
|
|
@@ -293,6 +200,229 @@ async function showActions(ctx, options, current) {
|
|
|
293
200
|
isCurrent: options.isCurrent
|
|
294
201
|
});
|
|
295
202
|
}
|
|
203
|
+
async function showReadyPlanMenu(ctx, options) {
|
|
204
|
+
const freshFlow = createFreshImplementationFlow(
|
|
205
|
+
ctx,
|
|
206
|
+
options.planThinkingLevel,
|
|
207
|
+
options.implementationDefaults,
|
|
208
|
+
options.implementFresh
|
|
209
|
+
);
|
|
210
|
+
const menu = defineMenu2({
|
|
211
|
+
start: "ready",
|
|
212
|
+
screens: {
|
|
213
|
+
ready: () => ({
|
|
214
|
+
kind: "actions",
|
|
215
|
+
title: "Proposed plan ready. What next?",
|
|
216
|
+
lines: [...IMPLEMENTATION_CONTEXT_LINES, options.implementationOutcome()],
|
|
217
|
+
items: [
|
|
218
|
+
{
|
|
219
|
+
id: "implement-here",
|
|
220
|
+
label: "Implement here",
|
|
221
|
+
description: "Continue in this session with the planning conversation.",
|
|
222
|
+
action: "implement-here"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
id: "implement-fresh",
|
|
226
|
+
label: "Start fresh and implement",
|
|
227
|
+
description: "Configure one-shot model and thinking choices first.",
|
|
228
|
+
to: "fresh"
|
|
229
|
+
},
|
|
230
|
+
{ id: "export", label: "Export plan\u2026", to: "export" },
|
|
231
|
+
{ id: "save", label: "Save for later", action: "save" },
|
|
232
|
+
{ id: "stay", label: "Stay in Plan mode", action: "stay" },
|
|
233
|
+
{ id: "exit", label: "Discard plan and exit", action: "exit" }
|
|
234
|
+
],
|
|
235
|
+
hint: "close"
|
|
236
|
+
}),
|
|
237
|
+
fresh: freshFlow.settingsScreen,
|
|
238
|
+
models: freshFlow.modelScreen,
|
|
239
|
+
thinking: freshFlow.thinkingScreen,
|
|
240
|
+
export: () => planExportInputScreen(options.getExportDestination)
|
|
241
|
+
},
|
|
242
|
+
actions: {
|
|
243
|
+
"implement-here": async () => {
|
|
244
|
+
await options.implementHere();
|
|
245
|
+
return { kind: "close" };
|
|
246
|
+
},
|
|
247
|
+
"select-model": async ({ itemId }) => {
|
|
248
|
+
freshFlow.selectModel(itemId);
|
|
249
|
+
return { kind: "back" };
|
|
250
|
+
},
|
|
251
|
+
"select-thinking": async ({ itemId }) => {
|
|
252
|
+
freshFlow.selectThinking(itemId);
|
|
253
|
+
return { kind: "back" };
|
|
254
|
+
},
|
|
255
|
+
"start-fresh": async ({ signal }) => {
|
|
256
|
+
await freshFlow.start(signal);
|
|
257
|
+
return { kind: "close" };
|
|
258
|
+
},
|
|
259
|
+
export: async ({ value, signal }) => await options.exportPlan(value ?? "", signal) ? { kind: "close" } : { kind: "rejected" },
|
|
260
|
+
save: async () => {
|
|
261
|
+
options.save();
|
|
262
|
+
return { kind: "close" };
|
|
263
|
+
},
|
|
264
|
+
stay: async () => {
|
|
265
|
+
options.stay();
|
|
266
|
+
return { kind: "close" };
|
|
267
|
+
},
|
|
268
|
+
exit: async () => {
|
|
269
|
+
options.exit();
|
|
270
|
+
return { kind: "close" };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
await runMenu2(ctx, menu, {
|
|
275
|
+
getState: () => void 0,
|
|
276
|
+
signal: options.signal,
|
|
277
|
+
isCurrent: options.isCurrent
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function createFreshImplementationFlow(ctx, planThinkingLevel, implementationDefaults, implementFresh) {
|
|
281
|
+
const models = snapshotAvailableModels(ctx);
|
|
282
|
+
const planModel = ctx.model ? { provider: ctx.model.provider, modelId: ctx.model.id } : void 0;
|
|
283
|
+
const planModelSummary = ctx.model ? `${safeModelMetadata(ctx.model.id, "unknown model")} [${safeModelMetadata(ctx.model.provider, "unknown provider")}]` : void 0;
|
|
284
|
+
const configuredModel = implementationDefaults?.model;
|
|
285
|
+
const configuredAvailableModel = findAvailableImplementationModel(
|
|
286
|
+
models.map((choice) => choice.modelInfo),
|
|
287
|
+
configuredModel
|
|
288
|
+
);
|
|
289
|
+
let unavailableDefaultActive = configuredModel !== void 0 && !configuredAvailableModel;
|
|
290
|
+
let selectedModel = configuredAvailableModel ? models.find((choice) => choice.modelInfo === configuredAvailableModel) : void 0;
|
|
291
|
+
let selectedModelUsesDefault = selectedModel !== void 0;
|
|
292
|
+
let selectedThinkingLevel = implementationDefaults?.thinkingLevel;
|
|
293
|
+
return {
|
|
294
|
+
settingsScreen: () => ({
|
|
295
|
+
kind: "actions",
|
|
296
|
+
title: "Fresh implementation settings",
|
|
297
|
+
lines: [
|
|
298
|
+
"These choices apply once to the new implementation session.",
|
|
299
|
+
...unavailableDefaultActive && configuredModel ? [
|
|
300
|
+
`Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`
|
|
301
|
+
] : []
|
|
302
|
+
],
|
|
303
|
+
items: [
|
|
304
|
+
{
|
|
305
|
+
id: "start-fresh",
|
|
306
|
+
label: "Start fresh implementation",
|
|
307
|
+
description: "Create the linked session and begin implementation.",
|
|
308
|
+
action: "start-fresh",
|
|
309
|
+
busyLabel: "Starting fresh implementation session\u2026"
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
id: "implementation-model",
|
|
313
|
+
label: "Model",
|
|
314
|
+
description: selectedModel?.summary ?? (planModelSummary ? `${planModelSummary} \xB7 same as plan` : "Same as plan"),
|
|
315
|
+
to: "models"
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
id: "implementation-thinking",
|
|
319
|
+
label: "Thinking level",
|
|
320
|
+
description: selectedThinkingLevel ?? (planThinkingLevel ? `${planThinkingLevel} \xB7 same as plan` : "Same as plan"),
|
|
321
|
+
to: "thinking"
|
|
322
|
+
}
|
|
323
|
+
]
|
|
324
|
+
}),
|
|
325
|
+
modelScreen: () => ({
|
|
326
|
+
kind: "choice",
|
|
327
|
+
title: "Implementation model",
|
|
328
|
+
items: [
|
|
329
|
+
{
|
|
330
|
+
id: "same-as-plan",
|
|
331
|
+
label: "Same as plan",
|
|
332
|
+
...planModelSummary ? { description: planModelSummary } : {}
|
|
333
|
+
},
|
|
334
|
+
...models.map((choice) => ({
|
|
335
|
+
id: choice.itemId,
|
|
336
|
+
label: choice.label,
|
|
337
|
+
details: choice.details,
|
|
338
|
+
searchText: choice.searchText
|
|
339
|
+
}))
|
|
340
|
+
],
|
|
341
|
+
action: "select-model",
|
|
342
|
+
initialItemId: selectedModel?.itemId ?? "same-as-plan",
|
|
343
|
+
enableSearch: true,
|
|
344
|
+
viewportSize: 10
|
|
345
|
+
}),
|
|
346
|
+
thinkingScreen: () => ({
|
|
347
|
+
kind: "choice",
|
|
348
|
+
title: "Implementation thinking level",
|
|
349
|
+
items: [
|
|
350
|
+
{
|
|
351
|
+
id: "same-as-plan",
|
|
352
|
+
label: "Same as plan"
|
|
353
|
+
},
|
|
354
|
+
...IMPLEMENTATION_THINKING_LEVELS.map((level) => ({
|
|
355
|
+
id: level,
|
|
356
|
+
label: `${level === planThinkingLevel ? "\u2713 " : ""}${level}`,
|
|
357
|
+
description: THINKING_LEVEL_DESCRIPTIONS[level]
|
|
358
|
+
}))
|
|
359
|
+
],
|
|
360
|
+
action: "select-thinking",
|
|
361
|
+
initialItemId: selectedThinkingLevel ?? "same-as-plan",
|
|
362
|
+
viewportSize: IMPLEMENTATION_THINKING_LEVELS.length + 1
|
|
363
|
+
}),
|
|
364
|
+
selectModel(itemId) {
|
|
365
|
+
const choice = models.find((candidate) => candidate.itemId === itemId);
|
|
366
|
+
selectedModel = itemId === "same-as-plan" || choice?.isPlanModel ? void 0 : choice;
|
|
367
|
+
selectedModelUsesDefault = false;
|
|
368
|
+
unavailableDefaultActive = false;
|
|
369
|
+
},
|
|
370
|
+
selectThinking(itemId) {
|
|
371
|
+
selectedThinkingLevel = IMPLEMENTATION_THINKING_LEVELS.find((level) => level === itemId);
|
|
372
|
+
},
|
|
373
|
+
start(signal) {
|
|
374
|
+
if (selectedModelUsesDefault && selectedModel && !findAvailableImplementationModel(
|
|
375
|
+
snapshotAvailableImplementationModels(ctx),
|
|
376
|
+
selectedModel.model
|
|
377
|
+
)) {
|
|
378
|
+
selectedModel = void 0;
|
|
379
|
+
selectedModelUsesDefault = false;
|
|
380
|
+
unavailableDefaultActive = true;
|
|
381
|
+
ctx.ui.notify(
|
|
382
|
+
`Configured default ${safeModelReference(configuredModel)} is unavailable; using same as plan.`,
|
|
383
|
+
"warning"
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
const model = selectedModel?.model ?? planModel;
|
|
387
|
+
const thinkingLevel = selectedThinkingLevel ?? planThinkingLevel;
|
|
388
|
+
return implementFresh(
|
|
389
|
+
{
|
|
390
|
+
...model ? { model: { ...model } } : {},
|
|
391
|
+
...thinkingLevel ? { thinkingLevel } : {}
|
|
392
|
+
},
|
|
393
|
+
signal
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function snapshotAvailableModels(ctx) {
|
|
399
|
+
return snapshotAvailableImplementationModels(ctx).map((model, index) => {
|
|
400
|
+
const provider = safeModelMetadata(model.provider, "unknown provider");
|
|
401
|
+
const modelId = safeModelMetadata(model.id, "unknown model");
|
|
402
|
+
const name = safeModelMetadata(model.name, "");
|
|
403
|
+
const isPlanModel = ctx.model?.provider === model.provider && ctx.model.id === model.id;
|
|
404
|
+
const summary = `${modelId} [${provider}]`;
|
|
405
|
+
return {
|
|
406
|
+
itemId: `model-${index}`,
|
|
407
|
+
model: { provider: model.provider, modelId: model.id },
|
|
408
|
+
modelInfo: model,
|
|
409
|
+
label: `${isPlanModel ? "\u2713 " : ""}${summary}${isPlanModel ? " \xB7 default" : ""}`,
|
|
410
|
+
summary,
|
|
411
|
+
...name ? { details: [`Model Name: ${name}`] } : {},
|
|
412
|
+
searchText: [provider, modelId, name].filter(Boolean).join(" "),
|
|
413
|
+
isPlanModel
|
|
414
|
+
};
|
|
415
|
+
}).sort((left, right) => Number(right.isPlanModel) - Number(left.isPlanModel));
|
|
416
|
+
}
|
|
417
|
+
function safeModelReference(model) {
|
|
418
|
+
if (!model) return "configured model";
|
|
419
|
+
return `${safeModelMetadata(model.modelId, "unknown model")} [${safeModelMetadata(model.provider, "unknown provider")}]`;
|
|
420
|
+
}
|
|
421
|
+
function safeModelMetadata(value, fallback) {
|
|
422
|
+
if (typeof value !== "string") return fallback;
|
|
423
|
+
const safe = sanitizeTerminalText(value).trim() || fallback;
|
|
424
|
+
return [...safe].slice(0, 512).join("");
|
|
425
|
+
}
|
|
296
426
|
|
|
297
427
|
// src/plan-launch-menu.ts
|
|
298
428
|
import { defineMenu as defineMenu3, runMenu as runMenu3 } from "@narumitw/pi-tui-kit";
|
|
@@ -408,11 +538,9 @@ async function showSavedPlanMenu(ctx, options) {
|
|
|
408
538
|
`${options.statusText} Use /plan show, /plan implement, /plan export, or /plan exit.`
|
|
409
539
|
);
|
|
410
540
|
}
|
|
411
|
-
const implementation = createImplementationOptions(ctx, options.implementationPreferences);
|
|
412
541
|
const menu = defineMenu4({
|
|
413
542
|
start: "saved",
|
|
414
543
|
screens: {
|
|
415
|
-
...implementation.screens,
|
|
416
544
|
saved: () => ({
|
|
417
545
|
kind: "actions",
|
|
418
546
|
title: "Saved plan",
|
|
@@ -420,8 +548,7 @@ async function showSavedPlanMenu(ctx, options) {
|
|
|
420
548
|
options.statusText,
|
|
421
549
|
"Implement here keeps this planning conversation.",
|
|
422
550
|
"Start fresh transfers only the approved plan to a new session.",
|
|
423
|
-
options.implementationOutcome()
|
|
424
|
-
implementation.summary()
|
|
551
|
+
options.implementationOutcome()
|
|
425
552
|
],
|
|
426
553
|
items: [
|
|
427
554
|
{ id: "show", label: "Show saved plan", action: "show" },
|
|
@@ -438,11 +565,6 @@ async function showSavedPlanMenu(ctx, options) {
|
|
|
438
565
|
action: "implement-fresh",
|
|
439
566
|
busyLabel: "Starting fresh implementation session\u2026"
|
|
440
567
|
},
|
|
441
|
-
{
|
|
442
|
-
id: "implementation-options",
|
|
443
|
-
label: "Implementation options\u2026",
|
|
444
|
-
to: "implementation-options"
|
|
445
|
-
},
|
|
446
568
|
{ id: "export", label: "Export plan\u2026", to: "export" },
|
|
447
569
|
{ id: "settings", label: "Settings", action: "settings" },
|
|
448
570
|
{ id: "clear", label: "Clear saved plan", action: "clear" }
|
|
@@ -452,17 +574,16 @@ async function showSavedPlanMenu(ctx, options) {
|
|
|
452
574
|
export: () => planExportInputScreen(options.getExportDestination)
|
|
453
575
|
},
|
|
454
576
|
actions: {
|
|
455
|
-
...implementation.actions,
|
|
456
577
|
show: async () => {
|
|
457
578
|
options.show();
|
|
458
579
|
return { kind: "close" };
|
|
459
580
|
},
|
|
460
|
-
"implement-here": async (
|
|
461
|
-
await options.implementHere(
|
|
581
|
+
"implement-here": async () => {
|
|
582
|
+
await options.implementHere();
|
|
462
583
|
return { kind: "close" };
|
|
463
584
|
},
|
|
464
585
|
"implement-fresh": async ({ signal }) => {
|
|
465
|
-
await options.implementFresh(signal
|
|
586
|
+
await options.implementFresh(signal);
|
|
466
587
|
return { kind: "close" };
|
|
467
588
|
},
|
|
468
589
|
export: async ({ value, signal }) => await options.exportPlan(value ?? "", signal) ? { kind: "close" } : { kind: "rejected" },
|
|
@@ -485,7 +606,11 @@ async function showSavedPlanMenu(ctx, options) {
|
|
|
485
606
|
}
|
|
486
607
|
|
|
487
608
|
// src/settings-menu.ts
|
|
488
|
-
import {
|
|
609
|
+
import {
|
|
610
|
+
defineMenu as defineMenu5,
|
|
611
|
+
runMenu as runMenu5,
|
|
612
|
+
sanitizeTerminalText as sanitizeTerminalText2
|
|
613
|
+
} from "@narumitw/pi-tui-kit";
|
|
489
614
|
async function showPlanModeSettings(ctx, options) {
|
|
490
615
|
const settingsPath = options.settingsPath ?? planModeSettingsPath();
|
|
491
616
|
const readSettings = options.readSettings ?? readPlanModeSettings;
|
|
@@ -500,6 +625,13 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
500
625
|
tools.map((tool, index) => [tool.name, `plan-settings-tool:${index}`])
|
|
501
626
|
);
|
|
502
627
|
const toolsByItemId = new Map(tools.map((tool) => [toolItemIds.get(tool.name), tool]));
|
|
628
|
+
const implementationModels = snapshotAvailableImplementationModels(ctx);
|
|
629
|
+
const modelItemIds = new Map(
|
|
630
|
+
implementationModels.map((model, index) => [model, `plan-settings-model:${index}`])
|
|
631
|
+
);
|
|
632
|
+
const modelsByItemId = new Map(
|
|
633
|
+
implementationModels.map((model) => [modelItemIds.get(model), model])
|
|
634
|
+
);
|
|
503
635
|
const loadState = async () => {
|
|
504
636
|
const loaded = await readSettings(options.settingsPath);
|
|
505
637
|
if (loaded.kind === "invalid") {
|
|
@@ -516,7 +648,6 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
516
648
|
notice: loaded.notice
|
|
517
649
|
};
|
|
518
650
|
};
|
|
519
|
-
let implementationPicker;
|
|
520
651
|
const menu = defineMenu5({
|
|
521
652
|
start: "settings",
|
|
522
653
|
screens: {
|
|
@@ -550,6 +681,21 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
550
681
|
values: IMPLEMENTATION_PLAN_RETENTIONS.map(retentionLabel),
|
|
551
682
|
action: "set-retention"
|
|
552
683
|
},
|
|
684
|
+
{
|
|
685
|
+
id: "defaultImplementationModel",
|
|
686
|
+
label: "Fresh model",
|
|
687
|
+
description: "Choose the default model for a fresh implementation session.",
|
|
688
|
+
currentValue: implementationModelValue(state.settings, implementationModels),
|
|
689
|
+
action: "open-implementation-model"
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
id: "defaultImplementationThinkingLevel",
|
|
693
|
+
label: "Fresh thinking",
|
|
694
|
+
description: "Choose the default thinking level for a fresh implementation session.",
|
|
695
|
+
currentValue: configuredImplementationThinkingLevel(state.settings) ?? "same as plan",
|
|
696
|
+
values: ["same as plan", ...IMPLEMENTATION_THINKING_LEVELS],
|
|
697
|
+
action: "set-implementation-thinking"
|
|
698
|
+
},
|
|
553
699
|
{
|
|
554
700
|
id: "defaultPlanExportPath",
|
|
555
701
|
label: "Export destination",
|
|
@@ -563,14 +709,9 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
563
709
|
description: "Set the global shortcut used to toggle Plan mode.",
|
|
564
710
|
currentValue: configuredPlanModeToggleShortcut(state.settings) ?? "none",
|
|
565
711
|
action: "open-shortcut"
|
|
566
|
-
}
|
|
567
|
-
...implementationSettingItems(state.settings)
|
|
712
|
+
}
|
|
568
713
|
]
|
|
569
714
|
},
|
|
570
|
-
"implementation-model": ({ state }) => {
|
|
571
|
-
implementationPicker ??= createImplementationModelPicker(ctx);
|
|
572
|
-
return implementationPicker.screen(state.settings);
|
|
573
|
-
},
|
|
574
715
|
tools: ({ state }) => ({
|
|
575
716
|
kind: "multiSelect",
|
|
576
717
|
title: "Default Plan policy allowlist",
|
|
@@ -597,6 +738,21 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
597
738
|
],
|
|
598
739
|
hint: "back"
|
|
599
740
|
}),
|
|
741
|
+
"implementation-model": ({ state }) => ({
|
|
742
|
+
kind: "choice",
|
|
743
|
+
title: "Fresh implementation model",
|
|
744
|
+
lines: ["Same as plan is the default and fallback when a configured model is unavailable."],
|
|
745
|
+
items: implementationModelItems(implementationModels, modelItemIds),
|
|
746
|
+
action: "set-implementation-model",
|
|
747
|
+
initialItemId: implementationModelItemId(
|
|
748
|
+
configuredImplementationModel(state.settings),
|
|
749
|
+
implementationModels,
|
|
750
|
+
modelItemIds
|
|
751
|
+
),
|
|
752
|
+
enableSearch: true,
|
|
753
|
+
viewportSize: 10,
|
|
754
|
+
hint: "back"
|
|
755
|
+
}),
|
|
600
756
|
export: ({ state }) => {
|
|
601
757
|
const configured = configuredPlanExportPath(state.settings);
|
|
602
758
|
const destination = planExportDestination(configured, ctx.cwd);
|
|
@@ -628,28 +784,6 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
628
784
|
})
|
|
629
785
|
},
|
|
630
786
|
actions: {
|
|
631
|
-
"open-implementation-model": async () => ({ kind: "to", screen: "implementation-model" }),
|
|
632
|
-
"set-implementation-model": async ({ ctx: actionCtx, itemId, signal }) => {
|
|
633
|
-
const model = implementationPicker?.selection(itemId);
|
|
634
|
-
if (model === void 0) return { kind: "rejected" };
|
|
635
|
-
const result = await savePatch(
|
|
636
|
-
actionCtx,
|
|
637
|
-
{ implementationModel: model },
|
|
638
|
-
signal,
|
|
639
|
-
"Implementation model saved. Applies when implementation starts."
|
|
640
|
-
);
|
|
641
|
-
return result.kind === "stay" ? { kind: "back" } : result;
|
|
642
|
-
},
|
|
643
|
-
"set-implementation-thinking": async ({ ctx: actionCtx, value, signal }) => {
|
|
644
|
-
const level = PLAN_MODE_THINKING_LEVELS.find((level2) => level2 === value);
|
|
645
|
-
if (!level) return { kind: "rejected" };
|
|
646
|
-
return savePatch(
|
|
647
|
-
actionCtx,
|
|
648
|
-
{ implementationThinkingLevel: level },
|
|
649
|
-
signal,
|
|
650
|
-
"Implementation thinking saved. Applies when implementation starts."
|
|
651
|
-
);
|
|
652
|
-
},
|
|
653
787
|
"set-thinking": async ({ ctx: actionCtx, value, signal }) => {
|
|
654
788
|
if (!PLAN_MODE_THINKING_LEVELS.includes(value)) {
|
|
655
789
|
return { kind: "rejected" };
|
|
@@ -672,6 +806,45 @@ async function showPlanModeSettings(ctx, options) {
|
|
|
672
806
|
`Plan reinjection: ${retentionLabel(implementationPlanRetention)}. Applies to the next Implement action.`
|
|
673
807
|
);
|
|
674
808
|
},
|
|
809
|
+
"open-implementation-model": async () => ({
|
|
810
|
+
kind: "to",
|
|
811
|
+
screen: "implementation-model"
|
|
812
|
+
}),
|
|
813
|
+
"set-implementation-model": async ({ ctx: actionCtx, itemId, signal }) => {
|
|
814
|
+
const model = itemId ? modelsByItemId.get(itemId) : void 0;
|
|
815
|
+
if (itemId !== "same-as-plan" && !model) return { kind: "rejected" };
|
|
816
|
+
const defaultImplementationModel = model ? { provider: model.provider, modelId: model.id } : null;
|
|
817
|
+
const result = await savePatch(
|
|
818
|
+
actionCtx,
|
|
819
|
+
{ defaultImplementationModel },
|
|
820
|
+
signal,
|
|
821
|
+
model ? `Fresh implementation model: ${safeModelReference2({ provider: model.provider, modelId: model.id })}.` : "Fresh implementation model: same as plan."
|
|
822
|
+
);
|
|
823
|
+
return result.kind === "stay" ? { kind: "to", screen: "settings" } : result;
|
|
824
|
+
},
|
|
825
|
+
"set-implementation-thinking": async ({ ctx: actionCtx, value, signal }) => {
|
|
826
|
+
if (value === "same as plan") {
|
|
827
|
+
return savePatch(
|
|
828
|
+
actionCtx,
|
|
829
|
+
{ defaultImplementationThinkingLevel: null },
|
|
830
|
+
signal,
|
|
831
|
+
"Fresh implementation thinking: same as plan."
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
if (!IMPLEMENTATION_THINKING_LEVELS.includes(
|
|
835
|
+
value
|
|
836
|
+
)) {
|
|
837
|
+
return { kind: "rejected" };
|
|
838
|
+
}
|
|
839
|
+
return savePatch(
|
|
840
|
+
actionCtx,
|
|
841
|
+
{
|
|
842
|
+
defaultImplementationThinkingLevel: value
|
|
843
|
+
},
|
|
844
|
+
signal,
|
|
845
|
+
`Fresh implementation thinking: ${value}.`
|
|
846
|
+
);
|
|
847
|
+
},
|
|
675
848
|
"open-export": async () => ({ kind: "to", screen: "export" }),
|
|
676
849
|
"set-export": async ({ ctx: actionCtx, value, signal }) => {
|
|
677
850
|
const defaultPlanExportPath = value?.trim() || null;
|
|
@@ -777,6 +950,42 @@ function invalidScreen(settingsPath, state) {
|
|
|
777
950
|
function retentionFromLabel(value) {
|
|
778
951
|
return IMPLEMENTATION_PLAN_RETENTIONS.find((retention) => retentionLabel(retention) === value);
|
|
779
952
|
}
|
|
953
|
+
function implementationModelValue(settings, models) {
|
|
954
|
+
const configured = configuredImplementationModel(settings);
|
|
955
|
+
if (!configured) return "same as plan";
|
|
956
|
+
return findAvailableImplementationModel(models, configured) ? safeModelReference2(configured) : `same as plan \xB7 ${safeModelReference2(configured)} unavailable`;
|
|
957
|
+
}
|
|
958
|
+
function implementationModelItems(models, itemIds) {
|
|
959
|
+
return [
|
|
960
|
+
{
|
|
961
|
+
id: "same-as-plan",
|
|
962
|
+
label: "Same as plan",
|
|
963
|
+
description: "Use the planning session model."
|
|
964
|
+
},
|
|
965
|
+
...models.map((model) => {
|
|
966
|
+
const reference = safeModelReference2({ provider: model.provider, modelId: model.id });
|
|
967
|
+
const name = safeModelMetadata2(model.name, "");
|
|
968
|
+
return {
|
|
969
|
+
id: itemIds.get(model),
|
|
970
|
+
label: reference,
|
|
971
|
+
...name ? { details: [`Model Name: ${name}`] } : {},
|
|
972
|
+
searchText: [reference, name].filter(Boolean).join(" ")
|
|
973
|
+
};
|
|
974
|
+
})
|
|
975
|
+
];
|
|
976
|
+
}
|
|
977
|
+
function implementationModelItemId(configured, models, itemIds) {
|
|
978
|
+
const model = findAvailableImplementationModel(models, configured);
|
|
979
|
+
return model ? itemIds.get(model) : "same-as-plan";
|
|
980
|
+
}
|
|
981
|
+
function safeModelReference2(model) {
|
|
982
|
+
return `${safeModelMetadata2(model.modelId, "unknown model")} [${safeModelMetadata2(model.provider, "unknown provider")}]`;
|
|
983
|
+
}
|
|
984
|
+
function safeModelMetadata2(value, fallback) {
|
|
985
|
+
if (typeof value !== "string") return fallback;
|
|
986
|
+
const safe = sanitizeTerminalText2(value).trim() || fallback;
|
|
987
|
+
return [...safe].slice(0, 512).join("");
|
|
988
|
+
}
|
|
780
989
|
function defaultToolsValue(configured) {
|
|
781
990
|
if (configured === void 0) return "Automatic safe built-ins";
|
|
782
991
|
if (configured.length === 0) return "No optional tools";
|
|
@@ -839,4 +1048,4 @@ export {
|
|
|
839
1048
|
showReadyPlanMenu,
|
|
840
1049
|
showSavedPlanMenu
|
|
841
1050
|
};
|
|
842
|
-
//# sourceMappingURL=interactive-ui-
|
|
1051
|
+
//# sourceMappingURL=interactive-ui-UNJGC2RQ.js.map
|