This repo translates stb/stb_image.h (single-header C, ~8000 LOC) into a single
monolithic port/stb_image.jai that:
- Mirrors the section order of
stb_image.has closely as possible. - Exports the same C ABI (every symbol in
E:\ProgrammingProjects\jai6\modules\stb_image\bindings.jai) so the upstreamstb/tests/image_test.cdriver can be linked against either the C or Jai implementation interchangeably. - Produces byte-identical outputs to the C build on the pngsuite corpus
when both are compiled with
-DSTBI_NO_SIMD -DPNGSUITE_PRIMARY.
The port itself is produced by orchestrating sub-agents via
agent_runner running deepseek v4 flash agents via OpenCode
Authoritative rules live in
PORTING.md — every porting and fix agent reads it first.
[ERROR_TYPES.md] is a leftover file from the agent pipeline stage 30, left there as example of what errors the agent had to fix.
This public version of the repo contains the final jai file + the orchestrator files. The harness has a lot of extra files and scripts to build the project and run test suites, which have been left outside. For more information on those, contact the author.
The stb_image.jai file is hardened and confirmed fully working. This whole pipeline was run for ~4 total dollars on deepseek-v4-flash tokens via official API
cd E:\ProgrammingProjects\stb_image_port
# 1. Probe the toolchain (jai.exe, cl.exe, #thread_local, static-lib symbol
# naming) and audit port\drafts.manifest.json against stb_image.h. Writes
# port\probes.json. Idempotent.
agent-runner run .claude\workflows\00-scaffold.workflow.js
# 2. Per-shard port of stb_image.h into port\drafts\NN_*.jai. Each shard
# runs Implement -> 2-vote adversarial Verify -> surgical Fix. Skips
# shards whose draft already exists unless force=true.
agent-runner run .claude\workflows\10-port-sections.workflow.js
# 3. Concatenate port\drafts\*.jai (manifest id order, sandwiched by .header
# and .footer) into port\stb_image.jai + port\shard_index.json. Audits
# every bindings.jai symbol; if missing/duplicate, a fixer agent edits
# the monolith and re-audits.
agent-runner run .claude\workflows\20-merge.workflow.js
# 4. Build the C reference exe, then loop a combined build+fix agent until
# the Jai build succeeds. Each round runs the compiler, fixes errors
# directly in port\stb_image.jai, and exits — the runner re-launches a
# new round. port\drafts\ is off-limits here.
agent-runner run .claude\workflows\30-build.workflow.js
# 5. (Optional) Per-shard function-level checkup: reviewer agents (parallel,
# one per shard) compare the monolith against the C master function-by-
# function. Shards with mismatches are resynced sequentially; each
# resync agent must leave the build green before its round ends.
agent-runner run .claude\workflows\31-checkup.workflow.js
# 6. Three-phase test pipeline: (a) full pngsuite walk via run_diff.bat,
# (b) probe each pngsuite/primary/*.png into probe.json with
# passing[]/failing[], (c) SERIAL per-failing-test fix agent; the JS
# runner rebuilds and reruns each test after its agent finishes.
agent-runner run .claude\workflows\40-test-diff.workflow.js
# 7. Iterate to byte-identical: each round picks the frontier shards from
# divergences.json / build_errors.json, fixes them, 2-vote verifies,
# rebuilds, retests. Loops up to max_rounds.
agent-runner run .claude\workflows\50-fix-divergences.workflow.js --args-json "{\"max_rounds\":8}"
# 8. (Optional) Crash-hardening pentest: N agents (default 4) run in
# parallel, each in its own git worktree, hunting malformed PNGs that
# crash the Jai loader. Worktrees are preserved post-run for inspection.
agent-runner run .claude\workflows\60-harden-suite.workflow.js --args-json "{\"agents\":4}"