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