Repository navigation
generate: external generators (native and wasm), built-ins through the protocol - #104
Merged
Merged
Conversation
…rator protocol Re-pins core 98d64fa, generation 2d922ce (the codegen comline-rust 8bbce6d and comline-typescript be8bc79 pin; identical to e8b8a73's), and those generators. - `generator = "<path>"` on a [[generate.target]]: a .wasm runs under wasmtime 49.0.3 (feature gen-wasm, default on) with no preopens, env, network or args past argv[0], 1 GiB memory; anything else runs natively with a cleared env. - Describe first: protocol, IR format, language and version are checked. - Wall-time limit (`timeout`, default 60 s), 256 MiB stdout and generated-bytes caps, stderr shown prefixed and capped at 64 KiB, and every generated path checked before anything is written. - Built-ins answer an encoded Request through protocol::respond in process. - Tests: a fixture crate with the real Rust generator and a hostile one, built natively and for wasm32-wasip1.
This was referenced Oct 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step A3 of the generator-protocol track (core#8): the CLI runs generators outside its binary, and the built-ins go through the same protocol.
Re-pin
98d64fa, comline-rust8bbce6d, comline-typescriptbe8bc79.2d922ce, note8b8a73: both generators pin2d922ce, and Cargo only unifies identical rev strings.codegen/is the same at both revs (git diff 2d922ce e8b8a73 -- codegenis empty).chat_project,simple_projectandvalidated_projectgive byte-identical trees incodeandlibmode frommainand from this branch.Built-ins
external::builtinencodesRequest::generate(..)and answers it withprotocol::respond(®istry, &bytes), so the built-ins go through the sameRequest/Responsetypes and the same response checks as an external generator. The cost is well under a millisecond: about 0.05–0.6 ms onchat_projectin a release build, next to about 0.15–0.3 ms for generation itself.generator = "<path>".wasm: runs under wasmtime=49.0.3with wasmtime-wasi p1, behind cargo featuregen-wasm(on by default).[file name]only, and TCP, UDP and name lookup are off.StoreLimits, with one instance.env_clear(), with stdin, stdout and stderr piped.PATHisn't kept: a generator needs no other programs. On Windows only,SYSTEMROOTis kept, because a process can't load system DLLs without it. The process is killed when it times out or overflows stdout.Describecomes first.protocolsrange doesn't includePROTOCOL_VERSION, or whoseir_formatsdoesn't includeIR_FORMAT. The message names both sides.Generate. AResponse::Errorbecomesgenerator: <message>.lang_targetsapplies to external generators too.[<file>].FileOut.pathmust be non-empty and relative. It may not contain\, NUL,:or empty components, and no component may be.or... A response with any bad path is refused whole, before anything is written. This applies to the built-ins too.Tests
tests/fixtures/generatorsis a small crate built by the tests, natively and forwasm32-wasip1, intoCARGO_TARGET_TMPDIR:realis the official Rust generator overserve_stdio, the same ascomline-gen-rust. Its output is byte-identical to the built-in's, incodeandlibmode, both native and wasm.hostilemisbehaves according to its file name. Each case runs native and wasm, fails with a message naming the generator, and leaves nothing written:dotdot(../)absoluteoversizedtimeout(an infinite loop withtimeout = 2)mismatch(protocol 7)stderr(prefixed and capped)future(version not offered)readfs, wasm only: reading the filesystem fails.CI installs
wasm32-wasip1, and adds a clippy run withoutgen-wasmand a fmt check of the fixture crate.Binary size (release, x86_64 Linux)
gen-wasmgen-wasm(wasmtime withcranelift,runtimeandstdonly)With wasmtime's default features it was 37.6 MB unstripped and 27.0 MB stripped.
Left for later
encodingsisDefault::default()until B3.reference/generator-protocol.md.