@ouro.bot/cli 0.1.0-alpha.15 → 0.1.0-alpha.151
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/psyche/SOUL.md +2 -2
- package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
- package/README.md +185 -191
- package/changelog.json +991 -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 +66 -21
- package/dist/heart/core.js +645 -112
- 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 +457 -0
- package/dist/heart/daemon/cadence.js +70 -0
- package/dist/heart/daemon/daemon-cli.js +2301 -205
- package/dist/heart/daemon/daemon-entry.js +131 -4
- package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
- package/dist/heart/daemon/daemon-tombstone.js +106 -0
- package/dist/heart/daemon/daemon.js +372 -3
- 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 +252 -0
- package/dist/heart/daemon/hatch-animation.js +10 -3
- package/dist/heart/daemon/hatch-flow.js +28 -111
- 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/process-manager.js +75 -0
- package/dist/heart/daemon/run-hooks.js +37 -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/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 +10 -7
- 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 +64 -21
- package/dist/heart/kicks.js +2 -20
- 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 +159 -0
- package/dist/heart/providers/anthropic-token.js +163 -0
- package/dist/heart/providers/anthropic.js +195 -34
- package/dist/heart/providers/azure.js +115 -9
- package/dist/heart/providers/github-copilot.js +157 -0
- package/dist/heart/providers/minimax.js +33 -3
- package/dist/heart/providers/openai-codex.js +49 -14
- package/dist/heart/session-activity.js +173 -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-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 +44 -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 +612 -88
- 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/index.js +59 -2
- package/dist/nerves/runtime.js +5 -1
- package/dist/repertoire/ado-client.js +4 -2
- 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/data/ado-endpoints.json +188 -0
- package/dist/repertoire/guardrails.js +290 -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 +12 -0
- package/dist/repertoire/tasks/index.js +23 -9
- package/dist/repertoire/tasks/parser.js +0 -2
- package/dist/repertoire/tasks/transitions.js +1 -20
- package/dist/repertoire/tools-base.js +990 -273
- package/dist/repertoire/tools-bluebubbles.js +94 -0
- package/dist/repertoire/tools-github.js +1 -6
- package/dist/repertoire/tools-teams.js +65 -59
- package/dist/repertoire/tools.js +281 -91
- 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 +981 -45
- package/dist/senses/cli-entry.js +1 -1
- package/dist/senses/cli-layout.js +187 -0
- package/dist/senses/cli.js +374 -131
- package/dist/senses/contextual-heartbeat.js +106 -0
- package/dist/senses/continuity.js +94 -0
- package/dist/senses/debug-activity.js +154 -0
- package/dist/senses/inner-dialog-worker.js +112 -19
- package/dist/senses/inner-dialog.js +621 -84
- package/dist/senses/pipeline.js +463 -0
- package/dist/senses/shared-turn.js +196 -0
- package/dist/senses/surface-tool.js +95 -0
- package/dist/senses/teams.js +796 -141
- 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,99 @@ 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 bundle_manifest_1 = require("../../mind/bundle-manifest");
|
|
50
|
+
const update_checker_1 = require("./update-checker");
|
|
51
|
+
const staged_restart_1 = require("./staged-restart");
|
|
52
|
+
const child_process_1 = require("child_process");
|
|
53
|
+
const pending_1 = require("../../mind/pending");
|
|
54
|
+
const agent_service_1 = require("./agent-service");
|
|
55
|
+
const channel_1 = require("../../mind/friends/channel");
|
|
56
|
+
const mcp_manager_1 = require("../../repertoire/mcp-manager");
|
|
57
|
+
const PIDFILE_PATH = path.join(os.homedir(), ".ouro-cli", "daemon.pids");
|
|
58
|
+
/**
|
|
59
|
+
* Kill all ouro processes from the previous daemon instance using the pidfile.
|
|
60
|
+
* On startup, reads PIDs from ~/.ouro-cli/daemon.pids, kills them all, then
|
|
61
|
+
* deletes the file. The new daemon writes its own PIDs after spawning.
|
|
62
|
+
*
|
|
63
|
+
* Falls back to ps-based scanning if the pidfile doesn't exist (first run
|
|
64
|
+
* or manual cleanup).
|
|
65
|
+
*/
|
|
66
|
+
/* v8 ignore start -- process lifecycle: uses kill/ps, tested via deployment @preserve */
|
|
67
|
+
function killOrphanProcesses() {
|
|
68
|
+
try {
|
|
69
|
+
let pidsToKill = [];
|
|
70
|
+
// Primary: read pidfile from previous daemon
|
|
71
|
+
try {
|
|
72
|
+
const raw = fs.readFileSync(PIDFILE_PATH, "utf-8");
|
|
73
|
+
pidsToKill = raw.split("\n").map((s) => parseInt(s.trim(), 10)).filter((n) => !isNaN(n) && n !== process.pid);
|
|
74
|
+
fs.unlinkSync(PIDFILE_PATH);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// No pidfile — fall back to ps scan
|
|
78
|
+
}
|
|
79
|
+
// Fallback: scan ps for any ouro entry processes we missed
|
|
80
|
+
if (pidsToKill.length === 0) {
|
|
81
|
+
try {
|
|
82
|
+
const result = (0, child_process_1.execSync)("ps -eo pid,command", { encoding: "utf-8", timeout: 5000 });
|
|
83
|
+
for (const line of result.split("\n")) {
|
|
84
|
+
if (!line.includes("agent-entry.js") && !line.includes("daemon-entry.js") && !line.includes("-entry.js --agent"))
|
|
85
|
+
continue;
|
|
86
|
+
const pid = parseInt(line.trim(), 10);
|
|
87
|
+
if (!isNaN(pid) && pid !== process.pid)
|
|
88
|
+
pidsToKill.push(pid);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch { /* ps failed — best effort */ }
|
|
92
|
+
}
|
|
93
|
+
if (pidsToKill.length > 0) {
|
|
94
|
+
for (const pid of pidsToKill) {
|
|
95
|
+
try {
|
|
96
|
+
process.kill(pid, "SIGTERM");
|
|
97
|
+
}
|
|
98
|
+
catch { /* already exited */ }
|
|
99
|
+
}
|
|
100
|
+
(0, runtime_1.emitNervesEvent)({
|
|
101
|
+
component: "daemon",
|
|
102
|
+
event: "daemon.orphan_cleanup",
|
|
103
|
+
message: `killed ${pidsToKill.length} orphaned ouro processes`,
|
|
104
|
+
meta: { pids: pidsToKill },
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
(0, runtime_1.emitNervesEvent)({
|
|
110
|
+
level: "warn",
|
|
111
|
+
component: "daemon",
|
|
112
|
+
event: "daemon.orphan_cleanup_error",
|
|
113
|
+
message: "failed to clean up orphaned ouro processes",
|
|
114
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Write all managed PIDs (daemon + children) to the pidfile.
|
|
120
|
+
* Called after all agents and senses are spawned.
|
|
121
|
+
*/
|
|
122
|
+
function writePidfile(extraPids = []) {
|
|
123
|
+
try {
|
|
124
|
+
const pids = [process.pid, ...extraPids].filter(Boolean);
|
|
125
|
+
fs.mkdirSync(path.dirname(PIDFILE_PATH), { recursive: true });
|
|
126
|
+
fs.writeFileSync(PIDFILE_PATH, pids.join("\n") + "\n", "utf-8");
|
|
127
|
+
}
|
|
128
|
+
catch { /* best effort */ }
|
|
129
|
+
}
|
|
42
130
|
function buildWorkerRows(snapshots) {
|
|
43
131
|
return snapshots.map((snapshot) => ({
|
|
44
132
|
agent: snapshot.name,
|
|
@@ -47,6 +135,8 @@ function buildWorkerRows(snapshots) {
|
|
|
47
135
|
pid: snapshot.pid,
|
|
48
136
|
restartCount: snapshot.restartCount,
|
|
49
137
|
startedAt: snapshot.startedAt,
|
|
138
|
+
lastExitCode: snapshot.lastExitCode ?? null,
|
|
139
|
+
lastSignal: snapshot.lastSignal ?? null,
|
|
50
140
|
}));
|
|
51
141
|
}
|
|
52
142
|
function formatStatusSummary(payload) {
|
|
@@ -87,6 +177,7 @@ class OuroDaemon {
|
|
|
87
177
|
router;
|
|
88
178
|
senseManager;
|
|
89
179
|
bundlesRoot;
|
|
180
|
+
mode;
|
|
90
181
|
server = null;
|
|
91
182
|
constructor(options) {
|
|
92
183
|
this.socketPath = options.socketPath;
|
|
@@ -96,6 +187,7 @@ class OuroDaemon {
|
|
|
96
187
|
this.router = options.router;
|
|
97
188
|
this.senseManager = options.senseManager ?? null;
|
|
98
189
|
this.bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
|
|
190
|
+
this.mode = options.mode ?? "production";
|
|
99
191
|
}
|
|
100
192
|
async start() {
|
|
101
193
|
if (this.server)
|
|
@@ -106,23 +198,109 @@ class OuroDaemon {
|
|
|
106
198
|
message: "starting daemon server",
|
|
107
199
|
meta: { socketPath: this.socketPath },
|
|
108
200
|
});
|
|
201
|
+
// Register update hooks and apply pending updates before starting agents
|
|
202
|
+
(0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
|
|
203
|
+
const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
|
|
204
|
+
await (0, update_hooks_1.applyPendingUpdates)(this.bundlesRoot, currentVersion);
|
|
205
|
+
// Start periodic update checker (polls npm registry every 30 minutes)
|
|
206
|
+
// Skip in dev mode — dev builds should not auto-update from npm
|
|
207
|
+
const bundlesRoot = this.bundlesRoot;
|
|
208
|
+
if (this.mode === "dev") {
|
|
209
|
+
(0, runtime_1.emitNervesEvent)({
|
|
210
|
+
component: "daemon",
|
|
211
|
+
event: "daemon.update_checker_skip",
|
|
212
|
+
message: "skipping update checker in dev mode",
|
|
213
|
+
meta: { reason: "dev mode" },
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const daemon = this;
|
|
218
|
+
(0, update_checker_1.startUpdateChecker)({
|
|
219
|
+
currentVersion,
|
|
220
|
+
deps: {
|
|
221
|
+
distTag: "alpha",
|
|
222
|
+
fetchRegistryJson: /* v8 ignore next -- integration: real HTTP fetch @preserve */ async () => {
|
|
223
|
+
const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
|
|
224
|
+
return res.json();
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
onUpdate: /* v8 ignore start -- integration: real npm install + process spawn @preserve */ async (result) => {
|
|
228
|
+
if (!result.latestVersion)
|
|
229
|
+
return;
|
|
230
|
+
await (0, staged_restart_1.performStagedRestart)(result.latestVersion, {
|
|
231
|
+
execSync: (cmd) => (0, child_process_1.execSync)(cmd, { stdio: "inherit" }),
|
|
232
|
+
spawnSync: child_process_1.spawnSync,
|
|
233
|
+
resolveNewCodePath: (_version) => {
|
|
234
|
+
try {
|
|
235
|
+
const resolved = (0, child_process_1.execSync)(`node -e "console.log(require.resolve('@ouro.bot/cli/package.json'))"`, { encoding: "utf-8" }).trim();
|
|
236
|
+
return resolved ? path.dirname(resolved) : null;
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
gracefulShutdown: () => daemon.stop(),
|
|
243
|
+
nodePath: process.execPath,
|
|
244
|
+
bundlesRoot,
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
/* v8 ignore stop */
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
// Pre-initialize MCP connections so they're ready for the first command (non-blocking)
|
|
251
|
+
/* v8 ignore next -- catch callback: getSharedMcpManager logs errors internally @preserve */
|
|
252
|
+
(0, mcp_manager_1.getSharedMcpManager)().catch(() => { });
|
|
253
|
+
/* v8 ignore start -- orphan cleanup + pidfile: calls process management functions @preserve */
|
|
254
|
+
killOrphanProcesses();
|
|
255
|
+
/* v8 ignore stop */
|
|
109
256
|
await this.processManager.startAutoStartAgents();
|
|
110
257
|
await this.senseManager?.startAutoStartSenses();
|
|
258
|
+
// Write all managed PIDs to disk so the next daemon can clean up
|
|
259
|
+
/* v8 ignore start -- pidfile write: collects PIDs from process managers @preserve */
|
|
260
|
+
const agentPids = this.processManager.listAgentSnapshots().map((s) => s.pid).filter((p) => p !== null);
|
|
261
|
+
const sensePids = this.senseManager?.listManagedPids?.() ?? [];
|
|
262
|
+
writePidfile([...agentPids, ...sensePids]);
|
|
263
|
+
/* v8 ignore stop */
|
|
111
264
|
this.scheduler.start?.();
|
|
112
265
|
await this.scheduler.reconcile?.();
|
|
113
266
|
await this.drainPendingBundleMessages();
|
|
267
|
+
await this.drainPendingSenseMessages();
|
|
114
268
|
if (fs.existsSync(this.socketPath)) {
|
|
115
269
|
fs.unlinkSync(this.socketPath);
|
|
116
270
|
}
|
|
117
271
|
this.server = net.createServer((connection) => {
|
|
118
272
|
let raw = "";
|
|
119
273
|
let responded = false;
|
|
274
|
+
/* v8 ignore start — connection error handler requires real socket error @preserve */
|
|
275
|
+
connection.on("error", (err) => {
|
|
276
|
+
(0, runtime_1.emitNervesEvent)({
|
|
277
|
+
level: "warn",
|
|
278
|
+
component: "daemon",
|
|
279
|
+
event: "daemon.connection_error",
|
|
280
|
+
message: "socket connection error",
|
|
281
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
/* v8 ignore stop */
|
|
120
285
|
const flushResponse = async () => {
|
|
121
286
|
if (responded)
|
|
122
287
|
return;
|
|
123
288
|
responded = true;
|
|
124
289
|
const response = await this.handleRawPayload(raw);
|
|
125
|
-
|
|
290
|
+
try {
|
|
291
|
+
connection.end(response);
|
|
292
|
+
/* v8 ignore start — EPIPE catch requires real socket disconnect @preserve */
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
(0, runtime_1.emitNervesEvent)({
|
|
296
|
+
level: "warn",
|
|
297
|
+
component: "daemon",
|
|
298
|
+
event: "daemon.connection_end_error",
|
|
299
|
+
message: "failed to send response to client (EPIPE)",
|
|
300
|
+
meta: { error: err instanceof Error ? err.message : String(err) },
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
/* v8 ignore stop */
|
|
126
304
|
};
|
|
127
305
|
connection.on("data", (chunk) => {
|
|
128
306
|
raw += chunk.toString("utf-8");
|
|
@@ -135,7 +313,22 @@ class OuroDaemon {
|
|
|
135
313
|
const server = this.server;
|
|
136
314
|
await new Promise((resolve, reject) => {
|
|
137
315
|
server.once("error", reject);
|
|
138
|
-
server.listen(this.socketPath, () =>
|
|
316
|
+
server.listen(this.socketPath, () => {
|
|
317
|
+
// Replace the one-time error listener with a persistent one after successful listen
|
|
318
|
+
server.removeAllListeners("error");
|
|
319
|
+
/* v8 ignore start — server error after listen requires real socket race condition @preserve */
|
|
320
|
+
server.on("error", (err) => {
|
|
321
|
+
(0, runtime_1.emitNervesEvent)({
|
|
322
|
+
level: "error",
|
|
323
|
+
component: "daemon",
|
|
324
|
+
event: "daemon.server_error",
|
|
325
|
+
message: "daemon server error after listen",
|
|
326
|
+
meta: { error: err.message, code: err.code ?? null },
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
/* v8 ignore stop */
|
|
330
|
+
resolve();
|
|
331
|
+
});
|
|
139
332
|
});
|
|
140
333
|
}
|
|
141
334
|
async drainPendingBundleMessages() {
|
|
@@ -186,6 +379,93 @@ class OuroDaemon {
|
|
|
186
379
|
fs.writeFileSync(pendingPath, next, "utf-8");
|
|
187
380
|
}
|
|
188
381
|
}
|
|
382
|
+
/** Drains per-sense pending dirs for always-on senses across all agents. */
|
|
383
|
+
static ALWAYS_ON_SENSES = new Set((0, channel_1.getAlwaysOnSenseNames)());
|
|
384
|
+
async drainPendingSenseMessages() {
|
|
385
|
+
if (!fs.existsSync(this.bundlesRoot))
|
|
386
|
+
return;
|
|
387
|
+
let bundleDirs;
|
|
388
|
+
try {
|
|
389
|
+
bundleDirs = fs.readdirSync(this.bundlesRoot, { withFileTypes: true });
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
for (const bundleDir of bundleDirs) {
|
|
395
|
+
if (!bundleDir.isDirectory() || !bundleDir.name.endsWith(".ouro"))
|
|
396
|
+
continue;
|
|
397
|
+
const agentName = bundleDir.name.replace(/\.ouro$/, "");
|
|
398
|
+
const pendingRoot = path.join(this.bundlesRoot, bundleDir.name, "state", "pending");
|
|
399
|
+
if (!fs.existsSync(pendingRoot))
|
|
400
|
+
continue;
|
|
401
|
+
let friendDirs;
|
|
402
|
+
try {
|
|
403
|
+
friendDirs = fs.readdirSync(pendingRoot, { withFileTypes: true });
|
|
404
|
+
}
|
|
405
|
+
catch {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
for (const friendDir of friendDirs) {
|
|
409
|
+
if (!friendDir.isDirectory())
|
|
410
|
+
continue;
|
|
411
|
+
const friendPath = path.join(pendingRoot, friendDir.name);
|
|
412
|
+
let channelDirs;
|
|
413
|
+
try {
|
|
414
|
+
channelDirs = fs.readdirSync(friendPath, { withFileTypes: true });
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
for (const channelDir of channelDirs) {
|
|
420
|
+
if (!channelDir.isDirectory())
|
|
421
|
+
continue;
|
|
422
|
+
if (!OuroDaemon.ALWAYS_ON_SENSES.has(channelDir.name))
|
|
423
|
+
continue;
|
|
424
|
+
const channelPath = path.join(friendPath, channelDir.name);
|
|
425
|
+
let keyDirs;
|
|
426
|
+
try {
|
|
427
|
+
keyDirs = fs.readdirSync(channelPath, { withFileTypes: true });
|
|
428
|
+
}
|
|
429
|
+
catch {
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
for (const keyDir of keyDirs) {
|
|
433
|
+
if (!keyDir.isDirectory())
|
|
434
|
+
continue;
|
|
435
|
+
const leafDir = path.join(channelPath, keyDir.name);
|
|
436
|
+
const messages = (0, pending_1.drainPending)(leafDir);
|
|
437
|
+
for (const msg of messages) {
|
|
438
|
+
try {
|
|
439
|
+
await this.router.send({
|
|
440
|
+
from: msg.from,
|
|
441
|
+
to: agentName,
|
|
442
|
+
content: msg.content,
|
|
443
|
+
priority: "normal",
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
// Best-effort delivery — log and continue
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (messages.length > 0) {
|
|
451
|
+
(0, runtime_1.emitNervesEvent)({
|
|
452
|
+
component: "daemon",
|
|
453
|
+
event: "daemon.startup_sense_drain",
|
|
454
|
+
message: "drained pending sense messages on startup",
|
|
455
|
+
meta: {
|
|
456
|
+
agent: agentName,
|
|
457
|
+
channel: channelDir.name,
|
|
458
|
+
friendId: friendDir.name,
|
|
459
|
+
key: keyDir.name,
|
|
460
|
+
count: messages.length,
|
|
461
|
+
},
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
189
469
|
async stop() {
|
|
190
470
|
(0, runtime_1.emitNervesEvent)({
|
|
191
471
|
component: "daemon",
|
|
@@ -193,6 +473,8 @@ class OuroDaemon {
|
|
|
193
473
|
message: "stopping daemon server",
|
|
194
474
|
meta: { socketPath: this.socketPath },
|
|
195
475
|
});
|
|
476
|
+
(0, update_checker_1.stopUpdateChecker)();
|
|
477
|
+
(0, mcp_manager_1.shutdownSharedMcpManager)();
|
|
196
478
|
this.scheduler.stop?.();
|
|
197
479
|
await this.processManager.stopAll();
|
|
198
480
|
await this.senseManager?.stopAll();
|
|
@@ -226,6 +508,27 @@ class OuroDaemon {
|
|
|
226
508
|
message: "handling daemon command",
|
|
227
509
|
meta: { kind: command.kind },
|
|
228
510
|
});
|
|
511
|
+
try {
|
|
512
|
+
return await this.handleCommandInner(command);
|
|
513
|
+
/* v8 ignore start — command error catch tested in daemon-command-error.test; instanceof branches defensive @preserve */
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
(0, runtime_1.emitNervesEvent)({
|
|
517
|
+
level: "error",
|
|
518
|
+
component: "daemon",
|
|
519
|
+
event: "daemon.command_error",
|
|
520
|
+
message: "unexpected error handling daemon command",
|
|
521
|
+
meta: {
|
|
522
|
+
kind: command.kind,
|
|
523
|
+
error: error instanceof Error ? error.message : String(error),
|
|
524
|
+
stack: error instanceof Error ? error.stack ?? null : null,
|
|
525
|
+
},
|
|
526
|
+
});
|
|
527
|
+
throw error;
|
|
528
|
+
}
|
|
529
|
+
/* v8 ignore stop */
|
|
530
|
+
}
|
|
531
|
+
async handleCommandInner(command) {
|
|
229
532
|
switch (command.kind) {
|
|
230
533
|
case "daemon.start":
|
|
231
534
|
await this.start();
|
|
@@ -237,13 +540,17 @@ class OuroDaemon {
|
|
|
237
540
|
const snapshots = this.processManager.listAgentSnapshots();
|
|
238
541
|
const workers = buildWorkerRows(snapshots);
|
|
239
542
|
const senses = this.senseManager?.listSenseRows() ?? [];
|
|
543
|
+
const repoRoot = (0, identity_1.getRepoRoot)();
|
|
240
544
|
const data = {
|
|
241
545
|
overview: {
|
|
242
546
|
daemon: "running",
|
|
243
547
|
health: workers.every((worker) => worker.status === "running") ? "ok" : "warn",
|
|
244
548
|
socketPath: this.socketPath,
|
|
549
|
+
...(0, runtime_metadata_1.getRuntimeMetadata)(),
|
|
245
550
|
workerCount: workers.length,
|
|
246
551
|
senseCount: senses.length,
|
|
552
|
+
entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
|
|
553
|
+
mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
|
|
247
554
|
},
|
|
248
555
|
workers,
|
|
249
556
|
senses,
|
|
@@ -264,7 +571,7 @@ class OuroDaemon {
|
|
|
264
571
|
ok: true,
|
|
265
572
|
summary: "logs: use `ouro logs` to tail daemon and agent output",
|
|
266
573
|
message: "log streaming available via ouro logs",
|
|
267
|
-
data: { logDir: "
|
|
574
|
+
data: { logDir: "~/AgentBundles/<agent>.ouro/state/daemon/logs" },
|
|
268
575
|
};
|
|
269
576
|
case "agent.start":
|
|
270
577
|
await this.processManager.startAgent(command.agent);
|
|
@@ -275,6 +582,32 @@ class OuroDaemon {
|
|
|
275
582
|
case "agent.restart":
|
|
276
583
|
await this.processManager.restartAgent?.(command.agent);
|
|
277
584
|
return { ok: true, message: `restarted ${command.agent}` };
|
|
585
|
+
case "agent.ask":
|
|
586
|
+
return (0, agent_service_1.handleAgentAsk)(command);
|
|
587
|
+
case "agent.status":
|
|
588
|
+
return (0, agent_service_1.handleAgentStatus)(command);
|
|
589
|
+
case "agent.catchup":
|
|
590
|
+
return (0, agent_service_1.handleAgentCatchup)(command);
|
|
591
|
+
case "agent.delegate":
|
|
592
|
+
return (0, agent_service_1.handleAgentDelegate)(command);
|
|
593
|
+
case "agent.getContext":
|
|
594
|
+
return (0, agent_service_1.handleAgentGetContext)(command);
|
|
595
|
+
case "agent.searchMemory":
|
|
596
|
+
return (0, agent_service_1.handleAgentSearchMemory)(command);
|
|
597
|
+
case "agent.getTask":
|
|
598
|
+
return (0, agent_service_1.handleAgentGetTask)(command);
|
|
599
|
+
case "agent.checkScope":
|
|
600
|
+
return (0, agent_service_1.handleAgentCheckScope)(command);
|
|
601
|
+
case "agent.requestDecision":
|
|
602
|
+
return (0, agent_service_1.handleAgentRequestDecision)(command);
|
|
603
|
+
case "agent.checkGuidance":
|
|
604
|
+
return (0, agent_service_1.handleAgentCheckGuidance)(command);
|
|
605
|
+
case "agent.reportProgress":
|
|
606
|
+
return (0, agent_service_1.handleAgentReportProgress)(command);
|
|
607
|
+
case "agent.reportBlocker":
|
|
608
|
+
return (0, agent_service_1.handleAgentReportBlocker)(command);
|
|
609
|
+
case "agent.reportComplete":
|
|
610
|
+
return (0, agent_service_1.handleAgentReportComplete)(command);
|
|
278
611
|
case "cron.list": {
|
|
279
612
|
const jobs = this.scheduler.listJobs();
|
|
280
613
|
const summary = jobs.length === 0
|
|
@@ -306,6 +639,13 @@ class OuroDaemon {
|
|
|
306
639
|
data: messages,
|
|
307
640
|
};
|
|
308
641
|
}
|
|
642
|
+
case "inner.wake":
|
|
643
|
+
await this.processManager.startAgent(command.agent);
|
|
644
|
+
this.processManager.sendToAgent?.(command.agent, { type: "message" });
|
|
645
|
+
return {
|
|
646
|
+
ok: true,
|
|
647
|
+
message: `woke inner dialog for ${command.agent}`,
|
|
648
|
+
};
|
|
309
649
|
case "chat.connect":
|
|
310
650
|
await this.processManager.startAgent(command.agent);
|
|
311
651
|
return {
|
|
@@ -328,6 +668,35 @@ class OuroDaemon {
|
|
|
328
668
|
data: receipt,
|
|
329
669
|
};
|
|
330
670
|
}
|
|
671
|
+
case "habit.poke": {
|
|
672
|
+
this.processManager.sendToAgent?.(command.agent, { type: "habit", habitName: command.habitName });
|
|
673
|
+
return {
|
|
674
|
+
ok: true,
|
|
675
|
+
message: `poked habit ${command.habitName} for ${command.agent}`,
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
case "mcp.list": {
|
|
679
|
+
const mcpManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
680
|
+
if (!mcpManager) {
|
|
681
|
+
return { ok: true, data: [], message: "no MCP servers configured" };
|
|
682
|
+
}
|
|
683
|
+
return { ok: true, data: mcpManager.listAllTools() };
|
|
684
|
+
}
|
|
685
|
+
case "mcp.call": {
|
|
686
|
+
const mcpCallManager = await (0, mcp_manager_1.getSharedMcpManager)();
|
|
687
|
+
if (!mcpCallManager) {
|
|
688
|
+
return { ok: false, error: "no MCP servers configured" };
|
|
689
|
+
}
|
|
690
|
+
try {
|
|
691
|
+
const parsedArgs = command.args ? JSON.parse(command.args) : {};
|
|
692
|
+
const result = await mcpCallManager.callTool(command.server, command.tool, parsedArgs);
|
|
693
|
+
return { ok: true, data: result };
|
|
694
|
+
}
|
|
695
|
+
catch (error) {
|
|
696
|
+
/* v8 ignore next -- defensive: callTool errors are always Error instances @preserve */
|
|
697
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
698
|
+
}
|
|
699
|
+
}
|
|
331
700
|
case "hatch.start":
|
|
332
701
|
return {
|
|
333
702
|
ok: true,
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.migrateHabitsFromTaskSystem = migrateHabitsFromTaskSystem;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
40
|
+
const habit_parser_1 = require("./habit-parser");
|
|
41
|
+
const parser_1 = require("../../repertoire/tasks/parser");
|
|
42
|
+
/** Fields that belong to the task system and should be stripped from migrated habits. */
|
|
43
|
+
const TASK_ONLY_FIELDS = new Set([
|
|
44
|
+
"type",
|
|
45
|
+
"category",
|
|
46
|
+
"requester",
|
|
47
|
+
"validator",
|
|
48
|
+
"scheduledAt",
|
|
49
|
+
"updated",
|
|
50
|
+
"depends_on",
|
|
51
|
+
"parent_task",
|
|
52
|
+
"artifacts",
|
|
53
|
+
]);
|
|
54
|
+
/** Regex matching the YYYY-MM-DD-HHMM- timestamp prefix in task filenames. */
|
|
55
|
+
const TIMESTAMP_PREFIX = /^\d{4}-\d{2}-\d{2}-\d{4}-/;
|
|
56
|
+
/** Map old task statuses to habit statuses. */
|
|
57
|
+
function mapStatus(taskStatus) {
|
|
58
|
+
if (taskStatus === "processing")
|
|
59
|
+
return "active";
|
|
60
|
+
if (taskStatus === "paused")
|
|
61
|
+
return "paused";
|
|
62
|
+
if (taskStatus === "done")
|
|
63
|
+
return null; // skip done habits
|
|
64
|
+
return "active"; // default to active for unknown statuses
|
|
65
|
+
}
|
|
66
|
+
/** Strip timestamp prefix from filename to get the slug name. */
|
|
67
|
+
function stripTimestampPrefix(filename) {
|
|
68
|
+
return filename.replace(TIMESTAMP_PREFIX, "");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Migrate habit files from the old `tasks/habits/` location to the new `habits/` bundle root.
|
|
72
|
+
* - Strips timestamp prefix from filenames
|
|
73
|
+
* - Maps task statuses to habit statuses
|
|
74
|
+
* - Strips task-only frontmatter fields
|
|
75
|
+
* - Preserves body text
|
|
76
|
+
* - Skips done habits, README files, and already-migrated habits
|
|
77
|
+
* - No-op if `tasks/habits/` does not exist
|
|
78
|
+
*/
|
|
79
|
+
function migrateHabitsFromTaskSystem(bundleRoot) {
|
|
80
|
+
const oldHabitsDir = path.join(bundleRoot, "tasks", "habits");
|
|
81
|
+
if (!fs.existsSync(oldHabitsDir)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
let files;
|
|
85
|
+
try {
|
|
86
|
+
files = fs.readdirSync(oldHabitsDir);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
/* v8 ignore next -- race condition: dir removed between existsSync and readdirSync @preserve */
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const mdFiles = files.filter((f) => f.endsWith(".md") && f !== "README.md");
|
|
93
|
+
if (mdFiles.length === 0)
|
|
94
|
+
return;
|
|
95
|
+
const newHabitsDir = path.join(bundleRoot, "habits");
|
|
96
|
+
fs.mkdirSync(newHabitsDir, { recursive: true });
|
|
97
|
+
let migratedCount = 0;
|
|
98
|
+
for (const file of mdFiles) {
|
|
99
|
+
const slugName = stripTimestampPrefix(file);
|
|
100
|
+
const targetPath = path.join(newHabitsDir, slugName);
|
|
101
|
+
// Skip if already migrated
|
|
102
|
+
if (fs.existsSync(targetPath)) {
|
|
103
|
+
(0, runtime_1.emitNervesEvent)({
|
|
104
|
+
component: "daemon",
|
|
105
|
+
event: "daemon.habit_migration_skip",
|
|
106
|
+
message: "habit already exists at target, skipping",
|
|
107
|
+
meta: { file, targetPath },
|
|
108
|
+
});
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const sourcePath = path.join(oldHabitsDir, file);
|
|
112
|
+
let content;
|
|
113
|
+
try {
|
|
114
|
+
content = fs.readFileSync(sourcePath, "utf-8");
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
// Parse frontmatter and body
|
|
120
|
+
const lines = content.split(/\r?\n/);
|
|
121
|
+
if (lines[0]?.trim() !== "---")
|
|
122
|
+
continue;
|
|
123
|
+
const closing = lines.findIndex((line, index) => index > 0 && line.trim() === "---");
|
|
124
|
+
if (closing === -1)
|
|
125
|
+
continue;
|
|
126
|
+
const rawFrontmatter = lines.slice(1, closing).join("\n");
|
|
127
|
+
const body = lines.slice(closing + 1).join("\n").trim();
|
|
128
|
+
const frontmatter = (0, parser_1.parseFrontmatter)(rawFrontmatter);
|
|
129
|
+
// Check status — skip done habits
|
|
130
|
+
const rawStatus = typeof frontmatter.status === "string" ? frontmatter.status : "processing";
|
|
131
|
+
const habitStatus = mapStatus(rawStatus);
|
|
132
|
+
if (habitStatus === null) {
|
|
133
|
+
(0, runtime_1.emitNervesEvent)({
|
|
134
|
+
component: "daemon",
|
|
135
|
+
event: "daemon.habit_migration_skip",
|
|
136
|
+
message: "skipping done habit",
|
|
137
|
+
meta: { file, status: rawStatus },
|
|
138
|
+
});
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
// Build new frontmatter, stripping task-only fields
|
|
142
|
+
const newFrontmatter = {};
|
|
143
|
+
if (typeof frontmatter.title === "string")
|
|
144
|
+
newFrontmatter.title = frontmatter.title;
|
|
145
|
+
if (typeof frontmatter.cadence === "string")
|
|
146
|
+
newFrontmatter.cadence = frontmatter.cadence;
|
|
147
|
+
newFrontmatter.status = habitStatus;
|
|
148
|
+
newFrontmatter.lastRun = typeof frontmatter.lastRun === "string" && frontmatter.lastRun !== "null"
|
|
149
|
+
? frontmatter.lastRun
|
|
150
|
+
: "null";
|
|
151
|
+
newFrontmatter.created = typeof frontmatter.created === "string" ? frontmatter.created : "null";
|
|
152
|
+
// Add any other non-task fields from original
|
|
153
|
+
for (const [key, value] of Object.entries(frontmatter)) {
|
|
154
|
+
if (TASK_ONLY_FIELDS.has(key))
|
|
155
|
+
continue;
|
|
156
|
+
if (key in newFrontmatter)
|
|
157
|
+
continue;
|
|
158
|
+
/* v8 ignore next -- dead code: status is caught by `key in newFrontmatter` above since newFrontmatter.status is always set @preserve */
|
|
159
|
+
if (key === "status")
|
|
160
|
+
continue; // already mapped
|
|
161
|
+
newFrontmatter[key] = value;
|
|
162
|
+
}
|
|
163
|
+
const rendered = (0, habit_parser_1.renderHabitFile)(newFrontmatter, body);
|
|
164
|
+
fs.writeFileSync(targetPath, rendered, "utf-8");
|
|
165
|
+
migratedCount++;
|
|
166
|
+
(0, runtime_1.emitNervesEvent)({
|
|
167
|
+
component: "daemon",
|
|
168
|
+
event: "daemon.habit_migrated",
|
|
169
|
+
message: "migrated habit from task system",
|
|
170
|
+
meta: { from: sourcePath, to: targetPath },
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (migratedCount > 0) {
|
|
174
|
+
(0, runtime_1.emitNervesEvent)({
|
|
175
|
+
component: "daemon",
|
|
176
|
+
event: "daemon.habit_migration_complete",
|
|
177
|
+
message: "habit migration complete",
|
|
178
|
+
meta: { bundleRoot, count: migratedCount },
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|