Skip to content

feat(work): add undo for accepted AI Work results - #466

Open
Dhruv-Sharma29 wants to merge 1 commit into
petertzy:mainfrom
Dhruv-Sharma29:feat/work-mode-undo
Open

Dhruv-Sharma29 wants to merge 1 commit into
petertzy:mainfrom
Dhruv-Sharma29:feat/work-mode-undo

Conversation

@Dhruv-Sharma29

Copy link
Copy Markdown
Contributor

Closes #462

Problem

Work Mode let you accept an AI result, but the Work panel had no way to undo it.

  • Active document: editor Undo (Cmd/Ctrl+Z) could step back over the AI edit, but nothing in Work Mode offered this.
  • Open project: accepting a proposal writes several tabs through React state, outside any single Monaco model, so editor Undo could not revert it at all.

Changes

Active-document Work

  • After a result is applied, the Work tab shows an Undo AI Changes button.
  • It restores the pre-Work text through the existing applyWorkEdit path, as one undoable editor edit. Editor Undo can then bring the AI result back.
  • If the document was edited after the AI result was applied, it refuses and points you to editor Undo instead. It never overwrites your later typing. The freshness check reuses isWorkResultFresh.

Project Work

  • Before accepting a proposal, captureProjectWorkUndo snapshots every tab the change touches.
  • Undo accepted changes in the project review calls revertProjectWork, which:
    • restores each modified tab's previous content and dirty state;
    • closes the tabs that the result opened;
    • leaves alone any tab that was edited after accepting, or a new file that was already saved, and lists those files in the status message;
    • keeps a tab dirty if its AI content was saved, because the file on disk no longer matches the restored text.
  • Switching projects clears the undo record.

Files

  • frontend/src/lib/project-work-undo.mjs: the capture and revert logic (pure functions, easy to test)
  • useProjectWork, useEditor (revertProjectChanges), useAIActions (undoWork, canUndoWork), AIPanel, ProjectWorkReview: wiring and buttons

Testing

  • New tests/project-work-undo.test.mjs covers: reverting edits and closing opened tabs, never discarding later user edits, and saved results and saved new files.
  • npm test (165 pass), npx tsc --noEmit, npm run lint, npm run build all pass.
  • I didn't test the full AI round trip by hand, because it needs a configured AI provider.

Work Mode let users accept AI results but gave no way to back them out
from the Work panel. Project Work was worse: it rewrites several tabs
through React state, so editor Undo could not revert it at all.

- Active document: an "Undo AI Changes" button restores the pre-Work
  text as one undoable editor edit. It refuses if the document was edited
  since, pointing the user to editor Undo instead.
- Open project: accepting a proposal snapshots every affected tab. "Undo
  accepted changes" restores them and closes tabs the result opened.
  Tabs edited or saved after accepting are left alone and listed.

Closes petertzy#462
Copilot AI balanced review requested due to automatic review settings November 6, 2026 08:46

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@petertzy
petertzy requested a review from karaaslanz November 6, 2026 11:18

This branch has not been deployed

No deployments
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.

Add Undo Support to Work Mode

2 participants