@ouro.bot/cli 0.1.0-alpha.1083 → 0.1.0-alpha.1085

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,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.1085",
6
+ "changes": [
7
+ "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."
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1084",
12
+ "changes": [
13
+ "Shepherd leaves Copilot app sessions alone while they wait on something besides their human: a session automation, a session they coordinate that is running or moved in the last two hours, a reply they asked another session for, or a message saying they are waiting. It answers a real stall once, then holds until the human writes again, read from the session's own log so a daemon restart cannot reset it. Its automatic messages are signed [Shepherd for <agent>], never as the human."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1083",
6
18
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1083",
2
+ "runtimeVersion": "0.1.0-alpha.1085",
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.1083</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1085</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -47,7 +47,6 @@ exports.presenceStatusJson = presenceStatusJson;
47
47
  exports.renderPresenceStatus = renderPresenceStatus;
48
48
  const path = __importStar(require("path"));
49
49
  const runtime_1 = require("../../nerves/runtime");
50
- const agent_discovery_1 = require("./agent-discovery");
51
50
  const agent_home_1 = require("./agent-home");
52
51
  const presence_1 = require("./presence");
53
52
  /** Add (or rename) this machine in the agent's roster. Creating a roster keeps every shared sense with `home`. */
@@ -76,13 +75,9 @@ async function joinPresenceRoster(options) {
76
75
  const machines = current
77
76
  ? block.machines.map((machine) => (machine.machineId === machineId ? { machineId, name: machineName, role } : machine))
78
77
  : [...block.machines, { machineId, name: machineName, role }];
79
- const owners = { ...block.owners };
80
- if (!existing) {
81
- const ownerId = (0, agent_discovery_1.parseAgentHome)(parsed.home)?.machineId ?? machineId;
82
- for (const sense of presence_1.SHARED_SENSES)
83
- owners[sense] = ownerId;
84
- }
85
- const next = { ...block, machines, owners };
78
+ // No sense is stamped on whoever joins first: an unclaimed shared sense stays with home until an always-on
79
+ // machine joins, then lives there. `ouro presence handoff` names an owner explicitly.
80
+ const next = { ...block, machines, owners: { ...block.owners } };
86
81
  return {
87
82
  kind: "write",
88
83
  next: { ...parsed, presence: next },
@@ -155,10 +150,10 @@ function presenceStatusJson(options) {
155
150
  const { presence, machineId, settings } = options;
156
151
  (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.presence_status_json", message: "rendered presence status as json", meta: { active: presence !== null } });
157
152
  if (!presence)
158
- return { enabled: settings.enabled, machine: null, peers: [], owns: [], owners: {}, legacy: [] };
153
+ return { enabled: settings.enabled, machine: null, peers: [], owns: [], owners: {}, disabled: [], legacy: [] };
159
154
  const me = presence.block.machines.find((machine) => machine.machineId === machineId);
160
155
  const owners = {};
161
- for (const sense of presence_1.SHARED_SENSES) {
156
+ for (const sense of (0, presence_1.enabledSharedSenses)(presence)) {
162
157
  const owner = (0, presence_1.effectiveOwner)(presence, sense);
163
158
  owners[sense] = presence.block.machines.find((machine) => machine.machineId === owner)?.name ?? owner;
164
159
  }
@@ -171,8 +166,9 @@ function presenceStatusJson(options) {
171
166
  const record = presence.peers.find((peer) => peer.machineId === machine.machineId);
172
167
  return { machineId: machine.machineId, name: machine.name, role: machine.role, seenAt: record?.seenAt ?? null, version: record?.version ?? null, location: record?.location ?? null };
173
168
  }),
174
- owns: presence_1.SHARED_SENSES.filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) === machineId),
169
+ owns: (0, presence_1.enabledSharedSenses)(presence).filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) === machineId),
175
170
  owners,
171
+ disabled: presence_1.SHARED_SENSES.filter((sense) => !(0, presence_1.senseEnabled)(presence, sense)),
176
172
  legacy: presence.legacy.map((id) => presence.block.machines.find((machine) => machine.machineId === id)?.name ?? id),
177
173
  };
178
174
  }
@@ -206,12 +202,15 @@ function renderPresenceStatus(options) {
206
202
  lines.push(`- ${machine.name}${me}: ${machine.role}; ${seen}${legacy}`);
207
203
  }
