Skip to content

refactor: Recency-Aware Listing - #13

Merged
sahil-noon merged 5 commits into
mainfrom
260530-rtmf-recency-aware-listing
May 31, 2026
Merged

sahil-noon merged 5 commits into
mainfrom
260530-rtmf-recency-aware-listing

Conversation

@sahil87

@sahil87 sahil87 commented May 31, 2026

Copy link
Copy Markdown
Owner

Meta

ID Type Confidence Plan Review
rtmf refactor 3.7/5.0 11/11 tasks, 0/19 acceptance ✓ 1 cycle

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

Impact: +734/−96 code (excluding fab/, docs/) · +1534/−100 total

Summary

wt list had no sorting — worktrees printed in raw git worktree list --porcelain order, burying the one you last touched. Meanwhile "recency" was already computed in two places (open/delete menus) 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 by list, open, and delete, mirroring the opt-in, JSON-aware design established by the --status flag in PR #9.

Changes

  • Shared recency helper + sort comparator (internal/worktree/recency.go): RecencyOf (worktree-dir mtime, zero time on stat failure), RecencyLess comparator (newest-first with deterministic Name-ascending tie-break), and a generic SortByRecency adapter. Replaces the two duplicated inline mtime loops in open/delete.
  • wt list --sort=recent|name|branch + audience-split default: TTY → recent, --json/--non-interactive → stable name, explicit --sort overrides in any mode. Adds a --non-interactive flag. Main worktree pinned to position 1 under all sort modes. --sort + --path is mutually exclusive (typed ExitInvalidArgs).
  • Reordered open/delete menus to full recency ordering: items now list newest-first via the shared comparator (was highlight-only); newest stays pre-selected.
  • "Last Active" column in wt list --status: relative time (e.g. 2h ago) via the opt-in LastActive *time.Time pointer (RFC3339 in JSON, omitted when nil); no new git subprocess.
  • Memory: updated wt-cli/list-status-contract.md, added wt-cli/recency-ordering-contract.md, updated docs/memory/index.md.

@sahil87
sahil87 force-pushed the 260530-rtmf-recency-aware-listing branch from 4cff5eb to 7441e5b Compare May 31, 2026 02:49
@sahil-noon
sahil-noon requested a review from Copilot May 31, 2026 07:28
sahil87 added 3 commits May 31, 2026 12:59
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.
@sahil87
sahil87 force-pushed the 260530-rtmf-recency-aware-listing branch from 7441e5b to 924226b Compare May 31, 2026 07:30

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

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, and last_active under --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.

Comment on lines +39 to +45
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]),
)
})

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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)

Comment thread src/cmd/wt/list.go Outdated
Comment on lines +203 to +214
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,
)
})

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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)

@sahil-noon
sahil-noon marked this pull request as ready for review May 31, 2026 15:36
@sahil-noon
sahil-noon merged commit f4b000d into main May 31, 2026
1 check passed
@sahil-noon
sahil-noon deleted the 260530-rtmf-recency-aware-listing branch May 31, 2026 15:36
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