<role> You are a senior frontend engineer who specializes in refactoring UI code for…
- User
<current_code> [paste your current UI code here] </current_code>
<target_qualities>
- Modular: split the UI into small, single-responsibility components/modules with clear inputs and boundaries; remove duplicated markup and logic.
- Extensible: structure it so a new UI element or feature can be added by adding code rather than rewriting existing components; expose clear extension points (props, slots, config, etc.).
- Editable: make it easy for a developer to find and change things — descriptive names, separation of structure / styling / logic / data, and configuration or content lifted out of hard-coded markup. </target_qualities>
If a meaningfully better structure would require a small behavior change, flag it rather than making it silently.
<success_criteria> A correct result has: identical behavior and appearance; clear single-responsibility modules; no duplicated UI logic; and a structure where adding a new component or feature is visibly simpler than before. </success_criteria>
focus on https://github.com/nickth3man/bballgenius/tree/main/src/core https://github.com/nickth3man/bballgenius/tree/main/src/shared/ui https://github.com/nickth3man/bballgenius/tree/main/src/shared/utils https://github.com/nickth3man/bballgenius/tree/main/src/tabs
Assistant
This is a terminal UI (TUI) app built on
@opentui/core, not a web/React app — so the pasted template (with its unfilled[paste your current UI code here]placeholders and "React/Vue/vanilla" stack hints) doesn't quite match reality. Let me ground myself in the actual code before critiquing the prompt. Launching parallel exploration of the focus areas.Assistant
I have a thorough picture now. Let me verify a few load-bearing claims directly before critiquing — the shared UI primitives, the tab contract, and how divergent the per-tab focus/key/status code really is.
Assistant
Assistant
Good — one-tab template approach, all four target areas, with flagged tweaks allowed. The pivotal remaining decision is which tab becomes the reference template. Let me read the actual divergent code in the candidate tabs so I can recommend well and write a concrete plan.
Assistant
I now have the concrete divergences in front of me. The one remaining branch is which tab to refactor as the reference template — and I noticed something the plan must respect: status-line separators already differ between tabs (
' | 'in GameCenter/SqlSandbox vs' · 'in TimeMachine), so any shared status-line helper must keep the separator per-tab to stay appearance-identical.Assistant
Time Machine as the reference — the hardest case, which is the strongest proof the abstractions generalize. Before finalizing, let me verify two things that affect the plan: what the existing TimeMachine tests reach into (so the refactor stays test-compatible), and whether the DB fixture for snapshot verification exists locally.
Assistant
The CI fixture exists (
data/fixtures/nba.ci.duckdb), so snapshot/integration tests are runnable — that's my safety net. AndtimeMachine.test.tsreaches into the controllers (PlayerModeController,BbrViewController) via a mockTimeMachineHost, not intofocusIndex/teamFocusIndex— so the focus refactor stays test-compatible as long as I keep theTimeMachineHostshape and controller constructors intact.I have everything I need. Writing the plan.
Assistant
The plan is written. Let me present it for approval.
Assistant
Plan approved. Let me start implementing. First, a baseline run to confirm the gating tests are green before I touch anything — so any later diff is unambiguously mine.
Assistant
Typecheck clean. Now baseline the gating tests:
Assistant
Important — the golden snapshots are already failing on
main, before any change of mine (3 fails, all appear SQL-Sandbox-related). That changes my verification baseline: I need to know exactly which tests are red now so I can tell pre-existing failures apart from any regression I introduce. Let me capture the precise list.Assistant
Critical finding: 3 golden snapshots are already red on
main— includingtime machine team comparison frame, which is my reference tab. These are pre-existing (likely stale snapshots on this Windows/fixture environment), not my doing. So byte-identical comparison against committed goldens isn't a trustworthy gate here. My gate instead becomes differential: the exact set of passing/failing tests must be unchanged before vs. after. Let me record a complete baseline.Assistant
Baseline locked: 127 pass / 6 skip / 3 fail, the 3 fails being pre-existing stale golden snapshots (saved to
/tmp/baseline_fails.txt). My gate: this set must be unchanged after the refactor. Since thetime machine team comparisonsnapshot is already red, I'll also do a direct before/after frame diff for TimeMachine to be certain focus rendering is unchanged.Now let me build the shared abstractions. First, confirm all import sites of
shared/uiso the barrel split stays transparent.Assistant
Baseline locked. The plan is sound; let me verify one coupling before writing code — how the mode controllers and
TimeMachineHostreadfocusIndex/teamFocusIndex, so my getter/setter delegation keeps them untouched.Assistant
All confirmed:
playerMode.ts:170andteamMode.ts:21writehost.focusIndex/teamFocusIndex, so getter/setter delegation is exactly right. AndfocusablePanelsis declared in two places but never read anywhere — safe to remove.Let me build the shared abstractions. Starting with the module split.
Assistant
focus.tsonly uses those classes as types — let me make it a type-only import to satisfy biome.Assistant
Now the barrel
index.ts:Assistant
Module split done. Let me typecheck that the barrel is transparent before touching TimeMachine:
Assistant
Typecheck clean — split is transparent. Now the reference refactor of
timeMachine/tab.ts. I'll work through it in careful, behavior-preserving edits.First, imports and the now-unneeded modulo constants:
Assistant
Now replace the focus state fields with the two
PaneFocusGroupfields:Assistant
Now instantiate the groups in the constructor, after all panels/inputs/scrolls exist:
Assistant
Now replace
focus()and the three private focus helpers with the group-driven version:Assistant
Now the status-line builder. The player status line introspects accumulated parts (
parts.some(p => p.includes(loaded))), so I'll add a smallincludesmethod toStatusLine:Assistant
Now
handleKeyPress→dispatchKeywith the existing checks wrapped in small helpers, preserving exact order:Assistant
Now remove the dead
focusablePanelsfrom theTimeMachineHostinterface:Assistant
Let me typecheck and lint the changes:
Assistant
Biome flags the implicit return in
forEachPanel. Fix with a block body:Assistant
Lint clean. Now the differential test gate — run the full suite and compare failing tests against the baseline:
Assistant
Differential gate passes: 127 pass / 6 skip / 3 fail — identical counts to baseline, and the 3 failing tests are the same pre-existing stale snapshots (game center, time machine, sql sandbox). Note the failure signature is identical across all three tabs — including game center and sql sandbox, which I never touched — confirming it's an environmental header/whitespace normalization artifact, not my changes. (The diff command itself misfired due to redirection order, but the printed names + counts are conclusive.)
Since the
time machinesnapshot was already red and it's my reference tab, let me prove definitively that my refactor did not alter its rendered frame — by capturing the generated frame before vs. after my change viagit stash:Assistant
Definitive proof: the rendered frame is byte-identical before and after my refactor. Combined with the unchanged 127/6/3 test result, the Time Machine reference refactor is provably behavior-preserving — focus, key dispatch, and status line all converged onto the shared abstractions with zero observable change.
Now the last piece of the reference work — target area #4, documenting the conventions in
AGENTS.md. The module map currently omitsshared/uientirely, and there's no documented tab-folder convention. Let me add both:Assistant
Final quick verification that everything's still green (the docs change can't affect tests, but confirming typecheck + lint after all edits):
Assistant