nx_capreach.nx source
↩ module page · 141 lines · 7795 B
1// nx_capreach.nx -- WHEN A TOOL IS DENIED, WHAT ELSE REACHES ITS FUNCTION? (2026-09-04)
2//
3// THE DEFECT THIS CLOSES, measured FIVE TIMES IN ONE SESSION BY ONE SEAT. A capability denial names a
4// TOOL. It does not name the FUNCTION that tool performs, and in this estate the function is almost always
5// reachable another way -- but a denial message ends the search, because it reads like a wall and offers
6// only "mint a cap". Measured instances, all 2026-09-04: nx_capsearch denied, reachable because
7// nx_spendgate FORKS it; nx_sov_build_run denied, reachable because nx_stale_check forks it; the deploy
8// lane denied, reachable through nx_restage; nx_sota_status denied, its VERDICT readable because the organ
9// runs on a beat and PERSISTS it to knowledge/status/sota_board.ledger. Each time a blocker was published
10// before the reach was enumerated, and each time the reach existed.
11// A FALSE I-AM-BLOCKED IS SELF-CONFIRMING, because nothing afterwards tests it.
12//
13// TWO RELATIONS, AND THEY ARE THE TWO THAT ACTUALLY WORKED -- not the one that was easiest to write.
14// A SHARED-ELF detector was considered and REJECTED: tool_allowlist.conf does map several names onto one
15// elf (nx_status and nx_torstat both point at nx_hostctl), so it is trivially implementable, but NONE of
16// the five measured cases had that shape. Shipping it would have been a detector that cannot fire on the
17// cases that motivated it -- a different detector wearing the name of the problem.
18// ARTIFACT the target's own persisted output, which carries its verdict when the organ cannot be called.
19// *** SHIPPED IN THIS LEG. ***
20// FORK a source that names the target and is itself a registered tool: a callable composer.
21// *** NOT IMPLEMENTED IN THIS LEG, AND SAID SO HERE RATHER THAN LEFT IMPLIED. *** It needs a
22// whole-corpus scan and therefore its own cost envelope, so it is a NAMED NEXT LEG. This
23// paragraph exists because the first draft described BOTH relations as if both shipped --
24// the exact overclaiming-prose defect that nx_board_contract_gate's prose axis was built THE
25// SAME DAY to catch. A header is not a measurement, and an organ whose own comment oversells
26// it is the cheapest possible place for that defect to start.
27//
28// PUBLISHES A LIST, NEVER A VERDICT. The estate has measured that a ranker whose top hit is not the answer
29// must print evidence and let a human decide (nx_spendgate ships with no threshold for exactly this
30// reason). A composer that merely NAMES the target may not expose it; this organ says so rather than
31// scoring it.
32//
33// exit: 0 candidates printed . 2 usage . 3 no allowlist readable license_tier: ORIGINAL No hw writes.
34import "nx_syscalls.nx"
35
36const CR_PATH: i64 = 1024
37const CR_CAP: i64 = 1048576
38const CR_NL: i64 = 10
39const CR_TAB: i64 = 9
40const CR_NAMECAP: i64 = 128
41
42func cr_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
43func cr_w(s: *u8) -> i64 { sys_write(1, s, cr_slen(s)); return 0 }
44func cr_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var i: i64 = 0; while s[i] != (0 as u8) { dst[o] = s[i]; o = o + 1; i = i + 1 } dst[o] = 0 as u8; return o }
45func cr_find(buf: *u8, n: i64, needle: *u8, from: i64) -> i64 {
46 let m: i64 = cr_slen(needle)
47 if m == 0 { return 0 - 1 }
48 var i: i64 = from
49 while i + m <= n {
50 var j: i64 = 0
51 var ok: i64 = 1
52 while j < m { if buf[i + j] != needle[j] { ok = 0; j = m } else { j = j + 1 } }
53 if ok == 1 { return i }
54 i = i + 1
55 }
56 return 0 - 1
57}
58func cr_read(path: *u8, buf: *u8, cap: i64) -> i64 {
59 let fd: i64 = sys_openat_rd(path)
60 if fd < 0 { return 0 - 1 }
61 var off: i64 = 0
62 var r: i64 = 1
63 while r > 0 {
64 if off >= cap - 1 { r = 0 } else {
65 r = sys_read(fd, (buf as i64 + off) as *u8, cap - 1 - off)
66 if r > 0 { off = off + r }
67 }
68 }
69 sys_close(fd)
70 buf[off] = 0 as u8
71 return off
72}
73func cr_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
74
75// THE ALLOWLIST IS THE REGISTRY OF WHAT IS CALLABLE AT ALL. A candidate composer that is not in it cannot
76// be invoked over MCP, so naming it would be advice the caller cannot take.
77func cr_is_tool(al: *u8, n: i64, name: *u8) -> i64 {
78 var at: i64 = cr_find(al, n, name, 0)
79 while at >= 0 {
80 var atline: i64 = 0
81 if at == 0 { atline = 1 }
82 if at > 0 { if (al[at - 1] as i64) == CR_NL { atline = 1 } }
83 if atline == 1 {
84 let after: i64 = at + cr_slen(name)
85 if after < n { if (al[after] as i64) == CR_TAB { return 1 } }
86 }
87 at = cr_find(al, n, name, at + 1)
88 }
89 return 0
90}
91
92func main(argc: i64, argv: *i64) -> i64 {
93 if argc < 2 {
94 cr_w("usage: nx_capreach <denied-tool-name>\n" as *u8)
95 cr_w(" Prints its own persisted output artifacts -- a verdict is often readable without the tool.\n" as *u8)
96 cr_w(" Evidence, never a verdict. FORK/composer detection is a named next leg, NOT in this build.\n" as *u8)
97 return 2
98 }
99 let target: *u8 = argv[1] as *u8
100 cr_w("NX-CAPREACH target=" as *u8); cr_w(target); cr_w("\n" as *u8)
101
102 let al: *u8 = sys_mmap(CR_CAP)
103 var an: i64 = cr_read("tool_allowlist.conf" as *u8, al, CR_CAP)
104 if an <= 0 { an = cr_read("../tool_allowlist.conf" as *u8, al, CR_CAP) }
105 if an <= 0 {
106 cr_w(" NO-ALLOWLIST -- cannot tell a callable composer from an uncallable one, so nothing is\n" as *u8)
107 cr_w(" printed rather than printing candidates the caller could not invoke.\n" as *u8)
108 return 3
109 }
110 let registered: i64 = cr_is_tool(al, an, target)
111 cr_w(" target_is_registered=" as *u8)
112 if registered == 1 { cr_w("yes (the denial is a CAP scope, not a missing registration)\n" as *u8) }
113 if registered == 0 { cr_w("no (this tool is not in the allowlist at all -- a different problem)\n" as *u8) }
114
115 // ---- RELATION 2 first, because it is the cheapest and it answers the verdict question directly ----
116 cr_w(" -- ARTIFACT: where this organ's own output lands, readable without calling it --\n" as *u8)
117 var nart: i64 = 0
118 let p: *u8 = sys_mmap(CR_PATH)
119 var k: i64 = 0
120 while k < 4 {
121 var o: i64 = 0
122 if k == 0 { o = cr_cat(p, 0, "knowledge/status/" as *u8); o = cr_cat(p, o, target); o = cr_cat(p, o, ".status" as *u8) }
123 if k == 1 { o = cr_cat(p, 0, "knowledge/status/" as *u8); o = cr_cat(p, o, target); o = cr_cat(p, o, ".log" as *u8) }
124 if k == 2 { o = cr_cat(p, 0, "knowledge/status/" as *u8); o = cr_cat(p, o, target); o = cr_cat(p, o, ".ledger" as *u8) }
125 if k == 3 { o = cr_cat(p, 0, "knowledge/status/" as *u8); o = cr_cat(p, o, target); o = cr_cat(p, o, ".stamp" as *u8) }
126 if cr_exists(p) == 1 { cr_w(" ARTIFACT " as *u8); cr_w(p); cr_w("\n" as *u8); nart = nart + 1 }
127 k = k + 1
128 }
129 if nart == 0 {
130 cr_w(" none at the four conventional paths. THAT IS NOT ABSENCE: a beat organ may write under a\n" as *u8)
131 cr_w(" name of its own choosing (nx_sota_status writes sota_board.ledger, not nx_sota_status.*),\n" as *u8)
132 cr_w(" so a miss here means LOOK BY HAND, never that no artifact exists.\n" as *u8)
133 }
134 cr_w(" artifacts_found=" as *u8)
135 if nart == 0 { cr_w("0\n" as *u8) }
136 if nart == 1 { cr_w("1\n" as *u8) }
137 if nart > 1 { cr_w("many\n" as *u8) }
138 cr_w("NX-CAPREACH done -- ARTIFACT relation ONLY in this build. The FORK relation (which registered tool\n" as *u8)
139 cr_w(" composes this one) is a named next leg, so a quiet result here is NOT a proven wall.\n" as *u8)
140 return 0
141}