fix: reuse runtime processes across project sessions

Multiple projects could spawn duplicate heavyweight runtimes, while settings
changes and remote reconnection could cancel or strand native conversations.
Share compatible local OpenCode and DeepSeek Harness process owners and
Agent-owned ACP connections, retaining workspace routing, per-session modes,
model attribution, question ownership, targeted cancellation and idle cleanup.

Restore remote pending questions and terminal task projections across reconnect
and desktop restart, and preserve accepted ordinary requests during settings
replacement while cancelling expert-team parents with their replaced scheduler.
Extend regression coverage and Agent type checks. Record measured resource and
real-model validation results, including failures and limitations.

Also include the conversation media-generation design drafts (not an implemented
feature), documentation entry links and dedicated Linux test-directory guidance.
Desktop and Agent changes must be delivered together for shared process results.

Validation: typecheck and lint passed; staged content and documentation links
checked. Prior full regression and live-model evidence are recorded in progress
notes; no new full test suite or model calls were run for this commit.

Release note: 多项目会话现在复用兼容的 OpenCode 和 DeepSeek Harness 进程,减少重复启动并保持工作区、工具和取消隔离。修复远端问答在断线、重启及配置更新后的恢复与状态同步问题,Desktop 与 Agent 需配套更新。
This commit is contained in:
mesalogo
2026-09-15 08:14:42 +08:00
parent b755951ecd
commit e5aa9ed688
65 changed files with 4116 additions and 365 deletions
+39 -15
View File
@@ -3,7 +3,8 @@ import {
type ModelRuntimeOptions
} from './model-runtime'
import { ContinueAgentRuntime } from './continue-runtime'
import { OpenCodeRuntime } from './opencode-runtime'
import { OpenCodeRuntime, type OpenCodeRuntimeOptions } from './opencode-runtime'
import type { LocalRuntimeRegistry } from './local-runtime-registry'
import {
DeepSeekHarnessRuntime,
type DeepSeekHarnessRuntimeOptions
@@ -57,6 +58,7 @@ const noModelTaskTools: ModelToolProviderLike = {
}
export type AgentCapabilityContext = {
localRuntimeRegistry?: LocalRuntimeRegistry
skillInstructions?: string
skillPackages?: RuntimeSkillPackage[]
mcpServers?: ResolvedMcpServer[]
@@ -213,8 +215,8 @@ export function createAgentRuntime(
if (!capabilities.deepseekHarnessLauncher) {
throw new Error('DeepSeek Harness 受控 Host 启动器不可用')
}
return new DeepSeekHarnessRuntime({
defaultWorkspace: workspace,
const options: DeepSeekHarnessRuntimeOptions = {
defaultWorkspace: capabilities.localRuntimeRegistry ? defaultWorkspace : workspace,
baseUrl: profile.baseUrl,
model: profile.modelName,
supportsImageInput: profile.supportsImageInput === true,
@@ -225,16 +227,26 @@ export function createAgentRuntime(
},
skillPackages: capabilities.skillPackages,
extensionPackages: capabilities.deepseekHarnessExtensions,
toolProvider: new ModelToolProvider(
getWorkspaceAccess(),
capabilities.mcpServers,
undefined,
capabilities.knowledgeGateway,
capabilities.webSearchEnabled === true,
{},
capabilities.launchEnvironmentProvider
createToolProvider: (directory) => new ModelToolProvider(
new LocalWorkspaceAccess(directory), capabilities.mcpServers, undefined,
capabilities.knowledgeGateway, capabilities.webSearchEnabled === true,
{}, capabilities.launchEnvironmentProvider
)
})
}
const create = () => new DeepSeekHarnessRuntime(options)
if (!capabilities.localRuntimeRegistry) return create()
const configuration = { ...options, defaultWorkspace: undefined, createToolProvider: undefined }
return capabilities.localRuntimeRegistry.acquire(
`deepseek-harness:${profile.id}`,
{
...configuration,
mcpServers: capabilities.mcpServers,
webSearchEnabled: capabilities.webSearchEnabled === true,
launchEnvironment: capabilities.launchEnvironmentProvider?.()
},
workspace,
create
)
}
if (provider === 'continue') {
@@ -293,7 +305,7 @@ export function createAgentRuntime(
'OpenCode 独立模型连接仅支持文本对话协议,不支持图像生成协议'
)
}
return new OpenCodeRuntime({
const options: OpenCodeRuntimeOptions = {
baseUrl,
embedded,
binaryPath:
@@ -311,13 +323,25 @@ export function createAgentRuntime(
skillInstructions: capabilities.skillInstructions,
skillPackages: capabilities.skillPackages,
sharedCacheRoot: capabilities.opencodeSharedCacheRoot,
defaultWorkspace: workspace,
defaultWorkspace: capabilities.localRuntimeRegistry ? defaultWorkspace : workspace,
knowledgeGateway: capabilities.knowledgeGateway,
mcpServers: capabilities.mcpServers,
customization: settings?.runtimeCustomization.opencode,
launchEnvironmentProvider:
capabilities.launchEnvironmentProvider
})
}
const create = () => new OpenCodeRuntime(options)
if (!capabilities.localRuntimeRegistry) return create()
const configuration = { ...options, defaultWorkspace: undefined }
return capabilities.localRuntimeRegistry.acquire(
`opencode:${settings?.opencodeModelProfile?.id ?? 'native'}`,
{
...configuration,
launchEnvironment: capabilities.launchEnvironmentProvider?.()
},
workspace,
create
)
}
const defaultModelProfile =