@ouro.bot/cli 0.1.0-alpha.16 → 0.1.0-alpha.160
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/AdoptionSpecialist.ouro/agent.json +3 -2
- package/AdoptionSpecialist.ouro/psyche/SOUL.md +3 -3
- package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
- package/README.md +186 -191
- package/changelog.json +1081 -0
- package/dist/heart/active-work.js +633 -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 +105 -0
- package/dist/heart/config.js +40 -30
- package/dist/heart/core.js +608 -123
- package/dist/heart/cross-chat-delivery.js +146 -0
- package/dist/heart/daemon/agent-discovery.js +81 -0
- package/dist/heart/daemon/agent-service.js +360 -0
- package/dist/heart/daemon/auth-flow.js +477 -0
- package/dist/heart/daemon/cadence.js +70 -0
- package/dist/heart/daemon/daemon-cli.js +2467 -205
- package/dist/heart/daemon/daemon-entry.js +131 -4
- package/dist/heart/daemon/daemon-health.js +136 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
- package/dist/heart/daemon/daemon-tombstone.js +123 -0
- package/dist/heart/daemon/daemon.js +434 -17
- package/dist/heart/daemon/habit-migration.js +181 -0
- package/dist/heart/daemon/habit-parser.js +119 -0
- package/dist/heart/daemon/habit-scheduler.js +369 -0
- package/dist/heart/daemon/hatch-animation.js +10 -3
- package/dist/heart/daemon/hatch-flow.js +30 -111
- package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
- package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
- package/dist/heart/daemon/inner-status.js +89 -0
- package/dist/heart/daemon/launchd.js +159 -0
- package/dist/heart/daemon/log-tailer.js +4 -3
- package/dist/heart/daemon/mcp-server.js +591 -0
- 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-global-installer.js +128 -0
- package/dist/heart/daemon/ouro-path-installer.js +78 -34
- package/dist/heart/daemon/ouro-version-manager.js +171 -0
- package/dist/heart/daemon/outlook-http.js +307 -0
- package/dist/heart/daemon/outlook-read.js +1281 -0
- package/dist/heart/daemon/outlook-render.js +1032 -0
- package/dist/heart/daemon/outlook-types.js +7 -0
- package/dist/heart/daemon/outlook-view.js +194 -0
- package/dist/heart/daemon/process-manager.js +75 -0
- package/dist/heart/daemon/run-hooks.js +39 -0
- package/dist/heart/daemon/runtime-logging.js +58 -15
- package/dist/heart/daemon/runtime-metadata.js +219 -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 +50 -2
- 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 +202 -0
- package/dist/heart/daemon/specialist-orchestrator.js +2 -2
- package/dist/heart/daemon/specialist-prompt.js +13 -8
- package/dist/heart/daemon/specialist-tools.js +53 -4
- package/dist/heart/daemon/staged-restart.js +114 -0
- package/dist/heart/daemon/task-scheduler.js +3 -25
- package/dist/heart/daemon/thoughts.js +507 -0
- package/dist/heart/daemon/update-checker.js +111 -0
- package/dist/heart/daemon/update-hooks.js +138 -0
- package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
- package/dist/heart/delegation.js +62 -0
- package/dist/heart/identity.js +136 -55
- package/dist/heart/kicks.js +2 -20
- package/dist/heart/migrate-config.js +127 -0
- package/dist/heart/model-capabilities.js +48 -0
- package/dist/heart/obligations.js +197 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/provider-failover.js +88 -0
- package/dist/heart/provider-ping.js +172 -0
- package/dist/heart/providers/anthropic-token.js +163 -0
- package/dist/heart/providers/anthropic.js +196 -36
- package/dist/heart/providers/azure.js +116 -10
- package/dist/heart/providers/github-copilot.js +157 -0
- package/dist/heart/providers/minimax.js +33 -3
- package/dist/heart/providers/openai-codex.js +51 -16
- package/dist/heart/session-activity.js +172 -0
- package/dist/heart/session-recall.js +216 -0
- package/dist/heart/streaming.js +117 -33
- package/dist/heart/target-resolution.js +127 -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-coordinator.js +28 -0
- package/dist/mind/associative-recall.js +122 -32
- package/dist/mind/bundle-manifest.js +14 -0
- package/dist/mind/context.js +125 -14
- package/dist/mind/{memory.js → diary.js} +70 -56
- 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/store-file.js +19 -0
- 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/obligations.js +134 -0
- package/dist/mind/pending.js +76 -9
- package/dist/mind/phrases.js +1 -0
- package/dist/mind/prompt.js +651 -91
- package/dist/mind/token-estimate.js +8 -12
- package/dist/nerves/cli-logging.js +15 -2
- package/dist/nerves/coverage/run-artifacts.js +1 -1
- package/dist/nerves/event-buffer.js +111 -0
- package/dist/nerves/index.js +63 -3
- package/dist/nerves/observation.js +20 -0
- package/dist/nerves/runtime.js +5 -1
- package/dist/repertoire/ado-semantic.js +6 -0
- package/dist/repertoire/coding/codex-jsonl.js +64 -0
- package/dist/repertoire/coding/context-pack.js +254 -0
- package/dist/repertoire/coding/feedback.js +301 -0
- package/dist/repertoire/coding/index.js +4 -1
- package/dist/repertoire/coding/manager.js +210 -4
- package/dist/repertoire/coding/spawner.js +58 -12
- package/dist/repertoire/coding/tools.js +176 -4
- package/dist/repertoire/guardrails.js +291 -0
- package/dist/repertoire/mcp-client.js +254 -0
- package/dist/repertoire/mcp-manager.js +198 -0
- package/dist/repertoire/skills.js +14 -23
- 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 +992 -273
- package/dist/repertoire/tools-bluebubbles.js +94 -0
- package/dist/repertoire/tools-github.js +1 -6
- package/dist/repertoire/tools-teams.js +12 -59
- package/dist/repertoire/tools.js +281 -101
- 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-client.js +258 -5
- package/dist/senses/bluebubbles-entry.js +2 -0
- package/dist/senses/bluebubbles-inbound-log.js +109 -0
- package/dist/senses/bluebubbles-media.js +339 -0
- package/dist/senses/bluebubbles-model.js +12 -4
- package/dist/senses/bluebubbles-mutation-log.js +45 -5
- package/dist/senses/bluebubbles-runtime-state.js +109 -0
- package/dist/senses/bluebubbles-session-cleanup.js +72 -0
- package/dist/senses/bluebubbles.js +1040 -45
- package/dist/senses/cli-entry.js +1 -1
- package/dist/senses/cli-layout.js +187 -0
- package/dist/senses/cli.js +419 -152
- package/dist/senses/commands.js +38 -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 +592 -84
- package/dist/senses/pipeline.js +502 -0
- package/dist/senses/shared-turn.js +196 -0
- package/dist/senses/surface-tool.js +95 -0
- package/dist/senses/teams.js +667 -120
- package/dist/senses/trust-gate.js +112 -2
- package/package.json +12 -4
- package/skills/configure-dev-tools.md +81 -0
- package/subagents/README.md +4 -70
- package/dist/heart/daemon/subagent-installer.js +0 -134
- package/subagents/work-doer.md +0 -233
- package/subagents/work-merger.md +0 -624
- package/subagents/work-planner.md +0 -373
|
@@ -34,11 +34,104 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.OuroDaemon = void 0;
|
|
37
|
+
exports.killOrphanProcesses = killOrphanProcesses;
|
|
38
|
+
exports.writePidfile = writePidfile;
|
|
37
39
|
const fs = __importStar(require("fs"));
|
|
38
40
|
const net = __importStar(require("net"));
|
|
41
|
+
const os = __importStar(require("os"));
|
|
39
42
|
const path = __importStar(require("path"));
|
|
40
43
|
const identity_1 = require("../identity");
|
|
41
44
|
const runtime_1 = require("../../nerves/runtime");
|
|
45
|
+
const runtime_metadata_1 = require("./runtime-metadata");
|
|
46
|
+
const runtime_mode_1 = require("./runtime-mode");
|
|
47
|
+
const update_hooks_1 = require("./update-hooks");
|
|
48
|
+
const bundle_meta_1 = require("./hooks/bundle-meta");
|
|
49
|
+
const agent_config_v2_1 = require("./hooks/agent-config-v2");
|
|
50
|
+
const bundle_manifest_1 = require("../../mind/bundle-manifest");
|
|
51
|
+
const update_checker_1 = require("./update-checker");
|
|
52
|
+
const staged_restart_1 = require("./staged-restart");
|
|
53
|
+
const child_process_1 = require("child_process");
|
|
54
|
+
const pending_1 = require("../../mind/pending");
|
|
55
|
+
const agent_service_1 = require("./agent-service");
|
|
56
|
+
const channel_1 = require("../../mind/friends/channel");
|
|
57
|
+
const mcp_manager_1 = require("../../repertoire/mcp-manager");
|
|
58
|
+
const outlook_http_1 = require("./outlook-http");
|
|
59
|
+
const outlook_types_1 = require("./outlook-types");
|
|
60
|
+
const outlook_read_1 = require("./outlook-read");
|
|
61
|
+
const outlook_view_1 = require("./outlook-view");
|
|
62
|
+
const PIDFILE_PATH = path.join(os.homedir(), ".ouro-cli", "daemon.pids");
|
|
63
|
+
/**
|
|
64
|
+
* Kill all ouro processes from the previous daemon instance using the pidfile.
|
|
65
|
+
* On startup, reads PIDs from ~/.ouro-cli/daemon.pids, kills them all, then
|
|
66
|
+
* deletes the file. The new daemon writes its own PIDs after spawning.
|
|
67
|
+
*
|
|
68
|
+
* Falls back to ps-based scanning if the pidfile doesn't exist (first run
|
|
69
|
+
* or manual cleanup).
|
|
70
|
+
*/
|
|
71
|
+
/* v8 ignore start -- process lifecycle: uses kill/ps, tested via deployment @preserve */
|
|
72
|
+
function killOrphanProcesses() {
|
|
73
|
+
try {
|
|
74
|
+
let pidsToKill = [];
|
|
75
|
+
// Primary: read pidfile from previous daemon
|
|
76
|
+
try {
|
|
77
|
+
const raw = fs.readFileSync(PIDFILE_PATH, "utf-8");
|
|
78
|
+
pidsToKill = raw.split("\n").map((s) => parseInt(s.trim(), 10)).filter((n) => !isNaN(n) && n !== process.pid);
|
|
79
|
+
fs.unlinkSync(PIDFILE_PATH);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// No pidfile — fall back to ps scan
|
|
83
|
+
}
|
|
84
|
+
// Fallback: scan ps for any ouro entry processes we missed
|
|
85
|
+
if (pidsToKill.length === 0) {
|
|
86
|
+
try {
|
|
87
|
+
const result = (0, child_process_1.execSync)("ps -eo pid,command", { encoding: "utf-8", timeout: 5000 });
|
|
88
|
+
for (const line of result.split("\n")) {
|
|
89
|
+
if (!line.includes("agent-entry.js") && !line.includes("daemon-entry.js") && !line.includes("-entry.js --agent"))
|
|
90
|
+
continue;
|
|
91
|
+
const pid = parseInt(line.trim(), 10);
|
|
92
|
+
if (!isNaN(pid) && pid !== process.pid)
|
|
93
|
+
pidsToKill.push(pid);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch { /* ps failed — best effort */ }
|
|
97
|
+
}
|
|
98
|
+
if (pidsToKill.length > 0) {
|
|
99
|
+
for (const pid of pidsToKill) {
|
|
100
|
+
try {
|
|
101
|
+
process.kill(pid, "SIGTERM");
|
|
102
|
+
}
|
|
103
|
+
catch { /* already exited */ }
|
|
104
|
+
}
|
|
105
|
+
(0, runtime_1.emitNervesEvent)({
|
|
106
|
+
component: "daemon",
|
|
107
|
+
event: "daemon.orphan_cleanup",
|
|
108
|
+
message: `killed ${pidsToKill.length} orphaned ouro processes`,
|
|
109
|
+
meta: { pids: pidsToKill },
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
(0, runtime_1.emitNervesEvent)({
|
|
115
|
+
level: "warn",
|
|
116
|
+
component: "daemon",
|
|
117
|
+
event: "daemon.orphan_cleanup_error",
|
|
118
|
+
message: "failed to clean up orphaned ouro processes",
|
|
119
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Write all managed PIDs (daemon + children) to the pidfile.
|
|
125
|
+
* Called after all agents and senses are spawned.
|
|
126
|
+
*/
|
|
127
|
+
function writePidfile(extraPids = []) {
|
|
128
|
+
try {
|
|
129
|
+
const pids = [process.pid, ...extraPids].filter(Boolean);
|
|
130
|
+
fs.mkdirSync(path.dirname(PIDFILE_PATH), { recursive: true });
|
|
131
|
+
fs.writeFileSync(PIDFILE_PATH, pids.join("\n") + "\n", "utf-8");
|
|
132
|
+
}
|
|
133
|
+
catch { /* best effort */ }
|
|
134
|
+
}
|
|
42
135
|
function buildWorkerRows(snapshots) {
|
|
43
136
|
return snapshots.map((snapshot) => ({
|
|
44
137
|
agent: snapshot.name,
|
|
@@ -47,6 +140,8 @@ function buildWorkerRows(snapshots) {
|
|
|
47
140
|
pid: snapshot.pid,
|
|
48
141
|
restartCount: snapshot.restartCount,
|
|
49
142
|
startedAt: snapshot.startedAt,
|
|
143
|
+
lastExitCode: snapshot.lastExitCode ?? null,
|
|
144
|
+
lastSignal: snapshot.lastSignal ?? null,
|
|
50
145
|
}));
|
|
51
146
|
}
|
|
52
147
|
function formatStatusSummary(payload) {
|
|
@@ -87,7 +182,9 @@ class OuroDaemon {
|
|
|
87
182
|
router;
|
|
88
183
|
senseManager;
|
|
89
184
|
bundlesRoot;
|
|
185
|
+
mode;
|
|
90
186
|
server = null;
|
|
187
|
+
outlookServer = null;
|
|
91
188
|
constructor(options) {
|
|
92
189
|
this.socketPath = options.socketPath;
|
|
93
190
|
this.processManager = options.processManager;
|
|
@@ -96,6 +193,28 @@ class OuroDaemon {
|
|
|
96
193
|
this.router = options.router;
|
|
97
194
|
this.senseManager = options.senseManager ?? null;
|
|
98
195
|
this.bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
|
|
196
|
+
this.mode = options.mode ?? "production";
|
|
197
|
+
}
|
|
198
|
+
buildStatusPayload() {
|
|
199
|
+
const snapshots = this.processManager.listAgentSnapshots();
|
|
200
|
+
const workers = buildWorkerRows(snapshots);
|
|
201
|
+
const senses = this.senseManager?.listSenseRows() ?? [];
|
|
202
|
+
const repoRoot = (0, identity_1.getRepoRoot)();
|
|
203
|
+
return {
|
|
204
|
+
overview: {
|
|
205
|
+
daemon: "running",
|
|
206
|
+
health: workers.every((worker) => worker.status === "running") ? "ok" : "warn",
|
|
207
|
+
socketPath: this.socketPath,
|
|
208
|
+
outlookUrl: `${this.outlookServer?.origin ?? "http://127.0.0.1:0"}/outlook`,
|
|
209
|
+
...(0, runtime_metadata_1.getRuntimeMetadata)(),
|
|
210
|
+
workerCount: workers.length,
|
|
211
|
+
senseCount: senses.length,
|
|
212
|
+
entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
|
|
213
|
+
mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
|
|
214
|
+
},
|
|
215
|
+
workers,
|
|
216
|
+
senses,
|
|
217
|
+
};
|
|
99
218
|
}
|
|
100
219
|
async start() {
|
|
101
220
|
if (this.server)
|
|
@@ -106,23 +225,143 @@ class OuroDaemon {
|
|
|
106
225
|
message: "starting daemon server",
|
|
107
226
|
meta: { socketPath: this.socketPath },
|
|
108
227
|
});
|
|
228
|
+
// Register update hooks and apply pending updates before starting agents
|
|
229
|
+
(0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
|
|
230
|
+
(0, update_hooks_1.registerUpdateHook)(agent_config_v2_1.agentConfigV2Hook);
|
|
231
|
+
const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
|
|
232
|
+
await (0, update_hooks_1.applyPendingUpdates)(this.bundlesRoot, currentVersion);
|
|
233
|
+
// Start periodic update checker (polls npm registry every 30 minutes)
|
|
234
|
+
// Skip in dev mode — dev builds should not auto-update from npm
|
|
235
|
+
const bundlesRoot = this.bundlesRoot;
|
|
236
|
+
if (this.mode === "dev") {
|
|
237
|
+
(0, runtime_1.emitNervesEvent)({
|
|
238
|
+
component: "daemon",
|
|
239
|
+
event: "daemon.update_checker_skip",
|
|
240
|
+
message: "skipping update checker in dev mode",
|
|
241
|
+
meta: { reason: "dev mode" },
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
const daemon = this;
|
|
246
|
+
(0, update_checker_1.startUpdateChecker)({
|
|
247
|
+
currentVersion,
|
|
248
|
+
deps: {
|
|
249
|
+
distTag: "alpha",
|
|
250
|
+
fetchRegistryJson: /* v8 ignore next -- integration: real HTTP fetch @preserve */ async () => {
|
|
251
|
+
const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
|
|
252
|
+
return res.json();
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
onUpdate: /* v8 ignore start -- integration: real npm install + process spawn @preserve */ async (result) => {
|
|
256
|
+
if (!result.latestVersion)
|
|
257
|
+
return;
|
|
258
|
+
await (0, staged_restart_1.performStagedRestart)(result.latestVersion, {
|
|
259
|
+
execSync: (cmd) => (0, child_process_1.execSync)(cmd, { stdio: "inherit" }),
|
|
260
|
+
spawnSync: child_process_1.spawnSync,
|
|
261
|
+
resolveNewCodePath: (_version) => {
|
|
262
|
+
try {
|
|
263
|
+
const resolved = (0, child_process_1.execSync)(`node -e "console.log(require.resolve('@ouro.bot/cli/package.json'))"`, { encoding: "utf-8" }).trim();
|
|
264
|
+
return resolved ? path.dirname(resolved) : null;
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
gracefulShutdown: () => daemon.stop(),
|
|
271
|
+
nodePath: process.execPath,
|
|
272
|
+
bundlesRoot,
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
/* v8 ignore stop */
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
// Pre-initialize MCP connections so they're ready for the first command (non-blocking)
|
|
279
|
+
/* v8 ignore next -- catch callback: getSharedMcpManager logs errors internally @preserve */
|
|
280
|
+
(0, mcp_manager_1.getSharedMcpManager)().catch(() => { });
|
|
281
|
+
/* v8 ignore start -- orphan cleanup + pidfile: calls process management functions @preserve */
|
|
282
|
+
killOrphanProcesses();
|
|
283
|
+
/* v8 ignore stop */
|
|
109
284
|
await this.processManager.startAutoStartAgents();
|
|
110
285
|
await this.senseManager?.startAutoStartSenses();
|
|
286
|
+
// Write all managed PIDs to disk so the next daemon can clean up
|
|
287
|
+
/* v8 ignore start -- pidfile write: collects PIDs from process managers @preserve */
|
|
288
|
+
const agentPids = this.processManager.listAgentSnapshots().map((s) => s.pid).filter((p) => p !== null);
|
|
289
|
+
const sensePids = this.senseManager?.listManagedPids?.() ?? [];
|
|
290
|
+
writePidfile([...agentPids, ...sensePids]);
|
|
291
|
+
/* v8 ignore stop */
|
|
111
292
|
this.scheduler.start?.();
|
|
112
293
|
await this.scheduler.reconcile?.();
|
|
113
294
|
await this.drainPendingBundleMessages();
|
|
295
|
+
await this.drainPendingSenseMessages();
|
|
296
|
+
/* v8 ignore start — Outlook server startup, tested via outlook-http.test.ts */
|
|
297
|
+
if (!this.outlookServer) {
|
|
298
|
+
this.outlookServer = await (0, outlook_http_1.startOutlookHttpServer)({
|
|
299
|
+
host: "127.0.0.1",
|
|
300
|
+
port: outlook_types_1.OUTLOOK_DEFAULT_PORT,
|
|
301
|
+
readMachineState: () => (0, outlook_read_1.readOutlookMachineState)({ bundlesRoot: this.bundlesRoot }),
|
|
302
|
+
readMachineView: ({ machine }) => {
|
|
303
|
+
const overview = this.buildStatusPayload().overview;
|
|
304
|
+
return (0, outlook_view_1.buildOutlookMachineView)({
|
|
305
|
+
machine,
|
|
306
|
+
daemon: {
|
|
307
|
+
status: overview.daemon,
|
|
308
|
+
health: overview.health,
|
|
309
|
+
mode: overview.mode,
|
|
310
|
+
socketPath: overview.socketPath,
|
|
311
|
+
outlookUrl: overview.outlookUrl,
|
|
312
|
+
entryPath: overview.entryPath,
|
|
313
|
+
workerCount: overview.workerCount,
|
|
314
|
+
senseCount: overview.senseCount,
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
readAgentState: (agentName) => (0, outlook_read_1.readOutlookAgentState)(agentName, { bundlesRoot: this.bundlesRoot }),
|
|
319
|
+
readAgentView: (agentName) => {
|
|
320
|
+
const agent = (0, outlook_read_1.readOutlookAgentState)(agentName, { bundlesRoot: this.bundlesRoot });
|
|
321
|
+
return (0, outlook_view_1.buildOutlookAgentView)({
|
|
322
|
+
agent,
|
|
323
|
+
viewer: { kind: "human" },
|
|
324
|
+
});
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/* v8 ignore stop */
|
|
114
329
|
if (fs.existsSync(this.socketPath)) {
|
|
115
330
|
fs.unlinkSync(this.socketPath);
|
|
116
331
|
}
|
|
117
332
|
this.server = net.createServer((connection) => {
|
|
118
333
|
let raw = "";
|
|
119
334
|
let responded = false;
|
|
335
|
+
/* v8 ignore start — connection error handler requires real socket error @preserve */
|
|
336
|
+
connection.on("error", (err) => {
|
|
337
|
+
(0, runtime_1.emitNervesEvent)({
|
|
338
|
+
level: "warn",
|
|
339
|
+
component: "daemon",
|
|
340
|
+
event: "daemon.connection_error",
|
|
341
|
+
message: "socket connection error",
|
|
342
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
/* v8 ignore stop */
|
|
120
346
|
const flushResponse = async () => {
|
|
121
347
|
if (responded)
|
|
122
348
|
return;
|
|
123
349
|
responded = true;
|
|
124
350
|
const response = await this.handleRawPayload(raw);
|
|
125
|
-
|
|
351
|
+
try {
|
|
352
|
+
connection.end(response);
|
|
353
|
+
/* v8 ignore start — EPIPE catch requires real socket disconnect @preserve */
|
|
354
|
+
}
|
|
355
|
+
catch (err) {
|
|
356
|
+
(0, runtime_1.emitNervesEvent)({
|
|
357
|
+
level: "warn",
|
|
358
|
+
component: "daemon",
|
|
359
|
+
event: "daemon.connection_end_error",
|
|
360
|
+
message: "failed to send response to client (EPIPE)",
|
|
361
|
+
meta: { error: err instanceof Error ? err.message : String(err) },
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
/* v8 ignore stop */
|
|
126
365
|
};
|
|
127
366
|
connection.on("data", (chunk) => {
|
|
128
367
|
raw += chunk.toString("utf-8");
|
|
@@ -135,7 +374,22 @@ class OuroDaemon {
|
|
|
135
374
|
const server = this.server;
|
|
136
375
|
await new Promise((resolve, reject) => {
|
|
137
376
|
server.once("error", reject);
|
|
138
|
-
server.listen(this.socketPath, () =>
|
|
377
|
+
server.listen(this.socketPath, () => {
|
|
378
|
+
// Replace the one-time error listener with a persistent one after successful listen
|
|
379
|
+
server.removeAllListeners("error");
|
|
380
|
+
/* v8 ignore start — server error after listen requires real socket race condition @preserve */
|
|
381
|
+
server.on("error", (err) => {
|
|
382
|
+
(0, runtime_1.emitNervesEvent)({
|
|
383
|
+
level: "error",
|
|
384
|
+
component: "daemon",
|
|
385
|
+
event: "daemon.server_error",
|
|
386
|
+
message: "daemon server error after listen",
|
|
387
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
/* v8 ignore stop */
|
|
391
|
+
resolve();
|
|
392
|
+
});
|
|
139
393
|
});
|
|
140
394
|
}
|
|
141
395
|
async drainPendingBundleMessages() {
|
|
@@ -186,6 +440,93 @@ class OuroDaemon {
|
|
|
186
440
|
fs.writeFileSync(pendingPath, next, "utf-8");
|
|
187
441
|
}
|
|
188
442
|
}
|
|
443
|
+
/** Drains per-sense pending dirs for always-on senses across all agents. */
|
|
444
|
+
static ALWAYS_ON_SENSES = new Set((0, channel_1.getAlwaysOnSenseNames)());
|
|
445
|
+
async drainPendingSenseMessages() {
|
|
446
|
+
if (!fs.existsSync(this.bundlesRoot))
|
|
447
|
+
return;
|
|
448
|
+
let bundleDirs;
|
|
449
|
+
try {
|
|
450
|
+
bundleDirs = fs.readdirSync(this.bundlesRoot, { withFileTypes: true });
|
|
451
|
+
}
|
|
452
|
+
catch {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
for (const bundleDir of bundleDirs) {
|
|
456
|
+
if (!bundleDir.isDirectory() || !bundleDir.name.endsWith(".ouro"))
|
|
457
|
+
continue;
|
|
458
|
+
const agentName = bundleDir.name.replace(/\.ouro$/, "");
|
|
459
|
+
const pendingRoot = path.join(this.bundlesRoot, bundleDir.name, "state", "pending");
|
|
460
|
+
if (!fs.existsSync(pendingRoot))
|
|
461
|
+
continue;
|
|
462
|
+
let friendDirs;
|
|
463
|
+
try {
|
|
464
|
+
friendDirs = fs.readdirSync(pendingRoot, { withFileTypes: true });
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
for (const friendDir of friendDirs) {
|
|
470
|
+
if (!friendDir.isDirectory())
|
|
471
|
+
continue;
|
|
472
|
+
const friendPath = path.join(pendingRoot, friendDir.name);
|
|
473
|
+
let channelDirs;
|
|
474
|
+
try {
|
|
475
|
+
channelDirs = fs.readdirSync(friendPath, { withFileTypes: true });
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
for (const channelDir of channelDirs) {
|
|
481
|
+
if (!channelDir.isDirectory())
|
|
482
|
+
continue;
|
|
483
|
+
if (!OuroDaemon.ALWAYS_ON_SENSES.has(channelDir.name))
|
|
484
|
+
continue;
|
|
485
|
+
const channelPath = path.join(friendPath, channelDir.name);
|
|
486
|
+
let keyDirs;
|
|
487
|
+
try {
|
|
488
|
+
keyDirs = fs.readdirSync(channelPath, { withFileTypes: true });
|
|
489
|
+
}
|
|
490
|
+
catch {
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
for (const keyDir of keyDirs) {
|
|
494
|
+
if (!keyDir.isDirectory())
|
|
495
|
+
continue;
|
|
496
|
+
const leafDir = path.join(channelPath, keyDir.name);
|
|
497
|
+
const messages = (0, pending_1.drainPending)(leafDir);
|
|
498
|
+
for (const msg of messages) {
|
|
499
|
+
try {
|
|
500
|
+
await this.router.send({
|
|
501
|
+
from: msg.from,
|
|
502
|
+
to: agentName,
|
|
503
|
+
content: msg.content,
|
|
504
|
+
priority: "normal",
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
catch {
|
|
508
|
+
// Best-effort delivery — log and continue
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (messages.length > 0) {
|
|
512
|
+
(0, runtime_1.emitNervesEvent)({
|
|
513
|
+
component: "daemon",
|
|
514
|
+
event: "daemon.startup_sense_drain",
|
|
515
|
+
message: "drained pending sense messages on startup",
|
|
516
|
+
meta: {
|
|
517
|
+
agent: agentName,
|
|
518
|
+
channel: channelDir.name,
|
|
519
|
+
friendId: friendDir.name,
|
|
520
|
+
key: keyDir.name,
|
|
521
|
+
count: messages.length,
|
|
522
|
+
},
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
189
530
|
async stop() {
|
|
190
531
|
(0, runtime_1.emitNervesEvent)({
|
|
191
532
|
component: "daemon",
|
|
@@ -193,6 +534,8 @@ class OuroDaemon {
|
|
|
193
534
|
message: "stopping daemon server",
|
|
194
535
|
meta: { socketPath: this.socketPath },
|
|
195
536
|
});
|
|
537
|
+
(0, update_checker_1.stopUpdateChecker)();
|
|
538
|
+
(0, mcp_manager_1.shutdownSharedMcpManager)();
|
|
196
539
|
this.scheduler.stop?.();
|
|
197
540
|
await this.processManager.stopAll();
|
|
198
541
|
await this.senseManager?.stopAll();
|
|
@@ -202,6 +545,10 @@ class OuroDaemon {
|
|
|
202
545
|
});
|
|
203
546
|
this.server = null;
|
|
204
547
|
}
|
|
548
|
+
if (this.outlookServer) {
|
|
549
|
+
await this.outlookServer.stop();
|
|
550
|
+
this.outlookServer = null;
|
|
551
|
+
}
|
|
205
552
|
if (fs.existsSync(this.socketPath)) {
|
|
206
553
|
fs.unlinkSync(this.socketPath);
|
|
207
554
|
}
|
|
@@ -226,6 +573,27 @@ class OuroDaemon {
|
|
|
226
573
|
message: "handling daemon command",
|
|
227
574
|
meta: { kind: command.kind },
|
|
228
575
|
});
|
|
576
|
+
try {
|
|
577
|
+
return await this.handleCommandInner(command);
|
|
578
|
+
/* v8 ignore start — command error catch tested in daemon-command-error.test; instanceof branches defensive @preserve */
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
(0, runtime_1.emitNervesEvent)({
|
|
582
|
+
level: "error",
|
|
583
|
+
component: "daemon",
|
|
584
|
+
event: "daemon.command_error",
|
|
585
|
+
message: "unexpected error handling daemon command",
|
|
586
|
+
meta: {
|
|
587
|
+
kind: command.kind,
|
|
588
|
+
error: error instanceof Error ? error.message : String(error),
|
|
589
|
+
stack: error instanceof Error ? error.stack ?? null : null,
|
|
590
|
+
},
|
|
591
|
+
});
|
|
592
|
+
throw error;
|
|
593
|
+
}
|
|
594
|
+
/* v8 ignore stop */
|
|
595
|
+
}
|
|
596
|
+
async handleCommandInner(command) {
|
|
229
597
|
switch (command.kind) {
|
|
230
598
|
case "daemon.start":
|
|
231
599
|
await this.start();
|
|
@@ -234,20 +602,7 @@ class OuroDaemon {
|
|
|
234
602
|
await this.stop();
|
|
235
603
|
return { ok: true, message: "daemon stopped" };
|
|
236
604
|
case "daemon.status": {
|
|
237
|
-
const
|
|
238
|
-
const workers = buildWorkerRows(snapshots);
|
|
239
|
-
const senses = this.senseManager?.listSenseRows() ?? [];
|
|
240
|
-
const data = {
|
|
241
|
-
overview: {
|
|
242
|
-
daemon: "running",
|
|
243
|
-
health: workers.every((worker) => worker.status === "running") ? "ok" : "warn",
|
|
244
|
-
socketPath: this.socketPath,
|
|
245
|
-
workerCount: workers.length,
|
|
246
|
-
senseCount: senses.length,
|
|
247
|
-
},
|
|
248
|
-
workers,
|
|
249
|
-
senses,
|
|
250
|
-
};
|
|
605
|
+
const data = this.buildStatusPayload();
|
|
251
606
|
return {
|
|
252
607
|
ok: true,
|
|
253
608
|
summary: formatStatusSummary(data),
|
|
@@ -264,7 +619,7 @@ class OuroDaemon {
|
|
|
264
619
|
ok: true,
|
|
265
620
|
summary: "logs: use `ouro logs` to tail daemon and agent output",
|
|
266
621
|
message: "log streaming available via ouro logs",
|
|
267
|
-
data: { logDir: "
|
|
622
|
+
data: { logDir: "~/AgentBundles/<agent>.ouro/state/daemon/logs" },
|
|
268
623
|
};
|
|
269
624
|
case "agent.start":
|
|
270
625
|
await this.processManager.startAgent(command.agent);
|
|
@@ -275,6 +630,32 @@ class OuroDaemon {
|
|
|
275
630
|
case "agent.restart":
|
|
276
631
|
await this.processManager.restartAgent?.(command.agent);
|
|
277
632
|
return { ok: true, message: `restarted ${command.agent}` };
|
|
633
|
+
case "agent.ask":
|
|
634
|
+
return (0, agent_service_1.handleAgentAsk)(command);
|
|
635
|
+
case "agent.status":
|
|
636
|
+
return (0, agent_service_1.handleAgentStatus)(command);
|
|
637
|
+
case "agent.catchup":
|
|
638
|
+
return (0, agent_service_1.handleAgentCatchup)(command);
|
|
639
|
+
case "agent.delegate":
|
|
640
|
+
return (0, agent_service_1.handleAgentDelegate)(command);
|
|
641
|
+
case "agent.getContext":
|
|
642
|
+
return (0, agent_service_1.handleAgentGetContext)(command);
|
|
643
|
+
case "agent.searchMemory":
|
|
644
|
+
return (0, agent_service_1.handleAgentSearchMemory)(command);
|
|
645
|
+
case "agent.getTask":
|
|
646
|
+
return (0, agent_service_1.handleAgentGetTask)(command);
|
|
647
|
+
case "agent.checkScope":
|
|
648
|
+
return (0, agent_service_1.handleAgentCheckScope)(command);
|
|
649
|
+
case "agent.requestDecision":
|
|
650
|
+
return (0, agent_service_1.handleAgentRequestDecision)(command);
|
|
651
|
+
case "agent.checkGuidance":
|
|
652
|
+
return (0, agent_service_1.handleAgentCheckGuidance)(command);
|
|
653
|
+
case "agent.reportProgress":
|
|
654
|
+
return (0, agent_service_1.handleAgentReportProgress)(command);
|
|
655
|
+
case "agent.reportBlocker":
|
|
656
|
+
return (0, agent_service_1.handleAgentReportBlocker)(command);
|
|
657
|
+
case "agent.reportComplete":
|
|
658
|
+
return (0, agent_service_1.handleAgentReportComplete)(command);
|
|
278
659
|
case "cron.list": {
|
|
279
660
|
const jobs = this.scheduler.listJobs();
|
|
280
661
|
const summary = jobs.length === 0
|
|
@@ -306,6 +687,13 @@ class OuroDaemon {
|
|
|
306
687
|
data: messages,
|
|
307
688
|
};
|
|
308
689
|
}
|
|
690
|
+
case "inner.wake":
|
|
691
|
+
await this.processManager.startAgent(command.agent);
|
|
692
|
+
this.processManager.sendToAgent?.(command.agent, { type: "message" });
|
|
693
|
+
return {
|
|
694
|
+
ok: true,
|
|
695
|
+
message: `woke inner dialog for ${command.agent}`,
|
|
696
|
+
};
|
|
309
697
|
case "chat.connect":
|
|
310
698
|
await this.processManager.startAgent(command.agent);
|
|
311
699
|
return {
|
|
@@ -328,6 +716,35 @@ class OuroDaemon {
|
|
|
328
716
|
data: receipt,
|
|
329
717
|
};
|
|
330
718
|
}
|
|
719
|
+
case "habit.poke": {
|
|
720
|
+
this.processManager.sendToAgent?.(command.agent, { type: "habit", habitName: command.habitName });
|
|
721
|
+
return {
|
|
722
|
+
ok: true,
|
|
723
|
+
message: `poked habit ${command.habitName} for ${command.agent}`,
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
case "mcp.list": {
|
|
727
|
+
const mcpManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
728
|
+
if (!mcpManager) {
|
|
729
|
+
return { ok: true, data: [], message: "no MCP servers configured" };
|
|
730
|
+
}
|
|
731
|
+
return { ok: true, data: mcpManager.listAllTools() };
|
|
732
|
+
}
|
|
733
|
+
case "mcp.call": {
|
|
734
|
+
const mcpCallManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
735
|
+
if (!mcpCallManager) {
|
|
736
|
+
return { ok: false, error: "no MCP servers configured" };
|
|
737
|
+
}
|
|
738
|
+
try {
|
|
739
|
+
const parsedArgs = command.args ? JSON.parse(command.args) : {};
|
|
740
|
+
const result = await mcpCallManager.callTool(command.server, command.tool, parsedArgs);
|
|
741
|
+
return { ok: true, data: result };
|
|
742
|
+
}
|
|
743
|
+
catch (error) {
|
|
744
|
+
/* v8 ignore next -- defensive: callTool errors are always Error instances @preserve */
|
|
745
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
746
|
+
}
|
|
747
|
+
}
|
|
331
748
|
case "hatch.start":
|
|
332
749
|
return {
|
|
333
750
|
ok: true,
|