dsh-memory-domains 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 lmx494
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 CHANGED
@@ -1,3 +1,137 @@
1
- # Temporary Holding Version
1
+ # dsh-memory-domains
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 人审策展的 agent 记忆库 —— DeepSeek Harness (DSH) 本地插件,**领域中心**的知识库形态。
4
+
5
+ 核心纪律:**AI 绝不自主写入记忆**。整理、升级、归档全部由人点按钮触发;AI 只负责起草,人审后才入库。
6
+
7
+ ## 它是什么
8
+
9
+ 管理"注入上下文的记忆"(上下文记忆),覆盖四种类型:
10
+
11
+ | 类型 | 内容 | 例子 |
12
+ |---|---|---|
13
+ | `mistake` 教训 | 负知识:什么不能做 | "波特率必须用 115200,9600 会乱码" |
14
+ | `fact` 事实 | 领域知识 | "MCU 寄存器基址 0x4000_0000" |
15
+ | `skill` 技能 | 流程/模板 | "接新传感器的五步流程" |
16
+ | `pref` 偏好 | 用户约定 | "输出用中文,先给结论" |
17
+
18
+ 每条还带**优先级** `priority`:`high`(★高,踩坑/硬约束/强偏好)或缺省 `normal`。AI 起草时建议、人审时可改(入库选择器/编辑表单/入库后卡片上的开关都能调);`memory_search` 对 high 条目 ×1.5 加权排序。
19
+
20
+ 三级组织:
21
+
22
+ - **领域**(主单元):`domains/<slug>.jsonl` + `domains.json` 注册表。领域由**用户手动创建**,名称+描述必填——描述是 agent 检索时的路标(覆盖什么/典型关键词/不覆盖什么),可点「✨ AI 起草」让 AI 扩写后人工确认。一条记忆只归一个领域。
23
+ - **全局记忆**:`global.jsonl` —— 跨领域通用知识 + 从领域手动「升级全局」的精选(复制+溯源,不删原件)
24
+ - **会话**:退居**来源**角色——轨迹 → AI 起草 → 人审时选领域或全局入库;会话卡片用于「整理」入口和"本会话贡献了哪些记忆"的溯源浏览
25
+
26
+ 生命周期:整理草稿(`candidates/` 暂存)→ 人审(可编辑,AI 会按已有领域建议归属)→ 选领域/全局入库 → 使用中可归档/恢复/删除。"没用的就不要记住"由人手动执行,AI 只提名不决策。
27
+
28
+ ## 功能
29
+
30
+ - **领域卡片墙**:领域卡(名称+描述+条目数)+ 全局库卡 + 「+ 新建领域」;下方会话区是整理入口;搜索框同时过滤领域名和会话标题
31
+ - **新建/编辑领域**:名称+描述必填;「✨ AI 起草描述」按名称自动生成规范描述
32
+ - **整理记忆**:AI 回顾会话轨迹(含工具调用/报错),起草记忆卡到待审区;prompt 里附领域清单,AI 会建议归属 slug
33
+ - **人审流**:草稿可编辑 → ✓入库时**选择目标领域或全局**(默认选中 AI 建议)/ ✗丢弃
34
+ - **升级全局**:领域条目一键复制进全局库,带 `promoted_from` 溯源;`scope=all` 检索自动去重
35
+ - **`memory_search` 工具**:agent 检索记忆(只读),BM25 排序 + CJK bigram 召回,结果附**领域地图**(slug/名称/描述),可用 `scope=domain&domain=<slug>` 精搜
36
+ - **🔍 发现项目**:领域详情页一键按领域画像搜 GitHub——AI 把领域名称+描述蒸馏成 3~5 个检索词,走 GitHub repo 搜索(stars 排序、去重),结果卡片可点;按需触发不打扰,配 `githubToken`/`GITHUB_TOKEN` 可提额
37
+
38
+ ## 架构
39
+
40
+ ```
41
+ index.js host 半区:apply(ctx) → memory_search 工具 + /memory/api/* 路由
42
+ client.js 前端半区:ModuleLoader bundle,零构建手写 React
43
+ ├── conversation.composer.dock 输入框上方「🧠 记忆库」按钮
44
+ └── sidebar.footer.action 侧栏入口
45
+ lib/
46
+ ├── session-log.js DSH 会话日志解码(多帧 zstd,含 tool/call+result 提取)
47
+ ├── store.js jsonl 存储:domains/global/candidates + 领域注册表 + 迁移 + 检索
48
+ ├── llm.js OpenAI 兼容网关调用(dsh-our-free-model 内置 openai-gateway)
49
+ └── review.js 轨迹→AI起草记忆卡(注入领域清单供归属建议)
50
+ cordis.patch.yml bundle patch:把插件插进 profile 名册 + 通用默认 config
51
+ ```
52
+
53
+ 数据目录 `~/.dsh/memory-domains/`:
54
+
55
+ ```
56
+ domains.json 领域注册表 [{slug,name,desc,created_at}]
57
+ domains/<slug>.jsonl 领域记忆
58
+ global.jsonl 全局记忆
59
+ candidates/<sid>.jsonl 待审草稿
60
+ sessions/<sid>.jsonl 存量会话记忆(仅迁移来源,启动时自动迁移后不再写入)
61
+ session-meta.json 会话标题/消息数缓存(后台预热,落盘加速)
62
+ settings.json 本机覆盖配置(不进 git,见下)
63
+ ```
64
+
65
+ **目录迁移**:旧版数据目录 `~/.dsh/memory-book/` 在首次启动时自动整体改名为 `~/.dsh/memory-domains/`(含 settings.json),只跑一次。
66
+
67
+ **存量迁移**:首次启动自动把旧版 `sessions/*.jsonl` 条目迁移——带 domain 标签的归入同名领域(描述占位待补),无标签的进全局;幂等,只跑一次。
68
+
69
+ ## 安装
70
+
71
+ **方式一:dshmarket 市场 / dsh plugin(推荐)**
72
+
73
+ 插件已发布 npm 并收录进社区目录。在 App 的 **Settings → Plugins → Discover** 搜 `dsh-memory-domains` 一键安装;或命令行:
74
+
75
+ ```cmd
76
+ dsh plugin --profile desktop add dsh-memory-domains
77
+ ```
78
+
79
+ 也可以直接从 GitHub 源安装:
80
+
81
+ ```cmd
82
+ dsh plugin --profile desktop add github:lmx494/dsh-memory-domains
83
+ ```
84
+
85
+ **方式二:link 本地开发**
86
+
87
+ DSH profile 的 `package.json` 加依赖并列入 `dsh.profile.bundles`:
88
+
89
+ ```json
90
+ "dependencies": { "dsh-memory-domains": "link:<本仓库路径>" },
91
+ "dsh": { "profile": { "bundles": ["dsh-memory-domains"] } }
92
+ ```
93
+
94
+ 并在 `node_modules/` 建 junction/symlink 指向本目录。重启 DSH 后输入框上方出现「🧠 记忆库」。
95
+
96
+ ## 配置
97
+
98
+ `cordis.patch.yml` 只带通用默认值。整理记忆走 **OpenAI 兼容网关**——默认对准 `dsh-our-free-model` 内置的 channel-pack openai-gateway(`127.0.0.1:8326`,模型池即该插件的模型);也可指向任何 OpenAI 兼容端点。**本机差异配置写到 `~/.dsh/memory-domains/settings.json`**(优先级最高、不进 git):
99
+
100
+ ```json
101
+ {
102
+ "baseUrl": "http://127.0.0.1:8326/v1",
103
+ "apiKeyFile": "C:/Users/<you>/.dsh/openai-gateway/api-key",
104
+ "reviewModel": "<你的网关支持的模型>",
105
+ "reviewTimeoutMs": 180000
106
+ }
107
+ ```
108
+
109
+ 所有键都可省略走代码默认值;`apiKey` 可代替 `apiKeyFile` 直接内联密钥(不建议提交进任何 git)。`githubToken`(或环境变量 `GITHUB_TOKEN`)给「发现项目」的 GitHub 搜索提额,匿名也能用只是限流低。
110
+
111
+ ## API
112
+
113
+ 同源 `/memory/api/*`(宿主把前缀路由挂在 `/api/` 命名空间下;非 GET/HEAD 校验 Origin 同源 + Host loopback,防浏览器跨站写入):
114
+
115
+ | 方法 | 路径 | 说明 |
116
+ |---|---|---|
117
+ | GET | `/api/sessions` | 会话清单(`pending`>0 表示标题还在后台预热) |
118
+ | GET/POST | `/api/domains*` | 领域列表 / 创建 / update / delete |
119
+ | POST | `/api/domains/draft` | AI 起草领域描述 `{name}` → `{desc}` |
120
+ | POST | `/api/discover` | 领域画像 → GitHub 项目发现 `{domain: slug}` → `{queries, repos, errors}` |
121
+ | GET | `/api/memories?scope=&domain=&session=` | `scope=domain&domain=<slug>` / `global` / `all`;`session=` 按来源会话过滤 |
122
+ | GET/POST | `/api/candidates*` | 草稿列表 / accept(带目标) / reject / update |
123
+ | POST | `/api/review` | 异步整理 `{session}` → `{job}` |
124
+ | GET | `/api/review/status?job=` | job 状态轮询 |
125
+ | POST | `/api/promote` `/api/archive` `/api/delete` `/api/create` | 条目操作 |
126
+
127
+ ## 设计边界
128
+
129
+ - **人管记忆,AI 只起草**:所有写入路径(整理/入库/升级/归档/删除/建领域)都由 UI 按钮或用户显式调用触发;`memory_search` 只读
130
+ - **领域是知识库单元**:一条记忆单归属;跨领域通用的走全局,避免多副本不同步
131
+ - **领域描述即路标**:描述必填且面向"任务是否属于此领域"的判断来写;AI 检索靠领域地图+关键词,不做向量检索
132
+ - **文件化可审计**:jsonl 纯文本、可 diff、可手改、可版本控制;无向量库、无嵌入服务
133
+ - **fail-open**:前端任何环节失败都不影响 DSH 主流程
134
+
135
+ ## 与 workflow-engine 的关系
136
+
137
+ `workflow-engine` 的 `mistakes.jsonl` + `learn.js` 是同一思想的领域实例(裁判 critique → AI 起草 → 人审入库)。本插件把它泛化成通用 agent 记忆层:轨迹源从"engine run 存档"换成"任意 DSH 会话",组织从"会话/全局两级"升级为"领域/全局"知识库,检索从"pack 工具"换成"memory_search"。两者的 jsonl 格式同构,可互相迁移。