3.9 KiB
PsychoScript (Rust)
The Rust implementation of the PsychoScript language layer, whose reference implementation is src/language/ of packages/codemode (the Language namespace: Runtime.make, Host, programs, suspend and resume, snapshots). It embeds in Rust programs with no Bun, Node or other JavaScript engine at build or run time. Code Mode (src/codemode/ of the reference: tools, schemas, the catalog, search, OpenAPI, hooks, maxToolCalls) is not part of this crate.
Parity with the reference language layer
This package is a second way to run and embed the same language, not a replacement. The two must stay equally capable in both directions.
- A language feature, built-in or host API lands in both 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.
- The public API in
crates/psychoscript/src/lib.rsis the Rust form ofsrc/language/index.ts; the README maps one to the other. Keep that table current. - Known differences are listed in the README; add to that list only with the owner's agreement, and prefer removing one.
Conformance
The recordings are generated from the reference's language layer; never edit them by hand. CI regenerates them and fails on any difference. Each generator's top comment states the host globals and runtime options it uses, which the Rust replays define the same way (conformance/reference.ts and conformance/reference.rs share the tools namespace):
conformance/cases/*.jsonbybun conformance/generate.ts, replayed bybench/tests/conformance.rs.conformance/host.jsonbybun conformance/host.ts(host functions: types, keys, idempotent and durable calls across a suspend, namespaces, failures,run.metadata, translation, limits), replayed bycrates/psychoscript/tests/host_recording.rs.conformance/boundary.jsonbybun conformance/boundary.ts(values crossing the host boundary, globals, module names and imports), replayed bycrates/psychoscript/tests/boundary.rs.conformance/streaming.jsonbybun conformance/streaming.ts(streaming responses, host-call arguments, fuel, suspensions), replayed bycrates/psychoscript/tests/streaming.rs.crates/psychoscript/tests/host.rsmirrors the reference'stest/language.test.ts.
Scope
- Pipeline: parse → compile to bytecode → stack VM. Values cross the host boundary as copies (
HostValue), never shared. - Out of scope, as in the reference: classes (rejected),
export, BigInt, Symbol beyond the well-known iterators.
Rules
- Functional style at the API: plugins are programs over data, not objects. Do not add classes to the language.
- Unsupported syntax throws
UnsupportedSyntaxwith a location where it runs; never panic on user input. - No
unsafeunless 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.shmust pass, andtest262/rust-skipped.txtandtest262/reference-gaps.txtmay only shrink. cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings, andcargo test --workspacemust 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, measured against the reference's language layer bybash bench/compare.sh. - CI: the
unitjob of.github/workflows/check-test.ymlruns these checks, round-trip conformance, conformance freshness, test262 and the informational bench on Linux, wheneverpackages/codemode,packages/codemode-rustor that workflow changed. - Nothing in the repo mentions internal tooling, private chats, home paths, hostnames or secrets.