@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.
- package/changelog.json +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/a2a/approval-relay.js +95 -0
- package/dist/a2a/refusals.js +2 -0
- package/dist/heart/approval-store.js +44 -1
- package/node_modules/@ouro.bot/friends/README.md +17 -4
- package/node_modules/@ouro.bot/friends/actions/generated/mcp.json +1105 -0
- package/node_modules/@ouro.bot/friends/changelog.json +72 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/adapter.d.ts +1 -1
- package/node_modules/@ouro.bot/friends/dist/a2a-client/envelope-binding.d.ts +2 -2
- package/node_modules/@ouro.bot/friends/dist/a2a-client/envelope-binding.js +12 -8
- package/node_modules/@ouro.bot/friends/dist/channel.d.ts +5 -0
- package/node_modules/@ouro.bot/friends/dist/channel.js +12 -1
- package/node_modules/@ouro.bot/friends/dist/connect.js +8 -8
- package/node_modules/@ouro.bot/friends/dist/grant-store-file.d.ts +3 -0
- package/node_modules/@ouro.bot/friends/dist/grant-store-file.js +30 -9
- package/node_modules/@ouro.bot/friends/dist/grants.d.ts +5 -1
- package/node_modules/@ouro.bot/friends/dist/grants.js +22 -6
- package/node_modules/@ouro.bot/friends/dist/index.d.ts +3 -3
- package/node_modules/@ouro.bot/friends/dist/index.js +5 -2
- package/node_modules/@ouro.bot/friends/dist/link-identity.js +9 -9
- package/node_modules/@ouro.bot/friends/dist/mcp/bin.js +2 -1
- package/node_modules/@ouro.bot/friends/dist/mcp/dispatch.js +211 -16
- package/node_modules/@ouro.bot/friends/dist/mcp/run-main.js +24 -13
- package/node_modules/@ouro.bot/friends/dist/mcp/schemas.js +9 -431
- package/node_modules/@ouro.bot/friends/dist/mcp/server.js +2 -1
- package/node_modules/@ouro.bot/friends/dist/message.d.ts +19 -1
- package/node_modules/@ouro.bot/friends/dist/message.js +31 -1
- package/node_modules/@ouro.bot/friends/dist/mission-result.d.ts +7 -0
- package/node_modules/@ouro.bot/friends/dist/mission-result.js +14 -7
- package/node_modules/@ouro.bot/friends/dist/mission-store-file.js +8 -0
- package/node_modules/@ouro.bot/friends/dist/missions.js +6 -5
- package/node_modules/@ouro.bot/friends/dist/notes.js +4 -4
- package/node_modules/@ouro.bot/friends/dist/outcomes.js +1 -1
- package/node_modules/@ouro.bot/friends/dist/share.d.ts +6 -1
- package/node_modules/@ouro.bot/friends/dist/share.js +40 -4
- package/node_modules/@ouro.bot/friends/dist/store-file.js +28 -13
- package/node_modules/@ouro.bot/friends/dist/tokens.d.ts +3 -1
- package/node_modules/@ouro.bot/friends/dist/tokens.js +5 -2
- package/node_modules/@ouro.bot/friends/dist/trust-mutation.js +2 -2
- package/node_modules/@ouro.bot/friends/dist/types.d.ts +12 -0
- package/node_modules/@ouro.bot/friends/dist/util/safe-id.d.ts +1 -0
- package/node_modules/@ouro.bot/friends/dist/util/safe-id.js +10 -0
- package/node_modules/@ouro.bot/friends/package.json +2 -1
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
|
@@ -75,6 +75,78 @@ function parseMaybeJson(v) {
|
|
|
75
75
|
}
|
|
76
76
|
return v;
|
|
77
77
|
}
|
|
78
|
+
/** Whether an envelope's subject has the shape the import reads: an object whose externalIds is a list of
|
|
79
|
+
* { provider, externalId } strings. Anything else answers invalid rather than throwing mid-import (#222). */
|
|
80
|
+
function isProfileShareSubject(subject) {
|
|
81
|
+
if (!subject || typeof subject !== "object")
|
|
82
|
+
return false;
|
|
83
|
+
const externalIds = subject.externalIds;
|
|
84
|
+
return Array.isArray(externalIds) && externalIds.every((ext) => !!ext && typeof ext === "object" &&
|
|
85
|
+
typeof ext.provider === "string" &&
|
|
86
|
+
typeof ext.externalId === "string");
|
|
87
|
+
}
|
|
88
|
+
/** Whether an envelope's notes, when present, are a list of { key, value } strings, and its outcomes, when present, a
|
|
89
|
+
* list (an outcome that isn't well formed is skipped on import). */
|
|
90
|
+
function isSharedPayload(envelope) {
|
|
91
|
+
const notesOk = envelope.notes === undefined || (Array.isArray(envelope.notes) && envelope.notes.every((note) => !!note && typeof note === "object" &&
|
|
92
|
+
typeof note.key === "string" && note.key !== "__proto__" &&
|
|
93
|
+
typeof note.value === "string"));
|
|
94
|
+
return notesOk && (envelope.outcomes === undefined || Array.isArray(envelope.outcomes));
|
|
95
|
+
}
|
|
96
|
+
const IDENTITY_PROVIDER_LIST = "aad, local, teams-conversation, imessage-handle, email-address, a2a-agent or telegram-user";
|
|
97
|
+
const MISSION_STATUSES = new Set(["active", "succeeded", "partial", "failed", "abandoned"]);
|
|
98
|
+
const INVALID_LIST = Symbol("invalid list");
|
|
99
|
+
/** A list argument, given as a list or as its JSON text: undefined when absent, INVALID_LIST when it isn't a list of
|
|
100
|
+
* items that pass `ok`. */
|
|
101
|
+
function listArg(v, ok) {
|
|
102
|
+
if (v === undefined || v === null)
|
|
103
|
+
return undefined;
|
|
104
|
+
let list = v;
|
|
105
|
+
if (typeof v === "string") {
|
|
106
|
+
try {
|
|
107
|
+
list = JSON.parse(v);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return INVALID_LIST;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return Array.isArray(list) && list.every(ok) ? list : INVALID_LIST;
|
|
114
|
+
}
|
|
115
|
+
const isRecord = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
116
|
+
const isParticipant = (v) => isRecord(v) && (v.agentId === undefined || typeof v.agentId === "string") && (v.agentName === undefined || typeof v.agentName === "string") &&
|
|
117
|
+
(!!v.agentId || !!v.agentName);
|
|
118
|
+
const isSharedLearning = (v) => isRecord(v) && typeof v.key === "string" && v.key !== "" && v.key !== "__proto__" && typeof v.value === "string";
|
|
119
|
+
const isLearningInput = (v) => isSharedLearning(v) &&
|
|
120
|
+
(v.shareable === undefined || typeof v.shareable === "boolean");
|
|
121
|
+
/** Whether a mission envelope names its mission: a subject whose missionKey is a non-empty string. */
|
|
122
|
+
function hasMissionSubject(envelope) {
|
|
123
|
+
return isRecord(envelope.subject) && typeof envelope.subject.missionKey === "string" && envelope.subject.missionKey !== "";
|
|
124
|
+
}
|
|
125
|
+
const TRUST_LEVELS = new Set(["family", "friend", "acquaintance", "stranger"]);
|
|
126
|
+
/** The answer for a trust level friends doesn't know. The store would save such a level as its default, friend, so
|
|
127
|
+
* the tools refuse it rather than report one level and keep another (#217). */
|
|
128
|
+
function invalidTrustLevel(level) {
|
|
129
|
+
return {
|
|
130
|
+
result: { ok: false, status: "invalid", message: `unrecognized trust level '${level}': use family, friend, acquaintance or stranger` },
|
|
131
|
+
isError: true,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** Usage record_interaction can count: an object whose output_tokens is a whole number of 0 or more. */
|
|
135
|
+
function isUsage(usage) {
|
|
136
|
+
if (!usage || typeof usage !== "object" || Array.isArray(usage))
|
|
137
|
+
return false;
|
|
138
|
+
const tokens = usage.output_tokens;
|
|
139
|
+
return typeof tokens === "number" && Number.isSafeInteger(tokens) && tokens >= 0;
|
|
140
|
+
}
|
|
141
|
+
/** An outcome record_interaction can save: a non-empty missionId, a result of success, partial or failed, and a note
|
|
142
|
+
* that is text when given. */
|
|
143
|
+
function isOutcomeInput(outcome) {
|
|
144
|
+
if (!outcome || typeof outcome !== "object" || Array.isArray(outcome))
|
|
145
|
+
return false;
|
|
146
|
+
const { missionId, result, note } = outcome;
|
|
147
|
+
return typeof missionId === "string" && missionId.length > 0 && (result === "success" || result === "partial" || result === "failed") &&
|
|
148
|
+
(note === undefined || typeof note === "string");
|
|
149
|
+
}
|
|
78
150
|
/** A grant-backed tool was called without a GrantStore wired (a store-only
|
|
79
151
|
* embedding). The consent surface needs grant persistence, so report it cleanly
|
|
80
152
|
* rather than guessing. */
|
|
@@ -179,21 +251,44 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
179
251
|
return { result, isError: result.ok === false };
|
|
180
252
|
}
|
|
181
253
|
case "record_interaction": {
|
|
182
|
-
const friendId = coerceString(args.friendId);
|
|
183
254
|
const usage = parseMaybeJson(args.usage);
|
|
184
255
|
const outcome = parseMaybeJson(args.outcome);
|
|
185
256
|
const familiarityDelta = coerceInt(args.familiarityDelta);
|
|
186
257
|
const provenance = parseMaybeJson(args.provenance);
|
|
187
|
-
if (usage === undefined && outcome === undefined) {
|
|
258
|
+
if (args.usage === undefined && args.outcome === undefined) {
|
|
188
259
|
return { result: { ok: true, status: "noop", message: "no usage or outcome provided" }, isError: false };
|
|
189
260
|
}
|
|
190
|
-
|
|
261
|
+
// Bad input answers invalid before anything is saved, rather than reading as success (#214).
|
|
262
|
+
if (args.usage !== undefined && !isUsage(usage)) {
|
|
263
|
+
return {
|
|
264
|
+
result: { ok: false, status: "invalid", message: "usage must be an object whose output_tokens is a whole number of 0 or more" },
|
|
265
|
+
isError: true,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (args.outcome !== undefined && !isOutcomeInput(outcome)) {
|
|
269
|
+
return {
|
|
270
|
+
result: { ok: false, status: "invalid", message: "outcome must be an object with a missionId and a result of success, partial or failed" },
|
|
271
|
+
isError: true,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const friend = await store.get(coerceString(args.friendId));
|
|
275
|
+
if (!friend) {
|
|
276
|
+
return { result: { ok: false, status: "not_found", message: "friend record not found" }, isError: true };
|
|
277
|
+
}
|
|
278
|
+
// Only an agent record keeps outcomes; on anyone else the store would drop the outcome it was told to save.
|
|
279
|
+
if (outcome !== undefined && friend.kind !== "agent") {
|
|
280
|
+
return {
|
|
281
|
+
result: { ok: false, status: "invalid", message: "outcomes are kept only on agent records; record this one's usage without an outcome" },
|
|
282
|
+
isError: true,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
// Writes go by the record's own id, so a friend named rather than given by uuid is saved too (#213).
|
|
286
|
+
const combined = { ok: true, status: "recorded" };
|
|
191
287
|
if (usage !== undefined) {
|
|
192
|
-
await (0, tokens_1.accumulateFriendTokens)(store,
|
|
193
|
-
combined.tokensAccumulated = true;
|
|
288
|
+
combined.tokensAccumulated = await (0, tokens_1.accumulateFriendTokens)(store, friend.id, usage);
|
|
194
289
|
}
|
|
195
290
|
if (outcome !== undefined) {
|
|
196
|
-
combined.outcome = await (0, outcomes_1.recordRelationshipOutcome)(store,
|
|
291
|
+
combined.outcome = await (0, outcomes_1.recordRelationshipOutcome)(store, friend.id, { missionId: outcome.missionId, result: outcome.result, note: outcome.note, provenance: outcome.provenance ?? provenance }, familiarityDelta);
|
|
197
292
|
}
|
|
198
293
|
return { result: combined, isError: false };
|
|
199
294
|
}
|
|
@@ -207,10 +302,13 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
207
302
|
return { result: results, isError: false };
|
|
208
303
|
}
|
|
209
304
|
case "set_trust": {
|
|
305
|
+
const trustLevel = coerceString(args.trustLevel);
|
|
306
|
+
if (!TRUST_LEVELS.has(trustLevel))
|
|
307
|
+
return invalidTrustLevel(trustLevel);
|
|
210
308
|
// SECURITY (finding 3): thread the audit sink + owner/sense context so the LIVE
|
|
211
309
|
// trust mutation actually writes a control-plane record. With no sink wired,
|
|
212
310
|
// setFriendTrust treats the ctx as a no-op (back-compat).
|
|
213
|
-
const result = await (0, trust_mutation_1.setFriendTrust)(store, coerceString(args.friendId),
|
|
311
|
+
const result = await (0, trust_mutation_1.setFriendTrust)(store, coerceString(args.friendId), trustLevel, {
|
|
214
312
|
...(audit ? { sink: audit } : {}),
|
|
215
313
|
actor: auditActor,
|
|
216
314
|
originSense: auditOriginSense,
|
|
@@ -218,6 +316,14 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
218
316
|
return { result, isError: result.ok === false };
|
|
219
317
|
}
|
|
220
318
|
case "link_identity": {
|
|
319
|
+
// An empty id would be saved as ["", ""], and one under a provider friends doesn't know is outside the closed
|
|
320
|
+
// provider set the rest of friends checks, yet both answered linked (#218).
|
|
321
|
+
if (!(0, types_1.isIdentityProvider)(args.provider) || coerceString(args.externalId).trim() === "") {
|
|
322
|
+
return {
|
|
323
|
+
result: { ok: false, status: "invalid", message: `link_identity needs an externalId and a provider: one of ${IDENTITY_PROVIDER_LIST}` },
|
|
324
|
+
isError: true,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
221
327
|
const result = await (0, link_identity_1.linkExternalId)(store, coerceString(args.friendId), {
|
|
222
328
|
provider: coerceString(args.provider),
|
|
223
329
|
externalId: coerceString(args.externalId),
|
|
@@ -233,10 +339,17 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
233
339
|
return { result, isError: result.ok === false };
|
|
234
340
|
}
|
|
235
341
|
case "onboard_agent": {
|
|
342
|
+
if (args.trustLevel !== undefined && !TRUST_LEVELS.has(coerceString(args.trustLevel)))
|
|
343
|
+
return invalidTrustLevel(String(args.trustLevel));
|
|
236
344
|
const explicitTrustLevel = coerceOptionalString(args.trustLevel);
|
|
345
|
+
const name = coerceString(args.name).trim();
|
|
346
|
+
const agentId = coerceString(args.agentId).trim();
|
|
347
|
+
if (name === "" || agentId === "") {
|
|
348
|
+
return { result: { ok: false, status: "invalid", message: "onboard_agent needs a name and an agentId" }, isError: true };
|
|
349
|
+
}
|
|
237
350
|
const record = await (0, agent_peer_1.upsertAgentPeer)(store, {
|
|
238
|
-
name
|
|
239
|
-
agentId
|
|
351
|
+
name,
|
|
352
|
+
agentId,
|
|
240
353
|
trustLevel: explicitTrustLevel,
|
|
241
354
|
a2a: parseMaybeJson(args.a2a),
|
|
242
355
|
mailbox: parseMaybeJson(args.mailbox),
|
|
@@ -272,6 +385,9 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
272
385
|
return { result: record, isError: false };
|
|
273
386
|
}
|
|
274
387
|
case "connect_to": {
|
|
388
|
+
if (args.trustLevel !== undefined && !TRUST_LEVELS.has(coerceString(args.trustLevel)))
|
|
389
|
+
return invalidTrustLevel(String(args.trustLevel));
|
|
390
|
+
const connectTrust = coerceOptionalString(args.trustLevel);
|
|
275
391
|
// The management-sense control plane (p11 inc2, brick 8). The boundary stays
|
|
276
392
|
// thin — coerce the peer handles + level, resolve the gate's management sense
|
|
277
393
|
// (the stdio path is owner-only ⇒ `local`), and forward to the library, which
|
|
@@ -288,7 +404,7 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
288
404
|
// real senseType via controlContext. The proof's stdio path commits.
|
|
289
405
|
senseType: controlContext?.senseType ?? "local",
|
|
290
406
|
...(controlContext?.membership ? { membership: controlContext.membership } : {}),
|
|
291
|
-
trustLevel:
|
|
407
|
+
trustLevel: connectTrust,
|
|
292
408
|
}, {
|
|
293
409
|
...(audit ? { audit } : {}),
|
|
294
410
|
actor: auditActor,
|
|
@@ -300,7 +416,15 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
300
416
|
return { result: await (0, whoami_1.whoami)(store), isError: false };
|
|
301
417
|
}
|
|
302
418
|
case "channel_caps": {
|
|
303
|
-
|
|
419
|
+
// A typo used to answer the defaults as if they were a real channel's (#225).
|
|
420
|
+
const channel = coerceString(args.channel);
|
|
421
|
+
if (!(0, channel_1.isKnownChannel)(channel)) {
|
|
422
|
+
return {
|
|
423
|
+
result: { ok: false, status: "unknown_channel", message: `${channel === "" ? "channel is required" : `unknown channel '${channel}'`}: use one of ${(0, channel_1.knownChannels)().join(", ")}` },
|
|
424
|
+
isError: true,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
return { result: (0, channel_1.getChannelCapabilities)(channel), isError: false };
|
|
304
428
|
}
|
|
305
429
|
case "resolve_room": {
|
|
306
430
|
const view = await (0, room_1.resolveRoom)(store, coerceString(args.groupExternalId), (coerceOptionalString(args.channel) ?? "mcp"));
|
|
@@ -336,6 +460,21 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
336
460
|
if (!envelope || typeof envelope !== "object") {
|
|
337
461
|
return { result: { ok: false, status: "invalid", message: "an envelope object is required" }, isError: true };
|
|
338
462
|
}
|
|
463
|
+
if (!isProfileShareSubject(envelope.subject)) {
|
|
464
|
+
return {
|
|
465
|
+
result: { ok: false, status: "invalid", message: "the envelope needs a subject whose externalIds is a list of { provider, externalId }" },
|
|
466
|
+
isError: true,
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
if (!isSharedPayload(envelope)) {
|
|
470
|
+
return {
|
|
471
|
+
result: { ok: false, status: "invalid", message: "the envelope's notes must be a list of { key, value } and its outcomes a list" },
|
|
472
|
+
isError: true,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (coerceString(args.fromAgentId).trim() === "") {
|
|
476
|
+
return { result: { ok: false, status: "invalid", message: "fromAgentId must name the agent the envelope came from" }, isError: true };
|
|
477
|
+
}
|
|
339
478
|
const result = await (0, share_1.importProfileShare)(store, {
|
|
340
479
|
envelope,
|
|
341
480
|
fromAgentId: coerceString(args.fromAgentId),
|
|
@@ -353,6 +492,10 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
353
492
|
isError: true,
|
|
354
493
|
};
|
|
355
494
|
}
|
|
495
|
+
// An expiry the grant can't honour would make a grant that consents to nothing, or one that never expires.
|
|
496
|
+
if (args.expiresAt !== undefined && (typeof args.expiresAt !== "string" || !(0, grants_1.isIsoDate)(args.expiresAt))) {
|
|
497
|
+
return { result: { ok: false, status: "invalid", message: "expiresAt must be an ISO date, such as 2027-01-01 or 2027-01-01T00:00:00Z" }, isError: true };
|
|
498
|
+
}
|
|
356
499
|
// Fork D compat seam (b): accept the new `subjectKey` arg, falling back to
|
|
357
500
|
// the legacy `subjectFriendId` so old-arg callers (incl. the unmodified
|
|
358
501
|
// examples) keep working. coerceString gives "" when an arg is absent, so
|
|
@@ -386,13 +529,31 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
386
529
|
case "record_mission": {
|
|
387
530
|
if (!missions)
|
|
388
531
|
return { result: NO_MISSION_STORE, isError: true };
|
|
532
|
+
// Everything is checked before anything is written, so the answer is what was saved (#224).
|
|
533
|
+
const participants = listArg(args.participants, isParticipant);
|
|
534
|
+
const learnings = listArg(args.learnings, isLearningInput);
|
|
535
|
+
const outcomes = listArg(args.outcomes, isOutcomeInput);
|
|
536
|
+
// null means unset, as it does for the lists.
|
|
537
|
+
const status = args.status === null ? undefined : args.status;
|
|
538
|
+
if (coerceString(args.missionKey).trim() === "" ||
|
|
539
|
+
(status !== undefined && !(typeof status === "string" && MISSION_STATUSES.has(status))) ||
|
|
540
|
+
participants === INVALID_LIST || learnings === INVALID_LIST || outcomes === INVALID_LIST) {
|
|
541
|
+
return {
|
|
542
|
+
result: {
|
|
543
|
+
ok: false,
|
|
544
|
+
status: "invalid",
|
|
545
|
+
message: "record_mission needs a missionKey; status, when given, is active, succeeded, partial, failed or abandoned; participants is a list of { agentId?, agentName? } naming at least one, learnings a list of { key, value }, and outcomes a list of { missionId, result } with result success, partial or failed (each a list or its JSON text)",
|
|
546
|
+
},
|
|
547
|
+
isError: true,
|
|
548
|
+
};
|
|
549
|
+
}
|
|
389
550
|
const input = {
|
|
390
551
|
missionKey: coerceString(args.missionKey),
|
|
391
552
|
title: coerceOptionalString(args.title),
|
|
392
|
-
status:
|
|
393
|
-
participants:
|
|
394
|
-
learnings:
|
|
395
|
-
outcomes:
|
|
553
|
+
status: status,
|
|
554
|
+
participants: participants,
|
|
555
|
+
learnings: learnings,
|
|
556
|
+
outcomes: outcomes,
|
|
396
557
|
};
|
|
397
558
|
const record = await (0, missions_1.recordMission)(missions, input);
|
|
398
559
|
return { result: record, isError: false };
|
|
@@ -445,6 +606,15 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
445
606
|
if (!envelope || typeof envelope !== "object") {
|
|
446
607
|
return { result: { ok: false, status: "invalid", message: "an envelope object is required" }, isError: true };
|
|
447
608
|
}
|
|
609
|
+
const shared = envelope;
|
|
610
|
+
if (!hasMissionSubject(envelope) ||
|
|
611
|
+
(shared.learnings !== undefined && !(Array.isArray(shared.learnings) && shared.learnings.every(isSharedLearning))) ||
|
|
612
|
+
(shared.outcomes !== undefined && !(Array.isArray(shared.outcomes) && shared.outcomes.every(isRecord)))) {
|
|
613
|
+
return {
|
|
614
|
+
result: { ok: false, status: "invalid", message: "the envelope needs a subject with a missionKey; learnings, when given, a list of { key, value }, and outcomes a list" },
|
|
615
|
+
isError: true,
|
|
616
|
+
};
|
|
617
|
+
}
|
|
448
618
|
const result = await (0, mission_share_1.importMissionShare)(missions, {
|
|
449
619
|
envelope,
|
|
450
620
|
fromAgentId: coerceString(args.fromAgentId),
|
|
@@ -489,6 +659,15 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
489
659
|
if (!envelope || typeof envelope !== "object") {
|
|
490
660
|
return { result: { ok: false, status: "invalid", message: "an envelope object is required" }, isError: true };
|
|
491
661
|
}
|
|
662
|
+
const task = envelope.task;
|
|
663
|
+
if (!hasMissionSubject(envelope) ||
|
|
664
|
+
!(0, types_2.isCoordinationIntent)(envelope.intent) ||
|
|
665
|
+
(task !== undefined && !(isRecord(task) && typeof task.requestId === "string" && task.requestId !== ""))) {
|
|
666
|
+
return {
|
|
667
|
+
result: { ok: false, status: "invalid", message: "the envelope needs a subject with a missionKey, an intent, and a task, when given, with a requestId" },
|
|
668
|
+
isError: true,
|
|
669
|
+
};
|
|
670
|
+
}
|
|
492
671
|
const result = await (0, coordination_1.importCoordination)(missions, {
|
|
493
672
|
envelope,
|
|
494
673
|
fromAgentId: coerceString(args.fromAgentId),
|
|
@@ -535,6 +714,18 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
535
714
|
if (!envelope || typeof envelope !== "object") {
|
|
536
715
|
return { result: { ok: false, status: "invalid", message: "an envelope object is required" }, isError: true };
|
|
537
716
|
}
|
|
717
|
+
// The import correlates on the envelope's requestId and lands the result under it, so the result must carry
|
|
718
|
+
// the same one (or none) and a summary (#224).
|
|
719
|
+
const deliverable = envelope.result;
|
|
720
|
+
if (!hasMissionSubject(envelope) ||
|
|
721
|
+
typeof envelope.requestId !== "string" || envelope.requestId === "" ||
|
|
722
|
+
!deliverable || typeof deliverable !== "object" || typeof deliverable.summary !== "string" ||
|
|
723
|
+
(deliverable.requestId !== undefined && deliverable.requestId !== envelope.requestId)) {
|
|
724
|
+
return {
|
|
725
|
+
result: { ok: false, status: "invalid", message: "the envelope needs subject.missionKey, a requestId, and a result with a summary and the same requestId, as send_result produces" },
|
|
726
|
+
isError: true,
|
|
727
|
+
};
|
|
728
|
+
}
|
|
538
729
|
const result = await (0, mission_result_1.importMissionResult)(missions, {
|
|
539
730
|
envelope,
|
|
540
731
|
fromAgentId: coerceString(args.fromAgentId),
|
|
@@ -543,7 +734,11 @@ async function dispatchTool(store, name, args, grants, missions, audit, controlC
|
|
|
543
734
|
return { result, isError: result.ok === false };
|
|
544
735
|
}
|
|
545
736
|
default: {
|
|
546
|
-
|
|
737
|
+
// `unknown_door` is the stable code (Ouro AX's unknown-door); `error` keeps the text older clients read.
|
|
738
|
+
return {
|
|
739
|
+
result: { ok: false, status: "unknown_door", message: `Unknown tool: ${name}. Call one of the tools tools/list names.`, error: `Unknown tool: ${name}` },
|
|
740
|
+
isError: true,
|
|
741
|
+
};
|
|
547
742
|
}
|
|
548
743
|
}
|
|
549
744
|
}
|
|
@@ -6,27 +6,38 @@ exports.runMain = runMain;
|
|
|
6
6
|
// Resolves the friends directory from `--dir <path>` (flag wins) or the
|
|
7
7
|
// `FRIENDS_DIR` environment variable, constructs a FileFriendStore over it, and
|
|
8
8
|
// starts an MCP server on the given streams. If neither source supplies a
|
|
9
|
-
// directory,
|
|
9
|
+
// directory (missing-dir), or argv holds anything but `--dir <path>`
|
|
10
|
+
// (unknown-door), it reports via `onError` and constructs nothing (returns null).
|
|
10
11
|
const observability_1 = require("../observability");
|
|
11
12
|
const file_bundle_1 = require("../file-bundle");
|
|
12
13
|
const server_1 = require("./server");
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
/** The codes an error message leads with, so an agent can match the failure without parsing its words. */
|
|
15
|
+
const MISSING_DIR = "missing-dir";
|
|
16
|
+
const UNKNOWN_DOOR = "unknown-door";
|
|
17
|
+
/** Parse `--dir <value>` from argv, the only argument the bin takes. Returns the
|
|
18
|
+
* value (undefined if the flag is absent or has no following value), or the
|
|
19
|
+
* first argument that isn't `--dir <value>`. */
|
|
20
|
+
function parseArgs(argv) {
|
|
21
|
+
const args = argv.slice(2);
|
|
22
|
+
let dir;
|
|
23
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
24
|
+
if (args[i] !== "--dir")
|
|
25
|
+
return { dir, unknown: args[i] };
|
|
26
|
+
dir = args[i + 1];
|
|
27
|
+
i += 1;
|
|
28
|
+
}
|
|
29
|
+
return { dir };
|
|
23
30
|
}
|
|
24
31
|
function runMain(argv, env, io) {
|
|
25
|
-
const flagDir =
|
|
32
|
+
const { dir: flagDir, unknown } = parseArgs(argv);
|
|
33
|
+
if (unknown !== undefined) {
|
|
34
|
+
io.onError(`${UNKNOWN_DOOR}: friends-mcp takes only --dir <path>, not '${unknown}'`);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
26
37
|
const dir = flagDir ?? env.FRIENDS_DIR;
|
|
27
38
|
const source = flagDir !== undefined ? "flag" : "env";
|
|
28
39
|
if (!dir) {
|
|
29
|
-
io.onError(
|
|
40
|
+
io.onError(`${MISSING_DIR}: friends-mcp requires --dir <path> or FRIENDS_DIR`);
|
|
30
41
|
return null;
|
|
31
42
|
}
|
|
32
43
|
(0, observability_1.emitNervesEvent)({
|