code wiki / _hdl_build / nx_crew_scribe.nx
nx_crew_scribe.nx source
↩ module page · 81 lines · 3895 B
1// nx_crew_scribe.nx -- how the areas COMMUNICATE + a team member DOCUMENTS it. Every handoff
2// between organs is a structured DELIVERABLE with a fixed, unambiguous schema (clear symbols,
3// like 1+1=2 -- each field has one meaning), and the SCRIBE (the Archivist organ) writes each
4// one to a PARSEABLE log so the team can parse its own history to improve clarity + efficiency.
5//
6// The deliverable schema (one line, key=value, machine-parseable):
7// CREWMSG seq=<n> from=<organ> to=<organ> kind=<kind> verdict=<verdict> subject=<sym> detail=<text>
8// from/to identify the AREAS; kind = what is being handed over; verdict = the clear result;
9// subject = the thing it is about; detail = human context. Areas only TALK via this protocol.
10// license_tier: ORIGINAL
11
12import "nx_syscalls.nx"
13const ORG_MAGIC_1024: i64 = 1024
14
15// the AREAS (organs)
16const ORG_ENGINEER: i64 = 1
17const ORG_DOCTOR: i64 = 2
18const ORG_BUILDER: i64 = 3
19const ORG_CONDUCTOR: i64 = 4
20const ORG_COUNCIL: i64 = 5
21const ORG_SCRIBE: i64 = 6
22// deliverable KINDS (what is handed over)
23const K_DETECT: i64 = 1
24const K_HEAL: i64 = 2
25const K_BUILD: i64 = 3
26const K_VERIFY: i64 = 4
27const K_ADMIT: i64 = 5
28const K_ESCALATE: i64 = 6
29// VERDICTS (the clear, unambiguous result)
30const V_OK: i64 = 1
31const V_BAD: i64 = 2
32const V_HEALED: i64 = 3
33const V_UNFIXABLE:i64 = 4
34const V_NEEDBUILD:i64 = 5
35
36func sc_org(o: i64) -> *u8 {
37 if o == ORG_ENGINEER { return "engineer" as *u8 }
38 if o == ORG_DOCTOR { return "doctor" as *u8 }
39 if o == ORG_BUILDER { return "builder" as *u8 }
40 if o == ORG_CONDUCTOR { return "conductor" as *u8 }
41 if o == ORG_COUNCIL { return "council" as *u8 }
42 return "scribe" as *u8
43}
44func sc_kind(k: i64) -> *u8 {
45 if k == K_DETECT { return "detect" as *u8 }
46 if k == K_HEAL { return "heal" as *u8 }
47 if k == K_BUILD { return "build" as *u8 }
48 if k == K_VERIFY { return "verify" as *u8 }
49 if k == K_ADMIT { return "admit" as *u8 }
50 return "escalate" as *u8
51}
52func sc_verdict(v: i64) -> *u8 {
53 if v == V_OK { return "OK" as *u8 }
54 if v == V_BAD { return "BAD" as *u8 }
55 if v == V_HEALED { return "HEALED" as *u8 }
56 if v == V_UNFIXABLE { return "UNFIXABLE" as *u8 }
57 return "NEEDBUILD" as *u8
58}
59
60func sc_app(buf: *u8, s: *u8) -> i64 { var oi: i64 = 0; while buf[oi] != (0 as u8) { oi = oi + 1 } var j: i64 = 0; while s[j] != (0 as u8) { buf[oi] = s[j]; oi = oi + 1; j = j + 1 } buf[oi] = 0 as u8; return 0 }
61func sc_appn(buf: *u8, v: i64) -> i64 { var oi: i64 = 0; while buf[oi] != (0 as u8) { oi = oi + 1 } let t: *u8 = sys_mmap(28); var m: i64=v; var k: i64=0; if m==0 {t[0]=48;k=1} while m>0 {t[k]=48+(m%10); m=m/10; k=k+1} var z: i64=0; while z<k {buf[oi]=t[k-1-z]; oi=oi+1; z=z+1} buf[oi]=0 as u8; return 0 }
62func sc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
63
64// the SCRIBE documents one deliverable handed between two areas, parseably. seq is a caller-
65// held counter (a memory slot) so the ordering of the conversation is recoverable.
66func scribe(seq: *i64, from: i64, to: i64, kind: i64, verdict: i64, subject: *u8, detail: *u8) -> i64 {
67 seq[0] = seq[0] + 1
68 let buf: *u8 = sys_mmap(ORG_MAGIC_1024); buf[0] = 0 as u8
69 sc_app(buf, "CREWMSG seq=" as *u8); sc_appn(buf, seq[0])
70 sc_app(buf, " from=" as *u8); sc_app(buf, sc_org(from))
71 sc_app(buf, " to=" as *u8); sc_app(buf, sc_org(to))
72 sc_app(buf, " kind=" as *u8); sc_app(buf, sc_kind(kind))
73 sc_app(buf, " verdict=" as *u8); sc_app(buf, sc_verdict(verdict))
74 sc_app(buf, " subject=" as *u8); sc_app(buf, subject)
75 sc_app(buf, " detail=" as *u8); sc_app(buf, detail); sc_app(buf, "\n" as *u8)
76 let ln: i64 = sc_slen(buf)
77 sys_write(1, buf, ln)
78 let lf: i64 = sys_openat_append("/tmp/nishi_crew.log" as *u8, 0x1a4)
79 if lf >= 0 { sys_write(lf, buf, ln); sys_close(lf) }
80 return 0
81}