@ouro.bot/cli 0.1.0-alpha.1363 → 0.1.0-alpha.1364

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,12 @@
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.1364",
6
+ "changes": [
7
+ "The Butler can send the messages it starts itself (house notices, external events, unprompted messages) to the owner's primary agent over A2A instead of to Telegram, set by senses.telegram.ownerNoticesTo in agent.json; replies stay on Telegram, and while the peer can't be reached only urgent messages go to Telegram, marked as a fallback."
8
+ ]
9
+ },
4
10
  {
5
11
  "version": "0.1.0-alpha.1363",
6
12
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1363",
2
+ "runtimeVersion": "0.1.0-alpha.1364",
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.1363</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1364</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -224,6 +224,27 @@ function normalizeAppSessionsConfig(rawSense, configFile) {
224
224
  result.digest = normalizeDigest(rawSense.digest, fail);
225
225
  return result;
226
226
  }
227
+ function normalizeOwnerNoticesTo(value, configFile) {
228
+ const fail = (message) => {
229
+ (0, runtime_1.emitNervesEvent)({ level: "error", event: "config_identity.error", component: "config/identity", message: "agent config has an invalid Telegram owner route", meta: { path: configFile } });
230
+ throw new Error(`agent.json at ${configFile}: ${message}`);
231
+ };
232
+ if (!value || typeof value !== "object" || Array.isArray(value))
233
+ return fail("senses.telegram.ownerNoticesTo must be { cardUrl, did }.");
234
+ const { cardUrl, did } = value;
235
+ let protocol = "";
236
+ try {
237
+ protocol = typeof cardUrl === "string" ? new URL(cardUrl).protocol : "";
238
+ }
239
+ catch {
240
+ protocol = "";
241
+ }
242
+ if (protocol !== "http:" && protocol !== "https:")
243
+ return fail("senses.telegram.ownerNoticesTo.cardUrl must be an http or https URL.");
244
+ if (typeof did !== "string" || !did.startsWith("did:key:"))
245
+ return fail("senses.telegram.ownerNoticesTo.did must be a did:key.");
246
+ return { cardUrl: cardUrl, did };
247
+ }
227
248
  function normalizeSenses(value, configFile) {
228
249
  const defaults = {
229
250
  cli: { ...exports.DEFAULT_AGENT_SENSES.cli },
@@ -318,6 +339,11 @@ function normalizeSenses(value, configFile) {
318
339
  defaults[senseName] = { enabled, ...normalizeAppSessionsConfig(rawSense, configFile) };
319
340
  continue;
320
341
  }
342
+ const ownerNoticesTo = rawSense.ownerNoticesTo;
343
+ if (senseName === "telegram" && ownerNoticesTo !== undefined) {
344
+ defaults[senseName] = { enabled, ownerNoticesTo: normalizeOwnerNoticesTo(ownerNoticesTo, configFile) };
345
+ continue;
346
+ }
321
347
  defaults[senseName] = { enabled };
322
348
  }
323
349
  return defaults;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OWNER_ROUTE_FALLBACK_PREFIX = void 0;
4
+ exports.ownerRouteUrgency = ownerRouteUrgency;
5
+ exports.ownerRouteDedupeKey = ownerRouteDedupeKey;
6
+ exports.ownerRouteItem = ownerRouteItem;
7
+ exports.formatOwnerRouteMessage = formatOwnerRouteMessage;
8
+ exports.createA2AOwnerRoute = createA2AOwnerRoute;
9
+ exports.ownerRouteForAgent = ownerRouteForAgent;
10
+ const node_crypto_1 = require("node:crypto");
11
+ const client_1 = require("../a2a/client");
12
+ const identity_1 = require("../a2a/identity");
13
+ const identity_2 = require("../heart/identity");
14
+ const runtime_1 = require("../nerves/runtime");
15
+ exports.OWNER_ROUTE_FALLBACK_PREFIX = "Slugger can't be reached, so this comes to you directly.";
16
+ function ownerRouteUrgency(key, critical) {
17
+ if (critical)
18
+ return "now";
19
+ if (key.startsWith("owner-notice:house-sweep:"))
20
+ return "batch";
21
+ return "today";
22
+ }
23
+ const slug = (value) => value.toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "");
24
+ function ownerRouteDedupeKey(key, text) {
25
+ const [kind, ...rest] = key.split(":");
26
+ const tail = rest.join(":");
27
+ let condition;
28
+ if (kind === "external-event") {
29
+ // The generation counts re-fires of one event; the condition is its source and id.
30
+ let identity;
31
+ try {
32
+ identity = JSON.parse(tail);
33
+ }
34
+ catch {
35
+ identity = null;
36
+ }
37
+ condition = Array.isArray(identity) && identity.length >= 2 ? `${identity[0]}-${identity[1]}` : key;
38
+ }
39
+ else if (kind === "proactive") {
40
+ // A proactive key is a fresh UUID each time, so the same words name the same condition.
41
+ condition = `proactive-${(0, node_crypto_1.createHash)("sha256").update(text).digest("hex").slice(0, 12)}`;
42
+ }
43
+ else {
44
+ condition = kind === "owner-notice" ? tail : key;
45
+ }
46
+ return `butler-${slug(condition)}`.slice(0, 120);
47
+ }
48
+ function ownerRouteItem(key, text, critical) {
49
+ return { key, text, urgency: ownerRouteUrgency(key, critical), dedupeKey: ownerRouteDedupeKey(key, text) };
50
+ }
51
+ function formatOwnerRouteMessage(item) {
52
+ const firstLine = item.text.trim().split("\n")[0].trim();
53
+ const ask = firstLine.length > 200 ? `${firstLine.slice(0, 199)}…` : firstLine;
54
+ return [
55
+ "from: the Butler (sanctuary, Ari's house server)",
56
+ `urgency: ${item.urgency}`,
57
+ `ask: ${ask}`,
58
+ "why only Ari: it is about his house, and the Butler reports to him",
59
+ `steps: ${item.text}`,
60
+ "deadline: none",
61
+ `dedupe key: ${item.dedupeKey}`,
62
+ ].join("\n");
63
+ }
64
+ const reason = (error) => error instanceof Error ? error.message : String(error);
65
+ function createA2AOwnerRoute(options) {
66
+ const fetchCard = options.fetchCard ?? client_1.fetchA2AAgentCard;
67
+ const send = options.send ?? client_1.sendSealedA2AChat;
68
+ return async (item) => {
69
+ try {
70
+ const served = (0, client_1.cardDid)(await fetchCard(options.cardUrl));
71
+ if (served !== options.did) {
72
+ const detail = `the card at ${options.cardUrl} serves ${served}, not the pinned ${options.did}`;
73
+ (0, runtime_1.emitNervesEvent)({ level: "error", component: "senses", event: "senses.telegram_owner_route_pin_mismatch", message: "the owner route's peer card serves another DID", meta: { cardUrl: options.cardUrl, served: served ?? null, pinned: options.did } });
74
+ return { status: "unreachable", detail };
75
+ }
76
+ await send({ cardUrl: options.cardUrl, text: formatOwnerRouteMessage(item), identity: await options.loadIdentity() });
77
+ (0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.telegram_owner_route_delivered", message: "sent a self-started Butler message to the owner's primary agent", meta: { urgency: item.urgency, dedupeKey: item.dedupeKey } });
78
+ return { status: "delivered" };
79
+ }
80
+ catch (error) {
81
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.telegram_owner_route_unreachable", message: "the owner's primary agent could not be reached", meta: { urgency: item.urgency, dedupeKey: item.dedupeKey, error: reason(error) } });
82
+ return { status: "unreachable", detail: reason(error) };
83
+ }
84
+ };
85
+ }
86
+ /** The owner route `agent.json` names (`senses.telegram.ownerNoticesTo`), signing as this agent's A2A identity; none when unset. */
87
+ function ownerRouteForAgent(agentName, agentRoot) {
88
+ const peer = (0, identity_2.loadAgentConfig)({ agentName, agentRoot }).senses?.telegram.ownerNoticesTo;
89
+ (0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.telegram_owner_route_configured", message: "read the Telegram owner route", meta: { agentName, cardUrl: peer?.cardUrl ?? null } });
90
+ if (!peer)
91
+ return undefined;
92
+ return createA2AOwnerRoute({ cardUrl: peer.cardUrl, did: peer.did, loadIdentity: () => (0, identity_1.loadSelfA2AIdentity)({ agentName }) });
93
+ }
@@ -91,6 +91,7 @@ const sanctuary_grounding_1 = require("./sanctuary-grounding");
91
91
  const telegram_approval_runtime_1 = require("./telegram-approval-runtime");
92
92
  const telegram_audit_ledger_1 = require("./telegram-audit-ledger");
93
93
  const session_events_1 = require("../heart/session-events");
94
+ const telegram_owner_route_1 = require("./telegram-owner-route");
94
95
  const telegram_handoff_1 = require("./telegram-handoff");
95
96
  const router_1 = require("../heart/external-events/router");
96
97
  const session_transaction_1 = require("../mind/session-transaction");
@@ -1054,12 +1055,59 @@ function createTelegramSenseApp(options) {
1054
1055
  (0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.telegram_notice_held_for_pacing", message: "held a house notice for quiet hours or the daily message cap", meta: { agentName: options.agentName, reason: pacingReason } });
1055
1056
  return true;
1056
1057
  };
1058
+ // Keys the owner's primary agent accepted, so a retry is already sent (as with the effect journal for Telegram).
1059
+ const routedKeysPath = path.join(agentRoot, "state", "telegram", "routed-owner-notices.json");
1060
+ const fallbackText = (text) => `${telegram_owner_route_1.OWNER_ROUTE_FALLBACK_PREFIX}\n\n${text}`;
1061
+ /**
1062
+ * Offers a self-started message to the owner route. Returns null when it is handled (the peer has it, or it waits in the
1063
+ * held file for the peer), or the text Telegram should send: the message itself with no route, or, for an urgent message
1064
+ * the peer can't take, the message marked as a fallback.
1065
+ */
1066
+ const routeSelfStarted = async (text, key, critical = (0, telegram_handoff_1.isCriticalNoticeKey)(key), signal) => {
1067
+ if (!options.ownerRoute)
1068
+ return text;
1069
+ // Older held notices go first, so the peer hears them in order.
1070
+ await releaseHeldNotices(signal);
1071
+ const item = (0, telegram_owner_route_1.ownerRouteItem)(key, text, critical);
1072
+ const outcome = await options.ownerRoute(item);
1073
+ if (outcome.status === "delivered") {
1074
+ (0, telegram_handoff_1.recordReleasedHeldKeys)(routedKeysPath, [key]);
1075
+ return null;
1076
+ }
1077
+ if (item.urgency === "now") {
1078
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.telegram_owner_route_fallback", message: "the owner's primary agent can't be reached; an urgent message goes to Telegram", meta: { agentName: options.agentName, dedupeKey: item.dedupeKey, detail: outcome.detail } });
1079
+ return fallbackText(text);
1080
+ }
1081
+ const held = (0, telegram_handoff_1.readHeldNotices)(heldNoticesPath);
1082
+ if (!held.some((notice) => notice.key === key))
1083
+ (0, telegram_handoff_1.writeHeldNotices)(heldNoticesPath, [...held, { key, text }]);
1084
+ (0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.telegram_notice_held_for_owner_route", message: "held a house notice until the owner's primary agent can be reached", meta: { agentName: options.agentName, dedupeKey: item.dedupeKey } });
1085
+ return null;
1086
+ };
1087
+ /** With an owner route, held notices go to the peer one by one; a critical one it can't take goes to Telegram as a fallback. */
1088
+ const releaseHeldNoticesToRoute = async (route, signal) => {
1089
+ const sessionPath = (0, shared_turn_1.getSenseSessionPath)(options.agentName, configuredOwnerFriendId, "telegram", configuredOwnerSessionKey, agentRoot);
1090
+ for (const notice of (0, telegram_handoff_1.readHeldNotices)(heldNoticesPath)) {
1091
+ const critical = (0, telegram_handoff_1.isCriticalNoticeKey)(notice.key);
1092
+ const outcome = await route((0, telegram_owner_route_1.ownerRouteItem)(notice.key, notice.text, critical));
1093
+ if (outcome.status !== "delivered" && !critical)
1094
+ continue;
1095
+ (0, telegram_handoff_1.writeHeldNotices)(heldNoticesPath, (0, telegram_handoff_1.readHeldNotices)(heldNoticesPath).filter((entry) => entry.key !== notice.key));
1096
+ if (outcome.status === "delivered") {
1097
+ (0, telegram_handoff_1.recordReleasedHeldKeys)(routedKeysPath, [notice.key]);
1098
+ continue;
1099
+ }
1100
+ await recordAcceptedEffects(sessionPath, [await deliverButlerEffect(fallbackText(notice.text), notice.key, signal)]);
1101
+ }
1102
+ };
1057
1103
  let heldNoticeRelease = Promise.resolve();
1058
1104
  const releaseHeldNotices = async (signal) => {
1059
1105
  // Nearly always nothing is held: return without queueing, so ordinary turns and the reconcile tick pay nothing.
1060
1106
  if ((0, telegram_handoff_1.readHeldNotices)(heldNoticesPath).length === 0)
1061
1107
  return;
1062
1108
  const release = heldNoticeRelease.then(async () => {
1109
+ if (options.ownerRoute)
1110
+ return releaseHeldNoticesToRoute(options.ownerRoute, signal);
1063
1111
  const held = (0, telegram_handoff_1.readHeldNotices)(heldNoticesPath);
1064
1112
  if (ownerChatIsHandedOff())
1065
1113
  return;
@@ -1881,10 +1929,13 @@ function createTelegramSenseApp(options) {
1881
1929
  return;
1882
1930
  }
1883
1931
  const key = `proactive:${(0, node_crypto_1.randomUUID)()}`;
1884
- if (holdNoticeDuringHandoff(proactiveText, key))
1932
+ const telegramText = await routeSelfStarted(proactiveText, key, undefined, signal);
1933
+ if (telegramText === null)
1934
+ return;
1935
+ if (holdNoticeDuringHandoff(telegramText, key))
1885
1936
  return;
1886
1937
  await releaseHeldNotices(signal);
1887
- const effect = await deliverButlerEffect(proactiveText, key, signal);
1938
+ const effect = await deliverButlerEffect(telegramText, key, signal);
1888
1939
  countProactiveSend();
1889
1940
  const sessionPath = (0, shared_turn_1.getSenseSessionPath)(options.agentName, configuredOwnerFriendId, "telegram", configuredOwnerSessionKey, agentRoot);
1890
1941
  await recordAcceptedEffects(sessionPath, [effect]);
@@ -1905,8 +1956,10 @@ function createTelegramSenseApp(options) {
1905
1956
  const sessionPath = (0, shared_turn_1.getSenseSessionPath)(options.agentName, configuredOwnerFriendId, "telegram", configuredOwnerSessionKey, agentRoot);
1906
1957
  const held = (0, telegram_handoff_1.readHeldNotices)(heldNoticesPath);
1907
1958
  const releasedKeys = (0, telegram_handoff_1.readReleasedHeldKeys)(releasedHeldKeysPath);
1959
+ const routedKeys = (0, telegram_handoff_1.readReleasedHeldKeys)(routedKeysPath);
1908
1960
  const ownerMessageExists = (candidate) => held.some((notice) => notice.key === candidate)
1909
1961
  || releasedKeys.includes(candidate)
1962
+ || routedKeys.includes(candidate)
1910
1963
  || getEffectJournal().readByIdempotencyKey(candidate) !== null;
1911
1964
  if (ownerMessageExists(key)) {
1912
1965
  // A retry after the message went out (or was held): finish the original send, never send a reworded second one.
@@ -1930,10 +1983,14 @@ function createTelegramSenseApp(options) {
1930
1983
  });
1931
1984
  return { status: "covered", effectKey: coveredBy };
1932
1985
  }
1933
- if (holdNoticeDuringHandoff(text, key, [key, ...relatedKeys].some(telegram_handoff_1.isCriticalNoticeKey)))
1986
+ const critical = [key, ...relatedKeys].some(telegram_handoff_1.isCriticalNoticeKey);
1987
+ const telegramText = await routeSelfStarted(text, key, critical, input.signal);
1988
+ if (telegramText === null)
1989
+ return { status: "sent", effectKey: key };
1990
+ if (holdNoticeDuringHandoff(telegramText, key, critical))
1934
1991
  return { status: "sent", effectKey: key };
1935
1992
  await releaseHeldNotices(input.signal);
1936
- const effect = await deliverButlerEffect(text, key, input.signal);
1993
+ const effect = await deliverButlerEffect(telegramText, key, input.signal);
1937
1994
  countProactiveSend();
1938
1995
  await recordAcceptedEffects(sessionPath, [effect]);
1939
1996
  return { status: "sent", effectKey: key };
@@ -1948,10 +2005,13 @@ function createTelegramSenseApp(options) {
1948
2005
  throw new Error("Telegram owner notice id is invalid");
1949
2006
  await runWithAcceptanceAuditOwner(async () => {
1950
2007
  const text = requiredText(input.text, "owner notice");
1951
- if (holdNoticeDuringHandoff(text, `owner-notice:${noticeId}`))
2008
+ const telegramText = await routeSelfStarted(text, `owner-notice:${noticeId}`, undefined, input.signal);
2009
+ if (telegramText === null)
2010
+ return;
2011
+ if (holdNoticeDuringHandoff(telegramText, `owner-notice:${noticeId}`))
1952
2012
  return;
1953
2013
  await releaseHeldNotices(input.signal);
1954
- const effect = await deliverButlerEffect(text, `owner-notice:${noticeId}`, input.signal);
2014
+ const effect = await deliverButlerEffect(telegramText, `owner-notice:${noticeId}`, input.signal);
1955
2015
  countProactiveSend();
1956
2016
  const sessionPath = (0, shared_turn_1.getSenseSessionPath)(options.agentName, configuredOwnerFriendId, "telegram", configuredOwnerSessionKey, agentRoot);
1957
2017
  await recordAcceptedEffects(sessionPath, [effect]);
@@ -2266,6 +2326,7 @@ async function startTelegramSenseApp(agentName, waitForAuthority = false) {
2266
2326
  authorityTransport,
2267
2327
  // The owner is in Los Angeles; a container without TZ would otherwise run quiet hours on UTC.
2268
2328
  proactivePacing: { timeZone: process.env.TZ || "America/Los_Angeles" },
2329
+ ...(() => { const ownerRoute = (0, telegram_owner_route_1.ownerRouteForAgent)(agentName, (0, identity_1.getAgentRoot)(agentName)); return ownerRoute ? { ownerRoute } : {}; })(),
2269
2330
  ...(await createProductionTelegramRelationshipComposition(agentName, credentials, undefined, authorityTransport)),
2270
2331
  ...(agentName === "sanctuary" ? { privilegedFailsafe: {
2271
2332
  eventRoot: (0, router_1.getExternalEventRoot)(),
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1363",
3
+ "version": "0.1.0-alpha.1364",
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.1363",
9
+ "version": "0.1.0-alpha.1364",
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.1363",
3
+ "version": "0.1.0-alpha.1364",
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": {