@astrofoundry/astrogate 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -7,8 +7,8 @@ Isolated agent workspaces on one host, each with its own specialists, a foreman,
7
7
  The owner runs this once per host, in a terminal on that host. The trust anchor is this repo's `allowed_signers` with `cli/verify-release.sh`: run it in a checkout, or in a folder holding copies of both. It checks the npm tarball before anything from it runs as root.
8
8
 
9
9
  ```sh
10
- v=0.1.2
10
+ v=0.1.3
11
11
  d=$(mktemp -d) && curl -fsSL -o "$d/core.tgz" "https://registry.npmjs.org/@astrofoundry/astrogate/-/astrogate-$v.tgz" && mkdir "$d/check" && sh cli/verify-release.sh "$d/core.tgz" allowed_signers "$v" "$d/check" && sudo sh "$d/check/package/cli/astrogate.sh" core update "$v" --signers allowed_signers
12
12
  ```
13
13
 
14
- After that, `sudo astrogate core update` installs the newest release, `sudo astrogate core rollback` goes back one version, and `astrogate doctor` checks the installed core against its signature.
14
+ After that, `sudo astrogate core update` installs the newest release with the tools it pins in `tools.lock`, `sudo astrogate core rollback` goes back one version, `astrogate tools` lists the tools, and `astrogate doctor` checks the core against its signature and runs each tool.
package/cli/astrogate.sh CHANGED
@@ -1,29 +1,34 @@
1
1
  #!/bin/sh
2
- # astrogate: the host command for the Astrogate core. Tools and workspaces follow.
2
+ # astrogate: the host command for the Astrogate core and the tools it pins. Workspaces follow.
3
3
  #
4
4
  # astrogate core [status] the current core, the kept previous one, and the newest on npm
5
- # sudo astrogate core update [<x.y.z>] the newest core on npm, or that version; the running core's
6
- # verify-release.sh checks its signature and every file first
7
- # sudo astrogate core rollback swaps the current core and the previous one
5
+ # sudo astrogate core update [<x.y.z>] the newest core on npm, or that version, and the tools it pins;
6
+ # the running core's verify-release.sh checks the core first, and
7
+ # each tool download must match the sha256 in the core's tools.lock
8
+ # sudo astrogate core rollback swaps the current core and the previous one, with their tools
9
+ # astrogate tools each tool's installed version and the version the core pins
8
10
  # astrogate doctor read-only checks; exits 1 when one fails
9
11
  #
10
12
  # The first install runs this script from a tarball the owner checked with the repo's
11
13
  # verify-release.sh, and adds `--signers <the repo's allowed_signers>`; root keeps that file
12
- # in /usr/local/etc/astrogate. Root runs only system programs and files in root-owned folders.
13
- # macOS only for now.
14
+ # in /usr/local/etc/astrogate. Root runs only system programs and files in root-owned folders;
15
+ # it runs a new tool only as nobody. macOS on Apple silicon only for now.
14
16
  set -eu
15
17
  PATH=/usr/bin:/bin:/usr/sbin:/sbin
16
18
  export PATH
17
19
  umask 022
18
20
 
19
21
  BASE=/usr/local/libexec/astrogate
22
+ TOOLS=$BASE/tools
20
23
  SIGNERS_DIR=/usr/local/etc/astrogate
21
24
  SIGNERS=$SIGNERS_DIR/allowed_signers
22
25
  COMMAND=/usr/local/bin/astrogate
23
26
  REGISTRY=https://registry.npmjs.org
27
+ # Installed in this order: gcloud's check runs with the pinned Python.
28
+ TOOL_NAMES="node jq bw python gcloud"
24
29
 
25
30
  usage() {
26
- echo "usage: astrogate core [status] | core update [<x.y.z>] [--signers <allowed_signers>] | core rollback | doctor" >&2
31
+ echo "usage: astrogate core [status] | core update [<x.y.z>] [--signers <allowed_signers>] | core rollback | tools | doctor" >&2
27
32
  exit 2
28
33
  }
29
34
 
@@ -38,6 +43,12 @@ valid_version() {
38
43
  printf '%s\n' "$1" | /usr/bin/grep -Eq '^(0|[1-9][0-9]{0,5})\.(0|[1-9][0-9]{0,5})\.(0|[1-9][0-9]{0,5})$'
39
44
  }
40
45
 
46
+ # A python-build-standalone release: CPython x.y.z and the build date that names the release.
47
+ valid_python_version() {
48
+ case "$1" in '' | *[!0-9.+]*) return 1 ;; esac
49
+ printf '%s\n' "$1" | /usr/bin/grep -Eq '^(0|[1-9][0-9]{0,5})\.(0|[1-9][0-9]{0,5})\.(0|[1-9][0-9]{0,5})\+[0-9]{8}$'
50
+ }
51
+
41
52
  # True when version $1 is older than version $2.
42
53
  version_lt() {
43
54
  old_ifs=$IFS
@@ -80,9 +91,9 @@ case "${1:-}" in
80
91
  *) usage ;;
