@vicary/pi-subagents 0.88.1 → 0.89.1

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 (93) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/bundle/agents.js +3 -3
  3. package/bundle/child-tool-plan.js +2 -2
  4. package/bundle/{chunk-4QFZZV3O.js → chunk-4AL6LDBY.js} +3 -1
  5. package/bundle/{chunk-5EMPFFO4.js → chunk-4FFKVLBG.js} +4 -4
  6. package/bundle/{chunk-L4YY2TOE.js → chunk-5TXWZB73.js} +1 -1
  7. package/bundle/{chunk-YDZ7BZD5.js → chunk-77VQEATI.js} +1 -1
  8. package/bundle/{chunk-7OX6O7DQ.js → chunk-BERAWSQQ.js} +5 -5
  9. package/bundle/{chunk-LV3CPYXJ.js → chunk-C22YEYFZ.js} +4 -4
  10. package/bundle/{chunk-AZPP3G4N.js → chunk-DVOXHOTY.js} +34 -5
  11. package/bundle/{chunk-2HKPEANZ.js → chunk-JLZFSOEL.js} +26 -15
  12. package/bundle/{chunk-CPSUJHZE.js → chunk-KCDPTXHT.js} +39 -10
  13. package/bundle/{chunk-4MVDMA5C.js → chunk-LWH7IGI3.js} +21 -7
  14. package/bundle/{chunk-DSHQWGHO.js → chunk-MIX3MCIF.js} +96 -96
  15. package/bundle/{chunk-BKISQ5CJ.js → chunk-NLDROUCR.js} +56 -34
  16. package/bundle/{chunk-2DIEL4WG.js → chunk-OUM6SEVD.js} +2 -2
  17. package/bundle/{chunk-XIA5GSEU.js → chunk-Q4VH72JI.js} +2 -2
  18. package/bundle/{chunk-D32H53HM.js → chunk-R3NH5XAL.js} +1 -1
  19. package/bundle/{chunk-CGWNA6EJ.js → chunk-R5XS4CVE.js} +98 -29
  20. package/bundle/{chunk-V7SZMS6W.js → chunk-RHMU7SXN.js} +2 -2
  21. package/bundle/{chunk-4ZQBZDF3.js → chunk-SG3NCWZW.js} +86 -20
  22. package/bundle/{chunk-KXW62VBU.js → chunk-SWGB2P5J.js} +1 -1
  23. package/bundle/{chunk-6CG2VAG4.js → chunk-TRN65L4F.js} +1 -1
  24. package/bundle/{chunk-GDR2ILWY.js → chunk-TXC7WIPL.js} +51 -22
  25. package/bundle/{chunk-IYT7X46U.js → chunk-UNLGCAC4.js} +5 -5
  26. package/bundle/{chunk-PYKBTBY6.js → chunk-URKQZHVH.js} +9 -9
  27. package/bundle/{chunk-W6HIYD2Z.js → chunk-UUW7P6KJ.js} +1 -1
  28. package/bundle/{chunk-CYKNHFXB.js → chunk-VEEUXJDO.js} +1 -1
  29. package/bundle/{chunk-JQTHG2ID.js → chunk-WMGQNIP7.js} +75 -32
  30. package/bundle/{chunk-47ZN7NKR.js → chunk-YJIU5WF4.js} +1 -1
  31. package/bundle/{chunk-RMZAAXIR.js → chunk-YLU5JFW2.js} +2 -2
  32. package/bundle/control-channel.js +2 -2
  33. package/bundle/index.js +2 -2
  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 +10 -4
  38. package/docs/configuration.md +2 -0
  39. package/docs/extension-api.md +1 -1
  40. package/docs/tool-reference.md +1 -1
  41. package/docs/workflows.md +5 -3
  42. package/package.json +2 -2
  43. package/src/extension/herdr-pi-bridge.js +79 -23
  44. package/src/extension/schemas.js +1 -1
  45. package/src/extension/subagent-options.js +5 -0
  46. package/src/intercom/result-intercom.js +3 -2
  47. package/src/runs/background/async-job-tracker.js +85 -9
  48. package/src/runs/background/async-status.d.ts +2 -0
  49. package/src/runs/background/async-status.js +8 -3
  50. package/src/runs/background/notify.d.ts +3 -0
  51. package/src/runs/background/notify.js +7 -2
  52. package/src/runs/background/run-status.js +3 -2
  53. package/src/runs/background/runner-child-launch.js +1 -0
  54. package/src/runs/background/subagent-runner.js +11 -8
  55. package/src/runs/foreground/execution.js +8 -7
  56. package/src/runs/foreground/subagent-executor.js +31 -5
  57. package/src/runs/shared/child-launch.d.ts +2 -0
  58. package/src/runs/shared/child-launch.js +1 -1
  59. package/src/runs/shared/child-session.d.ts +2 -1
  60. package/src/runs/shared/herdr-connection.d.ts +6 -0
  61. package/src/runs/shared/herdr-connection.js +11 -1
  62. package/src/runs/shared/herdr-machine.d.ts +2 -2
  63. package/src/runs/shared/herdr-machine.js +49 -22
  64. package/src/runs/shared/herdr-pane-host.d.ts +7 -19
  65. package/src/runs/shared/herdr-pane-host.js +48 -33
  66. package/src/runs/shared/herdr-pi-protocol.d.ts +1 -0
  67. package/src/runs/shared/herdr-pi-protocol.js +3 -2
  68. package/src/runs/shared/herdr-placed-run.d.ts +2 -12
  69. package/src/runs/shared/herdr-placed-run.js +10 -8
  70. package/src/runs/shared/kept-branch-text.d.ts +8 -0
  71. package/src/runs/shared/kept-branch-text.js +24 -0
  72. package/src/runs/shared/local-machine-access.d.ts +4 -1
  73. package/src/runs/shared/local-machine-access.js +6 -3
  74. package/src/runs/shared/mutation-evidence.d.ts +7 -1
  75. package/src/runs/shared/mutation-evidence.js +18 -2
  76. package/src/runs/shared/parallel-handoff.js +19 -7
  77. package/src/runs/shared/placed-run-owner.d.ts +4 -2
  78. package/src/runs/shared/placed-run-owner.js +15 -7
  79. package/src/runs/shared/rex-machine.d.ts +7 -3
  80. package/src/runs/shared/rex-machine.js +12 -9
  81. package/src/runs/shared/rex-pane-host.js +7 -27
  82. package/src/runs/shared/single-output.js +2 -2
  83. package/src/runs/shared/subagent-prompt-runtime.js +34 -0
  84. package/src/runs/shared/tool-availability.d.ts +4 -0
  85. package/src/runs/shared/tool-availability.js +7 -0
  86. package/src/runs/shared/worktree-cleanup-plan.js +2 -2
  87. package/src/runs/shared/worktree.d.ts +4 -14
  88. package/src/runs/shared/worktree.js +38 -8
  89. package/src/shared/types.d.ts +26 -2
  90. package/src/shared/utils.d.ts +2 -0
  91. package/src/shared/utils.js +9 -0
  92. package/src/workflows/workflow-child-summary.d.ts +2 -1
  93. package/src/workflows/workflow-child-summary.js +14 -6
@@ -3,8 +3,9 @@ import {
3
3
  REX_LOCAL_MACHINE,
4
4
  getAgentDir,
5
5
  getProjectConfigDir,
6
+ resolveLocalLaunchCwd,
6
7
  resolveRexLocalPlacement
7
- } from "./chunk-4MVDMA5C.js";
8
+ } from "./chunk-LWH7IGI3.js";
8
9
 
9
10
  // src/runs/shared/herdr-machine.ts
10
11
  import { spawnSync as spawnSync2 } from "node:child_process";
@@ -54,12 +55,20 @@ function decodeHerdrJsonLine(line) {
54
55
  function shellQuoteRemote(value) {
55
56
  return `'${value.replaceAll("'", "'\\''")}'`;
56
57
  }
58
+ function shellScriptCommand(script, args = []) {
59
+ return `sh -c ${shellQuoteRemote(script)} sh${args.map((arg) => ` ${shellQuoteRemote(arg)}`).join("")}`;
60
+ }
57
61
  function remoteShellCommand(script, args = []) {
58
- return `sh -c ${shellQuoteRemote(`PATH="${HERDR_REMOTE_PATH}"; export PATH; ${script}`)} sh${args.map((arg) => ` ${shellQuoteRemote(arg)}`).join("")}`;
62
+ return shellScriptCommand(`PATH="${HERDR_REMOTE_PATH}"; export PATH; ${script}`, args);
59
63
  }
60
64
  function canonicalHerdrSession(session) {
61
65
  return session && session !== "default" ? session : null;
62
66
  }
67
+ function herdrLocalEnv(socket, session, source) {
68
+ const { HERDR_SESSION: _session, HERDR_CLIENT_SOCKET_PATH: _client, HERDR_PANE_ID: _pane, HERDR_ENV: _env, HERDR_SOCKET_PATH: _socket, ...env } = source;
69
+ const selected = canonicalHerdrSession(session);
70
+ return { ...env, HERDR_SOCKET_PATH: socket, ...selected ? { HERDR_SESSION: selected } : {} };
71
+ }
63
72
  function sshEnvCommand(session, command) {
64
73
  const selected = canonicalHerdrSession(session), assignment = selected ? ` HERDR_SESSION=${shellQuoteRemote(selected)}` : "";
65
74
  return `/usr/bin/env -u HERDR_SOCKET_PATH -u HERDR_SESSION${assignment} ${remoteShellCommand(command)}`;
@@ -393,20 +402,13 @@ function parseMachineCatalog(json) {
393
402
  });
394
403
  }
395
404
  function readHerdrMachineCatalog(env, herdrBin) {
396
- const result = spawnSync2(herdrBin, ["machine", "list", "--json"], {
397
- env,
398
- encoding: "utf-8",
399
- maxBuffer: MAX_HERDR_MACHINE_LIST_BYTES,
400
- timeout: HERDR_MACHINE_LIST_TIMEOUT_MS,
401
- windowsHide: true
402
- });
403
- if (result.error) {
404
- const code = result.error.code;
405
- if (code === "ENOENT") throw new Error(`Herdr CLI '${herdrBin}' was not found on PATH. Saved-machine placement needs Herdr installed locally.`);
406
- throw new Error(`Failed to run herdr machine list --json: ${result.error.message}`);
407
- }
408
- if (result.status !== 0) throw new Error(`herdr machine list --json exited with code ${result.status}: ${(result.stderr || result.stdout).trim()}`);
409
- return parseMachineCatalog(result.stdout);
405
+ return parseMachineCatalog(runLocalHerdr(herdrBin, ["machine", "list", "--json"], env, `Herdr CLI '${herdrBin}' was not found on PATH. Saved-machine placement needs Herdr installed locally.`));
406
+ }
407
+ function runLocalHerdr(bin, args, env, notFound) {
408
+ const result = spawnSync2(bin, args, { env, encoding: "utf-8", maxBuffer: MAX_HERDR_MACHINE_LIST_BYTES, timeout: HERDR_MACHINE_LIST_TIMEOUT_MS, windowsHide: true });
409
+ if (result.error) throw new Error(result.error.code === "ENOENT" ? notFound : `Failed to run herdr ${args.join(" ")}: ${result.error.message}`, { cause: result.error });
410
+ if (result.status !== 0) throw new Error(`herdr ${args.join(" ")} exited with code ${result.status}: ${(result.stderr || result.stdout).trim().slice(0, 512)}`);
411
+ return result.stdout;
410
412
  }
411
413
  function selectMachine(catalog, requested) {
412
414
  const byId = catalog.find((entry) => entry.id === requested);
@@ -513,12 +515,35 @@ function resolveHerdrMachinePlacement(input) {
513
515
  ...settings?.env ? { env: settings.env } : {}
514
516
  };
515
517
  }
518
+ function resolveHerdrLocalPlacement(input) {
519
+ if (process.platform === "win32") throw new Error("Machine 'local' runs the child in a Herdr pane, which is not supported on Windows.");
520
+ const env = input.env, paneId = env.HERDR_PANE_ID.trim(), bin = input.herdrBin ?? env.HERDR_BIN ?? "herdr", notFound = `Machine 'local' needs the Herdr CLI, but '${bin}' was not found on PATH.`;
521
+ let endpoint;
522
+ try {
523
+ endpoint = parseHerdrEndpoint(runLocalHerdr(bin, ["status", "server", "--json"], env, notFound), env.HERDR_SESSION);
524
+ } catch (error) {
525
+ throw new Error(`Machine 'local' could not confirm this pane's Herdr server: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
526
+ }
527
+ let pane;
528
+ try {
529
+ pane = JSON.parse(runLocalHerdr(bin, ["pane", "get", paneId], herdrLocalEnv(endpoint.socket, endpoint.session, env), notFound));
530
+ } catch (error) {
531
+ throw new Error(`Machine 'local' needs this Pi's Herdr pane ${paneId}, but the Herdr server at ${endpoint.socket} did not return it: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
532
+ }
533
+ const result = pane?.result;
534
+ if (result?.type !== "pane_info" || result.pane?.pane_id !== paneId) throw new Error(`The Herdr server at ${endpoint.socket} did not confirm pane ${paneId}.`);
535
+ return { provider: "herdr", id: REX_LOCAL_MACHINE, socket: endpoint.socket, ...endpoint.session ? { session: endpoint.session } : {}, cwd: resolveLocalLaunchCwd(input.cwd, input.stepCwd) };
536
+ }
516
537
  function resolveMachinePlacement(input) {
517
538
  const requested = validateMachineName(input.machine);
518
539
  const settings = input.settings ?? readMachineSettings(input.cwd, [requested]);
519
540
  if (requested === REX_LOCAL_MACHINE) {
520
- if (settings?.rex) throw new Error("Machine 'local' is reserved for a Rex pane on this machine; give the Rex SSH host in subagents.machines.local.rex another name.");
521
- return { machine: resolveRexLocalPlacement({ cwd: input.cwd, stepCwd: input.stepCwd, env: input.env }) };
541
+ if (settings?.rex) throw new Error("Machine 'local' is reserved for a new tab on this machine; give the Rex SSH host in subagents.machines.local.rex another name.");
542
+ const env = input.env ?? process.env;
543
+ if (env.HERDR_ENV === "1" && env.HERDR_PANE_ID?.trim()) return { machine: resolveHerdrLocalPlacement({ cwd: input.cwd, stepCwd: input.stepCwd, env, herdrBin: input.herdrBin }) };
544
+ if (env.REX_SESSION?.trim()) return { machine: resolveRexLocalPlacement({ cwd: input.cwd, stepCwd: input.stepCwd, env }) };
545
+ const core = env.HC_TERMINAL_ID?.trim() ? " It runs in a Herdr Core terminal (HC_TERMINAL_ID), which machine 'local' does not support." : "";
546
+ throw new Error(`Machine 'local' opens the child in a new tab of the terminal this Pi runs in, but this Pi is running in neither Herdr (HERDR_ENV=1 with HERDR_PANE_ID) nor Rex (REX_SESSION).${core}`);
522
547
  }
523
548
  if (settings?.rex) return { machine: { provider: "rex", id: requested, target: settings.rex.ssh, cwd: validateRemoteCwd(remoteMachineCwd(input.stepCwd, settings.cwd, requested), requested) } };
524
549
  return resolveHerdrMachinePlacement(input);
@@ -527,16 +552,17 @@ var PLACED_RESTORE_UNSUPPORTED = "Pane-native remote Pi does not support fork, r
527
552
  function formatHerdrMachineRunnerUnsupported(input) {
528
553
  if (input.machine === void 0) return void 0;
529
554
  const name = input.machine.trim();
555
+ const local = name === REX_LOCAL_MACHINE;
530
556
  let rex;
531
557
  try {
532
- rex = name === REX_LOCAL_MACHINE || userRexMachine(name);
558
+ rex = local || userRexMachine(name);
533
559
  } catch (error) {
534
560
  return error instanceof Error ? error.message : String(error);
535
561
  }
536
562
  if (rex) {
537
- if (input.runnerType !== void 0 && input.runnerType !== "pi") return `Agent '${input.agentName}' requested machine '${name}', but Rex supports native Pi children only. Remove the machine or use a native Pi agent.`;
563
+ if (input.runnerType !== void 0 && input.runnerType !== "pi") return `Agent '${input.agentName}' requested machine '${name}', but ${local ? "machine 'local' runs" : "Rex supports"} native Pi children only. Remove the machine or use a native Pi agent.`;
538
564
  if (input.worktree === true) return `Agent '${input.agentName}' requested machine '${name}', but managed worktrees cannot be combined with machine placement.`;
539
- if (process.platform === "win32") return `Machine '${name}' runs the child in a Rex pane, which is not supported on Windows.`;
565
+ if (process.platform === "win32") return `Machine '${name}' runs the child in ${local ? "a Herdr or Rex pane" : "a Rex pane"}, which is not supported on Windows.`;
540
566
  return void 0;
541
567
  }
542
568
  if (input.runnerType !== void 0 && input.runnerType !== "pi" && input.runnerType !== "external-cli") {
@@ -551,8 +577,11 @@ function formatHerdrMachineRunnerUnsupported(input) {
551
577
  }
552
578
 
553
579
  export {
554
- remoteShellCommand,
580
+ shellScriptCommand,
581
+ herdrLocalEnv,
555
582
  runBoundedCommand,
583
+ parseHerdrEndpoint,
584
+ SocketRpcClient,
556
585
  sshMachineAccess,
557
586
  connectHerdrMachine,
558
587
  resolveMachinePlacement,
@@ -8,7 +8,7 @@ import {
8
8
  projectTimeoutRecovery,
9
9
  readAsyncRecoveryDescriptor,
10
10
  utf8Tail
11
- } from "./chunk-4ZQBZDF3.js";
11
+ } from "./chunk-SG3NCWZW.js";
12
12
  import {
13
13
  MAX_ARGS_BYTES,
14
14
  MAX_ARGS_DEPTH,
@@ -21,10 +21,10 @@ import {
21
21
  resultFilePath,
22
22
  resultPayloadMatchesSessionRun,
23
23
  resultPayloadPathForSessionRun
24
- } from "./chunk-CPSUJHZE.js";
24
+ } from "./chunk-KCDPTXHT.js";
25
25
  import {
26
26
  PROJECT_SUBAGENTS_RELATIVE_DIR
27
- } from "./chunk-YDZ7BZD5.js";
27
+ } from "./chunk-77VQEATI.js";
28
28
  import {
29
29
  listBackgroundWorkWakeChannels,
30
30
  snapshotBackgroundWork
@@ -50,7 +50,7 @@ import {
50
50
  waitToolName,
51
51
  withSettingsFileLease,
52
52
  writePrivateAtomicJson
53
- } from "./chunk-4MVDMA5C.js";
53
+ } from "./chunk-LWH7IGI3.js";
54
54
  import {
55
55
  DIRS,
56
56
  INTERCOM_DETACH_REQUEST_EVENT,
@@ -906,7 +906,7 @@ var SubagentParamProperties = {
906
906
  usageBudget: Type2.Optional(UsageBudgetOverride),
907
907
  agentScope: Type2.Optional(Type2.String({ description: "user/project/both (default); project wins collisions." })),
908
908
  cwd: Type2.Optional(Type2.String({ description: "Execution/project-pane directory." })),
909
- machine: Type2.Optional(Type2.String({ minLength: 1, maxLength: 128, description: 'Herdr saved machine id or label (runs an external CLI agent), a Rex host named in settings (runs a Pi child), or "local" (a Pi child in a Rex pane here). On another machine, cwd is a directory there.' })),
909
+ machine: Type2.Optional(Type2.String({ minLength: 1, maxLength: 128, description: 'Herdr saved machine id or label (runs an external CLI agent), a Rex host named in settings (runs a Pi child), or "local" (a Pi child in a new tab of the Herdr or Rex session this Pi runs in). On another machine, cwd is a directory there.' })),
910
910
  requireLauncher: Type2.Optional(Type2.Object({
911
911
  name: Type2.String({ pattern: RUNNER_LAUNCHER_NAME_PATTERN.source }),
912
912
  definitionDigest: Type2.String({ pattern: "^[0-9a-f]{64}$" })
@@ -7,37 +7,37 @@ import {
7
7
  safeTranscriptEvent,
8
8
  steerAsyncRun,
9
9
  steerWorkflowForegroundTarget
10
- } from "./chunk-7OX6O7DQ.js";
10
+ } from "./chunk-BERAWSQQ.js";
11
11
  import {
12
12
  FLEET_STATUS_WIDGET_KEY,
13
13
  runningTone,
14
14
  stepTaskSummary
15
- } from "./chunk-5EMPFFO4.js";
15
+ } from "./chunk-4FFKVLBG.js";
16
16
  import {
17
17
  foregroundChildStateLabel,
18
18
  formatAsyncRunTranscript,
19
19
  stopAsyncRun
20
- } from "./chunk-LV3CPYXJ.js";
20
+ } from "./chunk-C22YEYFZ.js";
21
21
  import {
22
22
  contextModeBadge,
23
23
  contextModeLabel,
24
24
  decodeUtf8Tail,
25
25
  listAsyncRuns
26
- } from "./chunk-4ZQBZDF3.js";
26
+ } from "./chunk-SG3NCWZW.js";
27
27
  import {
28
28
  reportSessionWarning
29
29
  } from "./chunk-HXRB42AF.js";
30
- import "./chunk-CPSUJHZE.js";
31
- import "./chunk-W6HIYD2Z.js";
30
+ import "./chunk-KCDPTXHT.js";
31
+ import "./chunk-UUW7P6KJ.js";
32
32
  import "./chunk-NIXWDZZV.js";
33
- import "./chunk-47ZN7NKR.js";
33
+ import "./chunk-YJIU5WF4.js";
34
34
  import "./chunk-7F6RKT6W.js";
35
35
  import "./chunk-YARY7JWU.js";
36
36
  import "./chunk-7J4ZXMY7.js";
37
37
  import {
38
38
  getArtifactPaths,
39
39
  getArtifactsDir
40
- } from "./chunk-YDZ7BZD5.js";
40
+ } from "./chunk-77VQEATI.js";
41
41
  import {
42
42
  snapshotExternalRuns
43
43
  } from "./chunk-UKG4V45O.js";
@@ -49,7 +49,7 @@ import {
49
49
  formatTokens,
50
50
  readStatus,
51
51
  shortenPath
52
- } from "./chunk-4MVDMA5C.js";
52
+ } from "./chunk-LWH7IGI3.js";
53
53
  import {
54
54
  DIRS
55
55
  } from "./chunk-JEZOSEWG.js";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  resolveWatchPath,
6
6
  writeAtomicJson
7
- } from "./chunk-4MVDMA5C.js";
7
+ } from "./chunk-LWH7IGI3.js";
8
8
  import {
9
9
  POLL_INTERVAL_MS
10
10
  } from "./chunk-JEZOSEWG.js";
