dsh-memu-memory 1.2.7 → 1.2.8
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/AGENTS.md +1 -1
- package/README.md +10 -15
- package/README.zh.md +10 -15
- package/docs/memory-semantics.md +23 -3
- package/lib/backup.js +1 -1
- package/lib/budget.js +31 -0
- package/lib/commitment.js +138 -0
- package/lib/consolidation-receipt.js +2 -0
- package/lib/consolidation-worker.js +3 -0
- package/lib/freshness.js +24 -0
- package/lib/inject.js +117 -10
- package/lib/lexicon.js +1 -1
- package/lib/local-vector-service.js +4 -1
- package/lib/memory.js +565 -32
- package/lib/memu.js +4 -0
- package/lib/private.js +5 -3
- package/lib/prompts/private-consolidation.mixed.md +2 -2
- package/lib/prompts/private-consolidation.rp.md +6 -1
- package/lib/prompts/private-policy.rp.md +4 -0
- package/lib/prompts/system-guide.rp.md +3 -0
- package/lib/recall-cache.js +10 -2
- package/lib/rpc.js +9 -2
- package/lib/snippet.js +25 -0
- package/lib/temporal.js +329 -0
- package/lib/text-retrieval.js +71 -0
- package/lib/tools.js +81 -4
- package/package.json +1 -1
- package/scripts/bench-recall.mjs +2 -2
- package/scripts/check-seed-compat.mjs +1 -1
- package/tests/backup.test.mjs +2 -2
- package/tests/commitment.test.mjs +144 -0
- package/tests/consolidation-fork.test.mjs +3 -3
- package/tests/disclosure.test.mjs +34 -17
- package/tests/fact-version.test.mjs +128 -0
- package/tests/help-page.test.mjs +1 -1
- package/tests/inject-conflict.test.mjs +94 -0
- package/tests/inject-guide.test.mjs +5 -3
- package/tests/inject.test.mjs +2 -2
- package/tests/injection-intent-budget.test.mjs +92 -0
- package/tests/lexicon-frequency.test.mjs +1 -1
- package/tests/memory-chain.test.mjs +140 -0
- package/tests/memory-fields.test.mjs +134 -0
- package/tests/memu-resident.test.mjs +33 -0
- package/tests/prompt-semantics.test.mjs +51 -0
- package/tests/query-decompose.test.mjs +62 -0
- package/tests/recall-cache.test.mjs +4 -2
- package/tests/recall-intent.test.mjs +100 -0
- package/tests/speaker-provenance.test.mjs +120 -0
- package/tests/temporal.test.mjs +124 -0
package/AGENTS.md
CHANGED
|
@@ -65,7 +65,7 @@ node scripts/acceptance-local.mjs # 50/50
|
|
|
65
65
|
npm run check # node --check + i18n + package.json + 文档预算
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
**结果口径**:以 `node --test` 输出的 `ℹ tests / pass / fail / skipped` 为准。用例数变了先问「是不是我加的」,失败先问「是不是并发写了同一个库」——这仓库真会多个会话同时改它。测试数字只作**带日期快照**引用(2026-11-
|
|
68
|
+
**结果口径**:以 `node --test` 输出的 `ℹ tests / pass / fail / skipped` 为准。用例数变了先问「是不是我加的」,失败先问「是不是并发写了同一个库」——这仓库真会多个会话同时改它。测试数字只作**带日期快照**引用(2026-11-06 实测 1473 tests / 1471 pass / 0 fail / 2 skipped;两条真实引擎用例按设计跳过,历史 1293/1291/1287/1280/1277/1273/1210/505/493/463/409/392 等不再代表当前),不当成当前保证。提交前逐条对 `docs/contributing.md` §10。
|
|
69
69
|
|
|
70
70
|
---
|
|
71
71
|
|
package/README.md
CHANGED
|
@@ -23,14 +23,18 @@
|
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
`dsh-memu-memory` is built for long-form RP and companion chats. It gives a DSH conversation a memory that behaves like memory instead of a log: three retention layers that fade, a first-turn anchor plus at most one per-turn recall, provenance that cannot be quietly upgraded from "I inferred it" to "they said it", contradictions that wait for a decision instead of
|
|
26
|
+
`dsh-memu-memory` is built for long-form RP and companion chats. It gives a DSH conversation a memory that behaves like memory instead of a log: three retention layers that fade, a first-turn anchor plus at most one per-turn recall, provenance that cannot be quietly upgraded from "I inferred it" to "they said it", contradictions that either wait for a decision or — when explicitly versioned — stay side by side with a conflict card instead of being silently merged, near-identical facts collapse to one entry and one recall seat, and an optional relationship graph with evidence. Speakers, characters, worlds and story branches form hard boundaries, and what a character is allowed to know stays separate from what actually happened.
|
|
27
27
|
|
|
28
28
|
It is **local-first by default**. The default `agent` backend stores full text in JSON indexes and recalls lexically — no Python, no embedding service, no API key. The `api` backend switches recall to the optional, pinned MemU engine (vector search). MemU is a plugin for people who want it, not a requirement for the plugin to start.
|
|
29
29
|
|
|
30
30
|
> [!WARNING]
|
|
31
31
|
> **Early-stage software.** This plugin is still early and may contain unforeseen errors, bugs or breaking changes. Back up your data, and please [report an issue](https://github.com/Tkingxiao/dsh-memu-memory/issues) or send a pull request — feedback helps the project improve.
|
|
32
32
|
|
|
33
|
-
> **Status:** 1.2.
|
|
33
|
+
> **Status:** 1.2.8. The first public release was 1.0.0. The manual now lives in [`docs/`](docs/), with [`AGENTS.md`](AGENTS.md) as a short index. Back up `~/.dsh/dsh-memu-memory` before upgrades, and read [Compatibility & limits](#compatibility--limits) before storing data you cannot re-create.
|
|
34
|
+
|
|
35
|
+
## Benchmark
|
|
36
|
+
|
|
37
|
+
The public [chat-memory-benchmark](https://github.com/Ornn8/chat-memory-benchmark) full 714-question run (2026-11-06, `dys-router / deepseek-v4.1-flash`, high reasoning) passed **653 / 714 (91.46%)**. The run's actual measured memory cost was **¥16.05**; the full run, including non-memory overhead, cost **¥24.45** (75,517,851 tokens total, at the provider's off-peak rate) — measured end to end, not extrapolated from a single session.
|
|
34
38
|
|
|
35
39
|
## Screenshots
|
|
36
40
|
|
|
@@ -60,10 +64,10 @@ All screenshots are the real WebUI on isolated example data, not anyone's memori
|
|
|
60
64
|
- **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
65
|
- **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.
|
|
62
66
|
- **Private links are algorithm-first.** After consolidation, a zero-token pass connects memories that share a rare name or alias in the same context/track and creates/reuses an entity hub (for example `yuike`). Uncertain pairs are handed to the consolidation worker for an evidence-based decision. Links are metadata (`source: 'auto'`), shown with an “Auto” badge in the graph and removable; they never rewrite a body, write a vector or delete anything.
|
|
63
|
-
- **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.
|
|
67
|
+
- **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.
|
|
64
68
|
- **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.
|
|
65
|
-
- **Provenance is a fact, not a style.** Every entry carries `source` (`user_said` / `
|
|
66
|
-
- **Contradictions
|
|
69
|
+
- **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.
|
|
70
|
+
- **Contradictions do not get silently merged.** An ordinary contradiction still lands as `pending_review`: it is not injected, not recalled, and appears in a review queue until someone accepts or rejects it. When the writer explicitly marks two statements as versions of one fact (`conflicts_with`), both stay active, are recalled together and surface as a conflict card; an explicit `supersedes` retires the old row without deleting its text.
|
|
67
71
|
- **Secrets stay excluded.** `secret` visibility, group-chat channels, characters, worlds, branches and `knownBy` all constrain reads and edits. Automatic recall never injects a `secret` memory, and a `secret` is still readable by an explicit recall from the same folder — it hides a memory from the prompt, it is not a lock. What actually separates two conversations in one folder is the `context` scope (`channelId` / `characterId` / `worldId` / `branchId`); a blank scope on both sides means one shared scope, which is the point of a folder. The old `visibility: 'session'` level is gone — reading turns it into `shared` with its `context` untouched, and `node scripts/migrate-visibility.mjs` rewrites libraries that still store it (`--apply`, backs up first).
|
|
68
72
|
- **People and stories are structured.** Group chat uses stable `speakerId` / `channelId`, not display names. RP uses `characterId` / `worldId` / `branchId`. Relationships are edges with a note and confidence, entities can be renamed without rewriting memory bodies, and the current relationship state (familiarity, trust, warmth, boundaries, promises) is a snapshot that keeps its history and evidence.
|
|
69
73
|
- **Images are pointers and captions, not pretend vision.** Attachments are deduplicated by SHA-256, quota-limited and tiered; an image without a description is remembered as "received an image", never as a scene the model did not see.
|
|
@@ -86,16 +90,7 @@ Four real long sessions from this machine were replayed read-only (no new chat)
|
|
|
86
90
|
|
|
87
91
|
Below-threshold turns on the two small sessions can still wake through starvation; on the 2,000+ event sessions they do not. None of the four had new human input after its real cursor, so none would fork again immediately.
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
| Consolidations/day | Monthly input | Monthly output |
|
|
92
|
-
|---|---:|---:|
|
|
93
|
-
| 2 | ~5.6M | ~0.11M |
|
|
94
|
-
| 4 | ~11M | ~0.23M |
|
|
95
|
-
| 6 | ~17M | ~0.34M |
|
|
96
|
-
| 6 (worst measured fork each) | ~39M | ~0.7M |
|
|
97
|
-
|
|
98
|
-
For scale, the whole 4-hour session tree measured here consumed 132M input and 1.28M output in one day, so active-memory forks are about **0.2%–1%** of the total. These are token counts, not money; cache reads are usually billed at a lower rate. The exact figure depends on turn count, memory-tool steps and how often the session actually goes idle.
|
|
93
|
+
End-to-end accuracy and the measured cost of the 714-question run are in [Benchmark](#benchmark).
|
|
99
94
|
|
|
100
95
|
## One WebUI
|
|
101
96
|
|
package/README.zh.md
CHANGED
|
@@ -23,14 +23,18 @@
|
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
`dsh-memu-memory` 面向长篇 RP 与陪伴对话,给 DSH
|
|
26
|
+
`dsh-memu-memory` 面向长篇 RP 与陪伴对话,给 DSH 一份「像记忆」的记忆,而不是一本日志:三种留存层会淡;首轮有锚点,之后每个用户回合最多召回一次;来源不能被悄悄从「我推断」升级成「对方说过」;互相矛盾的记忆会挂起等待裁决,明确标成同一事实的两个版本则并排保留并给出冲突卡,而不是被悄悄合并;几乎相同的事实只入一条、召回时同簇只占一席;关系可以是一条带证据的边。说话人、角色、世界线与剧情分支构成硬边界,角色「知道什么」与实际发生过什么分开保存。
|
|
27
27
|
|
|
28
28
|
默认**本地优先**。`agent` 后端把完整正文放在 JSON 索引里、用词法检索——不需要 Python、embedding 服务或 API key。`api` 后端才把检索交给可选的、锁定版本的 MemU 引擎(向量)。MemU 是「想要就用」的后端,不是插件能否启动的前提。
|
|
29
29
|
|
|
30
30
|
> [!WARNING]
|
|
31
31
|
> **早期版本提示。** 本插件仍处于早期阶段,可能存在无法预见的错误、bug 或不兼容变更。请先备份数据;欢迎[提交 Issue](https://github.com/Tkingxiao/dsh-memu-memory/issues) 或 PR 帮助改进。
|
|
32
32
|
|
|
33
|
-
> **状态:** 1.2.
|
|
33
|
+
> **状态:** 1.2.8。首个公开发布版本为 1.0.0。细节文档已迁到 [`docs/`](docs/),[`AGENTS.md`](AGENTS.md) 只做索引。升级前请备份 `~/.dsh/dsh-memu-memory`;如果要存无法重建的数据,请先读[兼容性与边界](#兼容性与边界)。
|
|
34
|
+
|
|
35
|
+
## 基准测试
|
|
36
|
+
|
|
37
|
+
公开的 [chat-memory-benchmark](https://github.com/Ornn8/chat-memory-benchmark) 714 题完整卷(2026-11-06,`dys-router / deepseek-v4.1-flash`,high 思考强度)通过 **653 / 714(91.46%)**。同一轮**实测记忆成本为 ¥16.05**;包含非记忆开销的总成本为 **¥24.45**(总 token 75,517,851,谷价),均为端到端实测,不是按单次会话外推。
|
|
34
38
|
|
|
35
39
|
## 界面
|
|
36
40
|
|
|
@@ -58,10 +62,10 @@
|
|
|
58
62
|
|
|
59
63
|
- **三层,一条时间线。** `short_term` 草稿默认 72 小时到期;`long_term` 是记忆主体;`must_remember` 需要理由与来源,按 365 天半衰并带 0.35 强度地板,可以**边缘化**,但不会为腾名额被自动删除。
|
|
60
64
|
- **召回是一个瞬间,不是一次倾倒。** 新会话或压缩后的第一个回合得到锚点块(pin / core / global 分段预算);之后每个用户回合最多一次召回。去重与 token 预算由代码执行,不交给提示词自觉。
|
|
61
|
-
- **日期要么是纪念日,要么是一天。** `MM-DD` 每年复发(生日);`YYYY-MM-DD`
|
|
65
|
+
- **日期要么是纪念日,要么是一天。** `MM-DD` 每年复发(生日);`YYYY-MM-DD` 在前一天和当天各响一次,之后就算用过了。说「今天 / 明天 / 下周X / 月底」的相对日期会按这一轮的场景时间换算成绝对日期再存;说「明天」的记忆存成带年份的日期,不会变成每年都冒出来的周年。
|
|
62
66
|
- **记忆会不均匀地淡。** 新近、访问次数、峰终、首因、习惯化、闪光灯记忆的准确度共同参与强度。情绪用四项构成(joy / anger / sorrow / fear,和为 1)加唤醒度 `arousal`(强度)与掌控感 `dominance` 描述;「嫉妒」这类复合情绪是四项的具名混合比例,不是新维度。情绪只影响召回排序:不进注入文本,也不改记忆正文。门控是三条独立条件的 OR——主导项占比 ≥ 0.35、`|arousal − 0.35| ≥ 0.1`、`|dominance| ≥ 0.25`;三条都不满足时两项乘数恒为 1。旧条目没有 emotion 时继续走原来的 valence 路径,不从旧 valence 反推四轴。一条生动但可能记错的记忆会显示「细节未必准」,而不是假装确定。
|
|
63
|
-
- **来源是事实,不是文风。** 每条记忆带 `source`(`user_said` / `
|
|
64
|
-
-
|
|
67
|
+
- **来源是事实,不是文风。** 每条记忆带 `source` / `source_kind`(`user_said` / `assistant_said` / `told` / `imagined` / `inferred` / `tool`)、`speaker_id`、`confidence`、`accuracy` 与说出口径。模糊的推断不能冒充原话,助手自己的承诺和计划也不能记成用户说的。
|
|
68
|
+
- **矛盾不会被悄悄合并。** 普通矛盾仍进入 `pending_review`:不注入、不召回,只出现在复核队列,等人或整理作业裁决。写入方明确把两种说法标成同一事实的版本(`conflicts_with`)时,两条都保持 active、一起召回并注入一张冲突卡;显式 `supersedes` 才退休旧条,正文不删。
|
|
65
69
|
- **秘密不进自动召回。** `secret`、群聊频道、角色、世界线、剧情分支与 `knownBy` 共同约束读写;`secret` 永远不会被自动注入,但同文件夹里**主动检索仍然读得到**——它挡的是「自己冒出来」,不是保险箱。真正把同一文件夹里的两段对话隔开的是 `context` 作用域(`channelId` / `characterId` / `worldId` / `branchId`);两边都没填就是同一个作用域,这正是「文件夹」的含义。旧的 `visibility: 'session'` 级别已删除:读到就按 `shared` 处理、`context` 原样保留,仍存着该级别的库用 `node scripts/migrate-visibility.mjs` 重写(`--apply` 才写,先备份)。
|
|
66
70
|
- **人与故事是有结构的。** 群聊用稳定的 `speakerId` / `channelId`,不拿显示名当身份;RP 用 `characterId` / `worldId` / `branchId` 隔离知识。关系边有理由和置信度,实体改名不动记忆正文,关系当前状态(熟悉、信任、温度、边界、承诺)是带证据和历史快照。
|
|
67
71
|
- **图片是指针加描述,不是假装能看图。** 附件按 SHA-256 去重、有配额、分三级留存;没有描述时只记「收到一张图片」,绝不编造画面。
|
|
@@ -84,16 +88,7 @@
|
|
|
84
88
|
|
|
85
89
|
两条小会话的未达分数回合仍可能因饥饿唤醒;2000 条事件以上的大会话不会。四个会话在真实游标之后都没有新的真人输入,因此不会立即再 fork。
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
| 每天整理次数 | 每月 input | 每月 output |
|
|
90
|
-
|---|---:|---:|
|
|
91
|
-
| 2 次 | ~5.6M | ~0.11M |
|
|
92
|
-
| 4 次 | ~11M | ~0.23M |
|
|
93
|
-
| 6 次 | ~17M | ~0.34M |
|
|
94
|
-
| 6 次(都按实测最贵的单次) | ~39M | ~0.7M |
|
|
95
|
-
|
|
96
|
-
作为参照,今天这棵 4 小时会话树实测 132M input + 1.28M output/日,主动记忆整理约占 **0.2%~1%**。以上是 token 量,不是金额;缓存读通常按更低单价计费。实际取决于回合数、记忆工具步数和会话真正空闲的次数。
|
|
91
|
+
714 题完整卷的通过率与实测成本见[基准测试](#基准测试)。
|
|
97
92
|
|
|
98
93
|
## 一个 WebUI
|
|
99
94
|
|
package/docs/memory-semantics.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
- 移出永久记忆 = **边缘化**:`marginalized=true`、`strength × 0.2`、召回排序里 `marginalized` 乘以 0.35(`recallPenalty` 字段仅作历史记录,当前不参与排序),**不删除**;条目仍在库里,`marginalReason` 在侧边栏可见(替代人类闸门的**事后**监督)。
|
|
21
21
|
- **unpin 由模型自己判断,侧边栏没有标记按钮、用户不参与。** 三重护栏:① `reason` 必填、第一人称、去空白后 ≥ 20 字符;② 每会话配额 `unpinBudgetPerSession`(默认 2);③ 冷却 `unpinCooldownMinutes`(默认 3)。放行后记 `unpinnedBy: model`、`unpinnedAt`、`originalPinSource`(保留原 pinSource 以便复 pin)。
|
|
22
22
|
- 正当的 unpin 只有两种:想起它本身正在伤人;它已经不再是我的一部分。不正当的:inconvenient、不想面对、用户这轮没提、永久记忆快满了。**这个区别要写进提示词。**
|
|
23
|
-
- 矛盾检测:同库同题改写或说法相反 → 新条挂 `pending_review` + `reviewReason` + `conflictingWith`,**不进注入不进召回**,等 `listReviews` / `resolveReview` 裁决(§3.9
|
|
23
|
+
- 矛盾检测:同库同题改写或说法相反 → 新条挂 `pending_review` + `reviewReason` + `conflictingWith`,**不进注入不进召回**,等 `listReviews` / `resolveReview` 裁决(§3.9)。写入方显式用 `conflicts_with`(或同一显式 `fact_key` 再次写入)声明“同一事实的两个版本”时是例外:两条都保持 active、互指并成对召回,注入为冲突卡(§8.17);明确取代用 `supersedes`。
|
|
24
24
|
|
|
25
25
|
### 8.3 全局记忆
|
|
26
26
|
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
|
|
41
41
|
- 静态 guide 与动态记忆都走 plugin 消息;当前版本不再注册本插件的 system prompt 段。所有会话(含 `persona` `complete: true`)统一由 `lib/inject.js` 的 `ensureUnifiedGuide` 在**回合首步**投放一条 `<memory-guide rules="…">` 插件消息;`rulesKey` 由协议版本、domain 和实际渲染正文计算,domain/覆盖/默认稿变化或压缩丢失(`guideLost`)时在下一个合法首步替换,同一规则不逐回合重复。旧 binding 只有 `guideMessageAt`、没有 `guideRulesKey` 时视为旧版,补投一次;失败 fail-open,不写新版本。
|
|
42
42
|
- 首轮锚点 + 每用户回合最多一次;长工具回合仅有新的真实人类消息批次时追加一次,普通工具步骤不触发。私有优先、全局补充;冲突时私有胜。
|
|
43
|
-
- **锚点和本回合召回只放标题卡**(1.2.2):`formatPrivateTitle` / `formatGlobalTitle` 输出 `[id]`、标题、`source`、owner、layer、日期/年龄、marginalized/open_loop、accuracy/uncertainty/disclosure 与附件计数,**不输出正文与附件 caption**。工具返回、记忆抽屉与浏览器仍是全文;要正文就按标题关键词或方括号里的 id 调 `memu_private_recall` / `memu_global_recall`。标题为空时回退正文前 40 字;`imagined
|
|
43
|
+
- **锚点和本回合召回只放标题卡**(1.2.2):`formatPrivateTitle` / `formatGlobalTitle` 输出 `[id]`、标题、`source`、owner、layer、日期/年龄、marginalized/open_loop、accuracy/uncertainty/disclosure 与附件计数,**不输出正文与附件 caption**。工具返回、记忆抽屉与浏览器仍是全文;要正文就按标题关键词或方括号里的 id 调 `memu_private_recall` / `memu_global_recall`。标题为空时回退正文前 40 字;`imagined` 等语义标签不能因为标题化而丢失。`never_say` 不进入自动注入面,`only_if_asked` 只在 boundary 查询里自动放行(§8.17);显式召回仍可读两者。跨库召回开启时(§8.15),private 标题卡可能来自其它同领域库;id 仍全局唯一,按 id 取正文仍走 `memu_private_recall`,写入仍只落在当前库。
|
|
44
44
|
- **条件式时效提示(工单 D)**:本回合召回块已经生成后,若其中至少一条真正进入文本的条目带时间敏感信号——`salientDate` 是已过去的 `YYYY-MM-DD`(年度 `MM-DD` 不算)、标题/正文命中固定词表 `最新|最近|现在|目前|今年|版本|价格|天气|新闻|比分|汇率`、或 `updatedAt||createdAt` 距现在 ≥ `freshnessDays`(`owner=about_project` 的工程事实不算年龄)——且 `freshnessHint !== false`、用户文本长度 ≥ `minUserChars`,就在最后一个 `</memory-context>` 之后追加**一个** `<memory-freshness>` 块,N 为去重后的 stale 条数。提示与召回共用 `turnTokens` 预算:放不下就丢弃提示,召回本身仍成功(fail-open,计算异常只 `warn`)。它只说「若你的会话里有可用的搜索工具就先核实」,**不声称** `web_search` 一定存在(工具面不确定性见 `docs/host-api.md` §6.8),也不改 `<memory-guide>`/`rulesKey`。`freshnessDays` 默认 30,范围 `[1,3650]`;`freshnessHint` 默认开。
|
|
45
45
|
- **rule 是前言,不是页脚**:`buildAnchor` 先输出锚点头与 `[rule]`,再输出 private/global/short_term 各段;inbound 路径的锚点之后直接衔接 `<memory-context>`,中间不再隔一条规则。
|
|
46
46
|
- **`injectedIds` 只能记真正进入文本的条目**,否则从未展示的记忆被白白压制 8 轮。
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
| 附件像素 | ✅ | ❌(`hidden: true`;`never_say` 的 caption 也不回显) |
|
|
80
80
|
|
|
81
81
|
- 所以 `secret` 的实际边界是「**不被自动注入、不当回响源、附件不出像素**」;同一文件夹里另一个会话**主动检索时照样能拿到**。它挡的是「自己冒出来」,不是「别人查到」。要「跨会话绝不外泄」,靠 §8.7 的上下文边界,不是 `secret`。
|
|
82
|
-
- 「只有我知道」= `disclosure: never_say
|
|
82
|
+
- 「只有我知道」= `disclosure: never_say`(不进入任何自动注入面,显式召回仍可读)+ `secret`(不自动浮现、附件不出像素)两个字段的组合,不是加密。侧边栏和记忆墙始终能看到正文——这是**事后监督**的设计,不是疏漏。
|
|
83
83
|
- 全局 curator 读的是会话日志与全局库,不读私有库条目(`compactGlobalIndex`),所以 `secret` 不会被复制进「每会话都注入」的全局记忆;跨文件夹(不同库)之间的私有召回**默认隔离**,只有显式打开 `crossLibraryRecall` 才会合并同领域库,且只读——见 §8.15。
|
|
84
84
|
|
|
85
85
|
### 8.7 上下文作用域:`channelId / characterId / worldId / branchId` + `knownBy`
|
|
@@ -201,3 +201,23 @@
|
|
|
201
201
|
|
|
202
202
|
---
|
|
203
203
|
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### 8.17 1.2.8:时间、版本、来源、承诺与召回意图
|
|
208
|
+
|
|
209
|
+
这一节只描述新增字段与策略,不改原有三层、可见范围与注入纪律。所有字段对旧数据都是**可选**:缺字段按空处理,不强制迁移,写入时补齐。
|
|
210
|
+
|
|
211
|
+
**时间**:写入时按这一轮的逻辑时间解析相对日期,落在 `event_time` / `observed_at`(ISO)、`absolute_date`(YYYY-MM-DD)、`date_precision`(`day|month|year|unknown`)、`date_source`(`explicit|relative`)。逻辑时间优先 `context.occurredAt`,其次会话 `sceneTime`,最后才是墙上时钟;解析失败不猜,只有确实出现相对时间词时才标 `date_precision=unknown`。原文保留在 `content`,不改写用户原话。`valid_from` / `valid_to` 是可选的有效窗口(`valid_from <= 今天 <= valid_to`),缺字段的旧条目照常召回;旧复核路径写的 `validFrom/validTo` 也会被识别。召回查询里的“明天/下周三/月底”同样先解析成绝对日期再检索,时间题注入按 `absolute_date` 最近优先排序。
|
|
212
|
+
|
|
213
|
+
**版本与冲突**:每条新记忆都有 `fact_key`(显式传入或由 `owner + 标题` 归一化)与 `version`。显式 `conflicts_with` 或“同一显式 fact_key 的再次写入”会让新旧两条都保持 `active`、互指 `conflicts_with`,召回命中一侧时另一侧成对带回,注入成一张 200 字内的冲突卡(“未确认哪版为准”)。显式 `supersedes` 才是取代:旧条 `status=superseded`、`valid_to` 落日期、正文与标题不删不改。兼容补充仍走 `memu_private_update`,保留原 id,不增加版本。旧的无关系字段的冲突仍按原路径进入 `pending_review`,行为不变。
|
|
214
|
+
|
|
215
|
+
**来源**:新增 `speaker_id`、`source_kind`(`user_said|assistant_said|told|imagined|inferred|tool`)、`quote_span`(`{seq, turn, textHash}`)、`storyline_id`、`branch_id`、`known_by`。`speaker_id` 显式 > `context.speakerId` > 按 `source_kind` 的 `user/assistant/tool/unknown`;不猜。助手自己的承诺、计划、事实用 `assistant_said`,不能记成用户说的。查询“我说过/你说过/他说的”时按说话人过滤:只排除明确属于别人的条目,缺 speaker 的旧条目保留。注入标题卡会显示非默认的 `speaker=`。
|
|
216
|
+
|
|
217
|
+
**承诺**:`commitment = {counterparty, action, due_at, status, closed_by, evidence_seq}`,`status` 是 `open|done|cancelled|expired`,也是权威;`open_loop` 只做兼容并随 `status` 同步。`open_loop=true` 的旧写法会派生一条 `open` 承诺,`due_at` 取本轮已解析日期。到期/临期(逾期、今天、明天)的未完成承诺最多 3 条、按 `due_at` 升序进一张 `[commitment]` 小卡;远期承诺不占每回合预算。`dueOpenLoops` 也优先看 `commitment.status` 与 `due_at`。
|
|
218
|
+
|
|
219
|
+
**召回意图**:`lib/text-retrieval.js` 的 `detectQueryIntent` / `decomposeQuery` 把查询分成 `date|entity|conflict|commitment|boundary|general`;日期与引号/`@`/已知实体名会被拆成可检索词。各意图的候选上限见 `lib/budget.js` 的 `RECALL_INTENT_TOPK`(general 5、date/entity 8、conflict 6、commitment/boundary 5),调用方显式给的更大 topK 不被压低,封顶 20。命中条目沿 `links` 扩展一跳(最多 2 条,实体题 3 条),只沿显式关系走。`disclosure` 现在是“何时能自动出现”的门:`never_say` 不进任何自动注入面(锚点、自动召回、提醒),`only_if_asked` 只在 `boundary` 意图的查询里自动放行;显式 `memu_private_recall` 仍可读两者。
|
|
220
|
+
|
|
221
|
+
**可观测性**:`getState` 增加 `recallCache` 段(`hits/misses/evictions/errors/staleSkipped/generations/...`);`staleSkipped` 统计 TTL 过期、代数清理与按 query 失效时被丢弃的缓存条目。
|
|
222
|
+
|
|
223
|
+
守卫:`tests/temporal.test.mjs`、`tests/memory-fields.test.mjs`、`tests/fact-version.test.mjs`、`tests/inject-conflict.test.mjs`、`tests/speaker-provenance.test.mjs`、`tests/commitment.test.mjs`、`tests/query-decompose.test.mjs`、`tests/recall-intent.test.mjs`、`tests/injection-intent-budget.test.mjs`、`tests/memory-chain.test.mjs`。
|
package/lib/backup.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from './paths.js'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Local-vector backup policy - safe latest-three backup retention.
|
|
12
12
|
*
|
|
13
13
|
* One rule, one place. Every managed backup of the current data root is created
|
|
14
14
|
* by createBackup(), published atomically, and only then may the oldest
|
package/lib/budget.js
CHANGED
|
@@ -94,3 +94,34 @@ export function packToBudget(items, maxTokens, render) {
|
|
|
94
94
|
}
|
|
95
95
|
return { lines, ids, used, omitted: Math.max(0, items.length - ids.length) }
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
// S6 意图预算:不同问题需要的候选数不同。时间/实体题需要更大的时间线或实体卡
|
|
99
|
+
// 面(8),冲突题 6 条成对,承诺/边界 5 条。用户显式设置的更大值不会被压低,
|
|
100
|
+
// 但也不会超过 20 条。
|
|
101
|
+
export const RECALL_INTENT_TOPK = Object.freeze({
|
|
102
|
+
general: 5,
|
|
103
|
+
date: 8,
|
|
104
|
+
entity: 8,
|
|
105
|
+
conflict: 6,
|
|
106
|
+
commitment: 5,
|
|
107
|
+
boundary: 5,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
export function intentTopK(intent, requested) {
|
|
111
|
+
const preset = RECALL_INTENT_TOPK[intent] ?? RECALL_INTENT_TOPK.general
|
|
112
|
+
const asked = Number(requested)
|
|
113
|
+
const hasAsked = Number.isFinite(asked) && asked > 0
|
|
114
|
+
// general 尊重调用方显式设置的更小值;专项意图(时间/实体/冲突…)需要更多证据,
|
|
115
|
+
// 只升不降,但同样封顶 20。
|
|
116
|
+
const wanted = !RECALL_INTENT_TOPK[intent] || intent === 'general'
|
|
117
|
+
? (hasAsked ? asked : preset)
|
|
118
|
+
: Math.max(hasAsked ? asked : 0, preset)
|
|
119
|
+
return Math.max(1, Math.min(20, wanted))
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function recallIntentBudget(intent, settings = {}) {
|
|
123
|
+
return {
|
|
124
|
+
intent: RECALL_INTENT_TOPK[intent] ? intent : 'general',
|
|
125
|
+
topK: intentTopK(intent, settings.privateTopK),
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// 承诺 / 欠账。
|
|
2
|
+
//
|
|
3
|
+
// `commitment.status` 是权威,`open_loop` 只保留做旧数据兼容:
|
|
4
|
+
// open → 还没兑现;done → 已兑现;cancelled → 明确取消;expired → 过期未完成。
|
|
5
|
+
// due_at 接受 YYYY-MM-DD 或 ISO 时间;比较按“到期那一天”算,不按时分秒。
|
|
6
|
+
|
|
7
|
+
export const COMMITMENT_STATUSES = ['open', 'done', 'cancelled', 'expired']
|
|
8
|
+
|
|
9
|
+
const DAY_MS = 86_400_000
|
|
10
|
+
const DATE_ONLY_RE = /^(\d{4})-(\d{2})-(\d{2})$/
|
|
11
|
+
|
|
12
|
+
function cleanText(value, max) {
|
|
13
|
+
if (value === undefined || value === null) return ''
|
|
14
|
+
return String(value).replace(/\s+/g, ' ').trim().slice(0, max)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function validDateOnly(text) {
|
|
18
|
+
const match = DATE_ONLY_RE.exec(text)
|
|
19
|
+
if (!match) return false
|
|
20
|
+
const year = Number(match[1])
|
|
21
|
+
const month = Number(match[2])
|
|
22
|
+
const day = Number(match[3])
|
|
23
|
+
if (month < 1 || month > 12 || day < 1) return false
|
|
24
|
+
return day <= new Date(Date.UTC(year, month, 0)).getUTCDate()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** YYYY-MM-DD or an ISO timestamp; anything else is refused. */
|
|
28
|
+
export function normalizeDueAt(value) {
|
|
29
|
+
if (value === undefined || value === null) return null
|
|
30
|
+
const text = String(value).trim()
|
|
31
|
+
if (!text) return null
|
|
32
|
+
if (DATE_ONLY_RE.test(text)) {
|
|
33
|
+
if (!validDateOnly(text)) throw new Error('commitment.due_at must be YYYY-MM-DD or an ISO date/time')
|
|
34
|
+
return text
|
|
35
|
+
}
|
|
36
|
+
const at = Date.parse(text)
|
|
37
|
+
if (!Number.isFinite(at)) throw new Error('commitment.due_at must be YYYY-MM-DD or an ISO date/time')
|
|
38
|
+
return new Date(at).toISOString()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function dueDateText(value) {
|
|
42
|
+
if (!value) return null
|
|
43
|
+
if (DATE_ONLY_RE.test(value)) return value
|
|
44
|
+
const at = new Date(value)
|
|
45
|
+
return Number.isFinite(at.getTime()) ? `${at.getUTCFullYear()}-${String(at.getUTCMonth() + 1).padStart(2, '0')}-${String(at.getUTCDate()).padStart(2, '0')}` : null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function localDateKey(now) {
|
|
49
|
+
const at = now instanceof Date ? now : new Date(now)
|
|
50
|
+
const safe = Number.isFinite(at.getTime()) ? at : new Date()
|
|
51
|
+
return `${safe.getFullYear()}-${String(safe.getMonth() + 1).padStart(2, '0')}-${String(safe.getDate()).padStart(2, '0')}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function daysBetween(fromKey, toKey) {
|
|
55
|
+
if (!fromKey || !toKey) return null
|
|
56
|
+
const from = Date.UTC(...fromKey.split('-').map((part, index) => index === 1 ? Number(part) - 1 : Number(part)))
|
|
57
|
+
const to = Date.UTC(...toKey.split('-').map((part, index) => index === 1 ? Number(part) - 1 : Number(part)))
|
|
58
|
+
return Math.round((to - from) / DAY_MS)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 归一一条承诺。显式传对象时字段错误会抛(写盘前拒绝,不静默改),
|
|
63
|
+
* 读取旧数据用 commitmentOf 的宽容口径。
|
|
64
|
+
*/
|
|
65
|
+
export function normalizeCommitment(value, { fallbackAction = '', fallbackDueAt = null } = {}) {
|
|
66
|
+
if (value === undefined || value === null) return null
|
|
67
|
+
if (typeof value !== 'object' || Array.isArray(value)) throw new Error('commitment must be an object')
|
|
68
|
+
const status = value.status === undefined || value.status === null || value.status === ''
|
|
69
|
+
? 'open' : String(value.status)
|
|
70
|
+
if (!COMMITMENT_STATUSES.includes(status)) {
|
|
71
|
+
throw new Error(`commitment.status must be ${COMMITMENT_STATUSES.join(', ')}`)
|
|
72
|
+
}
|
|
73
|
+
const action = cleanText(value.action ?? fallbackAction, 500)
|
|
74
|
+
if (!action) throw new Error('commitment.action is required')
|
|
75
|
+
const counterparty = cleanText(value.counterparty, 128) || null
|
|
76
|
+
const due = value.due_at ?? value.dueAt ?? fallbackDueAt
|
|
77
|
+
const dueAt = normalizeDueAt(due)
|
|
78
|
+
const closedByRaw = value.closed_by ?? value.closedBy ?? null
|
|
79
|
+
const evidenceRaw = value.evidence_seq ?? value.evidenceSeq ?? null
|
|
80
|
+
return {
|
|
81
|
+
counterparty,
|
|
82
|
+
action,
|
|
83
|
+
due_at: dueAt,
|
|
84
|
+
status,
|
|
85
|
+
closed_by: closedByRaw === null || closedByRaw === undefined || closedByRaw === ''
|
|
86
|
+
? null : String(closedByRaw).slice(0, 128),
|
|
87
|
+
evidence_seq: evidenceRaw === null || evidenceRaw === undefined || evidenceRaw === ''
|
|
88
|
+
? null : (Number.isSafeInteger(Number(evidenceRaw)) ? Number(evidenceRaw) : String(evidenceRaw).slice(0, 128)),
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Tolerant read for stored entries; a malformed object never crashes recall. */
|
|
93
|
+
export function commitmentOf(entry) {
|
|
94
|
+
if (!entry || typeof entry !== 'object' || !entry.commitment || typeof entry.commitment !== 'object') return null
|
|
95
|
+
try {
|
|
96
|
+
return normalizeCommitment(entry.commitment)
|
|
97
|
+
} catch {
|
|
98
|
+
return null
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** open_loop 兼容口径:有 commitment 就看 status,没有才看旧布尔值。 */
|
|
103
|
+
export function isOpenThread(entry) {
|
|
104
|
+
const commitment = commitmentOf(entry)
|
|
105
|
+
if (commitment) return commitment.status === 'open'
|
|
106
|
+
return entry?.openLoop === true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 承诺的到期日(YYYY-MM-DD);没有 due_at 返回 null。 */
|
|
110
|
+
export function commitmentDueDate(entry) {
|
|
111
|
+
const commitment = commitmentOf(entry)
|
|
112
|
+
if (!commitment) return null
|
|
113
|
+
return dueDateText(commitment.due_at)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 到期状态。`dueSoon` 只覆盖今天和明天:一张每回合都出现的承诺卡会变成噪声,
|
|
118
|
+
* 真正的“到期/逾期”才值得占预算。
|
|
119
|
+
*/
|
|
120
|
+
export function commitmentDueState(entryOrCommitment, { now = Date.now() } = {}) {
|
|
121
|
+
const commitment = entryOrCommitment?.status && entryOrCommitment?.action
|
|
122
|
+
? entryOrCommitment
|
|
123
|
+
: commitmentOf(entryOrCommitment)
|
|
124
|
+
if (!commitment || commitment.status !== 'open' || !commitment.due_at) {
|
|
125
|
+
return { open: commitment?.status === 'open', dueAt: null, daysUntil: null, overdue: false, dueSoon: false }
|
|
126
|
+
}
|
|
127
|
+
const dueAt = dueDateText(commitment.due_at)
|
|
128
|
+
const daysUntil = daysBetween(localDateKey(now), dueAt)
|
|
129
|
+
return {
|
|
130
|
+
open: true,
|
|
131
|
+
dueAt,
|
|
132
|
+
daysUntil,
|
|
133
|
+
overdue: daysUntil !== null && daysUntil < 0,
|
|
134
|
+
dueSoon: daysUntil !== null && daysUntil <= 1,
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { DAY_MS }
|
|
@@ -197,6 +197,8 @@ export function reconcileReceipt({ receipt, index = null, beforeIds = null, befo
|
|
|
197
197
|
for (const id of receipt?.heldIds || []) {
|
|
198
198
|
const entry = entries[id]
|
|
199
199
|
if (!entry) { missing.push(id); continue }
|
|
200
|
+
// S7.3:heldIds 只表示“仅 pending_review”。已经以 active 落库的矛盾条目属于
|
|
201
|
+
// 正常写入证据,应写在 createdIds/updatedIds,不能混进 held。
|
|
200
202
|
if (entry.status !== 'pending_review') { problems.push('held id ' + id + ' is not pending_review'); continue }
|
|
201
203
|
heldIds.push(id)
|
|
202
204
|
}
|
|
@@ -153,6 +153,9 @@ export function buildWorkerBrief({ snapshot, probe = null, contract = '', reason
|
|
|
153
153
|
'转录开头的 [memory-catalog · 已有记忆目录] 是本库已有条目,只用来去重/合并,不是对话内容,也不是用户发言。',
|
|
154
154
|
'本轮可用的工具:' + tools + '。',
|
|
155
155
|
'要做的:先按主题检索相关旧条目去重;同一事实的补充用 memu_private_update 合并(先拿到 id);真正新增、或与已有说法矛盾的内容用 memu_private_remember 一条一件;矛盾不要自己裁决,让它进待复核。',
|
|
156
|
+
'写库前必须落 speaker_id、source_kind、absolute_date:今天/明天/下周X/月底这类相对日期要按本轮时间算成绝对日期,不能只留原文;解析不了就标 date_precision=unknown,不要猜。',
|
|
157
|
+
'同一事实有两种说法时各写一条,用 conflicts_with 互指,不合并、不自行裁决;只有明确取代才用 supersedes,旧正文保留。助手说过的承诺、计划、事实同样要写,source_kind=assistant_said,不能记成用户说的。',
|
|
158
|
+
'承诺/约定写 commitment(对谁/做什么/due_at/status);到期未完成的承诺要留在库里,让后续注入能看到。每窗最多新增 10 条,值得留的日常事实即使琐碎也要写。',
|
|
156
159
|
'写完(remember/update 拿到 id)后调用 memu_private_link_suggest({ids:[...]}),把本轮创建/更新的 id 都传进去:高置信的记忆↔记忆关联与实体枢纽算法已经自动连好,只有不确定的候选交给你裁决。不回读整段会话,也不为这个另起一次整理。',
|
|
157
160
|
'候选只用 memu_private_link 裁决:note 要引用转录原话,同一实体或同一事件确有证据才 link;证据不足或拿不准就 noop;互相矛盾就 conflict,不 link。每轮最多确认 5 条,不要为每一对都连;不要为了这件事把整个记忆库读一遍。',
|
|
158
161
|
'词典抽取:遇到稳定、可复用、有证据的黑话/梗/术语,先用 memu_lexicon_search 查重,再用 memu_lexicon_propose 一条一词写入。term 是索引键(短、稳定、用户的真实写法),meaning 才是解释;不写 sensitive trigger,也不写只属于这一次剧情的一次性词。',
|
package/lib/freshness.js
CHANGED
|
@@ -51,6 +51,30 @@ function timestampMs(value) {
|
|
|
51
51
|
return Number.isFinite(at) ? at : null
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
function localDateKey(now) {
|
|
55
|
+
const at = new Date(baseTime(now))
|
|
56
|
+
return `${at.getFullYear()}-${String(at.getMonth() + 1).padStart(2, '0')}-${String(at.getDate()).padStart(2, '0')}`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* S1 的有效窗口:`valid_from <= scene day <= valid_to`。两个字段缺失都不影响召回
|
|
61
|
+
* (旧数据没有它们);只有显式写下的窗口才能把条目挡在召回之外。
|
|
62
|
+
* 返回的 reasons 用于活动日志/测试,调用方只关心 valid。
|
|
63
|
+
*/
|
|
64
|
+
export function validitySignals(entry, { now = Date.now() } = {}) {
|
|
65
|
+
const reasons = []
|
|
66
|
+
if (!entry || typeof entry !== 'object') return { valid: true, reasons }
|
|
67
|
+
const today = localDateKey(now)
|
|
68
|
+
// S1 用 snake_case;旧复核路径写过 validFrom/validTo,两个都要认。
|
|
69
|
+
const from = datedValue(entry.valid_from ?? entry.validFrom)
|
|
70
|
+
const to = datedValue(entry.valid_to ?? entry.validTo)
|
|
71
|
+
// An unfinished/invalid window is ignored rather than treated as "always valid":
|
|
72
|
+
// a repair should never make a memory vanish for the rest of the day.
|
|
73
|
+
if (from && today < from.text) reasons.push(`valid-from-future:${from.text}`)
|
|
74
|
+
if (to && today > to.text) reasons.push(`valid-to-past:${to.text}`)
|
|
75
|
+
return { valid: reasons.length === 0, reasons }
|
|
76
|
+
}
|
|
77
|
+
|
|
54
78
|
function thresholdDays(value) {
|
|
55
79
|
const days = Number(value)
|
|
56
80
|
return Number.isFinite(days) && days >= 0 ? days : DEFAULT_FRESHNESS_DAYS
|