@standardagents/code 0.14.2-linux-x64-gnu → 0.14.3-canary.6cc75f
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/bin/standard.mjs +4 -0
- package/bin/standardd.mjs +4 -0
- package/lib/artifact.mjs +363 -0
- package/lib/backend-profile.mjs +114 -0
- package/lib/install.mjs +93 -0
- package/lib/launcher.mjs +149 -0
- package/lib/platform.mjs +50 -0
- package/package.json +38 -18
- package/bin/standard +0 -0
- package/bin/standardd +0 -0
- package/bin/tmux +0 -0
- package/licenses/THIRD-PARTY.txt +0 -152
- package/manifest.json +0 -1
- package/manifest.sig +0 -1
package/bin/standard.mjs
ADDED
package/lib/artifact.mjs
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { createHash, createPublicKey, verify } from 'node:crypto'
|
|
2
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, readdirSync } from 'node:fs'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { isPreviewBuild, normalizeBackendProfile } from './backend-profile.mjs'
|
|
5
|
+
|
|
6
|
+
export const ARTIFACT_FORMAT = 'standard-npm-native-target-v2'
|
|
7
|
+
export const ARTIFACT_FILES = Object.freeze([
|
|
8
|
+
'bin/standard', 'bin/standardd', 'bin/tmux', 'licenses/THIRD-PARTY.txt',
|
|
9
|
+
])
|
|
10
|
+
export const BUNDLE_ARTIFACT_FORMAT = 'standard-npm-native-target-v3'
|
|
11
|
+
export const BUNDLE_ARTIFACT_FILES = Object.freeze([
|
|
12
|
+
// Stapled notarization tickets are distinct from the code signature seals.
|
|
13
|
+
'Standard Code.app/Contents/CodeResources',
|
|
14
|
+
'Standard Code.app/Contents/Info.plist',
|
|
15
|
+
'Standard Code.app/Contents/MacOS/standard',
|
|
16
|
+
'Standard Code.app/Contents/_CodeSignature/CodeResources',
|
|
17
|
+
'Standard Code Daemon.app/Contents/CodeResources',
|
|
18
|
+
'Standard Code Daemon.app/Contents/Info.plist',
|
|
19
|
+
'Standard Code Daemon.app/Contents/MacOS/standardd',
|
|
20
|
+
'Standard Code Daemon.app/Contents/Helpers/tmux',
|
|
21
|
+
'Standard Code Daemon.app/Contents/_CodeSignature/CodeResources',
|
|
22
|
+
...['TMUX-ARTIFACT-MANIFEST.sha256', 'TMUX-ARTIFACT-METADATA.txt',
|
|
23
|
+
'TMUX-BUILD-TOOLS.txt', 'TMUX-OTOOL-L.txt', 'TMUX-SIGNED-RUNTIME.sha256',
|
|
24
|
+
'licenses/libevent.txt', 'licenses/tmux.txt',
|
|
25
|
+
].map(path => `Standard Code Daemon.app/Contents/Resources/tmux/${path}`),
|
|
26
|
+
'licenses/THIRD-PARTY.txt',
|
|
27
|
+
])
|
|
28
|
+
|
|
29
|
+
export const RUNNER_ASSET_NAMES = Object.freeze([
|
|
30
|
+
'index.mjs', 'worker.mjs', 'loader.mjs', 'sdk.mjs', 'runtime.json', 'THIRD-PARTY.txt',
|
|
31
|
+
])
|
|
32
|
+
export const MAX_RUNNER_ASSET_BYTES = 16 * 1024 * 1024
|
|
33
|
+
export const RUNNER_ARTIFACT_FILES = Object.freeze([
|
|
34
|
+
...ARTIFACT_FILES, ...RUNNER_ASSET_NAMES.map(name => `lib/standard-plugin-runner/${name}`),
|
|
35
|
+
])
|
|
36
|
+
export const BUNDLE_RUNNER_ARTIFACT_FILES = Object.freeze([
|
|
37
|
+
...BUNDLE_ARTIFACT_FILES,
|
|
38
|
+
...RUNNER_ASSET_NAMES.map(name => `Standard Code Daemon.app/Contents/Resources/plugin-runner/${name}`),
|
|
39
|
+
])
|
|
40
|
+
|
|
41
|
+
export function artifactFiles(manifest) {
|
|
42
|
+
const hasRunner = manifest.files?.some(file => file.path?.includes('/plugin-runner/') || file.path?.startsWith('lib/standard-plugin-runner/'))
|
|
43
|
+
if (manifest.schema === 2 && manifest.format === ARTIFACT_FORMAT
|
|
44
|
+
&& manifest.target?.endsWith('-unknown-linux-gnu')) return hasRunner ? RUNNER_ARTIFACT_FILES : ARTIFACT_FILES
|
|
45
|
+
if (manifest.schema === 3 && manifest.format === BUNDLE_ARTIFACT_FORMAT
|
|
46
|
+
&& manifest.target?.endsWith('-apple-darwin')) return hasRunner ? BUNDLE_RUNNER_ARTIFACT_FILES : BUNDLE_ARTIFACT_FILES
|
|
47
|
+
throw new Error('Native artifact identity is invalid')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function artifactBinaryPath(manifest, command) {
|
|
51
|
+
if (!['standard', 'standardd', 'tmux'].includes(command)) throw new Error('Invalid artifact command')
|
|
52
|
+
artifactFiles(manifest)
|
|
53
|
+
if (manifest.target.endsWith('-unknown-linux-gnu')) return `bin/${command}`
|
|
54
|
+
if (command === 'tmux') return 'Standard Code Daemon.app/Contents/Helpers/tmux'
|
|
55
|
+
return `${command === 'standard' ? 'Standard Code' : 'Standard Code Daemon'}.app/Contents/MacOS/${command}`
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function artifactDirectories(files) {
|
|
59
|
+
const directories = new Set()
|
|
60
|
+
for (const file of files) {
|
|
61
|
+
for (let directory = dirname(file); directory !== '.'; directory = dirname(directory)) directories.add(directory)
|
|
62
|
+
}
|
|
63
|
+
return [...directories].sort()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Bundle signatures seal resources too: reject unmanifested contents and links
|
|
67
|
+
// at every directory level, including links in an executable's ancestors.
|
|
68
|
+
export function verifyArtifactTree(root, files, metadata = ['manifest.json', 'manifest.sig', 'package.json']) {
|
|
69
|
+
const allowedFiles = new Set([...files, ...metadata])
|
|
70
|
+
const allowedDirectories = new Set(artifactDirectories(files))
|
|
71
|
+
function visit(relative) {
|
|
72
|
+
const path = join(root, relative)
|
|
73
|
+
if (!lstatSync(path).isDirectory()) throw new Error(`Invalid artifact directory: ${path}`)
|
|
74
|
+
for (const name of readdirSync(path)) {
|
|
75
|
+
const child = relative ? `${relative}/${name}` : name
|
|
76
|
+
const entry = lstatSync(join(root, child))
|
|
77
|
+
if (entry.isDirectory() && allowedDirectories.has(child)) visit(child)
|
|
78
|
+
else if (!entry.isFile() || !allowedFiles.has(child)) throw new Error(`Unexpected artifact content: ${child}`)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
visit('')
|
|
82
|
+
for (const directory of allowedDirectories) {
|
|
83
|
+
if (!lstatSync(join(root, directory)).isDirectory()) throw new Error(`Invalid artifact directory: ${directory}`)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Check a native signed archive's listing before extraction: `names` from
|
|
88
|
+
// `tar -tzf` and the entry type letters from `tar -tvzf`. The archive must be
|
|
89
|
+
// exactly one of the signed layouts, with only regular files and the
|
|
90
|
+
// directories those files need. Returns the matching file list.
|
|
91
|
+
export function nativeArchiveLayout(names, types) {
|
|
92
|
+
const listed = names.map(name => name.replace(/^\.\//, '')).sort()
|
|
93
|
+
const layout = [ARTIFACT_FILES, BUNDLE_ARTIFACT_FILES, RUNNER_ARTIFACT_FILES, BUNDLE_RUNNER_ARTIFACT_FILES].find(files => {
|
|
94
|
+
const expected = [...artifactDirectories(files).map(path => `${path}/`), ...files, 'manifest.json', 'manifest.sig'].sort()
|
|
95
|
+
return listed.join('\n') === expected.join('\n')
|
|
96
|
+
})
|
|
97
|
+
if (!layout) throw new Error('native artifact archive has unexpected paths')
|
|
98
|
+
const expectedTypes = '-'.repeat(layout.length + 2) + 'd'.repeat(artifactDirectories(layout).length)
|
|
99
|
+
if ([...types].sort().join('') !== expectedTypes) {
|
|
100
|
+
throw new Error('native artifact archive must contain only regular files and expected directories')
|
|
101
|
+
}
|
|
102
|
+
return layout
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The four native targets the launcher has ever installed. The two deferred
|
|
106
|
+
// ones stay so their published history verifies.
|
|
107
|
+
export const NATIVE_ARTIFACT_TARGETS = Object.freeze([
|
|
108
|
+
'aarch64-apple-darwin', 'x86_64-apple-darwin',
|
|
109
|
+
'aarch64-unknown-linux-gnu', 'x86_64-unknown-linux-gnu',
|
|
110
|
+
])
|
|
111
|
+
// The browser viewer runtime: a fifth, distinct artifact kind that the same
|
|
112
|
+
// build workers compile and sign. It never installs through the launcher.
|
|
113
|
+
export const WEB_ARTIFACT_TARGET = 'wasm32-unknown-unknown'
|
|
114
|
+
export const ARTIFACT_TARGETS = Object.freeze([...NATIVE_ARTIFACT_TARGETS, WEB_ARTIFACT_TARGET])
|
|
115
|
+
|
|
116
|
+
// Web artifact (schema 4): the wasm-bindgen output, the bundled fonts, their
|
|
117
|
+
// licenses, and the build record, at the artifact root. The font and license
|
|
118
|
+
// sets vary with the pinned font list, so the manifest enumerates what the
|
|
119
|
+
// build produced and the verifier checks each path against these rules.
|
|
120
|
+
export const WEB_ARTIFACT_FORMAT = 'standard-npm-web-target-v1'
|
|
121
|
+
export const WEB_ARTIFACT_SCHEMA = 4
|
|
122
|
+
export const WEB_ARTIFACT_REQUIRED_FILES = Object.freeze([
|
|
123
|
+
'build.json', 'pkg/standard_web.js', 'pkg/standard_web_bg.wasm',
|
|
124
|
+
])
|
|
125
|
+
export const WEB_ARTIFACT_OPTIONAL_FILES = Object.freeze([
|
|
126
|
+
'pkg/standard_web.d.ts', 'pkg/standard_web_bg.wasm.d.ts',
|
|
127
|
+
])
|
|
128
|
+
// One level deep, one file kind each; at least one entry of each.
|
|
129
|
+
export const WEB_ARTIFACT_DIRECTORIES = Object.freeze({ fonts: /\.ttf$/, licenses: /\.txt$/ })
|
|
130
|
+
export const WEB_ARTIFACT_FILE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
|
|
131
|
+
// The sample plugins' browser artifacts (packages/web/scripts/build-plugins.mjs),
|
|
132
|
+
// optional: the Worker runtime and index at plugins/, and one directory per
|
|
133
|
+
// plugin id holding its manifest, component, transpiled glue and core modules.
|
|
134
|
+
export const WEB_ARTIFACT_PLUGIN_FILES = Object.freeze([
|
|
135
|
+
'plugins/worker.js', 'plugins/runtime.js', 'plugins/samples.json',
|
|
136
|
+
])
|
|
137
|
+
export const WEB_ARTIFACT_PLUGIN_ID = /^[a-z0-9][a-z0-9-]*$/
|
|
138
|
+
export const WEB_ARTIFACT_PLUGIN_FILE = /^[A-Za-z0-9][A-Za-z0-9._-]*\.(?:js|wasm|json)$/
|
|
139
|
+
export const MAX_WEB_ASSET_BYTES = 64 * 1024 * 1024
|
|
140
|
+
|
|
141
|
+
// Whether one artifact-relative path may appear in a web artifact.
|
|
142
|
+
export function webArtifactPathAllowed(path) {
|
|
143
|
+
if (typeof path !== 'string') return false
|
|
144
|
+
const parts = path.split('/')
|
|
145
|
+
if (!parts.every(part => WEB_ARTIFACT_FILE_NAME.test(part))) return false
|
|
146
|
+
if (WEB_ARTIFACT_REQUIRED_FILES.includes(path) || WEB_ARTIFACT_OPTIONAL_FILES.includes(path)) return true
|
|
147
|
+
if (WEB_ARTIFACT_PLUGIN_FILES.includes(path)) return true
|
|
148
|
+
if (parts.length === 3 && parts[0] === 'plugins') {
|
|
149
|
+
return WEB_ARTIFACT_PLUGIN_ID.test(parts[1]) && WEB_ARTIFACT_PLUGIN_FILE.test(parts[2])
|
|
150
|
+
}
|
|
151
|
+
return parts.length === 2 && Boolean(WEB_ARTIFACT_DIRECTORIES[parts[0]]?.test(parts[1]))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Whether a directory (without its trailing slash) may appear in a web
|
|
155
|
+
// artifact: pkg, the fixed directories, plugins, and one per plugin id.
|
|
156
|
+
export function webArtifactDirectoryAllowed(path) {
|
|
157
|
+
if (path === 'pkg' || path === 'plugins' || Object.hasOwn(WEB_ARTIFACT_DIRECTORIES, path)) return true
|
|
158
|
+
const parts = path.split('/')
|
|
159
|
+
return parts.length === 2 && parts[0] === 'plugins' && WEB_ARTIFACT_PLUGIN_ID.test(parts[1])
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Check a complete web file list: every path allowed, every required file
|
|
163
|
+
// present, each directory non-empty, no duplicates. Returns the sorted list.
|
|
164
|
+
export function webArtifactFileList(paths) {
|
|
165
|
+
if (!Array.isArray(paths) || paths.some(path => !webArtifactPathAllowed(path))) {
|
|
166
|
+
throw new Error('Web artifact file manifest is invalid')
|
|
167
|
+
}
|
|
168
|
+
const files = [...paths].sort()
|
|
169
|
+
if (new Set(files).size !== files.length) throw new Error('Web artifact file manifest is invalid')
|
|
170
|
+
const missing = WEB_ARTIFACT_REQUIRED_FILES.filter(path => !files.includes(path))
|
|
171
|
+
for (const directory of Object.keys(WEB_ARTIFACT_DIRECTORIES)) {
|
|
172
|
+
if (!files.some(path => path.startsWith(`${directory}/`))) missing.push(`${directory}/`)
|
|
173
|
+
}
|
|
174
|
+
if (missing.length) throw new Error(`Web artifact is incomplete: missing ${missing.join(', ')}`)
|
|
175
|
+
return files
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Enumerate a built web artifact root as the file list its manifest binds.
|
|
179
|
+
// Every entry must be a regular file the rules allow; anything else fails.
|
|
180
|
+
export function webArtifactFilesOnDisk(root, metadata = ['manifest.json', 'manifest.sig']) {
|
|
181
|
+
const files = []
|
|
182
|
+
function visit(relative) {
|
|
183
|
+
for (const name of readdirSync(join(root, relative))) {
|
|
184
|
+
const child = relative ? `${relative}/${name}` : name
|
|
185
|
+
if (!relative && metadata.includes(child)) continue
|
|
186
|
+
const entry = lstatSync(join(root, child))
|
|
187
|
+
if (entry.isDirectory() && webArtifactDirectoryAllowed(child)) visit(child)
|
|
188
|
+
else if (!entry.isFile() || !webArtifactPathAllowed(child)) throw new Error(`Unexpected artifact content: ${child}`)
|
|
189
|
+
else files.push(child)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
visit('')
|
|
193
|
+
return webArtifactFileList(files)
|
|
194
|
+
}
|
|
195
|
+
// Public trust anchor, not a credential. Never obtain the verification key
|
|
196
|
+
// from the package being verified or a mutable registry response.
|
|
197
|
+
export const ARTIFACT_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
198
|
+
MCowBQYDK2VwAyEAk+Ndu0WtdSgUFkraXP5CAUlQqzm+EN/My2AwkoPOMqg=
|
|
199
|
+
-----END PUBLIC KEY-----
|
|
200
|
+
`
|
|
201
|
+
|
|
202
|
+
export function validArtifactVersion(version) {
|
|
203
|
+
return typeof version === 'string'
|
|
204
|
+
&& /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(version)
|
|
205
|
+
&& (version.match(/^[^-]+-(.*)$/)?.[1].split('.') ?? []).every(part => !/^0\d+$/.test(part))
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function regularFile(path, limit) {
|
|
209
|
+
const descriptor = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW)
|
|
210
|
+
try {
|
|
211
|
+
const metadata = fstatSync(descriptor)
|
|
212
|
+
if (!metadata.isFile() || metadata.size < 1 || metadata.size > limit) throw new Error(`Invalid artifact file: ${path}`)
|
|
213
|
+
return { descriptor, metadata }
|
|
214
|
+
} catch (error) { closeSync(descriptor); throw error }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function boundedBytes(path, limit) {
|
|
218
|
+
const { descriptor } = regularFile(path, limit)
|
|
219
|
+
try {
|
|
220
|
+
const buffer = Buffer.alloc(limit + 1)
|
|
221
|
+
let size = 0
|
|
222
|
+
while (size <= limit) {
|
|
223
|
+
const count = readSync(descriptor, buffer, size, buffer.length - size, null)
|
|
224
|
+
if (!count) return buffer.subarray(0, size)
|
|
225
|
+
size += count
|
|
226
|
+
}
|
|
227
|
+
throw new Error(`Artifact exceeds size limit: ${path}`)
|
|
228
|
+
} finally { closeSync(descriptor) }
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Read and authenticate an artifact's manifest against the pinned key. The
|
|
232
|
+
// bytes that were signed are the bytes parsed; nothing is trusted before this.
|
|
233
|
+
function signedManifest(root, publicKey, label) {
|
|
234
|
+
if (!lstatSync(root).isDirectory()) throw new Error(`Invalid artifact directory: ${root}`)
|
|
235
|
+
const bytes = boundedBytes(join(root, 'manifest.json'), 64 * 1024)
|
|
236
|
+
const signature = boundedBytes(join(root, 'manifest.sig'), 256).toString('utf8').trim()
|
|
237
|
+
const key = createPublicKey(publicKey)
|
|
238
|
+
if (key.asymmetricKeyType !== 'ed25519' || !verify(null, bytes, key, Buffer.from(signature, 'base64'))) {
|
|
239
|
+
throw new Error(`${label} artifact signature is invalid`)
|
|
240
|
+
}
|
|
241
|
+
return JSON.parse(bytes)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Every manifested file must exist with exactly its signed size and digest.
|
|
245
|
+
function verifyFileDigests(root, manifest, limitFor, label) {
|
|
246
|
+
const buffer = Buffer.alloc(1024 * 1024)
|
|
247
|
+
for (const file of manifest.files) {
|
|
248
|
+
if (!Number.isSafeInteger(file.size) || !/^[0-9a-f]{64}$/.test(file.sha256)) throw new Error(`${label} artifact file metadata is invalid`)
|
|
249
|
+
const path = join(root, file.path)
|
|
250
|
+
const { descriptor, metadata } = regularFile(path, limitFor(file.path))
|
|
251
|
+
try {
|
|
252
|
+
if (metadata.size !== file.size) throw new Error(`${label} artifact size mismatch: ${file.path}`)
|
|
253
|
+
const hash = createHash('sha256')
|
|
254
|
+
let size = 0
|
|
255
|
+
for (;;) {
|
|
256
|
+
const count = readSync(descriptor, buffer, 0, buffer.length, null)
|
|
257
|
+
if (!count) break
|
|
258
|
+
size += count
|
|
259
|
+
if (size > file.size) throw new Error(`${label} artifact grew while verifying: ${file.path}`)
|
|
260
|
+
hash.update(buffer.subarray(0, count))
|
|
261
|
+
}
|
|
262
|
+
if (size !== file.size || hash.digest('hex') !== file.sha256) throw new Error(`${label} artifact digest mismatch: ${file.path}`)
|
|
263
|
+
} finally { closeSync(descriptor) }
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function verifyNativeArtifact(root, expected = {}, publicKey = ARTIFACT_PUBLIC_KEY) {
|
|
268
|
+
const manifest = signedManifest(root, publicKey, 'Native')
|
|
269
|
+
const files = artifactFiles(manifest)
|
|
270
|
+
if (manifest.repository !== 'standardagents/code-rs'
|
|
271
|
+
|| !NATIVE_ARTIFACT_TARGETS.includes(manifest.target)
|
|
272
|
+
|| !/^[0-9a-f]{40}$/.test(manifest.commit)
|
|
273
|
+
|| !validArtifactVersion(manifest.version)
|
|
274
|
+
|| ['commit', 'version', 'target'].some(name => expected[name] != null && manifest[name] !== expected[name])
|
|
275
|
+
|| manifest.signing?.algorithm !== 'ed25519') throw new Error('Native artifact identity is invalid')
|
|
276
|
+
if (Object.hasOwn(manifest, 'backendProfile') && (manifest.backendProfile == null || manifest.backendProfile === '')) {
|
|
277
|
+
throw new Error('Native artifact backend profile cannot be null')
|
|
278
|
+
}
|
|
279
|
+
const backendProfile = normalizeBackendProfile(manifest.backendProfile)
|
|
280
|
+
if (backendProfile && !isPreviewBuild(manifest.version)) {
|
|
281
|
+
throw new Error('Native artifact preview backend profile is not valid for this version')
|
|
282
|
+
}
|
|
283
|
+
if (!Array.isArray(manifest.files) || manifest.files.map(file => file.path).sort().join(',') !== [...files].sort().join(',')) {
|
|
284
|
+
throw new Error('Native artifact file manifest is invalid')
|
|
285
|
+
}
|
|
286
|
+
const runnerFiles = manifest.target.endsWith('-apple-darwin')
|
|
287
|
+
? BUNDLE_RUNNER_ARTIFACT_FILES.slice(BUNDLE_ARTIFACT_FILES.length)
|
|
288
|
+
: RUNNER_ARTIFACT_FILES.slice(ARTIFACT_FILES.length)
|
|
289
|
+
if (!manifest.files.some(file => runnerFiles.includes(file.path))) {
|
|
290
|
+
for (const path of runnerFiles) {
|
|
291
|
+
try { lstatSync(join(root, path)) }
|
|
292
|
+
catch (error) { if (error.code === 'ENOENT') continue; throw error }
|
|
293
|
+
throw new Error('Native artifact contains unsigned plugin runner files')
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (manifest.schema === 3) verifyArtifactTree(root, files)
|
|
297
|
+
else for (const directory of artifactDirectories(files)) {
|
|
298
|
+
if (!lstatSync(join(root, directory)).isDirectory()) throw new Error(`Invalid artifact directory: ${directory}`)
|
|
299
|
+
}
|
|
300
|
+
const tmux = manifest.files.find(file => file.path === artifactBinaryPath(manifest, 'tmux'))
|
|
301
|
+
if (manifest.runtime?.tmuxVersion !== '3.7' || manifest.runtime.tmuxSha256 !== tmux.sha256) {
|
|
302
|
+
throw new Error('Native artifact tmux identity is invalid')
|
|
303
|
+
}
|
|
304
|
+
const protocol = manifest.runtime.accountUpdateProtocol
|
|
305
|
+
if (protocol != null && (!Number.isSafeInteger(protocol) || protocol < 1 || protocol > 0xffff_ffff)) {
|
|
306
|
+
throw new Error('Native artifact account update protocol is invalid')
|
|
307
|
+
}
|
|
308
|
+
if (manifest.target.endsWith('-apple-darwin')
|
|
309
|
+
&& (manifest.signing.platformCodeSignature !== 'apple-developer-id'
|
|
310
|
+
|| manifest.signing.notarization?.status !== 'Accepted'
|
|
311
|
+
|| !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(manifest.signing.notarization?.submissionId ?? ''))) {
|
|
312
|
+
throw new Error('macOS artifact lacks signed notarization acceptance')
|
|
313
|
+
}
|
|
314
|
+
if (manifest.target.endsWith('-unknown-linux-gnu')
|
|
315
|
+
&& !/^\d+\.\d+(?:\.\d+)?$/.test(manifest.runtime.minimumGlibc ?? '')) throw new Error('Linux artifact lacks its glibc requirement')
|
|
316
|
+
verifyFileDigests(root, manifest, path => runnerFiles.includes(path) ? MAX_RUNNER_ASSET_BYTES : 256 * 1024 * 1024, 'Native')
|
|
317
|
+
return manifest
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Verify a web artifact root: the Ed25519 signature, the schema-4 identity,
|
|
321
|
+
// the file rules, the exact on-disk file set (nothing unmanifested, no
|
|
322
|
+
// links), the build record, and every digest. Returns the manifest.
|
|
323
|
+
export function verifyWebArtifact(root, expected = {}, publicKey = ARTIFACT_PUBLIC_KEY) {
|
|
324
|
+
const manifest = signedManifest(root, publicKey, 'Web')
|
|
325
|
+
if (manifest.schema !== WEB_ARTIFACT_SCHEMA || manifest.format !== WEB_ARTIFACT_FORMAT
|
|
326
|
+
|| manifest.target !== WEB_ARTIFACT_TARGET
|
|
327
|
+
|| manifest.repository !== 'standardagents/code-rs'
|
|
328
|
+
|| !/^[0-9a-f]{40}$/.test(manifest.commit)
|
|
329
|
+
|| !validArtifactVersion(manifest.version)
|
|
330
|
+
|| ['commit', 'version', 'target'].some(name => expected[name] != null && manifest[name] !== expected[name])
|
|
331
|
+
|| manifest.signing?.algorithm !== 'ed25519') throw new Error('Web artifact identity is invalid')
|
|
332
|
+
if (Object.hasOwn(manifest, 'backendProfile') && (manifest.backendProfile == null || manifest.backendProfile === '')) {
|
|
333
|
+
throw new Error('Web artifact backend profile cannot be null')
|
|
334
|
+
}
|
|
335
|
+
const backendProfile = normalizeBackendProfile(manifest.backendProfile)
|
|
336
|
+
if (backendProfile && !isPreviewBuild(manifest.version)) {
|
|
337
|
+
throw new Error('Web artifact preview backend profile is not valid for this version')
|
|
338
|
+
}
|
|
339
|
+
if (!Array.isArray(manifest.files)) throw new Error('Web artifact file manifest is invalid')
|
|
340
|
+
const files = webArtifactFileList(manifest.files.map(file => file?.path))
|
|
341
|
+
verifyArtifactTree(root, files)
|
|
342
|
+
verifyFileDigests(root, manifest, () => MAX_WEB_ASSET_BYTES, 'Web')
|
|
343
|
+
// The build record is the identity the bundle itself reports; it must name
|
|
344
|
+
// the signed build, not a local or foreign one.
|
|
345
|
+
let record
|
|
346
|
+
try { record = JSON.parse(boundedBytes(join(root, 'build.json'), 4096)) } catch { record = null }
|
|
347
|
+
if (record?.schema !== 1 || record.commit !== manifest.commit || record.version !== manifest.version) {
|
|
348
|
+
throw new Error('Web artifact build record does not name the signed build')
|
|
349
|
+
}
|
|
350
|
+
return manifest
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export function requireCompatibleGlibc(manifest, runtimeVersion) {
|
|
354
|
+
if (!manifest.target.endsWith('-unknown-linux-gnu')) return
|
|
355
|
+
const minimum = manifest.runtime.minimumGlibc
|
|
356
|
+
if (!/^\d+\.\d+(?:\.\d+)?$/.test(runtimeVersion ?? '')) throw new Error('Cannot determine this machine’s glibc version')
|
|
357
|
+
const actual = runtimeVersion.split('.').map(Number)
|
|
358
|
+
const required = minimum.split('.').map(Number)
|
|
359
|
+
for (let index = 0; index < 3; index++) {
|
|
360
|
+
if ((actual[index] ?? 0) > (required[index] ?? 0)) return
|
|
361
|
+
if ((actual[index] ?? 0) < (required[index] ?? 0)) throw new Error(`This Standard build requires glibc ${minimum}; this machine has ${runtimeVersion}`)
|
|
362
|
+
}
|
|
363
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const PROFILE_KEYS = ['schema', 'id', 'label', 'apiOrigin', 'relayEnvironment']
|
|
2
|
+
const PROFILE_ID = /^[a-z0-9][a-z0-9-]{0,47}$/
|
|
3
|
+
const DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/
|
|
4
|
+
const PROFILE_HOST_SUFFIXES = ['.standardcode.ai', '.standardagentbuilder.com']
|
|
5
|
+
|
|
6
|
+
export const BACKEND_PROFILE_SCHEMA = 1
|
|
7
|
+
|
|
8
|
+
export function isPreviewBuild(version) {
|
|
9
|
+
return typeof version === 'string' && /-(?:issue|branch)\./.test(version)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Validate and normalize the preview backend profile embedded in a native
|
|
14
|
+
* artifact. Production is represented by an absent or null profile.
|
|
15
|
+
*/
|
|
16
|
+
export function normalizeBackendProfile(value) {
|
|
17
|
+
if (value == null || value === '') return null
|
|
18
|
+
if (!isPlainObject(value)) throw new Error('backend profile must be an object')
|
|
19
|
+
const keys = Object.keys(value).sort()
|
|
20
|
+
if (keys.join(',') !== [...PROFILE_KEYS].sort().join(',')) {
|
|
21
|
+
throw new Error('backend profile has unexpected fields')
|
|
22
|
+
}
|
|
23
|
+
if (value.schema !== BACKEND_PROFILE_SCHEMA) throw new Error('backend profile schema is unsupported')
|
|
24
|
+
if (typeof value.id !== 'string' || !PROFILE_ID.test(value.id) || value.id === 'production') {
|
|
25
|
+
throw new Error('backend profile id is invalid')
|
|
26
|
+
}
|
|
27
|
+
if (typeof value.label !== 'string' || !/^[\x20-\x7e]{1,64}$/.test(value.label)) {
|
|
28
|
+
throw new Error('backend profile label must be printable ASCII up to 64 characters')
|
|
29
|
+
}
|
|
30
|
+
const apiOrigin = canonicalApiOrigin(value.apiOrigin)
|
|
31
|
+
if (apiOrigin === 'https://api.standardcode.ai') {
|
|
32
|
+
throw new Error('preview backend profile cannot use the production API origin')
|
|
33
|
+
}
|
|
34
|
+
if (!['staging', 'production'].includes(value.relayEnvironment)) {
|
|
35
|
+
throw new Error('backend profile relayEnvironment must be staging or production')
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
schema: BACKEND_PROFILE_SCHEMA,
|
|
39
|
+
id: value.id,
|
|
40
|
+
label: value.label,
|
|
41
|
+
apiOrigin,
|
|
42
|
+
relayEnvironment: value.relayEnvironment,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function serializeBackendProfile(value) {
|
|
47
|
+
const profile = normalizeBackendProfile(value)
|
|
48
|
+
return profile ? JSON.stringify(profile) : ''
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function backendProfilesEqual(left, right) {
|
|
52
|
+
const a = normalizeBackendProfile(left)
|
|
53
|
+
const b = normalizeBackendProfile(right)
|
|
54
|
+
return JSON.stringify(a) === JSON.stringify(b)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function backendProfileIdentitiesEqual(left, right) {
|
|
58
|
+
const a = normalizeBackendProfile(left)
|
|
59
|
+
const b = normalizeBackendProfile(right)
|
|
60
|
+
return (a?.id ?? 'production') === (b?.id ?? 'production')
|
|
61
|
+
&& (a?.apiOrigin ?? 'https://api.standardcode.ai') === (b?.apiOrigin ?? 'https://api.standardcode.ai')
|
|
62
|
+
&& (a?.relayEnvironment ?? 'production') === (b?.relayEnvironment ?? 'production')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function backendProfileFingerprint(value) {
|
|
66
|
+
const profile = normalizeBackendProfile(value)
|
|
67
|
+
const id = profile?.id ?? 'production'
|
|
68
|
+
const apiOrigin = profile?.apiOrigin ?? 'https://api.standardcode.ai'
|
|
69
|
+
const relayEnvironment = profile?.relayEnvironment ?? 'production'
|
|
70
|
+
const bytes = new TextEncoder().encode(
|
|
71
|
+
`standard-backend-v1\0${id}\0${apiOrigin}\0${relayEnvironment}`,
|
|
72
|
+
)
|
|
73
|
+
const digest = await crypto.subtle.digest('SHA-256', bytes)
|
|
74
|
+
return Array.from(new Uint8Array(digest), byte => byte.toString(16).padStart(2, '0')).join('')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A preview backend has a separate follow channel on the same Git branch. */
|
|
78
|
+
export async function backendProfileTag(baseTag, value) {
|
|
79
|
+
const profile = normalizeBackendProfile(value)
|
|
80
|
+
if (!profile) return baseTag
|
|
81
|
+
if (!/^(?:branch-|issue-)[a-z0-9-]+$/.test(baseTag)) {
|
|
82
|
+
throw new Error('preview backend profiles require a branch channel')
|
|
83
|
+
}
|
|
84
|
+
const tag = `${baseTag}-b-${(await backendProfileFingerprint(profile)).slice(0, 16)}`
|
|
85
|
+
if (tag.length > 64) throw new Error('backend-specific channel exceeds the tag length limit')
|
|
86
|
+
return tag
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function canonicalApiOrigin(value) {
|
|
90
|
+
if (typeof value !== 'string' || !value || value.trim() !== value) {
|
|
91
|
+
throw new Error('backend profile apiOrigin must be a canonical HTTPS origin')
|
|
92
|
+
}
|
|
93
|
+
let url
|
|
94
|
+
try { url = new URL(value) } catch { throw new Error('backend profile apiOrigin must be a canonical HTTPS origin') }
|
|
95
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.port
|
|
96
|
+
|| !['', '/'].includes(url.pathname) || url.search || url.hash
|
|
97
|
+
|| value !== url.origin) {
|
|
98
|
+
throw new Error('backend profile apiOrigin must be a canonical HTTPS origin')
|
|
99
|
+
}
|
|
100
|
+
const hostname = url.hostname
|
|
101
|
+
if (!hostname || hostname.length > 253 || hostname !== hostname.toLowerCase()) {
|
|
102
|
+
throw new Error('backend profile apiOrigin hostname is invalid')
|
|
103
|
+
}
|
|
104
|
+
const labels = hostname.split('.')
|
|
105
|
+
if (labels.some(label => !DNS_LABEL.test(label))
|
|
106
|
+
|| !PROFILE_HOST_SUFFIXES.some(suffix => hostname.endsWith(suffix))) {
|
|
107
|
+
throw new Error('backend profile apiOrigin hostname is not a supported first-party host')
|
|
108
|
+
}
|
|
109
|
+
return url.origin
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function isPlainObject(value) {
|
|
113
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
114
|
+
}
|
package/lib/install.mjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto'
|
|
3
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
import { artifactBinaryPath, nativeArchiveLayout, verifyNativeArtifact } from './artifact.mjs'
|
|
8
|
+
|
|
9
|
+
// A release's root package names each native target's signed archive in
|
|
10
|
+
// `standardArtifacts`; npm only selects the platform. The archive downloads
|
|
11
|
+
// from the build coordinator, which serves it from R2, and installs under this
|
|
12
|
+
// package's `native/<target>/` once its size, digest, layout, and signed
|
|
13
|
+
// manifest all check out. The daemon's launcher repair finds it there too.
|
|
14
|
+
export const ARTIFACT_ORIGIN = 'https://builds.standardcode.ai'
|
|
15
|
+
const MAX_ARCHIVE = 128 * 1024 * 1024
|
|
16
|
+
const PACKAGE_ROOT = fileURLToPath(new URL('..', import.meta.url))
|
|
17
|
+
|
|
18
|
+
export function nativeDirectory(target, root = PACKAGE_ROOT) {
|
|
19
|
+
return join(root, 'native', target)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function packageMetadata(root = PACKAGE_ROOT) {
|
|
23
|
+
return JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The signed archive a package names for `target`, or null when its binaries
|
|
27
|
+
// install as an npm platform package instead.
|
|
28
|
+
export function artifactPointer(metadata, target) {
|
|
29
|
+
const artifacts = metadata.standardArtifacts
|
|
30
|
+
if (artifacts === undefined) return null
|
|
31
|
+
const pointer = artifacts?.schema === 1 ? artifacts.targets?.[target] : undefined
|
|
32
|
+
if (!pointer
|
|
33
|
+
|| pointer.url !== `${ARTIFACT_ORIGIN}/artifacts/${metadata.version}/${target}.tar.gz`
|
|
34
|
+
|| !/^[0-9a-f]{64}$/.test(pointer.sha256 ?? '')
|
|
35
|
+
|| !Number.isSafeInteger(pointer.size) || pointer.size < 1 || pointer.size > MAX_ARCHIVE) {
|
|
36
|
+
throw new Error(`This package names no valid native archive for ${target}`)
|
|
37
|
+
}
|
|
38
|
+
return pointer
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The installed, verified artifact directory for `target`, or null.
|
|
42
|
+
export function installedArtifact(target, root = PACKAGE_ROOT, publicKey = undefined) {
|
|
43
|
+
const directory = nativeDirectory(target, root)
|
|
44
|
+
try {
|
|
45
|
+
return { directory, manifest: verifyNativeArtifact(directory, { version: packageMetadata(root).version, target }, publicKey) }
|
|
46
|
+
} catch {
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function tar(run, args) {
|
|
52
|
+
const result = run('tar', args, { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 })
|
|
53
|
+
if (result.error) throw result.error
|
|
54
|
+
if (result.status !== 0) throw new Error(`tar ${args[0]} failed: ${result.stderr}`)
|
|
55
|
+
return result.stdout
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function installNativeArtifact({ target, root = PACKAGE_ROOT, fetchImplementation = fetch, run = spawnSync, publicKey = undefined }) {
|
|
59
|
+
const installed = installedArtifact(target, root, publicKey)
|
|
60
|
+
if (installed) return installed.directory
|
|
61
|
+
const metadata = packageMetadata(root)
|
|
62
|
+
const pointer = artifactPointer(metadata, target)
|
|
63
|
+
if (!pointer) throw new Error(`This package carries no native archive for ${target}`)
|
|
64
|
+
const response = await fetchImplementation(pointer.url)
|
|
65
|
+
if (!response.ok) throw new Error(`Downloading the native archive failed with HTTP ${response.status}`)
|
|
66
|
+
const bytes = Buffer.from(await response.arrayBuffer())
|
|
67
|
+
if (bytes.length !== pointer.size || createHash('sha256').update(bytes).digest('hex') !== pointer.sha256) {
|
|
68
|
+
throw new Error('The downloaded native archive does not match its published size and digest')
|
|
69
|
+
}
|
|
70
|
+
const work = join(root, 'native', `.install-${randomUUID()}`)
|
|
71
|
+
mkdirSync(work, { recursive: true, mode: 0o700 })
|
|
72
|
+
try {
|
|
73
|
+
const archive = join(work, 'archive.tar.gz')
|
|
74
|
+
writeFileSync(archive, bytes, { mode: 0o600, flag: 'wx' })
|
|
75
|
+
nativeArchiveLayout(
|
|
76
|
+
tar(run, ['-tzf', archive]).trim().split('\n'),
|
|
77
|
+
tar(run, ['-tvzf', archive]).trim().split('\n').map(line => line[0]),
|
|
78
|
+
)
|
|
79
|
+
const extracted = join(work, 'artifact')
|
|
80
|
+
mkdirSync(extracted, { mode: 0o700 })
|
|
81
|
+
tar(run, ['-xzf', archive, '-C', extracted])
|
|
82
|
+
const manifest = verifyNativeArtifact(extracted, { version: metadata.version, target }, publicKey)
|
|
83
|
+
for (const command of ['standard', 'standardd', 'tmux']) {
|
|
84
|
+
chmodSync(join(extracted, artifactBinaryPath(manifest, command)), 0o755)
|
|
85
|
+
}
|
|
86
|
+
const destination = nativeDirectory(target, root)
|
|
87
|
+
rmSync(destination, { recursive: true, force: true })
|
|
88
|
+
renameSync(extracted, destination)
|
|
89
|
+
return destination
|
|
90
|
+
} finally {
|
|
91
|
+
rmSync(work, { recursive: true, force: true })
|
|
92
|
+
}
|
|
93
|
+
}
|
package/lib/launcher.mjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import { readFileSync, realpathSync, statSync } from 'node:fs'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import { dirname, isAbsolute, join } from 'node:path'
|
|
5
|
+
import process from 'node:process'
|
|
6
|
+
|
|
7
|
+
import { platformPackage } from './platform.mjs'
|
|
8
|
+
import { artifactBinaryPath, requireCompatibleGlibc, verifyNativeArtifact } from './artifact.mjs'
|
|
9
|
+
import { artifactPointer, installNativeArtifact, installedArtifact, nativeDirectory, packageMetadata } from './install.mjs'
|
|
10
|
+
|
|
11
|
+
const require = createRequire(import.meta.url)
|
|
12
|
+
const COMMANDS = new Set(['standard', 'standardd'])
|
|
13
|
+
|
|
14
|
+
export function resolveBinary(command, options = {}) {
|
|
15
|
+
if (!COMMANDS.has(command)) {
|
|
16
|
+
throw new Error(`Unknown Standard executable: ${command}`)
|
|
17
|
+
}
|
|
18
|
+
const environment = options.environment ?? process.env
|
|
19
|
+
const overrideDirectory = environment.STANDARD_CODE_BINARY_DIR
|
|
20
|
+
const binaryPath = overrideDirectory
|
|
21
|
+
? join(overrideDirectory, command)
|
|
22
|
+
: stableBinary(command, options) ?? resolvePackagedBinary(command, options)
|
|
23
|
+
const stat = statSync(binaryPath)
|
|
24
|
+
if (!stat.isFile()) {
|
|
25
|
+
throw new Error(`Resolved Standard executable is not a file: ${binaryPath}`)
|
|
26
|
+
}
|
|
27
|
+
return binaryPath
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// The daemon records its last stably booted native release as
|
|
31
|
+
// native-releases/stable. Starting it makes this package's age irrelevant:
|
|
32
|
+
// that build selects the account's active release with its own current
|
|
33
|
+
// verification rules. The packaged build remains the first-install fallback.
|
|
34
|
+
export function stableBinary(command, options = {}) {
|
|
35
|
+
const environment = options.environment ?? process.env
|
|
36
|
+
const home = environment.HOME
|
|
37
|
+
const argumentsList = options.arguments ?? process.argv.slice(2)
|
|
38
|
+
if (!home || !isAbsolute(home)
|
|
39
|
+
|| argumentsList.some(argument => argument === '--state-dir' || argument.startsWith('--state-dir='))) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
const { rustTarget } = platformPackage(options.platform, options.architecture, options.report)
|
|
43
|
+
const relative = rustTarget.endsWith('-unknown-linux-gnu')
|
|
44
|
+
? `bin/${command}`
|
|
45
|
+
: `${command === 'standard' ? 'Standard Code' : 'Standard Code Daemon'}.app/Contents/MacOS/${command}`
|
|
46
|
+
const uid = options.uid ?? process.getuid?.()
|
|
47
|
+
try {
|
|
48
|
+
const root = realpathSync(join(home, '.local/share/standard-code/state/native-releases'))
|
|
49
|
+
const slot = realpathSync(join(root, 'stable'))
|
|
50
|
+
if (dirname(slot) !== join(root, rustTarget)) return null
|
|
51
|
+
for (const directory of [root, slot]) {
|
|
52
|
+
const info = statSync(directory)
|
|
53
|
+
if (!info.isDirectory() || info.uid !== uid || (info.mode & 0o077) !== 0) return null
|
|
54
|
+
}
|
|
55
|
+
const binary = join(slot, relative)
|
|
56
|
+
const info = statSync(binary)
|
|
57
|
+
return info.isFile() && info.uid === uid ? binary : null
|
|
58
|
+
} catch {
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function resolvePackagedBinary(command, options) {
|
|
64
|
+
const platform = platformPackage(
|
|
65
|
+
options.platform,
|
|
66
|
+
options.architecture,
|
|
67
|
+
options.report,
|
|
68
|
+
)
|
|
69
|
+
const resolve = options.resolve ?? require.resolve
|
|
70
|
+
const report = options.report ?? process.report
|
|
71
|
+
// A release that carries no binaries on npm installs its signed R2 archive
|
|
72
|
+
// under this package instead (see install.mjs).
|
|
73
|
+
const downloaded = installedArtifact(platform.rustTarget, options.packageRoot)
|
|
74
|
+
if (downloaded) {
|
|
75
|
+
requireCompatibleGlibc(downloaded.manifest, report?.getReport()?.header?.glibcVersionRuntime)
|
|
76
|
+
return join(downloaded.directory, artifactBinaryPath(downloaded.manifest, command))
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const root = dirname(realpathSync(resolve(`${platform.packageName}/manifest.json`)))
|
|
80
|
+
const version = JSON.parse(readFileSync(new URL('../package.json', import.meta.url))).version
|
|
81
|
+
const artifact = verifyNativeArtifact(root, { version, target: platform.rustTarget })
|
|
82
|
+
requireCompatibleGlibc(artifact, report?.getReport()?.header?.glibcVersionRuntime)
|
|
83
|
+
return join(root, artifactBinaryPath(artifact, command))
|
|
84
|
+
} catch (error) {
|
|
85
|
+
const detail = error instanceof Error ? error.message : String(error)
|
|
86
|
+
throw new Error(
|
|
87
|
+
`The native package ${platform.packageName} is missing or incomplete. `
|
|
88
|
+
+ `Reinstall @standardagents/code for this platform. (${detail})`,
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function spawnBinary(command, args, options = {}) {
|
|
94
|
+
const binary = resolveBinary(command, options)
|
|
95
|
+
return spawnSync(binary, args, {
|
|
96
|
+
stdio: options.stdio ?? 'inherit',
|
|
97
|
+
env: options.environment ?? process.env,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Install this platform's signed R2 archive when the package names one and
|
|
102
|
+
// has no binaries installed yet. The package has no install script, so npm
|
|
103
|
+
// and pnpm install it without an allow-scripts prompt, and the first launch
|
|
104
|
+
// downloads and verifies the native build here (#684).
|
|
105
|
+
export async function ensureNativeBinaries(options = {}) {
|
|
106
|
+
if (options.environment?.STANDARD_CODE_BINARY_DIR ?? process.env.STANDARD_CODE_BINARY_DIR) return
|
|
107
|
+
const platform = platformPackage(options.platform, options.architecture, options.report)
|
|
108
|
+
if (installedArtifact(platform.rustTarget, options.packageRoot)) return
|
|
109
|
+
if (!artifactPointer(packageMetadata(options.packageRoot), platform.rustTarget)) return
|
|
110
|
+
try {
|
|
111
|
+
const resolve = options.resolve ?? require.resolve
|
|
112
|
+
resolve(`${platform.packageName}/manifest.json`)
|
|
113
|
+
return
|
|
114
|
+
} catch {
|
|
115
|
+
// No npm platform package: download the archive.
|
|
116
|
+
}
|
|
117
|
+
const log = options.log ?? (message => console.error(message))
|
|
118
|
+
log(`standard: installing the native build for ${platform.rustTarget} (first launch)`)
|
|
119
|
+
try {
|
|
120
|
+
await installNativeArtifact({ target: platform.rustTarget, root: options.packageRoot, fetchImplementation: options.fetchImplementation })
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (error?.code === 'EACCES' || error?.code === 'EPERM') {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`cannot write the native build under ${nativeDirectory(platform.rustTarget, options.packageRoot)}. `
|
|
125
|
+
+ 'The package belongs to another user (for example an npm install run with sudo); '
|
|
126
|
+
+ 'reinstall @standardagents/code with an npm prefix you own.',
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
throw error
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function main(command) {
|
|
134
|
+
try {
|
|
135
|
+
await ensureNativeBinaries()
|
|
136
|
+
const result = spawnBinary(command, process.argv.slice(2))
|
|
137
|
+
if (result.error) throw result.error
|
|
138
|
+
if (result.signal) {
|
|
139
|
+
console.error(`${command} terminated by ${result.signal}`)
|
|
140
|
+
process.exitCode = 1
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
process.exitCode = result.status ?? 1
|
|
144
|
+
} catch (error) {
|
|
145
|
+
const detail = error instanceof Error ? error.message : String(error)
|
|
146
|
+
console.error(`${command}: ${detail}`)
|
|
147
|
+
process.exitCode = 1
|
|
148
|
+
}
|
|
149
|
+
}
|
package/lib/platform.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const PLATFORMS = new Map([
|
|
2
|
+
['darwin:arm64', {
|
|
3
|
+
packageName: '@standardagents/code-darwin-arm64',
|
|
4
|
+
rustTarget: 'aarch64-apple-darwin',
|
|
5
|
+
}],
|
|
6
|
+
['darwin:x64', {
|
|
7
|
+
packageName: '@standardagents/code-darwin-x64',
|
|
8
|
+
rustTarget: 'x86_64-apple-darwin',
|
|
9
|
+
}],
|
|
10
|
+
['linux:arm64', {
|
|
11
|
+
packageName: '@standardagents/code-linux-arm64-gnu',
|
|
12
|
+
rustTarget: 'aarch64-unknown-linux-gnu',
|
|
13
|
+
}],
|
|
14
|
+
['linux:x64', {
|
|
15
|
+
packageName: '@standardagents/code-linux-x64-gnu',
|
|
16
|
+
rustTarget: 'x86_64-unknown-linux-gnu',
|
|
17
|
+
}],
|
|
18
|
+
])
|
|
19
|
+
|
|
20
|
+
export function platformPackage(
|
|
21
|
+
platform = process.platform,
|
|
22
|
+
architecture = process.arch,
|
|
23
|
+
report = process.report,
|
|
24
|
+
) {
|
|
25
|
+
const entry = PLATFORMS.get(`${platform}:${architecture}`)
|
|
26
|
+
if (!entry) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Standard does not yet provide binaries for ${platform}/${architecture}; `
|
|
29
|
+
+ 'Phase 0 supports macOS and glibc Linux on arm64/x64.',
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
if (platform === 'linux' && !isGlibc(report)) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
'Standard Phase 0 Linux packages require glibc; a musl build is not published yet.',
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
return entry
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function supportedPlatforms() {
|
|
41
|
+
return [...PLATFORMS.values()].map((entry) => ({ ...entry }))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isGlibc(report) {
|
|
45
|
+
try {
|
|
46
|
+
return Boolean(report?.getReport()?.header?.glibcVersionRuntime)
|
|
47
|
+
} catch {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standardagents/code",
|
|
3
|
-
"version": "0.14.
|
|
4
|
-
"description": "Standard
|
|
3
|
+
"version": "0.14.3-canary.6cc75f",
|
|
4
|
+
"description": "Platform launcher for the Standard universal terminal network.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "UNLICENSED",
|
|
5
7
|
"repository": {
|
|
6
8
|
"type": "git",
|
|
7
9
|
"url": "git+https://github.com/standardagents/code-rs.git"
|
|
8
10
|
},
|
|
9
|
-
"license": "UNLICENSED",
|
|
10
|
-
"os": [
|
|
11
|
-
"linux"
|
|
12
|
-
],
|
|
13
|
-
"cpu": [
|
|
14
|
-
"x64"
|
|
15
|
-
],
|
|
16
|
-
"libc": [
|
|
17
|
-
"glibc"
|
|
18
|
-
],
|
|
19
|
-
"files": [
|
|
20
|
-
"bin",
|
|
21
|
-
"licenses",
|
|
22
|
-
"manifest.json",
|
|
23
|
-
"manifest.sig"
|
|
24
|
-
],
|
|
25
11
|
"publishConfig": {
|
|
26
12
|
"access": "public",
|
|
27
13
|
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"standard": "bin/standard.mjs",
|
|
20
|
+
"standardd": "bin/standardd.mjs"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"bin",
|
|
24
|
+
"lib"
|
|
25
|
+
],
|
|
26
|
+
"standardArtifacts": {
|
|
27
|
+
"schema": 1,
|
|
28
|
+
"targets": {
|
|
29
|
+
"aarch64-apple-darwin": {
|
|
30
|
+
"url": "https://builds.standardcode.ai/artifacts/0.14.3-canary.6cc75f/aarch64-apple-darwin.tar.gz",
|
|
31
|
+
"sha256": "45f9458727aae1a6ed80dad7f8bff778d271a56b5148e3cdc9fceb22fafa2410",
|
|
32
|
+
"size": 22931785
|
|
33
|
+
},
|
|
34
|
+
"x86_64-unknown-linux-gnu": {
|
|
35
|
+
"url": "https://builds.standardcode.ai/artifacts/0.14.3-canary.6cc75f/x86_64-unknown-linux-gnu.tar.gz",
|
|
36
|
+
"sha256": "ef44b1a6a2c3623143f2dcb0505b56cce65d8649d21441cfe4373ed59bf5f6de",
|
|
37
|
+
"size": 28560078
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"standardUpgrade": {
|
|
42
|
+
"schema": 1,
|
|
43
|
+
"reader": 1,
|
|
44
|
+
"bridge": {
|
|
45
|
+
"version": "0.14.1-canary.76909e",
|
|
46
|
+
"commit": "76909e97ec56c2ba5490932135642962c4035596"
|
|
47
|
+
}
|
|
28
48
|
}
|
|
29
49
|
}
|
package/bin/standard
DELETED
|
Binary file
|
package/bin/standardd
DELETED
|
Binary file
|
package/bin/tmux
DELETED
|
Binary file
|
package/licenses/THIRD-PARTY.txt
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
libevent.txt
|
|
2
|
-
============
|
|
3
|
-
Libevent is available for use under the following license, commonly known
|
|
4
|
-
as the 3-clause (or "modified") BSD license:
|
|
5
|
-
|
|
6
|
-
==============================
|
|
7
|
-
Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
|
|
8
|
-
Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
|
|
9
|
-
|
|
10
|
-
Redistribution and use in source and binary forms, with or without
|
|
11
|
-
modification, are permitted provided that the following conditions
|
|
12
|
-
are met:
|
|
13
|
-
1. Redistributions of source code must retain the above copyright
|
|
14
|
-
notice, this list of conditions and the following disclaimer.
|
|
15
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
16
|
-
notice, this list of conditions and the following disclaimer in the
|
|
17
|
-
documentation and/or other materials provided with the distribution.
|
|
18
|
-
3. The name of the author may not be used to endorse or promote products
|
|
19
|
-
derived from this software without specific prior written permission.
|
|
20
|
-
|
|
21
|
-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
22
|
-
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
23
|
-
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
24
|
-
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
25
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
26
|
-
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
27
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
28
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
29
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
30
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
-
==============================
|
|
32
|
-
|
|
33
|
-
Portions of Libevent are based on works by others, also made available by
|
|
34
|
-
them under the three-clause BSD license above. The copyright notices are
|
|
35
|
-
available in the corresponding source files; the license is as above. Here's
|
|
36
|
-
a list:
|
|
37
|
-
|
|
38
|
-
log.c:
|
|
39
|
-
Copyright (c) 2000 Dug Song <dugsong@monkey.org>
|
|
40
|
-
Copyright (c) 1993 The Regents of the University of California.
|
|
41
|
-
|
|
42
|
-
strlcpy.c:
|
|
43
|
-
Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
|
44
|
-
|
|
45
|
-
win32select.c:
|
|
46
|
-
Copyright (c) 2003 Michael A. Davis <mike@datanerds.net>
|
|
47
|
-
|
|
48
|
-
evport.c:
|
|
49
|
-
Copyright (c) 2007 Sun Microsystems
|
|
50
|
-
|
|
51
|
-
ht-internal.h:
|
|
52
|
-
Copyright (c) 2002 Christopher Clark
|
|
53
|
-
|
|
54
|
-
minheap-internal.h:
|
|
55
|
-
Copyright (c) 2006 Maxim Yegorushkin <maxim.yegorushkin@gmail.com>
|
|
56
|
-
|
|
57
|
-
==============================
|
|
58
|
-
|
|
59
|
-
The arc4module is available under the following, sometimes called the
|
|
60
|
-
"OpenBSD" license:
|
|
61
|
-
|
|
62
|
-
Copyright (c) 1996, David Mazieres <dm@uun.org>
|
|
63
|
-
Copyright (c) 2008, Damien Miller <djm@openbsd.org>
|
|
64
|
-
|
|
65
|
-
Permission to use, copy, modify, and distribute this software for any
|
|
66
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
67
|
-
copyright notice and this permission notice appear in all copies.
|
|
68
|
-
|
|
69
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
70
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
71
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
72
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
73
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
74
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
75
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
76
|
-
|
|
77
|
-
==============================
|
|
78
|
-
|
|
79
|
-
The Windows timer code is based on code from libutp, which is
|
|
80
|
-
distributed under this license, sometimes called the "MIT" license.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
Copyright (c) 2010 BitTorrent, Inc.
|
|
84
|
-
|
|
85
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
86
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
87
|
-
in the Software without restriction, including without limitation the rights
|
|
88
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
89
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
90
|
-
furnished to do so, subject to the following conditions:
|
|
91
|
-
|
|
92
|
-
The above copyright notice and this permission notice shall be included in
|
|
93
|
-
all copies or substantial portions of the Software.
|
|
94
|
-
|
|
95
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
96
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
97
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
98
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
99
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
100
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
101
|
-
THE SOFTWARE.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
ncurses.txt
|
|
105
|
-
===========
|
|
106
|
-
Copyright 2018-2024,2025 Thomas E. Dickey
|
|
107
|
-
Copyright 1998-2017,2018 Free Software Foundation, Inc.
|
|
108
|
-
|
|
109
|
-
Permission is hereby granted, free of charge, to any person obtaining a
|
|
110
|
-
copy of this software and associated documentation files (the
|
|
111
|
-
"Software"), to deal in the Software without restriction, including
|
|
112
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
113
|
-
distribute, distribute with modifications, sublicense, and/or sell
|
|
114
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
115
|
-
furnished to do so, subject to the following conditions:
|
|
116
|
-
|
|
117
|
-
The above copyright notice and this permission notice shall be included
|
|
118
|
-
in all copies or substantial portions of the Software.
|
|
119
|
-
|
|
120
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
121
|
-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
122
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
123
|
-
IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
124
|
-
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
125
|
-
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
126
|
-
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
127
|
-
|
|
128
|
-
Except as contained in this notice, the name(s) of the above copyright
|
|
129
|
-
holders shall not be used in advertising or otherwise to promote the
|
|
130
|
-
sale, use or other dealings in this Software without prior written
|
|
131
|
-
authorization.
|
|
132
|
-
|
|
133
|
-
-- vile:txtmode fc=72
|
|
134
|
-
-- $Id: COPYING,v 1.14 2025/01/04 10:53:46 tom Exp $
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
tmux.txt
|
|
138
|
-
========
|
|
139
|
-
Copyright (c) Various Authors
|
|
140
|
-
|
|
141
|
-
Permission to use, copy, modify, and distribute this software for any
|
|
142
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
143
|
-
copyright notice and this permission notice appear in all copies.
|
|
144
|
-
|
|
145
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
146
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
147
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
148
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
149
|
-
WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
150
|
-
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
151
|
-
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
152
|
-
|
package/manifest.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"schema":2,"format":"standard-npm-native-target-v2","repository":"standardagents/code-rs","commit":"89a5a75f1ec0949a1ae901c7316179aa7727a348","version":"0.14.2","target":"x86_64-unknown-linux-gnu","runtime":{"tmuxVersion":"3.7","tmuxSha256":"253051129b9534f66a6b364f0613688886dca92c764db1660f081cdcaea882fe","accountUpdateProtocol":1,"minimumGlibc":"2.28"},"signing":{"algorithm":"ed25519","keyId":"team-2026-1","platformCodeSignature":"ed25519-only"},"files":[{"path":"bin/standard","size":17127016,"sha256":"eeee8aea296bdfc765bfe4ea058b7973bf61c3e5aa59ba5dcf4369eef67ab1cd"},{"path":"bin/standardd","size":18902560,"sha256":"0d724b1b0f38de99d3eeb482bef34b5e7ba444500f051d3f929d0d1a2e54128e"},{"path":"bin/tmux","size":1433024,"sha256":"253051129b9534f66a6b364f0613688886dca92c764db1660f081cdcaea882fe"},{"path":"licenses/THIRD-PARTY.txt","size":6779,"sha256":"fc410e91ff375a3057837d3029ec2626e6110a05f69b6fee7ca4e9f588b1a294"}]}
|
package/manifest.sig
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pVZscMwUhO55O8xQEuNSNrn2FUwFY4Kw/iVfdEer7rz+OL6xx9qQjXUWh7xEmoreblfCCFdx4mDYEIAKhE9iAg==
|