Repository navigation
refactor: Recency-Aware Listing - #13
Conversation
4cff5eb to
7441e5b
Compare
Add a single shared recency definition and consume it everywhere recency was previously computed inline or absent: - internal/worktree/recency.go: RecencyOf (worktree-dir mtime, zero time on stat failure), RecencyLess comparator (newest-first, Name-ascending tie-break), and a generic SortByRecency adapter. - wt list: --sort=recent|name|branch plus --non-interactive; audience-split default ordering (TTY->recent, --json/--non-interactive->stable name, explicit --sort overrides); main worktree pinned first under all modes; --sort + --path is mutually exclusive (ExitInvalidArgs). - wt list --status: new "Last Active" relative-time column (LastActive *time.Time opt-in pointer, RFC3339 in JSON; no new git subprocess). - wt open / wt delete: interactive menus list worktrees newest-first via the shared helper, consolidating two duplicated inline mtime loops; newest stays pre-selected. Memory: update list-status-contract.md, add recency-ordering-contract.md, update index.md.
7441e5b to
924226b
Compare
There was a problem hiding this comment.
Pull request overview
This PR promotes worktree recency to a shared concept across wt list, wt open, and wt delete, using worktree directory mtime as the common signal.
Changes:
- Adds shared recency helpers and newest-first ordering.
- Adds
wt list --sort,--non-interactive, recency-aware defaults, andlast_activeunder--status. - Updates open/delete menus, tests, and memory/spec documents.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/internal/worktree/recency.go |
Adds shared recency signal and sort helper. |
src/internal/worktree/recency_test.go |
Tests recency signal and comparator behavior. |
src/cmd/wt/open.go |
Uses shared recency sorting for open menu. |
src/cmd/wt/open_test.go |
Adds open-menu recency ordering coverage. |
src/cmd/wt/list.go |
Adds list sorting, defaults, and last-active display/JSON field. |
src/cmd/wt/list_test.go |
Adds list sorting and last-active coverage. |
src/cmd/wt/delete.go |
Uses shared recency sorting for delete menu. |
src/cmd/wt/delete_test.go |
Adds delete-menu recency ordering coverage. |
fab/changes/260530-rtmf-recency-aware-listing/* |
Adds change intake/spec/plan/status/history metadata. |
docs/memory/wt-cli/recency-ordering-contract.md |
Documents shared recency-ordering contract. |
docs/memory/wt-cli/list-status-contract.md |
Updates list/status contract for sorting and last active. |
docs/memory/index.md |
Links the new recency memory document. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func SortByRecency[T any](items []T, pathOf func(T) string, nameOf func(T) string) { | ||
| sort.SliceStable(items, func(i, j int) bool { | ||
| return RecencyLess( | ||
| RecencyOf(pathOf(items[i])), nameOf(items[i]), | ||
| RecencyOf(pathOf(items[j])), nameOf(items[j]), | ||
| ) | ||
| }) |
There was a problem hiding this comment.
Fixed — SortByRecency now stat's each item once into a precomputed key slice and sorts an index permutation (then applies it), so each item keeps a stable key and the comparator never re-stats or sees a changing mtime mid-sort. (27eadc3)
| recencyKey := func(e listEntry) time.Time { | ||
| if e.LastActive != nil { | ||
| return *e.LastActive | ||
| } | ||
| return wt.RecencyOf(e.Path) | ||
| } | ||
| sort.SliceStable(rest, func(i, j int) bool { | ||
| return wt.RecencyLess( | ||
| recencyKey(rest[i]), rest[i].Name, | ||
| recencyKey(rest[j]), rest[j].Name, | ||
| ) | ||
| }) |
There was a problem hiding this comment.
Fixed — the sortRecent path now precomputes each entry's recency key once (preferring LastActive, falling back to RecencyOf) before sorting an index permutation, so no path is re-stat'd inside the comparator and the ordering key stays consistent through the sort. (27eadc3)
Meta
Pipeline: intake ✓ → spec ✓ → apply ✓ → review ✓ → hydrate ✓ → ship → review-pr
Impact: +734/−96 code (excluding
fab/,docs/) · +1534/−100 totalSummary
wt listhad no sorting — worktrees printed in rawgit worktree list --porcelainorder, burying the one you last touched. Meanwhile "recency" was already computed in two places (open/deletemenus) but inconsistently (copy-pasted mtime loops) and invisibly (only highlighting a default). This change promotes recency to a first-class concept with a single shared definition consumed bylist,open, anddelete, mirroring the opt-in, JSON-aware design established by the--statusflag in PR #9.Changes
internal/worktree/recency.go):RecencyOf(worktree-dir mtime, zero time on stat failure),RecencyLesscomparator (newest-first with deterministic Name-ascending tie-break), and a genericSortByRecencyadapter. Replaces the two duplicated inline mtime loops inopen/delete.wt list --sort=recent|name|branch+ audience-split default: TTY → recent,--json/--non-interactive→ stable name, explicit--sortoverrides in any mode. Adds a--non-interactiveflag. Main worktree pinned to position 1 under all sort modes.--sort+--pathis mutually exclusive (typedExitInvalidArgs).open/deletemenus to full recency ordering: items now list newest-first via the shared comparator (was highlight-only); newest stays pre-selected.wt list --status: relative time (e.g.2h ago) via the opt-inLastActive *time.Timepointer (RFC3339 in JSON, omitted when nil); no new git subprocess.wt-cli/list-status-contract.md, addedwt-cli/recency-ordering-contract.md, updateddocs/memory/index.md.