code wiki / _hdl_build / nx_bugforge.nx
nx_bugforge.nx
buildroot/runtime/_hdl_build/nx_bugforge.nx
about
nx_bugforge.nx -- SWE-SCALE INSTANCE MINER (bugforge-swe-scale, 2026-07-24). The oracle today is
14 hand-seeded toy candidates; a frontier harness needs HUNDREDS of real-code instances plus a
learned fix corpus. This organ mines them MECHANICALLY from the real runtime tree:
1 SCAN real .nx files for LEAF-PURE functions (all-i64 params, i64 return, no calls, no loops,
no division, no pointers -- the v1 safety envelope, every exclusion COUNTED not silent)
2 MUTATE one operator swap per instance (data-driven op table: +/-, -/+, </>, >/<, */+)
3 VERIFY a generated PROBE compiles orig (renamed) + mutant side by side and sweeps the domain;
the ORIGINAL IS THE ORACLE -- divergent cases are real failing tests, agreement cases
are pass-to-pass regression teeth (the SWE-bench F2P+P2P contract, mechanically minted).
No divergence proof => instance DISCARDED (absence of proof is not equivalence).
4 EMIT a self-contained candidate (mutant under its REAL name + FNRES/FNCASE grader main) that
is byte-compatible with nx_autofix_auto's episode loop, a manifest row (name|path), and
a (buggy TAB fixed) corpus row for retrieval few-shots (single-line fns).
verbs: mine [maxn] [dir] (defaults 16, runtime) | selftest
bf_manifest.txt / bf_fixcorpus.txt are DERIVED artifacts regenerated per run (documented REPLACE).
license_tier: ORIGINAL No hw writes (Rule 26).
dependencies 3 imports · 0 importers
imports: nx_tool_run.nxnx_itoa_lib.nxnx_syscalls.nx
imported by: nobody (leaf or entry point)
structs
| none |
consts
| 21 | const BF_FCAP: i64 = 262144 // per-source-file read cap (bigger files skipped + counted) |
| 22 | const BF_DCAP: i64 = 65536 // getdents buffer |
| 23 | const BF_TCAP: i64 = 4096 // one extracted function text |
| 24 | const BF_SRCCAP: i64 = 32768 // generated probe/candidate source |
| 25 | const BF_OCAP: i64 = 524288 // build+run capture |
| 26 | const BF_LISTCAP: i64 = 131072 // manifest/corpus accumulators |
| 27 | const BF_PATHCAP: i64 = 256 |
| 28 | const BF_DOM: i64 = 6 // sweep half-width arity 1-2 (13 values/axis) |
| 29 | const BF_DOM3: i64 = 4 // sweep half-width arity 3 (9^3=729 evals) |
| 30 | const BF_MAXCASE: i64 = 6 // banked divergent (fail-to-pass) cases |
| 31 | const BF_MAXPASS: i64 = 6 // banked agreement (pass-to-pass) cases |
| 32 | const BF_PERFN: i64 = 2 // max instances per function (corpus diversity) |
| 33 | const BF_MINB: i64 = 30 // min fn bytes (below = trivial) |
| 34 | const BF_MAXB: i64 = 1200 // max fn bytes (fits the episode splice path) |
| 35 | const BF_NOPS: i64 = 5 |
| 36 | const BF_ZERO: i64 = 48 |
| 37 | const BF_MODE: i64 = 420 // 0644 file mode (decimal per the magic ratchet) |
functions
| 39 | func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } calls 1: sys_write |
| 44 | func wn(v: i64) -> i64 { nxi_out(v); return 0 } calls 1: nxi_out |
| 45 | func slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 46 | func sfind(hay: *u8, hn: i64, needle: *u8, from: i64) -> i64 |
| 59 | func bcat(b: *u8, off: i64, s: *u8) -> i64 |
| 65 | func bcatr(b: *u8, off: i64, s: *u8, n: i64) -> i64 |
| 71 | func bcatn(b: *u8, off: i64, v: i64) -> i64 calls 1: sys_mmap |
| 84 | func bq(b: *u8, off: i64) -> i64 { b[off] = 34 as u8; return off + 1 } called by 1: bqs |
| 86 | func bqs(b: *u8, off: i64, s: *u8) -> i64 |
| 92 | func scontains(hay: *u8, hn: i64, needle: *u8) -> i64 { if sfind(hay, hn, needle, 0) >= 0 { return 1 } return 0 } |
| 95 | func bf_read(path: *u8, buf: *u8, cap: i64) -> i64 |
| 110 | func bf_write(path: *u8, buf: *u8, n: i64) -> i64 |
| 119 | func bf_run(name: *u8, out: *u8, cap: i64) -> i64 |
| 131 | func bf_intafter(buf: *u8, n: i64, token: *u8, from: i64, box: *i64) -> i64 |
| 156 | func bf_fnend(fbuf: *u8, n: i64, at: i64) -> i64 |
| 177 | func bf_fnsig(t: *u8, tn: i64, nb: *u8) -> i64 calls 1: sfind |
| 208 | func bf_eligible(t: *u8, tn: i64) -> i64 |
| 252 | func bf_opget(i: i64, box: *i64) -> i64 |
| 261 | func bf_mutate(t: *u8, tn: i64, find: *u8, repl: *u8, out: *u8) -> i64 |
| 275 | func bf_rename(dst: *u8, o0: i64, t: *u8, tn: i64, newname: *u8) -> i64 |
| 284 | func bf_gen_head(g: *u8) -> i64 |
| 299 | func bf_gen_cw(g: *u8, o0: i64, lit: *u8) -> i64 |
| 307 | func bf_gen_nl(g: *u8, o0: i64) -> i64 |
| 320 | func bf_probe_src(g: *u8, t: *u8, tn: i64, mut: *u8, mn: i64, arity: i64) -> i64 |
| 395 | func bf_cand_src(g: *u8, mut: *u8, mn: i64, fname: *u8, arity: i64, cargs: *i64, cwant: *i64, ncase: i64, pargs: *i64, pval: *i64, npass: i64, srcpath: *u8, oplab: *u8) -> i64 |
| 486 | func bf_collect(outb: *u8, on: i64, tag: *u8, arity: i64, args: *i64, vals: *i64, maxn: i64) -> i64 |
| 547 | func bf_try(t: *u8, tn: i64, fname: *u8, arity: i64, opfind: *u8, oprepl: *u8, oplab: *u8, srcpath: *u8, verbose: i64) -> i64 |
| 635 | func bf_name_ok(nm: *u8) -> i64 |
| 651 | func bf_mine(maxn: i64, dir: *u8, app: i64) -> i64 |
| 829 | func bf_selftest() -> i64 |
| 888 | func main(argc: i64, argv: *i64) -> i64 |