@ouro.bot/cli 0.1.0-alpha.66 → 0.1.0-alpha.660

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 (449) hide show
  1. package/README.md +127 -23
  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-broken-remote.md +63 -0
  6. package/RepairGuide.ouro/skills/diagnose-stacked-typed-issues.md +35 -0
  7. package/RepairGuide.ouro/skills/diagnose-sync-blocked.md +54 -0
  8. package/RepairGuide.ouro/skills/diagnose-vault-expired.md +60 -0
  9. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +4 -2
  10. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +2 -2
  11. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +1 -1
  12. package/changelog.json +4209 -13
  13. package/dist/a2a/card.js +56 -0
  14. package/dist/a2a/client.js +143 -0
  15. package/dist/a2a/config.js +50 -0
  16. package/dist/a2a/onboarding.js +111 -0
  17. package/dist/a2a/server.js +498 -0
  18. package/dist/a2a/task-store.js +69 -0
  19. package/dist/a2a/types.js +3 -0
  20. package/dist/arc/attention-types.js +8 -0
  21. package/dist/arc/cares.js +144 -0
  22. package/dist/arc/episodes.js +118 -0
  23. package/dist/arc/evolution.js +487 -0
  24. package/dist/arc/flight-recorder.js +369 -0
  25. package/dist/arc/intentions.js +134 -0
  26. package/dist/arc/json-store.js +117 -0
  27. package/dist/arc/obligations.js +292 -0
  28. package/dist/arc/packets.js +288 -0
  29. package/dist/arc/presence.js +185 -0
  30. package/dist/arc/task-lifecycle.js +57 -0
  31. package/dist/commerce/store.js +755 -0
  32. package/dist/commerce/types.js +3 -0
  33. package/dist/heart/active-work.js +860 -43
  34. package/dist/heart/agent-entry.js +69 -3
  35. package/dist/heart/attachments/image-normalize.js +194 -0
  36. package/dist/heart/attachments/materialize.js +97 -0
  37. package/dist/heart/attachments/originals.js +88 -0
  38. package/dist/heart/attachments/render.js +29 -0
  39. package/dist/heart/attachments/sources/bluebubbles.js +156 -0
  40. package/dist/heart/attachments/sources/cli-local-file.js +78 -0
  41. package/dist/heart/attachments/sources/index.js +16 -0
  42. package/dist/heart/attachments/store.js +103 -0
  43. package/dist/heart/attachments/types.js +93 -0
  44. package/dist/heart/auth/auth-flow.js +479 -0
  45. package/dist/heart/awaiting/await-alert.js +146 -0
  46. package/dist/heart/awaiting/await-expiry.js +108 -0
  47. package/dist/heart/awaiting/await-loader.js +91 -0
  48. package/dist/heart/awaiting/await-parser.js +141 -0
  49. package/dist/heart/awaiting/await-runtime-state.js +100 -0
  50. package/dist/heart/awaiting/await-scheduler.js +377 -0
  51. package/dist/heart/background-operations.js +281 -0
  52. package/dist/heart/bridges/manager.js +137 -17
  53. package/dist/heart/bridges/store.js +14 -2
  54. package/dist/heart/bundle-state.js +168 -0
  55. package/dist/heart/commitments.js +135 -0
  56. package/dist/heart/config-registry.js +331 -0
  57. package/dist/heart/config.js +118 -119
  58. package/dist/heart/context-loss-gauntlet.js +354 -0
  59. package/dist/heart/core.js +1123 -247
  60. package/dist/heart/cross-chat-delivery.js +3 -18
  61. package/dist/heart/daemon/agent-config-check.js +419 -0
  62. package/dist/heart/daemon/agent-discovery.js +102 -3
  63. package/dist/heart/daemon/agent-service.js +523 -0
  64. package/dist/heart/daemon/agentic-repair.js +547 -0
  65. package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
  66. package/dist/heart/daemon/boot-sync-probe.js +197 -0
  67. package/dist/heart/daemon/cadence.js +70 -0
  68. package/dist/heart/daemon/cli-defaults.js +780 -0
  69. package/dist/heart/daemon/cli-desk.js +322 -0
  70. package/dist/heart/daemon/cli-exec.js +7767 -0
  71. package/dist/heart/daemon/cli-help.js +558 -0
  72. package/dist/heart/daemon/cli-parse.js +1688 -0
  73. package/dist/heart/daemon/cli-render-doctor.js +57 -0
  74. package/dist/heart/daemon/cli-render.js +763 -0
  75. package/dist/heart/daemon/cli-types.js +8 -0
  76. package/dist/heart/daemon/connect-bay.js +323 -0
  77. package/dist/heart/daemon/daemon-cli.js +29 -1750
  78. package/dist/heart/daemon/daemon-entry.js +485 -2
  79. package/dist/heart/daemon/daemon-health.js +176 -0
  80. package/dist/heart/daemon/daemon-rollup.js +57 -0
  81. package/dist/heart/daemon/daemon-runtime-sync.js +88 -13
  82. package/dist/heart/daemon/daemon-tombstone.js +236 -0
  83. package/dist/heart/daemon/daemon.js +937 -74
  84. package/dist/heart/daemon/dns-workflow.js +394 -0
  85. package/dist/heart/daemon/doctor-types.js +8 -0
  86. package/dist/heart/daemon/doctor.js +873 -0
  87. package/dist/heart/daemon/health-monitor.js +122 -1
  88. package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
  89. package/dist/heart/daemon/hooks/bundle-meta.js +135 -1
  90. package/dist/heart/daemon/http-health-probe.js +80 -0
  91. package/dist/heart/daemon/human-command-screens.js +234 -0
  92. package/dist/heart/daemon/human-readiness.js +114 -0
  93. package/dist/heart/daemon/inner-status.js +78 -0
  94. package/dist/heart/daemon/interactive-repair.js +394 -0
  95. package/dist/heart/daemon/launchd.js +37 -8
  96. package/dist/heart/daemon/log-tailer.js +79 -10
  97. package/dist/heart/daemon/logs-prune.js +110 -0
  98. package/dist/heart/daemon/mcp-canary.js +297 -0
  99. package/dist/heart/daemon/message-router.js +6 -2
  100. package/dist/heart/daemon/migrate-to-desk.js +848 -0
  101. package/dist/heart/daemon/os-cron-deps.js +135 -0
  102. package/dist/heart/daemon/os-cron.js +14 -12
  103. package/dist/heart/daemon/ouro-bot-entry.js +4 -2
  104. package/dist/heart/daemon/ouro-entry.js +3 -1
  105. package/dist/heart/daemon/plugin-cli.js +432 -0
  106. package/dist/heart/daemon/process-manager.js +511 -40
  107. package/dist/heart/daemon/provider-discovery.js +137 -0
  108. package/dist/heart/daemon/provider-ping-progress.js +83 -0
  109. package/dist/heart/daemon/pulse.js +475 -0
  110. package/dist/heart/daemon/readiness-repair.js +365 -0
  111. package/dist/heart/daemon/run-hooks.js +2 -0
  112. package/dist/heart/daemon/runtime-logging.js +35 -14
  113. package/dist/heart/daemon/runtime-metadata.js +2 -30
  114. package/dist/heart/daemon/safe-mode.js +161 -0
  115. package/dist/heart/daemon/sense-manager.js +564 -38
  116. package/dist/heart/daemon/session-id-resolver.js +131 -0
  117. package/dist/heart/daemon/skill-management-installer.js +1 -1
  118. package/dist/heart/daemon/socket-client.js +158 -11
  119. package/dist/heart/daemon/stale-bundle-prune.js +96 -0
  120. package/dist/heart/daemon/startup-tui.js +330 -0
  121. package/dist/heart/daemon/task-scheduler.js +117 -39
  122. package/dist/heart/daemon/terminal-ui.js +499 -0
  123. package/dist/heart/daemon/thoughts.js +229 -17
  124. package/dist/heart/daemon/up-progress.js +366 -0
  125. package/dist/heart/daemon/vault-items.js +56 -0
  126. package/dist/heart/delegation.js +1 -4
  127. package/dist/heart/habits/habit-migration.js +189 -0
  128. package/dist/heart/habits/habit-parser.js +203 -0
  129. package/dist/heart/habits/habit-runtime-state.js +100 -0
  130. package/dist/heart/habits/habit-scheduler.js +372 -0
  131. package/dist/heart/{daemon → hatch}/hatch-flow.js +40 -56
  132. package/dist/heart/{daemon → hatch}/hatch-specialist.js +6 -8
  133. package/dist/heart/{daemon → hatch}/specialist-prompt.js +12 -9
  134. package/dist/heart/{daemon → hatch}/specialist-tools.js +45 -18
  135. package/dist/heart/identity.js +174 -57
  136. package/dist/heart/kept-notes.js +289 -0
  137. package/dist/heart/kicks.js +1 -1
  138. package/dist/heart/machine-identity.js +161 -0
  139. package/dist/heart/mail-import-discovery.js +353 -0
  140. package/dist/heart/mailbox/mailbox-http-hooks.js +67 -0
  141. package/dist/heart/mailbox/mailbox-http-response.js +7 -0
  142. package/dist/heart/mailbox/mailbox-http-routes.js +250 -0
  143. package/dist/heart/mailbox/mailbox-http-static.js +103 -0
  144. package/dist/heart/mailbox/mailbox-http-transport.js +116 -0
  145. package/dist/heart/mailbox/mailbox-http.js +99 -0
  146. package/dist/heart/mailbox/mailbox-read.js +32 -0
  147. package/dist/heart/mailbox/mailbox-types.js +27 -0
  148. package/dist/heart/mailbox/mailbox-view.js +197 -0
  149. package/dist/heart/mailbox/readers/agent-machine.js +418 -0
  150. package/dist/heart/mailbox/readers/continuity-readers.js +324 -0
  151. package/dist/heart/mailbox/readers/mail.js +375 -0
  152. package/dist/heart/mailbox/readers/runtime-readers.js +728 -0
  153. package/dist/heart/mailbox/readers/sessions.js +232 -0
  154. package/dist/heart/mailbox/readers/shared.js +111 -0
  155. package/dist/heart/mcp/mcp-server.js +696 -0
  156. package/dist/heart/migrate-config.js +100 -0
  157. package/dist/heart/model-capabilities.js +19 -0
  158. package/dist/heart/orientation-frame.js +217 -0
  159. package/dist/heart/platform.js +81 -0
  160. package/dist/heart/provider-attempt.js +134 -0
  161. package/dist/heart/provider-binding-resolver.js +272 -0
  162. package/dist/heart/provider-credentials.js +425 -0
  163. package/dist/heart/provider-failover.js +311 -0
  164. package/dist/heart/provider-models.js +81 -0
  165. package/dist/heart/provider-ping.js +262 -0
  166. package/dist/heart/provider-readiness-cache.js +40 -0
  167. package/dist/heart/provider-visibility.js +188 -0
  168. package/dist/heart/providers/anthropic-token.js +131 -0
  169. package/dist/heart/providers/anthropic.js +139 -52
  170. package/dist/heart/providers/azure.js +23 -11
  171. package/dist/heart/providers/error-classification.js +127 -0
  172. package/dist/heart/providers/github-copilot.js +145 -0
  173. package/dist/heart/providers/minimax-vlm.js +189 -0
  174. package/dist/heart/providers/minimax.js +26 -8
  175. package/dist/heart/providers/openai-codex-token.js +349 -0
  176. package/dist/heart/providers/openai-codex.js +55 -40
  177. package/dist/heart/runtime-capability-check.js +170 -0
  178. package/dist/heart/runtime-credentials.js +367 -0
  179. package/dist/heart/runtime-cwd.js +87 -0
  180. package/dist/heart/sense-truth.js +17 -4
  181. package/dist/heart/session-activity.js +48 -24
  182. package/dist/heart/session-events.js +1133 -0
  183. package/dist/heart/session-playback-cli-main.js +5 -0
  184. package/dist/heart/session-playback-cli.js +36 -0
  185. package/dist/heart/session-playback.js +231 -0
  186. package/dist/heart/session-stats-cli-main.js +5 -0
  187. package/dist/heart/session-stats.js +182 -0
  188. package/dist/heart/session-transcript.js +133 -0
  189. package/dist/heart/start-of-turn-packet.js +351 -0
  190. package/dist/heart/streaming.js +44 -27
  191. package/dist/heart/structured-output.js +196 -0
  192. package/dist/heart/sync-classification.js +176 -0
  193. package/dist/heart/sync.js +449 -0
  194. package/dist/heart/target-resolution.js +9 -5
  195. package/dist/heart/tempo.js +93 -0
  196. package/dist/heart/temporal-view.js +41 -0
  197. package/dist/heart/timeouts.js +101 -0
  198. package/dist/heart/tool-activity-callbacks.js +59 -0
  199. package/dist/heart/tool-description.js +155 -0
  200. package/dist/heart/tool-friction.js +55 -0
  201. package/dist/heart/tool-loop.js +200 -0
  202. package/dist/heart/turn-context.js +430 -0
  203. package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +6 -5
  204. package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
  205. package/dist/heart/versioning/ouro-path-installer.js +426 -0
  206. package/dist/heart/versioning/ouro-version-manager.js +409 -0
  207. package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
  208. package/dist/heart/{daemon → versioning}/update-checker.js +6 -1
  209. package/dist/heart/versioning/update-hooks.js +154 -0
  210. package/dist/heart/work-card.js +386 -0
  211. package/dist/mailbox-ui/assets/index-B-V9vRQ0.js +61 -0
  212. package/dist/mailbox-ui/assets/index-BOZbGbkL.css +1 -0
  213. package/dist/mailbox-ui/index.html +15 -0
  214. package/dist/mailroom/attention.js +167 -0
  215. package/dist/mailroom/autonomy.js +209 -0
  216. package/dist/mailroom/blob-store.js +715 -0
  217. package/dist/mailroom/body-cache.js +61 -0
  218. package/dist/mailroom/core.js +788 -0
  219. package/dist/mailroom/entry.js +160 -0
  220. package/dist/mailroom/file-store.js +568 -0
  221. package/dist/mailroom/mbox-import.js +393 -0
  222. package/dist/mailroom/migration.js +164 -0
  223. package/dist/mailroom/outbound.js +380 -0
  224. package/dist/mailroom/policy.js +263 -0
  225. package/dist/mailroom/reader.js +233 -0
  226. package/dist/mailroom/search-cache.js +334 -0
  227. package/dist/mailroom/search-relevance.js +319 -0
  228. package/dist/mailroom/smtp-ingress.js +176 -0
  229. package/dist/mailroom/source-state.js +176 -0
  230. package/dist/mailroom/thread.js +109 -0
  231. package/dist/mailroom/travel-extract.js +89 -0
  232. package/dist/mind/bundle-manifest.js +21 -2
  233. package/dist/mind/context.js +250 -101
  234. package/dist/mind/desk-section.js +362 -0
  235. package/dist/mind/diary-integrity.js +60 -0
  236. package/dist/mind/{memory.js → diary.js} +68 -77
  237. package/dist/mind/embedding-provider.js +60 -0
  238. package/dist/mind/file-state.js +179 -0
  239. package/dist/mind/friends/channel.js +48 -0
  240. package/dist/mind/friends/resolver.js +67 -4
  241. package/dist/mind/friends/store-file.js +61 -4
  242. package/dist/mind/friends/types.js +2 -2
  243. package/dist/mind/{associative-recall.js → note-search.js} +47 -58
  244. package/dist/mind/obligation-steering.js +221 -0
  245. package/dist/mind/pending.js +6 -1
  246. package/dist/mind/prompt-refresh.js +3 -2
  247. package/dist/mind/prompt.js +1015 -140
  248. package/dist/mind/provenance-trust.js +26 -0
  249. package/dist/mind/record-paths.js +312 -0
  250. package/dist/mind/scrutiny.js +173 -0
  251. package/dist/nerves/cli-logging.js +7 -1
  252. package/dist/nerves/coverage/audit-rules.js +15 -6
  253. package/dist/nerves/coverage/audit.js +28 -2
  254. package/dist/nerves/coverage/cli.js +1 -1
  255. package/dist/nerves/coverage/contract.js +5 -5
  256. package/dist/nerves/coverage/file-completeness.js +139 -5
  257. package/dist/nerves/event-buffer.js +111 -0
  258. package/dist/nerves/index.js +224 -4
  259. package/dist/nerves/observation.js +20 -0
  260. package/dist/nerves/redact.js +79 -0
  261. package/dist/nerves/review/cli-main.js +5 -0
  262. package/dist/nerves/review/cli.js +156 -0
  263. package/dist/nerves/review/core.js +152 -0
  264. package/dist/nerves/runtime.js +5 -1
  265. package/dist/repertoire/ado-client.js +15 -56
  266. package/dist/repertoire/ado-semantic.js +16 -10
  267. package/dist/repertoire/api-client.js +97 -0
  268. package/dist/repertoire/bitwarden-store.js +1041 -0
  269. package/dist/repertoire/bundle-templates.js +71 -0
  270. package/dist/repertoire/bw-installer.js +180 -0
  271. package/dist/repertoire/coding/codex-jsonl.js +64 -0
  272. package/dist/repertoire/coding/context-pack.js +331 -0
  273. package/dist/repertoire/coding/feedback.js +197 -30
  274. package/dist/repertoire/coding/manager.js +166 -10
  275. package/dist/repertoire/coding/spawner.js +55 -9
  276. package/dist/repertoire/coding/tools.js +219 -7
  277. package/dist/repertoire/commerce-errors.js +109 -0
  278. package/dist/repertoire/commerce-self-test.js +156 -0
  279. package/dist/repertoire/credential-access.js +178 -0
  280. package/dist/repertoire/desk/classifier.js +362 -0
  281. package/dist/repertoire/duffel-client.js +185 -0
  282. package/dist/repertoire/github-client.js +14 -55
  283. package/dist/repertoire/graph-client.js +11 -52
  284. package/dist/repertoire/guardrails.js +159 -25
  285. package/dist/repertoire/mcp-client.js +295 -0
  286. package/dist/repertoire/mcp-manager.js +434 -0
  287. package/dist/repertoire/mcp-tools.js +83 -0
  288. package/dist/repertoire/plugin-mcp.js +175 -0
  289. package/dist/repertoire/plugins.js +253 -0
  290. package/dist/repertoire/shell-sessions.js +133 -0
  291. package/dist/repertoire/skills.js +48 -4
  292. package/dist/repertoire/stripe-client.js +131 -0
  293. package/dist/repertoire/tool-results.js +29 -0
  294. package/dist/repertoire/tools-a2a.js +283 -0
  295. package/dist/repertoire/tools-attachments.js +317 -0
  296. package/dist/repertoire/tools-awaiting.js +372 -0
  297. package/dist/repertoire/tools-base.js +63 -1082
  298. package/dist/repertoire/tools-bluebubbles.js +2 -0
  299. package/dist/repertoire/tools-bridge.js +144 -0
  300. package/dist/repertoire/tools-bundle.js +993 -0
  301. package/dist/repertoire/tools-commerce.js +253 -0
  302. package/dist/repertoire/tools-config.js +186 -0
  303. package/dist/repertoire/tools-continuity.js +252 -0
  304. package/dist/repertoire/tools-credential.js +383 -0
  305. package/dist/repertoire/tools-evolution.js +527 -0
  306. package/dist/repertoire/tools-files.js +344 -0
  307. package/dist/repertoire/tools-flight.js +290 -0
  308. package/dist/repertoire/tools-flow.js +119 -0
  309. package/dist/repertoire/tools-github.js +3 -8
  310. package/dist/repertoire/tools-mail.js +1975 -0
  311. package/dist/repertoire/tools-notes.js +418 -0
  312. package/dist/repertoire/tools-obligations.js +143 -0
  313. package/dist/repertoire/tools-orientation.js +31 -0
  314. package/dist/repertoire/tools-record.js +469 -0
  315. package/dist/repertoire/tools-runtime.js +150 -0
  316. package/dist/repertoire/tools-session.js +766 -0
  317. package/dist/repertoire/tools-shell.js +120 -0
  318. package/dist/repertoire/tools-stripe.js +224 -0
  319. package/dist/repertoire/tools-surface.js +344 -0
  320. package/dist/repertoire/tools-teams.js +12 -39
  321. package/dist/repertoire/tools-travel.js +125 -0
  322. package/dist/repertoire/tools-trip.js +982 -0
  323. package/dist/repertoire/tools-user-profile.js +146 -0
  324. package/dist/repertoire/tools-vault.js +40 -0
  325. package/dist/repertoire/tools-voice.js +145 -0
  326. package/dist/repertoire/tools.js +243 -79
  327. package/dist/repertoire/travel-api-client.js +360 -0
  328. package/dist/repertoire/user-profile.js +131 -0
  329. package/dist/repertoire/vault-setup.js +246 -0
  330. package/dist/repertoire/vault-unlock.js +594 -0
  331. package/dist/scripts/claude-code-hook.js +41 -0
  332. package/dist/scripts/claude-code-stop-hook.js +47 -0
  333. package/dist/senses/a2a-entry.js +78 -0
  334. package/dist/senses/attention-queue.js +186 -0
  335. package/dist/senses/await-turn-message.js +58 -0
  336. package/dist/senses/bluebubbles/active-turns.js +216 -0
  337. package/dist/senses/bluebubbles/attachment-cache.js +53 -0
  338. package/dist/senses/bluebubbles/attachment-download.js +137 -0
  339. package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +219 -18
  340. package/dist/senses/bluebubbles/entry.js +77 -0
  341. package/dist/senses/{bluebubbles-inbound-log.js → bluebubbles/inbound-log.js} +20 -3
  342. package/dist/senses/bluebubbles/index.js +2737 -0
  343. package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -71
  344. package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +33 -12
  345. package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +3 -3
  346. package/dist/senses/bluebubbles/processed-log.js +133 -0
  347. package/dist/senses/bluebubbles/replay.js +137 -0
  348. package/dist/senses/{bluebubbles-runtime-state.js → bluebubbles/runtime-state.js} +30 -2
  349. package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
  350. package/dist/senses/bluebubbles-meta-guard.js +40 -0
  351. package/dist/senses/cli/bracketed-paste.js +82 -0
  352. package/dist/senses/cli/image-paste.js +287 -0
  353. package/dist/senses/cli/image-ref-navigation.js +75 -0
  354. package/dist/senses/cli/ink-app.js +156 -0
  355. package/dist/senses/cli/inline-diff.js +64 -0
  356. package/dist/senses/cli/input-keys.js +174 -0
  357. package/dist/senses/cli/kill-ring.js +86 -0
  358. package/dist/senses/cli/message-list.js +51 -0
  359. package/dist/senses/cli/ouro-tui.js +607 -0
  360. package/dist/senses/cli/spinner-imperative.js +135 -0
  361. package/dist/senses/cli/spinner.js +101 -0
  362. package/dist/senses/cli/status-line.js +60 -0
  363. package/dist/senses/cli/streaming-markdown.js +526 -0
  364. package/dist/senses/cli/tool-display.js +85 -0
  365. package/dist/senses/cli/tool-render.js +85 -0
  366. package/dist/senses/cli/tui-store.js +240 -0
  367. package/dist/senses/cli/virtual-list.js +35 -0
  368. package/dist/senses/cli-entry.js +60 -8
  369. package/dist/senses/cli-layout.js +100 -0
  370. package/dist/senses/cli.js +517 -204
  371. package/dist/senses/commands.js +66 -3
  372. package/dist/senses/habit-turn-message.js +122 -0
  373. package/dist/senses/inner-dialog-worker.js +303 -22
  374. package/dist/senses/inner-dialog.js +525 -41
  375. package/dist/senses/mail-entry.js +66 -0
  376. package/dist/senses/mail.js +379 -0
  377. package/dist/senses/pipeline.js +857 -180
  378. package/dist/senses/proactive-content-guard.js +51 -0
  379. package/dist/senses/shared-turn.js +419 -0
  380. package/dist/senses/surface-tool.js +108 -0
  381. package/dist/senses/teams-entry.js +60 -8
  382. package/dist/senses/teams.js +390 -98
  383. package/dist/senses/trust-gate.js +100 -5
  384. package/dist/senses/voice/audio-playback.js +237 -0
  385. package/dist/senses/voice/audio-routing.js +119 -0
  386. package/dist/senses/voice/elevenlabs.js +202 -0
  387. package/dist/senses/voice/floor-control.js +431 -0
  388. package/dist/senses/voice/floor-controller.js +115 -0
  389. package/dist/senses/voice/golden-path.js +116 -0
  390. package/dist/senses/voice/index.js +29 -0
  391. package/dist/senses/voice/meeting.js +113 -0
  392. package/dist/senses/voice/outbound.js +190 -0
  393. package/dist/senses/voice/phone.js +33 -0
  394. package/dist/senses/voice/playback.js +139 -0
  395. package/dist/senses/voice/realtime-eval.js +496 -0
  396. package/dist/senses/voice/realtime-trace.js +531 -0
  397. package/dist/senses/voice/transcript.js +70 -0
  398. package/dist/senses/voice/turn.js +191 -0
  399. package/dist/senses/voice/twilio-phone-runtime.js +807 -0
  400. package/dist/senses/voice/twilio-phone.js +5079 -0
  401. package/dist/senses/voice/types.js +2 -0
  402. package/dist/senses/voice/whisper.js +161 -0
  403. package/dist/senses/voice-entry.js +81 -0
  404. package/dist/senses/voice-realtime-eval-command.js +99 -0
  405. package/dist/senses/voice-realtime-eval-entry.js +21 -0
  406. package/dist/senses/voice-twilio-entry.js +87 -0
  407. package/dist/trips/core.js +138 -0
  408. package/dist/trips/store.js +265 -0
  409. package/dist/util/frontmatter.js +69 -0
  410. package/package.json +55 -12
  411. package/skills/agent-commerce.md +113 -0
  412. package/skills/browser-navigation.md +117 -0
  413. package/skills/commerce-setup-guide.md +116 -0
  414. package/skills/commerce-setup.md +84 -0
  415. package/skills/configure-dev-tools.md +99 -0
  416. package/skills/travel-planning.md +138 -0
  417. package/dist/heart/daemon/auth-flow.js +0 -351
  418. package/dist/heart/daemon/ouro-path-installer.js +0 -178
  419. package/dist/heart/daemon/update-hooks.js +0 -138
  420. package/dist/heart/safe-workspace.js +0 -228
  421. package/dist/heart/session-recall.js +0 -116
  422. package/dist/repertoire/tasks/board.js +0 -134
  423. package/dist/repertoire/tasks/index.js +0 -224
  424. package/dist/repertoire/tasks/lifecycle.js +0 -80
  425. package/dist/repertoire/tasks/middleware.js +0 -65
  426. package/dist/repertoire/tasks/parser.js +0 -173
  427. package/dist/repertoire/tasks/scanner.js +0 -132
  428. package/dist/repertoire/tasks/transitions.js +0 -144
  429. package/dist/senses/bluebubbles-entry.js +0 -13
  430. package/dist/senses/bluebubbles.js +0 -1177
  431. package/dist/senses/debug-activity.js +0 -148
  432. package/subagents/README.md +0 -7
  433. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
  434. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
  435. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
  436. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
  437. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
  438. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
  439. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
  440. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
  441. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
  442. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
  443. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
  444. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
  445. /package/dist/{repertoire/tasks/types.js → heart/attachments/sources/adapter.js} +0 -0
  446. /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
  447. /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
  448. /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
  449. /package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +0 -0
@@ -34,21 +34,341 @@ 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.waitForOrphanProcessesToSettle = waitForOrphanProcessesToSettle;
41
+ exports.killOrphanProcesses = killOrphanProcesses;
42
+ exports.writePidfile = writePidfile;
43
+ exports.handleAgentSenseTurn = handleAgentSenseTurn;
44
+ exports.handleAgentAskTurn = handleAgentAskTurn;
37
45
  const fs = __importStar(require("fs"));
38
46
  const net = __importStar(require("net"));
47
+ const os = __importStar(require("os"));
39
48
  const path = __importStar(require("path"));
40
49
  const identity_1 = require("../identity");
50
+ const agent_discovery_1 = require("./agent-discovery");
41
51
  const runtime_1 = require("../../nerves/runtime");
42
52
  const runtime_metadata_1 = require("./runtime-metadata");
43
53
  const runtime_mode_1 = require("./runtime-mode");
44
- const update_hooks_1 = require("./update-hooks");
54
+ const update_hooks_1 = require("../versioning/update-hooks");
45
55
  const bundle_meta_1 = require("./hooks/bundle-meta");
56
+ const agent_config_v2_1 = require("./hooks/agent-config-v2");
46
57
  const bundle_manifest_1 = require("../../mind/bundle-manifest");
