code wiki / _hdl_build / nx_librarian_pipeline.nx
nx_librarian_pipeline.nx source
↩ module page · 74 lines · 3599 B
1// nx_librarian_pipeline.nx -- the LIBRARIAN's knowledge-refinement pipeline (operator: deep
2// research must build the team via the WHOLE chain unstructured -> structured -> meaningful ->
3// actionable -> reproducible, so we save the investment instead of throwing it away). Each
4// ingested research artifact is graded by how far it has been REFINED along the 5 stages; the
5// team can then gate: only ACTIONABLE (>=4) knowledge drives builds, only REPRODUCIBLE (5)
6// knowledge is trusted as settled. The Librarian validates ingested artifacts are well-formed
7// and parseable so the knowledge base stays reusable. RACI: the Librarian owns knowledge
8// integrity (it validates + grades + catalogs); it does not do the research or the builds.
9// license_tier: ORIGINAL
10
11import "nx_syscalls.nx"
12const KS_MAGIC_70000: i64 = 70000
13const KS_MAGIC_69000: i64 = 69000
14
15const KS_UNSTRUCTURED: i64 = 1 // raw fetched sources (the web, unverified)
16const KS_STRUCTURED: i64 = 2 // claims extracted + adversarially verified + cited
17const KS_MEANINGFUL: i64 = 3 // synthesis + connection to what we already have
18const KS_ACTIONABLE: i64 = 4 // concrete build tasks derived from the findings
19const KS_REPRODUCIBLE: i64 = 5 // each task becomes a verifiable gate; numbers re-checkable
20
21func lib_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
22
23// read up to cap bytes of a file into buf (one read; artifacts are small). returns bytes read.
24func lib_read_once(path: *u8, buf: *u8, cap: i64) -> i64 {
25 let fd: i64 = sys_openat_rd(path)
26 if fd < 0 { return 0 }
27 let n: i64 = sys_read(fd, buf, cap)
28 sys_close(fd)
29 if n < 0 { return 0 }
30 return n
31}
32
33// does buf[0..n) contain needle? plain substring scan.
34func lib_contains(buf: *u8, n: i64, needle: *u8) -> i64 {
35 let m: i64 = lib_strlen(needle)
36 if m == 0 { return 1 }
37 var i: i64 = 0
38 while i + m <= n {
39 var j: i64 = 0; var ok: i64 = 1
40 while j < m { if buf[i + j] != needle[j] { ok = 0; j = m } else { j = j + 1 } }
41 if ok == 1 { return 1 }
42 i = i + 1
43 }
44 return 0
45}
46
47// MATURITY = how many of the 5 refinement stages an artifact has reached (presence of its stage
48// marker). 5 = fully refined research that built the team. <5 = still raw; flag what is missing.
49func lib_maturity(path: *u8) -> i64 {
50 let buf: *u8 = sys_mmap(KS_MAGIC_70000)
51 let n: i64 = lib_read_once(path, buf, KS_MAGIC_69000)
52 if n <= 0 { return 0 }
53 var st: i64 = 0
54 if lib_contains(buf, n, "Stage 1" as *u8) == 1 { st = st + 1 }
55 if lib_contains(buf, n, "Stage 2" as *u8) == 1 { st = st + 1 }
56 if lib_contains(buf, n, "Stage 3" as *u8) == 1 { st = st + 1 }
57 if lib_contains(buf, n, "Stage 4" as *u8) == 1 { st = st + 1 }
58 if lib_contains(buf, n, "Stage 5" as *u8) == 1 { st = st + 1 }
59 return st
60}
61
62// gates the team uses on the knowledge base
63func lib_is_actionable(path: *u8) -> i64 { if lib_maturity(path) >= KS_ACTIONABLE { return 1 } return 0 }
64func lib_is_reproducible(path: *u8) -> i64 { if lib_maturity(path) >= KS_REPRODUCIBLE { return 1 } return 0 }
65
66// a well-formed research artifact also carries its provenance (citations) -- the Librarian checks
67// it is actually grounded (has a Sources/citation stage), not an unsourced opinion.
68func lib_is_cited(path: *u8) -> i64 {
69 let buf: *u8 = sys_mmap(KS_MAGIC_70000)
70 let n: i64 = lib_read_once(path, buf, KS_MAGIC_69000)
71 if lib_contains(buf, n, "arXiv" as *u8) == 1 { return 1 }
72 if lib_contains(buf, n, "Sources" as *u8) == 1 { return 1 }
73 return 0
74}