@standardagents/code 0.14.1-issue.613.93617f-linux-x64-gnu → 0.14.1-issue.613.93617f
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 +218 -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 -1049
- 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 -608
- package/lib/standard-plugin-runner/worker.mjs +0 -1421
- 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,218 @@
|
|
|
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
|
+
export const ARTIFACT_TARGETS = Object.freeze([
|
|
88
|
+
'aarch64-apple-darwin', 'x86_64-apple-darwin',
|
|
89
|
+
'aarch64-unknown-linux-gnu', 'x86_64-unknown-linux-gnu',
|
|
90
|
+
])
|
|
91
|
+
// Public trust anchor, not a credential. Never obtain the verification key
|
|
92
|
+
// from the package being verified or a mutable registry response.
|
|
93
|
+
export const ARTIFACT_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
94
|
+
MCowBQYDK2VwAyEAk+Ndu0WtdSgUFkraXP5CAUlQqzm+EN/My2AwkoPOMqg=
|
|
95
|
+
-----END PUBLIC KEY-----
|
|
96
|
+
`
|
|
97
|
+
|
|
98
|
+
export function validArtifactVersion(version) {
|
|
99
|
+
return typeof version === 'string'
|
|
100
|
+
&& /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(version)
|
|
101
|
+
&& (version.match(/^[^-]+-(.*)$/)?.[1].split('.') ?? []).every(part => !/^0\d+$/.test(part))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function regularFile(path, limit) {
|
|
105
|
+
const descriptor = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW)
|
|
106
|
+
try {
|
|
107
|
+
const metadata = fstatSync(descriptor)
|
|
108
|
+
if (!metadata.isFile() || metadata.size < 1 || metadata.size > limit) throw new Error(`Invalid artifact file: ${path}`)
|
|
109
|
+
return { descriptor, metadata }
|
|
110
|
+
} catch (error) { closeSync(descriptor); throw error }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function boundedBytes(path, limit) {
|
|
114
|
+
const { descriptor } = regularFile(path, limit)
|
|
115
|
+
try {
|
|
116
|
+
const buffer = Buffer.alloc(limit + 1)
|
|
117
|
+
let size = 0
|
|
118
|
+
while (size <= limit) {
|
|
119
|
+
const count = readSync(descriptor, buffer, size, buffer.length - size, null)
|
|
120
|
+
if (!count) return buffer.subarray(0, size)
|
|
121
|
+
size += count
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`Artifact exceeds size limit: ${path}`)
|
|
124
|
+
} finally { closeSync(descriptor) }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function verifyNativeArtifact(root, expected = {}, publicKey = ARTIFACT_PUBLIC_KEY) {
|
|
128
|
+
for (const directory of [root]) {
|
|
129
|
+
if (!lstatSync(directory).isDirectory()) throw new Error(`Invalid artifact directory: ${directory}`)
|
|
130
|
+
}
|
|
131
|
+
const bytes = boundedBytes(join(root, 'manifest.json'), 64 * 1024)
|
|
132
|
+
const signature = boundedBytes(join(root, 'manifest.sig'), 256).toString('utf8').trim()
|
|
133
|
+
const key = createPublicKey(publicKey)
|
|
134
|
+
if (key.asymmetricKeyType !== 'ed25519' || !verify(null, bytes, key, Buffer.from(signature, 'base64'))) {
|
|
135
|
+
throw new Error('Native artifact signature is invalid')
|
|
136
|
+
}
|
|
137
|
+
const manifest = JSON.parse(bytes)
|
|
138
|
+
const files = artifactFiles(manifest)
|
|
139
|
+
if (manifest.repository !== 'standardagents/code-rs'
|
|
140
|
+
|| !ARTIFACT_TARGETS.includes(manifest.target)
|
|
141
|
+
|| !/^[0-9a-f]{40}$/.test(manifest.commit)
|
|
142
|
+
|| !validArtifactVersion(manifest.version)
|
|
143
|
+
|| ['commit', 'version', 'target'].some(name => expected[name] != null && manifest[name] !== expected[name])
|
|
144
|
+
|| manifest.signing?.algorithm !== 'ed25519') throw new Error('Native artifact identity is invalid')
|
|
145
|
+
if (Object.hasOwn(manifest, 'backendProfile') && (manifest.backendProfile == null || manifest.backendProfile === '')) {
|
|
146
|
+
throw new Error('Native artifact backend profile cannot be null')
|
|
147
|
+
}
|
|
148
|
+
const backendProfile = normalizeBackendProfile(manifest.backendProfile)
|
|
149
|
+
if (backendProfile && !isPreviewBuild(manifest.version)) {
|
|
150
|
+
throw new Error('Native artifact preview backend profile is not valid for this version')
|
|
151
|
+
}
|
|
152
|
+
if (!Array.isArray(manifest.files) || manifest.files.map(file => file.path).sort().join(',') !== [...files].sort().join(',')) {
|
|
153
|
+
throw new Error('Native artifact file manifest is invalid')
|
|
154
|
+
}
|
|
155
|
+
const runnerFiles = manifest.target.endsWith('-apple-darwin')
|
|
156
|
+
? BUNDLE_RUNNER_ARTIFACT_FILES.slice(BUNDLE_ARTIFACT_FILES.length)
|
|
157
|
+
: RUNNER_ARTIFACT_FILES.slice(ARTIFACT_FILES.length)
|
|
158
|
+
if (!manifest.files.some(file => runnerFiles.includes(file.path))) {
|
|
159
|
+
for (const path of runnerFiles) {
|
|
160
|
+
try { lstatSync(join(root, path)) }
|
|
161
|
+
catch (error) { if (error.code === 'ENOENT') continue; throw error }
|
|
162
|
+
throw new Error('Native artifact contains unsigned plugin runner files')
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (manifest.schema === 3) verifyArtifactTree(root, files)
|
|
166
|
+
else for (const directory of artifactDirectories(files)) {
|
|
167
|
+
if (!lstatSync(join(root, directory)).isDirectory()) throw new Error(`Invalid artifact directory: ${directory}`)
|
|
168
|
+
}
|
|
169
|
+
const tmux = manifest.files.find(file => file.path === artifactBinaryPath(manifest, 'tmux'))
|
|
170
|
+
if (manifest.runtime?.tmuxVersion !== '3.7' || manifest.runtime.tmuxSha256 !== tmux.sha256) {
|
|
171
|
+
throw new Error('Native artifact tmux identity is invalid')
|
|
172
|
+
}
|
|
173
|
+
const protocol = manifest.runtime.accountUpdateProtocol
|
|
174
|
+
if (protocol != null && (!Number.isSafeInteger(protocol) || protocol < 1 || protocol > 0xffff_ffff)) {
|
|
175
|
+
throw new Error('Native artifact account update protocol is invalid')
|
|
176
|
+
}
|
|
177
|
+
if (manifest.target.endsWith('-apple-darwin')
|
|
178
|
+
&& (manifest.signing.platformCodeSignature !== 'apple-developer-id'
|
|
179
|
+
|| manifest.signing.notarization?.status !== 'Accepted'
|
|
180
|
+
|| !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(manifest.signing.notarization?.submissionId ?? ''))) {
|
|
181
|
+
throw new Error('macOS artifact lacks signed notarization acceptance')
|
|
182
|
+
}
|
|
183
|
+
if (manifest.target.endsWith('-unknown-linux-gnu')
|
|
184
|
+
&& !/^\d+\.\d+(?:\.\d+)?$/.test(manifest.runtime.minimumGlibc ?? '')) throw new Error('Linux artifact lacks its glibc requirement')
|
|
185
|
+
const buffer = Buffer.alloc(1024 * 1024)
|
|
186
|
+
for (const file of manifest.files) {
|
|
187
|
+
if (!Number.isSafeInteger(file.size) || !/^[0-9a-f]{64}$/.test(file.sha256)) throw new Error('Native artifact file metadata is invalid')
|
|
188
|
+
const path = join(root, file.path)
|
|
189
|
+
const { descriptor, metadata } = regularFile(path, runnerFiles.includes(file.path)
|
|
190
|
+
? MAX_RUNNER_ASSET_BYTES : 256 * 1024 * 1024)
|
|
191
|
+
try {
|
|
192
|
+
if (metadata.size !== file.size) throw new Error(`Native artifact size mismatch: ${file.path}`)
|
|
193
|
+
const hash = createHash('sha256')
|
|
194
|
+
let size = 0
|
|
195
|
+
for (;;) {
|
|
196
|
+
const count = readSync(descriptor, buffer, 0, buffer.length, null)
|
|
197
|
+
if (!count) break
|
|
198
|
+
size += count
|
|
199
|
+
if (size > file.size) throw new Error(`Native artifact grew while verifying: ${file.path}`)
|
|
200
|
+
hash.update(buffer.subarray(0, count))
|
|
201
|
+
}
|
|
202
|
+
if (size !== file.size || hash.digest('hex') !== file.sha256) throw new Error(`Native artifact digest mismatch: ${file.path}`)
|
|
203
|
+
} finally { closeSync(descriptor) }
|
|
204
|
+
}
|
|
205
|
+
return manifest
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function requireCompatibleGlibc(manifest, runtimeVersion) {
|
|
209
|
+
if (!manifest.target.endsWith('-unknown-linux-gnu')) return
|
|
210
|
+
const minimum = manifest.runtime.minimumGlibc
|
|
211
|
+
if (!/^\d+\.\d+(?:\.\d+)?$/.test(runtimeVersion ?? '')) throw new Error('Cannot determine this machine’s glibc version')
|
|
212
|
+
const actual = runtimeVersion.split('.').map(Number)
|
|
213
|
+
const required = minimum.split('.').map(Number)
|
|
214
|
+
for (let index = 0; index < 3; index++) {
|
|
215
|
+
if ((actual[index] ?? 0) > (required[index] ?? 0)) return
|
|
216
|
+
if ((actual[index] ?? 0) < (required[index] ?? 0)) throw new Error(`This Standard build requires glibc ${minimum}; this machine has ${runtimeVersion}`)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -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.613.93617f
|
|
4
|
-
"description": "Standard
|
|
3
|
+
"version": "0.14.1-issue.613.93617f",
|
|
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.613.93617f-darwin-arm64",
|
|
32
|
+
"@standardagents/code-linux-x64-gnu": "npm:@standardagents/code@0.14.1-issue.613.93617f-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
|