pi-subagent-manager 1.10.0 → 1.12.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 +9 -9
- package/dist/index.d.ts +2 -0
- package/dist/index.js +790 -0
- package/dist/orch/checklist-integration.js +176 -0
- package/dist/orch/context-entries.js +6 -0
- package/dist/orch/cost-ledger.js +38 -0
- package/dist/orch/diagnostics.js +86 -0
- package/dist/orch/extensions.js +66 -0
- package/dist/orch/housekeeping-usage.js +22 -0
- package/dist/orch/housekeeping.js +248 -0
- package/dist/orch/inherited-tools.js +57 -0
- package/dist/orch/mailbox.js +195 -0
- package/dist/orch/manager.js +970 -0
- package/dist/orch/paths.js +69 -0
- package/dist/orch/prompt.js +30 -0
- package/dist/orch/registry.js +115 -0
- package/dist/orch/runtime.js +835 -0
- package/dist/orch/tools.js +112 -0
- package/dist/orch/transcript.js +165 -0
- package/dist/prefs/agent-import.js +188 -0
- package/dist/prefs/config.js +878 -0
- package/dist/prefs/import-discovery.js +547 -0
- package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +0 -1
- package/dist/prefs/models.js +56 -0
- package/dist/prefs/settings.js +491 -0
- package/dist/types.js +1 -0
- package/dist/ui/agent-loader.js +63 -0
- package/dist/ui/agent-navigation-editor.js +168 -0
- package/dist/ui/cost-footer.js +209 -0
- package/dist/ui/dialog.js +505 -0
- package/dist/ui/import-picker.js +191 -0
- package/dist/ui/live-agent-view.js +527 -0
- package/dist/ui/model-picker.js +529 -0
- package/dist/ui/settings-ui.js +671 -0
- package/dist/ui/status-ui.js +470 -0
- package/dist/ui/thread-tree.js +142 -0
- package/dist/ui/tool-picker.js +331 -0
- package/dist/ui/transcript-tool.js +91 -0
- package/dist/ui/ui.js +1019 -0
- package/package.json +17 -5
- package/docs/assets/subagent-manager-demo.gif +0 -0
- package/docs/async-lifecycle.md +0 -153
- package/docs/custom-agents.md +0 -154
- package/docs/default-agents.md +0 -95
- package/docs/demo.md +0 -63
- package/docs/development.md +0 -74
- package/docs/importing-agents.md +0 -41
- package/docs/pi-footer.md +0 -128
- package/docs/research-claude.md +0 -258
- package/docs/research-codex.md +0 -143
- package/docs/research-default-agent-models.md +0 -121
- package/docs/research-model-audit-2026-10.md +0 -154
- package/docs/research-model-roles-coding.md +0 -99
- package/docs/research-model-roles-writing.md +0 -78
- package/docs/research-researcher-workflow.md +0 -97
- package/docs/settings.md +0 -293
- package/docs/subagent-extension-limitations.md +0 -98
- package/docs/threads.md +0 -73
- package/docs/tools-and-ui.md +0 -129
- package/src/index.ts +0 -920
- package/src/orch/checklist-integration.ts +0 -230
- package/src/orch/context-entries.ts +0 -15
- package/src/orch/cost-ledger.ts +0 -56
- package/src/orch/diagnostics.ts +0 -95
- package/src/orch/extensions.ts +0 -83
- package/src/orch/housekeeping-usage.ts +0 -47
- package/src/orch/housekeeping.ts +0 -348
- package/src/orch/inherited-tools.ts +0 -84
- package/src/orch/mailbox.ts +0 -261
- package/src/orch/manager.ts +0 -1084
- package/src/orch/paths.ts +0 -73
- package/src/orch/prompt.ts +0 -39
- package/src/orch/registry.ts +0 -168
- package/src/orch/runtime.ts +0 -1041
- package/src/orch/tools.ts +0 -190
- package/src/orch/transcript.ts +0 -186
- package/src/prefs/agent-import.ts +0 -245
- package/src/prefs/config.ts +0 -1017
- package/src/prefs/import-discovery.ts +0 -643
- package/src/prefs/models.ts +0 -74
- package/src/prefs/settings.ts +0 -614
- package/src/types.ts +0 -271
- package/src/ui/agent-loader.ts +0 -98
- package/src/ui/agent-navigation-editor.ts +0 -233
- package/src/ui/cost-footer.ts +0 -230
- package/src/ui/dialog.ts +0 -678
- package/src/ui/import-picker.ts +0 -231
- package/src/ui/live-agent-view.ts +0 -600
- package/src/ui/model-picker.ts +0 -701
- package/src/ui/settings-ui.ts +0 -830
- package/src/ui/status-ui.ts +0 -628
- package/src/ui/thread-tree.ts +0 -173
- package/src/ui/tool-picker.ts +0 -398
- package/src/ui/transcript-tool.ts +0 -142
- package/src/ui/ui.ts +0 -1407
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function createInheritedToolSource(pi) {
|
|
2
|
+
let loadout;
|
|
3
|
+
let context;
|
|
4
|
+
return {
|
|
5
|
+
captureLoadout(next) {
|
|
6
|
+
loadout = next;
|
|
7
|
+
return undefined;
|
|
8
|
+
},
|
|
9
|
+
captureContext(next) {
|
|
10
|
+
context = next;
|
|
11
|
+
},
|
|
12
|
+
reset() {
|
|
13
|
+
context = undefined;
|
|
14
|
+
},
|
|
15
|
+
snapshot() {
|
|
16
|
+
if (!loadout)
|
|
17
|
+
return { tools: [], activeNames: [] };
|
|
18
|
+
const rootContext = context;
|
|
19
|
+
const callable = new Set(loadout.callable.map((tool) => tool.name));
|
|
20
|
+
const active = new Set(loadout.declared.map((tool) => tool.name));
|
|
21
|
+
const info = new Map(pi.getAllTools().map((tool) => [tool.name, tool]));
|
|
22
|
+
const tools = [];
|
|
23
|
+
for (const tool of loadout.registered) {
|
|
24
|
+
const exposure = loadout.getExposure(tool.name);
|
|
25
|
+
if (!callable.has(tool.name) && !active.has(tool.name))
|
|
26
|
+
continue;
|
|
27
|
+
if (exposure === "hidden")
|
|
28
|
+
continue;
|
|
29
|
+
const metadata = info.get(tool.name);
|
|
30
|
+
tools.push({
|
|
31
|
+
...tool,
|
|
32
|
+
prepareArguments: undefined,
|
|
33
|
+
label: tool.label,
|
|
34
|
+
exposure,
|
|
35
|
+
namespace: loadout.getNamespace(tool.name),
|
|
36
|
+
annotations: metadata?.annotations,
|
|
37
|
+
promptGuidelines: metadata?.promptGuidelines,
|
|
38
|
+
defaultActive: active.has(tool.name),
|
|
39
|
+
async execute(_id, args, signal, onUpdate) {
|
|
40
|
+
if (!callable.has(tool.name)) {
|
|
41
|
+
throw new Error(`Cannot safely inherit model-only tool ${tool.name}: the SDK does not ` +
|
|
42
|
+
"provide a hook-preserving execution bridge. Run it in the main session.");
|
|
43
|
+
}
|
|
44
|
+
const bridge = rootContext ?? context;
|
|
45
|
+
if (!bridge) {
|
|
46
|
+
throw new Error("Inherited tool execution needs a main-session agent_* tool call first. " +
|
|
47
|
+
"Use agent_steer to resume this child instead of the thread dialog.");
|
|
48
|
+
}
|
|
49
|
+
const outcome = await bridge.executeTool(tool.name, args, { signal, onUpdate });
|
|
50
|
+
return { ...outcome.result, isError: outcome.isError };
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return { tools, activeNames: [...active] };
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
export const LEGACY_QUEUE_TYPE = "pi-subagent:queue:v1";
|
|
3
|
+
const ACCEPTED_TYPE = "pi-subagent:mailbox:accepted:v2";
|
|
4
|
+
const CONSUMED_TYPE = "pi-subagent:mailbox:consumed:v2";
|
|
5
|
+
const MIGRATION_TYPE = "pi-subagent:mailbox:migration:v2";
|
|
6
|
+
export const MAILBOX_FIELD = "piSubagentMailbox";
|
|
7
|
+
export const BOOTSTRAP_MESSAGE = "Subagent session initialized; awaiting parent input.";
|
|
8
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
9
|
+
const isAcceptedEntry = (entry) => entry.type === "custom" &&
|
|
10
|
+
entry.customType === ACCEPTED_TYPE &&
|
|
11
|
+
isAcceptedLedgerEntry(entry.data);
|
|
12
|
+
const isConsumedEntry = (entry) => entry.type === "custom" &&
|
|
13
|
+
entry.customType === CONSUMED_TYPE &&
|
|
14
|
+
isConsumedLedgerEntry(entry.data);
|
|
15
|
+
const isMigrationEntry = (entry, sourceEntryId) => entry.type === "custom" &&
|
|
16
|
+
entry.customType === MIGRATION_TYPE &&
|
|
17
|
+
isObject(entry.data) &&
|
|
18
|
+
entry.data.sourceEntryId === sourceEntryId;
|
|
19
|
+
const isAcceptedKind = (value) => value === "steer" || value === "followUp" || value === "update";
|
|
20
|
+
const isAcceptedLedgerEntry = (value) => isObject(value) &&
|
|
21
|
+
typeof value.id === "string" &&
|
|
22
|
+
isAcceptedKind(value.kind) &&
|
|
23
|
+
typeof value.content === "string" &&
|
|
24
|
+
typeof value.timestamp === "number";
|
|
25
|
+
const isConsumedLedgerEntry = (value) => isObject(value) && typeof value.id === "string" && typeof value.messageEntryId === "string";
|
|
26
|
+
const getMailboxMarker = (value) => {
|
|
27
|
+
if (!isObject(value))
|
|
28
|
+
return undefined;
|
|
29
|
+
const marker = value[MAILBOX_FIELD];
|
|
30
|
+
if (!isObject(marker) || typeof marker.id !== "string")
|
|
31
|
+
return undefined;
|
|
32
|
+
if (marker.kind !== "steer" &&
|
|
33
|
+
marker.kind !== "followUp" &&
|
|
34
|
+
marker.kind !== "update" &&
|
|
35
|
+
marker.kind !== "bootstrap")
|
|
36
|
+
return undefined;
|
|
37
|
+
return { id: marker.id, kind: marker.kind };
|
|
38
|
+
};
|
|
39
|
+
const normalizeLegacyQueue = (value) => {
|
|
40
|
+
if (!isObject(value))
|
|
41
|
+
return undefined;
|
|
42
|
+
const steering = value.steering;
|
|
43
|
+
const followUp = value.followUp;
|
|
44
|
+
if (!Array.isArray(steering) ||
|
|
45
|
+
!steering.every((text) => typeof text === "string") ||
|
|
46
|
+
!Array.isArray(followUp) ||
|
|
47
|
+
!followUp.every((text) => typeof text === "string")) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return { steering: [...steering], followUp: [...followUp] };
|
|
51
|
+
};
|
|
52
|
+
const getAcceptedIdFromEntry = (entry) => {
|
|
53
|
+
if (entry.type === "message" && entry.message.role === "user") {
|
|
54
|
+
return getMailboxMarker(entry.message)?.id;
|
|
55
|
+
}
|
|
56
|
+
if (entry.type === "custom_message") {
|
|
57
|
+
return getMailboxMarker(entry.details)?.id;
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
};
|
|
61
|
+
export const buildQueuedUserMessage = (entry) => ({
|
|
62
|
+
role: "user",
|
|
63
|
+
content: [{ type: "text", text: entry.content }],
|
|
64
|
+
timestamp: entry.timestamp,
|
|
65
|
+
[MAILBOX_FIELD]: { id: entry.id, kind: entry.kind },
|
|
66
|
+
});
|
|
67
|
+
export const buildUpdateDetails = (entry) => ({
|
|
68
|
+
[MAILBOX_FIELD]: { id: entry.id, kind: entry.kind },
|
|
69
|
+
});
|
|
70
|
+
export const buildBootstrapMessage = (timestamp = Date.now()) => ({
|
|
71
|
+
role: "user",
|
|
72
|
+
content: [{ type: "text", text: BOOTSTRAP_MESSAGE }],
|
|
73
|
+
timestamp,
|
|
74
|
+
[MAILBOX_FIELD]: { id: `bootstrap:${timestamp}`, kind: "bootstrap" },
|
|
75
|
+
});
|
|
76
|
+
export class DurableMailbox {
|
|
77
|
+
sessionManager;
|
|
78
|
+
accepted = new Map();
|
|
79
|
+
consumed = new Set();
|
|
80
|
+
enqueued = new Set();
|
|
81
|
+
constructor(sessionManager) {
|
|
82
|
+
this.sessionManager = sessionManager;
|
|
83
|
+
this.migrateLegacyQueue();
|
|
84
|
+
this.restore();
|
|
85
|
+
}
|
|
86
|
+
accept(kind, content, timestamp = Date.now()) {
|
|
87
|
+
return this.appendAccepted({ id: randomUUID(), kind, content, timestamp });
|
|
88
|
+
}
|
|
89
|
+
pending() {
|
|
90
|
+
return [...this.accepted.values()].filter((entry) => !this.consumed.has(entry.id));
|
|
91
|
+
}
|
|
92
|
+
replayablePending() {
|
|
93
|
+
return this.pending().filter((entry) => !this.enqueued.has(entry.id));
|
|
94
|
+
}
|
|
95
|
+
markEnqueued(id) {
|
|
96
|
+
this.enqueued.add(id);
|
|
97
|
+
}
|
|
98
|
+
clearQueuedInputs() {
|
|
99
|
+
for (const entry of this.accepted.values()) {
|
|
100
|
+
if (entry.kind === "steer" || entry.kind === "followUp")
|
|
101
|
+
this.enqueued.delete(entry.id);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
consumeAppended(messageEntryId, markerSource) {
|
|
105
|
+
const id = getMailboxMarker(markerSource)?.id;
|
|
106
|
+
if (!id || !this.accepted.has(id) || this.consumed.has(id))
|
|
107
|
+
return;
|
|
108
|
+
this.sessionManager.appendCustomEntry(CONSUMED_TYPE, { id, messageEntryId });
|
|
109
|
+
this.consumed.add(id);
|
|
110
|
+
this.enqueued.delete(id);
|
|
111
|
+
}
|
|
112
|
+
wrapAppends(onCheckpoint) {
|
|
113
|
+
const originalAppendMessage = this.sessionManager.appendMessage.bind(this.sessionManager);
|
|
114
|
+
const originalAppendCustomMessageEntry = this.sessionManager.appendCustomMessageEntry.bind(this.sessionManager);
|
|
115
|
+
this.sessionManager.appendMessage = (message) => {
|
|
116
|
+
const entryId = originalAppendMessage(message);
|
|
117
|
+
this.consumeAppended(entryId, message);
|
|
118
|
+
onCheckpoint();
|
|
119
|
+
return entryId;
|
|
120
|
+
};
|
|
121
|
+
this.sessionManager.appendCustomMessageEntry = (customType, content, display, details) => {
|
|
122
|
+
const entryId = originalAppendCustomMessageEntry(customType, content, display, details);
|
|
123
|
+
this.consumeAppended(entryId, details);
|
|
124
|
+
onCheckpoint();
|
|
125
|
+
return entryId;
|
|
126
|
+
};
|
|
127
|
+
return () => {
|
|
128
|
+
this.sessionManager.appendMessage = originalAppendMessage;
|
|
129
|
+
this.sessionManager.appendCustomMessageEntry = originalAppendCustomMessageEntry;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
appendAccepted(entry) {
|
|
133
|
+
this.sessionManager.appendCustomEntry(ACCEPTED_TYPE, entry);
|
|
134
|
+
this.accepted.set(entry.id, entry);
|
|
135
|
+
return entry;
|
|
136
|
+
}
|
|
137
|
+
migrateLegacyQueue() {
|
|
138
|
+
const branch = this.sessionManager.getBranch();
|
|
139
|
+
const legacy = [...branch]
|
|
140
|
+
.reverse()
|
|
141
|
+
.find((entry) => entry.type === "custom" && entry.customType === LEGACY_QUEUE_TYPE);
|
|
142
|
+
if (!legacy || branch.some((entry) => isMigrationEntry(entry, legacy.id)))
|
|
143
|
+
return;
|
|
144
|
+
const queue = normalizeLegacyQueue(legacy.data);
|
|
145
|
+
if (!queue)
|
|
146
|
+
return;
|
|
147
|
+
const existingIds = new Set();
|
|
148
|
+
for (const entry of branch) {
|
|
149
|
+
if (isAcceptedEntry(entry) || isConsumedEntry(entry))
|
|
150
|
+
existingIds.add(entry.data.id);
|
|
151
|
+
const acceptedId = getAcceptedIdFromEntry(entry);
|
|
152
|
+
if (acceptedId)
|
|
153
|
+
existingIds.add(acceptedId);
|
|
154
|
+
}
|
|
155
|
+
const appendLegacyAccepted = (kind, content, occurrenceIndex) => {
|
|
156
|
+
const accepted = {
|
|
157
|
+
id: `legacy:${legacy.id}:${kind}:${occurrenceIndex}`,
|
|
158
|
+
kind,
|
|
159
|
+
content,
|
|
160
|
+
timestamp: Date.parse(legacy.timestamp),
|
|
161
|
+
};
|
|
162
|
+
if (existingIds.has(accepted.id))
|
|
163
|
+
return;
|
|
164
|
+
this.appendAccepted(accepted);
|
|
165
|
+
existingIds.add(accepted.id);
|
|
166
|
+
};
|
|
167
|
+
queue.steering.forEach((content, occurrenceIndex) => {
|
|
168
|
+
appendLegacyAccepted("steer", content, occurrenceIndex);
|
|
169
|
+
});
|
|
170
|
+
queue.followUp.forEach((content, occurrenceIndex) => {
|
|
171
|
+
appendLegacyAccepted("followUp", content, occurrenceIndex);
|
|
172
|
+
});
|
|
173
|
+
this.sessionManager.appendCustomEntry(MIGRATION_TYPE, {
|
|
174
|
+
sourceEntryId: legacy.id,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
restore() {
|
|
178
|
+
this.accepted.clear();
|
|
179
|
+
this.consumed.clear();
|
|
180
|
+
this.enqueued.clear();
|
|
181
|
+
for (const entry of this.sessionManager.getBranch()) {
|
|
182
|
+
if (isAcceptedEntry(entry)) {
|
|
183
|
+
this.accepted.set(entry.data.id, entry.data);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (isConsumedEntry(entry)) {
|
|
187
|
+
this.consumed.add(entry.data.id);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const transcriptId = getAcceptedIdFromEntry(entry);
|
|
191
|
+
if (transcriptId)
|
|
192
|
+
this.consumed.add(transcriptId);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|