Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
db56604
feat(codemode): add embeddable Rust port
kommander Nov 17, 2026
eeee8dc
test(codemode): add a test262 parity runner for the Rust port
kommander Nov 17, 2026
4bc3e97
test(codemode): add perturbed variants and a plugin-event benchmark
kommander Nov 17, 2026
13570b7
chore(codemode): pin the Rust toolchain and prepare compare.sh for CI
kommander Nov 17, 2026
5b1125c
fix(codemode): stop compare.sh flagging its own output as an uncommit…
kommander Nov 17, 2026
f89740d
test(codemode): regenerate the benchmark results with variants and pl…
kommander Nov 17, 2026
251dfc8
chore(codemode): add a CI workflow for the Rust port
kommander Nov 17, 2026
9ab9595
docs(codemode): keep the TypeScript and Rust packages equally capable
kommander Nov 17, 2026
833099b
test(codemode): check test262 parity in both directions
kommander Nov 17, 2026
871b1af
feat(codemode): add schema tools, search, hooks, async host calls and…
kommander Nov 17, 2026
5379006
Merge the test262 runner into the host API work
kommander Nov 17, 2026
9f8c722
chore(codemode): run the Rust checks in check-test's unit job
kommander Nov 17, 2026
f0d1120
perf(codemode): compile tool schemas once and keep host calls off the…
kommander Nov 17, 2026
2ebbab5
test(codemode): cover extensions and tool calls against the reference
kommander Nov 17, 2026
b58381c
perf(codemode): make host globals and run ids only when a run uses them
kommander Nov 17, 2026
a0635fc
Merge the CI move into the host API work
kommander Nov 17, 2026
f356df0
fix(codemode): convert functions, generators and iterators through To…
kommander Nov 17, 2026
b2ba869
fix(codemode): evaluate new arguments before checking the constructor
kommander Nov 17, 2026
82bdea7
fix(codemode): evaluate the right side of o.x = v before checking o
kommander Nov 17, 2026
aa304b8
fix(codemode): delete on a primitive base is true unless the wrapper …
kommander Nov 17, 2026
223bff4
fix(codemode): match JS in built-in object details
kommander Nov 17, 2026
acd81ef
fix(codemode): let in find an array hole's inherited index
kommander Nov 17, 2026
f6bb82c
fix(codemode): convert Array arguments, lengths and sort elements thr…
kommander Nov 17, 2026
58c673f
fix(codemode): parse Unicode 17 identifiers with acorn 8.16
kommander Nov 17, 2026
dc76fbc
feat(codemode): add OpenAPI tools to the Rust port
kommander Nov 17, 2026
372836c
chore(codemode): regenerate the catalog expectations in the conforman…
kommander Nov 17, 2026
1b45ae7
feat(codemode): let a tool interrupt its whole run
kommander Nov 17, 2026
2071e01
fix(codemode): word the timeout diagnostic as the reference does
kommander Nov 17, 2026
4d060f8
feat(codemode): report unhandled rejections as warnings
kommander Nov 17, 2026
10c06d2
test(codemode): cover the warnings output budget
kommander Nov 17, 2026
5773c3d
fix(codemode): match the reference on 3.0 keywords, moved references …
kommander Nov 17, 2026
2a0de39
feat(codemode): add RegExp and regex-aware String methods
kommander Nov 17, 2026
fae9a99
feat(codemode): add String normalize, raw, isWellFormed and toWellFormed
kommander Nov 17, 2026
b857303
feat(codemode): add Date
kommander Nov 17, 2026
228bdba
feat(codemode): add Uint8Array, Buffer, TextEncoder, TextDecoder, ato…
kommander Nov 17, 2026
28df82c
feat(codemode): add Iterator helpers, WeakMap, WeakSet, groupBy and S…
kommander Nov 17, 2026
df123be
fix(codemode): reject non-object receivers in Object.prototype methods
kommander Nov 17, 2026
caeb177
feat(codemode): add URI functions, toExponential, Math.sumPrecise, f1…
kommander Nov 17, 2026
b1724d8
feat(codemode): add URL, URLSearchParams, Headers, crypto and structu…
kommander Nov 17, 2026
ff6dbde
perf(codemode): install the larger built-in groups only when a run us…
kommander Nov 17, 2026
ab2fbbd
fix(codemode): match JavaScriptCore's Math.hypot
kommander Nov 17, 2026
450f3fe
refactor(codemode): expose URL and Headers constructors to the crate
kommander Nov 17, 2026
1597db6
perf(codemode): resume generators on the dispatch loop
kommander Nov 17, 2026
95cc587
fix(codemode): stop ToNumber panicking on a non-ASCII string
kommander Nov 17, 2026
9783f81
perf(codemode): append concatenations in place
kommander Nov 17, 2026
925b00b
feat(codemode): add async generators and for await
kommander Nov 17, 2026
5c9d8fe
fix(codemode): give function kinds their own prototypes, like the ref…
kommander Nov 17, 2026
948739d
fix(codemode): reject circular values and Promise.race([]) like the r…
kommander Nov 17, 2026
d9bef6f
feat(codemode): add tagged templates
kommander Nov 17, 2026
28e7332
fix(codemode): bind programs as scripts and fix loop and parameter sc…
kommander Nov 17, 2026
d45feb5
test(codemode): adapt the reference's language tests as lang- cases
kommander Nov 17, 2026
17fc3e2
fix(codemode): guard opaque operands and word iteration errors like t…
kommander Nov 17, 2026
5a91e74
fix(codemode): one arguments object per call, keys converted once
kommander Nov 17, 2026
d6d8ca0
test(codemode): drop test262 files that RegExp and tagged templates n…
kommander Nov 17, 2026
8468baf
feat(codemode): carry dates, URLs, headers, bytes and RegExps across …
kommander Nov 17, 2026
46fe7df
feat(codemode): suspend and resume runs from snapshots
kommander Nov 17, 2026
1d0ce81
chore(codemode): check Rust conformance in round-trip mode in CI
kommander Nov 17, 2026
ad59ddf
feat(codemode): real array holes
kommander Nov 17, 2026
08453ce
perf(codemode): skip the exotic JSON hook until a run can hold such a…
kommander Nov 17, 2026
ee8cff4
fix(codemode): throw when a built-in accessor is read off its prototype
kommander Nov 17, 2026
261420a
fix(codemode): match the reference's host for Math.sumPrecise and **
kommander Nov 17, 2026
74fa6bf
feat(codemode): add console.table
kommander Nov 17, 2026
dfce7b4
fix(codemode): resolve \k to whichever duplicate named group matched
kommander Nov 17, 2026
564c449
fix(codemode): reject Promise combinators whose input cannot be iterated
kommander Nov 17, 2026
cc6d0c8
fix(codemode): let a function's name and length be deleted, and name …
kommander Nov 17, 2026
b7faceb
feat(codemode): stream HTTP responses to programs through extensions
kommander Nov 17, 2026
04a88fc
fix(codemode): delete, arguments, await names and iterator errors mat…
kommander Nov 17, 2026
83a6e04
fix(codemode): keep the clock across round trips and make round-trip …
kommander Nov 17, 2026
57b284c
fix(codemode): name the callee in call errors, as the reference does
kommander Nov 17, 2026
b59c319
fix(codemode): assigning undefined fails like assigning a constant
kommander Nov 17, 2026
fb3aa7e
fix(codemode): match the reference's Array methods on frozen arrays, …
kommander Nov 17, 2026
67e6316
feat(codemode): collate localeCompare like the reference's host
kommander Nov 17, 2026
3e6f176
feat(codemode): keep lone surrogates in strings
kommander Nov 17, 2026
217a99b
fix(codemode): word RegExp syntax errors as the reference's host does
kommander Nov 17, 2026
b640110
fix(codemode): read 2^32 - 1 and above on an array as plain keys
kommander Nov 17, 2026
2402dc6
fix(codemode): new Map and Object.fromEntries reject a non-entry as t…
kommander Nov 17, 2026
c09e47a
fix(codemode): iterator helpers name the call that made a record whos…
kommander Nov 17, 2026
9cf731f
fix(codemode): a program may name things await and still await at the…
kommander Nov 17, 2026
25dcb84
fix(codemode): start streaming reads where the reference's fuel runs out
kommander Nov 17, 2026
c49ebc2
feat(codemode): hold huge sparse arrays
kommander Nov 17, 2026
496415c
fix(codemode): keep lone surrogates in a streaming response's json()
kommander Nov 17, 2026
178443e
fix(codemode): spend the prelude's fuel in array, collection and set …
kommander Nov 17, 2026
37c98c0
fix(codemode): spend the prelude's fuel in sorts, bytes, replace and …
kommander Nov 17, 2026
6eb7319
fix(codemode): spend the prelude's fuel in the iterator helpers
kommander Nov 17, 2026
e488b27
fix(codemode): spend the reference's fuel in Promise combinators and …
kommander Nov 17, 2026
f9ee2e8
fix(codemode): spend the reference's fuel converting objects to primi…
kommander Nov 17, 2026
4887770
perf(codemode): keep the prelude's fuel cheap on the callback paths
kommander Nov 17, 2026
05daeda
fix(codemode): a custom iterator's native next costs a call
kommander Nov 17, 2026
5adbe73
fix(codemode): step a built-in iterator a custom Symbol.iterator retu…
kommander Nov 17, 2026
f92d608
fix(codemode): convert a native's listed values as the reference's $v…
kommander Nov 17, 2026
52f9f7b
fix(codemode): spend the reference's fuel in for await over sync iter…
kommander Nov 17, 2026
7484ae6
fix(codemode): convert the default sort's values as one list
kommander Nov 17, 2026
5c66d35
fix(codemode): stringify through the walk after 2,048 revisits of sha…
kommander Nov 17, 2026
b314a62
chore(codemode): let compare.sh run on macOS
kommander Nov 17, 2026
ddbc4e6
test(codemode): regenerate the benchmark results
kommander Nov 17, 2026
c6799f8
perf(codemode): skip the suspend bookkeeping when a built-in calls back
kommander Nov 17, 2026
dae7f1d
feat(codemode): await promises nested in what crosses to the host
kommander Nov 17, 2026
b03f740
fix(codemode): a crossing's depth error costs no fuel
kommander Nov 17, 2026
2450f6e
fix(codemode): JSON.stringify stops at the reference's depths
kommander Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
103 changes: 103 additions & 0 deletions .github/workflows/check-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ jobs:
# Pull requests diff against the merge's first parent; pushes diff against the previous dev head.
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}

# The Rust port of codemode is checked in this job, on Linux, only when it or its TypeScript reference changed.
# Runs without a base to diff against (manual runs, the release gate, a new branch) check it always.
- name: Decide whether the codemode Rust checks run
id: codemode-rust
if: runner.os == 'Linux'
run: |
paths=(packages/codemode packages/codemode-rust .github/workflows/check-test.yml)
if [ "$AFFECTED" != "true" ] || ! git cat-file -e "${TURBO_SCM_BASE}^{commit}" 2>/dev/null; then
run=true
elif git diff --quiet "$TURBO_SCM_BASE" "$TURBO_SCM_HEAD" -- "${paths[@]}"; then
run=false
else
run=true
fi
echo "run=$run" >> "$GITHUB_OUTPUT"
echo "codemode Rust checks: $run"

- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
Expand Down Expand Up @@ -155,6 +172,92 @@ jobs:
working-directory: packages/protocol
run: bun run check:generated

# The toolchain, profile and components come from packages/codemode-rust/rust-toolchain.toml.
- name: Install Rust for codemode
if: runner.os == 'Linux' && steps.codemode-rust.outputs.run == 'true'
working-directory: packages/codemode-rust
run: rustup toolchain install --no-self-update

# One cache for the debug and release builds below.
- name: Cache codemode Rust builds
if: runner.os == 'Linux' && steps.codemode-rust.outputs.run == 'true'
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
with:
shared-key: codemode-rust
key: ${{ hashFiles('packages/codemode-rust/rust-toolchain.toml') }}
workspaces: packages/codemode-rust -> target

- name: Check codemode Rust formatting, Clippy and tests
if: runner.os == 'Linux' && steps.codemode-rust.outputs.run == 'true'
timeout-minutes: 15
working-directory: packages/codemode-rust
run: |
cargo fmt --check
cargo clippy --locked --workspace --all-targets -- -D warnings
# Includes bench/tests/conformance.rs, which checks every conformance case against the reference outcome.
cargo test --locked --workspace

# Saves and restores every run at each host stop and after 64, 128, 256, ... loop iterations; outcomes must not
# change. Reuses the debug build of the step before and takes seconds.
- name: Check codemode Rust conformance in round-trip mode
if: runner.os == 'Linux' && steps.codemode-rust.outputs.run == 'true'
timeout-minutes: 5
working-directory: packages/codemode-rust
env:
PSYCHOSCRIPT_ROUNDTRIP: "1"
run: cargo test --locked -p psychoscript-bench --test conformance

# A change to the reference fails here until the Rust side is updated and the expectations regenerated.
- name: Check codemode Rust conformance expectations match the reference
if: runner.os == 'Linux' && steps.codemode-rust.outputs.run == 'true'
working-directory: packages/codemode-rust
run: |
bun conformance/generate.ts
bun conformance/catalog.ts
bun conformance/streaming.ts
git status --porcelain -- conformance
git diff --exit-code -- conformance
test -z "$(git status --porcelain -- conformance)"

