@ouro.bot/cli 0.1.0-alpha.27 → 0.1.0-alpha.270
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 +187 -191
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +3 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +1 -1
- package/changelog.json +1631 -0
- package/dist/arc/attention-types.js +8 -0
- package/dist/arc/cares.js +140 -0
- package/dist/arc/episodes.js +117 -0
- package/dist/arc/intentions.js +133 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +237 -0
- package/dist/arc/presence.js +185 -0
- package/dist/heart/active-work.js +832 -0
- package/dist/heart/agent-entry.js +37 -2
- package/dist/heart/auth/auth-flow.js +447 -0
- package/dist/heart/bridges/manager.js +358 -0
- package/dist/heart/bridges/state-machine.js +135 -0
- package/dist/heart/bridges/store.js +123 -0
- package/dist/heart/commitments.js +111 -0
- package/dist/heart/config-registry.js +304 -0
- package/dist/heart/config.js +63 -30
- package/dist/heart/core.js +644 -196
- package/dist/heart/cross-chat-delivery.js +131 -0
- package/dist/heart/daemon/agent-config-check.js +149 -0
- package/dist/heart/daemon/agent-discovery.js +79 -3
- package/dist/heart/daemon/agent-service.js +360 -0
- package/dist/heart/daemon/cadence.js +70 -0
- package/dist/heart/daemon/cli-defaults.js +557 -0
- package/dist/heart/daemon/cli-exec.js +1877 -0
- package/dist/heart/daemon/cli-parse.js +759 -0
- package/dist/heart/daemon/cli-render.js +503 -0
- package/dist/heart/daemon/cli-types.js +8 -0
- package/dist/heart/daemon/daemon-cli.js +29 -1155
- package/dist/heart/daemon/daemon-entry.js +214 -3
- package/dist/heart/daemon/daemon-health.js +136 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +153 -12
- package/dist/heart/daemon/daemon-tombstone.js +236 -0
- package/dist/heart/daemon/daemon.js +634 -54
- package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
- package/dist/heart/daemon/hooks/bundle-meta.js +115 -1
- package/dist/heart/daemon/inner-status.js +89 -0
- package/dist/heart/daemon/launchd.js +39 -8
- package/dist/heart/daemon/log-tailer.js +4 -3
- package/dist/heart/daemon/message-router.js +17 -8
- package/dist/heart/daemon/os-cron-deps.js +134 -0
- package/dist/heart/daemon/ouro-bot-entry.js +1 -1
- package/dist/heart/daemon/process-manager.js +123 -0
- package/dist/heart/daemon/run-hooks.js +2 -0
- package/dist/heart/daemon/runtime-logging.js +58 -15
- package/dist/heart/daemon/runtime-metadata.js +101 -0
- package/dist/heart/daemon/runtime-mode.js +67 -0
- package/dist/heart/daemon/safe-mode.js +161 -0
- package/dist/heart/daemon/sense-manager.js +72 -3
- package/dist/heart/daemon/session-id-resolver.js +131 -0
- package/dist/heart/daemon/skill-management-installer.js +94 -0
- package/dist/heart/daemon/socket-client.js +307 -0
- package/dist/heart/daemon/task-scheduler.js +3 -25
- package/dist/heart/daemon/thoughts.js +510 -0
- package/dist/heart/delegation.js +62 -0
- package/dist/heart/habits/habit-migration.js +181 -0
- package/dist/heart/habits/habit-parser.js +119 -0
- package/dist/heart/habits/habit-scheduler.js +371 -0
- package/dist/heart/{daemon → hatch}/hatch-flow.js +30 -120
- package/dist/heart/{daemon → hatch}/hatch-specialist.js +3 -3
- package/dist/heart/{daemon → hatch}/specialist-prompt.js +10 -7
- package/dist/heart/{daemon → hatch}/specialist-tools.js +49 -3
- package/dist/heart/identity.js +160 -58
- package/dist/heart/kicks.js +2 -20
- package/dist/heart/mcp/mcp-server.js +653 -0
- package/dist/heart/migrate-config.js +127 -0
- package/dist/heart/model-capabilities.js +59 -0
- package/dist/heart/outlook/outlook-http.js +439 -0
- package/dist/heart/outlook/outlook-read.js +1618 -0
- package/dist/heart/outlook/outlook-render.js +1032 -0
- package/dist/heart/outlook/outlook-types.js +7 -0
- package/dist/heart/outlook/outlook-view.js +194 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/provider-failover.js +88 -0
- package/dist/heart/provider-ping.js +162 -0
- package/dist/heart/providers/anthropic-token.js +163 -0
- package/dist/heart/providers/anthropic.js +169 -46
- package/dist/heart/providers/azure.js +98 -11
- package/dist/heart/providers/error-classification.js +63 -0
- package/dist/heart/providers/github-copilot.js +136 -0
- package/dist/heart/providers/minimax-vlm.js +189 -0
- package/dist/heart/providers/minimax.js +23 -5
- package/dist/heart/providers/openai-codex.js +33 -22
- package/dist/heart/session-activity.js +172 -0
- package/dist/heart/session-recall.js +216 -0
- package/dist/heart/start-of-turn-packet.js +330 -0
- package/dist/heart/streaming.js +36 -27
- package/dist/heart/sync.js +277 -0
- package/dist/heart/target-resolution.js +127 -0
- package/dist/heart/tempo.js +93 -0
- package/dist/heart/temporal-view.js +41 -0
- package/dist/heart/tool-activity-callbacks.js +36 -0
- package/dist/heart/tool-description.js +135 -0
- package/dist/heart/tool-loop.js +200 -0
- package/dist/heart/turn-context.js +358 -0
- package/dist/heart/turn-coordinator.js +28 -0
- package/dist/heart/versioning/ouro-bot-global-installer.js +128 -0
- package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
- package/dist/heart/{daemon → versioning}/ouro-path-installer.js +78 -35
- package/dist/heart/versioning/ouro-version-manager.js +171 -0
- package/dist/heart/{daemon → versioning}/staged-restart.js +30 -6
- package/dist/heart/{daemon → versioning}/update-checker.js +12 -2
- package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +41 -3
- package/dist/mind/associative-recall.js +126 -66
- package/dist/mind/bundle-manifest.js +8 -1
- package/dist/mind/context.js +125 -14
- package/dist/mind/{memory.js → diary.js} +68 -96
- package/dist/mind/embedding-provider.js +60 -0
- package/dist/mind/file-state.js +179 -0
- package/dist/mind/first-impressions.js +16 -2
- package/dist/mind/friends/channel.js +56 -0
- package/dist/mind/friends/group-context.js +144 -0
- package/dist/mind/friends/resolver.js +37 -0
- package/dist/mind/friends/store-file.js +58 -3
- package/dist/mind/friends/trust-explanation.js +74 -0
- package/dist/mind/friends/types.js +8 -0
- package/dist/mind/journal-index.js +161 -0
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +76 -9
- package/dist/mind/prompt.js +777 -109
- package/dist/mind/scrutiny.js +173 -0
- package/dist/mind/token-estimate.js +8 -12
- package/dist/nerves/coverage/audit.js +1 -1
- package/dist/nerves/coverage/file-completeness.js +50 -5
- package/dist/nerves/coverage/run-artifacts.js +1 -1
- package/dist/nerves/event-buffer.js +111 -0
- package/dist/nerves/index.js +64 -4
- package/dist/nerves/observation.js +20 -0
- package/dist/nerves/runtime.js +5 -1
- package/dist/outlook-ui/assets/index-Ck8agNeO.js +61 -0
- package/dist/outlook-ui/assets/index-LwChZTgL.css +1 -0
- package/dist/outlook-ui/index.html +15 -0
- package/dist/repertoire/ado-client.js +15 -56
- package/dist/repertoire/ado-semantic.js +11 -10
- package/dist/repertoire/api-client.js +97 -0
- package/dist/repertoire/bitwarden-store.js +319 -0
- package/dist/repertoire/bw-installer.js +79 -0
- package/dist/repertoire/coding/codex-jsonl.js +64 -0
- package/dist/repertoire/coding/context-pack.js +330 -0
- package/dist/repertoire/coding/feedback.js +197 -30
- package/dist/repertoire/coding/manager.js +149 -2
- package/dist/repertoire/coding/spawner.js +55 -9
- package/dist/repertoire/coding/tools.js +170 -7
- package/dist/repertoire/commerce-errors.js +109 -0
- package/dist/repertoire/commerce-self-test.js +156 -0
- package/dist/repertoire/credential-access.js +515 -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 +369 -0
- package/dist/repertoire/mcp-client.js +255 -0
- package/dist/repertoire/mcp-manager.js +305 -0
- package/dist/repertoire/mcp-tools.js +63 -0
- package/dist/repertoire/shell-sessions.js +133 -0
- package/dist/repertoire/skills.js +14 -23
- package/dist/repertoire/stripe-client.js +131 -0
- package/dist/repertoire/tasks/board.js +43 -5
- package/dist/repertoire/tasks/fix.js +182 -0
- package/dist/repertoire/tasks/index.js +28 -10
- package/dist/repertoire/tasks/lifecycle.js +2 -2
- package/dist/repertoire/tasks/parser.js +3 -2
- package/dist/repertoire/tasks/scanner.js +194 -37
- package/dist/repertoire/tasks/transitions.js +11 -28
- package/dist/repertoire/tools-base.js +43 -771
- package/dist/repertoire/tools-bluebubbles.js +201 -0
- package/dist/repertoire/tools-bridge.js +141 -0
- package/dist/repertoire/tools-config.js +185 -0
- package/dist/repertoire/tools-continuity.js +248 -0
- package/dist/repertoire/tools-credential.js +182 -0
- package/dist/repertoire/tools-files.js +342 -0
- package/dist/repertoire/tools-flight.js +224 -0
- package/dist/repertoire/tools-flow.js +62 -0
- package/dist/repertoire/tools-github.js +1 -7
- package/dist/repertoire/tools-memory.js +347 -0
- package/dist/repertoire/tools-session.js +739 -0
- package/dist/repertoire/tools-shell.js +120 -0
- package/dist/repertoire/tools-stripe.js +180 -0
- package/dist/repertoire/tools-surface.js +243 -0
- package/dist/repertoire/tools-teams.js +12 -62
- package/dist/repertoire/tools-travel.js +125 -0
- package/dist/repertoire/tools-user-profile.js +144 -0
- package/dist/repertoire/tools-vault.js +110 -0
- package/dist/repertoire/tools.js +155 -130
- package/dist/repertoire/travel-api-client.js +360 -0
- package/dist/repertoire/user-profile.js +118 -0
- package/dist/repertoire/vault-setup.js +241 -0
- package/dist/scripts/claude-code-hook.js +41 -0
- package/dist/scripts/claude-code-stop-hook.js +47 -0
- package/dist/senses/attention-queue.js +97 -0
- package/dist/senses/bluebubbles/attachment-cache.js +53 -0
- package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +145 -10
- package/dist/senses/bluebubbles/entry.js +13 -0
- package/dist/senses/bluebubbles/inbound-log.js +110 -0
- package/dist/senses/bluebubbles/index.js +1410 -0
- package/dist/senses/bluebubbles/media.js +455 -0
- package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +20 -5
- package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +46 -6
- package/dist/senses/bluebubbles/runtime-state.js +109 -0
- package/dist/senses/bluebubbles/session-cleanup.js +72 -0
- package/dist/senses/cli/bracketed-paste.js +82 -0
- package/dist/senses/cli/image-paste.js +211 -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 +578 -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 +83 -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 +1 -1
- package/dist/senses/cli-layout.js +187 -0
- package/dist/senses/cli.js +569 -246
- package/dist/senses/commands.js +65 -1
- package/dist/senses/continuity.js +94 -0
- package/dist/senses/habit-turn-message.js +108 -0
- package/dist/senses/inner-dialog-worker.js +112 -19
- package/dist/senses/inner-dialog.js +593 -85
- package/dist/senses/pipeline.js +552 -0
- package/dist/senses/shared-turn.js +199 -0
- package/dist/senses/surface-tool.js +68 -0
- package/dist/senses/teams.js +664 -165
- package/dist/senses/trust-gate.js +112 -2
- package/package.json +14 -7
- package/skills/agent-commerce.md +106 -0
- package/skills/browser-navigation.md +110 -0
- package/skills/commerce-setup-guide.md +116 -0
- package/skills/commerce-setup.md +84 -0
- package/skills/configure-dev-tools.md +81 -0
- package/skills/travel-planning.md +138 -0
- package/dist/heart/daemon/subagent-installer.js +0 -134
- package/dist/senses/bluebubbles-entry.js +0 -11
- package/dist/senses/bluebubbles-media.js +0 -244
- package/dist/senses/bluebubbles.js +0 -421
- package/dist/senses/debug-activity.js +0 -108
- package/subagents/README.md +0 -73
- package/subagents/work-doer.md +0 -235
- package/subagents/work-merger.md +0 -618
- package/subagents/work-planner.md +0 -382
- /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-serpent.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
- /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
- /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
- /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
- /package/dist/heart/{daemon → versioning}/update-hooks.js +0 -0
|
@@ -34,18 +34,242 @@ 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.killOrphanProcesses = killOrphanProcesses;
|
|
40
|
+
exports.writePidfile = writePidfile;
|
|
41
|
+
exports.handleAgentSenseTurn = handleAgentSenseTurn;
|
|
37
42
|
const fs = __importStar(require("fs"));
|
|
38
43
|
const net = __importStar(require("net"));
|
|
44
|
+
const os = __importStar(require("os"));
|
|
39
45
|
const path = __importStar(require("path"));
|
|
40
46
|
const identity_1 = require("../identity");
|
|
47
|
+
const agent_discovery_1 = require("./agent-discovery");
|
|
41
48
|
const runtime_1 = require("../../nerves/runtime");
|
|
42
49
|
const runtime_metadata_1 = require("./runtime-metadata");
|
|
43
|
-
const
|
|
50
|
+
const runtime_mode_1 = require("./runtime-mode");
|
|
51
|
+
const update_hooks_1 = require("../versioning/update-hooks");
|
|
44
52
|
const bundle_meta_1 = require("./hooks/bundle-meta");
|
|
53
|
+
const agent_config_v2_1 = require("./hooks/agent-config-v2");
|
|
45
54
|
const bundle_manifest_1 = require("../../mind/bundle-manifest");
|
|
46
|
-
const update_checker_1 = require("
|
|
47
|
-
const staged_restart_1 = require("
|
|
55
|
+
const update_checker_1 = require("../versioning/update-checker");
|
|
56
|
+
const staged_restart_1 = require("../versioning/staged-restart");
|
|
48
57
|
const child_process_1 = require("child_process");
|
|
58
|
+
const pending_1 = require("../../mind/pending");
|
|
59
|
+
const agent_service_1 = require("./agent-service");
|
|
60
|
+
const channel_1 = require("../../mind/friends/channel");
|
|
61
|
+
const mcp_manager_1 = require("../../repertoire/mcp-manager");
|
|
62
|
+
const outlook_http_1 = require("../outlook/outlook-http");
|
|
63
|
+
const outlook_types_1 = require("../outlook/outlook-types");
|
|
64
|
+
const outlook_read_1 = require("../outlook/outlook-read");
|
|
65
|
+
const outlook_view_1 = require("../outlook/outlook-view");
|
|
66
|
+
const PIDFILE_PATH = path.join(os.homedir(), ".ouro-cli", "daemon.pids");
|
|
67
|
+
/**
|
|
68
|
+
* Defense-in-depth: detect if we're running under vitest. The pidfile lives
|
|
69
|
+
* at a hardcoded path under the user's real ~/.ouro-cli/ — there's no DI
|
|
70
|
+
* seam to redirect it. So when a test creates a real OuroDaemon and calls
|
|
71
|
+
* start(), the daemon's killOrphanProcesses() reads the REAL pidfile,
|
|
72
|
+
* ps-verifies the PIDs, and SIGTERMs the production daemon. We saw this
|
|
73
|
+
* cause an outage on 2026-04-08 (alpha.265 daemon killed 93s after startup
|
|
74
|
+
* by a vitest test that called daemon.start()).
|
|
75
|
+
*
|
|
76
|
+
* Both killOrphanProcesses() and writePidfile() short-circuit under vitest
|
|
77
|
+
* to make the production pidfile sacred. Tests that need to verify these
|
|
78
|
+
* functions' behavior should use the extracted pure helpers
|
|
79
|
+
* (parseOrphanPidsFromPs, filterPidfilePidsToActualOrphans).
|
|
80
|
+
*/
|
|
81
|
+
function isVitestProcess() {
|
|
82
|
+
/* v8 ignore next -- defensive: process and process.argv always exist in node @preserve */
|
|
83
|
+
if (typeof process === "undefined" || !Array.isArray(process.argv))
|
|
84
|
+
return false;
|
|
85
|
+
return process.argv.some((arg) => typeof arg === "string" && arg.includes("vitest"));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Scan `ps -eo pid,ppid,command` output for daemon-owned entry points whose
|
|
89
|
+
* parent has died (PPID reparented to init/PID 1). Returns the list of PIDs
|
|
90
|
+
* that are safe to SIGTERM — true orphans, not children of live sibling
|
|
91
|
+
* daemons running from worktrees, test suites, or other users of the harness.
|
|
92
|
+
*
|
|
93
|
+
* Exported so unit tests can exercise the filter without shelling out.
|
|
94
|
+
*/
|
|
95
|
+
function parseOrphanPidsFromPs(psOutput, selfPid) {
|
|
96
|
+
const orphans = [];
|
|
97
|
+
for (const line of psOutput.split("\n")) {
|
|
98
|
+
// Explicitly exclude MCP server processes — they share a harness entry
|
|
99
|
+
// point but are not daemon children and must never be killed.
|
|
100
|
+
if (line.includes("mcp-serve") || line.includes("mcp serve"))
|
|
101
|
+
continue;
|
|
102
|
+
// Match only daemon-owned JS entry points.
|
|
103
|
+
if (!line.includes("agent-entry.js")
|
|
104
|
+
&& !line.includes("daemon-entry.js")
|
|
105
|
+
&& !line.includes("bluebubbles/entry.js")
|
|
106
|
+
&& !line.includes("teams-entry.js"))
|
|
107
|
+
continue;
|
|
108
|
+
// Parse `<pid> <ppid> <command...>`. ps pads these with leading spaces.
|
|
109
|
+
// Regex guarantees both groups are \d+ so parseInt can't produce NaN.
|
|
110
|
+
const match = line.trim().match(/^(\d+)\s+(\d+)\s/);
|
|
111
|
+
if (!match)
|
|
112
|
+
continue;
|
|
113
|
+
const pid = parseInt(match[1], 10);
|
|
114
|
+
const ppid = parseInt(match[2], 10);
|
|
115
|
+
if (pid === selfPid)
|
|
116
|
+
continue;
|
|
117
|
+
// CRITICAL: only kill processes whose parent is init (PID 1). A live
|
|
118
|
+
// PPID means the process belongs to another daemon instance (parallel
|
|
119
|
+
// test run, sibling worktree, another user of /tmp/ouroboros-daemon.sock).
|
|
120
|
+
// Killing those will crash unrelated harnesses — we saw this in B6
|
|
121
|
+
// when a vitest worker's daemon killed slugger's production children.
|
|
122
|
+
if (ppid !== 1)
|
|
123
|
+
continue;
|
|
124
|
+
orphans.push(pid);
|
|
125
|
+
}
|
|
126
|
+
return orphans;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Given a list of PIDs from the pidfile, return only those that are actual
|
|
130
|
+
* orphans (PPID reparented to init/PID 1). Protects against a polluted
|
|
131
|
+
* pidfile killing a PID that the OS has reassigned to an unrelated process.
|
|
132
|
+
*
|
|
133
|
+
* Implementation: shells out to `ps -p <csv> -o pid,ppid` for a batch lookup.
|
|
134
|
+
* Returns the empty list if ps fails — safer to skip cleanup than to
|
|
135
|
+
* wildcard-kill on a bad read.
|
|
136
|
+
*
|
|
137
|
+
* Exported for direct unit coverage.
|
|
138
|
+
*/
|
|
139
|
+
function filterPidfilePidsToActualOrphans(candidatePids, psRunner = runPsCheck) {
|
|
140
|
+
if (candidatePids.length === 0)
|
|
141
|
+
return [];
|
|
142
|
+
const psOutput = psRunner(candidatePids);
|
|
143
|
+
if (psOutput === null)
|
|
144
|
+
return [];
|
|
145
|
+
const survivingOrphans = [];
|
|
146
|
+
// `ps -p x,y,z -o pid,ppid` emits a header line then one row per found PID.
|
|
147
|
+
// PIDs not found (already exited) are silently omitted — which is the
|
|
148
|
+
// correct behavior for us: we only want to kill live orphans.
|
|
149
|
+
for (const line of psOutput.split("\n")) {
|
|
150
|
+
const match = line.trim().match(/^(\d+)\s+(\d+)$/);
|
|
151
|
+
if (!match)
|
|
152
|
+
continue;
|
|
153
|
+
const pid = parseInt(match[1], 10);
|
|
154
|
+
const ppid = parseInt(match[2], 10);
|
|
155
|
+
if (ppid !== 1)
|
|
156
|
+
continue;
|
|
157
|
+
if (!candidatePids.includes(pid))
|
|
158
|
+
continue;
|
|
159
|
+
survivingOrphans.push(pid);
|
|
160
|
+
}
|
|
161
|
+
return survivingOrphans;
|
|
162
|
+
}
|
|
163
|
+
/* v8 ignore start -- shells out to ps; covered by filterPidfilePidsToActualOrphans unit tests via injected runner @preserve */
|
|
164
|
+
function runPsCheck(pids) {
|
|
165
|
+
try {
|
|
166
|
+
const csv = pids.join(",");
|
|
167
|
+
return (0, child_process_1.execSync)(`ps -p ${csv} -o pid=,ppid=`, { encoding: "utf-8", timeout: 5000 });
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
// ps returns non-zero when none of the requested PIDs exist. Treat as
|
|
171
|
+
// "no survivors" rather than an error.
|
|
172
|
+
return "";
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/* v8 ignore stop */
|
|
176
|
+
/**
|
|
177
|
+
* Kill all ouro processes from the previous daemon instance using the pidfile.
|
|
178
|
+
* On startup, reads PIDs from ~/.ouro-cli/daemon.pids, kills them all, then
|
|
179
|
+
* deletes the file. The new daemon writes its own PIDs after spawning.
|
|
180
|
+
*
|
|
181
|
+
* Safety: pidfile contents are verified before being killed — each PID must
|
|
182
|
+
* be an actual orphan (PPID reparented to init/PID 1) via
|
|
183
|
+
* `filterPidfilePidsToActualOrphans`. Otherwise a polluted pidfile (written
|
|
184
|
+
* by a test, or a crashed daemon whose PIDs have since been reused by the
|
|
185
|
+
* OS) could SIGTERM unrelated processes.
|
|
186
|
+
*
|
|
187
|
+
* Falls back to ps-based scanning scoped to true orphans (PPID=1) if the
|
|
188
|
+
* pidfile doesn't exist (first run, previous daemon crashed before writing,
|
|
189
|
+
* manual cleanup). The scope is narrow on purpose — see parseOrphanPidsFromPs.
|
|
190
|
+
*/
|
|
191
|
+
/* v8 ignore start -- process lifecycle: uses kill/ps, tested via deployment @preserve */
|
|
192
|
+
function killOrphanProcesses() {
|
|
193
|
+
if (isVitestProcess()) {
|
|
194
|
+
(0, runtime_1.emitNervesEvent)({
|
|
195
|
+
level: "warn",
|
|
196
|
+
component: "daemon",
|
|
197
|
+
event: "daemon.orphan_cleanup_test_blocked",
|
|
198
|
+
message: "blocked killOrphanProcesses from touching real pidfile under vitest",
|
|
199
|
+
meta: { pidfilePath: PIDFILE_PATH },
|
|
200
|
+
});
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
let pidsToKill = [];
|
|
205
|
+
// Primary: read pidfile from previous daemon
|
|
206
|
+
try {
|
|
207
|
+
const raw = fs.readFileSync(PIDFILE_PATH, "utf-8");
|
|
208
|
+
const candidates = raw.split("\n")
|
|
209
|
+
.map((s) => parseInt(s.trim(), 10))
|
|
210
|
+
.filter((n) => !isNaN(n) && n !== process.pid);
|
|
211
|
+
// Verify each candidate is an actual live orphan before killing. See
|
|
212
|
+
// docstring above for why this matters.
|
|
213
|
+
pidsToKill = filterPidfilePidsToActualOrphans(candidates);
|
|
214
|
+
fs.unlinkSync(PIDFILE_PATH);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
// No pidfile — fall back to ps scan (scoped to orphans with PPID=1).
|
|
218
|
+
}
|
|
219
|
+
if (pidsToKill.length === 0) {
|
|
220
|
+
try {
|
|
221
|
+
const result = (0, child_process_1.execSync)("ps -eo pid,ppid,command", { encoding: "utf-8", timeout: 5000 });
|
|
222
|
+
pidsToKill = parseOrphanPidsFromPs(result, process.pid);
|
|
223
|
+
}
|
|
224
|
+
catch { /* ps failed — best effort */ }
|
|
225
|
+
}
|
|
226
|
+
if (pidsToKill.length > 0) {
|
|
227
|
+
for (const pid of pidsToKill) {
|
|
228
|
+
try {
|
|
229
|
+
process.kill(pid, "SIGTERM");
|
|
230
|
+
}
|
|
231
|
+
catch { /* already exited */ }
|
|
232
|
+
}
|
|
233
|
+
(0, runtime_1.emitNervesEvent)({
|
|
234
|
+
component: "daemon",
|
|
235
|
+
event: "daemon.orphan_cleanup",
|
|
236
|
+
message: `killed ${pidsToKill.length} orphaned ouro processes`,
|
|
237
|
+
meta: { pids: pidsToKill },
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
(0, runtime_1.emitNervesEvent)({
|
|
243
|
+
level: "warn",
|
|
244
|
+
component: "daemon",
|
|
245
|
+
event: "daemon.orphan_cleanup_error",
|
|
246
|
+
message: "failed to clean up orphaned ouro processes",
|
|
247
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Write all managed PIDs (daemon + children) to the pidfile.
|
|
253
|
+
* Called after all agents and senses are spawned.
|
|
254
|
+
*/
|
|
255
|
+
function writePidfile(extraPids = []) {
|
|
256
|
+
if (isVitestProcess()) {
|
|
257
|
+
(0, runtime_1.emitNervesEvent)({
|
|
258
|
+
level: "warn",
|
|
259
|
+
component: "daemon",
|
|
260
|
+
event: "daemon.write_pidfile_test_blocked",
|
|
261
|
+
message: "blocked writePidfile from clobbering real pidfile under vitest",
|
|
262
|
+
meta: { pidfilePath: PIDFILE_PATH, attemptedPids: extraPids.length },
|
|
263
|
+
});
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
const pids = [process.pid, ...extraPids].filter(Boolean);
|
|
268
|
+
fs.mkdirSync(path.dirname(PIDFILE_PATH), { recursive: true });
|
|
269
|
+
fs.writeFileSync(PIDFILE_PATH, pids.join("\n") + "\n", "utf-8");
|
|
270
|
+
}
|
|
271
|
+
catch { /* best effort */ }
|
|
272
|
+
}
|
|
49
273
|
function buildWorkerRows(snapshots) {
|
|
50
274
|
return snapshots.map((snapshot) => ({
|
|
51
275
|
agent: snapshot.name,
|
|
@@ -54,6 +278,8 @@ function buildWorkerRows(snapshots) {
|
|
|
54
278
|
pid: snapshot.pid,
|
|
55
279
|
restartCount: snapshot.restartCount,
|
|
56
280
|
startedAt: snapshot.startedAt,
|
|
281
|
+
lastExitCode: snapshot.lastExitCode ?? null,
|
|
282
|
+
lastSignal: snapshot.lastSignal ?? null,
|
|
57
283
|
}));
|
|
58
284
|
}
|
|
59
285
|
function formatStatusSummary(payload) {
|
|
@@ -86,6 +312,35 @@ function parseIncomingCommand(raw) {
|
|
|
86
312
|
}
|
|
87
313
|
return parsed;
|
|
88
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Handle agent.senseTurn command: runs a full agent turn via the daemon process.
|
|
317
|
+
* Dynamic import lazy-loads shared-turn. Hot-reload works because ouro dev
|
|
318
|
+
* restarts the daemon process (fresh module cache).
|
|
319
|
+
*/
|
|
320
|
+
async function handleAgentSenseTurn(command) {
|
|
321
|
+
try {
|
|
322
|
+
const { setAgentName } = await Promise.resolve().then(() => __importStar(require("../identity")));
|
|
323
|
+
setAgentName(command.agent);
|
|
324
|
+
const { runSenseTurn } = await Promise.resolve().then(() => __importStar(require("../../senses/shared-turn")));
|
|
325
|
+
const result = await runSenseTurn({
|
|
326
|
+
agentName: command.agent,
|
|
327
|
+
channel: command.channel,
|
|
328
|
+
sessionKey: command.sessionKey,
|
|
329
|
+
friendId: command.friendId,
|
|
330
|
+
userMessage: command.message,
|
|
331
|
+
});
|
|
332
|
+
return {
|
|
333
|
+
ok: true,
|
|
334
|
+
message: result.response,
|
|
335
|
+
data: { ponderDeferred: result.ponderDeferred },
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
catch (error) {
|
|
339
|
+
/* v8 ignore next -- branch: String(error) fallback only for non-Error throws @preserve */
|
|
340
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
341
|
+
return { ok: false, error: `sense turn failed: ${errorMessage}` };
|
|
342
|
+
}
|
|
343
|
+
}
|
|
89
344
|
class OuroDaemon {
|
|
90
345
|
socketPath;
|
|
91
346
|
processManager;
|
|
@@ -94,7 +349,9 @@ class OuroDaemon {
|
|
|
94
349
|
router;
|
|
95
350
|
senseManager;
|
|
96
351
|
bundlesRoot;
|
|
352
|
+
mode;
|
|
97
353
|
server = null;
|
|
354
|
+
outlookServer = null;
|
|
98
355
|
constructor(options) {
|
|
99
356
|
this.socketPath = options.socketPath;
|
|
100
357
|
this.processManager = options.processManager;
|
|
@@ -103,6 +360,32 @@ class OuroDaemon {
|
|
|
103
360
|
this.router = options.router;
|
|
104
361
|
this.senseManager = options.senseManager ?? null;
|
|
105
362
|
this.bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
|
|
363
|
+
this.mode = options.mode ?? "production";
|
|
364
|
+
}
|
|
365
|
+
buildStatusPayload() {
|
|
366
|
+
const snapshots = this.processManager.listAgentSnapshots();
|
|
367
|
+
const workers = buildWorkerRows(snapshots);
|
|
368
|
+
const senses = this.senseManager?.listSenseRows() ?? [];
|
|
369
|
+
const repoRoot = (0, identity_1.getRepoRoot)();
|
|
370
|
+
const sync = (0, agent_discovery_1.listBundleSyncRows)({ bundlesRoot: this.bundlesRoot });
|
|
371
|
+
const agents = (0, agent_discovery_1.listAllBundleAgents)({ bundlesRoot: this.bundlesRoot });
|
|
372
|
+
return {
|
|
373
|
+
overview: {
|
|
374
|
+
daemon: "running",
|
|
375
|
+
health: workers.every((worker) => worker.status === "running") ? "ok" : "warn",
|
|
376
|
+
socketPath: this.socketPath,
|
|
377
|
+
outlookUrl: this.outlookServer?.origin ?? "http://127.0.0.1:0",
|
|
378
|
+
...(0, runtime_metadata_1.getRuntimeMetadata)(),
|
|
379
|
+
workerCount: workers.length,
|
|
380
|
+
senseCount: senses.length,
|
|
381
|
+
entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
|
|
382
|
+
mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
|
|
383
|
+
},
|
|
384
|
+
workers,
|
|
385
|
+
senses,
|
|
386
|
+
sync,
|
|
387
|
+
agents,
|
|
388
|
+
};
|
|
106
389
|
}
|
|
107
390
|
async start() {
|
|
108
391
|
if (this.server)
|
|
@@ -115,59 +398,172 @@ class OuroDaemon {
|
|
|
115
398
|
});
|
|
116
399
|
// Register update hooks and apply pending updates before starting agents
|
|
117
400
|
(0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
|
|
401
|
+
(0, update_hooks_1.registerUpdateHook)(agent_config_v2_1.agentConfigV2Hook);
|
|
118
402
|
const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
|
|
119
403
|
await (0, update_hooks_1.applyPendingUpdates)(this.bundlesRoot, currentVersion);
|
|
120
404
|
// Start periodic update checker (polls npm registry every 30 minutes)
|
|
405
|
+
// Skip in dev mode — dev builds should not auto-update from npm
|
|
121
406
|
const bundlesRoot = this.bundlesRoot;
|
|
122
|
-
const
|
|
123
|
-
(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const resolved = (0, child_process_1.execSync)(`node -e "console.log(require.resolve('@ouro.bot/cli/package.json'))"`, { encoding: "utf-8" }).trim();
|
|
141
|
-
return resolved ? path.dirname(resolved) : null;
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
407
|
+
const daemonSocketPath = this.socketPath;
|
|
408
|
+
if (this.mode === "dev") {
|
|
409
|
+
(0, runtime_1.emitNervesEvent)({
|
|
410
|
+
component: "daemon",
|
|
411
|
+
event: "daemon.update_checker_skip",
|
|
412
|
+
message: "skipping update checker in dev mode",
|
|
413
|
+
meta: { reason: "dev mode" },
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
const daemon = this;
|
|
418
|
+
(0, update_checker_1.startUpdateChecker)({
|
|
419
|
+
currentVersion,
|
|
420
|
+
deps: {
|
|
421
|
+
distTag: "alpha",
|
|
422
|
+
fetchRegistryJson: /* v8 ignore next -- integration: real HTTP fetch @preserve */ async () => {
|
|
423
|
+
const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
|
|
424
|
+
return res.json();
|
|
146
425
|
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
426
|
+
},
|
|
427
|
+
onUpdate: /* v8 ignore start -- integration: real npm install + process spawn @preserve */ async (result) => {
|
|
428
|
+
if (!result.latestVersion)
|
|
429
|
+
return;
|
|
430
|
+
await (0, staged_restart_1.performStagedRestart)(result.latestVersion, {
|
|
431
|
+
execSync: (cmd) => (0, child_process_1.execSync)(cmd, { stdio: "inherit" }),
|
|
432
|
+
spawnSync: child_process_1.spawnSync,
|
|
433
|
+
resolveNewCodePath: (_version) => {
|
|
434
|
+
try {
|
|
435
|
+
const resolved = (0, child_process_1.execSync)(`node -e "console.log(require.resolve('@ouro.bot/cli/package.json'))"`, { encoding: "utf-8" }).trim();
|
|
436
|
+
return resolved ? path.dirname(resolved) : null;
|
|
437
|
+
}
|
|
438
|
+
catch {
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
gracefulShutdown: () => daemon.stop(),
|
|
443
|
+
spawnNewDaemon: (entryPath, sock) => {
|
|
444
|
+
const outFd = fs.openSync(os.devNull, "w");
|
|
445
|
+
const errFd = fs.openSync(os.devNull, "w");
|
|
446
|
+
const child = (0, child_process_1.spawn)(process.execPath, [entryPath, "--socket", sock], {
|
|
447
|
+
detached: true,
|
|
448
|
+
stdio: ["ignore", outFd, errFd],
|
|
449
|
+
});
|
|
450
|
+
child.unref();
|
|
451
|
+
return { pid: child.pid ?? null };
|
|
452
|
+
},
|
|
453
|
+
nodePath: process.execPath,
|
|
454
|
+
bundlesRoot,
|
|
455
|
+
socketPath: daemonSocketPath,
|
|
456
|
+
});
|
|
457
|
+
},
|
|
458
|
+
/* v8 ignore stop */
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
// MCP connections are lazily initialized per-agent during senseTurn
|
|
462
|
+
// (daemon manages multiple agents; agent identity must be set before loading MCP config)
|
|
463
|
+
/* v8 ignore start -- orphan cleanup + pidfile: calls process management functions @preserve */
|
|
464
|
+
killOrphanProcesses();
|
|
465
|
+
/* v8 ignore stop */
|
|
154
466
|
await this.processManager.startAutoStartAgents();
|
|
155
467
|
await this.senseManager?.startAutoStartSenses();
|
|
468
|
+
// Write all managed PIDs to disk so the next daemon can clean up
|
|
469
|
+
/* v8 ignore start -- pidfile write: collects PIDs from process managers @preserve */
|
|
470
|
+
const agentPids = this.processManager.listAgentSnapshots().map((s) => s.pid).filter((p) => p !== null);
|
|
471
|
+
const sensePids = this.senseManager?.listManagedPids?.() ?? [];
|
|
472
|
+
writePidfile([...agentPids, ...sensePids]);
|
|
473
|
+
/* v8 ignore stop */
|
|
156
474
|
this.scheduler.start?.();
|
|
157
475
|
await this.scheduler.reconcile?.();
|
|
158
476
|
await this.drainPendingBundleMessages();
|
|
477
|
+
await this.drainPendingSenseMessages();
|
|
478
|
+
/* v8 ignore start — Outlook server startup, tested via outlook-http.test.ts */
|
|
479
|
+
if (!this.outlookServer) {
|
|
480
|
+
try {
|
|
481
|
+
this.outlookServer = await (0, outlook_http_1.startOutlookHttpServer)({
|
|
482
|
+
host: "127.0.0.1",
|
|
483
|
+
port: outlook_types_1.OUTLOOK_DEFAULT_PORT,
|
|
484
|
+
bundlesRoot: this.bundlesRoot,
|
|
485
|
+
readMachineState: () => (0, outlook_read_1.readOutlookMachineState)({ bundlesRoot: this.bundlesRoot }),
|
|
486
|
+
readMachineView: ({ machine }) => {
|
|
487
|
+
const overview = this.buildStatusPayload().overview;
|
|
488
|
+
return (0, outlook_view_1.buildOutlookMachineView)({
|
|
489
|
+
machine,
|
|
490
|
+
daemon: {
|
|
491
|
+
status: overview.daemon,
|
|
492
|
+
health: overview.health,
|
|
493
|
+
mode: overview.mode,
|
|
494
|
+
socketPath: overview.socketPath,
|
|
495
|
+
outlookUrl: overview.outlookUrl,
|
|
496
|
+
entryPath: overview.entryPath,
|
|
497
|
+
workerCount: overview.workerCount,
|
|
498
|
+
senseCount: overview.senseCount,
|
|
499
|
+
},
|
|
500
|
+
});
|
|
501
|
+
},
|
|
502
|
+
readAgentState: (agentName) => (0, outlook_read_1.readOutlookAgentState)(agentName, { bundlesRoot: this.bundlesRoot }),
|
|
503
|
+
readAgentView: (agentName) => {
|
|
504
|
+
const agent = (0, outlook_read_1.readOutlookAgentState)(agentName, { bundlesRoot: this.bundlesRoot });
|
|
505
|
+
return (0, outlook_view_1.buildOutlookAgentView)({
|
|
506
|
+
agent,
|
|
507
|
+
viewer: { kind: "human" },
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
catch (error) {
|
|
513
|
+
(0, runtime_1.emitNervesEvent)({
|
|
514
|
+
level: "warn",
|
|
515
|
+
component: "daemon",
|
|
516
|
+
event: "daemon.outlook_start_failed",
|
|
517
|
+
message: `Outlook server failed to start: ${String(error)}`,
|
|
518
|
+
meta: { port: outlook_types_1.OUTLOOK_DEFAULT_PORT },
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
/* v8 ignore stop */
|
|
159
523
|
if (fs.existsSync(this.socketPath)) {
|
|
160
524
|
fs.unlinkSync(this.socketPath);
|
|
161
525
|
}
|
|
162
|
-
|
|
526
|
+
// allowHalfOpen: true lets the server keep its writable side open after
|
|
527
|
+
// the client sends FIN. Without this, when a client calls `client.end()`
|
|
528
|
+
// after writing a command, node closes the server's writable side
|
|
529
|
+
// automatically — so a long-running response (like an agent.senseTurn
|
|
530
|
+
// LLM turn that takes 5+ seconds) never reaches the client. The
|
|
531
|
+
// socket-client fix in #303/#334 also removed client.end() on the
|
|
532
|
+
// sending side, but this option is defense in depth: even if a future
|
|
533
|
+
// caller half-closes, the server still writes its response correctly.
|
|
534
|
+
this.server = net.createServer({ allowHalfOpen: true }, (connection) => {
|
|
163
535
|
let raw = "";
|
|
164
536
|
let responded = false;
|
|
537
|
+
/* v8 ignore start — connection error handler requires real socket error @preserve */
|
|
538
|
+
connection.on("error", (err) => {
|
|
539
|
+
(0, runtime_1.emitNervesEvent)({
|
|
540
|
+
level: "warn",
|
|
541
|
+
component: "daemon",
|
|
542
|
+
event: "daemon.connection_error",
|
|
543
|
+
message: "socket connection error",
|
|
544
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
/* v8 ignore stop */
|
|
165
548
|
const flushResponse = async () => {
|
|
166
549
|
if (responded)
|
|
167
550
|
return;
|
|
168
551
|
responded = true;
|
|
169
552
|
const response = await this.handleRawPayload(raw);
|
|
170
|
-
|
|
553
|
+
try {
|
|
554
|
+
connection.end(response);
|
|
555
|
+
/* v8 ignore start — EPIPE catch requires real socket disconnect @preserve */
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
(0, runtime_1.emitNervesEvent)({
|
|
559
|
+
level: "warn",
|
|
560
|
+
component: "daemon",
|
|
561
|
+
event: "daemon.connection_end_error",
|
|
562
|
+
message: "failed to send response to client (EPIPE)",
|
|
563
|
+
meta: { error: err instanceof Error ? err.message : String(err) },
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
/* v8 ignore stop */
|
|
171
567
|
};
|
|
172
568
|
connection.on("data", (chunk) => {
|
|
173
569
|
raw += chunk.toString("utf-8");
|
|
@@ -180,7 +576,22 @@ class OuroDaemon {
|
|
|
180
576
|
const server = this.server;
|
|
181
577
|
await new Promise((resolve, reject) => {
|
|
182
578
|
server.once("error", reject);
|
|
183
|
-
server.listen(this.socketPath, () =>
|
|
579
|
+
server.listen(this.socketPath, () => {
|
|
580
|
+
// Replace the one-time error listener with a persistent one after successful listen
|
|
581
|
+
server.removeAllListeners("error");
|
|
582
|
+
/* v8 ignore start — server error after listen requires real socket race condition @preserve */
|
|
583
|
+
server.on("error", (err) => {
|
|
584
|
+
(0, runtime_1.emitNervesEvent)({
|
|
585
|
+
level: "error",
|
|
586
|
+
component: "daemon",
|
|
587
|
+
event: "daemon.server_error",
|
|
588
|
+
message: "daemon server error after listen",
|
|
589
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
/* v8 ignore stop */
|
|
593
|
+
resolve();
|
|
594
|
+
});
|
|
184
595
|
});
|
|
185
596
|
}
|
|
186
597
|
async drainPendingBundleMessages() {
|
|
@@ -231,14 +642,105 @@ class OuroDaemon {
|
|
|
231
642
|
fs.writeFileSync(pendingPath, next, "utf-8");
|
|
232
643
|
}
|
|
233
644
|
}
|
|
645
|
+
/** Drains per-sense pending dirs for always-on senses across all agents. */
|
|
646
|
+
static ALWAYS_ON_SENSES = new Set((0, channel_1.getAlwaysOnSenseNames)());
|
|
647
|
+
async drainPendingSenseMessages() {
|
|
648
|
+
if (!fs.existsSync(this.bundlesRoot))
|
|
649
|
+
return;
|
|
650
|
+
let bundleDirs;
|
|
651
|
+
try {
|
|
652
|
+
bundleDirs = fs.readdirSync(this.bundlesRoot, { withFileTypes: true });
|
|
653
|
+
}
|
|
654
|
+
catch {
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
for (const bundleDir of bundleDirs) {
|
|
658
|
+
if (!bundleDir.isDirectory() || !bundleDir.name.endsWith(".ouro"))
|
|
659
|
+
continue;
|
|
660
|
+
const agentName = bundleDir.name.replace(/\.ouro$/, "");
|
|
661
|
+
const pendingRoot = path.join(this.bundlesRoot, bundleDir.name, "state", "pending");
|
|
662
|
+
if (!fs.existsSync(pendingRoot))
|
|
663
|
+
continue;
|
|
664
|
+
let friendDirs;
|
|
665
|
+
try {
|
|
666
|
+
friendDirs = fs.readdirSync(pendingRoot, { withFileTypes: true });
|
|
667
|
+
}
|
|
668
|
+
catch {
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
for (const friendDir of friendDirs) {
|
|
672
|
+
if (!friendDir.isDirectory())
|
|
673
|
+
continue;
|
|
674
|
+
const friendPath = path.join(pendingRoot, friendDir.name);
|
|
675
|
+
let channelDirs;
|
|
676
|
+
try {
|
|
677
|
+
channelDirs = fs.readdirSync(friendPath, { withFileTypes: true });
|
|
678
|
+
}
|
|
679
|
+
catch {
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
for (const channelDir of channelDirs) {
|
|
683
|
+
if (!channelDir.isDirectory())
|
|
684
|
+
continue;
|
|
685
|
+
if (!OuroDaemon.ALWAYS_ON_SENSES.has(channelDir.name))
|
|
686
|
+
continue;
|
|
687
|
+
const channelPath = path.join(friendPath, channelDir.name);
|
|
688
|
+
let keyDirs;
|
|
689
|
+
try {
|
|
690
|
+
keyDirs = fs.readdirSync(channelPath, { withFileTypes: true });
|
|
691
|
+
}
|
|
692
|
+
catch {
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
for (const keyDir of keyDirs) {
|
|
696
|
+
if (!keyDir.isDirectory())
|
|
697
|
+
continue;
|
|
698
|
+
const leafDir = path.join(channelPath, keyDir.name);
|
|
699
|
+
const messages = (0, pending_1.drainPending)(leafDir);
|
|
700
|
+
for (const msg of messages) {
|
|
701
|
+
try {
|
|
702
|
+
await this.router.send({
|
|
703
|
+
from: msg.from,
|
|
704
|
+
to: agentName,
|
|
705
|
+
content: msg.content,
|
|
706
|
+
priority: "normal",
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
catch {
|
|
710
|
+
// Best-effort delivery — log and continue
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
if (messages.length > 0) {
|
|
714
|
+
(0, runtime_1.emitNervesEvent)({
|
|
715
|
+
component: "daemon",
|
|
716
|
+
event: "daemon.startup_sense_drain",
|
|
717
|
+
message: "drained pending sense messages on startup",
|
|
718
|
+
meta: {
|
|
719
|
+
agent: agentName,
|
|
720
|
+
channel: channelDir.name,
|
|
721
|
+
friendId: friendDir.name,
|
|
722
|
+
key: keyDir.name,
|
|
723
|
+
count: messages.length,
|
|
724
|
+
},
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
234
732
|
async stop() {
|
|
733
|
+
// Must be named `_end` (not `_stop`) to satisfy the nerves audit's
|
|
734
|
+
// start/end pairing rule — see src/nerves/coverage/audit-rules.ts.
|
|
735
|
+
// This is the counterpart to `daemon.server_start` emitted at line 480.
|
|
235
736
|
(0, runtime_1.emitNervesEvent)({
|
|
236
737
|
component: "daemon",
|
|
237
|
-
event: "daemon.
|
|
738
|
+
event: "daemon.server_end",
|
|
238
739
|
message: "stopping daemon server",
|
|
239
740
|
meta: { socketPath: this.socketPath },
|
|
240
741
|
});
|
|
241
742
|
(0, update_checker_1.stopUpdateChecker)();
|
|
743
|
+
(0, mcp_manager_1.shutdownSharedMcpManager)();
|
|
242
744
|
this.scheduler.stop?.();
|
|
243
745
|
await this.processManager.stopAll();
|
|
244
746
|
await this.senseManager?.stopAll();
|
|
@@ -248,6 +750,12 @@ class OuroDaemon {
|
|
|
248
750
|
});
|
|
249
751
|
this.server = null;
|
|
250
752
|
}
|
|
753
|
+
/* v8 ignore start -- outlookServer stop: only reachable when the outlook HTTP server successfully bound to port 6876 during start(). Coverage fluctuates locally because a running production daemon holds the port and tests get EADDRINUSE, leaving outlookServer null. In CI the port is free and this block runs. Not worth fighting port contention to cover two trivial lines. @preserve */
|
|
754
|
+
if (this.outlookServer) {
|
|
755
|
+
await this.outlookServer.stop();
|
|
756
|
+
this.outlookServer = null;
|
|
757
|
+
}
|
|
758
|
+
/* v8 ignore stop */
|
|
251
759
|
if (fs.existsSync(this.socketPath)) {
|
|
252
760
|
fs.unlinkSync(this.socketPath);
|
|
253
761
|
}
|
|
@@ -272,6 +780,27 @@ class OuroDaemon {
|
|
|
272
780
|
message: "handling daemon command",
|
|
273
781
|
meta: { kind: command.kind },
|
|
274
782
|
});
|
|
783
|
+
try {
|
|
784
|
+
return await this.handleCommandInner(command);
|
|
785
|
+
/* v8 ignore start — command error catch tested in daemon-command-error.test; instanceof branches defensive @preserve */
|
|
786
|
+
}
|
|
787
|
+
catch (error) {
|
|
788
|
+
(0, runtime_1.emitNervesEvent)({
|
|
789
|
+
level: "error",
|
|
790
|
+
component: "daemon",
|
|
791
|
+
event: "daemon.command_error",
|
|
792
|
+
message: "unexpected error handling daemon command",
|
|
793
|
+
meta: {
|
|
794
|
+
kind: command.kind,
|
|
795
|
+
error: error instanceof Error ? error.message : String(error),
|
|
796
|
+
stack: error instanceof Error ? error.stack ?? null : null,
|
|
797
|
+
},
|
|
798
|
+
});
|
|
799
|
+
throw error;
|
|
800
|
+
}
|
|
801
|
+
/* v8 ignore stop */
|
|
802
|
+
}
|
|
803
|
+
async handleCommandInner(command) {
|
|
275
804
|
switch (command.kind) {
|
|
276
805
|
case "daemon.start":
|
|
277
806
|
await this.start();
|
|
@@ -280,21 +809,7 @@ class OuroDaemon {
|
|
|
280
809
|
await this.stop();
|
|
281
810
|
return { ok: true, message: "daemon stopped" };
|
|
282
811
|
case "daemon.status": {
|
|
283
|
-
const
|
|
284
|
-
const workers = buildWorkerRows(snapshots);
|
|
285
|
-
const senses = this.senseManager?.listSenseRows() ?? [];
|
|
286
|
-
const data = {
|
|
287
|
-
overview: {
|
|
288
|
-
daemon: "running",
|
|
289
|
-
health: workers.every((worker) => worker.status === "running") ? "ok" : "warn",
|
|
290
|
-
socketPath: this.socketPath,
|
|
291
|
-
...(0, runtime_metadata_1.getRuntimeMetadata)(),
|
|
292
|
-
workerCount: workers.length,
|
|
293
|
-
senseCount: senses.length,
|
|
294
|
-
},
|
|
295
|
-
workers,
|
|
296
|
-
senses,
|
|
297
|
-
};
|
|
812
|
+
const data = this.buildStatusPayload();
|
|
298
813
|
return {
|
|
299
814
|
ok: true,
|
|
300
815
|
summary: formatStatusSummary(data),
|
|
@@ -311,7 +826,7 @@ class OuroDaemon {
|
|
|
311
826
|
ok: true,
|
|
312
827
|
summary: "logs: use `ouro logs` to tail daemon and agent output",
|
|
313
828
|
message: "log streaming available via ouro logs",
|
|
314
|
-
data: { logDir: "
|
|
829
|
+
data: { logDir: "~/AgentBundles/<agent>.ouro/state/daemon/logs" },
|
|
315
830
|
};
|
|
316
831
|
case "agent.start":
|
|
317
832
|
await this.processManager.startAgent(command.agent);
|
|
@@ -322,6 +837,35 @@ class OuroDaemon {
|
|
|
322
837
|
case "agent.restart":
|
|
323
838
|
await this.processManager.restartAgent?.(command.agent);
|
|
324
839
|
return { ok: true, message: `restarted ${command.agent}` };
|
|
840
|
+
case "agent.ask":
|
|
841
|
+
return (0, agent_service_1.handleAgentAsk)(command);
|
|
842
|
+
case "agent.status":
|
|
843
|
+
return (0, agent_service_1.handleAgentStatus)(command);
|
|
844
|
+
case "agent.catchup":
|
|
845
|
+
return (0, agent_service_1.handleAgentCatchup)(command);
|
|
846
|
+
case "agent.delegate":
|
|
847
|
+
return (0, agent_service_1.handleAgentDelegate)(command);
|
|
848
|
+
case "agent.getContext":
|
|
849
|
+
return (0, agent_service_1.handleAgentGetContext)(command);
|
|
850
|
+
case "agent.searchMemory":
|
|
851
|
+
return (0, agent_service_1.handleAgentSearchMemory)(command);
|
|
852
|
+
case "agent.getTask":
|
|
853
|
+
return (0, agent_service_1.handleAgentGetTask)(command);
|
|
854
|
+
case "agent.checkScope":
|
|
855
|
+
return (0, agent_service_1.handleAgentCheckScope)(command);
|
|
856
|
+
case "agent.requestDecision":
|
|
857
|
+
return (0, agent_service_1.handleAgentRequestDecision)(command);
|
|
858
|
+
case "agent.checkGuidance":
|
|
859
|
+
return (0, agent_service_1.handleAgentCheckGuidance)(command);
|
|
860
|
+
case "agent.reportProgress":
|
|
861
|
+
return (0, agent_service_1.handleAgentReportProgress)(command);
|
|
862
|
+
case "agent.reportBlocker":
|
|
863
|
+
return (0, agent_service_1.handleAgentReportBlocker)(command);
|
|
864
|
+
case "agent.reportComplete":
|
|
865
|
+
return (0, agent_service_1.handleAgentReportComplete)(command);
|
|
866
|
+
case "agent.senseTurn":
|
|
867
|
+
return handleAgentSenseTurn(command);
|
|
868
|
+
/* v8 ignore stop */
|
|
325
869
|
case "cron.list": {
|
|
326
870
|
const jobs = this.scheduler.listJobs();
|
|
327
871
|
const summary = jobs.length === 0
|
|
@@ -353,6 +897,13 @@ class OuroDaemon {
|
|
|
353
897
|
data: messages,
|
|
354
898
|
};
|
|
355
899
|
}
|
|
900
|
+
case "inner.wake":
|
|
901
|
+
await this.processManager.startAgent(command.agent);
|
|
902
|
+
this.processManager.sendToAgent?.(command.agent, { type: "message" });
|
|
903
|
+
return {
|
|
904
|
+
ok: true,
|
|
905
|
+
message: `woke inner dialog for ${command.agent}`,
|
|
906
|
+
};
|
|
356
907
|
case "chat.connect":
|
|
357
908
|
await this.processManager.startAgent(command.agent);
|
|
358
909
|
return {
|
|
@@ -375,6 +926,35 @@ class OuroDaemon {
|
|
|
375
926
|
data: receipt,
|
|
376
927
|
};
|
|
377
928
|
}
|
|
929
|
+
case "habit.poke": {
|
|
930
|
+
this.processManager.sendToAgent?.(command.agent, { type: "habit", habitName: command.habitName });
|
|
931
|
+
return {
|
|
932
|
+
ok: true,
|
|
933
|
+
message: `poked habit ${command.habitName} for ${command.agent}`,
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
case "mcp.list": {
|
|
937
|
+
const mcpManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
938
|
+
if (!mcpManager) {
|
|
939
|
+
return { ok: true, data: [], message: "no MCP servers configured" };
|
|
940
|
+
}
|
|
941
|
+
return { ok: true, data: mcpManager.listAllTools() };
|
|
942
|
+
}
|
|
943
|
+
case "mcp.call": {
|
|
944
|
+
const mcpCallManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
945
|
+
if (!mcpCallManager) {
|
|
946
|
+
return { ok: false, error: "no MCP servers configured" };
|
|
947
|
+
}
|
|
948
|
+
try {
|
|
949
|
+
const parsedArgs = command.args ? JSON.parse(command.args) : {};
|
|
950
|
+
const result = await mcpCallManager.callTool(command.server, command.tool, parsedArgs);
|
|
951
|
+
return { ok: true, data: result };
|
|
952
|
+
}
|
|
953
|
+
catch (error) {
|
|
954
|
+
/* v8 ignore next -- defensive: callTool errors are always Error instances @preserve */
|
|
955
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
956
|
+
}
|
|
957
|
+
}
|
|
378
958
|
case "hatch.start":
|
|
379
959
|
return {
|
|
380
960
|
ok: true,
|