refactor(optimize): split 1948-line optimize.ts into focused modules#572
Open
tzone85 wants to merge 1 commit into
Open
refactor(optimize): split 1948-line optimize.ts into focused modules#572tzone85 wants to merge 1 commit into
tzone85 wants to merge 1 commit into
Conversation
src/optimize.ts was a 1948-line god file (2.4x the project's healthy ceiling) mixing constants, types, JSONL scanning, ~18 waste-detectors, session helpers, health/trend math, and terminal rendering. Split into 9 cohesive modules under src/optimize/, with optimize.ts kept as a barrel so the public API (runOptimize, scanAndDetect) and every re-exported symbol stay unchanged: - constants.ts (186) — all thresholds, colours, regexes, name sets - types.ts (121) — all shared types - scan.ts (205) — JSONL collection + session scanning - detectors-reads.ts (324) — junk/duplicate reads, claude.md bloat, ratio, cache - detectors-mcp.ts (419) — MCP coverage, schema cost, tool coverage, unused - detectors-ghosts.ts (174) — ghost agents/skills/commands, bash bloat - detectors-sessions.ts (376) — low-worth/context-bloat/outlier session detectors - health.ts (94) — health grade, urgency, trend - render.ts (153) — terminal report rendering - optimize.ts (141) — scanAndDetect + runOptimize + barrel re-exports Behaviour-verbatim relocation (one detector incidentally Prettier-reformatted; token-identical). Verified: tsc --noEmit clean; tsup build OK; 558 tests pass (incl. 108 optimize tests); HEAD-monolith vs this refactor produce byte-identical CLI output on the same data; autoreview confirmed barrel-complete, no duplicate re-exports, single shared resultCache, no circular imports.
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.
What
src/optimize.tswas a 1948-line god file (2.4× a healthy ceiling) mixing constants, types, JSONL scanning, ~18 waste-detectors, session helpers, health math, and rendering. Split into 9 cohesive modules undersrc/optimize/, withoptimize.tskept as a barrel so the public API (runOptimize,scanAndDetect) and every re-exported symbol stay unchanged.Behaviour-verbatim
Functions relocated verbatim (one detector incidentally Prettier-reformatted — token-identical, behaviour-neutral).
Verification
tsc --noEmitclean;tsupbuild OK.optimize.test.ts+ 32optimize-fs.test.ts).resultCache, no circular imports.