@ouro.bot/cli 0.1.0-alpha.16 → 0.1.0-alpha.161
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 +187 -191
- package/changelog.json +1088 -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 +445 -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 +369 -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/outlook-ui/assets/index-CXQG0mVx.js +61 -0
- package/dist/outlook-ui/assets/index-Gq7EdfkO.css +1 -0
- package/dist/outlook-ui/index.html +15 -0
- 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 +13 -5
- 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,154 @@ 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
|
+
try {
|
|
299
|
+
this.outlookServer = await (0, outlook_http_1.startOutlookHttpServer)({
|
|
300
|
+
host: "127.0.0.1",
|
|
301
|
+
port: outlook_types_1.OUTLOOK_DEFAULT_PORT,
|
|
302
|
+
readMachineState: () => (0, outlook_read_1.readOutlookMachineState)({ bundlesRoot: this.bundlesRoot }),
|
|
303
|
+
readMachineView: ({ machine }) => {
|
|
304
|
+
const overview = this.buildStatusPayload().overview;
|
|
305
|
+
return (0, outlook_view_1.buildOutlookMachineView)({
|
|
306
|
+
machine,
|
|
307
|
+
daemon: {
|
|
308
|
+
status: overview.daemon,
|
|
309
|
+
health: overview.health,
|
|
310
|
+
mode: overview.mode,
|
|
311
|
+
socketPath: overview.socketPath,
|
|
312
|
+
outlookUrl: overview.outlookUrl,
|
|
313
|
+
entryPath: overview.entryPath,
|
|
314
|
+
workerCount: overview.workerCount,
|
|
315
|
+
senseCount: overview.senseCount,
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
readAgentState: (agentName) => (0, outlook_read_1.readOutlookAgentState)(agentName, { bundlesRoot: this.bundlesRoot }),
|
|
320
|
+
readAgentView: (agentName) => {
|
|
321
|
+
const agent = (0, outlook_read_1.readOutlookAgentState)(agentName, { bundlesRoot: this.bundlesRoot });
|
|
322
|
+
return (0, outlook_view_1.buildOutlookAgentView)({
|
|
323
|
+
agent,
|
|
324
|
+
viewer: { kind: "human" },
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
(0, runtime_1.emitNervesEvent)({
|
|
331
|
+
level: "warn",
|
|
332
|
+
component: "daemon",
|
|
333
|
+
event: "daemon.outlook_start_failed",
|
|
334
|
+
message: `Outlook server failed to start: ${String(error)}`,
|
|
335
|
+
meta: { port: outlook_types_1.OUTLOOK_DEFAULT_PORT },
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/* v8 ignore stop */
|
|
114
340
|
if (fs.existsSync(this.socketPath)) {
|
|
115
341
|
fs.unlinkSync(this.socketPath);
|
|
116
342
|
}
|
|
117
343
|
this.server = net.createServer((connection) => {
|
|
118
344
|
let raw = "";
|
|
119
345
|
let responded = false;
|
|
346
|
+
/* v8 ignore start — connection error handler requires real socket error @preserve */
|
|
347
|
+
connection.on("error", (err) => {
|
|
348
|
+
(0, runtime_1.emitNervesEvent)({
|
|
349
|
+
level: "warn",
|
|
350
|
+
component: "daemon",
|
|
351
|
+
event: "daemon.connection_error",
|
|
352
|
+
message: "socket connection error",
|
|
353
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
/* v8 ignore stop */
|
|
120
357
|
const flushResponse = async () => {
|
|
121
358
|
if (responded)
|
|
122
359
|
return;
|
|
123
360
|
responded = true;
|
|
124
361
|
const response = await this.handleRawPayload(raw);
|
|
125
|
-
|
|
362
|
+
try {
|
|
363
|
+
connection.end(response);
|
|
364
|
+
/* v8 ignore start — EPIPE catch requires real socket disconnect @preserve */
|
|
365
|
+
}
|
|
366
|
+
catch (err) {
|
|
367
|
+
(0, runtime_1.emitNervesEvent)({
|
|
368
|
+
level: "warn",
|
|
369
|
+
component: "daemon",
|
|
370
|
+
event: "daemon.connection_end_error",
|
|
371
|
+
message: "failed to send response to client (EPIPE)",
|
|
372
|
+
meta: { error: err instanceof Error ? err.message : String(err) },
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
/* v8 ignore stop */
|
|
126
376
|
};
|
|
127
377
|
connection.on("data", (chunk) => {
|
|
128
378
|
raw += chunk.toString("utf-8");
|
|
@@ -135,7 +385,22 @@ class OuroDaemon {
|
|
|
135
385
|
const server = this.server;
|
|
136
386
|
await new Promise((resolve, reject) => {
|
|
137
387
|
server.once("error", reject);
|
|
138
|
-
server.listen(this.socketPath, () =>
|
|
388
|
+
server.listen(this.socketPath, () => {
|
|
389
|
+
// Replace the one-time error listener with a persistent one after successful listen
|
|
390
|
+
server.removeAllListeners("error");
|
|
391
|
+
/* v8 ignore start — server error after listen requires real socket race condition @preserve */
|
|
392
|
+
server.on("error", (err) => {
|
|
393
|
+
(0, runtime_1.emitNervesEvent)({
|
|
394
|
+
level: "error",
|
|
395
|
+
component: "daemon",
|
|
396
|
+
event: "daemon.server_error",
|
|
397
|
+
message: "daemon server error after listen",
|
|
398
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
/* v8 ignore stop */
|
|
402
|
+
resolve();
|
|
403
|
+
});
|
|
139
404
|
});
|
|
140
405
|
}
|
|
141
406
|
async drainPendingBundleMessages() {
|
|
@@ -186,6 +451,93 @@ class OuroDaemon {
|
|
|
186
451
|
fs.writeFileSync(pendingPath, next, "utf-8");
|
|
187
452
|
}
|
|
188
453
|
}
|
|
454
|
+
/** Drains per-sense pending dirs for always-on senses across all agents. */
|
|
455
|
+
static ALWAYS_ON_SENSES = new Set((0, channel_1.getAlwaysOnSenseNames)());
|
|
456
|
+
async drainPendingSenseMessages() {
|
|
457
|
+
if (!fs.existsSync(this.bundlesRoot))
|
|
458
|
+
return;
|
|
459
|
+
let bundleDirs;
|
|
460
|
+
try {
|
|
461
|
+
bundleDirs = fs.readdirSync(this.bundlesRoot, { withFileTypes: true });
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
for (const bundleDir of bundleDirs) {
|
|
467
|
+
if (!bundleDir.isDirectory() || !bundleDir.name.endsWith(".ouro"))
|
|
468
|
+
continue;
|
|
469
|
+
const agentName = bundleDir.name.replace(/\.ouro$/, "");
|
|
470
|
+
const pendingRoot = path.join(this.bundlesRoot, bundleDir.name, "state", "pending");
|
|
471
|
+
if (!fs.existsSync(pendingRoot))
|
|
472
|
+
continue;
|
|
473
|
+
let friendDirs;
|
|
474
|
+
try {
|
|
475
|
+
friendDirs = fs.readdirSync(pendingRoot, { withFileTypes: true });
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
for (const friendDir of friendDirs) {
|
|
481
|
+
if (!friendDir.isDirectory())
|
|
482
|
+
continue;
|
|
483
|
+
const friendPath = path.join(pendingRoot, friendDir.name);
|
|
484
|
+
let channelDirs;
|
|
485
|
+
try {
|
|
486
|
+
channelDirs = fs.readdirSync(friendPath, { withFileTypes: true });
|
|
487
|
+
}
|
|
488
|
+
catch {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
for (const channelDir of channelDirs) {
|
|
492
|
+
if (!channelDir.isDirectory())
|
|
493
|
+
continue;
|
|
494
|
+
if (!OuroDaemon.ALWAYS_ON_SENSES.has(channelDir.name))
|
|
495
|
+
continue;
|
|
496
|
+
const channelPath = path.join(friendPath, channelDir.name);
|
|
497
|
+
let keyDirs;
|
|
498
|
+
try {
|
|
499
|
+
keyDirs = fs.readdirSync(channelPath, { withFileTypes: true });
|
|
500
|
+
}
|
|
501
|
+
catch {
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
for (const keyDir of keyDirs) {
|
|
505
|
+
if (!keyDir.isDirectory())
|
|
506
|
+
continue;
|
|
507
|
+
const leafDir = path.join(channelPath, keyDir.name);
|
|
508
|
+
const messages = (0, pending_1.drainPending)(leafDir);
|
|
509
|
+
for (const msg of messages) {
|
|
510
|
+
try {
|
|
511
|
+
await this.router.send({
|
|
512
|
+
from: msg.from,
|
|
513
|
+
to: agentName,
|
|
514
|
+
content: msg.content,
|
|
515
|
+
priority: "normal",
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
catch {
|
|
519
|
+
// Best-effort delivery — log and continue
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (messages.length > 0) {
|
|
523
|
+
(0, runtime_1.emitNervesEvent)({
|
|
524
|
+
component: "daemon",
|
|
525
|
+
event: "daemon.startup_sense_drain",
|
|
526
|
+
message: "drained pending sense messages on startup",
|
|
527
|
+
meta: {
|
|
528
|
+
agent: agentName,
|
|
529
|
+
channel: channelDir.name,
|
|
530
|
+
friendId: friendDir.name,
|
|
531
|
+
key: keyDir.name,
|
|
532
|
+
count: messages.length,
|
|
533
|
+
},
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
189
541
|
async stop() {
|
|
190
542
|
(0, runtime_1.emitNervesEvent)({
|
|
191
543
|
component: "daemon",
|
|
@@ -193,6 +545,8 @@ class OuroDaemon {
|
|
|
193
545
|
message: "stopping daemon server",
|
|
194
546
|
meta: { socketPath: this.socketPath },
|
|
195
547
|
});
|
|
548
|
+
(0, update_checker_1.stopUpdateChecker)();
|
|
549
|
+
(0, mcp_manager_1.shutdownSharedMcpManager)();
|
|
196
550
|
this.scheduler.stop?.();
|
|
197
551
|
await this.processManager.stopAll();
|
|
198
552
|
await this.senseManager?.stopAll();
|
|
@@ -202,6 +556,10 @@ class OuroDaemon {
|
|
|
202
556
|
});
|
|
203
557
|
this.server = null;
|
|
204
558
|
}
|
|
559
|
+
if (this.outlookServer) {
|
|
560
|
+
await this.outlookServer.stop();
|
|
561
|
+
this.outlookServer = null;
|
|
562
|
+
}
|
|
205
563
|
if (fs.existsSync(this.socketPath)) {
|
|
206
564
|
fs.unlinkSync(this.socketPath);
|
|
207
565
|
}
|
|
@@ -226,6 +584,27 @@ class OuroDaemon {
|
|
|
226
584
|
message: "handling daemon command",
|
|
227
585
|
meta: { kind: command.kind },
|
|
228
586
|
});
|
|
587
|
+
try {
|
|
588
|
+
return await this.handleCommandInner(command);
|
|
589
|
+
/* v8 ignore start — command error catch tested in daemon-command-error.test; instanceof branches defensive @preserve */
|
|
590
|
+
}
|
|
591
|
+
catch (error) {
|
|
592
|
+
(0, runtime_1.emitNervesEvent)({
|
|
593
|
+
level: "error",
|
|
594
|
+
component: "daemon",
|
|
595
|
+
event: "daemon.command_error",
|
|
596
|
+
message: "unexpected error handling daemon command",
|
|
597
|
+
meta: {
|
|
598
|
+
kind: command.kind,
|
|
599
|
+
error: error instanceof Error ? error.message : String(error),
|
|
600
|
+
stack: error instanceof Error ? error.stack ?? null : null,
|
|
601
|
+
},
|
|
602
|
+
});
|
|
603
|
+
throw error;
|
|
604
|
+
}
|
|
605
|
+
/* v8 ignore stop */
|
|
606
|
+
}
|
|
607
|
+
async handleCommandInner(command) {
|
|
229
608
|
switch (command.kind) {
|
|
230
609
|
case "daemon.start":
|
|
231
610
|
await this.start();
|
|
@@ -234,20 +613,7 @@ class OuroDaemon {
|
|
|
234
613
|
await this.stop();
|
|
235
614
|
return { ok: true, message: "daemon stopped" };
|
|
236
615
|
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
|
-
};
|
|
616
|
+
const data = this.buildStatusPayload();
|
|
251
617
|
return {
|
|
252
618
|
ok: true,
|
|
253
619
|
summary: formatStatusSummary(data),
|
|
@@ -264,7 +630,7 @@ class OuroDaemon {
|
|
|
264
630
|
ok: true,
|
|
265
631
|
summary: "logs: use `ouro logs` to tail daemon and agent output",
|
|
266
632
|
message: "log streaming available via ouro logs",
|
|
267
|
-
data: { logDir: "
|
|
633
|
+
data: { logDir: "~/AgentBundles/<agent>.ouro/state/daemon/logs" },
|
|
268
634
|
};
|
|
269
635
|
case "agent.start":
|
|
270
636
|
await this.processManager.startAgent(command.agent);
|
|
@@ -275,6 +641,32 @@ class OuroDaemon {
|
|
|
275
641
|
case "agent.restart":
|
|
276
642
|
await this.processManager.restartAgent?.(command.agent);
|
|
277
643
|
return { ok: true, message: `restarted ${command.agent}` };
|
|
644
|
+
case "agent.ask":
|
|
645
|
+
return (0, agent_service_1.handleAgentAsk)(command);
|
|
646
|
+
case "agent.status":
|
|
647
|
+
return (0, agent_service_1.handleAgentStatus)(command);
|
|
648
|
+
case "agent.catchup":
|
|
649
|
+
return (0, agent_service_1.handleAgentCatchup)(command);
|
|
650
|
+
case "agent.delegate":
|
|
651
|
+
return (0, agent_service_1.handleAgentDelegate)(command);
|
|
652
|
+
case "agent.getContext":
|
|
653
|
+
return (0, agent_service_1.handleAgentGetContext)(command);
|
|
654
|
+
case "agent.searchMemory":
|
|
655
|
+
return (0, agent_service_1.handleAgentSearchMemory)(command);
|
|
656
|
+
case "agent.getTask":
|
|
657
|
+
return (0, agent_service_1.handleAgentGetTask)(command);
|
|
658
|
+
case "agent.checkScope":
|
|
659
|
+
return (0, agent_service_1.handleAgentCheckScope)(command);
|
|
660
|
+
case "agent.requestDecision":
|
|
661
|
+
return (0, agent_service_1.handleAgentRequestDecision)(command);
|
|
662
|
+
case "agent.checkGuidance":
|
|
663
|
+
return (0, agent_service_1.handleAgentCheckGuidance)(command);
|
|
664
|
+
case "agent.reportProgress":
|
|
665
|
+
return (0, agent_service_1.handleAgentReportProgress)(command);
|
|
666
|
+
case "agent.reportBlocker":
|
|
667
|
+
return (0, agent_service_1.handleAgentReportBlocker)(command);
|
|
668
|
+
case "agent.reportComplete":
|
|
669
|
+
return (0, agent_service_1.handleAgentReportComplete)(command);
|
|
278
670
|
case "cron.list": {
|
|
279
671
|
const jobs = this.scheduler.listJobs();
|
|
280
672
|
const summary = jobs.length === 0
|
|
@@ -306,6 +698,13 @@ class OuroDaemon {
|
|
|
306
698
|
data: messages,
|
|
307
699
|
};
|
|
308
700
|
}
|
|
701
|
+
case "inner.wake":
|
|
702
|
+
await this.processManager.startAgent(command.agent);
|
|
703
|
+
this.processManager.sendToAgent?.(command.agent, { type: "message" });
|
|
704
|
+
return {
|
|
705
|
+
ok: true,
|
|
706
|
+
message: `woke inner dialog for ${command.agent}`,
|
|
707
|
+
};
|
|
309
708
|
case "chat.connect":
|
|
310
709
|
await this.processManager.startAgent(command.agent);
|
|
311
710
|
return {
|
|
@@ -328,6 +727,35 @@ class OuroDaemon {
|
|
|
328
727
|
data: receipt,
|
|
329
728
|
};
|
|
330
729
|
}
|
|
730
|
+
case "habit.poke": {
|
|
731
|
+
this.processManager.sendToAgent?.(command.agent, { type: "habit", habitName: command.habitName });
|
|
732
|
+
return {
|
|
733
|
+
ok: true,
|
|
734
|
+
message: `poked habit ${command.habitName} for ${command.agent}`,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
case "mcp.list": {
|
|
738
|
+
const mcpManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
739
|
+
if (!mcpManager) {
|
|
740
|
+
return { ok: true, data: [], message: "no MCP servers configured" };
|
|
741
|
+
}
|
|
742
|
+
return { ok: true, data: mcpManager.listAllTools() };
|
|
743
|
+
}
|
|
744
|
+
case "mcp.call": {
|
|
745
|
+
const mcpCallManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
746
|
+
if (!mcpCallManager) {
|
|
747
|
+
return { ok: false, error: "no MCP servers configured" };
|
|
748
|
+
}
|
|
749
|
+
try {
|
|
750
|
+
const parsedArgs = command.args ? JSON.parse(command.args) : {};
|
|
751
|
+
const result = await mcpCallManager.callTool(command.server, command.tool, parsedArgs);
|
|
752
|
+
return { ok: true, data: result };
|
|
753
|
+
}
|
|
754
|
+
catch (error) {
|
|
755
|
+
/* v8 ignore next -- defensive: callTool errors are always Error instances @preserve */
|
|
756
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
757
|
+
}
|
|
758
|
+
}
|
|
331
759
|
case "hatch.start":
|
|
332
760
|
return {
|
|
333
761
|
ok: true,
|