Skip to content

feat: add --path flag to filter diff to a specific file or directory#227

Merged
agavra merged 5 commits into
agavra:mainfrom
anpryl:add-path-filter
Mar 30, 2026
Merged

feat: add --path flag to filter diff to a specific file or directory#227
agavra merged 5 commits into
agavra:mainfrom
anpryl:add-path-filter

Conversation

@anpryl
Copy link
Copy Markdown
Contributor

@anpryl anpryl commented Mar 26, 2026

Summary

Adds several features for AI agent integration workflows:

  1. --path flag — filters diff view to a specific file or directory
  2. --file flag — opens any file for annotation without requiring a VCS repository
  3. --stdout escape fix — prevents garbage in captured export output

Also fixes #203

Use Case: AI Agent Integration

tuicr's README describes the core workflow: "Let the agent loose, review the changes like a PR, drop comments where needed, and export everything as structured feedback." These features extend tuicr for document-driven review workflows.

The Problem

When using tuicr as part of an automated review workflow (e.g., an AI coding agent writes a design document, then opens tuicr for the user to annotate):

  1. --path problem: Without it, tuicr shows every changed file in the working tree — the user has to manually navigate to the relevant file
  2. --file problem: The document may not be committed (or even tracked by git). Currently tuicr requires a VCS repository, so reviewing an arbitrary file means staging it first and cleaning up after
  3. --stdout problem: Keyboard enhancement probe writes escape sequences to stdout before the /dev/tty redirect is established, leaking binary garbage into captured output

The Solution

# Review a file without needing git/hg/jj at all
tuicr --file plans/design.md --stdout

# Review only a specific file within a git diff
tuicr --path plans/design.md --stdout

# Review only files in a directory
tuicr --path src/components/

Real-World Workflow

This is used in a "review-plan" skill for Claude Code:

  1. Agent writes a design document to plans/feature-x.md
  2. Agent launches tuicr --file plans/feature-x.md --stdout in a tmux popup
  3. User reviews the document, leaves comments using tuicr's annotation features
  4. User exits with :wq — comments are exported to stdout
  5. Agent reads the structured feedback and revises the document

No git add needed. No VCS repo needed. Just a file and tuicr.

Details

--file flag (src/vcs/file.rs, src/vcs/traits.rs, src/app.rs, src/main.rs, src/theme/mod.rs)

  • FileBackend (src/vcs/file.rs): New VcsBackend implementation that reads a file and presents it as a synthetic "all lines added" diff with syntax highlighting — no git, hg, or jj required
  • VcsType::File (src/vcs/traits.rs): New variant for the file-only backend
  • CLI parsing (src/theme/mod.rs): Adds file_path: Option<String> to CliArgs, parses --file <PATH> and --file=<PATH> forms
  • Mutual exclusivity (src/main.rs): --file cannot be combined with --path, -r, or -w
  • App integration (src/app.rs): New code path in App::new that uses FileBackend, hides file list panel, and focuses on the diff view

--path flag (src/theme/mod.rs, src/app.rs, src/main.rs)

  • CLI parsing (src/theme/mod.rs): Adds path_filter: Option<String> to CliArgs, parses -p/--path <PATH> and --path=<PATH> forms with validation
  • Filtering (src/app.rs): New filter_by_path() method filters DiffFiles by exact filename match or directory prefix. Applied consistently across all diff retrieval paths
  • Auto-hide file list (src/app.rs): When path filter matches exactly one file, show_file_list is set to false and focus moves to the diff panel
  • Implicit --working-tree (src/main.rs): --path implies --working-tree unless -r is explicitly provided
  • 8 unit tests for CLI parsing edge cases

--stdout escape fix (src/main.rs)

  • Skip supports_keyboard_enhancement() probe when --stdout is active — keyboard enhancement is a minor UX improvement that doesn't affect core functionality

Compatibility

  • No breaking changes to existing CLI behavior
  • All new flags are opt-in; without them, tuicr behaves exactly as before
  • The --stdout fix only changes behavior when --stdout is already in use
  • All existing tests pass

Testing

# --file: review any file without a VCS repo
tuicr --file README.md
tuicr --file /tmp/notes.md --stdout

# --path: scope to a specific file in a git diff
echo "test" >> README.md && tuicr -p README.md

# --path: directory filter
tuicr -p src/

# --stdout: clean output
tuicr --file README.md --stdout

# mutual exclusivity: should error
tuicr --file foo.md --path bar.md
tuicr --file foo.md -w

anpryl and others added 2 commits March 26, 2026 10:27
Adds -p/--path <PATH> CLI flag that filters the diff view to only show
files matching the given path (exact file match or directory prefix).

When exactly one file matches, the file list is auto-hidden and the diff
view is focused directly. When used without -r, --path implies
--working-tree to skip the commit selector.

This enables workflows like `tuicr --path plans/current-plan.md` for
reviewing a single file's changes in isolation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The supports_keyboard_enhancement() call writes escape sequences to
stdout before the /dev/tty redirect is established. When --stdout is
used to capture export output, these sequences leak into the captured
content. Skip the probe entirely in --stdout mode since keyboard
enhancement is a minor UX improvement (Alt+Enter detection) that
doesn't affect core functionality.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@anpryl anpryl marked this pull request as ready for review March 26, 2026 09:03
@anpryl anpryl marked this pull request as draft March 26, 2026 10:55
Allows `tuicr --file path/to/file.md` to open any file for
review and annotation without requiring a git/hg/jj repository.

The file is presented as a synthetic "all lines added" diff with
syntax highlighting. Mutually exclusive with --path, -r, and -w.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner

@agavra agavra left a comment

Choose a reason for hiding this comment

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

Very cool feature, thanks @anpryl - I tested it locally and confirmed it works. This also fixes #203, since you're the second reporter of this I think it's acceptable to disable advanced keyboard shortcuts in this situation.

@agavra agavra marked this pull request as ready for review March 26, 2026 15:54
@agavra agavra marked this pull request as draft March 26, 2026 15:55
@agavra
Copy link
Copy Markdown
Owner

agavra commented Mar 26, 2026

Ah @anpryl I realized late this was a draft PR, I converted it back. LMK when you're ready to merge and I will merge it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@anpryl anpryl marked this pull request as ready for review March 29, 2026 09:42
@anpryl
Copy link
Copy Markdown
Contributor Author

anpryl commented Mar 29, 2026

@agavra It is ready for review!

@agavra agavra merged commit 41284b9 into agavra:main Mar 30, 2026
4 checks passed
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.

--stdout mode with redirected output writes terminal control characters into the file

2 participants