@ouro.bot/cli 0.1.0-alpha.1023 → 0.1.0-alpha.1025

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 CHANGED
@@ -1,6 +1,19 @@
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.1025",
6
+ "changes": [
7
+ "A Copilot account pool's refusals are shared by all of the agent's processes (state/account-refusals.json), so a spent account is skipped everywhere after one 402 or 429 instead of once per process."
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1024",
12
+ "changes": [
13
+ "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.",
14
+ "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."
15
+ ]
16
+ },
4
17
  {
5
18
  "version": "0.1.0-alpha.1023",
6
19
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1023",
2
+ "runtimeVersion": "0.1.0-alpha.1025",
3
3
  "bundleSchemaVersion": 3,
4
4
  "lastUpdated": "2026-09-03T00:00:00.000Z"
5
5
  }
@@ -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.1023</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1025</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -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
- home = parseAgentHome(JSON.parse(fs.readFileSync(path.join(agentRoot, "agent.json"), "utf-8")).home);
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 holdsAHome = machineId !== null && discovered.some((row) => row.home?.machineId === machineId);
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.home) {
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
- /** Record this machine as the agent's home in its synced agent.json. */
99
- async function moveAgentHomeHere(options) {
100
- const { agent, machineId, machineName } = options;
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: "daemon.agent_home_move_start",
110
- message: "moving agent home to this machine",
111
- meta: { agent, machineId },
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 ? "daemon.agent_home_move_end" : "daemon.agent_home_move_error",
119
+ event: result.ok ? `${options.events}_end` : `${options.events}_error`,
118
120
  message: result.message,
119
- meta: { agent, machineId, changed: result.changed },
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 writeHome = (parsed, current) => {
129
- const home = { machineId, machineName, since: now().toISOString() };
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 current = (0, agent_discovery_1.parseAgentHome)(config.parsed.home);
146
- if (current?.machineId === machineId) {
147
- return finish({ ok: true, changed: false, message: `${agent} already lives on this machine (${(0, agent_discovery_1.agentHomeLabel)(current)})` });
148
- }
149
- writeHome(config.parsed, current);
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: `${movedMessage(current)}; ${why}, so only this machine sees the change` });
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 \`ouro move ${agent} here\` again after that`);
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 move waited for the lock (the replay gate
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 move to, so nothing changed`);
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 move must not publish them as a side effect (${why})`);
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 current = (0, agent_discovery_1.parseAgentHome)(config.parsed.home);
199
+ const stamp = options.stamp(config.parsed);
201
200
  if (attempt === 1) {
202
- seen = current;
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 (current?.machineId === machineId) {
209
- return finish({ ok: true, changed: false, message: `${agent} already lives on this machine (${(0, agent_discovery_1.agentHomeLabel)(current)})` });
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
- writeHome(config.parsed, current);
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", `home: ${agent} moves to ${machineName}`, "--", "agent.json"]);
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 move, so nothing changed: ${errorText(error)}`);
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: `${movedMessage(current)}; the bundle has no remote, so only this machine sees the change` });
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: movedMessage(current) });
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
- // pre-move agent.json. If even that fails, say what to run by hand.
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 move 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
+ 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 move, so nothing changed: ${lastPushError}`);
238
+ return refuse(`could not push the ${options.noun}, so nothing changed: ${lastPushError}`);
238
239
  }
239
240
  catch (error) {
240
- return refuse(`could not move ${agent}, so nothing changed: ${errorText(error)}`);
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
- const upstream = JSON.parse(await git(agentRoot, ["show", `${(0, sync_1.syncTrackingRef)(sync)}:agent.json`]));
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" }); });
@@ -128,6 +128,8 @@ const provider_ping_1 = require("../provider-ping");
128
128
  const provider_readiness_cache_1 = require("../provider-readiness-cache");
129
129
  const agent_discovery_1 = require("./agent-discovery");
130
130
  const agent_home_1 = require("./agent-home");
131
+ const presence_roster_1 = require("./presence-roster");
132
+ const presence_1 = require("./presence");
131
133
  const prunable_bundle_1 = require("./prunable-bundle");
132
134
  const boot_sync_probe_1 = require("./boot-sync-probe");
133
135
  const connect_bay_1 = require("./connect-bay");
@@ -2352,6 +2354,65 @@ function currentMachineId(deps) {
2352
2354
  now: () => providerCliNow(deps),
2353
2355
  }).machineId;
2354
2356
  }
