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,69 @@
1
+ const SEGMENT = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
2
+ export function canonicalPath(value, caller = "/root") {
3
+ if (!value || value !== value.trim())
4
+ throw new Error("Agent path must not be empty or contain surrounding whitespace");
5
+ const path = value.startsWith("/") ? value : `${caller}/${value}`;
6
+ const parts = path.slice(1).split("/");
7
+ if (!parts.every((part) => SEGMENT.test(part)) || parts.length > 32) {
8
+ throw new Error("Agent paths require slash-separated names (letters, digits, - or _); no dot segments, escapes, empty segments or trailing slash");
9
+ }
10
+ return path;
11
+ }
12
+ export function parentPath(path) {
13
+ canonicalPath(path);
14
+ const last = path.lastIndexOf("/");
15
+ return last === 0 ? null : path.slice(0, last);
16
+ }
17
+ export function isDescendant(path, ancestor) {
18
+ return path.startsWith(`${ancestor}/`);
19
+ }
20
+ export function inheritContext(messages) {
21
+ const copy = structuredClone(messages);
22
+ const matchedCalls = new Set();
23
+ const matchedResults = new Set();
24
+ const pending = new Map();
25
+ for (const [messageIndex, message] of copy.entries()) {
26
+ if (message.role === "assistant") {
27
+ if (message.stopReason === "error" || message.stopReason === "aborted")
28
+ continue;
29
+ for (const [blockIndex, block] of message.content.entries()) {
30
+ if (block.type !== "toolCall")
31
+ continue;
32
+ const queue = pending.get(block.id);
33
+ const occurrence = { messageIndex, blockIndex };
34
+ if (queue)
35
+ queue.push(occurrence);
36
+ else
37
+ pending.set(block.id, [occurrence]);
38
+ }
39
+ continue;
40
+ }
41
+ if (message.role !== "toolResult")
42
+ continue;
43
+ const queue = pending.get(message.toolCallId);
44
+ const occurrence = queue?.shift();
45
+ if (!occurrence)
46
+ continue;
47
+ matchedCalls.add(`${occurrence.messageIndex}:${occurrence.blockIndex}`);
48
+ matchedResults.add(messageIndex);
49
+ if (queue && !queue.length)
50
+ pending.delete(message.toolCallId);
51
+ }
52
+ return copy.flatMap((message, messageIndex) => {
53
+ if (message.role === "system")
54
+ return [];
55
+ if (message.role === "assistant") {
56
+ if (message.stopReason === "error" || message.stopReason === "aborted")
57
+ return [];
58
+ message.content = message.content.filter((block, blockIndex) => block.type !== "toolCall" || matchedCalls.has(`${messageIndex}:${blockIndex}`));
59
+ if (!message.content.length)
60
+ return [];
61
+ if (message.stopReason === "toolUse" &&
62
+ !message.content.some((block) => block.type === "toolCall"))
63
+ message.stopReason = "stop";
64
+ }
65
+ if (message.role === "toolResult" && !matchedResults.has(messageIndex))
66
+ return [];
67
+ return [message];
68
+ });
69
+ }
@@ -0,0 +1,30 @@
1
+ import { checklistGuidance } from "./checklist-integration.js";
2
+ export function delegationGuidance(canSpawnChildren) {
3
+ return canSpawnChildren
4
+ ? "You may spawn subagents of your own if useful, subject to your tools, assigned scope, and shared concurrency limits."
5
+ : "You are at the maximum agent depth and cannot spawn any more subagents. Complete your assigned work yourself.";
6
+ }
7
+ export function subagentPrompt(settings, checklistEligible = false) {
8
+ if (settings.subagentMode === "off")
9
+ return undefined;
10
+ const policy = settings.subagentMode === "orchestration"
11
+ ? "Orchestration mode: /root only coordinates. Delegate every user task to subagents, even small or sequential tasks. Do not inspect/edit files, run commands, research, or execute task work yourself. Only plan, assign, monitor, clarify, and synthesize subagent results for the user. This restriction applies only to /root; subagents execute the work."
12
+ : "Opportunistic mode: do ordinary tasks yourself. Delegate only when work can be parallelized, is long-running, or is very large; do not spawn agents for small, quick, straightforward tasks.";
13
+ const waitingPolicy = settings.subagentMode === "orchestration"
14
+ ? "As an orchestrator, you must NEVER be blocked waiting for subagents. ALWAYS start every subagent in async/background mode with wait:false, even for small or sequential tasks. NEVER call agent_wait or use a foreground spawn. End your turn after assigning work so you remain free to talk to the user while subagents work. Check agent_status and collect available results with agent_output without blocking; if results are not ready, report that and leave the conversation free."
15
+ : "For independent parallel work, spawn all siblings with wait:false before agent_wait. Only await synchronous tasks whose results are needed in the current turn. For long-running tasks, create background agents with wait:false and do not immediately call agent_wait; end your turn so you remain free to talk to the user while they work. Await background results when the user asks you to collect them.";
16
+ return [
17
+ "## pi-subagent",
18
+ "You are /root, the main conversation (L1).",
19
+ policy,
20
+ "Call agent_types before choosing a type. Use task-based kebab-case paths, not type names. Choose context via agent_spawn path: /root/task forks the lexical parent's conversation; /task starts fresh with no inherited history. Use fresh agents for adversarial review or clean-slate research; give them a self-contained task without the current thread's conclusions.",
21
+ waitingPolicy,
22
+ 'Use agent_status to inspect and agent_output for full results. Completion, failure or stop of a wait:false agent is delivered to you as a message event that starts a new turn when you are idle (with Final Recap on, once after all outstanding async agents have finished). Pass timeoutMs to agent_spawn to get a status event if a child runs long; the child is not killed. Valid range 30000–300000 ms; omit for no timeout. To extend a running background agent\'s reporting timer, before or after a timeout event, call agent_steer({path: "/root/task", timeoutMs: 120000}) with message omitted entirely. This resets the timer from now (replacing any pending timer), without sending input, interrupting or resuming the agent; it requires the agent to still be running. After re-arming, end your turn to remain available while it works. For other timeout responses, follow the waiting policy above, send steering input or stop the agent.',
23
+ "Use agent_steer to send input or resume retained sessions. Paused agents have no final answer; completed agents hand back results. Both retain their session.",
24
+ `Maximum depth: ${settings.maxLevels} levels including L1. Shared concurrency: ${settings.maxConcurrent} active threads; waiting parents count.`,
25
+ delegationGuidance(settings.maxLevels > 1),
26
+ ...(settings.checklistIntegration && checklistEligible
27
+ ? [checklistGuidance(settings.subagentMode)]
28
+ : []),
29
+ ].join("\n");
30
+ }
@@ -0,0 +1,115 @@
1
+ export const REGISTRY_ENTRY = "pi-subagent:registry:v1";
2
+ export const REGISTRY_DELTA_ENTRY = "pi-subagent:registry-delta:v1";
3
+ export function readRegistry(branch) {
4
+ const deltas = [];
5
+ for (let index = branch.length - 1; index >= 0; index--) {
6
+ const entry = branch[index];
7
+ if (entry.type !== "custom")
8
+ continue;
9
+ if (entry.customType === REGISTRY_DELTA_ENTRY)
10
+ deltas.push(entry.data);
11
+ else if (entry.customType === REGISTRY_ENTRY)
12
+ return applyDeltas(parseRegistry(entry.data), deltas.reverse());
13
+ }
14
+ if (deltas.length)
15
+ throw new Error("Invalid registry format: delta without a full registry");
16
+ return undefined;
17
+ }
18
+ function parseRegistry(data) {
19
+ const registry = data;
20
+ if (registry?.version !== 1 || !Array.isArray(registry.threads))
21
+ throw new Error("Invalid registry format");
22
+ return registry;
23
+ }
24
+ function parseDelta(data, rootSessionId) {
25
+ const delta = data;
26
+ if (delta?.version !== 1 || !Array.isArray(delta.changes))
27
+ throw new Error("Invalid registry format");
28
+ if (delta.rootSessionId !== rootSessionId)
29
+ throw new Error("Invalid registry format: delta belongs to another root session");
30
+ return delta;
31
+ }
32
+ function applyDeltas(base, deltas) {
33
+ if (!deltas.length)
34
+ return base;
35
+ const threads = new Map(base.threads.map((thread) => [thread.view.path, thread]));
36
+ if (threads.size !== base.threads.length)
37
+ throw new Error("Invalid registry format: duplicate thread path");
38
+ for (const data of deltas) {
39
+ for (const change of parseDelta(data, base.rootSessionId).changes) {
40
+ if ("thread" in change) {
41
+ threads.set(change.thread.view.path, change.thread);
42
+ continue;
43
+ }
44
+ const current = threads.get(change.path);
45
+ if (!current)
46
+ throw new Error(`Invalid registry format: unknown thread ${change.path}`);
47
+ const view = { ...current.view, ...change.view };
48
+ for (const field of change.cleared ?? [])
49
+ delete view[field];
50
+ threads.set(change.path, { ...current, view });
51
+ }
52
+ }
53
+ return { ...base, threads: [...threads.values()] };
54
+ }
55
+ function serialize(thread) {
56
+ const { view, ...rest } = thread;
57
+ const fields = Object.entries(view).flatMap(([field, value]) => value === undefined ? [] : [[field, JSON.stringify(value)]]);
58
+ return { view: new Map(fields), rest: JSON.stringify(rest) };
59
+ }
60
+ function threadChange(thread, next, previous) {
61
+ if (!previous || previous.rest !== next.rest)
62
+ return { thread };
63
+ const view = {};
64
+ for (const [field, value] of next.view) {
65
+ if (previous.view.get(field) !== value)
66
+ view[field] = thread.view[field];
67
+ }
68
+ const cleared = [...previous.view.keys()].filter((field) => !next.view.has(field));
69
+ if (!Object.keys(view).length && !cleared.length)
70
+ return undefined;
71
+ return {
72
+ path: thread.view.path,
73
+ view,
74
+ ...(cleared.length ? { cleared: cleared } : {}),
75
+ };
76
+ }
77
+ export class RegistryWriter {
78
+ append;
79
+ persisted;
80
+ constructor(append) {
81
+ this.append = append;
82
+ }
83
+ reset() {
84
+ this.persisted = undefined;
85
+ }
86
+ write(rootSessionId, threads) {
87
+ const next = new Map(threads.map((thread) => [thread.view.path, serialize(thread)]));
88
+ const persisted = this.persisted;
89
+ if (persisted &&
90
+ persisted.rootSessionId === rootSessionId &&
91
+ keepsOrder(persisted.threads, threads)) {
92
+ const changes = threads.flatMap((thread) => {
93
+ const path = thread.view.path;
94
+ const change = threadChange(thread, next.get(path), persisted.threads.get(path));
95
+ return change ? [change] : [];
96
+ });
97
+ if (!changes.length)
98
+ return;
99
+ this.append(REGISTRY_DELTA_ENTRY, { version: 1, rootSessionId, changes });
100
+ }
101
+ else {
102
+ this.append(REGISTRY_ENTRY, { version: 1, rootSessionId, threads });
103
+ }
104
+ this.persisted = { rootSessionId, threads: next };
105
+ }
106
+ }
107
+ function keepsOrder(persisted, threads) {
108
+ let index = 0;
109
+ for (const path of persisted.keys()) {
110
+ if (threads[index]?.view.path !== path)
111
+ return false;
112
+ index++;
113
+ }
114
+ return true;
115
+ }