Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.
Port a whole app
Port a whole CLI, server or library, unit by unit, until it is pure Rust. Back to the README.
Port a whole app
The goal is a pure Rust app that behaves like the original, with the original kept as reference. Your agent writes the Rust; rust-anything orders the work, scaffolds it, and proves every step. The whole-app skill walks the agent through it, starting with the decisions only you can make:
- Grilling: the agent asks in rounds, each question with its recommended answer, until every
decision the port depends on is settled, and writes each one as an ADR in
rust/DECISIONS.md, withrust/GLOSSARY.mdmapping the original's terms to Rust names. - Research: background agents read each dependency's primary sources and write
rust/research/<topic>.md, with every semantic trap they found. - Across sessions:
rust/MAP.mdlists every unit with its state; a session claims one unit before it starts, and each checkpoint leaves arust/HANDOFF.mdfor the next session. Units in one wave can be ported in parallel by subagents. - Cutover: the agent does what it can and writes
rust/cutover.sh, an interactive script for the steps only you can do (deploys, DNS, secrets), with a way back at each step.
Grilling, research and these practices are adapted from Matt Pocock's skills.
Checking a rewrite in any language. app record and app replay only run programs: the
recording is what the original did from the outside (arguments, stdin, files, HTTP), and
app replay --build "<command>" runs any build against it. A rewrite in Go, or by hand, is
checked the same way as the Rust front door:
rust-anything app record . -- java -jar app.jar # what the original does
rust-anything app replay . --build "./app-go" # does the rewrite do the same?
The unit tools (bridge, record, diff, gate) and lift are Rust-specific.
Side effects: email, webhooks and databases
A rewrite can answer with the same JSON and still send an email twice or write different rows.
app record can record what leaves the process too, per case, and app replay compares it:
rust-anything app record . --effects http,smtp --effect-env WEBHOOK_URL=http-url \
--db-reset "sh scripts/reset-db.sh" --db-dump "sqlite3 app.db .dump" -- python3 app.py
--effects httpruns a local HTTP sink that answers every request with200 {}, set asHTTP_PROXY,HTTPS_PROXY,ALL_PROXY(and their lower-case forms) andRUST_ANYTHING_HTTP_SINK, withNO_PROXYemptied. Each request is recorded as method, URL, content type and body. HTTPS through the proxy is recorded asCONNECT host:443and refused, since the sink cannot read it: point HTTPS settings at the sink with--effect-envinstead. A client that ignores the proxy variables is not caught by the sink. A--db-dumpthat fails makesapp recordfail, and a replay in which it fails is a failing case, because a failed dump is no database state to match.--effects smtpruns a local mail server (SMTP_HOST,SMTP_PORT,RUST_ANYTHING_SMTP_SINK) that accepts everything, and records sender, recipients and the message.--effects smtp-rawruns the same server but records the raw, unparsed MIMEDATAinstead of decoded headers and parts; pass both (--effects smtp,smtp-raw) to get each case stored both ways.--effect-env VAR=KINDpoints one of the app's own settings at a sink:http-url,smtp-host,smtp-portorsmtp-url. Most apps read their webhook URL or mail host from a setting like this.--effect-response 'METHOD /path=STATUS [BODY|@FILE]'(repeatable) makes the HTTP sink answer matching requests with that status and body instead of200 {}: the first rule that matches wins,*is a wildcard in the method and path, and@FILEis read once and saved with the cases, so replay gets the same replies. Giving the flag again replaces the saved rules.--db-resetand--db-dumpare shell commands: reset puts the database in a known state before each case (each start, for servers), and dump prints its state after each case (each request, for servers); the dump's\r\nline endings are recorded as\n, so a recording made on Windows replays elsewhere. Cases then run one at a time. Both run in the folder the case runs in (the server's, with--fresh), soapp.dbis the one the app opened; a script they name by a relative path (scripts/reset-db.sh,reset.py,< schema.sql) is still the repository's. That holds for files with a script extension (.py,.sh,.bash,.js,.mjs,.cjs,.ts,.rb,.php,.pl,.ps1,.bat,.cmd,.sql); any other relative path, an extensionless script or the target of>included, is the case folder's.
What reached the sinks is stored as <case>.effects next to the case and compared like stdout:
the count and order of effects matter, values that differed between the original's two runs
(dates, ids) become wildcards, and effects the original sends in varying order are compared in any
order. The settings are saved with the cases, so replay starts the same sinks for every build.
Plan first: rust-anything analyze . --whole-app adds the app's shape (CLI, server or library)
and entry points, every external dependency (imported or declared) with its Rust crate and fit,
the port order as pieces (units that import each other move together), and numbered decisions
with a recommended answer: keep units, blocked units, dependencies with no or a partial crate.
Then prove the whole program from the outside. record and diff prove one unit; app record
and app replay prove the app, for any program, in any language (the app is a
black box):
rust-anything app record . -- python3 cli.py # the command that runs the original
rust-anything app replay . # the original must pass 100%
rust-anything app replay . --build "target/release/mytool"
app recordruns the original on the app's own documented examples ($ mytool ...lines in its Markdown and shell files, with the files they name), an--inputsJSONL file ({"name", "args", "stdin", "env", "files", "remove"};removedeletes paths from the--freshcopy before the case runs), and semantic traps derived from those cases (non-ASCII and emoji strings, negative division and modulo, overflow, large and tiny floats, map order, missing files). An input line that repeats an earlier case (the same arguments, stdin, environment and files) is not recorded again: the summary counts it and names the case it repeats. Each case runs twice; what differs between the two runs becomes a[..]wildcard (a line of another length, a...line), andapp recordfails when the original prints[..]or a...line itself in a field where its two runs also differ.--normalize timestamps|uuids|key-orderor--normalize name=regexadds normalizers, saved with the cases. A normalizer applies to the names of written files too: a file the app names by a time or an id (run-20261128T101500Z.log) is the same file in every run when a normalizer matches that part of its name. Thecargo testthatapp liftwrites compares written files by their exact names (trycmd), so it skips such a case: keepapp replayin CI for it.- Cases are trycmd files in
rust/app-cases/:<case>.toml(argv, env, exit code),.stdin,.stdout,.stderr,.in/(files in),.out/(files written),.removed(paths the case deleted, one per line) and.effects(what reached the--effectssinks). Read them; a Rust test can run them withtrycmdonce the port has a binary. rust/app-cases/rust-anything.cases.jsonis whatapp recordwrote for each case: a digest of the case's files, the fields whose[..]and...lines are the recording's own wildcards (everything else is compared as written, so an original that prints[..]or...is compared as that text), and the version of the interpreter and of the npm package the original ran as.app replaycompares standard output, standard error and written files byte for byte, the final newline,\rand blank lines included; a file or a removal the original did not produce is a difference too. A case whose files changed after recording, a case markedstatus = "skipped"and a recorded case whose files are gone each count as a case that did not pass (soapp liftrefuses): record again, or delete the case's entry from the file to accept an edit on purpose. A recording without this file (an older one) replays as before, reading[..]and...as wildcards, and says so on standard error.app recordfails, keeping what was recorded before, when a case timed out or got no answer, or when no case was recorded (RUST_ANYTHING_ALLOW_DROPPED=1accepts the smaller recording), and when the value of an environment variable named like a secret (TOKEN,PASSWORD,API_KEY...) is in anything it would write: record withenv -u NAME. It warns when every case (two or more) failed with the same exit code and the same error output, which is what a command that never reaches the app records (a module it cannot import, a wrong path), and quotes the error's last line.- A CLI that reads or writes files in the repository gets the same treatment as a server's state:
--fresh data(a file or folder, repeatable) is snapshotted intofiles/and copied into a new working directory before every case, so a case that writesdata/x.jsonstarts from the snapshot, not from the previous case's leftovers; the paths it removed are compared like the files it wrote. Name the folder without a trailing slash:--fresh data/puts the folder's contents at the root of the working directory (x.json, notdata/x.json), so a CLI that opensdata/x.jsondoes not find it.--no-freshclears the list and removes the snapshot, unless a case that stays reads it through anfs.basethat is inside it or above it (.and the case folder included). - Recording again replaces what the last recording wrote: a case it no longer writes (its input
was removed or renamed, or the original timed out on it) is deleted, in
http/too. The names are kept inrust-anything.jsonasrecorded, so a case you added by hand is left in place, andapp recordnames it, even when an input of its name timed out. A removed case's.in/folder stays while thefs.baseof a case that is kept is in it or goes through it. The names count only in the folder they were recorded in: after switching between a CLI and--http, nothing is removed. app replayruns any build against the cases, printspassed/total, writesrust/app-cases/replay-report.mdwith a diff per failing case, and exits non-zero on any mismatch. A build that appends to the file named byRUST_ANYTHING_FALLBACK_LOG(one line per fallback to the original), as the front door below does, also gets its fallback rate reported.app replay --case <name>reruns one case by the name the report gives it: the fast, repeatable loop for fixing a mismatch before running everything again.- Each failing field names where it first differs: the line and column of the text (where its
literal part stops matching), the JSON path inside a JSON body, or the status change
(
200→500). The report starts with a "Distinct differences" table: failing cases that differ the same way (same field, path and kind) are one row with a short stable id and a count. app replay --redactwrites the report and prints the failures as shapes only: where and how they differ, lengths and hashes, with no outputs, arguments or request paths, for a report you can share.- The report has no timings or temporary paths: two replays of the same build write the same
file. Commit it and run
app replaythengit diff --exit-code rust/app-cases/replay-report.mdin CI, and a half-ported app fails CI on any change in what passes, better or worse, until the report is updated with it.
Then move the entry point to Rust and hand it commands one unit at a time:
rust-anything app front-door . # rust/app: every command runs the original
rust-anything app wire . textkit --command upper # after textkit-rs passes gate
# write the glue in rust/app/src/units/textkit.rs, then:
rust-anything app wire . textkit # 100% again, lower fallback rate
app front-doorscaffoldsrust/app, a Rust binary named after the app: a clap parser for the commands and flags in the recorded cases, where every command runs the original with the same argv, stdin and environment and passes its output and exit code through. Each fallback is counted, so replaying the fresh front door gives 100% passed at 100% fallback (it builds and replays to show it). It never overwritesrust/app: the code is yours from then on.app wire <repo> <unit> --command <name>runsgateon the unit crate (--skip-gateif it just passed), adds it torust/appas a library, writessrc/units/<unit>.rsonce for you or your agent to fill in (parse the arguments, call<crate>::port, print what the original prints), routes the commands to it, then builds and replays.RUST_ANYTHING_UNIT_<NAME>=originalsends a wired unit back to the original until the lift.
Wire the app's own name as a command (--command mytool) for argv that names no command: no
arguments, unknown commands, usage errors.
app wire routes whole commands, never single call sites. A unit can hold only helpers (an
escaping function, a parser) that several commands call: wire those commands to it, and write each
command's Rust code in the unit's glue, which calls as many <crate>::port functions as it needs.
Rust code that answers a command in rust/app/src/main.rs before units::dispatch never reaches
a wired unit, so app wire refuses a main.rs that does not call units::dispatch, and app lift counts a helper as ported only through a wired command.
When replay passes with fallback rate 0 and every unit passes gate, make it a pure Rust app:
rust-anything app lift .
app liftrefuses until both hold, and says what blocks it: the cases still falling back, glue still a stub, units failing gate.- It does not take the front door's word that the original is gone. It scans
rust/appand the unit crates for a spawned process (Command::new,tokio::process,exec), an embedded interpreter or process runner (pyo3,rquickjs,deno_core,mlua,duct...), a path into the repository and the original's entry point; a process that runs the original's interpreter or program, or whose program is not a literal, blocks the lift, and any other program is listed. Then the final replay runs with the files the recorded command names (their top-level folder) moved out of the way and put back afterwards, so a front door that still shells out to the original fails its cases. The checklist prints how many cases passed and which files were hidden; when the recorded command names nothing in the repository, nothing can be hidden and it says so. - On a copy first, it removes the fallback path and the kill switches, turns each unit crate into
a plain library of
rust/app(nocdylib, bindings or generated wrappers), and addsrust/app/tests/app_cases.rs, which runsrust/app-caseswith trycmd oncargo test, so CI needs nothing but cargo. It skips the cases trycmd cannot check, whichapp replaystill does; recording again after the lift (app record) rewrites those skips for the new cases. - Then it runs the lift checklist: fmt, clippy
-D warningsand tests on every unit and onrust/app, every target named inrust/DECISIONS.mdbuilt or checked where it is installed, files read at run time and asset folders not embedded, and replay on the pure binary. Only when all of it passes are the changes written back. The original is never touched. - The checked crates are copied back through a journal,
rust/lift-commit.json, which keeps the checked copy until the lift is logged inrust/audit.jsonl. A lift that stops while copying back or at its final build (Ctrl-C, a CI timeout) is finished by the nextapp lift, and a repository whose top-level path is still named*.rust-anything-hidden(a final replay that was stopped) is refused until that path is put back.
Servers
The same commands prove HTTP servers. --http says the command starts a server; it takes its
port from PORT or {port} in the command (--port for one that always listens on the same
port):
rust-anything app record . --http -- node server.js
rust-anything app replay .
rust-anything app front-door . # axum: every route proxied
rust-anything app wire . api --route 'GET /users/{id}' --route '*'
rust-anything app lift .
- Requests come from
curllines in the app's docs (curl -X POST -d ... http://localhost:8080/x,--data-binary @filesent as raw bytes,-F/--formas amultipart/form-dataupload),--inputs({"name", "method", "path", "headers", "body" | "body_base64" | "body_file"}, abody_filerelative to the inputs file or the repository) and traps: path segments and query values swapped for the same traps as CLI arguments, bodies for text and JSON traps, and an unknown route. Each run starts the server fresh and sends the requests in name order, so state between requests is kept, and an input that repeats an earlier request (a read after a write) is a case of its own. - A server that keeps state in files gets a fresh copy for every start:
--fresh db.json(a file or folder, repeatable) is snapshotted intohttp/files/and copied into a new working directory each time the original, the front door or a build starts;--arg db.jsonis an argument every start gets after its command, so the Rust binary is started as the original is.--pace 50waits 50 ms after each response, for work a server does after answering (a file watcher reloading what it just wrote). A server gets 60 seconds to accept connections;--ready-timeout 180gives a slow start (a JVM, .NET) longer, and--ready-timeout 5makes a build that never listens fail fast. A framework that opens its port before its routes work gets--ready "GET /health": after the port opens, that request is sent until it answers 2xx, within the same wait, by record, replay and the front door. - Cases are
rust/app-cases/http/<case>.toml(the request, the status and the headers that matter) and<case>.body(the response body, with[..]where two runs differed).Date,Server,Connection, the framing headers,Server-TimingandX-Powered-Byare never compared.ETagandLast-Modifiedmust be there when the original sent them, with any value. Every other header the original sent is compared, and one the build sends that the original did not is a difference (optional_headerslists the ones only some runs of the original sent); a case you wrote by hand lists the headers it cares about and ignores the rest.curlexamples the recorder cannot read are named when recording (and in--jsonasskipped_examples). Mail in a charset the parser does not know is compared by its bytes; the common charsets are decoded, andReply-To,Sender,In-Reply-To,References,List-Unsubscribe,List-Id,X-PriorityandImportanceare part of the recorded message. - The front door is an axum server that starts the original on a port of its own and proxies
every route no unit answers.
wire --routetakes axum routes:METHOD /path/{param},/pathfor any method,*for everything else; the glue gets the route, its parameters and the request.liftremoves the proxy; HTTP cases then run in CI withapp replay.
Shadow live traffic
Recorded cases cover what the docs, --inputs and traps thought of. app shadow checks a build
against real requests too: a proxy sends each request to the original, relays its answer to the
client byte for byte, then sends the same request to the build and compares the two answers
(status, headers other than the per-response ones a recording leaves out, body) with the saved
normalizers:
rust-anything app shadow . --build rust/app/target/release/app --listen 8080
rust-anything app shadow . --build ./server-rs --upstream 127.0.0.1:3000 --keep
- Clients only ever get the original's answer, and the build is asked after the client has it, so a slow or broken build changes nothing for them. Requests are handled one at a time.
- The original runs for real: the saved command starts it (with its saved
--args), or--upstream HOST:PORTpoints at one already running. Each side effect happens once, there. - The build runs on a port of its own with the HTTP and mail sinks of
--effectsalways on (HTTP_PROXY,SMTP_HOST,SMTP_PORTand any saved--effect-env), and the--freshpaths copied from the repository into a working directory of its own when it starts. Its effects are dropped, not compared.--db-resetand--db-dumpare not run, and a database the build reaches over the network is not isolated: point the build at a copy. - A header whose value differed between the original's own runs when it was recorded is checked for presence only.
- Each mismatch is a line in
rust/app-cases/shadow/mismatches.jsonlwith the method, a hash of the path and, for each field that differed (body,status,header content-type), its shape asapp replay --redactwrites it: where it first differs, kind, line and column, lengths, never the values. The terminal shows the same, and at the end the distinct differences with how many requests each covers.--keepappends the request itself torust/app-cases/shadow/inputs.jsonl, whichapp record --inputsturns into a case, so a mismatch seen live is replayed with the full diff from then on. - It runs until Ctrl-C;
--requests 100stops after 100 requests and exits 1 if any mismatched. CLIs are not covered yet, and there is no MCP tool, since it runs until stopped.
Libraries
A library has no process to replay: its public API is the front door, and each unit's recorded cases are the proof.
rust-anything app front-door . # rust/app: a Rust crate with the public API
# each unit through the loop: bridge, record, port.rs, build, diff, gate; then:
rust-anything app wire . textkit-rs # re-exported from rust/app; the original imports its shadow
rust-anything app replay . # every wired unit's cases; fallback = exports still in the original
rust-anything app lift .
app front-doorfinds the public API (every unit's exports) when the repository has nomainand no server (--libraryotherwise), and scaffoldsrust/appas a library crate. Each wired unit becomes a module of it:pub use textkit_rs::port as textkit;.app wiretakes a crate made bybridge, runsgate, and writes the unit's shadow drop-in: the original package imports it in place of the unit, so its callers keep the original API and reach the Rust.RUST_ANYTHING_UNIT_<NAME>=originalsends the unit back (C: build without the shadow's flags).app replayruns every wired unit's recorded cases through its bindings. The fallback rate is the share of public exports Rust does not answer yet: unwired units, and exportsbridgekeeps in the original language.app liftneeds fallback 0 and every unit throughgate; it strips the bindings, wrappers and shadows from the units and leavesrust/appas one pure Rust library. It does not touch anyport.rs, so the cases that matched through the bindings still describe it; the checklist warns about files of the original that still import the shadows.
Saved settings (rust/app-cases/rust-anything.json)
app record saves its configuration in rust/app-cases/rust-anything.json, and app replay and
app lift read it on every run. Editing this file by hand is supported (for example to remove a
sticky setting or clear unordered). app front-door reads it once, when it scaffolds rust/app,
and copies run into rust/app/src/original.rs: after changing run, edit that file too and
rebuild, since app front-door never overwrites an existing rust/app.
| Field | Flag | On re-record |
|---|---|---|
name |
--name |
Replaces if passed; keeps saved otherwise |
run |
-- <cmd> |
Replaces if passed; keeps saved otherwise |
timeout_secs |
--timeout |
Replaces if passed; keeps saved (default 30) otherwise |
normalize |
--normalize NAME |
Merges (appends new built-in normalizer names) |
normalizers |
--normalize NAME=REGEX |
Merges (inserts or updates by NAME) |
http |
--http, --port, --arg, --pace, --ready-timeout, --ready |
Sticky once set; --no-http drops it and records as a CLI again |
http.port |
--port |
Replaces if passed; --port 0 removes it; keeps saved otherwise |
http.args |
--arg |
Replaces if passed; --no-args clears it; keeps saved otherwise |
http.pace_ms |
--pace |
Replaces if passed; --pace 0 clears it |
http.ready_secs |
--ready-timeout |
Replaces if passed; --ready-timeout 0 restores the default 60 |
http.ready_request |
--ready |
Replaces if passed; keeps saved (cannot be cleared via CLI) |
http.fresh / fresh |
--fresh |
Replaces if passed; --no-fresh clears it and removes the saved snapshot; keeps saved otherwise |
effects |
--effects, --effect-env, --effect-response, --db-reset, --db-dump |
Merges with saved sink and database settings; --effect-response replaces the saved rules |
float_tolerance |
--float-tolerance |
Replaces if passed; above 1e-6 needs --allow-large-tolerance; --float-tolerance 0 clears it |
float_files |
--float-file |
Replaces if passed; keeps saved otherwise |
unordered |
(written by app record) |
Recomputed from order noise; tells replay to compare those lines in any order |
across_lines |
(written by app record) |
Recomputed when a saved normalizer can match a line break: the cases and outputs where one did, which the lifted cargo test skips. Absent in an older recording, which skips every case with a [..] |
recorded |
(written by app record) |
Tracks generated case names so stale cases are cleaned up on the next app record |
Six of the seven are MCP tools: app_record, app_replay, app_front_door, app_wire, app_lift
and app_drift. app shadow is CLI only: it holds a proxy open in front of two servers, so a call has
nothing to return until the session ends.
Keep up with the original
The original keeps changing after the port starts, and after the lift. app drift checks both
sides at once:
rust-anything app drift . # the build is rust/app, built with cargo
rust-anything app drift . --build ./target/release/tcli # or any build
- It replays the original against
rust/app-cases: a case the original no longer matches changed upstream. - It lists the examples in the original's docs (shell lines for a CLI, curl lines for a server) that no case records yet.
- It replays the build: a case it no longer matches while the original still does is a port regression; one the original changed while the build still passes is marked "original changed, port still old".
It writes rust/app-cases/drift-report.md (with a diff per case, and the same stable paths as
replay-report.md, so CI can commit it), leaves replay-report.md as it was, and exits 1 on any
change. After a change upstream: app record again (it adds the new examples), then port what
changed until app replay passes. Libraries are not covered: for units, map --check exits 1
while any recording is stale (see How it works).
To check every week and on demand, in GitHub Actions:
name: drift
on:
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:
push:
branches: [main]
jobs:
drift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- uses: dtolnay/rust-toolchain@stable
- run: cargo install rust-anything --locked
- run: rust-anything app drift .
- if: failure()
uses: actions/upload-artifact@v4
with:
name: drift-report
path: rust/app-cases/drift-report.md
Set up the original's own runtime in place of setup-node (actions/setup-python,
actions/setup-go and so on).