@ouro.bot/cli 0.1.0-alpha.1622 → 0.1.0-alpha.1624

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,15 +1,30 @@
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.1624",
6
+ "changes": [
7
+ "Update the Ouro UI files to Ouro UI v1.3.587.",
8
+ "New `ouro mailbox handle set <person> <handle>`: the owner names the phone number (with its country code) or email address whose iMessages answer a person's letters. It is a CLI command only; no MCP or in-turn tool can set it. Each letter keeps the handle that was set when it was filed.",
9
+ "Letters now have a plain-text chat form: code, sender and subject, the reason only you can answer, links by label, the \"Options (from Ouro):\" block, and the exact replies that answer it, such as `Reply \"L7 1\" or \"L7 2\".` A line anchor such as `#L12` is dropped from a link so it can't be mistaken for a letter code. Nothing sends it yet.",
10
+ "`ouro mailbox handle set` only accepts the person letters actually go to (the family record naming this machine's owner), and refuses with `not-recipient` otherwise. It won't overwrite a damaged answering file (`answering-unreadable`), so nobody else's handle is lost.",
11
+ "A letter's body, its \"why only you\" line or a link label can no longer start with a number such as \"1 \" or \"2.\", so sender text can't pass for one of Ouro's option lines."
12
+ ]
13
+ },
4
14
  {
5
15
  "version": "0.1.0-alpha.1622",
6
16
  "changes": [
7
- "The Ouro AX census the harness runs in CI is now Ouro UI v1.3.585's, up from v1.3.465, and it is listed in `upstream-sources.lock.json`, so Ouro Current's update pull requests move it with every Ouro UI release instead of it waiting for a hand copy. The newer census also checks that a passthrough tool's call arguments come from its declared third-party source.",
8
17
  "iMessage: the BlueBubbles webhook now listens only on 127.0.0.1, the address Ouro registers it at, and refuses a post without the server's password (before, a post with no password at all got through). Each refused post is logged as `senses.bluebubbles_webhook_unauthorized`.",
9
18
  "Turns asked for over the daemon socket (MCP `send_message`, `agent.ask`, `agent.senseTurn`) and over the frontend socket are now marked as socket turns. `friend_link_code` refuses them with code `socket-turn`, since a socket caller picks its own friend and channel and so can't prove the family member is there.",
10
19
  "The file and shell tools now refuse writes under `state/letters/`, the mailbox's letters. Paths are normalised before the check, so `state//letters/` and quoted paths are caught. The shell check now looks at every redirect and `tee` target in a command, `>>`, `>|`, `&>` and chained commands included, not just the first."
11
20
  ]
12
21
  },
