niceeval 0.16.2-canary.98 → 0.16.3-canary.99

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 (40) hide show
  1. package/dist/inspection/facts.cjs +86 -31
  2. package/dist/inspection/facts.cjs.map +1 -1
  3. package/dist/inspection/facts.d.cts +2 -2
  4. package/dist/inspection/facts.d.mts +2 -2
  5. package/dist/inspection/facts.d.ts +2 -2
  6. package/dist/inspection/overview.cjs +2 -1
  7. package/dist/inspection/overview.cjs.map +1 -1
  8. package/dist/inspection/project-source.cjs +28 -19
  9. package/dist/inspection/project-source.cjs.map +1 -1
  10. package/dist/inspection/protocol.d.cts +17 -17
  11. package/dist/inspection/protocol.d.mts +17 -17
  12. package/dist/inspection/protocol.d.ts +17 -17
  13. package/dist/inspection/select.cjs +10 -6
  14. package/dist/inspection/select.cjs.map +1 -1
  15. package/dist/inspection/source.cjs +4 -2
  16. package/dist/inspection/source.cjs.map +1 -1
  17. package/dist/inspection/source.d.cts +1 -0
  18. package/dist/inspection/source.d.mts +1 -0
  19. package/dist/inspection/source.d.ts +1 -0
  20. package/dist/record/sqlite/database.cjs +2 -8
  21. package/dist/record/sqlite/database.cjs.map +1 -1
  22. package/dist/record/sqlite/index.cjs +13 -11
  23. package/dist/record/sqlite/index.cjs.map +1 -1
  24. package/dist/record/sqlite/index.d.cts +4 -2
  25. package/dist/record/sqlite/index.d.mts +4 -2
  26. package/dist/record/sqlite/index.d.ts +4 -2
  27. package/dist/record/sqlite/storage.cjs +118 -64
  28. package/dist/record/sqlite/storage.cjs.map +1 -1
  29. package/dist/record/sqlite/storage.d.cts +12 -5
  30. package/dist/record/sqlite/storage.d.mts +12 -5
  31. package/dist/record/sqlite/storage.d.ts +12 -5
  32. package/dist/record/sqlite/storage.js +48 -44
  33. package/dist/record/sqlite/types.cjs.map +1 -1
  34. package/dist/record/sqlite/types.d.cts +1 -1
  35. package/dist/record/sqlite/types.d.mts +1 -1
  36. package/dist/record/sqlite/types.d.ts +1 -1
  37. package/dist/view/cli/contribution.cjs +3 -2
  38. package/dist/view/cli/contribution.cjs.map +1 -1
  39. package/dist/view/function-runtime.mjs +251 -464
  40. package/package.json +1 -1
@@ -20,9 +20,25 @@ const protocol_ts_1 = require("../record/attachment/protocol.cjs");
20
20
  const core_ts_1 = require("../record/codec/core.cjs");
21
21
  const current_ts_1 = require("../record/family/current.cjs");
22
22
  const codec_ts_1 = require("./codec.cjs");
23
+ const bytes_ts_1 = require("./bytes.cjs");
23
24
  const RUN_PAGE_SIZE = 100;
24
25
  const ATTEMPT_CANDIDATE_RUN_LIMIT = 64;
25
26
  const ATTEMPT_TARGET_MEMBER_LIMIT = 256;
27
+ const decodedRuns = new WeakMap();
28
+ function readInspectionRun(source, runId) {
29
+ let cache = decodedRuns.get(source);
30
+ if (cache === undefined)
31
+ decodedRuns.set(source, cache = new Map());
32
+ const cached = cache.get(runId);
33
+ if (cached !== undefined)
34
+ return cached;
35
+ const physical = source.readSealedRunCore(runId);
36
+ if (physical === undefined)
37
+ return undefined;
38
+ const decoded = decodeInspectionRun(source, physical);
39
+ cache.set(runId, decoded);
40
+ return decoded;
41
+ }
26
42
  /**
27
43
  * Pins the source cutoff, exhausts the fixed Run-summary pagination, then
28
44
  * reads and strictly decodes every Run Core in that exact sealed generation.
@@ -63,11 +79,11 @@ function loadInspectionRuns(source) {
63
79
  throw factsError("Run pagination did not close the pinned sealed cutoff");
64
80
  }
65
81
  return Object.freeze(summaries.map((summary) => {
66
- const physical = source.readSealedRunCore(summary.runId);
67
- if (physical === undefined) {
82
+ const run = readInspectionRun(source, summary.runId);
83
+ if (run === undefined) {
68
84
  throw factsError(`Sealed Run ${summary.runId} disappeared from the pinned cutoff`);
69
85
  }
70
- return decodeInspectionRun(source, physical);
86
+ return run;
71
87
  }));
72
88
  }
73
89
  /** Reads a bounded, explicit Run selection without changing its caller order. */
@@ -75,9 +91,9 @@ function loadSelectedInspectionRuns(source, runIds) {
75
91
  const cutoff = source.cutoff();
76
92
  const loaded = [];
77
93
  for (const runId of new Set(runIds)) {
78
- const physical = source.readSealedRunCore(runId);
79
- if (physical !== undefined)
80
- loaded.push(decodeInspectionRun(source, physical));
94
+ const run = readInspectionRun(source, runId);
95
+ if (run !== undefined)
96
+ loaded.push(run);
81
97
  }
82
98
  requireCutoff(source.cutoff(), cutoff);
83
99
  return Object.freeze(loaded);
@@ -88,10 +104,7 @@ function loadInspectionRunResource(source, runId) {
88
104
  const resource = source.readRunResource(runId);
89
105
  if (resource === undefined)
90
106
  return undefined;
91
- const physical = source.readSealedRunCore(runId);
92
- const published = physical === undefined
93
- ? undefined
94
- : decodeInspectionRun(source, physical);
107
+ const published = readInspectionRun(source, runId);
95
108
  requireCutoff(source.cutoff(), cutoff);
96
109
  if (resource.published > 0 && published === undefined) {
97
110
  throw factsError(`Run ${runId} has published bindings without a readable Core`);
@@ -119,9 +132,9 @@ function validateRunResourceCore(resource, published) {
119
132
  }
120
133
  }
121
134
  }
122
- /** Strictly decodes all Core documents and Attachment JSON for one sealed Run. */
135
+ /** Strictly decodes Core, then decodes each Attachment only on first use. */
123
136
  function decodeInspectionRun(source, physical) {
124
- const run = decodedRight((0, core_ts_1.decodeRunDocument)(parseJson(physical.runCoreBytes, "Run Core")), "Run Core is invalid");
137
+ const run = decodedRight((0, core_ts_1.decodeRunDocument)(parseVerifiedJson(physical.runCoreBytes, physical.runCoreDigest, "Run Core")), "Run Core is invalid");
125
138
  if (run.runId !== physical.runId) {
126
139
  throw factsError("Run Core identity does not match its sealed row");
127
140
  }
@@ -129,7 +142,7 @@ function decodeInspectionRun(source, physical) {
129
142
  throw factsError("Run Core Slot rows do not match its expected denominator");
130
143
  }
131
144
  for (const [index, stored] of physical.slots.entries()) {
132
- const decoded = effect_1.Schema.decodeUnknownResult(core_ts_1.RecordSlotIdentitySchema, core_ts_1.RecordExactParseOptions)(parseJson(stored.coreBytes, "Slot Core"));
145
+ const decoded = effect_1.Schema.decodeUnknownResult(core_ts_1.RecordSlotIdentitySchema, core_ts_1.RecordExactParseOptions)(parseVerifiedJson(stored.coreBytes, stored.coreDigest, "Slot Core"));
133
146
  const slot = decodedRight(decoded, "Slot Core is invalid");
134
147
  const expected = run.expectedSlots[index];
135
148
  if (expected === undefined ||
@@ -143,7 +156,7 @@ function decodeInspectionRun(source, physical) {
143
156
  }
144
157
  }
145
158
  const members = physical.members.map((stored) => {
146
- const member = decodedRight((0, core_ts_1.decodeMemberDocument)(parseJson(stored.coreBytes, "Member Core")), "Member Core is invalid");
159
+ const member = decodedRight((0, core_ts_1.decodeMemberDocument)(parseVerifiedJson(stored.coreBytes, stored.coreDigest, "Member Core")), "Member Core is invalid");
147
160
  if (member.slotId !== stored.slotId ||
148
161
  member.action !== stored.action ||
149
162
  (member.attempt?.originRunId ?? undefined) !== stored.originRunId ||
@@ -153,7 +166,7 @@ function decodeInspectionRun(source, physical) {
153
166
  return member;
154
167
  });
155
168
  const attempts = physical.attempts.map((stored) => {
156
- const attempt = decodedRight((0, core_ts_1.decodeAttemptDocument)(parseJson(stored.coreBytes, "Attempt Core")), "Attempt Core is invalid");
169
+ const attempt = decodedRight((0, core_ts_1.decodeAttemptDocument)(parseVerifiedJson(stored.coreBytes, stored.coreDigest, "Attempt Core")), "Attempt Core is invalid");
157
170
  if (attempt.attemptId !== stored.attemptId ||
158
171
  attempt.originRunId !== run.runId ||
159
172
  (0, attempt_locator_ts_1.encodeAttemptLocator)(attempt.attemptId) !== stored.attemptLocator) {
@@ -171,9 +184,19 @@ function decodeInspectionRun(source, physical) {
171
184
  !localAttemptIds.has(attachment.ownerAttemptId))) {
172
185
  throw factsError("Attachment ownership does not match its sealed Run");
173
186
  }
187
+ let value;
188
+ let decoded = false;
174
189
  return Object.freeze({
175
190
  physical: attachment,
176
- value: parseInspectionJson(attachment.canonicalBytes, "Attachment"),
191
+ get value() {
192
+ if (!decoded) {
193
+ verifyDigest(attachment.canonicalBytes, attachment.canonicalDigest, "Attachment");
194
+ verifyDigest(attachment.logicalInventoryBytes, attachment.inventoryDigest, "Attachment inventory");
195
+ value = parseInspectionJson(attachment.canonicalBytes, "Attachment");
196
+ decoded = true;
197
+ }
198
+ return value;
199
+ },
177
200
  });
178
201
  });
179
202
  return Object.freeze({
@@ -238,26 +261,50 @@ function resolveInspectionAttempt(source, locator) {
238
261
  targets: Object.freeze(targets),
239
262
  });
240
263
  }
241
- /** Resolves one already loaded target Member without consulting a platform index. */
264
+ const memberIndexes = new WeakMap();
265
+ function memberIndex(runs) {
266
+ const cached = memberIndexes.get(runs);
267
+ if (cached !== undefined)
268
+ return cached;
269
+ const origins = new Map(runs.map((run) => [run.run.runId, {
270
+ run, attempts: new Map(run.attempts.map((attempt) => [attempt.attemptId, attempt])),
271
+ members: new Map(run.members.map((member) => [member.slotId, member])),
272
+ }]));
273
+ const targets = new Map();
274
+ for (const run of runs)
275
+ for (const member of run.members) {
276
+ if (member.attempt === null)
277
+ continue;
278
+ const { originRunId, attemptId } = member.attempt;
279
+ let byAttempt = targets.get(originRunId);
280
+ if (byAttempt === undefined)
281
+ targets.set(originRunId, byAttempt = new Map());
282
+ let members = byAttempt.get(attemptId);
283
+ if (members === undefined)
284
+ byAttempt.set(attemptId, members = []);
285
+ members.push(Object.freeze({ run, member }));
286
+ }
287
+ for (const byAttempt of targets.values())
288
+ for (const members of byAttempt.values())
289
+ Object.freeze(members);
290
+ const index = { origins, targets };
291
+ memberIndexes.set(runs, index);
292
+ return index;
293
+ }
294
+ /** Resolves already loaded facts through one shared identity index. */
242
295
  function resolveInspectionMemberAttempt(runs, target, member) {
243
296
  if (member.attempt === null)
244
297
  return undefined;
245
- const origin = runs.find(({ run }) => run.runId === member.attempt.originRunId);
246
- const attempt = origin?.attempts.find((candidate) => candidate.attemptId === member.attempt.attemptId &&
247
- candidate.originRunId === member.attempt.originRunId);
248
- if (origin === undefined || attempt === undefined)
298
+ const index = memberIndex(runs);
299
+ const origin = index.origins.get(member.attempt.originRunId);
300
+ const attempt = origin?.attempts.get(member.attempt.attemptId);
301
+ if (origin === undefined || attempt === undefined || attempt.originRunId !== member.attempt.originRunId)
249
302
  return undefined;
250
- const locator = (0, attempt_locator_ts_1.encodeAttemptLocator)(attempt.attemptId);
251
- const targets = runs.flatMap((run) => targetMembers(run, attempt).map((candidate) => Object.freeze({ run, member: candidate })));
252
- if (!targets.some(({ run, member: candidate }) => run.run.runId === target.run.runId && candidate.slotId === member.slotId)) {
303
+ const targets = index.targets.get(attempt.originRunId)?.get(attempt.attemptId) ?? [];
304
+ const targetMember = index.origins.get(target.run.runId)?.members.get(member.slotId);
305
+ if (targetMember?.attempt?.originRunId !== attempt.originRunId || targetMember.attempt.attemptId !== attempt.attemptId)
253
306
  return undefined;
254
- }
255
- return Object.freeze({
256
- attempt,
257
- origin,
258
- locator,
259
- targets: Object.freeze(targets),
260
- });
307
+ return Object.freeze({ attempt, origin: origin.run, locator: (0, attempt_locator_ts_1.encodeAttemptLocator)(attempt.attemptId), targets });
261
308
  }
262
309
  function attemptAttachment(resolved, family) {
263
310
  return resolved.origin.attachments.find(({ physical }) => physical.ownerKind === "attempt" &&
@@ -469,4 +516,12 @@ function factsError(reason, cause) {
469
516
  function compareText(left, right) {
470
517
  return left < right ? -1 : left > right ? 1 : 0;
471
518
  }
519
+ function verifyDigest(bytes, digest, label) {
520
+ if (new bytes_ts_1.InspectionSha256().update(bytes).digestHex() !== digest)
521
+ throw factsError(`${label} digest is invalid`);
522
+ }
523
+ function parseVerifiedJson(bytes, digest, label) {
524
+ verifyDigest(bytes, digest, label);
525
+ return parseJson(bytes, label);
526
+ }
472
527
  //# sourceMappingURL=facts.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"facts.js","sourceRoot":"","sources":["facts.ts"],"names":[],"mappings":";;AAmEA,gDAuCC;AAED,gEAUC;AAED,8DAgBC;AAqBD,kDAgEC;AAID,4DAiDC;AAED,wEAmBC;AACD,8CAIC;AACD,sCAEC;AAKD,4DA+BC;AAnVD,gDAAgD;AAChD,wDAAwD;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AC,CAAC,SAAS,CAAC;AACpB,CAAC;AACD,SAAS,YAAY,CAAC,KAAc,EAAE,GAAW;IAC7C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACvE,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACzD,CAAC;AACD,SAAS,KAAK,CAAC,IAAY,EAAE,OAAe;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5C,CAAC;AACD,SAAS,UAAU,CAAC,MAAc,EAAE,KAAe;IAC/C,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1E,CAAC;AACD,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa;IAC5C,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC","sourcesContent":["// @concord-file ne-eval-inspection-facts-reader\n// @concord-implements docs/feature/inspection/README.md\n// @concord-implements docs/feature/inspection/architecture.md\n// @concord-implements docs/feature/inspection/use-case/inspection-check-completeness.md\nimport { Result, Schema } from \"effect\";\nimport { encodeAttemptLocator } from \"../attempt-locator.ts\";\nimport { mintRecordContentHandle, type RecordContentHandle, } from \"../record/attachment/content.ts\";\nimport { enumerateRecordAttachmentClosure, hydrateRecordAttachmentCurrent, mintRecordAttachmentReference, RecordAttachmentReference, recordAttachmentReferenceWire, } from \"../record/attachment/protocol.ts\";\nimport { decodeAttemptDocument, decodeMemberDocument, decodeRunDocument, RecordExactParseOptions, RecordSlotIdentitySchema, } from \"../record/codec/core.ts\";\nimport { NiceEvalCurrentRecordAttachments, NiceEvalRecordAttachments, } from \"../record/family/current.ts\";\nimport type { AssertionsAttachment } from \"../record/family/assertions/definition.ts\";\nimport type { AttemptDocument, MemberDocument, RunDocument, } from \"../record/model/core.ts\";\nimport type { PersistedContentMetadata, SealedAttachmentMetadata, SealedRunCore, SealedRunCutoff, SealedRunSummary, } from \"../record/sqlite/types.ts\";\nimport { closeInspectionJson, isInspectionCodecError, type InspectionJson, } from \"./codec.ts\";\nimport type { InspectionFactSource } from \"./source.ts\";\nimport type { ReadableRunResource } from \"../run/storage/types.ts\";\nexport interface DecodedInspectionAttachment {\n readonly physical: SealedAttachmentMetadata;\n readonly value: InspectionJson;\n}\n/** A strictly decoded sealed Run with its browser-neutral reader capability. */\nexport interface LoadedInspectionRun {\n readonly source: InspectionFactSource;\n readonly physical: SealedRunCore;\n readonly run: RunDocument;\n readonly members: readonly MemberDocument[];\n readonly attempts: readonly AttemptDocument[];\n readonly attachments: readonly DecodedInspectionAttachment[];\n}\n/** Exact lifecycle resource plus its optional published Core at one cutoff. */\nexport interface LoadedInspectionRunResource {\n readonly source: InspectionFactSource;\n readonly resource: ReadableRunResource;\n readonly published?: LoadedInspectionRun;\n}\nexport interface InspectionAttemptTarget {\n readonly run: LoadedInspectionRun;\n readonly member: MemberDocument;\n}\n/** Exact origin Attempt plus every target membership visible to the resolver. */\nexport interface ResolvedInspectionAttempt {\n readonly attempt: AttemptDocument;\n readonly origin: LoadedInspectionRun;\n readonly locator: string;\n readonly targets: readonly InspectionAttemptTarget[];\n}\nexport type InspectionAssertionsRead = {\n readonly state: \"available\";\n readonly attachment: DecodedInspectionAttachment;\n readonly value: AssertionsAttachment;\n readonly contents: WeakMap<object, PersistedContentMetadata>;\n readonly issues: readonly InspectionJson[];\n} | {\n readonly state: \"not-recorded\" | \"unsupported\" | \"failed\";\n readonly attachment?: DecodedInspectionAttachment;\n readonly issues: readonly InspectionJson[];\n};\nconst RUN_PAGE_SIZE = 100;\nconst ATTEMPT_CANDIDATE_RUN_LIMIT = 64;\nconst ATTEMPT_TARGET_MEMBER_LIMIT = 256;\n/**\n * Pins the source cutoff, exhausts the fixed Run-summary pagination, then\n * reads and strictly decodes every Run Core in that exact sealed generation.\n */\n// @concord-code ne-eval-inspection-load-runs\n// @concord-implements docs/feature/inspection/architecture.md\n// @concord-implements docs/feature/inspection/use-case/inspection-check-completeness.md\nexport function loadInspectionRuns(source: InspectionFactSource): readonly LoadedInspectionRun[] {\n const cutoff = source.cutoff();\n const summaries: SealedRunSummary[] = [];\n const seen = new Set<string>();\n let afterRunId = \"\";\n for (;;) {\n const page = source.readSealedRunSummaryPage(afterRunId, RUN_PAGE_SIZE, cutoff.identity);\n requireCutoff(page.cutoff, cutoff);\n if (page.afterRunId !== afterRunId) {\n throw factsError(\"Run pagination returned a different cursor\");\n }\n let previous = afterRunId;\n for (const summary of page.summaries) {\n if (summary.runId <= previous || seen.has(summary.runId)) {\n throw factsError(\"Run pagination is not strictly ordered\");\n }\n seen.add(summary.runId);\n summaries.push(summary);\n previous = summary.runId;\n }\n if (page.nextAfterRunId === null)\n break;\n if (page.summaries.length === 0 ||\n page.nextAfterRunId !== page.summaries.at(-1)!.runId ||\n page.nextAfterRunId === afterRunId) {\n throw factsError(\"Run pagination returned an invalid continuation cursor\");\n }\n afterRunId = page.nextAfterRunId;\n }\n if (summaries.length !== cutoff.runCount) {\n throw factsError(\"Run pagination did not close the pinned sealed cutoff\");\n }\n return Object.freeze(summaries.map((summary) => {\n const physical = source.readSealedRunCore(summary.runId);\n if (physical === undefined) {\n throw factsError(`Sealed Run ${summary.runId} disappeared from the pinned cutoff`);\n }\n return decodeInspectionRun(source, physical);\n }));\n}\n/** Reads a bounded, explicit Run selection without changing its caller order. */\nexport function loadSelectedInspectionRuns(source: InspectionFactSource, runIds: readonly string[]): readonly LoadedInspectionRun[] {\n const cutoff = source.cutoff();\n const loaded: LoadedInspectionRun[] = [];\n for (const runId of new Set(runIds)) {\n const physical = source.readSealedRunCore(runId);\n if (physical !== undefined)\n loaded.push(decodeInspectionRun(source, physical));\n }\n requireCutoff(source.cutoff(), cutoff);\n return Object.freeze(loaded);\n}\n/** Reads Run create/close facts even when no Attempt Core has been published. */\nexport function loadInspectionRunResource(source: InspectionFactSource, runId: string): LoadedInspectionRunResource | undefined {\n const cutoff = source.cutoff();\n const resource = source.readRunResource(runId);\n if (resource === undefined)\n return undefined;\n const physical = source.readSealedRunCore(runId);\n const published = physical === undefined\n ? undefined\n : decodeInspectionRun(source, physical);\n requireCutoff(source.cutoff(), cutoff);\n if (resource.published > 0 && published === undefined) {\n throw factsError(`Run ${runId} has published bindings without a readable Core`);\n }\n if (published !== undefined)\n validateRunResourceCore(resource, published);\n return Object.freeze({ source, resource, ...(published === undefined ? {} : { published }) });\n}\nfunction validateRunResourceCore(resource: ReadableRunResource, published: LoadedInspectionRun): void {\n const run = published.run;\n if (run.runId !== resource.runId ||\n run.experimentId !== resource.experimentId ||\n run.startedAt !== Date.parse(resource.startedAt) ||\n run.expectedSlots.length !== resource.slots.length) {\n throw factsError(`Run ${resource.runId} lifecycle resource does not match its published Core`);\n }\n for (const [index, slot] of run.expectedSlots.entries()) {\n const expected = resource.slots[index];\n if (expected === undefined ||\n slot.slotId !== expected.slotId ||\n slot.evalId !== expected.evalId ||\n slot.attemptOrdinal !== expected.attemptOrdinal ||\n slot.executionIdentityDigest !== expected.executionIdentityDigest) {\n throw factsError(`Run ${resource.runId} expected Slot does not match its published Core`);\n }\n }\n}\n/** Strictly decodes all Core documents and Attachment JSON for one sealed Run. */\nexport function decodeInspectionRun(source: InspectionFactSource, physical: SealedRunCore): LoadedInspectionRun {\n const run = decodedRight(decodeRunDocument(parseJson(physical.runCoreBytes, \"Run Core\")), \"Run Core is invalid\");\n if (run.runId !== physical.runId) {\n throw factsError(\"Run Core identity does not match its sealed row\");\n }\n if (physical.slots.length !== run.expectedSlots.length) {\n throw factsError(\"Run Core Slot rows do not match its expected denominator\");\n }\n for (const [index, stored] of physical.slots.entries()) {\n const decoded = Schema.decodeUnknownResult(RecordSlotIdentitySchema, RecordExactParseOptions)(parseJson(stored.coreBytes, \"Slot Core\"));\n const slot = decodedRight(decoded, \"Slot Core is invalid\");\n const expected = run.expectedSlots[index];\n if (expected === undefined ||\n stored.ordinal !== index ||\n stored.slotId !== slot.slotId ||\n slot.slotId !== expected.slotId ||\n slot.evalId !== expected.evalId ||\n slot.attemptOrdinal !== expected.attemptOrdinal ||\n slot.executionIdentityDigest !== expected.executionIdentityDigest) {\n throw factsError(\"Slot Core does not match its sealed Run denominator\");\n }\n }\n const members = physical.members.map((stored) => {\n const member = decodedRight(decodeMemberDocument(parseJson(stored.coreBytes, \"Member Core\")), \"Member Core is invalid\");\n if (member.slotId !== stored.slotId ||\n member.action !== stored.action ||\n (member.attempt?.originRunId ?? undefined) !== stored.originRunId ||\n (member.attempt?.attemptId ?? undefined) !== stored.attemptId) {\n throw factsError(\"Member Core does not match its sealed row\");\n }\n return member;\n });\n const attempts = physical.attempts.map((stored) => {\n const attempt = decodedRight(decodeAttemptDocument(parseJson(stored.coreBytes, \"Attempt Core\")), \"Attempt Core is invalid\");\n if (attempt.attemptId !== stored.attemptId ||\n attempt.originRunId !== run.runId ||\n encodeAttemptLocator(attempt.attemptId) !== stored.attemptLocator) {\n throw factsError(\"Attempt Core does not match its sealed row\");\n }\n return attempt;\n });\n validateCoreRelations(run, members, attempts, physical.publicationManaged === true);\n const localAttemptIds = new Set<string>(attempts.map(({ attemptId }) => attemptId));\n const attachments = physical.attachments.map((attachment): DecodedInspectionAttachment => {\n if (attachment.ownerRunId !== run.runId ||\n attachment.ownerKind === \"run\" && attachment.ownerAttemptId !== undefined ||\n attachment.ownerKind === \"attempt\" &&\n (attachment.ownerAttemptId === undefined ||\n !localAttemptIds.has(attachment.ownerAttemptId))) {\n throw factsError(\"Attachment ownership does not match its sealed Run\");\n }\n return Object.freeze({\n physical: attachment,\n value: parseInspectionJson(attachment.canonicalBytes, \"Attachment\"),\n });\n });\n return Object.freeze({\n source,\n physical,\n run,\n members: Object.freeze(members),\n attempts: Object.freeze(attempts),\n attachments: Object.freeze(attachments),\n });\n}\n/** Resolves a public locator through the source's bounded exact index. */\n// @concord-code ne-eval-inspection-resolve-attempt\n// @concord-implements docs/feature/inspection/architecture.md\nexport function resolveInspectionAttempt(source: InspectionFactSource, locator: string): ResolvedInspectionAttempt | undefined {\n const projection = source.findAttemptLocatorCandidates(locator, ATTEMPT_CANDIDATE_RUN_LIMIT);\n if (projection.candidates.length === 0)\n return undefined;\n if (projection.ambiguous)\n return undefined;\n const origins = projection.candidates.filter(({ relation }) => relation === \"origin\");\n if (origins.length !== 1) {\n throw factsError(`Attempt ${locator} indexed projection is invalid`);\n }\n const identity = origins[0]!;\n const runs = loadSelectedInspectionRuns(source, projection.candidates.map(({ runId }) => runId));\n const byRunId = new Map<string, LoadedInspectionRun>(runs.map((run) => [run.run.runId, run] as const));\n const origin = byRunId.get(identity.originRunId);\n if (origin === undefined) {\n throw factsError(`Attempt ${locator} origin is not a sealed Run`);\n }\n const attempt = origin.attempts.find((candidate) => candidate.attemptId === identity.attemptId &&\n candidate.originRunId === identity.originRunId &&\n encodeAttemptLocator(candidate.attemptId) === locator);\n if (attempt === undefined) {\n throw factsError(`Attempt ${locator} origin Core is invalid`);\n }\n const targets: InspectionAttemptTarget[] = [];\n const targetRunIds = new Set(projection.candidates.flatMap((candidate) => candidate.relation === \"target\" &&\n candidate.originRunId === identity.originRunId &&\n candidate.attemptId === identity.attemptId\n ? [candidate.runId]\n : []));\n for (const runId of targetRunIds) {\n const run = byRunId.get(runId);\n if (run === undefined) {\n throw factsError(`Attempt ${locator} target is not a sealed Run`);\n }\n const members = targetMembers(run, attempt);\n if (members.length === 0) {\n throw factsError(`Attempt ${locator} target Core is invalid`);\n }\n if (targets.length + members.length > ATTEMPT_TARGET_MEMBER_LIMIT) {\n throw factsError(`Attempt ${locator} exceeds its fixed target member limit`);\n }\n targets.push(...members.map((member) => Object.freeze({ run, member })));\n }\n return Object.freeze({\n attempt,\n origin,\n locator,\n targets: Object.freeze(targets),\n });\n}\n/** Resolves one already loaded target Member without consulting a platform index. */\nexport function resolveInspectionMemberAttempt(runs: readonly LoadedInspectionRun[], target: LoadedInspectionRun, member: MemberDocument): ResolvedInspectionAttempt | undefined {\n if (member.attempt === null)\n return undefined;\n const origin = runs.find(({ run }) => run.runId === member.attempt!.originRunId);\n const attempt = origin?.attempts.find((candidate) => candidate.attemptId === member.attempt!.attemptId &&\n candidate.originRunId === member.attempt!.originRunId);\n if (origin === undefined || attempt === undefined)\n return undefined;\n const locator = encodeAttemptLocator(attempt.attemptId);\n const targets = runs.flatMap((run) => targetMembers(run, attempt).map((candidate) => Object.freeze({ run, member: candidate })));\n if (!targets.some(({ run, member: candidate }) => run.run.runId === target.run.runId && candidate.slotId === member.slotId)) {\n return undefined;\n }\n return Object.freeze({\n attempt,\n origin,\n locator,\n targets: Object.freeze(targets),\n });\n}\nexport function attemptAttachment(resolved: ResolvedInspectionAttempt, family: string): DecodedInspectionAttachment | undefined {\n return resolved.origin.attachments.find(({ physical }) => physical.ownerKind === \"attempt\" &&\n physical.ownerAttemptId === resolved.attempt.attemptId &&\n physical.family === family);\n}\nexport function runAttachment(run: LoadedInspectionRun, family: string): DecodedInspectionAttachment | undefined {\n return run.attachments.find(({ physical }) => physical.ownerKind === \"run\" && physical.family === family);\n}\n/** Reads only the current logical Assertions family, preserving failure state. */\n// @concord-code ne-eval-inspection-read-assertions\n// @concord-implements docs/feature/assertions/README.md\n// @concord-implements docs/feature/inspection/README.md\nexport function readInspectionAssertions(resolved: ResolvedInspectionAttempt): InspectionAssertionsRead {\n const attachment = attemptAttachment(resolved, NiceEvalRecordAttachments.assertions.family);\n if (attachment === undefined) {\n return Object.freeze({\n state: \"not-recorded\" as const,\n issues: Object.freeze([issue(\"assertions-not-recorded\", resolved.locator)]),\n });\n }\n if (attachment.physical.familyRevision !==\n NiceEvalCurrentRecordAttachments.assertions.revision) {\n return Object.freeze({\n state: \"unsupported\" as const,\n attachment,\n issues: Object.freeze([issue(\"assertions-revision-unsupported\", resolved.locator)]),\n });\n }\n const decoded = decodeCurrentAssertions(attachment);\n if (decoded === undefined) {\n return Object.freeze({\n state: \"failed\" as const,\n attachment,\n issues: Object.freeze([issue(\"assertions-current-invalid\", resolved.locator)]),\n });\n }\n return Object.freeze({\n state: \"available\" as const,\n attachment,\n value: decoded.value,\n contents: decoded.contents,\n issues: Object.freeze([]),\n });\n}\nfunction decodeCurrentAssertions(attachment: DecodedInspectionAttachment): {\n readonly value: AssertionsAttachment;\n readonly contents: WeakMap<object, PersistedContentMetadata>;\n} | undefined {\n const definition = NiceEvalRecordAttachments.assertions;\n const byHandle = new Map(attachment.physical.contents.map((content) => [content.logicalHandle, content]));\n const handles = new Map<string, RecordContentHandle>();\n const contents = new WeakMap<object, PersistedContentMetadata>();\n const usedContent = new Set<string>();\n const hydrated = hydrateRecordAttachmentCurrent(definition, attachment.value, {\n content: (token, declaration) => {\n const logicalHandle = exactMarker(token, \"$niceeval.record.content\");\n if (logicalHandle === undefined &&\n !hasOwnMarker(token, \"$niceeval.record.content\")) {\n return Result.succeed(undefined);\n }\n if (typeof logicalHandle !== \"string\") {\n return Result.fail({ code: \"current-content-bind-failed\" as const });\n }\n const metadata = byHandle.get(logicalHandle);\n if (metadata === undefined ||\n declaration.maximumBytes !== undefined &&\n metadata.byteLength > declaration.maximumBytes) {\n return Result.fail({ code: \"current-content-bind-failed\" as const });\n }\n let handle = handles.get(logicalHandle);\n if (handle === undefined) {\n handle = mintRecordContentHandle(declaration.kind);\n handles.set(logicalHandle, handle);\n contents.set(handle, metadata);\n }\n usedContent.add(logicalHandle);\n return Result.succeed(handle);\n },\n reference: (token, declaration) => {\n const marker = exactMarker(token, \"$niceeval.record.reference\");\n if (marker === undefined &&\n !hasOwnMarker(token, \"$niceeval.record.reference\")) {\n return Result.succeed(undefined);\n }\n if (typeof marker !== \"object\" || marker === null || Array.isArray(marker)) {\n return Result.fail({ code: \"current-reference-bind-failed\" as const });\n }\n const value = marker as Record<string, unknown>;\n if (Reflect.ownKeys(value).length !== 3 ||\n value.owner !== declaration.definition.owner ||\n value.family !== declaration.definition.family ||\n !(\"value\" in value)) {\n return Result.fail({ code: \"current-reference-bind-failed\" as const });\n }\n return Result.succeed(mintRecordAttachmentReference(RecordAttachmentReference.to(declaration.definition, declaration.valueSchema), value.value));\n },\n });\n if (Result.isFailure(hydrated) ||\n usedContent.size !== attachment.physical.contents.length) {\n return undefined;\n }\n const closure = enumerateRecordAttachmentClosure(definition, hydrated.success);\n if (Result.isFailure(closure))\n return undefined;\n const references = new Map<string, {\n readonly owner: string;\n readonly family: string;\n }>();\n for (const reference of closure.success.references) {\n const wire = recordAttachmentReferenceWire(reference);\n if (wire === undefined)\n return undefined;\n references.set(`${wire.owner}\\u0000${wire.family}`, Object.freeze({ owner: wire.owner, family: wire.family }));\n }\n const ordered = [...references.values()].sort((left, right) => compareText(left.owner, right.owner) || compareText(left.family, right.family));\n if (ordered.length !== attachment.physical.references.length)\n return undefined;\n for (let ordinal = 0; ordinal < ordered.length; ordinal += 1) {\n const logical = ordered[ordinal]!;\n const physical = attachment.physical.references[ordinal]!;\n if (physical.ordinal !== ordinal ||\n physical.owner !== logical.owner ||\n physical.family !== logical.family) {\n return undefined;\n }\n }\n return Object.freeze({ value: hydrated.success, contents });\n}\nfunction validateCoreRelations(run: RunDocument, members: readonly MemberDocument[], attempts: readonly AttemptDocument[], allowPendingSlots = false): void {\n const slots = new Map(run.expectedSlots.map((slot) => [slot.slotId, slot] as const));\n if (slots.size !== run.expectedSlots.length || (!allowPendingSlots && members.length !== slots.size) || members.length > slots.size) {\n throw factsError(\"Run Core does not close its expected Slot membership\");\n }\n const memberSlots = new Set<string>();\n for (const member of members) {\n if (!slots.has(member.slotId) || memberSlots.has(member.slotId)) {\n throw factsError(\"Run Core contains an invalid Member Slot\");\n }\n memberSlots.add(member.slotId);\n }\n const attemptIds = new Set<string>();\n for (const attempt of attempts) {\n const slot = slots.get(attempt.slotId);\n if (attemptIds.has(attempt.attemptId) ||\n slot === undefined ||\n attempt.evalId !== slot.evalId ||\n attempt.executionIdentityDigest !== slot.executionIdentityDigest) {\n throw factsError(\"Run Core contains an invalid origin Attempt\");\n }\n attemptIds.add(attempt.attemptId);\n }\n for (const member of members) {\n if (member.action === \"executed\" &&\n (member.attempt === null ||\n member.attempt.originRunId !== run.runId ||\n !attemptIds.has(member.attempt.attemptId))) {\n throw factsError(\"Executed Member does not name a local origin Attempt\");\n }\n }\n}\nfunction targetMembers(run: LoadedInspectionRun, attempt: AttemptDocument): readonly MemberDocument[] {\n return run.members.filter((member) => member.attempt !== null &&\n member.attempt.originRunId === attempt.originRunId &&\n member.attempt.attemptId === attempt.attemptId);\n}\nfunction requireCutoff(actual: SealedRunCutoff, expected: SealedRunCutoff): void {\n if (actual.identity !== expected.identity ||\n actual.runCount !== expected.runCount) {\n throw factsError(\"Inspection source changed its pinned sealed cutoff\");\n }\n}\nfunction parseJson(bytes: Uint8Array, owner: string): unknown {\n try {\n return JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes)) as unknown;\n }\n catch (cause) {\n throw factsError(`${owner} is not canonical UTF-8 JSON`, cause);\n }\n}\nfunction parseInspectionJson(bytes: Uint8Array, owner: string): InspectionJson {\n const closed = closeInspectionJson(parseJson(bytes, owner));\n if (isInspectionCodecError(closed)) {\n throw factsError(`${owner} is invalid: ${closed.reason}`);\n }\n return closed;\n}\nfunction decodedRight<A>(decoded: Result.Result<A, unknown>, reason: string): A {\n if (Result.isFailure(decoded))\n throw factsError(reason, decoded.failure);\n return decoded.success;\n}\nfunction exactMarker(value: unknown, key: string): unknown | undefined {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return undefined;\n }\n const keys = Reflect.ownKeys(value);\n if (keys.length !== 1 || keys[0] !== key)\n return undefined;\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n return descriptor?.enumerable === true && \"value\" in descriptor\n ? descriptor.value\n : undefined;\n}\nfunction hasOwnMarker(value: unknown, key: string): boolean {\n return typeof value === \"object\" && value !== null && !Array.isArray(value) &&\n Object.prototype.hasOwnProperty.call(value, key);\n}\nfunction issue(code: string, locator: string): InspectionJson {\n return Object.freeze({ code, locator });\n}\nfunction factsError(reason: string, cause?: unknown): Error {\n return new Error(reason, cause === undefined ? undefined : { cause });\n}\nfunction compareText(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n"]}
1
+ {"version":3,"file":"facts.js","sourceRoot":"","sources":["facts.ts"],"names":[],"mappings":";;AAmFA,gDAuCC;AAED,gEAUC;AAED,8DAaC;AAqBD,kDA0EC;AAID,4DAiDC;AAwCD,wEAaC;AACD,8CAIC;AACD,sCAEC;AAKD,4DA+BC;AA1YD,gDAAgD;AAChD,wDAAwD;AACxD,8DAA8D;AAC9D,wFAAwF;AACxF,mCAAwC;AACxC,8DAA6D;AAC7D,gEAAqG;AACrG,kEAA8M;AAC9M,qDAA6J;AAC7J,4DAA2G;AAI3G,yCAA+F;AAE/F,yCAA8C;AA2C9C,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,2BAA2B,GAAG,EAAE,CAAC;AACvC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,WAAW,GAAG,IAAI,OAAO,EAA0D,CAAC;AAC1F,SAAS,iBAAiB,CAAC,MAA4B,EAAE,KAAa;IAClE,IAAI,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,SAAS;QACnB,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,MAAM,KAAK,SAAS;QACpB,OAAO,MAAM,CAAC;IAClB,MAAM,QAAQ,GAAG,MAA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,CAAC;AACD,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa;IAC5C,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AACD,SAAS,YAAY,CAAC,KAAiB,EAAE,MAAc,EAAE,KAAa;IAClE,IAAI,IAAI,2BAAgB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,KAAK,MAAM;QAC3D,MAAM,UAAU,CAAC,GAAG,KAAK,oBAAoB,CAAC,CAAC;AACvD,CAAC;AACD,SAAS,iBAAiB,CAAC,KAAiB,EAAE,MAAc,EAAE,KAAa;IACvE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,OAAO,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC","sourcesContent":["// @concord-file ne-eval-inspection-facts-reader\n// @concord-implements docs/feature/inspection/README.md\n// @concord-implements docs/feature/inspection/architecture.md\n// @concord-implements docs/feature/inspection/use-case/inspection-check-completeness.md\nimport { Result, Schema } from \"effect\";\nimport { encodeAttemptLocator } from \"../attempt-locator.ts\";\nimport { mintRecordContentHandle, type RecordContentHandle, } from \"../record/attachment/content.ts\";\nimport { enumerateRecordAttachmentClosure, hydrateRecordAttachmentCurrent, mintRecordAttachmentReference, RecordAttachmentReference, recordAttachmentReferenceWire, } from \"../record/attachment/protocol.ts\";\nimport { decodeAttemptDocument, decodeMemberDocument, decodeRunDocument, RecordExactParseOptions, RecordSlotIdentitySchema, } from \"../record/codec/core.ts\";\nimport { NiceEvalCurrentRecordAttachments, NiceEvalRecordAttachments, } from \"../record/family/current.ts\";\nimport type { AssertionsAttachment } from \"../record/family/assertions/definition.ts\";\nimport type { AttemptDocument, MemberDocument, RunDocument, } from \"../record/model/core.ts\";\nimport type { PersistedContentMetadata, SealedAttachmentMetadata, SealedRunCore, SealedRunCutoff, SealedRunSummary, } from \"../record/sqlite/types.ts\";\nimport { closeInspectionJson, isInspectionCodecError, type InspectionJson, } from \"./codec.ts\";\nimport type { InspectionFactSource } from \"./source.ts\";\nimport { InspectionSha256 } from \"./bytes.ts\";\nimport type { ReadableRunResource } from \"../run/storage/types.ts\";\nexport interface DecodedInspectionAttachment {\n readonly physical: SealedAttachmentMetadata;\n readonly value: InspectionJson;\n}\n/** A strictly decoded sealed Run with its browser-neutral reader capability. */\nexport interface LoadedInspectionRun {\n readonly source: InspectionFactSource;\n readonly physical: SealedRunCore;\n readonly run: RunDocument;\n readonly members: readonly MemberDocument[];\n readonly attempts: readonly AttemptDocument[];\n readonly attachments: readonly DecodedInspectionAttachment[];\n}\n/** Exact lifecycle resource plus its optional published Core at one cutoff. */\nexport interface LoadedInspectionRunResource {\n readonly source: InspectionFactSource;\n readonly resource: ReadableRunResource;\n readonly published?: LoadedInspectionRun;\n}\nexport interface InspectionAttemptTarget {\n readonly run: LoadedInspectionRun;\n readonly member: MemberDocument;\n}\n/** Exact origin Attempt plus every target membership visible to the resolver. */\nexport interface ResolvedInspectionAttempt {\n readonly attempt: AttemptDocument;\n readonly origin: LoadedInspectionRun;\n readonly locator: string;\n readonly targets: readonly InspectionAttemptTarget[];\n}\nexport type InspectionAssertionsRead = {\n readonly state: \"available\";\n readonly attachment: DecodedInspectionAttachment;\n readonly value: AssertionsAttachment;\n readonly contents: WeakMap<object, PersistedContentMetadata>;\n readonly issues: readonly InspectionJson[];\n} | {\n readonly state: \"not-recorded\" | \"unsupported\" | \"failed\";\n readonly attachment?: DecodedInspectionAttachment;\n readonly issues: readonly InspectionJson[];\n};\nconst RUN_PAGE_SIZE = 100;\nconst ATTEMPT_CANDIDATE_RUN_LIMIT = 64;\nconst ATTEMPT_TARGET_MEMBER_LIMIT = 256;\nconst decodedRuns = new WeakMap<InspectionFactSource, Map<string, LoadedInspectionRun>>();\nfunction readInspectionRun(source: InspectionFactSource, runId: string): LoadedInspectionRun | undefined {\n let cache = decodedRuns.get(source);\n if (cache === undefined)\n decodedRuns.set(source, cache = new Map());\n const cached = cache.get(runId);\n if (cached !== undefined)\n return cached;\n const physical = source.readSealedRunCore(runId);\n if (physical === undefined)\n return undefined;\n const decoded = decodeInspectionRun(source, physical);\n cache.set(runId, decoded);\n return decoded;\n}\n/**\n * Pins the source cutoff, exhausts the fixed Run-summary pagination, then\n * reads and strictly decodes every Run Core in that exact sealed generation.\n */\n// @concord-code ne-eval-inspection-load-runs\n// @concord-implements docs/feature/inspection/architecture.md\n// @concord-implements docs/feature/inspection/use-case/inspection-check-completeness.md\nexport function loadInspectionRuns(source: InspectionFactSource): readonly LoadedInspectionRun[] {\n const cutoff = source.cutoff();\n const summaries: SealedRunSummary[] = [];\n const seen = new Set<string>();\n let afterRunId = \"\";\n for (;;) {\n const page = source.readSealedRunSummaryPage(afterRunId, RUN_PAGE_SIZE, cutoff.identity);\n requireCutoff(page.cutoff, cutoff);\n if (page.afterRunId !== afterRunId) {\n throw factsError(\"Run pagination returned a different cursor\");\n }\n let previous = afterRunId;\n for (const summary of page.summaries) {\n if (summary.runId <= previous || seen.has(summary.runId)) {\n throw factsError(\"Run pagination is not strictly ordered\");\n }\n seen.add(summary.runId);\n summaries.push(summary);\n previous = summary.runId;\n }\n if (page.nextAfterRunId === null)\n break;\n if (page.summaries.length === 0 ||\n page.nextAfterRunId !== page.summaries.at(-1)!.runId ||\n page.nextAfterRunId === afterRunId) {\n throw factsError(\"Run pagination returned an invalid continuation cursor\");\n }\n afterRunId = page.nextAfterRunId;\n }\n if (summaries.length !== cutoff.runCount) {\n throw factsError(\"Run pagination did not close the pinned sealed cutoff\");\n }\n return Object.freeze(summaries.map((summary) => {\n const run = readInspectionRun(source, summary.runId);\n if (run === undefined) {\n throw factsError(`Sealed Run ${summary.runId} disappeared from the pinned cutoff`);\n }\n return run;\n }));\n}\n/** Reads a bounded, explicit Run selection without changing its caller order. */\nexport function loadSelectedInspectionRuns(source: InspectionFactSource, runIds: readonly string[]): readonly LoadedInspectionRun[] {\n const cutoff = source.cutoff();\n const loaded: LoadedInspectionRun[] = [];\n for (const runId of new Set(runIds)) {\n const run = readInspectionRun(source, runId);\n if (run !== undefined)\n loaded.push(run);\n }\n requireCutoff(source.cutoff(), cutoff);\n return Object.freeze(loaded);\n}\n/** Reads Run create/close facts even when no Attempt Core has been published. */\nexport function loadInspectionRunResource(source: InspectionFactSource, runId: string): LoadedInspectionRunResource | undefined {\n const cutoff = source.cutoff();\n const resource = source.readRunResource(runId);\n if (resource === undefined)\n return undefined;\n const published = readInspectionRun(source, runId);\n requireCutoff(source.cutoff(), cutoff);\n if (resource.published > 0 && published === undefined) {\n throw factsError(`Run ${runId} has published bindings without a readable Core`);\n }\n if (published !== undefined)\n validateRunResourceCore(resource, published);\n return Object.freeze({ source, resource, ...(published === undefined ? {} : { published }) });\n}\nfunction validateRunResourceCore(resource: ReadableRunResource, published: LoadedInspectionRun): void {\n const run = published.run;\n if (run.runId !== resource.runId ||\n run.experimentId !== resource.experimentId ||\n run.startedAt !== Date.parse(resource.startedAt) ||\n run.expectedSlots.length !== resource.slots.length) {\n throw factsError(`Run ${resource.runId} lifecycle resource does not match its published Core`);\n }\n for (const [index, slot] of run.expectedSlots.entries()) {\n const expected = resource.slots[index];\n if (expected === undefined ||\n slot.slotId !== expected.slotId ||\n slot.evalId !== expected.evalId ||\n slot.attemptOrdinal !== expected.attemptOrdinal ||\n slot.executionIdentityDigest !== expected.executionIdentityDigest) {\n throw factsError(`Run ${resource.runId} expected Slot does not match its published Core`);\n }\n }\n}\n/** Strictly decodes Core, then decodes each Attachment only on first use. */\nexport function decodeInspectionRun(source: InspectionFactSource, physical: SealedRunCore): LoadedInspectionRun {\n const run = decodedRight(decodeRunDocument(parseVerifiedJson(physical.runCoreBytes, physical.runCoreDigest, \"Run Core\")), \"Run Core is invalid\");\n if (run.runId !== physical.runId) {\n throw factsError(\"Run Core identity does not match its sealed row\");\n }\n if (physical.slots.length !== run.expectedSlots.length) {\n throw factsError(\"Run Core Slot rows do not match its expected denominator\");\n }\n for (const [index, stored] of physical.slots.entries()) {\n const decoded = Schema.decodeUnknownResult(RecordSlotIdentitySchema, RecordExactParseOptions)(parseVerifiedJson(stored.coreBytes, stored.coreDigest, \"Slot Core\"));\n const slot = decodedRight(decoded, \"Slot Core is invalid\");\n const expected = run.expectedSlots[index];\n if (expected === undefined ||\n stored.ordinal !== index ||\n stored.slotId !== slot.slotId ||\n slot.slotId !== expected.slotId ||\n slot.evalId !== expected.evalId ||\n slot.attemptOrdinal !== expected.attemptOrdinal ||\n slot.executionIdentityDigest !== expected.executionIdentityDigest) {\n throw factsError(\"Slot Core does not match its sealed Run denominator\");\n }\n }\n const members = physical.members.map((stored) => {\n const member = decodedRight(decodeMemberDocument(parseVerifiedJson(stored.coreBytes, stored.coreDigest, \"Member Core\")), \"Member Core is invalid\");\n if (member.slotId !== stored.slotId ||\n member.action !== stored.action ||\n (member.attempt?.originRunId ?? undefined) !== stored.originRunId ||\n (member.attempt?.attemptId ?? undefined) !== stored.attemptId) {\n throw factsError(\"Member Core does not match its sealed row\");\n }\n return member;\n });\n const attempts = physical.attempts.map((stored) => {\n const attempt = decodedRight(decodeAttemptDocument(parseVerifiedJson(stored.coreBytes, stored.coreDigest, \"Attempt Core\")), \"Attempt Core is invalid\");\n if (attempt.attemptId !== stored.attemptId ||\n attempt.originRunId !== run.runId ||\n encodeAttemptLocator(attempt.attemptId) !== stored.attemptLocator) {\n throw factsError(\"Attempt Core does not match its sealed row\");\n }\n return attempt;\n });\n validateCoreRelations(run, members, attempts, physical.publicationManaged === true);\n const localAttemptIds = new Set<string>(attempts.map(({ attemptId }) => attemptId));\n const attachments = physical.attachments.map((attachment): DecodedInspectionAttachment => {\n if (attachment.ownerRunId !== run.runId ||\n attachment.ownerKind === \"run\" && attachment.ownerAttemptId !== undefined ||\n attachment.ownerKind === \"attempt\" &&\n (attachment.ownerAttemptId === undefined ||\n !localAttemptIds.has(attachment.ownerAttemptId))) {\n throw factsError(\"Attachment ownership does not match its sealed Run\");\n }\n let value: InspectionJson | undefined;\n let decoded = false;\n return Object.freeze({\n physical: attachment,\n get value(): InspectionJson {\n if (!decoded) {\n verifyDigest(attachment.canonicalBytes, attachment.canonicalDigest, \"Attachment\");\n verifyDigest(attachment.logicalInventoryBytes, attachment.inventoryDigest, \"Attachment inventory\");\n value = parseInspectionJson(attachment.canonicalBytes, \"Attachment\");\n decoded = true;\n }\n return value!;\n },\n });\n });\n return Object.freeze({\n source,\n physical,\n run,\n members: Object.freeze(members),\n attempts: Object.freeze(attempts),\n attachments: Object.freeze(attachments),\n });\n}\n/** Resolves a public locator through the source's bounded exact index. */\n// @concord-code ne-eval-inspection-resolve-attempt\n// @concord-implements docs/feature/inspection/architecture.md\nexport function resolveInspectionAttempt(source: InspectionFactSource, locator: string): ResolvedInspectionAttempt | undefined {\n const projection = source.findAttemptLocatorCandidates(locator, ATTEMPT_CANDIDATE_RUN_LIMIT);\n if (projection.candidates.length === 0)\n return undefined;\n if (projection.ambiguous)\n return undefined;\n const origins = projection.candidates.filter(({ relation }) => relation === \"origin\");\n if (origins.length !== 1) {\n throw factsError(`Attempt ${locator} indexed projection is invalid`);\n }\n const identity = origins[0]!;\n const runs = loadSelectedInspectionRuns(source, projection.candidates.map(({ runId }) => runId));\n const byRunId = new Map<string, LoadedInspectionRun>(runs.map((run) => [run.run.runId, run] as const));\n const origin = byRunId.get(identity.originRunId);\n if (origin === undefined) {\n throw factsError(`Attempt ${locator} origin is not a sealed Run`);\n }\n const attempt = origin.attempts.find((candidate) => candidate.attemptId === identity.attemptId &&\n candidate.originRunId === identity.originRunId &&\n encodeAttemptLocator(candidate.attemptId) === locator);\n if (attempt === undefined) {\n throw factsError(`Attempt ${locator} origin Core is invalid`);\n }\n const targets: InspectionAttemptTarget[] = [];\n const targetRunIds = new Set(projection.candidates.flatMap((candidate) => candidate.relation === \"target\" &&\n candidate.originRunId === identity.originRunId &&\n candidate.attemptId === identity.attemptId\n ? [candidate.runId]\n : []));\n for (const runId of targetRunIds) {\n const run = byRunId.get(runId);\n if (run === undefined) {\n throw factsError(`Attempt ${locator} target is not a sealed Run`);\n }\n const members = targetMembers(run, attempt);\n if (members.length === 0) {\n throw factsError(`Attempt ${locator} target Core is invalid`);\n }\n if (targets.length + members.length > ATTEMPT_TARGET_MEMBER_LIMIT) {\n throw factsError(`Attempt ${locator} exceeds its fixed target member limit`);\n }\n targets.push(...members.map((member) => Object.freeze({ run, member })));\n }\n return Object.freeze({\n attempt,\n origin,\n locator,\n targets: Object.freeze(targets),\n });\n}\ninterface InspectionMemberIndex {\n readonly origins: ReadonlyMap<string, {\n readonly run: LoadedInspectionRun;\n readonly attempts: ReadonlyMap<string, AttemptDocument>;\n readonly members: ReadonlyMap<string, MemberDocument>;\n }>;\n readonly targets: ReadonlyMap<string, ReadonlyMap<string, readonly InspectionAttemptTarget[]>>;\n}\nconst memberIndexes = new WeakMap<readonly LoadedInspectionRun[], InspectionMemberIndex>();\nfunction memberIndex(runs: readonly LoadedInspectionRun[]): InspectionMemberIndex {\n const cached = memberIndexes.get(runs);\n if (cached !== undefined)\n return cached;\n const origins = new Map(runs.map((run) => [run.run.runId, {\n run, attempts: new Map(run.attempts.map((attempt) => [attempt.attemptId, attempt])),\n members: new Map(run.members.map((member) => [member.slotId, member])),\n }]));\n const targets = new Map<string, Map<string, InspectionAttemptTarget[]>>();\n for (const run of runs)\n for (const member of run.members) {\n if (member.attempt === null)\n continue;\n const { originRunId, attemptId } = member.attempt;\n let byAttempt = targets.get(originRunId);\n if (byAttempt === undefined)\n targets.set(originRunId, byAttempt = new Map());\n let members = byAttempt.get(attemptId);\n if (members === undefined)\n byAttempt.set(attemptId, members = []);\n members.push(Object.freeze({ run, member }));\n }\n for (const byAttempt of targets.values())\n for (const members of byAttempt.values())\n Object.freeze(members);\n const index = { origins, targets };\n memberIndexes.set(runs, index);\n return index;\n}\n/** Resolves already loaded facts through one shared identity index. */\nexport function resolveInspectionMemberAttempt(runs: readonly LoadedInspectionRun[], target: LoadedInspectionRun, member: MemberDocument): ResolvedInspectionAttempt | undefined {\n if (member.attempt === null)\n return undefined;\n const index = memberIndex(runs);\n const origin = index.origins.get(member.attempt.originRunId);\n const attempt = origin?.attempts.get(member.attempt.attemptId);\n if (origin === undefined || attempt === undefined || attempt.originRunId !== member.attempt.originRunId)\n return undefined;\n const targets = index.targets.get(attempt.originRunId)?.get(attempt.attemptId) ?? [];\n const targetMember = index.origins.get(target.run.runId)?.members.get(member.slotId);\n if (targetMember?.attempt?.originRunId !== attempt.originRunId || targetMember.attempt.attemptId !== attempt.attemptId)\n return undefined;\n return Object.freeze({ attempt, origin: origin.run, locator: encodeAttemptLocator(attempt.attemptId), targets });\n}\nexport function attemptAttachment(resolved: ResolvedInspectionAttempt, family: string): DecodedInspectionAttachment | undefined {\n return resolved.origin.attachments.find(({ physical }) => physical.ownerKind === \"attempt\" &&\n physical.ownerAttemptId === resolved.attempt.attemptId &&\n physical.family === family);\n}\nexport function runAttachment(run: LoadedInspectionRun, family: string): DecodedInspectionAttachment | undefined {\n return run.attachments.find(({ physical }) => physical.ownerKind === \"run\" && physical.family === family);\n}\n/** Reads only the current logical Assertions family, preserving failure state. */\n// @concord-code ne-eval-inspection-read-assertions\n// @concord-implements docs/feature/assertions/README.md\n// @concord-implements docs/feature/inspection/README.md\nexport function readInspectionAssertions(resolved: ResolvedInspectionAttempt): InspectionAssertionsRead {\n const attachment = attemptAttachment(resolved, NiceEvalRecordAttachments.assertions.family);\n if (attachment === undefined) {\n return Object.freeze({\n state: \"not-recorded\" as const,\n issues: Object.freeze([issue(\"assertions-not-recorded\", resolved.locator)]),\n });\n }\n if (attachment.physical.familyRevision !==\n NiceEvalCurrentRecordAttachments.assertions.revision) {\n return Object.freeze({\n state: \"unsupported\" as const,\n attachment,\n issues: Object.freeze([issue(\"assertions-revision-unsupported\", resolved.locator)]),\n });\n }\n const decoded = decodeCurrentAssertions(attachment);\n if (decoded === undefined) {\n return Object.freeze({\n state: \"failed\" as const,\n attachment,\n issues: Object.freeze([issue(\"assertions-current-invalid\", resolved.locator)]),\n });\n }\n return Object.freeze({\n state: \"available\" as const,\n attachment,\n value: decoded.value,\n contents: decoded.contents,\n issues: Object.freeze([]),\n });\n}\nfunction decodeCurrentAssertions(attachment: DecodedInspectionAttachment): {\n readonly value: AssertionsAttachment;\n readonly contents: WeakMap<object, PersistedContentMetadata>;\n} | undefined {\n const definition = NiceEvalRecordAttachments.assertions;\n const byHandle = new Map(attachment.physical.contents.map((content) => [content.logicalHandle, content]));\n const handles = new Map<string, RecordContentHandle>();\n const contents = new WeakMap<object, PersistedContentMetadata>();\n const usedContent = new Set<string>();\n const hydrated = hydrateRecordAttachmentCurrent(definition, attachment.value, {\n content: (token, declaration) => {\n const logicalHandle = exactMarker(token, \"$niceeval.record.content\");\n if (logicalHandle === undefined &&\n !hasOwnMarker(token, \"$niceeval.record.content\")) {\n return Result.succeed(undefined);\n }\n if (typeof logicalHandle !== \"string\") {\n return Result.fail({ code: \"current-content-bind-failed\" as const });\n }\n const metadata = byHandle.get(logicalHandle);\n if (metadata === undefined ||\n declaration.maximumBytes !== undefined &&\n metadata.byteLength > declaration.maximumBytes) {\n return Result.fail({ code: \"current-content-bind-failed\" as const });\n }\n let handle = handles.get(logicalHandle);\n if (handle === undefined) {\n handle = mintRecordContentHandle(declaration.kind);\n handles.set(logicalHandle, handle);\n contents.set(handle, metadata);\n }\n usedContent.add(logicalHandle);\n return Result.succeed(handle);\n },\n reference: (token, declaration) => {\n const marker = exactMarker(token, \"$niceeval.record.reference\");\n if (marker === undefined &&\n !hasOwnMarker(token, \"$niceeval.record.reference\")) {\n return Result.succeed(undefined);\n }\n if (typeof marker !== \"object\" || marker === null || Array.isArray(marker)) {\n return Result.fail({ code: \"current-reference-bind-failed\" as const });\n }\n const value = marker as Record<string, unknown>;\n if (Reflect.ownKeys(value).length !== 3 ||\n value.owner !== declaration.definition.owner ||\n value.family !== declaration.definition.family ||\n !(\"value\" in value)) {\n return Result.fail({ code: \"current-reference-bind-failed\" as const });\n }\n return Result.succeed(mintRecordAttachmentReference(RecordAttachmentReference.to(declaration.definition, declaration.valueSchema), value.value));\n },\n });\n if (Result.isFailure(hydrated) ||\n usedContent.size !== attachment.physical.contents.length) {\n return undefined;\n }\n const closure = enumerateRecordAttachmentClosure(definition, hydrated.success);\n if (Result.isFailure(closure))\n return undefined;\n const references = new Map<string, {\n readonly owner: string;\n readonly family: string;\n }>();\n for (const reference of closure.success.references) {\n const wire = recordAttachmentReferenceWire(reference);\n if (wire === undefined)\n return undefined;\n references.set(`${wire.owner}\\u0000${wire.family}`, Object.freeze({ owner: wire.owner, family: wire.family }));\n }\n const ordered = [...references.values()].sort((left, right) => compareText(left.owner, right.owner) || compareText(left.family, right.family));\n if (ordered.length !== attachment.physical.references.length)\n return undefined;\n for (let ordinal = 0; ordinal < ordered.length; ordinal += 1) {\n const logical = ordered[ordinal]!;\n const physical = attachment.physical.references[ordinal]!;\n if (physical.ordinal !== ordinal ||\n physical.owner !== logical.owner ||\n physical.family !== logical.family) {\n return undefined;\n }\n }\n return Object.freeze({ value: hydrated.success, contents });\n}\nfunction validateCoreRelations(run: RunDocument, members: readonly MemberDocument[], attempts: readonly AttemptDocument[], allowPendingSlots = false): void {\n const slots = new Map(run.expectedSlots.map((slot) => [slot.slotId, slot] as const));\n if (slots.size !== run.expectedSlots.length || (!allowPendingSlots && members.length !== slots.size) || members.length > slots.size) {\n throw factsError(\"Run Core does not close its expected Slot membership\");\n }\n const memberSlots = new Set<string>();\n for (const member of members) {\n if (!slots.has(member.slotId) || memberSlots.has(member.slotId)) {\n throw factsError(\"Run Core contains an invalid Member Slot\");\n }\n memberSlots.add(member.slotId);\n }\n const attemptIds = new Set<string>();\n for (const attempt of attempts) {\n const slot = slots.get(attempt.slotId);\n if (attemptIds.has(attempt.attemptId) ||\n slot === undefined ||\n attempt.evalId !== slot.evalId ||\n attempt.executionIdentityDigest !== slot.executionIdentityDigest) {\n throw factsError(\"Run Core contains an invalid origin Attempt\");\n }\n attemptIds.add(attempt.attemptId);\n }\n for (const member of members) {\n if (member.action === \"executed\" &&\n (member.attempt === null ||\n member.attempt.originRunId !== run.runId ||\n !attemptIds.has(member.attempt.attemptId))) {\n throw factsError(\"Executed Member does not name a local origin Attempt\");\n }\n }\n}\nfunction targetMembers(run: LoadedInspectionRun, attempt: AttemptDocument): readonly MemberDocument[] {\n return run.members.filter((member) => member.attempt !== null &&\n member.attempt.originRunId === attempt.originRunId &&\n member.attempt.attemptId === attempt.attemptId);\n}\nfunction requireCutoff(actual: SealedRunCutoff, expected: SealedRunCutoff): void {\n if (actual.identity !== expected.identity ||\n actual.runCount !== expected.runCount) {\n throw factsError(\"Inspection source changed its pinned sealed cutoff\");\n }\n}\nfunction parseJson(bytes: Uint8Array, owner: string): unknown {\n try {\n return JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes)) as unknown;\n }\n catch (cause) {\n throw factsError(`${owner} is not canonical UTF-8 JSON`, cause);\n }\n}\nfunction parseInspectionJson(bytes: Uint8Array, owner: string): InspectionJson {\n const closed = closeInspectionJson(parseJson(bytes, owner));\n if (isInspectionCodecError(closed)) {\n throw factsError(`${owner} is invalid: ${closed.reason}`);\n }\n return closed;\n}\nfunction decodedRight<A>(decoded: Result.Result<A, unknown>, reason: string): A {\n if (Result.isFailure(decoded))\n throw factsError(reason, decoded.failure);\n return decoded.success;\n}\nfunction exactMarker(value: unknown, key: string): unknown | undefined {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return undefined;\n }\n const keys = Reflect.ownKeys(value);\n if (keys.length !== 1 || keys[0] !== key)\n return undefined;\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n return descriptor?.enumerable === true && \"value\" in descriptor\n ? descriptor.value\n : undefined;\n}\nfunction hasOwnMarker(value: unknown, key: string): boolean {\n return typeof value === \"object\" && value !== null && !Array.isArray(value) &&\n Object.prototype.hasOwnProperty.call(value, key);\n}\nfunction issue(code: string, locator: string): InspectionJson {\n return Object.freeze({ code, locator });\n}\nfunction factsError(reason: string, cause?: unknown): Error {\n return new Error(reason, cause === undefined ? undefined : { cause });\n}\nfunction compareText(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\nfunction verifyDigest(bytes: Uint8Array, digest: string, label: string): void {\n if (new InspectionSha256().update(bytes).digestHex() !== digest)\n throw factsError(`${label} digest is invalid`);\n}\nfunction parseVerifiedJson(bytes: Uint8Array, digest: string, label: string): unknown {\n verifyDigest(bytes, digest, label);\n return parseJson(bytes, label);\n}\n"]}
@@ -54,11 +54,11 @@ export declare function loadInspectionRuns(source: InspectionFactSource): readon
54
54
  export declare function loadSelectedInspectionRuns(source: InspectionFactSource, runIds: readonly string[]): readonly LoadedInspectionRun[];
55
55
  /** Reads Run create/close facts even when no Attempt Core has been published. */
56
56
  export declare function loadInspectionRunResource(source: InspectionFactSource, runId: string): LoadedInspectionRunResource | undefined;
57
- /** Strictly decodes all Core documents and Attachment JSON for one sealed Run. */
57
+ /** Strictly decodes Core, then decodes each Attachment only on first use. */
58
58
  export declare function decodeInspectionRun(source: InspectionFactSource, physical: SealedRunCore): LoadedInspectionRun;
59
59
  /** Resolves a public locator through the source's bounded exact index. */
60
60
  export declare function resolveInspectionAttempt(source: InspectionFactSource, locator: string): ResolvedInspectionAttempt | undefined;
61
- /** Resolves one already loaded target Member without consulting a platform index. */
61
+ /** Resolves already loaded facts through one shared identity index. */
62
62
  export declare function resolveInspectionMemberAttempt(runs: readonly LoadedInspectionRun[], target: LoadedInspectionRun, member: MemberDocument): ResolvedInspectionAttempt | undefined;
63
63
  export declare function attemptAttachment(resolved: ResolvedInspectionAttempt, family: string): DecodedInspectionAttachment | undefined;
64
64
  export declare function runAttachment(run: LoadedInspectionRun, family: string): DecodedInspectionAttachment | undefined;
@@ -54,11 +54,11 @@ export declare function loadInspectionRuns(source: InspectionFactSource): readon
54
54
  export declare function loadSelectedInspectionRuns(source: InspectionFactSource, runIds: readonly string[]): readonly LoadedInspectionRun[];
55
55
  /** Reads Run create/close facts even when no Attempt Core has been published. */
56
56
  export declare function loadInspectionRunResource(source: InspectionFactSource, runId: string): LoadedInspectionRunResource | undefined;
57
- /** Strictly decodes all Core documents and Attachment JSON for one sealed Run. */
57
+ /** Strictly decodes Core, then decodes each Attachment only on first use. */
58
58
  export declare function decodeInspectionRun(source: InspectionFactSource, physical: SealedRunCore): LoadedInspectionRun;
59
59
  /** Resolves a public locator through the source's bounded exact index. */
60
60
  export declare function resolveInspectionAttempt(source: InspectionFactSource, locator: string): ResolvedInspectionAttempt | undefined;
61
- /** Resolves one already loaded target Member without consulting a platform index. */
61
+ /** Resolves already loaded facts through one shared identity index. */
62
62
  export declare function resolveInspectionMemberAttempt(runs: readonly LoadedInspectionRun[], target: LoadedInspectionRun, member: MemberDocument): ResolvedInspectionAttempt | undefined;
63
63
  export declare function attemptAttachment(resolved: ResolvedInspectionAttempt, family: string): DecodedInspectionAttachment | undefined;
64
64
  export declare function runAttachment(run: LoadedInspectionRun, family: string): DecodedInspectionAttachment | undefined;
@@ -54,11 +54,11 @@ export declare function loadInspectionRuns(source: InspectionFactSource): readon
54
54
  export declare function loadSelectedInspectionRuns(source: InspectionFactSource, runIds: readonly string[]): readonly LoadedInspectionRun[];
55
55
  /** Reads Run create/close facts even when no Attempt Core has been published. */
56
56
  export declare function loadInspectionRunResource(source: InspectionFactSource, runId: string): LoadedInspectionRunResource | undefined;
57
- /** Strictly decodes all Core documents and Attachment JSON for one sealed Run. */
57
+ /** Strictly decodes Core, then decodes each Attachment only on first use. */
58
58
  export declare function decodeInspectionRun(source: InspectionFactSource, physical: SealedRunCore): LoadedInspectionRun;
59
59
  /** Resolves a public locator through the source's bounded exact index. */
60
60
  export declare function resolveInspectionAttempt(source: InspectionFactSource, locator: string): ResolvedInspectionAttempt | undefined;
61
- /** Resolves one already loaded target Member without consulting a platform index. */
61
+ /** Resolves already loaded facts through one shared identity index. */
62
62
  export declare function resolveInspectionMemberAttempt(runs: readonly LoadedInspectionRun[], target: LoadedInspectionRun, member: MemberDocument): ResolvedInspectionAttempt | undefined;
63
63
  export declare function attemptAttachment(resolved: ResolvedInspectionAttempt, family: string): DecodedInspectionAttachment | undefined;
64
64
  export declare function runAttachment(run: LoadedInspectionRun, family: string): DecodedInspectionAttachment | undefined;
@@ -63,6 +63,7 @@ function isLoadedInspectionRuns(facts) {
63
63
  return Array.isArray(facts);
64
64
  }
65
65
  function selectLatestSlots(runs, resolutionRuns = runs) {
66
+ const membersByRun = new Map(runs.map((run) => [run, new Map(run.members.map((member) => [member.slotId, member]))]));
66
67
  const latest = new Map();
67
68
  for (const target of runs) {
68
69
  for (const slot of target.run.expectedSlots) {
@@ -79,7 +80,7 @@ function selectLatestSlots(runs, resolutionRuns = runs) {
79
80
  left.slot.attemptOrdinal - right.slot.attemptOrdinal ||
80
81
  compareText(left.target.run.runId, right.target.run.runId))
81
82
  .map(({ target, slot }) => {
82
- const member = target.members.find((candidate) => candidate.slotId === slot.slotId);
83
+ const member = membersByRun.get(target)?.get(slot.slotId);
83
84
  const resolved = member === undefined
84
85
  ? undefined
85
86
  : (0, facts_ts_1.resolveInspectionMemberAttempt)(resolutionRuns, target, member);