@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
|
@@ -102,17 +102,15 @@ const TRUST_RANK = { family: 4, friend: 3, acquaintance: 2, stranger: 1 };
|
|
|
102
102
|
* namespace (never mutates the input). First-party `results` are NOT passed in and stay
|
|
103
103
|
* physically untouched. Idempotent per (agentId, requestId): an entry that already exists
|
|
104
104
|
* is preserved unchanged (never re-stamped). */
|
|
105
|
-
function mergeImportedResult(record, result, fromAgentId, now) {
|
|
105
|
+
function mergeImportedResult(record, requestId, result, fromAgentId, now) {
|
|
106
106
|
const existing = record.importedResults ?? {};
|
|
107
107
|
const forAgent = existing[fromAgentId] ?? {};
|
|
108
|
-
if (forAgent[result.requestId])
|
|
109
|
-
return existing;
|
|
110
108
|
return {
|
|
111
109
|
...existing,
|
|
112
110
|
[fromAgentId]: {
|
|
113
111
|
...forAgent,
|
|
114
|
-
[
|
|
115
|
-
requestId
|
|
112
|
+
[requestId]: {
|
|
113
|
+
requestId,
|
|
116
114
|
summary: result.summary,
|
|
117
115
|
...(result.artifact !== undefined ? { artifact: result.artifact } : {}),
|
|
118
116
|
...(result.outputs !== undefined ? { outputs: result.outputs } : {}),
|
|
@@ -161,7 +159,10 @@ async function importMissionResult(missions, input, options = {}) {
|
|
|
161
159
|
}
|
|
162
160
|
// (3) Correlation honesty — the requestId must name a delegation THIS agent issued
|
|
163
161
|
// first-party (A only accepts results for work it actually delegated).
|
|
164
|
-
|
|
162
|
+
// Only the mission's own entries count: "constructor" names no delegation.
|
|
163
|
+
const delegation = existing.delegations && Object.hasOwn(existing.delegations, input.envelope.requestId)
|
|
164
|
+
? existing.delegations[input.envelope.requestId]
|
|
165
|
+
: undefined;
|
|
165
166
|
if (!delegation) {
|
|
166
167
|
return { ok: false, status: "no_delegation" };
|
|
167
168
|
}
|
|
@@ -186,8 +187,14 @@ async function importMissionResult(missions, input, options = {}) {
|
|
|
186
187
|
}
|
|
187
188
|
// (4) Land the deliverable quarantined + attributed, never touching first-party, never
|
|
188
189
|
// recomputing status/participants (non-transitive).
|
|
190
|
+
// A replay, or a second result for the same request, keeps the first and says so (#224). The result lands under the
|
|
191
|
+
// requestId it was correlated on.
|
|
192
|
+
const requestId = input.envelope.requestId;
|
|
193
|
+
if (Object.hasOwn(existing.importedResults ?? {}, input.fromAgentId) && Object.hasOwn(existing.importedResults[input.fromAgentId], requestId)) {
|
|
194
|
+
return { ok: true, status: "noop", record: existing, message: "a result for this request from this agent is already imported; the first one is kept" };
|
|
195
|
+
}
|
|
189
196
|
const now = new Date().toISOString();
|
|
190
|
-
const importedResults = mergeImportedResult(existing, input.envelope.result, input.fromAgentId, now);
|
|
197
|
+
const importedResults = mergeImportedResult(existing, requestId, input.envelope.result, input.fromAgentId, now);
|
|
191
198
|
const updated = { ...existing, importedResults, updatedAt: now };
|
|
192
199
|
await missions.put(updated.id, updated);
|
|
193
200
|
(0, observability_1.emitNervesEvent)({
|
|
@@ -44,6 +44,7 @@ const fs = __importStar(require("fs"));
|
|
|
44
44
|
const fsPromises = __importStar(require("fs/promises"));
|
|
45
45
|
const path = __importStar(require("path"));
|
|
46
46
|
const observability_1 = require("./observability");
|
|
47
|
+
const safe_id_1 = require("./util/safe-id");
|
|
47
48
|
const MISSION_STATUSES = new Set([
|
|
48
49
|
"active",
|
|
49
50
|
"succeeded",
|
|
@@ -71,13 +72,20 @@ class FileMissionStore {
|
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
74
|
async get(id) {
|
|
75
|
+
// An id that would leave the missions directory names no mission.
|
|
76
|
+
if (!(0, safe_id_1.isSafeRecordId)(id))
|
|
77
|
+
return null;
|
|
74
78
|
const mission = await this.readJson(path.join(this.missionsPath, `${id}.json`));
|
|
75
79
|
return mission ? this.normalize(mission) : null;
|
|
76
80
|
}
|
|
77
81
|
async put(id, mission) {
|
|
82
|
+
if (!(0, safe_id_1.isSafeRecordId)(id))
|
|
83
|
+
throw new Error("mission id is invalid");
|
|
78
84
|
await fsPromises.writeFile(path.join(this.missionsPath, `${id}.json`), JSON.stringify(this.normalize(mission), null, 2), "utf-8");
|
|
79
85
|
}
|
|
80
86
|
async delete(id) {
|
|
87
|
+
if (!(0, safe_id_1.isSafeRecordId)(id))
|
|
88
|
+
throw new Error("mission id is invalid");
|
|
81
89
|
try {
|
|
82
90
|
await fsPromises.unlink(path.join(this.missionsPath, `${id}.json`));
|
|
83
91
|
}
|
|
@@ -14,15 +14,16 @@ exports.recordMission = recordMission;
|
|
|
14
14
|
// builtin is `node:crypto` (randomUUID), mirroring share.ts.
|
|
15
15
|
const node_crypto_1 = require("node:crypto");
|
|
16
16
|
const observability_1 = require("./observability");
|
|
17
|
-
/** Merge the input participants into the existing list, deduped by agentId
|
|
18
|
-
*
|
|
17
|
+
/** Merge the input participants into the existing list, deduped by agentId, or by agentName for a participant with
|
|
18
|
+
* no agentId. A participant already listed is skipped (idempotent). */
|
|
19
19
|
function mergeParticipants(existing, incoming) {
|
|
20
|
-
const
|
|
20
|
+
const keyOf = (p) => (p.agentId !== undefined ? `id:${p.agentId}` : `name:${p.agentName ?? ""}`);
|
|
21
|
+
const seen = new Set(existing.map(keyOf));
|
|
21
22
|
const merged = [...existing];
|
|
22
23
|
for (const p of incoming) {
|
|
23
|
-
if (!seen.has(p
|
|
24
|
+
if (!seen.has(keyOf(p))) {
|
|
24
25
|
merged.push(p);
|
|
25
|
-
seen.add(p
|
|
26
|
+
seen.add(keyOf(p));
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
return merged;
|
|
@@ -33,7 +33,7 @@ async function applyFriendNote(store, friendId, input) {
|
|
|
33
33
|
const now = new Date().toISOString();
|
|
34
34
|
if (type === "name") {
|
|
35
35
|
const updated = { ...record, name: content, updatedAt: now };
|
|
36
|
-
await store.put(
|
|
36
|
+
await store.put(updated.id, updated);
|
|
37
37
|
return { ok: true, status: "saved", record: updated };
|
|
38
38
|
}
|
|
39
39
|
if (type === "tool_preference") {
|
|
@@ -50,14 +50,14 @@ async function applyFriendNote(store, friendId, input) {
|
|
|
50
50
|
toolPreferences: { ...record.toolPreferences, [key]: content },
|
|
51
51
|
updatedAt: now,
|
|
52
52
|
};
|
|
53
|
-
await store.put(
|
|
53
|
+
await store.put(updated.id, updated);
|
|
54
54
|
return { ok: true, status: "saved", record: updated };
|
|
55
55
|
}
|
|
56
56
|
// type === "note"
|
|
57
57
|
// Redirect a "name" key to the name field rather than storing it as a note.
|
|
58
58
|
if (key === "name") {
|
|
59
59
|
const updated = { ...record, name: content, updatedAt: now };
|
|
60
|
-
await store.put(
|
|
60
|
+
await store.put(updated.id, updated);
|
|
61
61
|
return { ok: true, status: "redirected_to_name", record: updated };
|
|
62
62
|
}
|
|
63
63
|
const existing = record.notes[key];
|
|
@@ -76,7 +76,7 @@ async function applyFriendNote(store, friendId, input) {
|
|
|
76
76
|
},
|
|
77
77
|
updatedAt: now,
|
|
78
78
|
};
|
|
79
|
-
await store.put(
|
|
79
|
+
await store.put(updated.id, updated);
|
|
80
80
|
return { ok: true, status: "saved", record: updated };
|
|
81
81
|
}
|
|
82
82
|
catch (err) {
|
|
@@ -40,7 +40,7 @@ async function recordRelationshipOutcome(store, friendId, input, familiarityDelt
|
|
|
40
40
|
agentMeta: { ...meta, outcomes, sharedMissions, familiarity },
|
|
41
41
|
updatedAt: now,
|
|
42
42
|
};
|
|
43
|
-
await store.put(
|
|
43
|
+
await store.put(updated.id, updated);
|
|
44
44
|
(0, observability_1.emitNervesEvent)({
|
|
45
45
|
component: "friends",
|
|
46
46
|
event: "friends.outcome_recorded",
|
|
@@ -79,10 +79,13 @@ export interface ImportProfileShareInput {
|
|
|
79
79
|
trustOfSource: TrustLevel;
|
|
80
80
|
}
|
|
81
81
|
export type ImportProfileShareStatus = "imported" | "seeded" | "no_party" | "untrusted_source" | "untrusted_introduction";
|
|
82
|
-
export type ImportProfileShareResult =
|
|
82
|
+
export type ImportProfileShareResult =
|
|
83
|
+
/** `importedOutcomes` counts the shared outcomes that landed in `record.importedOutcomes`. */
|
|
84
|
+
{
|
|
83
85
|
ok: true;
|
|
84
86
|
status: "imported" | "seeded";
|
|
85
87
|
record: FriendRecord;
|
|
88
|
+
importedOutcomes: number;
|
|
86
89
|
} | {
|
|
87
90
|
ok: false;
|
|
88
91
|
status: "no_party" | "untrusted_source" | "untrusted_introduction";
|
|
@@ -104,5 +107,7 @@ export interface ImportProfileShareOptions {
|
|
|
104
107
|
* peer introduces it. Returns `{ ok, status, record }`.
|
|
105
108
|
*/
|
|
106
109
|
export declare function importProfileShare(store: FriendStore, input: ImportProfileShareInput, options?: ImportProfileShareOptions): Promise<ImportProfileShareResult>;
|
|
110
|
+
/** One peer may hold at most this many shared outcomes on a record; the oldest go first. */
|
|
111
|
+
export declare const MAX_IMPORTED_OUTCOMES_PER_PEER = 256;
|
|
107
112
|
/** One peer may hold at most this many unverified id claims on a record. */
|
|
108
113
|
export declare const MAX_IMPORTED_CLAIMS_PER_PEER = 32;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_IMPORTED_CLAIMS_PER_PEER = void 0;
|
|
3
|
+
exports.MAX_IMPORTED_CLAIMS_PER_PEER = exports.MAX_IMPORTED_OUTCOMES_PER_PEER = void 0;
|
|
4
4
|
exports.originalAsserterOf = originalAsserterOf;
|
|
5
5
|
exports.prepareProfileShare = prepareProfileShare;
|
|
6
6
|
exports.importProfileShare = importProfileShare;
|
|
@@ -142,7 +142,8 @@ function importedNoteFrom(note, fromAgentId, now) {
|
|
|
142
142
|
* untouched. Within the namespace, the newest import wins on key collision. */
|
|
143
143
|
function mergeImportedNotes(record, notes, fromAgentId, now) {
|
|
144
144
|
const existing = record.importedNotes ?? {};
|
|
145
|
-
const
|
|
145
|
+
const slot = Object.hasOwn(existing, fromAgentId) ? existing[fromAgentId] : undefined;
|
|
146
|
+
const forAgent = { ...(slot && typeof slot === "object" && !Array.isArray(slot) ? slot : {}) };
|
|
146
147
|
for (const note of notes) {
|
|
147
148
|
forAgent[note.key] = importedNoteFrom(note, fromAgentId, now);
|
|
148
149
|
}
|
|
@@ -208,6 +209,8 @@ async function importProfileShare(store, input, options = {}) {
|
|
|
208
209
|
return { ok: false, status: "untrusted_source" };
|
|
209
210
|
}
|
|
210
211
|
const now = new Date().toISOString();
|
|
212
|
+
// The number that lands: the newest MAX_IMPORTED_OUTCOMES_PER_PEER when the share carries more.
|
|
213
|
+
const sharedOutcomes = Math.min(importedOutcomesFrom(input.envelope, input.fromAgentId, now).length, exports.MAX_IMPORTED_OUTCOMES_PER_PEER);
|
|
211
214
|
const existing = await resolveSubject(store, input.envelope, input.fromAgentId);
|
|
212
215
|
if (!existing) {
|
|
213
216
|
// Unknown party. Fork E: only a friend/family peer may seed a new record.
|
|
@@ -223,7 +226,7 @@ async function importProfileShare(store, input, options = {}) {
|
|
|
223
226
|
message: "seeded new party from profile share",
|
|
224
227
|
meta: { friendId: withNotes.id, fromAgentId: input.fromAgentId },
|
|
225
228
|
});
|
|
226
|
-
return { ok: true, status: "seeded", record: withNotes };
|
|
229
|
+
return { ok: true, status: "seeded", record: withNotes, importedOutcomes: sharedOutcomes };
|
|
227
230
|
}
|
|
228
231
|
const updated = applyEnvelopeToRecord(existing, input.envelope, input.fromAgentId, now);
|
|
229
232
|
await store.put(updated.id, updated);
|
|
@@ -233,7 +236,38 @@ async function importProfileShare(store, input, options = {}) {
|
|
|
233
236
|
message: "imported profile share into existing party",
|
|
234
237
|
meta: { friendId: updated.id, fromAgentId: input.fromAgentId, scope: input.envelope.scope },
|
|
235
238
|
});
|
|
236
|
-
return { ok: true, status: "imported", record: updated };
|
|
239
|
+
return { ok: true, status: "imported", record: updated, importedOutcomes: sharedOutcomes };
|
|
240
|
+
}
|
|
241
|
+
/** One peer may hold at most this many shared outcomes on a record; the oldest go first. */
|
|
242
|
+
exports.MAX_IMPORTED_OUTCOMES_PER_PEER = 256;
|
|
243
|
+
const OUTCOME_RESULTS = new Set(["success", "partial", "failed"]);
|
|
244
|
+
/** The envelope's outcomes that are well formed, stamped with who asserted them. */
|
|
245
|
+
function importedOutcomesFrom(envelope, fromAgentId, now) {
|
|
246
|
+
// Only an outcomes share carries outcomes; the producer sends them in no other scope.
|
|
247
|
+
if (envelope.scope !== "outcomes" || !Array.isArray(envelope.outcomes))
|
|
248
|
+
return [];
|
|
249
|
+
return envelope.outcomes
|
|
250
|
+
.filter((outcome) => outcome && typeof outcome.missionId === "string" && outcome.missionId.length > 0 &&
|
|
251
|
+
OUTCOME_RESULTS.has(outcome.result) && typeof outcome.timestamp === "string")
|
|
252
|
+
.map((outcome) => ({
|
|
253
|
+
missionId: outcome.missionId,
|
|
254
|
+
result: outcome.result,
|
|
255
|
+
timestamp: outcome.timestamp,
|
|
256
|
+
...(typeof outcome.note === "string" ? { note: outcome.note } : {}),
|
|
257
|
+
importedAt: now,
|
|
258
|
+
assertedBy: { agentId: fromAgentId },
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
/** Merge shared outcomes into the peer's slot: one re-shared (same mission and timestamp) replaces its earlier copy. */
|
|
262
|
+
function mergeImportedOutcomes(record, incoming, fromAgentId) {
|
|
263
|
+
if (incoming.length === 0)
|
|
264
|
+
return record.importedOutcomes;
|
|
265
|
+
const existing = record.importedOutcomes ?? {};
|
|
266
|
+
const sameOutcome = (a, b) => a.missionId === b.missionId && a.timestamp === b.timestamp;
|
|
267
|
+
const slot = Object.hasOwn(existing, fromAgentId) ? existing[fromAgentId] : [];
|
|
268
|
+
const kept = (Array.isArray(slot) ? slot : []).filter((have) => !!have && typeof have === "object" && typeof have.missionId === "string" && !incoming.some((next) => sameOutcome(have, next)));
|
|
269
|
+
const merged = [...kept, ...incoming].slice(-exports.MAX_IMPORTED_OUTCOMES_PER_PEER);
|
|
270
|
+
return { ...existing, [fromAgentId]: merged };
|
|
237
271
|
}
|
|
238
272
|
/** One peer may hold at most this many unverified id claims on a record. */
|
|
239
273
|
exports.MAX_IMPORTED_CLAIMS_PER_PEER = 32;
|
|
@@ -264,6 +298,7 @@ function applyEnvelopeToRecord(record, envelope, fromAgentId, now) {
|
|
|
264
298
|
assertedBy: { agentId: fromAgentId },
|
|
265
299
|
importedAt: now,
|
|
266
300
|
}));
|
|
301
|
+
const importedOutcomes = mergeImportedOutcomes(record, importedOutcomesFrom(envelope, fromAgentId, now), fromAgentId);
|
|
267
302
|
const importedExternalIds = newClaims.length > 0
|
|
268
303
|
? capClaimsPerPeer([...(record.importedExternalIds ?? []), ...newClaims], fromAgentId)
|
|
269
304
|
: record.importedExternalIds;
|
|
@@ -273,6 +308,7 @@ function applyEnvelopeToRecord(record, envelope, fromAgentId, now) {
|
|
|
273
308
|
// trustLevel / role are intentionally NOT recomputed — an import must never
|
|
274
309
|
// change the party's trust (the single most important safety invariant).
|
|
275
310
|
...(importedNotes ? { importedNotes } : {}),
|
|
311
|
+
...(importedOutcomes ? { importedOutcomes } : {}),
|
|
276
312
|
updatedAt: now,
|
|
277
313
|
};
|
|
278
314
|
}
|
|
@@ -43,13 +43,13 @@ const crypto_1 = require("crypto");
|
|
|
43
43
|
const cap_string_1 = require("./util/cap-string");
|
|
44
44
|
const observability_1 = require("./observability");
|
|
45
45
|
const types_1 = require("./types");
|
|
46
|
+
const safe_id_1 = require("./util/safe-id");
|
|
46
47
|
const DEFAULT_ROLE = "friend";
|
|
47
48
|
const DEFAULT_TRUST_LEVEL = "friend";
|
|
48
49
|
const DEFAULT_ADMISSION_STATE = "unverified";
|
|
49
50
|
const DEFAULT_INITIATIVE_POLICY = "none";
|
|
50
51
|
const CLAIMS_DIR_NAME = "_external-id-claims";
|
|
51
52
|
const MAX_CLAIM_BYTES = 1_048_576;
|
|
52
|
-
const SAFE_RECORD_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
53
53
|
class FileFriendStore {
|
|
54
54
|
friendsPath;
|
|
55
55
|
friendsDirectoryFd;
|
|
@@ -84,11 +84,16 @@ class FileFriendStore {
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
async get(id) {
|
|
87
|
-
//
|
|
88
|
-
|
|
87
|
+
// An empty id names nobody: without this it would match a record whose name is empty.
|
|
88
|
+
if (id === "")
|
|
89
|
+
return null;
|
|
90
|
+
// Direct id lookup, only for an id that names a file in the friends directory (#212); any other id is a name.
|
|
91
|
+
const record = (0, safe_id_1.isSafeRecordId)(id) ? await this.readJson(path.join(this.friendsPath, `${id}.json`)) : null;
|
|
89
92
|
if (record)
|
|
90
93
|
return await this.normalizeWithClaims(record);
|
|
91
|
-
// Fallback: if id is a name (not UUID), scan for
|
|
94
|
+
// Fallback: if id is a name (not UUID), scan for the one friend of that name. Two of the same name are ambiguous,
|
|
95
|
+
// and a write by name must not land on whichever file is read first, so the name then finds nobody.
|
|
96
|
+
let match = null;
|
|
92
97
|
/* v8 ignore start -- name fallback: exercised by live proactive sends @preserve */
|
|
93
98
|
try {
|
|
94
99
|
this.assertFriendsDirectoryIdentity();
|
|
@@ -101,17 +106,21 @@ class FileFriendStore {
|
|
|
101
106
|
continue;
|
|
102
107
|
const normalized = await this.normalizeWithClaims(raw);
|
|
103
108
|
if (normalized.name?.toLowerCase() === id.toLowerCase()) {
|
|
104
|
-
|
|
109
|
+
if (match)
|
|
110
|
+
return null;
|
|
111
|
+
match = normalized;
|
|
105
112
|
}
|
|
106
113
|
}
|
|
107
114
|
this.assertFriendsDirectoryIdentity();
|
|
108
115
|
}
|
|
109
|
-
catch {
|
|
116
|
+
catch {
|
|
117
|
+
return null; /* directory unreadable */
|
|
118
|
+
}
|
|
110
119
|
/* v8 ignore stop */
|
|
111
|
-
return
|
|
120
|
+
return match;
|
|
112
121
|
}
|
|
113
122
|
async put(id, record) {
|
|
114
|
-
if (!
|
|
123
|
+
if (!(0, safe_id_1.isSafeRecordId)(id) || record.id !== id)
|
|
115
124
|
throw new Error("friend record id is invalid");
|
|
116
125
|
const existing = await this.readJson(path.join(this.friendsPath, `${id}.json`));
|
|
117
126
|
const existingIncarnation = typeof existing?.recordIncarnation === "string" && existing.recordIncarnation
|
|
@@ -128,6 +137,8 @@ class FileFriendStore {
|
|
|
128
137
|
}));
|
|
129
138
|
}
|
|
130
139
|
async delete(id) {
|
|
140
|
+
if (!(0, safe_id_1.isSafeRecordId)(id))
|
|
141
|
+
throw new Error("friend record id is invalid");
|
|
131
142
|
await this.removeFile(path.join(this.friendsPath, `${id}.json`));
|
|
132
143
|
}
|
|
133
144
|
async findByExternalId(provider, externalId, tenantId) {
|
|
@@ -193,7 +204,7 @@ class FileFriendStore {
|
|
|
193
204
|
return records;
|
|
194
205
|
}
|
|
195
206
|
async releaseExternalId(friendId, externalId) {
|
|
196
|
-
if (!
|
|
207
|
+
if (!(0, safe_id_1.isSafeRecordId)(friendId))
|
|
197
208
|
throw new Error("external identity claim target id is invalid");
|
|
198
209
|
const claimPath = this.pendingClaimPath(externalId);
|
|
199
210
|
await this.ensureClaimsDirectory();
|
|
@@ -323,6 +334,9 @@ class FileFriendStore {
|
|
|
323
334
|
? { importedNotes: raw.importedNotes }
|
|
324
335
|
: {}),
|
|
325
336
|
...(importedExternalIds ? { importedExternalIds } : {}),
|
|
337
|
+
...(raw.importedOutcomes && typeof raw.importedOutcomes === "object" && !Array.isArray(raw.importedOutcomes)
|
|
338
|
+
? { importedOutcomes: Object.fromEntries(Object.entries(raw.importedOutcomes).filter(([, outcomes]) => Array.isArray(outcomes))) }
|
|
339
|
+
: {}),
|
|
326
340
|
...(trustReset ? { trustReset } : {}),
|
|
327
341
|
totalTokens: typeof raw.totalTokens === "number" ? raw.totalTokens : 0,
|
|
328
342
|
createdAt: typeof raw.createdAt === "string" ? raw.createdAt : new Date().toISOString(),
|
|
@@ -509,7 +523,7 @@ class FileFriendStore {
|
|
|
509
523
|
!this.isSafeExternalId(parsed.externalId) ||
|
|
510
524
|
this.externalIdentityDigest(parsed.externalId) !== identityDigest ||
|
|
511
525
|
typeof parsed.friendId !== "string" ||
|
|
512
|
-
!
|
|
526
|
+
!(0, safe_id_1.isSafeRecordId)(parsed.friendId) ||
|
|
513
527
|
!this.isSafeRecordIncarnation(parsed.recordIncarnation) ||
|
|
514
528
|
(state === "pending" && targetKind === "create" && (!this.isSafeJournalCreateRecord(parsed.createRecord) ||
|
|
515
529
|
parsed.createRecord.id !== parsed.friendId ||
|
|
@@ -553,7 +567,7 @@ class FileFriendStore {
|
|
|
553
567
|
throw new Error("external identity create candidate is invalid");
|
|
554
568
|
}
|
|
555
569
|
const id = input.target.kind === "link" ? input.target.friendId : input.target.record.id;
|
|
556
|
-
if (!
|
|
570
|
+
if (!(0, safe_id_1.isSafeRecordId)(id))
|
|
557
571
|
throw new Error("external identity claim target id is invalid");
|
|
558
572
|
if (!this.isSafeExternalId(input.externalId))
|
|
559
573
|
throw new Error("external identity claim is invalid");
|
|
@@ -590,7 +604,7 @@ class FileFriendStore {
|
|
|
590
604
|
return false;
|
|
591
605
|
const candidate = record;
|
|
592
606
|
return typeof candidate.id === "string" &&
|
|
593
|
-
|
|
607
|
+
(0, safe_id_1.isSafeRecordId)(candidate.id) &&
|
|
594
608
|
typeof candidate.name === "string" &&
|
|
595
609
|
candidate.name.trim().length > 0 &&
|
|
596
610
|
candidate.name.length <= 256 &&
|
|
@@ -608,6 +622,7 @@ class FileFriendStore {
|
|
|
608
622
|
(candidate.notes === undefined || this.isEmptyRecord(candidate.notes)) &&
|
|
609
623
|
(candidate.connections === undefined || candidate.connections.length === 0) &&
|
|
610
624
|
candidate.importedNotes === undefined &&
|
|
625
|
+
candidate.importedOutcomes === undefined &&
|
|
611
626
|
candidate.agentMeta === undefined &&
|
|
612
627
|
(candidate.kind === undefined || candidate.kind === "human") &&
|
|
613
628
|
(candidate.totalTokens === undefined || candidate.totalTokens === 0);
|
|
@@ -619,7 +634,7 @@ class FileFriendStore {
|
|
|
619
634
|
const expectedKeys = ["admissionState", "connections", "createdAt", "externalIds", "id", "initiativePolicy", "kind", "name", "notes", "recordGeneration", "recordIncarnation", "relationshipPolicy", "role", "schemaVersion", "tenantMemberships", "toolPreferences", "totalTokens", "trustLevel", "updatedAt"];
|
|
620
635
|
return this.hasExactKeys(candidate, expectedKeys) &&
|
|
621
636
|
typeof candidate.id === "string" &&
|
|
622
|
-
|
|
637
|
+
(0, safe_id_1.isSafeRecordId)(candidate.id) &&
|
|
623
638
|
typeof candidate.recordIncarnation === "string" &&
|
|
624
639
|
this.isSafeRecordIncarnation(candidate.recordIncarnation) &&
|
|
625
640
|
Number.isSafeInteger(candidate.recordGeneration) &&
|
|
@@ -5,4 +5,6 @@ export interface UsageData {
|
|
|
5
5
|
reasoning_tokens: number;
|
|
6
6
|
total_tokens: number;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
/** Add a turn's output tokens to the friend's total. Returns whether any were added: false for no output tokens or a
|
|
9
|
+
* missing friend. */
|
|
10
|
+
export declare function accumulateFriendTokens(store: FriendStore, friendId: string, usage?: UsageData): Promise<boolean>;
|
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.accumulateFriendTokens = accumulateFriendTokens;
|
|
7
7
|
const observability_1 = require("./observability");
|
|
8
|
+
/** Add a turn's output tokens to the friend's total. Returns whether any were added: false for no output tokens or a
|
|
9
|
+
* missing friend. */
|
|
8
10
|
async function accumulateFriendTokens(store, friendId, usage) {
|
|
9
11
|
if (!usage?.output_tokens)
|
|
10
|
-
return;
|
|
12
|
+
return false;
|
|
11
13
|
const record = await store.get(friendId);
|
|
12
14
|
if (!record)
|
|
13
|
-
return;
|
|
15
|
+
return false;
|
|
14
16
|
// Only count output tokens (what the model generated for this friend).
|
|
15
17
|
// Input tokens are mostly system prompt re-sent every turn -- counting them
|
|
16
18
|
// would inflate the total and make the onboarding threshold meaningless.
|
|
@@ -23,4 +25,5 @@ async function accumulateFriendTokens(store, friendId, usage) {
|
|
|
23
25
|
message: "tokens accumulated for friend",
|
|
24
26
|
meta: { friendId, outputTokens: usage.output_tokens },
|
|
25
27
|
});
|
|
28
|
+
return true;
|
|
26
29
|
}
|
|
@@ -37,7 +37,7 @@ async function setFriendTrust(store, friendId, level, ctx) {
|
|
|
37
37
|
role: level,
|
|
38
38
|
updatedAt,
|
|
39
39
|
};
|
|
40
|
-
await store.put(
|
|
40
|
+
await store.put(updated.id, updated);
|
|
41
41
|
// Bug B — append one control-plane audit record on the successful mutation. The
|
|
42
42
|
// `targetDid` is the record's durable identity DID (identity.did, falling back to
|
|
43
43
|
// the migrated a2a.did via resolveAgentIdentity). `actor` defaults to the literal
|
|
@@ -53,7 +53,7 @@ async function setFriendTrust(store, friendId, level, ctx) {
|
|
|
53
53
|
const targetDid = (0, identity_1.resolveAgentIdentity)(current.agentMeta).did;
|
|
54
54
|
const record = {
|
|
55
55
|
action: "set_trust",
|
|
56
|
-
targetId:
|
|
56
|
+
targetId: current.id,
|
|
57
57
|
...(targetDid !== undefined ? { targetDid } : {}),
|
|
58
58
|
level,
|
|
59
59
|
...(ctx.basis !== undefined ? { basis: ctx.basis } : {}),
|
|
@@ -63,6 +63,14 @@ export interface ImportedNote {
|
|
|
63
63
|
assertedBy?: AgentAttribution;
|
|
64
64
|
originallyAssertedBy?: AgentAttribution;
|
|
65
65
|
}
|
|
66
|
+
export interface ImportedOutcome {
|
|
67
|
+
missionId: string;
|
|
68
|
+
result: "success" | "partial" | "failed";
|
|
69
|
+
timestamp: string;
|
|
70
|
+
note?: string;
|
|
71
|
+
importedAt: string;
|
|
72
|
+
assertedBy: AgentAttribution;
|
|
73
|
+
}
|
|
66
74
|
export type ShareScope = "name" | "identity" | "notes:safe" | "notes:all" | "outcomes" | "mission" | "coordinate";
|
|
67
75
|
export declare function isShareScope(value: unknown): value is ShareScope;
|
|
68
76
|
/** Identity-only scopes expose the join key (externalIds + name), never note
|
|
@@ -292,6 +300,10 @@ export interface FriendRecord {
|
|
|
292
300
|
* unverified claims: never indexed, never claimed, never used to resolve a sender.
|
|
293
301
|
* Absent on records that have never imported anything. */
|
|
294
302
|
importedExternalIds?: ImportedExternalId[];
|
|
303
|
+
/** Relationship outcomes other agents shared about this party, keyed by the
|
|
304
|
+
* asserting agentId. Advisory claims, kept apart from first-party outcomes.
|
|
305
|
+
* Absent on records that have never imported any. */
|
|
306
|
+
importedOutcomes?: Record<string, ImportedOutcome[]>;
|
|
295
307
|
/** Set when the record's authority was reset because the peer's DID changed. */
|
|
296
308
|
trustReset?: TrustReset;
|
|
297
309
|
totalTokens: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isSafeRecordId(id: string): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSafeRecordId = isSafeRecordId;
|
|
4
|
+
// A record id that names one file directly inside its store's directory: it starts with a letter or digit and holds
|
|
5
|
+
// only letters, digits, dots, underscores and hyphens, so it can't climb out with `..`, reach into a folder with `/`,
|
|
6
|
+
// or name a reserved `_`-prefixed collection. Every file store checks an id with this before joining it into a path.
|
|
7
|
+
const SAFE_RECORD_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
8
|
+
function isSafeRecordId(id) {
|
|
9
|
+
return SAFE_RECORD_ID.test(id);
|
|
10
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/friends",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.30",
|
|
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",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
30
|
"dist/",
|
|
31
|
+
"actions/generated/mcp.json",
|
|
31
32
|
"changelog.json"
|
|
32
33
|
],
|
|
33
34
|
"type": "commonjs",
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1394",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1394",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@ouro.bot/friends"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
15
|
-
"@ouro.bot/friends": "0.1.0-alpha.
|
|
15
|
+
"@ouro.bot/friends": "0.1.0-alpha.30",
|
|
16
16
|
"@types/react": "^17.0.91",
|
|
17
17
|
"@types/ws": "^8.18.1",
|
|
18
18
|
"ajv": "^8.20.0",
|
|
@@ -1427,9 +1427,9 @@
|
|
|
1427
1427
|
}
|
|
1428
1428
|
},
|
|
1429
1429
|
"node_modules/@ouro.bot/friends": {
|
|
1430
|
-
"version": "0.1.0-alpha.
|
|
1431
|
-
"resolved": "https://registry.npmjs.org/@ouro.bot/friends/-/friends-0.1.0-alpha.
|
|
1432
|
-
"integrity": "sha512-
|
|
1430
|
+
"version": "0.1.0-alpha.30",
|
|
1431
|
+
"resolved": "https://registry.npmjs.org/@ouro.bot/friends/-/friends-0.1.0-alpha.30.tgz",
|
|
1432
|
+
"integrity": "sha512-Z9fA6CsauYqTgtap2h0X30r5hT+X4jK/JzEVb3AunMmfhxdZRKOkwkcyaUaFcJX1ykbNVzVz+srHyJ2RjIxjCA==",
|
|
1433
1433
|
"inBundle": true,
|
|
1434
1434
|
"license": "Apache-2.0",
|
|
1435
1435
|
"dependencies": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1394",
|
|
4
4
|
"description": "Ouroboros, the agent harness: agents with durable memory that live where you talk (terminal, Teams, iMessage, mail, voice) and use real tools. Start with npx ouro.bot@latest.",
|
|
5
5
|
"homepage": "https://ouroboros.bot/",
|
|
6
6
|
"engines": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
],
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
68
|
-
"@ouro.bot/friends": "0.1.0-alpha.
|
|
68
|
+
"@ouro.bot/friends": "0.1.0-alpha.30",
|
|
69
69
|
"@types/react": "^17.0.91",
|
|
70
70
|
"@types/ws": "^8.18.1",
|
|
71
71
|
"ajv": "^8.20.0",
|