feat: add independent managed SSH agent packages

Managed SSH previously tied remote Agent and Runtime artifacts to desktop
packaging and Host activation. Settings now manages verified Linux x64 and
arm64 .gbagent packages explicitly, with source-aligned download and update
plus offline import and export. Each package contains the signed Agent, pinned
Node, and compatible OpenCode Runtime, and project activation never downloads
one automatically.

Dedicated native CI and a protected release workflow publish deterministic,
signed cumulative catalogs to GitHub and Beijing OSS without replacing the
desktop Latest release. Desktop packaging is metadata-only, remains independent
of Agent artifacts and signing credentials, and Linux desktop releases add RPM
installers.

The managed SSH path also keeps model credentials in Main, enforces Ask as
read-only, verifies signed Agent and Runtime inputs, preserves ACP recovery, and
reports Host update cancellation and failures accurately.

Release note: 远程项目现可在“设置”中手动下载、更新或离线导入签名 Agent 包,桌面安装包与远程组件发布相互独立;Linux 桌面版同时新增 RPM 安装包。
This commit is contained in:
mesalogo
2026-08-25 18:28:29 +08:00
parent 88658aceaa
commit e5aebaa67d
101 changed files with 11543 additions and 2168 deletions
+111
View File
@@ -0,0 +1,111 @@
import { describe, expect, it } from 'vitest'
import {
agentPackageArchiveName,
agentPackageCatalogEntrySchema,
agentPackageInventoryRequestSchema,
agentPackageInventorySchema,
isSafeAgentPackagePath
} from './agent-package-contracts'
const digest = 'a'.repeat(64)
function catalogEntry() {
const version = '0.11.2-e2e.13'
const archive = agentPackageArchiveName(version, 'x64')
return {
format: 'goodbuddy-agent-package',
formatVersion: 1,
product: 'GoodBuddy',
component: 'agent',
version,
minimumDesktopVersion: '0.11.0',
platform: 'linux',
architecture: 'x64',
agentProtocol: { major: 2, minor: 0 },
remoteRuntime: {
runtimeId: 'opencode',
provider: 'opencode',
version: '1.18.9',
bundleDigest: `sha256:${digest}`,
protocol: { major: 1, minor: 0 }
},
archive,
size: 1,
sha256: digest,
downloads: {
github: {
url:
'https://github.com/mesalogo/goodbuddy/releases/download/' +
`agent-v${version}/${archive}`
},
mirror: {
url:
'https://goodbuddy.oss-cn-beijing.aliyuncs.com/' +
`agent-releases/v${version}/${archive}`
}
}
} as const
}
describe('Agent package contracts', () => {
it('binds each catalog archive name to its signed identity', () => {
expect(agentPackageCatalogEntrySchema.parse(catalogEntry()))
.toMatchObject({
version: '0.11.2-e2e.13',
architecture: 'x64'
})
expect(() =>
agentPackageCatalogEntrySchema.parse({
...catalogEntry(),
archive: 'goodbuddy-agent-9.9.9-linux-x64.gbagent'
})
).toThrow()
})
it('requires one local inventory entry per architecture', () => {
const entry = {
platform: 'linux',
state: 'not-downloaded',
version: null,
remoteRuntimeVersion: null,
agentProtocol: null
} as const
expect(
agentPackageInventorySchema.parse({
checkedAt: '2026-08-25T00:00:00.000Z',
entries: [
{ ...entry, architecture: 'x64' },
{ ...entry, architecture: 'arm64' }
]
}).entries
).toHaveLength(2)
expect(() =>
agentPackageInventorySchema.parse({
checkedAt: '2026-08-25T00:00:00.000Z',
entries: [
{ ...entry, architecture: 'x64' },
{ ...entry, architecture: 'x64' }
]
})
).toThrow()
})
it('accepts only a bounded refresh flag for inventory reads', () => {
expect(agentPackageInventoryRequestSchema.parse({})).toEqual({
refresh: false
})
expect(() =>
agentPackageInventoryRequestSchema.parse({
refresh: true,
path: '/private/package'
})
).toThrow()
})
it('rejects cross-platform device and drive-style archive paths', () => {
expect(isSafeAgentPackagePath('agent/manifest.json')).toBe(true)
expect(isSafeAgentPackagePath('C:/escape')).toBe(false)
expect(isSafeAgentPackagePath('runtime/NUL')).toBe(false)
expect(isSafeAgentPackagePath('agent/file.')).toBe(false)
})
})
+275
View File
@@ -0,0 +1,275 @@
import { z } from 'zod'
import {
agentArchitectureSchema,
agentProtocolVersionSchema
} from './agent-installation-contracts'
export const AGENT_PACKAGE_FORMAT = 'goodbuddy-agent-package'
export const AGENT_PACKAGE_FORMAT_VERSION = 1
export function agentPackageArchiveName(
version: string,
architecture: 'x64' | 'arm64'
): string {
return `goodbuddy-agent-${version}-linux-${architecture}.gbagent`
}
const semanticVersionSchema = z
.string()
.min(1)
.max(128)
.regex(
/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:(?:0|[1-9]\d*)|(?:\d*[A-Za-z-][0-9A-Za-z-]*))(?:\.(?:(?:0|[1-9]\d*)|(?:\d*[A-Za-z-][0-9A-Za-z-]*)))*)?$/u
)
const sha256Schema = z.string().regex(/^[a-f0-9]{64}$/u)
const sha256DigestSchema = z.string().regex(/^sha256:[a-f0-9]{64}$/u)
const signingKeyIdSchema = z
.string()
.regex(/^[a-z0-9][a-z0-9._-]{0,63}$/u)
const safeArchiveNameSchema = z
.string()
.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
)
const windowsReservedNamePattern =
/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu
export function isSafeAgentPackagePath(path: string): boolean {
return (
path.length > 0 &&
path.length <= 512 &&
!path.startsWith('/') &&
!path.endsWith('/') &&
!path.includes('\\') &&
path.split('/').every(
(part) =>
part.length > 0 &&
part !== '.' &&
part !== '..' &&
!part.endsWith('.') &&
!part.endsWith(' ') &&
!part.includes(':') &&
[...part].every(
(character) => character.charCodeAt(0) > 0x1f
) &&
!windowsReservedNamePattern.test(part)
)
)
}
const packageFilePathSchema = z
.string()
.min(1)
.max(512)
.refine(
isSafeAgentPackagePath,
'Agent package file path is unsafe'
)
export const agentPackageFileSchema = z
.object({
path: packageFilePathSchema,
size: z.number().int().nonnegative().safe(),
sha256: sha256Schema,
mode: z.enum(['0644', '0755'])
})
.strict()
const agentPackageDescriptorObjectSchema = z
.object({
format: z.literal(AGENT_PACKAGE_FORMAT),
formatVersion: z.literal(AGENT_PACKAGE_FORMAT_VERSION),
product: z.literal('GoodBuddy'),
component: z.literal('agent'),
version: semanticVersionSchema,
minimumDesktopVersion: semanticVersionSchema,
platform: z.literal('linux'),
architecture: agentArchitectureSchema,
signingKeyId: signingKeyIdSchema,
agentProtocol: agentProtocolVersionSchema,
remoteRuntime: z
.object({
runtimeId: z.literal('opencode'),
provider: z.literal('opencode'),
version: semanticVersionSchema,
bundleDigest: sha256DigestSchema,
protocol: agentProtocolVersionSchema
})
.strict(),
contentDigest: sha256DigestSchema,
files: z
.array(agentPackageFileSchema)
.min(1)
.max(50_000)
})
.strict()
export const agentPackageDescriptorSchema =
agentPackageDescriptorObjectSchema
.superRefine((descriptor, context) => {
const paths = descriptor.files.map((file) => file.path)
if (new Set(paths).size !== paths.length) {
context.addIssue({
code: 'custom',
path: ['files'],
message: 'Agent package contains duplicate file paths'
})
}
})
export type AgentPackageDescriptor = z.infer<
typeof agentPackageDescriptorSchema
>
export const agentPackageDownloadSchema = z
.object({
url: z.url().max(2_048)
})
.strict()
export const agentPackageCatalogEntrySchema =
agentPackageDescriptorObjectSchema
.omit({
contentDigest: true,
files: true,
signingKeyId: true
})
.extend({
archive: safeArchiveNameSchema,
size: z.number().int().positive().safe(),
sha256: sha256Schema,
downloads: z
.object({
github: agentPackageDownloadSchema,
mirror: agentPackageDownloadSchema
})
.strict()
})
.strict()
.superRefine((entry, context) => {
if (
entry.archive !==
agentPackageArchiveName(entry.version, entry.architecture)
) {
context.addIssue({
code: 'custom',
path: ['archive'],
message:
'Agent package archive name does not match its identity'
})
}
})
export type AgentPackageCatalogEntry = z.infer<
typeof agentPackageCatalogEntrySchema
>
export const agentPackageCatalogSchema = z
.object({
formatVersion: z.literal(1),
product: z.literal('GoodBuddy'),
component: z.literal('agent'),
signingKeyId: signingKeyIdSchema,
generatedAt: z.string().datetime(),
entries: z
.array(agentPackageCatalogEntrySchema)
.min(1)
.max(200)
})
.strict()
.superRefine((catalog, context) => {
const identities = catalog.entries.map(
(entry) => `${entry.version}:${entry.architecture}`
)
if (new Set(identities).size !== identities.length) {
context.addIssue({
code: 'custom',
path: ['entries'],
message: 'Agent package catalog contains duplicate entries'
})
}
})
export type AgentPackageCatalog = z.infer<
typeof agentPackageCatalogSchema
>
export const agentPackageStateSchema = z.enum([
'not-downloaded',
'verified',
'invalid'
])
export const agentPackageInventoryEntrySchema = z
.object({
platform: z.literal('linux'),
architecture: agentArchitectureSchema,
state: agentPackageStateSchema,
version: semanticVersionSchema.nullable(),
remoteRuntimeVersion: semanticVersionSchema.nullable(),
agentProtocol: agentProtocolVersionSchema.nullable()
})
.strict()
export const agentPackageInventorySchema = z
.object({
checkedAt: z.string().datetime(),
entries: z
.array(agentPackageInventoryEntrySchema)
.length(agentArchitectureSchema.options.length)
})
.strict()
.superRefine((inventory, context) => {
const architectures = inventory.entries.map(
(entry) => entry.architecture
)
if (new Set(architectures).size !== architectures.length) {
context.addIssue({
code: 'custom',
path: ['entries'],
message:
'Agent package inventory contains duplicate architectures'
})
}
})
export type AgentPackageInventory = z.infer<
typeof agentPackageInventorySchema
>
export const agentPackageInventoryRequestSchema = z
.object({
refresh: z.boolean().default(false)
})
.strict()
export const agentPackageArchitectureRequestSchema = z
.object({
architecture: agentArchitectureSchema
})
.strict()
export type AgentPackageArchitectureRequest = z.infer<
typeof agentPackageArchitectureRequestSchema
>
export const agentPackageDownloadProgressSchema = z
.object({
architecture: agentArchitectureSchema,
phase: z.enum([
'catalog',
'downloading',
'verifying',
'installing'
]),
completedBytes: z.number().int().nonnegative().safe(),
totalBytes: z.number().int().positive().safe().nullable()
})
.strict()
export type AgentPackageDownloadProgress = z.infer<
typeof agentPackageDownloadProgressSchema
>
+26
View File
@@ -161,9 +161,17 @@ export type {
} from './remote-project-candidate-contracts'
import type { WeixinBindingSnapshot } from './weixin-channel-contracts'
import type { RemoteChannelActivity } from './remote-channel-contracts'
import type {
AgentPackageDownloadProgress,
AgentPackageInventory
} from './agent-package-contracts'
import type {
AgentArchitecture
} from './agent-installation-contracts'
import type {
SshHostDraftInspectionRequest,
SshHostKeyInspection,
RemoteEnvironmentUpdateProgress,
SshHostRemoteEnvironment,
SshHostsSnapshot,
SshDirectoryBrowseResult,
@@ -1548,6 +1556,19 @@ export type DesktopApi = {
}
sshHosts?: {
getSnapshot: () => Promise<SshHostsSnapshot>
getAgentPackageInventory: (
refresh?: boolean
) => Promise<AgentPackageInventory>
downloadAgentPackage: (
architecture: AgentArchitecture
) => Promise<AgentPackageInventory>
importAgentPackage: () => Promise<AgentPackageInventory | undefined>
exportAgentPackage: (
architecture: AgentArchitecture
) => Promise<void>
onAgentPackageProgress: (
listener: (progress: AgentPackageDownloadProgress) => void
) => () => void
remove: (hostId: string) => Promise<void>
inspectDraftHostKey: (
input: SshHostDraftInspectionRequest
@@ -1559,6 +1580,11 @@ export type DesktopApi = {
getRemoteEnvironment: (
hostId: string
) => Promise<SshHostRemoteEnvironment>
updateRemoteEnvironment: (hostId: string) => Promise<void>
cancelRemoteEnvironmentUpdate: (hostId: string) => Promise<void>
onRemoteEnvironmentUpdateProgress: (
listener: (progress: RemoteEnvironmentUpdateProgress) => void
) => () => void
browseDirectories: (
hostId: string,
path?: string
+16
View File
@@ -41,8 +41,24 @@ export const ipcChannels = {
'settings:ssh-hosts:discard-candidate',
sshHostsValidateAndSave:
'settings:ssh-hosts:validate-and-save',
sshHostsAgentPackageInventory:
'settings:ssh-hosts:agent-package:inventory',
sshHostsAgentPackageDownload:
'settings:ssh-hosts:agent-package:download',
sshHostsAgentPackageImport:
'settings:ssh-hosts:agent-package:import',
sshHostsAgentPackageExport:
'settings:ssh-hosts:agent-package:export',
sshHostsAgentPackageProgress:
'settings:ssh-hosts:agent-package:progress',
sshHostsRemoteEnvironment:
'settings:ssh-hosts:remote-environment',
sshHostsUpdateRemoteEnvironment:
'settings:ssh-hosts:remote-environment:update',
sshHostsCancelRemoteEnvironmentUpdate:
'settings:ssh-hosts:remote-environment:update:cancel',
sshHostsRemoteEnvironmentUpdateProgress:
'settings:ssh-hosts:remote-environment:update:progress',
sshHostsBrowseDirectories:
'settings:ssh-hosts:directories:browse',
sshHostsCancelDirectoryBrowse:
+23
View File
@@ -6,6 +6,7 @@ import {
sshDirectoryBrowseResultSchema,
sshHostCreateInputSchema,
sshHostDraftInspectionRequestSchema,
remoteEnvironmentUpdateProgressSchema,
sshHostRemoteEnvironmentSchema,
sshHostValidationRequestSchema
} from './ssh-host-contracts'
@@ -243,6 +244,28 @@ describe('SSH host contracts', () => {
).toThrow()
})
it('strictly validates coarse remote environment update progress', () => {
const hostId = '00000000-0000-4000-8000-000000000101'
for (const phase of ['agent', 'runtime', 'finalizing']) {
expect(
remoteEnvironmentUpdateProgressSchema.parse({
hostId,
phase
})
).toEqual({ hostId, phase })
}
for (const progress of [
{ hostId: 'not-a-uuid', phase: 'agent' },
{ hostId, phase: 'uploading' },
{ hostId, phase: 'runtime', path: '/home/user' },
{ hostId, phase: 'agent', command: 'whoami' }
]) {
expect(() =>
remoteEnvironmentUpdateProgressSchema.parse(progress)
).toThrow()
}
})
it('validates strict directory browse requests and treats an omitted path as valid', () => {
const hostId = '00000000-0000-4000-8000-000000000101'
expect(
+21
View File
@@ -282,6 +282,27 @@ export type SshHostRemoteEnvironment = z.infer<
typeof sshHostRemoteEnvironmentSchema
>
export const remoteEnvironmentUpdatePhaseSchema = z.enum([
'agent',
'runtime',
'finalizing'
])
export type RemoteEnvironmentUpdatePhase = z.infer<
typeof remoteEnvironmentUpdatePhaseSchema
>
export const remoteEnvironmentUpdateProgressSchema = z
.object({
hostId: sshHostIdSchema,
phase: remoteEnvironmentUpdatePhaseSchema
})
.strict()
export type RemoteEnvironmentUpdateProgress = z.infer<
typeof remoteEnvironmentUpdateProgressSchema
>
export const agentBootstrapIncompatibleReasonSchema = z.enum([
'non-linux',
'unsupported-architecture',