mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-30 00:47:36 +00:00
* feat(integrations): add ZCode memory plugin Package ReMe lifecycle hooks, MCP tools, and the reme-memory skill as an installable ZCode plugin. The hook queues completed turns locally and retries delivery from later sessions so transient service failures do not lose memory. * fix(zcode): resolve pre-commit failures without blocking delivery * fix(zcode): honor disabled memory, keep one prompt copy, document setup Address the review on the ZCode integration: - config.example.json ships an empty api_url so the default single-port deployment is derived from mcp_url instead of pointing at a port the default `reme start` does not open. - remember_prompt writes a single cache record per turn: a payload without a turn ID is read back from latest.json, so the extra hashed copy left plaintext prompt text behind after the turn was delivered. - flush_worker re-reads auto_memory before delivering and leaves pending files untouched when recording was disabled mid-flight; it also uses a worker.rerun marker so a delivery request arriving while another pass holds the lock triggers a rescan instead of being dropped. - README/README_ZH now follow the Qoder guide: dependency install, model credentials, an executable `reme start` with an explicit workspace, platform-specific commands, empty-api_url derivation, the memory_interval example vs default, MCP reconnect after endpoint changes, a health_check/version check before the memory test, and a qualified statement about the async hook field and the detached worker. - Regression tests cover all four behaviors. Co-Authored-By: Claude Code <noreply@anthropic.com> * docs(zcode): state the verified ZCode build Name the build the plugin was verified on and the reason compatibility rests on payload fields rather than a version number. Co-Authored-By: Claude Code <noreply@anthropic.com> * test(zcode): name unused flush_all config with an underscore * fix(zcode): make worker handoff race-safe and honor the recording switch The rerun marker was written only after a failed lock acquisition, so a contender suspended between the failed acquire and the marker write left a queued session and a marker with no worker to process them. The worker now publishes its request before contending for the lock, which leaves exactly two outcomes: the owner sees the marker and scans again, or the lock is free and this worker delivers itself. worker.rerun also dropped force semantics, so a SessionStart force request lost to a Stop owner whose rerun pass then stayed non-forced. A separate, never downgraded worker.force marker keeps the stronger request until the next pass. The auto_memory switch was checked once at worker entry and the snapshot reused for every batch, so disabling recording during a run still submitted later batches. The switch is now rechecked before every network submission and unsent queue files are preserved when it is disabled. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(zcode): claim worker requests atomically and scope them by endpoint The force marker was read with exists() and removed with unlink(), so a SessionStart contender that published worker.rerun and worker.force while a force=False owner held the lock had its request deleted by a pass that never saw it; the owner then delivered unforced and both markers were gone. Requests are now consumed by one atomic rename that returns whether this pass owns the force request, so a marker published after that step stays on disk for the next pass. worker.lock, worker.rerun and worker.force lived in the shared data directory while the queues are endpoint-scoped. An old-endpoint worker awaiting its acknowledgement therefore blocked a worker for a newly configured endpoint and then consumed its request while rescanning only the old queue. Scheduling state now lives under workers/<endpoint digest>, beside the queue it serves, so each endpoint's request reaches a worker that scans that endpoint. validate_config resolved the default Asia/Shanghai without checking whether an IANA database exists, so a Windows host without tzdata failed with "timezone must be an IANA timezone". Missing timezone data and an invalid key now report different errors, and the setup docs install tzdata on Windows and state what a missing database logs. Co-Authored-By: Claude Code <noreply@anthropic.com> * style(zcode): satisfy pre-commit on the timezone and endpoint tests Add the trailing comma add-trailing-comma expects in the missing-timezone-data error and rename the unused call() argument in the endpoint-switch regression test, so Pre-commit stays green without touching behavior. Co-Authored-By: Claude Code <noreply@anthropic.com> --------- Co-authored-by: Claude Code <noreply@anthropic.com>
322 lines
13 KiB
JavaScript
322 lines
13 KiB
JavaScript
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||
import path from "node:path";
|
||
import { fileURLToPath } from "node:url";
|
||
import { parse as parseYaml } from "yaml";
|
||
|
||
const siteDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||
const repoDir = path.resolve(siteDir, "..");
|
||
const outputDir = path.join(siteDir, ".generated", "site");
|
||
|
||
const externalDocuments = [
|
||
["zh/overview.md", "README_ZH.md"],
|
||
["en/overview.md", "README.md"],
|
||
["en/integrations/claude-code.md", "integrations/claude_code/README.md"],
|
||
["zh/integrations/claude-code.md", "integrations/claude_code/README_ZH.md"],
|
||
["en/integrations/codex.md", "integrations/codex/README.md"],
|
||
["zh/integrations/codex.md", "integrations/codex/README_ZH.md"],
|
||
["en/integrations/qoder.md", "integrations/qoder/README.md"],
|
||
["zh/integrations/qoder.md", "integrations/qoder/README_ZH.md"],
|
||
["en/integrations/zcode.md", "integrations/zcode/README.md"],
|
||
["zh/integrations/zcode.md", "integrations/zcode/README_ZH.md"],
|
||
["en/integrations/hermes.md", "integrations/hermes_agent/README.md"],
|
||
["zh/integrations/dsh.md", "integrations/dsh/README_ZH.md"],
|
||
["en/integrations/dsh.md", "integrations/dsh/README.md"],
|
||
["zh/integrations/openclaw.md", "integrations/openclaw/README_ZH.md"],
|
||
["en/integrations/openclaw.md", "integrations/openclaw/README.md"],
|
||
["zh/plugins/daily-paper.md", "plugins/daily_paper/README_ZH.md"],
|
||
["en/plugins/daily-paper.md", "plugins/daily_paper/README.md"],
|
||
["zh/plugins/auto-fin.md", "plugins/auto-fin/README_ZH.md"],
|
||
["en/plugins/auto-fin.md", "plugins/auto-fin/README.md"],
|
||
["zh/plugins/lme.md", "plugins/lme/README_ZH.md"],
|
||
["en/plugins/lme.md", "plugins/lme/README.md"],
|
||
["zh/plugins/beam.md", "plugins/beam/README_ZH.md"],
|
||
["en/plugins/beam.md", "plugins/beam/README.md"],
|
||
["zh/benchmarks/beam.md", "benchmark/beam/README_ZH.md"],
|
||
["en/benchmarks/beam.md", "benchmark/beam/README.md"],
|
||
["zh/benchmarks/longmemeval.md", "benchmark/longmemeval/README_ZH.md"],
|
||
["en/benchmarks/longmemeval.md", "benchmark/longmemeval/README.md"],
|
||
["zh/benchmarks/memlens.md", "benchmark/memlens/docs/zh/evaluation.md"],
|
||
["en/benchmarks/memlens.md", "benchmark/memlens/docs/en/evaluation.md"],
|
||
["zh/benchmarks/mobilemem.md", "benchmark/mobilemem/docs/zh/evaluation.md"],
|
||
["en/benchmarks/mobilemem.md", "benchmark/mobilemem/docs/en/evaluation.md"],
|
||
["zh/benchmarks/pibench.md", "benchmark/pibench/README_ZH.md"],
|
||
["en/benchmarks/pibench.md", "benchmark/pibench/README.md"],
|
||
["zh/benchmarks/toolmemory.md", "benchmark/toolmemory/README_ZH.md"],
|
||
["en/benchmarks/toolmemory.md", "benchmark/toolmemory/README.md"],
|
||
];
|
||
|
||
const externalDocumentRewrites = {
|
||
"README.md": [
|
||
['href="./LICENSE"', 'href="https://github.com/agentscope-ai/ReMe/blob/main/LICENSE"'],
|
||
['href="./README.md"', 'href="/en/overview"'],
|
||
['href="./README_ZH.md"', 'href="/zh/overview"'],
|
||
['src="docs/figure/', 'src="../figure/'],
|
||
["(docs/en/", "(./"],
|
||
],
|
||
"README_ZH.md": [
|
||
['href="./LICENSE"', 'href="https://github.com/agentscope-ai/ReMe/blob/main/LICENSE"'],
|
||
['href="./README.md"', 'href="/en/overview"'],
|
||
['href="./README_ZH.md"', 'href="/zh/overview"'],
|
||
['src="docs/figure/', 'src="../figure/'],
|
||
["(docs/zh/", "(./"],
|
||
],
|
||
"integrations/claude_code/README.md": [
|
||
["(./README_ZH.md)", "(/zh/integrations/claude-code)"],
|
||
],
|
||
"integrations/claude_code/README_ZH.md": [
|
||
["(./README.md)", "(/en/integrations/claude-code)"],
|
||
],
|
||
"integrations/codex/README.md": [
|
||
["(./README_ZH.md)", "(/zh/integrations/codex)"],
|
||
["(../../docs/en/configuration.md)", "(/en/configuration)"],
|
||
["(./figures/README.md)", "(https://github.com/agentscope-ai/ReMe/blob/main/integrations/codex/figures/README.md)"],
|
||
["(./figures/", "(/figures/codex/"],
|
||
],
|
||
"integrations/codex/README_ZH.md": [
|
||
["(./README.md)", "(/en/integrations/codex)"],
|
||
["(../../docs/zh/configuration.md)", "(/zh/configuration)"],
|
||
["(./figures/README.md)", "(https://github.com/agentscope-ai/ReMe/blob/main/integrations/codex/figures/README.md)"],
|
||
["(./figures/", "(/figures/codex/"],
|
||
],
|
||
"integrations/qoder/README.md": [
|
||
["(./README_ZH.md)", "(/zh/integrations/qoder)"],
|
||
],
|
||
"integrations/qoder/README_ZH.md": [
|
||
["(./README.md)", "(/en/integrations/qoder)"],
|
||
],
|
||
"integrations/zcode/README.md": [
|
||
["(./README_ZH.md)", "(/zh/integrations/zcode)"],
|
||
],
|
||
"integrations/zcode/README_ZH.md": [
|
||
["(./README.md)", "(/en/integrations/zcode)"],
|
||
],
|
||
"integrations/dsh/README.md": [
|
||
["(./README_ZH.md)", "(/zh/integrations/dsh)"],
|
||
["(./figures/", "(/figures/dsh/"],
|
||
],
|
||
"integrations/dsh/README_ZH.md": [
|
||
["(./figures/", "(/figures/dsh/"],
|
||
],
|
||
"integrations/openclaw/README.md": [
|
||
["(./README_ZH.md)", "(/zh/integrations/openclaw)"],
|
||
["(./figures/", "(/figures/openclaw/"],
|
||
],
|
||
"integrations/openclaw/README_ZH.md": [
|
||
["(./README.md)", "(/en/integrations/openclaw)"],
|
||
["(./figures/", "(/figures/openclaw/"],
|
||
],
|
||
"integrations/hermes_agent/README.md": [
|
||
["(README_ZH.md)", "(/zh/integrations/hermes)"],
|
||
["(figures/", "(/figures/hermes/"],
|
||
],
|
||
};
|
||
|
||
const externalDocumentPreambles = {
|
||
"README.md": "---\ntitle: ReMe Overview\ndescription: A local-first, self-evolving personal knowledge base for AI agents.\n---\n\n# ReMe Overview\n\n",
|
||
"README_ZH.md": "---\ntitle: ReMe 项目介绍\ndescription: 面向 AI Agent 的 local-first 自进化个人知识库。\n---\n\n# ReMe 项目介绍\n\n",
|
||
};
|
||
|
||
const groupNames = {
|
||
zh: {
|
||
system: "系统与诊断",
|
||
memory: "记忆演化",
|
||
retrieval: "检索与图谱",
|
||
daily: "Daily Note",
|
||
files: "文件操作",
|
||
},
|
||
en: {
|
||
system: "System and diagnostics",
|
||
memory: "Memory evolution",
|
||
retrieval: "Retrieval and graph",
|
||
daily: "Daily notes",
|
||
files: "File operations",
|
||
},
|
||
};
|
||
|
||
const jobGroups = {
|
||
version: "system",
|
||
app_config: "system",
|
||
chat: "system",
|
||
health_check: "system",
|
||
status: "system",
|
||
help: "system",
|
||
auto_dream: "memory",
|
||
auto_memory: "memory",
|
||
auto_memory_cc: "memory",
|
||
auto_resource: "memory",
|
||
proactive: "memory",
|
||
traverse: "retrieval",
|
||
graph_snapshot: "retrieval",
|
||
reindex: "retrieval",
|
||
search: "retrieval",
|
||
node_search: "retrieval",
|
||
daily_list: "daily",
|
||
daily_reindex: "daily",
|
||
daily_write: "daily",
|
||
frontmatter_delete: "files",
|
||
frontmatter_read: "files",
|
||
frontmatter_update: "files",
|
||
stat: "files",
|
||
list: "files",
|
||
move: "files",
|
||
delete: "files",
|
||
read: "files",
|
||
load: "files",
|
||
read_image: "files",
|
||
write: "files",
|
||
save: "files",
|
||
edit: "files",
|
||
};
|
||
|
||
function typeLabel(schema = {}) {
|
||
if (schema.oneOf) return schema.oneOf.map(typeLabel).join(" or ");
|
||
if (schema.type === "array") return `${typeLabel(schema.items || {})}[]`;
|
||
return schema.type || "any";
|
||
}
|
||
|
||
function markdownCell(value) {
|
||
if (value === undefined) return "—";
|
||
const rendered = typeof value === "string" ? value : JSON.stringify(value);
|
||
return rendered
|
||
.replaceAll("<", "<")
|
||
.replaceAll(">", ">")
|
||
.replaceAll("|", "\\|")
|
||
.replaceAll("\n", " ");
|
||
}
|
||
|
||
function buildJobReference(config, language) {
|
||
const isZh = language === "zh";
|
||
const jobs = Object.entries(config.jobs || {}).filter(([, job]) => !["background", "cron"].includes(job.backend));
|
||
const sections = new Map();
|
||
|
||
for (const [name, job] of jobs) {
|
||
const group = jobGroups[name] || "system";
|
||
if (!sections.has(group)) sections.set(group, []);
|
||
sections.get(group).push([name, job]);
|
||
}
|
||
|
||
const lines = [
|
||
"---",
|
||
`title: ${isZh ? "Job API 参考" : "Job API Reference"}`,
|
||
`description: ${isZh ? "从默认配置自动生成的可调用 Job、参数和服务边界。" : "Callable jobs, parameters, and service boundaries generated from the default configuration."}`,
|
||
"---",
|
||
"",
|
||
`# ${isZh ? "Job API 参考" : "Job API Reference"}`,
|
||
"",
|
||
isZh
|
||
? "本页从 `reme/config/default.yaml` 自动生成。它描述默认应用中的可调用 Job;插件和自定义配置可以增加、删除或覆盖 Job。运行 `reme help` 可查看当前服务的实际能力。"
|
||
: "This page is generated from `reme/config/default.yaml`. It describes callable jobs in the default application; plugins and custom configurations may add, remove, or override jobs. Run `reme help` to inspect the active service.",
|
||
"",
|
||
isZh
|
||
? "> 后台 Job 和 Cron Job 不通过服务暴露,因此不列入调用参考。"
|
||
: "> Background and cron jobs are not service-exposed and are omitted from the callable reference.",
|
||
"",
|
||
];
|
||
|
||
for (const [group, entries] of sections) {
|
||
lines.push(`## ${groupNames[language][group]}`, "");
|
||
for (const [name, job] of entries) {
|
||
const properties = job.parameters?.properties || {};
|
||
const required = new Set(job.parameters?.required || []);
|
||
lines.push(`### \`${name}\``, "", markdownCell(job.description || ""), "");
|
||
lines.push("```bash", `reme ${name}${Object.keys(properties).length ? " ..." : ""}`, "```", "");
|
||
if (!Object.keys(properties).length) {
|
||
lines.push(isZh ? "无参数。" : "No parameters.", "");
|
||
continue;
|
||
}
|
||
lines.push(
|
||
isZh
|
||
? "| 参数 | 类型 | 必填 | 默认值 | 说明 |"
|
||
: "| Parameter | Type | Required | Default | Description |",
|
||
"|---|---|---:|---|---|",
|
||
);
|
||
for (const [parameter, schema] of Object.entries(properties)) {
|
||
lines.push(
|
||
`| \`${parameter}\` | \`${markdownCell(typeLabel(schema))}\` | ${required.has(parameter) ? (isZh ? "是" : "yes") : (isZh ? "否" : "no")} | ${markdownCell(schema.default)} | ${markdownCell(schema.description || "—")} |`,
|
||
);
|
||
}
|
||
lines.push("");
|
||
}
|
||
}
|
||
return `${lines.join("\n")}\n`;
|
||
}
|
||
|
||
await rm(path.join(siteDir, ".generated"), { recursive: true, force: true });
|
||
await mkdir(outputDir, { recursive: true });
|
||
await cp(path.join(repoDir, "docs"), outputDir, {
|
||
recursive: true,
|
||
filter: (source) => ![".DS_Store", "plans"].includes(path.basename(source)),
|
||
});
|
||
await cp(path.join(siteDir, "public", "CNAME"), path.join(outputDir, "public", "CNAME"));
|
||
await cp(path.join(siteDir, "public", "ecosystem"), path.join(outputDir, "public", "ecosystem"), {
|
||
recursive: true,
|
||
});
|
||
await cp(path.join(repoDir, "docs/figure/reme-icon.svg"), path.join(outputDir, "public", "reme-icon.svg"));
|
||
await cp(path.join(repoDir, "docs/figure/reme-logo-fashion.svg"), path.join(outputDir, "public", "reme-logo.svg"));
|
||
|
||
const sourceMap = {};
|
||
for (const [destination, source] of externalDocuments) {
|
||
const destinationPath = path.join(outputDir, destination);
|
||
await mkdir(path.dirname(destinationPath), { recursive: true });
|
||
let content = await readFile(path.join(repoDir, source), "utf8");
|
||
for (const [from, to] of externalDocumentRewrites[source] || []) content = content.replaceAll(from, to);
|
||
content = `${externalDocumentPreambles[source] || ""}${content}`;
|
||
await writeFile(destinationPath, content);
|
||
sourceMap[destination] = source;
|
||
}
|
||
|
||
for (const language of ["zh", "en"]) {
|
||
const destination = `${language}/memlens_256k_evaluation.md`;
|
||
const title = language === "zh" ? "MemLens-256K 评测说明已迁移" : "MemLens-256K Evaluation Notes Have Moved";
|
||
const script = 'window.location.replace("./benchmarks/memlens" + window.location.hash);';
|
||
await writeFile(path.join(outputDir, destination), [
|
||
"---",
|
||
`title: ${title}`,
|
||
"sidebar: false",
|
||
"head:",
|
||
" - [meta, {name: robots, content: noindex}]",
|
||
` - [script, {}, ${JSON.stringify(script)}]`,
|
||
"---",
|
||
"",
|
||
`# ${title}`,
|
||
"",
|
||
"[MemLens-256K](./benchmarks/memlens.md)",
|
||
"",
|
||
].join("\n"));
|
||
sourceMap[destination] = "github-pages/scripts/generate-content.mjs";
|
||
}
|
||
|
||
await cp(path.join(repoDir, "benchmark/memlens/docs/figure"), path.join(outputDir, "public/figures/benchmarks/memlens"), {
|
||
recursive: true,
|
||
});
|
||
|
||
await cp(path.join(repoDir, "integrations/codex/figures"), path.join(outputDir, "public/figures/codex"), {
|
||
recursive: true,
|
||
filter: (source) => !source.endsWith(".md"),
|
||
});
|
||
await cp(path.join(repoDir, "integrations/dsh/figures"), path.join(outputDir, "public/figures/dsh"), {
|
||
recursive: true,
|
||
});
|
||
await cp(path.join(repoDir, "integrations/openclaw/figures"), path.join(outputDir, "public/figures/openclaw"), {
|
||
recursive: true,
|
||
});
|
||
await cp(path.join(repoDir, "integrations/hermes_agent/figures"), path.join(outputDir, "public/figures/hermes"), {
|
||
recursive: true,
|
||
});
|
||
|
||
for (const language of ["zh", "en"]) {
|
||
await cp(
|
||
path.join(repoDir, "benchmark/toolmemory/gitcha.png"),
|
||
path.join(outputDir, language, "benchmarks", "gitcha.png"),
|
||
);
|
||
}
|
||
|
||
const defaultConfig = parseYaml(await readFile(path.join(repoDir, "reme/config/default.yaml"), "utf8"));
|
||
for (const language of ["zh", "en"]) {
|
||
const destination = path.join(outputDir, language, "reference", "jobs.md");
|
||
await mkdir(path.dirname(destination), { recursive: true });
|
||
await writeFile(destination, buildJobReference(defaultConfig, language));
|
||
sourceMap[`${language}/reference/jobs.md`] = "reme/config/default.yaml";
|
||
}
|
||
|
||
await writeFile(path.join(outputDir, ".source-map.json"), `${JSON.stringify(sourceMap, null, 2)}\n`);
|