Skip to content

fix(hooks): keep the ledger honest, and stop treating CSS like a module - #19

Merged
sneg55 merged 1 commit into
mainfrom
fix/ledger-integrity-and-stylesheet-tier
Jul 9, 2026
Merged

sneg55 merged 1 commit into
mainfrom
fix/ledger-integrity-and-stylesheet-tier

Conversation

@sneg55

@sneg55 sneg55 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Found while running /reflect for the first time on a real project. Three defects in the harness made recurring_events untrustworthy, so the metric the skill reports on was wrong before any of its advice could be.

The ledger forked

log-event.sh resolved the project root by walking up for the first .git or package.json marker. In a monorepo, web/package.json matched first, so every edit under web/ wrote to web/.harness/ledger.jsonl. A reflection pointed at the repo root silently missed half the signal. On the project where this surfaced, that was 14 of 38 events.

It also meant that second ledger was not covered by a root .gitignore entry anchored at .harness/ledger.jsonl, so private signal was one git add -A from being committed.

Root is now the git toplevel. Fallback is a .git-marker walk (innermost wins, so it stays inside the repo), then an outermost package.json/.claude walk, both bounded at $HOME so a stray dotfiles repo cannot swallow every project.

Paths were absolute

harness-ledger-stats.sh clusters on (rule, path-prefix). file-size and lint stored absolute paths, so every one of their events landed in a single /Users bucket and produced no usable cluster. em-dash was the only rule with meaningful output, and only because it happened to relativize before calling the logger.

Paths are now stored relative to the root. Same ledger, real clusters.

Duplicates were counted twice

A hook registered once by this plugin and again in a user's ~/.claude/settings.json fires twice per edit and writes two identical rows. Every file-size and lint count read exactly 2x high. em-dash, registered once, was the only honest number.

An exact duplicate (same second, rule, file, detail) is now dropped. A genuinely differing event still appends, so the existing append test is unaffected. The dedup guard is belt and braces: it holds even after a user fixes their own double registration.

Stylesheets are not modules

They have no types, constants, validation, or helper functions to extract, so the block message telling Claude to create types.ts is noise. And 200 lines is tight for a language whose unit is roughly one declaration per line.

.css / .scss / .sass / .less now warn at 250 and block at 400, with split-by-layer advice (tokens, base, components, states). Module thresholds and advice are unchanged, and there is a regression test asserting exactly that.

Tests

Adds 7 cases. tests/run.sh is green, all 8 files.

  • path stored relative to project root
  • workspace member does not fork the ledger, and its path is relative to the repo root
  • exact duplicate rejected; a differing event still appends
  • 240-line stylesheet passes, 260 warns, 401 blocks with layer advice and no mention of types.ts
  • 301-line .ts still blocks at 300, still names types.ts

The existing suite caught a real bug in an earlier draft of this change: dropping .git from the fallback marker list made a non-repo tree fall through to $(pwd), scattering .harness/ into whatever the working directory happened to be. That is fixed here, and the fallback now has coverage.

🤖 Generated with Claude Code

Three defects made the recurring_events metric untrustworthy, found while
running /reflect on a real project.

The ledger forked. log-event.sh resolved the project root by walking up for
the first .git OR package.json marker, so an edit under a workspace member
(web/, with its own package.json) wrote to web/.harness/ledger.jsonl. A
reflection pointed at the repo root silently missed half the signal. Root is
now the git toplevel, with a .git-marker walk as fallback, bounded at $HOME
so it cannot escape into a parent dotfiles repo.

Paths were absolute, so harness-ledger-stats.sh clustered every file-size and
lint event under a single useless /Users prefix. Only em-dash, which happened
to relativize before calling, produced meaningful clusters. Paths are now
stored relative to the root.

Duplicate events were counted twice. A hook registered once by this plugin
and again in a user's settings.json fires twice per edit, so every count read
2x high. An exact duplicate (same second, rule, file, detail) is now dropped;
a genuinely differing event still appends.

Separately, stylesheets are not modules. They have no types, constants, or
helper functions to extract, so "extract types.ts" is meaningless advice for
them, and 200 lines is tight for a language of roughly one declaration per
line. CSS/SCSS/Sass/Less now warn at 250 and block at 400, with split-by-layer
advice (tokens, base, components, states). Module thresholds are unchanged.

Adds 7 test cases covering relative paths, the no-fork guarantee, duplicate
rejection, the stylesheet tier, and a regression guard that .ts thresholds and
advice stay put.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sneg55
sneg55 merged commit 5d8b2ee into main Jul 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant