code wiki / (root) / nx_dr_chain.nx

nx_dr_chain.nx source

↩ module page · 67 lines · 3068 B

1// nx_dr_chain.nx -- the CAPSTONE: one call runs the whole deep-research loop (DR-CHAIN). 2// Composes the live DR organs end-to-end instead of leaving them as eight separate calls: 3// JUDGE nx_dr_run tokenize each source doc, token-containment vs a SHARED 4// groundtruth-insight set (the DRBench task shape) -> coverage 5// CONDUCT nx_dr_conductor verify-yield -> Elo Tournament-of-Ideas -> opportunity-cost 6// budget dispatch -> which sources earn deep compute 7// SCORE nx_dr_drbench insight-recall over what was actually selected 8// ★NOVEL MEASUREMENT this makes possible: recall_all (if you could read every source) vs 9// recall_selected (what the budget-constrained agent actually got) -- the MEASURED COST of 10// the opportunity-cost constraint, which no single-agent tool reports. 11// Packed self-describing inputs keep every func <=6 params (NAS nx_cc >6-arg skew, seq239). 12// Deterministic/integer. No hardware writes (Rule 26). 13// 14// module: nishi-core.research.dr_chain 15// depends: nx_dr_run.nx, nx_dr_verify.nx, nx_syscalls.nx 16// genealogy_id: coscientist_2026_pipeline + drbench_2026_task_shape 17import "nx_dr_run.nx" 18import "nx_dr_verify.nx" 19import "nx_syscalls.nx" 20 21// Judge every source document against the shared insight set. 22// ins_pack: [0]=ni, [1..ni]=token offsets, [1+ni..2ni]=token lens, tokens from [1+2*ni] 23// doc_pack: [0]=ndocs, [1..ndocs]=token lens, tokens from [1+ndocs] (docs concatenated) 24// out_cov[d*ni + i] = 1 iff doc d covers insight i; out_sup[d] = covered count for doc d. 25func chain_judge_all(ins_pack: *i64, doc_pack: *i64, threshold: i64, out_sup: *i64, out_cov: *i64) -> i64 { 26 let ni: i64 = ins_pack[0] 27 let ndocs: i64 = doc_pack[0] 28 let ins_tok: *i64 = ((ins_pack as i64) + (1 + 2 * ni) * 8) as *i64 29 let doc_tok: *i64 = ((doc_pack as i64) + (1 + ndocs) * 8) as *i64 30 var doff: i64 = 0 31 var d: i64 = 0 32 while d < ndocs { 33 let dlen: i64 = doc_pack[1 + d] 34 let doc: *i64 = ((doc_tok as i64) + doff * 8) as *i64 35 var sup: i64 = 0 36 var i: i64 = 0 37 while i < ni { 38 let ins: *i64 = ((ins_tok as i64) + ins_pack[1 + i] * 8) as *i64 39 var c: i64 = 0 40 if dv_entail(ins, ins_pack[1 + ni + i], doc, dlen) >= threshold { c = 1 } 41 out_cov[d * ni + i] = c 42 sup = sup + c 43 i = i + 1 44 } 45 out_sup[d] = sup 46 doff = doff + dlen 47 d = d + 1 48 } 49 return 0 50} 51 52// An insight is covered by a document SUBSET iff ANY doc with sel[d]==1 covers it. 53// (sel all-ones -> recall_all; the conductor's selection -> recall_selected; all-zeros -> 0.) 54func chain_sel_cov(cov: *i64, sel: *i64, ndocs: i64, ni: i64, out_selcov: *i64) -> i64 { 55 var i: i64 = 0 56 while i < ni { 57 var any: i64 = 0 58 var d: i64 = 0 59 while d < ndocs { 60 if sel[d] == 1 { if cov[d * ni + i] == 1 { any = 1 } } 61 d = d + 1 62 } 63 out_selcov[i] = any 64 i = i + 1 65 } 66 return 0 67}