@chankov/agent-fleet 2.0.9 → 2.0.10

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 (465) hide show
  1. package/.pi/extensions/pi-voice-stt/README.md +24 -5
  2. package/.pi/extensions/pi-voice-stt/examples/stt.json +4 -4
  3. package/.pi/harnesses/agent-hub/package.json +1 -1
  4. package/.pi/harnesses/agent-hub/return-contract.js +34 -0
  5. package/.pi/harnesses/agent-hub/tools/dispatch-execution.ts +80 -18
  6. package/.pi/harnesses/coms/package.json +1 -1
  7. package/.pi/harnesses/damage-control-continue/package.json +1 -1
  8. package/.pi/harnesses/lib/changed-file-diagnostics.ts +642 -0
  9. package/.versions/2.0.10/.pi/agent-fleet/hermes/README.md +347 -0
  10. package/.versions/2.0.10/.pi/agent-fleet/hermes/desktop-plugins/agent-fleet-herdr/plugin.js +1291 -0
  11. package/.versions/2.0.10/.pi/agent-fleet/hermes/desktop-plugins/agent-fleet-herdr/presentation.js +672 -0
  12. package/.versions/2.0.10/.pi/agent-fleet/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
  13. package/.versions/2.0.10/.pi/agent-fleet/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
  14. package/.versions/2.0.10/.pi/agent-fleet/hermes/gates/gate-o-capability.md +8 -0
  15. package/.versions/2.0.10/.pi/agent-fleet/hermes/gates/gate-o-validator-fixtures.json +1 -0
  16. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +773 -0
  17. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/coms_registry.py +134 -0
  18. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/coms_send.py +350 -0
  19. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/herdr_source.py +193 -0
  20. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/manifest.json +4 -0
  21. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/plugin_api.py +444 -0
  22. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/sessions.py +205 -0
  23. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/tasks.py +300 -0
  24. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/watch.py +819 -0
  25. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/plugin.yaml +8 -0
  26. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +139 -0
  27. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
  28. package/.versions/2.0.10/.pi/agent-fleet/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
  29. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-conductor/SKILL.md +84 -0
  30. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-liaison/SKILL.md +84 -0
  31. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/SKILL.md +76 -0
  32. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/manifest.json +1 -0
  33. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog.py +249 -0
  34. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_actions.py +124 -0
  35. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_contract.py +76 -0
  36. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_delivery.py +10 -0
  37. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_engine.py +128 -0
  38. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_judgment.py +41 -0
  39. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_recovery.py +103 -0
  40. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_state.py +163 -0
  41. package/.versions/2.0.10/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_transport.py +138 -0
  42. package/.versions/2.0.10/.pi/agent-fleet/hermes/watchdog-tests/__init__.py +0 -0
  43. package/.versions/2.0.10/.pi/agent-fleet/hooks/coms-stop-hook.mjs +84 -0
  44. package/.versions/2.0.10/.pi/agent-fleet/scripts/claude-code-preflight.ts +70 -0
  45. package/.versions/2.0.10/.pi/agent-fleet/scripts/coms-claude-bridge.ts +411 -0
  46. package/.versions/2.0.10/.pi/agent-fleet/scripts/coms-cli.ts +425 -0
  47. package/.versions/2.0.10/.pi/agent-fleet/scripts/coms-hermes-bridge.ts +413 -0
  48. package/.versions/2.0.10/.pi/agent-fleet/scripts/fleet-codex-client.ts +69 -0
  49. package/.versions/2.0.10/.pi/agent-fleet/scripts/fleet-codex-read.py +148 -0
  50. package/.versions/2.0.10/.pi/agent-fleet/scripts/fleet.ts +216 -0
  51. package/.versions/2.0.10/.pi/agent-fleet/scripts/flow.ts +137 -0
  52. package/.versions/2.0.10/.pi/agent-fleet/scripts/hermes-monitor-capability-runner.ts +25 -0
  53. package/.versions/2.0.10/.pi/agent-fleet/scripts/hermes-monitor-scenario.ts +474 -0
  54. package/.versions/2.0.10/.pi/agent-fleet/scripts/hermes-watchdog-capability-probe.ts +45 -0
  55. package/.versions/2.0.10/.pi/agent-fleet/scripts/install-hermes-plugin.sh +180 -0
  56. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/claude-bridge-core.ts +210 -0
  57. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/coms-envelope.ts +582 -0
  58. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/fake-herdr-server.ts +88 -0
  59. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/fleet-codex-catalog.ts +63 -0
  60. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/fleet-codex-operations.ts +190 -0
  61. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/fleet-codex-session.ts +166 -0
  62. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/fleet-codex-transport.ts +124 -0
  63. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/fleet-command.ts +252 -0
  64. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/flow-command.ts +93 -0
  65. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/flow-maintenance.ts +230 -0
  66. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/herdr-layout.ts +281 -0
  67. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/hermes-bridge-core.ts +241 -0
  68. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/hermes-monitor-events.ts +1 -0
  69. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/hermes-monitor-herdr.ts +2 -0
  70. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/hermes-monitor-model.ts +3 -0
  71. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/hermes-monitor-registry.ts +2 -0
  72. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/hermes-monitor-socket.ts +2 -0
  73. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/hermes-monitor-store.ts +2 -0
  74. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/monitor-env.ts +146 -0
  75. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/peer-launch.ts +318 -0
  76. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/persona-banner.ts +62 -0
  77. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/persona-dirs.ts +25 -0
  78. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/runtime-dependencies.js +124 -0
  79. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/spawn-stagger.ts +101 -0
  80. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/team-project.ts +178 -0
  81. package/.versions/2.0.10/.pi/agent-fleet/scripts/lib/team-snapshot.ts +147 -0
  82. package/.versions/2.0.10/.pi/agent-fleet/scripts/package-lock.json +35 -0
  83. package/.versions/2.0.10/.pi/agent-fleet/scripts/package.json +9 -0
  84. package/.versions/2.0.10/.pi/agent-fleet/scripts/peer-banner.ts +41 -0
  85. package/.versions/2.0.10/.pi/agent-fleet/scripts/peer-launch.ts +283 -0
  86. package/.versions/2.0.10/.pi/agent-fleet/scripts/team-snapshot.ts +237 -0
  87. package/.versions/2.0.10/.pi/agent-fleet/scripts/team-up.ts +378 -0
  88. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/agent-phase.ts +133 -0
  89. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/changes.ts +61 -0
  90. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/debate.ts +149 -0
  91. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/env.ts +34 -0
  92. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/envelopes.ts +169 -0
  93. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/gates.ts +81 -0
  94. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/git.ts +96 -0
  95. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/merge.ts +95 -0
  96. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/model-profile.ts +22 -0
  97. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/model-visibility.ts +92 -0
  98. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/permissions.ts +130 -0
  99. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/personas.ts +57 -0
  100. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/poll.ts +86 -0
  101. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/quality.ts +64 -0
  102. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/run.ts +108 -0
  103. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/trace.ts +34 -0
  104. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/voices.ts +128 -0
  105. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/lib/writer-lease.ts +112 -0
  106. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/tsconfig.json +22 -0
  107. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/wf-build-test.ts +61 -0
  108. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/wf-debate.ts +87 -0
  109. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/wf-document.ts +50 -0
  110. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/wf-poll.ts +95 -0
  111. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/wf-quality.ts +20 -0
  112. package/.versions/2.0.10/.pi/agent-fleet/scripts/workflows/wf-scout.ts +38 -0
  113. package/.versions/2.0.10/.pi/agents/dispatch-policy.yaml +32 -0
  114. package/.versions/2.0.10/.pi/agents/model-profiles.yaml +83 -0
  115. package/.versions/2.0.10/.pi/agents/peers.yaml +147 -0
  116. package/.versions/2.0.10/.pi/agents/teams.yaml +41 -0
  117. package/.versions/2.0.10/.pi/agents/voices.yaml +13 -0
  118. package/.versions/2.0.10/.pi/damage-control-rules.yaml +297 -0
  119. package/.versions/2.0.10/.pi/extensions/btw/README.md +120 -0
  120. package/.versions/2.0.10/.pi/extensions/btw/index.ts +914 -0
  121. package/.versions/2.0.10/.pi/extensions/btw/package.json +6 -0
  122. package/.versions/2.0.10/.pi/extensions/btw/state.js +179 -0
  123. package/.versions/2.0.10/.pi/extensions/chrome-devtools-mcp/README.md +55 -0
  124. package/.versions/2.0.10/.pi/extensions/chrome-devtools-mcp/index.ts +93 -0
  125. package/.versions/2.0.10/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
  126. package/.versions/2.0.10/.pi/extensions/compact-and-continue/README.md +42 -0
  127. package/.versions/2.0.10/.pi/extensions/compact-and-continue/index.ts +120 -0
  128. package/.versions/2.0.10/.pi/extensions/compact-and-continue/package.json +6 -0
  129. package/.versions/2.0.10/.pi/extensions/mcp-bridge/README.md +46 -0
  130. package/.versions/2.0.10/.pi/extensions/mcp-bridge/index.ts +206 -0
  131. package/.versions/2.0.10/.pi/extensions/mcp-bridge/package.json +6 -0
  132. package/.versions/2.0.10/.pi/extensions/package-lock.json +1175 -0
  133. package/.versions/2.0.10/.pi/extensions/package.json +9 -0
  134. package/.versions/2.0.10/.pi/extensions/pi-voice-stt/README.md +224 -0
  135. package/.versions/2.0.10/.pi/extensions/pi-voice-stt/config.ts +198 -0
  136. package/.versions/2.0.10/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
  137. package/.versions/2.0.10/.pi/extensions/pi-voice-stt/index.ts +248 -0
  138. package/.versions/2.0.10/.pi/extensions/pi-voice-stt/package.json +6 -0
  139. package/.versions/2.0.10/.pi/extensions/pi-voice-stt/providers.ts +214 -0
  140. package/.versions/2.0.10/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
  141. package/.versions/2.0.10/.pi/harnesses/agent-hub/README.md +1217 -0
  142. package/.versions/2.0.10/.pi/harnesses/agent-hub/acceptance.ts +62 -0
  143. package/.versions/2.0.10/.pi/harnesses/agent-hub/access-approval.ts +135 -0
  144. package/.versions/2.0.10/.pi/harnesses/agent-hub/artifacts.js +146 -0
  145. package/.versions/2.0.10/.pi/harnesses/agent-hub/assertion-ledger.js +58 -0
  146. package/.versions/2.0.10/.pi/harnesses/agent-hub/backend-policy.js +174 -0
  147. package/.versions/2.0.10/.pi/harnesses/agent-hub/budget-continuation.ts +13 -0
  148. package/.versions/2.0.10/.pi/harnesses/agent-hub/budget-recovery.ts +97 -0
  149. package/.versions/2.0.10/.pi/harnesses/agent-hub/capability-confirmation.ts +47 -0
  150. package/.versions/2.0.10/.pi/harnesses/agent-hub/capability-packs.ts +180 -0
  151. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agent-model-thinking.ts +10 -0
  152. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agent-model.ts +10 -0
  153. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agent-models-substitute.ts +10 -0
  154. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agents-add.ts +9 -0
  155. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agents-drop.ts +9 -0
  156. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agents-history.ts +9 -0
  157. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agents-kill.ts +10 -0
  158. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agents-list.ts +9 -0
  159. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agents-restart.ts +10 -0
  160. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agents-save.ts +9 -0
  161. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/agents-team.ts +9 -0
  162. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/budget-continue.ts +10 -0
  163. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/compound.ts +9 -0
  164. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/coms.ts +9 -0
  165. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/context-command.ts +9 -0
  166. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/context.ts +43 -0
  167. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/debate.ts +9 -0
  168. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/dispatch-policy.ts +9 -0
  169. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/handoff.ts +10 -0
  170. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/hub-report.ts +9 -0
  171. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/models.ts +10 -0
  172. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/poll.ts +9 -0
  173. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/retry.ts +10 -0
  174. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/watchdog.ts +9 -0
  175. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/work-mode.ts +29 -0
  176. package/.versions/2.0.10/.pi/harnesses/agent-hub/commands/zoom.ts +10 -0
  177. package/.versions/2.0.10/.pi/harnesses/agent-hub/config/agents.ts +177 -0
  178. package/.versions/2.0.10/.pi/harnesses/agent-hub/config/model-profiles.ts +216 -0
  179. package/.versions/2.0.10/.pi/harnesses/agent-hub/config/overrides.ts +153 -0
  180. package/.versions/2.0.10/.pi/harnesses/agent-hub/context/agent-state.ts +30 -0
  181. package/.versions/2.0.10/.pi/harnesses/agent-hub/context/assertions-artifacts.ts +213 -0
  182. package/.versions/2.0.10/.pi/harnesses/agent-hub/context/budgets.ts +202 -0
  183. package/.versions/2.0.10/.pi/harnesses/agent-hub/context/hub-state.ts +40 -0
  184. package/.versions/2.0.10/.pi/harnesses/agent-hub/context-budget-snapshot.ts +105 -0
  185. package/.versions/2.0.10/.pi/harnesses/agent-hub/context-pressure.ts +191 -0
  186. package/.versions/2.0.10/.pi/harnesses/agent-hub/context-window.js +106 -0
  187. package/.versions/2.0.10/.pi/harnesses/agent-hub/debate-command.ts +176 -0
  188. package/.versions/2.0.10/.pi/harnesses/agent-hub/delegate.ts +446 -0
  189. package/.versions/2.0.10/.pi/harnesses/agent-hub/dispatch-coms.ts +237 -0
  190. package/.versions/2.0.10/.pi/harnesses/agent-hub/dispatch-core.ts +27 -0
  191. package/.versions/2.0.10/.pi/harnesses/agent-hub/dispatch-native-complete.ts +154 -0
  192. package/.versions/2.0.10/.pi/harnesses/agent-hub/dispatch-native-prepare.ts +156 -0
  193. package/.versions/2.0.10/.pi/harnesses/agent-hub/dispatch-native-spawn.ts +193 -0
  194. package/.versions/2.0.10/.pi/harnesses/agent-hub/dispatch-native-types.ts +230 -0
  195. package/.versions/2.0.10/.pi/harnesses/agent-hub/dispatch-native.ts +213 -0
  196. package/.versions/2.0.10/.pi/harnesses/agent-hub/dispatch-observability.ts +225 -0
  197. package/.versions/2.0.10/.pi/harnesses/agent-hub/docs-lane.js +122 -0
  198. package/.versions/2.0.10/.pi/harnesses/agent-hub/drift-watchdog.js +218 -0
  199. package/.versions/2.0.10/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
  200. package/.versions/2.0.10/.pi/harnesses/agent-hub/execution-evidence.ts +80 -0
  201. package/.versions/2.0.10/.pi/harnesses/agent-hub/external-blocker.js +85 -0
  202. package/.versions/2.0.10/.pi/harnesses/agent-hub/fixtures/registration-surface.json +57 -0
  203. package/.versions/2.0.10/.pi/harnesses/agent-hub/footer.ts +30 -0
  204. package/.versions/2.0.10/.pi/harnesses/agent-hub/helpers.ts +266 -0
  205. package/.versions/2.0.10/.pi/harnesses/agent-hub/hub-state-audit.js +64 -0
  206. package/.versions/2.0.10/.pi/harnesses/agent-hub/index.ts +2132 -0
  207. package/.versions/2.0.10/.pi/harnesses/agent-hub/input/completions.ts +76 -0
  208. package/.versions/2.0.10/.pi/harnesses/agent-hub/input/shortcuts.ts +20 -0
  209. package/.versions/2.0.10/.pi/harnesses/agent-hub/lifecycle/context-pressure.ts +123 -0
  210. package/.versions/2.0.10/.pi/harnesses/agent-hub/lifecycle/monitor-session.ts +104 -0
  211. package/.versions/2.0.10/.pi/harnesses/agent-hub/lifecycle/session-orchestration.ts +143 -0
  212. package/.versions/2.0.10/.pi/harnesses/agent-hub/lifecycle/turn-handlers.ts +74 -0
  213. package/.versions/2.0.10/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
  214. package/.versions/2.0.10/.pi/harnesses/agent-hub/monitor-invoke-journal.ts +131 -0
  215. package/.versions/2.0.10/.pi/harnesses/agent-hub/monitor-invoke.ts +92 -0
  216. package/.versions/2.0.10/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
  217. package/.versions/2.0.10/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
  218. package/.versions/2.0.10/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
  219. package/.versions/2.0.10/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
  220. package/.versions/2.0.10/.pi/harnesses/agent-hub/monitor-session-bridge.ts +266 -0
  221. package/.versions/2.0.10/.pi/harnesses/agent-hub/no-progress.ts +76 -0
  222. package/.versions/2.0.10/.pi/harnesses/agent-hub/package.json +7 -0
  223. package/.versions/2.0.10/.pi/harnesses/agent-hub/peer-spawn-plan.ts +116 -0
  224. package/.versions/2.0.10/.pi/harnesses/agent-hub/policy/models.ts +153 -0
  225. package/.versions/2.0.10/.pi/harnesses/agent-hub/policy/profile-activation.ts +62 -0
  226. package/.versions/2.0.10/.pi/harnesses/agent-hub/policy/profile-runtime.ts +120 -0
  227. package/.versions/2.0.10/.pi/harnesses/agent-hub/policy/roster.ts +94 -0
  228. package/.versions/2.0.10/.pi/harnesses/agent-hub/policy/work-mode.ts +119 -0
  229. package/.versions/2.0.10/.pi/harnesses/agent-hub/poll-command.ts +176 -0
  230. package/.versions/2.0.10/.pi/harnesses/agent-hub/presentation.ts +48 -0
  231. package/.versions/2.0.10/.pi/harnesses/agent-hub/prompts/context.ts +47 -0
  232. package/.versions/2.0.10/.pi/harnesses/agent-hub/prompts/fragments.ts +115 -0
  233. package/.versions/2.0.10/.pi/harnesses/agent-hub/prompts/session-start.ts +90 -0
  234. package/.versions/2.0.10/.pi/harnesses/agent-hub/prompts/system-prompt.ts +112 -0
  235. package/.versions/2.0.10/.pi/harnesses/agent-hub/provider-semaphore.js +138 -0
  236. package/.versions/2.0.10/.pi/harnesses/agent-hub/research/controls.ts +74 -0
  237. package/.versions/2.0.10/.pi/harnesses/agent-hub/research/runtime.ts +192 -0
  238. package/.versions/2.0.10/.pi/harnesses/agent-hub/research/spawn-run.ts +156 -0
  239. package/.versions/2.0.10/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
  240. package/.versions/2.0.10/.pi/harnesses/agent-hub/return-contract.js +327 -0
  241. package/.versions/2.0.10/.pi/harnesses/agent-hub/return-extract.js +75 -0
  242. package/.versions/2.0.10/.pi/harnesses/agent-hub/review-findings.js +102 -0
  243. package/.versions/2.0.10/.pi/harnesses/agent-hub/run-budget.js +537 -0
  244. package/.versions/2.0.10/.pi/harnesses/agent-hub/run-namespace.js +87 -0
  245. package/.versions/2.0.10/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
  246. package/.versions/2.0.10/.pi/harnesses/agent-hub/scope-gate.js +123 -0
  247. package/.versions/2.0.10/.pi/harnesses/agent-hub/session-health.js +110 -0
  248. package/.versions/2.0.10/.pi/harnesses/agent-hub/session-start.ts +42 -0
  249. package/.versions/2.0.10/.pi/harnesses/agent-hub/spawn.ts +404 -0
  250. package/.versions/2.0.10/.pi/harnesses/agent-hub/timeline.ts +54 -0
  251. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/action-executors.ts +149 -0
  252. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/coms-tools.ts +139 -0
  253. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/context.ts +134 -0
  254. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/dispatch-agent.ts +82 -0
  255. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/dispatch-execution.ts +335 -0
  256. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/execution-orchestration.ts +22 -0
  257. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/fleet-tools.ts +200 -0
  258. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/herdr-executors.ts +86 -0
  259. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/set-task-tier.ts +29 -0
  260. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/spawn-research.ts +62 -0
  261. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/team-adjust.ts +29 -0
  262. package/.versions/2.0.10/.pi/harnesses/agent-hub/tools/verification-contract.ts +77 -0
  263. package/.versions/2.0.10/.pi/harnesses/agent-hub/types.ts +63 -0
  264. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/activity-dots.ts +16 -0
  265. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/context-budget.ts +86 -0
  266. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/detail-panel.ts +178 -0
  267. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/fleet-actions.ts +76 -0
  268. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/fleet-dashboard.ts +99 -0
  269. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/fleet-editor.ts +44 -0
  270. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/fleet-source.ts +157 -0
  271. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/grid.ts +154 -0
  272. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/history-store.ts +137 -0
  273. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/history.ts +234 -0
  274. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/pool.ts +103 -0
  275. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/running-strip.ts +2 -0
  276. package/.versions/2.0.10/.pi/harnesses/agent-hub/ui/zoom.ts +204 -0
  277. package/.versions/2.0.10/.pi/harnesses/agent-hub/version.ts +42 -0
  278. package/.versions/2.0.10/.pi/harnesses/agent-hub/work-mode-controls.ts +56 -0
  279. package/.versions/2.0.10/.pi/harnesses/agent-hub/work-mode.ts +167 -0
  280. package/.versions/2.0.10/.pi/harnesses/ask-user-remote/README.md +59 -0
  281. package/.versions/2.0.10/.pi/harnesses/ask-user-remote/index.ts +558 -0
  282. package/.versions/2.0.10/.pi/harnesses/ask-user-remote/questions.ts +161 -0
  283. package/.versions/2.0.10/.pi/harnesses/ask-user-remote/race-core.js +124 -0
  284. package/.versions/2.0.10/.pi/harnesses/ask-user-remote/runtime-ask.ts +43 -0
  285. package/.versions/2.0.10/.pi/harnesses/coms/README.md +100 -0
  286. package/.versions/2.0.10/.pi/harnesses/coms/index.ts +282 -0
  287. package/.versions/2.0.10/.pi/harnesses/coms/package.json +7 -0
  288. package/.versions/2.0.10/.pi/harnesses/coms/version.ts +42 -0
  289. package/.versions/2.0.10/.pi/harnesses/damage-control-continue/README.md +135 -0
  290. package/.versions/2.0.10/.pi/harnesses/damage-control-continue/index.ts +541 -0
  291. package/.versions/2.0.10/.pi/harnesses/damage-control-continue/package.json +7 -0
  292. package/.versions/2.0.10/.pi/harnesses/damage-control-continue/version.ts +42 -0
  293. package/.versions/2.0.10/.pi/harnesses/lib/changed-file-diagnostics.ts +642 -0
  294. package/.versions/2.0.10/.pi/harnesses/lib/coms-core-io.ts +385 -0
  295. package/.versions/2.0.10/.pi/harnesses/lib/coms-core.ts +577 -0
  296. package/.versions/2.0.10/.pi/harnesses/lib/coms-registry-entry.ts +94 -0
  297. package/.versions/2.0.10/.pi/harnesses/lib/context-budget-child-prompt.ts +180 -0
  298. package/.versions/2.0.10/.pi/harnesses/lib/context-budget-hub-prompt.ts +114 -0
  299. package/.versions/2.0.10/.pi/harnesses/lib/context-budget-view.ts +107 -0
  300. package/.versions/2.0.10/.pi/harnesses/lib/context-budget.ts +114 -0
  301. package/.versions/2.0.10/.pi/harnesses/lib/damage-control-shared.ts +197 -0
  302. package/.versions/2.0.10/.pi/harnesses/lib/fixtures/context-budget-profiles.json +11 -0
  303. package/.versions/2.0.10/.pi/harnesses/lib/fixtures/hub-prompt-operator.legacy.txt +73 -0
  304. package/.versions/2.0.10/.pi/harnesses/lib/fixtures/hub-prompt-orchestrator.legacy.txt +73 -0
  305. package/.versions/2.0.10/.pi/harnesses/lib/fleet-dashboard-ops.ts +178 -0
  306. package/.versions/2.0.10/.pi/harnesses/lib/fleet-dashboard-view.ts +134 -0
  307. package/.versions/2.0.10/.pi/harnesses/lib/fleet-detail-view.ts +247 -0
  308. package/.versions/2.0.10/.pi/harnesses/lib/fleet-overlay.ts +26 -0
  309. package/.versions/2.0.10/.pi/harnesses/lib/fleet-panel.ts +34 -0
  310. package/.versions/2.0.10/.pi/harnesses/lib/fleet-read-model.ts +213 -0
  311. package/.versions/2.0.10/.pi/harnesses/lib/fleet-selection.ts +24 -0
  312. package/.versions/2.0.10/.pi/harnesses/lib/fleet-strip-controller.ts +74 -0
  313. package/.versions/2.0.10/.pi/harnesses/lib/fleet-strip-view.ts +132 -0
  314. package/.versions/2.0.10/.pi/harnesses/lib/fleet-transcript-store.ts +244 -0
  315. package/.versions/2.0.10/.pi/harnesses/lib/herdr-client.ts +472 -0
  316. package/.versions/2.0.10/.pi/harnesses/lib/herdr-presence.ts +399 -0
  317. package/.versions/2.0.10/.pi/harnesses/lib/hermes-monitor-events.ts +136 -0
  318. package/.versions/2.0.10/.pi/harnesses/lib/hermes-monitor-herdr.ts +28 -0
  319. package/.versions/2.0.10/.pi/harnesses/lib/hermes-monitor-model.ts +18 -0
  320. package/.versions/2.0.10/.pi/harnesses/lib/hermes-monitor-registry.ts +6 -0
  321. package/.versions/2.0.10/.pi/harnesses/lib/hermes-monitor-socket.ts +163 -0
  322. package/.versions/2.0.10/.pi/harnesses/lib/hermes-monitor-store.ts +31 -0
  323. package/.versions/2.0.10/.pi/harnesses/lib/spawned-peers.js +190 -0
  324. package/.versions/2.0.10/.pi/harnesses/lib/update-check.ts +222 -0
  325. package/.versions/2.0.10/.pi/harnesses/package-lock.json +2039 -0
  326. package/.versions/2.0.10/.pi/harnesses/package.json +10 -0
  327. package/.versions/2.0.10/.pi/prompts/af-build.md +24 -0
  328. package/.versions/2.0.10/.pi/prompts/af-code-simplify.md +22 -0
  329. package/.versions/2.0.10/.pi/prompts/af-constraints.md +31 -0
  330. package/.versions/2.0.10/.pi/prompts/af-plan.md +17 -0
  331. package/.versions/2.0.10/.pi/prompts/af-review.md +16 -0
  332. package/.versions/2.0.10/.pi/prompts/af-set-hermes-telegram.md +15 -0
  333. package/.versions/2.0.10/.pi/prompts/af-set-hermes-watchdog.md +6 -0
  334. package/.versions/2.0.10/.pi/prompts/af-ship.md +17 -0
  335. package/.versions/2.0.10/.pi/prompts/af-spec.md +15 -0
  336. package/.versions/2.0.10/.pi/prompts/af-test.md +19 -0
  337. package/.versions/2.0.10/.pi/skills/bowser/SKILL.md +145 -0
  338. package/.versions/2.0.10/.version +1 -0
  339. package/.versions/2.0.10/agents/architect.md +25 -0
  340. package/.versions/2.0.10/agents/bowser.md +28 -0
  341. package/.versions/2.0.10/agents/builder.md +56 -0
  342. package/.versions/2.0.10/agents/code-reviewer.md +210 -0
  343. package/.versions/2.0.10/agents/deep-researcher.md +33 -0
  344. package/.versions/2.0.10/agents/documenter.md +23 -0
  345. package/.versions/2.0.10/agents/orchestrator.md +23 -0
  346. package/.versions/2.0.10/agents/plan-reviewer.md +84 -0
  347. package/.versions/2.0.10/agents/planner.md +106 -0
  348. package/.versions/2.0.10/agents/releaser.md +25 -0
  349. package/.versions/2.0.10/agents/researcher.md +31 -0
  350. package/.versions/2.0.10/agents/security-auditor.md +168 -0
  351. package/.versions/2.0.10/agents/test-engineer.md +154 -0
  352. package/.versions/2.0.10/agents/web-debugger.md +44 -0
  353. package/.versions/2.0.10/agents/web-performance-auditor.md +194 -0
  354. package/.versions/2.0.10/bin/catalog/harness-runtime-closure.json +32 -0
  355. package/.versions/2.0.10/codex/fleet-session-client/SKILL.md +34 -0
  356. package/.versions/2.0.10/codex/fleet-session-client.zip +0 -0
  357. package/.versions/2.0.10/docs/ARCHITECTURE.md +416 -0
  358. package/.versions/2.0.10/docs/agent-fleet-setup.md +586 -0
  359. package/.versions/2.0.10/docs/claude-code-coms-bridge.md +134 -0
  360. package/.versions/2.0.10/docs/codex-session-bridge.md +219 -0
  361. package/.versions/2.0.10/docs/coms-hermes-bridge.md +188 -0
  362. package/.versions/2.0.10/docs/getting-started.md +126 -0
  363. package/.versions/2.0.10/docs/npm-install.md +383 -0
  364. package/.versions/2.0.10/docs/pi-extensions.md +449 -0
  365. package/.versions/2.0.10/docs/pi-setup.md +92 -0
  366. package/.versions/2.0.10/docs/skill-anatomy.md +150 -0
  367. package/.versions/2.0.10/install-manifest.json +2991 -0
  368. package/.versions/2.0.10/justfile +247 -0
  369. package/.versions/2.0.10/manifest-meta.json +970 -0
  370. package/.versions/2.0.10/references/accessibility-checklist.md +160 -0
  371. package/.versions/2.0.10/references/communication-contract.md +26 -0
  372. package/.versions/2.0.10/references/definition-of-done.md +67 -0
  373. package/.versions/2.0.10/references/fleet-coordination-patterns.md +171 -0
  374. package/.versions/2.0.10/references/observability-checklist.md +92 -0
  375. package/.versions/2.0.10/references/orchestration-patterns.md +370 -0
  376. package/.versions/2.0.10/references/performance-checklist.md +236 -0
  377. package/.versions/2.0.10/references/prompting-patterns.md +380 -0
  378. package/.versions/2.0.10/references/security-checklist.md +245 -0
  379. package/.versions/2.0.10/references/testing-patterns.md +235 -0
  380. package/.versions/2.0.10/references/workflow-authoring.md +304 -0
  381. package/.versions/2.0.10/skills/_internal/grilling.md +59 -0
  382. package/.versions/2.0.10/skills/browser-testing-with-devtools/SKILL.md +351 -0
  383. package/.versions/2.0.10/skills/code-review-and-quality/SKILL.md +396 -0
  384. package/.versions/2.0.10/skills/compound-learning/SKILL.md +137 -0
  385. package/.versions/2.0.10/skills/constraint-driven-development/SKILL.md +338 -0
  386. package/.versions/2.0.10/skills/constraint-driven-development/references/floor-guard.md +99 -0
  387. package/.versions/2.0.10/skills/context-engineering/SKILL.md +341 -0
  388. package/.versions/2.0.10/skills/deprecation-and-migration/SKILL.md +247 -0
  389. package/.versions/2.0.10/skills/designing-agents/SKILL.md +394 -0
  390. package/.versions/2.0.10/skills/designing-agents/pi-harness-authoring.md +222 -0
  391. package/.versions/2.0.10/skills/drafting-workflows/SKILL.md +143 -0
  392. package/.versions/2.0.10/skills/drafting-workflows/scripts/make-workflow.ts +177 -0
  393. package/.versions/2.0.10/skills/frontend-ui-engineering/SKILL.md +328 -0
  394. package/.versions/2.0.10/skills/git-workflow-and-versioning/SKILL.md +316 -0
  395. package/.versions/2.0.10/skills/idea-refine/SKILL.md +182 -0
  396. package/.versions/2.0.10/skills/idea-refine/examples.md +238 -0
  397. package/.versions/2.0.10/skills/idea-refine/frameworks.md +99 -0
  398. package/.versions/2.0.10/skills/idea-refine/refinement-criteria.md +113 -0
  399. package/.versions/2.0.10/skills/idea-refine/scripts/idea-refine.sh +15 -0
  400. package/.versions/2.0.10/skills/incremental-implementation/SKILL.md +302 -0
  401. package/.versions/2.0.10/skills/interview-me/SKILL.md +226 -0
  402. package/.versions/2.0.10/skills/orchestration-verification/SKILL.md +182 -0
  403. package/.versions/2.0.10/skills/peer-coms/SKILL.md +90 -0
  404. package/.versions/2.0.10/skills/performance-optimization/SKILL.md +496 -0
  405. package/.versions/2.0.10/skills/planning-and-task-breakdown/SKILL.md +289 -0
  406. package/.versions/2.0.10/skills/security-and-hardening/SKILL.md +524 -0
  407. package/.versions/2.0.10/skills/spec-driven-development/SKILL.md +295 -0
  408. package/.versions/2.0.10/skills/using-agent-skills/SKILL.md +198 -0
  409. package/.versions/2.0.10/vendor/agent-skills-upstream/LICENSE +21 -0
  410. package/.versions/2.0.10/vendor/agent-skills-upstream/README.md +430 -0
  411. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +367 -0
  412. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
  413. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
  414. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
  415. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
  416. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/constraint-driven-development/SKILL.md +311 -0
  417. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/constraint-driven-development/references/floor-guard.md +99 -0
  418. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +337 -0
  419. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
  420. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
  421. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +288 -0
  422. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
  423. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
  424. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
  425. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
  426. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
  427. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
  428. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
  429. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
  430. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
  431. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
  432. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +238 -0
  433. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +496 -0
  434. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +257 -0
  435. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +524 -0
  436. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +330 -0
  437. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +216 -0
  438. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +245 -0
  439. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +398 -0
  440. package/.versions/2.0.10/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +192 -0
  441. package/CHANGELOG.md +11 -0
  442. package/agents/architect.md +1 -1
  443. package/agents/bowser.md +1 -1
  444. package/agents/builder.md +1 -1
  445. package/agents/code-reviewer.md +1 -1
  446. package/agents/deep-researcher.md +1 -1
  447. package/agents/documenter.md +1 -1
  448. package/agents/orchestrator.md +1 -1
  449. package/agents/plan-reviewer.md +1 -1
  450. package/agents/planner.md +1 -1
  451. package/agents/releaser.md +1 -1
  452. package/agents/researcher.md +1 -1
  453. package/agents/security-auditor.md +1 -1
  454. package/agents/test-engineer.md +1 -1
  455. package/agents/web-debugger.md +1 -1
  456. package/agents/web-performance-auditor.md +1 -1
  457. package/bin/cli.js +8 -5
  458. package/bin/lib/path-boundaries.js +5 -6
  459. package/bin/lib/stt-wizard.js +154 -23
  460. package/docs/agent-fleet-setup.md +26 -8
  461. package/docs/npm-install.md +29 -2
  462. package/docs/pi-setup.md +16 -0
  463. package/install-manifest.json +1 -1
  464. package/package.json +13 -3
  465. package/skills/orchestration-verification/SKILL.md +1 -0
@@ -0,0 +1,413 @@
1
+ // .pi/agent-fleet/scripts/coms-hermes-bridge.ts
2
+ //
3
+ // Hermes/Telegram user-remote bridge daemon. Registers a coms peer, turns
4
+ // prompt envelopes into `hermes send` messages, watches the private answer-file
5
+ // wire, and replies to the sender with the mapped answer/error envelope.
6
+
7
+ import { spawn } from "node:child_process";
8
+ import * as fs from "node:fs";
9
+ import * as path from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+
12
+ import {
13
+ bindEndpoint,
14
+ ensureComsDirs,
15
+ isCancelEnvelope,
16
+ isPromptEnvelope,
17
+ makeConnHandler,
18
+ makeEndpoint,
19
+ makeResponseEnvelope,
20
+ nowIso,
21
+ removeRegistryEntry,
22
+ resolveUniqueName,
23
+ sendEnvelope,
24
+ ulid,
25
+ writeAck,
26
+ writeNack,
27
+ writeRegistryAtomic,
28
+ type AgentCard,
29
+ type PromptEnvelope,
30
+ type RegistryEntry,
31
+ type SenderIdentity,
32
+ } from "./lib/coms-envelope.ts";
33
+ import {
34
+ formatTelegramQuestion,
35
+ isValidQid,
36
+ logPath as defaultLogPath,
37
+ makeLogRecord,
38
+ mapAnswerToAskResponse,
39
+ qidFromPromptEnvelope,
40
+ questionsDir as defaultQuestionsDir,
41
+ renderLogRecord,
42
+ timeoutMsFromEnv,
43
+ timeoutOutcome,
44
+ validateAnswerFile,
45
+ type BridgeEventName,
46
+ type QuestionOption,
47
+ type QuestionState,
48
+ } from "./lib/hermes-bridge-core.ts";
49
+
50
+ const KEEPALIVE_MS = 30_000;
51
+ const DEFAULT_POLL_MS = 1_000;
52
+ const COLOR = "#38BDF8";
53
+ const DEFAULT_NAME = "user-remote";
54
+ const DEFAULT_PURPOSE = "Remote human via Hermes/Telegram";
55
+ const HERMES_PROFILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
56
+
57
+ interface PendingQuestion {
58
+ env: PromptEnvelope;
59
+ state: QuestionState;
60
+ options: QuestionOption[];
61
+ timer: NodeJS.Timeout;
62
+ }
63
+
64
+ interface ParsedPrompt {
65
+ question: string;
66
+ context?: string;
67
+ options: QuestionOption[];
68
+ }
69
+
70
+ function flagValue(argv: string[], flag: string): string | null {
71
+ const positions = argv.flatMap((arg, index) => arg === flag ? [index] : []);
72
+ if (positions.length > 1) die(`${flag} may only be specified once`);
73
+ const i = positions[0] ?? -1;
74
+ return i >= 0 && i + 1 < argv.length ? argv[i + 1] : null;
75
+ }
76
+
77
+ function die(msg: string): never {
78
+ console.error(`coms-hermes-bridge: ${msg}`);
79
+ process.exit(1);
80
+ }
81
+
82
+ function parsePrompt(env: PromptEnvelope): ParsedPrompt {
83
+ try {
84
+ const parsed = JSON.parse(env.prompt) as { question?: unknown; context?: unknown; options?: unknown };
85
+ if (parsed && typeof parsed === "object" && typeof parsed.question === "string") {
86
+ const rawOptions = Array.isArray(parsed.options) ? parsed.options : [];
87
+ const options = rawOptions
88
+ .map((option): QuestionOption | null => {
89
+ if (typeof option === "string") return { title: option };
90
+ if (option && typeof option === "object" && typeof (option as { title?: unknown }).title === "string") {
91
+ const desc = (option as { description?: unknown }).description;
92
+ return typeof desc === "string"
93
+ ? { title: (option as { title: string }).title, description: desc }
94
+ : { title: (option as { title: string }).title };
95
+ }
96
+ return null;
97
+ })
98
+ .filter((option): option is QuestionOption => option !== null);
99
+ const context = typeof parsed.context === "string" && parsed.context.trim() ? parsed.context : undefined;
100
+ return { question: parsed.question, context, options };
101
+ }
102
+ } catch {
103
+ // Plain coms-cli prompts are expected; fall through.
104
+ }
105
+ return {
106
+ question: env.prompt,
107
+ context: `From ${env.sender_name} @ ${env.sender_cwd}`,
108
+ options: [],
109
+ };
110
+ }
111
+
112
+ function appendLogFile(logFile: string, qid: string, event: BridgeEventName, detail?: unknown): void {
113
+ fs.mkdirSync(path.dirname(logFile), { recursive: true });
114
+ fs.appendFileSync(logFile, renderLogRecord(makeLogRecord(qid, event, detail)));
115
+ }
116
+
117
+ function appendAnswerRejectLog(logFile: string, qid: string, detail: unknown): void {
118
+ fs.mkdirSync(path.dirname(logFile), { recursive: true });
119
+ fs.appendFileSync(logFile, JSON.stringify({ at: nowIso(), qid, event: "answer_rejected", detail }) + "\n");
120
+ }
121
+
122
+ function hermesSend(to: string, text: string, profile: string | null): Promise<void> {
123
+ return new Promise((resolve, reject) => {
124
+ const args = [...(profile ? ["--profile", profile] : []), "send", "--to", to, text];
125
+ const child = spawn("hermes", args, { stdio: ["ignore", "pipe", "pipe"] });
126
+ let stderr = "";
127
+ let stdout = "";
128
+ child.stdout?.on("data", (chunk) => { stdout += chunk.toString("utf-8"); });
129
+ child.stderr?.on("data", (chunk) => { stderr += chunk.toString("utf-8"); });
130
+ child.once("error", (err) => reject(err));
131
+ child.once("close", (code) => {
132
+ if (code === 0) {
133
+ resolve();
134
+ return;
135
+ }
136
+ const detail = (stderr || stdout).trim();
137
+ reject(new Error(`hermes send failed${code === null ? "" : ` (${code})`}${detail ? `: ${detail}` : ""}`));
138
+ });
139
+ });
140
+ }
141
+
142
+ async function main(): Promise<void> {
143
+ const argv = process.argv.slice(2);
144
+ const requestedName = flagValue(argv, "--name") ?? DEFAULT_NAME;
145
+ const project = flagValue(argv, "--project") ?? "default";
146
+ const to = flagValue(argv, "--to") ?? "telegram";
147
+ const hermesProfile = flagValue(argv, "--hermes-profile");
148
+ const timeoutMs = Number(flagValue(argv, "--timeout") ?? timeoutMsFromEnv());
149
+ const pollMs = Number(flagValue(argv, "--poll-ms") ?? DEFAULT_POLL_MS);
150
+ const qDir = flagValue(argv, "--questions-dir") ?? defaultQuestionsDir();
151
+ const logFile = path.join(path.dirname(qDir), path.basename(defaultLogPath()));
152
+
153
+ if (hermesProfile && (!HERMES_PROFILE_RE.test(hermesProfile) || hermesProfile === "." || hermesProfile.includes(".."))) die("--hermes-profile must be a safe profile name");
154
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) die("--timeout must be a positive number");
155
+ if (!Number.isFinite(pollMs) || pollMs <= 0) die("--poll-ms must be a positive number");
156
+
157
+ ensureComsDirs(project);
158
+ fs.mkdirSync(qDir, { recursive: true });
159
+ fs.mkdirSync(path.dirname(logFile), { recursive: true });
160
+
161
+ const sessionId = ulid();
162
+ const uniqueName = resolveUniqueName(project, requestedName);
163
+ const id: SenderIdentity = {
164
+ session_id: sessionId,
165
+ name: uniqueName,
166
+ endpoint: makeEndpoint(sessionId),
167
+ cwd: process.cwd(),
168
+ };
169
+ const pending = new Map<string, PendingQuestion>();
170
+ const closed = new Map<string, QuestionState>();
171
+ // Answer files the liaison may still be mid-write: an invalid_json file is
172
+ // kept for a short grace window (first-seen timestamps below) instead of
173
+ // being eaten while the write is still in flight.
174
+ const invalidJsonSeen = new Map<string, number>();
175
+ const invalidJsonGraceMs = Math.max(2 * pollMs, 1_000);
176
+ const CLOSED_CAP = 1_000;
177
+
178
+ function markClosed(qid: string, state: QuestionState): void {
179
+ closed.set(qid, state);
180
+ if (closed.size > CLOSED_CAP) {
181
+ const oldest = closed.keys().next().value;
182
+ if (oldest !== undefined) closed.delete(oldest);
183
+ }
184
+ }
185
+
186
+ function queueDepth(): number {
187
+ return pending.size;
188
+ }
189
+
190
+ function registryEntry(): RegistryEntry {
191
+ return {
192
+ session_id: sessionId,
193
+ name: uniqueName,
194
+ purpose: DEFAULT_PURPOSE,
195
+ model: "hermes-bridge",
196
+ color: COLOR,
197
+ pid: process.pid,
198
+ endpoint: id.endpoint,
199
+ cwd: id.cwd,
200
+ started_at: nowIso(),
201
+ explicit: false,
202
+ version: 1,
203
+ context_used_pct: 0,
204
+ queue_depth: queueDepth(),
205
+ heartbeat_at: nowIso(),
206
+ };
207
+ }
208
+
209
+ async function sendResponse(env: PromptEnvelope, response: unknown, error: string | null = null): Promise<void> {
210
+ await sendEnvelope(env.sender_endpoint, makeResponseEnvelope(id, env.msg_id, response, error));
211
+ }
212
+
213
+ async function handleTimeout(qid: string): Promise<void> {
214
+ const item = pending.get(qid);
215
+ if (!item) return;
216
+ pending.delete(qid);
217
+ markClosed(qid, "timeout");
218
+ appendLogFile(logFile, qid, "timeout", { timeout_ms: timeoutMs });
219
+ const outcome = timeoutOutcome(qid, timeoutMs);
220
+ await hermesSend(to, outcome.telegramNote, hermesProfile).catch((err) => {
221
+ appendLogFile(logFile, qid, "delivery_error", { phase: "timeout_note", error: err instanceof Error ? err.message : String(err) });
222
+ });
223
+ await sendResponse(item.env, outcome.response, outcome.error).catch((err) => {
224
+ console.error(`coms-hermes-bridge: could not deliver timeout for ${qid}: ${err instanceof Error ? err.message : String(err)}`);
225
+ });
226
+ }
227
+
228
+ async function handlePrompt(env: PromptEnvelope): Promise<void> {
229
+ let qid: string;
230
+ try {
231
+ qid = qidFromPromptEnvelope(env);
232
+ } catch (err) {
233
+ await sendResponse(env, null, err instanceof Error ? err.message : String(err)).catch(() => {});
234
+ return;
235
+ }
236
+
237
+ const parsed = parsePrompt(env);
238
+ const duplicate = pending.get(qid);
239
+ if (duplicate) clearTimeout(duplicate.timer);
240
+ appendLogFile(logFile, qid, "question_received", { from: env.sender_name });
241
+ const timer = setTimeout(() => { void handleTimeout(qid); }, timeoutMs);
242
+ timer.unref?.();
243
+ pending.set(qid, { env, state: "pending", options: parsed.options, timer });
244
+
245
+ try {
246
+ await hermesSend(to, formatTelegramQuestion({
247
+ qid,
248
+ project,
249
+ question: parsed.question,
250
+ context: parsed.context,
251
+ options: parsed.options,
252
+ }), hermesProfile);
253
+ const item = pending.get(qid);
254
+ if (!item) return;
255
+ item.state = "delivered";
256
+ appendLogFile(logFile, qid, "delivered", { to });
257
+ } catch (err) {
258
+ const message = err instanceof Error ? err.message : String(err);
259
+ const item = pending.get(qid);
260
+ if (item) {
261
+ clearTimeout(item.timer);
262
+ pending.delete(qid);
263
+ }
264
+ appendLogFile(logFile, qid, "delivery_error", { error: message });
265
+ await sendResponse(env, null, message).catch((sendErr) => {
266
+ console.error(`coms-hermes-bridge: could not deliver error for ${qid}: ${sendErr instanceof Error ? sendErr.message : String(sendErr)}`);
267
+ });
268
+ }
269
+ }
270
+
271
+ async function handleCancel(refMsgId: string): Promise<void> {
272
+ if (!isValidQid(refMsgId)) return;
273
+ const item = pending.get(refMsgId);
274
+ if (!item) return;
275
+ clearTimeout(item.timer);
276
+ pending.delete(refMsgId);
277
+ markClosed(refMsgId, "cancelled");
278
+ appendLogFile(logFile, refMsgId, "cancelled", { reason: "cancel envelope" });
279
+ await hermesSend(to, `✖ [HUB-Q:${refMsgId}] The question was cancelled — it was answered from the console.`, hermesProfile).catch((err) => {
280
+ appendLogFile(logFile, refMsgId, "delivery_error", { phase: "cancel_note", error: err instanceof Error ? err.message : String(err) });
281
+ });
282
+ }
283
+
284
+ async function handleLateAnswer(qid: string): Promise<void> {
285
+ appendLogFile(logFile, qid, "late_answer", { state: closed.get(qid) ?? "unknown" });
286
+ await hermesSend(to, `ℹ [HUB-Q:${qid}] This question is already closed; the late answer was ignored.`, hermesProfile).catch((err) => {
287
+ appendLogFile(logFile, qid, "delivery_error", { phase: "late_note", error: err instanceof Error ? err.message : String(err) });
288
+ });
289
+ }
290
+
291
+ async function consumeAnswerFile(file: string): Promise<void> {
292
+ const full = path.join(qDir, file);
293
+ let raw: string;
294
+ try {
295
+ raw = fs.readFileSync(full, "utf-8");
296
+ } catch {
297
+ return;
298
+ }
299
+
300
+ const qidFromName = file.endsWith(".answer.json") ? file.slice(0, -".answer.json".length) : file;
301
+ if (isValidQid(qidFromName) && closed.has(qidFromName)) {
302
+ invalidJsonSeen.delete(file);
303
+ try { fs.unlinkSync(full); } catch { /* ignore */ }
304
+ await handleLateAnswer(qidFromName);
305
+ return;
306
+ }
307
+
308
+ const validation = validateAnswerFile(raw, full, pending.keys());
309
+ if (!validation.ok) {
310
+ if (validation.reason === "invalid_json") {
311
+ // Possibly a partial write from the liaison; retry until the grace expires.
312
+ const firstSeen = invalidJsonSeen.get(file);
313
+ if (firstSeen === undefined) {
314
+ invalidJsonSeen.set(file, Date.now());
315
+ return;
316
+ }
317
+ if (Date.now() - firstSeen < invalidJsonGraceMs) return;
318
+ }
319
+ invalidJsonSeen.delete(file);
320
+ const logQid = validation.qid && isValidQid(validation.qid) ? validation.qid : (isValidQid(qidFromName) ? qidFromName : "00000000000000000000000000");
321
+ // Remove the rejected file before publishing the event. Consumers use the
322
+ // log as the completion signal and may immediately write a corrected file
323
+ // at the same path; logging first lets this scan delete that replacement.
324
+ try { fs.unlinkSync(full); } catch { /* ignore */ }
325
+ appendAnswerRejectLog(logFile, logQid, { reason: validation.reason, file });
326
+ return;
327
+ }
328
+
329
+ invalidJsonSeen.delete(file);
330
+ const item = pending.get(validation.qid);
331
+ if (!item) return;
332
+ clearTimeout(item.timer);
333
+ pending.delete(validation.qid);
334
+ markClosed(validation.qid, "answered");
335
+ try { fs.unlinkSync(full); } catch { /* ignore */ }
336
+ appendLogFile(logFile, validation.qid, "answered", { answered_by: validation.answer.answered_by });
337
+ const response = mapAnswerToAskResponse(validation.answer.answer, item.options);
338
+ await sendResponse(item.env, response).catch((err) => {
339
+ console.error(`coms-hermes-bridge: could not deliver answer for ${validation.qid}: ${err instanceof Error ? err.message : String(err)}`);
340
+ });
341
+ }
342
+
343
+ async function scanAnswers(): Promise<void> {
344
+ let files: string[];
345
+ try {
346
+ files = fs.readdirSync(qDir);
347
+ } catch {
348
+ return;
349
+ }
350
+ for (const file of files) {
351
+ await consumeAnswerFile(file);
352
+ }
353
+ }
354
+
355
+ const server = await bindEndpoint(
356
+ id.endpoint,
357
+ makeConnHandler((env, socket) => {
358
+ if (isPromptEnvelope(env)) {
359
+ writeAck(socket, env.msg_id);
360
+ void handlePrompt(env);
361
+ } else if (isCancelEnvelope(env)) {
362
+ writeAck(socket, env.msg_id);
363
+ void handleCancel(env.ref_msg_id);
364
+ } else if ((env as { type?: string }).type === "ping") {
365
+ const card: AgentCard = {
366
+ name: uniqueName,
367
+ purpose: DEFAULT_PURPOSE,
368
+ model: "hermes-bridge",
369
+ color: COLOR,
370
+ context_used_pct: 0,
371
+ queue_depth: queueDepth(),
372
+ };
373
+ try {
374
+ socket.write(JSON.stringify({ type: "pong", msg_id: (env as { msg_id?: string }).msg_id ?? "", agent_card: card }) + "\n");
375
+ } catch { /* ignore */ }
376
+ try { socket.end(); } catch { /* ignore */ }
377
+ } else {
378
+ writeNack(socket, (env as { msg_id?: string }).msg_id ?? "", "bridge accepts prompts, cancels, and pings");
379
+ }
380
+ }),
381
+ );
382
+
383
+ const keepalive = setInterval(() => {
384
+ try { writeRegistryAtomic(registryEntry(), project); } catch { /* best-effort */ }
385
+ }, KEEPALIVE_MS);
386
+ keepalive.unref?.();
387
+ const watcher = setInterval(() => { void scanAnswers(); }, pollMs);
388
+ watcher.unref?.();
389
+
390
+ let shuttingDown = false;
391
+ function shutdown(): void {
392
+ if (shuttingDown) return;
393
+ shuttingDown = true;
394
+ clearInterval(keepalive);
395
+ clearInterval(watcher);
396
+ for (const item of pending.values()) clearTimeout(item.timer);
397
+ try { server.close(); } catch { /* ignore */ }
398
+ try { fs.unlinkSync(id.endpoint); } catch { /* ignore */ }
399
+ removeRegistryEntry(project, uniqueName);
400
+ process.exit(0);
401
+ }
402
+ process.on("SIGTERM", shutdown);
403
+ process.on("SIGINT", shutdown);
404
+
405
+ // Publish readiness only after shutdown handlers are installed. A caller may
406
+ // terminate the bridge as soon as its registry entry appears; publishing
407
+ // earlier can bypass cleanup and leave both the entry and socket behind.
408
+ writeRegistryAtomic(registryEntry(), project);
409
+ console.error(`coms-hermes-bridge: ${uniqueName}@${project} listening (${to})`);
410
+ }
411
+
412
+ const isEntry = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
413
+ if (isEntry) void main();
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ import * as fs from 'node:fs';
3
+ import {spawnSync} from 'node:child_process';
4
+ import * as os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { FleetSessionClient } from './lib/fleet-codex-session.ts';
8
+ import { clientCatalog, parseClientArguments } from './lib/fleet-codex-catalog.ts';
9
+ import { FleetClientOperations } from './lib/fleet-codex-operations.ts';
10
+
11
+ function readInstructionFile(filePath: string): string {
12
+ const resolved = path.resolve(filePath);
13
+ const stats = fs.lstatSync(resolved);
14
+ if (stats.isSymbolicLink() || !stats.isFile() || (process.getuid && stats.uid !== process.getuid()) || (stats.mode & 0o077)) {
15
+ throw Error('unsafe text file');
16
+ }
17
+ if (stats.size > 16000) throw Error('text file must contain at most 16000 bytes');
18
+ const flags = fs.constants.O_RDONLY | (typeof fs.constants.O_NOFOLLOW === 'number' ? fs.constants.O_NOFOLLOW : 0);
19
+ const fd = fs.openSync(resolved, flags);
20
+ try {
21
+ const opened = fs.fstatSync(fd);
22
+ if (!opened.isFile() || opened.size > 16000 || (process.getuid && opened.uid !== process.getuid()) || (opened.mode & 0o077)) {
23
+ throw Error('unsafe text file');
24
+ }
25
+ return fs.readFileSync(fd, 'utf8');
26
+ } finally { fs.closeSync(fd); }
27
+ }
28
+
29
+ export async function runClient(argv:string[],env:NodeJS.ProcessEnv=process.env,emit:(value:unknown)=>void=()=>{}) {
30
+ if(argv.length===1&&argv[0]==='--help')return clientCatalog();
31
+ const {command,flags}=parseClientArguments(argv);
32
+ const client=new FleetSessionClient({stateDir:flags['state-dir']??path.join(env.CODEX_HOME||path.join(os.homedir(),'.codex'),'fleet-client'),clientId:env.CODEX_THREAD_ID});
33
+ const operations=new FleetClientOperations(client);
34
+ switch(command){
35
+ case 'describe':return operations.describe();
36
+ case 'sessions':return client.sessions(flags.project);
37
+ case 'select':return client.select(flags.project,flags.peer);
38
+ case 'status':return operations.status();
39
+ case 'doctor': {
40
+ const dependency=(binary:string)=>{const r=spawnSync(binary,['--version'],{encoding:'utf8',timeout:3000,maxBuffer:4096});return {available:r.status===0,version:r.status===0?r.stdout.trim():null};};
41
+ return {node:process.version,python:dependency('python3'),herdr:dependency('herdr'),identityAvailable:!!env.CODEX_THREAD_ID,selection:env.CODEX_THREAD_ID?client.status():null,scope:'local client; no service lifecycle or model changes'};
42
+ }
43
+ case 'detach':return client.detach();
44
+ case 'activity':case 'summary':return operations.resync(true);
45
+ case 'resync':return operations.resync();
46
+ case 'replay':return operations.replay();
47
+ case 'receipts':return operations.receipts();
48
+ case 'questions':return operations.questions(flags.after);
49
+ case 'answer':return operations.answerQuestion(flags.id,flags.question,JSON.parse(readInstructionFile(flags['answer-file'])));
50
+ case 'cancel-question':return operations.answerQuestion(flags.id,flags.question,null);
51
+ case 'send':
52
+ return operations.send(flags.id,readInstructionFile(flags['text-file']),Number(flags['wait-ms']??1000));
53
+ case 'watch': {
54
+ const seconds=Number(flags.seconds);if(!Number.isInteger(seconds)||seconds<1||seconds>60)throw Error('watch seconds must be 1–60');
55
+ const end=Date.now()+seconds*1000;let count=0;
56
+ do {
57
+ // A source poll, not a model invocation. SIGINT ends only this local observer.
58
+ const start=Date.now();emit({type:'progress',...(await operations.resync(false,0))});count++;
59
+ const delay=Math.min(2000-(Date.now()-start),end-Date.now());if(delay>0)await new Promise(r=>setTimeout(r,delay));
60
+ }while(Date.now()<end);
61
+ return {type:'watch-ended',reason:'window elapsed; Pi continues independently',snapshots:count};
62
+ }
63
+ }
64
+ }
65
+ if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url)){
66
+ const emit=(value:unknown)=>process.stdout.write(JSON.stringify(value)+'\n');
67
+ try {emit(await runClient(process.argv.slice(2),process.env,emit));}
68
+ catch(error){emit({error:error instanceof Error?error.message:'client failure'});process.exitCode=1;}
69
+ }
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env python3
2
+ """Bounded read-only adapter; reuses Hermes readers without importing its server."""
3
+ import hashlib
4
+ import json
5
+ import os
6
+ import sys
7
+ import time
8
+ from datetime import datetime, timezone
9
+ from itertools import islice
10
+ from pathlib import Path
11
+
12
+ # The fleet runtime root (.pi/agent-fleet), not the project root: the Hermes
13
+ # readers this reuses are siblings of .pi/agent-fleet/scripts/, and both move together.
14
+ FLEET_ROOT = Path(__file__).resolve().parent.parent
15
+ sys.path.insert(0, str(FLEET_ROOT / 'hermes/plugins/agent-fleet-herdr/dashboard'))
16
+ sys.path.insert(0, str(FLEET_ROOT / 'hermes/skills/hub-watchdog/scripts'))
17
+ import activity
18
+ import herdr_source
19
+ from watchdog_transport import discover, MonitorTransport
20
+
21
+
22
+ def read_pane(project, peer):
23
+ try:
24
+ matches = [a for a in herdr_source.list_agents() if herdr_source.peer_key(a) == (project, peer) and a.get('agent') == 'pi']
25
+ if len(matches) != 1:
26
+ return {'paneId':None, 'state':'unknown', 'reason':'ambiguous' if matches else 'unavailable'}
27
+ a = matches[0]
28
+ return {'paneId':a.get('pane_id'), 'state':herdr_source.normalize_state(a.get('agent_status')), 'reason':''}
29
+ except herdr_source.HerdrUnavailable:
30
+ return {'paneId':None, 'state':'unknown', 'reason':'herdr unavailable'}
31
+
32
+
33
+ def read_activity(entry, cursor, root=None):
34
+ transcript, reason = activity.transcript_for_entry(entry, root=root)
35
+ if transcript is None:
36
+ return {**activity.unavailable(reason), 'cursor':cursor, 'gap':True}
37
+ info = transcript.stat()
38
+ identity = hashlib.sha256(f'{transcript}:{info.st_dev}:{info.st_ino}'.encode()).hexdigest()
39
+ after = cursor.get('seq', 0)
40
+ reset = bool(cursor) and (cursor.get('identity') != identity or after > info.st_size)
41
+ if reset: after = 0
42
+ steps = activity.steps_for_path(transcript)
43
+ fresh = [s for s in steps if s['seq'] > after]
44
+ result = activity.activity_for_entry(entry, after=after, limit=50, root=root)
45
+ # The canonical reader trims to newest whole lines. Surface that loss explicitly.
46
+ gap = reset or (info.st_size > activity.TAIL_BYTES and after < max(0, info.st_size-activity.TAIL_BYTES)) or len(fresh) > len(result['steps'])
47
+ return {**result, 'gap':gap, 'cursor':{'identity':identity, 'seq':result['seq']}, 'source':'pi_transcript'}
48
+
49
+
50
+ TASK_FIELDS = ('id','generation','kind','state','specialist','parentId','parentGeneration','updatedAt','outputSequence')
51
+
52
+ def read_tasks(transport, tasks, owner, hub, cursors):
53
+ selected = [t for t in tasks if t.get('ownerSessionId') == owner]
54
+ # Fair bounded window: oldest unread outputs first, then current task metadata.
55
+ selected.sort(key=lambda t: (cursors.get(f"{owner}:{hub}:{t['id']}:{t['generation']}", 0) >= t.get('outputSequence', 0), t.get('updatedAt','')))
56
+ results, next_cursors, gap = [], dict(cursors), len(selected) > 100
57
+ reads, pending = 0, 0
58
+ for task in selected[:100]:
59
+ item = {k:task[k] for k in TASK_FIELDS if k in task}
60
+ item.update(ownerSessionId=owner, hubInstanceId=hub)
61
+ key = f"{owner}:{hub}:{task['id']}:{task['generation']}"
62
+ after = cursors.get(key, 0)
63
+ if reads < 8 and (key not in cursors or task.get('outputSequence', 0) > after):
64
+ reads += 1
65
+ try:
66
+ output = transport._call({'type':'output','taskId':task['id'],'generation':task['generation'],'afterSequence':after})['output']
67
+ text = output.get('text', '')
68
+ item['output'] = text[-32768:]
69
+ item['outputGap'] = bool(output.get('truncated') or len(text) > 32768 or output.get('firstSequence', 0) > after + 1)
70
+ gap = gap or item['outputGap']
71
+ next_cursors[key] = output.get('sequence', after)
72
+ except Exception:
73
+ item['outputUnavailable'] = True; gap = True
74
+ if reads >= 8 and (key not in next_cursors or task.get('outputSequence',0) > next_cursors.get(key,0)):
75
+ item['outputDeferred'] = True; pending += 1
76
+ results.append(item)
77
+ active_keys = {f"{owner}:{hub}:{t['id']}:{t['generation']}" for t in selected}
78
+ return {'tasks':results, 'pendingOutputs':pending, 'cursor':{k:v for k,v in next_cursors.items() if k in active_keys}, 'gap':gap}
79
+
80
+
81
+ def read_monitor(entry, cursor, wait_ms=0):
82
+ runtime = Path(os.environ.get('AGENT_FLEET_MONITOR_RUNTIME_DIR', f'/tmp/agent-fleet-monitor-{os.getuid()}'))
83
+ profile = os.environ.get('AGENT_FLEET_PROFILE_ID')
84
+ pattern = (hashlib.sha256(profile.encode()).hexdigest() if profile else '*') + '/*/discovery-*.json'
85
+ candidates = []
86
+ try:
87
+ if runtime.is_symlink() or runtime.stat().st_uid != os.getuid(): raise ValueError()
88
+ paths = list(islice(runtime.glob(pattern), 33))
89
+ if len(paths) > 32: raise ValueError()
90
+ for p in paths:
91
+ try:
92
+ d = discover(str(runtime), p.parent.parent.name, p.parent.name, datetime.now(timezone.utc))
93
+ if d['lease'].get('pid') == entry['pid']: candidates.append(d)
94
+ except Exception:
95
+ continue
96
+ except Exception:
97
+ return {'available':False, 'reason':'monitor discovery unavailable', 'tasks':[], 'cursor':cursor, 'gap':True}
98
+ if len(candidates) != 1:
99
+ return {'available':False, 'reason':'monitor missing or ambiguous for selected Pi process', 'tasks':[], 'cursor':cursor, 'gap':True}
100
+ d = candidates[0]; transport = MonitorTransport(d, timeout=2)
101
+ owner = d['owner']; hub = d['lease']['hub']
102
+ reset = bool(cursor) and cursor.get('owner') != owner
103
+ previous = {} if reset else cursor
104
+ gap = reset
105
+ try:
106
+ if wait_ms: time.sleep(min(wait_ms, 2000)/1000)
107
+ snap = transport.snapshot()['snapshot']
108
+ tasks = read_tasks(transport, snap.get('tasks',[]), owner, hub, previous.get('outputs',{}))
109
+ return {'available':True, 'source':'hub_monitor', 'tasks':tasks['tasks'], 'pendingOutputs':tasks['pendingOutputs'], 'gap':gap or tasks['gap'],
110
+ 'cursor':{'owner':owner,'outputs':tasks['cursor']}}
111
+ except Exception:
112
+ return {'available':False, 'reason':'monitor unavailable', 'tasks':[], 'cursor':cursor, 'gap':True}
113
+
114
+
115
+ def project_replies(rows, pending):
116
+ """Match Pi's own respond() audit to the assistant text it used, never a guessed next turn."""
117
+ replies, latest = [], None
118
+ wanted = set(pending)
119
+ for _, line in rows:
120
+ try: record = json.loads(line)
121
+ except ValueError: continue
122
+ if record.get('type') == 'message' and record.get('message',{}).get('role') == 'assistant':
123
+ content = record['message'].get('content')
124
+ if isinstance(content,str): latest = content
125
+ elif isinstance(content,list): latest = '\n'.join(c['text'] for c in content if c.get('type') == 'text' and isinstance(c.get('text'),str))
126
+ data = record.get('data',{})
127
+ if record.get('customType') == 'coms-log' and data.get('event') in ('outbound_response','outbound_response_failed') and data.get('msg_id') in wanted and latest is not None:
128
+ replies.append({'wireId':data['msg_id'], 'state':'failed' if data.get('error') else 'result', 'result':latest[:16000], 'truncated':len(latest)>16000})
129
+ return replies
130
+
131
+
132
+ def read(request):
133
+ entry = request['entry']; cursor = request.get('cursor') or {}
134
+ pane = read_pane(request['project'], entry['name'])
135
+ transcript = read_activity(entry, cursor.get('activity',{}))
136
+ monitor = read_monitor(entry, cursor.get('monitor',{}), request.get('waitMs',0))
137
+ path, _ = activity.transcript_for_entry(entry)
138
+ replies = project_replies(activity.read_tail(path), request.get('pending', [])) if path else []
139
+ return {'replies':replies, 'observedAt':datetime.now(timezone.utc).isoformat(), 'pane':pane, 'activity':transcript, 'monitor':monitor,
140
+ 'partial':not transcript['available'] or not monitor['available'] or transcript['gap'] or monitor['gap'] or bool(monitor.get('pendingOutputs')),
141
+ 'cursor':{'activity':transcript['cursor'],'monitor':monitor['cursor']}}
142
+
143
+ if __name__ == '__main__':
144
+ try:
145
+ request = json.loads(sys.stdin.buffer.read(65537))
146
+ print(json.dumps(read(request), ensure_ascii=False))
147
+ except Exception:
148
+ print(json.dumps({'error':'read sources unavailable'})); sys.exit(1)