@chankov/agent-fleet 2.1.2 → 2.2.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 (861) hide show
  1. package/.pi/agent-fleet/hooks/coms-stop-hook.mjs +53 -13
  2. package/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/README.md +223 -0
  3. package/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/bootstrap-profile-0.167.json +5627 -0
  4. package/.pi/agent-fleet/scripts/fleet-codex-local-mcp.ts +4 -0
  5. package/.pi/agent-fleet/scripts/fleet.ts +13 -17
  6. package/.pi/agent-fleet/scripts/flow.ts +2 -2
  7. package/.pi/agent-fleet/scripts/lib/codex-bootstrap-files.ts +46 -0
  8. package/.pi/agent-fleet/scripts/lib/codex-bootstrap-probe.ts +44 -0
  9. package/.pi/agent-fleet/scripts/lib/codex-bootstrap-producer.ts +131 -0
  10. package/.pi/agent-fleet/scripts/lib/codex-daemon-observer.ts +137 -0
  11. package/.pi/agent-fleet/scripts/lib/codex-desktop-discovery.ts +84 -0
  12. package/.pi/agent-fleet/scripts/lib/codex-desktop-preflight.ts +130 -0
  13. package/.pi/agent-fleet/scripts/lib/codex-desktop-queue-host.ts +20 -13
  14. package/.pi/agent-fleet/scripts/lib/codex-measurement.ts +218 -0
  15. package/.pi/agent-fleet/scripts/lib/codex-native-presence.ts +61 -0
  16. package/.pi/agent-fleet/scripts/lib/codex-probe-transcript.ts +135 -0
  17. package/.pi/agent-fleet/scripts/lib/codex-send-lineage.ts +72 -0
  18. package/.pi/agent-fleet/scripts/lib/codex-unix-queue-rpc.ts +23 -13
  19. package/.pi/agent-fleet/scripts/lib/fleet-codex-allowlist-store.ts +100 -14
  20. package/.pi/agent-fleet/scripts/lib/fleet-codex-answers.ts +1 -1
  21. package/.pi/agent-fleet/scripts/lib/fleet-codex-bootstrap.ts +204 -0
  22. package/.pi/agent-fleet/scripts/lib/fleet-codex-connections.ts +9 -3
  23. package/.pi/agent-fleet/scripts/lib/fleet-codex-event-runtime.ts +32 -16
  24. package/.pi/agent-fleet/scripts/lib/fleet-codex-local-mcp.ts +41 -21
  25. package/.pi/agent-fleet/scripts/lib/fleet-codex-permission-transport.ts +21 -0
  26. package/.pi/agent-fleet/scripts/lib/fleet-command.ts +4 -8
  27. package/.pi/agent-fleet/scripts/lib/flow-maintenance.ts +2 -1
  28. package/.pi/agent-fleet/scripts/lib/team-project.ts +0 -2
  29. package/.pi/agent-fleet/scripts/team-up.ts +5 -12
  30. package/.pi/agent-fleet/scripts/workflows/lib/git.ts +9 -0
  31. package/.pi/agent-fleet/scripts/workflows/lib/quality.ts +17 -4
  32. package/.pi/agents/model-profiles.yaml +0 -2
  33. package/.pi/harnesses/agent-hub/README.md +116 -67
  34. package/.pi/harnesses/agent-hub/capability-packs.ts +7 -4
  35. package/.pi/harnesses/agent-hub/codex-bootstrap.ts +117 -0
  36. package/.pi/harnesses/agent-hub/commands/context.ts +0 -4
  37. package/.pi/harnesses/agent-hub/commands/recover.ts +2 -1
  38. package/.pi/harnesses/agent-hub/config/agents.ts +3 -1
  39. package/.pi/harnesses/agent-hub/config/model-profiles.ts +3 -0
  40. package/.pi/harnesses/agent-hub/context/assertions-artifacts.ts +14 -1
  41. package/.pi/harnesses/agent-hub/dispatch-native-prepare.ts +17 -0
  42. package/.pi/harnesses/agent-hub/dispatch-native-spawn.ts +3 -1
  43. package/.pi/harnesses/agent-hub/dispatch-native-types.ts +4 -0
  44. package/.pi/harnesses/agent-hub/dispatch-native.ts +9 -3
  45. package/.pi/harnesses/agent-hub/drift-watchdog.js +5 -10
  46. package/.pi/harnesses/agent-hub/execution-trace.ts +1 -1
  47. package/.pi/harnesses/agent-hub/filesystem-tool.ts +1 -1
  48. package/.pi/harnesses/agent-hub/footer.ts +2 -3
  49. package/.pi/harnesses/agent-hub/helpers.ts +4 -5
  50. package/.pi/harnesses/agent-hub/history-projection.ts +1 -1
  51. package/.pi/harnesses/agent-hub/index.ts +213 -196
  52. package/.pi/harnesses/agent-hub/input/shortcuts.ts +0 -7
  53. package/.pi/harnesses/agent-hub/lifecycle/session-orchestration.ts +0 -2
  54. package/.pi/harnesses/agent-hub/no-progress.ts +14 -9
  55. package/.pi/harnesses/agent-hub/operator-current-state.ts +5 -1
  56. package/.pi/harnesses/agent-hub/package.json +1 -1
  57. package/.pi/harnesses/agent-hub/policy/roster.ts +12 -3
  58. package/.pi/harnesses/agent-hub/policy/work-mode.ts +10 -49
  59. package/.pi/harnesses/agent-hub/poll-command.ts +12 -4
  60. package/.pi/harnesses/agent-hub/proactive-snapshot.ts +12 -4
  61. package/.pi/harnesses/agent-hub/process-obligations.ts +42 -9
  62. package/.pi/harnesses/agent-hub/prompts/context.ts +17 -0
  63. package/.pi/harnesses/agent-hub/prompts/fragments.ts +9 -1
  64. package/.pi/harnesses/agent-hub/prompts/session-start.ts +2 -3
  65. package/.pi/harnesses/agent-hub/prompts/system-prompt.ts +25 -8
  66. package/.pi/harnesses/agent-hub/provider-semaphore.js +5 -0
  67. package/.pi/harnesses/agent-hub/review-continuity.ts +5 -2
  68. package/.pi/harnesses/agent-hub/review-reuse.ts +2 -1
  69. package/.pi/harnesses/agent-hub/run-budget.js +22 -2
  70. package/.pi/harnesses/agent-hub/scope-gate.js +38 -0
  71. package/.pi/harnesses/agent-hub/scope-overlap.ts +46 -0
  72. package/.pi/harnesses/agent-hub/task-brief.ts +98 -0
  73. package/.pi/harnesses/agent-hub/tool-catalog-runtime.ts +4 -0
  74. package/.pi/harnesses/agent-hub/tool-catalog-state.ts +5 -3
  75. package/.pi/harnesses/agent-hub/tools/action-executors.ts +5 -7
  76. package/.pi/harnesses/agent-hub/tools/context.ts +2 -0
  77. package/.pi/harnesses/agent-hub/tools/dispatch-agent.ts +2 -1
  78. package/.pi/harnesses/agent-hub/tools/dispatch-execution.ts +184 -33
  79. package/.pi/harnesses/agent-hub/tools/poll-panel-core.ts +30 -0
  80. package/.pi/harnesses/agent-hub/tools/poll-panel.ts +33 -0
  81. package/.pi/harnesses/agent-hub/tools/run-flow.ts +41 -10
  82. package/.pi/harnesses/agent-hub/tools/team-adjust.ts +1 -1
  83. package/.pi/harnesses/agent-hub/ui/fleet-dashboard.ts +12 -2
  84. package/.pi/harnesses/agent-hub/work-mode.ts +44 -49
  85. package/.pi/harnesses/agent-hub/write-isolation.ts +53 -8
  86. package/.pi/harnesses/coms/package.json +1 -1
  87. package/.pi/harnesses/damage-control-continue/package.json +1 -1
  88. package/.pi/harnesses/lib/codex-compat.ts +97 -0
  89. package/.pi/harnesses/lib/codex-contract.ts +259 -0
  90. package/.pi/harnesses/lib/codex-notification-profile.ts +75 -0
  91. package/.pi/harnesses/lib/coms-core.ts +8 -4
  92. package/.pi/harnesses/lib/context-budget-child-prompt.ts +1 -1
  93. package/.pi/harnesses/lib/context-budget-hub-prompt.ts +6 -3
  94. package/.pi/harnesses/lib/fleet-bootstrap-channel.ts +148 -0
  95. package/.pi/harnesses/lib/fleet-codex-catalog.ts +30 -0
  96. package/.pi/harnesses/lib/fleet-codex-chat-view.ts +43 -0
  97. package/.pi/harnesses/lib/fleet-codex-namespace.ts +2 -0
  98. package/.pi/harnesses/lib/fleet-codex-policy-snapshot.ts +10 -0
  99. package/.pi/harnesses/lib/fleet-connection-control.ts +20 -3
  100. package/.pi/harnesses/lib/fleet-notification-admission.ts +32 -0
  101. package/.pi/harnesses/lib/fleet-notification-bootstrap.ts +152 -0
  102. package/.pi/harnesses/lib/fleet-notification-validation.ts +80 -25
  103. package/.pi/harnesses/lib/fleet-target-identity.ts +9 -0
  104. package/.versions/2.2.0/.pi/agent-fleet/hermes/README.md +347 -0
  105. package/.versions/2.2.0/.pi/agent-fleet/hermes/desktop-plugins/agent-fleet-herdr/plugin.js +1291 -0
  106. package/.versions/2.2.0/.pi/agent-fleet/hermes/desktop-plugins/agent-fleet-herdr/presentation.js +672 -0
  107. package/.versions/2.2.0/.pi/agent-fleet/hermes/desktop-plugins/agent-fleet-monitor/plugin.js +19 -0
  108. package/.versions/2.2.0/.pi/agent-fleet/hermes/desktop-plugins/agent-fleet-monitor/state.js +10 -0
  109. package/.versions/2.2.0/.pi/agent-fleet/hermes/gates/gate-o-capability.md +8 -0
  110. package/.versions/2.2.0/.pi/agent-fleet/hermes/gates/gate-o-validator-fixtures.json +1 -0
  111. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/activity.py +773 -0
  112. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/coms_registry.py +134 -0
  113. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/coms_send.py +350 -0
  114. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/herdr_source.py +193 -0
  115. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/manifest.json +4 -0
  116. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/plugin_api.py +444 -0
  117. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/sessions.py +205 -0
  118. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/tasks.py +300 -0
  119. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/dashboard/watch.py +819 -0
  120. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-herdr/plugin.yaml +8 -0
  121. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-monitor/dashboard/adapter.py +139 -0
  122. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-monitor/dashboard/manifest.json +11 -0
  123. package/.versions/2.2.0/.pi/agent-fleet/hermes/plugins/agent-fleet-monitor/dashboard/plugin_api.py +50 -0
  124. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-conductor/SKILL.md +84 -0
  125. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-liaison/SKILL.md +84 -0
  126. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/SKILL.md +76 -0
  127. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/manifest.json +1 -0
  128. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog.py +249 -0
  129. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_actions.py +124 -0
  130. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_contract.py +76 -0
  131. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_delivery.py +10 -0
  132. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_engine.py +128 -0
  133. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_judgment.py +41 -0
  134. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_recovery.py +103 -0
  135. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_state.py +163 -0
  136. package/.versions/2.2.0/.pi/agent-fleet/hermes/skills/hub-watchdog/scripts/watchdog_transport.py +138 -0
  137. package/.versions/2.2.0/.pi/agent-fleet/hermes/watchdog-tests/__init__.py +0 -0
  138. package/.versions/2.2.0/.pi/agent-fleet/hooks/coms-stop-hook.mjs +124 -0
  139. package/.versions/2.2.0/.pi/agent-fleet/scripts/claude-code-preflight.ts +70 -0
  140. package/.versions/2.2.0/.pi/agent-fleet/scripts/coms-claude-bridge.ts +440 -0
  141. package/.versions/2.2.0/.pi/agent-fleet/scripts/coms-cli.ts +430 -0
  142. package/.versions/2.2.0/.pi/agent-fleet/scripts/coms-hermes-bridge.ts +416 -0
  143. package/.versions/2.2.0/.pi/agent-fleet/scripts/exec-at-target.ts +10 -0
  144. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/0.167-shared.json +1900 -0
  145. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/README.md +223 -0
  146. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/assessment.md +83 -0
  147. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/bootstrap-profile-0.167.json +5627 -0
  148. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/bootstrap-profile.md +43 -0
  149. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/bootstrap.md +45 -0
  150. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/capture-profile.ts +53 -0
  151. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/capture.ts +102 -0
  152. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/catalog.md +91 -0
  153. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/channel.md +21 -0
  154. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/measurement.md +133 -0
  155. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/measurements.json +74 -0
  156. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/notification-profile-0.167.json +2679 -0
  157. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/observer.md +101 -0
  158. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/opaque-response.md +57 -0
  159. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/open-sent.md +68 -0
  160. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/probe-reader.md +51 -0
  161. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/profile.md +71 -0
  162. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/projection.md +147 -0
  163. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/reconnect.md +40 -0
  164. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/response-unions.md +74 -0
  165. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/semver.md +124 -0
  166. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/codex-notification-contracts/surface.md +73 -0
  167. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/fleet-codex-allowlist-store-child.ts +31 -0
  168. package/.versions/2.2.0/.pi/agent-fleet/scripts/fixtures/response-fixture.ts +23 -0
  169. package/.versions/2.2.0/.pi/agent-fleet/scripts/fleet-codex-local-mcp.mjs +26 -0
  170. package/.versions/2.2.0/.pi/agent-fleet/scripts/fleet-codex-local-mcp.ts +63 -0
  171. package/.versions/2.2.0/.pi/agent-fleet/scripts/fleet.ts +244 -0
  172. package/.versions/2.2.0/.pi/agent-fleet/scripts/flow.ts +166 -0
  173. package/.versions/2.2.0/.pi/agent-fleet/scripts/hermes-monitor-capability-runner.ts +25 -0
  174. package/.versions/2.2.0/.pi/agent-fleet/scripts/hermes-monitor-scenario.ts +474 -0
  175. package/.versions/2.2.0/.pi/agent-fleet/scripts/hermes-watchdog-capability-probe.ts +45 -0
  176. package/.versions/2.2.0/.pi/agent-fleet/scripts/install-hermes-plugin.sh +180 -0
  177. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/claude-bridge-core.ts +208 -0
  178. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-bootstrap-files.ts +46 -0
  179. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-bootstrap-probe.ts +44 -0
  180. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-bootstrap-producer.ts +131 -0
  181. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-daemon-observer.ts +137 -0
  182. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-desktop-discovery.ts +84 -0
  183. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-desktop-preflight.ts +130 -0
  184. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-desktop-queue-host.ts +113 -0
  185. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-measurement.ts +218 -0
  186. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-native-presence.ts +61 -0
  187. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-probe-transcript.ts +135 -0
  188. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-send-lineage.ts +72 -0
  189. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/codex-unix-queue-rpc.ts +101 -0
  190. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/coms-envelope.ts +582 -0
  191. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fake-herdr-server.ts +88 -0
  192. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-allowlist-store.ts +453 -0
  193. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-allowlist.ts +175 -0
  194. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-answer-transport.ts +73 -0
  195. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-answers.ts +74 -0
  196. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-bootstrap.ts +204 -0
  197. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-connections.ts +76 -0
  198. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-event-reply.ts +58 -0
  199. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-event-runtime.ts +132 -0
  200. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-instruction-store.ts +428 -0
  201. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-instruction-transport.ts +160 -0
  202. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-instructions.ts +175 -0
  203. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-local-mcp.ts +435 -0
  204. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-native-history.ts +215 -0
  205. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-observation-store.ts +208 -0
  206. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-observe-transport.ts +49 -0
  207. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-observe.ts +93 -0
  208. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-overview.ts +52 -0
  209. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-permission-transport.ts +44 -0
  210. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-permissions.ts +83 -0
  211. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-readonly.ts +213 -0
  212. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-relay-latency.ts +45 -0
  213. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-response-read.ts +26 -0
  214. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-response-transport.ts +38 -0
  215. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-codex-resync.ts +212 -0
  216. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/fleet-command.ts +264 -0
  217. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/flow-command.ts +107 -0
  218. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/flow-maintenance.ts +239 -0
  219. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/herdr-layout.ts +281 -0
  220. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/hermes-bridge-core.ts +241 -0
  221. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/hermes-monitor-events.ts +1 -0
  222. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/hermes-monitor-herdr.ts +2 -0
  223. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/hermes-monitor-model.ts +3 -0
  224. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/hermes-monitor-registry.ts +2 -0
  225. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/hermes-monitor-socket.ts +2 -0
  226. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/hermes-monitor-store.ts +2 -0
  227. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/monitor-env.ts +146 -0
  228. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/peer-launch.ts +318 -0
  229. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/peer-target.ts +1 -0
  230. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/persona-banner.ts +62 -0
  231. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/persona-dirs.ts +25 -0
  232. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/resource-closure.js +1 -0
  233. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/runtime-dependencies.js +124 -0
  234. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/session-launch.ts +56 -0
  235. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/spawn-stagger.ts +101 -0
  236. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/team-project.ts +176 -0
  237. package/.versions/2.2.0/.pi/agent-fleet/scripts/lib/team-snapshot.ts +160 -0
  238. package/.versions/2.2.0/.pi/agent-fleet/scripts/package-lock.json +57 -0
  239. package/.versions/2.2.0/.pi/agent-fleet/scripts/package.json +10 -0
  240. package/.versions/2.2.0/.pi/agent-fleet/scripts/peer-banner.ts +41 -0
  241. package/.versions/2.2.0/.pi/agent-fleet/scripts/peer-launch.ts +289 -0
  242. package/.versions/2.2.0/.pi/agent-fleet/scripts/pi-session.ts +9 -0
  243. package/.versions/2.2.0/.pi/agent-fleet/scripts/team-snapshot.ts +245 -0
  244. package/.versions/2.2.0/.pi/agent-fleet/scripts/team-up.ts +378 -0
  245. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/agent-phase.ts +181 -0
  246. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/changes.ts +61 -0
  247. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/debate.ts +149 -0
  248. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/env.ts +36 -0
  249. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/envelopes.ts +169 -0
  250. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/gates.ts +81 -0
  251. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/git.ts +108 -0
  252. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/isolated-snapshot.ts +130 -0
  253. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/merge.ts +95 -0
  254. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/model-profile.ts +22 -0
  255. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/model-visibility.ts +92 -0
  256. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/permissions.ts +137 -0
  257. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/personas.ts +57 -0
  258. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/poll.ts +86 -0
  259. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/project-policy.ts +37 -0
  260. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/quality.ts +78 -0
  261. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/run.ts +109 -0
  262. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/scout-data-boundary.ts +55 -0
  263. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/trace.ts +52 -0
  264. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/voices.ts +128 -0
  265. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/writer-lease-race.worker.mjs +36 -0
  266. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/lib/writer-lease.ts +148 -0
  267. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/tsconfig.json +22 -0
  268. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/wf-build-test.ts +61 -0
  269. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/wf-debate.ts +87 -0
  270. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/wf-document.ts +50 -0
  271. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/wf-poll.ts +95 -0
  272. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/wf-quality.ts +20 -0
  273. package/.versions/2.2.0/.pi/agent-fleet/scripts/workflows/wf-scout.ts +40 -0
  274. package/.versions/2.2.0/.pi/agents/dispatch-policy.yaml +32 -0
  275. package/.versions/2.2.0/.pi/agents/model-profiles.yaml +132 -0
  276. package/.versions/2.2.0/.pi/agents/peers.yaml +147 -0
  277. package/.versions/2.2.0/.pi/agents/teams.yaml +41 -0
  278. package/.versions/2.2.0/.pi/agents/voices.yaml +13 -0
  279. package/.versions/2.2.0/.pi/damage-control-rules.yaml +297 -0
  280. package/.versions/2.2.0/.pi/extensions/btw/README.md +120 -0
  281. package/.versions/2.2.0/.pi/extensions/btw/index.ts +916 -0
  282. package/.versions/2.2.0/.pi/extensions/btw/package.json +6 -0
  283. package/.versions/2.2.0/.pi/extensions/btw/state.js +179 -0
  284. package/.versions/2.2.0/.pi/extensions/chrome-devtools-mcp/README.md +55 -0
  285. package/.versions/2.2.0/.pi/extensions/chrome-devtools-mcp/index.ts +93 -0
  286. package/.versions/2.2.0/.pi/extensions/chrome-devtools-mcp/package.json +6 -0
  287. package/.versions/2.2.0/.pi/extensions/compact-and-continue/README.md +42 -0
  288. package/.versions/2.2.0/.pi/extensions/compact-and-continue/index.ts +136 -0
  289. package/.versions/2.2.0/.pi/extensions/compact-and-continue/package.json +6 -0
  290. package/.versions/2.2.0/.pi/extensions/mcp-bridge/README.md +46 -0
  291. package/.versions/2.2.0/.pi/extensions/mcp-bridge/index.ts +206 -0
  292. package/.versions/2.2.0/.pi/extensions/mcp-bridge/package.json +6 -0
  293. package/.versions/2.2.0/.pi/extensions/package-lock.json +1175 -0
  294. package/.versions/2.2.0/.pi/extensions/package.json +9 -0
  295. package/.versions/2.2.0/.pi/extensions/pi-voice-stt/README.md +224 -0
  296. package/.versions/2.2.0/.pi/extensions/pi-voice-stt/config.ts +199 -0
  297. package/.versions/2.2.0/.pi/extensions/pi-voice-stt/examples/stt.json +35 -0
  298. package/.versions/2.2.0/.pi/extensions/pi-voice-stt/index.ts +248 -0
  299. package/.versions/2.2.0/.pi/extensions/pi-voice-stt/package.json +6 -0
  300. package/.versions/2.2.0/.pi/extensions/pi-voice-stt/providers.ts +214 -0
  301. package/.versions/2.2.0/.pi/extensions/pi-voice-stt/recorder.ts +158 -0
  302. package/.versions/2.2.0/.pi/harnesses/agent-hub/README.md +1633 -0
  303. package/.versions/2.2.0/.pi/harnesses/agent-hub/acceptance.ts +204 -0
  304. package/.versions/2.2.0/.pi/harnesses/agent-hub/access-approval.ts +266 -0
  305. package/.versions/2.2.0/.pi/harnesses/agent-hub/action-authorization.ts +10 -0
  306. package/.versions/2.2.0/.pi/harnesses/agent-hub/agentic-contract.ts +43 -0
  307. package/.versions/2.2.0/.pi/harnesses/agent-hub/agentic-evidence.ts +64 -0
  308. package/.versions/2.2.0/.pi/harnesses/agent-hub/agentic-hub.ts +55 -0
  309. package/.versions/2.2.0/.pi/harnesses/agent-hub/agentic-runtime.ts +56 -0
  310. package/.versions/2.2.0/.pi/harnesses/agent-hub/agentic-sources-worker.mjs +4 -0
  311. package/.versions/2.2.0/.pi/harnesses/agent-hub/agentic-sources.ts +74 -0
  312. package/.versions/2.2.0/.pi/harnesses/agent-hub/agentic-state.ts +23 -0
  313. package/.versions/2.2.0/.pi/harnesses/agent-hub/approval-wait.ts +1 -0
  314. package/.versions/2.2.0/.pi/harnesses/agent-hub/artifacts.js +146 -0
  315. package/.versions/2.2.0/.pi/harnesses/agent-hub/assertion-ledger.js +68 -0
  316. package/.versions/2.2.0/.pi/harnesses/agent-hub/assist-profile.ts +19 -0
  317. package/.versions/2.2.0/.pi/harnesses/agent-hub/backend-policy.js +174 -0
  318. package/.versions/2.2.0/.pi/harnesses/agent-hub/bounded-output.ts +26 -0
  319. package/.versions/2.2.0/.pi/harnesses/agent-hub/budget-recovery.ts +123 -0
  320. package/.versions/2.2.0/.pi/harnesses/agent-hub/capability-confirmation.ts +47 -0
  321. package/.versions/2.2.0/.pi/harnesses/agent-hub/capability-packs.ts +187 -0
  322. package/.versions/2.2.0/.pi/harnesses/agent-hub/codex-bootstrap.ts +117 -0
  323. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agent-model-thinking.ts +10 -0
  324. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agent-model.ts +10 -0
  325. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agent-models-substitute.ts +10 -0
  326. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agents-add.ts +9 -0
  327. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agents-drop.ts +9 -0
  328. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agents-history.ts +9 -0
  329. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agents-kill.ts +10 -0
  330. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agents-list.ts +9 -0
  331. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agents-restart.ts +10 -0
  332. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agents-save.ts +9 -0
  333. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/agents-team.ts +9 -0
  334. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/audit.ts +9 -0
  335. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/compound.ts +9 -0
  336. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/coms.ts +9 -0
  337. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/config.ts +9 -0
  338. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/context-command.ts +9 -0
  339. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/context.ts +43 -0
  340. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/debate.ts +9 -0
  341. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/dispatch-policy.ts +9 -0
  342. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/handoff.ts +10 -0
  343. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/hub-report.ts +9 -0
  344. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/models.ts +10 -0
  345. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/poll.ts +9 -0
  346. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/recover.ts +62 -0
  347. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/retry.ts +10 -0
  348. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/task-triage-recover.ts +12 -0
  349. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/task-triage-waive.ts +12 -0
  350. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/watchdog.ts +9 -0
  351. package/.versions/2.2.0/.pi/harnesses/agent-hub/commands/zoom.ts +10 -0
  352. package/.versions/2.2.0/.pi/harnesses/agent-hub/config/agents.ts +183 -0
  353. package/.versions/2.2.0/.pi/harnesses/agent-hub/config/model-profiles.ts +240 -0
  354. package/.versions/2.2.0/.pi/harnesses/agent-hub/config/overrides.ts +166 -0
  355. package/.versions/2.2.0/.pi/harnesses/agent-hub/context/agent-state.ts +30 -0
  356. package/.versions/2.2.0/.pi/harnesses/agent-hub/context/assertions-artifacts.ts +234 -0
  357. package/.versions/2.2.0/.pi/harnesses/agent-hub/context/budgets.ts +152 -0
  358. package/.versions/2.2.0/.pi/harnesses/agent-hub/context/hub-state.ts +40 -0
  359. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-budget-snapshot.ts +105 -0
  360. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-compaction-monitor.ts +35 -0
  361. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-compaction-preflight.ts +21 -0
  362. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-compaction-runtime.ts +69 -0
  363. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-compaction.ts +34 -0
  364. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-continuity-broker.ts +44 -0
  365. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-continuity-child.ts +83 -0
  366. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-continuity-client.ts +22 -0
  367. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-continuity-compat.ts +45 -0
  368. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-continuity-owners.ts +17 -0
  369. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-continuity-registry.ts +8 -0
  370. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-continuity.ts +82 -0
  371. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-pressure.ts +222 -0
  372. package/.versions/2.2.0/.pi/harnesses/agent-hub/context-window.js +108 -0
  373. package/.versions/2.2.0/.pi/harnesses/agent-hub/damage-guard-approval.ts +83 -0
  374. package/.versions/2.2.0/.pi/harnesses/agent-hub/damage-guard-broker.ts +125 -0
  375. package/.versions/2.2.0/.pi/harnesses/agent-hub/damage-guard-contract.ts +22 -0
  376. package/.versions/2.2.0/.pi/harnesses/agent-hub/damage-guard-descendant.ts +76 -0
  377. package/.versions/2.2.0/.pi/harnesses/agent-hub/damage-guard-hub.ts +263 -0
  378. package/.versions/2.2.0/.pi/harnesses/agent-hub/damage-guard-identity.ts +12 -0
  379. package/.versions/2.2.0/.pi/harnesses/agent-hub/damage-guard-owners.ts +59 -0
  380. package/.versions/2.2.0/.pi/harnesses/agent-hub/damage-guard-state.ts +43 -0
  381. package/.versions/2.2.0/.pi/harnesses/agent-hub/damage-guard-test-tsconfig.json +19 -0
  382. package/.versions/2.2.0/.pi/harnesses/agent-hub/debate-command.ts +176 -0
  383. package/.versions/2.2.0/.pi/harnesses/agent-hub/delegate.ts +478 -0
  384. package/.versions/2.2.0/.pi/harnesses/agent-hub/deterministic-fs.ts +195 -0
  385. package/.versions/2.2.0/.pi/harnesses/agent-hub/diagnostic-probe-extension.ts +26 -0
  386. package/.versions/2.2.0/.pi/harnesses/agent-hub/diagnostic-series-budget.ts +178 -0
  387. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-coms.ts +258 -0
  388. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-core.ts +27 -0
  389. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-native-complete.ts +176 -0
  390. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-native-prepare.ts +318 -0
  391. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-native-spawn.ts +264 -0
  392. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-native-types.ts +297 -0
  393. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-native.ts +242 -0
  394. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-observability.ts +225 -0
  395. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-triage-contract.ts +27 -0
  396. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-triage-eval.ts +77 -0
  397. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-triage-policy.ts +29 -0
  398. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-triage-runtime.ts +55 -0
  399. package/.versions/2.2.0/.pi/harnesses/agent-hub/dispatch-triage-state.ts +33 -0
  400. package/.versions/2.2.0/.pi/harnesses/agent-hub/docs-lane.js +123 -0
  401. package/.versions/2.2.0/.pi/harnesses/agent-hub/drift-judge.ts +352 -0
  402. package/.versions/2.2.0/.pi/harnesses/agent-hub/drift-runtime.ts +480 -0
  403. package/.versions/2.2.0/.pi/harnesses/agent-hub/drift-system1-policy.ts +39 -0
  404. package/.versions/2.2.0/.pi/harnesses/agent-hub/drift-system1.ts +469 -0
  405. package/.versions/2.2.0/.pi/harnesses/agent-hub/drift-watchdog.js +344 -0
  406. package/.versions/2.2.0/.pi/harnesses/agent-hub/evidence-manifest.ts +51 -0
  407. package/.versions/2.2.0/.pi/harnesses/agent-hub/evidence-rules.js +96 -0
  408. package/.versions/2.2.0/.pi/harnesses/agent-hub/execution-evidence.ts +96 -0
  409. package/.versions/2.2.0/.pi/harnesses/agent-hub/execution-trace.ts +241 -0
  410. package/.versions/2.2.0/.pi/harnesses/agent-hub/external-blocker.js +92 -0
  411. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/adapters.ts +88 -0
  412. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/broker-client.ts +62 -0
  413. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/broker.ts +128 -0
  414. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/child-extension.ts +42 -0
  415. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/descendant.ts +67 -0
  416. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/discovery-worker.mjs +15 -0
  417. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/discovery.ts +126 -0
  418. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/evaluate.ts +57 -0
  419. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/hub.ts +170 -0
  420. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/native-context.ts +8 -0
  421. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/native-fixture.test-support.ts +108 -0
  422. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/owners.ts +100 -0
  423. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/results.ts +55 -0
  424. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/runtime.ts +130 -0
  425. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/semantic-profiles.ts +18 -0
  426. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/sources.ts +69 -0
  427. package/.versions/2.2.0/.pi/harnesses/agent-hub/file-discovery/state.ts +22 -0
  428. package/.versions/2.2.0/.pi/harnesses/agent-hub/filesystem-tool.ts +166 -0
  429. package/.versions/2.2.0/.pi/harnesses/agent-hub/fixtures/registration-surface.json +68 -0
  430. package/.versions/2.2.0/.pi/harnesses/agent-hub/fixtures/t0a-synthetic/catalog.ts +189 -0
  431. package/.versions/2.2.0/.pi/harnesses/agent-hub/footer.ts +29 -0
  432. package/.versions/2.2.0/.pi/harnesses/agent-hub/helpers.ts +269 -0
  433. package/.versions/2.2.0/.pi/harnesses/agent-hub/history-projection.ts +116 -0
  434. package/.versions/2.2.0/.pi/harnesses/agent-hub/hub-state-audit.js +41 -0
  435. package/.versions/2.2.0/.pi/harnesses/agent-hub/index.ts +2722 -0
  436. package/.versions/2.2.0/.pi/harnesses/agent-hub/input/completions.ts +82 -0
  437. package/.versions/2.2.0/.pi/harnesses/agent-hub/input/shortcuts.ts +16 -0
  438. package/.versions/2.2.0/.pi/harnesses/agent-hub/lifecycle/context-pressure.ts +231 -0
  439. package/.versions/2.2.0/.pi/harnesses/agent-hub/lifecycle/monitor-session.ts +104 -0
  440. package/.versions/2.2.0/.pi/harnesses/agent-hub/lifecycle/session-orchestration.ts +143 -0
  441. package/.versions/2.2.0/.pi/harnesses/agent-hub/lifecycle/turn-handlers.ts +90 -0
  442. package/.versions/2.2.0/.pi/harnesses/agent-hub/monitor-control.ts +9 -0
  443. package/.versions/2.2.0/.pi/harnesses/agent-hub/monitor-invoke-journal.ts +131 -0
  444. package/.versions/2.2.0/.pi/harnesses/agent-hub/monitor-invoke.ts +92 -0
  445. package/.versions/2.2.0/.pi/harnesses/agent-hub/monitor-lifecycle.ts +13 -0
  446. package/.versions/2.2.0/.pi/harnesses/agent-hub/monitor-publisher.ts +59 -0
  447. package/.versions/2.2.0/.pi/harnesses/agent-hub/monitor-recovery.ts +3 -0
  448. package/.versions/2.2.0/.pi/harnesses/agent-hub/monitor-runtime.ts +3 -0
  449. package/.versions/2.2.0/.pi/harnesses/agent-hub/monitor-session-bridge.ts +266 -0
  450. package/.versions/2.2.0/.pi/harnesses/agent-hub/no-progress.ts +627 -0
  451. package/.versions/2.2.0/.pi/harnesses/agent-hub/operator-current-state.ts +57 -0
  452. package/.versions/2.2.0/.pi/harnesses/agent-hub/operator-watchdog.ts +97 -0
  453. package/.versions/2.2.0/.pi/harnesses/agent-hub/orchestration-activation.ts +109 -0
  454. package/.versions/2.2.0/.pi/harnesses/agent-hub/orchestration-metrics.ts +78 -0
  455. package/.versions/2.2.0/.pi/harnesses/agent-hub/orchestration-route.ts +68 -0
  456. package/.versions/2.2.0/.pi/harnesses/agent-hub/package.json +7 -0
  457. package/.versions/2.2.0/.pi/harnesses/agent-hub/peer-spawn-plan.ts +116 -0
  458. package/.versions/2.2.0/.pi/harnesses/agent-hub/permission-channel.ts +87 -0
  459. package/.versions/2.2.0/.pi/harnesses/agent-hub/permission-relay.ts +84 -0
  460. package/.versions/2.2.0/.pi/harnesses/agent-hub/policy/models.ts +153 -0
  461. package/.versions/2.2.0/.pi/harnesses/agent-hub/policy/profile-activation.ts +62 -0
  462. package/.versions/2.2.0/.pi/harnesses/agent-hub/policy/profile-runtime.ts +120 -0
  463. package/.versions/2.2.0/.pi/harnesses/agent-hub/policy/roster.ts +103 -0
  464. package/.versions/2.2.0/.pi/harnesses/agent-hub/policy/work-mode.ts +103 -0
  465. package/.versions/2.2.0/.pi/harnesses/agent-hub/poll-command.ts +184 -0
  466. package/.versions/2.2.0/.pi/harnesses/agent-hub/presentation.ts +54 -0
  467. package/.versions/2.2.0/.pi/harnesses/agent-hub/private-config-current-state.ts +81 -0
  468. package/.versions/2.2.0/.pi/harnesses/agent-hub/private-config-fixtures.ts +26 -0
  469. package/.versions/2.2.0/.pi/harnesses/agent-hub/private-config-review.ts +100 -0
  470. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-config.ts +22 -0
  471. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-evaluate.ts +138 -0
  472. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-external-git.ts +82 -0
  473. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-external.ts +142 -0
  474. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-feedback.ts +104 -0
  475. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-findings.ts +115 -0
  476. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-local.ts +89 -0
  477. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-observer.ts +106 -0
  478. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-rules.ts +171 -0
  479. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-runtime.ts +318 -0
  480. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-selection.ts +68 -0
  481. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-snapshot-worker.mjs +12 -0
  482. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-snapshot.ts +287 -0
  483. package/.versions/2.2.0/.pi/harnesses/agent-hub/proactive-types.ts +70 -0
  484. package/.versions/2.2.0/.pi/harnesses/agent-hub/process-obligations.ts +210 -0
  485. package/.versions/2.2.0/.pi/harnesses/agent-hub/prompts/context.ts +72 -0
  486. package/.versions/2.2.0/.pi/harnesses/agent-hub/prompts/fragments.ts +94 -0
  487. package/.versions/2.2.0/.pi/harnesses/agent-hub/prompts/session-start.ts +89 -0
  488. package/.versions/2.2.0/.pi/harnesses/agent-hub/prompts/system-prompt.ts +142 -0
  489. package/.versions/2.2.0/.pi/harnesses/agent-hub/provider-semaphore.js +143 -0
  490. package/.versions/2.2.0/.pi/harnesses/agent-hub/reconcile.ts +26 -0
  491. package/.versions/2.2.0/.pi/harnesses/agent-hub/recover-policy.ts +44 -0
  492. package/.versions/2.2.0/.pi/harnesses/agent-hub/recover-state.ts +104 -0
  493. package/.versions/2.2.0/.pi/harnesses/agent-hub/recovery-contract.ts +151 -0
  494. package/.versions/2.2.0/.pi/harnesses/agent-hub/rerun-policy.ts +40 -0
  495. package/.versions/2.2.0/.pi/harnesses/agent-hub/research/controls.ts +74 -0
  496. package/.versions/2.2.0/.pi/harnesses/agent-hub/research/runtime.ts +215 -0
  497. package/.versions/2.2.0/.pi/harnesses/agent-hub/research/spawn-run.ts +221 -0
  498. package/.versions/2.2.0/.pi/harnesses/agent-hub/research-watchdog.ts +40 -0
  499. package/.versions/2.2.0/.pi/harnesses/agent-hub/return-contract.js +371 -0
  500. package/.versions/2.2.0/.pi/harnesses/agent-hub/return-extract.js +77 -0
  501. package/.versions/2.2.0/.pi/harnesses/agent-hub/review-closure.ts +43 -0
  502. package/.versions/2.2.0/.pi/harnesses/agent-hub/review-continuity.ts +76 -0
  503. package/.versions/2.2.0/.pi/harnesses/agent-hub/review-findings.js +96 -0
  504. package/.versions/2.2.0/.pi/harnesses/agent-hub/review-reuse.ts +48 -0
  505. package/.versions/2.2.0/.pi/harnesses/agent-hub/review-verdict.ts +6 -0
  506. package/.versions/2.2.0/.pi/harnesses/agent-hub/routing-observation.ts +41 -0
  507. package/.versions/2.2.0/.pi/harnesses/agent-hub/routing-proposal.ts +46 -0
  508. package/.versions/2.2.0/.pi/harnesses/agent-hub/run-budget.js +362 -0
  509. package/.versions/2.2.0/.pi/harnesses/agent-hub/run-namespace.js +93 -0
  510. package/.versions/2.2.0/.pi/harnesses/agent-hub/runtime-receipts.ts +63 -0
  511. package/.versions/2.2.0/.pi/harnesses/agent-hub/runtime-test-check.ts +85 -0
  512. package/.versions/2.2.0/.pi/harnesses/agent-hub/safety-routing.ts +28 -0
  513. package/.versions/2.2.0/.pi/harnesses/agent-hub/scope-gate.js +271 -0
  514. package/.versions/2.2.0/.pi/harnesses/agent-hub/scope-overlap.ts +46 -0
  515. package/.versions/2.2.0/.pi/harnesses/agent-hub/session-audit.ts +331 -0
  516. package/.versions/2.2.0/.pi/harnesses/agent-hub/session-health.js +110 -0
  517. package/.versions/2.2.0/.pi/harnesses/agent-hub/session-start.ts +42 -0
  518. package/.versions/2.2.0/.pi/harnesses/agent-hub/spawn.ts +702 -0
  519. package/.versions/2.2.0/.pi/harnesses/agent-hub/specialist-result-receipt.ts +13 -0
  520. package/.versions/2.2.0/.pi/harnesses/agent-hub/specialist-result.ts +78 -0
  521. package/.versions/2.2.0/.pi/harnesses/agent-hub/system1-activity.ts +625 -0
  522. package/.versions/2.2.0/.pi/harnesses/agent-hub/system1-communication-store.ts +225 -0
  523. package/.versions/2.2.0/.pi/harnesses/agent-hub/system1-report.ts +275 -0
  524. package/.versions/2.2.0/.pi/harnesses/agent-hub/system1-runtime.ts +271 -0
  525. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-brief.ts +98 -0
  526. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-continuation.ts +4 -0
  527. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-resume-contract.ts +80 -0
  528. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-authorization.ts +170 -0
  529. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-config.ts +21 -0
  530. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-contract.ts +14 -0
  531. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-live-stage-boundary.mjs +49 -0
  532. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-obligations.ts +120 -0
  533. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-policy.ts +16 -0
  534. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-review-contract.mjs +43 -0
  535. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-reviewer-only-contract.mjs +156 -0
  536. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-reviewer-only-diagnostics.mjs +112 -0
  537. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-runtime.ts +130 -0
  538. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-stage-guard.ts +21 -0
  539. package/.versions/2.2.0/.pi/harnesses/agent-hub/task-triage-state.ts +46 -0
  540. package/.versions/2.2.0/.pi/harnesses/agent-hub/timeline.ts +72 -0
  541. package/.versions/2.2.0/.pi/harnesses/agent-hub/tool-catalog-runtime.ts +83 -0
  542. package/.versions/2.2.0/.pi/harnesses/agent-hub/tool-catalog-state.ts +125 -0
  543. package/.versions/2.2.0/.pi/harnesses/agent-hub/tool-protocol.ts +134 -0
  544. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/action-executors.ts +214 -0
  545. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/ask-system1-files.ts +15 -0
  546. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/ask-system1.ts +25 -0
  547. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/coms-tools.ts +139 -0
  548. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/context.ts +149 -0
  549. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/dispatch-agent.ts +93 -0
  550. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/dispatch-execution.ts +928 -0
  551. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/dispatch-triage.ts +16 -0
  552. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/execution-orchestration.ts +22 -0
  553. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/fleet-tools.ts +201 -0
  554. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/herdr-executors.ts +100 -0
  555. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/poll-panel-core.ts +30 -0
  556. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/poll-panel.ts +33 -0
  557. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/run-flow.ts +177 -0
  558. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/set-task-tier.ts +31 -0
  559. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/spawn-research.ts +67 -0
  560. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/team-adjust.ts +29 -0
  561. package/.versions/2.2.0/.pi/harnesses/agent-hub/tools/verification-contract.ts +81 -0
  562. package/.versions/2.2.0/.pi/harnesses/agent-hub/tsconfig.json +22 -0
  563. package/.versions/2.2.0/.pi/harnesses/agent-hub/types.ts +66 -0
  564. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/activity-dots.ts +25 -0
  565. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/context-budget.ts +89 -0
  566. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/detail-panel.ts +192 -0
  567. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/fleet-actions.ts +78 -0
  568. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/fleet-dashboard.ts +173 -0
  569. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/fleet-editor.ts +44 -0
  570. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/fleet-source.ts +179 -0
  571. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/grid.ts +159 -0
  572. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/history-store.ts +137 -0
  573. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/history.ts +234 -0
  574. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/pool.ts +103 -0
  575. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/running-strip.ts +2 -0
  576. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/system1-communication.ts +59 -0
  577. package/.versions/2.2.0/.pi/harnesses/agent-hub/ui/zoom.ts +206 -0
  578. package/.versions/2.2.0/.pi/harnesses/agent-hub/unknown-tool-counter.ts +116 -0
  579. package/.versions/2.2.0/.pi/harnesses/agent-hub/version.ts +42 -0
  580. package/.versions/2.2.0/.pi/harnesses/agent-hub/watchdog-evaluation.ts +110 -0
  581. package/.versions/2.2.0/.pi/harnesses/agent-hub/work-mode.ts +183 -0
  582. package/.versions/2.2.0/.pi/harnesses/agent-hub/write-isolation.ts +232 -0
  583. package/.versions/2.2.0/.pi/harnesses/ask-user-remote/README.md +59 -0
  584. package/.versions/2.2.0/.pi/harnesses/ask-user-remote/index.ts +571 -0
  585. package/.versions/2.2.0/.pi/harnesses/ask-user-remote/questions.ts +206 -0
  586. package/.versions/2.2.0/.pi/harnesses/ask-user-remote/race-core.js +124 -0
  587. package/.versions/2.2.0/.pi/harnesses/ask-user-remote/runtime-ask.ts +90 -0
  588. package/.versions/2.2.0/.pi/harnesses/coms/README.md +105 -0
  589. package/.versions/2.2.0/.pi/harnesses/coms/index.ts +308 -0
  590. package/.versions/2.2.0/.pi/harnesses/coms/package.json +7 -0
  591. package/.versions/2.2.0/.pi/harnesses/coms/version.ts +42 -0
  592. package/.versions/2.2.0/.pi/harnesses/damage-control-continue/README.md +161 -0
  593. package/.versions/2.2.0/.pi/harnesses/damage-control-continue/index.ts +659 -0
  594. package/.versions/2.2.0/.pi/harnesses/damage-control-continue/package.json +7 -0
  595. package/.versions/2.2.0/.pi/harnesses/damage-control-continue/result-screen.ts +98 -0
  596. package/.versions/2.2.0/.pi/harnesses/damage-control-continue/system1-child.ts +45 -0
  597. package/.versions/2.2.0/.pi/harnesses/damage-control-continue/system1-client.ts +85 -0
  598. package/.versions/2.2.0/.pi/harnesses/damage-control-continue/system1-guard.ts +65 -0
  599. package/.versions/2.2.0/.pi/harnesses/damage-control-continue/version.ts +42 -0
  600. package/.versions/2.2.0/.pi/harnesses/lib/approval-wait.ts +17 -0
  601. package/.versions/2.2.0/.pi/harnesses/lib/bash-policy-analysis.ts +185 -0
  602. package/.versions/2.2.0/.pi/harnesses/lib/changed-file-diagnostics.ts +642 -0
  603. package/.versions/2.2.0/.pi/harnesses/lib/clarification-policy.ts +9 -0
  604. package/.versions/2.2.0/.pi/harnesses/lib/codex-compat.ts +97 -0
  605. package/.versions/2.2.0/.pi/harnesses/lib/codex-contract.ts +259 -0
  606. package/.versions/2.2.0/.pi/harnesses/lib/codex-notification-profile.ts +75 -0
  607. package/.versions/2.2.0/.pi/harnesses/lib/coms-core-io.ts +422 -0
  608. package/.versions/2.2.0/.pi/harnesses/lib/coms-core.ts +738 -0
  609. package/.versions/2.2.0/.pi/harnesses/lib/coms-instruction-receipts.ts +113 -0
  610. package/.versions/2.2.0/.pi/harnesses/lib/coms-observation.ts +74 -0
  611. package/.versions/2.2.0/.pi/harnesses/lib/coms-registry-entry.ts +99 -0
  612. package/.versions/2.2.0/.pi/harnesses/lib/coms-response-read.ts +107 -0
  613. package/.versions/2.2.0/.pi/harnesses/lib/context-budget-child-prompt.ts +214 -0
  614. package/.versions/2.2.0/.pi/harnesses/lib/context-budget-hub-prompt.ts +124 -0
  615. package/.versions/2.2.0/.pi/harnesses/lib/context-budget-view.ts +112 -0
  616. package/.versions/2.2.0/.pi/harnesses/lib/context-budget.ts +114 -0
  617. package/.versions/2.2.0/.pi/harnesses/lib/context-compaction-policy.js +35 -0
  618. package/.versions/2.2.0/.pi/harnesses/lib/damage-action-hash.ts +28 -0
  619. package/.versions/2.2.0/.pi/harnesses/lib/damage-auto-policy.ts +52 -0
  620. package/.versions/2.2.0/.pi/harnesses/lib/damage-control-presentation.ts +14 -0
  621. package/.versions/2.2.0/.pi/harnesses/lib/damage-control-shared.ts +276 -0
  622. package/.versions/2.2.0/.pi/harnesses/lib/damage-guard-port.ts +25 -0
  623. package/.versions/2.2.0/.pi/harnesses/lib/damage-policy.ts +35 -0
  624. package/.versions/2.2.0/.pi/harnesses/lib/damage-result-evidence.ts +25 -0
  625. package/.versions/2.2.0/.pi/harnesses/lib/damage-result-view.ts +16 -0
  626. package/.versions/2.2.0/.pi/harnesses/lib/deterministic-handle-path.ts +25 -0
  627. package/.versions/2.2.0/.pi/harnesses/lib/exact-permission-port.ts +38 -0
  628. package/.versions/2.2.0/.pi/harnesses/lib/execution-trace.ts +45 -0
  629. package/.versions/2.2.0/.pi/harnesses/lib/fixtures/context-budget-profiles.json +11 -0
  630. package/.versions/2.2.0/.pi/harnesses/lib/fixtures/hub-prompt-operator.legacy.txt +73 -0
  631. package/.versions/2.2.0/.pi/harnesses/lib/fixtures/hub-prompt-orchestrator.legacy.txt +73 -0
  632. package/.versions/2.2.0/.pi/harnesses/lib/fleet-bootstrap-channel.ts +148 -0
  633. package/.versions/2.2.0/.pi/harnesses/lib/fleet-codex-catalog.ts +30 -0
  634. package/.versions/2.2.0/.pi/harnesses/lib/fleet-codex-chat-view.ts +43 -0
  635. package/.versions/2.2.0/.pi/harnesses/lib/fleet-codex-event-bridge.ts +82 -0
  636. package/.versions/2.2.0/.pi/harnesses/lib/fleet-codex-namespace.ts +2 -0
  637. package/.versions/2.2.0/.pi/harnesses/lib/fleet-codex-policy-snapshot.ts +10 -0
  638. package/.versions/2.2.0/.pi/harnesses/lib/fleet-config/cli-bridge.ts +111 -0
  639. package/.versions/2.2.0/.pi/harnesses/lib/fleet-config/mutations.ts +201 -0
  640. package/.versions/2.2.0/.pi/harnesses/lib/fleet-config/snapshot.ts +417 -0
  641. package/.versions/2.2.0/.pi/harnesses/lib/fleet-config/transition.ts +68 -0
  642. package/.versions/2.2.0/.pi/harnesses/lib/fleet-config/ui.ts +269 -0
  643. package/.versions/2.2.0/.pi/harnesses/lib/fleet-config/view.ts +338 -0
  644. package/.versions/2.2.0/.pi/harnesses/lib/fleet-connection-control.ts +94 -0
  645. package/.versions/2.2.0/.pi/harnesses/lib/fleet-dashboard-ops.ts +178 -0
  646. package/.versions/2.2.0/.pi/harnesses/lib/fleet-dashboard-view.ts +174 -0
  647. package/.versions/2.2.0/.pi/harnesses/lib/fleet-detail-view.ts +339 -0
  648. package/.versions/2.2.0/.pi/harnesses/lib/fleet-event-source.ts +21 -0
  649. package/.versions/2.2.0/.pi/harnesses/lib/fleet-notification-admission.ts +32 -0
  650. package/.versions/2.2.0/.pi/harnesses/lib/fleet-notification-bootstrap.ts +152 -0
  651. package/.versions/2.2.0/.pi/harnesses/lib/fleet-notification-validation.ts +122 -0
  652. package/.versions/2.2.0/.pi/harnesses/lib/fleet-overlay.ts +26 -0
  653. package/.versions/2.2.0/.pi/harnesses/lib/fleet-panel.ts +34 -0
  654. package/.versions/2.2.0/.pi/harnesses/lib/fleet-question-reference.ts +42 -0
  655. package/.versions/2.2.0/.pi/harnesses/lib/fleet-read-model.ts +609 -0
  656. package/.versions/2.2.0/.pi/harnesses/lib/fleet-selection.ts +24 -0
  657. package/.versions/2.2.0/.pi/harnesses/lib/fleet-strip-controller.ts +75 -0
  658. package/.versions/2.2.0/.pi/harnesses/lib/fleet-strip-view.ts +179 -0
  659. package/.versions/2.2.0/.pi/harnesses/lib/fleet-target-identity.ts +9 -0
  660. package/.versions/2.2.0/.pi/harnesses/lib/fleet-transcript-store.ts +244 -0
  661. package/.versions/2.2.0/.pi/harnesses/lib/herdr-client.ts +472 -0
  662. package/.versions/2.2.0/.pi/harnesses/lib/herdr-presence.ts +399 -0
  663. package/.versions/2.2.0/.pi/harnesses/lib/hermes-monitor-events.ts +136 -0
  664. package/.versions/2.2.0/.pi/harnesses/lib/hermes-monitor-herdr.ts +28 -0
  665. package/.versions/2.2.0/.pi/harnesses/lib/hermes-monitor-model.ts +18 -0
  666. package/.versions/2.2.0/.pi/harnesses/lib/hermes-monitor-registry.ts +6 -0
  667. package/.versions/2.2.0/.pi/harnesses/lib/hermes-monitor-socket.ts +163 -0
  668. package/.versions/2.2.0/.pi/harnesses/lib/hermes-monitor-store.ts +31 -0
  669. package/.versions/2.2.0/.pi/harnesses/lib/identical-dialog.ts +27 -0
  670. package/.versions/2.2.0/.pi/harnesses/lib/installation-state.js +62 -0
  671. package/.versions/2.2.0/.pi/harnesses/lib/peer-target.ts +24 -0
  672. package/.versions/2.2.0/.pi/harnesses/lib/policy-roots.js +117 -0
  673. package/.versions/2.2.0/.pi/harnesses/lib/policy-roots.ts +32 -0
  674. package/.versions/2.2.0/.pi/harnesses/lib/process-shared.ts +9 -0
  675. package/.versions/2.2.0/.pi/harnesses/lib/resource-closure.js +26 -0
  676. package/.versions/2.2.0/.pi/harnesses/lib/safe-source-read.js +29 -0
  677. package/.versions/2.2.0/.pi/harnesses/lib/semantic-approval.ts +80 -0
  678. package/.versions/2.2.0/.pi/harnesses/lib/session-target.ts +62 -0
  679. package/.versions/2.2.0/.pi/harnesses/lib/spawned-peers.js +191 -0
  680. package/.versions/2.2.0/.pi/harnesses/lib/system1/config-agentic.js +15 -0
  681. package/.versions/2.2.0/.pi/harnesses/lib/system1/config-context-compaction.js +16 -0
  682. package/.versions/2.2.0/.pi/harnesses/lib/system1/config-damage-guard.js +24 -0
  683. package/.versions/2.2.0/.pi/harnesses/lib/system1/config-file-discovery.js +23 -0
  684. package/.versions/2.2.0/.pi/harnesses/lib/system1/config-json.js +37 -0
  685. package/.versions/2.2.0/.pi/harnesses/lib/system1/config-loader.js +53 -0
  686. package/.versions/2.2.0/.pi/harnesses/lib/system1/config-proactive.js +68 -0
  687. package/.versions/2.2.0/.pi/harnesses/lib/system1/config-triage.js +42 -0
  688. package/.versions/2.2.0/.pi/harnesses/lib/system1/config-v2.js +112 -0
  689. package/.versions/2.2.0/.pi/harnesses/lib/system1/config.js +50 -0
  690. package/.versions/2.2.0/.pi/harnesses/lib/system1/contracts.ts +154 -0
  691. package/.versions/2.2.0/.pi/harnesses/lib/system1/demo.ts +95 -0
  692. package/.versions/2.2.0/.pi/harnesses/lib/system1/jev.ts +503 -0
  693. package/.versions/2.2.0/.pi/harnesses/lib/system1/payload-screen.ts +65 -0
  694. package/.versions/2.2.0/.pi/harnesses/lib/system1/selection.js +11 -0
  695. package/.versions/2.2.0/.pi/harnesses/lib/system1/service.ts +245 -0
  696. package/.versions/2.2.0/.pi/harnesses/lib/system1/worktree-scopes.js +110 -0
  697. package/.versions/2.2.0/.pi/harnesses/lib/system1/worktree-scopes.ts +13 -0
  698. package/.versions/2.2.0/.pi/harnesses/lib/system1/worktree-service.ts +24 -0
  699. package/.versions/2.2.0/.pi/harnesses/lib/target-capabilities.js +7 -0
  700. package/.versions/2.2.0/.pi/harnesses/lib/update-check.ts +227 -0
  701. package/.versions/2.2.0/.pi/harnesses/lib/workspace-context.js +115 -0
  702. package/.versions/2.2.0/.pi/harnesses/lib/workspace-context.ts +22 -0
  703. package/.versions/2.2.0/.pi/harnesses/package-lock.json +2121 -0
  704. package/.versions/2.2.0/.pi/harnesses/package.json +13 -0
  705. package/.versions/2.2.0/.pi/prompts/af-build.md +27 -0
  706. package/.versions/2.2.0/.pi/prompts/af-code-simplify.md +22 -0
  707. package/.versions/2.2.0/.pi/prompts/af-constraints.md +31 -0
  708. package/.versions/2.2.0/.pi/prompts/af-plan.md +17 -0
  709. package/.versions/2.2.0/.pi/prompts/af-review.md +16 -0
  710. package/.versions/2.2.0/.pi/prompts/af-set-hermes-telegram.md +15 -0
  711. package/.versions/2.2.0/.pi/prompts/af-set-hermes-watchdog.md +6 -0
  712. package/.versions/2.2.0/.pi/prompts/af-setup-rules.md +20 -0
  713. package/.versions/2.2.0/.pi/prompts/af-ship.md +17 -0
  714. package/.versions/2.2.0/.pi/prompts/af-spec.md +15 -0
  715. package/.versions/2.2.0/.pi/prompts/af-test.md +19 -0
  716. package/.versions/2.2.0/.pi/skills/bowser/SKILL.md +145 -0
  717. package/.versions/2.2.0/.version +1 -0
  718. package/.versions/2.2.0/agents/architect.md +24 -0
  719. package/.versions/2.2.0/agents/bowser.md +28 -0
  720. package/.versions/2.2.0/agents/builder.md +55 -0
  721. package/.versions/2.2.0/agents/code-reviewer.md +209 -0
  722. package/.versions/2.2.0/agents/deep-researcher.md +32 -0
  723. package/.versions/2.2.0/agents/documenter.md +22 -0
  724. package/.versions/2.2.0/agents/plan-reviewer.md +83 -0
  725. package/.versions/2.2.0/agents/planner.md +107 -0
  726. package/.versions/2.2.0/agents/releaser.md +24 -0
  727. package/.versions/2.2.0/agents/researcher.md +30 -0
  728. package/.versions/2.2.0/agents/security-auditor.md +167 -0
  729. package/.versions/2.2.0/agents/test-engineer.md +153 -0
  730. package/.versions/2.2.0/agents/web-debugger.md +44 -0
  731. package/.versions/2.2.0/agents/web-performance-auditor.md +194 -0
  732. package/.versions/2.2.0/bin/catalog/harness-runtime-closure.json +85 -0
  733. package/.versions/2.2.0/docs/ARCHITECTURE.md +1291 -0
  734. package/.versions/2.2.0/docs/agent-fleet-setup.md +1161 -0
  735. package/.versions/2.2.0/docs/claude-code-coms-bridge.md +147 -0
  736. package/.versions/2.2.0/docs/codex-local-mcp.md +520 -0
  737. package/.versions/2.2.0/docs/codex-session-bridge.md +44 -0
  738. package/.versions/2.2.0/docs/codex-setup.md +183 -0
  739. package/.versions/2.2.0/docs/coms-hermes-bridge.md +188 -0
  740. package/.versions/2.2.0/docs/fleet-native-voice.md +151 -0
  741. package/.versions/2.2.0/docs/getting-started.md +126 -0
  742. package/.versions/2.2.0/docs/npm-install.md +535 -0
  743. package/.versions/2.2.0/docs/pi-extensions.md +450 -0
  744. package/.versions/2.2.0/docs/pi-setup.md +92 -0
  745. package/.versions/2.2.0/docs/skill-anatomy.md +150 -0
  746. package/.versions/2.2.0/install-manifest.json +3226 -0
  747. package/.versions/2.2.0/justfile +246 -0
  748. package/.versions/2.2.0/manifest-meta.json +1098 -0
  749. package/.versions/2.2.0/references/accessibility-checklist.md +160 -0
  750. package/.versions/2.2.0/references/communication-contract.md +26 -0
  751. package/.versions/2.2.0/references/definition-of-done.md +67 -0
  752. package/.versions/2.2.0/references/fleet-coordination-patterns.md +171 -0
  753. package/.versions/2.2.0/references/observability-checklist.md +92 -0
  754. package/.versions/2.2.0/references/orchestration-patterns.md +370 -0
  755. package/.versions/2.2.0/references/performance-checklist.md +236 -0
  756. package/.versions/2.2.0/references/prompting-patterns.md +380 -0
  757. package/.versions/2.2.0/references/security-checklist.md +245 -0
  758. package/.versions/2.2.0/references/testing-patterns.md +235 -0
  759. package/.versions/2.2.0/references/workflow-authoring.md +304 -0
  760. package/.versions/2.2.0/skills/_internal/grilling.md +59 -0
  761. package/.versions/2.2.0/skills/browser-testing-with-devtools/SKILL.md +351 -0
  762. package/.versions/2.2.0/skills/code-review-and-quality/SKILL.md +396 -0
  763. package/.versions/2.2.0/skills/compound-learning/SKILL.md +137 -0
  764. package/.versions/2.2.0/skills/constraint-driven-development/SKILL.md +338 -0
  765. package/.versions/2.2.0/skills/constraint-driven-development/references/floor-guard.md +99 -0
  766. package/.versions/2.2.0/skills/context-engineering/SKILL.md +341 -0
  767. package/.versions/2.2.0/skills/deprecation-and-migration/SKILL.md +247 -0
  768. package/.versions/2.2.0/skills/designing-agents/SKILL.md +394 -0
  769. package/.versions/2.2.0/skills/designing-agents/pi-harness-authoring.md +222 -0
  770. package/.versions/2.2.0/skills/drafting-workflows/SKILL.md +143 -0
  771. package/.versions/2.2.0/skills/drafting-workflows/scripts/make-workflow.ts +177 -0
  772. package/.versions/2.2.0/skills/fleet-connect/SKILL.md +29 -0
  773. package/.versions/2.2.0/skills/fleet-connect.zip +0 -0
  774. package/.versions/2.2.0/skills/fleet-native-voice/SKILL.md +103 -0
  775. package/.versions/2.2.0/skills/fleet-native-voice/agents/openai.yaml +4 -0
  776. package/.versions/2.2.0/skills/fleet-native-voice.zip +0 -0
  777. package/.versions/2.2.0/skills/frontend-ui-engineering/SKILL.md +328 -0
  778. package/.versions/2.2.0/skills/git-workflow-and-versioning/SKILL.md +316 -0
  779. package/.versions/2.2.0/skills/idea-refine/SKILL.md +182 -0
  780. package/.versions/2.2.0/skills/idea-refine/examples.md +238 -0
  781. package/.versions/2.2.0/skills/idea-refine/frameworks.md +99 -0
  782. package/.versions/2.2.0/skills/idea-refine/refinement-criteria.md +113 -0
  783. package/.versions/2.2.0/skills/idea-refine/scripts/idea-refine.sh +15 -0
  784. package/.versions/2.2.0/skills/incremental-implementation/SKILL.md +353 -0
  785. package/.versions/2.2.0/skills/incremental-implementation.zip +0 -0
  786. package/.versions/2.2.0/skills/interview-me/SKILL.md +226 -0
  787. package/.versions/2.2.0/skills/orchestration-verification/SKILL.md +182 -0
  788. package/.versions/2.2.0/skills/peer-coms/SKILL.md +90 -0
  789. package/.versions/2.2.0/skills/performance-optimization/SKILL.md +496 -0
  790. package/.versions/2.2.0/skills/planning-and-task-breakdown/SKILL.md +318 -0
  791. package/.versions/2.2.0/skills/planning-and-task-breakdown.zip +0 -0
  792. package/.versions/2.2.0/skills/repository-ai-setup/SKILL.md +135 -0
  793. package/.versions/2.2.0/skills/repository-ai-setup/references/agent-fleet-ai-state.template.json +4 -0
  794. package/.versions/2.2.0/skills/repository-ai-setup/references/apply-contract.md +74 -0
  795. package/.versions/2.2.0/skills/repository-ai-setup/references/provenance-template.md +16 -0
  796. package/.versions/2.2.0/skills/repository-ai-setup/references/setup-flow.md +108 -0
  797. package/.versions/2.2.0/skills/repository-ai-setup/references/verify-setup.md +20 -0
  798. package/.versions/2.2.0/skills/repository-ai-setup.zip +0 -0
  799. package/.versions/2.2.0/skills/security-and-hardening/SKILL.md +524 -0
  800. package/.versions/2.2.0/skills/spec-driven-development/SKILL.md +295 -0
  801. package/.versions/2.2.0/skills/spec-driven-development.zip +0 -0
  802. package/.versions/2.2.0/skills/using-agent-skills/SKILL.md +198 -0
  803. package/.versions/2.2.0/vendor/agent-skills-upstream/LICENSE +21 -0
  804. package/.versions/2.2.0/vendor/agent-skills-upstream/README.md +430 -0
  805. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/api-and-interface-design/SKILL.md +367 -0
  806. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/browser-testing-with-devtools/SKILL.md +317 -0
  807. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/ci-cd-and-automation/SKILL.md +390 -0
  808. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/code-review-and-quality/SKILL.md +396 -0
  809. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/code-simplification/SKILL.md +331 -0
  810. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/constraint-driven-development/SKILL.md +311 -0
  811. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/constraint-driven-development/references/floor-guard.md +99 -0
  812. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/context-engineering/SKILL.md +337 -0
  813. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/debugging-and-error-recovery/SKILL.md +300 -0
  814. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/deprecation-and-migration/SKILL.md +247 -0
  815. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/documentation-and-adrs/SKILL.md +288 -0
  816. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/doubt-driven-development/SKILL.md +243 -0
  817. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/frontend-ui-engineering/SKILL.md +328 -0
  818. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/git-workflow-and-versioning/SKILL.md +355 -0
  819. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/idea-refine/SKILL.md +178 -0
  820. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/idea-refine/examples.md +238 -0
  821. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/idea-refine/frameworks.md +99 -0
  822. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/idea-refine/refinement-criteria.md +113 -0
  823. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/idea-refine/scripts/idea-refine.sh +15 -0
  824. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/incremental-implementation/SKILL.md +249 -0
  825. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/interview-me/SKILL.md +225 -0
  826. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/observability-and-instrumentation/SKILL.md +238 -0
  827. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/performance-optimization/SKILL.md +496 -0
  828. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/planning-and-task-breakdown/SKILL.md +257 -0
  829. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/security-and-hardening/SKILL.md +524 -0
  830. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/shipping-and-launch/SKILL.md +330 -0
  831. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/source-driven-development/SKILL.md +216 -0
  832. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/spec-driven-development/SKILL.md +245 -0
  833. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/test-driven-development/SKILL.md +398 -0
  834. package/.versions/2.2.0/vendor/agent-skills-upstream/skills/using-agent-skills/SKILL.md +192 -0
  835. package/CHANGELOG.md +33 -0
  836. package/README.md +7 -10
  837. package/bin/lib/set-codex-mcp.js +1 -1
  838. package/bin/lib/validate-overrides.js +8 -1
  839. package/docs/ARCHITECTURE.md +122 -26
  840. package/docs/MIGRATION-agent-fleet.md +26 -5
  841. package/docs/agent-fleet-setup.md +44 -26
  842. package/docs/claude-code-coms-bridge.md +1 -1
  843. package/docs/codex-local-mcp.md +29 -12
  844. package/docs/codex-session-bridge.md +2 -2
  845. package/docs/codex-setup.md +1 -1
  846. package/docs/fleet-native-voice.md +10 -4
  847. package/docs/npm-install.md +1 -1
  848. package/docs/pi-extensions.md +13 -18
  849. package/docs/system1-agentic.md +1 -1
  850. package/docs/system1-file-discovery.md +2 -2
  851. package/docs/workflows.md +24 -1
  852. package/install-manifest.json +15 -28
  853. package/justfile +3 -4
  854. package/manifest-meta.json +13 -2
  855. package/package.json +4 -2
  856. package/skills/fleet-connect/SKILL.md +20 -16
  857. package/skills/fleet-connect.zip +0 -0
  858. package/skills/fleet-native-voice.zip +0 -0
  859. package/.pi/harnesses/agent-hub/commands/work-mode.ts +0 -29
  860. package/.pi/harnesses/agent-hub/work-mode-controls.ts +0 -56
  861. package/agents/orchestrator.md +0 -22
