code wiki / _hdl_build / nx_docportal_aiblog_lib.nx

nx_docportal_aiblog_lib.nx source

↩ module page · 65 lines · 3655 B

1// nx_docportal_aiblog_lib.nx -- the POLICY-GATED AI-blog writer (operator: "whether an ai writer can publish blog 2// posts with the content"). Composes a blog draft for a domain from ONLY the uploads whose owner flagged 3// DP_USE_AI_BLOG -- enforced by construction (a doc without the flag never enters the AI-blog corpus) AND re-checked 4// LIVE per doc (dp_may) so a consent withdrawal excludes it at once. HONEST SCOPE: the composer is a SOVEREIGN 5// EXTRACTIVE seat (deterministic title + intro + a lead excerpt per permitted doc + footer) -- the governed "writing 6// seat" of the Nishi Writer, not a neural LLM. The GOVERNANCE (whose content, only with consent) is the point; 7// swapping in a stronger generation seat does not change the gate. Composes nx_docportal_lib. license_tier: ORIGINAL 8import "nx_docportal_lib.nx" 9 10func ab_cat(out: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { out[o] = s[i]; o = o + 1; i = i + 1 } return o } 11 12// copy a lead excerpt of text[0..n) into out (up to maxlen chars, newlines/tabs -> space); append " ..." if truncated 13func ab_excerpt(out: *u8, o: i64, text: *u8, n: i64, maxlen: i64) -> i64 { 14 var lim: i64 = n; if lim > maxlen { lim = maxlen } 15 var i: i64 = 0 16 while i < lim { var c: i64 = text[i] as i64; if c == 9 { c = 32 } if c == 10 { c = 32 } if c == 13 { c = 32 } out[o] = c as u8; o = o + 1; i = i + 1 } 17 if n > maxlen { o = ab_cat(out, o, " ..." as *u8) } 18 return o 19} 20 21// compose a blog draft for <domain> from AI-blog-permitted public docs. draft -> out (cap); returns length; 22// countout[0] = number of docs used. Only docs whose LIVE policy permits DP_USE_AI_BLOG are included. 23func ab_compose_blog(domain: *u8, title: *u8, out: *u8, cap: i64, countout: *i64) -> i64 { 24 let path: *u8 = sys_mmap(512); dp_blogsrc(domain, path) 25 let szp: *i64 = sys_mmap(16) as *i64 26 let buf: *u8 = sys_read_file(path, szp) 27 var sz: i64 = 0 28 if (buf as i64) != 0 { sz = szp[0] } 29 30 var o: i64 = 0 31 o = ab_cat(out, o, "# " as *u8); o = ab_cat(out, o, title); o = ab_cat(out, o, "\n\n" as *u8) 32 o = ab_cat(out, o, "A roundup from our published resources. Drafted by the Nishi Writer from content our team explicitly cleared for publication.\n" as *u8) 33 34 var used: i64 = 0 35 var ls: i64 = 0; var i: i64 = 0 36 while i <= sz { 37 var eol: i64 = 0 38 if i == sz { eol = 1 } else { if buf[i] == (10 as u8) { eol = 1 } } 39 if eol == 1 { 40 if i > ls { 41 var tab: i64 = 0 - 1; var k: i64 = ls 42 while k < i { if buf[k] == (9 as u8) { if tab < 0 { tab = k } } k = k + 1 } 43 if tab > ls { 44 var cid: i64 = 0; var j: i64 = ls 45 while j < tab { let c: i64 = buf[j] as i64; if c >= 48 { if c <= 57 { cid = cid * 10 + (c - 48) } } j = j + 1 } 46 let textptr: *u8 = (buf as i64 + tab + 1) as *u8 47 let textlen: i64 = i - tab - 1 48 if dp_may(domain, DP_VIS_PUBLIC, cid, DP_USE_AI_BLOG) == 1 { // LIVE consent re-check 49 if o + textlen + 64 < cap { 50 o = ab_cat(out, o, "\n## Insight\n\n" as *u8) 51 o = ab_excerpt(out, o, textptr, textlen, 220) 52 o = ab_cat(out, o, "\n" as *u8) 53 used = used + 1 54 } 55 } 56 } 57 } 58 ls = i + 1 59 } 60 i = i + 1 61 } 62 o = ab_cat(out, o, "\n---\nPublished by the Nishi Writer under the uploaders' usage policy.\n" as *u8) 63 countout[0] = used 64 return o 65}