@ouro.bot/cli 0.1.0-alpha.6 → 0.1.0-alpha.600

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