feat: keep managed SSH prompts running on Hosts

Managed SSH prompts previously depended on Desktop-owned provider and transcript state, so accepted work could stop or become uncertain when the Desktop, network, or power disappeared. The Agent now owns accepted OpenCode prompt execution, model and tool rounds, cancellation, and the durable semantic transcript, while Desktop remains authoritative for permanent projects, conversations, tasks, and messages.

Recovered work attaches to the original conversation without replay. The project switcher also groups managed SSH projects by saved Host and shows live Agent connectivity beside each group without opening a connection merely to read status. Remote project subtitles now show only the path, and the Agent lock advances to 0.11.14 with Runtime ACP v4.

Release note: 托管 SSH 任务在桌面端、网络或电源中断后可继续在主机上运行,并能回到原会话精确恢复;项目菜单现按主机分组并显示实时连接状态。
This commit is contained in:
mesalogo
2026-08-31 11:04:41 +08:00
parent f6f8d5e053
commit 561de29f00
75 changed files with 13439 additions and 1327 deletions
@@ -29,12 +29,7 @@ import type {
const RUNTIME_ACP_CAPABILITY = {
name: 'runtime/acp',
exactVersion: 3,
critical: true
} as const
const RUNTIME_MODEL_BRIDGE_CAPABILITY = {
name: 'runtime/model-bridge',
exactVersion: 1,
exactVersion: 4,
critical: true
} as const
@@ -106,8 +101,7 @@ export async function createManagedRemoteAcpRuntime(
{
...agent,
requiredCapabilities: [
RUNTIME_ACP_CAPABILITY,
RUNTIME_MODEL_BRIDGE_CAPABILITY
RUNTIME_ACP_CAPABILITY
]
}
)
@@ -130,8 +124,7 @@ export async function createManagedRemoteAcpRuntime(
workspaceBinding,
agent,
activeConnection,
runtime,
options.modelBridge
runtime
)
const initialTransport =
await resources.prepareTransport(capabilities)
@@ -160,6 +153,7 @@ export async function createManagedRemoteAcpRuntime(
resources.openChannel(transport, bindingId),
bindingStore: options.bindingStore,
modelBridgePolicy: options.modelBridge.policy,
modelProfile: options.modelBridge.profile,
assertHostCurrent: (identity) => {
if (
identity.controllerId !== controllerId ||
@@ -213,6 +207,7 @@ class ManagedRemoteRuntimeResources {
| undefined
#workspaceTail: Promise<void> = Promise.resolve()
#disposePromise?: Promise<void>
#detachedForApplicationExit = false
constructor(
private readonly workspaceBinding: RemoteWorkspaceProjectBinding,
private readonly agent: AgentInstallationIdentity,
@@ -223,8 +218,7 @@ class ManagedRemoteRuntimeResources {
>
>
>,
private readonly runtime: ManagedRemoteRuntimeIdentity,
private readonly modelBridge: ManagedModelBridge
private readonly runtime: ManagedRemoteRuntimeIdentity
) {}
get workspaceIdentity(): string {
@@ -297,8 +291,7 @@ class ManagedRemoteRuntimeResources {
runtimeId: 'opencode',
runtimeBundleDigest: this.runtime.bundleDigest,
workspaceIdentity: this.workspaceIdentity
},
modelBridge: this.modelBridge.channel
}
})
try {
assertSameTransport(
@@ -388,10 +381,18 @@ class ManagedRemoteRuntimeResources {
}
dispose(): Promise<void> {
if (this.#detachedForApplicationExit) {
return Promise.resolve()
}
this.#disposePromise ??= this.#dispose()
return this.#disposePromise
}
detachForApplicationExit(): void {
this.#detachedForApplicationExit = true
this.#workspace = undefined
}
async #dispose(): Promise<void> {
await this.#workspaceTail
const errors: unknown[] = []
@@ -426,6 +427,7 @@ class ManagedRemoteAcpRuntime implements AgentRuntime {
#activeRuns = 0
#draining = false
#disposed = false
#detachedForApplicationExit = false
constructor(
private remote: AcpRemoteRuntime,
@@ -543,6 +545,9 @@ class ManagedRemoteAcpRuntime implements AgentRuntime {
}
forceShutdown(): Promise<void> {
if (this.#detachedForApplicationExit) {
return Promise.resolve()
}
this.#disposed = true
return this.#transitionTail
.then(() => this.remote.forceShutdown())
@@ -550,11 +555,21 @@ class ManagedRemoteAcpRuntime implements AgentRuntime {
}
dispose(): Promise<void> {
if (this.#detachedForApplicationExit) {
return Promise.resolve()
}
this.#disposed = true
this.#disposePromise ??= this.#dispose()
return this.#disposePromise
}
detachForApplicationExit(): void {
this.#disposed = true
this.#draining = true
this.#detachedForApplicationExit = true
this.resources.detachForApplicationExit()
}
async #dispose(): Promise<void> {
await this.#transitionTail
const results = await Promise.allSettled([
@@ -685,9 +700,6 @@ function assertRuntimeAdvertised(
const capability = capabilities.capabilities.find(
(entry) => entry.name === RUNTIME_ACP_CAPABILITY.name
)
const modelBridgeCapability = capabilities.capabilities.find(
(entry) => entry.name === RUNTIME_MODEL_BRIDGE_CAPABILITY.name
)
const advertised = capabilities.runtimes.filter(
(entry) => entry.runtimeId === 'opencode'
)
@@ -696,10 +708,6 @@ function assertRuntimeAdvertised(
capability.version !==
RUNTIME_ACP_CAPABILITY.exactVersion ||
!capability.critical ||
modelBridgeCapability === undefined ||
modelBridgeCapability.version !==
RUNTIME_MODEL_BRIDGE_CAPABILITY.exactVersion ||
!modelBridgeCapability.critical ||
advertised.length !== 1 ||
advertised[0]!.version !== runtime.runtimeVersion ||
advertised[0]!.bundleDigest !== runtime.bundleDigest ||