@@ -11,7 +11,7 @@ import {
11
11
  readStatus,
12
12
  writeAtomicJson,
13
13
  writePrivateAtomicJson
14
- } from "./chunk-4MVDMA5C.js";
14
+ } from "./chunk-LWH7IGI3.js";
15
15
  import {
16
16
  ASYNC_DIR,
17
17
  INTERCOM_DETACH_REQUEST_EVENT,
@@ -1,33 +1,34 @@
1
1
  import {
2
2
  rewriteSubagentPrompt
3
- } from "./chunk-AZPP3G4N.js";
3
+ } from "./chunk-DVOXHOTY.js";
4
4
  import {
5
5
  package_default
6
- } from "./chunk-6CG2VAG4.js";
6
+ } from "./chunk-TRN65L4F.js";
7
7
  import {
8
8
  WATCHDOG_DIFF_TOOL_NAME,
9
9
  captureWatchdogDiffBaseline,
10
10
  createWatchdogDiffTool
11
- } from "./chunk-IYT7X46U.js";
12
- import "./chunk-4ZQBZDF3.js";
13
- import "./chunk-CYKNHFXB.js";
11
+ } from "./chunk-UNLGCAC4.js";
12
+ import "./chunk-SG3NCWZW.js";
13
+ import "./chunk-VEEUXJDO.js";
14
14
  import {
15
15
  MODEL_ONLY_TOOL
16
16
  } from "./chunk-HXRB42AF.js";
