pi-subagent-manager 1.11.0 → 1.13.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 (169) hide show
  1. package/README.md +9 -9
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +1 -47
  4. package/dist/orch/checklist-integration.js +2 -30
  5. package/dist/orch/context-entries.js +0 -2
  6. package/dist/orch/cost-ledger.js +0 -5
  7. package/dist/orch/diagnostics.js +0 -9
  8. package/dist/orch/extensions.js +22 -21
  9. package/dist/orch/housekeeping-usage.js +0 -5
  10. package/dist/orch/housekeeping.js +1 -34
  11. package/dist/orch/inherited-tools.js +0 -14
  12. package/dist/orch/mailbox.js +0 -1
  13. package/dist/orch/manager.js +4 -44
  14. package/dist/orch/paths.js +0 -4
  15. package/dist/orch/prompt.js +1 -5
  16. package/dist/orch/registry.js +1 -20
  17. package/dist/orch/runtime.js +1 -48
  18. package/dist/orch/tools.js +0 -2
  19. package/dist/orch/transcript.js +0 -11
  20. package/dist/prefs/agent-import.js +2 -10
  21. package/dist/prefs/config.js +3 -51
  22. package/dist/prefs/import-discovery.js +0 -15
  23. package/dist/prefs/import-instructions.js +0 -2
  24. package/dist/prefs/models.js +0 -1
  25. package/dist/prefs/settings.js +22 -25
  26. package/dist/types.js +0 -1
  27. package/dist/ui/agent-loader.js +0 -10
  28. package/dist/ui/agent-navigation-editor.js +0 -21
  29. package/dist/ui/cost-footer.js +3 -9
  30. package/dist/ui/dialog.js +1 -29
  31. package/dist/ui/import-picker.js +0 -20
  32. package/dist/ui/live-agent-view.js +0 -19
  33. package/dist/ui/model-picker.js +0 -20
  34. package/dist/ui/settings-ui.js +8 -12
  35. package/dist/ui/status-ui.js +0 -17
  36. package/dist/ui/thread-tree.js +1 -12
  37. package/dist/ui/tool-picker.js +1 -4
  38. package/dist/ui/transcript-tool.js +0 -9
  39. package/dist/ui/ui.js +1 -29
  40. package/package.json +3 -3
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js.map +0 -1
  43. package/dist/orch/checklist-integration.d.ts +0 -48
  44. package/dist/orch/checklist-integration.d.ts.map +0 -1
  45. package/dist/orch/checklist-integration.js.map +0 -1
  46. package/dist/orch/context-entries.d.ts +0 -8
  47. package/dist/orch/context-entries.d.ts.map +0 -1
  48. package/dist/orch/context-entries.js.map +0 -1
  49. package/dist/orch/cost-ledger.d.ts +0 -16
  50. package/dist/orch/cost-ledger.d.ts.map +0 -1
  51. package/dist/orch/cost-ledger.js.map +0 -1
  52. package/dist/orch/diagnostics.d.ts +0 -13
  53. package/dist/orch/diagnostics.d.ts.map +0 -1
  54. package/dist/orch/diagnostics.js.map +0 -1
  55. package/dist/orch/extensions.d.ts +0 -15
  56. package/dist/orch/extensions.d.ts.map +0 -1
  57. package/dist/orch/extensions.js.map +0 -1
  58. package/dist/orch/housekeeping-usage.d.ts +0 -14
  59. package/dist/orch/housekeeping-usage.d.ts.map +0 -1
  60. package/dist/orch/housekeeping-usage.js.map +0 -1
  61. package/dist/orch/housekeeping.d.ts +0 -89
  62. package/dist/orch/housekeeping.d.ts.map +0 -1
  63. package/dist/orch/housekeeping.js.map +0 -1
  64. package/dist/orch/inherited-tools.d.ts +0 -18
  65. package/dist/orch/inherited-tools.d.ts.map +0 -1
  66. package/dist/orch/inherited-tools.js.map +0 -1
  67. package/dist/orch/mailbox.d.ts +0 -59
  68. package/dist/orch/mailbox.d.ts.map +0 -1
  69. package/dist/orch/mailbox.js.map +0 -1
  70. package/dist/orch/manager.d.ts +0 -82
  71. package/dist/orch/manager.d.ts.map +0 -1
  72. package/dist/orch/manager.js.map +0 -1
  73. package/dist/orch/paths.d.ts +0 -7
  74. package/dist/orch/paths.d.ts.map +0 -1
  75. package/dist/orch/paths.js.map +0 -1
  76. package/dist/orch/prompt.d.ts +0 -7
  77. package/dist/orch/prompt.d.ts.map +0 -1
  78. package/dist/orch/prompt.js.map +0 -1
  79. package/dist/orch/registry.d.ts +0 -49
  80. package/dist/orch/registry.d.ts.map +0 -1
  81. package/dist/orch/registry.js.map +0 -1
  82. package/dist/orch/runtime.d.ts +0 -11
  83. package/dist/orch/runtime.d.ts.map +0 -1
  84. package/dist/orch/runtime.js.map +0 -1
  85. package/dist/orch/tools.d.ts +0 -6
  86. package/dist/orch/tools.d.ts.map +0 -1
  87. package/dist/orch/tools.js.map +0 -1
  88. package/dist/orch/transcript.d.ts +0 -28
  89. package/dist/orch/transcript.d.ts.map +0 -1
  90. package/dist/orch/transcript.js.map +0 -1
  91. package/dist/prefs/agent-import.d.ts +0 -37
  92. package/dist/prefs/agent-import.d.ts.map +0 -1
  93. package/dist/prefs/agent-import.js.map +0 -1
  94. package/dist/prefs/config.d.ts +0 -108
  95. package/dist/prefs/config.d.ts.map +0 -1
  96. package/dist/prefs/config.js.map +0 -1
  97. package/dist/prefs/import-discovery.d.ts +0 -28
  98. package/dist/prefs/import-discovery.d.ts.map +0 -1
  99. package/dist/prefs/import-discovery.js.map +0 -1
  100. package/dist/prefs/import-instructions.d.ts +0 -3
  101. package/dist/prefs/import-instructions.d.ts.map +0 -1
  102. package/dist/prefs/import-instructions.js.map +0 -1
  103. package/dist/prefs/models.d.ts +0 -24
  104. package/dist/prefs/models.d.ts.map +0 -1
  105. package/dist/prefs/models.js.map +0 -1
  106. package/dist/prefs/settings.d.ts +0 -89
  107. package/dist/prefs/settings.d.ts.map +0 -1
  108. package/dist/prefs/settings.js.map +0 -1
  109. package/dist/types.d.ts +0 -293
  110. package/dist/types.d.ts.map +0 -1
  111. package/dist/types.js.map +0 -1
  112. package/dist/ui/agent-loader.d.ts +0 -21
  113. package/dist/ui/agent-loader.d.ts.map +0 -1
  114. package/dist/ui/agent-loader.js.map +0 -1
  115. package/dist/ui/agent-navigation-editor.d.ts +0 -46
  116. package/dist/ui/agent-navigation-editor.d.ts.map +0 -1
  117. package/dist/ui/agent-navigation-editor.js.map +0 -1
  118. package/dist/ui/cost-footer.d.ts +0 -37
  119. package/dist/ui/cost-footer.d.ts.map +0 -1
  120. package/dist/ui/cost-footer.js.map +0 -1
  121. package/dist/ui/dialog.d.ts +0 -135
  122. package/dist/ui/dialog.d.ts.map +0 -1
  123. package/dist/ui/dialog.js.map +0 -1
  124. package/dist/ui/import-picker.d.ts +0 -38
  125. package/dist/ui/import-picker.d.ts.map +0 -1
  126. package/dist/ui/import-picker.js.map +0 -1
  127. package/dist/ui/live-agent-view.d.ts +0 -82
  128. package/dist/ui/live-agent-view.d.ts.map +0 -1
  129. package/dist/ui/live-agent-view.js.map +0 -1
  130. package/dist/ui/model-picker.d.ts +0 -109
  131. package/dist/ui/model-picker.d.ts.map +0 -1
  132. package/dist/ui/model-picker.js.map +0 -1
  133. package/dist/ui/settings-ui.d.ts +0 -17
  134. package/dist/ui/settings-ui.d.ts.map +0 -1
  135. package/dist/ui/settings-ui.js.map +0 -1
  136. package/dist/ui/status-ui.d.ts +0 -67
  137. package/dist/ui/status-ui.d.ts.map +0 -1
  138. package/dist/ui/status-ui.js.map +0 -1
  139. package/dist/ui/thread-tree.d.ts +0 -22
  140. package/dist/ui/thread-tree.d.ts.map +0 -1
  141. package/dist/ui/thread-tree.js.map +0 -1
  142. package/dist/ui/tool-picker.d.ts +0 -46
  143. package/dist/ui/tool-picker.d.ts.map +0 -1
  144. package/dist/ui/tool-picker.js.map +0 -1
  145. package/dist/ui/transcript-tool.d.ts +0 -2
  146. package/dist/ui/transcript-tool.d.ts.map +0 -1
  147. package/dist/ui/transcript-tool.js.map +0 -1
  148. package/dist/ui/ui.d.ts +0 -41
  149. package/dist/ui/ui.d.ts.map +0 -1
  150. package/dist/ui/ui.js.map +0 -1
  151. package/docs/assets/subagent-manager-demo.gif +0 -0
  152. package/docs/async-lifecycle.md +0 -153
  153. package/docs/custom-agents.md +0 -154
  154. package/docs/default-agents.md +0 -95
  155. package/docs/demo.md +0 -63
  156. package/docs/development.md +0 -75
  157. package/docs/importing-agents.md +0 -41
  158. package/docs/pi-footer.md +0 -128
  159. package/docs/research-claude.md +0 -258
  160. package/docs/research-codex.md +0 -143
  161. package/docs/research-default-agent-models.md +0 -121
  162. package/docs/research-model-audit-2026-10.md +0 -154
  163. package/docs/research-model-roles-coding.md +0 -99
  164. package/docs/research-model-roles-writing.md +0 -78
  165. package/docs/research-researcher-workflow.md +0 -97
  166. package/docs/settings.md +0 -293
  167. package/docs/subagent-extension-limitations.md +0 -98
  168. package/docs/threads.md +0 -73
  169. package/docs/tools-and-ui.md +0 -129