208
204
  lines.push("owners:");
209
- for (const sense of presence_1.SHARED_SENSES) {
205
+ for (const sense of (0, presence_1.enabledSharedSenses)(presence)) {
210
206
  const owner = (0, presence_1.effectiveOwner)(presence, sense);
211
207
  const name = presence.block.machines.find((machine) => machine.machineId === owner)?.name ?? owner;
212
208
  const declared = presence.block.owners[sense];
213
209
  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
210
  lines.push(`- ${sense}: ${name}${held}`);
215
211
  }
212
+ const off = presence_1.SHARED_SENSES.filter((sense) => !(0, presence_1.senseEnabled)(presence, sense));
213
+ if (off.length > 0)
214
+ lines.push(`turned off in agent.json, so running on no machine: ${off.join(", ")}`);
216
215
  return lines.join("\n");
217
216
  }
@@ -72,6 +72,10 @@ 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;
76
80
  exports.readPresenceForAgent = readPresenceForAgent;
77
81
  exports.isRosterMember = isRosterMember;
@@ -304,7 +308,29 @@ function readPresence(agentJson, localFlag, peerRecords) {
304
308
  // A home off the roster runs every shared sense under the home lease.
305
309
  if (home && !block.machines.some((machine) => machine.machineId === home.machineId))
306
310
  legacy.push(home.machineId);
307
- return { block, home, legacy, peers: peerRecords };
311
+ const enabledSenses = enabledSensesOf(agentJson.senses);
312
+ return { block, home, legacy, peers: peerRecords, ...(enabledSenses ? { enabledSenses } : {}) };
313
+ }
314
+ /** The senses a `senses` block turns on. Habits run on schedulers, not a senses entry, so they count unless turned off. */
315
+ function enabledSensesOf(senses) {
316
+ if (!isRecord(senses))
317
+ return undefined;
318
+ const enabled = Object.entries(senses).filter(([, entry]) => isRecord(entry) && entry.enabled === true).map(([sense]) => sense);
319
+ if (!(isRecord(senses.habits) && senses.habits.enabled === false) && !enabled.includes("habits"))
320
+ enabled.push("habits");
321
+ return enabled;
322
+ }
323
+ /** Whether agent.json turns the sense on. A disabled sense runs nowhere, so no machine owns it in any sense a person cares about. */
324
+ function senseEnabled(presence, sense) {
325
+ return !presence.enabledSenses || presence.enabledSenses.includes(sense);
326
+ }
327
+ /** The shared senses agent.json turns on. */
328
+ function enabledSharedSenses(presence) {
329
+ return exports.SHARED_SENSES.filter((sense) => senseEnabled(presence, sense));
330
+ }
331
+ /** The roster's always-on machine, which keeps any shared sense nobody claimed: a laptop travels and sleeps. */
332
+ function alwaysOnMachine(presence) {
333
+ return presence.block.machines.find((machine) => machine.role === "always-on")?.machineId;
308
334
  }
309
335
  /**
310
336
  * Whether this machine may run a sense now: it owns it, and, for a shared
@@ -348,7 +374,7 @@ function rosterMachine(presence, machineId) {
348
374
  function effectiveOwner(presence, sense) {
349
375
  if (presence.legacy.length > 0 && presence.home)
350
376
  return presence.home.machineId;
351
- return presence.block.owners[sense] ?? presence.home?.machineId ?? presence.block.machines[0].machineId;
377
+ return presence.block.owners[sense] ?? alwaysOnMachine(presence) ?? presence.home?.machineId ?? presence.block.machines[0].machineId;
352
378
  }
353
379
  /** Whether this machine runs this sense under the roster. Machine-scoped senses run on every roster machine. */
