feat: 视觉能力去 Electron 化,经 HostBridge.screen 注入(迁移阶段1-A9)

- HostBridge 新增可选 screen 服务(listDisplays/primaryDisplay/dipToScreenPoint/
  displayMatching/captureDisplay),vision 3 处、cv-vision 2 处动态 import(electron)
  全部改为 requireScreenService();未注入时抛稳定的 host_unavailable
- demo 宿主 src/main/index.ts 用 desktopCapturer/screen 实现 screen 服务
- check-deps.mjs 升级:新增动态 import()/require() 扫描(旧正则实测 0 命中的盲区),
  合成用例验证命中,升级后真实源码 0 违规
- 包依赖闭包:补声明 @cantoo/pdf-lib、@napi-rs/canvas、pdfjs-dist
- cv-vision 测试从 vi.mock(electron) 改为宿主桥注入,11/11 通过
This commit is contained in:
yu committed 2026-11-06 10:53:42 +08:00
1 parent 1da00827ac
commit 1a20dd72d1
7 files changed
+161 -62

No files matched your search

+15
View File
@@ -18,6 +18,10 @@ const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..")
const srcRoot = path.join(pkgRoot, "src");
const IMPORT_RE = /(?:import|export)\s+(?:[\s\S]*?from\s*)?["']([^"']+)["']/g;
// 动态形式:import("x") / require("x") / createRequire 后的 require 调用。
// 旧正则要求 import 后跟空白,`import("electron")` 完全不匹配(实测 0 命中,
// vision/cv-vision 曾靠这个盲区逃过检查——迁移阶段1-A9 修复)。
const DYNAMIC_IMPORT_RE = /(?:\bimport\s*\(|\brequire\s*\()\s*["']([^"']+)["']/g;
async function walk(dir) {
const entries = await readdir(dir, { withFileTypes: true });
@@ -53,6 +57,17 @@ for (const file of await walk(srcRoot)) {
}
}
}
for (const match of source.matchAll(DYNAMIC_IMPORT_RE)) {
const spec = match[1];
const rel = path.relative(pkgRoot, file).replaceAll("\\", "/");
if (spec === "electron" || spec.startsWith("electron/")) {
offenders.push(`${rel}: 禁止动态 import("${spec}")(宿主能力走 HostBridge 注入)`);
continue;
}
if (spec.includes("src/main")) {
offenders.push(`${rel}: 禁止动态引用宿主模块 "${spec}"`);
}
}
}
if (offenders.length) {