dsh-context-graph 0.2.1 → 0.2.2
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 +1 -1
- package/cordis.patch.yml +1 -1
- package/graph.js +41 -11
- package/index.js +16 -4
- package/package.json +53 -53
package/README.md
CHANGED
|
@@ -85,7 +85,7 @@ Defaults live in [cordis.patch.yml](cordis.patch.yml). A patch replaces the row'
|
|
|
85
85
|
| `maxHits` | `5` | Nodes shown per human turn |
|
|
86
86
|
| `inlineMaxChars` | `1200` | A single dominant hit this short is shown verbatim |
|
|
87
87
|
| `surfaceMaxNodes` | `40` | Nodes listed at the start of a session |
|
|
88
|
-
| `builderMaxTokens` | `
|
|
88
|
+
| `builderMaxTokens` | `8192` | Output cap for the indexing call; thinking models spend part of it reasoning |
|
|
89
89
|
| `provider`, `model` | `''` | Empty: reuse the conversation's routed provider and model |
|
|
90
90
|
| `fold` | `true` | Fold old turns of the current chat into a table of contents |
|
|
91
91
|
| `foldAtTokens` | `24000` | Fold once the foldable part costs this much per request |
|
package/cordis.patch.yml
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
maxHits: 5 # nodes shown per human turn
|
|
11
11
|
inlineMaxChars: 1200 # one dominant hit this short is shown verbatim, no recall needed
|
|
12
12
|
surfaceMaxNodes: 40 # god nodes listed at the start of a session
|
|
13
|
-
builderMaxTokens:
|
|
13
|
+
builderMaxTokens: 8192 # thinking models spend part of this on reasoning
|
|
14
14
|
provider: '' # empty: reuse the conversation's routed provider/model
|
|
15
15
|
model: ''
|
|
16
16
|
fold: true # replace old turns of the current chat with a table of contents
|
package/graph.js
CHANGED
|
@@ -187,18 +187,48 @@ export function builderInstruction(graph) {
|
|
|
187
187
|
].join('\n')
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
/**
|
|
190
|
+
/** Complete top-level `{...}` objects inside the array that opens at `open`; an unfinished last one is dropped. */
|
|
191
|
+
function objectsInArray(text, open) {
|
|
192
|
+
const out = []
|
|
193
|
+
let depth = 0
|
|
194
|
+
let start = -1
|
|
195
|
+
let inString = false
|
|
196
|
+
for (let i = open + 1; i < text.length; i++) {
|
|
197
|
+
const ch = text[i]
|
|
198
|
+
if (inString) {
|
|
199
|
+
if (ch === '\\') i++
|
|
200
|
+
else if (ch === '"') inString = false
|
|
201
|
+
continue
|
|
202
|
+
}
|
|
203
|
+
if (ch === '"') inString = true
|
|
204
|
+
else if (ch === '{' || ch === '[') { if (depth++ === 0 && ch === '{') start = i }
|
|
205
|
+
else if (ch === '}' || ch === ']') {
|
|
206
|
+
if (depth === 0) break
|
|
207
|
+
if (--depth === 0 && ch === '}' && start >= 0) { out.push(text.slice(start, i + 1)); start = -1 }
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return out
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Tolerant extraction of the builder's JSON. Handles code fences, prose around it, `<think>` blocks,
|
|
215
|
+
* trailing commas, and output cut off mid-way (every complete node object is kept).
|
|
216
|
+
* `undefined` when there is no `"nodes"` array at all.
|
|
217
|
+
*/
|
|
191
218
|
export function parseBuilderOutput(text) {
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
if (
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
const edges =
|
|
201
|
-
return {
|
|
219
|
+
const clean = String(text ?? '').replace(/<think>[\s\S]*?(?:<\/think>|$)/g, '')
|
|
220
|
+
const at = clean.search(/"nodes"\s*:\s*\[/)
|
|
221
|
+
if (at < 0) return undefined
|
|
222
|
+
const nodes = []
|
|
223
|
+
for (const raw of objectsInArray(clean, clean.indexOf('[', at))) {
|
|
224
|
+
try { nodes.push(JSON.parse(raw.replace(/,\s*([}\]])/g, '$1'))) } catch { /* skip a malformed node */ }
|
|
225
|
+
}
|
|
226
|
+
const edgesAt = clean.search(/"edges"\s*:/)
|
|
227
|
+
const edges = edgesAt < 0 ? [] : [...clean.slice(edgesAt).matchAll(/\[\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*"([^"]+)"\s*\]/g)].map((m) => [m[1], m[2], m[3]])
|
|
228
|
+
return {
|
|
229
|
+
nodes: nodes.filter((n) => n && typeof n.label === 'string' && n.label.trim() && Array.isArray(n.msgs) && n.msgs.length > 0),
|
|
230
|
+
edges
|
|
231
|
+
}
|
|
202
232
|
}
|
|
203
233
|
|
|
204
234
|
/**
|
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { isAbsolute, join } from 'node:path'
|
|
16
|
-
import { stat } from 'node:fs/promises'
|
|
16
|
+
import { mkdir, stat, writeFile } from 'node:fs/promises'
|
|
17
17
|
|
|
18
18
|
import { BlockAssembler, createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
19
19
|
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
@@ -37,7 +37,7 @@ const DEFAULTS = {
|
|
|
37
37
|
maxHits: 5,
|
|
38
38
|
inlineMaxChars: 1200,
|
|
39
39
|
surfaceMaxNodes: 40,
|
|
40
|
-
builderMaxTokens:
|
|
40
|
+
builderMaxTokens: 8192,
|
|
41
41
|
provider: '',
|
|
42
42
|
model: '',
|
|
43
43
|
fold: true,
|
|
@@ -135,8 +135,20 @@ export function apply(ctx, config = {}) {
|
|
|
135
135
|
})) assembler.push(chunk)
|
|
136
136
|
const finish = assembler.finish
|
|
137
137
|
if (finish?.kind === 'error' || finish?.kind === 'aborted') throw new Error(finish.failure?.message ?? finish.kind)
|
|
138
|
-
const
|
|
139
|
-
|
|
138
|
+
const blocks = assembler.blocks()
|
|
139
|
+
const answer = textOf(blocks)
|
|
140
|
+
// Some thinking models put everything, JSON included, into reasoning blocks.
|
|
141
|
+
const reasoning = blocks.filter((b) => b?.type === 'reasoning').map((b) => b.text).join('\n')
|
|
142
|
+
const delta = parseBuilderOutput(answer) ?? parseBuilderOutput(reasoning)
|
|
143
|
+
if (!delta || (delta.nodes.length === 0 && finish?.kind === 'max-tokens')) {
|
|
144
|
+
const saved = join(dir, 'last-builder-output.txt')
|
|
145
|
+
await mkdir(dir, { recursive: true })
|
|
146
|
+
await writeFile(saved, `finish: ${finish?.kind}\n\n--- answer ---\n${answer}\n\n--- reasoning ---\n${reasoning}\n`, 'utf8')
|
|
147
|
+
const why = finish?.kind === 'max-tokens'
|
|
148
|
+
? `the model ran out of output tokens (builderMaxTokens ${cfg.builderMaxTokens}) before finishing`
|
|
149
|
+
: 'builder output was not the expected JSON'
|
|
150
|
+
return { status: 'failed', reason: `${why}; raw output saved to ${saved}` }
|
|
151
|
+
}
|
|
140
152
|
// Reversibility rule: a node is written only when it cites text we can store verbatim.
|
|
141
153
|
delta.nodes = delta.nodes.filter((n) => n.msgs.some((i) => span.messages[i]))
|
|
142
154
|
const now = new Date().toISOString()
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-context-graph",
|
|
3
|
-
"version": "0.2.
|
|
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
|
-
"type": "module",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": "./index.js",
|
|
9
|
-
"./graph": "./graph.js",
|
|
10
|
-
"./package.json": "./package.json"
|
|
11
|
-
},
|
|
12
|
-
"files": [
|
|
13
|
-
"index.js",
|
|
14
|
-
"graph.js",
|
|
15
|
-
"store.js",
|
|
16
|
-
"cordis.patch.yml",
|
|
17
|
-
"README.md",
|
|
18
|
-
"LICENSE"
|
|
19
|
-
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"test": "node --import ./test/resolve-dsh.mjs --test test/graph.test.js test/fold.test.js test/plugin.test.js"
|
|
22
|
-
},
|
|
23
|
-
"keywords": [
|
|
24
|
-
"dsh-plugin",
|
|
25
|
-
"deepseek-harness",
|
|
26
|
-
"deepseek",
|
|
27
|
-
"memory",
|
|
28
|
-
"context",
|
|
29
|
-
"knowledge-graph"
|
|
30
|
-
],
|
|
31
|
-
"license": "MIT",
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/William20100221/dsh-context-graph.git"
|
|
35
|
-
},
|
|
36
|
-
"homepage": "https://github.com/William20100221/dsh-context-graph#readme",
|
|
37
|
-
"bugs": {
|
|
38
|
-
"url": "https://github.com/William20100221/dsh-context-graph/issues"
|
|
39
|
-
},
|
|
40
|
-
"engines": {
|
|
41
|
-
"dsh": ">=0.2.1-rc.5 <0.3.0",
|
|
42
|
-
"node": ">=20"
|
|
43
|
-
},
|
|
44
|
-
"peerDependencies": {
|
|
45
|
-
"@deepseek-ai/dsh-llm": ">=0.2.1-rc.5 <0.3.0",
|
|
46
|
-
"@deepseek-ai/dsh-tools": ">=0.2.1-rc.5 <0.3.0"
|
|
47
|
-
},
|
|
48
|
-
"dsh": {
|
|
49
|
-
"bundle": {
|
|
50
|
-
"patch": "./cordis.patch.yml"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-context-graph",
|
|
3
|
+
"version": "0.2.2",
|
|
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
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./graph": "./graph.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"index.js",
|
|
14
|
+
"graph.js",
|
|
15
|
+
"store.js",
|
|
16
|
+
"cordis.patch.yml",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --import ./test/resolve-dsh.mjs --test test/graph.test.js test/fold.test.js test/plugin.test.js"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"dsh-plugin",
|
|
25
|
+
"deepseek-harness",
|
|
26
|
+
"deepseek",
|
|
27
|
+
"memory",
|
|
28
|
+
"context",
|
|
29
|
+
"knowledge-graph"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/William20100221/dsh-context-graph.git"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/William20100221/dsh-context-graph#readme",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/William20100221/dsh-context-graph/issues"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"dsh": ">=0.2.1-rc.5 <0.3.0",
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@deepseek-ai/dsh-llm": ">=0.2.1-rc.5 <0.3.0",
|
|
46
|
+
"@deepseek-ai/dsh-tools": ">=0.2.1-rc.5 <0.3.0"
|
|
47
|
+
},
|
|
48
|
+
"dsh": {
|
|
49
|
+
"bundle": {
|
|
50
|
+
"patch": "./cordis.patch.yml"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|