code wiki / _hdl_build / nx_dmkt_ideator.nx
nx_dmkt_ideator.nx source
↩ module page · 183 lines · 7172 B
1// nx_dmkt_ideator.nx -- DMKT product-mode recombination (F310): match product NEEDS against a
2// capability CATALOG and emit scored need->capability HYPOTHESES to a discovery plane (status=proposed).
3// Promotion happens ONLY after a plan run PROVES the combo (honest exceed discipline; mirrors
4// nx_atlas_discover but PRODUCT-mode: need-id substring in capability-note = a candidate composition
5// edge the eco-graph cannot see). Widens input beyond commontask (seq81 finding) to real product needs.
6// nx_dmkt_ideator [needs-prefix] [catalog-prefix] [out-prefix] [minscore]
7// defaults: knowledge/store/dmktneeds- knowledge/store/dmktcap- knowledge/store/dmktideas- 1
8// row cols (nx_store_put plane): col0=id col6=note ; out: IDEA<n> need->organ score proposed dmkt ...
9// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
10import "nx_store_seed_lib.nx"
11import "nx_seg_store.nx"
12import "nx_syscalls.nx"
13
14const DI_CAP: i64 = 1048576
15const DI_NL: i64 = 10
16const DI_TAB: i64 = 9
17const DI_MAXCOL: i64 = 16
18const DI_PAIR: i64 = 2
19const DI_SPB: i64 = 256
20const DI_MAXN: i64 = 64
21const DI_MAXOUT: i64 = 256
22const DI_STDERR: i64 = 2
23const DI_EXIT_IO: i64 = 1
24const DI_ZERO: i64 = 48
25const DI_NINE: i64 = 57
26const DI_B10: i64 = 10
27const DI_COLID: i64 = 0
28const DI_COLNOTE: i64 = 6
29
30func di_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
31func di_werr(s: *u8) -> i64 { sys_write(DI_STDERR, s, di_slen(s)); return 0 }
32func di_cols(q: *u8, ls: i64, le: i64, sp: *i64) -> i64 {
33 var c: i64 = 0
34 var p: i64 = ls
35 while c < DI_MAXCOL {
36 var e: i64 = p
37 var s: i64 = 1
38 while s == 1 { if e >= le { s = 0 } else { if q[e] == (DI_TAB as u8) { s = 0 } else { e = e + 1 } } }
39 sp[c*DI_PAIR] = p
40 sp[c*DI_PAIR+1] = e
41 c = c + 1
42 if e >= le { return c }
43 p = e + 1
44 }
45 return c
46}
47func di_has_slice(q: *u8, a: i64, b: i64, r: *u8, ka: i64, kb: i64) -> i64 {
48 let kn: i64 = kb - ka
49 if kn <= 0 { return 0 }
50 var i: i64 = a
51 while i + kn <= b {
52 var hit: i64 = 1
53 var j: i64 = 0
54 while j < kn { if q[i+j] != r[ka+j] { hit = 0; j = kn } else { j = j + 1 } }
55 if hit == 1 { return 1 }
56 i = i + 1
57 }
58 return 0
59}
60func di_atoi(s: *u8) -> i64 {
61 var v: i64 = 0
62 var i: i64 = 0
63 while s[i] != (0 as u8) { let c: i64 = s[i]; if c >= DI_ZERO { if c <= DI_NINE { v = v * DI_B10 + (c - DI_ZERO) } } i = i + 1 }
64 return v
65}
66func di_cat_slice(d: *u8, o: i64, q: *u8, a: i64, b: i64) -> i64 {
67 var oo: i64 = o
68 var i: i64 = a
69 while i < b { d[oo] = q[i]; oo = oo + 1; i = i + 1 }
70 return oo
71}
72
73func main(argc: i64, argv: *i64) -> i64 {
74 var needp: *u8 = "knowledge/store/dmktneeds-" as *u8
75 var catp: *u8 = "knowledge/store/dmktcap-" as *u8
76 var outp: *u8 = "knowledge/store/dmktideas-" as *u8
77 var minsc: i64 = 1
78 if argc > 1 { needp = argv[1] as *u8 }
79 if argc > 2 { catp = argv[2] as *u8 }
80 if argc > 3 { outp = argv[3] as *u8 }
81 if argc > 4 { minsc = di_atoi(argv[4] as *u8) }
82
83 let nbuf: *u8 = sys_mmap(DI_CAP)
84 let nn: i64 = sts_load(needp, nbuf, DI_CAP)
85 if nn <= 0 { di_werr("needs plane EMPTY / unseeded (fail-closed)\n" as *u8); sys_exit(DI_EXIT_IO); return DI_EXIT_IO }
86 let cbuf: *u8 = sys_mmap(DI_CAP)
87 let cn: i64 = sts_load(catp, cbuf, DI_CAP)
88 if cn <= 0 { di_werr("catalog plane EMPTY / unseeded (fail-closed)\n" as *u8); sys_exit(DI_EXIT_IO); return DI_EXIT_IO }
89
90 let sp: *i64 = sys_mmap(DI_SPB) as *i64
91 let nia: *i64 = sys_mmap(DI_MAXN*8) as *i64
92 let nib: *i64 = sys_mmap(DI_MAXN*8) as *i64
93 var nneeds: i64 = 0
94 var i: i64 = 0
95 while i < nn {
96 var le: i64 = i
97 var s: i64 = 1
98 while s == 1 { if le >= nn { s = 0 } else { if nbuf[le] == (DI_NL as u8) { s = 0 } else { le = le + 1 } } }
99 if le > i { if nneeds < DI_MAXN {
100 let ncol: i64 = di_cols(nbuf, i, le, sp)
101 if ncol >= 1 {
102 nia[nneeds] = sp[DI_COLID*DI_PAIR]
103 nib[nneeds] = sp[DI_COLID*DI_PAIR+1]
104 nneeds = nneeds + 1
105 }
106 } }
107 i = le + 1
108 }
109
110 let coa: *i64 = sys_mmap(DI_MAXN*8) as *i64
111 let cob: *i64 = sys_mmap(DI_MAXN*8) as *i64
112 let cta: *i64 = sys_mmap(DI_MAXN*8) as *i64
113 let ctb: *i64 = sys_mmap(DI_MAXN*8) as *i64
114 var ncaps: i64 = 0
115 var ci: i64 = 0
116 while ci < cn {
117 var le2: i64 = ci
118 var s2: i64 = 1
119 while s2 == 1 { if le2 >= cn { s2 = 0 } else { if cbuf[le2] == (DI_NL as u8) { s2 = 0 } else { le2 = le2 + 1 } } }
120 if le2 > ci { if ncaps < DI_MAXN {
121 let ccol: i64 = di_cols(cbuf, ci, le2, sp)
122 if ccol >= 7 {
123 coa[ncaps] = sp[DI_COLID*DI_PAIR]
124 cob[ncaps] = sp[DI_COLID*DI_PAIR+1]
125 cta[ncaps] = sp[DI_COLNOTE*DI_PAIR]
126 ctb[ncaps] = sp[DI_COLNOTE*DI_PAIR+1]
127 ncaps = ncaps + 1
128 }
129 } }
130 ci = le2 + 1
131 }
132
133 let out: *u8 = sys_mmap(DI_CAP)
134 var oo: i64 = 0
135 var nout: i64 = 0
136 var a: i64 = 0
137 while a < nneeds {
138 var b: i64 = 0
139 while b < ncaps {
140 if nout < DI_MAXOUT {
141 if di_has_slice(cbuf, cta[b], ctb[b], nbuf, nia[a], nib[a]) == 1 {
142 if 1 >= minsc {
143 oo = ss_cat(out, oo, "IDEA" as *u8)
144 oo = ss_catn(out, oo, nout)
145 out[oo] = DI_TAB as u8
146 oo = oo + 1
147 oo = di_cat_slice(out, oo, nbuf, nia[a], nib[a])
148 oo = ss_cat(out, oo, "->" as *u8)
149 oo = di_cat_slice(out, oo, cbuf, coa[b], cob[b])
150 out[oo] = DI_TAB as u8
151 oo = oo + 1
152 oo = ss_catn(out, oo, 1)
153 oo = ss_cat(out, oo, "\x09proposed\x09dmkt\x09" as *u8)
154 oo = di_cat_slice(out, oo, nbuf, nia[a], nib[a])
155 oo = ss_cat(out, oo, "+" as *u8)
156 oo = di_cat_slice(out, oo, cbuf, coa[b], cob[b])
157 oo = ss_cat(out, oo, "\x09try: plan 10 " as *u8)
158 oo = di_cat_slice(out, oo, cbuf, coa[b], cob[b])
159 out[oo] = DI_NL as u8
160 oo = oo + 1
161 nout = nout + 1
162 }
163 }
164 }
165 b = b + 1
166 }
167 a = a + 1
168 }
169 if nout == 0 { di_werr("no need-capability matches (saturated at this threshold)\n" as *u8); sys_exit(0); return 0 }
170 if sts_seed(outp, out, oo) < 0 { di_werr("ideas plane commit error\n" as *u8); sys_exit(DI_EXIT_IO); return DI_EXIT_IO }
171 let msg: *u8 = sys_mmap(128)
172 var mo: i64 = ss_cat(msg, 0, "DMKT-IDEATED proposals=" as *u8)
173 mo = ss_catn(msg, mo, nout)
174 mo = ss_cat(msg, mo, " needs=" as *u8)
175 mo = ss_catn(msg, mo, nneeds)
176 mo = ss_cat(msg, mo, " caps=" as *u8)
177 mo = ss_catn(msg, mo, ncaps)
178 msg[mo] = DI_NL as u8
179 mo = mo + 1
180 sys_write(1, msg, mo)
181 sys_exit(0)
182 return 0
183}