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:
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
import { agentPlatformSchema } from './agent-target'
|
||||
|
||||
const versionPattern =
|
||||
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+((?:[0-9a-zA-Z-]+)(?:\.[0-9a-zA-Z-]+)*))?$/u
|
||||
@@ -81,7 +82,7 @@ export const agentBundleManifestSchema = z
|
||||
formatVersion: z.literal(1),
|
||||
product: z.literal('GoodBuddy'),
|
||||
agentVersion: componentVersionSchema,
|
||||
platform: z.literal('linux'),
|
||||
platform: agentPlatformSchema,
|
||||
arch: agentArchitectureSchema,
|
||||
protocol: agentProtocolVersionSchema,
|
||||
signingKeyId: z.string().regex(keyIdPattern),
|
||||
@@ -248,7 +249,8 @@ export const agentRuntimeLockSchema = z
|
||||
targets: z
|
||||
.object({
|
||||
'linux-x64': lockedNodeTargetSchema,
|
||||
'linux-arm64': lockedNodeTargetSchema
|
||||
'linux-arm64': lockedNodeTargetSchema,
|
||||
'darwin-arm64': lockedNodeTargetSchema.optional()
|
||||
})
|
||||
.strict()
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
agentPackageArchiveName,
|
||||
agentPackageCatalogEntrySchema,
|
||||
agentPackageCatalogSchema,
|
||||
agentPackageInventoryRequestSchema,
|
||||
agentPackageInventorySchema,
|
||||
isSafeAgentPackagePath
|
||||
@@ -48,6 +49,27 @@ function catalogEntry() {
|
||||
}
|
||||
|
||||
describe('Agent package contracts', () => {
|
||||
it('accepts Linux and macOS arm64 independently in one signed catalog', () => {
|
||||
const linux = {
|
||||
...catalogEntry(),
|
||||
architecture: 'arm64',
|
||||
archive: agentPackageArchiveName('0.11.2', 'arm64', 'linux')
|
||||
}
|
||||
const mac = {
|
||||
...linux,
|
||||
platform: 'darwin',
|
||||
archive: agentPackageArchiveName('0.11.2', 'arm64', 'darwin')
|
||||
}
|
||||
const catalog = agentPackageCatalogSchema.parse({
|
||||
formatVersion: 1, product: 'GoodBuddy', component: 'agent',
|
||||
signingKeyId: 'test', generatedAt: '2026-09-06T00:00:00.000Z',
|
||||
entries: [catalogEntry(), linux, mac]
|
||||
})
|
||||
expect(catalog.entries).toHaveLength(3)
|
||||
expect(() => agentPackageCatalogSchema.parse({
|
||||
...catalog, entries: [...catalog.entries, mac]
|
||||
})).toThrow('duplicate')
|
||||
})
|
||||
it('binds each catalog archive name to its signed identity', () => {
|
||||
expect(agentPackageCatalogEntrySchema.parse(catalogEntry()))
|
||||
.toMatchObject({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
import { agentPlatformSchema, agentTargetKey, type AgentPlatform } from './agent-target'
|
||||
import {
|
||||
agentArchitectureSchema,
|
||||
agentProtocolVersionSchema
|
||||
@@ -9,9 +10,10 @@ export const AGENT_PACKAGE_FORMAT_VERSION = 1
|
||||
|
||||
export function agentPackageArchiveName(
|
||||
version: string,
|
||||
architecture: 'x64' | 'arm64'
|
||||
architecture: 'x64' | 'arm64',
|
||||
platform: AgentPlatform = 'linux'
|
||||
): string {
|
||||
return `goodbuddy-agent-${version}-linux-${architecture}.gbagent`
|
||||
return `goodbuddy-agent-${version}-${agentTargetKey({ platform, architecture })}.gbagent`
|
||||
}
|
||||
|
||||
const semanticVersionSchema = z
|
||||
@@ -31,7 +33,7 @@ const safeArchiveNameSchema = z
|
||||
.min(1)
|
||||
.max(255)
|
||||
.regex(
|
||||
/^goodbuddy-agent-(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?-linux-(?:x64|arm64)\.gbagent$/u
|
||||
/^goodbuddy-agent-(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?-(?:linux-(?:x64|arm64)|darwin-arm64)\.gbagent$/u
|
||||
)
|
||||
|
||||
const windowsReservedNamePattern =
|
||||
@@ -86,7 +88,7 @@ const agentPackageDescriptorObjectSchema = z
|
||||
component: z.literal('agent'),
|
||||
version: semanticVersionSchema,
|
||||
minimumDesktopVersion: semanticVersionSchema,
|
||||
platform: z.literal('linux'),
|
||||
platform: agentPlatformSchema,
|
||||
architecture: agentArchitectureSchema,
|
||||
signingKeyId: signingKeyIdSchema,
|
||||
agentProtocol: agentProtocolVersionSchema,
|
||||
@@ -152,7 +154,7 @@ export const agentPackageCatalogEntrySchema =
|
||||
.superRefine((entry, context) => {
|
||||
if (
|
||||
entry.archive !==
|
||||
agentPackageArchiveName(entry.version, entry.architecture)
|
||||
agentPackageArchiveName(entry.version, entry.architecture, entry.platform)
|
||||
) {
|
||||
context.addIssue({
|
||||
code: 'custom',
|
||||
@@ -182,7 +184,7 @@ export const agentPackageCatalogSchema = z
|
||||
.strict()
|
||||
.superRefine((catalog, context) => {
|
||||
const identities = catalog.entries.map(
|
||||
(entry) => `${entry.version}:${entry.architecture}`
|
||||
(entry) => `${entry.version}:${entry.platform}:${entry.architecture}`
|
||||
)
|
||||
if (new Set(identities).size !== identities.length) {
|
||||
context.addIssue({
|
||||
@@ -205,7 +207,7 @@ export const agentPackageStateSchema = z.enum([
|
||||
|
||||
export const agentPackageInventoryEntrySchema = z
|
||||
.object({
|
||||
platform: z.literal('linux'),
|
||||
platform: agentPlatformSchema,
|
||||
architecture: agentArchitectureSchema,
|
||||
state: agentPackageStateSchema,
|
||||
version: semanticVersionSchema.nullable(),
|
||||
@@ -247,12 +249,12 @@ export const agentPackageInventorySchema = z
|
||||
catalog: agentPackageCatalogStatusSchema,
|
||||
entries: z
|
||||
.array(agentPackageInventoryEntrySchema)
|
||||
.length(agentArchitectureSchema.options.length)
|
||||
.min(1).max(3)
|
||||
})
|
||||
.strict()
|
||||
.superRefine((inventory, context) => {
|
||||
const architectures = inventory.entries.map(
|
||||
(entry) => entry.architecture
|
||||
(entry) => `${entry.platform}-${entry.architecture}`
|
||||
)
|
||||
if (new Set(architectures).size !== architectures.length) {
|
||||
context.addIssue({
|
||||
@@ -276,7 +278,8 @@ export const agentPackageInventoryRequestSchema = z
|
||||
|
||||
export const agentPackageArchitectureRequestSchema = z
|
||||
.object({
|
||||
architecture: agentArchitectureSchema
|
||||
architecture: agentArchitectureSchema,
|
||||
platform: agentPlatformSchema.default('linux')
|
||||
})
|
||||
.strict()
|
||||
|
||||
@@ -287,6 +290,7 @@ export type AgentPackageArchitectureRequest = z.infer<
|
||||
export const agentPackageDownloadProgressSchema = z
|
||||
.object({
|
||||
architecture: agentArchitectureSchema,
|
||||
platform: agentPlatformSchema.default('linux'),
|
||||
phase: z.enum([
|
||||
'catalog',
|
||||
'downloading',
|
||||
|
||||
@@ -190,7 +190,7 @@ export const daemonStatusSchema = z
|
||||
label: 'Agent version'
|
||||
}),
|
||||
protocol: protocolVersionSchema,
|
||||
platform: z.literal('linux'),
|
||||
platform: z.enum(['linux', 'darwin']),
|
||||
architecture: z.enum(['x64', 'arm64']),
|
||||
supervisor: z.literal('detached-on-demand'),
|
||||
remoteUserIdentity: agentIdentifierSchema,
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const agentPlatformSchema = z.enum(['linux', 'darwin'])
|
||||
export type AgentPlatform = z.infer<typeof agentPlatformSchema>
|
||||
|
||||
export const AGENT_TARGETS = [
|
||||
{ platform: 'linux', architecture: 'x64' },
|
||||
{ platform: 'linux', architecture: 'arm64' },
|
||||
{ platform: 'darwin', architecture: 'arm64' }
|
||||
] as const
|
||||
|
||||
export type AgentTarget = (typeof AGENT_TARGETS)[number]
|
||||
export type AgentTargetKey = 'linux-x64' | 'linux-arm64' | 'darwin-arm64'
|
||||
|
||||
export function agentTargetKey(target: {
|
||||
platform: string
|
||||
architecture: string
|
||||
}): AgentTargetKey {
|
||||
if (!AGENT_TARGETS.some(entry =>
|
||||
entry.platform === target.platform && entry.architecture === target.architecture
|
||||
)) throw new Error(`Unsupported Agent target: ${target.platform}-${target.architecture}`)
|
||||
return `${target.platform}-${target.architecture}` as AgentTargetKey
|
||||
}
|
||||
|
||||
export function currentAgentPlatform(): AgentPlatform {
|
||||
const platform = agentPlatformSchema.parse(process.platform)
|
||||
agentTargetKey({ platform, architecture: process.arch })
|
||||
return platform
|
||||
}
|
||||
@@ -1660,11 +1660,13 @@ export type DesktopApi = {
|
||||
refresh?: boolean
|
||||
) => Promise<AgentPackageInventory>
|
||||
downloadAgentPackage: (
|
||||
architecture: AgentArchitecture
|
||||
architecture: AgentArchitecture,
|
||||
platform?: 'linux' | 'darwin'
|
||||
) => Promise<AgentPackageInventory>
|
||||
importAgentPackage: () => Promise<AgentPackageInventory | undefined>
|
||||
exportAgentPackage: (
|
||||
architecture: AgentArchitecture
|
||||
architecture: AgentArchitecture,
|
||||
platform?: 'linux' | 'darwin'
|
||||
) => Promise<void>
|
||||
onAgentPackageProgress: (
|
||||
listener: (progress: AgentPackageDownloadProgress) => void
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { AgentArchitecture } from '../agent-installation-contracts'
|
||||
import type { AgentPlatform } from '../agent-target'
|
||||
|
||||
export function binaryTargetArchitecture(
|
||||
bytes: Buffer,
|
||||
platform: AgentPlatform
|
||||
): AgentArchitecture | 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) : undefined
|
||||
return cpu === 0x0100000c ? 'arm64' : undefined
|
||||
}
|
||||
if (
|
||||
bytes.length < 20 || bytes[0] !== 0x7f ||
|
||||
bytes.toString('ascii', 1, 4) !== 'ELF' ||
|
||||
![1, 2].includes(bytes[5]!)
|
||||
) return undefined
|
||||
const machine = bytes[5] === 2 ? bytes.readUInt16BE(18) : bytes.readUInt16LE(18)
|
||||
return machine === 62 ? 'x64' : machine === 183 ? 'arm64' : undefined
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { binaryTargetArchitecture } from './binary-target'
|
||||
import type { AgentPlatform } from '../agent-target'
|
||||
import {
|
||||
createHash,
|
||||
createPublicKey,
|
||||
@@ -219,7 +221,8 @@ export async function verifyPublishedRuntimeBundle(
|
||||
await assertElfArchitecture(
|
||||
executablePath,
|
||||
options.architecture,
|
||||
'Runtime executable'
|
||||
'Runtime executable',
|
||||
manifest.platform
|
||||
)
|
||||
return {
|
||||
bundleDirectory,
|
||||
@@ -412,8 +415,11 @@ export function assertRuntimeManifestMatchesLock(
|
||||
architecture: AgentArchitecture
|
||||
): void {
|
||||
const expected = lock.runtimes.opencode
|
||||
const target = expected.targets[architecture]
|
||||
const target = manifest.platform === 'darwin'
|
||||
? expected.targets['darwin-arm64']
|
||||
: expected.targets[architecture]
|
||||
if (
|
||||
target === undefined ||
|
||||
manifest.runtimeId !== 'opencode' ||
|
||||
manifest.provider !== expected.provider ||
|
||||
manifest.runtimeVersion !== expected.version ||
|
||||
@@ -696,7 +702,8 @@ async function sha256File(filePath: string): Promise<string> {
|
||||
async function assertElfArchitecture(
|
||||
filePath: string,
|
||||
expected: AgentArchitecture,
|
||||
label: string
|
||||
label: string,
|
||||
platform: AgentPlatform
|
||||
): Promise<void> {
|
||||
const handle = await open(filePath, 'r')
|
||||
try {
|
||||
@@ -707,8 +714,8 @@ async function assertElfArchitecture(
|
||||
header.length,
|
||||
0
|
||||
)
|
||||
const actual = detectElfArchitecture(
|
||||
header.subarray(0, bytesRead)
|
||||
const actual = binaryTargetArchitecture(
|
||||
header.subarray(0, bytesRead), platform
|
||||
)
|
||||
if (actual !== expected) {
|
||||
throw new Error(
|
||||
@@ -718,26 +725,4 @@ async function assertElfArchitecture(
|
||||
} finally {
|
||||
await handle.close()
|
||||
}
|
||||
}
|
||||
|
||||
function detectElfArchitecture(
|
||||
header: Buffer
|
||||
): AgentArchitecture | undefined {
|
||||
if (
|
||||
header.length < 20 ||
|
||||
header[0] !== 0x7f ||
|
||||
header.toString('ascii', 1, 4) !== 'ELF' ||
|
||||
(header[5] !== 1 && header[5] !== 2)
|
||||
) {
|
||||
return undefined
|
||||
}
|
||||
const machine =
|
||||
header[5] === 2
|
||||
? header.readUInt16BE(18)
|
||||
: header.readUInt16LE(18)
|
||||
return machine === 62
|
||||
? 'x64'
|
||||
: machine === 183
|
||||
? 'arm64'
|
||||
: undefined
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ const remoteRuntimeManifestFields = {
|
||||
runtimeId: agentIdentifierSchema,
|
||||
runtimeVersion: agentBundleManifestSchema.shape.agentVersion,
|
||||
provider: remoteRuntimeProviderKindSchema,
|
||||
platform: z.literal('linux'),
|
||||
platform: z.enum(['linux', 'darwin']),
|
||||
architecture: agentArchitectureSchema,
|
||||
signingKeyId: agentReleaseKeySchema.shape.keyId,
|
||||
bundleDigest: sha256DigestSchema,
|
||||
@@ -252,7 +252,10 @@ export const remoteRuntimeLockSchema = z
|
||||
}),
|
||||
arm64: remoteRuntimeLockedTargetSchema.extend({
|
||||
package: z.literal('opencode-linux-arm64')
|
||||
})
|
||||
}),
|
||||
'darwin-arm64': remoteRuntimeLockedTargetSchema.extend({
|
||||
package: z.literal('opencode-darwin-arm64')
|
||||
}).optional()
|
||||
})
|
||||
.strict()
|
||||
})
|
||||
|
||||
@@ -404,6 +404,7 @@ export type RemoteEnvironmentUpdateProgress = z.infer<
|
||||
|
||||
export const agentBootstrapIncompatibleReasonSchema = z.enum([
|
||||
'non-linux',
|
||||
'unsupported-platform',
|
||||
'unsupported-architecture',
|
||||
'home-directory-unavailable',
|
||||
'uid-unavailable',
|
||||
@@ -562,12 +563,12 @@ export const agentBootstrapProbeResultSchema = z.discriminatedUnion(
|
||||
z
|
||||
.object({
|
||||
ready: z.literal(true),
|
||||
platform: z.literal('linux'),
|
||||
platform: z.enum(['linux', 'darwin']),
|
||||
architecture: z.enum(['x64', 'arm64']),
|
||||
canonicalHomeDirectory: canonicalRemotePathSchema,
|
||||
uid: z.number().int().min(0).max(4_294_967_294),
|
||||
shell: canonicalRemotePathSchema,
|
||||
procfs: z.literal('ready')
|
||||
procfs: z.enum(['ready', 'not-applicable'])
|
||||
})
|
||||
.strict(),
|
||||
z
|
||||
|
||||
Reference in New Issue
Block a user