feat: add managed SSH execution spaces

Add managed SSH Hosts and projects with signed side-by-side GoodBuddy Agent and OpenCode Runtime installation, Ask and Execute workspace access, a Main-owned model bridge, detached Agent lifecycle, durable ACP output recovery, and project activation UI.

Use protocol v2 with bounded FIFO frames over SSH instead of custom credit, priority, batching, or model-message chunking. Mismatched Host Agents now upgrade automatically, an exactly verified Node runtime is reused on-host, and local Portable builds can embed strictly verified Agent artifacts.

Release note: 新增托管 SSH 远程项目,可自动安装或升级签名 Agent/OpenCode Runtime,并在 SSH 断线后继续 Agent 工作和同步未确认输出。
This commit is contained in:
mesalogo
2026-08-24 23:02:18 +08:00
parent 3829a871f5
commit 607bb33249
258 changed files with 99449 additions and 2427 deletions
@@ -0,0 +1,167 @@
import { isAbsolute, normalize, resolve } from 'node:path'
import type {
AssistantProject,
ProjectRuntimeValidation,
SshExecutionValidation
} from '../../shared/assistant-contracts'
import {
LocalWorkspaceAccess,
UnsupportedRemoteWorkspaceAccess,
type RemoteWorkspaceAccessFactory,
type RemoteWorkspaceProjectBinding,
type WorkspaceAccess
} from '../workspace'
export const REMOTE_EXECUTION_SPACE_UNAVAILABLE =
'远程执行空间尚不可用'
export type LocalExecutionSpaceDescriptor = {
kind: 'local'
rootPath: string
cacheIdentity: string
routeIdentity: string
workspaceAccess: WorkspaceAccess
}
export type SshExecutionSpaceDescriptor = {
kind: 'ssh'
hostId: string
remoteRootPath: string
validation?: SshExecutionValidation
runtimeValidation?: ProjectRuntimeValidation
cacheIdentity: string
routeIdentity: string
workspaceAccess: WorkspaceAccess
}
export type ExecutionSpaceDescriptor =
| LocalExecutionSpaceDescriptor
| SshExecutionSpaceDescriptor
function normalizeLocalIdentity(rootPath: string): string {
const trimmed = rootPath.trim()
if (!trimmed) {
return 'local:unconfigured'
}
const normalized = normalize(
isAbsolute(trimmed) ? trimmed : resolve(trimmed)
)
return `local:${
process.platform === 'win32'
? normalized.toLocaleLowerCase('en-US')
: normalized
}`
}
export class ExecutionSpaceResolver {
constructor(
private readonly remoteWorkspaceAccessFactory?:
RemoteWorkspaceAccessFactory
) {}
resolveLocal(rootPath: string): LocalExecutionSpaceDescriptor {
const cacheIdentity = normalizeLocalIdentity(rootPath)
return {
kind: 'local',
rootPath,
cacheIdentity,
routeIdentity: cacheIdentity,
workspaceAccess: new LocalWorkspaceAccess(rootPath)
}
}
resolveProject(project: AssistantProject): ExecutionSpaceDescriptor {
const executionSpace = project.executionSpace ?? {
kind: 'local' as const,
rootPath: project.rootPath
}
if (executionSpace.kind === 'local') {
return this.resolveLocal(executionSpace.rootPath)
}
const sshValidation = executionSpace.validation
const runtimeValidation = project.runtimeValidation
const identity = {
hostId: executionSpace.hostId,
remoteRootPath: executionSpace.remoteRootPath,
validation: sshValidation,
runtimeValidation
}
const remoteBinding: RemoteWorkspaceProjectBinding | undefined =
sshValidation &&
runtimeValidation &&
sshValidation.agentInstallationIdAtValidation ===
runtimeValidation.agentInstallationIdAtValidation
? {
hostId: executionSpace.hostId,
remoteRootPath: executionSpace.remoteRootPath,
hostRevision: sshValidation.hostRevision,
hostKeyGeneration: sshValidation.hostKeyGeneration,
remoteUsername: sshValidation.remoteUsername,
workspaceIdentity: sshValidation.workspaceIdentity,
agentProtocolMajor: sshValidation.agentProtocolMajor,
agentInstallationId:
sshValidation.agentInstallationIdAtValidation,
agentBinaryDigest:
sshValidation.agentBinaryDigestAtValidation,
agentVersion: sshValidation.agentVersionAtValidation,
agentArchitecture:
sshValidation.agentArchitectureAtValidation
}
: undefined
return {
kind: 'ssh',
...identity,
cacheIdentity: JSON.stringify([
'ssh',
identity.hostId,
identity.remoteRootPath,
identity.validation
? [
identity.validation.hostRevision,
identity.validation.hostKeyGeneration,
identity.validation.remoteUsername,
identity.validation.workspaceIdentity,
identity.validation.agentProtocolMajor,
identity.validation.agentInstallationIdAtValidation,
identity.validation.agentBinaryDigestAtValidation,
identity.validation.agentVersionAtValidation,
identity.validation.agentArchitectureAtValidation,
identity.validation.validatedAt
]
: null,
identity.runtimeValidation
? [
identity.runtimeValidation.runtimeSelectionKey,
identity.runtimeValidation.runtimeBundleDigest,
identity.runtimeValidation.runtimeAdapterDigest,
identity.runtimeValidation
.agentInstallationIdAtValidation,
identity.runtimeValidation.validatedAt,
identity.runtimeValidation.workMode
]
: null
]),
routeIdentity: JSON.stringify([
'ssh',
project.id,
identity.hostId,
identity.remoteRootPath
]),
workspaceAccess:
remoteBinding && this.remoteWorkspaceAccessFactory
? this.remoteWorkspaceAccessFactory.create(remoteBinding)
: new UnsupportedRemoteWorkspaceAccess(
REMOTE_EXECUTION_SPACE_UNAVAILABLE
)
}
}
assertLocal(
descriptor: ExecutionSpaceDescriptor
): asserts descriptor is LocalExecutionSpaceDescriptor {
if (descriptor.kind !== 'local') {
throw new Error(REMOTE_EXECUTION_SPACE_UNAVAILABLE)
}
}
}