@ouro.bot/cli 0.1.0-alpha.1410 → 0.1.0-alpha.1412

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "_note": "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.1412",
6
+ "changes": [
7
+ "An await with a wake_at now waits for that time: it isn't checked before then, and it's checked once, right away, when the time comes. Until now only its cadence decided when it was checked."
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1411",
12
+ "changes": [
13
+ "The Butler's A2A server passes Ari's relayed approval answers to the Telegram sense, unopened and without starting a model turn, and only from the owner route's peer."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1410",
6
18
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1410",
2
+ "runtimeVersion": "0.1.0-alpha.1412",
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.1410</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1412</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,113 @@
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.MAX_RELAY_REPLY_BYTES = exports.RELAY_FORWARD_TIMEOUT_MS = exports.RELAY_REFUSED = exports.RELAY_TIMED_OUT = exports.RELAY_UNAVAILABLE = exports.RELAY_REPLY = void 0;
37
+ exports.approvalRelaySocketPath = approvalRelaySocketPath;
38
+ exports.forwardApprovalAnswer = forwardApprovalAnswer;
39
+ /**
40
+ * The A2A process's half of the approval relay. A verified sealed message that carries friends' signed `approvalAnswer`
41
+ * never becomes a model turn. Once the A2A server has verified it, the raw sealed message goes to the Telegram sense
42
+ * process over `state/approvals/relay/sock`, and that process opens it again, checks it and decides it beside the taps
43
+ * (security review H3, L4). This file is that one-line client.
44
+ */
45
+ const net = __importStar(require("node:net"));
46
+ const path = __importStar(require("node:path"));
47
+ const runtime_1 = require("../nerves/runtime");
48
+ /** Where the Telegram sense listens for relayed answers: alone in a folder only this agent's user can enter. */
49
+ function approvalRelaySocketPath(agentRoot) {
50
+ return path.join(agentRoot, "state", "approvals", "relay", "sock");
51
+ }
52
+ /** What the sender hears back. The Telegram process answers one of these; anything else reads as unavailable. */
53
+ exports.RELAY_REPLY = /^(denied|already_decided|expired|not_pending|refused:[a-z0-9_]{1,64})$/;
54
+ exports.RELAY_UNAVAILABLE = "refused:relay_unavailable";
55
+ /**
56
+ * The Telegram process took the answer but didn't reply in time, usually because a tap holds the approval's lock. The
57
+ * deny may still land, so this is not a refusal: the sender should tell Ari to check the card.
58
+ */
59
+ exports.RELAY_TIMED_OUT = "timed_out";
60
+ /** The one reply for a sender that isn't the owner route's peer, so nobody else learns how the relay is set up. */
61
+ exports.RELAY_REFUSED = "refused";
62
+ /** Deciding waits for the approval's lock, so give it time, but never hang a request. */
63
+ exports.RELAY_FORWARD_TIMEOUT_MS = 30_000;
64
+ /** A reply line is a few dozen bytes; anything longer than this isn't one. */
65
+ exports.MAX_RELAY_REPLY_BYTES = 1024;
66
+ async function forwardApprovalAnswer(input) {
67
+ const reply = await new Promise((resolve) => {
68
+ let data = "";
69
+ let sent = false;
70
+ let settled = false;
71
+ const finish = (value) => {
72
+ if (settled)
73
+ return;
74
+ settled = true;
75
+ socket.destroy();
76
+ resolve(value);
77
+ };
78
+ const socket = net.createConnection(input.socketPath);
79
+ socket.setEncoding("utf8");
80
+ /* v8 ignore next -- a local socket connects or fails at once, so a timeout before connect is a guard only @preserve */
81
+ socket.setTimeout(input.timeoutMs ?? exports.RELAY_FORWARD_TIMEOUT_MS, () => finish(sent ? exports.RELAY_TIMED_OUT : exports.RELAY_UNAVAILABLE));
82
+ socket.on("connect", () => { sent = true; socket.write(`${JSON.stringify({ message: input.message })}\n`); });
83
+ socket.on("data", (chunk) => {
84
+ data += chunk;
85
+ const newline = data.indexOf("\n");
86
+ if (newline < 0) {
87
+ if (data.length > exports.MAX_RELAY_REPLY_BYTES)
88
+ finish(exports.RELAY_UNAVAILABLE);
89
+ return;
90
+ }
91
+ let parsed;
92
+ try {
93
+ parsed = JSON.parse(data.slice(0, newline)).reply;
94
+ }
95
+ catch {
96
+ parsed = undefined;
97
+ }
98
+ finish(typeof parsed === "string" && exports.RELAY_REPLY.test(parsed) ? parsed : exports.RELAY_UNAVAILABLE);
99
+ });
100
+ socket.on("close", () => finish(exports.RELAY_UNAVAILABLE));
101
+ socket.on("error", () => finish(exports.RELAY_UNAVAILABLE));
102
+ });
103
+ // The level is worked out first: the nerves source scanner reads a call's object only up to its first "})".
104
+ const level = reply === exports.RELAY_UNAVAILABLE || reply === exports.RELAY_TIMED_OUT ? "warn" : "info";
105
+ (0, runtime_1.emitNervesEvent)({
106
+ level,
107
+ component: "channels",
108
+ event: "channel.a2a_approval_answer_forwarded",
109
+ message: "forwarded a relayed approval answer to the Telegram sense",
110
+ meta: { reply },
111
+ });
112
+ return reply;
113
+ }
@@ -37,6 +37,7 @@ exports.ESCALATION_CONFIRM_INTERVAL_MS = exports.A2A_TURN_TIMEOUT_MS = void 0;
37
37
  exports.a2aChatRelationship = a2aChatRelationship;
38
38
  exports.commandIdFor = commandIdFor;
39
39
  exports.startA2AServer = startA2AServer;
40
+ const approval_relay_forward_1 = require("./approval-relay-forward");
40
41
  const http = __importStar(require("node:http"));
41
42
  const node_crypto_1 = require("node:crypto");
42
43
  const a2a_client_1 = require("@ouro.bot/friends/a2a-client");
@@ -462,6 +463,38 @@ async function startA2AServer(options) {
462
463
  };
463
464
  // The message/send branch as one function, so a sealed message that arrives through the relay inbox runs exactly the
464
465
  // path a direct POST runs. `req` is absent for a relayed message: there are no HTTP headers to take a sender hint from.
466
+ /**
467
+ * A verified message carrying a signed `approvalAnswer`: forward it to the Telegram sense, which opens and checks it
468
+ * again, and send back its one-word outcome, sealed to the sender. It is never journaled and never reaches a model
469
+ * (review L4). Only the owner route's peer is forwarded; anyone else hears one generic `refused`. Everything that
470
+ * could fail is checked before forwarding, so a sender always hears whether a forwarded deny landed.
471
+ */
472
+ const answerRelayedApproval = async (rpcId, inbound, senderDid, conversationId, responseStyle) => {
473
+ // receiveShare pinned the sender before it reported the message as completed.
474
+ const pinned = inboundShareDeps.pinStore.get(senderDid);
475
+ let routeDid;
476
+ try {
477
+ routeDid = (options.approvalRelayPeerDid ?? (() => (0, identity_1.loadAgentConfig)({ agentName: options.agentName, agentRoot }).senses?.telegram.ownerNoticesTo?.did))();
478
+ }
479
+ catch {
480
+ routeDid = undefined;
481
+ }
482
+ const fromRoute = routeDid !== undefined && routeDid === senderDid;
483
+ if (!fromRoute)
484
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "channels", event: "channel.a2a_approval_answer_not_from_route", message: "refused an approval answer from a sender that isn't the owner route's peer", meta: { senderDid } });
485
+ const reply = fromRoute
486
+ ? await (options.forwardApprovalAnswer ?? approval_relay_forward_1.forwardApprovalAnswer)({ socketPath: (0, approval_relay_forward_1.approvalRelaySocketPath)(agentRoot), message: inbound })
487
+ : approval_relay_forward_1.RELAY_REFUSED;
488
+ // The signed conversation id, never the outer contextId: friends has already held it to its length limit.
489
+ const responseParts = (0, sealed_chat_1.sealChatMessage)({
490
+ sodium: inboundShareDeps.sodium, from: options.identity, recipientDid: senderDid, recipientEd25519Pub: pinned.ed25519Pub,
491
+ text: reply, ...(conversationId ? { conversationId } : {}),
492
+ }).parts;
493
+ const accessToken = (0, node_crypto_1.randomUUID)();
494
+ const task = taskFor({ taskId: (0, node_crypto_1.randomUUID)(), accessTokenHash: accessTokenHash(accessToken), contextId: inbound.contextId ?? "default", inbound, state: "TASK_STATE_COMPLETED", response: reply, responseParts });
495
+ taskStore.put(task, accessTokenScope(accessToken));
496
+ return jsonResponse(rpcId, publicTask(task, accessToken, responseStyle, true));
497
+ };
465
498
  const handleMessageSend = async (rpc, req, origin = "direct") => {
466
499
  const responseStyle = rpc.method === "message/send" ? "legacy" : "latest";
467
500
  const parsedInbound = messageFromParams(rpc.params);
@@ -518,6 +551,10 @@ async function startA2AServer(options) {
518
551
  if (bridged.outcome === "completed") {
519
552
  verifiedPeerAgentId = bridged.verifiedDid;
520
553
  verifiedPeerName = bridged.verifiedDid;
554
+ if (bridged.message?.approvalAnswer) {
555
+ // An approval answer is never a turn: the Telegram sense, which owns the cards, checks and decides it.
556
+ return answerRelayedApproval(rpc.id, inbound, bridged.verifiedDid, bridged.message.conversationId, responseStyle);
557
+ }
521
558
  if (bridged.message) {
522
559
  // Authenticated chat: the signed, sealed text IS the turn.
523
560
  verifiedShareText = bridged.message.text;
@@ -42,6 +42,15 @@ const cadence_1 = require("../daemon/cadence");
42
42
  const WATCH_DEBOUNCE_MS = 200;
43
43
  /** Cron-label namespace prefix to avoid collision with habits. */
44
44
  exports.AWAIT_CRON_LABEL_PREFIX_MARKER = "await";
45
+ /** setTimeout's longest delay; a wake further off is re-armed by the next reconcile. */
46
+ const MAX_TIMER_MS = 2_147_483_647;
47
+ /** Epoch ms of an await's wake_at, or null when it has none or it can't be read. */
48
+ function wakeAtMs(a) {
49
+ if (!a.wake_at)
50
+ return null;
51
+ const ms = Date.parse(a.wake_at);
52
+ return Number.isFinite(ms) ? ms : null;
53
+ }
45
54
  /** An await that ships with the package: it has no filer, friend, conversation or request behind it (the same test the private runtime uses for "no relationship"). */
46
55
  function isSystemAwait(a) {
47
56
  return !a.request_id && !a.filed_for_friend_id && !a.filed_from_key && (!a.filed_from || a.filed_from === "unknown");
@@ -62,6 +71,7 @@ class AwaitScheduler {
62
71
  timerFallbacks = new Map();
63
72
  degradedAwaitNames = new Map();
64
73
  periodicTimer = null;
74
+ wakeTimer = null;
65
75
  constructor(options) {
66
76
  this.agent = options.agent;
67
77
  this.awaitsDir = options.awaitsDir;
@@ -87,10 +97,13 @@ class AwaitScheduler {
87
97
  const awaits = this.scanAwaits();
88
98
  this.expireOverdueByMaxAge(awaits);
89
99
  const remaining = awaits.filter((a) => a.status === "pending" && !this.isExpiredByMaxAge(a));
90
- const jobs = this.buildJobs(remaining);
100
+ // An await with a wake_at still ahead is neither scheduled nor fired: it waits for that time.
101
+ const due = remaining.filter((a) => !this.waitsForWakeAt(a));
102
+ const jobs = this.buildJobs(due);
91
103
  this.osCronManager.sync(jobs);
92
104
  this.verifyCronAndCreateFallbacks(jobs);
93
- this.fireOverdueAwaits(remaining);
105
+ this.fireOverdueAwaits(due);
106
+ this.armWakeTimer(remaining);
94
107
  }
95
108
  reconcile() {
96
109
  (0, runtime_1.emitNervesEvent)({
@@ -103,10 +116,13 @@ class AwaitScheduler {
103
116
  const awaits = this.scanAwaits();
104
117
  this.expireOverdueByMaxAge(awaits);
105
118
  const remaining = awaits.filter((a) => a.status === "pending" && !this.isExpiredByMaxAge(a));
106
- const jobs = this.buildJobs(remaining);
119
+ // An await with a wake_at still ahead is neither scheduled nor fired: it waits for that time.
120
+ const due = remaining.filter((a) => !this.waitsForWakeAt(a));
121
+ const jobs = this.buildJobs(due);
107
122
  this.osCronManager.sync(jobs);
108
123
  this.verifyCronAndCreateFallbacks(jobs);
109
- this.fireOverdueAwaits(remaining);
124
+ this.fireOverdueAwaits(due);
125
+ this.armWakeTimer(remaining);
110
126
  }
111
127
  stop() {
112
128
  (0, runtime_1.emitNervesEvent)({
@@ -117,6 +133,7 @@ class AwaitScheduler {
117
133
  });
118
134
  this.stopPeriodicReconciliation();
119
135
  this.clearAllTimerFallbacks();
136
+ this.clearWakeTimer();
120
137
  this.osCronManager.removeAll();
121
138
  }
122
139
  getParseErrors() {
@@ -189,8 +206,50 @@ class AwaitScheduler {
189
206
  this.scheduleNextReconciliation(intervalMs);
190
207
  }, intervalMs);
191
208
  }
209
+ waitsForWakeAt(a) {
210
+ const wake = wakeAtMs(a);
211
+ return wake !== null && wake > this.deps.now();
212
+ }
213
+ /** One timer, at the nearest wake_at still ahead, that reconciles so that await is scheduled and fires on time. */
214
+ armWakeTimer(awaits) {
215
+ this.clearWakeTimer();
216
+ const nowMs = this.deps.now();
217
+ const next = Math.min(...awaits.map((a) => wakeAtMs(a) ?? Infinity).filter((ms) => ms > nowMs));
218
+ if (!Number.isFinite(next))
219
+ return;
220
+ const delay = Math.min(next - nowMs, MAX_TIMER_MS);
221
+ (0, runtime_1.emitNervesEvent)({
222
+ component: "daemon",
223
+ event: "daemon.await_wake_timer_armed",
224
+ message: "await scheduler waiting for the next wake_at",
225
+ meta: { agent: this.agent, delayMs: delay },
226
+ });
227
+ this.wakeTimer = setTimeout(() => {
228
+ this.wakeTimer = null;
229
+ this.reconcile();
230
+ }, delay);
231
+ }
232
+ clearWakeTimer() {
233
+ if (this.wakeTimer !== null) {
234
+ clearTimeout(this.wakeTimer);
235
+ this.wakeTimer = null;
236
+ }
237
+ }
192
238
  fireOverdueAwaits(awaits) {
193
239
  for (const a of awaits) {
240
+ // A wake_at that has passed fires once, at once, unless the await was checked since; then the cadence takes over.
241
+ const wake = wakeAtMs(a);
242
+ const lastCheckedAt = a.last_checked ? Date.parse(a.last_checked) : Number.NaN;
243
+ if (wake !== null && !(lastCheckedAt >= wake)) {
244
+ (0, runtime_1.emitNervesEvent)({
245
+ component: "daemon",
246
+ event: "daemon.await_fire",
247
+ message: "firing await at its wake_at",
248
+ meta: { awaitName: a.name, agent: this.agent, wakeAt: a.wake_at },
249
+ });
250
+ this.onAwaitFire(a.name);
251
+ continue;
252
+ }
194
253
  if (!a.cadence)
195
254
  continue;
196
255
  const cadenceMs = (0, cadence_1.parseCadenceToMs)(a.cadence);
@@ -33,10 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.RELAY_SOCKET_IDLE_TIMEOUT_MS = exports.MAX_RELAY_CONNECTIONS = exports.MAX_SOCKET_PATH_BYTES = void 0;
36
+ exports.RELAY_SOCKET_IDLE_TIMEOUT_MS = exports.MAX_RELAY_CONNECTIONS = exports.MAX_SOCKET_PATH_BYTES = exports.approvalRelaySocketPath = void 0;
37
37
  exports.relayAnswerSeenLedger = relayAnswerSeenLedger;
38
38
  exports.handleRelayedApprovalAnswer = handleRelayedApprovalAnswer;
39
- exports.approvalRelaySocketPath = approvalRelaySocketPath;
40
39
  exports.startApprovalRelaySocket = startApprovalRelaySocket;
41
40
  exports.createApprovalRelayDoor = createApprovalRelayDoor;
42
41
  /**
@@ -59,6 +58,7 @@ const net = __importStar(require("node:net"));
59
58
  const path = __importStar(require("node:path"));
60
59
  const a2a_client_1 = require("@ouro.bot/friends/a2a-client");
61
60
  const approval_relay_1 = require("../a2a/approval-relay");
61
+ const approval_relay_forward_1 = require("../a2a/approval-relay-forward");
62
62
  const identity_1 = require("../a2a/identity");
63
63
  const operator_trust_1 = require("../a2a/operator-trust");
64
64
  const identity_2 = require("../heart/identity");
@@ -101,10 +101,8 @@ async function handleRelayedApprovalAnswer(deps, message) {
101
101
  envelopeBindingId: opened.envelopeBindingId,
102
102
  });
103
103
  }
104
- /** The socket the A2A process forwards tagged envelopes to, alone in a folder only this agent's user can enter. */
105
- function approvalRelaySocketPath(agentRoot) {
106
- return path.join(agentRoot, "state", "approvals", "relay", "sock");
107
- }
104
+ var approval_relay_forward_2 = require("../a2a/approval-relay-forward");
105
+ Object.defineProperty(exports, "approvalRelaySocketPath", { enumerable: true, get: function () { return approval_relay_forward_2.approvalRelaySocketPath; } });
108
106
  const MAX_REQUEST_BYTES = 256 * 1024;
109
107
  /** macOS takes a socket path of at most 104 bytes and mishandles a longer one, so a longer path is refused instead. */
110
108
  exports.MAX_SOCKET_PATH_BYTES = 104;
@@ -232,7 +230,7 @@ function createApprovalRelayDoor(input) {
232
230
  seen: relayAnswerSeenLedger(input.agentRoot),
233
231
  };
234
232
  server = await startApprovalRelaySocket({
235
- socketPath: input.socketPath ?? approvalRelaySocketPath(input.agentRoot),
233
+ socketPath: input.socketPath ?? (0, approval_relay_forward_1.approvalRelaySocketPath)(input.agentRoot),
236
234
  handle: (message) => handleRelayedApprovalAnswer(deps, message),
237
235
  });
238
236
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1410",
3
+ "version": "0.1.0-alpha.1412",
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.1410",
9
+ "version": "0.1.0-alpha.1412",
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.1410",
3
+ "version": "0.1.0-alpha.1412",
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": {