Repository navigation
feat(agent): minimal agent edits, ask before saving unsaved work, readable history - #410
Conversation
…dable history Agent writes replaced the whole buffer, so the cursor jumped, undo recorded the entire file, and :AgentHistory showed two huge lines. They also saved the buffer, taking the user's unsaved changes to disk. - Apply agent writes as line hunks inside one transaction. The cursor and viewport stay on their text, and undo restores the cursor. - When a write targets a buffer with unsaved user changes, hold it and ask: apply and keep unsaved (default), apply and save, or don't apply. The answer is remembered per conversation and file until the next save. The question waits for a pause in typing and ignores keys for a moment; saving has no hotkey. Edit tools may wait 10 minutes; cancel, a lost app-server or a timed-out call closes the question. - Confirmation gains a multi-choice variant. - EditHistory (host API 0.22.0) takes scope "workspace" and returns file, turn, prompt, age, line counts and a unified diff with context per entry. :AgentHistory uses it: labelled rows across files, a themed diff, an agent-only filter, an empty state, and revert works in any open file with clear feedback.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4288c4188
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Keep host API 0.21.0: it is unreleased, so EditHistory.scope and the new entry fields join the existing 0.21.0 entry instead of a bump. - Bound history previews inside a single large replacement while still counting every added and removed line. - Release a pending unsaved-edit question when its conversation is closed, archived or reset, so later sessions are not held behind it. - Count only edits in the history summary, not the truncation notice.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4288c4188
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A capped preview reported total_lines as the kept length, and setting truncated made the workspace offer an "L full patch" action history cannot provide. Keep the full rendered length, end a capped preview with a note about the omitted lines, and leave the document untruncated.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d925053b89
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Show the selected row's diff whenever the selection moves, by mouse, half-page, gg/G, scrolling or filtering, so r reverts the edit on screen. - Workspace history entries drop the unbounded edits texts in favour of the bounded document, and an oversized result is trimmed to its newest entries instead of being dropped.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 928de2e483
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ines - After the user answers the unsaved-changes question, the status line reports what the write did (applied, saved, save failed, not applied) instead of the choice, which could claim success for a refused write. - Diff previews clip each line to 1,000 characters, so a changed line in a minified file does not keep the whole file in every preview.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb458c5676
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Choose the newest 500 transactions from parent links and timestamps first, then serialize and diff only those, so a long history of large edits does not stall the editor thread building entries it drops.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd5a3b4d15
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Only the new workspace scope is sorted newest first and capped; an unscoped request still returns the active buffer's whole undo tree in node order, as existing plugins expect.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c5d065582
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
History results now carry their scope, and heap trimming applies only to workspace results, which promise a newest-first prefix and a total. An unscoped result is delivered whole or not at all, as before.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7298366e7e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Unscoped EditHistory entries keep exactly their shipped shape; the diff document and labels are only added for the workspace scope, so a legacy result is no larger than before. - Diffs rendered from recorded replacements list hunks in document order, since agent hunks are applied bottom to top.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 505f0ca22a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
If the buffer was saved while the unsaved-changes question was open, the held write saw a clean buffer and was applied and saved, ignoring a "Don't apply". The answer now governs the write it was given for. Also make the typing-pause test independent of how slowly it runs.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9fab75f63e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The workspace hides meta lines by default once a diff has hunks, so the note about a capped preview was invisible. Render it as an unnumbered context line instead.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e53ce6d0a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Revert looked up the transaction's origin, and its buffer, by cloning the whole undo tree with every edit's text. Borrow the one transaction with UndoHistory::transaction_by_id instead.
|
@codex review |
# Conflicts: # docs/plugin_api_changes.json # src/codex/mod.rs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 91ae60fd5b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The real-Codex pair-mode evaluation found three problems with how agent edits land in the editor. Each one comes from the agent's write replacing the whole buffer and then saving it:
:AgentHistorywas unusable. Rows showed only a›marker. The detail was the whole file before and after with newlines stripped, so a one-line change read as two very long lines. The history also covered only the active buffer.What changed
Minimal edits (
src/editing/line_hunks.rs,apply_agent_contentsinsrc/editor.rs)similarand applied hunk by hunk inside the same single agent transaction.ustill undoes the whole agent edit and restores the cursor where it was.preserves_unsaved_edits, external change, NUL bytes, receipt capacity, and inline-history recording.Asking about unsaved changes (
src/editor/agent_edit_decision.rs,src/ui/confirmation.rs)u · Apply, keep unsaved: the default, and what Enter picks.Apply and save: today's behaviour. It has no hotkey, so you have to select it.n · Don't apply: also what Esc picks.Buffer::save_generationtracks the saves.saved: falsewith "left unsaved at the user's request", ordeclined: true.INSTRUCTIONStells it to report unsaved edits and never retry a declined one.write_fileandapply_editsmay now wait up to 10 minutes, instead of 30 s, in both the Codex dispatcher andEditorToolHost.Confirmationgainsnew_choicesfor any number of options, each with an optional hotkey, h/l/Tab navigation, a safe default and a designated cancel option.Edit history (
src/editor/edit_history.rs,plugins/agent.hk, host API0.22.0)EditHistory(callback, scope?)takes a new"workspace"scope that covers every open file, newest first. Each entry gains these fields:file: workspace-relative path.buffer_id.applied: false once the edit is undone.age: for example "5m ago".addedandremoved: line counts.document: a ready-to-show unified diff with hunk headers, three context lines and line numbers.turnandprompt: for agent edits.:AgentHistoryrenders:◆ src/util.rs +4 turn 1 · just nowfor agent edits and· src/report.rs +1 you · 5m agofor yours.atoggle that shows agent edits only.RevertTransactionnow finds the buffer that owns the transaction, so revert works on any open file without moving focus. It reports what it did, or why it can't revert.docs/PLUGIN_API.mdhas a new "Edit history" section.0.21.0stays in the supported list.How to Test
src/report.rsin a Rust project and put the cursor at 24:13 insideformat_cents. In the Agent pane, ask "Add a one-line doc comment directly abovepub fn summarize. Change nothing else."u. Expected: the comment is gone and the cursor is back at 24:13.// USER-UNSAVEDto that file without saving, then ask the agent for another doc comment.[ u · Apply, keep unsaved ] [ Apply and save ] [ n · Don't apply ].[+], the file on disk has neither change, and the agent reports that it left the buffer unsaved.n. Expected: nothing changes, and the agent describes the edit instead of retrying it.:AgentHistory.@@ -2,3 +2,7 @@headers, context and line numbers.ato show only agent edits. Select an agent edit to another file and pressr. Expected: "Reverted the agent edit in src/util.rs; the buffer is unsaved and u in it undoes the revert", and focus stays where it was.I ran all three flows against a real Codex app-server in tmux (
gpt-6.1-sol).Targeted tests:
cargo test --lib line_hunkscargo test --lib agent_edits_rewrite_only_changed_lines_and_keep_the_cursor_on_its_textcargo test --lib agent_edits_to_unsaved_buffers_ask_once_per_save_and_honour_each_choicecargo test --lib an_unsaved_edit_question_waits_for_a_typing_pause_and_ends_with_its_tool_callcargo test --lib choice_dialogs_ignore_early_keyscargo test --lib workspace_history_labels_agent_turns_shows_context_and_reverts_other_filescargo test --lib bundled_agent_history_labels_rows_and_shows_a_line_diff