2357
+ async function executePresence(command, deps) {
2358
+ const homeDir = providerCliHomeDir(deps);
2359
+ if (command.kind === "presence.location") {
2360
+ (0, presence_1.writeLocalPresenceSettings)({ ...(0, presence_1.readLocalPresenceSettings)(homeDir, {}), location: command.location }, homeDir);
2361
+ const message = `this machine's location is now ${command.location}`;
2362
+ deps.writeStdout(message);
2363
+ return message;
2364
+ }
2365
+ const identity = (0, machine_identity_1.loadOrCreateMachineIdentity)({ homeDir, now: () => providerCliNow(deps) });
2366
+ /* v8 ignore next -- production default: uses real bundles root @preserve */
2367
+ const bundlesRoot = deps.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
2368
+ const agentRoot = path.join(bundlesRoot, `${command.agent}.ouro`);
2369
+ if (command.kind === "presence.status") {
2370
+ const settings = (0, presence_1.readLocalPresenceSettings)(homeDir);
2371
+ let agentJson = null;
2372
+ try {
2373
+ agentJson = JSON.parse(fs.readFileSync(path.join(agentRoot, "agent.json"), "utf-8"));
2374
+ }
2375
+ catch {
2376
+ return returnCliFailure(deps, `cannot read ${command.agent}'s agent.json in ${agentRoot}`);
2377
+ }
2378
+ const presence = (0, presence_1.readPresence)(agentJson, settings.enabled, (0, presence_1.readPeerRecords)(agentRoot));
2379
+ if (command.json) {
2380
+ const json = JSON.stringify((0, presence_roster_1.presenceStatusJson)({ presence, machineId: identity.machineId, settings }));
2381
+ deps.writeStdout(json);
2382
+ return json;
2383
+ }
2384
+ const message = (0, presence_roster_1.renderPresenceStatus)({
2385
+ agent: command.agent,
2386
+ presence,
2387
+ flagEnabled: settings.enabled,
2388
+ machineId: identity.machineId,
2389
+ now: new Date(providerCliNow(deps)),
2390
+ });
2391
+ deps.writeStdout(message);
2392
+ return message;
2393
+ }
2394
+ if (command.kind === "presence.handoff") {
2395
+ const result = await (0, presence_roster_1.handoffPresenceSense)({ agent: command.agent, bundlesRoot, sense: command.sense, target: command.machine });
2396
+ if (!result.ok)
2397
+ return returnCliFailure(deps, result.message);
2398
+ deps.writeStdout(result.message);
2399
+ return result.message;
2400
+ }
2401
+ const result = await (0, presence_roster_1.joinPresenceRoster)({
2402
+ agent: command.agent,
2403
+ bundlesRoot,
2404
+ machineId: identity.machineId,
2405
+ machineName: command.name ?? (0, agent_home_1.machineDisplayName)(os.hostname(), identity.machineId),
2406
+ role: command.role ?? "peer",
2407
+ minVersion: (0, bundle_manifest_1.getPackageVersion)(),
2408
+ });
2409
+ if (!result.ok)
2410
+ return returnCliFailure(deps, result.message);
2411
+ (0, presence_1.writeLocalPresenceSettings)({ ...(0, presence_1.readLocalPresenceSettings)(homeDir, {}), enabled: true }, homeDir);
2412
+ const message = `${result.message}\npresence is on for this machine (~/.ouro-cli/presence.json); restart the daemon with \`ouro up\` so it follows the roster.`;
2413
+ deps.writeStdout(message);
2414
+ return message;
2415
+ }
2355
2416
  async function executeAgentMove(command, deps) {
2356
2417
  const identity = (0, machine_identity_1.loadOrCreateMachineIdentity)({ homeDir: providerCliHomeDir(deps), now: () => providerCliNow(deps) });
2357
2418
  /* v8 ignore next -- production default: uses real bundles root @preserve */
@@ -7625,6 +7686,32 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
7625
7686
  }
7626
7687
  targetVersion = previousVersion;
7627
7688
  }
