dsh-skill-eval 0.0.0-stage → 1.20.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +675 -0
  2. package/LICENSE +21 -0
  3. package/README.md +200 -2
  4. package/README.zh.md +157 -0
  5. package/client.js +2637 -0
  6. package/cordis.patch.yml +9 -0
  7. package/docs/ACCEPTANCE.md +71 -0
  8. package/docs/AUDIT.md +64 -0
  9. package/docs/CODE-REVIEW.md +49 -0
  10. package/docs/COMPARISON.md +33 -0
  11. package/docs/DETAIL.md +463 -0
  12. package/docs/DEV-RELOAD.md +114 -0
  13. package/docs/ENTRYPOINTS.md +65 -0
  14. package/docs/RELEASE.md +44 -0
  15. package/docs/RRSI-NOTES.md +129 -0
  16. package/docs/SCENARIOS.md +91 -0
  17. package/docs/UI-REVIEW.md +115 -0
  18. package/docs/WORKFLOW.md +108 -0
  19. package/icon.svg +9 -0
  20. package/index.js +1111 -0
  21. package/lib/accept.js +350 -0
  22. package/lib/advice.js +547 -0
  23. package/lib/critic.js +101 -0
  24. package/lib/dev.js +148 -0
  25. package/lib/history.js +140 -0
  26. package/lib/html.js +8 -0
  27. package/lib/inspect.js +142 -0
  28. package/lib/integrity.js +46 -0
  29. package/lib/loop.js +195 -0
  30. package/lib/random.js +29 -0
  31. package/lib/recorder.js +634 -0
  32. package/lib/render.js +582 -0
  33. package/lib/report.js +646 -0
  34. package/lib/score.js +525 -0
  35. package/lib/settings.js +396 -0
  36. package/lib/snapshot.js +166 -0
  37. package/lib/steps.js +141 -0
  38. package/lib/store.js +186 -0
  39. package/lib/validity.js +115 -0
  40. package/locale/en.json +6 -0
  41. package/locale/zh.json +6 -0
  42. package/package.json +96 -4
  43. package/scripts/accept.mjs +226 -0
  44. package/scripts/build-client.mjs +59 -0
  45. package/scripts/build.mjs +81 -0
  46. package/scripts/doctor.mjs +199 -0
  47. package/scripts/lib.mjs +52 -0
  48. package/scripts/verify-live.mjs +168 -0
