@ouro.bot/cli 0.1.0-alpha.55 → 0.1.0-alpha.550

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 (386) hide show
  1. package/README.md +133 -19
  2. package/RepairGuide.ouro/agent.json +5 -0
  3. package/RepairGuide.ouro/psyche/IDENTITY.md +19 -0
  4. package/RepairGuide.ouro/psyche/SOUL.md +55 -0
  5. package/RepairGuide.ouro/skills/diagnose-bootstrap-drift.md +54 -0
  6. package/RepairGuide.ouro/skills/diagnose-broken-remote.md +63 -0
  7. package/RepairGuide.ouro/skills/diagnose-stacked-typed-issues.md +35 -0
  8. package/RepairGuide.ouro/skills/diagnose-sync-blocked.md +54 -0
  9. package/RepairGuide.ouro/skills/diagnose-vault-expired.md +60 -0
  10. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +4 -2
  11. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +2 -2
  12. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +1 -1
  13. package/changelog.json +3555 -0
  14. package/dist/arc/attention-types.js +8 -0
  15. package/dist/arc/cares.js +140 -0
  16. package/dist/arc/episodes.js +117 -0
  17. package/dist/arc/intentions.js +133 -0
  18. package/dist/arc/json-store.js +117 -0
  19. package/dist/arc/obligations.js +237 -0
  20. package/dist/arc/packets.js +193 -0
  21. package/dist/arc/presence.js +185 -0
  22. package/dist/arc/task-lifecycle.js +65 -0
  23. package/dist/heart/active-work.js +837 -26
  24. package/dist/heart/agent-entry.js +58 -3
  25. package/dist/heart/attachments/image-normalize.js +194 -0
  26. package/dist/heart/attachments/materialize.js +97 -0
  27. package/dist/heart/attachments/originals.js +88 -0
  28. package/dist/heart/attachments/render.js +29 -0
  29. package/dist/heart/attachments/sources/adapter.js +2 -0
  30. package/dist/heart/attachments/sources/bluebubbles.js +156 -0
  31. package/dist/heart/attachments/sources/cli-local-file.js +78 -0
  32. package/dist/heart/attachments/sources/index.js +16 -0
  33. package/dist/heart/attachments/store.js +103 -0
  34. package/dist/heart/attachments/types.js +93 -0
  35. package/dist/heart/auth/auth-flow.js +479 -0
  36. package/dist/heart/background-operations.js +281 -0
  37. package/dist/heart/bundle-state.js +168 -0
  38. package/dist/heart/commitments.js +111 -0
  39. package/dist/heart/config-registry.js +304 -0
  40. package/dist/heart/config.js +114 -118
  41. package/dist/heart/core.js +925 -246
  42. package/dist/heart/cross-chat-delivery.js +3 -18
  43. package/dist/heart/daemon/agent-config-check.js +512 -0
  44. package/dist/heart/daemon/agent-discovery.js +102 -3
  45. package/dist/heart/daemon/agent-service.js +522 -0
  46. package/dist/heart/daemon/agentic-repair.js +554 -0
  47. package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
  48. package/dist/heart/daemon/boot-sync-probe.js +197 -0
  49. package/dist/heart/daemon/cadence.js +70 -0
  50. package/dist/heart/daemon/cli-defaults.js +665 -0
  51. package/dist/heart/daemon/cli-exec.js +7565 -0
  52. package/dist/heart/daemon/cli-help.js +498 -0
  53. package/dist/heart/daemon/cli-parse.js +1590 -0
  54. package/dist/heart/daemon/cli-render-doctor.js +57 -0
  55. package/dist/heart/daemon/cli-render.js +775 -0
  56. package/dist/heart/daemon/cli-types.js +8 -0
  57. package/dist/heart/daemon/connect-bay.js +323 -0
  58. package/dist/heart/daemon/daemon-cli.js +29 -1672
  59. package/dist/heart/daemon/daemon-entry.js +417 -2
  60. package/dist/heart/daemon/daemon-health.js +183 -0
  61. package/dist/heart/daemon/daemon-rollup.js +58 -0
  62. package/dist/heart/daemon/daemon-runtime-sync.js +87 -13
  63. package/dist/heart/daemon/daemon-tombstone.js +236 -0
  64. package/dist/heart/daemon/daemon.js +758 -71
  65. package/dist/heart/daemon/dns-workflow.js +394 -0
  66. package/dist/heart/daemon/doctor-types.js +8 -0
  67. package/dist/heart/daemon/doctor.js +844 -0
  68. package/dist/heart/daemon/drift-detection.js +146 -0
  69. package/dist/heart/daemon/health-monitor.js +122 -1
  70. package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
  71. package/dist/heart/daemon/hooks/bundle-meta.js +115 -1
  72. package/dist/heart/daemon/http-health-probe.js +80 -0
  73. package/dist/heart/daemon/human-command-screens.js +234 -0
  74. package/dist/heart/daemon/human-readiness.js +114 -0
  75. package/dist/heart/daemon/inner-status.js +102 -0
  76. package/dist/heart/daemon/interactive-repair.js +394 -0
  77. package/dist/heart/daemon/launchd.js +37 -8
  78. package/dist/heart/daemon/log-tailer.js +82 -12
  79. package/dist/heart/daemon/logs-prune.js +110 -0
  80. package/dist/heart/daemon/mcp-canary.js +297 -0
  81. package/dist/heart/daemon/message-router.js +2 -2
  82. package/dist/heart/daemon/os-cron-deps.js +135 -0
  83. package/dist/heart/daemon/os-cron.js +14 -12
  84. package/dist/heart/daemon/ouro-bot-entry.js +4 -2
  85. package/dist/heart/daemon/ouro-entry.js +3 -1
  86. package/dist/heart/daemon/process-manager.js +375 -33
  87. package/dist/heart/daemon/provider-discovery.js +137 -0
  88. package/dist/heart/daemon/provider-ping-progress.js +83 -0
  89. package/dist/heart/daemon/pulse.js +475 -0
  90. package/dist/heart/daemon/readiness-repair.js +365 -0
  91. package/dist/heart/daemon/run-hooks.js +2 -0
  92. package/dist/heart/daemon/runtime-logging.js +67 -16
  93. package/dist/heart/daemon/runtime-metadata.js +3 -31
  94. package/dist/heart/daemon/safe-mode.js +161 -0
  95. package/dist/heart/daemon/sense-manager.js +353 -38
  96. package/dist/heart/daemon/session-id-resolver.js +131 -0
  97. package/dist/heart/daemon/skill-management-installer.js +94 -0
  98. package/dist/heart/daemon/socket-client.js +158 -11
  99. package/dist/heart/daemon/stale-bundle-prune.js +96 -0
  100. package/dist/heart/daemon/startup-tui.js +330 -0
  101. package/dist/heart/daemon/task-scheduler.js +3 -25
  102. package/dist/heart/daemon/terminal-ui.js +499 -0
  103. package/dist/heart/daemon/thoughts.js +162 -17
  104. package/dist/heart/daemon/up-progress.js +366 -0
  105. package/dist/heart/daemon/vault-items.js +56 -0
  106. package/dist/heart/delegation.js +1 -1
  107. package/dist/heart/habits/habit-migration.js +189 -0
  108. package/dist/heart/habits/habit-parser.js +140 -0
  109. package/dist/heart/habits/habit-runtime-state.js +100 -0
  110. package/dist/heart/habits/habit-scheduler.js +372 -0
  111. package/dist/heart/{daemon → hatch}/hatch-flow.js +52 -117
  112. package/dist/heart/{daemon → hatch}/hatch-specialist.js +6 -8
  113. package/dist/heart/{daemon → hatch}/specialist-prompt.js +12 -9
  114. package/dist/heart/{daemon → hatch}/specialist-tools.js +35 -12
  115. package/dist/heart/identity.js +200 -51
  116. package/dist/heart/kept-notes.js +357 -0
  117. package/dist/heart/kicks.js +1 -1
  118. package/dist/heart/machine-identity.js +161 -0
  119. package/dist/heart/mail-import-discovery.js +353 -0
  120. package/dist/heart/mailbox/mailbox-http-hooks.js +66 -0
  121. package/dist/heart/mailbox/mailbox-http-response.js +7 -0
  122. package/dist/heart/mailbox/mailbox-http-routes.js +246 -0
  123. package/dist/heart/mailbox/mailbox-http-static.js +103 -0
  124. package/dist/heart/mailbox/mailbox-http-transport.js +116 -0
  125. package/dist/heart/mailbox/mailbox-http.js +99 -0
  126. package/dist/heart/mailbox/mailbox-read.js +31 -0
  127. package/dist/heart/mailbox/mailbox-types.js +27 -0
  128. package/dist/heart/mailbox/mailbox-view.js +195 -0
  129. package/dist/heart/mailbox/readers/agent-machine.js +382 -0
  130. package/dist/heart/mailbox/readers/continuity-readers.js +338 -0
  131. package/dist/heart/mailbox/readers/mail.js +362 -0
  132. package/dist/heart/mailbox/readers/runtime-readers.js +651 -0
  133. package/dist/heart/mailbox/readers/sessions.js +232 -0
  134. package/dist/heart/mailbox/readers/shared.js +111 -0
  135. package/dist/heart/mcp/mcp-server.js +683 -0
  136. package/dist/heart/migrate-config.js +100 -0
  137. package/dist/heart/model-capabilities.js +19 -0
  138. package/dist/heart/platform.js +81 -0
  139. package/dist/heart/provider-attempt.js +134 -0
  140. package/dist/heart/provider-binding-resolver.js +255 -0
  141. package/dist/heart/provider-credentials.js +425 -0
  142. package/dist/heart/provider-failover.js +301 -0
  143. package/dist/heart/provider-models.js +81 -0
  144. package/dist/heart/provider-ping.js +262 -0
  145. package/dist/heart/provider-state.js +216 -0
  146. package/dist/heart/provider-visibility.js +188 -0
  147. package/dist/heart/providers/anthropic-token.js +131 -0
  148. package/dist/heart/providers/anthropic.js +139 -52
  149. package/dist/heart/providers/azure.js +97 -13
  150. package/dist/heart/providers/error-classification.js +127 -0
  151. package/dist/heart/providers/github-copilot.js +145 -0
  152. package/dist/heart/providers/minimax-vlm.js +189 -0
  153. package/dist/heart/providers/minimax.js +26 -8
  154. package/dist/heart/providers/openai-codex.js +55 -40
  155. package/dist/heart/runtime-capability-check.js +170 -0
  156. package/dist/heart/runtime-credentials.js +367 -0
  157. package/dist/heart/runtime-cwd.js +87 -0
  158. package/dist/heart/sense-truth.js +11 -4
  159. package/dist/heart/session-activity.js +43 -22
  160. package/dist/heart/session-events.js +1149 -0
  161. package/dist/heart/session-playback-cli-main.js +5 -0
  162. package/dist/heart/session-playback-cli.js +36 -0
  163. package/dist/heart/session-playback.js +231 -0
  164. package/dist/heart/session-stats-cli-main.js +5 -0
  165. package/dist/heart/session-stats.js +182 -0
  166. package/dist/heart/session-transcript.js +243 -0
  167. package/dist/heart/start-of-turn-packet.js +345 -0
  168. package/dist/heart/streaming.js +44 -27
  169. package/dist/heart/sync-classification.js +176 -0
  170. package/dist/heart/sync.js +449 -0
  171. package/dist/heart/target-resolution.js +9 -5
  172. package/dist/heart/tempo.js +93 -0
  173. package/dist/heart/temporal-view.js +41 -0
  174. package/dist/heart/timeouts.js +101 -0
  175. package/dist/heart/tool-activity-callbacks.js +59 -0
  176. package/dist/heart/tool-description.js +139 -0
  177. package/dist/heart/tool-friction.js +55 -0
  178. package/dist/heart/tool-loop.js +200 -0
  179. package/dist/heart/turn-context.js +381 -0
  180. package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +6 -5
  181. package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
  182. package/dist/heart/versioning/ouro-path-installer.js +426 -0
  183. package/dist/heart/versioning/ouro-version-manager.js +295 -0
  184. package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
  185. package/dist/heart/{daemon → versioning}/update-checker.js +6 -1
  186. package/dist/heart/{daemon → versioning}/update-hooks.js +63 -59
  187. package/dist/mailbox-ui/assets/index-BPr5vNuM.css +1 -0
  188. package/dist/mailbox-ui/assets/index-Cm51CY9W.js +61 -0
  189. package/dist/mailbox-ui/index.html +15 -0
  190. package/dist/mailroom/attention.js +167 -0
  191. package/dist/mailroom/autonomy.js +209 -0
  192. package/dist/mailroom/blob-store.js +674 -0
  193. package/dist/mailroom/body-cache.js +61 -0
  194. package/dist/mailroom/core.js +720 -0
  195. package/dist/mailroom/entry.js +160 -0
  196. package/dist/mailroom/file-store.js +430 -0
  197. package/dist/mailroom/mbox-import.js +383 -0
  198. package/dist/mailroom/outbound.js +380 -0
  199. package/dist/mailroom/policy.js +263 -0
  200. package/dist/mailroom/reader.js +233 -0
  201. package/dist/mailroom/search-cache.js +256 -0
  202. package/dist/mailroom/search-relevance.js +319 -0
  203. package/dist/mailroom/smtp-ingress.js +176 -0
  204. package/dist/mailroom/source-state.js +176 -0
  205. package/dist/mailroom/thread.js +109 -0
  206. package/dist/mailroom/travel-extract.js +89 -0
  207. package/dist/mind/bundle-manifest.js +7 -1
  208. package/dist/mind/context.js +165 -101
  209. package/dist/mind/diary-integrity.js +60 -0
  210. package/dist/mind/{memory.js → diary.js} +62 -75
  211. package/dist/mind/embedding-provider.js +60 -0
  212. package/dist/mind/file-state.js +179 -0
  213. package/dist/mind/friends/channel.js +30 -0
  214. package/dist/mind/friends/resolver.js +54 -2
  215. package/dist/mind/friends/store-file.js +39 -3
  216. package/dist/mind/friends/types.js +2 -2
  217. package/dist/mind/journal-index.js +161 -0
  218. package/dist/mind/note-search.js +268 -0
  219. package/dist/mind/obligation-steering.js +221 -0
  220. package/dist/mind/pending.js +4 -0
  221. package/dist/mind/prompt-refresh.js +3 -2
  222. package/dist/mind/prompt.js +995 -123
  223. package/dist/mind/provenance-trust.js +26 -0
  224. package/dist/mind/scrutiny.js +173 -0
  225. package/dist/nerves/cli-logging.js +7 -1
  226. package/dist/nerves/coverage/audit-rules.js +15 -6
  227. package/dist/nerves/coverage/audit.js +28 -2
  228. package/dist/nerves/coverage/cli.js +1 -1
  229. package/dist/nerves/coverage/contract.js +5 -5
  230. package/dist/nerves/coverage/file-completeness.js +139 -5
  231. package/dist/nerves/coverage/run-artifacts.js +1 -1
  232. package/dist/nerves/event-buffer.js +111 -0
  233. package/dist/nerves/index.js +224 -4
  234. package/dist/nerves/observation.js +20 -0
  235. package/dist/nerves/redact.js +79 -0
  236. package/dist/nerves/review/cli-main.js +5 -0
  237. package/dist/nerves/review/cli.js +156 -0
  238. package/dist/nerves/review/core.js +152 -0
  239. package/dist/nerves/runtime.js +5 -1
  240. package/dist/repertoire/ado-client.js +15 -56
  241. package/dist/repertoire/ado-semantic.js +11 -10
  242. package/dist/repertoire/api-client.js +97 -0
  243. package/dist/repertoire/bitwarden-store.js +816 -0
  244. package/dist/repertoire/bundle-templates.js +72 -0
  245. package/dist/repertoire/bw-installer.js +180 -0
  246. package/dist/repertoire/coding/codex-jsonl.js +64 -0
  247. package/dist/repertoire/coding/context-pack.js +330 -0
  248. package/dist/repertoire/coding/feedback.js +197 -30
  249. package/dist/repertoire/coding/manager.js +158 -9
  250. package/dist/repertoire/coding/spawner.js +55 -9
  251. package/dist/repertoire/coding/tools.js +170 -7
  252. package/dist/repertoire/commerce-errors.js +109 -0
  253. package/dist/repertoire/commerce-self-test.js +156 -0
  254. package/dist/repertoire/credential-access.js +111 -0
  255. package/dist/repertoire/duffel-client.js +185 -0
  256. package/dist/repertoire/github-client.js +14 -55
  257. package/dist/repertoire/graph-client.js +11 -52
  258. package/dist/repertoire/guardrails.js +396 -0
  259. package/dist/repertoire/mcp-client.js +295 -0
  260. package/dist/repertoire/mcp-manager.js +362 -0
  261. package/dist/repertoire/mcp-tools.js +63 -0
  262. package/dist/repertoire/shell-sessions.js +133 -0
  263. package/dist/repertoire/skills.js +15 -24
  264. package/dist/repertoire/stripe-client.js +131 -0
  265. package/dist/repertoire/tasks/board.js +31 -5
  266. package/dist/repertoire/tasks/fix.js +182 -0
  267. package/dist/repertoire/tasks/index.js +16 -4
  268. package/dist/repertoire/tasks/lifecycle.js +2 -2
  269. package/dist/repertoire/tasks/parser.js +3 -2
  270. package/dist/repertoire/tasks/scanner.js +194 -37
  271. package/dist/repertoire/tasks/transitions.js +16 -78
  272. package/dist/repertoire/tool-results.js +29 -0
  273. package/dist/repertoire/tools-attachments.js +317 -0
  274. package/dist/repertoire/tools-base.js +47 -1075
  275. package/dist/repertoire/tools-bluebubbles.js +1 -0
  276. package/dist/repertoire/tools-bridge.js +142 -0
  277. package/dist/repertoire/tools-bundle.js +984 -0
  278. package/dist/repertoire/tools-config.js +185 -0
  279. package/dist/repertoire/tools-continuity.js +248 -0
  280. package/dist/repertoire/tools-credential.js +381 -0
  281. package/dist/repertoire/tools-files.js +342 -0
  282. package/dist/repertoire/tools-flight.js +224 -0
  283. package/dist/repertoire/tools-flow.js +119 -0
  284. package/dist/repertoire/tools-github.js +1 -7
  285. package/dist/repertoire/tools-mail.js +1857 -0
  286. package/dist/repertoire/tools-notes.js +421 -0
  287. package/dist/repertoire/tools-session.js +750 -0
  288. package/dist/repertoire/tools-shell.js +120 -0
  289. package/dist/repertoire/tools-stripe.js +180 -0
  290. package/dist/repertoire/tools-surface.js +243 -0
  291. package/dist/repertoire/tools-teams.js +9 -39
  292. package/dist/repertoire/tools-travel.js +125 -0
  293. package/dist/repertoire/tools-trip.js +604 -0
  294. package/dist/repertoire/tools-user-profile.js +144 -0
  295. package/dist/repertoire/tools-vault.js +40 -0
  296. package/dist/repertoire/tools.js +108 -100
  297. package/dist/repertoire/travel-api-client.js +360 -0
  298. package/dist/repertoire/user-profile.js +131 -0
  299. package/dist/repertoire/vault-setup.js +246 -0
  300. package/dist/repertoire/vault-unlock.js +561 -0
  301. package/dist/scripts/claude-code-hook.js +41 -0
  302. package/dist/scripts/claude-code-stop-hook.js +47 -0
  303. package/dist/senses/attention-queue.js +116 -0
  304. package/dist/senses/bluebubbles/active-turns.js +216 -0
  305. package/dist/senses/bluebubbles/attachment-cache.js +53 -0
  306. package/dist/senses/bluebubbles/attachment-download.js +137 -0
  307. package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +219 -18
  308. package/dist/senses/bluebubbles/entry.js +77 -0
  309. package/dist/senses/{bluebubbles-inbound-log.js → bluebubbles/inbound-log.js} +20 -3
  310. package/dist/senses/bluebubbles/index.js +2305 -0
  311. package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -70
  312. package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +33 -12
  313. package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +3 -3
  314. package/dist/senses/bluebubbles/processed-log.js +133 -0
  315. package/dist/senses/bluebubbles/replay.js +137 -0
  316. package/dist/senses/{bluebubbles-runtime-state.js → bluebubbles/runtime-state.js} +30 -2
  317. package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
  318. package/dist/senses/cli/bracketed-paste.js +82 -0
  319. package/dist/senses/cli/image-paste.js +287 -0
  320. package/dist/senses/cli/image-ref-navigation.js +75 -0
  321. package/dist/senses/cli/ink-app.js +156 -0
  322. package/dist/senses/cli/inline-diff.js +64 -0
  323. package/dist/senses/cli/input-keys.js +174 -0
  324. package/dist/senses/cli/kill-ring.js +86 -0
  325. package/dist/senses/cli/message-list.js +51 -0
  326. package/dist/senses/cli/ouro-tui.js +607 -0
  327. package/dist/senses/cli/spinner-imperative.js +135 -0
  328. package/dist/senses/cli/spinner.js +101 -0
  329. package/dist/senses/cli/status-line.js +60 -0
  330. package/dist/senses/cli/streaming-markdown.js +526 -0
  331. package/dist/senses/cli/tool-display.js +85 -0
  332. package/dist/senses/cli/tool-render.js +85 -0
  333. package/dist/senses/cli/tui-store.js +240 -0
  334. package/dist/senses/cli/virtual-list.js +35 -0
  335. package/dist/senses/cli-entry.js +60 -8
  336. package/dist/senses/cli-layout.js +187 -0
  337. package/dist/senses/cli.js +520 -209
  338. package/dist/senses/commands.js +66 -3
  339. package/dist/senses/habit-turn-message.js +108 -0
  340. package/dist/senses/inner-dialog-worker.js +175 -21
  341. package/dist/senses/inner-dialog.js +330 -27
  342. package/dist/senses/mail-entry.js +66 -0
  343. package/dist/senses/mail.js +379 -0
  344. package/dist/senses/pipeline.js +569 -182
  345. package/dist/senses/proactive-content-guard.js +51 -0
  346. package/dist/senses/shared-turn.js +248 -0
  347. package/dist/senses/surface-tool.js +68 -0
  348. package/dist/senses/teams-entry.js +60 -8
  349. package/dist/senses/teams.js +387 -98
  350. package/dist/senses/trust-gate.js +100 -5
  351. package/dist/trips/core.js +138 -0
  352. package/dist/trips/store.js +146 -0
  353. package/package.json +38 -7
  354. package/skills/agent-commerce.md +106 -0
  355. package/skills/browser-navigation.md +117 -0
  356. package/skills/commerce-setup-guide.md +116 -0
  357. package/skills/commerce-setup.md +84 -0
  358. package/skills/configure-dev-tools.md +101 -0
  359. package/skills/travel-planning.md +138 -0
  360. package/dist/heart/daemon/ouro-path-installer.js +0 -178
  361. package/dist/heart/daemon/subagent-installer.js +0 -166
  362. package/dist/heart/session-recall.js +0 -116
  363. package/dist/mind/associative-recall.js +0 -209
  364. package/dist/senses/bluebubbles-entry.js +0 -13
  365. package/dist/senses/bluebubbles.js +0 -1177
  366. package/dist/senses/debug-activity.js +0 -148
  367. package/subagents/README.md +0 -86
  368. package/subagents/work-doer.md +0 -237
  369. package/subagents/work-merger.md +0 -618
  370. package/subagents/work-planner.md +0 -390
  371. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
  372. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
  373. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
  374. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
  375. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
  376. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
  377. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
  378. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
  379. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
  380. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
  381. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
  382. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
  383. /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
  384. /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
  385. /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
  386. /package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +0 -0