17
17
  import "./chunk-W2BZS6UC.js";
18
18
  import {
19
19
  appendAgentRefinementOverlay
20
- } from "./chunk-XIA5GSEU.js";
21
- import "./chunk-CPSUJHZE.js";
20
+ } from "./chunk-Q4VH72JI.js";
21
+ import "./chunk-KCDPTXHT.js";
22
22
  import "./chunk-NIXWDZZV.js";
23
- import "./chunk-47ZN7NKR.js";
23
+ import "./chunk-YJIU5WF4.js";
24
24
  import "./chunk-7F6RKT6W.js";
25
25
  import {
26
26
  assertNoToolModifierEntries
27
- } from "./chunk-D32H53HM.js";
27
+ } from "./chunk-R3NH5XAL.js";
28
28
  import "./chunk-YARY7JWU.js";
29
- import "./chunk-YDZ7BZD5.js";
29
+ import "./chunk-77VQEATI.js";
30
30
  import {
31
+ HERDR_PI_MAX_ACCEPTANCE_PROMPT_BYTES,
31
32
  HERDR_PI_MAX_FRAME_BYTES,
32
33
  HERDR_PI_PROTOCOL,
33
34
  HERDR_PI_RUNTIME_DIR_ENV,
@@ -35,7 +36,7 @@ import {
35
36
  HerdrPiFrameDecoder,
36
37
  encodeHerdrPiFrame,
37
38
  validateHerdrPiRunId
38
- } from "./chunk-4QFZZV3O.js";
39
+ } from "./chunk-4AL6LDBY.js";
39
40
  import "./chunk-XA3DY6UG.js";
40
41
  import {
41
42
  buildAgentMemoryInjection,
@@ -43,7 +44,7 @@ import {
43
44
  discoverAgents,
44
45
  resolveExistingReadPaths,
45
46
  resolveSkills
46
- } from "./chunk-4MVDMA5C.js";
47
+ } from "./chunk-LWH7IGI3.js";
47
48
  import "./chunk-JEZOSEWG.js";
48
49
  import "./chunk-YFCK7H2S.js";
49
50
  import "./chunk-QXASAHIA.js";
@@ -63,6 +64,32 @@ function gitEvidence(cwd) {
63
64
  const dirty = run(["status", "--porcelain"]);
64
65
  return { ...head.status === 0 ? { head: head.stdout.trim() } : {}, ...branch.status === 0 ? { branch: branch.stdout.trim() } : {}, dirty: Boolean(dirty.stdout.trim()) };
65
66
  }
67
+ var TOOL_ARGS_FRAME_BUDGET = 64 * 1024;
68
+ function boundedToolArgs(args) {
69
+ if (!args || typeof args !== "object" || Array.isArray(args) || Buffer.byteLength(JSON.stringify(args)) <= TOOL_ARGS_FRAME_BUDGET) return args;
70
+ const shortened = Object.fromEntries(Object.entries(args).flatMap(([key, value]) => typeof value === "string" ? [[key, value.slice(0, 4096)]] : typeof value === "number" || typeof value === "boolean" ? [[key, value]] : []));
71
+ return Buffer.byteLength(JSON.stringify(shortened)) <= TOOL_ARGS_FRAME_BUDGET ? shortened : {};
72
+ }
73
+ var MESSAGE_FRAME_BUDGET = HERDR_PI_MAX_FRAME_BYTES - 64 * 1024;
74
+ var fitsMessageBudget = (value) => Buffer.byteLength(JSON.stringify(value)) <= MESSAGE_FRAME_BUDGET;
75
+ var omittedText = (what, bytes) => `[${what} omitted by the pi-subagents bridge: ${bytes} bytes did not fit in one bridge frame]`;
76
+ function boundedMessage(message) {
77
+ if (fitsMessageBudget(message)) return message;
78
+ const record = message;
79
+ const content = Array.isArray(record.content) ? record.content.map((block) => {
80
+ if (block.type === "image") return { type: "text", text: omittedText(`Image (${String(block.mimeType)})`, Buffer.byteLength(String(block.data))) };
81
+ if (block.type === "text" && typeof block.text === "string" && block.text.length > 65536) return { type: "text", text: `${block.text.slice(0, 65536)}
82
+ ${omittedText("The rest of this text", Buffer.byteLength(block.text.slice(65536)))}` };
83
+ if (block.type === "thinking" && typeof block.thinking === "string") return { type: "thinking", thinking: block.thinking.length > 4096 ? `${block.thinking.slice(0, 4096)}
84
+ ${omittedText("The rest of this thinking", Buffer.byteLength(block.thinking.slice(4096)))}` : block.thinking };
85
+ if (block.type === "toolCall") return { ...block, arguments: boundedToolArgs(block.arguments) };
86
+ return block;
87
+ }) : record.content;
88
+ const shrunk = { ...record, content, details: void 0 };
89
+ if (fitsMessageBudget(shrunk)) return shrunk;
90
+ const kept = Object.fromEntries(["role", "toolCallId", "toolName", "isError", "api", "provider", "model", "usage", "stopReason", "timestamp"].filter((key) => key in record).map((key) => [key, record[key]]));
91
+ return { ...kept, ...typeof record.errorMessage === "string" ? { errorMessage: record.errorMessage.slice(0, 4096) } : {}, content: [{ type: "text", text: omittedText("This message", Buffer.byteLength(JSON.stringify(message))) }] };
92
+ }
66
93
  function resolveRemoteHerdrResources(cwd, resources, remoteDefaultTools = []) {
67
94
  if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(resources.agent) || resources.skills?.some((name) => !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(name)) || resources.toolCeiling?.some((name) => !/^[A-Za-z0-9_-]{1,64}$/u.test(name)) || resources.reads !== void 0 && resources.reads !== false && (!Array.isArray(resources.reads) || resources.reads.some((name) => typeof name !== "string"))) throw new Error("Remote logical resource names are invalid.");
