code wiki / _hdl_build / nx_autonomy_grow_hardened.nx
nx_autonomy_grow_hardened.nx source
↩ module page · 118 lines · 8090 B
1// nx_autonomy_grow_hardened.nx -- Prevents gaming of growth loops by deduplicating family signatures and persisting authored patterns.
2import "nx_gate_gn.nx"
3import "nx_gate_base.nx"
4// nx_autonomy_grow_hardened.nx -- #1: close the two gaming vectors I exposed, so the continuous loop is DEPLOY-SAFE.
5// nx_autonomy_grow_loop deduped by exact SEQUENCE + within-run only -> two holes: (a) re-running re-registers; (b)
6// 2^x vs 3^x (same geometric family, different constant) would EACH accrue. This hardens the gate two ways:
7// FAMILY-SIGNATURE dedup -- sig = (construct kind, structural body-op), CONSTANT-INDEPENDENT. ncf_loop_eval(init,bop,c)
8// -> 2^x=(kind2,bop1) and 3^x=(kind2,bop1) collapse to ONE family; factorial=(kind2,bop3) is distinct. Closes (b).
9// PERSISTENT ledger -- authored signatures live in a FILE; the gate reads it before authoring, so a family seen in ANY
10// prior beat/run is deduped. Closes (a). (This gate clears the ledger at start for determinism; production keeps it.)
11// T1 NEW FAMILY: 2^x -> signature unseen -> AUTHOR + persist.
12// T2 FAMILY-DEDUP (closes b): 3^x -> SAME signature as 2^x (constant differs, family same) -> DEDUP.
13// T3 DISTINCT FAMILY: factorial -> different signature (bop=3) -> AUTHOR.
14// T4 PERSISTENT-DEDUP (closes a): 2^x again -> signature found IN THE FILE -> DEDUP.
15// T5 DEPLOY-SAFE: 4 candidates -> 2 authored (structurally distinct), 2 deduped -> the meter cannot be gamed by repetition OR parameter-variation -> safe to wire into nx_governed_pulse.
16// license_tier: ORIGINAL
17import "nx_ncf_synth.nx"
18import "nx_syscalls.nx"
19const K_MAGIC_1024: i64 = 1024
20const K_MAGIC_6561: i64 = 6561
21const K_MAGIC_40320: i64 = 40320
22
23
24func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
25" as *u8); return ok }
26func genuine_fit(xs: *i64, ys: *i64, n: i64, hx: i64, hy: i64, form_out: *i64) -> i64 {
27 let kind: i64=ncf_synth(xs, ys, n, form_out)
28 if kind==0 { return 0 }
29 if ncf_eval(kind, form_out, hx)!=hy { return 0 }
30 return kind
31}
32// CONSTANT-INDEPENDENT family signature: structure only (kind + body-op / order), NOT the numeric parameters.
33func fam_sig(kind: i64, form: *i64) -> i64 {
34 if kind==2 { return 200+form[1] } // (loop, bop): geometric(bop1)/factorial(bop3)/linear(bop0,2) -- ignores init,c
35 if kind==6 { return 600+form[0] } // (recurrence, order k): order-2/3/4 -- ignores coeffs
36 return kind*100 // other constructs: the kind IS the family
37}
38// persistent ledger of authored family-signatures (one decimal per line).
39func sig_in_file(sig: i64, path: *u8) -> i64 {
40 let lenp: *i64=sys_mmap(16) as *i64; let buf: *u8=sys_read_file(path, lenp)
41 if (buf as i64)==0 { return 0 }
42 let n: i64=lenp[0]; var i: i64=0; var cur: i64=0; var have: i64=0; var found: i64=0
43 while i<n {
44 let ch: *u8=((buf as i64)+i) as *u8
45 if ch[0]>=(48 as u8) { if ch[0]<=(57 as u8) { cur=(cur*10)+((ch[0] as i64)-48); have=1 } else { if have==1 { if cur==sig { found=1 } } cur=0; have=0 } } else { if have==1 { if cur==sig { found=1 } } cur=0; have=0 }
46 i=i+1
47 }
48 if have==1 { if cur==sig { found=1 } }
49 return found
50}
51func append_sig(sig: i64, path: *u8) -> i64 {
52 let fd: i64=sys_openat_append(path, 420); if fd<0 { return 0 }
53 let b: *u8=sys_mmap(24); var m: i64=sig; var k: i64=0; let t: *u8=sys_mmap(24)
54 if m==0 { t[0]=48 as u8; k=1 } while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 }
55 var w: i64=0; var q: i64=k-1; while q>=0 { b[w]=t[q]; w=w+1; q=q-1 } b[w]=10 as u8
56 sys_write(fd, b, w+1); sys_close(fd); return 0
57}
58func clear_ledger(path: *u8) -> i64 { let fd: i64=sys_openat_wr(path,420); if fd>=0 { sys_close(fd) } return 0 }
59
60// one gate decision: 1=AUTHOR (new family, persisted), 2=DEDUP (family seen), 0=REFUSED (out of grammar).
61func decide(xs: *i64, ys: *i64, n: i64, hx: i64, hy: i64, form: *i64, ledger: *u8, sigout: *i64) -> i64 {
62 let kind: i64=genuine_fit(xs, ys, n, hx, hy, form)
63 if kind==0 { sigout[0]=0-1; return 0 }
64 let sig: i64=fam_sig(kind, form); sigout[0]=sig
65 if sig_in_file(sig, ledger)==1 { return 2 }
66 append_sig(sig, ledger); return 1
67}
68
69func main() -> i64 {
70 gw("=== nx_autonomy_grow_hardened (#1): family-signature + persistent dedup -> deploy-safe gate ===\n" as *u8)
71 var pass: i64=0; var total: i64=0
72 let ledger: *u8="knowledge/status/authored_families.log" as *u8
73 clear_ledger(ledger)
74 let form: *i64=sys_mmap(128) as *i64; let sg: *i64=sys_mmap(16) as *i64
75 let xs: *i64=sys_mmap(128) as *i64; let ys: *i64=sys_mmap(128) as *i64
76 var i: i64=0; while i<8 { xs[i]=i; i=i+1 }
77 var authored: i64=0; var dedup: i64=0
78
79 // T1 NEW FAMILY: 2^x.
80 var p: i64=1; i=0; while i<8 { ys[i]=p; p=p*2; i=i+1 }
81 let r1: i64=decide(xs, ys, 8, 10, K_MAGIC_1024, form, ledger, sg); let s1: i64=sg[0]
82 if r1==1 { authored=authored+1 } else { if r1==2 { dedup=dedup+1 } }
83 total=total+1; if r1==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
84 gw("T1 NEW FAMILY: 2^x -> sig=" as *u8); gn(s1); gw(" unseen -> AUTHOR + persist\n" as *u8)
85
86 // T2 FAMILY-DEDUP (closes vector b): 3^x = same family, different constant.
87 p=1; i=0; while i<8 { ys[i]=p; p=p*3; i=i+1 }
88 let r2: i64=decide(xs, ys, 8, 8, K_MAGIC_6561, form, ledger, sg); let s2: i64=sg[0]
89 if r2==1 { authored=authored+1 } else { if r2==2 { dedup=dedup+1 } }
90 total=total+1; if r2==2 { if s2==s1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
91 gw("T2 FAMILY-DEDUP (closes b): 3^x -> sig=" as *u8); gn(s2); gw(" == 2^x's sig (constant differs, FAMILY same) -> DEDUP\n" as *u8)
92
93 // T3 DISTINCT FAMILY: factorial (bop=3).
94 ys[0]=1; var f: i64=1; i=1; while i<8 { f=f*i; ys[i]=f; i=i+1 }
95 let r3: i64=decide(xs, ys, 8, 8, K_MAGIC_40320, form, ledger, sg); let s3: i64=sg[0]
96 if r3==1 { authored=authored+1 } else { if r3==2 { dedup=dedup+1 } }
97 total=total+1; if r3==1 { if s3!=s1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
98 gw("T3 DISTINCT FAMILY: factorial -> sig=" as *u8); gn(s3); gw(" (bop=3, != geometric) -> AUTHOR\n" as *u8)
99
100 // T4 PERSISTENT-DEDUP (closes vector a): 2^x again -> found IN THE FILE.
101 p=1; i=0; while i<8 { ys[i]=p; p=p*2; i=i+1 }
102 let r4: i64=decide(xs, ys, 8, 10, K_MAGIC_1024, form, ledger, sg)
103 if r4==1 { authored=authored+1 } else { if r4==2 { dedup=dedup+1 } }
104 total=total+1; if r4==2 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
105 gw("T4 PERSISTENT-DEDUP (closes a): 2^x again -> sig found in the FILE -> DEDUP (re-runs cannot re-inflate)\n" as *u8)
106
107 // T5 DEPLOY-SAFE.
108 total=total+1; if authored==2 { if dedup==2 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
109 gw("T5 DEPLOY-SAFE: 4 candidates -> " as *u8); gn(authored); gw(" authored (structurally distinct), " as *u8); gn(dedup); gw(" deduped -> meter un-gameable by repetition OR parameter-variation\n" as *u8)
110
111 gw("\n GATE HARDENED: dedup is now by CONSTANT-INDEPENDENT family signature (2^x==3^x as one geometric family) AND PERSISTENT\n" as *u8)
112 gw(" (a FILE the gate reads before authoring, so any prior run counts). The two gaming vectors I exposed are closed: the meter\n" as *u8)
113 gw(" grows ONLY by structurally-novel families, once each, ever. THIS is the safe form to wire into nx_governed_pulse for\n" as *u8)
114 gw(" continuous accrual. Remaining honest gap: targets are still Claude-curated -> autonomous target-discovery is next (vector c).\n" as *u8)
115 gw("AUTONOMY-GROW-HARDENED verdict=" as *u8)
116 if pass==total { gw("GREEN passes=" as *u8); gn(pass); gw("/" as *u8); gn(total); gw(" -- family-signature + persistent dedup, deploy-safe gate\n" as *u8); sys_exit(0); return 0 }
117 gw("RED passes=" as *u8); gn(pass); gw("/" as *u8); gn(total); gw("\n" as *u8); sys_exit(1); return 1
118}