pi-subagents 0.84.0 → 0.86.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 (210) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/bundle/agents.js +3 -3
  3. package/bundle/child-tool-plan.js +2 -2
  4. package/bundle/{chunk-JG4QKI5M.js → chunk-2IYBCYFU.js} +214 -97
  5. package/bundle/{chunk-V2BZYLEP.js → chunk-374MZFF4.js} +7 -2
  6. package/bundle/{chunk-4E7BKDTX.js → chunk-3RKFH2UZ.js} +11 -156
  7. package/bundle/{chunk-F4ASL6OV.js → chunk-5H4BICQZ.js} +1 -1
  8. package/bundle/{chunk-PALJGGYC.js → chunk-6VD7BGIC.js} +6 -3
  9. package/bundle/{chunk-C5P5CHYK.js → chunk-77ASNIEM.js} +1 -1
  10. package/bundle/{chunk-XDQORLZ5.js → chunk-7ADDXUGF.js} +15 -6
  11. package/bundle/{chunk-PV63UFUR.js → chunk-7QA7ZA46.js} +183 -28
  12. package/bundle/{chunk-NKQ6JNAS.js → chunk-7ZUFN6ME.js} +2 -1
  13. package/bundle/{chunk-SSG7IEP5.js → chunk-A637IMAO.js} +2 -2
  14. package/bundle/{chunk-L3WFKBEI.js → chunk-BGXEAYUM.js} +247 -153
  15. package/bundle/{chunk-J5YL7LYR.js → chunk-BU6PFPVX.js} +59 -27
  16. package/bundle/{chunk-DZDETGRJ.js → chunk-BWC2LVII.js} +259 -216
  17. package/bundle/{chunk-CGN2TVE7.js → chunk-GJGTMLPE.js} +322 -18
  18. package/bundle/{chunk-D3JAFGMO.js → chunk-GRJHIXYF.js} +1 -1
  19. package/bundle/chunk-HXRB42AF.js +108 -0
  20. package/bundle/{chunk-LFDBD4PW.js → chunk-LGINOOY5.js} +2 -2
  21. package/bundle/{chunk-G2Z6ZH26.js → chunk-NAFLUJ26.js} +1 -1
  22. package/bundle/{chunk-235AWJUQ.js → chunk-O3YH7XIY.js} +324 -111
  23. package/bundle/{chunk-2DHZTCOL.js → chunk-PYOAIN3V.js} +2 -2
  24. package/bundle/{chunk-LNRJCP2Y.js → chunk-QGO6HXHG.js} +417 -242
  25. package/bundle/{chunk-VQVVHSY6.js → chunk-QM3JGE4W.js} +22 -11
  26. package/bundle/{chunk-2S4K53MV.js → chunk-S2Q75LP3.js} +1 -1
  27. package/bundle/{chunk-NENDSQUY.js → chunk-UR7OW5S7.js} +9 -6
  28. package/bundle/{chunk-AKOIVLA5.js → chunk-WN2E5XHN.js} +135 -77
  29. package/bundle/{chunk-2D52JFLF.js → chunk-YK3QYNLE.js} +41 -117
  30. package/bundle/{chunk-7BWGNDNK.js → chunk-ZJJCPV3L.js} +190 -1177
  31. package/bundle/chunk-ZPY5QZCS.js +1067 -0
  32. package/bundle/control-channel.js +2 -2
  33. package/bundle/index.js +1 -1
  34. package/bundle/intercom-bridge.js +2 -2
  35. package/bundle/preflight.js +8 -8
  36. package/bundle/project-panes.js +3 -3
  37. package/docs/agents.md +23 -2
  38. package/docs/configuration.md +4 -4
  39. package/docs/extension-api.md +16 -1
  40. package/docs/tool-reference.md +2 -0
  41. package/docs/workflows.md +30 -2
  42. package/package.json +1 -1
  43. package/src/agents/agent-management.js +27 -11
  44. package/src/agents/agent-memory.d.ts +1 -4
  45. package/src/agents/agent-memory.js +1 -4
  46. package/src/agents/agents.d.ts +1 -3
  47. package/src/agents/agents.js +7 -6
  48. package/src/agents/frontmatter.js +1 -8
  49. package/src/agents/global-npm-root.d.ts +1 -0
  50. package/src/agents/global-npm-root.js +11 -3
  51. package/src/agents/skills.d.ts +0 -3
  52. package/src/agents/skills.js +0 -3
  53. package/src/extension/config.js +7 -1
  54. package/src/extension/herdr-pi-bridge.js +10 -2
  55. package/src/extension/index.d.ts +0 -13
  56. package/src/extension/index.js +43 -32
  57. package/src/extension/public-execution.d.ts +1 -0
  58. package/src/extension/public-execution.js +4 -0
  59. package/src/extension/reply-workflow-script.js +24 -4
  60. package/src/extension/schemas.d.ts +8 -3
  61. package/src/extension/schemas.js +5 -3
  62. package/src/extension/session-switch.d.ts +25 -0
  63. package/src/extension/session-switch.js +138 -0
  64. package/src/extension/subagent-guide.d.ts +1 -1
  65. package/src/extension/subagent-guide.js +1 -1
  66. package/src/extension/subagent-launch-tool.d.ts +25 -0
  67. package/src/extension/subagent-launch-tool.js +48 -0
  68. package/src/extension/tool-activation.js +35 -12
  69. package/src/extension/tool-description.d.ts +1 -1
  70. package/src/extension/tool-description.js +14 -8
  71. package/src/inspectors/herdr/actions.d.ts +0 -1
  72. package/src/inspectors/herdr/actions.js +0 -1
  73. package/src/inspectors/session-roots-codec.d.ts +0 -1
  74. package/src/inspectors/session-roots-codec.js +0 -1
  75. package/src/inspectors/tmux/actions.d.ts +0 -1
  76. package/src/inspectors/tmux/actions.js +0 -1
  77. package/src/integrations/herdr-status.js +3 -8
  78. package/src/intercom/native-supervisor-channel.js +65 -9
  79. package/src/runs/background/async-execution.d.ts +5 -9
  80. package/src/runs/background/async-execution.js +62 -27
  81. package/src/runs/background/async-job-tracker.js +12 -0
  82. package/src/runs/background/async-resume.d.ts +2 -1
  83. package/src/runs/background/async-resume.js +112 -39
  84. package/src/runs/background/async-retention.js +6 -1
  85. package/src/runs/background/auto-drain.js +2 -1
  86. package/src/runs/background/boot-id.d.ts +1 -3
  87. package/src/runs/background/boot-id.js +1 -3
  88. package/src/runs/background/completion-batcher.d.ts +3 -4
  89. package/src/runs/background/completion-batcher.js +2 -3
  90. package/src/runs/background/control-channel.d.ts +0 -6
  91. package/src/runs/background/control-channel.js +0 -6
  92. package/src/runs/background/fleet-view.js +2 -3
  93. package/src/runs/background/notify.d.ts +0 -2
  94. package/src/runs/background/notify.js +0 -2
  95. package/src/runs/background/result-watcher.d.ts +1 -0
  96. package/src/runs/background/result-watcher.js +59 -29
  97. package/src/runs/background/resume-guidance.js +4 -2
  98. package/src/runs/background/retained-children.js +2 -1
  99. package/src/runs/background/run-child-session.d.ts +0 -1
  100. package/src/runs/background/run-child-session.js +1 -1
  101. package/src/runs/background/run-status.js +9 -7
  102. package/src/runs/background/scheduled-runs.d.ts +3 -1
  103. package/src/runs/background/scheduled-runs.js +13 -16
  104. package/src/runs/background/subagent-runner.d.ts +2 -4
  105. package/src/runs/background/subagent-runner.js +15 -12
  106. package/src/runs/background/subagent-wait.js +12 -15
  107. package/src/runs/background/wait-config.d.ts +2 -0
  108. package/src/runs/background/wait-config.js +17 -3
  109. package/src/runs/background/wait-tool.js +4 -2
  110. package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
  111. package/src/runs/background/workflow-terminal-proof.js +0 -1
  112. package/src/runs/foreground/execution.d.ts +0 -3
  113. package/src/runs/foreground/execution.js +17 -9
  114. package/src/runs/foreground/subagent-executor.d.ts +3 -2
  115. package/src/runs/foreground/subagent-executor.js +107 -26
  116. package/src/runs/shared/acceptance.js +69 -26
  117. package/src/runs/shared/child-commands.js +15 -2
  118. package/src/runs/shared/child-hooks.d.ts +1 -7
  119. package/src/runs/shared/child-hooks.js +13 -5
  120. package/src/runs/shared/child-launch.js +6 -2
  121. package/src/runs/shared/child-runtime-config.d.ts +0 -1
  122. package/src/runs/shared/child-session.d.ts +1 -1
  123. package/src/runs/shared/child-session.js +21 -2
  124. package/src/runs/shared/child-tool-plan.d.ts +0 -1
  125. package/src/runs/shared/child-tool-plan.js +0 -1
  126. package/src/runs/shared/claude-code-adapter.js +11 -0
  127. package/src/runs/shared/external-cli-contract.d.ts +49 -0
  128. package/src/runs/shared/external-cli-contract.js +18 -13
  129. package/src/runs/shared/external-cli-runner.js +26 -6
  130. package/src/runs/shared/herdr-connection.js +2 -1
  131. package/src/runs/shared/herdr-pane-host.d.ts +2 -2
  132. package/src/runs/shared/herdr-pane-host.js +17 -1
  133. package/src/runs/shared/herdr-placed-run.js +48 -22
  134. package/src/runs/shared/lane-metadata.d.ts +0 -1
  135. package/src/runs/shared/lane-metadata.js +0 -1
  136. package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
  137. package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
  138. package/src/runs/shared/model-resolution.d.ts +2 -2
  139. package/src/runs/shared/model-resolution.js +7 -1
  140. package/src/runs/shared/model-scope.d.ts +1 -5
  141. package/src/runs/shared/model-scope.js +1 -5
  142. package/src/runs/shared/mutation-evidence.d.ts +1 -1
  143. package/src/runs/shared/mutation-evidence.js +52 -7
  144. package/src/runs/shared/nested-events.d.ts +1 -0
  145. package/src/runs/shared/nested-events.js +1 -1
  146. package/src/runs/shared/parallel-utils.d.ts +0 -1
  147. package/src/runs/shared/permissions.js +5 -3
  148. package/src/runs/shared/placement-host.d.ts +5 -1
  149. package/src/runs/shared/rex-pane-host.d.ts +0 -1
  150. package/src/runs/shared/rex-pane-host.js +0 -2
  151. package/src/runs/shared/run-launch-folder.d.ts +12 -0
  152. package/src/runs/shared/run-launch-folder.js +21 -0
  153. package/src/runs/shared/runner-launcher.d.ts +12 -1
  154. package/src/runs/shared/runner-launcher.js +16 -0
  155. package/src/runs/shared/single-output.d.ts +3 -3
  156. package/src/runs/shared/single-output.js +5 -3
  157. package/src/runs/shared/structured-output.d.ts +8 -0
  158. package/src/runs/shared/structured-output.js +40 -5
  159. package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
  160. package/src/runs/shared/subagent-prompt-runtime.js +4 -2
  161. package/src/runs/shared/tool-timeout.js +2 -1
  162. package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
  163. package/src/runs/shared/worktree-cleanup-plan.js +0 -1
  164. package/src/runs/shared/worktree.d.ts +3 -0
  165. package/src/runs/shared/worktree.js +20 -0
  166. package/src/shared/capacity-resilient-json.d.ts +1 -1
  167. package/src/shared/child-cache-retention.d.ts +1 -2
  168. package/src/shared/child-cache-retention.js +1 -2
  169. package/src/shared/fleet-transcript-reader.d.ts +51 -0
  170. package/src/shared/fleet-transcript-reader.js +333 -0
  171. package/src/shared/formatters.d.ts +0 -18
  172. package/src/shared/formatters.js +0 -18
  173. package/src/shared/session-succession.d.ts +16 -1
  174. package/src/shared/session-succession.js +41 -2
  175. package/src/shared/session-warnings.d.ts +7 -0
  176. package/src/shared/session-warnings.js +26 -0
  177. package/src/shared/settings.d.ts +0 -23
  178. package/src/shared/settings.js +3 -35
  179. package/src/shared/types.d.ts +85 -59
  180. package/src/shared/types.js +0 -12
  181. package/src/shared/utils.d.ts +0 -14
  182. package/src/shared/utils.js +0 -22
  183. package/src/shared/wait-tool-name.d.ts +8 -0
  184. package/src/shared/wait-tool-name.js +13 -0
  185. package/src/slash/slash-commands.js +2 -1
  186. package/src/slash/subagent-cost.d.ts +3 -2
  187. package/src/slash/subagent-cost.js +22 -3
  188. package/src/slash/subagents-admin.js +0 -1
  189. package/src/tui/fleet-status.d.ts +0 -5
  190. package/src/tui/fleet-status.js +4 -24
  191. package/src/tui/fleet-transcript.d.ts +1 -44
  192. package/src/tui/fleet-transcript.js +1 -327
  193. package/src/tui/fleet.js +6 -4
  194. package/src/tui/render.d.ts +0 -9
  195. package/src/tui/render.js +161 -66
  196. package/src/tui/subagent-messages.js +3 -2
  197. package/src/watchdog/register-child.d.ts +2 -3
  198. package/src/watchdog/register-child.js +2 -3
  199. package/src/watchdog/turn-delta.js +2 -1
  200. package/src/workflows/scripted-workflow.js +241 -20
  201. package/src/workflows/workflow-launch-record.d.ts +15 -6
  202. package/src/workflows/workflow-launch-record.js +30 -12
  203. package/src/workflows/workflow-receipt.js +36 -53
  204. package/src/workflows/workflow-resume-claim.js +2 -2
  205. package/src/workflows/workflow-resume.d.ts +1 -1
  206. package/src/workflows/workflow-resume.js +11 -8
  207. package/src/workflows/workflow-script-worker.d.ts +13 -0
  208. package/src/workflows/workflow-script-worker.js +79 -0
  209. package/workflow-script-process.cjs +36 -0
  210. package/workflow-script-worker.cjs +4 -1
