@codyswann/lisa 4.42.3 → 4.42.4

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 (64) hide show
  1. package/all/copy-overwrite/scripts/check-conflict-markers.mjs +24 -1
  2. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  3. package/dist/core/lisa-owned-hash-ledger.js +4 -0
  4. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  5. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  6. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  7. package/dist/core/upstream-evidence-manifest.js +5 -2
  8. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  9. package/package.json +6 -5
  10. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  11. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  12. package/plugins/lisa/rules/reference/falsifiable-checks.md +20 -0
  13. package/plugins/lisa-agy/plugin.json +1 -1
  14. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  15. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  16. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  17. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  18. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  19. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  20. package/plugins/lisa-copilot/rules/reference/falsifiable-checks.md +20 -0
  21. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  22. package/plugins/lisa-cursor/rules/falsifiable-checks-reference.mdc +20 -0
  23. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  24. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  25. package/plugins/lisa-expo-agy/plugin.json +1 -1
  26. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  27. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  28. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  29. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  30. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  31. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  32. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  33. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  34. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  35. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  36. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  38. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  39. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  40. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  41. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  43. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  44. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  45. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  46. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  49. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  50. package/plugins/lisa-rails-agy/plugin.json +1 -1
  51. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  53. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  55. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  56. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  59. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  60. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  61. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  63. package/plugins/src/base/rules/reference/falsifiable-checks.md +20 -0
  64. package/scripts/check-empty-subject-guards.mjs +366 -0
