@ouro.bot/cli 0.1.0-alpha.1631 → 0.1.0-alpha.1633

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,17 @@
1
1
  {
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
+ {
5
+ "version": "0.1.0-alpha.1633",
6
+ "changes": [
7
+ "Reopening a saved Ouro chat in an ACP client such as Orca now works, and long chats come back whole. Before, the client was never told it could reopen them, and longer chats lost their latest turns when reopened.",
8
+ "When something inside Ouro fails during an ACP chat (for example the daemon restarting), Orca now shows that error instead of asking you to sign in.",
9
+ "The agent can no longer write something that passes for a letter into the person's letters chat (the one-to-one iMessage chat with their answering handle). The BlueBubbles client refuses agent text there that folds to a letter code such as `L7`, `L8` or `letter 3`, or to `Options (from Ouro):`, before anything reaches the server. It does the same for an attachment's file name, and for an edit that would turn any message into a letter. Only Ouro's own rendered letters carry the mark that lets them through. Ordinary text, other chats and group chats are unaffected.",
10
+ "The letters chat is found however a send names it: by its chat GUID in any field, by the GUID's own one-to-one shape even when a display name marks the chat as a group, and by the handle frozen on any letter still open, after the person's handle has changed. If `answering.json` doesn't read, coded text is refused in every one-to-one chat rather than let through.",
11
+ "When the letters chat refuses the agent's text, the agent hears why. A refused reply ends that turn without a retry, and a note in the agent's private runtime says the person hasn't heard back. `send_message` and `surface` return the refusal's own words. A caption is checked before its image or file goes, so a refusal never leaves half a message.",
12
+ "A proactive message the guard refuses is dropped from the outbox rather than retried on every drain, and the agent is told why. A mid-turn message the guard refuses is refused before it is counted as seen, so a later timeout or restart still replays the turn. A chat marked as a group decides nothing on its own: its handle does."
13
+ ]
14
+ },
4
15
  {
5
16
  "version": "0.1.0-alpha.1631",
6
17
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1631",
2
+ "runtimeVersion": "0.1.0-alpha.1633",
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.1631</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1633</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -37,6 +37,7 @@ exports.ANSWERING_FILE = void 0;
37
37
  exports.ownerFriendIds = ownerFriendIds;
38
38
  exports.normalizeAnsweringHandle = normalizeAnsweringHandle;
39
39
  exports.readAnsweringHandles = readAnsweringHandles;
40
+ exports.checkAnsweringHandles = checkAnsweringHandles;
40
41
  exports.writeAnsweringHandle = writeAnsweringHandle;
41
42
  exports.setAnsweringHandle = setAnsweringHandle;
42
43
  // Who letters go to, and the handles they answer from (design §3.4). A letter goes to the one family record naming
@@ -103,10 +104,14 @@ function readFile(lettersDir) {
103
104
  }
104
105
  /** Each person's answering handle, by friend id. Filing reads it; a file that doesn't read gives nobody a handle. */
105
106
  function readAnsweringHandles(lettersDir) {
107
+ return checkAnsweringHandles(lettersDir) ?? {};
108
+ }
109
+ /** Each person's answering handle, or null when the file doesn't read, for a caller that must fail closed. */
110
+ function checkAnsweringHandles(lettersDir) {
106
111
  const file = readFile(lettersDir);
107
112
  if (!file.ok) {
108
113
  (0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.answering_unreadable", message: "the answering handles file doesn't read, so no letter gets a handle", meta: { problem: file.problem } });
109
- return {};
114
+ return null;
110
115
  }
111
116
  const result = {};
112
117
  for (const [friendId, handle] of Object.entries(file.handles)) {
@@ -115,6 +115,10 @@ class LetterStore {
115
115
  this.syncDir(this.dir);
116
116
  (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.letter_rolled", message: "closed letter rolled", meta: { month } });
117
117
  }
118
+ /** Every readable letter not yet rolled into closed/; the chat guard reads it to cover handles frozen on letters. */
119
+ loadOpen() {
120
+ return this.letterFiles(this.dir).map((file) => this.parse(file, false)).filter((letter) => letter !== null);
121
+ }
118
122
  /** Every readable letter, open and closed, for rebuilding the index when the daemon starts. */
119
123
  loadAll() {
120
124
  const loaded = [];
@@ -1049,6 +1049,8 @@ exports.sessionToolDefinitions = [
1049
1049
  const { getProactiveInternalContentBlockReason, proactiveContentBlockGuidance } = await Promise.resolve().then(() => __importStar(require("../senses/proactive-content-guard")));
1050
1050
  return { status: "blocked", detail: proactiveContentBlockGuidance(getProactiveInternalContentBlockReason(request.content)) };
1051
1051
  }
1052
+ if (result.reason === "letter_guard")
1053
+ return { status: "blocked", detail: result.detail };
1052
1054
  if (result.reason === "send_error") {
1053
1055
  return {
1054
1056
  status: "failed",
@@ -232,6 +232,8 @@ function spontaneousOutreachSenders(agentName, agentRoot, content, queueItem, im
232
232
  const sent = await sendProactiveBlueBubblesMessageToSession({ friendId: target.friendId, sessionKey: target.key, text: content, intent: "generic_outreach", origin: "proactive", ...(imagePath ? { imagePath } : {}) });
233
233
  if (sent.reason === "image_unsendable")
234
234
  return { status: "refused", why: sent.detail ?? "the image could not be sent", imageProblem: true };
235
+ if (sent.reason === "letter_guard")
236
+ return { status: "refused", why: sent.detail };
235
237
  if (sent.delivered)
236
238
  return { status: "delivered", detail: "texted them by iMessage now" };
237
239
  if (sent.delivery?.state === "unknown")
@@ -38,6 +38,7 @@ const node_crypto_1 = require("node:crypto");
38
38
  const readline = __importStar(require("node:readline"));
39
39
  const frontend_socket_client_1 = require("../heart/frontend-socket-client");
40
40
  const runtime_1 = require("../nerves/runtime");
41
+ const bundle_manifest_1 = require("../mind/bundle-manifest");
41
42
  const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
42
43
  class AcpProtocolError extends Error {
43
44
  code;
@@ -286,7 +287,12 @@ function createAcpServer(options) {
286
287
  return;
287
288
  if (requestParams.protocolVersion !== 1)
288
289
  throw new AcpProtocolError(-32602, "protocolVersion must be 1");
289
- result(id, { protocolVersion: 1 });
290
+ result(id, {
291
+ protocolVersion: 1,
292
+ // Clients only reopen a saved chat when loading is advertised; observe-only mode refuses it.
293
+ agentCapabilities: { loadSession: !options.disableTools },
294
+ agentInfo: { name: "ouro", title: "Ouro", version: (0, bundle_manifest_1.getPackageVersion)() },
295
+ });
290
296
  return;
291
297
  }
292
298
  if (method === "session/new") {
@@ -311,22 +317,35 @@ function createAcpServer(options) {
311
317
  }
312
318
  const sessionId = requiredString(requestParams.sessionId, "sessionId");
313
319
  const frontend = await client();
314
- const replay = await frontend.request("session.load", {
315
- agent: options.agent,
316
- friendId: options.friendId,
317
- sessionKey: sessionId,
318
- afterSequence: 0,
319
- });
320
- if (!Array.isArray(replay?.events) || replay.events.length === 0) {
321
- throw new AcpProtocolError(-32001, "session not found");
320
+ // The journal answers in pages of up to 1,000 events; read every page so the newest turns show.
321
+ const events = [];
322
+ let pendingPermissions = [];
323
+ let afterSequence = 0;
324
+ for (;;) {
325
+ const page = await frontend.request("session.load", {
326
+ agent: options.agent,
327
+ friendId: options.friendId,
328
+ sessionKey: sessionId,
329
+ afterSequence,
330
+ });
331
+ const pageEvents = Array.isArray(page?.events) ? page.events : [];
332
+ events.push(...pageEvents);
333
+ pendingPermissions = page?.pendingPermissions ?? [];
334
+ const last = pageEvents.at(-1)?.sequence;
335
+ if (page?.hasMore !== true || typeof last !== "number" || last <= afterSequence)
336
+ break;
337
+ afterSequence = last;
322
338
  }
339
+ // -32002 is ACP's resource-not-found code; clients start a new session for an unsaved chat on it.
340
+ if (events.length === 0)
341
+ throw new AcpProtocolError(-32002, "session not found");
323
342
  // The replay rebuilds which calls are open; counters from an earlier load, or live events that
324
343
  // arrived while this load was pending (the journal holds them too), would misnumber them.
325
344
  toolCalls.delete(sessionId);
326
- for (const event of replay.events)
345
+ for (const event of events)
327
346
  replayEvent(sessionId, event);
328
347
  await subscribe(sessionId);
329
- for (const pending of replay.pendingPermissions ?? [])
348
+ for (const pending of pendingPermissions)
330
349
  permissionRequest(sessionId, pending);
331
350
  result(id, {});
332
351
  return;
@@ -388,7 +407,8 @@ function createAcpServer(options) {
388
407
  }
389
408
  catch (caught) {
390
409
  const id = request.id ?? null;
391
- const code = caught instanceof AcpProtocolError ? caught.code : -32000;
410
+ // ACP reserves -32000 for "authentication required", so an internal failure is JSON-RPC's -32603.
411
+ const code = caught instanceof AcpProtocolError ? caught.code : -32603;
392
412
  error(id, code, caught instanceof Error ? caught.message : String(caught));
393
413
  }
394
414
  }
@@ -49,6 +49,7 @@ const machine_identity_1 = require("../../heart/machine-identity");
49
49
  const runtime_credentials_1 = require("../../heart/runtime-credentials");
50
50
  const runtime_1 = require("../../nerves/runtime");
51
51
  const client_1 = require("./client");
52
+ const letter_guard_1 = require("./letter-guard");
52
53
  function text(value) {
53
54
  return typeof value === "string" ? value.trim() : "";
54
55
  }
@@ -120,7 +121,7 @@ async function sendLetterByBlueBubbles(request, agentRoot, clientFor = blueBubbl
120
121
  const client = await clientFor(request.agent, agentRoot);
121
122
  let sent;
122
123
  try {
123
- sent = await client.sendText({ chat: chatWithHandle(request.handle), text: request.text });
124
+ sent = await client.sendText({ chat: chatWithHandle(request.handle), text: request.text, mark: letter_guard_1.OURO_LETTER_SEND });
124
125
  }
125
126
  catch (error) {
126
127
  // A chat that doesn't exist yet can't be found by its handle; say what the person does about it.
@@ -12,6 +12,7 @@ const model_1 = require("./model");
12
12
  const media_1 = require("./media");
13
13
  const host_account_verifier_1 = require("./host-account-verifier");
14
14
  const send_health_1 = require("./send-health");
15
+ const letter_guard_1 = require("./letter-guard");
15
16
  class BlueBubblesSendError extends Error {
16
17
  httpStatus;
17
18
  status;
@@ -306,6 +307,13 @@ function createBlueBubblesClient(config = (0, config_1.getBlueBubblesConfig)(),
306
307
  const declaredHostUsername = () => "hostUsername" in hostOptions
307
308
  ? hostOptions.hostUsername
308
309
  : (0, identity_1.loadAgentConfig)().senses?.bluebubbles.hostUsername;
310
+ const agentRoot = () => hostOptions.agentRoot ?? (0, identity_1.getAgentRoot)(agentName());
311
+ // Agent text that could pass for a letter never reaches the person's letters chat (letter-guard.ts).
312
+ const guardLetterChat = (input) => {
313
+ const refused = (0, letter_guard_1.letterChatRefusal)(input, agentRoot());
314
+ if (refused)
315
+ throw new BlueBubblesSendError({ message: refused, httpStatus: null, errorCode: "letter_guard", transportInvoked: false });
316
+ };
309
317
  const recordBlocked = (code, detail) => (0, send_health_1.recordBlueBubblesSendBlocked)(agentName(), { code, detail }, hostOptions.agentRoot);
310
318
  const recordDelivered = (via) => (0, send_health_1.recordBlueBubblesSendDelivered)(agentName(), via, hostOptions.agentRoot);
311
319
  const assertHostAccount = (options = {}) => (0, host_account_verifier_1.verifyBlueBubblesServerAccount)({
@@ -322,6 +330,7 @@ function createBlueBubblesClient(config = (0, config_1.getBlueBubblesConfig)(),
322
330
  if (!trimmedText) {
323
331
  throw new Error("BlueBubbles send requires non-empty text.");
324
332
  }
333
+ guardLetterChat({ what: "message", chat: params.chat, text: trimmedText, mark: params.mark });
325
334
  const server = await assertHostAccount({ fresh: true });
326
335
  const resolvedChatGuid = await resolveChatGuid(params.chat, config, channelConfig);
327
336
  if (!resolvedChatGuid) {
@@ -460,6 +469,8 @@ function createBlueBubblesClient(config = (0, config_1.getBlueBubblesConfig)(),
460
469
  }
461
470
  },
462
471
  async sendAttachment(params) {
472
+ // The caption goes through sendText; the file's name is the attachment's one line of agent text.
473
+ guardLetterChat({ what: "attachment's name", chat: params.chat, text: params.file.name });
463
474
  await assertHostAccount();
464
475
  const chatGuid = await resolveChatGuid(params.chat, config, channelConfig);
465
476
  if (!chatGuid)
@@ -485,6 +496,8 @@ function createBlueBubblesClient(config = (0, config_1.getBlueBubblesConfig)(),
485
496
  recordDelivered("apple-script");
486
497
  },
487
498
  async editMessage(params) {
499
+ // An edit names no chat, so an edit that would turn a message into a letter is refused wherever it is.
500
+ guardLetterChat({ what: "edit", chat: null, text: `${params.text}\n${params.backwardsCompatibilityMessage ?? ""}`, mark: params.mark });
488
501
  await assertHostAccount();
489
502
  const messageGuid = params.messageGuid.trim();
490
503
  const text = params.text.trim();
@@ -84,6 +84,7 @@ const proactive_content_guard_1 = require("../proactive-content-guard");
84
84
  const bluebubbles_meta_guard_1 = require("../bluebubbles-meta-guard");
85
85
  const model_1 = require("./model");
86
86
  const client_1 = require("./client");
87
+ const letter_guard_1 = require("./letter-guard");
87
88
  const chat_interaction_1 = require("../../heart/chat-interaction");
88
89
  const reactions_1 = require("./reactions");
89
90
  const send_file_1 = require("./send-file");
@@ -1239,6 +1240,10 @@ function createBlueBubblesCallbacks(client, chat, replyTarget, isGroupChat, onVi
1239
1240
  }
1240
1241
  if (!await canRunOutbound())
1241
1242
  return;
1243
+ // Checked before the speak is reserved or counted as seen, since a refused speak never leaves.
1244
+ const letterRefusal = (0, letter_guard_1.letterChatRefusal)({ what: "message", chat, text: trimmed }, identity_1.getAgentRoot);
1245
+ if (letterRefusal)
1246
+ throw new client_1.BlueBubblesSendError({ message: letterRefusal, httpStatus: null, errorCode: "letter_guard", transportInvoked: false });
1242
1247
  const replyToMessageGuid = replyTarget.getReplyToMessageGuid();
1243
1248
  const speakRecord = reserveMidTurnSpeak(trimmed, replyToMessageGuid);
1244
1249
  /* v8 ignore next 4 -- see reserveMidTurnSpeak: a fresh key is never already reserved @preserve */
@@ -2216,7 +2221,7 @@ async function handleBlueBubblesNormalizedEvent(event, resolvedDeps, source, opt
2216
2221
  chatActions: (0, tools_chat_1.chatActionsForTurn)({
2217
2222
  setReplyTarget: (selection) => replyTarget.setSelection(selection),
2218
2223
  react: (emoji, messageId) => (0, reactions_1.reactInBlueBubbles)(client, event.chat, emoji, messageId),
2219
- sendFile: (filePath, caption) => (0, send_file_1.sendFileInBlueBubbles)(client, event.chat, filePath, caption),
2224
+ sendFile: (filePath, caption) => (0, send_file_1.sendFileInBlueBubbles)(client, event.chat, filePath, caption, identity_1.getAgentRoot),
2220
2225
  }, event.messageGuid),
2221
2226
  },
2222
2227
  });
@@ -2330,6 +2335,12 @@ async function handleBlueBubblesNormalizedEvent(event, resolvedDeps, source, opt
2330
2335
  // shutdown handler already decided this turn's result.
2331
2336
  if (controller.signal.aborted && !finalTransportInvoked)
2332
2337
  throw error;
2338
+ if (error instanceof client_1.BlueBubblesSendError && error.errorCode === "letter_guard") {
2339
+ // The reply named a letter code in the person's letters chat. Nothing left, and a retry would be refused
2340
+ // the same way, so the turn ends here and the agent hears why, to say it again by the letter's subject.
2341
+ (0, letter_guard_1.tellAgentReplyRefused)(resolvedDeps.getAgentName(), (0, identity_1.getAgentRoot)(), event.messageGuid, error.message);
2342
+ return { handled: true, notifiedAgent: false, kind: event.kind, reason: "letter_guard" };
2343
+ }
2333
2344
  (0, runtime_1.emitNervesEvent)({
2334
2345
  level: "warn",
2335
2346
  component: "senses",
@@ -4280,6 +4291,10 @@ async function sendProactiveBlueBubblesMessageToSession(params, deps = {}) {
4280
4291
  }
4281
4292
  image = read;
4282
4293
  }
4294
+ // The text is checked before the image goes, so a refused caption never leaves half a message.
4295
+ const letterRefusal = (0, letter_guard_1.letterChatRefusal)({ what: "message", chat, text: params.text }, identity_1.getAgentRoot);
4296
+ if (letterRefusal)
4297
+ return { delivered: false, reason: "letter_guard", detail: letterRefusal };
4283
4298
  const sentAt = Date.now();
4284
4299
  let imageSent = false;
4285
4300
  try {
@@ -4518,6 +4533,16 @@ async function drainAndSendPendingBlueBubbles(deps = {}, pendingRoot) {
4518
4533
  });
4519
4534
  }
4520
4535
  catch (error) {
4536
+ if (error instanceof client_1.BlueBubblesSendError && error.errorCode === "letter_guard") {
4537
+ // Refused before anything left: sending it again is refused again, so it goes, and the agent hears why.
4538
+ result.skipped++;
4539
+ try {
4540
+ fs.unlinkSync(filePath);
4541
+ }
4542
+ catch { /* ignore */ }
4543
+ (0, letter_guard_1.tellAgentReplyRefused)(resolvedDeps.getAgentName(), (0, identity_1.getAgentRoot)(), path.basename(filePath), error.message);
4544
+ continue;
4545
+ }
4521
4546
  result.failed++;
4522
4547
  (0, runtime_1.emitNervesEvent)({
4523
4548
  level: "error",
@@ -0,0 +1,144 @@
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.OURO_LETTER_SEND = void 0;
37
+ exports.answeringHandleSet = answeringHandleSet;
38
+ exports.oneToOneHandle = oneToOneHandle;
39
+ exports.letterChatRefusal = letterChatRefusal;
40
+ exports.tellAgentReplyRefused = tellAgentReplyRefused;
41
+ // Only Ouro writes letters into the person's chat (design §3.4, R5-5, R6-M1, R8-M2). The chat a letter is delivered
42
+ // to, the one-to-one chat with a handle in the agent's answering.json, takes no agent text that could pass for a
43
+ // letter code or Ouro's option block once folded, so the agent can't restate a letter in its own words and steer the
44
+ // answer. Only mailbox_deliver (and later the receipts) carry the mark that lets Ouro's own text through.
45
+ const path = __importStar(require("path"));
46
+ const answering_1 = require("../../heart/letters/answering");
47
+ const letter_1 = require("../../heart/letters/letter");
48
+ const store_1 = require("../../heart/letters/store");
49
+ const pending_1 = require("../../mind/pending");
50
+ const runtime_1 = require("../../nerves/runtime");
51
+ /** The mark on a send whose text Ouro rendered itself: a letter, or a receipt for one. */
52
+ exports.OURO_LETTER_SEND = Symbol("ouro letter send");
53
+ /**
54
+ * The handles whose one-to-one chats letters go to, normalised: each person's handle in answering.json, and the
55
+ * handle frozen on every letter still open, since its answer comes from that chat even after the person's handle
56
+ * changes. Null when answering.json doesn't read, so the guard fails closed rather than off.
57
+ */
58
+ function answeringHandleSet(agentRoot) {
59
+ const lettersDir = path.join(agentRoot, "state", "letters");
60
+ const current = (0, answering_1.checkAnsweringHandles)(lettersDir);
61
+ if (current === null)
62
+ return null;
63
+ try {
64
+ const frozen = new store_1.LetterStore(lettersDir).loadOpen().flatMap((stored) => stored.letter.answeringHandle ?? []);
65
+ return new Set([...Object.values(current), ...frozen]);
66
+ }
67
+ catch {
68
+ // Letters that don't read count like an answering.json that doesn't: closed.
69
+ return null;
70
+ }
71
+ }
72
+ /** The handle in a one-to-one chat GUID (`iMessage;-;+1555…`), `group` for a group GUID (`;+;`), or null for neither. */
73
+ function guidHandle(raw) {
74
+ if (!raw)
75
+ return null;
76
+ if (raw.includes(";+;"))
77
+ return "group";
78
+ const parts = raw.split(";-;");
79
+ return parts.length === 2 ? parts[1] : null;
80
+ }
81
+ /**
82
+ * The handle of a one-to-one chat, normalised, or null for a group or a chat with no handle. Any field may carry a
83
+ * chat GUID, since the client sends to an identifier that is a GUID as it is; the GUID's own shape decides whether
84
+ * it is one-to-one, and `isGroup`, which a display name alone can set, is not read.
85
+ */
86
+ function oneToOneHandle(chat) {
87
+ const target = chat.sendTarget.kind === "chat_identifier" ? chat.sendTarget.value : undefined;
88
+ const fields = [chat.chatGuid, chat.chatIdentifier, target];
89
+ const fromGuid = fields.map(guidHandle).find((found) => found !== null);
90
+ if (fromGuid === "group")
91
+ return null;
92
+ // isGroup alone decides nothing: a display name can set it, and a group's identifier is no handle anyway.
93
+ const raw = fromGuid ?? fields.find((field) => field);
94
+ if (!raw)
95
+ return null;
96
+ const checked = (0, answering_1.normalizeAnsweringHandle)(raw);
97
+ return checked.ok ? checked.handle : null;
98
+ }
99
+ function refusal(what, handle) {
100
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.bluebubbles_letter_guard", message: "agent text that could pass for a letter was refused", meta: { what, pinned: handle !== null } });
101
+ return `This ${what} names a letter code or Ouro's option block, which only Ouro writes${handle ? ` in ${handle}'s letters chat` : " where letters go"}. Refer to the letter by its subject instead.`;
102
+ }
103
+ /**
104
+ * Why agent text bound for a letters chat is refused, when it folds to a letter code or the option block, or null to
105
+ * let it through. `chat` is null when the send doesn't say its chat (an edit), and then any letters chat counts, so
106
+ * an edit can't turn a message into a letter. When answering.json doesn't read, every one-to-one chat counts.
107
+ */
108
+ function letterChatRefusal(input, agentRoot) {
109
+ if (input.mark === exports.OURO_LETTER_SEND || !(0, letter_1.hasLetterCode)(input.text))
110
+ return null;
111
+ // The agent's root is found only for text that names a code, which is rare.
112
+ const handles = answeringHandleSet(typeof agentRoot === "string" ? agentRoot : agentRoot());
113
+ if (handles !== null && handles.size === 0)
114
+ return null;
115
+ if (input.chat === null)
116
+ return refusal(input.what, null);
117
+ const handle = oneToOneHandle(input.chat);
118
+ if (handle === null)
119
+ return null;
120
+ if (handles === null)
121
+ return refusal(input.what, null);
122
+ return handles.has(handle) ? refusal(input.what, handle) : null;
123
+ }
124
+ /**
125
+ * Tells the agent, in its private runtime, that its reply to a message was refused for naming a letter code. The
126
+ * reply never left, so the person heard nothing until the agent says it again without the code.
127
+ */
128
+ function tellAgentReplyRefused(agent, agentRoot, messageGuid, refusalText) {
129
+ try {
130
+ (0, pending_1.queuePendingMessageOnce)((0, pending_1.getPrivateRuntimePendingDir)(agent, agentRoot), {
131
+ from: agent,
132
+ friendId: "self",
133
+ channel: "inner",
134
+ key: "dialog",
135
+ content: `my iMessage reply wasn't sent, so they haven't heard back from me: ${refusalText}`,
136
+ timestamp: Date.now(),
137
+ packetId: `letter-guard:${messageGuid}`,
138
+ });
139
+ }
140
+ catch (error) {
141
+ // The refusal itself stands; only the note to the agent is lost, and the log says so.
142
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.bluebubbles_letter_guard_note_failed", message: "couldn't tell the agent its reply was refused", meta: { messageGuid, reason: error.message } });
143
+ }
144
+ }
@@ -4,16 +4,21 @@ exports.MAX_IMESSAGE_FILE_BYTES = void 0;
4
4
  exports.sendFileInBlueBubbles = sendFileInBlueBubbles;
5
5
  const runtime_1 = require("../../nerves/runtime");
6
6
  const chat_file_1 = require("../chat-file");
7
+ const letter_guard_1 = require("./letter-guard");
7
8
  /** iMessage itself carries files far larger than this; the cap keeps one upload from tying up the turn. */
8
9
  exports.MAX_IMESSAGE_FILE_BYTES = 100_000_000;
9
10
  /** The shared send_file action on iMessage: the file, then its caption as a message of its own. */
10
- async function sendFileInBlueBubbles(client, chat, filePath, caption) {
11
+ async function sendFileInBlueBubbles(client, chat, filePath, caption, agentRoot) {
11
12
  if (!client.sendAttachment)
12
13
  throw new Error("this iMessage connection can't send files.");
13
14
  const file = await (0, chat_file_1.readChatFile)(filePath, exports.MAX_IMESSAGE_FILE_BYTES);
15
+ const text = caption.trim();
16
+ // The caption is checked before the file goes, so a refused caption never leaves half a message.
17
+ const refused = text ? (0, letter_guard_1.letterChatRefusal)({ what: "caption", chat, text }, agentRoot) : null;
18
+ if (refused)
19
+ throw new Error(refused);
14
20
  await client.sendAttachment({ chat, file });
15
21
  (0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.bluebubbles_file_sent", message: "sent a file over iMessage", meta: { contentType: file.contentType } });
16
- const text = caption.trim();
17
22
  if (text)
18
23
  await client.sendText({ chat, text });
19
24
  return `sent ${file.name}`;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1631",
3
+ "version": "0.1.0-alpha.1633",
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.1631",
9
+ "version": "0.1.0-alpha.1633",
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.1631",
3
+ "version": "0.1.0-alpha.1633",
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": {