@codyswann/lisa 4.101.10 → 4.102.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all/copy-overwrite/scripts/check-third-party-review-evidence.mjs +124 -28
- package/all/copy-overwrite/scripts/lib/completion-proof-github.mjs +5 -2
- package/all/copy-overwrite/scripts/lib/evidence-prune-apply.mjs +227 -0
- package/all/copy-overwrite/scripts/lib/evidence-prune-config.mjs +165 -0
- package/all/copy-overwrite/scripts/lib/evidence-prune-gh.mjs +256 -0
- package/all/copy-overwrite/scripts/lib/evidence-prune-records.mjs +101 -0
- package/all/copy-overwrite/scripts/lib/evidence-prune.mjs +243 -0
- package/all/copy-overwrite/scripts/lisa-evidence-prune.mjs +226 -0
- package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +1 -1
- package/dist/cli/doctor-third-party-evidence-seed.d.ts +9 -2
- package/dist/cli/doctor-third-party-evidence-seed.d.ts.map +1 -1
- package/dist/cli/doctor-third-party-evidence-seed.js +64 -4
- package/dist/cli/doctor-third-party-evidence-seed.js.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.js +76 -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/nightly-e2e-guard-behavior-certificate.js.map +1 -1
- package/dist/core/third-party-evidence-seed.d.ts +9 -1
- package/dist/core/third-party-evidence-seed.d.ts.map +1 -1
- package/dist/core/third-party-evidence-seed.js +41 -9
- package/dist/core/third-party-evidence-seed.js.map +1 -1
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +34 -6
- package/dist/core/upstream-evidence-manifest.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-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-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -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/scripts/two-channel-couplings.json +1 -1
- package/typescript/copy-overwrite/.prettierignore +6 -0
- package/typescript/create-only/.github/workflows/third-party-review-evidence.yml +34 -12
|
@@ -0,0 +1,256 @@
|
|
|
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 `gh` calls the evidence prune makes, each failing closed in plain words.
|
|
6
|
+
*
|
|
7
|
+
* Every read the prune decides from must be complete: a listing cut short or a
|
|
8
|
+
* record that cannot be read would make a depended-on file look unpinned, and
|
|
9
|
+
* an unpinned file is one the prune may delete. So a partial answer is always
|
|
10
|
+
* an error here, never an empty result (CodySwannGT/lisa#4720).
|
|
11
|
+
* @module scripts/lib/evidence-prune-gh
|
|
12
|
+
*/
|
|
13
|
+
import { createHash } from "node:crypto";
|
|
14
|
+
|
|
15
|
+
import { EvidencePruneError, reportedSha256 } from "./evidence-prune.mjs";
|
|
16
|
+
|
|
17
|
+
const PAGE_SIZE = 100;
|
|
18
|
+
/** Ten pages already exceed GitHub's 1000-file release cap. */
|
|
19
|
+
const MAX_PAGES = 20;
|
|
20
|
+
/** Release listings are not capped by GitHub; this only bounds a runaway. */
|
|
21
|
+
const MAX_RELEASE_PAGES = 1000;
|
|
22
|
+
const JSON_BUFFER = 64 * 1024 * 1024;
|
|
23
|
+
const TRANSFER_TIMEOUT_MS = 600_000;
|
|
24
|
+
const OCTET = "application/octet-stream";
|
|
25
|
+
|
|
26
|
+
/** The first line of a child's stderr, for a message an operator can act on. */
|
|
27
|
+
function said(result) {
|
|
28
|
+
const text = Buffer.isBuffer(result.stderr)
|
|
29
|
+
? result.stderr.toString("utf8")
|
|
30
|
+
: (result.stderr ?? "");
|
|
31
|
+
const line = text.trim().split("\n")[0]?.slice(0, 300);
|
|
32
|
+
return line ? ` GitHub said: ${line}` : "";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* sha256 of bytes as lowercase hex.
|
|
37
|
+
* @param {Buffer} bytes - File content.
|
|
38
|
+
* @returns {string} Hex digest.
|
|
39
|
+
*/
|
|
40
|
+
export function hashBytes(bytes) {
|
|
41
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The refusal for any listing that cannot be shown complete. */
|
|
45
|
+
function incompleteListing(what) {
|
|
46
|
+
return new EvidencePruneError(
|
|
47
|
+
`The file listing for ${what} is incomplete, so nothing was changed. Retry when GitHub answers fully.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A release-asset listing row the prune can decide from. */
|
|
52
|
+
const assetRow = row =>
|
|
53
|
+
Number.isSafeInteger(row?.id) &&
|
|
54
|
+
typeof row.name === "string" &&
|
|
55
|
+
Number.isSafeInteger(row.size);
|
|
56
|
+
|
|
57
|
+
/** A repository release listing row. */
|
|
58
|
+
const releaseRow = row =>
|
|
59
|
+
Number.isSafeInteger(row?.id) && typeof row.tag_name === "string";
|
|
60
|
+
|
|
61
|
+
/** Pages from `--paginate --slurp`, refused unless provably complete. */
|
|
62
|
+
function completePages(pages, { what, valid, maxPages }) {
|
|
63
|
+
if (
|
|
64
|
+
!Array.isArray(pages) ||
|
|
65
|
+
pages.length === 0 ||
|
|
66
|
+
pages.length >= maxPages ||
|
|
67
|
+
!pages.every(Array.isArray) ||
|
|
68
|
+
pages.slice(0, -1).some(page => page.length !== PAGE_SIZE) ||
|
|
69
|
+
pages.at(-1).length > PAGE_SIZE
|
|
70
|
+
)
|
|
71
|
+
throw incompleteListing(what);
|
|
72
|
+
const rows = pages.flat();
|
|
73
|
+
const ids = new Set(rows.map(row => row?.id));
|
|
74
|
+
if (ids.size !== rows.length || !rows.every(valid))
|
|
75
|
+
throw incompleteListing(what);
|
|
76
|
+
return rows;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** `gh` bound to one repository: raw output, JSON, and binary downloads. */
|
|
80
|
+
function client(run, repository) {
|
|
81
|
+
const root = `repos/${repository}`;
|
|
82
|
+
function gh(args, failure, options = {}) {
|
|
83
|
+
const result = run("gh", args, { maxBuffer: JSON_BUFFER, ...options });
|
|
84
|
+
if (result.status !== 0 || result.error)
|
|
85
|
+
throw Object.assign(new EvidencePruneError(`${failure}${said(result)}`), {
|
|
86
|
+
notFound: /HTTP 404/.test(String(result.stderr ?? "")),
|
|
87
|
+
});
|
|
88
|
+
return result.stdout;
|
|
89
|
+
}
|
|
90
|
+
function json(args, failure, options = {}) {
|
|
91
|
+
const text = gh(args, failure, options);
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(text);
|
|
94
|
+
} catch {
|
|
95
|
+
throw new EvidencePruneError(
|
|
96
|
+
`${failure} The answer was not complete JSON.`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function download(asset) {
|
|
101
|
+
const bytes = gh(
|
|
102
|
+
[
|
|
103
|
+
"api",
|
|
104
|
+
`${root}/releases/assets/${asset.id}`,
|
|
105
|
+
"--header",
|
|
106
|
+
`Accept: ${OCTET}`,
|
|
107
|
+
],
|
|
108
|
+
`Could not download ${asset.name} from ${repository}.`,
|
|
109
|
+
{ binary: true, maxBuffer: asset.size + 1, timeout: TRANSFER_TIMEOUT_MS }
|
|
110
|
+
);
|
|
111
|
+
if (!Buffer.isBuffer(bytes) || bytes.length !== asset.size)
|
|
112
|
+
throw new EvidencePruneError(
|
|
113
|
+
`The download of ${asset.name} was incomplete (${bytes?.length ?? 0} of ${asset.size} bytes).`
|
|
114
|
+
);
|
|
115
|
+
return bytes;
|
|
116
|
+
}
|
|
117
|
+
return { run, repository, root, gh, json, download };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Every row of a paginated listing, proven complete. */
|
|
121
|
+
function listComplete({ json }, path, shape) {
|
|
122
|
+
const failure = `Could not list ${shape.what}.`;
|
|
123
|
+
const pages = json(["api", "--paginate", "--slurp", path], failure);
|
|
124
|
+
const rows = completePages(pages, shape);
|
|
125
|
+
// A full last page is ambiguous: the listing may end there, or the
|
|
126
|
+
// pagination may have been cut short. The page after it must be empty.
|
|
127
|
+
if (rows.length === 0 || rows.length % PAGE_SIZE !== 0) return rows;
|
|
128
|
+
const next = json(["api", `${path}&page=${pages.length + 1}`], failure);
|
|
129
|
+
if (!Array.isArray(next) || next.length !== 0)
|
|
130
|
+
throw incompleteListing(shape.what);
|
|
131
|
+
return rows;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Every file in a release. */
|
|
135
|
+
function listAssets(bound, release) {
|
|
136
|
+
return listComplete(
|
|
137
|
+
bound,
|
|
138
|
+
`${bound.root}/releases/${release.id}/assets?per_page=${PAGE_SIZE}`,
|
|
139
|
+
{
|
|
140
|
+
what: `the files in release ${release.tag_name}`,
|
|
141
|
+
valid: assetRow,
|
|
142
|
+
maxPages: MAX_PAGES,
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Every release in the repository. */
|
|
148
|
+
function listReleases(bound) {
|
|
149
|
+
return listComplete(bound, `${bound.root}/releases?per_page=${PAGE_SIZE}`, {
|
|
150
|
+
what: `the releases in ${bound.repository}`,
|
|
151
|
+
valid: releaseRow,
|
|
152
|
+
maxPages: MAX_RELEASE_PAGES,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Whether `gh` can act: installed, and signed in to github.com.
|
|
158
|
+
* @param {Function} run - Child-process runner.
|
|
159
|
+
* @returns {"ok"|"missing"|"signed-out"} The state.
|
|
160
|
+
*/
|
|
161
|
+
export function ghAccess(run) {
|
|
162
|
+
const result = run("gh", ["auth", "status", "--hostname", "github.com"], {});
|
|
163
|
+
if (result.status === null || result.error?.code === "ENOENT")
|
|
164
|
+
return "missing";
|
|
165
|
+
return result.status === 0 ? "ok" : "signed-out";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A release by tag, or null when GitHub says it does not exist. */
|
|
169
|
+
function readRelease({ root, repository, json }, tag) {
|
|
170
|
+
try {
|
|
171
|
+
return json(
|
|
172
|
+
["api", `${root}/releases/tags/${encodeURIComponent(tag)}`],
|
|
173
|
+
`Could not read the release ${tag} in ${repository}.`
|
|
174
|
+
);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if (error.notFound) return null;
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The three writes the prune makes: create the archive, upload, delete. */
|
|
182
|
+
function writes({ root, repository, gh, json }) {
|
|
183
|
+
return {
|
|
184
|
+
createRelease: (tag, branch) =>
|
|
185
|
+
gh(
|
|
186
|
+
[
|
|
187
|
+
"release",
|
|
188
|
+
"create",
|
|
189
|
+
tag,
|
|
190
|
+
"--repo",
|
|
191
|
+
repository,
|
|
192
|
+
"--target",
|
|
193
|
+
branch,
|
|
194
|
+
"--title",
|
|
195
|
+
tag,
|
|
196
|
+
"--notes",
|
|
197
|
+
"Archived Lisa evidence",
|
|
198
|
+
"--latest=false",
|
|
199
|
+
],
|
|
200
|
+
`Could not create the archive release ${tag} in ${repository}.`
|
|
201
|
+
),
|
|
202
|
+
upload: (release, name, bytes) =>
|
|
203
|
+
json(
|
|
204
|
+
[
|
|
205
|
+
"api",
|
|
206
|
+
"--method",
|
|
207
|
+
"POST",
|
|
208
|
+
`https://uploads.github.com/${root}/releases/${release.id}/assets?name=${encodeURIComponent(name)}`,
|
|
209
|
+
"--header",
|
|
210
|
+
`Content-Type: ${OCTET}`,
|
|
211
|
+
// gh does not set a length for a body read from stdin, and the
|
|
212
|
+
// upload host refuses it: "Bad Content-Length (HTTP 400)".
|
|
213
|
+
"--header",
|
|
214
|
+
`Content-Length: ${bytes.length}`,
|
|
215
|
+
"--input",
|
|
216
|
+
"-",
|
|
217
|
+
],
|
|
218
|
+
`Could not upload ${name} to the archive release ${release.tag_name}.`,
|
|
219
|
+
{ input: bytes, timeout: TRANSFER_TIMEOUT_MS }
|
|
220
|
+
),
|
|
221
|
+
remove: asset =>
|
|
222
|
+
gh(
|
|
223
|
+
["api", "--method", "DELETE", `${root}/releases/assets/${asset.id}`],
|
|
224
|
+
`Archived ${asset.name}, but could not delete it from the evidence release.`
|
|
225
|
+
),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Bind the prune's GitHub reads and writes to one repository.
|
|
231
|
+
* @param {Function} run - `(command, args, options) => {status, stdout, stderr, error}`.
|
|
232
|
+
* @param {string} repository - `owner/name`.
|
|
233
|
+
* @returns {object} The prune's GitHub operations.
|
|
234
|
+
*/
|
|
235
|
+
export function pruneGitHub(run, repository) {
|
|
236
|
+
const bound = client(run, repository);
|
|
237
|
+
return {
|
|
238
|
+
repository,
|
|
239
|
+
repo: () =>
|
|
240
|
+
bound.json(
|
|
241
|
+
["api", bound.root],
|
|
242
|
+
`Could not read the repository ${repository}; check that gh can see it.`
|
|
243
|
+
),
|
|
244
|
+
release: tag => readRelease(bound, tag),
|
|
245
|
+
assets: release => listAssets(bound, release),
|
|
246
|
+
releases: () => listReleases(bound),
|
|
247
|
+
asset: id =>
|
|
248
|
+
bound.json(
|
|
249
|
+
["api", `${bound.root}/releases/assets/${id}`],
|
|
250
|
+
`Could not read back release file ${id}.`
|
|
251
|
+
),
|
|
252
|
+
download: bound.download,
|
|
253
|
+
sha256: asset => reportedSha256(asset) ?? hashBytes(bound.download(asset)),
|
|
254
|
+
...writes(bound),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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 completion records the prune must honour, from every accepted release.
|
|
6
|
+
*
|
|
7
|
+
* The completion-proof validator accepts proof from every accepted evidence
|
|
8
|
+
* release — the legacy `pr-assets`, the configured release or template, and any
|
|
9
|
+
* listed history — and the publisher writes each new record into whichever of
|
|
10
|
+
* them is current. So after a project rotates its release, a record in this
|
|
11
|
+
* month's release can depend on a file in last month's. Reading pins from the
|
|
12
|
+
* pruned release alone would let the prune delete that file
|
|
13
|
+
* (CodySwannGT/lisa#4720). Every accepted release is read, and every record in
|
|
14
|
+
* each must parse, or the run stops before anything changes.
|
|
15
|
+
* @module scripts/lib/evidence-prune-records
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
isAcceptedEvidenceRelease,
|
|
19
|
+
resolveEvidenceRelease,
|
|
20
|
+
} from "./completion-proof-github.mjs";
|
|
21
|
+
import { COMPLETION_RECORD, EvidencePruneError } from "./evidence-prune.mjs";
|
|
22
|
+
|
|
23
|
+
const isRecord = asset => COMPLETION_RECORD.test(asset.name);
|
|
24
|
+
|
|
25
|
+
/** One completion record, parsed; any failure stops the run before a write. */
|
|
26
|
+
function readRecord(gh, asset) {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(gh.download(asset).toString("utf8"));
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new EvidencePruneError(
|
|
31
|
+
`The completion record ${asset.name} could not be read (${error.message}). Nothing was changed: every record must be readable to know which files are still needed.`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Every accepted release's complete listing, and every record in them.
|
|
38
|
+
* @param {object} gh - The prune's GitHub operations.
|
|
39
|
+
* @param {object} policy - `verification.completion` from the Lisa config.
|
|
40
|
+
* @param {string} tag - The release being pruned.
|
|
41
|
+
* @returns {object|null} `{source, assets, accepted, recordAssets, records}`,
|
|
42
|
+
* or null when the pruned release does not exist.
|
|
43
|
+
*/
|
|
44
|
+
export function evidenceSnapshot(gh, policy, tag) {
|
|
45
|
+
const accepted = gh
|
|
46
|
+
.releases()
|
|
47
|
+
.filter(release => isAcceptedEvidenceRelease(policy, release.tag_name));
|
|
48
|
+
const source = accepted.find(release => release.tag_name === tag);
|
|
49
|
+
if (!source) return null;
|
|
50
|
+
const others = accepted
|
|
51
|
+
.filter(release => release !== source)
|
|
52
|
+
.flatMap(release => gh.assets(release));
|
|
53
|
+
const assets = gh.assets(source);
|
|
54
|
+
const recordAssets = [...others, ...assets].filter(isRecord);
|
|
55
|
+
return {
|
|
56
|
+
source,
|
|
57
|
+
assets,
|
|
58
|
+
accepted,
|
|
59
|
+
recordAssets,
|
|
60
|
+
records: recordAssets.map(asset => readRecord(gh, asset)),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A re-read of records published since the snapshot, for the check made
|
|
66
|
+
* before each delete.
|
|
67
|
+
*
|
|
68
|
+
* It re-lists the snapshot's accepted releases plus every release the
|
|
69
|
+
* publisher can write a new record into: the one it resolves to now, so a
|
|
70
|
+
* rotation across a month boundary during a long run is still seen, and the
|
|
71
|
+
* one `LISA_EVIDENCE_RELEASE` pins, which the publisher uses instead when set
|
|
72
|
+
* and creates when absent. It does not re-list the repository's releases on
|
|
73
|
+
* every delete: on a repository with thousands of releases that alone is
|
|
74
|
+
* twenty-odd calls per file, and those two are the only releases the
|
|
75
|
+
* publisher creates.
|
|
76
|
+
* @param {object} gh - The prune's GitHub operations.
|
|
77
|
+
* @param {object} policy - `verification.completion` from the Lisa config.
|
|
78
|
+
* @param {object[]} accepted - The snapshot's accepted releases.
|
|
79
|
+
* @param {object} [options] - Where the publisher may write.
|
|
80
|
+
* @param {() => Date} [options.clock] - The time the publisher resolves at.
|
|
81
|
+
* @param {string} [options.pinned] - The validated `LISA_EVIDENCE_RELEASE`.
|
|
82
|
+
* @returns {(known: Set<number>) => {ids: number[], records: unknown[]}} The
|
|
83
|
+
* re-reader: given the record ids already read, the ones that are new.
|
|
84
|
+
*/
|
|
85
|
+
export function recordRescanner(gh, policy, accepted, options = {}) {
|
|
86
|
+
const clock = options.clock ?? (() => new Date());
|
|
87
|
+
return known => {
|
|
88
|
+
const targets = [resolveEvidenceRelease(policy, clock()), options.pinned];
|
|
89
|
+
const extra = [...new Set(targets.filter(Boolean))]
|
|
90
|
+
.filter(tag => !accepted.some(release => release.tag_name === tag))
|
|
91
|
+
.map(tag => gh.release(tag))
|
|
92
|
+
.filter(Boolean);
|
|
93
|
+
const fresh = [...accepted, ...extra]
|
|
94
|
+
.flatMap(release => gh.assets(release))
|
|
95
|
+
.filter(asset => isRecord(asset) && !known.has(asset.id));
|
|
96
|
+
return {
|
|
97
|
+
ids: fresh.map(asset => asset.id),
|
|
98
|
+
records: fresh.map(asset => readRecord(gh, asset)),
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
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
|
+
* Pure planning for the evidence prune: which files a completion record still
|
|
6
|
+
* depends on, which are safe to move, and how the plan reads to an operator.
|
|
7
|
+
*
|
|
8
|
+
* GitHub caps a release at 1000 files, and a full evidence release stops every
|
|
9
|
+
* completion (CodySwannGT/lisa#4692, #4720). Only files nothing depends on may
|
|
10
|
+
* move, because the completion-proof validator reads proof only from the
|
|
11
|
+
* evidence releases it accepts; an archived file a record names would stop
|
|
12
|
+
* validating. So the pinned set is deliberately over-inclusive: any asset id or
|
|
13
|
+
* 64-hex digest anywhere inside any completion record pins a file.
|
|
14
|
+
* @module scripts/lib/evidence-prune
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Completion records are never pruned; they are the `supersedes` audit chain. */
|
|
18
|
+
export const COMPLETION_RECORD = /^completion-.*\.json$/;
|
|
19
|
+
/** Evidence younger than this is assumed to belong to work still in flight. */
|
|
20
|
+
export const DEFAULT_MIN_AGE_DAYS = 14;
|
|
21
|
+
const DAY_MS = 86_400_000;
|
|
22
|
+
const HEX_DIGEST = /[0-9a-f]{64}/gi;
|
|
23
|
+
const ASSET_ID_KEY = /^asset_?id$/i;
|
|
24
|
+
const ASSET_URL_ID = /\/releases\/assets\/(\d+)/g;
|
|
25
|
+
|
|
26
|
+
/** A refusal whose message is already written for the operator. */
|
|
27
|
+
export class EvidencePruneError extends Error {
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} message - Plain-language reason and what to do next.
|
|
30
|
+
* @param {object} [details] - Machine-readable context for `--json`.
|
|
31
|
+
*/
|
|
32
|
+
constructor(message, details = {}) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "EvidencePruneError";
|
|
35
|
+
this.details = details;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The archive release a run moves files into: `<release>-archive-YYYY-MM`.
|
|
41
|
+
* @param {string} release - The evidence release being pruned.
|
|
42
|
+
* @param {Date} now - Run time; its UTC year and month name the archive.
|
|
43
|
+
* @returns {string} The archive release tag.
|
|
44
|
+
*/
|
|
45
|
+
export function archiveReleaseTag(release, now) {
|
|
46
|
+
return `${release}-archive-${now.toISOString().slice(0, 7)}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Every asset id and digest one JSON value mentions, at any depth. */
|
|
50
|
+
function walk(value, key = "") {
|
|
51
|
+
if (Array.isArray(value)) return value.flatMap(item => walk(item, key));
|
|
52
|
+
if (value && typeof value === "object")
|
|
53
|
+
return Object.entries(value).flatMap(([name, item]) => walk(item, name));
|
|
54
|
+
const text = typeof value === "string" ? value : "";
|
|
55
|
+
const keyed =
|
|
56
|
+
ASSET_ID_KEY.test(key) && /^\d+$/.test(String(value))
|
|
57
|
+
? [{ id: Number(value) }]
|
|
58
|
+
: [];
|
|
59
|
+
return [
|
|
60
|
+
...keyed,
|
|
61
|
+
...[...text.matchAll(ASSET_URL_ID)].map(match => ({
|
|
62
|
+
id: Number(match[1]),
|
|
63
|
+
})),
|
|
64
|
+
...(text.match(HEX_DIGEST) ?? []).map(hex => ({
|
|
65
|
+
digest: hex.toLowerCase(),
|
|
66
|
+
})),
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The asset ids and sha256 digests any completion record depends on.
|
|
72
|
+
* @param {unknown[]} records - Every parsed completion record in the release.
|
|
73
|
+
* @returns {{assetIds: Set<number>, digests: Set<string>}} The pinned values.
|
|
74
|
+
*/
|
|
75
|
+
export function collectPins(records) {
|
|
76
|
+
const found = records.flatMap(record => walk(record));
|
|
77
|
+
return {
|
|
78
|
+
assetIds: new Set(found.filter(row => "id" in row).map(row => row.id)),
|
|
79
|
+
digests: new Set(
|
|
80
|
+
found.filter(row => "digest" in row).map(row => row.digest)
|
|
81
|
+
),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Two pin sets as one.
|
|
87
|
+
* @param {{assetIds: Set<number>, digests: Set<string>}} a - Pins.
|
|
88
|
+
* @param {{assetIds: Set<number>, digests: Set<string>}} b - More pins.
|
|
89
|
+
* @returns {{assetIds: Set<number>, digests: Set<string>}} Their union.
|
|
90
|
+
*/
|
|
91
|
+
export function mergePins(a, b) {
|
|
92
|
+
return {
|
|
93
|
+
assetIds: new Set([...a.assetIds, ...b.assetIds]),
|
|
94
|
+
digests: new Set([...a.digests, ...b.digests]),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Whether a record depends on a file, by its asset id or its sha256.
|
|
100
|
+
* @param {{assetIds: Set<number>, digests: Set<string>}} pins - Pins.
|
|
101
|
+
* @param {number} id - Asset id.
|
|
102
|
+
* @param {string} sha - The file's sha256.
|
|
103
|
+
* @returns {boolean} True when the file is pinned.
|
|
104
|
+
*/
|
|
105
|
+
export function isPinned(pins, id, sha) {
|
|
106
|
+
return pins.assetIds.has(id) || pins.digests.has(sha);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The sha256 GitHub reports for an asset, or null when it reports none.
|
|
111
|
+
* @param {{digest?: string|null}} asset - Native release-asset metadata.
|
|
112
|
+
* @returns {string|null} Lowercase hex digest.
|
|
113
|
+
*/
|
|
114
|
+
export function reportedSha256(asset) {
|
|
115
|
+
const match = /^sha256:([0-9a-f]{64})$/i.exec(asset?.digest ?? "");
|
|
116
|
+
return match ? match[1].toLowerCase() : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Upload time in ms; a listing row without one is an incomplete listing. */
|
|
120
|
+
function uploadedAt(asset) {
|
|
121
|
+
const time = Date.parse(asset.created_at);
|
|
122
|
+
if (!Number.isFinite(time))
|
|
123
|
+
throw new EvidencePruneError(
|
|
124
|
+
`The file listing is incomplete: ${JSON.stringify(asset.name)} has no upload time. Nothing was changed.`
|
|
125
|
+
);
|
|
126
|
+
return time;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Why one file stays, or `candidate` when it may move.
|
|
131
|
+
*
|
|
132
|
+
* A file GitHub reported no digest for is hashed only when the time rules
|
|
133
|
+
* already make it a candidate, so the `pinned` count is a lower bound when
|
|
134
|
+
* digests are missing: a sha-pinned file the time rules keep anyway is counted
|
|
135
|
+
* as `kept`. Safety is unaffected — no file is a candidate without its sha256
|
|
136
|
+
* being checked against every pin.
|
|
137
|
+
*/
|
|
138
|
+
function classify(asset, context) {
|
|
139
|
+
if (COMPLETION_RECORD.test(asset.name)) return "pinned";
|
|
140
|
+
if (context.pins.assetIds.has(asset.id)) return "pinned";
|
|
141
|
+
const time = uploadedAt(asset);
|
|
142
|
+
const eligible =
|
|
143
|
+
context.newest !== null && time < context.newest && time < context.cutoff;
|
|
144
|
+
const sha = reportedSha256(asset) ?? (eligible ? context.hashOf(asset) : "");
|
|
145
|
+
if (context.pins.digests.has(sha)) return "pinned";
|
|
146
|
+
return eligible ? "candidate" : "kept";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Decide which files of one release may be archived and removed.
|
|
151
|
+
*
|
|
152
|
+
* A candidate is unpinned, uploaded before the newest completion record (a
|
|
153
|
+
* newer record has superseded it), and older than `minAgeDays`. A release with
|
|
154
|
+
* no completion record has nothing superseded, so nothing is a candidate.
|
|
155
|
+
* @param {object} input - Planning inputs.
|
|
156
|
+
* @param {string} input.release - The release tag.
|
|
157
|
+
* @param {object[]} input.assets - The complete native asset listing.
|
|
158
|
+
* @param {unknown[]} input.records - Every parsed completion record, from
|
|
159
|
+
* every accepted evidence release.
|
|
160
|
+
* @param {object[]} [input.recordAssets] - Listing rows of those records,
|
|
161
|
+
* whose newest upload time decides what is superseded; defaults to the
|
|
162
|
+
* records inside `assets`.
|
|
163
|
+
* @param {Date} input.now - Run time.
|
|
164
|
+
* @param {number} input.minAgeDays - Minimum candidate age.
|
|
165
|
+
* @param {(asset: object) => string} input.hashOf - sha256 for an asset
|
|
166
|
+
* GitHub reported no digest for; called only when the answer matters.
|
|
167
|
+
* @returns {{release: string, total: number, pinned: number, kept: number,
|
|
168
|
+
* newestRecordAt: string|null, minAgeDays: number,
|
|
169
|
+
* candidates: Array<{id: number, name: string, size: number,
|
|
170
|
+
* created_at: string, sha256: string|null}>}} The plan: counts and the
|
|
171
|
+
* candidates, oldest first.
|
|
172
|
+
*/
|
|
173
|
+
export function planPrune({
|
|
174
|
+
release,
|
|
175
|
+
assets,
|
|
176
|
+
records,
|
|
177
|
+
recordAssets = assets.filter(asset => COMPLETION_RECORD.test(asset.name)),
|
|
178
|
+
now,
|
|
179
|
+
minAgeDays,
|
|
180
|
+
hashOf,
|
|
181
|
+
}) {
|
|
182
|
+
const times = recordAssets.map(uploadedAt);
|
|
183
|
+
const context = {
|
|
184
|
+
pins: collectPins(records),
|
|
185
|
+
newest: times.length ? Math.max(...times) : null,
|
|
186
|
+
cutoff: now.getTime() - minAgeDays * DAY_MS,
|
|
187
|
+
hashOf,
|
|
188
|
+
};
|
|
189
|
+
const rows = assets.map(asset => ({ asset, kind: classify(asset, context) }));
|
|
190
|
+
const count = kind => rows.filter(row => row.kind === kind).length;
|
|
191
|
+
const candidates = rows
|
|
192
|
+
.filter(row => row.kind === "candidate")
|
|
193
|
+
.map(({ asset }) => ({
|
|
194
|
+
id: asset.id,
|
|
195
|
+
name: asset.name,
|
|
196
|
+
size: asset.size,
|
|
197
|
+
created_at: asset.created_at,
|
|
198
|
+
sha256: reportedSha256(asset),
|
|
199
|
+
}))
|
|
200
|
+
.sort(
|
|
201
|
+
(a, b) =>
|
|
202
|
+
Date.parse(a.created_at) - Date.parse(b.created_at) || a.id - b.id
|
|
203
|
+
);
|
|
204
|
+
return {
|
|
205
|
+
release,
|
|
206
|
+
total: assets.length,
|
|
207
|
+
pinned: count("pinned"),
|
|
208
|
+
kept: count("kept"),
|
|
209
|
+
newestRecordAt:
|
|
210
|
+
context.newest === null ? null : new Date(context.newest).toISOString(),
|
|
211
|
+
minAgeDays,
|
|
212
|
+
candidates,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The plain-language report an operator reads.
|
|
218
|
+
* @param {object} report - A plan, plus the repository, archive and outcome.
|
|
219
|
+
* @returns {string[]} Report lines.
|
|
220
|
+
*/
|
|
221
|
+
export function formatReport(report) {
|
|
222
|
+
const verb = report.applied
|
|
223
|
+
? "Archive release"
|
|
224
|
+
: "Archive release (would use)";
|
|
225
|
+
return [
|
|
226
|
+
`Evidence release: ${report.release} (${report.repository})`,
|
|
227
|
+
`Total files: ${report.total}`,
|
|
228
|
+
`Pinned: ${report.pinned} (completion records and files they depend on)`,
|
|
229
|
+
`Kept as recent or not yet superseded: ${report.kept}`,
|
|
230
|
+
`Prune candidates: ${report.candidates.length}`,
|
|
231
|
+
`${verb}: ${report.archiveRelease}`,
|
|
232
|
+
...report.candidates.map(
|
|
233
|
+
row => ` ${row.name} ${row.size} bytes uploaded ${row.created_at}`
|
|
234
|
+
),
|
|
235
|
+
...(report.applied
|
|
236
|
+
? []
|
|
237
|
+
: [
|
|
238
|
+
report.candidates.length
|
|
239
|
+
? "Dry run: nothing was changed. Re-run with --apply to archive these files and then remove them."
|
|
240
|
+
: "Dry run: nothing was changed, and there is nothing to prune.",
|
|
241
|
+
]),
|
|
242
|
+
];
|
|
243
|
+
}
|