354
380
  function ownsSense(presence, machineId, sense) {
@@ -359,7 +385,7 @@ function ownsSense(presence, machineId, sense) {
359
385
  return effectiveOwner(presence, sense) === machineId;
360
386
  }
361
387
  function ownedSharedSenses(presence, machineId) {
362
- return exports.SHARED_SENSES.filter((sense) => ownsSense(presence, machineId, sense));
388
+ return enabledSharedSenses(presence).filter((sense) => ownsSense(presence, machineId, sense));
363
389
  }
364
390
  /** A machine name a person would type: case-insensitive, `.local` ignored; ids match too. */
365
391
  function findRosterMachine(presence, nameOrId) {
@@ -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,29 @@ function renderWhereAmI(presence, self, nowMs = Date.now()) {
86
90
  lines.push(`- ${peer.name} (${facts}): ${seen}`);
87
91
  }
88
92
  }
89
- const own = presence_1.SHARED_SENSES.filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) === self.machineId);
90
- const elsewhere = presence_1.SHARED_SENSES.filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) !== self.machineId);
91
- lines.push(`shared senses i own here: ${own.length > 0 ? own.join(", ") : "none"}.`);
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 elsewhere = enabled.filter((sense) => (0, presence_1.effectiveOwner)(presence, sense) !== self.machineId);
97
+ const here = own.map((sense) => {
98
+ // 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
+ return holder ? `${sense} (not yet: waiting for ${machineName(holder.machineId)} to let go)` : sense;
101
+ });
102
+ lines.push(`shared senses that run here: ${here.length > 0 ? here.join(", ") : "none"}.`);
92
103
  if (elsewhere.length > 0) {
93
- lines.push(`owned by a peer: ${elsewhere.map((sense) => `${sense} (${machineName((0, presence_1.effectiveOwner)(presence, sense))})`).join(", ")}.`);
104
+ lines.push(`shared senses that run on a peer: ${elsewhere.map((sense) => {
105
+ const owner = (0, presence_1.effectiveOwner)(presence, sense);
106
+ const record = presence.peers.find((peer) => peer.machineId === owner);
107
+ 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";
108
+ return `${sense} (${machineName(owner)}; ${shown})`;
109
+ }).join(", ")}.`);
94
110
  }
