@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
@@ -36,6 +36,73 @@ const WRITE_ERROR = "write-error";
36
36
 
37
37
  export { ensureEvidenceRelease };
38
38
 
39
+ /** The exact bytes a record is published as; one serializer, everywhere. */
40
+ function recordBytes(record) {
41
+ return Buffer.from(`${JSON.stringify(record, null, 2)}\n`);
42
+ }
43
+
44
+ /**
45
+ * This record, stamped with a stored asset's `captured_at`, when that makes
46
+ * it byte-identical to the stored bytes and a well-formed record; else null.
47
+ * @param {object} record - The record this publish built.
48
+ * @param {Buffer} stored - A candidate asset's bytes.
49
+ * @returns {{record: object, bytes: Buffer}|null} The adoptable record.
50
+ */
51
+ function identicalRecord(record, stored) {
52
+ let adopted;
53
+ try {
54
+ adopted = { ...record, captured_at: JSON.parse(stored).captured_at };
55
+ // A missing or malformed captured_at is not a record this publisher
56
+ // could have written; never adopt it.
57
+ validateRecordShape(adopted);
58
+ } catch {
59
+ return null;
60
+ }
61
+ const bytes = recordBytes(adopted);
62
+ return bytes.equals(stored) ? { record: adopted, bytes } : null;
63
+ }
64
+
65
+ /**
66
+ * The record this publish would upload, if an earlier run already uploaded it.
67
+ *
68
+ * A run that dies after `gh release upload` but before posting its locator
69
+ * leaves the record in the release with nothing pointing at it. The re-run
70
+ * computes the same revision, but its fresh `captured_at` gives it a different
71
+ * digest and so a different asset name, and it used to upload a second copy
72
+ * (CodySwannGT/lisa#4733). Each same-revision asset this publisher uploaded is
73
+ * read back; if this record, stamped with that asset's `captured_at`, has the
74
+ * exact same bytes, that asset is adopted.
75
+ *
76
+ * Every release the capacity check opened is searched, not only the one the
77
+ * upload would go to: the stranded upload may itself have filled a release
78
+ * and pushed this run on to its overflow release (CodySwannGT/lisa#4838). A
79
+ * candidate read that fails (after the transport's retries) refuses, rather
80
+ * than uploading a duplicate. The caller's readback and trust checks still
81
+ * run on the adopted asset, in the release that holds it.
82
+ * @param {object} transport - The bounded GitHub proof transport.
83
+ * @param {object[]} releases - Opened releases, each with its `assets`.
84
+ * @param {object} record - The record this publish built.
85
+ * @param {number} publisher - The native publisher identity.
86
+ * @returns {{record: object, bytes: Buffer, evidence: object}|null} The
87
+ * adopted record and the release holding it, or null.
88
+ */
89
+ function strandedRecord(transport, releases, record, publisher) {
90
+ const prefix = `${record.record_id}-r${record.revision}-`;
91
+ for (const evidence of releases) {
92
+ for (const candidate of evidence.assets ?? []) {
93
+ if (
94
+ !candidate.name?.startsWith(prefix) ||
95
+ candidate.uploader?.id !== publisher
96
+ )
97
+ continue;
98
+ const stored = transport.asset(candidate.id, MAX_RECORD_BYTES).bytes;
99
+ const adopted = identicalRecord(record, stored);
100
+ if (adopted) return { ...adopted, evidence };
101
+ }
102
+ }
103
+ return null;
104
+ }
105
+
39
106
  /** Upload one file to a release; the failure's diagnostics, or null on success. */
40
107
  function attemptUpload(context, transport, evidence, file) {
41
108
  const uploaded = context.run(
@@ -51,24 +118,24 @@ function attemptUpload(context, transport, evidence, file) {
51
118
  }
52
119
 
53
120
  /**
54
- * Upload the record to the target release, rolling over once to the next
121
+ * Upload the record to the checked release, rolling over once to the next
55
122
  * overflow release when GitHub reports the release full mid-upload (another
56
123
  * publisher filled it after the capacity check). A pinned release is refused
57
124
  * instead, as it is before the upload (CodySwannGT/lisa#4838).
125
+ * @param {object} context - The canonical publish context.
126
+ * @param {object} transport - The bounded GitHub proof transport.
127
+ * @param {{tag: string, pinned: boolean}} target - The resolved release.
128
+ * @param {object} checked - The release the capacity check chose.
129
+ * @param {string} file - The record file to upload.
58
130
  * @returns {object} The release the record now lives in.
59
131
  */
60
- function uploadProof(context, transport, target, file) {
61
- const options = { tag: target.tag, pinned: target.pinned };
62
- let evidence = ensureEvidenceRelease(
63
- context.run,
64
- transport,
65
- context.policy,
66
- options
67
- );
132
+ function uploadProof(context, transport, target, checked, file) {
133
+ let evidence = checked;
68
134
  let failure = attemptUpload(context, transport, evidence, file);
69
135
  if (failure && failure.full !== false && !target.pinned) {
70
136
  evidence = ensureEvidenceRelease(context.run, transport, context.policy, {
71
- ...options,
137
+ tag: target.tag,
138
+ pinned: target.pinned,
72
139
  from: evidence.index + 1,
73
140
  });
74
141
  failure = attemptUpload(context, transport, evidence, file);
@@ -88,6 +155,23 @@ function uploadProof(context, transport, target, file) {
88
155
  );
89
156
  }
90
157
 
158
+ /**
159
+ * Write the record's bytes to a temporary file named for its asset and upload
160
+ * it; the temporary file is always removed.
161
+ * @returns {object} The release the record now lives in.
162
+ */
163
+ function uploadRecord(context, transport, target, checked, name, bytes) {
164
+ const temporary = mkdtempSync(join(tmpdir(), "lisa-completion-proof-"));
165
+ try {
166
+ mkdirSync(temporary, { recursive: true });
167
+ const file = join(temporary, name);
168
+ writeFileSync(file, bytes);
169
+ return uploadProof(context, transport, target, checked, file);
170
+ } finally {
171
+ rmSync(temporary, { recursive: true, force: true });
172
+ }
173
+ }
174
+
91
175
  /** Recover the monotonic native index without treating old malformed proof as valid. */
92
176
  function previousLocator(
93
177
  context,
@@ -211,80 +295,109 @@ export function publishCompletionProof(context, input) {
211
295
  validateRecordShape(record);
212
296
  if (record.state === "accepted-for-completion")
213
297
  evaluateAcceptedRecord({ record }, context, subject, transport);
214
- const bytes = Buffer.from(`${JSON.stringify(record, null, 2)}\n`);
298
+ // Refuse an oversized record before any write, such as creating a release.
215
299
  requireProof(
216
- bytes.length <= MAX_RECORD_BYTES,
300
+ recordBytes(record).length <= MAX_RECORD_BYTES,
217
301
  "The completion record exceeds its bounded publication size."
218
302
  );
219
- const digest = sha256(bytes);
303
+ const checked = ensureEvidenceRelease(
304
+ context.run,
305
+ transport,
306
+ context.policy,
307
+ { tag: target.tag, pinned: target.pinned }
308
+ );
309
+ const adopted = strandedRecord(
310
+ transport,
311
+ [checked, ...(checked.passed ?? [])],
312
+ record,
313
+ publisher
314
+ );
315
+ const published = adopted ?? { record, bytes: recordBytes(record) };
316
+ const digest = sha256(published.bytes);
220
317
  const name = `${recordId}-r${record.revision}-${digest}.json`;
221
- const temporary = mkdtempSync(join(tmpdir(), "lisa-completion-proof-"));
222
- try {
223
- mkdirSync(temporary, { recursive: true });
224
- const file = join(temporary, name);
225
- writeFileSync(file, bytes);
226
- const evidence = uploadProof(context, transport, target, file);
227
- const matching = releaseAssets(transport, evidence.release).filter(
228
- asset => asset.name === name
229
- );
230
- requireProof(
231
- matching.length === 1,
232
- "The uploaded completion asset cannot be uniquely read back.",
233
- READ_ERROR
234
- );
235
- const stored = transport.asset(matching[0].id, MAX_RECORD_BYTES);
236
- requireProof(
237
- stored.bytes.equals(bytes) &&
238
- sha256(stored.bytes) === digest &&
239
- stored.metadata.uploader?.id === publisher,
240
- "The native uploaded acceptance bytes or publisher differ from the producer's record."
241
- );
242
- const publisherState = transport.trustedPublisher(stored.metadata, record, {
243
- publishing: true,
244
- });
245
- // Recheck native scope after upload; do not publish acceptance for changed requirements.
246
- const fresh = {
247
- ...context.readSubject(),
248
- comments: context.readComments(),
249
- };
250
- requireProof(
251
- sha256(primarySpecProjection(fresh.body)) === record.spec_sha256,
252
- "Requirements changed during proof publication; no locator was written.",
253
- "pending-proof"
254
- );
255
- if (record.state === "accepted-for-completion")
256
- evaluateAcceptedRecord({ record }, context, fresh, transport);
257
- const locator = {
258
- schema_version: 1,
259
- record_id: recordId,
260
- revision: record.revision,
261
- repository: context.repository,
262
- asset_id: stored.metadata.id,
263
- sha256: digest,
264
- };
265
- const body = `${PROOF_MARKER}\n${JSON.stringify(locator)}`;
266
- const comment = context.postLocator(body, subject.native_id);
267
- const readback = context
268
- .readComments()
269
- .find(row => String(row.id) === String(comment.id));
270
- requireProof(
271
- readback?.body === body &&
272
- String((readback.user ?? readback.author)?.id) === trackerActor,
273
- "The native completion locator or publisher did not read back exactly.",
274
- WRITE_ERROR
275
- );
276
- const deferredProducer = !publisherState.ready;
277
- return {
278
- category: deferredProducer ? "published/pending-producer" : "published",
279
- record_id: recordId,
280
- revision: record.revision,
281
- asset_id: stored.metadata.id,
282
- sha256: digest,
283
- comment_id: comment.id,
284
- ref: context.ref,
285
- terminal_mutation: false,
286
- };
287
- } finally {
288
- rmSync(temporary, { recursive: true, force: true });
289
- }
318
+ const evidence =
319
+ adopted?.evidence ??
320
+ uploadRecord(context, transport, target, checked, name, published.bytes);
321
+ return locateRecord(context, transport, {
322
+ record: published.record,
323
+ bytes: published.bytes,
324
+ evidence,
325
+ name,
326
+ digest,
327
+ publisher,
328
+ trackerActor,
329
+ nativeId: subject.native_id,
330
+ });
331
+ }
332
+
333
+ /**
334
+ * Read the uploaded (or adopted) record back exactly, re-run every trust and
335
+ * acceptance check against it, and only then post and read back its locator.
336
+ * @param {object} context - The canonical publish context.
337
+ * @param {object} transport - The bounded GitHub proof transport.
338
+ * @param {object} published - The record, its bytes, asset name and digest,
339
+ * the release, the publisher and tracker identities, and the subject id.
340
+ * @returns {object} The publication result.
341
+ */
342
+ function locateRecord(context, transport, published) {
343
+ const { record, bytes, evidence, name, digest, publisher } = published;
344
+ const matching = releaseAssets(transport, evidence.release).filter(
345
+ asset => asset.name === name
346
+ );
347
+ requireProof(
348
+ matching.length === 1,
349
+ "The uploaded completion asset cannot be uniquely read back.",
350
+ READ_ERROR
351
+ );
352
+ const stored = transport.asset(matching[0].id, MAX_RECORD_BYTES);
353
+ requireProof(
354
+ stored.bytes.equals(bytes) &&
355
+ sha256(stored.bytes) === digest &&
356
+ stored.metadata.uploader?.id === publisher,
357
+ "The native uploaded acceptance bytes or publisher differ from the producer's record."
358
+ );
359
+ const publisherState = transport.trustedPublisher(stored.metadata, record, {
360
+ publishing: true,
361
+ });
362
+ // Recheck native scope after upload; do not publish acceptance for changed requirements.
363
+ const fresh = {
364
+ ...context.readSubject(),
365
+ comments: context.readComments(),
366
+ };
367
+ requireProof(
368
+ sha256(primarySpecProjection(fresh.body)) === record.spec_sha256,
369
+ "Requirements changed during proof publication; no locator was written.",
370
+ "pending-proof"
371
+ );
372
+ if (record.state === "accepted-for-completion")
373
+ evaluateAcceptedRecord({ record }, context, fresh, transport);
374
+ const locator = {
375
+ schema_version: 1,
376
+ record_id: record.record_id,
377
+ revision: record.revision,
378
+ repository: context.repository,
379
+ asset_id: stored.metadata.id,
380
+ sha256: digest,
381
+ };
382
+ const body = `${PROOF_MARKER}\n${JSON.stringify(locator)}`;
383
+ const comment = context.postLocator(body, published.nativeId);
384
+ const readback = context
385
+ .readComments()
386
+ .find(row => String(row.id) === String(comment.id));
387
+ requireProof(
388
+ readback?.body === body &&
389
+ String((readback.user ?? readback.author)?.id) === published.trackerActor,
390
+ "The native completion locator or publisher did not read back exactly.",
391
+ WRITE_ERROR
392
+ );
393
+ return {
394
+ category: publisherState.ready ? "published" : "published/pending-producer",
395
+ record_id: record.record_id,
396
+ revision: record.revision,
397
+ asset_id: stored.metadata.id,
398
+ sha256: digest,
399
+ comment_id: comment.id,
400
+ ref: context.ref,
401
+ terminal_mutation: false,
402
+ };
290
403
  }
@@ -17,7 +17,6 @@
17
17
  */
18
18
  import {
19
19
  CompletionProofError,
20
- MAX_NATIVE_JSON_BYTES,
21
20
  requireProof,
22
21
  } from "./completion-proof-shape.mjs";
23
22
  import {
@@ -85,28 +84,13 @@ export function excerpt(stderr) {
85
84
  }
86
85
 
87
86
  /**
88
- * Read a release by tag in one call; `null` only for GitHub's explicit 404.
89
- * Any other failure goes through the bounded transport, which reports it as a
90
- * read error instead of guessing the release is absent and creating it.
87
+ * Read a release by tag; `null` only for GitHub's explicit 404. Any other
88
+ * failure is retried when transient and then reported as a read error naming
89
+ * the release endpoint, instead of guessing the release is absent and
90
+ * creating it (CodySwannGT/lisa#4733).
91
91
  */
92
- function readRelease(run, transport, tag) {
93
- const path = `${transport.root}/releases/tags/${tag}`;
94
- const result = run("gh", ["api", path], {
95
- allowFailure: true,
96
- maxBuffer: MAX_NATIVE_JSON_BYTES,
97
- });
98
- if (result.status === 0 && !result.error) {
99
- try {
100
- return JSON.parse(result.stdout);
101
- } catch {
102
- throw new CompletionProofError(
103
- READ_ERROR,
104
- "The evidence release metadata is not complete JSON."
105
- );
106
- }
107
- }
108
- if (/HTTP 404/.test(result.stderr ?? "")) return null;
109
- return transport.json(path);
92
+ function readRelease(transport, tag) {
93
+ return transport.optionalJson(`${transport.root}/releases/tags/${tag}`);
110
94
  }
111
95
 
112
96
  /**
@@ -147,7 +131,7 @@ export function uploadHitLimit(stderr, transport, release) {
147
131
 
148
132
  /** A release by tag, created when absent; a concurrent creator may win. */
149
133
  function openRelease(run, transport, tag) {
150
- let release = readRelease(run, transport, tag);
134
+ let release = readRelease(transport, tag);
151
135
  if (!release) {
152
136
  const created = run(
153
137
  "gh",
@@ -165,7 +149,7 @@ function openRelease(run, transport, tag) {
165
149
  ],
166
150
  { allowFailure: true }
167
151
  );
168
- release = readRelease(run, transport, tag);
152
+ release = readRelease(transport, tag);
169
153
  const reason = excerpt(created.stderr);
170
154
  requireProof(
171
155
  release,
@@ -173,7 +157,8 @@ function openRelease(run, transport, tag) {
173
157
  WRITE_ERROR
174
158
  );
175
159
  }
176
- return { tag, release, count: releaseAssets(transport, release).length };
160
+ const assets = releaseAssets(transport, release);
161
+ return { tag, release, count: assets.length, assets };
177
162
  }
178
163
 
179
164
  /**
@@ -189,8 +174,11 @@ function openRelease(run, transport, tag) {
189
174
  * when full instead of rolling over.
190
175
  * @param {number} [options.from] - The overflow position to start at; 1 (the
191
176
  * tag itself) by default, higher after an upload found a release full.
192
- * @returns {{tag: string, release: object, count: number, index: number}} The
193
- * usable release and its overflow position.
177
+ * @returns {{tag: string, release: object, count: number, assets: object[],
178
+ * index: number, passed: object[]}} The usable release, the assets it held
179
+ * when checked, its overflow position, and every full release opened and
180
+ * passed over on the way to it, so a publisher can look there for a record
181
+ * it already uploaded (CodySwannGT/lisa#4733).
194
182
  */
195
183
  export function ensureEvidenceRelease(run, transport, policy, options = {}) {
196
184
  const base =
@@ -204,9 +192,10 @@ export function ensureEvidenceRelease(run, transport, policy, options = {}) {
204
192
  pinned: true,
205
193
  })
206
194
  );
207
- return { ...pinned, index: 1 };
195
+ return { ...pinned, index: 1, passed: [] };
208
196
  }
209
197
  let last = { tag: base, count: undefined };
198
+ const passed = [];
210
199
  for (
211
200
  let index = options.from ?? 1;
212
201
  index <= EVIDENCE_RELEASE_MAX_OVERFLOW;
@@ -219,7 +208,9 @@ export function ensureEvidenceRelease(run, transport, policy, options = {}) {
219
208
  `${fullReleaseMessage(last.tag, transport.repository, last.count, { policy })} Lisa could not roll over to \`${tag}\`: the release name is too long for an overflow suffix (GitHub allows 100 characters), so shorten \`verification.completion.evidenceRelease\`.`
220
209
  );
221
210
  last = openRelease(run, transport, tag);
222
- if (last.count < EVIDENCE_RELEASE_NEAR_FULL) return { ...last, index };
211
+ if (last.count < EVIDENCE_RELEASE_NEAR_FULL)
212
+ return { ...last, index, passed: [...passed] };
213
+ passed.push(last);
223
214
  }
224
215
  throw new CompletionProofError(
225
216
  WRITE_ERROR,
@@ -27,6 +27,7 @@ const COMMON = [
27
27
  "lib/completion-proof-shape.mjs",
28
28
  "lib/completion-proof-source.mjs",
29
29
  "lib/evidence-release-capacity.mjs",
30
+ "lib/usage-artifact-ref.mjs",
30
31
  "lib/usage-effectiveness.mjs",
31
32
  "lib/usage-ledger-integrity.mjs",
32
33
  "lib/usage-ledger.mjs",
@@ -0,0 +1,8 @@
1
+ // This file is managed by Lisa and IS replaced on each `lisa` run.
2
+ // Do not edit directly — durable changes belong upstream in Lisa.
3
+
4
+ export declare const LINEAR_REQUIRED_FORM: "linear:<workspace>/<KEY-N>";
5
+ export declare function canonicalArtifactRefViolation(
6
+ ref: string
7
+ ): string | null;
8
+ export declare function assertCanonicalArtifactRef(ref: string): void;
@@ -0,0 +1,77 @@
1
+ // This file is managed by Lisa and IS replaced on each `lisa` run.
2
+ // Do not edit directly — durable changes belong upstream in Lisa.
3
+
4
+ /**
5
+ * The one `artifact_ref` grammar shared by the usage writer and the usage
6
+ * read-back integrity check.
7
+ *
8
+ * Writers must produce a Linear ref as `linear:<workspace>/<KEY-N>`. The
9
+ * completion-proof reader (`isVerifyEntryFor` in
10
+ * `scripts/lib/completion-proof-content.mjs`) matches that form exactly,
11
+ * case-sensitively, against an uppercase issue identifier; it also tolerates a
12
+ * bare `KEY-N`, but it never recognises the short `linear:<KEY-N>`. The writer
13
+ * is a pure utility with no config or workspace context, so it cannot
14
+ * normalise a short ref reliably. It refuses it instead, so producer and
15
+ * consumer agree on one grammar and a bad ref fails loudly at write time
16
+ * rather than silently later (CodySwannGT/lisa#4699).
17
+ *
18
+ * An agent that writes the `lisa:usage-entry` token by hand never passes
19
+ * through the writer, so the read-back integrity check
20
+ * (`usage-ledger-integrity.mjs`) reports the same violation from this same
21
+ * module (CodySwannGT/lisa#4846). Keeping the grammar here, rather than in the
22
+ * TypeScript writer, is what stops the two from drifting apart.
23
+ *
24
+ * Only the shape is checked, not the value: the workspace must still equal the
25
+ * `linear.workspace` key in `.lisa.config.json` exactly, including case.
26
+ *
27
+ * Only the `linear:` scheme is checked. Other providers' refs (`github:...`,
28
+ * bare Jira `KEY-N`, `notion:...`, and so on) pass through unchanged.
29
+ */
30
+
31
+ const LINEAR_PREFIX = "linear:";
32
+ const LINEAR_REST_PATTERN = /^[^/\s]+\/[A-Z][A-Z0-9_]*-\d+$/;
33
+
34
+ /** Operator-facing name of the only Linear form the reader recognises. */
35
+ export const LINEAR_REQUIRED_FORM = "linear:<workspace>/<KEY-N>";
36
+
37
+ /**
38
+ * Describe why an `artifact_ref` would never be recognised by the
39
+ * completion-proof reader.
40
+ *
41
+ * @param {string} ref Candidate or stored `artifact_ref`.
42
+ * @returns {string | null} An operator-readable explanation naming the
43
+ * required form, or null when the ref is acceptable (any non-Linear ref, or
44
+ * a Linear ref already in `linear:<workspace>/<KEY-N>` form).
45
+ */
46
+ export function canonicalArtifactRefViolation(ref) {
47
+ if (!ref.startsWith(LINEAR_PREFIX)) {
48
+ return null;
49
+ }
50
+ if (LINEAR_REST_PATTERN.test(ref.slice(LINEAR_PREFIX.length))) {
51
+ return null;
52
+ }
53
+ return (
54
+ `Usage artifact_ref "${ref}" is not a canonical Linear reference. ` +
55
+ `Write it as ${LINEAR_REQUIRED_FORM} (for example linear:acme/ENG-11), ` +
56
+ `taking <workspace> from the linear.workspace key in .lisa.config.json. ` +
57
+ `The completion proof never recognises a short linear:<KEY-N> or a ` +
58
+ `lowercase key, so such an entry would later be refused as absent.`
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Refuse a usage `artifact_ref` that the completion-proof reader would never
64
+ * recognise.
65
+ *
66
+ * @param {string} ref Candidate `artifact_ref` about to be written.
67
+ * @returns {void}
68
+ * @throws {Error} When `ref` starts with `linear:` but is not
69
+ * `linear:<workspace>/<KEY-N>` (no `/`, an empty workspace or one holding
70
+ * whitespace, or a key that is not an uppercase `KEY-N`).
71
+ */
72
+ export function assertCanonicalArtifactRef(ref) {
73
+ const violation = canonicalArtifactRefViolation(ref);
74
+ if (violation !== null) {
75
+ throw new Error(violation);
76
+ }
77
+ }
@@ -6,3 +6,6 @@ export declare function verifyLisaUsageSectionIntegrity(
6
6
  storedDocument: string,
7
7
  expected?: { entryIds?: readonly string[] }
8
8
  ): LisaUsageSectionIntegrityResult;
9
+ export declare function isLisaUsageLedgerIntact(
10
+ storedDocument: string
11
+ ): boolean;
@@ -1,6 +1,10 @@
1
1
  // This file is managed by Lisa and IS replaced on each `lisa` run.
2
2
  // Do not edit directly — durable changes belong upstream in Lisa.
3
3
 
4
+ import {
5
+ LINEAR_REQUIRED_FORM,
6
+ canonicalArtifactRefViolation,
7
+ } from "./usage-artifact-ref.mjs";
4
8
  import { LISA_USAGE_HEADING, parseLisaUsageSection } from "./usage-ledger.mjs";
5
9
  /**
6
10
  * Sort ids so an integrity report is deterministic regardless of document order.
@@ -97,6 +101,43 @@ function findRollupCoverageGaps(rollup, parsedEntryIds) {
97
101
  `Stored section contains direct entries absent from rollup direct_entry_ids: ${unrecorded.join(", ")}.`
98
102
  );
99
103
  }
104
+ /**
105
+ * Report direct entries whose `artifact_ref` the completion-proof reader would
106
+ * never recognise. The writer refuses such a ref, but a token written by hand
107
+ * never passes through the writer, and the entry would otherwise be refused
108
+ * only later, at completion, as "absent" (CodySwannGT/lisa#4846). The grammar
109
+ * comes from the module the writer uses, so the two cannot drift apart.
110
+ *
111
+ * When the caller names the entries it just wrote, only those are checked: a
112
+ * legacy short-ref row written before the grammar existed must not block every
113
+ * later write to the same artifact, including the qualified entry that
114
+ * replaces it. With no ids every entry is checked.
115
+ *
116
+ * @param {readonly { entryId: string, artifactRef: string }[]} entries Direct
117
+ * entries parsed from the stored section.
118
+ * @param {readonly string[]} expectedEntryIds Entry ids the caller just wrote;
119
+ * empty to check every entry.
120
+ * @returns Zero or one `non-canonical-artifact-ref` issue.
121
+ */
122
+ function findNonCanonicalArtifactRefs(entries, expectedEntryIds) {
123
+ const inScope =
124
+ expectedEntryIds.length === 0
125
+ ? entries
126
+ : entries.filter(entry => expectedEntryIds.includes(entry.entryId));
127
+ const offending = inScope
128
+ .filter(entry => canonicalArtifactRefViolation(entry.artifactRef) !== null)
129
+ .sort((left, right) =>
130
+ left.entryId > right.entryId ? 1 : left.entryId < right.entryId ? -1 : 0
131
+ );
132
+ const refs = offending.map(
133
+ entry => `${entry.entryId} (${entry.artifactRef})`
134
+ );
135
+ return reportIssue(
136
+ "non-canonical-artifact-ref",
137
+ offending.map(entry => entry.entryId),
138
+ `Stored section has entries whose artifact_ref the completion proof will never recognise: ${refs.join(", ")}. Rewrite each Linear ref as ${LINEAR_REQUIRED_FORM}, taking <workspace> from the linear.workspace key in .lisa.config.json.`
139
+ );
140
+ }
100
141
  /**
101
142
  * Verify that a STORED managed usage section is still a readable ledger.
102
143
  *
@@ -153,6 +194,28 @@ export function verifyLisaUsageSectionIntegrity(storedDocument, expected) {
153
194
  droppedExpected.flatMap(issue => issue.entryIds)
154
195
  ),
155
196
  ...findRollupCoverageGaps(parsed.rollup, parsedEntryIds),
197
+ ...findNonCanonicalArtifactRefs(parsed.entries, expectedEntryIds),
156
198
  ];
157
199
  return { ok: issues.length === 0, issues };
158
200
  }
201
+ /**
202
+ * Whether a stored managed usage section is an intact, enumerable ledger,
203
+ * ignoring `artifact_ref` grammar.
204
+ *
205
+ * The completion proof applies the reader's own grammar (`isVerifyEntryFor`)
206
+ * per expected Verify entry, and before CodySwannGT/lisa#4846 a section whose
207
+ * entries carried a short Linear ref was still an intact ledger to it. A legacy
208
+ * row with a short ref on some OTHER flow is harmless to that reader, so the
209
+ * write-time grammar issue must not turn such a body into a fatal integrity
210
+ * failure at completion. This keeps completion behaviour exactly as it was:
211
+ * nothing newly accepted, nothing newly refused.
212
+ *
213
+ * @param {string} storedDocument Artifact body or comment body as read back.
214
+ * @returns {boolean} True when every reported issue is an artifact_ref
215
+ * grammar issue (or there are none).
216
+ */
217
+ export function isLisaUsageLedgerIntact(storedDocument) {
218
+ return verifyLisaUsageSectionIntegrity(storedDocument).issues.every(
219
+ issue => issue.code === "non-canonical-artifact-ref"
220
+ );
221
+ }
@@ -72,6 +72,7 @@ export interface LisaUsageSectionIntegrityIssue {
72
72
  | "missing-entry-token"
73
73
  | "missing-rollup-token"
74
74
  | "missing-section"
75
+ | "non-canonical-artifact-ref"
75
76
  | "unrecorded-entry";
76
77
  entryIds: readonly string[];
77
78
  message: string;