dsh-skill-eval 0.0.0-stage → 1.20.3
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 +718 -0
- package/LICENSE +21 -0
- package/README.md +207 -2
- package/README.zh.md +164 -0
- package/client.js +2791 -0
- package/cordis.patch.yml +9 -0
- package/docs/ACCEPTANCE.md +71 -0
- package/docs/AUDIT.md +82 -0
- package/docs/CODE-REVIEW.md +49 -0
- package/docs/COMPARISON.md +33 -0
- package/docs/DETAIL.md +468 -0
- package/docs/DEV-RELOAD.md +114 -0
- package/docs/ENTRYPOINTS.md +65 -0
- package/docs/RELEASE.md +44 -0
- package/docs/RRSI-NOTES.md +129 -0
- package/docs/SCENARIOS.md +91 -0
- package/docs/UI-REVIEW.md +115 -0
- package/docs/WORKFLOW.md +108 -0
- package/icon.svg +9 -0
- package/index.js +1173 -0
- package/lib/accept.js +350 -0
- package/lib/advice.js +557 -0
- package/lib/critic.js +101 -0
- package/lib/dev.js +148 -0
- package/lib/history.js +141 -0
- package/lib/html.js +17 -0
- package/lib/inspect.js +142 -0
- package/lib/integrity.js +46 -0
- package/lib/loop.js +195 -0
- package/lib/random.js +29 -0
- package/lib/recorder.js +644 -0
- package/lib/render.js +580 -0
- package/lib/report.js +689 -0
- package/lib/score.js +565 -0
- package/lib/settings.js +415 -0
- package/lib/snapshot.js +250 -0
- package/lib/steps.js +141 -0
- package/lib/store.js +240 -0
- package/lib/validity.js +125 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +96 -4
- package/scripts/accept.mjs +227 -0
- package/scripts/build-client.mjs +59 -0
- package/scripts/build.mjs +81 -0
- package/scripts/doctor.mjs +234 -0
- package/scripts/lib.mjs +87 -0
- package/scripts/verify-live.mjs +178 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Post-restart acceptance for dsh-skill-eval.
|
|
4
|
+
*
|
|
5
|
+
* node scripts/accept.mjs [baseUrl] [--data-dir <dir>]
|
|
6
|
+
*
|
|
7
|
+
* Exit code 0 = every automatic check passed. A non-zero exit prints the stale
|
|
8
|
+
* hint: the running host is still serving an older plugin generation, so quit
|
|
9
|
+
* and reopen DeepSeek Harness.
|
|
10
|
+
*/
|
|
11
|
+
import { readFile, readdir, stat } from 'node:fs/promises'
|
|
12
|
+
import { homedir } from 'node:os'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
import process from 'node:process'
|
|
15
|
+
import { runAcceptance } from '../lib/accept.js'
|
|
16
|
+
import { dashboardBase, expectedVersion, parseCliArgs, resolveBaseUrl } from './lib.mjs'
|
|
17
|
+
|
|
18
|
+
const args = process.argv.slice(2)
|
|
19
|
+
const parsedArgs = parseCliArgs(args)
|
|
20
|
+
const baseArg = parsedArgs.baseArg
|
|
21
|
+
const dataDirOverride = parsedArgs.values['--data-dir'] ? path.resolve(parsedArgs.values['--data-dir']) : null
|
|
22
|
+
const resolved = await resolveBaseUrl(baseArg)
|
|
23
|
+
const baseUrl = resolved.baseUrl
|
|
24
|
+
const manifest = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
|
|
25
|
+
const currentVersion = expectedVersion(manifest.version)
|
|
26
|
+
const version = typeof manifest.version === 'string' ? manifest.version : null
|
|
27
|
+
|
|
28
|
+
async function findDataDir() {
|
|
29
|
+
if (dataDirOverride) return dataDirOverride
|
|
30
|
+
const home = process.env.DSH_HOME || path.join(homedir(), '.dsh')
|
|
31
|
+
const root = path.join(home, 'skill-eval')
|
|
32
|
+
let candidates
|
|
33
|
+
try {
|
|
34
|
+
candidates = await readdir(root)
|
|
35
|
+
} catch {
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
let best = null
|
|
39
|
+
for (const name of candidates) {
|
|
40
|
+
const dir = path.join(root, name)
|
|
41
|
+
try {
|
|
42
|
+
const info = await stat(path.join(dir, 'events.jsonl'))
|
|
43
|
+
if (!best || info.mtimeMs > best.mtimeMs) best = { dir, mtimeMs: info.mtimeMs }
|
|
44
|
+
} catch {
|
|
45
|
+
// no telemetry in this profile yet
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return best ? best.dir : null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function unreachable(url, cause) {
|
|
52
|
+
const error = new Error(
|
|
53
|
+
`${url} is unreachable (${cause && cause.code ? cause.code : cause && cause.message ? cause.message : 'fetch failed'})`,
|
|
54
|
+
)
|
|
55
|
+
error.unreachable = true
|
|
56
|
+
return error
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function readJson(response, url) {
|
|
60
|
+
const type = response.headers.get('content-type') || ''
|
|
61
|
+
if (!type.includes('application/json')) {
|
|
62
|
+
throw new Error(`${url} returned ${type || 'no content-type'} instead of JSON (route missing)`)
|
|
63
|
+
}
|
|
64
|
+
return response.json()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function fetchReport() {
|
|
68
|
+
const url = `${baseUrl}/skill-eval/data`
|
|
69
|
+
const controller = new AbortController()
|
|
70
|
+
const timer = setTimeout(() => controller.abort(), 5000)
|
|
71
|
+
try {
|
|
72
|
+
let response
|
|
73
|
+
try {
|
|
74
|
+
response = await fetch(url, { signal: controller.signal, headers: { accept: 'application/json' } })
|
|
75
|
+
} catch (cause) {
|
|
76
|
+
throw unreachable(url, cause)
|
|
77
|
+
}
|
|
78
|
+
if (!response.ok) throw new Error(`${url} returned HTTP ${response.status}`)
|
|
79
|
+
return await readJson(response, url)
|
|
80
|
+
} finally {
|
|
81
|
+
clearTimeout(timer)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function fetchVersioned() {
|
|
86
|
+
if (!version) throw new Error('package version is unknown')
|
|
87
|
+
const url = `${baseUrl}/skill-eval/data/${version}`
|
|
88
|
+
const controller = new AbortController()
|
|
89
|
+
const timer = setTimeout(() => controller.abort(), 5000)
|
|
90
|
+
try {
|
|
91
|
+
let response
|
|
92
|
+
try {
|
|
93
|
+
response = await fetch(url, { signal: controller.signal, headers: { accept: 'application/json' } })
|
|
94
|
+
} catch (cause) {
|
|
95
|
+
throw unreachable(url, cause)
|
|
96
|
+
}
|
|
97
|
+
if (!response.ok) throw new Error(`${url} returned HTTP ${response.status}`)
|
|
98
|
+
return await readJson(response, url)
|
|
99
|
+
} finally {
|
|
100
|
+
clearTimeout(timer)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const dashboard = dashboardBase()
|
|
105
|
+
|
|
106
|
+
async function fetchConfigPage() {
|
|
107
|
+
const versioned = `${baseUrl}${dashboard}/board/${manifestVersion()}/config`
|
|
108
|
+
const canonical = `${baseUrl}${dashboard}/config`
|
|
109
|
+
const url = versioned
|
|
110
|
+
const controller = new AbortController()
|
|
111
|
+
const timer = setTimeout(() => controller.abort(), 5000)
|
|
112
|
+
try {
|
|
113
|
+
let response
|
|
114
|
+
try {
|
|
115
|
+
response = await fetch(url, { signal: controller.signal, headers: { accept: 'text/html' } })
|
|
116
|
+
} catch (cause) {
|
|
117
|
+
throw unreachable(url, cause)
|
|
118
|
+
}
|
|
119
|
+
if (response.status === 404) {
|
|
120
|
+
const fallback = await fetch(canonical, { signal: controller.signal, headers: { accept: 'text/html' } })
|
|
121
|
+
if (!fallback.ok) throw new Error(`${canonical} returned HTTP ${fallback.status}`)
|
|
122
|
+
return await fallback.text()
|
|
123
|
+
}
|
|
124
|
+
if (!response.ok) throw new Error(`${url} returned HTTP ${response.status}`)
|
|
125
|
+
return await response.text()
|
|
126
|
+
} finally {
|
|
127
|
+
clearTimeout(timer)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function fetchSettingsApi() {
|
|
132
|
+
const url = `${baseUrl}${dashboard}/settings/${manifestVersion()}`
|
|
133
|
+
const controller = new AbortController()
|
|
134
|
+
const timer = setTimeout(() => controller.abort(), 5000)
|
|
135
|
+
try {
|
|
136
|
+
let response
|
|
137
|
+
try {
|
|
138
|
+
response = await fetch(url, { signal: controller.signal, headers: { accept: 'application/json' } })
|
|
139
|
+
} catch (cause) {
|
|
140
|
+
throw unreachable(url, cause)
|
|
141
|
+
}
|
|
142
|
+
if (response.status === 404) {
|
|
143
|
+
const fallbackUrl = `${baseUrl}${dashboard}/settings`
|
|
144
|
+
const fallback = await fetch(fallbackUrl, { signal: controller.signal, headers: { accept: 'application/json' } })
|
|
145
|
+
if (!fallback.ok) throw new Error(`${fallbackUrl} returned HTTP ${fallback.status}`)
|
|
146
|
+
return await readJson(fallback, fallbackUrl)
|
|
147
|
+
}
|
|
148
|
+
if (!response.ok) throw new Error(`${url} returned HTTP ${response.status}`)
|
|
149
|
+
return await readJson(response, url)
|
|
150
|
+
} finally {
|
|
151
|
+
clearTimeout(timer)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function manifestVersion() {
|
|
156
|
+
return expectedVersion(currentVersion)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function readFiles() {
|
|
160
|
+
// The served report names the data directory it actually read; prefer it over
|
|
161
|
+
// scanning profiles, which can pick a different profile with a newer mtime.
|
|
162
|
+
let dataDir = dataDirOverride
|
|
163
|
+
if (!dataDir) {
|
|
164
|
+
try {
|
|
165
|
+
const served = await fetchReport()
|
|
166
|
+
if (served && typeof served.dataDir === 'string' && served.dataDir.length > 0) dataDir = served.dataDir
|
|
167
|
+
} catch {
|
|
168
|
+
// fall back to the profile scan below
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
dataDir = dataDir ?? (await findDataDir())
|
|
172
|
+
if (!dataDir) throw new Error('no skill-eval data directory found (has any skill been loaded yet?)')
|
|
173
|
+
const eventsPath = path.join(dataDir, 'events.jsonl')
|
|
174
|
+
const snapshotMarkdownPath = path.join(dataDir, 'reports', 'latest.md')
|
|
175
|
+
const snapshotJsonPath = path.join(dataDir, 'reports', 'latest.json')
|
|
176
|
+
const raw = await readFile(eventsPath, 'utf8')
|
|
177
|
+
const events = []
|
|
178
|
+
for (const line of raw.split('\n')) {
|
|
179
|
+
const trimmed = line.trim()
|
|
180
|
+
if (!trimmed) continue
|
|
181
|
+
try {
|
|
182
|
+
events.push(JSON.parse(trimmed))
|
|
183
|
+
} catch {
|
|
184
|
+
// torn write
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const readOptional = async (file) => {
|
|
188
|
+
try {
|
|
189
|
+
return await readFile(file, 'utf8')
|
|
190
|
+
} catch {
|
|
191
|
+
return null
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
eventsPath,
|
|
196
|
+
snapshotMarkdownPath,
|
|
197
|
+
snapshotJsonPath,
|
|
198
|
+
events,
|
|
199
|
+
snapshotText: await readOptional(snapshotMarkdownPath),
|
|
200
|
+
snapshotJsonText: await readOptional(snapshotJsonPath),
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const report = await runAcceptance({
|
|
205
|
+
baseUrl,
|
|
206
|
+
fetchReport,
|
|
207
|
+
fetchVersioned,
|
|
208
|
+
fetchConfigPage,
|
|
209
|
+
fetchSettingsApi,
|
|
210
|
+
readFiles,
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
if (!baseUrl) {
|
|
214
|
+
console.log('dsh-skill-eval acceptance: no base URL')
|
|
215
|
+
console.log(` pass one explicitly: node scripts/accept.mjs http://127.0.0.1:<port>`)
|
|
216
|
+
console.log(` or export DSH_WEB_URL (the GUI port changes on every launch)`)
|
|
217
|
+
process.exit(1)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
console.log(`dsh-skill-eval acceptance — ${baseUrl} (from ${resolved.source})`)
|
|
221
|
+
for (const item of report.results) {
|
|
222
|
+
const mark = item.ok ? 'PASS' : 'FAIL'
|
|
223
|
+
console.log(` [${mark}] ${item.id.padEnd(18)} ${item.detail}`)
|
|
224
|
+
}
|
|
225
|
+
console.log('')
|
|
226
|
+
console.log(report.summary)
|
|
227
|
+
process.exit(report.ok ? 0 : 1)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Build the browser artifact from client/*.js.
|
|
4
|
+
*
|
|
5
|
+
* The DSH client loader evaluates one self-contained factory file, and this
|
|
6
|
+
* project deliberately avoids a bundler dependency. Each part is a plain
|
|
7
|
+
* JavaScript snippet in the factory's lexical scope; this script concatenates
|
|
8
|
+
* them in `client/parts.json` order and wraps the result in the loader format.
|
|
9
|
+
*
|
|
10
|
+
* node scripts/build-client.mjs # write client.js
|
|
11
|
+
* node scripts/build-client.mjs --check # exit 1 when client.js is stale
|
|
12
|
+
*/
|
|
13
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
import { fileURLToPath } from 'node:url'
|
|
16
|
+
|
|
17
|
+
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
18
|
+
const parts = JSON.parse(await readFile(path.join(root, 'client/parts.json'), 'utf8'))
|
|
19
|
+
|
|
20
|
+
const header = `/**
|
|
21
|
+
* GENERATED FILE — do not edit directly.
|
|
22
|
+
* Source: client/*.js · build: node scripts/build-client.mjs
|
|
23
|
+
*/
|
|
24
|
+
window.__ModuleLoader__.load({
|
|
25
|
+
id: 'dsh-skill-eval',
|
|
26
|
+
factory(require) {
|
|
27
|
+
`
|
|
28
|
+
const footer = ` },
|
|
29
|
+
})
|
|
30
|
+
`
|
|
31
|
+
const indent = (text) =>
|
|
32
|
+
text
|
|
33
|
+
.split('\n')
|
|
34
|
+
.map((line) => (line.length > 0 ? ` ${line}` : line))
|
|
35
|
+
.join('\n')
|
|
36
|
+
const sections = []
|
|
37
|
+
for (const part of parts) {
|
|
38
|
+
const text = await readFile(path.join(root, 'client', part), 'utf8')
|
|
39
|
+
sections.push(` // client/${part}\n${indent(text.trimEnd())}\n`)
|
|
40
|
+
}
|
|
41
|
+
const output = header + '\n' + sections.join('\n') + footer
|
|
42
|
+
|
|
43
|
+
const target = path.join(root, 'client.js')
|
|
44
|
+
if (process.argv.includes('--check')) {
|
|
45
|
+
let current = ''
|
|
46
|
+
try {
|
|
47
|
+
current = await readFile(target, 'utf8')
|
|
48
|
+
} catch {
|
|
49
|
+
// missing counts as stale
|
|
50
|
+
}
|
|
51
|
+
if (current !== output) {
|
|
52
|
+
console.error('client.js is stale: run `node scripts/build-client.mjs` and re-check the page.')
|
|
53
|
+
process.exit(1)
|
|
54
|
+
}
|
|
55
|
+
console.log('client.js is up to date with client/*.js')
|
|
56
|
+
} else {
|
|
57
|
+
await writeFile(target, output, 'utf8')
|
|
58
|
+
console.log(`client.js rebuilt from ${parts.length} parts (${output.length} chars)`)
|
|
59
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* One-command build for dsh-skill-eval.
|
|
4
|
+
*
|
|
5
|
+
* node scripts/build.mjs # format check, lint, client build, doctor, tests
|
|
6
|
+
* node scripts/build.mjs --fast # client build + doctor only
|
|
7
|
+
* node scripts/build.mjs --pack # full checks + dist/<version>.tgz + doctor --release
|
|
8
|
+
* node scripts/build.mjs --install # pack + install into the desktop profile
|
|
9
|
+
* node scripts/build.mjs --install=name # pack + install into another DSH profile
|
|
10
|
+
* node scripts/build.mjs --fix # prettier --write before the checks
|
|
11
|
+
*
|
|
12
|
+
* The script is intentionally dependency-free and uses the same commands the
|
|
13
|
+
* release checklist documents, so a local build and CI cannot drift.
|
|
14
|
+
*/
|
|
15
|
+
import { spawnSync } from 'node:child_process'
|
|
16
|
+
import { readFile, stat } from 'node:fs/promises'
|
|
17
|
+
import path from 'node:path'
|
|
18
|
+
import { fileURLToPath } from 'node:url'
|
|
19
|
+
|
|
20
|
+
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
21
|
+
const args = process.argv.slice(2)
|
|
22
|
+
const has = (flag) => args.includes(flag)
|
|
23
|
+
const valueOf = (flag) => {
|
|
24
|
+
const match = args.find((arg) => arg === flag || arg.startsWith(`${flag}=`))
|
|
25
|
+
if (!match) return null
|
|
26
|
+
return match.includes('=') ? match.slice(match.indexOf('=') + 1) : ''
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const fix = has('--fix')
|
|
30
|
+
const fast = has('--fast')
|
|
31
|
+
const installArg = valueOf('--install')
|
|
32
|
+
const doInstall = installArg !== null
|
|
33
|
+
const doPack = has('--pack') || doInstall
|
|
34
|
+
const profile = installArg || 'desktop'
|
|
35
|
+
|
|
36
|
+
function run(label, command, commandArgs) {
|
|
37
|
+
console.log(`\n▶ ${label}`)
|
|
38
|
+
const result = spawnSync(command, commandArgs, { cwd: root, stdio: 'inherit', env: process.env })
|
|
39
|
+
if (result.error) {
|
|
40
|
+
console.error(`\n✖ ${label} could not start: ${result.error.message}`)
|
|
41
|
+
process.exit(1)
|
|
42
|
+
}
|
|
43
|
+
if (result.status !== 0) {
|
|
44
|
+
console.error(`\n✖ ${label} failed with exit code ${result.status ?? 'unknown'}`)
|
|
45
|
+
process.exit(result.status ?? 1)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function npm(script) {
|
|
50
|
+
run(`npm run ${script}`, 'npm', ['run', script])
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const manifest = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'))
|
|
54
|
+
console.log(`dsh-skill-eval ${manifest.version} · ${fast ? 'fast build' : 'full build'}${doPack ? ' + pack' : ''}`)
|
|
55
|
+
|
|
56
|
+
if (fix) npm('format')
|
|
57
|
+
if (!fast) {
|
|
58
|
+
npm('format:check')
|
|
59
|
+
npm('lint')
|
|
60
|
+
}
|
|
61
|
+
run('build client', process.execPath, [path.join(root, 'scripts/build-client.mjs')])
|
|
62
|
+
run('doctor', process.execPath, [path.join(root, 'scripts/doctor.mjs')])
|
|
63
|
+
if (!fast) run('tests', process.execPath, ['--test', 'test/'])
|
|
64
|
+
|
|
65
|
+
let tarball = null
|
|
66
|
+
if (doPack) {
|
|
67
|
+
npm('release:pack')
|
|
68
|
+
tarball = path.join(root, 'dist', `dsh-skill-eval-${manifest.version}.tgz`)
|
|
69
|
+
const info = await stat(tarball).catch(() => null)
|
|
70
|
+
if (!info) {
|
|
71
|
+
console.error(`\n✖ packed tarball not found: ${path.relative(root, tarball)}`)
|
|
72
|
+
process.exit(1)
|
|
73
|
+
}
|
|
74
|
+
run('doctor --release', process.execPath, [path.join(root, 'scripts/doctor.mjs'), '--release'])
|
|
75
|
+
console.log(`\n✔ artifact ${path.relative(root, tarball)} · ${Math.round(info.size / 1024)} kB`)
|
|
76
|
+
if (doInstall) run(`install into ${profile}`, 'dsh', ['plugin', '--profile', profile, 'add', tarball])
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
console.log(
|
|
80
|
+
`\n✔ build complete${doPack ? ` · ${path.relative(root, tarball)}` : ''}${doInstall ? ` · installed into ${profile}` : ''}`,
|
|
81
|
+
)
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Packaging doctor: catch drift between the manifest, the bundle patch, the
|
|
4
|
+
* client registration keys and the files those names point at.
|
|
5
|
+
*
|
|
6
|
+
* These are the failures that only show up as "the plugin silently does not
|
|
7
|
+
* appear" after a restart, so they are worth a cheap pre-flight check.
|
|
8
|
+
*/
|
|
9
|
+
import { access, readFile, readdir } from 'node:fs/promises'
|
|
10
|
+
import { execFile } from 'node:child_process'
|
|
11
|
+
import { promisify } from 'node:util'
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
|
|
15
|
+
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
16
|
+
const rows = []
|
|
17
|
+
const add = (id, ok, detail) => rows.push({ id, ok, detail })
|
|
18
|
+
const run = promisify(execFile)
|
|
19
|
+
|
|
20
|
+
async function exists(relative) {
|
|
21
|
+
try {
|
|
22
|
+
await access(path.join(root, relative))
|
|
23
|
+
return true
|
|
24
|
+
} catch {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const manifest = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'))
|
|
30
|
+
|
|
31
|
+
add('manifest-name', manifest.name === 'dsh-skill-eval', manifest.name)
|
|
32
|
+
add('manifest-version', /^\d+\.\d+\.\d+$/.test(manifest.version ?? ''), manifest.version)
|
|
33
|
+
add(
|
|
34
|
+
'exports-host',
|
|
35
|
+
typeof manifest.exports?.['.'] === 'string' || typeof manifest.exports?.['.']?.default === 'string',
|
|
36
|
+
JSON.stringify(manifest.exports?.['.'] ?? null),
|
|
37
|
+
)
|
|
38
|
+
add('exports-client', Boolean(manifest.exports?.['./client']), JSON.stringify(manifest.exports?.['./client'] ?? null))
|
|
39
|
+
add('engines-dsh', typeof manifest.dsh?.engines?.dsh === 'string', manifest.dsh?.engines?.dsh ?? 'missing')
|
|
40
|
+
add(
|
|
41
|
+
'bundle-patch',
|
|
42
|
+
Boolean(manifest.dsh?.bundle?.patch) && (await exists(manifest.dsh.bundle.patch)),
|
|
43
|
+
manifest.dsh?.bundle?.patch ?? 'missing',
|
|
44
|
+
)
|
|
45
|
+
add('client-platform', manifest.dsh?.client?.platform === 'web', JSON.stringify(manifest.dsh?.client ?? null))
|
|
46
|
+
|
|
47
|
+
// bundle patch row -> native settings key the client must register
|
|
48
|
+
let rowId
|
|
49
|
+
try {
|
|
50
|
+
const patch = await readFile(path.join(root, manifest.dsh?.bundle?.patch ?? 'cordis.patch.yml'), 'utf8')
|
|
51
|
+
const match = patch.match(/^\s*-\s*id:\s*([A-Za-z0-9_-]+)\s*$/m)
|
|
52
|
+
rowId = match?.[1] ?? null
|
|
53
|
+
add('patch-row-id', Boolean(rowId), rowId ?? 'no `- id:` row found in the patch')
|
|
54
|
+
} catch (error) {
|
|
55
|
+
add('patch-row-id', false, error instanceof Error ? error.message : String(error))
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const client = await readFile(path.join(root, 'client.js'), 'utf8')
|
|
59
|
+
// The native settings page is the bundle config seat, keyed by package name
|
|
60
|
+
// (same pattern as dsh-context), so the key must appear in the client.
|
|
61
|
+
const bundleKey = manifest.name
|
|
62
|
+
const hasSeat = client.includes("name: 'plugins.bundle.config'")
|
|
63
|
+
add(
|
|
64
|
+
'bundle-config-key',
|
|
65
|
+
hasSeat && client.includes(`key: '${bundleKey}'`),
|
|
66
|
+
hasSeat
|
|
67
|
+
? `client registers plugins.bundle.config key "${bundleKey}"`
|
|
68
|
+
: 'plugins.bundle.config seat missing in client',
|
|
69
|
+
)
|
|
70
|
+
add(
|
|
71
|
+
'board-panel-seat',
|
|
72
|
+
client.includes("name: 'sidebar.panellist'") && client.includes("name: 'main'"),
|
|
73
|
+
'sidebar.panellist + main panel registration present',
|
|
74
|
+
)
|
|
75
|
+
} catch (error) {
|
|
76
|
+
add('bundle-config-key', false, error instanceof Error ? error.message : String(error))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// every relative import must resolve (a typo here is a silent boot failure)
|
|
80
|
+
const sources = [
|
|
81
|
+
'index.js',
|
|
82
|
+
'client.js',
|
|
83
|
+
...(await readdir(path.join(root, 'lib'))).filter((name) => name.endsWith('.js')).map((name) => `lib/${name}`),
|
|
84
|
+
]
|
|
85
|
+
const missingImports = []
|
|
86
|
+
for (const source of sources) {
|
|
87
|
+
const text = await readFile(path.join(root, source), 'utf8')
|
|
88
|
+
for (const match of text.matchAll(/from\s+['"](\.[^'"]+)['"]/g)) {
|
|
89
|
+
const target = path.resolve(root, path.dirname(source), match[1])
|
|
90
|
+
if (!(await exists(path.relative(root, target)))) missingImports.push(`${source} → ${match[1]}`)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
add(
|
|
94
|
+
'relative-imports',
|
|
95
|
+
missingImports.length === 0,
|
|
96
|
+
missingImports.length === 0 ? `${sources.length} file(s) clean` : missingImports.join('; '),
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
// locale resources feed the plugin's localized title/description in the UI
|
|
100
|
+
let localeOk = false
|
|
101
|
+
let localeDetail
|
|
102
|
+
try {
|
|
103
|
+
const zh = JSON.parse(await readFile(path.join(root, 'locale/zh.json'), 'utf8'))
|
|
104
|
+
const en = JSON.parse(await readFile(path.join(root, 'locale/en.json'), 'utf8'))
|
|
105
|
+
const ok = (entry) =>
|
|
106
|
+
entry &&
|
|
107
|
+
entry.meta &&
|
|
108
|
+
typeof entry.meta.title === 'string' &&
|
|
109
|
+
entry.meta.title.length > 0 &&
|
|
110
|
+
typeof entry.meta.description === 'string' &&
|
|
111
|
+
entry.meta.description.length > 0
|
|
112
|
+
localeOk = ok(zh) && ok(en)
|
|
113
|
+
localeDetail = localeOk ? 'zh/en meta.title + meta.description present' : 'meta.title/meta.description missing'
|
|
114
|
+
} catch (error) {
|
|
115
|
+
localeDetail = error instanceof Error ? error.message : String(error)
|
|
116
|
+
}
|
|
117
|
+
add('locale-meta', localeOk, localeDetail)
|
|
118
|
+
|
|
119
|
+
// the shipped client.js must match its source parts. A published tarball does
|
|
120
|
+
// not ship client/ (only the built client.js), so a missing parts.json means
|
|
121
|
+
// "packaged install" and there is nothing to compare against.
|
|
122
|
+
if (await exists('client/parts.json')) {
|
|
123
|
+
try {
|
|
124
|
+
await run(process.execPath, [path.join(root, 'scripts/build-client.mjs'), '--check'], { cwd: root })
|
|
125
|
+
add('client-build', true, 'client.js matches client/*.js')
|
|
126
|
+
} catch {
|
|
127
|
+
add('client-build', false, 'client.js is stale: run `node scripts/build-client.mjs`')
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
add('client-build', true, 'packaged install: client.js is prebuilt (client/ sources are not shipped)')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// the client half must reference the versioned data route it will fetch
|
|
134
|
+
try {
|
|
135
|
+
const client = await readFile(path.join(root, 'client.js'), 'utf8')
|
|
136
|
+
add(
|
|
137
|
+
'client-data-version',
|
|
138
|
+
client.includes(`'${manifest.version}'`) || client.includes(`"${manifest.version}"`),
|
|
139
|
+
`client DATA_VERSION matches ${manifest.version}`,
|
|
140
|
+
)
|
|
141
|
+
} catch {
|
|
142
|
+
add('client-data-version', false, 'client.js unreadable')
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ---------------------------------------------------------------- release gate
|
|
146
|
+
// Run with --release before publishing: these catch the mistakes that make a
|
|
147
|
+
// tarball installable-but-broken (no license, private:true, docs screenshots
|
|
148
|
+
// inside the package, missing bins, stale dist artifact).
|
|
149
|
+
add(
|
|
150
|
+
'license-file',
|
|
151
|
+
(await exists('LICENSE')) && manifest.license === 'MIT',
|
|
152
|
+
manifest.license
|
|
153
|
+
? `${manifest.license} · ${(await exists('LICENSE')) ? 'LICENSE present' : 'LICENSE missing'}`
|
|
154
|
+
: 'no license field',
|
|
155
|
+
)
|
|
156
|
+
add(
|
|
157
|
+
'publishable',
|
|
158
|
+
manifest.private !== true,
|
|
159
|
+
manifest.private === true ? 'package.json still has private:true' : 'private not set',
|
|
160
|
+
)
|
|
161
|
+
const declaredFiles = Array.isArray(manifest.files) ? manifest.files : []
|
|
162
|
+
const filesOk =
|
|
163
|
+
declaredFiles.includes('index.js') &&
|
|
164
|
+
declaredFiles.includes('client.js') &&
|
|
165
|
+
declaredFiles.includes('lib/**/*.js') &&
|
|
166
|
+
declaredFiles.includes('cordis.patch.yml') &&
|
|
167
|
+
declaredFiles.includes('icon.svg') &&
|
|
168
|
+
declaredFiles.includes('docs/*.md') &&
|
|
169
|
+
declaredFiles.includes('locale') &&
|
|
170
|
+
declaredFiles.includes('scripts') &&
|
|
171
|
+
declaredFiles.includes('README.md') &&
|
|
172
|
+
declaredFiles.includes('CHANGELOG.md') &&
|
|
173
|
+
declaredFiles.includes('LICENSE') &&
|
|
174
|
+
!declaredFiles.includes('docs')
|
|
175
|
+
add(
|
|
176
|
+
'package-files',
|
|
177
|
+
filesOk,
|
|
178
|
+
filesOk
|
|
179
|
+
? 'files list is explicit and excludes docs/ui screenshots'
|
|
180
|
+
: `unexpected files list: ${declaredFiles.join(', ')}`,
|
|
181
|
+
)
|
|
182
|
+
const bins = manifest.bin ?? {}
|
|
183
|
+
const binScripts = Object.values(bins)
|
|
184
|
+
const binsExist =
|
|
185
|
+
['dsh-skill-eval-verify', 'dsh-skill-eval-doctor', 'dsh-skill-eval-accept'].every((name) => name in bins) &&
|
|
186
|
+
(await Promise.all(binScripts.map((script) => exists(script.replace(/^\.\//, ''))))).every(Boolean)
|
|
187
|
+
add('bin-complete', binsExist, Object.keys(bins).join(', ') || 'no bins')
|
|
188
|
+
add(
|
|
189
|
+
'release-script',
|
|
190
|
+
typeof manifest.scripts?.['release:check'] === 'string',
|
|
191
|
+
manifest.scripts?.['release:check'] ?? 'missing release:check',
|
|
192
|
+
)
|
|
193
|
+
if (process.argv.includes('--release')) {
|
|
194
|
+
const artifact = `dist/${manifest.name}-${manifest.version}.tgz`
|
|
195
|
+
if (!(await exists(artifact))) {
|
|
196
|
+
add('dist-artifact', false, `run "npm run release:pack" to build ${artifact}`)
|
|
197
|
+
} else {
|
|
198
|
+
try {
|
|
199
|
+
// Opening the tarball is the only way to catch a files-list edit that
|
|
200
|
+
// ships a manifest but drops a runtime file (locale, scripts, lib).
|
|
201
|
+
const { stdout } = await run('tar', ['-tzf', path.join(root, artifact)])
|
|
202
|
+
const entries = stdout.split('\n').filter(Boolean)
|
|
203
|
+
const required = [
|
|
204
|
+
'package/index.js',
|
|
205
|
+
'package/client.js',
|
|
206
|
+
'package/cordis.patch.yml',
|
|
207
|
+
'package/locale/en.json',
|
|
208
|
+
'package/locale/zh.json',
|
|
209
|
+
'package/scripts/doctor.mjs',
|
|
210
|
+
]
|
|
211
|
+
const missing = required.filter((entry) => !entries.includes(entry))
|
|
212
|
+
const hasLib = entries.some((entry) => entry.startsWith('package/lib/') && entry.endsWith('.js'))
|
|
213
|
+
add(
|
|
214
|
+
'dist-artifact',
|
|
215
|
+
missing.length === 0 && hasLib,
|
|
216
|
+
missing.length === 0 && hasLib
|
|
217
|
+
? `${artifact} (${entries.length} entries)`
|
|
218
|
+
: `missing ${missing.join(', ') || 'lib/*.js'}`,
|
|
219
|
+
)
|
|
220
|
+
} catch (error) {
|
|
221
|
+
add('dist-artifact', false, error instanceof Error ? error.message : String(error))
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const failed = rows.filter((row) => !row.ok)
|
|
227
|
+
console.log(`dsh-skill-eval doctor — ${manifest.name}@${manifest.version}`)
|
|
228
|
+
for (const row of rows) console.log(` [${row.ok ? 'PASS' : 'FAIL'}] ${row.id.padEnd(20)} ${row.detail}`)
|
|
229
|
+
console.log('')
|
|
230
|
+
if (failed.length > 0) {
|
|
231
|
+
console.log(`FAIL (${failed.length}) — fix these before a restart, they cause silent non-appearance.`)
|
|
232
|
+
process.exit(1)
|
|
233
|
+
}
|
|
234
|
+
console.log('PASS — manifest, patch, client keys and imports agree.')
|
package/scripts/lib.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** Shared plumbing for the terminal check scripts (accept / verify). */
|
|
2
|
+
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import { homedir } from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { pickBaseUrl } from '../lib/accept.js'
|
|
6
|
+
|
|
7
|
+
/** The relay bridge the desktop app writes; missing/unreadable means "none". */
|
|
8
|
+
export async function readBridge() {
|
|
9
|
+
const home = process.env.DSH_HOME || path.join(homedir(), '.dsh')
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(await readFile(path.join(home, 'remote-web-ui-relay-bridge.json'), 'utf8'))
|
|
12
|
+
} catch {
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Parse CLI arguments for the terminal checks: flags that take a value must
|
|
19
|
+
* consume their value instead of leaking it into the positional base URL.
|
|
20
|
+
* Returns { baseArg, values } where values is keyed by the flag name.
|
|
21
|
+
*/
|
|
22
|
+
export function parseCliArgs(argv, flagsWithValues = ['--data-dir']) {
|
|
23
|
+
const args = Array.isArray(argv) ? argv : []
|
|
24
|
+
let baseArg = null
|
|
25
|
+
const values = {}
|
|
26
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
27
|
+
const arg = String(args[i])
|
|
28
|
+
if (arg === '--') {
|
|
29
|
+
const next = args[i + 1]
|
|
30
|
+
if (next !== undefined && baseArg === null) baseArg = String(next)
|
|
31
|
+
break
|
|
32
|
+
}
|
|
33
|
+
if (arg.startsWith('--') && arg.includes('=')) {
|
|
34
|
+
const name = arg.slice(0, arg.indexOf('='))
|
|
35
|
+
if (flagsWithValues.includes(name)) values[name] = arg.slice(name.length + 1)
|
|
36
|
+
continue
|
|
37
|
+
}
|
|
38
|
+
if (flagsWithValues.includes(arg)) {
|
|
39
|
+
const value = args[i + 1]
|
|
40
|
+
if (value !== undefined) {
|
|
41
|
+
values[arg] = String(value)
|
|
42
|
+
i += 1
|
|
43
|
+
}
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
if (arg.startsWith('--')) continue
|
|
47
|
+
if (baseArg === null) baseArg = arg
|
|
48
|
+
}
|
|
49
|
+
return { baseArg, values }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Base URL precedence: explicit argument > DSH_WEB_URL > relay bridge. */
|
|
53
|
+
export async function resolveBaseUrl(explicit) {
|
|
54
|
+
return pickBaseUrl(explicit, process.env.DSH_WEB_URL, await readBridge())
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Dashboard base path (`DSH_SKILL_EVAL_BASE` overrides the default). */
|
|
58
|
+
export function dashboardBase() {
|
|
59
|
+
return (process.env.DSH_SKILL_EVAL_BASE || '/skill-eval').replace(/\/$/, '')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Version that the check scripts expect the host to serve. */
|
|
63
|
+
export function expectedVersion(fallback) {
|
|
64
|
+
return process.env.DSH_SKILL_EVAL_VERSION || fallback
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* GET with a timeout and a content-type assertion. Returns `{body, type}` and
|
|
69
|
+
* throws an error whose message names the URL, like the old inline helpers.
|
|
70
|
+
*/
|
|
71
|
+
export async function httpGet(base, pathname, { expectType, timeoutMs = 5000 } = {}) {
|
|
72
|
+
const url = base + pathname
|
|
73
|
+
const controller = new AbortController()
|
|
74
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs)
|
|
75
|
+
try {
|
|
76
|
+
const response = await fetch(url, { signal: controller.signal })
|
|
77
|
+
const body = await response.text()
|
|
78
|
+
const type = response.headers.get('content-type') || ''
|
|
79
|
+
if (!response.ok) throw new Error(`${url} → HTTP ${response.status}`)
|
|
80
|
+
if (expectType && type.indexOf(expectType) === -1) {
|
|
81
|
+
throw new Error(`${url} → ${type || 'no content-type'} (expected ${expectType})`)
|
|
82
|
+
}
|
|
83
|
+
return { body, type }
|
|
84
|
+
} finally {
|
|
85
|
+
clearTimeout(timer)
|
|
86
|
+
}
|
|
87
|
+
}
|