@ouro.bot/cli 0.1.0-alpha.1392 → 0.1.0-alpha.1394

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.
Files changed (47) hide show
  1. package/changelog.json +12 -0
  2. package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
  3. package/deploy/unraid/sanctuary.xml +1 -1
  4. package/dist/a2a/approval-relay.js +95 -0
  5. package/dist/a2a/refusals.js +2 -0
  6. package/dist/heart/approval-store.js +44 -1
  7. package/node_modules/@ouro.bot/friends/README.md +17 -4
  8. package/node_modules/@ouro.bot/friends/actions/generated/mcp.json +1105 -0
  9. package/node_modules/@ouro.bot/friends/changelog.json +72 -0
  10. package/node_modules/@ouro.bot/friends/dist/a2a-client/adapter.d.ts +1 -1
  11. package/node_modules/@ouro.bot/friends/dist/a2a-client/envelope-binding.d.ts +2 -2
  12. package/node_modules/@ouro.bot/friends/dist/a2a-client/envelope-binding.js +12 -8
  13. package/node_modules/@ouro.bot/friends/dist/channel.d.ts +5 -0
  14. package/node_modules/@ouro.bot/friends/dist/channel.js +12 -1
  15. package/node_modules/@ouro.bot/friends/dist/connect.js +8 -8
  16. package/node_modules/@ouro.bot/friends/dist/grant-store-file.d.ts +3 -0
  17. package/node_modules/@ouro.bot/friends/dist/grant-store-file.js +30 -9
  18. package/node_modules/@ouro.bot/friends/dist/grants.d.ts +5 -1
  19. package/node_modules/@ouro.bot/friends/dist/grants.js +22 -6
  20. package/node_modules/@ouro.bot/friends/dist/index.d.ts +3 -3
  21. package/node_modules/@ouro.bot/friends/dist/index.js +5 -2
  22. package/node_modules/@ouro.bot/friends/dist/link-identity.js +9 -9
  23. package/node_modules/@ouro.bot/friends/dist/mcp/bin.js +2 -1
  24. package/node_modules/@ouro.bot/friends/dist/mcp/dispatch.js +211 -16
  25. package/node_modules/@ouro.bot/friends/dist/mcp/run-main.js +24 -13
  26. package/node_modules/@ouro.bot/friends/dist/mcp/schemas.js +9 -431
  27. package/node_modules/@ouro.bot/friends/dist/mcp/server.js +2 -1
  28. package/node_modules/@ouro.bot/friends/dist/message.d.ts +19 -1
  29. package/node_modules/@ouro.bot/friends/dist/message.js +31 -1
  30. package/node_modules/@ouro.bot/friends/dist/mission-result.d.ts +7 -0
  31. package/node_modules/@ouro.bot/friends/dist/mission-result.js +14 -7
  32. package/node_modules/@ouro.bot/friends/dist/mission-store-file.js +8 -0
  33. package/node_modules/@ouro.bot/friends/dist/missions.js +6 -5
  34. package/node_modules/@ouro.bot/friends/dist/notes.js +4 -4
  35. package/node_modules/@ouro.bot/friends/dist/outcomes.js +1 -1
  36. package/node_modules/@ouro.bot/friends/dist/share.d.ts +6 -1
  37. package/node_modules/@ouro.bot/friends/dist/share.js +40 -4
  38. package/node_modules/@ouro.bot/friends/dist/store-file.js +28 -13
  39. package/node_modules/@ouro.bot/friends/dist/tokens.d.ts +3 -1
  40. package/node_modules/@ouro.bot/friends/dist/tokens.js +5 -2
  41. package/node_modules/@ouro.bot/friends/dist/trust-mutation.js +2 -2
  42. package/node_modules/@ouro.bot/friends/dist/types.d.ts +12 -0
  43. package/node_modules/@ouro.bot/friends/dist/util/safe-id.d.ts +1 -0
  44. package/node_modules/@ouro.bot/friends/dist/util/safe-id.js +10 -0
  45. package/node_modules/@ouro.bot/friends/package.json +2 -1
  46. package/npm-shrinkwrap.json +6 -6
  47. package/package.json +2 -2