- name: Read the pinned test262 revision
id: test262
if: runner.os == 'Linux' && steps.codemode-rust.outputs.run == 'true'
run: |
revision=$(jq -r .revision packages/codemode/test/test262/manifest.json)
echo "revision=$revision" >> "$GITHUB_OUTPUT"
echo "checkout=$HOME/.cache/test262-$revision" >> "$GITHUB_OUTPUT"

- name: Cache the test262 checkout
if: runner.os == 'Linux' && steps.codemode-rust.outputs.run == 'true'
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ${{ steps.test262.outputs.checkout }}
key: test262-${{ steps.test262.outputs.revision }}

# Parity both ways, against test262/rust-skipped.txt and test262/reference-gaps.txt; see test262/README.md.
- name: Check codemode Rust test262 parity
if: runner.os == 'Linux' && steps.codemode-rust.outputs.run == 'true'
timeout-minutes: 10
working-directory: packages/codemode-rust
env:
TEST262_CHECKOUT: ${{ steps.test262.outputs.checkout }}
run: bash test262/run.sh

# Shared runners are too noisy for a performance gate; the numbers go to the job summary only.
- name: Benchmark codemode Rust against the reference (informational)
if: runner.os == 'Linux' && steps.codemode-rust.outputs.run == 'true'
continue-on-error: true
timeout-minutes: 10
working-directory: packages/codemode-rust
env:
ITERATIONS: "5"
COLD_RUNS: "5"
PLUGIN_RUNS: "2000"
run: |
[ -x /usr/bin/time ] || (sudo apt-get update && sudo apt-get install -y time)
bash bench/compare.sh
cat bench/RESULTS.md >> "$GITHUB_STEP_SUMMARY"

