pi-subagent-manager 1.8.0 → 1.9.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/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/orch/context-entries.ts +15 -0
- package/src/orch/manager.ts +16 -1
- package/src/orch/runtime.ts +7 -0
- package/src/types.ts +10 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
offerAgentImport,
|
|
15
15
|
} from "./prefs/agent-import.ts";
|
|
16
16
|
import { ThreadManager } from "./orch/manager.ts";
|
|
17
|
+
import { inheritedContextEntries } from "./orch/context-entries.ts";
|
|
17
18
|
import { loadManagerSettings } from "./prefs/settings.ts";
|
|
18
19
|
import { configureAgents } from "./ui/settings-ui.ts";
|
|
19
20
|
import { AgentNavigationController } from "./ui/status-ui.ts";
|
|
@@ -656,6 +657,8 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
656
657
|
...limits,
|
|
657
658
|
createDriver: driverFactory,
|
|
658
659
|
rootSnapshot: () => buildSessionContext(requireContext().sessionManager.getBranch()).messages,
|
|
660
|
+
rootContextEntries: () =>
|
|
661
|
+
inheritedContextEntries(requireContext().sessionManager.getBranch()),
|
|
659
662
|
getType: (name) => store.get(name),
|
|
660
663
|
toolsFor,
|
|
661
664
|
onEventError: (error, event) => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { InheritedContextEntry } from "../types.ts";
|
|
2
|
+
|
|
3
|
+
/** Preserve only pruner state; other extension state is private to its session. */
|
|
4
|
+
export function inheritedContextEntries(
|
|
5
|
+
branch: readonly { type: string; customType?: string; data?: unknown }[],
|
|
6
|
+
): InheritedContextEntry[] {
|
|
7
|
+
return structuredClone(
|
|
8
|
+
branch.flatMap((entry) =>
|
|
9
|
+
entry.type === "custom" &&
|
|
10
|
+
(entry.customType === "context-prune-index" || entry.customType === "context-prune-frontier")
|
|
11
|
+
? [{ customType: entry.customType, data: entry.data }]
|
|
12
|
+
: [],
|
|
13
|
+
),
|
|
14
|
+
);
|
|
15
|
+
}
|
package/src/orch/manager.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
AgentDriver,
|
|
5
5
|
AgentType,
|
|
6
6
|
DriverOptions,
|
|
7
|
+
InheritedContextEntry,
|
|
7
8
|
ManagerOptions,
|
|
8
9
|
SavedThread,
|
|
9
10
|
SavedThreadView,
|
|
@@ -22,6 +23,7 @@ interface Record {
|
|
|
22
23
|
view: ThreadView;
|
|
23
24
|
definition: AgentType;
|
|
24
25
|
inherited: AgentMessage[];
|
|
26
|
+
inheritedContextEntries: InheritedContextEntry[];
|
|
25
27
|
contextReady?: Promise<void>;
|
|
26
28
|
contextPending?: boolean;
|
|
27
29
|
startup: AbortController;
|
|
@@ -232,7 +234,10 @@ export class ThreadManager {
|
|
|
232
234
|
view,
|
|
233
235
|
definition: structuredClone(record.definition),
|
|
234
236
|
...(!view.sessionFile && !record.contextPending
|
|
235
|
-
? {
|
|
237
|
+
? {
|
|
238
|
+
inherited: structuredClone(record.inherited),
|
|
239
|
+
inheritedContextEntries: structuredClone(record.inheritedContextEntries),
|
|
240
|
+
}
|
|
236
241
|
: {}),
|
|
237
242
|
};
|
|
238
243
|
});
|
|
@@ -274,6 +279,7 @@ export class ThreadManager {
|
|
|
274
279
|
view,
|
|
275
280
|
definition: structuredClone(item.definition),
|
|
276
281
|
inherited: structuredClone(item.inherited ?? []),
|
|
282
|
+
inheritedContextEntries: structuredClone(item.inheritedContextEntries ?? []),
|
|
277
283
|
// A reservation saved before its lexical parent opened has no snapshot yet.
|
|
278
284
|
contextPending: !view.sessionFile && item.inherited === undefined && view.parent !== null,
|
|
279
285
|
startup: new AbortController(),
|
|
@@ -337,6 +343,11 @@ export class ThreadManager {
|
|
|
337
343
|
: parentRecord?.driver
|
|
338
344
|
? inheritContext(parentRecord.driver.snapshot())
|
|
339
345
|
: [];
|
|
346
|
+
const inheritedContextEntries = structuredClone(
|
|
347
|
+
parent === "/root"
|
|
348
|
+
? (this.options.rootContextEntries?.() ?? [])
|
|
349
|
+
: (parentRecord?.driver?.contextEntries?.() ?? []),
|
|
350
|
+
);
|
|
340
351
|
const now = Date.now();
|
|
341
352
|
const record: Record = {
|
|
342
353
|
view: {
|
|
@@ -358,6 +369,7 @@ export class ThreadManager {
|
|
|
358
369
|
},
|
|
359
370
|
definition: type,
|
|
360
371
|
inherited,
|
|
372
|
+
inheritedContextEntries,
|
|
361
373
|
contextPending: !!(parentRecord && !parentRecord.driver),
|
|
362
374
|
startup: new AbortController(),
|
|
363
375
|
pauseRequested: false,
|
|
@@ -730,6 +742,7 @@ export class ThreadManager {
|
|
|
730
742
|
canSpawnChildren,
|
|
731
743
|
type: record.definition,
|
|
732
744
|
inherited: record.inherited,
|
|
745
|
+
inheritedContextEntries: record.inheritedContextEntries,
|
|
733
746
|
tools: this.options.toolsFor(record.view.path),
|
|
734
747
|
parentPath: record.view.parent,
|
|
735
748
|
sessionFile: record.view.sessionFile,
|
|
@@ -983,6 +996,7 @@ export class ThreadManager {
|
|
|
983
996
|
if (record.contextReady) return record.contextReady;
|
|
984
997
|
if (!record.view.parent || record.view.parent === "/root") {
|
|
985
998
|
record.inherited = inheritContext(this.options.rootSnapshot());
|
|
999
|
+
record.inheritedContextEntries = structuredClone(this.options.rootContextEntries?.() ?? []);
|
|
986
1000
|
record.contextPending = false;
|
|
987
1001
|
return undefined;
|
|
988
1002
|
}
|
|
@@ -991,6 +1005,7 @@ export class ThreadManager {
|
|
|
991
1005
|
ready = this.ensureDriver(parentRecord, readOnly)
|
|
992
1006
|
.then((driver) => {
|
|
993
1007
|
record.inherited = inheritContext(driver.snapshot());
|
|
1008
|
+
record.inheritedContextEntries = structuredClone(driver.contextEntries?.() ?? []);
|
|
994
1009
|
record.contextPending = false;
|
|
995
1010
|
if (record.contextReady === ready) record.contextReady = undefined;
|
|
996
1011
|
this.touch(record);
|
package/src/orch/runtime.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { TranscriptChannel } from "./transcript.ts";
|
|
|
31
31
|
import { delegationGuidance } from "./prompt.ts";
|
|
32
32
|
import { discoverSubagentExtensions, selectSubagentExtensions } from "./extensions.ts";
|
|
33
33
|
import type { InheritedToolSource } from "./inherited-tools.ts";
|
|
34
|
+
import { inheritedContextEntries } from "./context-entries.ts";
|
|
34
35
|
import type {
|
|
35
36
|
ModelSelectionMode,
|
|
36
37
|
SubagentExtensionSelection,
|
|
@@ -347,6 +348,9 @@ export function createDriverFactory(
|
|
|
347
348
|
sessionManager.appendMessage(message);
|
|
348
349
|
}
|
|
349
350
|
}
|
|
351
|
+
for (const entry of options.inheritedContextEntries ?? []) {
|
|
352
|
+
sessionManager.appendCustomEntry(entry.customType, entry.data);
|
|
353
|
+
}
|
|
350
354
|
}
|
|
351
355
|
const restored = options.sessionFile ? sessionManager.buildSessionContext() : undefined;
|
|
352
356
|
const modelSelection = getModelSelection();
|
|
@@ -979,6 +983,9 @@ export function createDriverFactory(
|
|
|
979
983
|
snapshot() {
|
|
980
984
|
return structuredClone(session.messages);
|
|
981
985
|
},
|
|
986
|
+
contextEntries() {
|
|
987
|
+
return inheritedContextEntries(sessionManager.getBranch());
|
|
988
|
+
},
|
|
982
989
|
observeTranscript(listener) {
|
|
983
990
|
assertOpen();
|
|
984
991
|
return transcript.observe(listener);
|
package/src/types.ts
CHANGED
|
@@ -140,10 +140,17 @@ export interface TranscriptObservation {
|
|
|
140
140
|
}
|
|
141
141
|
export type TranscriptListener = (snapshot: TranscriptSnapshot) => void;
|
|
142
142
|
|
|
143
|
+
/** Opaque session metadata needed to reproduce inherited context transformations. */
|
|
144
|
+
export interface InheritedContextEntry {
|
|
145
|
+
customType: string;
|
|
146
|
+
data: unknown;
|
|
147
|
+
}
|
|
148
|
+
|
|
143
149
|
export interface AgentDriver {
|
|
144
150
|
prompt(message: string): Promise<void>;
|
|
145
151
|
steer(message: string): Promise<void>;
|
|
146
152
|
snapshot(): AgentMessage[];
|
|
153
|
+
contextEntries?(): InheritedContextEntry[];
|
|
147
154
|
observeTranscript?(listener: TranscriptListener): TranscriptObservation;
|
|
148
155
|
output(): string;
|
|
149
156
|
abort(): Promise<void>;
|
|
@@ -158,6 +165,7 @@ export interface DriverOptions {
|
|
|
158
165
|
canSpawnChildren?: boolean;
|
|
159
166
|
type: AgentType;
|
|
160
167
|
inherited: AgentMessage[];
|
|
168
|
+
inheritedContextEntries?: InheritedContextEntry[];
|
|
161
169
|
tools: ToolDefinition[];
|
|
162
170
|
onEvent(event: DriverEvent): void;
|
|
163
171
|
shouldPause(): boolean;
|
|
@@ -198,6 +206,7 @@ export interface SavedThread {
|
|
|
198
206
|
definition: AgentType;
|
|
199
207
|
/** Reserved threads may not have a transcript yet; preserve their initial context. */
|
|
200
208
|
inherited?: AgentMessage[];
|
|
209
|
+
inheritedContextEntries?: InheritedContextEntry[];
|
|
201
210
|
}
|
|
202
211
|
export interface ThreadService {
|
|
203
212
|
list(): ThreadView[];
|
|
@@ -245,6 +254,7 @@ export interface ThreadActivity {
|
|
|
245
254
|
export interface ManagerOptions {
|
|
246
255
|
createDriver: DriverFactory;
|
|
247
256
|
rootSnapshot(): AgentMessage[];
|
|
257
|
+
rootContextEntries?(): InheritedContextEntry[];
|
|
248
258
|
getType(name: string): AgentType;
|
|
249
259
|
toolsFor(path: string): ToolDefinition[];
|
|
250
260
|
onEvent?(event: ThreadEvent): void;
|