@tpsdev-ai/flair 0.56.0 → 0.58.0
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/README.md +19 -20
- package/SECURITY.md +4 -1
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1800 -293
- package/dist/commands/agent.js +22 -15
- package/dist/commands/bridge.js +40 -3
- package/dist/commands/doctor.js +214 -4
- package/dist/commands/federation.js +265 -38
- package/dist/commands/hook.js +10 -2
- package/dist/commands/init.js +179 -48
- package/dist/commands/memory.js +24 -2
- package/dist/commands/quality.js +26 -18
- package/dist/commands/service.js +137 -22
- package/dist/commands/status.js +114 -3
- package/dist/commands/upgrade.js +204 -84
- package/dist/doctor-client.js +50 -4
- package/dist/federation/scheduler.js +253 -4
- package/dist/install/clients.js +89 -23
- package/dist/install/global-bin-path.js +26 -6
- package/dist/lib/atomic-write.js +256 -0
- package/dist/lib/auth-resolve.js +46 -0
- package/dist/lib/daemon-liveness.js +61 -0
- package/dist/lib/doctor-run.js +5 -0
- package/dist/lib/embed-gpu-doctor.js +49 -26
- package/dist/lib/federation-memory-attributes.js +15 -0
- package/dist/lib/init-admin-pass.js +4 -2
- package/dist/lib/init-listener-environ.js +38 -0
- package/dist/lib/init-occupied-listener.js +165 -0
- package/dist/lib/instance-identity-row.js +580 -0
- package/dist/lib/launchd-domain-preflight.js +448 -0
- package/dist/lib/launchd-management.js +176 -6
- package/dist/lib/launchd-repair.js +95 -0
- package/dist/lib/memory-attributes.js +77 -0
- package/dist/lib/node-alias-path.js +95 -0
- package/dist/lib/npm-registry.js +119 -6
- package/dist/lib/owned-pins.js +20 -6
- package/dist/lib/redact-token-id.js +197 -0
- package/dist/lib/service-repoint-apply.js +267 -0
- package/dist/lib/service-repoint.js +575 -0
- package/dist/lib/toml-string-array.js +104 -0
- package/dist/lib/tree-divergence.js +716 -0
- package/dist/lib/upgrade-plain-tree.js +18 -8
- package/dist/lib/upgrade-prior-liveness.js +69 -0
- package/dist/lib/upgrade-rollback.js +116 -0
- package/dist/rem/runner.js +11 -0
- package/dist/resources/Agent.js +27 -14
- package/dist/resources/AgentSeed.js +39 -2
- package/dist/resources/Asset.js +3 -11
- package/dist/resources/Credential.js +4 -10
- package/dist/resources/Federation.js +299 -127
- package/dist/resources/Integration.js +8 -32
- package/dist/resources/Memory.js +623 -86
- package/dist/resources/MemoryArchive.js +9 -0
- package/dist/resources/MemoryBootstrap.js +23 -12
- package/dist/resources/MemoryCandidate.js +3 -11
- package/dist/resources/MemoryDedupStats.js +1 -1
- package/dist/resources/MemoryFeed.js +214 -5
- package/dist/resources/MemoryGrant.js +19 -40
- package/dist/resources/MemoryHostSource.js +90 -0
- package/dist/resources/MemoryMaintenance.js +121 -32
- package/dist/resources/MemoryReflect.js +4 -1
- package/dist/resources/MemoryReindex.js +7 -4
- package/dist/resources/MemoryUsage.js +55 -18
- package/dist/resources/Presence.js +18 -10
- package/dist/resources/RecordUsage.js +30 -40
- package/dist/resources/Relationship.js +170 -89
- package/dist/resources/SemanticSearch.js +44 -19
- package/dist/resources/Soul.js +31 -19
- package/dist/resources/XAA.js +7 -3
- package/dist/resources/agent-auth.js +16 -10
- package/dist/resources/auth-middleware.js +164 -50
- package/dist/resources/auto-promote-lib.js +4 -4
- package/dist/resources/bm25-index-service.js +246 -32
- package/dist/resources/bm25-status.js +132 -0
- package/dist/resources/bm25.js +13 -14
- package/dist/resources/ed25519-auth.js +11 -54
- package/dist/resources/embed-gpu.js +262 -47
- package/dist/resources/embeddings-boot.js +52 -17
- package/dist/resources/federation-classify.js +12 -0
- package/dist/resources/federation-cleanup.js +289 -51
- package/dist/resources/federation-crypto.js +65 -19
- package/dist/resources/health.js +105 -22
- package/dist/resources/host-pointer/registry.js +35 -0
- package/dist/resources/host-pointer-adapter.js +15 -0
- package/dist/resources/host-source-visibility.js +167 -0
- package/dist/resources/host-source.js +151 -0
- package/dist/resources/in-process-api.js +2 -1
- package/dist/resources/instance-create-lock.js +363 -0
- package/dist/resources/instance-identity-rows.js +43 -0
- package/dist/resources/instance-identity.js +97 -12
- package/dist/resources/mcp-handler.js +155 -51
- package/dist/resources/mcp-tool-arguments.js +83 -0
- package/dist/resources/mcp-tools.js +28 -25
- package/dist/resources/memory-consolidate-lib.js +3 -1
- package/dist/resources/memory-declared-attributes.js +103 -0
- package/dist/resources/memory-feed-lib.js +5 -1
- package/dist/resources/memory-host-source.js +163 -0
- package/dist/resources/memory-visibility.js +10 -7
- package/dist/resources/migrations/synthetic-test-migration.js +4 -1
- package/dist/resources/migrations/visibility-backfill.js +4 -1
- package/dist/resources/originator-instance.js +235 -0
- package/dist/resources/promotion-stamp.js +2 -0
- package/dist/resources/provenance.js +111 -11
- package/dist/resources/rate-limit.js +6 -4
- package/dist/resources/record-owner-guard.js +19 -0
- package/dist/resources/record-type-kit.js +44 -23
- package/dist/resources/record-types.js +6 -6
- package/dist/resources/relay-ops.js +28 -3
- package/dist/resources/replay-store.js +289 -0
- package/dist/resources/request-transaction.js +78 -0
- package/dist/resources/search-readiness.js +26 -22
- package/dist/resources/semantic-retrieval-core.js +103 -4
- package/dist/resources/table-helpers.js +33 -0
- package/dist/resources/table-patch-policy.js +109 -0
- package/dist/resources/table-patches.js +17 -0
- package/dist/resources/table-post-policy.js +138 -0
- package/dist/resources/table-posts.js +22 -0
- package/dist/resources/table-subscription-policy.js +135 -0
- package/dist/resources/table-subscriptions.js +19 -0
- package/dist/resources/tool-descriptors/index.js +15 -15
- package/dist/resources/trust-block.js +10 -3
- package/dist/resources/usage-recording.js +169 -41
- package/dist/src/lib/instance-identity-row.js +580 -0
- package/dist/src/lib/memory-attributes.js +77 -0
- package/dist/src/lib/redact-token-id.js +197 -0
- package/docs/api-reference.md +80 -16
- package/docs/auth.md +5 -5
- package/docs/claude-code.md +137 -6
- package/docs/deploying-on-fabric.md +6 -3
- package/docs/deployment.md +1 -1
- package/docs/embedding-in-a-harper-app.md +3 -3
- package/docs/federation.md +17 -10
- package/docs/hosted-on-fabric.md +4 -3
- package/docs/integrations.md +28 -19
- package/docs/mcp-clients.md +26 -32
- package/docs/n8n.md +8 -8
- package/docs/notes/mcp-oauth-model2.md +27 -18
- package/docs/openclaw.md +29 -28
- package/docs/quickstart.md +5 -0
- package/docs/releasing.md +134 -2
- package/docs/spoke-bringup.md +14 -11
- package/docs/standalone-local.md +2 -2
- package/docs/supply-chain-policy.md +28 -10
- package/docs/system-requirements.md +1 -1
- package/docs/troubleshooting.md +11 -0
- package/docs/upgrade.md +189 -63
- package/package.json +9 -5
- package/schemas/agent.graphql +9 -6
- package/schemas/federation.graphql +2 -11
- package/schemas/memory.graphql +106 -17
- package/schemas/replay.graphql +18 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +22 -0
- package/dist/resources/federation-nonce-store.js +0 -195
|
@@ -14,12 +14,10 @@
|
|
|
14
14
|
* memory WRITE; each cited id is credited the same way, post-commit and
|
|
15
15
|
* failure-isolated from the write itself.
|
|
16
16
|
*
|
|
17
|
-
* `recordUsageContribution()` is
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* read-modify-write. This move changes WHERE the logic lives, not what it
|
|
22
|
-
* does — behavior is byte-identical for RecordUsage.ts's existing callers.
|
|
17
|
+
* `recordUsageContribution()` is the one (agentId, memoryId) ledger write —
|
|
18
|
+
* see its doc below for the read-scope gate it applies, the ledger-then-count
|
|
19
|
+
* ordering, the individually-wrapped `withDetachedTxn` discipline, and the
|
|
20
|
+
* accepted best-effort race on the final read-modify-write.
|
|
23
21
|
*
|
|
24
22
|
* `recordCitations()` is the NEW batch helper citation-on-write uses: the
|
|
25
23
|
* same agent-required / cap / dedup / per-id failure-isolation shape as
|
|
@@ -30,22 +28,33 @@
|
|
|
30
28
|
* the flair#775 read-scope gate below is the REVERSE direction — the writer's
|
|
31
29
|
* scope vets the cited ids, the cited ids never widen anything).
|
|
32
30
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
31
|
+
* READ SCOPE, ON BOTH SURFACES. A contribution is recorded only for a memory
|
|
32
|
+
* in the contributing agent's read scope: `resolveReadScope(agentId).isAllowed(record)`
|
|
33
|
+
* — the scope Memory.get() applies to a NON-ADMIN by-id read. It applies to
|
|
34
|
+
* admin agents here too, although an admin's Memory reads are unfiltered. A
|
|
35
|
+
* memory outside that scope takes the SAME branch as an id that does not
|
|
36
|
+
* exist: the caller gets the same response and the memory's counters do not
|
|
37
|
+
* change. Any difference between the two (an error, a response or shape
|
|
38
|
+
* difference, a ledger row the caller can read back) would tell the caller
|
|
39
|
+
* "that id exists but you can't see it".
|
|
40
|
+
* - recordUsageContribution() REQUIRES the predicate (`canRead`). It applies
|
|
41
|
+
* it to its first read of the memory, before the ledger row is written
|
|
42
|
+
* (out of scope there: no row), and again to the re-read before the count
|
|
43
|
+
* bump (out of scope there: the row already written stays, and the count
|
|
44
|
+
* is not bumped). No caller of the ledger core can credit a memory without
|
|
45
|
+
* a read-scope decision.
|
|
46
|
+
* - recordUsageBatch() (POST /RecordUsage) and recordCitations()
|
|
47
|
+
* (citation-on-write) each resolve the caller's scope ONCE per batch and
|
|
48
|
+
* fail CLOSED: if the scope cannot be resolved, nothing in the batch is
|
|
49
|
+
* credited. recordCitations() also pre-checks each cited id (flair#775).
|
|
50
|
+
* - The ledger's own read path (resources/MemoryUsage.ts) applies the same
|
|
51
|
+
* rule to NON-ADMIN reads through isLedgerRowVisible()/readableLedgerRows():
|
|
52
|
+
* a non-admin reader sees its own row only while the memory it names
|
|
53
|
+
* exists and is readable. Admin and trusted internal ledger reads are
|
|
54
|
+
* unfiltered.
|
|
47
55
|
*/
|
|
48
56
|
import { databases } from "harper";
|
|
57
|
+
import { stripUndeclaredMemoryAttributes } from "./memory-declared-attributes.js";
|
|
49
58
|
import { withDetachedTxn } from "./table-helpers.js";
|
|
50
59
|
import { resolveReadScope } from "./memory-read-scope.js";
|
|
51
60
|
/**
|
|
@@ -58,6 +67,15 @@ export const MAX_USAGE_IDS_PER_CALL = 20;
|
|
|
58
67
|
/**
|
|
59
68
|
* One (agentId, memoryId) contribution — the shared ledger-write core.
|
|
60
69
|
*
|
|
70
|
+
* READ-SCOPE GATE: `canRead` is the contributing agent's read-scope predicate
|
|
71
|
+
* (`resolveReadScope(agentId).isAllowed`, resolved once per batch by the
|
|
72
|
+
* caller). The memory row is checked against it before the ledger row is
|
|
73
|
+
* written, and the re-fetched row is checked again before the count is
|
|
74
|
+
* bumped. At the first read, a memory that does not exist and a memory the
|
|
75
|
+
* agent cannot read end on the same silent no-op: no ledger row, no count
|
|
76
|
+
* change. At the re-read the ledger row is already written; a rejection there
|
|
77
|
+
* leaves the row in place and skips the count bump.
|
|
78
|
+
*
|
|
61
79
|
* Ledger-row-create FIRST, THEN the Memory.usageCount bump — so a crash
|
|
62
80
|
* between the two leaves the SAFE failure state (ledger row exists, count
|
|
63
81
|
* not yet bumped: a later retry just re-checks and no-ops) rather than the
|
|
@@ -85,11 +103,11 @@ export const MAX_USAGE_IDS_PER_CALL = 20;
|
|
|
85
103
|
* inflation), and orthogonal to the anti-gaming properties the cap/floor
|
|
86
104
|
* and dedup ledger actually defend.
|
|
87
105
|
*
|
|
88
|
-
* Called by
|
|
89
|
-
* recordCitations() below (citation-on-write) — identical ledger
|
|
90
|
-
* regardless of which surface triggered the contribution.
|
|
106
|
+
* Called by recordUsageBatch() (POST /RecordUsage, explicit usage feedback)
|
|
107
|
+
* and by recordCitations() below (citation-on-write) — identical ledger
|
|
108
|
+
* semantics regardless of which surface triggered the contribution.
|
|
91
109
|
*/
|
|
92
|
-
export async function recordUsageContribution(ctx, agentId, memoryId, attribution, now) {
|
|
110
|
+
export async function recordUsageContribution(ctx, agentId, memoryId, attribution, now, canRead) {
|
|
93
111
|
const ledgerId = `${agentId}:${memoryId}`;
|
|
94
112
|
// Bypasses resources/MemoryUsage.ts's own auth wrapper by design — this
|
|
95
113
|
// IS the trusted internal caller that resource's module doc describes
|
|
@@ -98,9 +116,11 @@ export async function recordUsageContribution(ctx, agentId, memoryId, attributio
|
|
|
98
116
|
const existingContribution = await withDetachedTxn(ctx, () => databases.flair.MemoryUsage.get(ledgerId)).catch(() => null);
|
|
99
117
|
if (existingContribution)
|
|
100
118
|
return; // already counted by this agent — silent no-op
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
119
|
+
// Absent, unreadable, or a failed read: ONE silent no-op branch (no
|
|
120
|
+
// enumeration). A read failure is never evidence the memory is readable.
|
|
121
|
+
const memory = await withDetachedTxn(ctx, () => databases.flair.Memory.get(memoryId)).catch(() => null);
|
|
122
|
+
if (!memory || !canRead(memory))
|
|
123
|
+
return;
|
|
104
124
|
const ledgerRecord = { id: ledgerId, agentId, memoryId, createdAt: now };
|
|
105
125
|
if (attribution)
|
|
106
126
|
ledgerRecord.attribution = attribution;
|
|
@@ -120,17 +140,23 @@ export async function recordUsageContribution(ctx, agentId, memoryId, attributio
|
|
|
120
140
|
// this write path smuggle OTHER field changes through instead of just the
|
|
121
141
|
// count (RecordUsage.ts module doc's "WHY THIS IS ITS OWN ENDPOINT").
|
|
122
142
|
const fresh = await withDetachedTxn(ctx, () => databases.flair.Memory.get(memoryId)).catch(() => null);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
143
|
+
// Deleted, or moved out of the agent's read scope, between the check above
|
|
144
|
+
// and now — the count is not bumped (the ledger row written above stays).
|
|
145
|
+
// The count is only ever bumped on a row in the agent's read scope.
|
|
146
|
+
if (!fresh || !canRead(fresh))
|
|
147
|
+
return;
|
|
148
|
+
const usageRow = { ...fresh, usageCount: (fresh.usageCount ?? 0) + 1 };
|
|
149
|
+
stripUndeclaredMemoryAttributes(usageRow);
|
|
150
|
+
await withDetachedTxn(ctx, () => databases.flair.Memory.put(usageRow));
|
|
126
151
|
}
|
|
127
152
|
/**
|
|
128
|
-
* Default record fetch for
|
|
129
|
-
*
|
|
130
|
-
*
|
|
153
|
+
* Default record fetch for the read-scope gates in this module
|
|
154
|
+
* (recordCitations() and the ledger read helpers below) — the RAW Memory
|
|
155
|
+
* table (bypassing the Memory RESOURCE class's own read wrapper; the same
|
|
156
|
+
* trusted-internal-caller pattern recordUsageContribution() uses) so
|
|
131
157
|
* `scope.isAllowed` runs against the raw stored record. Never throws: a
|
|
132
|
-
* fetch failure reads as "not found", which
|
|
133
|
-
* identical to a nonexistent id.
|
|
158
|
+
* fetch failure reads as "not found", which every gate treats as not
|
|
159
|
+
* readable — identical to a nonexistent id.
|
|
134
160
|
*/
|
|
135
161
|
async function fetchMemoryForScopeCheck(ctx, memoryId) {
|
|
136
162
|
return withDetachedTxn(ctx, () => databases.flair.Memory.get(memoryId)).catch(() => null);
|
|
@@ -207,15 +233,14 @@ export async function recordCitations(ctx, auth, usedMemoryIds, now, recordFn =
|
|
|
207
233
|
// flair#775 slice 1 read-scope gate. The raw fetch + in-process
|
|
208
234
|
// predicate is deliberately ONE branch for both "doesn't exist" and
|
|
209
235
|
// "exists but out of the writer's read scope" — uniform silent drop
|
|
210
|
-
// (see the module doc). recordUsageContribution
|
|
211
|
-
//
|
|
212
|
-
//
|
|
213
|
-
//
|
|
214
|
-
// batch.
|
|
236
|
+
// (see the module doc). recordUsageContribution applies the same
|
|
237
|
+
// predicate again to the rows it reads itself (it is passed
|
|
238
|
+
// `scope.isAllowed`), so this pre-check is a second point-lookup of
|
|
239
|
+
// the same record — accepted on a ≤20-id advisory batch.
|
|
215
240
|
const record = await fetchFn(ctx, id);
|
|
216
241
|
if (!record || !scope.isAllowed(record))
|
|
217
242
|
continue;
|
|
218
|
-
await recordFn(ctx, auth.agentId, id, undefined, now);
|
|
243
|
+
await recordFn(ctx, auth.agentId, id, undefined, now, scope.isAllowed);
|
|
219
244
|
}
|
|
220
245
|
catch (err) {
|
|
221
246
|
// Never let one bad id stop the batch — same no-op-on-error discipline
|
|
@@ -224,3 +249,106 @@ export async function recordCitations(ctx, auth, usedMemoryIds, now, recordFn =
|
|
|
224
249
|
}
|
|
225
250
|
}
|
|
226
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* POST /RecordUsage's batch (resources/RecordUsage.ts) — credits each id in
|
|
254
|
+
* `memoryIds` through `recordFn` (the real `recordUsageContribution` by
|
|
255
|
+
* default) under the CALLER's read scope.
|
|
256
|
+
*
|
|
257
|
+
* - The caller's scope is resolved ONCE per batch via resolveReadScope — the
|
|
258
|
+
* scope Memory.get() applies to non-admin readers, applied here to admin
|
|
259
|
+
* callers too — and its `isAllowed` predicate is handed to every
|
|
260
|
+
* contribution, which applies it to each Memory row it reads.
|
|
261
|
+
* - Fail CLOSED: if the scope cannot be resolved, nothing in the batch is
|
|
262
|
+
* credited. The endpoint's response does not change (RecordUsage.ts's
|
|
263
|
+
* "NO ID ENUMERATION"), so a failure is visible only in the server log.
|
|
264
|
+
* - Each id is credited independently: one id throwing never stops the
|
|
265
|
+
* rest, and the failure is logged server-side, never surfaced to the
|
|
266
|
+
* caller.
|
|
267
|
+
*
|
|
268
|
+
* Input validation, the per-call cap and the attribution sanitizer stay in
|
|
269
|
+
* RecordUsage.post(); `memoryIds` arrives here already validated and deduped.
|
|
270
|
+
* `recordFn` / `scopeFn` are unit-test injection seams
|
|
271
|
+
* (test/unit/usage-recording.test.ts) — the production caller passes neither.
|
|
272
|
+
*/
|
|
273
|
+
export async function recordUsageBatch(ctx, agentId, memoryIds, attribution, now, recordFn = recordUsageContribution, scopeFn = resolveReadScope) {
|
|
274
|
+
let scope;
|
|
275
|
+
try {
|
|
276
|
+
scope = await scopeFn(agentId);
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
console.error("RecordUsage.post: read-scope resolution failed — batch not recorded (no-op)", { err });
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
for (const memoryId of memoryIds) {
|
|
283
|
+
try {
|
|
284
|
+
await recordFn(ctx, agentId, memoryId, attribution, now, scope.isAllowed);
|
|
285
|
+
}
|
|
286
|
+
catch (err) {
|
|
287
|
+
// Never let one bad id fail the whole batch, and never let an internal
|
|
288
|
+
// error leak existence information either — log server-side, collapse
|
|
289
|
+
// to the same no-op the response already returns for every other
|
|
290
|
+
// outcome.
|
|
291
|
+
console.error("RecordUsage.post: failed to record usage (treated as no-op)", { memoryId, err });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
// ─── The ledger's read rule (resources/MemoryUsage.ts) ──────────────────────
|
|
296
|
+
//
|
|
297
|
+
// A non-admin reader sees its own MemoryUsage row only while the memory the row
|
|
298
|
+
// names exists and is in the reader's read scope. A row about a memory the
|
|
299
|
+
// reader cannot read reads exactly like a row that does not exist. A failed
|
|
300
|
+
// scope resolution or a failed Memory read hides the row: unknown evidence is
|
|
301
|
+
// never treated as readable. Admin and trusted internal ledger reads do not go
|
|
302
|
+
// through these helpers (resources/MemoryUsage.ts leaves them unfiltered).
|
|
303
|
+
/**
|
|
304
|
+
* Is this one ledger row about a memory `scope` can read? A row with no
|
|
305
|
+
* `memoryId`, a memory that does not exist, and a failed read are all `false`.
|
|
306
|
+
*/
|
|
307
|
+
async function isLedgerRowAboutReadableMemory(ctx, row, scope, fetchFn) {
|
|
308
|
+
const memoryId = row?.memoryId;
|
|
309
|
+
if (typeof memoryId !== "string" || memoryId.length === 0)
|
|
310
|
+
return false;
|
|
311
|
+
try {
|
|
312
|
+
const memory = await fetchFn(ctx, memoryId);
|
|
313
|
+
return !!memory && scope.isAllowed(memory) === true;
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* By-id form of the ledger read rule, for MemoryUsage.get(): resolves the
|
|
321
|
+
* reader's scope and checks the one row. `false` on any failure.
|
|
322
|
+
* `scopeFn` / `fetchFn` are unit-test injection seams.
|
|
323
|
+
*/
|
|
324
|
+
export async function isLedgerRowVisible(ctx, readerId, row, scopeFn = resolveReadScope, fetchFn = fetchMemoryForScopeCheck) {
|
|
325
|
+
let scope;
|
|
326
|
+
try {
|
|
327
|
+
scope = await scopeFn(readerId);
|
|
328
|
+
}
|
|
329
|
+
catch (err) {
|
|
330
|
+
console.error("MemoryUsage.get: read-scope resolution failed — row hidden", { err });
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
return isLedgerRowAboutReadableMemory(ctx, row, scope, fetchFn);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Collection form of the ledger read rule, for MemoryUsage.search(): yields
|
|
337
|
+
* only the rows of `rows` about memories the reader can read, in source
|
|
338
|
+
* order. The scope is resolved once; if that fails, nothing is yielded.
|
|
339
|
+
* `scopeFn` / `fetchFn` are unit-test injection seams.
|
|
340
|
+
*/
|
|
341
|
+
export async function* readableLedgerRows(ctx, readerId, rows, scopeFn = resolveReadScope, fetchFn = fetchMemoryForScopeCheck) {
|
|
342
|
+
let scope;
|
|
343
|
+
try {
|
|
344
|
+
scope = await scopeFn(readerId);
|
|
345
|
+
}
|
|
346
|
+
catch (err) {
|
|
347
|
+
console.error("MemoryUsage.search: read-scope resolution failed — no rows returned", { err });
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
for await (const row of rows) {
|
|
351
|
+
if (await isLedgerRowAboutReadableMemory(ctx, row, scope, fetchFn))
|
|
352
|
+
yield row;
|
|
353
|
+
}
|
|
354
|
+
}
|