81
92
  esac
82
93
  ;;
83
- doctor)
94
+ tools | doctor)
84
95
  [ $# -eq 1 ] || usage
85
- action=doctor
96
+ action=$1
86
97
  ;;
87
98
  *) usage ;;
88
99
  esac
@@ -116,7 +127,7 @@ latest_version() {
116
127
  }
117
128
 
118
129
  fetch() {
119
- /usr/bin/curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSL --retry 2 --max-time 300 -o "$2" "$1" || fail "download failed: $1"
130
+ /usr/bin/curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSL --retry 2 --max-time 900 -o "$2" "$1" || fail "download failed: $1"
120
131
  }
121
132
 
122
133
  # A directory only root can change: owned by uid 0, not a link, writable by nobody else.
@@ -143,6 +154,11 @@ ensure_root_dir() {
143
154
  check_root_dir "$1"
144
155
  }
145
156
 
157
+ # Files in folder $1 that are not root's or that group or others can write, at most three.
158
+ unsafe_files() {
159
+ /usr/bin/find "$1" \( ! -user root -o -perm -0002 -o -perm -0020 \) -print 2>/dev/null | /usr/bin/head -n 3 | /usr/bin/tr '\n' ' '
160
+ }
161
+
146
162
  # Points current at versions/$1, and previous at the version current named before.
