跳转到内容

公共子路径导出

除了主插件入口外,opencode-mem 还暴露一个稳定的子路径, 其他 opencode 插件可直接导入。这避免了在编写读写同一记忆存储的第三方工具时, 不得不逆向工程容器标签约定。

规范的容器标签辅助函数。与 opencode-mem 自身用于 限定自动捕获记忆范围的相同函数。

import { getProjectTagInfo, getUserTagInfo, getTags } from "opencode-mem/tags";
// Canonical project tag derived from cwd (git remote URL if present, else
// the project root path). Format: `opencode_project_<sha16>`.
const projectTag = getProjectTagInfo(process.cwd()).tag;
// Canonical user tag derived from `git config user.email`.
// Format: `opencode_user_<sha16>`.
const userTag = getUserTagInfo().tag;
// Both at once.
const { user, project } = getTags(process.cwd());

这些辅助函数产生的标签与自动捕获写入的匹配,因此调用 POST /api/memories 的第三方 插件会落入系统其余部分已理解的同一分片。手工制作的标签若子串不是 _project_ 或 _user_,会落入 /api/stats 与 /api/memories 静默过滤掉的影子分片 — 使用这些辅助函数可避免该陷阱。