@ouro.bot/cli 0.1.0-alpha.7 → 0.1.0-alpha.71
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 +70 -9
- package/AdoptionSpecialist.ouro/psyche/SOUL.md +5 -2
- package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
- package/README.md +147 -205
- package/assets/ouroboros.png +0 -0
- package/changelog.json +395 -0
- package/dist/heart/active-work.js +178 -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/config.js +68 -23
- package/dist/heart/core.js +282 -92
- package/dist/heart/cross-chat-delivery.js +146 -0
- package/dist/heart/daemon/agent-discovery.js +81 -0
- package/dist/heart/daemon/auth-flow.js +409 -0
- package/dist/heart/daemon/daemon-cli.js +1408 -248
- package/dist/heart/daemon/daemon-entry.js +55 -6
- package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
- package/dist/heart/daemon/daemon.js +216 -10
- package/dist/heart/daemon/hatch-animation.js +10 -3
- package/dist/heart/daemon/hatch-flow.js +7 -82
- package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
- package/dist/heart/daemon/launchd.js +159 -0
- package/dist/heart/daemon/log-tailer.js +4 -3
- package/dist/heart/daemon/message-router.js +17 -8
- package/dist/heart/daemon/ouro-bot-entry.js +0 -0
- package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
- package/dist/heart/daemon/ouro-entry.js +0 -0
- package/dist/heart/daemon/ouro-path-installer.js +178 -0
- package/dist/heart/daemon/ouro-uti.js +11 -2
- package/dist/heart/daemon/process-manager.js +14 -1
- 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 +307 -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 +53 -84
- package/dist/heart/daemon/specialist-prompt.js +64 -5
- package/dist/heart/daemon/specialist-tools.js +213 -58
- package/dist/heart/daemon/staged-restart.js +114 -0
- package/dist/heart/daemon/thoughts.js +379 -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 +126 -21
- package/dist/heart/kicks.js +1 -19
- package/dist/heart/model-capabilities.js +48 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/providers/anthropic.js +74 -9
- package/dist/heart/providers/azure.js +86 -7
- package/dist/heart/providers/github-copilot.js +149 -0
- package/dist/heart/providers/minimax.js +4 -0
- package/dist/heart/providers/openai-codex.js +12 -3
- package/dist/heart/safe-workspace.js +228 -0
- package/dist/heart/sense-truth.js +61 -0
- package/dist/heart/session-activity.js +169 -0
- package/dist/heart/session-recall.js +116 -0
- package/dist/heart/streaming.js +100 -22
- package/dist/heart/target-resolution.js +123 -0
- package/dist/heart/turn-coordinator.js +28 -0
- package/dist/mind/associative-recall.js +14 -2
- package/dist/mind/bundle-manifest.js +70 -0
- package/dist/mind/context.js +27 -11
- package/dist/mind/first-impressions.js +16 -2
- package/dist/mind/friends/channel.js +35 -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/memory.js +27 -26
- package/dist/mind/pending.js +72 -9
- package/dist/mind/phrases.js +1 -0
- package/dist/mind/prompt.js +358 -77
- 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/repertoire/ado-client.js +4 -2
- package/dist/repertoire/coding/feedback.js +134 -0
- package/dist/repertoire/coding/index.js +4 -1
- package/dist/repertoire/coding/manager.js +62 -4
- package/dist/repertoire/coding/spawner.js +3 -3
- package/dist/repertoire/coding/tools.js +41 -2
- package/dist/repertoire/data/ado-endpoints.json +188 -0
- package/dist/repertoire/guardrails.js +279 -0
- package/dist/repertoire/mcp-client.js +254 -0
- package/dist/repertoire/mcp-manager.js +195 -0
- package/dist/repertoire/skills.js +3 -26
- package/dist/repertoire/tasks/board.js +12 -0
- package/dist/repertoire/tasks/index.js +23 -9
- package/dist/repertoire/tasks/transitions.js +1 -2
- package/dist/repertoire/tools-base.js +642 -251
- package/dist/repertoire/tools-bluebubbles.js +93 -0
- package/dist/repertoire/tools-teams.js +58 -25
- package/dist/repertoire/tools.js +93 -52
- package/dist/senses/bluebubbles-client.js +210 -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 +893 -45
- package/dist/senses/cli-layout.js +87 -0
- package/dist/senses/cli.js +348 -144
- package/dist/senses/continuity.js +94 -0
- package/dist/senses/debug-activity.js +148 -0
- package/dist/senses/inner-dialog-worker.js +47 -18
- package/dist/senses/inner-dialog.js +333 -84
- package/dist/senses/pipeline.js +278 -0
- package/dist/senses/teams.js +573 -129
- package/dist/senses/trust-gate.js +112 -2
- package/package.json +14 -3
- package/subagents/README.md +4 -70
- package/dist/heart/daemon/specialist-session.js +0 -142
- package/dist/heart/daemon/subagent-installer.js +0 -125
- package/dist/inner-worker-entry.js +0 -4
- package/subagents/work-doer.md +0 -233
- package/subagents/work-merger.md +0 -624
- package/subagents/work-planner.md +0 -373
|
@@ -35,11 +35,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ensureDaemonRunning = ensureDaemonRunning;
|
|
37
37
|
exports.parseOuroCommand = parseOuroCommand;
|
|
38
|
+
exports.discoverExistingCredentials = discoverExistingCredentials;
|
|
38
39
|
exports.createDefaultOuroCliDeps = createDefaultOuroCliDeps;
|
|
39
40
|
exports.runOuroCli = runOuroCli;
|
|
40
41
|
const child_process_1 = require("child_process");
|
|
42
|
+
const crypto_1 = require("crypto");
|
|
41
43
|
const fs = __importStar(require("fs"));
|
|
42
|
-
const net = __importStar(require("net"));
|
|
43
44
|
const os = __importStar(require("os"));
|
|
44
45
|
const path = __importStar(require("path"));
|
|
45
46
|
const identity_1 = require("../identity");
|
|
@@ -47,16 +48,201 @@ const runtime_1 = require("../../nerves/runtime");
|
|
|
47
48
|
const store_file_1 = require("../../mind/friends/store-file");
|
|
48
49
|
const types_1 = require("../../mind/friends/types");
|
|
49
50
|
const ouro_uti_1 = require("./ouro-uti");
|
|
50
|
-
const
|
|
51
|
+
const ouro_path_installer_1 = require("./ouro-path-installer");
|
|
52
|
+
const skill_management_installer_1 = require("./skill-management-installer");
|
|
51
53
|
const hatch_flow_1 = require("./hatch-flow");
|
|
52
54
|
const specialist_orchestrator_1 = require("./specialist-orchestrator");
|
|
55
|
+
const specialist_prompt_1 = require("./specialist-prompt");
|
|
56
|
+
const specialist_tools_1 = require("./specialist-tools");
|
|
57
|
+
const runtime_metadata_1 = require("./runtime-metadata");
|
|
58
|
+
const runtime_mode_1 = require("./runtime-mode");
|
|
59
|
+
const daemon_runtime_sync_1 = require("./daemon-runtime-sync");
|
|
60
|
+
const agent_discovery_1 = require("./agent-discovery");
|
|
61
|
+
const update_hooks_1 = require("./update-hooks");
|
|
62
|
+
const bundle_meta_1 = require("./hooks/bundle-meta");
|
|
63
|
+
const bundle_manifest_1 = require("../../mind/bundle-manifest");
|
|
64
|
+
const tasks_1 = require("../../repertoire/tasks");
|
|
65
|
+
const thoughts_1 = require("./thoughts");
|
|
66
|
+
const ouro_bot_global_installer_1 = require("./ouro-bot-global-installer");
|
|
67
|
+
const launchd_1 = require("./launchd");
|
|
68
|
+
const socket_client_1 = require("./socket-client");
|
|
69
|
+
const session_activity_1 = require("../session-activity");
|
|
70
|
+
const auth_flow_1 = require("./auth-flow");
|
|
71
|
+
function stringField(value) {
|
|
72
|
+
return typeof value === "string" ? value : null;
|
|
73
|
+
}
|
|
74
|
+
function numberField(value) {
|
|
75
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
76
|
+
}
|
|
77
|
+
function booleanField(value) {
|
|
78
|
+
return typeof value === "boolean" ? value : null;
|
|
79
|
+
}
|
|
80
|
+
function parseStatusPayload(data) {
|
|
81
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
82
|
+
return null;
|
|
83
|
+
const raw = data;
|
|
84
|
+
const overview = raw.overview;
|
|
85
|
+
const senses = raw.senses;
|
|
86
|
+
const workers = raw.workers;
|
|
87
|
+
if (!overview || typeof overview !== "object" || Array.isArray(overview))
|
|
88
|
+
return null;
|
|
89
|
+
if (!Array.isArray(senses) || !Array.isArray(workers))
|
|
90
|
+
return null;
|
|
91
|
+
const parsedOverview = {
|
|
92
|
+
daemon: stringField(overview.daemon) ?? "unknown",
|
|
93
|
+
health: stringField(overview.health) ?? "unknown",
|
|
94
|
+
socketPath: stringField(overview.socketPath) ?? "unknown",
|
|
95
|
+
version: stringField(overview.version) ?? "unknown",
|
|
96
|
+
lastUpdated: stringField(overview.lastUpdated) ?? "unknown",
|
|
97
|
+
repoRoot: stringField(overview.repoRoot) ?? "unknown",
|
|
98
|
+
configFingerprint: stringField(overview.configFingerprint) ?? "unknown",
|
|
99
|
+
workerCount: numberField(overview.workerCount) ?? 0,
|
|
100
|
+
senseCount: numberField(overview.senseCount) ?? 0,
|
|
101
|
+
entryPath: stringField(overview.entryPath) ?? "unknown",
|
|
102
|
+
mode: stringField(overview.mode) ?? "unknown",
|
|
103
|
+
};
|
|
104
|
+
const parsedSenses = senses.map((entry) => {
|
|
105
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
106
|
+
return null;
|
|
107
|
+
const row = entry;
|
|
108
|
+
const agent = stringField(row.agent);
|
|
109
|
+
const sense = stringField(row.sense);
|
|
110
|
+
const status = stringField(row.status);
|
|
111
|
+
const detail = stringField(row.detail);
|
|
112
|
+
const enabled = booleanField(row.enabled);
|
|
113
|
+
if (!agent || !sense || !status || detail === null || enabled === null)
|
|
114
|
+
return null;
|
|
115
|
+
return {
|
|
116
|
+
agent,
|
|
117
|
+
sense,
|
|
118
|
+
label: stringField(row.label) ?? undefined,
|
|
119
|
+
enabled,
|
|
120
|
+
status,
|
|
121
|
+
detail,
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
const parsedWorkers = workers.map((entry) => {
|
|
125
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
126
|
+
return null;
|
|
127
|
+
const row = entry;
|
|
128
|
+
const agent = stringField(row.agent);
|
|
129
|
+
const worker = stringField(row.worker);
|
|
130
|
+
const status = stringField(row.status);
|
|
131
|
+
const restartCount = numberField(row.restartCount);
|
|
132
|
+
const hasPid = Object.prototype.hasOwnProperty.call(row, "pid");
|
|
133
|
+
const pid = row.pid === null ? null : numberField(row.pid);
|
|
134
|
+
const pidInvalid = !hasPid || (row.pid !== null && pid === null);
|
|
135
|
+
if (!agent || !worker || !status || restartCount === null || pidInvalid)
|
|
136
|
+
return null;
|
|
137
|
+
return {
|
|
138
|
+
agent,
|
|
139
|
+
worker,
|
|
140
|
+
status,
|
|
141
|
+
pid,
|
|
142
|
+
restartCount,
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
if (parsedSenses.some((row) => row === null) || parsedWorkers.some((row) => row === null))
|
|
146
|
+
return null;
|
|
147
|
+
return {
|
|
148
|
+
overview: parsedOverview,
|
|
149
|
+
senses: parsedSenses,
|
|
150
|
+
workers: parsedWorkers,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function humanizeSenseName(sense, label) {
|
|
154
|
+
if (label)
|
|
155
|
+
return label;
|
|
156
|
+
if (sense === "cli")
|
|
157
|
+
return "CLI";
|
|
158
|
+
if (sense === "bluebubbles")
|
|
159
|
+
return "BlueBubbles";
|
|
160
|
+
if (sense === "teams")
|
|
161
|
+
return "Teams";
|
|
162
|
+
return sense;
|
|
163
|
+
}
|
|
164
|
+
function formatTable(headers, rows) {
|
|
165
|
+
const widths = headers.map((header, index) => Math.max(header.length, ...rows.map((row) => row[index].length)));
|
|
166
|
+
const renderRow = (row) => `| ${row.map((cell, index) => cell.padEnd(widths[index])).join(" | ")} |`;
|
|
167
|
+
const divider = `|-${widths.map((width) => "-".repeat(width)).join("-|-")}-|`;
|
|
168
|
+
return [
|
|
169
|
+
renderRow(headers),
|
|
170
|
+
divider,
|
|
171
|
+
...rows.map(renderRow),
|
|
172
|
+
].join("\n");
|
|
173
|
+
}
|
|
174
|
+
function formatDaemonStatusOutput(response, fallback) {
|
|
175
|
+
const payload = parseStatusPayload(response.data);
|
|
176
|
+
if (!payload)
|
|
177
|
+
return fallback;
|
|
178
|
+
const overviewRows = [
|
|
179
|
+
["Daemon", payload.overview.daemon],
|
|
180
|
+
["Socket", payload.overview.socketPath],
|
|
181
|
+
["Version", payload.overview.version],
|
|
182
|
+
["Last Updated", payload.overview.lastUpdated],
|
|
183
|
+
["Entry Path", payload.overview.entryPath],
|
|
184
|
+
["Mode", payload.overview.mode],
|
|
185
|
+
["Workers", String(payload.overview.workerCount)],
|
|
186
|
+
["Senses", String(payload.overview.senseCount)],
|
|
187
|
+
["Health", payload.overview.health],
|
|
188
|
+
];
|
|
189
|
+
const senseRows = payload.senses.map((row) => [
|
|
190
|
+
row.agent,
|
|
191
|
+
humanizeSenseName(row.sense, row.label),
|
|
192
|
+
row.enabled ? "ON" : "OFF",
|
|
193
|
+
row.status,
|
|
194
|
+
row.detail,
|
|
195
|
+
]);
|
|
196
|
+
const workerRows = payload.workers.map((row) => [
|
|
197
|
+
row.agent,
|
|
198
|
+
row.worker,
|
|
199
|
+
row.status,
|
|
200
|
+
row.pid === null ? "n/a" : String(row.pid),
|
|
201
|
+
String(row.restartCount),
|
|
202
|
+
]);
|
|
203
|
+
return [
|
|
204
|
+
"Overview",
|
|
205
|
+
formatTable(["Item", "Value"], overviewRows),
|
|
206
|
+
"",
|
|
207
|
+
"Senses",
|
|
208
|
+
formatTable(["Agent", "Sense", "Enabled", "State", "Detail"], senseRows),
|
|
209
|
+
"",
|
|
210
|
+
"Workers",
|
|
211
|
+
formatTable(["Agent", "Worker", "State", "PID", "Restarts"], workerRows),
|
|
212
|
+
].join("\n");
|
|
213
|
+
}
|
|
53
214
|
async function ensureDaemonRunning(deps) {
|
|
54
215
|
const alive = await deps.checkSocketAlive(deps.socketPath);
|
|
55
216
|
if (alive) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
217
|
+
const localRuntime = (0, runtime_metadata_1.getRuntimeMetadata)();
|
|
218
|
+
let runningRuntimePromise = null;
|
|
219
|
+
const fetchRunningRuntimeMetadata = async () => {
|
|
220
|
+
runningRuntimePromise ??= (async () => {
|
|
221
|
+
const status = await deps.sendCommand(deps.socketPath, { kind: "daemon.status" });
|
|
222
|
+
const payload = parseStatusPayload(status.data);
|
|
223
|
+
return {
|
|
224
|
+
version: payload?.overview.version ?? "unknown",
|
|
225
|
+
lastUpdated: payload?.overview.lastUpdated ?? "unknown",
|
|
226
|
+
repoRoot: payload?.overview.repoRoot ?? "unknown",
|
|
227
|
+
configFingerprint: payload?.overview.configFingerprint ?? "unknown",
|
|
228
|
+
};
|
|
229
|
+
})();
|
|
230
|
+
return runningRuntimePromise;
|
|
59
231
|
};
|
|
232
|
+
return (0, daemon_runtime_sync_1.ensureCurrentDaemonRuntime)({
|
|
233
|
+
socketPath: deps.socketPath,
|
|
234
|
+
localVersion: localRuntime.version,
|
|
235
|
+
localLastUpdated: localRuntime.lastUpdated,
|
|
236
|
+
localRepoRoot: localRuntime.repoRoot,
|
|
237
|
+
localConfigFingerprint: localRuntime.configFingerprint,
|
|
238
|
+
fetchRunningVersion: async () => (await fetchRunningRuntimeMetadata()).version,
|
|
239
|
+
fetchRunningRuntimeMetadata,
|
|
240
|
+
stopDaemon: async () => {
|
|
241
|
+
await deps.sendCommand(deps.socketPath, { kind: "daemon.stop" });
|
|
242
|
+
},
|
|
243
|
+
cleanupStaleSocket: deps.cleanupStaleSocket,
|
|
244
|
+
startDaemonProcess: deps.startDaemonProcess,
|
|
245
|
+
});
|
|
60
246
|
}
|
|
61
247
|
deps.cleanupStaleSocket(deps.socketPath);
|
|
62
248
|
const started = await deps.startDaemonProcess(deps.socketPath);
|
|
@@ -65,17 +251,90 @@ async function ensureDaemonRunning(deps) {
|
|
|
65
251
|
message: `daemon started (pid ${started.pid ?? "unknown"})`,
|
|
66
252
|
};
|
|
67
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Extract `--agent <name>` from an args array, returning the agent name and
|
|
256
|
+
* the remaining args with the flag pair removed.
|
|
257
|
+
*/
|
|
258
|
+
function extractAgentFlag(args) {
|
|
259
|
+
const idx = args.indexOf("--agent");
|
|
260
|
+
if (idx === -1 || idx + 1 >= args.length)
|
|
261
|
+
return { rest: args };
|
|
262
|
+
const agent = args[idx + 1];
|
|
263
|
+
const rest = [...args.slice(0, idx), ...args.slice(idx + 2)];
|
|
264
|
+
return { agent, rest };
|
|
265
|
+
}
|
|
68
266
|
function usage() {
|
|
69
267
|
return [
|
|
70
268
|
"Usage:",
|
|
71
269
|
" ouro [up]",
|
|
72
|
-
" ouro stop|status|logs|hatch",
|
|
270
|
+
" ouro stop|down|status|logs|hatch",
|
|
271
|
+
" ouro -v|--version",
|
|
272
|
+
" ouro auth --agent <name> [--provider <provider>]",
|
|
273
|
+
" ouro auth verify --agent <name> [--provider <provider>]",
|
|
274
|
+
" ouro auth switch --agent <name> --provider <provider>",
|
|
73
275
|
" ouro chat <agent>",
|
|
74
276
|
" ouro msg --to <agent> [--session <id>] [--task <ref>] <message>",
|
|
75
277
|
" ouro poke <agent> --task <task-id>",
|
|
76
278
|
" ouro link <agent> --friend <id> --provider <provider> --external-id <external-id>",
|
|
279
|
+
" ouro task board [<status>] [--agent <name>]",
|
|
280
|
+
" ouro task create <title> [--type <type>] [--agent <name>]",
|
|
281
|
+
" ouro task update <id> <status> [--agent <name>]",
|
|
282
|
+
" ouro task show <id> [--agent <name>]",
|
|
283
|
+
" ouro task actionable|deps|sessions [--agent <name>]",
|
|
284
|
+
" ouro reminder create <title> --body <body> [--at <iso>] [--cadence <interval>] [--category <category>] [--agent <name>]",
|
|
285
|
+
" ouro friend list [--agent <name>]",
|
|
286
|
+
" ouro friend show <id> [--agent <name>]",
|
|
287
|
+
" ouro friend create --name <name> [--trust <level>] [--agent <name>]",
|
|
288
|
+
" ouro thoughts [--last <n>] [--json] [--follow] [--agent <name>]",
|
|
289
|
+
" ouro friend link <agent> --friend <id> --provider <p> --external-id <eid>",
|
|
290
|
+
" ouro friend unlink <agent> --friend <id> --provider <p> --external-id <eid>",
|
|
291
|
+
" ouro whoami [--agent <name>]",
|
|
292
|
+
" ouro session list [--agent <name>]",
|
|
293
|
+
" ouro mcp list",
|
|
294
|
+
" ouro mcp call <server> <tool> [--args '{...}']",
|
|
295
|
+
].join("\n");
|
|
296
|
+
}
|
|
297
|
+
function formatVersionOutput() {
|
|
298
|
+
return (0, runtime_metadata_1.getRuntimeMetadata)().version;
|
|
299
|
+
}
|
|
300
|
+
function buildStoppedStatusPayload(socketPath) {
|
|
301
|
+
const metadata = (0, runtime_metadata_1.getRuntimeMetadata)();
|
|
302
|
+
const repoRoot = (0, identity_1.getRepoRoot)();
|
|
303
|
+
return {
|
|
304
|
+
overview: {
|
|
305
|
+
daemon: "stopped",
|
|
306
|
+
health: "warn",
|
|
307
|
+
socketPath,
|
|
308
|
+
version: metadata.version,
|
|
309
|
+
lastUpdated: metadata.lastUpdated,
|
|
310
|
+
repoRoot: metadata.repoRoot,
|
|
311
|
+
configFingerprint: metadata.configFingerprint,
|
|
312
|
+
workerCount: 0,
|
|
313
|
+
senseCount: 0,
|
|
314
|
+
entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
|
|
315
|
+
mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
|
|
316
|
+
},
|
|
317
|
+
senses: [],
|
|
318
|
+
workers: [],
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function daemonUnavailableStatusOutput(socketPath) {
|
|
322
|
+
return [
|
|
323
|
+
formatDaemonStatusOutput({
|
|
324
|
+
ok: true,
|
|
325
|
+
summary: "daemon not running",
|
|
326
|
+
data: buildStoppedStatusPayload(socketPath),
|
|
327
|
+
}, "daemon not running"),
|
|
328
|
+
"",
|
|
329
|
+
"daemon not running; run `ouro up`",
|
|
77
330
|
].join("\n");
|
|
78
331
|
}
|
|
332
|
+
function isDaemonUnavailableError(error) {
|
|
333
|
+
const code = typeof error === "object" && error !== null && "code" in error
|
|
334
|
+
? String(error.code ?? "")
|
|
335
|
+
: "";
|
|
336
|
+
return code === "ENOENT" || code === "ECONNREFUSED";
|
|
337
|
+
}
|
|
79
338
|
function parseMessageCommand(args) {
|
|
80
339
|
let to;
|
|
81
340
|
let sessionId;
|
|
@@ -127,7 +386,7 @@ function parsePokeCommand(args) {
|
|
|
127
386
|
throw new Error(`Usage\n${usage()}`);
|
|
128
387
|
return { kind: "task.poke", agent, taskId };
|
|
129
388
|
}
|
|
130
|
-
function parseLinkCommand(args) {
|
|
389
|
+
function parseLinkCommand(args, kind = "friend.link") {
|
|
131
390
|
const agent = args[0];
|
|
132
391
|
if (!agent)
|
|
133
392
|
throw new Error(`Usage\n${usage()}`);
|
|
@@ -159,7 +418,7 @@ function parseLinkCommand(args) {
|
|
|
159
418
|
throw new Error(`Unknown identity provider '${providerRaw}'. Use aad|local|teams-conversation.`);
|
|
160
419
|
}
|
|
161
420
|
return {
|
|
162
|
-
kind
|
|
421
|
+
kind,
|
|
163
422
|
agent,
|
|
164
423
|
friendId,
|
|
165
424
|
provider: providerRaw,
|
|
@@ -167,8 +426,67 @@ function parseLinkCommand(args) {
|
|
|
167
426
|
};
|
|
168
427
|
}
|
|
169
428
|
function isAgentProvider(value) {
|
|
170
|
-
return value === "azure" || value === "anthropic" || value === "minimax" || value === "openai-codex";
|
|
429
|
+
return value === "azure" || value === "anthropic" || value === "minimax" || value === "openai-codex" || value === "github-copilot";
|
|
430
|
+
}
|
|
431
|
+
/* v8 ignore start -- hasStoredCredentials: per-provider branches tested via auth switch tests @preserve */
|
|
432
|
+
function hasStoredCredentials(provider, providerSecrets) {
|
|
433
|
+
if (provider === "anthropic")
|
|
434
|
+
return !!providerSecrets.setupToken;
|
|
435
|
+
if (provider === "openai-codex")
|
|
436
|
+
return !!providerSecrets.oauthAccessToken;
|
|
437
|
+
if (provider === "github-copilot")
|
|
438
|
+
return !!providerSecrets.githubToken;
|
|
439
|
+
if (provider === "minimax")
|
|
440
|
+
return !!providerSecrets.apiKey;
|
|
441
|
+
// azure
|
|
442
|
+
return !!providerSecrets.endpoint && !!providerSecrets.apiKey;
|
|
443
|
+
}
|
|
444
|
+
/* v8 ignore stop */
|
|
445
|
+
/* v8 ignore start -- verifyProviderCredentials: per-provider branches tested via auth verify tests @preserve */
|
|
446
|
+
async function verifyProviderCredentials(provider, providers, fetchImpl = fetch) {
|
|
447
|
+
const p = providers[provider];
|
|
448
|
+
if (!p)
|
|
449
|
+
return "not configured";
|
|
450
|
+
if (provider === "anthropic") {
|
|
451
|
+
const token = p.setupToken || "";
|
|
452
|
+
if (!token)
|
|
453
|
+
return "failed (no token)";
|
|
454
|
+
if (token.startsWith("sk-ant-"))
|
|
455
|
+
return "ok";
|
|
456
|
+
return "failed (invalid token format)";
|
|
457
|
+
}
|
|
458
|
+
if (provider === "openai-codex") {
|
|
459
|
+
const token = p.oauthAccessToken || "";
|
|
460
|
+
return token ? "ok" : "failed (no token)";
|
|
461
|
+
}
|
|
462
|
+
if (provider === "github-copilot") {
|
|
463
|
+
const token = p.githubToken || "";
|
|
464
|
+
if (!token)
|
|
465
|
+
return "failed (no token)";
|
|
466
|
+
try {
|
|
467
|
+
const response = await fetchImpl("https://api.github.com/copilot_internal/user", {
|
|
468
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
469
|
+
});
|
|
470
|
+
return response.ok ? "ok" : `failed (HTTP ${response.status})`;
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
return `failed (${error.message})`;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (provider === "minimax") {
|
|
477
|
+
const apiKey = p.apiKey || "";
|
|
478
|
+
return apiKey ? "ok" : "failed (no api key)";
|
|
479
|
+
}
|
|
480
|
+
// azure
|
|
481
|
+
const endpoint = p.endpoint || "";
|
|
482
|
+
const apiKey = p.apiKey || "";
|
|
483
|
+
if (!endpoint)
|
|
484
|
+
return "failed (no endpoint)";
|
|
485
|
+
if (!apiKey)
|
|
486
|
+
return "failed (no api key)";
|
|
487
|
+
return "ok";
|
|
171
488
|
}
|
|
489
|
+
/* v8 ignore stop */
|
|
172
490
|
function parseHatchCommand(args) {
|
|
173
491
|
let agentName;
|
|
174
492
|
let humanName;
|
|
@@ -224,7 +542,7 @@ function parseHatchCommand(args) {
|
|
|
224
542
|
}
|
|
225
543
|
}
|
|
226
544
|
if (providerRaw && !isAgentProvider(providerRaw)) {
|
|
227
|
-
throw new Error("Unknown provider. Use azure|anthropic|minimax|openai-codex.");
|
|
545
|
+
throw new Error("Unknown provider. Use azure|anthropic|minimax|openai-codex|github-copilot.");
|
|
228
546
|
}
|
|
229
547
|
const provider = providerRaw && isAgentProvider(providerRaw) ? providerRaw : undefined;
|
|
230
548
|
return {
|
|
@@ -236,13 +554,245 @@ function parseHatchCommand(args) {
|
|
|
236
554
|
migrationPath,
|
|
237
555
|
};
|
|
238
556
|
}
|
|
557
|
+
function parseTaskCommand(args) {
|
|
558
|
+
const { agent, rest: cleaned } = extractAgentFlag(args);
|
|
559
|
+
const [sub, ...rest] = cleaned;
|
|
560
|
+
if (!sub)
|
|
561
|
+
throw new Error(`Usage\n${usage()}`);
|
|
562
|
+
if (sub === "board") {
|
|
563
|
+
const status = rest[0];
|
|
564
|
+
return status
|
|
565
|
+
? { kind: "task.board", status, ...(agent ? { agent } : {}) }
|
|
566
|
+
: { kind: "task.board", ...(agent ? { agent } : {}) };
|
|
567
|
+
}
|
|
568
|
+
if (sub === "create") {
|
|
569
|
+
const title = rest[0];
|
|
570
|
+
if (!title)
|
|
571
|
+
throw new Error(`Usage\n${usage()}`);
|
|
572
|
+
let type;
|
|
573
|
+
for (let i = 1; i < rest.length; i++) {
|
|
574
|
+
if (rest[i] === "--type" && rest[i + 1]) {
|
|
575
|
+
type = rest[i + 1];
|
|
576
|
+
i += 1;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return type
|
|
580
|
+
? { kind: "task.create", title, type, ...(agent ? { agent } : {}) }
|
|
581
|
+
: { kind: "task.create", title, ...(agent ? { agent } : {}) };
|
|
582
|
+
}
|
|
583
|
+
if (sub === "update") {
|
|
584
|
+
const id = rest[0];
|
|
585
|
+
const status = rest[1];
|
|
586
|
+
if (!id || !status)
|
|
587
|
+
throw new Error(`Usage\n${usage()}`);
|
|
588
|
+
return { kind: "task.update", id, status, ...(agent ? { agent } : {}) };
|
|
589
|
+
}
|
|
590
|
+
if (sub === "show") {
|
|
591
|
+
const id = rest[0];
|
|
592
|
+
if (!id)
|
|
593
|
+
throw new Error(`Usage\n${usage()}`);
|
|
594
|
+
return { kind: "task.show", id, ...(agent ? { agent } : {}) };
|
|
595
|
+
}
|
|
596
|
+
if (sub === "actionable")
|
|
597
|
+
return { kind: "task.actionable", ...(agent ? { agent } : {}) };
|
|
598
|
+
if (sub === "deps")
|
|
599
|
+
return { kind: "task.deps", ...(agent ? { agent } : {}) };
|
|
600
|
+
if (sub === "sessions")
|
|
601
|
+
return { kind: "task.sessions", ...(agent ? { agent } : {}) };
|
|
602
|
+
throw new Error(`Usage\n${usage()}`);
|
|
603
|
+
}
|
|
604
|
+
function parseAuthCommand(args) {
|
|
605
|
+
const first = args[0];
|
|
606
|
+
// Support both positional (`auth switch`) and flag (`auth --switch`) forms
|
|
607
|
+
if (first === "verify" || first === "switch" || first === "--verify" || first === "--switch") {
|
|
608
|
+
const subcommand = first.replace(/^--/, "");
|
|
609
|
+
const { agent, rest } = extractAgentFlag(args.slice(1));
|
|
610
|
+
let provider;
|
|
611
|
+
/* v8 ignore start -- provider flag parsing: branches tested via CLI parsing tests @preserve */
|
|
612
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
613
|
+
if (rest[i] === "--provider") {
|
|
614
|
+
const value = rest[i + 1];
|
|
615
|
+
if (!isAgentProvider(value))
|
|
616
|
+
throw new Error(`Usage\n${usage()}`);
|
|
617
|
+
provider = value;
|
|
618
|
+
i += 1;
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
/* v8 ignore stop */
|
|
623
|
+
/* v8 ignore next -- defensive: agent always provided in tests @preserve */
|
|
624
|
+
if (!agent)
|
|
625
|
+
throw new Error(`Usage\n${usage()}`);
|
|
626
|
+
if (subcommand === "switch") {
|
|
627
|
+
if (!provider)
|
|
628
|
+
throw new Error(`auth switch requires --provider.\n${usage()}`);
|
|
629
|
+
return { kind: "auth.switch", agent, provider };
|
|
630
|
+
}
|
|
631
|
+
return provider ? { kind: "auth.verify", agent, provider } : { kind: "auth.verify", agent };
|
|
632
|
+
}
|
|
633
|
+
const { agent, rest } = extractAgentFlag(args);
|
|
634
|
+
let provider;
|
|
635
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
636
|
+
if (rest[i] === "--provider") {
|
|
637
|
+
const value = rest[i + 1];
|
|
638
|
+
if (!isAgentProvider(value))
|
|
639
|
+
throw new Error(`Usage\n${usage()}`);
|
|
640
|
+
provider = value;
|
|
641
|
+
i += 1;
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (!agent)
|
|
646
|
+
throw new Error(`Usage\n${usage()}`);
|
|
647
|
+
return provider ? { kind: "auth.run", agent, provider } : { kind: "auth.run", agent };
|
|
648
|
+
}
|
|
649
|
+
function parseReminderCommand(args) {
|
|
650
|
+
const { agent, rest: cleaned } = extractAgentFlag(args);
|
|
651
|
+
const [sub, ...rest] = cleaned;
|
|
652
|
+
if (!sub)
|
|
653
|
+
throw new Error(`Usage\n${usage()}`);
|
|
654
|
+
if (sub === "create") {
|
|
655
|
+
const title = rest[0];
|
|
656
|
+
if (!title)
|
|
657
|
+
throw new Error(`Usage\n${usage()}`);
|
|
658
|
+
let body;
|
|
659
|
+
let scheduledAt;
|
|
660
|
+
let cadence;
|
|
661
|
+
let category;
|
|
662
|
+
let requester;
|
|
663
|
+
for (let i = 1; i < rest.length; i++) {
|
|
664
|
+
if (rest[i] === "--body" && rest[i + 1]) {
|
|
665
|
+
body = rest[i + 1];
|
|
666
|
+
i += 1;
|
|
667
|
+
}
|
|
668
|
+
else if (rest[i] === "--at" && rest[i + 1]) {
|
|
669
|
+
scheduledAt = rest[i + 1];
|
|
670
|
+
i += 1;
|
|
671
|
+
}
|
|
672
|
+
else if (rest[i] === "--cadence" && rest[i + 1]) {
|
|
673
|
+
cadence = rest[i + 1];
|
|
674
|
+
i += 1;
|
|
675
|
+
}
|
|
676
|
+
else if (rest[i] === "--category" && rest[i + 1]) {
|
|
677
|
+
category = rest[i + 1];
|
|
678
|
+
i += 1;
|
|
679
|
+
}
|
|
680
|
+
else if (rest[i] === "--requester" && rest[i + 1]) {
|
|
681
|
+
requester = rest[i + 1];
|
|
682
|
+
i += 1;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (!body)
|
|
686
|
+
throw new Error(`Usage\n${usage()}`);
|
|
687
|
+
if (!scheduledAt && !cadence)
|
|
688
|
+
throw new Error(`Usage\n${usage()}`);
|
|
689
|
+
return {
|
|
690
|
+
kind: "reminder.create",
|
|
691
|
+
title,
|
|
692
|
+
body,
|
|
693
|
+
...(scheduledAt ? { scheduledAt } : {}),
|
|
694
|
+
...(cadence ? { cadence } : {}),
|
|
695
|
+
...(category ? { category } : {}),
|
|
696
|
+
...(requester ? { requester } : {}),
|
|
697
|
+
...(agent ? { agent } : {}),
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
throw new Error(`Usage\n${usage()}`);
|
|
701
|
+
}
|
|
702
|
+
function parseSessionCommand(args) {
|
|
703
|
+
const { agent, rest: cleaned } = extractAgentFlag(args);
|
|
704
|
+
const [sub] = cleaned;
|
|
705
|
+
if (!sub)
|
|
706
|
+
throw new Error(`Usage\n${usage()}`);
|
|
707
|
+
if (sub === "list")
|
|
708
|
+
return { kind: "session.list", ...(agent ? { agent } : {}) };
|
|
709
|
+
throw new Error(`Usage\n${usage()}`);
|
|
710
|
+
}
|
|
711
|
+
function parseThoughtsCommand(args) {
|
|
712
|
+
const { agent, rest: cleaned } = extractAgentFlag(args);
|
|
713
|
+
let last;
|
|
714
|
+
let json = false;
|
|
715
|
+
let follow = false;
|
|
716
|
+
for (let i = 0; i < cleaned.length; i++) {
|
|
717
|
+
if (cleaned[i] === "--last" && i + 1 < cleaned.length) {
|
|
718
|
+
last = Number.parseInt(cleaned[i + 1], 10);
|
|
719
|
+
i++;
|
|
720
|
+
}
|
|
721
|
+
if (cleaned[i] === "--json")
|
|
722
|
+
json = true;
|
|
723
|
+
if (cleaned[i] === "--follow" || cleaned[i] === "-f")
|
|
724
|
+
follow = true;
|
|
725
|
+
}
|
|
726
|
+
return { kind: "thoughts", ...(agent ? { agent } : {}), ...(last ? { last } : {}), ...(json ? { json } : {}), ...(follow ? { follow } : {}) };
|
|
727
|
+
}
|
|
728
|
+
function parseFriendCommand(args) {
|
|
729
|
+
const { agent, rest: cleaned } = extractAgentFlag(args);
|
|
730
|
+
const [sub, ...rest] = cleaned;
|
|
731
|
+
if (!sub)
|
|
732
|
+
throw new Error(`Usage\n${usage()}`);
|
|
733
|
+
if (sub === "list")
|
|
734
|
+
return { kind: "friend.list", ...(agent ? { agent } : {}) };
|
|
735
|
+
if (sub === "show") {
|
|
736
|
+
const friendId = rest[0];
|
|
737
|
+
if (!friendId)
|
|
738
|
+
throw new Error(`Usage\n${usage()}`);
|
|
739
|
+
return { kind: "friend.show", friendId, ...(agent ? { agent } : {}) };
|
|
740
|
+
}
|
|
741
|
+
if (sub === "create") {
|
|
742
|
+
let name;
|
|
743
|
+
let trustLevel;
|
|
744
|
+
for (let i = 0; i < rest.length; i++) {
|
|
745
|
+
if (rest[i] === "--name" && rest[i + 1]) {
|
|
746
|
+
name = rest[i + 1];
|
|
747
|
+
i += 1;
|
|
748
|
+
}
|
|
749
|
+
else if (rest[i] === "--trust" && rest[i + 1]) {
|
|
750
|
+
trustLevel = rest[i + 1];
|
|
751
|
+
i += 1;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
if (!name)
|
|
755
|
+
throw new Error(`Usage\n${usage()}`);
|
|
756
|
+
return {
|
|
757
|
+
kind: "friend.create",
|
|
758
|
+
name,
|
|
759
|
+
...(trustLevel ? { trustLevel } : {}),
|
|
760
|
+
...(agent ? { agent } : {}),
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
if (sub === "link")
|
|
764
|
+
return parseLinkCommand(rest, "friend.link");
|
|
765
|
+
if (sub === "unlink")
|
|
766
|
+
return parseLinkCommand(rest, "friend.unlink");
|
|
767
|
+
throw new Error(`Usage\n${usage()}`);
|
|
768
|
+
}
|
|
769
|
+
function parseMcpCommand(args) {
|
|
770
|
+
const [sub, ...rest] = args;
|
|
771
|
+
if (!sub)
|
|
772
|
+
throw new Error(`Usage\n${usage()}`);
|
|
773
|
+
if (sub === "list")
|
|
774
|
+
return { kind: "mcp.list" };
|
|
775
|
+
if (sub === "call") {
|
|
776
|
+
const server = rest[0];
|
|
777
|
+
const tool = rest[1];
|
|
778
|
+
if (!server || !tool)
|
|
779
|
+
throw new Error(`Usage\n${usage()}`);
|
|
780
|
+
const argsIdx = rest.indexOf("--args");
|
|
781
|
+
const mcpArgs = argsIdx !== -1 && rest[argsIdx + 1] ? rest[argsIdx + 1] : undefined;
|
|
782
|
+
return { kind: "mcp.call", server, tool, ...(mcpArgs ? { args: mcpArgs } : {}) };
|
|
783
|
+
}
|
|
784
|
+
throw new Error(`Usage\n${usage()}`);
|
|
785
|
+
}
|
|
239
786
|
function parseOuroCommand(args) {
|
|
240
787
|
const [head, second] = args;
|
|
241
788
|
if (!head)
|
|
242
789
|
return { kind: "daemon.up" };
|
|
790
|
+
if (head === "--agent" && second) {
|
|
791
|
+
return parseOuroCommand(args.slice(2));
|
|
792
|
+
}
|
|
243
793
|
if (head === "up")
|
|
244
794
|
return { kind: "daemon.up" };
|
|
245
|
-
if (head === "stop")
|
|
795
|
+
if (head === "stop" || head === "down")
|
|
246
796
|
return { kind: "daemon.stop" };
|
|
247
797
|
if (head === "status")
|
|
248
798
|
return { kind: "daemon.status" };
|
|
@@ -250,6 +800,34 @@ function parseOuroCommand(args) {
|
|
|
250
800
|
return { kind: "daemon.logs" };
|
|
251
801
|
if (head === "hatch")
|
|
252
802
|
return parseHatchCommand(args.slice(1));
|
|
803
|
+
if (head === "auth")
|
|
804
|
+
return parseAuthCommand(args.slice(1));
|
|
805
|
+
if (head === "task")
|
|
806
|
+
return parseTaskCommand(args.slice(1));
|
|
807
|
+
if (head === "reminder")
|
|
808
|
+
return parseReminderCommand(args.slice(1));
|
|
809
|
+
if (head === "friend")
|
|
810
|
+
return parseFriendCommand(args.slice(1));
|
|
811
|
+
if (head === "mcp")
|
|
812
|
+
return parseMcpCommand(args.slice(1));
|
|
813
|
+
if (head === "whoami") {
|
|
814
|
+
const { agent } = extractAgentFlag(args.slice(1));
|
|
815
|
+
return { kind: "whoami", ...(agent ? { agent } : {}) };
|
|
816
|
+
}
|
|
817
|
+
if (head === "session")
|
|
818
|
+
return parseSessionCommand(args.slice(1));
|
|
819
|
+
if (head === "changelog") {
|
|
820
|
+
const sliced = args.slice(1);
|
|
821
|
+
const { agent, rest: remaining } = extractAgentFlag(sliced);
|
|
822
|
+
let from;
|
|
823
|
+
const fromIdx = remaining.indexOf("--from");
|
|
824
|
+
if (fromIdx !== -1 && remaining[fromIdx + 1]) {
|
|
825
|
+
from = remaining[fromIdx + 1];
|
|
826
|
+
}
|
|
827
|
+
return { kind: "changelog", ...(from ? { from } : {}), ...(agent ? { agent } : {}) };
|
|
828
|
+
}
|
|
829
|
+
if (head === "thoughts")
|
|
830
|
+
return parseThoughtsCommand(args.slice(1));
|
|
253
831
|
if (head === "chat") {
|
|
254
832
|
if (!second)
|
|
255
833
|
throw new Error(`Usage\n${usage()}`);
|
|
@@ -263,38 +841,6 @@ function parseOuroCommand(args) {
|
|
|
263
841
|
return parseLinkCommand(args.slice(1));
|
|
264
842
|
throw new Error(`Unknown command '${args.join(" ")}'.\n${usage()}`);
|
|
265
843
|
}
|
|
266
|
-
function defaultSendCommand(socketPath, command) {
|
|
267
|
-
return new Promise((resolve, reject) => {
|
|
268
|
-
const client = net.createConnection(socketPath);
|
|
269
|
-
let raw = "";
|
|
270
|
-
client.on("connect", () => {
|
|
271
|
-
client.write(JSON.stringify(command));
|
|
272
|
-
client.end();
|
|
273
|
-
});
|
|
274
|
-
client.on("data", (chunk) => {
|
|
275
|
-
raw += chunk.toString("utf-8");
|
|
276
|
-
});
|
|
277
|
-
client.on("error", reject);
|
|
278
|
-
client.on("end", () => {
|
|
279
|
-
const trimmed = raw.trim();
|
|
280
|
-
if (trimmed.length === 0 && command.kind === "daemon.stop") {
|
|
281
|
-
resolve({ ok: true, message: "daemon stopped" });
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
if (trimmed.length === 0) {
|
|
285
|
-
reject(new Error("Daemon returned empty response."));
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
try {
|
|
289
|
-
const parsed = JSON.parse(trimmed);
|
|
290
|
-
resolve(parsed);
|
|
291
|
-
}
|
|
292
|
-
catch (error) {
|
|
293
|
-
reject(error);
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
844
|
function defaultStartDaemonProcess(socketPath) {
|
|
299
845
|
const entry = path.join((0, identity_1.getRepoRoot)(), "dist", "heart", "daemon", "daemon-entry.js");
|
|
300
846
|
const child = (0, child_process_1.spawn)("node", [entry, "--socket", socketPath], {
|
|
@@ -308,46 +854,6 @@ function defaultWriteStdout(text) {
|
|
|
308
854
|
// eslint-disable-next-line no-console -- terminal UX: CLI command output
|
|
309
855
|
console.log(text);
|
|
310
856
|
}
|
|
311
|
-
function defaultCheckSocketAlive(socketPath) {
|
|
312
|
-
return new Promise((resolve) => {
|
|
313
|
-
const client = net.createConnection(socketPath);
|
|
314
|
-
let raw = "";
|
|
315
|
-
let done = false;
|
|
316
|
-
const finalize = (alive) => {
|
|
317
|
-
if (done)
|
|
318
|
-
return;
|
|
319
|
-
done = true;
|
|
320
|
-
resolve(alive);
|
|
321
|
-
};
|
|
322
|
-
if ("setTimeout" in client && typeof client.setTimeout === "function") {
|
|
323
|
-
client.setTimeout(800, () => {
|
|
324
|
-
client.destroy();
|
|
325
|
-
finalize(false);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
client.on("connect", () => {
|
|
329
|
-
client.write(JSON.stringify({ kind: "daemon.status" }));
|
|
330
|
-
client.end();
|
|
331
|
-
});
|
|
332
|
-
client.on("data", (chunk) => {
|
|
333
|
-
raw += chunk.toString("utf-8");
|
|
334
|
-
});
|
|
335
|
-
client.on("error", () => finalize(false));
|
|
336
|
-
client.on("end", () => {
|
|
337
|
-
if (raw.trim().length === 0) {
|
|
338
|
-
finalize(false);
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
try {
|
|
342
|
-
JSON.parse(raw);
|
|
343
|
-
finalize(true);
|
|
344
|
-
}
|
|
345
|
-
catch {
|
|
346
|
-
finalize(false);
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
857
|
function defaultCleanupStaleSocket(socketPath) {
|
|
352
858
|
if (fs.existsSync(socketPath)) {
|
|
353
859
|
fs.unlinkSync(socketPath);
|
|
@@ -382,9 +888,38 @@ function defaultFallbackPendingMessage(command) {
|
|
|
382
888
|
});
|
|
383
889
|
return pendingPath;
|
|
384
890
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
891
|
+
function defaultEnsureDaemonBootPersistence(socketPath) {
|
|
892
|
+
if (process.platform !== "darwin") {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
const homeDir = os.homedir();
|
|
896
|
+
const launchdDeps = {
|
|
897
|
+
exec: (cmd) => { (0, child_process_1.execSync)(cmd, { stdio: "ignore" }); },
|
|
898
|
+
writeFile: (filePath, content) => fs.writeFileSync(filePath, content, "utf-8"),
|
|
899
|
+
removeFile: (filePath) => fs.rmSync(filePath, { force: true }),
|
|
900
|
+
existsFile: (filePath) => fs.existsSync(filePath),
|
|
901
|
+
mkdirp: (dir) => fs.mkdirSync(dir, { recursive: true }),
|
|
902
|
+
homeDir,
|
|
903
|
+
userUid: process.getuid?.() ?? 0,
|
|
904
|
+
};
|
|
905
|
+
const entryPath = path.join((0, identity_1.getRepoRoot)(), "dist", "heart", "daemon", "daemon-entry.js");
|
|
906
|
+
/* v8 ignore next -- covered via mock in daemon-cli-defaults.test.ts; v8 on CI attributes the real fs.existsSync branch to the non-mock load @preserve */
|
|
907
|
+
if (!fs.existsSync(entryPath)) {
|
|
908
|
+
(0, runtime_1.emitNervesEvent)({
|
|
909
|
+
level: "warn",
|
|
910
|
+
component: "daemon",
|
|
911
|
+
event: "daemon.entry_path_missing",
|
|
912
|
+
message: "entryPath does not exist on disk — plist may point to a stale location. Run 'ouro daemon install' from the correct location.",
|
|
913
|
+
meta: { entryPath },
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
const logDir = (0, identity_1.getAgentDaemonLogsDir)();
|
|
917
|
+
(0, launchd_1.installLaunchAgent)(launchdDeps, {
|
|
918
|
+
nodePath: process.execPath,
|
|
919
|
+
entryPath,
|
|
920
|
+
socketPath,
|
|
921
|
+
logDir,
|
|
922
|
+
envPath: process.env.PATH,
|
|
388
923
|
});
|
|
389
924
|
}
|
|
390
925
|
async function defaultPromptInput(question) {
|
|
@@ -402,144 +937,316 @@ async function defaultPromptInput(question) {
|
|
|
402
937
|
}
|
|
403
938
|
}
|
|
404
939
|
function defaultListDiscoveredAgents() {
|
|
405
|
-
|
|
940
|
+
return (0, agent_discovery_1.listEnabledBundleAgents)({
|
|
941
|
+
bundlesRoot: (0, identity_1.getAgentBundlesRoot)(),
|
|
942
|
+
readdirSync: fs.readdirSync,
|
|
943
|
+
readFileSync: fs.readFileSync,
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
function discoverExistingCredentials(secretsRoot) {
|
|
947
|
+
const found = [];
|
|
406
948
|
let entries;
|
|
407
949
|
try {
|
|
408
|
-
entries = fs.readdirSync(
|
|
950
|
+
entries = fs.readdirSync(secretsRoot, { withFileTypes: true });
|
|
409
951
|
}
|
|
410
952
|
catch {
|
|
411
|
-
return
|
|
953
|
+
return found;
|
|
412
954
|
}
|
|
413
|
-
const discovered = [];
|
|
414
955
|
for (const entry of entries) {
|
|
415
|
-
if (!entry.isDirectory()
|
|
956
|
+
if (!entry.isDirectory())
|
|
416
957
|
continue;
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
let enabled = true;
|
|
958
|
+
const secretsPath = path.join(secretsRoot, entry.name, "secrets.json");
|
|
959
|
+
let raw;
|
|
420
960
|
try {
|
|
421
|
-
|
|
422
|
-
const parsed = JSON.parse(raw);
|
|
423
|
-
if (typeof parsed.enabled === "boolean") {
|
|
424
|
-
enabled = parsed.enabled;
|
|
425
|
-
}
|
|
961
|
+
raw = fs.readFileSync(secretsPath, "utf-8");
|
|
426
962
|
}
|
|
427
963
|
catch {
|
|
428
964
|
continue;
|
|
429
965
|
}
|
|
430
|
-
|
|
431
|
-
|
|
966
|
+
let parsed;
|
|
967
|
+
try {
|
|
968
|
+
parsed = JSON.parse(raw);
|
|
969
|
+
}
|
|
970
|
+
catch {
|
|
971
|
+
continue;
|
|
972
|
+
}
|
|
973
|
+
if (!parsed.providers)
|
|
974
|
+
continue;
|
|
975
|
+
for (const [provName, provConfig] of Object.entries(parsed.providers)) {
|
|
976
|
+
if (provName === "anthropic" && provConfig.setupToken) {
|
|
977
|
+
found.push({ agentName: entry.name, provider: "anthropic", credentials: { setupToken: provConfig.setupToken }, providerConfig: { ...provConfig } });
|
|
978
|
+
}
|
|
979
|
+
else if (provName === "openai-codex" && provConfig.oauthAccessToken) {
|
|
980
|
+
found.push({ agentName: entry.name, provider: "openai-codex", credentials: { oauthAccessToken: provConfig.oauthAccessToken }, providerConfig: { ...provConfig } });
|
|
981
|
+
}
|
|
982
|
+
else if (provName === "minimax" && provConfig.apiKey) {
|
|
983
|
+
found.push({ agentName: entry.name, provider: "minimax", credentials: { apiKey: provConfig.apiKey }, providerConfig: { ...provConfig } });
|
|
984
|
+
}
|
|
985
|
+
else if (provName === "azure" && provConfig.apiKey && provConfig.endpoint && provConfig.deployment) {
|
|
986
|
+
found.push({ agentName: entry.name, provider: "azure", credentials: { apiKey: provConfig.apiKey, endpoint: provConfig.endpoint, deployment: provConfig.deployment }, providerConfig: { ...provConfig } });
|
|
987
|
+
}
|
|
432
988
|
}
|
|
433
989
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const alreadyLinked = current.externalIds.some((ext) => ext.provider === command.provider && ext.externalId === command.externalId);
|
|
443
|
-
if (alreadyLinked) {
|
|
444
|
-
return `identity already linked: ${command.provider}:${command.externalId}`;
|
|
445
|
-
}
|
|
446
|
-
const now = new Date().toISOString();
|
|
447
|
-
await friendStore.put(command.friendId, {
|
|
448
|
-
...current,
|
|
449
|
-
externalIds: [
|
|
450
|
-
...current.externalIds,
|
|
451
|
-
{
|
|
452
|
-
provider: command.provider,
|
|
453
|
-
externalId: command.externalId,
|
|
454
|
-
linkedAt: now,
|
|
455
|
-
},
|
|
456
|
-
],
|
|
457
|
-
updatedAt: now,
|
|
990
|
+
// Deduplicate by provider+credential value (keep first seen)
|
|
991
|
+
const seen = new Set();
|
|
992
|
+
return found.filter((cred) => {
|
|
993
|
+
const key = `${cred.provider}:${JSON.stringify(cred.credentials)}`;
|
|
994
|
+
if (seen.has(key))
|
|
995
|
+
return false;
|
|
996
|
+
seen.add(key);
|
|
997
|
+
return true;
|
|
458
998
|
});
|
|
459
|
-
return `linked ${command.provider}:${command.externalId} to ${command.friendId}`;
|
|
460
999
|
}
|
|
461
|
-
/* v8 ignore
|
|
1000
|
+
/* v8 ignore start -- integration: interactive terminal specialist session @preserve */
|
|
462
1001
|
async function defaultRunAdoptionSpecialist() {
|
|
463
|
-
const
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
|
|
1002
|
+
const { runCliSession } = await Promise.resolve().then(() => __importStar(require("../../senses/cli")));
|
|
1003
|
+
const { patchRuntimeConfig } = await Promise.resolve().then(() => __importStar(require("../config")));
|
|
1004
|
+
const { setAgentName, setAgentConfigOverride } = await Promise.resolve().then(() => __importStar(require("../identity")));
|
|
1005
|
+
const readlinePromises = await Promise.resolve().then(() => __importStar(require("readline/promises")));
|
|
1006
|
+
const crypto = await Promise.resolve().then(() => __importStar(require("crypto")));
|
|
1007
|
+
// Phase 1: cold CLI — collect provider/credentials with a simple readline
|
|
1008
|
+
const coldRl = readlinePromises.createInterface({ input: process.stdin, output: process.stdout });
|
|
1009
|
+
const coldPrompt = async (q) => {
|
|
1010
|
+
const answer = await coldRl.question(q);
|
|
467
1011
|
return answer.trim();
|
|
468
1012
|
};
|
|
1013
|
+
let providerRaw;
|
|
1014
|
+
let credentials = {};
|
|
1015
|
+
let providerConfig = {};
|
|
1016
|
+
const tempDir = path.join(os.tmpdir(), `ouro-hatch-${crypto.randomUUID()}`);
|
|
469
1017
|
try {
|
|
470
|
-
const
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
1018
|
+
const secretsRoot = path.join(os.homedir(), ".agentsecrets");
|
|
1019
|
+
const discovered = discoverExistingCredentials(secretsRoot);
|
|
1020
|
+
const existingBundleCount = (0, specialist_orchestrator_1.listExistingBundles)((0, identity_1.getAgentBundlesRoot)()).length;
|
|
1021
|
+
const hatchVerb = existingBundleCount > 0 ? "let's hatch a new agent." : "let's hatch your first agent.";
|
|
1022
|
+
// Default models per provider (used when entering new credentials)
|
|
1023
|
+
const defaultModels = {
|
|
1024
|
+
anthropic: "claude-opus-4-6",
|
|
1025
|
+
minimax: "MiniMax-Text-01",
|
|
1026
|
+
"openai-codex": "gpt-5.4",
|
|
1027
|
+
"github-copilot": "claude-sonnet-4.6",
|
|
1028
|
+
azure: "",
|
|
1029
|
+
};
|
|
1030
|
+
if (discovered.length > 0) {
|
|
1031
|
+
process.stdout.write(`\n\ud83d\udc0d welcome to ouroboros! ${hatchVerb}\n`);
|
|
1032
|
+
process.stdout.write("i found existing API credentials:\n\n");
|
|
1033
|
+
const unique = [...new Map(discovered.map((d) => [`${d.provider}`, d])).values()];
|
|
1034
|
+
for (let i = 0; i < unique.length; i++) {
|
|
1035
|
+
const model = unique[i].providerConfig.model || unique[i].providerConfig.deployment || "";
|
|
1036
|
+
const modelLabel = model ? `, ${model}` : "";
|
|
1037
|
+
process.stdout.write(` ${i + 1}. ${unique[i].provider}${modelLabel} (from ${unique[i].agentName})\n`);
|
|
1038
|
+
}
|
|
1039
|
+
process.stdout.write("\n");
|
|
1040
|
+
const choice = await coldPrompt("use one of these? enter number, or 'new' for a different key: ");
|
|
1041
|
+
const idx = parseInt(choice, 10) - 1;
|
|
1042
|
+
if (idx >= 0 && idx < unique.length) {
|
|
1043
|
+
providerRaw = unique[idx].provider;
|
|
1044
|
+
credentials = unique[idx].credentials;
|
|
1045
|
+
providerConfig = unique[idx].providerConfig;
|
|
1046
|
+
}
|
|
1047
|
+
else {
|
|
1048
|
+
const pRaw = await coldPrompt("provider (anthropic/azure/minimax/openai-codex/github-copilot): ");
|
|
1049
|
+
if (!isAgentProvider(pRaw)) {
|
|
1050
|
+
process.stdout.write("unknown provider. run `ouro hatch` to try again.\n");
|
|
1051
|
+
coldRl.close();
|
|
1052
|
+
return null;
|
|
1053
|
+
}
|
|
1054
|
+
providerRaw = pRaw;
|
|
1055
|
+
providerConfig = { model: defaultModels[providerRaw] };
|
|
1056
|
+
if (providerRaw === "anthropic")
|
|
1057
|
+
credentials.setupToken = await coldPrompt("API key: ");
|
|
1058
|
+
if (providerRaw === "openai-codex")
|
|
1059
|
+
credentials.oauthAccessToken = await coldPrompt("OAuth token: ");
|
|
1060
|
+
if (providerRaw === "minimax")
|
|
1061
|
+
credentials.apiKey = await coldPrompt("API key: ");
|
|
1062
|
+
if (providerRaw === "azure") {
|
|
1063
|
+
credentials.apiKey = await coldPrompt("API key: ");
|
|
1064
|
+
credentials.endpoint = await coldPrompt("endpoint: ");
|
|
1065
|
+
credentials.deployment = await coldPrompt("deployment: ");
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
475
1068
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
1069
|
+
else {
|
|
1070
|
+
process.stdout.write(`\n\ud83d\udc0d welcome to ouroboros! ${hatchVerb}\n`);
|
|
1071
|
+
process.stdout.write("i need an API key to power our conversation.\n\n");
|
|
1072
|
+
const pRaw = await coldPrompt("provider (anthropic/azure/minimax/openai-codex/github-copilot): ");
|
|
1073
|
+
if (!isAgentProvider(pRaw)) {
|
|
1074
|
+
process.stdout.write("unknown provider. run `ouro hatch` to try again.\n");
|
|
1075
|
+
coldRl.close();
|
|
1076
|
+
return null;
|
|
1077
|
+
}
|
|
1078
|
+
providerRaw = pRaw;
|
|
1079
|
+
providerConfig = { model: defaultModels[providerRaw] };
|
|
1080
|
+
if (providerRaw === "anthropic")
|
|
1081
|
+
credentials.setupToken = await coldPrompt("API key: ");
|
|
1082
|
+
if (providerRaw === "openai-codex")
|
|
1083
|
+
credentials.oauthAccessToken = await coldPrompt("OAuth token: ");
|
|
1084
|
+
if (providerRaw === "minimax")
|
|
1085
|
+
credentials.apiKey = await coldPrompt("API key: ");
|
|
1086
|
+
if (providerRaw === "azure") {
|
|
1087
|
+
credentials.apiKey = await coldPrompt("API key: ");
|
|
1088
|
+
credentials.endpoint = await coldPrompt("endpoint: ");
|
|
1089
|
+
credentials.deployment = await coldPrompt("deployment: ");
|
|
1090
|
+
}
|
|
487
1091
|
}
|
|
488
|
-
|
|
489
|
-
|
|
1092
|
+
coldRl.close();
|
|
1093
|
+
process.stdout.write("\n");
|
|
1094
|
+
// Phase 2: configure runtime for adoption specialist
|
|
490
1095
|
const bundleSourceDir = path.resolve(__dirname, "..", "..", "..", "AdoptionSpecialist.ouro");
|
|
491
1096
|
const bundlesRoot = (0, identity_1.getAgentBundlesRoot)();
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
1097
|
+
const secretsRoot2 = path.join(os.homedir(), ".agentsecrets");
|
|
1098
|
+
// Suppress non-critical log noise during adoption (no secrets.json, etc.)
|
|
1099
|
+
const { setRuntimeLogger } = await Promise.resolve().then(() => __importStar(require("../../nerves/runtime")));
|
|
1100
|
+
const { createLogger } = await Promise.resolve().then(() => __importStar(require("../../nerves")));
|
|
1101
|
+
setRuntimeLogger(createLogger({ level: "error" }));
|
|
1102
|
+
// Configure runtime: set agent identity + config override so runAgent
|
|
1103
|
+
// doesn't try to read from ~/AgentBundles/AdoptionSpecialist.ouro/
|
|
1104
|
+
setAgentName("AdoptionSpecialist");
|
|
1105
|
+
// Build specialist system prompt
|
|
1106
|
+
const soulText = (0, specialist_orchestrator_1.loadSoulText)(bundleSourceDir);
|
|
1107
|
+
const identitiesDir = path.join(bundleSourceDir, "psyche", "identities");
|
|
1108
|
+
const identity = (0, specialist_orchestrator_1.pickRandomIdentity)(identitiesDir);
|
|
1109
|
+
// Load identity-specific spinner phrases (falls back to DEFAULT_AGENT_PHRASES)
|
|
1110
|
+
const { loadIdentityPhrases } = await Promise.resolve().then(() => __importStar(require("./specialist-orchestrator")));
|
|
1111
|
+
const phrases = loadIdentityPhrases(bundleSourceDir, identity.fileName);
|
|
1112
|
+
setAgentConfigOverride({
|
|
1113
|
+
version: 1,
|
|
1114
|
+
enabled: true,
|
|
497
1115
|
provider: providerRaw,
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
},
|
|
504
|
-
callbacks: {
|
|
505
|
-
onModelStart: () => { },
|
|
506
|
-
onModelStreamStart: () => { },
|
|
507
|
-
onTextChunk: (text) => process.stdout.write(text),
|
|
508
|
-
onReasoningChunk: () => { },
|
|
509
|
-
onToolStart: () => { },
|
|
510
|
-
onToolEnd: () => { },
|
|
511
|
-
onError: (err) => process.stderr.write(`error: ${err.message}\n`),
|
|
1116
|
+
phrases,
|
|
1117
|
+
});
|
|
1118
|
+
patchRuntimeConfig({
|
|
1119
|
+
providers: {
|
|
1120
|
+
[providerRaw]: { ...providerConfig, ...credentials },
|
|
512
1121
|
},
|
|
513
1122
|
});
|
|
1123
|
+
const existingBundles = (0, specialist_orchestrator_1.listExistingBundles)(bundlesRoot);
|
|
1124
|
+
const systemPrompt = (0, specialist_prompt_1.buildSpecialistSystemPrompt)(soulText, identity.content, existingBundles, {
|
|
1125
|
+
tempDir,
|
|
1126
|
+
provider: providerRaw,
|
|
1127
|
+
});
|
|
1128
|
+
// Build specialist tools
|
|
1129
|
+
const specialistTools = (0, specialist_tools_1.getSpecialistTools)();
|
|
1130
|
+
const specialistExecTool = (0, specialist_tools_1.createSpecialistExecTool)({
|
|
1131
|
+
tempDir,
|
|
1132
|
+
credentials,
|
|
1133
|
+
provider: providerRaw,
|
|
1134
|
+
bundlesRoot,
|
|
1135
|
+
secretsRoot: secretsRoot2,
|
|
1136
|
+
animationWriter: (text) => process.stdout.write(text),
|
|
1137
|
+
});
|
|
1138
|
+
// Run the adoption specialist session via runCliSession
|
|
1139
|
+
const result = await runCliSession({
|
|
1140
|
+
agentName: "AdoptionSpecialist",
|
|
1141
|
+
tools: specialistTools,
|
|
1142
|
+
execTool: specialistExecTool,
|
|
1143
|
+
exitOnToolCall: "complete_adoption",
|
|
1144
|
+
autoFirstTurn: true,
|
|
1145
|
+
banner: false,
|
|
1146
|
+
disableCommands: true,
|
|
1147
|
+
skipSystemPromptRefresh: true,
|
|
1148
|
+
messages: [
|
|
1149
|
+
{ role: "system", content: systemPrompt },
|
|
1150
|
+
{ role: "user", content: "hi" },
|
|
1151
|
+
],
|
|
1152
|
+
});
|
|
1153
|
+
if (result.exitReason === "tool_exit" && result.toolResult) {
|
|
1154
|
+
const parsed = typeof result.toolResult === "string" ? JSON.parse(result.toolResult) : result.toolResult;
|
|
1155
|
+
if (parsed.success && parsed.agentName) {
|
|
1156
|
+
return parsed.agentName;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return null;
|
|
514
1160
|
}
|
|
515
|
-
catch {
|
|
516
|
-
|
|
1161
|
+
catch (err) {
|
|
1162
|
+
process.stderr.write(`\nouro adoption error: ${err instanceof Error ? err.stack ?? err.message : String(err)}\n`);
|
|
1163
|
+
coldRl.close();
|
|
517
1164
|
return null;
|
|
518
1165
|
}
|
|
1166
|
+
finally {
|
|
1167
|
+
// Clear specialist config/identity so the hatched agent gets its own
|
|
1168
|
+
setAgentConfigOverride(null);
|
|
1169
|
+
const { resetProviderRuntime } = await Promise.resolve().then(() => __importStar(require("../core")));
|
|
1170
|
+
resetProviderRuntime();
|
|
1171
|
+
const { resetConfigCache } = await Promise.resolve().then(() => __importStar(require("../config")));
|
|
1172
|
+
resetConfigCache();
|
|
1173
|
+
// Restore default logging
|
|
1174
|
+
const { setRuntimeLogger: restoreLogger } = await Promise.resolve().then(() => __importStar(require("../../nerves/runtime")));
|
|
1175
|
+
restoreLogger(null);
|
|
1176
|
+
// Clean up temp dir if it still exists
|
|
1177
|
+
try {
|
|
1178
|
+
if (fs.existsSync(tempDir)) {
|
|
1179
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
catch {
|
|
1183
|
+
// Best effort cleanup
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
519
1186
|
}
|
|
520
|
-
|
|
1187
|
+
/* v8 ignore stop */
|
|
1188
|
+
function createDefaultOuroCliDeps(socketPath = socket_client_1.DEFAULT_DAEMON_SOCKET_PATH) {
|
|
521
1189
|
return {
|
|
522
1190
|
socketPath,
|
|
523
|
-
sendCommand:
|
|
1191
|
+
sendCommand: socket_client_1.sendDaemonCommand,
|
|
524
1192
|
startDaemonProcess: defaultStartDaemonProcess,
|
|
525
1193
|
writeStdout: defaultWriteStdout,
|
|
526
|
-
checkSocketAlive:
|
|
1194
|
+
checkSocketAlive: socket_client_1.checkDaemonSocketAlive,
|
|
527
1195
|
cleanupStaleSocket: defaultCleanupStaleSocket,
|
|
528
1196
|
fallbackPendingMessage: defaultFallbackPendingMessage,
|
|
529
|
-
installSubagents: defaultInstallSubagents,
|
|
530
|
-
linkFriendIdentity: defaultLinkFriendIdentity,
|
|
531
1197
|
listDiscoveredAgents: defaultListDiscoveredAgents,
|
|
532
1198
|
runHatchFlow: hatch_flow_1.runHatchFlow,
|
|
533
1199
|
promptInput: defaultPromptInput,
|
|
534
1200
|
runAdoptionSpecialist: defaultRunAdoptionSpecialist,
|
|
1201
|
+
runAuthFlow: auth_flow_1.runRuntimeAuthFlow,
|
|
535
1202
|
registerOuroBundleType: ouro_uti_1.registerOuroBundleUti,
|
|
1203
|
+
installOuroCommand: ouro_path_installer_1.installOuroCommand,
|
|
1204
|
+
syncGlobalOuroBotWrapper: ouro_bot_global_installer_1.syncGlobalOuroBotWrapper,
|
|
1205
|
+
ensureSkillManagement: skill_management_installer_1.ensureSkillManagement,
|
|
1206
|
+
ensureDaemonBootPersistence: defaultEnsureDaemonBootPersistence,
|
|
536
1207
|
/* v8 ignore next 3 -- integration: launches interactive CLI session @preserve */
|
|
537
1208
|
startChat: async (agentName) => {
|
|
538
1209
|
const { main } = await Promise.resolve().then(() => __importStar(require("../../senses/cli")));
|
|
539
1210
|
await main(agentName);
|
|
540
1211
|
},
|
|
1212
|
+
scanSessions: async () => {
|
|
1213
|
+
const agentName = (0, identity_1.getAgentName)();
|
|
1214
|
+
const agentRoot = (0, identity_1.getAgentRoot)(agentName);
|
|
1215
|
+
return (0, session_activity_1.listSessionActivity)({
|
|
1216
|
+
sessionsDir: path.join(agentRoot, "state", "sessions"),
|
|
1217
|
+
friendsDir: path.join(agentRoot, "friends"),
|
|
1218
|
+
agentName,
|
|
1219
|
+
}).map((entry) => ({
|
|
1220
|
+
friendId: entry.friendId,
|
|
1221
|
+
friendName: entry.friendName,
|
|
1222
|
+
channel: entry.channel,
|
|
1223
|
+
lastActivity: entry.lastActivityAt,
|
|
1224
|
+
}));
|
|
1225
|
+
},
|
|
541
1226
|
};
|
|
542
1227
|
}
|
|
1228
|
+
function formatMcpResponse(command, response) {
|
|
1229
|
+
if (command.kind === "mcp.list") {
|
|
1230
|
+
const allTools = response.data;
|
|
1231
|
+
if (!allTools || allTools.length === 0) {
|
|
1232
|
+
return response.message ?? "no tools available from connected MCP servers";
|
|
1233
|
+
}
|
|
1234
|
+
const lines = [];
|
|
1235
|
+
for (const entry of allTools) {
|
|
1236
|
+
lines.push(`[${entry.server}]`);
|
|
1237
|
+
for (const tool of entry.tools) {
|
|
1238
|
+
lines.push(` ${tool.name}: ${tool.description}`);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
return lines.join("\n");
|
|
1242
|
+
}
|
|
1243
|
+
// mcp.call
|
|
1244
|
+
const result = response.data;
|
|
1245
|
+
if (!result) {
|
|
1246
|
+
return response.message ?? "no result";
|
|
1247
|
+
}
|
|
1248
|
+
return result.content.map((c) => c.text).join("\n");
|
|
1249
|
+
}
|
|
543
1250
|
function toDaemonCommand(command) {
|
|
544
1251
|
return command;
|
|
545
1252
|
}
|
|
@@ -547,28 +1254,17 @@ async function resolveHatchInput(command, deps) {
|
|
|
547
1254
|
const prompt = deps.promptInput;
|
|
548
1255
|
const agentName = command.agentName ?? (prompt ? await prompt("Hatchling name: ") : "");
|
|
549
1256
|
const humanName = command.humanName ?? (prompt ? await prompt("Your name: ") : os.userInfo().username);
|
|
550
|
-
const providerRaw = command.provider ?? (prompt ? await prompt("Provider (azure|anthropic|minimax|openai-codex): ") : "");
|
|
1257
|
+
const providerRaw = command.provider ?? (prompt ? await prompt("Provider (azure|anthropic|minimax|openai-codex|github-copilot): ") : "");
|
|
551
1258
|
if (!agentName || !humanName || !isAgentProvider(providerRaw)) {
|
|
552
1259
|
throw new Error(`Usage\n${usage()}`);
|
|
553
1260
|
}
|
|
554
|
-
const credentials =
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
}
|
|
561
|
-
if (providerRaw === "minimax" && !credentials.apiKey && prompt) {
|
|
562
|
-
credentials.apiKey = await prompt("MiniMax API key: ");
|
|
563
|
-
}
|
|
564
|
-
if (providerRaw === "azure") {
|
|
565
|
-
if (!credentials.apiKey && prompt)
|
|
566
|
-
credentials.apiKey = await prompt("Azure API key: ");
|
|
567
|
-
if (!credentials.endpoint && prompt)
|
|
568
|
-
credentials.endpoint = await prompt("Azure endpoint: ");
|
|
569
|
-
if (!credentials.deployment && prompt)
|
|
570
|
-
credentials.deployment = await prompt("Azure deployment: ");
|
|
571
|
-
}
|
|
1261
|
+
const credentials = await (0, auth_flow_1.resolveHatchCredentials)({
|
|
1262
|
+
agentName,
|
|
1263
|
+
provider: providerRaw,
|
|
1264
|
+
credentials: command.credentials,
|
|
1265
|
+
promptInput: prompt,
|
|
1266
|
+
runAuthFlow: deps.runAuthFlow,
|
|
1267
|
+
});
|
|
572
1268
|
return {
|
|
573
1269
|
agentName,
|
|
574
1270
|
humanName,
|
|
@@ -594,12 +1290,240 @@ async function registerOuroBundleTypeNonBlocking(deps) {
|
|
|
594
1290
|
});
|
|
595
1291
|
}
|
|
596
1292
|
}
|
|
1293
|
+
async function performSystemSetup(deps) {
|
|
1294
|
+
// Install ouro command to PATH (non-blocking)
|
|
1295
|
+
if (deps.installOuroCommand) {
|
|
1296
|
+
try {
|
|
1297
|
+
deps.installOuroCommand();
|
|
1298
|
+
}
|
|
1299
|
+
catch (error) {
|
|
1300
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1301
|
+
level: "warn",
|
|
1302
|
+
component: "daemon",
|
|
1303
|
+
event: "daemon.system_setup_ouro_cmd_error",
|
|
1304
|
+
message: "failed to install ouro command to PATH",
|
|
1305
|
+
meta: { error: error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error) },
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if (deps.syncGlobalOuroBotWrapper) {
|
|
1310
|
+
try {
|
|
1311
|
+
await Promise.resolve(deps.syncGlobalOuroBotWrapper());
|
|
1312
|
+
}
|
|
1313
|
+
catch (error) {
|
|
1314
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1315
|
+
level: "warn",
|
|
1316
|
+
component: "daemon",
|
|
1317
|
+
event: "daemon.system_setup_ouro_bot_wrapper_error",
|
|
1318
|
+
message: "failed to sync global ouro.bot wrapper",
|
|
1319
|
+
meta: { error: error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error) },
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
// Ensure skill-management skill is available
|
|
1324
|
+
if (deps.ensureSkillManagement) {
|
|
1325
|
+
try {
|
|
1326
|
+
await deps.ensureSkillManagement();
|
|
1327
|
+
/* v8 ignore start -- defensive: ensureSkillManagement handles its own errors internally @preserve */
|
|
1328
|
+
}
|
|
1329
|
+
catch (error) {
|
|
1330
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1331
|
+
level: "warn",
|
|
1332
|
+
component: "daemon",
|
|
1333
|
+
event: "daemon.system_setup_skill_management_error",
|
|
1334
|
+
message: "failed to ensure skill-management skill",
|
|
1335
|
+
meta: { error: error instanceof Error ? error.message : String(error) },
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
/* v8 ignore stop */
|
|
1339
|
+
}
|
|
1340
|
+
// Register .ouro bundle type (UTI on macOS)
|
|
1341
|
+
await registerOuroBundleTypeNonBlocking(deps);
|
|
1342
|
+
}
|
|
1343
|
+
function executeTaskCommand(command, taskMod) {
|
|
1344
|
+
if (command.kind === "task.board") {
|
|
1345
|
+
if (command.status) {
|
|
1346
|
+
const lines = taskMod.boardStatus(command.status);
|
|
1347
|
+
return lines.length > 0 ? lines.join("\n") : "no tasks in that status";
|
|
1348
|
+
}
|
|
1349
|
+
const board = taskMod.getBoard();
|
|
1350
|
+
return board.full || board.compact || "no tasks found";
|
|
1351
|
+
}
|
|
1352
|
+
if (command.kind === "task.create") {
|
|
1353
|
+
try {
|
|
1354
|
+
const created = taskMod.createTask({
|
|
1355
|
+
title: command.title,
|
|
1356
|
+
type: command.type ?? "one-shot",
|
|
1357
|
+
category: "general",
|
|
1358
|
+
body: "",
|
|
1359
|
+
});
|
|
1360
|
+
return `created: ${created}`;
|
|
1361
|
+
}
|
|
1362
|
+
catch (error) {
|
|
1363
|
+
return `error: ${error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error)}`;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
if (command.kind === "task.update") {
|
|
1367
|
+
const result = taskMod.updateStatus(command.id, command.status);
|
|
1368
|
+
if (!result.ok) {
|
|
1369
|
+
return `error: ${result.reason ?? "status update failed"}`;
|
|
1370
|
+
}
|
|
1371
|
+
const archivedSuffix = result.archived && result.archived.length > 0
|
|
1372
|
+
? ` | archived: ${result.archived.join(", ")}`
|
|
1373
|
+
: "";
|
|
1374
|
+
return `updated: ${command.id} -> ${result.to}${archivedSuffix}`;
|
|
1375
|
+
}
|
|
1376
|
+
if (command.kind === "task.show") {
|
|
1377
|
+
const task = taskMod.getTask(command.id);
|
|
1378
|
+
if (!task)
|
|
1379
|
+
return `task not found: ${command.id}`;
|
|
1380
|
+
return [
|
|
1381
|
+
`title: ${task.title}`,
|
|
1382
|
+
`type: ${task.type}`,
|
|
1383
|
+
`status: ${task.status}`,
|
|
1384
|
+
`category: ${task.category}`,
|
|
1385
|
+
`created: ${task.created}`,
|
|
1386
|
+
`updated: ${task.updated}`,
|
|
1387
|
+
`path: ${task.path}`,
|
|
1388
|
+
task.body ? `\n${task.body}` : "",
|
|
1389
|
+
].filter(Boolean).join("\n");
|
|
1390
|
+
}
|
|
1391
|
+
if (command.kind === "task.actionable") {
|
|
1392
|
+
const lines = taskMod.boardAction();
|
|
1393
|
+
return lines.length > 0 ? lines.join("\n") : "no action required";
|
|
1394
|
+
}
|
|
1395
|
+
if (command.kind === "task.deps") {
|
|
1396
|
+
const lines = taskMod.boardDeps();
|
|
1397
|
+
return lines.length > 0 ? lines.join("\n") : "no unresolved dependencies";
|
|
1398
|
+
}
|
|
1399
|
+
// command.kind === "task.sessions"
|
|
1400
|
+
const lines = taskMod.boardSessions();
|
|
1401
|
+
return lines.length > 0 ? lines.join("\n") : "no active sessions";
|
|
1402
|
+
}
|
|
1403
|
+
const TRUST_RANK = { family: 4, friend: 3, acquaintance: 2, stranger: 1 };
|
|
1404
|
+
/* v8 ignore start -- defensive: ?? fallbacks are unreachable when inputs are valid TrustLevel values @preserve */
|
|
1405
|
+
function higherTrust(a, b) {
|
|
1406
|
+
const rankA = TRUST_RANK[a ?? "stranger"] ?? 1;
|
|
1407
|
+
const rankB = TRUST_RANK[b ?? "stranger"] ?? 1;
|
|
1408
|
+
return rankA >= rankB ? (a ?? "stranger") : (b ?? "stranger");
|
|
1409
|
+
}
|
|
1410
|
+
/* v8 ignore stop */
|
|
1411
|
+
async function executeFriendCommand(command, store) {
|
|
1412
|
+
if (command.kind === "friend.list") {
|
|
1413
|
+
const listAll = store.listAll;
|
|
1414
|
+
if (!listAll)
|
|
1415
|
+
return "friend store does not support listing";
|
|
1416
|
+
const friends = await listAll.call(store);
|
|
1417
|
+
if (friends.length === 0)
|
|
1418
|
+
return "no friends found";
|
|
1419
|
+
const lines = friends.map((f) => {
|
|
1420
|
+
const trust = f.trustLevel ?? "unknown";
|
|
1421
|
+
return `${f.id} ${f.name} ${trust}`;
|
|
1422
|
+
});
|
|
1423
|
+
return lines.join("\n");
|
|
1424
|
+
}
|
|
1425
|
+
if (command.kind === "friend.show") {
|
|
1426
|
+
const record = await store.get(command.friendId);
|
|
1427
|
+
if (!record)
|
|
1428
|
+
return `friend not found: ${command.friendId}`;
|
|
1429
|
+
return JSON.stringify(record, null, 2);
|
|
1430
|
+
}
|
|
1431
|
+
if (command.kind === "friend.create") {
|
|
1432
|
+
const now = new Date().toISOString();
|
|
1433
|
+
const id = (0, crypto_1.randomUUID)();
|
|
1434
|
+
const trustLevel = (command.trustLevel ?? "acquaintance");
|
|
1435
|
+
await store.put(id, {
|
|
1436
|
+
id,
|
|
1437
|
+
name: command.name,
|
|
1438
|
+
trustLevel,
|
|
1439
|
+
externalIds: [],
|
|
1440
|
+
tenantMemberships: [],
|
|
1441
|
+
toolPreferences: {},
|
|
1442
|
+
notes: {},
|
|
1443
|
+
totalTokens: 0,
|
|
1444
|
+
createdAt: now,
|
|
1445
|
+
updatedAt: now,
|
|
1446
|
+
schemaVersion: 1,
|
|
1447
|
+
});
|
|
1448
|
+
return `created: ${id} (${command.name}, ${trustLevel})`;
|
|
1449
|
+
}
|
|
1450
|
+
if (command.kind === "friend.link") {
|
|
1451
|
+
const current = await store.get(command.friendId);
|
|
1452
|
+
if (!current)
|
|
1453
|
+
return `friend not found: ${command.friendId}`;
|
|
1454
|
+
const alreadyLinked = current.externalIds.some((ext) => ext.provider === command.provider && ext.externalId === command.externalId);
|
|
1455
|
+
if (alreadyLinked)
|
|
1456
|
+
return `identity already linked: ${command.provider}:${command.externalId}`;
|
|
1457
|
+
const now = new Date().toISOString();
|
|
1458
|
+
const newExternalIds = [
|
|
1459
|
+
...current.externalIds,
|
|
1460
|
+
{ provider: command.provider, externalId: command.externalId, linkedAt: now },
|
|
1461
|
+
];
|
|
1462
|
+
// Orphan cleanup: check if another friend has this externalId
|
|
1463
|
+
const orphan = await store.findByExternalId(command.provider, command.externalId);
|
|
1464
|
+
let mergeMessage = "";
|
|
1465
|
+
let mergedNotes = { ...current.notes };
|
|
1466
|
+
let mergedTrust = current.trustLevel;
|
|
1467
|
+
let orphanExternalIds = [];
|
|
1468
|
+
if (orphan && orphan.id !== command.friendId) {
|
|
1469
|
+
// Merge orphan's notes (target's notes take priority)
|
|
1470
|
+
mergedNotes = { ...orphan.notes, ...current.notes };
|
|
1471
|
+
// Keep higher trust level
|
|
1472
|
+
mergedTrust = higherTrust(current.trustLevel, orphan.trustLevel);
|
|
1473
|
+
// Collect orphan's other externalIds (excluding the one being linked)
|
|
1474
|
+
orphanExternalIds = orphan.externalIds.filter((ext) => !(ext.provider === command.provider && ext.externalId === command.externalId));
|
|
1475
|
+
await store.delete(orphan.id);
|
|
1476
|
+
mergeMessage = ` (merged orphan ${orphan.id})`;
|
|
1477
|
+
}
|
|
1478
|
+
await store.put(command.friendId, {
|
|
1479
|
+
...current,
|
|
1480
|
+
externalIds: [...newExternalIds, ...orphanExternalIds],
|
|
1481
|
+
notes: mergedNotes,
|
|
1482
|
+
trustLevel: mergedTrust,
|
|
1483
|
+
updatedAt: now,
|
|
1484
|
+
});
|
|
1485
|
+
return `linked ${command.provider}:${command.externalId} to ${command.friendId}${mergeMessage}`;
|
|
1486
|
+
}
|
|
1487
|
+
// command.kind === "friend.unlink"
|
|
1488
|
+
const current = await store.get(command.friendId);
|
|
1489
|
+
if (!current)
|
|
1490
|
+
return `friend not found: ${command.friendId}`;
|
|
1491
|
+
const idx = current.externalIds.findIndex((ext) => ext.provider === command.provider && ext.externalId === command.externalId);
|
|
1492
|
+
if (idx === -1)
|
|
1493
|
+
return `identity not linked: ${command.provider}:${command.externalId}`;
|
|
1494
|
+
const now = new Date().toISOString();
|
|
1495
|
+
const filtered = current.externalIds.filter((_, i) => i !== idx);
|
|
1496
|
+
await store.put(command.friendId, { ...current, externalIds: filtered, updatedAt: now });
|
|
1497
|
+
return `unlinked ${command.provider}:${command.externalId} from ${command.friendId}`;
|
|
1498
|
+
}
|
|
1499
|
+
function executeReminderCommand(command, taskMod) {
|
|
1500
|
+
try {
|
|
1501
|
+
const created = taskMod.createTask({
|
|
1502
|
+
title: command.title,
|
|
1503
|
+
type: command.cadence ? "habit" : "one-shot",
|
|
1504
|
+
category: command.category ?? "reminder",
|
|
1505
|
+
body: command.body,
|
|
1506
|
+
scheduledAt: command.scheduledAt,
|
|
1507
|
+
cadence: command.cadence,
|
|
1508
|
+
requester: command.requester,
|
|
1509
|
+
});
|
|
1510
|
+
return `created: ${created}`;
|
|
1511
|
+
}
|
|
1512
|
+
catch (error) {
|
|
1513
|
+
return `error: ${error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error)}`;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
597
1516
|
async function runOuroCli(args, deps = createDefaultOuroCliDeps()) {
|
|
598
1517
|
if (args.includes("--help") || args.includes("-h")) {
|
|
599
1518
|
const text = usage();
|
|
600
1519
|
deps.writeStdout(text);
|
|
601
1520
|
return text;
|
|
602
1521
|
}
|
|
1522
|
+
if (args.length === 1 && (args[0] === "-v" || args[0] === "--version")) {
|
|
1523
|
+
const text = formatVersionOutput();
|
|
1524
|
+
deps.writeStdout(text);
|
|
1525
|
+
return text;
|
|
1526
|
+
}
|
|
603
1527
|
let command;
|
|
604
1528
|
try {
|
|
605
1529
|
command = parseOuroCommand(args);
|
|
@@ -618,23 +1542,12 @@ async function runOuroCli(args, deps = createDefaultOuroCliDeps()) {
|
|
|
618
1542
|
if (args.length === 0) {
|
|
619
1543
|
const discovered = await Promise.resolve(deps.listDiscoveredAgents ? deps.listDiscoveredAgents() : defaultListDiscoveredAgents());
|
|
620
1544
|
if (discovered.length === 0 && deps.runAdoptionSpecialist) {
|
|
1545
|
+
// System setup first — ouro command, subagents, UTI — before the interactive specialist
|
|
1546
|
+
await performSystemSetup(deps);
|
|
621
1547
|
const hatchlingName = await deps.runAdoptionSpecialist();
|
|
622
1548
|
if (!hatchlingName) {
|
|
623
1549
|
return "";
|
|
624
1550
|
}
|
|
625
|
-
try {
|
|
626
|
-
await deps.installSubagents();
|
|
627
|
-
}
|
|
628
|
-
catch (error) {
|
|
629
|
-
(0, runtime_1.emitNervesEvent)({
|
|
630
|
-
level: "warn",
|
|
631
|
-
component: "daemon",
|
|
632
|
-
event: "daemon.subagent_install_error",
|
|
633
|
-
message: "subagent auto-install failed",
|
|
634
|
-
meta: { error: error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error) },
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
await registerOuroBundleTypeNonBlocking(deps);
|
|
638
1551
|
await ensureDaemonRunning(deps);
|
|
639
1552
|
if (deps.startChat) {
|
|
640
1553
|
await deps.startChat(hatchlingName);
|
|
@@ -681,19 +1594,34 @@ async function runOuroCli(args, deps = createDefaultOuroCliDeps()) {
|
|
|
681
1594
|
meta: { kind: command.kind },
|
|
682
1595
|
});
|
|
683
1596
|
if (command.kind === "daemon.up") {
|
|
684
|
-
|
|
685
|
-
|
|
1597
|
+
await performSystemSetup(deps);
|
|
1598
|
+
if (deps.ensureDaemonBootPersistence) {
|
|
1599
|
+
try {
|
|
1600
|
+
await Promise.resolve(deps.ensureDaemonBootPersistence(deps.socketPath));
|
|
1601
|
+
}
|
|
1602
|
+
catch (error) {
|
|
1603
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1604
|
+
level: "warn",
|
|
1605
|
+
component: "daemon",
|
|
1606
|
+
event: "daemon.system_setup_launchd_error",
|
|
1607
|
+
message: "failed to persist daemon boot startup",
|
|
1608
|
+
meta: { error: error instanceof Error ? error.message : String(error), socketPath: deps.socketPath },
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
686
1611
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
1612
|
+
// Run update hooks before starting daemon so user sees the output
|
|
1613
|
+
(0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
|
|
1614
|
+
const bundlesRoot = (0, identity_1.getAgentBundlesRoot)();
|
|
1615
|
+
const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
|
|
1616
|
+
const updateSummary = await (0, update_hooks_1.applyPendingUpdates)(bundlesRoot, currentVersion);
|
|
1617
|
+
if (updateSummary.updated.length > 0) {
|
|
1618
|
+
const agents = updateSummary.updated.map((e) => e.agent);
|
|
1619
|
+
const from = updateSummary.updated[0].from;
|
|
1620
|
+
const to = updateSummary.updated[0].to;
|
|
1621
|
+
const fromStr = from ? ` (was ${from})` : "";
|
|
1622
|
+
const count = agents.length;
|
|
1623
|
+
deps.writeStdout(`updated ${count} agent${count === 1 ? "" : "s"} to runtime ${to}${fromStr}`);
|
|
695
1624
|
}
|
|
696
|
-
await registerOuroBundleTypeNonBlocking(deps);
|
|
697
1625
|
const daemonResult = await ensureDaemonRunning(deps);
|
|
698
1626
|
deps.writeStdout(daemonResult.message);
|
|
699
1627
|
return daemonResult.message;
|
|
@@ -702,33 +1630,264 @@ async function runOuroCli(args, deps = createDefaultOuroCliDeps()) {
|
|
|
702
1630
|
deps.tailLogs();
|
|
703
1631
|
return "";
|
|
704
1632
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
const
|
|
1633
|
+
// ── mcp subcommands (routed through daemon socket) ──
|
|
1634
|
+
if (command.kind === "mcp.list" || command.kind === "mcp.call") {
|
|
1635
|
+
const daemonCommand = toDaemonCommand(command);
|
|
1636
|
+
let response;
|
|
1637
|
+
try {
|
|
1638
|
+
response = await deps.sendCommand(deps.socketPath, daemonCommand);
|
|
1639
|
+
}
|
|
1640
|
+
catch {
|
|
1641
|
+
const message = "daemon unavailable — start with `ouro up` first";
|
|
1642
|
+
deps.writeStdout(message);
|
|
1643
|
+
return message;
|
|
1644
|
+
}
|
|
1645
|
+
if (!response.ok) {
|
|
1646
|
+
const message = response.error ?? "unknown error";
|
|
1647
|
+
deps.writeStdout(message);
|
|
1648
|
+
return message;
|
|
1649
|
+
}
|
|
1650
|
+
const message = formatMcpResponse(command, response);
|
|
1651
|
+
deps.writeStdout(message);
|
|
1652
|
+
return message;
|
|
1653
|
+
}
|
|
1654
|
+
// ── task subcommands (local, no daemon socket needed) ──
|
|
1655
|
+
if (command.kind === "task.board" || command.kind === "task.create" || command.kind === "task.update" ||
|
|
1656
|
+
command.kind === "task.show" || command.kind === "task.actionable" || command.kind === "task.deps" ||
|
|
1657
|
+
command.kind === "task.sessions") {
|
|
1658
|
+
/* v8 ignore start -- production default: requires full identity setup @preserve */
|
|
1659
|
+
const taskMod = deps.taskModule ?? (0, tasks_1.getTaskModule)();
|
|
1660
|
+
/* v8 ignore stop */
|
|
1661
|
+
const message = executeTaskCommand(command, taskMod);
|
|
1662
|
+
deps.writeStdout(message);
|
|
1663
|
+
return message;
|
|
1664
|
+
}
|
|
1665
|
+
// ── reminder subcommands (local, no daemon socket needed) ──
|
|
1666
|
+
if (command.kind === "reminder.create") {
|
|
1667
|
+
/* v8 ignore start -- production default: requires full identity setup @preserve */
|
|
1668
|
+
const taskMod = deps.taskModule ?? (0, tasks_1.getTaskModule)();
|
|
1669
|
+
/* v8 ignore stop */
|
|
1670
|
+
const message = executeReminderCommand(command, taskMod);
|
|
1671
|
+
deps.writeStdout(message);
|
|
1672
|
+
return message;
|
|
1673
|
+
}
|
|
1674
|
+
// ── friend subcommands (local, no daemon socket needed) ──
|
|
1675
|
+
if (command.kind === "friend.list" || command.kind === "friend.show" || command.kind === "friend.create" ||
|
|
1676
|
+
command.kind === "friend.link" || command.kind === "friend.unlink") {
|
|
1677
|
+
/* v8 ignore start -- production default: requires full identity setup @preserve */
|
|
1678
|
+
let store = deps.friendStore;
|
|
1679
|
+
if (!store) {
|
|
1680
|
+
// Derive agent-scoped friends dir from --agent flag or link/unlink's agent field
|
|
1681
|
+
const agentName = ("agent" in command && command.agent) ? command.agent : undefined;
|
|
1682
|
+
const friendsDir = agentName
|
|
1683
|
+
? path.join((0, identity_1.getAgentBundlesRoot)(), `${agentName}.ouro`, "friends")
|
|
1684
|
+
: path.join((0, identity_1.getAgentBundlesRoot)(), "friends");
|
|
1685
|
+
store = new store_file_1.FileFriendStore(friendsDir);
|
|
1686
|
+
}
|
|
1687
|
+
/* v8 ignore stop */
|
|
1688
|
+
const message = await executeFriendCommand(command, store);
|
|
1689
|
+
deps.writeStdout(message);
|
|
1690
|
+
return message;
|
|
1691
|
+
}
|
|
1692
|
+
// ── auth (local, no daemon socket needed) ──
|
|
1693
|
+
if (command.kind === "auth.run") {
|
|
1694
|
+
const provider = command.provider ?? (0, auth_flow_1.readAgentConfigForAgent)(command.agent).config.provider;
|
|
1695
|
+
/* v8 ignore next -- tests always inject runAuthFlow; default is for production @preserve */
|
|
1696
|
+
const authRunner = deps.runAuthFlow ?? auth_flow_1.runRuntimeAuthFlow;
|
|
1697
|
+
const result = await authRunner({
|
|
1698
|
+
agentName: command.agent,
|
|
1699
|
+
provider,
|
|
1700
|
+
promptInput: deps.promptInput,
|
|
1701
|
+
});
|
|
1702
|
+
// Behavior: ouro auth stores credentials only — does NOT switch provider.
|
|
1703
|
+
// Use `ouro auth switch` to change the active provider.
|
|
1704
|
+
deps.writeStdout(result.message);
|
|
1705
|
+
return result.message;
|
|
1706
|
+
}
|
|
1707
|
+
// ── auth verify (local, no daemon socket needed) ──
|
|
1708
|
+
/* v8 ignore start -- auth verify/switch: tested in daemon-cli.test.ts but v8 traces differ in CI @preserve */
|
|
1709
|
+
if (command.kind === "auth.verify") {
|
|
1710
|
+
const { secrets } = (0, auth_flow_1.loadAgentSecrets)(command.agent);
|
|
1711
|
+
const providers = secrets.providers;
|
|
1712
|
+
const fetchFn = deps.fetchImpl ?? fetch;
|
|
1713
|
+
if (command.provider) {
|
|
1714
|
+
const status = await verifyProviderCredentials(command.provider, providers, fetchFn);
|
|
1715
|
+
const message = `${command.provider}: ${status}`;
|
|
1716
|
+
deps.writeStdout(message);
|
|
1717
|
+
return message;
|
|
1718
|
+
}
|
|
1719
|
+
const lines = [];
|
|
1720
|
+
for (const p of Object.keys(providers)) {
|
|
1721
|
+
const status = await verifyProviderCredentials(p, providers, fetchFn);
|
|
1722
|
+
lines.push(`${p}: ${status}`);
|
|
1723
|
+
}
|
|
1724
|
+
const message = lines.join("\n");
|
|
1725
|
+
deps.writeStdout(message);
|
|
1726
|
+
return message;
|
|
1727
|
+
}
|
|
1728
|
+
// ── auth switch (local, no daemon socket needed) ──
|
|
1729
|
+
if (command.kind === "auth.switch") {
|
|
1730
|
+
const { secrets } = (0, auth_flow_1.loadAgentSecrets)(command.agent);
|
|
1731
|
+
const providerSecrets = secrets.providers[command.provider];
|
|
1732
|
+
if (!providerSecrets || !hasStoredCredentials(command.provider, providerSecrets)) {
|
|
1733
|
+
const message = `no credentials stored for ${command.provider}. Run \`ouro auth --agent ${command.agent} --provider ${command.provider}\` first.`;
|
|
1734
|
+
deps.writeStdout(message);
|
|
1735
|
+
return message;
|
|
1736
|
+
}
|
|
1737
|
+
(0, auth_flow_1.writeAgentProviderSelection)(command.agent, command.provider);
|
|
1738
|
+
const message = `switched ${command.agent} to ${command.provider}`;
|
|
1739
|
+
deps.writeStdout(message);
|
|
1740
|
+
return message;
|
|
1741
|
+
}
|
|
1742
|
+
/* v8 ignore stop */
|
|
1743
|
+
// ── whoami (local, no daemon socket needed) ──
|
|
1744
|
+
if (command.kind === "whoami") {
|
|
1745
|
+
if (command.agent) {
|
|
1746
|
+
const agentRoot = path.join((0, identity_1.getAgentBundlesRoot)(), `${command.agent}.ouro`);
|
|
1747
|
+
const message = [
|
|
1748
|
+
`agent: ${command.agent}`,
|
|
1749
|
+
`home: ${agentRoot}`,
|
|
1750
|
+
`bones: ${(0, runtime_metadata_1.getRuntimeMetadata)().version}`,
|
|
1751
|
+
].join("\n");
|
|
1752
|
+
deps.writeStdout(message);
|
|
1753
|
+
return message;
|
|
1754
|
+
}
|
|
1755
|
+
/* v8 ignore start -- production default: requires full identity setup @preserve */
|
|
1756
|
+
try {
|
|
1757
|
+
const info = deps.whoamiInfo
|
|
1758
|
+
? deps.whoamiInfo()
|
|
1759
|
+
: {
|
|
1760
|
+
agentName: (0, identity_1.getAgentName)(),
|
|
1761
|
+
homePath: path.join((0, identity_1.getAgentBundlesRoot)(), `${(0, identity_1.getAgentName)()}.ouro`),
|
|
1762
|
+
bonesVersion: (0, runtime_metadata_1.getRuntimeMetadata)().version,
|
|
1763
|
+
};
|
|
1764
|
+
const message = [
|
|
1765
|
+
`agent: ${info.agentName}`,
|
|
1766
|
+
`home: ${info.homePath}`,
|
|
1767
|
+
`bones: ${info.bonesVersion}`,
|
|
1768
|
+
].join("\n");
|
|
1769
|
+
deps.writeStdout(message);
|
|
1770
|
+
return message;
|
|
1771
|
+
}
|
|
1772
|
+
catch {
|
|
1773
|
+
const message = "error: no agent context — use --agent <name> to specify";
|
|
1774
|
+
deps.writeStdout(message);
|
|
1775
|
+
return message;
|
|
1776
|
+
}
|
|
1777
|
+
/* v8 ignore stop */
|
|
1778
|
+
}
|
|
1779
|
+
// ── changelog (local, no daemon socket needed) ──
|
|
1780
|
+
if (command.kind === "changelog") {
|
|
1781
|
+
try {
|
|
1782
|
+
const changelogPath = deps.getChangelogPath
|
|
1783
|
+
? deps.getChangelogPath()
|
|
1784
|
+
: (0, bundle_manifest_1.getChangelogPath)();
|
|
1785
|
+
const raw = fs.readFileSync(changelogPath, "utf-8");
|
|
1786
|
+
const entries = JSON.parse(raw);
|
|
1787
|
+
let filtered = entries;
|
|
1788
|
+
if (command.from) {
|
|
1789
|
+
const fromVersion = command.from;
|
|
1790
|
+
filtered = entries.filter((e) => e.version > fromVersion);
|
|
1791
|
+
}
|
|
1792
|
+
if (filtered.length === 0) {
|
|
1793
|
+
const message = "no changelog entries found.";
|
|
1794
|
+
deps.writeStdout(message);
|
|
1795
|
+
return message;
|
|
1796
|
+
}
|
|
1797
|
+
const lines = [];
|
|
1798
|
+
for (const entry of filtered) {
|
|
1799
|
+
lines.push(`## ${entry.version}${entry.date ? ` (${entry.date})` : ""}`);
|
|
1800
|
+
if (entry.changes) {
|
|
1801
|
+
for (const change of entry.changes) {
|
|
1802
|
+
lines.push(`- ${change}`);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
lines.push("");
|
|
1806
|
+
}
|
|
1807
|
+
const message = lines.join("\n").trim();
|
|
1808
|
+
deps.writeStdout(message);
|
|
1809
|
+
return message;
|
|
1810
|
+
}
|
|
1811
|
+
catch {
|
|
1812
|
+
const message = "no changelog entries found.";
|
|
1813
|
+
deps.writeStdout(message);
|
|
1814
|
+
return message;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
// ── thoughts (local, no daemon socket needed) ──
|
|
1818
|
+
if (command.kind === "thoughts") {
|
|
1819
|
+
try {
|
|
1820
|
+
const agentName = command.agent ?? (0, identity_1.getAgentName)();
|
|
1821
|
+
const agentRoot = path.join((0, identity_1.getAgentBundlesRoot)(), `${agentName}.ouro`);
|
|
1822
|
+
const sessionFilePath = (0, thoughts_1.getInnerDialogSessionPath)(agentRoot);
|
|
1823
|
+
if (command.json) {
|
|
1824
|
+
try {
|
|
1825
|
+
const raw = fs.readFileSync(sessionFilePath, "utf-8");
|
|
1826
|
+
deps.writeStdout(raw);
|
|
1827
|
+
return raw;
|
|
1828
|
+
}
|
|
1829
|
+
catch {
|
|
1830
|
+
const message = "no inner dialog session found";
|
|
1831
|
+
deps.writeStdout(message);
|
|
1832
|
+
return message;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
const turns = (0, thoughts_1.parseInnerDialogSession)(sessionFilePath);
|
|
1836
|
+
const message = (0, thoughts_1.formatThoughtTurns)(turns, command.last ?? 10);
|
|
1837
|
+
deps.writeStdout(message);
|
|
1838
|
+
if (command.follow) {
|
|
1839
|
+
deps.writeStdout("\n\n--- following (ctrl+c to stop) ---\n");
|
|
1840
|
+
/* v8 ignore start -- callback tested via followThoughts unit tests @preserve */
|
|
1841
|
+
const stop = (0, thoughts_1.followThoughts)(sessionFilePath, (formatted) => {
|
|
1842
|
+
deps.writeStdout("\n" + formatted);
|
|
1843
|
+
});
|
|
1844
|
+
/* v8 ignore stop */
|
|
1845
|
+
// Block until process exit; cleanup watcher on SIGINT/SIGTERM
|
|
1846
|
+
return new Promise((resolve) => {
|
|
1847
|
+
const cleanup = () => { stop(); resolve(message); };
|
|
1848
|
+
process.once("SIGINT", cleanup);
|
|
1849
|
+
process.once("SIGTERM", cleanup);
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
return message;
|
|
1853
|
+
}
|
|
1854
|
+
catch {
|
|
1855
|
+
const message = "error: no agent context — use --agent <name> to specify";
|
|
1856
|
+
deps.writeStdout(message);
|
|
1857
|
+
return message;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
// ── session list (local, no daemon socket needed) ──
|
|
1861
|
+
if (command.kind === "session.list") {
|
|
1862
|
+
/* v8 ignore start -- production default: requires full identity setup @preserve */
|
|
1863
|
+
const scanner = deps.scanSessions ?? (async () => []);
|
|
1864
|
+
/* v8 ignore stop */
|
|
1865
|
+
const sessions = await scanner();
|
|
1866
|
+
if (sessions.length === 0) {
|
|
1867
|
+
const message = "no active sessions";
|
|
1868
|
+
deps.writeStdout(message);
|
|
1869
|
+
return message;
|
|
1870
|
+
}
|
|
1871
|
+
const lines = sessions.map((s) => `${s.friendId} ${s.friendName} ${s.channel} ${s.lastActivity}`);
|
|
1872
|
+
const message = lines.join("\n");
|
|
708
1873
|
deps.writeStdout(message);
|
|
709
1874
|
return message;
|
|
710
1875
|
}
|
|
1876
|
+
if (command.kind === "chat.connect" && deps.startChat) {
|
|
1877
|
+
await ensureDaemonRunning(deps);
|
|
1878
|
+
await deps.startChat(command.agent);
|
|
1879
|
+
return "";
|
|
1880
|
+
}
|
|
711
1881
|
if (command.kind === "hatch.start") {
|
|
712
1882
|
// Route through adoption specialist when no explicit hatch args were provided
|
|
713
1883
|
const hasExplicitHatchArgs = !!(command.agentName || command.humanName || command.provider || command.credentials);
|
|
714
1884
|
if (deps.runAdoptionSpecialist && !hasExplicitHatchArgs) {
|
|
1885
|
+
// System setup first — ouro command, subagents, UTI — before the interactive specialist
|
|
1886
|
+
await performSystemSetup(deps);
|
|
715
1887
|
const hatchlingName = await deps.runAdoptionSpecialist();
|
|
716
1888
|
if (!hatchlingName) {
|
|
717
1889
|
return "";
|
|
718
1890
|
}
|
|
719
|
-
try {
|
|
720
|
-
await deps.installSubagents();
|
|
721
|
-
}
|
|
722
|
-
catch (error) {
|
|
723
|
-
(0, runtime_1.emitNervesEvent)({
|
|
724
|
-
level: "warn",
|
|
725
|
-
component: "daemon",
|
|
726
|
-
event: "daemon.subagent_install_error",
|
|
727
|
-
message: "subagent auto-install failed",
|
|
728
|
-
meta: { error: error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error) },
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
await registerOuroBundleTypeNonBlocking(deps);
|
|
732
1891
|
await ensureDaemonRunning(deps);
|
|
733
1892
|
if (deps.startChat) {
|
|
734
1893
|
await deps.startChat(hatchlingName);
|
|
@@ -744,19 +1903,7 @@ async function runOuroCli(args, deps = createDefaultOuroCliDeps()) {
|
|
|
744
1903
|
}
|
|
745
1904
|
const hatchInput = await resolveHatchInput(command, deps);
|
|
746
1905
|
const result = await hatchRunner(hatchInput);
|
|
747
|
-
|
|
748
|
-
await deps.installSubagents();
|
|
749
|
-
}
|
|
750
|
-
catch (error) {
|
|
751
|
-
(0, runtime_1.emitNervesEvent)({
|
|
752
|
-
level: "warn",
|
|
753
|
-
component: "daemon",
|
|
754
|
-
event: "daemon.subagent_install_error",
|
|
755
|
-
message: "subagent auto-install failed",
|
|
756
|
-
meta: { error: error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error) },
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
await registerOuroBundleTypeNonBlocking(deps);
|
|
1906
|
+
await performSystemSetup(deps);
|
|
760
1907
|
const daemonResult = await ensureDaemonRunning(deps);
|
|
761
1908
|
if (deps.startChat) {
|
|
762
1909
|
await deps.startChat(hatchInput.agentName);
|
|
@@ -778,9 +1925,22 @@ async function runOuroCli(args, deps = createDefaultOuroCliDeps()) {
|
|
|
778
1925
|
deps.writeStdout(message);
|
|
779
1926
|
return message;
|
|
780
1927
|
}
|
|
1928
|
+
if (command.kind === "daemon.status" && isDaemonUnavailableError(error)) {
|
|
1929
|
+
const message = daemonUnavailableStatusOutput(deps.socketPath);
|
|
1930
|
+
deps.writeStdout(message);
|
|
1931
|
+
return message;
|
|
1932
|
+
}
|
|
1933
|
+
if (command.kind === "daemon.stop" && isDaemonUnavailableError(error)) {
|
|
1934
|
+
const message = "daemon not running";
|
|
1935
|
+
deps.writeStdout(message);
|
|
1936
|
+
return message;
|
|
1937
|
+
}
|
|
781
1938
|
throw error;
|
|
782
1939
|
}
|
|
783
|
-
const
|
|
1940
|
+
const fallbackMessage = response.summary ?? response.message ?? (response.ok ? "ok" : `error: ${response.error ?? "unknown error"}`);
|
|
1941
|
+
const message = command.kind === "daemon.status"
|
|
1942
|
+
? formatDaemonStatusOutput(response, fallbackMessage)
|
|
1943
|
+
: fallbackMessage;
|
|
784
1944
|
deps.writeStdout(message);
|
|
785
1945
|
return message;
|
|
786
1946
|
}
|