@@ -1,22 +1,18 @@
1
1
  import {
2
2
  PLACED_RESTORE_UNSUPPORTED,
3
- REX_BUNDLE_BIN,
4
- REX_CALL_TIMEOUT_MS,
5
- REX_EXIT_GONE,
6
- REX_EXIT_UNREACHABLE,
7
- REX_MAX_OUTPUT,
8
3
  connectHerdrMachine,
9
- isRexLocalMachine,
10
4
  remoteShellCommand,
11
- resolveRexBinary,
12
- rexCommandEnv,
13
- rexGlobalArgs,
14
5
  runBoundedCommand,
15
6
  sshMachineAccess
16
- } from "./chunk-2D52JFLF.js";
7
+ } from "./chunk-YK3QYNLE.js";
17
8
  import {
18
9
  package_default
19
- } from "./chunk-NKQ6JNAS.js";
10
+ } from "./chunk-7ZUFN6ME.js";
11
+ import {
12
+ ensureSupervisorChannelDir
13
+ } from "./chunk-ZPY5QZCS.js";
14
+ import "./chunk-HXRB42AF.js";
15
+ import "./chunk-NIXWDZZV.js";
20
16
  import {
21
17
  HERDR_PI_MODE_ENV,
22
18
  HERDR_PI_PROTOCOL,
@@ -27,9 +23,18 @@ import {
27
23
  validateHerdrPiRunId
28
24
  } from "./chunk-4QFZZV3O.js";
29
25
  import {
26
+ REX_BUNDLE_BIN,
27
+ REX_CALL_TIMEOUT_MS,
28
+ REX_EXIT_GONE,
29
+ REX_EXIT_UNREACHABLE,
30
+ REX_MAX_OUTPUT,
30
31
  getAgentDir,
31
- getPiSpawnCommand
32
- } from "./chunk-LNRJCP2Y.js";
32
+ getPiSpawnCommand,
33
+ isRexLocalMachine,
34
+ resolveRexBinary,
35
+ rexCommandEnv,
36
+ rexGlobalArgs
37
+ } from "./chunk-QGO6HXHG.js";
33
38
  import "./chunk-JEZOSEWG.js";
