dsh-memu-memory 1.3.12 → 1.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +2 -2
- package/docs/contributing.md +14 -2
- package/docs/memory-semantics.md +2 -2
- package/docs/troubleshooting.md +61 -1
- package/lib/auto-link/candidates.js +10 -5
- package/lib/auto-link/terminology.js +34 -18
- package/lib/binding-diagnostics.js +2 -2
- package/lib/client.js +335 -36
- package/lib/cycle.js +41 -8
- package/lib/diagnostics.js +514 -0
- package/lib/environment-check.js +325 -0
- package/lib/graph.js +94 -21
- package/lib/index.js +70 -2
- package/lib/local-embedding-manager.js +39 -5
- package/lib/paths.js +153 -10
- package/lib/private.js +14 -2
- package/lib/rpc.js +34 -1
- package/lib/state.js +71 -2
- package/lib/tools.js +4 -20
- package/lib/vector-profile.js +302 -8
- package/lib/webui/graph-view.bundle.js +1 -1
- package/lib/webui/graph-view.js +1 -2
- package/lib/webui/standalone.js +2 -2
- package/package.json +1 -1
- package/tests/auto-link-candidates.test.mjs +71 -0
- package/tests/client-render.test.mjs +116 -3
- package/tests/cycle.test.mjs +158 -1
- package/tests/diagnostics.test.mjs +257 -0
- package/tests/environment-check.test.mjs +159 -0
- package/tests/graph-view.test.mjs +31 -3
- package/tests/graph.test.mjs +110 -0
- package/tests/tools.test.mjs +95 -0
- package/tests/webui-auth.test.mjs +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# 更新日志 / Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.14] - 2026-11-22
|
|
4
|
+
|
|
5
|
+
> 归档不再误伤在用的库:scope 不在 DSH 工作区注册表只说明"这不是工作区",不说明"没人用"。修掉"库被自动归档、绑定会话却继续读写 9 小时"的自相矛盾状态,并堵住它带来的误删风险。
|
|
6
|
+
|
|
7
|
+
- **归档判定补上"在用"这一半**(`lib/cycle.js` `runLibraryHousekeeping`):`lib/state.js` 新增 `inUseLibraryIds()` / `isLibraryInUse()`,按存活绑定(`sessionGone !== true`)判定;扫描对仍被会话绑定的库不再归档,并在返工结果里给出 `skippedInUse`,同一库只提示一次。外部报告的现场正是这条路径:IM 插件数据目录建库后 176 秒被归档,之后 9 小时 172 条活动、6 次召回全部成功,而 UI 里库已消失。
|
|
8
|
+
- **旧数据的收窄**:1.3.13 及更早的归档没有 `archivedBy`,事后分不清「用户点的归档」和「老扫描误归档」。所以对这类库只复活「还热」的(`lastUsedAt` 在 14 天内);冷归档保持归档——本机实测 `rp`(14 个绑定)与 `ai中转站`(4 个)正属后者。
|
|
9
|
+
- **误归档自愈**:`archiveLibrary(id, { by })` 记录归档来源(`sweep` / `user`)。扫描遇到「已归档但仍有存活绑定且不是用户归档」的库会就地复活(`revived`),不再要求 scope 回到工作区注册表——那条件对 `.dsh/im`、profile 目录这类路径永不满足。
|
|
10
|
+
- **用户意图优先**:`archivedBy === 'user'` 的归档不会被扫描复活;`ensureSession` 快路径对误归档库(非 user)就地复活,避免"已绑定会话继续读写归档库"的旧形态。
|
|
11
|
+
- **误删风险关掉**:`deleteLibrary(id, { force })` 只拒绝「危险归档 + 仍在用」这一类(扫描误归档 = `archivedWhileInUse`,与自愈共用同一判据);用户主动归档、以及冷数据的旧归档照旧可删,删不掉的老库不会出现。RPC 仅在 `confirmed` 时透传 `force`;`purgeArchivedAfterDays` 的清理候选排除在用库(此前只看年龄)。
|
|
12
|
+
- 守卫:`tests/cycle.test.mjs` 新增 9 条——在用库跨三轮 sweep 不归档且仍在列表、无人用的库照常归档且 `archivedBy='sweep'`、误归档在用库被复活、用户归档不被复活、冷/热两种旧归档的复活判据、purge 不把在用库列入候选、删除在用库被拒(解绑后放行)、快路径复活。
|
|
13
|
+
- 文档同步:`docs/troubleshooting.md` 新增 §3.46(症状/根因/守卫)与症状速查一行。
|
|
14
|
+
|
|
15
|
+
## [1.3.13] - 2026-11-21
|
|
16
|
+
|
|
17
|
+
> 诊断体系:插件内部故障有了自己的出口(诊断页 + 启动弹窗 + 自动/手动修复),并修掉三类会让召回静默降级的真实故障——摘要把镜像元数据算成"制品已变"、运行时目录失效、0 字节遗留锁永不自愈。
|
|
18
|
+
|
|
19
|
+
- **诊断存储(与活动日志分开)**:新增 `lib/diagnostics.js`,写 `diagnostics/events.jsonl`(2MB 轮转)+ `acknowledged.json`,内存环形 500 条;同 `(scope, code, message)` 60 秒内只累加 `count`;`detail` 统一脱敏。`KNOWN_CODES` 把故障码映射成「哪一层坏了 / 能不能自动修 / 修之前会不会丢数据」。
|
|
20
|
+
- **诊断页(设置 → 诊断,`#/settings/diagnostics`)**:上半张环境自检(数据目录、遗留锁、引擎、向量 profile、运行时、模型、worker),每项给证据与建议并配按钮(可自动修的给按钮,破坏性的标"需手动");下半张按 level/关键词过滤诊断记录,可整页复制。独立 WebUI 的 `PAGE_NAMES` 同步。
|
|
21
|
+
- **启动检查 + 主页弹窗**:启动 6 秒后跑一次自检,error/warn 项落诊断(`ENV_*`);主页顶部弹出提醒卡(`getDiagnosticAlerts`,最多 4 条按 code 汇总),点"稍后/打开诊断"即 `acknowledgeDiagnostics`,同一问题不再天天弹、再次发生才重新提醒。
|
|
22
|
+
- **修复:自动只做安全项**:`SAFE_REPAIRS`=释放可证明遗弃的锁(`release-stale-locks`)、重签摘要(`resign-vector-profile`)、重指运行时目录(`repoint-runtime-dir`),受 `autoInstallEngine` 开关约束;`MANUAL_REPAIRS`=重装运行时/模型、重建向量代际、重装引擎,只能手动、且 `confirmed === true`。每步无论成败都记 `MEMU_DIAGNOSTIC_REPAIRED` / `MEMU_DIAGNOSTIC_REPAIR_FAILED`。
|
|
23
|
+
- **锁加固**:`withFileLock` 载荷改成 `pid\nISO`(兼容旧的一行裸 pid),EEXIST 时先判定遗弃(无法解析且≥10s / 自身 pid 但无事务且≥10s / 死 pid 立即 / ≥60s 超龄),遗弃则就地释放重试并发 `MEMU_LOCK_BROKEN` 事件。真实事故:0 字节 `consolidation.json.lock` 里 `Number('')===0` 永不满足清理条件,整理连败 84 次。
|
|
24
|
+
- **摘要改成身份视图**:`manifestDigest` 只摘 `runtime` 的身份字段(engine/abi/version/os/arch 与制品 name/version/sha256/integrity),镜像源与文案(`sources`/`label`/`displayName`/`summary`)不再入摘要,字典与数组两种制品形态都剥;老算法继续接受;`manifestDrift` 区分"只有元数据漂移(warn 一次、继续用)"与"身份变了(抛错、要重建)";逐字段一致却摘要对不上仍按不可信处理。
|
|
25
|
+
- **重签与重指**:`resignVectorProfile` 拒绝身份变更,改前备份 `vector-active.json.bak-resign-*`;`repointVectorRuntimeDir` 备份 `.bak-runtimedir-*`,候选目录同时扫 `downloads/embeddings/runtime`(真实布局)与旧 `downloads/runtime`,且要求 `onnxruntime-node/package.json` 真在(只剩 `bin/` 的空壳不算候选)。
|
|
26
|
+
- **整理收尾失败带原因**:worker 收尾 followup 失败原先只写 `consolidation wrapup followup failed`,诊断页照着查不到任何东西;现在带 `code: message`(`describeError`),并在 `lib/binding-diagnostics.js` 的 `RUNTIME_STATE` 里同步 `inFlight` 的源码位置。
|
|
27
|
+
- **worker 可观测**:`local-embedding-manager` 不再丢弃子进程 stderr(脱敏后保留末 4000 字),失败时挂 `error.embedding = {stderrTail, modelDir, runtimeDir}` 并通过 `setEmbeddingFailureSink` 写诊断——「worker exited before it became ready」从此带原因。
|
|
28
|
+
- **读盘修复**:`ensureLoaded` 只有在真的从中间截断时才丢第一行;此前无条件 `shift()`,导致"落盘了但重启后诊断页永远空白"。
|
|
29
|
+
- 守卫:`tests/diagnostics.test.mjs`(去重/独立落盘/脱敏/确认后不再弹/修复双向记账/锁四判据/三算法兼容/drift 分类/重启后可读)、`tests/environment-check.test.mjs`(检查项形状、遗弃锁可见、`confirmed` 门禁、失败也记账、安全名单不可越界、运行时目录发现)、`tests/client-render.test.mjs` 逐页探针 13 → 14 页。
|
|
30
|
+
- 文档同步:`docs/contributing.md` §5.4.1(诊断/修复扩展点)、`docs/troubleshooting.md` §3.29(三类真实故障的症状→根因→诊断码→修复动作)。
|
|
31
|
+
|
|
3
32
|
## [1.3.12] - 2026-11-20
|
|
4
33
|
|
|
5
34
|
> 全局记忆生命周期与私有同权:记忆墙全局块多选批量归档/恢复/删除、抽屉与全局记忆页的归档/恢复/两段确认永久删除补齐;内容仍由 curator 书写。
|
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ All screenshots are the real WebUI on isolated example data, not anyone's memori
|
|
|
60
60
|
- **Recall is a moment, not a dump.** The first turn after a session starts (or after compaction) gets an anchor block with budgets for pinned, core and global memory. After that, each user turn gets at most one recall. Deduplication and a token budget are enforced in code, not left to the prompt. Anchor and recall entries are **title cards**: title, id and semantic tags only. The body stays in the drawer and behind `memu_private_recall` / `memu_global_recall`, so the same budget exposes far more memories without pasting text the model never asked for.
|
|
61
61
|
- **Invisible memories cannot crowd out visible ones.** Private lexical recall builds its scoring corpus after applying conversation context, speaker and disclosure rules, including the lexical branch of mixed recall. Explicit reads retain their disclosure permissions.
|
|
62
62
|
- **A private lexicon writes itself.** The consolidation worker extracts stable, evidenced slang, memes and project terms with one term per entry. Ordinary entries become active immediately (no human review queue), while sensitive triggers and sensitive edits stay user-only. The lexicon page is a card flow with active/archived tabs, edit, archive/restore and two-step permanent delete. A **global lexicon** sits beside the per-library ones: every conversation reads it, only you write it. With same-domain cross-library recall on, the anchor, this-turn match and `memu_lexicon_search` merge those libraries too — the page still browses one book at a time.
|
|
63
|
-
- **Private links come from assertions, not statistics.** `autoLinkMode` defaults to *candidates only*: a local zero-token pass ranks names into a review queue and writes nothing. Once you confirm an entity, its names and aliases are matched against memory text (`entity-mention`); `conflicts_with` / `supersedes` / the same `fact_key` add field-evidence edges. Lexical similarity, shared tokens and vectors never create an edge. Confirming, renaming, merging or deleting an entity maintains its edges immediately, and a removed auto edge is suppressed so it cannot come back. Links are metadata, shown with an “Auto” badge in the graph; they never rewrite a body, write a vector or delete anything. Existing libraries migrate with `node scripts/rebuild-auto-links.mjs` (dry-run first, `--apply` takes a backup).
|
|
63
|
+
- **Private links come from assertions, not statistics.** `autoLinkMode` defaults to *candidates only*: a local zero-token pass ranks names into a review queue and writes nothing. Once you confirm an entity, its names and aliases are matched against memory text (`entity-mention`); `conflicts_with` / `supersedes` / the same `fact_key` add field-evidence edges. Lexical similarity, shared tokens and vectors never create an edge. Confirming, renaming, merging or deleting an entity maintains its edges immediately, and a removed auto edge is suppressed so it cannot come back. Links are metadata, shown with an “Auto” badge in the graph; they never rewrite a body, write a vector or delete anything. Existing libraries migrate with `node scripts/rebuild-auto-links.mjs` (dry-run first, `--apply` takes a backup). New names proposed by a model must appear as complete quoted, introduced or delimited names in the source memory; a substring or the link note alone is insufficient. Existing names and aliases remain reusable, and rejected links leave no new entity.
|
|
64
64
|
- **A date is either an anniversary or one day.** `MM-DD` recurs every year (a birthday); `YYYY-MM-DD` fires the day before and the day itself, then is spent. Relative wording (今天 / 明天 / 下周X / 月底) is resolved against the turn's scene time and stored as an absolute date; a memory that says "tomorrow" is stored as the dated form, so an appointment does not come back every year.
|
|
65
65
|
- **Memory fades unevenly.** Recency, access count, peak and end effects, primacy, habituation and flashbulb accuracy feed one strength score. Mood is described by four components (joy / anger / sorrow / fear, summing to 1) plus arousal (intensity) and dominance (sense of control); a compound mood such as jealousy is a named mix of the four, not a new axis. Mood only reorders recall: it never enters the injected text and never rewrites a memory body. Gating is the OR of three independent conditions — the dominant share is >= 0.35, |arousal - 0.35| >= 0.1, or |dominance| >= 0.25; when none holds, both multipliers are exactly 1. Older entries carry no emotion and keep the old valence path; the four axes are never inferred back from valence. A vivid memory can be more confident than it is accurate, and the UI says so.
|
|
66
66
|
- **Provenance is a fact, not a style.** Every entry carries `source` / `source_kind` (`user_said` / `assistant_said` / `told` / `imagined` / `inferred` / `tool`), `speaker_id`, `confidence`, `accuracy`, and disclosure rules. A vague recollection cannot impersonate a quote, and the assistant's own promises or plans cannot be filed as something the user said.
|
|
@@ -95,7 +95,7 @@ The sidebar has exactly **one** entry: **MemU WebUI**. The memory wall and all s
|
|
|
95
95
|
|
|
96
96
|
**In-place work.** Clicking a memory card opens a right-side drawer with the full text and the fields that decide how it behaves — title, content, tags, disclosure, confidence, open loop — plus save, archive, restore and "open in the browser" for heavier work. Archived memories can be deleted in the same drawer; the first click only arms it and the second confirms. Global memories keep their curator-written content read-only in the drawer, but archive, restore and two-step permanent delete work there just like private ones, and link to their own page. Filters and scroll position stay where they were. Cards that carry images use the first usable attachment as a cover, and the drawer opens the full gallery; `secret` and `never_say` entries never receive a pixel URL, so they show a label instead.
|
|
97
97
|
|
|
98
|
-
**One page for the graph.** **Relations** is its own full-screen page in the WebUI (`#/settings/graph`): the canvas on the left, the inspector on the right, and a **Manage** tab
|
|
98
|
+
**One page for the graph.** **Relations** is its own full-screen page in the WebUI (`#/settings/graph`): the canvas on the left, the inspector on the right, and a **Manage** tab using the same domain and search filters. **All libraries** combines private libraries with separate identities for same-id nodes and follows 200-node pages through trailing entities; the canvas retains every loaded node. The editable **Domain** filter accepts built-in or custom domains (for example `coding` or `project:travel`), matches the full normalized name, and shows all domains when empty. Missing memory domains count as `general`; a filtered entity appears when linked to a matching memory. Source and rule filters narrow displayed edges. Settings → Relations opens this page; graph browsing retains the existing library and session authorization boundaries.
|
|
99
99
|
|
|
100
100
|
The graph runs on a **self-written continuous force engine** — no third-party runtime is bundled. It stays alive while you work, preserves node positions and the camera across background data refreshes, and stops requesting frames the moment it cools down, so an open graph costs no idle GPU. Dragging pins a node exactly where you drop it (release never yanks it back), and only the cluster you touched keeps simulating: frozen clusters act as obstacles the moving one cannot slide through. Repulsion, link distance and centering are adjustable in the panel, labels avoid collisions, and the minimap repaints only after the canvas does. Zoomed all the way out the nodes necessarily merge on screen — separation lives in world coordinates, so spread clusters with repulsion/link distance instead of the zoom. Settings → Relations is a single button that opens the full-screen graph page in the WebUI, where you can also add, edit and delete nodes, and filter edges by the rule that produced them. The layout only visualizes recorded links: it never infers or writes relationships. The graph page also lists **entity merge candidates** (same kind, contained or near-identical spellings) — suggestions only, confirmed by two clicks, and merging redirects links and folds aliases into the main node without deleting any memory.
|
|
101
101
|
|
package/docs/contributing.md
CHANGED
|
@@ -78,9 +78,9 @@ npm run check # node --check + i18n 键对齐 + package.j
|
|
|
78
78
|
|
|
79
79
|
### 5.3 新增一个 RPC 方法
|
|
80
80
|
|
|
81
|
-
<!-- rpc-method-count:
|
|
81
|
+
<!-- rpc-method-count: 109 -->
|
|
82
82
|
|
|
83
|
-
1. `lib/rpc.js` 的 `switch` 加 case(共
|
|
83
|
+
1. `lib/rpc.js` 的 `switch` 加 case(共 109 个方法,按功能分组,别乱插)。
|
|
84
84
|
2. 返回**形状稳定**:客户端 `call()` 直接解构,列表类给 `{items, total}` 而不是裸数组。
|
|
85
85
|
3. `revisionOnly` 分支只回 `{revision, stamp}`、**不要求 sessionId**(三端轮询,设置页与独立页没会话)、**不塞业务数据**(每 2.5 秒一次);顺带 `noteMemoryBeat()`,`memu_status` 靠它分「没写」与「没人轮询」。
|
|
86
86
|
4. 写成功后 `bumpMemoryRevision()`/`notifyMemoryWrite()`(§7);能让 `state.json` 或索引落盘的写,`state.js` 自动记写事件供 `memu_status` 展示。
|
|
@@ -94,6 +94,18 @@ npm run check # node --check + i18n 键对齐 + package.j
|
|
|
94
94
|
4. 独立页(`lib/webui/`)要同步显示就走 `BroadcastChannel` 的 `memory-write`,并让 WebUI `settingRow` 读同一份 `getSettingsState`。
|
|
95
95
|
5. **新增整页**:`PAGE` 加键 → `pageDefs` → `pageBlocks` → 导航图标 → 两处文案 → 渲染探针(`tests/client-render.test.mjs` 逐页渲染)。
|
|
96
96
|
|
|
97
|
+
### 5.4.1 新增一条诊断 / 一个修复动作
|
|
98
|
+
|
|
99
|
+
诊断是**插件自己的体检**,与活动日志(`logs/activity.jsonl`,记"发生了什么")刻意分开:活动日志给用户看流程,诊断记"哪里坏了、能怎么修"。
|
|
100
|
+
|
|
101
|
+
1. **记一条**:`recordDiagnostic({level, scope, code, message, detail, hint, repair})`(`lib/diagnostics.js`)。`code` 用大写下划线常量,同一个 `(scope, code, message)` 在 60 秒窗口内只累加 `count`,不会刷屏;`detail` 里的 secret 会被 `redactSecrets`(`lib/paths.js:63`)脱敏——**宁可少记,不可记明文 key**。
|
|
102
|
+
2. **让报错自动进来**:抛错路径统一走 `recordErrorDiagnostic(error, {source, detail})`;`error.code` 命中 `KNOWN_CODES` 表就自动带上 scope / 修复动作 / hint。
|
|
103
|
+
3. **登记故障码**:`KNOWN_CODES`(`lib/diagnostics.js`)里给 `{scope, repair, manual, hint}`。`repair` 必须是 `lib/environment-check.js` 里 `REPAIRS` 的键,否则诊断页只显示"无可用修复"。
|
|
104
|
+
4. **新增修复动作**:在 `lib/environment-check.js` 的 `REPAIRS` 加一项 `{label, run}`,同时决定它进 `SAFE_REPAIRS`(启动时自动跑、幂等、不删用户数据)还是 `MANUAL_REPAIRS`(必须用户点、可能重建索引或重装引擎)。**破坏性动作永远不进 SAFE**。
|
|
105
|
+
5. **每一项修复都要 `recordRepair({action, ok, detail})`**——失败也要进诊断,否则"修了但没修好"无从判断。
|
|
106
|
+
6. **检查项**:`runEnvironmentCheck` 的 items 形如 `{id, level, ok, title, detail, hint, repair}`,诊断页与启动弹窗都只认这个形状;加检查项记得在 `tests/environment-check.test.mjs` 里加一条"缺什么报什么"的用例。
|
|
107
|
+
7. 前端:诊断页 `diagnosticsBlock`(`lib/client.js`)已把"环境自检 + 诊断记录"两块渲染完,新动作不用改前端,只要出现在 `getRepairOptions` 里就会长出按钮。
|
|
108
|
+
|
|
97
109
|
### 5.5 新增一个提示词变体 / 类型页
|
|
98
110
|
|
|
99
111
|
1. 变体命名 `<name>.<domain>.md`,与基础稿同在 `lib/prompts/`。**只有三个 key 支持分域**:`system-guide`、`private-policy`、`private-consolidation`;`global-curator` 不分域(职责就是跨域整理)。
|
package/docs/memory-semantics.md
CHANGED
|
@@ -165,9 +165,9 @@
|
|
|
165
165
|
|
|
166
166
|
**私有自动关联(v3 确定性版)。** 写边只有一条路径:`lib/auto-link/` 的纯函数判定。`settings.autoLinkMode` 三档:`suggest`(默认)只生成候选、**自动整理不写边**,但你显式确认实体仍会补挂(§14 S4 的迁移流程);`deterministic` 自动整理也写由证据推出的确定性边;`off` 全关——连确认/新建/改名/合并触发的提及维护也不写。判定表只有两类:① `entity-mention`——记忆标题/正文按 NFKC+大小写/标点归一化后命中一个 **confirmed** 实体的名字/别名(CJK 子串 ≥2 字,Latin 词边界,`yuike` 不命中 `yuikeee`),产出 `memory→entity` 边;② 字段证据——`conflicts_with` / `supersedes` / 同 `fact_key`+同上下文签名的相邻版本,产出 memory↔memory 的 `conflict` / `supersede` / `fact-key` 边。两类边固定 `confidence: 1.0`、`schemaVersion: 2`,带 `evidence.rule`(枚举 `entity-mention` / `conflict` / `supersede` / `fact-key` / `worker-quote`)。词面相似度、共享 token、向量与所有统计量**永不建边**;它们只参与 `anchor-candidates.json` 的候选排序。
|
|
167
167
|
|
|
168
|
-
**实体生命周期。** `provisional`(默认)不产生任何边,`confirmed` 才允许 R1,`archived` 视同不可用。手工创建(UI/RPC)直接 confirmed;worker 经 `memu_private_link` 点名只创建 provisional 实体与一条非 auto
|
|
168
|
+
**实体生命周期。** `provisional`(默认)不产生任何边,`confirmed` 才允许 R1,`archived` 视同不可用。手工创建(UI/RPC)直接 confirmed;worker 经 `memu_private_link` 点名只创建 provisional 实体与一条非 auto 边;新实体名必须在来源记忆的标题或正文中以完整引号、名字引导加右边界、或两侧分隔的表面出现,不能由词语子串、代词或 link note 推出。已有实体/别名按 NFKC 与大小写复用;名称、来源可见性、边类型、理由、置信度与数量限制先校验,再创建新实体(`allowWorkerAssertion` 是 v3 预留开关,本版不读取)。确认/改名/合并/删除都会级联:确认立即跑一次增量提及(不等下次整理);rename 重算该实体的提及边;merge 把来源实体的 `evidence.entityId` 改指主节点并继承 confirmed;delete(force)回收 auto 边并把 `(from,to,kind,rule)` 写进 `index/<lib>.link-suppression.json`。带 `conflicts_with` / `supersedes` / 同 `fact_key` 配对的写入,以及复核接受(replace 会把旧条目改成 superseded)也会立即重算受影响条目的字段证据边,不等下一次整理。用户在关系图删除 auto 边同样写抑制键,后续重算不会复活。
|
|
169
169
|
|
|
170
|
-
**候选队列与迁移。** `anchor-candidates.json` 是派生物:CJK 2–4gram / Latin token 的 df/titleDf/边界/凝聚/PMI/LLR 只用于排序;Tier 1
|
|
170
|
+
**候选队列与迁移。** `anchor-candidates.json` 是派生物:CJK 2–4gram / Latin token 的 df/titleDf/边界/凝聚/PMI/LLR 只用于排序;Tier 1 是有完整表面证据(引号/名字引导/标识符/用户维护词典)的候选,完整引号或名字引导不再给内部的短 n-gram 背书;Tier 2 仅统计特征;已知完整引号/名字表面的子片段,若无独立完整证据则不提名。候选提取器版本与完整策略参与内存、磁盘派生缓存校验,更新后重算旧快照。候选仍不创建实体,历史实体也不因本次过滤被自动删除或合并。没有 status 的旧实体按 DESIGN §9.3 分级:只有 `origin ∈ {user,agent,worker}` 或被非 auto 边引用才保留 confirmed,其余落 provisional。`scripts/rebuild-auto-links.mjs`(默认 dry-run,`--apply` 先整库备份)删除全部 `source:'auto'` 旧边、落实体状态,并为已确认实体重建确定性边;确认与 dry-run 幂等后再把 `autoLinkMode` 切到 `deterministic`。
|
|
171
171
|
|
|
172
172
|
**召回治理与失败隔离。** `recallRelations` 的 top-2 扩展显式排除 `evidence.rule === 'entity-mention'`——提及是事实索引不是关系,`confidence=1.0` 不能挤掉手动边与字段证据;字段证据边照常参与。判定层纯函数、无 IO/时钟/随机;写库失败只 warn,绝不让已经成功的整理失败;`links[]` 仍只是元数据,不改正文、不写向量、不删记忆。worker 写工具为 remember/remember_batch/update/link/link_suggest(2026-11-15 起 link 两件挂回:auto-link 的不确定候选留给整理回合逐条裁决),读工具为空(记忆目录与本地召回由插件在任务包开头注入),但「有没有写能力」仍只由 remember/update 判定。
|
|
173
173
|
|
package/docs/troubleshooting.md
CHANGED
|
@@ -44,10 +44,14 @@ worker 前置依赖 / 完整包超限 / usage 未知 → §3.39
|
|
|
44
44
|
本地向量模型装不上 / 切不过去 / 召回 400 → §3.25
|
|
45
45
|
整理超时(fork 预算不够)→ §3.26
|
|
46
46
|
图谱改了没生效 / 缩到最小打架 / 导航被掰竖 → §3.27
|
|
47
|
+
全部库图谱缺绿色实体 / 按域筛选 → §3.43
|
|
48
|
+
自动出现「忆组件 / 主人一 / 人一 / 主人一说」等碎片实体 → §3.44
|
|
47
49
|
WebUI 开着 GPU 占用高 / 时钟钉高档 → §3.28
|
|
48
50
|
长链跑批库不增长 / 考试大面积「不知道」→ §3.29
|
|
49
51
|
同一条用户消息每轮注入两次 / 第二次召回 0 条 → §3.30
|
|
50
52
|
mac 一键安装引擎报 dlopen 签名错 / 事后引擎目录是空的 → §3.31
|
|
53
|
+
插件内部报错要取证与一键修复 / 启动弹窗 → §3.45
|
|
54
|
+
库从列表消失但仍在写入 / 召回正常 → §3.46
|
|
51
55
|
```
|
|
52
56
|
|
|
53
57
|
## 3. 出过的问题:症状 → 落点 → 守卫
|
|
@@ -408,7 +412,7 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
|
|
|
408
412
|
|
|
409
413
|
### 2.1 模块地图
|
|
410
414
|
|
|
411
|
-
<!-- rpc-method-count:
|
|
415
|
+
<!-- rpc-method-count: 109 -->
|
|
412
416
|
|
|
413
417
|
| 文件 | 职责 / 什么时候碰它 |
|
|
414
418
|
|---|---|
|
|
@@ -739,3 +743,59 @@ grep tests 里的硬编码清单。守卫:全量 `npm test` 1676/1674 pass / 0
|
|
|
739
743
|
**落点:** 全局生命周期走既有 `archiveMemory` / `updateMemory` / `deleteMemory` 加显式 `scope:'global'`(`lib/rpc.js`),鉴权与全局复核队列同口径(`authorizeGlobalReviewRoute`:embedded 要活绑定,standalone 走 `libraryId=null` 的 `review.manage`);`scope:'global'` 与 `libraryId` 同现在鉴权层就拒。`lib/memory.js` 的 `globalSetStatus` 只改 status(召回/锚点/注入统一过 `isMemoryEligible`,archived 立即排除,不动向量行);全局 `updateMemory` 只接受 `{status:'active'}`。`globalDelete` 只开放 archived/suppressed/expired + 显式确认 + 删除前 `backupDatabases`,单事务级联清他条 `links[].to` 与 `duplicateOf/relatedTo/conflictingWith/supersededBy/absorbedBy`;带 `absorbedFrom` 的合并稿与活跃合并的来源拒删。前端:记忆墙全局块多选与私有同权(`lib/client.js` MemoryWallPanel),抽屉全局条目内容只读但生命周期按钮齐全,全局记忆页每条带归档/恢复/两段删除。
|
|
740
744
|
|
|
741
745
|
**守卫:** `tests/global-lifecycle.test.mjs`(归档即排除召回/恢复即回来、状态机边界、内容补丁拒绝、删除级联与合并守卫、管理视图仍见 archived、私有路径回归);`tests/webui-auth.test.mjs` 的「global lifecycle」凭据矩阵(活绑定/悬空会话/作用域冲突/review.manage 四态);`tests/client-render.test.mjs` 的全局块多选批量归档与抽屉两段删除(注意 harness 的 hook 游标全局递增:同一棵树只能 walk 一遍)。
|
|
746
|
+
|
|
747
|
+
### 3.43 全部库图谱缺绿色实体与域筛选
|
|
748
|
+
|
|
749
|
+
**症状**:选择全部库后,后面库的绿色实体不见,或大库只剩记忆节点。
|
|
750
|
+
|
|
751
|
+
**原因与修复**:旧接口每库先取 200 个节点,实体排在记忆后;前端合并时用裸 id 去重,画布又把合并输入截到 200。现在私有图谱无焦点浏览显式传 `offset` 分页,按返回的 `nextOffset` 读完;跨页边保留端点,跨库显示 id 由库和原始 id 组成,管理操作仍用原始 id 写回所属库。画布不再重复截断输入。旧接口默认页上限与焦点邻域仍保留,分页不扩大会话可访问库。读取失败会显示库名,不再静默吞掉。
|
|
752
|
+
|
|
753
|
+
**筛选**:顶部域输入框可输入完整自定义域,或选择已有域;NFKC、首尾空白和大小写规范化后精确匹配,清空显示全部域。缺失域按 `general`,实体随匹配记忆出现,图与管理列表共用结果。仅更改大小写或空白不会清空画布。
|
|
754
|
+
|
|
755
|
+
**守卫**:`tests/graph.test.mjs` 覆盖分页、跨页边、域与权限;`tests/client-render.test.mjs` 覆盖 204 节点跨库分页、同 id 隔离、域切换、原始 id 编辑与部分失败;`tests/graph-view.test.mjs` 覆盖超过 200 节点的尾部实体与实际 bundle。改引擎后执行 `npm run build:graph`。
|
|
756
|
+
|
|
757
|
+
### 3.44 自动实体把词语片段当成人名
|
|
758
|
+
|
|
759
|
+
**症状**:自动整理或候选队列出现「忆组件」「主人一」「人一」「主人一说」等被截断的人物节点;无效的关联请求报错后还可能留下孤立实体。
|
|
760
|
+
|
|
761
|
+
**原因与修复**:旧候选提取把完整引号或名字引导后的文本再次拆成 n-gram,内部片段也继承表面证据。新候选只给完整称呼背书,并过滤没有独立边界的子片段。模型通过 `memu_private_link` 创建未知实体时,来源记忆本身必须包含完整引号、名字引导加右边界、或两侧分隔的名称,link note 不算来源证据;先校验来源、边类型、理由、置信度和数量限制,再创建 provisional 实体,普通参数错误不再遗留孤立节点。既有实体和别名仍可复用,手动创建与已确认实体的提及匹配保持原规则。
|
|
762
|
+
|
|
763
|
+
**守卫与旧数据**:`tests/tools.test.mjs` 覆盖四种碎片、虚构理由、Latin 子串、完整姓名/昵称/别名与失败不留节点;`tests/auto-link-candidates.test.mjs` 覆盖完整表面、内部片段和派生缓存。不能仅按字符串把历史节点自动删除或归并——「主人一」也可能是真实昵称;先核对原始记忆,再在关系图中按证据改名、合并或删除。此修复不改写现有记忆或实体。
|
|
764
|
+
|
|
765
|
+
### 3.45 诊断页:插件内部到底哪儿坏了(1.3.13 起)
|
|
766
|
+
|
|
767
|
+
**症状**:召回突然降级成"只有关键词命中"、写入报 `VECTOR_PROFILE_MANIFEST_CHANGED` / `the local embedding worker exited before it became ready`、整理任务一直说 `the consolidation lease could not be persisted`,但设置页一切正常、活动日志里只有一行警告。
|
|
768
|
+
|
|
769
|
+
**落点**:这类故障以前**没有出口**——`logs/activity.jsonl` 记的是流程(谁在什么时候召回了几条),而"哪个文件坏了、能不能修"无处可看;活动日志里那一行 `logger.warn` 还是被 `fail-open` 吞掉之后的残渣。2026-11 这三类真实故障就是这样坏了 9 天才被发现(同一句 manifest 报错在活动日志里出现 661 次,最早的 2026-11-12):
|
|
770
|
+
|
|
771
|
+
| 症状 | 真实根因 | 诊断里的 code | 修复动作 |
|
|
772
|
+
|---|---|---|---|
|
|
773
|
+
| 召回降级 661 次 | catalog 的 `runtime.sources` 加了国内镜像元数据,摘要却把整个 `runtime` 算进身份 → 向量空间被误判为"制品清单已变" | `VECTOR_PROFILE_MANIFEST_CHANGED` | `resign-vector-profile`(重签摘要,不动 25 条向量) |
|
|
774
|
+
| 写入/召回报 worker exited | `vector-active.json` 的 `runtimeDir` 指向一个已不存在的 UUID 目录(`onnxruntime-node` MODULE_NOT_FOUND,而这行 stderr 被旧代码 `() => {}` 丢掉了) | `LOCAL_VECTOR_RUNTIME_UNAVAILABLE` | `repoint-runtime-dir` |
|
|
775
|
+
| 整理 84 次 `lease could not be persisted` | `consolidation.json.lock` 是 0 字节(写锁时崩在 `writeFileSync` 之前),旧 `withFileLock` 把锁内容当 pid,`Number('')===0` 永远进不了清理分支 → 每次都等到超时 | `DSH_MEMU_STORE_BUSY` | `release-stale-locks` |
|
|
776
|
+
|
|
777
|
+
**现在**:
|
|
778
|
+
- **诊断页**:设置 → 诊断(`#/settings/diagnostics`),或独立 WebUI 的「诊断」。上半张是**环境自检**(数据目录可写 / 遗留锁 / 引擎 python / 向量 profile 摘要 / 向量运行时 / 模型目录 / embedding worker),每项给状态、证据、怎么办,能自动修的给按钮、破坏性的标"需手动";下半张是**诊断记录**,按 level 与关键词过滤,`detail` 里是结构化证据(脱敏后的 stderr 尾巴、路径、changedFields),可整页复制。
|
|
779
|
+
- **主页启动弹窗**:启动引导自检发现 error/warn 级问题时,主页顶部弹一张卡(最多 4 条,按 code 汇总"×N")。点"稍后"或"打开诊断"都会 `acknowledgeDiagnostics`,**同一问题不再天天弹**,只有再次发生(count 增长)才重新提醒。
|
|
780
|
+
- **启动自动修复**:`autoInstallEngine` 打开时,启动 6 秒后跑一次自检,只自动执行**安全且幂等**的三件事(清遗弃锁 / 重签摘要 / 重指运行时目录);重建索引、重装运行时/模型/引擎一律留手动入口——它们会动用户数据或几十 MB 下载,不该静默发生。
|
|
781
|
+
- **落盘位置**:`~/.dsh/dsh-memu-memory/diagnostics/events.jsonl`(2MB 轮转到 `events.1.jsonl`),与 `logs/activity.jsonl` 分开;同一 `(scope, code, message)` 60 秒内只累加 `count`,维修动作无论成功失败都记一行 `MEMU_DIAGNOSTIC_REPAIRED` / `MEMU_DIAGNOSTIC_REPAIR_FAILED`。
|
|
782
|
+
|
|
783
|
+
**自己查的顺序**:先看诊断页环境自检的红项(它们决定"能不能修"),再看诊断记录里最新一条的 `detail`——`stderrTail` / `changedFields` / `busy.owner`+`busy.ageMs` 通常直接点名坏在哪。锁类问题不要手动删 `*.lock`:诊断页的「释放遗留锁」会先核对 pid 是否还活着、锁是否超过 60 秒,只清能证明是遗弃的(手动删可能拆掉另一个插件副本正在用的事务)。
|
|
784
|
+
|
|
785
|
+
**守卫**:`tests/diagnostics.test.mjs`(去重计数、独立落盘、脱敏、告警确认后不再弹、修复双向记账、锁四种遗弃判据、三种摘要算法兼容、镜像漂移 vs 身份变更)、`tests/environment-check.test.mjs`(缺什么报什么、安全/手动分组、`confirmed` 门禁)、`tests/client-render.test.mjs` 的逐页探针(14 页)。
|
|
786
|
+
|
|
787
|
+
### 3.46 库从列表消失但仍在被读写(归档判定只看工作区注册表)
|
|
788
|
+
|
|
789
|
+
**症状**:某个记忆库在 UI / `memu_status` / 库列表里查不到,但绑定它的会话照常写入、召回也 `ok=true`;`state.json` 里该库 `archived: true`,而 `lastUsedAt` 还在持续刷新。宿主日志能搜到一行 `archived library <id>: workspace <scopeKey> is no longer registered in DSH`。
|
|
790
|
+
|
|
791
|
+
**落点(1.3.13 及更早)**:归档判定只认 `workspaceRegistry`(`cycle.js` 的 `registeredScopes`)——它回答「这个目录是不是 DSH 工作区」,**不回答「这个库还有没有人用」**。于是 IM 插件数据目录、profile 下的目录这类 scope 永远不在册,建库后几分钟就被 sweep 归档;而 `ensureSession` 快路径与召回准入都不看 `archived`,会话继续读写,形成「归档但活跃」。恢复条件(scope 回到注册表)对这类路径永不满足,所以不会自愈。更糟的是 `deleteLibrary` 只接受「已归档」的库、`purgeArchivedAfterDays` 只按年龄清理,在用的库恰好落进可删状态。真实现场(2026-11-21 外部报告):建库 176 秒后被归档,之后 9 小时 172 条活动、6 次召回全成功。
|
|
792
|
+
|
|
793
|
+
**现在(1.3.14 起)**:
|
|
794
|
+
- 归档前先看「有没有存活绑定」:`state.inUseLibraryIds()` 按 `sessionGone !== true` 的会话绑定判定;在用的库不归档,结果里给 `skippedInUse`,同一个库只提示一次。
|
|
795
|
+
- 归档来源写入 `archivedBy`(`sweep` / `user`)。扫描遇到「已归档 + 仍有存活绑定 + 非用户归档」会**就地复活**;`ensureSession` 快路径同样复活误归档库。用户主动归档的不动。
|
|
796
|
+
- 旧数据(1.3.13 及更早,没有 `archivedBy`)分不清是谁归档的,所以只复活**还热**的库:`lastUsedAt` 在 14 天内才算误归档;更早的保持归档(本机 `rp` / `ai中转站` 就属于这种「归档 + 旧绑定」的冷数据,升级后不会被突然翻出来)。
|
|
797
|
+
- `deleteLibrary(id)` 只拒绝「危险归档 + 仍在用」这一类(判据 `archivedWhileInUse` 与自愈共用);用户主动归档、冷数据的旧归档照旧可删。RPC 只在 `confirmed` 时透传 `force`;`purgeArchivedAfterDays` 的候选排除在用库。
|
|
798
|
+
|
|
799
|
+
**怎么确认**:`state.json` 里看 `archived` / `archivedBy` / `lastUsedAt` 三者是否自相矛盾;宿主日志搜 `archived library` 与 `kept library`。修好后旧数据在下一轮 sweep(启动后 8 秒或每 5 分钟)或下一条消息时自动复活。
|
|
800
|
+
|
|
801
|
+
**守卫**:`tests/cycle.test.mjs` —— 在用库跨三轮 sweep 不归档且仍在列表、无人用的库照常归档并记 `archivedBy='sweep'`、误归档在用库被复活、用户归档不被复活、purge 不把在用库列入候选、删除在用库被拒(解绑后放行)、快路径复活。
|
|
@@ -15,6 +15,7 @@ import { buildTermStats, rankCandidates } from './terminology.js'
|
|
|
15
15
|
import { normalizeForIndex } from './normalize.js'
|
|
16
16
|
|
|
17
17
|
const CACHE = new Map()
|
|
18
|
+
const CANDIDATE_VERSION = 2
|
|
18
19
|
|
|
19
20
|
export function candidatesFile(libraryId) {
|
|
20
21
|
if (!isSafeId(libraryId)) throw new Error('invalid library id')
|
|
@@ -71,11 +72,13 @@ function entitySurfaceMap(entities) {
|
|
|
71
72
|
export function generateAnchorCandidates({ libraryId, now = Date.now(), force = false, policy = AUTOLINK_POLICY_V3 } = {}) {
|
|
72
73
|
if (!isSafeId(libraryId)) throw new Error('invalid library id')
|
|
73
74
|
const signature = statSignature(libraryId)
|
|
75
|
+
const policyKey = JSON.stringify(Object.entries(policy).sort(([a], [b]) => a.localeCompare(b)))
|
|
74
76
|
const cached = CACHE.get(libraryId)
|
|
75
|
-
if (!force && cached && cached.
|
|
76
|
-
const stored = readStored(libraryId)
|
|
77
|
-
if (
|
|
78
|
-
|
|
77
|
+
if (!force && cached?.signature === signature && cached.policyKey === policyKey) return cached.value
|
|
78
|
+
const stored = force ? null : readStored(libraryId)
|
|
79
|
+
if (stored?.candidateVersion === CANDIDATE_VERSION && stored.revision === signature
|
|
80
|
+
&& stored.policyKey === policyKey && Array.isArray(stored.tiers?.tier1)) {
|
|
81
|
+
CACHE.set(libraryId, { signature, policyKey, value: stored })
|
|
79
82
|
return stored
|
|
80
83
|
}
|
|
81
84
|
|
|
@@ -115,15 +118,17 @@ export function generateAnchorCandidates({ libraryId, now = Date.now(), force =
|
|
|
115
118
|
|
|
116
119
|
const value = {
|
|
117
120
|
version: 1,
|
|
121
|
+
candidateVersion: CANDIDATE_VERSION,
|
|
118
122
|
libraryId,
|
|
119
123
|
revision: signature,
|
|
120
124
|
policyVersion: AUTOLINK_POLICY_VERSION,
|
|
125
|
+
policyKey,
|
|
121
126
|
generatedAt: new Date(now).toISOString(),
|
|
122
127
|
totals: { memories: rows.length, entities: entityItems.length, tier1: tiers.tier1.length, tier2: tiers.tier2.length },
|
|
123
128
|
tiers,
|
|
124
129
|
entities: { provisional, confirmed },
|
|
125
130
|
}
|
|
126
|
-
CACHE.set(libraryId, { signature, value })
|
|
131
|
+
CACHE.set(libraryId, { signature, policyKey, value })
|
|
127
132
|
try { writeJson(candidatesFile(libraryId), value) } catch {}
|
|
128
133
|
return value
|
|
129
134
|
}
|
|
@@ -14,8 +14,11 @@ const FUNCTION_CHARS = new Set('的了是和与也就都很又还你我他她它
|
|
|
14
14
|
// Measure-word templates: 一条/两只/这个/那些… A name never starts with one.
|
|
15
15
|
const MEASURE_PREFIX = /^(一|两|三|几|每|这|那|半)?[条只把张个位次件场顿盘杯碗袋包串支根颗头匹群套双对份页篇段句声口]/
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
const INTRO_RE = /(
|
|
17
|
+
const QUOTED_SURFACE = /「([^」\n]+)」|『([^』\n]+)』|《([^》\n]+)》|“([^”\n]+)”|‘([^’\n]+)’|"([^"\n]+)"|'([^'\n]+)'/g
|
|
18
|
+
const INTRO_RE = /(?:名叫|名字(?:是|叫|为)?|称呼(?:是|为)?|自称|叫|\busername\b|\bnickname\b)[ \t]*:?[ \t]*/g
|
|
19
|
+
const SURFACE_RUN = /[\p{L}\p{N}_]+(?:[.-][\p{L}\p{N}_]+)*/gu
|
|
20
|
+
const START_SURFACE = new RegExp('^' + SURFACE_RUN.source, 'u')
|
|
21
|
+
const WHOLE_SURFACE = /^(?:[\u3400-\u9fff\uf900-\ufaff]+|[a-z0-9][a-z0-9._-]*)$/
|
|
19
22
|
|
|
20
23
|
/** Terms whose surface shape cannot be a name on its own (ranking hint only). */
|
|
21
24
|
export function looksGeneric(token) {
|
|
@@ -30,31 +33,43 @@ function isLatinTerm(term) {
|
|
|
30
33
|
return /^[a-z0-9]/.test(term) && !/[\u3400-\u9fff\uf900-\ufaff]/.test(term)
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
// Keep weak statistics for the entire corpus, but give strong evidence only to
|
|
37
|
+
// an exact surface. Record CJK fragments even when the parent itself is longer
|
|
38
|
+
// than the statistical n-gram cap.
|
|
39
|
+
function collectSurface(value, evidence, fragments, policy) {
|
|
40
|
+
const surface = value.trim()
|
|
41
|
+
if (WHOLE_SURFACE.test(surface)) evidence.add(surface)
|
|
42
|
+
for (const run of surface.match(CJK_RUN) || []) {
|
|
36
43
|
for (let size = policy.ngramCjkMin; size <= Math.min(policy.ngramCjkMax, run.length); size += 1) {
|
|
37
|
-
for (let i = 0; i + size <= run.length; i += 1)
|
|
44
|
+
for (let i = 0; i + size <= run.length; i += 1) {
|
|
45
|
+
const fragment = run.slice(i, i + size)
|
|
46
|
+
if (fragment !== surface) fragments.add(fragment)
|
|
47
|
+
}
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
|
-
for (const token of value.match(LATIN_RUN) || []) {
|
|
41
|
-
if (token.length >= policy.latinMin && token.length <= policy.latinMax) set.add(token)
|
|
42
|
-
}
|
|
43
50
|
}
|
|
44
51
|
|
|
45
|
-
/** Quoted spans and name-intro neighbours, collected once per library. */
|
|
46
52
|
function surfaceEvidence(docs, policy) {
|
|
47
53
|
const quoted = new Set()
|
|
48
54
|
const intro = new Set()
|
|
55
|
+
const fragments = new Set()
|
|
56
|
+
const fullRuns = new Set()
|
|
49
57
|
for (const { text } of docs) {
|
|
50
|
-
const source = String(text || '')
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
const source = String(text || '').normalize('NFKC').toLowerCase()
|
|
59
|
+
const quotesByStart = new Map()
|
|
60
|
+
for (const match of source.matchAll(QUOTED_SURFACE)) {
|
|
61
|
+
const value = match.slice(1).find(part => part !== undefined)
|
|
62
|
+
quotesByStart.set(match.index, value)
|
|
63
|
+
collectSurface(value, quoted, fragments, policy)
|
|
64
|
+
}
|
|
65
|
+
for (const match of source.matchAll(INTRO_RE)) {
|
|
66
|
+
const start = match.index + match[0].length
|
|
67
|
+
const value = quotesByStart.get(start) ?? source.slice(start).match(START_SURFACE)?.[0]
|
|
68
|
+
if (value) collectSurface(value, intro, fragments, policy)
|
|
69
|
+
}
|
|
70
|
+
for (const run of source.match(SURFACE_RUN) || []) fullRuns.add(run)
|
|
56
71
|
}
|
|
57
|
-
return { quoted, intro }
|
|
72
|
+
return { quoted, intro, fragments, fullRuns }
|
|
58
73
|
}
|
|
59
74
|
|
|
60
75
|
function llrFor(term, tf, unigram, ngramTotals) {
|
|
@@ -213,7 +228,7 @@ function scoreOf(stat, { size, quoted, mixed, intro, titleBoost, lexiconTier1, l
|
|
|
213
228
|
*/
|
|
214
229
|
export function rankCandidates(entries, stats, { policy = AUTOLINK_POLICY_V3, lexiconUser = new Set(), lexiconModel = new Set() } = {}) {
|
|
215
230
|
const docs = entries.map(({ text, title }) => ({ text: `${title || ''}\n${text || ''}` }))
|
|
216
|
-
const { quoted, intro } = surfaceEvidence(docs, policy)
|
|
231
|
+
const { quoted, intro, fragments, fullRuns } = surfaceEvidence(docs, policy)
|
|
217
232
|
const size = Math.max(1, entries.length)
|
|
218
233
|
const tier1 = []
|
|
219
234
|
const tier2 = []
|
|
@@ -232,6 +247,7 @@ export function rankCandidates(entries, stats, { policy = AUTOLINK_POLICY_V3, le
|
|
|
232
247
|
const isIntro = intro.has(term)
|
|
233
248
|
const lexiconTier1 = lexiconUser.has(normalized)
|
|
234
249
|
const lexiconModelHit = !lexiconTier1 && lexiconModel.has(normalized)
|
|
250
|
+
if (fragments.has(term) && !isQuoted && !isIntro && !lexiconTier1 && !fullRuns.has(term)) continue
|
|
235
251
|
const titleBoost = stat.titleDf >= policy.minTitleDf
|
|
236
252
|
const row = {
|
|
237
253
|
term,
|
|
@@ -54,9 +54,9 @@ export const RUNTIME_STATE = Object.freeze([
|
|
|
54
54
|
{ layer: 'temporary-map', file: 'lib/inbound.js:13', name: 'calls', keyedBy: 'sessionId', clearedBy: 'tool/result or turn/end' },
|
|
55
55
|
{ layer: 'temporary-map', file: 'lib/inbound.js:14', name: 'sessions', keyedBy: 'sessionId', clearedBy: 'session/disposed (releaseInboundSession)' },
|
|
56
56
|
{ layer: 'temporary-map', file: 'lib/media.js:19', name: 'captures', keyedBy: 'sessionId', clearedBy: 'capture settle' },
|
|
57
|
-
{ layer: 'temporary-map', file: 'lib/private.js:
|
|
57
|
+
{ layer: 'temporary-map', file: 'lib/private.js:1040', name: 'inFlight', keyedBy: 'sessionId', clearedBy: 'consolidation settle' },
|
|
58
58
|
{ layer: 'temporary-map', file: 'lib/curator.js:56', name: 'jobs', keyedBy: 'job id', clearedBy: 'curation settle' },
|
|
59
|
-
{ layer: 'cache', file: 'lib/state.js:
|
|
59
|
+
{ layer: 'cache', file: 'lib/state.js:1461', name: 'indexCache', keyedBy: 'libraryId', clearedBy: 'next load / external write' },
|
|
60
60
|
{ layer: 'cache', file: 'lib/paths.js:52', name: 'readFailures', keyedBy: 'absolute file', clearedBy: 'a later successful read' },
|
|
61
61
|
])
|
|
62
62
|
|