@@ -0,0 +1,73 @@
1
+ // S6b shared pure wire contract + bounded explicit-root transport. Import has no I/O.
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import {validOpaqueToolCallId} from '../../../harnesses/lib/fleet-question-reference.ts';
4
+ import { lstat } from 'node:fs/promises';
5
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
6
+ import { createConnection } from 'node:net';
7
+ import { validInstructionTarget, targetKey, type QuestionReceipt, type QuestionOutcome } from './fleet-codex-instruction-store.ts';
8
+ import type { TargetEpoch } from './fleet-codex-allowlist.ts';
9
+ export const questionCapability = {name:'fleet_question_actions',version:2,expectedToolCallId:true,firstWinner:'pi_question_latch',receipt:'volatile_bounded'} as const;
10
+ export const object = (v:unknown):v is Record<string,unknown>=>!!v&&typeof v==='object'&&!Array.isArray(v);
11
+ export const exact = (v:unknown, required:string[], optional:string[]=[]):v is Record<string,unknown>=>object(v)&&required.every(k=>Object.hasOwn(v,k))&&Object.keys(v).every(k=>required.includes(k)||optional.includes(k));
12
+ export const validId=(v:unknown):v is string=>typeof v==='string'&&/^[A-Za-z0-9][A-Za-z0-9._-]{0,95}$/.test(v);
13
+ export const validHash=(v:unknown):v is string=>typeof v==='string'&&/^[a-f0-9]{64}$/.test(v);
14
+ const date=(v:unknown):v is string=>typeof v==='string'&&v.length<=40&&Number.isFinite(Date.parse(v));
15
+ const clean=(v:unknown,max=16000):v is string=>typeof v==='string'&&v.trim().length>0&&Buffer.byteLength(v)<=max&&!/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/u.test(v);
16
+ export const validToolCall=validOpaqueToolCallId;
17
+ export type HumanResponse = {kind:'freeform';text:string}|{kind:'selection';selections:string[];comment?:string}|null;
18
+ export type QuestionSnapshot={id:string;toolCallId:string;owner:TargetEpoch;question:string;context?:string;options:{title:string;description?:string}[];allowMultiple:boolean;allowFreeform:boolean;allowComment:boolean;createdAt:string;expiresAt:null;state:string};
19
+ export function validSnapshot(v:unknown):v is QuestionSnapshot {
20
+ if(!exact(v,['id','toolCallId','owner','question','options','allowMultiple','allowFreeform','allowComment','createdAt','expiresAt','state'],['context'])||!validId(v.id)||!validToolCall(v.toolCallId)||!validInstructionTarget(v.owner)||!clean(v.question)||v.context!==undefined&&!clean(v.context)||!Array.isArray(v.options)||v.options.length>64||!['allowMultiple','allowFreeform','allowComment'].every(k=>typeof v[k]==='boolean')||!date(v.createdAt)||v.expiresAt!==null||!['pending','answered','cancelled','expired','failed'].includes(v.state as string))return false;
21
+ if(!v.options.every(o=>exact(o,['title'],['description'])&&clean(o.title)&& (o.description===undefined||clean(o.description))))return false;
22
+ return new Set(v.options.map(o=>o.title)).size===v.options.length&&Buffer.byteLength(JSON.stringify(v))<=16000;
23
+ }
24
+ const sha=(v:unknown)=>createHash('sha256').update(JSON.stringify(v)).digest('hex');
25
+ export function questionDigest(q:QuestionSnapshot):string{return sha(['fleet-question-v2',targetKey(q.owner),q.id,q.toolCallId,q.question,q.context??null,q.options.map(o=>[o.title,o.description??null]),q.allowMultiple,q.allowFreeform,q.allowComment,q.createdAt,q.expiresAt]);}
26
+ export function normalizeAnswer(input:unknown):HumanResponse {
27
+ if(input===null)return null;
28
+ if(Buffer.byteLength(JSON.stringify(input)??'')>16000)throw Error('INVALID_ARGUMENTS');
29
+ if(exact(input,['kind','text'])&&input.kind==='freeform'&&clean(input.text))return {kind:'freeform',text:input.text.trim()};
30
+ if(!exact(input,['kind','selections'],['comment'])||input.kind!=='selection'||!Array.isArray(input.selections)||!input.selections.length||input.selections.length>64||!input.selections.every(v=>clean(v))||new Set(input.selections).size!==input.selections.length||input.comment!==undefined&&typeof input.comment!=='string'||typeof input.comment==='string'&&input.comment.trim()&&!clean(input.comment))throw Error('INVALID_ARGUMENTS');
31
+ return {kind:'selection',selections:[...input.selections] as string[],...(typeof input.comment==='string'&&input.comment.trim()?{comment:input.comment.trim()}:{})};
32
+ }
33
+ export function validateQuestionAnswer(q:QuestionSnapshot,a:HumanResponse):boolean {
34
+ if(a===null)return true;
35
+ return a.kind==='freeform'?q.allowFreeform:(!a.comment||q.allowComment)&&(q.allowMultiple||a.selections.length===1)&&a.selections.every(t=>q.options.some(o=>o.title===t));
36
+ }
37
+ export function answerDigest(operation:'answer'|'refusal',owner:TargetEpoch,qid:string,toolCallId:string,qDigest:string,response:unknown):string {
38
+ const a=normalizeAnswer(response),canonical=a===null?null:a.kind==='freeform'?['freeform',a.text]:['selection',a.selections,a.comment??null];
39
+ return sha(['fleet-human-action-v2',operation,targetKey(owner),qid,toolCallId,qDigest,canonical]);
40
+ }
41
+ export type QuestionBinding={questionId:string;toolCallId:string;questionDigest:string;actionDigest:string;wireId:string;operation:'answer'|'refusal'};
42
+ export function validBinding(v:Record<string,unknown>):boolean{return validId(v.questionId)&&validToolCall(v.toolCallId)&&validHash(v.questionDigest)&&validHash(v.actionDigest)&&validHash(v.wireId);}
43
+ export class AnswerTransportError extends Error {readonly code:string;constructor(code:string){super(code);this.code=code;}}
44
+ function fail(code:string):never{throw new AnswerTransportError(code);}
45
+ export class AnswerTransport {
46
+ readonly #root:string;readonly #timeout:number;
47
+ constructor(options:{registryRoot:string;timeoutMs?:number}){if(!isAbsolute(options.registryRoot)||resolve(options.registryRoot)!==options.registryRoot)fail('UNSAFE_PATH');this.#root=options.registryRoot;this.#timeout=options.timeoutMs??1500;if(!Number.isInteger(this.#timeout)||this.#timeout<1||this.#timeout>1500)fail('INVALID_TRANSPORT_OPTIONS');}
48
+ async #endpoint(t:TargetEpoch){if(!validInstructionTarget(t))fail('INVALID_TARGET');for(let p=this.#root;;p=dirname(p)){const s=await lstat(p);if(s.isSymbolicLink()||!s.isDirectory())fail('UNSAFE_PATH');if(p===dirname(p))break;}const dir=await lstat(join(this.#root,'sockets'));if(!dir.isDirectory()||dir.isSymbolicLink())fail('UNSAFE_PATH');const path=join(this.#root,'sockets',t.sessionId+'.sock'),s=await lstat(path);if(!s.isSocket()||s.isSymbolicLink()||process.getuid&&s.uid!==process.getuid())fail('UNSAFE_PATH');return{path,dev:s.dev,ino:s.ino};}
49
+ async #rpc(t:TargetEpoch,fields:Record<string,unknown>,beforeWrite?:()=>Promise<void>,signal?:AbortSignal):Promise<Record<string,unknown>>{
50
+ const ep=await this.#endpoint(t),msg_id=typeof fields.msg_id==='string'?fields.msg_id:randomUUID();
51
+ const envelope={type:'question_request',version:2,msg_id,owner:t,...fields,sender_session:'local-codex-answer',sender_endpoint:'',hops:0,timestamp:new Date().toISOString()},frame=JSON.stringify(envelope)+'\n';if(Buffer.byteLength(frame)>32768)fail('FRAME_TOO_LARGE');
52
+ return new Promise((yes,no)=>{let done=false,b=Buffer.alloc(0);const socket=createConnection(ep.path);const finish=(error?:unknown,r?:Record<string,unknown>)=>{if(done)return;done=true;clearTimeout(timer);signal?.removeEventListener('abort',abort);socket.destroy();error?no(error):yes(r!);};const abort=()=>finish(new AnswerTransportError('CANCELLED'));const timer=setTimeout(()=>finish(new AnswerTransportError('RPC_TIMEOUT')),this.#timeout);signal?.addEventListener('abort',abort,{once:true});if(signal?.aborted){abort();return;}
53
+ socket.once('connect',()=>{void(async()=>{try{const now=await this.#endpoint(t);if(now.dev!==ep.dev||now.ino!==ep.ino)fail('TARGET_CHANGED');if(done||signal?.aborted)return;await beforeWrite?.();if(!done&&!signal?.aborted)socket.write(frame);}catch(e){finish(e);}})();});
54
+ socket.on('data',(chunk:Buffer)=>{if(b.length+chunk.length>32768){finish(new AnswerTransportError('RPC_INVALID'));return;}b=Buffer.concat([b,chunk]);const end=b.indexOf(10);if(end<0)return;try{const r:unknown=JSON.parse(new TextDecoder('utf-8',{fatal:true}).decode(b.subarray(0,end)));if(!object(r)||r.type!=='question_response'||r.version!==2||r.msg_id!==msg_id||!validInstructionTarget(r.owner)||targetKey(r.owner)!==targetKey(t))fail('RPC_INVALID');finish(undefined,r);}catch(e){finish(e);}});socket.once('error',()=>finish(new AnswerTransportError('RPC_UNAVAILABLE')));socket.once('close',()=>finish(new AnswerTransportError('RPC_UNAVAILABLE')));
55
+ });
56
+ }
57
+ async inspect(t:TargetEpoch,qid:string,toolCallId:string,signal?:AbortSignal):Promise<QuestionSnapshot>{
58
+ if(!validId(qid)||!validToolCall(toolCallId))fail('INVALID_ARGUMENTS');const r=await this.#rpc(t,{operation:'inspect',questionId:qid,toolCallId},undefined,signal);
59
+ if(!exact(r,['type','version','msg_id','owner','questionId','toolCallId','questionDigest','actionDigest','wireId','status','ready','capability','question'])||r.status!=='pending'||r.ready!==true||!exact(r.capability,Object.keys(questionCapability))||!Object.entries(questionCapability).every(([k,v])=>(r.capability as Record<string,unknown>)[k]===v)||r.questionId!==qid||r.toolCallId!==toolCallId||r.actionDigest!==null||r.wireId!==null||!validSnapshot(r.question)||r.question.state!=='pending'||targetKey(r.question.owner)!==targetKey(t)||r.question.id!==qid||r.question.toolCallId!==toolCallId||r.questionDigest!==questionDigest(r.question))fail('ANSWER_UNSUPPORTED');return r.question;
60
+ }
61
+ #outcome(r:Record<string,unknown>,binding:QuestionBinding):QuestionOutcome|null{
62
+ if(!exact(r,['type','version','msg_id','owner','questionId','toolCallId','questionDigest','actionDigest','wireId','status'],r.status==='unknown'?[]:['outcome','decisionAt'])||r.questionId!==binding.questionId||r.toolCallId!==binding.toolCallId||r.questionDigest!==binding.questionDigest||r.actionDigest!==binding.actionDigest||r.wireId!==binding.wireId)fail('RECEIPT_INVALID');if(r.status==='unknown')return null;
63
+ if(!['accepted','late','expired','rejected'].includes(r.status as string)||!date(r.decisionAt)||r.outcome!==(r.status==='accepted'?(binding.operation==='answer'?'answered':'declined'):r.status))fail('RECEIPT_INVALID');
64
+ return {state:r.status as QuestionReceipt['state'],detail:null,result:{outcome:r.outcome as NonNullable<QuestionReceipt['result']>['outcome'],decisionAt:r.decisionAt,observedAt:new Date().toISOString(),source:'pi_question_rpc_v2'}};
65
+ }
66
+ async send(t:TargetEpoch,binding:QuestionBinding,response:HumanResponse,options:{beforeWrite:()=>Promise<void>;signal?:AbortSignal}):Promise<QuestionOutcome>{
67
+ if(!validInstructionTarget(t)||!exact(binding,['questionId','toolCallId','questionDigest','actionDigest','wireId','operation'])||!validBinding(binding)||!['answer','refusal'].includes(binding.operation)||(binding.operation==='refusal')!==(response===null)||answerDigest(binding.operation,t,binding.questionId,binding.toolCallId,binding.questionDigest,response)!==binding.actionDigest)fail('INVALID_ARGUMENTS');
68
+ // Read-only inspect precedes the only mutation. A downgrade never triggers v1 fallback.
69
+ const q=await this.inspect(t,binding.questionId,binding.toolCallId,options.signal);if(questionDigest(q)!==binding.questionDigest||!validateQuestionAnswer(q,response)||answerDigest(binding.operation,t,binding.questionId,binding.toolCallId,binding.questionDigest,response)!==binding.actionDigest)fail('QUESTION_CHANGED');
70
+ const r=await this.#rpc(t,{...binding,operation:binding.operation,response,msg_id:binding.wireId},options.beforeWrite,options.signal);return this.#outcome(r,binding)??{state:'unknown',detail:'OUTCOME_UNAVAILABLE',result:null};
71
+ }
72
+ async receipt(t:TargetEpoch,binding:QuestionBinding,signal?:AbortSignal):Promise<QuestionOutcome|null>{if(!validInstructionTarget(t)||!exact(binding,['questionId','toolCallId','questionDigest','actionDigest','wireId','operation'])||!validBinding(binding)||!['answer','refusal'].includes(binding.operation))fail('INVALID_ARGUMENTS');const r=await this.#rpc(t,{...binding,operation:'receipt'},undefined,signal);return this.#outcome(r,binding);}
73
+ }
@@ -0,0 +1,74 @@
1
+ // S6b native-context human actions. The API is cooperative, not human attestation.
2
+ import { randomUUID } from 'node:crypto';
3
+ import { redactSecrets } from '../../../harnesses/lib/fleet-transcript-store.ts';
4
+ import { AllowedSessionsPolicy, type ConversationKey, type TargetEpoch } from './fleet-codex-allowlist.ts';
5
+ import { AllowedSessionsStore, type StoreHandle } from './fleet-codex-allowlist-store.ts';
6
+ import { ReadonlyFleetBridge, type RegistryReader } from './fleet-codex-readonly.ts';
7
+ import { ActionLedger, targetKey, validInstructionTarget, type QuestionReceipt, type QuestionOutcome } from './fleet-codex-instruction-store.ts';
8
+ import { exact, validId, validToolCall, normalizeAnswer, validSnapshot, validateQuestionAnswer, answerDigest, questionDigest, type AnswerTransport, type QuestionBinding } from './fleet-codex-answer-transport.ts';
9
+ export class AnswerError extends Error {readonly code:string;constructor(code:string){super(code);this.code=code;}}
10
+ function fail(code:string):never{throw new AnswerError(code);}
11
+ const key=(c:ConversationKey)=>JSON.stringify([c.hostProfile,c.principal,c.threadId]);
12
+ export function parseAnswer(v:unknown){
13
+ if(!exact(v,['requestId','target','questionId','toolCallId','operation','response'])||Buffer.byteLength(JSON.stringify(v))>65536||!validId(v.requestId)||!validInstructionTarget(v.target)||!validId(v.questionId)||!validToolCall(v.toolCallId)||v.operation!=='answer'&&v.operation!=='refusal'||(v.operation==='refusal')!==(v.response===null))fail('INVALID_ARGUMENTS');
14
+ let response;try{response=normalizeAnswer(v.response);}catch{fail('INVALID_ARGUMENTS');}
15
+ return {requestId:v.requestId,target:structuredClone(v.target),questionId:v.questionId,toolCallId:v.toolCallId,operation:v.operation as 'answer'|'refusal',response};
16
+ }
17
+ type Args=ReturnType<typeof parseAnswer>;
18
+ type Access={store:AllowedSessionsStore;handle:StoreHandle};
19
+ type Proposal={context:string;expires:number;args:Args;access:Access;questionDigest:string;digest:string;promise?:Promise<Record<string,unknown>>;outcome?:{result?:Record<string,unknown>;error?:unknown}};
20
+ export type AnswerBridgeOptions={policyRoot:string;assertNewAction?:(context:ConversationKey,requestId:string)=>void;registryReader:RegistryReader;transport:Pick<AnswerTransport,'inspect'|'send'|'receipt'>;now?:()=>number;monotonic?:()=>number;pendingBudget?:(context:string)=>{total:number;context:number}};
21
+ export class AnswerBridge {
22
+ readonly #options:AnswerBridgeOptions;readonly #auth:ReadonlyFleetBridge;readonly #ledger:ActionLedger;readonly #pending=new Map<string,Proposal>();
23
+ constructor(options:AnswerBridgeOptions){this.#options=options;this.#auth=new ReadonlyFleetBridge({registryReader:options.registryReader,policyBaseDir:options.policyRoot,now:options.now});this.#ledger=new ActionLedger(options.policyRoot+'.instructions',{now:options.now});}
24
+ #context(c:ConversationKey){new AllowedSessionsPolicy().list(c);if(!exact(c,['hostProfile','principal','threadId']))fail('IDENTITY_REQUIRED');}
25
+ #time(){const t=(this.#options.monotonic??(()=>performance.now()))();if(!Number.isFinite(t)||t<0)fail('CLOCK_INVALID');return t;}
26
+ #prune(){const n=this.#time();for(const [id,p]of this.#pending)if(!p.promise&&p.expires<=n)this.#pending.delete(id);}
27
+ pendingCount(context?:string){this.#prune();return context===undefined?this.#pending.size:[...this.#pending.values()].filter(p=>p.context===context).length;}
28
+ #history(receipt:QuestionReceipt){return {status:'historical',source:'local_action_ledger',scope:'historical_only',completion:'not_established',humanProvenance:'unknown',receipt};}
29
+ #same(old:ReturnType<ActionLedger['lookupAction']>,a:Args):QuestionReceipt {
30
+ if(!old||old.operation==='instruction'||old.operation!==a.operation||targetKey(old.target)!==targetKey(a.target)||old.questionId!==a.questionId||old.toolCallId!==a.toolCallId||old.digest!==answerDigest(a.operation,a.target,a.questionId,a.toolCallId,old.questionDigest,a.response))fail('INTENT_CONFLICT');return old;
31
+ }
32
+ async #read(c:ConversationKey,t:TargetEpoch){const r=await this.#auth.checkAllowedReadTarget(c,{project:t.project,peer:t.peer});if(targetKey(r.target)!==targetKey(t))fail('TARGET_CHANGED');}
33
+ async #access(c:ConversationKey,t:TargetEpoch,a?:Access):Promise<Access>{
34
+ await this.#read(c,t);const s=await this.#auth.discoverCandidates(c,{project:t.project});if(s.status!=='complete'||s.partial)fail('REGISTRY_UNAVAILABLE');
35
+ const matches=s.candidates.filter(v=>v.target.peer===t.peer);if(matches.length!==1||matches[0].presence!=='fresh'||targetKey(matches[0].target)!==targetKey(t))fail('TARGET_CHANGED');
36
+ const counts=new Map<string,number>();for(const v of s.candidates)counts.set(v.target.peer,(counts.get(v.target.peer)??0)+1);const current=s.candidates.filter(v=>v.presence==='fresh'&&counts.get(v.target.peer)===1).map(v=>v.target);
37
+ if(!a){const store=new AllowedSessionsStore(this.#options.policyRoot,c),state=await store.list(current),found=state.bindings.filter(v=>targetKey(v.target)===targetKey(t));if(found.length!==1)fail('NOT_ALLOWED');a={store,handle:await store.resolve(found[0].alias,current)};}
38
+ if(targetKey(await a.store.authorize(a.handle,'send',current))!==targetKey(t))fail('TARGET_CHANGED');return a;
39
+ }
40
+ async prepare(c:ConversationKey,input:unknown,signal?:AbortSignal):Promise<Record<string,unknown>>{
41
+ this.#context(c);const args=parseAnswer(input),old=this.#ledger.lookupAction(c,args.requestId);if(old)return this.#history(this.#same(old,args));this.#options.assertNewAction?.(c,args.requestId);this.#ledger.assertWritable(c);
42
+ if(signal?.aborted)fail('REQUEST_CANCELLED');const access=await this.#access(c,args.target),q=await this.#options.transport.inspect(args.target,args.questionId,args.toolCallId,signal);
43
+ await this.#read(c,args.target);if(signal?.aborted)fail('REQUEST_CANCELLED');
44
+ if(!validSnapshot(q)||redactSecrets(JSON.stringify(q))!==JSON.stringify(q)||q.state!=='pending'||targetKey(q.owner)!==targetKey(args.target)||q.id!==args.questionId||q.toolCallId!==args.toolCallId||!validateQuestionAnswer(q,args.response))fail('QUESTION_CHANGED');
45
+ this.#prune();const budget=this.#options.pendingBudget?.(key(c))??{total:0,context:0};if(this.#pending.size+budget.total>=64||this.pendingCount(key(c))+budget.context>=16)fail('BUSY');
46
+ const proposalId=randomUUID(),qd=questionDigest(q),digest=answerDigest(args.operation,args.target,args.questionId,args.toolCallId,qd,args.response);
47
+ this.#pending.set(proposalId,{context:key(c),expires:this.#time()+300000,args,access,questionDigest:qd,digest});
48
+ return {status:'prepared',source:'local_human_action_proposal',proposalId,expiresInSeconds:300,...args,question:structuredClone(q),questionDigest:qd,digest,expectedRevision:access.handle.revision,requiresHumanConfirmation:false,requiresActualHumanResponse:true,humanProvenance:'unknown',effect:args.operation==='refusal'?'one question-scoped human refusal; not Pi turn cancel':'one addressed human answer to this exact pending question; not an LLM instruction'};
49
+ }
50
+ async commit(c:ConversationKey,id:string,signal?:AbortSignal):Promise<Record<string,unknown>>{
51
+ this.#context(c);this.#prune();const p=this.#pending.get(id);if(!p||p.context!==key(c)||p.expires<=this.#time())fail('PROPOSAL_UNAVAILABLE');
52
+ if(p.outcome){if(p.outcome.error)throw p.outcome.error;return structuredClone(p.outcome.result!);}if(p.promise)return p.promise;
53
+ p.promise=(async()=>{let reserved:QuestionReceipt|undefined;
54
+ try{
55
+ const a=p.args,old=this.#ledger.lookupAction(c,a.requestId);if(old)return this.#history(this.#same(old,a));if(signal?.aborted)fail('REQUEST_CANCELLED');this.#options.assertNewAction?.(c,a.requestId);await this.#access(c,a.target,p.access);if(signal?.aborted)fail('REQUEST_CANCELLED');
56
+ const reservation=this.#ledger.reserveAction(c,{operation:a.operation,requestId:a.requestId,target:a.target,questionId:a.questionId,toolCallId:a.toolCallId,questionDigest:p.questionDigest,digest:p.digest},{alias:p.access.handle.alias,policyRevision:p.access.handle.revision});
57
+ if(!reservation.created)return this.#history(this.#same(reservation.receipt,a));reserved=reservation.receipt as QuestionReceipt;
58
+ let result=await this.#options.transport.send(a.target,this.#binding(reserved),a.response,{signal,beforeWrite:async()=>{await this.#access(c,a.target,p.access);if(signal?.aborted)fail('REQUEST_CANCELLED');this.#options.assertNewAction?.(c,a.requestId);this.#ledger.markActionAttempt(c,a.requestId);}});
59
+ try{await this.#read(c,a.target);}catch{result={state:'unknown',detail:'AUTHORIZATION_CHANGED',result:null};}
60
+ if(signal?.aborted)result={state:'unknown',detail:'TRANSPORT_UNCERTAIN',result:null};
61
+ return {...this.#history(this.#ledger.recordAction(c,a.requestId,result)),status:'recorded',source:'local_action_receipt'};
62
+ }catch(error){if(reserved){try{this.#ledger.recordAction(c,reserved.requestId,{state:'not_sent',detail:'TRANSPORT_UNCERTAIN',result:null});}catch{/* preserve original uncertain state; no retry */}}throw error;}
63
+ })();
64
+ try{const result=await p.promise;p.outcome={result};return structuredClone(result);}catch(error){p.outcome={error};throw error;}finally{p.promise=undefined;}
65
+ }
66
+ #binding(r:QuestionReceipt):QuestionBinding{return{operation:r.operation,questionId:r.questionId,toolCallId:r.toolCallId,questionDigest:r.questionDigest,actionDigest:r.digest,wireId:r.wireId};}
67
+ async receipt(c:ConversationKey,input:unknown,signal?:AbortSignal):Promise<Record<string,unknown>>{
68
+ this.#context(c);if(!exact(input,['requestId'],['refresh'])||!validId(input.requestId)||Object.hasOwn(input,'refresh')&&typeof input.refresh!=='boolean')fail('INVALID_ARGUMENTS');
69
+ let r=this.#ledger.lookupAction(c,input.requestId);if(!r)fail('INTENT_UNAVAILABLE');if(r.operation==='instruction')fail('INTENT_CONFLICT');if(input.refresh!==true)return this.#history(r);this.#ledger.assertWritable(c);
70
+ if(signal?.aborted)fail('REQUEST_CANCELLED');await this.#read(c,r.target);if(!r.attempted)return this.#history(r);
71
+ const remote:QuestionOutcome|null=await this.#options.transport.receipt(r.target,this.#binding(r),signal);await this.#read(c,r.target);if(signal?.aborted)fail('REQUEST_CANCELLED');
72
+ if(remote)r=this.#ledger.recordAction(c,r.requestId,remote);return {...this.#history(r),refresh:remote?'terminal_observed':'unknown'};
73
+ }
74
+ }
@@ -0,0 +1,204 @@
1
+ import {createHash,randomUUID} from 'node:crypto';
2
+ import {readFileSync,lstatSync} from 'node:fs';
3
+ import {join,dirname} from 'node:path';
4
+ import {NotificationBootstrap,type BootstrapServices,type BootstrapNamespace,type BootstrapScope,type BootstrapInspection} from '../../../harnesses/lib/fleet-notification-bootstrap.ts';
5
+ import {assessLoadedFleetCatalog} from '../../../harnesses/lib/fleet-codex-catalog.ts';
6
+ import {codexRightsSnapshot} from '../../../harnesses/lib/fleet-codex-policy-snapshot.ts';
7
+ import {namespaceKey,type BootstrapPresence} from '../../../harnesses/lib/fleet-bootstrap-channel.ts';
8
+ import {issueBootstrapAdmission} from '../../../harnesses/lib/fleet-notification-admission.ts';
9
+ import {codexNotificationBootstrapPolicy} from '../../../harnesses/lib/codex-notification-profile.ts';
10
+ import {assessQueueCompatibility,targetKey,validInstructionTarget,type NotificationConfig,type QueueCompatibilityAssessment} from '../../../harnesses/lib/fleet-notification-validation.ts';
11
+ import {AllowedSessionsStore,StoreError,type StoreSnapshot} from './fleet-codex-allowlist-store.ts';
12
+ import type {TargetEpoch} from './fleet-codex-allowlist.ts';
13
+ import {CodexDaemonObserver} from './codex-daemon-observer.ts';
14
+ import {measureDaemon,exportSchema,schemaExportStillCurrent,CodexMeasurementError,type DaemonMeasurement} from './codex-measurement.ts';
15
+ import {CodexUnixQueueRpc} from './codex-unix-queue-rpc.ts';
16
+ import {CodexProbeTranscript} from './codex-probe-transcript.ts';
17
+ import {CodexBootstrapProbe} from './codex-bootstrap-probe.ts';
18
+ import type {AutomaticDesktopData} from './codex-desktop-discovery.ts';
19
+ import {DesktopPreflightRegistry,type DesktopPreflightRecord} from './codex-desktop-preflight.ts';
20
+ import {NativePresenceDirectory,type NativePresence} from './codex-native-presence.ts';
21
+ import {privateDirectory,directoryCurrent,writePrivateJson,readPrivateJson,privateFileIdentity} from './codex-bootstrap-files.ts';
22
+ import {FleetCodexNotificationRuntime,parseNotificationConfiguration} from './fleet-codex-event-runtime.ts';
23
+
24
+ type DesktopConfirmation=Parameters<BootstrapServices['confirm']>[0]&{desktopMapping?:Pick<DesktopPreflightRecord,'desktop'|'desktopVersion'|'versionSource'|'socketPath'|'codexHome'|'binaryPath'>};
25
+ type Eligible=Exclude<QueueCompatibilityAssessment,{level:'blocked'}>;
26
+ type Snapshot={namespace:BootstrapNamespace;owner:TargetEpoch;record:DesktopPreflightRecord;observation:BootstrapPresence;store:AllowedSessionsStore;state:StoreSnapshot|null;observer:CodexDaemonObserver;measurement:DaemonMeasurement;assessment:Eligible;catalog:any;wall:number;transcriptPath?:string};
27
+ export type BootstrapChatRow={namespace:BootstrapNamespace;producer:'fresh'|'missing'|'stale'|'ambiguous';hostInstance?:string;clientInfo?:BootstrapPresence['clientInfo'];rights:readonly string[];rightsStatus:string;expiresAt?:number;notification:string;reason?:string;compatibility?:string;daemonVersion?:string;desktopVersion?:string;socketEpoch?:string;bindingEpoch?:string;lastProbe?:{id:string;receiptId:string};lastNotification?:unknown;proposalState?:string};
28
+ type Activation=Parameters<BootstrapServices['activate']>[0];
29
+ type Active={runtime:FleetCodexNotificationRuntime;config:NotificationConfig;path:string;identity:string;parentIdentity:string;guard:()=>boolean;request:Activation;snapshot:Snapshot;controller:AbortController;monoUntil:number;wall:number;rechecking:boolean;attempted:boolean;recheckFailure?:string;autoBudget:{remaining:number}};
30
+ const clone=<T>(v:T):T=>structuredClone(v);
31
+ const same=(a:unknown,b:unknown)=>JSON.stringify(a)===JSON.stringify(b);
32
+ const hash=(v:unknown)=>createHash('sha256').update(JSON.stringify(v)).digest('hex');
33
+ // Cached diagnostics only: exact internal codes, never raw exceptions/UA/paths.
34
+ const recheckFailures=new Set(['daemon_version_unavailable','daemon_observation_failed','measurement_timeout','measurement_cancelled','invalid_socket_epoch','initialize_epoch_mismatch','socket_epoch_changed','schema_binary_changed','native_presence_required','desktop_preflight_required','catalog_not_ready','continuation_scope_changed','continuation_rights_changed','continuation_config_changed','compat_recheck_failed','compat_recheck_changed','bootstrap_cancelled','bootstrap_context_changed','daemon_context_changed','bootstrap_rights_changed','bootstrap_probe_not_sent','bootstrap_probe_unknown_no_replay','compat_recheck_probe_unknown','bootstrap_activation_cancelled','bootstrap_activation_changed','bootstrap_config_scope_mismatch','bootstrap_config_changed','notification_journal_root_conflict','bootstrap_file_changed','bootstrap_file_publication_unknown']);
35
+ function recheckFailure(stage:'inspect'|'probe'|'verify'|'activate',error:unknown,cancelled:boolean){return 'd7_'+stage+'_'+(cancelled?'cancelled':error instanceof Error&&recheckFailures.has(error.message)?error.message:'failed');}
36
+ /** Production AF services. All status/render data is cached. No active services
37
+ * are created until explicit native prepare/UI enable; raw presence is never
38
+ * promoted to Desktop identity or no-load capability. Only Codex writes rights.
39
+ * Missing operator-observed Desktop/process/catalog mapping fails closed and is
40
+ * a live-preflight prerequisite, not fabricated offline qualification. */
41
+ export class FleetCodexBootstrap {
42
+ readonly coordinator:NotificationBootstrap;readonly native:NativePresenceDirectory;readonly preflight:DesktopPreflightRegistry;
43
+ private readonly options:{policyRoot:string;namespace:{hostProfile:string;principal:string};owner:()=>TargetEpoch|null;presence:(c:BootstrapNamespace,lease?:boolean)=>BootstrapPresence|null;writeRights:BootstrapServices['codexWriteRights'];confirm:(review:DesktopConfirmation,signal:AbortSignal)=>Promise<boolean>;discoverDesktop?:(signal:AbortSignal)=>Promise<AutomaticDesktopData>;confirmPreflight:ConstructorParameters<typeof DesktopPreflightRegistry>[0]['confirm'];procRoot?:string;referenceDocuments?:unknown;legacy?:()=>{config:NotificationConfig;runtime?:FleetCodexNotificationRuntime;release:()=>void}|undefined};
44
+ readonly #automatic=new Map<string,DesktopPreflightRecord>();readonly #root:string;readonly #stop=new AbortController();#epoch=new AbortController();readonly #snapshots=new Map<string,Snapshot>();readonly #active=new Map<string,Active>();readonly #rows=new Map<string,BootstrapChatRow>();readonly #schemas=new Map<string,Awaited<ReturnType<typeof exportSchema>>>();readonly #exports=new Map<string,Promise<Awaited<ReturnType<typeof exportSchema>>>>();readonly #busy=new Set<string>();#refreshing=false;
45
+ constructor(options:FleetCodexBootstrap['options']){
46
+ this.options={...options,namespace:{...options.namespace}};this.#root=options.policyRoot+'.bootstrap';this.native=new NativePresenceDirectory(options.policyRoot+'.presence');
47
+ this.preflight=new DesktopPreflightRegistry({root:join(this.#root,'desktop-mappings'),procRoot:options.procRoot,confirm:async(review,signal)=>{const accepted=await options.confirmPreflight(review,signal);if(accepted===true&&!signal.aborted)await privateDirectory(this.#root,true);return accepted;}});
48
+ this.coordinator=new NotificationBootstrap({owner:options.owner,inspect:(c,s)=>this.#inspect(c,s),confirm:(r,s)=>this.#confirm(r,s),codexWriteRights:options.writeRights,probe:(r,s)=>this.#probe(r,s),activate:(r,s)=>this.#activate(r,s),disable:(c,s)=>this.#disable(c,s)});
49
+ }
50
+ async #confirm(review:Parameters<BootstrapServices['confirm']>[0],signal:AbortSignal){
51
+ const key=namespaceKey(review.scope.namespace),snapshot=this.#snapshots.get(key);if(!snapshot)throw Error('bootstrap_inspection_required');this.#guard(snapshot);
52
+ const record=snapshot.record,ask=()=>this.options.confirm({...review,...(this.preflight.isAutomaticDraft(record)?{desktopMapping:{desktop:clone(record.desktop),desktopVersion:record.desktopVersion,versionSource:record.versionSource,socketPath:record.socketPath,codexHome:record.codexHome,binaryPath:record.binaryPath}}:{})},signal);
53
+ const accepted=await ask();if(!accepted)return false;this.#guard(snapshot);
54
+ if(signal.aborted||!snapshot.transcriptPath)throw Error('bootstrap_cancelled');
55
+ const reader=new CodexProbeTranscript({codexHome:record.codexHome,timeoutMs:2000});
56
+ try{await reader.securePermissions(snapshot.transcriptPath,review.scope.namespace.threadId,signal,()=>this.#guard(snapshot));}finally{await reader.stop();}
57
+ if(!this.preflight.isAutomaticDraft(record))return true;
58
+ const confirmed=await this.preflight.confirmAutomatic(record,snapshot.observation,async()=>{this.#guard(snapshot);return true;},signal,()=>this.#guard(snapshot));
59
+ if(!confirmed)return false;snapshot.record=confirmed;this.#automatic.delete(key);return true;
60
+ }
61
+
62
+ #owner(){const owner=this.options.owner();if(!validInstructionTarget(owner))throw Error('owner_unavailable');return clone(owner);}
63
+ async #rights(c:BootstrapNamespace){const store=new AllowedSessionsStore(this.options.policyRoot,c);try{return {store,state:await store.open()};}catch(e){if(e instanceof StoreError&&e.code==='STATE_MISSING')return {store,state:null};throw Error('codex_rights_unavailable');}}
64
+ #catalog(observation:BootstrapPresence){const catalog={identity:'host_context_validated',protocolVersion:observation.protocolVersion,tools:observation.catalog.map(name=>({name}))};if(!assessLoadedFleetCatalog(catalog).ready)throw Error('catalog_not_ready');return catalog;}
65
+ #rightsCurrent(snapshot:Snapshot,allowSend=false){
66
+ if(snapshot.store.snapshotCurrent(snapshot.state))return true;
67
+ const next=allowSend?snapshot.store.advanceSendSnapshot(snapshot.state,snapshot.owner):null;
68
+ if(!next)return false;snapshot.state=next;return true;
69
+ }
70
+ #guard(snapshot:Snapshot,scope?:BootstrapScope,assessment?:Eligible,lease=false,allowSend=false){
71
+ const seen=this.options.presence(snapshot.namespace,lease),owner=this.options.owner();
72
+ if(this.#stop.signal.aborted||!owner||targetKey(owner)!==targetKey(snapshot.owner)||!seen||seen.hostInstance!==snapshot.observation.hostInstance||(!this.preflight.currentNow(snapshot.record,seen)&&(!!scope||lease||!this.preflight.observedCurrentNow(snapshot.record,seen)))||!this.#rightsCurrent(snapshot,allowSend)||Date.now()<snapshot.wall)throw Error('bootstrap_context_changed');
73
+ this.#catalog(seen);
74
+ if(snapshot.observer.socketEpoch(this.#stop.signal)!==snapshot.measurement.socketEpoch)throw Error('daemon_context_changed');
75
+ if(assessment&&!same(assessment.context,snapshot.assessment.context))throw Error('daemon_context_changed');
76
+ if(scope){const rights=codexRightsSnapshot(snapshot.state,owner),project=(r:readonly string[])=>allowSend?r.filter(r=>r!=='send'):r;if(targetKey(scope.owner)!==targetKey(owner)||namespaceKey(scope.namespace)!==namespaceKey(snapshot.namespace)||scope.binding.hostInstance!==seen.hostInstance||rights.status!=='active'||rights.expiresAt!==scope.until||Date.now()>=scope.until||!same(project(rights.rights),project(scope.rights)))throw Error('bootstrap_rights_changed');}
77
+ }
78
+ async #contract(record:DesktopPreflightRecord,measured:DaemonMeasurement,signal:AbortSignal){
79
+ if(!record.binaryPath)return {state:'unavailable' as const,daemonVersion:measured.version,desktopVersion:record.desktopVersion,socketEpoch:measured.socketEpoch,reason:'matching_binary_unavailable' as const};
80
+ const key=hash([record.binaryPath,measured.version,measured.socketEpoch]);let evidence=this.#schemas.get(key);
81
+ try{
82
+ if(evidence&&!await schemaExportStillCurrent(record.binaryPath,evidence,{signal,timeoutMs:2000})){this.#schemas.delete(key);evidence=undefined;}
83
+ if(!evidence){let pending=this.#exports.get(key);if(!pending){pending=exportSchema(record.binaryPath,measured,{signal,timeoutMs:8000});this.#exports.set(key,pending);void pending.finally(()=>this.#exports.delete(key)).catch(()=>{});}evidence=await pending;if(signal.aborted)throw Error('bootstrap_cancelled');if(!await schemaExportStillCurrent(record.binaryPath,evidence,{signal,timeoutMs:2000}))throw Error('schema_binary_changed');if(this.#schemas.size>=2)this.#schemas.delete(this.#schemas.keys().next().value!);this.#schemas.set(key,evidence);}
84
+ return {state:'available' as const,daemonVersion:evidence.version,desktopVersion:record.desktopVersion,socketEpoch:evidence.socketEpoch,documents:evidence.documents};
85
+ }catch(e){if(!signal.aborted&&e instanceof CodexMeasurementError&&e.code==='measurement_timeout')return {state:'unavailable' as const,daemonVersion:measured.version,desktopVersion:record.desktopVersion,socketEpoch:measured.socketEpoch,reason:'schema_export_timeout' as const};throw e;}
86
+ }
87
+ async #inspect(c:BootstrapNamespace,signal:AbortSignal,lease=false):Promise<BootstrapInspection>{
88
+ if(c.hostProfile!==this.options.namespace.hostProfile||c.principal!==this.options.namespace.principal||this.#stop.signal.aborted||signal.aborted)throw Error('native_namespace_unavailable');
89
+ if(!lease&&this.#active.get(namespaceKey(c))?.rechecking)throw Error('bootstrap_recheck_in_progress');
90
+ const owner=this.#owner(),observation=this.options.presence(c,lease);if(!observation)throw Error('native_presence_required');
91
+ if(!lease){const all=await this.native.list(signal),matching=all.filter(r=>r.fresh&&namespaceKey(r.observation.namespace)===namespaceKey(c)&&r.observation.hostInstance===observation.hostInstance);if(matching.length!==1||matching[0].observation.hostInstance!==observation.hostInstance)throw Error('native_presence_ambiguous_or_unavailable');}
92
+ let record=await this.preflight.current(observation,signal);
93
+ if(!record&&!lease&&this.options.discoverDesktop){
94
+ const key=namespaceKey(c),draft=this.#automatic.get(key);
95
+ if(draft&&this.preflight.observedCurrentNow(draft,observation))record=draft;
96
+ else{if(this.#automatic.size>=32&&!this.#automatic.has(key))throw Error('bootstrap_capacity');record=await this.preflight.observeAutomatic(observation,await this.options.discoverDesktop(signal),signal);this.#automatic.set(key,record);}
97
+ }
98
+ if(!record)throw Error('desktop_preflight_required');
99
+ this.#catalog(record.observation);const catalog=this.#catalog(observation),{store,state}=await this.#rights(c),observer=new CodexDaemonObserver({socketPath:record.socketPath}),measurement=await measureDaemon(observer,{signal,timeoutMs:2000});
100
+ const contract=await this.#contract(record,measurement,signal),reference=this.options.referenceDocuments??JSON.parse(readFileSync(new URL('../fixtures/codex-notification-contracts/bootstrap-profile-0.167.json',import.meta.url),'utf8')).referenceDocuments;
101
+ const assessment=assessQueueCompatibility({daemonVersion:measurement.version,desktopVersion:record.desktopVersion,socketEpoch:measurement.socketEpoch,contract},codexNotificationBootstrapPolicy(reference));if(assessment.level==='blocked')throw Error(assessment.reason);
102
+ const snapshot:Snapshot={namespace:clone(c),owner,record,observation:clone(observation),store,state,observer,measurement,assessment,catalog,wall:Date.now()};
103
+ const guard=()=>{if(signal.aborted)throw Error('bootstrap_cancelled');this.#guard(snapshot,undefined,undefined,lease);};guard();
104
+ // Actual capability check: exact metadata path/header, no turns/hydration,
105
+ // before/after notLoaded observations. It is NOT inferred from reader source.
106
+ const rpc=new CodexUnixQueueRpc({socketPath:record.socketPath}),reader=new CodexProbeTranscript({codexHome:record.codexHome,timeoutMs:2000});
107
+ try{const pin={daemonVersion:measurement.version,socketEpoch:measurement.socketEpoch};const read=async()=>{guard();const raw:any=await rpc.request('thread/read',{threadId:c.threadId,includeTurns:false},{signal,pin,beforeWrite:guard});guard();if(raw?.thread?.id!==c.threadId||raw.thread.status?.type!=='notLoaded'||typeof raw.thread.path!=='string')throw Error('probe_read_capability_unavailable');return raw.thread.path as string;};
108
+ const path=await read();await reader.checkCapability(path,c.threadId,signal);snapshot.transcriptPath=path;if(await read()!==path)throw Error('probe_read_path_changed');
109
+ }finally{await reader.stop();}
110
+ guard();if(this.#snapshots.size>=32&&!this.#snapshots.has(namespaceKey(c))){const old=[...this.#snapshots.keys()].find(k=>!this.#active.has(k)&&!this.#busy.has(k));if(!old)throw Error('bootstrap_capacity');this.#snapshots.delete(old);}this.#snapshots.set(namespaceKey(c),snapshot);return {desktopIdentity:this.preflight.identityFingerprint(record),hostInstance:observation.hostInstance,identity:'host_context_validated',catalog,assessment,probeReadCapability:'verified_without_loading',rights:codexRightsSnapshot(state,owner)};
111
+ }
112
+ async #probe(request:Parameters<BootstrapServices['probe']>[0],signal:AbortSignal,lease=false){
113
+ const snapshot=this.#snapshots.get(namespaceKey(request.scope.namespace));if(!snapshot)throw Error('bootstrap_inspection_required');this.#guard(snapshot,request.scope,request.assessment,lease);
114
+ const reader=new CodexProbeTranscript({codexHome:snapshot.record.codexHome}),driver=new CodexBootstrapProbe({rpc:new CodexUnixQueueRpc({socketPath:snapshot.record.socketPath}),reader,guard:()=>this.#guard(snapshot,request.scope,request.assessment,lease)});
115
+ try{return await driver.run(request,signal);}finally{await reader.stop();}
116
+ }
117
+ async #activate(request:Activation,signal:AbortSignal,continuation?:Active){
118
+ if(continuation)signal=AbortSignal.any([signal,continuation.controller.signal]);
119
+ const key=namespaceKey(request.scope.namespace),snapshot=this.#snapshots.get(key);if(!snapshot)throw Error('bootstrap_inspection_required');const deadline=performance.now()+4000;
120
+ const guard=()=>{if(signal.aborted||performance.now()>=deadline)throw Error('bootstrap_activation_cancelled');this.#guard(snapshot,request.scope,request.assessment,!!continuation);if(continuation)this.#continuationCurrent(key,continuation,false);};guard();
121
+ const scopeHash=hash([request.scope.namespace,request.scope.owner]),legacy=this.options.legacy?.(),matchingLegacy=legacy&&legacy.config.approval.binding.threadId===request.scope.namespace.threadId&&targetKey(legacy.config.approval.target)===targetKey(request.scope.owner)?legacy:undefined;
122
+ const old=this.#active.get(key),sameOld=old&&targetKey(old.config.approval.target)===targetKey(request.scope.owner)?old:undefined;
123
+ const path=join(this.#root,'configs',scopeHash+'.json'),previous=await readPrivateJson(path,32768,signal);guard();let saved:NotificationConfig|undefined;
124
+ if(previous){saved=parseNotificationConfiguration(JSON.stringify(previous.value));if(!saved.compat||namespaceKey(saved.compat.namespace)!==key||saved.approval.binding.threadId!==request.scope.namespace.threadId||targetKey(saved.approval.target)!==targetKey(request.scope.owner))throw Error('bootstrap_config_scope_mismatch');}
125
+ const roots=[sameOld?.config.stateRoot,matchingLegacy?.config.stateRoot,saved?.stateRoot].filter((r):r is string=>typeof r==='string');if(new Set(roots).size>1)throw Error('notification_journal_root_conflict');const stateRoot=roots[0]??join(this.#root,'events',scopeHash);
126
+ if(old){await old.runtime.stopAndDrain();if(!continuation)this.#active.delete(key);}if(matchingLegacy){await matchingLegacy.runtime?.stopAndDrain();matchingLegacy.release();}guard();
127
+ await privateDirectory(dirname(stateRoot),true);await privateDirectory(dirname(path),true);guard();const parentIdentity=await privateDirectory(dirname(path));
128
+ let identity:string|undefined,completed=false,admitted:ReturnType<typeof issueBootstrapAdmission>;
129
+ const current=()=>{try{if(!completed&&(signal.aborted||performance.now()>=deadline))return false;this.#guard(snapshot,request.scope,request.assessment,true,completed);return !!identity&&directoryCurrent(dirname(path),parentIdentity)&&privateFileIdentity(lstatSync(path))===identity&&performance.now()<leaseDeadline;}catch{return false;}};
130
+ const leaseDeadline=continuation?.monoUntil??performance.now()+Math.max(0,request.scope.until-Date.now());admitted=issueBootstrapAdmission(request,{stateRoot,socketPath:snapshot.record.socketPath,messageBudgetMs:30000},current);
131
+ guard();if(continuation&&previous?.identity!==continuation.identity)throw Error('bootstrap_config_changed');identity=await writePrivateJson(path,admitted.config,{signal,guard,expected:previous?.identity??null});guard();
132
+ await this.refreshCached();guard();
133
+ const runtime=new FleetCodexNotificationRuntime(admitted.config,()=>this.options.owner(),undefined,undefined,admitted.admission,()=>{const active=this.#active.get(key);if(active?.runtime===runtime)this.#scheduleRecheck(key,active);});
134
+ try{await runtime.start();guard();if(!current())throw Error('bootstrap_activation_changed');this.#active.set(key,{runtime,config:admitted.config,path,identity,parentIdentity,guard:current,request:clone(request),snapshot,controller:new AbortController(),monoUntil:leaseDeadline,wall:continuation?.wall??Date.now(),rechecking:false,attempted:false,autoBudget:continuation?.autoBudget??{remaining:4}});completed=true;if(continuation)continuation.controller.abort();return {enabled:true as const};}catch(e){runtime.stop();throw e;}
135
+ }
136
+ async #disable(c:BootstrapNamespace,signal:AbortSignal){
137
+ const key=namespaceKey(c),active=this.#active.get(key);if(active){active.controller.abort();active.runtime.stop();this.#active.delete(key);if(!this.#stop.signal.aborted&&!signal.aborted)await writePrivateJson(active.path,{...active.config,optedIn:false},{signal,expected:active.identity});}
138
+ await this.refreshCached();
139
+ }
140
+ async #attach(c:BootstrapNamespace,signal:AbortSignal){
141
+ if(this.options.presence(c))return;const key=namespaceKey(c),rows=(await this.native.list(signal)).filter(r=>r.fresh&&namespaceKey(r.observation.namespace)===key);if(rows.length!==1)throw Error('native_presence_required');const r=rows[0];let attach:string|undefined;
142
+ try{attach=await this.native.requestAttach({schema:r.schema,observation:r.observation,observedAt:r.observedAt},this.#owner(),signal);const until=performance.now()+5000;
143
+ while(!this.options.presence(c)){if(signal.aborted||this.#stop.signal.aborted||performance.now()>=until)throw Error('native_writer_unavailable');await new Promise(resolve=>setTimeout(resolve,50));}
144
+ }finally{if(attach)await this.native.cancelAttach(attach).catch(()=>{});}
145
+ }
146
+ async capturePreflight(c:BootstrapNamespace,parameters:Parameters<DesktopPreflightRegistry['capture']>[1],signal=new AbortController().signal){signal=AbortSignal.any([signal,this.#epoch.signal,this.#stop.signal]);await this.#attach(c,signal);const observed=this.options.presence(c);if(!observed)throw Error('native_presence_required');this.#catalog(observed);const record=await this.preflight.capture(observed,parameters,signal);await this.refreshCached();return record;}
147
+ async enable(c:BootstrapNamespace,rights:readonly ('read'|'send'|'approve')[]=['read','send','approve'],durationHours=12,signal=new AbortController().signal){
148
+ signal=AbortSignal.any([signal,this.#epoch.signal,this.#stop.signal]);const key=namespaceKey(c);if(this.#busy.has(key))throw Error('bootstrap_busy');this.#busy.add(key);
149
+ try{
150
+ await this.#attach(c,signal);
151
+ const prepared=await this.coordinator.prepare(c,Date.now()+durationHours*3600000,rights,signal);if(prepared.status!=='prepared'||!('proposalId'in prepared))return prepared;return await this.coordinator.commit(prepared.proposalId as string,c,signal);
152
+ }finally{this.#busy.delete(key);await this.refreshCached();}
153
+ }
154
+ #continuationCurrent(key:string,active:Active,file=true){
155
+ const scope=active.request.scope,seen=this.options.presence(scope.namespace,true),owner=this.options.owner();
156
+ if(this.#stop.signal.aborted||active.controller.signal.aborted||this.#active.get(key)!==active||!owner||targetKey(owner)!==targetKey(scope.owner)||Date.now()<active.wall||Date.now()>=scope.until||performance.now()>=active.monoUntil||!seen||seen.hostInstance!==scope.binding.hostInstance||!this.preflight.currentNow(active.snapshot.record,seen)||!this.#rightsCurrent(active.snapshot,true))throw Error('continuation_scope_changed');
157
+ this.#catalog(seen);const rights=codexRightsSnapshot(active.snapshot.state,owner),withoutSend=(r:readonly string[])=>r.filter(r=>r!=='send');if(rights.status!=='active'||rights.revision<active.config.approval.authorityRevision||rights.expiresAt!==scope.until||!same(withoutSend(rights.rights),withoutSend(scope.rights)))throw Error('continuation_rights_changed');
158
+ if(file&&(!directoryCurrent(dirname(active.path),active.parentIdentity)||privateFileIdentity(lstatSync(active.path))!==active.identity))throw Error('continuation_config_changed');
159
+ }
160
+ #scheduleRecheck(key:string,active:Active){
161
+ if(active.attempted||active.rechecking||this.#stop.signal.aborted)return;active.attempted=true;active.rechecking=true;
162
+ // Only a detected context invalidation schedules this. Cached status/UI refresh
163
+ // never calls it. One attempt: unknown probe/activation is never replayed.
164
+ void this.#recheck(key,active).catch(()=>{}).finally(()=>{active.rechecking=false;});
165
+ }
166
+ async #recheck(key:string,active:Active){
167
+ const deadline=new AbortController(),timer=setTimeout(()=>deadline.abort(),60000),signal=AbortSignal.any([deadline.signal,active.controller.signal,this.#epoch.signal,this.#stop.signal]);
168
+ let stage:'inspect'|'probe'|'verify'|'activate'='inspect';
169
+ try{
170
+ this.#continuationCurrent(key,active);const inspection=await this.#inspect(active.request.scope.namespace,signal,true);this.#continuationCurrent(key,active);
171
+ if(!same(inspection.rights,codexRightsSnapshot(active.snapshot.state,active.request.scope.owner)))throw Error('continuation_rights_changed');
172
+ // A missing schema cannot prove the old used contract is still the same.
173
+ // D6 stays paused with guidance; do not silently authorize a new version.
174
+ if(inspection.assessment.level==='contract_unverified'||inspection.assessment.level==='blocked'||active.config.compat?.level!==inspection.assessment.level||!active.config.compat.fingerprint||inspection.assessment.fingerprint!==active.config.compat.fingerprint||active.autoBudget.remaining<=0)throw Error('compat_recheck_failed');
175
+ const scope={...clone(active.request.scope),rights:[...inspection.rights.rights],binding:{...active.request.scope.binding,epoch:randomUUID()}},probeId=randomUUID();active.autoBudget.remaining--;
176
+ stage='probe';const receipt=await this.#probe({scope,assessment:inspection.assessment,probeId},signal,true);this.#continuationCurrent(key,active);
177
+ if(receipt.status!=='acknowledged')throw Error('compat_recheck_probe_unknown');stage='verify';const after=await this.#inspect(scope.namespace,signal,true);this.#continuationCurrent(key,active);
178
+ if(after.assessment.level==='blocked'||!same(after.assessment,inspection.assessment)||!same(after.rights,inspection.rights))throw Error('compat_recheck_changed');
179
+ stage='activate';await this.#activate({scope,assessment:inspection.assessment,receipt,catalog:inspection.catalog,rights:inspection.rights},signal,active);
180
+ }catch(error){if(this.#active.get(key)===active)active.recheckFailure=recheckFailure(stage,error,signal.aborted);}
181
+ finally{clearTimeout(timer);}
182
+ }
183
+ /** Separate safety watcher, not rendering/status. It may only retire the old
184
+ * runtime; continuation runs under the prior Pi scope, same fingerprint and
185
+ * original common wall/monotonic lease, with no Codex writer calls. */
186
+ checkContexts(){for(const [key,active]of this.#active)if(!active.guard())active.runtime.pauseForContextChange();}
187
+ hasRuntimeFor(threadId:string){return [...this.#active.values()].some(a=>a.config.approval.binding.threadId===threadId);}
188
+ async disable(c:BootstrapNamespace){const key=namespaceKey(c),active=this.#active.get(key);if(active){active.controller.abort();active.runtime.stop();}const result=await this.coordinator.disable(c);if(active&&this.#active.get(key)===active){await this.#disable(c,this.#stop.signal);return {status:'disabled',activation:'not_performed'};}return result;}
189
+ rows(){return [...this.#rows.values()].map(clone);}
190
+ async refreshCached(){
191
+ if(this.#refreshing||this.#stop.signal.aborted)return;this.#refreshing=true;
192
+ try{
193
+ let presences:Readonly<NativePresence&{fresh:boolean}>[]=[];try{presences=await this.native.list();}catch{}
194
+ const keys=new Map<string,BootstrapNamespace>();for(const p of presences)if(p.observation.namespace.hostProfile===this.options.namespace.hostProfile&&p.observation.namespace.principal===this.options.namespace.principal)keys.set(namespaceKey(p.observation.namespace),p.observation.namespace);for(const c of this.coordinator.rows())keys.set(namespaceKey(c.namespace),c.namespace);for(const s of this.#snapshots.values())keys.set(namespaceKey(s.namespace),s.namespace);
195
+ for(const [key,c]of [...keys].slice(0,32)){
196
+ const rows=presences.filter(p=>namespaceKey(p.observation.namespace)===key),attached=this.options.presence(c),fresh=rows.filter(p=>p.fresh&&(!attached||p.observation.hostInstance===attached.hostInstance)),seen=fresh.length===1?fresh[0].observation:rows[0]?.observation,active=this.#active.get(key),snapshot=this.#snapshots.get(key),phase=this.coordinator.rows().find(r=>namespaceKey(r.namespace)===key);
197
+ const status=active?.runtime.status();let rights:ReturnType<typeof codexRightsSnapshot>;try{rights=codexRightsSnapshot((await this.#rights(c)).state,this.#owner());}catch{rights={revision:0,rights:[],status:'unavailable'};}
198
+ this.#rows.set(key,{namespace:clone(c),producer:fresh.length>1?'ambiguous':fresh.length===1?'fresh':rows.length?'stale':'missing',hostInstance:seen?.hostInstance,clientInfo:seen?.clientInfo,rights:rights.rights,rightsStatus:rights.status,expiresAt:rights.expiresAt,notification:active?.rechecking?'rechecking_context':status?.enabled?'enabled':status?.reason??'disabled',reason:active?.recheckFailure??status?.reason??phase?.reason,proposalState:phase?.state,compatibility:active?.config.compat?.level??snapshot?.assessment.level,daemonVersion:active?.config.compat?.daemonVersion??snapshot?.measurement.version,desktopVersion:active?.config.compat?.desktopVersion??snapshot?.record.desktopVersion,socketEpoch:active?.config.compat?.socketEpoch??snapshot?.measurement.socketEpoch,bindingEpoch:active?.config.approval.binding.epoch,lastProbe:active?.config.compat?.probe,lastNotification:status?.lastNotification});
199
+ }
200
+ }finally{this.#refreshing=false;}
201
+ }
202
+ reset(){this.#epoch.abort();this.#epoch=new AbortController();this.coordinator.reset();for(const a of this.#active.values()){a.controller.abort();a.runtime.stop();}this.#active.clear();this.#snapshots.clear();this.#automatic.clear();this.#rows.clear();}
203
+ stop(){this.#stop.abort();this.#epoch.abort();this.coordinator.stop();for(const a of this.#active.values()){a.controller.abort();a.runtime.stop();}this.#active.clear();this.#automatic.clear();}
204
+ }
@@ -0,0 +1,76 @@
1
+ import {randomUUID} from 'node:crypto';
2
+ import {AllowedSessionsStore,StoreError,type StoreOptions} from './fleet-codex-allowlist-store.ts';
3
+ import type {ConversationKey,TargetEpoch,Right} from './fleet-codex-allowlist.ts';
4
+ import {PermissionTransport} from './fleet-codex-permission-transport.ts';
5
+ import type {CodexBootstrapProducer} from './codex-bootstrap-producer.ts';
6
+ import {validInstructionTarget,targetKey} from '../../../harnesses/lib/fleet-notification-validation.ts';
7
+ export class ConnectionError extends Error {readonly code:string;constructor(code:string){super(code);this.code=code;}}
8
+ function fail(code:string):never{throw new ConnectionError(code);}
9
+ const key=(c:ConversationKey)=>JSON.stringify([c.hostProfile,c.principal,c.threadId]);
10
+ export function parseConnection(v:any,operation:'prepare'|'commit'|'status'){
11
+ const fields=operation==='prepare'?['target','rights','durationHours','notifications','desktopConfirmed']:operation==='status'?['target']:['proposalId','quiescentWritersConfirmed'];
12
+ if(!v||typeof v!=='object'||Array.isArray(v)||Object.keys(v).some(k=>!fields.includes(k)))fail('INVALID_ARGUMENTS');
13
+ if(operation==='commit'){if(v.quiescentWritersConfirmed!==undefined&&typeof v.quiescentWritersConfirmed!=='boolean')fail('INVALID_ARGUMENTS');if(typeof v.proposalId!=='string'||!/^[a-f0-9-]{36}$/.test(v.proposalId))fail('INVALID_ARGUMENTS');return;}
14
+ if(!validInstructionTarget(v.target))fail('INVALID_ARGUMENTS');
15
+ if(operation==='status')return;
16
+ if(v.rights!==undefined&&(!Array.isArray(v.rights)||JSON.stringify(v.rights)!==JSON.stringify(['read',...(v.rights.includes('send')?['send']:[]),...(v.rights.includes('approve')?['approve']:[])])))fail('READ_REQUIRED_ORDERED_UNIQUE_RIGHTS');
17
+ if(v.durationHours!==undefined&&(!Number.isInteger(v.durationHours)||v.durationHours<1||v.durationHours>720)||v.notifications!==undefined&&typeof v.notifications!=='boolean'||v.desktopConfirmed!==undefined&&typeof v.desktopConfirmed!=='boolean')fail('INVALID_ARGUMENTS');
18
+ }
19
+ type Candidate={target:TargetEpoch;current:TargetEpoch[]};
20
+ type Pending={context:string;target:TargetEpoch;rights:Right[];until:number;revision:number|null;existing:boolean;alias:string;remoteProposal?:string;expires:number;promise?:Promise<any>;outcome?:any};
21
+ /** Native UX orchestration. Cooperative explicit-review contract, not human attestation. */
22
+ type ConnectionOptions={policyRoot:string;candidate:(c:ConversationKey,t:TargetEpoch)=>Promise<Candidate>;transport:Pick<PermissionTransport,'rpc'>;now?:()=>number;monotonic?:()=>number;storeOptions?:StoreOptions;pendingBudget?:(context:string)=>{total:number;context:number};bootstrap?:CodexBootstrapProducer};
23
+ export class ConnectionBridge {
24
+ private pending=new Map<string,Pending>();
25
+ private options:ConnectionOptions;
26
+ constructor(options:ConnectionOptions){this.options=options;}
27
+ private now(){return (this.options.now??Date.now)();}
28
+ private mono(){return (this.options.monotonic??(()=>performance.now()))();}
29
+ private store(c:ConversationKey){return new AllowedSessionsStore(this.options.policyRoot,c,{...this.options.storeOptions,now:this.options.now});}
30
+ private async state(c:ConversationKey){try{return await this.store(c).open();}catch(e){if(e instanceof StoreError&&e.code==='STATE_MISSING')return null;throw e;}}
31
+ private async remote(c:ConversationKey,t:TargetEpoch,operation:string,payload:object,signal?:AbortSignal){return this.options.transport.rpc(t,{operation,payload:{namespace:c,...payload}},async()=>{const selected=await this.options.candidate(c,t);if(targetKey(selected.target)!==targetKey(t))fail('TARGET_CHANGED');},signal);}
32
+ async status(c:ConversationKey,a:any,signal?:AbortSignal){
33
+ const selected=await this.options.candidate(c,a.target);if(targetKey(selected.target)!==targetKey(a.target))fail('TARGET_CHANGED');
34
+ const state=await this.state(c),b=state?.bindings.find(b=>targetKey(b.target)===targetKey(a.target));
35
+ let remote:any;try{const bootstrap=this.options.bootstrap?await this.options.bootstrap.status(c,a.target,signal):undefined;remote=bootstrap?.status==='cached'?bootstrap:await this.remote(c,a.target,'status',{},signal);}catch(e){remote={status:'unavailable',reason:(e as any).code??'control_unavailable'};}
36
+ return {status:'observed',target:a.target,namespace:c,rights:b?{stored:b.rights,effective:b.status==='active'&&(b.expiresAt===undefined||b.expiresAt>this.now()),expiresAt:b.expiresAt??null,reason:b.expiresAt!==undefined&&b.expiresAt<=this.now()?'rights_expired':b.status}:{stored:[],effective:false,reason:'not_connected'},notifications:remote.notifications??{enabled:false,reason:remote.reason??remote.status},delivery:'not_established_by_status'};
37
+ }
38
+ legacyPendingCount(context?:string){for(const [id,p] of this.pending)if(!p.promise&&p.expires<=this.mono())this.pending.delete(id);return context===undefined?this.pending.size:[...this.pending.values()].filter(p=>p.context===context).length;}
39
+ pendingCount(context?:string){return this.legacyPendingCount(context)+(this.options.bootstrap?.pendingCount(context)??0);}
40
+ observe(c:ConversationKey){this.options.bootstrap?.observe(c);}
41
+ stop(){this.options.bootstrap?.stop();}
42
+ async prepare(c:ConversationKey,a:any,signal?:AbortSignal){
43
+ const other=this.options.pendingBudget?.(key(c))??{total:0,context:0};if(this.pendingCount()+other.total>=64||this.pendingCount(key(c))+other.context>=16)fail('BUSY');
44
+ if(this.options.bootstrap&&a.notifications!==false)return this.options.bootstrap.prepare(c,a,signal);
45
+ const selected=await this.options.candidate(c,a.target);if(targetKey(selected.target)!==targetKey(a.target))fail('TARGET_CHANGED');
46
+ const state=await this.state(c),existing=state?.bindings.find(b=>b.target.project===a.target.project&&b.target.peer===a.target.peer);
47
+ if(existing&&(targetKey(existing.target)!==targetKey(a.target)||existing.status!=='active'))fail('REBIND_REQUIRED');
48
+ const rights=(a.rights??existing?.rights??['read']) as Right[],until=this.now()+(a.durationHours??12)*3600000;
49
+ if(existing&&JSON.stringify(existing.rights)!==JSON.stringify(rights))return {status:'blocked',reason:'existing_rights_preserved_use_explicit_binding_transition',storedRights:existing.rights};
50
+ if(existing?.expiresAt!==undefined&&existing.expiresAt<=this.now())return {status:'blocked',reason:'rights_expired_explicit_reenrollment_required'};
51
+ let remote:any;
52
+ if(a.notifications!==false){
53
+ if(a.desktopConfirmed!==true)return {status:'blocked',reason:'loaded_desktop_confirmation_required',noChanges:true};
54
+ try{remote=await this.remote(c,a.target,'prepare',{until,desktopConfirmed:true},signal);}catch(e){return {status:'blocked',reason:(e as any).code??'control_unavailable',noChanges:true};}
55
+ if(remote.status!=='prepared')return {status:'blocked',reason:remote.reason??'host_mapping_required',remote,noChanges:true};
56
+ }
57
+ for(const [id,p] of this.pending)if(!p.promise&&p.expires<=this.mono())this.pending.delete(id);
58
+ const freshBudget=this.options.pendingBudget?.(key(c))??{total:0,context:0};if(this.pending.size+freshBudget.total>=64||[...this.pending.values()].filter(p=>p.context===key(c)).length+freshBudget.context>=16)fail('BUSY');
59
+ const proposalId=randomUUID();this.pending.set(proposalId,{context:key(c),target:selected.target,rights:[...rights],until,revision:state?.revision??null,existing:!!existing,alias:existing?.alias??selected.target.project+':'+selected.target.peer,remoteProposal:remote?.proposalId,expires:this.mono()+300000});
60
+ return {status:'prepared',proposalId,expiresInSeconds:300,target:selected.target,namespace:c,proposedRights:rights,rightsUntil:existing?existing.expiresAt??null:until,existingRightsPreserved:!!existing,notificationsUntil:remote?until:null,eventKinds:remote?['message','question','permission']:[],requiresExplicitConfirmation:true,humanProvenance:'unknown',compatibility:existing?'existing_policy_unchanged':'policy_v3_old_writers_fail_closed',requiresQuiescentWriters:!existing,delivery:'not_attempted'};
61
+ }
62
+ async commit(c:ConversationKey,id:string,signal?:AbortSignal,quiescentWritersConfirmed=false){
63
+ if(this.options.bootstrap?.has(c,id))return this.options.bootstrap.beginCommit(c,id,signal);
64
+ const p=this.pending.get(id);if(!p||p.context!==key(c)||p.expires<=this.mono())fail('PROPOSAL_UNAVAILABLE');if(p.outcome)return structuredClone(p.outcome);if(!p.existing&&!quiescentWritersConfirmed)fail('QUIESCENT_WRITERS_CONFIRMATION_REQUIRED');if(p.promise)return p.promise;
65
+ p.promise=(async()=>{let rightsCommitted=false;try{
66
+ if(signal?.aborted)fail('REQUEST_CANCELLED');
67
+ const selected=await this.options.candidate(c,p.target);if(targetKey(selected.target)!==targetKey(p.target))fail('TARGET_CHANGED');
68
+ const store=this.store(c);let state=await this.state(c);if((state?.revision??null)!==p.revision)fail('STATE_CHANGED');
69
+ if(!p.existing){if(p.until<=this.now())fail('RIGHTS_EXPIRED');if(!state)state=await store.initialize();state=await store.connect({alias:p.target.project+':'+p.target.peer,target:p.target,rights:p.rights,expiresAt:p.until},selected.current,state.revision);rightsCommitted=true;}
70
+ else{const h=await store.resolve(p.alias,selected.current);await store.authorize(h,'read',selected.current);}
71
+ let notifications:any={status:'not_requested'};
72
+ if(p.remoteProposal){if(signal?.aborted)fail('REQUEST_CANCELLED');notifications=await this.remote(c,p.target,'commit',{proposalId:p.remoteProposal},signal);}
73
+ p.outcome={status:['not_requested','renewed'].includes(notifications.status)?'committed':'partially_applied_or_unknown',target:p.target,rightsCommitted,existingRightsPreserved:p.existing,notifications,delivery:'not_established_by_commit'};
74
+ }catch(e){p.outcome={status:'failed_or_unknown',reason:(e as any).code??'IO_ERROR',rightsCommitted,replayAllowed:false};}return structuredClone(p.outcome);})();return p.promise;
75
+ }
76
+ }
@@ -0,0 +1,58 @@
1
+ import {createHash} from 'node:crypto';
2
+ import {decodeQuestionReference} from '../../../harnesses/lib/fleet-question-reference.ts';
3
+ import {targetKey,validInstructionTarget} from './fleet-codex-instruction-store.ts';
4
+ import {redactSecrets} from '../../../harnesses/lib/fleet-transcript-store.ts';
5
+ import type {AddressedFleetEvent,CodexEventBinding} from '../../../harnesses/lib/fleet-codex-event-bridge.ts';
6
+ import type {TargetEpoch} from './fleet-codex-allowlist.ts';
7
+ const sha=(v:unknown)=>createHash('sha256').update(JSON.stringify(v)??'null').digest('hex');
8
+ export type FleetEventReply={kind:'message';summary:string}|{kind:'question';response:unknown}|{kind:'permission';decision:'allow_once'|'deny';reason:string};
9
+ export type ReplyPorts={
10
+ /** Decoded tool payloads from the ACTUAL native host context, never identity copied from notification text. */
11
+ invoke(name:string,args:unknown):Promise<any>;
12
+ currentBinding():CodexEventBinding|null;
13
+ /** First-party native invocation metadata, independent of BOTH the event and saved binding. */
14
+ nativeIdentity():{threadId:string;identityAssurance:'host_context_validated'|'unknown'}|null;
15
+ /** Human workflow only; never a boolean supplied by the notification/model payload. */
16
+ confirmHuman?:(proposal:unknown)=>Promise<boolean>;
17
+ };
18
+ /** Route a host/model-selected response; never chooses task necessity or manufactures
19
+ * human consent. Native APIs independently enforce read/send/approve and exact freshness. */
20
+ export async function replyFleetEvent(event:AddressedFleetEvent,target:TargetEpoch,reply:FleetEventReply,ports:ReplyPorts){
21
+ const binding=ports.currentBinding();
22
+ const fresh=()=>{const now=ports.currentBinding(),native=typeof ports.nativeIdentity==='function'?ports.nativeIdentity():null;return native?.identityAssurance==='host_context_validated'&&!!binding&&native.threadId===binding.threadId&&!!now&&sha(now)===sha(binding)&&event.bindingId===binding.id&&event.bindingEpoch===binding.epoch&&event.fleetOwner===binding.fleetOwner&&binding.fleetOwner===targetKey(target)&&Date.now()<event.deadline;};
23
+ if(!validInstructionTarget(target)||!fresh()||reply.kind!==event.kind)throw Error('event_reply_stale_or_wrong_kind');
24
+ const question=event.kind==='question'?decodeQuestionReference(event.reference):null;
25
+ if(event.kind==='question'&&!question)throw Error('event_reply_reference_invalid');
26
+ const prefix='fleet:'+event.kind+'/';
27
+ if(!question&&!event.reference.startsWith(prefix))throw Error('event_reply_reference_invalid');
28
+ const parts=question?[]:event.reference.slice(prefix.length).split('/');
29
+ if(parts.some(p=>!/^[A-Za-z0-9][A-Za-z0-9._-]{0,255}$/.test(p)))throw Error('event_reply_reference_invalid');
30
+ const requestId='reply-'+sha([binding!.id,binding!.epoch,event.id,event.kind]);
31
+ if(reply.kind==='message')return {status:'summary_only',source:'codex_machine',summaryPreview:redactSecrets(reply.summary).slice(0,1024),humanConsent:false,piEffect:'not_established'};
32
+ if(reply.kind==='question'){
33
+ if(!question)throw Error('question_reference_incomplete');
34
+ if(redactSecrets(JSON.stringify(reply.response))!==JSON.stringify(reply.response))throw Error('question_response_unaddressable');
35
+ const proposal=await ports.invoke('fleet_answer_prepare',{requestId,target,questionId:question.questionId,toolCallId:question.toolCallId,operation:reply.response===null?'refusal':'answer',response:reply.response});
36
+ if(!fresh())throw Error('event_reply_expired');
37
+ if(!ports.confirmHuman)return {status:'human_confirmation_required',proposal,humanConsent:false};
38
+ if(!await ports.confirmHuman(proposal))return {status:'human_confirmation_not_obtained',humanConsent:false};
39
+ if(!fresh())throw Error('event_reply_expired');
40
+ const result=await ports.invoke('fleet_answer_commit',{proposalId:proposal.proposalId});
41
+ return {status:'question_commit_returned',result,humanProvenance:'host_callback_not_cryptographic',piEffect:'not_established'};
42
+ }
43
+ if(parts.length!==1||parts[0].length>96||!['allow_once','deny'].includes(reply.decision)||!reply.reason?.trim()||reply.reason.length>2000||redactSecrets(reply.reason)!==reply.reason)throw Error('permission_reply_invalid');
44
+ let cursor:string|null=null,snapshot:any,seen=new Set<string>();
45
+ for(let page=0;page<8;page++){
46
+ if(!fresh())throw Error('event_reply_expired');
47
+ const result=await ports.invoke('fleet_permissions',{target,operation:'list',snapshot:null,...(cursor?{cursor}:{})});
48
+ if(result?.status!=='ok'||!Array.isArray(result.requests))throw Error('permission_list_unavailable');
49
+ snapshot=result.requests.find((r:any)=>r?.snapshot?.id===parts[0])?.snapshot;if(snapshot)break;
50
+ cursor=result.nextCursor??null;if(!cursor)break;if(seen.has(cursor))throw Error('permission_cursor_invalid');seen.add(cursor);
51
+ }
52
+ if(!snapshot||!validInstructionTarget(snapshot.owner)||targetKey(snapshot.owner)!==targetKey(target)||!fresh())throw Error('permission_not_pending');
53
+ const inspection=await ports.invoke('fleet_permissions',{target,operation:'inspect',snapshot});
54
+ if(inspection?.status!=='ok'||inspection.state?.status!=='pending'||sha(inspection.view?.snapshot)!==sha(snapshot)||!fresh())throw Error('permission_changed');
55
+ const result=await ports.invoke('fleet_permission_decide',{requestId,snapshot,decision:reply.decision,reason:reply.reason});
56
+ // Tool return/accepted_by_latch is not applied or tool completion. No automatic retry.
57
+ return {status:'machine_decision_returned',source:'codex_machine',humanConsent:false,result,piEffect:'not_established',automaticResend:false};
58
+ }