@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
|
@@ -17,8 +17,7 @@ Persistent defaults belong in [Settings](./settings.md).
|
|
|
17
17
|
The TUI selector supports fuzzy search and paging; RPC shows the unfiltered list.
|
|
18
18
|
Blocked, inactive, or not-yet-registered tools remain distinguishable, and selected names awaiting metadata stay selected for first-request resolution.
|
|
19
19
|
Reopen the selector to refresh newly registered tools.
|
|
20
|
-
Active and ready workflows lock
|
|
21
|
-
Ready and saved plans expose **Implementation options…**, which stages model/thinking for that menu's implementation actions without changing the planner or saved defaults.
|
|
20
|
+
Active and ready workflows lock tools and settings; exit and start a new workflow to change the allowlist.
|
|
22
21
|
See [Planning and implementation](../README.md#-planning-and-implementation) for the first-request policy boundary, completion, and same-session versus fresh-session handoff.
|
|
23
22
|
|
|
24
23
|
## Busy transitions and recovery
|
|
@@ -29,9 +28,6 @@ An ordinary follow-up or `/plan finalize` can still run while Plan mode is activ
|
|
|
29
28
|
|
|
30
29
|
`show`, `save`, `export`, and `implement` require an applicable stored plan; `finalize` requires active Plan mode.
|
|
31
30
|
Cancellation and failed implementation preflight leave the stored plan intact.
|
|
32
|
-
`/plan implement` applies saved implementation preferences; menu actions additionally accept the current menu's draft overrides.
|
|
33
|
-
After kickoff, settlement, abort, and clearing an active plan do not restore model/thinking.
|
|
34
|
-
See [implementation preferences](./settings.md#implementation-model-and-thinking) for inheritance, provider-transfer effects, and partial fresh-session recovery.
|
|
35
31
|
For finalization retries, fresh-session recovery, and non-interactive limitations, see [Planning and implementation](../README.md#-planning-and-implementation).
|
|
36
32
|
|
|
37
33
|
## Export Markdown
|
package/docs/settings.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[Back to README](../README.md)
|
|
4
4
|
|
|
5
|
-
- [Implementation model and thinking](#implementation-model-and-thinking)
|
|
6
5
|
- [Default Plan policy tools](#default-plan-policy-tools)
|
|
7
6
|
- [Plan reinjection](#plan-reinjection)
|
|
7
|
+
- [Fresh implementation runtime](#fresh-implementation-runtime)
|
|
8
8
|
- [Export destination](#export-destination)
|
|
9
9
|
- [Toggle shortcut](#toggle-shortcut)
|
|
10
10
|
- [Safe shell subcommands](#safe-shell-subcommands)
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
## ⚙️ Settings
|
|
14
14
|
|
|
15
|
-
|
|
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**.
|
|
16
16
|
You can also edit `$PI_CODING_AGENT_DIR/pi-plan-mode.json` (normally `~/.pi/agent/pi-plan-mode.json`) manually.
|
|
17
17
|
`safeSubcommands` is JSON-only.
|
|
18
18
|
The optional file is read at session start, watched for changes, and created only by an explicit Settings save or manual edit.
|
|
@@ -22,6 +22,11 @@ The shortcut is disabled when `toggleShortcut` is omitted.
|
|
|
22
22
|
"thinkingLevel": "inherit",
|
|
23
23
|
"defaultPlanTools": ["read", "bash", "grep", "find", "ls"],
|
|
24
24
|
"implementationPlanRetention": "clear-on-start",
|
|
25
|
+
"defaultImplementationModel": {
|
|
26
|
+
"provider": "anthropic",
|
|
27
|
+
"modelId": "claude-sonnet-4-5"
|
|
28
|
+
},
|
|
29
|
+
"defaultImplementationThinkingLevel": "high",
|
|
25
30
|
"defaultPlanExportPath": "PLAN.md",
|
|
26
31
|
"safeSubcommands": {
|
|
27
32
|
"git": ["rev-parse", "blame"],
|
|
@@ -33,27 +38,6 @@ The shortcut is disabled when `toggleShortcut` is omitted.
|
|
|
33
38
|
}
|
|
34
39
|
```
|
|
35
40
|
|
|
36
|
-
### Implementation model and thinking
|
|
37
|
-
|
|
38
|
-
`implementationModel` is an optional object with exact, case-sensitive `provider` and `id` strings. Both must be non-blank and at most 4,096 characters; IDs are opaque, so slashes and colons are not parsed. Omit this field or choose **Use current** to make no model change. For fresh implementation, that means the destination's normal startup model, not a forced copy of the source model.
|
|
39
|
-
|
|
40
|
-
`implementationThinkingLevel` accepts `inherit` (the default), `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`. `inherit` preserves normal behavior: same-session handoff restores a temporary Plan thinking override when appropriate, a model switch uses Pi's model/default thinking policy, and a fresh session uses its normal startup thinking. It does not promise to retain the planner's temporary thinking level. Explicit implementation thinking applies after model selection; Pi clamps it to the target's supported levels, and Plan mode reports an adjustment.
|
|
41
|
-
|
|
42
|
-
```json
|
|
43
|
-
{
|
|
44
|
-
"implementationModel": { "provider": "openai", "id": "your-registered-model-id" },
|
|
45
|
-
"implementationThinkingLevel": "high"
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Settings saves immediately but does not switch the running session. Each implementation menu snapshots those defaults when opened. **Implementation options…** edits a draft shared by both implementation actions in that menu; backing out of a nested picker leaves its previous choice, while closing the owning menu discards all its overrides. Reopen `/plan` to use updated defaults. `/plan implement` uses current saved defaults without a selector. Precedence is built-in behavior, user defaults, then the current menu's override; **Use current** and `inherit` can explicitly override fixed defaults.
|
|
50
|
-
|
|
51
|
-
The model picker uses Pi's scoped models when configured, otherwise its available catalogue. It does not refresh providers or resolve auth merely to display choices; close and reopen the owning menu after refreshing Pi's catalogue. Display labels are sanitized without changing raw model identity. No registered match or failed authentication blocks an explicit target rather than silently selecting a fallback.
|
|
52
|
-
|
|
53
|
-
Before kickoff, failed or cancelled preparation retains the ready/saved plan. Same-session recovery restores only still-owned runtime changes and does not overwrite a later manual choice. Pi owns authentication and model-selection operations, which have no public cancellation signal; the extension waits for them to settle and rejects stale continuations. After a fresh replacement commits, a preference failure leaves the request in the destination editor instead of starting with a fallback. If kickoff then fails, the destination retains its selected model/thinking and existing editor or active-plan recovery; the source remains resumable. Reload/resume never replays a pending preference request.
|
|
54
|
-
|
|
55
|
-
After successful kickoff there is **no automatic restoration** on `agent_end`, `agent_settled`, user abort, or active-plan clearing. A settled run is not proof that the implementation task is complete. Later manual model/thinking changes are preserved. These preferences never write Pi's global model or thinking defaults, and existing plan-retention cleanup is unchanged.
|
|
56
|
-
|
|
57
41
|
### Plan helper tools
|
|
58
42
|
|
|
59
43
|
Plan helper schemas are stable from extension registration onward, and Plan mode does not call `setActiveTools()`.
|
|
@@ -100,6 +84,24 @@ Changing this setting applies to the next Implement action only.
|
|
|
100
84
|
Each guaranteed-plan implementation stores its effective policy, so a later Settings save cannot shorten or extend an implementation already in progress.
|
|
101
85
|
Conversation-history-only implementation has no active Plan-mode state to show, export, or clear after kickoff.
|
|
102
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
|
+
|
|
103
105
|
### Export destination
|
|
104
106
|
|
|
105
107
|
`defaultPlanExportPath` controls only exports that omit a path.
|
|
@@ -163,7 +165,7 @@ A missing file stays absent until an explicit save.
|
|
|
163
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.
|
|
164
166
|
This in-process queue is not a cross-process lock, so concurrent separate Pi processes can still race.
|
|
165
167
|
|
|
166
|
-
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`.
|
|
167
169
|
Compatibility: a valid legacy `plan-mode.json` remains readable with a warning and is never modified automatically.
|
|
168
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.
|
|
169
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,37 +1,37 @@
|
|
|
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
|
-
import {
|
|
4
|
-
FRESH_PREFERENCES_ENTRY,
|
|
5
|
-
freshPreferencesApplied,
|
|
6
|
-
} from "./fresh-implementation-preferences.js";
|
|
7
|
-
import {
|
|
8
|
-
hasImplementationPreferences,
|
|
9
|
-
preflightImplementationPreferences,
|
|
10
|
-
sameModel,
|
|
11
|
-
} from "./implementation-preferences.js";
|
|
12
4
|
import { PLAN_HISTORY_IMPLEMENTATION_PROMPT } from "./message-transform.js";
|
|
13
5
|
import { createModeContractMessage } from "./mode-contract.js";
|
|
14
|
-
import type { ImplementationPlanRetention
|
|
15
|
-
import
|
|
6
|
+
import type { ImplementationPlanRetention } from "./settings.js";
|
|
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";
|
|
16
16
|
|
|
17
17
|
type NewSessionOptions = Exclude<Parameters<ExtensionCommandContext["newSession"]>[0], undefined>;
|
|
18
18
|
type ReplacementContext = Parameters<NonNullable<NewSessionOptions["withSession"]>>[0];
|
|
19
19
|
|
|
20
20
|
export interface FreshImplementationRequest {
|
|
21
|
-
preferences?: ImplementationPreferences;
|
|
22
21
|
plan: string;
|
|
23
22
|
source: PlanCompletionSource;
|
|
24
23
|
retention: ImplementationPlanRetention;
|
|
25
24
|
stateEntryType: string;
|
|
25
|
+
runtime?: ImplementationRuntimeSelection;
|
|
26
26
|
isCurrent(): boolean;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
interface FreshImplementationFromStateOptions {
|
|
30
|
-
preferences?: ImplementationPreferences;
|
|
31
30
|
getState(): PlanModeState;
|
|
32
31
|
menuIsCurrent(): boolean;
|
|
33
32
|
retention: ImplementationPlanRetention;
|
|
34
33
|
stateEntryType: string;
|
|
34
|
+
runtime?: ImplementationRuntimeSelection;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export type FreshImplementationResult =
|
|
@@ -87,9 +87,9 @@ export async function startFreshImplementationFromState(
|
|
|
87
87
|
return startFreshImplementationSession(ctx, {
|
|
88
88
|
plan,
|
|
89
89
|
source,
|
|
90
|
-
preferences: options.preferences,
|
|
91
90
|
retention: options.retention,
|
|
92
91
|
stateEntryType: options.stateEntryType,
|
|
92
|
+
runtime: options.runtime,
|
|
93
93
|
isCurrent,
|
|
94
94
|
});
|
|
95
95
|
}
|
|
@@ -104,40 +104,29 @@ export async function startFreshImplementationSession(
|
|
|
104
104
|
|
|
105
105
|
await ctx.waitForIdle();
|
|
106
106
|
if (!request.isCurrent()) return { kind: "stale" };
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const originalThinking = ctx.thinkingLevel;
|
|
110
|
-
const preflightCurrent = () =>
|
|
111
|
-
request.isCurrent() &&
|
|
112
|
-
sameModel(ctx.model, originalModel) &&
|
|
113
|
-
ctx.thinkingLevel === originalThinking;
|
|
114
|
-
const preferencesId = hasImplementationPreferences(preferences) ? randomUUID() : undefined;
|
|
115
|
-
if (preferencesId) {
|
|
116
|
-
try {
|
|
117
|
-
if (!(await preflightImplementationPreferences(ctx, preferences, preflightCurrent)))
|
|
118
|
-
return { kind: "stale" };
|
|
119
|
-
} catch (error) {
|
|
120
|
-
if (preflightCurrent())
|
|
121
|
-
safeNotify(ctx, `Unable to implement the plan: ${safeErrorDetail(error)}`, "error");
|
|
122
|
-
return { kind: "rejected" };
|
|
123
|
-
}
|
|
124
|
-
} else if (!(await preflightModel(ctx, preflightCurrent))) return { kind: "rejected" };
|
|
125
|
-
if (!preflightCurrent() || !ctx.isIdle()) return { kind: "stale" };
|
|
107
|
+
if (!(await preflightModel(ctx, request))) return { kind: "rejected" };
|
|
108
|
+
if (!request.isCurrent()) return { kind: "stale" };
|
|
126
109
|
|
|
127
110
|
const usesConversationHistory = request.retention === "clear-on-start";
|
|
128
|
-
const
|
|
111
|
+
const pendingImplementationRuntime = pendingRuntimeIntent(request.runtime);
|
|
112
|
+
const activeImplementation = usesConversationHistory
|
|
129
113
|
? undefined
|
|
130
114
|
: {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
source: request.source,
|
|
137
|
-
startedAt: Date.now(),
|
|
138
|
-
retention: request.retention,
|
|
139
|
-
},
|
|
115
|
+
id: randomUUID(),
|
|
116
|
+
plan: request.plan,
|
|
117
|
+
source: request.source,
|
|
118
|
+
startedAt: Date.now(),
|
|
119
|
+
retention: request.retention,
|
|
140
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;
|
|
141
130
|
const handoff = usesConversationHistory
|
|
142
131
|
? formatTransferredPlanPrompt(request.plan, true)
|
|
143
132
|
: formatImplementationHandoff(request.plan);
|
|
@@ -153,12 +142,6 @@ export async function startFreshImplementationSession(
|
|
|
153
142
|
...(parentSession ? { parentSession } : {}),
|
|
154
143
|
setup: async (sessionManager) => {
|
|
155
144
|
try {
|
|
156
|
-
if (preferencesId)
|
|
157
|
-
sessionManager.appendCustomEntry(FRESH_PREFERENCES_ENTRY, {
|
|
158
|
-
id: preferencesId,
|
|
159
|
-
status: "pending",
|
|
160
|
-
preferences,
|
|
161
|
-
});
|
|
162
145
|
const contract = createModeContractMessage("normal");
|
|
163
146
|
sessionManager.appendCustomMessageEntry(
|
|
164
147
|
contract.customType,
|
|
@@ -174,35 +157,44 @@ export async function startFreshImplementationSession(
|
|
|
174
157
|
}
|
|
175
158
|
},
|
|
176
159
|
withSession: async (replacementCtx) => {
|
|
177
|
-
if (
|
|
178
|
-
!setupError &&
|
|
179
|
-
preferencesId &&
|
|
180
|
-
!freshPreferencesApplied(replacementCtx, preferencesId)
|
|
181
|
-
) {
|
|
182
|
-
setupError =
|
|
183
|
-
"Implementation model/thinking could not be applied or changed before kickoff";
|
|
184
|
-
}
|
|
185
160
|
if (setupError) {
|
|
186
161
|
recoverSetupFailure(replacementCtx, handoff, setupError);
|
|
187
162
|
return;
|
|
188
163
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
} catch (error: unknown) {
|
|
192
|
-
kickoffError = safeErrorDetail(error);
|
|
164
|
+
const reportKickoffFailure = (detail: string) => {
|
|
165
|
+
kickoffError = detail;
|
|
193
166
|
const recoveredInEditor =
|
|
194
167
|
usesConversationHistory && safeSetEditorText(replacementCtx, handoff);
|
|
195
168
|
safeNotify(
|
|
196
169
|
replacementCtx,
|
|
197
170
|
usesConversationHistory
|
|
198
171
|
? recoveredInEditor
|
|
199
|
-
? `Fresh session created, but implementation did not start: ${
|
|
200
|
-
: `Fresh session created, but implementation did not start: ${
|
|
201
|
-
: `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.`,
|
|
202
175
|
"error",
|
|
203
176
|
);
|
|
177
|
+
};
|
|
178
|
+
try {
|
|
179
|
+
await replacementCtx.sendUserMessage(handoff);
|
|
180
|
+
} catch (error: unknown) {
|
|
181
|
+
reportKickoffFailure(safeErrorDetail(error));
|
|
204
182
|
return;
|
|
205
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
|
+
}
|
|
206
198
|
safeNotify(
|
|
207
199
|
replacementCtx,
|
|
208
200
|
"Fresh implementation session started. Only the approved plan was transferred.",
|
|
@@ -226,29 +218,113 @@ export async function startFreshImplementationSession(
|
|
|
226
218
|
return setupError || kickoffError ? { kind: "partial" } : { kind: "started" };
|
|
227
219
|
}
|
|
228
220
|
|
|
229
|
-
async function preflightModel(ctx: ExtensionCommandContext,
|
|
230
|
-
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
|
+
}
|
|
231
262
|
if (!model) {
|
|
232
|
-
ctx
|
|
263
|
+
notifyCurrent(ctx, request, "Unable to implement the plan: no model is selected.", "warning");
|
|
233
264
|
return false;
|
|
234
265
|
}
|
|
235
266
|
let auth: Awaited<ReturnType<ExtensionCommandContext["modelRegistry"]["getApiKeyAndHeaders"]>>;
|
|
236
267
|
try {
|
|
237
268
|
auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
238
269
|
} catch (error: unknown) {
|
|
239
|
-
|
|
240
|
-
ctx.ui.notify(`Unable to implement the plan: ${safeErrorDetail(error)}`, "error");
|
|
241
|
-
}
|
|
270
|
+
notifyCurrent(ctx, request, `Unable to implement the plan: ${safeErrorDetail(error)}`, "error");
|
|
242
271
|
return false;
|
|
243
272
|
}
|
|
244
|
-
if (!isCurrent()) return false;
|
|
273
|
+
if (!request.isCurrent()) return false;
|
|
245
274
|
if (!auth.ok) {
|
|
246
|
-
|
|
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
|
+
);
|
|
247
283
|
return false;
|
|
248
284
|
}
|
|
249
285
|
return true;
|
|
250
286
|
}
|
|
251
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
|
+
|
|
252
328
|
function recoverSetupFailure(ctx: ReplacementContext, handoff: string, setupError: string) {
|
|
253
329
|
const recoveredInEditor = safeSetEditorText(ctx, handoff);
|
|
254
330
|
safeNotify(
|
|
@@ -289,10 +365,15 @@ function isCommandContext(ctx: ExtensionContext): ctx is ExtensionCommandContext
|
|
|
289
365
|
function safeErrorDetail(error: unknown) {
|
|
290
366
|
const detail = error instanceof Error ? error.message : String(error);
|
|
291
367
|
const normalized =
|
|
292
|
-
[...detail]
|
|
368
|
+
[...stripVTControlCharacters(detail)]
|
|
293
369
|
.map((character) => {
|
|
294
370
|
const codePoint = character.codePointAt(0) ?? 0;
|
|
295
|
-
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;
|
|
296
377
|
})
|
|
297
378
|
.join("")
|
|
298
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
|
+
}
|