@flowingspring/dsh-workspace-memory 0.1.0

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/DESIGN.md ADDED
@@ -0,0 +1,137 @@
1
+ # DSH Workspace Memory — Design
2
+
3
+ ## Goal
4
+
5
+ Provide durable, workspace-scoped memory for DeepSeek Harness while remaining
6
+ independent from any particular UI or voice plugin. Ordinary DSH Agents and
7
+ `dsh-voco` share the same memory whenever their Sessions have the same `cwd`.
8
+
9
+ The plugin owns memory. Callers only cross the `WorkspaceMemory` seam.
10
+
11
+ ## External interface
12
+
13
+ ```ts
14
+ interface WorkspaceMemory {
15
+ recall(input: RecallInput): Promise<MemoryContext>
16
+ checkpoint(input: CheckpointInput): Promise<CheckpointResult>
17
+ }
18
+ ```
19
+
20
+ - `recall` returns a bounded stable summary plus query-relevant entries.
21
+ - `checkpoint` accepts newly completed conversation messages. It buffers,
22
+ deduplicates, decides whether a stage is ready, distils durable facts, and
23
+ persists them. Callers do not implement checkpoint policy.
24
+ - Both operations resolve scope from `sessionId` or an explicit `cwd`.
25
+ - Missing/empty `cwd` resolves to the global scope.
26
+ - A project scope recalls both global and workspace entries; writes may be classified
27
+ as `global` or `workspace` by the distiller.
28
+ - Failure to recall memory never prevents an Agent or voice response.
29
+
30
+ The production adapter is the Cordis `workspaceMemory` service. Tests use an
31
+ in-memory/fake adapter at the same seam.
32
+
33
+ ## Scope and storage
34
+
35
+ Default root: `$DSH_HOME/workspace-memory` (fallback `~/.dsh/workspace-memory`).
36
+
37
+ ```text
38
+ workspace-memory/
39
+ global/
40
+ memory_summary.md
41
+ memory_entries.json
42
+ state.json
43
+ checkpoints/
44
+ summary_history/
45
+ scopes/
46
+ ws-<sha256-prefix>/
47
+ scope.json
48
+ memory_summary.md
49
+ memory_entries.json
50
+ state.json
51
+ checkpoints/
52
+ summary_history/
53
+ ```
54
+
55
+ Workspace identity is the normalized absolute `cwd`. Runtime data stays out of
56
+ the user's Git checkout unless `memoryDir` is explicitly configured there.
57
+ Writes use a per-scope promise queue and atomic temporary-file rename.
58
+
59
+ ## Retrieval
60
+
61
+ Version 1 deliberately has no BM25, vector database, or embedding dependency.
62
+ It performs structured lexical retrieval over parsed entries:
63
+
64
+ 1. exact phrase and normalized substring matches;
65
+ 2. title, retrieval-term, and tag matches;
66
+ 3. ASCII word and CJK character-bigram coverage;
67
+ 4. description/content matches;
68
+ 5. importance, recency, and a short-lived surfaced-memory penalty.
69
+
70
+ The result is bounded by entry count and UTF-8 bytes. Memory is always treated
71
+ as reference data and never as an instruction overriding the current user.
72
+
73
+ ## Checkpoint policy
74
+
75
+ A stage is logical, not hourly. A checkpoint becomes eligible when any of the
76
+ following is true:
77
+
78
+ - a background Agent turn/task completes;
79
+ - at least `checkpointTurns` completed user turns are buffered (default 10);
80
+ - buffered text reaches `checkpointChars` (default 4000 characters);
81
+ - the buffer remains idle for `idleCheckpointMs` (default 5 minutes);
82
+ - the Session closes or a caller explicitly forces a checkpoint.
83
+
84
+ Only completed messages enter the buffer. Checkpointing is asynchronous from
85
+ Agent/voice response delivery. A scope queue prevents concurrent mutations.
86
+
87
+ The distiller outputs durable atomic facts only: preferences, project facts,
88
+ decisions, conventions, fixes, and explicitly requested memories. Greetings,
89
+ temporary instructions, progress chatter, and unconfirmed speculation are
90
+ discarded. Similar existing entries are updated instead of duplicated.
91
+
92
+ After `consolidateEvery` successful checkpoints (default 5), the summary is
93
+ rebuilt from active entries. A bounded history is kept before replacement.
94
+
95
+ ## DSH integration
96
+
97
+ - `systemPrompt.context` injects the stable summary on every Agent step.
98
+ - `agent/pre-step` calls `recall` for the current user message and appends only
99
+ relevant entries on step 1.
100
+ - `agent/turn-stopping` submits the completed turn to the checkpoint buffer
101
+ without forcing an LLM distillation; threshold, idle, task-end, and close
102
+ policy decides when a stage is ready.
103
+ - memory tools provide explicit search, remember, and forget operations.
104
+ - `memory_search` remains the Agentic second-search seam: an Agent can issue
105
+ alternate queries when the automatic first recall is insufficient.
106
+
107
+ ## Voco integration
108
+
109
+ - Before frontend routing, Voco optionally calls `workspaceMemory.recall`.
110
+ - The returned context is included as quoted reference material for the router.
111
+ - Completed voice utterances are submitted to `checkpoint`; policy remains
112
+ inside the memory module.
113
+ - Voice Session close forces a final evaluation of the buffered stage.
114
+ - If the service is absent or fails, Voco uses its existing behavior unchanged.
115
+ - Delegated background Agents already inherit the source `cwd`, so they resolve
116
+ the same workspace scope without a Voco-specific storage path.
117
+
118
+ ## Safety and failure behavior
119
+
120
+ - Obvious credential-shaped values are rejected from automatic persistence and
121
+ redacted from recall output.
122
+ - Malformed LLM output leaves the store unchanged.
123
+ - Memory I/O, retrieval, or distillation failure is logged and never fails the
124
+ foreground Agent/voice operation.
125
+ - Checkpoint input has a hard byte cap.
126
+ - Memory context is clearly delimited and labelled as untrusted reference data.
127
+
128
+ ## Initial acceptance criteria
129
+
130
+ 1. Two Sessions with the same normalized `cwd` recall the same entries.
131
+ 2. Different workspaces remain isolated.
132
+ 3. Exact, ASCII-token, and Chinese-bigram queries return ranked entries.
133
+ 4. Repeated checkpoint messages are deduplicated by message id.
134
+ 5. Threshold, idle, task-end, and close triggers are deterministic in tests.
135
+ 6. Voco behaves exactly as before when `workspaceMemory` is unavailable.
136
+ 7. A Voco frontend query receives bounded memory when it is available.
137
+ 8. Core store/retrieval tests require no running DSH process or remote model.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FlowingSpring
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # dsh-workspace-memory
2
+
3
+ 面向 DeepSeek Harness 的 Workspace 长期记忆插件。它让相同工作目录下的多个
4
+ Session 共享一份稳定摘要和长期原子记忆,并通过可选 Cordis 接口与
5
+ [`dsh-voco`](../dsh-voco/README.md) 的语音前台集成。
6
+
7
+ ## 当前能力
8
+
9
+ - 按规范化 `cwd` 隔离 Workspace;相同 Workspace 的 Voice Session、后台
10
+ Agent Session 和普通 Session 共享记忆。
11
+ - 每个 Agent step 自动注入一份有上限的 `memory_summary.md`。
12
+ - 在 Agent 第一 step 根据当前用户消息自动检索相关长期记忆。
13
+ - 不使用 BM25、Embedding 或向量数据库:采用精确短语、英文词、中文字符
14
+ bigram、标签、重要性和新近度综合排序。
15
+ - 任务结束、10 轮对话、4000 字符、空闲 5 分钟或 Session 关闭时评估
16
+ checkpoint;不会按固定小时机械写入。
17
+ - Agent turn 结束只进入 checkpoint 缓冲,不会每轮强制调用记忆蒸馏模型。
18
+ - LLM 只蒸馏长期有效事实;重复/近重复事实会更新原条目。
19
+ - 提供 `memory_search`、`memory_remember`、`memory_forget` 工具。
20
+ - 凭据形态内容默认拒绝持久化,并在模型输入前脱敏。
21
+ - 没有安装本插件时,`dsh-voco` 保持原有行为。
22
+
23
+ 详细契约见 [DESIGN.md](./DESIGN.md)。
24
+
25
+ ## 安装(当前源码版本)
26
+
27
+ ```powershell
28
+ pnpm install
29
+ pnpm build
30
+ $plugin = (Resolve-Path .).Path
31
+ dsh plugin --profile web add $plugin
32
+ ```
33
+
34
+ 重启 `dsh web` 后生效。尚未发布 npm 时请使用本地路径安装。
35
+
36
+ 运行数据默认写入:
37
+
38
+ ```text
39
+ $DSH_HOME/workspace-memory
40
+ ```
41
+
42
+ 如果没有设置 `DSH_HOME`,则使用 `~/.dsh/workspace-memory`。数据不会写进
43
+ Git 项目目录,除非显式配置 `memoryDir`。
44
+
45
+ ## 配置
46
+
47
+ 安装生成的 loader row 可以覆盖以下配置:
48
+
49
+ ```yaml
50
+ - insert:
51
+ - id: workspace-memory
52
+ name: '@flowingspring/dsh-workspace-memory'
53
+ config:
54
+ memoryDir: ''
55
+ checkpointTurns: 10
56
+ checkpointChars: 4000
57
+ idleCheckpointMs: 300000
58
+ consolidateEvery: 5
59
+ summaryMaxBytes: 3000
60
+ recallMaxBytes: 5000
61
+ recallLimit: 8
62
+ checkpointMaxChars: 40000
63
+ keepSummaryVersions: 10
64
+ surfacedPenalty: 8
65
+ summarizeProvider: ''
66
+ summarizeModel: ''
67
+ ```
68
+
69
+ `summarizeProvider` 和 `summarizeModel` 为空时使用 DSH 当前默认模型。
70
+
71
+ ## 存储结构
72
+
73
+ ```text
74
+ workspace-memory/
75
+ ├── global/
76
+ └── scopes/
77
+ └── ws-<hash>/
78
+ ├── scope.json
79
+ ├── memory_summary.md
80
+ ├── memory_entries.json
81
+ ├── state.json
82
+ ├── checkpoints/
83
+ └── summary_history/
84
+ ```
85
+
86
+ 项目 Session 会同时读取 `global/` 与对应 `scopes/ws-<hash>/` 的摘要和长期记忆;
87
+ 全局记忆适合用户偏好和通用工作方式,Workspace 记忆适合项目架构、决策和修复。
88
+
89
+ `memory_entries.json` 是事实来源;`memory_summary.md` 是自动注入的短摘要;
90
+ `checkpoints/` 保留每次阶段性蒸馏的可审计 Markdown 记录。
91
+
92
+ ## 开发验证
93
+
94
+ 源码与测试均使用 TypeScript;`pnpm build` 将 ESM JavaScript 和类型声明生成到
95
+ `lib/`,该目录不提交到 Git。
96
+
97
+ ```powershell
98
+ pnpm test
99
+ pnpm typecheck
100
+ pnpm build
101
+ pnpm pack --dry-run
102
+ ```
103
+
104
+ ## License
105
+
106
+ MIT
@@ -0,0 +1,10 @@
1
+ # Workspace memory is independent from Voco. Installing both enables their
2
+ # optional Cordis service integration; either plugin can run alone.
3
+ - insert:
4
+ - id: workspace-memory
5
+ name: '@flowingspring/dsh-workspace-memory'
6
+ config:
7
+ checkpointTurns: 10
8
+ checkpointChars: 4000
9
+ idleCheckpointMs: 300000
10
+ consolidateEvery: 5