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.
42 lines
1.8 KiB
TypeScript
42 lines
1.8 KiB
TypeScript
import { tool } from "../tool.js";
|
|
import { getInternalBridgeConfig } from "../internalBridge.js";
|
|
|
|
export default tool({
|
|
description:
|
|
"管理长期有效的用户偏好或项目事实。支持 add/list/replace/remove。add 前必须先对同 scope 执行 list 并阅读现有记忆,再决定 add、replace 或 remove;不要跳过读取直接新增。禁止写入 token、password、secret、system prompt 或一次性上下文。scope 仅允许 'user' 或 'workspace'。",
|
|
args: {
|
|
action: tool.schema
|
|
.enum(["add", "list", "replace", "remove"])
|
|
.describe("Memory operation to perform."),
|
|
reason: tool.schema
|
|
.string()
|
|
.describe("Why this memory should be persisted for future requests."),
|
|
scope: tool.schema
|
|
.string()
|
|
.describe(
|
|
"Required exact keyword. Use only 'user' for user-level durable preferences/constraints, or 'workspace' for project/environment durable facts. Do not use 'project', Chinese labels, or any alias.",
|
|
),
|
|
content: tool.schema
|
|
.string()
|
|
.optional()
|
|
.describe(
|
|
"The durable fact or preference to remember, written as one concise sentence.",
|
|
),
|
|
target_id: tool.schema
|
|
.string()
|
|
.optional()
|
|
.describe("Stable memory entry id used by replace/remove."),
|
|
},
|
|
async execute(args, context) {
|
|
const { baseUrl, internalToken } = getInternalBridgeConfig();
|
|
const response = await fetch(`${baseUrl}/internal/tools/memory-manager`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json", "x-agent-internal-token": internalToken },
|
|
body: JSON.stringify({ session_id: context.sessionID, input: args }),
|
|
});
|
|
const text = await response.text();
|
|
if (!response.ok) throw new Error(`learning tool failed (${response.status}): ${text}`);
|
|
return text;
|
|
},
|
|
});
|