package/changelog.json CHANGED
@@ -1,6 +1,18 @@
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.1394",
6
+ "changes": [
7
+ "Groundwork for relaying Ari's approval answers: the relay token, the trust-folder switch and a store method for a relayed deny. Nothing uses them yet."
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1393",
12
+ "changes": [
13
+ "Use friends 0.1.0-alpha.30, which can carry a signed answer to an approval prompt."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1392",
6
18
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1392",
2
+ "runtimeVersion": "0.1.0-alpha.1394",
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.1392</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1394</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,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MIN_RELAY_KEY_LENGTH = exports.APPROVAL_RELAY_FILE = void 0;
4
+ exports.approvalRelayToken = approvalRelayToken;
5
+ exports.relayTokensEqual = relayTokensEqual;
6
+ exports.checkRelayedDecision = checkRelayedDecision;
7
+ exports.readApprovalRelaySwitch = readApprovalRelaySwitch;
8
+ /**
9
+ * The approval relay: Ari answers a tool approval by replying to his primary agent (the owner route's peer) instead of
10
+ * tapping the Telegram card, and that agent's harness sends the answer back as a signed `approvalAnswer`.
11
+ *
12
+ * This file holds the pieces that do no I/O beyond reading the operator's switch:
13
+ * - the relay token, which binds an answer to one approval and one route DID;
14
+ * - the trust-folder switch, which turns the relay on;
15
+ * - the v1 rule that only `deny` is relayed.
16
+ *
17
+ * Design: desk sanctuary-server/butler-productionization/ouroboros/2026-11-23-signed-relay-design-v3.md.
18
+ */
19
+ const node_crypto_1 = require("node:crypto");
20
+ const runtime_1 = require("../nerves/runtime");
21
+ const operator_trust_1 = require("./operator-trust");
22
+ const trusted_files_1 = require("./trusted-files");
23
+ /** The Butler's switch, in its operator trust folder. Root-owned, so neither the agent nor its shell can turn it on. */
24
+ exports.APPROVAL_RELAY_FILE = "approval-relay.json";
25
+ const DOMAIN = "ouro.approval-relay.v1\0";
26
+ /** A decision token is 32 random bytes in base64url (43 characters); anything under 32 characters isn't one. */
27
+ exports.MIN_RELAY_KEY_LENGTH = 32;
28
+ const DID = /^did:[a-z0-9]+:[A-Za-z0-9._:%-]{1,512}$/;
29
+ const ISO = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?Z$/;
30
+ /**
31
+ * `HMAC-SHA256(decisionToken, "ouro.approval-relay.v1\0" || approvalId || "\0" || routeDid)`, base64url. The decision
32
+ * token is the approval's own secret, so only the Butler can compute it, and the route DID means an outstanding token
33
+ * stops matching once the route rotates. It refuses to compute with an empty or short key (a settled approval has no
34
+ * token, and a short one isn't a decision token).
35
+ * Never log it.
36
+ */
37
+ function approvalRelayToken(input) {
38
+ const parts = [input.decisionToken, input.approvalId, input.routeDid];
39
+ if (parts.some((part) => typeof part !== "string" || part.length === 0 || part.includes("\0"))
40
+ || input.decisionToken.length < exports.MIN_RELAY_KEY_LENGTH) {
41
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.approval_relay_token_refused", message: "refused to compute an approval relay token without a decision token, approval id and route DID", meta: { reason: "missing_input" } });
42
+ throw new Error("approval relay token needs a decision token, an approval id and a route DID");
43
+ }
44
+ return (0, node_crypto_1.createHmac)("sha256", input.decisionToken).update(`${DOMAIN}${input.approvalId}\0${input.routeDid}`).digest("base64url");
45
+ }
46
+ /** Constant-time comparison of two relay tokens. Empty or non-string never matches. */
47
+ function relayTokensEqual(a, b) {
48
+ if (typeof a !== "string" || typeof b !== "string" || a.length === 0)
49
+ return false;
50
+ const left = Buffer.from(a);
51
+ const right = Buffer.from(b);
52
+ return left.length === right.length && (0, node_crypto_1.timingSafeEqual)(left, right);
53
+ }
54
+ /**
55
+ * v1 relays `deny` only. Approve is refused here in code, before any switch or list is read, so allowing it later means
56
+ * changing code (and friends, whose `approvalAnswer` also takes deny only), not editing a file.
57
+ */
58
+ function checkRelayedDecision(decision) {
59
+ if (decision === "deny")
60
+ return { ok: true, decision: "deny" };
61
+ const reason = decision === "approve" ? "approve_not_in_v1" : "unknown_decision";
62
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.approval_relay_decision_refused", message: "refused a relayed approval decision v1 does not relay", meta: { reason } });
63
+ return { ok: false, reason };
64
+ }
65
+ /**
66
+ * Reads `{ schemaVersion: 1, did, expiresAt, approveTools, source }` from the operator trust folder. Missing,
67
+ * untrusted, malformed or expired is off. `approveTools` must be a list of names but is never returned: v1 relays deny
68
+ * only, whatever it lists. A copy anywhere under the bundle is never read.
69
+ */
70
+ function readApprovalRelaySwitch(agentRoot, now = new Date()) {
71
+ const raw = (0, trusted_files_1.inspectTrustedJson)((0, operator_trust_1.operatorTrustFile)(agentRoot, exports.APPROVAL_RELAY_FILE));
72
+ if (raw.state === "missing")
73
+ return { on: false, reason: "missing" };
74
+ if (raw.state === "untrusted")
75
+ return off("untrusted", raw.reason);
76
+ const value = raw.value;
77
+ if (!value || typeof value !== "object" || Array.isArray(value))
78
+ return off("malformed");
79
+ const v = value;
80
+ const valid = Object.keys(v).sort().join(",") === "approveTools,did,expiresAt,schemaVersion,source"
81
+ && v.schemaVersion === 1
82
+ && typeof v.did === "string" && DID.test(v.did)
83
+ && typeof v.expiresAt === "string" && ISO.test(v.expiresAt) && Number.isFinite(Date.parse(v.expiresAt))
84
+ && Array.isArray(v.approveTools) && v.approveTools.every((tool) => typeof tool === "string")
85
+ && typeof v.source === "string" && v.source.trim().length > 0;
86
+ if (!valid)
87
+ return off("malformed");
88
+ if (now.getTime() >= Date.parse(v.expiresAt))
89
+ return off("expired");
90
+ return { on: true, did: v.did, expiresAt: v.expiresAt, source: v.source };
91
+ }
92
+ function off(reason, detail) {
93
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.approval_relay_switch_off", message: "the approval relay switch is off because its trust-folder file can't be used", meta: { reason, ...(detail ? { detail } : {}) } });
94
+ return { on: false, reason, ...(detail ? { detail } : {}) };
95
+ }
@@ -19,6 +19,8 @@ const REFUSALS = {
19
19
  unbound_delegation: { message: "the delegated command has no signed binding (the sender runs an older harness)", next: UPGRADE, retry: false },
20
20
  stale_envelope: { message: "the envelope is more than 7 days old or dated in the future", next: `Check the sender's clock. ${RESEND}`, retry: false },
21
21
  stale_delegation: { message: "the delegated command is more than 10 minutes old", next: `Check the sender's clock. ${RESEND}`, retry: false },
22
+ unbound_approval_answer: { message: "the approval answer has no signed binding (the sender runs an older harness)", next: UPGRADE, retry: false },
23
+ stale_approval_answer: { message: "the approval answer is more than 10 minutes old or dated in the future", next: "Check the sender's clock. Answer again from the approval prompt if it is still open.", retry: false },
22
24
  replayed: { message: "this message was already received", next: `Nothing to do if it was delivered; otherwise ${RESEND.toLowerCase()}`, retry: false },
23
25
  in_flight: { message: "the same message is being handled right now", next: "Retry in a moment.", retry: true },
24
26
  resolve_failed: { message: "the sender's DID could not be resolved or pinned (it is not a did:key, its pinned key differs, or a key rotation was refused)", next: "Send from the identity this agent knows you by, or ask the operator to re-link you.", retry: false },
@@ -123,7 +123,9 @@ function canonicalApprovalArguments(value) {
123
123
  }
124
124
  function hasExactKeys(value) {
125
125
  const actual = Object.keys(value).sort();
126
- const expected = [...RECORD_KEYS, ...("ownerBinding" in value ? ["ownerBinding"] : [])].sort();
126
+ const expected = [
127
+ ...RECORD_KEYS, ...("ownerBinding" in value ? ["ownerBinding"] : []), ...("relayDecision" in value ? ["relayDecision"] : []),
128
+ ].sort();
127
129
  return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
128
130
  }
129
131
  function validOwnerBinding(value) {
@@ -131,6 +133,10 @@ function validOwnerBinding(value) {
131
133
  && ["friendId", "requestId", "sessionEventId", "sessionKey"].every((key) => isNonEmpty(value[key]) && value[key] === value[key].trim())
132
134
  && typeof value.profileVersion === "number" && Number.isSafeInteger(value.profileVersion) && value.profileVersion > 0;
133
135
  }
136
+ function validRelayDecision(value) {
137
+ return isObject(value) && Object.keys(value).sort().join(",") === "actor,decidedAt,envelopeBindingId,senderDid"
138
+ && value.actor === "owner-via-relay" && isNonEmpty(value.senderDid) && isNonEmpty(value.envelopeBindingId) && isTimestamp(value.decidedAt);
139
+ }
134
140
  function validStateShape(record) {
135
141
  const hasOwner = isNonEmpty(record.ownerId);
136
142
  const hasAttempt = isTimestamp(record.attemptedAt);
@@ -200,6 +206,8 @@ function parseApprovalRecord(value) {
200
206
  fail("corrupt_record");
201
207
  if ("ownerBinding" in value && !validOwnerBinding(value.ownerBinding))
202
208
  fail("corrupt_record");
209
+ if ("relayDecision" in value && (!validRelayDecision(value.relayDecision) || value.state !== "denied"))
210
+ fail("corrupt_record");
203
211
  const record = value;
204
212
  if (!UUID.test(record.approvalId))
205
213
  fail("corrupt_record");
@@ -325,6 +333,17 @@ function observeDecide(operation) {
325
333
  throw error;
326
334
  }
327
335
  }
336
+ function observeDecideRelayed(operation) {
337
+ try {
338
+ const result = operation();
339
+ (0, runtime_1.emitNervesEvent)({ component: "heart", event: "approval.store_decide_relayed", message: "relayed approval decision completed", meta: { operation: "decide_relayed", outcome: "success" } });
340
+ return result;
341
+ }
342
+ catch (error) {
343
+ (0, runtime_1.emitNervesEvent)({ level: "error", component: "heart", event: "approval.store_decide_relayed", message: "relayed approval decision failed", meta: operationErrorMeta("decide_relayed", error) });
344
+ throw error;
345
+ }
346
+ }
328
347
  function observeExpire(operation) {
329
348
  try {
330
349
  const result = operation();
@@ -691,6 +710,30 @@ function openApprovalStore(options) {
691
710
  return cas(previous, { ...previous, state: "claimed", ownerId: input.ownerId, epoch: previous.epoch + 1, updatedAt: timestamp() });
692
711
  });
693
712
  },
713
+ decideRelayed(input) {
714
+ return observeDecideRelayed(() => {
715
+ if (input.decision !== "deny")
716
+ fail("relay_decision_not_allowed");
717
+ if (!isNonEmpty(input.senderDid) || !isNonEmpty(input.envelopeBindingId))
718
+ fail("invalid_relay_decision");
719
+ const previous = requireRecord(input.approvalId);
720
+ const decisionAt = now().getTime();
721
+ if (!tokenMatches(input.decisionToken, previous.decisionTokenDigest))
722
+ fail("decision_binding_mismatch");
723
+ if (previous.state === "denied" && previous.relayDecision?.envelopeBindingId === input.envelopeBindingId
724
+ && previous.relayDecision.senderDid === input.senderDid)
725
+ return previous;
726
+ if (previous.state !== "proposed")
727
+ fail("decision_not_eligible");
728
+ if (decisionAt >= Date.parse(previous.expiresAt)) {
729
+ return cas(previous, { ...previous, state: "expired", updatedAt: timestamp() });
730
+ }
731
+ const relayDecision = {
732
+ actor: "owner-via-relay", senderDid: input.senderDid, envelopeBindingId: input.envelopeBindingId, decidedAt: timestamp(),
733
+ };
734
+ return cas(previous, { ...previous, state: "denied", relayDecision, updatedAt: timestamp() });
735
+ });
736
+ },
694
737
  expire(input) {
695
738
  return observeExpire(() => {
696
739
  const previous = requireRecord(input.approvalId);
@@ -124,10 +124,23 @@ Because it is signed, a recipient who opens a message cannot re-seal the same si
124
124
  third party, and a relabelled kind fails. `receiveShare` (and `checkEnvelopeBinding`, for hosts with
125
125
  their own receive path) rejects with `signed_recipient_mismatch`, `signed_kind_mismatch`,
126
126
  `malformed_binding` or `replayed` (same `mid:<sender>:<id>`). Every envelope must also be fresh:
127
- `issuedAt` (ISO-8601 with a zone) at most 7 days old, and an envelope carrying `onBehalfOf` at most
128
- 10 minutes old (`stale_envelope` / `stale_delegation`), with 2 minutes of clock skew allowed. An
129
- envelope with no `binding` (an older sender) is accepted with `bound: false` unless it is a
130
- delegated command (`unbound_delegation`) or the host sets `rejectUnboundEnvelopes` (`unbound_envelope`).
127
+ `issuedAt` (ISO-8601 with a zone) at most 7 days old, and an envelope carrying `onBehalfOf` or
128
+ `approvalAnswer` at most 10 minutes old (`stale_envelope` / `stale_delegation` /
129
+ `stale_approval_answer`), with 2 minutes of clock skew allowed. An envelope with no `binding` (an
130
+ older sender) is accepted with `bound: false` unless it is a delegated command
131
+ (`unbound_delegation`), an approval answer (`unbound_approval_answer`) or the host sets
132
+ `rejectUnboundEnvelopes` (`unbound_envelope`).
133
+
134
+ **Approval answers.** A message may carry a signed `approvalAnswer: { relayToken, decision }`, where
135
+ `relayToken` is 16 to 128 base64url characters and `decision` is `deny`, the only decision this
136
+ version accepts: a receiver refuses any other as malformed, so allowing `approve` takes a new
137
+ release. It is signed with the text, so a relay can neither add, strip nor change it, and it claims
138
+ nothing on its own: the recipient matches the token against an approval it routed to that sender.
139
+ `prepareMessage` refuses a malformed answer, or one combined with `onBehalfOf`, as
140
+ `invalid_approval_answer`; `receiveMessage` refuses the same as `malformed_message`, and refuses
141
+ any answer as `untrusted_source` when it is given no verifier or `tofuVerifier` (neither checks a signature).
142
+ `checkEnvelopeBinding` refuses an answer on any kind but `message` as `malformed_binding`. Only
143
+ harness code should set it, never a model-facing tool.
131
144
  A completed result carries the signed `bindingId`. `checkEnvelopeBinding` is check-only: a host
132
145
  with its own receive path must hold an in-memory claim across its own awaits, and mark the returned
133
146
  `seenKey` (and its blob key) in the ledger only after the signature verifies. `receiveShare` does