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