95
- lines.push("machine-scoped senses (cli, shepherd, app-sessions) run on every presence and see only their own machine.");
111
+ const off = presence_1.SHARED_SENSES.filter((sense) => !(0, presence_1.senseEnabled)(presence, sense)).map((sense) => SENSE_NAMES[sense] ?? sense);
112
+ if (off.length > 0)
113
+ lines.push(`turned off in agent.json, so running on no machine: ${off.join(", ")}.`);
114
+ const local = MACHINE_SENSES.filter((sense) => (0, presence_1.senseEnabled)(presence, sense));
115
+ lines.push(`machine-scoped senses that run on every presence and see only their own machine: ${local.length > 0 ? local.join(", ") : "none"}.`);
96
116
  if (presence.legacy.length > 0) {
97
117
  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
118
  }
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.HANDOFF_TOOLS = exports.CHILD_RECENT_MS = void 0;
37
+ exports.databaseHold = databaseHold;
38
+ exports.copilotAppHold = copilotAppHold;
39
+ const fs = __importStar(require("node:fs"));
40
+ const path = __importStar(require("node:path"));
41
+ const sqlite_1 = require("../../heart/sqlite");
42
+ const runtime_1 = require("../../nerves/runtime");
43
+ /**
44
+ * Why Shepherd leaves a stopped Copilot app session alone. A session that is waiting on something
45
+ * other than its human (a schedule, a lane it coordinates, a reply it asked for) is not stalled,
46
+ * and one Shepherd already nudged since its human last wrote is not nudged again. Every reason
47
+ * comes from the app's own records, so it holds across daemon restarts and across machines.
48
+ */
49
+ /** A coordinated session that moved this recently still counts as live work. */
50
+ exports.CHILD_RECENT_MS = 2 * 3_600_000;
51
+ /** Tools that hand work to another session, whose answer the caller then waits for. */
52
+ exports.HANDOFF_TOOLS = new Set([
53
+ "send_session_message", "create_session", "write_agent", "open_pr_session", "open_issue_session", "fork_session", "run_dynamic_workflow",
54
+ ]);
55
+ /** What the agent says when it is waiting on something other than its human. */
56
+ const WAITING_WORDS = new RegExp([
57
+ String.raw `\b(?:i'?m|i am|we'?re|still|now|currently|just)\s+(?:waiting|holding)\b`,
58
+ String.raw `\bwaiting\s+(?:on|for|until)\b`,
59
+ String.raw `\b(?:i'?ll|i will|will|going to)\s+(?:wait|hold|check back|report back|pick (?:it|this) up)\b`,
60
+ String.raw `\b(?:until|once|when)\s+(?:it|they|that|those|the \w+|#\d+|\w+'s \w+)\s+(?:lands?|merges?|finish(?:es)?|repl(?:y|ies)|reports?|returns?|completes?|comes? back|is (?:in|done|merged|green))\b`,
61
+ String.raw `\bbackground (?:agents?|tasks?|lanes?|work|shells?|jobs?)\b`,
62
+ String.raw `\blanes? (?:is|are) (?:running|working|under ?way)\b`,
63
+ String.raw `\bon hold\b`,
64
+ ].join("|"), "i");
65
+ function hasTable(db, table) {
66
+ return !!db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table);
67
+ }
68
+ function columns(db, table) {
69
+ return new Set(db.prepare(`SELECT name FROM pragma_table_info('${table}')`).all().map(row => row.name));
70
+ }
71
+ /** The app database's reasons to leave the session alone, or null. A database that exists but cannot be read holds. */
72
+ function databaseHold(stateDir, sessionId, now) {
73
+ const file = path.join(stateDir, "data.db");
74
+ if (!fs.existsSync(file))
75
+ return null;
76
+ let db;
77
+ try {
78
+ db = (0, sqlite_1.openDatabase)(file, { readonly: true, fileMustExist: true, timeout: 3_000 });
79
+ }
80
+ catch (error) {
81
+ return `the Copilot app database could not be read (${String(error).slice(0, 120)})`;
82
+ }
83
+ try {
84
+ if (hasTable(db, "session_automations")) {
85
+ const automation = db.prepare(`SELECT name FROM session_automations
86
+ WHERE (session_id = ? OR owner_session_id = ?) AND paused_at IS NULL LIMIT 1`).get(sessionId, sessionId);
87
+ if (automation)
88
+ return `it has a session automation${automation.name ? ` ("${automation.name}")` : ""}, which wakes it on schedule`;
89
+ }
90
+ const children = [];
91
+ if (hasTable(db, "workspaces") && hasTable(db, "sessions")) {
92
+ const has = columns(db, "workspaces");
93
+ const by = ["creator_session_id", "coordinating_creator_session_id"].filter(column => has.has(column));
94
+ if (by.length > 0) {
95
+ children.push(...db.prepare(`SELECT s.id, s.title, s.is_running, s.updated_at FROM workspaces w JOIN sessions s ON s.id = w.session_id
96
+ WHERE w.archived_at IS NULL AND s.id != ? AND (${by.map(column => `w.${column} = ?`).join(" OR ")})`).all(sessionId, ...by.map(() => sessionId)));
97
+ }
98
+ }
99
+ if (hasTable(db, "chat_parent_links") && hasTable(db, "sessions")) {
100
+ const has = columns(db, "chat_parent_links");
101
+ const by = ["parent_session_id", "coordinating_creator_session_id"].filter(column => has.has(column));
102
+ if (by.length > 0) {
103
+ children.push(...db.prepare(`SELECT s.id, s.title, s.is_running, s.updated_at FROM chat_parent_links c JOIN sessions s ON s.id = c.session_id
104
+ WHERE s.archived_at IS NULL AND s.id != ? AND (${by.map(column => `c.${column} = ?`).join(" OR ")})`).all(sessionId, ...by.map(() => sessionId)));
105
+ }
106
+ }
107
+ const live = children.filter(child => child.is_running === 1 || now - Date.parse(child.updated_at ?? "") < exports.CHILD_RECENT_MS);
108
+ if (live.length > 0) {
109
+ const named = live.slice(0, 3).map(child => child.title ? `"${child.title.slice(0, 60)}"` : child.id.slice(0, 8)).join(", ");
110
+ return `it coordinates ${live.length} live session${live.length === 1 ? "" : "s"} (${named}${live.length > 3 ? ", …" : ""}) and waits on them`;
111
+ }
112
+ return null;
113
+ }
114
+ catch (error) {
115
+ return `the Copilot app database could not be read (${String(error).slice(0, 120)})`;
116
+ }
117
+ finally {
118
+ db.close();
119
+ }
120
+ }
121
+ /** Why Shepherd must not nudge this stopped session, or null when it may judge it. */
122
+ function copilotAppHold(stateDir, sessionId, facts, lastBody, now) {
123
+ const reason = holdReason(stateDir, sessionId, facts, lastBody, now);
124
+ (0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.shepherd_copilot_app_hold", message: reason ? "Shepherd holds off a stopped Copilot app session" : "no hold on a stopped Copilot app session",
125
+ meta: { session: sessionId.slice(0, 8), held: reason !== null } });
126
+ return reason;
127
+ }
128
+ function holdReason(stateDir, sessionId, facts, lastBody, now) {
129
+ if (facts.shepherdAt !== null && (facts.humanAt === null || facts.humanAt < facts.shepherdAt)) {
130
+ return "Shepherd already nudged it once since its human last wrote; one nudge per stall";
131
+ }
132
+ const handoff = facts.lastTurnTools.find(tool => exports.HANDOFF_TOOLS.has(tool));
133
+ if (handoff)
134
+ return `its last turn handed work to another session (${handoff}), so it is waiting on that reply`;
135
+ if (lastBody && WAITING_WORDS.test(lastBody))
136
+ return "its last message says it is waiting on something other than its human";
137
+ return databaseHold(stateDir, sessionId, now);
138
+ }
@@ -49,6 +49,7 @@ const node_crypto_1 = require("node:crypto");
49
49
  const ws_1 = __importDefault(require("ws"));