@@ -34,21 +34,302 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.OuroDaemon = void 0;
37
+ exports.parseOrphanPidsFromPs = parseOrphanPidsFromPs;
38
+ exports.filterPidfilePidsToActualOrphans = filterPidfilePidsToActualOrphans;
39
+ exports.mergeUniqueOrphanPids = mergeUniqueOrphanPids;
40
+ exports.killOrphanProcesses = killOrphanProcesses;
41
+ exports.writePidfile = writePidfile;
42
+ exports.handleAgentSenseTurn = handleAgentSenseTurn;
37
43
  const fs = __importStar(require("fs"));
38
44
  const net = __importStar(require("net"));
45
+ const os = __importStar(require("os"));
39
46
  const path = __importStar(require("path"));
40
47
  const identity_1 = require("../identity");
48
+ const agent_discovery_1 = require("./agent-discovery");
41
49
  const runtime_1 = require("../../nerves/runtime");
42
50
  const runtime_metadata_1 = require("./runtime-metadata");
43
51
  const runtime_mode_1 = require("./runtime-mode");
44
- const update_hooks_1 = require("./update-hooks");
52
+ const update_hooks_1 = require("../versioning/update-hooks");
45
53
  const bundle_meta_1 = require("./hooks/bundle-meta");
54
+ const agent_config_v2_1 = require("./hooks/agent-config-v2");
46
55
  const bundle_manifest_1 = require("../../mind/bundle-manifest");
