@nimiplatform/nimi-coding 0.4.0 → 0.5.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 (47) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +47 -35
  3. package/README.zh-CN.md +48 -36
  4. package/cli/commands/authority.mjs +80 -125
  5. package/cli/constants.mjs +1 -1
  6. package/cli/dev/check-authority-surface.mjs +17 -8
  7. package/cli/dev/check-product-conformance.mjs +4 -32
  8. package/cli/lib/authority/audit.mjs +262 -185
  9. package/cli/lib/authority/change-candidates.mjs +807 -0
  10. package/cli/lib/authority/closed-sets.mjs +7 -8
  11. package/cli/lib/authority/compile.mjs +6 -24
  12. package/cli/lib/authority/compiled-snapshot.mjs +143 -0
  13. package/cli/lib/authority/consumers.mjs +69 -19
  14. package/cli/lib/authority/diagnostics.mjs +7 -1
  15. package/cli/lib/authority/diff.mjs +77 -54
  16. package/cli/lib/authority/format.mjs +4 -32
  17. package/cli/lib/authority/git-snapshot.mjs +34 -379
  18. package/cli/lib/authority/graph.mjs +10 -10
  19. package/cli/lib/authority/impact.mjs +17 -144
  20. package/cli/lib/authority/review.mjs +33 -43
  21. package/cli/lib/authority/sarif.mjs +1 -8
  22. package/cli/lib/authority/source-yaml.mjs +0 -4
  23. package/cli/lib/authority/surface.mjs +19 -1
  24. package/cli/lib/authority/terms.mjs +10 -9
  25. package/cli/lib/authority/validate.mjs +6 -14
  26. package/cli/lib/entrypoints.mjs +2 -1
  27. package/contracts/authority-source.schema.yaml +0 -6
  28. package/contracts/authority-verifier-bindings.schema.yaml +21 -10
  29. package/methodology/authority-authoring.yaml +9 -26
  30. package/methodology/core.yaml +5 -3
  31. package/package.json +1 -1
  32. package/spec/authority-audit.yaml +56 -52
  33. package/spec/authority-authoring.yaml +3 -16
  34. package/spec/authority-change-candidates.yaml +146 -0
  35. package/spec/authority-consumers.yaml +7 -0
  36. package/spec/authority-discovery.yaml +2 -2
  37. package/spec/authority-graph.yaml +1 -1
  38. package/spec/authority-impact.yaml +16 -39
  39. package/spec/authority-review.yaml +29 -47
  40. package/spec/authority-terms.yaml +5 -1
  41. package/spec/product-scope.yaml +8 -7
  42. package/cli/lib/authority/evidence-snapshot.mjs +0 -1
  43. package/cli/lib/authority/evidence.mjs +0 -1432
  44. package/contracts/authority-evidence-bindings.schema.yaml +0 -53
  45. package/contracts/authority-evidence-probe-results.schema.yaml +0 -38
  46. package/contracts/authority-impact-dispositions.schema.yaml +0 -13
  47. package/spec/authority-evidence.yaml +0 -200
