@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.
Files changed (153) hide show
  1. package/README.md +19 -20
  2. package/SECURITY.md +4 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli.js +1800 -293
  5. package/dist/commands/agent.js +22 -15
  6. package/dist/commands/bridge.js +40 -3
  7. package/dist/commands/doctor.js +214 -4
  8. package/dist/commands/federation.js +265 -38
  9. package/dist/commands/hook.js +10 -2
  10. package/dist/commands/init.js +179 -48
  11. package/dist/commands/memory.js +24 -2
  12. package/dist/commands/quality.js +26 -18
  13. package/dist/commands/service.js +137 -22
  14. package/dist/commands/status.js +114 -3
  15. package/dist/commands/upgrade.js +204 -84
  16. package/dist/doctor-client.js +50 -4
  17. package/dist/federation/scheduler.js +253 -4
  18. package/dist/install/clients.js +89 -23
  19. package/dist/install/global-bin-path.js +26 -6
  20. package/dist/lib/atomic-write.js +256 -0
  21. package/dist/lib/auth-resolve.js +46 -0
  22. package/dist/lib/daemon-liveness.js +61 -0
  23. package/dist/lib/doctor-run.js +5 -0
  24. package/dist/lib/embed-gpu-doctor.js +49 -26
  25. package/dist/lib/federation-memory-attributes.js +15 -0
  26. package/dist/lib/init-admin-pass.js +4 -2
  27. package/dist/lib/init-listener-environ.js +38 -0
  28. package/dist/lib/init-occupied-listener.js +165 -0
  29. package/dist/lib/instance-identity-row.js +580 -0
  30. package/dist/lib/launchd-domain-preflight.js +448 -0
  31. package/dist/lib/launchd-management.js +176 -6
  32. package/dist/lib/launchd-repair.js +95 -0
  33. package/dist/lib/memory-attributes.js +77 -0
  34. package/dist/lib/node-alias-path.js +95 -0
  35. package/dist/lib/npm-registry.js +119 -6
  36. package/dist/lib/owned-pins.js +20 -6
  37. package/dist/lib/redact-token-id.js +197 -0
  38. package/dist/lib/service-repoint-apply.js +267 -0
  39. package/dist/lib/service-repoint.js +575 -0
  40. package/dist/lib/toml-string-array.js +104 -0
  41. package/dist/lib/tree-divergence.js +716 -0
  42. package/dist/lib/upgrade-plain-tree.js +18 -8
  43. package/dist/lib/upgrade-prior-liveness.js +69 -0
  44. package/dist/lib/upgrade-rollback.js +116 -0
  45. package/dist/rem/runner.js +11 -0
  46. package/dist/resources/Agent.js +27 -14
  47. package/dist/resources/AgentSeed.js +39 -2
  48. package/dist/resources/Asset.js +3 -11
  49. package/dist/resources/Credential.js +4 -10
  50. package/dist/resources/Federation.js +299 -127
  51. package/dist/resources/Integration.js +8 -32
  52. package/dist/resources/Memory.js +623 -86
  53. package/dist/resources/MemoryArchive.js +9 -0
  54. package/dist/resources/MemoryBootstrap.js +23 -12
  55. package/dist/resources/MemoryCandidate.js +3 -11
  56. package/dist/resources/MemoryDedupStats.js +1 -1
  57. package/dist/resources/MemoryFeed.js +214 -5
  58. package/dist/resources/MemoryGrant.js +19 -40
  59. package/dist/resources/MemoryHostSource.js +90 -0
  60. package/dist/resources/MemoryMaintenance.js +121 -32
  61. package/dist/resources/MemoryReflect.js +4 -1
  62. package/dist/resources/MemoryReindex.js +7 -4
  63. package/dist/resources/MemoryUsage.js +55 -18
  64. package/dist/resources/Presence.js +18 -10
  65. package/dist/resources/RecordUsage.js +30 -40
  66. package/dist/resources/Relationship.js +170 -89
  67. package/dist/resources/SemanticSearch.js +44 -19
  68. package/dist/resources/Soul.js +31 -19
  69. package/dist/resources/XAA.js +7 -3
  70. package/dist/resources/agent-auth.js +16 -10
  71. package/dist/resources/auth-middleware.js +164 -50
  72. package/dist/resources/auto-promote-lib.js +4 -4
  73. package/dist/resources/bm25-index-service.js +246 -32
  74. package/dist/resources/bm25-status.js +132 -0
  75. package/dist/resources/bm25.js +13 -14
  76. package/dist/resources/ed25519-auth.js +11 -54
  77. package/dist/resources/embed-gpu.js +262 -47
  78. package/dist/resources/embeddings-boot.js +52 -17
  79. package/dist/resources/federation-classify.js +12 -0
  80. package/dist/resources/federation-cleanup.js +289 -51
  81. package/dist/resources/federation-crypto.js +65 -19
  82. package/dist/resources/health.js +105 -22
  83. package/dist/resources/host-pointer/registry.js +35 -0
  84. package/dist/resources/host-pointer-adapter.js +15 -0
  85. package/dist/resources/host-source-visibility.js +167 -0
  86. package/dist/resources/host-source.js +151 -0
  87. package/dist/resources/in-process-api.js +2 -1
  88. package/dist/resources/instance-create-lock.js +363 -0
  89. package/dist/resources/instance-identity-rows.js +43 -0
  90. package/dist/resources/instance-identity.js +97 -12
  91. package/dist/resources/mcp-handler.js +155 -51
  92. package/dist/resources/mcp-tool-arguments.js +83 -0
  93. package/dist/resources/mcp-tools.js +28 -25
  94. package/dist/resources/memory-consolidate-lib.js +3 -1
  95. package/dist/resources/memory-declared-attributes.js +103 -0
  96. package/dist/resources/memory-feed-lib.js +5 -1
  97. package/dist/resources/memory-host-source.js +163 -0
  98. package/dist/resources/memory-visibility.js +10 -7
  99. package/dist/resources/migrations/synthetic-test-migration.js +4 -1
  100. package/dist/resources/migrations/visibility-backfill.js +4 -1
  101. package/dist/resources/originator-instance.js +235 -0
  102. package/dist/resources/promotion-stamp.js +2 -0
  103. package/dist/resources/provenance.js +111 -11
  104. package/dist/resources/rate-limit.js +6 -4
  105. package/dist/resources/record-owner-guard.js +19 -0
  106. package/dist/resources/record-type-kit.js +44 -23
  107. package/dist/resources/record-types.js +6 -6
  108. package/dist/resources/relay-ops.js +28 -3
  109. package/dist/resources/replay-store.js +289 -0
  110. package/dist/resources/request-transaction.js +78 -0
  111. package/dist/resources/search-readiness.js +26 -22
  112. package/dist/resources/semantic-retrieval-core.js +103 -4
  113. package/dist/resources/table-helpers.js +33 -0
  114. package/dist/resources/table-patch-policy.js +109 -0
  115. package/dist/resources/table-patches.js +17 -0
  116. package/dist/resources/table-post-policy.js +138 -0
  117. package/dist/resources/table-posts.js +22 -0
  118. package/dist/resources/table-subscription-policy.js +135 -0
  119. package/dist/resources/table-subscriptions.js +19 -0
  120. package/dist/resources/tool-descriptors/index.js +15 -15
  121. package/dist/resources/trust-block.js +10 -3
  122. package/dist/resources/usage-recording.js +169 -41
  123. package/dist/src/lib/instance-identity-row.js +580 -0
  124. package/dist/src/lib/memory-attributes.js +77 -0
  125. package/dist/src/lib/redact-token-id.js +197 -0
  126. package/docs/api-reference.md +80 -16
  127. package/docs/auth.md +5 -5
  128. package/docs/claude-code.md +137 -6
  129. package/docs/deploying-on-fabric.md +6 -3
  130. package/docs/deployment.md +1 -1
  131. package/docs/embedding-in-a-harper-app.md +3 -3
  132. package/docs/federation.md +17 -10
  133. package/docs/hosted-on-fabric.md +4 -3
  134. package/docs/integrations.md +28 -19
  135. package/docs/mcp-clients.md +26 -32
  136. package/docs/n8n.md +8 -8
  137. package/docs/notes/mcp-oauth-model2.md +27 -18
  138. package/docs/openclaw.md +29 -28
  139. package/docs/quickstart.md +5 -0
  140. package/docs/releasing.md +134 -2
  141. package/docs/spoke-bringup.md +14 -11
  142. package/docs/standalone-local.md +2 -2
  143. package/docs/supply-chain-policy.md +28 -10
  144. package/docs/system-requirements.md +1 -1
  145. package/docs/troubleshooting.md +11 -0
  146. package/docs/upgrade.md +189 -63
  147. package/package.json +9 -5
  148. package/schemas/agent.graphql +9 -6
  149. package/schemas/federation.graphql +2 -11
  150. package/schemas/memory.graphql +106 -17
  151. package/schemas/replay.graphql +18 -0
  152. package/templates/launchd/start-flair-with-admin-pass.sh +22 -0
  153. 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 an EXACT extraction of what was
18
- * RecordUsage.ts's private `_recordOne()` — see its doc below for the
19
- * ledger-then-count ordering, the individually-wrapped `withDetachedTxn`
20
- * discipline, and the accepted best-effort race on the final
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
- * recordCitations() additionally validates each cited id against the
34
- * WRITER's own read-scope before crediting (flair#775, a Kern+Sherlock
35
- * binding condition on the locked design): citing a memory the writer cannot
36
- * read is silently dropped, uniformly with a nonexistent id — never an
37
- * error, never a distinguishable code path (an error, or any response/shape
38
- * difference, would leak "that id exists but you can't see it").
39
- * POST /RecordUsage is DELIBERATELY not scope-gated — its module doc
40
- * establishes usage feedback as a cross-agent contract (agent B reports
41
- * using agent A's memory regardless of A's visibility setting);
42
- * citation-on-write is a separate write surface with a narrower threat
43
- * model (the ids ride along on the WRITER's own memory-creation call, so
44
- * crediting an unreadable id would let a writer both probe for and boost
45
- * memories it cannot see). So the scope gate lives HERE, not retrofitted
46
- * onto recordUsageContribution() — do not "unify" the two surfaces.
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 RecordUsage.post() (explicit usage feedback) and by
89
- * recordCitations() below (citation-on-write) — identical ledger semantics
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
- const memoryExists = await withDetachedTxn(ctx, () => databases.flair.Memory.get(memoryId)).catch(() => null);
102
- if (!memoryExists)
103
- return; // no such memory — silent no-op (no enumeration)
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
- if (!fresh)
124
- return; // deleted between the checks above and now — no-op
125
- await withDetachedTxn(ctx, () => databases.flair.Memory.put({ ...fresh, usageCount: (fresh.usageCount ?? 0) + 1 }));
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 recordCitations()'s read-scope gate — the RAW
129
- * Memory table (bypassing the Memory RESOURCE class's own read wrapper; the
130
- * same trusted-internal-caller pattern recordUsageContribution() uses) so
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 the gate silently drops —
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's own existence
211
- // re-check makes this a second point-lookup of the same record;
212
- // accepted — keeping the shared ledger core byte-identical for
213
- // RecordUsage.post() is worth two point-lookups on a ≤20-id advisory
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
+ }