22
+ {
23
+ "version": "0.1.0-alpha.1621",
24
+ "changes": [
25
+ "The Ouro AX census the harness runs in CI is now Ouro UI v1.3.585's, up from v1.3.465, and it is listed in `upstream-sources.lock.json`, so Ouro Current's update pull requests move it with every Ouro UI release instead of it waiting for a hand copy. The newer census also checks that a passthrough tool's call arguments come from its declared third-party source."
26
+ ]
27
+ },
13
28
  {
14
29
  "version": "0.1.0-alpha.1620",
15
30
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1622",
2
+ "runtimeVersion": "0.1.0-alpha.1624",
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.1622</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1624</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAILBOX_HANDLE_COMMANDS = void 0;
4
+ const cards_1 = require("./cards");
5
+ exports.MAILBOX_HANDLE_COMMANDS = [
6
+ {
7
+ name: "mailbox handle", effect: "private", readOnly: true, summary: "The command for the handles that answer letters.",
8
+ ax: {
9
+ id: "cli:mailbox handle", group: "mailbox", effect: "read",
10
+ when: "Names the one handle command, set, which says whose iMessages answer a person's letters.",
11
+ errors: [(0, cards_1.needsSubcommand)("mailbox handle", "set"), (0, cards_1.unknownFlag)("mailbox handle")],
12
+ },
13
+ },
14
+ {
15
+ name: "mailbox handle set", effect: "private", summary: "Set the iMessage handle whose messages answer a person's letters.",
16
+ example: "mailbox handle set friend-ari +15551234567 --agent slugger",
17
+ ax: {
18
+ id: "cli:mailbox handle set", group: "mailbox", effect: "write", idempotent: true,
19
+ when: "Before letters can reach a person in chat: names the phone number or email address they answer from; letters filed afterwards use it.",
20
+ errors: [
21
+ (0, cards_1.usageError)("mailbox handle set", "needs the person (a friend id or name) and the handle.", "Run it as ouro mailbox handle set <person> <handle>, the handle a phone number with its country code or an email address."),
22
+ { code: "bad-handle", means: "The handle isn't an email address or a phone number with its country code.", fix: "Write the number with its country code, such as +15551234567, or give the email address the person uses for iMessage." },
23
+ { code: "no-person", means: "No friend of this agent has that id or name.", fix: "Find the person's friend id with ouro friend list, then pass it." },
24
+ { code: "which-person", means: "Several friends have that name.", fix: "Pass the person's friend id instead, from ouro friend list." },
25
+ { code: "not-recipient", means: "That friend isn't who letters go to: the family record naming this machine's owner.", fix: "Pass that record's id, which the refusal names, or link the person's record to this machine's owner first." },
26
+ { code: "answering-unreadable", means: "The answering handles file doesn't read, so it wasn't replaced and no handle was lost.", fix: "Move the file the refusal names aside, then set each person's handle again." },
27
+ (0, cards_1.unknownFlag)("mailbox handle set"),
28
+ ...(0, cards_1.agentErrors)("mailbox handle set"),
29
+ ],
30
+ },
31
+ },
32
+ ];
@@ -42,7 +42,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
42
42
  return (mod && mod.__esModule) ? mod : { "default": mod };
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.pingGithubCopilotModel = exports.MAILBOX_CLI_REFUSAL_CODES = void 0;
45
+ exports.pingGithubCopilotModel = exports.MAILBOX_CLI_REFUSAL_CODES = exports.HANDLE_SET_REFUSAL_CODES = void 0;
46
46
  exports.runMcpServeCliLifecycle = runMcpServeCliLifecycle;
47
47
  exports.summarizeDaemonStartupFailure = summarizeDaemonStartupFailure;
48
48
  exports.writeSyncProbeSummary = writeSyncProbeSummary;
@@ -113,8 +113,11 @@ const cli_parse_1 = require("./cli-parse");
113
113
  const cli_parse_2 = require("./cli-parse");
114
114
  const cli_help_1 = require("./cli-help");
115
115
  const cli_manifest_1 = require("./cli-manifest");
116
+ const answering_1 = require("../letters/answering");
116
117
  const doors_1 = require("../letters/doors");
117
118
  /** The codes the mailbox commands fail with: the doors' own checks and the daemon's letters writer. */
119
+ /** The codes `ouro mailbox handle set` refuses with, from src/heart/letters/answering.ts. */
120
+ exports.HANDLE_SET_REFUSAL_CODES = new Set(["bad-handle", "no-person", "which-person", "not-recipient", "answering-unreadable"]);
118
121
  exports.MAILBOX_CLI_REFUSAL_CODES = new Set([
119
122
  "daemon-down", "bad-input", "no-agent", "not-found",
120
123
  "invalid-letter", "no-person", "not-sender", "not-waiting", "no-answering-handle",
@@ -573,6 +576,7 @@ function agentResolutionFailureMode(command) {
573
576
  case "a2a.escalation":
574
577
  case "a2a.delegatedCommands":
575
578
  case "mailbox.action":
579
+ case "mailbox.handle.set":
576
580
  return "throw";
577
581
  case "provider.use":
578
582
  case "provider.check":
@@ -8974,6 +8978,23 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
8974
8978
  deps.writeStdout(message);
8975
8979
  return message;
8976
8980
  }
8981
+ // ── mailbox handle set (local: the owner names whose messages answer a person's letters) ──
8982
+ if (command.kind === "mailbox.handle.set") {
8983
+ const bundlesRoot = deps.bundlesRoot ?? /* v8 ignore next -- production default @preserve */ (0, identity_1.getAgentBundlesRoot)();
8984
+ let message;
8985
+ try {
8986
+ message = await (0, answering_1.setAnsweringHandle)(path.join(bundlesRoot, `${command.agent}.ouro`), command.person, command.handle);
8987
+ }
8988
+ catch (error) {
8989
+ // A refusal the card names keeps its code; anything else is a failure, not a refusal.
8990
+ const code = error.code;
8991
+ if (typeof code === "string" && exports.HANDLE_SET_REFUSAL_CODES.has(code))
8992
+ throw error;
8993
+ throw new Error(error.message);
8994
+ }
8995
+ deps.writeStdout(message);
8996
+ return message;
8997
+ }
8977
8998
  // ── changelog (local, no daemon socket needed) ──
8978
8999
  if (command.kind === "changelog") {
8979
9000
  try {
@@ -22,6 +22,7 @@ const shepherd_1 = require("./cli-commands/shepherd");
22
22
  const rsvp_1 = require("./cli-commands/rsvp");
23
23
  const dns_1 = require("./cli-commands/dns");
24
24
  const entry_points_1 = require("./cli-commands/entry-points");
25
+ const mailbox_handle_1 = require("./cli-commands/mailbox-handle");
25
26
  const doors_1 = require("../letters/doors");
26
27
  /** The CLI-level card: what words no command has answer. */
27
28
  exports.serverErrors = [
@@ -44,6 +45,8 @@ exports.CLI_COMMANDS = [
44
45
  ...dns_1.DNS_COMMANDS,
45
46
  // Generated by ouro-actions from actions/mailbox.actions.mts, not declared by hand.
46
47
  ...(0, doors_1.mailboxCliDeclarations)(),
48
+ // Declared by hand outside that group, so it has no MCP or tool door.
49
+ ...mailbox_handle_1.MAILBOX_HANDLE_COMMANDS,
47
50
  ];
48
51
  /**
49
52
  * Programs an agent's shell can start as `node <path>` beside the ouro command, such as the daemon and the senses.
@@ -468,6 +468,7 @@ function usage() {
468
468
  " ouro shepherd maintenance --agent <name> --expected-revision <n> --request-id <id> --destination <path> [--json]",
469
469
  " ouro session list [--agent <name>]",
470
470
  ...(0, doors_1.mailboxUsageLines)().map((line) => ` ${line}`),
471
+ " ouro mailbox handle set <person> <handle> [--agent <name>]",
471
472
  " ouro mcp list",
472
473
  " ouro mcp call <server> <tool> [--args '{...}']",
473
474
  " ouro mcp doctor --agent <name> [--json]",
@@ -694,11 +695,20 @@ const MAILBOX_USAGE_WORDS = Object.keys(exports.MAILBOX_CLI_WORDS).join("|");
694
695
  function parseMailboxCommand(args) {
695
696
  const { agent, rest } = extractAgentFlag(args);
696
697
  const sub = rest[0];
698
+ // `handle set` is declared by hand outside the generated group (cli-commands/mailbox-handle.ts).
699
+ if (sub === "handle") {
700
+ const flag = rest.find((word) => word.startsWith("--"));
701
+ if (flag)
702
+ throw Object.assign(new Error(`ouro mailbox handle set takes no ${flag}; it takes only --agent.`), { code: "unknown-flag" });
703
+ if (rest[1] !== "set" || rest.length !== 4)
704
+ throw new Error("Usage: ouro mailbox handle set <person> <handle> [--agent <agent>]");
705
+ return { kind: "mailbox.handle.set", person: rest[2], handle: rest[3], ...(agent ? { agent } : {}) };
706
+ }
697
707
  const personOnly = sub === undefined ? undefined : (0, doors_1.readMailboxDoors)().refusals[`mailbox_${sub}`];
698
708
  if (personOnly)
699
709
  throw Object.assign(new Error(personOnly.summary), { code: "person-only" });
700
710
  if (sub === undefined || !Object.hasOwn(exports.MAILBOX_CLI_WORDS, sub)) {
701
- throw new Error(`Usage: ouro mailbox ${MAILBOX_USAGE_WORDS} [--json]`);
711
+ throw new Error(`Usage: ouro mailbox ${MAILBOX_USAGE_WORDS}|handle set [--json]`);
702
712
  }
703
713
  const parsed = (0, doors_1.parseMailboxCli)(sub, rest.slice(1));
704
714
  return {
@@ -0,0 +1,177 @@
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.ANSWERING_FILE = void 0;
37
+ exports.ownerFriendIds = ownerFriendIds;
38
+ exports.normalizeAnsweringHandle = normalizeAnsweringHandle;
39
+ exports.readAnsweringHandles = readAnsweringHandles;
40
+ exports.writeAnsweringHandle = writeAnsweringHandle;
41
+ exports.setAnsweringHandle = setAnsweringHandle;
42
+ // Who letters go to, and the handles they answer from (design §3.4). A letter goes to the one family record naming
43
+ // this machine's owner. Its answering handle is the one iMessage handle whose messages may answer it, set only by the
44
+ // owner with the CLI-only `ouro mailbox handle set`; the file tools refuse this folder. The friend record's own
45
+ // identities are never used to decide who may answer, since several paths write them. Filing freezes the person's
46
+ // handle into the letter, so changing it later leaves letters already filed alone.
47
+ const fs = __importStar(require("fs"));
48
+ const path = __importStar(require("path"));
49
+ const crypto_1 = require("crypto");
50
+ const friends_1 = require("@ouro.bot/friends");
51
+ const runtime_1 = require("../../nerves/runtime");
52
+ exports.ANSWERING_FILE = "answering.json";
53
+ const listBundleFriends = (root) => new friends_1.FileFriendStore(path.join(root, "friends")).listAll();
54
+ /** The family records in a bundle's friends folder that name this machine's owner, the rule `ouro friend link-code` uses. */
55
+ async function ownerFriendIds(bundleRoot, owner, list = listBundleFriends) {
56
+ const friends = await list(bundleRoot);
57
+ return friends
58
+ .filter((record) => record.trustLevel === "family" && record.externalIds.some((id) => (0, friends_1.isLocalMachineOwnerIdentity)(id.provider, id.externalId, owner)))
59
+ .map((record) => record.id);
60
+ }
61
+ /**
62
+ * A handle the way both sides compare it: an email address in lowercase, or a phone number in E.164 (`+` and
63
+ * digits only). A number without its country code is refused rather than guessed. The answer reader compares a
64
+ * sender, and the handle in a chat GUID, through this same function.
65
+ */
66
+ function normalizeAnsweringHandle(raw) {
67
+ const trimmed = raw.trim();
68
+ if (trimmed.includes("@")) {
69
+ const email = trimmed.toLowerCase();
70
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)
71
+ ? { ok: true, handle: email }
72
+ : { ok: false, problem: `"${trimmed}" isn't an email address or a phone number.` };
73
+ }
74
+ const compact = trimmed.replace(/[\s().-]/g, "");
75
+ if (/^\+[1-9]\d{6,14}$/.test(compact))
76
+ return { ok: true, handle: compact };
77
+ if (/^\d{7,15}$/.test(compact))
78
+ return { ok: false, problem: `"${trimmed}" has no country code. Write it with one, such as +15551234567.` };
79
+ return { ok: false, problem: `"${trimmed}" isn't an email address or a phone number.` };
80
+ }
81
+ /** The file as stored: missing means nobody has a handle yet; anything else that doesn't read is a problem. */
82
+ function readFile(lettersDir) {
83
+ let raw;
84
+ try {
85
+ raw = fs.readFileSync(path.join(lettersDir, exports.ANSWERING_FILE), "utf8");
86
+ }
87
+ catch (error) {
88
+ if (error.code === "ENOENT")
89
+ return { ok: true, handles: {} };
90
+ return { ok: false, problem: error.message };
91
+ }
92
+ let parsed;
93
+ try {
94
+ parsed = JSON.parse(raw);
95
+ }
96
+ catch (error) {
97
+ return { ok: false, problem: error.message };
98
+ }
99
+ const handles = parsed?.handles;
100
+ if (!handles || typeof handles !== "object" || Array.isArray(handles))
101
+ return { ok: false, problem: "it has no handles object" };
102
+ return { ok: true, handles: handles };
103
+ }
104
+ /** Each person's answering handle, by friend id. Filing reads it; a file that doesn't read gives nobody a handle. */
105
+ function readAnsweringHandles(lettersDir) {
106
+ const file = readFile(lettersDir);
107
+ if (!file.ok) {
108
+ (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 {};
110
+ }
111
+ const result = {};
112
+ for (const [friendId, handle] of Object.entries(file.handles)) {
113
+ if (typeof handle !== "string")
114
+ continue;
115
+ const checked = normalizeAnsweringHandle(handle);
116
+ if (checked.ok)
117
+ result[friendId] = checked.handle;
118
+ }
119
+ return result;
120
+ }
121
+ function refusal(code, message) {
122
+ return Object.assign(new Error(message), { code });
123
+ }
124
+ /**
125
+ * Sets one person's handle and keeps every other entry as stored. A file that doesn't read is refused rather than
126
+ * replaced, so a torn file never silently drops other people's handles. The new file is written under a name of its
127
+ * own, synced, renamed into place, and the folder synced.
128
+ */
129
+ function writeAnsweringHandle(lettersDir, friendId, handle) {
130
+ fs.mkdirSync(lettersDir, { recursive: true });
131
+ const file = readFile(lettersDir);
132
+ if (!file.ok)
133
+ throw refusal("answering-unreadable", `${path.join(lettersDir, exports.ANSWERING_FILE)} doesn't read (${file.problem}), so it wasn't replaced. Fix: move it aside, then set each person's handle again.`);
134
+ const tmp = path.join(lettersDir, `${exports.ANSWERING_FILE}.${process.pid}.${(0, crypto_1.randomBytes)(4).toString("hex")}.tmp`);
135
+ const fd = fs.openSync(tmp, "wx", 0o600);
136
+ try {
137
+ fs.writeSync(fd, `${JSON.stringify({ v: 1, handles: { ...file.handles, [friendId]: handle } }, null, 2)}\n`);
138
+ fs.fsyncSync(fd);
139
+ }
140
+ finally {
141
+ fs.closeSync(fd);
142
+ }
143
+ fs.renameSync(tmp, path.join(lettersDir, exports.ANSWERING_FILE));
144
+ const dir = fs.openSync(lettersDir, "r");
145
+ try {
146
+ fs.fsyncSync(dir);
147
+ }
148
+ finally {
149
+ fs.closeSync(dir);
150
+ }
151
+ (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.answering_handle_set", message: "a person's answering handle was set", meta: { friendId } });
152
+ }
153
+ /**
154
+ * `ouro mailbox handle set <person> <handle>`: finds the person among the agent's friends by id, or else by name
155
+ * (ignoring case), and sets their handle. Only a person letters go to can have one. Throws with the card's code when
156
+ * the handle or the person doesn't check out.
157
+ */
158
+ async function setAnsweringHandle(bundleRoot, person, rawHandle, deps = {}) {
159
+ const checked = normalizeAnsweringHandle(rawHandle);
160
+ if (!checked.ok)
161
+ throw refusal("bad-handle", checked.problem);
162
+ const list = deps.list ?? listBundleFriends;
163
+ const friends = await list(bundleRoot);
164
+ const byId = friends.find((record) => record.id === person);
165
+ const byName = friends.filter((record) => record.name.toLowerCase() === person.toLowerCase());
166
+ if (!byId && byName.length > 1)
167
+ throw refusal("which-person", `${byName.length} friends are named ${person}: ${byName.map((record) => record.id).join(", ")}. Pass one of those ids.`);
168
+ const friend = byId ?? byName[0];
169
+ if (!friend)
170
+ throw refusal("no-person", `No friend is ${person}. Find the person's id with ouro friend list.`);
171
+ const recipients = await ownerFriendIds(bundleRoot, (deps.owner ?? friends_1.machineOwnerUsername)(), async () => friends);
172
+ if (!recipients.includes(friend.id)) {
173
+ throw refusal("not-recipient", `${friend.name} (${friend.id}) isn't who letters go to: that is the family record naming this machine's owner${recipients.length === 1 ? `, ${recipients[0]}` : ""}.`);
174
+ }
175
+ writeAnsweringHandle(path.join(bundleRoot, "state", "letters"), friend.id, checked.handle);
176
+ return `${friend.name} (${friend.id}) answers letters from ${checked.handle}. Letters filed from now on go to that chat; letters already filed keep the handle they were filed with.`;
177
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_OPTIONS = exports.LETTER_LIMITS = exports.LETTER_KINDS = void 0;
3
+ exports.LINE_ANCHOR = exports.DEFAULT_OPTIONS = exports.LETTER_LIMITS = exports.LETTER_KINDS = void 0;
4
4
  exports.fold = fold;
5
5
  exports.storedText = storedText;
6
6
  exports.hasLetterCode = hasLetterCode;
@@ -99,6 +99,16 @@ function text(name, input, limit, required) {
99
99
  refuse(`${name} contains a letter code or Ouro's answer form, which only Ouro writes. Fix: say it without a code such as L8.`);
100
100
  return storedText(value);
101
101
  }
102
+ /**
103
+ * Sender text that gets a chat line of its own (whyOnlyYou, body, a link's label): it may not open the way one of
104
+ * Ouro's option lines does, a small number and then a space, so "1 Merge — ships it" can't sit above the real block.
105
+ */
106
+ function ownLine(name, input, limit, required) {
107
+ const value = text(name, input, limit, required);
108
+ if (value !== undefined && /^\p{Nd}{1,2}[\s.)]/u.test(fold(value).trim()))
109
+ refuse(`${name} starts with a number, which would read as one of Ouro's options. Fix: start it with a word.`);
110
+ return value;
111
+ }
102
112
  function options(kind, value) {
103
113
  if (kind !== "decide") {
104
114
  if (value !== undefined)
@@ -126,14 +136,14 @@ function options(kind, value) {
126
136
  return { id: String(index + 1), label, effect };
127
137
  });
128
138
  }
129
- // A line anchor such as GitHub's #L207 or #L207-L213, which would otherwise read as a letter code.
130
- const LINE_ANCHOR = /#L\d+(?:C\d+)?(?:-L\d+(?:C\d+)?)?$/;
139
+ /** A line anchor such as GitHub's #L207 or #L207-L213, which would otherwise read as a letter code: the one place a code may sit in a url. */
140
+ exports.LINE_ANCHOR = /#L\d+(?:C\d+)?(?:-L\d+(?:C\d+)?)?$/;
131
141
  /** A link's address: checked like other sender text, except that a line anchor at its end is allowed. */
132
142
  function url(at, value) {
133
143
  const address = plain(`${at}'s url`, value, exports.LETTER_LIMITS.url, true);
134
144
  if (!/^https?:\/\//.test(address))
135
145
  refuse(`${at}'s url must start with https:// or http://.`);
136
- if (hasLetterCode(address.replace(LINE_ANCHOR, "")))
146
+ if (hasLetterCode(address.replace(exports.LINE_ANCHOR, "")))
137
147
  refuse(`${at}'s url contains a letter code, which only Ouro writes. Fix: link to a page whose address has no code such as L8.`);
138
148
  return storedText(address);
139
149
  }
@@ -148,7 +158,7 @@ function links(value) {
148
158
  const at = `link ${index + 1}`;
149
159
  if (!isObject(entry))
150
160
  refuse(`${at} must be { label, url }.`);
151
- const label = text(`${at}'s label`, entry.label, exports.LETTER_LIMITS.linkLabel, true);
161
+ const label = ownLine(`${at}'s label`, entry.label, exports.LETTER_LIMITS.linkLabel, true);
152
162
  return { label, url: url(at, entry.url) };
153
163
  });
154
164
  }
@@ -168,10 +178,10 @@ function draft(input) {
168
178
  if (!exports.LETTER_KINDS.includes(kind))
169
179
  refuse(`kind must be one of ${exports.LETTER_KINDS.join(", ")}.`);
170
180
  const subject = text("subject", input.subject, exports.LETTER_LIMITS.subject, true);
171
- const whyOnlyYou = text("whyOnlyYou", input.whyOnlyYou, exports.LETTER_LIMITS.whyOnlyYou, false);
181
+ const whyOnlyYou = ownLine("whyOnlyYou", input.whyOnlyYou, exports.LETTER_LIMITS.whyOnlyYou, false);
172
182
  if (!whyOnlyYou && kind !== "know")
173
183
  refuse(`whyOnlyYou is required for a ${kind} letter. Fix: say in one line why only the person can answer.`);
174
- const body = text("body", input.body, exports.LETTER_LIMITS.body, false) ?? "";
184
+ const body = ownLine("body", input.body, exports.LETTER_LIMITS.body, false) ?? "";
175
185
  const letterOptions = options(kind, input.options);
176
186
  const letterLinks = links(input.links);
177
187
  const urgency = (input.urgency ?? "whenever");
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPTIONS_LINE = void 0;
4
+ exports.renderLetter = renderLetter;
5
+ // How a letter reads in chat (design §3.4): plain text the harness writes, never the agent. The sender's fields
6
+ // were checked and collapsed to one line each when the letter was filed, so nothing here can fake the option block.
7
+ const runtime_1 = require("../../nerves/runtime");
8
+ const letter_1 = require("./letter");
9
+ /** The fixed line above the harness's own option block; sender text containing it is refused at filing. */
10
+ exports.OPTIONS_LINE = "Options (from Ouro):";
11
+ /** A heads-up tells; every other kind asks. */
12
+ const VERB = { decide: "asks", do: "asks", accept: "asks", know: "says" };
13
+ function agentName(agent) {
14
+ return agent.charAt(0).toUpperCase() + agent.slice(1);
15
+ }
16
+ /** The answers a person can send, in the form the reader accepts: `"L7 1"`, `"L7 1" or "L7 2"`, and so on. */
17
+ function replyLine(letter) {
18
+ const answers = letter.options.map((option) => `"${letter.code} ${option.id}"`);
19
+ const spoken = answers.length === 1 ? answers[0] : `${answers.slice(0, -1).join(", ")} or ${answers.at(-1)}`;
20
+ return `Reply ${spoken}.`;
21
+ }
22
+ /**
23
+ * The letter as the person reads it. A link shows its label and address; a line anchor is dropped from the
24
+ * address, so the chat never shows a code-shaped `#L12` beside the letter's own code.
25
+ */
26
+ function renderLetter(letter) {
27
+ const lines = [`${letter.code} · ${agentName(letter.from.agent)} ${VERB[letter.kind]}: ${letter.subject}`];
28
+ if (letter.whyOnlyYou)
29
+ lines.push(letter.whyOnlyYou);
30
+ if (letter.body)
31
+ lines.push(letter.body);
32
+ for (const link of letter.links)
33
+ lines.push(`${link.label}: ${link.url.replace(letter_1.LINE_ANCHOR, "")}`);
34
+ lines.push(exports.OPTIONS_LINE);
35
+ for (const option of letter.options)
36
+ lines.push(`${option.id} ${option.label} — ${option.effect}`);
37
+ lines.push(replyLine(letter));
38
+ const text = lines.join("\n");
39
+ (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.rendered", message: "a letter was rendered for chat", meta: { code: letter.code, lines: lines.length } });
40
+ return text;
41
+ }
@@ -33,8 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.LettersWriter = exports.ROLL_AFTER_MS = exports.LetterRefusal = void 0;
37
- exports.ownerFriendIds = ownerFriendIds;
36
+ exports.LettersWriter = exports.ROLL_AFTER_MS = exports.LetterRefusal = exports.ownerFriendIds = void 0;
38
37
  exports.answerLettersCommand = answerLettersCommand;
39
38
  // The letters' single writer (design §3.2): the daemon holds one of these, and every door (CLI, MCP, in-turn tools)
40
39
  // reaches it over the daemon's socket with a `letters.action` command. Each agent's letters live in its own bundle,
@@ -44,6 +43,8 @@ const path = __importStar(require("path"));
44
43
  const friends_1 = require("@ouro.bot/friends");
45
44
  const runtime_1 = require("../../nerves/runtime");
46
45
  const letter_1 = require("./letter");
46
+ const answering_1 = require("./answering");
47
+ Object.defineProperty(exports, "ownerFriendIds", { enumerable: true, get: function () { return answering_1.ownerFriendIds; } });
47
48
  const letter_index_1 = require("./letter-index");
48
49
  const store_1 = require("./store");
49
50
  /** A refusal the door answers with its card's code. */
@@ -61,13 +62,6 @@ exports.ROLL_AFTER_MS = 90 * 24 * 60 * 60 * 1000;
61
62
  const AGENT_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
62
63
  const WAIT_DEFAULT_S = 60;
63
64
  const WAIT_MAX_S = 300;
64
- /** The family records in a bundle's friends folder that name this machine's owner, the rule `ouro friend link-code` uses. */
65
- async function ownerFriendIds(bundleRoot, owner, list) {
66
- const friends = await (list ?? ((root) => new friends_1.FileFriendStore(path.join(root, "friends")).listAll()))(bundleRoot);
67
- return friends
68
- .filter((record) => record.trustLevel === "family" && record.externalIds.some((id) => (0, friends_1.isLocalMachineOwnerIdentity)(id.provider, id.externalId, owner)))
69
- .map((record) => record.id);
70
- }
71
65
  function ageOf(createdAt, now) {
72
66
  const minutes = Math.max(0, Math.floor((now - Date.parse(createdAt)) / 60000));
73
67
  if (minutes < 60)
@@ -183,7 +177,7 @@ class LettersWriter {
183
177
  }
184
178
  async person(agent) {
185
179
  const bundle = path.join(this.deps.bundlesRoot, `${agent}.ouro`);
186
- const ids = await ownerFriendIds(bundle, (this.deps.ownerUsername ?? friends_1.machineOwnerUsername)(), this.deps.listFriends);
180
+ const ids = await (0, answering_1.ownerFriendIds)(bundle, (this.deps.ownerUsername ?? friends_1.machineOwnerUsername)(), this.deps.listFriends);
187
181
  if (ids.length === 1)
188
182
  return ids[0];
189
183
  throw new LetterRefusal("no-person", ids.length === 0
@@ -216,7 +210,11 @@ class LettersWriter {
216
210
  // The counter moves first, so a crash after it can skip a code but never reuse one.
217
211
  letters.store.writeNextCode(number + 1);
218
212
  letters.index.reserve(number + 1);
219
- const letter = { v: 1, id: (this.deps.newId ?? letter_1.newLetterId)(now.getTime()), code: `L${number}`, to, from, ...draft, createdAt: now.toISOString() };
213
+ // The person's answering handle is frozen into the letter now, so a later change leaves this letter alone.
214
+ const answeringHandle = (0, answering_1.readAnsweringHandles)(letters.store.dir)[to];
215
+ const letter = {
216
+ v: 1, id: (this.deps.newId ?? letter_1.newLetterId)(now.getTime()), code: `L${number}`, ...(answeringHandle ? { answeringHandle } : {}), to, from, ...draft, createdAt: now.toISOString(),
217
+ };
220
218
  try {
221
219
  letters.store.create(letter);
222
220
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1622",
3
+ "version": "0.1.0-alpha.1624",
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.1622",
9
+ "version": "0.1.0-alpha.1624",
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.1622",
3
+ "version": "0.1.0-alpha.1624",
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": {