Skip to content

Commit 6a9fd3b

Browse files
committed
feat(panel): 热力右侧补上 8 周沉淀图,新增 vs 巩固两根柱
状态页的 .mneme-tokenflow 里三块图各自占整行,热力 745px 之外空着约 220px。 把热力与新的沉淀图并成两列(窄容器回落单列),并给后者一条自己的数据源。 口径三件,都不许复用现成的东西: - 不用 dream_runs.applied:degraded 轮里它也是非零(11-03 两轮 14、16,当日 receipt_chain 只有 19 行),拿它当「今天沉淀了多少」会把失败轮算成成果。 逐条真源只有 receipt_chain 的 kind IN (merge,update) AND verdict='live'。 - merged 按 record_id 去重,不是数行数:同一条记录被多轮合并会重复记账 (56 天窗口 2412 行只对应 1796 个记录),数行数会把反复合并同一批显示成 大量巩固,恰好抹掉要看的那道剪刀差。 - added 排掉 source='imported'(别人导入的原文不是本库长出来的),谓词写 (source IS NULL OR source <> ?)——本方行 source 为 NULL,只写 <> 会因三值 逻辑把整批本地行一起丢掉。 前端未到(null)与已知为空({})分开:前者不画柱也不画图例,否则加载态先画 8 根零高柱子再「长出来」。days 缺省 56(与热力同窗),钳 1..365。 新路由 policy=open,SECURITY.md 中英两张表同步;两根柱的颜色进 contrast.test.js 的 GRAPHICS 表按 3:1 审。 验证:npm test 2719 tests / 2718 pass / 0 fail / 1 skipped;check-sync 85 文件 一致。变异自证六处全部变红(merged 退回数行数、去掉 imported 排除、 null 二分改成 []、删 @container 回落、全零空态改 false、柱子色改回宿主 label token)。
1 parent 2a5e72b commit 6a9fd3b

13 files changed

Lines changed: 500 additions & 24 deletions

File tree

‎SECURITY.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ The token is a lock on the **write** surface, not a wall around the whole API.
153153

