import { tool } from "@opencode-ai/plugin"; const internalBaseUrl = process.env.TJWATER_AGENT_INTERNAL_BASE_URL ?? "http://127.0.0.1:8787"; const internalToken = process.env.TJWATER_AGENT_INTERNAL_TOKEN ?? ""; 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."), 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 response = await fetch( `${internalBaseUrl}/internal/tools/memory-manager`, { method: "POST", headers: { "Content-Type": "application/json", "x-agent-internal-token": internalToken, }, body: JSON.stringify({ ...args, session_id: context.sessionID, }), }, ); const text = await response.text(); if (!response.ok) { throw new Error(text); } return text; }, });