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 CHANGED
@@ -1,132 +1,148 @@
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
- Status: v0.2.0. Installs and loads in the dsh desktop app; folding and indexing are not yet
16
- verified with a live model. 18 tests pass against the published dsh packages.
17
-
18
- ## What it does
19
-
20
- | Moment | What happens | Cost |
21
- |---|---|---|
22
- | 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 |
23
- | 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 |
24
- | 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 |
25
- | 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 |
26
- | Model calls `recall(id)` | `n12`: the topic's verbatim source and neighbours. `t7`: folded turn 7 exactly, including tool calls. | one tool round trip |
27
- | `/context-graph` | `stats`, `build` (index now), `fold` (index and fold now), `find <words>`. | none |
28
-
29
- Design rules, in order of importance:
30
-
31
- 1. **Nothing is written without its source.** A node is stored only together with the verbatim
32
- messages it was drawn from. The gist is a pointer, never the record.
33
- 2. **Fold in batches, not every turn.** DeepSeek bills re-sent cached input at about 1/30 price,
34
- and any fold restarts that cache. So a fold happens only when the old part is large
35
- (24k tokens by default) and the table of contents is under half its size. Between folds the
36
- prefix stays stable and cached. Matcher blocks ride at the end of the newest message.
37
- 3. **Old decisions resolve to new ones.** A `supersedes` edge makes a hit on the old node show
38
- the replacement instead.
39
- 4. **Matching is lexical.** Labels, aliases and gists; English words, identifiers and Chinese
40
- bigrams. The builder is asked to write aliases precisely so this works without embeddings.
41
-
42
- The full design, including what was borrowed from `dsh-plugin-save-token` and why cache
43
- economics make cross-session memory the main win, is in [docs/core-design.md](docs/core-design.md).
44
-
45
- ## Install
46
-
47
- Desktop app: **Plugins → Add plugin**, official npm registry, enter `dsh-context-graph`,
48
- install, then fully restart the app so the `/context-graph` command appears.
49
-
50
- Command line (use the profile your app runs; the desktop app uses `desktop`):
51
-
52
- ```sh
53
- dsh plugin --profile desktop add dsh-context-graph
54
- ```
55
-
56
- **Updates.** dsh 0.2.1 desktop builds have no update check for third-party plugins, so the
57
- plugin checks npm itself once per app start. When a newer version exists, your next chat reply
58
- ends with one line saying so, and `/context-graph stats` shows it on its first line. To update:
59
- Plugins, open dsh-context-graph, **Uninstall**, then **Add plugin** `dsh-context-graph@<new version>`
60
- and restart the app. Name the exact version: dsh's pnpm holds back very new releases otherwise.
61
- Turn the check off with the environment variable `DSH_CONTEXT_GRAPH_NO_UPDATE_CHECK=1`.
62
-
63
- Remove with `dsh plugin --profile desktop remove dsh-context-graph`.
64
-
65
- ## Releasing a new version
66
-
67
- ```sh
68
- npm test
69
- npm version patch
70
- npm publish
71
- git push --follow-tags
72
- ```
73
-
74
- `npm version patch` bumps the version, commits and tags it. `npm publish` needs `npm login`
75
- once. Users then see the new version after pressing Refresh on the Plugins page.
76
-
77
- ## Configuration
78
-
79
- Defaults live in [cordis.patch.yml](cordis.patch.yml). A patch replaces the row's whole
80
- `config`, so restate every key you keep.
81
-
82
- | Key | Default | Meaning |
83
- |---|---|---|
84
- | `dir` | `.context-graph` | Graph folder, relative to the agent workspace or absolute |
85
- | `buildEveryTurns` | `4` | Index after this many new human turns |
86
- | `buildMinChars` | `400` | ...and at least this much new text |
87
- | `maxHits` | `5` | Nodes shown per human turn |
88
- | `inlineMaxChars` | `1200` | A single dominant hit this short is shown verbatim |
89
- | `surfaceMaxNodes` | `40` | Nodes listed at the start of a session |
90
- | `builderMaxTokens` | `8192` | Output cap for the indexing call; thinking models spend part of it reasoning |
91
- | `provider`, `model` | `''` | Empty: reuse the conversation's routed provider and model |
92
- | `fold` | `true` | Fold old turns of the current chat into a table of contents |
93
- | `foldAtTokens` | `24000` | Fold once the foldable part costs this much per request |
94
- | `keepTurns` | `2` | Newest human turns never folded |
95
-
96
- ## Files
97
-
98
- ```
99
- index.js dsh plugin: builder, matcher, recall tool, meter, /context-graph command
100
- graph.js pure core: tokenize, match, merge, render, builder prompt and parser
101
- store.js graph.json and src/<id>.md read/write
102
- cordis.patch.yml mounts the plugin at the profile root with default config
103
- test/ node --test; plugin.test.js needs DSH_NODE_MODULES (see below)
104
- docs/ design
105
- ```
106
-
107
- ## Testing
108
-
109
- Unit tests need nothing:
110
-
111
- ```sh
112
- node --test test/graph.test.js
113
- ```
114
-
115
- The wiring test imports the real dsh packages from an existing dsh install. Point it at that
116
- install's `node_modules`:
117
-
118
- ```sh
119
- DSH_NODE_MODULES=/path/to/dsh/node_modules npm test
120
- ```
121
-
122
- Without the variable it is skipped. Nothing here calls a model.
123
-
124
- ## Known limits
125
-
126
- - Builds are indexed per process; after a restart the first build of a resumed session re-reads
127
- its whole surface. Existing ids are reused, so this costs one larger call, not duplicates.
128
- - Two agents writing the same workspace graph at once: last writer wins.
129
- - Subagent sessions are neither indexed nor given memory blocks.
130
- - Tool outputs are not indexed as topics, but they are folded and `recall("tN")` returns them (each capped at 2000 characters).
131
- - Only indexed turns are folded. After an app restart the index position resets, so the first fold waits for one build.
132
- - A skill list or runtime-context message inside the folded part is copied into the fold message so the model keeps it.
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 # 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 # 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: ''