feat(agent): migrate OpenCode 2 runtime and sandbox tools

Upgrade the runtime and native plugin API to OpenCode 2.0.24. Restore
session-scoped learning, credential renewal, typed project queries and
controlled frontend actions from the legacy Agent.

Replace host Shell execution with an approved Landlock/seccomp executor
and persistent per-session workspaces. Add typed Bocha search and Tianditu
geocoding bridges using the owning session credential. Require a working
kernel sandbox before startup and persist workspace files in deployments.

Validation completed before this commit: TypeScript checks, 150 Bun tests,
Docker build and UID 10001 sandbox execution, native Shell approval and
session recovery. Tianditu succeeded; Bocha currently reports exhausted
account quota. Unrelated investigation-report contract work is excluded.
This commit is contained in:
2026-10-08 15:46:37 +08:00
parent 1a9b0cafc1
commit 7383ed6d13
93 changed files with 8065 additions and 1098 deletions
+10 -3
View File
@@ -58,16 +58,23 @@ const envSchema = z
.default("./logs/llm-request-audit.log"),
// 内部工具桥鉴权 token;embedded 可自动生成,client 模式必须与外部 OpenCode 显式共享。
AGENT_INTERNAL_TOKEN: optionalString(),
// opencode 运行模式:embedded 会启动本地 CLI 子进程;client 只连接现有 server。
// 每个 OpenCode 会话独占的 Shell 工作目录;与受保护的业务 data/logs 分开。
CONVERSATION_WORKSPACE_ROOT: z.string().default("./.agent-workspaces"),
SANDBOX_MAX_OUTPUT_BYTES: z.coerce.number().int().positive().max(16 * 1024 * 1024).default(1024 * 1024),
// OpenCode 2 CLI 命令或绝对路径。
OPENCODE_COMMAND: z.string().default("opencode2"),
// 外部 OpenCode 2 Server 的密码;embedded 模式自动管理。
OPENCODE_CLIENT_PASSWORD: optionalString(),
// embedded 启动私有 CLI 子进程;client 连接现有 V2 server。
OPENCODE_MODE: z.enum(["embedded", "client"]).default("embedded"),
// embedded opencode server 的监听地址。
OPENCODE_HOSTNAME: z.string().default("127.0.0.1"),
// embedded opencode server 的监听端口;0 表示由系统动态分配。
OPENCODE_PORT: z.coerce.number().int().nonnegative().default(0),
// opencode SDK 启动或连接运行时时的超时时间(毫秒)。
// OpenCode 2 启动超时时间(毫秒)。
OPENCODE_TIMEOUT_MS: z.coerce.number().int().positive().default(5000),
// 默认使用的 opencode 模型标识。
OPENCODE_MODEL: z.string().default("deepseek/deepseek-v4-flash"),
OPENCODE_MODEL: z.string().default("deepseek/deepseek-flash"),
// 后台工况任务首选模型;缺省沿用 OPENCODE_MODEL,运行时会从实际可用模型中选择回退。
OPERATIONAL_TASK_MODEL: optionalString(),
// 聊天 UI 和 /stream 允许选择的 opencode 模型完整配置,JSON 数组。