act-receipts/: scraper-mcp.act_receipt.v1 schema + Python/JS reference impls#58
Merged
Conversation
… impls Companion code for the part-2 article on cache-friendly action receipts: https://gregshevchenko.com/research/mcp-stack-token-economy-part-2/ A cache-friendly action receipt is what a browser MCP returns after performing a user-shaped action (click, type, submit, scroll), instead of the full DOM. The receipt's byte representation stays stable across calls when the page region the agent acted on didn't change — so Anthropic's 5-minute prompt cache can hit on the next agent turn. Contents: - schema/act_receipt_v1.json — JSON Schema (Draft-07) - schema/act_receipt_v1.md — human-readable spec - python/act_receipts.py — Python reference: validate / canonicalize / hash / score - python/artifact_guard.py — detect_selector_miss_artifact() guard pattern - js/canonical_bytes.mjs — JS port (byte-equivalent with Python) - python/tests/ + js/canonical_bytes.test.mjs — cross-runtime equivalence proven on 4 fixtures (Python generated the goldens; JS asserts the same SHA-256) - scenarios/ — the 3 A/B scenarios from the article (iana / jitter / HN) - examples/jitter_endpoint.py — minimal /test/jitter to reproduce AB2 locally Test status: - python: 23/23 PASS (5 test suites) - js: 7/7 PASS (Node 20+ --test runner) - Cross-runtime byte equivalence VERIFIED — same canonical bytes + same SHA-256 in both runtimes on the shared fixture file License: MIT (matches repo root) Credits: - LakshmanTurlapati/FSB (BSL 1.1) — architectural inspiration; adopted the shape, not the code, so this is an independent clean implementation - u/pquattro on r/ClaudeAI — feedback on part-1 cache-friendliness framing that pushed us to measure the browser-MCP layer too Status: reference implementation, NOT a published npm/PyPI package. Copy what you need; the article documents the boundary of applicability. Default-on stays OFF in our own production stack — wall-time cost on real-prod targets is too steep for a global default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion code for the part-2 article on cache-friendly action receipts:
👉 https://gregshevchenko.com/research/mcp-stack-token-economy-part-2/
A cache-friendly action receipt is what a browser MCP returns after performing a user-shaped action (click, type, submit, scroll), instead of the full DOM. The receipt's byte representation stays stable across calls when the page region the agent acted on didn't change — so Anthropic's 5-minute prompt cache can hit on the next agent turn.
What ships in
act-receipts/schema/act_receipt_v1.jsonschema/act_receipt_v1.mdpython/act_receipts.pypython/artifact_guard.pydetect_selector_miss_artifact()— useful for any CSS-selector LLM evaljs/canonical_bytes.mjspython/tests/+js/canonical_bytes.test.mjsscenarios//test/jitter/ HN)examples/jitter_endpoint.py/test/jitterto reproduce AB2 locallyTest status
python -m unittest discover -s testsnode --test canonical_bytes.test.mjsArticle TL;DR
Three honest measurements on a real browser-MCP:
/test/jitter, controlled noise): +80pp delta. Mechanism works on documented DOM jitter.unique_hashes2 vs 3 (+5pp by count), modal-fraction -25pp (metric artifact at bimodal N=20), and wall_ms +3017ms mean (+37%) / +7.7s p95 — real overhead.Default-on stays OFF in our own production stack. The receipt is an opt-in tool for sites with documented DOM noise.
Bonus: an artifact-postmortem where a first reading of +77.8pp turned out to be a CSS selector miss caught by deterministic Python repro. There's now a permanent
detect_selector_miss_artifact()guard — useful to anyone running LLM evals against CSS-selectored regions.Credits
License
MIT (matches repo root).
Why here, not a separate repo
Continuation of the two-axis framework from part 1, which lives in this repo's README + benchmark/. One canonical destination is better than two for discovery.
Status
Reference implementation, not a published package. Copy what you need; the article documents the boundary of applicability.