Skip to content

refactor: wt list — status opt-in, fast by default - #9

Merged
sahil-noon merged 3 commits into
mainfrom
260516-lfa8-list-status-opt-in
May 16, 2026
Merged

sahil-noon merged 3 commits into
mainfrom
260516-lfa8-list-status-opt-in

Conversation

@sahil-noon

Copy link
Copy Markdown
Collaborator

Meta

ID Type Confidence Plan Review
lfa8 refactor 4.7/5.0 13/13 tasks, 35/35 acceptance ✓ ✓ 1 cycle

Pipeline: intake ✓ → spec ✓ → apply ✓ → review ✓ → hydrate ✓ → ship → review-pr

Impact: +389/−138 code (excluding fab/, docs/) · +1004/−188 total

Summary

wt list was paying for a dashboard view by default — forking up to 5 git subprocesses per worktree (3 for dirty, 2 for unpushed). On a 25-worktree repo that meant ~125 forks and 5.5s wall time, scaling linearly with worktree count — exactly the wrong gradient for a discovery command meant to encourage cheap worktree usage. Status enrichment is now opt-in via --status; the default path runs exactly one git worktree list --porcelain invocation regardless of worktree count, targeting ≤100ms wall time.

Changes

  • Default wt list output drops the Status column. Three-column table: Name / Branch / Path. Zero per-worktree git invocations.
  • New --status flag opts back into dirty/unpushed enrichment. Parallel worker pool of min(runtime.NumCPU(), 8); output ordering preserved.
  • Single-call git invocations under --status: git status --porcelain replaces the 3-call checkDirty; git rev-list --count @{u}..HEAD replaces the 2-call getUnpushedInDir (uses @{u} shorthand, drops separate rev-parse).
  • JSON shape: Dirty/Unpushed are now *bool/*int with omitempty. Default mode omits the keys entirely; --status always emits them — so consumers can distinguish "not computed" from "computed and clean".
  • Flag exclusivity: --status + --path rejects with ExitInvalidArgs. --status + --json is permitted.
  • Tests split into default-mode and --status-mode coverage. 9 new tests: flag presence, headers, dirty marker, unpushed marker (↑2), JSON shape, ordering under parallelism, mutex.
  • Docs: docs/specs/cli-surface.md updated; new memory file docs/memory/wt-cli/list-status-contract.md captures the post-change invariants; README sample output and command-reference updated.

Test plan

  • go vet ./src/... clean
  • go test ./src/cmd/wt/... -run TestList -count=1 → 25/25 PASS
  • go test -race ./src/cmd/wt/... -run "TestList_Status.*" → PASS (no data races in worker pool)
  • go test ./src/cmd/wt/... -run TestIntegration -count=1 → 12/12 PASS (unchanged integration tests)
  • Manual: wt list on a 25+ worktree repo confirms sub-100ms wall time (recommended)
  • Manual: wt list --status on same repo confirms dashboard view returns under 1s

sahil87 added 2 commits May 16, 2026 18:49
Default `wt list` now spawns exactly one git subprocess
(`git worktree list --porcelain`) regardless of worktree count — output is
Name/Branch/Path only. Pass `--status` for the dashboard view, which forks
`git status --porcelain` and `git rev-list --count @{u}..HEAD` per worktree
under a bounded worker pool (min(NumCPU, 8)). 5.5s → ≤100ms on a 25-worktree
repo for the default path; ≤1s under --status.

- Replace 3-call checkDirty with single `git status --porcelain`
- Replace 2-call getUnpushedInDir with single `git rev-list --count @{u}..HEAD`
- Split listEntries into Basic (zero per-wt forks) and Enriched (parallel)
- Switch listEntry.Dirty/Unpushed to *bool/*int so omitempty distinguishes
  "not computed" (key absent) from "computed and clean/0" (key present)
- Reject --status + --path with ExitInvalidArgs
- Split tests into default-mode and --status-mode coverage; add 6 new tests
  (--status flag, header, dirty, unpushed, JSON shape, ordering, mutex)
- Update docs/specs/cli-surface.md and README sample output
- Add docs/memory/wt-cli/list-status-contract.md

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors wt list to make per-worktree status enrichment opt-in via a new --status flag. The default path now performs a single git worktree list --porcelain invocation regardless of worktree count, reducing wall time from O(N forks) to O(1). When --status is set, enrichment runs in parallel via a bounded worker pool, and the per-worktree work itself is collapsed (git status --porcelain replaces the 3-call dirty check; git rev-list --count @{u}..HEAD replaces the 2-call upstream lookup).

Changes:

  • Drop Status column from default output; emit Name/Branch/Path only. JSON omits dirty/unpushed keys via *bool/*int + omitempty so consumers can distinguish "not computed" from "clean".
  • New --status flag (mutually exclusive with --path) runs enrichment in a worker pool of min(NumCPU, 8) while preserving porcelain ordering through indexed slice writes.
  • Collapse checkDirty and getUnpushedInDir to single git invocations each.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/cmd/wt/list.go Splits getEnrichedEntries into basic/enriched paths, adds --status flag and worker pool, swaps multi-call git helpers for single-call ones, pointer-field JSON shape.
src/cmd/wt/list_test.go Splits tests into default-mode and --status-mode; adds coverage for flag presence, exclusivity, unpushed marker, parallel ordering, JSON shapes.
README.md Updates sample output and command-reference row to reflect new default.
docs/specs/cli-surface.md Documents --status flag, mutex rules, default-output column set.
docs/memory/wt-cli/list-status-contract.md New memory file capturing post-change invariants.
docs/memory/index.md Indexes the new memory file.
fab/changes/260516-lfa8-list-status-opt-in/* Fab pipeline artifacts (intake/spec/plan/status).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sahil-noon
sahil-noon marked this pull request as ready for review May 16, 2026 13:47
@sahil-noon
sahil-noon merged commit b701f66 into main May 16, 2026
@sahil-noon
sahil-noon deleted the 260516-lfa8-list-status-opt-in branch May 16, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants