fix(openclaw): secure status diagnostics

This commit is contained in:
jinli.yl 2026-09-11 11:51:56 +08:00
parent 2d035319e9
commit 18a4f1ad09
4 changed files with 139 additions and 30 deletions

View file

@ -180,14 +180,9 @@ Restore a larger interval after testing to reduce model calls.
### Auto Dream
Wait for `dreamCron`, or call the authenticated local operator endpoint to run one real consolidation:
```bash
curl -fsS -X POST http://127.0.0.1:18799/plugins/reme/status/api/dream \
-H 'Content-Type: application/json'
```
Reload **ReMe Memory → Memory Consolidation**, verify `Last result: completed`, and inspect the ReMe digest update.
Wait for `dreamCron`, then reload **ReMe Memory → Memory Consolidation**, verify `Last result: completed`, and inspect
the ReMe digest update. The plugin status route is read-only; memory consolidation runs only through the configured
scheduler.
![Completed Auto Dream run](./figures/auto-dream.png)

View file

@ -174,15 +174,8 @@ ReMe 后台任务完成,再在另一个全新会话中禁止工具并询问该
### Auto Dream
等待 `dreamCron`,或者在本机通过认证的运维端点执行一次真实整理:
```bash
curl -fsS -X POST http://127.0.0.1:18799/plugins/reme/status/api/dream \
-H 'Content-Type: application/json'
```
刷新 **ReMe Memory → Memory Consolidation**,确认 `Last result: completed`,并检查 ReMe workspace 中的 digest
变更。
等待 `dreamCron`,然后刷新 **ReMe Memory → Memory Consolidation**,确认 `Last result: completed`,并检查 ReMe
workspace 中的 digest 变更。插件状态路由保持只读;记忆整理只由已配置的调度器触发。
![已完成的 Auto Dream](./figures/auto-dream.png)

View file

