code wiki / _hdl_build / nx_researcher_spec_test.nx

nx_researcher_spec_test.nx source

↩ module page · 53 lines · 3922 B

1// nx_researcher_spec_test.nx -- the Researcher takes the NEED "match a query beyond exact terms" 2// (semantic retrieval) and emits a buildable SPEC decomposed to Layer-8. It produces TWO candidate 3// specs and chooses honestly: 4// SPEC A co-occurrence vectors + integer cosine -> primitives {COUNT, IMUL, IADD, ISQRT}, all 5// available at L8 -> COMPLETE + ACTIONABLE -> hand to the Builder, build bits-up. 6// SPEC B learned embeddings -> needs EMBED_TRAIN, NOT available -> flag as an LLM-gap, do not fake. 7// So the team finds its own next build AND knows where it must stop and flag Claude. Exit 0 on 6/6. 8// license_tier: ORIGINAL 9 10import "nx_researcher_spec.nx" 11import "nx_syscalls.nx" 12 13func rt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 14func rt_num(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(1,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 } 15 16func main() -> i64 { 17 rt_puts("=== RESEARCHER: turn the need (semantic match) into a Layer-8 build spec ===\n" as *u8) 18 19 // SPEC A: co-occurrence semantic retrieval, built from L8 integer ops 20 let primsA: *i64 = sys_mmap(8 * 8) as *i64 21 primsA[0]=RS_PRIM_COUNT; primsA[1]=RS_PRIM_IMUL; primsA[2]=RS_PRIM_IADD; primsA[3]=RS_PRIM_ISQRT 22 let nA: i64 = 4 23 // named=1, layer=L8, inputs={corpus,query}=2, outputs={ranked doc}=1, prims=4, gate=present(1) 24 let completeA: i64 = rs_spec_complete(1, RS_L8, 2, 1, nA, 1) 25 let actionableA: i64 = rs_spec_actionable(completeA, primsA, nA) 26 let missingA: i64 = rs_first_missing(primsA, nA) 27 rt_puts(" SPEC A (co-occurrence): layer=L" as *u8); rt_num(RS_L8); rt_puts(" complete=" as *u8); rt_num(completeA); rt_puts(" actionable=" as *u8); rt_num(actionableA); rt_puts(" missing-prim=" as *u8); rt_num(missingA); rt_puts(" (-1=none, all L8 ops available)\n" as *u8) 28 29 // SPEC B: learned embeddings -- needs a trainer the team does not have 30 let primsB: *i64 = sys_mmap(8 * 8) as *i64 31 primsB[0]=RS_PRIM_COUNT; primsB[1]=RS_PRIM_EMBED_TRAIN 32 let nB: i64 = 2 33 let completeB: i64 = rs_spec_complete(1, RS_L8, 2, 1, nB, 1) 34 let actionableB: i64 = rs_spec_actionable(completeB, primsB, nB) 35 let missingB: i64 = rs_first_missing(primsB, nB) 36 let llmgapB: i64 = rs_missing_is_llm_gap(missingB) 37 rt_puts(" SPEC B (learned embed): complete=" as *u8); rt_num(completeB); rt_puts(" actionable=" as *u8); rt_num(actionableB); rt_puts(" missing-prim=" as *u8); rt_num(missingB); rt_puts(" is-LLM-gap=" as *u8); rt_num(llmgapB); rt_puts(" (flag, don't fake)\n" as *u8) 38 39 rt_puts(" DECISION: build SPEC A bits-up (Builder), flag SPEC B's trainer as an LLM-gap.\n" as *u8) 40 41 let r: *i64 = sys_mmap(8 * 8) as *i64 42 r[0] = 0; if completeA == 1 { r[0] = 1 } // A is a full spec 43 r[1] = 0; if actionableA == 1 { r[1] = 1 } // A buildable now (all prims at L8) 44 r[2] = 0; if missingA == 0 - 1 { r[2] = 1 } // nothing missing for A 45 r[3] = 0; if actionableB == 0 { r[3] = 1 } // B not buildable yet 46 r[4] = 0; if missingB == RS_PRIM_EMBED_TRAIN { r[4] = 1 }// B's blocker = the trainer 47 r[5] = 0; if llmgapB == 1 { r[5] = 1 } // and that blocker is honestly an LLM-gap 48 var pass: i64 = 0; var i: i64 = 0 49 while i < 6 { pass = pass + r[i]; i = i + 1 } 50 rt_puts("----\n passed " as *u8); rt_num(pass); rt_puts("/6\n" as *u8) 51 if pass == 6 { rt_puts(" SPEC EMITTED: the Researcher decomposed the need to L8, chose the buildable co-occurrence path, and flagged the learned-embedding rung as an LLM-gap. Builder can start.\n" as *u8); sys_exit(0); return 0 } 52 rt_puts(" FAIL\n" as *u8); sys_exit(1); return 1 53}