Commit Graph

3 Commits

Author SHA1 Message Date
a44c2e46c7 feat: M4 — TUI AI panel on 'a' with toggle, loading/error states
Add the on-demand AI suggestion panel to the TUI so pressing 'a' asks the
configured provider about the current scan result.

Model additions:
- aiSugs field ([]ai.Suggestion) and aiCmd() method that calls
  ai.Provider.Suggest(context.Background(), result)
- aiResultMsg/aiErrorMsg message types for the async flow

Update handler:
- 'a' toggles the panel: if visible, it hides; if hidden, it starts the AI
  request (aiLoading flag guards against duplicates)
- aiResultMsg populates aiSugs and opens the panel
- aiErrorMsg prepends "AI:" to the error and places it in the status bar
  error field (non-blocking — the scan result stays visible)

View:
- aiPanelView renders a separator line, "AI SUGGESTIONS" header, and one
  row per suggestion: [priority] action message, with an indented "$ cmd"
  line when a command is present
- loading state shows " asking AI..." with the dim style
- status bar right-hand hints include "a AI" only when a provider is
  configured (nil check)

Tests:
- 'a' fires aiCmd; second 'a' toggles the panel off
- aiResultMsg opens the panel and populates aiSugs
- aiErrorMsg closes the panel and sets the error with "AI:" prefix
- aiPanelView contains "AI SUGGESTIONS", priority labels, and messages
- AI toggle hides the panel on second press

Verified: go build, go vet, go test -race (12 packages), gofmt clean.
2026-08-02 09:12:56 +02:00
3d389ac3e8 feat: M3 — TUI interaction (periodic scan, countdown, change markers)
Replace the static-scan boot in the TUI with a reactive scan loop anchored
on bubbletea.Tick and user-driven 'r' rescan.

Scan loop (tea.Tick instead of goroutine — no leak):
- Init returns a tick Cmd when --interval > 0; on each tick the model
  fires scanCmd and chains the next tick in the Update handler, producing
  a self-regulating interval loop that stops naturally on quit
- 'r' key triggers an immediate rescan when the model is not already
  loading, for on-demand refresh
- scanResultMsg handler records prevResult, computes status.Changed into a
  changed set (keyed by repo path), and updates lastScan
- scanErrorMsg stores the error text on the model (displayed in the status
  bar) without stopping the loop

Change detection in the view:
- Repos whose state changed since the previous scan get a ▲ prefix (yellow
  bold) in the repo list, distinguishing them from the > cursor

Status bar improvements:
- Countdown "next: 23s" when --interval is active, computed from
  time.Since(lastScan); "scanning…" shown during async scans
- Updated keybinding hints: r refresh, g/G home/end

Navigation additions:
- g/Home jumps to top, G/End jumps to bottom

Styles:
- Changed style (yellow bold foreground) for ▲ markers
- Styles struct now includes all five variants

Tests:
- Home/End keys navigate to first/last repo
- 'r' fires scanCmd when not loading
- ▲ marker appears for changed repos
- Interval tick fires scan when idle
- Countdown "next:" shown in status bar

Verified: go build, go vet, go test -race (12 packages), gofmt clean.
2026-08-02 09:10:56 +02:00
2656f29019 feat: M2 — TUI skeleton (bubbletea model/view/styles)
Ship a working `gitflow tui` command: static scan result rendered as a
lipgloss-styled table, with keyboard navigation and a detail pane.

TUI package (internal/tui):
- Model struct: holds scan result, cursor, detail/help toggles, loading
  state, error display, and injected app/AI/config dependencies
- Update: handles WindowSizeMsg (resize), KeyMsg for navigation (j/↑/k/↓,
  Home/End, Enter/Space for detail, ? for help, q/Ctrl-C for quit), and
  async scanResultMsg/scanErrorMsg for the M3 periodic scan loop
- View: repo list table (STATUS/REPOSITORY/BRANCH/AHEAD-BEHIND/CHGS/STASH)
  with cursor highlighting and dimmed error rows, expandable detail pane
  showing files, and a status bar (scan summary + keybinding hints)
- styles.go: lipgloss Styles (Header/Row/CursorRow/StatusBar) with
  dark/light theme palettes that mirror the CLI's ThemeMode
- Loading and empty states; help overlay with keybinding reference

Presenter API surface (needed by the TUI):
- ShortPath exported (home → ~ collapsing, reused by TUI and CLI)
- StatusSymbolFor exported (✓ ✗ ↑ ↓ ⇄ ◉ ▢ ! symbols, reused)
- ShortPath is kept as a wrapper so internal formatter callers are
  unaffected

CLI (cmd/gitflow):
- newTUICmd: resolves config, builds AI provider, calls tui.New() for the
  initial scan, and runs the bubbletea Program
- Wired into root command under `gitflow tui` with full flag set
  (--dir, --interval, --exclude, etc.)

Dependencies: bubbletea v1.3.10, lipgloss v1.1.0, a stable x/term tree

Testing:
- Model logic tests: cursor navigation (arrow + j/k), bottom/top clamping,
  detail toggle (Enter/Space), ? help, q/Ctrl-C quit, view renders
  repo names/branch/status columns, detail pane shows file lists, help
  overlay shows keybindings, loading/empty states

Verified: go build, go vet, go test -race (12 packages), gofmt clean,
`gitflow tui --help` prints command usage.
2026-08-02 09:08:10 +02:00