@ -24,12 +24,11 @@ export function createReMeStatusHandler(options: StatusPageOptions) {
}
if (request.method === "GET" && pathname === `${STATUS_PATH}/api/status`) {
const payload = await statusPayload(options);
sendJson(response, payload.reme.connected ? 200 : 503, payload);
return;
}
if (request.method === "POST" && pathname === `${STATUS_PATH}/api/dream`) {
await options.runtime.runDream();
sendJson(response, 200, { runtime: options.runtime.snapshot() });
sendJson(
response,
payload.reme.connected && payload.reme.healthy ? 200 : 503,
payload,
);
return;
}
sendJson(response, 404, { error: "Not found" });
@ -41,11 +40,15 @@ async function statusPayload(options: StatusPageOptions) {
options.client.requestJob("health_check"),
options.client.requestJob("status"),
]);
const healthDetails = health.metadata?.health as
| Record<string, unknown>
| undefined;
return {
endpoint: options.config.endpoint,
runtime: options.runtime.snapshot(),
reme: {
connected: health.ok,
healthy: health.ok && healthDetails?.healthy === true,
health: health.metadata,
status: status.metadata,
error: health.error || status.error || "",
@ -81,9 +84,9 @@ const STATUS_HTML = `<!doctype html>
:root{color-scheme:dark;--bg:#0b0d12;--panel:#12151d;--panel2:#181c26;--line:#292e3b;--text:#f3f5f7;--muted:#979dab;--green:#63d4a3;--blue:#79a8ff;--amber:#f2be5c;--red:#ff7b86}*{box-sizing:border-box}body{margin:0;background:radial-gradient(circle at 80% -10%,#202c42 0,transparent 32%),var(--bg);color:var(--text);font:14px/1.5 Inter,ui-sans-serif,system-ui,-apple-system,sans-serif}.shell{max-width:1240px;margin:auto;padding:32px}.top{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:24px}.brand{display:flex;gap:14px;align-items:center}.logo{width:46px;height:46px;border-radius:14px;display:grid;place-items:center;background:linear-gradient(145deg,#678ff7,#725de3);box-shadow:0 8px 26px #506ddd44;font-size:22px}.eyebrow{font-size:11px;text-transform:uppercase;letter-spacing:.14em;color:var(--blue);font-weight:700}h1{font-size:26px;margin:1px 0 0}.sub{color:var(--muted);margin-top:3px}.status{display:flex;align-items:center;gap:8px;padding:8px 12px;border:1px solid var(--line);border-radius:99px;background:#10131a}.dot{width:8px;height:8px;border-radius:50%;background:var(--amber)}.dot.ok{background:var(--green);box-shadow:0 0 12px #63d4a377}.tabs{display:flex;gap:4px;border-bottom:1px solid var(--line);margin-bottom:22px}.tab{color:var(--muted);text-decoration:none;padding:11px 15px;font-weight:650;border-bottom:2px solid transparent}.view{display:none}.view:target{display:block}.shell:not(:has(.view:target)) #overview{display:block}.shell:not(:has(.view:target)) .tab:first-child,body:has(#overview:target) a[href="#overview"],body:has(#memory:target) a[href="#memory"],body:has(#dream:target) a[href="#dream"],body:has(#components:target) a[href="#components"]{color:var(--text);border-color:var(--blue)}.grid{display:grid;grid-template-columns:repeat(4,1fr);gap:14px}.card{background:linear-gradient(155deg,var(--panel2),var(--panel));border:1px solid var(--line);border-radius:14px;padding:18px;box-shadow:0 10px 35px #0002}.wide{grid-column:span 2}.full{grid-column:1/-1}.label{color:var(--muted);font-size:12px}.metric{font-size:25px;font-weight:720;margin-top:6px}.metric.small{font-size:15px;word-break:break-all}.good{color:var(--green)}.warn{color:var(--amber)}.bad{color:var(--red)}h2{font-size:15px;margin:0 0 14px}.flow{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.step{background:#0d1017;border:1px solid var(--line);border-radius:10px;padding:12px 15px;min-width:145px}.arrow{color:#596172}.rows{display:grid;gap:8px}.row{display:grid;grid-template-columns:1.3fr .8fr .8fr 1fr;gap:12px;align-items:center;padding:10px 12px;background:#0e1118;border:1px solid #242936;border-radius:9px}.pill{display:inline-flex;width:max-content;padding:3px 8px;border-radius:99px;background:#25382f;color:var(--green);font-size:11px;font-weight:700}.pill.failed{background:#40262c;color:var(--red)}.pill.running{background:#3c3526;color:var(--amber)}.empty{color:var(--muted);padding:20px 0}.component-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:10px}.component{padding:13px;background:#0e1118;border:1px solid var(--line);border-radius:10px}.component strong{display:block;margin-bottom:3px}.footer{margin-top:22px;color:#747b89;font-size:12px}@media(max-width:850px){.grid{grid-template-columns:1fr 1fr}.wide{grid-column:span 2}.component-grid{grid-template-columns:1fr 1fr}}@media(max-width:560px){.shell{padding:20px}.grid{grid-template-columns:1fr}.wide,.full{grid-column:span 1}.top{gap:15px;flex-direction:column}.tabs{overflow:auto}.row{grid-template-columns:1fr 1fr}}
</style></head><body><main class="shell"><header class="top"><div class="brand"><div class="logo">◈</div><div><div class="eyebrow">OpenClaw Memory Provider</div><h1>ReMe</h1><div class="sub">File-native memory, recall, and consolidation</div></div></div><div class="status"><span class="dot" id="dot"></span><span id="connection">Connecting…</span></div></header>
<nav class="tabs"><a class="tab" href="#overview">Overview</a><a class="tab" href="#memory">Auto Memory</a><a class="tab" href="#dream">Memory Consolidation</a><a class="tab" href="#components">Components</a></nav>
<section class="view" id="overview"><div class="grid"><article class="card"><div class="label">ReMe service</div><div class="metric good">{{health}}</div></article><article class="card"><div class="label">Runtime phase</div><div class="metric">{{phase}}</div></article><article class="card"><div class="label">Indexed documents</div><div class="metric">{{documents}}</div></article><article class="card"><div class="label">Active sessions</div><div class="metric">{{sessions}}</div></article><article class="card wide"><h2>Memory automation</h2><div class="flow"><div class="step"><div class="label">1 · Prompt</div>Automatic recall</div><span class="arrow">→</span><div class="step"><div class="label">2 · Response</div>Turn capture</div><span class="arrow">→</span><div class="step"><div class="label">3 · Workspace</div>File-native memory</div></div></article><article class="card wide"><h2>Connection</h2><div class="label">ReMe endpoint</div><div class="metric small">{{endpoint}}</div><div class="label" style="margin-top:14px">ReMe version</div><div>{{version}}</div></article></div></section>
<section class="view" id="overview"><div class="grid"><article class="card"><div class="label">ReMe service</div><div class="metric {{healthClass}}">{{health}}</div></article><article class="card"><div class="label">Runtime phase</div><div class="metric">{{phase}}</div></article><article class="card"><div class="label">Indexed documents</div><div class="metric">{{documents}}</div></article><article class="card"><div class="label">Active sessions</div><div class="metric">{{sessions}}</div></article><article class="card wide"><h2>Memory automation</h2><div class="flow"><div class="step"><div class="label">1 · Prompt</div>Automatic recall</div><span class="arrow">→</span><div class="step"><div class="label">2 · Response</div>Turn capture</div><span class="arrow">→</span><div class="step"><div class="label">3 · Workspace</div>File-native memory</div></div></article><article class="card wide"><h2>Connection</h2><div class="label">ReMe endpoint</div><div class="metric small">{{endpoint}}</div><div class="label" style="margin-top:14px">ReMe version</div><div>{{version}}</div></article></div></section>
<section class="view" id="memory"><div class="grid"><article class="card"><div class="label">Automatic capture</div><div class="metric">{{capture}}</div></article><article class="card"><div class="label">Batch interval</div><div class="metric">{{interval}}</div></article><article class="card"><div class="label">Queued turns</div><div class="metric">{{queued}}</div></article><article class="card"><div class="label">Active sessions</div><div class="metric">{{sessions}}</div></article><article class="card full"><h2>Recent capture activity</h2><div class="rows">{{activity}}</div></article></div></section>
<section class="view" id="dream"><div class="grid"><article class="card"><div class="label">Auto Dream</div><div class="metric">{{dreamEnabled}}</div></article><article class="card"><div class="label">Schedule</div><div class="metric small">{{cron}}</div></article><article class="card"><div class="label">Timezone</div><div class="metric small">{{timezone}}</div></article><article class="card"><div class="label">Last result</div><div class="metric small">{{dreamResult}}</div></article><article class="card wide"><h2>Next consolidation</h2><div class="metric small">{{nextDream}}</div><p class="sub">Auto Dream evolves daily notes into durable knowledge while workspace files remain the source of truth.</p></article><article class="card wide"><h2>Operator verification</h2><p class="sub">Use the authenticated status API or wait for the schedule, then reload this page to inspect the result.</p></article></div></section>
<section class="view" id="dream"><div class="grid"><article class="card"><div class="label">Auto Dream</div><div class="metric">{{dreamEnabled}}</div></article><article class="card"><div class="label">Schedule</div><div class="metric small">{{cron}}</div></article><article class="card"><div class="label">Timezone</div><div class="metric small">{{timezone}}</div></article><article class="card"><div class="label">Last result</div><div class="metric small">{{dreamResult}}</div></article><article class="card wide"><h2>Next consolidation</h2><div class="metric small">{{nextDream}}</div><p class="sub">Auto Dream evolves daily notes into durable knowledge while workspace files remain the source of truth.</p></article><article class="card wide"><h2>Operator verification</h2><p class="sub">Wait for the configured schedule, then reload this page and inspect the ReMe workspace digest.</p></article></div></section>
<section class="view" id="components"><article class="card"><h2>ReMe component health</h2><div class="component-grid">{{components}}</div></article></section><div class="footer">Live diagnostics are served through OpenClaw's authenticated plugin route. No model credentials are exposed.</div></main>
</body></html>`;
@ -99,7 +102,12 @@ function renderStatusHtml(
| undefined) || {};
const documents = components.file_store?.default?.n_chunks ?? "—";
const values: Record<string, unknown> = {
health: payload.reme.connected ? "Healthy" : "Offline",
health: payload.reme.connected
? payload.reme.healthy
? "Healthy"
: "Unhealthy"
: "Offline",
healthClass: payload.reme.healthy ? "good" : "bad",
phase: payload.runtime.phase,
documents,
sessions: payload.runtime.autoMemory.activeSessions,
@ -157,8 +165,16 @@ function renderStatusHtml(
];
}
return instances.map(([name, details]) => {
const healthy =
details.is_started === true && details.is_healthy !== false;
const healthLabel =
details.is_started !== true
? "Stopped"
: healthy
? "Healthy"
: "Unhealthy";
const summary = Object.entries(details)
.filter(([key]) => key !== "is_started")
.filter(([key]) => !["is_started", "is_healthy"].includes(key))
.slice(0, 2)
.map(
([key, value]) =>
@ -169,9 +185,9 @@ function renderStatusHtml(
.join(" · ");
return `<div class="component"><strong>${escapeHtml(
group.replaceAll("_", " "),
)} · ${escapeHtml(name)}</strong><span class="good">${
details.is_started === false ? "Stopped" : "Healthy"
}</span><div class="label">${summary}</div></div>`;
)} · ${escapeHtml(name)}</strong><span class="${
healthy ? "good" : "bad"
}">${healthLabel}</span><div class="label">${summary}</div></div>`;
});
},
);

