@ouro.bot/cli 0.1.0-alpha.1146 → 0.1.0-alpha.1148

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 (157) 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/heart/daemon/cli-defaults.js +16 -25
  5. package/dist/heart/versioning/release-sources.js +15 -3
  6. package/node_modules/@ouro.bot/friends/LICENSE +201 -0
  7. package/node_modules/@ouro.bot/friends/README.md +674 -0
  8. package/node_modules/@ouro.bot/friends/changelog.json +125 -0
  9. package/node_modules/@ouro.bot/friends/dist/a2a-client/a2a-message.d.ts +39 -0
  10. package/node_modules/@ouro.bot/friends/dist/a2a-client/a2a-message.js +54 -0
  11. package/node_modules/@ouro.bot/friends/dist/a2a-client/adapter.d.ts +117 -0
  12. package/node_modules/@ouro.bot/friends/dist/a2a-client/adapter.js +202 -0
  13. package/node_modules/@ouro.bot/friends/dist/a2a-client/agent-card.d.ts +50 -0
  14. package/node_modules/@ouro.bot/friends/dist/a2a-client/agent-card.js +32 -0
  15. package/node_modules/@ouro.bot/friends/dist/a2a-client/did-key.d.ts +38 -0
  16. package/node_modules/@ouro.bot/friends/dist/a2a-client/did-key.js +120 -0
  17. package/node_modules/@ouro.bot/friends/dist/a2a-client/did-verifier.d.ts +195 -0
  18. package/node_modules/@ouro.bot/friends/dist/a2a-client/did-verifier.js +342 -0
  19. package/node_modules/@ouro.bot/friends/dist/a2a-client/did-web.d.ts +26 -0
  20. package/node_modules/@ouro.bot/friends/dist/a2a-client/did-web.js +140 -0
  21. package/node_modules/@ouro.bot/friends/dist/a2a-client/envelope-binding.d.ts +62 -0
  22. package/node_modules/@ouro.bot/friends/dist/a2a-client/envelope-binding.js +79 -0
  23. package/node_modules/@ouro.bot/friends/dist/a2a-client/index.d.ts +26 -0
  24. package/node_modules/@ouro.bot/friends/dist/a2a-client/index.js +82 -0
  25. package/node_modules/@ouro.bot/friends/dist/a2a-client/jcs.d.ts +5 -0
  26. package/node_modules/@ouro.bot/friends/dist/a2a-client/jcs.js +84 -0
  27. package/node_modules/@ouro.bot/friends/dist/a2a-client/reachability.d.ts +22 -0
  28. package/node_modules/@ouro.bot/friends/dist/a2a-client/reachability.js +17 -0
  29. package/node_modules/@ouro.bot/friends/dist/a2a-client/roster-verify.d.ts +15 -0
  30. package/node_modules/@ouro.bot/friends/dist/a2a-client/roster-verify.js +61 -0
  31. package/node_modules/@ouro.bot/friends/dist/a2a-client/seal.d.ts +47 -0
  32. package/node_modules/@ouro.bot/friends/dist/a2a-client/seal.js +95 -0
  33. package/node_modules/@ouro.bot/friends/dist/a2a-client/sealed-envelope.d.ts +58 -0
  34. package/node_modules/@ouro.bot/friends/dist/a2a-client/sealed-envelope.js +113 -0
  35. package/node_modules/@ouro.bot/friends/dist/a2a-client/sign.d.ts +42 -0
  36. package/node_modules/@ouro.bot/friends/dist/a2a-client/sign.js +87 -0
  37. package/node_modules/@ouro.bot/friends/dist/a2a-client/sodium.d.ts +5 -0
  38. package/node_modules/@ouro.bot/friends/dist/a2a-client/sodium.js +19 -0
  39. package/node_modules/@ouro.bot/friends/dist/account-roster.d.ts +52 -0
  40. package/node_modules/@ouro.bot/friends/dist/account-roster.js +108 -0
  41. package/node_modules/@ouro.bot/friends/dist/agent-peer.d.ts +26 -0
  42. package/node_modules/@ouro.bot/friends/dist/agent-peer.js +138 -0
  43. package/node_modules/@ouro.bot/friends/dist/audit.d.ts +42 -0
  44. package/node_modules/@ouro.bot/friends/dist/audit.js +86 -0
  45. package/node_modules/@ouro.bot/friends/dist/channel.d.ts +11 -0
  46. package/node_modules/@ouro.bot/friends/dist/channel.js +161 -0
  47. package/node_modules/@ouro.bot/friends/dist/connect-authority.d.ts +43 -0
  48. package/node_modules/@ouro.bot/friends/dist/connect-authority.js +84 -0
  49. package/node_modules/@ouro.bot/friends/dist/connect.d.ts +56 -0
  50. package/node_modules/@ouro.bot/friends/dist/connect.js +163 -0
  51. package/node_modules/@ouro.bot/friends/dist/consent.d.ts +34 -0
  52. package/node_modules/@ouro.bot/friends/dist/consent.js +65 -0
  53. package/node_modules/@ouro.bot/friends/dist/coordination.d.ts +116 -0
  54. package/node_modules/@ouro.bot/friends/dist/coordination.js +329 -0
  55. package/node_modules/@ouro.bot/friends/dist/delegation-grant.d.ts +21 -0
  56. package/node_modules/@ouro.bot/friends/dist/delegation-grant.js +39 -0
  57. package/node_modules/@ouro.bot/friends/dist/file-bundle.d.ts +17 -0
  58. package/node_modules/@ouro.bot/friends/dist/file-bundle.js +27 -0
  59. package/node_modules/@ouro.bot/friends/dist/friend-lookup.d.ts +9 -0
  60. package/node_modules/@ouro.bot/friends/dist/friend-lookup.js +69 -0
  61. package/node_modules/@ouro.bot/friends/dist/grant-store-file.d.ts +16 -0
  62. package/node_modules/@ouro.bot/friends/dist/grant-store-file.js +136 -0
  63. package/node_modules/@ouro.bot/friends/dist/grant-store.d.ts +7 -0
  64. package/node_modules/@ouro.bot/friends/dist/grant-store.js +8 -0
  65. package/node_modules/@ouro.bot/friends/dist/grants.d.ts +39 -0
  66. package/node_modules/@ouro.bot/friends/dist/grants.js +84 -0
  67. package/node_modules/@ouro.bot/friends/dist/group-context.d.ts +21 -0
  68. package/node_modules/@ouro.bot/friends/dist/group-context.js +145 -0
  69. package/node_modules/@ouro.bot/friends/dist/identity.d.ts +17 -0
  70. package/node_modules/@ouro.bot/friends/dist/identity.js +68 -0
  71. package/node_modules/@ouro.bot/friends/dist/index.d.ts +73 -0
  72. package/node_modules/@ouro.bot/friends/dist/index.js +161 -0
  73. package/node_modules/@ouro.bot/friends/dist/link-identity.d.ts +14 -0
  74. package/node_modules/@ouro.bot/friends/dist/link-identity.js +157 -0
  75. package/node_modules/@ouro.bot/friends/dist/mailbox/index.d.ts +105 -0
  76. package/node_modules/@ouro.bot/friends/dist/mailbox/index.js +205 -0
  77. package/node_modules/@ouro.bot/friends/dist/mcp/bin.d.ts +2 -0
  78. package/node_modules/@ouro.bot/friends/dist/mcp/bin.js +16 -0
  79. package/node_modules/@ouro.bot/friends/dist/mcp/dispatch.d.ts +40 -0
  80. package/node_modules/@ouro.bot/friends/dist/mcp/dispatch.js +549 -0
  81. package/node_modules/@ouro.bot/friends/dist/mcp/index.d.ts +6 -0
  82. package/node_modules/@ouro.bot/friends/dist/mcp/index.js +14 -0
  83. package/node_modules/@ouro.bot/friends/dist/mcp/run-main.d.ts +7 -0
  84. package/node_modules/@ouro.bot/friends/dist/mcp/run-main.js +48 -0
  85. package/node_modules/@ouro.bot/friends/dist/mcp/schemas.d.ts +10 -0
  86. package/node_modules/@ouro.bot/friends/dist/mcp/schemas.js +445 -0
  87. package/node_modules/@ouro.bot/friends/dist/mcp/server.d.ts +30 -0
  88. package/node_modules/@ouro.bot/friends/dist/mcp/server.js +194 -0
  89. package/node_modules/@ouro.bot/friends/dist/message.d.ts +75 -0
  90. package/node_modules/@ouro.bot/friends/dist/message.js +99 -0
  91. package/node_modules/@ouro.bot/friends/dist/mission-result.d.ts +82 -0
  92. package/node_modules/@ouro.bot/friends/dist/mission-result.js +200 -0
  93. package/node_modules/@ouro.bot/friends/dist/mission-share.d.ts +94 -0
  94. package/node_modules/@ouro.bot/friends/dist/mission-share.js +232 -0
  95. package/node_modules/@ouro.bot/friends/dist/mission-store-file.d.ts +18 -0
  96. package/node_modules/@ouro.bot/friends/dist/mission-store-file.js +161 -0
  97. package/node_modules/@ouro.bot/friends/dist/mission-store.d.ts +10 -0
  98. package/node_modules/@ouro.bot/friends/dist/mission-store.js +9 -0
  99. package/node_modules/@ouro.bot/friends/dist/missions.d.ts +31 -0
  100. package/node_modules/@ouro.bot/friends/dist/missions.js +98 -0
  101. package/node_modules/@ouro.bot/friends/dist/notes.d.ts +11 -0
  102. package/node_modules/@ouro.bot/friends/dist/notes.js +90 -0
  103. package/node_modules/@ouro.bot/friends/dist/observability.d.ts +27 -0
  104. package/node_modules/@ouro.bot/friends/dist/observability.js +31 -0
  105. package/node_modules/@ouro.bot/friends/dist/outcomes.d.ts +9 -0
  106. package/node_modules/@ouro.bot/friends/dist/outcomes.js +51 -0
  107. package/node_modules/@ouro.bot/friends/dist/resolver.d.ts +59 -0
  108. package/node_modules/@ouro.bot/friends/dist/resolver.js +276 -0
  109. package/node_modules/@ouro.bot/friends/dist/results.d.ts +10 -0
  110. package/node_modules/@ouro.bot/friends/dist/results.js +2 -0
  111. package/node_modules/@ouro.bot/friends/dist/room.d.ts +22 -0
  112. package/node_modules/@ouro.bot/friends/dist/room.js +40 -0
  113. package/node_modules/@ouro.bot/friends/dist/roster-store-file.d.ts +16 -0
  114. package/node_modules/@ouro.bot/friends/dist/roster-store-file.js +125 -0
  115. package/node_modules/@ouro.bot/friends/dist/roster-store-memory.d.ts +9 -0
  116. package/node_modules/@ouro.bot/friends/dist/roster-store-memory.js +20 -0
  117. package/node_modules/@ouro.bot/friends/dist/roster-store.d.ts +29 -0
  118. package/node_modules/@ouro.bot/friends/dist/roster-store.js +9 -0
  119. package/node_modules/@ouro.bot/friends/dist/roster-verifier.d.ts +23 -0
  120. package/node_modules/@ouro.bot/friends/dist/roster-verifier.js +47 -0
  121. package/node_modules/@ouro.bot/friends/dist/share.d.ts +108 -0
  122. package/node_modules/@ouro.bot/friends/dist/share.js +278 -0
  123. package/node_modules/@ouro.bot/friends/dist/standing.d.ts +83 -0
  124. package/node_modules/@ouro.bot/friends/dist/standing.js +111 -0
  125. package/node_modules/@ouro.bot/friends/dist/store-file.d.ts +82 -0
  126. package/node_modules/@ouro.bot/friends/dist/store-file.js +1074 -0
  127. package/node_modules/@ouro.bot/friends/dist/store.d.ts +43 -0
  128. package/node_modules/@ouro.bot/friends/dist/store.js +4 -0
  129. package/node_modules/@ouro.bot/friends/dist/tokens.d.ts +8 -0
  130. package/node_modules/@ouro.bot/friends/dist/tokens.js +26 -0
  131. package/node_modules/@ouro.bot/friends/dist/trust-explanation.d.ts +22 -0
  132. package/node_modules/@ouro.bot/friends/dist/trust-explanation.js +90 -0
  133. package/node_modules/@ouro.bot/friends/dist/trust-mutation.d.ts +16 -0
  134. package/node_modules/@ouro.bot/friends/dist/trust-mutation.js +67 -0
  135. package/node_modules/@ouro.bot/friends/dist/types.d.ts +321 -0
  136. package/node_modules/@ouro.bot/friends/dist/types.js +55 -0
  137. package/node_modules/@ouro.bot/friends/dist/util/cap-string.d.ts +7 -0
  138. package/node_modules/@ouro.bot/friends/dist/util/cap-string.js +35 -0
  139. package/node_modules/@ouro.bot/friends/dist/verifier.d.ts +11 -0
  140. package/node_modules/@ouro.bot/friends/dist/verifier.js +29 -0
  141. package/node_modules/@ouro.bot/friends/dist/whoami.d.ts +7 -0
  142. package/node_modules/@ouro.bot/friends/dist/whoami.js +39 -0
  143. package/node_modules/@ouro.bot/friends/package.json +81 -0
  144. package/node_modules/libsodium/LICENSE +16 -0
  145. package/node_modules/libsodium/README.md +281 -0
  146. package/node_modules/libsodium/dist/modules/libsodium.js +1 -0
  147. package/node_modules/libsodium/dist/modules-esm/libsodium.mjs +1 -0
  148. package/node_modules/libsodium/package.json +54 -0
  149. package/node_modules/libsodium-wrappers/LICENSE +16 -0
  150. package/node_modules/libsodium-wrappers/README.md +281 -0
  151. package/node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.d.ts +2155 -0
  152. package/node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.js +1 -0
  153. package/node_modules/libsodium-wrappers/dist/modules-esm/libsodium-wrappers.d.mts +2743 -0
  154. package/node_modules/libsodium-wrappers/dist/modules-esm/libsodium-wrappers.mjs +1 -0
  155. package/node_modules/libsodium-wrappers/package.json +74 -0
  156. package/npm-shrinkwrap.json +2 -2
  157. package/package.json +4 -1
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ // friends-mcp — stdio entrypoint for the friends MCP server.
5
+ //
6
+ // Thin wrapper: all arg-parsing and store construction live in `runMain` (which
7
+ // is covered by tests). This file is the only module excluded from coverage —
8
+ // its sole uncovered lines are the process wiring below.
9
+ const run_main_1 = require("./run-main");
10
+ (0, run_main_1.runMain)(process.argv, process.env, {
11
+ stdin: process.stdin,
12
+ stdout: process.stdout,
13
+ onError: () => {
14
+ process.exitCode = 1;
15
+ },
16
+ });
@@ -0,0 +1,40 @@
1
+ import type { FriendStore } from "../store";
2
+ import type { GrantStore } from "../grant-store";
3
+ import type { MissionStore } from "../mission-store";
4
+ import type { AuditSink } from "../audit";
5
+ import type { SenseType } from "../types";
6
+ import type { AccountMembershipResult } from "../account-roster";
7
+ type Args = Record<string, unknown>;
8
+ export interface DispatchResult {
9
+ result: unknown;
10
+ isError: boolean;
11
+ }
12
+ /** WHO/WHENCE context stamped onto a control-plane audit record (finding 3). The MCP
13
+ * server passes the local owner/sense it was constructed with. */
14
+ export interface ControlPlaneContext {
15
+ actor?: string;
16
+ originSense?: string;
17
+ /** The management SENSE the gate evaluates for `connect_to` (p11 inc2, brick 8).
18
+ * The stdio path is owner-only, so this defaults to `local` (`?? "local"`) — a
19
+ * `local` management sense COMMITS. A network/multi-tenant transport that constructs
20
+ * the server MUST pass its real senseType (`open` ⇒ confirm-prompt downgrade; `closed`
21
+ * ⇒ gated by `membership`). Distinct from `originSense` (a free-form audit string like
22
+ * "stdio"); this is the typed SenseType the authority predicate consumes. */
23
+ senseType?: SenseType;
24
+ /** The PRE-COMPUTED account-roster membership for a `closed`-sense `connect_to`
25
+ * (p11 inc2). The stdio `local` path never consults it (left `undefined`); a `closed`
26
+ * network transport supplies the membership it already evaluated against the roster.
27
+ * The boundary stays thin — it forwards this to the library, computing no membership
28
+ * itself (the MCP `resolve_party` path does not wire a roster context). */
29
+ membership?: AccountMembershipResult;
30
+ }
31
+ /** Whether wiring an AuditSink should also stamp a record for an `onboard_agent` trust
32
+ * seat: only when the owner explicitly set a trustLevel (a deliberate trust decision).
33
+ * A cold contact with no trustLevel lands at the safe `stranger` default (Bug A) and is
34
+ * NOT an owner trust mutation, so it is not audited. */
35
+ export declare function coerceBool(v: unknown): boolean;
36
+ export declare function coerceInt(v: unknown): number | undefined;
37
+ export declare function coerceString(v: unknown): string;
38
+ export declare function coerceOptionalString(v: unknown): string | undefined;
39
+ export declare function dispatchTool(store: FriendStore, name: string, args: Args, grants?: GrantStore, missions?: MissionStore, audit?: AuditSink, controlContext?: ControlPlaneContext): Promise<DispatchResult>;
40
+ export {};
@@ -0,0 +1,549 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.coerceBool = coerceBool;
4
+ exports.coerceInt = coerceInt;
5
+ exports.coerceString = coerceString;
6
+ exports.coerceOptionalString = coerceOptionalString;
7
+ exports.dispatchTool = dispatchTool;
8
+ // Tool dispatch for the friends MCP server.
9
+ //
10
+ // MCP sends string-ish args; the coercion helpers normalize them before calling
11
+ // the library fns. `dispatchTool` is a flat tool → library-fn map (D9/D10) with
12
+ // NO domain logic of its own — every behavior lives in the friends library.
13
+ const observability_1 = require("../observability");
14
+ const identity_1 = require("../identity");
15
+ const types_1 = require("../types");
16
+ const resolver_1 = require("../resolver");
17
+ const trust_explanation_1 = require("../trust-explanation");
18
+ const standing_1 = require("../standing");
19
+ const channel_1 = require("../channel");
20
+ const group_context_1 = require("../group-context");
21
+ const tokens_1 = require("../tokens");
22
+ const notes_1 = require("../notes");
23
+ const trust_mutation_1 = require("../trust-mutation");
24
+ const link_identity_1 = require("../link-identity");
25
+ const agent_peer_1 = require("../agent-peer");
26
+ const outcomes_1 = require("../outcomes");
27
+ const whoami_1 = require("../whoami");
28
+ const room_1 = require("../room");
29
+ const share_1 = require("../share");
30
+ const grants_1 = require("../grants");
31
+ const missions_1 = require("../missions");
32
+ const mission_share_1 = require("../mission-share");
33
+ const coordination_1 = require("../coordination");
34
+ const types_2 = require("../types");
35
+ const connect_1 = require("../connect");
36
+ const mission_result_1 = require("../mission-result");
37
+ /** SECURITY (finding 3-A): the friends MCP server speaks JSON-RPC over **stdio**, and
38
+ * stdio is an owner-only channel — the local user who launched the process is the only
39
+ * actor. So when no explicit controlContext is wired, audited mutations are attributed
40
+ * to the stdio owner boundary rather than the generic "unknown". A network/multi-tenant
41
+ * transport MUST pass its own authenticated actor instead of relying on these. */
42
+ const STDIO_OWNER_ACTOR = "owner:stdio";
43
+ const STDIO_ORIGIN_SENSE = "stdio";
44
+ /** Whether wiring an AuditSink should also stamp a record for an `onboard_agent` trust
45
+ * seat: only when the owner explicitly set a trustLevel (a deliberate trust decision).
46
+ * A cold contact with no trustLevel lands at the safe `stranger` default (Bug A) and is
47
+ * NOT an owner trust mutation, so it is not audited. */
48
+ function coerceBool(v) {
49
+ return v === true || v === "true";
50
+ }
51
+ function coerceInt(v) {
52
+ if (v === undefined || v === null)
53
+ return undefined;
54
+ const n = typeof v === "number" ? v : parseInt(String(v), 10);
55
+ return Number.isNaN(n) ? undefined : n;
56
+ }
57
+ function coerceString(v) {
58
+ return typeof v === "string" ? v : "";
59
+ }
60
+ function coerceOptionalString(v) {
61
+ return typeof v === "string" ? v : undefined;
62
+ }
63
+ /** Parse a value that may be a JSON-string-encoded object/array. Returns
64
+ * undefined when the value is absent or the string fails to parse (guarded). */
65
+ function parseMaybeJson(v) {
66
+ if (v === undefined || v === null)
67
+ return undefined;
68
+ if (typeof v === "string") {
69
+ try {
70
+ return JSON.parse(v);
71
+ }
72
+ catch {
73
+ return undefined;
74
+ }
75
+ }
76
+ return v;
77
+ }
78
+ /** A grant-backed tool was called without a GrantStore wired (a store-only
79
+ * embedding). The consent surface needs grant persistence, so report it cleanly
80
+ * rather than guessing. */
81
+ const NO_GRANT_STORE = { ok: false, status: "unsupported", message: "no grant store configured (consent/share tools require one)" };
82
+ /** A mission-backed tool was called without a MissionStore wired (a store-only
83
+ * embedding). The mission ledger needs mission persistence, so report it cleanly
84
+ * rather than guessing. */
85
+ const NO_MISSION_STORE = { ok: false, status: "unsupported", message: "no mission store configured (mission tools require one)" };
86
+ async function dispatchTool(store, name, args, grants, missions, audit, controlContext) {
87
+ (0, observability_1.emitNervesEvent)({
88
+ component: "clients",
89
+ event: "clients.mcp_dispatch",
90
+ message: "dispatching friends mcp tool",
91
+ meta: { tool: name },
92
+ });
93
+ // SECURITY (finding 3 / 3-A): resolve the WHO/WHENCE for an audited mutation. With
94
+ // no explicit context, attribute to the stdio owner boundary (the only actor on an
95
+ // owner-only stdio channel) rather than the generic "unknown".
96
+ const auditActor = controlContext?.actor ?? STDIO_OWNER_ACTOR;
97
+ const auditOriginSense = controlContext?.originSense ?? STDIO_ORIGIN_SENSE;
98
+ switch (name) {
99
+ case "resolve_party": {
100
+ const provider = coerceString(args.provider);
101
+ const externalId = coerceString(args.externalId);
102
+ const tenantId = coerceOptionalString(args.tenantId);
103
+ const displayName = coerceString(args.displayName) || "Unknown";
104
+ const channel = coerceString(args.channel);
105
+ const existing = await store.findByExternalId(provider, externalId, tenantId);
106
+ const created = existing === null;
107
+ const resolved = await new resolver_1.FriendResolver(store, { provider, externalId, tenantId, displayName, channel }).resolve();
108
+ return { result: { friend: resolved.friend, channel: resolved.channel, created }, isError: false };
109
+ }
110
+ case "describe_trust": {
111
+ const friend = await store.get(coerceString(args.friendId));
112
+ if (!friend) {
113
+ return { result: { ok: false, status: "not_found", message: "friend record not found" }, isError: true };
114
+ }
115
+ const explanation = (0, trust_explanation_1.describeTrustContext)({
116
+ friend,
117
+ channel: coerceString(args.channel),
118
+ isGroupChat: coerceBool(args.isGroupChat),
119
+ });
120
+ return { result: explanation, isError: false };
121
+ }
122
+ case "assess_standing": {
123
+ // Pure read mirroring describe_trust: resolve the record, run the store-free
124
+ // assessment, return the value. No rule injected at the boundary — the tool
125
+ // uses DEFAULT_STANDING_RULE via the fn's `rule ?? DEFAULT` fallback. Never
126
+ // writes trust; never produces a wire artifact.
127
+ const friend = await store.get(coerceString(args.friendId));
128
+ if (!friend) {
129
+ return { result: { ok: false, status: "not_found", message: "friend record not found" }, isError: true };
130
+ }
131
+ return { result: (0, standing_1.assessStanding)(friend), isError: false };
132
+ }
133
+ case "explain_standing": {
134
+ const friend = await store.get(coerceString(args.friendId));
135
+ if (!friend) {
136
+ return { result: { ok: false, status: "not_found", message: "friend record not found" }, isError: true };
137
+ }
138
+ return { result: (0, standing_1.explainStanding)(friend), isError: false };
139
+ }
140
+ case "get_friend": {
141
+ const friend = await store.get(coerceString(args.friendId));
142
+ if (!friend) {
143
+ return { result: { ok: false, status: "not_found", message: "friend record not found" }, isError: true };
144
+ }
145
+ return { result: friend, isError: false };
146
+ }
147
+ case "list_friends": {
148
+ const all = typeof store.listAll === "function" ? await store.listAll() : [];
149
+ const trust = coerceOptionalString(args.trust);
150
+ const kind = coerceOptionalString(args.kind);
151
+ const limit = coerceInt(args.limit);
152
+ let filtered = all;
153
+ if (trust !== undefined)
154
+ filtered = filtered.filter((f) => f.trustLevel === trust);
155
+ if (kind !== undefined)
156
+ filtered = filtered.filter((f) => f.kind === kind);
157
+ if (limit !== undefined)
158
+ filtered = filtered.slice(0, limit);
159
+ return { result: filtered, isError: false };
160
+ }
161
+ case "save_note": {
162
+ const type = coerceString(args.type);
163
+ // The library helper takes a typed `type` union; the MCP boundary validates
164
+ // the raw string here so an unknown type is a clean `invalid` result
165
+ // rather than garbage written under an undefined key.
166
+ if (type !== "name" && type !== "tool_preference" && type !== "note") {
167
+ return {
168
+ result: { ok: false, status: "invalid", message: `unrecognized note type '${type}' — use name, tool_preference, or note` },
169
+ isError: true,
170
+ };
171
+ }
172
+ const result = await (0, notes_1.applyFriendNote)(store, coerceString(args.friendId), {
173
+ type,
174
+ key: coerceOptionalString(args.key),
175
+ content: coerceString(args.content),
176
+ override: coerceBool(args.override),
177
+ provenance: parseMaybeJson(args.provenance),
178
+ });
179
+ return { result, isError: result.ok === false };
180
+ }
181
+ case "record_interaction": {
182
+ const friendId = coerceString(args.friendId);
183
+ const usage = parseMaybeJson(args.usage);
184
+ const outcome = parseMaybeJson(args.outcome);
185
+ const familiarityDelta = coerceInt(args.familiarityDelta);
186
+ const provenance = parseMaybeJson(args.provenance);
187
+ if (usage === undefined && outcome === undefined) {
188
+ return { result: { ok: true, status: "noop", message: "no usage or outcome provided" }, isError: false };
189
+ }
190
+ const combined = {};
191
+ if (usage !== undefined) {
192
+ await (0, tokens_1.accumulateFriendTokens)(store, friendId, usage);
193
+ combined.tokensAccumulated = true;
194
+ }
195
+ if (outcome !== undefined) {
196
+ combined.outcome = await (0, outcomes_1.recordRelationshipOutcome)(store, friendId, { missionId: outcome.missionId, result: outcome.result, note: outcome.note, provenance: outcome.provenance ?? provenance }, familiarityDelta);
197
+ }
198
+ return { result: combined, isError: false };
199
+ }
200
+ case "upsert_group": {
201
+ const participants = parseMaybeJson(args.participants) ?? [];
202
+ const results = await (0, group_context_1.upsertGroupContextParticipants)({
203
+ store,
204
+ participants,
205
+ groupExternalId: coerceString(args.groupExternalId),
206
+ });
207
+ return { result: results, isError: false };
208
+ }
209
+ case "set_trust": {
210
+ // SECURITY (finding 3): thread the audit sink + owner/sense context so the LIVE
211
+ // trust mutation actually writes a control-plane record. With no sink wired,
212
+ // setFriendTrust treats the ctx as a no-op (back-compat).
213
+ const result = await (0, trust_mutation_1.setFriendTrust)(store, coerceString(args.friendId), coerceString(args.trustLevel), {
214
+ ...(audit ? { sink: audit } : {}),
215
+ actor: auditActor,
216
+ originSense: auditOriginSense,
217
+ });
218
+ return { result, isError: result.ok === false };
219
+ }
220
+ case "link_identity": {
221
+ const result = await (0, link_identity_1.linkExternalId)(store, coerceString(args.friendId), {
222
+ provider: coerceString(args.provider),
223
+ externalId: coerceString(args.externalId),
224
+ tenantId: coerceOptionalString(args.tenantId),
225
+ });
226
+ return { result, isError: result.ok === false };
227
+ }
228
+ case "unlink_identity": {
229
+ const result = await (0, link_identity_1.unlinkExternalId)(store, coerceString(args.friendId), {
230
+ provider: coerceString(args.provider),
231
+ externalId: coerceString(args.externalId),
232
+ });
233
+ return { result, isError: result.ok === false };
234
+ }
235
+ case "onboard_agent": {
236
+ const explicitTrustLevel = coerceOptionalString(args.trustLevel);
237
+ const record = await (0, agent_peer_1.upsertAgentPeer)(store, {
238
+ name: coerceString(args.name),
239
+ agentId: coerceString(args.agentId),
240
+ trustLevel: explicitTrustLevel,
241
+ a2a: parseMaybeJson(args.a2a),
242
+ mailbox: parseMaybeJson(args.mailbox),
243
+ bundleName: coerceOptionalString(args.bundleName),
244
+ });
245
+ // SECURITY (finding 3): an owner-initiated trust SEAT (an explicit trustLevel) is
246
+ // a control-plane trust mutation, so audit it through the wired sink. A cold
247
+ // contact with no trustLevel falls to the safe `stranger` default (Bug A) — not
248
+ // an owner trust decision — so it is left unaudited.
249
+ if (audit && explicitTrustLevel !== undefined) {
250
+ const targetDid = (0, identity_1.resolveAgentIdentity)(record.agentMeta).did;
251
+ const auditRecord = {
252
+ action: "set_trust",
253
+ targetId: record.id,
254
+ ...(targetDid !== undefined ? { targetDid } : {}),
255
+ // The level the record actually holds: a pending DID reset ignores the request.
256
+ level: record.trustLevel,
257
+ actor: auditActor,
258
+ originSense: auditOriginSense,
259
+ ts: record.updatedAt,
260
+ };
261
+ await audit.append(auditRecord);
262
+ }
263
+ if (record.trustRaiseIgnored) {
264
+ return {
265
+ result: {
266
+ ...record,
267
+ note: "The requested trust level was ignored because this peer's DID changed and its trust was reset. Use set_trust to raise it.",
268
+ },
269
+ isError: false,
270
+ };
271
+ }
272
+ return { result: record, isError: false };
273
+ }
274
+ case "connect_to": {
275
+ // The management-sense control plane (p11 inc2, brick 8). The boundary stays
276
+ // thin — coerce the peer handles + level, resolve the gate's management sense
277
+ // (the stdio path is owner-only ⇒ `local`), and forward to the library, which
278
+ // owns the authority gate + disambiguation + introduce + audit. `isError` reflects
279
+ // ok===false (a `downgraded` / `needs_handle_or_introduction` result is an error
280
+ // result like the other mutation cases).
281
+ const result = await (0, connect_1.connectAgents)(store, {
282
+ peer: {
283
+ agentId: coerceOptionalString(args.agentId),
284
+ did: coerceOptionalString(args.did),
285
+ name: coerceOptionalString(args.name),
286
+ },
287
+ // The stdio default is `local` (owner-only); a network transport supplies its
288
+ // real senseType via controlContext. The proof's stdio path commits.
289
+ senseType: controlContext?.senseType ?? "local",
290
+ ...(controlContext?.membership ? { membership: controlContext.membership } : {}),
291
+ trustLevel: coerceOptionalString(args.trustLevel),
292
+ }, {
293
+ ...(audit ? { audit } : {}),
294
+ actor: auditActor,
295
+ originSense: auditOriginSense,
296
+ });
297
+ return { result, isError: result.ok === false };
298
+ }
299
+ case "whoami": {
300
+ return { result: await (0, whoami_1.whoami)(store), isError: false };
301
+ }
302
+ case "channel_caps": {
303
+ return { result: (0, channel_1.getChannelCapabilities)(coerceString(args.channel)), isError: false };
304
+ }
305
+ case "resolve_room": {
306
+ const view = await (0, room_1.resolveRoom)(store, coerceString(args.groupExternalId), (coerceOptionalString(args.channel) ?? "mcp"));
307
+ return { result: view, isError: false };
308
+ }
309
+ case "share_profile": {
310
+ // De-stubbed producer. Self identity comes from whoami (the dispatch is
311
+ // store-only); the subject is named by join key inside the library.
312
+ if (!grants)
313
+ return { result: NO_GRANT_STORE, isError: true };
314
+ const scope = coerceString(args.scope);
315
+ if (!(0, types_1.isShareScope)(scope)) {
316
+ return {
317
+ result: { ok: false, status: "invalid", message: `unrecognized scope '${scope}' — use name, identity, notes:safe, notes:all, or outcomes` },
318
+ isError: true,
319
+ };
320
+ }
321
+ const self = await (0, whoami_1.whoami)(store);
322
+ // whoami sets selfFriendId + selfAgentName together or neither; the local
323
+ // self id (selfFriendId) is the asserter tag. "" when there is no self yet.
324
+ const selfAgentId = self.selfFriendId ?? "";
325
+ const result = await (0, share_1.prepareProfileShare)(store, grants, {
326
+ friendId: coerceString(args.friendId),
327
+ toAgentId: coerceString(args.toAgentId),
328
+ scope: scope,
329
+ selfAgentId,
330
+ proof: coerceOptionalString(args.proof),
331
+ });
332
+ return { result, isError: result.ok === false };
333
+ }
334
+ case "import_profile": {
335
+ const envelope = parseMaybeJson(args.envelope);
336
+ if (!envelope || typeof envelope !== "object") {
337
+ return { result: { ok: false, status: "invalid", message: "an envelope object is required" }, isError: true };
338
+ }
339
+ const result = await (0, share_1.importProfileShare)(store, {
340
+ envelope,
341
+ fromAgentId: coerceString(args.fromAgentId),
342
+ trustOfSource: coerceString(args.trustOfSource),
343
+ });
344
+ return { result, isError: result.ok === false };
345
+ }
346
+ case "grant_share": {
347
+ if (!grants)
348
+ return { result: NO_GRANT_STORE, isError: true };
349
+ const scope = coerceString(args.scope);
350
+ if (!(0, types_1.isShareScope)(scope)) {
351
+ return {
352
+ result: { ok: false, status: "invalid", message: `unrecognized scope '${scope}' — use name, identity, notes:safe, notes:all, or outcomes` },
353
+ isError: true,
354
+ };
355
+ }
356
+ // Fork D compat seam (b): accept the new `subjectKey` arg, falling back to
357
+ // the legacy `subjectFriendId` so old-arg callers (incl. the unmodified
358
+ // examples) keep working. coerceString gives "" when an arg is absent, so
359
+ // `||` selects subjectKey when present, else subjectFriendId.
360
+ const grant = await (0, grants_1.grantShare)(grants, {
361
+ subjectKey: coerceString(args.subjectKey) || coerceString(args.subjectFriendId),
362
+ recipientAgentId: coerceString(args.recipientAgentId),
363
+ scope: scope,
364
+ expiresAt: coerceOptionalString(args.expiresAt),
365
+ });
366
+ return { result: grant, isError: false };
367
+ }
368
+ case "revoke_share": {
369
+ if (!grants)
370
+ return { result: NO_GRANT_STORE, isError: true };
371
+ const result = await (0, grants_1.revokeShare)(grants, coerceString(args.grantId));
372
+ return { result, isError: result.ok === false };
373
+ }
374
+ case "list_shares": {
375
+ if (!grants)
376
+ return { result: NO_GRANT_STORE, isError: true };
377
+ // Fork D compat seam (b): accept `subjectKey`, falling back to the legacy
378
+ // `subjectFriendId` filter arg.
379
+ const result = await (0, grants_1.listShares)(grants, {
380
+ subjectKey: coerceOptionalString(args.subjectKey) ?? coerceOptionalString(args.subjectFriendId),
381
+ recipientAgentId: coerceOptionalString(args.recipientAgentId),
382
+ effectiveOnly: coerceBool(args.effectiveOnly),
383
+ });
384
+ return { result, isError: false };
385
+ }
386
+ case "record_mission": {
387
+ if (!missions)
388
+ return { result: NO_MISSION_STORE, isError: true };
389
+ const input = {
390
+ missionKey: coerceString(args.missionKey),
391
+ title: coerceOptionalString(args.title),
392
+ status: coerceOptionalString(args.status),
393
+ participants: parseMaybeJson(args.participants),
394
+ learnings: parseMaybeJson(args.learnings),
395
+ outcomes: parseMaybeJson(args.outcomes),
396
+ };
397
+ const record = await (0, missions_1.recordMission)(missions, input);
398
+ return { result: record, isError: false };
399
+ }
400
+ case "get_mission": {
401
+ if (!missions)
402
+ return { result: NO_MISSION_STORE, isError: true };
403
+ const record = await missions.get(coerceString(args.missionId));
404
+ if (!record) {
405
+ return { result: { ok: false, status: "not_found", message: "mission record not found" }, isError: true };
406
+ }
407
+ return { result: record, isError: false };
408
+ }
409
+ case "list_missions": {
410
+ if (!missions)
411
+ return { result: NO_MISSION_STORE, isError: true };
412
+ const all = await missions.listAll();
413
+ const limit = coerceInt(args.limit);
414
+ const result = limit !== undefined ? all.slice(0, limit) : all;
415
+ return { result, isError: false };
416
+ }
417
+ case "share_mission": {
418
+ // Producer. Self identity comes from whoami (the dispatch is store-only);
419
+ // the mission is named by its missionKey inside the library. Gated on BOTH a
420
+ // GrantStore (consent) and a MissionStore.
421
+ if (!missions || !grants)
422
+ return { result: NO_MISSION_STORE, isError: true };
423
+ const scope = coerceString(args.scope);
424
+ if (scope !== "mission" && scope !== "outcomes") {
425
+ return {
426
+ result: { ok: false, status: "invalid", message: `unrecognized mission scope '${scope}' — use mission or outcomes` },
427
+ isError: true,
428
+ };
429
+ }
430
+ const self = await (0, whoami_1.whoami)(store);
431
+ const selfAgentId = self.selfFriendId ?? "";
432
+ const result = await (0, mission_share_1.prepareMissionShare)(missions, store, grants, {
433
+ missionId: coerceString(args.missionId),
434
+ toAgentId: coerceString(args.toAgentId),
435
+ scope,
436
+ selfAgentId,
437
+ proof: coerceOptionalString(args.proof),
438
+ });
439
+ return { result, isError: result.ok === false };
440
+ }
441
+ case "import_mission": {
442
+ if (!missions)
443
+ return { result: NO_MISSION_STORE, isError: true };
444
+ const envelope = parseMaybeJson(args.envelope);
445
+ if (!envelope || typeof envelope !== "object") {
446
+ return { result: { ok: false, status: "invalid", message: "an envelope object is required" }, isError: true };
447
+ }
448
+ const result = await (0, mission_share_1.importMissionShare)(missions, {
449
+ envelope,
450
+ fromAgentId: coerceString(args.fromAgentId),
451
+ trustOfSource: coerceString(args.trustOfSource),
452
+ });
453
+ return { result, isError: result.ok === false };
454
+ }
455
+ case "coordinate": {
456
+ // Producer (brick 5). Self identity comes from whoami (the dispatch is
457
+ // store-only); the mission is named by its missionKey inside the library.
458
+ // Gated on BOTH a GrantStore (consent via the "coordinate" scope) and a
459
+ // MissionStore — like share_mission.
460
+ if (!missions || !grants)
461
+ return { result: NO_MISSION_STORE, isError: true };
462
+ const intent = coerceString(args.intent);
463
+ if (!(0, types_2.isCoordinationIntent)(intent)) {
464
+ return {
465
+ result: { ok: false, status: "invalid", message: `unrecognized coordination intent '${intent}' — use request, offer, accept, decline, or handoff` },
466
+ isError: true,
467
+ };
468
+ }
469
+ const self = await (0, whoami_1.whoami)(store);
470
+ const selfAgentId = self.selfFriendId ?? "";
471
+ const result = await (0, coordination_1.prepareCoordination)(missions, store, grants, {
472
+ missionId: coerceString(args.missionId),
473
+ toAgentId: coerceString(args.toAgentId),
474
+ intent,
475
+ note: coerceOptionalString(args.note),
476
+ proposedAssignee: parseMaybeJson(args.proposedAssignee),
477
+ selfAgentId,
478
+ // gap-1 (p11 inc2): an optional task-spec, meaningful only on a `request`. The
479
+ // library mints the requestId + records the delegation first-party.
480
+ task: parseMaybeJson(args.task),
481
+ proof: coerceOptionalString(args.proof),
482
+ });
483
+ return { result, isError: result.ok === false };
484
+ }
485
+ case "import_coordination": {
486
+ if (!missions)
487
+ return { result: NO_MISSION_STORE, isError: true };
488
+ const envelope = parseMaybeJson(args.envelope);
489
+ if (!envelope || typeof envelope !== "object") {
490
+ return { result: { ok: false, status: "invalid", message: "an envelope object is required" }, isError: true };
491
+ }
492
+ const result = await (0, coordination_1.importCoordination)(missions, {
493
+ envelope,
494
+ fromAgentId: coerceString(args.fromAgentId),
495
+ trustOfSource: coerceString(args.trustOfSource),
496
+ });
497
+ return { result, isError: result.ok === false };
498
+ }
499
+ case "get_coordination": {
500
+ // Read lens (brick 5), like get_mission: return the mission's coordination
501
+ // sub-object (assignee + log), or the empty default when unset.
502
+ if (!missions)
503
+ return { result: NO_MISSION_STORE, isError: true };
504
+ const record = await missions.get(coerceString(args.missionId));
505
+ if (!record) {
506
+ return { result: { ok: false, status: "not_found", message: "mission record not found" }, isError: true };
507
+ }
508
+ return { result: record.coordination ?? { assignee: undefined, log: [] }, isError: false };
509
+ }
510
+ case "send_result": {
511
+ // Producer (gap-2): B returns its deliverable. Self identity comes from whoami
512
+ // (the dispatch is store-only); the mission is named by its missionKey inside the
513
+ // library. Gated on BOTH a GrantStore (consent via the "coordinate" scope) and a
514
+ // MissionStore — exactly like share_mission.
515
+ if (!missions || !grants)
516
+ return { result: NO_MISSION_STORE, isError: true };
517
+ const self = await (0, whoami_1.whoami)(store);
518
+ const selfAgentId = self.selfFriendId ?? "";
519
+ const result = await (0, mission_result_1.prepareMissionResult)(missions, store, grants, {
520
+ missionId: coerceString(args.missionId),
521
+ toAgentId: coerceString(args.toAgentId),
522
+ requestId: coerceString(args.requestId),
523
+ result: parseMaybeJson(args.result) ?? { summary: "" },
524
+ selfAgentId,
525
+ proof: coerceOptionalString(args.proof),
526
+ });
527
+ return { result, isError: result.ok === false };
528
+ }
529
+ case "import_result": {
530
+ // Consumer (gap-2): A imports B's deliverable. Gated on the MissionStore, like
531
+ // import_mission. An invalid/malformed envelope is a clean `invalid` result.
532
+ if (!missions)
533
+ return { result: NO_MISSION_STORE, isError: true };
534
+ const envelope = parseMaybeJson(args.envelope);
535
+ if (!envelope || typeof envelope !== "object") {
536
+ return { result: { ok: false, status: "invalid", message: "an envelope object is required" }, isError: true };
537
+ }
538
+ const result = await (0, mission_result_1.importMissionResult)(missions, {
539
+ envelope,
540
+ fromAgentId: coerceString(args.fromAgentId),
541
+ trustOfSource: coerceString(args.trustOfSource),
542
+ });
543
+ return { result, isError: result.ok === false };
544
+ }
545
+ default: {
546
+ return { result: { error: `Unknown tool: ${name}` }, isError: true };
547
+ }
548
+ }
549
+ }
@@ -0,0 +1,6 @@
1
+ export { createFriendsMcpServer } from "./server";
2
+ export type { FriendsMcpServer, FriendsMcpServerOptions } from "./server";
3
+ export { getToolSchemas } from "./schemas";
4
+ export type { McpToolSchema } from "./schemas";
5
+ export { runMain } from "./run-main";
6
+ export type { RunMainIo } from "./run-main";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runMain = exports.getToolSchemas = exports.createFriendsMcpServer = void 0;
4
+ // @ouro.bot/friends/mcp — the MCP server surface.
5
+ //
6
+ // A thin, harness-agnostic MCP tool surface over the friends library: dual
7
+ // stdio framing, a flat tool → library-fn dispatch, and NO agent turn. Consumed
8
+ // via the `friends-mcp` bin or embedded directly through `createFriendsMcpServer`.
9
+ var server_1 = require("./server");
10
+ Object.defineProperty(exports, "createFriendsMcpServer", { enumerable: true, get: function () { return server_1.createFriendsMcpServer; } });
11
+ var schemas_1 = require("./schemas");
12
+ Object.defineProperty(exports, "getToolSchemas", { enumerable: true, get: function () { return schemas_1.getToolSchemas; } });
13
+ var run_main_1 = require("./run-main");
14
+ Object.defineProperty(exports, "runMain", { enumerable: true, get: function () { return run_main_1.runMain; } });
@@ -0,0 +1,7 @@
1
+ import type { FriendsMcpServer } from "./server";
2
+ export interface RunMainIo {
3
+ stdin: NodeJS.ReadableStream;
4
+ stdout: NodeJS.WritableStream;
5
+ onError: (message: string) => void;
6
+ }
7
+ export declare function runMain(argv: string[], env: NodeJS.ProcessEnv, io: RunMainIo): FriendsMcpServer | null;