@standardagents/code 0.14.1-issue.653.6647dc-linux-x64-gnu → 0.14.1-issue.653.6647dc
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 +326 -0
- package/lib/backend-profile.mjs +114 -0
- package/lib/launcher.mjs +75 -0
- package/lib/platform.mjs +50 -0
- package/package.json +30 -18
- package/postinstall.mjs +12 -0
- package/bin/standard +0 -4
- package/bin/standardd +0 -4
- package/bin/tmux +0 -0
- package/lib/standard-plugin-runner/THIRD-PARTY.txt +0 -252
- package/lib/standard-plugin-runner/index.mjs +0 -1093
- package/lib/standard-plugin-runner/loader.mjs +0 -210817
- package/lib/standard-plugin-runner/runtime.json +0 -1
- package/lib/standard-plugin-runner/sdk.mjs +0 -634
- package/lib/standard-plugin-runner/worker.mjs +0 -1561
- 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,326 @@
|
|
|
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
|
+
// The four native targets the launcher has ever installed. The two deferred
|
|
88
|
+
// ones stay so their published history verifies.
|
|
89
|
+
export const NATIVE_ARTIFACT_TARGETS = Object.freeze([
|
|
90
|
+
'aarch64-apple-darwin', 'x86_64-apple-darwin',
|
|
91
|
+
'aarch64-unknown-linux-gnu', 'x86_64-unknown-linux-gnu',
|
|
92
|
+
])
|
|
93
|
+
// The browser viewer runtime: a fifth, distinct artifact kind that the same
|
|
94
|
+
// build workers compile and sign. It never installs through the launcher.
|
|
95
|
+
export const WEB_ARTIFACT_TARGET = 'wasm32-unknown-unknown'
|
|
96
|
+
export const ARTIFACT_TARGETS = Object.freeze([...NATIVE_ARTIFACT_TARGETS, WEB_ARTIFACT_TARGET])
|
|
97
|
+
|
|
98
|
+
// Web artifact (schema 4): the wasm-bindgen output, the bundled fonts, their
|
|
99
|
+
// licenses, and the build record, at the artifact root. The font and license
|
|
100
|
+
// sets vary with the pinned font list, so the manifest enumerates what the
|
|
101
|
+
// build produced and the verifier checks each path against these rules.
|
|
102
|
+
export const WEB_ARTIFACT_FORMAT = 'standard-npm-web-target-v1'
|
|
103
|
+
export const WEB_ARTIFACT_SCHEMA = 4
|
|
104
|
+
export const WEB_ARTIFACT_REQUIRED_FILES = Object.freeze([
|
|
105
|
+
'build.json', 'pkg/standard_web.js', 'pkg/standard_web_bg.wasm',
|
|
106
|
+
])
|
|
107
|
+
export const WEB_ARTIFACT_OPTIONAL_FILES = Object.freeze([
|
|
108
|
+
'pkg/standard_web.d.ts', 'pkg/standard_web_bg.wasm.d.ts',
|
|
109
|
+
])
|
|
110
|
+
// One level deep, one file kind each; at least one entry of each.
|
|
111
|
+
export const WEB_ARTIFACT_DIRECTORIES = Object.freeze({ fonts: /\.ttf$/, licenses: /\.txt$/ })
|
|
112
|
+
export const WEB_ARTIFACT_FILE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
|
|
113
|
+
export const MAX_WEB_ASSET_BYTES = 64 * 1024 * 1024
|
|
114
|
+
|
|
115
|
+
// Whether one artifact-relative path may appear in a web artifact.
|
|
116
|
+
export function webArtifactPathAllowed(path) {
|
|
117
|
+
if (typeof path !== 'string') return false
|
|
118
|
+
const parts = path.split('/')
|
|
119
|
+
if (!parts.every(part => WEB_ARTIFACT_FILE_NAME.test(part))) return false
|
|
120
|
+
if (WEB_ARTIFACT_REQUIRED_FILES.includes(path) || WEB_ARTIFACT_OPTIONAL_FILES.includes(path)) return true
|
|
121
|
+
return parts.length === 2 && Boolean(WEB_ARTIFACT_DIRECTORIES[parts[0]]?.test(parts[1]))
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Check a complete web file list: every path allowed, every required file
|
|
125
|
+
// present, each directory non-empty, no duplicates. Returns the sorted list.
|
|
126
|
+
export function webArtifactFileList(paths) {
|
|
127
|
+
if (!Array.isArray(paths) || paths.some(path => !webArtifactPathAllowed(path))) {
|
|
128
|
+
throw new Error('Web artifact file manifest is invalid')
|
|
129
|
+
}
|
|
130
|
+
const files = [...paths].sort()
|
|
131
|
+
if (new Set(files).size !== files.length) throw new Error('Web artifact file manifest is invalid')
|
|
132
|
+
const missing = WEB_ARTIFACT_REQUIRED_FILES.filter(path => !files.includes(path))
|
|
133
|
+
for (const directory of Object.keys(WEB_ARTIFACT_DIRECTORIES)) {
|
|
134
|
+
if (!files.some(path => path.startsWith(`${directory}/`))) missing.push(`${directory}/`)
|
|
135
|
+
}
|
|
136
|
+
if (missing.length) throw new Error(`Web artifact is incomplete: missing ${missing.join(', ')}`)
|
|
137
|
+
return files
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Enumerate a built web artifact root as the file list its manifest binds.
|
|
141
|
+
// Every entry must be a regular file the rules allow; anything else fails.
|
|
142
|
+
export function webArtifactFilesOnDisk(root, metadata = ['manifest.json', 'manifest.sig']) {
|
|
143
|
+
const files = []
|
|
144
|
+
function visit(relative) {
|
|
145
|
+
for (const name of readdirSync(join(root, relative))) {
|
|
146
|
+
const child = relative ? `${relative}/${name}` : name
|
|
147
|
+
if (!relative && metadata.includes(child)) continue
|
|
148
|
+
const entry = lstatSync(join(root, child))
|
|
149
|
+
if (entry.isDirectory() && !relative && Object.hasOwn(WEB_ARTIFACT_DIRECTORIES, child)) visit(child)
|
|
150
|
+
else if (entry.isDirectory() && !relative && child === 'pkg') visit(child)
|
|
151
|
+
else if (!entry.isFile() || !webArtifactPathAllowed(child)) throw new Error(`Unexpected artifact content: ${child}`)
|
|
152
|
+
else files.push(child)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
visit('')
|
|
156
|
+
return webArtifactFileList(files)
|
|
157
|
+
}
|
|
158
|
+
// Public trust anchor, not a credential. Never obtain the verification key
|
|
159
|
+
// from the package being verified or a mutable registry response.
|
|
160
|
+
export const ARTIFACT_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
161
|
+
MCowBQYDK2VwAyEAk+Ndu0WtdSgUFkraXP5CAUlQqzm+EN/My2AwkoPOMqg=
|
|
162
|
+
-----END PUBLIC KEY-----
|
|
163
|
+
`
|
|
164
|
+
|
|
165
|
+
export function validArtifactVersion(version) {
|
|
166
|
+
return typeof version === 'string'
|
|
167
|
+
&& /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(version)
|
|
168
|
+
&& (version.match(/^[^-]+-(.*)$/)?.[1].split('.') ?? []).every(part => !/^0\d+$/.test(part))
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function regularFile(path, limit) {
|
|
172
|
+
const descriptor = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW)
|
|
173
|
+
try {
|
|
174
|
+
const metadata = fstatSync(descriptor)
|
|
175
|
+
if (!metadata.isFile() || metadata.size < 1 || metadata.size > limit) throw new Error(`Invalid artifact file: ${path}`)
|
|
176
|
+
return { descriptor, metadata }
|
|
177
|
+
} catch (error) { closeSync(descriptor); throw error }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function boundedBytes(path, limit) {
|
|
181
|
+
const { descriptor } = regularFile(path, limit)
|
|
182
|
+
try {
|
|
183
|
+
const buffer = Buffer.alloc(limit + 1)
|
|
184
|
+
let size = 0
|
|
185
|
+
while (size <= limit) {
|
|
186
|
+
const count = readSync(descriptor, buffer, size, buffer.length - size, null)
|
|
187
|
+
if (!count) return buffer.subarray(0, size)
|
|
188
|
+
size += count
|
|
189
|
+
}
|
|
190
|
+
throw new Error(`Artifact exceeds size limit: ${path}`)
|
|
191
|
+
} finally { closeSync(descriptor) }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Read and authenticate an artifact's manifest against the pinned key. The
|
|
195
|
+
// bytes that were signed are the bytes parsed; nothing is trusted before this.
|
|
196
|
+
function signedManifest(root, publicKey, label) {
|
|
197
|
+
if (!lstatSync(root).isDirectory()) throw new Error(`Invalid artifact directory: ${root}`)
|
|
198
|
+
const bytes = boundedBytes(join(root, 'manifest.json'), 64 * 1024)
|
|
199
|
+
const signature = boundedBytes(join(root, 'manifest.sig'), 256).toString('utf8').trim()
|
|
200
|
+
const key = createPublicKey(publicKey)
|
|
201
|
+
if (key.asymmetricKeyType !== 'ed25519' || !verify(null, bytes, key, Buffer.from(signature, 'base64'))) {
|
|
202
|
+
throw new Error(`${label} artifact signature is invalid`)
|
|
203
|
+
}
|
|
204
|
+
return JSON.parse(bytes)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Every manifested file must exist with exactly its signed size and digest.
|
|
208
|
+
function verifyFileDigests(root, manifest, limitFor, label) {
|
|
209
|
+
const buffer = Buffer.alloc(1024 * 1024)
|
|
210
|
+
for (const file of manifest.files) {
|
|
211
|
+
if (!Number.isSafeInteger(file.size) || !/^[0-9a-f]{64}$/.test(file.sha256)) throw new Error(`${label} artifact file metadata is invalid`)
|
|
212
|
+
const path = join(root, file.path)
|
|
213
|
+
const { descriptor, metadata } = regularFile(path, limitFor(file.path))
|
|
214
|
+
try {
|
|
215
|
+
if (metadata.size !== file.size) throw new Error(`${label} artifact size mismatch: ${file.path}`)
|
|
216
|
+
const hash = createHash('sha256')
|
|
217
|
+
let size = 0
|
|
218
|
+
for (;;) {
|
|
219
|
+
const count = readSync(descriptor, buffer, 0, buffer.length, null)
|
|
220
|
+
if (!count) break
|
|
221
|
+
size += count
|
|
222
|
+
if (size > file.size) throw new Error(`${label} artifact grew while verifying: ${file.path}`)
|
|
223
|
+
hash.update(buffer.subarray(0, count))
|
|
224
|
+
}
|
|
225
|
+
if (size !== file.size || hash.digest('hex') !== file.sha256) throw new Error(`${label} artifact digest mismatch: ${file.path}`)
|
|
226
|
+
} finally { closeSync(descriptor) }
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function verifyNativeArtifact(root, expected = {}, publicKey = ARTIFACT_PUBLIC_KEY) {
|
|
231
|
+
const manifest = signedManifest(root, publicKey, 'Native')
|
|
232
|
+
const files = artifactFiles(manifest)
|
|
233
|
+
if (manifest.repository !== 'standardagents/code-rs'
|
|
234
|
+
|| !NATIVE_ARTIFACT_TARGETS.includes(manifest.target)
|
|
235
|
+
|| !/^[0-9a-f]{40}$/.test(manifest.commit)
|
|
236
|
+
|| !validArtifactVersion(manifest.version)
|
|
237
|
+
|| ['commit', 'version', 'target'].some(name => expected[name] != null && manifest[name] !== expected[name])
|
|
238
|
+
|| manifest.signing?.algorithm !== 'ed25519') throw new Error('Native artifact identity is invalid')
|
|
239
|
+
if (Object.hasOwn(manifest, 'backendProfile') && (manifest.backendProfile == null || manifest.backendProfile === '')) {
|
|
240
|
+
throw new Error('Native artifact backend profile cannot be null')
|
|
241
|
+
}
|
|
242
|
+
const backendProfile = normalizeBackendProfile(manifest.backendProfile)
|
|
243
|
+
if (backendProfile && !isPreviewBuild(manifest.version)) {
|
|
244
|
+
throw new Error('Native artifact preview backend profile is not valid for this version')
|
|
245
|
+
}
|
|
246
|
+
if (!Array.isArray(manifest.files) || manifest.files.map(file => file.path).sort().join(',') !== [...files].sort().join(',')) {
|
|
247
|
+
throw new Error('Native artifact file manifest is invalid')
|
|
248
|
+
}
|
|
249
|
+
const runnerFiles = manifest.target.endsWith('-apple-darwin')
|
|
250
|
+
? BUNDLE_RUNNER_ARTIFACT_FILES.slice(BUNDLE_ARTIFACT_FILES.length)
|
|
251
|
+
: RUNNER_ARTIFACT_FILES.slice(ARTIFACT_FILES.length)
|
|
252
|
+
if (!manifest.files.some(file => runnerFiles.includes(file.path))) {
|
|
253
|
+
for (const path of runnerFiles) {
|
|
254
|
+
try { lstatSync(join(root, path)) }
|
|
255
|
+
catch (error) { if (error.code === 'ENOENT') continue; throw error }
|
|
256
|
+
throw new Error('Native artifact contains unsigned plugin runner files')
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (manifest.schema === 3) verifyArtifactTree(root, files)
|
|
260
|
+
else for (const directory of artifactDirectories(files)) {
|
|
261
|
+
if (!lstatSync(join(root, directory)).isDirectory()) throw new Error(`Invalid artifact directory: ${directory}`)
|
|
262
|
+
}
|
|
263
|
+
const tmux = manifest.files.find(file => file.path === artifactBinaryPath(manifest, 'tmux'))
|
|
264
|
+
if (manifest.runtime?.tmuxVersion !== '3.7' || manifest.runtime.tmuxSha256 !== tmux.sha256) {
|
|
265
|
+
throw new Error('Native artifact tmux identity is invalid')
|
|
266
|
+
}
|
|
267
|
+
const protocol = manifest.runtime.accountUpdateProtocol
|
|
268
|
+
if (protocol != null && (!Number.isSafeInteger(protocol) || protocol < 1 || protocol > 0xffff_ffff)) {
|
|
269
|
+
throw new Error('Native artifact account update protocol is invalid')
|
|
270
|
+
}
|
|
271
|
+
if (manifest.target.endsWith('-apple-darwin')
|
|
272
|
+
&& (manifest.signing.platformCodeSignature !== 'apple-developer-id'
|
|
273
|
+
|| manifest.signing.notarization?.status !== 'Accepted'
|
|
274
|
+
|| !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(manifest.signing.notarization?.submissionId ?? ''))) {
|
|
275
|
+
throw new Error('macOS artifact lacks signed notarization acceptance')
|
|
276
|
+
}
|
|
277
|
+
if (manifest.target.endsWith('-unknown-linux-gnu')
|
|
278
|
+
&& !/^\d+\.\d+(?:\.\d+)?$/.test(manifest.runtime.minimumGlibc ?? '')) throw new Error('Linux artifact lacks its glibc requirement')
|
|
279
|
+
verifyFileDigests(root, manifest, path => runnerFiles.includes(path) ? MAX_RUNNER_ASSET_BYTES : 256 * 1024 * 1024, 'Native')
|
|
280
|
+
return manifest
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Verify a web artifact root: the Ed25519 signature, the schema-4 identity,
|
|
284
|
+
// the file rules, the exact on-disk file set (nothing unmanifested, no
|
|
285
|
+
// links), the build record, and every digest. Returns the manifest.
|
|
286
|
+
export function verifyWebArtifact(root, expected = {}, publicKey = ARTIFACT_PUBLIC_KEY) {
|
|
287
|
+
const manifest = signedManifest(root, publicKey, 'Web')
|
|
288
|
+
if (manifest.schema !== WEB_ARTIFACT_SCHEMA || manifest.format !== WEB_ARTIFACT_FORMAT
|
|
289
|
+
|| manifest.target !== WEB_ARTIFACT_TARGET
|
|
290
|
+
|| manifest.repository !== 'standardagents/code-rs'
|
|
291
|
+
|| !/^[0-9a-f]{40}$/.test(manifest.commit)
|
|
292
|
+
|| !validArtifactVersion(manifest.version)
|
|
293
|
+
|| ['commit', 'version', 'target'].some(name => expected[name] != null && manifest[name] !== expected[name])
|
|
294
|
+
|| manifest.signing?.algorithm !== 'ed25519') throw new Error('Web artifact identity is invalid')
|
|
295
|
+
if (Object.hasOwn(manifest, 'backendProfile') && (manifest.backendProfile == null || manifest.backendProfile === '')) {
|
|
296
|
+
throw new Error('Web artifact backend profile cannot be null')
|
|
297
|
+
}
|
|
298
|
+
const backendProfile = normalizeBackendProfile(manifest.backendProfile)
|
|
299
|
+
if (backendProfile && !isPreviewBuild(manifest.version)) {
|
|
300
|
+
throw new Error('Web artifact preview backend profile is not valid for this version')
|
|
301
|
+
}
|
|
302
|
+
if (!Array.isArray(manifest.files)) throw new Error('Web artifact file manifest is invalid')
|
|
303
|
+
const files = webArtifactFileList(manifest.files.map(file => file?.path))
|
|
304
|
+
verifyArtifactTree(root, files)
|
|
305
|
+
verifyFileDigests(root, manifest, () => MAX_WEB_ASSET_BYTES, 'Web')
|
|
306
|
+
// The build record is the identity the bundle itself reports; it must name
|
|
307
|
+
// the signed build, not a local or foreign one.
|
|
308
|
+
let record
|
|
309
|
+
try { record = JSON.parse(boundedBytes(join(root, 'build.json'), 4096)) } catch { record = null }
|
|
310
|
+
if (record?.schema !== 1 || record.commit !== manifest.commit || record.version !== manifest.version) {
|
|
311
|
+
throw new Error('Web artifact build record does not name the signed build')
|
|
312
|
+
}
|
|
313
|
+
return manifest
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function requireCompatibleGlibc(manifest, runtimeVersion) {
|
|
317
|
+
if (!manifest.target.endsWith('-unknown-linux-gnu')) return
|
|
318
|
+
const minimum = manifest.runtime.minimumGlibc
|
|
319
|
+
if (!/^\d+\.\d+(?:\.\d+)?$/.test(runtimeVersion ?? '')) throw new Error('Cannot determine this machine’s glibc version')
|
|
320
|
+
const actual = runtimeVersion.split('.').map(Number)
|
|
321
|
+
const required = minimum.split('.').map(Number)
|
|
322
|
+
for (let index = 0; index < 3; index++) {
|
|
323
|
+
if ((actual[index] ?? 0) > (required[index] ?? 0)) return
|
|
324
|
+
if ((actual[index] ?? 0) < (required[index] ?? 0)) throw new Error(`This Standard build requires glibc ${minimum}; this machine has ${runtimeVersion}`)
|
|
325
|
+
}
|
|
326
|
+
}
|
|
@@ -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/launcher.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import { readFileSync, realpathSync, statSync } from 'node:fs'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import { dirname, 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
|
+
|
|
10
|
+
const require = createRequire(import.meta.url)
|
|
11
|
+
const COMMANDS = new Set(['standard', 'standardd'])
|
|
12
|
+
|
|
13
|
+
export function resolveBinary(command, options = {}) {
|
|
14
|
+
if (!COMMANDS.has(command)) {
|
|
15
|
+
throw new Error(`Unknown Standard executable: ${command}`)
|
|
16
|
+
}
|
|
17
|
+
const environment = options.environment ?? process.env
|
|
18
|
+
const overrideDirectory = environment.STANDARD_CODE_BINARY_DIR
|
|
19
|
+
const binaryPath = overrideDirectory
|
|
20
|
+
? join(overrideDirectory, command)
|
|
21
|
+
: resolvePackagedBinary(command, options)
|
|
22
|
+
const stat = statSync(binaryPath)
|
|
23
|
+
if (!stat.isFile()) {
|
|
24
|
+
throw new Error(`Resolved Standard executable is not a file: ${binaryPath}`)
|
|
25
|
+
}
|
|
26
|
+
return binaryPath
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function resolvePackagedBinary(command, options) {
|
|
30
|
+
const platform = platformPackage(
|
|
31
|
+
options.platform,
|
|
32
|
+
options.architecture,
|
|
33
|
+
options.report,
|
|
34
|
+
)
|
|
35
|
+
const resolve = options.resolve ?? require.resolve
|
|
36
|
+
try {
|
|
37
|
+
const root = dirname(realpathSync(resolve(`${platform.packageName}/manifest.json`)))
|
|
38
|
+
const version = JSON.parse(readFileSync(new URL('../package.json', import.meta.url))).version
|
|
39
|
+
const artifact = verifyNativeArtifact(root, { version, target: platform.rustTarget })
|
|
40
|
+
const report = options.report ?? process.report
|
|
41
|
+
requireCompatibleGlibc(artifact, report?.getReport()?.header?.glibcVersionRuntime)
|
|
42
|
+
return join(root, artifactBinaryPath(artifact, command))
|
|
43
|
+
} catch (error) {
|
|
44
|
+
const detail = error instanceof Error ? error.message : String(error)
|
|
45
|
+
throw new Error(
|
|
46
|
+
`The native package ${platform.packageName} is missing or incomplete. `
|
|
47
|
+
+ `Reinstall @standardagents/code for this platform. (${detail})`,
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function spawnBinary(command, args, options = {}) {
|
|
53
|
+
const binary = resolveBinary(command, options)
|
|
54
|
+
return spawnSync(binary, args, {
|
|
55
|
+
stdio: options.stdio ?? 'inherit',
|
|
56
|
+
env: options.environment ?? process.env,
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function main(command) {
|
|
61
|
+
try {
|
|
62
|
+
const result = spawnBinary(command, process.argv.slice(2))
|
|
63
|
+
if (result.error) throw result.error
|
|
64
|
+
if (result.signal) {
|
|
65
|
+
console.error(`${command} terminated by ${result.signal}`)
|
|
66
|
+
process.exitCode = 1
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
process.exitCode = result.status ?? 1
|
|
70
|
+
} catch (error) {
|
|
71
|
+
const detail = error instanceof Error ? error.message : String(error)
|
|
72
|
+
console.error(`${command}: ${detail}`)
|
|
73
|
+
process.exitCode = 1
|
|
74
|
+
}
|
|
75
|
+
}
|
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,30 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standardagents/code",
|
|
3
|
-
"version": "0.14.1-issue.653.6647dc
|
|
4
|
-
"description": "Standard
|
|
3
|
+
"version": "0.14.1-issue.653.6647dc",
|
|
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
|
-
"
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
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
|
+
},
|
|
19
22
|
"files": [
|
|
20
23
|
"bin",
|
|
21
|
-
"licenses",
|
|
22
24
|
"lib",
|
|
23
|
-
"
|
|
24
|
-
"manifest.sig"
|
|
25
|
+
"postinstall.mjs"
|
|
25
26
|
],
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
27
|
+
"scripts": {
|
|
28
|
+
"postinstall": "node postinstall.mjs"
|
|
29
|
+
},
|
|
30
|
+
"optionalDependencies": {
|
|
31
|
+
"@standardagents/code-darwin-arm64": "npm:@standardagents/code@0.14.1-issue.653.6647dc-darwin-arm64",
|
|
32
|
+
"@standardagents/code-linux-x64-gnu": "npm:@standardagents/code@0.14.1-issue.653.6647dc-linux-x64-gnu"
|
|
33
|
+
},
|
|
34
|
+
"standardUpgrade": {
|
|
35
|
+
"schema": 1,
|
|
36
|
+
"reader": 1,
|
|
37
|
+
"bridge": {
|
|
38
|
+
"version": "0.14.1-canary.76909e",
|
|
39
|
+
"commit": "76909e97ec56c2ba5490932135642962c4035596"
|
|
40
|
+
}
|
|
29
41
|
}
|
|
30
42
|
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { chmodSync } from 'node:fs'
|
|
2
|
+
|
|
3
|
+
import { resolveBinary } from './lib/launcher.mjs'
|
|
4
|
+
|
|
5
|
+
for (const command of ['standard', 'standardd']) {
|
|
6
|
+
try {
|
|
7
|
+
chmodSync(resolveBinary(command), 0o755)
|
|
8
|
+
} catch (error) {
|
|
9
|
+
const detail = error instanceof Error ? error.message : String(error)
|
|
10
|
+
console.warn(`@standardagents/code: ${detail}`)
|
|
11
|
+
}
|
|
12
|
+
}
|
package/bin/standard
DELETED
package/bin/standardd
DELETED
package/bin/tmux
DELETED
|
Binary file
|