From 18a4f1ad09a6c26166eee55989eb2efa95450c95 Mon Sep 17 00:00:00 2001 From: "jinli.yl" Date: Fri, 11 Sep 2026 11:51:56 +0800 Subject: [PATCH] fix(openclaw): secure status diagnostics --- integrations/openclaw/README.md | 11 +- integrations/openclaw/README_ZH.md | 11 +- integrations/openclaw/src/status-page.ts | 42 ++++--- integrations/openclaw/tests/openclaw.test.mjs | 105 ++++++++++++++++++ 4 files changed, 139 insertions(+), 30 deletions(-) diff --git a/integrations/openclaw/README.md b/integrations/openclaw/README.md index a312d069..f87a5051 100644 --- a/integrations/openclaw/README.md +++ b/integrations/openclaw/README.md @@ -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) diff --git a/integrations/openclaw/README_ZH.md b/integrations/openclaw/README_ZH.md index 50ccc725..907c3475 100644 --- a/integrations/openclaw/README_ZH.md +++ b/integrations/openclaw/README_ZH.md @@ -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) diff --git a/integrations/openclaw/src/status-page.ts b/integrations/openclaw/src/status-page.ts index 917cc977..ba05842b 100644 --- a/integrations/openclaw/src/status-page.ts +++ b/integrations/openclaw/src/status-page.ts @@ -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 + | 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 = ` :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}}
OpenClaw Memory Provider

ReMe

File-native memory, recall, and consolidation
Connecting…
-
ReMe service
{{health}}
Runtime phase
{{phase}}
Indexed documents
{{documents}}
Active sessions
{{sessions}}

Memory automation

1 · Prompt
Automatic recall
→
2 · Response
Turn capture
→
3 · Workspace
File-native memory

Connection

ReMe endpoint
{{endpoint}}
ReMe version
{{version}}
+
ReMe service
{{health}}
Runtime phase
{{phase}}
Indexed documents
{{documents}}
Active sessions
{{sessions}}

Memory automation

1 · Prompt
Automatic recall
→
2 · Response
Turn capture
→
3 · Workspace
File-native memory

Connection

ReMe endpoint
{{endpoint}}
ReMe version
{{version}}
Automatic capture
{{capture}}
Batch interval
{{interval}}
Queued turns
{{queued}}
Active sessions
{{sessions}}

Recent capture activity

{{activity}}
-
Auto Dream
{{dreamEnabled}}
Schedule
{{cron}}
Timezone
{{timezone}}
Last result
{{dreamResult}}

Next consolidation

{{nextDream}}

Auto Dream evolves daily notes into durable knowledge while workspace files remain the source of truth.

Operator verification

Use the authenticated status API or wait for the schedule, then reload this page to inspect the result.

+
Auto Dream
{{dreamEnabled}}
Schedule
{{cron}}
Timezone
{{timezone}}
Last result
{{dreamResult}}

Next consolidation

{{nextDream}}

Auto Dream evolves daily notes into durable knowledge while workspace files remain the source of truth.

Operator verification

Wait for the configured schedule, then reload this page and inspect the ReMe workspace digest.

ReMe component health

{{components}}
`; @@ -99,7 +102,12 @@ function renderStatusHtml( | undefined) || {}; const documents = components.file_store?.default?.n_chunks ?? "—"; const values: Record = { - 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 `
${escapeHtml( group.replaceAll("_", " "), - )} · ${escapeHtml(name)}${ - details.is_started === false ? "Stopped" : "Healthy" - }
${summary}
`; + )} · ${escapeHtml(name)}${healthLabel}
${summary}
`; }); }, ); diff --git a/integrations/openclaw/tests/openclaw.test.mjs b/integrations/openclaw/tests/openclaw.test.mjs index d10f3ba8..fd679a80 100644 --- a/integrations/openclaw/tests/openclaw.test.mjs +++ b/integrations/openclaw/tests/openclaw.test.mjs @@ -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 = [];