@agst/cli 0.2.8 → 0.2.9

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.
Files changed (2) hide show
  1. package/bin/agst.js +93 -41
  2. package/package.json +1 -1
package/bin/agst.js CHANGED
@@ -6,6 +6,11 @@
6
6
  * version), checks its ed25519 signature against the key below, and runs it
7
7
  * with your arguments. No dependencies, so `npx @agst/cli` starts fast.
8
8
  *
9
+ * Which runner: the signed pointer <releases>/runner/latest.json, which
10
+ * runner.yml writes after every upload, so a runner release needs no npm
11
+ * publish. When the pointer can't be fetched or verified, the launcher keeps
12
+ * the runner already installed, or else falls back to RUNNER_VERSION.
13
+ *
9
14
  * Binaries live at <releases>/runner/<version>/august-runner-<platform>,
10
15
  * cached in ~/.august/bin. ~/.august/bin/agst always points at the current
11
16
  * one, so a systemd unit (`agst serve --install`) survives upgrades, and
@@ -13,9 +18,10 @@
13
18
  * release and restarts that unit.
14
19
  *
15
20
  * Environment:
16
- * AGST_HOME cache dir (default ~/.august/bin)
17
- * AGST_RELEASES_URL where binaries are fetched (default releases.agst.me)
18
- * AGST_RUNNER run this binary instead (development)
21
+ * AGST_HOME cache dir (default ~/.august/bin)
22
+ * AGST_RELEASES_URL where binaries are fetched (default releases.agst.me)
23
+ * AGST_RUNNER run this binary instead (development)
24
+ * AGST_RUNNER_VERSION use this runner version, ignoring the pointer
19
25
  */
20
26
 
21
27
  import { spawn, execFileSync } from "node:child_process";
@@ -24,13 +30,22 @@ import fs from "node:fs";
24
30
  import os from "node:os";
25
31
  import path from "node:path";
26
32
 
27
- /** The runner this launcher ships with. Bumped with every agst release. */
33
+ /**
34
+ * The fallback runner, used only when the pointer is unreachable and nothing
35
+ * is installed yet. It doesn't need to move with every runner release.
36
+ */
28
37
  const RUNNER_VERSION = "0.3.7";
29
38
  const RELEASES =
30
39
  process.env.AGST_RELEASES_URL ?? "https://releases.agst.me/runner";
31
- /** The runner signing key (SPKI, base64): the same one sandboxes verify. */
32
- const PUBLIC_KEY =
33
- "MCowBQYDK2VwAyEANIOelkzkxgmMs+OxFfJuJQxF7uhKabc5ILj92UP2/uk=";
40
+ /** The runner signing key: the same one sandboxes verify. */
41
+ const PUBLIC_KEY = createPublicKey({
42
+ key: Buffer.from(
43
+ "MCowBQYDK2VwAyEANIOelkzkxgmMs+OxFfJuJQxF7uhKabc5ILj92UP2/uk=",
44
+ "base64",
45
+ ),
46
+ format: "der",
47
+ type: "spki",
48
+ });
34
49
  const PLATFORMS = new Set(["linux-x64", "linux-arm64", "darwin-arm64"]);
