@codyswann/lisa 4.111.0 → 4.111.2

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 (105) hide show
  1. package/all/copy-overwrite/scripts/lib/completion-proof-content.mjs +2 -2
  2. package/all/copy-overwrite/scripts/lib/completion-proof-github.mjs +242 -62
  3. package/all/copy-overwrite/scripts/lib/completion-proof-projection.mjs +2 -2
  4. package/all/copy-overwrite/scripts/lib/completion-proof-publisher.mjs +195 -82
  5. package/all/copy-overwrite/scripts/lib/evidence-release-capacity.mjs +20 -29
  6. package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +1 -0
  7. package/all/copy-overwrite/scripts/lib/usage-artifact-ref.d.mts +8 -0
  8. package/all/copy-overwrite/scripts/lib/usage-artifact-ref.mjs +77 -0
  9. package/all/copy-overwrite/scripts/lib/usage-ledger-integrity.d.mts +3 -0
  10. package/all/copy-overwrite/scripts/lib/usage-ledger-integrity.mjs +63 -0
  11. package/all/copy-overwrite/scripts/lib/usage-ledger.d.mts +1 -0
  12. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +14 -7
  13. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  14. package/dist/core/lisa-owned-hash-ledger.js +66 -0
  15. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  16. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  17. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  18. package/dist/core/upstream-evidence-manifest.js +28 -14
  19. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  20. package/dist/utils/usage-accounting.d.ts +1 -1
  21. package/dist/utils/usage-accounting.d.ts.map +1 -1
  22. package/dist/utils/usage-accounting.js +1 -1
  23. package/dist/utils/usage-accounting.js.map +1 -1
  24. package/package.json +4 -4
  25. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  26. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  27. package/plugins/lisa/rules/reference/usage-accounting.md +9 -1
  28. package/plugins/lisa-agy/plugin.json +1 -1
  29. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  30. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  31. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  32. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  33. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  34. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  35. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  36. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa-copilot/rules/reference/usage-accounting.md +9 -1
  38. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  39. package/plugins/lisa-cursor/rules/usage-accounting-reference.mdc +9 -1
  40. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  42. package/plugins/lisa-devin/rules/reference/usage-accounting.md +9 -1
  43. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  44. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  45. package/plugins/lisa-expo-agy/plugin.json +1 -1
  46. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  49. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  50. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  52. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  53. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  57. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  59. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  60. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  64. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  66. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  67. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  69. package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
  70. package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
  71. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  72. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  73. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  74. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  76. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  77. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  78. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  79. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  80. package/plugins/lisa-rails-agy/plugin.json +1 -1
  81. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  83. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  84. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  85. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  86. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  87. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  88. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  89. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  90. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  91. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  92. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  93. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  94. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  95. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  96. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  97. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  98. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  99. package/plugins/src/base/rules/reference/usage-accounting.md +9 -1
  100. package/scripts/two-channel-couplings.json +1 -1
  101. package/typescript/copy-overwrite/.prettierignore +1 -0
  102. package/dist/utils/usage-artifact-ref.d.ts +0 -30
  103. package/dist/utils/usage-artifact-ref.d.ts.map +0 -1
  104. package/dist/utils/usage-artifact-ref.js +0 -55
  105. package/dist/utils/usage-artifact-ref.js.map +0 -1
@@ -12,7 +12,7 @@ import {
12
12
  section,
13
13
  } from "./completion-proof-shape.mjs";
14
14
  import { parseLisaUsageSection } from "./usage-ledger.mjs";
15
- import { verifyLisaUsageSectionIntegrity } from "./usage-ledger-integrity.mjs";
15
+ import { isLisaUsageLedgerIntact } from "./usage-ledger-integrity.mjs";
16
16
 
17
17
  /** Find captured structured records without evaluating their contents. */
