Files
goodbuddy/src/main/execution-space/execution-space-resolver.ts
T
mesalogo 459cc21e3d
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build Linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build Linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
fix: make managed SSH sessions fast and resilient
Managed SSH project selection repeatedly activated the remote Host and could
leave idle ACP bindings rejected as stale-controller after a controller
generation change. Host environment updates also coupled project state to
component installation evidence and presented a crowded control surface.

Project selection is now local-only, one Host connection serves compatible
project and conversation callers, idle bindings are safely replaced only
after proven controller takeover, and active prompts keep exact resume/replay.
Remote environment setup now uses explicit signed compound package
preparation with bounded transfer, rollback, recovery, and clearer settings.

Managed Hosts must be updated to separately distributed Agent 0.11.6 before
the daemon-side controller recovery fix takes effect. Desktop packages do not
embed the Agent or remote Runtime, and existing project data is preserved.

Release note: 托管 SSH 项目切换不再重复连接,同一 Host 可顺畅承载多个项目和对话;同时修复重连后的 stale-controller,并优化远程环境安装、更新与状态布局。
2026-08-29 10:58:19 +08:00

111 lines
2.8 KiB
TypeScript

import { isAbsolute, normalize, resolve } from 'node:path'
import type { AssistantProject } 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
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 binding: RemoteWorkspaceProjectBinding = {
hostId: executionSpace.hostId,
remoteRootPath: executionSpace.remoteRootPath
}
return {
kind: 'ssh',
...binding,
cacheIdentity: JSON.stringify([
'ssh',
binding.hostId,
binding.remoteRootPath
]),
routeIdentity: JSON.stringify([
'ssh',
project.id,
binding.hostId,
binding.remoteRootPath
]),
workspaceAccess:
this.remoteWorkspaceAccessFactory
? this.remoteWorkspaceAccessFactory.create(binding)
: new UnsupportedRemoteWorkspaceAccess(
REMOTE_EXECUTION_SPACE_UNAVAILABLE
)
}
}
assertLocal(
descriptor: ExecutionSpaceDescriptor
): asserts descriptor is LocalExecutionSpaceDescriptor {
if (descriptor.kind !== 'local') {
throw new Error(REMOTE_EXECUTION_SPACE_UNAVAILABLE)
}
}
}