Repository navigation
feat: review history auto-save on quit - #72
Conversation
Add app/history/ package that saves review session history to ~/.config/revdiff/history/<repo>/<timestamp>.md on quit. Includes header metadata, annotations, and git diff for annotated files. Wired into main app quit path. All errors logged, never fatal.
Move standalone Save/gitDiff/gitCommitHash/filterRepoFiles functions to methods on Service struct. Extract history save logic from run() into saveHistory() with histReq parameter struct. Fix gofmt indentation in layout.go from merged PR #71.
There was a problem hiding this comment.
Pull request overview
Adds an automatic “review history” persistence path so annotations aren’t lost after quitting the TUI, by saving a markdown snapshot (annotations + relevant diffs) to a configurable history directory.
Changes:
- Introduces
app/historypackage to write history markdown entries (header metadata + annotations + optionalgit difffor annotated files). - Wires history auto-save into the normal quit path in
app/main.goand adds--history-dir/REVDIFF_HISTORY_DIR/ config support. - Updates user/docs references (README, site docs, internal reference docs) to describe the feature.
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
app/history/history.go |
New history persistence implementation (file layout, git metadata/diff capture, path filtering). |
app/history/history_test.go |
Adds unit tests for history saving across git and non-git modes. |
app/main.go |
Adds --history-dir option and invokes history save on normal quit with annotations. |
README.md |
Documents review history feature and CLI option. |
site/docs.html |
Adds “Review history” docs section and adds --history-dir to options list. |
.claude-plugin/skills/revdiff/references/usage.md |
Updates internal usage reference with review history behavior. |
.claude-plugin/skills/revdiff/references/config.md |
Adds --history-dir / env var to config reference table. |
CLAUDE.md |
Updates project structure docs to include app/history/. |
docs/plans/completed/20260408-review-history.md |
Adds completed implementation plan record for the feature. |
app/keymap/layout.go / app/keymap/keymap.go |
Formatting-only adjustments (indent alignment). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| cmd := exec.CommandContext(context.Background(), "git", args...) | ||
| cmd.Dir = p.GitRoot | ||
| out, err := cmd.Output() | ||
| if err != nil { |
There was a problem hiding this comment.
The exec.CommandContext calls here will likely trigger gosec (G204) because args include user/annotation-derived values (ref and pathspecs). Elsewhere (app/diff/diff.go) similar git execs are annotated with //nolint:gosec plus an explanation; consider matching that pattern or routing through the existing git runner to satisfy lint consistently.
| cmd := exec.CommandContext(context.Background(), "git", args...) | ||
| cmd.Dir = p.GitRoot | ||
| out, err := cmd.Output() | ||
| if err != nil { |
There was a problem hiding this comment.
On git diff failure, the log only prints the generic error (often just an exit status) and loses stderr, which makes it hard to diagnose why the diff section is missing. Consider capturing *exec.ExitError and logging trimmed exitErr.Stderr (similar to diff.Git.runGit), or use CombinedOutput and log the stderr text.
| if err != nil { | |
| if err != nil { | |
| if exitErr, ok := err.(*exec.ExitError); ok { | |
| stderr := strings.TrimSpace(string(exitErr.Stderr)) | |
| if stderr != "" { | |
| log.Printf("[WARN] history: git diff: %s", stderr) | |
| return "" | |
| } | |
| } |
| out, err := cmd.Output() | ||
| if err != nil { |
There was a problem hiding this comment.
gitCommitHash silently returns "" on error without logging. The feature/docs state that errors are logged to stderr but never fail the process; consider logging a warning when git rev-parse fails (including stderr) so missing commit hashes are diagnosable while still non-fatal.
| out, err := cmd.Output() | |
| if err != nil { | |
| out, err := cmd.CombinedOutput() | |
| if err != nil { | |
| msg := strings.TrimSpace(string(out)) | |
| if msg != "" { | |
| log.Printf("[WARN] history: git rev-parse --short HEAD: %v: %s", err, msg) | |
| } else { | |
| log.Printf("[WARN] history: git rev-parse --short HEAD: %v", err) | |
| } |
| ### Review History | ||
|
|
||
| When you quit with annotations (`q`), revdiff automatically saves a copy of the review session to `~/.config/revdiff/history/<repo-name>/<timestamp>.md`. This is a safety net — if annotations are lost (process crash, agent fails to capture stdout), the history file preserves them. | ||
|
|
||
| Each history file contains: | ||
| - Header with path, git refs, and commit hash | ||
| - Full annotation output (same format as stdout) | ||
| - Raw git diff for annotated files only | ||
|
|
||
| History auto-save is always on and silent — errors are logged to stderr, never fail the process. No history is saved on discard quit (`Q`) or when there are no annotations. | ||
|
|
||
| Override the history directory with `--history-dir`, `REVDIFF_HISTORY_DIR` env var, or `history-dir` in the config file. |
There was a problem hiding this comment.
Docs claim history is always saved under .../history/<repo-name>/<timestamp>.md, but the implementation uses stdin/<timestamp>.md for --stdin and (in non-git single-file --only) uses the parent directory basename instead of a repo name. Consider clarifying these non-git directory naming rules in this section to avoid user confusion when they look for the saved file.
| <h2 id="review-history">Review history</h2> | ||
| <p>When you quit with annotations (<code>q</code>), revdiff automatically saves a copy of the review session to <code>~/.config/revdiff/history/<repo-name>/<timestamp>.md</code>. This is a safety net — if annotations are lost (process crash, agent fails to capture stdout), the history file preserves them.</p> | ||
| <p>Each history file contains a header with path, git refs, and commit hash, the full annotation output (same format as stdout), and the raw git diff for annotated files only.</p> | ||
| <p>History auto-save is always on and silent — errors are logged to stderr, never fail the process. No history is saved on discard quit (<code>Q</code>) or when there are no annotations.</p> | ||
| <p>Override the directory with <code>--history-dir</code>, <code>REVDIFF_HISTORY_DIR</code> env var, or <code>history-dir</code> in the config file.</p> | ||
|
|
There was a problem hiding this comment.
This section states history files are saved under .../history/<repo-name>/..., but non-git modes don’t have a repo name (implementation uses stdin/ for --stdin and the parent directory basename for single-file --only). Consider updating this page to reflect the actual subdirectory naming in non-git modes so users can locate the saved file reliably.
|
|
||
| ## Technical Details | ||
| - **History directory**: default `~/.config/revdiff/history/`, overridable via `--history-dir` CLI flag, `REVDIFF_HISTORY_DIR` env var, or `history-dir` config key. Same precedence as other options: CLI > env > config > default | ||
| - Timestamp format for filenames: `2006-01-02T15-04-05` (filesystem-safe, no colons) |
There was a problem hiding this comment.
The plan states the filename timestamp format is 2006-01-02T15-04-05 (no milliseconds), but the implementation/test uses 2006-01-02T15-04-05.000.md. Consider updating the plan text to match the implemented filename format for accuracy.
| - Timestamp format for filenames: `2006-01-02T15-04-05` (filesystem-safe, no colons) | |
| - Timestamp format for filenames: `2006-01-02T15-04-05.000` (filesystem-safe, no colons, includes milliseconds) |
| ## Review History | ||
|
|
||
| When you quit with annotations (`q`), revdiff automatically saves a copy of the review session to `~/.config/revdiff/history/<repo-name>/<timestamp>.md`. This is a safety net — if annotations are lost (process crash, agent fails to capture stdout), the history file preserves them. | ||
|
|
||
| Each history file contains: | ||
| - Header with path, git refs, and commit hash | ||
| - Full annotation output (same format as stdout) | ||
| - Raw git diff for annotated files only | ||
|
|
||
| History auto-save is always on and silent — errors are logged to stderr, never fail the process. No history is saved on discard quit (`Q`) or when there are no annotations. | ||
|
|
||
| Override the history directory with `--history-dir`, `REVDIFF_HISTORY_DIR` env var, or `history-dir` in the config file. |
There was a problem hiding this comment.
This doc says history saves to .../history/<repo-name>/<timestamp>.md unconditionally, but the implementation uses stdin/ for --stdin sessions and different subdir naming for non-git --only. Consider clarifying the subdirectory naming rules for non-git modes here to match actual behavior.
Capture stderr from git diff failures for better diagnostics. Clarify docs that --stdin saves under stdin/ subdir and --only uses parent directory name instead of repo name.
Deploying revdiff with
|
| Latest commit: |
7b6d8e7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d41098e4.revdiff.pages.dev |
| Branch Preview URL: | https://review-history.revdiff.pages.dev |
What: auto-save review sessions (annotations + relevant file diffs) to
~/.config/revdiff/history/<repo>/<timestamp>.mdon normal quit.Why: when revdiff is used as a review tool from Claude Code or other agents, annotations are output to stdout. If the agent fails to capture stdout, crashes, or the user wants to reference a past review, annotations are lost. This provides a silent safety net - every review session with annotations gets persisted automatically.
How it works:
q) with annotations present, saves a markdown file with header metadata (path, refs, commit hash), the formatted annotations, and rawgit diffoutput for only the annotated filesQ) or empty annotations, nothing is saved--history-dirflag /REVDIFF_HISTORY_DIRenv / config file, defaults to~/.config/revdiff/history/--only,--stdin) save annotations without diff sectionDesign:
app/history/package withServicestruct andSave()methodhistory.New(baseDir).Save(params)called from extractedsaveHistory()helper inapp/main.goServicewraps all git interaction (diff, commit hash, file filtering) as methodsfilterRepoFiles()canonicalizes paths and filters out files outside the git repo to prevent git errors