feat: run agent tools with host permissions

This commit is contained in:
mesalogo
2026-08-15 18:06:03 +08:00
parent 79e2511f6f
commit 34bbfab2af
38 changed files with 224 additions and 1395 deletions
+3 -31
View File
@@ -38,10 +38,6 @@ import {
buildRuntimeEnvironment,
runtimePrivacyEnvironment
} from './process-environment'
import {
buildBubblewrapLaunch,
type RuntimeSandboxResolution
} from './runtime-sandbox'
import {
boundedToolDetail,
safeToolErrorDetail
@@ -388,7 +384,6 @@ export type OpenCodeRuntimeOptions = {
modelProfile?: ResolvedModelProfile
skillInstructions?: string
skillPackages?: RuntimeSkillPackage[]
sandbox?: RuntimeSandboxResolution
knowledgeGateway?: KnowledgeMcpGateway
}
@@ -741,13 +736,6 @@ export class OpenCodeRuntime implements AgentRuntime {
) {
throw new Error('OpenCode 独立模型连接尚未配置 API Key')
}
const sandbox = this.options.sandbox
if (
sandbox?.status.mode === 'strict' &&
!sandbox.status.available
) {
throw new Error(sandbox.status.detail)
}
const skillIds = this.getNativeSkillIds()
const registration = await this.createSkillRegistration()
try {
@@ -813,25 +801,11 @@ export class OpenCodeRuntime implements AgentRuntime {
'--hostname=127.0.0.1',
`--port=${port}`
]
const launch =
sandbox?.status.available && sandbox.binaryPath
? buildBubblewrapLaunch({
binaryPath: sandbox.binaryPath,
command: binaryPath,
args: serverArgs,
workspace: this.options.defaultWorkspace,
readOnlyPaths: this.options.configPath.trim()
? [resolve(this.options.configPath)]
: [],
writablePaths: [registration.root],
platform: this.dependencies.platform
})
: { command: binaryPath, args: serverArgs }
return await new Promise<OpenCodeServer>((resolveServer, reject) => {
const child = this.dependencies.spawn(
launch.command,
launch.args,
binaryPath,
serverArgs,
{
cwd: this.options.defaultWorkspace,
env,
@@ -1019,9 +993,7 @@ export class OpenCodeRuntime implements AgentRuntime {
available: true,
supportsToolExecution: this.supportsToolExecution,
detail: this.server
? this.options.sandbox
? `由 GoodBuddy 管理本机 OpenCode 进程;${this.options.sandbox.status.detail}`
: '由 GoodBuddy 管理本机 OpenCode 进程'
? '由 GoodBuddy 以当前用户权限管理本机 OpenCode 进程'
: `已连接 ${this.options.baseUrl}`
}
} catch (error) {