@chankov/agent-fleet 1.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (476) hide show
  1. package/.pi/harnesses/agent-hub/README.md +57 -66
  2. package/.pi/harnesses/agent-hub/capability-packs.ts +4 -4
  3. package/.pi/harnesses/agent-hub/commands/agent-model-thinking.ts +10 -0
  4. package/.pi/harnesses/agent-hub/commands/agent-model.ts +10 -0
  5. package/.pi/harnesses/agent-hub/commands/agent-models-substitute.ts +10 -0
  6. package/.pi/harnesses/agent-hub/commands/agents-add.ts +9 -0
  7. package/.pi/harnesses/agent-hub/commands/agents-drop.ts +9 -0
  8. package/.pi/harnesses/agent-hub/commands/agents-history.ts +9 -0
  9. package/.pi/harnesses/agent-hub/commands/agents-kill.ts +10 -0
  10. package/.pi/harnesses/agent-hub/commands/agents-list.ts +9 -0
  11. package/.pi/harnesses/agent-hub/commands/agents-restart.ts +10 -0
  12. package/.pi/harnesses/agent-hub/commands/agents-save.ts +9 -0
  13. package/.pi/harnesses/agent-hub/commands/agents-team.ts +9 -0
  14. package/.pi/harnesses/agent-hub/commands/compound.ts +9 -0
  15. package/.pi/harnesses/agent-hub/commands/coms.ts +9 -0
  16. package/.pi/harnesses/agent-hub/commands/context-command.ts +9 -0
  17. package/.pi/harnesses/agent-hub/commands/context.ts +39 -0
  18. package/.pi/harnesses/agent-hub/commands/dispatch-policy.ts +9 -0
  19. package/.pi/harnesses/agent-hub/commands/handoff.ts +10 -0
  20. package/.pi/harnesses/agent-hub/commands/hub-report.ts +9 -0
  21. package/.pi/harnesses/agent-hub/commands/models.ts +10 -0
  22. package/.pi/harnesses/agent-hub/commands/watchdog.ts +9 -0
  23. package/.pi/harnesses/agent-hub/commands/work-mode.ts +29 -0
  24. package/.pi/harnesses/agent-hub/commands/zoom.ts +10 -0
  25. package/.pi/harnesses/agent-hub/config/agents.ts +171 -0
  26. package/.pi/harnesses/agent-hub/config/overrides.ts +118 -0
  27. package/.pi/harnesses/agent-hub/context/agent-state.ts +30 -0
  28. package/.pi/harnesses/agent-hub/context/assertions-artifacts.ts +211 -0
  29. package/.pi/harnesses/agent-hub/context/budgets.ts +208 -0
  30. package/.pi/harnesses/agent-hub/context/hub-state.ts +40 -0
  31. package/.pi/harnesses/agent-hub/dispatch-coms.ts +232 -0
  32. package/.pi/harnesses/agent-hub/dispatch-core.ts +27 -0
  33. package/.pi/harnesses/agent-hub/dispatch-native-complete.ts +135 -0
  34. package/.pi/harnesses/agent-hub/dispatch-native-prepare.ts +153 -0
  35. package/.pi/harnesses/agent-hub/dispatch-native-spawn.ts +191 -0
  36. package/.pi/harnesses/agent-hub/dispatch-native-types.ts +207 -0
  37. package/.pi/harnesses/agent-hub/dispatch-native.ts +184 -0
  38. package/.pi/harnesses/agent-hub/dispatch-observability.ts +220 -0
  39. package/.pi/harnesses/agent-hub/drift-watchdog.js +3 -3
  40. package/.pi/harnesses/agent-hub/footer.ts +3 -9
  41. package/.pi/harnesses/agent-hub/helpers.ts +2 -2
  42. package/.pi/harnesses/agent-hub/index.ts +1324 -9645
  43. package/.pi/harnesses/agent-hub/input/completions.ts +76 -0
  44. package/.pi/harnesses/agent-hub/input/shortcuts.ts +47 -0
  45. package/.pi/harnesses/agent-hub/lifecycle/context-pressure.ts +123 -0
  46. package/.pi/harnesses/agent-hub/lifecycle/monitor-session.ts +104 -0
  47. package/.pi/harnesses/agent-hub/lifecycle/session-orchestration.ts +139 -0
  48. package/.pi/harnesses/agent-hub/lifecycle/turn-handlers.ts +95 -0
  49. package/.pi/harnesses/agent-hub/package.json +1 -1
  50. package/.pi/harnesses/agent-hub/policy/models.ts +126 -0
  51. package/.pi/harnesses/agent-hub/policy/roster.ts +79 -0
  52. package/.pi/harnesses/agent-hub/policy/work-mode.ts +118 -0
  53. package/.pi/harnesses/agent-hub/presentation.ts +48 -0
  54. package/.pi/harnesses/agent-hub/prompts/context.ts +46 -0
  55. package/.pi/harnesses/agent-hub/prompts/fragments.ts +115 -0
  56. package/.pi/harnesses/agent-hub/prompts/session-start.ts +88 -0
  57. package/.pi/harnesses/agent-hub/prompts/system-prompt.ts +110 -0
  58. package/.pi/harnesses/agent-hub/research/controls.ts +75 -0
  59. package/.pi/harnesses/agent-hub/research/runtime.ts +184 -0
  60. package/.pi/harnesses/agent-hub/research/spawn-run.ts +146 -0
  61. package/.pi/harnesses/agent-hub/session-start.ts +42 -0
  62. package/.pi/harnesses/agent-hub/timeline.ts +54 -0
  63. package/.pi/harnesses/agent-hub/tools/action-executors.ts +146 -0
  64. package/.pi/harnesses/agent-hub/tools/coms-tools.ts +139 -0
  65. package/.pi/harnesses/agent-hub/tools/context.ts +132 -0
  66. package/.pi/harnesses/agent-hub/tools/dispatch-agent.ts +79 -0
  67. package/.pi/harnesses/agent-hub/tools/dispatch-execution.ts +200 -0
  68. package/.pi/harnesses/agent-hub/tools/execution-orchestration.ts +22 -0
  69. package/.pi/harnesses/agent-hub/tools/fleet-tools.ts +202 -0
  70. package/.pi/harnesses/agent-hub/tools/herdr-executors.ts +82 -0
  71. package/.pi/harnesses/agent-hub/tools/set-task-tier.ts +29 -0
  72. package/.pi/harnesses/agent-hub/tools/spawn-research.ts +62 -0
  73. package/.pi/harnesses/agent-hub/tools/team-adjust.ts +29 -0
  74. package/.pi/harnesses/agent-hub/tools/verification-contract.ts +77 -0
  75. package/.pi/harnesses/agent-hub/types.ts +60 -0
  76. package/.pi/harnesses/agent-hub/ui/context-budget.ts +86 -0
  77. package/.pi/harnesses/agent-hub/ui/detail-panel.ts +175 -0
  78. package/.pi/harnesses/agent-hub/ui/fleet-dashboard.ts +130 -0
  79. package/.pi/harnesses/agent-hub/ui/grid.ts +306 -0
  80. package/.pi/harnesses/agent-hub/ui/history-store.ts +137 -0
  81. package/.pi/harnesses/agent-hub/ui/history.ts +234 -0
  82. package/.pi/harnesses/agent-hub/ui/pool.ts +103 -0
  83. package/.pi/harnesses/agent-hub/ui/zoom.ts +204 -0
  84. package/.pi/harnesses/agent-hub/work-mode-controls.ts +56 -0
  85. package/.pi/harnesses/agent-hub/{posture.ts → work-mode.ts} +36 -27
  86. package/.pi/harnesses/coms/index.ts +139 -1630
  87. package/.pi/harnesses/coms/package.json +1 -1
  88. package/.pi/harnesses/damage-control-continue/package.json +1 -1
  89. package/.pi/harnesses/lib/coms-core-io.ts +385 -0
  90. package/.pi/harnesses/lib/coms-core.ts +577 -0
  91. package/.pi/harnesses/lib/context-budget-hub-prompt.ts +3 -5
  92. package/.versions/2.0.0/.pi/agents/dispatch-policy.yaml +32 -0
  93. package/.versions/2.0.0/.pi/agents/model-profiles.yaml +27 -0
  94. package/.versions/2.0.0/.pi/agents/peers.yaml +142 -0
  95. package/.versions/2.0.0/.pi/agents/teams.yaml +41 -0
  96. package/.versions/2.0.0/.pi/damage-control-rules.yaml +297 -0
  97. package/.versions/2.0.0/.pi/extensions/agent-fleet-update-check/README.md +57 -0
  98. package/.versions/2.0.0/.pi/extensions/agent-fleet-update-check/index.ts +161 -0
  99. package/.versions/2.0.0/.pi/extensions/agent-fleet-update-check/package.json +6 -0
  100. package/.versions/2.0.0/.pi/extensions/btw/README.md +120 -0
  101. package/.versions/2.0.0/.pi/extensions/btw/index.ts +914 -0
  102. package/.versions/2.0.0/.pi/extensions/btw/package.json +6 -0
  103. package/.versions/2.0.0/.pi/extensions/btw/state.js +179 -0
  104. package/.versions/2.0.0/.pi/extensions/chrome-devtools-mcp/README.md +55 -0
  105. package/.versions/2.0.0/.pi/extensions/chrome-devtools-mcp/index.ts +93 -0
  106. package/.versions/2.0.0/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
  107. package/.versions/2.0.0/.pi/extensions/compact-and-continue/README.md +42 -0
  108. package/.versions/2.0.0/.pi/extensions/compact-and-continue/index.ts +120 -0
  109. package/.versions/2.0.0/.pi/extensions/compact-and-continue/package.json +6 -0
  110. package/.versions/2.0.0/.pi/extensions/mcp-bridge/README.md +46 -0
  111. package/.versions/2.0.0/.pi/extensions/mcp-bridge/index.ts +206 -0
  112. package/.versions/2.0.0/.pi/extensions/mcp-bridge/package.json +6 -0
  113. package/.versions/2.0.0/.pi/extensions/package-lock.json +1175 -0
  114. package/.versions/2.0.0/.pi/extensions/package.json +9 -0
  115. package/.versions/2.0.0/.pi/extensions/pi-voice-stt/README.md +205 -0
  116. package/.versions/2.0.0/.pi/extensions/pi-voice-stt/config.ts +198 -0
  117. package/.versions/2.0.0/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
  118. package/.versions/2.0.0/.pi/extensions/pi-voice-stt/index.ts +248 -0
  119. package/.versions/2.0.0/.pi/extensions/pi-voice-stt/package.json +6 -0
  120. package/.versions/2.0.0/.pi/extensions/pi-voice-stt/providers.ts +214 -0
  121. package/.versions/2.0.0/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
  122. package/.versions/2.0.0/.pi/harnesses/agent-hub/README.md +1161 -0
  123. package/.versions/2.0.0/.pi/harnesses/agent-hub/access-approval.ts +135 -0
  124. package/.versions/2.0.0/.pi/harnesses/agent-hub/artifacts.js +146 -0
  125. package/.versions/2.0.0/.pi/harnesses/agent-hub/assertion-ledger.js +58 -0
  126. package/.versions/2.0.0/.pi/harnesses/agent-hub/backend-policy.js +174 -0
  127. package/.versions/2.0.0/.pi/harnesses/agent-hub/budget-continuation.ts +73 -0
  128. package/.versions/2.0.0/.pi/harnesses/agent-hub/capability-confirmation.ts +47 -0
  129. package/.versions/2.0.0/.pi/harnesses/agent-hub/capability-packs.ts +180 -0
  130. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agent-model-thinking.ts +10 -0
  131. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agent-model.ts +10 -0
  132. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agent-models-substitute.ts +10 -0
  133. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agents-add.ts +9 -0
  134. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agents-drop.ts +9 -0
  135. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agents-history.ts +9 -0
  136. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agents-kill.ts +10 -0
  137. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agents-list.ts +9 -0
  138. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agents-restart.ts +10 -0
  139. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agents-save.ts +9 -0
  140. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/agents-team.ts +9 -0
  141. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/compound.ts +9 -0
  142. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/coms.ts +9 -0
  143. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/context-command.ts +9 -0
  144. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/context.ts +39 -0
  145. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/dispatch-policy.ts +9 -0
  146. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/handoff.ts +10 -0
  147. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/hub-report.ts +9 -0
  148. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/models.ts +10 -0
  149. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/watchdog.ts +9 -0
  150. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/work-mode.ts +29 -0
  151. package/.versions/2.0.0/.pi/harnesses/agent-hub/commands/zoom.ts +10 -0
  152. package/.versions/2.0.0/.pi/harnesses/agent-hub/config/agents.ts +171 -0
  153. package/.versions/2.0.0/.pi/harnesses/agent-hub/config/overrides.ts +118 -0
  154. package/.versions/2.0.0/.pi/harnesses/agent-hub/context/agent-state.ts +30 -0
  155. package/.versions/2.0.0/.pi/harnesses/agent-hub/context/assertions-artifacts.ts +211 -0
  156. package/.versions/2.0.0/.pi/harnesses/agent-hub/context/budgets.ts +208 -0
  157. package/.versions/2.0.0/.pi/harnesses/agent-hub/context/hub-state.ts +40 -0
  158. package/.versions/2.0.0/.pi/harnesses/agent-hub/context-budget-snapshot.ts +105 -0
  159. package/.versions/2.0.0/.pi/harnesses/agent-hub/context-pressure.ts +191 -0
  160. package/.versions/2.0.0/.pi/harnesses/agent-hub/context-window.js +106 -0
  161. package/.versions/2.0.0/.pi/harnesses/agent-hub/delegate.ts +446 -0
  162. package/.versions/2.0.0/.pi/harnesses/agent-hub/dispatch-coms.ts +232 -0
  163. package/.versions/2.0.0/.pi/harnesses/agent-hub/dispatch-core.ts +27 -0
  164. package/.versions/2.0.0/.pi/harnesses/agent-hub/dispatch-native-complete.ts +135 -0
  165. package/.versions/2.0.0/.pi/harnesses/agent-hub/dispatch-native-prepare.ts +153 -0
  166. package/.versions/2.0.0/.pi/harnesses/agent-hub/dispatch-native-spawn.ts +191 -0
  167. package/.versions/2.0.0/.pi/harnesses/agent-hub/dispatch-native-types.ts +207 -0
  168. package/.versions/2.0.0/.pi/harnesses/agent-hub/dispatch-native.ts +184 -0
  169. package/.versions/2.0.0/.pi/harnesses/agent-hub/dispatch-observability.ts +220 -0
  170. package/.versions/2.0.0/.pi/harnesses/agent-hub/docs-lane.js +122 -0
  171. package/.versions/2.0.0/.pi/harnesses/agent-hub/drift-watchdog.js +218 -0
  172. package/.versions/2.0.0/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
  173. package/.versions/2.0.0/.pi/harnesses/agent-hub/external-blocker.js +85 -0
  174. package/.versions/2.0.0/.pi/harnesses/agent-hub/fixtures/registration-surface.json +53 -0
  175. package/.versions/2.0.0/.pi/harnesses/agent-hub/footer.ts +30 -0
  176. package/.versions/2.0.0/.pi/harnesses/agent-hub/helpers.ts +266 -0
  177. package/.versions/2.0.0/.pi/harnesses/agent-hub/hub-state-audit.js +59 -0
  178. package/.versions/2.0.0/.pi/harnesses/agent-hub/index.ts +1850 -0
  179. package/.versions/2.0.0/.pi/harnesses/agent-hub/input/completions.ts +76 -0
  180. package/.versions/2.0.0/.pi/harnesses/agent-hub/input/shortcuts.ts +47 -0
  181. package/.versions/2.0.0/.pi/harnesses/agent-hub/lifecycle/context-pressure.ts +123 -0
  182. package/.versions/2.0.0/.pi/harnesses/agent-hub/lifecycle/monitor-session.ts +104 -0
  183. package/.versions/2.0.0/.pi/harnesses/agent-hub/lifecycle/session-orchestration.ts +139 -0
  184. package/.versions/2.0.0/.pi/harnesses/agent-hub/lifecycle/turn-handlers.ts +95 -0
  185. package/.versions/2.0.0/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
  186. package/.versions/2.0.0/.pi/harnesses/agent-hub/monitor-invoke-journal.ts +131 -0
  187. package/.versions/2.0.0/.pi/harnesses/agent-hub/monitor-invoke.ts +92 -0
  188. package/.versions/2.0.0/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
  189. package/.versions/2.0.0/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
  190. package/.versions/2.0.0/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
  191. package/.versions/2.0.0/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
  192. package/.versions/2.0.0/.pi/harnesses/agent-hub/monitor-session-bridge.ts +266 -0
  193. package/.versions/2.0.0/.pi/harnesses/agent-hub/package.json +7 -0
  194. package/.versions/2.0.0/.pi/harnesses/agent-hub/peer-spawn-plan.ts +116 -0
  195. package/.versions/2.0.0/.pi/harnesses/agent-hub/policy/models.ts +126 -0
  196. package/.versions/2.0.0/.pi/harnesses/agent-hub/policy/roster.ts +79 -0
  197. package/.versions/2.0.0/.pi/harnesses/agent-hub/policy/work-mode.ts +118 -0
  198. package/.versions/2.0.0/.pi/harnesses/agent-hub/presentation.ts +48 -0
  199. package/.versions/2.0.0/.pi/harnesses/agent-hub/prompts/context.ts +46 -0
  200. package/.versions/2.0.0/.pi/harnesses/agent-hub/prompts/fragments.ts +115 -0
  201. package/.versions/2.0.0/.pi/harnesses/agent-hub/prompts/session-start.ts +88 -0
  202. package/.versions/2.0.0/.pi/harnesses/agent-hub/prompts/system-prompt.ts +110 -0
  203. package/.versions/2.0.0/.pi/harnesses/agent-hub/provider-semaphore.js +138 -0
  204. package/.versions/2.0.0/.pi/harnesses/agent-hub/research/controls.ts +75 -0
  205. package/.versions/2.0.0/.pi/harnesses/agent-hub/research/runtime.ts +184 -0
  206. package/.versions/2.0.0/.pi/harnesses/agent-hub/research/spawn-run.ts +146 -0
  207. package/.versions/2.0.0/.pi/harnesses/agent-hub/research-retention.js +34 -0
  208. package/.versions/2.0.0/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
  209. package/.versions/2.0.0/.pi/harnesses/agent-hub/return-contract.js +293 -0
  210. package/.versions/2.0.0/.pi/harnesses/agent-hub/return-extract.js +75 -0
  211. package/.versions/2.0.0/.pi/harnesses/agent-hub/review-findings.js +102 -0
  212. package/.versions/2.0.0/.pi/harnesses/agent-hub/run-budget.js +537 -0
  213. package/.versions/2.0.0/.pi/harnesses/agent-hub/run-namespace.js +87 -0
  214. package/.versions/2.0.0/.pi/harnesses/agent-hub/safety-routing.ts +22 -0
  215. package/.versions/2.0.0/.pi/harnesses/agent-hub/scope-gate.js +103 -0
  216. package/.versions/2.0.0/.pi/harnesses/agent-hub/session-health.js +110 -0
  217. package/.versions/2.0.0/.pi/harnesses/agent-hub/session-start.ts +42 -0
  218. package/.versions/2.0.0/.pi/harnesses/agent-hub/spawn.ts +388 -0
  219. package/.versions/2.0.0/.pi/harnesses/agent-hub/timeline.ts +54 -0
  220. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/action-executors.ts +146 -0
  221. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/coms-tools.ts +139 -0
  222. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/context.ts +132 -0
  223. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/dispatch-agent.ts +79 -0
  224. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/dispatch-execution.ts +200 -0
  225. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/execution-orchestration.ts +22 -0
  226. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/fleet-tools.ts +202 -0
  227. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/herdr-executors.ts +82 -0
  228. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/set-task-tier.ts +29 -0
  229. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/spawn-research.ts +62 -0
  230. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/team-adjust.ts +29 -0
  231. package/.versions/2.0.0/.pi/harnesses/agent-hub/tools/verification-contract.ts +77 -0
  232. package/.versions/2.0.0/.pi/harnesses/agent-hub/types.ts +60 -0
  233. package/.versions/2.0.0/.pi/harnesses/agent-hub/ui/context-budget.ts +86 -0
  234. package/.versions/2.0.0/.pi/harnesses/agent-hub/ui/detail-panel.ts +175 -0
  235. package/.versions/2.0.0/.pi/harnesses/agent-hub/ui/fleet-dashboard.ts +130 -0
  236. package/.versions/2.0.0/.pi/harnesses/agent-hub/ui/grid.ts +306 -0
  237. package/.versions/2.0.0/.pi/harnesses/agent-hub/ui/history-store.ts +137 -0
  238. package/.versions/2.0.0/.pi/harnesses/agent-hub/ui/history.ts +234 -0
  239. package/.versions/2.0.0/.pi/harnesses/agent-hub/ui/pool.ts +103 -0
  240. package/.versions/2.0.0/.pi/harnesses/agent-hub/ui/zoom.ts +204 -0
  241. package/.versions/2.0.0/.pi/harnesses/agent-hub/version.ts +42 -0
  242. package/.versions/2.0.0/.pi/harnesses/agent-hub/work-mode-controls.ts +56 -0
  243. package/.versions/2.0.0/.pi/harnesses/agent-hub/work-mode.ts +167 -0
  244. package/.versions/2.0.0/.pi/harnesses/ask-user-remote/README.md +53 -0
  245. package/.versions/2.0.0/.pi/harnesses/ask-user-remote/index.ts +532 -0
  246. package/.versions/2.0.0/.pi/harnesses/ask-user-remote/race-core.js +106 -0
  247. package/.versions/2.0.0/.pi/harnesses/coms/README.md +100 -0
  248. package/.versions/2.0.0/.pi/harnesses/coms/index.ts +276 -0
  249. package/.versions/2.0.0/.pi/harnesses/coms/package.json +7 -0
  250. package/.versions/2.0.0/.pi/harnesses/coms/version.ts +42 -0
  251. package/.versions/2.0.0/.pi/harnesses/damage-control-continue/README.md +124 -0
  252. package/.versions/2.0.0/.pi/harnesses/damage-control-continue/index.ts +536 -0
  253. package/.versions/2.0.0/.pi/harnesses/damage-control-continue/package.json +7 -0
  254. package/.versions/2.0.0/.pi/harnesses/damage-control-continue/version.ts +42 -0
  255. package/.versions/2.0.0/.pi/harnesses/lib/coms-core-io.ts +385 -0
  256. package/.versions/2.0.0/.pi/harnesses/lib/coms-core.ts +577 -0
  257. package/.versions/2.0.0/.pi/harnesses/lib/coms-registry-entry.ts +94 -0
  258. package/.versions/2.0.0/.pi/harnesses/lib/context-budget-child-prompt.ts +179 -0
  259. package/.versions/2.0.0/.pi/harnesses/lib/context-budget-hub-prompt.ts +114 -0
  260. package/.versions/2.0.0/.pi/harnesses/lib/context-budget-view.ts +107 -0
  261. package/.versions/2.0.0/.pi/harnesses/lib/context-budget.ts +114 -0
  262. package/.versions/2.0.0/.pi/harnesses/lib/damage-control-shared.ts +197 -0
  263. package/.versions/2.0.0/.pi/harnesses/lib/fixtures/context-budget-profiles.json +11 -0
  264. package/.versions/2.0.0/.pi/harnesses/lib/fixtures/hub-prompt-operator.legacy.txt +73 -0
  265. package/.versions/2.0.0/.pi/harnesses/lib/fixtures/hub-prompt-orchestrator.legacy.txt +73 -0
  266. package/.versions/2.0.0/.pi/harnesses/lib/fleet-dashboard-ops.ts +155 -0
  267. package/.versions/2.0.0/.pi/harnesses/lib/fleet-dashboard-view.ts +142 -0
  268. package/.versions/2.0.0/.pi/harnesses/lib/fleet-detail-view.ts +247 -0
  269. package/.versions/2.0.0/.pi/harnesses/lib/fleet-overlay.ts +26 -0
  270. package/.versions/2.0.0/.pi/harnesses/lib/fleet-panel.ts +34 -0
  271. package/.versions/2.0.0/.pi/harnesses/lib/fleet-read-model.ts +131 -0
  272. package/.versions/2.0.0/.pi/harnesses/lib/fleet-selection.ts +24 -0
  273. package/.versions/2.0.0/.pi/harnesses/lib/fleet-transcript-store.ts +244 -0
  274. package/.versions/2.0.0/.pi/harnesses/lib/herdr-client.ts +472 -0
  275. package/.versions/2.0.0/.pi/harnesses/lib/herdr-presence.ts +399 -0
  276. package/.versions/2.0.0/.pi/harnesses/lib/hermes-monitor-events.ts +136 -0
  277. package/.versions/2.0.0/.pi/harnesses/lib/hermes-monitor-herdr.ts +28 -0
  278. package/.versions/2.0.0/.pi/harnesses/lib/hermes-monitor-model.ts +18 -0
  279. package/.versions/2.0.0/.pi/harnesses/lib/hermes-monitor-registry.ts +6 -0
  280. package/.versions/2.0.0/.pi/harnesses/lib/hermes-monitor-socket.ts +163 -0
  281. package/.versions/2.0.0/.pi/harnesses/lib/hermes-monitor-store.ts +31 -0
  282. package/.versions/2.0.0/.pi/harnesses/lib/spawned-peers.js +190 -0
  283. package/.versions/2.0.0/.pi/harnesses/package-lock.json +2039 -0
  284. package/.versions/2.0.0/.pi/harnesses/package.json +10 -0
  285. package/.versions/2.0.0/.pi/prompts/af-build.md +24 -0
  286. package/.versions/2.0.0/.pi/prompts/af-code-simplify.md +22 -0
  287. package/.versions/2.0.0/.pi/prompts/af-plan.md +17 -0
  288. package/.versions/2.0.0/.pi/prompts/af-review.md +16 -0
  289. package/.versions/2.0.0/.pi/prompts/af-set-hermes-telegram.md +15 -0
  290. package/.versions/2.0.0/.pi/prompts/af-set-hermes-watchdog.md +6 -0
  291. package/.versions/2.0.0/.pi/prompts/af-ship.md +17 -0
  292. package/.versions/2.0.0/.pi/prompts/af-spec.md +15 -0
  293. package/.versions/2.0.0/.pi/prompts/af-test.md +19 -0
  294. package/.versions/2.0.0/.pi/skills/bowser/SKILL.md +145 -0
  295. package/.versions/2.0.0/.version +1 -0
  296. package/.versions/2.0.0/agents/architect.md +25 -0
  297. package/.versions/2.0.0/agents/bowser.md +28 -0
  298. package/.versions/2.0.0/agents/builder.md +56 -0
  299. package/.versions/2.0.0/agents/code-reviewer.md +209 -0
  300. package/.versions/2.0.0/agents/deep-researcher.md +33 -0
  301. package/.versions/2.0.0/agents/documenter.md +19 -0
  302. package/.versions/2.0.0/agents/orchestrator.md +23 -0
  303. package/.versions/2.0.0/agents/plan-reviewer.md +84 -0
  304. package/.versions/2.0.0/agents/planner.md +71 -0
  305. package/.versions/2.0.0/agents/releaser.md +25 -0
  306. package/.versions/2.0.0/agents/researcher.md +29 -0
  307. package/.versions/2.0.0/agents/security-auditor.md +168 -0
  308. package/.versions/2.0.0/agents/test-engineer.md +154 -0
  309. package/.versions/2.0.0/agents/web-debugger.md +44 -0
  310. package/.versions/2.0.0/agents/web-performance-auditor.md +194 -0
  311. package/.versions/2.0.0/bin/catalog/harness-runtime-closure.json +38 -0
  312. package/.versions/2.0.0/codex/CONDUCTOR.md +148 -0
  313. package/.versions/2.0.0/docs/ARCHITECTURE.md +404 -0
  314. package/.versions/2.0.0/docs/agent-fleet-setup.md +468 -0
  315. package/.versions/2.0.0/docs/claude-code-coms-bridge.md +128 -0
  316. package/.versions/2.0.0/docs/codex-remote-conductor.md +170 -0
  317. package/.versions/2.0.0/docs/coms-hermes-bridge.md +189 -0
  318. package/.versions/2.0.0/docs/getting-started.md +98 -0
  319. package/.versions/2.0.0/docs/npm-install.md +292 -0
  320. package/.versions/2.0.0/docs/pi-extensions.md +439 -0
  321. package/.versions/2.0.0/docs/pi-setup.md +74 -0
  322. package/.versions/2.0.0/docs/skill-anatomy.md +150 -0
  323. package/.versions/2.0.0/hermes/README.md +347 -0
  324. package/.versions/2.0.0/hermes/desktop-plugins/agent-fleet-herdr/plugin.js +1291 -0
  325. package/.versions/2.0.0/hermes/desktop-plugins/agent-fleet-herdr/presentation.js +672 -0
  326. package/.versions/2.0.0/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
  327. package/.versions/2.0.0/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
  328. package/.versions/2.0.0/hermes/gates/gate-o-capability.md +8 -0
  329. package/.versions/2.0.0/hermes/gates/gate-o-validator-fixtures.json +1 -0
  330. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +770 -0
  331. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/dashboard/coms_registry.py +134 -0
  332. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/dashboard/coms_send.py +350 -0
  333. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/dashboard/herdr_source.py +193 -0
  334. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/dashboard/manifest.json +4 -0
  335. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/dashboard/plugin_api.py +444 -0
  336. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/dashboard/sessions.py +205 -0
  337. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/dashboard/tasks.py +300 -0
  338. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/dashboard/watch.py +819 -0
  339. package/.versions/2.0.0/hermes/plugins/agent-fleet-herdr/plugin.yaml +8 -0
  340. package/.versions/2.0.0/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +139 -0
  341. package/.versions/2.0.0/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
  342. package/.versions/2.0.0/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
  343. package/.versions/2.0.0/hermes/skills/hub-conductor/SKILL.md +84 -0
  344. package/.versions/2.0.0/hermes/skills/hub-liaison/SKILL.md +84 -0
  345. package/.versions/2.0.0/hermes/skills/hub-watchdog/SKILL.md +76 -0
  346. package/.versions/2.0.0/hermes/skills/hub-watchdog/manifest.json +1 -0
  347. package/.versions/2.0.0/hermes/skills/hub-watchdog/scripts/watchdog.py +249 -0
  348. package/.versions/2.0.0/hermes/skills/hub-watchdog/scripts/watchdog_actions.py +124 -0
  349. package/.versions/2.0.0/hermes/skills/hub-watchdog/scripts/watchdog_contract.py +76 -0
  350. package/.versions/2.0.0/hermes/skills/hub-watchdog/scripts/watchdog_delivery.py +10 -0
  351. package/.versions/2.0.0/hermes/skills/hub-watchdog/scripts/watchdog_engine.py +128 -0
  352. package/.versions/2.0.0/hermes/skills/hub-watchdog/scripts/watchdog_judgment.py +41 -0
  353. package/.versions/2.0.0/hermes/skills/hub-watchdog/scripts/watchdog_recovery.py +103 -0
  354. package/.versions/2.0.0/hermes/skills/hub-watchdog/scripts/watchdog_state.py +163 -0
  355. package/.versions/2.0.0/hermes/skills/hub-watchdog/scripts/watchdog_transport.py +138 -0
  356. package/.versions/2.0.0/hermes/watchdog-tests/__init__.py +0 -0
  357. package/.versions/2.0.0/hooks/coms-stop-hook.mjs +84 -0
  358. package/.versions/2.0.0/install-manifest.json +2745 -0
  359. package/.versions/2.0.0/justfile +272 -0
  360. package/.versions/2.0.0/manifest-meta.json +882 -0
  361. package/.versions/2.0.0/references/accessibility-checklist.md +160 -0
  362. package/.versions/2.0.0/references/definition-of-done.md +67 -0
  363. package/.versions/2.0.0/references/fleet-coordination-patterns.md +151 -0
  364. package/.versions/2.0.0/references/observability-checklist.md +91 -0
  365. package/.versions/2.0.0/references/orchestration-patterns.md +370 -0
  366. package/.versions/2.0.0/references/performance-checklist.md +153 -0
  367. package/.versions/2.0.0/references/prompting-patterns.md +380 -0
  368. package/.versions/2.0.0/references/security-checklist.md +179 -0
  369. package/.versions/2.0.0/references/testing-patterns.md +236 -0
  370. package/.versions/2.0.0/scripts/codex-conductor.ts +41 -0
  371. package/.versions/2.0.0/scripts/codex-remote-control.ts +167 -0
  372. package/.versions/2.0.0/scripts/coms-claude-bridge.ts +411 -0
  373. package/.versions/2.0.0/scripts/coms-cli.ts +484 -0
  374. package/.versions/2.0.0/scripts/coms-hermes-bridge.ts +413 -0
  375. package/.versions/2.0.0/scripts/fleet.ts +185 -0
  376. package/.versions/2.0.0/scripts/hermes-monitor-capability-runner.ts +25 -0
  377. package/.versions/2.0.0/scripts/hermes-monitor-scenario.ts +474 -0
  378. package/.versions/2.0.0/scripts/hermes-watchdog-capability-probe.ts +45 -0
  379. package/.versions/2.0.0/scripts/install-hermes-plugin.sh +180 -0
  380. package/.versions/2.0.0/scripts/lib/claude-bridge-core.ts +210 -0
  381. package/.versions/2.0.0/scripts/lib/codex-conductor.ts +88 -0
  382. package/.versions/2.0.0/scripts/lib/codex-remote-control.ts +480 -0
  383. package/.versions/2.0.0/scripts/lib/coms-envelope.ts +582 -0
  384. package/.versions/2.0.0/scripts/lib/fake-herdr-server.ts +88 -0
  385. package/.versions/2.0.0/scripts/lib/fleet-command.ts +270 -0
  386. package/.versions/2.0.0/scripts/lib/herdr-layout.ts +281 -0
  387. package/.versions/2.0.0/scripts/lib/hermes-bridge-core.ts +241 -0
  388. package/.versions/2.0.0/scripts/lib/hermes-monitor-events.ts +1 -0
  389. package/.versions/2.0.0/scripts/lib/hermes-monitor-herdr.ts +2 -0
  390. package/.versions/2.0.0/scripts/lib/hermes-monitor-model.ts +3 -0
  391. package/.versions/2.0.0/scripts/lib/hermes-monitor-registry.ts +2 -0
  392. package/.versions/2.0.0/scripts/lib/hermes-monitor-socket.ts +2 -0
  393. package/.versions/2.0.0/scripts/lib/hermes-monitor-store.ts +2 -0
  394. package/.versions/2.0.0/scripts/lib/monitor-env.ts +146 -0
  395. package/.versions/2.0.0/scripts/lib/peer-launch.ts +318 -0
  396. package/.versions/2.0.0/scripts/lib/persona-banner.ts +62 -0
  397. package/.versions/2.0.0/scripts/lib/spawn-stagger.ts +101 -0
  398. package/.versions/2.0.0/scripts/lib/team-project.ts +213 -0
  399. package/.versions/2.0.0/scripts/lib/team-snapshot.ts +147 -0
  400. package/.versions/2.0.0/scripts/peer-banner.ts +40 -0
  401. package/.versions/2.0.0/scripts/peer-launch.ts +259 -0
  402. package/.versions/2.0.0/scripts/team-snapshot.ts +237 -0
  403. package/.versions/2.0.0/scripts/team-up.ts +406 -0
  404. package/.versions/2.0.0/skills/_internal/grilling.md +59 -0
  405. package/.versions/2.0.0/skills/browser-testing-with-devtools/SKILL.md +351 -0
  406. package/.versions/2.0.0/skills/code-review-and-quality/SKILL.md +381 -0
  407. package/.versions/2.0.0/skills/compound-learning/SKILL.md +137 -0
  408. package/.versions/2.0.0/skills/context-engineering/SKILL.md +291 -0
  409. package/.versions/2.0.0/skills/deprecation-and-migration/SKILL.md +206 -0
  410. package/.versions/2.0.0/skills/designing-agents/SKILL.md +394 -0
  411. package/.versions/2.0.0/skills/designing-agents/pi-harness-authoring.md +222 -0
  412. package/.versions/2.0.0/skills/frontend-ui-engineering/SKILL.md +328 -0
  413. package/.versions/2.0.0/skills/git-workflow-and-versioning/SKILL.md +316 -0
  414. package/.versions/2.0.0/skills/idea-refine/SKILL.md +182 -0
  415. package/.versions/2.0.0/skills/idea-refine/examples.md +238 -0
  416. package/.versions/2.0.0/skills/idea-refine/frameworks.md +99 -0
  417. package/.versions/2.0.0/skills/idea-refine/refinement-criteria.md +113 -0
  418. package/.versions/2.0.0/skills/idea-refine/scripts/idea-refine.sh +15 -0
  419. package/.versions/2.0.0/skills/incremental-implementation/SKILL.md +298 -0
  420. package/.versions/2.0.0/skills/interview-me/SKILL.md +226 -0
  421. package/.versions/2.0.0/skills/orchestration-verification/SKILL.md +181 -0
  422. package/.versions/2.0.0/skills/peer-coms/SKILL.md +90 -0
  423. package/.versions/2.0.0/skills/performance-optimization/SKILL.md +350 -0
  424. package/.versions/2.0.0/skills/planning-and-task-breakdown/SKILL.md +263 -0
  425. package/.versions/2.0.0/skills/security-and-hardening/SKILL.md +461 -0
  426. package/.versions/2.0.0/skills/spec-driven-development/SKILL.md +256 -0
  427. package/.versions/2.0.0/skills/using-agent-skills/SKILL.md +197 -0
  428. package/.versions/2.0.0/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
  429. package/.versions/2.0.0/vendor/agent-skills-upstream/LICENSE +21 -0
  430. package/.versions/2.0.0/vendor/agent-skills-upstream/README.md +11 -0
  431. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +294 -0
  432. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
  433. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
  434. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
  435. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
  436. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +289 -0
  437. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
  438. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
  439. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +278 -0
  440. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
  441. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
  442. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
  443. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
  444. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
  445. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
  446. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
  447. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
  448. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
  449. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
  450. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +203 -0
  451. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +350 -0
  452. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +234 -0
  453. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +467 -0
  454. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +310 -0
  455. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +194 -0
  456. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +206 -0
  457. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +383 -0
  458. package/.versions/2.0.0/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +191 -0
  459. package/CHANGELOG.md +33 -0
  460. package/README.md +5 -5
  461. package/agents/orchestrator.md +3 -1
  462. package/bin/lib/overrides.js +2 -0
  463. package/bin/lib/validate-overrides.js +1 -1
  464. package/docs/ARCHITECTURE.md +42 -13
  465. package/docs/MIGRATION-agent-fleet.md +4 -4
  466. package/docs/agent-fleet-setup.md +15 -15
  467. package/docs/npm-install.md +1 -1
  468. package/docs/pi-extensions.md +16 -18
  469. package/install-manifest.json +1 -1
  470. package/justfile +2 -2
  471. package/package.json +3 -2
  472. package/scripts/fleet.ts +10 -10
  473. package/scripts/lib/fleet-command.ts +15 -11
  474. package/scripts/lib/team-project.ts +2 -2
  475. package/scripts/team-up.ts +10 -10
  476. package/.pi/harnesses/agent-hub/execution-profile.ts +0 -69
