nx_authorgen.nx source
↩ module page · 151 lines · 9596 B
1// nx_authorgen.nx -- ★THE AUTHORING FRONT-END (operator 2026-07-13, ref orcaclient.com "Describe a Mod, Get It
2// Built"): natural-language request -> a structured content descriptor -> the generative engine BUILDS it -> VALIDATE.
3// The Orca pattern on the sovereign substrate: describe a creature in words, get it built and placed in the world.
4// v0 = a RULE-BASED parser (data-driven keyword->gene rules, case-insensitive substring match) -- honest as a v0;
5// the trained-LLM front-end (our own no-float Qwen) is the named upgrade. ★ANTI-HALLUCINATION (the real
6// differentiator vs "the AI writes the code and hopes"): report which requested features were BUILT and which CANNOT
7// be, and REFUSE (build nothing) when no creature is recognized -- no fake builds. (Named nx_authorgen to avoid the
8// existing nx_intent.nx = Captain Moroni intent-declaration security primitive; different concern entirely.)
9// license_tier: ORIGINAL
10import "nx_syscalls.nx"
11import "nx_genome.nx"
12import "nx_worldpipe.nx"
13const K_MAGIC_2500: i64 = 2500
14const K_MAGIC_12345: i64 = 12345
15
16static AG_PLAN: i64 // -1 = no creature recognized, else the body plan
17static AG_KIND: i64 // 0 none/refused, 1 creature, 2 world, 3 game (the content type)
18static AG_NFEAT: i64 // recognized feature-modifiers applied
19static AG_UNMET: i64 // requested features we honestly CANNOT build (anti-hallucination)
20// ★content type 3: GAME params (difficulty design-table -> the existing nx_game_web_emit emit_arcade)
21static AG_GW: i64
22static AG_GH: i64
23static AG_NG: i64
24static AG_NH: i64
25static AG_SEED: i64
26
27func ag_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
28func ag_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
29// case-insensitive substring: is `needle` in the first `n` bytes of `hay`?
30func ag_has(hay: *u8, n: i64, needle: *u8) -> i64 {
31 let m: i64 = ag_slen(needle)
32 if m == 0 { return 0 }
33 var i: i64 = 0
34 while i + m <= n {
35 var k: i64 = 0
36 while k < m { if ag_lc(hay[i+k] as i64) != ag_lc(needle[k] as i64) { k = m + 9 } else { k = k + 1 } }
37 if k == m { return 1 }
38 i = i + 1
39 }
40 return 0
41}
42
43// parse a natural-language creature request -> set the genome params. Returns the body plan (-1 = refuse).
44func ag_parse(text: *u8) -> i64 {
45 gen_defaults() // clean slate every parse
46 let n: i64 = ag_slen(text)
47 AG_PLAN = 0 - 1
48 AG_KIND = 0
49 AG_NFEAT = 0
50 AG_UNMET = 0
51 // ---- body plan ----
52 if ag_has(text, n, "rabbit" as *u8) == 1 { AG_PLAN = 1; AG_NFEAT = AG_NFEAT + 1 }
53 if ag_has(text, n, "bunny" as *u8) == 1 { AG_PLAN = 1; AG_NFEAT = AG_NFEAT + 1 }
54 if ag_has(text, n, "hare" as *u8) == 1 { AG_PLAN = 1; AG_NFEAT = AG_NFEAT + 1 }
55 if ag_has(text, n, "monster" as *u8) == 1 { AG_PLAN = 2; AG_NFEAT = AG_NFEAT + 1 }
56 if ag_has(text, n, "demon" as *u8) == 1 { AG_PLAN = 2; AG_NFEAT = AG_NFEAT + 1 }
57 if ag_has(text, n, "beast" as *u8) == 1 { AG_PLAN = 2; AG_NFEAT = AG_NFEAT + 1 }
58 if ag_has(text, n, "dragon" as *u8) == 1 { AG_PLAN = 2; AG_NFEAT = AG_NFEAT + 1 }
59 if ag_has(text, n, "human" as *u8) == 1 { AG_PLAN = 0; AG_NFEAT = AG_NFEAT + 1 }
60 if ag_has(text, n, "person" as *u8) == 1 { AG_PLAN = 0; AG_NFEAT = AG_NFEAT + 1 }
61 // ---- feature modifiers ----
62 if ag_has(text, n, "long ear" as *u8) == 1 { gen_set_earlen(175); AG_NFEAT = AG_NFEAT + 1 }
63 if ag_has(text, n, "short ear" as *u8) == 1 { gen_set_earlen(55); AG_NFEAT = AG_NFEAT + 1 }
64 if ag_has(text, n, "four arm" as *u8) == 1 { gen_set_armpairs(2); AG_NFEAT = AG_NFEAT + 1 }
65 if ag_has(text, n, "4 arm" as *u8) == 1 { gen_set_armpairs(2); AG_NFEAT = AG_NFEAT + 1 }
66 if ag_has(text, n, "two arm" as *u8) == 1 { gen_set_armpairs(1); AG_NFEAT = AG_NFEAT + 1 }
67 if ag_has(text, n, "2 arm" as *u8) == 1 { gen_set_armpairs(1); AG_NFEAT = AG_NFEAT + 1 }
68 if ag_has(text, n, "no horn" as *u8) == 1 { gen_set_horns(0); AG_NFEAT = AG_NFEAT + 1 } else {
69 if ag_has(text, n, "horn" as *u8) == 1 { gen_set_horns(1); AG_NFEAT = AG_NFEAT + 1 } }
70 if ag_has(text, n, "no tail" as *u8) == 1 { gen_set_tail(0); AG_NFEAT = AG_NFEAT + 1 } else {
71 if ag_has(text, n, "tail" as *u8) == 1 { gen_set_tail(1); AG_NFEAT = AG_NFEAT + 1 } }
72 // ---- content kind: creature if a plan was found; else try WORLD ----
73 if AG_PLAN >= 0 { AG_KIND = 1 }
74 if AG_KIND == 0 {
75 var isWorld: i64 = 0
76 if ag_has(text, n, "world" as *u8) == 1 { isWorld = 1 }
77 if ag_has(text, n, "land" as *u8) == 1 { isWorld = 1 }
78 if ag_has(text, n, "terrain" as *u8) == 1 { isWorld = 1 }
79 if ag_has(text, n, "landscape" as *u8) == 1 { isWorld = 1 }
80 if ag_has(text, n, "island" as *u8) == 1 { isWorld = 1 }
81 if ag_has(text, n, "mountain" as *u8) == 1 { isWorld = 1 }
82 if ag_has(text, n, "desert" as *u8) == 1 { isWorld = 1 }
83 if ag_has(text, n, "continent" as *u8) == 1 { isWorld = 1 }
84 if isWorld == 1 {
85 AG_KIND = 2
86 wp_init(7) // deterministic seed; character comes from the adjectives
87 AG_NFEAT = AG_NFEAT + 1
88 // ---- climate ----
89 if ag_has(text, n, "snow" as *u8) == 1 { wp_set_temp_bias(0-380); AG_NFEAT = AG_NFEAT + 1 }
90 if ag_has(text, n, "cold" as *u8) == 1 { wp_set_temp_bias(0-380); AG_NFEAT = AG_NFEAT + 1 }
91 if ag_has(text, n, "ice" as *u8) == 1 { wp_set_temp_bias(0-380); AG_NFEAT = AG_NFEAT + 1 }
92 if ag_has(text, n, "arctic" as *u8) == 1 { wp_set_temp_bias(0-420); AG_NFEAT = AG_NFEAT + 1 }
93 if ag_has(text, n, "frozen" as *u8) == 1 { wp_set_temp_bias(0-420); AG_NFEAT = AG_NFEAT + 1 }
94 if ag_has(text, n, "hot" as *u8) == 1 { wp_set_temp_bias(360); AG_NFEAT = AG_NFEAT + 1 }
95 if ag_has(text, n, "desert" as *u8) == 1 { wp_set_temp_bias(360); AG_NFEAT = AG_NFEAT + 1 }
96 if ag_has(text, n, "tropical" as *u8) == 1 { wp_set_temp_bias(300); AG_NFEAT = AG_NFEAT + 1 }
97 // ---- relief ----
98 if ag_has(text, n, "mountain" as *u8) == 1 { wp_set_mount_scale(K_MAGIC_2500); AG_NFEAT = AG_NFEAT + 1 }
99 if ag_has(text, n, "alpine" as *u8) == 1 { wp_set_mount_scale(K_MAGIC_2500); AG_NFEAT = AG_NFEAT + 1 }
100 if ag_has(text, n, "flat" as *u8) == 1 { wp_set_mount_scale(500); AG_NFEAT = AG_NFEAT + 1 }
101 if ag_has(text, n, "plain" as *u8) == 1 { wp_set_mount_scale(500); AG_NFEAT = AG_NFEAT + 1 }
102 // ---- land / sea ----
103 if ag_has(text, n, "island" as *u8) == 1 { wp_set_cont_bias(0-300); AG_NFEAT = AG_NFEAT + 1 }
104 if ag_has(text, n, "ocean" as *u8) == 1 { wp_set_cont_bias(0-300); AG_NFEAT = AG_NFEAT + 1 }
105 if ag_has(text, n, "sea" as *u8) == 1 { wp_set_cont_bias(0-240); AG_NFEAT = AG_NFEAT + 1 }
106 if ag_has(text, n, "continent" as *u8) == 1 { wp_set_cont_bias(300); AG_NFEAT = AG_NFEAT + 1 }
107 }
108 }
109 // ---- content type 3: GAME (difficulty design-table -> emit_arcade params) ----
110 if AG_KIND == 0 {
111 var isGame: i64 = 0
112 if ag_has(text, n, "game" as *u8) == 1 { isGame = 1 }
113 if ag_has(text, n, "arcade" as *u8) == 1 { isGame = 1 }
114 if ag_has(text, n, "collect" as *u8) == 1 { isGame = 1 }
115 if ag_has(text, n, "maze" as *u8) == 1 { isGame = 1 }
116 if ag_has(text, n, "dungeon" as *u8) == 1 { isGame = 1 }
117 if ag_has(text, n, "level" as *u8) == 1 { isGame = 1 }
118 if isGame == 1 {
119 AG_KIND = 3
120 AG_NFEAT = AG_NFEAT + 1
121 AG_GW = 12; AG_GH = 10; AG_NG = 7; AG_NH = 5; AG_SEED = K_MAGIC_12345 // NORMAL
122 if ag_has(text, n, "easy" as *u8) == 1 { AG_GW = 8; AG_GH = 8; AG_NG = 4; AG_NH = 2; AG_NFEAT = AG_NFEAT + 1 }
123 if ag_has(text, n, "hard" as *u8) == 1 { AG_GW = 16; AG_GH = 12; AG_NG = 10; AG_NH = 9; AG_NFEAT = AG_NFEAT + 1 }
124 if ag_has(text, n, "nightmare" as *u8) == 1 { AG_GW = 20; AG_GH = 14; AG_NG = 13; AG_NH = 14; AG_NFEAT = AG_NFEAT + 1 }
125 if ag_has(text, n, "brutal" as *u8) == 1 { AG_GW = 20; AG_GH = 14; AG_NG = 13; AG_NH = 14; AG_NFEAT = AG_NFEAT + 1 }
126 if ag_has(text, n, "big" as *u8) == 1 { AG_GW = AG_GW + 6; AG_GH = AG_GH + 4; AG_NFEAT = AG_NFEAT + 1 }
127 }
128 }
129 // ---- UNMET: requested capabilities we honestly cannot build (report, never fake) ----
130 if ag_has(text, n, "wing" as *u8) == 1 { AG_UNMET = AG_UNMET + 1 }
131 if ag_has(text, n, "fire" as *u8) == 1 { AG_UNMET = AG_UNMET + 1 }
132 if ag_has(text, n, "fly" as *u8) == 1 { AG_UNMET = AG_UNMET + 1 }
133 if ag_has(text, n, "magic" as *u8) == 1 { AG_UNMET = AG_UNMET + 1 }
134 if ag_has(text, n, "breathe" as *u8) == 1 { AG_UNMET = AG_UNMET + 1 }
135 if ag_has(text, n, "glow" as *u8) == 1 { AG_UNMET = AG_UNMET + 1 }
136 return AG_PLAN
137}
138// build the parsed creature. Returns part count, or 0 if no creature recognized (HONEST refusal -- no fake build).
139func ag_build() -> i64 {
140 if AG_PLAN < 0 { return 0 }
141 return genome_build(AG_PLAN)
142}
143func ag_plan() -> i64 { return AG_PLAN }
144func ag_kind() -> i64 { return AG_KIND } // 0 none/refused, 1 creature, 2 world, 3 game
145func ag_nfeat() -> i64 { return AG_NFEAT }
146func ag_unmet() -> i64 { return AG_UNMET }
147func ag_game_gw() -> i64 { return AG_GW }
148func ag_game_gh() -> i64 { return AG_GH }
149func ag_game_ng() -> i64 { return AG_NG }
150func ag_game_nh() -> i64 { return AG_NH }
151func ag_game_seed() -> i64 { return AG_SEED }