Add `/repl` to run your own cells in the `clai2` `run_code` REPL, from the terminal or the web UI

Merged
MP
2mo ago
+504-69

Part 11 of the clai2 web UI stack (… → #10278 → this PR). Based on #10278. No linked issue: requested by the CLAI maintainer, building on #10256.

Why. Since #10256, code mode keeps the run_code REPL with the session between turns. This lets the user change its state too, from the terminal or the web UI, and lets the model know.

New public surface

  • /repl CODE: runs your own cell in the session's REPL between turns. It prints what the cell printed and returned (-> value). A failing cell is reported as an error, not retried.
  • Web plugin: cells you run are marked by_user and labelled you in the REPL panel, and the panel gets an input (Enter runs, Shift+Enter adds a line) that sends /repl.

How it works, with no new harness API. A cell is a run of the session's own agent and capabilities (Session.run_in_repl) whose model is scripted (ReplCell): it calls run_code once with the user's code, then stops. So the cell gets exactly what the model's cells get: the session's tools, sandbox mounts, resource limits, and the repl_store from #10256. There is no second way to drive Monty.

  • The run is kept out of the conversation and marked with run metadata (REPL_CELL), so the web UI shows a cell, not a turn.
  • The next prompt carries a note per cell ("Between turns, the user ran this cell in your run_code REPL…"), since the variables are in the model's sandbox now. The browser hides that note from the chat bubble; the panel already shows the cells.
  • Notes stay with their conversation: after /new, they are dropped.
  • Session gains _add_local_workspace, shared by prompt and run_in_repl.

Verification.

  • tests/clai2/test_repl_state.py::test_a_user_cell_runs_in_the_session_repl: /repl x = 41, then the model's own x + 1 returns 42 on the next turn, whose prompt carries the notes once.
  • More tests there cover a failing cell, notes staying with their conversation, the refusals, a cell during a turn, and how results are formatted.
  • tests/clai2/test_web.py::test_a_repl_cell_from_the_browser: a cell from the browser is by_user, starts no turn, and reports 42.
  • The plugin and repl_cells have 100% branch coverage.
  • Headed Playwright against clai2 --web with claude-code:claude-haiku-4-5: I ran secret = "pydantic" * 2 (printed set 16) and secret.upper() (PYDANTICPYDANTIC) from the panel. The model then ran print(secret) without defining it and answered "pydanticpydantic". The terminal showed the same cells. No page errors.

What changes for existing users. A new /repl command. Nothing else changes unless they use it.

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.