@ouro.bot/cli 0.1.0-alpha.1647 → 0.1.0-alpha.1648

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
@@ -2,18 +2,28 @@
2
2
  "_note": "Each pull request writes its own change note under changes/; the release job on main gives each landed change its version and adds the notes here (scripts/release-version.cjs). On main this file stops at the last version set by hand; the published package has every release. Agents read this file directly via read_file to understand what changed between versions.",
3
3
  "versions": [
4
4
  {
5
- "version": "0.1.0-alpha.1647",
5
+ "version": "0.1.0-alpha.1648",
6
6
  "changes": [
7
- "A letter now closes as expired once its `expiresAt` has passed with no answer. The daemon checks every minute and waits ten minutes past the expiry before closing a letter, so an answer the person sent in time still counts when it is read late. It then releases anyone waiting on the letter and wakes the agent that owns it with a note in its private runtime: \"letter L7 expired at … with no answer from my person\". An expired letter can't be answered or delivered. A new private-runtime policy rule allows that wake only when it names the letter and comes from the expiry pass.",
8
- "A `now` letter whose sender sets no `expiresAt` now expires 24 hours after it is filed. Other letters still never expire unless their sender says so. Refiling a letter with the same `dedupeKey` doesn't extend its expiry, and once a letter is past its expiry the same `dedupeKey` files a new letter.",
9
- "`mailbox_send` refuses an `expiresAt` that has already passed.",
10
- "A daemon with no letters loads none of the mailbox's code for the expiry pass.",
11
7
  "The Butler's host upgrade tells the bundle migration which Butler name the new image runs (`--butler-name`), so the bundle's own files (agent.json, the replay-client provisioning record, recent attachments, skills and HOUSE.md) name the container path that image mounts.",
12
8
  "An await filed from an external event still resolves after the Butler's events folder moves to its other name, in either direction.",
13
9
  "When the Butler starts and finds events saved under its other name, it merges them into its own folder even when both folders exist. It combines the privileged spool's replay manifests first, so no accepted envelope is accepted twice. A record both folders have keeps the running Butler's copy, and the other copy moves to `external-events/.adoption-conflicts/<other name>/<time>/`, with a warning; nothing is deleted and the start goes on. Only a move that fails stops the daemon from starting, with guidance naming the container and Unraid host paths. An other-name entry that is a symlink is left alone, with a warning.",
14
10
  "An upgrade that would change the Butler's name is refused, before anything is paused or changed, unless the running release can take a rollback across the rename. Ship a release from after this change with the name unchanged first, then the release that renames it.",
15
11
  "A held upgrade (`--hold-commit`) now says that a rollback puts the migrated bundle files back as they were before the migrate, so edits made to them during the hold are lost.",
16
- "The health acceptance probe runs as the Butler whose bundle is on disk, and the privileged spool scan files envelopes under the Butler the daemon start set, so neither recreates the other name's events folder after the rename."
12
+ "The health acceptance probe runs as the Butler whose bundle is on disk, and the privileged spool scan files envelopes under the Butler the daemon start set, so neither recreates the other name's events folder after the rename.",
13
+ "A letter filed from an agent's turn now remembers that turn's session. Once the person's answer is recorded, the daemon queues \"Ari answered L7: 2 Ouro — after lunch\" in that session, so the conversation that asked reads the answer on its next turn. A letter filed from the private runtime, the CLI or an MCP client has no session to return to. The agent's private runtime is told of every answer as before, and anyone waiting with `mailbox_wait` is released as before.",
14
+ "Each try to return an answer writes a `returned` event. A try that fails is tried again after a minute, then after a doubling wait of at most an hour, until it succeeds.",
15
+ "The session must be one the agent has really had turns in. A voice session gets no returned note, because a voice call drops notes older than a few minutes. The note comes from the mailbox, so Telegram's rule that drops an agent's own stale outreach doesn't remove it.",
16
+ "The agent's private runtime note about an answer now names the session that asked, so the agent can raise the answer there sooner than that session's next turn.",
17
+ "When another caller refiles a letter, the reply says the answer returns to the session that first filed it."
18
+ ]
19
+ },
20
+ {
21
+ "version": "0.1.0-alpha.1646",
22
+ "changes": [
23
+ "A letter now closes as expired once its `expiresAt` has passed with no answer. The daemon checks every minute and waits ten minutes past the expiry before closing a letter, so an answer the person sent in time still counts when it is read late. It then releases anyone waiting on the letter and wakes the agent that owns it with a note in its private runtime: \"letter L7 expired at … with no answer from my person\". An expired letter can't be answered or delivered. A new private-runtime policy rule allows that wake only when it names the letter and comes from the expiry pass.",
24
+ "A `now` letter whose sender sets no `expiresAt` now expires 24 hours after it is filed. Other letters still never expire unless their sender says so. Refiling a letter with the same `dedupeKey` doesn't extend its expiry, and once a letter is past its expiry the same `dedupeKey` files a new letter.",
25
+ "`mailbox_send` refuses an `expiresAt` that has already passed.",
26
+ "A daemon with no letters loads none of the mailbox's code for the expiry pass."
17
27
  ]
18
28
  },
19
29
  {
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1647",
2
+ "runtimeVersion": "0.1.0-alpha.1648",
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.1647</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1648</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -1232,13 +1232,18 @@ class OuroDaemon {
1232
1232
  }
1233
1233
  }
1234
1234
  /**
1235
- * One expiry pass. It reads no letters code until some bundle has letters, so a daemon without them loads nothing.
1236
- * Answers how many letters it closed.
1235
+ * One expiry pass, which also retries returning answers to the sessions that asked. It reads no letters code until
1236
+ * some bundle has letters, so a daemon without them loads nothing. Answers how many letters it closed.
1237
1237
  */
1238
1238
  async expireLetters() {
1239
1239
  try {
1240
1240
  const any = !!this.lettersWriter || fs.readdirSync(this.bundlesRoot).some((name) => fs.existsSync(path.join(this.bundlesRoot, name, "state", "letters")));
1241
- return any ? await (await this.letters()).expireDue() : 0;
1241
+ if (!any)
1242
+ return 0;
1243
+ const writer = await this.letters();
1244
+ const expired = await writer.expireDue();
1245
+ await writer.returnAnswers();
1246
+ return expired;
1242
1247
  }
1243
1248
  catch (error) {
1244
1249
  // No bundles folder yet means no letters, not a failure worth a warning every minute.
@@ -55,7 +55,10 @@ function answerReceipt(letter, answer) {
55
55
  /** The agent's note; the subject, label and note are other people's words, so they are quoted as theirs. */
56
56
  function letterAnsweredNote(letter, answer) {
57
57
  const note = answer.note ? `, with the note ${JSON.stringify(answer.note)}` : "";
58
- return `my person answered letter ${letter.code} (its sender's subject: ${JSON.stringify(letter.subject)}) with option ${answer.option}, ${JSON.stringify(answer.label)}${note}. mailbox_read shows it.`;
58
+ const session = letter.from.session;
59
+ // The session that asked reads the answer on its next turn; naming it lets me raise the answer there sooner.
60
+ const asked = session ? ` it was asked from my ${session.channel} session with ${session.friendId} (${JSON.stringify(session.key)}), where the answer is left too.` : "";
61
+ return `my person answered letter ${letter.code} (its sender's subject: ${JSON.stringify(letter.subject)}) with option ${answer.option}, ${JSON.stringify(answer.label)}${note}.${asked} mailbox_read shows it.`;
59
62
  }
60
63
  function letterAnsweredWake(agent, letter) {
61
64
  return {
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ANSWERING_FILE = void 0;
36
+ exports.listBundleFriends = exports.ANSWERING_FILE = void 0;
37
37
  exports.ownerFriendIds = ownerFriendIds;
38
38
  exports.normalizeAnsweringHandle = normalizeAnsweringHandle;
39
39
  exports.readAnsweringHandles = readAnsweringHandles;
@@ -52,8 +52,9 @@ const friends_1 = require("@ouro.bot/friends");
52
52
  const runtime_1 = require("../../nerves/runtime");
53
53
  exports.ANSWERING_FILE = "answering.json";
54
54
  const listBundleFriends = (root) => new friends_1.FileFriendStore(path.join(root, "friends")).listAll();
55
+ exports.listBundleFriends = listBundleFriends;
55
56
  /** The family records in a bundle's friends folder that name this machine's owner, the rule `ouro friend link-code` uses. */
56
- async function ownerFriendIds(bundleRoot, owner, list = listBundleFriends) {
57
+ async function ownerFriendIds(bundleRoot, owner, list = exports.listBundleFriends) {
57
58
  const friends = await list(bundleRoot);
58
59
  return friends
59
60
  .filter((record) => record.trustLevel === "family" && record.externalIds.some((id) => (0, friends_1.isLocalMachineOwnerIdentity)(id.provider, id.externalId, owner)))
@@ -164,7 +165,7 @@ async function setAnsweringHandle(bundleRoot, person, rawHandle, deps = {}) {
164
165
  const checked = normalizeAnsweringHandle(rawHandle);
165
166
  if (!checked.ok)
166
167
  throw refusal("bad-handle", checked.problem);
167
- const list = deps.list ?? listBundleFriends;
168
+ const list = deps.list ?? exports.listBundleFriends;
168
169
  const friends = await list(bundleRoot);
169
170
  const byId = friends.find((record) => record.id === person);
170
171
  const byName = friends.filter((record) => record.name.toLowerCase() === person.toLowerCase());
@@ -35,6 +35,7 @@ async function runMailboxTool(name, args, ctx) {
35
35
  try {
36
36
  return JSON.stringify(await (0, doors_1.runMailboxAction)(name, input, {
37
37
  agent: ctx?.agentName ?? (0, identity_1.getAgentName)(),
38
+ ...(ctx?.currentSession ? { session: { friendId: ctx.currentSession.friendId, channel: ctx.currentSession.channel, key: ctx.currentSession.key } } : {}),
38
39
  ...(ctx?.daemonSocketPath ? { socketPath: ctx.daemonSocketPath } : {}),
39
40
  }));
40
41
  }
@@ -218,7 +218,10 @@ async function runMailboxAction(action, input, caller) {
218
218
  }
219
219
  const send = caller.send ?? (await Promise.resolve().then(() => __importStar(require("../daemon/socket-client")))).sendDaemonCommand;
220
220
  const socketPath = caller.socketPath ?? (await Promise.resolve().then(() => __importStar(require("../daemon/socket-client")))).DEFAULT_DAEMON_SOCKET_PATH;
221
- const command = { kind: "letters.action", agent: caller.agent, action, input, ...(caller.dryRun ? { dryRun: true } : {}) };
221
+ const command = {
222
+ kind: "letters.action", agent: caller.agent, action, input, ...(caller.dryRun ? { dryRun: true } : {}),
223
+ ...(caller.session && action === "mailbox_send" ? { session: caller.session } : {}),
224
+ };
222
225
  // A wait holds the socket for its own timeout, and a deliver for its chat send (the daemon answers within
223
226
  // DELIVER_DEADLINE_MS of starting it, perhaps after another deliver ahead of it); anything else answers at once.
224
227
  const waitSeconds = action === "mailbox_wait" ? Number(input.timeout ?? 60) : action === "mailbox_deliver" ? 60 : 0;
@@ -0,0 +1,99 @@
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.RETURN_BACKOFF_MAX_MS = void 0;
37
+ exports.returnSession = returnSession;
38
+ exports.answerReturnText = answerReturnText;
39
+ exports.queueAnswerReturn = queueAnswerReturn;
40
+ exports.returnDue = returnDue;
41
+ // Returning a person's answer to the session that asked (design §3.4, "Answer return"). A letter filed from an
42
+ // agent's turn remembers that turn's session; once the answer is recorded, the daemon queues a note in that session,
43
+ // so its next turn reads "Ari answered L7: Ouro". The agent's private runtime is told separately (answered-note.ts).
44
+ const fs = __importStar(require("fs"));
45
+ const config_1 = require("../config");
46
+ const pending_1 = require("../../mind/pending");
47
+ const runtime_1 = require("../../nerves/runtime");
48
+ /**
49
+ * Channels a returned note can't serve: the private runtime is told of every answer anyway, and a voice session drops
50
+ * any note older than a few minutes unread.
51
+ */
52
+ const NO_RETURN_CHANNELS = new Set(["inner", "voice"]);
53
+ /**
54
+ * The session a letter returns its answer to, or null when there is none to return to: a caller with no session
55
+ * (the CLI, an MCP client), a channel in NO_RETURN_CHANNELS, coordinates that would name a folder outside the
56
+ * agent's own, or a session the agent has never had. With `agentRoot`, the session must have its session file.
57
+ */
58
+ function returnSession(value, agentRoot) {
59
+ if (typeof value !== "object" || value === null)
60
+ return null;
61
+ const { friendId, channel, key } = value;
62
+ if (![friendId, channel, key].every((part) => (0, config_1.isValidSessionCoordinate)(part) && part.length <= 300))
63
+ return null;
64
+ const session = { friendId: friendId, channel: channel, key: key };
65
+ if (NO_RETURN_CHANNELS.has(session.channel))
66
+ return null;
67
+ if (agentRoot !== undefined && !fs.existsSync((0, config_1.resolveSessionPath)(session.friendId, session.channel, session.key, { agentRoot })))
68
+ return null;
69
+ return session;
70
+ }
71
+ /** The note the asking session reads; the label and note are the person's words. */
72
+ function answerReturnText(person, letter, answer) {
73
+ return `${person} answered ${letter.code}: ${answer.option} ${answer.label}${answer.note ? ` — ${answer.note}` : ""}`;
74
+ }
75
+ /** Queues the note in the session's pending folder, once per letter. A failed write throws. */
76
+ function queueAnswerReturn(agent, agentRoot, session, text, letter, at) {
77
+ (0, pending_1.queuePendingMessageOnce)((0, pending_1.getPendingDir)(agent, session.friendId, session.channel, session.key, agentRoot), {
78
+ // From the mailbox, not the agent: a Telegram session drops the agent's own stale notes unread.
79
+ from: "mailbox", friendId: session.friendId, channel: session.channel, key: session.key, content: text, timestamp: Date.parse(at), packetId: `letter-returned:${letter.id}`,
80
+ });
81
+ (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.answer_returned", message: "an answer was returned to the session that asked", meta: { code: letter.code, channel: session.channel } });
82
+ }
83
+ /** The longest wait between tries, so a session that can't be written is still tried every hour. */
84
+ exports.RETURN_BACKOFF_MAX_MS = 60 * 60_000;
85
+ /**
86
+ * Whether an answered letter's return is due now: it has a session, no try has succeeded, and the wait after the last
87
+ * failed try (one minute, doubling, at most an hour) has passed.
88
+ */
89
+ function returnDue(letter, events, now) {
90
+ if (!returnSession(letter.from.session) || !events.some((event) => event.t === "answered"))
91
+ return false;
92
+ const tries = events.filter((event) => event.t === "returned" && event.to === "session");
93
+ if (tries.some((event) => event.ok))
94
+ return false;
95
+ if (tries.length === 0)
96
+ return true;
97
+ const wait = Math.min(60_000 * 2 ** (tries.length - 1), exports.RETURN_BACKOFF_MAX_MS);
98
+ return now >= Date.parse(tries[tries.length - 1].at) + wait;
99
+ }
@@ -46,6 +46,7 @@ const answer_reader_1 = require("./answer-reader");
46
46
  const letter_1 = require("./letter");
47
47
  const answering_1 = require("./answering");
48
48
  Object.defineProperty(exports, "ownerFriendIds", { enumerable: true, get: function () { return answering_1.ownerFriendIds; } });
49
+ const return_to_session_1 = require("./return-to-session");
49
50
  const render_1 = require("./render");
50
51
  const letter_index_1 = require("./letter-index");
51
52
  const store_1 = require("./store");
@@ -115,18 +116,19 @@ class LettersWriter {
115
116
  if (typeof input !== "object" || input === null || Array.isArray(input))
116
117
  throw new LetterRefusal("bad-input", "The action's input must be an object.");
117
118
  const letters = this.open(agent, options.dryRun === true);
118
- const result = await this.dispatch(letters, action, input, options.dryRun === true);
119
+ const session = action === "mailbox_send" ? (0, return_to_session_1.returnSession)(options.session, path.join(this.deps.bundlesRoot, `${agent}.ouro`)) : null;
120
+ const result = await this.dispatch(letters, action, input, options.dryRun === true, session);
119
121
  (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.action_done", message: "letters action done", meta: { action, outcome: result.outcome } });
120
122
  return result;
121
123
  }
122
- dispatch(letters, action, input, dryRun) {
124
+ dispatch(letters, action, input, dryRun, session) {
123
125
  switch (action) {
124
126
  case "mailbox_send": return this.serial(letters, () => {
125
127
  // Each send first rolls the letters closed long enough, so a daemon that runs for months still rolls them; a
126
128
  // dry run writes nothing, so it doesn't roll.
127
129
  if (!dryRun)
128
130
  this.rollClosed(letters);
129
- return this.send(letters, input, dryRun);
131
+ return this.send(letters, input, dryRun, session);
130
132
  });
131
133
  case "mailbox_list": return Promise.resolve(this.list(letters, input));
132
134
  case "mailbox_read": return Promise.resolve(this.read(letters, input));
@@ -229,12 +231,12 @@ class LettersWriter {
229
231
  ? "No family friend record names this machine's owner, so Ouro can't tell who the letter is to."
230
232
  : `${ids.length} family records name this machine's owner, so Ouro can't tell which one the letter is to.`);
231
233
  }
232
- async send(letters, input, dryRun) {
234
+ async send(letters, input, dryRun, session) {
233
235
  const checked = (0, letter_1.checkLetterInput)(input);
234
236
  if (!checked.ok)
235
237
  throw new LetterRefusal("invalid-letter", checked.problem);
236
238
  const { lane, ...draft } = checked.letter;
237
- const from = { agent: letters.agent, ...(lane ? { lane } : {}) };
239
+ const from = { agent: letters.agent, ...(session ? { session } : {}), ...(lane ? { lane } : {}) };
238
240
  const now = this.now();
239
241
  if (draft.expiresAt && Date.parse(draft.expiresAt) <= now.getTime()) {
240
242
  throw new LetterRefusal("invalid-letter", `expiresAt ${draft.expiresAt} has already passed. Fix: give a time in the future, or leave it out.`);
@@ -249,7 +251,8 @@ class LettersWriter {
249
251
  return { outcome: "done", id: letter.id, code: letter.code, state: "answered", message: `${letter.code} was answered ${optionText(letter, answer.option)} in the last day, so the answer stands.` };
250
252
  }
251
253
  this.addEvent(letters, letter.id, { t: "refiled", at: now.toISOString(), by: letters.agent });
252
- return { outcome: "done", id: letter.id, code: letter.code, state: "waiting", message: `${letter.code} is already waiting with this dedupeKey, so it was refiled, not filed again.` };
254
+ const elsewhere = letter.from.session && JSON.stringify(letter.from.session) !== JSON.stringify(session) ? " Its answer returns to the session that first filed it." : "";
255
+ return { outcome: "done", id: letter.id, code: letter.code, state: "waiting", message: `${letter.code} is already waiting with this dedupeKey, so it was refiled, not filed again.${elsewhere}` };
253
256
  }
254
257
  const to = await this.person(letters.agent);
255
258
  if (dryRun)
@@ -332,9 +335,76 @@ class LettersWriter {
332
335
  const label = letter.options.find((option) => option.id === answer.option).label;
333
336
  (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.answer_recorded", message: "a person's answer was recorded", meta: { code: letter.code, hostTrust } });
334
337
  this.deps.onAnswered?.(letters.agent, letter, { option: answer.option, label, ...(answer.note ? { note: answer.note } : {}), messageGuid: message.guid, at }).catch(() => undefined);
338
+ // Its own step on the queue, so the person's answer is recorded and answered on whatever the return does.
339
+ void this.serial(letters, () => this.returnAnswer(letters, letter.id)).catch((error) => {
340
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.return_step_failed", message: "an answer's return step failed; the retry pass tries it again", meta: { code: letter.code, reason: error.message } });
341
+ });
335
342
  return { recorded: true, id: letter.id, code: letter.code, subject: letter.subject, option: answer.option, label, ...(answer.note ? { note: answer.note } : {}) };
336
343
  });
337
344
  }
345
+ /**
346
+ * Returns an answered letter's answer to the session that asked, when that is due, and records the try as a
347
+ * `returned` event. A failed try is retried by returnAnswers; the answer stands either way.
348
+ */
349
+ async returnAnswer(letters, id) {
350
+ const entry = letters.index.get(id);
351
+ const { letter } = entry;
352
+ if (!(0, return_to_session_1.returnDue)(letter, entry.events, this.now().getTime()))
353
+ return false;
354
+ const answer = entry.events.findLast((event) => event.t === "answered");
355
+ const label = letter.options.find((option) => option.id === answer.option).label;
356
+ const at = this.now().toISOString();
357
+ try {
358
+ const bundle = path.join(this.deps.bundlesRoot, `${letters.agent}.ouro`);
359
+ const friends = await (this.deps.listFriends ?? answering_1.listBundleFriends)(bundle).catch(() => []);
360
+ const person = friends.find((friend) => friend.id === letter.to)?.name || "my person";
361
+ (0, return_to_session_1.queueAnswerReturn)(letters.agent, bundle, letter.from.session, (0, return_to_session_1.answerReturnText)(person, letter, { option: answer.option, label, ...(answer.note ? { note: answer.note } : {}) }), letter, answer.at);
362
+ this.addEvent(letters, id, { t: "returned", at, to: "session", ok: true });
363
+ }
364
+ catch (error) {
365
+ const detail = error.message;
366
+ this.addEvent(letters, id, { t: "returned", at, to: "session", ok: false, detail });
367
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.return_failed", message: "an answer couldn't be returned to the session that asked; it will be tried again", meta: { code: letter.code, detail } });
368
+ }
369
+ return true;
370
+ }
371
+ /**
372
+ * Tries again every answer whose return to its session failed and is due, across the bundles that have letters.
373
+ * The daemon runs it on a timer; it answers how many it tried.
374
+ */
375
+ async returnAnswers() {
376
+ let tried = 0;
377
+ let names = [];
378
+ try {
379
+ names = fs.readdirSync(this.deps.bundlesRoot);
380
+ }
381
+ catch (error) {
382
+ if (error.code !== "ENOENT")
383
+ throw error;
384
+ }
385
+ for (const name of names) {
386
+ const agent = name.endsWith(".ouro") ? name.slice(0, -".ouro".length) : "";
387
+ if (!AGENT_NAME.test(agent) || !fs.existsSync(path.join(this.deps.bundlesRoot, name, "state", "letters")))
388
+ continue;
389
+ try {
390
+ const letters = this.open(agent, false);
391
+ tried += await this.serial(letters, async () => {
392
+ const now = this.now().getTime();
393
+ let count = 0;
394
+ for (const entry of letters.index.list({ all: true }).filter((entry) => entry.state === "answered")) {
395
+ if ((0, return_to_session_1.returnDue)(entry.letter, entry.events, now) && await this.returnAnswer(letters, entry.letter.id))
396
+ count += 1;
397
+ }
398
+ return count;
399
+ });
400
+ }
401
+ catch (error) {
402
+ // One agent's letters that don't read leave the others' returns alone.
403
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.returns_failed", message: "an agent's answers could not be checked for return", meta: { agent, reason: error.message } });
404
+ }
405
+ }
406
+ return tried;
407
+ }
338
408
  list(letters, input) {
339
409
  const now = this.now().getTime();
340
410
  const entries = letters.index.list({
@@ -456,7 +526,7 @@ function mayHaveSent(error) {
456
526
  /** The daemon's answer to a `letters.action` command: the result, or the refusal's code and text. */
457
527
  async function answerLettersCommand(writer, command) {
458
528
  try {
459
- return { ok: true, data: await writer.run(command.agent, command.action, command.input, { dryRun: command.dryRun === true }) };
529
+ return { ok: true, data: await writer.run(command.agent, command.action, command.input, { dryRun: command.dryRun === true, session: command.session }) };
460
530
  }
461
531
  catch (error) {
462
532
  if (error instanceof LetterRefusal)
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1647",
3
+ "version": "0.1.0-alpha.1648",
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.1647",
9
+ "version": "0.1.0-alpha.1648",
10
10
  "bundleDependencies": [
11
11
  "@ouro.bot/friends"
12
12
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1647",
3
+ "version": "0.1.0-alpha.1648",
4
4
  "description": "Ouroboros, the agent harness: agents with durable memory that live where you talk (terminal, Teams, iMessage, mail, voice) and use real tools. Start with npx ouro.bot@latest.",
5
5
  "homepage": "https://ouroboros.bot/",
6
6
  "engines": {