@miracle352/statute 0.0.0-stage → 0.3.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 (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +319 -2
  3. package/action.yml +356 -0
  4. package/bin/hook.js +81 -0
  5. package/bin/init.js +142 -0
  6. package/bin/mcp.js +166 -0
  7. package/bin/scope.js +78 -0
  8. package/bin/shots.js +52 -0
  9. package/bin/statute.js +362 -0
  10. package/examples/expect/newsletter_test.md +22 -0
  11. package/examples/expect/output-newsletter/.internal/execution.json +2053 -0
  12. package/examples/expect/output-newsletter/.internal/meta.json +39 -0
  13. package/examples/expect/output-newsletter/.internal/steps/1-d2368411/flows/0/actions.ndjson +2 -0
  14. package/examples/expect/output-newsletter/.internal/steps/2-a9e761f8/flows/0/actions.ndjson +6 -0
  15. package/examples/expect/output-newsletter/.internal/steps/3-63305a01/flows/0/actions.ndjson +2 -0
  16. package/examples/expect/output-newsletter/Result.md +21 -0
  17. package/examples/expect/search_test.md +20 -0
  18. package/laws/README.md +24 -0
  19. package/laws/accept_still_works_test.md +12 -0
  20. package/laws/cancel_as_easy_as_signup_test.md +15 -0
  21. package/laws/output-reject_means_reject/.internal/execution.json +1279 -0
  22. package/laws/output-reject_means_reject/.internal/meta.json +18 -0
  23. package/laws/output-reject_means_reject/.internal/steps/1-567cc234/flows/0/actions.ndjson +6 -0
  24. package/laws/output-reject_means_reject/.internal/steps/2-e3c06462/flows/0/actions.ndjson +1 -0
  25. package/laws/output-reject_means_reject/.internal/steps/3-3040a29b/flows/0/actions.ndjson +2 -0
  26. package/laws/output-reject_means_reject/Result.md +21 -0
  27. package/laws/price_shown_is_price_paid_test.md +12 -0
  28. package/laws/reject_means_reject_test.md +15 -0
  29. package/package.json +65 -4
  30. package/replays/cancel-demo-shop/evidence/cancel-1794754943192.evidence +0 -0
  31. package/replays/cancel-demo-shop/evidence/cancel-1794755110410.evidence +0 -0
  32. package/replays/cancel-demo-shop/loop.json +32 -0
  33. package/replays/demo-shop/evidence/consent-1794751413210.evidence +0 -0
  34. package/replays/demo-shop/evidence/consent-1794751523524.evidence +0 -0
  35. package/replays/demo-shop/evidence/consent-accept-1794751588395.evidence +0 -0
  36. package/replays/demo-shop/loop.json +40 -0
  37. package/replays/haxcms/evidence/consent-1794831086682.evidence +0 -0
  38. package/replays/haxcms/evidence/consent-1794831262757.evidence +0 -0
  39. package/replays/haxcms/evidence/consent-accept-1794831347132.evidence +0 -0
  40. package/replays/haxcms/loop.json +56 -0
  41. package/replays/in-the-wake-check/consent.json +67 -0
  42. package/replays/in-the-wake-check/consent.md +32 -0
  43. package/replays/kane-testmd-demo-shop/evidence/consent-1794935266000.evidence +0 -0
  44. package/replays/kane-testmd-demo-shop/loop.json +18 -0
  45. package/replays/lumen-pr-2/evidence/consent-1794929771799.evidence +0 -0
  46. package/replays/lumen-pr-2/evidence/consent-1794929845913.evidence +0 -0
  47. package/replays/lumen-pr-2/evidence/consent-accept-1794929886905.evidence +0 -0
  48. package/replays/lumen-pr-2/loop.json +57 -0
  49. package/replays/newsletter-expect/evidence/newsletter_test-round1-1795518837738.evidence +0 -0
  50. package/replays/newsletter-expect/evidence/newsletter_test-round2-1795519079029.evidence +0 -0
  51. package/replays/newsletter-expect/loop.json +99 -0
  52. package/replays/price-demo-shop/evidence/price-1794837093949.evidence +0 -0
  53. package/replays/price-demo-shop/evidence/price-1794837311639.evidence +0 -0
  54. package/replays/price-demo-shop/loop.json +43 -0
  55. package/rules/trackers.json +61 -0
  56. package/site/assets/fonts/OFL-archivo.txt +93 -0
  57. package/site/assets/fonts/OFL-geist.txt +93 -0
  58. package/site/assets/fonts/OFL-instrument-serif.txt +93 -0
  59. package/site/assets/fonts/archivo.woff2 +0 -0
  60. package/site/assets/fonts/geist.woff2 +0 -0
  61. package/site/assets/fonts/instrument-serif-italic.woff2 +0 -0
  62. package/site/assets/fonts/instrument-serif.woff2 +0 -0
  63. package/site/assets/fonts/inter.woff2 +0 -0
  64. package/site/assets/fonts/jetbrains-mono.woff2 +0 -0
  65. package/skill/statute/SKILL.md +57 -0
  66. package/src/agent.js +70 -0
  67. package/src/app.js +41 -0
  68. package/src/evidence.js +80 -0
  69. package/src/expect-cli.js +296 -0
  70. package/src/expect-view.js +79 -0
  71. package/src/expect.js +392 -0
  72. package/src/infer.js +32 -0
  73. package/src/kane.js +124 -0
  74. package/src/pack.js +128 -0
  75. package/src/packs/cancel.js +83 -0
  76. package/src/packs/consent-accept.js +57 -0
  77. package/src/packs/consent.js +237 -0
  78. package/src/packs/price.js +104 -0
  79. package/src/page.js +360 -0
  80. package/src/report.js +59 -0
  81. package/src/zip.js +38 -0
package/src/page.js ADDED
@@ -0,0 +1,360 @@
1
+ // Builds statute-report/index.html: a self-contained case file of what Kane
2
+ // caught, what the agent changed, and what Kane proved. Pure code, no AI.
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const zip = require("./zip");
6
+ const evidence = require("./evidence");
7
+
8
+ // The site's fonts, built into each case file so it looks the same offline.
9
+ const fontB64 = (f) => { try { return fs.readFileSync(path.join(__dirname, "..", "site", "assets", "fonts", f)).toString("base64"); } catch { return ""; } };
10
+ const FONT_SERIF = fontB64("instrument-serif.woff2");
11
+ const FONT_SANS = fontB64("geist.woff2");
12
+
13
+ const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
14
+
15
+ // Tiny, safe markdown: paragraphs, **bold**, `code`.
16
+ function md(s) {
17
+ return String(s || "")
18
+ .trim()
19
+ .split(/\n{2,}/)
20
+ .map((p) => `<p>${esc(p).replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>").replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\n/g, " ")}</p>`)
21
+ .join("");
22
+ }
23
+
24
+ // Width and height of a JPEG or PNG, read from its header.
25
+ function imageSize(b) {
26
+ if (b[0] === 0x89 && b[1] === 0x50) return { w: b.readUInt32BE(16), h: b.readUInt32BE(20) };
27
+ let i = 2;
28
+ while (i < b.length) {
29
+ if (b[i] !== 0xff) return null;
30
+ const m = b[i + 1];
31
+ const len = b.readUInt16BE(i + 2);
32
+ if (m >= 0xc0 && m <= 0xcf && m !== 0xc4 && m !== 0xc8 && m !== 0xcc) return { h: b.readUInt16BE(i + 5), w: b.readUInt16BE(i + 7) };
33
+ i += 2 + len;
34
+ }
35
+ return null;
36
+ }
37
+
38
+ // Step screenshots + captions from a sealed Kane evidence pack.
39
+ function steps(packPath) {
40
+ if (!packPath || !fs.existsSync(packPath)) return [];
41
+ const buf = fs.readFileSync(packPath);
42
+ const list = zip.entries(buf);
43
+ // Page size Kane browsed at; screenshots may be taken at a higher pixel ratio.
44
+ let viewW = 0;
45
+ const res = list.find((e) => /result\.yaml$/.test(e.name));
46
+ if (res) {
47
+ const m = zip.read(buf, res).toString("utf8").match(/resolution:\s*'?(\d+)x(\d+)/);
48
+ if (m) viewW = Number(m[1]);
49
+ }
50
+ const out = [];
51
+ for (const e of list) {
52
+ const m = e.name.match(/steps\/(\d+)-[^/]+\/step\.json$/);
53
+ if (!m) continue;
54
+ let s;
55
+ try { s = JSON.parse(zip.read(buf, e).toString("utf8")); } catch { continue; }
56
+ const dir = e.name.replace(/step\.json$/, "");
57
+ const shot = list.find((x) => x.name === dir + "screenshot.jpg" || x.name === dir + "screenshot.png");
58
+ const raw = shot ? zip.read(buf, shot) : null;
59
+ const img = raw ? `data:image/${shot.name.endsWith(".png") ? "png" : "jpeg"};base64,${raw.toString("base64")}` : null;
60
+ const size = raw ? imageSize(raw) : null;
61
+ const caption = String(s.summary || "").replace(/^\w+:\s*/, "").replace(/^(Clicking|Waiting)\s+/i, (w) => w);
62
+ let rect = s.element_rect || null;
63
+ if (rect && size && viewW && size.w !== viewW) {
64
+ const k = size.w / viewW;
65
+ rect = { x: rect.x * k, y: rect.y * k, width: rect.width * k, height: rect.height * k };
66
+ }
67
+ out.push({ n: Number(m[1]), kind: s.kind || "", status: s.status, caption, url: s.url, img, size, rect });
68
+ }
69
+ return out.sort((a, b) => a.n - b.n);
70
+ }
71
+
72
+ // Older loop.json files did not record which pack belongs to which entry:
73
+ // match by pack id and the closest time before the entry.
74
+ function findPack(out, entry) {
75
+ if (entry.evidence && fs.existsSync(entry.evidence)) return entry.evidence;
76
+ const dir = path.join(out, "evidence");
77
+ if (!fs.existsSync(dir)) return null;
78
+ const at = Date.parse(entry.at);
79
+ let best = null;
80
+ for (const f of fs.readdirSync(dir)) {
81
+ const m = f.match(/^(.+)-(\d+)\.evidence$/);
82
+ if (!m || m[1] !== entry.pack) continue;
83
+ const t = Number(m[2]);
84
+ if (t <= at + 5000 && (!best || t > best.t)) best = { t, file: path.join(dir, f) };
85
+ }
86
+ return best && best.file;
87
+ }
88
+
89
+ const PHASE = { after: 'After “Reject”', before: "Before any choice", unknown: "During the visit" };
90
+
91
+ function trackerTable(result) {
92
+ const rows = (result.trackerRequests || []).slice().sort((a, b) => ({ after: 0, before: 1, unknown: 2 }[a.phase] - { after: 0, before: 1, unknown: 2 }[b.phase]));
93
+ if (!rows.length) return "";
94
+ return `<div class="tw"><table class="t"><thead><tr><th>When</th><th>Tracker</th><th>Request</th><th class="num">Times</th><th>Visitor ID sent</th></tr></thead><tbody>${rows
95
+ .map((r) => `<tr class="${r.phase}"><td>${PHASE[r.phase]}</td><td>${esc(r.tracker)}${r.consentDenied ? ` <small>consent denied, not counted</small>` : r.loaderOnly ? ` <small>tag manager code only, not counted</small>` : ""}</td><td class="mono">${esc(r.method || "")} ${esc(r.url.replace(/^https?:\/\//, ""))}</td><td class="num">${r.count}</td><td class="mono">${esc((r.ids || []).map((i) => i.split(": ").pop()).join(", "))}</td></tr>`)
96
+ .join("")}</tbody></table></div>`;
97
+ }
98
+
99
+ // Zoom into the spot Kane clicked and outline it. Falls back to the whole shot.
100
+ function zoom(s) {
101
+ if (!s.size || !s.rect || !s.rect.width) return `<img src="${s.img}" alt="">`;
102
+ const W = Math.min(s.size.w, Math.round(s.size.w * 0.42)), H = Math.round(W * 9 / 16);
103
+ const cx = s.rect.x + s.rect.width / 2, cy = s.rect.y + s.rect.height / 2;
104
+ const x0 = Math.max(0, Math.min(s.size.w - W, cx - W / 2));
105
+ const y0 = Math.max(0, Math.min(s.size.h - H, cy - H / 2));
106
+ const pct = (v, of) => (v / of * 100).toFixed(3) + "%";
107
+ return `<div class="zoom" style="aspect-ratio:${W}/${H}"><img src="${s.img}" alt="" style="width:${pct(s.size.w, W)};left:${pct(-x0, W)};top:${pct(-y0, H)}"><i style="left:${pct(s.rect.x - x0 - 6, W)};top:${pct(s.rect.y - y0 - 6, H)};width:${pct(s.rect.width + 12, W)};height:${pct(s.rect.height + 12, H)}"></i></div>`;
108
+ }
109
+
110
+ function shot(s, key, note) {
111
+ if (!s || !s.img) return "";
112
+ return `<figure><a href="#${key}-${s.n}" aria-label="Open Kane's full screenshot">${zoom(s)}</a><figcaption>Kane's screenshot, step ${s.n}: ${esc(s.caption)}. ${esc(note)}</figcaption></figure>`;
113
+ }
114
+
115
+ function filmstrip(list, id) {
116
+ if (!list.length) return "";
117
+ return `<ol class="strip">${list
118
+ .map((s) => `<li>${s.img ? `<a href="#${id}-${s.n}"><img src="${s.img}" alt="Step ${s.n}: ${esc(s.caption)}" loading="lazy"></a>` : ""}<span><b>${s.n}</b> ${esc(s.caption)}</span></li>`)
119
+ .join("")}</ol>${list
120
+ .filter((s) => s.img)
121
+ .map((s) => `<a class="lightbox" id="${id}-${s.n}" href="#_"><img src="${s.img}" alt=""><span>Step ${s.n} · ${esc(s.caption)}</span></a>`)
122
+ .join("")}`;
123
+ }
124
+
125
+ function build({ out, packs, url = "" }) {
126
+ const loopFile = path.join(out, "loop.json");
127
+ let loop;
128
+ if (fs.existsSync(loopFile)) {
129
+ loop = JSON.parse(fs.readFileSync(loopFile, "utf8"));
130
+ } else {
131
+ // A single check, no loop: show the last run of each pack.
132
+ const timeline = [];
133
+ for (const id of Object.keys(packs)) {
134
+ const f = path.join(out, `${id}.last-run.json`);
135
+ if (!fs.existsSync(f)) continue;
136
+ const last = JSON.parse(fs.readFileSync(f, "utf8"));
137
+ timeline.push({ round: 1, step: "kane", pack: id, evidence: last.packPath, run: last.end && last.end.test_url, at: new Date().toISOString(), credits: last.end && last.end.credits_consumed, kaneStatus: last.end && last.end.status, kaneSummary: last.end && last.end.summary });
138
+ }
139
+ loop = { pack: timeline[0] && timeline[0].pack, timeline, url };
140
+ }
141
+ const main = packs[loop.pack] || Object.values(packs)[0];
142
+
143
+ // Re-judge every Kane run from its sealed pack, so the page is always
144
+ // derived from evidence rather than from saved text.
145
+ const entries = loop.timeline.map((t, i) => {
146
+ if (t.step !== "kane") return t;
147
+ const packPath = findPack(out, t);
148
+ const pk = packs[t.pack];
149
+ let result = null;
150
+ if (packPath && pk) {
151
+ const network = evidence.networkFromPack(packPath);
152
+ const end = t.kaneStatus ? { status: t.kaneStatus, summary: t.kaneSummary } : null;
153
+ result = pk.judge({ end, events: [], network, strict: !!loop.strict });
154
+ t.run = t.run || network.shareLink;
155
+ }
156
+ return { ...t, packPath, result, shots: steps(packPath), key: `r${i}` };
157
+ });
158
+
159
+ const kaneRuns = entries.filter((e) => e.step === "kane");
160
+ const first = kaneRuns.find((e) => e.pack === main.id);
161
+ const lastMain = [...kaneRuns].reverse().find((e) => e.pack === main.id);
162
+ const fixed = !!lastMain && lastMain.result && lastMain.result.verdict === "pass" && first && first.result && first.result.verdict === "violation";
163
+ const status = fixed ? "fixed" : lastMain && lastMain.result ? lastMain.result.verdict : "inconclusive";
164
+ // Every counted tracker request made without consent: after Reject, or before any choice.
165
+ const afterCount = (r) => (r && r.trackerRequests ? r.trackerRequests.filter((x) => !x.notCounted).reduce((a, x) => a + x.count, 0) : 0);
166
+ const ids = (first && first.result && first.result.idsAfterReject) || [];
167
+ const rounds = Math.max(1, ...entries.map((e) => e.round || 1));
168
+ const credits = loop.credits != null ? Number(loop.credits) : kaneRuns.reduce((a, e) => a + (Number(e.credits) || 0), 0);
169
+ const agentEntry = entries.find((e) => e.step === "agent");
170
+
171
+ const views = {
172
+ consent: {
173
+ headline: {
174
+ fixed: "Kane caught a visitor being tracked after they clicked “Reject”. Claude Code fixed it. Kane proved the fix.",
175
+ violation: "Kane caught a visitor being tracked after they refused cookies.",
176
+ pass: "Kane refused cookies and no tracker followed.",
177
+ },
178
+ stat: () => [`${afterCount(first && first.result)} → ${afterCount(lastMain && lastMain.result)}`, "tracker requests without consent"],
179
+ exhibit: () => `
180
+ <div class="ex-grid">
181
+ <div>
182
+ <p class="lead">${esc(first.result.why)}</p>
183
+ ${ids.length ? `<div class="idbox"><span>Visitor ID sent to Google after “Reject”</span><code>${esc(ids[0].split(": ").pop())}</code><small>${esc(ids[0].split(": ")[0])}</small></div>` : ""}
184
+ ${first.result.rejectClick ? `<p class="meta">Kane clicked “${esc(first.result.rejectClick.label)}” at <span class="mono">${esc((first.result.rejectClick.time || "").replace("T", " ").replace(/\.\d+Z$/, " UTC"))}</span>. Every request after that moment is counted as after the refusal.</p>` : ""}
185
+ </div>
186
+ ${shot(first.shots.find((x) => /reject|declin|refus/i.test(x.caption)) || first.shots[first.shots.length - 1], first.key, "The outline marks what it clicked.")}
187
+ </div>
188
+ ${trackerTable(first.result)}`,
189
+ },
190
+ cancel: {
191
+ headline: {
192
+ fixed: "Kane subscribed in a couple of clicks but could not cancel online. Claude Code fixed it. Kane proved cancelling is now as easy as signing up.",
193
+ violation: "Kane subscribed in a couple of clicks but could not cancel the same way.",
194
+ pass: "Kane cancelled the subscription online as easily as it signed up.",
195
+ },
196
+ stat: () => [`${first && first.result ? first.result.cancelClicks : "—"} → ${lastMain && lastMain.result ? lastMain.result.cancelClicks : "—"}`, `steps to cancel (signup: ${first && first.result ? first.result.signupClicks : "—"})`],
197
+ exhibit: () => `
198
+ <div class="ex-grid">
199
+ <div>
200
+ <p class="lead">${esc(first.result.why)}</p>
201
+ <div class="paths">
202
+ <div><h4>Subscribing · ${first.result.signup.length}</h4><ol>${first.result.signup.map((x) => `<li>${esc(x)}</li>`).join("")}</ol></div>
203
+ <div class="bad"><h4>Cancelling · ${first.result.cancel.length}${first.result.confirmed ? "" : ", never confirmed"}</h4><ol>${first.result.cancel.map((x) => `<li>${esc(x)}</li>`).join("") || "<li>No way found</li>"}</ol></div>
204
+ </div>
205
+ </div>
206
+ ${shot(first.shots[first.shots.length - 1], first.key, "Where Kane's attempt to cancel ended.")}
207
+ </div>`,
208
+ },
209
+ price: {
210
+ headline: {
211
+ fixed: "Kane found a fee that only appeared at checkout. Claude Code fixed it. Kane proved the shopper now pays the price they were shown.",
212
+ violation: "Kane found a fee that only appeared at checkout.",
213
+ pass: "Kane paid the price it was shown, apart from shipping and tax.",
214
+ },
215
+ stat: () => {
216
+ const e = (r) => (r && r.extra != null ? r.extra.toFixed(2) : "—");
217
+ return [`${e(first && first.result)} → ${e(lastMain && lastMain.result)}`, "added at checkout beyond the shown price"];
218
+ },
219
+ exhibit: () => `
220
+ <div class="ex-grid">
221
+ <div>
222
+ <p class="lead">${esc(first.result.why)}</p>
223
+ <div class="paths">
224
+ <div><h4>Shown on the product page</h4><ol><li class="mono">${esc((first.result.readings || {}).product_price || "—")}</li></ol></div>
225
+ <div class="bad"><h4>Total at checkout</h4><ol><li class="mono">${esc((first.result.readings || {}).checkout_total || "—")}</li>${first.result.shipping ? `<li>shipping ${first.result.shipping.toFixed(2)}</li>` : ""}${first.result.tax ? `<li>tax ${first.result.tax.toFixed(2)}</li>` : ""}</ol></div>
226
+ </div>
227
+ </div>
228
+ ${shot(first.shots[first.shots.length - 1], first.key, "The checkout page Kane read the total from.")}
229
+ </div>`,
230
+ },
231
+ };
232
+ const view = views[main.id] || views.consent;
233
+ const headline = view.headline[status] || "This run could not prove anything either way.";
234
+ const [statBig, statLabel] = view.stat();
235
+
236
+ const exhibit = first && first.result && first.result.verdict === "violation" ? `
237
+ <section class="exhibit">
238
+ <div class="label">Exhibit A · what Kane recorded</div>${view.exhibit()}
239
+ </section>` : "";
240
+
241
+ const timeline = entries.map((e) => {
242
+ if (e.step === "agent") {
243
+ return `<li class="ev agent"><div class="who">Round ${e.round} · Claude Code</div><h3>Changed the app</h3><div class="prose">${md(e.summary)}</div></li>`;
244
+ }
245
+ const pk = packs[e.pack];
246
+ const v = e.result ? e.result.verdict : e.verdict || "inconclusive";
247
+ return `<li class="ev ${v}"><div class="who">Round ${e.round} · Kane · ${esc(pk ? pk.title : e.pack)}</div>
248
+ <h3><span class="pill ${v}">${v === "pass" ? "Proven" : v === "violation" ? "Violation" : "Inconclusive"}</span></h3>
249
+ <p>${esc(e.result ? e.result.why : e.why)}</p>
250
+ ${filmstrip(e.shots, e.key)}
251
+ <p class="links">${e.run ? `<a href="${esc(e.run)}" target="_blank" rel="noopener">Open this run in TestMu Test Manager ↗</a>` : ""}${e.packPath ? `<span class="mono">${esc(path.basename(e.packPath))}</span>` : ""}</p></li>`;
252
+ }).join("");
253
+
254
+ const generated = new Date().toISOString().replace("T", " ").replace(/\.\d+Z$/, " UTC");
255
+ const html = `<!doctype html>
256
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
257
+ <title>Statute · ${esc(main.title)} · ${status === "fixed" ? "Fixed" : status}</title>
258
+ <style>
259
+ @font-face{font-family:IS;src:url(data:font/woff2;base64,${FONT_SERIF}) format("woff2")}
260
+ @font-face{font-family:GS;src:url(data:font/woff2;base64,${FONT_SANS}) format("woff2");font-weight:100 900}
261
+ :root{--bg:#000;--panel:#0b0b0b;--panel2:#141414;--line:rgba(255,255,255,.09);--ink:#fff;--soft:rgba(255,255,255,.66);--mute:rgba(255,255,255,.42);--red:#ff6159;--red-bg:rgba(255,97,89,.12);--green:#5fe3a7;--green-bg:rgba(95,227,167,.12);--amber:#f2c66d;--serif:IS,Georgia,serif;--sans:GS,system-ui,sans-serif}
262
+ *{box-sizing:border-box}html{-webkit-text-size-adjust:100%}
263
+ body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.6 var(--sans);-webkit-font-smoothing:antialiased}
264
+ body:before{content:"";position:fixed;inset:0;pointer-events:none;background:radial-gradient(60% 40% at 50% 0%,rgba(95,227,167,.10),transparent 70%)}
265
+ .wrap{max-width:1080px;margin:0 auto;padding:0 clamp(18px,4vw,32px);position:relative}
266
+ header.top{border-bottom:1px solid var(--line);position:sticky;top:0;z-index:5;background:rgba(0,0,0,.7);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}
267
+ header.top .wrap{display:flex;justify-content:space-between;align-items:center;gap:16px;min-height:60px;font-size:13px;color:var(--mute)}
268
+ header.top .wrap>div:last-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:60%}
269
+ .mark{font:400 24px/1 var(--serif);color:var(--ink);display:flex;align-items:center;gap:10px}
270
+ .mark i{font:500 11px var(--sans);font-style:normal;color:var(--mute);padding:5px 10px;border:1px solid var(--line);border-radius:999px}
271
+ .mono,code{font-family:ui-monospace,"Cascadia Mono",Consolas,Menlo,monospace;font-size:.86em}
272
+ .hero{padding:clamp(48px,8vw,88px) 0 40px;border-bottom:1px solid var(--line)}
273
+ .stamp{display:inline-flex;align-items:center;gap:8px;padding:7px 16px;border-radius:999px;font:400 20px/1 var(--serif);font-style:italic;border:1px solid currentColor;animation:land .9s cubic-bezier(.22,1,.36,1) both}
274
+ .stamp:before{content:"";width:7px;height:7px;border-radius:50%;background:currentColor;box-shadow:0 0 12px currentColor}
275
+ .stamp.fixed,.stamp.pass{color:var(--green);background:var(--green-bg);box-shadow:0 0 40px rgba(95,227,167,.18)}
276
+ .stamp.violation{color:var(--red);background:var(--red-bg);box-shadow:0 0 40px rgba(255,97,89,.18)}.stamp.inconclusive{color:var(--amber)}
277
+ @keyframes land{from{opacity:0;transform:scale(1.4);filter:blur(10px)}to{opacity:1;transform:none;filter:none}}
278
+ h1{font:400 clamp(44px,7vw,84px)/1 var(--serif);margin:22px 0 16px;letter-spacing:-.02em}
279
+ .deck{font-size:clamp(17px,2vw,21px);line-height:1.5;max-width:760px;margin:0;color:var(--soft)}
280
+ .stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px;margin-top:40px}
281
+ .stats div{background:var(--panel);border:1px solid var(--line);border-radius:18px;padding:18px 20px}
282
+ .stats b{display:block;font:400 clamp(26px,4vw,44px)/1.05 var(--serif);font-variant-numeric:tabular-nums;white-space:nowrap}
283
+ .stats div:first-child b{color:var(--green)}.stats span{font-size:13px;color:var(--mute)}
284
+ .label{display:inline-block;font-size:12px;color:var(--soft);padding:6px 12px;border:1px solid var(--line);border-radius:999px;background:rgba(255,255,255,.04);margin-bottom:22px}
285
+ section{padding:clamp(44px,7vw,72px) 0;border-bottom:1px solid var(--line)}
286
+ .exhibit{position:relative}
287
+ .ex-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.1fr);gap:clamp(20px,4vw,40px);align-items:start}
288
+ .lead{font:400 clamp(22px,2.6vw,30px)/1.25 var(--serif);margin:0 0 20px}
289
+ .idbox{background:var(--red-bg);border:1px solid rgba(255,97,89,.35);padding:16px 18px;margin:0 0 18px;border-radius:16px}
290
+ .idbox span{display:block;font-size:13px;color:var(--red)}.idbox code{display:block;font-size:clamp(18px,4.6vw,26px);word-break:break-all;margin:6px 0;color:var(--ink)}.idbox small{color:var(--mute)}
291
+ .meta{font-size:14px;color:var(--mute)}
292
+ figure{margin:0}figure img{width:100%;border:1px solid var(--line);border-radius:14px;display:block}
293
+ .zoom{position:relative;overflow:hidden;border:1px solid var(--line);border-radius:14px;background:#111}.zoom img{position:absolute;max-width:none;border:0;border-radius:0}
294
+ .zoom i{position:absolute;border:2px solid var(--red);border-radius:8px;box-shadow:0 0 0 9999px rgba(0,0,0,.35),0 0 24px rgba(255,97,89,.6)}
295
+ figcaption{font-size:13px;color:var(--mute);margin-top:10px}
296
+ .tw{overflow-x:auto;margin-top:32px;-webkit-overflow-scrolling:touch;background:var(--panel);border:1px solid var(--line);border-radius:18px;padding:6px 18px}
297
+ table.t{width:100%;min-width:640px;border-collapse:collapse;font-size:14px}
298
+ .t th{text-align:left;font-weight:500;font-size:12px;color:var(--mute);border-bottom:1px solid var(--line);padding:12px 12px 12px 0}
299
+ .t td{border-bottom:1px solid var(--line);padding:12px 12px 12px 0;vertical-align:top;color:var(--soft)}.t tr:last-child td{border-bottom:0}.t .num{text-align:right;color:var(--ink)}
300
+ .t tr.after td:first-child{color:var(--red)}.t tr.before td:first-child{color:var(--amber)}.t small{color:var(--mute)}
301
+ ol.timeline{list-style:none;margin:0;padding:0;position:relative}
302
+ ol.timeline:before{content:"";position:absolute;left:8px;top:10px;bottom:10px;width:1px;background:linear-gradient(var(--red),var(--line) 40%,var(--green))}
303
+ .ev{position:relative;padding:0 0 40px 44px}
304
+ .ev:before{content:"";position:absolute;left:0;top:6px;width:17px;height:17px;border-radius:50%;background:var(--bg);border:2px solid var(--mute)}
305
+ .ev.violation:before{border-color:var(--red);background:var(--red);box-shadow:0 0 16px rgba(255,97,89,.6)}
306
+ .ev.pass:before{border-color:var(--green);background:var(--green);box-shadow:0 0 16px rgba(95,227,167,.6)}
307
+ .ev.agent:before{border-color:var(--ink);background:var(--panel2)}
308
+ .who{font-size:13px;color:var(--mute)}
309
+ .ev h3{margin:6px 0 10px;font:400 28px/1.15 var(--serif)}
310
+ .pill{display:inline-block;font:500 12px/1 var(--sans);padding:7px 12px;border-radius:999px}
311
+ .pill.violation{background:var(--red-bg);color:var(--red)}.pill.pass{background:var(--green-bg);color:var(--green)}.pill.inconclusive{background:rgba(242,198,109,.12);color:var(--amber)}
312
+ .ev p{color:var(--soft)}
313
+ .prose{background:var(--panel);border:1px solid var(--line);border-radius:16px;padding:6px 20px;max-width:780px;color:var(--soft)}.prose code{background:rgba(255,255,255,.08);padding:1px 6px;border-radius:5px;color:var(--ink)}.prose strong{color:var(--ink)}
314
+ ol.strip{list-style:none;padding:0;margin:16px 0;display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px}
315
+ .strip a{display:block;text-decoration:none;transition:transform .3s}.strip a:hover{transform:translateY(-2px)}
316
+ .strip img{width:100%;aspect-ratio:16/10;object-fit:cover;object-position:top;border:1px solid var(--line);border-radius:10px;display:block;background:#111}
317
+ .strip span{display:block;font-size:12px;color:var(--mute);margin-top:7px;line-height:1.35}.strip b{color:var(--soft);font-weight:500}
318
+ .links{font-size:14px;display:flex;gap:18px;flex-wrap:wrap;align-items:center}.links a{color:var(--ink);text-underline-offset:4px;text-decoration-color:rgba(255,255,255,.3)}.links .mono{color:var(--mute)}
319
+ .lightbox{display:none;position:fixed;inset:0;background:rgba(0,0,0,.92);z-index:10;padding:4vh 4vw;text-decoration:none;flex-direction:column;align-items:center;justify-content:center}
320
+ .lightbox:target{display:flex}.lightbox img{max-width:100%;max-height:84vh;border-radius:12px;background:#111}.lightbox span{color:var(--soft);margin-top:14px;font-size:14px}
321
+ .paths{display:grid;grid-template-columns:1fr 1fr;gap:12px}.paths>div{background:var(--panel);border:1px solid var(--line);border-radius:16px;padding:16px 18px}
322
+ .paths h4{margin:0 0 8px;font:500 13px var(--sans);color:var(--green)}.paths .bad h4{color:var(--red)}.paths ol{margin:0;padding-left:20px;font-size:14px;color:var(--soft)}.paths li{margin-bottom:4px}
323
+ .law{display:grid;grid-template-columns:1fr 1fr;gap:clamp(20px,4vw,40px)}.law ul{margin:0;padding:0;list-style:none;display:grid;gap:10px}
324
+ .law li{background:var(--panel);border:1px solid var(--line);border-radius:14px;padding:14px 16px;color:var(--soft);font-size:15px}.law li strong{display:block;color:var(--ink);font-weight:500;margin-bottom:2px}
325
+ footer{padding:32px 0 56px;font-size:13px;color:var(--mute)}footer a{color:var(--soft)}
326
+ a{color:var(--green)}a:focus-visible{outline:2px solid var(--green);outline-offset:2px}
327
+ @media (max-width:760px){.ex-grid,.law,.paths{grid-template-columns:1fr}.stats{grid-template-columns:1fr 1fr}.t{font-size:13px}}
328
+ @media (prefers-reduced-motion:reduce){*{animation:none!important;scroll-behavior:auto}}
329
+ </style></head><body>
330
+ <header class="top"><div class="wrap"><div class="mark">Statute<i>Case file</i></div><div title="${esc(loop.url || "")}">${esc(loop.title ? loop.title.split(":")[0] : loop.url || "")}</div></div></header>
331
+ <main class="wrap">
332
+ <div class="hero">
333
+ <span class="stamp ${status}">${status === "fixed" ? "Fixed and proven" : status === "pass" ? "Proven" : status === "violation" ? "Violation" : "Inconclusive"}</span>
334
+ <h1>${esc(main.title)}</h1>
335
+ <p class="deck">${esc(headline)}</p>
336
+ <div class="stats">
337
+ <div><b>${esc(statBig)}</b><span>${esc(statLabel)}</span></div>
338
+ <div><b>${rounds}</b><span>round${rounds === 1 ? "" : "s"}</span></div>
339
+ <div><b>${kaneRuns.length}</b><span>Kane runs in a real browser</span></div>
340
+ <div><b>${credits ? credits.toFixed(1) : "—"}</b><span>Kane credits</span></div>
341
+ </div>
342
+ </div>
343
+ ${exhibit}
344
+ <section>
345
+ <div class="label">What happened</div>
346
+ <ol class="timeline">${timeline}</ol>
347
+ </section>
348
+ <section class="law">
349
+ <div><div class="label">The rule</div><p class="lead">${esc(main.rule)}</p></div>
350
+ <div><div class="label">Why it matters</div><ul>${main.laws.map((l) => `<li><strong>${esc(l.ref)}</strong>: ${esc(l.gist)}</li>`).join("")}</ul></div>
351
+ </section>
352
+ </main>
353
+ <footer><div class="wrap">Evidence, not legal advice. Every verdict on this page is computed by code from Kane CLI's sealed evidence packs. Generated ${generated}. <a href="https://statute-production.up.railway.app">Statute</a></div></footer>
354
+ </body></html>`;
355
+ const file = path.join(out, "index.html");
356
+ fs.writeFileSync(file, html);
357
+ return file;
358
+ }
359
+
360
+ module.exports = { build, steps };
package/src/report.js ADDED
@@ -0,0 +1,59 @@
1
+ // Writes the human report and the fix packet a coding agent reads.
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+
5
+ const PHASE = { after: 'After "Reject"', before: "Before any choice", unknown: "During the visit" };
6
+
7
+ function write(outDir, pack, result, meta) {
8
+ fs.mkdirSync(outDir, { recursive: true });
9
+ const json = { pack: pack.id, title: pack.title, rule: pack.rule, laws: pack.laws, ...result, ...meta };
10
+ fs.writeFileSync(path.join(outDir, `${pack.id}.json`), JSON.stringify(json, null, 2));
11
+
12
+ const lines = [];
13
+ const badge = { pass: "PASS", violation: "VIOLATION", inconclusive: "INCONCLUSIVE" }[result.verdict];
14
+ lines.push(`# ${badge}: ${pack.title}`, "", result.why, "");
15
+ if (result.rejectClick) {
16
+ lines.push(`Kane clicked **${result.rejectClick.label}**${result.rejectClick.time ? ` at ${result.rejectClick.time}` : ""}.`, "");
17
+ }
18
+ lines.push("## Rule", "", pack.rule, "");
19
+ lines.push("## Why it matters", "");
20
+ for (const l of pack.laws) lines.push(`- **${l.ref}**: ${l.gist}`);
21
+ lines.push("", "_Evidence, not legal advice._", "");
22
+
23
+ const reqs = result.trackerRequests || [];
24
+ if (reqs.length) {
25
+ lines.push("## Tracker requests Kane recorded", "", "| When | Tracker | Endpoint | Times | Pages | Visitor ID sent |", "|---|---|---|---|---|---|");
26
+ const order = { after: 0, before: 1, unknown: 2 };
27
+ for (const r of [...reqs].sort((a, b) => order[a.phase] - order[b.phase])) {
28
+ lines.push(`| ${PHASE[r.phase]} | ${r.tracker}${r.consentDenied ? " (consent denied, not counted)" : r.loaderOnly ? " (tag manager code only, not counted)" : ""} | ${r.method || ""} ${r.url} | ${r.count} | ${r.pages.join(", ")} | ${r.ids.join("; ")} |`);
29
+ }
30
+ lines.push("");
31
+ }
32
+ if (result.signup) {
33
+ lines.push(`## Subscribing: ${result.signup.length} click${result.signup.length === 1 ? "" : "s"}`, "");
34
+ result.signup.forEach((x, i) => lines.push(`${i + 1}. ${x}`));
35
+ lines.push("", `## Cancelling: ${result.cancel.length} step${result.cancel.length === 1 ? "" : "s"}${result.confirmed ? ", confirmed" : ", never confirmed"}`, "");
36
+ result.cancel.forEach((x, i) => lines.push(`${i + 1}. ${x}`));
37
+ if (result.kaneReason) lines.push("", `Kane stopped because: ${result.kaneReason}`);
38
+ lines.push("");
39
+ }
40
+ if ((result.trackerCookies || []).length) {
41
+ lines.push("## Tracker cookies present", "", result.trackerCookies.map((c) => `\`${c}\``).join(", "), "");
42
+ }
43
+ if (result.verdict === "violation") lines.push("## How to fix", "", pack.fixHint, "");
44
+ lines.push("## Evidence", "");
45
+ if (meta.evidence) {
46
+ const name = String(meta.evidence).split(/[\\/]/).pop();
47
+ lines.push(process.env.GITHUB_ACTIONS
48
+ ? `- Sealed Kane evidence pack: \`evidence/${name}\` inside the **statute-case-file** artifact (open with \`kane-cli evidence serve <path>\`)`
49
+ : `- Sealed Kane evidence pack: \`${meta.evidence}\` (open with \`kane-cli evidence serve <path>\`)`);
50
+ }
51
+ if (meta.testUrl) lines.push(`- Kane run: ${meta.testUrl}`);
52
+ if (meta.kaneStatus === "failed") lines.push(`- Kane's run ended early (${String(meta.kaneSummary || "no reason given").split("\n")[0]}); the verdict uses what it recorded up to that point.`);
53
+ if (meta.credits != null) lines.push(`- Credits used: ${Number(meta.credits).toFixed(1)}`);
54
+ lines.push("");
55
+ fs.writeFileSync(path.join(outDir, `${pack.id}.md`), "\ufeff" + lines.join("\n"));
56
+ return path.join(outDir, `${pack.id}.md`);
57
+ }
58
+
59
+ module.exports = { write };
package/src/zip.js ADDED
@@ -0,0 +1,38 @@
1
+ // Minimal zip reader (stored + deflate, no zip64). Enough for Kane .evidence packs.
2
+ const zlib = require("zlib");
3
+
4
+ function entries(buf) {
5
+ let eocd = -1;
6
+ for (let i = buf.length - 22; i >= Math.max(0, buf.length - 65557); i--) {
7
+ if (buf.readUInt32LE(i) === 0x06054b50) { eocd = i; break; }
8
+ }
9
+ if (eocd < 0) throw new Error("not a zip file (no end-of-central-directory record)");
10
+ const count = buf.readUInt16LE(eocd + 10);
11
+ let p = buf.readUInt32LE(eocd + 16);
12
+ const out = [];
13
+ for (let n = 0; n < count; n++) {
14
+ if (buf.readUInt32LE(p) !== 0x02014b50) throw new Error("corrupt central directory");
15
+ const method = buf.readUInt16LE(p + 10);
16
+ const compSize = buf.readUInt32LE(p + 20);
17
+ const nameLen = buf.readUInt16LE(p + 28);
18
+ const extraLen = buf.readUInt16LE(p + 30);
19
+ const commentLen = buf.readUInt16LE(p + 32);
20
+ const local = buf.readUInt32LE(p + 42);
21
+ const name = buf.toString("utf8", p + 46, p + 46 + nameLen);
22
+ out.push({ name, method, compSize, local });
23
+ p += 46 + nameLen + extraLen + commentLen;
24
+ }
25
+ return out;
26
+ }
27
+
28
+ function read(buf, entry) {
29
+ const p = entry.local;
30
+ if (buf.readUInt32LE(p) !== 0x04034b50) throw new Error("corrupt local header: " + entry.name);
31
+ const start = p + 30 + buf.readUInt16LE(p + 26) + buf.readUInt16LE(p + 28);
32
+ const data = buf.subarray(start, start + entry.compSize);
33
+ if (entry.method === 0) return data;
34
+ if (entry.method === 8) return zlib.inflateRawSync(data, { maxOutputLength: 256 * 1024 * 1024 });
35
+ throw new Error(`unsupported compression ${entry.method} in ${entry.name}`);
36
+ }
37
+
38
+ module.exports = { entries, read };