@oalo-ai/cli 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/man/oalo.1 CHANGED
@@ -1,4 +1,4 @@
1
- .TH OALO 1 "" "oalo 0.1.0" "OALO CLI"
1
+ .TH OALO 1 "" "oalo 0.3.0" "OALO CLI"
2
2
  .SH NAME
3
3
  oalo \- wire a local app into your Oalo workspace
4
4
  .SH SYNOPSIS
@@ -368,25 +368,51 @@ Each one says what was seen: which process, how many restarts, a memory kill wit
368
368
  .PP
369
369
  Exit codes: 0 no open incident; 1 an incident is open, or the request failed; 2 bad arguments or no CLI token.
370
370
  .SS db
371
- All of an env's data as plain SQL (every app's own tables and the Oalo models), to keep a copy or take it anywhere.
371
+ All of an env's data as plain SQL (every app's own tables and the Oalo models), to keep a copy or take it anywhere. Or load an existing Postgres database into an env.
372
372
  .PP
373
373
  \fBoalo db dump [\-\-env dev|prod] [\-\-out <file.sql>] [\-\-force]\fR
374
374
  .br
375
+ \fBoalo db restore <file> \-\-env dev|prod [\-\-schema <name>] [\-\-check] [\-\-yes]\fR
376
+ .br
377
+ \fBoalo db restore \-\-from\-env <VAR> \-\-env dev|prod [\-\-schema <name>] [\-\-check] [\-\-yes]\fR
378
+ .br
375
379
  .TP
376
380
  \fB\-\-env dev|prod\fR
377
- Which env's data. Default prod.
381
+ dump: which env's data. Default prod. restore: which env the data goes into, always on the command line.
378
382
  .TP
379
383
  \fB\-\-out <file.sql>\fR
380
384
  Where to write it. Default <workspace>\-<env>\-<date>.sql here.
381
385
  .TP
382
386
  \fB\-\-force\fR
383
387
  Replace the file if it exists.
