@moonquake2004/dsh-doctor 0.4.31 → 0.4.32
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/dsh-doctor.mjs +131 -19
- package/package.json +1 -1
package/dsh-doctor.mjs
CHANGED
|
@@ -690,6 +690,110 @@ function checkProfile(name) {
|
|
|
690
690
|
}
|
|
691
691
|
}
|
|
692
692
|
|
|
693
|
+
// P20 / P21:第三方插件把整棵插件树拖垮的两种**静态可判**形态(社区 #6693 实测)
|
|
694
|
+
// 报告者在 host 侧 `apply()` 里连续撞了两个独立致命错、client 侧撞了两个静默白屏错;
|
|
695
|
+
// 其核心抱怨是"唯一的诊断入口被故障本身摧毁"。这两条都不需要执行插件代码即可判定。
|
|
696
|
+
{
|
|
697
|
+
const pkgDirs19 = listProfilePackages(dir);
|
|
698
|
+
// 收集 client 产物(三种真实布局,与 dsh-security SP7 的收集口径一致)
|
|
699
|
+
const clientFiles = [];
|
|
700
|
+
const hostFiles = [];
|
|
701
|
+
const MAX_PER_PKG = 8;
|
|
702
|
+
for (const { dir: pkgDir } of pkgDirs19) {
|
|
703
|
+
const push = (arr, f) => { if (arr.length < MAX_PER_PKG && existsSync(f) && /\.(js|mjs|cjs)$/.test(f)) arr.push(f); };
|
|
704
|
+
const clientDir = join(pkgDir, 'client');
|
|
705
|
+
if (existsSync(clientDir)) {
|
|
706
|
+
try { for (const e of readdirSync(clientDir, { withFileTypes: true })) if (e.isFile()) push(clientFiles, join(clientDir, e.name)); } catch { /* 不可读 */ }
|
|
707
|
+
}
|
|
708
|
+
push(clientFiles, join(pkgDir, 'lib', 'client.js'));
|
|
709
|
+
push(clientFiles, join(pkgDir, 'client.js'));
|
|
710
|
+
let mf = null;
|
|
711
|
+
try { mf = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8')); } catch { /* 跳过 */ }
|
|
712
|
+
const mainRel = typeof mf?.main === 'string' ? mf.main : (typeof mf?.exports === 'string' ? mf.exports : null);
|
|
713
|
+
if (mainRel) push(hostFiles, join(pkgDir, mainRel));
|
|
714
|
+
push(hostFiles, join(pkgDir, 'lib', 'index.js'));
|
|
715
|
+
push(hostFiles, join(pkgDir, 'index.js'));
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// P20:client 产物必须是 `__ModuleLoader__.load({ id, factory })` 的 CJS 工厂。
|
|
719
|
+
// 写成裸 ESM(顶层 export/import)会在浏览器抛 `Unexpected token 'export'` 而**服务端零痕迹**——
|
|
720
|
+
// 注意:`node --check` 抓不到它,因为那是**合法 ESM 语法**(dsh-security SP7 用的是 --check)。
|
|
721
|
+
const p20 = [];
|
|
722
|
+
let p20scanned = 0;
|
|
723
|
+
for (const f of clientFiles) {
|
|
724
|
+
let text; try { text = readFileSync(f, 'utf8'); } catch { continue; }
|
|
725
|
+
p20scanned++;
|
|
726
|
+
const hasFactory = /__ModuleLoader__\s*\.\s*load\s*\(/.test(text);
|
|
727
|
+
const topLevelEsm = /^\s*(export\s|import\s)/m.test(text);
|
|
728
|
+
if (hasFactory) continue;
|
|
729
|
+
if (topLevelEsm) p20.push(`${f.split('/node_modules/')[1] || f}(未见 __ModuleLoader__.load,且有顶层 export/import)`);
|
|
730
|
+
}
|
|
731
|
+
if (!p20scanned) reportSkip('profile', 'P20', '未发现 client 产物,跳过加载格式检查');
|
|
732
|
+
else if (p20.length) {
|
|
733
|
+
report('profile', 'P20', false,
|
|
734
|
+
`client 产物不是 CJS 工厂(${p20.length}/${p20scanned} 个):\n ${p20.slice(0, 5).join('\n ')}\n`
|
|
735
|
+
+ ` —— 浏览器会抛 \`Uncaught SyntaxError: Unexpected token 'export'\`,**服务端日志里出现 0 次**:`
|
|
736
|
+
+ `systemd 健康、端口在听、页面永远空白(#6693 实测:整份 journal 里该错误计数为 0)`,
|
|
737
|
+
'把 client 半边改成 `__ModuleLoader__.load({ id, factory })` 的 CJS 工厂形态(参照 dsh-better-sidebar / dsh-dream-skin)');
|
|
738
|
+
} else {
|
|
739
|
+
report('profile', 'P20', true, `client 产物均为 CJS 工厂形态(${p20scanned} 个)`);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// P21:**沙箱专属符号在普通插件里不存在**(host 与 client 两侧一律如此,同一根因两个面)
|
|
743
|
+
// host 侧:裸 `harness` → ReferenceError: harness is not defined(#6693 规则 2,出现 55 次)
|
|
744
|
+
// client 侧:`styles` / `ctx.get('host')` 等同样拿不到(#6693 规则 4)
|
|
745
|
+
// 判据保守:文件里**完全没有** `typeof <symbol>` 守卫才报(有守卫则只提示——词法上无法证明守卫顺序,
|
|
746
|
+
// 而报告者特别指出 `harness.handle && …` 这种写法挡不住:裸标识符在 `&&` 短路之前就被解析)。
|
|
747
|
+
const p21 = [];
|
|
748
|
+
const notes21 = [];
|
|
749
|
+
// 匹配前的净化(两轮实测教训,都是真实 profile 上的误报):
|
|
750
|
+
// 1) `//#region styles` 这类**注释**区域标记会被当成裸引用(6 处全是它);
|
|
751
|
+
// 2) `"deepseek-harness"` / `/api/harness/connector/stream` 这类**字符串**同理(3 处全是它)。
|
|
752
|
+
// 故:剥注释 + 剥字符串字面量(近似,不处理转义/嵌套模板)+ 要求符号处于**代码位置**
|
|
753
|
+
// (后跟 `.` / `[` / `(` —— 真正使用一个全局必然如此)+ 若文件本地声明了同名变量则不算。
|
|
754
|
+
const stripAll = (t) => t
|
|
755
|
+
.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
|
756
|
+
.replace(/(^|[^:])\/\/[^\n]*/g, '$1 ')
|
|
757
|
+
.replace(/'(?:[^'\\\n]|\\.)*'/g, ' ')
|
|
758
|
+
.replace(/"(?:[^"\\\n]|\\.)*"/g, ' ')
|
|
759
|
+
.replace(/`(?:[^`\\]|\\.)*`/g, ' ');
|
|
760
|
+
const scan = (files, symbols, side) => {
|
|
761
|
+
for (const f of files) {
|
|
762
|
+
let text; try { text = stripAll(readFileSync(f, 'utf8')); } catch { continue; }
|
|
763
|
+
const rel = f.split('/node_modules/')[1] || f;
|
|
764
|
+
for (const sym of symbols) {
|
|
765
|
+
const useRe = new RegExp(`(^|[^\\w.$])\\b${sym}\\b\\s*[.[(]`, 'm');
|
|
766
|
+
if (!useRe.test(text)) continue;
|
|
767
|
+
const declared = new RegExp(`\\b(?:const|let|var|function|class)\\s+${sym}\\b|[{,]\\s*${sym}\\s*[,}]`).test(text);
|
|
768
|
+
if (declared) continue; // 本地声明同名变量 → 不是沙箱符号
|
|
769
|
+
const guarded = new RegExp(`typeof\\s+${sym}\\b`).test(text);
|
|
770
|
+
if (guarded) { notes21.push(`${rel}: 引用 ${sym}(同文件有 typeof 守卫,但词法上无法证明守卫顺序)`); continue; }
|
|
771
|
+
p21.push(`${rel}(${side}): 裸引用沙箱专属符号 \`${sym}\``);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
scan(hostFiles, ['harness'], 'host');
|
|
776
|
+
scan(clientFiles, ['harness', 'styles'], 'client');
|
|
777
|
+
// client 侧还常通过 ctx.get('host'/'styles') 取沙箱服务
|
|
778
|
+
for (const f of clientFiles) {
|
|
779
|
+
let text; try { text = stripAll(readFileSync(f, 'utf8')); } catch { continue; }
|
|
780
|
+
const m = /ctx\.get\(\s*['"](host|styles)['"]/.exec(text);
|
|
781
|
+
if (m) p21.push(`${f.split('/node_modules/')[1] || f}(client): ctx.get('${m[1]}') —— 沙箱宿主专属服务,常驻 bundle 里拿不到`);
|
|
782
|
+
}
|
|
783
|
+
if (p21.length) {
|
|
784
|
+
report('profile', 'P21', false,
|
|
785
|
+
`插件的 host/client 半边引用了**沙箱专属符号**(${p21.length} 处)——这类符号在从 node_modules 加载的普通插件里一律不存在:\n `
|
|
786
|
+
+ p21.slice(0, 6).join('\n ')
|
|
787
|
+
+ (p21.length > 6 ? `\n …另有 ${p21.length - 6} 处` : '')
|
|
788
|
+
+ `\n host 侧表现为 \`ReferenceError: harness is not defined\`(在 \`apply()\` 内同步抛出 → cordis 中断装载链 → Web UI 整体不可用)`,
|
|
789
|
+
'移除这些引用或用宿主提供的等价能力;若确需守卫,必须写成 `typeof X !== \"undefined\"` **放在最前**——`X.foo && …` 挡不住(裸标识符先被解析)');
|
|
790
|
+
} else if (notes21.length) {
|
|
791
|
+
report('profile', 'P21', true, `未见裸引用沙箱专属符号(${notes21.length} 处有 typeof 守卫,未计入)`);
|
|
792
|
+
} else {
|
|
793
|
+
report('profile', 'P21', true, `扫描 ${hostFiles.length} 个 host 入口与 ${clientFiles.length} 个 client 产物,未见沙箱专属符号引用`);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
693
797
|
// P19:插件声明的 host peer 范围 vs 实际提供的 host 版本(社区 #6678 @ciceroyang 提案)
|
|
694
798
|
// 这是"升级后起不来"的常见原因之一:插件声明只支持某段 core 版本,而实际装的核心已在区间外,
|
|
695
799
|
// 安装时却没有任何警告(#6680 的机制:profile 的 pnpm 配置 autoInstallPeers:false 且 host 由
|
|
@@ -698,24 +802,7 @@ function checkProfile(name) {
|
|
|
698
802
|
const findings19 = [];
|
|
699
803
|
let unknown19 = 0;
|
|
700
804
|
let checked19 = 0;
|
|
701
|
-
|
|
702
|
-
// 只看 isDirectory 会漏掉它们,这正是社区提醒的坑)
|
|
703
|
-
const pkgDirs19 = [];
|
|
704
|
-
try {
|
|
705
|
-
for (const e of readdirSync(join(dir, 'node_modules'), { withFileTypes: true })) {
|
|
706
|
-
if (!e.name || e.name.startsWith('.') || e.name === '.bin') continue;
|
|
707
|
-
if (e.name.startsWith('@')) {
|
|
708
|
-
try {
|
|
709
|
-
for (const sub of readdirSync(join(dir, 'node_modules', e.name), { withFileTypes: true })) {
|
|
710
|
-
if (!sub.name || sub.name.startsWith('.')) continue;
|
|
711
|
-
if (sub.isDirectory() || sub.isSymbolicLink()) pkgDirs19.push({ name: `${e.name}/${sub.name}`, dir: join(dir, 'node_modules', e.name, sub.name) });
|
|
712
|
-
}
|
|
713
|
-
} catch { /* 跳过不可读 scope */ }
|
|
714
|
-
} else if (e.isDirectory() || e.isSymbolicLink()) {
|
|
715
|
-
pkgDirs19.push({ name: e.name, dir: join(dir, 'node_modules', e.name) });
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
} catch { /* 无 node_modules */ }
|
|
805
|
+
const pkgDirs19 = listProfilePackages(dir);
|
|
719
806
|
for (const { name: pkgName, dir: pkgDir } of pkgDirs19) {
|
|
720
807
|
let mf;
|
|
721
808
|
try { mf = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8')); } catch { continue; }
|
|
@@ -1875,7 +1962,10 @@ catalogSeverity.set('P15', 'error');
|
|
|
1875
1962
|
catalogSeverity.set('P16', 'warn');
|
|
1876
1963
|
catalogSeverity.set('P17', 'warn');
|
|
1877
1964
|
catalogSeverity.set('P18', 'warn');
|
|
1878
|
-
catalogSeverity.set('P19', 'warn');
|
|
1965
|
+
catalogSeverity.set('P19', 'warn');
|
|
1966
|
+
catalogSeverity.set('P20', 'warn'); // #6693:client 格式问题在浏览器才炸,服务端零痕迹——高价值提示但不阻断 CI
|
|
1967
|
+
// P21 不设 warn:它是在 apply() 内**同步抛出**、直接中断整棵装载链的致命类(#6693 实测 195+55 次),
|
|
1968
|
+
// 且我们两轮去误报(注释/字符串)后在真实 profile 的 8 个 host 入口 + 8 个 client 产物上零误报,故按 error 处理。 // #6678:声明不匹配是风险信号而非确定失败,提示但不阻断 // #6667:条件性风险(需游离本地模块才触发),提示但不翻退出码
|
|
1879
1969
|
|
|
1880
1970
|
function bundledCatalog() {
|
|
1881
1971
|
const p = new URL('./checks.json', import.meta.url);
|
|
@@ -2332,6 +2422,28 @@ function resolveHostVersion(profileDir, name) {
|
|
|
2332
2422
|
* 注意:--boot-check 会**执行插件顶层代码**(这正是"启动"本身的语义),故为显式开关、非默认行为。
|
|
2333
2423
|
*/
|
|
2334
2424
|
|
|
2425
|
+
/** 枚举 profile node_modules 里的包(含 scoped)。**跟随软链接**——pnpm 与 file:/dev 安装都是软链接,
|
|
2426
|
+
* 只看 isDirectory() 会漏掉它们(社区 #6678 提醒的坑)。P19/P20/P21 共用。 */
|
|
2427
|
+
function listProfilePackages(profileDir) {
|
|
2428
|
+
const out = [];
|
|
2429
|
+
try {
|
|
2430
|
+
for (const e of readdirSync(join(profileDir, 'node_modules'), { withFileTypes: true })) {
|
|
2431
|
+
if (!e.name || e.name.startsWith('.') || e.name === '.bin') continue;
|
|
2432
|
+
if (e.name.startsWith('@')) {
|
|
2433
|
+
try {
|
|
2434
|
+
for (const sub of readdirSync(join(profileDir, 'node_modules', e.name), { withFileTypes: true })) {
|
|
2435
|
+
if (!sub.name || sub.name.startsWith('.')) continue;
|
|
2436
|
+
if (sub.isDirectory() || sub.isSymbolicLink()) out.push({ name: `${e.name}/${sub.name}`, dir: join(profileDir, 'node_modules', e.name, sub.name) });
|
|
2437
|
+
}
|
|
2438
|
+
} catch { /* 跳过不可读 scope */ }
|
|
2439
|
+
} else if (e.isDirectory() || e.isSymbolicLink()) {
|
|
2440
|
+
out.push({ name: e.name, dir: join(profileDir, 'node_modules', e.name) });
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
} catch { /* 无 node_modules */ }
|
|
2444
|
+
return out;
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2335
2447
|
/** 解析 profile 的启动列表与各 bundle 的 entry(含用户 patch 的 insert),跳过 disabled 与已隔离项。 */
|
|
2336
2448
|
function collectBootEntries(profileDir) {
|
|
2337
2449
|
const manifest = JSON.parse(readFileSync(join(profileDir, 'package.json'), 'utf8'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonquake2004/dsh-doctor",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.32",
|
|
4
4
|
"description": "Offline diagnostic for DeepSeek Harness — 28 built-in + 5 catalog checks across env/profile/session (Layer A checks-as-data), self-update (Layer B), and a semi-automatic LLM observer (Layer C, --observe); Doctor panel in web UI settings.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|