nx_spendgate.nx source
↩ module page · 177 lines · 8418 B
1// nx_spendgate.nx -- ASK BEFORE YOU SPEND. The gate between "I should build X" and building X.
2//
3// WHY IT EXISTS. On 2026-08-07 I built `nx_strdiff` when `nx_contentdiff` already existed and did the
4// same job better, wrote `ss_khash` when `nx_web_shard_compact` already carried the identical hash
5// dedup, and ran a 649-row `nx_stalecensus` that DUPLICATED a sibling seat's completed run -- the
6// third of those saturated the mgmt API for ~25 minutes and bought nothing. Every one of those was
7// preventable by a single query against tooling that already existed and worked.
8// ★★★★★★"I DIDN'T KNOW IT EXISTED" IS A RETRIEVAL FAILURE, NOT A DISCOVERY.
9// A line in a doc did not stop me. An exit code is branched on; an advisory is skipped.
10//
11// COMPOSES THE INCUMBENTS, never reimplements them (building a fourth duplicate to prevent duplicates
12// would be its own punchline):
13// nx_presubmit <name> -- is the NAME taken or dual-copied? MECHANICAL, decidable
14// nx_capsearch <intent words> -- what already does something like this? RANKED, NOT decidable
15//
16// ⛔WHY THERE IS NO SIMILARITY THRESHOLD, AND WHY ADDING ONE WOULD BE A LIE. Measured over four
17// queries whose ground truth I knew, because I had just lived each one:
18// DUPLICATE (nx_contentdiff existed) top=nx_route_diff score=499998
19// NOVEL (fixture ratchet) top=nx_govern_sweep score=421048
20// DUPLICATE (nx_capsearch existed) top=nishi_search score=470584
21// NOVEL (no pre-spend gate) top=nx_adnet_recbeat score=500000 <-- HIGHEST OF ALL FOUR
22// The highest score in the set belongs to a NOVEL case, and in BOTH duplicate cases the true incumbent
23// ranked SECOND, not first. Any cutoff would have blocked the novel work and waved the duplicates
24// through -- the precise inversion of the tool's purpose.
25// ★★★★★★A RULER THAT SCORES A NOVEL THING HIGHEST OF ALL CANNOT BE THRESHOLDED -- PUBLISH THE LIST,
26// NOT A VERDICT. ★★★★★TOP-1 IS NOT THE ANSWER; THE LIST IS.
27// So this gate automates ONLY what is mechanically decidable and REFUSES to synthesise the rest. It
28// prints the candidates and makes you look. That is the honest maximum.
29//
30// It does NOT create anything. A gate that performs the act it authorises cannot be re-run to audit
31// its own decision -- the same rule nx_adoptgate states for promotion.
32//
33// nx_spendgate <proposed-name> <intent words...>
34// -> SPEND-GATE name=<n> presubmit=FREE|TAKEN verdict=REVIEW|BLOCKED
35// exit 0 REVIEW (name is free; READ the candidates before spending) | 1 BLOCKED (name taken) | 3 usage
36// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
37import "nx_tool_run.nx"
38
39const SG_HOST: *u8 = "/volume1/homes/elderwesto/nishihost"
40const SG_PRESUB: *u8 = "/volume1/homes/elderwesto/nishihost/nx_presubmit.elf"
41const SG_CAPSEARCH: *u8 = "/volume1/homes/elderwesto/nishihost/nx_capsearch.elf"
42const SG_CAP: i64 = 262144
43const SG_TMO: i64 = 60000
44const SG_AVCAP: i64 = 512
45
46func sgp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
47func sgw(b: *u8, n: i64) -> i64 { sys_write(1, b, n); return 0 }
48
49// Scan the WHOLE buffer, never just the head: a captured stream merges stdout and stderr, so the line
50// you want is routinely not first. (Classifying by the first bytes read every SUCCESS as unparsed once
51// already -- nx_adoptgate carries the same warning for the same reason.)
52func sgfind(buf: *u8, n: i64, ndl: *u8) -> i64 {
53 var nl: i64 = 0
54 while ndl[nl] != (0 as u8) { nl = nl + 1 }
55 if nl == 0 { return 1 }
56 if n < nl { return 0 }
57 var i: i64 = 0
58 while i <= n - nl {
59 var m: i64 = 1
60 var c: i64 = 0
61 while c < nl {
62 if buf[i + c] != ndl[c] { m = 0; c = nl } else { c = c + 1 }
63 }
64 if m == 1 { return 1 }
65 i = i + 1
66 }
67 return 0
68}
69
70func main(argc: i64, argv: *i64) -> i64 {
71 if argc < 3 {
72 sgp("usage: nx_spendgate <proposed-name> <intent words...>\
73" as *u8)
74 sgp(" asks nx_presubmit (name collision, decidable) and nx_capsearch (incumbents, NOT decidable)\
75" as *u8)
76 sgp(" exit 0 REVIEW | 1 BLOCKED (name taken) | 3 usage\
77" as *u8)
78 sys_exit(3)
79 return 3
80 }
81 let name: *u8 = argv[1] as *u8
82 let out: *u8 = sys_mmap(SG_CAP)
83 let ol: *i64 = sys_mmap(16) as *i64
84 let av: *i64 = sys_mmap(SG_AVCAP) as *i64
85
86 // ---- STEP 1 (MECHANICAL): is the name already taken in either source dir?
87 av[0] = SG_PRESUB as i64
88 av[1] = name as i64
89 av[2] = 0
90 ol[0] = 0
91 tr_run_capture_cwd(SG_PRESUB, av, out, SG_CAP, ol, SG_TMO, SG_HOST)
92 // READ THE VOCABULARY, DO NOT GUESS IT. The first cut of this gate tested for "verdict":"TAKEN"
93 // -- a value nx_presubmit never emits. It reports FREE, EXISTS-in-hdl_build, or
94 // SHADOW-RISK-runtime-twin. The gate still BLOCKED (a missing verdict is not a pass, so it failed
95 // closed) but it blocked for the WRONG REASON and told the caller nothing useful.
96 // ★★★★★I INVENTED A SCHEMA INSTEAD OF READING ONE -- rule 1, in the very organ built to stop me
97 // spending on things I had not checked.
98 // So: key on the ONE value that means safe, and treat everything else as taken. That is
99 // fail-closed AND future-proof -- a verdict nobody has invented yet still blocks, where an
100 // enumerate-the-bad-states test would silently pass it.
101 let free: i64 = sgfind(out, ol[0], "\"verdict\":\"FREE\"" as *u8)
102 let taken: i64 = sgfind(out, ol[0], "\"verdict\":\"" as *u8)
103 // A MISSING VERDICT IS NOT A PASS. If the ruler did not speak, say so rather than assuming FREE --
104 // an absent measurement must never read as a satisfied one.
105 var namestate: i64 = 0
106 // ORDER MATTERS: the `taken` test is a SUPERSET of the `free` test -- it matches any verdict field
107 // at all, FREE included. As two independent ifs the second overwrote the first, so EVERY name came
108 // back TAKEN, free ones included. The BAD-input case still passed; only running the GOOD input
109 // exposed it.
110 // **TESTING ONLY THE BAD INPUT SHIPS A DETECTOR THAT FIRES ON EVERYTHING** -- which is exactly the
111 // two-sided contract gv_bite enforces, and it caught this on the first run.
112 if free == 1 { namestate = 1 } else {
113 if taken == 1 { namestate = 2 }
114 }
115
116 sgp("SPEND-GATE name=" as *u8)
117 sgp(name)
118 sgp(" presubmit=" as *u8)
119 if namestate == 1 { sgp("FREE" as *u8) }
120 if namestate == 2 { sgp("TAKEN" as *u8) }
121 if namestate == 0 { sgp("UNKNOWN" as *u8) }
122 sgp("\
123" as *u8)
124
125 if namestate == 2 {
126 sgp(" the name already exists in a source dir -- you are about to create a dual copy.\
127" as *u8)
128 sgp(" nx_presubmit said, verbatim (it names the file AND the fix):\
129" as *u8)
130 sgw(out, ol[0])
131 sgp("\
132SPEND-GATE verdict=BLOCKED reason=name-taken\
133" as *u8)
134 sys_exit(1)
135 return 1
136 }
137 if namestate == 0 {
138 sgp(" nx_presubmit did not report a verdict -- treating as BLOCKED, never as free.\
139" as *u8)
140 sgp("SPEND-GATE verdict=BLOCKED reason=no-presubmit-verdict\
141" as *u8)
142 sys_exit(1)
143 return 1
144 }
145
146 // ---- STEP 2 (NOT DECIDABLE -- PUBLISHED, NOT JUDGED): who already does something like this?
147 av[0] = SG_CAPSEARCH as i64
148 var n: i64 = 1
149 var s: i64 = 2
150 while s < argc {
151 if n < SG_AVCAP / 8 - 2 { av[n] = argv[s] as i64; n = n + 1 }
152 s = s + 1
153 }
154 av[n] = 0
155 ol[0] = 0
156 tr_run_capture_cwd(SG_CAPSEARCH, av, out, SG_CAP, ol, SG_TMO, SG_HOST)
157
158 sgp(" -- INCUMBENT CANDIDATES (nx_capsearch over the registered tool corpus) --\
159" as *u8)
160 sgp(" READ THESE. The score CANNOT tell duplicate from novel: measured, a NOVEL query scored the\
161" as *u8)
162 sgp(" highest of four cases and both true incumbents ranked SECOND. No cutoff is applied here on\
163" as *u8)
164 sgp(" purpose -- the judgement is yours and the evidence is below.\
165" as *u8)
166 if ol[0] > 0 { sgw(out, ol[0]) } else {
167 sgp(" (nx_capsearch produced NO output -- that is NOT evidence of absence. A cap-file or\
168" as *u8)
169 sgp(" transport failure prints nothing; re-run it directly before believing the silence.)\
170" as *u8)
171 }
172 sgp("\
173SPEND-GATE verdict=REVIEW reason=name-free-incumbents-listed\
174" as *u8)
175 sys_exit(0)
176 return 0
177}