Repository navigation
fix(hooks): keep the ledger honest, and stop treating CSS like a module - #19
Merged
Merged
Conversation
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>
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.
Found while running
/reflectfor the first time on a real project. Three defects in the harness maderecurring_eventsuntrustworthy, so the metric the skill reports on was wrong before any of its advice could be.The ledger forked
log-event.shresolved the project root by walking up for the first.gitorpackage.jsonmarker. In a monorepo,web/package.jsonmatched first, so every edit underweb/wrote toweb/.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
.gitignoreentry anchored at.harness/ledger.jsonl, so private signal was onegit add -Afrom being committed.Root is now the git toplevel. Fallback is a
.git-marker walk (innermost wins, so it stays inside the repo), then an outermostpackage.json/.claudewalk, both bounded at$HOMEso a stray dotfiles repo cannot swallow every project.Paths were absolute
harness-ledger-stats.shclusters on(rule, path-prefix).file-sizeandlintstored absolute paths, so every one of their events landed in a single/Usersbucket and produced no usable cluster.em-dashwas 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.jsonfires twice per edit and writes two identical rows. Everyfile-sizeandlintcount 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.tsis noise. And 200 lines is tight for a language whose unit is roughly one declaration per line..css/.scss/.sass/.lessnow 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.shis green, all 8 files.types.ts.tsstill blocks at 300, still namestypes.tsThe existing suite caught a real bug in an earlier draft of this change: dropping
.gitfrom 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