@ouro.bot/cli 0.1.0-alpha.26 → 0.1.0-alpha.261
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 +1582 -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 +145 -0
- 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 +464 -0
- package/dist/heart/daemon/cli-types.js +8 -0
- package/dist/heart/daemon/daemon-cli.js +29 -1179
- package/dist/heart/daemon/daemon-entry.js +216 -4
- 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 +123 -0
- package/dist/heart/daemon/daemon.js +590 -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 +276 -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 +157 -55
- 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/phrases.js +1 -0
- package/dist/mind/prompt.js +765 -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 +1374 -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 +168 -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 +581 -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 -107
- 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,202 @@ 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
|
+
* Scan `ps -eo pid,ppid,command` output for daemon-owned entry points whose
|
|
69
|
+
* parent has died (PPID reparented to init/PID 1). Returns the list of PIDs
|
|
70
|
+
* that are safe to SIGTERM — true orphans, not children of live sibling
|
|
71
|
+
* daemons running from worktrees, test suites, or other users of the harness.
|
|
72
|
+
*
|
|
73
|
+
* Exported so unit tests can exercise the filter without shelling out.
|
|
74
|
+
*/
|
|
75
|
+
function parseOrphanPidsFromPs(psOutput, selfPid) {
|
|
76
|
+
const orphans = [];
|
|
77
|
+
for (const line of psOutput.split("\n")) {
|
|
78
|
+
// Explicitly exclude MCP server processes — they share a harness entry
|
|
79
|
+
// point but are not daemon children and must never be killed.
|
|
80
|
+
if (line.includes("mcp-serve") || line.includes("mcp serve"))
|
|
81
|
+
continue;
|
|
82
|
+
// Match only daemon-owned JS entry points.
|
|
83
|
+
if (!line.includes("agent-entry.js")
|
|
84
|
+
&& !line.includes("daemon-entry.js")
|
|
85
|
+
&& !line.includes("bluebubbles/entry.js")
|
|
86
|
+
&& !line.includes("teams-entry.js"))
|
|
87
|
+
continue;
|
|
88
|
+
// Parse `<pid> <ppid> <command...>`. ps pads these with leading spaces.
|
|
89
|
+
// Regex guarantees both groups are \d+ so parseInt can't produce NaN.
|
|
90
|
+
const match = line.trim().match(/^(\d+)\s+(\d+)\s/);
|
|
91
|
+
if (!match)
|
|
92
|
+
continue;
|
|
93
|
+
const pid = parseInt(match[1], 10);
|
|
94
|
+
const ppid = parseInt(match[2], 10);
|
|
95
|
+
if (pid === selfPid)
|
|
96
|
+
continue;
|
|
97
|
+
// CRITICAL: only kill processes whose parent is init (PID 1). A live
|
|
98
|
+
// PPID means the process belongs to another daemon instance (parallel
|
|
99
|
+
// test run, sibling worktree, another user of /tmp/ouroboros-daemon.sock).
|
|
100
|
+
// Killing those will crash unrelated harnesses — we saw this in B6
|
|
101
|
+
// when a vitest worker's daemon killed slugger's production children.
|
|
102
|
+
if (ppid !== 1)
|
|
103
|
+
continue;
|
|
104
|
+
orphans.push(pid);
|
|
105
|
+
}
|
|
106
|
+
return orphans;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Given a list of PIDs from the pidfile, return only those that are actual
|
|
110
|
+
* orphans (PPID reparented to init/PID 1). Protects against a polluted
|
|
111
|
+
* pidfile killing a PID that the OS has reassigned to an unrelated process.
|
|
112
|
+
*
|
|
113
|
+
* Implementation: shells out to `ps -p <csv> -o pid,ppid` for a batch lookup.
|
|
114
|
+
* Returns the empty list if ps fails — safer to skip cleanup than to
|
|
115
|
+
* wildcard-kill on a bad read.
|
|
116
|
+
*
|
|
117
|
+
* Exported for direct unit coverage.
|
|
118
|
+
*/
|
|
119
|
+
function filterPidfilePidsToActualOrphans(candidatePids, psRunner = runPsCheck) {
|
|
120
|
+
if (candidatePids.length === 0)
|
|
121
|
+
return [];
|
|
122
|
+
const psOutput = psRunner(candidatePids);
|
|
123
|
+
if (psOutput === null)
|
|
124
|
+
return [];
|
|
125
|
+
const survivingOrphans = [];
|
|
126
|
+
// `ps -p x,y,z -o pid,ppid` emits a header line then one row per found PID.
|
|
127
|
+
// PIDs not found (already exited) are silently omitted — which is the
|
|
128
|
+
// correct behavior for us: we only want to kill live orphans.
|
|
129
|
+
for (const line of psOutput.split("\n")) {
|
|
130
|
+
const match = line.trim().match(/^(\d+)\s+(\d+)$/);
|
|
131
|
+
if (!match)
|
|
132
|
+
continue;
|
|
133
|
+
const pid = parseInt(match[1], 10);
|
|
134
|
+
const ppid = parseInt(match[2], 10);
|
|
135
|
+
if (ppid !== 1)
|
|
136
|
+
continue;
|
|
137
|
+
if (!candidatePids.includes(pid))
|
|
138
|
+
continue;
|
|
139
|
+
survivingOrphans.push(pid);
|
|
140
|
+
}
|
|
141
|
+
return survivingOrphans;
|
|
142
|
+
}
|
|
143
|
+
/* v8 ignore start -- shells out to ps; covered by filterPidfilePidsToActualOrphans unit tests via injected runner @preserve */
|
|
144
|
+
function runPsCheck(pids) {
|
|
145
|
+
try {
|
|
146
|
+
const csv = pids.join(",");
|
|
147
|
+
return (0, child_process_1.execSync)(`ps -p ${csv} -o pid=,ppid=`, { encoding: "utf-8", timeout: 5000 });
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// ps returns non-zero when none of the requested PIDs exist. Treat as
|
|
151
|
+
// "no survivors" rather than an error.
|
|
152
|
+
return "";
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/* v8 ignore stop */
|
|
156
|
+
/**
|
|
157
|
+
* Kill all ouro processes from the previous daemon instance using the pidfile.
|
|
158
|
+
* On startup, reads PIDs from ~/.ouro-cli/daemon.pids, kills them all, then
|
|
159
|
+
* deletes the file. The new daemon writes its own PIDs after spawning.
|
|
160
|
+
*
|
|
161
|
+
* Safety: pidfile contents are verified before being killed — each PID must
|
|
162
|
+
* be an actual orphan (PPID reparented to init/PID 1) via
|
|
163
|
+
* `filterPidfilePidsToActualOrphans`. Otherwise a polluted pidfile (written
|
|
164
|
+
* by a test, or a crashed daemon whose PIDs have since been reused by the
|
|
165
|
+
* OS) could SIGTERM unrelated processes.
|
|
166
|
+
*
|
|
167
|
+
* Falls back to ps-based scanning scoped to true orphans (PPID=1) if the
|
|
168
|
+
* pidfile doesn't exist (first run, previous daemon crashed before writing,
|
|
169
|
+
* manual cleanup). The scope is narrow on purpose — see parseOrphanPidsFromPs.
|
|
170
|
+
*/
|
|
171
|
+
/* v8 ignore start -- process lifecycle: uses kill/ps, tested via deployment @preserve */
|
|
172
|
+
function killOrphanProcesses() {
|
|
173
|
+
try {
|
|
174
|
+
let pidsToKill = [];
|
|
175
|
+
// Primary: read pidfile from previous daemon
|
|
176
|
+
try {
|
|
177
|
+
const raw = fs.readFileSync(PIDFILE_PATH, "utf-8");
|
|
178
|
+
const candidates = raw.split("\n")
|
|
179
|
+
.map((s) => parseInt(s.trim(), 10))
|
|
180
|
+
.filter((n) => !isNaN(n) && n !== process.pid);
|
|
181
|
+
// Verify each candidate is an actual live orphan before killing. See
|
|
182
|
+
// docstring above for why this matters.
|
|
183
|
+
pidsToKill = filterPidfilePidsToActualOrphans(candidates);
|
|
184
|
+
fs.unlinkSync(PIDFILE_PATH);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// No pidfile — fall back to ps scan (scoped to orphans with PPID=1).
|
|
188
|
+
}
|
|
189
|
+
if (pidsToKill.length === 0) {
|
|
190
|
+
try {
|
|
191
|
+
const result = (0, child_process_1.execSync)("ps -eo pid,ppid,command", { encoding: "utf-8", timeout: 5000 });
|
|
192
|
+
pidsToKill = parseOrphanPidsFromPs(result, process.pid);
|
|
193
|
+
}
|
|
194
|
+
catch { /* ps failed — best effort */ }
|
|
195
|
+
}
|
|
196
|
+
if (pidsToKill.length > 0) {
|
|
197
|
+
for (const pid of pidsToKill) {
|
|
198
|
+
try {
|
|
199
|
+
process.kill(pid, "SIGTERM");
|
|
200
|
+
}
|
|
201
|
+
catch { /* already exited */ }
|
|
202
|
+
}
|
|
203
|
+
(0, runtime_1.emitNervesEvent)({
|
|
204
|
+
component: "daemon",
|
|
205
|
+
event: "daemon.orphan_cleanup",
|
|
206
|
+
message: `killed ${pidsToKill.length} orphaned ouro processes`,
|
|
207
|
+
meta: { pids: pidsToKill },
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
(0, runtime_1.emitNervesEvent)({
|
|
213
|
+
level: "warn",
|
|
214
|
+
component: "daemon",
|
|
215
|
+
event: "daemon.orphan_cleanup_error",
|
|
216
|
+
message: "failed to clean up orphaned ouro processes",
|
|
217
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Write all managed PIDs (daemon + children) to the pidfile.
|
|
223
|
+
* Called after all agents and senses are spawned.
|
|
224
|
+
*/
|
|
225
|
+
function writePidfile(extraPids = []) {
|
|
226
|
+
try {
|
|
227
|
+
const pids = [process.pid, ...extraPids].filter(Boolean);
|
|
228
|
+
fs.mkdirSync(path.dirname(PIDFILE_PATH), { recursive: true });
|
|
229
|
+
fs.writeFileSync(PIDFILE_PATH, pids.join("\n") + "\n", "utf-8");
|
|
230
|
+
}
|
|
231
|
+
catch { /* best effort */ }
|
|
232
|
+
}
|
|
49
233
|
function buildWorkerRows(snapshots) {
|
|
50
234
|
return snapshots.map((snapshot) => ({
|
|
51
235
|
agent: snapshot.name,
|
|
@@ -54,6 +238,8 @@ function buildWorkerRows(snapshots) {
|
|
|
54
238
|
pid: snapshot.pid,
|
|
55
239
|
restartCount: snapshot.restartCount,
|
|
56
240
|
startedAt: snapshot.startedAt,
|
|
241
|
+
lastExitCode: snapshot.lastExitCode ?? null,
|
|
242
|
+
lastSignal: snapshot.lastSignal ?? null,
|
|
57
243
|
}));
|
|
58
244
|
}
|
|
59
245
|
function formatStatusSummary(payload) {
|
|
@@ -86,6 +272,35 @@ function parseIncomingCommand(raw) {
|
|
|
86
272
|
}
|
|
87
273
|
return parsed;
|
|
88
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* Handle agent.senseTurn command: runs a full agent turn via the daemon process.
|
|
277
|
+
* Dynamic import lazy-loads shared-turn. Hot-reload works because ouro dev
|
|
278
|
+
* restarts the daemon process (fresh module cache).
|
|
279
|
+
*/
|
|
280
|
+
async function handleAgentSenseTurn(command) {
|
|
281
|
+
try {
|
|
282
|
+
const { setAgentName } = await Promise.resolve().then(() => __importStar(require("../identity")));
|
|
283
|
+
setAgentName(command.agent);
|
|
284
|
+
const { runSenseTurn } = await Promise.resolve().then(() => __importStar(require("../../senses/shared-turn")));
|
|
285
|
+
const result = await runSenseTurn({
|
|
286
|
+
agentName: command.agent,
|
|
287
|
+
channel: command.channel,
|
|
288
|
+
sessionKey: command.sessionKey,
|
|
289
|
+
friendId: command.friendId,
|
|
290
|
+
userMessage: command.message,
|
|
291
|
+
});
|
|
292
|
+
return {
|
|
293
|
+
ok: true,
|
|
294
|
+
message: result.response,
|
|
295
|
+
data: { ponderDeferred: result.ponderDeferred },
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
/* v8 ignore next -- branch: String(error) fallback only for non-Error throws @preserve */
|
|
300
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
301
|
+
return { ok: false, error: `sense turn failed: ${errorMessage}` };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
89
304
|
class OuroDaemon {
|
|
90
305
|
socketPath;
|
|
91
306
|
processManager;
|
|
@@ -94,7 +309,9 @@ class OuroDaemon {
|
|
|
94
309
|
router;
|
|
95
310
|
senseManager;
|
|
96
311
|
bundlesRoot;
|
|
312
|
+
mode;
|
|
97
313
|
server = null;
|
|
314
|
+
outlookServer = null;
|
|
98
315
|
constructor(options) {
|
|
99
316
|
this.socketPath = options.socketPath;
|
|
100
317
|
this.processManager = options.processManager;
|
|
@@ -103,6 +320,30 @@ class OuroDaemon {
|
|
|
103
320
|
this.router = options.router;
|
|
104
321
|
this.senseManager = options.senseManager ?? null;
|
|
105
322
|
this.bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
|
|
323
|
+
this.mode = options.mode ?? "production";
|
|
324
|
+
}
|
|
325
|
+
buildStatusPayload() {
|
|
326
|
+
const snapshots = this.processManager.listAgentSnapshots();
|
|
327
|
+
const workers = buildWorkerRows(snapshots);
|
|
328
|
+
const senses = this.senseManager?.listSenseRows() ?? [];
|
|
329
|
+
const repoRoot = (0, identity_1.getRepoRoot)();
|
|
330
|
+
const sync = (0, agent_discovery_1.listBundleSyncRows)({ bundlesRoot: this.bundlesRoot });
|
|
331
|
+
return {
|
|
332
|
+
overview: {
|
|
333
|
+
daemon: "running",
|
|
334
|
+
health: workers.every((worker) => worker.status === "running") ? "ok" : "warn",
|
|
335
|
+
socketPath: this.socketPath,
|
|
336
|
+
outlookUrl: this.outlookServer?.origin ?? "http://127.0.0.1:0",
|
|
337
|
+
...(0, runtime_metadata_1.getRuntimeMetadata)(),
|
|
338
|
+
workerCount: workers.length,
|
|
339
|
+
senseCount: senses.length,
|
|
340
|
+
entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
|
|
341
|
+
mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
|
|
342
|
+
},
|
|
343
|
+
workers,
|
|
344
|
+
senses,
|
|
345
|
+
sync,
|
|
346
|
+
};
|
|
106
347
|
}
|
|
107
348
|
async start() {
|
|
108
349
|
if (this.server)
|
|
@@ -115,59 +356,172 @@ class OuroDaemon {
|
|
|
115
356
|
});
|
|
116
357
|
// Register update hooks and apply pending updates before starting agents
|
|
117
358
|
(0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
|
|
359
|
+
(0, update_hooks_1.registerUpdateHook)(agent_config_v2_1.agentConfigV2Hook);
|
|
118
360
|
const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
|
|
119
361
|
await (0, update_hooks_1.applyPendingUpdates)(this.bundlesRoot, currentVersion);
|
|
120
362
|
// Start periodic update checker (polls npm registry every 30 minutes)
|
|
363
|
+
// Skip in dev mode — dev builds should not auto-update from npm
|
|
121
364
|
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
|
-
}
|
|
365
|
+
const daemonSocketPath = this.socketPath;
|
|
366
|
+
if (this.mode === "dev") {
|
|
367
|
+
(0, runtime_1.emitNervesEvent)({
|
|
368
|
+
component: "daemon",
|
|
369
|
+
event: "daemon.update_checker_skip",
|
|
370
|
+
message: "skipping update checker in dev mode",
|
|
371
|
+
meta: { reason: "dev mode" },
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
const daemon = this;
|
|
376
|
+
(0, update_checker_1.startUpdateChecker)({
|
|
377
|
+
currentVersion,
|
|
378
|
+
deps: {
|
|
379
|
+
distTag: "alpha",
|
|
380
|
+
fetchRegistryJson: /* v8 ignore next -- integration: real HTTP fetch @preserve */ async () => {
|
|
381
|
+
const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
|
|
382
|
+
return res.json();
|
|
146
383
|
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
384
|
+
},
|
|
385
|
+
onUpdate: /* v8 ignore start -- integration: real npm install + process spawn @preserve */ async (result) => {
|
|
386
|
+
if (!result.latestVersion)
|
|
387
|
+
return;
|
|
388
|
+
await (0, staged_restart_1.performStagedRestart)(result.latestVersion, {
|
|
389
|
+
execSync: (cmd) => (0, child_process_1.execSync)(cmd, { stdio: "inherit" }),
|
|
390
|
+
spawnSync: child_process_1.spawnSync,
|
|
391
|
+
resolveNewCodePath: (_version) => {
|
|
392
|
+
try {
|
|
393
|
+
const resolved = (0, child_process_1.execSync)(`node -e "console.log(require.resolve('@ouro.bot/cli/package.json'))"`, { encoding: "utf-8" }).trim();
|
|
394
|
+
return resolved ? path.dirname(resolved) : null;
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
gracefulShutdown: () => daemon.stop(),
|
|
401
|
+
spawnNewDaemon: (entryPath, sock) => {
|
|
402
|
+
const outFd = fs.openSync(os.devNull, "w");
|
|
403
|
+
const errFd = fs.openSync(os.devNull, "w");
|
|
404
|
+
const child = (0, child_process_1.spawn)(process.execPath, [entryPath, "--socket", sock], {
|
|
405
|
+
detached: true,
|
|
406
|
+
stdio: ["ignore", outFd, errFd],
|
|
407
|
+
});
|
|
408
|
+
child.unref();
|
|
409
|
+
return { pid: child.pid ?? null };
|
|
410
|
+
},
|
|
411
|
+
nodePath: process.execPath,
|
|
412
|
+
bundlesRoot,
|
|
413
|
+
socketPath: daemonSocketPath,
|
|
414
|
+
});
|
|
415
|
+
},
|
|
416
|
+
/* v8 ignore stop */
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
// MCP connections are lazily initialized per-agent during senseTurn
|
|
420
|
+
// (daemon manages multiple agents; agent identity must be set before loading MCP config)
|
|
421
|
+
/* v8 ignore start -- orphan cleanup + pidfile: calls process management functions @preserve */
|
|
422
|
+
killOrphanProcesses();
|
|
423
|
+
/* v8 ignore stop */
|
|
154
424
|
await this.processManager.startAutoStartAgents();
|
|
155
425
|
await this.senseManager?.startAutoStartSenses();
|
|
426
|
+
// Write all managed PIDs to disk so the next daemon can clean up
|
|
427
|
+
/* v8 ignore start -- pidfile write: collects PIDs from process managers @preserve */
|
|
428
|
+
const agentPids = this.processManager.listAgentSnapshots().map((s) => s.pid).filter((p) => p !== null);
|
|
429
|
+
const sensePids = this.senseManager?.listManagedPids?.() ?? [];
|
|
430
|
+
writePidfile([...agentPids, ...sensePids]);
|
|
431
|
+
/* v8 ignore stop */
|
|
156
432
|
this.scheduler.start?.();
|
|
157
433
|
await this.scheduler.reconcile?.();
|
|
158
434
|
await this.drainPendingBundleMessages();
|
|
435
|
+
await this.drainPendingSenseMessages();
|
|
436
|
+
/* v8 ignore start — Outlook server startup, tested via outlook-http.test.ts */
|
|
437
|
+
if (!this.outlookServer) {
|
|
438
|
+
try {
|
|
439
|
+
this.outlookServer = await (0, outlook_http_1.startOutlookHttpServer)({
|
|
440
|
+
host: "127.0.0.1",
|
|
441
|
+
port: outlook_types_1.OUTLOOK_DEFAULT_PORT,
|
|
442
|
+
bundlesRoot: this.bundlesRoot,
|
|
443
|
+
readMachineState: () => (0, outlook_read_1.readOutlookMachineState)({ bundlesRoot: this.bundlesRoot }),
|
|
444
|
+
readMachineView: ({ machine }) => {
|
|
445
|
+
const overview = this.buildStatusPayload().overview;
|
|
446
|
+
return (0, outlook_view_1.buildOutlookMachineView)({
|
|
447
|
+
machine,
|
|
448
|
+
daemon: {
|
|
449
|
+
status: overview.daemon,
|
|
450
|
+
health: overview.health,
|
|
451
|
+
mode: overview.mode,
|
|
452
|
+
socketPath: overview.socketPath,
|
|
453
|
+
outlookUrl: overview.outlookUrl,
|
|
454
|
+
entryPath: overview.entryPath,
|
|
455
|
+
workerCount: overview.workerCount,
|
|
456
|
+
senseCount: overview.senseCount,
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
},
|
|
460
|
+
readAgentState: (agentName) => (0, outlook_read_1.readOutlookAgentState)(agentName, { bundlesRoot: this.bundlesRoot }),
|
|
461
|
+
readAgentView: (agentName) => {
|
|
462
|
+
const agent = (0, outlook_read_1.readOutlookAgentState)(agentName, { bundlesRoot: this.bundlesRoot });
|
|
463
|
+
return (0, outlook_view_1.buildOutlookAgentView)({
|
|
464
|
+
agent,
|
|
465
|
+
viewer: { kind: "human" },
|
|
466
|
+
});
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
(0, runtime_1.emitNervesEvent)({
|
|
472
|
+
level: "warn",
|
|
473
|
+
component: "daemon",
|
|
474
|
+
event: "daemon.outlook_start_failed",
|
|
475
|
+
message: `Outlook server failed to start: ${String(error)}`,
|
|
476
|
+
meta: { port: outlook_types_1.OUTLOOK_DEFAULT_PORT },
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
/* v8 ignore stop */
|
|
159
481
|
if (fs.existsSync(this.socketPath)) {
|
|
160
482
|
fs.unlinkSync(this.socketPath);
|
|
161
483
|
}
|
|
162
|
-
|
|
484
|
+
// allowHalfOpen: true lets the server keep its writable side open after
|
|
485
|
+
// the client sends FIN. Without this, when a client calls `client.end()`
|
|
486
|
+
// after writing a command, node closes the server's writable side
|
|
487
|
+
// automatically — so a long-running response (like an agent.senseTurn
|
|
488
|
+
// LLM turn that takes 5+ seconds) never reaches the client. The
|
|
489
|
+
// socket-client fix in #303/#334 also removed client.end() on the
|
|
490
|
+
// sending side, but this option is defense in depth: even if a future
|
|
491
|
+
// caller half-closes, the server still writes its response correctly.
|
|
492
|
+
this.server = net.createServer({ allowHalfOpen: true }, (connection) => {
|
|
163
493
|
let raw = "";
|
|
164
494
|
let responded = false;
|
|
495
|
+
/* v8 ignore start — connection error handler requires real socket error @preserve */
|
|
496
|
+
connection.on("error", (err) => {
|
|
497
|
+
(0, runtime_1.emitNervesEvent)({
|
|
498
|
+
level: "warn",
|
|
499
|
+
component: "daemon",
|
|
500
|
+
event: "daemon.connection_error",
|
|
501
|
+
message: "socket connection error",
|
|
502
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
/* v8 ignore stop */
|
|
165
506
|
const flushResponse = async () => {
|
|
166
507
|
if (responded)
|
|
167
508
|
return;
|
|
168
509
|
responded = true;
|
|
169
510
|
const response = await this.handleRawPayload(raw);
|
|
170
|
-
|
|
511
|
+
try {
|
|
512
|
+
connection.end(response);
|
|
513
|
+
/* v8 ignore start — EPIPE catch requires real socket disconnect @preserve */
|
|
514
|
+
}
|
|
515
|
+
catch (err) {
|
|
516
|
+
(0, runtime_1.emitNervesEvent)({
|
|
517
|
+
level: "warn",
|
|
518
|
+
component: "daemon",
|
|
519
|
+
event: "daemon.connection_end_error",
|
|
520
|
+
message: "failed to send response to client (EPIPE)",
|
|
521
|
+
meta: { error: err instanceof Error ? err.message : String(err) },
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
/* v8 ignore stop */
|
|
171
525
|
};
|
|
172
526
|
connection.on("data", (chunk) => {
|
|
173
527
|
raw += chunk.toString("utf-8");
|
|
@@ -180,7 +534,22 @@ class OuroDaemon {
|
|
|
180
534
|
const server = this.server;
|
|
181
535
|
await new Promise((resolve, reject) => {
|
|
182
536
|
server.once("error", reject);
|
|
183
|
-
server.listen(this.socketPath, () =>
|
|
537
|
+
server.listen(this.socketPath, () => {
|
|
538
|
+
// Replace the one-time error listener with a persistent one after successful listen
|
|
539
|
+
server.removeAllListeners("error");
|
|
540
|
+
/* v8 ignore start — server error after listen requires real socket race condition @preserve */
|
|
541
|
+
server.on("error", (err) => {
|
|
542
|
+
(0, runtime_1.emitNervesEvent)({
|
|
543
|
+
level: "error",
|
|
544
|
+
component: "daemon",
|
|
545
|
+
event: "daemon.server_error",
|
|
546
|
+
message: "daemon server error after listen",
|
|
547
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
/* v8 ignore stop */
|
|
551
|
+
resolve();
|
|
552
|
+
});
|
|
184
553
|
});
|
|
185
554
|
}
|
|
186
555
|
async drainPendingBundleMessages() {
|
|
@@ -231,14 +600,105 @@ class OuroDaemon {
|
|
|
231
600
|
fs.writeFileSync(pendingPath, next, "utf-8");
|
|
232
601
|
}
|
|
233
602
|
}
|
|
603
|
+
/** Drains per-sense pending dirs for always-on senses across all agents. */
|
|
604
|
+
static ALWAYS_ON_SENSES = new Set((0, channel_1.getAlwaysOnSenseNames)());
|
|
605
|
+
async drainPendingSenseMessages() {
|
|
606
|
+
if (!fs.existsSync(this.bundlesRoot))
|
|
607
|
+
return;
|
|
608
|
+
let bundleDirs;
|
|
609
|
+
try {
|
|
610
|
+
bundleDirs = fs.readdirSync(this.bundlesRoot, { withFileTypes: true });
|
|
611
|
+
}
|
|
612
|
+
catch {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
for (const bundleDir of bundleDirs) {
|
|
616
|
+
if (!bundleDir.isDirectory() || !bundleDir.name.endsWith(".ouro"))
|
|
617
|
+
continue;
|
|
618
|
+
const agentName = bundleDir.name.replace(/\.ouro$/, "");
|
|
619
|
+
const pendingRoot = path.join(this.bundlesRoot, bundleDir.name, "state", "pending");
|
|
620
|
+
if (!fs.existsSync(pendingRoot))
|
|
621
|
+
continue;
|
|
622
|
+
let friendDirs;
|
|
623
|
+
try {
|
|
624
|
+
friendDirs = fs.readdirSync(pendingRoot, { withFileTypes: true });
|
|
625
|
+
}
|
|
626
|
+
catch {
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
for (const friendDir of friendDirs) {
|
|
630
|
+
if (!friendDir.isDirectory())
|
|
631
|
+
continue;
|
|
632
|
+
const friendPath = path.join(pendingRoot, friendDir.name);
|
|
633
|
+
let channelDirs;
|
|
634
|
+
try {
|
|
635
|
+
channelDirs = fs.readdirSync(friendPath, { withFileTypes: true });
|
|
636
|
+
}
|
|
637
|
+
catch {
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
for (const channelDir of channelDirs) {
|
|
641
|
+
if (!channelDir.isDirectory())
|
|
642
|
+
continue;
|
|
643
|
+
if (!OuroDaemon.ALWAYS_ON_SENSES.has(channelDir.name))
|
|
644
|
+
continue;
|
|
645
|
+
const channelPath = path.join(friendPath, channelDir.name);
|
|
646
|
+
let keyDirs;
|
|
647
|
+
try {
|
|
648
|
+
keyDirs = fs.readdirSync(channelPath, { withFileTypes: true });
|
|
649
|
+
}
|
|
650
|
+
catch {
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
for (const keyDir of keyDirs) {
|
|
654
|
+
if (!keyDir.isDirectory())
|
|
655
|
+
continue;
|
|
656
|
+
const leafDir = path.join(channelPath, keyDir.name);
|
|
657
|
+
const messages = (0, pending_1.drainPending)(leafDir);
|
|
658
|
+
for (const msg of messages) {
|
|
659
|
+
try {
|
|
660
|
+
await this.router.send({
|
|
661
|
+
from: msg.from,
|
|
662
|
+
to: agentName,
|
|
663
|
+
content: msg.content,
|
|
664
|
+
priority: "normal",
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
catch {
|
|
668
|
+
// Best-effort delivery — log and continue
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (messages.length > 0) {
|
|
672
|
+
(0, runtime_1.emitNervesEvent)({
|
|
673
|
+
component: "daemon",
|
|
674
|
+
event: "daemon.startup_sense_drain",
|
|
675
|
+
message: "drained pending sense messages on startup",
|
|
676
|
+
meta: {
|
|
677
|
+
agent: agentName,
|
|
678
|
+
channel: channelDir.name,
|
|
679
|
+
friendId: friendDir.name,
|
|
680
|
+
key: keyDir.name,
|
|
681
|
+
count: messages.length,
|
|
682
|
+
},
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
234
690
|
async stop() {
|
|
691
|
+
// Must be named `_end` (not `_stop`) to satisfy the nerves audit's
|
|
692
|
+
// start/end pairing rule — see src/nerves/coverage/audit-rules.ts.
|
|
693
|
+
// This is the counterpart to `daemon.server_start` emitted at line 480.
|
|
235
694
|
(0, runtime_1.emitNervesEvent)({
|
|
236
695
|
component: "daemon",
|
|
237
|
-
event: "daemon.
|
|
696
|
+
event: "daemon.server_end",
|
|
238
697
|
message: "stopping daemon server",
|
|
239
698
|
meta: { socketPath: this.socketPath },
|
|
240
699
|
});
|
|
241
700
|
(0, update_checker_1.stopUpdateChecker)();
|
|
701
|
+
(0, mcp_manager_1.shutdownSharedMcpManager)();
|
|
242
702
|
this.scheduler.stop?.();
|
|
243
703
|
await this.processManager.stopAll();
|
|
244
704
|
await this.senseManager?.stopAll();
|
|
@@ -248,6 +708,10 @@ class OuroDaemon {
|
|
|
248
708
|
});
|
|
249
709
|
this.server = null;
|
|
250
710
|
}
|
|
711
|
+
if (this.outlookServer) {
|
|
712
|
+
await this.outlookServer.stop();
|
|
713
|
+
this.outlookServer = null;
|
|
714
|
+
}
|
|
251
715
|
if (fs.existsSync(this.socketPath)) {
|
|
252
716
|
fs.unlinkSync(this.socketPath);
|
|
253
717
|
}
|
|
@@ -272,6 +736,27 @@ class OuroDaemon {
|
|
|
272
736
|
message: "handling daemon command",
|
|
273
737
|
meta: { kind: command.kind },
|
|
274
738
|
});
|
|
739
|
+
try {
|
|
740
|
+
return await this.handleCommandInner(command);
|
|
741
|
+
/* v8 ignore start — command error catch tested in daemon-command-error.test; instanceof branches defensive @preserve */
|
|
742
|
+
}
|
|
743
|
+
catch (error) {
|
|
744
|
+
(0, runtime_1.emitNervesEvent)({
|
|
745
|
+
level: "error",
|
|
746
|
+
component: "daemon",
|
|
747
|
+
event: "daemon.command_error",
|
|
748
|
+
message: "unexpected error handling daemon command",
|
|
749
|
+
meta: {
|
|
750
|
+
kind: command.kind,
|
|
751
|
+
error: error instanceof Error ? error.message : String(error),
|
|
752
|
+
stack: error instanceof Error ? error.stack ?? null : null,
|
|
753
|
+
},
|
|
754
|
+
});
|
|
755
|
+
throw error;
|
|
756
|
+
}
|
|
757
|
+
/* v8 ignore stop */
|
|
758
|
+
}
|
|
759
|
+
async handleCommandInner(command) {
|
|
275
760
|
switch (command.kind) {
|
|
276
761
|
case "daemon.start":
|
|
277
762
|
await this.start();
|
|
@@ -280,21 +765,7 @@ class OuroDaemon {
|
|
|
280
765
|
await this.stop();
|
|
281
766
|
return { ok: true, message: "daemon stopped" };
|
|
282
767
|
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
|
-
};
|
|
768
|
+
const data = this.buildStatusPayload();
|
|
298
769
|
return {
|
|
299
770
|
ok: true,
|
|
300
771
|
summary: formatStatusSummary(data),
|
|
@@ -311,7 +782,7 @@ class OuroDaemon {
|
|
|
311
782
|
ok: true,
|
|
312
783
|
summary: "logs: use `ouro logs` to tail daemon and agent output",
|
|
313
784
|
message: "log streaming available via ouro logs",
|
|
314
|
-
data: { logDir: "
|
|
785
|
+
data: { logDir: "~/AgentBundles/<agent>.ouro/state/daemon/logs" },
|
|
315
786
|
};
|
|
316
787
|
case "agent.start":
|
|
317
788
|
await this.processManager.startAgent(command.agent);
|
|
@@ -322,6 +793,35 @@ class OuroDaemon {
|
|
|
322
793
|
case "agent.restart":
|
|
323
794
|
await this.processManager.restartAgent?.(command.agent);
|
|
324
795
|
return { ok: true, message: `restarted ${command.agent}` };
|
|
796
|
+
case "agent.ask":
|
|
797
|
+
return (0, agent_service_1.handleAgentAsk)(command);
|
|
798
|
+
case "agent.status":
|
|
799
|
+
return (0, agent_service_1.handleAgentStatus)(command);
|
|
800
|
+
case "agent.catchup":
|
|
801
|
+
return (0, agent_service_1.handleAgentCatchup)(command);
|
|
802
|
+
case "agent.delegate":
|
|
803
|
+
return (0, agent_service_1.handleAgentDelegate)(command);
|
|
804
|
+
case "agent.getContext":
|
|
805
|
+
return (0, agent_service_1.handleAgentGetContext)(command);
|
|
806
|
+
case "agent.searchMemory":
|
|
807
|
+
return (0, agent_service_1.handleAgentSearchMemory)(command);
|
|
808
|
+
case "agent.getTask":
|
|
809
|
+
return (0, agent_service_1.handleAgentGetTask)(command);
|
|
810
|
+
case "agent.checkScope":
|
|
811
|
+
return (0, agent_service_1.handleAgentCheckScope)(command);
|
|
812
|
+
case "agent.requestDecision":
|
|
813
|
+
return (0, agent_service_1.handleAgentRequestDecision)(command);
|
|
814
|
+
case "agent.checkGuidance":
|
|
815
|
+
return (0, agent_service_1.handleAgentCheckGuidance)(command);
|
|
816
|
+
case "agent.reportProgress":
|
|
817
|
+
return (0, agent_service_1.handleAgentReportProgress)(command);
|
|
818
|
+
case "agent.reportBlocker":
|
|
819
|
+
return (0, agent_service_1.handleAgentReportBlocker)(command);
|
|
820
|
+
case "agent.reportComplete":
|
|
821
|
+
return (0, agent_service_1.handleAgentReportComplete)(command);
|
|
822
|
+
case "agent.senseTurn":
|
|
823
|
+
return handleAgentSenseTurn(command);
|
|
824
|
+
/* v8 ignore stop */
|
|
325
825
|
case "cron.list": {
|
|
326
826
|
const jobs = this.scheduler.listJobs();
|
|
327
827
|
const summary = jobs.length === 0
|
|
@@ -353,6 +853,13 @@ class OuroDaemon {
|
|
|
353
853
|
data: messages,
|
|
354
854
|
};
|
|
355
855
|
}
|
|
856
|
+
case "inner.wake":
|
|
857
|
+
await this.processManager.startAgent(command.agent);
|
|
858
|
+
this.processManager.sendToAgent?.(command.agent, { type: "message" });
|
|
859
|
+
return {
|
|
860
|
+
ok: true,
|
|
861
|
+
message: `woke inner dialog for ${command.agent}`,
|
|
862
|
+
};
|
|
356
863
|
case "chat.connect":
|
|
357
864
|
await this.processManager.startAgent(command.agent);
|
|
358
865
|
return {
|
|
@@ -375,6 +882,35 @@ class OuroDaemon {
|
|
|
375
882
|
data: receipt,
|
|
376
883
|
};
|
|
377
884
|
}
|
|
885
|
+
case "habit.poke": {
|
|
886
|
+
this.processManager.sendToAgent?.(command.agent, { type: "habit", habitName: command.habitName });
|
|
887
|
+
return {
|
|
888
|
+
ok: true,
|
|
889
|
+
message: `poked habit ${command.habitName} for ${command.agent}`,
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
case "mcp.list": {
|
|
893
|
+
const mcpManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
894
|
+
if (!mcpManager) {
|
|
895
|
+
return { ok: true, data: [], message: "no MCP servers configured" };
|
|
896
|
+
}
|
|
897
|
+
return { ok: true, data: mcpManager.listAllTools() };
|
|
898
|
+
}
|
|
899
|
+
case "mcp.call": {
|
|
900
|
+
const mcpCallManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
901
|
+
if (!mcpCallManager) {
|
|
902
|
+
return { ok: false, error: "no MCP servers configured" };
|
|
903
|
+
}
|
|
904
|
+
try {
|
|
905
|
+
const parsedArgs = command.args ? JSON.parse(command.args) : {};
|
|
906
|
+
const result = await mcpCallManager.callTool(command.server, command.tool, parsedArgs);
|
|
907
|
+
return { ok: true, data: result };
|
|
908
|
+
}
|
|
909
|
+
catch (error) {
|
|
910
|
+
/* v8 ignore next -- defensive: callTool errors are always Error instances @preserve */
|
|
911
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
912
|
+
}
|
|
913
|
+
}
|
|
378
914
|
case "hatch.start":
|
|
379
915
|
return {
|
|
380
916
|
ok: true,
|