50
50
  const runtime_1 = require("../../nerves/runtime");
51
51
  const cmux_1 = require("./cmux");
52
+ const copilot_app_holds_1 = require("./copilot-app-holds");
52
53
  /**
53
54
  * The GitHub Copilot app host. The app runs a local WebSocket server whose port and token it
54
55
  * rewrites under `<stateDir>/run/` on every launch, so each connection reads them fresh. Shepherd
@@ -192,6 +193,8 @@ function readConversation(stateDir, sessionId) {
192
193
  const lines = [];
193
194
  const permissions = new Map();
194
195
  let humanAt = null;
196
+ let shepherdAt = null;
197
+ let lastTurnTools = [];
195
198
  const push = (block) => {
196
199
  for (const line of block.split(/\r?\n/))
197
200
  lines.push(line);
@@ -217,6 +220,12 @@ function readConversation(stateDir, sessionId) {
217
220
  continue;
218
221
  switch (event.type) {
219
222
  case "user.message":
223
+ lastTurnTools = [];
224
+ if (SHEPHERD_LABEL.test(str(data.content) ?? "")) {
225
+ const at = Date.parse(str(event.timestamp) ?? "");
226
+ if (!Number.isNaN(at))
227
+ shepherdAt = at;
228
+ }
220
229
  if (str(data.content))
221
230
  push(`› ${str(data.source) ? `(${data.source}) ` : ""}${data.content}`);
222
231
  break;
@@ -225,6 +234,8 @@ function readConversation(stateDir, sessionId) {
225
234
  push(data.content);
226
235
  break;
227
236
  case "tool.execution_start": {
237
+ if (str(data.toolName))
238
+ lastTurnTools.push(data.toolName);
228
239
  const args = isRecord(data.arguments) ? data.arguments : {};
229
240
  const what = str(args.description) ?? str(args.command) ?? str(args.question) ?? str(args.path) ?? "";
230
241
  push(`• ${str(data.toolName) ?? "tool"}${what ? `: ${what.replace(/\s+/g, " ").slice(0, 160)}` : ""}`);
@@ -254,7 +265,7 @@ function readConversation(stateDir, sessionId) {
254
265
  const pending = [...permissions.entries()].at(-1);
255
266
  if (pending)
256
267
  lines.push(`Waiting for permission: ${pending[1].replace(/\s+/g, " ").slice(0, 300)}`);
257
- return { lines, pendingPermission: pending?.[0] ?? null, humanAt };
268
+ return { lines, pendingPermission: pending?.[0] ?? null, humanAt, shepherdAt, lastTurnTools };
258
269
  }
259
270
  /** One connection: frames go to `onFrame` until the socket closes. Throws if the socket cannot be created. */
