Skip to content

feat(cli): add /diff command to show git changes in working directory#22662

Closed
wesleysimplicio wants to merge 2 commits into
NousResearch:mainfrom
wesleysimplicio:fix/ag05-salvage-4839-diff-command
Closed

feat(cli): add /diff command to show git changes in working directory#22662
wesleysimplicio wants to merge 2 commits into
NousResearch:mainfrom
wesleysimplicio:fix/ag05-salvage-4839-diff-command

Conversation

@wesleysimplicio

@wesleysimplicio wesleysimplicio commented May 9, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Adds /diff slash command to show staged and unstaged git changes in the current working directory - /diff prints stat summary then full diff (staged and unstaged separated) - /diff --stat shows stat summary only, skips full diff output - Uses git diff directly 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 - Registers CommandDef("diff", ..., cli_only=True, args_hint="[--stat]") in COMMAND_REGISTRY

Root cause

The detailed rationale from the original PR body is preserved below. This template update keeps the review structure consistent with #29640.

Fix

  • introduce the smallest surface needed for the new capability in the touched subsystem
  • preserve existing behavior and defaults outside the new entry point or configuration path
  • cover the new path with focused validation before asking for review

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

  • Veja a descrição original preservada abaixo para detalhes de validação, testes e notas de verificação.
Original body

Related PRs / issues

N/A

Original body

Summary

  • Adds /diff slash command to show staged and unstaged git changes in the current working directory - /diff prints stat summary then full diff (staged and unstaged separated) - /diff --stat shows stat summary only, skips full diff output - Uses git diff directly 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 - Registers CommandDef("diff", ..., cli_only=True, args_hint="[--stat]") in COMMAND_REGISTRY

What Changed

  • Standardized this PR body to the current Hermes Turbo template.
  • Preserved the original detailed description below for reference.

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

  • Veja a descrição original preservada abaixo para detalhes de validação, testes e notas de verificação.
Original body

What does this PR do?

Summary

  • Adds /diff slash command to show staged and unstaged git changes in the current working directory
  • /diff prints stat summary then full diff (staged and unstaged separated)
  • /diff --stat shows stat summary only, skips full diff output
  • Uses git diff directly 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
  • Registers CommandDef("diff", ..., cli_only=True, args_hint="[--stat]") in COMMAND_REGISTRY

Salvage of #4839.

Test plan

  • pytest tests/cli/test_diff_command.py — 10 tests pass
  • Registry: resolve_command("diff") returns entry with cli_only=True
  • Not a git repo → prints "Not a git repository"
  • No changes → prints "No changes"
  • Unstaged changes → prints "Unstaged:" section
  • Staged changes → prints "Staged:" section
  • --stat flag → stat only, no full diff subprocess call
  • Timeout → prints "Git diff timed out"
  • Source inspection: process_command routes canonical == "diff" to _handle_diff_command

🤖 Generated with Claude Code

Solution Sketch

  • introduce the smallest surface needed for the new capability in the touched subsystem
  • preserve existing behavior and defaults outside the new entry point or configuration path
  • cover the new path with focused validation before asking for review

Related Issue

N/A

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • preserved the existing technical rationale and validation notes inside the template body
  • scoped this PR description to the implementation already present on the branch
  • aligned the delivery format with .github/PULL_REQUEST_TEMPLATE.md

How to Test

  1. Review the existing validation notes preserved in this PR body.
  2. Run the focused checks for the touched area.
  3. Confirm the scoped change still behaves as described above.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

  • N/A.

Generated by Hermes Turbo


Generated by Hermes Turbo

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>
Copilot AI review requested due to automatic review settings May 9, 2026 15:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 diff in COMMAND_REGISTRY as a CLI-only command with args_hint="[--stat]".
  • Add HermesCLI._handle_diff_command() and route canonical == "diff" to it from process_command.
  • Add a new pytest suite covering basic /diff behaviors (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 thread cli.py Outdated
Comment thread cli.py
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.
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels May 9, 2026
@wesleysimplicio

Copy link
Copy Markdown
Contributor Author

Closing non-fix PR as requested — mantendo apenas PRs de fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants