@ouro.bot/cli 0.1.0-alpha.62 → 0.1.0-alpha.636
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 +4070 -13
- package/dist/arc/attention-types.js +8 -0
- package/dist/arc/cares.js +144 -0
- package/dist/arc/episodes.js +118 -0
- package/dist/arc/intentions.js +134 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +266 -0
- package/dist/arc/packets.js +194 -0
- package/dist/arc/presence.js +185 -0
- package/dist/arc/task-lifecycle.js +57 -0
- package/dist/heart/active-work.js +831 -43
- package/dist/heart/agent-entry.js +69 -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/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/awaiting/await-alert.js +146 -0
- package/dist/heart/awaiting/await-expiry.js +108 -0
- package/dist/heart/awaiting/await-loader.js +91 -0
- package/dist/heart/awaiting/await-parser.js +141 -0
- package/dist/heart/awaiting/await-runtime-state.js +100 -0
- package/dist/heart/awaiting/await-scheduler.js +377 -0
- package/dist/heart/background-operations.js +281 -0
- package/dist/heart/bridges/manager.js +137 -17
- package/dist/heart/bridges/store.js +14 -2
- package/dist/heart/bundle-state.js +168 -0
- package/dist/heart/commitments.js +135 -0
- package/dist/heart/config-registry.js +322 -0
- package/dist/heart/config.js +114 -119
- package/dist/heart/core.js +914 -248
- 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-desk.js +322 -0
- package/dist/heart/daemon/cli-exec.js +7468 -0
- package/dist/heart/daemon/cli-help.js +505 -0
- package/dist/heart/daemon/cli-parse.js +1554 -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 -1700
- package/dist/heart/daemon/daemon-entry.js +485 -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 +905 -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 +873 -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 +79 -10
- package/dist/heart/daemon/logs-prune.js +110 -0
- package/dist/heart/daemon/mcp-canary.js +297 -0
- package/dist/heart/daemon/migrate-to-desk.js +848 -0
- 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/plugin-cli.js +432 -0
- package/dist/heart/daemon/process-manager.js +463 -34
- 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 +11 -3
- package/dist/heart/daemon/runtime-metadata.js +2 -30
- package/dist/heart/daemon/safe-mode.js +161 -0
- package/dist/heart/daemon/sense-manager.js +493 -38
- package/dist/heart/daemon/session-id-resolver.js +131 -0
- package/dist/heart/daemon/skill-management-installer.js +22 -9
- 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 +117 -39
- package/dist/heart/daemon/terminal-ui.js +499 -0
- package/dist/heart/daemon/thoughts.js +229 -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 -4
- 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 +37 -14
- package/dist/heart/identity.js +168 -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 +197 -0
- package/dist/heart/mailbox/readers/agent-machine.js +418 -0
- package/dist/heart/mailbox/readers/continuity-readers.js +319 -0
- package/dist/heart/mailbox/readers/mail.js +375 -0
- package/dist/heart/mailbox/readers/runtime-readers.js +756 -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 +656 -0
- package/dist/heart/migrate-config.js +100 -0
- package/dist/heart/model-capabilities.js +19 -0
- package/dist/heart/orientation-frame.js +217 -0
- package/dist/heart/platform.js +81 -0
- package/dist/heart/provider-attempt.js +134 -0
- package/dist/heart/provider-binding-resolver.js +272 -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 +23 -11
- 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 +48 -24
- package/dist/heart/session-events.js +1163 -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 +133 -0
- package/dist/heart/start-of-turn-packet.js +345 -0
- package/dist/heart/streaming.js +44 -27
- package/dist/heart/structured-output.js +196 -0
- 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 +143 -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-9-AxCxuB.js +61 -0
- package/dist/mailbox-ui/assets/index-CWzt267f.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 +715 -0
- package/dist/mailroom/body-cache.js +61 -0
- package/dist/mailroom/core.js +788 -0
- package/dist/mailroom/entry.js +160 -0
- package/dist/mailroom/file-store.js +568 -0
- package/dist/mailroom/mbox-import.js +393 -0
- package/dist/mailroom/migration.js +164 -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 +334 -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 +14 -1
- package/dist/mind/context.js +251 -101
- package/dist/mind/desk-section.js +310 -0
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/{memory.js → diary.js} +68 -76
- 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 +48 -4
- package/dist/mind/friends/types.js +2 -2
- package/dist/mind/journal-index.js +162 -0
- package/dist/mind/note-search.js +268 -0
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +6 -1
- package/dist/mind/prompt-refresh.js +3 -2
- package/dist/mind/prompt.js +1058 -146
- 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 +139 -5
- 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 +16 -10
- package/dist/repertoire/api-client.js +97 -0
- package/dist/repertoire/bitwarden-store.js +997 -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 +331 -0
- package/dist/repertoire/coding/feedback.js +197 -30
- package/dist/repertoire/coding/manager.js +163 -10
- package/dist/repertoire/coding/spawner.js +55 -9
- package/dist/repertoire/coding/tools.js +177 -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/desk/classifier.js +362 -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 +385 -0
- package/dist/repertoire/mcp-client.js +295 -0
- package/dist/repertoire/mcp-manager.js +403 -0
- package/dist/repertoire/mcp-tools.js +83 -0
- package/dist/repertoire/plugin-mcp.js +175 -0
- package/dist/repertoire/plugins.js +253 -0
- package/dist/repertoire/shell-sessions.js +133 -0
- package/dist/repertoire/skills.js +48 -4
- package/dist/repertoire/stripe-client.js +131 -0
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-attachments.js +317 -0
- package/dist/repertoire/tools-awaiting.js +372 -0
- package/dist/repertoire/tools-base.js +57 -1082
- package/dist/repertoire/tools-bluebubbles.js +2 -0
- package/dist/repertoire/tools-bridge.js +144 -0
- package/dist/repertoire/tools-bundle.js +993 -0
- package/dist/repertoire/tools-config.js +186 -0
- package/dist/repertoire/tools-continuity.js +252 -0
- package/dist/repertoire/tools-credential.js +383 -0
- package/dist/repertoire/tools-files.js +344 -0
- package/dist/repertoire/tools-flight.js +227 -0
- package/dist/repertoire/tools-flow.js +119 -0
- package/dist/repertoire/tools-github.js +3 -8
- package/dist/repertoire/tools-mail.js +1975 -0
- package/dist/repertoire/tools-notes.js +438 -0
- package/dist/repertoire/tools-obligations.js +143 -0
- package/dist/repertoire/tools-orientation.js +31 -0
- package/dist/repertoire/tools-record.js +464 -0
- package/dist/repertoire/tools-runtime.js +150 -0
- package/dist/repertoire/tools-session.js +756 -0
- package/dist/repertoire/tools-shell.js +120 -0
- package/dist/repertoire/tools-stripe.js +182 -0
- package/dist/repertoire/tools-surface.js +316 -0
- package/dist/repertoire/tools-teams.js +12 -39
- package/dist/repertoire/tools-travel.js +125 -0
- package/dist/repertoire/tools-trip.js +982 -0
- package/dist/repertoire/tools-user-profile.js +146 -0
- package/dist/repertoire/tools-vault.js +40 -0
- package/dist/repertoire/tools-voice.js +145 -0
- package/dist/repertoire/tools.js +215 -103
- 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/await-turn-message.js +58 -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 +2599 -0
- package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -71
- 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/bluebubbles-meta-guard.js +40 -0
- 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 +100 -0
- package/dist/senses/cli.js +517 -204
- package/dist/senses/commands.js +66 -3
- package/dist/senses/habit-turn-message.js +108 -0
- package/dist/senses/inner-dialog-worker.js +254 -22
- package/dist/senses/inner-dialog.js +488 -39
- package/dist/senses/mail-entry.js +66 -0
- package/dist/senses/mail.js +379 -0
- package/dist/senses/pipeline.js +666 -181
- package/dist/senses/proactive-content-guard.js +51 -0
- package/dist/senses/shared-turn.js +393 -0
- package/dist/senses/surface-tool.js +70 -0
- package/dist/senses/teams-entry.js +60 -8
- package/dist/senses/teams.js +388 -98
- package/dist/senses/trust-gate.js +100 -5
- package/dist/senses/voice/audio-playback.js +237 -0
- package/dist/senses/voice/audio-routing.js +119 -0
- package/dist/senses/voice/elevenlabs.js +202 -0
- package/dist/senses/voice/floor-control.js +431 -0
- package/dist/senses/voice/floor-controller.js +115 -0
- package/dist/senses/voice/golden-path.js +116 -0
- package/dist/senses/voice/index.js +29 -0
- package/dist/senses/voice/meeting.js +113 -0
- package/dist/senses/voice/outbound.js +190 -0
- package/dist/senses/voice/phone.js +33 -0
- package/dist/senses/voice/playback.js +139 -0
- package/dist/senses/voice/realtime-eval.js +496 -0
- package/dist/senses/voice/realtime-trace.js +531 -0
- package/dist/senses/voice/transcript.js +70 -0
- package/dist/senses/voice/turn.js +191 -0
- package/dist/senses/voice/twilio-phone-runtime.js +807 -0
- package/dist/senses/voice/twilio-phone.js +5079 -0
- package/dist/senses/voice/types.js +2 -0
- package/dist/senses/voice/whisper.js +161 -0
- package/dist/senses/voice-entry.js +81 -0
- package/dist/senses/voice-realtime-eval-command.js +99 -0
- package/dist/senses/voice-realtime-eval-entry.js +21 -0
- package/dist/senses/voice-twilio-entry.js +87 -0
- package/dist/trips/core.js +138 -0
- package/dist/trips/store.js +265 -0
- package/dist/util/frontmatter.js +53 -0
- package/package.json +42 -8
- 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 +99 -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/safe-workspace.js +0 -228
- package/dist/heart/session-recall.js +0 -116
- package/dist/mind/associative-recall.js +0 -209
- package/dist/repertoire/tasks/board.js +0 -134
- package/dist/repertoire/tasks/index.js +0 -224
- package/dist/repertoire/tasks/lifecycle.js +0 -80
- package/dist/repertoire/tasks/middleware.js +0 -65
- package/dist/repertoire/tasks/parser.js +0 -173
- package/dist/repertoire/tasks/scanner.js +0 -132
- package/dist/repertoire/tasks/transitions.js +0 -144
- 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 -7
- /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/{repertoire/tasks/types.js → heart/attachments/sources/adapter.js} +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,340 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.OuroDaemon = void 0;
|
|
37
|
+
exports.parseOrphanPidsFromPs = parseOrphanPidsFromPs;
|
|
38
|
+
exports.filterPidfilePidsToActualOrphans = filterPidfilePidsToActualOrphans;
|
|
39
|
+
exports.mergeUniqueOrphanPids = mergeUniqueOrphanPids;
|
|
40
|
+
exports.waitForOrphanProcessesToSettle = waitForOrphanProcessesToSettle;
|
|
41
|
+
exports.killOrphanProcesses = killOrphanProcesses;
|
|
42
|
+
exports.writePidfile = writePidfile;
|
|
43
|
+
exports.handleAgentSenseTurn = handleAgentSenseTurn;
|
|
44
|
+
exports.handleAgentAskTurn = handleAgentAskTurn;
|
|
37
45
|
const fs = __importStar(require("fs"));
|
|
38
46
|
const net = __importStar(require("net"));
|
|
47
|
+
const os = __importStar(require("os"));
|
|
39
48
|
const path = __importStar(require("path"));
|
|
40
49
|
const identity_1 = require("../identity");
|
|
50
|
+
const agent_discovery_1 = require("./agent-discovery");
|
|
41
51
|
const runtime_1 = require("../../nerves/runtime");
|
|
42
52
|
const runtime_metadata_1 = require("./runtime-metadata");
|
|
43
53
|
const runtime_mode_1 = require("./runtime-mode");
|
|
44
|
-
const update_hooks_1 = require("
|
|
54
|
+
const update_hooks_1 = require("../versioning/update-hooks");
|
|
45
55
|
const bundle_meta_1 = require("./hooks/bundle-meta");
|
|
56
|
+
const agent_config_v2_1 = require("./hooks/agent-config-v2");
|
|
46
57
|
const bundle_manifest_1 = require("../../mind/bundle-manifest");
|
|
47
|
-
const update_checker_1 = require("
|
|
48
|
-
const staged_restart_1 = require("./staged-restart");
|
|
58
|
+
const update_checker_1 = require("../versioning/update-checker");
|
|
49
59
|
const child_process_1 = require("child_process");
|
|
50
60
|
const pending_1 = require("../../mind/pending");
|
|
61
|
+
const agent_service_1 = require("./agent-service");
|
|
51
62
|
const channel_1 = require("../../mind/friends/channel");
|
|
63
|
+
const mcp_manager_1 = require("../../repertoire/mcp-manager");
|
|
64
|
+
const mailbox_http_1 = require("../mailbox/mailbox-http");
|
|
65
|
+
const mailbox_types_1 = require("../mailbox/mailbox-types");
|
|
66
|
+
const mailbox_read_1 = require("../mailbox/mailbox-read");
|
|
67
|
+
const mailbox_view_1 = require("../mailbox/mailbox-view");
|
|
68
|
+
const provider_visibility_1 = require("../provider-visibility");
|
|
69
|
+
const socket_client_1 = require("./socket-client");
|
|
70
|
+
const PIDFILE_PATH = path.join(os.homedir(), ".ouro-cli", "daemon.pids");
|
|
71
|
+
/**
|
|
72
|
+
* Defense-in-depth: detect if we're running under vitest. The pidfile lives
|
|
73
|
+
* at a hardcoded path under the user's real ~/.ouro-cli/ — there's no DI
|
|
74
|
+
* seam to redirect it. So when a test creates a real OuroDaemon and calls
|
|
75
|
+
* start(), the daemon's killOrphanProcesses() reads the REAL pidfile,
|
|
76
|
+
* ps-verifies the PIDs, and SIGTERMs the production daemon. We saw this
|
|
77
|
+
* cause an outage on 2026-04-08 (alpha.265 daemon killed 93s after startup
|
|
78
|
+
* by a vitest test that called daemon.start()).
|
|
79
|
+
*
|
|
80
|
+
* Both killOrphanProcesses() and writePidfile() short-circuit under vitest
|
|
81
|
+
* to make the production pidfile sacred. Tests that need to verify these
|
|
82
|
+
* functions' behavior should use the extracted pure helpers
|
|
83
|
+
* (parseOrphanPidsFromPs, filterPidfilePidsToActualOrphans).
|
|
84
|
+
*/
|
|
85
|
+
function isVitestProcess() {
|
|
86
|
+
/* v8 ignore next -- defensive: process and process.argv always exist in node @preserve */
|
|
87
|
+
if (typeof process === "undefined" || !Array.isArray(process.argv))
|
|
88
|
+
return false;
|
|
89
|
+
return process.argv.some((arg) => typeof arg === "string" && arg.includes("vitest"));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Scan `ps -eo pid,ppid,command` output for daemon-owned entry points whose
|
|
93
|
+
* parent has died (PPID reparented to init/PID 1). Returns the list of PIDs
|
|
94
|
+
* that are safe to SIGTERM — true orphans, not children of live sibling
|
|
95
|
+
* daemons running from worktrees, test suites, or other users of the harness.
|
|
96
|
+
*
|
|
97
|
+
* Exported so unit tests can exercise the filter without shelling out.
|
|
98
|
+
*/
|
|
99
|
+
function parseOrphanPidsFromPs(psOutput, selfPid) {
|
|
100
|
+
const orphans = [];
|
|
101
|
+
for (const line of psOutput.split("\n")) {
|
|
102
|
+
// Explicitly exclude MCP server processes — they share a harness entry
|
|
103
|
+
// point but are not daemon children and must never be killed.
|
|
104
|
+
if (line.includes("mcp-serve") || line.includes("mcp serve"))
|
|
105
|
+
continue;
|
|
106
|
+
// Match only daemon-owned JS entry points.
|
|
107
|
+
if (!line.includes("agent-entry.js")
|
|
108
|
+
&& !line.includes("daemon-entry.js")
|
|
109
|
+
&& !line.includes("bluebubbles/entry.js")
|
|
110
|
+
&& !line.includes("mail-entry.js")
|
|
111
|
+
&& !line.includes("teams-entry.js"))
|
|
112
|
+
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 a production agent's 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
|
+
}
|
|
52
371
|
function buildWorkerRows(snapshots) {
|
|
53
372
|
return snapshots.map((snapshot) => ({
|
|
54
373
|
agent: snapshot.name,
|
|
@@ -57,19 +376,60 @@ function buildWorkerRows(snapshots) {
|
|
|
57
376
|
pid: snapshot.pid,
|
|
58
377
|
restartCount: snapshot.restartCount,
|
|
59
378
|
startedAt: snapshot.startedAt,
|
|
379
|
+
lastExitCode: snapshot.lastExitCode ?? null,
|
|
380
|
+
lastSignal: snapshot.lastSignal ?? null,
|
|
381
|
+
errorReason: snapshot.errorReason ?? null,
|
|
382
|
+
fixHint: snapshot.fixHint ?? null,
|
|
60
383
|
}));
|
|
61
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
|
+
}
|
|
62
408
|
function formatStatusSummary(payload) {
|
|
63
|
-
if (payload.overview.workerCount === 0 && payload.overview.senseCount === 0) {
|
|
409
|
+
if (payload.overview.workerCount === 0 && payload.overview.senseCount === 0 && (payload.healthChecks ?? []).length === 0) {
|
|
64
410
|
return "no managed agents";
|
|
65
411
|
}
|
|
66
|
-
const
|
|
67
|
-
...payload.workers
|
|
68
|
-
|
|
69
|
-
.
|
|
70
|
-
|
|
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}`),
|
|
71
421
|
];
|
|
72
|
-
const detail =
|
|
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
|
+
}
|
|
73
433
|
return `daemon=${payload.overview.daemon}\tworkers=${payload.overview.workerCount}\tsenses=${payload.overview.senseCount}\thealth=${payload.overview.health}${detail}`;
|
|
74
434
|
}
|
|
75
435
|
function parseIncomingCommand(raw) {
|
|
@@ -89,6 +449,59 @@ function parseIncomingCommand(raw) {
|
|
|
89
449
|
}
|
|
90
450
|
return parsed;
|
|
91
451
|
}
|
|
452
|
+
function isValidSenseReviveCommand(command) {
|
|
453
|
+
return typeof command.agent === "string"
|
|
454
|
+
&& typeof command.sense === "string"
|
|
455
|
+
&& typeof command.reason === "string";
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Handle agent.senseTurn command: runs a full agent turn via the daemon process.
|
|
459
|
+
* Dynamic import lazy-loads shared-turn. Hot-reload works because ouro dev
|
|
460
|
+
* restarts the daemon process (fresh module cache).
|
|
461
|
+
*/
|
|
462
|
+
async function handleAgentSenseTurn(command) {
|
|
463
|
+
try {
|
|
464
|
+
const { setAgentName } = await Promise.resolve().then(() => __importStar(require("../identity")));
|
|
465
|
+
setAgentName(command.agent);
|
|
466
|
+
const { runSenseTurn } = await Promise.resolve().then(() => __importStar(require("../../senses/shared-turn")));
|
|
467
|
+
const result = await runSenseTurn({
|
|
468
|
+
agentName: command.agent,
|
|
469
|
+
channel: command.channel,
|
|
470
|
+
sessionKey: command.sessionKey,
|
|
471
|
+
friendId: command.friendId,
|
|
472
|
+
userMessage: command.message,
|
|
473
|
+
});
|
|
474
|
+
return {
|
|
475
|
+
ok: true,
|
|
476
|
+
message: result.response,
|
|
477
|
+
data: { ponderDeferred: result.ponderDeferred },
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
/* v8 ignore next -- branch: String(error) fallback only for non-Error throws @preserve */
|
|
482
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
483
|
+
return { ok: false, error: `sense turn failed: ${errorMessage}` };
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
async function handleAgentAskTurn(command) {
|
|
487
|
+
/* v8 ignore start -- ask command parameter defaults are legacy MCP compatibility; send_message shares the primary path @preserve */
|
|
488
|
+
const question = typeof command.question === "string" ? command.question : "";
|
|
489
|
+
if (!question.trim())
|
|
490
|
+
return { ok: false, error: "Missing required parameter: question" };
|
|
491
|
+
const channel = typeof command.channel === "string" && command.channel.trim() ? command.channel.trim() : "mcp";
|
|
492
|
+
const sessionKey = typeof command.sessionKey === "string" && command.sessionKey.trim()
|
|
493
|
+
? command.sessionKey.trim()
|
|
494
|
+
: `agent-ask:${command.friendId}`;
|
|
495
|
+
/* v8 ignore stop */
|
|
496
|
+
return handleAgentSenseTurn({
|
|
497
|
+
kind: "agent.senseTurn",
|
|
498
|
+
agent: command.agent,
|
|
499
|
+
friendId: command.friendId,
|
|
500
|
+
channel,
|
|
501
|
+
sessionKey,
|
|
502
|
+
message: question,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
92
505
|
class OuroDaemon {
|
|
93
506
|
socketPath;
|
|
94
507
|
processManager;
|
|
@@ -97,7 +510,13 @@ class OuroDaemon {
|
|
|
97
510
|
router;
|
|
98
511
|
senseManager;
|
|
99
512
|
bundlesRoot;
|
|
513
|
+
mode;
|
|
100
514
|
server = null;
|
|
515
|
+
mailboxServer = null;
|
|
516
|
+
socketIdentity = null;
|
|
517
|
+
senseAutostartTimer = null;
|
|
518
|
+
mailboxServerFactory;
|
|
519
|
+
onStopCommandComplete;
|
|
101
520
|
constructor(options) {
|
|
102
521
|
this.socketPath = options.socketPath;
|
|
103
522
|
this.processManager = options.processManager;
|
|
@@ -106,6 +525,77 @@ class OuroDaemon {
|
|
|
106
525
|
this.router = options.router;
|
|
107
526
|
this.senseManager = options.senseManager ?? null;
|
|
108
527
|
this.bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
|
|
528
|
+
this.mode = options.mode ?? "production";
|
|
529
|
+
this.mailboxServerFactory = options.mailboxServerFactory ?? this.createDefaultMailboxServer.bind(this);
|
|
530
|
+
this.onStopCommandComplete = options.onStopCommandComplete ?? null;
|
|
531
|
+
}
|
|
532
|
+
/* 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 */
|
|
533
|
+
createDefaultMailboxServer() {
|
|
534
|
+
return (0, mailbox_http_1.startMailboxHttpServer)({
|
|
535
|
+
host: "127.0.0.1",
|
|
536
|
+
port: mailbox_types_1.MAILBOX_DEFAULT_PORT,
|
|
537
|
+
bundlesRoot: this.bundlesRoot,
|
|
538
|
+
readMachineState: () => (0, mailbox_read_1.readMailboxMachineState)({ bundlesRoot: this.bundlesRoot }),
|
|
539
|
+
readMachineView: ({ machine }) => {
|
|
540
|
+
const overview = this.buildStatusPayload().overview;
|
|
541
|
+
return (0, mailbox_view_1.buildMailboxMachineView)({
|
|
542
|
+
machine,
|
|
543
|
+
daemon: {
|
|
544
|
+
status: overview.daemon,
|
|
545
|
+
health: overview.health,
|
|
546
|
+
mode: overview.mode,
|
|
547
|
+
socketPath: overview.socketPath,
|
|
548
|
+
mailboxUrl: overview.mailboxUrl,
|
|
549
|
+
entryPath: overview.entryPath,
|
|
550
|
+
workerCount: overview.workerCount,
|
|
551
|
+
senseCount: overview.senseCount,
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
},
|
|
555
|
+
readAgentState: (agentName) => (0, mailbox_read_1.readMailboxAgentState)(agentName, { bundlesRoot: this.bundlesRoot }),
|
|
556
|
+
readAgentView: (agentName) => {
|
|
557
|
+
const agent = (0, mailbox_read_1.readMailboxAgentState)(agentName, { bundlesRoot: this.bundlesRoot });
|
|
558
|
+
return (0, mailbox_view_1.buildMailboxAgentView)({
|
|
559
|
+
agent,
|
|
560
|
+
viewer: { kind: "human" },
|
|
561
|
+
});
|
|
562
|
+
},
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
/* v8 ignore stop */
|
|
566
|
+
buildStatusPayload() {
|
|
567
|
+
const snapshots = this.processManager.listAgentSnapshots();
|
|
568
|
+
const workers = buildWorkerRows(snapshots);
|
|
569
|
+
const senses = this.senseManager?.listSenseRows() ?? [];
|
|
570
|
+
const healthChecks = this.healthMonitor.getLastResults?.() ?? [];
|
|
571
|
+
const repoRoot = (0, identity_1.getRepoRoot)();
|
|
572
|
+
const sync = (0, agent_discovery_1.listBundleSyncRows)({ bundlesRoot: this.bundlesRoot });
|
|
573
|
+
const agents = (0, agent_discovery_1.listAllBundleAgents)({ bundlesRoot: this.bundlesRoot });
|
|
574
|
+
const providers = agents.flatMap((agent) => (0, provider_visibility_1.providerVisibilityStatusRows)((0, provider_visibility_1.buildAgentProviderVisibility)({
|
|
575
|
+
agentName: agent.name,
|
|
576
|
+
agentRoot: path.join(this.bundlesRoot, `${agent.name}.ouro`),
|
|
577
|
+
})));
|
|
578
|
+
const mailboxUrl = this.mailboxServer?.origin ?? "http://127.0.0.1:0";
|
|
579
|
+
return {
|
|
580
|
+
overview: {
|
|
581
|
+
daemon: "running",
|
|
582
|
+
health: overviewHealth(workers, senses, healthChecks),
|
|
583
|
+
socketPath: this.socketPath,
|
|
584
|
+
mailboxUrl,
|
|
585
|
+
outlookUrl: mailboxUrl,
|
|
586
|
+
...(0, runtime_metadata_1.getRuntimeMetadata)(),
|
|
587
|
+
workerCount: workers.length,
|
|
588
|
+
senseCount: senses.length,
|
|
589
|
+
entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
|
|
590
|
+
mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
|
|
591
|
+
},
|
|
592
|
+
workers,
|
|
593
|
+
senses,
|
|
594
|
+
...(healthChecks.length > 0 ? { healthChecks } : {}),
|
|
595
|
+
sync,
|
|
596
|
+
agents,
|
|
597
|
+
...(providers.length > 0 ? { providers } : {}),
|
|
598
|
+
};
|
|
109
599
|
}
|
|
110
600
|
async start() {
|
|
111
601
|
if (this.server)
|
|
@@ -116,62 +606,180 @@ class OuroDaemon {
|
|
|
116
606
|
message: "starting daemon server",
|
|
117
607
|
meta: { socketPath: this.socketPath },
|
|
118
608
|
});
|
|
609
|
+
try {
|
|
610
|
+
await this.startInner();
|
|
611
|
+
}
|
|
612
|
+
catch (err) {
|
|
613
|
+
// Emit a paired terminating event (`_error`) so the nerves audit's
|
|
614
|
+
// start_end_pairing rule is satisfied when startup throws mid-sequence
|
|
615
|
+
// and `stop()` (which emits `server_end`) is never called.
|
|
616
|
+
(0, runtime_1.emitNervesEvent)({
|
|
617
|
+
level: "error",
|
|
618
|
+
component: "daemon",
|
|
619
|
+
event: "daemon.server_error",
|
|
620
|
+
message: "daemon start failed",
|
|
621
|
+
meta: {
|
|
622
|
+
error: err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err),
|
|
623
|
+
},
|
|
624
|
+
});
|
|
625
|
+
throw err;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
async startInner() {
|
|
119
629
|
// Register update hooks and apply pending updates before starting agents
|
|
120
630
|
(0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
|
|
631
|
+
(0, update_hooks_1.registerUpdateHook)(agent_config_v2_1.agentConfigV2Hook);
|
|
121
632
|
const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
|
|
122
633
|
await (0, update_hooks_1.applyPendingUpdates)(this.bundlesRoot, currentVersion);
|
|
123
634
|
// 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
|
-
}
|
|
635
|
+
// Skip in dev mode — dev builds should not auto-update from npm
|
|
636
|
+
if (this.mode === "dev") {
|
|
637
|
+
(0, runtime_1.emitNervesEvent)({
|
|
638
|
+
component: "daemon",
|
|
639
|
+
event: "daemon.update_checker_skip",
|
|
640
|
+
message: "skipping update checker in dev mode",
|
|
641
|
+
meta: { reason: "dev mode" },
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
(0, update_checker_1.startUpdateChecker)({
|
|
646
|
+
currentVersion,
|
|
647
|
+
deps: {
|
|
648
|
+
distTag: update_checker_1.CLI_UPDATE_DIST_TAG,
|
|
649
|
+
fetchRegistryJson: /* v8 ignore next -- integration: real HTTP fetch @preserve */ async () => {
|
|
650
|
+
const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
|
|
651
|
+
return res.json();
|
|
149
652
|
},
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
await
|
|
158
|
-
|
|
653
|
+
},
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
// MCP connections are lazily initialized per-agent during senseTurn
|
|
657
|
+
// (daemon manages multiple agents; agent identity must be set before loading MCP config)
|
|
658
|
+
/* v8 ignore start -- orphan cleanup + pidfile: calls process management functions @preserve */
|
|
659
|
+
const killedOrphanPids = killOrphanProcesses(this.socketPath);
|
|
660
|
+
await waitForOrphanProcessesToSettle(killedOrphanPids);
|
|
661
|
+
/* v8 ignore stop */
|
|
662
|
+
await this.openCommandSocket();
|
|
663
|
+
this.triggerAutoStartAgents();
|
|
664
|
+
this.triggerAutoStartSensesWhenAgentsSettled();
|
|
665
|
+
// Write all managed PIDs to disk so the next daemon can clean up
|
|
666
|
+
/* v8 ignore start -- pidfile write: collects PIDs from process managers @preserve */
|
|
667
|
+
const agentPids = this.processManager.listAgentSnapshots().map((s) => s.pid).filter((p) => p !== null);
|
|
668
|
+
const sensePids = this.senseManager?.listManagedPids?.() ?? [];
|
|
669
|
+
writePidfile([...agentPids, ...sensePids], this.socketPath);
|
|
670
|
+
/* v8 ignore stop */
|
|
159
671
|
this.scheduler.start?.();
|
|
160
672
|
await this.scheduler.reconcile?.();
|
|
161
673
|
await this.drainPendingBundleMessages();
|
|
162
674
|
await this.drainPendingSenseMessages();
|
|
675
|
+
// startInner is only reachable when this.server is null (guarded in
|
|
676
|
+
// start()), and stop() nulls out this.mailboxServer alongside this.server,
|
|
677
|
+
// so mailboxServer is guaranteed unset here — no need for a guard.
|
|
678
|
+
try {
|
|
679
|
+
this.mailboxServer = await this.mailboxServerFactory();
|
|
680
|
+
}
|
|
681
|
+
catch (error) {
|
|
682
|
+
(0, runtime_1.emitNervesEvent)({
|
|
683
|
+
level: "warn",
|
|
684
|
+
component: "daemon",
|
|
685
|
+
event: "daemon.mailbox_start_failed",
|
|
686
|
+
message: `Mailbox server failed to start: ${String(error)}`,
|
|
687
|
+
meta: { port: mailbox_types_1.MAILBOX_DEFAULT_PORT },
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
triggerAutoStartAgents() {
|
|
692
|
+
if (this.processManager.triggerAutoStartAgents) {
|
|
693
|
+
this.processManager.triggerAutoStartAgents();
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
void this.processManager.startAutoStartAgents().catch((error) => {
|
|
697
|
+
(0, runtime_1.emitNervesEvent)({
|
|
698
|
+
level: "error",
|
|
699
|
+
component: "daemon",
|
|
700
|
+
event: "daemon.agent_autostart_error",
|
|
701
|
+
message: "agent autostart failed after daemon socket opened",
|
|
702
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
triggerAutoStartSenses() {
|
|
707
|
+
/* v8 ignore next -- defensive: callers already check senseManager before delegating here @preserve */
|
|
708
|
+
if (!this.senseManager)
|
|
709
|
+
return;
|
|
710
|
+
if (this.senseManager.triggerAutoStartSenses) {
|
|
711
|
+
this.senseManager.triggerAutoStartSenses();
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
void this.senseManager.startAutoStartSenses().catch((error) => {
|
|
715
|
+
(0, runtime_1.emitNervesEvent)({
|
|
716
|
+
level: "error",
|
|
717
|
+
component: "daemon",
|
|
718
|
+
event: "daemon.sense_autostart_error",
|
|
719
|
+
message: "sense autostart failed after daemon socket opened",
|
|
720
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
721
|
+
});
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
triggerAutoStartSensesWhenAgentsSettled() {
|
|
725
|
+
if (!this.senseManager)
|
|
726
|
+
return;
|
|
727
|
+
const waitingOnAgents = this.processManager.listAgentSnapshots()
|
|
728
|
+
.some((snapshot) => snapshot.status === "starting");
|
|
729
|
+
if (!waitingOnAgents) {
|
|
730
|
+
this.triggerAutoStartSenses();
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
this.senseAutostartTimer = setTimeout(() => {
|
|
734
|
+
this.senseAutostartTimer = null;
|
|
735
|
+
this.triggerAutoStartSensesWhenAgentsSettled();
|
|
736
|
+
}, 250);
|
|
737
|
+
}
|
|
738
|
+
async openCommandSocket() {
|
|
163
739
|
if (fs.existsSync(this.socketPath)) {
|
|
164
740
|
fs.unlinkSync(this.socketPath);
|
|
165
741
|
}
|
|
166
|
-
|
|
742
|
+
// allowHalfOpen: true lets the server keep its writable side open after
|
|
743
|
+
// the client sends FIN. Without this, when a client calls `client.end()`
|
|
744
|
+
// after writing a command, node closes the server's writable side
|
|
745
|
+
// automatically — so a long-running response (like an agent.senseTurn
|
|
746
|
+
// LLM turn that takes 5+ seconds) never reaches the client. The
|
|
747
|
+
// socket-client fix in #303/#334 also removed client.end() on the
|
|
748
|
+
// sending side, but this option is defense in depth: even if a future
|
|
749
|
+
// caller half-closes, the server still writes its response correctly.
|
|
750
|
+
this.server = net.createServer({ allowHalfOpen: true }, (connection) => {
|
|
167
751
|
let raw = "";
|
|
168
752
|
let responded = false;
|
|
753
|
+
/* v8 ignore start — connection error handler requires real socket error @preserve */
|
|
754
|
+
connection.on("error", (err) => {
|
|
755
|
+
(0, runtime_1.emitNervesEvent)({
|
|
756
|
+
level: "warn",
|
|
757
|
+
component: "daemon",
|
|
758
|
+
event: "daemon.connection_error",
|
|
759
|
+
message: "socket connection error",
|
|
760
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
761
|
+
});
|
|
762
|
+
});
|
|
763
|
+
/* v8 ignore stop */
|
|
169
764
|
const flushResponse = async () => {
|
|
170
765
|
if (responded)
|
|
171
766
|
return;
|
|
172
767
|
responded = true;
|
|
173
768
|
const response = await this.handleRawPayload(raw);
|
|
174
|
-
|
|
769
|
+
try {
|
|
770
|
+
connection.end(response);
|
|
771
|
+
/* v8 ignore start — EPIPE catch requires real socket disconnect @preserve */
|
|
772
|
+
}
|
|
773
|
+
catch (err) {
|
|
774
|
+
(0, runtime_1.emitNervesEvent)({
|
|
775
|
+
level: "warn",
|
|
776
|
+
component: "daemon",
|
|
777
|
+
event: "daemon.connection_end_error",
|
|
778
|
+
message: "failed to send response to client (EPIPE)",
|
|
779
|
+
meta: { error: err instanceof Error ? err.message : String(err) },
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
/* v8 ignore stop */
|
|
175
783
|
};
|
|
176
784
|
connection.on("data", (chunk) => {
|
|
177
785
|
raw += chunk.toString("utf-8");
|
|
@@ -184,7 +792,23 @@ class OuroDaemon {
|
|
|
184
792
|
const server = this.server;
|
|
185
793
|
await new Promise((resolve, reject) => {
|
|
186
794
|
server.once("error", reject);
|
|
187
|
-
server.listen(this.socketPath, () =>
|
|
795
|
+
server.listen(this.socketPath, () => {
|
|
796
|
+
// Replace the one-time error listener with a persistent one after successful listen
|
|
797
|
+
server.removeAllListeners("error");
|
|
798
|
+
this.socketIdentity = readSocketIdentity(this.socketPath);
|
|
799
|
+
/* v8 ignore start — server error after listen requires real socket race condition @preserve */
|
|
800
|
+
server.on("error", (err) => {
|
|
801
|
+
(0, runtime_1.emitNervesEvent)({
|
|
802
|
+
level: "error",
|
|
803
|
+
component: "daemon",
|
|
804
|
+
event: "daemon.server_error",
|
|
805
|
+
message: "daemon server error after listen",
|
|
806
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
807
|
+
});
|
|
808
|
+
});
|
|
809
|
+
/* v8 ignore stop */
|
|
810
|
+
resolve();
|
|
811
|
+
});
|
|
188
812
|
});
|
|
189
813
|
}
|
|
190
814
|
async drainPendingBundleMessages() {
|
|
@@ -323,25 +947,87 @@ class OuroDaemon {
|
|
|
323
947
|
}
|
|
324
948
|
}
|
|
325
949
|
async stop() {
|
|
950
|
+
// Must be named `_end` (not `_stop`) to satisfy the nerves audit's
|
|
951
|
+
// start/end pairing rule — see src/nerves/coverage/audit-rules.ts.
|
|
952
|
+
// This is the counterpart to `daemon.server_start` emitted at line 480.
|
|
326
953
|
(0, runtime_1.emitNervesEvent)({
|
|
327
954
|
component: "daemon",
|
|
328
|
-
event: "daemon.
|
|
955
|
+
event: "daemon.server_end",
|
|
329
956
|
message: "stopping daemon server",
|
|
330
957
|
meta: { socketPath: this.socketPath },
|
|
331
958
|
});
|
|
332
959
|
(0, update_checker_1.stopUpdateChecker)();
|
|
960
|
+
(0, mcp_manager_1.shutdownSharedMcpManager)();
|
|
333
961
|
this.scheduler.stop?.();
|
|
962
|
+
this.healthMonitor.stopPeriodicChecks?.();
|
|
963
|
+
if (this.senseAutostartTimer) {
|
|
964
|
+
clearTimeout(this.senseAutostartTimer);
|
|
965
|
+
this.senseAutostartTimer = null;
|
|
966
|
+
}
|
|
334
967
|
await this.processManager.stopAll();
|
|
335
968
|
await this.senseManager?.stopAll();
|
|
336
969
|
if (this.server) {
|
|
337
|
-
await
|
|
338
|
-
|
|
339
|
-
|
|
970
|
+
// DO NOT `await` server.close() here. server.close() resolves only
|
|
971
|
+
// after every open connection has closed. When stop() is invoked
|
|
972
|
+
// from the daemon.stop command handler, the calling client's
|
|
973
|
+
// connection is STILL open — its flushResponse() is currently
|
|
974
|
+
// awaiting THIS function. Awaiting close() creates a deadlock:
|
|
975
|
+
//
|
|
976
|
+
// client → flushResponse → handleRawPayload → daemon.stop case
|
|
977
|
+
// → stop() → await server.close() (waits for client's connection)
|
|
978
|
+
// → client's connection waits for flushResponse to call
|
|
979
|
+
// connection.end() → DEADLOCK
|
|
980
|
+
//
|
|
981
|
+
// Both processes sit in kevent forever. Verified live on
|
|
982
|
+
// 2026-04-08: alpha.268 daemon hung at `daemon.server_end` log
|
|
983
|
+
// line for 5+ minutes after a client sent daemon.stop, while the
|
|
984
|
+
// client (alpha.270 ouro up) hung waiting for the response.
|
|
985
|
+
//
|
|
986
|
+
// This regressed when #303/#334/#339 stopped half-closing the
|
|
987
|
+
// client socket and switched the server to allowHalfOpen: true.
|
|
988
|
+
// Previously, the client called .end() after writing its command,
|
|
989
|
+
// which (with allowHalfOpen: false) caused node to auto-tear-down
|
|
990
|
+
// the server's writable side — incidentally unblocking
|
|
991
|
+
// server.close() before the response was sent. The half-close
|
|
992
|
+
// breakage masked this deadlock; the fix exposed it.
|
|
993
|
+
//
|
|
994
|
+
// Solution: fire close() and let it complete asynchronously. Once
|
|
995
|
+
// stop() returns, the daemon.stop case returns its response,
|
|
996
|
+
// flushResponse() calls connection.end(response), the connection
|
|
997
|
+
// closes, and server.close()'s pending callback fires. The event
|
|
998
|
+
// loop drains and the daemon exits cleanly.
|
|
999
|
+
this.server.close();
|
|
340
1000
|
this.server = null;
|
|
341
1001
|
}
|
|
342
|
-
if (
|
|
1002
|
+
if (this.mailboxServer) {
|
|
1003
|
+
await this.mailboxServer.stop();
|
|
1004
|
+
this.mailboxServer = null;
|
|
1005
|
+
}
|
|
1006
|
+
const socketPathExists = fs.existsSync(this.socketPath);
|
|
1007
|
+
const currentSocketIdentity = socketPathExists ? readSocketIdentity(this.socketPath) : null;
|
|
1008
|
+
if (sameSocketIdentity(this.socketIdentity, currentSocketIdentity)) {
|
|
343
1009
|
fs.unlinkSync(this.socketPath);
|
|
344
1010
|
}
|
|
1011
|
+
else if (socketPathExists) {
|
|
1012
|
+
const expectedSocketIdentity = { dev: null, ino: null, ctimeMs: null, ...this.socketIdentity };
|
|
1013
|
+
const actualSocketIdentity = { dev: null, ino: null, ctimeMs: null, ...currentSocketIdentity };
|
|
1014
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1015
|
+
level: "warn",
|
|
1016
|
+
component: "daemon",
|
|
1017
|
+
event: "daemon.socket_cleanup_skipped",
|
|
1018
|
+
message: "skipped daemon socket cleanup because the socket path no longer belongs to this daemon",
|
|
1019
|
+
meta: {
|
|
1020
|
+
socketPath: this.socketPath,
|
|
1021
|
+
expectedDev: expectedSocketIdentity.dev,
|
|
1022
|
+
expectedIno: expectedSocketIdentity.ino,
|
|
1023
|
+
expectedCtimeMs: expectedSocketIdentity.ctimeMs,
|
|
1024
|
+
actualDev: actualSocketIdentity.dev,
|
|
1025
|
+
actualIno: actualSocketIdentity.ino,
|
|
1026
|
+
actualCtimeMs: actualSocketIdentity.ctimeMs,
|
|
1027
|
+
},
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
this.socketIdentity = null;
|
|
345
1031
|
}
|
|
346
1032
|
async handleRawPayload(raw) {
|
|
347
1033
|
try {
|
|
@@ -363,32 +1049,58 @@ class OuroDaemon {
|
|
|
363
1049
|
message: "handling daemon command",
|
|
364
1050
|
meta: { kind: command.kind },
|
|
365
1051
|
});
|
|
1052
|
+
try {
|
|
1053
|
+
return await this.handleCommandInner(command);
|
|
1054
|
+
/* v8 ignore start — command error catch tested in daemon-command-error.test; instanceof branches defensive @preserve */
|
|
1055
|
+
}
|
|
1056
|
+
catch (error) {
|
|
1057
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1058
|
+
level: "error",
|
|
1059
|
+
component: "daemon",
|
|
1060
|
+
event: "daemon.command_error",
|
|
1061
|
+
message: "unexpected error handling daemon command",
|
|
1062
|
+
meta: {
|
|
1063
|
+
kind: command.kind,
|
|
1064
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1065
|
+
stack: error instanceof Error ? error.stack ?? null : null,
|
|
1066
|
+
},
|
|
1067
|
+
});
|
|
1068
|
+
throw error;
|
|
1069
|
+
}
|
|
1070
|
+
/* v8 ignore stop */
|
|
1071
|
+
}
|
|
1072
|
+
async handleCommandInner(command) {
|
|
366
1073
|
switch (command.kind) {
|
|
367
1074
|
case "daemon.start":
|
|
368
1075
|
await this.start();
|
|
369
1076
|
return { ok: true, message: "daemon started" };
|
|
370
1077
|
case "daemon.stop":
|
|
371
1078
|
await this.stop();
|
|
1079
|
+
this.onStopCommandComplete?.();
|
|
372
1080
|
return { ok: true, message: "daemon stopped" };
|
|
373
|
-
case "daemon.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
senseCount: senses.length,
|
|
386
|
-
entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
|
|
387
|
-
mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
|
|
1081
|
+
case "daemon.restart": {
|
|
1082
|
+
// Restart is "stop + let launchctl respawn." Under launchctl's KeepAlive
|
|
1083
|
+
// policy the process is auto-restarted on exit, so daemon.restart and
|
|
1084
|
+
// daemon.stop differ only in intent + audit trail. In dev (no launchctl),
|
|
1085
|
+
// the process simply exits — same observable behavior as daemon.stop.
|
|
1086
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1087
|
+
component: "daemon",
|
|
1088
|
+
event: "daemon.restart_requested",
|
|
1089
|
+
message: "daemon restart requested",
|
|
1090
|
+
meta: {
|
|
1091
|
+
reason: command.reason ?? null,
|
|
1092
|
+
requestedBy: command.requestedBy ?? null,
|
|
388
1093
|
},
|
|
389
|
-
|
|
390
|
-
|
|
1094
|
+
});
|
|
1095
|
+
await this.stop();
|
|
1096
|
+
this.onStopCommandComplete?.();
|
|
1097
|
+
return {
|
|
1098
|
+
ok: true,
|
|
1099
|
+
message: "daemon restarting — launchctl will respawn",
|
|
391
1100
|
};
|
|
1101
|
+
}
|
|
1102
|
+
case "daemon.status": {
|
|
1103
|
+
const data = this.buildStatusPayload();
|
|
392
1104
|
return {
|
|
393
1105
|
ok: true,
|
|
394
1106
|
summary: formatStatusSummary(data),
|
|
@@ -407,6 +1119,48 @@ class OuroDaemon {
|
|
|
407
1119
|
message: "log streaming available via ouro logs",
|
|
408
1120
|
data: { logDir: "~/AgentBundles/<agent>.ouro/state/daemon/logs" },
|
|
409
1121
|
};
|
|
1122
|
+
case "daemon.sense_revive": {
|
|
1123
|
+
if (!isValidSenseReviveCommand(command)) {
|
|
1124
|
+
return {
|
|
1125
|
+
ok: false,
|
|
1126
|
+
error: "Invalid daemon.sense_revive payload: expected string fields 'agent', 'sense', and 'reason'.",
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
const revivedSenseRow = await this.senseManager?.reviveSense?.(command.agent, command.sense);
|
|
1130
|
+
if (revivedSenseRow) {
|
|
1131
|
+
return {
|
|
1132
|
+
ok: true,
|
|
1133
|
+
message: `revived ${command.agent}/${command.sense}`,
|
|
1134
|
+
data: revivedSenseRow,
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
const managedSenseSnapshots = this.processManager.listAgentSnapshots()
|
|
1138
|
+
.filter((snapshot) => snapshot.name.startsWith(`${command.agent}:`));
|
|
1139
|
+
if (managedSenseSnapshots.length === 0) {
|
|
1140
|
+
return {
|
|
1141
|
+
ok: false,
|
|
1142
|
+
error: `No managed agent '${command.agent}' is registered with daemon-managed senses.`,
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
const exactTargetName = `${command.agent}:${command.sense}`;
|
|
1146
|
+
const target = managedSenseSnapshots.find((snapshot) => snapshot.name === exactTargetName)
|
|
1147
|
+
?? managedSenseSnapshots.find((snapshot) => snapshot.channel === command.sense);
|
|
1148
|
+
if (!target) {
|
|
1149
|
+
return {
|
|
1150
|
+
ok: false,
|
|
1151
|
+
error: `No managed sense '${command.sense}' is registered for agent '${command.agent}'.`,
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
this.processManager.resetAgentFailureState(target.name);
|
|
1155
|
+
await this.processManager.startAgent(target.name);
|
|
1156
|
+
const freshSnapshot = this.processManager.listAgentSnapshots()
|
|
1157
|
+
.find((snapshot) => snapshot.name === target.name) ?? target;
|
|
1158
|
+
return {
|
|
1159
|
+
ok: true,
|
|
1160
|
+
message: `revived ${command.agent}/${command.sense}`,
|
|
1161
|
+
data: freshSnapshot,
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
410
1164
|
case "agent.start":
|
|
411
1165
|
await this.processManager.startAgent(command.agent);
|
|
412
1166
|
return { ok: true, message: `started ${command.agent}` };
|
|
@@ -416,6 +1170,35 @@ class OuroDaemon {
|
|
|
416
1170
|
case "agent.restart":
|
|
417
1171
|
await this.processManager.restartAgent?.(command.agent);
|
|
418
1172
|
return { ok: true, message: `restarted ${command.agent}` };
|
|
1173
|
+
case "agent.ask":
|
|
1174
|
+
return handleAgentAskTurn(command);
|
|
1175
|
+
case "agent.status":
|
|
1176
|
+
return (0, agent_service_1.handleAgentStatus)(command);
|
|
1177
|
+
case "agent.catchup":
|
|
1178
|
+
return (0, agent_service_1.handleAgentCatchup)(command);
|
|
1179
|
+
case "agent.delegate":
|
|
1180
|
+
return (0, agent_service_1.handleAgentDelegate)(command);
|
|
1181
|
+
case "agent.getContext":
|
|
1182
|
+
return (0, agent_service_1.handleAgentGetContext)(command);
|
|
1183
|
+
case "agent.searchNotes":
|
|
1184
|
+
return (0, agent_service_1.handleAgentSearchNotes)(command);
|
|
1185
|
+
case "agent.getTask":
|
|
1186
|
+
return (0, agent_service_1.handleAgentGetTask)(command);
|
|
1187
|
+
case "agent.checkScope":
|
|
1188
|
+
return (0, agent_service_1.handleAgentCheckScope)(command);
|
|
1189
|
+
case "agent.requestDecision":
|
|
1190
|
+
return (0, agent_service_1.handleAgentRequestDecision)(command);
|
|
1191
|
+
case "agent.checkGuidance":
|
|
1192
|
+
return (0, agent_service_1.handleAgentCheckGuidance)(command);
|
|
1193
|
+
case "agent.reportProgress":
|
|
1194
|
+
return (0, agent_service_1.handleAgentReportProgress)(command);
|
|
1195
|
+
case "agent.reportBlocker":
|
|
1196
|
+
return (0, agent_service_1.handleAgentReportBlocker)(command);
|
|
1197
|
+
case "agent.reportComplete":
|
|
1198
|
+
return (0, agent_service_1.handleAgentReportComplete)(command);
|
|
1199
|
+
case "agent.senseTurn":
|
|
1200
|
+
return handleAgentSenseTurn(command);
|
|
1201
|
+
/* v8 ignore stop */
|
|
419
1202
|
case "cron.list": {
|
|
420
1203
|
const jobs = this.scheduler.listJobs();
|
|
421
1204
|
const summary = jobs.length === 0
|
|
@@ -428,6 +1211,20 @@ class OuroDaemon {
|
|
|
428
1211
|
return { ok: result.ok, message: result.message };
|
|
429
1212
|
}
|
|
430
1213
|
case "message.send": {
|
|
1214
|
+
// Pure queue-only delivery. We DO NOT wake the recipient — that was
|
|
1215
|
+
// the 2026-05-11 $50 bleed. The Claude Code post-tool-use hook
|
|
1216
|
+
// (cli-exec.ts) intentionally sends only message.send for tool-use
|
|
1217
|
+
// events to avoid waking the agent on every tool call. The hook's
|
|
1218
|
+
// intent was completely defeated by this handler calling
|
|
1219
|
+
// `sendToAgent({type: "message"})`, which woke the inner-dialog
|
|
1220
|
+
// worker on EVERY message.send anyway. ~30 message.send/min × the
|
|
1221
|
+
// 3-turn instinct-loop cap = ~90 turns/min sustained for hours.
|
|
1222
|
+
//
|
|
1223
|
+
// Callers that want immediate processing must send `inner.wake`
|
|
1224
|
+
// explicitly after message.send. The CLI `ouro msg` does so
|
|
1225
|
+
// (lifecycle-boundary delivery should wake); the hook does so
|
|
1226
|
+
// only on session-start / stop, not per tool-use; the API does
|
|
1227
|
+
// not (notifications go to the queue).
|
|
431
1228
|
const receipt = await this.router.send({
|
|
432
1229
|
from: command.from,
|
|
433
1230
|
to: command.to,
|
|
@@ -436,7 +1233,6 @@ class OuroDaemon {
|
|
|
436
1233
|
sessionId: command.sessionId,
|
|
437
1234
|
taskRef: command.taskRef,
|
|
438
1235
|
});
|
|
439
|
-
this.processManager.sendToAgent?.(command.to, { type: "message" });
|
|
440
1236
|
return { ok: true, message: `queued message ${receipt.id}`, data: receipt };
|
|
441
1237
|
}
|
|
442
1238
|
case "message.poll": {
|
|
@@ -476,10 +1272,48 @@ class OuroDaemon {
|
|
|
476
1272
|
data: receipt,
|
|
477
1273
|
};
|
|
478
1274
|
}
|
|
1275
|
+
case "habit.poke": {
|
|
1276
|
+
this.processManager.sendToAgent?.(command.agent, { type: "habit", habitName: command.habitName });
|
|
1277
|
+
return {
|
|
1278
|
+
ok: true,
|
|
1279
|
+
message: `poked habit ${command.habitName} for ${command.agent}`,
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
case "await.poke": {
|
|
1283
|
+
this.processManager.sendToAgent?.(command.agent, { type: "await", awaitName: command.awaitName });
|
|
1284
|
+
return {
|
|
1285
|
+
ok: true,
|
|
1286
|
+
message: `poked await ${command.awaitName} for ${command.agent}`,
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
case "mcp.list": {
|
|
1290
|
+
(0, identity_1.setAgentName)(command.agent ?? "default");
|
|
1291
|
+
const mcpManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
1292
|
+
if (!mcpManager) {
|
|
1293
|
+
return { ok: true, data: [], message: "no MCP servers configured" };
|
|
1294
|
+
}
|
|
1295
|
+
return { ok: true, data: mcpManager.listAllTools() };
|
|
1296
|
+
}
|
|
1297
|
+
case "mcp.call": {
|
|
1298
|
+
(0, identity_1.setAgentName)(command.agent ?? "default");
|
|
1299
|
+
const mcpCallManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
1300
|
+
if (!mcpCallManager) {
|
|
1301
|
+
return { ok: false, error: "no MCP servers configured" };
|
|
1302
|
+
}
|
|
1303
|
+
try {
|
|
1304
|
+
const parsedArgs = command.args ? JSON.parse(command.args) : {};
|
|
1305
|
+
const result = await mcpCallManager.callTool(command.server, command.tool, parsedArgs);
|
|
1306
|
+
return { ok: true, data: result };
|
|
1307
|
+
}
|
|
1308
|
+
catch (error) {
|
|
1309
|
+
/* v8 ignore next -- defensive: callTool errors are always Error instances @preserve */
|
|
1310
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
479
1313
|
case "hatch.start":
|
|
480
1314
|
return {
|
|
481
1315
|
ok: true,
|
|
482
|
-
message: "hatch flow is stubbed
|
|
1316
|
+
message: "hatch flow is stubbed; the interactive implementation lands in a later milestone",
|
|
483
1317
|
};
|
|
484
1318
|
default:
|
|
485
1319
|
return {
|