@@ -1,1432 +0,0 @@
1
- import { Buffer } from "node:buffer";
2
- import { createHash } from "node:crypto";
3
- import { lstat, realpath } from "node:fs/promises";
4
- import path from "node:path";
5
- import { fileURLToPath } from "node:url";
6
-
7
- import YAML, { isMap, isScalar, isSeq } from "yaml";
8
-
9
- import { compileAuthorityPath } from "./compile.mjs";
10
- import { compareText, createLocator, makeDiagnostic, portablePath, sortDiagnostics } from "./diagnostics.mjs";
11
- import { AuthorityInputError } from "./format.mjs";
12
- import { withGitEvidenceSnapshot } from "./evidence-snapshot.mjs";
13
- import { AuthorityReviewRefusal, captureStableRegularFile } from "./git-snapshot.mjs";
14
- import { buildAuthorityGraphSnapshot } from "./graph.mjs";
15
-
16
- const EVIDENCE_FORMAT = "nimicoding.authority-evidence/v1";
17
- const BINDING_FORMAT = "nimicoding.authority-evidence-bindings/v1";
18
- const RESULT_FORMAT = "nimicoding.authority-evidence-probe-results/v1";
19
- const PACKAGE_PROBE = "package-script-target-reachability/v1";
20
- const BINDING_IDENTITY_FORMAT = "nimicoding.authority-evidence-binding/v1";
21
- const REPOSITORY_INPUT_IDENTITY_FORMAT = "nimicoding.repository-evidence-input/v1";
22
- const RESULT_CONTENT_IDENTITY_FORMAT = "nimicoding.authority-evidence-probe-result-content/v1";
23
- const FINGERPRINT_FORMAT = "nimicoding.authority-evidence-fingerprint/v1";
24
- const SHA256_IDENTITY = /^sha256:[0-9a-f]{64}$/;
25
- const IDENTIFIER = /^[a-z](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z](?:[a-z0-9-]*[a-z0-9])?)+$/;
26
- const SCRIPT_NAME = /^[a-z0-9](?:[a-z0-9._:-]*[a-z0-9])?$/;
27
- const VERSION = /^[A-Za-z0-9](?:[A-Za-z0-9._+-]*[A-Za-z0-9])?$/;
28
- const bindingContractPath = fileURLToPath(new URL("../../../contracts/authority-evidence-bindings.schema.yaml", import.meta.url));
29
- const resultContractPath = fileURLToPath(new URL("../../../contracts/authority-evidence-probe-results.schema.yaml", import.meta.url));
30
- const UTF8 = new TextDecoder("utf-8", { fatal: true });
31
-
32
- let contractsPromise = null;
33
-
34
- function exactObject(value, fields) {
35
- return value !== null && typeof value === "object" && !Array.isArray(value)
36
- && Object.keys(value).length === fields.length
37
- && Object.keys(value).every((key) => fields.includes(key));
38
- }
39
-
40
- function pointerToken(value) {
41
- return String(value).replaceAll("~", "~0").replaceAll("/", "~1");
42
- }
43
-
44
- function nodeRange(node, locator) {
45
- const range = node?.range;
46
- if (!Array.isArray(range)) return locator.range(0);
47
- return locator.range(range[0], range[1] ?? range[0]);
48
- }
49
-
50
- function collectLocations(node, locator, pointer, locations) {
51
- if (!node) return;
52
- locations.set(pointer, nodeRange(node, locator));
53
- if (isMap(node)) {
54
- for (const pair of node.items) {
55
- const key = isScalar(pair.key) ? String(pair.key.value) : "";
56
- const childPointer = `${pointer}/${pointerToken(key)}`;
57
- locations.set(childPointer, nodeRange(pair.value ?? pair.key, locator));
58
- collectLocations(pair.value, locator, childPointer, locations);
59
- }
60
- } else if (isSeq(node)) {
61
- node.items.forEach((item, index) => collectLocations(item, locator, `${pointer}/${index}`, locations));
62
- }
63
- }
64
-
65
- async function loadContracts() {
66
- if (!contractsPromise) contractsPromise = Promise.all([
67
- import("node:fs/promises").then(({ readFile }) => readFile(bindingContractPath, "utf8")),
68
- import("node:fs/promises").then(({ readFile }) => readFile(resultContractPath, "utf8")),
69
- ]).then(([bindingText, resultText]) => {
70
- const binding = YAML.parse(bindingText);
71
- const result = YAML.parse(resultText);
72
- if (binding?.version !== 1 || binding?.contract?.id !== "nimicoding.authority-evidence-bindings.v1") {
73
- throw new Error("installed authority evidence binding contract is invalid");
74
- }
75
- if (result?.version !== 1 || result?.contract?.id !== "nimicoding.authority-evidence-probe-results.v1") {
76
- throw new Error("installed authority evidence result contract is invalid");
77
- }
78
- return { binding, result };
79
- });
80
- return contractsPromise;
81
- }
82
-
83
- function location(parsed, pointer) {
84
- return {
85
- file: parsed.file,
86
- range: parsed.locations.get(pointer) ?? parsed.locations.get("") ?? { start: { line: 1, column: 1 }, end: { line: 1, column: 1 } },
87
- sourcePointer: pointer,
88
- };
89
- }
90
-
91
- function syntaxLocation(error, file, locator) {
92
- const positions = Array.isArray(error?.pos) ? error.pos : [0, 0];
93
- return {
94
- file,
95
- range: locator.range(positions[0] ?? 0, positions[1] ?? positions[0] ?? 0),
96
- sourcePointer: "",
97
- };
98
- }
99
-
100
- function evidenceDiagnostic(code, file, reason, at = null, repair = "declare one exact project-owned evidence binding without adding product semantics or executable behavior") {
101
- return makeDiagnostic({
102
- code,
103
- file,
104
- range: at?.range ?? { start: { line: 1, column: 1 }, end: { line: 1, column: 1 } },
105
- pointer: at?.sourcePointer ?? "",
106
- reason,
107
- repair,
108
- });
109
- }
110
-
111
- function bindingDiagnostic(file, reason, at = null) {
112
- return evidenceDiagnostic("AUTH_EVIDENCE_BINDING_INVALID", file, reason, at);
113
- }
114
-
115
- function resultDiagnostic(file, reason, at = null) {
116
- return evidenceDiagnostic(
117
- "AUTH_EVIDENCE_RESULT_INVALID",
118
- file,
119
- reason,
120
- at,
121
- "supply one closed external result whose repository, authority, binding, and probe identities match this exact evidence input",
122
- );
123
- }
124
-
125
- function parseYamlBytes(bytes, file, kind) {
126
- let text;
127
- try {
128
- text = UTF8.decode(bytes);
129
- } catch {
130
- const diagnostic = kind === "binding" ? bindingDiagnostic(file, "evidence binding bytes are not valid UTF-8") : resultDiagnostic(file, "evidence probe result bytes are not valid UTF-8");
131
- return { ok: false, diagnostics: [diagnostic] };
132
- }
133
- const locator = createLocator(text);
134
- const documents = YAML.parseAllDocuments(text, {
135
- keepSourceTokens: true,
136
- prettyErrors: false,
137
- strict: true,
138
- uniqueKeys: true,
139
- version: "1.2",
140
- });
141
- if (documents.length !== 1 || documents[0].errors.length > 0 || !isMap(documents[0].contents)) {
142
- const error = documents[0]?.errors?.[0];
143
- const at = syntaxLocation(error, file, locator);
144
- const reason = documents.length !== 1
145
- ? `evidence ${kind} must contain exactly one YAML document`
146
- : error ? `invalid evidence ${kind} YAML: ${error.message.split(" at line")[0]}` : `evidence ${kind} requires one top-level mapping`;
147
- return { ok: false, diagnostics: [kind === "binding" ? bindingDiagnostic(file, reason, at) : resultDiagnostic(file, reason, at)] };
148
- }
149
- let data;
150
- try {
151
- data = documents[0].toJS({ maxAliasCount: 0 });
152
- } catch (error) {
153
- const diagnostic = kind === "binding" ? bindingDiagnostic(file, `invalid evidence binding YAML: ${error.message}`) : resultDiagnostic(file, `invalid evidence probe result YAML: ${error.message}`);
154
- return { ok: false, diagnostics: [diagnostic] };
155
- }
156
- const locations = new Map();
157
- collectLocations(documents[0].contents, locator, "", locations);
158
- return { ok: true, parsed: { data, file, text, locator, locations } };
159
- }
160
-
161
- function validRepositoryPath(value) {
162
- if (typeof value !== "string" || value.length === 0 || value !== value.normalize("NFC") || value.startsWith("-") || value.includes("\\") || value.includes("\0") || value.includes("\n") || value.includes("\r") || path.posix.isAbsolute(value)) return false;
163
- const parts = value.split("/");
164
- return parts.every((part) => part.length > 0 && part !== "." && part !== ".." && part.toLowerCase() !== ".git");
165
- }
166
-
167
- function pathCollisionKey(value) {
168
- return value.normalize("NFC").toLowerCase();
169
- }
170
-
171
- export async function parseEvidenceBindings(bytes, file) {
172
- const decoded = parseYamlBytes(bytes, file, "binding");
173
- if (!decoded.ok) return decoded;
174
- const { binding: contract } = await loadContracts();
175
- const parsed = decoded.parsed;
176
- const data = parsed.data;
177
- if (!exactObject(data, contract.fields.top) || data.format !== BINDING_FORMAT || !Array.isArray(data.required_bindings) || data.required_bindings.length === 0 || !Array.isArray(data.bindings)) {
178
- return { ok: false, diagnostics: [bindingDiagnostic(file, "evidence bindings require exact format, required_bindings, and bindings fields", location(parsed, ""))] };
179
- }
180
- const required = [];
181
- const requiredIds = new Set();
182
- for (let index = 0; index < data.required_bindings.length; index += 1) {
183
- const id = data.required_bindings[index];
184
- const pointer = `/required_bindings/${index}`;
185
- if (typeof id !== "string" || !IDENTIFIER.test(id)) return { ok: false, diagnostics: [bindingDiagnostic(file, "required evidence binding IDs must be exact dotted lowercase identifiers", location(parsed, pointer))] };
186
- if (requiredIds.has(id)) return { ok: false, diagnostics: [bindingDiagnostic(file, `duplicate required evidence binding ID: ${id}`, location(parsed, pointer))] };
187
- requiredIds.add(id);
188
- required.push({ id, location: location(parsed, pointer) });
189
- }
190
- const bindings = [];
191
- const bindingIds = new Set();
192
- const globalLocatorPaths = new Map();
193
- for (let index = 0; index < data.bindings.length; index += 1) {
194
- const value = data.bindings[index];
195
- const pointer = `/bindings/${index}`;
196
- if (!exactObject(value, contract.fields.binding)) return { ok: false, diagnostics: [bindingDiagnostic(file, "each evidence binding requires exact id, authority, probe, manifest, command, tests, and external_probe fields", location(parsed, pointer))] };
197
- if (typeof value.id !== "string" || !IDENTIFIER.test(value.id)) return { ok: false, diagnostics: [bindingDiagnostic(file, "evidence binding id must be one exact dotted lowercase identifier", location(parsed, `${pointer}/id`))] };
198
- if (bindingIds.has(value.id)) return { ok: false, diagnostics: [bindingDiagnostic(file, `duplicate evidence binding ID: ${value.id}`, location(parsed, `${pointer}/id`))] };
199
- bindingIds.add(value.id);
200
- if (!exactObject(value.authority, contract.fields.authority)
201
- || typeof value.authority.unit !== "string" || !IDENTIFIER.test(value.authority.unit)
202
- || typeof value.authority.scope !== "string" || !IDENTIFIER.test(value.authority.scope)) {
203
- return { ok: false, diagnostics: [bindingDiagnostic(file, "binding authority requires one exact active rule ID and one exact declared scope", location(parsed, `${pointer}/authority`))] };
204
- }
205
- if (value.probe !== PACKAGE_PROBE) return { ok: false, diagnostics: [bindingDiagnostic(file, `unknown package evidence probe: ${String(value.probe)}`, location(parsed, `${pointer}/probe`))] };
206
- if (!validRepositoryPath(value.manifest)) return { ok: false, diagnostics: [bindingDiagnostic(file, "binding manifest must be one normalized safe repository-relative path", location(parsed, `${pointer}/manifest`))] };
207
- if (!exactObject(value.command, contract.fields.command) || typeof value.command.script !== "string" || !SCRIPT_NAME.test(value.command.script) || !validRepositoryPath(value.command.target)) {
208
- return { ok: false, diagnostics: [bindingDiagnostic(file, "binding command requires one exact safe script name and repository-relative target", location(parsed, `${pointer}/command`))] };
209
- }
210
- if (!exactObject(value.tests, contract.fields.tests) || typeof value.tests.script !== "string" || !SCRIPT_NAME.test(value.tests.script) || !Array.isArray(value.tests.targets) || value.tests.targets.length === 0) {
211
- return { ok: false, diagnostics: [bindingDiagnostic(file, "binding tests require one exact safe script name and a non-empty target list", location(parsed, `${pointer}/tests`))] };
212
- }
213
- if (value.tests.script === value.command.script) {
214
- return { ok: false, diagnostics: [bindingDiagnostic(file, "binding command and test script keys must be distinct", location(parsed, `${pointer}/tests/script`))] };
215
- }
216
- const testTargets = [];
217
- const targetPaths = new Set();
218
- for (let targetIndex = 0; targetIndex < value.tests.targets.length; targetIndex += 1) {
219
- const target = value.tests.targets[targetIndex];
220
- const targetPointer = `${pointer}/tests/targets/${targetIndex}`;
221
- if (!validRepositoryPath(target)) return { ok: false, diagnostics: [bindingDiagnostic(file, "test targets must be normalized safe repository-relative paths", location(parsed, targetPointer))] };
222
- const collision = pathCollisionKey(target);
223
- if (targetPaths.has(collision)) return { ok: false, diagnostics: [bindingDiagnostic(file, `duplicate or portable-colliding test target: ${target}`, location(parsed, targetPointer))] };
224
- targetPaths.add(collision);
225
- testTargets.push({ path: target, location: location(parsed, targetPointer) });
226
- }
227
- const locatorPaths = [value.manifest, value.command.target, ...testTargets.map((entry) => entry.path)];
228
- const locatorCollisions = new Set();
229
- for (const locatorPath of locatorPaths) {
230
- const collision = pathCollisionKey(locatorPath);
231
- if (locatorCollisions.has(collision)) return { ok: false, diagnostics: [bindingDiagnostic(file, `binding locator roles must resolve to distinct portable paths: ${locatorPath}`, location(parsed, pointer))] };
232
- locatorCollisions.add(collision);
233
- }
234
- for (const entry of [
235
- { path: value.manifest, location: location(parsed, `${pointer}/manifest`) },
236
- { path: value.command.target, location: location(parsed, `${pointer}/command/target`) },
237
- ...testTargets,
238
- ]) {
239
- const collision = pathCollisionKey(entry.path);
240
- const existing = globalLocatorPaths.get(collision);
241
- if (existing && existing.path !== entry.path) {
242
- return { ok: false, diagnostics: [bindingDiagnostic(file, `cross-binding repository locators must not portable-collide: ${existing.path} and ${entry.path}`, entry.location)] };
243
- }
244
- globalLocatorPaths.set(collision, entry);
245
- }
246
- let externalProbe = null;
247
- if (value.external_probe !== null) {
248
- if (!exactObject(value.external_probe, contract.fields.external_probe)
249
- || typeof value.external_probe.id !== "string" || !IDENTIFIER.test(value.external_probe.id)
250
- || typeof value.external_probe.version !== "string" || !VERSION.test(value.external_probe.version)
251
- || typeof value.external_probe.required !== "boolean") {
252
- return { ok: false, diagnostics: [bindingDiagnostic(file, "external_probe must be null or exact id, explicit version, and required fields", location(parsed, `${pointer}/external_probe`))] };
253
- }
254
- externalProbe = {
255
- ...value.external_probe,
256
- location: location(parsed, `${pointer}/external_probe`),
257
- };
258
- }
259
- bindings.push({
260
- id: value.id,
261
- authority: { unit: value.authority.unit, scope: value.authority.scope },
262
- probe: value.probe,
263
- manifest: value.manifest,
264
- command: value.command,
265
- tests: { script: value.tests.script, targets: testTargets },
266
- externalProbe,
267
- location: location(parsed, `${pointer}/id`),
268
- authorityLocation: location(parsed, `${pointer}/authority/unit`),
269
- scopeLocation: location(parsed, `${pointer}/authority/scope`),
270
- manifestLocation: location(parsed, `${pointer}/manifest`),
271
- commandScriptLocation: location(parsed, `${pointer}/command/script`),
272
- commandTargetLocation: location(parsed, `${pointer}/command/target`),
273
- testScriptLocation: location(parsed, `${pointer}/tests/script`),
274
- });
275
- }
276
- required.sort((left, right) => compareText(left.id, right.id));
277
- bindings.sort((left, right) => compareText(left.id, right.id));
278
- return { ok: true, diagnostics: [], required, bindings };
279
- }
280
-
281
- export async function parseEvidenceProbeResults(bytes, file) {
282
- const decoded = parseYamlBytes(bytes, file, "result");
283
- if (!decoded.ok) return decoded;
284
- const { result: contract } = await loadContracts();
285
- const parsed = decoded.parsed;
286
- const data = parsed.data;
287
- if (!exactObject(data, contract.fields.top) || data.format !== RESULT_FORMAT || !Array.isArray(data.results)) {
288
- return { ok: false, diagnostics: [resultDiagnostic(file, "probe results require exact format, authority_content_identity, repository_input_identity, binding_identity, and results fields", location(parsed, ""))] };
289
- }
290
- for (const [field, pointer] of [
291
- [data.authority_content_identity, "/authority_content_identity"],
292
- [data.repository_input_identity, "/repository_input_identity"],
293
- [data.binding_identity, "/binding_identity"],
294
- ]) {
295
- if (typeof field !== "string" || !SHA256_IDENTITY.test(field)) return { ok: false, diagnostics: [resultDiagnostic(file, "probe result identities must be sha256-prefixed lowercase hexadecimal values", location(parsed, pointer))] };
296
- }
297
- const results = [];
298
- const seen = new Set();
299
- for (let index = 0; index < data.results.length; index += 1) {
300
- const value = data.results[index];
301
- const pointer = `/results/${index}`;
302
- if (!exactObject(value, contract.fields.item) || !exactObject(value?.adapter, contract.fields.adapter)) return { ok: false, diagnostics: [resultDiagnostic(file, "each probe result requires exact binding, probe, version, adapter, execution, and outcome fields", location(parsed, pointer))] };
303
- if (typeof value.binding !== "string" || !IDENTIFIER.test(value.binding) || typeof value.probe !== "string" || !IDENTIFIER.test(value.probe) || typeof value.version !== "string" || !VERSION.test(value.version)) {
304
- return { ok: false, diagnostics: [resultDiagnostic(file, "probe result binding, probe, and version must be exact identifiers", location(parsed, pointer))] };
305
- }
306
- if (seen.has(value.binding)) return { ok: false, diagnostics: [resultDiagnostic(file, `duplicate external probe result for binding: ${value.binding}`, location(parsed, `${pointer}/binding`))] };
307
- seen.add(value.binding);
308
- if (typeof value.adapter.id !== "string" || !IDENTIFIER.test(value.adapter.id) || typeof value.adapter.version !== "string" || !VERSION.test(value.adapter.version)) {
309
- return { ok: false, diagnostics: [resultDiagnostic(file, "external adapter requires one exact identifier and explicit version", location(parsed, `${pointer}/adapter`))] };
310
- }
311
- if (!contract.execution.includes(value.execution)) return { ok: false, diagnostics: [resultDiagnostic(file, "external execution must be completed, failed, or unsupported", location(parsed, `${pointer}/execution`))] };
312
- const validOutcome = value.execution === "completed" ? ["passed", "failed"].includes(value.outcome) : value.outcome === null;
313
- if (!validOutcome) return { ok: false, diagnostics: [resultDiagnostic(file, "completed external execution requires passed or failed outcome; failed or unsupported execution requires null outcome", location(parsed, `${pointer}/outcome`))] };
314
- results.push({ ...value, location: location(parsed, pointer) });
315
- }
316
- results.sort((left, right) => compareText(left.binding, right.binding));
317
- return {
318
- ok: true,
319
- diagnostics: [],
320
- authorityContentIdentity: data.authority_content_identity,
321
- repositoryInputIdentity: data.repository_input_identity,
322
- bindingIdentity: data.binding_identity,
323
- results,
324
- };
325
- }
326
-
327
- function frame(hash, value) {
328
- const bytes = Buffer.isBuffer(value) ? value : Buffer.from(value, "utf8");
329
- const length = Buffer.alloc(8);
330
- length.writeBigUInt64BE(BigInt(bytes.length));
331
- hash.update(length);
332
- hash.update(bytes);
333
- }
334
-
335
- function identity(domain, values) {
336
- const hash = createHash("sha256");
337
- frame(hash, domain);
338
- for (const value of values) frame(hash, value);
339
- return `sha256:${hash.digest("hex")}`;
340
- }
341
-
342
- export function evidenceBindingIdentity(bytes) {
343
- return identity(BINDING_IDENTITY_FORMAT, [bytes]);
344
- }
345
-
346
- export function evidenceRepositoryInputIdentity(locatorEntries) {
347
- const ordered = [...locatorEntries].sort((left, right) => compareText(left.path, right.path));
348
- const values = [String(ordered.length)];
349
- for (const entry of ordered) values.push(entry.path, entry.type, entry.bytes ?? Buffer.alloc(0));
350
- return identity(REPOSITORY_INPUT_IDENTITY_FORMAT, values);
351
- }
352
-
353
- export function evidenceProbeResultContentIdentity(bytes) {
354
- return identity(RESULT_CONTENT_IDENTITY_FORMAT, [bytes]);
355
- }
356
-
357
- function fingerprint(parts) {
358
- return identity(FINGERPRINT_FORMAT, parts);
359
- }
360
-
361
- function locatorPaths(parsedBindings) {
362
- const values = new Map();
363
- for (const binding of parsedBindings.bindings) {
364
- for (const value of [binding.manifest, binding.command.target, ...binding.tests.targets.map((target) => target.path)]) {
365
- const collision = pathCollisionKey(value);
366
- const existing = values.get(collision);
367
- if (existing && existing !== value) throw new Error("portable locator collision escaped binding validation");
368
- values.set(collision, value);
369
- }
370
- }
371
- return [...values.values()].sort(compareText);
372
- }
373
-
374
- function validBudget(value) {
375
- return Number.isSafeInteger(value) && value > 0;
376
- }
377
-
378
- function refused(diagnostics, evidenceBytes = 0) {
379
- return {
380
- ok: false,
381
- diagnostics: sortDiagnostics(diagnostics),
382
- fileCount: 0,
383
- unitCount: 0,
384
- evidenceBytes,
385
- evidence: null,
386
- partial: false,
387
- };
388
- }
389
-
390
- function budgetDiagnostic(kind, required, admitted, at = null) {
391
- return evidenceDiagnostic(
392
- "AUTH_EVIDENCE_BUDGET",
393
- at?.file ?? ".",
394
- `complete authority evidence requires ${required} ${kind} but the explicit budget is ${admitted}`,
395
- at,
396
- "increase the explicit evidence budget; partial locator, edge, input, or output evidence is forbidden",
397
- );
398
- }
399
-
400
- function snapshotDiagnostic(error) {
401
- const code = error.code === "AUTH_EVIDENCE_INPUT_BUDGET"
402
- ? "AUTH_EVIDENCE_BUDGET"
403
- : error.code?.startsWith("AUTH_EVIDENCE_") ? error.code : "AUTH_EVIDENCE_CAPTURE_INVALID";
404
- return evidenceDiagnostic(
405
- code,
406
- error.file ?? ".",
407
- error.message,
408
- null,
409
- "provide one complete stable repository evidence input; no partial evidence snapshot is admitted",
410
- );
411
- }
412
-
413
- function sameStrings(left, right) {
414
- return left.length === right.length && left.every((value, index) => value === right[index]);
415
- }
416
-
417
- function portableLocation(file, range = null, sourcePointer = "") {
418
- return {
419
- file,
420
- range: range ?? { start: { line: 1, column: 1 }, end: { line: 1, column: 1 } },
421
- sourcePointer,
422
- };
423
- }
424
-
425
- function relatedLocation(role, value) {
426
- return { role, location: value };
427
- }
428
-
429
- function compareRelatedLocation(left, right) {
430
- return compareText(left.role, right.role)
431
- || compareText(left.location.file, right.location.file)
432
- || left.location.range.start.line - right.location.range.start.line
433
- || left.location.range.start.column - right.location.range.start.column
434
- || compareText(left.location.sourcePointer, right.location.sourcePointer);
435
- }
436
-
437
- function compareItem(left, right) {
438
- return compareText(left.binding, right.binding)
439
- || compareText(left.code, right.code)
440
- || compareText(left.logicalTarget ?? "", right.logicalTarget ?? "");
441
- }
442
-
443
- function commonItem(code, binding, basis, message, primaryLocation, relatedLocations, witness, logicalTarget = "") {
444
- return {
445
- code,
446
- fingerprint: fingerprint([code, PACKAGE_PROBE, binding.id, binding.authority.unit, binding.authority.scope, logicalTarget]),
447
- binding: binding.id,
448
- required: binding.required,
449
- authority: binding.authority.unit,
450
- scope: binding.authority.scope,
451
- basis,
452
- message,
453
- primaryLocation,
454
- relatedLocations: [...relatedLocations].sort(compareRelatedLocation),
455
- witness,
456
- logicalTarget,
457
- };
458
- }
459
-
460
- function requiredBindingGap(required) {
461
- const code = "AUTH_EVIDENCE_REQUIRED_BINDING_MISSING";
462
- return {
463
- code,
464
- fingerprint: fingerprint([code, required.id]),
465
- binding: required.id,
466
- required: true,
467
- authority: null,
468
- scope: null,
469
- basis: "required_coverage",
470
- message: `required authority evidence binding is missing: ${required.id}`,
471
- primaryLocation: required.location,
472
- relatedLocations: [],
473
- witness: { type: "required-binding", required: true, present: false },
474
- logicalTarget: required.id,
475
- };
476
- }
477
-
478
- function parseManifest(bytes, file) {
479
- let text;
480
- try {
481
- text = UTF8.decode(bytes);
482
- } catch {
483
- return { ok: false, reason: "manifest bytes are not valid UTF-8", location: portableLocation(file) };
484
- }
485
- let json;
486
- try {
487
- json = JSON.parse(text);
488
- } catch (error) {
489
- return { ok: false, reason: `manifest is not valid JSON: ${error.message}`, location: portableLocation(file) };
490
- }
491
- if (json === null || typeof json !== "object" || Array.isArray(json)) {
492
- return { ok: false, reason: "manifest JSON must be one top-level object", location: portableLocation(file) };
493
- }
494
- const locator = createLocator(text);
495
- const document = YAML.parseDocument(text, {
496
- keepSourceTokens: true,
497
- prettyErrors: false,
498
- strict: true,
499
- uniqueKeys: true,
500
- version: "1.2",
501
- });
502
- if (document.errors.length > 0 || !isMap(document.contents)) {
503
- const error = document.errors[0];
504
- return { ok: false, reason: `manifest cannot be uniquely addressed: ${error?.message?.split(" at line")[0] ?? "invalid object"}`, location: portableLocation(file, syntaxLocation(error, file, locator).range) };
505
- }
506
- const scriptsPair = document.contents.items.find((pair) => isScalar(pair.key) && pair.key.value === "scripts");
507
- if (!scriptsPair || !isMap(scriptsPair.value)) {
508
- return { ok: false, reason: "manifest requires one scripts object for this probe", location: portableLocation(file) };
509
- }
510
- function script(name) {
511
- const pair = scriptsPair.value.items.find((entry) => isScalar(entry.key) && entry.key.value === name);
512
- const pointer = `/scripts/${pointerToken(name)}`;
513
- if (!pair) return { state: "missing", value: null, location: portableLocation(file, nodeRange(scriptsPair.value, locator), pointer) };
514
- if (!isScalar(pair.value) || typeof pair.value.value !== "string") {
515
- return { state: "unsupported", value: null, location: portableLocation(file, nodeRange(pair.value ?? pair.key, locator), pointer), reason: `manifest script ${name} must be one string` };
516
- }
517
- return { state: "present", value: pair.value.value, location: portableLocation(file, nodeRange(pair.value, locator), pointer) };
518
- }
519
- return { ok: true, script };
520
- }
521
-
522
- function scriptTokens(value) {
523
- if (typeof value !== "string" || !/^[\x21-\x7e]+(?: [\x21-\x7e]+)*$/.test(value)) return null;
524
- return value.split(" ");
525
- }
526
-
527
- function validScriptTarget(value) {
528
- return validRepositoryPath(value) && /^[A-Za-z0-9._/-]+$/.test(value);
529
- }
530
-
531
- function parseCommandScript(value) {
532
- const tokens = scriptTokens(value);
533
- if (!tokens || tokens.length !== 4 || tokens[0] !== "node" || tokens[1] !== "--import" || tokens[2] !== "tsx" || !validScriptTarget(tokens[3])) {
534
- return { ok: false, reason: "command script is outside the closed `node --import tsx <target>` grammar" };
535
- }
536
- return { ok: true, target: tokens[3] };
537
- }
538
-
539
- function parseTestScript(value) {
540
- const tokens = scriptTokens(value);
541
- if (!tokens || tokens.length < 5 || tokens[0] !== "pnpm" || tokens[1] !== "exec" || tokens[2] !== "vitest" || tokens[3] !== "run") {
542
- return { ok: false, reason: "test script is outside the closed `pnpm exec vitest run <targets...>` grammar" };
543
- }
544
- const targets = tokens.slice(4);
545
- if (targets.some((target) => !validScriptTarget(target)) || new Set(targets.map(pathCollisionKey)).size !== targets.length) {
546
- return { ok: false, reason: "test script targets must be unique safe repository-relative paths without flags, globs, quoting, or shell syntax" };
547
- }
548
- return { ok: true, targets };
549
- }
550
-
551
- function inputState(inputByPath, file) {
552
- const input = inputByPath.get(file);
553
- if (!input || input.role !== "locator") throw new Error(`captured evidence locator is missing from snapshot adapter output: ${file}`);
554
- return input;
555
- }
556
-
557
- function locatorRecord(id, role, file, input, declaredLocation) {
558
- return {
559
- id,
560
- role,
561
- path: file,
562
- existence: input.type === "regular-file" ? "present" : "missing",
563
- declarationLocation: declaredLocation,
564
- ...(input.type === "regular-file" ? { repositoryLocation: portableLocation(file) } : {}),
565
- };
566
- }
567
-
568
- function reachabilityFinding(binding, logicalTarget, message, primaryLocation, relatedLocations, witness) {
569
- return commonItem(
570
- "AUTH_EVIDENCE_REQUIRED_TARGET_UNREACHABLE",
571
- binding,
572
- "governance_bound_package_probe",
573
- message,
574
- primaryLocation,
575
- relatedLocations,
576
- witness,
577
- logicalTarget,
578
- );
579
- }
580
-
581
- function capabilityGap(binding, logicalTarget, message, primaryLocation, relatedLocations, witness) {
582
- return commonItem(
583
- "AUTH_EVIDENCE_PROBE_UNSUPPORTED",
584
- binding,
585
- "required_probe_capability",
586
- message,
587
- primaryLocation,
588
- relatedLocations,
589
- witness,
590
- logicalTarget,
591
- );
592
- }
593
-
594
- function proofEdge(id, source, target, basis, status, sourceLocation = null, targetLocation = null, extra = {}) {
595
- return { id, source, target, basis, status, sourceLocation, targetLocation, ...extra };
596
- }
597
-
598
- function compareProofEdge(left, right) {
599
- return compareText(left.source, right.source)
600
- || compareText(left.target, right.target)
601
- || compareText(left.id, right.id);
602
- }
603
-
604
- function evaluatePackageProbe(binding, authorityNode, inputByPath) {
605
- const observations = [];
606
- const findings = [];
607
- const gaps = [];
608
- const manifestInput = inputState(inputByPath, binding.manifest);
609
- const commandInput = inputState(inputByPath, binding.command.target);
610
- const testInputs = binding.tests.targets.map((target) => ({ target, input: inputState(inputByPath, target.path) }));
611
- const commandScriptLocator = {
612
- id: "command-script",
613
- role: "producer",
614
- path: `${binding.manifest}#scripts/${binding.command.script}`,
615
- existence: "indeterminate",
616
- declarationLocation: binding.commandScriptLocation,
617
- };
618
- const testScriptLocator = {
619
- id: "test-script",
620
- role: "test-producer",
621
- path: `${binding.manifest}#scripts/${binding.tests.script}`,
622
- existence: "indeterminate",
623
- declarationLocation: binding.testScriptLocation,
624
- };
625
- const locators = [
626
- {
627
- id: "authority",
628
- role: "authority",
629
- authorityId: binding.authority.unit,
630
- existence: "present",
631
- declarationLocation: binding.authorityLocation,
632
- repositoryLocation: authorityNode.node.location,
633
- scopeRepositoryLocation: authorityNode.scopeLocation,
634
- },
635
- locatorRecord("manifest", "manifest", binding.manifest, manifestInput, binding.manifestLocation),
636
- commandScriptLocator,
637
- locatorRecord("command-target", "implementation", binding.command.target, commandInput, binding.commandTargetLocation),
638
- testScriptLocator,
639
- ...testInputs.map(({ target, input }, index) => locatorRecord(`test-target-${index + 1}`, "test", target.path, input, target.location)),
640
- ];
641
- const baseRelated = [
642
- relatedLocation("authority", authorityNode.node.location),
643
- relatedLocation("authority-scope", authorityNode.scopeLocation),
644
- relatedLocation("binding", binding.location),
645
- relatedLocation("binding-manifest", binding.manifestLocation),
646
- ];
647
- if (commandInput.type !== "regular-file") {
648
- findings.push(reachabilityFinding(
649
- binding,
650
- "command-target",
651
- `bound command target is missing: ${binding.command.target}`,
652
- binding.commandTargetLocation,
653
- baseRelated,
654
- { type: "locator-existence", role: "implementation", path: binding.command.target, existence: "missing" },
655
- ));
656
- }
657
- for (let index = 0; index < testInputs.length; index += 1) {
658
- const target = testInputs[index];
659
- if (target.input.type === "regular-file") continue;
660
- findings.push(reachabilityFinding(
661
- binding,
662
- `test-target-${index + 1}`,
663
- `bound test target is missing: ${target.target.path}`,
664
- target.target.location,
665
- baseRelated,
666
- { type: "locator-existence", role: "test", path: target.target.path, existence: "missing" },
667
- ));
668
- }
669
- let manifest = null;
670
- if (manifestInput.type !== "regular-file") {
671
- findings.push(reachabilityFinding(
672
- binding,
673
- "manifest",
674
- `bound manifest locator is missing: ${binding.manifest}`,
675
- binding.manifestLocation,
676
- baseRelated,
677
- { type: "locator-existence", role: "manifest", path: binding.manifest, existence: "missing" },
678
- ));
679
- } else {
680
- manifest = parseManifest(manifestInput.bytes, binding.manifest);
681
- if (!manifest.ok) {
682
- gaps.push(capabilityGap(
683
- binding,
684
- "manifest",
685
- `package script probe cannot decide manifest ${binding.manifest}: ${manifest.reason}`,
686
- manifest.location,
687
- baseRelated,
688
- { type: "manifest-parse", supported: false, reason: manifest.reason },
689
- ));
690
- }
691
- }
692
-
693
- const commandEdge = {
694
- source: "command-script",
695
- target: "command-target",
696
- basis: "closed_package_script_grammar",
697
- status: "indeterminate",
698
- };
699
- let commandScript = null;
700
- if (manifest?.ok) {
701
- commandScript = manifest.script(binding.command.script);
702
- if (commandScript.state === "missing") {
703
- commandScriptLocator.existence = "missing";
704
- commandEdge.status = "missing";
705
- findings.push(reachabilityFinding(
706
- binding,
707
- `script:${binding.command.script}`,
708
- `bound command script is missing from ${binding.manifest}: ${binding.command.script}`,
709
- binding.commandScriptLocation,
710
- [...baseRelated, relatedLocation("manifest", portableLocation(binding.manifest))],
711
- { type: "manifest-script", script: binding.command.script, present: false },
712
- ));
713
- } else if (commandScript.state === "unsupported") {
714
- commandScriptLocator.existence = "present";
715
- commandScriptLocator.repositoryLocation = commandScript.location;
716
- gaps.push(capabilityGap(
717
- binding,
718
- `script:${binding.command.script}`,
719
- commandScript.reason,
720
- commandScript.location,
721
- baseRelated,
722
- { type: "manifest-script", script: binding.command.script, supported: false },
723
- ));
724
- } else {
725
- commandScriptLocator.existence = "present";
726
- commandScriptLocator.repositoryLocation = commandScript.location;
727
- const parsed = parseCommandScript(commandScript.value);
728
- commandEdge.sourceLocation = commandScript.location;
729
- if (!parsed.ok) {
730
- gaps.push(capabilityGap(
731
- binding,
732
- `script:${binding.command.script}`,
733
- parsed.reason,
734
- commandScript.location,
735
- baseRelated,
736
- { type: "closed-command-grammar", script: binding.command.script, supported: false },
737
- ));
738
- } else if (parsed.target !== binding.command.target) {
739
- commandEdge.status = "mismatch";
740
- findings.push(reachabilityFinding(
741
- binding,
742
- "command-script-target-match",
743
- `command script target does not match the bound implementation locator: expected ${binding.command.target}; observed ${parsed.target}`,
744
- commandScript.location,
745
- [...baseRelated, relatedLocation("binding-target", binding.commandTargetLocation)],
746
- { type: "command-target", expected: binding.command.target, observed: parsed.target, match: false },
747
- ));
748
- } else if (commandInput.type !== "regular-file") {
749
- commandEdge.status = "missing";
750
- } else {
751
- commandEdge.status = "reachable";
752
- commandEdge.targetLocation = portableLocation(binding.command.target);
753
- }
754
- }
755
- }
756
-
757
- const expectedTestTargets = binding.tests.targets.map((target) => target.path);
758
- const testEdges = expectedTestTargets.map((target, index) => ({
759
- source: "test-script",
760
- target: `test-target-${index + 1}`,
761
- targetPath: target,
762
- basis: "closed_package_script_grammar",
763
- status: "indeterminate",
764
- }));
765
- let testScript = null;
766
- if (manifest?.ok) {
767
- testScript = manifest.script(binding.tests.script);
768
- if (testScript.state === "missing") {
769
- testScriptLocator.existence = "missing";
770
- for (const edge of testEdges) edge.status = "missing";
771
- findings.push(reachabilityFinding(
772
- binding,
773
- `script:${binding.tests.script}`,
774
- `bound test script is missing from ${binding.manifest}: ${binding.tests.script}`,
775
- binding.testScriptLocation,
776
- [...baseRelated, relatedLocation("manifest", portableLocation(binding.manifest))],
777
- { type: "manifest-script", script: binding.tests.script, present: false },
778
- ));
779
- } else if (testScript.state === "unsupported") {
780
- testScriptLocator.existence = "present";
781
- testScriptLocator.repositoryLocation = testScript.location;
782
- gaps.push(capabilityGap(
783
- binding,
784
- `script:${binding.tests.script}`,
785
- testScript.reason,
786
- testScript.location,
787
- baseRelated,
788
- { type: "manifest-script", script: binding.tests.script, supported: false },
789
- ));
790
- } else {
791
- testScriptLocator.existence = "present";
792
- testScriptLocator.repositoryLocation = testScript.location;
793
- const parsed = parseTestScript(testScript.value);
794
- for (const edge of testEdges) edge.sourceLocation = testScript.location;
795
- if (!parsed.ok) {
796
- gaps.push(capabilityGap(
797
- binding,
798
- `script:${binding.tests.script}`,
799
- parsed.reason,
800
- testScript.location,
801
- baseRelated,
802
- { type: "closed-test-grammar", script: binding.tests.script, supported: false },
803
- ));
804
- } else if (!sameStrings(parsed.targets, expectedTestTargets)) {
805
- const expectedSet = new Set(expectedTestTargets);
806
- const observedSet = new Set(parsed.targets);
807
- for (const edge of testEdges) edge.status = observedSet.has(edge.targetPath) ? "mismatch" : "missing";
808
- findings.push(reachabilityFinding(
809
- binding,
810
- "test-targets",
811
- `test script targets do not exactly match the bound ordered test locator set for ${binding.tests.script}`,
812
- testScript.location,
813
- [...baseRelated, ...binding.tests.targets.map((target) => relatedLocation("binding-test-target", target.location))],
814
- {
815
- type: "test-target-set",
816
- expected: expectedTestTargets,
817
- observed: parsed.targets,
818
- missing: expectedTestTargets.filter((target) => !observedSet.has(target)),
819
- unexpected: parsed.targets.filter((target) => !expectedSet.has(target)),
820
- orderedMatch: false,
821
- },
822
- ));
823
- } else {
824
- for (let index = 0; index < testEdges.length; index += 1) {
825
- const edge = testEdges[index];
826
- const target = testInputs[index];
827
- if (target.input.type !== "regular-file") {
828
- edge.status = "missing";
829
- } else {
830
- edge.status = "reachable";
831
- edge.targetLocation = portableLocation(target.target.path);
832
- }
833
- }
834
- }
835
- }
836
- }
837
-
838
- const hasGap = gaps.length > 0;
839
- const hasFinding = findings.length > 0;
840
- const reachability = hasFinding ? "unreachable" : hasGap ? "indeterminate" : "reachable";
841
- const manifestRepositoryLocation = manifestInput.type === "regular-file" ? portableLocation(binding.manifest) : null;
842
- const commandScriptEntryStatus = !manifest?.ok ? "indeterminate" : commandScript?.state === "missing" ? "missing" : "reachable";
843
- const testScriptEntryStatus = !manifest?.ok ? "indeterminate" : testScript?.state === "missing" ? "missing" : "reachable";
844
- const edges = [
845
- proofEdge("authority-binding", "authority", "binding", "project_binding", "bound", authorityNode.node.location, binding.location),
846
- proofEdge(
847
- "binding-manifest",
848
- "binding",
849
- "manifest",
850
- "declared_locator",
851
- manifestInput.type === "regular-file" ? "reachable" : "missing",
852
- binding.location,
853
- manifestRepositoryLocation,
854
- ),
855
- proofEdge(
856
- "manifest-command-script",
857
- "manifest",
858
- "command-script",
859
- "manifest_scripts_entry",
860
- commandScriptEntryStatus,
861
- manifestRepositoryLocation,
862
- commandScriptEntryStatus === "reachable" ? commandScript.location : null,
863
- ),
864
- proofEdge(
865
- "command-script-command-target",
866
- commandEdge.source,
867
- commandEdge.target,
868
- commandEdge.basis,
869
- commandEdge.status,
870
- commandEdge.sourceLocation ?? null,
871
- commandEdge.targetLocation ?? null,
872
- ),
873
- proofEdge(
874
- "manifest-test-script",
875
- "manifest",
876
- "test-script",
877
- "manifest_scripts_entry",
878
- testScriptEntryStatus,
879
- manifestRepositoryLocation,
880
- testScriptEntryStatus === "reachable" ? testScript.location : null,
881
- ),
882
- ...testEdges.map((edge) => proofEdge(
883
- `${edge.source}-${edge.target}`,
884
- edge.source,
885
- edge.target,
886
- edge.basis,
887
- edge.status,
888
- edge.sourceLocation ?? null,
889
- edge.targetLocation ?? null,
890
- { targetPath: edge.targetPath },
891
- )),
892
- ].sort(compareProofEdge);
893
- observations.push(commonItem(
894
- "AUTH_EVIDENCE_PACKAGE_PROBE_OBSERVATION",
895
- binding,
896
- "project_binding_package_probe",
897
- `evaluated declared package-script targets for evidence binding ${binding.id}`,
898
- binding.location,
899
- [
900
- relatedLocation("authority", authorityNode.node.location),
901
- relatedLocation("authority-scope", authorityNode.scopeLocation),
902
- ...(commandScript?.location ? [relatedLocation("command-script", commandScript.location)] : []),
903
- ...(testScript?.location ? [relatedLocation("test-script", testScript.location)] : []),
904
- ...(commandInput.type === "regular-file" ? [relatedLocation("command-target", portableLocation(binding.command.target))] : []),
905
- ...testInputs.filter(({ input }) => input.type === "regular-file").map(({ target }) => relatedLocation("test-target", portableLocation(target.path))),
906
- ],
907
- {
908
- type: "package-script-target-reachability",
909
- probe: PACKAGE_PROBE,
910
- reachability,
911
- execution: "not_executed",
912
- conformance: "not_evaluated",
913
- command: commandEdge,
914
- tests: testEdges,
915
- },
916
- "package-probe",
917
- ));
918
-
919
- locators.sort((left, right) => compareText(left.id, right.id));
920
-
921
- return {
922
- reachability,
923
- locators,
924
- edges,
925
- command: {
926
- script: binding.command.script,
927
- target: binding.command.target,
928
- scriptLocation: commandScript?.location ?? null,
929
- edge: commandEdge,
930
- },
931
- tests: {
932
- script: binding.tests.script,
933
- targets: expectedTestTargets,
934
- scriptLocation: testScript?.location ?? null,
935
- edges: testEdges,
936
- },
937
- observations,
938
- findings,
939
- gaps,
940
- };
941
- }
942
-
943
- function externalObservation(binding, externalProbe, status, reportedOutcome, adapter, primaryLocation) {
944
- const code = "AUTH_EVIDENCE_EXTERNAL_PROBE_OBSERVATION";
945
- const logicalTarget = `${externalProbe.id}@${externalProbe.version}`;
946
- return {
947
- code,
948
- fingerprint: fingerprint([code, externalProbe.id, externalProbe.version, binding.id, binding.authority.unit, binding.authority.scope]),
949
- binding: binding.id,
950
- required: externalProbe.required,
951
- authority: binding.authority.unit,
952
- scope: binding.authority.scope,
953
- basis: "external_supplied",
954
- message: `external probe state for ${binding.id}: ${status}${reportedOutcome === null ? "" : `/${reportedOutcome}`}`,
955
- primaryLocation,
956
- relatedLocations: [relatedLocation("binding", binding.location)],
957
- witness: {
958
- type: "external-supplied-probe-result",
959
- probe: externalProbe.id,
960
- version: externalProbe.version,
961
- status,
962
- reportedOutcome,
963
- adapter,
964
- source: "external_supplied",
965
- packageAttestation: false,
966
- },
967
- logicalTarget,
968
- };
969
- }
970
-
971
- function externalGap(binding, externalProbe, code, status, reportedOutcome, adapter, primaryLocation) {
972
- const logicalTarget = `${externalProbe.id}@${externalProbe.version}`;
973
- return {
974
- code,
975
- fingerprint: fingerprint([code, externalProbe.id, externalProbe.version, binding.id, binding.authority.unit, binding.authority.scope]),
976
- binding: binding.id,
977
- required: true,
978
- authority: binding.authority.unit,
979
- scope: binding.authority.scope,
980
- basis: "required_external_evidence",
981
- message: `required external probe evidence for ${binding.id} is ${status}${reportedOutcome === null ? "" : `/${reportedOutcome}`}`,
982
- primaryLocation,
983
- relatedLocations: [relatedLocation("binding", binding.location)],
984
- witness: {
985
- type: "external-supplied-probe-result",
986
- probe: externalProbe.id,
987
- version: externalProbe.version,
988
- status,
989
- reportedOutcome,
990
- adapter,
991
- source: "external_supplied",
992
- packageAttestation: false,
993
- },
994
- logicalTarget,
995
- };
996
- }
997
-
998
- function evaluateExternalProbe(binding, result) {
999
- const externalProbe = binding.externalProbe;
1000
- if (externalProbe === null) return { record: null, observations: [], gaps: [] };
1001
- let status = "not_provided";
1002
- let reportedOutcome = null;
1003
- let adapter = null;
1004
- let primaryLocation = externalProbe.location;
1005
- if (result) {
1006
- adapter = result.adapter;
1007
- primaryLocation = result.location;
1008
- if (result.execution === "completed") {
1009
- status = "reported_completed";
1010
- reportedOutcome = result.outcome === "passed" ? "reported_passed" : "reported_failed";
1011
- } else if (result.execution === "failed") status = "reported_execution_failed";
1012
- else status = "reported_unsupported";
1013
- }
1014
- const record = {
1015
- id: externalProbe.id,
1016
- version: externalProbe.version,
1017
- required: externalProbe.required,
1018
- status,
1019
- reportedOutcome,
1020
- source: result ? "external_supplied" : "not_provided",
1021
- packageAttestation: false,
1022
- adapter,
1023
- };
1024
- const observation = externalObservation(binding, externalProbe, status, reportedOutcome, adapter, primaryLocation);
1025
- if (!externalProbe.required || (status === "reported_completed" && reportedOutcome === "reported_passed")) {
1026
- return { record, observations: [observation], gaps: [] };
1027
- }
1028
- const code = status === "not_provided"
1029
- ? "AUTH_EVIDENCE_EXTERNAL_PROBE_NOT_PROVIDED"
1030
- : status === "reported_execution_failed"
1031
- ? "AUTH_EVIDENCE_EXTERNAL_PROBE_EXECUTION_FAILED"
1032
- : status === "reported_unsupported"
1033
- ? "AUTH_EVIDENCE_EXTERNAL_PROBE_UNSUPPORTED"
1034
- : "AUTH_EVIDENCE_EXTERNAL_PROBE_REPORTED_FAILURE";
1035
- return {
1036
- record,
1037
- observations: [observation],
1038
- gaps: [externalGap(binding, externalProbe, code, status, reportedOutcome, adapter, primaryLocation)],
1039
- };
1040
- }
1041
-
1042
- function validateExternalResults(parsed, parsedBindings, identities, file) {
1043
- if (parsed === null) return { ok: true, byBinding: new Map() };
1044
- for (const [actual, expected, label] of [
1045
- [parsed.authorityContentIdentity, identities.authorityContentIdentity, "authority content identity"],
1046
- [parsed.repositoryInputIdentity, identities.repositoryInputIdentity, "repository input identity"],
1047
- [parsed.bindingIdentity, identities.bindingIdentity, "binding identity"],
1048
- ]) {
1049
- if (actual !== expected) return { ok: false, diagnostics: [resultDiagnostic(file, `external probe result ${label} does not match this exact captured input`)] };
1050
- }
1051
- const bindings = new Map(parsedBindings.bindings.map((binding) => [binding.id, binding]));
1052
- const byBinding = new Map();
1053
- for (const result of parsed.results) {
1054
- const binding = bindings.get(result.binding);
1055
- if (!binding || binding.externalProbe === null) return { ok: false, diagnostics: [resultDiagnostic(file, `external probe result does not match one configured external probe binding: ${result.binding}`, result.location)] };
1056
- if (result.probe !== binding.externalProbe.id || result.version !== binding.externalProbe.version) {
1057
- return { ok: false, diagnostics: [resultDiagnostic(file, `external probe ID or version does not match binding ${binding.id}`, result.location)] };
1058
- }
1059
- byBinding.set(binding.id, result);
1060
- }
1061
- return { ok: true, byBinding };
1062
- }
1063
-
1064
- function normalizeCompilerPath(file, root) {
1065
- const relative = portablePath(file, root);
1066
- if (path.isAbsolute(relative)) return path.basename(relative);
1067
- if (relative === ".nimi/spec" || relative.startsWith(".nimi/spec/")) return relative;
1068
- const rootPortable = root.split(path.sep).join(path.posix.sep);
1069
- if (rootPortable.endsWith("/.nimi/spec")) return path.posix.join(".nimi/spec", relative);
1070
- return relative;
1071
- }
1072
-
1073
- function normalizeCompilerDiagnostics(diagnostics, root) {
1074
- return diagnostics.map((diagnostic) => ({
1075
- ...diagnostic,
1076
- path: normalizeCompilerPath(diagnostic.path, root),
1077
- related: diagnostic.related.map((related) => ({ ...related, path: normalizeCompilerPath(related.path, root) })),
1078
- }));
1079
- }
1080
-
1081
- function corpusInputDiagnostic(error, root) {
1082
- const portableRoot = root.split(path.sep).join(path.posix.sep);
1083
- const reason = error.message
1084
- .split(root).join(".nimi/spec")
1085
- .split(portableRoot).join(".nimi/spec")
1086
- .split(path.sep).join(path.posix.sep);
1087
- return evidenceDiagnostic(
1088
- "AUTH_EVIDENCE_CORPUS_INVALID",
1089
- ".nimi/spec",
1090
- reason,
1091
- null,
1092
- "provide one complete canonical authority corpus; unsupported or partial inputs are refused",
1093
- );
1094
- }
1095
-
1096
- function manifestInputDiagnostic(binding, parsedManifest) {
1097
- return evidenceDiagnostic(
1098
- "AUTH_EVIDENCE_MANIFEST_INVALID",
1099
- binding.manifest,
1100
- `bound manifest is not an admitted input for ${PACKAGE_PROBE}: ${parsedManifest.reason}`,
1101
- parsedManifest.location,
1102
- "provide one valid UTF-8 JSON object with one uniquely addressable scripts object; unsupported script commands are reported separately as probe gaps",
1103
- );
1104
- }
1105
-
1106
- async function compileEvidenceAuthority(root) {
1107
- try {
1108
- const result = await compileAuthorityPath(root);
1109
- if (result.ok) return { result, diagnostics: [] };
1110
- return { result: null, diagnostics: normalizeCompilerDiagnostics(result.diagnostics, root) };
1111
- } catch (error) {
1112
- if (error instanceof AuthorityInputError) return { result: null, diagnostics: [corpusInputDiagnostic(error, root)] };
1113
- throw error;
1114
- }
1115
- }
1116
-
1117
- function validateBindingAuthority(binding, graph) {
1118
- const resolved = graph.byId.get(binding.authority.unit);
1119
- if (!resolved || resolved.unit.kind !== "rule" || resolved.unit.lifecycle !== "active") {
1120
- return bindingDiagnostic(
1121
- binding.authorityLocation.file,
1122
- `binding authority must resolve to one exact active rule: ${binding.authority.unit}`,
1123
- binding.authorityLocation,
1124
- );
1125
- }
1126
- if (!resolved.unit.semantic.scope.includes(binding.authority.scope)) {
1127
- return bindingDiagnostic(
1128
- binding.scopeLocation.file,
1129
- `binding scope must be an exact declared member of ${binding.authority.unit}: ${binding.authority.scope}`,
1130
- binding.scopeLocation,
1131
- );
1132
- }
1133
- return null;
1134
- }
1135
-
1136
- function authorityScopeLocation(binding, resolved, compiled, basePath) {
1137
- const scopeIndex = resolved.unit.semantic.scope.indexOf(binding.authority.scope);
1138
- const mapped = compiled.sourceMap.fields[`/units/${resolved.unitIndex}/semantic/scope/${scopeIndex}`];
1139
- if (!mapped) throw new Error(`admitted authority scope has no SourceMap location: ${binding.authority.unit}/${binding.authority.scope}`);
1140
- return {
1141
- file: portablePath(mapped.file, basePath),
1142
- range: mapped.range,
1143
- sourcePointer: mapped.sourcePointer,
1144
- };
1145
- }
1146
-
1147
- function proofCounts(parsedBindings) {
1148
- let locators = 0;
1149
- let edges = 0;
1150
- for (const binding of parsedBindings.bindings) {
1151
- const tests = binding.tests.targets.length;
1152
- locators += 5 + tests;
1153
- edges += 5 + tests;
1154
- }
1155
- return { locators, edges };
1156
- }
1157
-
1158
- function distinctBindingCount(parsedBindings) {
1159
- return new Set([
1160
- ...parsedBindings.required.map((entry) => entry.id),
1161
- ...parsedBindings.bindings.map((binding) => binding.id),
1162
- ]).size;
1163
- }
1164
-
1165
- function authorityBasePath(root) {
1166
- const portable = root.split(path.sep).join(path.posix.sep);
1167
- return portable.endsWith("/.nimi/spec") ? path.dirname(path.dirname(root)) : root;
1168
- }
1169
-
1170
- function canonicalEvidenceBytes(evidence) {
1171
- return Buffer.byteLength(JSON.stringify(evidence), "utf8");
1172
- }
1173
-
1174
- async function composeEvidence(snapshot, initialBindings, bindingPath, probeResultsPath, budgets) {
1175
- const inputByPath = new Map(snapshot.inputs.map((entry) => [entry.path, entry]));
1176
- const capturedBinding = inputByPath.get(bindingPath);
1177
- if (!capturedBinding || capturedBinding.role !== "binding" || capturedBinding.type !== "regular-file") throw new Error("evidence snapshot omitted the captured binding file");
1178
- const parsedBindings = await parseEvidenceBindings(capturedBinding.bytes, bindingPath);
1179
- if (!parsedBindings.ok) return refused(parsedBindings.diagnostics);
1180
- const initialPaths = locatorPaths(initialBindings);
1181
- const capturedPaths = locatorPaths(parsedBindings);
1182
- if (!sameStrings(initialPaths, capturedPaths)) {
1183
- throw new AuthorityReviewRefusal(
1184
- "AUTH_EVIDENCE_CAPTURE_CHANGED",
1185
- "evidence binding changed its declared locator universe while the repository snapshot was captured",
1186
- bindingPath,
1187
- );
1188
- }
1189
- const compiled = await compileEvidenceAuthority(snapshot.authority.root);
1190
- if (!compiled.result) return refused(compiled.diagnostics);
1191
- if (compiled.result.fileCount !== snapshot.authority.fileCount) throw new Error("captured authority file count does not match complete compiler admission");
1192
- const firstLocation = parsedBindings.bindings[0]?.location ?? parsedBindings.required[0]?.location ?? null;
1193
- if (compiled.result.unitCount > budgets.maxUnits) return refused([budgetDiagnostic("authority units", compiled.result.unitCount, budgets.maxUnits, firstLocation)]);
1194
- const bindingCount = distinctBindingCount(parsedBindings);
1195
- if (bindingCount > budgets.maxBindings) return refused([budgetDiagnostic("binding IDs", bindingCount, budgets.maxBindings, firstLocation)]);
1196
- const proof = proofCounts(parsedBindings);
1197
- if (proof.locators > budgets.maxLocators) return refused([budgetDiagnostic("logical evidence locators", proof.locators, budgets.maxLocators, firstLocation)]);
1198
- if (proof.edges > budgets.maxEdges) return refused([budgetDiagnostic("declared evidence edges", proof.edges, budgets.maxEdges, firstLocation)]);
1199
-
1200
- const authorityBase = authorityBasePath(snapshot.authority.root);
1201
- const graph = buildAuthorityGraphSnapshot(compiled.result, authorityBase, []);
1202
- for (const binding of parsedBindings.bindings) {
1203
- const diagnostic = validateBindingAuthority(binding, graph);
1204
- if (diagnostic) return refused([diagnostic]);
1205
- const manifestInput = inputState(inputByPath, binding.manifest);
1206
- if (manifestInput.type === "regular-file") {
1207
- const parsedManifest = parseManifest(manifestInput.bytes, binding.manifest);
1208
- if (!parsedManifest.ok) return refused([manifestInputDiagnostic(binding, parsedManifest)]);
1209
- }
1210
- }
1211
- const bindingIdentity = evidenceBindingIdentity(capturedBinding.bytes);
1212
- const locatorEntries = capturedPaths.map((file) => inputByPath.get(file));
1213
- if (locatorEntries.some((entry) => !entry || entry.role !== "locator")) throw new Error("evidence snapshot did not return the exact declared locator universe");
1214
- const repositoryInputIdentity = evidenceRepositoryInputIdentity(locatorEntries);
1215
- const identities = {
1216
- authorityContentIdentity: snapshot.authority.contentIdentity,
1217
- repositoryInputIdentity,
1218
- bindingIdentity,
1219
- };
1220
-
1221
- let parsedResults = null;
1222
- let resultContentIdentity = null;
1223
- if (probeResultsPath !== null) {
1224
- const capturedResults = inputByPath.get(probeResultsPath);
1225
- if (!capturedResults || capturedResults.role !== "probe-results" || capturedResults.type !== "regular-file") throw new Error("evidence snapshot omitted the supplied probe result file");
1226
- parsedResults = await parseEvidenceProbeResults(capturedResults.bytes, probeResultsPath);
1227
- if (!parsedResults.ok) return refused(parsedResults.diagnostics);
1228
- resultContentIdentity = evidenceProbeResultContentIdentity(capturedResults.bytes);
1229
- }
1230
- const validatedResults = validateExternalResults(parsedResults, parsedBindings, identities, probeResultsPath ?? bindingPath);
1231
- if (!validatedResults.ok) return refused(validatedResults.diagnostics);
1232
-
1233
- const requiredIds = new Set(parsedBindings.required.map((entry) => entry.id));
1234
- const configuredIds = new Set(parsedBindings.bindings.map((binding) => binding.id));
1235
- const observations = [];
1236
- const findings = [];
1237
- const gaps = parsedBindings.required.filter((entry) => !configuredIds.has(entry.id)).map(requiredBindingGap);
1238
- const bindingRecords = [];
1239
- for (const binding of parsedBindings.bindings) {
1240
- binding.required = requiredIds.has(binding.id);
1241
- const resolvedAuthority = graph.byId.get(binding.authority.unit);
1242
- const authorityNode = {
1243
- ...resolvedAuthority,
1244
- scopeLocation: authorityScopeLocation(binding, resolvedAuthority, compiled.result, authorityBase),
1245
- };
1246
- const evaluated = evaluatePackageProbe(binding, authorityNode, inputByPath);
1247
- observations.push(...evaluated.observations);
1248
- findings.push(...evaluated.findings);
1249
- gaps.push(...evaluated.gaps);
1250
- const external = evaluateExternalProbe(binding, validatedResults.byBinding.get(binding.id) ?? null);
1251
- observations.push(...external.observations);
1252
- gaps.push(...external.gaps);
1253
- bindingRecords.push({
1254
- id: binding.id,
1255
- required: binding.required,
1256
- authority: {
1257
- unit: binding.authority.unit,
1258
- scope: binding.authority.scope,
1259
- location: authorityNode.node.location,
1260
- scopeLocation: authorityNode.scopeLocation,
1261
- },
1262
- packageProbe: {
1263
- id: PACKAGE_PROBE,
1264
- version: "1",
1265
- execution: "package_computed",
1266
- reachability: evaluated.reachability,
1267
- conformance: "not_evaluated",
1268
- },
1269
- manifest: {
1270
- path: binding.manifest,
1271
- existence: inputState(inputByPath, binding.manifest).type === "regular-file" ? "present" : "missing",
1272
- },
1273
- command: evaluated.command,
1274
- tests: evaluated.tests,
1275
- locators: evaluated.locators,
1276
- edges: evaluated.edges,
1277
- externalProbe: external.record,
1278
- obligationKeys: {
1279
- consumer: { ruleId: binding.authority.unit, type: "consumer", target: binding.authority.scope },
1280
- test: { ruleId: binding.authority.unit, type: "test", target: binding.authority.unit },
1281
- },
1282
- });
1283
- }
1284
- const returnedProof = bindingRecords.reduce((counts, binding) => ({
1285
- locators: counts.locators + binding.locators.length,
1286
- edges: counts.edges + binding.edges.length,
1287
- }), { locators: 0, edges: 0 });
1288
- if (returnedProof.locators !== proof.locators || returnedProof.edges !== proof.edges) {
1289
- throw new Error("complete evidence graph counts do not match returned locator and edge records");
1290
- }
1291
- observations.sort(compareItem);
1292
- findings.sort(compareItem);
1293
- gaps.sort(compareItem);
1294
- const requiredFinding = findings.some((finding) => finding.required);
1295
- const requiredGap = gaps.some((gap) => gap.required);
1296
- const complete = !requiredGap;
1297
- const evidenceStatus = requiredFinding ? "unavailable" : requiredGap ? "indeterminate" : "available";
1298
- const presentLocatorFiles = locatorEntries.filter((entry) => entry.type === "regular-file").length;
1299
- const missingLocatorFiles = locatorEntries.length - presentLocatorFiles;
1300
- const evidence = {
1301
- format: EVIDENCE_FORMAT,
1302
- operationStatus: "completed",
1303
- evidenceStatus,
1304
- complete,
1305
- partial: false,
1306
- conformanceStatus: "not_evaluated",
1307
- identities: {
1308
- headCommitOid: snapshot.headOid,
1309
- authorityContentIdentity: identities.authorityContentIdentity,
1310
- repositoryInputIdentity: identities.repositoryInputIdentity,
1311
- bindingIdentity: identities.bindingIdentity,
1312
- externalResultContentIdentity: resultContentIdentity,
1313
- boundary: "complete_authority_and_binding_declared_repository_paths",
1314
- unboundRepositoryFilesInspected: false,
1315
- },
1316
- bindings: bindingRecords,
1317
- observations,
1318
- findings,
1319
- gaps,
1320
- counts: {
1321
- bindings: {
1322
- required: parsedBindings.required.length,
1323
- configured: parsedBindings.bindings.length,
1324
- evaluated: parsedBindings.bindings.length,
1325
- },
1326
- inputs: {
1327
- authorityFiles: snapshot.authority.fileCount,
1328
- locatorFilesPresent: presentLocatorFiles,
1329
- locatorFilesMissing: missingLocatorFiles,
1330
- capturedFiles: snapshot.inputs.filter((entry) => entry.type === "regular-file").length + snapshot.authority.fileCount,
1331
- capturedBytes: snapshot.capturedInputBytes,
1332
- authorityUnits: compiled.result.unitCount,
1333
- },
1334
- proof,
1335
- returned: {
1336
- observations: observations.length,
1337
- findings: findings.length,
1338
- gaps: gaps.length,
1339
- },
1340
- },
1341
- budgets,
1342
- };
1343
- const evidenceBytes = canonicalEvidenceBytes(evidence);
1344
- if (evidenceBytes > budgets.maxBytes) return refused([budgetDiagnostic("output UTF-8 bytes", evidenceBytes, budgets.maxBytes, firstLocation)], evidenceBytes);
1345
- return {
1346
- ok: true,
1347
- diagnostics: [],
1348
- fileCount: snapshot.authority.fileCount + snapshot.inputs.filter((entry) => entry.type === "regular-file").length,
1349
- unitCount: compiled.result.unitCount,
1350
- evidenceBytes,
1351
- evidence,
1352
- partial: false,
1353
- };
1354
- }
1355
-
1356
- function validatePublicPath(value, requiredPrefix, label) {
1357
- if (!validRepositoryPath(value) || !value.startsWith(requiredPrefix)) {
1358
- return evidenceDiagnostic(
1359
- "AUTH_EVIDENCE_INPUT_INVALID",
1360
- typeof value === "string" ? value : ".",
1361
- `${label} must be one safe repository-relative path under ${requiredPrefix}`,
1362
- null,
1363
- `place the ${label} under ${requiredPrefix} without path escape or option syntax`,
1364
- );
1365
- }
1366
- return null;
1367
- }
1368
-
1369
- async function captureInitialBinding(repositoryPath, bindingPath, maxInputBytes) {
1370
- const requested = path.resolve(process.cwd(), repositoryPath);
1371
- try {
1372
- const requestedInfo = await lstat(requested, { bigint: true });
1373
- if (requestedInfo.isSymbolicLink() || !requestedInfo.isDirectory()) throw new AuthorityReviewRefusal("AUTH_EVIDENCE_REPOSITORY_INVALID", "repository path must be one regular non-symlink directory", ".");
1374
- const repository = await realpath(requested);
1375
- let absolute = repository;
1376
- const parts = bindingPath.split("/");
1377
- for (let index = 0; index < parts.length; index += 1) {
1378
- absolute = path.join(absolute, parts[index]);
1379
- const info = await lstat(absolute, { bigint: true });
1380
- if (info.isSymbolicLink() || (index < parts.length - 1 ? !info.isDirectory() : !info.isFile())) {
1381
- throw new AuthorityReviewRefusal("AUTH_EVIDENCE_BINDING_INVALID", "evidence binding path and ancestors must be regular non-symlink entries", bindingPath);
1382
- }
1383
- }
1384
- const info = await lstat(absolute, { bigint: true });
1385
- if (info.size > BigInt(maxInputBytes)) throw new AuthorityReviewRefusal("AUTH_EVIDENCE_BUDGET", `evidence binding alone requires ${info.size} input bytes but max-input-bytes is ${maxInputBytes}`, bindingPath);
1386
- return await captureStableRegularFile(absolute, bindingPath, repository, maxInputBytes);
1387
- } catch (error) {
1388
- if (error instanceof AuthorityReviewRefusal) throw error;
1389
- throw new AuthorityReviewRefusal("AUTH_EVIDENCE_BINDING_INVALID", `evidence binding is not safely readable: ${error.message}`, bindingPath);
1390
- }
1391
- }
1392
-
1393
- export async function evidenceAuthorityRepository(repositoryPath, bindingPath, probeResultsPath, budgets, options = {}) {
1394
- if (![budgets?.maxUnits, budgets?.maxBindings, budgets?.maxLocators, budgets?.maxEdges, budgets?.maxInputBytes, budgets?.maxBytes].every(validBudget)) {
1395
- return refused([budgetDiagnostic("positive safe-integer budget values", "all", "invalid")]);
1396
- }
1397
- const bindingPathDiagnostic = validatePublicPath(bindingPath, ".nimi/config/", "binding");
1398
- if (bindingPathDiagnostic) return refused([bindingPathDiagnostic]);
1399
- if (probeResultsPath !== null) {
1400
- const resultPathDiagnostic = validatePublicPath(probeResultsPath, ".nimi/local/", "probe result");
1401
- if (resultPathDiagnostic) return refused([resultPathDiagnostic]);
1402
- if (probeResultsPath === bindingPath) return refused([resultDiagnostic(probeResultsPath, "probe result path must be distinct from the tracked binding path")]);
1403
- }
1404
- try {
1405
- const initialBytes = await captureInitialBinding(repositoryPath, bindingPath, budgets.maxInputBytes);
1406
- const initialBindings = await parseEvidenceBindings(initialBytes, bindingPath);
1407
- if (!initialBindings.ok) return refused(initialBindings.diagnostics);
1408
- const paths = locatorPaths(initialBindings);
1409
- if (paths.includes(bindingPath) || (probeResultsPath !== null && paths.includes(probeResultsPath))) {
1410
- return refused([bindingDiagnostic(bindingPath, "binding, supplied-result, and locator paths must be distinct")]);
1411
- }
1412
- return await withGitEvidenceSnapshot({
1413
- repositoryPath,
1414
- bindingPath,
1415
- probeResultsPath,
1416
- locatorPaths: paths,
1417
- maxInputBytes: budgets.maxInputBytes,
1418
- hooks: options.snapshotHooks ?? null,
1419
- }, (snapshot) => composeEvidence(snapshot, initialBindings, bindingPath, probeResultsPath, budgets));
1420
- } catch (error) {
1421
- if (error instanceof AuthorityReviewRefusal) return refused([snapshotDiagnostic(error)]);
1422
- throw error;
1423
- }
1424
- }
1425
-
1426
- export {
1427
- BINDING_FORMAT,
1428
- EVIDENCE_FORMAT,
1429
- PACKAGE_PROBE,
1430
- RESULT_FORMAT,
1431
- canonicalEvidenceBytes,
1432
- };