@ouro.bot/cli 0.1.0-alpha.1084 → 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 +12 -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 +55 -13
- package/dist/heart/daemon/presence.js +89 -7
- package/dist/mind/where-am-i.js +29 -5
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
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
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1085",
|
|
12
|
+
"changes": [
|
|
13
|
+
"Presence names only the senses agent.json turns on: a disabled sense is listed as running on no machine, never as owned by one, in ouro presence status (with a new disabled list in --json), in published records and in the agent's where-i-am. A shared sense with no named owner now lives on the roster's always-on machine instead of whoever joined first, and joining no longer stamps every sense on the first machine. Where-i-am says whether each sense actually runs here or, per the peer's own record, there, and lists machine-scoped senses from agent.json instead of a fixed list."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1084",
|
|
6
18
|
"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,11 +43,11 @@ 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"));
|
|
49
50
|
const runtime_1 = require("../../nerves/runtime");
|
|
50
|
-
const agent_discovery_1 = require("./agent-discovery");
|
|
51
51
|
const agent_home_1 = require("./agent-home");
|
|
52
52
|
const presence_1 = require("./presence");
|
|
53
53
|
/** Add (or rename) this machine in the agent's roster. Creating a roster keeps every shared sense with `home`. */
|
|
@@ -76,13 +76,9 @@ async function joinPresenceRoster(options) {
|
|
|
76
76
|
const machines = current
|
|
77
77
|
? block.machines.map((machine) => (machine.machineId === machineId ? { machineId, name: machineName, role } : machine))
|
|
78
78
|
: [...block.machines, { machineId, name: machineName, role }];
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
for (const sense of presence_1.SHARED_SENSES)
|
|
83
|
-
owners[sense] = ownerId;
|
|
84
|
-
}
|
|
85
|
-
const next = { ...block, machines, owners };
|
|
79
|
+
// No sense is stamped on whoever joins first: an unclaimed shared sense stays with home until an always-on
|
|
80
|
+
// machine joins, then lives there. `ouro presence handoff` names an owner explicitly.
|
|
81
|
+
const next = { ...block, machines, owners: { ...block.owners } };
|
|
86
82
|
return {
|
|
87
83
|
kind: "write",
|
|
88
84
|
next: { ...parsed, presence: next },
|
|
@@ -150,15 +146,52 @@ async function handoffPresenceSense(options) {
|
|
|
150
146
|
},
|
|
151
147
|
});
|
|
152
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
|
+
}
|
|
153
186
|
/** `ouro presence status --json`: this machine, its peers and what it owns, for tools such as an arrival check. */
|
|
154
187
|
function presenceStatusJson(options) {
|
|
155
188
|
const { presence, machineId, settings } = options;
|
|
156
189
|
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.presence_status_json", message: "rendered presence status as json", meta: { active: presence !== null } });
|
|
157
190
|
if (!presence)
|
|
158
|
-
return { enabled: settings.enabled, machine: null, peers: [], owns: [], owners: {}, legacy: [] };
|
|
191
|
+
return { enabled: settings.enabled, machine: null, peers: [], owns: [], failover: [], owners: {}, disabled: [], legacy: [] };
|
|
159
192
|
const me = presence.block.machines.find((machine) => machine.machineId === machineId);
|
|
160
193
|
const owners = {};
|
|
161
|
-
for (const sense of presence_1.
|
|
194
|
+
for (const sense of (0, presence_1.enabledSharedSenses)(presence)) {
|
|
162
195
|
const owner = (0, presence_1.effectiveOwner)(presence, sense);
|
|
163
196
|
owners[sense] = presence.block.machines.find((machine) => machine.machineId === owner)?.name ?? owner;
|
|
164
197
|
}
|
|
@@ -171,8 +204,12 @@ function presenceStatusJson(options) {
|
|
|
171
204
|
const record = presence.peers.find((peer) => peer.machineId === machine.machineId);
|
|
172
205
|
return { machineId: machine.machineId, name: machine.name, role: machine.role, seenAt: record?.seenAt ?? null, version: record?.version ?? null, location: record?.location ?? null };
|
|
173
206
|
}),
|
|
174
|
-
owns: presence_1.
|
|
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
|
+
})),
|
|
175
211
|
owners,
|
|
212
|
+
disabled: presence_1.SHARED_SENSES.filter((sense) => !(0, presence_1.senseEnabled)(presence, sense)),
|
|
176
213
|
legacy: presence.legacy.map((id) => presence.block.machines.find((machine) => machine.machineId === id)?.name ?? id),
|
|
177
214
|
};
|
|
178
215
|
}
|
|
@@ -206,12 +243,17 @@ function renderPresenceStatus(options) {
|
|
|
206
243
|
lines.push(`- ${machine.name}${me}: ${machine.role}; ${seen}${legacy}`);
|
|
207
244
|
}
|
|
208
245
|
lines.push("owners:");
|
|
209
|
-
for (const sense of presence_1.
|
|
246
|
+
for (const sense of (0, presence_1.enabledSharedSenses)(presence)) {
|
|
210
247
|
const owner = (0, presence_1.effectiveOwner)(presence, sense);
|
|
211
248
|
const name = presence.block.machines.find((machine) => machine.machineId === owner)?.name ?? owner;
|
|
212
249
|
const declared = presence.block.owners[sense];
|
|
213
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)` : "";
|
|
214
|
-
|
|
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}`);
|
|
215
254
|
}
|
|
255
|
+
const off = presence_1.SHARED_SENSES.filter((sense) => !(0, presence_1.senseEnabled)(presence, sense));
|
|
256
|
+
if (off.length > 0)
|
|
257
|
+
lines.push(`turned off in agent.json, so running on no machine: ${off.join(", ")}`);
|
|
216
258
|
return lines.join("\n");
|
|
217
259
|
}
|
|
@@ -72,7 +72,16 @@ exports.presenceSettingsPath = presenceSettingsPath;
|
|
|
72
72
|
exports.readLocalPresenceSettings = readLocalPresenceSettings;
|
|
73
73
|
exports.writeLocalPresenceSettings = writeLocalPresenceSettings;
|
|
74
74
|
exports.readPresence = readPresence;
|
|
75
|
+
exports.enabledSensesOf = enabledSensesOf;
|
|
76
|
+
exports.senseEnabled = senseEnabled;
|
|
77
|
+
exports.enabledSharedSenses = enabledSharedSenses;
|
|
78
|
+
exports.alwaysOnMachine = alwaysOnMachine;
|
|
75
79
|
exports.mayRunSense = mayRunSense;
|
|
80
|
+
exports.holdsFailover = holdsFailover;
|
|
81
|
+
exports.failoverLeasePath = failoverLeasePath;
|
|
82
|
+
exports.readFailoverLeases = readFailoverLeases;
|
|
83
|
+
exports.writeFailoverLeases = writeFailoverLeases;
|
|
84
|
+
exports.failoverSenses = failoverSenses;
|
|
76
85
|
exports.readPresenceForAgent = readPresenceForAgent;
|
|
77
86
|
exports.isRosterMember = isRosterMember;
|
|
78
87
|
exports.rosterMachine = rosterMachine;
|
|
@@ -179,6 +188,8 @@ function parsePeerRecord(value) {
|
|
|
179
188
|
}
|
|
180
189
|
if (Array.isArray(value.owns))
|
|
181
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");
|
|
182
193
|
if (isRecord(value.appSessions))
|
|
183
194
|
record.appSessions = value.appSessions;
|
|
184
195
|
return record;
|
|
@@ -287,7 +298,7 @@ function writeLocalPresenceSettings(settings, homeDir = os.homedir()) {
|
|
|
287
298
|
* The presence this machine should follow, or null for today's one-home lease
|
|
288
299
|
* (flag off, or no usable block).
|
|
289
300
|
*/
|
|
290
|
-
function readPresence(agentJson, localFlag, peerRecords) {
|
|
301
|
+
function readPresence(agentJson, localFlag, peerRecords, failover = []) {
|
|
291
302
|
if (!localFlag || !isRecord(agentJson))
|
|
292
303
|
return null;
|
|
293
304
|
const block = parsePresenceBlock(agentJson.presence);
|
|
@@ -304,7 +315,29 @@ function readPresence(agentJson, localFlag, peerRecords) {
|
|
|
304
315
|
// A home off the roster runs every shared sense under the home lease.
|
|
305
316
|
if (home && !block.machines.some((machine) => machine.machineId === home.machineId))
|
|
306
317
|
legacy.push(home.machineId);
|
|
307
|
-
|
|
318
|
+
const enabledSenses = enabledSensesOf(agentJson.senses);
|
|
319
|
+
return { block, home, legacy, peers: peerRecords, ...(enabledSenses ? { enabledSenses } : {}), ...(failover.length > 0 ? { failover } : {}) };
|
|
320
|
+
}
|
|
321
|
+
/** The senses a `senses` block turns on. Habits run on schedulers, not a senses entry, so they count unless turned off. */
|
|
322
|
+
function enabledSensesOf(senses) {
|
|
323
|
+
if (!isRecord(senses))
|
|
324
|
+
return undefined;
|
|
325
|
+
const enabled = Object.entries(senses).filter(([, entry]) => isRecord(entry) && entry.enabled === true).map(([sense]) => sense);
|
|
326
|
+
if (!(isRecord(senses.habits) && senses.habits.enabled === false) && !enabled.includes("habits"))
|
|
327
|
+
enabled.push("habits");
|
|
328
|
+
return enabled;
|
|
329
|
+
}
|
|
330
|
+
/** Whether agent.json turns the sense on. A disabled sense runs nowhere, so no machine owns it in any sense a person cares about. */
|
|
331
|
+
function senseEnabled(presence, sense) {
|
|
332
|
+
return !presence.enabledSenses || presence.enabledSenses.includes(sense);
|
|
333
|
+
}
|
|
334
|
+
/** The shared senses agent.json turns on. */
|
|
335
|
+
function enabledSharedSenses(presence) {
|
|
336
|
+
return exports.SHARED_SENSES.filter((sense) => senseEnabled(presence, sense));
|
|
337
|
+
}
|
|
338
|
+
/** The roster's always-on machine, which keeps any shared sense nobody claimed: a laptop travels and sleeps. */
|
|
339
|
+
function alwaysOnMachine(presence) {
|
|
340
|
+
return presence.block.machines.find((machine) => machine.role === "always-on")?.machineId;
|
|
308
341
|
}
|
|
309
342
|
/**
|
|
310
343
|
* Whether this machine may run a sense now: it owns it, and, for a shared
|
|
@@ -319,7 +352,56 @@ function mayRunSense(presence, machineId, sense) {
|
|
|
319
352
|
return false;
|
|
320
353
|
if (!isSharedSense(sense))
|
|
321
354
|
return true;
|
|
322
|
-
|
|
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));
|
|
323
405
|
}
|
|
324
406
|
/** Read the bundle's agent.json, the local flag and the peer records together. */
|
|
325
407
|
function readPresenceForAgent(agentRoot, options = {}) {
|
|
@@ -333,7 +415,7 @@ function readPresenceForAgent(agentRoot, options = {}) {
|
|
|
333
415
|
catch {
|
|
334
416
|
return null;
|
|
335
417
|
}
|
|
336
|
-
return readPresence(agentJson, true, readPeerRecords(agentRoot));
|
|
418
|
+
return readPresence(agentJson, true, readPeerRecords(agentRoot), readFailoverLeases(agentRoot));
|
|
337
419
|
}
|
|
338
420
|
function isRosterMember(presence, machineId) {
|
|
339
421
|
return presence.block.machines.some((machine) => machine.machineId === machineId);
|
|
@@ -348,7 +430,7 @@ function rosterMachine(presence, machineId) {
|
|
|
348
430
|
function effectiveOwner(presence, sense) {
|
|
349
431
|
if (presence.legacy.length > 0 && presence.home)
|
|
350
432
|
return presence.home.machineId;
|
|
351
|
-
return presence.block.owners[sense] ?? presence.home?.machineId ?? presence.block.machines[0].machineId;
|
|
433
|
+
return presence.block.owners[sense] ?? alwaysOnMachine(presence) ?? presence.home?.machineId ?? presence.block.machines[0].machineId;
|
|
352
434
|
}
|
|
353
435
|
/** Whether this machine runs this sense under the roster. Machine-scoped senses run on every roster machine. */
|
|
354
436
|
function ownsSense(presence, machineId, sense) {
|
|
@@ -356,10 +438,10 @@ function ownsSense(presence, machineId, sense) {
|
|
|
356
438
|
return false;
|
|
357
439
|
if (!isSharedSense(sense))
|
|
358
440
|
return true;
|
|
359
|
-
return effectiveOwner(presence, sense) === machineId;
|
|
441
|
+
return effectiveOwner(presence, sense) === machineId || holdsFailover(presence, machineId, sense);
|
|
360
442
|
}
|
|
361
443
|
function ownedSharedSenses(presence, machineId) {
|
|
362
|
-
return
|
|
444
|
+
return enabledSharedSenses(presence).filter((sense) => ownsSense(presence, machineId, sense));
|
|
363
445
|
}
|
|
364
446
|
/** A machine name a person would type: case-insensitive, `.local` ignored; ids match too. */
|
|
365
447
|
function findRosterMachine(presence, nameOrId) {
|
package/dist/mind/where-am-i.js
CHANGED
|
@@ -65,6 +65,10 @@ function sessionCounts(record) {
|
|
|
65
65
|
const parts = Object.entries(counts).filter(([, count]) => typeof count === "number").map(([state, count]) => `${count} ${state}`);
|
|
66
66
|
return parts.length > 0 ? `; copilot app sessions: ${parts.join(", ")}` : "";
|
|
67
67
|
}
|
|
68
|
+
/** Senses every presence runs for its own machine. */
|
|
69
|
+
const MACHINE_SENSES = ["cli", "shepherd", "app-sessions"];
|
|
70
|
+
/** What a person calls a sense whose name is the integration's. */
|
|
71
|
+
const SENSE_NAMES = { bluebubbles: "bluebubbles (iMessage)" };
|
|
68
72
|
function renderWhereAmI(presence, self, nowMs = Date.now()) {
|
|
69
73
|
if (!presence)
|
|
70
74
|
return "";
|
|
@@ -86,13 +90,33 @@ function renderWhereAmI(presence, self, nowMs = Date.now()) {
|
|
|
86
90
|
lines.push(`- ${peer.name} (${facts}): ${seen}`);
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
93
|
+
// Only senses agent.json turns on: a disabled sense runs on no machine, whatever the roster's owners say.
|
|
94
|
+
const enabled = (0, presence_1.enabledSharedSenses)(presence);
|
|
95
|
+
const own = enabled.filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) === self.machineId);
|
|
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));
|
|
98
|
+
const here = own.map((sense) => {
|
|
99
|
+
// The same wait mayRunSense applies: a peer whose record still runs it has not let go yet.
|
|
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));
|
|
101
|
+
return holder ? `${sense} (not yet: waiting for ${machineName(holder.machineId)} to let go)` : sense;
|
|
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
|
+
}
|
|
92
107
|
if (elsewhere.length > 0) {
|
|
93
|
-
lines.push(`
|
|
108
|
+
lines.push(`shared senses that run on a peer: ${elsewhere.map((sense) => {
|
|
109
|
+
const owner = (0, presence_1.effectiveOwner)(presence, sense);
|
|
110
|
+
const record = presence.peers.find((peer) => peer.machineId === owner);
|
|
111
|
+
const shown = record?.owns?.includes(sense) ? `its record from ${ago(record.seenAt, nowMs)} says it runs it` : "its last record does not show it running";
|
|
112
|
+
return `${sense} (${machineName(owner)}; ${shown})`;
|
|
113
|
+
}).join(", ")}.`);
|
|
94
114
|
}
|
|
95
|
-
|
|
115
|
+
const off = presence_1.SHARED_SENSES.filter((sense) => !(0, presence_1.senseEnabled)(presence, sense)).map((sense) => SENSE_NAMES[sense] ?? sense);
|
|
116
|
+
if (off.length > 0)
|
|
117
|
+
lines.push(`turned off in agent.json, so running on no machine: ${off.join(", ")}.`);
|
|
118
|
+
const local = MACHINE_SENSES.filter((sense) => (0, presence_1.senseEnabled)(presence, sense));
|
|
119
|
+
lines.push(`machine-scoped senses that run on every presence and see only their own machine: ${local.length > 0 ? local.join(", ") : "none"}.`);
|
|
96
120
|
if (presence.legacy.length > 0) {
|
|
97
121
|
lines.push(`until ${presence.legacy.map((id) => machineName(id)).join(", ")} publish${presence.legacy.length === 1 ? "es" : ""} a current presence record, every shared sense stays with home.`);
|
|
98
122
|
}
|
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",
|