@codyswann/lisa 4.90.0 → 4.90.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/all/copy-overwrite/scripts/lib/completion-proof-shape.mjs +31 -2
  2. package/all/copy-overwrite/scripts/lisa-enforcement-fallback.sh +2 -2
  3. package/all/copy-overwrite/scripts/lisa-enforcement-freshness.mjs +1 -2
  4. package/all/copy-overwrite/scripts/lisa-hooks/parity-safety-net.sh +9 -3634
  5. package/all/copy-overwrite/scripts/lisa-postinstall.mjs +16 -5
  6. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +1 -1
  7. package/dist/cli/apply.d.ts.map +1 -1
  8. package/dist/cli/apply.js +25 -4
  9. package/dist/cli/apply.js.map +1 -1
  10. package/dist/cli/lisa-test-run-process-group.d.ts.map +1 -1
  11. package/dist/cli/lisa-test-run-process-group.js +19 -2
  12. package/dist/cli/lisa-test-run-process-group.js.map +1 -1
  13. package/dist/core/bootstrap-environment.d.ts +10 -1
  14. package/dist/core/bootstrap-environment.d.ts.map +1 -1
  15. package/dist/core/bootstrap-environment.js +14 -5
  16. package/dist/core/bootstrap-environment.js.map +1 -1
  17. package/dist/core/enforcement-coverage.d.ts +2 -2
  18. package/dist/core/enforcement-coverage.d.ts.map +1 -1
  19. package/dist/core/enforcement-coverage.js +2 -3
  20. package/dist/core/enforcement-coverage.js.map +1 -1
  21. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  22. package/dist/core/lisa-owned-hash-ledger.js +18 -0
  23. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  24. package/dist/core/native-safety-net-retirement.d.ts +13 -0
  25. package/dist/core/native-safety-net-retirement.d.ts.map +1 -0
  26. package/dist/core/native-safety-net-retirement.js +23 -0
  27. package/dist/core/native-safety-net-retirement.js.map +1 -0
  28. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  29. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  30. package/dist/core/upstream-evidence-manifest.js +44 -57
  31. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  32. package/dist/migrations/index.d.ts +1 -0
  33. package/dist/migrations/index.d.ts.map +1 -1
  34. package/dist/migrations/index.js +3 -0
  35. package/dist/migrations/index.js.map +1 -1
  36. package/dist/migrations/retire-native-safety-net.d.ts +18 -0
  37. package/dist/migrations/retire-native-safety-net.d.ts.map +1 -0
  38. package/dist/migrations/retire-native-safety-net.js +36 -0
  39. package/dist/migrations/retire-native-safety-net.js.map +1 -0
  40. package/dist/opencode/plugin-catalog.d.ts.map +1 -1
  41. package/dist/opencode/plugin-catalog.js +1 -0
  42. package/dist/opencode/plugin-catalog.js.map +1 -1
  43. package/dist/opencode/plugin-templates/lisa-parity-safety-net.ts +2 -48
  44. package/dist/opencode/plugin-templates/parity-safety-net.sh +9 -3634
  45. package/package.json +8 -6
  46. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  48. package/plugins/lisa/.codex-plugin/skills/lisa-linear-validate-issue/SKILL.md +1 -1
  49. package/plugins/lisa/.codex-plugin/skills/lisa-tracker-evidence/SKILL.md +1 -1
  50. package/plugins/lisa/hooks/parity-safety-net.agy.sh +5 -49
  51. package/plugins/lisa/hooks/parity-safety-net.sh +9 -3634
  52. package/plugins/lisa/skills/lisa-linear-validate-issue/SKILL.md +1 -1
  53. package/plugins/lisa/skills/lisa-tracker-evidence/SKILL.md +1 -1
  54. package/plugins/lisa-agy/hooks/parity-safety-net.agy.sh +5 -49
  55. package/plugins/lisa-agy/hooks/parity-safety-net.sh +9 -3634
  56. package/plugins/lisa-agy/plugin.json +1 -1
  57. package/plugins/lisa-agy/skills/lisa-linear-validate-issue/SKILL.md +1 -1
  58. package/plugins/lisa-agy/skills/lisa-tracker-evidence/SKILL.md +1 -1
  59. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  60. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  61. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  62. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  64. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  66. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  67. package/plugins/lisa-copilot/hooks/parity-safety-net.sh +9 -3634
  68. package/plugins/lisa-copilot/skills/lisa-linear-validate-issue/SKILL.md +1 -1
  69. package/plugins/lisa-copilot/skills/lisa-tracker-evidence/SKILL.md +1 -1
  70. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  71. package/plugins/lisa-cursor/hooks/parity-safety-net.sh +9 -3634
  72. package/plugins/lisa-cursor/skills/lisa-linear-validate-issue/SKILL.md +1 -1
  73. package/plugins/lisa-cursor/skills/lisa-tracker-evidence/SKILL.md +1 -1
  74. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  76. package/plugins/lisa-devin/hooks/parity-safety-net.sh +9 -3634
  77. package/plugins/lisa-devin/skills/lisa-linear-validate-issue/SKILL.md +1 -1
  78. package/plugins/lisa-devin/skills/lisa-tracker-evidence/SKILL.md +1 -1
  79. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  80. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  81. package/plugins/lisa-expo-agy/plugin.json +1 -1
  82. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  83. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  84. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  85. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  86. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  87. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  88. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  89. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  90. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  91. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  92. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  93. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  94. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  95. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  96. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  97. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  98. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  99. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  100. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  101. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  102. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  103. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  104. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  105. package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
  106. package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
  107. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  108. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  109. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  110. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  111. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  112. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  113. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  114. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  115. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  116. package/plugins/lisa-rails-agy/plugin.json +1 -1
  117. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  118. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  119. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  120. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  121. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  122. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  123. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  124. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  125. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  126. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  127. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  128. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  129. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  130. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  131. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  132. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  133. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  134. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  135. package/plugins/src/base/hooks/parity-safety-net.agy.sh +5 -49
  136. package/plugins/src/base/hooks/parity-safety-net.sh +9 -3634
  137. package/plugins/src/base/skills/lisa-linear-validate-issue/SKILL.md +1 -1
  138. package/plugins/src/base/skills/lisa-tracker-evidence/SKILL.md +1 -1
  139. package/scripts/build-plugins.sh +3 -0
  140. package/scripts/check-generated-artifact-merge-coverage.mjs +7 -0
  141. package/scripts/fixtures/native-safety-net-retirement/Dockerfile +5 -0
  142. package/scripts/fixtures/native-safety-net-retirement/invoke-opencode.mjs +13 -0
  143. package/scripts/fixtures/native-safety-net-retirement/isolated-linker.mjs +101 -0
  144. package/scripts/fixtures/native-safety-net-retirement/journey.mjs +381 -0
  145. package/scripts/fixtures/native-safety-net-retirement/probes.mjs +208 -0
  146. package/scripts/fixtures/native-safety-net-retirement/reduced-core.mjs +93 -0
  147. package/scripts/generate-lisa-owned-hash-ledger.mjs +1 -1
  148. package/scripts/generate-retired-safety-net-manifest.mjs +56 -0
  149. package/scripts/install-claude-plugins.sh +9 -5
  150. package/scripts/lib/retired-safety-net-manifest.json +150 -0
  151. package/scripts/lisa-enforcement-fallback.sh +2 -2
  152. package/scripts/lisa-enforcement-freshness.mjs +1 -2
  153. package/scripts/remedy-conformance.mjs +5 -1
  154. package/scripts/retire-native-safety-net.mjs +237 -0
  155. package/scripts/verify-native-safety-net-retirement.mjs +287 -0
