@codyswann/lisa 4.101.11 → 4.102.1
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-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/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/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +31 -5
- 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/copy-overwrite/scripts/check-skipped-required-checks.mjs +143 -15
|
@@ -34,9 +34,12 @@ const ACCEPTED_KEY = "verification.completion.acceptedEvidenceReleases";
|
|
|
34
34
|
/**
|
|
35
35
|
* Whether a concrete name is a tag GitHub and git both accept: the character
|
|
36
36
|
* set and length, and none of git's ref-name exclusions that the character set
|
|
37
|
-
* still lets through (`..`, a trailing `.`, a `.lock` ending).
|
|
37
|
+
* still lets through (`..`, a trailing `.`, a `.lock` ending). Exported so the
|
|
38
|
+
* evidence prune validates its archive release by the same rule (#4720).
|
|
39
|
+
* @param {string} name - A concrete release name.
|
|
40
|
+
* @returns {boolean} True when the name is a usable tag.
|
|
38
41
|
*/
|
|
39
|
-
function usableTag(name) {
|
|
42
|
+
export function usableTag(name) {
|
|
40
43
|
return (
|
|
41
44
|
RELEASE_TAG.test(name) &&
|
|
42
45
|
!name.includes("..") &&
|
|
@@ -0,0 +1,227 @@
|
|
|
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 `--apply` half of the evidence prune: copy, confirm, and only then delete.
|
|
6
|
+
*
|
|
7
|
+
* Each candidate is downloaded, uploaded to the archive release under the same
|
|
8
|
+
* name, read back, and compared by sha256. Just before the delete, completion
|
|
9
|
+
* records published since the plan was made are read, so a record that came to
|
|
10
|
+
* depend on the file mid-run keeps it. The original is deleted only after both
|
|
11
|
+
* checks pass, so a failed or corrupted copy can never cost the only copy of a
|
|
12
|
+
* file, and the first failure stops the run (CodySwannGT/lisa#4720).
|
|
13
|
+
* @module scripts/lib/evidence-prune-apply
|
|
14
|
+
*/
|
|
15
|
+
import {
|
|
16
|
+
EVIDENCE_RELEASE_ASSET_LIMIT,
|
|
17
|
+
EVIDENCE_RELEASE_NEAR_FULL,
|
|
18
|
+
} from "./completion-proof-github.mjs";
|
|
19
|
+
import {
|
|
20
|
+
collectPins,
|
|
21
|
+
EvidencePruneError,
|
|
22
|
+
isPinned,
|
|
23
|
+
mergePins,
|
|
24
|
+
reportedSha256,
|
|
25
|
+
} from "./evidence-prune.mjs";
|
|
26
|
+
import { hashBytes } from "./evidence-prune-gh.mjs";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The exact refusal an operator reads when the archive has no room left.
|
|
30
|
+
* @param {string} tag - Archive release tag.
|
|
31
|
+
* @returns {string} The message.
|
|
32
|
+
*/
|
|
33
|
+
export function nearlyFullMessage(tag) {
|
|
34
|
+
return `Archive release ${tag} is nearly full (${EVIDENCE_RELEASE_NEAR_FULL} of GitHub's ${EVIDENCE_RELEASE_ASSET_LIMIT}-file limit); re-run next month or pass --archive-release <name>.`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The archive release, created from the default branch when absent. */
|
|
38
|
+
function openArchive(gh, tag, branch) {
|
|
39
|
+
const existing = gh.release(tag);
|
|
40
|
+
if (existing) return existing;
|
|
41
|
+
gh.createRelease(tag, branch);
|
|
42
|
+
const created = gh.release(tag);
|
|
43
|
+
if (!created)
|
|
44
|
+
throw new EvidencePruneError(
|
|
45
|
+
`The archive release ${tag} was created but cannot be read back; nothing was archived.`
|
|
46
|
+
);
|
|
47
|
+
return created;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Refuse a copy whose bytes differ, naming the file and both hashes. */
|
|
51
|
+
function requireSame(name, expected, actual, where) {
|
|
52
|
+
if (expected !== actual)
|
|
53
|
+
throw new EvidencePruneError(
|
|
54
|
+
`${where} of ${name} does not match the original (original sha256 ${expected}, ${where.toLowerCase()} sha256 ${actual}); the original was not deleted.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Read the archive copy back and require the original's exact bytes.
|
|
60
|
+
*
|
|
61
|
+
* The copy is downloaded and hashed rather than trusted by its reported
|
|
62
|
+
* `digest`: the digest is GitHub's claim about the bytes, and the only copy of
|
|
63
|
+
* a file is about to be deleted on the strength of this check. When a digest
|
|
64
|
+
* is reported it must agree as well.
|
|
65
|
+
*/
|
|
66
|
+
function confirmCopy(gh, candidate, copy, sha) {
|
|
67
|
+
const readBack = gh.asset(copy.id);
|
|
68
|
+
if (readBack?.name !== candidate.name || readBack.state !== "uploaded")
|
|
69
|
+
throw new EvidencePruneError(
|
|
70
|
+
`The archive copy of ${candidate.name} cannot be read back as an uploaded file; the original was not deleted.`
|
|
71
|
+
);
|
|
72
|
+
requireSame(
|
|
73
|
+
candidate.name,
|
|
74
|
+
sha,
|
|
75
|
+
hashBytes(gh.download(readBack)),
|
|
76
|
+
"The archive copy"
|
|
77
|
+
);
|
|
78
|
+
const reported = reportedSha256(readBack);
|
|
79
|
+
if (reported)
|
|
80
|
+
requireSame(candidate.name, sha, reported, "The archive copy's digest");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The state after leaving one candidate where it is, with the reason. */
|
|
84
|
+
function skip(state, candidate, reason) {
|
|
85
|
+
return {
|
|
86
|
+
...state,
|
|
87
|
+
skipped: [...state.skipped, { name: candidate.name, reason }],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Pins with every record published since the last read folded in. */
|
|
92
|
+
function repin(ctx, state) {
|
|
93
|
+
const fresh = ctx.rescan(state.known);
|
|
94
|
+
return {
|
|
95
|
+
...state,
|
|
96
|
+
pins: mergePins(state.pins, collectPins(fresh.records)),
|
|
97
|
+
known: new Set([...state.known, ...fresh.ids]),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Delete the original; a failure here leaves a confirmed archive copy. */
|
|
102
|
+
function removeOriginal(ctx, state, candidate) {
|
|
103
|
+
try {
|
|
104
|
+
ctx.gh.remove(candidate);
|
|
105
|
+
return { ...state, archived: [...state.archived, candidate.name] };
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return {
|
|
108
|
+
...state,
|
|
109
|
+
archivedNotDeleted: [...state.archivedNotDeleted, candidate.name],
|
|
110
|
+
error: error.message,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Archive one candidate, confirm it, re-check its pins, then delete it.
|
|
117
|
+
* @param {object} ctx - Run context: `gh`, `archive`, `held`, `tag`,
|
|
118
|
+
* `release` and `rescan`.
|
|
119
|
+
* @param {object} state - Outcome so far, archive count and current pins.
|
|
120
|
+
* @param {object} candidate - The file to move.
|
|
121
|
+
* @returns {object} The next state.
|
|
122
|
+
*/
|
|
123
|
+
function archiveStep(ctx, state, candidate) {
|
|
124
|
+
const { gh, held, tag, release } = ctx;
|
|
125
|
+
const prior = held.get(candidate.name);
|
|
126
|
+
// An interrupted upload leaves an asset GitHub never finished; it cannot be
|
|
127
|
+
// hashed or replaced, and deleting it is the operator's call, not ours.
|
|
128
|
+
if (prior && prior.state !== "uploaded")
|
|
129
|
+
throw new EvidencePruneError(
|
|
130
|
+
`${candidate.name} in ${tag} is a half-finished upload (state ${JSON.stringify(prior.state)}); delete it from ${tag} and re-run.`
|
|
131
|
+
);
|
|
132
|
+
if (!prior && state.count >= EVIDENCE_RELEASE_NEAR_FULL)
|
|
133
|
+
throw new EvidencePruneError(nearlyFullMessage(tag));
|
|
134
|
+
const bytes = gh.download(candidate);
|
|
135
|
+
const sha = hashBytes(bytes);
|
|
136
|
+
if (candidate.sha256)
|
|
137
|
+
requireSame(candidate.name, candidate.sha256, sha, "The download");
|
|
138
|
+
// post-evidence.sh reuses names such as `pr-<N>-<file>` with --clobber, so a
|
|
139
|
+
// same-named archive file may be a different file, not an earlier copy.
|
|
140
|
+
if (prior && gh.sha256(prior) !== sha)
|
|
141
|
+
return skip(
|
|
142
|
+
state,
|
|
143
|
+
candidate,
|
|
144
|
+
`a different file named ${candidate.name} is already in ${tag}; kept in ${release}`
|
|
145
|
+
);
|
|
146
|
+
const copy = prior ?? gh.upload(ctx.archive, candidate.name, bytes);
|
|
147
|
+
confirmCopy(gh, candidate, copy, sha);
|
|
148
|
+
const next = repin(ctx, { ...state, count: state.count + (prior ? 0 : 1) });
|
|
149
|
+
if (isPinned(next.pins, candidate.id, sha))
|
|
150
|
+
return skip(
|
|
151
|
+
next,
|
|
152
|
+
candidate,
|
|
153
|
+
`${candidate.name}: a completion record published during this run now depends on it; kept in ${release}, and its archive copy stays in ${tag}`
|
|
154
|
+
);
|
|
155
|
+
return removeOriginal(ctx, next, candidate);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** One reducer step: nothing more happens once a step has failed. */
|
|
159
|
+
function step(ctx, state, candidate) {
|
|
160
|
+
if (state.error) return state;
|
|
161
|
+
try {
|
|
162
|
+
return archiveStep(ctx, state, candidate);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return { ...state, error: error.message };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Archive and delete every candidate in order, stopping at the first failure.
|
|
170
|
+
* @param {object} gh - The prune's GitHub operations.
|
|
171
|
+
* @param {object[]} candidates - The plan's ordered candidates.
|
|
172
|
+
* @param {object} target - Archive selection and pin sources.
|
|
173
|
+
* @param {string} target.tag - Archive release tag.
|
|
174
|
+
* @param {string} target.branch - Default branch the archive is created from.
|
|
175
|
+
* @param {string} target.release - The release being pruned.
|
|
176
|
+
* @param {object} target.pins - Pins from the snapshot's records.
|
|
177
|
+
* @param {Set<number>} target.known - Record asset ids already read.
|
|
178
|
+
* @param {Function} target.rescan - Reads records published since `known`.
|
|
179
|
+
* @returns {object} `archived`, `archivedNotDeleted`, `skipped`,
|
|
180
|
+
* `notArchived` and `error`.
|
|
181
|
+
*/
|
|
182
|
+
export function applyPrune(gh, candidates, target) {
|
|
183
|
+
const start = {
|
|
184
|
+
archived: [],
|
|
185
|
+
archivedNotDeleted: [],
|
|
186
|
+
skipped: [],
|
|
187
|
+
error: null,
|
|
188
|
+
pins: target.pins,
|
|
189
|
+
known: target.known,
|
|
190
|
+
};
|
|
191
|
+
const outcome = (() => {
|
|
192
|
+
if (candidates.length === 0) return start;
|
|
193
|
+
try {
|
|
194
|
+
const archive = openArchive(gh, target.tag, target.branch);
|
|
195
|
+
const listed = gh.assets(archive);
|
|
196
|
+
const ctx = {
|
|
197
|
+
...target,
|
|
198
|
+
gh,
|
|
199
|
+
archive,
|
|
200
|
+
held: new Map(listed.map(asset => [asset.name, asset])),
|
|
201
|
+
};
|
|
202
|
+
return candidates.reduce(
|
|
203
|
+
(state, candidate) => step(ctx, state, candidate),
|
|
204
|
+
{
|
|
205
|
+
...start,
|
|
206
|
+
count: listed.length,
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
return { ...start, error: error.message };
|
|
211
|
+
}
|
|
212
|
+
})();
|
|
213
|
+
const handled = new Set([
|
|
214
|
+
...outcome.archived,
|
|
215
|
+
...outcome.archivedNotDeleted,
|
|
216
|
+
...outcome.skipped.map(row => row.name),
|
|
217
|
+
]);
|
|
218
|
+
return {
|
|
219
|
+
archived: outcome.archived,
|
|
220
|
+
archivedNotDeleted: outcome.archivedNotDeleted,
|
|
221
|
+
skipped: outcome.skipped,
|
|
222
|
+
notArchived: candidates
|
|
223
|
+
.map(row => row.name)
|
|
224
|
+
.filter(name => !handled.has(name)),
|
|
225
|
+
error: outcome.error,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
* Inputs for the evidence prune: its flags, the project's Lisa config, which
|
|
6
|
+
* release to prune, and which repository it lives in.
|
|
7
|
+
*
|
|
8
|
+
* The release is resolved exactly as `lisa-work-item.mjs evidence-release`
|
|
9
|
+
* resolves it — `--release`, then `LISA_EVIDENCE_RELEASE`, then the configured
|
|
10
|
+
* `verification.completion.evidenceRelease` — through the one shared resolver,
|
|
11
|
+
* so the prune always reads the release new evidence is written to
|
|
12
|
+
* (CodySwannGT/lisa#4692, #4720).
|
|
13
|
+
* @module scripts/lib/evidence-prune-config
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
evidenceReleaseOverride,
|
|
20
|
+
resolveEvidenceRelease,
|
|
21
|
+
usableTag,
|
|
22
|
+
} from "./completion-proof-github.mjs";
|
|
23
|
+
import { DEFAULT_MIN_AGE_DAYS, EvidencePruneError } from "./evidence-prune.mjs";
|
|
24
|
+
|
|
25
|
+
const VALUE_FLAGS = new Map([
|
|
26
|
+
["--release", "release"],
|
|
27
|
+
["--archive-release", "archiveRelease"],
|
|
28
|
+
["--repo", "repo"],
|
|
29
|
+
["--min-age-days", "minAgeDays"],
|
|
30
|
+
]);
|
|
31
|
+
const SWITCHES = new Map([
|
|
32
|
+
["--apply", "apply"],
|
|
33
|
+
["--json", "json"],
|
|
34
|
+
["--help", "help"],
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Parse the prune's command line; an unknown or valueless flag is refused.
|
|
39
|
+
* @param {string[]} args - Arguments after the script name.
|
|
40
|
+
* @returns {object} Parsed options.
|
|
41
|
+
*/
|
|
42
|
+
export function parseFlags(args) {
|
|
43
|
+
const parse = (index, flags) => {
|
|
44
|
+
if (index >= args.length) return flags;
|
|
45
|
+
const arg = args[index];
|
|
46
|
+
if (SWITCHES.has(arg))
|
|
47
|
+
return parse(index + 1, { ...flags, [SWITCHES.get(arg)]: true });
|
|
48
|
+
const value = args[index + 1];
|
|
49
|
+
if (!VALUE_FLAGS.has(arg) || value === undefined || value.startsWith("--"))
|
|
50
|
+
throw new EvidencePruneError(
|
|
51
|
+
`Unrecognised argument ${JSON.stringify(arg)}. Run with --help for the options.`
|
|
52
|
+
);
|
|
53
|
+
// An empty operand must not fall through to a default: `--release ""`
|
|
54
|
+
// would silently prune the configured release, and Number("") is 0.
|
|
55
|
+
if (value.trim() === "")
|
|
56
|
+
throw new EvidencePruneError(
|
|
57
|
+
`${arg} needs a value; it was given an empty one. Run with --help for the options.`
|
|
58
|
+
);
|
|
59
|
+
return parse(index + 2, { ...flags, [VALUE_FLAGS.get(arg)]: value });
|
|
60
|
+
};
|
|
61
|
+
const flags = parse(0, {});
|
|
62
|
+
const days = Number(flags.minAgeDays ?? DEFAULT_MIN_AGE_DAYS);
|
|
63
|
+
if (!Number.isInteger(days) || days < 0)
|
|
64
|
+
throw new EvidencePruneError(
|
|
65
|
+
`--min-age-days must be a whole number of days, not ${JSON.stringify(flags.minAgeDays)}.`
|
|
66
|
+
);
|
|
67
|
+
return { ...flags, minAgeDays: days };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A JSON file, or `{}` when it is absent; unreadable config is a refusal. */
|
|
71
|
+
function readJson(file) {
|
|
72
|
+
if (!existsSync(file)) return {};
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
75
|
+
} catch {
|
|
76
|
+
throw new EvidencePruneError(
|
|
77
|
+
`${file} is not valid JSON; fix it and retry.`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Objects merge key by key; anything else in `override` replaces `base`. */
|
|
83
|
+
function merge(base, override) {
|
|
84
|
+
const plain = value =>
|
|
85
|
+
value && typeof value === "object" && !Array.isArray(value);
|
|
86
|
+
if (!plain(base) || !plain(override)) return override ?? base;
|
|
87
|
+
return Object.fromEntries(
|
|
88
|
+
[...new Set([...Object.keys(base), ...Object.keys(override)])].map(key => [
|
|
89
|
+
key,
|
|
90
|
+
key in override ? merge(base[key], override[key]) : base[key],
|
|
91
|
+
])
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The project's Lisa config, with `.lisa.config.local.json` layered on top.
|
|
97
|
+
* @param {string} cwd - Project root.
|
|
98
|
+
* @returns {object} Effective config.
|
|
99
|
+
*/
|
|
100
|
+
export function readLisaConfig(cwd) {
|
|
101
|
+
return merge(
|
|
102
|
+
readJson(join(cwd, ".lisa.config.json")),
|
|
103
|
+
readJson(join(cwd, ".lisa.config.local.json"))
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The release to prune and the archive it moves into.
|
|
109
|
+
* @param {object} flags - Parsed flags.
|
|
110
|
+
* @param {object} config - Effective Lisa config.
|
|
111
|
+
* @param {object} env - Process environment.
|
|
112
|
+
* @param {Date} now - Run time.
|
|
113
|
+
* @param {(release: string) => string} archiveFor - Default archive name.
|
|
114
|
+
* @returns {{release: string, archiveRelease: string}} Concrete tags.
|
|
115
|
+
*/
|
|
116
|
+
export function resolveReleases(flags, config, env, now, archiveFor) {
|
|
117
|
+
const policy = config.verification?.completion ?? {};
|
|
118
|
+
const pinned = env.LISA_EVIDENCE_RELEASE?.trim();
|
|
119
|
+
const release = flags.release
|
|
120
|
+
? evidenceReleaseOverride(policy, flags.release, "--release")
|
|
121
|
+
: pinned
|
|
122
|
+
? evidenceReleaseOverride(policy, pinned)
|
|
123
|
+
: resolveEvidenceRelease(policy, now);
|
|
124
|
+
const archiveRelease = flags.archiveRelease ?? archiveFor(release);
|
|
125
|
+
if (usableTag(archiveRelease) && archiveRelease !== release)
|
|
126
|
+
return { release, archiveRelease };
|
|
127
|
+
if (flags.archiveRelease)
|
|
128
|
+
throw new EvidencePruneError(
|
|
129
|
+
`--archive-release ${JSON.stringify(archiveRelease)} is not usable: name a different release using letters, digits, ".", "_" or "-".`
|
|
130
|
+
);
|
|
131
|
+
throw new EvidencePruneError(
|
|
132
|
+
`The archive release name made from ${release} (${archiveRelease}) is not a usable GitHub release name; it is likely over 100 characters. Name a shorter archive release explicitly (see --help).`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* `owner/name` from `--repo`, then the Lisa config, then the checkout's remote.
|
|
138
|
+
* @param {object} flags - Parsed flags.
|
|
139
|
+
* @param {object} config - Effective Lisa config.
|
|
140
|
+
* @param {Function} run - Child-process runner.
|
|
141
|
+
* @returns {string} The repository.
|
|
142
|
+
*/
|
|
143
|
+
export function resolveRepository(flags, config, run) {
|
|
144
|
+
const configured =
|
|
145
|
+
config.github?.org && config.github?.repo
|
|
146
|
+
? `${config.github.org}/${config.github.repo}`
|
|
147
|
+
: undefined;
|
|
148
|
+
const viewed = () => {
|
|
149
|
+
const result = run("gh", ["repo", "view", "--json", "nameWithOwner"], {});
|
|
150
|
+
try {
|
|
151
|
+
return result.status === 0
|
|
152
|
+
? JSON.parse(result.stdout).nameWithOwner
|
|
153
|
+
: undefined;
|
|
154
|
+
} catch {
|
|
155
|
+
// probe-direction: fail-closed — an unreadable `gh repo view` leaves no repository, and the caller refuses to run rather than guessing one.
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const repository = flags.repo ?? configured ?? viewed();
|
|
160
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(repository ?? ""))
|
|
161
|
+
throw new EvidencePruneError(
|
|
162
|
+
"Could not tell which GitHub repository holds the evidence. Pass --repo <owner/name>, or set github.org and github.repo in .lisa.config.json."
|
|
163
|
+
);
|
|
164
|
+
return repository;
|
|
165
|
+
}
|
|
@@ -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
|
+
}
|