trace2rules
Mine and audit coding-agent sessions into evidence-backed AGENTS.md rules.
trace2rules is a local-first CLI. It ingests agent trajectories, mines recurring friction, audits existing AGENTS.md/CLAUDE.md rules against real sessions, and identifies whether each rule is observed, compliant, violated, unobserved, or already enforced by CI/pre-commit.
The output is a proposal, not an automatically applied AGENTS.md.
Quick start
Paste this into your coding agent to audit the current checkout:
Install trace2rules if missing (`uv tool install trace2rules`). Audit this repo's AGENTS.md and CLAUDE.md against my local sessions with `trace2rules audit`. Report unobserved, violated, and unenforced rules, and propose existing CI/pre-commit checks without duplicating configured enforcement.
Or run the audit manually:
trace2rules audit
trace2rules audit --prompt > audit.txt
Paste this into your coding agent to mine your local sessions:
Install trace2rules if missing (`uv tool install trace2rules`). Run `trace2rules run --out-dir reports/` for my local agent sessions. Read the report files and synthesize repo-specific AGENTS.md rules yourself. Keep only rules supported by the evidence.
Or run it manually:
uv tool install trace2rules
trace2rules run --out-dir reports/
An existing AGENTS.md or CLAUDE.md in a session’s cwd is discovered automatically and included in that repo’s prompt. Use --agents PATH only to override discovery from a different checkout.
Then give reports/*.md to your own coding agent to synthesize the rules. run ingests local sessions automatically when the database is empty.
Examples
Auditing a real AGENTS.md
On the Open-SWE swc-project/swc split (188 sessions), the current AGENTS.md audit finds 66 rules: 9 measured, 1 partial, and 56 unmeasured.
| Rule | Coverage | Followed | Violations | Confidence | Enforcement |
|---|---|---|---|---|---|
| Read the codebase before editing | measured | 121 | 64/185 (35%) | high | guidance only |
| Verify assumptions against source and tests | measured | 121 | 64/185 (35%) | high | guidance only |
git commit only after git add |
measured | 8 | 6/14 (43%) | low | guidance only |
| Submodule update before tests | measured | 0 | 32/32 (100%) | medium | guidance only |
Snapshot updates with UPDATE=1 cargo test |
measured | 11 | 147/171 (86%) | high | missing |
cargo fmt --all |
measured | 0 | 185/185 (100%) | high | CI configured |
cargo clippy --all --all-targets -- -D warnings |
measured | 0 | 185/185 (100%) | high | CI configured |
cargo test -p <crate> |
measured | 5 | 158/171 (92%) | high | missing |
--no-verify guard |
partial | 13 | 1/14 (7%) | low | missing |
configured means the command appears in .github/workflows/CI.yml; it does not prove the check is required by branch protection. available means a Makefile/package target exists but is not wired into CI. missing means no mechanism was found.
Rules generated from report prompts
swc-project/swc
- [guidance] Reproduce before editing crate sources: 118 sessions edited source with no preceding failing exec. Start with a targeted test such as
RUSTUP_TOOLCHAIN=1.84.1 cargo test -p swc_ecma_transforms_compat --lib regex_dot_all --offline. - [guidance] Read the exact target range before editing: 72 sessions made 132 edits with no prior read, e.g. inspect the
ExprExtsites incrates/swc_ecma_utils/src/lib.rs. - [enforceable] Require validation after edits: 26 sessions had no test/lint exec after the first edit and 74 of 188 sessions were unvalidated. Add a CI job running
RUSTUP_TOOLCHAIN=1.84.1 cargo test -p <changed-crate> --offline; the pinned toolchain was the successful delta in 21 sessions.
rkkautsar/trace2rules
- [enforceable] Make
uv run pytest -qa required check in.github/workflows/ci.yml. - [enforceable] Keep dependencies declared in
pyproject.tomland install withuv sync --frozen;environment_thrashfound 29 package-manager calls across 7 sessions, 5 failed. - [guidance] Read the owning package module by symbol or range, not whole-file:
src/trace2rules/cli.pyandsrc/trace2rules/ingest.pywere read-only hotspots in 26/77 and 24/77 sessions. - [guidance] Read the target file or exact range before editing: 6 sessions made 274 edits with no prior read of the target, concentrated in
src/trace2rules/cli.pyandsrc/trace2rules/ingest.py. - [guidance] For bug fixes, reproduce the failure first: 4 sessions edited source without a preceding failing exec. Run the narrowest failing test before changing source.
rkkautsar/louibot
- [enforceable] Gate changes with
npm run format:check && npm run build && npm test, matching.github/workflows/ci.yml; 3 sessions used each validation command. - [guidance] Read
src/agent.tsand its matching test before editing: 133 edits had no prior read across 6 sessions, andsrc/agent.tshad 227 reads across 9 sessions. - [enforceable] Block
git push --force-with-leaseoncodex/*branches andrm -rf .louibot/benchmarks/runs/<run>; 3 destructive/gate-bypassing invocations occurred across 3 sessions.
rkkautsar/personal-website
- [enforceable] Run
npm run lint && npm run format:check, plusnpm run check:workerforfunctions/**andnpm run test:discussionforfunctions/api/discussion/[slug].ts; 3 sessions made edits with no test/lint exec after the first edit. - [enforceable] Reproduce API/worker failures before editing source: 3 sessions edited source with no preceding failing exec; extend
npm run test:discussionfirst. - [guidance] Read
src/components/sections/WritingSection.tsx,src/index.css, andsrc/blog/client.tsbefore editing; 117 edits across 3 sessions had no prior read of the target.
Scope
trace2rules proposes durable, normative AGENTS.md rules, not memories.
It targets two destinations:
- Enforceable rules: a CI check, pre-commit hook, lint rule, or test can observe and enforce them.
- Stable AGENTS rules: durable repo or global policy that future agents should follow even though it is not mechanically checkable.
It deliberately does not mine memories, historical decisions, ownership, dates, task state, or "what happened" summaries. Those are contextual and belong in a memory system, not in AGENTS.md. If evidence is descriptive rather than prescriptive, the tool should omit it.
How it works
- Ingest normalizes tool calls into DuckDB (
sessions,tool_events,feedback_events,test_results). - Mining finds hotspots, recovery loops, validation gaps, edit rejections, blind edits, environment thrash, destructive commands, generated-path edits, dependency drift, and correction loops.
- Sequence mining normalizes commands and paths, anchors patterns at errors, allows small gaps, and reports support/failure context. Exact sequences use lift and paired-rework evidence; windows never cross a compaction boundary.
- Report selects bounded findings and writes one readable Markdown evidence prompt per repo.
- Audit checks existing
AGENTS.mdrules against sessions.holdoutsplits sessions by time and audits the same rules on an earlier train slice and later holdout.
Generated verifier scripts and low-support task-specific sequences are filtered before reporting.
Commands
| Command | Purpose |
|---|---|
ingest |
Load sessions and tool events into DuckDB |
mine |
Show friction findings and failure signals |
report |
Emit findings and evidence as JSON or a Markdown report prompt |
run |
Ingest if needed, then write one evidence prompt per detected repo |
doctor |
Check install, Node, source stores, and database schema |
patterns |
Mine error-anchored, normalized attribute patterns |
exact |
Show recurring normalized sequences with evidence |
audit |
Audit existing AGENTS.md rules against sessions and suggest enforcement |
holdout |
Audit rules on an earlier train split and a later time holdout |
Useful options:
trace2rules ingest # ~, all detected local stores
trace2rules ingest --format swe-rebench # opt into the public dataset
trace2rules ingest --format open-swe --repos owner/name
trace2rules ingest --source PATH --limit 200
trace2rules exact --length 4 --per-repo 2
trace2rules patterns --top 10
trace2rules audit --agents AGENTS.md
trace2rules audit --agents AGENTS.md --commit HEAD --json
trace2rules audit --agents AGENTS.md --prompt
trace2rules holdout --agents AGENTS.md --fraction 0.3
trace2rules report --prompt --min-support 5
trace2rules report --prompt --max-rules 5
trace2rules run --out-dir reports/ --max-rules 10
Local sessions
--source is repeatable and defaults to your home directory. It scans:
~/.claude/projects~/.codex/sessions~/.pi/agent/sessions~/.omp/agent/sessions~/.local/share/opencode
The default cap is 200 sessions per source. --limit N selects the newest N files per invocation; re-runs can select a different set when files are added or touched. Use --limit 0 for the full deterministic set. OpenCode is read directly from its SQLite database; JSON exports are still accepted:
uv run trace2rules ingest --format agent-trajectory --source ~/.local/share/opencode
The repository label is inferred from the git remote (owner/name) when available, falling back to the working-directory basename. report --prompt emits one prompt per detected repo:
trace2rules report --prompt --out-dir reports/
Local ingest treats each compaction segment as its own session by default; use --no-split-compactions to keep the original boundaries. This applies to OMP, Pi, Codex, Claude Code, and OpenCode.
run and mine auto-ingest local sessions when the database is empty. ingest writes to $TMPDIR/trace2rules/trace2rules.duckdb by default. Set TRACE2RULES_DB to use a persistent path.
Install
uv tool install trace2rules
# or
pip install trace2rules
For development from a clone:
uv sync
agent-trajectory calls its bundled JS bridge through the system Node runtime for Claude Code, Codex, Pi, and OMP. Install Node.js 20 or newer; OpenCode SQLite ingestion is pure Python.
Supported ingestion formats:
| Format | What it reads |
|---|---|
open-swe |
nvidia/Open-SWE-Traces parquet, cached locally; --repos owner/name is required |
swe-rebench |
nebius/SWE-rebench-openhands-trajectories parquet, opt-in and cached locally |
agent-trajectory |
Local Claude Code, Codex, Pi, OMP, OpenCode SQLite/JSON |
Datasets are not included in this repository.
Configuration
Variables are read from the process environment. trace2rules does not load .env files.
| Variable | Purpose |
|---|---|
TRACE2RULES_DB |
Override the default DuckDB path |
TRACE2RULES_CACHE_DIR |
Local parquet cache; defaults to ~/.cache/trace2rules |
TRACE2RULES_WINDOWS_STORES |
Set to 1 to scan Windows agent stores from WSL |
Data and privacy
- Session data stays in your local DuckDB database.
report/runperform no LLM calls. Findings can still contain commands, paths, and repository names; review before sharing a prompt externally.data/is gitignored.
Known limits
- Detectors are heuristics. Review every proposed rule.
- Local-session formats change frequently.
agent-trajectoryis the compatibility layer; pin its version.
Development
uv sync
uv run pytest
uv build
License
MIT. See LICENSE.
Metadata
Release files for trace2rules 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trace2rules-0.2.0.tar.gz | 90.9 kB | With provenance | Details for trace2rules-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trace2rules-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for trace2rules-0.2.0-py3-none-any.whl |
Total release size: 212.3 kB
Release files / trace2rules-0.2.0.tar.gz
| Download URL | trace2rules-0.2.0.tar.gz |
|---|---|
| Size | 90.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d5a54a288ccc6e5fbcd30df75b51ec03c79f30e2e1c1694e396d1d31291483e
|
|
BLAKE2b-256 checksum How to use checksums |
23d46bbddf6119325389b8168069b5ccd238265fd40ba5b5597cd58931fd15c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / trace2rules-0.2.0-py3-none-any.whl
| Download URL | trace2rules-0.2.0-py3-none-any.whl |
|---|---|
| Size | 121.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e7d1aabfdc23e27730155166ca5c2a581861c2ff8de726c61dfb36042094fa2
|
|
BLAKE2b-256 checksum How to use checksums |
220844f865c219bac22be01b1a7b1ea05e367cfd4b1973667b07ef2e13aecba6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for trace2rules 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for trace2rules-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.