dsh-context-graph 0.2.3 → 0.3.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 +14 -2
- package/README.zh.md +38 -0
- package/icon.svg +15 -0
- package/index.js +8 -5
- package/lib/client.js +118 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +7 -0
- package/package.json +16 -2
package/README.md
CHANGED
|
@@ -12,8 +12,16 @@ turn (t1, t2, ...). The model follows that table to the exact part it needs with
|
|
|
12
12
|
or `recall("n12")`. Your newest turns stay word for word. Nothing is deleted: the full turns stay
|
|
13
13
|
in the session log and in the chat window.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
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).
|
|
17
25
|
|
|
18
26
|
## What it does
|
|
19
27
|
|
|
@@ -99,6 +107,10 @@ Defaults live in [cordis.patch.yml](cordis.patch.yml). A patch replaces the row'
|
|
|
99
107
|
index.js dsh plugin: builder, matcher, recall tool, meter, /context-graph command
|
|
100
108
|
graph.js pure core: tokenize, match, merge, render, builder prompt and parser
|
|
101
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
|
|
102
114
|
cordis.patch.yml mounts the plugin at the profile root with default config
|
|
103
115
|
test/ node --test; plugin.test.js needs DSH_NODE_MODULES (see below)
|
|
104
116
|
docs/ design
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# 上下文图谱(dsh-context-graph)
|
|
2
|
+
|
|
3
|
+
DeepSeek Harness 插件:把过往对话记成一张小型主题图谱,并把长对话的旧轮次折叠成目录,让每次请求少发送输入 token。需要细节时,模型按目录找到原文。
|
|
4
|
+
|
|
5
|
+
## 它做什么
|
|
6
|
+
|
|
7
|
+
| 时机 | 发生了什么 |
|
|
8
|
+
|---|---|
|
|
9
|
+
| 每 4 轮人类发言 | 回合结束后,用一次小型模型调用把新内容整理进 `.context-graph/graph.json`,并原样保存被引用的消息。不会拖慢回复。 |
|
|
10
|
+
| 新对话的第一条消息 | 附上之前对话中最重要的主题(编号、名称、一句话要点),最多 40 条。 |
|
|
11
|
+
| 每条人类消息 | 按词语重合匹配图谱(不调用模型),把最多 5 个相关主题附在消息末尾。 |
|
|
12
|
+
| 对话旧内容每次请求超过约 24k token | 在下一轮开始时,把旧轮次替换为一份目录:主题列表加每轮一句话。最近 2 轮保持原样。原文不删除,聊天窗口照常显示。 |
|
|
13
|
+
| 模型调用 `recall` | `n12`:返回该主题的原文和相邻主题。`t7`:原样返回被折叠的第 7 轮,包括工具输出。 |
|
|
14
|
+
|
|
15
|
+
## 命令
|
|
16
|
+
|
|
17
|
+
在对话中输入(菜单弹出时先选 `context-graph`,再输入后面的词):
|
|
18
|
+
|
|
19
|
+
- `/context-graph`:状态,包括主题数、待索引轮数、是否有新版本。
|
|
20
|
+
- `/context-graph build`:立即索引当前对话。
|
|
21
|
+
- `/context-graph fold`:立即索引并折叠旧轮次。
|
|
22
|
+
- `/context-graph find 关键词`:查找相关主题。
|
|
23
|
+
|
|
24
|
+
## 安装与更新
|
|
25
|
+
|
|
26
|
+
插件 → 添加插件 → 官方 npm 源 → 输入 `dsh-context-graph`,安装后完全重启应用。
|
|
27
|
+
|
|
28
|
+
有新版本时,你的下一次回复末尾会提示一次,`/context-graph` 的第一行也会显示。更新方法:打开本插件 → 卸载 → 添加插件 `dsh-context-graph@新版本号` → 重启。务必写明版本号:dsh 的 pnpm 默认会暂缓刚发布的版本。
|
|
29
|
+
|
|
30
|
+
## 关于费用
|
|
31
|
+
|
|
32
|
+
DeepSeek 对重复发送的已缓存输入只收约 1/30 的价格,而每次折叠都会让缓存重新开始一次。所以折叠只在旧内容很大时、并且目录不到原内容一半时才发生。短对话里它什么都不做。最大的收益来自新对话:不用重复解释,图谱已经记得之前的决定。
|
|
33
|
+
|
|
34
|
+
## 设置
|
|
35
|
+
|
|
36
|
+
默认值见 [cordis.patch.yml](cordis.patch.yml)。如果你的对话模型是"思考型"模型(例如 Qwen3)而且较慢,可以用 `provider` 和 `model` 让索引改用更快的模型。
|
|
37
|
+
|
|
38
|
+
英文完整说明见 [README.md](README.md)。
|
package/icon.svg
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g transform="translate(1.5 1.5) scale(0.9166666667)">
|
|
3
|
+
<rect x="6" y="6" width="24" height="24" rx="7" fill="url(#a)" fill-opacity="0.8" />
|
|
4
|
+
<path d="M13 13.5L23 15.5M13 13.5L16 23M23 15.5L16 23" stroke="#FFFFFF" stroke-width="1.6" stroke-linecap="round" />
|
|
5
|
+
<circle cx="13" cy="13.5" r="2.6" fill="#FFFFFF" />
|
|
6
|
+
<circle cx="23" cy="15.5" r="2.2" fill="#FFFFFF" />
|
|
7
|
+
<circle cx="16" cy="23" r="2.2" fill="#FFFFFF" />
|
|
8
|
+
</g>
|
|
9
|
+
<defs>
|
|
10
|
+
<linearGradient id="a" x1="18" y1="6" x2="18" y2="30" gradientUnits="userSpaceOnUse">
|
|
11
|
+
<stop stop-color="#7AC2FF" />
|
|
12
|
+
<stop offset="1" stop-color="#4A65E8" />
|
|
13
|
+
</linearGradient>
|
|
14
|
+
</defs>
|
|
15
|
+
</svg>
|
package/index.js
CHANGED
|
@@ -382,17 +382,19 @@ export function apply(ctx, config = {}) {
|
|
|
382
382
|
return fold(agent, { force: true })
|
|
383
383
|
})
|
|
384
384
|
if (result.status !== 'folded') return { kind: 'error', text: `Not folded: ${result.reason}` }
|
|
385
|
-
return { kind: 'success', text: `Folded
|
|
385
|
+
return { kind: 'success', text: `Folded t1-t${result.turns} · ~${result.before} → ~${result.after} tokens per request
|
|
386
386
|
}
|
|
387
387
|
if (sub === 'build') {
|
|
388
388
|
const result = await agent.runMaintenance(() => build(agent, { force: true }))
|
|
389
389
|
if (result.status !== 'built') return { kind: 'error', text: `Build ${result.status}: ${result.reason ?? ''}`.trim() }
|
|
390
|
-
return { kind: 'success', text:
|
|
390
|
+
return { kind: 'success', text: `${result.nodes} topics indexed (${result.newNodes} new) · graph has ${result.totalNodes} topics\nLinks: ${result.edges}\nFolder: ${result.dir}` }
|
|
391
391
|
}
|
|
392
392
|
const graph = await getGraph(dirFor(agent))
|
|
393
393
|
if (sub === 'find') {
|
|
394
394
|
const hits = matchNodes(graph, rest.join(' '), { max: cfg.maxHits })
|
|
395
|
-
return { kind: 'success', text:
|
|
395
|
+
if (hits.length === 0) return { kind: 'success', text: 'No matching topics' }
|
|
396
|
+
const lines = hits.map(({ id, node }) => `${id} ${node.label}: ${node.gist}`)
|
|
397
|
+
return { kind: 'success', text: [`${hits.length} matching ${hits.length === 1 ? 'topic' : 'topics'}`, ...lines].join('\n') }
|
|
396
398
|
}
|
|
397
399
|
if (sub !== 'stats') return { kind: 'error', text: 'Usage: /context-graph [stats|build|fold|find <words>]' }
|
|
398
400
|
const m = meter.main
|
|
@@ -403,9 +405,10 @@ export function apply(ctx, config = {}) {
|
|
|
403
405
|
return {
|
|
404
406
|
kind: 'success',
|
|
405
407
|
text: [
|
|
408
|
+
`${Object.keys(graph.nodes).length} topics · ${graph.edges.length} links · ${pending} turns waiting to be indexed${updates.current() ? ' · update available' : ''}`,
|
|
406
409
|
`Version ${version}: ${updates.current() ?? 'no newer version found'}`,
|
|
407
|
-
`Graph: ${
|
|
408
|
-
`This chat
|
|
410
|
+
`Graph folder: ${dirFor(agent)}`,
|
|
411
|
+
`This chat indexes itself every ${cfg.buildEveryTurns} turns; /context-graph build indexes it now.`,
|
|
409
412
|
'Counters below are since the app started:',
|
|
410
413
|
`Builds: ${meter.builds}; builder tokens in/out: ${meter.builder.input + meter.builder.cacheRead + meter.builder.cacheWrite}/${meter.builder.output}`,
|
|
411
414
|
`Folds: ${meter.folds}; ~${meter.foldSaved} input tokens removed from every later request`,
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Chat card for `/context-graph`, hand-written in dsh's client-bundle format (no build step).
|
|
2
|
+
// The shell loads this file as a plain script; `require` reaches only the shell's shared modules.
|
|
3
|
+
// Layout follows dsh's own command card: DisclosureRow with a 14px icon, a title, a one-line
|
|
4
|
+
// summary, and the remaining lines as an expandable body.
|
|
5
|
+
window.__ModuleLoader__.load({
|
|
6
|
+
id: 'dsh-context-graph',
|
|
7
|
+
factory: (require) => {
|
|
8
|
+
var module = { exports: {} }
|
|
9
|
+
var exports = module.exports
|
|
10
|
+
const { useState } = require('react')
|
|
11
|
+
const { jsx, jsxs } = require('react/jsx-runtime')
|
|
12
|
+
const { DisclosureRow } = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
13
|
+
|
|
14
|
+
const NAMESPACE = 'dsh-context-graph'
|
|
15
|
+
const en = {
|
|
16
|
+
stats: 'Context graph',
|
|
17
|
+
build: 'Index this chat',
|
|
18
|
+
fold: 'Fold old turns',
|
|
19
|
+
find: 'Find topics',
|
|
20
|
+
running: 'Working…',
|
|
21
|
+
failed: 'Failed'
|
|
22
|
+
}
|
|
23
|
+
const zh = {
|
|
24
|
+
stats: '上下文图谱',
|
|
25
|
+
build: '索引当前对话',
|
|
26
|
+
fold: '折叠旧轮次',
|
|
27
|
+
find: '查找主题',
|
|
28
|
+
running: '处理中…',
|
|
29
|
+
failed: '失败'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const CSS = [
|
|
33
|
+
'.dshcg-root{margin:2px 0}',
|
|
34
|
+
'.dshcg-summary{margin-left:8px;font-size:13px;opacity:.72}',
|
|
35
|
+
'.dshcg-summary[data-error]{color:var(--color-text-danger,#d64545);opacity:1}',
|
|
36
|
+
'.dshcg-body{padding:6px 0 6px 24px;font-size:13px;line-height:1.6;white-space:pre-wrap;word-break:break-word}'
|
|
37
|
+
].join('')
|
|
38
|
+
if (typeof document !== 'undefined' && document.querySelector('style[data-plugin-css="dsh-context-graph"]') === null) {
|
|
39
|
+
const tag = document.createElement('style')
|
|
40
|
+
tag.dataset.pluginCss = NAMESPACE
|
|
41
|
+
tag.textContent = CSS
|
|
42
|
+
document.head.appendChild(tag)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Three linked nodes: the same mark as the plugin icon, drawn in the current text colour.
|
|
46
|
+
const ICON = jsxs('svg', {
|
|
47
|
+
width: 14,
|
|
48
|
+
height: 14,
|
|
49
|
+
viewBox: '0 0 24 24',
|
|
50
|
+
fill: 'none',
|
|
51
|
+
stroke: 'currentColor',
|
|
52
|
+
strokeWidth: 2,
|
|
53
|
+
strokeLinecap: 'round',
|
|
54
|
+
'aria-hidden': true,
|
|
55
|
+
children: [
|
|
56
|
+
jsx('path', { d: 'M7 7l10 3M7 7l3 10M17 10l-7 7' }),
|
|
57
|
+
jsx('circle', { cx: 7, cy: 7, r: 2.5, fill: 'currentColor' }),
|
|
58
|
+
jsx('circle', { cx: 17, cy: 10, r: 2, fill: 'currentColor' }),
|
|
59
|
+
jsx('circle', { cx: 10, cy: 17, r: 2, fill: 'currentColor' })
|
|
60
|
+
]
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const SUBCOMMANDS = ['stats', 'build', 'fold', 'find']
|
|
64
|
+
|
|
65
|
+
/** Title key from the typed arguments (`/context-graph fold` -> fold); no argument means stats. */
|
|
66
|
+
function subcommandOf(args) {
|
|
67
|
+
const first = String(args ?? '').trim().split(/\s+/)[0] || 'stats'
|
|
68
|
+
return SUBCOMMANDS.includes(first) ? first : 'stats'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Host text: line 1 is the summary, later lines are the details shown when expanded. */
|
|
72
|
+
function splitText(text) {
|
|
73
|
+
const lines = String(text ?? '').split('\n')
|
|
74
|
+
return { summary: lines[0] ?? '', body: lines.slice(1).join('\n').trim() }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function ContextGraphCard({ node, t }) {
|
|
78
|
+
const [open, setOpen] = useState(false)
|
|
79
|
+
const outcome = node.outcome
|
|
80
|
+
const running = outcome === null
|
|
81
|
+
const failed = outcome?.kind === 'error'
|
|
82
|
+
const { summary, body } = splitText(outcome?.text)
|
|
83
|
+
const shown = running ? t('running') : summary || (failed ? t('failed') : '')
|
|
84
|
+
const hasBody = !running && body.length > 0
|
|
85
|
+
return jsx('div', {
|
|
86
|
+
className: 'dshcg-root',
|
|
87
|
+
'data-state': running ? 'running' : failed ? 'error' : 'ok',
|
|
88
|
+
children: jsx(DisclosureRow, {
|
|
89
|
+
icon: ICON,
|
|
90
|
+
title: t(subcommandOf(node.args)),
|
|
91
|
+
running,
|
|
92
|
+
open: open && hasBody,
|
|
93
|
+
expandable: hasBody,
|
|
94
|
+
expandOnRowClick: true,
|
|
95
|
+
keepContentWhenOpen: true,
|
|
96
|
+
onToggle: () => setOpen((value) => !value),
|
|
97
|
+
collapsedContent: shown ? jsx('span', { className: 'dshcg-summary', 'data-error': failed || undefined, children: shown }) : undefined,
|
|
98
|
+
children: open && hasBody ? jsx('div', { className: 'dshcg-body', children: body }) : undefined
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const inject = ['slots', 'locale']
|
|
104
|
+
function apply(ctx) {
|
|
105
|
+
ctx.effect(() => ctx.locale.register(NAMESPACE, { en, zh }), 'dsh-context-graph: dictionaries')
|
|
106
|
+
ctx.slots.inject('conversation.chat.commandview', () =>
|
|
107
|
+
ctx.slots.register({ name: 'conversation.chat.commandview', key: 'context-graph', locale: NAMESPACE }, ContextGraphCard)
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.inject = inject
|
|
112
|
+
exports.apply = apply
|
|
113
|
+
exports.ContextGraphCard = ContextGraphCard
|
|
114
|
+
exports.subcommandOf = subcommandOf
|
|
115
|
+
exports.splitText = splitText
|
|
116
|
+
return module.exports
|
|
117
|
+
}
|
|
118
|
+
})
|
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-context-graph",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "DeepSeek Harness plugin: remembers past conversations as a small graph and folds old turns of a long chat into a table of contents, so fewer input tokens are sent; exact text is recalled on demand",
|
|
5
|
+
"icon": "./icon.svg",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "index.js",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": "./index.js",
|
|
10
|
+
"./client": "./lib/client.js",
|
|
9
11
|
"./graph": "./graph.js",
|
|
12
|
+
"./locale/*.json": "./locale/*.json",
|
|
10
13
|
"./package.json": "./package.json"
|
|
11
14
|
},
|
|
12
15
|
"files": [
|
|
@@ -14,12 +17,16 @@
|
|
|
14
17
|
"graph.js",
|
|
15
18
|
"store.js",
|
|
16
19
|
"update.js",
|
|
20
|
+
"lib/client.js",
|
|
21
|
+
"locale",
|
|
22
|
+
"icon.svg",
|
|
17
23
|
"cordis.patch.yml",
|
|
18
24
|
"README.md",
|
|
25
|
+
"README.zh.md",
|
|
19
26
|
"LICENSE"
|
|
20
27
|
],
|
|
21
28
|
"scripts": {
|
|
22
|
-
"test": "node --import ./test/resolve-dsh.mjs --test test/graph.test.js test/fold.test.js test/update.test.js test/plugin.test.js"
|
|
29
|
+
"test": "node --import ./test/resolve-dsh.mjs --test test/graph.test.js test/fold.test.js test/update.test.js test/client.test.js test/plugin.test.js"
|
|
23
30
|
},
|
|
24
31
|
"keywords": [
|
|
25
32
|
"dsh-plugin",
|
|
@@ -49,6 +56,13 @@
|
|
|
49
56
|
"dsh": {
|
|
50
57
|
"bundle": {
|
|
51
58
|
"patch": "./cordis.patch.yml"
|
|
59
|
+
},
|
|
60
|
+
"client": {
|
|
61
|
+
"platform": "web",
|
|
62
|
+
"inject": [
|
|
63
|
+
"@deepseek-ai/dsh-client-ui-renderer",
|
|
64
|
+
"@deepseek-ai/dsh-client-locale"
|
|
65
|
+
]
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
68
|
}
|