154154
- **The real boundary is loopback + the DSH host listener.** The host-side routes (`/api/dsh-mneme/*`) are mounted on the DSH port, which binds `127.0.0.1` and is fenced by the host against DNS rebinding and cross-site browser requests. That fence does **not** establish identity: any local process, and any page running in the host's own origin, is inside the perimeter.
155155
- **Authentication is opt-in and fail-open.** `apiToken` defaults to empty; while it is empty, `isAuthorized()` returns true for every request — reads *and* writes. Setting a token gates the write routes and the sensitive reads; it does not gate plain reads.
156-
- **Open reads (no token even when one is configured)**: `GET /`, `/info`, `/version-check`, `/list`, `/recall-stats`, `/search`, `/semantic`, `/semantic/llm-audit`, `/semantic/llm-audit/stats`, `/semantic/graph/*`, `/entities`, `/memories/entities`, `/dream-status`, `/inject-status`, `/inject-preview`, `/pipeline`, `/candidates`, `/llm-providers`, `/config-keys`, plus the `GET`/`HEAD` branches of `/profile`, `/rules`, `/persona`, `/mode`, `/features`, `/commands`, `/nudge`, and of the two share-receive routes `/receive` and `/receive/undo`. Treat them as readable by anything local. `/receive` and `/receive/undo` belong on this list even though they write: under the `token-write` policy, `needsToken()` exempts `GET`/`HEAD` from the token, so the only thing genuinely open on those two paths is a `405` — no read branch exists. This section mirrors the policy declarations rather than anyone's intent, which is why a write route shows up under "open reads"; `dsh-mneme/test/security-doc.test.js` compares both lists against the routes actually mounted, in both directions.
156+
- **Open reads (no token even when one is configured)**: `GET /`, `/info`, `/version-check`, `/list`, `/recall-stats`, `/search`, `/semantic`, `/semantic/llm-audit`, `/semantic/llm-audit/stats`, `/semantic/consolidation-stats`, `/semantic/graph/*`, `/entities`, `/memories/entities`, `/dream-status`, `/inject-status`, `/inject-preview`, `/pipeline`, `/candidates`, `/llm-providers`, `/config-keys`, plus the `GET`/`HEAD` branches of `/profile`, `/rules`, `/persona`, `/mode`, `/features`, `/commands`, `/nudge`, and of the two share-receive routes `/receive` and `/receive/undo`. Treat them as readable by anything local. `/receive` and `/receive/undo` belong on this list even though they write: under the `token-write` policy, `needsToken()` exempts `GET`/`HEAD` from the token, so the only thing genuinely open on those two paths is a `405` — no read branch exists. This section mirrors the policy declarations rather than anyone's intent, which is why a write route shows up under "open reads"; `dsh-mneme/test/security-doc.test.js` compares both lists against the routes actually mounted, in both directions.
157157
- **Gated routes (when a token is configured)**: every write — `/create`, `/update`, `/delete`, `/import`, `/bootstrap`, `/vector-config`, `/vector-reindex`, `/runtime/provision`, `/maintenance/reclaim`, `/test-model`, `/conflicts/resolve`, `/profile/extract` (POST-only: one host-LLM call that returns a profile **draft**; other methods get 405 before any side effect), `/receive`, `/receive/undo` (the two share-receive routes write into *this* machine's library, which is why they are `token-write`), and the non-`GET` branches of `/profile`, `/rules`, `/persona`, `/mode`, `/features`, `/commands`, `/nudge` — plus six reads: `/export`, `/external-api`, `/conflicts`, `/health`, `/share`, `/memory/provenance`. `/share` is gated because the share pack is a whole-library read delivered over POST, and it answers 405 to GET — no open read path exists. `/memory/provenance` is gated because it returns the **verbatim raw text** of distilled conversation windows (opt-in via `distillRecords.enabled`); chained with the open list route it would otherwise let any local process enumerate ids and then pull that text back, which reaches the same result as `/export` in a different shape.
158158
- **The standalone data plane** (`127.0.0.1:8790`) is the opposite shape: every route except `GET /health` requires its own Bearer token. Pointing `externalApiHost` at a non-loopback address therefore turns it into a plaintext, token-only HTTP surface — an explicit operator decision.
159159
- **Consequence**: if you expose the plugin beyond loopback (reverse proxy, non-loopback bind), set `apiToken` *and* check that the plain reads above are acceptable to expose — they are not covered by it.
@@ -539,7 +539,7 @@ Token 是**写**面上的锁,不是把整个 API 围起来的墙。
539539

540540
- **真正的边界是回环 + 宿主监听器。** 宿主侧路由(`/api/dsh-mneme/*`)挂在 DSH 端口上,该端口绑 `127.0.0.1`,并由宿主挡掉 DNS rebinding 与跨站浏览器请求。这道围栏**不建立身份**:任何本地进程、以及任何跑在宿主同源页面里的脚本,都在这道围栏之内。
541541
- **鉴权是 opt-in 且 fail-open。** `apiToken` 默认为空;为空期间 `isAuthorized()` 对每个请求都返回 true——读和写都放行。配了 token 之后,它守的是写路由与敏感读,不守普通读。
542-
- **开放读(即使配了 token 也不需要)**:`GET /`、`/info`、`/version-check`、`/list`、`/recall-stats`、`/search`、`/semantic`、`/semantic/llm-audit`、`/semantic/llm-audit/stats`、`/semantic/graph/*`、`/entities`、`/memories/entities`、`/dream-status`、`/inject-status`、`/inject-preview`、`/pipeline`、`/candidates`、`/llm-providers`、`/config-keys`,以及 `/profile`、`/rules`、`/persona`、`/mode`、`/features`、`/commands`、`/nudge`、`/receive`、`/receive/undo` 的 `GET`/`HEAD` 分支。把它们当作「本地任何东西都能读」。`/receive`、`/receive/undo` 明明是写路由也出现在这一串里,这不是笔误:`token-write` 下 `needsToken()` 对 `GET`/`HEAD` 免 token,所以这两条路径上真正「开放」的只有一个 `405`,压根没有可读分支。这一节照 policy 声明抄、不照意图写,`dsh-mneme/test/security-doc.test.js` 会拿真实装配出来的路由双向比对这两行。
542+
- **开放读(即使配了 token 也不需要)**:`GET /`、`/info`、`/version-check`、`/list`、`/recall-stats`、`/search`、`/semantic`、`/semantic/llm-audit`、`/semantic/llm-audit/stats`、`/semantic/consolidation-stats`、`/semantic/graph/*`、`/entities`、`/memories/entities`、`/dream-status`、`/inject-status`、`/inject-preview`、`/pipeline`、`/candidates`、`/llm-providers`、`/config-keys`,以及 `/profile`、`/rules`、`/persona`、`/mode`、`/features`、`/commands`、`/nudge`、`/receive`、`/receive/undo` 的 `GET`/`HEAD` 分支。把它们当作「本地任何东西都能读」。`/receive`、`/receive/undo` 明明是写路由也出现在这一串里,这不是笔误:`token-write` 下 `needsToken()` 对 `GET`/`HEAD` 免 token,所以这两条路径上真正「开放」的只有一个 `405`,压根没有可读分支。这一节照 policy 声明抄、不照意图写,`dsh-mneme/test/security-doc.test.js` 会拿真实装配出来的路由双向比对这两行。
543543
- **受门控的路由(配了 token 之后)**:全部写操作——`/create`、`/update`、`/delete`、`/import`、`/bootstrap`、`/vector-config`、`/vector-reindex`、`/runtime/provision`、`/maintenance/reclaim`、`/test-model`、`/conflicts/resolve`、`/profile/extract`(只收 POST:花一次宿主 LLM 产一段画像**草稿**,其它方法在产生任何副作用之前就 405)、`/receive`、`/receive/undo`(这两条写的是**本机自己的库**,所以归 `token-write`),以及 `/profile`、`/rules`、`/persona`、`/mode`、`/features`、`/commands`、`/nudge` 的非 `GET` 分支——外加六条读:`/export`、`/external-api`、`/conflicts`、`/health`、`/share`(分享包是「用 POST 递出来的全库读取」,GET 一律 405,没有开放的读分支)、`/memory/provenance`(它回的是蒸馏窗口的**逐字会话原文**,并自 #512 起按窗口带出 `distill_run_id` / `run_type` / `trigger_source` / `run_status` 的运行归因;`distillRecords.enabled` 打开才有;否则把它和上面那个开放的列表路由串起来,任何本地进程都能先枚举 id、再按 id 把那些原文捞回去——可达结果与 `/export`(一次拿全库)同量级,只是换了形状)。
544544
- **独立数据面**(`127.0.0.1:8790`)是反过来的形状:除 `GET /health` 外每条路由都要自己的 Bearer token。因此把 `externalApiHost` 指向非回环地址,就等于把它变成一个「明文、只靠 token」的 HTTP 面——这是运营者的显式决定。
545545
- **推论**:如果你把插件暴露到回环之外(反代、绑非回环地址),请设 `apiToken`,**并**核对上面那串开放读是否也能被看到——它们不受 token 保护。

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## [Unreleased]
44

5+
- **状态页热力右侧那块常年空着的 220px 补上「8 周沉淀」图:新增 vs 巩固两根柱并排、归档给总量(用户 2026-11-04 提的)**:热力图 56 格 × 11px 只有约 745px 宽,而这块容器可用宽 968px,右边一直空着——**空白不是某个空 div,是「三块图各自独占整行」造成的**,所以改的是布局(热力与沉淀并成两列,窄容器回落单列),而不是往某个槽里塞图。新图要回答的是面板此前答不了的那个问题:库是在巩固,还是只在膨胀。
6+
7+
- **口径不许复用 `dream_runs.applied`**:那一列在 degraded 轮里也是非零(实测 2026-11-03 两轮分别 14、16,而当日 receipt_chain 总共 19 行),拿它当「今天沉淀了多少」会把失败轮算成成果。逐条真源只有 `receipt_chain`:`kind IN ('merge','update') AND verdict='live'`。**这一条正是「跑了很多轮但看起来没沉淀」假象的来源**,也是这套图存在的理由。
8+
- **`merged` 按 record_id 去重,不是数行数**:同一条记录被多轮合并会重复记账(本机 56 天窗口 2412 行只对应 1796 个记录),数行数会把「反复合并同一批」显示成「大量巩固」,恰好抹掉要看的那道剪刀差。SQL 用子查询 `GROUP BY day, record_id` 再外层 `count(*)`,测试锁死这个口径(把 `GROUP BY day, record_id` 改成再加 `receipt_id` → 红)。
9+
- **`added` 必须排掉 `source = 'imported'`**:别人导入的原文不是本库长出来的,混进来会把导入量算成自己的产出。谓词写 `(source IS NULL OR source <> ?)`——本方行 `source` 为 NULL,只写 `<>` 会因三值逻辑把整批本地行一起丢掉;常量取 `src/memory-source.js` 的 `IMPORTED_SOURCE`,不硬编码字符串(变异:去掉这个谓词 → 红)。
10+
- **`archived` 用 `archived_at`,不是 `archived` 布尔**:那一列是「进入归档面那一刻」且幂等(重复归档不刷新、取消归档置 NULL),所以 `date(archived_at)` 日聚合正好是「当天新归档条数」。**归档面 10-12 之前恒为 0**,它不该和另外两条被当成长期对照读——所以这张图只画两根柱(新增 vs 巩固),归档数进图例给总量。
11+
- **不新建表、不落盘日报、不加 cron**:图是读时聚合,三条 SQL 各扫各的。766MB 活库实测 56 天窗口 49ms + 45ms + 2ms,可接受,不加索引。**「每天写一份日报」这个形态被否掉**,理由是它要么每次全量重算(等于把今天已经算过的东西再算一遍),要么追加写 JSONL——后者断电会粘连出半行,而面板要的是「现在库里长什么样」,不是一份历史存档。
12+
- **未到 / 已知为空必须分开**:`sinkStats === null` 时既不画柱也不画图例(否则加载态先画 8 根零高柱子再「长出来」,用户看到的是一次假抖动);`{}` 且三总量全 0 才画空态那句话。`days` 缺省 56(正好 8 周,与热力同窗),钳 1..365,`days=0` 回落缺省而不是钳到 1(与 `llm-audit/stats` 同一套写法,两条曲线对同一个参数给同样的窗口)。
13+
- **两根柱的颜色进图形锁**:柱高差就是结论本身(新增高、巩固矮 = 库在膨胀),掉回浅灰等于把结论擦掉。`.mneme-sinkbar--added` / `--merged` 用 `--mneme-chart-3` / `--mneme-chart-2`,并加进 `test/contrast.test.js` 的 GRAPHICS 表按 3:1 审(不引入任何新字面量色)。
14+
- **验证**:`npm test` 2719 tests / 2718 pass / 0 fail / 1 skipped;`check-sync` 85 文件一致。变异自证六处,全部当场变红:`merged` 退回数行数 → 红「同一 record_id 的两条 receipt 只能算 1 条巩固」;`added` 去掉 imported 排除 → 红;前端把 `if (!sinkStats) return null` 改成 `return []` → 红;删掉 `@container (max-width:960px)` 回落 → 红;把全零空态分支改成 `false` → 红;柱子改回 `--dsw-alias-label-tertiary` → 红(对比度锁 + 语义层锁双杀)。
15+
516
- **记忆库从「侧栏 footer 挤一个入口 + 居中浮层」改成宿主原生面板位:侧栏一颗图标进 `sidebar.panellist`,正文落 `main` 整页(参照 dsh-baleen,用户 2026-11-04 提的)**:此前唯一的完整入口是 `sidebar.footer.action`,点开是一个 `createPortal` 到 `document.body` 的居中浮层——它不是宿主的面板,占着屏幕中央却不参与宿主的布局与导航状态,Esc/焦点环/背板点击都得自己实现一遍,而截图里它看起来又很像「一个新窗口」。宿主早就给了成对的座位:`sidebar.panellist`(侧栏面板列表,list 槽)与 `main`(正文区,keyed 槽),侧栏一行的点击由宿主 `PanelRow` 自己调 `layout.selectPanel(id)`,插件只交一颗图标和一片内容。**main 的 `key` 必须与侧栏的 `id` 逐字相同**(两者都取 `dsh-mneme`)——宿主按 `options.key` 在 keyed 槽里找 entry,对不上会抛 `layout.selectPanel: main panel "…" is not registered`;这条不是防御性写作,是宿主 `layout.js` 里真会抛的那一行。
617

718
- **模板块只交「图标」和「页面」,不自己造按钮、不做关闭**:宿主 `PanelRow` 已经渲染了 `button` + `aria-label` + `Tooltip` + `aria-current` + active 高亮,插件再套一层按钮就是两颗可聚焦元素(Tab 停两次、读屏报两次),而 `onClick` 还得自己去 `selectPanel`——那是宿主自己的活。回到会话也不由我们提供:宿主所有「打开会话」的路径都走 `selectPanel(null)`(`workspace.js` 的 `openSession` / `openWorkspaceSession` 都是 `replaceMain(…, "reveal")`),baleen 的面板同样没有返回按钮。`main` 槽只给出 `min-width:0; overflow:hidden` 的容器,注册者必须自己铺满 `100%` 并自管滚动,所以外层新增 `.mneme-panel`。

‎dsh-mneme/README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ v0.3.0 起新增**记忆基因**层:从记忆里抽取**命名实体**、**带
247247
248248
> 只读端点,与 list/search/semantic 一样在设置 `apiToken` 后仍保持开放。
249249
250+
沉淀曲线(面板状态页「8 周沉淀」图的数据源):
251+
252+
- `GET /api/dsh-mneme/semantic/consolidation-stats?days=` — 近 N 天(缺省 56,钳 1–365)按天返回三条序列:`added`(新建记忆,排除外来导入行)、`merged`(当天被巩固掉的**去重记录数**,取自 `receipt_chain` 里 `kind∈(merge,update)` 且 `verdict='live'`)、`archived`(当天进入归档面的条数),另附三个窗口合计。
253+
254+
`merged` 刻意按去重 `record_id` 数而不是行数:同一条记录被多轮巩固重复记账是常态(活库实测 2412 行只对应 1796 个记录),按行数会把「又记了一遍」算成「又沉淀了一条」。新增与合并背离才是这张图要看的东西——2026-10-25–10-31 那段新增照旧、合并归零,只看新增或只看总量都发现不了。
255+
250256
### 记忆库主区视图与记忆图谱 🕸️(v0.5.0)
251257

252258
记忆功能从侧边栏抽屉收进**主内容区全宽 tab**(conversation.view 插槽,与「对话 / Trajectory」并列),侧边栏「记忆」入口点击后直接激活该 tab。页面顶部子 tab 行切换三个子视图:

‎dsh-mneme/lib/api.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,27 @@ export function createApi(ctx, service, settings, commands, embedder, semantic =
13121312
}
13131313
});
13141314

