@codyswann/lisa 4.101.11 → 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.
Files changed (89) hide show
  1. package/all/copy-overwrite/scripts/lib/completion-proof-github.mjs +5 -2
  2. package/all/copy-overwrite/scripts/lib/evidence-prune-apply.mjs +227 -0
  3. package/all/copy-overwrite/scripts/lib/evidence-prune-config.mjs +165 -0
  4. package/all/copy-overwrite/scripts/lib/evidence-prune-gh.mjs +256 -0
  5. package/all/copy-overwrite/scripts/lib/evidence-prune-records.mjs +101 -0
  6. package/all/copy-overwrite/scripts/lib/evidence-prune.mjs +243 -0
  7. package/all/copy-overwrite/scripts/lisa-evidence-prune.mjs +226 -0
  8. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +1 -1
  9. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  10. package/dist/core/lisa-owned-hash-ledger.js +74 -0
  11. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  12. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  13. package/dist/core/nightly-e2e-guard-behavior-certificate.js.map +1 -1
  14. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  15. package/dist/core/upstream-evidence-manifest.js +29 -4
  16. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  17. package/package.json +4 -4
  18. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  19. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  20. package/plugins/lisa-agy/plugin.json +1 -1
  21. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  22. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  23. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  24. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  25. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  26. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  27. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  28. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  29. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  30. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  31. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  32. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  33. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  34. package/plugins/lisa-expo-agy/plugin.json +1 -1
  35. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  36. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  38. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  39. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  41. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  42. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  43. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  44. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  45. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  46. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  48. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  49. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  50. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  53. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  55. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  56. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
  59. package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
  60. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  62. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  63. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  64. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  66. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  67. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  69. package/plugins/lisa-rails-agy/plugin.json +1 -1
  70. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  71. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  72. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  73. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  74. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  76. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  77. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  78. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  79. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  80. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  81. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  83. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  84. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  85. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  86. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  87. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  88. package/scripts/two-channel-couplings.json +1 -1
  89. package/typescript/copy-overwrite/.prettierignore +6 -0
@@ -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
+ }
@@ -0,0 +1,226 @@
1
+ #!/usr/bin/env node
2
+ // This file is managed by Lisa and IS replaced on each `lisa` run.
3
+ // Do not edit directly — durable changes belong upstream in Lisa.
4
+
5
+ /**
6
+ * @file lisa-evidence-prune.mjs
7
+ * @description Dry-run-first prune for a full completion-proof evidence release.
8
+ *
9
+ * GitHub caps a release at 1000 files, and once the evidence release is full
10
+ * no work item can be marked complete (CodySwannGT/lisa#4692). This command
11
+ * finds evidence files no completion record in any accepted evidence release
12
+ * still depends on, copies each to a monthly archive release, confirms the copy
13
+ * byte-for-byte, re-reads records published meanwhile, and only then deletes
14
+ * the original (CodySwannGT/lisa#4720). By default it only reports; it changes
15
+ * nothing without `--apply`.
16
+ *
17
+ * It is a plain Node script driven through `gh`, so it runs the same under
18
+ * every coding agent Lisa supports and from a terminal or a scheduled job.
19
+ *
20
+ * Usage: node scripts/lisa-evidence-prune.mjs [--apply] [--json]
21
+ * [--release <name>] [--archive-release <name>] [--repo <owner/name>]
22
+ * [--min-age-days <n>]
23
+ * @module lisa-evidence-prune
24
+ */
25
+ import { boundedSpawnSync } from "./lib/bounded-spawn.mjs";
26
+ import {
27
+ acceptedEvidenceReleases,
28
+ evidenceReleaseOverride,
29
+ } from "./lib/completion-proof-github.mjs";
30
+ import {
31
+ archiveReleaseTag,
32
+ collectPins,
33
+ EvidencePruneError,
34
+ formatReport,
35
+ planPrune,
36
+ } from "./lib/evidence-prune.mjs";
37
+ import { applyPrune } from "./lib/evidence-prune-apply.mjs";
38
+ import {
39
+ parseFlags,
40
+ readLisaConfig,
41
+ resolveReleases,
42
+ resolveRepository,
43
+ } from "./lib/evidence-prune-config.mjs";
44
+ import { ghAccess, pruneGitHub } from "./lib/evidence-prune-gh.mjs";
45
+ import {
46
+ evidenceSnapshot,
47
+ recordRescanner,
48
+ } from "./lib/evidence-prune-records.mjs";
49
+ import { invokedAsScript } from "./lib/invoked-as-script.mjs";
50
+
51
+ const USAGE = [
52
+ "Usage: node scripts/lisa-evidence-prune.mjs [options]",
53
+ "",
54
+ "Reports which evidence files no completion record depends on. Nothing changes without --apply.",
55
+ "",
56
+ " --apply Archive each candidate, confirm the copy, then delete the original",
57
+ " --json Print the report as JSON",
58
+ " --release <name> Evidence release to prune (default: the configured one)",
59
+ " --archive-release <name> Archive release (default: <release>-archive-YYYY-MM)",
60
+ " --repo <owner/name> Repository (default: .lisa.config.json, then this checkout)",
61
+ " --min-age-days <n> Keep evidence younger than this many days (default 14)",
62
+ ];
63
+
64
+ const ACCESS_REFUSALS = {
65
+ missing:
66
+ "gh was not found. Install the GitHub CLI (https://cli.github.com), run `gh auth login`, and retry.",
67
+ "signed-out":
68
+ "gh is not signed in to github.com. Run `gh auth login` and retry.",
69
+ };
70
+
71
+ /** The real `gh` runner: bounded, and binary-safe when a download asks. */
72
+ function spawnRun(command, args, options = {}) {
73
+ const result = boundedSpawnSync(command, args, {
74
+ encoding: options.binary ? null : "utf8",
75
+ input: options.input,
76
+ maxBuffer: options.maxBuffer,
77
+ timeout: options.timeout,
78
+ });
79
+ return {
80
+ status: result.status,
81
+ error: result.error,
82
+ stdout: result.stdout ?? (options.binary ? Buffer.alloc(0) : ""),
83
+ stderr: String(result.stderr ?? ""),
84
+ };
85
+ }
86
+
87
+ /** `gh` installed and signed in, then read (and, for --apply, write) access. */
88
+ function requireAccess(flags, deps, config) {
89
+ const access = ghAccess(deps.run);
90
+ if (access !== "ok") throw new EvidencePruneError(ACCESS_REFUSALS[access]);
91
+ const repository = resolveRepository(flags, config, deps.run);
92
+ const gh = pruneGitHub(deps.run, repository);
93
+ const repo = gh.repo();
94
+ if (flags.apply && repo.permissions?.push !== true)
95
+ throw new EvidencePruneError(
96
+ `--apply needs write access to ${repository} to archive and delete release files, and the signed-in gh account does not have it. A dry run (without --apply) needs only read access.`
97
+ );
98
+ return { gh, repo, repository };
99
+ }
100
+
101
+ /** Gather, plan, and (under `--apply`) archive; returns the report. */
102
+ function prune(flags, deps) {
103
+ const config = readLisaConfig(deps.cwd);
104
+ const policy = config.verification?.completion ?? {};
105
+ // Validate the whole evidence-release policy, history included, before any
106
+ // provider call: a malformed list must not surface halfway through a run.
107
+ acceptedEvidenceReleases(policy);
108
+ const pinned = deps.env.LISA_EVIDENCE_RELEASE?.trim();
109
+ const pinnedRelease = pinned
110
+ ? evidenceReleaseOverride(policy, pinned)
111
+ : undefined;
112
+ const { release, archiveRelease } = resolveReleases(
113
+ flags,
114
+ config,
115
+ deps.env,
116
+ deps.now,
117
+ tag => archiveReleaseTag(tag, deps.now)
118
+ );
119
+ const { gh, repo, repository } = requireAccess(flags, deps, config);
120
+ const snapshot = evidenceSnapshot(gh, policy, release);
121
+ if (!snapshot)
122
+ throw new EvidencePruneError(
123
+ `The evidence release ${release} was not found in ${repository}. Nothing was changed; check the name, or pass --release <name>.`
124
+ );
125
+ const plan = planPrune({
126
+ release,
127
+ assets: snapshot.assets,
128
+ records: snapshot.records,
129
+ recordAssets: snapshot.recordAssets,
130
+ now: deps.now,
131
+ minAgeDays: flags.minAgeDays,
132
+ hashOf: gh.sha256,
133
+ });
134
+ const report = {
135
+ ...plan,
136
+ repository,
137
+ archiveRelease,
138
+ applied: Boolean(flags.apply),
139
+ };
140
+ if (!flags.apply) return report;
141
+ return {
142
+ ...report,
143
+ ...applyPrune(gh, plan.candidates, {
144
+ tag: archiveRelease,
145
+ branch: repo.default_branch,
146
+ release,
147
+ pins: collectPins(snapshot.records),
148
+ known: new Set(snapshot.recordAssets.map(asset => asset.id)),
149
+ rescan: recordRescanner(gh, policy, snapshot.accepted, {
150
+ pinned: pinnedRelease,
151
+ }),
152
+ }),
153
+ };
154
+ }
155
+
156
+ /** A heading with its count, then one indented line per entry. */
157
+ function section(heading, entries) {
158
+ return [`${heading}: ${entries.length}`, ...entries.map(row => ` ${row}`)];
159
+ }
160
+
161
+ /** What `--apply` did, in words. */
162
+ function outcomeLines(report) {
163
+ if (!report.applied) return [];
164
+ const archive = report.archiveRelease;
165
+ return [
166
+ `Archived to ${archive} and removed: ${report.archived.length}`,
167
+ ...(report.skipped.length
168
+ ? section(
169
+ "Skipped",
170
+ report.skipped.map(row => row.reason)
171
+ )
172
+ : []),
173
+ ...(report.archivedNotDeleted.length
174
+ ? section(
175
+ `Archived to ${archive} but not removed`,
176
+ report.archivedNotDeleted
177
+ )
178
+ : []),
179
+ ...(report.error
180
+ ? [
181
+ `Stopped: ${report.error}`,
182
+ ...section(
183
+ `Not archived (still in ${report.release})`,
184
+ report.notArchived
185
+ ),
186
+ ]
187
+ : []),
188
+ ];
189
+ }
190
+
191
+ /**
192
+ * Run the prune.
193
+ * @param {string[]} [args] - Command-line arguments.
194
+ * @param {object} [deps] - Injected for tests: `run`, `now`, `cwd`, `env`, `out`.
195
+ * @returns {Promise<number>} Exit code: 0 on success, 1 on any refusal or stop.
196
+ */
197
+ export async function main(args = process.argv.slice(2), deps = {}) {
198
+ const out = deps.out ?? (line => console.log(line));
199
+ const err = deps.out ?? (line => console.error(line));
200
+ const json = args.includes("--json");
201
+ try {
202
+ const flags = parseFlags(args);
203
+ if (flags.help) {
204
+ USAGE.forEach(line => out(line));
205
+ return 0;
206
+ }
207
+ const report = prune(flags, {
208
+ run: deps.run ?? spawnRun,
209
+ now: deps.now ?? new Date(),
210
+ cwd: deps.cwd ?? process.cwd(),
211
+ env: deps.env ?? process.env,
212
+ });
213
+ const lines = json
214
+ ? [JSON.stringify(report, null, 2)]
215
+ : [...formatReport(report), ...outcomeLines(report)];
216
+ lines.forEach(line => (report.error ? err(line) : out(line)));
217
+ return report.error ? 1 : 0;
218
+ } catch (error) {
219
+ err(
220
+ json ? JSON.stringify({ error: error.message }, null, 2) : error.message
221
+ );
222
+ return 1;
223
+ }
224
+ }
225
+
226
+ if (invokedAsScript(import.meta.url)) process.exitCode = await main();
@@ -119,7 +119,7 @@
119
119
  "children": []
120
120
  },
121
121
  "lib/completion-proof-github.mjs": {
122
- "sha256": "e8152fec3b77c3d9b79358f7972b60e4ea0d0ed32618aff614bc787875ddfb92",
122
+ "sha256": "82ef0da12fc5c31fc48237808f94cbfd73f0d2128ae1da18ceedcea90284d467",
123
123
  "staticImports": [
124
124
  "lib/completion-proof-shape.mjs"
125
125
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"lisa-owned-hash-ledger.d.ts","sourceRoot":"","sources":["../../src/core/lisa-owned-hash-ledger.ts"],"names":[],"mappings":"AACA,6EAA6E;AAE7E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAC3C,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAm2EjC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CACpD,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAswEjC,CAAC"}
1
+ {"version":3,"file":"lisa-owned-hash-ledger.d.ts","sourceRoot":"","sources":["../../src/core/lisa-owned-hash-ledger.ts"],"names":[],"mappings":"AACA,6EAA6E;AAE7E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAC3C,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAw4EjC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CACpD,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CA2yEjC,CAAC"}