260
271
  function openStream(url, openSocket, onFrame, onClose) {
@@ -482,10 +493,27 @@ function createCopilotAppHost(connection, options = {}) {
482
493
  const session = inventory.find(candidate => candidate.id === sessionId);
483
494
  if (!session)
484
495
  return;
496
+ const body = lastBody.get(sessionId) ?? null;
497
+ let hold;
498
+ try {
499
+ let facts = { humanAt: null, shepherdAt: null, lastTurnTools: [] };
500
+ try {
501
+ facts = readConversation(stateDir, sessionId);
502
+ }
503
+ catch (error) {
504
+ // A session with no log yet has said and been sent nothing.
505
+ if (error.code !== "ENOENT")
506
+ throw error;
507
+ }
508
+ hold = (0, copilot_app_holds_1.copilotAppHold)(stateDir, sessionId, facts, body, now());
509
+ }
510
+ catch (error) {
511
+ hold = `its records could not be read (${String(error).slice(0, 120)})`;
512
+ }
485
513
  handlers.returned({
486
514
  sessionId, transitionId, agent: session.agent, cwd: session.cwd ?? null,
487
515
  workspaceTitle: session.workspaceTitle ?? null, title: session.title,
488
- lastBody: lastBody.get(sessionId) ?? null, backgroundWork,
516
+ lastBody: body, backgroundWork, hold,
489
517
  });
490
518
  }, GRACE_MS));
491
519
  };
@@ -78,6 +78,7 @@ const BLOCK_DESCRIPTION = {
78
78
  state_changed: "it changed while I was looking",
79
79
  custody: "an earlier reply may still be on its way",
80
80
  stopped: "Shepherd was stopping",
81
+ hold: "it's waiting on something besides you, or I already nudged it once",
81
82
  };
82
83
  /** Kinds a "needs-me" owner still hears about. */
83
84
  const NEEDS_ME = new Set(["gate", "done", "loop_guard"]);
@@ -430,6 +430,8 @@ async function startShepherdSenseApp(options) {
430
430
  void wake(wakeIds.splice(0));
431
431
  }, WAKE_DELAY_MS);
432
432
  };
433
+ /** Automatic input is signed by Shepherd itself: the human sent none of it. */
434
+ const automaticLabel = `[Shepherd for ${presentation.name}]`;
433
435
  async function dispatch(record, reply, instance, screenFingerprint, expected, canSend) {
434
436
  const claim = custody.claimDispatch({ host: host.name, session: record.session, instance, screenFingerprint,
435
437
  guidanceRevision: String(record.guidanceRevision), reply: reply.text,
@@ -443,9 +445,9 @@ async function startShepherdSenseApp(options) {
443
445
  let result;
444
446
  try {
445
447
  if (expected)
446
- result = await host.promptIfUnchanged(record.session, `[${presentation.name} for ${human}] ${exports.PERIODIC_RESUME}`, expected, canSend);
448
+ result = await host.promptIfUnchanged(record.session, `${automaticLabel} ${exports.PERIODIC_RESUME}`, expected, canSend);
447
449
  else {
448
- await host.prompt(record.session, `[${presentation.name} for ${human}] ${reply.text}`);
450
+ await host.prompt(record.session, `${automaticLabel} ${reply.text}`);
449
451
  result = { state: "sent" };
450
452
  }
451
453
  }
@@ -520,6 +522,13 @@ async function startShepherdSenseApp(options) {
520
522
  notice = false;
521
523
  return;
522
524
  }
525
+ if (!periodic && event.hold) {
526
+ // The host says this stop is not a stall: no judge call, no input and no notice.
527
+ Object.assign(record, { kind: "working", reason: `held: ${event.hold}` });
528
+ record.actionBlockReason = "hold";
529
+ notice = false;
530
+ return;
531
+ }
523
532
  if (!periodic && event.backgroundWork && state.backgroundBody !== undefined && state.backgroundBody === event.lastBody) {
524
533
  // Still waiting on the same background work with nothing new to say: no judge call.
525
534
  Object.assign(record, { kind: "working", reason: "still waiting on its background work; nothing new since the last judgment" });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1083",
3
+ "version": "0.1.0-alpha.1085",
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.1083",
9
+ "version": "0.1.0-alpha.1085",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.78.0",
12
12
  "@ouro.bot/friends": "0.1.0-alpha.18",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1083",
3
+ "version": "0.1.0-alpha.1085",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },