Skip to content

feat(list): expose worktree last activity in schema 2 JSON - #4699

Merged
max-sixty merged 1 commit into
max-sixty:mainfrom
zichen0116:fix/list-json-modified-at
Nov 21, 2026
Merged

max-sixty merged 1 commit into
max-sixty:mainfrom
zichen0116:fix/list-json-modified-at

Conversation

@zichen0116

@zichen0116 zichen0116 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4515.

Problem

Dashboards and cleanup tooling that want a per-worktree last-activity timestamp currently have to re-run git status per worktree, because schema 2 list JSON has no such field.

Change

Adds worktree.modified_at to schema 2 list JSON: the later of head.committed_at and the newest mtime among the changed or untracked files git status reports for that worktree. The statusline's schema 2 JSON envelope carries the same field for its single item and collects the mtimes as well — before this, it never set needs_mtime, so a dirty worktree silently reported the HEAD commit time.

No-value semantics follow the existing Tri pattern:

  • Branch-only rows have no worktree object, so the field is absent there.
  • null when the status is unresolved.
  • A clean worktree reports the commit time without extra filesystem stats.

To collect the file mtimes reliably, the shared cached status query behind wt list gains -z, and the paths that collect mtimes run it with --untracked-files=all instead of normal, still one subprocess per worktree. Only the schema 2 JSON paths collect mtimes — wt list --format=json and the statusline's schema 2 JSON — so the table, the text statusline, and the picker keep the normal query and never pay the per-file stat loop. The old text output quoted unusual filenames and collapsed untracked directories, so paths could not be trusted for stat calls; the NUL-delimited form also expands untracked directories into individual files. parse_working_tree_status, the conflict checks, and the picker diff state all read the same byte-oriented records now. Missing or deleted files are skipped rather than failing the row, and renames use the destination path.

Docs: the worktree field table in the list command help (source for the generated command page and skill mirrors) gains the modified_at row, and docs/public/schema/list-v2.json is regenerated.

Verification

Validated with Rust 1.99 (the pinned 1.98 toolchain install is broken in this environment; no toolchain files were changed):

  • cargo fmt --check — pass
  • cargo clippy --all-targets -- -D warnings — pass
  • cargo test --lib --bins commands::list — 300 passed
  • cargo test --lib --bins — 2597 passed (run with root's cap_dac_override dropped; one permission-based picker test fails under unrestricted root because a read-only directory stays writable there, unrelated to this change)
  • cargo test --test integration integration_tests::list:: — 103 passed, including a new test proving a clean worktree reports the commit time and a dirty worktree with a nested untracked file (with a newline in its name) reports that file's mtime
  • cargo test --test integration integration_tests::readme_sync::test_docs_are_in_sync — pass
  • Six list-JSON snapshots updated; their diffs contain only 33 added modified_at lines

Not run: the full hook pre-merge gate — pre-commit and cargo-nextest are unavailable in this environment, so its all-feature, doctest, and documentation checks remain unrun.

Follow-up (statusline modified_at fix):

  • New test test_statusline_json_modified_at fails before the fix (a dirty worktree's statusline JSON reports the HEAD commit time) and passes after
  • cargo test --test integration for the statusline and list modules — 202 passed
  • cargo test --lib --bins — 1570 + 1017 passed, with only the pre-existing root-environment picker failure noted above
  • cargo fmt --check and cargo clippy --all-targets -- -D warnings — pass

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The field works, and the -z migration of the status consumers looks right. Two costs remain, and both land on every wt list render, not just schema 2 JSON consumers. That trade belongs to a maintainer, so I'm not approving yet. On #4515, switching the shared status call to =all was raised as the open maintainer decision, and nobody has made it on the thread.

  • --untracked-files=all on the shared status query. status_porcelain_cached backs the table, the statusline (re-rendered on every agent prompt), and the picker's diff state, as well as the JSON output. A new untracked directory that isn't ignored used to be one d/ record and is now one record per file. Each of those records is held in the per-worktree cache and cloned on every cache hit.
  • The mtime stat loop runs whenever the worktree is dirty. newest_changed_file_mtime is called from compute_working_tree_diff, so the table, statusline, and picker all pay one symlink_metadata per changed or untracked file and then discard the result. Only json_worktree reads it. With =all, a worktree holding 20k untracked generated files costs 20k stats per render. Computing it only when JSON output is requested would keep the other paths at their old cost. Whether the =all switch should also apply only to JSON is the same decision as above.

Comment thread src/commands/list/collect/tasks.rs Resolved
@zichen0116
zichen0116 force-pushed the fix/list-json-modified-at branch from f9ba4ce to 0ed8417 Compare November 5, 2026 13:29

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This commit is based on current main (79f19f6) but undoes four changes already merged there. That looks like stale copies of whole files from an older checkout. As a result the crate doesn't compile, and lint, fast-checks, feature-check, code-coverage and the macOS/Windows tests are all red. The CI error:

error[E0599]: no method named `create_removal_backup` found for struct `WorkingTree<'a>`
   --> src/git/remove.rs:517:22

What the diff undoes, apart from the modified_at work:

  • #4545, the wt remove --force backup. It deletes WorkingTree::create_removal_backup, record_backup and SafetyBackup::print_recovery_hints from src/git/repository/working_tree.rs. It also deletes their unborn-branch test, and puts back the older create_safety_backup that can't handle an unborn branch. src/git/remove.rs and src/commands/step/squash.rs still call the deleted methods. Don't fix the build by removing those calls: that would make --force discard uncommitted changes without a backup.
  • #4694, the IPv6 loopback probe. In src/commands/list/collect/tasks.rs it removes probe_addr, the ::1 probe in compute_url_status, and both url_status_detects_* tests.
  • #4703 and #4545 help text. In src/cli/mod.rs it drops the Alt-x picker sentence and the refs/wt-backup/<branch> sentence from wt remove help.
  • The wt switch fork-branch paragraph. It restores the older "requires renaming first" wording in place of the current text about falling back to a prefixed branch, which #4542 added.

The help_list_long snapshot change probably carries the same reverted lines. Re-applying only the modified_at changes onto current main should clear all of this.

The earlier concerns about --untracked-files=all and the mtime loop are settled. Both now run only when json_schema == Some(2), and the table and picker keep the normal cache entry.

Because the diff currently removes the --force backup path, I've asked @max-sixty to review.

@zichen0116
zichen0116 force-pushed the fix/list-json-modified-at branch from 0ed8417 to 9cdd035 Compare November 5, 2026 13:38
@zichen0116

Copy link
Copy Markdown
Contributor Author

Thanks for the review — both points are addressed in the latest push (rebased onto current main, single commit):

  • Untracked-files mode is now per-invocation. status_porcelain_cached() is back to --untracked-files=normal for table/statusline/picker; only the schema 2 JSON path requests --untracked-files=all. The shared cache is keyed by (worktree path, mode), so a normal entry can never be served to the JSON path (and vice versa).
  • The mtime stat loop runs only when JSON needs it. A needs_mtime flag threads from handle_list (true only for schema 2 JSON) through CollectOptions/TaskContext into compute_working_tree_diff; the picker passes false explicitly. When off, newest_file_mtime stays None and no per-file stats run.

Verified locally: cargo test --lib --bins (1017 passed; the one failure is the pre-existing test_write_handles_write_failure, which also fails on a clean tree under root), list integration tests 250/250, help 76/76, docs sync passes, cargo clippy --all-targets -- -D warnings clean, fmt clean. JSON output is unchanged (spot-checked: dirty worktree modified_at = newest file mtime, clean worktree = commit time); no table snapshot changed.

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In schema 2, wt list statusline --format=json emits the same JsonItemV2, but it never sets needs_mtime. As a result, a dirty worktree reports modified_at equal to head.committed_at, which is wrong. run_json in src/commands/statusline.rs builds its options with statusline_options, which is CollectOptions::for_columns(...), and that defaults needs_mtime: false. With the flag off, compute_working_tree_diff returns newest_file_mtime: None, drain_results_with_timings stores it as Some(None), and modified_at() treats that as "resolved, no file mtimes", so it falls back to the commit time. A consumer reading the statusline JSON would conclude the worktree hasn't been touched since its last commit even when it has uncommitted edits. There are two possible fixes:

  • Set needs_mtime in run_json when json_schema == 2. That costs one worktree's stats, not the whole repo's.
  • Keep the outer None when mtimes weren't collected, so the field reads null rather than a confident wrong value.

Either way, a statusline JSON case in test_list_json_modified_at, or next to the existing statusline JSON tests, would pin it.

The latest push no longer reverts the --force backup, the IPv6 probe or the help-text changes, and nothing in the diff now widens a deletion. The PR description still says the shared status query moves to --untracked-files=all. Now only the schema 2 JSON path uses all, and every other caller stays on normal (with -z added).

@zichen0116
zichen0116 force-pushed the fix/list-json-modified-at branch from 9cdd035 to 33505c8 Compare November 6, 2026 03:50
@zichen0116

Copy link
Copy Markdown
Contributor Author

Fixed the statusline path: run_json now sets needs_mtime when the resolved schema is 2, so wt list statusline --format=json collects per-file mtimes for its one worktree, and a dirty worktree reports the newest file's mtime instead of falling back to head.committed_at. Schema 1 and the text statusline keep the cheap plan. Added test_statusline_json_modified_at next to the other statusline JSON tests — clean worktree reports the commit time, and a nested untracked file with a pinned mtime is reported exactly; it fails before this change and passes after.

Also updated the PR description: the --untracked-files=all wording now matches the implementation (only the schema 2 JSON paths use it; every other caller stays on normal, with -z added).

Rebased onto current main (d022f768). The two skill reference files keep the anchor repairs from that commit and only add the modified_at row; nothing outside the modified_at change is in the diff.

Local verification: statusline + list integration modules 202 passed; lib/bins 1570 + 1017 passed (the one failure is the known root-environment picker write test); cargo fmt --check and cargo clippy --all-targets -- -D warnings clean.

worktrunk-bot
worktrunk-bot previously approved these changes Nov 6, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

test (windows) fails on test_list_json_modified_at: Windows rejects a newline in a filename, so File::create returns InvalidFilename (os error 123) before wt list runs (job log). The rest of the suite passes on Windows, and Linux and macOS are green. Keeping the newline everywhere except Windows still covers the -z path parsing on the platforms where such names can exist.

Comment thread tests/integration_tests/list.rs Resolved
@worktrunk-bot
worktrunk-bot dismissed their stale review November 6, 2026 04:20

CI failed — test_list_json_modified_at can't create a newline filename on Windows.

@zichen0116
zichen0116 force-pushed the fix/list-json-modified-at branch from 33505c8 to 8180172 Compare November 6, 2026 13:04
@zichen0116

Copy link
Copy Markdown
Contributor Author

Fixed the Windows failure in test_list_json_modified_at: the test used a filename containing a newline, which Windows rejects (os error 123). It now uses a plain filename on Windows and keeps the newline name everywhere else, so the -z parsing coverage stays on the platforms where such names can exist. Verified locally: cargo test --test integration integration_tests::list:: 103/103, fmt and clippy clean. Rebased onto current main (1a40681) before pushing.

@max-sixty
max-sixty merged commit c854ede into max-sixty:main Nov 21, 2026
37 checks passed
@max-sixty max-sixty mentioned this pull request Nov 21, 2026
max-sixty pushed a commit that referenced this pull request Nov 22, 2026
)

`parse_untracked_files` had its own loop over `git status --porcelain
-z` records, including the rule that skips a rename's or copy's source
field. `porcelain_entries_z`, added in #4699, already implements that
walk. `parse_untracked_files` now keeps that iterator's `??` records and
drops its own copy. Behavior is unchanged, and the existing
`parse_untracked_files` unit tests, including the rename-source case,
pass unmodified. Its only caller is the auto-staging warning in
`warn_about_untracked_files`.

`parse_porcelain_z` still walks the records itself, because it returns
rename source paths too and the shared iterator drops them.

Co-authored-by: worktrunk-bot <[email protected]>
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.

Expose a per-worktree last-activity timestamp (worktree.modified_at) in the list JSON

3 participants