2026-11-26 15:39 UTC

trace2rules mines agent logs into reviewable repository rules

state: seedheat: mediumuncertainty: mediumrelevance: mediumcoding-agent-memory agent-governance coding-agent-auditrkkautsar

What is this?

Developer rkkautsar released trace2rules, an MIT-licensed, local-first CLI for analyzing coding-agent session logs. It ingests trajectories from several local agent stores or public datasets, mines recurring friction, and audits AGENTS.md/CLAUDE.md guidance against observed sessions. Audits are deterministic; mining produces evidence prompts for rule proposals, which users review and can validate before applying. The project says session data remains in a local DuckDB database, though users should review prompts before sharing them. Its README reports a sample audit of 188 Open-SWE sessions, where 55 of 65 rules were unmeasured. Evidence here is the project’s GitHub README and the developer’s Show HN post; independent adoption or validation is not established.

Why it matters

This turns coding-agent logs into a potential feedback loop for improving repository guidance: recurring mistakes can be surfaced as candidate rules, and existing instructions can be checked against observed behavior. That could make agent workflows more maintainable and auditable without letting an automated system silently rewrite policy. It is a developer tool rather than a new model, and its practical value depends on session coverage, heuristic quality, and human review; the supplied evidence demonstrates a workflow and one example, not broad effectiveness.

Current assessment

New release: rkkautsar’s trace2rules is presented as a local-first CLI for mining coding-agent trajectories and auditing repository instructions. It supports session stores associated with Claude Code, Codex, Pi, OMP, and OpenCode, plus named public datasets. The project says mining makes no LLM calls; optional prompt files can be given to an agent to synthesize proposals. Audits report rule verdicts and enforcement status, and proposed Markdown can be checked before users apply it. This is evidence-backed, reviewable guidance generation—not automatic modification of AGENTS.md, and the README explicitly distinguishes durable normative rules from contextual memory. The author’s sample on an Open-SWE split of 188 sessions reports 65 existing rules, 10 measured and 55 unmeasured; this is a project-reported example, not independent validation. The tool recommends roughly 10 or more local sessions for useful results, notes its detectors are heuristic, and cautions that prompts may contain commands, paths, and repository names. Significance is the possibility of making agent behavior a source of auditable repository policy and identifying guidance that is unobserved, violated, or already enforced. Evidence supplied does not establish adoption, accuracy across projects, or improved agent performance.

Measured heat

now 0 pts/hpeak 2 pts/hcomments 0/hpeers p10momentum: steady2 platformsage 115h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

11-21 20:21 (minted)⭐ origin echo-reconstructedA local-first CLI mines coding-agent sessions for recurring friction, audits AGENTS.md and CLAUDE.md rules against session evidence, and pro
rkkautsar on github (echo) · attributed from hn.story.50592998 · published time unknown
—
11-21 19:55first on hacker news · published · lag ?Show HN: trace2rules – Mine and audit coding-agent logs into AGENTS.md rules
rkkautsar
—
11-21 19:55amplified on hacker news 👑hn.story.50592998
rkkautsar
peak 2 · 1 comments · 98% of case engagement
11-21 20:20our radar first saw it · lag ?discovery anchor: hn.story.50592998—
pace: p41 vs 2105 stories at the 96h mark (now 115h old) — ahead of adobe-max-ai-agents-creative-tools-mcp (1.5x), behind 42loop-agent-operated-product-experiment (0.8x)

Evidence (2) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnShow HN: trace2rules – Mine and audit coding-agent logs into AGENTS.md rules
Retrieved article excerpt

Open article · Retrieved 2026-11-21T20:21:28.316037+00:00

# 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`.

> **Small local corpus?** Results are most useful with about 10+ local sessions. With fewer, ingest a public dataset first; see [Public datasets](https://github.com/rkkautsar/trace2rules#public-datasets).

## Quick start

Paste this into your coding agent to audit the current checkout:

```
Install trace2rules if missing (`uv tool install trace2rules`). Run `trace2rules audit --prompt > audit.txt`, read audit.txt, and list unobserved, violated, and unenforced rules. Propose concrete enforcement without duplicating existing CI/pre-commit checks.
```

Or run the deterministic audit manually:

```
trace2rules audit
```

Paste this into your coding agent to generate rules:

```
Install trace2rules if missing (`uv tool install trace2rules`). Run `trace2rules mine --prompt --out-dir prompts/` for my local agent sessions. Read the prompt files and synthesize repo-specific AGENTS.md rules yourself. Keep only rules supported by the evidence.
```

Or generate the evidence prompts manually:

```
trace2rules mine --prompt --out-dir prompts/
```

See [Auditing AGENTS.md](https://github.com/rkkautsar/trace2rules#auditing-agentsmd) and [Generating rules](https://github.com/rkkautsar/trace2rules#generating-rules) for the full flows.

## Auditing AGENTS.md

`trace2rules audit` is deterministic: it prints counts, coverage, verdicts, enforcement status, and deterministic suggestions.

For a fresh-agent review, emit the evidence prompt:

```
trace2rules audit --prompt > audit.txt
```

Give `audit.txt` to your agent. The LLM receives the audit table but not the deterministic suggestions.

After the agent writes proposed rules, validate them:

```
trace2rules audit --proposal AGENTS.proposed.md
```

`--proposal` parses the proposed Markdown, audits it against sessions, and prints verdicts before you apply it.

On the Open-SWE `swc-project/swc` split (188 sessions), the current `AGENTS.md` audit finds 65 rules: 10 measured, 0 partial, and 55 unmeasured.

| Rule | Followed | Violations | Confidence | Enforcement |
| --- | --- | --- | --- | --- |
| Commit frequently | 136 | 52/188 (28%) | high | missing |
| No nightly-only rustc features | 172 | 16/188 (9%) | low | missing |
| Use `gh` for GitHub data | 18 | 6/24 (25%) | medium | `.github/workflows/CI.yml` |
| Snapshot update with `UPDATE=1 cargo test` | 23 | 2/25 (8%) | medium | missing |
| `--no-verify` guard | 13 | 1/14 (7%) | low | missing |
| Read the codebase before editing | 123 | 62/185 (34%) | high | guidance only |
| Verify assumptions against source/tests | 123 | 62/185 (34%) | high | guidance only |
| Submodule update before tests | 0 | 32/32 (100%) | medium | guidance only |
| `git commit` only after `git add` | 8 | 6/14 (43%) | low | guidance only |
| `cargo test -p <crate>` | 14 | 0/14 (0%) | low | missing |

#### LLM review of the swc audit

An `audit --prompt` pass over the same table suggests:

- Delete the four stale binding commands and add a workflow that checks backticked `AGENTS.md` paths at `HEAD`.
- Reword commit cadence: commit one logical change after `cargo fmt --all -- --check` and the narrowest affected `cargo test -p <crate>`.
- Enforce the nightly rule with `cargo +stable check` and a guard rejecting `#![feature(...)]`, `RUSTC_BOOTSTRAP`, and nightly `rust-toolchain.toml`.
- Replace the GitHub access rule with: use `gh`; CI fails on `curl`/`wget` to `github.com`.
- Run snapshot tests with `UPDATE` unset; keep `UPDATE=1` local-only for regeneration.
- Make hooks and CI apply the same checks so `--no-verify` cannot bypass them.
- Consolidate the two read rules into a PR `Source:`/`Test:` requirement.
- Initialize submodules before every test job.
- Stage explicit paths with `git add`; reject `git commit -a`.

The review proposed three new rules: no package-scoped test commands in root `AGENTS.md`, every AGENTS path must exist at `HEAD`, and CI must run with `UPDATE` unset.

MSRV is not measured yet, so the review does not propose a separate MSRV enforcement rule.

`audit` prints the audited/total session count and audits all sessions by default. Pass `--latest-commit` to use the latest `AGENTS.md` commit as a cutoff; use `--since`/`--until` for explicit dates. By default, audit output shows measured and partial rules only; pass `--all-rules` to include unmeasured rules.

## Generating rules

Mining produces evidence, not rules. `trace2rules mine --prompt --out-dir prompts/` writes one prompt per detected repository; give those prompts to your agent. The agent proposes rules, then validate them with `audit --proposal`. Use `--root` when the checkout is not the directory containing `AGENTS.md`, so path and enforcement checks inspect the real repository.

**`swc-project/swc`**

- [guidance] Before changing implementation code, run an existing fixture/test or add a focused failing test and execute it on the unmodified tree; do not use a standalone `/tmp` mock as the only reproduction for changes under `crates/`.
- [guidance] Create one-off reproductions under `/tmp` or as tests/fixtures in the affected crate; do not add a temporary workspace crate or edit workspace `Cargo.toml`/`Cargo.lock` for a reproduction.
- [guidance] When the default toolchain rejects repository rustflags, run cargo with `RUSTUP_TOOLCHAIN=<stable>` and set `RUSTFLAGS` at invocation; do not edit `.cargo/config.toml` to work around the toolchain.
- [guidance] For large source files, read the relevant ranges with `sed -n '<start>,<end>p' <file>` or locate symbols with `rg -n`; do not page whole files until output is clipped.

**`rkkautsar/trace2rules`**

- [guidance] Keep `src/trace2rules/cli.py` limited to Typer wiring and option parsing; put non-CLI logic in a dedicated module under `src/trace2rules/`.
- [guidance] When adding, renaming, or removing a CLI command or option in `src/trace2rules/cli.py`, update the matching row in the `README.md` command table in the same change.

The latest synthesis produced these four rules after the stale-path filter was corrected. Rules are marked `guidance` when no concrete CI, pre-commit, or lint check exists; enforceable rules require a specific check. Validate proposals with `audit --proposal`.

## 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

1. **Ingest** normalizes tool calls into DuckDB (`sessions`, `tool_events`, `feedback_events`, `test_results`).
2. **Mining** finds hotspots, recovery loops, validation gaps, edit rejections, blind edits, environment thrash, destructive commands, generated-path edits, dependency drift, and correction loops.
3. **Sequence mining** normalizes commands and paths, then mines repo-local sequential rules (`antecedent -> specific error`) with support, confidence, lift, and a representative evidence window. Exact sequences use lift and paired-rework evidence; windows never cross a compaction boundary.
4. **Prompt** selects bounded findings and writes one readable Markdown evidence prompt per repo when `mine --prompt` is used.
5. **Audit** checks existing `AGENTS.md` rules against sessions. `holdout` splits 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 prompting.

## Commands

| Command | Purpose |
| --- | --- |
| `ingest` | Load sessions and tool events into DuckDB |
| `mine` | Mine friction findings, JSON, or evidence prompts; auto-ingests local sessions |
| `doctor` | Check install, Node, source stores, and database schema |
| `patterns` | Mine repo-local sequential rules (antecedent → specific error) |
| `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 --root . --prompt
trace2rules audit --agents AGENTS.md --all-rules
trace2rules holdout --agents AGENTS.md --fraction 0.3
trace2rules mine --prompt --min-support 5
trace2rules mine --prompt --max-rules 5
trace2rules mine --prompt --out-dir prompts/ --max-rules 10
trace2rules mine --json
```

## 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. `mine --prompt` emits one prompt per detected repo:

```
trace2rules mine --prompt --out-dir prompts/
```

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.

`mine` and `audit` auto-ingest local sessions. They refresh the default database on each run; explicit `--source` or non-default `--format` triggers ingestion into a custom `--db`. `ingest` writes to `$XDG_DATA_HOME/trace2rules/trace2rules.duckdb` by default (`~/.local/share/...`). Set `TRACE2RULES_DB` to override it.

## Public datasets

Use a public dataset when the local corpus is small. Both datasets are public and require no Hugging Face token. The first run downloads the parquet into `~/.cache/trace2rules`; set `TRACE2RULES_CACHE_DIR` to move it, or pass `--refresh-cache` to re-download.

### `swe-rebench`

[nebius/SWE-rebench-openhands-trajectories](https://huggingface.co/datasets/nebius/SWE-rebench-openhands-trajectories)

```
trace2rules ingest --format swe-rebench
trace2rules ingest --format swe-rebench --repos django__django --limit 50
```

The default repositories are `django__django` and `pytest-dev__pytest`. For `swe-rebench`, `--repos` takes instance prefixes such as `django__django`.

### `open-swe`

[nvidia/Open-SWE-Traces](https://huggingface.co/datasets/nvidia/Open-SWE-Traces)

```
trace2rules ingest --format open-swe --repos owner/name
```

`--repos` is required for `open-swe` and takes repository labels in `owner/name` form. This downloads six public `train-*.parquet` files.

### `agent-trajectory`

rkkautsar21
🟧 echo.github ⭐A local-first CLI mines coding-agent sessions for recurring friction, audits AGENTS.md and CLAUDE.md rules against session evidence, and prorkkautsar——

Interpretation history

Decision trace