147
163
  switch_to() {
148
164
  before=$(link_version current)
@@ -169,8 +185,168 @@ prune() {
169
185
 
170
186
  require_root() {
171
187
  [ "$(/usr/bin/id -u)" = 0 ] || fail "run it as root: sudo astrogate core $action"
188
+ [ "$(/usr/bin/uname -m)" = arm64 ] || fail "only Apple silicon is supported yet"
189
+ }
190
+
191
+ # Root's work folder: only root can list it; nobody gets its own folder inside for tool checks.
192
+ make_work() {
193
+ work=$(/usr/bin/mktemp -d /private/var/tmp/astrogate.XXXXXX)
194
+ trap '/bin/rm -rf "$work"' EXIT
195
+ trap 'exit 1' HUP INT TERM
196
+ /bin/chmod 0711 "$work"
197
+ /bin/mkdir -m 0700 "$work/nobody"
198
+ /usr/sbin/chown nobody "$work/nobody"
199
+ }
200
+
201
+ # --- tools ------------------------------------------------------------------
202
+
203
+ tool_version_ok() {
204
+ case "$1" in python) valid_python_version "$2" ;; *) valid_version "$2" ;; esac
205
+ }
206
+
207
+ # The version core folder $1 pins for tool $2, or nothing.
208
+ pinned_version() {
209
+ [ -f "$1/tools.lock" ] || return 0
210
+ /usr/bin/awk -v t="$2" '$1 == t && NF == 4 { print $2; exit }' "$1/tools.lock"
211
+ }
212
+
213
+ # Fails unless core folder $1 has no tools.lock, or one whose lines are all
214
+ # "<tool> <version> <sha256> <https url>" with one valid version per tool.
215
+ check_lock() {
216
+ [ -f "$1/tools.lock" ] || return 0
217
+ bad_line=$(/usr/bin/awk -v names=" $TOOL_NAMES " '
218
+ /^#/ || NF == 0 { next }
219
+ NF != 4 || index(names, " " $1 " ") == 0 || length($3) != 64 || $3 !~ /^[0-9a-f]+$/ { print NR; exit }
220
+ $4 !~ /^https:\/\/(nodejs\.org|github\.com|dl\.google\.com)\/[A-Za-z0-9.\/_+-]+$/ { print NR; exit }
221
+ ($1 in seen) && seen[$1] != $2 { print NR; exit }
222
+ { seen[$1] = $2 }' "$1/tools.lock")
223
+ [ -z "$bad_line" ] || fail "$1/tools.lock line $bad_line is no <tool> <version> <sha256> <https url>, or pins a second version"
224
+ for tool in $TOOL_NAMES; do
225
+ pin=$(pinned_version "$1" "$tool")
226
+ [ -z "$pin" ] || tool_version_ok "$tool" "$pin" || fail "$1/tools.lock pins $tool $pin, which is no valid version"
227
+ done
228
+ }
229
+
230
+ # Runs a tool from / with a clean environment; as nobody when root runs this script, so root never runs a download.
231
+ run_tool() {
232
+ if [ "$(/usr/bin/id -u)" = 0 ]; then
233
+ (cd / && exec /usr/bin/sudo -n -u nobody /usr/bin/env -i PATH=/usr/bin:/bin:/usr/sbin:/sbin HOME=/var/empty "$@")
234
+ else
235
+ (cd / && exec /usr/bin/env -i PATH=/usr/bin:/bin:/usr/sbin:/sbin HOME="$HOME" "$@")
236
+ fi
237
+ }
238
+
239
+ # True when tool $1 in folder $3 answers with version $2. $4 is a folder the runner can write;
240
+ # gcloud runs with the Python folder $5.
241
+ tool_answers() {
242
+ case "$1" in
243
+ node) [ "$(run_tool "$3/bin/node" --version 2>/dev/null)" = "v$2" ] ;;
244
+ jq) [ "$(run_tool "$3/jq" --version 2>/dev/null)" = "jq-$2" ] ;;
245
+ bw) [ "$(run_tool BITWARDENCLI_APPDATA_DIR="$4" "$3/bw" --version 2>/dev/null)" = "$2" ] ;;
246
+ python) [ "$(run_tool "$3/bin/python3" -c 'import ssl, sqlite3, sys; print("%d.%d.%d" % sys.version_info[:3])' 2>/dev/null)" = "${2%+*}" ] ;;
247
+ gcloud) [ "$(run_tool CLOUDSDK_PYTHON="$5/bin/python3" CLOUDSDK_CONFIG="$4" CLOUDSDK_CORE_DISABLE_PROMPTS=1 "$3/bin/gcloud" version 2>/dev/null | /usr/bin/head -n 1)" = "Google Cloud SDK $2" ] ;;
248
+ *) return 1 ;;
249
+ esac
250
+ }
251
+
252
+ unpack_tool() {
253
+ case "$1" in
254
+ node | python) /usr/bin/tar -xzf "$2" --no-same-owner --strip-components 1 -C "$3" ;;
255
+ gcloud) /usr/bin/tar -xzf "$2" --no-same-owner -C "$3" ;;
256
+ bw) /usr/bin/unzip -q "$2" bw -d "$3" && /bin/chmod 0755 "$3/bw" ;;
257
+ jq) /usr/bin/install -m 0755 "$2" "$3/jq" ;;
258
+ esac
259
+ }
260
+
261
+ # Installs tool $2 at the version core folder $1 pins: every download must match its sha256,
262
+ # and the tool must answer with its version, run as nobody, before it moves into place.
263
+ install_tool() {
264
+ core=$1 tool=$2
265
+ pin=$(pinned_version "$core" "$tool")
266
+ dest=$TOOLS/$tool/$pin
267
+ /bin/rm -rf "$work/$tool" "$dest.partial"
268
+ /bin/mkdir "$work/$tool"
269
+ /bin/mkdir -m 0755 "$dest.partial"
270
+ downloads=$(/usr/bin/awk -v t="$tool" '$1 == t && NF == 4 { print $3, $4 }' "$core/tools.lock")
271
+ while read -r sum url; do
272
+ file=$work/$tool/${url##*/}
273
+ fetch "$url" "$file"
274
+ [ "$(/usr/bin/shasum -a 256 "$file" | /usr/bin/cut -d' ' -f1)" = "$sum" ] || fail "checksum mismatch for $url"
275
+ unpack_tool "$tool" "$file" "$dest.partial" || fail "cannot unpack $url"
276
+ done <<EOF
277
+ $downloads
278
+ EOF
279
+ /usr/sbin/chown -R root:wheel "$dest.partial"
280
+ /bin/chmod -R u=rwX,go=rX "$dest.partial"
281
+ tool_answers "$tool" "$pin" "$dest.partial" "$work/nobody" "$TOOLS/python/$(pinned_version "$core" python)" ||
282
+ fail "$tool $pin does not answer with its version; nothing changed"
283
+ /bin/mv "$dest.partial" "$dest"
284
+ echo "installed $tool $pin"
172
285
  }
173
286
 
287
+ # Installs every tool version core folder $1 pins that is not there yet; switches nothing.
288
+ stage_tools() {
289
+ check_lock "$1"
290
+ [ -f "$1/tools.lock" ] || return 0
291
+ ensure_root_dir "$TOOLS"
292
+ for tool in $TOOL_NAMES; do
293
+ pin=$(pinned_version "$1" "$tool")
294
+ [ -n "$pin" ] || continue
295
+ ensure_root_dir "$TOOLS/$tool"
296
+ [ -d "$TOOLS/$tool/$pin" ] || install_tool "$1" "$tool"
297
+ done
298
+ }
299
+
300
+ # Points each tool's current link at the version core folder $1 pins.
301
+ link_tools() {
302
+ [ -f "$1/tools.lock" ] || return 0
303
+ for tool in $TOOL_NAMES; do
304
+ pin=$(pinned_version "$1" "$tool")
305
+ [ -n "$pin" ] && [ -d "$TOOLS/$tool/$pin" ] || continue
306
+ [ "$(/usr/bin/readlink "$TOOLS/$tool/current" 2>/dev/null || true)" != "$pin" ] || continue
307
+ /bin/rm -f "$TOOLS/$tool/current.new"
308
+ /bin/ln -s "$pin" "$TOOLS/$tool/current.new"
309
+ /bin/mv -h "$TOOLS/$tool/current.new" "$TOOLS/$tool/current"
310
+ echo "$tool $pin is current"
311
+ done
312
+ }
313
+
314
+ # Removes the tool versions, and the tools, that neither the current nor the previous core pins.
315
+ prune_tools() {
316
+ for tool_dir in "$TOOLS"/*; do
317
+ [ -d "$tool_dir" ] && [ ! -L "$tool_dir" ] || continue
318
+ tool=${tool_dir##*/}
319
+ keep_current=$(pinned_version "$BASE/current" "$tool")
320
+ keep_previous=$(pinned_version "$BASE/previous" "$tool")
321
+ if [ -z "$keep_current" ] && [ -z "$keep_previous" ]; then
322
+ /bin/rm -rf "$tool_dir"
323
+ continue
324
+ fi
325
+ for dir in "$tool_dir"/*; do
326
+ [ -e "$dir" ] || [ -L "$dir" ] || continue
327
+ name=${dir##*/}
328
+ [ "$name" = current ] || [ "$name" = "$keep_current" ] || [ "$name" = "$keep_previous" ] || /bin/rm -rf "$dir"
329
+ done
330
+ done
331
+ }
332
+
333
+ tools_status() {
334
+ current=$(link_version current)
335
+ [ -n "$current" ] || fail "no core is installed"
336
+ if [ ! -f "$BASE/current/tools.lock" ]; then
337
+ echo "core $current pins no tools"
338
+ return 0
339
+ fi
340
+ for tool in $TOOL_NAMES; do
341
+ pin=$(pinned_version "$BASE/current" "$tool")
342
+ [ -n "$pin" ] || continue
343
+ have=$(/usr/bin/readlink "$TOOLS/$tool/current" 2>/dev/null || true)
344
+ if [ "$have" = "$pin" ]; then echo "$tool $pin"; else echo "$tool ${have:-missing}; core $current pins $pin (sudo astrogate core update)"; fi
345
+ done
346
+ }
347
+
348
+ # --- core -------------------------------------------------------------------
349
+
174
350
  core_status() {
175
351
  current=$(link_version current)
176
352
  previous=$(link_version previous)
@@ -201,17 +377,17 @@ core_update() {
201
377
  fail "npm names $version as newest, older than the installed $current; name a version to go back"
202
378
  fi
203
379
  fi
380
+ make_work
204
381
  if [ "$version" = "$current" ]; then
205
- echo "core $current is installed"
382
+ stage_tools "$BASE/current"
383
+ link_tools "$BASE/current"
384
+ echo "core $current is installed, with the tools it pins"
206
385
  return 0
207
386
  fi
208
387
  # The installed core checks a new one; only the first install uses the copy next to this script.
209
388
  if [ -n "$current" ]; then verifier=$BASE/current/cli/verify-release.sh; else verifier=$HERE/verify-release.sh; fi
210
389
  [ -f "$verifier" ] || fail "$verifier is missing"
211
390
 
212
- work=$(/usr/bin/mktemp -d /private/var/tmp/astrogate.XXXXXX)
213
- trap '/bin/rm -rf "$work"' EXIT
214
- trap 'exit 1' HUP INT TERM
215
391
  fetch "$REGISTRY/@astrofoundry/astrogate/-/astrogate-$version.tgz" "$work/core.tgz"
216
392
  /bin/mkdir "$work/check"
217
393
  /bin/sh "$verifier" "$work/core.tgz" "$signers" "$version" "$work/check" >/dev/null
@@ -224,8 +400,12 @@ core_update() {
224
400
  /bin/chmod 0755 "$target.new/cli/astrogate.sh" "$target.new/cli/verify-release.sh"
225
401
  /bin/rm -rf "$target"
226
402
  /bin/mv "$target.new" "$target"
403
+ # Every tool the new core pins is in place before anything switches.
404
+ stage_tools "$target"
227
405
  switch_to "$version"
406
+ link_tools "$BASE/current"
228
407
  prune
408
+ prune_tools
229
409
 
230
410
  if [ ! -f "$SIGNERS" ]; then
231
411
  ensure_root_dir /usr/local/etc
@@ -246,7 +426,10 @@ core_rollback() {
246
426
  current=$(link_version current)
247
427
  previous=$(link_version previous)
248
428
  [ -n "$previous" ] && [ -d "$BASE/versions/$previous" ] || fail "no previous core to roll back to"
429
+ make_work
430
+ stage_tools "$BASE/versions/$previous"
249
431
  switch_to "$previous"
432
+ link_tools "$BASE/current"
250
433
  echo "core $current -> $previous; astrogate core rollback again goes forward"
251
434
  }
252
435
 
@@ -260,20 +443,47 @@ bad() {
260
443
  failed=1
261
444
  }
262
445
 
446
+ doctor_tools() {
447
+ if [ ! -f "$BASE/current/tools.lock" ]; then
448
+ warn "core $current pins no tools"
449
+ return 0
450
+ fi
451
+ scratch=$(/usr/bin/mktemp -d)
452
+ for tool in $TOOL_NAMES; do
453
+ pin=$(pinned_version "$BASE/current" "$tool")
454
+ [ -n "$pin" ] || continue
455
+ have=$(/usr/bin/readlink "$TOOLS/$tool/current" 2>/dev/null || true)
456
+ if [ "$have" != "$pin" ]; then
457
+ bad "$tool is ${have:-missing}; core $current pins $pin (sudo astrogate core update)"
458
+ continue
459
+ fi
460
+ problem=$(root_dir_problem "$TOOLS/$tool/$pin")
461
+ [ -n "$problem" ] || problem=$(unsafe_files "$TOOLS/$tool/$pin")
462
+ if [ -n "$problem" ]; then
463
+ bad "$tool $pin is not root-only: $problem"
464
+ elif tool_answers "$tool" "$pin" "$TOOLS/$tool/current" "$scratch" "$TOOLS/python/current"; then
465
+ ok "$tool $pin"
466
+ else
467
+ bad "$tool $pin does not answer with its version"
468
+ fi
469
+ done
470
+ /bin/rm -rf "$scratch"
471
+ }
472
+
263
473
  doctor() {
264
474
  printf 'astrogate doctor on %s, macOS %s on %s\n' "$(/bin/hostname -s)" "$(/usr/bin/sw_vers -productVersion)" "$(/usr/bin/uname -m)"
265
475
  current=$(link_version current)
266
476
  if [ -z "$current" ] || [ ! -d "$BASE/versions/$current" ]; then
267
477
  bad "no core in $BASE/current: install it (README, First install)"
268
- [ "$failed" = 0 ] || exit 1
478
+ exit 1
269
479
  fi
270
480
  problems=""
271
481
  for dir in / /usr /usr/local /usr/local/libexec "$BASE" "$BASE/versions" "$BASE/versions/$current"; do
272
482
  problem=$(root_dir_problem "$dir")
273
483
  [ -z "$problem" ] || problems="$problems; $problem"
274
484
  done
275
- unsafe=$(/usr/bin/find "$BASE/versions/$current" \( ! -user root -o -perm -0002 -o -perm -0020 \) -print 2>/dev/null | /usr/bin/head -n 3)
276
- [ -z "$unsafe" ] || problems="$problems; not root-only: $(printf '%s' "$unsafe" | /usr/bin/tr '\n' ' ')"
485
+ unsafe=$(unsafe_files "$BASE/versions/$current")
486
+ [ -z "$unsafe" ] || problems="$problems; not root-only: $unsafe"
277
487
  if [ -z "$problems" ]; then ok "core folders are root-only"; else bad "core folders${problems}"; fi
278
488
 
279
489
  if [ -f "$SIGNERS" ] && [ "$(/usr/bin/stat -f '%u %Lp' "$SIGNERS")" = "0 644" ]; then
@@ -298,6 +508,7 @@ doctor() {
298
508
  previous=$(link_version previous)
299
509
  if [ -n "$previous" ] && [ -d "$BASE/versions/$previous" ]; then ok "previous core $previous kept for rollback"; else warn "no previous core to roll back to"; fi
300
510
  if [ "$(/usr/bin/readlink "$COMMAND" 2>/dev/null || true)" = "$BASE/current/cli/astrogate.sh" ]; then ok "$COMMAND"; else bad "$COMMAND does not link to $BASE/current/cli/astrogate.sh"; fi
511
+ doctor_tools
301
512
  [ "$failed" = 0 ] || exit 1
302
513
  }
303
514
 
@@ -305,5 +516,6 @@ case "$action" in
305
516
  status) core_status ;;
306
517
  update) core_update ;;
307
518
  rollback) core_rollback ;;
519
+ tools) tools_status ;;
308
520
  doctor) doctor ;;
