Skip to content

feat: review history auto-save on quit - #72

Merged
umputun merged 4 commits into
masterfrom
review-history
Apr 8, 2026
Merged

umputun merged 4 commits into
masterfrom
review-history

Conversation

@umputun

@umputun umputun commented Apr 8, 2026

Copy link
Copy Markdown
Owner

What: auto-save review sessions (annotations + relevant file diffs) to ~/.config/revdiff/history/<repo>/<timestamp>.md on 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:

  • on normal quit (q) with annotations present, saves a markdown file with header metadata (path, refs, commit hash), the formatted annotations, and raw git diff output for only the annotated files
  • on discard quit (Q) or empty annotations, nothing is saved
  • history directory is configurable via --history-dir flag / REVDIFF_HISTORY_DIR env / config file, defaults to ~/.config/revdiff/history/
  • non-git modes (--only, --stdin) save annotations without diff section
  • all errors are logged to stderr, never fail the process

Design:

  • new app/history/ package with Service struct and Save() method
  • history.New(baseDir).Save(params) called from extracted saveHistory() helper in app/main.go
  • Service wraps all git interaction (diff, commit hash, file filtering) as methods
  • filterRepoFiles() canonicalizes paths and filters out files outside the git repo to prevent git errors

umputun added 3 commits April 8, 2026 14:09
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.
Copilot AI review requested due to automatic review settings April 8, 2026 20:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/history package to write history markdown entries (header metadata + annotations + optional git diff for annotated files).
  • Wires history auto-save into the normal quit path in app/main.go and 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.

Comment thread app/history/history.go
Comment on lines +132 to +135
cmd := exec.CommandContext(context.Background(), "git", args...)
cmd.Dir = p.GitRoot
out, err := cmd.Output()
if err != nil {

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread app/history/history.go
cmd := exec.CommandContext(context.Background(), "git", args...)
cmd.Dir = p.GitRoot
out, err := cmd.Output()
if err != nil {

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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 ""
}
}

Copilot uses AI. Check for mistakes.
Comment thread app/history/history.go
Comment on lines +150 to +151
out, err := cmd.Output()
if err != nil {

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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)
}

Copilot uses AI. Check for mistakes.
Comment thread README.md
Comment on lines +431 to +442
### 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.

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread site/docs.html
Comment on lines +213 to +218
<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/&lt;repo-name&gt;/&lt;timestamp&gt;.md</code>. This is a safety net &mdash; 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 &mdash; 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>

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

## 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)

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
- 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)

Copilot uses AI. Check for mistakes.
Comment on lines +159 to +170
## 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.

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 8, 2026 •

Copy link
Copy Markdown

Deploying revdiff with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7b6d8e7
Status: ✅  Deploy successful!
Preview URL: https://d41098e4.revdiff.pages.dev
Branch Preview URL: https://review-history.revdiff.pages.dev

View logs

@umputun
umputun merged commit 238c47f into master Apr 8, 2026
3 checks passed
@umputun
umputun deleted the review-history branch April 8, 2026 20:37
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.

2 participants