@ouro.bot/friends 0.1.0-alpha.4 → 0.1.0-alpha.6

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 (70) hide show
  1. package/README.md +79 -8
  2. package/changelog.json +12 -0
  3. package/dist/a2a-client/a2a-message.d.ts +39 -0
  4. package/dist/a2a-client/a2a-message.js +54 -0
  5. package/dist/a2a-client/adapter.d.ts +97 -0
  6. package/dist/a2a-client/adapter.js +114 -0
  7. package/dist/a2a-client/agent-card.d.ts +50 -0
  8. package/dist/a2a-client/agent-card.js +32 -0
  9. package/dist/a2a-client/did-key.d.ts +38 -0
  10. package/dist/a2a-client/did-key.js +120 -0
  11. package/dist/a2a-client/did-verifier.d.ts +109 -0
  12. package/dist/a2a-client/did-verifier.js +163 -0
  13. package/dist/a2a-client/did-web.d.ts +26 -0
  14. package/dist/a2a-client/did-web.js +140 -0
  15. package/dist/a2a-client/index.d.ts +24 -0
  16. package/dist/a2a-client/index.js +76 -0
  17. package/dist/a2a-client/jcs.d.ts +5 -0
  18. package/dist/a2a-client/jcs.js +84 -0
  19. package/dist/a2a-client/reachability.d.ts +22 -0
  20. package/dist/a2a-client/reachability.js +17 -0
  21. package/dist/a2a-client/roster-verify.d.ts +15 -0
  22. package/dist/a2a-client/roster-verify.js +61 -0
  23. package/dist/a2a-client/seal.d.ts +47 -0
  24. package/dist/a2a-client/seal.js +95 -0
  25. package/dist/a2a-client/sealed-envelope.d.ts +55 -0
  26. package/dist/a2a-client/sealed-envelope.js +94 -0
  27. package/dist/a2a-client/sign.d.ts +42 -0
  28. package/dist/a2a-client/sign.js +87 -0
  29. package/dist/a2a-client/sodium.d.ts +5 -0
  30. package/dist/a2a-client/sodium.js +19 -0
  31. package/dist/account-roster.d.ts +52 -0
  32. package/dist/account-roster.js +108 -0
  33. package/dist/agent-peer.js +10 -2
  34. package/dist/audit.d.ts +38 -0
  35. package/dist/audit.js +86 -0
  36. package/dist/file-bundle.d.ts +5 -0
  37. package/dist/file-bundle.js +4 -0
  38. package/dist/friend-lookup.d.ts +9 -0
  39. package/dist/friend-lookup.js +69 -0
  40. package/dist/identity.d.ts +17 -0
  41. package/dist/identity.js +68 -0
  42. package/dist/index.d.ts +13 -0
  43. package/dist/index.js +31 -2
  44. package/dist/{a2a → mailbox}/index.js +10 -3
  45. package/dist/mcp/bin.js +0 -0
  46. package/dist/mcp/dispatch.d.ts +12 -1
  47. package/dist/mcp/dispatch.js +45 -3
  48. package/dist/mcp/run-main.js +8 -5
  49. package/dist/mcp/schemas.js +1 -1
  50. package/dist/mcp/server.d.ts +9 -0
  51. package/dist/mcp/server.js +2 -2
  52. package/dist/resolver.d.ts +32 -1
  53. package/dist/resolver.js +50 -3
  54. package/dist/roster-store-file.d.ts +16 -0
  55. package/dist/roster-store-file.js +125 -0
  56. package/dist/roster-store-memory.d.ts +9 -0
  57. package/dist/roster-store-memory.js +20 -0
  58. package/dist/roster-store.d.ts +29 -0
  59. package/dist/roster-store.js +9 -0
  60. package/dist/roster-verifier.d.ts +23 -0
  61. package/dist/roster-verifier.js +47 -0
  62. package/dist/store-file.d.ts +6 -2
  63. package/dist/store-file.js +28 -5
  64. package/dist/trust-explanation.d.ts +7 -1
  65. package/dist/trust-explanation.js +52 -34
  66. package/dist/trust-mutation.d.ts +13 -1
  67. package/dist/trust-mutation.js +31 -2
  68. package/dist/types.d.ts +33 -7
  69. package/package.json +15 -6
  70. /package/dist/{a2a → mailbox}/index.d.ts +0 -0
@@ -190,30 +190,43 @@ class FileFriendStore {
190
190
  const meta = raw;
191
191
  if (typeof meta.bundleName !== "string")
192
192
  return undefined;
193
+ // Mailbox is top-level on AgentMeta since the phase-8 demote. Read the
194
+ // top-level `meta.mailbox` first; if absent, MIGRATE-ON-READ from a legacy
195
+ // alpha.4 record that nested it under `a2a.mailbox`. schemaVersion stays 1;
196
+ // every legacy record reads clean.
197
+ const a2aRaw = meta.a2a && typeof meta.a2a === "object" && !Array.isArray(meta.a2a)
198
+ ? meta.a2a
199
+ : undefined;
200
+ const mailbox = this.normalizeMailbox(meta.mailbox) ??
201
+ (a2aRaw ? this.normalizeMailbox(a2aRaw.mailbox) : undefined);
202
+ const a2a = this.normalizeA2AMeta(meta.a2a);
193
203
  return {
194
204
  bundleName: meta.bundleName,
195
205
  familiarity: typeof meta.familiarity === "number" ? meta.familiarity : 0,
196
206
  sharedMissions: Array.isArray(meta.sharedMissions) ? meta.sharedMissions : [],
197
207
  outcomes: Array.isArray(meta.outcomes) ? meta.outcomes : [],
198
- ...(this.normalizeA2AMeta(meta.a2a) ? { a2a: this.normalizeA2AMeta(meta.a2a) } : {}),
208
+ ...(a2a ? { a2a } : {}),
209
+ ...(mailbox ? { mailbox } : {}),
199
210
  };
200
211
  }
201
212
  normalizeA2AMeta(raw) {
202
213
  if (!raw || typeof raw !== "object" || Array.isArray(raw))
203
214
  return undefined;
204
215
  const meta = raw;
205
- const mailbox = this.normalizeMailbox(meta.mailbox);
216
+ const relay = this.normalizeRelay(meta.relay);
206
217
  const a2a = {
207
218
  ...(typeof meta.cardUrl === "string" ? { cardUrl: meta.cardUrl } : {}),
208
219
  ...(typeof meta.endpointUrl === "string" ? { endpointUrl: meta.endpointUrl } : {}),
209
220
  ...(typeof meta.agentId === "string" ? { agentId: meta.agentId } : {}),
210
221
  ...(typeof meta.protocolVersion === "string" ? { protocolVersion: meta.protocolVersion } : {}),
211
- ...(mailbox ? { mailbox } : {}),
222
+ ...(relay ? { relay } : {}),
223
+ ...(typeof meta.did === "string" ? { did: meta.did } : {}),
212
224
  };
213
225
  return Object.keys(a2a).length > 0 ? a2a : undefined;
214
226
  }
