interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / agent-archive / main.om

191 lines · 3878 bytes Raw Blame History
1note agent-archive CLI: reads TSV records (ts_ms\tagent\trole\tpriv\ttext) from stdin,
2note builds SHA-256 hash-chained archive, verifies chain integrity, and exports public redacted JSONL.
3note Compose: si/directives/om2.om + si/agent-archive/lib.om + si/agent-archive/main.om
4
5text aa_cli_err_parse "agent-archive: malformed TSV record\n"
6text aa_cli_err_chain "agent-archive: archive append or chain verification failed\n"
7
8fn aa_write_all fd int buf view uchar * n ulong to bool
9done = ulong 0
10while lt done n bound 65536
11k = write fd buf done sub n done
12if le k 0
13ret false
14end
15done = add done ulong k
16end
17ret true
18end
19
20fn aa_read_stdin dst edit uchar * to long
21got = ulong 0
22cap = len dst
23while lt got cap bound 65536
24k = read 0 dst got sub cap got
25if lt k 0
26ret -1
27end
28if eq k 0
29break
30end
31got = add got ulong k
32end
33ret long got
34end
35
36fn aa_trim_eol line view uchar * to ulong
37n = len line
38if gt n 0
39if eq get line sub n 1 10
40n = sub n 1
41end
42end
43if gt n 0
44if eq get line sub n 1 13
45n = sub n 1
46end
47end
48ret n
49end
50
51fn aa_parse_tsv_rec line view uchar * rec edit AaChainEntry to long
52n = aa_trim_eol line
53tabs = new ulong 5 0
54tc = ulong 0
55i = ulong 0
56while lt i n bound 16384
57if eq get line i 9
58if lt tc 5
59put tabs tc i
60end
61tc = add tc 1
62end
63i = add i 1
64end
65if ne tc 4
66ret -1
67end
68v = aa_parse_u64 part line 0 get tabs 0
69if lt v 0
70ret -1
71end
72put rec ts_ms ulong v
73v = aa_parse_agent part line add get tabs 0 1 sub sub get tabs 1 get tabs 0 1
74if lt v 0
75ret -1
76end
77put rec agent_id ulong v
78v = aa_parse_role part line add get tabs 1 1 sub sub get tabs 2 get tabs 1 1
79if lt v 0
80ret -1
81end
82put rec role_id ulong v
83v = aa_parse_u64 part line add get tabs 2 1 sub sub get tabs 3 get tabs 2 1
84if lt v 0
85ret -1
86end
87put rec is_priv ulong v
88ret long add get tabs 3 1
89end
90
91fn aa_cli_stage_line line view uchar * src_pos ulong meta edit AaArchiveMeta rec edit AaChainEntry text_buf edit uchar 16384 to int
92toff_rel = aa_parse_tsv_rec line rec
93if lt toff_rel 0
94ret -10
95end
96eff = aa_trim_eol line
97if lt eff ulong toff_rel
98ret -10
99end
100put rec src_pos src_pos
101ret aa_stage_record meta rec part line ulong toff_rel sub eff ulong toff_rel text_buf
102end
103
104fn aa_cli_export_all cnt ulong entries view ulong 288 hashes view uchar 4096 text_buf view uchar 16384 to int
105rec = new AaChainEntry 0 0 0 0 0 0 0 0 0
106outln = new uchar 2048 0
107i = ulong 0
108while lt i cnt bound 64
109aa_load_entry entries i rec
110en = aa_export_jsonl rec hashes text_buf false outln
111if gt en 0
112if not aa_write_all 1 outln ulong en
113ret 1
114end
115end
116i = add i 1
117end
118ret 0
119end
120
121fn aa_cli_ingest_all inbuf view uchar 16384 total ulong meta edit AaArchiveMeta entries edit ulong 288 hashes edit uchar 4096 text_buf edit uchar 16384 to int
122rec = new AaChainEntry 0 0 0 0 0 0 0 0 0
123cur = ulong 0
124while lt cur total bound 16384
125ls = cur
126while lt cur total bound 16384
127if eq get inbuf cur 10
128cur = add cur 1
129break
130end
131cur = add cur 1
132end
133ll = sub cur ls
134if eq ll 0
135continue
136end
137if eq get inbuf ls 10
138continue
139end
140st = aa_cli_stage_line part inbuf ls ll ls meta rec text_buf
141if ne st 0
142ret st
143end
144idx = get meta cnt
145cm = aa_commit_record meta rec entries
146if lt cm 0
147ret cm
148end
149if eq cm 0
150if not aa_link_record idx rec hashes text_buf
151ret -4
152end
153end
154end
155ret 0
156end
157
158fn main to int
159inbuf = new uchar 16384 0
160nread = aa_read_stdin inbuf
161if lt nread 0
162ret 1
163end
164meta = new AaArchiveMeta 0 0 0
165entries = new ulong 288 0
166hashes = new uchar 4096 0
167text_buf = new uchar 16384 0
168rc = aa_cli_ingest_all inbuf ulong nread meta entries hashes text_buf
169if eq rc -10
170w = aa_write_all 2 aa_cli_err_parse len aa_cli_err_parse
171if not w
172ret 2
173end
174ret 1
175end
176if ne rc 0
177w = aa_write_all 2 aa_cli_err_chain len aa_cli_err_chain
178if not w
179ret 2
180end
181ret 1
182end
183if ne aa_verify_chain get meta cnt entries hashes text_buf 0
184w = aa_write_all 2 aa_cli_err_chain len aa_cli_err_chain
185if not w
186ret 2
187end
188ret 1
189end
190ret aa_cli_export_all get meta cnt entries hashes text_buf
191end