dsh-context-graph 0.3.0 → 0.6.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 CHANGED
@@ -1,144 +1,251 @@
1
- # dsh-context-graph
2
-
3
- A DeepSeek Harness (dsh) plugin that remembers your past conversations as a small graph.
4
- New sessions start with a one-screen map of what was decided before, each turn gets the few
5
- nodes that match what you just asked, and the model fetches the verbatim original text only
6
- when it needs it. Old messages stop being re-sent; decisions stop getting lost.
7
-
8
- **Folding (v0.2.0).** Every chat normally re-sends all earlier messages on every turn. Once the
9
- older part of a chat costs more than `foldAtTokens` per request, the plugin replaces it with one
10
- short table of contents: the topics found in it and a one-line list of what you asked in each
11
- turn (t1, t2, ...). The model follows that table to the exact part it needs with `recall("t7")`
12
- or `recall("n12")`. Your newest turns stay word for word. Nothing is deleted: the full turns stay
13
- in the session log and in the chat window.
14
-
15
- **Looks like dsh (v0.3.0).** The Plugins page shows the plugin's own icon in dsh's icon style, a
16
- title and description in English or Chinese (上下文图谱), and a Chinese detail page. In chat,
17
- `/context-graph` results appear in dsh's own command card: a titled row with a one-line summary
18
- that expands to the details.
19
-
20
- Status: v0.3.0. Installs and loads in the dsh desktop app (dsh 0.2.1-rc.5); folding and indexing
21
- are not yet verified with a live model. 28 tests pass against the published dsh packages.
22
-
23
- Using Claude Code instead? The Claude version is a separate plugin built for Claude's app:
24
- [claude-context-graph](https://github.com/William20100221/claude-context-graph).
25
-
26
- ## What it does
27
-
28
- | Moment | What happens | Cost |
29
- |---|---|---|
30
- | Every 4 human turns (default) | After the turn closes, one small auxiliary model call indexes the new messages into `.context-graph/graph.json` and stores the cited messages verbatim under `.context-graph/src/`. | about the span's tokens in, under 1k out, off the critical path |
31
- | First human turn of a session | A `[context-graph]` block lists the best-connected nodes from earlier sessions: id, label, one-line gist. | about 15 tokens per node, 40 nodes max |
32
- | Every human turn | The prompt is matched against node labels and aliases 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 |
33
- | Older part of this chat costs more than 24k tokens per request | At the start of your next turn it is replaced by a table of contents (topics plus one line per turn). The last 2 turns stay as they are. | breaks the provider cache once per fold, then every later request is smaller |
34
- | Model calls `recall(id)` | `n12`: the topic's verbatim source and neighbours. `t7`: folded turn 7 exactly, including tool calls. | one tool round trip |
35
- | `/context-graph` | `stats`, `build` (index now), `fold` (index and fold now), `find <words>`. | none |
36
-
37
- Design rules, in order of importance:
38
-
39
- 1. **Nothing is written without its source.** A node is stored only together with the verbatim
40
- messages it was drawn from. The gist is a pointer, never the record.
41
- 2. **Fold in batches, not every turn.** DeepSeek bills re-sent cached input at about 1/30 price,
42
- and any fold restarts that cache. So a fold happens only when the old part is large
43
- (24k tokens by default) and the table of contents is under half its size. Between folds the
44
- prefix stays stable and cached. Matcher blocks ride at the end of the newest message.
45
- 3. **Old decisions resolve to new ones.** A `supersedes` edge makes a hit on the old node show
46
- the replacement instead.
47
- 4. **Matching is lexical.** Labels, aliases and gists; English words, identifiers and Chinese
48
- bigrams. The builder is asked to write aliases precisely so this works without embeddings.
49
-
50
- The full design, including what was borrowed from `dsh-plugin-save-token` and why cache
51
- economics make cross-session memory the main win, is in [docs/core-design.md](docs/core-design.md).
52
-
53
- ## Install
54
-
55
- Desktop app: **Plugins → Add plugin**, official npm registry, enter `dsh-context-graph`,
56
- install, then fully restart the app so the `/context-graph` command appears.
57
-
58
- Command line (use the profile your app runs; the desktop app uses `desktop`):
59
-
60
- ```sh
61
- dsh plugin --profile desktop add dsh-context-graph
62
- ```
63
-
64
- **Updates.** dsh 0.2.1 desktop builds have no update check for third-party plugins, so the
65
- plugin checks npm itself once per app start. When a newer version exists, your next chat reply
66
- ends with one line saying so, and `/context-graph stats` shows it on its first line. To update:
67
- Plugins, open dsh-context-graph, **Uninstall**, then **Add plugin** `dsh-context-graph@<new version>`
68
- and restart the app. Name the exact version: dsh's pnpm holds back very new releases otherwise.
69
- Turn the check off with the environment variable `DSH_CONTEXT_GRAPH_NO_UPDATE_CHECK=1`.
70
-
71
- Remove with `dsh plugin --profile desktop remove dsh-context-graph`.
72
-
73
- ## Releasing a new version
74
-
75
- ```sh
76
- npm test
77
- npm version patch
78
- npm publish
79
- git push --follow-tags
80
- ```
81
-
82
- `npm version patch` bumps the version, commits and tags it. `npm publish` needs `npm login`
83
- once. Users then see the new version after pressing Refresh on the Plugins page.
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` | Graph folder, relative to the agent workspace or absolute |
93
- | `buildEveryTurns` | `4` | Index after this many new human turns |
94
- | `buildMinChars` | `400` | ...and at least this much new text |
95
- | `maxHits` | `5` | Nodes shown per human turn |
96
- | `inlineMaxChars` | `1200` | A single dominant hit this short is shown verbatim |
97
- | `surfaceMaxNodes` | `40` | Nodes listed at the start of a session |
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
- | `fold` | `true` | Fold old turns of the current chat into a table of contents |
101
- | `foldAtTokens` | `24000` | Fold once the foldable part costs this much per request |
102
- | `keepTurns` | `2` | Newest human turns never folded |
103
-
104
- ## Files
105
-
106
- ```
107
- index.js dsh plugin: builder, matcher, recall tool, meter, /context-graph command
108
- graph.js pure core: tokenize, match, merge, render, builder prompt and parser
109
- store.js graph.json and src/<id>.md read/write
110
- update.js once-per-start check of npm for a newer version
111
- lib/client.js dsh chat card for /context-graph (DisclosureRow, en/zh titles)
112
- icon.svg Plugins page icon in dsh's built-in icon style
113
- locale/ Plugins page title and description (en, zh); zh links README.zh.md
114
- cordis.patch.yml mounts the plugin at the profile root with default config
115
- test/ node --test; plugin.test.js needs DSH_NODE_MODULES (see below)
116
- docs/ design
117
- ```
118
-
119
- ## Testing
120
-
121
- Unit tests need nothing:
122
-
123
- ```sh
124
- node --test test/graph.test.js
125
- ```
126
-
127
- The wiring test imports the real dsh packages from an existing dsh install. Point it at that
128
- install's `node_modules`:
129
-
130
- ```sh
131
- DSH_NODE_MODULES=/path/to/dsh/node_modules npm test
132
- ```
133
-
134
- Without the variable it is skipped. Nothing here calls a model.
135
-
136
- ## Known limits
137
-
138
- - Builds are indexed per process; after a restart the first build of a resumed session re-reads
139
- its whole surface. Existing ids are reused, so this costs one larger call, not duplicates.
140
- - Two agents writing the same workspace graph at once: last writer wins.
141
- - Subagent sessions are neither indexed nor given memory blocks.
142
- - Tool outputs are not indexed as topics, but they are folded and `recall("tN")` returns them (each capped at 2000 characters).
143
- - Only indexed turns are folded. After an app restart the index position resets, so the first fold waits for one build.
144
- - A skill list or runtime-context message inside the folded part is copied into the fold message so the model keeps it.
1
+ <p align="center">
2
+ <img src="icon.svg" width="72" height="72" alt="Context Graph icon">
3
+ </p>
4
+
5
+ <h1 align="center">Context Graph for DeepSeek Harness</h1>
6
+
7
+ <p align="center">
8
+ Memory for your chats, on from the moment you install it.<br>
9
+ Later chats get a few lines that point at what was decided; the model fetches the exact text only when it needs it.
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://www.npmjs.com/package/dsh-context-graph"><img alt="npm" src="https://img.shields.io/npm/v/dsh-context-graph?label=npm&color=4A65E8"></a>
14
+ <img alt="dsh" src="https://img.shields.io/badge/dsh-0.2.1-7AC2FF">
15
+ <img alt="license" src="https://img.shields.io/badge/license-MIT-lightgrey">
16
+ <a href="README.zh.md"><img alt="中文" src="https://img.shields.io/badge/文档-中文-4A65E8"></a>
17
+ </p>
18
+
19
+ ---
20
+
21
+ **The problem.** Every message you send re-sends the whole conversation, and a new chat knows
22
+ nothing about the last one. You re-explain, the model re-reads, and you pay input tokens for both.
23
+
24
+ **What this does.** In every chat (memory is on by default), the plugin indexes what was
25
+ decided into a small graph of topics, each stored together with the original messages. Other
26
+ chats in the same workspace get, at most, a few lines like this appended to your message:
27
+
28
+ ```
29
+ [context-graph] Related past context from yesterday (by chat). Call recall(id) for the verbatim source.
30
+ - c3n12 builder timeout: builderMaxTokens raised to 8192 after the 524s (2026-11-01)
31
+ - c3n4 publish flow: npm version patch, npm publish (2FA), git push --follow-tags (2026-11-01)
32
+ ```
33
+
34
+ The model calls `recall("c3n12")` when a gist is not precise enough and gets the original turns,
35
+ word for word. Nothing is summarised away, and nothing is sent that you did not ask for.
36
+
37
+ > **First principle:** save input tokens without losing quality. A few lines per message; exact
38
+ > text on demand.
39
+ >
40
+ > **Turning it off.** Plugins page → Context Graph → switch it off: no chat is indexed or gets
41
+ > anything added. To stop only one chat, run `/context-graph off` in it.
42
+
43
+ ## Quick start
44
+
45
+ 1. **Plugins → Add plugin**, official npm registry, type `dsh-context-graph`, install, then fully
46
+ restart the app (new slash commands need a restart).
47
+ 2. Chat as usual. Every chat indexes itself every 4 turns and is shared with the other chats of
48
+ its workspace. Type `/context-graph`, pick it from the menu, then `build` to index one right away.
49
+ 3. Open a new chat in the same workspace and ask about something from the first.
50
+ 4. To keep one chat out of the others, run `/context-graph unshare` in it.
51
+
52
+ Command line instead of the Plugins page (the desktop app uses the `desktop` profile):
53
+
54
+ ```sh
55
+ dsh plugin --profile desktop add dsh-context-graph
56
+ ```
57
+
58
+ ## Commands
59
+
60
+ All commands are `/context-graph <word>`. Type `/context-graph`, pick it from the menu, then type
61
+ the word. Results show in dsh's own command card: a one-line summary that expands to the details.
62
+ No word means `stats`.
63
+
64
+ ### `on` — resume memory for this chat
65
+
66
+ Memory is already on in every chat. `on` undoes an earlier `off` and indexes the chat right away.
67
+
68
+ Indexes the chat right away and then again every 4 human turns (one small auxiliary model call
69
+ each time, using the chat's own routed model unless you configure another). Creates
70
+ `.context-graph/chats/<chat>/` with the chat's graph, its verbatim sources and a `meta.json`
71
+ holding its title, dates and flags. From now on every message you send in this chat is matched
72
+ against the other shared chats of the workspace, and the first message of the chat also carries the
73
+ list of those chats, newest first.
74
+
75
+ Card: `Memory on · 7 topics in this chat · 2 shared chats to draw on`
76
+
77
+ ### `off` — stop memory for this chat only
78
+
79
+ To stop it in every chat, switch the plugin off on the Plugins page instead.
80
+
81
+ Stops indexing and stops adding anything to your requests. The graph folder stays on disk, so
82
+ `on` later resumes where it left off. Other chats keep seeing this chat if it is shared.
83
+
84
+ ### `share` / `unshare` — keep a chat private, or share it again
85
+
86
+ Every chat is shared by default: other chats with memory on can match and recall its topics.
87
+ `unshare` makes this chat private; `share` undoes that. Nothing is copied or merged: the graph stays in its own folder with its own dates, and its
88
+ ids carry the chat number (`c3n12`) so every hit traces back to where it came from. Both take
89
+ effect at once. A chat shared
90
+ before its first index has nothing to offer yet; it fills in every 4 turns or with `build`.
91
+
92
+ Card: `Shared with the workspace · 7 topics`
93
+
94
+ ### `stats` — where things stand (default)
95
+
96
+ First line: memory on/off, topics in this chat, shared/private, how many shared chats are
97
+ visible, how many of this chat's turns are waiting to be indexed, and `update available` when a
98
+ newer version is on npm. The body shows the version, the memory folder, and counters since the app
99
+ started: builds and builder tokens, injected blocks and their size, recalls, and the main
100
+ conversation's input split into uncached, cache-read and cache-write with the cache-hit rate. A
101
+ high cache-hit rate is the sign that memory is saving money rather than spending it.
102
+
103
+ Card: `Memory on · 7 topics in this chat · shared · 2 shared chats · 3 turns waiting to be indexed`
104
+
105
+ ### `build` — index this chat now
106
+
107
+ Runs the indexing call immediately instead of waiting for the next 4-turn mark. Useful right
108
+ before you switch chats. Needs memory on. If the model's answer cannot be read, the raw output is
109
+ saved to `last-builder-output.txt` in the chat's folder and the card tells you why.
110
+
111
+ Card: `3 topics indexed (2 new) · this chat has 7 topics`
112
+
113
+ ### `map` — every chat in the workspace
114
+
115
+ Lists all indexed chats newest first: chat id, start date, title, topic count and flags (`this
116
+ chat`, `memory on`, `shared`/`private`), each followed by its most connected topics with their ids.
117
+ This is the text form of the graph; a visual page is planned.
118
+
119
+ ```
120
+ 2 chats in C:\Projects\site\.context-graph
121
+ c2 2026-11-02 Fix the login redirect loop · 4 topics · this chat, memory on, private
122
+ - c2n1 redirect loop cause: session cookie set with the wrong path (2026-11-02)
123
+ c1 2026-11-01 Set up CI for the site · 6 topics · memory on, shared
124
+ - c1n3 deploy step: GitHub Pages from the gh-pages branch (2026-11-01)
125
+ ```
126
+
127
+ ### `find <words>` — search the shared chats
128
+
129
+ The same matcher the plugin runs on your messages, so you can see what the model would be shown.
130
+ Time words narrow it: `find 524 timeout last week` looks in chats active last week first. Only
131
+ shared chats of other conversations are searched; the current chat's own topics are left out
132
+ because they are already in its context.
133
+
134
+ Card: `2 matching topics`, then `c3n12 builder timeout: ...` per line.
135
+
136
+ ## How matching and recall work
137
+
138
+ **Matching is lexical and free.** Your message is split into words, identifiers (`clear_conversation`
139
+ also yields `clear` and `conversation`) and Chinese character pairs. Topic labels and aliases count
140
+ double, gists single, well-connected topics get a small boost, and a topic only counts when a label
141
+ or alias word matched. Up to 5 hits are shown; when one hit is clearly ahead and its source is
142
+ short, the source is included verbatim so no `recall` round trip is needed. A changed decision
143
+ links to its replacement with a `supersedes` edge, so a hit on the old one shows the new one.
144
+
145
+ **Time is the first filter.** If your message names a time, the search runs in that slice first and
146
+ widens only if it finds nothing:
147
+
148
+ | You write | Searched first |
149
+ |---|---|
150
+ | `yesterday`, `昨天` | chats active yesterday |
151
+ | `3 days ago`, `3天前` | that day |
152
+ | `last week`, `上周` / `this week`, `本周` | Monday to Monday |
153
+ | `last month`, `上个月` | that calendar month |
154
+ | `2026-11-01`, `11月1日` | that day |
155
+
156
+ If nothing matches in the slice and nothing matches anywhere, the chats from that time are listed
157
+ instead, so "what did we do yesterday?" still gets a useful answer.
158
+
159
+ **Recall ids.** The model (or you, in a message) can ask for:
160
+
161
+ | Id | Returns |
162
+ |---|---|
163
+ | `c3n12` | Topic 12 of chat 3: label, gist, the original messages word for word, and linked topics |
164
+ | `c3` | Chat 3: title, dates, and its topics most connected first |
165
+ | `2026-11-01` | Every shared chat active that day, each with its topics from that day first |
166
+ | `t7` | Turn 7 of the current chat word for word, including tool calls and results |
167
+
168
+ ## What it costs
169
+
170
+ | Moment | Added to the request |
171
+ |---|---|
172
+ | Chats without `on` | nothing |
173
+ | First message of a chat | about 15 tokens per shared chat, 20 chats at most |
174
+ | Every later message | nothing when no topic matches; under about 150 tokens when some do |
175
+ | Indexing | one auxiliary call every 4 turns, off the critical path; roughly the new text in, under 1k tokens out |
176
+ | `recall` | one tool round trip with the exact text |
177
+
178
+ Injected blocks are appended to the end of your newest message, never inserted earlier, so the
179
+ provider's prefix cache keeps working. DeepSeek bills cached input at a small fraction of the
180
+ uncached price; protecting that cache matters more than shaving a few lines.
181
+
182
+ ## Configuration
183
+
184
+ Defaults live in [cordis.patch.yml](cordis.patch.yml). A patch replaces the row's whole `config`,
185
+ so restate every key you keep.
186
+
187
+ | Key | Default | Meaning |
188
+ |---|---|---|
189
+ | `dir` | `.context-graph` | Memory folder, relative to the agent workspace or absolute |
190
+ | `buildEveryTurns` | `4` | Index after this many new human turns (chats with memory on) |
191
+ | `buildMinChars` | `400` | ...and at least this much new text |
192
+ | `maxHits` | `5` | Topics shown per human turn |
193
+ | `inlineMaxChars` | `1200` | A single dominant hit this short is shown verbatim |
194
+ | `surfaceMaxChats` | `20` | Shared chats listed on the first message of each chat |
195
+ | `builderMaxTokens` | `8192` | Output cap for the indexing call; thinking models spend part of it reasoning |
196
+ | `provider`, `model` | `''` | Empty: reuse the conversation's routed provider and model. Set both to index with a cheaper or faster model |
197
+
198
+ ## Updating
199
+
200
+ dsh 0.2.1 desktop builds have no update check for third-party plugins, so the plugin checks npm
201
+ itself once per app start. When a newer version exists, your next chat reply ends with one line
202
+ saying so, and `/context-graph stats` shows it on its first line. To update: Plugins, open
203
+ dsh-context-graph, **Uninstall**, then **Add plugin** `dsh-context-graph@<new version>` and restart.
204
+ Name the exact version: dsh's pnpm holds back very new releases otherwise. Turn the check off with
205
+ `DSH_CONTEXT_GRAPH_NO_UPDATE_CHECK=1`.
206
+
207
+ Remove with `dsh plugin --profile desktop remove dsh-context-graph`.
208
+
209
+ ## On disk
210
+
211
+ ```
212
+ .context-graph/chats/<sessionId>/meta.json cid, title, startedAt, lastActiveAt, turns; memoryOff / private only after off / unshare
213
+ .context-graph/chats/<sessionId>/graph.json topics and links; every topic has its time
214
+ .context-graph/chats/<sessionId>/src/<id>.md verbatim messages behind each topic
215
+ ```
216
+
217
+ Delete a chat's folder to forget it. Delete `.context-graph/` to forget the workspace.
218
+
219
+ ## Development
220
+
221
+ ```
222
+ index.js dsh plugin: builder, matcher, recall tool, meter, /context-graph command
223
+ graph.js pure core: tokenize, match, time ranges, merge, render, builder prompt and parser
224
+ store.js chats/<chat>/{meta.json, graph.json, src/<id>.md}
225
+ update.js once-per-start check of npm for a newer version
226
+ lib/client.js dsh chat card for /context-graph (DisclosureRow, en/zh titles)
227
+ icon.svg Plugins page icon in dsh's built-in icon style
228
+ locale/ Plugins page title and description (en, zh); zh links README.zh.md
229
+ cordis.patch.yml mounts the plugin at the profile root with default config
230
+ test/ node --test
231
+ ```
232
+
233
+ Unit tests need nothing: `node --test test/graph.test.js`. The wiring test imports the real dsh
234
+ packages from an existing install: `DSH_NODE_MODULES=/path/to/dsh/node_modules npm test`. Nothing
235
+ here calls a model.
236
+
237
+ Release: `npm test`, `npm version patch`, `npm publish`, `git push --follow-tags`.
238
+
239
+ ## Known limits
240
+
241
+ - Not yet verified with a live model; tests run against the published dsh packages.
242
+ - Builds are tracked per process; after a restart the first build of a resumed chat re-reads its
243
+ whole surface. Existing ids are reused, so this costs one larger call, not duplicates.
244
+ - Two agents writing the same chat's graph at once: last writer wins.
245
+ - Subagent sessions are neither indexed nor given memory blocks.
246
+ - Tool outputs are not indexed as topics; `recall("tN")` returns them (each capped at 2000 characters).
247
+ - The chat title is the first message, shortened, until dsh exposes its own titles to plugins.
248
+ - The visual graph page is not built yet; `map` is the text version.
249
+
250
+ Using Claude Code? The Claude version is a separate plugin built for Claude's app:
251
+ [claude-context-graph](https://github.com/William20100221/claude-context-graph).
package/README.zh.md CHANGED
@@ -1,25 +1,65 @@
1
1
  # 上下文图谱(dsh-context-graph)
2
2
 
3
- DeepSeek Harness 插件:把过往对话记成一张小型主题图谱,并把长对话的旧轮次折叠成目录,让每次请求少发送输入 token。需要细节时,模型按目录找到原文。
3
+ DeepSeek Harness 插件:给每个对话一张小型记忆图谱,安装后默认开启。同一工作区里的其他对话会收到几行指向过往结论的提示,模型需要细节时再取回原文。旧消息不再重复发送,结论也不会丢失。
4
+
5
+ 第一原则:在不损失质量的前提下减少输入 token。
6
+
7
+ **如何关闭:** 插件页 → 上下文图谱 → 关闭开关,所有对话都不再索引,也不再往请求里加内容。只想停用某个对话,在该对话里运行 `/context-graph off`。
4
8
 
5
9
  ## 它做什么
6
10
 
11
+ 每个对话默认开启记忆:
12
+
7
13
  | 时机 | 发生了什么 |
8
14
  |---|---|
9
- | 每 4 轮人类发言 | 回合结束后,用一次小型模型调用把新内容整理进 `.context-graph/graph.json`,并原样保存被引用的消息。不会拖慢回复。 |
10
- | 新对话的第一条消息 | 附上之前对话中最重要的主题(编号、名称、一句话要点),最多 40 条。 |
11
- | 每条人类消息 | 按词语重合匹配图谱(不调用模型),把最多 5 个相关主题附在消息末尾。 |
12
- | 对话旧内容每次请求超过约 24k token | 在下一轮开始时,把旧轮次替换为一份目录:主题列表加每轮一句话。最近 2 轮保持原样。原文不删除,聊天窗口照常显示。 |
13
- | 模型调用 `recall` | `n12`:返回该主题的原文和相邻主题。`t7`:原样返回被折叠的第 7 轮,包括工具输出。 |
15
+ | 每个对话 | 每 4 轮人类发言索引一次:一次小型模型调用把主题写进 `.context-graph/chats/<对话>/graph.json`,并原样保存被引用的消息。不会拖慢回复。 |
16
+ | 每个对话的第一条消息 | 附上本工作区已共享的对话列表(最新在前):对话编号、日期、标题、主题数。 |
17
+ | 每条人类消息 | 按词语重合匹配其他已共享对话的主题(不调用模型),把最多 5 个相关主题附在消息末尾。唯一且很短的命中会直接附原文。 |
18
+ | 消息里提到时间 | “昨天”“上周”“11月1日”“2026-11-01”……先搜那个时间段:先按对话,再按主题,最后才搜全部。没有命中时,列出那段时间的对话。 |
19
+ | 模型调用 `recall` | `c3n12`:该主题的原文和相邻主题。`c3`:某个对话的主题列表。`2026-11-01`:那天的全部对话和主题。`t7`:当前对话第 7 轮的原文。 |
20
+ | 共享 | 每个对话默认与同一工作区的其他对话共享。只是一个标记,不复制、不合并。`/context-graph unshare` 让某个对话保持私有。 |
21
+
22
+ 设计规则:
23
+
24
+ 1. **默认开启,随时可关。** 插件页关闭本插件即全部停用;`/context-graph off` 只停用当前对话。
25
+ 2. **没有原文不写入。** 主题只和它来源的原始消息一起保存。要点是指针,不是记录。
26
+ 3. **只组织,不合并。** 每个对话的图谱留在自己的文件夹里,带自己的日期。编号带对话号(`c3n12`),每个主题都能追溯到来源对话。
27
+ 4. **时间是第一过滤条件。**
28
+ 5. **只在末尾追加**,保住服务商的前缀缓存。隐藏或折叠旧轮次不是本插件的工作。
14
29
 
15
30
  ## 命令
16
31
 
17
- 在对话中输入(菜单弹出时先选 `context-graph`,再输入后面的词):
32
+ 输入 `/context-graph`,在菜单里选中后再输入后面的词:
33
+
34
+ 结果显示在 dsh 自带的命令卡片里:第一行是摘要,展开看详情。不带词等于 `stats`。
35
+
36
+ **`on` — 恢复本对话的记忆。** 记忆默认已开启;`on` 用于撤销之前的 `off`,并立即索引一次;之后每 4 轮人类发言再索引一次(每次一个小型模型调用,默认用本对话的模型)。在 `.context-graph/chats/<对话>/` 下建立图谱、原文和 `meta.json`(标题、日期、标记)。此后你在本对话发的每条消息都会去匹配工作区里其他已共享的对话;开启后的第一条消息还会附上这些对话的列表。
37
+ 卡片:`Memory on · 7 topics in this chat · 2 shared chats to draw on`
38
+
39
+ **`off` — 只关闭本对话的记忆。** 要在所有对话里关闭,请在插件页关闭本插件。 停止索引,不再往请求里加任何内容。图谱文件保留,之后 `on` 可以接着用。若本对话已共享,其他对话仍能看到它。
40
+
41
+ **`share` / `unshare` — 共享或设为私有。** 每个对话默认共享;`unshare` 让本对话私有,`share` 撤销私有。共享只是给本对话打一个标记,其他开了记忆的对话就能匹配和取回它的主题。不复制、不合并:图谱留在自己的文件夹,编号带对话号(`c3n12`),每个命中都能追溯来源。`unshare` 立刻恢复私有。尚未索引的对话可以共享,但在索引之前没有内容。
18
42
 
19
- - `/context-graph`:状态,包括主题数、待索引轮数、是否有新版本。
20
- - `/context-graph build`:立即索引当前对话。
21
- - `/context-graph fold`:立即索引并折叠旧轮次。
22
- - `/context-graph find 关键词`:查找相关主题。
43
+ **`stats` — 当前状态(默认)。** 第一行:记忆开/关、本对话主题数、共享/私有、可见的共享对话数、待索引轮数,以及有新版本时的 `update available`。正文:版本、记忆文件夹,以及应用启动以来的计数:索引次数与 token、附加块数量与大小、recall 次数、主对话输入的未缓存/缓存读/缓存写与缓存命中率。命中率高,说明记忆在省钱而不是花钱。
44
+
45
+ **`build` — 立即索引。** 不等下一个 4 轮节点,适合在切换对话前运行。需要记忆已开启。模型输出无法解析时,原始输出保存到该对话文件夹的 `last-builder-output.txt`,卡片说明原因。
46
+
47
+ **`map` — 工作区的全部对话。** 最新在前:对话编号、开始日期、标题、主题数和标记(`this chat`、`memory on`、`shared`/`private`),下面列出各自连接最多的主题及编号。这是图谱的文字版;可视化页面在计划中。
48
+
49
+ **`find 关键词` — 在已共享对话里查找。** 用的就是插件匹配你消息时的同一套规则,可以看到模型会被展示什么。时间词会缩小范围:`find 524 超时 上周` 先搜上周活跃的对话。只搜其他对话,本对话自己的主题已在上下文里,不重复。
50
+
51
+ ### 取回编号
52
+
53
+ | 编号 | 返回 |
54
+ |---|---|
55
+ | `c3n12` | 对话 3 的主题 12:名称、要点、原始消息原文、相邻主题 |
56
+ | `c3` | 对话 3:标题、日期、按连接数排序的主题 |
57
+ | `2026-11-01` | 当天活跃的全部共享对话,各自那天的主题在前 |
58
+ | `t7` | 当前对话第 7 轮的原文,含工具调用与结果 |
59
+
60
+ ### 时间词
61
+
62
+ `昨天`/`yesterday`、`前天`、`3天前`、`上周`/`本周`、`上个月`/`本月`、`2026-11-01`、`11月1日`。先搜那段时间活跃的对话,再搜那段时间更新的主题,最后才搜全部;都没有时列出那段时间的对话。
23
63
 
24
64
  ## 安装与更新
25
65
 
@@ -27,12 +67,18 @@ DeepSeek Harness 插件:把过往对话记成一张小型主题图谱,并把
27
67
 
28
68
  有新版本时,你的下一次回复末尾会提示一次,`/context-graph` 的第一行也会显示。更新方法:打开本插件 → 卸载 → 添加插件 `dsh-context-graph@新版本号` → 重启。务必写明版本号:dsh 的 pnpm 默认会暂缓刚发布的版本。
29
69
 
30
- ## 关于费用
31
-
32
- DeepSeek 对重复发送的已缓存输入只收约 1/30 的价格,而每次折叠都会让缓存重新开始一次。所以折叠只在旧内容很大时、并且目录不到原内容一半时才发生。短对话里它什么都不做。最大的收益来自新对话:不用重复解释,图谱已经记得之前的决定。
70
+ ## 文件
33
71
 
34
- ## 设置
72
+ ```
73
+ .context-graph/chats/<对话>/meta.json 编号、标题、开始/最近时间、轮数;执行 off / unshare 后才有 memoryOff / private
74
+ .context-graph/chats/<对话>/graph.json 主题与链接,每个主题带时间
75
+ .context-graph/chats/<对话>/src/<id>.md 每个主题背后的原始消息
76
+ ```
35
77
 
36
- 默认值见 [cordis.patch.yml](cordis.patch.yml)。如果你的对话模型是"思考型"模型(例如 Qwen3)而且较慢,可以用 `provider` 和 `model` 让索引改用更快的模型。
78
+ ## 已知限制
37
79
 
38
- 英文完整说明见 [README.md](README.md)。
80
+ - 重启后,续聊的第一次索引会重读整个对话(编号复用,不会重复)。
81
+ - 两个代理同时写同一个对话的图谱:后写的覆盖先写的。
82
+ - 子代理会话不索引,也不附加记忆。
83
+ - 对话标题暂用第一条消息的缩写。
84
+ - 侧边栏的可视化图谱页面尚未实现,`/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 # nodes shown per human turn
11
- inlineMaxChars: 1200 # one dominant hit this short is shown verbatim, no recall needed
12
- surfaceMaxNodes: 40 # god nodes listed at the start of a session
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 # shared chats listed on the first message of each chat
13
+ builderMaxTokens: 8192 # thinking models spend part of this on reasoning
14
+ provider: '' # empty: reuse the conversation's routed provider/model
15
+ model: ''