7689
+ // A daemon below presence knows only `home`: leave every roster first and publish it, so peers
7690
+ // fall back to home before this machine runs shared senses under the home lease.
7691
+ let leftPresence = [];
7692
+ if ((0, presence_1.compareVersions)(targetVersion, presence_1.PRESENCE_FIRST_VERSION) < 0) {
7693
+ const identity = (0, machine_identity_1.readMachineIdentity)(providerCliHomeDir(deps));
7694
+ /* v8 ignore next -- production default: uses real bundles root @preserve */
7695
+ const bundlesRoot = deps.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
7696
+ const unpublished = [];
7697
+ for (const agent of identity ? (0, agent_discovery_1.listAllBundleAgents)({ bundlesRoot, machineId: identity.machineId }).map((row) => row.name) : []) {
7698
+ const agentRoot = path.join(bundlesRoot, `${agent}.ouro`);
7699
+ if (!fs.existsSync(path.join(agentRoot, "presence", `${identity.machineId}.json`)))
7700
+ continue;
7701
+ const published = await (0, presence_1.leavePresence)(agentRoot, identity.machineId, async () => {
7702
+ const sync = readAgentSyncConfigForCliMutation(agent, deps);
7703
+ if (!sync.enabled)
7704
+ return true;
7705
+ return (await (0, sync_1.syncNow)(agentRoot, sync, agent, deps.syncLockWaitMs ?? CLI_SYNC_LOCK_WAIT_MS)).ok;
7706
+ });
7707
+ leftPresence.push(agent);
7708
+ if (!published)
7709
+ unpublished.push(agent);
7710
+ }
7711
+ if (unpublished.length > 0 && !command.force) {
7712
+ return returnCliFailure(deps, `could not publish that this machine left ${unpublished.join(", ")}'s presence roster, so nothing was rolled back: a daemon on ${targetVersion} would run their shared senses while a peer still does; fix bundle sync (\`ouro sync --agent <agent>\`) or rerun with --force`);
7713
+ }
7714
+ }
7628
7715
  writeVersionIntentWithRecoveryLauncher(deps, {
7629
7716
  schemaVersion: 1,
7630
7717
  mode: "pinned",
@@ -7640,7 +7727,7 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
7640
7727
  catch {
7641
7728
  // Daemon may not be running — that's fine
7642
7729
  }
7643
- const message = `rolled back to ${targetVersion} (was ${currentVersion})`;
7730
+ const message = `rolled back to ${targetVersion} (was ${currentVersion})${leftPresence.length > 0 ? `; this machine left the presence roster of ${leftPresence.join(", ")}, so their shared senses stay with home` : ""}`;
7644
7731
  deps.writeStdout(message);
7645
7732
  return message;
7646
7733
  }
@@ -8203,6 +8290,10 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
8203
8290
  if (command.kind === "desk.admin") {
8204
8291
  return (0, desk_admin_1.executeDeskAdminCommand)(command, deps);
8205
8292
  }
8293
+ // ── presence: one agent on several machines (local, no daemon needed) ──
8294
+ if (command.kind === "presence.join" || command.kind === "presence.handoff" || command.kind === "presence.status" || command.kind === "presence.location") {
8295
+ return executePresence(command, deps);
8296
+ }
8206
8297
  // ── move: make this machine the agent's home (local, no daemon needed) ──
8207
8298
  if (command.kind === "agent.move") {
8208
8299
  return executeAgentMove(command, deps);
@@ -118,6 +118,13 @@ exports.COMMAND_REGISTRY = {
118
118
  usage: "ouro move <agent> here",
119
119
  example: "ouro move my-agent here",
120
120
  },
121
+ presence: {
122
+ category: "Agents",
123
+ 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",
124
+ 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|…>",
125
+ example: "ouro presence handoff teams aris-mac-mini --agent my-agent",
126
+ subcommands: ["join", "handoff", "status", "location"],
127
+ },
121
128
  whoami: {
122
129
  category: "Agents",
123
130
  description: "Show current agent identity info",
@@ -3235,10 +3235,46 @@ function parseOuroCommand(args) {
3235
3235
  }
3236
3236
  return { kind: "daemon.dev", repoPath, clone, clonePath };
3237
3237
  }
3238
- if (head === "rollback")
3239
- return { kind: "rollback", ...(second ? { version: second } : {}) };
3238
+ if (head === "rollback") {
3239
+ const rest = args.slice(1);
3240
+ const force = rest.includes("--force");
3241
+ const version = rest.find((arg) => arg !== "--force");
3242
+ return { kind: "rollback", ...(version ? { version } : {}), ...(force ? { force: true } : {}) };
3243
+ }
3240
3244
  if (head === "versions")
3241
3245
  return { kind: "versions" };
3246
+ if (head === "presence") {
3247
+ 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|…>";
3248
+ const { agent, rest } = extractAgentFlag(args.slice(1));
3249
+ const [sub, ...tail] = rest;
3250
+ if (sub === "location") {
3251
+ if (tail.length !== 1 || !tail[0])
3252
+ throw new Error(usage);
3253
+ return { kind: "presence.location", location: tail[0] };
3254
+ }
3255
+ if (!agent)
3256
+ throw new Error(usage);
3257
+ if (sub === "status" && tail.length === 0)
3258
+ return { kind: "presence.status", agent };
3259
+ if (sub === "status" && tail.length === 1 && tail[0] === "--json")
3260
+ return { kind: "presence.status", agent, json: true };
3261
+ if (sub === "handoff" && tail.length === 2)
3262
+ return { kind: "presence.handoff", agent, sense: tail[0], machine: tail[1] };
3263
+ if (sub === "join") {
3264
+ const command = { kind: "presence.join", agent };
3265
+ for (let i = 0; i < tail.length; i++) {
3266
+ const value = tail[i + 1];
3267
+ if ((tail[i] === "--role" || tail[i] === "--name") && value) {
3268
+ command[tail[i] === "--role" ? "role" : "name"] = value;
3269
+ i++;
3270
+ continue;
3271
+ }
3272
+ throw new Error(usage);
3273
+ }
3274
+ return command;
3275
+ }
3276
+ throw new Error(usage);
3277
+ }
3242
3278
  if (head === "move") {
3243
3279
  if (args.length !== 3 || !second || args[2] !== "here")
3244
3280
  throw new Error("Usage: ouro move <agent> here");