@standardagents/code 0.14.100-canary.564e99 → 0.14.103-canary.806f0c

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/lib/install.mjs CHANGED
@@ -55,7 +55,22 @@ function tar(run, args) {
55
55
  return result.stdout
56
56
  }
57
57
 
58
- export async function installNativeArtifact({ target, root = PACKAGE_ROOT, fetchImplementation = fetch, run = spawnSync, publicKey = undefined }) {
58
+ // Reads a download to the end, reporting each chunk, and refuses a body larger
59
+ // than the published size before it is buffered.
60
+ async function readBody(response, size, onProgress) {
61
+ if (!response.body) return Buffer.from(await response.arrayBuffer())
62
+ const chunks = []
63
+ let received = 0
64
+ for await (const chunk of response.body) {
65
+ received += chunk.length
66
+ if (received > size) throw new Error('The downloaded native archive does not match its published size and digest')
67
+ chunks.push(chunk)
68
+ onProgress(received, size)
69
+ }
70
+ return Buffer.concat(chunks, received)
71
+ }
72
+
73
+ export async function installNativeArtifact({ target, root = PACKAGE_ROOT, fetchImplementation = fetch, run = spawnSync, publicKey = undefined, onProgress = () => {} }) {
59
74
  const installed = installedArtifact(target, root, publicKey)
60
75
  if (installed) return installed.directory
61
76
  const metadata = packageMetadata(root)
@@ -63,7 +78,7 @@ export async function installNativeArtifact({ target, root = PACKAGE_ROOT, fetch
63
78
  if (!pointer) throw new Error(`This package carries no native archive for ${target}`)
64
79
  const response = await fetchImplementation(pointer.url)
65
80
  if (!response.ok) throw new Error(`Downloading the native archive failed with HTTP ${response.status}`)
66
- const bytes = Buffer.from(await response.arrayBuffer())
81
+ const bytes = await readBody(response, pointer.size, onProgress)
67
82
  if (bytes.length !== pointer.size || createHash('sha256').update(bytes).digest('hex') !== pointer.sha256) {
68
83
  throw new Error('The downloaded native archive does not match its published size and digest')
69
84
  }
package/lib/launcher.mjs CHANGED
@@ -7,6 +7,7 @@ import process from 'node:process'
7
7
  import { platformPackage } from './platform.mjs'
8
8
  import { artifactBinaryPath, requireCompatibleGlibc, verifyNativeArtifact } from './artifact.mjs'
9
9
  import { artifactPointer, installNativeArtifact, installedArtifact, nativeDirectory, packageMetadata } from './install.mjs'
10
+ import { createSteps, megabytes, progressBar } from './progress.mjs'
10
11
 
11
12
  const require = createRequire(import.meta.url)
12
13
  const COMMANDS = new Set(['standard', 'standardd'])
@@ -121,22 +122,33 @@ export async function ensureNativeBinaries(options = {}) {
121
122
  } catch {
122
123
  // No npm platform package: download the archive.
123
124
  }
124
- const log = options.log ?? (message => console.error(message))
125
- log(`standard: installing the native build for ${platform.rustTarget} (first launch)`)
125
+ const steps = createSteps({ stream: options.stream, environment: options.environment, version: packageMetadata(options.packageRoot).version })
126
+ steps.header()
127
+ const step = steps.start('Downloading Standard Code')
126
128
  try {
127
- await installNativeArtifact({ target: platform.rustTarget, root: options.packageRoot, fetchImplementation: options.fetchImplementation })
129
+ await installNativeArtifact({
130
+ target: platform.rustTarget,
131
+ root: options.packageRoot,
132
+ fetchImplementation: options.fetchImplementation,
133
+ onProgress: (received, total) => step.update(`${progressBar(received, total)} ${megabytes(received)} of ${megabytes(total)} MB`),
134
+ })
128
135
  } catch (error) {
129
136
  if (error?.code === 'EACCES' || error?.code === 'EPERM') {
130
- throw new Error(
131
- `cannot write the native build under ${nativeDirectory(platform.rustTarget, options.packageRoot)}. `
137
+ const message = `Cannot write the native build under ${nativeDirectory(platform.rustTarget, options.packageRoot)}. `
132
138
  + 'The package belongs to another user (for example an npm install run with sudo); '
133
- + 'reinstall @standardagents/code with an npm prefix you own.',
134
- )
139
+ + 'reinstall @standardagents/code with an npm prefix you own.'
140
+ step.fail('Download did not complete', message)
141
+ throw new ReportedError(message)
135
142
  }
136
- throw error
143
+ step.fail('Download did not complete', error instanceof Error ? error.message : String(error))
144
+ throw new ReportedError(String(error))
137
145
  }
146
+ step.done(`Downloaded Standard Code (${megabytes(artifactPointer(packageMetadata(options.packageRoot), platform.rustTarget).size)} MB)`)
138
147
  }
139
148
 
149
+ // An error the setup progress already showed.
150
+ class ReportedError extends Error {}
151
+
140
152
  export async function main(command) {
141
153
  try {
142
154
  await ensureNativeBinaries()
@@ -149,8 +161,10 @@ export async function main(command) {
149
161
  }
150
162
  process.exitCode = result.status ?? 1
151
163
  } catch (error) {
152
- const detail = error instanceof Error ? error.message : String(error)
153
- console.error(`${command}: ${detail}`)
164
+ if (!(error instanceof ReportedError)) {
165
+ const detail = error instanceof Error ? error.message : String(error)
166
+ console.error(`${command}: ${detail}`)
167
+ }
154
168
  process.exitCode = 1
155
169
  }
156
170
  }
@@ -0,0 +1,62 @@
1
+ import process from 'node:process'
2
+
3
+ // First-launch progress on stderr, in the same layout the native client uses
4
+ // for its sign-in and daemon steps. The launcher prints the header, so it
5
+ // tells the native client not to print it again.
6
+ export const HEADER_SHOWN = 'STANDARD_SETUP_HEADER_SHOWN'
7
+ const FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
8
+ const BAR = 24
9
+
10
+ export function megabytes(bytes) {
11
+ return (bytes / 1_000_000).toFixed(1)
12
+ }
13
+
14
+ export function progressBar(received, total, width = BAR) {
15
+ const filled = total > 0 ? Math.min(width, Math.round((received / total) * width)) : 0
16
+ return '█'.repeat(filled) + '░'.repeat(width - filled)
17
+ }
18
+
19
+ export function createSteps({ stream = process.stderr, environment = process.env, version = '' } = {}) {
20
+ const live = Boolean(stream.isTTY)
21
+ const color = live && environment.NO_COLOR === undefined
22
+ const paint = (code, text) => (color ? `\x1b[${code}m${text}\x1b[0m` : text)
23
+ return {
24
+ header() {
25
+ stream.write(`\n ${paint('1', 'Standard Code')} ${paint('2', version)}\n\n`)
26
+ environment[HEADER_SHOWN] = '1'
27
+ },
28
+ start(label) {
29
+ let frame = 0
30
+ let detail = ''
31
+ const draw = () => stream.write(`\r\x1b[2K ${paint('33', FRAMES[frame])} ${label}${detail}`)
32
+ let timer = null
33
+ if (live) {
34
+ draw()
35
+ // The animation only redraws this line; it is not a status poll.
36
+ timer = setInterval(() => {
37
+ frame = (frame + 1) % FRAMES.length
38
+ draw()
39
+ }, 80)
40
+ } else {
41
+ stream.write(` … ${label}\n`)
42
+ }
43
+ const halt = () => {
44
+ if (timer) clearInterval(timer)
45
+ if (live) stream.write('\r\x1b[2K')
46
+ }
47
+ return {
48
+ update(text) {
49
+ detail = text ? ` ${paint('2', text)}` : ''
50
+ },
51
+ done(text) {
52
+ halt()
53
+ stream.write(` ${paint('32', '✓')} ${text}\n`)
54
+ },
55
+ fail(text, cause) {
56
+ halt()
57
+ stream.write(` ${paint('31', '✗')} ${text}\n ${paint('2', cause)}\n\n`)
58
+ },
59
+ }
60
+ },
61
+ }
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standardagents/code",
3
- "version": "0.14.100-canary.564e99",
3
+ "version": "0.14.103-canary.806f0c",
4
4
  "description": "Platform launcher for the Standard universal terminal network.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -27,14 +27,14 @@
27
27
  "schema": 1,
28
28
  "targets": {
29
29
  "aarch64-apple-darwin": {
30
- "url": "https://builds.standardcode.ai/artifacts/0.14.100-canary.564e99/aarch64-apple-darwin.tar.gz",
31
- "sha256": "e396de4733caa2bc3a7a83b4a16ae27885c2a4a4827bd29cb628decd9ef013bc",
32
- "size": 30575920
30
+ "url": "https://builds.standardcode.ai/artifacts/0.14.103-canary.806f0c/aarch64-apple-darwin.tar.gz",
31
+ "sha256": "b2326590c98bab9f4ef881738ae3318b896a7d5cf9ad6934d8bc2e71ce7625c1",
32
+ "size": 30670441
33
33
  },
34
34
  "x86_64-unknown-linux-gnu": {
35
- "url": "https://builds.standardcode.ai/artifacts/0.14.100-canary.564e99/x86_64-unknown-linux-gnu.tar.gz",
36
- "sha256": "a75261aa25a5a49edf625e05cf93e647b0ef9416ee15f0757d71fbda9c3e339d",
37
- "size": 29524726
35
+ "url": "https://builds.standardcode.ai/artifacts/0.14.103-canary.806f0c/x86_64-unknown-linux-gnu.tar.gz",
36
+ "sha256": "5772d3ee4fc434a3791e2a382213e466de1c3dfef465076a0cd45bd639c34527",
37
+ "size": 29655260
38
38
  }
39
39
  }
40
40
  },