215
- /** Preserve an additive a2a.mailbox coord only when both fields are strings;
216
- * otherwise drop it (absent ⇒ unchanged — the additive guarantee). */
227
+ /** Preserve the top-level mailbox coord only when both fields are strings;
228
+ * otherwise drop it (absent ⇒ unchanged — the additive guarantee). Also used to
229
+ * migrate a legacy nested `a2a.mailbox`. */
217
230
  normalizeMailbox(raw) {
218
231
  if (!raw || typeof raw !== "object" || Array.isArray(raw))
219
232
  return undefined;
@@ -222,6 +235,16 @@ class FileFriendStore {
222
235
  return undefined;
223
236
  return { repo: m.repo, selfOutboxAgentId: m.selfOutboxAgentId };
224
237
  }
238
+ /** Preserve an additive a2a.relay coord only when both fields are strings;
239
+ * otherwise drop it (absent ⇒ unchanged — the additive guarantee). */
240
+ normalizeRelay(raw) {
241
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
242
+ return undefined;
243
+ const r = raw;
244
+ if (typeof r.url !== "string" || typeof r.handle !== "string")
245
+ return undefined;
246
+ return { url: r.url, handle: r.handle };
247
+ }
225
248
  async readJson(filePath) {
226
249
  try {
227
250
  const raw = await fsPromises.readFile(filePath, "utf-8");
@@ -1,5 +1,5 @@
1
1
  import type { Channel, FriendRecord, TrustLevel } from "./types";
2
- export type TrustBasis = "direct" | "shared_group" | "unknown";
2
+ export type TrustBasis = "direct" | "shared_group" | "unknown" | "same_account";
3
3
  export interface TrustExplanation {
4
4
  level: TrustLevel;
5
5
  basis: TrustBasis;
@@ -13,4 +13,10 @@ export declare function describeTrustContext(input: {
13
13
  friend: FriendRecord;
14
14
  channel: Channel;
15
15
  isGroupChat?: boolean;
16
+ /** When the relationship is `family` AND this hint is `"same_account"`, the
17
+ * explanation attributes the family trust to the signed account roster
18
+ * (`basis: "same_account"`) instead of the generic `direct`. Ignored for any
19
+ * non-family level. Absent ⇒ existing behavior byte-for-byte. (Unit 3a stub:
20
+ * accepted but not yet honored — implemented GREEN in Unit 3b.) */
21
+ basisHint?: TrustBasis;
16
22
  }): TrustExplanation;
@@ -11,14 +11,17 @@ function resolveLevel(friend) {
11
11
  function describeTrustContext(input) {
12
12
  const level = resolveLevel(input.friend);
13
13
  const relatedGroupId = findRelatedGroupId(input.friend);
14
- const explanation = level === "family" || level === "friend"
14
+ // The same-account variant only applies where the relationship is actually
15
+ // account-derived family: level === "family" AND the caller hints same_account
16
+ // (the roster path seats it). It keeps the family tier's permits/constraints but
17
+ // attributes the trust to the signed account roster, not generic direct trust.
18
+ const isSameAccountFamily = level === "family" && input.basisHint === "same_account";
19
+ const explanation = isSameAccountFamily
15
20
  ? {
16
21
  level,
17
- basis: "direct",
18
- summary: level === "family"
19
- ? "direct family trust"
20
- : "direct trusted relationship",
21
- why: "this relationship is directly trusted rather than inferred through a shared group or cold first contact.",
22
+ basis: "same_account",
23
+ summary: "same-account family (signed account roster)",
24
+ why: "this agent is recognized as the same owner's agent via the signed account roster, not through a shared group or cold first contact.",
22
25
  permits: [
23
26
  "local operations when appropriate",
24
27
  "proactive follow-through",
@@ -26,39 +29,54 @@ function describeTrustContext(input) {
26
29
  ],
27
30
  constraints: [],
28
31
  }
29
- : level === "acquaintance"
32
+ : level === "family" || level === "friend"
30
33
  ? {
31
34
  level,
32
- basis: "shared_group",
33
- summary: relatedGroupId
34
- ? "known through the shared project group"
35
- : "known through a shared group context",
36
- why: relatedGroupId
37
- ? `this trust comes from the shared group context ${relatedGroupId}, not from direct endorsement.`
38
- : "this trust comes from shared group context rather than direct endorsement.",
35
+ basis: "direct",
36
+ summary: level === "family"
37
+ ? "direct family trust"
38
+ : "direct trusted relationship",
39
+ why: "this relationship is directly trusted rather than inferred through a shared group or cold first contact.",
39
40
  permits: [
40
- "group-safe coordination",
41
- "normal conversation inside the shared context",
41
+ "local operations when appropriate",
42
+ "proactive follow-through",
43
+ "full collaborative problem solving",
42
44
  ],
43
- constraints: [
44
- "guarded local actions",
45
- "do not assume broad private authority",
46
- ],
47
- relatedGroupId,
45
+ constraints: [],
48
46
  }
49
- : {
50
- level,
51
- basis: "unknown",
52
- summary: "truly unknown first-contact context",
53
- why: "this person is not known through direct trust or a shared group context.",
54
- permits: [
55
- "safe first-contact orientation only",
56
- ],
57
- constraints: [
58
- "first contact does not reach the full model on open channels",
59
- "no local or privileged actions",
60
- ],
61
- };
47
+ : level === "acquaintance"
48
+ ? {
49
+ level,
50
+ basis: "shared_group",
51
+ summary: relatedGroupId
52
+ ? "known through the shared project group"
53
+ : "known through a shared group context",
54
+ why: relatedGroupId
55
+ ? `this trust comes from the shared group context ${relatedGroupId}, not from direct endorsement.`
56
+ : "this trust comes from shared group context rather than direct endorsement.",
57
+ permits: [
58
+ "group-safe coordination",
59
+ "normal conversation inside the shared context",
60
+ ],
61
+ constraints: [
62
+ "guarded local actions",
63
+ "do not assume broad private authority",
64
+ ],
65
+ relatedGroupId,
66
+ }
67
+ : {
68
+ level,
69
+ basis: "unknown",
70
+ summary: "truly unknown first-contact context",
71
+ why: "this person is not known through direct trust or a shared group context.",
72
+ permits: [
73
+ "safe first-contact orientation only",
74
+ ],
75
+ constraints: [
76
+ "first contact does not reach the full model on open channels",
77
+ "no local or privileged actions",
78
+ ],
79
+ };
62
80
  (0, observability_1.emitNervesEvent)({
63
81
  component: "friends",
64
82
  event: "friends.trust_explained",
@@ -1,4 +1,16 @@
1
1
  import type { FriendStore } from "./store";
2
2
  import type { TrustLevel } from "./types";
3
3
  import type { FriendOpResult } from "./results";
4
- export declare function setFriendTrust(store: FriendStore, friendId: string, level: TrustLevel): Promise<FriendOpResult>;
4
+ import type { AuditSink } from "./audit";
5
+ import type { TrustBasis } from "./trust-explanation";
6
+ /** Optional control-plane context for a trust mutation (Bug B). When a `sink` is
7
+ * supplied, a successful mutation appends one append-only control-plane audit
8
+ * record carrying WHO (`actor`), the `basis` and `originSense`, and WHEN. All
9
+ * fields are optional so the existing 3-arg callers are unaffected. */
10
+ export interface SetFriendTrustContext {
11
+ actor?: string;
12
+ originSense?: string;
13
+ basis?: TrustBasis;
14
+ sink?: AuditSink;
15
+ }
16
+ export declare function setFriendTrust(store: FriendStore, friendId: string, level: TrustLevel, ctx?: SetFriendTrustContext): Promise<FriendOpResult>;
@@ -7,7 +7,8 @@ exports.setFriendTrust = setFriendTrust;
7
7
  // `trustLevel` and `role` to the same level (so the record's coarse role tracks
8
8
  // its trust). A missing friend is a normal `not_found` result, never a throw.
9
9
  const observability_1 = require("./observability");
10
- async function setFriendTrust(store, friendId, level) {
10
+ const identity_1 = require("./identity");
11
+ async function setFriendTrust(store, friendId, level, ctx) {
11
12
  (0, observability_1.emitNervesEvent)({
12
13
  component: "friends",
13
14
  event: "friends.trust_set",
@@ -16,14 +17,42 @@ async function setFriendTrust(store, friendId, level) {
16
17
  });
17
18
  const current = await store.get(friendId);
18
19
  if (!current) {
20
+ // not_found is an early return BEFORE any mutation — and so writes NO audit
21
+ // record. The control-plane log captures actual standing changes only.
19
22
  return { ok: false, status: "not_found", message: "friend record not found" };
20
23
  }
24
+ const updatedAt = new Date().toISOString();
21
25
  const updated = {
22
26
  ...current,
23
27
  trustLevel: level,
24
28
  role: level,
25
- updatedAt: new Date().toISOString(),
29
+ updatedAt,
26
30
  };
27
31
  await store.put(friendId, updated);
32
+ // Bug B — append one control-plane audit record on the successful mutation. The
33
+ // `targetDid` is the record's durable identity DID (identity.did, falling back to
34
+ // the migrated a2a.did via resolveAgentIdentity). `actor` defaults to the literal
35
+ // "unknown" when the caller threads no context. No sink ⇒ a clean no-op.
36
+ //
37
+ // NOTE (finding 6-B): the append runs AFTER store.put, so it is best-effort with
38
+ // respect to the mutation — if the sink append throws/crashes, the trust change is
39
+ // already persisted but the audit line may be missing. We keep this ordering on
40
+ // purpose (the mutation is the source of truth; the audit is an observability log,
41
+ // not a 2-phase-commit participant). A throwing sink rejects this call so the caller
42
+ // still sees the failure; it does not roll back the already-applied mutation.
43
+ if (ctx?.sink) {
44
+ const targetDid = (0, identity_1.resolveAgentIdentity)(current.agentMeta).did;
45
+ const record = {
46
+ action: "set_trust",
47
+ targetId: friendId,
48
+ ...(targetDid !== undefined ? { targetDid } : {}),
49
+ level,
50
+ ...(ctx.basis !== undefined ? { basis: ctx.basis } : {}),
51
+ actor: ctx.actor ?? "unknown",
52
+ ...(ctx.originSense !== undefined ? { originSense: ctx.originSense } : {}),
53
+ ts: updatedAt,
54
+ };
55
+ await ctx.sink.append(record);
56
+ }
28
57
  return { ok: true, status: "updated", record: updated };
29
58
  }
package/dist/types.d.ts CHANGED
@@ -108,19 +108,45 @@ export interface AgentMeta {
108
108
  familiarity: number;
109
109
  sharedMissions: string[];
110
110
  outcomes: RelationshipOutcome[];
111
+ /** The durable identity home (p11 Item 2 — the DID re-key). `did` is the
112
+ * cross-agent primary key; `pinnedKey` is its TOFU-pinned Ed25519 public key.
113
+ * Additive + optional: legacy records carry only `a2a.did` (or nothing) and
114
+ * migrate-on-read into this shape via `resolveAgentIdentity`. schemaVersion
115
+ * stays 1. */
116
+ identity?: {
117
+ did: string;
118
+ pinnedKey?: string;
119
+ handle?: string;
120
+ pinnedAt?: string;
121
+ };
111
122
  a2a?: {
112
123
  cardUrl?: string;
113
124
  endpointUrl?: string;
114
125
  agentId?: string;
115
126
  protocolVersion?: string;
116
- /** Optional A2A git-mailbox coordinates (brick two). The mailbox is a
117
- * dedicated PRIVATE repo holding only in-flight envelopes; `selfOutboxAgentId`
118
- * is the dir THIS peer writes its outbox under. Absent on records that don't
119
- * use the git-mailbox transport. */
120
- mailbox?: {
121
- repo: string;
122
- selfOutboxAgentId: string;
127
+ /** Optional friends-relay coordinates (phase 8). When a peer has no directly
128
+ * reachable A2A `endpointUrl`, the host delivers via the UNTRUSTED relay at
129
+ * `url`, addressing the peer by its opaque `handle`. The relay carries only
130
+ * ciphertext (the E2E sign-then-seal overlay) — it never sees content. Absent
131
+ * on peers reachable directly or only via the git-mailbox fallback. */
132
+ relay?: {
133
+ url: string;
134
+ handle: string;
123
135
  };
136
+ /** The peer's pinned DID (phase 8 — `did:key:…` or `did:web:…`). `agentId ===
137
+ * did` (the DID is the cross-agent identity primary key); pinned on first
138
+ * contact (TOFU) and verified on every use thereafter. Absent until the peer
139
+ * presents a DID-bearing proof. */
140
+ did?: string;
141
+ };
142
+ /** Optional git-mailbox FALLBACK coordinates (the demoted no-endpoint transport;
143
+ * see src/mailbox/). The mailbox is a dedicated PRIVATE repo holding only
144
+ * in-flight envelopes; `selfOutboxAgentId` is the dir THIS peer writes its outbox
145
+ * under. Top-level since phase 8's demote (was nested under `a2a` in alpha.4 —
146
+ * legacy records migrate-on-read). Absent on peers that don't use the fallback. */
147
+ mailbox?: {
148
+ repo: string;
149
+ selfOutboxAgentId: string;
124
150
  };
125
151
  }
126
152
  export interface FriendRecord {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/friends",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "The who's-who / identity / relationship substrate for agents — trust ladder (family/friend/acquaintance/stranger), multi-party and multi-agent, consumed via the FriendStore interface + FriendResolver.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -14,9 +14,13 @@
14
14
  "types": "./dist/mcp/index.d.ts",
15
15
  "default": "./dist/mcp/index.js"
16
16
  },
17
- "./a2a": {
18
- "types": "./dist/a2a/index.d.ts",
19
- "default": "./dist/a2a/index.js"
17
+ "./mailbox": {
18
+ "types": "./dist/mailbox/index.d.ts",
19
+ "default": "./dist/mailbox/index.js"
20
+ },
21
+ "./a2a-client": {
22
+ "types": "./dist/a2a-client/index.d.ts",
23
+ "default": "./dist/a2a-client/index.js"
20
24
  }
21
25
  },
22
26
  "bin": {
@@ -29,6 +33,7 @@
29
33
  "type": "commonjs",
30
34
  "scripts": {
31
35
  "build": "tsc",
36
+ "postbuild": "node -e \"require('fs').chmodSync('dist/mcp/bin.js', 0o755)\"",
32
37
  "prepare": "npm run build",
33
38
  "pretest": "npm run build",
34
39
  "pretest:coverage": "npm run build",
@@ -37,10 +42,11 @@
37
42
  "lint": "eslint src/",
38
43
  "typecheck": "tsc --noEmit",
39
44
  "example:cross-agent-moat": "npm run build && tsx examples/cross-agent-moat.ts",
40
- "example:a2a-git-mailbox": "npm run build && tsx examples/a2a-git-mailbox.ts",
45
+ "example:mailbox-fallback": "npm run build && tsx examples/mailbox-fallback.ts",
41
46
  "example:cross-agent-mission-memory": "npm run build && tsx examples/cross-agent-mission-memory.ts",
42
47
  "example:cross-agent-standing": "npm run build && tsx examples/cross-agent-standing.ts",
43
48
  "example:cross-agent-coordination": "npm run build && tsx examples/cross-agent-coordination.ts",
49
+ "example:cross-agent-a2a-relay": "npm run build && tsx examples/cross-agent-a2a-relay.ts",
44
50
  "release:bump": "node scripts/release-bump.cjs",
45
51
  "release:preflight": "node scripts/release-preflight.cjs",
46
52
  "release:trust:check": "node scripts/npm-trusted-publishers.cjs check",
@@ -54,8 +60,11 @@
54
60
  "publishConfig": {
55
61
  "access": "public"
56
62
  },
57
- "dependencies": {},
63
+ "dependencies": {
64
+ "libsodium-wrappers": "0.8.4"
65
+ },
58
66
  "devDependencies": {
67
+ "@types/libsodium-wrappers": "0.8.2",
59
68
  "@types/node": "^22.0.0",
60
69
  "@vitest/coverage-v8": "^4.1.8",
61
70
  "eslint": "^10.0.2",
File without changes