47
- const update_checker_1 = require("./update-checker");
48
- const staged_restart_1 = require("./staged-restart");
58
+ const update_checker_1 = require("../versioning/update-checker");
49
59
  const child_process_1 = require("child_process");
50
60
  const pending_1 = require("../../mind/pending");
61
+ const agent_service_1 = require("./agent-service");
51
62
  const channel_1 = require("../../mind/friends/channel");
63
+ const mcp_manager_1 = require("../../repertoire/mcp-manager");
64
+ const mailbox_http_1 = require("../mailbox/mailbox-http");
65
+ const mailbox_types_1 = require("../mailbox/mailbox-types");
66
+ const mailbox_read_1 = require("../mailbox/mailbox-read");
67
+ const mailbox_view_1 = require("../mailbox/mailbox-view");
68
+ const provider_visibility_1 = require("../provider-visibility");
69
+ const socket_client_1 = require("./socket-client");
70
+ const PIDFILE_PATH = path.join(os.homedir(), ".ouro-cli", "daemon.pids");
71
+ /**
72
+ * Defense-in-depth: detect if we're running under vitest. The pidfile lives
73
+ * at a hardcoded path under the user's real ~/.ouro-cli/ — there's no DI
74
+ * seam to redirect it. So when a test creates a real OuroDaemon and calls
75
+ * start(), the daemon's killOrphanProcesses() reads the REAL pidfile,
76
+ * ps-verifies the PIDs, and SIGTERMs the production daemon. We saw this
77
+ * cause an outage on 2026-04-08 (alpha.265 daemon killed 93s after startup
78
+ * by a vitest test that called daemon.start()).
79
+ *
80
+ * Both killOrphanProcesses() and writePidfile() short-circuit under vitest
81
+ * to make the production pidfile sacred. Tests that need to verify these
82
+ * functions' behavior should use the extracted pure helpers
83
+ * (parseOrphanPidsFromPs, filterPidfilePidsToActualOrphans).
84
+ */
85
+ function isVitestProcess() {
86
+ /* v8 ignore next -- defensive: process and process.argv always exist in node @preserve */
87
+ if (typeof process === "undefined" || !Array.isArray(process.argv))
88
+ return false;
89
+ return process.argv.some((arg) => typeof arg === "string" && arg.includes("vitest"));
90
+ }
91
+ /**
92
+ * Scan `ps -eo pid,ppid,command` output for daemon-owned entry points whose
93
+ * parent has died (PPID reparented to init/PID 1). Returns the list of PIDs
94
+ * that are safe to SIGTERM — true orphans, not children of live sibling
95
+ * daemons running from worktrees, test suites, or other users of the harness.
96
+ *
97
+ * Exported so unit tests can exercise the filter without shelling out.
98
+ */
99
+ function parseOrphanPidsFromPs(psOutput, selfPid) {
100
+ const orphans = [];
101
+ for (const line of psOutput.split("\n")) {
102
+ // Explicitly exclude MCP server processes — they share a harness entry
103
+ // point but are not daemon children and must never be killed.
104
+ if (line.includes("mcp-serve") || line.includes("mcp serve"))
105
+ continue;
106
+ // Match only daemon-owned JS entry points.
107
+ if (!line.includes("agent-entry.js")
108
+ && !line.includes("daemon-entry.js")
109
+ && !line.includes("bluebubbles/entry.js")
110
+ && !line.includes("mail-entry.js")
111
+ && !line.includes("teams-entry.js")
112
+ && !line.includes("a2a-entry.js"))
113
+ continue;
114
+ // Parse `<pid> <ppid> <command...>`. ps pads these with leading spaces.
115
+ // Regex guarantees both groups are \d+ so parseInt can't produce NaN.
116
+ const match = line.trim().match(/^(\d+)\s+(\d+)\s/);
117
+ if (!match)
118
+ continue;
119
+ const pid = parseInt(match[1], 10);
120
+ const ppid = parseInt(match[2], 10);
121
+ if (pid === selfPid)
122
+ continue;
123
+ // CRITICAL: only kill processes whose parent is init (PID 1). A live
124
+ // PPID means the process belongs to another daemon instance (parallel
125
+ // test run, sibling worktree, another user of /tmp/ouroboros-daemon.sock).
126
+ // Killing those will crash unrelated harnesses — we saw this in B6
127
+ // when a vitest worker's daemon killed a production agent's children.
128
+ if (ppid !== 1)
129
+ continue;
130
+ orphans.push(pid);
131
+ }
132
+ return orphans;
133
+ }
134
+ /**
135
+ * Given a list of PIDs from the pidfile, return only those that are actual
136
+ * orphans (PPID reparented to init/PID 1). Protects against a polluted
137
+ * pidfile killing a PID that the OS has reassigned to an unrelated process.
138
+ *
139
+ * Implementation: shells out to `ps -p <csv> -o pid,ppid` for a batch lookup.
140
+ * Returns the empty list if ps fails — safer to skip cleanup than to
141
+ * wildcard-kill on a bad read.
142
+ *
143
+ * Exported for direct unit coverage.
144
+ */
145
+ function filterPidfilePidsToActualOrphans(candidatePids, psRunner = runPsCheck) {
146
+ if (candidatePids.length === 0)
147
+ return [];
148
+ const psOutput = psRunner(candidatePids);
149
+ if (psOutput === null)
150
+ return [];
151
+ const survivingOrphans = [];
152
+ // `ps -p x,y,z -o pid,ppid` emits a header line then one row per found PID.
153
+ // PIDs not found (already exited) are silently omitted — which is the
154
+ // correct behavior for us: we only want to kill live orphans.
155
+ for (const line of psOutput.split("\n")) {
156
+ const match = line.trim().match(/^(\d+)\s+(\d+)$/);
157
+ if (!match)
158
+ continue;
159
+ const pid = parseInt(match[1], 10);
160
+ const ppid = parseInt(match[2], 10);
161
+ if (ppid !== 1)
162
+ continue;
163
+ if (!candidatePids.includes(pid))
164
+ continue;
165
+ survivingOrphans.push(pid);
166
+ }
167
+ return survivingOrphans;
168
+ }
169
+ function mergeUniqueOrphanPids(...sources) {
170
+ const merged = [];
171
+ const seen = new Set();
172
+ for (const source of sources) {
173
+ for (const pid of source) {
174
+ if (seen.has(pid))
175
+ continue;
176
+ seen.add(pid);
177
+ merged.push(pid);
178
+ }
179
+ }
180
+ return merged;
181
+ }
182
+ const ORPHAN_CLEANUP_SETTLE_TIMEOUT_MS = 5_000;
183
+ const ORPHAN_CLEANUP_SETTLE_POLL_INTERVAL_MS = 50;
184
+ /* v8 ignore start -- process liveness probe; pure wait behavior covered via injected deps @preserve */
185
+ function defaultIsPidAlive(pid) {
186
+ try {
187
+ process.kill(pid, 0);
188
+ return true;
189
+ }
190
+ catch (error) {
191
+ return error.code === "EPERM";
192
+ }
193
+ }
194
+ /* v8 ignore stop */
195
+ /* v8 ignore start -- real timer wiring; wait behavior covered via injected sleep @preserve */
196
+ async function defaultSettleSleep(ms) {
197
+ await new Promise((resolve) => setTimeout(resolve, ms));
198
+ }
199
+ /* v8 ignore stop */
200
+ async function waitForOrphanProcessesToSettle(pids, deps = {}) {
201
+ if (pids.length === 0)
202
+ return [];
203
+ const isPidAlive = deps.isPidAlive ?? defaultIsPidAlive;
204
+ const now = deps.now ?? Date.now;
205
+ const sleep = deps.sleep ?? defaultSettleSleep;
206
+ const timeoutMs = deps.timeoutMs ?? ORPHAN_CLEANUP_SETTLE_TIMEOUT_MS;
207
+ const pollIntervalMs = deps.pollIntervalMs ?? ORPHAN_CLEANUP_SETTLE_POLL_INTERVAL_MS;
208
+ const deadline = now() + timeoutMs;
209
+ let survivors = pids.filter(isPidAlive);
210
+ while (survivors.length > 0 && now() < deadline) {
211
+ await sleep(pollIntervalMs);
212
+ survivors = pids.filter(isPidAlive);
213
+ }
214
+ return survivors;
215
+ }
216
+ /* v8 ignore start -- shells out to ps; covered by filterPidfilePidsToActualOrphans unit tests via injected runner @preserve */
217
+ function runPsCheck(pids) {
218
+ try {
219
+ const csv = pids.join(",");
220
+ return (0, child_process_1.execSync)(`ps -p ${csv} -o pid=,ppid=`, { encoding: "utf-8", timeout: 5000 });
221
+ }
222
+ catch {
223
+ // ps returns non-zero when none of the requested PIDs exist. Treat as
224
+ // "no survivors" rather than an error.
225
+ return "";
226
+ }
227
+ }
228
+ /* v8 ignore stop */
229
+ /**
230
+ * Kill all ouro processes from the previous daemon instance using the pidfile.
231
+ * On startup, reads PIDs from ~/.ouro-cli/daemon.pids, kills them all, then
232
+ * deletes the file. The new daemon writes its own PIDs after spawning.
233
+ *
234
+ * Safety: pidfile contents are verified before being killed — each PID must
235
+ * be an actual orphan (PPID reparented to init/PID 1) via
236
+ * `filterPidfilePidsToActualOrphans`. Otherwise a polluted pidfile (written
237
+ * by a test, or a crashed daemon whose PIDs have since been reused by the
238
+ * OS) could SIGTERM unrelated processes.
239
+ *
240
+ * Falls back to ps-based scanning scoped to true orphans (PPID=1) if the
241
+ * pidfile doesn't exist (first run, previous daemon crashed before writing,
242
+ * manual cleanup). The scope is narrow on purpose — see parseOrphanPidsFromPs.
243
+ */
244
+ /* v8 ignore start -- process lifecycle: uses kill/ps, tested via deployment @preserve */
245
+ function isProductionDaemonSocketPath(socketPath) {
246
+ return socketPath === socket_client_1.DEFAULT_DAEMON_SOCKET_PATH;
247
+ }
248
+ function killOrphanProcesses(socketPath = socket_client_1.DEFAULT_DAEMON_SOCKET_PATH) {
249
+ if (!isProductionDaemonSocketPath(socketPath)) {
250
+ (0, runtime_1.emitNervesEvent)({
251
+ level: "warn",
252
+ component: "daemon",
253
+ event: "daemon.orphan_cleanup_nonproduction_blocked",
254
+ message: "blocked orphan cleanup for non-production daemon socket",
255
+ meta: { socketPath, pidfilePath: PIDFILE_PATH },
256
+ });
257
+ return [];
258
+ }
259
+ if (isVitestProcess()) {
260
+ (0, runtime_1.emitNervesEvent)({
261
+ level: "warn",
262
+ component: "daemon",
263
+ event: "daemon.orphan_cleanup_test_blocked",
264
+ message: "blocked killOrphanProcesses from touching real pidfile under vitest",
265
+ meta: { pidfilePath: PIDFILE_PATH },
266
+ });
267
+ return [];
268
+ }
269
+ try {
270
+ let pidfileOrphans = [];
271
+ let scanOrphans = [];
272
+ // Primary: read pidfile from previous daemon
273
+ try {
274
+ const raw = fs.readFileSync(PIDFILE_PATH, "utf-8");
275
+ const candidates = raw.split("\n")
276
+ .map((s) => parseInt(s.trim(), 10))
277
+ .filter((n) => !isNaN(n) && n !== process.pid);
278
+ // Verify each candidate is an actual live orphan before killing. See
279
+ // docstring above for why this matters.
280
+ pidfileOrphans = filterPidfilePidsToActualOrphans(candidates);
281
+ fs.unlinkSync(PIDFILE_PATH);
282
+ }
283
+ catch {
284
+ // No pidfile — the ps scan below still covers true orphans.
285
+ }
286
+ // Always supplement the pidfile with the scoped ps scan. A stale or
287
+ // partial pidfile can otherwise kill one old daemon while leaving a
288
+ // sibling PPID=1 daemon alive without a socket.
289
+ try {
290
+ const result = (0, child_process_1.execSync)("ps -eo pid,ppid,command", { encoding: "utf-8", timeout: 5000 });
291
+ scanOrphans = parseOrphanPidsFromPs(result, process.pid);
292
+ }
293
+ catch { /* ps failed — best effort */ }
294
+ const pidsToKill = mergeUniqueOrphanPids(pidfileOrphans, scanOrphans);
295
+ if (pidsToKill.length > 0) {
296
+ for (const pid of pidsToKill) {
297
+ try {
298
+ process.kill(pid, "SIGTERM");
299
+ }
300
+ catch { /* already exited */ }
301
+ }
302
+ (0, runtime_1.emitNervesEvent)({
303
+ component: "daemon",
304
+ event: "daemon.orphan_cleanup",
305
+ message: `killed ${pidsToKill.length} orphaned ouro processes`,
306
+ meta: { pids: pidsToKill },
307
+ });
308
+ }
309
+ return pidsToKill;
310
+ }
311
+ catch (error) {
312
+ (0, runtime_1.emitNervesEvent)({
313
+ level: "warn",
314
+ component: "daemon",
315
+ event: "daemon.orphan_cleanup_error",
316
+ message: "failed to clean up orphaned ouro processes",
317
+ meta: { error: error instanceof Error ? error.message : String(error) },
318
+ });
319
+ return [];
320
+ }
321
+ }
322
+ /**
323
+ * Write all managed PIDs (daemon + children) to the pidfile.
324
+ * Called after all agents and senses are spawned.
325
+ */
326
+ function writePidfile(extraPids = [], socketPath = socket_client_1.DEFAULT_DAEMON_SOCKET_PATH) {
327
+ if (!isProductionDaemonSocketPath(socketPath)) {
328
+ (0, runtime_1.emitNervesEvent)({
329
+ level: "warn",
330
+ component: "daemon",
331
+ event: "daemon.write_pidfile_nonproduction_blocked",
332
+ message: "blocked production pidfile write for non-production daemon socket",
333
+ meta: { socketPath, pidfilePath: PIDFILE_PATH, attemptedPids: extraPids.length },
334
+ });
335
+ return;
336
+ }
337
+ if (isVitestProcess()) {
338
+ (0, runtime_1.emitNervesEvent)({
339
+ level: "warn",
340
+ component: "daemon",
341
+ event: "daemon.write_pidfile_test_blocked",
342
+ message: "blocked writePidfile from clobbering real pidfile under vitest",
343
+ meta: { pidfilePath: PIDFILE_PATH, attemptedPids: extraPids.length },
344
+ });
345
+ return;
346
+ }
347
+ try {
348
+ const pids = [process.pid, ...extraPids].filter(Boolean);
349
+ fs.mkdirSync(path.dirname(PIDFILE_PATH), { recursive: true });
350
+ fs.writeFileSync(PIDFILE_PATH, pids.join("\n") + "\n", "utf-8");
351
+ }
352
+ catch { /* best effort */ }
353
+ }
354
+ function readSocketIdentity(socketPath) {
355
+ try {
356
+ const stats = fs.lstatSync(socketPath);
357
+ return {
358
+ dev: stats.dev,
359
+ ino: stats.ino,
360
+ ctimeMs: stats.ctimeMs,
361
+ };
362
+ }
363
+ catch {
364
+ return null;
365
+ }
366
+ }
367
+ function sameSocketIdentity(left, right) {
368
+ if (!left || !right)
369
+ return false;
370
+ return left.dev === right.dev && left.ino === right.ino && left.ctimeMs === right.ctimeMs;
371
+ }
52
372
  function buildWorkerRows(snapshots) {
53
373
  return snapshots.map((snapshot) => ({
54
374
  agent: snapshot.name,
@@ -57,19 +377,60 @@ function buildWorkerRows(snapshots) {
57
377
  pid: snapshot.pid,
58
378
  restartCount: snapshot.restartCount,
59
379
  startedAt: snapshot.startedAt,
380
+ lastExitCode: snapshot.lastExitCode ?? null,
381
+ lastSignal: snapshot.lastSignal ?? null,
382
+ errorReason: snapshot.errorReason ?? null,
383
+ fixHint: snapshot.fixHint ?? null,
60
384
  }));
61
385
  }
386
+ function unhealthySenseRows(senses) {
387
+ return senses.filter((row) => {
388
+ if (!row.enabled)
389
+ return false;
390
+ if (row.status === "disabled" || row.status === "not_attached")
391
+ return false;
392
+ if (row.status === "interactive" || row.status === "running")
393
+ return false;
394
+ return true;
395
+ });
396
+ }
397
+ function unhealthyHealthChecks(healthChecks) {
398
+ return healthChecks.filter((row) => row.status !== "ok");
399
+ }
400
+ function overviewHealth(workers, senses, healthChecks = []) {
401
+ if (!workers.every((worker) => worker.status === "running"))
402
+ return "warn";
403
+ if (unhealthySenseRows(senses).length > 0)
404
+ return "warn";
405
+ if (unhealthyHealthChecks(healthChecks).length > 0)
406
+ return "warn";
407
+ return "ok";
408
+ }
62
409
  function formatStatusSummary(payload) {
63
- if (payload.overview.workerCount === 0 && payload.overview.senseCount === 0) {
410
+ if (payload.overview.workerCount === 0 && payload.overview.senseCount === 0 && (payload.healthChecks ?? []).length === 0) {
64
411
  return "no managed agents";
65
412
  }
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}`),
413
+ const degraded = [
414
+ ...payload.workers
415
+ .filter((row) => row.status !== "running")
416
+ .map((row) => `worker:${row.agent}/${row.worker}:${row.status}`),
417
+ ...unhealthySenseRows(payload.senses)
418
+ .map((row) => `sense:${row.agent}/${row.sense}:${row.status}`),
419
+ ...(payload.healthChecks ?? [])
420
+ .filter((row) => row.status !== "ok")
421
+ .map((row) => `health-check:${row.name}:${row.status}`),
71
422
  ];
72
- const detail = rows.length > 0 ? `\titems=${rows.join(",")}` : "";
423
+ const detail = degraded.length > 0 ? `\tdegraded=${degraded.join(",")}` : "";
424
+ if (!detail) {
425
+ const rows = [
426
+ ...payload.workers.map((row) => `${row.agent}/${row.worker}:${row.status}`),
427
+ ...payload.senses
428
+ .filter((row) => row.enabled)
429
+ .map((row) => `${row.agent}/${row.sense}:${row.status}`),
430
+ ];
431
+ const items = rows.length > 0 ? `\titems=${rows.join(",")}` : "";
432
+ return `daemon=${payload.overview.daemon}\tworkers=${payload.overview.workerCount}\tsenses=${payload.overview.senseCount}\thealth=${payload.overview.health}${items}`;
433
+ }
73
434
  return `daemon=${payload.overview.daemon}\tworkers=${payload.overview.workerCount}\tsenses=${payload.overview.senseCount}\thealth=${payload.overview.health}${detail}`;
74
435
  }
75
436
  function parseIncomingCommand(raw) {
@@ -89,6 +450,64 @@ function parseIncomingCommand(raw) {
89
450
  }
90
451
  return parsed;
91
452
  }
453
+ function isValidSenseReviveCommand(command) {
454
+ return typeof command.agent === "string"
455
+ && typeof command.sense === "string"
456
+ && typeof command.reason === "string";
457
+ }
458
+ /**
459
+ * Handle agent.senseTurn command: runs a full agent turn via the daemon process.
460
+ * Dynamic import lazy-loads shared-turn. Hot-reload works because ouro dev
461
+ * restarts the daemon process (fresh module cache).
462
+ */
463
+ async function handleAgentSenseTurn(command, runtime) {
464
+ try {
465
+ const { setAgentName } = await Promise.resolve().then(() => __importStar(require("../identity")));
466
+ setAgentName(command.agent);
467
+ const { runSenseTurn } = await Promise.resolve().then(() => __importStar(require("../../senses/shared-turn")));
468
+ const result = await runSenseTurn({
469
+ agentName: command.agent,
470
+ channel: command.channel,
471
+ sessionKey: command.sessionKey,
472
+ friendId: command.friendId,
473
+ userMessage: command.message,
474
+ ...(runtime?.socketPath ? { toolContext: { daemonSocketPath: runtime.socketPath } } : {}),
475
+ // Per-turn, per-agent runtime MCP injection (e.g. Workbench's ouro_workbench).
476
+ // Scoped to THIS turn only — never stored as module state, so a concurrent
477
+ // turn for a different agent cannot inherit these servers.
478
+ ...(command.runtimeMcp ? { runtimeMcpServers: command.runtimeMcp } : {}),
479
+ });
480
+ return {
481
+ ok: true,
482
+ message: result.response,
483
+ data: { ponderDeferred: result.ponderDeferred },
484
+ };
485
+ }
486
+ catch (error) {
487
+ /* v8 ignore next -- branch: String(error) fallback only for non-Error throws @preserve */
488
+ const errorMessage = error instanceof Error ? error.message : String(error);
489
+ return { ok: false, error: `sense turn failed: ${errorMessage}` };
490
+ }
491
+ }
492
+ async function handleAgentAskTurn(command, runtime) {
493
+ /* v8 ignore start -- ask command parameter defaults are legacy MCP compatibility; send_message shares the primary path @preserve */
494
+ const question = typeof command.question === "string" ? command.question : "";
495
+ if (!question.trim())
496
+ return { ok: false, error: "Missing required parameter: question" };
497
+ const channel = typeof command.channel === "string" && command.channel.trim() ? command.channel.trim() : "mcp";
498
+ const sessionKey = typeof command.sessionKey === "string" && command.sessionKey.trim()
499
+ ? command.sessionKey.trim()
500
+ : `agent-ask:${command.friendId}`;
501
+ /* v8 ignore stop */
502
+ return handleAgentSenseTurn({
503
+ kind: "agent.senseTurn",
504
+ agent: command.agent,
505
+ friendId: command.friendId,
506
+ channel,
507
+ sessionKey,
508
+ message: question,
509
+ }, runtime);
510
+ }
92
511
  class OuroDaemon {
93
512
  socketPath;
94
513
  processManager;
@@ -97,7 +516,13 @@ class OuroDaemon {
97
516
  router;
98
517
  senseManager;
99
518
  bundlesRoot;
519
+ mode;
100
520
  server = null;
521
+ mailboxServer = null;
522
+ socketIdentity = null;
523
+ senseAutostartTimer = null;
524
+ mailboxServerFactory;
525
+ onStopCommandComplete;
101
526
  constructor(options) {
102
527
  this.socketPath = options.socketPath;
103
528
  this.processManager = options.processManager;
@@ -106,6 +531,77 @@ class OuroDaemon {
106
531
  this.router = options.router;
107
532
  this.senseManager = options.senseManager ?? null;
108
533
  this.bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
534
+ this.mode = options.mode ?? "production";
535
+ this.mailboxServerFactory = options.mailboxServerFactory ?? this.createDefaultMailboxServer.bind(this);
536
+ this.onStopCommandComplete = options.onStopCommandComplete ?? null;
537
+ }
538
+ /* 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 */
539
+ createDefaultMailboxServer() {
540
+ return (0, mailbox_http_1.startMailboxHttpServer)({
541
+ host: "127.0.0.1",
542
+ port: mailbox_types_1.MAILBOX_DEFAULT_PORT,
543
+ bundlesRoot: this.bundlesRoot,
544
+ readMachineState: () => (0, mailbox_read_1.readMailboxMachineState)({ bundlesRoot: this.bundlesRoot }),
545
+ readMachineView: ({ machine }) => {
546
+ const overview = this.buildStatusPayload().overview;
547
+ return (0, mailbox_view_1.buildMailboxMachineView)({
548
+ machine,
549
+ daemon: {
550
+ status: overview.daemon,
551
+ health: overview.health,
552
+ mode: overview.mode,
553
+ socketPath: overview.socketPath,
554
+ mailboxUrl: overview.mailboxUrl,
555
+ entryPath: overview.entryPath,
556
+ workerCount: overview.workerCount,
557
+ senseCount: overview.senseCount,
558
+ },
559
+ });
560
+ },
561
+ readAgentState: (agentName) => (0, mailbox_read_1.readMailboxAgentState)(agentName, { bundlesRoot: this.bundlesRoot }),
562
+ readAgentView: (agentName) => {
563
+ const agent = (0, mailbox_read_1.readMailboxAgentState)(agentName, { bundlesRoot: this.bundlesRoot });
564
+ return (0, mailbox_view_1.buildMailboxAgentView)({
565
+ agent,
566
+ viewer: { kind: "human" },
567
+ });
568
+ },
569
+ });
570
+ }
571
+ /* v8 ignore stop */
572
+ buildStatusPayload() {
573
+ const snapshots = this.processManager.listAgentSnapshots();
574
+ const workers = buildWorkerRows(snapshots);
575
+ const senses = this.senseManager?.listSenseRows() ?? [];
576
+ const healthChecks = this.healthMonitor.getLastResults?.() ?? [];
577
+ const repoRoot = (0, identity_1.getRepoRoot)();
578
+ const sync = (0, agent_discovery_1.listBundleSyncRows)({ bundlesRoot: this.bundlesRoot });
579
+ const agents = (0, agent_discovery_1.listAllBundleAgents)({ bundlesRoot: this.bundlesRoot });
580
+ const providers = agents.flatMap((agent) => (0, provider_visibility_1.providerVisibilityStatusRows)((0, provider_visibility_1.buildAgentProviderVisibility)({
581
+ agentName: agent.name,
582
+ agentRoot: path.join(this.bundlesRoot, `${agent.name}.ouro`),
583
+ })));
584
+ const mailboxUrl = this.mailboxServer?.origin ?? "http://127.0.0.1:0";
585
+ return {
586
+ overview: {
587
+ daemon: "running",
588
+ health: overviewHealth(workers, senses, healthChecks),
589
+ socketPath: this.socketPath,
590
+ mailboxUrl,
591
+ outlookUrl: mailboxUrl,
592
+ ...(0, runtime_metadata_1.getRuntimeMetadata)(),
593
+ workerCount: workers.length,
594
+ senseCount: senses.length,
595
+ entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
596
+ mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
597
+ },
598
+ workers,
599
+ senses,
600
+ ...(healthChecks.length > 0 ? { healthChecks } : {}),
601
+ sync,
602
+ agents,
603
+ ...(providers.length > 0 ? { providers } : {}),
604
+ };
109
605
  }
110
606
  async start() {
111
607
  if (this.server)
@@ -116,62 +612,180 @@ class OuroDaemon {
116
612
  message: "starting daemon server",
117
613
  meta: { socketPath: this.socketPath },
118
614
  });
615
+ try {
616
+ await this.startInner();
617
+ }
618
+ catch (err) {
619
+ // Emit a paired terminating event (`_error`) so the nerves audit's
620
+ // start_end_pairing rule is satisfied when startup throws mid-sequence
621
+ // and `stop()` (which emits `server_end`) is never called.
622
+ (0, runtime_1.emitNervesEvent)({
623
+ level: "error",
624
+ component: "daemon",
625
+ event: "daemon.server_error",
626
+ message: "daemon start failed",
627
+ meta: {
628
+ error: err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err),
629
+ },
630
+ });
631
+ throw err;
632
+ }
633
+ }
634
+ async startInner() {
119
635
  // Register update hooks and apply pending updates before starting agents
120
636
  (0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
637
+ (0, update_hooks_1.registerUpdateHook)(agent_config_v2_1.agentConfigV2Hook);
121
638
  const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
122
639
  await (0, update_hooks_1.applyPendingUpdates)(this.bundlesRoot, currentVersion);
123
640
  // 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
- }
641
+ // Skip in dev mode — dev builds should not auto-update from npm
642
+ if (this.mode === "dev") {
643
+ (0, runtime_1.emitNervesEvent)({
644
+ component: "daemon",
645
+ event: "daemon.update_checker_skip",
646
+ message: "skipping update checker in dev mode",
647
+ meta: { reason: "dev mode" },
648
+ });
649
+ }
650
+ else {
651
+ (0, update_checker_1.startUpdateChecker)({
652
+ currentVersion,
653
+ deps: {
654
+ distTag: update_checker_1.CLI_UPDATE_DIST_TAG,
655
+ fetchRegistryJson: /* v8 ignore next -- integration: real HTTP fetch @preserve */ async () => {
656
+ const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
657
+ return res.json();
149
658
  },
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();
659
+ },
660
+ });
661
+ }
662
+ // MCP connections are lazily initialized per-agent during senseTurn
663
+ // (daemon manages multiple agents; agent identity must be set before loading MCP config)
664
+ /* v8 ignore start -- orphan cleanup + pidfile: calls process management functions @preserve */
665
+ const killedOrphanPids = killOrphanProcesses(this.socketPath);
666
+ await waitForOrphanProcessesToSettle(killedOrphanPids);
667
+ /* v8 ignore stop */
668
+ await this.openCommandSocket();
669
+ this.triggerAutoStartAgents();
670
+ this.triggerAutoStartSensesWhenAgentsSettled();
671
+ // Write all managed PIDs to disk so the next daemon can clean up
672
+ /* v8 ignore start -- pidfile write: collects PIDs from process managers @preserve */
673
+ const agentPids = this.processManager.listAgentSnapshots().map((s) => s.pid).filter((p) => p !== null);
674
+ const sensePids = this.senseManager?.listManagedPids?.() ?? [];
675
+ writePidfile([...agentPids, ...sensePids], this.socketPath);
676
+ /* v8 ignore stop */
159
677
  this.scheduler.start?.();
160
678
  await this.scheduler.reconcile?.();
161
679
  await this.drainPendingBundleMessages();
162
680
  await this.drainPendingSenseMessages();
681
+ // startInner is only reachable when this.server is null (guarded in
682
+ // start()), and stop() nulls out this.mailboxServer alongside this.server,
683
+ // so mailboxServer is guaranteed unset here — no need for a guard.
684
+ try {
685
+ this.mailboxServer = await this.mailboxServerFactory();
686
+ }
687
+ catch (error) {
688
+ (0, runtime_1.emitNervesEvent)({
689
+ level: "warn",
690
+ component: "daemon",
691
+ event: "daemon.mailbox_start_failed",
692
+ message: `Mailbox server failed to start: ${String(error)}`,
693
+ meta: { port: mailbox_types_1.MAILBOX_DEFAULT_PORT },
694
+ });
695
+ }
696
+ }
697
+ triggerAutoStartAgents() {
698
+ if (this.processManager.triggerAutoStartAgents) {
699
+ this.processManager.triggerAutoStartAgents();
700
+ return;
701
+ }
702
+ void this.processManager.startAutoStartAgents().catch((error) => {
703
+ (0, runtime_1.emitNervesEvent)({
704
+ level: "error",
705
+ component: "daemon",
706
+ event: "daemon.agent_autostart_error",
707
+ message: "agent autostart failed after daemon socket opened",
708
+ meta: { error: error instanceof Error ? error.message : String(error) },
709
+ });
710
+ });
711
+ }
712
+ triggerAutoStartSenses() {
713
+ /* v8 ignore next -- defensive: callers already check senseManager before delegating here @preserve */
714
+ if (!this.senseManager)
715
+ return;
716
+ if (this.senseManager.triggerAutoStartSenses) {
717
+ this.senseManager.triggerAutoStartSenses();
718
+ return;
719
+ }
720
+ void this.senseManager.startAutoStartSenses().catch((error) => {
721
+ (0, runtime_1.emitNervesEvent)({
722
+ level: "error",
723
+ component: "daemon",
724
+ event: "daemon.sense_autostart_error",
725
+ message: "sense autostart failed after daemon socket opened",
726
+ meta: { error: error instanceof Error ? error.message : String(error) },
727
+ });
728
+ });
729
+ }
730
+ triggerAutoStartSensesWhenAgentsSettled() {
731
+ if (!this.senseManager)
732
+ return;
733
+ const waitingOnAgents = this.processManager.listAgentSnapshots()
734
+ .some((snapshot) => snapshot.status === "starting");
735
+ if (!waitingOnAgents) {
736
+ this.triggerAutoStartSenses();
737
+ return;
738
+ }
739
+ this.senseAutostartTimer = setTimeout(() => {
740
+ this.senseAutostartTimer = null;
741
+ this.triggerAutoStartSensesWhenAgentsSettled();
742
+ }, 250);
743
+ }
744
+ async openCommandSocket() {
163
745
  if (fs.existsSync(this.socketPath)) {
164
746
  fs.unlinkSync(this.socketPath);
165
747
  }
166
- this.server = net.createServer((connection) => {
748
+ // allowHalfOpen: true lets the server keep its writable side open after
749
+ // the client sends FIN. Without this, when a client calls `client.end()`
750
+ // after writing a command, node closes the server's writable side
751
+ // automatically — so a long-running response (like an agent.senseTurn
752
+ // LLM turn that takes 5+ seconds) never reaches the client. The
753
+ // socket-client fix in #303/#334 also removed client.end() on the
754
+ // sending side, but this option is defense in depth: even if a future
755
+ // caller half-closes, the server still writes its response correctly.
756
+ this.server = net.createServer({ allowHalfOpen: true }, (connection) => {
167
757
  let raw = "";
168
758
  let responded = false;
759
+ /* v8 ignore start — connection error handler requires real socket error @preserve */
760
+ connection.on("error", (err) => {
761
+ (0, runtime_1.emitNervesEvent)({
762
+ level: "warn",
763
+ component: "daemon",
764
+ event: "daemon.connection_error",
765
+ message: "socket connection error",
766
+ meta: { error: err.message, code: err.code ?? null },
767
+ });
768
+ });
769
+ /* v8 ignore stop */
169
770
  const flushResponse = async () => {
170
771
  if (responded)
171
772
  return;
172
773
  responded = true;
173
774
  const response = await this.handleRawPayload(raw);
174
- connection.end(response);
775
+ try {
776
+ connection.end(response);
777
+ /* v8 ignore start — EPIPE catch requires real socket disconnect @preserve */
778
+ }
779
+ catch (err) {
780
+ (0, runtime_1.emitNervesEvent)({
781
+ level: "warn",
782
+ component: "daemon",
783
+ event: "daemon.connection_end_error",
784
+ message: "failed to send response to client (EPIPE)",
785
+ meta: { error: err instanceof Error ? err.message : String(err) },
786
+ });
787
+ }
788
+ /* v8 ignore stop */
175
789
  };
176
790
  connection.on("data", (chunk) => {
177
791
  raw += chunk.toString("utf-8");
@@ -184,7 +798,23 @@ class OuroDaemon {
184
798
  const server = this.server;
185
799
  await new Promise((resolve, reject) => {
186
800
  server.once("error", reject);
187
- server.listen(this.socketPath, () => resolve());
801
+ server.listen(this.socketPath, () => {
802
+ // Replace the one-time error listener with a persistent one after successful listen
803
+ server.removeAllListeners("error");
804
+ this.socketIdentity = readSocketIdentity(this.socketPath);
805
+ /* v8 ignore start — server error after listen requires real socket race condition @preserve */
806
+ server.on("error", (err) => {
807
+ (0, runtime_1.emitNervesEvent)({
808
+ level: "error",
809
+ component: "daemon",
810
+ event: "daemon.server_error",
811
+ message: "daemon server error after listen",
812
+ meta: { error: err.message, code: err.code ?? null },
813
+ });
814
+ });
815
+ /* v8 ignore stop */
816
+ resolve();
817
+ });
188
818
  });
189
819
  }
190
820
  async drainPendingBundleMessages() {
@@ -323,25 +953,87 @@ class OuroDaemon {
323
953
  }
324
954
  }
325
955
  async stop() {
956
+ // Must be named `_end` (not `_stop`) to satisfy the nerves audit's
957
+ // start/end pairing rule — see src/nerves/coverage/audit-rules.ts.
958
+ // This is the counterpart to `daemon.server_start` emitted at line 480.
326
959
  (0, runtime_1.emitNervesEvent)({
327
960
  component: "daemon",
328
- event: "daemon.server_stop",
961
+ event: "daemon.server_end",
329
962
  message: "stopping daemon server",
330
963
  meta: { socketPath: this.socketPath },
331
964
  });
332
965
  (0, update_checker_1.stopUpdateChecker)();
966
+ (0, mcp_manager_1.shutdownSharedMcpManager)();
333
967
  this.scheduler.stop?.();
968
+ this.healthMonitor.stopPeriodicChecks?.();
969
+ if (this.senseAutostartTimer) {
970
+ clearTimeout(this.senseAutostartTimer);
971
+ this.senseAutostartTimer = null;
972
+ }
334
973
  await this.processManager.stopAll();
335
974
  await this.senseManager?.stopAll();
336
975
  if (this.server) {
337
- await new Promise((resolve) => {
338
- this.server?.close(() => resolve());
339
- });
976
+ // DO NOT `await` server.close() here. server.close() resolves only
977
+ // after every open connection has closed. When stop() is invoked
978
+ // from the daemon.stop command handler, the calling client's
979
+ // connection is STILL open — its flushResponse() is currently
980
+ // awaiting THIS function. Awaiting close() creates a deadlock:
981
+ //
982
+ // client → flushResponse → handleRawPayload → daemon.stop case
983
+ // → stop() → await server.close() (waits for client's connection)
984
+ // → client's connection waits for flushResponse to call
985
+ // connection.end() → DEADLOCK
986
+ //
987
+ // Both processes sit in kevent forever. Verified live on
988
+ // 2026-04-08: alpha.268 daemon hung at `daemon.server_end` log
989
+ // line for 5+ minutes after a client sent daemon.stop, while the
990
+ // client (alpha.270 ouro up) hung waiting for the response.
991
+ //
992
+ // This regressed when #303/#334/#339 stopped half-closing the
993
+ // client socket and switched the server to allowHalfOpen: true.
994
+ // Previously, the client called .end() after writing its command,
995
+ // which (with allowHalfOpen: false) caused node to auto-tear-down
996
+ // the server's writable side — incidentally unblocking
997
+ // server.close() before the response was sent. The half-close
998
+ // breakage masked this deadlock; the fix exposed it.
999
+ //
1000
+ // Solution: fire close() and let it complete asynchronously. Once
1001
+ // stop() returns, the daemon.stop case returns its response,
1002
+ // flushResponse() calls connection.end(response), the connection
1003
+ // closes, and server.close()'s pending callback fires. The event
1004
+ // loop drains and the daemon exits cleanly.
1005
+ this.server.close();
340
1006
  this.server = null;
341
1007
  }
342
- if (fs.existsSync(this.socketPath)) {
1008
+ if (this.mailboxServer) {
1009
+ await this.mailboxServer.stop();
1010
+ this.mailboxServer = null;
1011
+ }
1012
+ const socketPathExists = fs.existsSync(this.socketPath);
1013
+ const currentSocketIdentity = socketPathExists ? readSocketIdentity(this.socketPath) : null;
1014
+ if (sameSocketIdentity(this.socketIdentity, currentSocketIdentity)) {
343
1015
  fs.unlinkSync(this.socketPath);
344
1016
  }
1017
+ else if (socketPathExists) {
1018
+ const expectedSocketIdentity = { dev: null, ino: null, ctimeMs: null, ...this.socketIdentity };
1019
+ const actualSocketIdentity = { dev: null, ino: null, ctimeMs: null, ...currentSocketIdentity };
1020
+ (0, runtime_1.emitNervesEvent)({
1021
+ level: "warn",
1022
+ component: "daemon",
1023
+ event: "daemon.socket_cleanup_skipped",
1024
+ message: "skipped daemon socket cleanup because the socket path no longer belongs to this daemon",
1025
+ meta: {
1026
+ socketPath: this.socketPath,
1027
+ expectedDev: expectedSocketIdentity.dev,
1028
+ expectedIno: expectedSocketIdentity.ino,
1029
+ expectedCtimeMs: expectedSocketIdentity.ctimeMs,
1030
+ actualDev: actualSocketIdentity.dev,
1031
+ actualIno: actualSocketIdentity.ino,
1032
+ actualCtimeMs: actualSocketIdentity.ctimeMs,
1033
+ },
1034
+ });
1035
+ }
1036
+ this.socketIdentity = null;
345
1037
  }
346
1038
  async handleRawPayload(raw) {
347
1039
  try {
@@ -363,32 +1055,58 @@ class OuroDaemon {
363
1055
  message: "handling daemon command",
364
1056
  meta: { kind: command.kind },
365
1057
  });
1058
+ try {
1059
+ return await this.handleCommandInner(command);
1060
+ /* v8 ignore start — command error catch tested in daemon-command-error.test; instanceof branches defensive @preserve */
1061
+ }
1062
+ catch (error) {
1063
+ (0, runtime_1.emitNervesEvent)({
1064
+ level: "error",
1065
+ component: "daemon",
1066
+ event: "daemon.command_error",
1067
+ message: "unexpected error handling daemon command",
1068
+ meta: {
1069
+ kind: command.kind,
1070
+ error: error instanceof Error ? error.message : String(error),
1071
+ stack: error instanceof Error ? error.stack ?? null : null,
1072
+ },
1073
+ });
1074
+ throw error;
1075
+ }
1076
+ /* v8 ignore stop */
1077
+ }
1078
+ async handleCommandInner(command) {
366
1079
  switch (command.kind) {
367
1080
  case "daemon.start":
368
1081
  await this.start();
369
1082
  return { ok: true, message: "daemon started" };
370
1083
  case "daemon.stop":
371
1084
  await this.stop();
1085
+ this.onStopCommandComplete?.();
372
1086
  return { ok: true, message: "daemon stopped" };
373
- 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),
1087
+ case "daemon.restart": {
1088
+ // Restart is "stop + let launchctl respawn." Under launchctl's KeepAlive
1089
+ // policy the process is auto-restarted on exit, so daemon.restart and
1090
+ // daemon.stop differ only in intent + audit trail. In dev (no launchctl),
1091
+ // the process simply exits — same observable behavior as daemon.stop.
1092
+ (0, runtime_1.emitNervesEvent)({
1093
+ component: "daemon",
1094
+ event: "daemon.restart_requested",
1095
+ message: "daemon restart requested",
1096
+ meta: {
1097
+ reason: command.reason ?? null,
1098
+ requestedBy: command.requestedBy ?? null,
388
1099
  },
389
- workers,
390
- senses,
1100
+ });
1101
+ await this.stop();
1102
+ this.onStopCommandComplete?.();
1103
+ return {
1104
+ ok: true,
1105
+ message: "daemon restarting — launchctl will respawn",
391
1106
  };
1107
+ }
1108
+ case "daemon.status": {
1109
+ const data = this.buildStatusPayload();
392
1110
  return {
393
1111
  ok: true,
394
1112
  summary: formatStatusSummary(data),
@@ -407,15 +1125,109 @@ class OuroDaemon {
407
1125
  message: "log streaming available via ouro logs",
408
1126
  data: { logDir: "~/AgentBundles/<agent>.ouro/state/daemon/logs" },
409
1127
  };
1128
+ case "daemon.sense_revive": {
1129
+ if (!isValidSenseReviveCommand(command)) {
1130
+ return {
1131
+ ok: false,
1132
+ error: "Invalid daemon.sense_revive payload: expected string fields 'agent', 'sense', and 'reason'.",
1133
+ };
1134
+ }
1135
+ const revivedSenseRow = await this.senseManager?.reviveSense?.(command.agent, command.sense);
1136
+ if (revivedSenseRow) {
1137
+ return {
1138
+ ok: true,
1139
+ message: `revived ${command.agent}/${command.sense}`,
1140
+ data: revivedSenseRow,
1141
+ };
1142
+ }
1143
+ const managedSenseSnapshots = this.processManager.listAgentSnapshots()
1144
+ .filter((snapshot) => snapshot.name.startsWith(`${command.agent}:`));
1145
+ if (managedSenseSnapshots.length === 0) {
1146
+ return {
1147
+ ok: false,
1148
+ error: `No managed agent '${command.agent}' is registered with daemon-managed senses.`,
1149
+ };
1150
+ }
1151
+ const exactTargetName = `${command.agent}:${command.sense}`;
1152
+ const target = managedSenseSnapshots.find((snapshot) => snapshot.name === exactTargetName)
1153
+ ?? managedSenseSnapshots.find((snapshot) => snapshot.channel === command.sense);
1154
+ if (!target) {
1155
+ return {
1156
+ ok: false,
1157
+ error: `No managed sense '${command.sense}' is registered for agent '${command.agent}'.`,
1158
+ };
1159
+ }
1160
+ this.processManager.resetAgentFailureState(target.name);
1161
+ await this.processManager.startAgent(target.name);
1162
+ const freshSnapshot = this.processManager.listAgentSnapshots()
1163
+ .find((snapshot) => snapshot.name === target.name) ?? target;
1164
+ return {
1165
+ ok: true,
1166
+ message: `revived ${command.agent}/${command.sense}`,
1167
+ data: freshSnapshot,
1168
+ };
1169
+ }
410
1170
  case "agent.start":
411
1171
  await this.processManager.startAgent(command.agent);
412
1172
  return { ok: true, message: `started ${command.agent}` };
413
1173
  case "agent.stop":
414
1174
  await this.processManager.stopAgent?.(command.agent);
415
1175
  return { ok: true, message: `stopped ${command.agent}` };
416
- case "agent.restart":
417
- await this.processManager.restartAgent?.(command.agent);
418
- return { ok: true, message: `restarted ${command.agent}` };
1176
+ case "agent.restart": {
1177
+ if (!this.processManager.restartAgent) {
1178
+ return { ok: false, error: "Managed agent restart is not available." };
1179
+ }
1180
+ const managed = this.processManager.listAgentSnapshots()
1181
+ .some((snapshot) => snapshot.name === command.agent);
1182
+ if (!managed) {
1183
+ return { ok: false, error: `Unknown managed agent '${command.agent}'.` };
1184
+ }
1185
+ const restartWork = command.skipConfigCheck === true
1186
+ ? this.processManager.restartAgent(command.agent, { skipConfigCheck: true })
1187
+ : this.processManager.restartAgent(command.agent);
1188
+ void restartWork.catch((error) => {
1189
+ (0, runtime_1.emitNervesEvent)({
1190
+ level: "error",
1191
+ component: "daemon",
1192
+ event: "daemon.agent_restart_request_error",
1193
+ message: "managed agent restart failed after request acknowledgement",
1194
+ meta: {
1195
+ agent: command.agent,
1196
+ error: error instanceof Error ? error.message : String(error),
1197
+ },
1198
+ });
1199
+ });
1200
+ return { ok: true, message: `restart requested for ${command.agent}` };
1201
+ }
1202
+ case "agent.ask":
1203
+ return handleAgentAskTurn(command, { socketPath: this.socketPath });
1204
+ case "agent.status":
1205
+ return (0, agent_service_1.handleAgentStatus)(command);
1206
+ case "agent.catchup":
1207
+ return (0, agent_service_1.handleAgentCatchup)(command);
1208
+ case "agent.delegate":
1209
+ return (0, agent_service_1.handleAgentDelegate)(command);
1210
+ case "agent.getContext":
1211
+ return (0, agent_service_1.handleAgentGetContext)(command);
1212
+ case "agent.searchFacts":
1213
+ return (0, agent_service_1.handleAgentSearchFacts)(command);
1214
+ case "agent.getTask":
1215
+ return (0, agent_service_1.handleAgentGetTask)(command);
1216
+ case "agent.checkScope":
1217
+ return (0, agent_service_1.handleAgentCheckScope)(command);
1218
+ case "agent.requestDecision":
1219
+ return (0, agent_service_1.handleAgentRequestDecision)(command);
1220
+ case "agent.checkGuidance":
1221
+ return (0, agent_service_1.handleAgentCheckGuidance)(command);
1222
+ case "agent.reportProgress":
1223
+ return (0, agent_service_1.handleAgentReportProgress)(command);
1224
+ case "agent.reportBlocker":
1225
+ return (0, agent_service_1.handleAgentReportBlocker)(command);
1226
+ case "agent.reportComplete":
1227
+ return (0, agent_service_1.handleAgentReportComplete)(command);
1228
+ case "agent.senseTurn":
1229
+ return handleAgentSenseTurn(command, { socketPath: this.socketPath });
1230
+ /* v8 ignore stop */
419
1231
  case "cron.list": {
420
1232
  const jobs = this.scheduler.listJobs();
421
1233
  const summary = jobs.length === 0
@@ -428,6 +1240,20 @@ class OuroDaemon {
428
1240
  return { ok: result.ok, message: result.message };
429
1241
  }
430
1242
  case "message.send": {
1243
+ // Pure queue-only delivery. We DO NOT wake the recipient — that was
1244
+ // the 2026-05-11 $50 bleed. The Claude Code post-tool-use hook
1245
+ // (cli-exec.ts) intentionally sends only message.send for tool-use
1246
+ // events to avoid waking the agent on every tool call. The hook's
1247
+ // intent was completely defeated by this handler calling
1248
+ // `sendToAgent({type: "message"})`, which woke the inner-dialog
1249
+ // worker on EVERY message.send anyway. ~30 message.send/min × the
1250
+ // 3-turn instinct-loop cap = ~90 turns/min sustained for hours.
1251
+ //
1252
+ // Callers that want immediate processing must send `inner.wake`
1253
+ // explicitly after message.send. The CLI `ouro msg` does so
1254
+ // (lifecycle-boundary delivery should wake); the hook does so
1255
+ // only on session-start / stop, not per tool-use; the API does
1256
+ // not (notifications go to the queue).
431
1257
  const receipt = await this.router.send({
432
1258
  from: command.from,
433
1259
  to: command.to,
@@ -436,7 +1262,6 @@ class OuroDaemon {
436
1262
  sessionId: command.sessionId,
437
1263
  taskRef: command.taskRef,
438
1264
  });
439
- this.processManager.sendToAgent?.(command.to, { type: "message" });
440
1265
  return { ok: true, message: `queued message ${receipt.id}`, data: receipt };
441
1266
  }
442
1267
  case "message.poll": {
@@ -476,10 +1301,48 @@ class OuroDaemon {
476
1301
  data: receipt,
477
1302
  };
478
1303
  }
1304
+ case "habit.poke": {
1305
+ this.processManager.sendToAgent?.(command.agent, { type: "habit", habitName: command.habitName, trigger: "poke" });
1306
+ return {
1307
+ ok: true,
1308
+ message: `poked habit ${command.habitName} for ${command.agent}`,
1309
+ };
1310
+ }
1311
+ case "await.poke": {
1312
+ this.processManager.sendToAgent?.(command.agent, { type: "await", awaitName: command.awaitName });
1313
+ return {
1314
+ ok: true,
1315
+ message: `poked await ${command.awaitName} for ${command.agent}`,
1316
+ };
1317
+ }
1318
+ case "mcp.list": {
1319
+ (0, identity_1.setAgentName)(command.agent ?? "default");
1320
+ const mcpManager = await (0, mcp_manager_1.getSharedMcpManager)();
1321
+ if (!mcpManager) {
1322
+ return { ok: true, data: [], message: "no MCP servers configured" };
1323
+ }
1324
+ return { ok: true, data: mcpManager.listAllTools() };
1325
+ }
1326
+ case "mcp.call": {
1327
+ (0, identity_1.setAgentName)(command.agent ?? "default");
1328
+ const mcpCallManager = await (0, mcp_manager_1.getSharedMcpManager)();
1329
+ if (!mcpCallManager) {
1330
+ return { ok: false, error: "no MCP servers configured" };
1331
+ }
1332
+ try {
1333
+ const parsedArgs = command.args ? JSON.parse(command.args) : {};
1334
+ const result = await mcpCallManager.callTool(command.server, command.tool, parsedArgs);
1335
+ return { ok: true, data: result };
1336
+ }
1337
+ catch (error) {
1338
+ /* v8 ignore next -- defensive: callTool errors are always Error instances @preserve */
1339
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
1340
+ }
1341
+ }
479
1342
  case "hatch.start":
480
1343
  return {
481
1344
  ok: true,
482
- message: "hatch flow is stubbed in Gate 3 and completed in Gate 6",
1345
+ message: "hatch flow is stubbed; the interactive implementation lands in a later milestone",
483
1346
  };
484
1347
  default:
485
1348
  return {