code wiki / _hdl_build / nx_codewiki_ask.nx

nx_codewiki_ask.nx source

↩ module page · 48 lines · 1937 B

1// nx_codewiki_ask.nx -- ASK THE CODE WIKI, and nothing else. 2// 3// ===== WHY THIS IS A SEPARATE BINARY ===== 4// 5// The allowlist grants a tool either FIXED args (caller argv ignored) or full 6// caller control -- there is no middle. A question must come from the caller, 7// so this tool's row must be unpinned; and an unpinned row on the GENERATOR 8// would hand its holder an arbitrary-path read/write primitive (walk any root, 9// write pages anywhere). So the ask surface is its own entry point that 10// composes the same library and can do exactly one thing: read its own index 11// and print cited hits. **Least authority by construction, not by promise.** 12// 13// nx_codewiki_ask <question words...> 14// 15// Retrieval is LEXICAL and says so: a question sharing no token with the 16// corpus returns NO-MATCH rather than the least-bad guess. 17// 18// license_tier: ORIGINAL No hw writes (Rule 26). 19import "nx_syscalls.nx" 20import "nx_eco_graph.nx" 21import "nx_gatelib.nx" 22import "nx_import_scan.nx" 23import "nx_codewiki_lib.nx" 24const K_MAGIC_1024: i64 = 1024 25 26func cwa_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 27 28func main(argc: i64, argv: *i64) -> i64 { 29 if argc < 2 { 30 cwa_w("usage: nx_codewiki_ask <question words...>\n" as *u8) 31 sys_exit(1) 32 return 1 33 } 34 let toks: *u8 = sys_mmap(K_MAGIC_1024) 35 let toff: *i64 = sys_mmap(CW_ASKQTOK * 8) as *i64 36 let tlen: *i64 = sys_mmap(CW_ASKQTOK * 8) as *i64 37 let nt: i64 = cw_qtok(argv, argc, 1, toks, toff, tlen) 38 if nt == 0 { 39 cwa_w("ASK-NO-TOKENS: question carries no word of 3+ characters.\n" as *u8) 40 sys_exit(1) 41 return 1 42 } 43 let hits: i64 = cw_ask("sites/nishifamily/code/askindex.tsv" as *u8, toks, toff, tlen, nt, 44 "https://nishifamily.com/code/" as *u8, 0 as *u8) 45 if hits < 0 { sys_exit(2); return 2 } 46 sys_exit(0) 47 return 0 48}