code wiki / _hdl_build / nx_browser_arc_pipeline.nx
nx_browser_arc_pipeline.nx source
↩ module page · 92 lines · 4250 B
1// nx_browser_arc_pipeline.nx -- the WARDEN routes the BROWSER arc's open rungs (B1-B5,
2// pm_plan arc=BROWSER) through the team's CLEAN RACI build pipeline. Evidence-driven:
3// a rung's stage is DERIVED from the Engineer's durable gate log (knowledge/status/
4// browser_gate.log), never asserted -- a rung is ADMITTED only when its named gate row
5// PASSES in the latest run; a FAILING row routes to the Doctor; an ABSENT row routes
6// through bp_run, which flags NEEDS_TUTOR honestly when the core is novel (not yet in
7// the Builder's pattern library) or SCAFFOLD-READY when the team can author it alone.
8// The arc's autonomy permil (bp_autonomy_permil) measures how much of the browser the
9// team can build hands-off -- driven up by adding pattern emitters, never by hiding
10// the Claude dependency. Composes nx_build_pipeline (Warden) + nx_build_raci (RACI).
11// LAWS: struct-free, integer-only, no shell. license_tier: ORIGINAL
12import "nx_build_pipeline.nx"
13import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
14import "nx_syscalls.nx"
15
16// find the LAST occurrence of NUL-terminated pat in buf[0..len); -1 if absent.
17// last-wins because the gate log is append-only: the latest run is the live verdict.
18func ba_find_last(buf: *u8, len: i64, pat: *u8) -> i64 {
19 var plen: i64 = 0
20 while pat[plen] != (0 as u8) { plen = plen + 1 }
21 if plen == 0 { return 0 - 1 }
22 var best: i64 = 0 - 1
23 var i: i64 = 0
24 while i + plen <= len {
25 var j: i64 = 0
26 var ok: i64 = 1
27 while j < plen {
28 if buf[i + j] != pat[j] { ok = 0; j = plen }
29 if ok == 1 { j = j + 1 }
30 }
31 if ok == 1 { best = i }
32 i = i + 1
33 }
34 return best
35}
36
37// status of one gate row in the log content: 1=PASS 0=FAIL -1=ABSENT.
38// rowpat must be the unambiguous "row=<module> " form (trailing space).
39func ba_row_status(buf: *u8, len: i64, rowpat: *u8) -> i64 {
40 let at: i64 = ba_find_last(buf, len, rowpat)
41 if at < 0 { return 0 - 1 }
42 var e: i64 = at
43 var scanning: i64 = 1
44 while scanning == 1 {
45 if e >= len { scanning = 0 }
46 if scanning == 1 { if buf[e] == (10 as u8) { scanning = 0 } }
47 if scanning == 1 { e = e + 1 }
48 }
49 let sub: *u8 = ((buf as i64) + at) as *u8
50 if ba_find_last(sub, e - at, "verdict=PASS\x00" as *u8) >= 0 { return 1 }
51 return 0
52}
53
54// route one rung through the RACI: stage from (pattern coverage, gate-row evidence).
55// ABSENT evidence -> fresh assignment: novel core = NEEDS_TUTOR (honest, measured),
56// pattern-covered = SCAFFOLDED (team authors hands-off). PRESENT evidence -> resolve
57// on the Engineer's verdict: PASS = ADMITTED, FAIL = HEALED (Doctor's queue).
58func ba_rung_stage(pattern_id: i64, row_status: i64) -> i64 {
59 let d0: i64 = br_decide(BR_BUILDER, BR_ENGINEER, BR_DOCTOR, 1, 1, 0, 2)
60 if d0 == BR_FLOW_RACI_BAD { return BP_RACI_BAD }
61 if row_status < 0 {
62 if bp_core_autonomous(pattern_id) == 0 { return BP_NEEDS_TUTOR }
63 return BP_SCAFFOLDED
64 }
65 let d: i64 = br_decide(BR_BUILDER, BR_ENGINEER, BR_DOCTOR, 1, row_status, 0, 2)
66 if d == BR_FLOW_ADMIT { return BP_ADMITTED }
67 if d == BR_FLOW_HEAL { return BP_HEALED }
68 return BP_REJECTED
69}
70
71// stage -> printable name (for the durable arc log)
72func ba_stage_name(stage: i64) -> *u8 {
73 if stage == BP_ADMITTED { return "ADMITTED\x00" as *u8 }
74 if stage == BP_NEEDS_TUTOR { return "NEEDS_TUTOR\x00" as *u8 }
75 if stage == BP_SCAFFOLDED { return "SCAFFOLD-READY\x00" as *u8 }
76 if stage == BP_HEALED { return "HEAL-QUEUED\x00" as *u8 }
77 if stage == BP_REJECTED { return "REJECTED\x00" as *u8 }
78 return "RACI-BAD\x00" as *u8
79}
80
81func ba_fputs(fd: i64, s: *u8) -> i64 {
82 var n: i64 = 0
83 while s[n] != (0 as u8) { n = n + 1 }
84 sys_write(fd, s, n)
85 return 0
86}
87
88// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
89// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
90// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
91// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
92func ba_fputn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }