@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.
- package/all/copy-overwrite/scripts/lib/completion-proof-content.mjs +2 -2
- package/all/copy-overwrite/scripts/lib/completion-proof-github.mjs +242 -62
- package/all/copy-overwrite/scripts/lib/completion-proof-projection.mjs +2 -2
- package/all/copy-overwrite/scripts/lib/completion-proof-publisher.mjs +195 -82
- package/all/copy-overwrite/scripts/lib/evidence-release-capacity.mjs +20 -29
- package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +1 -0
- package/all/copy-overwrite/scripts/lib/usage-artifact-ref.d.mts +8 -0
- package/all/copy-overwrite/scripts/lib/usage-artifact-ref.mjs +77 -0
- package/all/copy-overwrite/scripts/lib/usage-ledger-integrity.d.mts +3 -0
- package/all/copy-overwrite/scripts/lib/usage-ledger-integrity.mjs +63 -0
- package/all/copy-overwrite/scripts/lib/usage-ledger.d.mts +1 -0
- package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +14 -7
- package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.js +66 -0
- package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +28 -14
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/dist/utils/usage-accounting.d.ts +1 -1
- package/dist/utils/usage-accounting.d.ts.map +1 -1
- package/dist/utils/usage-accounting.js +1 -1
- package/dist/utils/usage-accounting.js.map +1 -1
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/rules/reference/usage-accounting.md +9 -1
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/rules/reference/usage-accounting.md +9 -1
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/rules/usage-accounting-reference.mdc +9 -1
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/rules/reference/usage-accounting.md +9 -1
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/rules/reference/usage-accounting.md +9 -1
- package/scripts/two-channel-couplings.json +1 -1
- package/typescript/copy-overwrite/.prettierignore +1 -0
- package/dist/utils/usage-artifact-ref.d.ts +0 -30
- package/dist/utils/usage-artifact-ref.d.ts.map +0 -1
- package/dist/utils/usage-artifact-ref.js +0 -55
- 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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
298
|
+
// Refuse an oversized record before any write, such as creating a release.
|
|
215
299
|
requireProof(
|
|
216
|
-
|
|
300
|
+
recordBytes(record).length <= MAX_RECORD_BYTES,
|
|
217
301
|
"The completion record exceeds its bounded publication size."
|
|
218
302
|
);
|
|
219
|
-
const
|
|
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
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
|
89
|
-
*
|
|
90
|
-
*
|
|
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(
|
|
93
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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,
|
|
193
|
-
* usable release
|
|
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)
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|