@@ -0,0 +1,366 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * check-empty-subject-guards — refuse a guard that prints a success line when
4
+ * its comparison had no subject (CodySwannGT/lisa#3888).
5
+ *
6
+ * ## The defect
7
+ *
8
+ * Not "the guard is wrong". The guard did not run against anything, and said
9
+ * OK:
10
+ *
11
+ * ```
12
+ * ✓ no leftover conflict markers in 0 tracked files
13
+ * ```
14
+ *
15
+ * That line is a REQUIRED push gate reporting on bytes nobody read. The count
16
+ * was in hand the whole time and the guard did not read it, so an empty
17
+ * subject set and a satisfied comparison render identically. The same shape
18
+ * has produced a type gate that compiled 0 of 1375 test files and reported
19
+ * success, a gate runner that recorded PASSED off an exit code alone, and a
20
+ * review gate that went green off a review that never started.
21
+ *
22
+ * The acceptance criterion is the one #3888 states: **a guard that emits a
23
+ * success line must be able to say what it examined, and must fail closed when
24
+ * that count is zero.** A subject count of zero is not a pass.
25
+ *
26
+ * ## Why this is measured by RUNNING the guards, not by reading them
27
+ *
28
+ * A static sweep would have to recognise "a subject collection" across thirty
29
+ * hand-written scripts, and a heuristic that misses one reports a clean tree —
30
+ * which is the very failure being swept for. Executing the guard asks the
31
+ * question directly and cannot be satisfied by a shape.
32
+ *
33
+ * The subject-free input is an **empty git repository**: every guard here
34
+ * enumerates something out of a tree, and a tree with nothing in it is the
35
+ * cheapest honest way to hand one an empty subject set. Both the root argument
36
+ * and the working directory point at it, so a guard that ignores its `--root`
37
+ * and anchors on `process.cwd()` still sees the empty tree rather than this
38
+ * repository.
39
+ *
40
+ * ## What counts as a finding
41
+ *
42
+ * Exit 0 **and** a success marker in the output. Both halves are load-bearing:
43
+ *
44
+ * - Exit 0 alone is not a finding. A guard may legitimately have nothing to
45
+ * do, and two here say exactly that — `check-state-classification` reports
46
+ * `not-adopted` and `check-merge-driver-registration` reports "nothing to
47
+ * register". Neither claims a check was satisfied; both STATE that their
48
+ * subject was absent, which is the criterion met rather than violated.
49
+ * - A success marker alone is not a finding either: a guard is free to print
50
+ * a tick for the sub-checks that did pass on its way to a non-zero exit.
51
+ *
52
+ * So the finding is precisely "printed OK, and exited as though it meant it".
53
+ * There is no allowlist and no roster of excuse words — the discriminator is
54
+ * the guard's own verdict vocabulary.
55
+ *
56
+ * ## Declared blind spots
57
+ *
58
+ * Stated rather than hidden, in the manner of the sibling sweeps:
59
+ *
60
+ * - A guard that declares no root override cannot be pointed at an empty
61
+ * tree, so it is COUNTED and NAMED in the report but not probed. That
62
+ * population is where an unmeasured instance would hide, which is why the
63
+ * count is printed rather than silently dropped: a guard leaving the probed
64
+ * population shows up as that number rising.
65
+ * - A guard whose subject set is not a tree — a queue read over the network,
66
+ * a process list — is out of reach of this input even when it is
67
+ * root-scoped. It will refuse for a reason unrelated to emptiness, and that
68
+ * refusal is accepted here.
69
+ * - Only the FIRST accepted probe form decides. A guard taking both `--root`
70
+ * and a positional root is probed once.
71
+ *
72
+ * ## Why it fails at zero probed
73
+ *
74
+ * An empty inspection and a clean tree print the same tick — the defect this
75
+ * module exists for, applied to this module. The count of guards actually
76
+ * probed is part of the report, and a count of zero is exit 2 rather than
77
+ * exit 0. A directory that does not exist, a `--guards-root` pointed
78
+ * somewhere wrong, and a discovery pattern that stopped matching all reach
79
+ * that branch.
80
+ *
81
+ * Determinism: Node built-ins only, no network, no clock, no `Math.random`.
82
+ * Children run under a deadline, so a hung guard is a throw rather than a
83
+ * verdict. The discovery root is a parameter so the suite can point it at a
84
+ * fixture tree holding a known offender.
85
+ *
86
+ * CLI:
87
+ * node scripts/check-empty-subject-guards.mjs [--json] [--guards-root <dir>]
88
+ *
89
+ * The flag is `--guards-root` and NOT `--root`, deliberately: `--root` is the
90
+ * token this sweep reads out of other guards' headers to decide they are
91
+ * probeable, and a sweep that probed itself would recurse.
92
+ *
93
+ * Exit codes (mirroring the sibling check-* scripts):
94
+ * 0 — guards were probed and none reported success on an empty tree.
95
+ * 1 — >=1 guard printed a success line and exited 0 having examined nothing.
96
+ * 2 — operational error: unknown flag, unreadable root, `git` unavailable,
97
+ * or ZERO guards probed.
98
+ *
99
+ * @module scripts/check-empty-subject-guards
100
+ */
101
+ import { mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs";
102
+ import { tmpdir } from "node:os";
103
+ import path from "node:path";
104
+ import process from "node:process";
105
+
106
+ import { boundedSpawnSync } from "./lib/bounded-spawn.mjs";
107
+ import { invokedAsScript } from "./lib/invoked-as-script.mjs";
108
+
109
+ /**
110
+ * Directory names holding guard scripts, relative to the discovery root.
111
+ *
112
+ * `scripts` is this repository's own lane; `<stack>/copy-overwrite/scripts` is
113
+ * the delivered lane, and it is derived by reading the top level rather than
114
+ * listed, so a new stack directory joins the population on the day it appears.
115
+ */
116
+ const GUARD_DIRECTORY = "scripts";
117
+
118
+ /** The delivery lane a stack directory holds its guard scripts in. */
119
+ const DELIVERED_LANE = path.join("copy-overwrite", "scripts");
120
+
121
+ /** Guard scripts are named `check-*.mjs`; nothing else in those lanes is one. */
122
+ const GUARD_FILE = /^check-.+\.mjs$/;
123
+
124
+ /** Bytes of a guard's header scanned for its declared CLI. */
125
+ const HEADER_BYTES = 8000;
126
+
127
+ /** A guard's declared root override, in the order the probe tries them. */
128
+ const ROOT_FORMS = Object.freeze([
129
+ { flag: "--root", token: "--root" },
130
+ { flag: null, token: "[root]" },
131
+ { flag: null, token: "[rootDir]" },
132
+ ]);
133
+
134
+ /**
135
+ * Verdict vocabulary: what a guard prints when it means "this check passed".
136
+ *
137
+ * Deliberately narrow. A guard reporting that its subject was ABSENT —
138
+ * "not-adopted", "nothing to register" — is stating what it examined, which is
139
+ * the criterion satisfied, so nothing here matches that wording.
140
+ */
141
+ const SUCCESS_MARKERS = Object.freeze(["✓", "✔", "✅", "PASSED", "PASS"]);
142
+
143
+ /** Standalone `OK`, which is a verdict; `OKAY` inside a word is not. */
144
+ const OK_TOKEN = /(?:^|[^A-Za-z])OK(?:[^A-Za-z]|$)/;
145
+
146
+ /** Per-guard deadline. A guard that outlives it is a throw, not a verdict. */
147
+ const PROBE_BUDGET_MS = 60_000;
148
+
149
+ /** Usage error — distinguishes an invalid invocation (exit 2) from a finding. */
150
+ export class UsageError extends Error {}
151
+
152
+ /**
153
+ * Does this output claim a check was satisfied?
154
+ * @param {string} output Combined stdout and stderr of a probed guard.
155
+ * @returns {boolean} True when the guard printed a success verdict.
156
+ */
157
+ export function claimsSuccess(output) {
158
+ if (SUCCESS_MARKERS.some(marker => output.includes(marker))) return true;
159
+ return OK_TOKEN.test(output);
160
+ }
161
+
162
+ /**
163
+ * The root override a guard declares in its own header, if any.
164
+ *
165
+ * Read from the header rather than from an arg parser because the header is
166
+ * the guard's contract with its callers — a guard that stops documenting
167
+ * `--root` has changed that contract, and dropping out of the probed
168
+ * population is the correct consequence, made visible by the report's
169
+ * not-probeable count.
170
+ * @param {string} source The guard's source text.
171
+ * @returns {{ flag: string|null }|undefined} The form, or undefined.
172
+ */
173
+ export function declaredRootForm(source) {
174
+ const header = source.slice(0, HEADER_BYTES);
175
+ return ROOT_FORMS.find(form => header.includes(form.token));
176
+ }
177
+
178
+ /**
179
+ * Every guard script under the discovery root, in a stable order.
180
+ * @param {string} root Directory to discover guards under.
181
+ * @returns {string[]} Paths relative to `root`, sorted.
182
+ */
183
+ export function discoverGuards(root) {
184
+ const lanes = [GUARD_DIRECTORY];
185
+ for (const entry of readDirectory(root)) {
186
+ if (entry === GUARD_DIRECTORY || entry.startsWith(".")) continue;
187
+ const lane = path.join(entry, DELIVERED_LANE);
188
+ if (readDirectory(path.join(root, lane)).length > 0) lanes.push(lane);
189
+ }
190
+ return lanes
191
+ .flatMap(lane =>
192
+ readDirectory(path.join(root, lane))
193
+ .filter(name => GUARD_FILE.test(name))
194
+ .map(name => path.join(lane, name))
195
+ )
196
+ .sort((a, b) => a.localeCompare(b));
197
+ }
198
+
199
+ /**
200
+ * `readdirSync` that answers with an empty list instead of throwing.
201
+ * @param {string} directory Directory to read.
202
+ * @returns {string[]} Entry names, or `[]` when unreadable.
203
+ */
204
+ function readDirectory(directory) {
205
+ try {
206
+ return readdirSync(directory);
207
+ } catch {
208
+ return [];
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Run one guard against a subject-free tree.
214
+ * @param {string} script Absolute path to the guard.
215
+ * @param {{ flag: string|null }} form The declared root form.
216
+ * @param {string} empty Absolute path to the empty repository.
217
+ * @returns {{ status: number|null, output: string }} Exit status and output.
218
+ */
219
+ function probe(script, form, empty) {
220
+ const args = form.flag ? [script, form.flag, empty] : [script, empty];
221
+ const result = boundedSpawnSync(process.execPath, args, {
222
+ cwd: empty,
223
+ encoding: "utf8",
224
+ timeout: PROBE_BUDGET_MS,
225
+ });
226
+ return {
227
+ output: `${result.stdout ?? ""}${result.stderr ?? ""}`,
228
+ status: result.status,
229
+ };
230
+ }
231
+
232
+ /**
233
+ * Create a git repository with no tracked files.
234
+ * @returns {string} Absolute path to the repository.
235
+ * @throws {UsageError} When `git` is unavailable or `init` fails.
236
+ */
237
+ export function createEmptyRepository() {
238
+ const directory = mkdtempSync(path.join(tmpdir(), "lisa-3888-"));
239
+ const result = boundedSpawnSync("git", ["init", "-q", directory], {
240
+ encoding: "utf8",
241
+ });
242
+ if (result.status !== 0) {
243
+ rmSync(directory, { force: true, recursive: true });
244
+ throw new UsageError(
245
+ `git init failed in ${directory}: ${result.stderr ?? result.error?.message ?? "unknown"}`
246
+ );
247
+ }
248
+ return directory;
249
+ }
250
+
251
+ /**
252
+ * Probe every root-scoped guard under `root` against an empty repository.
253
+ * @param {string} root Directory to discover guards under.
254
+ * @returns {{ probed: number, findings: object[], notProbeable: string[] }} Report.
255
+ */
256
+ export function sweep(root) {
257
+ const report = { findings: [], notProbeable: [], probed: 0 };
258
+ const guards = discoverGuards(root);
259
+ const empty = createEmptyRepository();
260
+ try {
261
+ for (const relative of guards) {
262
+ const absolute = path.join(root, relative);
263
+ const form = declaredRootForm(readFileSync(absolute, "utf8"));
264
+ if (!form) {
265
+ report.notProbeable.push(relative);
266
+ continue;
267
+ }
268
+ report.probed += 1;
269
+ const { status, output } = probe(absolute, form, empty);
270
+ if (status === 0 && claimsSuccess(output)) {
271
+ report.findings.push({
272
+ guard: relative,
273
+ verdict: firstVerdictLine(output),
274
+ });
275
+ }
276
+ }
277
+ } finally {
278
+ rmSync(empty, { force: true, recursive: true });
279
+ }
280
+ return report;
281
+ }
282
+
283
+ /**
284
+ * The first output line carrying a success marker, for the report.
285
+ * @param {string} output Combined output of a probed guard.
286
+ * @returns {string} That line, trimmed.
287
+ */
288
+ function firstVerdictLine(output) {
289
+ const lines = output.split("\n");
290
+ return (lines.find(line => claimsSuccess(line)) ?? lines[0] ?? "").trim();
291
+ }
292
+
293
+ /**
294
+ * Render the human-readable report.
295
+ * @param {{ probed: number, findings: object[], notProbeable: string[] }} report Result.
296
+ * @returns {string} The report text.
297
+ */
298
+ export function formatReport(report) {
299
+ const lines = [
300
+ `check:empty-subject-guards — probed ${report.probed} root-scoped guard(s) ` +
301
+ `against an empty repository; ${report.notProbeable.length} guard(s) ` +
302
+ `declare no root override and were not probed.`,
303
+ ];
304
+ if (report.probed === 0) {
305
+ lines.push(
306
+ " ✖ ZERO guards probed. A sweep that ran nothing cannot report a clean tree; treating this as a failure, not an all-clear."
307
+ );
308
+ return lines.join("\n");
309
+ }
310
+ for (const finding of report.findings) {
311
+ lines.push(
312
+ ` ✖ ${finding.guard} — exited 0 and printed a success line having examined nothing:`,
313
+ ` ${finding.verdict}`
314
+ );
315
+ }
316
+ if (report.findings.length === 0) {
317
+ lines.push(
318
+ " ✔ Every probed guard refused, or stated that its subject was absent."
319
+ );
320
+ return lines.join("\n");
321
+ }
322
+ lines.push(
323
+ "",
324
+ "Fix: read the subject count before rendering the verdict. An enumeration",
325
+ "that produced nothing is an operational failure of the scan (exit 2), not",
326
+ 'a clean result — the wording the sibling guards use is "a scan of nothing',
327
+ 'is not a pass". A guard that legitimately has nothing to do says THAT',
328
+ "instead, in the manner of `not-adopted`, rather than printing a tick."
329
+ );
330
+ return lines.join("\n");
331
+ }
332
+
333
+ /**
334
+ * CLI entry point.
335
+ * @returns {void}
336
+ */
337
+ export function main() {
338
+ const args = process.argv.slice(2);
339
+ let root = ".";
340
+ let json = false;
341
+ try {
342
+ for (let index = 0; index < args.length; index += 1) {
343
+ const arg = args[index];
344
+ if (arg === "--json") json = true;
345
+ else if (arg === "--guards-root") {
346
+ const value = args[index + 1];
347
+ if (value === undefined || value.startsWith("--")) {
348
+ throw new UsageError("--guards-root requires a value");
349
+ }
350
+ root = value;
351
+ index += 1;
352
+ } else throw new UsageError(`unknown argument: ${arg}`);
353
+ }
354
+ const report = sweep(path.resolve(root));
355
+ console.log(json ? JSON.stringify(report, null, 2) : formatReport(report));
356
+ if (report.probed === 0) process.exitCode = 2;
357
+ else if (report.findings.length > 0) process.exitCode = 1;
358
+ } catch (error) {
359
+ console.error(`check:empty-subject-guards: ${error.message}`);
360
+ process.exitCode = 2;
361
+ }
362
+ }
363
+
364
+ if (invokedAsScript(import.meta.url)) {
365
+ main();
366
+ }