35
50
  /**
36
51
  * How people run this, for the hints the runner prints ("Run `npx @agst/cli
@@ -60,14 +75,64 @@ async function download(url) {
60
75
  return Buffer.from(await response.arrayBuffer());
61
76
  }
62
77
 
78
+ /**
79
+ * The version runner/latest.json names, or undefined when it can't be
80
+ * fetched or its signature (over `agst-runner-latest:<version>`, made by
81
+ * runner.yml with the runner key) doesn't check out.
82
+ */
83
+ async function latestVersion() {
84
+ try {
85
+ const response = await fetch(`${RELEASES}/latest.json`, {
86
+ signal: AbortSignal.timeout(3000),
87
+ });
88
+ if (!response.ok) return undefined;
89
+ const { version, signature } = await response.json();
90
+ if (!/^\d+\.\d+\.\d+$/.test(version) || typeof signature !== "string") {
91
+ return undefined;
92
+ }
93
+ const signed = Buffer.from(`agst-runner-latest:${version}`);
94
+ const valid = verify(
95
+ null,
96
+ signed,
97
+ PUBLIC_KEY,
98
+ Buffer.from(signature, "base64"),
99
+ );
100
+ return valid ? version : undefined;
101
+ } catch {
102
+ return undefined;
103
+ }
104
+ }
105
+
106
+ /** The runner version ~/.august/bin/agst points at, if any. */
107
+ function linkedVersion(binDir) {
108
+ try {
109
+ return versionOf(fs.readlinkSync(path.join(binDir, "agst")));
110
+ } catch {
111
+ return undefined;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * The runner to use: an explicit AGST_RUNNER_VERSION, else the pointer, else
117
+ * whatever is installed (offline keeps working), else the fallback pin.
118
+ */
119
+ async function resolveVersion(binDir) {
120
+ return (
121
+ process.env.AGST_RUNNER_VERSION ??
122
+ (await latestVersion()) ??
123
+ linkedVersion(binDir) ??
124
+ RUNNER_VERSION
125
+ );
126
+ }
127
+
63
128
  /** Fetches and verifies the binary unless it's already cached. */
64
- async function ensureBinary(binDir, platform) {
65
- const file = path.join(binDir, `august-runner-${RUNNER_VERSION}-${platform}`);
129
+ async function ensureBinary(binDir, platform, version) {
130
+ const file = path.join(binDir, `august-runner-${version}-${platform}`);
66
131
  if (fs.existsSync(file)) return file;
67
132
 
68
133
  fs.mkdirSync(binDir, { recursive: true });
69
- const base = `${RELEASES}/${RUNNER_VERSION}/august-runner-${platform}`;
70
- process.stderr.write(`agst: fetching the August runner ${RUNNER_VERSION}…\n`);
134
+ const base = `${RELEASES}/${version}/august-runner-${platform}`;
135
+ process.stderr.write(`agst: fetching the August runner ${version}…\n`);
71
136
  let binary;
72
137
  let signature;
73
138
  try {
@@ -78,12 +143,7 @@ async function ensureBinary(binDir, platform) {
78
143
  } catch (cause) {
79
144
  fail(`couldn't download the runner (${cause.message}).`);
80
145
  }
81
- const key = createPublicKey({
82
- key: Buffer.from(PUBLIC_KEY, "base64"),
83
- format: "der",
84
- type: "spki",
85
- });
86
- if (!verify(null, binary, key, signature)) {
146
+ if (!verify(null, binary, PUBLIC_KEY, signature)) {
87
147
  fail("the downloaded runner failed its signature check. Not running it.");
88
148
  }
89
149
 
@@ -152,13 +212,13 @@ function serviceBinary() {
152
212
  }
153
213
 
154
214
  /**
155
- * `agst update`: bring this box to the newest release and restart the
156
- * service onto it. Runs in the newest launcher: an older one (a stale npx
157
- * cache) hands off to `npx <package>@<latest> update` first, since the
158
- * launcher is what pins the runner. Then the usual fetch + verify + link,
159
- * a restart of the systemd unit if one is installed, and a prune of runner
160
- * binaries older than the previous one. Threads, settings and paired
161
- * devices live outside ~/.august/bin and are never touched.
215
+ * `agst update`: bring this box to the runner the pointer names and restart
216
+ * the service onto it. Runs in the newest launcher: an older one (a stale
217
+ * npx cache) hands off to `npx <package>@<latest> update` first, so launcher
218
+ * fixes arrive too. Then the usual fetch + verify + link, a restart of the
219
+ * systemd unit if one is installed, and a prune of runner binaries other
220
+ * than the current and previous one. Threads, settings and paired devices
221
+ * live outside ~/.august/bin and are never touched.
162
222
  */
163
223
  async function update(binDir, platform) {
164
224
  if (!process.env.AGST_UPDATE_HANDOFF) {
@@ -184,36 +244,28 @@ async function update(binDir, platform) {
184
244
  }
185
245
  }
186
246
 
187
- const link = path.join(binDir, "agst");
188
- let previous;
189
- try {
190
- previous = versionOf(fs.readlinkSync(link));
191
- } catch {
192
- // First install on this box.
193
- }
194
- const runner = await ensureBinary(binDir, platform);
247
+ const previous = linkedVersion(binDir); // undefined on a first install
248
+ const target = await resolveVersion(binDir);
249
+ const runner = await ensureBinary(binDir, platform, target);
195
250
  linkCurrent(binDir, runner);
196
251
  const hasUnit = process.platform === "linux" && fs.existsSync(UNIT_FILE);
197
252
 
198
- if (previous === RUNNER_VERSION) {
253
+ if (previous === target) {
199
254
  // The link can be current while the service still runs the old binary:
200
255
  // an earlier update linked it and then failed before the restart.
201
256
  const running = hasUnit ? serviceBinary() : undefined;
202
257
  if (!running || running === fs.realpathSync(runner)) {
203
- console.log(`agst: already on the newest runner (${RUNNER_VERSION}).`);
258
+ console.log(`agst: already on the newest runner (${target}).`);
204
259
  return;
205
260
  }
206
- console.log(`agst: the service is behind, moving it to ${RUNNER_VERSION}.`);
261
+ console.log(`agst: the service is behind, moving it to ${target}.`);
207
262
  } else {
208
- console.log(
209
- `agst: runner ${previous ? `${previous} → ` : ""}${RUNNER_VERSION}.`,
210
- );
263
+ console.log(`agst: runner ${previous ? `${previous} → ` : ""}${target}.`);
211
264
 
212
265
  // Keep the current binary and the one before it (a quick way back).
213
266
  for (const name of fs.readdirSync(binDir)) {
214
267
  const version = versionOf(name);
215
- if (!version || version === RUNNER_VERSION || version === previous)
216
- continue;
268
+ if (!version || version === target || version === previous) continue;
217
269
  fs.rmSync(path.join(binDir, name), { force: true });
218
270
  }
219
271
  }
@@ -255,7 +307,7 @@ async function main() {
255
307
  `no runner build for ${platform} yet (have: ${[...PLATFORMS].join(", ")}).`,
256
308
  );
257
309
  }
258
- runner = await ensureBinary(binDir, platform);
310
+ runner = await ensureBinary(binDir, platform, await resolveVersion(binDir));
259
311
  stable = linkCurrent(binDir, runner);
260
312
  }
261
313
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agst/cli",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "August agent orchestrator. Run Claude Code and OpenCode agents on any machine and drive them from the August app on your Mac or phone.",
5
5
  "keywords": [
6
6
  "august",