Skip to content

Fix profile-dependent code usage reflow from shared provider width #4

Description

@atyrode

Context

Switching authentication vaults in code can shift or recompose the Usage layout even when the two provider blocks would fit at their independent widths. The affected live state initially looked email-dependent, but terminal-cell measurement showed the longest row was a Claude Fable unavailable row rather than the account email.

This is separate from atyrode/dotfiles#220's investigation into an in-session OMP footer, but the corrected measurement and responsive primitives should become the reusable foundation for that work.

Proven root cause

layoutGroups computes one global colW from the widest rendered row across every provider, then assigns that width to every provider and tests horizontal fit with:

available width >= global maximum × provider count

Observed affected-state widths using lipgloss.Width:

  • account identity row: 31 cells;
  • tight usage row: 48 cells;
  • Fable unavailable row: 53 cells.

After the current two-cell allowance, one 55-cell Claude requirement is duplicated onto Codex, producing a 110-cell threshold even though Codex needs less.

Git history shows the stale invariant:

  • 2d9ddec introduced horizontally joined provider blocks;
  • 38cc253 added colW * len(order) fit selection;
  • a143bd4 established a single global colW;
  • 402eed2 / PR fix(code): harden auth vault identities dotfiles#214 broadened the maximum scan to all broker identity/status rows without revisiting equal-width allocation.

Why tests missed it

The current package and focused responsive tests pass. They protect no overflow, bounded height, footer placement, representative compositions, and full long-email visibility. They do not vary asymmetric provider maxima at one fixed viewport or assert cross-vault/state composition stability. Some representative widths derive from the implementation's own measured minima, so an inflated breakpoint can move the test fixture and remain green.

A temporary regression probe demonstrated the missing contract:

provider A allocated width: 49
provider B allocated width: 55
fixed viewport:             104

The independent widths fit (49 + 55 = 104), but current code stacks because it computes 55 * 2 = 110. The probe failed on current main and was removed after diagnosis.

Required change

  • Measure intrinsic width per provider block.
  • Decide horizontal fit from the sum of provider widths, not a shared maximum multiplied across siblings.
  • Keep lipgloss.Width terminal-cell measurement.
  • Define responsive elision priority for optional status/identity before changing macro composition.
  • Avoid volatile usage/network fields changing the outer layout unless essential content genuinely cannot fit.
  • Preserve loading/loaded/stale geometry where the content contract permits it.

Permanent regression coverage

  • Asymmetric 49/55 provider blocks remain side by side at a fixed 104-cell viewport.
  • Widening one provider does not change an unrelated provider's allocated width.
  • Provider-order permutations produce the same required total width and fit decision.
  • A fixed-width table covers normal, tight, unavailable, missing, cached/stale, long-identity, and multiple-account states.
  • Same-size vault switches preserve composition whenever independent essential widths fit.
  • Fixed external boundary cases complement implementation-derived breakpoint tests.
  • Optional identity/status elides before core usage values or unrelated panes move.

Visual verification

At identical terminal dimensions, capture every configured test vault/state at wide, fit-boundary, medium, and narrow sizes. Compare provider column starts, usage height, routing boundary, footer position, and horizontal/stacked orientation—not merely whether each individual frame remains in bounds.

Acceptance criteria

  • Provider groups use independently measured widths.
  • The demonstrated 104-cell asymmetric regression passes.
  • Changing only provider/vault content causes no gratuitous macro reflow.
  • No rendered line exceeds the terminal width at representative and boundary sizes.
  • Usage bar, percentage, and reset information outrank optional identity/status under width pressure.
  • Existing loading, stale-data, and provider-availability behavior remains correct.
  • Focused Go tests and character-exact TUI captures cover the regression.
  • Any generic measurement/elision primitive extracted to cli-kit is application-neutral and reused by both call sites rather than duplicated.

Likely ownership

  • pkgs/code-tui/main.go
  • pkgs/code-tui/main_test.go
  • pkgs/cli-kit/ only if a genuinely generic primitive emerges

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions