Refactor: 17% LOC reduction - #123
Draft
tmck-code wants to merge 10 commits into
Draft
Conversation
Remove comments and docstrings that narrate past changes: rejected alternatives, old constant values, superseded designs, task/decision IDs (D1-D9, "Task 3.2", "task 4.1"), openspec/design.md citations, and a stale "REMOVE AFTER 0.11.0" marker. Compress surviving comments to a terse one-line statement of what the code does, and drop docstrings where the function name and signature already say it. Currently-binding invariants are kept, compressed to one line: column and elbow arithmetic, PUA glyph widths, shed-ladder ordering, width floors, cache key semantics, and subagent status-resolution priority. claude/: 14160 -> 11928 lines (2232 removed, 15.8%). Behaviour unchanged: 1570 tests pass, ruff clean, demo visual diff byte-identical across consecutive renders. Also drops an unused TYPE_CHECKING import and dead branch in yas/tokens.py, and annotates mon.tick(args) which the staged-file mypy gate surfaced. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Tier 1-4 pass across the yas package and mon: - dead code: Pill.gradient_fg, rainbow_color, _parse_iso_to_epoch - dataclass conversions: RowSpec, LayoutSpec, Pill, WindowSlice, SessionView, Theme/Config field plumbing - dedupe: spark_rgb/gradient_rgb share one path; ITALIC_OFF wired through text - RunningSubagent.last_activity is now always a tuple; the None case was unreachable and forced Optional handling at three renderer call sites - docs updated to match (README, CONTEXT, ARCHITECTURE) claude/ 11,929 -> 11,338 lines. No behaviour change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The sub-key trim sorted on repr(float(resume_after)) and dropped the lexicographically smallest, so '9.0' outranked '10.0' and recently-used entries were evicted while stale ones survived. The docstring already claimed recency ordering; now the code matches it. Behaviour change, not a refactor - kept separate from 7970743. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- test_token_rate: FakeTime._now was mutated and never reset, making the file order-fragile under -n auto. Each test now gets an isolated clock. - test_cohort_visibility: _conclusively_retired was stubbed to a constant True, so the real predicate never ran. Un-stubbed and split in two. The real predicate exposes a production bug: its staleness threshold is max(FINISHED_LINGER, COHORT_GRACE) + TERMINAL_SKEW = 125s, while visible()'s own _retired() check uses 120s on the same branch. Anything conclusively retired is therefore already dropped by visible(), leaving the mispredict re-parse block in subagents.py unreachable. Pinned as xfail(strict=True) rather than re-stubbed; the production fix is a separate decision. - test_tokens_cost: the assertion compared a call to itself and could never fail. Now compares default vs explicit show_icons=True, per its docstring. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…elpers - delete ~201 `# ==== Section ====` banner comments (these already violated the repo's pytest style guide) - delete ~328 bare `# setup` / `# run` / `# expected` / `# assert` marker lines; the phases name the code shape, they are not emitted as comments - lift _silence_dynamic into conftest (it was written twice and had drifted) - hoist ~25 function-local strip_ansi imports to module level - drop ~50 redundant Renderer() instantiations - collapse the test_config.py bool-knob matrix into a parametrised test test/ 22,108 -> 21,275. No test cases added or removed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Covers the audit items the first sweep did not reach: parse_cache, test_info parametrisation, table-driven cases in mon_layout / mon_tui / context_line, an inert idiom in subagent_rows, plus mon_discovery and migrate. test/ 21,275 -> 20,986. Collected count unchanged at 1572. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
One in test_info.py, one in test_task_list.py. Each had a surviving copy with the same body, fixtures and parametrisation, so collected count drops 1572 -> 1570 with no loss of coverage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@DataClass costs class-DEFINITION time, not per-instance time: dataclasses._process_class ran 16 times at import for ~11ms, about 24% of total runtime. The statusline is a cold-start CLI invoked on every prompt, so import time is runtime - make bench measured 1.13-1.18x slower than main with non-overlapping minima. All 16 sites (themes, pill, layout, tasks_view, config, session, subagents, toolcounts) are now hand-written __slots__ classes. Bench is back to 1.01-1.02x with overlapping minima. Costs +412 lines against the LOC goal. Correct trade: the lines are paid once, the milliseconds are paid on every render. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
KNOWN_ISSUES.md covers why @DataClass is banned in claude/yas (class- definition cost paid at import, and import time is runtime for a cold-start CLI), with the measurements, plus the two production bugs found during the LOC work: the unreachable recovery block in subagents.py and the wide-char bug in mon/layout.py::_visible_len. CODING_STANDARDS.md gets the one-paragraph ruling under deliberate deviations, pointing at the detail. Co-Authored-By: Claude Opus 5 <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.
Context
LOC reduction across
claude/(yas) andtest/, without deleting working code or tests.claude/(yas)test/Changes
Where the yas reduction came from
Pill.gradient_fg,rainbow_color,_parse_iso_to_epoch),spark_rgb/gradient_rgbdedupe@dataclassto__slots__classes (see Benchmark)Where the test reduction came from
# setup/# run/# expected/# assertmarkers, and their blank lines_silence_dynamiclifted to conftest (3 drifted copies), hoistedstrip_ansiimports, dedupedRenderer()instantiationsCollected tests: 1571 -> 1570.
Behaviour changes
repr(float(resume_after))and dropped the lexicographically smallest, so'9.0'outranked'10.0'— recently-used entries were evicted while stale ones survived. Now sorts by recency, as its docstring always claimed.RunningSubagent.last_activitytightened fromtuple | Noneto always-tuple. TheNonebranch was unreachable and forcedOptionalhandling at three renderer call sites.Test defects fixed
test_token_rate.py:FakeTime._nowwas mutated and never reset — order-fragile under-n auto.test_cohort_visibility.py: stubbed_conclusively_retiredto a constant, so the real predicate never ran.test_tokens_cost.py: an assertion compared a call to itself and could never fail.Two pre-existing bugs found, not fixed here
Both are written up in
KNOWN_ISSUES.md.claude/yas/info/subagents.py~1081-1122._conclusively_retiredrequires 125s staleness (max(FINISHED_LINGER, COHORT_GRACE) + TERMINAL_SKEW);visible()'s own_retired()uses 120s on the same branch. Anything conclusively retired is already gone, so the mispredict re-parse block never executes. Pinned asxfail(strict=True). Fix is to align the constants or delete the block.claude/mon/layout.py::_visible_lenmishandles wide characters.Why not more
themes.pyis 1,641 lines of palette data; 0 of 39Themefields are identical across all 15 themes.build_wideandsubagent_row, are dense column arithmetic, not boilerplate.Further reduction means deleting tests or working code.
Checklist
Screenshots / recording
Renderer code changed, but the demo gate shows no drift: a baseline built in a separate worktree and run twice fingerprints the pre-existing elapsed-time noise, and every remaining diff falls in those classes.
Benchmark
mainPRConverting 16 classes to
@dataclassmade the branch 1.13-1.18x slower thanmain, minima non-overlapping. The cost is class-definition time, not per-instance:dataclasses._process_classran 16 times at import for ~11ms, ~24% of total runtime. The statusline is a cold-start CLI run on every prompt, so import time is runtime. All 16 sites are now hand-written__slots__classes, at +412 lines. Ruling recorded inCODING_STANDARDS.mdandKNOWN_ISSUES.md.pytest, ruff and the demo gate all stayed green through the regression. Only
make benchcaught it.System info