@ouro.bot/cli 0.1.0-alpha.1085 → 0.1.0-alpha.1086
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 +6 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/daemon/cli-exec.js +10 -2
- package/dist/heart/daemon/cli-help.js +1 -1
- package/dist/heart/daemon/cli-parse.js +9 -1
- package/dist/heart/daemon/presence-daemon.js +4 -2
- package/dist/heart/daemon/presence-roster.js +46 -3
- package/dist/heart/daemon/presence.js +61 -5
- package/dist/mind/where-am-i.js +6 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
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.1086",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Presence failover: ouro presence failover take|release <sense> lets a machine run a shared sense in place of an owner that stopped answering, through a machine-local lease under the bundle's state/. The roster is unchanged, so the owner runs the sense again as soon as it is back and never waits on the stand-in; the stand-in's record lists the sense under failover, and status, status --json and where-i-am say who is standing in, since when and why. The Teams tunnel controller in the desk tooling takes the lease after the endpoint stops answering and releases it when the owner reclaims the endpoint."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1085",
|
|
6
12
|
"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.1086</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -2405,7 +2405,7 @@ async function executePresence(command, deps) {
|
|
|
2405
2405
|
catch {
|
|
2406
2406
|
return returnCliFailure(deps, `cannot read ${command.agent}'s agent.json in ${agentRoot}`);
|
|
2407
2407
|
}
|
|
2408
|
-
const presence = (0, presence_1.readPresence)(agentJson, settings.enabled, (0, presence_1.readPeerRecords)(agentRoot));
|
|
2408
|
+
const presence = (0, presence_1.readPresence)(agentJson, settings.enabled, (0, presence_1.readPeerRecords)(agentRoot), (0, presence_1.readFailoverLeases)(agentRoot));
|
|
2409
2409
|
if (command.json) {
|
|
2410
2410
|
const json = JSON.stringify((0, presence_roster_1.presenceStatusJson)({ presence, machineId: identity.machineId, settings }));
|
|
2411
2411
|
deps.writeStdout(json);
|
|
@@ -2421,6 +2421,14 @@ async function executePresence(command, deps) {
|
|
|
2421
2421
|
deps.writeStdout(message);
|
|
2422
2422
|
return message;
|
|
2423
2423
|
}
|
|
2424
|
+
if (command.kind === "presence.failover") {
|
|
2425
|
+
const result = (0, presence_roster_1.presenceFailover)({ agent: command.agent, agentRoot, machineId: identity.machineId, action: command.action, sense: command.sense,
|
|
2426
|
+
reason: command.reason, now: new Date(providerCliNow(deps)), presence: (0, presence_1.readPresenceForAgent)(agentRoot, { homeDir }) });
|
|
2427
|
+
if (!result.ok)
|
|
2428
|
+
return returnCliFailure(deps, result.message);
|
|
2429
|
+
deps.writeStdout(result.message);
|
|
2430
|
+
return result.message;
|
|
2431
|
+
}
|
|
2424
2432
|
if (command.kind === "presence.handoff") {
|
|
2425
2433
|
const result = await (0, presence_roster_1.handoffPresenceSense)({ agent: command.agent, bundlesRoot, sense: command.sense, target: command.machine });
|
|
2426
2434
|
if (!result.ok)
|
|
@@ -8362,7 +8370,7 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
|
|
|
8362
8370
|
return (0, desk_admin_1.executeDeskAdminCommand)(command, deps);
|
|
8363
8371
|
}
|
|
8364
8372
|
// ── presence: one agent on several machines (local, no daemon needed) ──
|
|
8365
|
-
if (command.kind === "presence.join" || command.kind === "presence.handoff" || command.kind === "presence.status" || command.kind === "presence.location") {
|
|
8373
|
+
if (command.kind === "presence.join" || command.kind === "presence.handoff" || command.kind === "presence.status" || command.kind === "presence.failover" || command.kind === "presence.location") {
|
|
8366
8374
|
return executePresence(command, deps);
|
|
8367
8375
|
}
|
|
8368
8376
|
// ── move: make this machine the agent's home (local, no daemon needed) ──
|
|
@@ -129,7 +129,7 @@ exports.COMMAND_REGISTRY = {
|
|
|
129
129
|
presence: {
|
|
130
130
|
category: "Agents",
|
|
131
131
|
description: "Run one agent on several machines at once: join this machine to its roster, hand a shared sense (Teams, habits, …) to another machine, or see who owns what",
|
|
132
|
-
usage: "ouro presence join --agent <name> [--role <role>] [--name <machine name>] | ouro presence handoff <sense> <machine> --agent <name> | ouro presence status --agent <name> [--json] | ouro presence location <home|office|…>",
|
|
132
|
+
usage: "ouro presence join --agent <name> [--role <role>] [--name <machine name>] | ouro presence handoff <sense> <machine> --agent <name> | ouro presence status --agent <name> [--json] | ouro presence failover take|release <sense> --agent <name> [--reason <why>] | ouro presence location <home|office|…>",
|
|
133
133
|
example: "ouro presence handoff teams aris-mac-mini --agent my-agent",
|
|
134
134
|
subcommands: ["join", "handoff", "status", "location"],
|
|
135
135
|
},
|
|
@@ -3288,7 +3288,7 @@ function parseOuroCommand(args) {
|
|
|
3288
3288
|
if (head === "versions")
|
|
3289
3289
|
return { kind: "versions" };
|
|
3290
3290
|
if (head === "presence") {
|
|
3291
|
-
const usage = "Usage: ouro presence join --agent <name> [--role <role>] [--name <machine name>] | ouro presence handoff <sense> <machine> --agent <name> | ouro presence status --agent <name> [--json] | ouro presence location <home|office|…>";
|
|
3291
|
+
const usage = "Usage: ouro presence join --agent <name> [--role <role>] [--name <machine name>] | ouro presence handoff <sense> <machine> --agent <name> | ouro presence status --agent <name> [--json] | ouro presence failover take|release <sense> --agent <name> [--reason <why>] | ouro presence location <home|office|…>";
|
|
3292
3292
|
const { agent, rest } = extractAgentFlag(args.slice(1));
|
|
3293
3293
|
const [sub, ...tail] = rest;
|
|
3294
3294
|
if (sub === "location") {
|
|
@@ -3304,6 +3304,14 @@ function parseOuroCommand(args) {
|
|
|
3304
3304
|
return { kind: "presence.status", agent, json: true };
|
|
3305
3305
|
if (sub === "handoff" && tail.length === 2)
|
|
3306
3306
|
return { kind: "presence.handoff", agent, sense: tail[0], machine: tail[1] };
|
|
3307
|
+
if (sub === "failover" && (tail[0] === "take" || tail[0] === "release") && tail[1]) {
|
|
3308
|
+
const [action, sense, ...options] = tail;
|
|
3309
|
+
if (options.length === 0)
|
|
3310
|
+
return { kind: "presence.failover", agent, action, sense };
|
|
3311
|
+
if (action === "take" && options.length === 2 && options[0] === "--reason" && options[1])
|
|
3312
|
+
return { kind: "presence.failover", agent, action, sense, reason: options[1] };
|
|
3313
|
+
throw new Error(usage);
|
|
3314
|
+
}
|
|
3307
3315
|
if (sub === "join") {
|
|
3308
3316
|
const command = { kind: "presence.join", agent };
|
|
3309
3317
|
for (let i = 0; i < tail.length; i++) {
|
|
@@ -234,8 +234,9 @@ class PresenceTicker {
|
|
|
234
234
|
async publish(agent, presence) {
|
|
235
235
|
const now = (this.deps.now ?? (() => new Date()))();
|
|
236
236
|
const owns = (0, presence_1.ownedSharedSenses)(presence, this.deps.machineId);
|
|
237
|
+
const failover = (0, presence_1.failoverSenses)(presence, this.deps.machineId);
|
|
237
238
|
const last = this.lastPublishedMs.get(agent);
|
|
238
|
-
const ownsChanged = this.lastOwns.get(agent) !== owns.join(",");
|
|
239
|
+
const ownsChanged = this.lastOwns.get(agent) !== [...owns, ...failover.map((sense) => `failover:${sense}`)].join(",");
|
|
239
240
|
if (!ownsChanged && last !== undefined && now.getTime() - last < exports.PEER_RECORD_INTERVAL_MS)
|
|
240
241
|
return;
|
|
241
242
|
const agentRoot = path.join(this.deps.bundlesRoot, `${agent}.ouro`);
|
|
@@ -252,11 +253,12 @@ class PresenceTicker {
|
|
|
252
253
|
os: describeOs(),
|
|
253
254
|
location: settings.location ?? (machine.role === "always-on" ? "home" : "unknown"),
|
|
254
255
|
owns,
|
|
256
|
+
...(failover.length > 0 ? { failover } : {}),
|
|
255
257
|
...this.deps.extraRecord?.(agent),
|
|
256
258
|
};
|
|
257
259
|
(0, presence_1.writePeerRecord)(agentRoot, record);
|
|
258
260
|
this.lastPublishedMs.set(agent, now.getTime());
|
|
259
|
-
this.lastOwns.set(agent, owns.join(","));
|
|
261
|
+
this.lastOwns.set(agent, [...owns, ...failover.map((sense) => `failover:${sense}`)].join(","));
|
|
260
262
|
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.presence_record_published", message: "published this machine's presence record", meta: { agent, machineId: this.deps.machineId, version: this.deps.version } });
|
|
261
263
|
}
|
|
262
264
|
}
|
|
@@ -43,6 +43,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
43
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
44
|
exports.joinPresenceRoster = joinPresenceRoster;
|
|
45
45
|
exports.handoffPresenceSense = handoffPresenceSense;
|
|
46
|
+
exports.presenceFailover = presenceFailover;
|
|
46
47
|
exports.presenceStatusJson = presenceStatusJson;
|
|
47
48
|
exports.renderPresenceStatus = renderPresenceStatus;
|
|
48
49
|
const path = __importStar(require("path"));
|
|
@@ -145,12 +146,49 @@ async function handoffPresenceSense(options) {
|
|
|
145
146
|
},
|
|
146
147
|
});
|
|
147
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* `ouro presence failover take|release <sense>`: run a shared sense here in place of its owner while the owner is
|
|
151
|
+
* unreachable, or stop doing so. The roster is unchanged, so the owner runs the sense again as soon as it is back; the
|
|
152
|
+
* stand-in (or whatever watches for that, such as the Teams tunnel controller) then releases.
|
|
153
|
+
*/
|
|
154
|
+
function presenceFailover(options) {
|
|
155
|
+
const { agent, agentRoot, machineId, action, sense, presence } = options;
|
|
156
|
+
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.presence_failover", message: `presence failover ${action}`, meta: { agent, sense, action } });
|
|
157
|
+
const leases = (0, presence_1.readFailoverLeases)(agentRoot);
|
|
158
|
+
if (action === "release") {
|
|
159
|
+
const rest = leases.filter((lease) => lease.sense !== sense);
|
|
160
|
+
if (rest.length === leases.length)
|
|
161
|
+
return { ok: true, message: `this machine was not standing in for ${agent}'s ${sense}; nothing to release` };
|
|
162
|
+
(0, presence_1.writeFailoverLeases)(agentRoot, rest);
|
|
163
|
+
return { ok: true, message: `released ${agent}'s ${sense}: this machine stops it within about a minute, and its owner runs it` };
|
|
164
|
+
}
|
|
165
|
+
if (!presence)
|
|
166
|
+
return { ok: false, message: `presence is off here or ${agent} has no roster, so there is no owner to stand in for` };
|
|
167
|
+
if (!(0, presence_1.isSharedSense)(sense))
|
|
168
|
+
return { ok: false, message: `${sense} is not a shared sense; shared senses are ${presence_1.SHARED_SENSES.join(", ")}` };
|
|
169
|
+
const me = presence.block.machines.find((machine) => machine.machineId === machineId);
|
|
170
|
+
if (!me)
|
|
171
|
+
return { ok: false, message: `this machine is not on ${agent}'s roster; run \`ouro presence join --agent ${agent}\` first` };
|
|
172
|
+
const owner = (0, presence_1.effectiveOwner)(presence, sense);
|
|
173
|
+
const ownerName = presence.block.machines.find((machine) => machine.machineId === owner)?.name ?? owner;
|
|
174
|
+
if (owner === machineId)
|
|
175
|
+
return { ok: false, message: `${me.name} already owns ${agent}'s ${sense}; there is nothing to stand in for` };
|
|
176
|
+
if (leases.some((lease) => lease.sense === sense && lease.machine === machineId)) {
|
|
177
|
+
return { ok: true, message: `${me.name} is already standing in for ${ownerName} on ${agent}'s ${sense}` };
|
|
178
|
+
}
|
|
179
|
+
const reason = options.reason?.trim() || `${ownerName} stopped answering`;
|
|
180
|
+
(0, presence_1.writeFailoverLeases)(agentRoot, [...leases.filter((lease) => lease.sense !== sense), { sense, machine: machineId, from: owner, since: options.now.toISOString(), reason }]);
|
|
181
|
+
return {
|
|
182
|
+
ok: true,
|
|
183
|
+
message: `${me.name} now runs ${agent}'s ${sense} in place of ${ownerName} (${reason}); the daemon starts it within about a minute. ${ownerName} takes it back as soon as it runs again; release with \`ouro presence failover release ${sense} --agent ${agent}\``,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
148
186
|
/** `ouro presence status --json`: this machine, its peers and what it owns, for tools such as an arrival check. */
|
|
149
187
|
function presenceStatusJson(options) {
|
|
150
188
|
const { presence, machineId, settings } = options;
|
|
151
189
|
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.presence_status_json", message: "rendered presence status as json", meta: { active: presence !== null } });
|
|
152
190
|
if (!presence)
|
|
153
|
-
return { enabled: settings.enabled, machine: null, peers: [], owns: [], owners: {}, disabled: [], legacy: [] };
|
|
191
|
+
return { enabled: settings.enabled, machine: null, peers: [], owns: [], failover: [], owners: {}, disabled: [], legacy: [] };
|
|
154
192
|
const me = presence.block.machines.find((machine) => machine.machineId === machineId);
|
|
155
193
|
const owners = {};
|
|
156
194
|
for (const sense of (0, presence_1.enabledSharedSenses)(presence)) {
|
|
@@ -166,7 +204,10 @@ function presenceStatusJson(options) {
|
|
|
166
204
|
const record = presence.peers.find((peer) => peer.machineId === machine.machineId);
|
|
167
205
|
return { machineId: machine.machineId, name: machine.name, role: machine.role, seenAt: record?.seenAt ?? null, version: record?.version ?? null, location: record?.location ?? null };
|
|
168
206
|
}),
|
|
169
|
-
owns: (0, presence_1.enabledSharedSenses)(presence).filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) === machineId),
|
|
207
|
+
owns: (0, presence_1.enabledSharedSenses)(presence).filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) === machineId || (0, presence_1.holdsFailover)(presence, machineId, sense)),
|
|
208
|
+
failover: (presence.failover ?? []).filter((lease) => lease.machine === machineId).map((lease) => ({
|
|
209
|
+
sense: lease.sense, from: presence.block.machines.find((machine) => machine.machineId === lease.from)?.name ?? lease.from, since: lease.since, reason: lease.reason,
|
|
210
|
+
})),
|
|
170
211
|
owners,
|
|
171
212
|
disabled: presence_1.SHARED_SENSES.filter((sense) => !(0, presence_1.senseEnabled)(presence, sense)),
|
|
172
213
|
legacy: presence.legacy.map((id) => presence.block.machines.find((machine) => machine.machineId === id)?.name ?? id),
|
|
@@ -207,7 +248,9 @@ function renderPresenceStatus(options) {
|
|
|
207
248
|
const name = presence.block.machines.find((machine) => machine.machineId === owner)?.name ?? owner;
|
|
208
249
|
const declared = presence.block.owners[sense];
|
|
209
250
|
const held = declared && declared !== owner ? ` (roster names ${presence.block.machines.find((machine) => machine.machineId === declared)?.name ?? declared}; held by home until every machine runs presence)` : "";
|
|
210
|
-
|
|
251
|
+
const standIn = presence.failover?.find((lease) => lease.sense === sense);
|
|
252
|
+
const failover = standIn ? `; this machine stands in for it since ${standIn.since} (${standIn.reason})` : "";
|
|
253
|
+
lines.push(`- ${sense}: ${name}${held}${failover}`);
|
|
211
254
|
}
|
|
212
255
|
const off = presence_1.SHARED_SENSES.filter((sense) => !(0, presence_1.senseEnabled)(presence, sense));
|
|
213
256
|
if (off.length > 0)
|
|
@@ -77,6 +77,11 @@ exports.senseEnabled = senseEnabled;
|
|
|
77
77
|
exports.enabledSharedSenses = enabledSharedSenses;
|
|
78
78
|
exports.alwaysOnMachine = alwaysOnMachine;
|
|
79
79
|
exports.mayRunSense = mayRunSense;
|
|
80
|
+
exports.holdsFailover = holdsFailover;
|
|
81
|
+
exports.failoverLeasePath = failoverLeasePath;
|
|
82
|
+
exports.readFailoverLeases = readFailoverLeases;
|
|
83
|
+
exports.writeFailoverLeases = writeFailoverLeases;
|
|
84
|
+
exports.failoverSenses = failoverSenses;
|
|
80
85
|
exports.readPresenceForAgent = readPresenceForAgent;
|
|
81
86
|
exports.isRosterMember = isRosterMember;
|
|
82
87
|
exports.rosterMachine = rosterMachine;
|
|
@@ -183,6 +188,8 @@ function parsePeerRecord(value) {
|
|
|
183
188
|
}
|
|
184
189
|
if (Array.isArray(value.owns))
|
|
185
190
|
record.owns = value.owns.filter((sense) => typeof sense === "string");
|
|
191
|
+
if (Array.isArray(value.failover))
|
|
192
|
+
record.failover = value.failover.filter((sense) => typeof sense === "string");
|
|
186
193
|
if (isRecord(value.appSessions))
|
|
187
194
|
record.appSessions = value.appSessions;
|
|
188
195
|
return record;
|
|
@@ -291,7 +298,7 @@ function writeLocalPresenceSettings(settings, homeDir = os.homedir()) {
|
|
|
291
298
|
* The presence this machine should follow, or null for today's one-home lease
|
|
292
299
|
* (flag off, or no usable block).
|
|
293
300
|
*/
|
|
294
|
-
function readPresence(agentJson, localFlag, peerRecords) {
|
|
301
|
+
function readPresence(agentJson, localFlag, peerRecords, failover = []) {
|
|
295
302
|
if (!localFlag || !isRecord(agentJson))
|
|
296
303
|
return null;
|
|
297
304
|
const block = parsePresenceBlock(agentJson.presence);
|
|
@@ -309,7 +316,7 @@ function readPresence(agentJson, localFlag, peerRecords) {
|
|
|
309
316
|
if (home && !block.machines.some((machine) => machine.machineId === home.machineId))
|
|
310
317
|
legacy.push(home.machineId);
|
|
311
318
|
const enabledSenses = enabledSensesOf(agentJson.senses);
|
|
312
|
-
return { block, home, legacy, peers: peerRecords, ...(enabledSenses ? { enabledSenses } : {}) };
|
|
319
|
+
return { block, home, legacy, peers: peerRecords, ...(enabledSenses ? { enabledSenses } : {}), ...(failover.length > 0 ? { failover } : {}) };
|
|
313
320
|
}
|
|
314
321
|
/** The senses a `senses` block turns on. Habits run on schedulers, not a senses entry, so they count unless turned off. */
|
|
315
322
|
function enabledSensesOf(senses) {
|
|
@@ -345,7 +352,56 @@ function mayRunSense(presence, machineId, sense) {
|
|
|
345
352
|
return false;
|
|
346
353
|
if (!isSharedSense(sense))
|
|
347
354
|
return true;
|
|
348
|
-
|
|
355
|
+
// A stand-in runs the sense because its owner is gone, whatever the owner's last record said.
|
|
356
|
+
if (holdsFailover(presence, machineId, sense))
|
|
357
|
+
return true;
|
|
358
|
+
// The owner never waits on a stand-in: the stand-in lets go once the owner runs the sense again.
|
|
359
|
+
return !presence.peers.some((peer) => peer.machineId !== machineId && isRosterMember(presence, peer.machineId) && peer.owns?.includes(sense) && !peer.failover?.includes(sense));
|
|
360
|
+
}
|
|
361
|
+
/** Whether this machine holds a failover lease on the sense. */
|
|
362
|
+
function holdsFailover(presence, machineId, sense) {
|
|
363
|
+
return !!presence.failover?.some((lease) => lease.sense === sense && lease.machine === machineId);
|
|
364
|
+
}
|
|
365
|
+
function failoverLeasePath(agentRoot) {
|
|
366
|
+
return path.join(agentRoot, "state", "presence", "failover.json");
|
|
367
|
+
}
|
|
368
|
+
/** This machine's failover leases; a missing or malformed file holds none. */
|
|
369
|
+
function readFailoverLeases(agentRoot) {
|
|
370
|
+
let parsed;
|
|
371
|
+
try {
|
|
372
|
+
parsed = JSON.parse(fs.readFileSync(failoverLeasePath(agentRoot), "utf-8"));
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
return [];
|
|
376
|
+
}
|
|
377
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.leases))
|
|
378
|
+
return [];
|
|
379
|
+
const leases = [];
|
|
380
|
+
for (const lease of parsed.leases) {
|
|
381
|
+
if (!isRecord(lease))
|
|
382
|
+
continue;
|
|
383
|
+
const sense = text(lease.sense);
|
|
384
|
+
const machine = text(lease.machine);
|
|
385
|
+
const from = text(lease.from);
|
|
386
|
+
const since = text(lease.since);
|
|
387
|
+
if (!sense || !isSharedSense(sense) || !machine || !from || !since)
|
|
388
|
+
continue;
|
|
389
|
+
leases.push({ sense, machine, from, since, reason: text(lease.reason) ?? "" });
|
|
390
|
+
}
|
|
391
|
+
return leases;
|
|
392
|
+
}
|
|
393
|
+
/** Replace this machine's failover leases (an empty list removes the file's leases). */
|
|
394
|
+
function writeFailoverLeases(agentRoot, leases) {
|
|
395
|
+
const target = failoverLeasePath(agentRoot);
|
|
396
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
397
|
+
const temp = `${target}.${process.pid}.tmp`;
|
|
398
|
+
fs.writeFileSync(temp, `${JSON.stringify({ leases }, null, 2)}\n`, "utf-8");
|
|
399
|
+
fs.renameSync(temp, target);
|
|
400
|
+
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.presence_failover_written", message: "updated this machine's failover leases", meta: { agentRoot, senses: leases.map((lease) => lease.sense) } });
|
|
401
|
+
}
|
|
402
|
+
/** The shared senses this machine runs as a stand-in. */
|
|
403
|
+
function failoverSenses(presence, machineId) {
|
|
404
|
+
return exports.SHARED_SENSES.filter((sense) => holdsFailover(presence, machineId, sense));
|
|
349
405
|
}
|
|
350
406
|
/** Read the bundle's agent.json, the local flag and the peer records together. */
|
|
351
407
|
function readPresenceForAgent(agentRoot, options = {}) {
|
|
@@ -359,7 +415,7 @@ function readPresenceForAgent(agentRoot, options = {}) {
|
|
|
359
415
|
catch {
|
|
360
416
|
return null;
|
|
361
417
|
}
|
|
362
|
-
return readPresence(agentJson, true, readPeerRecords(agentRoot));
|
|
418
|
+
return readPresence(agentJson, true, readPeerRecords(agentRoot), readFailoverLeases(agentRoot));
|
|
363
419
|
}
|
|
364
420
|
function isRosterMember(presence, machineId) {
|
|
365
421
|
return presence.block.machines.some((machine) => machine.machineId === machineId);
|
|
@@ -382,7 +438,7 @@ function ownsSense(presence, machineId, sense) {
|
|
|
382
438
|
return false;
|
|
383
439
|
if (!isSharedSense(sense))
|
|
384
440
|
return true;
|
|
385
|
-
return effectiveOwner(presence, sense) === machineId;
|
|
441
|
+
return effectiveOwner(presence, sense) === machineId || holdsFailover(presence, machineId, sense);
|
|
386
442
|
}
|
|
387
443
|
function ownedSharedSenses(presence, machineId) {
|
|
388
444
|
return enabledSharedSenses(presence).filter((sense) => ownsSense(presence, machineId, sense));
|
package/dist/mind/where-am-i.js
CHANGED
|
@@ -93,13 +93,17 @@ function renderWhereAmI(presence, self, nowMs = Date.now()) {
|
|
|
93
93
|
// Only senses agent.json turns on: a disabled sense runs on no machine, whatever the roster's owners say.
|
|
94
94
|
const enabled = (0, presence_1.enabledSharedSenses)(presence);
|
|
95
95
|
const own = enabled.filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) === self.machineId);
|
|
96
|
-
const
|
|
96
|
+
const standIn = (presence.failover ?? []).filter((lease) => lease.machine === self.machineId);
|
|
97
|
+
const elsewhere = enabled.filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) !== self.machineId && !standIn.some((lease) => lease.sense === sense));
|
|
97
98
|
const here = own.map((sense) => {
|
|
98
99
|
// The same wait mayRunSense applies: a peer whose record still runs it has not let go yet.
|
|
99
|
-
const holder = presence.peers.find((peer) => peer.machineId !== self.machineId && (0, presence_1.isRosterMember)(presence, peer.machineId) && peer.owns?.includes(sense));
|
|
100
|
+
const holder = presence.peers.find((peer) => peer.machineId !== self.machineId && (0, presence_1.isRosterMember)(presence, peer.machineId) && peer.owns?.includes(sense) && !peer.failover?.includes(sense));
|
|
100
101
|
return holder ? `${sense} (not yet: waiting for ${machineName(holder.machineId)} to let go)` : sense;
|
|
101
102
|
});
|
|
102
103
|
lines.push(`shared senses that run here: ${here.length > 0 ? here.join(", ") : "none"}.`);
|
|
104
|
+
for (const lease of standIn) {
|
|
105
|
+
lines.push(`i am running ${lease.sense} here in place of ${machineName(lease.from)} since ${ago(lease.since, nowMs)}, because ${lease.reason || "it stopped answering"}; ${machineName(lease.from)} takes it back as soon as it runs again.`);
|
|
106
|
+
}
|
|
103
107
|
if (elsewhere.length > 0) {
|
|
104
108
|
lines.push(`shared senses that run on a peer: ${elsewhere.map((sense) => {
|
|
105
109
|
const owner = (0, presence_1.effectiveOwner)(presence, sense);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1086",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1086",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|