Skip to content

feat(core): add experimental stateful Code Mode REPL - #68600

Draft
rekram1-node wants to merge 6 commits into
devfrom
session-repl
Draft

rekram1-node wants to merge 6 commits into
devfrom
session-repl

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

N/A (experimental feat behind optInOnly flag codemode_repl).

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds an experimental, opt-in persistent REPL for Code Mode (execute tool), guarded by the new optInOnly flag codemode_repl (requires full_codemode; enable with OPENCODE_FLAGS=full_codemode,codemode_repl or experimental.codemode_repl: true).

  • psychoscript@0.14.0: bumps psychoscript from 0.11.0 to 0.14.0 (includes feat(runtime): add experimental persistent sessions psychoscript#249).
  • @opencode/codemode: wraps runtime.experimental.session() and runtime.experimental.restore() from psychoscript/effect, including optional SessionStore, and resets per-cell tool call lists in run.metadata when runId changes between cells.
  • SQLite persistence + lazy unloading (packages/core/src/codemode/repl.ts, sql.ts): stores one zstd-compressed root snapshot per session in codemode_repl_session and SHA-256 content-addressed blobs in codemode_repl_blob + codemode_repl_blob_ref. After each settled cell (including throws), bindings untouched for >5 cells unload automatically to blobs, and transient blobs written during a tool-inventory swap are GC'd in the commit transaction. Cold sessions evict by LRU (MAX_WARM_SESSIONS = 64 / MAX_WARM_BYTES = 256 MiB), spilling remaining bindings so cold restores stay tiny and lazy.
  • Session lifecycle: fork shares blob refs zero-copy when at or before copiedSeq; revert stage cancels any active background REPL job and drops the warm VM (leaving SQLite intact for undo); revert commit resets if visible_seq >= boundary.seq; session delete releases refs and cleans orphan blobs. Tool catalog changes (e.g. MCP add/remove) transfer state cleanly to the new runtime; build or extension-mode changes reset with a 1-line [repl reset: ...] footer.
  • Isolation & public API: automations, Tool.check, and subagents stay stateless. execute keeps its name and code parameter. Live binding summaries append as a 1-line tool-result footer (prompt-cache safe). Only codemode_repl is added to the experimental config flag registry (client types regenerated).

How did you verify your code works?

  • cd packages/codemode && bun typecheck && bun run typecheck:tsc && bun test — 337 pass, 0 fail.
  • cd packages/core && bun typecheck && bun run typecheck:tsc — 0 errors across 2,104 files.
  • cd packages/core && bun test test/codemode/repl.test.ts test/codemode.test.ts test/codemode-input-blocks.test.ts test/codemode/durable.test.ts test/codemode/execute-durable.test.ts test/automation.test.ts — 114 pass, 0 fail (covers persistence, cold unloading to SQLite blobs, lazy restore after forget, MCP inventory swap, zero-copy fork + orphan blob GC, mode-key reset notice, per-cell inputs scoping, and automation parity).
  • cd packages/client && bun run generate — regenerated packages/client/src/promise/generated/types.ts.
  • bunx oxlint on all modified/new source files — clean.

Screenshots / recordings

N/A (no UI changes).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.

1 participant