47
- const update_checker_1 = require("./update-checker");
48
- const staged_restart_1 = require("./staged-restart");
56
+ const update_checker_1 = require("../versioning/update-checker");
49
57
  const child_process_1 = require("child_process");
50
58
  const pending_1 = require("../../mind/pending");
59
+ const agent_service_1 = require("./agent-service");
51
60
  const channel_1 = require("../../mind/friends/channel");
61
+ const mcp_manager_1 = require("../../repertoire/mcp-manager");
62
+ const mailbox_http_1 = require("../mailbox/mailbox-http");
63
+ const mailbox_types_1 = require("../mailbox/mailbox-types");
64
+ const mailbox_read_1 = require("../mailbox/mailbox-read");
65
+ const mailbox_view_1 = require("../mailbox/mailbox-view");
66
+ const provider_visibility_1 = require("../provider-visibility");
67
+ const socket_client_1 = require("./socket-client");
68
+ const PIDFILE_PATH = path.join(os.homedir(), ".ouro-cli", "daemon.pids");
69
+ /**
70
+ * Defense-in-depth: detect if we're running under vitest. The pidfile lives
71
+ * at a hardcoded path under the user's real ~/.ouro-cli/ — there's no DI
72
+ * seam to redirect it. So when a test creates a real OuroDaemon and calls
73
+ * start(), the daemon's killOrphanProcesses() reads the REAL pidfile,
74
+ * ps-verifies the PIDs, and SIGTERMs the production daemon. We saw this
75
+ * cause an outage on 2026-04-08 (alpha.265 daemon killed 93s after startup
76
+ * by a vitest test that called daemon.start()).
77
+ *
78
+ * Both killOrphanProcesses() and writePidfile() short-circuit under vitest
79
+ * to make the production pidfile sacred. Tests that need to verify these
80
+ * functions' behavior should use the extracted pure helpers
81
+ * (parseOrphanPidsFromPs, filterPidfilePidsToActualOrphans).
82
+ */
83
+ function isVitestProcess() {
84
+ /* v8 ignore next -- defensive: process and process.argv always exist in node @preserve */
85
+ if (typeof process === "undefined" || !Array.isArray(process.argv))
86
+ return false;
87
+ return process.argv.some((arg) => typeof arg === "string" && arg.includes("vitest"));
88
+ }
89
+ /**
90
+ * Scan `ps -eo pid,ppid,command` output for daemon-owned entry points whose
91
+ * parent has died (PPID reparented to init/PID 1). Returns the list of PIDs
92
+ * that are safe to SIGTERM — true orphans, not children of live sibling
93
+ * daemons running from worktrees, test suites, or other users of the harness.
94
+ *
95
+ * Exported so unit tests can exercise the filter without shelling out.
96
+ */
97
+ function parseOrphanPidsFromPs(psOutput, selfPid) {
98
+ const orphans = [];
99
+ for (const line of psOutput.split("\n")) {
100
+ // Explicitly exclude MCP server processes — they share a harness entry
101
+ // point but are not daemon children and must never be killed.
102
+ if (line.includes("mcp-serve") || line.includes("mcp serve"))
103
+ continue;
104
+ // Match only daemon-owned JS entry points.
105
+ if (!line.includes("agent-entry.js")
106
+ && !line.includes("daemon-entry.js")
107
+ && !line.includes("bluebubbles/entry.js")
108
+ && !line.includes("mail-entry.js")
109
+ && !line.includes("teams-entry.js"))
110
+ continue;
111
+ // Parse `<pid> <ppid> <command...>`. ps pads these with leading spaces.
112
+ // Regex guarantees both groups are \d+ so parseInt can't produce NaN.
113
+ const match = line.trim().match(/^(\d+)\s+(\d+)\s/);
114
+ if (!match)
115
+ continue;
116
+ const pid = parseInt(match[1], 10);
117
+ const ppid = parseInt(match[2], 10);
118
+ if (pid === selfPid)
119
+ continue;
120
+ // CRITICAL: only kill processes whose parent is init (PID 1). A live
121
+ // PPID means the process belongs to another daemon instance (parallel
122
+ // test run, sibling worktree, another user of /tmp/ouroboros-daemon.sock).
123
+ // Killing those will crash unrelated harnesses — we saw this in B6
124
+ // when a vitest worker's daemon killed slugger's production children.
125
+ if (ppid !== 1)
126
+ continue;
127
+ orphans.push(pid);
128
+ }
129
+ return orphans;
130
+ }
131
+ /**
132
+ * Given a list of PIDs from the pidfile, return only those that are actual
133
+ * orphans (PPID reparented to init/PID 1). Protects against a polluted
134
+ * pidfile killing a PID that the OS has reassigned to an unrelated process.
135
+ *
136
+ * Implementation: shells out to `ps -p <csv> -o pid,ppid` for a batch lookup.
137
+ * Returns the empty list if ps fails — safer to skip cleanup than to
138
+ * wildcard-kill on a bad read.
139
+ *
140
+ * Exported for direct unit coverage.
141
+ */
142
+ function filterPidfilePidsToActualOrphans(candidatePids, psRunner = runPsCheck) {
143
+ if (candidatePids.length === 0)
144
+ return [];
145
+ const psOutput = psRunner(candidatePids);
146
+ if (psOutput === null)
147
+ return [];
148
+ const survivingOrphans = [];
149
+ // `ps -p x,y,z -o pid,ppid` emits a header line then one row per found PID.
150
+ // PIDs not found (already exited) are silently omitted — which is the
151
+ // correct behavior for us: we only want to kill live orphans.
152
+ for (const line of psOutput.split("\n")) {
153
+ const match = line.trim().match(/^(\d+)\s+(\d+)$/);
154
+ if (!match)
155
+ continue;
156
+ const pid = parseInt(match[1], 10);
157
+ const ppid = parseInt(match[2], 10);
158
+ if (ppid !== 1)
159
+ continue;
160
+ if (!candidatePids.includes(pid))
161
+ continue;
162
+ survivingOrphans.push(pid);
163
+ }
164
+ return survivingOrphans;
165
+ }
166
+ function mergeUniqueOrphanPids(...sources) {
167
+ const merged = [];
168
+ const seen = new Set();
169
+ for (const source of sources) {
170
+ for (const pid of source) {
171
+ if (seen.has(pid))
172
+ continue;
173
+ seen.add(pid);
174
+ merged.push(pid);
175
+ }
176
+ }
177
+ return merged;
178
+ }
179
+ /* v8 ignore start -- shells out to ps; covered by filterPidfilePidsToActualOrphans unit tests via injected runner @preserve */
180
+ function runPsCheck(pids) {
181
+ try {
182
+ const csv = pids.join(",");
183
+ return (0, child_process_1.execSync)(`ps -p ${csv} -o pid=,ppid=`, { encoding: "utf-8", timeout: 5000 });
184
+ }
185
+ catch {
186
+ // ps returns non-zero when none of the requested PIDs exist. Treat as
187
+ // "no survivors" rather than an error.
188
+ return "";
189
+ }
190
+ }
191
+ /* v8 ignore stop */
192
+ /**
193
+ * Kill all ouro processes from the previous daemon instance using the pidfile.
194
+ * On startup, reads PIDs from ~/.ouro-cli/daemon.pids, kills them all, then
195
+ * deletes the file. The new daemon writes its own PIDs after spawning.
196
+ *
197
+ * Safety: pidfile contents are verified before being killed — each PID must
198
+ * be an actual orphan (PPID reparented to init/PID 1) via
199
+ * `filterPidfilePidsToActualOrphans`. Otherwise a polluted pidfile (written
200
+ * by a test, or a crashed daemon whose PIDs have since been reused by the
201
+ * OS) could SIGTERM unrelated processes.
202
+ *
203
+ * Falls back to ps-based scanning scoped to true orphans (PPID=1) if the
204
+ * pidfile doesn't exist (first run, previous daemon crashed before writing,
205
+ * manual cleanup). The scope is narrow on purpose — see parseOrphanPidsFromPs.
206
+ */
207
+ /* v8 ignore start -- process lifecycle: uses kill/ps, tested via deployment @preserve */
208
+ function isProductionDaemonSocketPath(socketPath) {
209
+ return socketPath === socket_client_1.DEFAULT_DAEMON_SOCKET_PATH;
210
+ }
211
+ function killOrphanProcesses(socketPath = socket_client_1.DEFAULT_DAEMON_SOCKET_PATH) {
212
+ if (!isProductionDaemonSocketPath(socketPath)) {
213
+ (0, runtime_1.emitNervesEvent)({
214
+ level: "warn",
215
+ component: "daemon",
216
+ event: "daemon.orphan_cleanup_nonproduction_blocked",
217
+ message: "blocked orphan cleanup for non-production daemon socket",
218
+ meta: { socketPath, pidfilePath: PIDFILE_PATH },
219
+ });
220
+ return;
221
+ }
222
+ if (isVitestProcess()) {
223
+ (0, runtime_1.emitNervesEvent)({
224
+ level: "warn",
225
+ component: "daemon",
226
+ event: "daemon.orphan_cleanup_test_blocked",
227
+ message: "blocked killOrphanProcesses from touching real pidfile under vitest",
228
+ meta: { pidfilePath: PIDFILE_PATH },
229
+ });
230
+ return;
231
+ }
232
+ try {
233
+ let pidfileOrphans = [];
234
+ let scanOrphans = [];
235
+ // Primary: read pidfile from previous daemon
236
+ try {
237
+ const raw = fs.readFileSync(PIDFILE_PATH, "utf-8");
238
+ const candidates = raw.split("\n")
239
+ .map((s) => parseInt(s.trim(), 10))
240
+ .filter((n) => !isNaN(n) && n !== process.pid);
241
+ // Verify each candidate is an actual live orphan before killing. See
242
+ // docstring above for why this matters.
243
+ pidfileOrphans = filterPidfilePidsToActualOrphans(candidates);
244
+ fs.unlinkSync(PIDFILE_PATH);
245
+ }
246
+ catch {
247
+ // No pidfile — the ps scan below still covers true orphans.
248
+ }
249
+ // Always supplement the pidfile with the scoped ps scan. A stale or
250
+ // partial pidfile can otherwise kill one old daemon while leaving a
251
+ // sibling PPID=1 daemon alive without a socket.
252
+ try {
253
+ const result = (0, child_process_1.execSync)("ps -eo pid,ppid,command", { encoding: "utf-8", timeout: 5000 });
254
+ scanOrphans = parseOrphanPidsFromPs(result, process.pid);
255
+ }
256
+ catch { /* ps failed — best effort */ }
257
+ const pidsToKill = mergeUniqueOrphanPids(pidfileOrphans, scanOrphans);
258
+ if (pidsToKill.length > 0) {
259
+ for (const pid of pidsToKill) {
260
+ try {
261
+ process.kill(pid, "SIGTERM");
262
+ }
263
+ catch { /* already exited */ }
264
+ }
265
+ (0, runtime_1.emitNervesEvent)({
266
+ component: "daemon",
267
+ event: "daemon.orphan_cleanup",
268
+ message: `killed ${pidsToKill.length} orphaned ouro processes`,
269
+ meta: { pids: pidsToKill },
270
+ });
271
+ }
272
+ }
273
+ catch (error) {
274
+ (0, runtime_1.emitNervesEvent)({
275
+ level: "warn",
276
+ component: "daemon",
277
+ event: "daemon.orphan_cleanup_error",
278
+ message: "failed to clean up orphaned ouro processes",
279
+ meta: { error: error instanceof Error ? error.message : String(error) },
280
+ });
281
+ }
282
+ }
283
+ /**
284
+ * Write all managed PIDs (daemon + children) to the pidfile.
285
+ * Called after all agents and senses are spawned.
286
+ */
287
+ function writePidfile(extraPids = [], socketPath = socket_client_1.DEFAULT_DAEMON_SOCKET_PATH) {
288
+ if (!isProductionDaemonSocketPath(socketPath)) {
289
+ (0, runtime_1.emitNervesEvent)({
290
+ level: "warn",
291
+ component: "daemon",
292
+ event: "daemon.write_pidfile_nonproduction_blocked",
293
+ message: "blocked production pidfile write for non-production daemon socket",
294
+ meta: { socketPath, pidfilePath: PIDFILE_PATH, attemptedPids: extraPids.length },
295
+ });
296
+ return;
297
+ }
298
+ if (isVitestProcess()) {
299
+ (0, runtime_1.emitNervesEvent)({
300
+ level: "warn",
301
+ component: "daemon",
302
+ event: "daemon.write_pidfile_test_blocked",
303
+ message: "blocked writePidfile from clobbering real pidfile under vitest",
304
+ meta: { pidfilePath: PIDFILE_PATH, attemptedPids: extraPids.length },
305
+ });
306
+ return;
307
+ }
308
+ try {
309
+ const pids = [process.pid, ...extraPids].filter(Boolean);
310
+ fs.mkdirSync(path.dirname(PIDFILE_PATH), { recursive: true });
311
+ fs.writeFileSync(PIDFILE_PATH, pids.join("\n") + "\n", "utf-8");
312
+ }
313
+ catch { /* best effort */ }
314
+ }
315
+ function readSocketIdentity(socketPath) {
316
+ try {
317
+ const stats = fs.lstatSync(socketPath);
318
+ return {
319
+ dev: stats.dev,
320
+ ino: stats.ino,
321
+ ctimeMs: stats.ctimeMs,
322
+ };
323
+ }
324
+ catch {
325
+ return null;
326
+ }
327
+ }
328
+ function sameSocketIdentity(left, right) {
329
+ if (!left || !right)
330
+ return false;
331
+ return left.dev === right.dev && left.ino === right.ino && left.ctimeMs === right.ctimeMs;
332
+ }
52
333
  function buildWorkerRows(snapshots) {
53
334
  return snapshots.map((snapshot) => ({
54
335
  agent: snapshot.name,
@@ -57,19 +338,60 @@ function buildWorkerRows(snapshots) {
57
338
  pid: snapshot.pid,
58
339
  restartCount: snapshot.restartCount,
59
340
  startedAt: snapshot.startedAt,
341
+ lastExitCode: snapshot.lastExitCode ?? null,
342
+ lastSignal: snapshot.lastSignal ?? null,
343
+ errorReason: snapshot.errorReason ?? null,
344
+ fixHint: snapshot.fixHint ?? null,
60
345
  }));
61
346
  }
347
+ function unhealthySenseRows(senses) {
348
+ return senses.filter((row) => {
349
+ if (!row.enabled)
350
+ return false;
351
+ if (row.status === "disabled" || row.status === "not_attached")
352
+ return false;
353
+ if (row.status === "interactive" || row.status === "running")
354
+ return false;
355
+ return true;
356
+ });
357
+ }
358
+ function unhealthyHealthChecks(healthChecks) {
359
+ return healthChecks.filter((row) => row.status !== "ok");
360
+ }
361
+ function overviewHealth(workers, senses, healthChecks = []) {
362
+ if (!workers.every((worker) => worker.status === "running"))
363
+ return "warn";
364
+ if (unhealthySenseRows(senses).length > 0)
365
+ return "warn";
366
+ if (unhealthyHealthChecks(healthChecks).length > 0)
367
+ return "warn";
368
+ return "ok";
369
+ }
62
370
  function formatStatusSummary(payload) {
63
- if (payload.overview.workerCount === 0 && payload.overview.senseCount === 0) {
371
+ if (payload.overview.workerCount === 0 && payload.overview.senseCount === 0 && (payload.healthChecks ?? []).length === 0) {
64
372
  return "no managed agents";
65
373
  }
66
- const rows = [
67
- ...payload.workers.map((row) => `${row.agent}/${row.worker}:${row.status}`),
68
- ...payload.senses
69
- .filter((row) => row.enabled)
70
- .map((row) => `${row.agent}/${row.sense}:${row.status}`),
374
+ const degraded = [
375
+ ...payload.workers
376
+ .filter((row) => row.status !== "running")
377
+ .map((row) => `worker:${row.agent}/${row.worker}:${row.status}`),
378
+ ...unhealthySenseRows(payload.senses)
379
+ .map((row) => `sense:${row.agent}/${row.sense}:${row.status}`),
380
+ ...(payload.healthChecks ?? [])
381
+ .filter((row) => row.status !== "ok")
382
+ .map((row) => `health-check:${row.name}:${row.status}`),
71
383
  ];
72
- const detail = rows.length > 0 ? `\titems=${rows.join(",")}` : "";
384
+ const detail = degraded.length > 0 ? `\tdegraded=${degraded.join(",")}` : "";
385
+ if (!detail) {
386
+ const rows = [
387
+ ...payload.workers.map((row) => `${row.agent}/${row.worker}:${row.status}`),
388
+ ...payload.senses
389
+ .filter((row) => row.enabled)
390
+ .map((row) => `${row.agent}/${row.sense}:${row.status}`),
391
+ ];
392
+ const items = rows.length > 0 ? `\titems=${rows.join(",")}` : "";
393
+ return `daemon=${payload.overview.daemon}\tworkers=${payload.overview.workerCount}\tsenses=${payload.overview.senseCount}\thealth=${payload.overview.health}${items}`;
394
+ }
73
395
  return `daemon=${payload.overview.daemon}\tworkers=${payload.overview.workerCount}\tsenses=${payload.overview.senseCount}\thealth=${payload.overview.health}${detail}`;
74
396
  }
75
397
  function parseIncomingCommand(raw) {
@@ -89,6 +411,35 @@ function parseIncomingCommand(raw) {
89
411
  }
90
412
  return parsed;
91
413
  }
414
+ /**
415
+ * Handle agent.senseTurn command: runs a full agent turn via the daemon process.
416
+ * Dynamic import lazy-loads shared-turn. Hot-reload works because ouro dev
417
+ * restarts the daemon process (fresh module cache).
418
+ */
419
+ async function handleAgentSenseTurn(command) {
420
+ try {
421
+ const { setAgentName } = await Promise.resolve().then(() => __importStar(require("../identity")));
422
+ setAgentName(command.agent);
423
+ const { runSenseTurn } = await Promise.resolve().then(() => __importStar(require("../../senses/shared-turn")));
424
+ const result = await runSenseTurn({
425
+ agentName: command.agent,
426
+ channel: command.channel,
427
+ sessionKey: command.sessionKey,
428
+ friendId: command.friendId,
429
+ userMessage: command.message,
430
+ });
431
+ return {
432
+ ok: true,
433
+ message: result.response,
434
+ data: { ponderDeferred: result.ponderDeferred },
435
+ };
436
+ }
437
+ catch (error) {
438
+ /* v8 ignore next -- branch: String(error) fallback only for non-Error throws @preserve */
439
+ const errorMessage = error instanceof Error ? error.message : String(error);
440
+ return { ok: false, error: `sense turn failed: ${errorMessage}` };
441
+ }
442
+ }
92
443
  class OuroDaemon {
93
444
  socketPath;
94
445
  processManager;
@@ -97,7 +448,13 @@ class OuroDaemon {
97
448
  router;
98
449
  senseManager;
99
450
  bundlesRoot;
451
+ mode;
100
452
  server = null;
453
+ mailboxServer = null;
454
+ socketIdentity = null;
455
+ senseAutostartTimer = null;
456
+ mailboxServerFactory;
457
+ onStopCommandComplete;
101
458
  constructor(options) {
102
459
  this.socketPath = options.socketPath;
103
460
  this.processManager = options.processManager;
@@ -106,6 +463,77 @@ class OuroDaemon {
106
463
  this.router = options.router;
107
464
  this.senseManager = options.senseManager ?? null;
108
465
  this.bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
466
+ this.mode = options.mode ?? "production";
467
+ this.mailboxServerFactory = options.mailboxServerFactory ?? this.createDefaultMailboxServer.bind(this);
468
+ this.onStopCommandComplete = options.onStopCommandComplete ?? null;
469
+ }
470
+ /* v8 ignore start -- default mailbox server wiring: production-only path, tests inject mailboxServerFactory stub instead. startMailboxHttpServer itself has full coverage in mailbox-http.test.ts @preserve */
471
+ createDefaultMailboxServer() {
472
+ return (0, mailbox_http_1.startMailboxHttpServer)({
473
+ host: "127.0.0.1",
474
+ port: mailbox_types_1.MAILBOX_DEFAULT_PORT,
475
+ bundlesRoot: this.bundlesRoot,
476
+ readMachineState: () => (0, mailbox_read_1.readMailboxMachineState)({ bundlesRoot: this.bundlesRoot }),
477
+ readMachineView: ({ machine }) => {
478
+ const overview = this.buildStatusPayload().overview;
479
+ return (0, mailbox_view_1.buildMailboxMachineView)({
480
+ machine,
481
+ daemon: {
482
+ status: overview.daemon,
483
+ health: overview.health,
484
+ mode: overview.mode,
485
+ socketPath: overview.socketPath,
486
+ mailboxUrl: overview.mailboxUrl,
487
+ entryPath: overview.entryPath,
488
+ workerCount: overview.workerCount,
489
+ senseCount: overview.senseCount,
490
+ },
491
+ });
492
+ },
493
+ readAgentState: (agentName) => (0, mailbox_read_1.readMailboxAgentState)(agentName, { bundlesRoot: this.bundlesRoot }),
494
+ readAgentView: (agentName) => {
495
+ const agent = (0, mailbox_read_1.readMailboxAgentState)(agentName, { bundlesRoot: this.bundlesRoot });
496
+ return (0, mailbox_view_1.buildMailboxAgentView)({
497
+ agent,
498
+ viewer: { kind: "human" },
499
+ });
500
+ },
501
+ });
502
+ }
503
+ /* v8 ignore stop */
504
+ buildStatusPayload() {
505
+ const snapshots = this.processManager.listAgentSnapshots();
506
+ const workers = buildWorkerRows(snapshots);
507
+ const senses = this.senseManager?.listSenseRows() ?? [];
508
+ const healthChecks = this.healthMonitor.getLastResults?.() ?? [];
509
+ const repoRoot = (0, identity_1.getRepoRoot)();
510
+ const sync = (0, agent_discovery_1.listBundleSyncRows)({ bundlesRoot: this.bundlesRoot });
511
+ const agents = (0, agent_discovery_1.listAllBundleAgents)({ bundlesRoot: this.bundlesRoot });
512
+ const providers = agents.flatMap((agent) => (0, provider_visibility_1.providerVisibilityStatusRows)((0, provider_visibility_1.buildAgentProviderVisibility)({
513
+ agentName: agent.name,
514
+ agentRoot: path.join(this.bundlesRoot, `${agent.name}.ouro`),
515
+ })));
516
+ const mailboxUrl = this.mailboxServer?.origin ?? "http://127.0.0.1:0";
517
+ return {
518
+ overview: {
519
+ daemon: "running",
520
+ health: overviewHealth(workers, senses, healthChecks),
521
+ socketPath: this.socketPath,
522
+ mailboxUrl,
523
+ outlookUrl: mailboxUrl,
524
+ ...(0, runtime_metadata_1.getRuntimeMetadata)(),
525
+ workerCount: workers.length,
526
+ senseCount: senses.length,
527
+ entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
528
+ mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
529
+ },
530
+ workers,
531
+ senses,
532
+ ...(healthChecks.length > 0 ? { healthChecks } : {}),
533
+ sync,
534
+ agents,
535
+ ...(providers.length > 0 ? { providers } : {}),
536
+ };
109
537
  }
110
538
  async start() {
111
539
  if (this.server)
@@ -116,62 +544,179 @@ class OuroDaemon {
116
544
  message: "starting daemon server",
117
545
  meta: { socketPath: this.socketPath },
118
546
  });
547
+ try {
548
+ await this.startInner();
549
+ }
550
+ catch (err) {
551
+ // Emit a paired terminating event (`_error`) so the nerves audit's
552
+ // start_end_pairing rule is satisfied when startup throws mid-sequence
553
+ // and `stop()` (which emits `server_end`) is never called.
554
+ (0, runtime_1.emitNervesEvent)({
555
+ level: "error",
556
+ component: "daemon",
557
+ event: "daemon.server_error",
558
+ message: "daemon start failed",
559
+ meta: {
560
+ error: err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err),
561
+ },
562
+ });
563
+ throw err;
564
+ }
565
+ }
566
+ async startInner() {
119
567
  // Register update hooks and apply pending updates before starting agents
120
568
  (0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
569
+ (0, update_hooks_1.registerUpdateHook)(agent_config_v2_1.agentConfigV2Hook);
121
570
  const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
122
571
  await (0, update_hooks_1.applyPendingUpdates)(this.bundlesRoot, currentVersion);
123
572
  // Start periodic update checker (polls npm registry every 30 minutes)
124
- const bundlesRoot = this.bundlesRoot;
125
- const daemon = this;
126
- (0, update_checker_1.startUpdateChecker)({
127
- currentVersion,
128
- deps: {
129
- distTag: "alpha",
130
- fetchRegistryJson: /* v8 ignore next -- integration: real HTTP fetch @preserve */ async () => {
131
- const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
132
- return res.json();
133
- },
134
- },
135
- onUpdate: /* v8 ignore start -- integration: real npm install + process spawn @preserve */ async (result) => {
136
- if (!result.latestVersion)
137
- return;
138
- await (0, staged_restart_1.performStagedRestart)(result.latestVersion, {
139
- execSync: (cmd) => (0, child_process_1.execSync)(cmd, { stdio: "inherit" }),
140
- spawnSync: child_process_1.spawnSync,
141
- resolveNewCodePath: (_version) => {
142
- try {
143
- const resolved = (0, child_process_1.execSync)(`node -e "console.log(require.resolve('@ouro.bot/cli/package.json'))"`, { encoding: "utf-8" }).trim();
144
- return resolved ? path.dirname(resolved) : null;
145
- }
146
- catch {
147
- return null;
148
- }
573
+ // Skip in dev mode — dev builds should not auto-update from npm
574
+ if (this.mode === "dev") {
575
+ (0, runtime_1.emitNervesEvent)({
576
+ component: "daemon",
577
+ event: "daemon.update_checker_skip",
578
+ message: "skipping update checker in dev mode",
579
+ meta: { reason: "dev mode" },
580
+ });
581
+ }
582
+ else {
583
+ (0, update_checker_1.startUpdateChecker)({
584
+ currentVersion,
585
+ deps: {
586
+ distTag: update_checker_1.CLI_UPDATE_DIST_TAG,
587
+ fetchRegistryJson: /* v8 ignore next -- integration: real HTTP fetch @preserve */ async () => {
588
+ const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
589
+ return res.json();
149
590
  },
150
- gracefulShutdown: () => daemon.stop(),
151
- nodePath: process.execPath,
152
- bundlesRoot,
153
- });
154
- },
155
- /* v8 ignore stop */
156
- });
157
- await this.processManager.startAutoStartAgents();
158
- await this.senseManager?.startAutoStartSenses();
591
+ },
592
+ });
593
+ }
594
+ // MCP connections are lazily initialized per-agent during senseTurn
595
+ // (daemon manages multiple agents; agent identity must be set before loading MCP config)
596
+ /* v8 ignore start -- orphan cleanup + pidfile: calls process management functions @preserve */
597
+ killOrphanProcesses(this.socketPath);
598
+ /* v8 ignore stop */
599
+ await this.openCommandSocket();
600
+ this.triggerAutoStartAgents();
601
+ this.triggerAutoStartSensesWhenAgentsSettled();
602
+ // Write all managed PIDs to disk so the next daemon can clean up
603
+ /* v8 ignore start -- pidfile write: collects PIDs from process managers @preserve */
604
+ const agentPids = this.processManager.listAgentSnapshots().map((s) => s.pid).filter((p) => p !== null);
605
+ const sensePids = this.senseManager?.listManagedPids?.() ?? [];
606
+ writePidfile([...agentPids, ...sensePids], this.socketPath);
607
+ /* v8 ignore stop */
159
608
  this.scheduler.start?.();
160
609
  await this.scheduler.reconcile?.();
161
610
  await this.drainPendingBundleMessages();
162
611
  await this.drainPendingSenseMessages();
612
+ // startInner is only reachable when this.server is null (guarded in
613
+ // start()), and stop() nulls out this.mailboxServer alongside this.server,
614
+ // so mailboxServer is guaranteed unset here — no need for a guard.
615
+ try {
616
+ this.mailboxServer = await this.mailboxServerFactory();
617
+ }
618
+ catch (error) {
619
+ (0, runtime_1.emitNervesEvent)({
620
+ level: "warn",
621
+ component: "daemon",
622
+ event: "daemon.mailbox_start_failed",
623
+ message: `Mailbox server failed to start: ${String(error)}`,
624
+ meta: { port: mailbox_types_1.MAILBOX_DEFAULT_PORT },
625
+ });
626
+ }
627
+ }
628
+ triggerAutoStartAgents() {
629
+ if (this.processManager.triggerAutoStartAgents) {
630
+ this.processManager.triggerAutoStartAgents();
631
+ return;
632
+ }
633
+ void this.processManager.startAutoStartAgents().catch((error) => {
634
+ (0, runtime_1.emitNervesEvent)({
635
+ level: "error",
636
+ component: "daemon",
637
+ event: "daemon.agent_autostart_error",
638
+ message: "agent autostart failed after daemon socket opened",
639
+ meta: { error: error instanceof Error ? error.message : String(error) },
640
+ });
641
+ });
642
+ }
643
+ triggerAutoStartSenses() {
644
+ /* v8 ignore next -- defensive: callers already check senseManager before delegating here @preserve */
645
+ if (!this.senseManager)
646
+ return;
647
+ if (this.senseManager.triggerAutoStartSenses) {
648
+ this.senseManager.triggerAutoStartSenses();
649
+ return;
650
+ }
651
+ void this.senseManager.startAutoStartSenses().catch((error) => {
652
+ (0, runtime_1.emitNervesEvent)({
653
+ level: "error",
654
+ component: "daemon",
655
+ event: "daemon.sense_autostart_error",
656
+ message: "sense autostart failed after daemon socket opened",
657
+ meta: { error: error instanceof Error ? error.message : String(error) },
658
+ });
659
+ });
660
+ }
661
+ triggerAutoStartSensesWhenAgentsSettled() {
662
+ if (!this.senseManager)
663
+ return;
664
+ const waitingOnAgents = this.processManager.listAgentSnapshots()
665
+ .some((snapshot) => snapshot.status === "starting");
666
+ if (!waitingOnAgents) {
667
+ this.triggerAutoStartSenses();
668
+ return;
669
+ }
670
+ this.senseAutostartTimer = setTimeout(() => {
671
+ this.senseAutostartTimer = null;
672
+ this.triggerAutoStartSensesWhenAgentsSettled();
673
+ }, 250);
674
+ }
675
+ async openCommandSocket() {
163
676
  if (fs.existsSync(this.socketPath)) {
164
677
  fs.unlinkSync(this.socketPath);
165
678
  }
166
- this.server = net.createServer((connection) => {
679
+ // allowHalfOpen: true lets the server keep its writable side open after
680
+ // the client sends FIN. Without this, when a client calls `client.end()`
681
+ // after writing a command, node closes the server's writable side
682
+ // automatically — so a long-running response (like an agent.senseTurn
683
+ // LLM turn that takes 5+ seconds) never reaches the client. The
684
+ // socket-client fix in #303/#334 also removed client.end() on the
685
+ // sending side, but this option is defense in depth: even if a future
686
+ // caller half-closes, the server still writes its response correctly.
687
+ this.server = net.createServer({ allowHalfOpen: true }, (connection) => {
167
688
  let raw = "";
168
689
  let responded = false;
690
+ /* v8 ignore start — connection error handler requires real socket error @preserve */
691
+ connection.on("error", (err) => {
692
+ (0, runtime_1.emitNervesEvent)({
693
+ level: "warn",
694
+ component: "daemon",
695
+ event: "daemon.connection_error",
696
+ message: "socket connection error",
697
+ meta: { error: err.message, code: err.code ?? null },
698
+ });
699
+ });
700
+ /* v8 ignore stop */
169
701
  const flushResponse = async () => {
170
702
  if (responded)
171
703
  return;
172
704
  responded = true;
173
705
  const response = await this.handleRawPayload(raw);
174
- connection.end(response);
706
+ try {
707
+ connection.end(response);
708
+ /* v8 ignore start — EPIPE catch requires real socket disconnect @preserve */
709
+ }
710
+ catch (err) {
711
+ (0, runtime_1.emitNervesEvent)({
712
+ level: "warn",
713
+ component: "daemon",
714
+ event: "daemon.connection_end_error",
715
+ message: "failed to send response to client (EPIPE)",
716
+ meta: { error: err instanceof Error ? err.message : String(err) },
717
+ });
718
+ }
719
+ /* v8 ignore stop */
175
720
  };
176
721
  connection.on("data", (chunk) => {
177
722
  raw += chunk.toString("utf-8");
@@ -184,7 +729,23 @@ class OuroDaemon {
184
729
  const server = this.server;
185
730
  await new Promise((resolve, reject) => {
186
731
  server.once("error", reject);
187
- server.listen(this.socketPath, () => resolve());
732
+ server.listen(this.socketPath, () => {
733
+ // Replace the one-time error listener with a persistent one after successful listen
734
+ server.removeAllListeners("error");
735
+ this.socketIdentity = readSocketIdentity(this.socketPath);
736
+ /* v8 ignore start — server error after listen requires real socket race condition @preserve */
737
+ server.on("error", (err) => {
738
+ (0, runtime_1.emitNervesEvent)({
739
+ level: "error",
740
+ component: "daemon",
741
+ event: "daemon.server_error",
742
+ message: "daemon server error after listen",
743
+ meta: { error: err.message, code: err.code ?? null },
744
+ });
745
+ });
746
+ /* v8 ignore stop */
747
+ resolve();
748
+ });
188
749
  });
189
750
  }
190
751
  async drainPendingBundleMessages() {
@@ -323,25 +884,87 @@ class OuroDaemon {
323
884
  }
324
885
  }
325
886
  async stop() {
887
+ // Must be named `_end` (not `_stop`) to satisfy the nerves audit's
888
+ // start/end pairing rule — see src/nerves/coverage/audit-rules.ts.
889
+ // This is the counterpart to `daemon.server_start` emitted at line 480.
326
890
  (0, runtime_1.emitNervesEvent)({
327
891
  component: "daemon",
328
- event: "daemon.server_stop",
892
+ event: "daemon.server_end",
329
893
  message: "stopping daemon server",
330
894
  meta: { socketPath: this.socketPath },
331
895
  });
332
896
  (0, update_checker_1.stopUpdateChecker)();
897
+ (0, mcp_manager_1.shutdownSharedMcpManager)();
333
898
  this.scheduler.stop?.();
899
+ this.healthMonitor.stopPeriodicChecks?.();
900
+ if (this.senseAutostartTimer) {
901
+ clearTimeout(this.senseAutostartTimer);
902
+ this.senseAutostartTimer = null;
903
+ }
334
904
  await this.processManager.stopAll();
335
905
  await this.senseManager?.stopAll();
336
906
  if (this.server) {
337
- await new Promise((resolve) => {
338
- this.server?.close(() => resolve());
339
- });
907
+ // DO NOT `await` server.close() here. server.close() resolves only
908
+ // after every open connection has closed. When stop() is invoked
909
+ // from the daemon.stop command handler, the calling client's
910
+ // connection is STILL open — its flushResponse() is currently
911
+ // awaiting THIS function. Awaiting close() creates a deadlock:
912
+ //
913
+ // client → flushResponse → handleRawPayload → daemon.stop case
914
+ // → stop() → await server.close() (waits for client's connection)
915
+ // → client's connection waits for flushResponse to call
916
+ // connection.end() → DEADLOCK
917
+ //
918
+ // Both processes sit in kevent forever. Verified live on
919
+ // 2026-04-08: alpha.268 daemon hung at `daemon.server_end` log
920
+ // line for 5+ minutes after a client sent daemon.stop, while the
921
+ // client (alpha.270 ouro up) hung waiting for the response.
922
+ //
923
+ // This regressed when #303/#334/#339 stopped half-closing the
924
+ // client socket and switched the server to allowHalfOpen: true.
925
+ // Previously, the client called .end() after writing its command,
926
+ // which (with allowHalfOpen: false) caused node to auto-tear-down
927
+ // the server's writable side — incidentally unblocking
928
+ // server.close() before the response was sent. The half-close
929
+ // breakage masked this deadlock; the fix exposed it.
930
+ //
931
+ // Solution: fire close() and let it complete asynchronously. Once
932
+ // stop() returns, the daemon.stop case returns its response,
933
+ // flushResponse() calls connection.end(response), the connection
934
+ // closes, and server.close()'s pending callback fires. The event
935
+ // loop drains and the daemon exits cleanly.
936
+ this.server.close();
340
937
  this.server = null;
341
938
  }
342
- if (fs.existsSync(this.socketPath)) {
939
+ if (this.mailboxServer) {
940
+ await this.mailboxServer.stop();
941
+ this.mailboxServer = null;
942
+ }
943
+ const socketPathExists = fs.existsSync(this.socketPath);
944
+ const currentSocketIdentity = socketPathExists ? readSocketIdentity(this.socketPath) : null;
945
+ if (sameSocketIdentity(this.socketIdentity, currentSocketIdentity)) {
343
946
  fs.unlinkSync(this.socketPath);
344
947
  }
948
+ else if (socketPathExists) {
949
+ const expectedSocketIdentity = { dev: null, ino: null, ctimeMs: null, ...this.socketIdentity };
950
+ const actualSocketIdentity = { dev: null, ino: null, ctimeMs: null, ...currentSocketIdentity };
951
+ (0, runtime_1.emitNervesEvent)({
952
+ level: "warn",
953
+ component: "daemon",
954
+ event: "daemon.socket_cleanup_skipped",
955
+ message: "skipped daemon socket cleanup because the socket path no longer belongs to this daemon",
956
+ meta: {
957
+ socketPath: this.socketPath,
958
+ expectedDev: expectedSocketIdentity.dev,
959
+ expectedIno: expectedSocketIdentity.ino,
960
+ expectedCtimeMs: expectedSocketIdentity.ctimeMs,
961
+ actualDev: actualSocketIdentity.dev,
962
+ actualIno: actualSocketIdentity.ino,
963
+ actualCtimeMs: actualSocketIdentity.ctimeMs,
964
+ },
965
+ });
966
+ }
967
+ this.socketIdentity = null;
345
968
  }
346
969
  async handleRawPayload(raw) {
347
970
  try {
@@ -363,32 +986,37 @@ class OuroDaemon {
363
986
  message: "handling daemon command",
364
987
  meta: { kind: command.kind },
365
988
  });
989
+ try {
990
+ return await this.handleCommandInner(command);
991
+ /* v8 ignore start — command error catch tested in daemon-command-error.test; instanceof branches defensive @preserve */
992
+ }
993
+ catch (error) {
994
+ (0, runtime_1.emitNervesEvent)({
995
+ level: "error",
996
+ component: "daemon",
997
+ event: "daemon.command_error",
998
+ message: "unexpected error handling daemon command",
999
+ meta: {
1000
+ kind: command.kind,
1001
+ error: error instanceof Error ? error.message : String(error),
1002
+ stack: error instanceof Error ? error.stack ?? null : null,
1003
+ },
1004
+ });
1005
+ throw error;
1006
+ }
1007
+ /* v8 ignore stop */
1008
+ }
1009
+ async handleCommandInner(command) {
366
1010
  switch (command.kind) {
367
1011
  case "daemon.start":
368
1012
  await this.start();
369
1013
  return { ok: true, message: "daemon started" };
370
1014
  case "daemon.stop":
371
1015
  await this.stop();
1016
+ this.onStopCommandComplete?.();
372
1017
  return { ok: true, message: "daemon stopped" };
373
1018
  case "daemon.status": {
374
- const snapshots = this.processManager.listAgentSnapshots();
375
- const workers = buildWorkerRows(snapshots);
376
- const senses = this.senseManager?.listSenseRows() ?? [];
377
- const repoRoot = (0, identity_1.getRepoRoot)();
378
- const data = {
379
- overview: {
380
- daemon: "running",
381
- health: workers.every((worker) => worker.status === "running") ? "ok" : "warn",
382
- socketPath: this.socketPath,
383
- ...(0, runtime_metadata_1.getRuntimeMetadata)(),
384
- workerCount: workers.length,
385
- senseCount: senses.length,
386
- entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
387
- mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
388
- },
389
- workers,
390
- senses,
391
- };
1019
+ const data = this.buildStatusPayload();
392
1020
  return {
393
1021
  ok: true,
394
1022
  summary: formatStatusSummary(data),
@@ -405,7 +1033,7 @@ class OuroDaemon {
405
1033
  ok: true,
406
1034
  summary: "logs: use `ouro logs` to tail daemon and agent output",
407
1035
  message: "log streaming available via ouro logs",
408
- data: { logDir: "~/.agentstate/daemon/logs" },
1036
+ data: { logDir: "~/AgentBundles/<agent>.ouro/state/daemon/logs" },
409
1037
  };
410
1038
  case "agent.start":
411
1039
  await this.processManager.startAgent(command.agent);
@@ -416,6 +1044,35 @@ class OuroDaemon {
416
1044
  case "agent.restart":
417
1045
  await this.processManager.restartAgent?.(command.agent);
418
1046
  return { ok: true, message: `restarted ${command.agent}` };
1047
+ case "agent.ask":
1048
+ return (0, agent_service_1.handleAgentAsk)(command);
1049
+ case "agent.status":
1050
+ return (0, agent_service_1.handleAgentStatus)(command);
1051
+ case "agent.catchup":
1052
+ return (0, agent_service_1.handleAgentCatchup)(command);
1053
+ case "agent.delegate":
1054
+ return (0, agent_service_1.handleAgentDelegate)(command);
1055
+ case "agent.getContext":
1056
+ return (0, agent_service_1.handleAgentGetContext)(command);
1057
+ case "agent.searchNotes":
1058
+ return (0, agent_service_1.handleAgentSearchNotes)(command);
1059
+ case "agent.getTask":
1060
+ return (0, agent_service_1.handleAgentGetTask)(command);
1061
+ case "agent.checkScope":
1062
+ return (0, agent_service_1.handleAgentCheckScope)(command);
1063
+ case "agent.requestDecision":
1064
+ return (0, agent_service_1.handleAgentRequestDecision)(command);
1065
+ case "agent.checkGuidance":
1066
+ return (0, agent_service_1.handleAgentCheckGuidance)(command);
1067
+ case "agent.reportProgress":
1068
+ return (0, agent_service_1.handleAgentReportProgress)(command);
1069
+ case "agent.reportBlocker":
1070
+ return (0, agent_service_1.handleAgentReportBlocker)(command);
1071
+ case "agent.reportComplete":
1072
+ return (0, agent_service_1.handleAgentReportComplete)(command);
1073
+ case "agent.senseTurn":
1074
+ return handleAgentSenseTurn(command);
1075
+ /* v8 ignore stop */
419
1076
  case "cron.list": {
420
1077
  const jobs = this.scheduler.listJobs();
421
1078
  const summary = jobs.length === 0
@@ -436,6 +1093,7 @@ class OuroDaemon {
436
1093
  sessionId: command.sessionId,
437
1094
  taskRef: command.taskRef,
438
1095
  });
1096
+ await this.processManager.startAgent(command.to);
439
1097
  this.processManager.sendToAgent?.(command.to, { type: "message" });
440
1098
  return { ok: true, message: `queued message ${receipt.id}`, data: receipt };
441
1099
  }
@@ -476,6 +1134,35 @@ class OuroDaemon {
476
1134
  data: receipt,
477
1135
  };
478
1136
  }
1137
+ case "habit.poke": {
1138
+ this.processManager.sendToAgent?.(command.agent, { type: "habit", habitName: command.habitName });
1139
+ return {
1140
+ ok: true,
1141
+ message: `poked habit ${command.habitName} for ${command.agent}`,
1142
+ };
1143
+ }
1144
+ case "mcp.list": {
1145
+ const mcpManager = await (0, mcp_manager_1.getSharedMcpManager)();
1146
+ if (!mcpManager) {
1147
+ return { ok: true, data: [], message: "no MCP servers configured" };
1148
+ }
1149
+ return { ok: true, data: mcpManager.listAllTools() };
1150
+ }
1151
+ case "mcp.call": {
1152
+ const mcpCallManager = await (0, mcp_manager_1.getSharedMcpManager)();
1153
+ if (!mcpCallManager) {
1154
+ return { ok: false, error: "no MCP servers configured" };
1155
+ }
1156
+ try {
1157
+ const parsedArgs = command.args ? JSON.parse(command.args) : {};
1158
+ const result = await mcpCallManager.callTool(command.server, command.tool, parsedArgs);
1159
+ return { ok: true, data: result };
1160
+ }
1161
+ catch (error) {
1162
+ /* v8 ignore next -- defensive: callTool errors are always Error instances @preserve */
1163
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
1164
+ }
1165
+ }
479
1166
  case "hatch.start":
480
1167
  return {
481
1168
  ok: true,