@@ -1,12 +1,6 @@
1
1
  import { stripTerminalSequences } from "@earendil-works/pi-tui";
2
2
  import { modelIdentity } from "../prefs/models.js";
3
3
  import { captureHousekeepingUsageSession, reportHousekeepingUsage } from "./housekeeping-usage.js";
4
- /**
5
- * [labs] Housekeeping: a user-chosen model names each active agent's current work in one line.
6
- *
7
- * Strictly additive. Every failure path (no model, no credentials, provider error, timeout,
8
- * stale run) leaves the agent's raw status untouched.
9
- */
10
4
  export const SUMMARY_MAX_CHARS = 80;
11
5
  const SYSTEM_PROMPT = `You label what an AI agent is doing right now, for a compact tree view. ` +
12
6
  `Reply with ONLY one line of at most ${SUMMARY_MAX_CHARS} characters: a present-participle phrase ` +
@@ -27,7 +21,6 @@ export function buildHousekeepingRequest(activity, previous) {
27
21
  ].join("\n"),
28
22
  };
29
23
  }
30
- /** Single sanitized line, bounded; empty string when nothing usable remains. */
31
24
  export function cleanSummary(text) {
32
25
  let line = stripTerminalSequences(text)
33
26
  .replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, " ")
@@ -44,14 +37,6 @@ export function cleanSummary(text) {
44
37
  line = `${line.slice(0, SUMMARY_MAX_CHARS - 1).trimEnd()}…`;
45
38
  return line;
46
39
  }
47
- /**
48
- * Coalescing, throttled, cancellable summary scheduler.
49
- *
50
- * - One call in flight per agent; activity during a call only marks it dirty.
51
- * - Calls for one agent are spaced by `minIntervalMs` (doubling after failures, capped).
52
- * - A global concurrency cap bounds simultaneous calls.
53
- * - A new run, settlement, disable or reset aborts in-flight work; late results are dropped.
54
- */
55
40
  export class HousekeepingSummarizer {
56
41
  options;
57
42
  states = new Map();
@@ -71,12 +56,10 @@ export class HousekeepingSummarizer {
71
56
  this.maxConcurrent = Math.max(1, options.maxConcurrent ?? 2);
72
57
  this.maxFailures = Math.max(1, options.maxFailures ?? 3);
73
58
  }
74
- /** Feed new activity for an active agent. Cheap and synchronous. */
75
59
  notify(activity) {
76
60
  if (this.disposed)
77
61
  return;
78
62
  if (!this.safeEnabled()) {
79
- // Unavailable (disabled, model gone, credentials lost): never leave a stale label behind.
80
63
  this.drop(activity.path);
81
64
  this.safeClear(activity.path, activity.run);
82
65
  return;
@@ -94,11 +77,9 @@ export class HousekeepingSummarizer {
94
77
  state.dirty = true;
95
78
  this.schedule(activity.path, state);
96
79
  }
97
- /** Agent settled, paused or was removed: abort and forget. */
98
80
  settle(path) {
99
81
  this.drop(path);
100
82
  }
101
- /** Feature disabled, model changed, or session replaced. */
102
83
  cancelAll() {
103
84
  for (const path of [...this.states.keys()])
104
85
  this.drop(path);
@@ -116,7 +97,6 @@ export class HousekeepingSummarizer {
116
97
  this.options.clear?.(path, run);
117
98
  }
118
99
  catch {
119
- /* Display cleanup must not break scheduling. */
120
100
  }
121
101
  }
122
102
  safeEnabled() {
@@ -141,7 +121,7 @@ export class HousekeepingSummarizer {
141
121
  if (state.timer !== undefined || state.inFlight || !state.dirty)
142
122
  return;
143
123
  if (state.failures >= this.maxFailures)
144
- return; // Given up for this run.
124
+ return;
145
125
  const interval = Math.min(MAX_BACKOFF_MS, this.minIntervalMs * 2 ** state.failures);
146
126
  const wait = state.lastStart ? state.lastStart + interval - Date.now() : 0;
147
127
  const delay = Math.max(this.debounceMs, wait, minDelay);
@@ -173,14 +153,12 @@ export class HousekeepingSummarizer {
173
153
  this.running++;
174
154
  try {
175
155
  const raw = await this.options.complete(buildHousekeepingRequest(activity, state.lastSummary), controller.signal);
176
- // Stale: dropped, superseded run or disabled while the provider was answering.
177
156
  if (this.states.get(path) !== state || !this.safeEnabled())
178
157
  return;
179
158
  if (controller.signal.aborted)
180
159
  throw controller.signal.reason ?? new Error("Housekeeping call aborted");
181
160
  const summary = cleanSummary(raw);
182
161
  if (!summary) {
183
- // An unusable answer is an unsuccessful refresh: the old label no longer describes the work.
184
162
  state.lastSummary = undefined;
185
163
  this.safeClear(path, activity.run);
186
164
  return;
@@ -190,7 +168,6 @@ export class HousekeepingSummarizer {
190
168
  state.lastSummary = summary;
191
169
  }
192
170
  catch (error) {
193
- // Dropped (settled, new run, disabled) is not a provider failure; a timeout is.
194
171
  if (this.states.get(path) !== state)
195
172
  return;
196
173
  state.lastSummary = undefined;
@@ -202,7 +179,6 @@ export class HousekeepingSummarizer {
202
179
  this.options.onFailure?.(error instanceof Error ? error.message : String(error));
203
180
  }
204
181
  catch {
205
- /* Diagnostics must not break summarization bookkeeping. */
206
182
  }
207
183
  }
208
184
  }
@@ -216,17 +192,12 @@ export class HousekeepingSummarizer {
216
192
  }
217
193
  }
218
194
  }
219
- /** Models selectable as housekeeping model: every available model, scoped ones flagged. */
220
195
  export function housekeepingCandidates(ctx) {
221
196
  const scoped = new Set((ctx.scopedModels ?? []).map(({ model }) => modelIdentity(model)));
222
197
  return ctx.modelRegistry
223
198
  .getAvailable()
224
199
  .map((model) => ({ model, scoped: scoped.has(modelIdentity(model)) }));
225
200
  }
226
- /**
227
- * Resolve the selected housekeeping model against the live registry.
228
- * Undefined (feature inert) when unselected, unknown, unauthenticated or virtual.
229
- */
230
201
  export function resolveHousekeepingModel(ctx, identity) {
231
202
  const slash = identity.indexOf("/");
232
203
  if (slash <= 0)
@@ -238,7 +209,6 @@ export function resolveHousekeepingModel(ctx, identity) {
238
209
  return undefined;
239
210
  return model;
240
211
  }
241
- /** One-shot, tool-less completion through pi's provider-neutral registry API. */
242
212
  export function createHousekeepingCompleter(getContext, getModelIdentity, onUsageRecorded) {
243
213
  return async (request, signal) => {
244
214
  const ctx = getContext();
@@ -261,14 +231,12 @@ export function createHousekeepingCompleter(getContext, getModelIdentity, onUsag
261
231
  ],
262
232
  }, { signal, maxTokens: 96, cacheRetention: "none" })
263
233
  .result();
264
- // Account reported usage before checking whether this answer is usable or still current.
265
234
  const entry = reportHousekeepingUsage(session, response);
266
235
  try {
267
236
  if (entry && getContext() === ctx)
268
237
  onUsageRecorded?.(ctx);
269
238
  }
270
239
  catch {
271
- /* A stale context or UI failure must not turn a successful summary into a failure. */
272
240
  }
273
241
  if (response.stopReason === "error" || response.stopReason === "aborted")
274
242
  throw new Error(response.errorMessage || `Housekeeping model ${response.stopReason}`);
@@ -278,4 +246,3 @@ export function createHousekeepingCompleter(getContext, getModelIdentity, onUsag
278
246
  .join("");
279
247
  };
280
248
  }
281
- //# sourceMappingURL=housekeeping.js.map
@@ -1,8 +1,3 @@
1
- /**
2
- * Capture the public loadout API and a root execution bridge. Keep the bridge alive for
3
- * detached children, but always pass their signal rather than the spawning call's signal.
4
- * Built-ins and manager controls are replaced with child-local implementations by runtime.
5
- */
6
1
  export function createInheritedToolSource(pi) {
7
2
  let loadout;
8
3
  let context;
@@ -15,8 +10,6 @@ export function createInheritedToolSource(pi) {
15
10
  context = next;
16
11
  },
17
12
  reset() {
18
- // session_start is emitted after the replacement loadout is prepared; do not
19
- // discard that fresh snapshot (or an unchanged loadout on /tree).
20
13
  context = undefined;
21
14
  },
22
15
  snapshot() {
@@ -29,7 +22,6 @@ export function createInheritedToolSource(pi) {
29
22
  const tools = [];
30
23
  for (const tool of loadout.registered) {
31
24
  const exposure = loadout.getExposure(tool.name);
32
- // Inactive direct tools and hidden tools are not available in the root either.
33
25
  if (!callable.has(tool.name) && !active.has(tool.name))
34
26
  continue;
35
27
  if (exposure === "hidden")
@@ -37,8 +29,6 @@ export function createInheritedToolSource(pi) {
37
29
  const metadata = info.get(tool.name);
38
30
  tools.push({
39
31
  ...tool,
40
- // The root execution pipeline applies argument preparation. Running it in
41
- // the child too would corrupt non-idempotent preparation shims.
42
32
  prepareArguments: undefined,
43
33
  label: tool.label,
44
34
  exposure,
@@ -48,9 +38,6 @@ export function createInheritedToolSource(pi) {
48
38
  defaultActive: active.has(tool.name),
49
39
  async execute(_id, args, signal, onUpdate) {
50
40
  if (!callable.has(tool.name)) {
51
- // The SDK rejects nested model-only execution. Calling its captured
52
- // wrapper directly would bypass root permission/result hooks. Known
53
- // SDK orchestrators are instead recreated locally by runtime.
54
41
  throw new Error(`Cannot safely inherit model-only tool ${tool.name}: the SDK does not ` +
55
42
  "provide a hook-preserving execution bridge. Run it in the main session.");
56
43
  }
@@ -68,4 +55,3 @@ export function createInheritedToolSource(pi) {
68
55
  },
69
56
  };
70
57
  }
71
- //# sourceMappingURL=inherited-tools.js.map
@@ -193,4 +193,3 @@ export class DurableMailbox {
193
193
  }
194
194
  }
195
195
  }
196
- //# sourceMappingURL=mailbox.js.map
@@ -4,8 +4,8 @@ import { canonicalPath, inheritContext, isDescendant, parentPath } from "./paths
4
4
  import { DEFAULT_MANAGER_SETTINGS } from "../prefs/settings.js";
5
5
  const RECENT_ACTIVITY_LIMIT = 12;
6
6
  const active = (view) => view.state === "starting" || view.state === "running";
7
- export const MIN_SPAWN_TIMEOUT_MS = 30_000;
8
- export const MAX_SPAWN_TIMEOUT_MS = 300_000;
7
+ const MIN_SPAWN_TIMEOUT_MS = 30_000;
8
+ const MAX_SPAWN_TIMEOUT_MS = 300_000;
9
9
  function assertSpawnTimeout(timeoutMs) {
10
10
  if (!Number.isInteger(timeoutMs) ||
11
11
  timeoutMs < MIN_SPAWN_TIMEOUT_MS ||
@@ -30,7 +30,6 @@ function abortable(work, signal) {
30
30
  });
31
31
  });
32
32
  }
33
- /** Runtime-neutral thread ownership, context inheritance, lifecycle and durable registry. */
34
33
  export class ThreadManager {
35
34
  options;
36
35
  records = new Map();
@@ -39,14 +38,12 @@ export class ThreadManager {
39
38
  constructor(options) {
40
39
  this.options = options;
41
40
  }
42
- /** New limits affect future launches/resumes, never cancel existing work. */
43
41
  setLimits(limits) {
44
42
  this.options = { ...this.options, ...limits };
45
43
  }
46
44
  list() {
47
45
  return [...this.records.values()].map((record) => this.view(record));
48
46
  }
49
- /** Preview eligible completed sessions without changing retained records. */
50
47
  reapCandidates(only) {
51
48
  this.assertLive();
52
49
  const records = [...this.records.values()];
@@ -55,7 +52,6 @@ export class ThreadManager {
55
52
  .filter((record) => record.view.state === "completed" && (!record.initializing || record.driver))
56
53
  .filter((record) => !records.some((other) => active(other.view) && isDescendant(record.view.path, other.view.path)))
57
54
  .map((record) => record.view.path));
58
- // Any retained descendant still needs its lexical ancestors.
59
55
  for (const record of records) {
60
56
  if (eligible.has(record.view.path))
61
57
  continue;
@@ -70,7 +66,6 @@ export class ThreadManager {
70
66
  .sort((a, b) => a.view.createdAt - b.view.createdAt)
71
67
  .map((record) => record.view.path);
72
68
  }
73
- /** Revalidate an optional confirmed snapshot before forgetting sessions. */
74
69
  reap(only) {
75
70
  const reaped = [];
76
71
  for (const path of this.reapCandidates(only)) {
@@ -84,7 +79,6 @@ export class ThreadManager {
84
79
  }
85
80
  return reaped;
86
81
  }
87
- /** Bind authority once; models and the user UI share this small composable service. */
88
82
  scope(caller) {
89
83
  caller = canonicalPath(caller);
90
84
  return {
@@ -121,13 +115,12 @@ export class ThreadManager {
121
115
  output(path, caller = "/root") {
122
116
  const view = this.get(path, caller);
123
117
  if (view.state === "paused")
124
- return ""; // No answer handback from a paused turn.
118
+ return "";
125
119
  return view.output ?? "";
126
120
  }
127
121
  saved() {
128
122
  return [...this.records.values()].map((record) => {
129
123
  const current = this.view(record);
130
- // Explicit durable schema: adding UI fields must not silently change session storage.
131
124
  const view = {
132
125
  path: current.path,
133
126
  parent: current.parent,
@@ -145,7 +138,6 @@ export class ThreadManager {
145
138
  createdAt: current.createdAt,
146
139
  ...(current.lastStartedAt !== undefined ? { lastStartedAt: current.lastStartedAt } : {}),
147
140
  sessionFile: current.sessionFile,
148
- // Settled totals only. startedAt and partial usage must not churn persistence.
149
141
  elapsedMs: record.view.elapsedMs ?? 0,
150
142
  inputTokens: record.view.inputTokens ?? 0,
151
143
  outputTokens: record.view.outputTokens ?? 0,
@@ -204,7 +196,6 @@ export class ThreadManager {
204
196
  definition: structuredClone(item.definition),
205
197
  inherited: structuredClone(item.inherited ?? []),
206
198
  inheritedContextEntries: structuredClone(item.inheritedContextEntries ?? []),
207
- // A reservation saved before its lexical parent opened has no snapshot yet.
208
199
  contextPending: !view.sessionFile && item.inherited === undefined && view.parent !== null,
209
200
  startup: new AbortController(),
210
201
  ...(Object.prototype.hasOwnProperty.call(savedView, "sessionLeafId")
@@ -241,7 +232,6 @@ export class ThreadManager {
241
232
  if (!args.task.trim())
242
233
  throw new Error("Task must not be empty");
243
234
  const segments = path.slice(1).split("/");
244
- // Independent roots still represent agents launched by the main L1 conversation.
245
235
  const level = segments.length + (segments[0] === "root" ? 0 : 1);
246
236
  const maxLevels = this.options.maxLevels ?? DEFAULT_MANAGER_SETTINGS.maxLevels;
247
237
  if (this.options.maxLevels === undefined && this.options.maxDepth !== undefined
@@ -254,7 +244,6 @@ export class ThreadManager {
254
244
  const type = structuredClone(this.options.getType(args.type));
255
245
  const parentRecord = parent && parent !== "/root" ? this.record(parent) : undefined;
256
246
  this.assertStartableAncestors(path);
257
- // Reservation is synchronous: subtree cancellation sees children even during lazy parent reopen.
258
247
  const inherited = parent === "/root"
259
248
  ? inheritContext(this.options.rootSnapshot())
260
249
  : parentRecord?.driver
@@ -299,10 +288,6 @@ export class ThreadManager {
299
288
  this.armTimeout(record, args.timeoutMs);
300
289
  return args.wait === false ? this.view(record) : this.wait(caller, path, undefined, signal);
301
290
  }
302
- /**
303
- * Steer/resume a thread and/or re-arm its report-only timeout.
304
- * timeoutMs without message only re-arms (the child must be running); both does steer then re-arm.
305
- */
306
291
  async steer(caller, path, message, timeoutMs) {
307
292
  this.assertLive();
308
293
  caller = canonicalPath(caller);
@@ -327,7 +312,6 @@ export class ThreadManager {
327
312
  this.assertCallerMaySteer(caller);
328
313
  if (!active(record.view))
329
314
  this.assertStartableAncestors(path);
330
- // A detached spawn reserves immediately, but its original task must reach prompt() before steering.
331
315
  if (record.view.state === "starting") {
332
316
  if (!record.started)
333
317
  throw new Error("Thread start invariant violated");
@@ -342,7 +326,6 @@ export class ThreadManager {
342
326
  return rearm();
343
327
  }
344
328
  this.assertCapacity();
345
- // Resumes return immediately, regardless of the original spawn mode or restored metadata.
346
329
  record.async = true;
347
330
  this.start(record, message);
348
331
  return rearm();
@@ -382,7 +365,6 @@ export class ThreadManager {
382
365
  if (!message.trim() || message.length > 8000)
383
366
  throw new Error("Progress message must contain 1–8000 characters");
384
367
  record.view.status = message;
385
- // An explicit progress report outranks a generated summary until fresh activity.
386
368
  delete record.view.summary;
387
369
  this.touch(record);
388
370
  this.emit({
@@ -401,7 +383,6 @@ export class ThreadManager {
401
383
  record.view.status = reason.trim() || "Awaiting further input";
402
384
  delete record.view.summary;
403
385
  this.touch(record);
404
- // Remains running until the SDK settles. No interim final answer leaks through wait().
405
386
  return this.view(record);
406
387
  }
407
388
  async stop(caller, path) {
@@ -438,7 +419,6 @@ export class ThreadManager {
438
419
  if (path === "/root")
439
420
  throw new Error("Main is not a child transcript observation target");
440
421
  const record = this.record(path);
441
- // Idle/restored history may be lazily loaded, but attachment never prompts/resumes a turn.
442
422
  if (!active(record.view))
443
423
  await this.ensureDriver(record, true);
444
424
  this.assertLive();
@@ -448,7 +428,6 @@ export class ThreadManager {
448
428
  if (record.driver)
449
429
  this.attachTranscript(record, record.driver);
450
430
  else {
451
- // A starting child gets a placeholder immediately; existing startup supplies the live source.
452
431
  void this.ensureDriver(record, true).catch((error) => {
453
432
  if (this.disposed || !listeners.has(registered))
454
433
  return;
@@ -468,7 +447,6 @@ export class ThreadManager {
468
447
  },
469
448
  };
470
449
  }
471
- /** Re-arm a running child's report-only timeout from now (replaces any pending timer). */
472
450
  extendTimeout(caller, path, timeoutMs) {
473
451
  this.assertLive();
474
452
  path = canonicalPath(path, caller);
@@ -480,7 +458,6 @@ export class ThreadManager {
480
458
  this.armTimeout(record, timeoutMs);
481
459
  return this.view(record);
482
460
  }
483
- /** Number of detached agents still working; recap waits for this to reach zero. */
484
461
  outstandingAsync() {
485
462
  return [...this.records.values()].filter((r) => r.async && active(r.view)).length;
486
463
  }
@@ -526,12 +503,10 @@ export class ThreadManager {
526
503
  }
527
504
  }
528
505
  catch {
529
- /* best effort */
530
506
  }
531
507
  return parts.slice(-2).join("\n---\n").slice(-2000);
532
508
  }
533
509
  async deliver(path, content) {
534
- // Restored parents may be idle and unopened; reports still belong in their retained transcript.
535
510
  const driver = await this.ensureDriver(this.record(path), true);
536
511
  await driver.sendUpdate(content);
537
512
  }
@@ -611,12 +586,11 @@ export class ThreadManager {
611
586
  finally {
612
587
  this.clearTimeout(record);
613
588
  this.freezeElapsed(record);
614
- // A settled agent shows its real status; summaries describe active work only.
615
589
  delete record.view.summary;
616
590
  record.liveInputTokens = 0;
617
591
  record.liveOutputTokens = 0;
618
592
  record.liveCostUsd = undefined;
619
- markStarted(); // Failed/cancelled initialization must also release callers waiting to steer.
593
+ markStarted();
620
594
  this.touch(record);
621
595
  if (!this.disposed && epoch === this.epoch)
622
596
  this.emit({
@@ -638,7 +612,6 @@ export class ThreadManager {
638
612
  let diagnosticDriver;
639
613
  const creation = Promise.resolve()
640
614
  .then(async () => {
641
- // Inspection and delivery can initialize a reserved child before start().
642
615
  const contextReady = this.prepareInheritedContext(record, readOnly);
643
616
  if (contextReady)
644
617
  await abortable(contextReady, signal);
@@ -781,11 +754,9 @@ export class ThreadManager {
781
754
  listener(snapshot);
782
755
  }
783
756
  catch {
784
- /* UI failure must not affect execution. */
785
757
  }
786
758
  }
787
759
  }
788
- /** Bounded activity context for the housekeeping summarizer; never affects lifecycle. */
789
760
  recordActivity(record, line) {
790
761
  const recent = (record.recentActivity ??= []);
791
762
  recent.push(line.slice(0, 600));
@@ -803,10 +774,8 @@ export class ThreadManager {
803
774
  });
804
775
  }
805
776
  catch {
806
- /* Optional labs feature: never interrupt a runner. */
807
777
  }
808
778
  }
809
- /** [labs] Apply a generated one-line summary; false when stale (run changed, settled, paused or gone). */
810
779
  setSummary(path, run, summary) {
811
780
  const record = this.records.get(path);
812
781
  const text = summary.replace(/\s+/g, " ").trim();
@@ -821,12 +790,10 @@ export class ThreadManager {
821
790
  if (record.view.summary === text)
822
791
  return true;
823
792
  record.view.summary = text;
824
- // Display-only: a metrics event refreshes UI without rewriting persisted registry/cost state.
825
793
  if (!this.disposed)
826
794
  this.emit({ kind: "metrics", thread: this.view(record) });
827
795
  return true;
828
796
  }
829
- /** [labs] Remove one run's summary (stale refresh failed/unavailable); no-op for other runs or none. */
830
797
  clearSummary(path, run) {
831
798
  const record = this.records.get(path);
832
799
  if (this.disposed || !record || record.runId !== run || record.view.summary === undefined)
@@ -835,7 +802,6 @@ export class ThreadManager {
835
802
  this.emit({ kind: "metrics", thread: this.view(record) });
836
803
  return true;
837
804
  }
838
- /** Drop every generated summary (feature disabled or model changed). */
839
805
  clearSummaries() {
840
806
  for (const record of this.records.values()) {
841
807
  if (record.view.summary === undefined)
@@ -850,8 +816,6 @@ export class ThreadManager {
850
816
  this.options.onEvent?.(event);
851
817
  }
852
818
  catch (error) {
853
- // Widgets/persistence/delivery run on the runner's event path. An exception
854
- // here must not orphan a prompt promise or reject detached settlement.
855
819
  try {
856
820
  if (this.options.onEventError)
857
821
  this.options.onEventError(error, event);
@@ -859,7 +823,6 @@ export class ThreadManager {
859
823
  console.warn(`Subagent ${event.kind} notification failed: ${errorText(error)}`);
860
824
  }
861
825
  catch {
862
- /* A failing diagnostic sink must not turn a notification into a crash. */
863
826
  }
864
827
  }
865
828
  }
@@ -869,7 +832,6 @@ export class ThreadManager {
869
832
  if (!this.disposed)
870
833
  this.emit({ kind: "change", thread: this.view(record) });
871
834
  }
872
- /** Fold driver-cumulative usage into persisted totals. Partials only refresh the live view. */
873
835
  applyUsage(record, event) {
874
836
  const cursor = record.usageCursor ?? { input: 0, output: 0 };
875
837
  const costUsd = event.costUsd !== undefined && Number.isFinite(event.costUsd) && event.costUsd >= 0
@@ -947,7 +909,6 @@ export class ThreadManager {
947
909
  const leaf = record.driver?.sessionLeafId;
948
910
  return leaf !== undefined ? leaf : record.sessionLeafId;
949
911
  }
950
- /** Live persisted file, else the saved file of a restored parent that has not been opened. */
951
912
  lexicalParentSessionFile(record) {
952
913
  const parent = record.view.parent;
953
914
  if (!parent || parent === "/root")
@@ -1007,4 +968,3 @@ export class ThreadManager {
1007
968
  throw new Error(`${caller} may address only its descendants (not siblings, unrelated trees or ancestors)`);
1008
969
  }
1009
970
  }
1010
- //# sourceMappingURL=manager.js.map
@@ -17,7 +17,6 @@ export function parentPath(path) {
17
17
  export function isDescendant(path, ancestor) {
18
18
  return path.startsWith(`${ancestor}/`);
19
19
  }
20
- /** Snapshot conversation, not the parent's prompt/loadout; retain only matched tool exchanges. */
21
20
  export function inheritContext(messages) {
22
21
  const copy = structuredClone(messages);
23
22
  const matchedCalls = new Set();
@@ -51,7 +50,6 @@ export function inheritContext(messages) {
51
50
  pending.delete(message.toolCallId);
52
51
  }
53
52
  return copy.flatMap((message, messageIndex) => {
54
- // Only the system prompt/loadout is replaced; custom and shell messages are real conversation context.
55
53
  if (message.role === "system")
56
54
  return [];
57
55
  if (message.role === "assistant") {
@@ -60,7 +58,6 @@ export function inheritContext(messages) {
60
58
  message.content = message.content.filter((block, blockIndex) => block.type !== "toolCall" || matchedCalls.has(`${messageIndex}:${blockIndex}`));
61
59
  if (!message.content.length)
62
60
  return [];
63
- // A tools-only assistant without remaining calls should not claim a toolUse stop.
64
61
  if (message.stopReason === "toolUse" &&
65
62
  !message.content.some((block) => block.type === "toolCall"))
66
63
  message.stopReason = "stop";
@@ -70,4 +67,3 @@ export function inheritContext(messages) {
70
67
  return [message];
71
68
  });
72
69
  }
73
- //# sourceMappingURL=paths.js.map
@@ -4,10 +4,7 @@ export function delegationGuidance(canSpawnChildren) {
4
4
  ? "You may spawn subagents of your own if useful, subject to your tools, assigned scope, and shared concurrency limits."
5
5
  : "You are at the maximum agent depth and cannot spawn any more subagents. Complete your assigned work yourself.";
6
6
  }
7
- /** Root-only guidance: child SDK sessions use their own worker prompt. */
8
- export function subagentPrompt(settings,
9
- /** Caller-verified pi-checklist eligibility; ignored unless the Labs opt-in is also on. */
10
- checklistEligible = false) {
7
+ export function subagentPrompt(settings, checklistEligible = false) {
11
8
  if (settings.subagentMode === "off")
12
9
  return undefined;
13
10
  const policy = settings.subagentMode === "orchestration"
@@ -31,4 +28,3 @@ checklistEligible = false) {
31
28
  : []),
32
29
  ].join("\n");
33
30
  }
34
- //# sourceMappingURL=prompt.js.map
@@ -1,15 +1,5 @@
1
- /** Every retained thread. Written first after each attach and whenever threads are removed. */
2
1
  export const REGISTRY_ENTRY = "pi-subagent:registry:v1";
3
- /**
4
- * What changed since the previous registry entry on the branch. Each child checkpoint changes a
5
- * few view fields of one thread; rewriting the whole registry for each grew root sessions by
6
- * gigabytes, and Pi holds every session entry in memory.
7
- */
8
2
  export const REGISTRY_DELTA_ENTRY = "pi-subagent:registry-delta:v1";
9
- /**
10
- * The registry saved on a branch: its last full entry with every later delta applied in order.
11
- * Returns undefined when the branch has no registry. Throws on malformed entries.
12
- */
13
3
  export function readRegistry(branch) {
14
4
  const deltas = [];
15
5
  for (let index = branch.length - 1; index >= 0; index--) {
@@ -42,7 +32,6 @@ function parseDelta(data, rootSessionId) {
42
32
  function applyDeltas(base, deltas) {
43
33
  if (!deltas.length)
44
34
  return base;
45
- // Map insertion order is registry order: changes replace in place, added threads append.
46
35
  const threads = new Map(base.threads.map((thread) => [thread.view.path, thread]));
47
36
  if (threads.size !== base.threads.length)
48
37
  throw new Error("Invalid registry format: duplicate thread path");
@@ -65,9 +54,7 @@ function applyDeltas(base, deltas) {
65
54
  }
66
55
  function serialize(thread) {
67
56
  const { view, ...rest } = thread;
68
- const fields = Object.entries(view).flatMap(([field, value]) =>
69
- // JSON omits undefined fields, so they read back as cleared.
70
- value === undefined ? [] : [[field, JSON.stringify(value)]]);
57
+ const fields = Object.entries(view).flatMap(([field, value]) => value === undefined ? [] : [[field, JSON.stringify(value)]]);
71
58
  return { view: new Map(fields), rest: JSON.stringify(rest) };
72
59
  }
73
60
  function threadChange(thread, next, previous) {
@@ -87,15 +74,12 @@ function threadChange(thread, next, previous) {
87
74
  ...(cleared.length ? { cleared: cleared } : {}),
88
75
  };
89
76
  }
90
- /** Appends registry entries so that readRegistry() on the current branch returns the last write. */
91
77
  export class RegistryWriter {
92
78
  append;
93
- /** The threads, in order, that readRegistry() returns for the current branch. */
94
79
  persisted;
95
80
  constructor(append) {
96
81
  this.append = append;
97
82
  }
98
- /** The session or branch changed: the next write must be a full registry. */
99
83
  reset() {
100
84
  this.persisted = undefined;
101
85
  }
@@ -117,11 +101,9 @@ export class RegistryWriter {
117
101
  else {
118
102
  this.append(REGISTRY_ENTRY, { version: 1, rootSessionId, threads });
119
103
  }
120
- // After the append: a failed write must not become the base for the next delta.
121
104
  this.persisted = { rootSessionId, threads: next };
122
105
  }
123
106
  }
124
- /** A delta cannot remove or reorder threads: every persisted path must keep its position. */
125
107
  function keepsOrder(persisted, threads) {
126
108
  let index = 0;
127
109
  for (const path of persisted.keys()) {
@@ -131,4 +113,3 @@ function keepsOrder(persisted, threads) {
131
113
  }
132
114
  return true;
133
115
  }
134
- //# sourceMappingURL=registry.js.map