@ouro.bot/cli 0.1.0-alpha.1021 → 0.1.0-alpha.1024
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/changelog.json +34 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/auth/auth-flow.js +17 -12
- package/dist/heart/core.js +19 -2
- package/dist/heart/daemon/agent-discovery.js +22 -5
- package/dist/heart/daemon/agent-home.js +101 -47
- package/dist/heart/daemon/cli-defaults.js +27 -6
- package/dist/heart/daemon/cli-exec.js +95 -1
- package/dist/heart/daemon/cli-help.js +7 -0
- package/dist/heart/daemon/cli-parse.js +38 -2
- package/dist/heart/daemon/daemon-entry.js +121 -1
- package/dist/heart/daemon/launchd.js +3 -0
- package/dist/heart/daemon/mcp-canary.js +2 -1
- package/dist/heart/daemon/os-cron-deps.js +4 -0
- package/dist/heart/daemon/presence-daemon.js +263 -0
- package/dist/heart/daemon/presence-roster.js +217 -0
- package/dist/heart/daemon/presence.js +380 -0
- package/dist/heart/daemon/provider-discovery.js +34 -0
- package/dist/heart/daemon/sense-manager.js +111 -35
- package/dist/heart/hatch/hatch-flow.js +3 -1
- package/dist/heart/hatch/specialist-prompt.js +1 -0
- package/dist/heart/hatch/specialist-tools.js +47 -2
- package/dist/heart/private-runtime/ledger.js +19 -28
- package/dist/heart/private-runtime/policy.js +13 -0
- package/dist/heart/providers/anthropic.js +24 -1
- package/dist/heart/providers/github-copilot.js +18 -1
- package/dist/heart/tool-images.js +42 -0
- package/dist/mind/prompt.js +2 -0
- package/dist/mind/where-am-i.js +122 -0
- package/dist/repertoire/mcp-tools.js +21 -5
- package/dist/repertoire/vault-setup.js +82 -30
- package/dist/repertoire/vault-unlock.js +18 -4
- package/dist/senses/cli/ouro-tui.js +2 -2
- package/dist/senses/cli/tui-store.js +11 -0
- package/dist/senses/cli.js +38 -9
- package/dist/senses/terminal-handoff.js +44 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1024",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Presence: one named agent runs on several machines at once from a git-synced bundle. agent.json gets an opt-in presence roster (machines, owners, minVersion); shared senses such as Teams and habits run only on their owner, and read as not attached on its peers; `ouro presence join|handoff|status|location`; each copy's prompt says which machine it is on, its peers and what it owns.",
|
|
8
|
+
"Habit and await plists on Macs installed by the ouro.bot installer now call ~/.ouro-cli/bin/ouro; launchd's PATH never had a bare `ouro`, so those habits never ran."
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"version": "0.1.0-alpha.1023",
|
|
13
|
+
"changes": [
|
|
14
|
+
"Habits run again. The private runtime policy allows a habit wake that carries verified daemon provenance (habit, matching habit-trigger and habit-occurrence refs, and the habit scheduler, habit.poke or habit.probe as source), where before every habit fire was denied as default policy deny. A denied private-turn decision no longer reserves its idempotency key, so a habit whose first attempt was denied, and then retried after a provider credential revision change, runs on its next fire instead of failing forever with idempotency-key fingerprint mismatch."
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"version": "0.1.0-alpha.1020",
|
|
19
|
+
"changes": [
|
|
20
|
+
"Images that MCP tools return (for example a plugin's screenshot tool) now reach the model: vision models get them in a message right after the step's tool results, and other models get a note that images were left out. GitHub Copilot requests that carry images send the Copilot-Vision-Request header, and the Anthropic provider sends base64 images as image blocks."
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"version": "0.1.0-alpha.1018",
|
|
25
|
+
"changes": [
|
|
26
|
+
"Hatch and ouro vault create register vault accounts with Vaultwarden's current two-step flow (send-verification-email, then register/finish), falling back to the old /identity/accounts/register only on servers that lack it. When a server has signups closed, the error says to have its admin invite the agent's email.",
|
|
27
|
+
"OURO_VAULT_UNLOCK_STORE (for example plaintext-file on a headless appliance without secret-tool) picks the local vault unlock store for every ouro command when no --store is given. Hatch (interactive and --answers) and ouro vault create/replace/recover check for a usable unlock store before creating the vault account, so a missing store no longer leaves an orphaned account behind."
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"version": "0.1.0-alpha.1019",
|
|
32
|
+
"changes": [
|
|
33
|
+
"ouro hatch on a host with GH_TOKEN or GITHUB_TOKEN set: the github-copilot option it offers now looks up the account's Copilot endpoint first, so choosing it works instead of failing with 'no credentials configured'.",
|
|
34
|
+
"The hatchling vault unlock prompt during ouro hatch pauses the conversation view: the spinner stops, the prompt is visible, and what you type is hidden instead of being echoed into the chat input.",
|
|
35
|
+
"A failed complete_adoption no longer crashes ouro hatch with a JSON parse error: the guide explains the error and can retry, and quitting prints what went wrong."
|
|
36
|
+
]
|
|
37
|
+
},
|
|
4
38
|
{
|
|
5
39
|
"version": "0.1.0-alpha.1021",
|
|
6
40
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1024</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -39,6 +39,7 @@ exports.storeProviderCredentials = storeProviderCredentials;
|
|
|
39
39
|
exports.writeAgentModel = writeAgentModel;
|
|
40
40
|
exports.readAccountPoolSettings = readAccountPoolSettings;
|
|
41
41
|
exports.collectGithubCopilotPoolCredentials = collectGithubCopilotPoolCredentials;
|
|
42
|
+
exports.discoverGithubCopilotBaseUrl = discoverGithubCopilotBaseUrl;
|
|
42
43
|
exports.collectRuntimeAuthCredentials = collectRuntimeAuthCredentials;
|
|
43
44
|
exports.resolveHatchCredentials = resolveHatchCredentials;
|
|
44
45
|
exports.runRuntimeAuthFlow = runRuntimeAuthFlow;
|
|
@@ -331,6 +332,21 @@ async function collectGithubCopilotPoolCredentials(input, settings, deps) {
|
|
|
331
332
|
});
|
|
332
333
|
return credentials;
|
|
333
334
|
}
|
|
335
|
+
/** Ask GitHub which Copilot API endpoint serves this token's account (`endpoints.api`). */
|
|
336
|
+
async function discoverGithubCopilotBaseUrl(token, fetchImpl = fetch) {
|
|
337
|
+
const response = await fetchImpl("https://api.github.com/copilot_internal/user", {
|
|
338
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
339
|
+
});
|
|
340
|
+
if (!response.ok) {
|
|
341
|
+
throw new Error(`GitHub Copilot endpoint discovery failed (HTTP ${response.status}). Ensure your GitHub account has Copilot access.`);
|
|
342
|
+
}
|
|
343
|
+
const body = await response.json();
|
|
344
|
+
const baseUrl = body?.endpoints?.api;
|
|
345
|
+
if (!baseUrl) {
|
|
346
|
+
throw new Error("GitHub Copilot endpoint discovery returned no endpoints.api. Ensure your GitHub account has Copilot access.");
|
|
347
|
+
}
|
|
348
|
+
return baseUrl;
|
|
349
|
+
}
|
|
334
350
|
async function collectRuntimeAuthCredentials(input, deps) {
|
|
335
351
|
const spawnSync = deps.spawnSync ?? child_process_1.spawnSync;
|
|
336
352
|
const homeDir = deps.homeDir ?? os.homedir();
|
|
@@ -389,18 +405,7 @@ async function collectRuntimeAuthCredentials(input, deps) {
|
|
|
389
405
|
}
|
|
390
406
|
}
|
|
391
407
|
writeAuthProgress(input, "checking GitHub Copilot access...");
|
|
392
|
-
const
|
|
393
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
394
|
-
});
|
|
395
|
-
if (!response.ok) {
|
|
396
|
-
throw new Error(`GitHub Copilot endpoint discovery failed (HTTP ${response.status}). Ensure your GitHub account has Copilot access.`);
|
|
397
|
-
}
|
|
398
|
-
const body = await response.json();
|
|
399
|
-
const baseUrl = body?.endpoints?.api;
|
|
400
|
-
/* v8 ignore next -- defensive: valid response but missing endpoints field @preserve */
|
|
401
|
-
if (!baseUrl) {
|
|
402
|
-
throw new Error("GitHub Copilot endpoint discovery returned no endpoints.api. Ensure your GitHub account has Copilot access.");
|
|
403
|
-
}
|
|
408
|
+
const baseUrl = await discoverGithubCopilotBaseUrl(token);
|
|
404
409
|
return { githubToken: token, baseUrl };
|
|
405
410
|
}
|
|
406
411
|
if (input.provider === "openai-codex") {
|
package/dist/heart/core.js
CHANGED
|
@@ -25,6 +25,7 @@ const source_grounding_1 = require("./source-grounding");
|
|
|
25
25
|
const shelf_claims_1 = require("./shelf-claims");
|
|
26
26
|
const reply_style_1 = require("./reply-style");
|
|
27
27
|
const tools_1 = require("../repertoire/tools");
|
|
28
|
+
const tool_images_1 = require("./tool-images");
|
|
28
29
|
const tool_arguments_1 = require("../repertoire/tool-arguments");
|
|
29
30
|
const session_events_1 = require("./session-events");
|
|
30
31
|
const tool_approval_1 = require("./tool-approval");
|
|
@@ -2354,6 +2355,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
2354
2355
|
}
|
|
2355
2356
|
await streamCallbackBuffer?.flush();
|
|
2356
2357
|
pushGenerated(msg);
|
|
2358
|
+
const batchToolImages = [];
|
|
2357
2359
|
// Every pre-dispatch gate accepted the complete batch.
|
|
2358
2360
|
for (const tc of result.toolCalls) {
|
|
2359
2361
|
if (signal?.aborted)
|
|
@@ -2587,16 +2589,20 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
2587
2589
|
let toolResult;
|
|
2588
2590
|
let success;
|
|
2589
2591
|
let invoked = false;
|
|
2592
|
+
const toolImages = [];
|
|
2593
|
+
const withToolImageSink = (context) => context
|
|
2594
|
+
? { ...context, attachToolImages: (images) => { toolImages.push(...images); } }
|
|
2595
|
+
: context;
|
|
2590
2596
|
try {
|
|
2591
2597
|
const routineActionSelection = approvalCalls.find((entry) => entry.call.id === tc.id)?.routineActionSelection;
|
|
2592
2598
|
const executionToolContext = routineActionSelection && augmentedToolContext ? { ...augmentedToolContext, routineActionSelection } : augmentedToolContext;
|
|
2593
2599
|
if (options?.execTool && !relationship) {
|
|
2594
2600
|
invoked = true;
|
|
2595
|
-
toolResult = await options.execTool(tc.name, args, trustedToolContext);
|
|
2601
|
+
toolResult = await options.execTool(tc.name, args, withToolImageSink(trustedToolContext));
|
|
2596
2602
|
success = true;
|
|
2597
2603
|
}
|
|
2598
2604
|
else {
|
|
2599
|
-
const execution = await (0, tools_1.executeTool)(tc.name, args, executionToolContext, options?.execTool);
|
|
2605
|
+
const execution = await (0, tools_1.executeTool)(tc.name, args, withToolImageSink(executionToolContext), options?.execTool);
|
|
2600
2606
|
invoked = execution.kind !== "rejected_before_handler";
|
|
2601
2607
|
success = execution.kind === "handler_succeeded";
|
|
2602
2608
|
toolResult = "error" in execution ? `error: ${execution.error}` : execution.text;
|
|
@@ -2606,6 +2612,12 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
2606
2612
|
toolResult = `error: ${e}`;
|
|
2607
2613
|
success = false;
|
|
2608
2614
|
}
|
|
2615
|
+
if (success && toolImages.length > 0) {
|
|
2616
|
+
const visible = (0, tool_images_1.canModelSeeToolImages)(providerRuntime.model);
|
|
2617
|
+
toolResult = `${toolResult}${toolResult ? "\n\n" : ""}${(0, tool_images_1.toolImagesNote)(toolImages.length, providerRuntime.model, visible)}`;
|
|
2618
|
+
if (visible)
|
|
2619
|
+
batchToolImages.push({ toolName: tc.name, callId: tc.id, images: toolImages });
|
|
2620
|
+
}
|
|
2609
2621
|
if (invoked && requiredToolCallNames.includes(tc.name) && !options?.requiredToolCalls?.requireSuccessfulResults)
|
|
2610
2622
|
dispatchedRequiredToolCalls.add(tc.name);
|
|
2611
2623
|
turnToolRecords.push({ name: tc.name, args, result: toolResult });
|
|
@@ -2646,6 +2658,11 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
2646
2658
|
callbacks.onToolEnd(tc.name, (0, tools_1.buildToolResultSummary)(tc.name, args, modelResult, success, toolSelection), success);
|
|
2647
2659
|
callbacks.onToolResult?.(messages);
|
|
2648
2660
|
}
|
|
2661
|
+
if (batchToolImages.length > 0 && !signal?.aborted) {
|
|
2662
|
+
pushGenerated((0, tool_images_1.buildToolImagesMessage)(batchToolImages));
|
|
2663
|
+
// Responses-API providers keep native input; rebuild it so the images reach the next call.
|
|
2664
|
+
providerRuntime.resetTurnState(messages);
|
|
2665
|
+
}
|
|
2649
2666
|
}
|
|
2650
2667
|
}
|
|
2651
2668
|
catch (e) {
|
|
@@ -50,6 +50,7 @@ const identity_1 = require("../identity");
|
|
|
50
50
|
const machine_identity_1 = require("../machine-identity");
|
|
51
51
|
const runtime_1 = require("../../nerves/runtime");
|
|
52
52
|
const sync_health_1 = require("../sync-health");
|
|
53
|
+
const presence_1 = require("./presence");
|
|
53
54
|
/**
|
|
54
55
|
* True when the value is the string `"library"`. Library bundles are
|
|
55
56
|
* content-only resources — never run as agents, never appear in sync surfaces.
|
|
@@ -125,12 +126,16 @@ function agentHomeLabel(home) {
|
|
|
125
126
|
* The home this bundle names when it is another machine, else null. Used by
|
|
126
127
|
* the turn pipeline to decline turns for an agent that has moved away.
|
|
127
128
|
*/
|
|
128
|
-
function readAgentHomeElsewhere(agentRoot, machineId = (0, machine_identity_1.readMachineIdentity)()?.machineId ?? null) {
|
|
129
|
+
function readAgentHomeElsewhere(agentRoot, machineId = (0, machine_identity_1.readMachineIdentity)()?.machineId ?? null, presenceEnabled) {
|
|
129
130
|
if (machineId === null)
|
|
130
131
|
return null;
|
|
131
132
|
let home;
|
|
132
133
|
try {
|
|
133
|
-
|
|
134
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(agentRoot, "agent.json"), "utf-8"));
|
|
135
|
+
const roster = (0, presence_1.parsePresenceBlock)(parsed.presence);
|
|
136
|
+
if (roster?.machines.some((machine) => machine.machineId === machineId) && (presenceEnabled ?? (0, presence_1.readLocalPresenceSettings)().enabled))
|
|
137
|
+
return null;
|
|
138
|
+
home = parseAgentHome(parsed.home);
|
|
134
139
|
}
|
|
135
140
|
catch {
|
|
136
141
|
return null;
|
|
@@ -150,6 +155,8 @@ function stripDiscoveryMetadata(row) {
|
|
|
150
155
|
publicRow.homeMachine = agentHomeLabel(row.home);
|
|
151
156
|
if (row.homeNameMatchesThisMachine)
|
|
152
157
|
publicRow.homeNameMatchesThisMachine = true;
|
|
158
|
+
if (row.presence)
|
|
159
|
+
publicRow.presence = true;
|
|
153
160
|
return publicRow;
|
|
154
161
|
}
|
|
155
162
|
/**
|
|
@@ -191,6 +198,7 @@ function discoverBundleAgents(options = {}) {
|
|
|
191
198
|
let kind;
|
|
192
199
|
let manageable = false;
|
|
193
200
|
let home = null;
|
|
201
|
+
let presenceBlock = null;
|
|
194
202
|
try {
|
|
195
203
|
const raw = readFileSync(configPath, "utf-8");
|
|
196
204
|
const parsed = JSON.parse(raw);
|
|
@@ -204,11 +212,12 @@ function discoverBundleAgents(options = {}) {
|
|
|
204
212
|
}
|
|
205
213
|
manageable = isManageableAgentConfig(parsed);
|
|
206
214
|
home = parseAgentHome(parsed.home);
|
|
215
|
+
presenceBlock = (0, presence_1.parsePresenceBlock)(parsed.presence);
|
|
207
216
|
}
|
|
208
217
|
catch {
|
|
209
218
|
continue;
|
|
210
219
|
}
|
|
211
|
-
const row = { name: agentName, enabled, manageable, home };
|
|
220
|
+
const row = { name: agentName, enabled, manageable, home, presenceBlock };
|
|
212
221
|
if (kind !== undefined)
|
|
213
222
|
row.kind = kind;
|
|
214
223
|
if (enabled && !isLibraryKind(kind) && !manageable) {
|
|
@@ -221,11 +230,19 @@ function discoverBundleAgents(options = {}) {
|
|
|
221
230
|
const identity = options.machineId === undefined ? (0, machine_identity_1.readMachineIdentity)() : null;
|
|
222
231
|
const machineId = options.machineId === undefined ? identity?.machineId ?? null : options.machineId;
|
|
223
232
|
const thisMachineNames = new Set((options.hostnameAliases ?? identity?.hostnameAliases ?? []).map(normalizeMachineName));
|
|
224
|
-
const
|
|
233
|
+
const anyRoster = discovered.some((row) => row.presenceBlock !== null);
|
|
234
|
+
const presenceEnabled = anyRoster && (options.presenceEnabled ?? (0, presence_1.readLocalPresenceSettings)().enabled);
|
|
235
|
+
const presentHere = (row) => presenceEnabled && machineId !== null && !!row.presenceBlock?.machines.some((machine) => machine.machineId === machineId);
|
|
236
|
+
const holdsAHome = machineId !== null && discovered.some((row) => row.home?.machineId === machineId || presentHere(row));
|
|
225
237
|
for (const row of discovered) {
|
|
226
238
|
if (!row.enabled || isLibraryKind(row.kind) || !row.manageable)
|
|
227
239
|
continue;
|
|
228
|
-
if (row
|
|
240
|
+
if (presentHere(row)) {
|
|
241
|
+
// Presence: every roster machine runs the agent; `home` stays for daemons that know only it.
|
|
242
|
+
row.homeState = "here";
|
|
243
|
+
row.presence = true;
|
|
244
|
+
}
|
|
245
|
+
else if (row.home) {
|
|
229
246
|
row.homeState = row.home.machineId === machineId ? "here" : "elsewhere";
|
|
230
247
|
if (row.homeState === "elsewhere" && thisMachineNames.has(normalizeMachineName(row.home.machineName))) {
|
|
231
248
|
row.homeNameMatchesThisMachine = true;
|
|
@@ -52,8 +52,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
52
52
|
})();
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
exports.machineDisplayName = machineDisplayName;
|
|
55
|
+
exports.updateSyncedAgentJson = updateSyncedAgentJson;
|
|
55
56
|
exports.moveAgentHomeHere = moveAgentHomeHere;
|
|
56
57
|
exports.readUpstreamAgentHome = readUpstreamAgentHome;
|
|
58
|
+
exports.readUpstreamAgentConfig = readUpstreamAgentConfig;
|
|
57
59
|
exports.checkAgentHomes = checkAgentHomes;
|
|
58
60
|
const fs = __importStar(require("fs"));
|
|
59
61
|
const path = __importStar(require("path"));
|
|
@@ -61,6 +63,7 @@ const child_process_1 = require("child_process");
|
|
|
61
63
|
const runtime_1 = require("../../nerves/runtime");
|
|
62
64
|
const sync_1 = require("../sync");
|
|
63
65
|
const agent_discovery_1 = require("./agent-discovery");
|
|
66
|
+
const presence_1 = require("./presence");
|
|
64
67
|
const SYNC_NETWORK = {
|
|
65
68
|
fetch: (agentRoot, config) => (0, sync_1.fetchRemote)(agentRoot, config),
|
|
66
69
|
push: (agentRoot, config) => (0, sync_1.pushHeadToBranch)(agentRoot, config),
|
|
@@ -78,9 +81,6 @@ function readSyncSettings(parsed) {
|
|
|
78
81
|
function errorText(error) {
|
|
79
82
|
return error instanceof Error ? error.message : String(error);
|
|
80
83
|
}
|
|
81
|
-
function sameHome(left, right) {
|
|
82
|
-
return (left?.machineId ?? null) === (right?.machineId ?? null);
|
|
83
|
-
}
|
|
84
84
|
/** A readable machine name for a lease: the hostname without `.local`, or the id. */
|
|
85
85
|
function machineDisplayName(hostname, machineId) {
|
|
86
86
|
return hostname.trim().replace(/\.local$/, "") || machineId;
|
|
@@ -95,28 +95,30 @@ function recordedPushError(agentRoot) {
|
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Compare-and-swap one change to a bundle's synced agent.json on its remote.
|
|
100
|
+
* `ouro move` and `ouro presence` share it; see the header for the protocol.
|
|
101
|
+
*/
|
|
102
|
+
async function updateSyncedAgentJson(options) {
|
|
103
|
+
const { agent, retryCommand } = options;
|
|
101
104
|
const agentRoot = path.join(options.bundlesRoot, `${agent}.ouro`);
|
|
102
105
|
const configPath = path.join(agentRoot, "agent.json");
|
|
103
106
|
const git = options.execFileSync ?? child_process_1.execFileSync;
|
|
104
107
|
const network = options.network ?? SYNC_NETWORK;
|
|
105
|
-
const now = options.now ?? (() => new Date());
|
|
106
108
|
const run = (args) => git("git", args, { cwd: agentRoot, stdio: "pipe", timeout: 30_000 }).toString().trim();
|
|
107
109
|
(0, runtime_1.emitNervesEvent)({
|
|
108
110
|
component: "daemon",
|
|
109
|
-
event:
|
|
110
|
-
message: "
|
|
111
|
-
meta: { agent,
|
|
111
|
+
event: `${options.events}_start`,
|
|
112
|
+
message: "updating the synced agent.json",
|
|
113
|
+
meta: { agent, ...options.meta },
|
|
112
114
|
});
|
|
113
115
|
const finish = (result) => {
|
|
114
116
|
(0, runtime_1.emitNervesEvent)({
|
|
115
117
|
level: result.ok ? "info" : "warn",
|
|
116
118
|
component: "daemon",
|
|
117
|
-
event: result.ok ?
|
|
119
|
+
event: result.ok ? `${options.events}_end` : `${options.events}_error`,
|
|
118
120
|
message: result.message,
|
|
119
|
-
meta: { agent,
|
|
121
|
+
meta: { agent, ...options.meta, changed: result.changed },
|
|
120
122
|
});
|
|
121
123
|
return result;
|
|
122
124
|
};
|
|
@@ -125,13 +127,9 @@ async function moveAgentHomeHere(options) {
|
|
|
125
127
|
const text = fs.readFileSync(configPath, "utf-8");
|
|
126
128
|
return { text, parsed: JSON.parse(text) };
|
|
127
129
|
};
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
if (current)
|
|
131
|
-
home.previous = { machineId: current.machineId, machineName: current.machineName };
|
|
132
|
-
fs.writeFileSync(configPath, `${JSON.stringify({ ...parsed, home }, null, 2)}\n`, "utf-8");
|
|
130
|
+
const writeConfig = (next) => {
|
|
131
|
+
fs.writeFileSync(configPath, `${JSON.stringify(next, null, 2)}\n`, "utf-8");
|
|
133
132
|
};
|
|
134
|
-
const movedMessage = (current) => `${agent} now lives on ${(0, agent_discovery_1.agentHomeLabel)({ machineId, machineName })}${current ? ` (moved from ${(0, agent_discovery_1.agentHomeLabel)(current)})` : ""}`;
|
|
135
133
|
let config;
|
|
136
134
|
try {
|
|
137
135
|
config = readConfig();
|
|
@@ -142,15 +140,16 @@ async function moveAgentHomeHere(options) {
|
|
|
142
140
|
const sync = readSyncSettings(config.parsed);
|
|
143
141
|
const hasGit = fs.existsSync(path.join(agentRoot, ".git"));
|
|
144
142
|
if (!sync.enabled || !hasGit) {
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
const decision = options.decide(config.parsed, "local");
|
|
144
|
+
if (decision.kind === "refuse")
|
|
145
|
+
return refuse(decision.message);
|
|
146
|
+
if (decision.kind === "noop")
|
|
147
|
+
return finish({ ok: true, changed: false, message: decision.message });
|
|
148
|
+
writeConfig(decision.next);
|
|
150
149
|
const why = sync.enabled ? "the bundle is not a git repo" : "bundle sync is off";
|
|
151
|
-
return finish({ ok: true, changed: true, message: `${
|
|
150
|
+
return finish({ ok: true, changed: true, message: `${decision.message}; ${why}, so only this machine sees the change` });
|
|
152
151
|
}
|
|
153
|
-
const pausedRefusal = (until) => refuse(`${agent}'s bundle sync is paused until ${until}, so nothing changed; run
|
|
152
|
+
const pausedRefusal = (until) => refuse(`${agent}'s bundle sync is paused until ${until}, so nothing changed; run \`${retryCommand}\` again after that`);
|
|
154
153
|
const pausedUntil = (0, sync_1.syncPausedUntil)(agentRoot);
|
|
155
154
|
if (pausedUntil !== null)
|
|
156
155
|
return pausedRefusal(pausedUntil);
|
|
@@ -159,7 +158,7 @@ async function moveAgentHomeHere(options) {
|
|
|
159
158
|
return refuse(`another bundle sync holds ${agent}'s lock${lock.holderPid === null ? "" : ` (pid ${lock.holderPid})`}, so nothing changed; try again in a moment`);
|
|
160
159
|
}
|
|
161
160
|
try {
|
|
162
|
-
// A pause can begin while this
|
|
161
|
+
// A pause can begin while this update waited for the lock (the replay gate
|
|
163
162
|
// pauses, then takes the lock), so look again now that the lock is ours.
|
|
164
163
|
const pausedNow = (0, sync_1.syncPausedUntil)(agentRoot);
|
|
165
164
|
if (pausedNow !== null)
|
|
@@ -181,13 +180,13 @@ async function moveAgentHomeHere(options) {
|
|
|
181
180
|
run(["rev-parse", "--verify", "-q", tracking]);
|
|
182
181
|
}
|
|
183
182
|
catch {
|
|
184
|
-
return refuse(`${agent}'s bundle remote has no ${sync.branch} branch to publish the
|
|
183
|
+
return refuse(`${agent}'s bundle remote has no ${sync.branch} branch to publish the ${options.noun} to, so nothing changed`);
|
|
185
184
|
}
|
|
186
185
|
const unpushed = Number(run(["rev-list", "--count", `${tracking}..HEAD`]));
|
|
187
186
|
if (unpushed > 0) {
|
|
188
187
|
const recorded = recordedPushError(agentRoot);
|
|
189
188
|
const why = recorded ? `the last bundle push failed with: ${recorded}` : `run \`ouro sync --agent ${agent}\` to see why they did not publish`;
|
|
190
|
-
return refuse(`${agent}'s bundle has ${unpushed} unpushed commit${unpushed === 1 ? "" : "s"}, so nothing changed; fix bundle sync first, because a
|
|
189
|
+
return refuse(`${agent}'s bundle has ${unpushed} unpushed commit${unpushed === 1 ? "" : "s"}, so nothing changed; fix bundle sync first, because a ${options.noun} must not publish them as a side effect (${why})`);
|
|
191
190
|
}
|
|
192
191
|
try {
|
|
193
192
|
run(["merge", "--ff-only", "-q", tracking]);
|
|
@@ -197,52 +196,87 @@ async function moveAgentHomeHere(options) {
|
|
|
197
196
|
}
|
|
198
197
|
config = readConfig();
|
|
199
198
|
}
|
|
200
|
-
const
|
|
199
|
+
const stamp = options.stamp(config.parsed);
|
|
201
200
|
if (attempt === 1) {
|
|
202
|
-
seen =
|
|
203
|
-
}
|
|
204
|
-
else if (!sameHome(current, seen)) {
|
|
205
|
-
const winner = current ? (0, agent_discovery_1.agentHomeLabel)(current) : "no machine";
|
|
206
|
-
return refuse(`another machine changed ${agent}'s home while this move was being published (it now names ${winner}), so this move was undone; run \`ouro move ${agent} here\` again to take it over`);
|
|
201
|
+
seen = stamp;
|
|
207
202
|
}
|
|
208
|
-
if (
|
|
209
|
-
|
|
203
|
+
else if (stamp !== seen) {
|
|
204
|
+
const lost = options.lostRace(config.parsed);
|
|
205
|
+
return refuse(`another machine changed ${agent}'s ${lost.field} while this ${options.noun} was being published (${lost.now}), so this ${options.noun} was undone; run \`${retryCommand}\` again to take it over`);
|
|
210
206
|
}
|
|
211
|
-
|
|
207
|
+
const decision = options.decide(config.parsed, hasRemote ? "remote" : "local");
|
|
208
|
+
if (decision.kind === "refuse")
|
|
209
|
+
return refuse(decision.message);
|
|
210
|
+
if (decision.kind === "noop")
|
|
211
|
+
return finish({ ok: true, changed: false, message: decision.message });
|
|
212
|
+
writeConfig(decision.next);
|
|
212
213
|
try {
|
|
213
|
-
run(["-c", `user.name=${agent}`, "-c", `user.email=${agent}@ouro.local`, "commit", "-q", "-m",
|
|
214
|
+
run(["-c", `user.name=${agent}`, "-c", `user.email=${agent}@ouro.local`, "commit", "-q", "-m", decision.commitMessage, "--", "agent.json"]);
|
|
214
215
|
}
|
|
215
216
|
catch (error) {
|
|
216
217
|
fs.writeFileSync(configPath, config.text, "utf-8");
|
|
217
|
-
return refuse(`could not commit the
|
|
218
|
+
return refuse(`could not commit the ${options.noun}, so nothing changed: ${errorText(error)}`);
|
|
218
219
|
}
|
|
219
220
|
if (!hasRemote) {
|
|
220
|
-
return finish({ ok: true, changed: true, message: `${
|
|
221
|
+
return finish({ ok: true, changed: true, message: `${decision.message}; the bundle has no remote, so only this machine sees the change` });
|
|
221
222
|
}
|
|
222
223
|
const pushed = await network.push(agentRoot, sync);
|
|
223
224
|
if (pushed.ok)
|
|
224
|
-
return finish({ ok: true, changed: true, message:
|
|
225
|
+
return finish({ ok: true, changed: true, message: decision.message });
|
|
225
226
|
lastPushError = pushed.error ?? "push failed";
|
|
226
227
|
// Undo exactly our own commit; the working tree goes back to the
|
|
227
|
-
//
|
|
228
|
+
// previous agent.json. If even that fails, say what to run by hand.
|
|
228
229
|
try {
|
|
229
230
|
run(["reset", "-q", "--soft", "HEAD~1"]);
|
|
230
231
|
run(["reset", "-q", "HEAD", "--", "agent.json"]);
|
|
231
232
|
fs.writeFileSync(configPath, config.text, "utf-8");
|
|
232
233
|
}
|
|
233
234
|
catch (error) {
|
|
234
|
-
return refuse(`the
|
|
235
|
+
return refuse(`the ${options.noun} could not be pushed (${lastPushError}) and its local commit could not be undone (${errorText(error)}); run \`git -C ${agentRoot} reset --soft HEAD~1\` and restore agent.json`);
|
|
235
236
|
}
|
|
236
237
|
}
|
|
237
|
-
return refuse(`could not push the
|
|
238
|
+
return refuse(`could not push the ${options.noun}, so nothing changed: ${lastPushError}`);
|
|
238
239
|
}
|
|
239
240
|
catch (error) {
|
|
240
|
-
return refuse(`could not
|
|
241
|
+
return refuse(`could not ${options.verb} ${agent}, so nothing changed: ${errorText(error)}`);
|
|
241
242
|
}
|
|
242
243
|
finally {
|
|
243
244
|
lock.release();
|
|
244
245
|
}
|
|
245
246
|
}
|
|
247
|
+
/** Record this machine as the agent's home in its synced agent.json. */
|
|
248
|
+
async function moveAgentHomeHere(options) {
|
|
249
|
+
const { agent, machineId, machineName } = options;
|
|
250
|
+
const now = options.now ?? (() => new Date());
|
|
251
|
+
const movedMessage = (current) => `${agent} now lives on ${(0, agent_discovery_1.agentHomeLabel)({ machineId, machineName })}${current ? ` (moved from ${(0, agent_discovery_1.agentHomeLabel)(current)})` : ""}`;
|
|
252
|
+
return updateSyncedAgentJson({
|
|
253
|
+
agent,
|
|
254
|
+
bundlesRoot: options.bundlesRoot,
|
|
255
|
+
retryCommand: `ouro move ${agent} here`,
|
|
256
|
+
events: "daemon.agent_home_move",
|
|
257
|
+
meta: { machineId },
|
|
258
|
+
execFileSync: options.execFileSync,
|
|
259
|
+
lockWaitMs: options.lockWaitMs,
|
|
260
|
+
network: options.network,
|
|
261
|
+
stamp: (parsed) => (0, agent_discovery_1.parseAgentHome)(parsed.home)?.machineId ?? "",
|
|
262
|
+
noun: "move",
|
|
263
|
+
verb: "move",
|
|
264
|
+
lostRace: (parsed) => {
|
|
265
|
+
const current = (0, agent_discovery_1.parseAgentHome)(parsed.home);
|
|
266
|
+
return { field: "home", now: `it now names ${current ? (0, agent_discovery_1.agentHomeLabel)(current) : "no machine"}` };
|
|
267
|
+
},
|
|
268
|
+
decide: (parsed) => {
|
|
269
|
+
const current = (0, agent_discovery_1.parseAgentHome)(parsed.home);
|
|
270
|
+
if (current?.machineId === machineId) {
|
|
271
|
+
return { kind: "noop", message: `${agent} already lives on this machine (${(0, agent_discovery_1.agentHomeLabel)(current)})` };
|
|
272
|
+
}
|
|
273
|
+
const home = { machineId, machineName, since: now().toISOString() };
|
|
274
|
+
if (current)
|
|
275
|
+
home.previous = { machineId: current.machineId, machineName: current.machineName };
|
|
276
|
+
return { kind: "write", next: { ...parsed, home }, commitMessage: `home: ${agent} moves to ${machineName}`, message: movedMessage(current) };
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
}
|
|
246
280
|
function execGit(cwd, args) {
|
|
247
281
|
return new Promise((resolve, reject) => {
|
|
248
282
|
(0, child_process_1.execFile)("git", args, { cwd, timeout: 20_000 }, (error, stdout) => {
|
|
@@ -261,6 +295,11 @@ function execGit(cwd, args) {
|
|
|
261
295
|
* It never commits or pushes.
|
|
262
296
|
*/
|
|
263
297
|
async function readUpstreamAgentHome(agentRoot, git = execGit) {
|
|
298
|
+
const upstream = await readUpstreamAgentConfig(agentRoot, git);
|
|
299
|
+
return upstream === undefined ? undefined : (0, agent_discovery_1.parseAgentHome)(upstream.home);
|
|
300
|
+
}
|
|
301
|
+
/** The remote's agent.json (fetch only, as for the lease); undefined when unknown. */
|
|
302
|
+
async function readUpstreamAgentConfig(agentRoot, git = execGit) {
|
|
264
303
|
try {
|
|
265
304
|
const sync = readSyncSettings(JSON.parse(fs.readFileSync(path.join(agentRoot, "agent.json"), "utf-8")));
|
|
266
305
|
if (!sync.enabled || !fs.existsSync(path.join(agentRoot, ".git")))
|
|
@@ -274,8 +313,7 @@ async function readUpstreamAgentHome(agentRoot, git = execGit) {
|
|
|
274
313
|
const fetched = await (0, sync_1.fetchRemote)(agentRoot, sync);
|
|
275
314
|
if (!fetched.ok)
|
|
276
315
|
return undefined;
|
|
277
|
-
|
|
278
|
-
return (0, agent_discovery_1.parseAgentHome)(upstream.home);
|
|
316
|
+
return JSON.parse(await git(agentRoot, ["show", `${(0, sync_1.syncTrackingRef)(sync)}:agent.json`]));
|
|
279
317
|
}
|
|
280
318
|
finally {
|
|
281
319
|
lock.release();
|
|
@@ -295,7 +333,9 @@ async function checkAgentHomes(options) {
|
|
|
295
333
|
bundlesRoot: options.bundlesRoot,
|
|
296
334
|
machineId: options.machineId,
|
|
297
335
|
hostnameAliases: options.hostnameAliases ?? [],
|
|
336
|
+
...(options.presenceEnabled === undefined ? {} : { presenceEnabled: options.presenceEnabled }),
|
|
298
337
|
});
|
|
338
|
+
const readUpstreamConfig = options.readUpstreamConfig ?? ((agentRoot) => readUpstreamAgentConfig(agentRoot));
|
|
299
339
|
const managed = new Set(options.managedAgents);
|
|
300
340
|
const readUpstreamHome = options.readUpstreamHome ?? readUpstreamAgentHome;
|
|
301
341
|
const conflicts = [];
|
|
@@ -320,6 +360,20 @@ async function checkAgentHomes(options) {
|
|
|
320
360
|
const row = rows.find((candidate) => candidate.name === name);
|
|
321
361
|
if (!row || (row.homeState !== "here" && row.homeState !== "fallback"))
|
|
322
362
|
continue;
|
|
363
|
+
if (row.presence) {
|
|
364
|
+
// Present by roster: a conflict only when the remote's roster dropped this machine.
|
|
365
|
+
const upstreamConfig = await readUpstreamConfig(path.join(options.bundlesRoot, `${name}.ouro`));
|
|
366
|
+
if (upstreamConfig === undefined)
|
|
367
|
+
continue;
|
|
368
|
+
const roster = (0, presence_1.parsePresenceBlock)(upstreamConfig.presence);
|
|
369
|
+
if (roster?.machines.some((machine) => machine.machineId === options.machineId))
|
|
370
|
+
continue;
|
|
371
|
+
const upstreamHome = (0, agent_discovery_1.parseAgentHome)(upstreamConfig.home);
|
|
372
|
+
if (upstreamHome && upstreamHome.machineId !== options.machineId) {
|
|
373
|
+
conflicts.push({ name, where: `left the presence roster and moved to ${(0, agent_discovery_1.agentHomeLabel)(upstreamHome)} upstream` });
|
|
374
|
+
}
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
323
377
|
const upstream = await readUpstreamHome(path.join(options.bundlesRoot, `${name}.ouro`));
|
|
324
378
|
if (upstream && upstream.machineId !== options.machineId) {
|
|
325
379
|
conflicts.push({ name, where: `moved to ${(0, agent_discovery_1.agentHomeLabel)(upstream)} upstream` });
|
|
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
exports.defaultStartDaemonProcess = defaultStartDaemonProcess;
|
|
43
43
|
exports.defaultStartDaemonForFrontend = defaultStartDaemonForFrontend;
|
|
44
44
|
exports.readFirstBundleMetaVersion = readFirstBundleMetaVersion;
|
|
45
|
+
exports.niceOption = niceOption;
|
|
45
46
|
exports.isDaemonLaunchAgentLoaded = isDaemonLaunchAgentLoaded;
|
|
46
47
|
exports.waitForBootstrappedDaemonSocket = waitForBootstrappedDaemonSocket;
|
|
47
48
|
exports.defaultListHomeAgents = defaultListHomeAgents;
|
|
@@ -75,6 +76,7 @@ const daemon_health_1 = require("./daemon-health");
|
|
|
75
76
|
const log_tailer_1 = require("./log-tailer");
|
|
76
77
|
const home_filesystem_1 = require("./home-filesystem");
|
|
77
78
|
const launchd_1 = require("./launchd");
|
|
79
|
+
const presence_1 = require("./presence");
|
|
78
80
|
const linux_service_1 = require("./linux-service");
|
|
79
81
|
const socket_client_1 = require("./socket-client");
|
|
80
82
|
const session_activity_1 = require("../session-activity");
|
|
@@ -322,8 +324,14 @@ function writeDaemonBootPlist(socketPath) {
|
|
|
322
324
|
socketPath,
|
|
323
325
|
logDir: path.join((0, ouro_version_manager_1.getOuroCliHome)(homeDir), "daemon", "logs"),
|
|
324
326
|
envPath: process.env.PATH,
|
|
327
|
+
...niceOption(homeDir),
|
|
325
328
|
});
|
|
326
329
|
}
|
|
330
|
+
/** `nice` from this machine's `~/.ouro-cli/presence.json`, when set. */
|
|
331
|
+
function niceOption(homeDir) {
|
|
332
|
+
const nice = (0, presence_1.readLocalPresenceSettings)(homeDir, {}).nice;
|
|
333
|
+
return nice === undefined ? {} : { nice };
|
|
334
|
+
}
|
|
327
335
|
function isDaemonLaunchAgentLoaded(deps) {
|
|
328
336
|
const userUid = deps?.userUid ?? currentUserUid();
|
|
329
337
|
const exec = deps?.exec ?? ((cmd) => { (0, child_process_1.execSync)(cmd, { stdio: "ignore" }); });
|
|
@@ -591,7 +599,7 @@ async function defaultRunSerpentGuide() {
|
|
|
591
599
|
});
|
|
592
600
|
}
|
|
593
601
|
// Scan environment variables for API keys using the shared helper
|
|
594
|
-
const envCreds = (0, provider_discovery_1.scanEnvVarCredentials)(process.env);
|
|
602
|
+
const envCreds = await (0, provider_discovery_1.completeEnvDiscoveredCredentials)((0, provider_discovery_1.scanEnvVarCredentials)(process.env), (token) => (0, auth_flow_1.discoverGithubCopilotBaseUrl)(token));
|
|
595
603
|
const envDiscovered = [];
|
|
596
604
|
for (const cred of envCreds) {
|
|
597
605
|
// Enrich with default model and first matching env var name (for display)
|
|
@@ -716,13 +724,17 @@ async function defaultRunSerpentGuide() {
|
|
|
716
724
|
});
|
|
717
725
|
// Build specialist tools
|
|
718
726
|
const specialistTools = (0, specialist_tools_1.getSpecialistTools)();
|
|
727
|
+
let lastAdoptionError = null;
|
|
719
728
|
const specialistExecTool = (0, specialist_tools_1.createSpecialistExecTool)({
|
|
720
729
|
tempDir,
|
|
721
730
|
credentials: selectedCredentialPayload,
|
|
722
731
|
provider: providerRaw,
|
|
723
732
|
bundlesRoot,
|
|
724
733
|
animationWriter: (text) => process.stdout.write(text),
|
|
725
|
-
promptSecret:
|
|
734
|
+
promptSecret: async (question) => {
|
|
735
|
+
const { withTerminalHandedOff } = await Promise.resolve().then(() => __importStar(require("../../senses/terminal-handoff")));
|
|
736
|
+
return withTerminalHandedOff(() => defaultPromptSecret(question));
|
|
737
|
+
},
|
|
726
738
|
});
|
|
727
739
|
// Run the serpent guide session via runCliSession
|
|
728
740
|
const result = await runCliSession({
|
|
@@ -730,6 +742,12 @@ async function defaultRunSerpentGuide() {
|
|
|
730
742
|
tools: specialistTools,
|
|
731
743
|
execTool: specialistExecTool,
|
|
732
744
|
exitOnToolCall: "complete_adoption",
|
|
745
|
+
// A failed adoption goes back to the guide, which explains it and can retry.
|
|
746
|
+
exitOnToolResult: (toolResult) => {
|
|
747
|
+
const outcome = (0, specialist_tools_1.parseAdoptionResult)(toolResult);
|
|
748
|
+
lastAdoptionError = outcome.ok ? null : outcome.error;
|
|
749
|
+
return outcome.ok;
|
|
750
|
+
},
|
|
733
751
|
autoFirstTurn: true,
|
|
734
752
|
banner: false,
|
|
735
753
|
disableCommands: true,
|
|
@@ -740,10 +758,13 @@ async function defaultRunSerpentGuide() {
|
|
|
740
758
|
],
|
|
741
759
|
});
|
|
742
760
|
if (result.exitReason === "tool_exit" && result.toolResult) {
|
|
743
|
-
const
|
|
744
|
-
if (
|
|
745
|
-
return
|
|
746
|
-
|
|
761
|
+
const outcome = (0, specialist_tools_1.parseAdoptionResult)(result.toolResult);
|
|
762
|
+
if (outcome.ok)
|
|
763
|
+
return outcome.agentName;
|
|
764
|
+
lastAdoptionError = outcome.error;
|
|
765
|
+
}
|
|
766
|
+
if (lastAdoptionError) {
|
|
767
|
+
process.stdout.write(`\nhatch didn't finish: ${lastAdoptionError}\nfix that, then run \`ouro hatch\` again.\n`);
|
|
747
768
|
}
|
|
748
769
|
return null;
|
|
749
770
|
}
|