1315+
// 沉淀曲线(面板「8 周沉淀」图):按天返回 added / merged / archived 三条序列。
1316+
// 与 llm-audit/stats 并列但不同源——那边算的是「花了多少 token」,这边算的是
1317+
// 「进来了多少条、真被巩固掉多少条、归档了多少条」。合并数与新增数背离时
1318+
// (2026-10-25~10-31 那段:新增照旧、合并归零)这张图是唯一能一眼看出来的地方。
1319+
// 窗口钳制 1-365 天(缺省 56,正好是热力图的 8 周),口径见 store.getConsolidationStats。
1320+
register({
1321+
kind: "exact",
1322+
path: "/api/dsh-mneme/semantic/consolidation-stats",
1323+
policy: "open",
1324+
handler(req, res) {
1325+
try {
1326+
const url = new URL(req.url, "http://localhost");
1327+
const days = Math.max(1, Math.min(365, Number(url.searchParams.get("days") ?? 56) || 56));
1328+
const stats = service.getConsolidationStats?.({ days }) ?? null;
1329+
sendJson(res, 200, stats ?? { error: "unavailable" });
1330+
} catch {
1331+
sendJson(res, 500, { error: "internal" });
1332+
}
1333+
}
1334+
});
1335+
13151336
// --- 记忆级溯源读出口(#399 写、#421 读)-----------------------------------
13161337
// #399 把蒸馏窗口的原文落进 distill_records、把 memory → (session, seq 区间)
13171338
// 的归因写进 memory_provenance,但只做了写:库里有答案、service.provenanceFor

0 commit comments

Comments
 (0)