dsh-code-index 0.5.0 → 0.7.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/CHANGELOG.md +83 -0
- package/LICENSE +0 -0
- package/README.md +46 -1
- package/README.zh.md +27 -2
- package/cordis.patch.yml +0 -0
- package/dist/client.js +12 -3
- package/dist/client.js.map +1 -1
- package/dist/index.js +2343 -194
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/scripts/fix-wsl-links.mjs +0 -0
- package/scripts/release-smoke.mjs +177 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-code-index",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Structural context engine for DSH — tree-sitter symbol index, ranked search, repo map, call graph, and change-aware context.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
20
|
"scripts",
|
|
21
|
-
"cordis.patch.yml"
|
|
21
|
+
"cordis.patch.yml",
|
|
22
|
+
"CHANGELOG.md"
|
|
22
23
|
],
|
|
23
24
|
"scripts": {
|
|
24
25
|
"build": "tsup && tsup --config tsup.client.config.ts",
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"dev:client": "tsup --config tsup.client.config.ts --watch",
|
|
27
28
|
"test": "vitest run",
|
|
28
29
|
"typecheck": "tsc --noEmit",
|
|
30
|
+
"release:smoke": "node scripts/release-smoke.mjs",
|
|
29
31
|
"fix:wsl-links": "node scripts/fix-wsl-links.mjs",
|
|
30
32
|
"prepare": "tsup && tsup --config tsup.client.config.ts",
|
|
31
33
|
"prepublishOnly": "tsup && tsup --config tsup.client.config.ts"
|
|
File without changes
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
7
|
+
|
|
8
|
+
const root = path.resolve(fileURLToPath(new URL('..', import.meta.url)))
|
|
9
|
+
const packageJson = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
10
|
+
const npm = 'npm'
|
|
11
|
+
|
|
12
|
+
function shellQuote(value) {
|
|
13
|
+
return /[\s"]/.test(value) ? `"${value.replace(/"/g, '\\"')}"` : value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function run(command, args, cwd) {
|
|
17
|
+
const invocation = [command, ...args].map(shellQuote).join(' ')
|
|
18
|
+
const commandArgs = process.platform === 'win32'
|
|
19
|
+
? ['/d', '/s', '/c', invocation]
|
|
20
|
+
: args
|
|
21
|
+
const executable = process.platform === 'win32' ? process.env.ComSpec ?? 'cmd.exe' : command
|
|
22
|
+
const executableArgs = process.platform === 'win32' ? commandArgs : args
|
|
23
|
+
return execFileSync(executable, executableArgs, {
|
|
24
|
+
cwd,
|
|
25
|
+
encoding: 'utf8',
|
|
26
|
+
stdio: ['ignore', 'pipe', 'inherit'],
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function parseJsonArrayOutput(output, command) {
|
|
31
|
+
const text = output.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, '')
|
|
32
|
+
for (let start = 0; start < text.length; start += 1) {
|
|
33
|
+
if (text[start] !== '[') continue
|
|
34
|
+
let depth = 0
|
|
35
|
+
let inString = false
|
|
36
|
+
let escaped = false
|
|
37
|
+
for (let index = start; index < text.length; index += 1) {
|
|
38
|
+
const char = text[index]
|
|
39
|
+
if (inString) {
|
|
40
|
+
if (escaped) escaped = false
|
|
41
|
+
else if (char === '\\') escaped = true
|
|
42
|
+
else if (char === '"') inString = false
|
|
43
|
+
continue
|
|
44
|
+
}
|
|
45
|
+
if (char === '"') {
|
|
46
|
+
inString = true
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
if (char === '[') depth += 1
|
|
50
|
+
else if (char === ']') {
|
|
51
|
+
depth -= 1
|
|
52
|
+
if (depth === 0) {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(text.slice(start, index + 1))
|
|
55
|
+
if (Array.isArray(parsed)) return parsed
|
|
56
|
+
} catch {
|
|
57
|
+
break
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
throw new Error(`${command} did not return a JSON array`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const packed = parseJsonArrayOutput(run(npm, ['pack', '--ignore-scripts', '--json'], root), 'npm pack')
|
|
67
|
+
assert.equal(packed.length, 1, 'npm pack must produce exactly one artifact')
|
|
68
|
+
const tarball = path.resolve(root, packed[0].filename)
|
|
69
|
+
const listed = new Set(packed[0].files.map((file) => file.path))
|
|
70
|
+
const expectedFiles = [
|
|
71
|
+
'package.json',
|
|
72
|
+
'README.md',
|
|
73
|
+
'README.zh.md',
|
|
74
|
+
'CHANGELOG.md',
|
|
75
|
+
'LICENSE',
|
|
76
|
+
'cordis.patch.yml',
|
|
77
|
+
'dist/index.js',
|
|
78
|
+
'dist/client.js',
|
|
79
|
+
'scripts/fix-wsl-links.mjs',
|
|
80
|
+
'scripts/release-smoke.mjs',
|
|
81
|
+
]
|
|
82
|
+
for (const file of expectedFiles) assert.ok(listed.has(file), `tarball is missing ${file}`)
|
|
83
|
+
|
|
84
|
+
const smokeDir = mkdtempSync(path.join(os.tmpdir(), 'dsh-code-index-release-'))
|
|
85
|
+
try {
|
|
86
|
+
run(npm, ['init', '--yes'], smokeDir)
|
|
87
|
+
run(npm, ['install', '--ignore-scripts', '--no-save', tarball], smokeDir)
|
|
88
|
+
|
|
89
|
+
const installedPackage = JSON.parse(
|
|
90
|
+
readFileSync(path.join(smokeDir, 'node_modules', packageJson.name, 'package.json'), 'utf8'),
|
|
91
|
+
)
|
|
92
|
+
assert.equal(installedPackage.version, packageJson.version)
|
|
93
|
+
assert.equal(installedPackage.main, './dist/index.js')
|
|
94
|
+
assert.equal(installedPackage.exports['.'].default, './dist/index.js')
|
|
95
|
+
assert.match(installedPackage.engines.node, />=22/)
|
|
96
|
+
assert.equal(installedPackage.license, 'MIT')
|
|
97
|
+
|
|
98
|
+
const plugin = await import(
|
|
99
|
+
pathToFileURL(path.join(smokeDir, 'node_modules', packageJson.name, 'dist', 'index.js')).href,
|
|
100
|
+
)
|
|
101
|
+
const registered = []
|
|
102
|
+
const disposers = []
|
|
103
|
+
const ctx = {
|
|
104
|
+
effect(effect) {
|
|
105
|
+
const disposer = effect()
|
|
106
|
+
if (typeof disposer === 'function') disposers.push(disposer)
|
|
107
|
+
},
|
|
108
|
+
tools: {
|
|
109
|
+
register(tool) {
|
|
110
|
+
registered.push(tool.name)
|
|
111
|
+
return () => {}
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
systemPrompt: { section: () => () => {} },
|
|
115
|
+
}
|
|
116
|
+
plugin.apply(ctx, { autoInject: false, codeHealth: true })
|
|
117
|
+
assert.deepEqual(registered, [
|
|
118
|
+
'code_index',
|
|
119
|
+
'code_symbols',
|
|
120
|
+
'code_search',
|
|
121
|
+
'code_map',
|
|
122
|
+
'code_refs',
|
|
123
|
+
'code_change_context',
|
|
124
|
+
'code_context',
|
|
125
|
+
'code_health',
|
|
126
|
+
])
|
|
127
|
+
|
|
128
|
+
const exec = { agent: { session: { header: { cwd: root } } } }
|
|
129
|
+
const tools = new Map(plugin.tools.map((tool) => [tool.name, tool]))
|
|
130
|
+
const invoke = (name, args) => tools.get(name).execute(args, exec)
|
|
131
|
+
const status = await invoke('code_index', { action: 'build', repoRoot: root })
|
|
132
|
+
assert.match(status, /files indexed:/)
|
|
133
|
+
assert.ok(Array.isArray(await invoke('code_symbols', { limit: 2, repoRoot: root })))
|
|
134
|
+
assert.ok(Array.isArray(await invoke('code_search', { query: 'buildIndex', repoRoot: root })))
|
|
135
|
+
assert.match(await invoke('code_map', { repoRoot: root }), /repo map|no indexable symbols/)
|
|
136
|
+
assert.match(await invoke('code_refs', { symbol: 'buildIndex', repoRoot: root }), /definitions:|no definition/)
|
|
137
|
+
assert.match(
|
|
138
|
+
await invoke('code_change_context', { files: ['src/index.ts'], repoRoot: root }),
|
|
139
|
+
/CHANGED:/,
|
|
140
|
+
)
|
|
141
|
+
assert.match(
|
|
142
|
+
await invoke('code_context', {
|
|
143
|
+
task: 'How does plugin loading work?',
|
|
144
|
+
repoRoot: root,
|
|
145
|
+
budgetChars: 5_000,
|
|
146
|
+
}),
|
|
147
|
+
/Task context|Primary symbols:/,
|
|
148
|
+
)
|
|
149
|
+
assert.match(await invoke('code_health', { repoRoot: root }), /repo health/)
|
|
150
|
+
|
|
151
|
+
for (const dispose of disposers.reverse()) dispose()
|
|
152
|
+
|
|
153
|
+
const compactRegistered = []
|
|
154
|
+
const compactDisposers = []
|
|
155
|
+
plugin.apply(
|
|
156
|
+
{
|
|
157
|
+
effect(effect) {
|
|
158
|
+
const disposer = effect()
|
|
159
|
+
if (typeof disposer === 'function') compactDisposers.push(disposer)
|
|
160
|
+
},
|
|
161
|
+
tools: {
|
|
162
|
+
register(tool) {
|
|
163
|
+
compactRegistered.push(tool.name)
|
|
164
|
+
return () => {}
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
systemPrompt: { section: () => () => {} },
|
|
168
|
+
},
|
|
169
|
+
{ autoInject: false, codeHealth: true, toolSurface: 'compact' },
|
|
170
|
+
)
|
|
171
|
+
assert.deepEqual(compactRegistered, ['code_index', 'code_context', 'code_health'])
|
|
172
|
+
for (const dispose of compactDisposers.reverse()) dispose()
|
|
173
|
+
console.log(`release smoke passed for ${packageJson.name}@${packageJson.version}`)
|
|
174
|
+
} finally {
|
|
175
|
+
rmSync(smokeDir, { recursive: true, force: true })
|
|
176
|
+
rmSync(tarball, { force: true })
|
|
177
|
+
}
|