68
95
  const discovered = discoverAgents(cwd, "both").agents.filter((agent2) => agent2.name === resources.agent || agent2.aliases?.includes(resources.agent));
@@ -89,18 +116,10 @@ function registerHerdrPiBridge(pi) {
89
116
  const runId = validateHerdrPiRunId(process.env[HERDR_PI_RUN_ENV]);
90
117
  const runDir = process.env[HERDR_PI_RUNTIME_DIR_ENV];
91
118
  if (!runDir || !path.isAbsolute(runDir) || fs.lstatSync(runDir).isSymbolicLink()) throw new Error("Herdr bridge runtime directory was not authoritatively provisioned.");
92
- fs.chmodSync(runDir, 448);
93
119
  const socketPath = path.join(runDir, "bridge.sock");
94
120
  const manifestPath = path.join(runDir, "manifest.json");
95
- for (const candidate of [socketPath, manifestPath]) {
96
- try {
97
- const stat = fs.lstatSync(candidate);
98
- if (stat.isSymbolicLink()) throw new Error(`Refusing symlink at '${candidate}'.`);
99
- fs.rmSync(candidate, { force: true });
100
- } catch (error) {
101
- if (error.code !== "ENOENT") throw error;
102
- }
103
- }
121
+ const claims = globalThis[/* @__PURE__ */ Symbol.for("pi-subagents.herdr-bridge-claims")] ??= /* @__PURE__ */ new Set();
122
+ let claimed = false;
104
123
  let client;
105
124
  let context;
106
125
  let nativeSessionId;
@@ -115,8 +134,10 @@ function registerHerdrPiBridge(pi) {
115
134
  let journalBytes = 0;
116
135
  const journal = [];
117
136
  const send = (frame) => {
118
- const record = { protocol: HERDR_PI_PROTOCOL, runId, ...frame, cursor: ++evidenceCursor };
137
+ const record = { protocol: HERDR_PI_PROTOCOL, runId, ...frame, cursor: evidenceCursor + 1 };
119
138
  const size = Buffer.byteLength(JSON.stringify(record));
139
+ if (size >= HERDR_PI_MAX_FRAME_BYTES) throw new Error(`pi-subagents bridge frame '${frame.type}' is ${size} bytes, over the ${HERDR_PI_MAX_FRAME_BYTES}-byte limit.`);
140
+ evidenceCursor++;
120
141
  journal.push(record);
121
142
  journalBytes += size;
122
143
  while (journal.length > 512 || journalBytes > 8 * 1024 * 1024) {
@@ -126,6 +147,7 @@ function registerHerdrPiBridge(pi) {
126
147
  if (!client || client.destroyed) return;
127
148
  client.write(encodeHerdrPiFrame(record));
128
149
  };
150
+ const sendReady = (ctx) => send({ type: "ready", packageVersion: package_default.version, nativeSessionId, sessionFile: ctx.sessionManager?.getSessionFile?.(), cwd: process.cwd(), tools: pi.getActiveTools(), model: ctx.model?.provider && ctx.model.id ? `${ctx.model.provider}/${ctx.model.id}` : void 0, configured, activeRequestId, evidenceCursor, evidenceFloor: journal[0]?.cursor ?? evidenceCursor + 1, initialGit: gitEvidence(process.cwd()) });
129
151
  const sessionId = (ctx) => ctx.sessionManager?.getSessionId?.();
130
152
  pi.registerTool({
131
153
  name: "contact_supervisor",
@@ -166,7 +188,7 @@ ${answer}` }], details };
166
188
  api.sendUserMessage(request.text ?? "");
167
189
  } else if (request.operation === "steer") api.sendUserMessage(request.text ?? "", { deliverAs: "steer" });
168
190
  else if (request.operation === "follow-up") api.sendUserMessage(request.text ?? "", { deliverAs: "followUp" });
169
- else if (request.operation === "abort") api.abort();
191
+ else if (request.operation === "abort") ctx.abort();
170
192
  else {
171
193
  const entry = request.supervisorId ? supervisor.get(request.supervisorId) : void 0;
172
194
  if (!entry) throw new Error("Unknown supervisor request.");
@@ -188,23 +210,44 @@ ${answer}` }], details };
188
210
  ${resolvedSystemPrompt}` } : void 0;
189
211
  });
190
212
  on("session_start", (_event, ctx) => {
213
+ if (claims.has(runDir)) return;
191
214
  context = ctx;
192
215
  nativeSessionId = sessionId(ctx);
193
216
  if (!nativeSessionId) throw new Error("Pane-native Pi bridge requires a persisted native session identity.");
217
+ claims.add(runDir);
218
+ claimed = true;
219
+ fs.chmodSync(runDir, 448);
220
+ for (const candidate of [socketPath, manifestPath]) {
221
+ try {
222
+ const stat = fs.lstatSync(candidate);
223
+ if (stat.isSymbolicLink()) throw new Error(`Refusing symlink at '${candidate}'.`);
224
+ fs.rmSync(candidate, { force: true });
225
+ } catch (error) {
226
+ if (error.code !== "ENOENT") throw error;
227
+ }
228
+ }
229
+ server.listen(socketPath, () => {
230
+ fs.chmodSync(socketPath, 384);
231
+ });
194
232
  fs.writeFileSync(manifestPath, JSON.stringify({ protocol: HERDR_PI_PROTOCOL, packageVersion: package_default.version, runId, socketPath, nativeSessionId, pid: process.pid }), { mode: 384, flag: "wx" });
195
- send({ type: "ready", packageVersion: package_default.version, nativeSessionId, sessionFile: ctx.sessionManager?.getSessionFile?.(), cwd: process.cwd(), tools: pi.getActiveTools(), model: ctx.model?.provider && ctx.model.id ? `${ctx.model.provider}/${ctx.model.id}` : void 0, configured, activeRequestId, evidenceCursor, evidenceFloor: journal[0]?.cursor ?? evidenceCursor + 1, initialGit: gitEvidence(process.cwd()) });
233
+ sendReady(ctx);
196
234
  });
197
235
  on("message_end", (event) => {
198
- const message = event.message;
199
- if (message?.role === "assistant") finalAssistant = message;
236
+ const message = boundedMessage(event.message);
237
+ if (message.role === "assistant") finalAssistant = message;
200
238
  send({ type: "event", requestId: activeRequestId, event: { ...event, message }, nativeSessionId });
201
239
  });
240
+ on("tool_execution_start", (event) => send({ type: "event", requestId: activeRequestId, event: { type: "tool_execution_start", toolCallId: event.toolCallId, toolName: event.toolName, args: boundedToolArgs(event.args) }, nativeSessionId }));
241
+ on("tool_execution_end", (event) => send({ type: "event", requestId: activeRequestId, event: { type: "tool_execution_end", toolCallId: event.toolCallId, toolName: event.toolName, isError: event.isError }, nativeSessionId }));
202
242
  on("agent_settled", (_event, ctx) => {
203
243
  const requestId = activeRequestId;
204
244
  send({ type: "settled", requestId, nativeSessionId, idle: ctx.isIdle(), pending: ctx.hasPendingMessages(), finalAssistant, finalGit: gitEvidence(process.cwd()) });
205
245
  if (ctx.isIdle() && !ctx.hasPendingMessages()) activeRequestId = void 0;
206
246
  });
207
247
  on("session_shutdown", () => {
248
+ if (!claimed) return;
249
+ claimed = false;
250
+ claims.delete(runDir);
208
251
  server.close();
209
252
  client?.destroy();
210
253
  try {
@@ -243,9 +286,12 @@ ${resolvedSystemPrompt}` } : void 0;
243
286
  const invalidSkills = resources.skills !== void 0 && (!Array.isArray(resources.skills) || resources.skills.some((name) => typeof name !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(name)));
244
287
  const invalidReads = resources.reads !== void 0 && resources.reads !== false && (!Array.isArray(resources.reads) || resources.reads.some((name) => typeof name !== "string"));
245
288
  if (typeof resources.agent !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(resources.agent) || invalidSkills || invalidReads) throw new Error("Remote logical resource names are invalid.");
289
+ const acceptancePrompt = resources.acceptancePrompt;
290
+ if (acceptancePrompt !== void 0 && (typeof acceptancePrompt !== "string" || Buffer.byteLength(acceptancePrompt) > HERDR_PI_MAX_ACCEPTANCE_PROMPT_BYTES)) throw new Error("Bridge acceptance instructions are invalid or too large.");
246
291
  const resolved = resolveRemoteHerdrResources(process.cwd(), { agent: resources.agent, ...resources.skills ? { skills: resources.skills } : {}, ...resources.toolCeiling ? { toolCeiling: resources.toolCeiling } : {}, ...resources.reads !== void 0 ? { reads: resources.reads } : {} }, context ? pi.getActiveTools() : []);
247
- resolvedSystemPrompt = resolved.systemPrompt;
248
292
  resolvedContextPolicy = resolved;
293
+ resolvedSystemPrompt = acceptancePrompt ? `${resolved.systemPrompt}
294
+ ${acceptancePrompt}` : resolved.systemPrompt;
249
295
  if (resolved.tools.includes(WATCHDOG_DIFF_TOOL_NAME) && !pi.getAllTools().some((tool) => tool.name === WATCHDOG_DIFF_TOOL_NAME)) pi.registerTool(createWatchdogDiffTool(captureWatchdogDiffBaseline(process.cwd()), { workingTreeAtLaunch: true }));
250
296
  pi.setActiveTools(resolved.tools);
251
297
  const acknowledged = context ? pi.getActiveTools() : [];
@@ -275,10 +321,7 @@ ${resolvedSystemPrompt}` } : void 0;
275
321
  socket.on("close", () => {
276
322
  if (client === socket) client = void 0;
277
323
  });
278
- if (context && nativeSessionId) send({ type: "ready", packageVersion: package_default.version, nativeSessionId, sessionFile: context.sessionManager?.getSessionFile?.(), cwd: process.cwd(), tools: pi.getActiveTools(), model: context.model?.provider && context.model.id ? `${context.model.provider}/${context.model.id}` : void 0, configured, activeRequestId, evidenceCursor, evidenceFloor: journal[0]?.cursor ?? evidenceCursor + 1, initialGit: gitEvidence(process.cwd()) });
279
- });
280
- server.listen(socketPath, () => {
281
- fs.chmodSync(socketPath, 384);
324
+ if (context && nativeSessionId) sendReady(context);
282
325
  });
283
326
  }
284
327
  export {
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-7F6RKT6W.js";
4
4
  import {
5
5
  getAgentDir
6
- } from "./chunk-4MVDMA5C.js";
6
+ } from "./chunk-LWH7IGI3.js";
7
7
 
8
8
  // src/intercom/intercom-bridge.ts
9
9
  import * as fs from "node:fs";
@@ -11,13 +11,13 @@ import {
11
11
  validateAuthorityPolicy,
12
12
  validateMissionStoreConfig,
13
13
  validateModelResponseAliases
14
- } from "./chunk-CPSUJHZE.js";
14
+ } from "./chunk-KCDPTXHT.js";
15
15
  import {
16
16
  getAgentDir,
17
17
  readStatus,
18
18
  validatePermissionConfig,
19
19
  writePrivateAtomicJson
20
- } from "./chunk-4MVDMA5C.js";
20
+ } from "./chunk-LWH7IGI3.js";
21
21
  import {
22
22
  FLEET_KEYBINDING_ACTIONS,
23
23
  RUNNER_LAUNCHER_NAME_PATTERN,
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  requestAsyncStop
3
- } from "./chunk-W6HIYD2Z.js";
3
+ } from "./chunk-UUW7P6KJ.js";
4
4
  import "./chunk-NIXWDZZV.js";
5
- import "./chunk-4MVDMA5C.js";
5
+ import "./chunk-LWH7IGI3.js";
6
6
  import "./chunk-JEZOSEWG.js";
7
7
  import "./chunk-YFCK7H2S.js";
8
8
  import "./chunk-QXASAHIA.js";
package/bundle/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  HERDR_PI_MODE_ENV
3
- } from "./chunk-4QFZZV3O.js";
3
+ } from "./chunk-4AL6LDBY.js";
4
4
 
5
5
  // src/shared/package-version.ts
6
6
  import * as fs from "node:fs";
@@ -17,7 +17,7 @@ function readInstalledPackageVersion() {
17
17
  var loadedPackageVersion = readInstalledPackageVersion();
18
18
 
19
19
  // index.ts
20
- var registerExtension = process.env[HERDR_PI_MODE_ENV] === "1" ? (await import("./chunk-JQTHG2ID.js")).default : process.env.PI_SUBAGENT_CHILD === "1" ? void 0 : (await import("./chunk-CGWNA6EJ.js")).default;
20
+ var registerExtension = process.env[HERDR_PI_MODE_ENV] === "1" ? (await import("./chunk-WMGQNIP7.js")).default : process.env.PI_SUBAGENT_CHILD === "1" ? void 0 : (await import("./chunk-R5XS4CVE.js")).default;
21
21
  function registerSubagentExtension(pi) {
22
22
  const installedVersion = readInstalledPackageVersion();
23
23
  if (installedVersion !== loadedPackageVersion) {
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  resolveIntercomSessionTarget
3
- } from "./chunk-47ZN7NKR.js";
3
+ } from "./chunk-YJIU5WF4.js";
4
4
  import "./chunk-7F6RKT6W.js";
5
- import "./chunk-4MVDMA5C.js";
5
+ import "./chunk-LWH7IGI3.js";
6
6
  import "./chunk-JEZOSEWG.js";
7
7
  import "./chunk-YFCK7H2S.js";
8
8
  import "./chunk-QXASAHIA.js";
@@ -2,22 +2,22 @@ import {
2
2
  buildEffectiveSystemPrompt,
3
3
  canPreferForkFromSnapshot,
4
4
  resolveSubagentLaunchContext
5
- } from "./chunk-V7SZMS6W.js";
6
- import "./chunk-XIA5GSEU.js";
5
+ } from "./chunk-RHMU7SXN.js";
6
+ import "./chunk-Q4VH72JI.js";
7
7
  import {
8
8
  loadConfig
9
- } from "./chunk-RMZAAXIR.js";
9
+ } from "./chunk-YLU5JFW2.js";
10
10
  import {
11
11
  nestedResultsPath,
12
12
  processTerminalCandidatePath,
13
13
  processTerminalPath,
14
14
  resultFilePath
15
- } from "./chunk-CPSUJHZE.js";
15
+ } from "./chunk-KCDPTXHT.js";
16
16
  import {
17
17
  applyIntercomBridgeToAgent,
18
18
  resolveIntercomBridge,
19
19
  validateIntercomBridgeConfig
20
- } from "./chunk-47ZN7NKR.js";
20
+ } from "./chunk-YJIU5WF4.js";
21
21
  import {
22
22
  AGENT_DEFINITION_PROJECTION_VERSION,
23
23
  resolveLaunchBinding,
@@ -26,7 +26,7 @@ import {
26
26
  import {
27
27
  applyThinkingSuffix,
28
28
  resolvePiLaunchToolPlan
29
- } from "./chunk-D32H53HM.js";
29
+ } from "./chunk-R3NH5XAL.js";
30
30
  import {
31
31
  assertRequiredChildExtensionsAdmitted,
32
32
  resolveRequiredChildExtensions
@@ -34,7 +34,7 @@ import {
34
34
  import {
35
35
  getArtifactPaths,
36
36
  getArtifactsDir
37
- } from "./chunk-YDZ7BZD5.js";
37
+ } from "./chunk-77VQEATI.js";
38
38
  import {
39
39
  assertClaudeCodeModelScope,
40
40
  assertThinkingWithinCeiling,
@@ -61,7 +61,7 @@ import {
61
61
  resolveSkillsWithFallback,
62
62
  resolveStepBehavior,
63
63
  unknownAgentDiagnosticContext
64
- } from "./chunk-4MVDMA5C.js";
64
+ } from "./chunk-LWH7IGI3.js";
65
65
  import {
66
66
  DIRS,
67
67
  SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
@@ -8,10 +8,10 @@ import {
8
8
  openProjectPane,
9
9
  projectPaneBindingPath,
10
10
  readProjectPaneBinding
11
- } from "./chunk-2DIEL4WG.js";
11
+ } from "./chunk-OUM6SEVD.js";
12
12
  import "./chunk-7J4ZXMY7.js";
13
- import "./chunk-YDZ7BZD5.js";
14
- import "./chunk-4MVDMA5C.js";
13
+ import "./chunk-77VQEATI.js";
14
+ import "./chunk-LWH7IGI3.js";
15
15
  import "./chunk-JEZOSEWG.js";
16
16
  import "./chunk-YFCK7H2S.js";
17
17
  import "./chunk-QXASAHIA.js";