View file

@ -10,6 +10,21 @@ import plugin, {
openClawSessionId,
resolveOpenClawConfig,
} from "../dist/index.js";
import { createReMeStatusHandler } from "../dist/status-page.js";
function responseRecorder() {
return {
body: "",
headers: new Map(),
statusCode: 0,
setHeader(name, value) {
this.headers.set(name, value);
},
end(body = "") {
this.body = String(body);
},
};
}
test("normalizes OpenClaw configuration and stable session ids", () => {
const config = resolveOpenClawConfig(
@ -215,6 +230,96 @@ test("runs one coalesced OpenClaw Auto Dream task", async () => {
await runtime.disposeAll();
});
test("keeps status routes read-only and reports unhealthy components", async () => {
let dreamCalls = 0;
const runtime = {
async runDream() {
dreamCalls += 1;
},
snapshot() {
return {
phase: "running",
autoMemory: {
enabled: true,
interval: 5,
activeSessions: 0,
queuedTurns: 0,
recentActivity: [],
},
autoDream: {
enabled: true,
cron: "0 23 * * *",
timezone: "Asia/Shanghai",
running: false,
},
};
},
};
const handler = createReMeStatusHandler({
config: resolveOpenClawConfig({}, {}),
runtime,
client: {
async requestJob(job) {
if (job === "health_check") {
return {
ok: true,
metadata: {
health: {
healthy: false,
version: "test",
components: {
embedding_store: {
default: { is_started: true, is_healthy: false },
},
},
},
},
};
}
return { ok: true, metadata: { status: {} } };
},
},
});
const statusResponse = responseRecorder();
await handler(
{ method: "GET", url: "/plugins/reme/status/api/status" },
statusResponse,
);
assert.equal(statusResponse.statusCode, 503);
assert.deepEqual(JSON.parse(statusResponse.body).reme, {
connected: true,
healthy: false,
health: {
health: {
healthy: false,
version: "test",
components: {
embedding_store: {
default: { is_started: true, is_healthy: false },
},
},
},
},
status: { status: {} },
error: "",
});
const pageResponse = responseRecorder();
await handler({ method: "GET", url: "/plugins/reme/status" }, pageResponse);
assert.equal(pageResponse.statusCode, 200);
assert.match(pageResponse.body, /class="metric bad">Unhealthy/);
assert.match(pageResponse.body, /class="bad">Unhealthy/);
const writeResponse = responseRecorder();
await handler(
{ method: "POST", url: "/plugins/reme/status/api/dream" },
writeResponse,
);
assert.equal(writeResponse.statusCode, 404);
assert.equal(dreamCalls, 0);
});
test("registers OpenClaw recall, capture, tool, and shutdown lifecycle", async () => {
const originalFetch = globalThis.fetch;
const calls = [];