nx_goalmap.nx source
↩ module page · 117 lines · 6243 B
1// nx_goalmap.nx -- CLI over nx_goalmap_lib (seat-system, 2026-09-05): the estate maps an operator goal onto
2// the boards from DATA so a seat does not spend frontier tokens re-reading them. Everything is in the lib;
3// this file only parses argv and writes the capped digest.
4// nx_goalmap <domains-csv> <word> [word...]
5// nx_goalmap record [conf] -> EC38 (2026-09-06): the estate mines its OWN RECORD for compare-worthy work no board
6// carries. Refreshes the invoked-tool set from the action journal (forks nx_actlog freq),
7// then gm_record_gaps over the DECLARED source set (knowledge/recordgaps.conf) writes the
8// candidate plane knowledge/store/comparegaps- and prints a JSON whose partition sums
9// exit 0 digest written | 2 usage | 3 no domain readable | 4 duplicate rung id (refused by name)
10// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
11import "nx_syscalls.nx"
12import "nx_sovjson_lib.nx"
13import "nx_goalmap_lib.nx"
14import "nx_tool_run.nx"
15
16const GMC_EXIT_USAGE: i64 = 2
17const GMC_NL: i64 = 10
18const GMC_STDOUT: i64 = 1
19const GMC_STDERR: i64 = 2
20const GMC_FREQ_TOPN: *u8 = "8192" // rows the freq refresh asks for; the miner's own soft cap still bounds the document
21const GMC_FREQ_CAP: i64 = 4194304
22const GMC_MODE644: i64 = 420
23
24func gmc_nl(fd: i64) -> i64 { let b: *u8 = sys_mmap(4); b[0] = GMC_NL as u8; sys_write(fd, b, 1); return 0 }
25func gmc_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
26// the miner, from whichever root serves it (the job lane's CWD decides which spelling resolves)
27func gmc_actlog(out: *u8) -> i64 {
28 if gmc_exists("_offc/nx_actlog.elf" as *u8) == 1 { sj_cat(out, 0, "_offc/nx_actlog.elf" as *u8); return 1 }
29 if gmc_exists("./nx_actlog.elf" as *u8) == 1 { sj_cat(out, 0, "./nx_actlog.elf" as *u8); return 1 }
30 if gmc_exists("../nx_actlog.elf" as *u8) == 1 { sj_cat(out, 0, "../nx_actlog.elf" as *u8); return 1 }
31 return 0
32}
33// refresh the invoked set: fork `nx_actlog freq <journal> <topn>` and write its JSON to the conf's invoked path.
34// Returns bytes written; 0 when the conf names no journal or no invoked path; -1 when the miner is absent or failed
35// (the record verb then reads whatever freq JSON exists and reports the invoked source ABSENT if none -- never a
36// silent zero). The receipt is printed on stderr beside the document so a stale invoked set is visible.
37func gmc_refresh_invoked(conf: *u8) -> i64 {
38 let paths: *i64 = sys_mmap(GR_S_N * 8) as *i64
39 var s: i64 = 0
40 while s < GR_S_N { let pb: *u8 = sys_mmap(GM_PATHB); pb[0] = 0 as u8; paths[s] = pb as i64; s = s + 1 }
41 let plane: *u8 = sys_mmap(GM_PATHB)
42 let declared: *i64 = sys_mmap(GR_S_N * 8) as *i64
43 let unknown: *i64 = sys_mmap(GM_SPAN) as *i64
44 unknown[0] = 0
45 let cadp: *i64 = sys_mmap(GM_SPAN) as *i64
46 cadp[0] = GR_CADENCE_DEFAULT
47 if gr_conf_load(conf, paths, plane, declared, unknown, cadp) < 0 { return 0 }
48 let journal: *u8 = paths[GR_S_JOURNAL] as *u8
49 let invoked: *u8 = paths[GR_S_INVOKED] as *u8
50 if journal[0] == (0 as u8) { return 0 }
51 if invoked[0] == (0 as u8) { return 0 }
52 let elf: *u8 = sys_mmap(GM_PATHB)
53 if gmc_actlog(elf) == 0 { return 0 - 1 }
54 let av: *i64 = sys_mmap(64) as *i64
55 av[0] = elf as i64
56 av[1] = "freq" as *u8 as i64
57 av[2] = journal as i64
58 av[3] = GMC_FREQ_TOPN as i64
59 av[4] = 0
60 let cap: *u8 = sys_mmap(GMC_FREQ_CAP)
61 let cl: *i64 = sys_mmap(GM_SPAN) as *i64
62 let ex: i64 = tr_run_capture(elf, av, cap, GMC_FREQ_CAP - 1, cl)
63 if ex != 0 { return 0 - 1 }
64 if cl[0] <= 0 { return 0 - 1 }
65 let fd: i64 = sys_openat_wr(invoked, GMC_MODE644)
66 if fd < 0 { return 0 - 1 }
67 let w: i64 = sys_write(fd, cap, cl[0])
68 sys_close(fd)
69 return w
70}
71
72func main(argc: i64, argv: *i64) -> i64 {
73 if argc >= 2 { if gm_str_eq(argv[1] as *u8, "record" as *u8) == 1 {
74 var conf: *u8 = GR_CONF_DEFAULT
75 if argc >= 3 { conf = argv[2] as *u8 }
76 let refreshed: i64 = gmc_refresh_invoked(conf)
77 let ro: *u8 = sys_mmap(GR_OUTB)
78 let rn: i64 = gm_record_gaps(conf, ro)
79 if rn < 0 {
80 sj_werr("nx_goalmap record: the conf is unreadable (exit 1) or no regen.list is readable under the plans source (exit 3) -- the census is UNOBSERVABLE and wrote no plane" as *u8)
81 gmc_nl(GMC_STDERR)
82 sys_exit(0 - rn)
83 return 0 - rn
84 }
85 sj_werr("nx_goalmap record: invoked refresh bytes=" as *u8)
86 let rb: *u8 = sys_mmap(32)
87 let ro2: i64 = sj_catn(rb, 0, refreshed)
88 sys_write(GMC_STDERR, rb, ro2)
89 gmc_nl(GMC_STDERR)
90 sys_write(GMC_STDOUT, ro, rn)
91 sys_exit(0)
92 return 0
93 } }
94 if argc < 3 {
95 sj_werr("usage: nx_goalmap <domains-csv> <word> [word...] -> capped JSON digest: per domain the rung rows whose title, done-rule or symbol carry the words (score = distinct words), status from the matrix and the operator accept- plane, ledger size and last epoch, matrix watch gaps with SOURCE/BUILT/PROMOTED probed, and a dependency order; exit 3 = no domain readable, 4 = duplicate rung id refused | nx_goalmap record [conf] -> EC38 record-gap census (candidate plane + partition)" as *u8)
96 gmc_nl(GMC_STDERR)
97 sys_exit(GMC_EXIT_USAGE)
98 return GMC_EXIT_USAGE
99 }
100 // v1.2 (2026-09-05): sized from the INPUT, never from a guess -- every word argv carries is a word (the old cap
101 // of 24 dropped the rest in silence), and the output buffer is what the lib declares it needs for this many
102 // domains (the old fixed 16 KB was overrun by multi-domain scaffolding: debt 1788626163)
103 let words: *i64 = sys_mmap((argc - 2) * 8) as *i64
104 var nw: i64 = 0
105 var i: i64 = 2
106 while i < argc { words[nw] = argv[i]; nw = nw + 1; i = i + 1 }
107 let out: *u8 = sys_mmap(gm_outbuf(argv[1] as *u8))
108 let n: i64 = gm_run("" as *u8, argv[1] as *u8, words, nw, out)
109 if n < 0 {
110 sys_write(GMC_STDOUT, out, sj_vlen(out))
111 sys_exit(0 - n)
112 return 0 - n
113 }
114 sys_write(GMC_STDOUT, out, n)
115 sys_exit(0)
116 return 0
117}