@@ -0,0 +1,226 @@
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, resolveBaseUrl } from './lib.mjs'
17
+
18
+ const args = process.argv.slice(2)
19
+ const baseArg = args.find((arg) => !arg.startsWith('--'))
20
+ const dataDirFlag = args.indexOf('--data-dir')
21
+ const resolved = await resolveBaseUrl(baseArg)
22
+ const baseUrl = resolved.baseUrl
23
+ const manifest = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
24
+ const currentVersion = expectedVersion(manifest.version)
25
+ const version = typeof manifest.version === 'string' ? manifest.version : null
26
+
27
+ async function findDataDir() {
28
+ if (dataDirFlag >= 0 && args[dataDirFlag + 1]) return path.resolve(args[dataDirFlag + 1])
29
+ const home = process.env.DSH_HOME || path.join(homedir(), '.dsh')
30
+ const root = path.join(home, 'skill-eval')
31
+ let candidates
32
+ try {
33
+ candidates = await readdir(root)
34
+ } catch {
35
+ return null
36
+ }
37
+ let best = null
38
+ for (const name of candidates) {
39
+ const dir = path.join(root, name)
40
+ try {
41
+ const info = await stat(path.join(dir, 'events.jsonl'))
42
+ if (!best || info.mtimeMs > best.mtimeMs) best = { dir, mtimeMs: info.mtimeMs }
43
+ } catch {
44
+ // no telemetry in this profile yet
45
+ }
46
+ }
47
+ return best ? best.dir : null
48
+ }
49
+
50
+ function unreachable(url, cause) {
51
+ const error = new Error(
52
+ `${url} is unreachable (${cause && cause.code ? cause.code : cause && cause.message ? cause.message : 'fetch failed'})`,
53
+ )
54
+ error.unreachable = true
55
+ return error
56
+ }
57
+
58
+ async function readJson(response, url) {
59
+ const type = response.headers.get('content-type') || ''
60
+ if (!type.includes('application/json')) {
61
+ throw new Error(`${url} returned ${type || 'no content-type'} instead of JSON (route missing)`)
62
+ }
63
+ return response.json()
64
+ }
65
+
66
+ async function fetchReport() {
67
+ const url = `${baseUrl}/skill-eval/data`
68
+ const controller = new AbortController()
69
+ const timer = setTimeout(() => controller.abort(), 5000)
70
+ try {
71
+ let response
72
+ try {
73
+ response = await fetch(url, { signal: controller.signal, headers: { accept: 'application/json' } })
74
+ } catch (cause) {
75
+ throw unreachable(url, cause)
76
+ }
77
+ if (!response.ok) throw new Error(`${url} returned HTTP ${response.status}`)
78
+ return await readJson(response, url)
79
+ } finally {
80
+ clearTimeout(timer)
81
+ }
82
+ }
83
+
84
+ async function fetchVersioned() {
85
+ if (!version) throw new Error('package version is unknown')
86
+ const url = `${baseUrl}/skill-eval/data/${version}`
87
+ const controller = new AbortController()
88
+ const timer = setTimeout(() => controller.abort(), 5000)
89
+ try {
90
+ let response
91
+ try {
92
+ response = await fetch(url, { signal: controller.signal, headers: { accept: 'application/json' } })
93
+ } catch (cause) {
94
+ throw unreachable(url, cause)
95
+ }
96
+ if (!response.ok) throw new Error(`${url} returned HTTP ${response.status}`)
97
+ return await readJson(response, url)
98
+ } finally {
99
+ clearTimeout(timer)
100
+ }
101
+ }
102
+
103
+ const dashboard = dashboardBase()
104
+
105
+ async function fetchConfigPage() {
106
+ const versioned = `${baseUrl}${dashboard}/board/${manifestVersion()}/config`
107
+ const canonical = `${baseUrl}${dashboard}/config`
108
+ const url = versioned
109
+ const controller = new AbortController()
110
+ const timer = setTimeout(() => controller.abort(), 5000)
111
+ try {
112
+ let response
113
+ try {
114
+ response = await fetch(url, { signal: controller.signal, headers: { accept: 'text/html' } })
115
+ } catch (cause) {
116
+ throw unreachable(url, cause)
117
+ }
118
+ if (response.status === 404) {
119
+ const fallback = await fetch(canonical, { signal: controller.signal, headers: { accept: 'text/html' } })
120
+ if (!fallback.ok) throw new Error(`${canonical} returned HTTP ${fallback.status}`)
121
+ return await fallback.text()
122
+ }
123
+ if (!response.ok) throw new Error(`${url} returned HTTP ${response.status}`)
124
+ return await response.text()
125
+ } finally {
126
+ clearTimeout(timer)
127
+ }
128
+ }
129
+
130
+ async function fetchSettingsApi() {
131
+ const url = `${baseUrl}${dashboard}/settings/${manifestVersion()}`
132
+ const controller = new AbortController()
133
+ const timer = setTimeout(() => controller.abort(), 5000)
134
+ try {
135
+ let response
136
+ try {
137
+ response = await fetch(url, { signal: controller.signal, headers: { accept: 'application/json' } })
138
+ } catch (cause) {
139
+ throw unreachable(url, cause)
140
+ }
141
+ if (response.status === 404) {
142
+ const fallbackUrl = `${baseUrl}${dashboard}/settings`
143
+ const fallback = await fetch(fallbackUrl, { signal: controller.signal, headers: { accept: 'application/json' } })
144
+ if (!fallback.ok) throw new Error(`${fallbackUrl} returned HTTP ${fallback.status}`)
145
+ return await readJson(fallback, fallbackUrl)
146
+ }
147
+ if (!response.ok) throw new Error(`${url} returned HTTP ${response.status}`)
148
+ return await readJson(response, url)
149
+ } finally {
150
+ clearTimeout(timer)
151
+ }
152
+ }
153
+
154
+ function manifestVersion() {
155
+ return expectedVersion(currentVersion)
156
+ }
157
+
158
+ async function readFiles() {
159
+ // The served report names the data directory it actually read; prefer it over
160
+ // scanning profiles, which can pick a different profile with a newer mtime.
161
+ let dataDir = dataDirFlag >= 0 && args[dataDirFlag + 1] ? path.resolve(args[dataDirFlag + 1]) : null
162
+ if (!dataDir) {
163
+ try {
164
+ const served = JSON.parse(await fetchReport())
165
+ if (served && typeof served.dataDir === 'string' && served.dataDir.length > 0) dataDir = served.dataDir
166
+ } catch {
167
+ // fall back to the profile scan below
168
+ }
169
+ }
170
+ dataDir = dataDir ?? (await findDataDir())
171
+ if (!dataDir) throw new Error('no skill-eval data directory found (has any skill been loaded yet?)')
172
+ const eventsPath = path.join(dataDir, 'events.jsonl')
173
+ const snapshotMarkdownPath = path.join(dataDir, 'reports', 'latest.md')
174
+ const snapshotJsonPath = path.join(dataDir, 'reports', 'latest.json')
175
+ const raw = await readFile(eventsPath, 'utf8')
176
+ const events = []
177
+ for (const line of raw.split('\n')) {
178
+ const trimmed = line.trim()
179
+ if (!trimmed) continue
180
+ try {
181
+ events.push(JSON.parse(trimmed))
182
+ } catch {
183
+ // torn write
184
+ }
185
+ }
186
+ const readOptional = async (file) => {
187
+ try {
188
+ return await readFile(file, 'utf8')
189
+ } catch {
190
+ return null
191
+ }
192
+ }
193
+ return {
194
+ eventsPath,
195
+ snapshotMarkdownPath,
196
+ snapshotJsonPath,
197
+ events,
198
+ snapshotText: await readOptional(snapshotMarkdownPath),
199
+ snapshotJsonText: await readOptional(snapshotJsonPath),
200
+ }
201
+ }
202
+
203
+ const report = await runAcceptance({
204
+ baseUrl,
205
+ fetchReport,
206
+ fetchVersioned,
207
+ fetchConfigPage,
208
+ fetchSettingsApi,
209
+ readFiles,
210
+ })
211
+
212
+ if (!baseUrl) {
213
+ console.log('dsh-skill-eval acceptance: no base URL')
214
+ console.log(` pass one explicitly: node scripts/accept.mjs http://127.0.0.1:<port>`)
215
+ console.log(` or export DSH_WEB_URL (the GUI port changes on every launch)`)
216
+ process.exit(1)
217
+ }
218
+
219
+ console.log(`dsh-skill-eval acceptance — ${baseUrl} (from ${resolved.source})`)
220
+ for (const item of report.results) {
221
+ const mark = item.ok ? 'PASS' : 'FAIL'
222
+ console.log(` [${mark}] ${item.id.padEnd(18)} ${item.detail}`)
223
+ }
224
+ console.log('')
225
+ console.log(report.summary)
226
+ 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,199 @@
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
120
+ try {
121
+ await run(process.execPath, [path.join(root, 'scripts/build-client.mjs'), '--check'], { cwd: root })
122
+ add('client-build', true, 'client.js matches client/*.js')
123
+ } catch {
124
+ add('client-build', false, 'client.js is stale: run `node scripts/build-client.mjs`')
125
+ }
126
+
127
+ // the client half must reference the versioned data route it will fetch
128
+ try {
129
+ const client = await readFile(path.join(root, 'client.js'), 'utf8')
130
+ add(
131
+ 'client-data-version',
132
+ client.includes(`'${manifest.version}'`) || client.includes(`"${manifest.version}"`),
133
+ `client DATA_VERSION matches ${manifest.version}`,
134
+ )
135
+ } catch {
136
+ add('client-data-version', false, 'client.js unreadable')
137
+ }
138
+
139
+ // ---------------------------------------------------------------- release gate
140
+ // Run with --release before publishing: these catch the mistakes that make a
141
+ // tarball installable-but-broken (no license, private:true, docs screenshots
142
+ // inside the package, missing bins, stale dist artifact).
143
+ add(
144
+ 'license-file',
145
+ (await exists('LICENSE')) && manifest.license === 'MIT',
146
+ manifest.license
147
+ ? `${manifest.license} · ${(await exists('LICENSE')) ? 'LICENSE present' : 'LICENSE missing'}`
148
+ : 'no license field',
149
+ )
150
+ add(
151
+ 'publishable',
152
+ manifest.private !== true,
153
+ manifest.private === true ? 'package.json still has private:true' : 'private not set',
154
+ )
155
+ const declaredFiles = Array.isArray(manifest.files) ? manifest.files : []
156
+ const filesOk =
157
+ declaredFiles.includes('index.js') &&
158
+ declaredFiles.includes('client.js') &&
159
+ declaredFiles.includes('lib/**/*.js') &&
160
+ declaredFiles.includes('cordis.patch.yml') &&
161
+ declaredFiles.includes('icon.svg') &&
162
+ declaredFiles.includes('docs/*.md') &&
163
+ !declaredFiles.includes('docs')
164
+ add(
165
+ 'package-files',
166
+ filesOk,
167
+ filesOk
168
+ ? 'files list is explicit and excludes docs/ui screenshots'
169
+ : `unexpected files list: ${declaredFiles.join(', ')}`,
170
+ )
171
+ const bins = manifest.bin ?? {}
172
+ const binScripts = Object.values(bins)
173
+ const binsExist =
174
+ ['dsh-skill-eval-verify', 'dsh-skill-eval-doctor', 'dsh-skill-eval-accept'].every((name) => name in bins) &&
175
+ (await Promise.all(binScripts.map((script) => exists(script.replace(/^\.\//, ''))))).every(Boolean)
176
+ add('bin-complete', binsExist, Object.keys(bins).join(', ') || 'no bins')
177
+ add(
178
+ 'release-script',
179
+ typeof manifest.scripts?.['release:check'] === 'string',
180
+ manifest.scripts?.['release:check'] ?? 'missing release:check',
181
+ )
182
+ if (process.argv.includes('--release')) {
183
+ const artifact = `dist/${manifest.name}-${manifest.version}.tgz`
184
+ add(
185
+ 'dist-artifact',
186
+ await exists(artifact),
187
+ (await exists(artifact)) ? artifact : `run "npm run release:pack" to build ${artifact}`,
188
+ )
189
+ }
190
+
191
+ const failed = rows.filter((row) => !row.ok)
192
+ console.log(`dsh-skill-eval doctor — ${manifest.name}@${manifest.version}`)
193
+ for (const row of rows) console.log(` [${row.ok ? 'PASS' : 'FAIL'}] ${row.id.padEnd(20)} ${row.detail}`)
194
+ console.log('')
195
+ if (failed.length > 0) {
196
+ console.log(`FAIL (${failed.length}) — fix these before a restart, they cause silent non-appearance.`)
197
+ process.exit(1)
198
+ }
199
+ console.log('PASS — manifest, patch, client keys and imports agree.')
@@ -0,0 +1,52 @@
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
+ /** Base URL precedence: explicit argument > DSH_WEB_URL > relay bridge. */
18
+ export async function resolveBaseUrl(explicit) {
19
+ return pickBaseUrl(explicit, process.env.DSH_WEB_URL, await readBridge())
20
+ }
21
+
22
+ /** Dashboard base path (`DSH_SKILL_EVAL_BASE` overrides the default). */
23
+ export function dashboardBase() {
24
+ return (process.env.DSH_SKILL_EVAL_BASE || '/skill-eval').replace(/\/$/, '')
25
+ }
26
+
27
+ /** Version that the check scripts expect the host to serve. */
28
+ export function expectedVersion(fallback) {
29
+ return process.env.DSH_SKILL_EVAL_VERSION || fallback
30
+ }
31
+
32
+ /**
33
+ * GET with a timeout and a content-type assertion. Returns `{body, type}` and
34
+ * throws an error whose message names the URL, like the old inline helpers.
35
+ */
36
+ export async function httpGet(base, pathname, { expectType, timeoutMs = 5000 } = {}) {
37
+ const url = base + pathname
38
+ const controller = new AbortController()
39
+ const timer = setTimeout(() => controller.abort(), timeoutMs)
40
+ try {
41
+ const response = await fetch(url, { signal: controller.signal })
42
+ const body = await response.text()
43
+ const type = response.headers.get('content-type') || ''
44
+ if (!response.ok) throw new Error(`${url} → HTTP ${response.status}`)
45
+ if (expectType && type.indexOf(expectType) === -1) {
46
+ throw new Error(`${url} → ${type || 'no content-type'} (expected ${expectType})`)
47
+ }
48
+ return { body, type }
49
+ } finally {
50
+ clearTimeout(timer)
51
+ }
52
+ }