build:
name: build (${{ matrix.settings.name }})
# Compiling the CLI and smoke-testing its service lifecycle is part of the full tier.
Expand Down
1 change: 1 addition & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
"**/*.d.ts",
"**/sdk.gen.ts",
"packages/plugins/figma/skills/**",
"packages/codemode-rust/conformance/cases/**",
".agent/**",
".agents/**",
".claude/**",
Expand Down
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/codemode-rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
37 changes: 37 additions & 0 deletions packages/codemode-rust/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# PsychoScript (Rust)

A Rust port of OpenCode's Code Mode (`packages/codemode` in anomalyco/opencode, the reference implementation), embeddable in Rust programs with no Bun, Node or other JavaScript engine at build or run time.

## Parity with the TypeScript package

This package is a second way to run and embed the same language, not a replacement. `packages/codemode` stays, and the two packages must stay equally capable in both directions.

- A language feature, built-in or host API lands in both packages or in neither. Rust-native forms of a reference API (futures instead of Effects, closures or traits instead of services) are fine; Rust-only capabilities are not.
- Conformance expectations are always generated from `packages/codemode`; never edit them by hand. CI regenerates them and fails on any difference.
- `test262/rust-skipped.txt` lists reference-passing files Rust still fails; it may only shrink.

## Scope: minimal, targeted

In scope:

- The language subset needed by the nine reference benchmark programs (`conformance/cases/bench-*`), the plugin reducer example, and the other conformance cases.
- Pipeline: parse → compile to bytecode → stack VM. Values cross the host boundary as JSON copies (`serde_json::Value`), never shared.
- Host API in `crates/psychoscript/src/lib.rs`, the Rust form of the reference's README API: schema-described tools (sync or futures) at dotted paths with namespaces, OpenAPI tools (`openapi::from_spec` over a host `HttpClient`), the catalog and `search`, hooks, extensions with `import`/`require`, programs (`Runtime::program`), suspending and resuming runs (`Suspender`, `Runtime::resume`, idempotent and durable tools, extension `snapshot` hooks), JSON bindings, limits (`timeout_ms`, `max_tool_calls`, `max_output_bytes`), `console.log` captured into `logs`.
- Parity runs both ways: add no language feature or host API the reference lacks. Rust-native forms of reference APIs (futures for Effects, a blocking `execute`) are fine.
- `conformance/catalog.json` is generated by `bun conformance/catalog.ts` from the reference; never edit it by hand.
- `conformance/streaming.json` is generated by `bun conformance/streaming.ts` from the reference (streaming responses, which the reference has no tests for); never edit it by hand.

Out of scope: classes (rejected, like the reference), `export`, Effect integration, BigInt, Symbol beyond iterators.

## Rules

- Functional style at the API: plugins are programs over data, not objects. Do not add classes to the language.
- Unsupported syntax returns `UnsupportedSyntax` with a location; never panic on user input.
- No `unsafe` unless measured and justified in a comment.
- Dependencies: pure Rust only, and few. Justify each in the commit that adds it.
- test262 parity runs both ways: `bash test262/run.sh` must pass, and `test262/rust-skipped.txt` and `test262/reference-gaps.txt` may only shrink.
- `cargo fmt --check`, `cargo clippy --workspace --all-targets -- -D warnings`, and `cargo test --workspace` must pass.
- The conformance cases must also pass in round-trip mode, which saves and restores every run at each host stop and after 64, 128, 256, … loop iterations: `PSYCHOSCRIPT_ROUNDTRIP=1 cargo test -p psychoscript-bench --test conformance`.
- Benchmark claims need the command, machine and numbers in `bench/RESULTS.md`.
- CI: the `unit` job of `.github/workflows/check-test.yml` runs these checks, round-trip conformance, conformance freshness, test262 and the informational bench on Linux, whenever `packages/codemode`, `packages/codemode-rust` or that workflow changed.
- Nothing in the repo mentions internal tooling, private chats, home paths, hostnames or secrets.
Loading
Loading