@@ -0,0 +1,237 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Retire only hash-proven Lisa safety-net handlers. Old registrations stay
4
+ * callable, including commands captured by an already running agent. Never
5
+ * disable the enclosing Lisa plugin or rewrite an operator's settings.
6
+ */
7
+ import { createHash, randomUUID } from "node:crypto";
8
+ import {
9
+ constants,
10
+ lstatSync,
11
+ openSync,
12
+ closeSync,
13
+ chmodSync,
14
+ readFileSync,
15
+ readdirSync,
16
+ realpathSync,
17
+ renameSync,
18
+ unlinkSync,
19
+ writeFileSync,
20
+ } from "node:fs";
21
+ import { homedir } from "node:os";
22
+ import path from "node:path";
23
+ import { invokedAsScript } from "./lib/invoked-as-script.mjs";
24
+
25
+ const packageRoot = path.resolve(import.meta.dirname, "..");
26
+ const manifest = JSON.parse(
27
+ readFileSync(
28
+ new URL("./lib/retired-safety-net-manifest.json", import.meta.url),
29
+ "utf8"
30
+ )
31
+ );
32
+ const sha = bytes => createHash("sha256").update(bytes).digest("hex");
33
+
34
+ /**
35
+ * Known installed plugin containers, never arbitrary registry installPaths.
36
+ * Walks do not follow symlinks into source checkouts or other user directories.
37
+ * Global Lisa plugin copies must also retire: they can serve many projects.
38
+ * @param {NodeJS.ProcessEnv} [env] Runtime configuration
39
+ * @returns {string[]} Container roots
40
+ */
41
+ export function installedPluginRoots(env = process.env) {
42
+ const home = homedir();
43
+ return [
44
+ path.join(
45
+ env.CLAUDE_CODE_PLUGIN_CACHE_DIR ||
46
+ path.join(
47
+ env.CLAUDE_CONFIG_DIR || path.join(home, ".claude"),
48
+ "plugins"
49
+ ),
50
+ "cache"
51
+ ),
52
+ path.join(env.CODEX_HOME || path.join(home, ".codex"), "plugins/cache"),
53
+ path.join(home, ".cursor/plugins/cache"),
54
+ path.join(home, ".cursor/plugins/local"),
55
+ path.join(home, ".gemini/config/plugins"),
56
+ path.join(home, ".copilot/installed-plugins"),
57
+ path.join(
58
+ env.XDG_CONFIG_HOME || path.join(home, ".config"),
59
+ "devin/plugins"
60
+ ),
61
+ ];
62
+ }
63
+
64
+ /**
65
+ * Inspect a path without treating inaccessible data as an absent installation.
66
+ * @param {string} file Candidate path
67
+ * @returns {import('node:fs').Stats|undefined} Stat if present
68
+ */
69
+ function stat(file) {
70
+ try {
71
+ return lstatSync(file);
72
+ } catch (error) {
73
+ if (error.code === "ENOENT") return undefined;
74
+ throw error;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Refuse symlink ancestors: renaming through them would edit another checkout.
80
+ * @param {string} file Absolute path
81
+ * @returns {boolean} Whether all existing components are literal
82
+ */
83
+ function literalPath(file) {
84
+ const parent = path.dirname(file);
85
+ if (parent !== file && !literalPath(parent)) return false;
86
+ return stat(file)?.isSymbolicLink() !== true;
87
+ }
88
+
89
+ /**
90
+ * Select exact target filenames under bounded plugin trees, preserving all else.
91
+ * @param {string} root Container or project handler directory
92
+ * @param {number} depth Remaining nesting budget
93
+ * @returns {string[]} Existing regular target handlers
94
+ */
95
+ function findHandlers(root, depth = 7) {
96
+ const info = stat(root);
97
+ if (!info?.isDirectory() || !literalPath(root)) return [];
98
+ return readdirSync(root, { withFileTypes: true }).flatMap(entry => {
99
+ const file = path.join(root, entry.name);
100
+ if (entry.isFile() && Object.hasOwn(manifest, entry.name)) return [file];
101
+ return depth > 0 && entry.isDirectory()
102
+ ? findHandlers(file, depth - 1)
103
+ : [];
104
+ });
105
+ }
106
+
107
+ /**
108
+ * Replace an owned target atomically, breaking cache hardlinks instead of
109
+ * changing their shared inode. Revalidate the read image immediately before
110
+ * rename. A custom or concurrently changed copy is preserved and reported.
111
+ * @param {string} file Target handler
112
+ * @param {boolean} dryRun Report without writes
113
+ * @returns {{path:string,status:string}} Per-handler result
114
+ */
115
+ function retireHandler(file, dryRun) {
116
+ const entry = manifest[path.basename(file)];
117
+ const before = stat(file);
118
+ if (!before?.isFile() || !literalPath(file))
119
+ return { path: file, status: "preserved-nonliteral" };
120
+ const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
121
+ let bytes;
122
+ try {
123
+ bytes = readFileSync(fd);
124
+ } finally {
125
+ closeSync(fd);
126
+ }
127
+ if (bytes.equals(Buffer.from(entry.shim)))
128
+ return { path: file, status: "already-retired" };
129
+ if (!entry.hashes.includes(sha(bytes)))
130
+ return { path: file, status: "preserved-custom" };
131
+ if (dryRun) return { path: file, status: "would-retire" };
132
+ const temporary = path.join(
133
+ path.dirname(file),
134
+ `.lisa-retire-${randomUUID()}`
135
+ );
136
+ try {
137
+ writeFileSync(temporary, entry.shim, {
138
+ flag: "wx",
139
+ mode: before.mode & 0o777,
140
+ });
141
+ chmodSync(temporary, before.mode & 0o777);
142
+ const current = stat(file);
143
+ if (
144
+ !literalPath(file) ||
145
+ current?.ino !== before.ino ||
146
+ current?.dev !== before.dev ||
147
+ !readFileSync(file).equals(bytes)
148
+ ) {
149
+ throw new Error(
150
+ `Safety-net retirement preserved a concurrently changed handler: ${file}`
151
+ );
152
+ }
153
+ renameSync(temporary, file);
154
+ } finally {
155
+ if (stat(temporary)) unlinkSync(temporary);
156
+ }
157
+ return { path: file, status: "retired" };
158
+ }
159
+
160
+ /**
161
+ * Reconcile existing target handlers; no template apply or evidence writes.
162
+ * @param {{projectDir:string,dryRun?:boolean,pluginRoots?:readonly string[]}} options Scope
163
+ * @returns {{path:string,status:string}[]} Exact decisions
164
+ */
165
+ export function retireNativeSafetyNet({
166
+ projectDir,
167
+ dryRun = false,
168
+ pluginRoots = [],
169
+ }) {
170
+ const root = realpathSync(projectDir);
171
+ const local = [
172
+ "scripts/lisa-hooks",
173
+ ".claude",
174
+ ".codex",
175
+ ".devin",
176
+ ".cursor",
177
+ ".opencode",
178
+ ".agents/plugins",
179
+ ".github/plugins",
180
+ "plugins",
181
+ ];
182
+ const handlers = [
183
+ ...new Set(
184
+ [...local.map(dir => path.join(root, dir)), ...pluginRoots].flatMap(dir =>
185
+ findHandlers(dir)
186
+ )
187
+ ),
188
+ ].sort();
189
+ return handlers.map(file => retireHandler(file, dryRun));
190
+ }
191
+
192
+ if (invokedAsScript(import.meta.url)) {
193
+ const args = process.argv.slice(2);
194
+ const supported = new Set(["--install", "--dry-run", "--json"]);
195
+ for (const argument of args.filter(value => value.startsWith("--"))) {
196
+ if (!supported.delete(argument))
197
+ throw new Error(`Unknown or duplicate retirement option: ${argument}`);
198
+ }
199
+ const destinations = args.filter(value => !value.startsWith("--"));
200
+ if (destinations.length > 1)
201
+ throw new Error("Retirement accepts exactly one project destination");
202
+ const dependency = packageRoot.endsWith(
203
+ path.join(path.sep, "node_modules", "@codyswann", "lisa")
204
+ );
205
+ const virtualStore = dependency
206
+ ? [".pnpm", ".bun"]
207
+ .map(store => path.join(path.sep, "node_modules", store) + path.sep)
208
+ .find(marker => packageRoot.includes(marker))
209
+ : undefined;
210
+ const installRoot = virtualStore
211
+ ? packageRoot.split(virtualStore)[0]
212
+ : dependency
213
+ ? path.resolve(packageRoot, "../../..")
214
+ : packageRoot;
215
+ const projectDir = path.resolve(
216
+ destinations[0] ||
217
+ (args.includes("--install") ? installRoot : process.cwd())
218
+ );
219
+ // Source-repository dependency installation is not a downstream update.
220
+ // Explicit apply reuses this reconciler after copying its target templates.
221
+ const selfInstall = args.includes("--install") && projectDir === packageRoot;
222
+ const decisions = selfInstall
223
+ ? []
224
+ : retireNativeSafetyNet({
225
+ projectDir,
226
+ dryRun: args.includes("--dry-run"),
227
+ // A source checkout's build/test/apply is not a dependency update. Only
228
+ // an installed dependency reconciles its independent installed copies.
229
+ pluginRoots: dependency ? installedPluginRoots() : [],
230
+ });
231
+ if (args.includes("--json")) console.log(JSON.stringify(decisions));
232
+ else
233
+ for (const decision of decisions) {
234
+ if (decision.status !== "already-retired")
235
+ console.log(`lisa: safety-net ${decision.status}: ${decision.path}`);
236
+ }
237
+ }
@@ -0,0 +1,287 @@
1
+ #!/usr/bin/env node
2
+ /** Run the codified package-update journey in a genuinely isolated filesystem. */
3
+ import assert from "node:assert/strict";
4
+ import { spawnSync } from "node:child_process";
5
+ import { createHash, randomUUID } from "node:crypto";
6
+ import {
7
+ chmodSync,
8
+ copyFileSync,
9
+ existsSync,
10
+ mkdirSync,
11
+ mkdtempSync,
12
+ readFileSync,
13
+ readdirSync,
14
+ writeFileSync,
15
+ } from "node:fs";
16
+ import { tmpdir } from "node:os";
17
+ import path from "node:path";
18
+
19
+ const root = path.resolve(import.meta.dirname, "..");
20
+ const fixture = path.join(
21
+ root,
22
+ "scripts/fixtures/native-safety-net-retirement"
23
+ );
24
+ const args = process.argv.slice(2);
25
+ const CANDIDATE_OPTION = "--candidate";
26
+ const flags = new Set(["--out", CANDIDATE_OPTION, "--image"]);
27
+ assert.equal(args.length % 2, 0, "Each verifier option needs a value");
28
+ for (let index = 0; index < args.length; index += 2) {
29
+ assert.ok(
30
+ flags.delete(args[index]),
31
+ `Unknown or duplicate verifier option: ${args[index]}`
32
+ );
33
+ assert.ok(
34
+ args[index + 1] && !args[index + 1].startsWith("--"),
35
+ "Verifier option needs a value"
36
+ );
37
+ }
38
+ const option = name => {
39
+ const index = args.indexOf(name);
40
+ return index < 0 ? undefined : args[index + 1];
41
+ };
42
+ const out = path.resolve(
43
+ option("--out") || mkdtempSync(path.join(tmpdir(), "lisa-retirement-proof-"))
44
+ );
45
+ mkdirSync(out, { recursive: true, mode: 0o700 });
46
+ assert.equal(
47
+ readdirSync(out).length,
48
+ 0,
49
+ "Choose a fresh evidence directory; earlier packets must be preserved"
50
+ );
51
+ const transcript = [];
52
+ const sha = bytes => createHash("sha256").update(bytes).digest("hex");
53
+ const record = (file, value) =>
54
+ writeFileSync(path.join(out, file), `${JSON.stringify(value, null, 2)}\n`, {
55
+ mode: 0o600,
56
+ });
57
+
58
+ /** Bounded controller process; all tool output is retained in the packet. */
59
+ function run(command, parameters, milliseconds = 25 * 60_000) {
60
+ const result = spawnSync(command, parameters, {
61
+ cwd: root,
62
+ encoding: "utf8",
63
+ timeout: milliseconds,
64
+ maxBuffer: 32 * 1024 * 1024,
65
+ });
66
+ const row = {
67
+ command,
68
+ args: parameters,
69
+ status: result.status,
70
+ signal: result.signal,
71
+ error: result.error?.message ?? null,
72
+ stdout: result.stdout ?? "",
73
+ stderr: result.stderr ?? "",
74
+ };
75
+ transcript.push(row);
76
+ record("controller-transcript.json", transcript);
77
+ assert.equal(result.error, undefined, JSON.stringify(row));
78
+ assert.equal(result.signal, null, JSON.stringify(row));
79
+ assert.equal(result.status, 0, JSON.stringify(row));
80
+ return row.stdout;
81
+ }
82
+
83
+ /** Inspect the actual created container rather than trusting creation flags. */
84
+ function inspect(id) {
85
+ const data = JSON.parse(run("docker", ["inspect", id], 30_000))[0];
86
+ assert.equal(data.Id, id);
87
+ assert.deepEqual(data.Mounts, []);
88
+ const host = data.HostConfig;
89
+ for (const key of [
90
+ "Binds",
91
+ "Mounts",
92
+ "VolumesFrom",
93
+ "Devices",
94
+ "DeviceRequests",
95
+ "CapAdd",
96
+ ])
97
+ assert.ok(host[key] == null || host[key].length === 0, key);
98
+ assert.equal(host.Privileged, false);
99
+ assert.ok(host.CapDrop.includes("ALL"));
100
+ assert.deepEqual(host.SecurityOpt, ["no-new-privileges"]);
101
+ assert.equal(host.NetworkMode, "bridge");
102
+ assert.equal(host.PidMode, "");
103
+ assert.equal(host.IpcMode, "private");
104
+ assert.equal(host.CgroupnsMode, "private");
105
+ return data;
106
+ }
107
+
108
+ /** Public immutable baseline bytes, pinned independently of registry metadata. */
109
+ async function baseline() {
110
+ const metadataResponse = await fetch(
111
+ "https://registry.npmjs.org/@codyswann%2Flisa/4.90.0",
112
+ { signal: AbortSignal.timeout(60_000) }
113
+ );
114
+ assert.equal(metadataResponse.status, 200);
115
+ const metadata = await metadataResponse.json();
116
+ assert.equal(metadata.gitHead, "f7355b414bdf0c994b04fdb1cf9b0b8edc473ba9");
117
+ const response = await fetch(
118
+ "https://registry.npmjs.org/@codyswann/lisa/-/lisa-4.90.0.tgz",
119
+ { signal: AbortSignal.timeout(120_000) }
120
+ );
121
+ assert.equal(response.status, 200);
122
+ const bytes = Buffer.from(await response.arrayBuffer());
123
+ const measured = {
124
+ sha256: sha(bytes),
125
+ integrity: `sha512-${createHash("sha512").update(bytes).digest("base64")}`,
126
+ };
127
+ assert.equal(
128
+ measured.sha256,
129
+ "9b8f63426cc9d75821a8e085842fd3cd053bd40d0b5502bec75cd89f41356fbf"
130
+ );
131
+ assert.equal(
132
+ measured.integrity,
133
+ "sha512-5CrCmSlov+Nj/1SuwHX9Nx4SHlezHc5e59Oest0oEnGrYOmJI3tuvBmLaHOHRnV+tlbAEf+ZO3aQ94I/GkZMdw=="
134
+ );
135
+ assert.equal(measured.integrity, metadata.dist.integrity);
136
+ writeFileSync(path.join(out, "baseline.tgz"), bytes, { mode: 0o644 });
137
+ record("baseline-identity.json", {
138
+ version: "4.90.0",
139
+ git_head: metadata.gitHead,
140
+ ...measured,
141
+ });
142
+ }
143
+
144
+ let id;
145
+ try {
146
+ assert.ok(
147
+ existsSync(path.join(fixture, "journey.mjs")),
148
+ "Run the source checkout's verifier, which contains its codified fixture."
149
+ );
150
+ await baseline();
151
+ const candidate = path.join(out, "candidate.tgz");
152
+ if (option(CANDIDATE_OPTION))
153
+ copyFileSync(path.resolve(option(CANDIDATE_OPTION)), candidate);
154
+ else run("bun", ["pm", "pack", "--filename", candidate]);
155
+ // Public archives and fixture programs need to be readable after docker cp
156
+ // preserves the host UID into a capability-dropped container. Parent stays700.
157
+ chmodSync(candidate, 0o644);
158
+ record("candidate-identity.json", {
159
+ archive_sha256: sha(readFileSync(candidate)),
160
+ verification_driver_head: run("git", ["rev-parse", "HEAD"], 30_000).trim(),
161
+ verification_driver_worktree_status: run(
162
+ "git",
163
+ ["status", "--porcelain"],
164
+ 30_000
165
+ ),
166
+ artifact_source: option(CANDIDATE_OPTION)
167
+ ? "Caller-supplied immutable archive; source/release relationship must be verified separately"
168
+ : "Packed from this checkout; dirty status is recorded and is not exact-commit proof",
169
+ fixture: [
170
+ "journey.mjs",
171
+ "probes.mjs",
172
+ "invoke-opencode.mjs",
173
+ "Dockerfile",
174
+ "reduced-core.mjs",
175
+ "isolated-linker.mjs",
176
+ ].map(file => ({
177
+ file,
178
+ sha256: sha(readFileSync(path.join(fixture, file))),
179
+ })),
180
+ });
181
+ const image = option("--image") || "lisa-native-safety-net-retirement:v1";
182
+ if (!option("--image")) run("docker", ["build", "--tag", image, fixture]);
183
+ const imageData = JSON.parse(
184
+ run("docker", ["image", "inspect", image], 30_000)
185
+ )[0];
186
+ const name = `lisa-native-safety-net-retirement-${randomUUID()}`;
187
+ id = run(
188
+ "docker",
189
+ [
190
+ "create",
191
+ "--name",
192
+ name,
193
+ "--label",
194
+ "lisa.verification=native-safety-net-retirement",
195
+ "--cap-drop",
196
+ "ALL",
197
+ "--security-opt",
198
+ "no-new-privileges",
199
+ "--network",
200
+ "bridge",
201
+ "--ipc",
202
+ "private",
203
+ "--cgroupns",
204
+ "private",
205
+ "--pids-limit",
206
+ "512",
207
+ "--memory",
208
+ "4g",
209
+ "--cpus",
210
+ "2",
211
+ "--entrypoint",
212
+ "/usr/bin/timeout",
213
+ imageData.Id,
214
+ "--signal=TERM",
215
+ "--kill-after=10s",
216
+ "20m",
217
+ "node",
218
+ "/proof/journey.mjs",
219
+ ],
220
+ 30_000
221
+ ).trim();
222
+ assert.match(id, /^[a-f0-9]{64}$/);
223
+ record("container-lease.json", {
224
+ id,
225
+ name,
226
+ image_id: imageData.Id,
227
+ created_at: new Date().toISOString(),
228
+ });
229
+ record("isolation-inspection.json", inspect(id));
230
+ run("docker", ["cp", `${fixture}/.`, `${id}:/proof`], 30_000);
231
+ run(
232
+ "docker",
233
+ ["cp", path.join(out, "baseline.tgz"), `${id}:/baseline.tgz`],
234
+ 30_000
235
+ );
236
+ run("docker", ["cp", candidate, `${id}:/candidate.tgz`], 30_000);
237
+ const output = run("docker", ["start", "--attach", id]);
238
+ console.log(output);
239
+ const finished = inspect(id);
240
+ record("final-inspection.json", finished);
241
+ assert.equal(finished.State.Running, false);
242
+ assert.equal(finished.State.ExitCode, 0);
243
+ run("docker", ["cp", `${id}:/evidence`, path.join(out, "runtime")], 30_000);
244
+ const result = JSON.parse(
245
+ readFileSync(path.join(out, "runtime/retirement-proof.json"), "utf8")
246
+ );
247
+ assert.match(result.outcome, /^PASS:/);
248
+ const isolated = JSON.parse(result.isolated_linker_update.stdout);
249
+ assert.match(isolated.outcome, /^PASS:/);
250
+ assert.deepEqual(
251
+ isolated.before.results.map(row => row.status),
252
+ [2, 2, 0]
253
+ );
254
+ assert.deepEqual(
255
+ isolated.after.results.map(row => row.status),
256
+ [0, 2, 0]
257
+ );
258
+ record("result.json", {
259
+ outcome: result.outcome,
260
+ archive_sha256: sha(readFileSync(candidate)),
261
+ runtime_proof_sha256: sha(
262
+ readFileSync(path.join(out, "runtime/retirement-proof.json"))
263
+ ),
264
+ container_id: id,
265
+ observed_at: new Date().toISOString(),
266
+ limits: result.boundary,
267
+ });
268
+ console.log(`Evidence: ${out}`);
269
+ } finally {
270
+ if (id) {
271
+ // Collect failures too. Preserve the leased container for diagnosis; never
272
+ // force-remove another process or silently overwrite a previous packet.
273
+ const state = JSON.parse(run("docker", ["inspect", id], 30_000))[0];
274
+ if (!state.State.Running && !existsSync(path.join(out, "runtime"))) {
275
+ try {
276
+ run(
277
+ "docker",
278
+ ["cp", `${id}:/evidence`, path.join(out, "runtime")],
279
+ 30_000
280
+ );
281
+ } catch (error) {
282
+ console.error(`Evidence collection failed: ${error.message}`);
283
+ }
284
+ }
285
+ record("last-inspection.json", state);
286
+ }
287
+ }