309
521
  esac
@@ -1,5 +1,5 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { mkdirSync, mkdtempSync, readdirSync, readFileSync, readlinkSync, rmSync } from "node:fs";
2
+ import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, readlinkSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { describe, expect, it } from "vitest";
@@ -7,6 +7,9 @@ import { describe, expect, it } from "vitest";
7
7
  const SCRIPT = join(import.meta.dirname, "astrogate.sh");
8
8
  const isRoot = process.getuid?.() === 0;
9
9
  const isMac = process.platform === "darwin";
10
+ const REPO = join(import.meta.dirname, "..");
11
+ const SHA = "a".repeat(64);
12
+ const TOOL_FUNCTIONS = ["fail", "valid_version", "valid_python_version", "tool_version_ok", "pinned_version", "check_lock"];
10
13
 
11
14
  function astrogate(...args: string[]) {
12
15
  return spawnSync("/bin/sh", [SCRIPT, ...args], { encoding: "utf-8" });
@@ -42,6 +45,7 @@ describe("astrogate", () => {
42
45
  [["core", "update", "--signers", "a", "--signers", "b"]],
43
46
  [["core", "rollback", "1.2.3"]],
44
47
  [["doctor", "now"]],
48
+ [["tools", "now"]],
45
49
  [["update"]],
46
50
  ])("refuses %j with a usage error before anything else", (args) => {
47
51
  const result = astrogate(...args);
@@ -110,4 +114,73 @@ describe("astrogate", () => {
110
114
  rmSync(base, { recursive: true, force: true });
111
115
  }
112
116
  });
117
+
118
+ describe("tools.lock", () => {
119
+ const withLock = (lock: string, call: (dir: string) => string) => {
120
+ const dir = mkdtempSync(join(tmpdir(), "astrogate-lock-"));
121
+ try {
122
+ writeFileSync(join(dir, "tools.lock"), lock);
123
+ return shellFunctions(TOOL_FUNCTIONS, `TOOL_NAMES="node jq bw python gcloud"\n${call(dir)}`);
124
+ } finally {
125
+ rmSync(dir, { recursive: true, force: true });
126
+ }
127
+ };
128
+
129
+ it("accepts the committed tools.lock and reads its pins", () => {
130
+ const result = shellFunctions(TOOL_FUNCTIONS, `TOOL_NAMES="node jq bw python gcloud"\ncheck_lock '${REPO}'\nfor t in $TOOL_NAMES; do printf '%s=%s\\n' "$t" "$(pinned_version '${REPO}' "$t")"; done`);
131
+ expect(result.stderr).toBe("");
132
+ expect(result.stdout).toMatch(/^node=\d+\.\d+\.\d+\njq=\d+\.\d+\.\d+\nbw=\d+\.\d+\.\d+\npython=\d+\.\d+\.\d+\+\d{8}\ngcloud=\d+\.\d+\.\d+\n$/);
133
+ });
134
+
135
+ it("accepts a core without tools.lock", () => {
136
+ expect(shellFunctions(TOOL_FUNCTIONS, `TOOL_NAMES=node\ncheck_lock '${tmpdir()}/astrogate-no-such-core'`).status).toBe(0);
137
+ });
138
+
139
+ it.each([
140
+ ["three fields", `jq 1.8.2 ${SHA}\n`],
141
+ ["an unknown tool", `curl 8.0.0 ${SHA} https://github.com/x/curl\n`],
142
+ ["a short sha256", `jq 1.8.2 ${SHA.slice(1)} https://github.com/x/jq\n`],
143
+ ["an upper-case sha256", `jq 1.8.2 ${SHA.toUpperCase()} https://github.com/x/jq\n`],
144
+ ["plain http", `jq 1.8.2 ${SHA} http://github.com/x/jq\n`],
145
+ ["another host", `jq 1.8.2 ${SHA} https://example.com/x/jq\n`],
146
+ ["a host that only starts like an allowed one", `jq 1.8.2 ${SHA} https://github.com.example.com/x/jq\n`],
147
+ ["a query string", `jq 1.8.2 ${SHA} https://github.com/x/jq?y=1\n`],
148
+ ["two versions of one tool", `gcloud 1.0.0 ${SHA} https://dl.google.com/a.tgz\ngcloud 1.0.1 ${SHA} https://dl.google.com/b.tgz\n`],
149
+ ["a bad version", `node 26.14 ${SHA} https://nodejs.org/x.tgz\n`],
150
+ ["a python version without its build date", `python 3.14.10 ${SHA} https://github.com/x/py.tgz\n`],
151
+ ])("refuses %s", (_, lock) => {
152
+ const result = withLock(lock, (dir) => `check_lock '${dir}'`);
153
+ expect(result.status).toBe(1);
154
+ expect(result.stderr).toMatch(/^astrogate: .*tools\.lock (line \d+|pins)/);
155
+ });
156
+ });
157
+
158
+ it.runIf(isMac)("links the pinned tool versions and prunes the ones no kept core pins", () => {
159
+ const base = mkdtempSync(join(tmpdir(), "astrogate-tools-"));
160
+ try {
161
+ const tools = join(base, "tools");
162
+ const core = (v: string, lock: string) => {
163
+ mkdirSync(join(base, "versions", v), { recursive: true });
164
+ writeFileSync(join(base, "versions", v, "tools.lock"), lock);
165
+ };
166
+ core("1.0.0", `jq 1.8.1 ${SHA} https://github.com/x/jq\nbw 2026.1.0 ${SHA} https://github.com/x/bw\n`);
167
+ core("1.1.0", `jq 1.8.2 ${SHA} https://github.com/x/jq\n`);
168
+ for (const d of ["jq/1.8.0", "jq/1.8.1", "jq/1.8.2", "jq/1.8.2.partial", "bw/2026.1.0", "node/26.0.0"]) mkdirSync(join(tools, d), { recursive: true });
169
+ symlinkSync("1.8.0", join(tools, "jq", "current"));
170
+ const run = (call: string) =>
171
+ shellFunctions([...TOOL_FUNCTIONS, "link_version", "switch_to", "link_tools", "prune_tools"], `BASE='${base}'\nTOOLS='${tools}'\nTOOL_NAMES="node jq bw python gcloud"\n${call}`);
172
+
173
+ expect(run("switch_to 1.0.0 && switch_to 1.1.0 && link_tools \"$BASE/current\"").stdout).toBe("jq 1.8.2 is current\n");
174
+ expect(readlinkSync(join(tools, "jq", "current"))).toBe("1.8.2");
175
+ expect(run("prune_tools").status).toBe(0);
176
+ expect(readdirSync(join(tools, "jq")).sort()).toEqual(["1.8.1", "1.8.2", "current"]);
177
+ expect(readdirSync(join(tools, "bw"))).toEqual(["2026.1.0"]);
178
+ expect(existsSync(join(tools, "node"))).toBe(false);
179
+
180
+ expect(run('switch_to 1.0.0 && link_tools "$BASE/current"').stdout).toBe("jq 1.8.1 is current\nbw 2026.1.0 is current\n");
181
+ expect(readlinkSync(join(tools, "jq", "current"))).toBe("1.8.1");
182
+ } finally {
183
+ rmSync(base, { recursive: true, force: true });
184
+ }
185
+ });
113
186
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/astrogate",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Astrogate core: isolated agent workspaces with specialists, a foreman, and chat bridges, for the pi coding agent and Claude Code.",
5
5
  "packageManager": "pnpm@12.23.0",
6
6
  "scripts": {
@@ -8,6 +8,7 @@
8
8
  "lint": "eslint .",
9
9
  "build": "node scripts/build.ts",
10
10
  "prepack": "node scripts/build.ts",
11
+ "pin-tools": "node scripts/pin-tools.ts",
11
12
  "typecheck": "tsc --noEmit",
12
13
  "check": "tsc --noEmit && eslint . && node scripts/build.ts && vitest run --coverage",
13
14
  "release:patch": "node scripts/release.ts patch",
@@ -36,7 +37,8 @@
36
37
  "harness",
37
38
  "release.sha256",
38
39
  "release.sha256.sig",
39
- "specialists"
40
+ "specialists",
41
+ "tools.lock"
40
42
  ],
41
43
  "repository": {
42
44
  "type": "git",
package/release.sha256 CHANGED
@@ -1,10 +1,10 @@
1
- 18e5d7d16e71779794629880e19fd14d28d6fb7b5db9ccdc64511e8b6c69a4a9 README.md
1
+ aa08819cc3d490adab1ed75efd822e30d808b029935a2ecb24ee8d37c9e21d8f README.md
2
2
  b9b0f9fa90b9a230157de1fefef1aa5a624bfd7b50527b67ad86ecc62414aadb agents/foreman.md
3
3
  4091f50a5a9ff72e2f1571c6de054d9c891dbe294aa58e6a55ad9a1bff2f766a cli/astro-install.sh
4
4
  9f371247fdaea09e1551f940fd91eacb7d242baea343fce66f12fc8e22ba064b cli/astro.sh
5
5
  8e054f8286876b77e0887d0b0e2a62d4a048fd41bfa0048d126e0c9171869cf6 cli/astro.test.ts
6
- a41c87a4a7ed07382a58de6e8f382e2dba9123de2aca6aa8275bd31df8985a48 cli/astrogate.sh
7
- 08d772b724401f59988b99ad3cadd381c2280975fda38f76a7dfc7853188e117 cli/astrogate.test.ts
6
+ cc09e939b079cea163f5a88e5e3d67ff98e3c5e617cdb7cb40ae2bfc10c240da cli/astrogate.sh
7
+ f32adea3492890fbb5c03a1b4a1bf1e55d37978141d3f7c684d77b3aa705914c cli/astrogate.test.ts
8
8
  07b9aef7e5d0ee43959e0c16e00ec3a202769c94faea4167257513bf15b9383c cli/verify-release.sh
9
9
  29614fd0eb1ad08215baf827b00ee2b98ccb73ca0ccf770bc5a0084c71da5926 cli/verify-release.test.ts
10
10
  369bc39629e3997f35ea22a4ba4d37f84da52c60ca3bf6fa5c623861a1a58329 dist/bridge.js
@@ -69,7 +69,7 @@ e76423d9c09263e064e48e6608c6eb07f70bc350841153f7c251376b8b424dc6 extensions/sub
69
69
  484c52d2e9d93dbe4aec878b5afc494f0076f5b79b5f4d24423933b39913bc3b harness/claude/main.ts
70
70
  e1d07bd981bd4ff6385246b6c1ad41349718c1e490b2bff675291dc7b568cd69 harness/claude/mcp.ts
71
71
  194b623038d56a2565ad42d30d1db72ca453e654bfc84996800362e8a972282b harness/claude/settings.ts
72
- 916cc870de3aa2881387ef4a95c25f7d9145b0f97ea2b940326eb85ea29f4868 package.json
72
+ df7a19e52965cab6b1f2d8b61087ca082efd7273e145206c5f9e85409e3fba89 package.json
73
73
  642383b14db5dbfb7caa6a185591263e4294a73323bf4c78606f7b85f0817fd0 specialists/AGENTS.md
74
74
  a385cf5e3b59de30b5ed9b0840d6cf6198b577668f18dfd5de13a714fb047c3e specialists/README.md
75
75
  729f8c29d7cf716be5b01d5df869eeda6d4683f86a4915a52fb8adfdebe1f9d2 specialists/entry/specialist-cli.sh
@@ -97,3 +97,4 @@ c1abde1e550c0f4703fd0b2536cc4002c7edf6468c18a03ebaa516fd1ce093c3 specialists/li
97
97
  31959f525a0b0aff070b4a19a9677d446d3425481e936dcd9ca2d957f4e51142 specialists/lib/tunnel.test.ts
98
98
  ed93bfcef355a0a3aa7d679395b2f6ce9ce4c5709253fda7f63c1f3927f5d324 specialists/lib/tunnel.ts
99
99
  7a36850a90c3a5e8c2a02fe386f93a0b6e664431799154f548e7ac9f33e84a90 specialists/provision/provision.sh
100
+ d182f87697c383c29075dc8b5415fc6fa3832ab33ccf14d5df8a941d9435b5c9 tools.lock
@@ -1,6 +1,6 @@
1
1
  -----BEGIN SSH SIGNATURE-----
2
2
  U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUteIwPdKqPwfNc4vHQPUE+JWMC
3
3
  nmuMUwttLeX5wtyIoAAAAOYXN0cm9nYXRlLWNvcmUAAAAAAAAABnNoYTUxMgAAAFMAAAAL
4
- c3NoLWVkMjU1MTkAAABA1taMKjBlPVP2TGVWp2cWTZZg0JKYd8T3E72x2KrpeX9nZazV3p
5
- TvxaRwQhZeJlqy0k1VRXRZiO5y6W1+M9e6Dw==
4
+ c3NoLWVkMjU1MTkAAABAT9XJeDq5pjTkKw2BsXczy1z+M0gF/+I8QF8BZgYM7+8j7IAtqJ
5
+ bosolZ798rX+LPeMbMe1q2DCngFQOdExI9Dw==
6
6
  -----END SSH SIGNATURE-----
package/tools.lock ADDED
@@ -0,0 +1,12 @@
1
+ # Tools the core installs on every host, pinned by version and sha256.
2
+ # Written by `pnpm pin-tools <tool> <version>`; `astrogate core update` installs exactly these.
3
+ # tool version sha256 url
4
+ node 26.14.0 1c65aaa7d4f1a86e3448f09c536ea45f6e23e2ef472390eee080e9a8deb9a1fe https://nodejs.org/dist/v26.14.0/node-v26.14.0-darwin-arm64.tar.gz
5
+ jq 1.8.2 2d75340ba57a4b4b4c8708a21c2dc8e958a48aaa8bba13b27f77f6e4c0eca07e https://github.com/jqlang/jq/releases/download/jq-1.8.2/jq-macos-arm64
6
+ bw 2026.11.1 0447a5c94b5893deb3fbe4f4ac02e8d811e2f9815c27d567d08b4fc70486cff1 https://github.com/bitwarden/clients/releases/download/cli-v2026.11.1/bw-bit-macos-arm64-2026.11.1.zip
7
+ python 3.14.10+20261201 3106ec6408d5b9ebbb759ca09a1206e5191223d571af57de5fb34fe8c30fa703 https://github.com/astral-sh/python-build-standalone/releases/download/20261201/cpython-3.14.10+20261201-aarch64-apple-darwin-install_only_stripped.tar.gz
8
+ gcloud 594.0.1 f3d680f1d2bcf89b575bbba309305f2d897236d19b82e7d78462cf632ee2252d https://dl.google.com/dl/cloudsdk/channels/rapid/components/google-cloud-sdk-core-20261121205138.tar.gz
9
+ gcloud 594.0.1 0e7d184def218336a3850e51d64b3f4d680fcbd8e075e63205ae78296d6884cc https://dl.google.com/dl/cloudsdk/channels/rapid/components/google-cloud-sdk-core-nix-20261022194556.tar.gz
10
+ gcloud 594.0.1 da085036b39328aedcf43423e29676f40a7743c593f7165d1e5d7bc0e56d2b69 https://dl.google.com/dl/cloudsdk/channels/rapid/components/google-cloud-sdk-gcloud-deps-20261106082013.tar.gz
11
+ gcloud 594.0.1 3bbd67e1be71d5c67c78561c00cb5694668cab238161ff6a6092c0fab1c3068b https://dl.google.com/dl/cloudsdk/channels/rapid/components/google-cloud-sdk-gcloud-deps-darwin-arm-20260622153051.tar.gz
12
+ gcloud 594.0.1 e26abbb067a73858fd55d2d04fd961663118ddf07d849cd86aefea9a0844025a https://dl.google.com/dl/cloudsdk/channels/rapid/components/google-cloud-sdk-gcloud-crc32c-darwin-arm-20261016073856.tar.gz