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