marimo icon indicating copy to clipboard operation
marimo copied to clipboard

Auto-run code suggested by AI

Open vangberg opened this issue 1 year ago • 12 comments

Description

When I currently use AI completion, the workflow is as follows:

  1. Open AI completion
  2. Enter prompt
  3. Accept suggestion
  4. Run cell

Image

When I use Marimo, I often only care about the output. If the output is correct, the code is correct, since it does not need to generalize to arbitrary input, but is often limited to a single dataset.

With AI completion, I need to accept the suggested code change before I can see if it produces the correct output. This poses two problems. First, it is an extra step, breaking flow. Second, it makes it difficult to iterate on the code. If the output is not as expected, I need to start the process over, i.e. open AI completion and enter a new prompt, since the old prompt is gone.

Suggested solution

Auto-running the suggested code, while keeping the AI completion open, could improve this. A similar situation arose today in Cursor – I was using the Agent to help me produce a Markdown file. I had three columns open, one with the source, one with the Markdown preview, and one with the chat sidebar:

Image

I did not look at the source at all – since the rendered Markdown is what I cared about. I think the same is (often) the case in Marimo.

Will you submit a PR?

  • [ ] Yes

Alternative

No response

Additional context

Continued from https://github.com/marimo-team/marimo/discussions/5037

vangberg avatar Jun 04 '25 18:06 vangberg

Accept and run is a great suggestion. We could probably make a pass with our chat suggestions too.

dmadisetti avatar Jun 06 '25 19:06 dmadisetti

I think you are proposing that the code runs after accept. I'm looking for the suggested code to run immediately, before I hit accept or reject. The whole idea is that I need to see the output to decide if the code is actually good.

So, the flow would be:

  1. Type my prompt (e.g., "Plot x against y...").
  2. See the suggested code AND the live output (the plot).
  3. If the output's wrong, I tweak my prompt and repeat.
  4. If it's right, I accept.

Does that make sense?

vangberg avatar Jun 06 '25 20:06 vangberg

Yes, but it's dangerous. I think there's a spectrum of risk tolerance when it comes to generated code- and erring on the more conservative side is definitely the safer choice.

Maybe something we can make configurable though.

dmadisetti avatar Jun 06 '25 22:06 dmadisetti

Totally makes sense being safe-by-default.

On a walk the other day, it hit me, that all I really want/need is the ability to manually run the suggested code before accepting it. So if the UI was as it is today, with the added ability to run the suggested code before accepting/rejecting/fixing prompt, then it would fix the problem I described initially.

vangberg avatar Jun 15 '25 14:06 vangberg

Is this still something we want to solve before trying to run it?

https://github.com/marimo-team/marimo/blob/92c7bbb6f9a6e3542310a0507d43ba0f3d67fde6/frontend/src/core/codemirror/completion/Autocompleter.ts#L4 I need to check this, right?

rubiagatra avatar Jul 19 '25 06:07 rubiagatra

For what it's worth, Posit's new Databot does something like what I suggested.

Execute – The code is automatically executed in the current R or Python session. The output (including console output, plots, and tables) is visible both to the user and to Databot.

vangberg avatar Aug 29 '25 17:08 vangberg

Hi! I'd like to take a stab at this. Reading through the thread, I see two related but distinct needs:

"Accept and Run" chain accept + run cell in one click (the simpler ask) "Run before accepting" — a way to execute the suggested code while the AI panel stays open, so the output informs the accept/reject decision, with the cell reverting cleanly if rejected

My plan is to implement both in a single PR:

Add an "Accept and run" button alongside the existing Accept button Add a "Run" button that temporarily applies the suggestion and runs the cell, keeping the panel open for iteration. On rejection, the cell reverts to its previous state.

A few things I want to confirm before I start:

For "run before accepting" should the cell revert to its pre-suggestion state on reject, or stay with the AI code? Is there an existing mechanism for temporarily staging code into a cell without committing it, or would I need to handle that manually? @dmadisetti any preference on where the "run" button should live in the UI — next to Accept/Reject, or as a separate keyboard shortcut?

Happy to start with just "Accept and Run" first as a smaller PR if that's preferred.

Sushit-prog avatar Apr 01 '26 02:04 Sushit-prog

Thanks for the quick response, I saw the needs discussion label added. Happy to scope this down to just the "Accept and Run" button as a starting point if that's easier to move forward on, since that part seems already agreed upon. The "run before accepting" flow can be a separate discussion/issue if needed. Let me know how you'd like to proceed!

Sushit-prog avatar Apr 01 '26 14:04 Sushit-prog

Hi! I'm a CS student participating in CodePath's AI Open Source Capstone. I'd like to take a stab at the "Accept and Run" scoped version of this feature — a button that chains accept + run cell in one click. Happy to keep the "run before accepting" flow as a separate follow-up. Let me know if there are any preferences on UI placement or if this is still up for grabs!

AhnfLabib avatar Jul 08 '26 23:07 AhnfLabib

Hi! I've opened a draft PR implementing the safer scoped version of this feature discussed in the thread:

➡️ https://github.com/marimo-team/marimo/pull/10458

Scope: manual Run on AI cell completions (apply suggestion → run cell → keep AI panel open). Reject restores the session baseline. Accept keeps the code. Accept+▶ is unchanged. No auto-execute when a completion arrives.

Happy to adjust based on maintainer feedback — especially given the needs discussion label. Thanks!

AhnfLabib avatar Aug 05 '26 00:08 AhnfLabib

Hi! I'd like to work on this. My proposed approach: add a small "auto-run" toggle in the AI completion panel — when enabled, accepting a suggestion runs the cell immediately while keeping the panel open, reusing the existing run-cell action. No changes to the accept flow otherwise. Does that direction sound good, or would you prefer it handled differently?

noranobody avatar Sep 13 '26 13:09 noranobody

Hi, I'd like to work on this. Could a maintainer confirm the intended scope: is auto-running AI-suggested code expected to be implemented on the frontend (TypeScript) side, the Python side, or both? Happy to take the Python-side slice if that's where it belongs.

dasarijashwanth avatar Nov 27 '26 06:11 dasarijashwanth