@@ -0,0 +1,672 @@
1
+ /**
2
+ * Pure view logic for the Agent Fleet herdr pane — no React, no DOM, no ctx.
3
+ *
4
+ * The Desktop loader evaluates `plugin.js` as a standalone blob: relative
5
+ * imports cannot resolve, so the plugin file must be self-contained. The block
6
+ * between the SHARED markers below is therefore copied verbatim into
7
+ * `plugin.js`, and `presentation.test.js` fails if the two copies drift.
8
+ *
9
+ * Everything here answers one question: what does a human see, and does it read
10
+ * as the state it actually is? The probe taught that the hard way — success and
11
+ * failure rendered as one long line of raw JSON, and the success read as a
12
+ * stack trace. Hence `{ tone, headline, detail }` triples instead of formatted
13
+ * strings, and hence "herdr is not answering" and "herdr answered, nobody is
14
+ * running" being two different sentences.
15
+ */
16
+
17
+ // <<< SHARED WITH plugin.js — keep byte-identical >>>
18
+
19
+ // StatusDot tones. `detached` and `unknown` are both "we can't see it", but
20
+ // they arrive from different places: detached = herdr answered and had no pane,
21
+ // unknown = herdr did not answer at all.
22
+ const STATE_TONE = { working: 'good', idle: 'muted', blocked: 'warn', detached: 'bad', unknown: 'bad' }
23
+
24
+ const STATE_LABEL = {
25
+ working: 'working',
26
+ idle: 'idle',
27
+ blocked: 'needs answer',
28
+ detached: 'detached',
29
+ unknown: 'unknown'
30
+ }
31
+
32
+ // A dispatch is a prompt this pane handed to a peer. `failed` never reached the
33
+ // peer at all; `error` reached it and came back refused; `timeout` reached it
34
+ // and was never answered. Three different things to do about it, so three
35
+ // words.
36
+ const DISPATCH_TONE = { pending: 'muted', answered: 'good', error: 'bad', failed: 'bad', timeout: 'warn' }
37
+
38
+ const DISPATCH_LABEL = {
39
+ pending: 'working on it',
40
+ answered: 'answered',
41
+ error: 'refused',
42
+ failed: 'not delivered',
43
+ timeout: 'no answer'
44
+ }
45
+
46
+ function stateTone(state) {
47
+ return STATE_TONE[state] ?? 'bad'
48
+ }
49
+
50
+ function stateLabel(state) {
51
+ return STATE_LABEL[state] ?? 'unknown'
52
+ }
53
+
54
+ function countSessions(projects) {
55
+ return projects.reduce((total, group) => total + (group.sessions?.length ?? 0), 0)
56
+ }
57
+
58
+ function countWaiting(projects) {
59
+ return projects.reduce((total, group) => total + (group.sessions ?? []).filter(s => s.needs_answer).length, 0)
60
+ }
61
+
62
+ function plural(count, noun) {
63
+ return `${count} ${noun}${count === 1 ? '' : 's'}`
64
+ }
65
+
66
+ /** Seconds to something a glance can read: `45s`, `3m12s`, `2h13m`, `3d4h`.
67
+ *
68
+ * Seconds survive up to the hour mark because that is the range a human is
69
+ * watching a turn in; above it, nobody counts seconds. An unusable input —
70
+ * the backend sends `null` for a timestamp it could not parse — returns the
71
+ * empty string, so a caller that forwards it renders nothing rather than
72
+ * "0s", which would be a claim. */
73
+ function formatAge(seconds) {
74
+ if (typeof seconds !== 'number' || !Number.isFinite(seconds) || seconds < 0) return ''
75
+ const whole = Math.floor(seconds)
76
+ if (whole < 60) return `${whole}s`
77
+ if (whole < 3600) return `${Math.floor(whole / 60)}m${String(whole % 60).padStart(2, '0')}s`
78
+ if (whole < 86400) return `${Math.floor(whole / 3600)}h${Math.floor((whole % 3600) / 60)}m`
79
+
80
+ return `${Math.floor(whole / 86400)}d${Math.floor((whole % 86400) / 3600)}h`
81
+ }
82
+
83
+ /** Why a row cannot be seen, or why it should not be trusted — in a sentence.
84
+ *
85
+ * `detached` used to be the end of the story, which made a herdr that was up
86
+ * but empty look exactly like a peer that had left its pane. `herdrPanes` is
87
+ * the pane count from the payload; `undefined` means the payload predates it,
88
+ * and the answer degrades to the older, vaguer sentence rather than inventing
89
+ * a number. */
90
+ function sessionNote(session, herdrPanes) {
91
+ const state = session.state ?? 'unknown'
92
+
93
+ // Checked before the state, because a stopped heartbeat says something about
94
+ // the PROCESS, while `detached` only says something about our view of it.
95
+ if (session.stale) {
96
+ const age = formatAge(session.heartbeat_age_s)
97
+
98
+ return age ? `no heartbeat for ${age}` : 'no heartbeat'
99
+ }
100
+
101
+ if (state === 'detached') {
102
+ if (herdrPanes === 0) return 'alive — herdr reports no panes at all'
103
+ if (typeof herdrPanes === 'number') return `alive — none of ${plural(herdrPanes, 'herdr pane')} reports it`
104
+
105
+ return 'alive, but no herdr pane reports it'
106
+ }
107
+
108
+ if (state === 'unknown') return 'herdr did not answer — state unknown'
109
+
110
+ return ''
111
+ }
112
+
113
+ /** The pane's own status line: `{ kind, tone, headline, detail, projects }`.
114
+ *
115
+ * `kind` drives which body renders; `tone`/`headline`/`detail` are what the
116
+ * header shows in every case, so the state is legible without reading the
117
+ * payload. */
118
+ function presentSessions(value) {
119
+ const projects = value?.projects ?? []
120
+ const dispatches = value?.dispatches ?? []
121
+ // Every branch below spreads this. The renderer maps over `projects` and
122
+ // `dispatches` unconditionally, so a branch that forgets one is not a missing
123
+ // list — it is a blank pane reading "failed to render". `herdrPanes` rides
124
+ // along because it belongs to the payload, not to any one row, and the rows
125
+ // are what need it.
126
+ const base = { projects, dispatches, herdrPanes: value?.herdr_panes }
127
+
128
+ if (value?.error) {
129
+ const message = String(value.error)
130
+ // The enable gate is middleware in front of routing (web_server.py:576), so
131
+ // a disabled plugin and a missing route are the same 404. Fail closed and
132
+ // calm: this is a configuration answer, not a crash.
133
+ const notEnabled = /\b404\b/.test(message)
134
+
135
+ return {
136
+ ...base,
137
+ kind: 'unavailable',
138
+ tone: 'muted',
139
+ headline: notEnabled ? 'Fleet backend not enabled' : 'Fleet backend unavailable',
140
+ detail: notEnabled
141
+ ? 'hermes plugins enable agent-fleet-herdr && hermes gateway restart'
142
+ : message.slice(0, 200),
143
+ projects: []
144
+ }
145
+ }
146
+
147
+ if (value?.loading) {
148
+ return { ...base, kind: 'loading', tone: 'muted', headline: 'Reading the fleet…', detail: '' }
149
+ }
150
+
151
+ const herdrDown = value?.herdr === false
152
+
153
+ if (projects.length === 0) {
154
+ return {
155
+ ...base,
156
+ kind: 'empty',
157
+ tone: 'muted',
158
+ headline: 'No live Agent Fleet sessions',
159
+ // Two genuinely different situations, two different sentences.
160
+ detail: herdrDown ? 'herdr is not answering either' : 'Nothing registered in the coms registry'
161
+ }
162
+ }
163
+
164
+ const waiting = countWaiting(projects)
165
+
166
+ return {
167
+ ...base,
168
+ kind: 'projects',
169
+ tone: waiting > 0 ? 'warn' : 'good',
170
+ headline:
171
+ waiting > 0
172
+ ? `${plural(waiting, 'agent')} waiting for you`
173
+ : `${plural(countSessions(projects), 'session')} in ${plural(projects.length, 'project')}`,
174
+ detail: herdrDown ? 'herdr not answering — states unknown' : ''
175
+ }
176
+ }
177
+
178
+ /** One sent prompt, already decided. `state` is deliberately absent: whether a
179
+ * peer sits in a herdr pane has nothing to do with whether it can be asked —
180
+ * coms goes to the peer's own socket — so a `detached` agent is a perfectly
181
+ * good target and must not be rendered as an unavailable one. */
182
+ function presentDispatch(dispatch, nowMs = Date.now()) {
183
+ const status = dispatch.status ?? 'pending'
184
+ const label = DISPATCH_LABEL[status] ?? status
185
+ // A turn takes minutes. Without this, `working on it` is indistinguishable
186
+ // from `stuck` for the entire time it matters. A finished dispatch keeps the
187
+ // time it TOOK — `Date.parse` of a missing timestamp is NaN, which is falsy,
188
+ // so an unanswered one ages against now.
189
+ const sentMs = Date.parse(dispatch.sent_at ?? '')
190
+ const untilMs = Date.parse(dispatch.answered_at ?? '') || nowMs
191
+ const age = Number.isFinite(sentMs) ? formatAge((untilMs - sentMs) / 1000) : ''
192
+
193
+ return {
194
+ id: dispatch.msg_id,
195
+ target: `${dispatch.name} · ${dispatch.project}`,
196
+ tone: DISPATCH_TONE[status] ?? 'bad',
197
+ label,
198
+ age,
199
+ prompt: dispatch.prompt ?? '',
200
+ // The reason a failure happened is more use than the answer that is absent.
201
+ body: dispatch.response ?? dispatch.detail ?? '',
202
+ pending: status === 'pending',
203
+ ariaLabel: `${dispatch.prompt ?? ''} — ${label}${age ? ` after ${age}` : ''} by ${dispatch.name}`
204
+ }
205
+ }
206
+
207
+ /** The row a `(project, name)` selection points at, or null.
208
+ *
209
+ * The selection is a pair of strings held by the pane; the row it names is
210
+ * re-found in every payload rather than copied at click time, so an action
211
+ * offered for it is decided on what is true now, not on what was true when it
212
+ * was clicked — and a row that dies while its modal is open says so. */
213
+ function findSession(projects, target) {
214
+ if (!target) return null
215
+ const group = (projects ?? []).find(item => item.project === target.project)
216
+
217
+ return (group?.sessions ?? []).find(session => session.name === target.name) ?? null
218
+ }
219
+
220
+ // What a step in the timeline is. `blocked` is the only one that raises its
221
+ // voice: the agent stopped and is waiting on a person. `done` is muted on
222
+ // purpose — a finished turn is the resting state, not an achievement.
223
+ const ACTIVITY_TONE = { tool: 'muted', assistant: 'good', dispatch: 'good', blocked: 'warn', done: 'muted' }
224
+
225
+ /** `…/activity` -> the timeline, and the one line that says what it is doing.
226
+ *
227
+ * The headline is the whole point of the phase: `working · 3m12s · bash git
228
+ * rev-list…` instead of `working`. It degrades a piece at a time — no
229
+ * timestamp drops the age, no transcript drops everything but the verdict —
230
+ * because a session with nothing on disk to read (a bridged Claude Code peer,
231
+ * a cwd that moved) is ordinary, and must read as an honest absence rather
232
+ * than as a broken panel. */
233
+ function presentActivity(payload, session = {}) {
234
+ const verdict = stateLabel(session?.state ?? 'unknown')
235
+ const blank = { available: false, headline: verdict, note: '', steps: [], seq: 0 }
236
+
237
+ if (!payload || payload.loading) return { ...blank, note: payload?.loading ? 'Reading the transcript…' : '' }
238
+
239
+ if (payload.error) {
240
+ const message = String(payload.error)
241
+ // The route is new; a Desktop that has not restarted since it landed 404s
242
+ // on it while the rest of the pane works perfectly. Naming that is more
243
+ // use than the status code.
244
+ return {
245
+ ...blank,
246
+ note: /\b404\b/.test(message) ? 'Restart Hermes Desktop to pick up the activity route' : message.slice(0, 120)
247
+ }
248
+ }
249
+
250
+ const seq = typeof payload.seq === 'number' ? payload.seq : 0
251
+ if (payload.available !== true) {
252
+ return { ...blank, seq, note: payload.reason || 'no transcript matches this session' }
253
+ }
254
+
255
+ const current = payload.current
256
+ const age = formatAge(current?.since_s)
257
+ const doing = current ? [current.label, current.detail].filter(Boolean).join(' ') : ''
258
+
259
+ return {
260
+ available: true,
261
+ // Joined from whatever survived: `working · 3m12s · bash git status`, or
262
+ // just `working` when the transcript has nothing to add.
263
+ headline: [verdict, age, doing].filter(Boolean).join(' · '),
264
+ note: '',
265
+ steps: (payload.steps ?? []).map((step, index) => ({
266
+ // The list is append-only and `seq` is a byte offset, so this is stable
267
+ // across polls even when one line contributed several steps.
268
+ key: `${step.seq}:${index}`,
269
+ kind: step.kind ?? '',
270
+ tone: ACTIVITY_TONE[step.kind] ?? 'muted',
271
+ label: step.label ?? step.kind ?? '',
272
+ detail: step.detail ?? '',
273
+ ariaLabel: [step.label, step.detail].filter(Boolean).join(' ')
274
+ })),
275
+ seq
276
+ }
277
+ }
278
+
279
+ // The monitor's task vocabulary (hermes-monitor-model.ts). `recovering` is the
280
+ // one that needed a word rather than a state name: the task is alive and the
281
+ // connection to it is not, which is a different worry from either "running" or
282
+ // "failed".
283
+ const TASK_TONE = {
284
+ starting: 'muted',
285
+ running: 'good',
286
+ cancelling: 'warn',
287
+ recovering: 'warn',
288
+ completed: 'muted',
289
+ blocked: 'warn',
290
+ failed: 'bad',
291
+ cancelled: 'muted',
292
+ orphaned: 'bad'
293
+ }
294
+
295
+ const TASK_LABEL = {
296
+ starting: 'starting',
297
+ running: 'running',
298
+ cancelling: 'cancelling…',
299
+ recovering: 'reconnecting',
300
+ completed: 'done',
301
+ blocked: 'needs answer',
302
+ failed: 'failed',
303
+ cancelled: 'cancelled',
304
+ orphaned: 'orphaned'
305
+ }
306
+
307
+ // Cancellable exactly where the backend says so (tasks.ACTIVE_STATES). Kept as
308
+ // its own list rather than "not terminal" so the two ends can be compared by
309
+ // reading them, and a button that would always 422 is never offered.
310
+ const TASK_ACTIVE = ['starting', 'running', 'cancelling', 'recovering']
311
+
312
+ /** `…/tasks` -> the subagent tree, flattened for rendering with a depth.
313
+ *
314
+ * A flat list with `depth` rather than nested arrays: the tree is at most two
315
+ * levels (a hub turn and its specialists), and a renderer that walks a nested
316
+ * structure has to recurse for a shape that cannot get deeper. The indentation
317
+ * is a presentational fact, so it is decided here.
318
+ *
319
+ * `available: false` is the ordinary answer — the monitor is opt-in and most
320
+ * hubs run without it — so it returns a sentence, never an alarm. */
321
+ function presentTasks(payload) {
322
+ const blank = { available: false, note: '', rows: [], running: 0 }
323
+
324
+ if (!payload || payload.loading) return { ...blank, note: payload?.loading ? 'Asking the monitor…' : '' }
325
+
326
+ if (payload.error) {
327
+ const message = String(payload.error)
328
+ // Same 404 as the activity route: a Desktop that has not restarted since
329
+ // this landed has no such route, while everything else in the pane works.
330
+ return {
331
+ ...blank,
332
+ note: /\b404\b/.test(message) ? 'Restart Hermes Desktop to pick up the tasks route' : message.slice(0, 120)
333
+ }
334
+ }
335
+
336
+ if (payload.available !== true) return { ...blank, note: payload.reason || 'no monitored hub for this session' }
337
+
338
+ const rows = []
339
+ let running = 0
340
+ for (const parent of payload.tasks ?? []) {
341
+ for (const [depth, task] of [[0, parent], ...(parent.children ?? []).map(c => [1, c])]) {
342
+ const state = task.state ?? 'orphaned'
343
+ if (TASK_ACTIVE.includes(state)) running += 1
344
+ rows.push({
345
+ key: `${task.hubInstanceId ?? ''}:${task.id}:${task.generation}`,
346
+ depth,
347
+ // The specialist is who it is; the id is only how it is addressed, and
348
+ // a hub turn has no specialist to name.
349
+ label: task.specialist || task.id,
350
+ tone: TASK_TONE[state] ?? 'muted',
351
+ state: TASK_LABEL[state] ?? state,
352
+ // A parent whose own parent was pruned is said out loud — the hierarchy
353
+ // is missing a level and a silently promoted row would misread as a
354
+ // top-level turn.
355
+ note: task.orphaned_parent ? 'parent no longer in the monitor' : '',
356
+ output: task.output ?? '',
357
+ truncated: Boolean(task.truncated),
358
+ canCancel: TASK_ACTIVE.includes(state),
359
+ taskId: task.id,
360
+ generation: task.generation,
361
+ ariaLabel: `${task.specialist || task.id}: ${TASK_LABEL[state] ?? state}`
362
+ })
363
+ }
364
+ }
365
+
366
+ return {
367
+ available: true,
368
+ note: rows.length ? '' : 'this hub has not spawned any subagents',
369
+ rows,
370
+ running
371
+ }
372
+ }
373
+
374
+ /** The modal a selected row opens: everything the 300px row had to truncate,
375
+ * plus what can be done about it.
376
+ *
377
+ * A list of actions rather than a fixed pair of buttons, because the set is
378
+ * what changes: sending a prompt used to live here and will again, and an
379
+ * action that is currently impossible is returned DISABLED with the reason
380
+ * instead of being hidden — "why can't I focus this one" is the question the
381
+ * panel exists to answer.
382
+ *
383
+ * Nothing selected is the resting state, not an error, so it returns a closed
384
+ * modal rather than a complaint. */
385
+ function presentSessionMenu({ target, session, herdrPanes, busy, error, activity, tasks } = {}) {
386
+ if (!target) {
387
+ return {
388
+ open: false,
389
+ title: '',
390
+ state: '',
391
+ note: '',
392
+ description: '',
393
+ facts: [],
394
+ actions: [],
395
+ activity: presentActivity(null),
396
+ tasks: presentTasks(null),
397
+ error: ''
398
+ }
399
+ }
400
+
401
+ const state = session?.state ?? 'unknown'
402
+ // A row that vanished from the payload between the click and this render: the
403
+ // selection is re-found every time (`findSession`), so `null` here means the
404
+ // session is gone, and saying so is better than an empty modal.
405
+ const facts = session
406
+ ? [
407
+ ['Purpose', session.purpose],
408
+ ['Model', session.model],
409
+ ['Directory', session.cwd],
410
+ ['Context', typeof session.context_used_pct === 'number' ? `${session.context_used_pct}%` : ''],
411
+ ['Queue', typeof session.queue_depth === 'number' ? String(session.queue_depth) : ''],
412
+ ['Uptime', formatAge(session.uptime_s)],
413
+ // Absent means the entry was written by a coms too old to carry it —
414
+ // not "just now", so it says nothing at all.
415
+ ['Heartbeat', formatAge(session.heartbeat_age_s) ? `${formatAge(session.heartbeat_age_s)} ago` : ''],
416
+ ['Pane', session.pane_id]
417
+ ]
418
+ .filter(([, value]) => Boolean(value))
419
+ .map(([label, value]) => ({ label, value: String(value) }))
420
+ : []
421
+
422
+ const note = session ? sessionNote(session, herdrPanes) : 'this session is no longer in the registry'
423
+ const timeline = presentActivity(session ? activity : null, session ?? {})
424
+ const subagents = presentTasks(session ? tasks : null)
425
+ const verdict = session ? stateLabel(state) : 'gone'
426
+
427
+ return {
428
+ open: true,
429
+ title: `${target.name} · ${target.project}`,
430
+ state: verdict,
431
+ note,
432
+ // The one line under the title. The transcript wins when it has something
433
+ // to say — `working · 3m12s · bash git status` answers "what is it doing",
434
+ // which `working — ` never could — and the registry's verdict is the
435
+ // fallback, not a second line saying the same word twice.
436
+ //
437
+ // A running subagent count joins it because a hub whose own transcript is
438
+ // idle while three specialists work is the case the panel used to read as
439
+ // "nothing is happening".
440
+ description: [
441
+ timeline.available ? timeline.headline : note ? `${verdict} — ${note}` : verdict,
442
+ subagents.running ? plural(subagents.running, 'subagent') : ''
443
+ ]
444
+ .filter(Boolean)
445
+ .join(' · '),
446
+ facts,
447
+ activity: timeline,
448
+ // The subagents this hub spawned, live, with a Cancel on each. The only
449
+ // part of the modal that can STOP something rather than describe it.
450
+ tasks: subagents,
451
+ actions: [
452
+ {
453
+ id: 'focus',
454
+ label: 'Focus pane',
455
+ // Possible only while herdr reports a pane for this peer. A `detached`
456
+ // row is a live session — coms still reaches its own socket — there is
457
+ // simply nothing to bring to the front.
458
+ enabled: Boolean(session?.workspace_id) && !busy,
459
+ detail: session?.workspace_id
460
+ ? 'Bring the herdr pane running it to the front'
461
+ : 'No herdr pane is hosting this agent right now'
462
+ }
463
+ ],
464
+ error: error ?? ''
465
+ }
466
+ }
467
+
468
+ /** One row, already decided: colour is never the only carrier of "waiting".
469
+ *
470
+ * `herdrPanes` comes from the payload, not from the row, which is why this
471
+ * takes a second argument instead of reading a global. */
472
+ function presentSession(session, { herdrPanes } = {}) {
473
+ const state = session.state ?? 'unknown'
474
+ const note = sessionNote(session, herdrPanes)
475
+ const uptime = formatAge(session.uptime_s)
476
+ const meta = [session.model, session.repo]
477
+
478
+ // Context and queue are what the herdr sidebar shows for the same peer;
479
+ // keeping the vocabulary identical means one glance works in both places.
480
+ if (typeof session.context_used_pct === 'number') meta.push(`ctx ${session.context_used_pct}%`)
481
+ // A queue of zero is the resting state and says nothing worth 4 characters
482
+ // in a 300px pane. A queue that is NOT zero is the reason a peer looks idle
483
+ // while work is waiting.
484
+ if (session.queue_depth) meta.push(`q${session.queue_depth}`)
485
+ if (uptime) meta.push(`up ${uptime}`)
486
+
487
+ return {
488
+ name: session.name,
489
+ tone: stateTone(state),
490
+ label: stateLabel(state),
491
+ // A glyph, not a hue — a red dot is invisible to a third of the reasons
492
+ // people open an accessibility guideline.
493
+ marker: session.needs_answer ? '▲' : '·',
494
+ meta: meta.filter(Boolean).join(' · '),
495
+ note,
496
+ ariaLabel: `${session.name}: ${stateLabel(state)}${session.needs_answer ? ', waiting for an answer' : ''}${note ? `, ${note}` : ''}`
497
+ }
498
+ }
499
+
500
+ // What a fleet transition is worth interrupting for. `error` and `warning` are
501
+ // sticky in the app's notification stack (notifications.ts:defaultDuration),
502
+ // which is the correct behaviour for "somebody is waiting on you" and the wrong
503
+ // one for "a session ended".
504
+ const EVENT_KIND = {
505
+ needs_answer: 'warning',
506
+ stale: 'warning',
507
+ dispatch_failed: 'warning',
508
+ vanished: 'error',
509
+ unblocked: 'info',
510
+ finished: 'info',
511
+ dispatch_answered: 'info',
512
+ throttled: 'info'
513
+ }
514
+
515
+ const EVENT_TITLE = {
516
+ needs_answer: 'Waiting for you',
517
+ stale: 'Heartbeat stopped',
518
+ dispatch_failed: 'Prompt failed',
519
+ vanished: 'Agent vanished',
520
+ unblocked: 'No longer waiting',
521
+ finished: 'Session ended',
522
+ dispatch_answered: 'Answer received',
523
+ throttled: 'Too much at once'
524
+ }
525
+
526
+ /** `/events` -> the toasts to raise and the cursor to resume from.
527
+ *
528
+ * `primed` is false for the very first answer, whose events are whatever
529
+ * survived in the buffer from before this pane existed. Their cursor is taken
530
+ * and their toasts are dropped: a pane opening is not the moment to be told
531
+ * about a question that was answered an hour ago, and the list below is where
532
+ * the current state lives anyway.
533
+ *
534
+ * `after` is what the caller has already shown. Two feeds deliver the same
535
+ * numbered events — the poll and the socket — and either may repeat what the
536
+ * other just delivered, so the cursor is applied HERE rather than trusted to
537
+ * the request: an event at or behind it is one this pane has already raised.
538
+ * For the same reason the returned cursor never goes backwards, so a frame
539
+ * that overtakes another cannot un-see events.
540
+ *
541
+ * The toast id is `(kind, project, name)`, which the app treats as a replace —
542
+ * so an agent that flaps updates one toast instead of stacking a column of
543
+ * them. */
544
+ function presentEvents(payload, primed = true, after = 0) {
545
+ const reported = typeof payload?.seq === 'number' ? payload.seq : 0
546
+ const cursor = typeof after === 'number' && after > 0 ? after : 0
547
+ const events = (primed ? payload?.events ?? [] : []).filter(
548
+ event => typeof event?.seq !== 'number' || event.seq > cursor
549
+ )
550
+
551
+ return {
552
+ seq: Math.max(reported, cursor),
553
+ toasts: events.map(event => ({
554
+ id: `agent-fleet:${event.kind}:${event.project ?? ''}:${event.name ?? ''}`,
555
+ kind: EVENT_KIND[event.kind] ?? 'info',
556
+ title: EVENT_TITLE[event.kind] ?? 'Agent Fleet',
557
+ message: event.message ?? event.kind
558
+ }))
559
+ }
560
+ }
561
+
562
+ // A socket frame this recent means the push transport is delivering. Longer
563
+ // than the server's 20s keepalive so one late frame does not read as a dead
564
+ // connection — `ctx.socket` gives the caller no close event, so "when did it
565
+ // last speak" is the only liveness signal there is.
566
+ const SOCKET_FRESH_MS = 25000
567
+
568
+ // How often to poll anyway while the socket is delivering. Not zero, ever: the
569
+ // stream drops a batch rather than queue it without bound, and this is what
570
+ // picks that batch up. It is the difference between a fallback and a hope.
571
+ const SOCKET_POLL_MS = 30000
572
+
573
+ /** Whether a tick of the events poll should actually fetch.
574
+ *
575
+ * The socket does not replace the poll, it slows it down: with frames
576
+ * arriving, the poll drops from every 5s to every 30s and becomes a safety
577
+ * net; the moment frames stop — a dropped connection, an OAuth remote where
578
+ * `ctx.socket` is a documented no-op — the next tick fetches again. Nothing
579
+ * has to detect the failure, because nothing was ever switched off. */
580
+ function shouldPollEvents({ lastFrameAt = 0, lastPollAt = 0, now = 0 } = {}) {
581
+ if (!lastFrameAt || now - lastFrameAt > SOCKET_FRESH_MS) return true
582
+
583
+ return !lastPollAt || now - lastPollAt >= SOCKET_POLL_MS
584
+ }
585
+
586
+ /** 3s polling with the two guards the monitor pane learned to need
587
+ * (`state.js:createActiveViewController`): no overlapping requests, and an
588
+ * epoch that voids answers arriving after the pane went away. Timer functions
589
+ * are injectable so the whole thing is testable without a DOM.
590
+ *
591
+ * Both feeds run on this — `/sessions` for the list and `/events` for the
592
+ * toasts — because the guards are the same problem in both cases.
593
+ *
594
+ * `shouldPoll` is the third guard, and only the events feed uses it: a tick
595
+ * that answers false is skipped, not cancelled, so the cadence can change
596
+ * without the timer being torn down and rebuilt. */
597
+ function createSessionsPoller({
598
+ fetchSessions,
599
+ onValue,
600
+ intervalMs = 3000,
601
+ shouldPoll = null,
602
+ setTimer = setInterval,
603
+ clearTimer = clearInterval
604
+ }) {
605
+ let timer = null
606
+ let visible = false
607
+ let inFlight = null
608
+ let epoch = 0
609
+
610
+ const poll = () => {
611
+ if (!visible || inFlight) return inFlight
612
+ if (shouldPoll && !shouldPoll()) return null
613
+ const requestEpoch = epoch
614
+ const request = (async () => {
615
+ try {
616
+ const payload = await fetchSessions()
617
+ if (visible && requestEpoch === epoch) onValue(payload)
618
+ } catch (error) {
619
+ if (visible && requestEpoch === epoch) onValue({ error: error?.message ?? String(error) })
620
+ }
621
+ })().finally(() => {
622
+ if (inFlight === request) inFlight = null
623
+ })
624
+
625
+ inFlight = request
626
+
627
+ return request
628
+ }
629
+
630
+ return {
631
+ poll,
632
+ setVisible(next) {
633
+ if (!next) {
634
+ visible = false
635
+ epoch++
636
+ if (timer) clearTimer(timer)
637
+ timer = null
638
+
639
+ return
640
+ }
641
+ visible = true
642
+ if (!timer) timer = setTimer(() => void poll(), intervalMs)
643
+ },
644
+ dispose() {
645
+ visible = false
646
+ epoch++
647
+ if (timer) clearTimer(timer)
648
+ timer = null
649
+ }
650
+ }
651
+ }
652
+
653
+ // <<< END SHARED >>>
654
+
655
+ export {
656
+ countSessions,
657
+ countWaiting,
658
+ createSessionsPoller,
659
+ findSession,
660
+ formatAge,
661
+ presentActivity,
662
+ presentDispatch,
663
+ presentEvents,
664
+ presentSession,
665
+ presentSessionMenu,
666
+ presentSessions,
667
+ presentTasks,
668
+ sessionNote,
669
+ shouldPollEvents,
670
+ stateLabel,
671
+ stateTone
672
+ }