@ferris1225/pi-subagents 0.32.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -22
- package/agents/reviewer.md +2 -0
- package/package.json +2 -2
- package/src/agents.ts +2 -7
- package/src/announcements.ts +62 -0
- package/src/completion.ts +7 -36
- package/src/config.ts +327 -364
- package/src/dispatch.ts +1682 -1878
- package/src/fixloop.ts +0 -16
- package/src/format.ts +4 -8
- package/src/index.ts +8 -9
- package/src/models.ts +17 -39
- package/src/monitor.ts +64 -175
- package/src/rpc-run.ts +2 -41
- package/src/runtime.ts +272 -285
- package/src/session-fork.ts +0 -4
- package/src/setup.ts +4 -4
- package/src/spawn.ts +542 -562
- package/src/tools.ts +706 -748
- package/src/ui.ts +3 -7
- package/src/widget.ts +90 -178
- package/src/worktree.ts +1 -1
- package/src/inspector-panel.ts +0 -363
- package/src/inspector.ts +0 -369
- package/src/trajectory.ts +0 -503
package/src/runtime.ts
CHANGED
|
@@ -1,285 +1,272 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared per-session runtime state for pi-subagents.
|
|
3
|
-
*
|
|
4
|
-
* The extension registers several tools (subagent, subagent_wait/status/stop)
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `createRuntime` builds those once per extension load and hands the same object
|
|
8
|
-
* to every registration site, so state stays in one place without globals.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
12
|
-
import { rmSync } from "node:fs";
|
|
13
|
-
import { BackgroundTaskQueue } from "./background.ts";
|
|
14
|
-
import {
|
|
15
|
-
completionGroupTriggersTurn,
|
|
16
|
-
createCompletionBatcher,
|
|
17
|
-
formatActiveRunsFooter,
|
|
18
|
-
formatCompletionMessage,
|
|
19
|
-
type CompletionBatcher,
|
|
20
|
-
type CompletionMessageItem,
|
|
21
|
-
} from "./completion.ts";
|
|
22
|
-
import { loadConfigSync, type ThinkingLevel } from "./config.ts";
|
|
23
|
-
import { isRunActiveStatus, monitor } from "./monitor.ts";
|
|
24
|
-
import {
|
|
25
|
-
persistRecoveryRecords,
|
|
26
|
-
recoveryRecordFromFinalization,
|
|
27
|
-
type RecoveryRecord,
|
|
28
|
-
} from "./recovery.ts";
|
|
29
|
-
import type { RpcRunControl } from "./rpc-run.ts";
|
|
30
|
-
import {
|
|
31
|
-
import type {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
| "
|
|
36
|
-
| "
|
|
37
|
-
| "
|
|
38
|
-
| "
|
|
39
|
-
| "
|
|
40
|
-
| "
|
|
41
|
-
| "
|
|
42
|
-
| "
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
cwd
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
runtime.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
runtime.threads.clear();
|
|
274
|
-
monitor.clear();
|
|
275
|
-
// The append-only inspector history (trajectory + transcript) is
|
|
276
|
-
// parent-session scoped: it must never leak into the next session.
|
|
277
|
-
inspectorStore.clearAll();
|
|
278
|
-
},
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
runtime.completionBatcher = createCompletionBatcher<CompletionMessageItem>({
|
|
282
|
-
emit: runtime.sendCompletionGroup,
|
|
283
|
-
});
|
|
284
|
-
return runtime;
|
|
285
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Shared per-session runtime state for pi-subagents.
|
|
3
|
+
*
|
|
4
|
+
* The extension registers several tools (subagent, subagent_wait/status/stop)
|
|
5
|
+
* that share the background queue, completion batcher, abort controllers per
|
|
6
|
+
* run, and settled-results store.
|
|
7
|
+
* `createRuntime` builds those once per extension load and hands the same object
|
|
8
|
+
* to every registration site, so state stays in one place without globals.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
12
|
+
import { rmSync } from "node:fs";
|
|
13
|
+
import { BackgroundTaskQueue } from "./background.ts";
|
|
14
|
+
import {
|
|
15
|
+
completionGroupTriggersTurn,
|
|
16
|
+
createCompletionBatcher,
|
|
17
|
+
formatActiveRunsFooter,
|
|
18
|
+
formatCompletionMessage,
|
|
19
|
+
type CompletionBatcher,
|
|
20
|
+
type CompletionMessageItem,
|
|
21
|
+
} from "./completion.ts";
|
|
22
|
+
import { loadConfigSync, type ThinkingLevel } from "./config.ts";
|
|
23
|
+
import { isRunActiveStatus, monitor } from "./monitor.ts";
|
|
24
|
+
import {
|
|
25
|
+
persistRecoveryRecords,
|
|
26
|
+
recoveryRecordFromFinalization,
|
|
27
|
+
type RecoveryRecord,
|
|
28
|
+
} from "./recovery.ts";
|
|
29
|
+
import type { RpcRunControl } from "./rpc-run.ts";
|
|
30
|
+
import type { SingleResult } from "./spawn.ts";
|
|
31
|
+
import type { IsolationMode, WorktreeFinalization, WorktreeIsolation } from "./worktree.ts";
|
|
32
|
+
|
|
33
|
+
export type ThreadState =
|
|
34
|
+
| "queued"
|
|
35
|
+
| "resuming"
|
|
36
|
+
| "running"
|
|
37
|
+
| "steering"
|
|
38
|
+
| "interrupting"
|
|
39
|
+
| "parked"
|
|
40
|
+
| "completed"
|
|
41
|
+
| "failed"
|
|
42
|
+
| "stopped";
|
|
43
|
+
|
|
44
|
+
export type ThreadLifecycleOperation = "park" | "resume" | "fork" | "stop" | "settle";
|
|
45
|
+
|
|
46
|
+
export interface SubagentThread {
|
|
47
|
+
id: number;
|
|
48
|
+
generation: number;
|
|
49
|
+
agentName: string;
|
|
50
|
+
task: string;
|
|
51
|
+
/** Caller-facing cwd in the original worktree. */
|
|
52
|
+
cwd: string;
|
|
53
|
+
/** Actual child cwd (the equivalent path inside an isolated worktree). */
|
|
54
|
+
executionCwd: string;
|
|
55
|
+
vision: boolean;
|
|
56
|
+
/** Exact primary→fallback refs inherited by a session fork. */
|
|
57
|
+
modelPool: string[];
|
|
58
|
+
thinkingLevel?: ThinkingLevel;
|
|
59
|
+
isolation: IsolationMode;
|
|
60
|
+
worktree?: WorktreeIsolation;
|
|
61
|
+
state: ThreadState;
|
|
62
|
+
control: RpcRunControl;
|
|
63
|
+
queueController?: AbortController;
|
|
64
|
+
/** Resolves only after the current generation's queue work has fully
|
|
65
|
+
* quiesced and released its concurrency slot. Auto-fix orchestration is part
|
|
66
|
+
* of the parent generation and replaces/extends this promise. */
|
|
67
|
+
generationCompletion: Promise<void>;
|
|
68
|
+
/** Synchronous CAS used by lifecycle controls across their async preflight. */
|
|
69
|
+
lifecycleVersion: number;
|
|
70
|
+
lifecycleOperation?: ThreadLifecycleOperation;
|
|
71
|
+
sessionId?: string;
|
|
72
|
+
sessionDir?: string;
|
|
73
|
+
/** Most recent generation result, retained for parked destructive-stop output. */
|
|
74
|
+
lastResult?: SingleResult;
|
|
75
|
+
/** A destructive stop retires context even if the active child settles later. */
|
|
76
|
+
retireOnSettle?: boolean;
|
|
77
|
+
retired?: boolean;
|
|
78
|
+
/** Abort the active generation to a stable checkpoint and wait until its
|
|
79
|
+
* queue work has published that checkpoint and released its slot. */
|
|
80
|
+
park: () => Promise<"queued" | "active">;
|
|
81
|
+
/** Installed by dispatch so the control tool can restart the same logical id. */
|
|
82
|
+
resume: (objective?: string, ctx?: ExtensionContext) => Promise<SingleResult>;
|
|
83
|
+
/** Create a new logical thread from this thread's retained Pi session branch. */
|
|
84
|
+
fork: (objective?: string, ctx?: ExtensionContext) => Promise<SingleResult>;
|
|
85
|
+
forkedFromRunId?: number;
|
|
86
|
+
forkChildRunIds: number[];
|
|
87
|
+
/** Dispatch-owned, generation-guarded worktree settlement hook. */
|
|
88
|
+
finalizeIsolation: (generation: number, result?: SingleResult) => Promise<WorktreeFinalization | undefined>;
|
|
89
|
+
/** Best-effort shutdown notification for retained integration artifacts. */
|
|
90
|
+
notifyIsolationFailure?: (finalization: WorktreeFinalization) => void;
|
|
91
|
+
isolationFailureNotified?: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface SubagentRuntime {
|
|
95
|
+
configPath: string;
|
|
96
|
+
backgroundQueue: BackgroundTaskQueue;
|
|
97
|
+
/** False after session_shutdown; guards delivery and queue work. */
|
|
98
|
+
sessionActive: boolean;
|
|
99
|
+
/** Deliver a batch of completion messages to the main window, waking it only
|
|
100
|
+
* when the batch needs a turn. */
|
|
101
|
+
sendCompletionGroup: (items: CompletionMessageItem[]) => void;
|
|
102
|
+
completionBatcher: CompletionBatcher<CompletionMessageItem>;
|
|
103
|
+
/** Abort controllers per active run, so subagent_stop can cancel a run in-turn. */
|
|
104
|
+
runControllers: Map<number, AbortController>;
|
|
105
|
+
/** Final results keyed by run id, so subagent_wait can hand the model the
|
|
106
|
+
* actual result in-turn instead of it sleeping/polling for a wake-up message. */
|
|
107
|
+
settledRuns: Map<number, SingleResult>;
|
|
108
|
+
settledListeners: Map<number, Set<(result: SingleResult) => void>>;
|
|
109
|
+
registerRunResult: (runId: number, result: SingleResult) => void;
|
|
110
|
+
/** Logical threads outlive process attempts and completed generations. */
|
|
111
|
+
threads: Map<number, SubagentThread>;
|
|
112
|
+
/** Resume/fork setup that has claimed a thread but has not yet enqueued its
|
|
113
|
+
* next generation. Shutdown invalidates these claims and waits for cleanup. */
|
|
114
|
+
preflightOperations: Set<Promise<void>>;
|
|
115
|
+
/** Every session directory retained for this parent session, including
|
|
116
|
+
* auto-fix internals that are not directly controllable. */
|
|
117
|
+
sessionDirs: Set<string>;
|
|
118
|
+
retainSession: (result: Pick<SingleResult, "sessionDir">) => void;
|
|
119
|
+
retireThreadSession: (thread: SubagentThread) => void;
|
|
120
|
+
/** Flip sessionActive off and release all session-scoped resources. */
|
|
121
|
+
shutdown: () => Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function createRuntime(pi: ExtensionAPI, configPath: string): SubagentRuntime {
|
|
125
|
+
// Init-time decisions need the config synchronously; the full (migrating)
|
|
126
|
+
// async load runs per tool call.
|
|
127
|
+
const initialConfig = loadConfigSync(configPath);
|
|
128
|
+
const backgroundQueue = new BackgroundTaskQueue(initialConfig.maxConcurrency);
|
|
129
|
+
|
|
130
|
+
const runtime: SubagentRuntime = {
|
|
131
|
+
configPath,
|
|
132
|
+
backgroundQueue,
|
|
133
|
+
sessionActive: true,
|
|
134
|
+
sendCompletionGroup: (items) => {
|
|
135
|
+
if (!runtime.sessionActive || items.length === 0) return;
|
|
136
|
+
// A result arriving for one run does not mean sibling runs are done.
|
|
137
|
+
// Computing this at delivery (emit) time — not when the item was
|
|
138
|
+
// pushed — reflects the current monitor state, since finishing runs
|
|
139
|
+
// are removed from the monitor before their completion is pushed.
|
|
140
|
+
// Auto-fix parents are flipped back to "running" while their chain
|
|
141
|
+
// owns the logical run, so they are included without a special case.
|
|
142
|
+
const active = monitor
|
|
143
|
+
.getRuns()
|
|
144
|
+
.filter((run) => isRunActiveStatus(run.status))
|
|
145
|
+
.map((run) => ({ id: run.id, agent: run.agent, label: run.label }));
|
|
146
|
+
const message = {
|
|
147
|
+
customType: "subagent-result",
|
|
148
|
+
content: formatCompletionMessage(items) + formatActiveRunsFooter(active),
|
|
149
|
+
display: true,
|
|
150
|
+
};
|
|
151
|
+
if (completionGroupTriggersTurn(items)) {
|
|
152
|
+
// steer: the result is injected after the current tool call even mid-turn,
|
|
153
|
+
// or starts a new turn when idle. followUp would sit in the queue until the
|
|
154
|
+
// whole turn ends — a main agent waiting for the result (sleep/poll) would
|
|
155
|
+
// never see it delivered, which is exactly the "returned but never woken"
|
|
156
|
+
// failure mode.
|
|
157
|
+
pi.sendMessage(message, { deliverAs: "steer", triggerTurn: true });
|
|
158
|
+
} else {
|
|
159
|
+
// No-wake delivery: nextTurn rides along with the next user turn and can
|
|
160
|
+
// never start a continuation by itself. followUp would auto-continue
|
|
161
|
+
// whenever pi is already streaming, defeating the opt-out.
|
|
162
|
+
pi.sendMessage(message, { deliverAs: "nextTurn" });
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
completionBatcher: undefined as unknown as CompletionBatcher<CompletionMessageItem>,
|
|
166
|
+
runControllers: new Map<number, AbortController>(),
|
|
167
|
+
settledRuns: new Map<number, SingleResult>(),
|
|
168
|
+
settledListeners: new Map<number, Set<(result: SingleResult) => void>>(),
|
|
169
|
+
threads: new Map<number, SubagentThread>(),
|
|
170
|
+
preflightOperations: new Set<Promise<void>>(),
|
|
171
|
+
sessionDirs: new Set<string>(),
|
|
172
|
+
retainSession: (result) => {
|
|
173
|
+
if (result.sessionDir) runtime.sessionDirs.add(result.sessionDir);
|
|
174
|
+
},
|
|
175
|
+
retireThreadSession: (thread) => {
|
|
176
|
+
thread.retired = true;
|
|
177
|
+
if (!thread.sessionDir) return;
|
|
178
|
+
const sessionDir = thread.sessionDir;
|
|
179
|
+
try {
|
|
180
|
+
rmSync(sessionDir, { recursive: true, force: true });
|
|
181
|
+
runtime.sessionDirs.delete(sessionDir);
|
|
182
|
+
thread.sessionDir = undefined;
|
|
183
|
+
thread.sessionId = undefined;
|
|
184
|
+
} catch {
|
|
185
|
+
/* best-effort; shutdown retries the still-retained directory */
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
registerRunResult: (runId, result) => {
|
|
189
|
+
runtime.settledRuns.set(runId, result);
|
|
190
|
+
const listeners = runtime.settledListeners.get(runId);
|
|
191
|
+
if (listeners) {
|
|
192
|
+
runtime.settledListeners.delete(runId);
|
|
193
|
+
for (const listener of listeners) {
|
|
194
|
+
try {
|
|
195
|
+
listener(result);
|
|
196
|
+
} catch {
|
|
197
|
+
/* listener errors must never break settling */
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
shutdown: async () => {
|
|
203
|
+
if (!runtime.sessionActive) return;
|
|
204
|
+
runtime.sessionActive = false;
|
|
205
|
+
const shutdownThreads = [...runtime.threads.values()];
|
|
206
|
+
// Invalidate every lifecycle claim synchronously before the first await.
|
|
207
|
+
// Resume/fork preflight checks both this version and sessionActive, then
|
|
208
|
+
// cleans any worktree/session it created before resolving its tracker.
|
|
209
|
+
for (const thread of shutdownThreads) {
|
|
210
|
+
thread.lifecycleVersion++;
|
|
211
|
+
thread.lifecycleOperation = "stop";
|
|
212
|
+
thread.retired = true;
|
|
213
|
+
thread.retireOnSettle = true;
|
|
214
|
+
thread.state = "stopped";
|
|
215
|
+
}
|
|
216
|
+
const preflights = [...runtime.preflightOperations];
|
|
217
|
+
runtime.completionBatcher.dispose();
|
|
218
|
+
runtime.backgroundQueue.cancelAll();
|
|
219
|
+
// Await live RPC process-tree cleanup and continuation preflight rollback
|
|
220
|
+
// before removing sessions/worktrees or clearing ownership maps.
|
|
221
|
+
await Promise.all([
|
|
222
|
+
Promise.all(
|
|
223
|
+
shutdownThreads.map((thread) =>
|
|
224
|
+
thread.control.stop("Parent session shut down").catch(() => undefined),
|
|
225
|
+
),
|
|
226
|
+
),
|
|
227
|
+
Promise.allSettled(preflights),
|
|
228
|
+
runtime.backgroundQueue.waitForIdle(),
|
|
229
|
+
]);
|
|
230
|
+
// Parked work owns no queue task, so shutdown is its final settlement.
|
|
231
|
+
// Active/stopped tasks may already have finalized; the handle and callback
|
|
232
|
+
// are idempotent and generation-guarded.
|
|
233
|
+
const recoveryRecords: RecoveryRecord[] = [];
|
|
234
|
+
for (const thread of runtime.threads.values()) {
|
|
235
|
+
const finalization = await thread.finalizeIsolation(thread.generation).catch(() => undefined);
|
|
236
|
+
if (finalization?.status === "retained") {
|
|
237
|
+
recoveryRecords.push(recoveryRecordFromFinalization(thread.id, finalization));
|
|
238
|
+
if (!thread.isolationFailureNotified) {
|
|
239
|
+
thread.isolationFailureNotified = true;
|
|
240
|
+
try {
|
|
241
|
+
thread.notifyIsolationFailure?.(finalization);
|
|
242
|
+
} catch {
|
|
243
|
+
/* the parent UI may already be shutting down */
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// Persist before tearing down the old runtime. A /new, /resume, or quit
|
|
249
|
+
// must not make the only recovery paths unreachable.
|
|
250
|
+
await persistRecoveryRecords(runtime.configPath, recoveryRecords).catch(() => undefined);
|
|
251
|
+
runtime.settledRuns.clear();
|
|
252
|
+
runtime.settledListeners.clear();
|
|
253
|
+
runtime.runControllers.clear();
|
|
254
|
+
for (const sessionDir of runtime.sessionDirs) {
|
|
255
|
+
try {
|
|
256
|
+
rmSync(sessionDir, { recursive: true, force: true });
|
|
257
|
+
} catch {
|
|
258
|
+
/* best-effort */
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
runtime.sessionDirs.clear();
|
|
262
|
+
runtime.preflightOperations.clear();
|
|
263
|
+
runtime.threads.clear();
|
|
264
|
+
monitor.clear();
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
runtime.completionBatcher = createCompletionBatcher<CompletionMessageItem>({
|
|
269
|
+
emit: runtime.sendCompletionGroup,
|
|
270
|
+
});
|
|
271
|
+
return runtime;
|
|
272
|
+
}
|
package/src/session-fork.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { tmpdir } from "node:os";
|
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
|
|
9
9
|
export interface ForkedSession {
|
|
10
|
-
sourceSessionFile: string;
|
|
11
10
|
sessionDir: string;
|
|
12
11
|
sessionId: string;
|
|
13
12
|
sessionFile: string;
|
|
@@ -15,7 +14,6 @@ export interface ForkedSession {
|
|
|
15
14
|
|
|
16
15
|
/** Locate one retained session by its authoritative header id. */
|
|
17
16
|
export async function findRetainedSessionFile(
|
|
18
|
-
cwd: string,
|
|
19
17
|
sessionDir: string,
|
|
20
18
|
sessionId: string,
|
|
21
19
|
): Promise<string> {
|
|
@@ -47,7 +45,6 @@ export async function forkRetainedSession(options: {
|
|
|
47
45
|
sessionId: string;
|
|
48
46
|
}): Promise<ForkedSession> {
|
|
49
47
|
const sourceSessionFile = await findRetainedSessionFile(
|
|
50
|
-
options.cwd,
|
|
51
48
|
options.sessionDir,
|
|
52
49
|
options.sessionId,
|
|
53
50
|
);
|
|
@@ -72,7 +69,6 @@ export async function forkRetainedSession(options: {
|
|
|
72
69
|
throw new Error(`Forked session branch has no persisted assistant checkpoint at ${sessionFile}.`);
|
|
73
70
|
}
|
|
74
71
|
return {
|
|
75
|
-
sourceSessionFile,
|
|
76
72
|
sessionDir,
|
|
77
73
|
sessionId: manager.getSessionId(),
|
|
78
74
|
sessionFile,
|
package/src/setup.ts
CHANGED
|
@@ -30,10 +30,11 @@ import {
|
|
|
30
30
|
import {
|
|
31
31
|
CURRENT_MAIN_MODEL,
|
|
32
32
|
applyModelPoolChoice,
|
|
33
|
-
|
|
33
|
+
availableModelsInScope,
|
|
34
34
|
buildAgentModelPoolRows,
|
|
35
35
|
buildModelPickerItems,
|
|
36
36
|
currentModelRef,
|
|
37
|
+
modelRef,
|
|
37
38
|
type AgentModelPoolMaps,
|
|
38
39
|
type ModelPickerSlot,
|
|
39
40
|
type ModelPoolSlot,
|
|
@@ -215,11 +216,10 @@ async function pickConfiguredModel(
|
|
|
215
216
|
configuredRef: string | undefined,
|
|
216
217
|
escNote: string,
|
|
217
218
|
): Promise<string | undefined> {
|
|
218
|
-
const
|
|
219
|
-
const models = registry.getAll?.() ?? registry.getAvailable();
|
|
219
|
+
const models = availableModelsInScope(ctx);
|
|
220
220
|
const items = buildModelPickerItems({
|
|
221
221
|
models,
|
|
222
|
-
availableRefs:
|
|
222
|
+
availableRefs: models.map(modelRef),
|
|
223
223
|
slot,
|
|
224
224
|
configuredRef,
|
|
225
225
|
mainRef: currentModelRef(ctx),
|