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:
@@ -1,7 +1,8 @@
|
||||
import { refreshSessionCredential } from "../product/credential-refresh.js";
|
||||
import { type Router } from "express";
|
||||
import { z } from "zod";
|
||||
|
||||
import { getLocalAgentContext } from "../context/localContext.js";
|
||||
import { getLocalAgentContext, getTrustedProductCredential } from "../context/localContext.js";
|
||||
import { logger } from "../logger.js";
|
||||
import { type OpencodeRuntimeAdapter } from "../runtime/opencode.js";
|
||||
import { type SessionMetadataStore } from "../sessions/metadataStore.js";
|
||||
@@ -72,6 +73,21 @@ export const registerChatInteractionRoutes = (
|
||||
sessionUiStateStore,
|
||||
}: RegisterInteractionRoutesOptions,
|
||||
) => {
|
||||
chatRouter.post("/session/:session_id/credentials", async (req, res) => {
|
||||
const record = await sessionMetadataStore.get(getLocalAgentContext(req), req.params.session_id);
|
||||
const credential = getTrustedProductCredential(req);
|
||||
if (!record || !credential) { res.status(404).json({ message: "session not found" }); return; }
|
||||
const run = activeRuns.get(record.sessionId);
|
||||
const requestId = typeof req.body?.request_id === "string" ? req.body.request_id : undefined;
|
||||
if (!run || run.status !== "running" || (!requestId && record.purpose !== "task_execution")) {
|
||||
res.status(409).json({ message: "credential refresh is not pending" }); return;
|
||||
}
|
||||
if (!refreshSessionCredential(record.sessionId, credential, requestId)) {
|
||||
res.status(409).json({ message: "credential refresh request does not match" }); return;
|
||||
}
|
||||
res.status(202).json({ accepted: true });
|
||||
});
|
||||
|
||||
chatRouter.post("/permission/:request_id/reply", async (req, res) => {
|
||||
const requestId = req.params.request_id?.trim();
|
||||
const parsed = permissionReplyPayloadSchema.safeParse(req.body);
|
||||
|
||||
Reference in New Issue
Block a user