dsh-context-graph 0.2.3 → 0.4.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/README.md +148 -132
- package/README.zh.md +63 -0
- package/cordis.patch.yml +15 -18
- package/graph.js +144 -109
- package/icon.svg +15 -0
- package/index.js +410 -421
- package/lib/client.js +126 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +7 -0
- package/package.json +17 -3
- package/store.js +55 -20
package/README.md
CHANGED
|
@@ -1,132 +1,148 @@
|
|
|
1
|
-
# dsh-context-graph
|
|
2
|
-
|
|
3
|
-
A DeepSeek Harness (dsh) plugin that
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
2. **
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
npm
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
|
91
|
-
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
node --test
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
1
|
+
# dsh-context-graph
|
|
2
|
+
|
|
3
|
+
A DeepSeek Harness (dsh) plugin that gives each chat a small memory graph you switch on when you
|
|
4
|
+
want it. Other chats in the same workspace then get a short pointer to what was decided before, and
|
|
5
|
+
the model fetches the exact original text only when it needs it. Old messages are not re-sent;
|
|
6
|
+
decisions are not lost.
|
|
7
|
+
|
|
8
|
+
First principle: save input tokens without losing quality. The plugin adds nothing to a request
|
|
9
|
+
unless you turned memory on in that chat, and what it adds is a few lines that point at exact text.
|
|
10
|
+
|
|
11
|
+
Status: v0.4.0. Loads in the dsh desktop app (dsh 0.2.1-rc.5); not yet verified with a live model.
|
|
12
|
+
Tests pass against the published dsh packages.
|
|
13
|
+
|
|
14
|
+
Using Claude Code instead? The Claude version is a separate plugin built for Claude's app:
|
|
15
|
+
[claude-context-graph](https://github.com/William20100221/claude-context-graph).
|
|
16
|
+
|
|
17
|
+
## How it works
|
|
18
|
+
|
|
19
|
+
Nothing happens in a chat until you run `/context-graph on`. From then on:
|
|
20
|
+
|
|
21
|
+
| Moment | What happens | Cost |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| `/context-graph on` | The chat is indexed now, then again every 4 human turns: one small auxiliary model call writes topics into `.context-graph/chats/<chat>/graph.json` and stores the cited messages verbatim. | about the new text's tokens in, under 1k out, off the critical path |
|
|
24
|
+
| First message after `on` | One block lists the shared chats of this workspace, newest first: chat id, date, title, topic count. | about 15 tokens per chat |
|
|
25
|
+
| Every human message | Your words are matched against the topics of the other shared chats by word overlap (no model call). Up to 5 hits are appended to the message. One clearly dominant short hit is included verbatim. | under about 150 tokens |
|
|
26
|
+
| Your message names a time | "yesterday", "last week", "11月1日", "2026-11-01" ... that slice is searched first: chats active then, then topics from then, then everything. If nothing matches, the chats from that time are listed instead. | same |
|
|
27
|
+
| Model calls `recall(id)` | `c3n12`: the topic's verbatim source and linked topics. `c3`: a chat's topics. `2026-11-01`: every chat and topic from that day. `t7`: turn 7 of this chat word for word. | one tool round trip |
|
|
28
|
+
| `/context-graph share` | Lets other chats in the workspace see this chat's graph. Nothing is copied or merged; it is a flag on the chat. | none |
|
|
29
|
+
|
|
30
|
+
Design rules, in order:
|
|
31
|
+
|
|
32
|
+
1. **Off until asked.** No surface map, no matches, no indexing in a chat that has not run `on`.
|
|
33
|
+
2. **Nothing is written without its source.** A topic is stored only together with the verbatim
|
|
34
|
+
messages it was drawn from. The gist is a pointer, never the record.
|
|
35
|
+
3. **Organise, never merge.** Each chat's graph stays in its own folder with its own dates. Sharing
|
|
36
|
+
is a flag. Ids carry the chat number (`c3n12`) so every topic traces back to its chat.
|
|
37
|
+
4. **Time is the first filter.** A named day or week narrows the search before anything else.
|
|
38
|
+
5. **Append at the end.** Injected blocks ride at the tail of the newest message so the provider's
|
|
39
|
+
prefix cache survives. Hiding or folding old turns is not this plugin's job.
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
Type `/context-graph`, pick it from the menu, then type the word:
|
|
44
|
+
|
|
45
|
+
| Command | Does |
|
|
46
|
+
|---|---|
|
|
47
|
+
| `on` / `off` | Start or stop memory for this chat. `off` keeps the graph file. |
|
|
48
|
+
| `share` / `unshare` | Let other chats in the workspace use this chat's graph, or stop. |
|
|
49
|
+
| `stats` (default) | Memory state, topic counts, shared chats, pending turns, token counters. |
|
|
50
|
+
| `build` | Index this chat now. |
|
|
51
|
+
| `map` | Every chat in the workspace, newest first, with its top topics. |
|
|
52
|
+
| `find <words>` | Search the shared chats; time words narrow it. |
|
|
53
|
+
|
|
54
|
+
Results show in dsh's own command card: a one-line summary that expands to the details.
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
Desktop app: **Plugins → Add plugin**, official npm registry, enter `dsh-context-graph`,
|
|
59
|
+
install, then fully restart the app so the `/context-graph` command appears.
|
|
60
|
+
|
|
61
|
+
Command line (use the profile your app runs; the desktop app uses `desktop`):
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
dsh plugin --profile desktop add dsh-context-graph
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Updates.** dsh 0.2.1 desktop builds have no update check for third-party plugins, so the
|
|
68
|
+
plugin checks npm itself once per app start. When a newer version exists, your next chat reply
|
|
69
|
+
ends with one line saying so, and `/context-graph stats` shows it on its first line. To update:
|
|
70
|
+
Plugins, open dsh-context-graph, **Uninstall**, then **Add plugin** `dsh-context-graph@<new version>`
|
|
71
|
+
and restart the app. Name the exact version: dsh's pnpm holds back very new releases otherwise.
|
|
72
|
+
Turn the check off with the environment variable `DSH_CONTEXT_GRAPH_NO_UPDATE_CHECK=1`.
|
|
73
|
+
|
|
74
|
+
Remove with `dsh plugin --profile desktop remove dsh-context-graph`.
|
|
75
|
+
|
|
76
|
+
## Releasing a new version
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
npm test
|
|
80
|
+
npm version patch
|
|
81
|
+
npm publish
|
|
82
|
+
git push --follow-tags
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Configuration
|
|
86
|
+
|
|
87
|
+
Defaults live in [cordis.patch.yml](cordis.patch.yml). A patch replaces the row's whole
|
|
88
|
+
`config`, so restate every key you keep.
|
|
89
|
+
|
|
90
|
+
| Key | Default | Meaning |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `dir` | `.context-graph` | Memory folder, relative to the agent workspace or absolute |
|
|
93
|
+
| `buildEveryTurns` | `4` | Index after this many new human turns (chats with memory on) |
|
|
94
|
+
| `buildMinChars` | `400` | ...and at least this much new text |
|
|
95
|
+
| `maxHits` | `5` | Topics shown per human turn |
|
|
96
|
+
| `inlineMaxChars` | `1200` | A single dominant hit this short is shown verbatim |
|
|
97
|
+
| `surfaceMaxChats` | `20` | Chats listed right after `on` |
|
|
98
|
+
| `builderMaxTokens` | `8192` | Output cap for the indexing call; thinking models spend part of it reasoning |
|
|
99
|
+
| `provider`, `model` | `''` | Empty: reuse the conversation's routed provider and model |
|
|
100
|
+
|
|
101
|
+
## Files
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
index.js dsh plugin: builder, matcher, recall tool, meter, /context-graph command
|
|
105
|
+
graph.js pure core: tokenize, match, time ranges, merge, render, builder prompt and parser
|
|
106
|
+
store.js chats/<chat>/{meta.json, graph.json, src/<id>.md}
|
|
107
|
+
update.js once-per-start check of npm for a newer version
|
|
108
|
+
lib/client.js dsh chat card for /context-graph (DisclosureRow, en/zh titles)
|
|
109
|
+
icon.svg Plugins page icon in dsh's built-in icon style
|
|
110
|
+
locale/ Plugins page title and description (en, zh); zh links README.zh.md
|
|
111
|
+
cordis.patch.yml mounts the plugin at the profile root with default config
|
|
112
|
+
test/ node --test; plugin.test.js needs DSH_NODE_MODULES (see below)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
On disk, per workspace:
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
.context-graph/chats/<sessionId>/meta.json cid, title, startedAt, lastActiveAt, turns, memory, shared
|
|
119
|
+
.context-graph/chats/<sessionId>/graph.json topics and links; every topic has its time
|
|
120
|
+
.context-graph/chats/<sessionId>/src/<id>.md verbatim messages behind each topic
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Testing
|
|
124
|
+
|
|
125
|
+
Unit tests need nothing:
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
node --test test/graph.test.js
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The wiring test imports the real dsh packages from an existing dsh install. Point it at that
|
|
132
|
+
install's `node_modules`:
|
|
133
|
+
|
|
134
|
+
```sh
|
|
135
|
+
DSH_NODE_MODULES=/path/to/dsh/node_modules npm test
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Without the variable it is skipped. Nothing here calls a model.
|
|
139
|
+
|
|
140
|
+
## Known limits
|
|
141
|
+
|
|
142
|
+
- Builds are indexed per process; after a restart the first build of a resumed chat re-reads its
|
|
143
|
+
whole surface. Existing ids are reused, so this costs one larger call, not duplicates.
|
|
144
|
+
- Two agents writing the same chat's graph at once: last writer wins.
|
|
145
|
+
- Subagent sessions are neither indexed nor given memory blocks.
|
|
146
|
+
- Tool outputs are not indexed as topics; `recall("tN")` returns them (each capped at 2000 characters).
|
|
147
|
+
- The chat title is the first message, shortened, until dsh exposes its own titles to plugins.
|
|
148
|
+
- The graph page (a visual map in the sidebar) is not built yet; `/context-graph map` is the text version.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# 上下文图谱(dsh-context-graph)
|
|
2
|
+
|
|
3
|
+
DeepSeek Harness 插件:给每个对话一张小型记忆图谱,由你决定何时开启。同一工作区里的其他对话会收到几行指向过往结论的提示,模型需要细节时再取回原文。旧消息不再重复发送,结论也不会丢失。
|
|
4
|
+
|
|
5
|
+
第一原则:在不损失质量的前提下减少输入 token。没有在某个对话里运行 `/context-graph on`,插件不会往请求里加任何内容。
|
|
6
|
+
|
|
7
|
+
## 它做什么
|
|
8
|
+
|
|
9
|
+
在对话里运行 `/context-graph on` 之后:
|
|
10
|
+
|
|
11
|
+
| 时机 | 发生了什么 |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `/context-graph on` | 立即索引当前对话,之后每 4 轮人类发言再索引一次:一次小型模型调用把主题写进 `.context-graph/chats/<对话>/graph.json`,并原样保存被引用的消息。不会拖慢回复。 |
|
|
14
|
+
| 开启后的第一条消息 | 附上本工作区已共享的对话列表(最新在前):对话编号、日期、标题、主题数。 |
|
|
15
|
+
| 每条人类消息 | 按词语重合匹配其他已共享对话的主题(不调用模型),把最多 5 个相关主题附在消息末尾。唯一且很短的命中会直接附原文。 |
|
|
16
|
+
| 消息里提到时间 | “昨天”“上周”“11月1日”“2026-11-01”……先搜那个时间段:先按对话,再按主题,最后才搜全部。没有命中时,列出那段时间的对话。 |
|
|
17
|
+
| 模型调用 `recall` | `c3n12`:该主题的原文和相邻主题。`c3`:某个对话的主题列表。`2026-11-01`:那天的全部对话和主题。`t7`:当前对话第 7 轮的原文。 |
|
|
18
|
+
| `/context-graph share` | 让工作区里的其他对话看到本对话的图谱。只是一个标记,不复制、不合并。 |
|
|
19
|
+
|
|
20
|
+
设计规则:
|
|
21
|
+
|
|
22
|
+
1. **不开不动。** 没有运行 `on` 的对话不会被索引,也不会收到任何附加内容。
|
|
23
|
+
2. **没有原文不写入。** 主题只和它来源的原始消息一起保存。要点是指针,不是记录。
|
|
24
|
+
3. **只组织,不合并。** 每个对话的图谱留在自己的文件夹里,带自己的日期。编号带对话号(`c3n12`),每个主题都能追溯到来源对话。
|
|
25
|
+
4. **时间是第一过滤条件。**
|
|
26
|
+
5. **只在末尾追加**,保住服务商的前缀缓存。隐藏或折叠旧轮次不是本插件的工作。
|
|
27
|
+
|
|
28
|
+
## 命令
|
|
29
|
+
|
|
30
|
+
输入 `/context-graph`,在菜单里选中后再输入后面的词:
|
|
31
|
+
|
|
32
|
+
| 命令 | 作用 |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `on` / `off` | 开启或关闭本对话的记忆。`off` 保留图谱文件。 |
|
|
35
|
+
| `share` / `unshare` | 允许或停止工作区里的其他对话使用本对话的图谱。 |
|
|
36
|
+
| `stats`(默认) | 记忆状态、主题数、共享对话数、待索引轮数、token 计数。 |
|
|
37
|
+
| `build` | 立即索引当前对话。 |
|
|
38
|
+
| `map` | 工作区里的全部对话(最新在前)及其主要主题。 |
|
|
39
|
+
| `find 关键词` | 在已共享对话里查找;时间词会缩小范围。 |
|
|
40
|
+
|
|
41
|
+
结果显示在 dsh 自带的命令卡片里:第一行是摘要,展开看详情。
|
|
42
|
+
|
|
43
|
+
## 安装与更新
|
|
44
|
+
|
|
45
|
+
插件 → 添加插件 → 官方 npm 源 → 输入 `dsh-context-graph`,安装后完全重启应用。
|
|
46
|
+
|
|
47
|
+
有新版本时,你的下一次回复末尾会提示一次,`/context-graph` 的第一行也会显示。更新方法:打开本插件 → 卸载 → 添加插件 `dsh-context-graph@新版本号` → 重启。务必写明版本号:dsh 的 pnpm 默认会暂缓刚发布的版本。
|
|
48
|
+
|
|
49
|
+
## 文件
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
.context-graph/chats/<对话>/meta.json 编号、标题、开始/最近时间、轮数、memory、shared
|
|
53
|
+
.context-graph/chats/<对话>/graph.json 主题与链接,每个主题带时间
|
|
54
|
+
.context-graph/chats/<对话>/src/<id>.md 每个主题背后的原始消息
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 已知限制
|
|
58
|
+
|
|
59
|
+
- 重启后,续聊的第一次索引会重读整个对话(编号复用,不会重复)。
|
|
60
|
+
- 两个代理同时写同一个对话的图谱:后写的覆盖先写的。
|
|
61
|
+
- 子代理会话不索引,也不附加记忆。
|
|
62
|
+
- 对话标题暂用第一条消息的缩写。
|
|
63
|
+
- 侧边栏的可视化图谱页面尚未实现,`/context-graph map` 是文字版。
|
package/cordis.patch.yml
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
# Mounted at the profile root so the recall tool, the matcher and the builder are available to
|
|
2
|
-
# every agent. Every value below is the default; restate the whole config block when you change one.
|
|
3
|
-
- insert:
|
|
4
|
-
- id: context-graph
|
|
5
|
-
name: dsh-context-graph
|
|
6
|
-
config:
|
|
7
|
-
dir: .context-graph # relative to the agent workspace, or an absolute path
|
|
8
|
-
buildEveryTurns: 4 # index after this many new human turns
|
|
9
|
-
buildMinChars: 400 # ...and at least this much new text
|
|
10
|
-
maxHits: 5 #
|
|
11
|
-
inlineMaxChars: 1200 # one dominant hit this short is shown verbatim, no recall needed
|
|
12
|
-
|
|
13
|
-
builderMaxTokens: 8192 # thinking models spend part of this on reasoning
|
|
14
|
-
provider: '' # empty: reuse the conversation's routed provider/model
|
|
15
|
-
model: ''
|
|
16
|
-
fold: true # replace old turns of the current chat with a table of contents
|
|
17
|
-
foldAtTokens: 24000 # fold once the foldable part costs this much per request
|
|
18
|
-
keepTurns: 2 # newest human turns always kept word for word
|
|
1
|
+
# Mounted at the profile root so the recall tool, the matcher and the builder are available to
|
|
2
|
+
# every agent. Every value below is the default; restate the whole config block when you change one.
|
|
3
|
+
- insert:
|
|
4
|
+
- id: context-graph
|
|
5
|
+
name: dsh-context-graph
|
|
6
|
+
config:
|
|
7
|
+
dir: .context-graph # relative to the agent workspace, or an absolute path
|
|
8
|
+
buildEveryTurns: 4 # index after this many new human turns (only in chats with memory on)
|
|
9
|
+
buildMinChars: 400 # ...and at least this much new text
|
|
10
|
+
maxHits: 5 # topics shown per human turn
|
|
11
|
+
inlineMaxChars: 1200 # one dominant hit this short is shown verbatim, no recall needed
|
|
12
|
+
surfaceMaxChats: 20 # chats listed right after /context-graph on
|
|
13
|
+
builderMaxTokens: 8192 # thinking models spend part of this on reasoning
|
|
14
|
+
provider: '' # empty: reuse the conversation's routed provider/model
|
|
15
|
+
model: ''
|