Skip to content

feat: flush annotations to output file without exiting (O key) - #249

Merged
umputun merged 13 commits into
masterfrom
in-session-annotation-flush
Jul 3, 2026
Merged

umputun merged 13 commits into
masterfrom
in-session-annotation-flush

Conversation

@umputun

@umputun umputun commented Jul 3, 2026

Copy link
Copy Markdown
Owner

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 --output file without exiting. Gated on -o being 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-reload skips the "Annotations will be dropped" confirm on R, so the flush-reload loop needs no per-iteration y. Mirrors --no-confirm-discard (flag + REVDIFF_NO_CONFIRM_RELOAD env + no-confirm-reload ini), 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 bare os.WriteFile. No new package, no writer interface, no injected dependency. The Model holds the destination as a plain modelConfigState.outputPath value 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 in docs/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.

umputun added 11 commits July 2, 2026 04:04
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.
Copilot AI review requested due to automatic review settings July 3, 2026 03:40
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

Deploying revdiff with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6569c45
Status: ✅  Deploy successful!
Preview URL: https://60e69b11.revdiff.pages.dev
Branch Preview URL: https://in-session-annotation-flush.revdiff.pages.dev

View logs

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 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_output to write current annotations to --output without exiting (with status-bar feedback and safe atomic writes).
  • Adds --no-confirm-reload to skip the “annotations will be dropped” confirmation when reloading with R.
  • 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 thread app/annotation/store.go Outdated
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 thread app/main.go
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.

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

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.

Comment thread docs/ARCHITECTURE.md Outdated
### 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.
Comment thread CLAUDE.md Outdated
- `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.
@umputun
umputun merged commit dd599a5 into master Jul 3, 2026
5 checks passed
@umputun
umputun deleted the in-session-annotation-flush branch July 3, 2026 04:08
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