34
39
  import "./chunk-YFCK7H2S.js";
35
40
  import "./chunk-QXASAHIA.js";
@@ -459,8 +464,18 @@ var herdrPaneHost = {
459
464
  const { terminalId } = await startHerdrAgent(connection, owned, request.kind, request.name, request.args, options);
460
465
  return { owned, terminalId };
461
466
  },
462
- async prompt(connection, identity, text) {
463
- await connection.client.call("agent.prompt", { target: identity.agentName, text });
467
+ async prompt(connection, identity, text, options = {}) {
468
+ const clock = options.clock ?? { now: () => Date.now(), wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)) }, deadline = clock.now() + (options.timeoutMs ?? 5e3), pollMs = options.pollMs ?? 100;
469
+ for (; ; ) {
470
+ try {
471
+ await connection.client.call("agent.prompt", { target: identity.agentName, text });
472
+ return;
473
+ } catch (error) {
474
+ if (!(error instanceof Error) || !error.message.includes("is not an active named agent") || clock.now() >= deadline) throw error;
475
+ await clock.wait(Math.min(pollMs, deadline - clock.now()));
476
+ if (options.stopped?.()) throw new Error("Remote Pi prompt was not sent because the run was stopped.", { cause: error });
477
+ }
478
+ }
464
479
  },
465
480
  subscribe(connection, paneId, listener, onDisconnect) {
466
481
  return connection.client.subscribe(herdrStatusSubscriptions(paneId), listener, onDisconnect);
@@ -964,6 +979,7 @@ var HerdrPiSession = class {
964
979
  #reconnectFactory;
965
980
  #reconnectFailure;
966
981
  #replyTimer;
982
+ #repliesInFlight = /* @__PURE__ */ new Set();
967
983
  supervisorDir;
968
984
  runtime;
969
985
  owner;
@@ -978,20 +994,35 @@ var HerdrPiSession = class {
978
994
  this.#initialGit = initialGit;
979
995
  bridge.adopt((frame) => this.#frame(frame));
980
996
  if (this.supervisorDir) {
981
- this.#replyTimer = setInterval(() => {
982
- const replies = path5.join(this.supervisorDir, "replies");
983
- for (const name of fs3.existsSync(replies) ? fs3.readdirSync(replies) : []) {
984
- const file = path5.join(replies, name);
985
- try {
986
- const value = JSON.parse(fs3.readFileSync(file, "utf8"));
987
- if (typeof value.message === "string" && typeof value.requestId === "string") void this.#operation("supervisor-reply", value.message, value.requestId, typeof value.error === "string" ? value.error : void 0).then(() => fs3.rmSync(file, { force: true }));
988
- } catch {
989
- }
990
- }
991
- }, 50);
997
+ this.#replyTimer = setInterval(() => this.#deliverSupervisorReplies(this.supervisorDir), 50);
992
998
  this.#replyTimer.unref?.();
993
999
  }
994
1000
  }
1001
+ // Runs on a timer, where a throw or an unhandled rejection exits Pi. A reply that can't be read or delivered stays
1002
+ // on disk for the next tick, once its earlier delivery has settled; a lost transport reaches the session through the
1003
+ // bridge failure.
1004
+ #deliverSupervisorReplies(supervisorDir) {
1005
+ const replies = path5.join(supervisorDir, "replies");
1006
+ let names;
1007
+ try {
1008
+ names = fs3.existsSync(replies) ? fs3.readdirSync(replies) : [];
1009
+ } catch {
1010
+ return;
1011
+ }
1012
+ for (const name of names) {
1013
+ const file = path5.join(replies, name);
1014
+ if (this.#repliesInFlight.has(file)) continue;
1015
+ try {
1016
+ const value = JSON.parse(fs3.readFileSync(file, "utf8"));
1017
+ if (typeof value.message === "string" && typeof value.requestId === "string") {
1018
+ this.#repliesInFlight.add(file);
1019
+ void this.#operation("supervisor-reply", value.message, value.requestId, typeof value.error === "string" ? value.error : void 0).then(() => fs3.rmSync(file, { force: true })).catch(() => {
1020
+ }).finally(() => this.#repliesInFlight.delete(file));
1021
+ }
1022
+ } catch {
1023
+ }
1024
+ }
1025
+ }
995
1026
  get host() {
996
1027
  return this.owner.host;
997
1028
  }
