@alanzhao/dsh-memory-lite 0.4.0 → 0.5.1
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/README.en.md +27 -4
- package/README.md +27 -4
- package/lib/config.d.ts +22 -2
- package/lib/config.js +29 -1
- package/lib/config.js.map +1 -1
- package/lib/extract/decision.d.ts +16 -0
- package/lib/extract/decision.js +60 -2
- package/lib/extract/decision.js.map +1 -1
- package/lib/extract/index.d.ts +35 -2
- package/lib/extract/index.js +138 -41
- package/lib/extract/index.js.map +1 -1
- package/lib/extract/prompt.d.ts +4 -0
- package/lib/extract/prompt.js +64 -5
- package/lib/extract/prompt.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/memory-store.d.ts +44 -5
- package/lib/memory-store.js +129 -19
- package/lib/memory-store.js.map +1 -1
- package/lib/patch.d.ts +67 -0
- package/lib/patch.js +179 -0
- package/lib/patch.js.map +1 -0
- package/lib/status.js +2 -0
- package/lib/status.js.map +1 -1
- package/lib/tools/remember.js +3 -1
- package/lib/tools/remember.js.map +1 -1
- package/lib/tools/update-memory.js +2 -2
- package/lib/tools/update-memory.js.map +1 -1
- package/package.json +3 -2
package/README.en.md
CHANGED
|
@@ -28,7 +28,7 @@ After installing you should see:
|
|
|
28
28
|
- a full settings page under **Settings → memory-lite** (screenshot below)
|
|
29
29
|
- ask the model to remember something ("remember that I use pnpm") — it calls `remember` and a file lands under `~/.agent-memory/peers/<peer>/memories/preferences/` (directories are created on first use)
|
|
30
30
|
|
|
31
|
-
Compatibility: **dsh ≥ 0.1.5** (
|
|
31
|
+
Compatibility: **dsh ≥ 0.1.5** (full support for dsh 0.2.1-rc.2 specification and engines constraint, seamless integration with Working Directory decoupling and managed Subagent Activation isolation; dual-track compatibility for 0.1.7+ SettingsForms/configForms, backward compatible to 0.1.5), Node ≥ 22.
|
|
32
32
|
|
|
33
33
|
<p align="center">
|
|
34
34
|
<img src="docs/preview/settings-extraction.png" alt="Settings → memory-lite: extraction mode and triggers" width="560">
|
|
@@ -40,7 +40,7 @@ Compatibility: **dsh ≥ 0.1.5** (dual-track compatibility for dsh 0.1.7 Setting
|
|
|
40
40
|
|---|---|
|
|
41
41
|
| Explicit memory (5 tools) | `read_memory` / `search_memory` / `remember` / `update_memory` / `forget_memory`; `update` archives the previous content into `## History`, `forget` is a soft delete into `.trash/` |
|
|
42
42
|
| L0 catalog injection | one resident catalog message per session (rendered from `_index.md`); re-published when the index changes or compaction moves it off the visible surface |
|
|
43
|
-
| Implicit extraction | a background run feeds the new conversation window to the model and applies a create / merge / update / skip decision, with dedup search and parse-failure repair |
|
|
43
|
+
| Implicit extraction | a background run feeds the new conversation window to the model and applies a create / merge / update / skip decision, with dedup search and parse-failure repair; before landing on an existing file the model is shown that file's numbered lines for a reconcile pass (replace / delete / insert / noop) instead of a blind append |
|
|
44
44
|
| Cross-peer sharing | mount another peer's memories read-only under `shared/<name>/` |
|
|
45
45
|
| Header indicator | capsule + three-state dot in the session header, polling the run status every 10 s |
|
|
46
46
|
| Peer isolation | the peer name derives from the session cwd (basename + short hash); cwd-less sessions fall back to `defaultPeer` |
|
|
@@ -80,6 +80,10 @@ Everything is edited in **Settings → memory-lite** and stored under the `dsh-m
|
|
|
80
80
|
| Model | Extraction model | follows the live global default model unless pinned to a provider/model |
|
|
81
81
|
| | Reasoning effort | read from the selected model's declaration; **off is recommended** |
|
|
82
82
|
| Reliability | Parse retry | one cheap repair call when the answer is not valid JSON (on by default) |
|
|
83
|
+
| Reconcile | `extraction.reconcile` | before a merge / update lands on an existing file, show the model its numbered Current lines and let it answer with line edits or noop; falls back to append on failure. On by default; one extra call per merge / update |
|
|
84
|
+
| | `extraction.reconcileMaxBytes` | byte budget for the numbered Current shown to the reconcile call, default 24576; larger files skip reconcile and append |
|
|
85
|
+
| History | `history.maxEntries` / `entryMaxChars` | keep only the newest N History lines per file (default 5), each at most M characters (default 240). Set in `cordis.patch.yml` only, **restart to apply** |
|
|
86
|
+
| | `history.archiveKeep` | save the whole previous file as a snapshot before every update / patch (newest 5 kept by default, 0 = off). **Restart to apply** |
|
|
83
87
|
| | Audit log | writes `peers/{peer}/sessions/{session-id}.json` and `extraction.log` |
|
|
84
88
|
| Catalog | Token cap | truncation cap for the L0 catalog, default 1200 |
|
|
85
89
|
| UI | Indicator order | header utilities slot order; refresh the page after saving |
|
|
@@ -98,16 +102,17 @@ Full schema and defaults: [`src/config.ts`](https://github.com/alanzhao0128/dsh-
|
|
|
98
102
|
│ │ ├── _index.md # L0 catalog (generated; hand-editable)
|
|
99
103
|
│ │ ├── preferences/ entities/ events/ experiences/
|
|
100
104
|
│ │ │ └── {slug}.md # L1 full text
|
|
105
|
+
│ ├── .history/{category}/{slug}.md/ # full pre-change snapshots (never searched or injected)
|
|
101
106
|
│ └── sessions/ # extraction bookmark + audit + extraction.log
|
|
102
107
|
└── .trash/ # soft-deleted memories (dated folders)
|
|
103
108
|
```
|
|
104
109
|
|
|
105
|
-
Each memory file uses `## Current` / `## History` / `## Related
|
|
110
|
+
Each memory file uses `## Current` / `## History` / `## Related`. Before an update the complete previous file is saved under `.history/`, and `## History` itself keeps only the newest few one-line notes instead of piling up old bodies. The catalog summary describes the whole file: the extractor writes one sentence when it creates the file, and later merges no longer overwrite it with the first words of the newest fact. The four categories are retrieval paths for the model: preferences (always relevant), entities (mentioned knowledge), events (time-related), experiences (task lessons).
|
|
106
111
|
|
|
107
112
|
## How it works (short version)
|
|
108
113
|
|
|
109
114
|
- **Catalog injection**: in the `agent/pre-step` waterfall the peer's `_index.md` is rendered into one `user/message` carrying the official `plugin` source kind with the `catalog` form; subagent sessions get none.
|
|
110
|
-
- **Extraction**: triggered by `windowTurns` or idle → select the window → grep existing memories for dedup → one LLM decision → write files → advance the per-session bookmark. **A failed run keeps the bookmark**, so the same window is retried on the next trigger.
|
|
115
|
+
- **Extraction**: triggered by `windowTurns` or idle → select the window → grep existing memories for dedup → one LLM decision → (when it lands on an existing file) a second LLM reconcile call that sees the file's numbered lines and answers with replace / delete / insert / append or noop; out-of-range lines, heavily shortened lines and mass deletions are rejected and fall back to append → write files → advance the per-session bookmark. **A failed run keeps the bookmark**, so the same window is retried on the next trigger.
|
|
111
116
|
- **Safety**: every file access goes through a containment boundary (relative paths only; `..`, absolute paths and symlink escapes are rejected at the executor).
|
|
112
117
|
- **Concurrency**: all writes go through a serial queue with atomic tmp+rename replacement.
|
|
113
118
|
|
|
@@ -142,6 +147,24 @@ Your memories are not deleted: `~/.agent-memory` is left for you to keep or remo
|
|
|
142
147
|
- The browser half (indicator + settings page) needs the web profile's `connection` service; under a headless profile the plugin still loads (tools + extraction work) and simply has no browser surfaces.
|
|
143
148
|
- Extraction quality depends on the model you pick; small models produce JSON that needs repair more often.
|
|
144
149
|
|
|
150
|
+
## Changelog
|
|
151
|
+
|
|
152
|
+
### v0.5.1 (2026-11-15)
|
|
153
|
+
- **Higher extraction output budget & truncation guard**: bumped `EXTRACTION_MAX_TOKENS` from `4096` to `32768` so reasoning models and the `reconcile` pass do not exhaust the budget on heavier windows; `collectStream` now also rejects `finish.kind === 'max-tokens'` as an explicit `llm-error` instead of letting truncated JSON enter tolerant parsing or repair.
|
|
154
|
+
|
|
155
|
+
### v0.5.0 (2026-11-13)
|
|
156
|
+
- **No more nested bullets**: lines that already carry `-` / `1.` / `#` / table / indentation keep their shape; only plain lines get a `- `. Duplicate detection now ignores list markers.
|
|
157
|
+
- **Capped History**: only the newest `history.maxEntries` lines survive, each truncated; the full previous file goes to `peers/{peer}/.history/` (never searched or injected), pruned by `history.archiveKeep`.
|
|
158
|
+
- **Stable catalog summaries**: `create` asks the extractor for a one-sentence `summary`; `merge` / `remember` appends no longer overwrite an existing summary; `update` may carry a new one.
|
|
159
|
+
- **Reconcile**: merge / update / create onto an existing file costs one extra LLM call in which the model sees the file's numbered lines and answers with line edits or noop; a rejected patch or failed call falls back to append (with reconcile on, an update is no longer a blind whole-file replace). Turn off with `extraction.reconcile: false`.
|
|
160
|
+
- Audit entries and `extraction.log` gain the outcomes `patch` / `noop`, plus a `reconcileFallback` field when reconcile gave up.
|
|
161
|
+
|
|
162
|
+
### v0.4.1
|
|
163
|
+
- **DSH 0.2.1-rc.2 Specification & Engines Alignment**: Declared `"engines": { "dsh": ">=0.1.2-rc.1" }` in `package.json`, adhering to the official priority evaluation of `engines.dsh`.
|
|
164
|
+
- **Fixed Volatile Reference Validation Bug**: Resolved `ValidationError` during `installSettingsCompat` by cleanly unwrapping volatile references with `unwrapConfig`.
|
|
165
|
+
- **L0 Catalog Category Priority & Anti-Truncation**: Enforced stable output priority in `renderIndex` (`preferences -> entities -> experiences -> events`) and expanded default `index.maxTokens` to 2000, preventing core rules and assets from being dropped by token budgets.
|
|
166
|
+
- **Triple Gate for Background Extraction**: Overhauled `extractionSystem` with a strict negative exclusion list, 30-day durability test, and aggressive merge requirement to eliminate over-extraction and memory fragmentation.
|
|
167
|
+
|
|
145
168
|
## Development
|
|
146
169
|
|
|
147
170
|
```sh
|
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ dsh plugin --profile web add @alanzhao/dsh-memory-lite
|
|
|
27
27
|
- **设置 → memory-lite** 出现完整配置页(下图)
|
|
28
28
|
- 对模型说「记住:我用 pnpm 作为包管理器」,它会调用 `remember`,文件落到 `~/.agent-memory/peers/<peer>/memories/preferences/`(首次使用会自动建目录)
|
|
29
29
|
|
|
30
|
-
兼容性:**dsh ≥ 0.1.5
|
|
30
|
+
兼容性:**dsh ≥ 0.1.5**(首发支持 dsh 0.2.1-rc.2 规范与 engines 约束,原生兼容 Working Directory 解耦与 Subagent 托管 Activation 隔离机制;双轨适配 0.1.7+ SettingsForms/configForms,向后兼容 0.1.5),Node ≥ 22。
|
|
31
31
|
|
|
32
32
|
<p align="center">
|
|
33
33
|
<img src="docs/preview/settings-extraction.png" alt="设置 → memory-lite:提取模式与触发方式" width="560">
|
|
@@ -39,7 +39,7 @@ dsh plugin --profile web add @alanzhao/dsh-memory-lite
|
|
|
39
39
|
|---|---|
|
|
40
40
|
| 显式记忆(5 个工具) | `read_memory` / `search_memory` / `remember` / `update_memory` / `forget_memory`;`update` 把旧内容归档进 `## History`,`forget` 是软删除(进 `.trash/`) |
|
|
41
41
|
| L0 目录注入 | 每个会话注入一条常驻的记忆目录消息(`_index.md` 渲染);目录变化、或压缩把它挤出可见面时自动重发 |
|
|
42
|
-
| 隐式提取 | 后台把新增对话窗口喂给模型,产出 create / merge / update / skip
|
|
42
|
+
| 隐式提取 | 后台把新增对话窗口喂给模型,产出 create / merge / update / skip 决策,带去重检索与解析失败重试;落到已有文件前会再让模型对照该文件的编号行做一次「对账」(replace / delete / insert / noop),而不是盲目追加 |
|
|
43
43
|
| 跨 peer 共享 | 把别的 peer 的记忆以只读方式挂到 `shared/<name>/` 下 |
|
|
44
44
|
| 头部指示器 | 标题栏胶囊 + 三色点,每 10 秒轮询一次运行状态 |
|
|
45
45
|
| peer 隔离 | peer 名由会话 cwd 推导(目录名 + 短哈希),无 cwd 的会话落到 `defaultPeer` |
|
|
@@ -79,6 +79,10 @@ dsh plugin --profile web add @alanzhao/dsh-memory-lite
|
|
|
79
79
|
| 提取模型 | 提取模型 | 默认跟随全局默认模型(活值);也可固定到某个 provider/model |
|
|
80
80
|
| | 推理强度 | 按所选模型声明的强度读取;**建议 off** |
|
|
81
81
|
| 可靠性 | 解析失败重试 | JSON 解析失败时一次廉价 repair 调用(默认开) |
|
|
82
|
+
| 对账 | `extraction.reconcile` | merge / update 落到已有文件前,把该文件 Current 的编号行给模型,让它输出行级编辑或 noop;失败自动退回追加。默认开,每次 merge / update 多一次调用 |
|
|
83
|
+
| | `extraction.reconcileMaxBytes` | 展示给对账调用的 Current 字节上限,默认 24576;更大的文件跳过对账、直接追加 |
|
|
84
|
+
| History | `history.maxEntries` / `entryMaxChars` | 每个文件 History 只留最新 N 行(默认 5),每行最多 M 字符(默认 240)。仅在 `cordis.patch.yml` 里配置,**重启生效** |
|
|
85
|
+
| | `history.archiveKeep` | 每次 update / patch 前把整个旧文件存成快照(默认保留最近 5 份,0 = 不存)。**重启生效** |
|
|
82
86
|
| | 审计日志 | 写 `peers/{peer}/sessions/{session-id}.json` 与 `extraction.log` |
|
|
83
87
|
| 目录注入 | 目录 token 上限 | L0 目录截断上限,默认 1200 |
|
|
84
88
|
| 界面 | 指示器位置 | 标题栏 utilities 槽顺序;保存后刷新页面生效 |
|
|
@@ -97,16 +101,17 @@ dsh plugin --profile web add @alanzhao/dsh-memory-lite
|
|
|
97
101
|
│ │ ├── _index.md # L0 目录(生成;可人工编辑)
|
|
98
102
|
│ │ ├── preferences/ entities/ events/ experiences/
|
|
99
103
|
│ │ │ └── {slug}.md # L1 全文
|
|
104
|
+
│ ├── .history/{category}/{slug}.md/ # update / patch 前的完整旧文件快照(不参与检索与注入)
|
|
100
105
|
│ └── sessions/ # 提取书签 + 审计 + extraction.log
|
|
101
106
|
└── .trash/ # forget 的软删除(按日期分目录)
|
|
102
107
|
```
|
|
103
108
|
|
|
104
|
-
每个记忆文件用 `## Current` / `## History` / `## Related`
|
|
109
|
+
每个记忆文件用 `## Current` / `## History` / `## Related` 三段。更新前会把完整旧文件存进 `.history/` 快照,`## History` 本身只留最新几行一句话记录,不再整段堆旧内容。目录里的摘要描述整个文件:新建时由提取模型写一句话,之后 merge 不会再用最新事实的前几个字覆盖它。四个分类是给模型的检索路径:preferences(总是相关)、entities(被提到的事实)、events(时间相关)、experiences(任务经验)。
|
|
105
110
|
|
|
106
111
|
## 工作原理(简版)
|
|
107
112
|
|
|
108
113
|
- **目录注入**:在 `agent/pre-step` 瀑布里把 `_index.md` 渲染成一条带官方 `plugin` + `catalog` 形式的 `user/message`;子代理会话不注入。
|
|
109
|
-
- **提取**:按 `windowTurns` 或空闲触发 → 取窗口内消息 → grep 已有记忆去重 → 一次 LLM 决策 → 写文件 → 推进每会话书签。**失败不推进书签**,下次触发重试。
|
|
114
|
+
- **提取**:按 `windowTurns` 或空闲触发 → 取窗口内消息 → grep 已有记忆去重 → 一次 LLM 决策 → (落到已有文件时)第二次 LLM「对账」:看着该文件的编号行输出 replace / delete / insert / append 或 noop,行号越界、整行被大幅缩写、一次删太多都会被拒绝并退回追加 → 写文件 → 推进每会话书签。**失败不推进书签**,下次触发重试。
|
|
110
115
|
- **安全**:所有文件访问过包含边界(只允许相对路径;`..`、绝对路径、symlink 逃逸在执行层拒绝)。
|
|
111
116
|
- **并发**:所有写入走串行队列 + 原子替换(tmp + rename)。
|
|
112
117
|
|
|
@@ -141,6 +146,24 @@ dsh plugin --profile web remove @alanzhao/dsh-memory-lite
|
|
|
141
146
|
- 浏览器半边(指示器 + 设置页)需要 web profile 的 `connection` 服务;headless profile 下插件照常加载(工具 + 提取可用),只是没有这两个界面。
|
|
142
147
|
- 隐式提取的质量取决于你选的模型;小模型更容易产出需要 repair 的 JSON。
|
|
143
148
|
|
|
149
|
+
## 变更历史 (Changelog)
|
|
150
|
+
|
|
151
|
+
### v0.5.1(2026-11-15)
|
|
152
|
+
- **放宽提取输出上限并拦截截断**:`EXTRACTION_MAX_TOKENS` 由 `4096` 提高到 `32768`,避免思考模型与 `reconcile` 阶段在长窗口下耗尽输出配额;同时在 `collectStream` 中将 `finish.kind === 'max-tokens'` 显式按 `llm-error` 抛出,杜绝截断后的半截 JSON 流入容错解析或修复流程。
|
|
153
|
+
|
|
154
|
+
### v0.5.0(2026-11-13)
|
|
155
|
+
- **不再嵌套项目符号**:已带 `-` / `1.` / `#` / 表格 / 缩进的行保持原样,只给普通行补 `- `;去重改为忽略列表标记后比较。
|
|
156
|
+
- **History 有上限**:只留最新 `history.maxEntries` 行、每行截断;完整旧文件存进 `peers/{peer}/.history/`(不检索、不注入),按 `history.archiveKeep` 保留。
|
|
157
|
+
- **目录摘要稳定**:`create` 要求提取模型给一句话 `summary`;`merge` / `remember` 追加不再覆盖已有摘要;`update` 可选带新摘要。
|
|
158
|
+
- **对账(reconcile)**:merge / update / create 落到已有文件前,多一次 LLM 调用,模型对照该文件的编号行输出行级补丁或 noop;补丁校验失败或调用失败退回追加(update 在对账开启时不再盲目整体替换)。可用 `extraction.reconcile: false` 关闭。
|
|
159
|
+
- 审计与 `extraction.log` 新增结果类型 `patch` / `noop`,对账退回时带 `reconcileFallback` 字段。
|
|
160
|
+
|
|
161
|
+
### v0.4.1
|
|
162
|
+
- **DSH 0.2.1-rc.2 规范与 engines 对齐**:在 `package.json` 中声明 `"engines": { "dsh": ">=0.1.2-rc.1" }`,契合官方优先识别 `engines.dsh` 的最新兼容性机制。
|
|
163
|
+
- **修复 Volatile 配置二次校验缺陷**:修复了在注入底层 `installSettingsCompat` 时未解包 Volatile Ref 导致的 `ValidationError`。
|
|
164
|
+
- **L0 目录分类优先级固化与防截断**:`renderIndex` 强制按 `preferences -> entities -> experiences -> events` 优先级输出,并将默认 `index.maxTokens` 扩容至 2000,杜绝核心行为准则和资产信息被挤出上下文。
|
|
165
|
+
- **后台提取三重硬门禁(Triple Gate)**:重构 `extractionSystem`,设立排他性负面清单(否决单次排错与临时工具抄录)、30天耐久度法则与激进 Merge 约束,彻底根除过度提取与记忆粉尘化。
|
|
166
|
+
|
|
144
167
|
## 开发
|
|
145
168
|
|
|
146
169
|
```sh
|
package/lib/config.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const DEFAULT_MEMORY_ROOT = "~/.agent-memory";
|
|
|
11
11
|
/** Default peer used for sessions without a usable cwd. */
|
|
12
12
|
export declare const DEFAULT_PEER = "dsh-web";
|
|
13
13
|
/** Default cap on catalog size, in approximate tokens. */
|
|
14
|
-
export declare const DEFAULT_INDEX_MAX_TOKENS =
|
|
14
|
+
export declare const DEFAULT_INDEX_MAX_TOKENS = 2000;
|
|
15
15
|
/** Default session-header indicator slot order (ascending; -1 sits left of the built-in "Session log" capsule). */
|
|
16
16
|
export declare const DEFAULT_HEADER_ORDER = -1;
|
|
17
17
|
/** Per-session peer derivation from `SessionHeader.cwd`. */
|
|
@@ -25,7 +25,7 @@ export interface WorkspacePeersConfig {
|
|
|
25
25
|
}
|
|
26
26
|
/** L0 catalog sizing. */
|
|
27
27
|
export interface IndexConfig {
|
|
28
|
-
/** Approximate token cap for the catalog; entries past the cap are truncated. Defaults to
|
|
28
|
+
/** Approximate token cap for the catalog; entries past the cap are truncated. Defaults to 2000. */
|
|
29
29
|
maxTokens: number;
|
|
30
30
|
/** Index sort order; `mtime` newest-first is the only supported value. Defaults to `mtime`. */
|
|
31
31
|
sortBy: 'mtime';
|
|
@@ -58,6 +58,15 @@ export interface SharingConfig {
|
|
|
58
58
|
/** Ordered mount declarations, visible to every peer except the target itself. */
|
|
59
59
|
mounts: SharingMountConfig[];
|
|
60
60
|
}
|
|
61
|
+
/** Retention for a memory file's History section and its full-snapshot archive. */
|
|
62
|
+
export interface HistoryConfig {
|
|
63
|
+
/** Newest History entries kept per file (one line each); 0 drops History entirely. Defaults to 5. */
|
|
64
|
+
maxEntries: number;
|
|
65
|
+
/** Max characters per History line; longer lines are cut with an ellipsis. Defaults to 240. */
|
|
66
|
+
entryMaxChars: number;
|
|
67
|
+
/** Full pre-change snapshots kept per file under `<peer>/.history/`; 0 disables archiving. Defaults to 5. */
|
|
68
|
+
archiveKeep: number;
|
|
69
|
+
}
|
|
61
70
|
/** Extraction model selection: an explicit route wins; empty = the global default model (agent-default-model). */
|
|
62
71
|
export interface ExtractionLlmConfig {
|
|
63
72
|
/** Combined "provider/model" route, e.g. 'deepseek-official/deepseek-v4-flash'. Empty = global default. */
|
|
@@ -107,6 +116,15 @@ export interface ExtractionConfig {
|
|
|
107
116
|
maxConcurrentRequests: number;
|
|
108
117
|
/** On a failed JSON parse, one cheap repair call re-asks the model for valid JSON. Defaults to true. */
|
|
109
118
|
parseRetry: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Before a merge/update lands on an existing file, show the model that file's
|
|
121
|
+
* numbered Current lines and let it answer with line-targeted edits (or noop)
|
|
122
|
+
* instead of blindly appending. One extra LLM call, only for merge/update
|
|
123
|
+
* decisions. A failed reconcile falls back to a plain append. Defaults to true.
|
|
124
|
+
*/
|
|
125
|
+
reconcile: boolean;
|
|
126
|
+
/** Byte budget for the numbered Current shown to the reconcile call; larger files fall back to append. Defaults to 24576. */
|
|
127
|
+
reconcileMaxBytes: number;
|
|
110
128
|
}
|
|
111
129
|
/** Raw plugin configuration as written in cordis.yml; every field optional. */
|
|
112
130
|
export interface MemoryConfig {
|
|
@@ -117,6 +135,7 @@ export interface MemoryConfig {
|
|
|
117
135
|
tools?: Partial<ToolsConfig>;
|
|
118
136
|
extraction?: Partial<ExtractionConfig>;
|
|
119
137
|
sharing?: Partial<SharingConfig>;
|
|
138
|
+
history?: Partial<HistoryConfig>;
|
|
120
139
|
ui?: Partial<UiConfig>;
|
|
121
140
|
}
|
|
122
141
|
/** Fully defaulted configuration after {@link resolveConfig}. */
|
|
@@ -129,6 +148,7 @@ export interface ResolvedConfig {
|
|
|
129
148
|
tools: ToolsConfig;
|
|
130
149
|
extraction: ExtractionConfig;
|
|
131
150
|
sharing: SharingConfig;
|
|
151
|
+
history: HistoryConfig;
|
|
132
152
|
ui: UiConfig;
|
|
133
153
|
}
|
|
134
154
|
/** Validate the plugin configuration shape. Unknown keys are tolerated for forward compatibility. */
|
package/lib/config.js
CHANGED
|
@@ -13,7 +13,7 @@ export const DEFAULT_MEMORY_ROOT = '~/.agent-memory';
|
|
|
13
13
|
/** Default peer used for sessions without a usable cwd. */
|
|
14
14
|
export const DEFAULT_PEER = 'dsh-web';
|
|
15
15
|
/** Default cap on catalog size, in approximate tokens. */
|
|
16
|
-
export const DEFAULT_INDEX_MAX_TOKENS =
|
|
16
|
+
export const DEFAULT_INDEX_MAX_TOKENS = 2000;
|
|
17
17
|
/** Default session-header indicator slot order (ascending; -1 sits left of the built-in "Session log" capsule). */
|
|
18
18
|
export const DEFAULT_HEADER_ORDER = -1;
|
|
19
19
|
/**
|
|
@@ -64,6 +64,8 @@ export const Config = z.object({
|
|
|
64
64
|
auditLog: asVolatile(z.boolean()),
|
|
65
65
|
maxConcurrentRequests: asVolatile(z.number()),
|
|
66
66
|
parseRetry: asVolatile(z.boolean()),
|
|
67
|
+
reconcile: asVolatile(z.boolean()),
|
|
68
|
+
reconcileMaxBytes: asVolatile(z.number()),
|
|
67
69
|
}),
|
|
68
70
|
sharing: z.object({
|
|
69
71
|
enabled: asVolatile(z.boolean()),
|
|
@@ -74,6 +76,11 @@ export const Config = z.object({
|
|
|
74
76
|
readonly: z.boolean(),
|
|
75
77
|
}))),
|
|
76
78
|
}),
|
|
79
|
+
history: z.object({
|
|
80
|
+
maxEntries: asVolatile(z.number()),
|
|
81
|
+
entryMaxChars: asVolatile(z.number()),
|
|
82
|
+
archiveKeep: asVolatile(z.number()),
|
|
83
|
+
}),
|
|
77
84
|
ui: z.object({
|
|
78
85
|
headerOrder: asVolatile(z.number()),
|
|
79
86
|
}),
|
|
@@ -159,6 +166,8 @@ export function resolveConfig(rawConfig = {}) {
|
|
|
159
166
|
auditLog: config.extraction?.auditLog ?? true,
|
|
160
167
|
maxConcurrentRequests: config.extraction?.maxConcurrentRequests ?? 1,
|
|
161
168
|
parseRetry: config.extraction?.parseRetry ?? true,
|
|
169
|
+
reconcile: config.extraction?.reconcile ?? true,
|
|
170
|
+
reconcileMaxBytes: config.extraction?.reconcileMaxBytes ?? 24576,
|
|
162
171
|
};
|
|
163
172
|
for (const [key, value] of [
|
|
164
173
|
['windowTurns', extraction.windowTurns],
|
|
@@ -168,6 +177,7 @@ export function resolveConfig(rawConfig = {}) {
|
|
|
168
177
|
['turnDebounceMs', extraction.turnDebounceMs],
|
|
169
178
|
['maxConcurrentRequests', extraction.maxConcurrentRequests],
|
|
170
179
|
['idleTimeoutMin', extraction.idleTimeoutMin],
|
|
180
|
+
['reconcileMaxBytes', extraction.reconcileMaxBytes],
|
|
171
181
|
]) {
|
|
172
182
|
if (!Number.isInteger(value) || value < 0) {
|
|
173
183
|
throw new Error(`dsh-memory-lite: extraction.${key} must be a non-negative integer, got ${value}`);
|
|
@@ -203,6 +213,23 @@ export function resolveConfig(rawConfig = {}) {
|
|
|
203
213
|
throw new Error('dsh-memory-lite: sharing mount subpath must not escape the memories root, got ' + JSON.stringify(mount.subpath));
|
|
204
214
|
}
|
|
205
215
|
}
|
|
216
|
+
const history = {
|
|
217
|
+
maxEntries: config.history?.maxEntries ?? 5,
|
|
218
|
+
entryMaxChars: config.history?.entryMaxChars ?? 240,
|
|
219
|
+
archiveKeep: config.history?.archiveKeep ?? 5,
|
|
220
|
+
};
|
|
221
|
+
for (const [key, value] of [
|
|
222
|
+
['maxEntries', history.maxEntries],
|
|
223
|
+
['entryMaxChars', history.entryMaxChars],
|
|
224
|
+
['archiveKeep', history.archiveKeep],
|
|
225
|
+
]) {
|
|
226
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
227
|
+
throw new Error(`dsh-memory-lite: history.${key} must be a non-negative integer, got ${value}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (history.entryMaxChars < 20) {
|
|
231
|
+
throw new Error(`dsh-memory-lite: history.entryMaxChars must be >= 20, got ${history.entryMaxChars}`);
|
|
232
|
+
}
|
|
206
233
|
const ui = {
|
|
207
234
|
headerOrder: config.ui?.headerOrder ?? DEFAULT_HEADER_ORDER,
|
|
208
235
|
};
|
|
@@ -217,6 +244,7 @@ export function resolveConfig(rawConfig = {}) {
|
|
|
217
244
|
tools: { schemaMinimal: config.tools?.schemaMinimal ?? true },
|
|
218
245
|
extraction,
|
|
219
246
|
sharing,
|
|
247
|
+
history,
|
|
220
248
|
ui,
|
|
221
249
|
};
|
|
222
250
|
}
|
package/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D,gEAAgE;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,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,wCAAwC,KAAK,EAAE,CAAC,CAAA;QACjG,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,aAAa,GAAG,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,6DAA6D,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;IACvG,CAAC;IACD,MAAM,EAAE,GAAG;QACT,WAAW,EAAE,MAAM,CAAC,EAAE,EAAE,WAAW,IAAI,oBAAoB;KAC5D,CAAA;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,2DAA2D,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA;IAC9F,CAAC;IACD,OAAO;QACL,IAAI;QACJ,WAAW;QACX,cAAc;QACd,KAAK;QACL,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,EAAE,aAAa,IAAI,IAAI,EAAE;QAC7D,UAAU;QACV,OAAO;QACP,OAAO;QACP,EAAE;KACH,CAAA;AACH,CAAC"}
|
|
@@ -6,17 +6,22 @@
|
|
|
6
6
|
* closed vocabulary.
|
|
7
7
|
* @module dsh-memory-lite/src/extract/decision
|
|
8
8
|
*/
|
|
9
|
+
import type { PatchOp } from '../patch.js';
|
|
9
10
|
export type ExtractionDecisionKind = 'create' | 'merge' | 'update' | 'skip';
|
|
10
11
|
export interface CreateDecision {
|
|
11
12
|
readonly kind: 'create';
|
|
12
13
|
readonly category: string;
|
|
13
14
|
readonly title: string;
|
|
14
15
|
readonly content: string;
|
|
16
|
+
/** One-sentence description of the whole file for the L0 index (optional). */
|
|
17
|
+
readonly summary?: string;
|
|
15
18
|
}
|
|
16
19
|
export interface PathDecision {
|
|
17
20
|
readonly kind: 'merge' | 'update';
|
|
18
21
|
readonly path: string;
|
|
19
22
|
readonly content: string;
|
|
23
|
+
/** Replacement index summary; only honoured for `update` (optional). */
|
|
24
|
+
readonly summary?: string;
|
|
20
25
|
}
|
|
21
26
|
export interface SkipDecision {
|
|
22
27
|
readonly kind: 'skip';
|
|
@@ -34,3 +39,14 @@ export declare function parseDecision(text: string): ExtractionDecision;
|
|
|
34
39
|
* a JSON object from `"key": "value"` pairs; throws only when neither works.
|
|
35
40
|
*/
|
|
36
41
|
export declare function extractJsonObject(text: string): string;
|
|
42
|
+
/** Outcome of the reconcile call that follows a merge/update on an existing file. */
|
|
43
|
+
export type ReconcileDecision = {
|
|
44
|
+
readonly kind: 'noop';
|
|
45
|
+
readonly reason?: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: 'patch';
|
|
48
|
+
readonly ops: readonly PatchOp[];
|
|
49
|
+
readonly summary?: string;
|
|
50
|
+
};
|
|
51
|
+
/** Parse the reconcile model's answer (`noop` or `patch` with line-targeted ops). */
|
|
52
|
+
export declare function parseReconcile(text: string): ReconcileDecision;
|
package/lib/extract/decision.js
CHANGED
|
@@ -29,7 +29,8 @@ export function parseDecision(text) {
|
|
|
29
29
|
if (category === '' || title === '' || content === '') {
|
|
30
30
|
throw new Error('create decision requires category, title, and content');
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
const summary = cleanSummary(record.summary);
|
|
33
|
+
return { kind, category, title, content, ...(summary === undefined ? {} : { summary }) };
|
|
33
34
|
}
|
|
34
35
|
case 'merge':
|
|
35
36
|
case 'update': {
|
|
@@ -38,7 +39,8 @@ export function parseDecision(text) {
|
|
|
38
39
|
if (path === '' || content === '') {
|
|
39
40
|
throw new Error(`${kind} decision requires path and content`);
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
const summary = cleanSummary(record.summary);
|
|
43
|
+
return { kind, path, content, ...(summary === undefined ? {} : { summary }) };
|
|
42
44
|
}
|
|
43
45
|
default: {
|
|
44
46
|
const reason = str(record.reason);
|
|
@@ -115,4 +117,60 @@ function rebuildFromPairs(text) {
|
|
|
115
117
|
function str(value) {
|
|
116
118
|
return typeof value === 'string' ? value.trim() : '';
|
|
117
119
|
}
|
|
120
|
+
/** Index summaries are one line; collapse whitespace and cap the length. */
|
|
121
|
+
function cleanSummary(value) {
|
|
122
|
+
const text = str(value).replaceAll(/\s+/g, ' ');
|
|
123
|
+
if (text === '')
|
|
124
|
+
return undefined;
|
|
125
|
+
return text.length <= 160 ? text : text.slice(0, 159) + '…';
|
|
126
|
+
}
|
|
127
|
+
/** Parse the reconcile model's answer (`noop` or `patch` with line-targeted ops). */
|
|
128
|
+
export function parseReconcile(text) {
|
|
129
|
+
const parsed = JSON.parse(extractJsonObject(text));
|
|
130
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
131
|
+
throw new Error('reconcile decision is not an object');
|
|
132
|
+
}
|
|
133
|
+
const record = parsed;
|
|
134
|
+
const kind = typeof record.decision === 'string' ? record.decision : '';
|
|
135
|
+
if (kind === 'noop') {
|
|
136
|
+
const reason = str(record.reason);
|
|
137
|
+
return { kind: 'noop', ...(reason === '' ? {} : { reason }) };
|
|
138
|
+
}
|
|
139
|
+
if (kind !== 'patch') {
|
|
140
|
+
throw new Error(`reconcile decision must be noop or patch, got ${JSON.stringify(kind)}`);
|
|
141
|
+
}
|
|
142
|
+
if (!Array.isArray(record.ops) || record.ops.length === 0) {
|
|
143
|
+
throw new Error('patch decision requires a non-empty ops array');
|
|
144
|
+
}
|
|
145
|
+
const ops = record.ops.map((raw, index) => {
|
|
146
|
+
if (typeof raw !== 'object' || raw === null)
|
|
147
|
+
throw new Error(`patch op ${index} is not an object`);
|
|
148
|
+
const op = raw;
|
|
149
|
+
switch (op.op) {
|
|
150
|
+
case 'replace':
|
|
151
|
+
return { op: 'replace', line: int(op.line, index), content: nonEmpty(op.content, index) };
|
|
152
|
+
case 'delete':
|
|
153
|
+
return { op: 'delete', line: int(op.line, index) };
|
|
154
|
+
case 'insert':
|
|
155
|
+
return { op: 'insert', after: int(op.after, index), content: nonEmpty(op.content, index) };
|
|
156
|
+
case 'append':
|
|
157
|
+
return { op: 'append', content: nonEmpty(op.content, index) };
|
|
158
|
+
default:
|
|
159
|
+
throw new Error(`patch op ${index} has unknown op ${JSON.stringify(op.op)}`);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
const summary = cleanSummary(record.summary);
|
|
163
|
+
return { kind: 'patch', ops, ...(summary === undefined ? {} : { summary }) };
|
|
164
|
+
}
|
|
165
|
+
function int(value, index) {
|
|
166
|
+
if (typeof value !== 'number' || !Number.isInteger(value))
|
|
167
|
+
throw new Error(`patch op ${index} needs an integer line number`);
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
function nonEmpty(value, index) {
|
|
171
|
+
const text = str(value);
|
|
172
|
+
if (text === '')
|
|
173
|
+
throw new Error(`patch op ${index} needs non-empty content`);
|
|
174
|
+
return text;
|
|
175
|
+
}
|
|
118
176
|
//# sourceMappingURL=decision.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision.js","sourceRoot":"","sources":["../../src/extract/decision.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"decision.js","sourceRoot":"","sources":["../../src/extract/decision.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA8BH,MAAM,CAAC,MAAM,cAAc,GAAsC,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;AAEtG,0EAA0E;AAC1E,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;AAEtF,8DAA8D;AAC9D,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACpC,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACxC,IAAI,OAAO,MA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AAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAA;AAC9E,CAAC;AAED,SAAS,GAAG,CAAC,KAAc,EAAE,KAAa;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,YAAY,KAAK,+BAA+B,CAAC,CAAA;IAC5H,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc,EAAE,KAAa;IAC7C,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;IACvB,IAAI,IAAI,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,YAAY,KAAK,0BAA0B,CAAC,CAAA;IAC7E,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/lib/extract/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { Context } from '@deepseek-ai/cordis';
|
|
|
12
12
|
import type { MemoryStore } from '../memory-store.js';
|
|
13
13
|
import type { MemoryDeps } from '../tool-utils.js';
|
|
14
14
|
import type { StatusTracker } from '../status.js';
|
|
15
|
-
import { type ExtractionDecision } from './decision.js';
|
|
15
|
+
import { type ExtractionDecision, type ReconcileDecision } from './decision.js';
|
|
16
16
|
import { type CheckpointFile } from './checkpoint.js';
|
|
17
17
|
interface ExtractionState {
|
|
18
18
|
pending: number;
|
|
@@ -51,8 +51,41 @@ export interface ExtractionSessionLike {
|
|
|
51
51
|
export declare function applyExtraction(ctx: Context, deps: MemoryDeps, tracker: StatusTracker): void;
|
|
52
52
|
/** One extraction run: window -> grep -> LLM -> write -> checkpoint. */
|
|
53
53
|
export declare function extractOnce(session: ExtractionSessionLike, state: ExtractionState, ctx: Context, deps: MemoryDeps, signal: AbortSignal, tracker: StatusTracker): Promise<void>;
|
|
54
|
+
/** What the reconcile model is asked to fold into an existing file. */
|
|
55
|
+
export interface ReconcileRequest {
|
|
56
|
+
readonly path: string;
|
|
57
|
+
readonly title: string;
|
|
58
|
+
/** The file's Current body (its numbering is what the model's line numbers refer to). */
|
|
59
|
+
readonly current: string;
|
|
60
|
+
readonly kind: 'create' | 'merge' | 'update';
|
|
61
|
+
/** The proposed addition exactly as the extractor wrote it. */
|
|
62
|
+
readonly content: string;
|
|
63
|
+
}
|
|
64
|
+
/** Reconcile result; `fallback` means "could not reconcile, append instead". */
|
|
65
|
+
export type ReconcileAnswer = ReconcileDecision | {
|
|
66
|
+
readonly kind: 'fallback';
|
|
67
|
+
readonly reason: string;
|
|
68
|
+
};
|
|
69
|
+
/** Optional collaborators for {@link applyDecisionDetailed}. */
|
|
70
|
+
export interface ApplyHooks {
|
|
71
|
+
/** Present = reconcile merge/update/create against an existing file before writing. */
|
|
72
|
+
readonly reconcile?: (request: ReconcileRequest) => Promise<ReconcileAnswer>;
|
|
73
|
+
}
|
|
74
|
+
/** How a decision was actually applied (`patch`/`noop` come from reconcile). */
|
|
75
|
+
export interface AppliedDecision {
|
|
76
|
+
readonly path: string | undefined;
|
|
77
|
+
readonly applied: 'create' | 'merge' | 'update' | 'patch' | 'noop' | 'skip';
|
|
78
|
+
/** Why reconcile gave up and the change was appended instead. */
|
|
79
|
+
readonly fallback?: string;
|
|
80
|
+
}
|
|
54
81
|
/** Apply one decision through the store (all writes go through the queue). */
|
|
55
|
-
export declare function applyDecision(store: MemoryStore, peer: string, decision: ExtractionDecision): Promise<string | undefined>;
|
|
82
|
+
export declare function applyDecision(store: MemoryStore, peer: string, decision: ExtractionDecision, hooks?: ApplyHooks): Promise<string | undefined>;
|
|
83
|
+
/**
|
|
84
|
+
* Apply one decision and report how it landed. Index summaries describe the
|
|
85
|
+
* whole file, so only a brand-new file (or an explicit `summary`) sets one;
|
|
86
|
+
* merging a fact never replaces it with that fact's first words.
|
|
87
|
+
*/
|
|
88
|
+
export declare function applyDecisionDetailed(store: MemoryStore, peer: string, decision: ExtractionDecision, hooks?: ApplyHooks): Promise<AppliedDecision>;
|
|
56
89
|
/** Light keyword heuristic: frequent Latin words and CJK characters. */
|
|
57
90
|
export declare function extractKeywords(text: string, max: number): string[];
|
|
58
91
|
export {};
|