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 / protocol / synapse / map / src / 70-new.om

460 lines · 8984 bytes Raw Blame History
1note ======== new: scaffold a connected child repo ========
2note Files are created with O_EXCL (an existing file is never replaced) under DIR, which must not hold a
3note .crumb yet. The crumb is then checked by `crumb validate DIR`, run as
4note /usr/bin/env HOME=.. PATH=.. crumb validate DIR (execprog gives an empty environment, no PATH search).
5
6global gnf ulong 32
7
8const SNPO ulong 30
9const SNPL ulong 31
10const SNNO ulong 32
11const SNNL ulong 33
12const SNUO ulong 34
13const SNUL ulong 35
14const SNLO ulong 36
15const SNLL ulong 37
16const SNDI ulong 38
17const SNFI ulong 39
18
19text tfcrumb ".crumb"
20text tfgoals ".goals.json"
21text tfreadme "README.md"
22text tfagents "AGENTS.md"
23text tfspin "synapse.pin"
24text tfppr "PARENT-PR.md"
25text tsynapse "synapse"
26text tdeflay "tool"
27text tc1 "{\"schema_version\":\"1.0.0\",\"name\":"
28text tc2 ",\"extensions\":{\"map\":{\"parent\":"
29text tc3 ",\"parent_status\":\"CONFIRMED\"}}}\n"
30text tg1 "{\"schema\":\"goals/v1\",\"project\":"
31text tg2 ",\"goals\":[{\"id\":\"g1\",\"title\":"
32text tg3 ",\"status\":\"pending\"}]}\n"
33text tr1 "Child of ["
34text tr2 "](https://github.com/"
35text tr3 ") at `"
36text tr4 "`.\n\n# "
37text tr5 "\n\n## Connected repos\n\n- Parent: ["
38text tr6 ")\n"
39text ta1 "# "
40text ta2 ": agent brief\n\nPurpose: "
41text ta3 "\nParent: "
42text ta4 "\n\nBefore starting work here, run `synapse-map where \"<task>\"` to confirm this is the right repo, and\n`synapse-map check` after changing this repo's .crumb. New standalone components get their own\nrepo via `synapse-map new`, connected to a parent.\n"
43text tp1 "Add this line under \"Connected repos\" in the README.md of "
44text tp2 ":\n\n- ["
45text tp3 "): "
46text tnexist "synapse-map: refusing to scaffold: .crumb already exists in "
47text tnwrite "synapse-map: cannot create "
48text tenv "/usr/bin/env"
49text tcrumbc "crumb"
50text tvalid "validate"
51text tdefpath "PATH=/usr/local/bin:/usr/bin:/bin"
52text tdefhome "HOME=/"
53text tkdir "dir"
54text tkfiles "files"
55text tkcv "crumb_validate"
56text tpass "PASS"
57text tfail "FAIL"
58text tnotrun "NOT_RUN"
59text tunkref "unknown"
60
61note ---- new --publish declarations (functions in 75-publish.om) ----
62
63global garv ulong 128
64
65const SPKN ulong 40
66const SPRO ulong 41
67const SPRL ulong 42
68const SCLO ulong 43
69const SCLL ulong 44
70const SBRO ulong 45
71const SBRL ulong 46
72const SCHO ulong 47
73const SCHL ulong 48
74const SLNO ulong 49
75const SLNL ulong 50
76const SDRY ulong 51
77const SFNO ulong 52
78const SFNL ulong 53
79
80text tfpub "--publish"
81text tfdry "--dry-run"
82text tswnew "--publish --dry-run"
83text tpathsfx "/.local/bin:/usr/bin:/bin"
84text tpathk "PATH="
85text tgit "git"
86text tgh "gh"
87text tdashc "-C"
88text tdashcc "-c"
89text tuname "user.name=Drake Stapleton"
90text tumail "user.email=aien@aienos.com"
91text tinit "init"
92text tdashb "-b"
93text tmain "main"
94text tadd "add"
95text tdasha "-A"
96text tcommit "commit"
97text tdashs "-s"
98text tdashm "-m"
99text tmsg1 "Scaffold "
100text tmsg1b " (synapse-map new)"
101text tmsg2 "docs: connect "
102text trepo "repo"
103text tcreate "create"
104text tpublic "--public"
105text tdescr "--description"
106text tsource "--source"
107text tpush "--push"
108text tclone "clone"
109text tghurl "https://github.com/"
110text tparsfx ".parent"
111text tchkout "checkout"
112text tconn "connected/"
113text treadme "README.md"
114text torigin "origin"
115text tdashu "-u"
116text tpr "pr"
117text tdraft "--draft"
118text tdashr "-R"
119text thead "--head"
120text ttitle "--title"
121text tconnt "Connect "
122text tbodyf "--body-file"
123text tsppr "/PARENT-PR.md"
124text tkargv "argv"
125text tkedit "edit"
126text tkline "line"
127text tkstep "step"
128text tkstat "status"
129text tkpub "published"
130text tkbr "branch"
131text tconnh "## Connected repos"
132text tconnhb "\n## Connected repos\n\n"
133text tsreadme "/README.md"
134text tpubdry "synapse-map: --dry-run needs --publish\n"
135
136fn sm_ndir t view uchar * to void
137sm_pclr
138sm_parg get gst SNDI
139sm_pc 47
140sm_ptx t
141end
142
143note sm_nput: write gout to DIR/t with O_EXCL and record the name; any failure exits 70 (73 on EEXIST)
144fn sm_nput t view uchar * to void
145sm_ndir t
146w = sm_wrnew
147if lt w 0
148sm_err tnwrite
149k = write 2 gpath 0 get gst SPLEN
150sm_errnl
151sm_die 70
152end
153n = get gst SNFI
154put gnf n sm_pt t
155put gnf add n 16 len t
156put gst SNFI add n 1
157end
158
159fn sm_nq k ulong to void
160sm_oq get gst k get gst add k 1
161end
162
163fn sm_nraw k ulong to void
164sm_op get gst k get gst add k 1
165end
166
167note sm_nrepo: the owner/repo part of the parent (before '@')
168fn sm_nrepo to void
169po = get gst SNPO
170sm_op po sm_pfind po get gst SNPL 64
171end
172
173fn sm_nref to void
174po = get gst SNPO
175pn = get gst SNPL
176q = sm_pfind po pn 64
177if lt q pn
178sm_op add po add q 1 sub sub pn q 1
179end
180end
181
182fn sm_nfiles to void
183sm_ot tc1
184sm_nq SNNO
185sm_okc tkpurp
186sm_nq SNUO
187sm_okc tklay
188sm_nq SNLO
189sm_ot tc2
190sm_nq SNPO
191sm_ot tc3
192sm_nput tfcrumb
193sm_ot tg1
194sm_nq SNNO
195sm_ot tg2
196sm_nq SNUO
197sm_ot tg3
198sm_nput tfgoals
199sm_ot tr1
200sm_nrepo
201sm_ot tr2
202sm_nrepo
203sm_ot tr3
204sm_nref
205sm_ot tr4
206sm_nraw SNNO
207sm_ob 10
208sm_ob 10
209sm_nraw SNUO
210sm_ot tr5
211sm_nrepo
212sm_ot tr2
213sm_nrepo
214sm_ot tr6
215sm_nput tfreadme
216sm_ot ta1
217sm_nraw SNNO
218sm_ot ta2
219sm_nraw SNUO
220sm_ot ta3
221sm_nraw SNPO
222sm_ot ta4
223sm_nput tfagents
224po = get gst SNPO
225q = sm_pfind po get gst SNPL 64
226s = sm_pfind po q 47
227if lt s q
228if sm_pteq add po add s 1 sub sub q s 1 tsynapse
229sm_nraw SNPO
230sm_ob 10
231sm_nput tfspin
232end
233end
234sm_ot tp1
235sm_nrepo
236sm_ot tp2
237sm_nraw SNNO
238sm_ot tr2
239if lt s q
240sm_op po add s 1
241end
242sm_nraw SNNO
243sm_ot tp3
244sm_nraw SNUO
245sm_ob 10
246sm_nput tfppr
247end
248
249note sm_pkadd: append one record (pool slice) to the packed list in gpk at offset p; the slice is also
250note kept in garv for --dry-run printing; returns the new offset
251fn sm_pkadd p ulong o ulong n ulong to ulong
252k = get gst SPKN
253if or gt add add p n 2 len gpk ge k 64
254put gst SOVF 4
255ret p
256end
257put gpk p uchar and n 255
258put gpk add p 1 uchar shr n 8
259for i ulong n
260put gpk add add p 2 i get gpool add o i
261end
262put gpk 0 uchar add get gpk 0 1
263put garv mul k 2 o
264put garv add mul k 2 1 n
265put gst SPKN add k 1
266ret add add p 2 n
267end
268
269fn sm_pktx p ulong t view uchar * to ulong
270o = sm_pt t
271ret sm_pkadd p o len t
272end
273
274note sm_nvalid: 0 PASS, 1 FAIL, 2 NOT_RUN (fork, exec or wait failed, or crumb missing: exit 127)
275fn sm_nvalid to ulong
276put gpk 0 0
277put gpk 1 0
278put gst SPKN 0
279p = sm_pktx 2 tenv
280h = sm_envkv thomee
281if eq h SNONE
282p = sm_pktx p tdefhome
283else
284p = sm_pkadd p h get gst SSLEN
285end
286e = sm_envkv tpathe
287if eq e SNONE
288p = sm_pktx p tdefpath
289else
290p = sm_pkadd p e get gst SSLEN
291end
292p = sm_pktx p tcrumbc
293p = sm_pktx p tvalid
294d = sm_apool get gst SNDI
295p = sm_pkadd p d get gst SSLEN
296if ne get gst SOVF 0
297put gst SOVF 0
298ret 2
299end
300c = sm_pkrun p
301if eq c 0
302ret 0
303end
304if or eq c 127 ge c 256
305ret 2
306end
307ret 1
308end
309
310note sm_nreport: print the new-repo JSON report for directory argument di; exit 1 when validation failed
311fn sm_nreport di ulong to void
312v = sm_nvalid
313sm_ob 123
314sm_ok tkok
315sm_obool ne v 1
316sm_okc tkdir
317dq = sm_apool di
318sm_oq dq get gst SSLEN
319sm_okc tkfiles
320sm_ob 91
321for i ulong get gst SNFI
322if gt i 0
323sm_ob 44
324end
325fo = get gnf i
326fl = get gnf add i 16
327sm_oq fo fl
328end
329sm_ob 93
330sm_okc tkcv
331if eq v 0
332sm_otq tpass
333end
334if eq v 1
335sm_otq tfail
336end
337if eq v 2
338sm_otq tnotrun
339end
340sm_ob 125
341sm_ob 10
342if eq v 1
343sm_die 1
344end
345end
346
347fn sm_cnew to int
348np = sm_argscan tvfnew tswnew
349dry = sm_aflag tfdry
350pub = sm_aflag tfpub
351if and gt dry 0 eq pub 0
352sm_err tpubdry
353sm_die 64
354end
355put gst SDRY dry
356if ne np 1
357sm_usage
358end
359ni = get gst SSLEN
360pai = sm_aval tfparent
361ui = sm_aval tfpurp
362di = sm_aval tfdir
363if or eq pai 0 or eq ui 0 eq di 0
364sm_usage
365end
366if not sm_nameok ni
367sm_usage
368end
369put gst SNDI di
370o = sm_apool ni
371put gst SNNO o
372put gst SNNL get gst SSLEN
373o = sm_apool ui
374put gst SNUO o
375put gst SNUL get gst SSLEN
376li = sm_aval tflayer
377if gt li 0
378o = sm_apool li
379put gst SNLL get gst SSLEN
380else
381o = sm_pt tdeflay
382put gst SNLL len tdeflay
383end
384put gst SNLO o
385sm_home
386sm_nparent pai
387sm_ndir tfcrumb
388if eq faccess gpath 0 get gst SPLEN 0 0
389sm_err tnexist
390k = write 2 gpath 0 get gst SPLEN
391sm_errnl
392sm_die 64
393end
394sm_pclr
395sm_parg di
396sm_mkdirp
397put gst SNFI 0
398sm_nfiles
399sm_nreport di
400if gt pub 0
401sm_publish
402end
403ret 0
404end
405
406note sm_nparent: normalise --parent to owner/repo@ref; without @ref the parent's default branch from the
407note map (when a map exists) is used, else @unknown
408fn sm_nparent pai ulong to void
409a = sm_apool pai
410an = get gst SSLEN
411if or eq an 0 eq get gab sm_ao pai 64
412sm_usage
413end
414o = sm_pfull a an
415n = get gst SSLEN
416if lt sm_pfind o n 64 n
417put gst SNPO o
418put gst SNPL n
419ret
420end
421sm_phome tmapf
422x = sm_rdfile
423if ge x 0
424y = sm_jload 3 0
425end
426r = sm_find o n
427s = get gst SPOOL
428z = sm_pcp o n
429sm_pb 64
430if ne r SNONE
431if gt sm_fl r FDEF 0
432z = sm_pcp sm_fo r FDEF sm_fl r FDEF
433else
434z = sm_pt tunkref
435end
436else
437z = sm_pt tunkref
438end
439put gst SNPO s
440put gst SNPL sub get gst SPOOL s
441end
442
443note sm_nameok: a repo name is 1..100 bytes of letters, digits, '.', '_' and '-', not starting with '.'
444fn sm_nameok i ulong to bool
445o = sm_ao i
446n = sm_al i
447if or eq n 0 gt n 100
448ret false
449end
450if eq get gab o 46
451ret false
452end
453for j ulong n
454c = sm_lc get gab add o j
455if not or sm_isword c or eq c 46 or eq c 95 eq c 45
456ret false
457end
458end
459ret true
460end