388
+ .TP
389
+ \fB\-\-from\-env <VAR>\fR
390
+ restore: copy from a running database instead of a file. VAR is the environment variable that holds its postgres:// or postgresql:// URL. Only its host is ever shown.
391
+ .TP
392
+ \fB\-\-schema <name>\fR
393
+ restore: the source schema to load. Default public, or the only one when there's just one.
394
+ .TP
395
+ \fB\-\-check\fR
396
+ restore: do everything but the write, and report what would happen. Nothing is written, so it never asks.
397
+ .TP
398
+ \fB\-\-yes\fR
399
+ restore: go ahead with prod without asking. Needed for prod when there's no terminal to ask at.
384
400
  .IP \(bu 2
385
401
  Workspace admins only: it holds every member's data. Restore it into any Postgres with psql \-f.
386
402
  .IP \(bu 2
387
403
  Your code is in git (oalo deploy \-\-pull); this is the data. Together they are everything you need to run your apps elsewhere.
404
+ .IP \(bu 2
405
+ restore loads a dump file made by pg_dump (like Heroku's latest.dump), up to 10 GB, or copies from a database URL. Admins only, and one restore at a time per Base.
406
+ .IP \(bu 2
407
+ The tables land in the env's schema, owned by the app's database login, so its Procfile \fBrelease:\fR migrations can alter them. Your app reads them at DATABASE_URL.
408
+ .IP \(bu 2
409
+ It's refused if a table name already exists there, and the names are listed. A failed restore leaves the env as it was.
410
+ .IP \(bu 2
411
+ The URL is never a flag value, since that stays in your shell history. Put it in a variable and pass \-\-from\-env VAR.
412
+ .IP \(bu 2
413
+ Run it with \-\-check first. prod asks before it writes; without a terminal it needs \-\-yes. Stop writes to the old database before the copy: writes made after it starts are lost.
388
414
  .PP
389
- Exit codes: 0 a whole dump was written; 1 refused, unreachable, or cut off (the partial file is removed); 2 bad arguments, the file exists, or no CLI token.
415
+ Exit codes: 0 a whole dump was written, or the restore (or check) passed; 1 refused, unreachable, cut off (a partial dump is removed), or the restore failed or was declined; 2 bad arguments, the file exists or is missing, or no CLI token.
390
416
  .SS metrics
391
417
  A number from the workspace's data: count, sum or average over a model's rows, events or contacts, grouped or over time.
392
418
  .PP
@@ -911,6 +937,41 @@ How a server app starts: its Procfile (\fBweb:\fR, workers, \fBrelease:\fR), els
911
937
  Admins and members with Developer access only. Progress streams while it runs.
912
938
  .PP
913
939
  Exit codes: 0 deployed; 1 refused or failed; 2 bad arguments, no CLI token, or not in a git repo.
940
+ .SS migrate
941
+ Move an app from Heroku, Railway, Render, Fly.io or Primcloud: its Procfile, sizes, health path and variables, worked out from its files and that platform's CLI.
942
+ .PP
943
+ \fBoalo migrate <heroku|railway|render|fly|primcloud> [\-\-from\-app <name>] [\-\-env\-file <file>] [\-\-json]\fR
944
+ .br
945
+ \fBoalo migrate <platform> \-\-apply [\-\-app <slug>]\fR
946
+ .br
947
+ .TP
948
+ \fB\-\-from\-app <name>\fR
949
+ The app or service on the old platform (a Heroku or Fly app, a Railway or Render service). Default: what that platform's CLI is linked to here, or fly.toml's app.
950
+ .TP
951
+ \fB\-\-env\-file <file>\fR
952
+ More variables, from a .env file (NAME=value lines). They win over what the platform's CLI reported. For Primcloud, and for Fly secrets, which can't be read back.
953
+ .TP
954
+ \fB\-\-apply\fR
955
+ Write the Procfile and .oalo/app.json (never over an existing Procfile; app.json only gains keys it lacks), and set the variables on the app's prod env. Without it, nothing changes.
956
+ .TP
957
+ \fB\-\-no\-cli\fR
958
+ Don't run the old platform's CLI; read only the files here and \-\-env\-file.
959
+ .TP
960
+ \fB\-\-app <slug>\fR
961
+ The Oalo app the variables go to. Default: the app this folder is linked to (oalo deploy \-\-new links it).
962
+ .TP
963
+ \fB\-\-json\fR
964
+ The plan as JSON: names only, never a value.
965
+ .IP \(bu 2
966
+ Run it in the app's repo. It reads fly.toml, railway.json or railway.toml, render.yaml, app.json and the Procfile, and asks the platform's CLI for variables (heroku, railway), secret names (fly) and dyno sizes (heroku) when it's installed and signed in.
967
+ .IP \(bu 2
968
+ Variables: PORT and each platform's own (HEROKU_*, RAILWAY_*, RENDER_*, FLY_*) are left out, and DATABASE_URL becomes EXTERNAL_DATABASE_URL, since DATABASE_URL on Oalo is the Base's own Postgres. Values are never printed or written to a file; \-\-apply sends them to prod without restarting the app.
969
+ .IP \(bu 2
970
+ It says what doesn't carry over: cron jobs, volumes and disks, private addresses (*.railway.internal, *.flycast), extra replicas, build commands, an Aptfile, a VM bigger than large.
971
+ .IP \(bu 2
972
+ The order: oalo migrate <platform> (read the plan), \-\-apply, commit, oalo deploy \-\-new, oalo migrate <platform> \-\-apply again (now the app exists, it sets the variables), then the data (oalo db restore) and oalo deploy \-\-env prod. \fBoalo docs migrating\-from\-<platform>\fR walks through it.
973
+ .PP
974
+ Exit codes: 0 the plan was shown, or applied; 1 a config file couldn't be read, or the variables couldn't be set; 2 bad arguments, an unknown platform, or no CLI token.
914
975
  .SS env
915
976
  An app's environment variables on Oalo (API keys, settings), per env: list, set, unset, rotate\-token.
916
977
  .PP
@@ -1298,6 +1359,93 @@ Reads OALO_URL and OALO_CLI_TOKEN, or falls back to what \fBoalo link \-\-cli\-t
1298
1359
  Needs a CLI token.
1299
1360
  .PP
1300
1361
  Exit codes: 0 stopped cleanly; 1 no workspace or CLI token.
1362
+ .SS coord
1363
+ Several agents on one codebase: a shared task board, a worktree per task, a merge queue. First run: \fBoalo coord install\fR.
1364
+ .PP
1365
+ \fBoalo coord install [\-\-force] [\-\-json]\fR
1366
+ .br
1367
+ \fBoalo coord init [\-\-main <branch>] [\-\-test\-cmd <cmd>] [\-\-merge auto|manual] [\-\-signal\-review]\fR
1368
+ .br
1369
+ \fBoalo coord hooks install [\-\-claude] [\-\-opencode]\fR
1370
+ .br
1371
+ \fBoalo coord mcp\fR
1372
+ .br
1373
+ \fBoalo coord board [\-\-json]\fR
1374
+ .br
1375
+ \fBoalo coord events [\-\-follow] [\-\-since <id>] [\-\-json]\fR
1376
+ .br
1377
+ \fBoalo coord files [\-\-json] [\-\-main <branch>]\fR
1378
+ .br
1379
+ \fBoalo coord view [\-\-port <n>] [\-\-main <branch>] [\-\-no\-open]\fR
1380
+ .br
1381
+ \fBoalo coord claim <task>\fR
1382
+ .br
1383
+ \fBoalo coord merge [\-\-all]\fR
1384
+ .br
1385
+ \fBoalo coord approve plan [\-\-yes] | merge <task> | signal <task> <milestone> | proposal <id> [\-\-note <text>]\fR
1386
+ .br
1387
+ \fBoalo coord reject proposal <id> [\-\-note <text>]\fR
1388
+ .br
1389
+ \fBoalo coord hook <pre\-tool|stop|subagent\-stop|check\-write|check\-stop|check\-command>\fR
1390
+ .br
1391
+ .TP
1392
+ \fB\-\-force\fR
1393
+ install: download again even if this version is installed.
1394
+ .TP
1395
+ \fB\-\-main <branch>\fR
1396
+ init: branch the merge queue integrates into. Default: current branch.
1397
+ .TP
1398
+ \fB\-\-test\-cmd <cmd>\fR
1399
+ init: merge\-gate test command. Default: detected (mix test, npm test, ...).
1400
+ .TP
1401
+ \fB\-\-merge auto|manual\fR
1402
+ init: manual holds each merge for \fBapprove merge\fR.
1403
+ .TP
1404
+ \fB\-\-signal\-review\fR
1405
+ init: milestones unblock dependents only after \fBapprove signal\fR.
1406
+ .TP
1407
+ \fB\-\-yes\fR
1408
+ approve plan: skip the confirmation after the plan is shown.
1409
+ .TP
1410
+ \fB\-\-note <text>\fR
1411
+ approve/reject proposal: a note the worker sees with the decision.
1412
+ .TP
1413
+ \fB\-\-json\fR
1414
+ install/board/events/files: machine\-readable output.
1415
+ .TP
1416
+ \fB\-\-follow\fR
1417
+ events: keep streaming.
1418
+ .TP
1419
+ \fB\-\-all\fR
1420
+ merge: keep merging until the queue is idle or blocked.
1421
+ .IP \(bu 2
1422
+ Coord lets several coding agent sessions (Claude Code, OpenCode, Codex, any MCP client) work on one git repo at once. It runs on your machine; the board is .oalo/coord.db in the repo. No Oalo workspace or sign\-in is needed. Full guide: https://oalo.ai/docs/several\-agents\-one\-repo (or \fBoalo docs several\-agents\-one\-repo\fR when signed in).
1423
+ .IP \(bu 2
1424
+ Setup, once per machine: \fBoalo coord install\fR downloads coord for it (about 25 MB on macOS, 37 MB on Linux, checked against this package's checksum). Once per repo: \fBoalo coord init\fR, then \fBoalo coord hooks install\fR, then commit .oalo/coord.json, .gitignore, .claude/settings.json, .mcp.json, opencode.json and .opencode/. .claude/settings.local.json holds this machine's worktree folder and stays out of git.
1425
+ .IP \(bu 2
1426
+ Coord never starts agents. The person opens the sessions, or a manager starts workers as its harness's own subagents. Every session opened in the repo, or in a task's worktree, gets the board's tools through the \fBoalo\-coord\fR MCP server that hooks install registers; the server finds the one board from any worktree. The board also gives each session a short orientation; the person tells it its role. Manager: "You're the oalo coord manager for this repo. Call manager_guide, then plan: <goal>". Worker: "You're an oalo coord worker. Call task_next and follow the brief."
1427
+ .IP \(bu 2
1428
+ Manager: reads manager_guide (the full playbook), then drafts tasks with task_create (title, spec, acceptance criteria, writes: the globs it may change, provides: milestones it will signal, depends_on), then calls plan_submit. Nothing runs until the person approves. Then it handles the inbox (inbox, ack, answer, decide), reviews reports (task_detail, task_reopen) and merges (merge_next). Other tools: task_update, task_cancel, board, wait.
1429
+ .IP \(bu 2
1430
+ Worker: calls task_next, which returns a claim token, its own git worktree and a brief with the spec and how to finish. It works only inside that worktree and its write set, commits, calls signal as soon as a milestone others wait on is committed, and ends with task_done or task_fail and a report. Other tools: release (paths it is finished with), signal_amend, lease_acquire / lease_release (a port, the dev database, migrations), ask, propose_change, report_blocked, notify, wait. Every worker call passes its claim.
1431
+ .IP \(bu 2
1432
+ Messages need no polling: each worker reply carries its notices (answers, decisions, changed dependencies) and who is waiting on it. In Claude Code and OpenCode, a worker that stops while holding a task is sent back to finish it (up to three times) and gets answers to its questions. In Claude Code the manager's stop also waits for its inbox while tasks are running; in other harnesses the manager calls wait.
1433
+ .IP \(bu 2
1434
+ Only a person approves, in their own terminal: \fBapprove plan\fR (shows the design, the tasks and their files, then asks to type yes; it covers only the drafts sent with plan_submit, unchanged since), \fBapprove merge\fR, \fBapprove signal\fR, \fBapprove proposal\fR, \fBreject proposal\fR. They refuse from an agent's shell. An agent tells the person what is waiting and the command to run.
1435
+ .IP \(bu 2
1436
+ Scheduling: a task starts when every milestone it depends on is signalled and no running task's write set overlaps its own. A worker that signals a milestone mid\-task lets its dependents start from that commit right away.
1437
+ .IP \(bu 2
1438
+ Merge queue (merge_next, \fBoalo coord merge\fR): one run at a time. A task merges with a merge commit after every task it builds on has merged, and only if the project's test command passes, then the task's own test_cmd if it has one. A conflict or failing test sends it back to a worker with the output. A branch that changes .oalo/coord.json, .oalo/setup or the hook and MCP config waits for \fBapprove merge\fR.
1439
+ .IP \(bu 2
1440
+ Rework: task_reopen, a merge conflict or a failing merge test sends a task back, and they count together: first held for the same worker for claim_ttl_s, then any worker; the third time it stops as needs_human until the manager sets it back to ready. A worker silent for claim_ttl_s (15 minutes) loses its claim, the manager gets its commits in a report, and the next worker resumes the same worktree.
1441
+ .IP \(bu 2
1442
+ Settings in .oalo/coord.json (a person edits them): main_branch, test_cmd, merge (auto or manual), signal_review, claim_ttl_s, port_base, port_span. Task worktrees live in ~/.oalo/worktrees/<repo>\-<hash>/<task> (OALO_HOME moves them). An executable .oalo/setup runs in each new worktree with OALO_TASK_ID, OALO_WORKTREE, OALO_PROJECT_ROOT, OALO_PORT_BASE, OALO_PORT_SPAN and OALO_DB_NAME set.
1443
+ .IP \(bu 2
1444
+ The hooks block edits outside a worker's worktree and write set, and edits to coord's own files. Shell writes (sed \-i, redirects) aren't intercepted; the merge queue still catches their damage. Harnesses without hooks rely on the merge queue alone.
1445
+ .IP \(bu 2
1446
+ macOS and Linux only.
1447
+ .PP
1448
+ Exit codes: 0 ok; 1 operation refused or failed (message on stderr); 2 bad arguments; 3 no board here; run `oalo coord init`; 4 coord isn't installed on this machine; run `oalo coord install`.
1301
1449
  .SH BOT SETTINGS
1302
1450
  Read with \fBoalo bots settings <bot>\fR, changed with \fBoalo bots settings <bot> set key=value\fR, explained with \fBoalo bots settings \-\-explain <key>\fR. A change to a published bot needs \-\-yes.
1303
1451
  .SS knowledge
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oalo-ai/cli",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "Wire a local app into your OALO workspace: link a token, generate typed bindings, and serve the build surface over MCP.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -24,9 +24,11 @@
24
24
  "scripts": {
25
25
  "smoke": "node test/smoke.mjs",
26
26
  "smoke:mcp": "node test/mcp-smoke.mjs",
27
- "test:coord": "bun test test/coord.test.ts",
27
+ "test:coord": "bun test test/coord.test.ts test/coord-files.test.ts test/coord-hooks.test.ts test/coord-fixes.test.ts",
28
28
  "test:unit": "node --test test/*.test.mjs",
29
- "man": "node scripts/man.mjs"
29
+ "man": "node scripts/man.mjs",
30
+ "coord:build": "node scripts/coord_build.mjs",
31
+ "prepublishOnly": "node scripts/coord_check.mjs"
30
32
  },
31
33
  "publishConfig": {
32
34
  "access": "public"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oalo",
3
3
  "description": "Work on an Oalo workspace from Claude Code: edit chat flows, loops and code tools, lint and push them safely, and run test conversations with a bot.",
4
- "version": "0.1.0",
4
+ "version": "0.3.0",
5
5
  "author": { "name": "Oalo" },
6
6
  "mcpServers": {
7
7
  "oalo": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: oalo
3
- description: Build and change an Oalo workspace (the person's Oalo Base) from the terminal with the oalo CLI or its MCP server: chat flows, loops (automations), code tools, bots and what they know, data models and rows, hosting a repo and its environment variables, and what an app gets from Oalo (its own token, events into workflows, workflows as functions, its endpoints as bot tools, a chat widget, member sign-in and sync). Use when editing a flow, loop or tool, testing how a bot answers, moving data in or out of Oalo, bringing or deploying an app, or wiring an app's own code to Oalo.
3
+ description: Build and change an Oalo workspace (the person's Oalo Base) from the terminal with the oalo CLI or its MCP server: chat flows, loops (automations), code tools, bots and what they know, data models and rows, hosting a repo and its environment variables, and what an app gets from Oalo (its own token, events into workflows, workflows as functions, its endpoints as bot tools, a chat widget, member sign-in and sync). Use when editing a flow, loop or tool, testing how a bot answers, moving data in or out of Oalo, bringing or deploying an app, wiring an app's own code to Oalo, or splitting work across several agent sessions on one repo.
4
4
  ---
5
5
 
6
6
  # Working on an Oalo workspace
@@ -263,6 +263,29 @@ oalo deploy --app shop --env prod # build and swap the live release
263
263
  6. **Rolling back** (`oalo deploy --rollback`, MCP: `oalo_releases`) changes what
264
264
  live visitors get: only when the person asks. `--history` lists the
265
265
  releases.
266
+ 7. **Bringing a database in** (from Heroku, Railway, Render, Fly.io or
267
+ Primcloud): `oalo db restore <dump file> --env prod --check`, then the same
268
+ without `--check` once the person says go. The dump comes from the old
269
+ platform (Heroku: `heroku pg:backups:capture`, then `heroku
270
+ pg:backups:download` gives `latest.dump`). Or the person puts the old
271
+ database's URL in an environment variable and you pass `--from-env VAR`.
272
+ Never write a database URL into a command or a flag. Always name `--env`.
273
+ Have the person stop writes to the old database first: anything written
274
+ after the copy starts is lost. `oalo docs migrating-from-heroku` (or
275
+ `-railway`, `-render`, `-fly`, `-primcloud`) has each platform's steps.
276
+ 8. **Moving an app from another platform** (Heroku, Railway, Render, Fly.io,
277
+ Primcloud): in the app's repo, run `oalo migrate <platform> --from-app
278
+ <name>` first (the app or service's name on the old platform, the Heroku
279
+ app say) and show the person the plan; it changes nothing. Only `--apply`
280
+ writes the Procfile and `.oalo/app.json` and sets the variables, and it
281
+ sets them only once the app exists, so the order is `--apply`, commit,
282
+ `oalo deploy --new`, then the same `oalo migrate ... --apply` again. The
283
+ variables go to the app's prod settings with nothing restarted or deployed,
284
+ so this doesn't put it live; the preview keeps its own (`--env dev`, test
285
+ keys). It never prints a value. Don't copy variables by hand with `oalo env
286
+ set NAME=value`: for values it can't read (Fly secrets, Primcloud) the
287
+ person puts them in a .env file and you pass `--env-file`. Then the data
288
+ (rule 7), and live only when the person says so.
266
289
 
267
290
  ## An app's environment variables
268
291
 
@@ -392,6 +415,21 @@ oalo channels # WhatsApp, Instagram, emai
392
415
  but the bot's data tools leave it out, and it can't be embedded. Don't
393
416
  vectorize it.
394
417
 
418
+ ## Several agents on one repo
419
+
420
+ When the person wants work split across several agent sessions on one repo at
421
+ once, use `oalo coord`: a shared task board, a git worktree per task and a
422
+ merge queue that runs the tests. It needs no Oalo workspace.
423
+
424
+ 1. **Set it up once:** `oalo coord install` (once per machine), then in the
425
+ repo `oalo coord init` and `oalo coord hooks install`, and commit what they
426
+ write. Each session then has the board's tools (MCP server `oalo-coord`).
427
+ 2. **The person approves, never you.** The manager drafts tasks and calls
428
+ `plan_submit`; the person runs `oalo coord approve plan` in their own
429
+ terminal. Never run `oalo coord approve` or `reject` yourself: say what is
430
+ waiting and give them the command.
431
+ 3. `oalo help coord` has every command.
432
+
395
433
  ## Reading the docs
396
434
 
397
435
  Before building on a feature you don't know, read Oalo's own docs. They come
@@ -0,0 +1,103 @@
1
+ /**
2
+ * `oalo coord` from the npm package. Coord itself is a Bun-compiled binary
3
+ * (it needs bun:sqlite); `oalo coord install` downloads the build for this
4
+ * machine, checks it against the SHA-256 shipped in this package, and every
5
+ * other `oalo coord ...` runs it.
6
+ */
7
+ import { spawn, spawnSync } from "node:child_process";
8
+ import { createHash } from "node:crypto";
9
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
10
+ import { homedir } from "node:os";
11
+ import { join } from "node:path";
12
+ import { gunzipSync } from "node:zlib";
13
+
14
+ /** Where the builds are published; OALO_COORD_DOWNLOAD_URL overrides it. */
15
+ const DOWNLOAD_BASE = "https://oalo.ai/dl/coord";
16
+ /** Exit code when the binary isn't installed; `oalo help coord --json` lists it. */
17
+ export const NOT_INSTALLED = 4;
18
+
19
+ function release() {
20
+ try {
21
+ return JSON.parse(readFileSync(new URL("../coord-release.json", import.meta.url), "utf8"));
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ function platform() {
28
+ const os = { darwin: "darwin", linux: "linux" }[process.platform];
29
+ const arch = { arm64: "arm64", x64: "x64" }[process.arch];
30
+ return os && arch ? `${os}-${arch}` : null;
31
+ }
32
+
33
+ export function coordBinary(version) {
34
+ return join(process.env.OALO_HOME || homedir(), ".oalo", "bin", `oalo-coord-${version}`);
35
+ }
36
+
37
+ export async function coordInstall(flags) {
38
+ const rel = release();
39
+ const target = platform();
40
+ const say = (obj, text) => (flags.json ? console.log(JSON.stringify(obj)) : console.log(text));
41
+ if (!rel) {
42
+ console.error("oalo coord install: this oalo has no coord build listed; upgrade with `npm install -g @oalo-ai/cli`");
43
+ process.exit(1);
44
+ }
45
+ const entry = target && rel.targets[target];
46
+ if (!entry) {
47
+ console.error(`oalo coord install: no build for ${process.platform}-${process.arch} (macOS and Linux, arm64 and x64, are supported)`);
48
+ process.exit(1);
49
+ }
50
+ const bin = coordBinary(rel.version);
51
+ if (existsSync(bin) && !flags.force) {
52
+ return say({ installed: true, version: rel.version, path: bin, already: true }, `oalo coord ${rel.version} is already installed (${bin})`);
53
+ }
54
+
55
+ const url = `${process.env.OALO_COORD_DOWNLOAD_URL || DOWNLOAD_BASE}/${rel.version}/${entry.file}`;
56
+ if (!flags.json) console.error(`downloading ${url} (${(entry.bytes / 1e6).toFixed(0)} MB)`);
57
+ let res;
58
+ try {
59
+ res = await fetch(url);
60
+ } catch (err) {
61
+ console.error(`oalo coord install: download failed: ${err.message}`);
62
+ process.exit(1);
63
+ }
64
+ if (!res.ok) {
65
+ console.error(`oalo coord install: download failed: HTTP ${res.status} for ${url}`);
66
+ process.exit(1);
67
+ }
68
+ const gz = Buffer.from(await res.arrayBuffer());
69
+ const sha = createHash("sha256").update(gz).digest("hex");
70
+ if (sha !== entry.sha256) {
71
+ console.error(`oalo coord install: the download doesn't match this package's checksum (got ${sha}, want ${entry.sha256}); nothing was installed`);
72
+ process.exit(1);
73
+ }
74
+
75
+ mkdirSync(join(bin, ".."), { recursive: true });
76
+ const tmp = `${bin}.part`;
77
+ writeFileSync(tmp, gunzipSync(gz));
78
+ chmodSync(tmp, 0o755);
79
+ // Apple Silicon runs only signed code; Bun signs its builds ad hoc, and this
80
+ // re-applies that in case a build came from elsewhere.
81
+ if (process.platform === "darwin") spawnSync("codesign", ["--force", "--sign", "-", tmp], { stdio: "ignore" });
82
+ const check = spawnSync(tmp, ["--version"], { encoding: "utf8" });
83
+ if (check.status !== 0 || check.stdout.trim() !== rel.version) {
84
+ rmSync(tmp, { force: true });
85
+ console.error(`oalo coord install: the downloaded build didn't start (${(check.stderr || check.error?.message || "").trim()}); nothing was installed`);
86
+ process.exit(1);
87
+ }
88
+ renameSync(tmp, bin);
89
+ say({ installed: true, version: rel.version, path: bin }, `installed oalo coord ${rel.version} (${bin})\nNext, in your project: oalo coord init`);
90
+ }
91
+
92
+ /** Run an installed coord with these arguments; exits with its exit code. */
93
+ export function coordRun(argv) {
94
+ const rel = release();
95
+ const bin = rel && coordBinary(rel.version);
96
+ if (!bin || !existsSync(bin)) {
97
+ console.error("oalo coord isn't installed on this machine yet. Run `oalo coord install` (a one-time download, 25 to 37 MB), then try again.");
98
+ process.exit(NOT_INSTALLED);
99
+ }
100
+ const child = spawn(bin, argv, { stdio: "inherit" });
101
+ for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) process.on(sig, () => child.kill(sig));
102
+ child.on("exit", (code, signal) => process.exit(code ?? (signal ? 1 : 0)));
103
+ }