dsh-tidy-display 0.3.1 → 0.4.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.
Files changed (60) hide show
  1. package/CHANGELOG.de.md +4 -4
  2. package/CHANGELOG.es.md +4 -4
  3. package/CHANGELOG.fr.md +4 -4
  4. package/CHANGELOG.it.md +4 -4
  5. package/CHANGELOG.md +15 -10
  6. package/CHANGELOG.ru.md +4 -4
  7. package/README.de.md +5 -5
  8. package/README.en.md +5 -5
  9. package/README.es.md +5 -5
  10. package/README.fr.md +5 -5
  11. package/README.it.md +5 -5
  12. package/README.md +5 -5
  13. package/README.ru.md +5 -5
  14. package/compat/harness-020rc2.json +99 -99
  15. package/lib/client.js +733 -420
  16. package/lib/client.js.map +1 -1
  17. package/lib/types/client/Reader.d.ts.map +1 -1
  18. package/lib/types/client/Reader.js +10 -6
  19. package/lib/types/client/Reader.js.map +1 -1
  20. package/lib/types/client/ReasoningCard.d.ts +2 -1
  21. package/lib/types/client/ReasoningCard.d.ts.map +1 -1
  22. package/lib/types/client/ReasoningCard.js +26 -4
  23. package/lib/types/client/ReasoningCard.js.map +1 -1
  24. package/lib/types/client/SettingsSection.d.ts +2 -0
  25. package/lib/types/client/SettingsSection.d.ts.map +1 -1
  26. package/lib/types/client/SettingsSection.js +2 -1
  27. package/lib/types/client/SettingsSection.js.map +1 -1
  28. package/lib/types/client/family-host.d.ts +51 -0
  29. package/lib/types/client/family-host.d.ts.map +1 -0
  30. package/lib/types/client/family-host.js +147 -0
  31. package/lib/types/client/family-host.js.map +1 -0
  32. package/lib/types/client/settings-copy.d.ts +1 -1
  33. package/lib/types/client/settings-copy.d.ts.map +1 -1
  34. package/lib/types/client/settings-copy.js +18 -0
  35. package/lib/types/client/settings-copy.js.map +1 -1
  36. package/lib/types/client/settings.d.ts.map +1 -1
  37. package/lib/types/client/settings.js +18 -8
  38. package/lib/types/client/settings.js.map +1 -1
  39. package/lib/types/client/store.d.ts +6 -0
  40. package/lib/types/client/store.d.ts.map +1 -1
  41. package/lib/types/client/store.js +2 -0
  42. package/lib/types/client/store.js.map +1 -1
  43. package/lib/types/client/types.d.ts +1 -0
  44. package/lib/types/client/types.d.ts.map +1 -1
  45. package/package.json +184 -183
  46. package/scripts/hosts.mjs +80 -80
  47. package/scripts/sync-hosts.mjs +170 -170
  48. package/scripts/test-host-compat.mjs +378 -378
  49. package/src/client/Reader.tsx +805 -801
  50. package/src/client/ReasoningCard.tsx +23 -5
  51. package/src/client/SettingsSection.tsx +19 -0
  52. package/src/client/family-host.ts +198 -0
  53. package/src/client/index.tsx +306 -306
  54. package/src/client/locales.ts +2422 -2422
  55. package/src/client/projection.ts +1 -1
  56. package/src/client/settings-copy.ts +100 -80
  57. package/src/client/settings.tsx +28 -10
  58. package/src/client/store.ts +11 -3
  59. package/src/client/types.ts +1 -0
  60. package/tests/browser-fold-scroll-issue.tsx +45 -45
@@ -1,378 +1,378 @@
1
- /**
2
- * test-host-compat.mjs —— 本地隔离矩阵执行体(improve-dsh-plugins/enum-peer-migration
3
- * /INDEX.md §E:`_wt` 工作树 + 离线 tgz 的 CI 前身)。
4
- *
5
- * 骨架沿 dsh-date-wrapper P0 试点定型版;沙箱加固(传递 dsh-* 全量钉版)与
6
- * HTTP 探针回读沿 dsh-paste-dock 执行体。每格 = 一个宿主 rc:
7
- * 1. tgz 缓存(`pnpm pack @deepseek-ai/dsh@<version>` → `.compat-results/host-tgz/`);
8
- * 2. 沙箱安装:宿主 tgz + **钉宿主自己的 Cordis 线**(INDEX §A 铁律:cordis 本体 +
9
- * group/hmr/include/loader/timer 五件,按宿主线 4.0.2/4.0.4 分档,经
10
- * pnpm-workspace.yaml overrides)+ `.pnpmfile.cjs` 把全部传递 `@deepseek-ai/dsh*`
11
- * 钉到宿主版本(防混装)。pnpm `--ignore-scripts`。
12
- * 3. 插件 tgz(lib/ 已入库,pack 无需构建)经**宿主 CLI 自建 profile** 装入:
13
- * `dsh plugin --profile web add <tgz>` —— peer 闸(app-boot
14
- * evaluatePluginCompatibility,逐 dsh-* peer 对宿主运行时版本 semver 匹配)
15
- * 在这一步咬合,add 日志可判 plugin-blocked。
16
- * 4. 引导形态协商:A 形 `--profile web --port 0 --no-open`(0.1.0-rc.8+),
17
- * 老线回退 C 形裸启动(默认端口,可能弹浏览器)。
18
- * 5. HTTP 探针(带 landing 会话 cookie):
19
- * GET /tidy-display/skill-status → 200 + JSON(scanGenerativeMcpappsStatus)
20
- * POST /tidy-display/reveal {path:''} → 400 {ok:false,error:'Empty path'}
21
- * (空路径探针不弹资源管理器窗口,纯语义验证路由与 handler 挂载)
22
- * 6. 日志断言:正向签名 `[my-plugins/dsh-tidy-display] loaded`;反向签名
23
- * 挂载/审计/重名/兼容拦截。
24
- *
25
- * 指纹门禁说明:本插件 18 文件哈希基线针对宿主 **monorepo 源码**,npm 发布包只带
26
- * lib/ 无 src/ ——矩阵格无法从沙箱采集指纹(需逐版本 monorepo 检出,CI 化事项)。
27
- * 故本执行体以**行为冒烟**为验收(spec §6 口径:指纹回答"宿主改没改",冒烟回答
28
- * "插件还能不能用")。
29
- *
30
- * 归因(日志签名):
31
- * - ready + 探针全过 + 无签名 → green
32
- * - /requires the Cordis HMR service/ → host-blocked(宿主引导墙,非插件问题)
33
- * - /is incompatible with dsh/(add 或 boot)→ plugin-blocked(peer 闸拒入/拒挂)
34
- * - 挂载/审计/重名签名 → plugin-blocked(notes 注明)
35
- *
36
- * 产物:`.compat-results/<version>/{install.log, plugin-add.log, boot-<X>.log,
37
- * result.json}` + 汇总 `results.json` + 绿名单 `verified.json`
38
- * (sync-hosts.mjs 据此写 README 的 Runtime-verified 行)。沙箱在系统临时目录:
39
- * 绿格即弃,红/错误格保留(路径见 result.json 的 sandbox 字段,--keep 全留)。
40
- *
41
- * 用法:
42
- * node scripts/test-host-compat.mjs # 全量(hosts.mjs 枚举)
43
- * node scripts/test-host-compat.mjs --only 0.2.0-rc.2 # 单格复跑
44
- * node scripts/test-host-compat.mjs --keep # 全部保留 sandbox 便于复查
45
- * node scripts/test-host-compat.mjs --force # 忽略已有结论强制重跑
46
- */
47
- import { spawn, spawnSync } from 'node:child_process'
48
- import { existsSync } from 'node:fs'
49
- import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises'
50
- import { tmpdir } from 'node:os'
51
- import path from 'node:path'
52
- import { fileURLToPath, pathToFileURL } from 'node:url'
53
- import { supportedHosts } from './hosts.mjs'
54
-
55
- const ROOT = path.resolve(fileURLToPath(new URL('..', import.meta.url)))
56
- const RESULTS = path.join(ROOT, '.compat-results')
57
- const MATRIX = path.join(RESULTS, 'matrix')
58
- const TGZ_CACHE = path.join(RESULTS, 'host-tgz')
59
- const WIN32 = process.platform === 'win32'
60
- const PNPM = WIN32 ? 'pnpm.cmd' : 'pnpm'
61
- const NPM = WIN32 ? 'npm.cmd' : 'npm'
62
- const INSTALL_ARGS = ['install', '--ignore-scripts', '--prefer-offline', '--loglevel=error']
63
- const REGISTRY = '--registry=https://registry.npmjs.org/'
64
-
65
- /** INDEX §A 铁律:cordis-plugin-* 钉宿主自己的 Cordis 线(映射表与 date-wrapper/paste-dock 执行体一致)。 */
66
- function cordisPin(hostVersion) {
67
- const [triplet] = hostVersion.split('-')
68
- const [maj, min, patch] = triplet.split('.').map(Number)
69
- return [maj, min, patch] >= [0, 1, 7] ? '4.0.4' : '4.0.2'
70
- }
71
- const CORDIS_PLUGIN_PINS = {
72
- '4.0.2': {
73
- '@deepseek-ai/cordis-plugin-group': '1.0.2',
74
- '@deepseek-ai/cordis-plugin-hmr': '1.0.17',
75
- '@deepseek-ai/cordis-plugin-include': '1.0.7',
76
- '@deepseek-ai/cordis-plugin-loader': '1.0.3',
77
- '@deepseek-ai/cordis-plugin-timer': '1.1.4',
78
- },
79
- '4.0.4': {
80
- '@deepseek-ai/cordis-plugin-group': '1.0.4',
81
- '@deepseek-ai/cordis-plugin-hmr': '1.0.19',
82
- '@deepseek-ai/cordis-plugin-include': '1.0.9',
83
- '@deepseek-ai/cordis-plugin-loader': '1.0.5',
84
- '@deepseek-ai/cordis-plugin-timer': '1.1.6',
85
- },
86
- }
87
-
88
- // pnpm 的通配 override 不保证匹配传递依赖;解析每个包时统一官方版本。
89
- function pinHostDependencies(pkg, version) {
90
- const pinned = { ...pkg }
91
- for (const field of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
92
- if (!pkg[field]) continue
93
- pinned[field] = Object.fromEntries(
94
- Object.entries(pkg[field]).map(([name, range]) => [
95
- name,
96
- name === '@deepseek-ai/dsh' || name.startsWith('@deepseek-ai/dsh-') ? version : range,
97
- ]),
98
- )
99
- }
100
- return pinned
101
- }
102
-
103
- const args = process.argv.slice(2)
104
- const only = args.includes('--only') ? args[args.indexOf('--only') + 1] : undefined
105
- const keep = args.includes('--keep')
106
- const force = args.includes('--force')
107
- const bootTimeoutSec = args.includes('--timeout') ? Number(args[args.indexOf('--timeout') + 1]) : 90
108
- const versions = only ? [only] : [...supportedHosts]
109
-
110
- /** 顺序跑外部命令,非零退出/超时均带尾巴抛错。(win32 的 pnpm.cmd 必须经 shell 启动) */
111
- function run(cwd, cmd, cmdArgs, label, limitMs = 15 * 60_000, env = process.env) {
112
- const r = spawnSync(cmd, cmdArgs, { cwd, encoding: 'utf8', shell: WIN32, windowsHide: true, timeout: limitMs, env })
113
- if (r.error?.code === 'ETIMEDOUT' || r.signal === 'SIGTERM') {
114
- throw new Error(`${label} 超时(>${Math.round(limitMs / 60_000)}min)`)
115
- }
116
- if (r.status !== 0) {
117
- throw new Error(
118
- `${label} 失败(exit ${r.status}${r.error ? `,${r.error.code ?? r.error.message}` : ''})\nstdout: ${(r.stdout ?? '').slice(-600)}\nstderr: ${(r.stderr ?? '').slice(-600)}`,
119
- )
120
- }
121
- return r
122
- }
123
-
124
- async function ensureTgz(version) {
125
- await mkdir(TGZ_CACHE, { recursive: true })
126
- const dest = path.join(TGZ_CACHE, `deepseek-ai-dsh-${version}.tgz`)
127
- if (existsSync(dest)) return dest
128
- console.log(` pack host ${version}`)
129
- // npm 而非 pnpm:本仓 pnpm-workspace.yaml 无 packages 字段,pnpm pack 会被
130
- // workspace 解析绊倒(date-wrapper 无此文件故未踩);npm pack 不读 workspace。
131
- await run(TGZ_CACHE, NPM, ['pack', `@deepseek-ai/dsh@${version}`, '--pack-destination', TGZ_CACHE, '--registry=https://registry.npmjs.org/', '--loglevel=error'], `npm pack host ${version}`)
132
- return dest
133
- }
134
-
135
- /** 就绪横幅(宽松:老版本横幅不一定带 dsh 前缀)。 */
136
- const READY_RE = /https?:\/\/(127\.0\.0\.1|localhost):/
137
- const HMR_WALL_RE = /requires the Cordis HMR service/
138
- const COMPAT_BLOCK_RE = /is incompatible with dsh/
139
- const AUDIT_RE = /startup audit|failed to mount|mount error|failed to start/i
140
- const DUP_RE = /already (been )?registered|duplicate|conflict/i
141
- const LOADED_RE = /\[my-plugins\/dsh-tidy-display\] loaded/
142
-
143
- /** 无头启动一次,返回 { outcome, log, child };就绪/退出/超时先到先得。
144
- * 不在此处杀进程:HTTP 探针要在宿主存活窗口内跑(runCell 探完再 stopHost)。 */
145
- async function bootOnce(binJs, cwd, env, extraArgs, timeoutSec) {
146
- const child = spawn(process.execPath, [binJs, ...extraArgs], { cwd, env, windowsHide: true })
147
- let log = ''
148
- child.stdout.on('data', (d) => { log += d })
149
- child.stderr.on('data', (d) => { log += d })
150
- const exited = new Promise((resolve) => child.on('exit', (code) => resolve({ exited: true, code })))
151
- const timer = new Promise((resolve) => setTimeout(() => resolve({ timeout: true }), timeoutSec * 1000))
152
- const ready = (async () => {
153
- while (!READY_RE.test(log)) await new Promise((r) => setTimeout(r, 400))
154
- await new Promise((r) => setTimeout(r, 1200)) // 留给插件挂载/审计日志冲刷
155
- return { ready: true }
156
- })()
157
- const outcome = await Promise.race([exited, timer, ready])
158
- return { outcome, log, child }
159
- }
160
-
161
- /** 杀宿主进程树(win32 用 taskkill /T 连子进程)。 */
162
- async function stopHost(child) {
163
- if (!child || child.exitCode !== null) return
164
- if (WIN32) spawnSync('taskkill', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true })
165
- else child.kill('SIGKILL')
166
- await new Promise((r) => setTimeout(r, 300)) // 杀树后给日志冲刷留时间
167
- }
168
-
169
- /** HTTP 探针:landing 取会话 cookie,打两条插件路由。返回 { checks, errors }。 */
170
- async function probeRoutes(url) {
171
- const checks = {}
172
- const errors = []
173
- const landing = await fetch(url, { redirect: 'manual' })
174
- const cookie = landing.headers
175
- .getSetCookie()
176
- .map((value) => value.split(';')[0])
177
- .join('; ')
178
- const headers = cookie ? { cookie } : {}
179
- try {
180
- const res = await fetch(new URL('/tidy-display/skill-status', url), {
181
- headers, signal: AbortSignal.timeout(20_000),
182
- })
183
- const text = await res.text()
184
- checks.skillStatus = res.status === 200
185
- if (res.status === 200) {
186
- try { checks.skillStatusJson = typeof JSON.parse(text) === 'object' } catch { checks.skillStatusJson = false }
187
- } else {
188
- errors.push(`skill-status ${res.status}: ${text.slice(0, 200)}`)
189
- }
190
- } catch (e) {
191
- checks.skillStatus = false
192
- errors.push(`skill-status fetch: ${String(e?.message ?? e).slice(0, 200)}`)
193
- }
194
- try {
195
- const res = await fetch(new URL('/tidy-display/reveal', url), {
196
- method: 'POST', headers: { ...headers, 'content-type': 'application/json' },
197
- body: JSON.stringify({ path: '' }), signal: AbortSignal.timeout(20_000),
198
- })
199
- const text = await res.text()
200
- checks.revealEmptyPath = res.status === 400 && /Empty path/.test(text)
201
- if (!checks.revealEmptyPath) errors.push(`reveal empty-path ${res.status}: ${text.slice(0, 200)}`)
202
- } catch (e) {
203
- checks.revealEmptyPath = false
204
- errors.push(`reveal fetch: ${String(e?.message ?? e).slice(0, 200)}`)
205
- }
206
- return { checks, errors }
207
- }
208
-
209
- async function runCell(version) {
210
- // 沙箱放系统临时目录(paste-dock 布局),证据目录留在仓内 .compat-results/。
211
- // 教训(2026-10-04 首跑实证):沙箱嵌在仓内时,corepack pnpm 垫片按 cwd 向上
212
- // 走查 packageManager pin 解析到 pnpm 9.x,宿主 CLI 的内部 `pnpm add` 在
213
- // profile workspace 根触发 ERR_PNPM_ADDING_TO_ROOT;TEMP 下无 pin → corepack
214
- // 默认 pnpm 12.x,与 paste-dock 全绿矩阵一致。
215
- const cell = path.join(MATRIX, version)
216
- await mkdir(cell, { recursive: true })
217
- const sandboxRoot = await mkdtemp(path.join(tmpdir(), `dsh-tidy-display-compat-${version}-`))
218
- const sandbox = path.join(sandboxRoot, 'sandbox')
219
- const homeDir = path.join(sandbox, 'home')
220
- const userProfile = path.join(sandbox, 'user')
221
- const workspace = path.join(sandbox, 'workspace')
222
- for (const dir of [sandbox, userProfile, workspace]) await mkdir(dir, { recursive: true })
223
- const env = { ...process.env, DSH_HOME: homeDir, USERPROFILE: userProfile }
224
- const checks = { version, notes: [], sandbox }
225
-
226
- // 1-2. 宿主 tgz + 钉线安装(overrides 钉 cordis 五件套;pnpmfile 钉全部传递 dsh-*)
227
- const hostTgz = await ensureTgz(version)
228
- const cordis = cordisPin(version)
229
- if (!existsSync(path.join(sandbox, 'node_modules', '@deepseek-ai', 'dsh', 'package.json'))) {
230
- await writeFile(path.join(sandbox, 'package.json'), JSON.stringify({
231
- name: 'dsh-host-cell',
232
- private: true,
233
- dependencies: { '@deepseek-ai/dsh': pathToFileURL(hostTgz).href },
234
- }, null, 2))
235
- await writeFile(path.join(sandbox, 'pnpm-workspace.yaml'), `packages:\n - .\nautoInstallPeers: true\nstrictPeerDependencies: false\noverrides:\n${Object.entries({ '@deepseek-ai/cordis': cordis, ...CORDIS_PLUGIN_PINS[cordis] }).map(([n, v]) => ` '${n}': '${v}'`).join('\n')}\n`)
236
- await writeFile(path.join(sandbox, '.pnpmfile.cjs'), `const pinHostDependencies = ${pinHostDependencies.toString()};\nmodule.exports = { hooks: { readPackage: (pkg) => pinHostDependencies(pkg, ${JSON.stringify(version)}) } };\n`, 'utf8')
237
- console.log(` install host ${version}(cordis 线 ${cordis})…`)
238
- const installLog = run(sandbox, PNPM, INSTALL_ARGS, `install host ${version}`)
239
- await writeFile(path.join(cell, 'install.log'), installLog.stdout ?? '')
240
- }
241
- checks.hostInstalled = JSON.parse(await readFile(path.join(sandbox, 'node_modules', '@deepseek-ai', 'dsh', 'package.json'), 'utf8')).version === version
242
- if (!checks.hostInstalled) throw new Error(`宿主安装版本与格子不符: ${version}`)
243
- const binJs = path.join(sandbox, 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js')
244
-
245
- // 3. 打插件包(lib 已入库,pack 无构建;npm pack 理由同 ensureTgz)→ 宿主 CLI 自建 profile 并装入(peer 闸咬合)
246
- await run(ROOT, NPM, ['pack', '--pack-destination', cell, '--loglevel=error'], 'npm pack plugin')
247
- const packed = (await readdir(cell)).find((f) => /^dsh-tidy-display-.*\.tgz$/.test(f))
248
- if (!packed) throw new Error('插件 tgz 打包失败')
249
- const pluginTgz = path.join(cell, packed)
250
- const addRun = spawnSync(process.execPath, [binJs, 'plugin', '--profile', 'web', 'add', pluginTgz, REGISTRY], {
251
- cwd: sandbox, encoding: 'utf8', shell: false, windowsHide: true, timeout: 10 * 60_000, env,
252
- })
253
- const addLog = `${addRun.stdout ?? ''}${addRun.stderr ?? ''}`
254
- await writeFile(path.join(cell, 'plugin-add.log'), addLog)
255
- checks.pluginAdded = addRun.status === 0
256
- if (!checks.pluginAdded) {
257
- if (COMPAT_BLOCK_RE.test(addLog)) {
258
- checks.verdict = 'plugin-blocked'
259
- checks.notes.push('plugin add 阶段 peer 闸拒绝')
260
- await writeResult(cell, checks)
261
- return checks
262
- }
263
- throw new Error(`dsh plugin add 失败(exit ${addRun.status})\n${addLog.slice(-600)}`)
264
- }
265
-
266
- // 4. 引导形态协商:A 形(--port 0 --no-open,0.1.0-rc.8+)→ C 形(裸启动)
267
- const shapes = [
268
- ['A', ['--profile', 'web', '--port', '0', '--no-open']],
269
- ['C', ['--profile', 'web']],
270
- ]
271
- let last = { outcome: {}, log: '', child: undefined }
272
- let shapeUsed
273
- for (const [shape, extra] of shapes) {
274
- last = await bootOnce(binJs, workspace, env, extra, bootTimeoutSec)
275
- shapeUsed = shape
276
- await writeFile(path.join(cell, `boot-${shape}.log`), last.log)
277
- if (last.outcome.ready || HMR_WALL_RE.test(last.log) || COMPAT_BLOCK_RE.test(last.log)) break
278
- await stopHost(last.child)
279
- if (shape === 'C') break
280
- checks.notes.push(`A 形旗标不被 ${version} 接受,回退 C 形`)
281
- }
282
- const bootLog = last.log
283
-
284
- // 5. 归因(日志签名)
285
- checks.booted = Boolean(last.outcome.ready)
286
- checks.bootShape = shapeUsed
287
- if (!checks.booted) {
288
- await stopHost(last.child)
289
- if (HMR_WALL_RE.test(bootLog)) {
290
- checks.verdict = 'host-blocked'
291
- checks.notes.push('宿主 hmr 引导墙(date-wrapper 基座对照亦然)——宿主侧问题,非插件不兼容')
292
- } else if (COMPAT_BLOCK_RE.test(bootLog)) {
293
- checks.verdict = 'plugin-blocked'
294
- checks.notes.push('boot 阶段 peer 闸拦截')
295
- } else {
296
- checks.verdict = 'plugin-blocked'
297
- checks.notes.push(`未就绪且无已知签名(${last.outcome.exited ? `exit ${last.outcome.code}` : '超时'}),见 boot 日志`)
298
- }
299
- await writeResult(cell, checks)
300
- return checks
301
- }
302
- checks.noMountError = !AUDIT_RE.test(bootLog)
303
- checks.noDupContext = !bootLog.split('\n').some((line) => /tidy-display/.test(line) && DUP_RE.test(line))
304
- checks.noCompatBlock = !COMPAT_BLOCK_RE.test(bootLog)
305
- checks.loadedLogPresent = LOADED_RE.test(bootLog)
306
- if (!checks.noMountError) checks.notes.push('挂载/审计错误签名')
307
- if (!checks.noDupContext) checks.notes.push('疑似重名注册签名')
308
- if (!checks.loadedLogPresent) checks.notes.push('宿主日志无插件 apply 正向签名(inject 未满足或挂载失活)')
309
-
310
- // 6. HTTP 探针(宿主存活窗口内:就绪 URL 从横幅取;--port 0 时是随机端口真实地址)
311
- try {
312
- const match = bootLog.match(/http:\/\/(?:127\.0\.0\.1|localhost):\d+/)
313
- if (!match) {
314
- checks.routesProbed = false
315
- checks.notes.push('横幅无可解析 URL,路由探针跳过')
316
- } else {
317
- const { checks: routeChecks, errors } = await probeRoutes(match[0])
318
- Object.assign(checks, routeChecks)
319
- checks.routesProbed = true
320
- if (errors.length) checks.notes.push(...errors)
321
- }
322
- } finally {
323
- await stopHost(last.child)
324
- }
325
-
326
- checks.green =
327
- checks.noMountError && checks.noDupContext && checks.noCompatBlock && checks.loadedLogPresent &&
328
- checks.skillStatus === true && checks.revealEmptyPath === true
329
- checks.verdict = checks.green ? 'green' : 'plugin-blocked'
330
- await writeResult(cell, checks)
331
- return checks
332
- }
333
-
334
- async function writeResult(cell, checks) {
335
- await writeFile(path.join(cell, 'result.json'), JSON.stringify(checks, null, 2) + '\n')
336
- }
337
-
338
- // ── 主流程 ───────────────────────────────────────────────────────────────────
339
- await mkdir(MATRIX, { recursive: true })
340
- const results = []
341
- for (const version of versions) {
342
- const cellResult = path.join(MATRIX, version, 'result.json')
343
- if (!force && existsSync(cellResult)) {
344
- const prev = JSON.parse(await readFile(cellResult, 'utf8'))
345
- if (prev.green || prev.verdict === 'host-blocked') {
346
- console.log(`skip ${version}(已有结论 ${prev.verdict},--force 重跑)`)
347
- results.push(prev)
348
- continue
349
- }
350
- }
351
- process.stdout.write(`cell ${version} … `)
352
- try {
353
- const checks = await runCell(version)
354
- console.log(`${checks.verdict.toUpperCase()}${checks.notes.length ? `(${checks.notes.join(';')})` : ''}`)
355
- results.push(checks)
356
- } catch (error) {
357
- console.log('ERROR')
358
- const checks = { version, verdict: 'error', green: false, error: String(error.message ?? error) }
359
- results.push(checks)
360
- await mkdir(path.join(MATRIX, version), { recursive: true })
361
- await writeResult(path.join(MATRIX, version), checks)
362
- }
363
- // 绿格即弃沙箱;红/错误格保留 TEMP 沙箱供复查(路径在 result.json 的 sandbox 字段)
364
- const last = results.at(-1)
365
- if (last?.green && last.sandbox && !keep) {
366
- await rm(path.dirname(last.sandbox), { recursive: true, force: true, maxRetries: 3, retryDelay: 500 }).catch(() => {})
367
- }
368
- }
369
-
370
- const verified = results.filter((r) => r.green).map((r) => r.version)
371
- const pluginBlocked = results.filter((r) => r.verdict === 'plugin-blocked').map((r) => r.version)
372
- const hostBlocked = results.filter((r) => r.verdict === 'host-blocked').map((r) => r.version)
373
- await writeFile(path.join(RESULTS, 'results.json'), JSON.stringify({ generatedAt: new Date().toISOString(), results }, null, 2) + '\n')
374
- await writeFile(path.join(RESULTS, 'verified.json'), JSON.stringify({ generatedAt: new Date().toISOString(), verified, pluginBlocked, hostBlocked }, null, 2) + '\n')
375
- console.log(`\n绿 ${verified.length}/${results.length}: ${verified.join(', ') || '(无)'}`)
376
- if (pluginBlocked.length) console.log(`插件不兼容 ${pluginBlocked.length}: ${pluginBlocked.join(', ')}`)
377
- if (hostBlocked.length) console.log(`宿主阻塞(不可判定)${hostBlocked.length}: ${hostBlocked.join(', ')}`)
378
- if (!only) console.log('下一步:node scripts/sync-hosts.mjs --write # 把 verified 清单下发七语 README')
1
+ /**
2
+ * test-host-compat.mjs —— 本地隔离矩阵执行体(improve-dsh-plugins/enum-peer-migration
3
+ * /INDEX.md §E:`_wt` 工作树 + 离线 tgz 的 CI 前身)。
4
+ *
5
+ * 骨架沿 dsh-date-wrapper P0 试点定型版;沙箱加固(传递 dsh-* 全量钉版)与
6
+ * HTTP 探针回读沿 dsh-paste-dock 执行体。每格 = 一个宿主 rc:
7
+ * 1. tgz 缓存(`pnpm pack @deepseek-ai/dsh@<version>` → `.compat-results/host-tgz/`);
8
+ * 2. 沙箱安装:宿主 tgz + **钉宿主自己的 Cordis 线**(INDEX §A 铁律:cordis 本体 +
9
+ * group/hmr/include/loader/timer 五件,按宿主线 4.0.2/4.0.4 分档,经
10
+ * pnpm-workspace.yaml overrides)+ `.pnpmfile.cjs` 把全部传递 `@deepseek-ai/dsh*`
11
+ * 钉到宿主版本(防混装)。pnpm `--ignore-scripts`。
12
+ * 3. 插件 tgz(lib/ 已入库,pack 无需构建)经**宿主 CLI 自建 profile** 装入:
13
+ * `dsh plugin --profile web add <tgz>` —— peer 闸(app-boot
14
+ * evaluatePluginCompatibility,逐 dsh-* peer 对宿主运行时版本 semver 匹配)
15
+ * 在这一步咬合,add 日志可判 plugin-blocked。
16
+ * 4. 引导形态协商:A 形 `--profile web --port 0 --no-open`(0.1.0-rc.8+),
17
+ * 老线回退 C 形裸启动(默认端口,可能弹浏览器)。
18
+ * 5. HTTP 探针(带 landing 会话 cookie):
19
+ * GET /tidy-display/skill-status → 200 + JSON(scanGenerativeMcpappsStatus)
20
+ * POST /tidy-display/reveal {path:''} → 400 {ok:false,error:'Empty path'}
21
+ * (空路径探针不弹资源管理器窗口,纯语义验证路由与 handler 挂载)
22
+ * 6. 日志断言:正向签名 `[my-plugins/dsh-tidy-display] loaded`;反向签名
23
+ * 挂载/审计/重名/兼容拦截。
24
+ *
25
+ * 指纹门禁说明:本插件 18 文件哈希基线针对宿主 **monorepo 源码**,npm 发布包只带
26
+ * lib/ 无 src/ ——矩阵格无法从沙箱采集指纹(需逐版本 monorepo 检出,CI 化事项)。
27
+ * 故本执行体以**行为冒烟**为验收(spec §6 口径:指纹回答"宿主改没改",冒烟回答
28
+ * "插件还能不能用")。
29
+ *
30
+ * 归因(日志签名):
31
+ * - ready + 探针全过 + 无签名 → green
32
+ * - /requires the Cordis HMR service/ → host-blocked(宿主引导墙,非插件问题)
33
+ * - /is incompatible with dsh/(add 或 boot)→ plugin-blocked(peer 闸拒入/拒挂)
34
+ * - 挂载/审计/重名签名 → plugin-blocked(notes 注明)
35
+ *
36
+ * 产物:`.compat-results/<version>/{install.log, plugin-add.log, boot-<X>.log,
37
+ * result.json}` + 汇总 `results.json` + 绿名单 `verified.json`
38
+ * (sync-hosts.mjs 据此写 README 的 Runtime-verified 行)。沙箱在系统临时目录:
39
+ * 绿格即弃,红/错误格保留(路径见 result.json 的 sandbox 字段,--keep 全留)。
40
+ *
41
+ * 用法:
42
+ * node scripts/test-host-compat.mjs # 全量(hosts.mjs 枚举)
43
+ * node scripts/test-host-compat.mjs --only 0.2.0-rc.2 # 单格复跑
44
+ * node scripts/test-host-compat.mjs --keep # 全部保留 sandbox 便于复查
45
+ * node scripts/test-host-compat.mjs --force # 忽略已有结论强制重跑
46
+ */
47
+ import { spawn, spawnSync } from 'node:child_process'
48
+ import { existsSync } from 'node:fs'
49
+ import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises'
50
+ import { tmpdir } from 'node:os'
51
+ import path from 'node:path'
52
+ import { fileURLToPath, pathToFileURL } from 'node:url'
53
+ import { supportedHosts } from './hosts.mjs'
54
+
55
+ const ROOT = path.resolve(fileURLToPath(new URL('..', import.meta.url)))
56
+ const RESULTS = path.join(ROOT, '.compat-results')
57
+ const MATRIX = path.join(RESULTS, 'matrix')
58
+ const TGZ_CACHE = path.join(RESULTS, 'host-tgz')
59
+ const WIN32 = process.platform === 'win32'
60
+ const PNPM = WIN32 ? 'pnpm.cmd' : 'pnpm'
61
+ const NPM = WIN32 ? 'npm.cmd' : 'npm'
62
+ const INSTALL_ARGS = ['install', '--ignore-scripts', '--prefer-offline', '--loglevel=error']
63
+ const REGISTRY = '--registry=https://registry.npmjs.org/'
64
+
65
+ /** INDEX §A 铁律:cordis-plugin-* 钉宿主自己的 Cordis 线(映射表与 date-wrapper/paste-dock 执行体一致)。 */
66
+ function cordisPin(hostVersion) {
67
+ const [triplet] = hostVersion.split('-')
68
+ const [maj, min, patch] = triplet.split('.').map(Number)
69
+ return [maj, min, patch] >= [0, 1, 7] ? '4.0.4' : '4.0.2'
70
+ }
71
+ const CORDIS_PLUGIN_PINS = {
72
+ '4.0.2': {
73
+ '@deepseek-ai/cordis-plugin-group': '1.0.2',
74
+ '@deepseek-ai/cordis-plugin-hmr': '1.0.17',
75
+ '@deepseek-ai/cordis-plugin-include': '1.0.7',
76
+ '@deepseek-ai/cordis-plugin-loader': '1.0.3',
77
+ '@deepseek-ai/cordis-plugin-timer': '1.1.4',
78
+ },
79
+ '4.0.4': {
80
+ '@deepseek-ai/cordis-plugin-group': '1.0.4',
81
+ '@deepseek-ai/cordis-plugin-hmr': '1.0.19',
82
+ '@deepseek-ai/cordis-plugin-include': '1.0.9',
83
+ '@deepseek-ai/cordis-plugin-loader': '1.0.5',
84
+ '@deepseek-ai/cordis-plugin-timer': '1.1.6',
85
+ },
86
+ }
87
+
88
+ // pnpm 的通配 override 不保证匹配传递依赖;解析每个包时统一官方版本。
89
+ function pinHostDependencies(pkg, version) {
90
+ const pinned = { ...pkg }
91
+ for (const field of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
92
+ if (!pkg[field]) continue
93
+ pinned[field] = Object.fromEntries(
94
+ Object.entries(pkg[field]).map(([name, range]) => [
95
+ name,
96
+ name === '@deepseek-ai/dsh' || name.startsWith('@deepseek-ai/dsh-') ? version : range,
97
+ ]),
98
+ )
99
+ }
100
+ return pinned
101
+ }
102
+
103
+ const args = process.argv.slice(2)
104
+ const only = args.includes('--only') ? args[args.indexOf('--only') + 1] : undefined
105
+ const keep = args.includes('--keep')
106
+ const force = args.includes('--force')
107
+ const bootTimeoutSec = args.includes('--timeout') ? Number(args[args.indexOf('--timeout') + 1]) : 90
108
+ const versions = only ? [only] : [...supportedHosts]
109
+
110
+ /** 顺序跑外部命令,非零退出/超时均带尾巴抛错。(win32 的 pnpm.cmd 必须经 shell 启动) */
111
+ function run(cwd, cmd, cmdArgs, label, limitMs = 15 * 60_000, env = process.env) {
112
+ const r = spawnSync(cmd, cmdArgs, { cwd, encoding: 'utf8', shell: WIN32, windowsHide: true, timeout: limitMs, env })
113
+ if (r.error?.code === 'ETIMEDOUT' || r.signal === 'SIGTERM') {
114
+ throw new Error(`${label} 超时(>${Math.round(limitMs / 60_000)}min)`)
115
+ }
116
+ if (r.status !== 0) {
117
+ throw new Error(
118
+ `${label} 失败(exit ${r.status}${r.error ? `,${r.error.code ?? r.error.message}` : ''})\nstdout: ${(r.stdout ?? '').slice(-600)}\nstderr: ${(r.stderr ?? '').slice(-600)}`,
119
+ )
120
+ }
121
+ return r
122
+ }
123
+
124
+ async function ensureTgz(version) {
125
+ await mkdir(TGZ_CACHE, { recursive: true })
126
+ const dest = path.join(TGZ_CACHE, `deepseek-ai-dsh-${version}.tgz`)
127
+ if (existsSync(dest)) return dest
128
+ console.log(` pack host ${version}`)
129
+ // npm 而非 pnpm:本仓 pnpm-workspace.yaml 无 packages 字段,pnpm pack 会被
130
+ // workspace 解析绊倒(date-wrapper 无此文件故未踩);npm pack 不读 workspace。
131
+ await run(TGZ_CACHE, NPM, ['pack', `@deepseek-ai/dsh@${version}`, '--pack-destination', TGZ_CACHE, '--registry=https://registry.npmjs.org/', '--loglevel=error'], `npm pack host ${version}`)
132
+ return dest
133
+ }
134
+
135
+ /** 就绪横幅(宽松:老版本横幅不一定带 dsh 前缀)。 */
136
+ const READY_RE = /https?:\/\/(127\.0\.0\.1|localhost):/
137
+ const HMR_WALL_RE = /requires the Cordis HMR service/
138
+ const COMPAT_BLOCK_RE = /is incompatible with dsh/
139
+ const AUDIT_RE = /startup audit|failed to mount|mount error|failed to start/i
140
+ const DUP_RE = /already (been )?registered|duplicate|conflict/i
141
+ const LOADED_RE = /\[my-plugins\/dsh-tidy-display\] loaded/
142
+
143
+ /** 无头启动一次,返回 { outcome, log, child };就绪/退出/超时先到先得。
144
+ * 不在此处杀进程:HTTP 探针要在宿主存活窗口内跑(runCell 探完再 stopHost)。 */
145
+ async function bootOnce(binJs, cwd, env, extraArgs, timeoutSec) {
146
+ const child = spawn(process.execPath, [binJs, ...extraArgs], { cwd, env, windowsHide: true })
147
+ let log = ''
148
+ child.stdout.on('data', (d) => { log += d })
149
+ child.stderr.on('data', (d) => { log += d })
150
+ const exited = new Promise((resolve) => child.on('exit', (code) => resolve({ exited: true, code })))
151
+ const timer = new Promise((resolve) => setTimeout(() => resolve({ timeout: true }), timeoutSec * 1000))
152
+ const ready = (async () => {
153
+ while (!READY_RE.test(log)) await new Promise((r) => setTimeout(r, 400))
154
+ await new Promise((r) => setTimeout(r, 1200)) // 留给插件挂载/审计日志冲刷
155
+ return { ready: true }
156
+ })()
157
+ const outcome = await Promise.race([exited, timer, ready])
158
+ return { outcome, log, child }
159
+ }
160
+
161
+ /** 杀宿主进程树(win32 用 taskkill /T 连子进程)。 */
162
+ async function stopHost(child) {
163
+ if (!child || child.exitCode !== null) return
164
+ if (WIN32) spawnSync('taskkill', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true })
165
+ else child.kill('SIGKILL')
166
+ await new Promise((r) => setTimeout(r, 300)) // 杀树后给日志冲刷留时间
167
+ }
168
+
169
+ /** HTTP 探针:landing 取会话 cookie,打两条插件路由。返回 { checks, errors }。 */
170
+ async function probeRoutes(url) {
171
+ const checks = {}
172
+ const errors = []
173
+ const landing = await fetch(url, { redirect: 'manual' })
174
+ const cookie = landing.headers
175
+ .getSetCookie()
176
+ .map((value) => value.split(';')[0])
177
+ .join('; ')
178
+ const headers = cookie ? { cookie } : {}
179
+ try {
180
+ const res = await fetch(new URL('/tidy-display/skill-status', url), {
181
+ headers, signal: AbortSignal.timeout(20_000),
182
+ })
183
+ const text = await res.text()
184
+ checks.skillStatus = res.status === 200
185
+ if (res.status === 200) {
186
+ try { checks.skillStatusJson = typeof JSON.parse(text) === 'object' } catch { checks.skillStatusJson = false }
187
+ } else {
188
+ errors.push(`skill-status ${res.status}: ${text.slice(0, 200)}`)
189
+ }
190
+ } catch (e) {
191
+ checks.skillStatus = false
192
+ errors.push(`skill-status fetch: ${String(e?.message ?? e).slice(0, 200)}`)
193
+ }
194
+ try {
195
+ const res = await fetch(new URL('/tidy-display/reveal', url), {
196
+ method: 'POST', headers: { ...headers, 'content-type': 'application/json' },
197
+ body: JSON.stringify({ path: '' }), signal: AbortSignal.timeout(20_000),
198
+ })
199
+ const text = await res.text()
200
+ checks.revealEmptyPath = res.status === 400 && /Empty path/.test(text)
201
+ if (!checks.revealEmptyPath) errors.push(`reveal empty-path ${res.status}: ${text.slice(0, 200)}`)
202
+ } catch (e) {
203
+ checks.revealEmptyPath = false
204
+ errors.push(`reveal fetch: ${String(e?.message ?? e).slice(0, 200)}`)
205
+ }
206
+ return { checks, errors }
207
+ }
208
+
209
+ async function runCell(version) {
210
+ // 沙箱放系统临时目录(paste-dock 布局),证据目录留在仓内 .compat-results/。
211
+ // 教训(2026-10-04 首跑实证):沙箱嵌在仓内时,corepack pnpm 垫片按 cwd 向上
212
+ // 走查 packageManager pin 解析到 pnpm 9.x,宿主 CLI 的内部 `pnpm add` 在
213
+ // profile workspace 根触发 ERR_PNPM_ADDING_TO_ROOT;TEMP 下无 pin → corepack
214
+ // 默认 pnpm 12.x,与 paste-dock 全绿矩阵一致。
215
+ const cell = path.join(MATRIX, version)
216
+ await mkdir(cell, { recursive: true })
217
+ const sandboxRoot = await mkdtemp(path.join(tmpdir(), `dsh-tidy-display-compat-${version}-`))
218
+ const sandbox = path.join(sandboxRoot, 'sandbox')
219
+ const homeDir = path.join(sandbox, 'home')
220
+ const userProfile = path.join(sandbox, 'user')
221
+ const workspace = path.join(sandbox, 'workspace')
222
+ for (const dir of [sandbox, userProfile, workspace]) await mkdir(dir, { recursive: true })
223
+ const env = { ...process.env, DSH_HOME: homeDir, USERPROFILE: userProfile }
224
+ const checks = { version, notes: [], sandbox }
225
+
226
+ // 1-2. 宿主 tgz + 钉线安装(overrides 钉 cordis 五件套;pnpmfile 钉全部传递 dsh-*)
227
+ const hostTgz = await ensureTgz(version)
228
+ const cordis = cordisPin(version)
229
+ if (!existsSync(path.join(sandbox, 'node_modules', '@deepseek-ai', 'dsh', 'package.json'))) {
230
+ await writeFile(path.join(sandbox, 'package.json'), JSON.stringify({
231
+ name: 'dsh-host-cell',
232
+ private: true,
233
+ dependencies: { '@deepseek-ai/dsh': pathToFileURL(hostTgz).href },
234
+ }, null, 2))
235
+ await writeFile(path.join(sandbox, 'pnpm-workspace.yaml'), `packages:\n - .\nautoInstallPeers: true\nstrictPeerDependencies: false\noverrides:\n${Object.entries({ '@deepseek-ai/cordis': cordis, ...CORDIS_PLUGIN_PINS[cordis] }).map(([n, v]) => ` '${n}': '${v}'`).join('\n')}\n`)
236
+ await writeFile(path.join(sandbox, '.pnpmfile.cjs'), `const pinHostDependencies = ${pinHostDependencies.toString()};\nmodule.exports = { hooks: { readPackage: (pkg) => pinHostDependencies(pkg, ${JSON.stringify(version)}) } };\n`, 'utf8')
237
+ console.log(` install host ${version}(cordis 线 ${cordis})…`)
238
+ const installLog = run(sandbox, PNPM, INSTALL_ARGS, `install host ${version}`)
239
+ await writeFile(path.join(cell, 'install.log'), installLog.stdout ?? '')
240
+ }
241
+ checks.hostInstalled = JSON.parse(await readFile(path.join(sandbox, 'node_modules', '@deepseek-ai', 'dsh', 'package.json'), 'utf8')).version === version
242
+ if (!checks.hostInstalled) throw new Error(`宿主安装版本与格子不符: ${version}`)
243
+ const binJs = path.join(sandbox, 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js')
244
+
245
+ // 3. 打插件包(lib 已入库,pack 无构建;npm pack 理由同 ensureTgz)→ 宿主 CLI 自建 profile 并装入(peer 闸咬合)
246
+ await run(ROOT, NPM, ['pack', '--pack-destination', cell, '--loglevel=error'], 'npm pack plugin')
247
+ const packed = (await readdir(cell)).find((f) => /^dsh-tidy-display-.*\.tgz$/.test(f))
248
+ if (!packed) throw new Error('插件 tgz 打包失败')
249
+ const pluginTgz = path.join(cell, packed)
250
+ const addRun = spawnSync(process.execPath, [binJs, 'plugin', '--profile', 'web', 'add', pluginTgz, REGISTRY], {
251
+ cwd: sandbox, encoding: 'utf8', shell: false, windowsHide: true, timeout: 10 * 60_000, env,
252
+ })
253
+ const addLog = `${addRun.stdout ?? ''}${addRun.stderr ?? ''}`
254
+ await writeFile(path.join(cell, 'plugin-add.log'), addLog)
255
+ checks.pluginAdded = addRun.status === 0
256
+ if (!checks.pluginAdded) {
257
+ if (COMPAT_BLOCK_RE.test(addLog)) {
258
+ checks.verdict = 'plugin-blocked'
259
+ checks.notes.push('plugin add 阶段 peer 闸拒绝')
260
+ await writeResult(cell, checks)
261
+ return checks
262
+ }
263
+ throw new Error(`dsh plugin add 失败(exit ${addRun.status})\n${addLog.slice(-600)}`)
264
+ }
265
+
266
+ // 4. 引导形态协商:A 形(--port 0 --no-open,0.1.0-rc.8+)→ C 形(裸启动)
267
+ const shapes = [
268
+ ['A', ['--profile', 'web', '--port', '0', '--no-open']],
269
+ ['C', ['--profile', 'web']],
270
+ ]
271
+ let last = { outcome: {}, log: '', child: undefined }
272
+ let shapeUsed
273
+ for (const [shape, extra] of shapes) {
274
+ last = await bootOnce(binJs, workspace, env, extra, bootTimeoutSec)
275
+ shapeUsed = shape
276
+ await writeFile(path.join(cell, `boot-${shape}.log`), last.log)
277
+ if (last.outcome.ready || HMR_WALL_RE.test(last.log) || COMPAT_BLOCK_RE.test(last.log)) break
278
+ await stopHost(last.child)
279
+ if (shape === 'C') break
280
+ checks.notes.push(`A 形旗标不被 ${version} 接受,回退 C 形`)
281
+ }
282
+ const bootLog = last.log
283
+
284
+ // 5. 归因(日志签名)
285
+ checks.booted = Boolean(last.outcome.ready)
286
+ checks.bootShape = shapeUsed
287
+ if (!checks.booted) {
288
+ await stopHost(last.child)
289
+ if (HMR_WALL_RE.test(bootLog)) {
290
+ checks.verdict = 'host-blocked'
291
+ checks.notes.push('宿主 hmr 引导墙(date-wrapper 基座对照亦然)——宿主侧问题,非插件不兼容')
292
+ } else if (COMPAT_BLOCK_RE.test(bootLog)) {
293
+ checks.verdict = 'plugin-blocked'
294
+ checks.notes.push('boot 阶段 peer 闸拦截')
295
+ } else {
296
+ checks.verdict = 'plugin-blocked'
297
+ checks.notes.push(`未就绪且无已知签名(${last.outcome.exited ? `exit ${last.outcome.code}` : '超时'}),见 boot 日志`)
298
+ }
299
+ await writeResult(cell, checks)
300
+ return checks
301
+ }
302
+ checks.noMountError = !AUDIT_RE.test(bootLog)
303
+ checks.noDupContext = !bootLog.split('\n').some((line) => /tidy-display/.test(line) && DUP_RE.test(line))
304
+ checks.noCompatBlock = !COMPAT_BLOCK_RE.test(bootLog)
305
+ checks.loadedLogPresent = LOADED_RE.test(bootLog)
306
+ if (!checks.noMountError) checks.notes.push('挂载/审计错误签名')
307
+ if (!checks.noDupContext) checks.notes.push('疑似重名注册签名')
308
+ if (!checks.loadedLogPresent) checks.notes.push('宿主日志无插件 apply 正向签名(inject 未满足或挂载失活)')
309
+
310
+ // 6. HTTP 探针(宿主存活窗口内:就绪 URL 从横幅取;--port 0 时是随机端口真实地址)
311
+ try {
312
+ const match = bootLog.match(/http:\/\/(?:127\.0\.0\.1|localhost):\d+/)
313
+ if (!match) {
314
+ checks.routesProbed = false
315
+ checks.notes.push('横幅无可解析 URL,路由探针跳过')
316
+ } else {
317
+ const { checks: routeChecks, errors } = await probeRoutes(match[0])
318
+ Object.assign(checks, routeChecks)
319
+ checks.routesProbed = true
320
+ if (errors.length) checks.notes.push(...errors)
321
+ }
322
+ } finally {
323
+ await stopHost(last.child)
324
+ }
325
+
326
+ checks.green =
327
+ checks.noMountError && checks.noDupContext && checks.noCompatBlock && checks.loadedLogPresent &&
328
+ checks.skillStatus === true && checks.revealEmptyPath === true
329
+ checks.verdict = checks.green ? 'green' : 'plugin-blocked'
330
+ await writeResult(cell, checks)
331
+ return checks
332
+ }
333
+
334
+ async function writeResult(cell, checks) {
335
+ await writeFile(path.join(cell, 'result.json'), JSON.stringify(checks, null, 2) + '\n')
336
+ }
337
+
338
+ // ── 主流程 ───────────────────────────────────────────────────────────────────
339
+ await mkdir(MATRIX, { recursive: true })
340
+ const results = []
341
+ for (const version of versions) {
342
+ const cellResult = path.join(MATRIX, version, 'result.json')
343
+ if (!force && existsSync(cellResult)) {
344
+ const prev = JSON.parse(await readFile(cellResult, 'utf8'))
345
+ if (prev.green || prev.verdict === 'host-blocked') {
346
+ console.log(`skip ${version}(已有结论 ${prev.verdict},--force 重跑)`)
347
+ results.push(prev)
348
+ continue
349
+ }
350
+ }
351
+ process.stdout.write(`cell ${version} … `)
352
+ try {
353
+ const checks = await runCell(version)
354
+ console.log(`${checks.verdict.toUpperCase()}${checks.notes.length ? `(${checks.notes.join(';')})` : ''}`)
355
+ results.push(checks)
356
+ } catch (error) {
357
+ console.log('ERROR')
358
+ const checks = { version, verdict: 'error', green: false, error: String(error.message ?? error) }
359
+ results.push(checks)
360
+ await mkdir(path.join(MATRIX, version), { recursive: true })
361
+ await writeResult(path.join(MATRIX, version), checks)
362
+ }
363
+ // 绿格即弃沙箱;红/错误格保留 TEMP 沙箱供复查(路径在 result.json 的 sandbox 字段)
364
+ const last = results.at(-1)
365
+ if (last?.green && last.sandbox && !keep) {
366
+ await rm(path.dirname(last.sandbox), { recursive: true, force: true, maxRetries: 3, retryDelay: 500 }).catch(() => {})
367
+ }
368
+ }
369
+
370
+ const verified = results.filter((r) => r.green).map((r) => r.version)
371
+ const pluginBlocked = results.filter((r) => r.verdict === 'plugin-blocked').map((r) => r.version)
372
+ const hostBlocked = results.filter((r) => r.verdict === 'host-blocked').map((r) => r.version)
373
+ await writeFile(path.join(RESULTS, 'results.json'), JSON.stringify({ generatedAt: new Date().toISOString(), results }, null, 2) + '\n')
374
+ await writeFile(path.join(RESULTS, 'verified.json'), JSON.stringify({ generatedAt: new Date().toISOString(), verified, pluginBlocked, hostBlocked }, null, 2) + '\n')
375
+ console.log(`\n绿 ${verified.length}/${results.length}: ${verified.join(', ') || '(无)'}`)
376
+ if (pluginBlocked.length) console.log(`插件不兼容 ${pluginBlocked.length}: ${pluginBlocked.join(', ')}`)
377
+ if (hostBlocked.length) console.log(`宿主阻塞(不可判定)${hostBlocked.length}: ${hostBlocked.join(', ')}`)
378
+ if (!only) console.log('下一步:node scripts/sync-hosts.mjs --write # 把 verified 清单下发七语 README')