Repository navigation
feat: flush annotations to output file without exiting (O key) - #249
Merged
Merged
Conversation
Plan for issue #248: O key to flush annotations to the --output file without exiting. Store-owned atomic persistence (annotation.Store.WriteFile), no interface/injection; output path as a plain modelConfigState value.
wire ActionFlushOutput to Model.handleFlushOutput: flush annotations to the -o/--output file without exiting, reporting via outputState.hint. gate on empty output path and empty store, log write failures as [WARN]. add the output hint to transientHint priority (after reload) and to the hint-reset blocks in handleKey and mouse handling. also drop a shadowing local plainRenderer closure in model_test.go that duplicated the package-level helper (surfaced by govet shadow).
Pairs with the O in-session flush (#248): with -o set, the reviewer flushes annotations with O, then R reloads to re-diff the changed tree. This flag skips the 'Annotations will be dropped' confirm on R so the flush-reload loop needs no per-iteration y press. Mirrors --no-confirm-discard (flag + REVDIFF_NO_CONFIRM_RELOAD env + no-confirm-reload ini), off by default.
Deploying revdiff with
|
| Latest commit: |
6569c45
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://60e69b11.revdiff.pages.dev |
| Branch Preview URL: | https://in-session-annotation-flush.revdiff.pages.dev |
There was a problem hiding this comment.
Pull request overview
Adds an in-session “flush annotations to file” workflow to revdiff, enabling a keep-open review tab where annotations can be exported to the configured --output file without quitting, then code can be reloaded and re-reviewed iteratively.
Changes:
- Introduces
O/flush_outputto write current annotations to--outputwithout exiting (with status-bar feedback and safe atomic writes). - Adds
--no-confirm-reloadto skip the “annotations will be dropped” confirmation when reloading withR. - Unifies file-output writes to use a shared atomic write path and updates docs/skills accordingly.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| site/docs.html | Documents --no-confirm-reload, O flush keybinding, and flush_output action. |
| README.md | Updates CLI options and keybindings to include --no-confirm-reload and O flush. |
| plugins/pi/skills/revdiff/SKILL.md | Notes O flush behavior for standalone usage context. |
| plugins/codex/skills/revdiff/SKILL.md | Teaches Codex flow to read output after a human flushes mid-session without relaunching. |
| plugins/codex/skills/revdiff/references/usage.md | Adds O key and flush explanation to usage reference. |
| plugins/codex/skills/revdiff/references/config.md | Adds flush_output to action list and documents the action semantics. |
| docs/plans/completed/20260702-in-session-annotation-flush.md | Captures implementation plan and testing/acceptance criteria for the feature. |
| docs/ARCHITECTURE.md | Updates architecture notes to include atomic WriteFile and the O flush workflow. |
| CLAUDE.md | Adds a gotcha entry describing how flush is gated, persisted, and hinted. |
| app/ui/view.go | Adds output hint into transient hint priority order. |
| app/ui/output.go | Implements handleFlushOutput + output transient hint state. |
| app/ui/output_test.go | Adds unit tests for flush behavior, dispatch, hint visibility/clearing, and output-path wiring. |
| app/ui/mouse.go | Clears output hint on mouse events like other transient hints. |
| app/ui/mouse_test.go | Extends transient-hint clearing tests to include output hint. |
| app/ui/model.go | Wires OutputPath, NoConfirmReload, adds dispatch for flush_output, and clears output hints on keypress. |
| app/ui/model_test.go | Adds transient-hint priority test coverage for output hint behavior. |
| app/ui/handlers_test.go | Adds coverage for --no-confirm-reload direct reload behavior. |
| app/main.go | Wires NoConfirmReload + OutputPath into the model and routes exit-time file writes through store atomic write. |
| app/main_test.go | Updates tests for file output path to go through the atomic store writer. |
| app/keymap/keymap.go | Adds flush_output action and default O binding + help text. |
| app/keymap/keymap_test.go | Adds tests for validity, default binding, help entry, and dump output for flush_output. |
| app/config.go | Adds --no-confirm-reload option with env/ini wiring. |
| app/config_test.go | Adds parsing tests for --no-confirm-reload via flag/env/config. |
| app/annotation/store.go | Adds (*Store).WriteFile for atomic temp+rename persistence. |
| app/annotation/store_test.go | Adds tests for atomic file write semantics, overwrite, mode, and cleanup behavior. |
| .claude-plugin/skills/revdiff/SKILL.md | Documents the mid-session O flush workflow for the Claude plugin skill. |
| .claude-plugin/skills/revdiff/references/usage.md | Adds O key and flush explanation to plugin usage reference. |
| .claude-plugin/skills/revdiff/references/config.md | Adds --no-confirm-reload, flush_output action, and flush explanation to plugin config reference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+178
to
+183
| func (s *Store) WriteFile(path string) error { | ||
| content := s.FormatOutput() | ||
| tmp, err := os.CreateTemp(filepath.Dir(path), ".revdiff-output-*") | ||
| if err != nil { | ||
| return fmt.Errorf("create temp file: %w", err) | ||
| } |
Comment on lines
277
to
281
| func writeAnnotationOutput(r annotationOutputReq) (int, error) { | ||
| code := annotationExitCode(r.opts.ExitCodeOnAnnotations, r.output) | ||
| if r.opts.Output != "" { | ||
| if err := os.WriteFile(r.opts.Output, []byte(r.output), 0o600); err != nil { | ||
| if err := r.store.WriteFile(r.opts.Output); err != nil { | ||
| return 0, fmt.Errorf("write output: %w", err) |
- Store.WriteFile delegates to fsutil.AtomicWriteFile instead of a hand-rolled temp+rename. Reuses the existing tested atomic writer and gets filepath.Clean for free. - exit-time file write uses the already-computed output string via fsutil.AtomicWriteFile, dropping the redundant re-format and the store field from annotationOutputReq. File content, exit code, and stdout now share a single source.
| ### app/annotation/ — annotation store | ||
|
|
||
| In-memory store for annotations. Each `Annotation` has file, line, text, and optional `EndLine` for hunk range headers (triggered when comment contains "hunk" keyword). Structured output formatting for export. `FormatOutput` escapes body lines that start with `## ` (with trailing space, matching the record-header form) by prefixing a single space so downstream parsers cannot confuse a comment line for a new record header. Lines starting with `###` or `##` without a space are left unchanged. | ||
| In-memory store for annotations. Each `Annotation` has file, line, text, and optional `EndLine` for hunk range headers (triggered when comment contains "hunk" keyword). Structured output formatting for export. `FormatOutput` escapes body lines that start with `## ` (with trailing space, matching the record-header form) by prefixing a single space so downstream parsers cannot confuse a comment line for a new record header. Lines starting with `###` or `##` without a space are left unchanged. `WriteFile(path)` formats via `FormatOutput` and writes atomically (temp file in the target directory + rename, mode 0o600), used by both the exit-time file write and the in-session `O` flush so a concurrent reader never sees a truncated file. |
| - `scrollDiffViewportBy(delta)` is now a pure YOffset shifter — returns `true` iff YOffset changed. No pin, no render, no TOC sync. All deferred to `flushWheelPending`. | ||
| - During a wheel burst the diff cursor index (`m.nav.diffCursor`) and the cursor highlight in the rendered string are both stale (matches less/vim behavior — no visible cursor during a fast scroll). After `wheelRenderDelay` of wheel idle, or on the next key/resize event, the flush pins the cursor to the viewport edge and re-renders. | ||
| - Reload (`R` key): `reloadState` on `Model` holds `pending bool` (waiting for y/cancel), `hint string` (transient status-bar message), and `applicable bool` (false in `--stdin` mode — stream consumed). `ReloadApplicable` is wired at the composition root in `main.go`, following the same pattern as `CommitsApplicable`. The reload method is named `triggerReload()` — not `reload()` — because Go forbids a method and a field with the same name on the same type (`Model.reload` is the state field). Reload resets the diff cursor to the top of the file; tree selection (which file) is restored by `SelectByPath` in `handleFilesLoaded`. | ||
| - Output flush (`O` key, `flush_output` action): `Model.handleFlushOutput` (in `app/ui/output.go`) writes the current annotations to the `--output` file without exiting, enabling a keep-open review loop (annotate → `O` flush → hand file to an AI agent → `R` reload → continue). Gated on `m.cfg.outputPath` (copied from `ModelConfig.OutputPath` = `opts.Output` in `main.go`) — empty path IS the mode gate (`"Output flush requires -o/--output"` hint, no write); no interface, no injected writer, no applicability bool. Persistence lives in the annotation domain: `annotation.Store.WriteFile(path)` does `FormatOutput()` + atomic temp-file+rename (0o600), the SAME method the exit-time `writeAnnotationOutput` file branch now calls instead of a bare `os.WriteFile` (unified atomic write — a concurrent AI reader never sees a truncated file). Flush is a pure export: the store is never mutated, so annotations persist in-session and re-flush overwrites with the full current set (snapshot, not append). Clearing stays exclusively `R` reload's job (`store.Clear()`), so `R` still shows its "Annotations will be dropped" confirm even right after an `O` flush (by design — no dirty-since-flush flag). Feedback is a transient `outputState.hint` (mirrors `reloadState.hint`): rendered by `transientHint()` in `view.go`, cleared alongside other hints in `handleKey` and `mouse.go`. Empty store → `"No annotations to flush"` (matches exit-time empty-skip); write error → `[WARN]` log + `"Flush failed"`. |
| **Project-specific stricter addendum:** In this repository, count `ctx context.Context` toward the 4-parameter limit from CLAUDE.md. Do not use the `ctx`-exempt exception in the canonical block above when implementing this plan. | ||
|
|
||
| ## Testing Strategy | ||
| - **unit tests**: required for every task. `Store.WriteFile` (success overwrite of existing file, empty content, target-dir-missing → error, resulting mode 0o600, no leftover temp file on success, temp removed on error, byte-identical to `FormatOutput()`); keymap default binding + valid action + Dump/help entry; `handleFlushOutput` (empty path → hint + no write, empty store → "no annotations" hint + no write, success → file matches `FormatOutput()` + hint with count, write error → "flush failed" hint); dispatch routing of `ActionFlushOutput`; hint cleared on next key; `transientHint()` includes the new hint at the right priority; `writeAnnotationOutput` file branch now routes through the atomic store write. |
| - `annotation.Store` gains `WriteFile(path string) error`: it formats itself via `FormatOutput()` and writes atomically — a temp file in the target's directory, then `os.Rename` over the target (mode 0o600). Atomic on a single filesystem, so a concurrent reader sees either the old or the new complete file, never a truncated one. The temp+rename logic is inline in the method (called only there); no standalone helper. | ||
| - The Model holds the destination as a plain value: `modelConfigState.outputPath`, set from `ModelConfig.OutputPath` in `NewModel` (a plain string copy, exactly like `ref`/`only`/`workDir`). `outputPath == ""` IS the mode gate — no interface, no injected writer, no applicability bool. | ||
| - A new `ActionFlushOutput` keymap action (default `O`) dispatches to `Model.handleFlushOutput`, which flushes via `m.store.WriteFile(m.cfg.outputPath)` and reports through a new `outputState.hint` shown in the status bar. | ||
| - `app/main.go` sets `ModelConfig.OutputPath: opts.Output`; the exit-time `writeAnnotationOutput` file branch calls `m.Store().WriteFile(opts.Output)` instead of `os.WriteFile`, unifying on the atomic write. The stdout branch, empty-output skip, and exit-code logic stay at the composition root. |
00f1810 changed Store.WriteFile to delegate to fsutil.AtomicWriteFile and made the exit-time write call fsutil directly, but ARCHITECTURE.md, CLAUDE.md, and the completed plan still described the old store-routed design. Copilot flagged the mismatch on #249. Update the living docs to match, and add a post-review note to the plan reconciling its as-planned detail.
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.
implements the permanent-review-tab workflow from #248: keep revdiff open, annotate, hand the annotations to an AI agent, reload, repeat without quitting.
What's new
O(flush_output) writes the current annotations to the--outputfile without exiting. Gated on-obeing set (no file destination means nothing to flush, shows a hint). Pure export: the store is not cleared, so annotations stay in-session and re-flushing overwrites with the full current set.--no-confirm-reloadskips the "Annotations will be dropped" confirm onR, so the flush-reload loop needs no per-iterationy. Mirrors--no-confirm-discard(flag +REVDIFF_NO_CONFIRM_RELOADenv +no-confirm-reloadini), off by default.Design
persistence lives in the annotation domain:
annotation.Store.WriteFile(path)formats and writes atomically (temp file + rename), so a concurrent AI reader never sees a truncated file. The exit-time write now uses the same method instead of a bareos.WriteFile. No new package, no writer interface, no injected dependency. The Model holds the destination as a plainmodelConfigState.outputPathvalue and calls the store directly.Loop
annotate ->
O(writes file, annotations stay) -> agent reads the file and edits code ->R(re-diffs, drops the now-stale annotations, no confirm with--no-confirm-reload) -> continue.tests cover the atomic write, the handler paths (no
-o, empty store, success, error), the keymap action, exit-time parity, and the new flag. Plan indocs/plans/completed/.plugin/package versions are intentionally not bumped here: this depends on a new binary feature, so the launcher/skill bumps wait for the tagged binary release.