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.
Files changed (95) hide show
  1. package/README.md +9 -9
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +790 -0
  4. package/dist/orch/checklist-integration.js +176 -0
  5. package/dist/orch/context-entries.js +6 -0
  6. package/dist/orch/cost-ledger.js +38 -0
  7. package/dist/orch/diagnostics.js +86 -0
  8. package/dist/orch/extensions.js +66 -0
  9. package/dist/orch/housekeeping-usage.js +22 -0
  10. package/dist/orch/housekeeping.js +248 -0
  11. package/dist/orch/inherited-tools.js +57 -0
  12. package/dist/orch/mailbox.js +195 -0
  13. package/dist/orch/manager.js +970 -0
  14. package/dist/orch/paths.js +69 -0
  15. package/dist/orch/prompt.js +30 -0
  16. package/dist/orch/registry.js +115 -0
  17. package/dist/orch/runtime.js +835 -0
  18. package/dist/orch/tools.js +112 -0
  19. package/dist/orch/transcript.js +165 -0
  20. package/dist/prefs/agent-import.js +188 -0
  21. package/dist/prefs/config.js +878 -0
  22. package/dist/prefs/import-discovery.js +547 -0
  23. package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +0 -1
  24. package/dist/prefs/models.js +56 -0
  25. package/dist/prefs/settings.js +491 -0
  26. package/dist/types.js +1 -0
  27. package/dist/ui/agent-loader.js +63 -0
  28. package/dist/ui/agent-navigation-editor.js +168 -0
  29. package/dist/ui/cost-footer.js +209 -0
  30. package/dist/ui/dialog.js +505 -0
  31. package/dist/ui/import-picker.js +191 -0
  32. package/dist/ui/live-agent-view.js +527 -0
  33. package/dist/ui/model-picker.js +529 -0
  34. package/dist/ui/settings-ui.js +671 -0
  35. package/dist/ui/status-ui.js +470 -0
  36. package/dist/ui/thread-tree.js +142 -0
  37. package/dist/ui/tool-picker.js +331 -0
  38. package/dist/ui/transcript-tool.js +91 -0
  39. package/dist/ui/ui.js +1019 -0
  40. package/package.json +17 -5
  41. package/docs/assets/subagent-manager-demo.gif +0 -0
  42. package/docs/async-lifecycle.md +0 -153
  43. package/docs/custom-agents.md +0 -154
  44. package/docs/default-agents.md +0 -95
  45. package/docs/demo.md +0 -63
  46. package/docs/development.md +0 -74
  47. package/docs/importing-agents.md +0 -41
  48. package/docs/pi-footer.md +0 -128
  49. package/docs/research-claude.md +0 -258
  50. package/docs/research-codex.md +0 -143
  51. package/docs/research-default-agent-models.md +0 -121
  52. package/docs/research-model-audit-2026-10.md +0 -154
  53. package/docs/research-model-roles-coding.md +0 -99
  54. package/docs/research-model-roles-writing.md +0 -78
  55. package/docs/research-researcher-workflow.md +0 -97
  56. package/docs/settings.md +0 -293
  57. package/docs/subagent-extension-limitations.md +0 -98
  58. package/docs/threads.md +0 -73
  59. package/docs/tools-and-ui.md +0 -129
  60. package/src/index.ts +0 -920
  61. package/src/orch/checklist-integration.ts +0 -230
  62. package/src/orch/context-entries.ts +0 -15
  63. package/src/orch/cost-ledger.ts +0 -56
  64. package/src/orch/diagnostics.ts +0 -95
  65. package/src/orch/extensions.ts +0 -83
  66. package/src/orch/housekeeping-usage.ts +0 -47
  67. package/src/orch/housekeeping.ts +0 -348
  68. package/src/orch/inherited-tools.ts +0 -84
  69. package/src/orch/mailbox.ts +0 -261
  70. package/src/orch/manager.ts +0 -1084
  71. package/src/orch/paths.ts +0 -73
  72. package/src/orch/prompt.ts +0 -39
  73. package/src/orch/registry.ts +0 -168
  74. package/src/orch/runtime.ts +0 -1041
  75. package/src/orch/tools.ts +0 -190
  76. package/src/orch/transcript.ts +0 -186
  77. package/src/prefs/agent-import.ts +0 -245
  78. package/src/prefs/config.ts +0 -1017
  79. package/src/prefs/import-discovery.ts +0 -643
  80. package/src/prefs/models.ts +0 -74
  81. package/src/prefs/settings.ts +0 -614
  82. package/src/types.ts +0 -271
  83. package/src/ui/agent-loader.ts +0 -98
  84. package/src/ui/agent-navigation-editor.ts +0 -233
  85. package/src/ui/cost-footer.ts +0 -230
  86. package/src/ui/dialog.ts +0 -678
  87. package/src/ui/import-picker.ts +0 -231
  88. package/src/ui/live-agent-view.ts +0 -600
  89. package/src/ui/model-picker.ts +0 -701
  90. package/src/ui/settings-ui.ts +0 -830
  91. package/src/ui/status-ui.ts +0 -628
  92. package/src/ui/thread-tree.ts +0 -173
  93. package/src/ui/tool-picker.ts +0 -398
  94. package/src/ui/transcript-tool.ts +0 -142
  95. 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
+ }