nx_cite_redline_gate.nx source
↩ module page · 129 lines · 5975 B
1// nx_cite_redline_gate.nx -- F993 PRODUCT SURFACE: document-level citation redline.
2// A chatbot verifies one quote; a drafting tool must verify EVERY citation in a filed paragraph and
3// strike the ones that cannot be grounded. This proves the whole-document scanner catches a real mix
4// -- a good cite, a fabricated cite, a made-up source, and the malformed-citation dodge -- and that the
5// document-level green light (cite_doc_clean) refuses a paragraph carrying even one bad citation.
6// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
7
8import "nx_cite_lib.nx"
9
10func rl_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
11func rl_putn(v: i64) -> i64 {
12 let t: *u8 = sys_mmap(32)
13 var o: i64 = 0
14 var m: i64 = v
15 if m < 0 { t[o] = 45 as u8; o = o + 1; m = 0 - m }
16 let d: *u8 = sys_mmap(32)
17 var k: i64 = 0
18 if m == 0 { d[0] = 48 as u8; k = 1 }
19 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
20 var i: i64 = 0
21 while i < k { t[o] = d[k - 1 - i]; o = o + 1; i = i + 1 }
22 sys_write(1, t, o)
23 return 0
24}
25func rl_ck(cnt: *i64, name: *u8, got: i64, want: i64) -> i64 {
26 if got == want {
27 cnt[0] = cnt[0] + 1
28 rl_puts(" PASS " as *u8); rl_puts(name); rl_puts(" = " as *u8); rl_putn(got); rl_puts("\n" as *u8)
29 return 1
30 }
31 cnt[1] = cnt[1] + 1
32 rl_puts(" FAIL " as *u8); rl_puts(name); rl_puts(" got " as *u8); rl_putn(got)
33 rl_puts(" want " as *u8); rl_putn(want); rl_puts("\n" as *u8)
34 return 0
35}
36func rl_id(tag: *u8, nonce: i64, out: *u8) -> i64 {
37 var o: i64 = mt_catcopy(out, 0, tag)
38 o = mt_catn(out, o, nonce)
39 out[o] = 0 as u8
40 return o
41}
42
43func main(argc: i64, argv: *i64) -> i64 {
44 let pfx: *u8 = "knowledge/store/redlinegate-" as *u8
45 let nonce: i64 = sys_now_us()
46 let cnt: *i64 = sys_mmap(16) as *i64
47 cnt[0] = 0
48 cnt[1] = 0
49
50 rl_puts("NISHI-CITE-REDLINE-GATE (F993 product surface: verify every citation in a filed paragraph)\n" as *u8)
51
52 // store one real source; use a FIXED short id so the doc can reference it literally
53 let sid: *u8 = sys_mmap(64)
54 rl_id("S-" as *u8, nonce, sid)
55 cite_source_put(pfx, sid, "The trust account shall be reconciled quarterly." as *u8)
56
57 let rep: *u8 = sys_mmap(65536)
58
59 // ---- D1: an all-good document -> ZERO struck, clean ----
60 // build "...<<S-nonce|The trust account shall be reconciled quarterly.>>..."
61 let d1: *u8 = sys_mmap(4096)
62 var o: i64 = mt_catcopy(d1, 0, "Per the rule, <<" as *u8)
63 o = mt_catcopy(d1, o, sid)
64 o = mt_catcopy(d1, o, "|The trust account shall be reconciled quarterly.>> as required." as *u8)
65 d1[o] = 0 as u8
66 rl_ck(cnt, "D1 all-verified document -> 0 struck" as *u8, cite_scan_doc(pfx, d1, rep), 0)
67 rl_ck(cnt, "D1a document is clean (filable)" as *u8, cite_doc_clean(pfx, d1), 1)
68
69 // ---- D2: a document with a FABRICATED quote to the real source -> 1 struck ----
70 let d2: *u8 = sys_mmap(4096)
71 o = mt_catcopy(d2, 0, "The court held <<" as *u8)
72 o = mt_catcopy(d2, o, sid)
73 o = mt_catcopy(d2, o, "|The trust account may be reconciled whenever convenient.>> here." as *u8)
74 d2[o] = 0 as u8
75 rl_ck(cnt, "D2 fabricated quote -> 1 struck" as *u8, cite_scan_doc(pfx, d2, rep), 1)
76 rl_ck(cnt, "D2a document is NOT clean" as *u8, cite_doc_clean(pfx, d2), 0)
77
78 // ---- D3: a document citing a MADE-UP source -> 1 struck ----
79 let d3: *u8 = sys_mmap(4096)
80 o = mt_catcopy(d3, 0, "See <<Smith-v-Nobody-999|anything at all>> for support." as *u8)
81 d3[o] = 0 as u8
82 rl_ck(cnt, "D3 made-up source -> 1 struck" as *u8, cite_scan_doc(pfx, d3, rep), 1)
83
84 // ---- D4: a MIX of good + fabricated + missing-source in one paragraph -> exactly 2 struck ----
85 let d4: *u8 = sys_mmap(4096)
86 o = mt_catcopy(d4, 0, "First <<" as *u8)
87 o = mt_catcopy(d4, o, sid)
88 o = mt_catcopy(d4, o, "|The trust account shall be reconciled quarterly.>>" as *u8) // good
89 o = mt_catcopy(d4, o, " and second <<" as *u8)
90 o = mt_catcopy(d4, o, sid)
91 o = mt_catcopy(d4, o, "|reconciled monthly>>" as *u8) // fabricated
92 o = mt_catcopy(d4, o, " and third <<Ghost-Case-1|whatever>> done." as *u8) // missing source
93 d4[o] = 0 as u8
94 rl_ck(cnt, "D4 mixed paragraph (1 good, 2 bad) -> exactly 2 struck" as *u8, cite_scan_doc(pfx, d4, rep), 2)
95
96 // ---- D5: THE DODGE. An UNTERMINATED citation (no closing >>) must be STRUCK, not skipped ----
97 let d5: *u8 = sys_mmap(4096)
98 o = mt_catcopy(d5, 0, "Sneaky <<" as *u8)
99 o = mt_catcopy(d5, o, sid)
100 o = mt_catcopy(d5, o, "|reconciled monthly with no closing marker so verification is skipped" as *u8)
101 d5[o] = 0 as u8
102 rl_ck(cnt, "D5 unterminated citation (the dodge) -> STRUCK not skipped" as *u8, cite_scan_doc(pfx, d5, rep), 1)
103
104 // ---- D6: a document with NO citations -> 0 struck (vacuously clean, honestly) ----
105 rl_ck(cnt, "D6 no-citation prose -> 0 struck" as *u8,
106 cite_scan_doc(pfx, "Plain prose with nothing to verify at all." as *u8, rep), 0)
107
108 // ---- D7: report content is populated (the human sees WHY, not just a count) ----
109 cite_scan_doc(pfx, d4, rep)
110 var rlen: i64 = 0
111 while rep[rlen] != (0 as u8) { rlen = rlen + 1 }
112 var has_report: i64 = 0
113 if rlen > 0 { has_report = 1 }
114 rl_ck(cnt, "D7 redline report is populated for the drafter" as *u8, has_report, 1)
115
116 rl_puts("---- sample redline (D4) ----\n" as *u8)
117 rl_puts(rep)
118
119 rl_puts("nx_cite_redline_gate: pass=" as *u8); rl_putn(cnt[0])
120 rl_puts(" fail=" as *u8); rl_putn(cnt[1]); rl_puts("\n" as *u8)
121 if cnt[1] == 0 {
122 rl_puts("F993 nx_cite_redline: VERDICT=GREEN (every citation in a document verified or struck; the dodge is closed)\n" as *u8)
123 sys_exit(0)
124 return 0
125 }
126 rl_puts("F993 nx_cite_redline: VERDICT=RED\n" as *u8)
127 sys_exit(1)
128 return 1
129}