feat: support macOS arm64 remote Agent hosts

Extend GoodBuddy Agent packaging, installation, SSH attachment, Runtime lifecycle, and Desktop package management to macOS arm64. Linux x64, Linux arm64, and Darwin arm64 share the existing signed catalog. Preserve Ask read-only behavior and Execute account permissions, and stop detached tool descendants during Mac cancellation.

Upgrade Desktop before publishing the first mixed-platform catalog because older Linux-only readers reject Darwin entries. Intel Macs are not supported; no launchd service or administrator access is required. This commit does not publish a release.

Validation: 3520 tests passed, 57 skipped; typecheck, lint, and development build passed. Real Mac installation, Ask/Execute, cancellation and reconnect passed; final Linux installation, Ask and reconnect passed. Nine real model requests were recorded.

Release note: 支持将 Apple Silicon Mac 用作远程项目 Host,可安装 macOS arm64 Agent 并使用 Ask、Execute 和断线重连;与 Linux 共用一个包目录,发布混合目录前需升级 Desktop。
This commit is contained in:
mesalogo
2026-09-06 16:14:02 +08:00
parent 1f01c26e04
commit 9c6d1611e2
68 changed files with 1283 additions and 439 deletions
+6 -4
View File
@@ -1537,7 +1537,8 @@ describe('registerIpcHandlers SSH hosts', () => {
]
} as const
const agentPackageManager = {
getSnapshot: vi.fn(async () => agentPackageInventory),
getAllSnapshot: vi.fn(async () => agentPackageInventory),
forPlatform: vi.fn(() => agentPackageManager),
download: vi.fn(
async (
architecture: 'x64' | 'arm64',
@@ -1675,7 +1676,7 @@ describe('registerIpcHandlers SSH hosts', () => {
)?.(event, { refresh: true })
).resolves.toEqual(agentPackageInventory)
expect(
agentPackageManager.getSnapshot
agentPackageManager.getAllSnapshot
).toHaveBeenCalledWith({ refresh: true })
await expect(
electronMocks.handlers.get(
@@ -1690,6 +1691,7 @@ describe('registerIpcHandlers SSH hosts', () => {
ipcChannels.sshHostsAgentPackageProgress,
{
architecture: 'x64',
platform: 'linux',
phase: 'downloading',
completedBytes: 1,
totalBytes: 2
@@ -1902,8 +1904,8 @@ describe('registerIpcHandlers SSH hosts', () => {
})
).rejects.toThrow('拒绝来自未知窗口的 IPC 请求')
expect(
agentPackageManager.getSnapshot
).toHaveBeenCalledOnce()
agentPackageManager.getAllSnapshot
).toHaveBeenCalledTimes(3)
await expect(
electronMocks.handlers.get(
+9 -11
View File
@@ -5123,7 +5123,7 @@ export function registerIpcHandlers(
const request =
agentPackageInventoryRequestSchema.parse(input ?? {})
return agentPackageInventorySchema.parse(
await agentPackageManager.getSnapshot(request)
await agentPackageManager.getAllSnapshot(request)
)
}
)
@@ -5135,10 +5135,9 @@ export function registerIpcHandlers(
if (!agentPackageManager) {
throw new Error('Agent 包管理服务不可用')
}
const { architecture } =
const { architecture, platform } =
agentPackageArchitectureRequestSchema.parse(input)
return agentPackageInventorySchema.parse(
await agentPackageManager.download(
await agentPackageManager.forPlatform(platform).download(
architecture,
(progress) =>
sendValidatedProgress(
@@ -5148,7 +5147,7 @@ export function registerIpcHandlers(
progress
)
)
)
return agentPackageManager.getAllSnapshot()
}
)
@@ -5171,9 +5170,8 @@ export function registerIpcHandlers(
if (result.canceled || !archivePath) {
return undefined
}
return agentPackageInventorySchema.parse(
await agentPackageManager.importArchive(archivePath)
)
await agentPackageManager.importArchive(archivePath)
return agentPackageManager.getAllSnapshot()
}
)
@@ -5184,10 +5182,10 @@ export function registerIpcHandlers(
if (!agentPackageManager) {
throw new Error('Agent 包管理服务不可用')
}
const { architecture } =
const { architecture, platform } =
agentPackageArchitectureRequestSchema.parse(input)
const defaultPath =
await agentPackageManager.getExportArchiveName(
await agentPackageManager.forPlatform(platform).getExportArchiveName(
architecture
)
const result = await dialog.showSaveDialog(window, {
@@ -5204,7 +5202,7 @@ export function registerIpcHandlers(
const destination = result.filePath.endsWith('.gbagent')
? result.filePath
: `${result.filePath}.gbagent`
await agentPackageManager.exportArchive(
await agentPackageManager.forPlatform(platform).exportArchive(
architecture,
destination
)
+20 -38
View File
@@ -1,3 +1,5 @@
import { binaryTargetArchitecture } from '../../shared/node/binary-target'
import type { AgentPlatform } from '../../shared/agent-target'
import {
createHash,
createPublicKey,
@@ -206,9 +208,10 @@ export async function verifyAgentBundleDirectory(
await assertElfArchitecture(
join(bundleDirectory, manifest.entrypoint.runtimePath),
manifest.arch,
'Agent Node runtime'
'Agent Node runtime',
manifest.platform
)
const koffiPaths = requiredKoffiPayloadPaths(manifest.arch)
const koffiPaths = requiredKoffiPayloadPaths(manifest.arch, manifest.platform)
assertKoffiManifest(
manifest,
runtimeLock.koffi.version,
@@ -218,7 +221,8 @@ export async function verifyAgentBundleDirectory(
await assertElfArchitecture(
join(bundleDirectory, ...nativePath.split('/')),
manifest.arch,
'Agent Koffi native binding'
'Agent Koffi native binding',
manifest.platform
)
}
return {
@@ -349,15 +353,19 @@ export function assertAgentManifestMatchesRuntimeLock(
}
function requiredKoffiPayloadPaths(
architecture: AgentArchitecture
architecture: AgentArchitecture,
platform: AgentPlatform
): {
required: string[]
native: string[]
} {
const packageRoot = 'lib/node_modules/koffi'
const nativePackage =
`@koromix/koffi-linux-${architecture}`
`@koromix/koffi-${platform}-${architecture}`
const nativeRoot = `lib/node_modules/${nativePackage}`
const native = platform === 'darwin'
? [`${nativeRoot}/darwin_${architecture}/koffi.node`]
: [`${nativeRoot}/linux_${architecture}/koffi.node`, `${nativeRoot}/musl_${architecture}/koffi.node`]
return {
required: [
`${packageRoot}/package.json`,
@@ -366,13 +374,9 @@ function requiredKoffiPayloadPaths(
`${packageRoot}/src/koffi/src/static.js`,
`${nativeRoot}/package.json`,
`${nativeRoot}/index.js`,
`${nativeRoot}/linux_${architecture}/koffi.node`,
`${nativeRoot}/musl_${architecture}/koffi.node`
...native
],
native: [
`${nativeRoot}/linux_${architecture}/koffi.node`,
`${nativeRoot}/musl_${architecture}/koffi.node`
]
native
}
}
@@ -390,7 +394,7 @@ function assertKoffiManifest(
}
}
const nativePackage =
`@koromix/koffi-linux-${manifest.arch}`
`@koromix/koffi-${manifest.platform}-${manifest.arch}`
const koffiLicense = manifest.licenses.find(
(license) => license.package === 'koffi'
)
@@ -614,14 +618,15 @@ function modeString(mode: number): string {
async function assertElfArchitecture(
filePath: string,
expectedArchitecture: AgentArchitecture,
description: string
description: string,
platform: AgentPlatform
): Promise<void> {
const handle = await open(filePath, 'r')
try {
const header = Buffer.alloc(64)
const { bytesRead } = await handle.read(header, 0, header.length, 0)
const actualArchitecture = detectElfArchitecture(
header.subarray(0, bytesRead)
const actualArchitecture = binaryTargetArchitecture(
header.subarray(0, bytesRead), platform
)
if (actualArchitecture !== expectedArchitecture) {
throw new Error(
@@ -633,29 +638,6 @@ async function assertElfArchitecture(
}
}
function detectElfArchitecture(
buffer: Buffer
): AgentArchitecture | undefined {
if (
buffer.length < 20 ||
buffer[0] !== 0x7f ||
buffer.toString('ascii', 1, 4) !== 'ELF' ||
(buffer[5] !== 1 && buffer[5] !== 2)
) {
return undefined
}
const machine =
buffer[5] === 2
? buffer.readUInt16BE(18)
: buffer.readUInt16LE(18)
if (machine === 62) {
return 'x64'
}
if (machine === 183) {
return 'arm64'
}
return undefined
}
function parseContract<T>(
schema: { safeParse(value: unknown): {
@@ -43,7 +43,7 @@ export type AgentInstallationIdentity = {
major: number
minor: number
}
platform: 'linux'
platform: 'linux' | 'darwin'
architecture: AgentArchitecture
supervisor: 'detached-on-demand'
}
@@ -239,7 +239,7 @@ export class AgentInstallationManager {
protocol: {
...(registeredProtocol ?? runtimeLock.protocol)
},
platform: 'linux',
platform: probe.platform,
architecture: registered.arch,
supervisor: 'detached-on-demand'
}
@@ -20,6 +20,7 @@ import {
} from '../../shared/agent-package-contracts'
import {
AgentPackageManager,
selectLatestCompatibleEntry,
type VerifiedRemoteAgentInstallCandidate
} from './agent-package-manager'
@@ -256,6 +257,22 @@ function response(
}
describe('AgentPackageManager remote install candidates', () => {
it('selects Linux and Darwin arm64 independently from one catalog', async () => {
await createFixture('mirror', (catalog) => {
for (const platform of ['linux', 'darwin'] as const) {
catalog.entries.push({
...catalog.entries[0]!,
platform,
architecture: 'arm64',
archive: `goodbuddy-agent-2.0.0-${platform}-arm64.gbagent`
})
}
const parsed = agentPackageCatalogSchema.parse(catalog)
expect(selectLatestCompatibleEntry(parsed, 'arm64', '2.0.0').platform).toBe('linux')
expect(selectLatestCompatibleEntry(parsed, 'arm64', '2.0.0', 'darwin').platform).toBe('darwin')
expect(() => selectLatestCompatibleEntry(parsed, 'x64', '2.0.0', 'darwin')).toThrow()
})
})
it('removes interrupted manager-owned staging on startup', async () => {
const fixture = await createFixture('mirror')
const packageRoot = join(
+88 -26
View File
@@ -16,6 +16,7 @@ import {
writeFile
} from 'node:fs/promises'
import { basename, join, resolve } from 'node:path'
import { agentPlatformSchema, type AgentPlatform } from '../../shared/agent-target'
import {
agentPackageArchiveName,
agentPackageCatalogSchema,
@@ -94,6 +95,7 @@ type CatalogState =
}
export type AgentPackageManagerOptions = {
platform?: AgentPlatform
userDataPath: string
desktopVersion: string
keyRegistryPath: string
@@ -104,7 +106,7 @@ export type AgentPackageManagerOptions = {
export type VerifiedRemoteAgentInstallCandidate = {
source: UpdateSource
platform: 'linux'
platform: AgentPlatform
architecture: AgentArchitecture
version: string
minimumDesktopVersion: string
@@ -161,6 +163,7 @@ export type AgentPackageArchiveLease = {
}
export type AcquireInstallArchiveOptions = {
platform?: AgentPlatform
signal?: AbortSignal
onProgress?: (progress: AgentPackageDownloadProgress) => void
}
@@ -185,7 +188,7 @@ function candidateFromCatalogEntry(
): VerifiedRemoteAgentInstallCandidate {
return {
source,
platform: 'linux',
platform: entry.platform,
architecture: entry.architecture,
version: entry.version,
minimumDesktopVersion: entry.minimumDesktopVersion,
@@ -209,7 +212,7 @@ function candidateFromVerifiedRecord(
const descriptor = record.verified.descriptor
return {
source,
platform: 'linux',
platform: descriptor.platform,
architecture: descriptor.architecture,
version: descriptor.version,
minimumDesktopVersion: descriptor.minimumDesktopVersion,
@@ -220,7 +223,8 @@ function candidateFromVerifiedRecord(
},
archive: agentPackageArchiveName(
descriptor.version,
descriptor.architecture
descriptor.architecture,
descriptor.platform
),
size,
sha256: record.archiveSha256,
@@ -229,6 +233,9 @@ function candidateFromVerifiedRecord(
}
export class AgentPackageManager {
readonly #options: AgentPackageManagerOptions
readonly #platform: AgentPlatform
readonly #platformManagers = new Map<AgentPlatform, AgentPackageManager>()
readonly #rootDirectory: string
readonly #desktopVersion: string
readonly #keyRegistryPath: string
@@ -250,6 +257,8 @@ export class AgentPackageManager {
#catalogState?: CatalogState
constructor(options: AgentPackageManagerOptions) {
this.#options = options
this.#platform = agentPlatformSchema.parse(options.platform ?? 'linux')
this.#rootDirectory = resolve(
options.userDataPath,
'remote-components',
@@ -263,6 +272,31 @@ export class AgentPackageManager {
this.#startupCleanup = this.#cleanupInterruptedArtifacts()
}
forPlatform(platform: AgentPlatform): AgentPackageManager {
if (platform === this.#platform) return this
let manager = this.#platformManagers.get(platform)
if (!manager) {
manager = new AgentPackageManager({ ...this.#options, platform })
this.#platformManagers.set(platform, manager)
}
return manager
}
async getAllSnapshot(options: { refresh?: boolean } = {}): Promise<AgentPackageInventory> {
const linux = await this.forPlatform('linux').getSnapshot(options)
const darwin = this.forPlatform('darwin')
darwin.#catalogState = this.forPlatform('linux').#catalogState
const mac = await darwin.getInventory(options)
return agentPackageInventorySchema.parse({
...linux,
entries: [...linux.entries, ...mac.entries]
})
}
#select(catalog: AgentPackageCatalog, architecture: AgentArchitecture, desktopVersion: string) {
return selectLatestCompatibleEntry(catalog, architecture, desktopVersion, this.#platform)
}
async getInventory(
options: { refresh?: boolean } = {}
): Promise<AgentPackageInventory> {
@@ -270,7 +304,9 @@ export class AgentPackageManager {
this.#installed.clear()
}
const entries = await Promise.all(
agentArchitectureSchema.options.map(async (architecture) => {
agentArchitectureSchema.options.filter(architecture =>
this.#platform === 'linux' || architecture === 'arm64'
).map(async (architecture) => {
let record: InstalledRecord | undefined
let state: 'not-downloaded' | 'verified' | 'invalid'
try {
@@ -283,7 +319,7 @@ export class AgentPackageManager {
}
const latestVersion = this.#latestVersion(architecture)
return {
platform: 'linux' as const,
platform: this.#platform,
architecture,
state,
version: record?.verified.descriptor.version ?? null,
@@ -334,8 +370,11 @@ export class AgentPackageManager {
async getRemoteEnvironmentCatalog(
architecture: AgentArchitecture,
options: { signal?: AbortSignal } = {}
options: { signal?: AbortSignal; platform?: AgentPlatform } = {}
): Promise<VerifiedRemoteAgentEnvironmentCatalog> {
if (options.platform && options.platform !== this.#platform) {
return this.forPlatform(options.platform).getRemoteEnvironmentCatalog(architecture, options)
}
options.signal?.throwIfAborted()
let entry: AgentPackageCatalogEntry
let source: UpdateSource | undefined
@@ -346,7 +385,7 @@ export class AgentPackageManager {
source,
options.signal
)
entry = selectLatestCompatibleEntry(
entry = this.#select(
catalog,
architecture,
this.#desktopVersion
@@ -406,8 +445,11 @@ export class AgentPackageManager {
*/
async getRemoteInstallCandidate(
architecture: AgentArchitecture,
options: { signal?: AbortSignal } = {}
options: { signal?: AbortSignal; platform?: AgentPlatform } = {}
): Promise<VerifiedRemoteAgentInstallCandidate> {
if (options.platform && options.platform !== this.#platform) {
return this.forPlatform(options.platform).getRemoteInstallCandidate(architecture, options)
}
options.signal?.throwIfAborted()
const source = await this.#getUpdateSource()
options.signal?.throwIfAborted()
@@ -415,7 +457,7 @@ export class AgentPackageManager {
source,
options.signal
)
const entry = selectLatestCompatibleEntry(
const entry = this.#select(
catalog,
architecture,
this.#desktopVersion
@@ -463,7 +505,7 @@ export class AgentPackageManager {
source,
signal
)
const entry = selectLatestCompatibleEntry(
const entry = this.#select(
catalog,
architecture,
this.#desktopVersion
@@ -484,6 +526,11 @@ export class AgentPackageManager {
expectedCandidate: VerifiedRemoteAgentInstallCandidate,
options: AcquireInstallArchiveOptions = {}
): Promise<AgentPackageArchiveLease> {
if (expectedCandidate.platform !== this.#platform) {
return this.forPlatform(expectedCandidate.platform).acquireInstallArchive(
architecture, expectedCandidate, options
)
}
return this.#runExclusive(
architecture,
async () => {
@@ -507,7 +554,7 @@ export class AgentPackageManager {
source,
options.signal
)
const entry = selectLatestCompatibleEntry(
const entry = this.#select(
catalog,
architecture,
this.#desktopVersion
@@ -534,6 +581,9 @@ export class AgentPackageManager {
architecture: AgentArchitecture,
options: AcquireInstallArchiveOptions = {}
): Promise<AgentPackageArchiveLease> {
if (options.platform && options.platform !== this.#platform) {
return this.forPlatform(options.platform).acquireGoodBuddyInstallArchive(architecture, options)
}
return this.#runExclusive(
architecture,
async () => {
@@ -562,7 +612,7 @@ export class AgentPackageManager {
}
let entry: AgentPackageCatalogEntry
if (this.#catalogState?.state === 'available') {
entry = selectLatestCompatibleEntry(
entry = this.#select(
this.#catalogState.catalog,
architecture,
this.#desktopVersion
@@ -584,7 +634,7 @@ export class AgentPackageManager {
source,
options.signal
)
entry = selectLatestCompatibleEntry(
entry = this.#select(
catalog,
architecture,
this.#desktopVersion
@@ -651,6 +701,7 @@ export class AgentPackageManager {
): Promise<boolean> {
const descriptor = record.verified.descriptor
if (
descriptor.platform === candidate.platform &&
descriptor.architecture === candidate.architecture &&
descriptor.version === candidate.version &&
descriptor.minimumDesktopVersion ===
@@ -831,11 +882,12 @@ export class AgentPackageManager {
)
const architecture =
installed.verified.descriptor.architecture
return await this.#runExclusive(
const manager = this.forPlatform(installed.verified.descriptor.platform)
return await manager.#runExclusive(
architecture,
async () => {
await this.#publishInstalled(installed, architecture)
return this.getInventory()
await manager.#publishInstalled(installed, architecture)
return manager.getInventory()
}
)
} finally {
@@ -918,7 +970,8 @@ export class AgentPackageManager {
.verified.descriptor
return agentPackageArchiveName(
descriptor.version,
descriptor.architecture
descriptor.architecture,
descriptor.platform
)
}
@@ -978,7 +1031,10 @@ export class AgentPackageManager {
desktopVersion: this.#desktopVersion,
trustedRegistry: await this.#loadTrustedRegistry()
})
if (packageContent.descriptor.version !== entry.name) {
if (
packageContent.descriptor.version !== entry.name ||
packageContent.descriptor.platform !== this.#platform
) {
continue
}
const archivePath = join(directory, 'package.gbagent')
@@ -1051,6 +1107,10 @@ export class AgentPackageManager {
architecture: AgentArchitecture,
catalogEntry?: AgentPackageCatalogEntry
): Promise<InstalledRecord> {
if (
installed.verified.descriptor.platform !== this.#platform ||
installed.verified.descriptor.architecture !== architecture
) throw new Error('Agent package does not match the selected platform and architecture')
const destination = join(
this.#architectureRoot(architecture),
installed.verified.descriptor.version
@@ -1318,7 +1378,7 @@ export class AgentPackageManager {
return null
}
try {
return selectLatestCompatibleEntry(
return this.#select(
this.#catalogState.catalog,
architecture,
this.#desktopVersion
@@ -1701,7 +1761,7 @@ export class AgentPackageManager {
await mkdir(this.#rootDirectory, { recursive: true })
const path = join(
this.#rootDirectory,
`.stage-linux-${architecture}-${randomUUID()}`
`.stage-${this.#platform}-${architecture}-${randomUUID()}`
)
await mkdir(path)
return path
@@ -1710,7 +1770,7 @@ export class AgentPackageManager {
async #cleanupInterruptedArtifacts(): Promise<void> {
await this.#removeOwnedTemporaryDirectories(
this.#rootDirectory,
/^\.stage-linux-(?:x64|arm64|import)-[0-9a-f-]{36}$/u
new RegExp(`^\\.stage-${this.#platform}-(?:x64|arm64|import)-[0-9a-f-]{36}$`, 'u')
)
await Promise.all(
agentArchitectureSchema.options.map((architecture) =>
@@ -1756,7 +1816,7 @@ export class AgentPackageManager {
#architectureRoot(
architecture: AgentArchitecture
): string {
return join(this.#rootDirectory, `linux-${architecture}`)
return join(this.#rootDirectory, `${this.#platform}-${architecture}`)
}
#loadTrustedRegistry(): Promise<AgentReleaseKeyRegistry> {
@@ -1825,10 +1885,10 @@ export class AgentPackageManager {
observer:
| ((progress: AgentPackageDownloadProgress) => void)
| undefined,
progress: AgentPackageDownloadProgress
progress: Omit<AgentPackageDownloadProgress, 'platform'>
): void {
try {
observer?.(agentPackageDownloadProgressSchema.parse(progress))
observer?.(agentPackageDownloadProgressSchema.parse({ ...progress, platform: this.#platform }))
} catch {
// Progress observers cannot alter the package operation.
}
@@ -1838,11 +1898,13 @@ export class AgentPackageManager {
export function selectLatestCompatibleEntry(
catalog: AgentPackageCatalog,
architecture: AgentArchitecture,
desktopVersion: string
desktopVersion: string,
platform: AgentPlatform = 'linux'
): AgentPackageCatalogEntry {
const entry = catalog.entries
.filter(
(candidate) =>
candidate.platform === platform &&
candidate.architecture === architecture &&
compareSemanticVersions(
desktopVersion,
@@ -188,6 +188,7 @@ export async function verifyExtractedAgentPackage(options: {
}
)
if (
agentBundle.manifest.platform !== descriptor.platform ||
agentBundle.manifest.agentVersion !== descriptor.version ||
agentBundle.manifest.protocol.major !==
descriptor.agentProtocol.major ||
@@ -231,6 +232,7 @@ export async function verifyExtractedAgentPackage(options: {
}
)
if (
runtimeBundle.manifest.platform !== descriptor.platform ||
runtimeBundle.manifest.runtimeVersion !==
descriptor.remoteRuntime.version ||
runtimeBundle.manifest.bundleDigest !==
@@ -63,6 +63,7 @@ const windowsReservedNamePattern =
type JsonRecord = Record<string, unknown>
type Architecture = 'x64' | 'arm64'
type Platform = 'linux' | 'darwin'
type Protocol = { major: number; minor: number }
type FileRecord = {
path: string
@@ -94,7 +95,7 @@ export type PackageInstallerAgentIdentity = {
agentVersion: string
manifestSha256: string
binaryDigest: string
platform: 'linux'
platform: Platform
architecture: Architecture
protocol: Protocol
supervisor: 'detached-on-demand'
@@ -107,7 +108,7 @@ export type PackageInstallerRuntimeIdentity = {
manifestDigest: string
runtimeAdapterDigest: string
acpCapabilitiesDigest: string
platform: 'linux'
platform: Platform
architecture: Architecture
protocol: Protocol
}
@@ -818,7 +819,7 @@ function assertOuterDescriptor(
descriptor.component !== 'agent' ||
!versionPattern.test(String(descriptor.version)) ||
!versionPattern.test(String(descriptor.minimumDesktopVersion)) ||
descriptor.platform !== 'linux' ||
!isSupportedTarget(descriptor.platform, architecture) ||
!['x64', 'arm64'].includes(String(architecture)) ||
typeof descriptor.signingKeyId !== 'string' ||
!digestPattern.test(String(descriptor.contentDigest)) ||
@@ -920,7 +921,7 @@ function assertAgentManifest(
manifest.formatVersion !== 1 ||
manifest.product !== 'GoodBuddy' ||
!versionPattern.test(String(manifest.agentVersion)) ||
manifest.platform !== 'linux' ||
!isSupportedTarget(manifest.platform, manifest.arch) ||
!['x64', 'arm64'].includes(String(manifest.arch)) ||
!isRecord(manifest.entrypoint) ||
!Array.isArray(manifest.licenses)
@@ -944,6 +945,7 @@ function assertAgentManifest(
lock.formatVersion !== 1 ||
manifest.agentVersion !== lock.agentVersion ||
manifest.arch !== descriptor.architecture ||
manifest.platform !== descriptor.platform ||
manifest.agentVersion !== descriptor.version ||
canonicalJson(agentProtocol) !== canonicalJson(descriptor.agentProtocol) ||
canonicalJson(agentProtocol) !== canonicalJson(lock.protocol)
@@ -1002,7 +1004,7 @@ function assertAgentManifest(
}
const architecture = manifest.arch as Architecture
const koffiPackageRoot = 'lib/node_modules/koffi'
const koffiNativePackage = `@koromix/koffi-linux-${architecture}`
const koffiNativePackage = `@koromix/koffi-${manifest.platform}-${architecture}`
const koffiNativeRoot =
`lib/node_modules/${koffiNativePackage}`
for (const required of [
@@ -1017,10 +1019,7 @@ function assertAgentManifest(
throw new Error(`Agent Koffi payload is missing: ${required}`)
}
}
for (const native of [
`lib/node_modules/@koromix/koffi-linux-${manifest.arch}/linux_${manifest.arch}/koffi.node`,
`lib/node_modules/@koromix/koffi-linux-${manifest.arch}/musl_${manifest.arch}/koffi.node`
]) {
for (const native of nativeKoffiPaths(manifest.platform as Platform, architecture)) {
if (!declared.has(native)) {
throw new Error(`Agent Koffi payload is missing: ${native}`)
}
@@ -1091,11 +1090,12 @@ function assertRuntimeManifest(
const runtime = isRecord(lock.runtimes) && isRecord(lock.runtimes.opencode)
? lock.runtimes.opencode
: undefined
const targetKey = descriptor.platform === 'darwin' ? 'darwin-arm64' : String(descriptor.architecture)
const target =
runtime !== undefined &&
isRecord(runtime.targets) &&
isRecord(runtime.targets[String(descriptor.architecture)])
? runtime.targets[String(descriptor.architecture)]
isRecord(runtime.targets[targetKey])
? runtime.targets[targetKey]
: undefined
const remote = descriptor.remoteRuntime as JsonRecord
if (
@@ -1103,7 +1103,7 @@ function assertRuntimeManifest(
manifest.product !== 'GoodBuddy' ||
manifest.runtimeId !== 'opencode' ||
manifest.provider !== 'opencode' ||
manifest.platform !== 'linux' ||
manifest.platform !== descriptor.platform ||
manifest.architecture !== descriptor.architecture ||
!versionPattern.test(String(manifest.runtimeVersion)) ||
!digestPattern.test(String(manifest.bundleDigest)) ||
@@ -1255,7 +1255,26 @@ function assertRuntimeManifest(
}
}
function elfArchitecture(bytes: Buffer): Architecture | undefined {
function isSupportedTarget(platform: unknown, architecture: unknown): boolean {
return (platform === 'linux' && (architecture === 'x64' || architecture === 'arm64')) ||
(platform === 'darwin' && architecture === 'arm64')
}
function nativeKoffiPaths(platform: Platform, architecture: Architecture): string[] {
const root = `lib/node_modules/@koromix/koffi-${platform}-${architecture}`
return platform === 'darwin'
? [`${root}/darwin_${architecture}/koffi.node`]
: [`${root}/linux_${architecture}/koffi.node`, `${root}/musl_${architecture}/koffi.node`]
}
function elfArchitecture(bytes: Buffer, platform: Platform): Architecture | undefined {
if (platform === 'darwin') {
if (bytes.length < 8) return undefined
const cpu = bytes.readUInt32LE(0) === 0xfeedfacf
? bytes.readUInt32LE(4)
: bytes.readUInt32BE(0) === 0xfeedfacf ? bytes.readUInt32BE(4) : 0
return cpu === 0x0100000c ? 'arm64' : undefined
}
if (
bytes.length < 20 ||
!bytes.subarray(0, 4).equals(Buffer.from([0x7f, 0x45, 0x4c, 0x46]))
@@ -1273,32 +1292,16 @@ function elfArchitecture(bytes: Buffer): Architecture | undefined {
function assertExtractedArchitectures(
preparedRoot: string,
architecture: Architecture
architecture: Architecture,
platform: Platform
): void {
for (const path of [
join(preparedRoot, 'agent', 'node'),
join(
preparedRoot,
'agent',
'lib',
'node_modules',
`@koromix/koffi-linux-${architecture}`,
`linux_${architecture}`,
'koffi.node'
),
join(
preparedRoot,
'agent',
'lib',
'node_modules',
`@koromix/koffi-linux-${architecture}`,
`musl_${architecture}`,
'koffi.node'
),
...nativeKoffiPaths(platform, architecture).map(path => join(preparedRoot, 'agent', path)),
join(preparedRoot, 'runtime', 'bin', 'opencode')
]) {
if (
elfArchitecture(readFileHeader(path, 64)) !== architecture
elfArchitecture(readFileHeader(path, 64), platform) !== architecture
) {
throw new Error(`Installed executable architecture mismatch: ${basename(path)}`)
}
@@ -1518,7 +1521,7 @@ function verifyArchive(
agentVersion: String(agentManifest.agentVersion),
manifestSha256: agentManifestSha256,
binaryDigest: `sha256:${agentManifestSha256}`,
platform: 'linux',
platform: descriptor.platform as Platform,
architecture,
protocol: protocol(agentManifest.protocol, 'Agent protocol'),
supervisor: 'detached-on-demand'
@@ -1530,7 +1533,7 @@ function verifyArchive(
manifestDigest: runtime.manifestDigest,
runtimeAdapterDigest: String(runtime.manifest.adapterDigest),
acpCapabilitiesDigest: String(runtime.manifest.acpCapabilitiesDigest),
platform: 'linux',
platform: descriptor.platform as Platform,
architecture,
protocol: protocol(runtime.manifest.protocol, 'Runtime protocol')
}
@@ -1766,7 +1769,7 @@ function extractPayload(
} finally {
closeSync(handle)
}
assertExtractedArchitectures(temporary, verified.agent.architecture)
assertExtractedArchitectures(temporary, verified.agent.architecture, verified.agent.platform)
chmodSync(temporary, 0o700)
renameSync(temporary, destinationRoot)
} catch (error) {
@@ -2127,7 +2130,7 @@ function readPreparedState(path: string): PreparedState {
!sha256Pattern.test(String(agent.manifestSha256)) ||
agent.installationId !== `agent-${String(agent.manifestSha256)}` ||
agent.binaryDigest !== `sha256:${String(agent.manifestSha256)}` ||
agent.platform !== 'linux' ||
!isSupportedTarget(agent.platform, agent.architecture) ||
!['x64', 'arm64'].includes(String(agent.architecture)) ||
agent.supervisor !== 'detached-on-demand' ||
runtime.runtimeId !== 'opencode' ||
@@ -2136,7 +2139,7 @@ function readPreparedState(path: string): PreparedState {
!digestPattern.test(String(runtime.manifestDigest)) ||
!digestPattern.test(String(runtime.runtimeAdapterDigest)) ||
!digestPattern.test(String(runtime.acpCapabilitiesDigest)) ||
runtime.platform !== 'linux' ||
runtime.platform !== agent.platform ||
runtime.architecture !== agent.architecture
) {
throw new Error('Prepared package state identity is invalid')
@@ -2159,7 +2162,7 @@ function readPreparedState(path: string): PreparedState {
agentVersion: String(agent.agentVersion),
manifestSha256: String(agent.manifestSha256),
binaryDigest: String(agent.binaryDigest),
platform: 'linux',
platform: agent.platform as Platform,
architecture: agent.architecture as Architecture,
protocol: agentProtocol,
supervisor: 'detached-on-demand'
@@ -2171,7 +2174,7 @@ function readPreparedState(path: string): PreparedState {
manifestDigest: String(runtime.manifestDigest),
runtimeAdapterDigest: String(runtime.runtimeAdapterDigest),
acpCapabilitiesDigest: String(runtime.acpCapabilitiesDigest),
platform: 'linux',
platform: agent.platform as Platform,
architecture: runtime.architecture as Architecture,
protocol: runtimeProtocol
}
@@ -2322,7 +2325,7 @@ function assertPreparedIdentity(
agentVersion: String(agentManifest.agentVersion),
manifestSha256: agentManifestSha256,
binaryDigest: `sha256:${agentManifestSha256}`,
platform: 'linux',
platform: agentManifest.platform as Platform,
architecture,
protocol: protocol(agentManifest.protocol, 'Agent protocol'),
supervisor: 'detached-on-demand'
@@ -2336,7 +2339,7 @@ function assertPreparedIdentity(
acpCapabilitiesDigest: String(
runtime.manifest.acpCapabilitiesDigest
),
platform: 'linux',
platform: agentManifest.platform as Platform,
architecture,
protocol: protocol(
runtime.manifest.protocol,
@@ -48,7 +48,7 @@ type ManagedRemoteRuntimeIdentity = {
bundleDigest: string
runtimeAdapterDigest: string
acpCapabilitiesDigest: string
platform: 'linux'
platform: 'linux' | 'darwin'
architecture: 'x64' | 'arm64'
}
@@ -648,7 +648,7 @@ function runtimeIdentityFromCapabilities(
): ManagedRemoteRuntimeIdentity {
if (
installation.runtimeId !== 'opencode' ||
installation.platform !== 'linux'
(installation.platform !== 'linux' && !(installation.platform === 'darwin' && installation.architecture === 'arm64'))
) {
throw new Error(
'Remote Agent does not advertise the current Runtime'
@@ -660,7 +660,7 @@ function runtimeIdentityFromCapabilities(
bundleDigest: installation.bundleDigest,
runtimeAdapterDigest: installation.runtimeAdapterDigest,
acpCapabilitiesDigest: installation.acpCapabilitiesDigest,
platform: 'linux',
platform: installation.platform,
architecture: installation.architecture
}
assertRuntimeAdvertised(runtime, capabilities)
@@ -155,6 +155,7 @@ function harness(options: {
installationId: agentInstallationId,
binaryDigest: status.binaryDigest,
version: status.agentVersion,
platform: 'linux',
architecture,
protocolMajor: 1
},
@@ -165,7 +165,7 @@ function assertInstallationIdentity(
): void {
if (
installation.runtimeId !== 'opencode' ||
installation.platform !== 'linux' ||
installation.platform !== input.agent.platform ||
installation.architecture !== input.agent.architecture
) {
throw new Error(
@@ -64,7 +64,7 @@ export type RemoteAgentInstallationIdentity = {
major: number
minor: number
}
platform: 'linux'
platform: 'linux' | 'darwin'
architecture: 'x64' | 'arm64'
supervisor: 'detached-on-demand'
requiredCapabilities?: ReadonlyArray<{
@@ -1145,7 +1145,7 @@ function validateInstallation(
input.protocol ?? AGENT_PROTOCOL_VERSION
)
if (
input.platform !== 'linux' ||
(input.platform !== 'linux' && !(input.platform === 'darwin' && input.architecture === 'arm64')) ||
!['x64', 'arm64'].includes(input.architecture) ||
input.supervisor !== 'detached-on-demand'
) {
@@ -164,7 +164,8 @@ export class RemoteEnvironmentPreparer implements Preparer {
await this.#acquireGoodBuddyArchive(
probe.architecture,
emit,
signal
signal,
probe.platform
)
candidate = archiveLease.candidate
method = 'goodbuddy-transfer'
@@ -173,7 +174,7 @@ export class RemoteEnvironmentPreparer implements Preparer {
candidate =
await this.#agentPackageManager.getRemoteInstallCandidate(
probe.architecture,
{ signal }
{ signal, platform: probe.platform }
)
} catch (error) {
if (requestedMethod === 'remote-download') {
@@ -183,14 +184,15 @@ export class RemoteEnvironmentPreparer implements Preparer {
await this.#acquireGoodBuddyArchive(
probe.architecture,
emit,
signal
signal,
probe.platform
)
candidate = archiveLease.candidate
method = 'goodbuddy-transfer'
}
}
signal.throwIfAborted()
assertCandidate(candidate, probe.architecture)
assertCandidate(candidate, probe.architecture, probe.platform)
await assertTargetCurrent(this.#resolver, target, signal)
operationId = randomUUID()
@@ -503,12 +505,14 @@ export class RemoteEnvironmentPreparer implements Preparer {
method: RemoteEnvironmentPreparationMethod,
phase: RemoteEnvironmentUpdateProgress['phase']
) => void,
signal: AbortSignal
signal: AbortSignal,
platform: 'linux' | 'darwin'
): Promise<AgentPackageArchiveLease> {
return this.#agentPackageManager.acquireGoodBuddyInstallArchive(
architecture,
{
signal,
platform,
onProgress: (progress) => {
emit(
'goodbuddy-transfer',
@@ -674,10 +678,11 @@ function assertSameLeaseIdentity(
function assertCandidate(
candidate: VerifiedRemoteAgentInstallCandidate,
architecture: 'x64' | 'arm64'
architecture: 'x64' | 'arm64',
platform: 'linux' | 'darwin'
): void {
if (
candidate.platform !== 'linux' ||
candidate.platform !== platform ||
candidate.architecture !== architecture
) {
throw new Error('签名 Agent 安装候选与 Host 架构不匹配')
@@ -59,6 +59,7 @@ export type RemoteProjectRuntimeValidationInput = Readonly<{
installationId: AgentInstallationIdentity['installationId']
binaryDigest: string
version: string
platform: 'linux' | 'darwin'
architecture: 'x64' | 'arm64'
protocolMajor: number
}>
@@ -308,6 +309,7 @@ export class RemoteProjectSaveService {
installationId: installation.installationId,
binaryDigest: installation.binaryDigest,
version: installation.agentVersion,
platform: installation.platform,
architecture: installation.architecture,
protocolMajor: installation.protocol.major
},
@@ -484,7 +486,7 @@ function assertInstallation(
installation.installationId
) ||
!sha256DigestSchema.safeParse(installation.binaryDigest).success ||
installation.platform !== 'linux' ||
(installation.platform !== 'linux' && !(installation.platform === 'darwin' && installation.architecture === 'arm64')) ||
!['x64', 'arm64'].includes(installation.architecture) ||
installation.supervisor !== 'detached-on-demand'
) {
@@ -36,7 +36,7 @@ export type RemoteRuntimeInstallationIdentity = {
manifestDigest: string
runtimeAdapterDigest: string
acpCapabilitiesDigest: string
platform: 'linux'
platform: 'linux' | 'darwin'
architecture: AgentArchitecture
}
@@ -188,7 +188,7 @@ export class RemoteRuntimeInstallationManager {
)
}
if (
probe.platform !== 'linux' ||
(probe.platform !== 'linux' && !(probe.platform === 'darwin' && probe.architecture === 'arm64')) ||
(
probe.architecture !== 'x64' &&
probe.architecture !== 'arm64'
@@ -279,7 +279,7 @@ export class RemoteRuntimeInstallationManager {
runtimeAdapterDigest,
acpCapabilitiesDigest:
current.acpCapabilitiesDigest,
platform: 'linux',
platform: probe.platform,
architecture: current.architecture
}
} catch (error) {
@@ -275,7 +275,7 @@ async function validateVerifiedBundle(
verified.bundleDirectory !== bundleDirectory ||
manifest.runtimeId !== 'opencode' ||
manifest.provider !== 'opencode' ||
manifest.platform !== 'linux' ||
(manifest.platform !== 'linux' && !(manifest.platform === 'darwin' && manifest.architecture === 'arm64')) ||
manifest.architecture !== architecture
) {
throw new Error(
+2 -1
View File
@@ -214,7 +214,8 @@ describe('fixed Agent SSH commands', () => {
const cases: Array<
[Partial<Record<string, string>>, string]
> = [
[{ os: 'Darwin' }, 'non-linux'],
[{ os: 'Darwin' }, 'unsupported-architecture'],
[{ os: 'FreeBSD' }, 'unsupported-platform'],
[{ arch: 'riscv64' }, 'unsupported-architecture'],
[{ home: 'unknown' }, 'home-directory-unavailable'],
[{ uid: 'unknown' }, 'uid-unavailable'],
+7 -7
View File
@@ -129,17 +129,17 @@ export function parseAgentBootstrapProbeOutput(
}
const os = values.get('os')
if (os !== 'Linux') {
return incompatible('non-linux')
if (os !== 'Linux' && os !== 'Darwin') {
return incompatible('unsupported-platform')
}
const rawArchitecture = values.get('arch')
const architecture =
rawArchitecture === 'x86_64'
? 'x64'
: rawArchitecture === 'aarch64'
: rawArchitecture === 'aarch64' || rawArchitecture === 'arm64'
? 'arm64'
: undefined
if (!architecture) {
if (!architecture || (os === 'Darwin' && architecture !== 'arm64')) {
return incompatible('unsupported-architecture')
}
@@ -169,17 +169,17 @@ export function parseAgentBootstrapProbeOutput(
if (procfs !== 'ready' && procfs !== 'unavailable') {
throw new Error('Agent 启动探针返回了无效结果')
}
if (procfs === 'unavailable') {
if (procfs === 'unavailable' && os === 'Linux') {
return incompatible('procfs-unavailable')
}
return agentBootstrapProbeResultSchema.parse({
ready: true,
platform: 'linux',
platform: os === 'Darwin' ? 'darwin' : 'linux',
architecture,
canonicalHomeDirectory: home,
uid,
shell,
procfs: 'ready'
procfs: os === 'Darwin' ? 'not-applicable' : 'ready'
})
}
+2 -2
View File
@@ -83,7 +83,7 @@ export type SshHostRemoteEnvironmentInspectorOptions = {
remoteRuntimeLockPath: string
loadRemoteEnvironmentCatalog?: (
architecture: 'x64' | 'arm64',
options: { signal?: AbortSignal }
options: { signal?: AbortSignal; platform?: 'linux' | 'darwin' }
) => Promise<RemoteEnvironmentCatalog>
now?: () => Date
}
@@ -155,7 +155,7 @@ export class SshHostRemoteEnvironmentInspector {
await Promise.all([
this.#loadRemoteEnvironmentCatalog(
probe.architecture,
{ signal }
{ signal, platform: probe.platform }
),
readOptionalRegistry(
sftp,
@@ -503,7 +503,7 @@ describe("fixed SSH remote package bootstrap", () => {
'--archive-sha256-verified true',
);
expect(SSH_REMOTE_PACKAGE_BOOTSTRAP_SCRIPT).toContain(
'actual_sha256=$(sha256sum "$archive"',
'actual_sha256=$(hash_sha256 "$archive"',
);
});
+17 -9
View File
@@ -127,7 +127,7 @@ export type SshRemotePackageAgentIdentity = {
agentVersion: string;
manifestSha256: string;
binaryDigest: string;
platform: "linux";
platform: "linux" | "darwin";
architecture: "x64" | "arm64";
protocol: SshRemotePackageProtocol;
supervisor: "detached-on-demand";
@@ -140,7 +140,7 @@ export type SshRemotePackageRuntimeIdentity = {
manifestDigest: string;
runtimeAdapterDigest: string;
acpCapabilitiesDigest: string;
platform: "linux";
platform: "linux" | "darwin";
architecture: "x64" | "arm64";
protocol: SshRemotePackageProtocol;
};
@@ -614,9 +614,17 @@ if [ "$action" = prepare-uploaded ]; then
run_prepare
fi
command -v curl >/dev/null 2>&1 || stop unavailable missing-curl
command -v sha256sum >/dev/null 2>&1 || stop unavailable missing-sha256sum
hash_sha256() {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$@"
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 "$@"
else
return 1
fi
}
command -v unzip >/dev/null 2>&1 || stop unavailable missing-unzip
printf test | sha256sum >/dev/null 2>&1 || stop unavailable missing-sha256sum
printf test | hash_sha256 >/dev/null 2>&1 || stop unavailable missing-sha256sum
unzip -v >/dev/null 2>&1 || stop unavailable missing-unzip
if ! mkdir -p -- "$staging_root"; then stop unavailable managed-path-unavailable; fi
if [ -L "$goodbuddy_root" ] || [ -L "$managed_root" ] ||
@@ -708,7 +716,7 @@ set -- $actual_size
actual_size=${SHELL_FIRST_POSITIONAL_OR_EMPTY}
[ "$actual_size" = "$expected_size" ] || stop failed size-mismatch
emit_progress verifying
actual_sha256=$(sha256sum "$archive" 2>/dev/null) || stop failed sha256-mismatch
actual_sha256=$(hash_sha256 "$archive" 2>/dev/null) || stop failed sha256-mismatch
set -- $actual_sha256
actual_sha256=${SHELL_FIRST_POSITIONAL_OR_EMPTY}
[ "$actual_sha256" = "$expected_sha256" ] || stop failed sha256-mismatch
@@ -973,7 +981,7 @@ function parsePackageIdentity(
agent.installationId !== `agent-${agent.manifestSha256}` ||
agent.binaryDigest !== `sha256:${agent.manifestSha256}` ||
!isVersion(agent.agentVersion) ||
agent.platform !== "linux" ||
(agent.platform !== "linux" && !(agent.platform === "darwin" && architecture === "arm64")) ||
(architecture !== "x64" && architecture !== "arm64") ||
!agentProtocol ||
agent.supervisor !== "detached-on-demand" ||
@@ -987,7 +995,7 @@ function parsePackageIdentity(
!DIGEST_PATTERN.test(runtime.runtimeAdapterDigest) ||
typeof runtime.acpCapabilitiesDigest !== "string" ||
!DIGEST_PATTERN.test(runtime.acpCapabilitiesDigest) ||
runtime.platform !== "linux" ||
runtime.platform !== agent.platform ||
runtime.architecture !== architecture ||
!runtimeProtocol
) {
@@ -1003,7 +1011,7 @@ function parsePackageIdentity(
agentVersion: agent.agentVersion,
manifestSha256: agent.manifestSha256,
binaryDigest: agent.binaryDigest,
platform: "linux",
platform: agent.platform as "linux" | "darwin",
architecture,
protocol: agentProtocol,
supervisor: "detached-on-demand",
@@ -1015,7 +1023,7 @@ function parsePackageIdentity(
manifestDigest: runtime.manifestDigest,
runtimeAdapterDigest: runtime.runtimeAdapterDigest,
acpCapabilitiesDigest: runtime.acpCapabilitiesDigest,
platform: "linux",
platform: agent.platform as "linux" | "darwin",
architecture,
protocol: runtimeProtocol,
},