@narumitw/pi-plan-mode 0.57.1 → 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 -4
- package/dist/chunks/{chunk-57OBPS7P.js → chunk-QHHHBTDO.js} +170 -83
- package/dist/chunks/chunk-QHHHBTDO.js.map +7 -0
- package/dist/chunks/{interactive-ui-N2ZKBVNE.js → interactive-ui-UNJGC2RQ.js} +322 -14
- package/dist/chunks/interactive-ui-UNJGC2RQ.js.map +7 -0
- package/dist/index.ts +667 -152
- package/dist/index.ts.map +4 -4
- package/docs/settings.md +26 -2
- package/package.json +1 -1
- package/src/command.ts +1 -0
- package/src/fresh-handoff-coordinator.ts +55 -0
- package/src/fresh-implementation.ts +153 -29
- package/src/implementation-models.ts +48 -0
- package/src/plan-action-controller.ts +78 -7
- package/src/plan-action-menus.ts +272 -17
- package/src/plan-mode.ts +454 -21
- package/src/settings-menu.ts +157 -2
- package/src/settings.ts +81 -1
- package/src/state.ts +62 -0
- package/dist/chunks/chunk-57OBPS7P.js.map +0 -7
- package/dist/chunks/interactive-ui-N2ZKBVNE.js.map +0 -7
package/docs/settings.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
- [Default Plan policy tools](#default-plan-policy-tools)
|
|
6
6
|
- [Plan reinjection](#plan-reinjection)
|
|
7
|
+
- [Fresh implementation runtime](#fresh-implementation-runtime)
|
|
7
8
|
- [Export destination](#export-destination)
|
|
8
9
|
- [Toggle shortcut](#toggle-shortcut)
|
|
9
10
|
- [Safe shell subcommands](#safe-shell-subcommands)
|
|
@@ -11,7 +12,7 @@
|
|
|
11
12
|
|
|
12
13
|
## ⚙️ Settings
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
Run `/plan settings` or open **Settings** from an inactive `/plan` menu to edit **Plan thinking**, **Plan policy tools**, **Plan reinjection**, **Fresh model**, **Fresh thinking**, **Export destination**, and **Plan mode shortcut**.
|
|
15
16
|
You can also edit `$PI_CODING_AGENT_DIR/pi-plan-mode.json` (normally `~/.pi/agent/pi-plan-mode.json`) manually.
|
|
16
17
|
`safeSubcommands` is JSON-only.
|
|
17
18
|
The optional file is read at session start, watched for changes, and created only by an explicit Settings save or manual edit.
|
|
@@ -21,6 +22,11 @@ The shortcut is disabled when `toggleShortcut` is omitted.
|
|
|
21
22
|
"thinkingLevel": "inherit",
|
|
22
23
|
"defaultPlanTools": ["read", "bash", "grep", "find", "ls"],
|
|
23
24
|
"implementationPlanRetention": "clear-on-start",
|
|
25
|
+
"defaultImplementationModel": {
|
|
26
|
+
"provider": "anthropic",
|
|
27
|
+
"modelId": "claude-sonnet-4-5"
|
|
28
|
+
},
|
|
29
|
+
"defaultImplementationThinkingLevel": "high",
|
|
24
30
|
"defaultPlanExportPath": "PLAN.md",
|
|
25
31
|
"safeSubcommands": {
|
|
26
32
|
"git": ["rev-parse", "blame"],
|
|
@@ -78,6 +84,24 @@ Changing this setting applies to the next Implement action only.
|
|
|
78
84
|
Each guaranteed-plan implementation stores its effective policy, so a later Settings save cannot shorten or extend an implementation already in progress.
|
|
79
85
|
Conversation-history-only implementation has no active Plan-mode state to show, export, or clear after kickoff.
|
|
80
86
|
|
|
87
|
+
### Fresh implementation runtime
|
|
88
|
+
|
|
89
|
+
Omit `defaultImplementationModel` and `defaultImplementationThinkingLevel` to use **same as plan**, the default.
|
|
90
|
+
A configured model is an object with non-empty `provider` and `modelId` strings of at most 512 characters each.
|
|
91
|
+
`defaultImplementationThinkingLevel` accepts `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max`; use omission rather than `inherit` for **same as plan**.
|
|
92
|
+
Choosing **Same as plan** in Settings removes the corresponding field.
|
|
93
|
+
|
|
94
|
+
The model picker snapshots the current session's scoped models when a non-empty scope exists, otherwise Pi's currently available models.
|
|
95
|
+
A configured model outside that catalogue remains stored but is ineffective for that handoff: Settings and the ready-plan fresh screen report that it is unavailable and fall back to the planning session model.
|
|
96
|
+
The preference becomes effective again if the model returns to the applicable catalogue.
|
|
97
|
+
This fallback also protects a persistent default that disappears while the ready-plan fresh screen is open.
|
|
98
|
+
Authentication and one-shot model races still use the normal fresh-handoff preflight and recovery behavior.
|
|
99
|
+
|
|
100
|
+
These persistent values seed each ready-plan **Start fresh and implement** screen, where either choice can be overridden once without changing Settings.
|
|
101
|
+
The saved-plan direct fresh action applies the persistent values without an extra picker and warns when its configured model falls back.
|
|
102
|
+
Changes save immediately and apply to later fresh implementation actions; an already open fresh-action screen keeps its own menu-local draft.
|
|
103
|
+
They never switch the planning session's current model or thinking level.
|
|
104
|
+
|
|
81
105
|
### Export destination
|
|
82
106
|
|
|
83
107
|
`defaultPlanExportPath` controls only exports that omit a path.
|
|
@@ -141,7 +165,7 @@ A missing file stays absent until an explicit save.
|
|
|
141
165
|
Invalid JSON, invalid values, oversized content, non-regular files, and read failures make Settings read-only; the existing bytes and previous effective settings remain.
|
|
142
166
|
This in-process queue is not a cross-process lock, so concurrent separate Pi processes can still race.
|
|
143
167
|
|
|
144
|
-
Invalid settings produce a warning and fall back to inherited thinking, available safe-built-in tool defaults, `clear-on-start`, and `PLAN.md`.
|
|
168
|
+
Invalid settings produce a warning and fall back to inherited Plan thinking, available safe-built-in tool defaults, `clear-on-start`, same-as-plan fresh runtime choices, and `PLAN.md`.
|
|
145
169
|
Compatibility: a valid legacy `plan-mode.json` remains readable with a warning and is never modified automatically.
|
|
146
170
|
If Settings is explicitly saved while only that legacy file exists, the extension creates canonical `pi-plan-mode.json` from the complete legacy document, applies the selected change, preserves unknown fields, and leaves the legacy file untouched.
|
|
147
171
|
If both files exist, the canonical filename takes precedence.
|
package/package.json
CHANGED
package/src/command.ts
CHANGED
|
@@ -10,6 +10,7 @@ const PLAN_COMMAND_COMPLETIONS: readonly CommandArgumentCompletion[] = [
|
|
|
10
10
|
{ value: "finalize", label: "finalize", description: "Request a completed plan" },
|
|
11
11
|
{ value: "implement", label: "implement", description: "Implement the completed or saved plan" },
|
|
12
12
|
{ value: "save", label: "save", description: "Save the completed plan for later" },
|
|
13
|
+
{ value: "settings", label: "settings", description: "Open Plan mode settings" },
|
|
13
14
|
{ value: "export", label: "export", description: "Export the stored plan to a Markdown file" },
|
|
14
15
|
{ value: "exit", label: "exit", description: "Leave Plan mode or clear a saved/active plan" },
|
|
15
16
|
{ value: "off", label: "off", description: "Leave Plan mode or clear a saved/active plan" },
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface DeferredFreshHandoffDependencies {
|
|
2
|
+
schedule(callback: () => void): unknown;
|
|
3
|
+
cancel(handle: unknown): void;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface DeferredFreshHandoffCoordinator {
|
|
7
|
+
schedule(
|
|
8
|
+
run: (isCurrent: () => boolean) => Promise<void>,
|
|
9
|
+
onError: (error: unknown) => void,
|
|
10
|
+
): void;
|
|
11
|
+
cancel(): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const defaultDependencies: DeferredFreshHandoffDependencies = {
|
|
15
|
+
schedule: (callback) => setTimeout(callback, 0),
|
|
16
|
+
cancel: (handle) => clearTimeout(handle as ReturnType<typeof setTimeout>),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function createDeferredFreshHandoffCoordinator(
|
|
20
|
+
dependencies: DeferredFreshHandoffDependencies = defaultDependencies,
|
|
21
|
+
): DeferredFreshHandoffCoordinator {
|
|
22
|
+
let generation = 0;
|
|
23
|
+
let pending: { generation: number; handle: unknown } | undefined;
|
|
24
|
+
|
|
25
|
+
const cancel = () => {
|
|
26
|
+
generation += 1;
|
|
27
|
+
if (!pending) return;
|
|
28
|
+
dependencies.cancel(pending.handle);
|
|
29
|
+
pending = undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
schedule(run, onError) {
|
|
34
|
+
cancel();
|
|
35
|
+
const taskGeneration = generation;
|
|
36
|
+
const handle = dependencies.schedule(() => {
|
|
37
|
+
if (pending?.generation !== taskGeneration || generation !== taskGeneration) return;
|
|
38
|
+
pending = undefined;
|
|
39
|
+
const isCurrent = () => generation === taskGeneration;
|
|
40
|
+
void Promise.resolve()
|
|
41
|
+
.then(() => run(isCurrent))
|
|
42
|
+
.catch((error: unknown) => {
|
|
43
|
+
if (!isCurrent()) return;
|
|
44
|
+
try {
|
|
45
|
+
onError(error);
|
|
46
|
+
} catch {
|
|
47
|
+
// Detached error reporting must not create another unhandled rejection.
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
pending = { generation: taskGeneration, handle };
|
|
52
|
+
},
|
|
53
|
+
cancel,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { stripVTControlCharacters } from "node:util";
|
|
2
3
|
import type { ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
4
|
import { PLAN_HISTORY_IMPLEMENTATION_PROMPT } from "./message-transform.js";
|
|
4
5
|
import { createModeContractMessage } from "./mode-contract.js";
|
|
5
6
|
import type { ImplementationPlanRetention } from "./settings.js";
|
|
6
|
-
import
|
|
7
|
+
import {
|
|
8
|
+
type ImplementationRuntimeSelection,
|
|
9
|
+
isPendingImplementationModelIdentifier,
|
|
10
|
+
MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH,
|
|
11
|
+
type PendingImplementationRuntime,
|
|
12
|
+
type PlanCompletionSource,
|
|
13
|
+
type PlanModeState,
|
|
14
|
+
restorePlanModeState,
|
|
15
|
+
} from "./state.js";
|
|
7
16
|
|
|
8
17
|
type NewSessionOptions = Exclude<Parameters<ExtensionCommandContext["newSession"]>[0], undefined>;
|
|
9
18
|
type ReplacementContext = Parameters<NonNullable<NewSessionOptions["withSession"]>>[0];
|
|
@@ -13,6 +22,7 @@ export interface FreshImplementationRequest {
|
|
|
13
22
|
source: PlanCompletionSource;
|
|
14
23
|
retention: ImplementationPlanRetention;
|
|
15
24
|
stateEntryType: string;
|
|
25
|
+
runtime?: ImplementationRuntimeSelection;
|
|
16
26
|
isCurrent(): boolean;
|
|
17
27
|
}
|
|
18
28
|
|
|
@@ -21,6 +31,7 @@ interface FreshImplementationFromStateOptions {
|
|
|
21
31
|
menuIsCurrent(): boolean;
|
|
22
32
|
retention: ImplementationPlanRetention;
|
|
23
33
|
stateEntryType: string;
|
|
34
|
+
runtime?: ImplementationRuntimeSelection;
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
export type FreshImplementationResult =
|
|
@@ -78,6 +89,7 @@ export async function startFreshImplementationFromState(
|
|
|
78
89
|
source,
|
|
79
90
|
retention: options.retention,
|
|
80
91
|
stateEntryType: options.stateEntryType,
|
|
92
|
+
runtime: options.runtime,
|
|
81
93
|
isCurrent,
|
|
82
94
|
});
|
|
83
95
|
}
|
|
@@ -92,23 +104,29 @@ export async function startFreshImplementationSession(
|
|
|
92
104
|
|
|
93
105
|
await ctx.waitForIdle();
|
|
94
106
|
if (!request.isCurrent()) return { kind: "stale" };
|
|
95
|
-
if (!(await preflightModel(ctx, request
|
|
107
|
+
if (!(await preflightModel(ctx, request))) return { kind: "rejected" };
|
|
96
108
|
if (!request.isCurrent()) return { kind: "stale" };
|
|
97
109
|
|
|
98
110
|
const usesConversationHistory = request.retention === "clear-on-start";
|
|
99
|
-
const
|
|
111
|
+
const pendingImplementationRuntime = pendingRuntimeIntent(request.runtime);
|
|
112
|
+
const activeImplementation = usesConversationHistory
|
|
100
113
|
? undefined
|
|
101
114
|
: {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
source: request.source,
|
|
108
|
-
startedAt: Date.now(),
|
|
109
|
-
retention: request.retention,
|
|
110
|
-
},
|
|
115
|
+
id: randomUUID(),
|
|
116
|
+
plan: request.plan,
|
|
117
|
+
source: request.source,
|
|
118
|
+
startedAt: Date.now(),
|
|
119
|
+
retention: request.retention,
|
|
111
120
|
};
|
|
121
|
+
const destinationState: PlanModeState | undefined =
|
|
122
|
+
activeImplementation || pendingImplementationRuntime
|
|
123
|
+
? {
|
|
124
|
+
enabled: false,
|
|
125
|
+
awaitingAction: false,
|
|
126
|
+
...(activeImplementation ? { activeImplementation } : {}),
|
|
127
|
+
...(pendingImplementationRuntime ? { pendingImplementationRuntime } : {}),
|
|
128
|
+
}
|
|
129
|
+
: undefined;
|
|
112
130
|
const handoff = usesConversationHistory
|
|
113
131
|
? formatTransferredPlanPrompt(request.plan, true)
|
|
114
132
|
: formatImplementationHandoff(request.plan);
|
|
@@ -143,23 +161,40 @@ export async function startFreshImplementationSession(
|
|
|
143
161
|
recoverSetupFailure(replacementCtx, handoff, setupError);
|
|
144
162
|
return;
|
|
145
163
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
} catch (error: unknown) {
|
|
149
|
-
kickoffError = safeErrorDetail(error);
|
|
164
|
+
const reportKickoffFailure = (detail: string) => {
|
|
165
|
+
kickoffError = detail;
|
|
150
166
|
const recoveredInEditor =
|
|
151
167
|
usesConversationHistory && safeSetEditorText(replacementCtx, handoff);
|
|
152
168
|
safeNotify(
|
|
153
169
|
replacementCtx,
|
|
154
170
|
usesConversationHistory
|
|
155
171
|
? recoveredInEditor
|
|
156
|
-
? `Fresh session created, but implementation did not start: ${
|
|
157
|
-
: `Fresh session created, but implementation did not start: ${
|
|
158
|
-
: `Fresh session created, but implementation did not start: ${
|
|
172
|
+
? `Fresh session created, but implementation did not start: ${detail}. The implementation request is in the editor; submit it or resume the parent planning session.`
|
|
173
|
+
: `Fresh session created, but implementation did not start: ${detail}. The implementation request could not be restored to the editor; resume the parent planning session.`
|
|
174
|
+
: `Fresh session created, but implementation did not start: ${detail}. Send a message to continue, use /plan exit to clear the active plan, or resume the parent planning session.`,
|
|
159
175
|
"error",
|
|
160
176
|
);
|
|
177
|
+
};
|
|
178
|
+
try {
|
|
179
|
+
await replacementCtx.sendUserMessage(handoff);
|
|
180
|
+
} catch (error: unknown) {
|
|
181
|
+
reportKickoffFailure(safeErrorDetail(error));
|
|
161
182
|
return;
|
|
162
183
|
}
|
|
184
|
+
if (pendingImplementationRuntime) {
|
|
185
|
+
const runtimeStatus = destinationRuntimeConsumptionStatus(
|
|
186
|
+
replacementCtx,
|
|
187
|
+
request.stateEntryType,
|
|
188
|
+
);
|
|
189
|
+
if (runtimeStatus !== "consumed") {
|
|
190
|
+
reportKickoffFailure(
|
|
191
|
+
runtimeStatus === "pending"
|
|
192
|
+
? "fresh implementation settings could not be consumed"
|
|
193
|
+
: "fresh implementation settings could not be verified as consumed",
|
|
194
|
+
);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
163
198
|
safeNotify(
|
|
164
199
|
replacementCtx,
|
|
165
200
|
"Fresh implementation session started. Only the approved plan was transferred.",
|
|
@@ -183,29 +218,113 @@ export async function startFreshImplementationSession(
|
|
|
183
218
|
return setupError || kickoffError ? { kind: "partial" } : { kind: "started" };
|
|
184
219
|
}
|
|
185
220
|
|
|
186
|
-
async function preflightModel(ctx: ExtensionCommandContext,
|
|
187
|
-
const
|
|
221
|
+
async function preflightModel(ctx: ExtensionCommandContext, request: FreshImplementationRequest) {
|
|
222
|
+
const requestedModel = request.runtime?.model;
|
|
223
|
+
let model = ctx.model;
|
|
224
|
+
if (requestedModel) {
|
|
225
|
+
if (
|
|
226
|
+
!isPendingImplementationModelIdentifier(requestedModel.provider) ||
|
|
227
|
+
!isPendingImplementationModelIdentifier(requestedModel.modelId)
|
|
228
|
+
) {
|
|
229
|
+
notifyCurrent(
|
|
230
|
+
ctx,
|
|
231
|
+
request,
|
|
232
|
+
`Unable to implement the plan: implementation model provider and ID must each contain 1-${MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH} characters. Choose another model and retry.`,
|
|
233
|
+
"warning",
|
|
234
|
+
);
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
const isCurrentModel =
|
|
238
|
+
ctx.model?.provider === requestedModel.provider && ctx.model.id === requestedModel.modelId;
|
|
239
|
+
if (!isCurrentModel) {
|
|
240
|
+
try {
|
|
241
|
+
model = ctx.modelRegistry.find(requestedModel.provider, requestedModel.modelId);
|
|
242
|
+
} catch (error: unknown) {
|
|
243
|
+
notifyCurrent(
|
|
244
|
+
ctx,
|
|
245
|
+
request,
|
|
246
|
+
`Unable to implement the plan: ${safeErrorDetail(error)}`,
|
|
247
|
+
"error",
|
|
248
|
+
);
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (!model) {
|
|
253
|
+
notifyCurrent(
|
|
254
|
+
ctx,
|
|
255
|
+
request,
|
|
256
|
+
`Unable to implement the plan: implementation model ${safeModelReference(requestedModel)} is no longer available. Choose another model and retry.`,
|
|
257
|
+
"warning",
|
|
258
|
+
);
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
188
262
|
if (!model) {
|
|
189
|
-
ctx
|
|
263
|
+
notifyCurrent(ctx, request, "Unable to implement the plan: no model is selected.", "warning");
|
|
190
264
|
return false;
|
|
191
265
|
}
|
|
192
266
|
let auth: Awaited<ReturnType<ExtensionCommandContext["modelRegistry"]["getApiKeyAndHeaders"]>>;
|
|
193
267
|
try {
|
|
194
268
|
auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
195
269
|
} catch (error: unknown) {
|
|
196
|
-
|
|
197
|
-
ctx.ui.notify(`Unable to implement the plan: ${safeErrorDetail(error)}`, "error");
|
|
198
|
-
}
|
|
270
|
+
notifyCurrent(ctx, request, `Unable to implement the plan: ${safeErrorDetail(error)}`, "error");
|
|
199
271
|
return false;
|
|
200
272
|
}
|
|
201
|
-
if (!isCurrent()) return false;
|
|
273
|
+
if (!request.isCurrent()) return false;
|
|
202
274
|
if (!auth.ok) {
|
|
203
|
-
|
|
275
|
+
notifyCurrent(
|
|
276
|
+
ctx,
|
|
277
|
+
request,
|
|
278
|
+
requestedModel
|
|
279
|
+
? `Unable to implement the plan with ${safeModelReference(model)}: ${safeErrorDetail(auth.error)}. Choose another model or configure authentication, then retry.`
|
|
280
|
+
: `Unable to implement the plan: ${safeErrorDetail(auth.error)}`,
|
|
281
|
+
"warning",
|
|
282
|
+
);
|
|
204
283
|
return false;
|
|
205
284
|
}
|
|
206
285
|
return true;
|
|
207
286
|
}
|
|
208
287
|
|
|
288
|
+
function notifyCurrent(
|
|
289
|
+
ctx: Pick<ExtensionContext, "ui">,
|
|
290
|
+
request: FreshImplementationRequest,
|
|
291
|
+
message: string,
|
|
292
|
+
level: "info" | "warning" | "error",
|
|
293
|
+
) {
|
|
294
|
+
if (request.isCurrent()) safeNotify(ctx, message, level);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function pendingRuntimeIntent(
|
|
298
|
+
selection: ImplementationRuntimeSelection | undefined,
|
|
299
|
+
): PendingImplementationRuntime | undefined {
|
|
300
|
+
if (!selection?.model && !selection?.thinkingLevel) return undefined;
|
|
301
|
+
return {
|
|
302
|
+
version: 1,
|
|
303
|
+
...(selection.model
|
|
304
|
+
? { model: { provider: selection.model.provider, modelId: selection.model.modelId } }
|
|
305
|
+
: {}),
|
|
306
|
+
...(selection.thinkingLevel ? { thinkingLevel: selection.thinkingLevel } : {}),
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function safeModelReference(model: { provider: string; id?: string; modelId?: string }) {
|
|
311
|
+
return safeErrorDetail(`${model.provider}/${model.modelId ?? model.id ?? "unknown"}`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function destinationRuntimeConsumptionStatus(
|
|
315
|
+
ctx: ReplacementContext,
|
|
316
|
+
stateEntryType: string,
|
|
317
|
+
): "consumed" | "pending" | "unavailable" {
|
|
318
|
+
try {
|
|
319
|
+
return restorePlanModeState(ctx.sessionManager.getBranch(), stateEntryType)
|
|
320
|
+
.pendingImplementationRuntime
|
|
321
|
+
? "pending"
|
|
322
|
+
: "consumed";
|
|
323
|
+
} catch {
|
|
324
|
+
return "unavailable";
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
209
328
|
function recoverSetupFailure(ctx: ReplacementContext, handoff: string, setupError: string) {
|
|
210
329
|
const recoveredInEditor = safeSetEditorText(ctx, handoff);
|
|
211
330
|
safeNotify(
|
|
@@ -246,10 +365,15 @@ function isCommandContext(ctx: ExtensionContext): ctx is ExtensionCommandContext
|
|
|
246
365
|
function safeErrorDetail(error: unknown) {
|
|
247
366
|
const detail = error instanceof Error ? error.message : String(error);
|
|
248
367
|
const normalized =
|
|
249
|
-
[...detail]
|
|
368
|
+
[...stripVTControlCharacters(detail)]
|
|
250
369
|
.map((character) => {
|
|
251
370
|
const codePoint = character.codePointAt(0) ?? 0;
|
|
252
|
-
return codePoint <= 0x1f ||
|
|
371
|
+
return codePoint <= 0x1f ||
|
|
372
|
+
(codePoint >= 0x7f && codePoint <= 0x9f) ||
|
|
373
|
+
(codePoint >= 0x202a && codePoint <= 0x202e) ||
|
|
374
|
+
(codePoint >= 0x2066 && codePoint <= 0x2069)
|
|
375
|
+
? " "
|
|
376
|
+
: character;
|
|
253
377
|
})
|
|
254
378
|
.join("")
|
|
255
379
|
.replace(/\s+/gu, " ")
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
export const MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH = 512;
|
|
4
|
+
|
|
5
|
+
export interface ImplementationModelOverride {
|
|
6
|
+
provider: string;
|
|
7
|
+
modelId: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface AvailableImplementationModel {
|
|
11
|
+
provider: string;
|
|
12
|
+
id: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isPendingImplementationModelIdentifier(value: unknown): value is string {
|
|
17
|
+
return (
|
|
18
|
+
typeof value === "string" &&
|
|
19
|
+
value.trim().length > 0 &&
|
|
20
|
+
value.length <= MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function snapshotAvailableImplementationModels(
|
|
25
|
+
ctx: ExtensionContext,
|
|
26
|
+
): AvailableImplementationModel[] {
|
|
27
|
+
const getAvailable = ctx.modelRegistry.getAvailable;
|
|
28
|
+
const availableModels =
|
|
29
|
+
typeof getAvailable === "function" ? getAvailable.call(ctx.modelRegistry) : [];
|
|
30
|
+
const scopedModels = ctx.scopedModels ?? [];
|
|
31
|
+
if (scopedModels.length === 0) return availableModels;
|
|
32
|
+
return scopedModels.flatMap((entry) => {
|
|
33
|
+
const availableModel = availableModels.find(
|
|
34
|
+
(model) => model.provider === entry.model.provider && model.id === entry.model.id,
|
|
35
|
+
);
|
|
36
|
+
return availableModel ? [availableModel] : [];
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function findAvailableImplementationModel(
|
|
41
|
+
models: readonly AvailableImplementationModel[],
|
|
42
|
+
configured: ImplementationModelOverride | undefined,
|
|
43
|
+
): AvailableImplementationModel | undefined {
|
|
44
|
+
if (!configured) return undefined;
|
|
45
|
+
return models.find(
|
|
46
|
+
(model) => model.provider === configured.provider && model.id === configured.modelId,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -1,6 +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
|
|
7
|
+
import {
|
|
8
|
+
configuredImplementationModel,
|
|
9
|
+
configuredImplementationThinkingLevel,
|
|
10
|
+
type PlanModeFixedThinkingLevel,
|
|
11
|
+
type PlanModeSettings,
|
|
12
|
+
} from "./settings.js";
|
|
13
|
+
import type { ImplementationRuntimeSelection, PlanModeState } from "./state.js";
|
|
4
14
|
|
|
5
15
|
type InteractiveUi = typeof import("./interactive-ui.js");
|
|
6
16
|
|
|
@@ -9,17 +19,26 @@ interface MenuLifecycle {
|
|
|
9
19
|
isCurrent(): boolean;
|
|
10
20
|
}
|
|
11
21
|
|
|
22
|
+
export type FreshImplementationTiming = "immediate" | "after-settled";
|
|
23
|
+
|
|
12
24
|
interface PlanActionControllerOptions {
|
|
13
25
|
loadInteractiveUi(): Promise<InteractiveUi>;
|
|
14
26
|
getState(): PlanModeState;
|
|
15
27
|
captureLifecycle(): MenuLifecycle;
|
|
16
28
|
statusText(): string;
|
|
29
|
+
getThinkingLevel(): PlanModeFixedThinkingLevel | undefined;
|
|
30
|
+
getSettings(): PlanModeSettings;
|
|
17
31
|
implementationOutcome(): string;
|
|
18
32
|
getExportDestination(ctx: ExtensionContext): PlanExportDestination;
|
|
19
33
|
show(ctx: ExtensionContext): void;
|
|
20
34
|
finalize(ctx: ExtensionContext): void;
|
|
21
35
|
implementHere(ctx: ExtensionContext): void | Promise<void>;
|
|
22
|
-
implementFresh(
|
|
36
|
+
implementFresh(
|
|
37
|
+
ctx: ExtensionContext,
|
|
38
|
+
isCurrent: () => boolean,
|
|
39
|
+
runtime: ImplementationRuntimeSelection | undefined,
|
|
40
|
+
timing: FreshImplementationTiming,
|
|
41
|
+
): void | Promise<void>;
|
|
23
42
|
exportPlan(
|
|
24
43
|
ctx: ExtensionContext,
|
|
25
44
|
path: string,
|
|
@@ -34,8 +53,53 @@ interface PlanActionControllerOptions {
|
|
|
34
53
|
}
|
|
35
54
|
|
|
36
55
|
export function createPlanActionController(options: PlanActionControllerOptions) {
|
|
37
|
-
const
|
|
38
|
-
|
|
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
|
+
};
|
|
39
103
|
|
|
40
104
|
return {
|
|
41
105
|
async showSaved(ctx: ExtensionContext) {
|
|
@@ -51,7 +115,8 @@ export function createPlanActionController(options: PlanActionControllerOptions)
|
|
|
51
115
|
isCurrent: lifecycle.isCurrent,
|
|
52
116
|
show: () => options.show(ctx),
|
|
53
117
|
implementHere: () => options.implementHere(ctx),
|
|
54
|
-
implementFresh: (signal) =>
|
|
118
|
+
implementFresh: (signal) =>
|
|
119
|
+
freshAction(ctx, lifecycle, signal, effectiveDefaults(ctx), "immediate"),
|
|
55
120
|
exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
|
|
56
121
|
settings: (signal) => options.settings(ctx, signal, lifecycle.isCurrent),
|
|
57
122
|
clear: () => options.clearSaved(ctx),
|
|
@@ -68,6 +133,8 @@ export function createPlanActionController(options: PlanActionControllerOptions)
|
|
|
68
133
|
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
69
134
|
await ui.showPlanModeMenu(ctx, {
|
|
70
135
|
statusText: options.statusText(),
|
|
136
|
+
planThinkingLevel: options.getThinkingLevel(),
|
|
137
|
+
implementationDefaults: configuredDefaults(),
|
|
71
138
|
hasReadyPlan: options.getState().latestPlan !== undefined,
|
|
72
139
|
implementationOutcome: options.implementationOutcome,
|
|
73
140
|
getExportDestination: () => options.getExportDestination(ctx),
|
|
@@ -75,7 +142,8 @@ export function createPlanActionController(options: PlanActionControllerOptions)
|
|
|
75
142
|
show: () => options.show(ctx),
|
|
76
143
|
finalize: () => options.finalize(ctx),
|
|
77
144
|
implementHere: () => options.implementHere(ctx),
|
|
78
|
-
implementFresh: (signal) =>
|
|
145
|
+
implementFresh: (runtime, signal) =>
|
|
146
|
+
freshAction(ctx, lifecycle, signal, runtime, "immediate"),
|
|
79
147
|
exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
|
|
80
148
|
save: () => options.save(ctx),
|
|
81
149
|
stay: () => options.stay(ctx),
|
|
@@ -89,10 +157,13 @@ export function createPlanActionController(options: PlanActionControllerOptions)
|
|
|
89
157
|
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
90
158
|
await ui.showReadyPlanMenu(ctx, {
|
|
91
159
|
...lifecycle,
|
|
160
|
+
planThinkingLevel: options.getThinkingLevel(),
|
|
161
|
+
implementationDefaults: configuredDefaults(),
|
|
92
162
|
implementationOutcome: options.implementationOutcome,
|
|
93
163
|
getExportDestination: () => options.getExportDestination(ctx),
|
|
94
164
|
implementHere: () => options.implementHere(ctx),
|
|
95
|
-
implementFresh: (signal) =>
|
|
165
|
+
implementFresh: (runtime, signal) =>
|
|
166
|
+
freshAction(ctx, lifecycle, signal, runtime, "after-settled"),
|
|
96
167
|
exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
|
|
97
168
|
save: () => options.save(ctx),
|
|
98
169
|
stay: () => undefined,
|