feat(cli): add /diff command to show git changes in working directory#22662
Closed
wesleysimplicio wants to merge 2 commits into
Closed
feat(cli): add /diff command to show git changes in working directory#22662wesleysimplicio wants to merge 2 commits into
wesleysimplicio wants to merge 2 commits into
Conversation
Salvage of NousResearch#4839. /diff shows stat summary + full diff for both staged and unstaged changes in the current working directory. /diff --stat shows the summary only. Uses git directly with per-call timeouts; works in any git repo and prints a clear message when not inside one. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new CLI-only /diff slash command intended to display staged/unstaged git changes (stat summary and optionally full diffs), and wires it into command resolution and CLI dispatch.
Changes:
- Register
diffinCOMMAND_REGISTRYas a CLI-only command withargs_hint="[--stat]". - Add
HermesCLI._handle_diff_command()and routecanonical == "diff"to it fromprocess_command. - Add a new pytest suite covering basic
/diffbehaviors (registry, routing, no-repo, no-changes, staged/unstaged,--stat, timeout).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
cli.py |
Implements /diff handler and routes process_command to it. |
hermes_cli/commands.py |
Registers the new diff command in the central registry. |
tests/cli/test_diff_command.py |
Adds tests for /diff registration, dispatch, and key output behaviors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+5709
to
+5716
| try: | ||
| _sp.run( | ||
| ["git", "rev-parse", "--is-inside-work-tree"], | ||
| cwd=cwd, capture_output=True, check=True, timeout=5, | ||
| ) | ||
| except Exception: | ||
| _cprint(f" {_DIM}Not a git repository.{_RST}") | ||
| return |
|
|
||
| assert any("staged" in p.lower() for p in printed) | ||
|
|
||
|
|
…taged full diffs Repo-check now distinguishes FileNotFoundError (git missing), TimeoutExpired, and CalledProcessError (not a repo) instead of catching all exceptions as 'Not a git repository.'. Validates cwd before invoking git. Full-diff section now runs both 'git diff --cached' and 'git diff' (each under its own header) when their corresponding stat output is non-empty, matching the documented behavior. Adds regression tests for: git missing, both staged+unstaged present.
Contributor
Author
|
Closing non-fix PR as requested — mantendo apenas PRs de fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
/diffslash command to show staged and unstaged git changes in the current working directory -/diffprints stat summary then full diff (staged and unstaged separated) -/diff --statshows stat summary only, skips full diff output - Usesgit diffdirectly with per-call timeouts (5s for repo check, 10s for stats, 30s for full diff) - Gracefully handles: not a git repo, no changes, timeout, unexpected errors - RegistersCommandDef("diff", ..., cli_only=True, args_hint="[--stat]")inCOMMAND_REGISTRYRoot cause
The detailed rationale from the original PR body is preserved below. This template update keeps the review structure consistent with #29640.
Fix
Why this shape
This shape mirrors #29640 so reviewers can quickly compare scope, root cause, fix, tests, and related context without having to decode a custom PR description.
Tests
Original body
Related PRs / issues
N/A
Original body
Summary
/diffslash command to show staged and unstaged git changes in the current working directory -/diffprints stat summary then full diff (staged and unstaged separated) -/diff --statshows stat summary only, skips full diff output - Usesgit diffdirectly with per-call timeouts (5s for repo check, 10s for stats, 30s for full diff) - Gracefully handles: not a git repo, no changes, timeout, unexpected errors - RegistersCommandDef("diff", ..., cli_only=True, args_hint="[--stat]")inCOMMAND_REGISTRYWhat Changed
Fluxo
A mudança continua seguindo o fluxo original descrito na seção preservada abaixo, sem ampliar o escopo funcional deste PR.
Visão
A padronização melhora a revisão, reduz ruído e evita deriva de formatação entre PRs abertos.
Test Plan
Original body
What does this PR do?
Summary
/diffslash command to show staged and unstaged git changes in the current working directory/diffprints stat summary then full diff (staged and unstaged separated)/diff --statshows stat summary only, skips full diff outputgit diffdirectly with per-call timeouts (5s for repo check, 10s for stats, 30s for full diff)CommandDef("diff", ..., cli_only=True, args_hint="[--stat]")inCOMMAND_REGISTRYSalvage of #4839.
Test plan
pytest tests/cli/test_diff_command.py— 10 tests passresolve_command("diff")returns entry withcli_only=True--statflag → stat only, no full diff subprocess callprocess_commandroutescanonical == "diff"to_handle_diff_command🤖 Generated with Claude Code
Solution Sketch
Related Issue
N/A
Type of Change
Changes Made
.github/PULL_REQUEST_TEMPLATE.mdHow to Test
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Generated by Hermes Turbo
Generated by Hermes Turbo