18
18
  function records(value, depth = 0, budget = { remaining: 100000 }) {
@@ -433,7 +433,7 @@ export function validateVerifyUsage(documents, ref, expectedIds, context) {
433
433
  continue;
434
434
  }
435
435
  if (!parsed.range) continue;
436
- if (!verifyLisaUsageSectionIntegrity(canonical).ok) {
436
+ if (!isLisaUsageLedgerIntact(canonical)) {
437
437
  requireProof(
438
438
  index > 0,
439
439
  "The work-item body's canonical usage ledger failed its stored-surface integrity check."
@@ -216,6 +216,19 @@ const ESCAPE_FLAG = "--allow-escape-sequences";
216
216
  /** How gh < 2.97, which has no escape check, rejects that flag. */
217
217
  const UNKNOWN_ESCAPE_FLAG = /unknown flag:? --allow-escape-sequences/;
218
218
  const OCTET_STREAM = "Accept: application/octet-stream";
219
+ /**
220
+ * Backoff before each retry of a transient read: three retries, four attempts
221
+ * in all (CodySwannGT/lisa#4733). A publish makes about a hundred reads, and a
222
+ * replay of one caller repo's read set lost roughly 1% of them at random.
223
+ */
224
+ const READ_RETRY_DELAYS_MS = Object.freeze([250, 1000, 3000]);
225
+ /**
226
+ * Diagnostics of a network fault that a later identical read can outlive: a
227
+ * connect or dial timeout, a TLS handshake timeout, a reset connection, a cut
228
+ * stream, an i/o timeout, or GitHub's own 500/502/503/504.
229
+ */
230
+ const TRANSIENT_STDERR =
231
+ /(?:connect|dial)[^\n]*(?:timed out|timeout)|TLS handshake timeout|connection reset|ECONNRESET|unexpected EOF|i\/o timeout|HTTP 50[0234]\b/i;
219
232
  /** The longest stderr excerpt a read failure quotes. */
220
233
  const STDERR_EXCERPT = 200;
221
234
  const ESC = 0x1b;
@@ -321,6 +334,91 @@ function readFailure(result, maxBuffer) {
321
334
  return null;
322
335
  }
323
336
 
337
+ /**
338
+ * Whether a failed `gh` run may succeed if repeated unchanged. A spawn timeout
339
+ * and the network faults above are; a 4xx, a byte ceiling, a missing gh or an
340
+ * unknown flag would fail the same way again, so they are reported at once.
341
+ * @param {object} result - The canonical runner's spawn result.
342
+ * @returns {boolean} True when the read is worth repeating.
343
+ */
344
+ function transientRun(result) {
345
+ if (result.error) return result.error.code === "ETIMEDOUT";
346
+ return result.status !== 0 && TRANSIENT_STDERR.test(result.stderr ?? "");
347
+ }
348
+
349
+ /** `gh api` flags that send a request body, which makes the call a write. */
350
+ const BODY_FLAGS = new Set(["-f", "-F", "--field", "--raw-field", "--input"]);
351
+ /** `gh api` flags that pick the HTTP method. */
352
+ const METHOD_FLAGS = new Set(["-X", "--method"]);
353
+
354
+ /**
355
+ * The HTTP method one `gh api` argument names, or null when it names none:
356
+ * `-X POST`, `--method POST`, `--method=POST` and `-XPOST` all count.
357
+ * @param {string[]} args - Exact `gh` argument vector.
358
+ * @param {number} index - Position of the argument to read.
359
+ * @returns {string|null} The upper-cased method, or null.
360
+ */
361
+ function methodAt(args, index) {
362
+ const value = args[index];
363
+ if (METHOD_FLAGS.has(value)) return String(args[index + 1]).toUpperCase();
364
+ const joined = /^(?:--method=|-X)(.+)$/.exec(value);
365
+ return joined ? joined[1].toUpperCase() : null;
366
+ }
367
+
368
+ /**
369
+ * Whether a `gh` call can change GitHub state. Such a call is never repeated:
370
+ * a write that timed out may still have landed, and a retry would apply it
371
+ * twice (CodySwannGT/lisa#4733).
372
+ * @param {string[]} args - Exact `gh` argument vector.
373
+ * @returns {boolean} True for any body flag or a non-GET method.
374
+ */
375
+ function writes(args) {
376
+ return args.some((value, index) => {
377
+ if (BODY_FLAGS.has(value) || /^--(?:raw-)?field=|^--input=/.test(value))
378
+ return true;
379
+ const method = methodAt(args, index);
380
+ return method !== null && method !== "GET";
381
+ });
382
+ }
383
+
384
+ /**
385
+ * Block the thread for a retry backoff. The transport is synchronous end to
386
+ * end (its runner is spawnSync-based), so the wait is too.
387
+ * @param {number} ms - Milliseconds to wait.
388
+ */
389
+ function sleepSync(ms) {
390
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
391
+ }
392
+
393
+ /** How many attempts a read took, when it took more than one. */
394
+ function attemptsNote(attempts) {
395
+ return attempts > 1 ? `; after ${attempts} attempts` : "";
396
+ }
397
+
398
+ /** The refusal for a read that did not complete. */
399
+ function incompleteRead(detail) {
400
+ return new CompletionProofError(
401
+ READ_ERROR,
402
+ `A required GitHub completion-proof read did not complete (${detail}); restore repository access and retry canonical Verify/evidence.`
403
+ );
404
+ }
405
+
406
+ /** The refusal for a read whose body never parsed. */
407
+ function unparseableRead(detail) {
408
+ return new CompletionProofError(
409
+ READ_ERROR,
410
+ `A required GitHub proof response is not complete JSON (${detail}).`
411
+ );
412
+ }
413
+
414
+ /** The refusal for an asset whose download never matched its metadata. */
415
+ function incompleteDownload(detail) {
416
+ return new CompletionProofError(
417
+ "invalid-proof",
418
+ `The proof attachment download is incomplete (${detail}).`
419
+ );
420
+ }
421
+
324
422
  /**
325
423
  * Which read an endpoint is, for the operator.
326
424
  * @param {string} target - Repository-relative endpoint ("" for the repository).
@@ -365,8 +463,21 @@ function describeRead({ kind, args, root, failure, stderr }) {
365
463
  /** `/<owner>/<repo>/releases/download/<tag>/<asset>`, and nothing nested. */
366
464
  const DOWNLOAD_PATH = /^\/([^/]+\/[^/]+)\/releases\/download\/([^/]+)\/[^/]+$/;
367
465
 
368
- /** The transport reuses the canonical CLI's deadline and failure boundary. */
369
- export function githubProofTransport(run, repository, policy = {}) {
466
+ /**
467
+ * The transport reuses the canonical CLI's deadline and failure boundary.
468
+ * @param {Function} run - The canonical spawnSync-based runner.
469
+ * @param {string} repository - `<owner>/<repo>` every read is confined to.
470
+ * @param {object} [policy] - `verification.completion` from the Lisa config.
471
+ * @param {object} [retry] - Read retry pacing; tests replace the wait.
472
+ * @param {readonly number[]} [retry.delays] - Backoff before each retry.
473
+ * @param {Function} [retry.sleep] - Synchronous wait, given milliseconds.
474
+ */
475
+ export function githubProofTransport(
476
+ run,
477
+ repository,
478
+ policy = {},
479
+ { delays = READ_RETRY_DELAYS_MS, sleep = sleepSync } = {}
480
+ ) {
370
481
  requireProof(
371
482
  /^[\w.-]+\/[\w.-]+$/.test(repository),
372
483
  "The implementation repository is not canonical."
@@ -376,8 +487,9 @@ export function githubProofTransport(run, repository, policy = {}) {
376
487
  * Run one bounded `gh` read and report, rather than throw, how it ended.
377
488
  * @param {string[]} args - Exact `gh` argument vector.
378
489
  * @param {object} [options] - Runner options plus an optional `kind`.
379
- * @returns {{result: object, failure: string|null}} The run and, when it
380
- * failed, a description naming the read.
490
+ * @returns {object} The run, its bytes as `value` and, when it failed, a
491
+ * `failure` naming the read, whether it is `transient`, and how to
492
+ * `refuse` it.
381
493
  */
382
494
  function attempt(args, options = {}) {
383
495
  const { kind, ...runOptions } = options;
@@ -390,19 +502,60 @@ export function githubProofTransport(run, repository, policy = {}) {
390
502
  const failure = readFailure(result, maxBuffer);
391
503
  return {
392
504
  result,
505
+ value: result.stdout,
393
506
  failure:
394
507
  failure &&
395
508
  describeRead({ kind, args, root, failure, stderr: result.stderr }),
509
+ transient: failure !== null && transientRun(result),
510
+ refuse: incompleteRead,
396
511
  };
397
512
  }
398
- /** The bytes of a completed read; a failed one names itself (#4773). */
399
- function settle({ result, failure }) {
400
- if (failure)
401
- throw new CompletionProofError(
402
- READ_ERROR,
403
- `A required GitHub completion-proof read did not complete (${failure}); restore repository access and retry canonical Verify/evidence.`
404
- );
405
- return result.stdout;
513
+ /**
514
+ * Repeat a whole read unit while it fails transiently, within the bound.
515
+ * A unit is the read plus whatever proves it whole (a parse, a size check),
516
+ * so a truncated body is retried exactly like a dropped connection.
517
+ * @param {Function} unit - One read attempt, returning an attempt outcome.
518
+ * @returns {object} The final outcome, with how many attempts it took.
519
+ */
520
+ function retried(unit) {
521
+ let outcome = unit();
522
+ let attempts = 1;
523
+ while (outcome.failure && outcome.transient && attempts <= delays.length) {
524
+ sleep(delays[attempts - 1]);
525
+ outcome = unit();
526
+ attempts += 1;
527
+ }
528
+ return { ...outcome, attempts };
529
+ }
530
+ /** The failure detail of an outcome, with its attempt count. */
531
+ function detail(outcome) {
532
+ return `${outcome.failure}${attemptsNote(outcome.attempts)}`;
533
+ }
534
+ /** The value of a completed read; a failed one names itself (#4773). */
535
+ function settle(outcome) {
536
+ if (outcome.failure) throw outcome.refuse(detail(outcome));
537
+ return outcome.value;
538
+ }
539
+ /**
540
+ * One read whose body must be complete JSON. A body that does not parse is
541
+ * transient, since a cut stream is how that usually happens.
542
+ * @param {string[]} args - Exact `gh` argument vector.
543
+ * @returns {object} One attempt outcome holding the parsed body.
544
+ */
545
+ function parsedAttempt(args) {
546
+ const read = attempt(args);
547
+ if (read.failure) return read;
548
+ try {
549
+ return { ...read, value: JSON.parse(read.value) };
550
+ } catch {
551
+ return {
552
+ ...read,
553
+ failure: describeRead({ args, root, failure: "unparseable response" }),
554
+ transient: true,
555
+ unparseable: true,
556
+ refuse: unparseableRead,
557
+ };
558
+ }
406
559
  }
407
560
  /**
408
561
  * One bounded `gh` read.
@@ -412,7 +565,8 @@ export function githubProofTransport(run, repository, policy = {}) {
412
565
  * @returns {string|Buffer} The complete response.
413
566
  */
414
567
  function call(args, options = {}) {
415
- return settle(attempt(args, options));
568
+ if (writes(args)) return settle({ ...attempt(args, options), attempts: 1 });
569
+ return settle(retried(() => attempt(args, options)));
416
570
  }
417
571
  // gh >= 2.97 needs the flag and gh < 2.97 rejects it. Assumed supported
418
572
  // until gh rejects it once; remembered for this transport's later downloads.
@@ -424,12 +578,13 @@ export function githubProofTransport(run, repository, policy = {}) {
424
578
  * without `--allow-escape-sequences`, so an ANSI-coloured test log failed
425
579
  * every terminal transition on CI's gh while an older local gh, which
426
580
  * rejects the flag, read it fine (CodySwannGT/lisa#4773). The bytes go to a
427
- * Buffer and are hashed, never to a terminal, so allowing them is safe.
581
+ * Buffer and are hashed, never to a terminal, so allowing them is safe. A
582
+ * rejected flag is a probe, not an attempt, so it never counts as one.
428
583
  * @param {number} id - Native asset identifier.
429
584
  * @param {number} max - Byte ceiling for this attachment.
430
- * @returns {Buffer} The raw asset bytes.
585
+ * @returns {object} One attempt outcome holding the raw bytes.
431
586
  */
432
- function downloadAsset(id, max) {
587
+ function downloadAttempt(id, max) {
433
588
  const args = [
434
589
  "api",
435
590
  `${root}/releases/assets/${id}`,
@@ -442,35 +597,73 @@ export function githubProofTransport(run, repository, policy = {}) {
442
597
  const rejected =
443
598
  flagged.result.status !== 0 &&
444
599
  UNKNOWN_ESCAPE_FLAG.test(flagged.result.stderr ?? "");
445
- if (!rejected) return settle(flagged);
600
+ if (!rejected) return flagged;
446
601
  escapeFlagSupported = false;
447
602
  }
448
- return call(args, options);
603
+ return attempt(args, options);
604
+ }
605
+ /**
606
+ * One download checked against its metadata: a body of any other length
607
+ * is a cut transfer, so it is transient like a dropped connection.
608
+ * @param {number} id - Native asset identifier.
609
+ * @param {number} max - Byte ceiling for this attachment.
610
+ * @param {number} size - The byte size native metadata declares.
611
+ * @returns {object} One attempt outcome holding the raw bytes.
612
+ */
613
+ function wholeDownload(id, max, size) {
614
+ const read = downloadAttempt(id, max);
615
+ if (read.failure) return read;
616
+ if (Buffer.isBuffer(read.value) && read.value.length === size) return read;
617
+ return {
618
+ ...read,
619
+ failure: `asset-download releases/assets/${id}: ${Buffer.byteLength(read.value ?? "")} of ${size} bytes`,
620
+ transient: true,
621
+ refuse: incompleteDownload,
622
+ };
449
623
  }
450
624
  function json(path, paginated = false) {
451
625
  requireProof(
452
626
  path.startsWith(`${root}/`) || path === root,
453
627
  "A completion read selected another repository."
454
628
  );
455
- const bytes = call(
456
- paginated ? ["api", "--paginate", "--slurp", path] : ["api", path]
457
- );
458
- try {
459
- const parsed = JSON.parse(bytes);
460
- if (paginated) {
461
- requireProof(
462
- Array.isArray(parsed) && parsed.length <= 100,
463
- "The required GitHub pagination is incomplete or exceeds its bound."
464
- );
465
- }
466
- return parsed;
467
- } catch (error) {
468
- if (error instanceof CompletionProofError) throw error;
469
- throw new CompletionProofError(
470
- READ_ERROR,
471
- `A required GitHub proof response is not complete JSON (${describeRead({ args: ["api", path], root, failure: "unparseable response" })}).`
629
+ const args = paginated
630
+ ? ["api", "--paginate", "--slurp", path]
631
+ : ["api", path];
632
+ const parsed = settle(retried(() => parsedAttempt(args)));
633
+ if (paginated)
634
+ requireProof(
635
+ Array.isArray(parsed) && parsed.length <= 100,
636
+ "The required GitHub pagination is incomplete or exceeds its bound."
472
637
  );
473
- }
638
+ return parsed;
639
+ }
640
+ /**
641
+ * A JSON read GitHub may answer with an explicit 404. Only that 404 is an
642
+ * answer; every other failure is retried when transient and then refused.
643
+ * @param {string} path - Repository-confined endpoint.
644
+ * @returns {object} The final outcome; `absent` is true for the 404.
645
+ */
646
+ function optionalRead(path) {
647
+ requireProof(
648
+ path.startsWith(`${root}/`),
649
+ "A completion read selected another repository."
650
+ );
651
+ const read = retried(() => parsedAttempt(["api", path]));
652
+ const absent =
653
+ Boolean(read.failure) &&
654
+ !read.unparseable &&
655
+ read.result.status !== 0 &&
656
+ /HTTP 404/.test(read.result.stderr ?? "");
657
+ return { ...read, absent };
658
+ }
659
+ /**
660
+ * Read JSON that may not exist, such as a release looked up by tag.
661
+ * @param {string} path - Repository-confined endpoint.
662
+ * @returns {object|null} The parsed body, or null for GitHub's explicit 404.
663
+ */
664
+ function optionalJson(path) {
665
+ const read = optionalRead(path);
666
+ return read.absent ? null : settle(read);
474
667
  }
475
668
  function trustedPublisher(
476
669
  asset,
@@ -562,31 +755,21 @@ export function githubProofTransport(run, repository, policy = {}) {
562
755
  row.type === "Bot" &&
563
756
  row.repository_id === repositoryId
564
757
  );
565
- const read = attempt([
566
- "api",
567
- `${root}/collaborators/${encodeURIComponent(user.login)}/permission`,
568
- ]);
569
- const { result } = read;
570
- if (read.failure) {
571
- if (result.status !== 0 && /HTTP 404/.test(result.stderr ?? ""))
572
- return false;
573
- throw new CompletionProofError(
574
- READ_ERROR,
575
- `The native proof publisher's repository authority could not be read (${read.failure}).`
576
- );
577
- }
578
- let permission;
579
- try {
580
- permission = JSON.parse(result.stdout);
581
- } catch {
758
+ const read = optionalRead(
759
+ `${root}/collaborators/${encodeURIComponent(user.login)}/permission`
760
+ );
761
+ if (read.absent) return false;
762
+ if (read.failure)
582
763
  throw new CompletionProofError(
583
764
  READ_ERROR,
584
- "Native publisher permissions are unreadable."
765
+ read.unparseable
766
+ ? `Native publisher permissions are unreadable (${detail(read)}).`
767
+ : `The native proof publisher's repository authority could not be read (${detail(read)}).`
585
768
  );
586
- }
769
+ const permission = read.value;
587
770
  return (
588
- permission.user?.id === user.id &&
589
- ["write", "maintain", "admin"].includes(permission.permission)
771
+ permission?.user?.id === user.id &&
772
+ ["write", "maintain", "admin"].includes(permission?.permission)
590
773
  );
591
774
  }
592
775
  function asset(id, max = MAX_ATTACHMENT_BYTES) {
@@ -622,16 +805,13 @@ export function githubProofTransport(run, repository, policy = {}) {
622
805
  isAcceptedEvidenceRelease(policy, download[2]),
623
806
  `The proof attachment is outside the implementation repository's accepted evidence releases (${acceptedEvidenceReleases(policy).join(", ")}).`
624
807
  );
625
- const bytes = downloadAsset(id, max);
626
- requireProof(
627
- Buffer.isBuffer(bytes) && bytes.length === metadata.size,
628
- "The proof attachment download is incomplete."
629
- );
808
+ const bytes = settle(retried(() => wholeDownload(id, max, metadata.size)));
630
809
  return { metadata, bytes };
631
810
  }
632
811
  return {
633
812
  call,
634
813
  json,
814
+ optionalJson,
635
815
  asset,
636
816
  trustedPublisher,
637
817
  eligibleCommentAuthor,
@@ -3,7 +3,7 @@
3
3
 
4
4
  /** Exclude only actual canonical accounting; retain unknown requirement text. */
5
5
  import { parseLisaUsageSection } from "./usage-ledger.mjs";
6
- import { verifyLisaUsageSectionIntegrity } from "./usage-ledger-integrity.mjs";
6
+ import { isLisaUsageLedgerIntact } from "./usage-ledger-integrity.mjs";
7
7
  import { requireProof } from "./completion-proof-errors.mjs";
8
8
 
9
9
  /** Stable presentation matching; this does not parse or authorize usage data. */
@@ -105,7 +105,7 @@ export function usageSpecRemainder(document) {
105
105
  try {
106
106
  parsed = parseLisaUsageSection(document);
107
107
  requireProof(
108
- verifyLisaUsageSectionIntegrity(document).ok,
108
+ isLisaUsageLedgerIntact(document),
109
109
  "The canonical usage section is not an intact stored ledger."
110
110
  );
111
111
  } catch {