Skip to content

feat(ai): run suggested code before accepting (#5196) - #10458

Open
AhnfLabib wants to merge 11 commits into
marimo-team:mainfrom
AhnfLabib:issue-5196-ai-run-before-accept
Open

feat(ai): run suggested code before accepting (#5196)#10458
AhnfLabib wants to merge 11 commits into
marimo-team:mainfrom
AhnfLabib:issue-5196-ai-run-before-accept

Conversation

@AhnfLabib

Copy link
Copy Markdown

This pull request was authored by a coding agent.

What does this PR do?

Adds a manual Run action on AI cell completions so users can execute the suggested code, see output, and then Accept or Reject while the AI panel stays open. Reject restores the pre-session cell baseline. Accept keeps the suggestion. Accept+▶ (accept-then-run) is unchanged. Suggestions are never auto-executed when they arrive.

Why was this PR needed?

Related to #5196 (continued from discussion #5037). Users often need cell output to judge AI suggestions; requiring Accept first breaks iteration and loses the prompt. Maintainers flagged auto-run as dangerous; this implements the safer manual run-before-accept path. Note: Accept-and-run already ships in main; this PR addresses the remaining gap.

What are the relevant issue numbers?

Related to #5196

(Issue is still labeled needs discussion, so this is a draft for review rather than Closes.)

Screenshots / Recordings (if applicable)

Manual QA recommended: AI completion → Run → output appears with panel open → Reject restores / Accept keeps.

Does this PR meet the acceptance criteria?

  • Tests added for new/changed behavior
  • All tests passing (focused Vitest suites for helpers + Run button)
  • Follows project style guide
  • No breaking changes introduced
  • Documentation updated (if applicable) — N/A for this UX affordance

📝 Summary (upstream template)

Related to #5196.

Adds manual preview-run for AI cell suggestions without accepting, with baseline restore on reject/close.

📋 Pre-Review Checklist

  • For large changes / UX: discussed on issue Auto-run code suggested by AI #5196 (scoped to manual Run; issue still needs discussion — seeking maintainer guidance)
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes (optional).

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable.
  • Tests have been added for the changes made.

Safety

Manual Run only — never executes on completion stream finish.

AhnfLabib and others added 6 commits August 4, 2026 20:11
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Allows previewing AI suggestion output while keeping the completion
panel open; reject restores the session baseline.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview Aug 5, 2026 1:04am

Request Review

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@AhnfLabib

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

AhnfLabib and others added 3 commits August 4, 2026 20:47
Align with upstream reject behavior while still restoring the
session baseline when a suggestion was preview-run.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep preview baseline restore and adopt main's reject-keeps-prompt-open behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
@AhnfLabib
AhnfLabib marked this pull request as ready for review August 5, 2026 00:51
Copilot AI review requested due to automatic review settings August 5, 2026 00:51
@AhnfLabib
AhnfLabib marked this pull request as draft August 5, 2026 00:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a “preview run” path for AI completion suggestions in the editor: users can manually run the suggested code without accepting it, then either accept to keep it or reject/close to restore the pre-session baseline, keeping the AI panel/prompt available for iteration.

Changes:

  • Adds baseline-capture/restore helpers to support running suggested code before acceptance, with restoration on reject/close/resubmit.
  • Introduces a new Run button for AI completions and wires it into the completion banner and inline action row.
  • Adds Vitest coverage for the new helpers and the Run button behavior.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
frontend/src/components/editor/ai/completion-preview.ts Adds small helper functions to track baseline and decide when/how to restore or render merge “original” code after preview runs.
frontend/src/components/editor/ai/completion-handlers.tsx Adds RunCompletionButton UI component used to preview-run suggestions.
frontend/src/components/editor/ai/ai-completion-editor.tsx Implements preview-run flow (baseline capture, run, restore on reject/close, correct merge original after preview).
frontend/src/components/editor/ai/tests/completion-preview.test.ts Tests baseline/restore/merge-original helper logic.
frontend/src/components/editor/ai/tests/completion-handlers.test.tsx Tests RunCompletionButton click and disabled state.
.gitignore Ignores local .worktrees/ directories.

Comment thread frontend/src/components/editor/ai/completion-handlers.tsx Outdated
@AhnfLabib
AhnfLabib marked this pull request as ready for review August 5, 2026 01:01
AhnfLabib and others added 2 commits August 4, 2026 21:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ahnaf Labib <105464161+AhnfLabib@users.noreply.github.com>
@Light2Dark

Copy link
Copy Markdown
Member

could you share a video? @AhnfLabib

@AhnfLabib

Copy link
Copy Markdown
Author
marimo_ahnaf_demo.mov

@Light2Dark Here's a demo of the manual Run-before-accept flow:

  1. Run (preview) → then Accept
  2. Accept + ▶ (accept-and-run)
  3. Reject (restores baseline / discards suggestion)

Happy to adjust based on feedback!

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.

3 participants