@@ -1102,6 +1133,7 @@ var HerdrPiSession = class {
1102
1133
  const createdAt = Date.now();
1103
1134
  const file = path5.join(this.supervisorDir, "requests", `${path5.basename(frame.requestId)}.json`);
1104
1135
  const request = { type: "subagent.supervisor.request", id: frame.requestId, createdAt, ...reason !== "progress_update" ? { expiresAt: createdAt + 10 * 6e4 } : {}, reason, message: typeof frame.message === "string" ? frame.message : "", ...frame.interview && typeof frame.interview === "object" ? { interview: frame.interview } : {}, expectsReply: reason !== "progress_update", runId: this.runtime.runId ?? this.identity.runId, agent: this.runtime.agent ?? "remote", childIndex: this.runtime.childIndex ?? 0, orchestratorSessionId: this.runtime.orchestratorSessionId };
1136
+ ensureSupervisorChannelDir(this.supervisorDir);
1105
1137
  try {
1106
1138
  fs3.writeFileSync(file, JSON.stringify(request), { mode: 384, flag: "wx" });
1107
1139
  } catch (error) {
@@ -1117,7 +1149,7 @@ var HerdrPiSession = class {
1117
1149
  if (operation === "prompt") completion = new Promise((resolve, reject) => this.#operations.set(requestId, { resolve, reject, accepted: false, settled: false }));
1118
1150
  try {
1119
1151
  await Promise.race([this.bridge.prepare(requestId, operation, text, supervisorId, supervisorError), this.bridge.failure]);
1120
- await this.host.prompt(this.connection, this.identity, `/pi-subagents-bridge ${requestId}`);
1152
+ await this.host.prompt(this.connection, this.identity, `/pi-subagents-bridge ${requestId}`, operation === "abort" ? {} : { stopped: () => this.#aborted || this.#disposed });
1121
1153
  await completion;
1122
1154
  } catch (error) {
1123
1155
  if (operation === "prompt" && this.bridge.failed) {