@ouro.bot/cli 0.1.0-alpha.69 → 0.1.0-alpha.691
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 +133 -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 +4398 -14
- package/dist/a2a/card.js +57 -0
- package/dist/a2a/client.js +180 -0
- package/dist/a2a/config.js +50 -0
- package/dist/a2a/delegation-stores.js +56 -0
- package/dist/a2a/did-resolution.js +93 -0
- package/dist/a2a/identity.js +170 -0
- package/dist/a2a/inbound-share.js +107 -0
- package/dist/a2a/mission-result-wire.js +196 -0
- package/dist/a2a/onboarding.js +115 -0
- package/dist/a2a/pin-store.js +132 -0
- package/dist/a2a/seen-ledger.js +120 -0
- package/dist/a2a/server.js +604 -0
- package/dist/a2a/task-store.js +69 -0
- package/dist/a2a/transport.js +45 -0
- package/dist/a2a/types.js +3 -0
- 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/evolution.js +490 -0
- package/dist/arc/flight-recorder.js +810 -0
- package/dist/arc/intentions.js +134 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +326 -0
- package/dist/arc/packets.js +288 -0
- package/dist/arc/presence.js +185 -0
- package/dist/arc/task-lifecycle.js +57 -0
- package/dist/commerce/store.js +755 -0
- package/dist/commerce/types.js +3 -0
- package/dist/heart/active-work.js +867 -43
- package/dist/heart/agent-entry.js +160 -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 +378 -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 +331 -0
- package/dist/heart/config.js +122 -119
- package/dist/heart/context-loss-gauntlet.js +354 -0
- package/dist/heart/context-loss-sentinel.js +993 -0
- package/dist/heart/core.js +1297 -269
- package/dist/heart/cross-chat-delivery.js +8 -22
- package/dist/heart/daemon/agent-config-check.js +451 -0
- package/dist/heart/daemon/agent-discovery.js +185 -3
- package/dist/heart/daemon/agent-service.js +523 -0
- package/dist/heart/daemon/agentic-repair.js +547 -0
- package/dist/heart/daemon/await-private-wake.js +59 -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 +780 -0
- package/dist/heart/daemon/cli-desk.js +322 -0
- package/dist/heart/daemon/cli-exec.js +8100 -0
- package/dist/heart/daemon/cli-help.js +601 -0
- package/dist/heart/daemon/cli-parse.js +1995 -0
- package/dist/heart/daemon/cli-render-doctor.js +57 -0
- package/dist/heart/daemon/cli-render.js +770 -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 -1814
- package/dist/heart/daemon/daemon-entry.js +668 -6
- 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 +1222 -84
- 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/habit-private-wake.js +56 -0
- package/dist/heart/daemon/health-monitor.js +131 -3
- package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
- package/dist/heart/daemon/hooks/bundle-meta.js +135 -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 +78 -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/message-router.js +45 -5
- 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 +519 -40
- 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 +511 -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 +41 -14
- 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 +583 -43
- package/dist/heart/daemon/session-id-resolver.js +131 -0
- package/dist/heart/daemon/skill-management-installer.js +1 -1
- package/dist/heart/daemon/socket-client.js +171 -12
- package/dist/heart/daemon/stale-bundle-prune.js +96 -0
- package/dist/heart/daemon/startup-tui.js +338 -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 +255 -43
- 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/external-events/router.js +121 -0
- package/dist/heart/habits/habit-migration.js +189 -0
- package/dist/heart/habits/habit-parser.js +211 -0
- package/dist/heart/habits/habit-runtime-state.js +114 -0
- package/dist/heart/habits/habit-scheduler.js +411 -0
- package/dist/heart/habits/habit-session-summary.js +318 -0
- package/dist/heart/habits/habit-session.js +618 -0
- package/dist/heart/{daemon → hatch}/hatch-flow.js +51 -57
- 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 +53 -18
- package/dist/heart/identity.js +174 -58
- package/dist/heart/kept-notes.js +289 -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 +96 -0
- package/dist/heart/mailbox/mailbox-http-response.js +7 -0
- package/dist/heart/mailbox/mailbox-http-routes.js +375 -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 +37 -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 +428 -0
- package/dist/heart/mailbox/readers/continuity-readers.js +329 -0
- package/dist/heart/mailbox/readers/mail.js +375 -0
- package/dist/heart/mailbox/readers/runtime-readers.js +815 -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 +696 -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/primitives.js +1 -1
- package/dist/heart/private-runtime/decision-renderer.js +156 -0
- package/dist/heart/private-runtime/index.js +18 -0
- package/dist/heart/private-runtime/ledger.js +218 -0
- package/dist/heart/private-runtime/policy.js +214 -0
- package/dist/heart/private-runtime/types.js +2 -0
- package/dist/heart/progress-story.js +1 -1
- package/dist/heart/provider-attempt.js +134 -0
- package/dist/heart/provider-binding-resolver.js +273 -0
- package/dist/heart/provider-credentials.js +425 -0
- package/dist/heart/provider-failover.js +311 -0
- package/dist/heart/provider-models.js +81 -0
- package/dist/heart/provider-ping.js +262 -0
- package/dist/heart/provider-readiness-cache.js +119 -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-token.js +349 -0
- package/dist/heart/providers/openai-codex.js +55 -40
- package/dist/heart/runtime-capability-check.js +170 -0
- package/dist/heart/runtime-credentials.js +389 -0
- package/dist/heart/runtime-cwd.js +87 -0
- package/dist/heart/sense-truth.js +17 -4
- package/dist/heart/session-activity.js +90 -24
- package/dist/heart/session-events.js +1133 -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 +365 -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 +11 -7
- 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 +155 -0
- package/dist/heart/tool-friction.js +55 -0
- package/dist/heart/tool-loop.js +200 -0
- package/dist/heart/turn-context.js +450 -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 +409 -0
- package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
- package/dist/heart/{daemon → versioning}/update-checker.js +6 -1
- package/dist/heart/versioning/update-hooks.js +154 -0
- package/dist/heart/work-card.js +390 -0
- package/dist/mailbox-ui/assets/index-Du_9G9WO.css +1 -0
- package/dist/mailbox-ui/assets/index-J8zDwHmE.js +1 -0
- package/dist/mailbox-ui/assets/vendor-CcN1XpQ9.js +61 -0
- package/dist/mailbox-ui/index.html +16 -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 +24 -2
- package/dist/mind/context.js +250 -101
- package/dist/mind/desk-section.js +362 -0
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/{memory.js → diary.js} +68 -77
- package/dist/mind/embedding-provider.js +60 -0
- package/dist/mind/file-state.js +179 -0
- package/dist/mind/{associative-recall.js → note-search.js} +47 -58
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +13 -8
- package/dist/mind/prompt-refresh.js +3 -2
- package/dist/mind/prompt.js +1009 -169
- package/dist/mind/provenance-trust.js +26 -0
- package/dist/mind/record-paths.js +312 -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 +1042 -0
- package/dist/repertoire/bundle-templates.js +71 -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 +218 -30
- package/dist/repertoire/coding/index.js +15 -3
- package/dist/repertoire/coding/manager.js +166 -10
- package/dist/repertoire/coding/spawner.js +58 -11
- package/dist/repertoire/coding/tools.js +242 -14
- package/dist/repertoire/coding/workbench-client.js +272 -0
- package/dist/repertoire/coding/workbench-manager.js +346 -0
- 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 +159 -27
- package/dist/repertoire/mcp-client.js +44 -3
- package/dist/repertoire/mcp-manager.js +259 -20
- 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-a2a.js +699 -0
- package/dist/repertoire/tools-attachments.js +317 -0
- package/dist/repertoire/tools-awaiting.js +372 -0
- package/dist/repertoire/tools-base.js +63 -1095
- 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-commerce.js +253 -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-evolution.js +527 -0
- package/dist/repertoire/tools-files.js +344 -0
- package/dist/repertoire/tools-flight.js +290 -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 +459 -0
- package/dist/repertoire/tools-obligations.js +143 -0
- package/dist/repertoire/tools-orientation.js +31 -0
- package/dist/repertoire/tools-record.js +482 -0
- package/dist/repertoire/tools-runtime.js +150 -0
- package/dist/repertoire/tools-session.js +881 -0
- package/dist/repertoire/tools-shell.js +120 -0
- package/dist/repertoire/tools-stripe.js +224 -0
- package/dist/repertoire/tools-surface.js +355 -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 +250 -80
- 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/a2a-entry.js +115 -0
- package/dist/senses/attention-queue.js +186 -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 +2732 -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 +39 -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 +521 -214
- package/dist/senses/commands.js +66 -3
- package/dist/senses/habit-turn-message.js +160 -0
- package/dist/senses/mail-entry.js +66 -0
- package/dist/senses/mail.js +395 -0
- package/dist/senses/pipeline.js +873 -179
- package/dist/senses/private-runtime-worker.js +584 -0
- package/dist/senses/private-runtime.js +1145 -0
- package/dist/senses/proactive-content-guard.js +51 -0
- package/dist/senses/shared-turn.js +416 -0
- package/dist/senses/surface-tool.js +109 -0
- package/dist/senses/teams-entry.js +60 -8
- package/dist/senses/teams.js +397 -112
- package/dist/senses/trust-gate.js +104 -9
- 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 +5077 -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 +69 -0
- package/package.json +57 -12
- package/skills/agent-commerce.md +113 -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/daemon/update-hooks.js +0 -138
- package/dist/heart/safe-workspace.js +0 -228
- package/dist/heart/session-recall.js +0 -116
- package/dist/mind/friends/channel.js +0 -84
- package/dist/mind/friends/group-context.js +0 -144
- package/dist/mind/friends/resolver.js +0 -84
- package/dist/mind/friends/store-file.js +0 -190
- package/dist/mind/friends/store.js +0 -4
- package/dist/mind/friends/tokens.js +0 -26
- package/dist/mind/friends/trust-explanation.js +0 -74
- package/dist/mind/friends/types.js +0 -29
- 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 -1180
- package/dist/senses/debug-activity.js +0 -148
- package/dist/senses/inner-dialog-worker.js +0 -90
- package/dist/senses/inner-dialog.js +0 -480
- 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,43 +34,416 @@ 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");
|
|
51
|
-
const
|
|
61
|
+
const agent_service_1 = require("./agent-service");
|
|
62
|
+
const friends_1 = require("@ouro.bot/friends");
|
|
52
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 private_runtime_1 = require("../private-runtime");
|
|
70
|
+
const socket_client_1 = require("./socket-client");
|
|
71
|
+
const flight_recorder_1 = require("../../arc/flight-recorder");
|
|
72
|
+
const await_private_wake_1 = require("./await-private-wake");
|
|
73
|
+
const habit_private_wake_1 = require("./habit-private-wake");
|
|
74
|
+
const habit_parser_1 = require("../habits/habit-parser");
|
|
75
|
+
const habit_runtime_state_1 = require("../habits/habit-runtime-state");
|
|
76
|
+
const router_1 = require("../external-events/router");
|
|
77
|
+
const PIDFILE_PATH = path.join(os.homedir(), ".ouro-cli", "daemon.pids");
|
|
78
|
+
/**
|
|
79
|
+
* Defense-in-depth: detect if we're running under vitest. The pidfile lives
|
|
80
|
+
* at a hardcoded path under the user's real ~/.ouro-cli/ — there's no DI
|
|
81
|
+
* seam to redirect it. So when a test creates a real OuroDaemon and calls
|
|
82
|
+
* start(), the daemon's killOrphanProcesses() reads the REAL pidfile,
|
|
83
|
+
* ps-verifies the PIDs, and SIGTERMs the production daemon. We saw this
|
|
84
|
+
* cause an outage on 2026-04-08 (alpha.265 daemon killed 93s after startup
|
|
85
|
+
* by a vitest test that called daemon.start()).
|
|
86
|
+
*
|
|
87
|
+
* Both killOrphanProcesses() and writePidfile() short-circuit under vitest
|
|
88
|
+
* to make the production pidfile sacred. Tests that need to verify these
|
|
89
|
+
* functions' behavior should use the extracted pure helpers
|
|
90
|
+
* (parseOrphanPidsFromPs, filterPidfilePidsToActualOrphans).
|
|
91
|
+
*/
|
|
92
|
+
function isVitestProcess() {
|
|
93
|
+
/* v8 ignore next -- defensive: process and process.argv always exist in node @preserve */
|
|
94
|
+
if (typeof process === "undefined" || !Array.isArray(process.argv))
|
|
95
|
+
return false;
|
|
96
|
+
return process.argv.some((arg) => typeof arg === "string" && arg.includes("vitest"));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Scan `ps -eo pid,ppid,command` output for daemon-owned entry points whose
|
|
100
|
+
* parent has died (PPID reparented to init/PID 1). Returns the list of PIDs
|
|
101
|
+
* that are safe to SIGTERM — true orphans, not children of live sibling
|
|
102
|
+
* daemons running from worktrees, test suites, or other users of the harness.
|
|
103
|
+
*
|
|
104
|
+
* Exported so unit tests can exercise the filter without shelling out.
|
|
105
|
+
*/
|
|
106
|
+
function parseOrphanPidsFromPs(psOutput, selfPid) {
|
|
107
|
+
const orphans = [];
|
|
108
|
+
for (const line of psOutput.split("\n")) {
|
|
109
|
+
// Explicitly exclude MCP server processes — they share a harness entry
|
|
110
|
+
// point but are not daemon children and must never be killed.
|
|
111
|
+
if (line.includes("mcp-serve") || line.includes("mcp serve"))
|
|
112
|
+
continue;
|
|
113
|
+
// Match only daemon-owned JS entry points.
|
|
114
|
+
if (!line.includes("agent-entry.js")
|
|
115
|
+
&& !line.includes("daemon-entry.js")
|
|
116
|
+
&& !line.includes("bluebubbles/entry.js")
|
|
117
|
+
&& !line.includes("mail-entry.js")
|
|
118
|
+
&& !line.includes("teams-entry.js")
|
|
119
|
+
&& !line.includes("a2a-entry.js"))
|
|
120
|
+
continue;
|
|
121
|
+
// Parse `<pid> <ppid> <command...>`. ps pads these with leading spaces.
|
|
122
|
+
// Regex guarantees both groups are \d+ so parseInt can't produce NaN.
|
|
123
|
+
const match = line.trim().match(/^(\d+)\s+(\d+)\s/);
|
|
124
|
+
if (!match)
|
|
125
|
+
continue;
|
|
126
|
+
const pid = parseInt(match[1], 10);
|
|
127
|
+
const ppid = parseInt(match[2], 10);
|
|
128
|
+
if (pid === selfPid)
|
|
129
|
+
continue;
|
|
130
|
+
// CRITICAL: only kill processes whose parent is init (PID 1). A live
|
|
131
|
+
// PPID means the process belongs to another daemon instance (parallel
|
|
132
|
+
// test run, sibling worktree, another user of /tmp/ouroboros-daemon.sock).
|
|
133
|
+
// Killing those will crash unrelated harnesses — we saw this in B6
|
|
134
|
+
// when a vitest worker's daemon killed a production agent's children.
|
|
135
|
+
if (ppid !== 1)
|
|
136
|
+
continue;
|
|
137
|
+
orphans.push(pid);
|
|
138
|
+
}
|
|
139
|
+
return orphans;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Given a list of PIDs from the pidfile, return only those that are actual
|
|
143
|
+
* orphans (PPID reparented to init/PID 1). Protects against a polluted
|
|
144
|
+
* pidfile killing a PID that the OS has reassigned to an unrelated process.
|
|
145
|
+
*
|
|
146
|
+
* Implementation: shells out to `ps -p <csv> -o pid,ppid` for a batch lookup.
|
|
147
|
+
* Returns the empty list if ps fails — safer to skip cleanup than to
|
|
148
|
+
* wildcard-kill on a bad read.
|
|
149
|
+
*
|
|
150
|
+
* Exported for direct unit coverage.
|
|
151
|
+
*/
|
|
152
|
+
function filterPidfilePidsToActualOrphans(candidatePids, psRunner = runPsCheck) {
|
|
153
|
+
if (candidatePids.length === 0)
|
|
154
|
+
return [];
|
|
155
|
+
const psOutput = psRunner(candidatePids);
|
|
156
|
+
if (psOutput === null)
|
|
157
|
+
return [];
|
|
158
|
+
const survivingOrphans = [];
|
|
159
|
+
// `ps -p x,y,z -o pid,ppid` emits a header line then one row per found PID.
|
|
160
|
+
// PIDs not found (already exited) are silently omitted — which is the
|
|
161
|
+
// correct behavior for us: we only want to kill live orphans.
|
|
162
|
+
for (const line of psOutput.split("\n")) {
|
|
163
|
+
const match = line.trim().match(/^(\d+)\s+(\d+)$/);
|
|
164
|
+
if (!match)
|
|
165
|
+
continue;
|
|
166
|
+
const pid = parseInt(match[1], 10);
|
|
167
|
+
const ppid = parseInt(match[2], 10);
|
|
168
|
+
if (ppid !== 1)
|
|
169
|
+
continue;
|
|
170
|
+
if (!candidatePids.includes(pid))
|
|
171
|
+
continue;
|
|
172
|
+
survivingOrphans.push(pid);
|
|
173
|
+
}
|
|
174
|
+
return survivingOrphans;
|
|
175
|
+
}
|
|
176
|
+
function mergeUniqueOrphanPids(...sources) {
|
|
177
|
+
const merged = [];
|
|
178
|
+
const seen = new Set();
|
|
179
|
+
for (const source of sources) {
|
|
180
|
+
for (const pid of source) {
|
|
181
|
+
if (seen.has(pid))
|
|
182
|
+
continue;
|
|
183
|
+
seen.add(pid);
|
|
184
|
+
merged.push(pid);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return merged;
|
|
188
|
+
}
|
|
189
|
+
const ORPHAN_CLEANUP_SETTLE_TIMEOUT_MS = 5_000;
|
|
190
|
+
const ORPHAN_CLEANUP_SETTLE_POLL_INTERVAL_MS = 50;
|
|
191
|
+
/* v8 ignore start -- process liveness probe; pure wait behavior covered via injected deps @preserve */
|
|
192
|
+
function defaultIsPidAlive(pid) {
|
|
193
|
+
try {
|
|
194
|
+
process.kill(pid, 0);
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
return error.code === "EPERM";
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/* v8 ignore stop */
|
|
202
|
+
/* v8 ignore start -- real timer wiring; wait behavior covered via injected sleep @preserve */
|
|
203
|
+
async function defaultSettleSleep(ms) {
|
|
204
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
205
|
+
}
|
|
206
|
+
/* v8 ignore stop */
|
|
207
|
+
async function waitForOrphanProcessesToSettle(pids, deps = {}) {
|
|
208
|
+
if (pids.length === 0)
|
|
209
|
+
return [];
|
|
210
|
+
const isPidAlive = deps.isPidAlive ?? defaultIsPidAlive;
|
|
211
|
+
const now = deps.now ?? Date.now;
|
|
212
|
+
const sleep = deps.sleep ?? defaultSettleSleep;
|
|
213
|
+
const timeoutMs = deps.timeoutMs ?? ORPHAN_CLEANUP_SETTLE_TIMEOUT_MS;
|
|
214
|
+
const pollIntervalMs = deps.pollIntervalMs ?? ORPHAN_CLEANUP_SETTLE_POLL_INTERVAL_MS;
|
|
215
|
+
const deadline = now() + timeoutMs;
|
|
216
|
+
let survivors = pids.filter(isPidAlive);
|
|
217
|
+
while (survivors.length > 0 && now() < deadline) {
|
|
218
|
+
await sleep(pollIntervalMs);
|
|
219
|
+
survivors = pids.filter(isPidAlive);
|
|
220
|
+
}
|
|
221
|
+
return survivors;
|
|
222
|
+
}
|
|
223
|
+
/* v8 ignore start -- shells out to ps; covered by filterPidfilePidsToActualOrphans unit tests via injected runner @preserve */
|
|
224
|
+
function runPsCheck(pids) {
|
|
225
|
+
try {
|
|
226
|
+
const csv = pids.join(",");
|
|
227
|
+
return (0, child_process_1.execSync)(`ps -p ${csv} -o pid=,ppid=`, { encoding: "utf-8", timeout: 5000 });
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
// ps returns non-zero when none of the requested PIDs exist. Treat as
|
|
231
|
+
// "no survivors" rather than an error.
|
|
232
|
+
return "";
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/* v8 ignore stop */
|
|
236
|
+
/**
|
|
237
|
+
* Kill all ouro processes from the previous daemon instance using the pidfile.
|
|
238
|
+
* On startup, reads PIDs from ~/.ouro-cli/daemon.pids, kills them all, then
|
|
239
|
+
* deletes the file. The new daemon writes its own PIDs after spawning.
|
|
240
|
+
*
|
|
241
|
+
* Safety: pidfile contents are verified before being killed — each PID must
|
|
242
|
+
* be an actual orphan (PPID reparented to init/PID 1) via
|
|
243
|
+
* `filterPidfilePidsToActualOrphans`. Otherwise a polluted pidfile (written
|
|
244
|
+
* by a test, or a crashed daemon whose PIDs have since been reused by the
|
|
245
|
+
* OS) could SIGTERM unrelated processes.
|
|
246
|
+
*
|
|
247
|
+
* Falls back to ps-based scanning scoped to true orphans (PPID=1) if the
|
|
248
|
+
* pidfile doesn't exist (first run, previous daemon crashed before writing,
|
|
249
|
+
* manual cleanup). The scope is narrow on purpose — see parseOrphanPidsFromPs.
|
|
250
|
+
*/
|
|
251
|
+
/* v8 ignore start -- process lifecycle: uses kill/ps, tested via deployment @preserve */
|
|
252
|
+
function isProductionDaemonSocketPath(socketPath) {
|
|
253
|
+
return socketPath === socket_client_1.DEFAULT_DAEMON_SOCKET_PATH;
|
|
254
|
+
}
|
|
255
|
+
function killOrphanProcesses(socketPath = socket_client_1.DEFAULT_DAEMON_SOCKET_PATH) {
|
|
256
|
+
if (!isProductionDaemonSocketPath(socketPath)) {
|
|
257
|
+
(0, runtime_1.emitNervesEvent)({
|
|
258
|
+
level: "warn",
|
|
259
|
+
component: "daemon",
|
|
260
|
+
event: "daemon.orphan_cleanup_nonproduction_blocked",
|
|
261
|
+
message: "blocked orphan cleanup for non-production daemon socket",
|
|
262
|
+
meta: { socketPath, pidfilePath: PIDFILE_PATH },
|
|
263
|
+
});
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
if (isVitestProcess()) {
|
|
267
|
+
(0, runtime_1.emitNervesEvent)({
|
|
268
|
+
level: "warn",
|
|
269
|
+
component: "daemon",
|
|
270
|
+
event: "daemon.orphan_cleanup_test_blocked",
|
|
271
|
+
message: "blocked killOrphanProcesses from touching real pidfile under vitest",
|
|
272
|
+
meta: { pidfilePath: PIDFILE_PATH },
|
|
273
|
+
});
|
|
274
|
+
return [];
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
let pidfileOrphans = [];
|
|
278
|
+
let scanOrphans = [];
|
|
279
|
+
// Primary: read pidfile from previous daemon
|
|
280
|
+
try {
|
|
281
|
+
const raw = fs.readFileSync(PIDFILE_PATH, "utf-8");
|
|
282
|
+
const candidates = raw.split("\n")
|
|
283
|
+
.map((s) => parseInt(s.trim(), 10))
|
|
284
|
+
.filter((n) => !isNaN(n) && n !== process.pid);
|
|
285
|
+
// Verify each candidate is an actual live orphan before killing. See
|
|
286
|
+
// docstring above for why this matters.
|
|
287
|
+
pidfileOrphans = filterPidfilePidsToActualOrphans(candidates);
|
|
288
|
+
fs.unlinkSync(PIDFILE_PATH);
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
// No pidfile — the ps scan below still covers true orphans.
|
|
292
|
+
}
|
|
293
|
+
// Always supplement the pidfile with the scoped ps scan. A stale or
|
|
294
|
+
// partial pidfile can otherwise kill one old daemon while leaving a
|
|
295
|
+
// sibling PPID=1 daemon alive without a socket.
|
|
296
|
+
try {
|
|
297
|
+
const result = (0, child_process_1.execSync)("ps -eo pid,ppid,command", { encoding: "utf-8", timeout: 5000 });
|
|
298
|
+
scanOrphans = parseOrphanPidsFromPs(result, process.pid);
|
|
299
|
+
}
|
|
300
|
+
catch { /* ps failed — best effort */ }
|
|
301
|
+
const pidsToKill = mergeUniqueOrphanPids(pidfileOrphans, scanOrphans);
|
|
302
|
+
if (pidsToKill.length > 0) {
|
|
303
|
+
for (const pid of pidsToKill) {
|
|
304
|
+
try {
|
|
305
|
+
process.kill(pid, "SIGTERM");
|
|
306
|
+
}
|
|
307
|
+
catch { /* already exited */ }
|
|
308
|
+
}
|
|
309
|
+
(0, runtime_1.emitNervesEvent)({
|
|
310
|
+
component: "daemon",
|
|
311
|
+
event: "daemon.orphan_cleanup",
|
|
312
|
+
message: `killed ${pidsToKill.length} orphaned ouro processes`,
|
|
313
|
+
meta: { pids: pidsToKill },
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
return pidsToKill;
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
(0, runtime_1.emitNervesEvent)({
|
|
320
|
+
level: "warn",
|
|
321
|
+
component: "daemon",
|
|
322
|
+
event: "daemon.orphan_cleanup_error",
|
|
323
|
+
message: "failed to clean up orphaned ouro processes",
|
|
324
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
325
|
+
});
|
|
326
|
+
return [];
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Write all managed PIDs (daemon + children) to the pidfile.
|
|
331
|
+
* Called after all agents and senses are spawned.
|
|
332
|
+
*/
|
|
333
|
+
function writePidfile(extraPids = [], socketPath = socket_client_1.DEFAULT_DAEMON_SOCKET_PATH) {
|
|
334
|
+
if (!isProductionDaemonSocketPath(socketPath)) {
|
|
335
|
+
(0, runtime_1.emitNervesEvent)({
|
|
336
|
+
level: "warn",
|
|
337
|
+
component: "daemon",
|
|
338
|
+
event: "daemon.write_pidfile_nonproduction_blocked",
|
|
339
|
+
message: "blocked production pidfile write for non-production daemon socket",
|
|
340
|
+
meta: { socketPath, pidfilePath: PIDFILE_PATH, attemptedPids: extraPids.length },
|
|
341
|
+
});
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (isVitestProcess()) {
|
|
345
|
+
(0, runtime_1.emitNervesEvent)({
|
|
346
|
+
level: "warn",
|
|
347
|
+
component: "daemon",
|
|
348
|
+
event: "daemon.write_pidfile_test_blocked",
|
|
349
|
+
message: "blocked writePidfile from clobbering real pidfile under vitest",
|
|
350
|
+
meta: { pidfilePath: PIDFILE_PATH, attemptedPids: extraPids.length },
|
|
351
|
+
});
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
const pids = [process.pid, ...extraPids].filter(Boolean);
|
|
356
|
+
fs.mkdirSync(path.dirname(PIDFILE_PATH), { recursive: true });
|
|
357
|
+
fs.writeFileSync(PIDFILE_PATH, pids.join("\n") + "\n", "utf-8");
|
|
358
|
+
}
|
|
359
|
+
catch { /* best effort */ }
|
|
360
|
+
}
|
|
361
|
+
function readSocketIdentity(socketPath) {
|
|
362
|
+
try {
|
|
363
|
+
const stats = fs.lstatSync(socketPath);
|
|
364
|
+
return {
|
|
365
|
+
dev: stats.dev,
|
|
366
|
+
ino: stats.ino,
|
|
367
|
+
ctimeMs: stats.ctimeMs,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function sameSocketIdentity(left, right) {
|
|
375
|
+
if (!left || !right)
|
|
376
|
+
return false;
|
|
377
|
+
return left.dev === right.dev && left.ino === right.ino && left.ctimeMs === right.ctimeMs;
|
|
378
|
+
}
|
|
53
379
|
function buildWorkerRows(snapshots) {
|
|
54
380
|
return snapshots.map((snapshot) => ({
|
|
55
381
|
agent: snapshot.name,
|
|
56
382
|
worker: snapshot.channel,
|
|
383
|
+
autoStart: snapshot.autoStart ?? true,
|
|
57
384
|
status: snapshot.status,
|
|
58
385
|
pid: snapshot.pid,
|
|
59
386
|
restartCount: snapshot.restartCount,
|
|
60
387
|
startedAt: snapshot.startedAt,
|
|
388
|
+
lastExitCode: snapshot.lastExitCode ?? null,
|
|
389
|
+
lastSignal: snapshot.lastSignal ?? null,
|
|
390
|
+
errorReason: snapshot.errorReason ?? null,
|
|
391
|
+
fixHint: snapshot.fixHint ?? null,
|
|
61
392
|
}));
|
|
62
393
|
}
|
|
394
|
+
function unhealthySenseRows(senses) {
|
|
395
|
+
return senses.filter((row) => {
|
|
396
|
+
if (!row.enabled)
|
|
397
|
+
return false;
|
|
398
|
+
if (row.status === "disabled" || row.status === "not_attached")
|
|
399
|
+
return false;
|
|
400
|
+
if (row.status === "interactive" || row.status === "running")
|
|
401
|
+
return false;
|
|
402
|
+
return true;
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function isParkedWorker(row) {
|
|
406
|
+
return row.autoStart === false && row.status === "stopped";
|
|
407
|
+
}
|
|
408
|
+
function unhealthyWorkerRows(workers) {
|
|
409
|
+
return workers.filter((row) => !isParkedWorker(row) && row.status !== "running");
|
|
410
|
+
}
|
|
411
|
+
function unhealthyHealthChecks(healthChecks) {
|
|
412
|
+
return healthChecks.filter((row) => row.status !== "ok");
|
|
413
|
+
}
|
|
414
|
+
function overviewHealth(workers, senses, healthChecks = []) {
|
|
415
|
+
if (unhealthyWorkerRows(workers).length > 0)
|
|
416
|
+
return "warn";
|
|
417
|
+
if (unhealthySenseRows(senses).length > 0)
|
|
418
|
+
return "warn";
|
|
419
|
+
if (unhealthyHealthChecks(healthChecks).length > 0)
|
|
420
|
+
return "warn";
|
|
421
|
+
return "ok";
|
|
422
|
+
}
|
|
63
423
|
function formatStatusSummary(payload) {
|
|
64
|
-
if (payload.overview.workerCount === 0 && payload.overview.senseCount === 0) {
|
|
424
|
+
if (payload.overview.workerCount === 0 && payload.overview.senseCount === 0 && (payload.healthChecks ?? []).length === 0) {
|
|
65
425
|
return "no managed agents";
|
|
66
426
|
}
|
|
67
|
-
const
|
|
68
|
-
...payload.workers
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.map((row) =>
|
|
427
|
+
const degraded = [
|
|
428
|
+
...unhealthyWorkerRows(payload.workers)
|
|
429
|
+
.map((row) => `worker:${row.agent}/${row.worker}:${row.status}`),
|
|
430
|
+
...unhealthySenseRows(payload.senses)
|
|
431
|
+
.map((row) => `sense:${row.agent}/${row.sense}:${row.status}`),
|
|
432
|
+
...(payload.healthChecks ?? [])
|
|
433
|
+
.filter((row) => row.status !== "ok")
|
|
434
|
+
.map((row) => `health-check:${row.name}:${row.status}`),
|
|
72
435
|
];
|
|
73
|
-
const detail =
|
|
436
|
+
const detail = degraded.length > 0 ? `\tdegraded=${degraded.join(",")}` : "";
|
|
437
|
+
if (!detail) {
|
|
438
|
+
const rows = [
|
|
439
|
+
...payload.workers.map((row) => `${row.agent}/${row.worker}:${row.status}`),
|
|
440
|
+
...payload.senses
|
|
441
|
+
.filter((row) => row.enabled)
|
|
442
|
+
.map((row) => `${row.agent}/${row.sense}:${row.status}`),
|
|
443
|
+
];
|
|
444
|
+
const items = rows.length > 0 ? `\titems=${rows.join(",")}` : "";
|
|
445
|
+
return `daemon=${payload.overview.daemon}\tworkers=${payload.overview.workerCount}\tsenses=${payload.overview.senseCount}\thealth=${payload.overview.health}${items}`;
|
|
446
|
+
}
|
|
74
447
|
return `daemon=${payload.overview.daemon}\tworkers=${payload.overview.workerCount}\tsenses=${payload.overview.senseCount}\thealth=${payload.overview.health}${detail}`;
|
|
75
448
|
}
|
|
76
449
|
function parseIncomingCommand(raw) {
|
|
@@ -90,6 +463,85 @@ function parseIncomingCommand(raw) {
|
|
|
90
463
|
}
|
|
91
464
|
return parsed;
|
|
92
465
|
}
|
|
466
|
+
function isValidSenseReviveCommand(command) {
|
|
467
|
+
return typeof command.agent === "string"
|
|
468
|
+
&& typeof command.sense === "string"
|
|
469
|
+
&& typeof command.reason === "string";
|
|
470
|
+
}
|
|
471
|
+
function isValidTaskPokeCommand(command) {
|
|
472
|
+
return typeof command.agent === "string"
|
|
473
|
+
&& command.agent.trim().length > 0
|
|
474
|
+
&& typeof command.taskId === "string"
|
|
475
|
+
&& command.taskId.trim().length > 0;
|
|
476
|
+
}
|
|
477
|
+
function isValidHabitPokeCommand(command) {
|
|
478
|
+
return typeof command.agent === "string"
|
|
479
|
+
&& command.agent.trim().length > 0
|
|
480
|
+
&& typeof command.habitName === "string"
|
|
481
|
+
&& command.habitName.trim().length > 0;
|
|
482
|
+
}
|
|
483
|
+
function taskIdFromTaskPokePrivateWakeCommand(command) {
|
|
484
|
+
if (command.kind !== "private.wake" || command.triggerSource !== "task-poke")
|
|
485
|
+
return null;
|
|
486
|
+
const taskRef = command.originRefs?.find((ref) => ref.kind === "task" && typeof ref.id === "string");
|
|
487
|
+
if (!taskRef || typeof taskRef.id !== "string")
|
|
488
|
+
return null;
|
|
489
|
+
const trimmed = taskRef.id.trim();
|
|
490
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Handle agent.senseTurn command: runs a full agent turn via the daemon process.
|
|
494
|
+
* Dynamic import lazy-loads shared-turn. Hot-reload works because ouro dev
|
|
495
|
+
* restarts the daemon process (fresh module cache).
|
|
496
|
+
*/
|
|
497
|
+
async function handleAgentSenseTurn(command, runtime) {
|
|
498
|
+
try {
|
|
499
|
+
const { setAgentName } = await Promise.resolve().then(() => __importStar(require("../identity")));
|
|
500
|
+
setAgentName(command.agent);
|
|
501
|
+
const { runSenseTurn } = await Promise.resolve().then(() => __importStar(require("../../senses/shared-turn")));
|
|
502
|
+
const result = await runSenseTurn({
|
|
503
|
+
agentName: command.agent,
|
|
504
|
+
channel: command.channel,
|
|
505
|
+
sessionKey: command.sessionKey,
|
|
506
|
+
friendId: command.friendId,
|
|
507
|
+
userMessage: command.message,
|
|
508
|
+
...(runtime?.socketPath ? { toolContext: { daemonSocketPath: runtime.socketPath } } : {}),
|
|
509
|
+
// Per-turn, per-agent runtime MCP injection (e.g. Workbench's ouro_workbench).
|
|
510
|
+
// Scoped to THIS turn only — never stored as module state, so a concurrent
|
|
511
|
+
// turn for a different agent cannot inherit these servers.
|
|
512
|
+
...(command.runtimeMcp ? { runtimeMcpServers: command.runtimeMcp } : {}),
|
|
513
|
+
});
|
|
514
|
+
return {
|
|
515
|
+
ok: true,
|
|
516
|
+
message: result.response,
|
|
517
|
+
data: { ponderDeferred: result.ponderDeferred },
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
catch (error) {
|
|
521
|
+
/* v8 ignore next -- branch: String(error) fallback only for non-Error throws @preserve */
|
|
522
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
523
|
+
return { ok: false, error: `sense turn failed: ${errorMessage}` };
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
async function handleAgentAskTurn(command, runtime) {
|
|
527
|
+
/* v8 ignore start -- ask command parameter defaults are legacy MCP compatibility; send_message shares the primary path @preserve */
|
|
528
|
+
const question = typeof command.question === "string" ? command.question : "";
|
|
529
|
+
if (!question.trim())
|
|
530
|
+
return { ok: false, error: "Missing required parameter: question" };
|
|
531
|
+
const channel = typeof command.channel === "string" && command.channel.trim() ? command.channel.trim() : "mcp";
|
|
532
|
+
const sessionKey = typeof command.sessionKey === "string" && command.sessionKey.trim()
|
|
533
|
+
? command.sessionKey.trim()
|
|
534
|
+
: `agent-ask:${command.friendId}`;
|
|
535
|
+
/* v8 ignore stop */
|
|
536
|
+
return handleAgentSenseTurn({
|
|
537
|
+
kind: "agent.senseTurn",
|
|
538
|
+
agent: command.agent,
|
|
539
|
+
friendId: command.friendId,
|
|
540
|
+
channel,
|
|
541
|
+
sessionKey,
|
|
542
|
+
message: question,
|
|
543
|
+
}, runtime);
|
|
544
|
+
}
|
|
93
545
|
class OuroDaemon {
|
|
94
546
|
socketPath;
|
|
95
547
|
processManager;
|
|
@@ -98,7 +550,15 @@ class OuroDaemon {
|
|
|
98
550
|
router;
|
|
99
551
|
senseManager;
|
|
100
552
|
bundlesRoot;
|
|
553
|
+
mode;
|
|
101
554
|
server = null;
|
|
555
|
+
mailboxServer = null;
|
|
556
|
+
socketIdentity = null;
|
|
557
|
+
senseAutostartTimer = null;
|
|
558
|
+
mailboxServerFactory;
|
|
559
|
+
privateRuntimePolicyDeps;
|
|
560
|
+
onStopCommandComplete;
|
|
561
|
+
externalEventRoot;
|
|
102
562
|
constructor(options) {
|
|
103
563
|
this.socketPath = options.socketPath;
|
|
104
564
|
this.processManager = options.processManager;
|
|
@@ -107,6 +567,80 @@ class OuroDaemon {
|
|
|
107
567
|
this.router = options.router;
|
|
108
568
|
this.senseManager = options.senseManager ?? null;
|
|
109
569
|
this.bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
|
|
570
|
+
this.mode = options.mode ?? "production";
|
|
571
|
+
this.mailboxServerFactory = options.mailboxServerFactory ?? this.createDefaultMailboxServer.bind(this);
|
|
572
|
+
this.privateRuntimePolicyDeps = options.privateRuntimePolicyDeps ?? {};
|
|
573
|
+
this.onStopCommandComplete = options.onStopCommandComplete ?? null;
|
|
574
|
+
this.externalEventRoot = options.externalEventRoot ?? null;
|
|
575
|
+
}
|
|
576
|
+
/* 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 */
|
|
577
|
+
createDefaultMailboxServer() {
|
|
578
|
+
return (0, mailbox_http_1.startMailboxHttpServer)({
|
|
579
|
+
host: "127.0.0.1",
|
|
580
|
+
port: mailbox_types_1.MAILBOX_DEFAULT_PORT,
|
|
581
|
+
bundlesRoot: this.bundlesRoot,
|
|
582
|
+
readMachineState: () => (0, mailbox_read_1.readMailboxMachineState)({ bundlesRoot: this.bundlesRoot }),
|
|
583
|
+
readMachineView: ({ machine }) => {
|
|
584
|
+
const overview = this.buildStatusPayload().overview;
|
|
585
|
+
return (0, mailbox_view_1.buildMailboxMachineView)({
|
|
586
|
+
machine,
|
|
587
|
+
daemon: {
|
|
588
|
+
status: overview.daemon,
|
|
589
|
+
health: overview.health,
|
|
590
|
+
mode: overview.mode,
|
|
591
|
+
socketPath: overview.socketPath,
|
|
592
|
+
mailboxUrl: overview.mailboxUrl,
|
|
593
|
+
entryPath: overview.entryPath,
|
|
594
|
+
workerCount: overview.workerCount,
|
|
595
|
+
senseCount: overview.senseCount,
|
|
596
|
+
},
|
|
597
|
+
});
|
|
598
|
+
},
|
|
599
|
+
readAgentState: (agentName) => (0, mailbox_read_1.readMailboxAgentState)(agentName, { bundlesRoot: this.bundlesRoot }),
|
|
600
|
+
readAgentView: (agentName) => {
|
|
601
|
+
const agent = (0, mailbox_read_1.readMailboxAgentState)(agentName, { bundlesRoot: this.bundlesRoot });
|
|
602
|
+
return (0, mailbox_view_1.buildMailboxAgentView)({
|
|
603
|
+
agent,
|
|
604
|
+
viewer: { kind: "human" },
|
|
605
|
+
});
|
|
606
|
+
},
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
/* v8 ignore stop */
|
|
610
|
+
buildStatusPayload() {
|
|
611
|
+
const snapshots = this.processManager.listAgentSnapshots();
|
|
612
|
+
const workers = buildWorkerRows(snapshots);
|
|
613
|
+
const senses = this.senseManager?.listSenseRows() ?? [];
|
|
614
|
+
const healthChecks = this.healthMonitor.getLastResults?.() ?? [];
|
|
615
|
+
const repoRoot = (0, identity_1.getRepoRoot)();
|
|
616
|
+
const sync = (0, agent_discovery_1.listBundleSyncRows)({ bundlesRoot: this.bundlesRoot });
|
|
617
|
+
const agents = (0, agent_discovery_1.listAllBundleAgents)({ bundlesRoot: this.bundlesRoot });
|
|
618
|
+
const providerAgents = (0, agent_discovery_1.listEnabledBundleAgents)({ bundlesRoot: this.bundlesRoot });
|
|
619
|
+
const providers = providerAgents.flatMap((agentName) => (0, provider_visibility_1.providerVisibilityStatusRows)((0, provider_visibility_1.buildAgentProviderVisibility)({
|
|
620
|
+
agentName,
|
|
621
|
+
agentRoot: path.join(this.bundlesRoot, `${agentName}.ouro`),
|
|
622
|
+
})));
|
|
623
|
+
const mailboxUrl = this.mailboxServer?.origin ?? "http://127.0.0.1:0";
|
|
624
|
+
return {
|
|
625
|
+
overview: {
|
|
626
|
+
daemon: "running",
|
|
627
|
+
health: overviewHealth(workers, senses, healthChecks),
|
|
628
|
+
socketPath: this.socketPath,
|
|
629
|
+
mailboxUrl,
|
|
630
|
+
outlookUrl: mailboxUrl,
|
|
631
|
+
...(0, runtime_metadata_1.getRuntimeMetadata)(),
|
|
632
|
+
workerCount: workers.length,
|
|
633
|
+
senseCount: senses.length,
|
|
634
|
+
entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
|
|
635
|
+
mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
|
|
636
|
+
},
|
|
637
|
+
workers,
|
|
638
|
+
senses,
|
|
639
|
+
...(healthChecks.length > 0 ? { healthChecks } : {}),
|
|
640
|
+
sync,
|
|
641
|
+
agents,
|
|
642
|
+
...(providers.length > 0 ? { providers } : {}),
|
|
643
|
+
};
|
|
110
644
|
}
|
|
111
645
|
async start() {
|
|
112
646
|
if (this.server)
|
|
@@ -117,65 +651,182 @@ class OuroDaemon {
|
|
|
117
651
|
message: "starting daemon server",
|
|
118
652
|
meta: { socketPath: this.socketPath },
|
|
119
653
|
});
|
|
654
|
+
try {
|
|
655
|
+
await this.startInner();
|
|
656
|
+
}
|
|
657
|
+
catch (err) {
|
|
658
|
+
// Emit a paired terminating event (`_error`) so the nerves audit's
|
|
659
|
+
// start_end_pairing rule is satisfied when startup throws mid-sequence
|
|
660
|
+
// and `stop()` (which emits `server_end`) is never called.
|
|
661
|
+
(0, runtime_1.emitNervesEvent)({
|
|
662
|
+
level: "error",
|
|
663
|
+
component: "daemon",
|
|
664
|
+
event: "daemon.server_error",
|
|
665
|
+
message: "daemon start failed",
|
|
666
|
+
meta: {
|
|
667
|
+
error: err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err),
|
|
668
|
+
},
|
|
669
|
+
});
|
|
670
|
+
throw err;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
async startInner() {
|
|
120
674
|
// Register update hooks and apply pending updates before starting agents
|
|
121
675
|
(0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
|
|
676
|
+
(0, update_hooks_1.registerUpdateHook)(agent_config_v2_1.agentConfigV2Hook);
|
|
122
677
|
const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
|
|
123
678
|
await (0, update_hooks_1.applyPendingUpdates)(this.bundlesRoot, currentVersion);
|
|
124
679
|
// Start periodic update checker (polls npm registry every 30 minutes)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
const resolved = (0, child_process_1.execSync)(`node -e "console.log(require.resolve('@ouro.bot/cli/package.json'))"`, { encoding: "utf-8" }).trim();
|
|
145
|
-
return resolved ? path.dirname(resolved) : null;
|
|
146
|
-
}
|
|
147
|
-
catch {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
680
|
+
// Skip in dev mode — dev builds should not auto-update from npm
|
|
681
|
+
if (this.mode === "dev") {
|
|
682
|
+
(0, runtime_1.emitNervesEvent)({
|
|
683
|
+
component: "daemon",
|
|
684
|
+
event: "daemon.update_checker_skip",
|
|
685
|
+
message: "skipping update checker in dev mode",
|
|
686
|
+
meta: { reason: "dev mode" },
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
(0, update_checker_1.startUpdateChecker)({
|
|
691
|
+
currentVersion,
|
|
692
|
+
deps: {
|
|
693
|
+
distTag: update_checker_1.CLI_UPDATE_DIST_TAG,
|
|
694
|
+
/* v8 ignore start -- integration: real HTTP fetch @preserve */
|
|
695
|
+
fetchRegistryJson: async () => {
|
|
696
|
+
const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
|
|
697
|
+
return res.json();
|
|
150
698
|
},
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
await this.
|
|
162
|
-
|
|
699
|
+
/* v8 ignore stop */
|
|
700
|
+
},
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
// MCP connections are lazily initialized per-agent during senseTurn
|
|
704
|
+
// (daemon manages multiple agents; agent identity must be set before loading MCP config)
|
|
705
|
+
/* v8 ignore start -- orphan cleanup + pidfile: calls process management functions @preserve */
|
|
706
|
+
const killedOrphanPids = killOrphanProcesses(this.socketPath);
|
|
707
|
+
await waitForOrphanProcessesToSettle(killedOrphanPids);
|
|
708
|
+
/* v8 ignore stop */
|
|
709
|
+
await this.openCommandSocket();
|
|
710
|
+
this.triggerAutoStartAgents();
|
|
711
|
+
this.triggerAutoStartSensesWhenAgentsSettled();
|
|
712
|
+
// Write all managed PIDs to disk so the next daemon can clean up
|
|
713
|
+
/* v8 ignore start -- pidfile write: collects PIDs from process managers @preserve */
|
|
714
|
+
const agentPids = this.processManager.listAgentSnapshots().map((s) => s.pid).filter((p) => p !== null);
|
|
715
|
+
const sensePids = this.senseManager?.listManagedPids?.() ?? [];
|
|
716
|
+
writePidfile([...agentPids, ...sensePids], this.socketPath);
|
|
717
|
+
/* v8 ignore stop */
|
|
163
718
|
this.scheduler.start?.();
|
|
164
719
|
await this.scheduler.reconcile?.();
|
|
165
720
|
await this.drainPendingBundleMessages();
|
|
166
721
|
await this.drainPendingSenseMessages();
|
|
722
|
+
// startInner is only reachable when this.server is null (guarded in
|
|
723
|
+
// start()), and stop() nulls out this.mailboxServer alongside this.server,
|
|
724
|
+
// so mailboxServer is guaranteed unset here — no need for a guard.
|
|
725
|
+
try {
|
|
726
|
+
this.mailboxServer = await this.mailboxServerFactory();
|
|
727
|
+
}
|
|
728
|
+
catch (error) {
|
|
729
|
+
(0, runtime_1.emitNervesEvent)({
|
|
730
|
+
level: "warn",
|
|
731
|
+
component: "daemon",
|
|
732
|
+
event: "daemon.mailbox_start_failed",
|
|
733
|
+
message: `Mailbox server failed to start: ${String(error)}`,
|
|
734
|
+
meta: { port: mailbox_types_1.MAILBOX_DEFAULT_PORT },
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
triggerAutoStartAgents() {
|
|
739
|
+
if (this.processManager.triggerAutoStartAgents) {
|
|
740
|
+
this.processManager.triggerAutoStartAgents();
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
void this.processManager.startAutoStartAgents().catch((error) => {
|
|
744
|
+
(0, runtime_1.emitNervesEvent)({
|
|
745
|
+
level: "error",
|
|
746
|
+
component: "daemon",
|
|
747
|
+
event: "daemon.agent_autostart_error",
|
|
748
|
+
message: "agent autostart failed after daemon socket opened",
|
|
749
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
triggerAutoStartSenses() {
|
|
754
|
+
/* v8 ignore next -- defensive: callers already check senseManager before delegating here @preserve */
|
|
755
|
+
if (!this.senseManager)
|
|
756
|
+
return;
|
|
757
|
+
if (this.senseManager.triggerAutoStartSenses) {
|
|
758
|
+
this.senseManager.triggerAutoStartSenses();
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
void this.senseManager.startAutoStartSenses().catch((error) => {
|
|
762
|
+
(0, runtime_1.emitNervesEvent)({
|
|
763
|
+
level: "error",
|
|
764
|
+
component: "daemon",
|
|
765
|
+
event: "daemon.sense_autostart_error",
|
|
766
|
+
message: "sense autostart failed after daemon socket opened",
|
|
767
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
768
|
+
});
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
triggerAutoStartSensesWhenAgentsSettled() {
|
|
772
|
+
if (!this.senseManager)
|
|
773
|
+
return;
|
|
774
|
+
const waitingOnAgents = this.processManager.listAgentSnapshots()
|
|
775
|
+
.some((snapshot) => snapshot.status === "starting");
|
|
776
|
+
if (!waitingOnAgents) {
|
|
777
|
+
this.triggerAutoStartSenses();
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
this.senseAutostartTimer = setTimeout(() => {
|
|
781
|
+
this.senseAutostartTimer = null;
|
|
782
|
+
this.triggerAutoStartSensesWhenAgentsSettled();
|
|
783
|
+
}, 250);
|
|
784
|
+
}
|
|
785
|
+
async openCommandSocket() {
|
|
167
786
|
if (fs.existsSync(this.socketPath)) {
|
|
168
787
|
fs.unlinkSync(this.socketPath);
|
|
169
788
|
}
|
|
170
|
-
|
|
789
|
+
// allowHalfOpen: true lets the server keep its writable side open after
|
|
790
|
+
// the client sends FIN. Without this, when a client calls `client.end()`
|
|
791
|
+
// after writing a command, node closes the server's writable side
|
|
792
|
+
// automatically — so a long-running response (like an agent.senseTurn
|
|
793
|
+
// LLM turn that takes 5+ seconds) never reaches the client. The
|
|
794
|
+
// socket-client fix in #303/#334 also removed client.end() on the
|
|
795
|
+
// sending side, but this option is defense in depth: even if a future
|
|
796
|
+
// caller half-closes, the server still writes its response correctly.
|
|
797
|
+
this.server = net.createServer({ allowHalfOpen: true }, (connection) => {
|
|
171
798
|
let raw = "";
|
|
172
799
|
let responded = false;
|
|
800
|
+
/* v8 ignore start — connection error handler requires real socket error @preserve */
|
|
801
|
+
connection.on("error", (err) => {
|
|
802
|
+
(0, runtime_1.emitNervesEvent)({
|
|
803
|
+
level: "warn",
|
|
804
|
+
component: "daemon",
|
|
805
|
+
event: "daemon.connection_error",
|
|
806
|
+
message: "socket connection error",
|
|
807
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
808
|
+
});
|
|
809
|
+
});
|
|
810
|
+
/* v8 ignore stop */
|
|
173
811
|
const flushResponse = async () => {
|
|
174
812
|
if (responded)
|
|
175
813
|
return;
|
|
176
814
|
responded = true;
|
|
177
815
|
const response = await this.handleRawPayload(raw);
|
|
178
|
-
|
|
816
|
+
try {
|
|
817
|
+
connection.end(response);
|
|
818
|
+
/* v8 ignore start — EPIPE catch requires real socket disconnect @preserve */
|
|
819
|
+
}
|
|
820
|
+
catch (err) {
|
|
821
|
+
(0, runtime_1.emitNervesEvent)({
|
|
822
|
+
level: "warn",
|
|
823
|
+
component: "daemon",
|
|
824
|
+
event: "daemon.connection_end_error",
|
|
825
|
+
message: "failed to send response to client (EPIPE)",
|
|
826
|
+
meta: { error: err instanceof Error ? err.message : String(err) },
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
/* v8 ignore stop */
|
|
179
830
|
};
|
|
180
831
|
connection.on("data", (chunk) => {
|
|
181
832
|
raw += chunk.toString("utf-8");
|
|
@@ -188,7 +839,23 @@ class OuroDaemon {
|
|
|
188
839
|
const server = this.server;
|
|
189
840
|
await new Promise((resolve, reject) => {
|
|
190
841
|
server.once("error", reject);
|
|
191
|
-
server.listen(this.socketPath, () =>
|
|
842
|
+
server.listen(this.socketPath, () => {
|
|
843
|
+
// Replace the one-time error listener with a persistent one after successful listen
|
|
844
|
+
server.removeAllListeners("error");
|
|
845
|
+
this.socketIdentity = readSocketIdentity(this.socketPath);
|
|
846
|
+
/* v8 ignore start — server error after listen requires real socket race condition @preserve */
|
|
847
|
+
server.on("error", (err) => {
|
|
848
|
+
(0, runtime_1.emitNervesEvent)({
|
|
849
|
+
level: "error",
|
|
850
|
+
component: "daemon",
|
|
851
|
+
event: "daemon.server_error",
|
|
852
|
+
message: "daemon server error after listen",
|
|
853
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
854
|
+
});
|
|
855
|
+
});
|
|
856
|
+
/* v8 ignore stop */
|
|
857
|
+
resolve();
|
|
858
|
+
});
|
|
192
859
|
});
|
|
193
860
|
}
|
|
194
861
|
async drainPendingBundleMessages() {
|
|
@@ -240,7 +907,7 @@ class OuroDaemon {
|
|
|
240
907
|
}
|
|
241
908
|
}
|
|
242
909
|
/** Drains per-sense pending dirs for always-on senses across all agents. */
|
|
243
|
-
static ALWAYS_ON_SENSES = new Set((0,
|
|
910
|
+
static ALWAYS_ON_SENSES = new Set((0, friends_1.getAlwaysOnSenseNames)());
|
|
244
911
|
async drainPendingSenseMessages() {
|
|
245
912
|
if (!fs.existsSync(this.bundlesRoot))
|
|
246
913
|
return;
|
|
@@ -327,26 +994,87 @@ class OuroDaemon {
|
|
|
327
994
|
}
|
|
328
995
|
}
|
|
329
996
|
async stop() {
|
|
997
|
+
// Must be named `_end` (not `_stop`) to satisfy the nerves audit's
|
|
998
|
+
// start/end pairing rule — see src/nerves/coverage/audit-rules.ts.
|
|
999
|
+
// This is the counterpart to `daemon.server_start` emitted at line 480.
|
|
330
1000
|
(0, runtime_1.emitNervesEvent)({
|
|
331
1001
|
component: "daemon",
|
|
332
|
-
event: "daemon.
|
|
1002
|
+
event: "daemon.server_end",
|
|
333
1003
|
message: "stopping daemon server",
|
|
334
1004
|
meta: { socketPath: this.socketPath },
|
|
335
1005
|
});
|
|
336
1006
|
(0, update_checker_1.stopUpdateChecker)();
|
|
337
1007
|
(0, mcp_manager_1.shutdownSharedMcpManager)();
|
|
338
1008
|
this.scheduler.stop?.();
|
|
1009
|
+
this.healthMonitor.stopPeriodicChecks?.();
|
|
1010
|
+
if (this.senseAutostartTimer) {
|
|
1011
|
+
clearTimeout(this.senseAutostartTimer);
|
|
1012
|
+
this.senseAutostartTimer = null;
|
|
1013
|
+
}
|
|
339
1014
|
await this.processManager.stopAll();
|
|
340
1015
|
await this.senseManager?.stopAll();
|
|
341
1016
|
if (this.server) {
|
|
342
|
-
await
|
|
343
|
-
|
|
344
|
-
|
|
1017
|
+
// DO NOT `await` server.close() here. server.close() resolves only
|
|
1018
|
+
// after every open connection has closed. When stop() is invoked
|
|
1019
|
+
// from the daemon.stop command handler, the calling client's
|
|
1020
|
+
// connection is STILL open — its flushResponse() is currently
|
|
1021
|
+
// awaiting THIS function. Awaiting close() creates a deadlock:
|
|
1022
|
+
//
|
|
1023
|
+
// client → flushResponse → handleRawPayload → daemon.stop case
|
|
1024
|
+
// → stop() → await server.close() (waits for client's connection)
|
|
1025
|
+
// → client's connection waits for flushResponse to call
|
|
1026
|
+
// connection.end() → DEADLOCK
|
|
1027
|
+
//
|
|
1028
|
+
// Both processes sit in kevent forever. Verified live on
|
|
1029
|
+
// 2026-04-08: alpha.268 daemon hung at `daemon.server_end` log
|
|
1030
|
+
// line for 5+ minutes after a client sent daemon.stop, while the
|
|
1031
|
+
// client (alpha.270 ouro up) hung waiting for the response.
|
|
1032
|
+
//
|
|
1033
|
+
// This regressed when #303/#334/#339 stopped half-closing the
|
|
1034
|
+
// client socket and switched the server to allowHalfOpen: true.
|
|
1035
|
+
// Previously, the client called .end() after writing its command,
|
|
1036
|
+
// which (with allowHalfOpen: false) caused node to auto-tear-down
|
|
1037
|
+
// the server's writable side — incidentally unblocking
|
|
1038
|
+
// server.close() before the response was sent. The half-close
|
|
1039
|
+
// breakage masked this deadlock; the fix exposed it.
|
|
1040
|
+
//
|
|
1041
|
+
// Solution: fire close() and let it complete asynchronously. Once
|
|
1042
|
+
// stop() returns, the daemon.stop case returns its response,
|
|
1043
|
+
// flushResponse() calls connection.end(response), the connection
|
|
1044
|
+
// closes, and server.close()'s pending callback fires. The event
|
|
1045
|
+
// loop drains and the daemon exits cleanly.
|
|
1046
|
+
this.server.close();
|
|
345
1047
|
this.server = null;
|
|
346
1048
|
}
|
|
347
|
-
if (
|
|
1049
|
+
if (this.mailboxServer) {
|
|
1050
|
+
await this.mailboxServer.stop();
|
|
1051
|
+
this.mailboxServer = null;
|
|
1052
|
+
}
|
|
1053
|
+
const socketPathExists = fs.existsSync(this.socketPath);
|
|
1054
|
+
const currentSocketIdentity = socketPathExists ? readSocketIdentity(this.socketPath) : null;
|
|
1055
|
+
if (sameSocketIdentity(this.socketIdentity, currentSocketIdentity)) {
|
|
348
1056
|
fs.unlinkSync(this.socketPath);
|
|
349
1057
|
}
|
|
1058
|
+
else if (socketPathExists) {
|
|
1059
|
+
const expectedSocketIdentity = { dev: null, ino: null, ctimeMs: null, ...this.socketIdentity };
|
|
1060
|
+
const actualSocketIdentity = { dev: null, ino: null, ctimeMs: null, ...currentSocketIdentity };
|
|
1061
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1062
|
+
level: "warn",
|
|
1063
|
+
component: "daemon",
|
|
1064
|
+
event: "daemon.socket_cleanup_skipped",
|
|
1065
|
+
message: "skipped daemon socket cleanup because the socket path no longer belongs to this daemon",
|
|
1066
|
+
meta: {
|
|
1067
|
+
socketPath: this.socketPath,
|
|
1068
|
+
expectedDev: expectedSocketIdentity.dev,
|
|
1069
|
+
expectedIno: expectedSocketIdentity.ino,
|
|
1070
|
+
expectedCtimeMs: expectedSocketIdentity.ctimeMs,
|
|
1071
|
+
actualDev: actualSocketIdentity.dev,
|
|
1072
|
+
actualIno: actualSocketIdentity.ino,
|
|
1073
|
+
actualCtimeMs: actualSocketIdentity.ctimeMs,
|
|
1074
|
+
},
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
this.socketIdentity = null;
|
|
350
1078
|
}
|
|
351
1079
|
async handleRawPayload(raw) {
|
|
352
1080
|
try {
|
|
@@ -368,32 +1096,223 @@ class OuroDaemon {
|
|
|
368
1096
|
message: "handling daemon command",
|
|
369
1097
|
meta: { kind: command.kind },
|
|
370
1098
|
});
|
|
1099
|
+
try {
|
|
1100
|
+
return await this.handleCommandInner(command);
|
|
1101
|
+
/* v8 ignore start — command error catch tested in daemon-command-error.test; instanceof branches defensive @preserve */
|
|
1102
|
+
}
|
|
1103
|
+
catch (error) {
|
|
1104
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1105
|
+
level: "error",
|
|
1106
|
+
component: "daemon",
|
|
1107
|
+
event: "daemon.command_error",
|
|
1108
|
+
message: "unexpected error handling daemon command",
|
|
1109
|
+
meta: {
|
|
1110
|
+
kind: command.kind,
|
|
1111
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1112
|
+
stack: error instanceof Error ? error.stack ?? null : null,
|
|
1113
|
+
},
|
|
1114
|
+
});
|
|
1115
|
+
throw error;
|
|
1116
|
+
}
|
|
1117
|
+
/* v8 ignore stop */
|
|
1118
|
+
}
|
|
1119
|
+
hasManagedPrivateRuntime(agent) {
|
|
1120
|
+
return this.processManager.listAgentSnapshots().some((snapshot) => snapshot.name === agent && snapshot.channel === "private-runtime");
|
|
1121
|
+
}
|
|
1122
|
+
buildPrivateRuntimeWakeRequest(command) {
|
|
1123
|
+
if (command.kind === "inner.wake") {
|
|
1124
|
+
return {
|
|
1125
|
+
agent: command.agent,
|
|
1126
|
+
origin: "daemon.private.wake",
|
|
1127
|
+
reason: "legacy inner.wake compatibility alias",
|
|
1128
|
+
providerLane: "inner",
|
|
1129
|
+
triggerSource: "legacy",
|
|
1130
|
+
budgetClass: "interactive",
|
|
1131
|
+
originRefs: [{ kind: "daemon-command", id: "inner.wake" }],
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
return {
|
|
1135
|
+
agent: command.agent,
|
|
1136
|
+
origin: "daemon.private.wake",
|
|
1137
|
+
reason: command.reason ?? "manual private-runtime wake",
|
|
1138
|
+
providerLane: "inner",
|
|
1139
|
+
triggerSource: command.triggerSource ?? "manual",
|
|
1140
|
+
budgetClass: command.budgetClass ?? "interactive",
|
|
1141
|
+
...(command.idempotencyKey ? { idempotencyKey: command.idempotencyKey } : {}),
|
|
1142
|
+
originRefs: command.originRefs ?? [{ kind: "daemon-command", id: "private.wake" }],
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
buildAwaitPrivateWakeCommand(command) {
|
|
1146
|
+
return (0, await_private_wake_1.buildAwaitPrivateWakeCommand)({
|
|
1147
|
+
agent: command.agent,
|
|
1148
|
+
awaitName: command.awaitName,
|
|
1149
|
+
triggerSource: "await-poke",
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
buildTaskPokePrivateWakeCommand(command, receiptId) {
|
|
1153
|
+
return {
|
|
1154
|
+
kind: "private.wake",
|
|
1155
|
+
agent: command.agent,
|
|
1156
|
+
reason: `task poke ${command.taskId}`,
|
|
1157
|
+
triggerSource: "task-poke",
|
|
1158
|
+
budgetClass: "scheduled",
|
|
1159
|
+
idempotencyKey: `task-poke:${command.agent}:${command.taskId}:${receiptId}`,
|
|
1160
|
+
originRefs: [
|
|
1161
|
+
{ kind: "task", id: command.taskId },
|
|
1162
|
+
{ kind: "queue-receipt", id: receiptId },
|
|
1163
|
+
{ kind: "daemon-command", id: "task.poke" },
|
|
1164
|
+
],
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
buildExternalEventPrivateWakeCommand(command, receiptId) {
|
|
1168
|
+
return {
|
|
1169
|
+
kind: "private.wake",
|
|
1170
|
+
agent: command.agent,
|
|
1171
|
+
reason: `external event ${command.source}/${command.eventType}`,
|
|
1172
|
+
triggerSource: "external-event",
|
|
1173
|
+
budgetClass: "interactive",
|
|
1174
|
+
idempotencyKey: `external-event:${command.agent}:${command.source}:${command.eventId}`,
|
|
1175
|
+
originRefs: [
|
|
1176
|
+
{ kind: "external-event", id: command.eventId, source: command.source, eventType: command.eventType },
|
|
1177
|
+
{ kind: "queue-receipt", id: receiptId },
|
|
1178
|
+
{ kind: "daemon-command", id: "external.event.submit" },
|
|
1179
|
+
],
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
resolveHabitPokeOccurrenceId(command, trigger) {
|
|
1183
|
+
if (trigger === "poke" || trigger === "manual")
|
|
1184
|
+
return undefined;
|
|
1185
|
+
const agentRoot = path.join(this.bundlesRoot, `${command.agent}.ouro`);
|
|
1186
|
+
const habitPath = path.join(agentRoot, "habits", `${command.habitName}.md`);
|
|
1187
|
+
if (!fs.existsSync(habitPath))
|
|
1188
|
+
return { skipReason: "habit file not found" };
|
|
1189
|
+
const habit = (0, habit_runtime_state_1.applyHabitRuntimeState)(agentRoot, (0, habit_parser_1.parseHabitFile)(fs.readFileSync(habitPath, "utf-8"), habitPath));
|
|
1190
|
+
if (habit.cadence === null)
|
|
1191
|
+
return { skipReason: "habit has no cadence" };
|
|
1192
|
+
const cadence = habit.cadence;
|
|
1193
|
+
if (habit.lastRun === null)
|
|
1194
|
+
return `${trigger}:first-run:${cadence}`;
|
|
1195
|
+
return `${trigger}:last-run:${habit.lastRun}:cadence:${cadence}`;
|
|
1196
|
+
}
|
|
1197
|
+
buildPrivateRuntimeWorkerWakeMessage(command, decision) {
|
|
1198
|
+
const awaitName = (0, await_private_wake_1.awaitNameFromPrivateWakeCommand)(command);
|
|
1199
|
+
if (awaitName) {
|
|
1200
|
+
return {
|
|
1201
|
+
type: "await",
|
|
1202
|
+
awaitName,
|
|
1203
|
+
privateTurnDecision: decision,
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
const taskId = taskIdFromTaskPokePrivateWakeCommand(command);
|
|
1207
|
+
if (taskId) {
|
|
1208
|
+
return {
|
|
1209
|
+
type: "poke",
|
|
1210
|
+
taskId,
|
|
1211
|
+
privateTurnDecision: decision,
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
const habitMessage = (0, habit_private_wake_1.habitMessageFromPrivateWakeCommand)(command);
|
|
1215
|
+
if (habitMessage) {
|
|
1216
|
+
return {
|
|
1217
|
+
type: "habit",
|
|
1218
|
+
habitName: habitMessage.habitName,
|
|
1219
|
+
trigger: habitMessage.trigger,
|
|
1220
|
+
privateTurnDecision: decision,
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
return { type: "message", privateTurnDecision: decision };
|
|
1224
|
+
}
|
|
1225
|
+
queueExternalEventForPrivateRuntime(record) {
|
|
1226
|
+
const pendingDir = path.join(this.bundlesRoot, `${record.agent}.ouro`, "state", "pending", pending_1.PRIVATE_RUNTIME_PENDING.friendId, pending_1.PRIVATE_RUNTIME_PENDING.channel, pending_1.PRIVATE_RUNTIME_PENDING.key);
|
|
1227
|
+
const originKey = `${record.source}:${record.eventId}`;
|
|
1228
|
+
const parsedReceivedAt = Date.parse(record.receivedAt);
|
|
1229
|
+
(0, pending_1.queuePendingMessage)(pendingDir, {
|
|
1230
|
+
from: "ouro-external-event",
|
|
1231
|
+
friendId: "ouro-external-event",
|
|
1232
|
+
channel: "external-event",
|
|
1233
|
+
key: originKey,
|
|
1234
|
+
content: (0, router_1.buildExternalEventMessage)(record),
|
|
1235
|
+
timestamp: Number.isFinite(parsedReceivedAt) ? parsedReceivedAt : Date.now(),
|
|
1236
|
+
delegatedFrom: {
|
|
1237
|
+
friendId: "ouro-external-event",
|
|
1238
|
+
channel: "external-event",
|
|
1239
|
+
key: originKey,
|
|
1240
|
+
},
|
|
1241
|
+
obligationStatus: "pending",
|
|
1242
|
+
mode: "relay",
|
|
1243
|
+
});
|
|
1244
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1245
|
+
component: "daemon",
|
|
1246
|
+
event: "daemon.external_event_private_runtime_queued",
|
|
1247
|
+
message: "queued external event for private-runtime attention",
|
|
1248
|
+
meta: {
|
|
1249
|
+
agent: record.agent,
|
|
1250
|
+
source: record.source,
|
|
1251
|
+
eventType: record.eventType,
|
|
1252
|
+
eventId: record.eventId,
|
|
1253
|
+
pendingDir,
|
|
1254
|
+
},
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
async handlePrivateRuntimeWake(command, beforeDispatch) {
|
|
1258
|
+
if (!this.hasManagedPrivateRuntime(command.agent)) {
|
|
1259
|
+
return {
|
|
1260
|
+
ok: false,
|
|
1261
|
+
error: `No managed agent '${command.agent}' is registered with daemon-managed private runtime.`,
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
const decision = await (0, private_runtime_1.requestPrivateTurnDecision)(this.buildPrivateRuntimeWakeRequest(command), {
|
|
1265
|
+
bundlesRoot: this.bundlesRoot,
|
|
1266
|
+
...this.privateRuntimePolicyDeps,
|
|
1267
|
+
});
|
|
1268
|
+
if (!decision.executable) {
|
|
1269
|
+
return {
|
|
1270
|
+
ok: true,
|
|
1271
|
+
message: `private-runtime wake denied for ${command.agent}: ${decision.deniedReason}`,
|
|
1272
|
+
data: { decision },
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
await beforeDispatch?.(decision);
|
|
1276
|
+
await this.processManager.startAgent(command.agent);
|
|
1277
|
+
this.processManager.sendToAgent?.(command.agent, this.buildPrivateRuntimeWorkerWakeMessage(command, decision));
|
|
1278
|
+
return {
|
|
1279
|
+
ok: true,
|
|
1280
|
+
message: `woke private runtime for ${command.agent}`,
|
|
1281
|
+
data: { decision },
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
async handleCommandInner(command) {
|
|
371
1285
|
switch (command.kind) {
|
|
372
1286
|
case "daemon.start":
|
|
373
1287
|
await this.start();
|
|
374
1288
|
return { ok: true, message: "daemon started" };
|
|
375
1289
|
case "daemon.stop":
|
|
376
1290
|
await this.stop();
|
|
1291
|
+
this.onStopCommandComplete?.();
|
|
377
1292
|
return { ok: true, message: "daemon stopped" };
|
|
378
|
-
case "daemon.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
senseCount: senses.length,
|
|
391
|
-
entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
|
|
392
|
-
mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
|
|
1293
|
+
case "daemon.restart": {
|
|
1294
|
+
// Restart is "stop + let launchctl respawn." Under launchctl's KeepAlive
|
|
1295
|
+
// policy the process is auto-restarted on exit, so daemon.restart and
|
|
1296
|
+
// daemon.stop differ only in intent + audit trail. In dev (no launchctl),
|
|
1297
|
+
// the process simply exits — same observable behavior as daemon.stop.
|
|
1298
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1299
|
+
component: "daemon",
|
|
1300
|
+
event: "daemon.restart_requested",
|
|
1301
|
+
message: "daemon restart requested",
|
|
1302
|
+
meta: {
|
|
1303
|
+
reason: command.reason ?? null,
|
|
1304
|
+
requestedBy: command.requestedBy ?? null,
|
|
393
1305
|
},
|
|
394
|
-
|
|
395
|
-
|
|
1306
|
+
});
|
|
1307
|
+
await this.stop();
|
|
1308
|
+
this.onStopCommandComplete?.();
|
|
1309
|
+
return {
|
|
1310
|
+
ok: true,
|
|
1311
|
+
message: "daemon restarting — launchctl will respawn",
|
|
396
1312
|
};
|
|
1313
|
+
}
|
|
1314
|
+
case "daemon.status": {
|
|
1315
|
+
const data = this.buildStatusPayload();
|
|
397
1316
|
return {
|
|
398
1317
|
ok: true,
|
|
399
1318
|
summary: formatStatusSummary(data),
|
|
@@ -412,15 +1331,112 @@ class OuroDaemon {
|
|
|
412
1331
|
message: "log streaming available via ouro logs",
|
|
413
1332
|
data: { logDir: "~/AgentBundles/<agent>.ouro/state/daemon/logs" },
|
|
414
1333
|
};
|
|
1334
|
+
case "daemon.sense_revive": {
|
|
1335
|
+
if (!isValidSenseReviveCommand(command)) {
|
|
1336
|
+
return {
|
|
1337
|
+
ok: false,
|
|
1338
|
+
error: "Invalid daemon.sense_revive payload: expected string fields 'agent', 'sense', and 'reason'.",
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
const revivedSenseRow = await this.senseManager?.reviveSense?.(command.agent, command.sense);
|
|
1342
|
+
if (revivedSenseRow) {
|
|
1343
|
+
return {
|
|
1344
|
+
ok: true,
|
|
1345
|
+
message: `revived ${command.agent}/${command.sense}`,
|
|
1346
|
+
data: revivedSenseRow,
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
const managedSenseSnapshots = this.processManager.listAgentSnapshots()
|
|
1350
|
+
.filter((snapshot) => snapshot.name.startsWith(`${command.agent}:`));
|
|
1351
|
+
if (managedSenseSnapshots.length === 0) {
|
|
1352
|
+
return {
|
|
1353
|
+
ok: false,
|
|
1354
|
+
error: `No managed agent '${command.agent}' is registered with daemon-managed senses.`,
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
const exactTargetName = `${command.agent}:${command.sense}`;
|
|
1358
|
+
const target = managedSenseSnapshots.find((snapshot) => snapshot.name === exactTargetName)
|
|
1359
|
+
?? managedSenseSnapshots.find((snapshot) => snapshot.channel === command.sense);
|
|
1360
|
+
if (!target) {
|
|
1361
|
+
return {
|
|
1362
|
+
ok: false,
|
|
1363
|
+
error: `No managed sense '${command.sense}' is registered for agent '${command.agent}'.`,
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
this.processManager.resetAgentFailureState(target.name);
|
|
1367
|
+
await this.processManager.startAgent(target.name);
|
|
1368
|
+
const freshSnapshot = this.processManager.listAgentSnapshots()
|
|
1369
|
+
.find((snapshot) => snapshot.name === target.name) ?? target;
|
|
1370
|
+
return {
|
|
1371
|
+
ok: true,
|
|
1372
|
+
message: `revived ${command.agent}/${command.sense}`,
|
|
1373
|
+
data: freshSnapshot,
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
415
1376
|
case "agent.start":
|
|
416
1377
|
await this.processManager.startAgent(command.agent);
|
|
417
1378
|
return { ok: true, message: `started ${command.agent}` };
|
|
418
1379
|
case "agent.stop":
|
|
419
1380
|
await this.processManager.stopAgent?.(command.agent);
|
|
420
1381
|
return { ok: true, message: `stopped ${command.agent}` };
|
|
421
|
-
case "agent.restart":
|
|
422
|
-
|
|
423
|
-
|
|
1382
|
+
case "agent.restart": {
|
|
1383
|
+
if (!this.processManager.restartAgent) {
|
|
1384
|
+
return { ok: false, error: "Managed agent restart is not available." };
|
|
1385
|
+
}
|
|
1386
|
+
const managedSnapshot = this.processManager.listAgentSnapshots()
|
|
1387
|
+
.find((snapshot) => snapshot.name === command.agent);
|
|
1388
|
+
if (!managedSnapshot) {
|
|
1389
|
+
return { ok: false, error: `Unknown managed agent '${command.agent}'.` };
|
|
1390
|
+
}
|
|
1391
|
+
if (managedSnapshot.autoStart === false && managedSnapshot.status === "stopped") {
|
|
1392
|
+
return { ok: true, message: `restart skipped for parked non-autostart agent '${command.agent}'` };
|
|
1393
|
+
}
|
|
1394
|
+
const restartWork = command.skipConfigCheck === true
|
|
1395
|
+
? this.processManager.restartAgent(command.agent, { skipConfigCheck: true })
|
|
1396
|
+
: this.processManager.restartAgent(command.agent);
|
|
1397
|
+
void restartWork.catch((error) => {
|
|
1398
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1399
|
+
level: "error",
|
|
1400
|
+
component: "daemon",
|
|
1401
|
+
event: "daemon.agent_restart_request_error",
|
|
1402
|
+
message: "managed agent restart failed after request acknowledgement",
|
|
1403
|
+
meta: {
|
|
1404
|
+
agent: command.agent,
|
|
1405
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1406
|
+
},
|
|
1407
|
+
});
|
|
1408
|
+
});
|
|
1409
|
+
return { ok: true, message: `restart requested for ${command.agent}` };
|
|
1410
|
+
}
|
|
1411
|
+
case "agent.ask":
|
|
1412
|
+
return handleAgentAskTurn(command, { socketPath: this.socketPath });
|
|
1413
|
+
case "agent.status":
|
|
1414
|
+
return (0, agent_service_1.handleAgentStatus)(command);
|
|
1415
|
+
case "agent.catchup":
|
|
1416
|
+
return (0, agent_service_1.handleAgentCatchup)(command);
|
|
1417
|
+
case "agent.delegate":
|
|
1418
|
+
return (0, agent_service_1.handleAgentDelegate)(command);
|
|
1419
|
+
case "agent.getContext":
|
|
1420
|
+
return (0, agent_service_1.handleAgentGetContext)(command);
|
|
1421
|
+
case "agent.searchFacts":
|
|
1422
|
+
return (0, agent_service_1.handleAgentSearchFacts)(command);
|
|
1423
|
+
case "agent.getTask":
|
|
1424
|
+
return (0, agent_service_1.handleAgentGetTask)(command);
|
|
1425
|
+
case "agent.checkScope":
|
|
1426
|
+
return (0, agent_service_1.handleAgentCheckScope)(command);
|
|
1427
|
+
case "agent.requestDecision":
|
|
1428
|
+
return (0, agent_service_1.handleAgentRequestDecision)(command);
|
|
1429
|
+
case "agent.checkGuidance":
|
|
1430
|
+
return (0, agent_service_1.handleAgentCheckGuidance)(command);
|
|
1431
|
+
case "agent.reportProgress":
|
|
1432
|
+
return (0, agent_service_1.handleAgentReportProgress)(command);
|
|
1433
|
+
case "agent.reportBlocker":
|
|
1434
|
+
return (0, agent_service_1.handleAgentReportBlocker)(command);
|
|
1435
|
+
case "agent.reportComplete":
|
|
1436
|
+
return (0, agent_service_1.handleAgentReportComplete)(command);
|
|
1437
|
+
case "agent.senseTurn":
|
|
1438
|
+
return handleAgentSenseTurn(command, { socketPath: this.socketPath });
|
|
1439
|
+
/* v8 ignore stop */
|
|
424
1440
|
case "cron.list": {
|
|
425
1441
|
const jobs = this.scheduler.listJobs();
|
|
426
1442
|
const summary = jobs.length === 0
|
|
@@ -429,10 +1445,28 @@ class OuroDaemon {
|
|
|
429
1445
|
return { ok: true, summary, data: jobs };
|
|
430
1446
|
}
|
|
431
1447
|
case "cron.trigger": {
|
|
1448
|
+
const habitResult = await this.scheduler.triggerHabitJob?.(command.jobId);
|
|
1449
|
+
if (habitResult?.ok) {
|
|
1450
|
+
return { ok: true, message: habitResult.message };
|
|
1451
|
+
}
|
|
432
1452
|
const result = await this.scheduler.triggerJob(command.jobId);
|
|
433
1453
|
return { ok: result.ok, message: result.message };
|
|
434
1454
|
}
|
|
435
1455
|
case "message.send": {
|
|
1456
|
+
// Pure queue-only delivery. We DO NOT wake the recipient — that was
|
|
1457
|
+
// the 2026-05-11 $50 bleed. The Claude Code post-tool-use hook
|
|
1458
|
+
// (cli-exec.ts) intentionally sends only message.send for tool-use
|
|
1459
|
+
// events to avoid waking the agent on every tool call. The hook's
|
|
1460
|
+
// intent was completely defeated by this handler calling
|
|
1461
|
+
// `sendToAgent({type: "message"})`, which woke the private runtime
|
|
1462
|
+
// worker on EVERY message.send anyway. ~30 message.send/min × the
|
|
1463
|
+
// 3-turn instinct-loop cap = ~90 turns/min sustained for hours.
|
|
1464
|
+
//
|
|
1465
|
+
// Callers that want immediate processing must send `private.wake`
|
|
1466
|
+
// explicitly after message.send. The CLI `ouro msg` does so
|
|
1467
|
+
// (lifecycle-boundary delivery should wake); the hook does so
|
|
1468
|
+
// only on session-start / stop, not per tool-use; the API does
|
|
1469
|
+
// not (notifications go to the queue).
|
|
436
1470
|
const receipt = await this.router.send({
|
|
437
1471
|
from: command.from,
|
|
438
1472
|
to: command.to,
|
|
@@ -441,7 +1475,6 @@ class OuroDaemon {
|
|
|
441
1475
|
sessionId: command.sessionId,
|
|
442
1476
|
taskRef: command.taskRef,
|
|
443
1477
|
});
|
|
444
|
-
this.processManager.sendToAgent?.(command.to, { type: "message" });
|
|
445
1478
|
return { ok: true, message: `queued message ${receipt.id}`, data: receipt };
|
|
446
1479
|
}
|
|
447
1480
|
case "message.poll": {
|
|
@@ -452,13 +1485,75 @@ class OuroDaemon {
|
|
|
452
1485
|
data: messages,
|
|
453
1486
|
};
|
|
454
1487
|
}
|
|
455
|
-
case "
|
|
456
|
-
|
|
457
|
-
|
|
1488
|
+
case "external.event.submit": {
|
|
1489
|
+
const record = (0, router_1.recordExternalEvent)({
|
|
1490
|
+
agent: command.agent,
|
|
1491
|
+
source: command.source,
|
|
1492
|
+
eventType: command.eventType,
|
|
1493
|
+
eventId: command.eventId,
|
|
1494
|
+
summary: command.summary,
|
|
1495
|
+
evidence: command.evidence,
|
|
1496
|
+
payloadPath: command.payloadPath,
|
|
1497
|
+
priority: command.priority,
|
|
1498
|
+
}, {
|
|
1499
|
+
...(this.externalEventRoot ? { root: this.externalEventRoot } : {}),
|
|
1500
|
+
});
|
|
1501
|
+
const receipt = await this.router.send({
|
|
1502
|
+
from: "ouro-external-event",
|
|
1503
|
+
to: command.agent,
|
|
1504
|
+
content: (0, router_1.buildExternalEventMessage)(record),
|
|
1505
|
+
priority: record.priority,
|
|
1506
|
+
sessionId: command.sessionId,
|
|
1507
|
+
taskRef: command.taskRef ?? `${record.source}:${record.eventId}`,
|
|
1508
|
+
});
|
|
1509
|
+
let wake = null;
|
|
1510
|
+
if (command.wake !== false) {
|
|
1511
|
+
wake = await this.handlePrivateRuntimeWake(this.buildExternalEventPrivateWakeCommand(command, receipt.id), () => this.queueExternalEventForPrivateRuntime(record));
|
|
1512
|
+
}
|
|
1513
|
+
return {
|
|
1514
|
+
ok: true,
|
|
1515
|
+
message: command.wake === false
|
|
1516
|
+
? `queued external event ${record.source}/${record.eventId} as ${receipt.id}`
|
|
1517
|
+
: `queued external event ${record.source}/${record.eventId} as ${receipt.id}; ${wake?.message ?? "wake skipped"}`,
|
|
1518
|
+
data: { event: record, receipt, wake },
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
case "private.decisions": {
|
|
1522
|
+
const requestedLimit = Number.isInteger(command.limit) && command.limit && command.limit > 0 ? command.limit : 20;
|
|
1523
|
+
const limit = Math.min(requestedLimit, 1000);
|
|
1524
|
+
const ledgerPath = (0, private_runtime_1.privateTurnLedgerPath)(command.agent, { bundlesRoot: this.bundlesRoot });
|
|
1525
|
+
const ledgerExists = fs.existsSync(ledgerPath);
|
|
1526
|
+
let decisions;
|
|
1527
|
+
try {
|
|
1528
|
+
decisions = ledgerExists ? (0, private_runtime_1.readPrivateTurnLedger)(ledgerPath) : [];
|
|
1529
|
+
}
|
|
1530
|
+
catch {
|
|
1531
|
+
return {
|
|
1532
|
+
ok: false,
|
|
1533
|
+
error: `private-runtime decision ledger is malformed: ${ledgerPath}; repair or remove malformed JSONL rows before reading decisions`,
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
const guidance = ledgerExists
|
|
1537
|
+
? undefined
|
|
1538
|
+
: `No private-runtime decision ledger exists for ${command.agent}; run an explicit private-runtime trigger or check ${path.dirname(ledgerPath)}.`;
|
|
1539
|
+
const payload = (0, private_runtime_1.buildPrivateDecisionReadPayload)({
|
|
1540
|
+
agent: command.agent,
|
|
1541
|
+
ledgerPath,
|
|
1542
|
+
decisions,
|
|
1543
|
+
limit,
|
|
1544
|
+
...(guidance ? { guidance } : {}),
|
|
1545
|
+
});
|
|
458
1546
|
return {
|
|
459
1547
|
ok: true,
|
|
460
|
-
|
|
1548
|
+
summary: (0, private_runtime_1.privateDecisionCountSummary)(payload.decisions.length),
|
|
1549
|
+
...(guidance ? { message: guidance } : {}),
|
|
1550
|
+
data: payload,
|
|
461
1551
|
};
|
|
1552
|
+
}
|
|
1553
|
+
case "inner.wake":
|
|
1554
|
+
return this.handlePrivateRuntimeWake(command);
|
|
1555
|
+
case "private.wake":
|
|
1556
|
+
return this.handlePrivateRuntimeWake(command);
|
|
462
1557
|
case "chat.connect":
|
|
463
1558
|
await this.processManager.startAgent(command.agent);
|
|
464
1559
|
return {
|
|
@@ -466,6 +1561,12 @@ class OuroDaemon {
|
|
|
466
1561
|
message: `connected to ${command.agent}`,
|
|
467
1562
|
};
|
|
468
1563
|
case "task.poke": {
|
|
1564
|
+
if (!isValidTaskPokeCommand(command)) {
|
|
1565
|
+
return {
|
|
1566
|
+
ok: false,
|
|
1567
|
+
error: "Invalid task.poke payload: expected non-empty string fields 'agent' and 'taskId'.",
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
469
1570
|
const receipt = await this.router.send({
|
|
470
1571
|
from: "ouro-poke",
|
|
471
1572
|
to: command.agent,
|
|
@@ -474,14 +1575,50 @@ class OuroDaemon {
|
|
|
474
1575
|
taskRef: command.taskId,
|
|
475
1576
|
});
|
|
476
1577
|
await this.scheduler.recordTaskRun?.(command.agent, command.taskId);
|
|
477
|
-
this.
|
|
1578
|
+
await this.handlePrivateRuntimeWake(this.buildTaskPokePrivateWakeCommand(command, receipt.id));
|
|
478
1579
|
return {
|
|
479
1580
|
ok: true,
|
|
480
1581
|
message: `queued poke ${receipt.id}`,
|
|
481
1582
|
data: receipt,
|
|
482
1583
|
};
|
|
483
1584
|
}
|
|
1585
|
+
case "habit.poke": {
|
|
1586
|
+
if (!isValidHabitPokeCommand(command)) {
|
|
1587
|
+
return {
|
|
1588
|
+
ok: false,
|
|
1589
|
+
error: "Invalid habit.poke payload: expected non-empty string fields 'agent' and 'habitName'.",
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
const trigger = command.trigger ?? "poke";
|
|
1593
|
+
if (!(0, flight_recorder_1.isHabitRunTrigger)(trigger)) {
|
|
1594
|
+
return { ok: false, error: `invalid habit trigger: ${String(trigger)}` };
|
|
1595
|
+
}
|
|
1596
|
+
if (!this.hasManagedPrivateRuntime(command.agent)) {
|
|
1597
|
+
return {
|
|
1598
|
+
ok: false,
|
|
1599
|
+
error: `No managed agent '${command.agent}' is registered with daemon-managed private runtime.`,
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
const occurrenceId = this.resolveHabitPokeOccurrenceId(command, trigger);
|
|
1603
|
+
if (typeof occurrenceId === "object") {
|
|
1604
|
+
return {
|
|
1605
|
+
ok: true,
|
|
1606
|
+
message: `skipped scheduled habit ${command.habitName} for ${command.agent}: ${occurrenceId.skipReason}`,
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
return this.handlePrivateRuntimeWake((0, habit_private_wake_1.buildHabitPrivateWakeCommand)({
|
|
1610
|
+
agent: command.agent,
|
|
1611
|
+
habitName: command.habitName,
|
|
1612
|
+
trigger,
|
|
1613
|
+
sourceRef: { kind: "daemon-command", id: "habit.poke" },
|
|
1614
|
+
occurrenceId,
|
|
1615
|
+
}));
|
|
1616
|
+
}
|
|
1617
|
+
case "await.poke": {
|
|
1618
|
+
return this.handlePrivateRuntimeWake(this.buildAwaitPrivateWakeCommand(command));
|
|
1619
|
+
}
|
|
484
1620
|
case "mcp.list": {
|
|
1621
|
+
(0, identity_1.setAgentName)(command.agent ?? "default");
|
|
485
1622
|
const mcpManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
486
1623
|
if (!mcpManager) {
|
|
487
1624
|
return { ok: true, data: [], message: "no MCP servers configured" };
|
|
@@ -489,6 +1626,7 @@ class OuroDaemon {
|
|
|
489
1626
|
return { ok: true, data: mcpManager.listAllTools() };
|
|
490
1627
|
}
|
|
491
1628
|
case "mcp.call": {
|
|
1629
|
+
(0, identity_1.setAgentName)(command.agent ?? "default");
|
|
492
1630
|
const mcpCallManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
493
1631
|
if (!mcpCallManager) {
|
|
494
1632
|
return { ok: false, error: "no MCP servers configured" };
|
|
@@ -506,7 +1644,7 @@ class OuroDaemon {
|
|
|
506
1644
|
case "hatch.start":
|
|
507
1645
|
return {
|
|
508
1646
|
ok: true,
|
|
509
|
-
message: "hatch flow is stubbed
|
|
1647
|
+
message: "hatch flow is stubbed; the interactive implementation lands in a later milestone",
|
|
510
1648
|
};
|
|
511
1649
|
default:
|
|
512
1650
|
return {
|