@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.
- package/LICENSE +21 -0
- package/README.md +319 -2
- package/action.yml +356 -0
- package/bin/hook.js +81 -0
- package/bin/init.js +142 -0
- package/bin/mcp.js +166 -0
- package/bin/scope.js +78 -0
- package/bin/shots.js +52 -0
- package/bin/statute.js +362 -0
- package/examples/expect/newsletter_test.md +22 -0
- package/examples/expect/output-newsletter/.internal/execution.json +2053 -0
- package/examples/expect/output-newsletter/.internal/meta.json +39 -0
- package/examples/expect/output-newsletter/.internal/steps/1-d2368411/flows/0/actions.ndjson +2 -0
- package/examples/expect/output-newsletter/.internal/steps/2-a9e761f8/flows/0/actions.ndjson +6 -0
- package/examples/expect/output-newsletter/.internal/steps/3-63305a01/flows/0/actions.ndjson +2 -0
- package/examples/expect/output-newsletter/Result.md +21 -0
- package/examples/expect/search_test.md +20 -0
- package/laws/README.md +24 -0
- package/laws/accept_still_works_test.md +12 -0
- package/laws/cancel_as_easy_as_signup_test.md +15 -0
- package/laws/output-reject_means_reject/.internal/execution.json +1279 -0
- package/laws/output-reject_means_reject/.internal/meta.json +18 -0
- package/laws/output-reject_means_reject/.internal/steps/1-567cc234/flows/0/actions.ndjson +6 -0
- package/laws/output-reject_means_reject/.internal/steps/2-e3c06462/flows/0/actions.ndjson +1 -0
- package/laws/output-reject_means_reject/.internal/steps/3-3040a29b/flows/0/actions.ndjson +2 -0
- package/laws/output-reject_means_reject/Result.md +21 -0
- package/laws/price_shown_is_price_paid_test.md +12 -0
- package/laws/reject_means_reject_test.md +15 -0
- package/package.json +65 -4
- package/replays/cancel-demo-shop/evidence/cancel-1794754943192.evidence +0 -0
- package/replays/cancel-demo-shop/evidence/cancel-1794755110410.evidence +0 -0
- package/replays/cancel-demo-shop/loop.json +32 -0
- package/replays/demo-shop/evidence/consent-1794751413210.evidence +0 -0
- package/replays/demo-shop/evidence/consent-1794751523524.evidence +0 -0
- package/replays/demo-shop/evidence/consent-accept-1794751588395.evidence +0 -0
- package/replays/demo-shop/loop.json +40 -0
- package/replays/haxcms/evidence/consent-1794831086682.evidence +0 -0
- package/replays/haxcms/evidence/consent-1794831262757.evidence +0 -0
- package/replays/haxcms/evidence/consent-accept-1794831347132.evidence +0 -0
- package/replays/haxcms/loop.json +56 -0
- package/replays/in-the-wake-check/consent.json +67 -0
- package/replays/in-the-wake-check/consent.md +32 -0
- package/replays/kane-testmd-demo-shop/evidence/consent-1794935266000.evidence +0 -0
- package/replays/kane-testmd-demo-shop/loop.json +18 -0
- package/replays/lumen-pr-2/evidence/consent-1794929771799.evidence +0 -0
- package/replays/lumen-pr-2/evidence/consent-1794929845913.evidence +0 -0
- package/replays/lumen-pr-2/evidence/consent-accept-1794929886905.evidence +0 -0
- package/replays/lumen-pr-2/loop.json +57 -0
- package/replays/newsletter-expect/evidence/newsletter_test-round1-1795518837738.evidence +0 -0
- package/replays/newsletter-expect/evidence/newsletter_test-round2-1795519079029.evidence +0 -0
- package/replays/newsletter-expect/loop.json +99 -0
- package/replays/price-demo-shop/evidence/price-1794837093949.evidence +0 -0
- package/replays/price-demo-shop/evidence/price-1794837311639.evidence +0 -0
- package/replays/price-demo-shop/loop.json +43 -0
- package/rules/trackers.json +61 -0
- package/site/assets/fonts/OFL-archivo.txt +93 -0
- package/site/assets/fonts/OFL-geist.txt +93 -0
- package/site/assets/fonts/OFL-instrument-serif.txt +93 -0
- package/site/assets/fonts/archivo.woff2 +0 -0
- package/site/assets/fonts/geist.woff2 +0 -0
- package/site/assets/fonts/instrument-serif-italic.woff2 +0 -0
- package/site/assets/fonts/instrument-serif.woff2 +0 -0
- package/site/assets/fonts/inter.woff2 +0 -0
- package/site/assets/fonts/jetbrains-mono.woff2 +0 -0
- package/skill/statute/SKILL.md +57 -0
- package/src/agent.js +70 -0
- package/src/app.js +41 -0
- package/src/evidence.js +80 -0
- package/src/expect-cli.js +296 -0
- package/src/expect-view.js +79 -0
- package/src/expect.js +392 -0
- package/src/infer.js +32 -0
- package/src/kane.js +124 -0
- package/src/pack.js +128 -0
- package/src/packs/cancel.js +83 -0
- package/src/packs/consent-accept.js +57 -0
- package/src/packs/consent.js +237 -0
- package/src/packs/price.js +104 -0
- package/src/page.js +360 -0
- package/src/report.js +59 -0
- package/src/zip.js +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 0xMiiracle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,320 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Statute
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/miracle352/statute/actions/workflows/test.yml)
|
|
4
|
+
|
|
5
|
+
**Your agent's code works. Is it legal?**
|
|
6
|
+
|
|
7
|
+
Ask Claude Code to "add Google Analytics" and it will usually add a cookie banner too, and tell you cookies are "only set if you accept". Is that true? Paste Google's own tag the way its setup page says, and analytics fires before anyone is asked. Either way the site works and every functional test passes, and nobody has checked the one thing the law cares about. Statute is the check your agent can't skip: Kane CLI opens your app in a real Chrome, clicks Reject, reads the checkout, tries to cancel, and records everything. Code, not a model, judges Kane's sealed evidence against the law. On a violation the report goes back to your agent, and Kane returns to prove the fix. A fix only counts when Kane says so.
|
|
8
|
+
|
|
9
|
+
**And for any Kane test, not just the laws: Kane says the steps ran; Statute says what the page did.** Write a few expectations in a Kane test file ("what was typed in *Sign up* never leaves this site", "no request to a tracker after *Refuse cookies*", "no server errors") and Statute checks them against Kane's sealed evidence: every request, cookie, console message and value Kane recorded, across steps, with plain code. See [Expectations for any Kane test](#expectations-for-any-kane-test).
|
|
10
|
+
|
|
11
|
+
There are no tests to write for the laws. The laws are the tests: consent (GDPR and ePrivacy), drip pricing (California SB 478, UK DMCC Act, EU Consumer Rights Directive) and click-to-cancel. It runs on every pull request that could break one, and on your live site every night. The same checks found 7 of 15 big European sites tracking visitors without consent.
|
|
12
|
+
|
|
13
|
+
**Watch the whole loop on a real pull request:** [statute-production.up.railway.app/loop.html](https://statute-production.up.railway.app/loop.html)
|
|
14
|
+
|
|
15
|
+
### What Kane CLI does here
|
|
16
|
+
|
|
17
|
+
Kane isn't a test runner bolted on at the end. Statute uses it three ways:
|
|
18
|
+
|
|
19
|
+
- **As the runtime.** Kane does the work Statute exists for: it uses the app like a visitor, and its sealed evidence pack (network log, action log, screenshots) is the only input to every verdict. For the census, Kane ran in TestMu's cloud browsers in each site's own country, so it saw the cookie banners a local visitor sees. (The live site's browser runs in the US.)
|
|
20
|
+
- **As the build loop.** When an agent fixes a violation, the fix only counts once Kane passes it, in Claude Code (a Stop hook or the agent skill) or in CI.
|
|
21
|
+
- **As the safety net.** On every pull request that touches tracking, prices or subscriptions, and on the live site every night.
|
|
22
|
+
|
|
23
|
+
It also ships inside Kane's own formats: the three laws as Kane CLI test files you can run with `kane-cli testmd run`, and an agent skill alongside Kane's own. See [Use it with Kane CLI directly](#use-it-with-kane-cli-directly).
|
|
24
|
+
|
|
25
|
+
Built for the [Kane CLI Online Hackathon](https://www.kaneclihack.sh/) (12 to 19 November 2026).
|
|
26
|
+
|
|
27
|
+
## For judges: one minute per score
|
|
28
|
+
|
|
29
|
+
| Criterion | The proof |
|
|
30
|
+
|---|---|
|
|
31
|
+
| **Bar 1: works end to end** | Click **Run it live** on the [loop page](https://statute-production.up.railway.app/loop.html): our server copies a shop with Google's tag pasted in, Kane catches it, real Claude Code fixes it, Kane proves the fix, while you watch (about 5 minutes). Or, with no account and no credits: `npx @miracle352/statute demo` |
|
|
32
|
+
| **Bar 2: Kane caught or proved something** | On strangers' live sites: [7 of 15 big European sites](https://statute-production.up.railway.app/#census) tracked visitors without consent; [cruisinginthewake.com](https://statute-production.up.railway.app/cases/in-the-wake.html) tracks before any choice; [HAXCMS](https://statute-production.up.railway.app/cases/haxcms.html) loaded Analytics with no way to refuse; on [3 of 8 online pharmacies](#expectations-for-any-kane-test), a "pregnancy test" search reached an ad or marketing company, twice after refusing cookies. Kane also had a recording gap, now [reported upstream](https://github.com/LambdaTest/kane-cli/issues/249) |
|
|
33
|
+
| **Bar 3: agent and Kane talk to each other** | [miracle352/lumen#2](https://github.com/miracle352/lumen/pull/2): Kane's report went to Claude Code, which fixed the code and said "I haven't re-run Kane"; Kane then proved Decline and Accept, and Statute pushed the fix to the pull request |
|
|
34
|
+
| **Ships** | A [live site](https://statute-production.up.railway.app) that audits your URL, a [GitHub Action](#use-it-in-ci) with `npx @miracle352/statute init`, a [page that judges any Kane evidence pack](https://statute-production.up.railway.app/judge.html), a nightly production watch, a Claude Code hook and [agent skill](skill/statute/SKILL.md), an MCP server, and the laws as [Kane CLI test files](laws/) |
|
|
35
|
+
| **Verified** | Verdicts are code over Kane's sealed evidence, never a model's opinion. 69 tests, including a golden test that re-judges 16 real recorded Kane runs on every commit. A check that can't prove anything says so ("not judged") instead of passing |
|
|
36
|
+
| **Closed loop** | Three places: in CI (the Action fixes and pushes only what Kane passed), in Claude Code (its Stop hook won't let the agent finish until Kane passes), and live on the [loop page](https://statute-production.up.railway.app/loop.html) |
|
|
37
|
+
| **Craft** | No tests to write: the laws are the tests. One command to add it to a repo. A pull request that touches only styles or docs costs 0 credits. Kane's screenshots right in the PR comment |
|
|
38
|
+
|
|
39
|
+
## Start here
|
|
40
|
+
|
|
41
|
+
| Time | What | Where |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| 5 min | **Run the loop live.** Kane catches a pasted Google tag, real Claude Code fixes it, Kane proves the fix, on our server while you watch | [Loop page](https://statute-production.up.railway.app/loop.html) → **Run it live** |
|
|
44
|
+
| 2 min | **The whole loop on a real repo, no human touching code.** A developer pastes Google's tag the way Google's setup page says. Statute reads the diff, Kane finds tracking with no way to refuse, Claude Code adds consent, Kane proves Reject and Accept, and Statute pushes the proven fix to the pull request | [miracle352/lumen#2](https://github.com/miracle352/lumen/pull/2) |
|
|
45
|
+
| 1 min | **The agent's claim, verified.** Asked only to "add Google Analytics", Claude Code added a consent banner and said cookies are set only after Accept. Kane checked: true, with screenshots | [miracle352/lumen#1](https://github.com/miracle352/lumen/pull/1) |
|
|
46
|
+
| 1 min | Watch Kane audit our demo shop live, in a real browser on our server | [statute-production.up.railway.app](https://statute-production.up.railway.app) → "Watch Kane audit our demo shop" |
|
|
47
|
+
| 1 min | Real open-source code: Kane finds HAXCMS loading Google Analytics with no way to refuse, Claude Code adds a banner, Kane proves Decline and Accept. The maintainer closed the PR to solve it in HAXCMS's plugin system instead | [Case file](https://statute-production.up.railway.app/cases/haxcms.html) · [PR haxtheweb/haxcms-nodejs#289](https://github.com/haxtheweb/haxcms-nodejs/pull/289) · [issue #2955](https://github.com/haxtheweb/issues/issues/2955) |
|
|
48
|
+
| 1 min | A live public site, confirmed: cruisinginthewake.com sends 6 Google Analytics hits with a visitor ID before any choice, matching the site's own open issue | [Case file](https://statute-production.up.railway.app/cases/in-the-wake.html) · [their issue #1684](https://github.com/jsschrstrcks1/InTheWake/issues/1684) |
|
|
49
|
+
| 1 min | The Statute Census: 7 of 15 popular European sites tracked visitors without consent, each checked by hand | [Census section](https://statute-production.up.railway.app/#census) |
|
|
50
|
+
| 1 min | Kane inside Claude Code: the agent's "done" blocked until the law holds, in a real session | [Screenshots](#put-kane-inside-your-agent) |
|
|
51
|
+
| 1 min | The GitHub Action commenting a violation on a real pull request, and skipping the PRs that can't break a law | [The PR](https://github.com/miracle352/statute/pulls?q=is%3Apr+%22Test+the+Statute+action%22) · [how](#on-pull-requests-only-when-it-matters) |
|
|
52
|
+
| 1 min | The nightly watch: Kane checks the live site, opens an issue on a violation, closes it once fixed | [Watch issue](https://github.com/miracle352/statute/issues?q=label%3Astatute) · [how](#on-the-live-site-every-night) |
|
|
53
|
+
| 1 min | **Kane passed; the page still leaked.** A newsletter test passes in Kane while the visitor's email goes to Google Analytics. Statute catches it from the same evidence, Claude Code fixes it, Kane and Statute prove the fix. Drop in your own Kane evidence pack on the same page | [Judge a Kane run](https://statute-production.up.railway.app/judge.html) · [how](#expectations-for-any-kane-test) |
|
|
54
|
+
| 1 min | Run it yourself with no Kane credits and no login | `npx @miracle352/statute demo` |
|
|
55
|
+
| 2 min | Add it to your repo: every pull request, plus production every night | `npx @miracle352/statute init --fix --live https://your-site.com` |
|
|
56
|
+
| 10 min | Run the whole loop on your machine (Kane CLI and Claude Code needed, about 31 credits) | `npm run demo:fix` |
|
|
57
|
+
|
|
58
|
+
`demo` needs only Node 22. It re-judges seven recorded runs (Lumen PR #2 from GitHub Actions, the Kane test file on the demo shop, the demo shop's Reject, price and cancel checks, the newsletter expectations, and HAXCMS) from their sealed Kane evidence packs in `replays/` and rebuilds each case file in `statute-report/replay/`. Nothing is sent to Kane.
|
|
59
|
+
|
|
60
|
+
## The checks
|
|
61
|
+
|
|
62
|
+
| Check | The rule | Laws it comes from |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| Reject means reject | After a visitor refuses cookies, no analytics or ads tag may load and no visitor ID may leave the browser. | ePrivacy Directive 2002/58/EC Art. 5(3); GDPR Art. 4(11) and Art. 7; California Civil Code §1798.120 |
|
|
65
|
+
| Accept still works | After Accept, the site's tags load. This is the guard that stops an agent from "fixing" the first check by deleting analytics. | |
|
|
66
|
+
| Cancel as easy as signup | A subscription started online can be cancelled online, in no more steps than it took to start. | Cal. Bus. & Prof. Code §17602; German Civil Code §312k; EU Directive 2023/2673 Art. 11a |
|
|
67
|
+
| The price shown is the price paid | Kane reads the price on the product page and the total at checkout; code compares them after taking off shipping and tax. | California Civil Code §1770(a)(29) (SB 478); UK DMCC Act 2024 s.230; EU Directive 2011/83/EU Art. 6(1)(e) |
|
|
68
|
+
|
|
69
|
+
## How a verdict is made
|
|
70
|
+
|
|
71
|
+
1. **Kane visits.** `kane-cli run --agent` drives Chrome with a plain-English objective: deal with the cookie banner first by refusing, open a page, reload. Kane seals the run into an evidence pack: HAR files, an action log with timestamps, screenshots.
|
|
72
|
+
2. **Code judges.** `src/packs/consent.js` reads the pack. It finds the moment of the Reject click in Kane's action log, splits every request into before and after that moment, and matches hosts against a tracker list (`rules/trackers.json`). It pulls Google Analytics client IDs out of `/g/collect` hits, so "the same visitor ID went out after Reject" is a fact from the traffic, not a guess. Two things are shown but not counted: Google Consent Mode hits that say consent was denied, and Google Tag Manager's own code loading with no measurement hit.
|
|
73
|
+
3. **Your agent fixes.** `statute fix` hands the report, the rule and the law to Claude Code (`claude -p`, edit tools only, working in your app's folder). It restarts your app and sends Kane back.
|
|
74
|
+
4. **Kane proves.** The loop stops when Reject passes *and* Accept still loads the tags, or after three rounds. The case file shows every round with Kane's screenshots and share links.
|
|
75
|
+
|
|
76
|
+
## Expectations for any Kane test
|
|
77
|
+
|
|
78
|
+
Kane's verdict answers "did the steps run?". Kane can also assert on network traffic inside one step, in plain English, and `kane-cli evidence verdict` judges a pack's results against a policy. What nothing checks is the page's behaviour across the whole visit: which hosts got the email the visitor typed two steps earlier, whether a tracker fired at any point after a refusal, whether a request failed behind a page that looks fine. Kane records all of that in the evidence pack anyway. Statute reads it, with code, after the run.
|
|
79
|
+
|
|
80
|
+
Write the expectations in your Kane test file, inside a comment Kane ignores:
|
|
81
|
+
|
|
82
|
+
```markdown
|
|
83
|
+
# Lumen: the newsletter keeps the email address private
|
|
84
|
+
|
|
85
|
+
<!-- expect
|
|
86
|
+
- text "jane.doe@example.com" never leaves this site
|
|
87
|
+
- what was typed in "Sign up for the newsletter" never leaves this site
|
|
88
|
+
- no server errors
|
|
89
|
+
- no failed requests to this site
|
|
90
|
+
-->
|
|
91
|
+
|
|
92
|
+
## Accept cookies
|
|
93
|
+
Go to {{url}}. In the cookie banner, click Accept all.
|
|
94
|
+
|
|
95
|
+
## Sign up for the newsletter
|
|
96
|
+
Type jane.doe@example.com into the newsletter email field and click Sign up. Then wait 10 seconds, so the page's tags have time to send.
|
|
97
|
+
|
|
98
|
+
## Confirmation
|
|
99
|
+
Verify the page says the visitor is on the list.
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npx @miracle352/statute expect examples/expect/newsletter_test.md --url http://localhost:4173/ --start "node demo-store/server.js"
|
|
104
|
+
# and the loop: Claude Code fixes what broke, Kane runs the test again
|
|
105
|
+
npx @miracle352/statute expect examples/expect/newsletter_test.md --url http://localhost:4173/ --start "node demo-store/server.js" --fix --app demo-store
|
|
106
|
+
# judge any sealed pack again, no credits
|
|
107
|
+
npx @miracle352/statute expect .testmuai/evidence/<run>.evidence
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
| Rule | What it catches |
|
|
111
|
+
|---|---|
|
|
112
|
+
**A recorded run.** On our demo shop, the newsletter form sends the address in the page URL, and Google Analytics copies the URL into its hit. Kane ran the test above and **passed** it: every step worked. Statute read the same pack and found `jane.doe@example.com` in a request to `www.google-analytics.com`. Claude Code got the report and changed the form to POST and gated the tags on consent; Kane ran the test again and passed, and this time Statute agreed: the hit went out without the address. Both sealed packs are in [`replays/newsletter-expect/`](replays/newsletter-expect/), and `npx @miracle352/statute replay newsletter-expect` judges them again with no credits.
|
|
113
|
+
|
|
114
|
+
**On real sites.** On 24 November 2026 we ran [`examples/expect/search_test.md`](examples/expect/search_test.md) on 13 large online pharmacies in 9 countries: refuse optional cookies if the site lets you, search for "pregnancy test", wait 10 seconds. Kane got through the search on 8; the other 5 blocked automated browsers or failed to load. On **3 of the 8, the search reached an advertising or marketing company**: on 2 after Kane had refused optional cookies, on 1 that offered no way to refuse. Kane passed 2 of those 3 runs. Of the rest, 1 sent the search to an analytics tool it discloses under "decline advertising cookies", 1 only to its own service providers (site search, an accessibility widget), and 3 kept it on the site. Six were checked from Nigeria, two from the US over a VPN. Each finding was checked against Kane's screenshots of the refusal. We don't publish the names: one run per site isn't enough to accuse anyone, and the test is public, so anyone can repeat it.
|
|
115
|
+
|
|
116
|
+
| `no request to a tracker` / `a third party` / `<host>` `[after\|before\|during "<step>"]` | tags that fire after a refusal, calls to hosts you didn't expect |
|
|
117
|
+
| `no visitor ID sent to a tracker [...]` | Google Analytics client IDs, Meta browser IDs, click IDs in tracker hits |
|
|
118
|
+
| `no tracker cookie [...]` | `_ga`, `_fbp` and other tracker cookies set or sent |
|
|
119
|
+
| `what was typed in "<step>" never leaves this site` | PII sent to another host as typed, URL-encoded, Base64 or SHA-256 hashed (the way ad pixels "match" emails) |
|
|
120
|
+
| `text "<value>" never leaves this site`, `value of $<variable> never leaves this site` | the same, for a fixed value or one Kane read from the page |
|
|
121
|
+
| `no server errors`, `no failed requests to this site`, `no console errors` | failures behind a page that looks fine (favicon noise ignored) |
|
|
122
|
+
| `value $<a> equals \| is at most \| is at least $<b> [plus $<c>]` | numbers Kane stored, compared exactly: price shown against total charged |
|
|
123
|
+
| `clicks in "<step>" at most clicks in "<step>" [plus <n>]` | effort: cancelling against subscribing |
|
|
124
|
+
|
|
125
|
+
**No expectations written? Statute writes them, with code, from what Kane did.** Where Kane typed, it adds `what was typed in "<step>" never leaves this site`; where Kane clicked Reject, Decline or Refuse (in 11 languages; "decline advertising cookies" doesn't count as refusing everything), it adds no tracker request, visitor ID or tracker cookie after that click; and every run gets `no server errors`. So any Kane test or pack you already have can be checked as it is, and Statute prints the rules so you can paste them into the test. On the 19 packs we have here, the inferred rules caught the same leaks as the hand-written ones, including the pharmacy search that went to an ad company after "Weigeren".
|
|
126
|
+
|
|
127
|
+
Steps are your test's `## headings`; "after" and "before" are measured from the last thing Kane did in that step. A rule Statute can't check from the evidence (a missing step, an unknown rule, no network log) is reported as *not checked*, never as a pass. Kane records network traffic while a step runs, not in the gaps between steps ([kane-cli#249](https://github.com/LambdaTest/kane-cli/issues/249)), so a tag that fires a few seconds after a page loads can fall into a gap and go unrecorded; a fast replay from Kane's step cache makes this more likely. Statute checks for it: unless Kane recorded at least 6 seconds of traffic after the last page load, a clean network result is reported as *not checked*, with the fix (end the step that loads the page with a wait). Exit codes are 0, 1 and 3, and a verdict in Kane's own format (the `evidence-cli` verdict schema that `kane-cli evidence verdict` writes) is saved next to the pack as `<pack>.verdicts/statute.verdict.json`.
|
|
128
|
+
|
|
129
|
+
Or judge a pack in the browser: [statute-production.up.railway.app/judge.html](https://statute-production.up.railway.app/judge.html) opens with the recorded run above, draws the whole run on one time axis (what Kane recorded, the gaps it didn't, and the request that broke an expectation), and takes your own `.evidence` file. The pack is read in memory on the server and never stored.
|
|
130
|
+
|
|
131
|
+
It works everywhere the laws do: `tests:` in the GitHub Action, `"tests": [...]` in `statute.json` for the Claude Code hook, and a `statute_expect` tool in the MCP server.
|
|
132
|
+
|
|
133
|
+
## Use it with Kane CLI directly
|
|
134
|
+
|
|
135
|
+
Already use Kane? The laws are plain Kane CLI test files in [`laws/`](laws/). Kane runs them and seals the evidence; Statute's code judges the pack against the law. Kane's own pass only says the steps ran; the legal verdict comes from the evidence.
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
kane-cli testmd run laws/reject_means_reject_test.md --variables '{"url":{"value":"https://your-site.com"}}'
|
|
139
|
+
npx @miracle352/statute judge consent --latest
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Proven on a real run: Kane ran `reject_means_reject_test.md` against the demo shop and reported PASSED, because every step ran. Statute judged the same sealed pack a VIOLATION: Google Analytics and the Meta pixel loaded before any choice and again after Reject, with a visitor ID. Re-judge it yourself with `npx @miracle352/statute demo kane-testmd-demo-shop`.
|
|
143
|
+
|
|
144
|
+
There's one file per law (`reject_means_reject`, `accept_still_works`, `price_shown_is_price_paid`, `cancel_as_easy_as_signup`), each judged with `judge consent`, `consent-accept`, `price` or `cancel`. `--latest` reads the newest sealed pack in `.testmuai/evidence/` or your Kane sessions folder.
|
|
145
|
+
|
|
146
|
+
**The agent skill.** Kane ships a skill so coding agents verify their own work (`npx @testmuai/kane-cli-skill`). Statute's skill sits next to it: after a change to tracking, prices or subscriptions, the agent runs the matching law check, fixes what fails, and isn't done until Kane passes.
|
|
147
|
+
|
|
148
|
+
npx @miracle352/statute skill # for every project
|
|
149
|
+
npx @miracle352/statute skill --project # just this repository (.claude/skills/statute)
|
|
150
|
+
|
|
151
|
+
## Put Kane inside your agent
|
|
152
|
+
|
|
153
|
+
Statute can sit inside the coding agent itself, so the agent hears from Kane without you running anything.
|
|
154
|
+
|
|
155
|
+
**As an MCP server.** Any agent that speaks MCP gets two tools: `statute_check` (Kane checks a page against a rule; the verdict and evidence come back into the conversation) and `statute_rules` (the rules and the laws behind them).
|
|
156
|
+
|
|
157
|
+
claude mcp add statute -- npx -y @miracle352/statute mcp
|
|
158
|
+
|
|
159
|
+
Then ask the agent to "check consent on http://localhost:3000 with statute", or let it decide to after it touches a cookie banner, a price or a subscription flow.
|
|
160
|
+
|
|
161
|
+
**As a Claude Code hook.** When Claude Code is about to finish, Kane checks the app. On a violation the hook blocks the stop and hands Claude the report, so it keeps fixing until Kane passes (three rounds at most). Add `statute.json` and `.claude/settings.json` to your project:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{ "check": "consent", "url": "http://localhost:3000/", "start": "npm run dev", "rounds": 3 }
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{ "hooks": { "Stop": [ { "hooks": [ { "type": "command", "timeout": 900,
|
|
169
|
+
"command": "npx -y @miracle352/statute hook" } ] } ] } }
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`check` can be a list, for example `["consent", "price"]`. Projects without a `statute.json` are left alone.
|
|
173
|
+
|
|
174
|
+
**A real Claude Code session, 16 November 2026.** In the demo shop folder (with the hook and `statute.json` above), I asked Claude Code for something unrelated: *"Add a short newsletter signup line to the homepage footer."* It added the form and tried to finish. The hook ran Kane, which found 6 tracker requests after Reject and the same Google Analytics visitor ID sent three times, and blocked the stop:
|
|
175
|
+
|
|
176
|
+

|
|
177
|
+
|
|
178
|
+
Claude read the report, fixed the shop's tracking code on its own (the tags now load only after Accept), and tried to finish again. Kane re-checked, passed, and the hook let it stop. Nobody typed anything between the two:
|
|
179
|
+
|
|
180
|
+

|
|
181
|
+
|
|
182
|
+
The MCP server in the same session: Claude Code called `statute_check` itself and reported Kane's verdict back:
|
|
183
|
+
|
|
184
|
+

|
|
185
|
+
|
|
186
|
+
## Use it in CI
|
|
187
|
+
|
|
188
|
+
Statute guards two places: every pull request, and the live site every night.
|
|
189
|
+
|
|
190
|
+
### On pull requests, only when it matters
|
|
191
|
+
|
|
192
|
+
With `check: auto`, Statute reads the pull request diff first. Plain pattern matching on the changed lines, no model: a tracker domain from [`rules/trackers.json`](rules/trackers.json), a `gtag(` or `fbq(` call, or cookie and consent code runs the consent check; a fee, price or checkout change runs the price check; subscription or cancellation code runs the cancel check. A change to styles or docs runs nothing, says so on the PR, and costs no Kane credits. When a check does run, the comment says which changed file triggered it.
|
|
193
|
+
|
|
194
|
+
```yaml
|
|
195
|
+
# .github/workflows/statute.yml
|
|
196
|
+
on: pull_request
|
|
197
|
+
permissions:
|
|
198
|
+
contents: read
|
|
199
|
+
pull-requests: write
|
|
200
|
+
jobs:
|
|
201
|
+
statute:
|
|
202
|
+
runs-on: ubuntu-latest
|
|
203
|
+
steps:
|
|
204
|
+
- uses: actions/checkout@v4
|
|
205
|
+
with:
|
|
206
|
+
fetch-depth: 0 # auto needs the diff
|
|
207
|
+
- uses: miracle352/statute@main
|
|
208
|
+
with:
|
|
209
|
+
check: auto # or consent, price, cancel, or several: "consent price"
|
|
210
|
+
url: http://localhost:3000 # or your PR preview URL
|
|
211
|
+
start: npm ci && npm start # leave out when checking a preview URL
|
|
212
|
+
lt-username: ${{ secrets.LT_USERNAME }}
|
|
213
|
+
lt-access-key: ${{ secrets.LT_ACCESS_KEY }}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
You can try the classifier on any diff: `git diff main...HEAD | node bin/scope.js --json`.
|
|
217
|
+
|
|
218
|
+
### On the live site, every night
|
|
219
|
+
|
|
220
|
+
Half of what breaks these laws never goes through a pull request: a tag added in Google Tag Manager, a fee switched on in a payments dashboard, a consent tool's settings changed. Run the same Action on a schedule against production with `issue: "true"`. On a violation it opens an issue with Kane's report; while it keeps failing it adds a comment; once Kane sees the site pass again it closes the issue by itself.
|
|
221
|
+
|
|
222
|
+
```yaml
|
|
223
|
+
# .github/workflows/statute-watch.yml
|
|
224
|
+
on:
|
|
225
|
+
schedule:
|
|
226
|
+
- cron: "17 2 * * *"
|
|
227
|
+
permissions:
|
|
228
|
+
contents: read
|
|
229
|
+
issues: write
|
|
230
|
+
jobs:
|
|
231
|
+
watch:
|
|
232
|
+
runs-on: ubuntu-latest
|
|
233
|
+
steps:
|
|
234
|
+
- uses: miracle352/statute@main
|
|
235
|
+
with:
|
|
236
|
+
url: https://your-site.example
|
|
237
|
+
check: consent price
|
|
238
|
+
issue: "true"
|
|
239
|
+
fail-on: never
|
|
240
|
+
lt-username: ${{ secrets.LT_USERNAME }}
|
|
241
|
+
lt-access-key: ${{ secrets.LT_ACCESS_KEY }}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
This repository runs both on itself: [`statute.yml`](.github/workflows/statute.yml) on pull requests and [`statute-watch.yml`](.github/workflows/statute-watch.yml) every night against the demo shop on the live site. The shop ships with its bugs on purpose, so the watch keeps an issue open: [the watch issue](https://github.com/miracle352/statute/issues?q=label%3Astatute).
|
|
245
|
+
|
|
246
|
+
See the PR comment on a real pull request: [the PR](https://github.com/miracle352/statute/pulls?q=is%3Apr+%22Test+the+Statute+action%22).
|
|
247
|
+
|
|
248
|
+
Set `LT_USERNAME` and `LT_ACCESS_KEY` as repository secrets (your TestMu AI username and access key). Each check that runs costs Kane credits, about 20 to 40.
|
|
249
|
+
|
|
250
|
+
## The live site
|
|
251
|
+
|
|
252
|
+
`server/index.js` serves the site, the demo shop at `/demo`, and live audits. When you start one, the server launches Chrome, Kane drives it, and the console streams Kane's steps, a screenshot of Kane's tab every 0.7 seconds and every request the browser sends. The verdict comes from Kane's evidence pack when the run ends.
|
|
253
|
+
|
|
254
|
+
Guard rails: public `http`/`https` sites only (private, internal and metadata addresses are refused), 40 live audits a day, and a site audited in the last 24 hours shows its saved result. Live audits run the Reject check; the cancel check needs an account and runs on the demo shop.
|
|
255
|
+
|
|
256
|
+
## The Census
|
|
257
|
+
|
|
258
|
+
`bin/census.js` ran the Reject check on 31 popular sites in 17 countries. The first pass ran from my machine. Every site that could not be judged from there was run again from a TestMu AI cloud browser in the site's own country (`kane-cli run --ws-endpoint` with a `geoLocation` capability), so it showed the banner a local visitor sees: 14 sites, 13 of them in Europe.
|
|
259
|
+
|
|
260
|
+
- 15 were judged. **7 kept tracking after Reject or before any choice.** 8 held up.
|
|
261
|
+
- 7 blocked automated browsers and 9 could not be run (more on that below), so they are listed as not judged.
|
|
262
|
+
- Every flagged site was checked by hand against its evidence. One was a false alarm: only Google Tag Manager's code had loaded. We changed the rule in code and re-judged everything from the saved packs (`node bin/census.js --rejudge`), so it is now listed as held up, with a note saying so.
|
|
263
|
+
- Site names stay private (`census/private/`, not in git). The site shows them as "an Italian news site" and so on.
|
|
264
|
+
|
|
265
|
+
## What it doesn't do
|
|
266
|
+
|
|
267
|
+
- **It is evidence, not legal advice.** Statute shows what a browser did and when. Whether that breaks the law where you operate is for a lawyer.
|
|
268
|
+
- **A pass is about one visit.** Kane refuses, opens one page and reloads. A tracker that only fires on checkout or after a scroll would be missed.
|
|
269
|
+
- **The tracker list decides what counts.** A tracker missing from `rules/trackers.json` is not seen. First-party analytics on the site's own domain is not counted.
|
|
270
|
+
- **Kane proves the law, not the whole change.** On HAXCMS, Claude Code's fix passed both Kane checks but showed the banner on sites with no Google Analytics ID at all, which the issue says should stay unchanged. Kane only tested a site that had an ID. A person caught it, and the upstream PR uses a version that skips the banner when there is no ID.
|
|
271
|
+
- **The HAXCMS fix was not merged.** The maintainer, who opened the original issue, closed the PR: he is solving it through a revision of HAXCMS's plugin architecture rather than by changing the page template. The problem Kane found stands; the fix that lands upstream will be theirs, not ours.
|
|
272
|
+
- **My setup mistake, caught by the loop.** On the first HAXCMS run I had left an already-fixed copy of one template file in the example folder, and Claude Code copied it. Its own report said so. I restored the original files, moved my patch out of the folder and ran the loop again; the second run is the one published.
|
|
273
|
+
- **Location matters.** Run from Nigeria, most European sites showed no banner at all, so they could not be judged. That is why the Census switched to in-country cloud browsers. After 16 sessions the cloud browsers stopped accepting new runs on this account, so 9 sites outside Europe were never run.
|
|
274
|
+
- **Kane once filed a fee as shipping.** The first version of the price check asked Kane for "the shipping cost", and Kane put the shop's €4.99 service fee there, so the check passed when it should have failed. Now Kane only copies each checkout line with the shop's own name for it, and code decides which lines are shipping or tax.
|
|
275
|
+
- **Kane's own timeout is not always kept.** One cloud run hung for hours. Every Kane run now has a hard limit (`src/kane.js`), and the run is recorded as not judged.
|
|
276
|
+
- **Some sites block automated browsers.** Those are listed as not judged, never as passes.
|
|
277
|
+
|
|
278
|
+
## Run it locally
|
|
279
|
+
|
|
280
|
+
Node 22, [Kane CLI](https://www.npmjs.com/package/@testmuai/kane-cli) (`npm i -g @testmuai/kane-cli && kane-cli login`), and Claude Code for the fix loop. No npm install: Statute has no dependencies.
|
|
281
|
+
|
|
282
|
+
npm run demo replay recorded runs, no credits
|
|
283
|
+
npm test 69 tests: every judge, the diff check, and a golden test that
|
|
284
|
+
re-judges the 16 recorded Kane runs and fails if a verdict changes
|
|
285
|
+
npm start the site on http://localhost:8080, live audits included
|
|
286
|
+
npm run check:consent one Reject check on the demo shop
|
|
287
|
+
npm run demo:fix find, fix and prove on the demo shop
|
|
288
|
+
npm run demo:reset put the demo shop's bugs back
|
|
289
|
+
npm run check:price one price check on the demo shop
|
|
290
|
+
npm run demo:fix-price find, fix and prove the hidden checkout fee
|
|
291
|
+
npm run demo:hax find, fix and prove on the HAXCMS template
|
|
292
|
+
npm run demo:hax-reset put HAXCMS's original files back
|
|
293
|
+
|
|
294
|
+
node bin/statute.js check consent --url <url> [--start "<cmd>"]
|
|
295
|
+
node bin/statute.js fix consent --url <url> --start "<cmd>" --app <dir>
|
|
296
|
+
|
|
297
|
+
To host it: the `Dockerfile` installs Chrome and Kane CLI. Set `LT_USERNAME` and `LT_ACCESS_KEY` so Kane can sign in on the server.
|
|
298
|
+
|
|
299
|
+
## Layout
|
|
300
|
+
|
|
301
|
+
src/kane.js runs kane-cli, reads its event stream, hard time limit
|
|
302
|
+
src/evidence.js reads Kane evidence packs (HAR, action log, screenshots)
|
|
303
|
+
src/packs/ the checks: consent, consent-accept, cancel, price
|
|
304
|
+
src/agent.js hands a report to Claude Code
|
|
305
|
+
src/page.js builds the case file from sealed evidence
|
|
306
|
+
bin/statute.js check, fix, replay
|
|
307
|
+
bin/mcp.js Statute as an MCP server for coding agents
|
|
308
|
+
bin/hook.js Statute as a Claude Code Stop hook
|
|
309
|
+
bin/scope.js reads a diff and picks the checks it could affect (check: auto)
|
|
310
|
+
bin/shots.js pulls Kane's key screenshots out of the evidence for PR comments
|
|
311
|
+
laws/ the three laws as Kane CLI test files (kane-cli testmd run)
|
|
312
|
+
skill/statute/ the agent skill (statute skill)
|
|
313
|
+
test/ 69 tests, including a golden test over 16 recorded Kane runs
|
|
314
|
+
bin/census.js the Census runner, --rejudge
|
|
315
|
+
server/ the live site, audit queue, Chrome and its live view
|
|
316
|
+
demo-store/ Lumen, a shop with deliberate compliance bugs
|
|
317
|
+
examples/haxcms/ HAXCMS's site template, unchanged, with a GA ID set
|
|
318
|
+
replays/ recorded Kane runs for the zero-credit demo
|
|
319
|
+
|
|
320
|
+
Photos on the site: Wikimedia Commons (CC0 and public domain). HAXCMS template: Apache-2.0.
|