@astrofoundry/astrogate 0.1.7 → 0.1.8

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/cli/astrogate.sh CHANGED
@@ -236,17 +236,22 @@ pinned_version() {
236
236
  /usr/bin/awk -v t="$2" '$1 == t && NF == 4 { print $2; exit }' "$1/tools.lock"
237
237
  }
238
238
 
239
- # Fails unless core folder $1 has no tools.lock, or one whose lines are all
240
- # "<tool> <version> <sha256> <https url>" with one valid version per tool.
241
- check_lock() {
242
- [ -f "$1/tools.lock" ] || return 0
243
- bad_line=$(/usr/bin/awk -v names=" $TOOL_NAMES " '
239
+ # Fails unless lock file $1 has only "<tool> <version> <sha256> <https url>" lines, with tools
240
+ # among the names $2, hosts the pattern $3 matches, and one version per tool. A pattern writes a
241
+ # dot as [.]: awk would read a backslash in a -v value as an escape.
242
+ check_lock_lines() {
243
+ bad_line=$(/usr/bin/awk -v names=" $2 " -v url="^https://($3)/[A-Za-z0-9./_+@-]+$" '
244
244
  /^#/ || NF == 0 { next }
245
- NF != 4 || index(names, " " $1 " ") == 0 || length($3) != 64 || $3 !~ /^[0-9a-f]+$/ { print NR; exit }
246
- $4 !~ /^https:\/\/(nodejs\.org|github\.com|dl\.google\.com)\/[A-Za-z0-9.\/_+-]+$/ { print NR; exit }
245
+ NF != 4 || index(names, " " $1 " ") == 0 || length($3) != 64 || $3 !~ /^[0-9a-f]+$/ || $4 !~ url { print NR; exit }
247
246
  ($1 in seen) && seen[$1] != $2 { print NR; exit }
248
- { seen[$1] = $2 }' "$1/tools.lock")
249
- [ -z "$bad_line" ] || fail "$1/tools.lock line $bad_line is no <tool> <version> <sha256> <https url>, or pins a second version"
247
+ { seen[$1] = $2 }' "$1")
248
+ [ -z "$bad_line" ] || fail "$1 line $bad_line is no <tool> <version> <sha256> <https url>, or pins a second version"
249
+ }
250
+
251
+ # Fails unless core folder $1 has no tools.lock, or one with valid lines and versions.
252
+ check_lock() {
253
+ [ -f "$1/tools.lock" ] || return 0
254
+ check_lock_lines "$1/tools.lock" "$TOOL_NAMES" 'nodejs[.]org|github[.]com|dl[.]google[.]com'
250
255
  for tool in $TOOL_NAMES; do
251
256
  pin=$(pinned_version "$1" "$tool")
252
257
  [ -z "$pin" ] || tool_version_ok "$tool" "$pin" || fail "$1/tools.lock pins $tool $pin, which is no valid version"
@@ -9,7 +9,7 @@ const isRoot = process.getuid?.() === 0;
9
9
  const isMac = process.platform === "darwin";
10
10
  const REPO = join(import.meta.dirname, "..");
11
11
  const SHA = "a".repeat(64);
12
- const TOOL_FUNCTIONS = ["fail", "valid_version", "valid_python_version", "tool_version_ok", "pinned_version", "check_lock"];
12
+ const TOOL_FUNCTIONS = ["fail", "valid_version", "valid_python_version", "tool_version_ok", "pinned_version", "check_lock_lines", "check_lock"];
13
13
 
14
14
  function astrogate(...args: string[]) {
15
15
  return spawnSync("/bin/sh", [SCRIPT, ...args], { encoding: "utf-8" });
package/cli/workspace.sh CHANGED
@@ -244,6 +244,115 @@ mkdir -p "$HOME/.claude/agents"
244
244
  "$node" --preserve-symlinks-main "$bundle" agents "$HOME/.claude/agents" "$node"
245
245
  "$node" --preserve-symlinks-main "$bundle" settings "$HOME/.claude/settings.json" "$node"'
246
246
 
247
+ # Tools a pack pins in site/tools.lock, the same line format as the core's: they install into the
248
+ # keys user's home, each download checked against the signed pack's sha256.
249
+ PACK_TOOLS="arcane-cli trendarr"
250
+ PACK_TOOL_HOSTS='github[.]com|registry[.]npmjs[.]org'
251
+
252
+ ARCANE_VERSION='out=$("$HOME/.specialists/bin/arcane-cli" --version 2>/dev/null) || exit 0
253
+ printf "%s\n" "$out" | awk '"'"'{ for (i = 1; i < NF; i++) if ($i == "version") { print $(i + 1); exit } }'"'"''
254
+
255
+ # Swaps in the staged arcane-cli after it reports version $2; the old one stays as arcane-cli.previous.
256
+ INSTALL_ARCANE='stage=$1; v=$2
257
+ bin="$HOME/.specialists/bin"
258
+ check() { "$1" --version 2>/dev/null | awk -v v="$v" '"'"'{ for (i = 1; i < NF; i++) if ($i == "version" && $(i + 1) == v) f = 1 } END { exit !f }'"'"'; }
259
+ mkdir -p "$bin"
260
+ cp "$stage/arcane-cli" "$bin/.arcane-cli.new"
261
+ chmod 0700 "$bin/.arcane-cli.new"
262
+ check "$bin/.arcane-cli.new" || { rm -f "$bin/.arcane-cli.new"; echo "the new arcane-cli does not report version $v" >&2; exit 1; }
263
+ had=no
264
+ if [ -e "$bin/arcane-cli" ]; then mv "$bin/arcane-cli" "$bin/arcane-cli.previous"; had=yes; fi
265
+ mv "$bin/.arcane-cli.new" "$bin/arcane-cli"
266
+ if ! check "$bin/arcane-cli"; then
267
+ rm -f "$bin/arcane-cli"
268
+ [ "$had" = no ] || mv "$bin/arcane-cli.previous" "$bin/arcane-cli"
269
+ echo "restored the previous arcane-cli" >&2
270
+ exit 1
271
+ fi'
272
+
273
+ # trendarr lives in versioned folders behind the stable link bin/trendarr, so media.json's
274
+ # trendarrCli path never changes; bin/trendarr.previous keeps the last one.
275
+ TRENDARR_COMMON='bin="$HOME/.specialists/bin"
276
+ cli() { printf "%s/node_modules/@astrofoundry/trendarr/dist/cli.js" "$1"; }
277
+ version_of() { plutil -extract version raw -o - "$1/node_modules/@astrofoundry/trendarr/package.json" 2>/dev/null; }
278
+ link() { rm -f "$bin/.$1.tmp"; ln -s "$2" "$bin/.$1.tmp"; mv -h "$bin/.$1.tmp" "$bin/$1"; }'
279
+
280
+ TRENDARR_VERSION="$TRENDARR_COMMON"'
281
+ [ -e "$bin/trendarr" ] || exit 0
282
+ version_of "$bin/trendarr" || exit 0'
283
+
284
+ # npm installs the checked tarball and its dependencies, without install scripts.
285
+ INSTALL_TRENDARR="$TRENDARR_COMMON"'
286
+ node=$1; npm=$2; tarball=$3; v=$4
287
+ dir="$bin/trendarr-$v"
288
+ mkdir -p "$bin"
289
+ rm -rf "$dir.partial"
290
+ "$node" "$npm" install --prefix "$dir.partial" --omit=dev --ignore-scripts --no-audit --no-fund --no-update-notifier "$tarball" >/dev/null
291
+ [ "$("$node" "$(cli "$dir.partial")" --version)" = "$v" ] || { rm -rf "$dir.partial"; echo "trendarr $v does not report its version" >&2; exit 1; }
292
+ before=$(readlink "$bin/trendarr" 2>/dev/null || true)
293
+ rm -rf "$dir"
294
+ mv "$dir.partial" "$dir"
295
+ link trendarr "trendarr-$v"
296
+ if [ "$("$node" "$(cli "$bin/trendarr")" --version)" != "$v" ]; then
297
+ if [ -n "$before" ]; then link trendarr "$before"; else rm -f "$bin/trendarr"; fi
298
+ echo "restored the previous trendarr" >&2
299
+ exit 1
300
+ fi
301
+ if [ -n "$before" ] && [ "$before" != "trendarr-$v" ]; then link trendarr.previous "$before"; fi
302
+ keep=$(readlink "$bin/trendarr.previous" 2>/dev/null || true)
303
+ for d in "$bin"/trendarr-*; do
304
+ [ -d "$d" ] || continue
305
+ n=${d##*/}
306
+ [ "$n" = "trendarr-$v" ] || [ "$n" = "$keep" ] || rm -rf "$d"
307
+ done'
308
+
309
+ # Downloads every pack tool the pack folder $1 pins into $work/tools-<tool>, each checked against its sha256.
310
+ fetch_pack_tools() {
311
+ [ -f "$1/site/tools.lock" ] || return 0
312
+ check_lock_lines "$1/site/tools.lock" "$PACK_TOOLS" "$PACK_TOOL_HOSTS"
313
+ for tool in $PACK_TOOLS; do
314
+ pin=$(pinned_version "$1/site" "$tool")
315
+ [ -n "$pin" ] || continue
316
+ valid_version "$pin" || fail "site/tools.lock pins $tool $pin, which is no valid version"
317
+ /bin/mkdir -p "$work/tools-$tool"
318
+ downloads=$(/usr/bin/awk -v t="$tool" '$1 == t && NF == 4 { print $3, $4 }' "$1/site/tools.lock")
319
+ while read -r sum url; do
320
+ file=$work/tools-$tool/${url##*/}
321
+ fetch "$url" "$file"
322
+ [ "$(/usr/bin/shasum -a 256 "$file" | /usr/bin/cut -d' ' -f1)" = "$sum" ] || fail "checksum mismatch for $url"
323
+ done <<DOWNLOADS
324
+ $downloads
325
+ DOWNLOADS
326
+ done
327
+ }
328
+
329
+ # Installs the fetched pack tools as the keys user, each only when its version changes.
330
+ install_pack_tools() {
331
+ [ -f "$1/site/tools.lock" ] || return 0
332
+ pin=$(pinned_version "$1/site" arcane-cli)
333
+ if [ -n "$pin" ] && [ "$(as_user "$keys" "$ARCANE_VERSION")" != "$pin" ]; then
334
+ /bin/mkdir "$work/acli"
335
+ for archive in "$work/tools-arcane-cli"/*; do /usr/bin/tar -xzf "$archive" --no-same-owner -C "$work/acli"; done
336
+ cli=$(/usr/bin/find "$work/acli" -type f -name arcane-cli | /usr/bin/head -n 1)
337
+ [ -n "$cli" ] || fail "no arcane-cli binary in the pinned download"
338
+ tool_stage=$(user_stage "$keys-arcane")
339
+ /bin/cp "$cli" "$tool_stage/arcane-cli"
340
+ hand_stage "$keys" "$tool_stage"
341
+ as_user "$keys" "$INSTALL_ARCANE" "$tool_stage" "$pin" || fail "arcane-cli $pin failed its check"
342
+ echo "arcane-cli $pin installed"
343
+ fi
344
+ pin=$(pinned_version "$1/site" trendarr)
345
+ if [ -n "$pin" ] && [ "$(as_user "$keys" "$TRENDARR_VERSION")" != "$pin" ]; then
346
+ npm=$TOOLS/node/current/lib/node_modules/npm/bin/npm-cli.js
347
+ [ -f "$npm" ] || fail "the core's Node has no npm"
348
+ tool_stage=$(user_stage "$keys-trendarr")
349
+ /bin/cp "$work/tools-trendarr"/*.tgz "$tool_stage/trendarr.tgz"
350
+ hand_stage "$keys" "$tool_stage"
351
+ as_user "$keys" "$INSTALL_TRENDARR" "$NODE" "$npm" "$tool_stage/trendarr.tgz" "$pin" || fail "trendarr $pin failed its check"
352
+ echo "trendarr $pin installed"
353
+ fi
354
+ }
355
+
247
356
  # The services pack.json $1 names, checked, one per line; fails on none, a bad name, or a repeat.
248
357
  pack_services() {
249
358
  i=0
@@ -303,6 +412,7 @@ pack_update() {
303
412
  src=$work/pkg/specialists
304
413
  [ -d "$src/lib" ] && [ -f "$src/provision/provision.sh" ] || fail "the pack has no specialists/lib or provision.sh"
305
414
  services=$(pack_services "$manifest")
415
+ fetch_pack_tools "$work/pkg"
306
416
  wrappers=$(user_stage "$keys")
307
417
  /bin/cp -R "$src/lib" "$wrappers/lib"
308
418
  for s in $services; do
@@ -325,7 +435,8 @@ pack_update() {
325
435
  hand_stage "$keys" "$wrappers"
326
436
  hand_stage "$agent" "$agent_pack"
327
437
  as_user "$keys" "$SWAP_WRAPPERS" "$NODE" "$wrappers" $services || fail "pack $version failed its check; ${installed:-no} previous version kept"
438
+ install_pack_tools "$work/pkg"
328
439
  as_user "$agent" "$SWAP_AGENT_PACK" "$JQ" "$agent_pack" || fail "the agent side of pack $version failed; the wrappers are in, run the update again"
329
440
  as_user "$agent" "$CLAUDE_FILES" "$NODE" "$BASE/current/dist/claude.js" >/dev/null || fail "the Claude Code files of $agent failed; run the update again"
330
- echo "pack $version in workspace $ws: wrappers, config, agents, skills, bridge plugin, gate, Claude Code agents${installed:+; previous $installed}"
441
+ echo "pack $version in workspace $ws: wrappers, config, tools, agents, skills, bridge plugin, gate, Claude Code agents${installed:+; previous $installed}"
331
442
  }
@@ -20,11 +20,11 @@ function shellFunctions(names: string[], call: string) {
20
20
  return spawnSync("/bin/sh", ["-c", `set -eu\nfail() { echo "$*" >&2; exit 1; }\n${bodies.join("\n")}\n${call}`], { encoding: "utf-8" });
21
21
  }
22
22
 
23
- /** The body of a single-quoted shell variable of workspace.sh, a script that runs as a workspace user. */
23
+ /** The value of a workspace.sh variable that holds a script for a workspace user, as the shell reads it. */
24
24
  function userScript(name: string): string {
25
- const body = new RegExp(`^${name}='([^']*)'$`, "m").exec(readFileSync(SCRIPT, "utf-8"))?.[1];
26
- if (body === undefined) throw new Error(`${name} not found in the script`);
27
- return body;
25
+ const result = spawnSync("/bin/sh", ["-c", `TOOLS=/t; . '${SCRIPT}'; printf '%s' "$${name}"`], { encoding: "utf-8" });
26
+ if (result.status !== 0 || result.stdout === "") throw new Error(`${name} not found in the script: ${result.stderr}`);
27
+ return result.stdout;
28
28
  }
29
29
 
30
30
  function runAs(home: string, name: string, ...args: string[]) {
@@ -207,3 +207,36 @@ describe("astrogate-run", () => {
207
207
  expect(result.stderr).toContain(message);
208
208
  });
209
209
  });
210
+
211
+ describe("pack tools", () => {
212
+ it("swaps in an arcane-cli that reports the pinned version and keeps the old one", () => {
213
+ const dir = mkdtempSync(join(tmpdir(), "pack-arcane-"));
214
+ try {
215
+ const home = join(dir, "home");
216
+ mkdirSync(home);
217
+ const stage = (version: string) => {
218
+ const s = join(dir, `stage-${version}`);
219
+ mkdirSync(s);
220
+ writeFileSync(join(s, "arcane-cli"), `#!/bin/sh\necho "arcane-cli version ${version}"\n`, { mode: 0o755 });
221
+ return s;
222
+ };
223
+ expect(runAs(home, "ARCANE_VERSION").stdout).toBe("");
224
+ expect(runAs(home, "INSTALL_ARCANE", stage("3.2.1"), "3.2.1").status).toBe(0);
225
+ expect(runAs(home, "ARCANE_VERSION").stdout).toBe("3.2.1\n");
226
+ const wrong = runAs(home, "INSTALL_ARCANE", stage("3.2.2"), "3.3.0");
227
+ expect(wrong.stderr).toContain("does not report version 3.3.0");
228
+ expect(runAs(home, "ARCANE_VERSION").stdout).toBe("3.2.1\n");
229
+ expect(runAs(home, "INSTALL_ARCANE", stage("3.3.0"), "3.3.0").status).toBe(0);
230
+ expect(runAs(home, "ARCANE_VERSION").stdout).toBe("3.3.0\n");
231
+ expect(existsSync(join(home, ".specialists", "bin", "arcane-cli.previous"))).toBe(true);
232
+ } finally {
233
+ rmSync(dir, { recursive: true, force: true });
234
+ }
235
+ });
236
+
237
+ it("names the pack tools and their download hosts in one place", () => {
238
+ const text = readFileSync(SCRIPT, "utf-8");
239
+ expect(text).toContain('PACK_TOOLS="arcane-cli trendarr"');
240
+ expect(text).toContain("PACK_TOOL_HOSTS='github[.]com|registry[.]npmjs[.]org'");
241
+ });
242
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/astrogate",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
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": {
package/release.sha256 CHANGED
@@ -3,12 +3,12 @@ b9b0f9fa90b9a230157de1fefef1aa5a624bfd7b50527b67ad86ecc62414aadb agents/foreman
3
3
  4091f50a5a9ff72e2f1571c6de054d9c891dbe294aa58e6a55ad9a1bff2f766a cli/astro-install.sh
4
4
  9f371247fdaea09e1551f940fd91eacb7d242baea343fce66f12fc8e22ba064b cli/astro.sh
5
5
  8e054f8286876b77e0887d0b0e2a62d4a048fd41bfa0048d126e0c9171869cf6 cli/astro.test.ts
6
- fcaa22165a9eb71c5602b80f5bb9f715030ee43d57b816e8592931e61471d818 cli/astrogate.sh
7
- 448bfae7119dc5fbc89ace088d71c3ed6a8a170e0c862624a2a383bfacd74786 cli/astrogate.test.ts
6
+ b6d6a42fffba89e8456e668a1e5d6e7b1c1ce3c1c9ed4d674cdc487ea4af8340 cli/astrogate.sh
7
+ 14fe7aeb17c89708f5d26f6224756f2aad3083e470bc5c8b907303714d6fcc62 cli/astrogate.test.ts
8
8
  07b9aef7e5d0ee43959e0c16e00ec3a202769c94faea4167257513bf15b9383c cli/verify-release.sh
9
9
  29614fd0eb1ad08215baf827b00ee2b98ccb73ca0ccf770bc5a0084c71da5926 cli/verify-release.test.ts
10
- 303df3526339b36483396d20a9378800a78d005ea5bf5195390e8f7e2ae4368d cli/workspace.sh
11
- 8343f04a5509ad5bd216a94d56f376e214650aec99c4993ba506bebd3ec81725 cli/workspace.test.ts
10
+ d2d6a57b6848067b466d357d9338460cd97d24283b111ef7b9deea56408b8cd0 cli/workspace.sh
11
+ e7851bc2fccc1cdae49ce8444bda7caeb781748665a4da95c01d81d94b5bb918 cli/workspace.test.ts
12
12
  87077122362031c7496ad6c191c00bd3ab90e39d8901286f78462ddbb7c76bae dist/bridge.js
13
13
  06d6ce0f4763fe1552573336ad32e5dff23fc5e1e8a2b4243c974b6f7e439840 dist/claude.js
14
14
  04ed58933a8ff2c05d92df0068038a6003c8b2fbc2f323a377fa530a16a3a867 dist/extensions/bridge/index.js
@@ -72,7 +72,7 @@ e6a327ff2e489bb9f3ed72d4e7eed207f9f2532e1da9b1d520ccf74aeaf594b5 harness/claude
72
72
  e1d07bd981bd4ff6385246b6c1ad41349718c1e490b2bff675291dc7b568cd69 harness/claude/mcp.ts
73
73
  194b623038d56a2565ad42d30d1db72ca453e654bfc84996800362e8a972282b harness/claude/settings.ts
74
74
  987ae3b35d82ae3212cc70d12cff6913ac3f91a803fe7056ccd8010a8f960d2f pack_signers
75
- 2f3f7d0bd41b9fdc1a06034e3d97253168242866976a8fb97ff8f346d61bcf27 package.json
75
+ 42ca45c84ac2b36434fbe2dd93451f821f7881609a929afdd0b33e41420b93ce package.json
76
76
  642383b14db5dbfb7caa6a185591263e4294a73323bf4c78606f7b85f0817fd0 specialists/AGENTS.md
77
77
  a385cf5e3b59de30b5ed9b0840d6cf6198b577668f18dfd5de13a714fb047c3e specialists/README.md
78
78
  270cf6cf3b4df6246d0aa8714ed02bd505e5a78c00f35fded4d20a6ac0382f30 specialists/entry/astrogate-run.sh
@@ -100,5 +100,5 @@ cf173051f31cc92bc3715cf05c27e78ad000148136eca2deb402a0565a955c63 specialists/li
100
100
  c1abde1e550c0f4703fd0b2536cc4002c7edf6468c18a03ebaa516fd1ce093c3 specialists/lib/ssh.ts
101
101
  31959f525a0b0aff070b4a19a9677d446d3425481e936dcd9ca2d957f4e51142 specialists/lib/tunnel.test.ts
102
102
  ed93bfcef355a0a3aa7d679395b2f6ce9ce4c5709253fda7f63c1f3927f5d324 specialists/lib/tunnel.ts
103
- 7a36850a90c3a5e8c2a02fe386f93a0b6e664431799154f548e7ac9f33e84a90 specialists/provision/provision.sh
103
+ b116df8b203f1a3353cca404d519dd838122392b1c2ef292aa5716b62839e65a specialists/provision/provision.sh
104
104
  d182f87697c383c29075dc8b5415fc6fa3832ab33ccf14d5df8a941d9435b5c9 tools.lock
@@ -1,6 +1,6 @@
1
1
  -----BEGIN SSH SIGNATURE-----
2
2
  U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUteIwPdKqPwfNc4vHQPUE+JWMC
3
3
  nmuMUwttLeX5wtyIoAAAAOYXN0cm9nYXRlLWNvcmUAAAAAAAAABnNoYTUxMgAAAFMAAAAL
4
- c3NoLWVkMjU1MTkAAABARv+rEBkEdTqJ5xwiThakdabKpYxQQ4Dp2lJkmETbkHQkMUBojI
5
- Z00gJ95yYTZ77yCwQPcHqiqofV7vfcQROJDA==
4
+ c3NoLWVkMjU1MTkAAABAbY0iFrYWd84L/4RUgVlTVjR4tCBNLaRav/kT0sI5JGEDsDTHHt
5
+ AWnJT8FYTiyN4i+JAZD92Y7M12OL4YxrAOCg==
6
6
  -----END SSH SIGNATURE-----
@@ -2,7 +2,7 @@
2
2
  # specialist-provision: copy every Secure Note of the Vaultwarden collection
3
3
  # `specialists` into ~/.specialists/secrets/<note>/<FIELD> (mode 0600).
4
4
  # Fields ending in _B64 are base64-decoded and written without the suffix.
5
- # Runs as the `specialist` user. Idempotent; stale fields are removed.
5
+ # Runs as a workspace's keys user, with the core's bw and jq. Idempotent; stale fields are removed.
6
6
  set -eu
7
7
  umask 077
8
8
 
@@ -12,8 +12,8 @@ client_file="$config_dir/client.env"
12
12
  password_file="$config_dir/master-password"
13
13
  root="$home/.specialists"
14
14
  collection_name="${SPECIALISTS_COLLECTION:-specialists}"
15
- BW=/usr/local/libexec/specialist-bw/current/bw
16
- JQ=/usr/local/libexec/specialist-jq/current/jq
15
+ BW=/usr/local/libexec/astrogate/tools/bw/current/bw
16
+ JQ=/usr/local/libexec/astrogate/tools/jq/current/jq
17
17
 
18
18
  for f in "$client_file" "$password_file"; do
19
19
  [ -f "$f" ] || { echo "missing $f" >&2; exit 2; }