pi-web-ui 0.114.1 → 0.114.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 (117) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +187 -187
  3. package/README.zh-CN.md +227 -227
  4. package/README.zh-TW.md +227 -227
  5. package/bin/device-hub-cli.mjs +577 -577
  6. package/bin/frp-manager.mjs +1573 -1573
  7. package/bin/pi-device-hub.mjs +9 -9
  8. package/bin/pi-web-ui.mjs +4081 -4081
  9. package/deploy/nginx-subpath.conf +100 -100
  10. package/deploy/pi-web-ui.service +36 -36
  11. package/dist/server/agent-service.js +59 -10
  12. package/dist/server/attachments.js +6 -6
  13. package/dist/server/canvas/canvas-orchestrator.js +3 -3
  14. package/dist/server/communicate-tool.js +37 -11
  15. package/dist/server/compaction-instructions.js +8 -8
  16. package/dist/server/device-center/desktop-page.js +228 -228
  17. package/dist/server/device-center/hub-page.js +64 -64
  18. package/dist/server/device-center/native-desktop/macos.js +190 -190
  19. package/dist/server/device-center/native-desktop/windows.js +116 -116
  20. package/dist/server/dsh/runtime/cordis.yml +1 -1
  21. package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
  22. package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
  23. package/dist/server/dsh/runtime/launcher.mjs +235 -235
  24. package/dist/server/dsh/runtime/override.patch.yml +89 -89
  25. package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
  26. package/dist/server/durable/durable-event-projector.js +19 -3
  27. package/dist/server/durable/durable-models.js +134 -65
  28. package/dist/server/eval-tool.js +135 -135
  29. package/dist/server/model-resolver.js +4 -1
  30. package/dist/server/patch-bash-process.js +89 -89
  31. package/dist/server/patch-tool.js +9 -9
  32. package/dist/server/patch-turn-end-boundary.js +3 -3
  33. package/dist/server/persona-chain.js +8 -8
  34. package/dist/server/remote-ssh-service.js +39 -39
  35. package/dist/server/schedule-agent-tool.js +11 -6
  36. package/dist/server/scheduler-tasks.js +84 -2
  37. package/dist/server/scm-commitmsg.js +10 -10
  38. package/dist/server/setup-page.js +620 -620
  39. package/dist/server/universal/universal-session.js +19 -18
  40. package/dist/server/vision-bridge.js +18 -18
  41. package/docs/device-center.md +148 -148
  42. package/docs/device-desktop.md +48 -48
  43. package/docs/dsh-engine.md +493 -493
  44. package/extensions/webui.ts +335 -335
  45. package/package.json +1 -1
  46. package/plugin-sdk/README.md +174 -174
  47. package/plugin-sdk/client-utils.mjs +279 -279
  48. package/plugin-sdk/import-check.mjs +210 -210
  49. package/plugin-sdk/index.d.ts +698 -698
  50. package/plugin-sdk/index.mjs +696 -696
  51. package/plugin-sdk/package.json +13 -13
  52. package/plugin-sdk/ssh-host-trust.mjs +225 -225
  53. package/themes/aetheris.css +501 -501
  54. package/themes/ayu-light.css +116 -116
  55. package/themes/bases/flow-base.css +1357 -1357
  56. package/themes/bases/obsidian-base.css +895 -895
  57. package/themes/bases/statusbar-flat-base.css +112 -112
  58. package/themes/bases/zhujian-base.css +688 -688
  59. package/themes/bases/zhupi-base.css +660 -660
  60. package/themes/catppuccin-latte.css +119 -119
  61. package/themes/catppuccin.css +116 -116
  62. package/themes/claude-code-dark.css +147 -147
  63. package/themes/codex.css +114 -114
  64. package/themes/cyberpunk.css +50 -50
  65. package/themes/dark-teal.css +264 -264
  66. package/themes/dazzle.css +38 -38
  67. package/themes/everforest-light.css +115 -115
  68. package/themes/flow-light.css +164 -164
  69. package/themes/flow.css +161 -161
  70. package/themes/geist.css +114 -114
  71. package/themes/gruvbox-light.css +115 -115
  72. package/themes/kanagawa-lotus.css +115 -115
  73. package/themes/md-preview.css +24 -24
  74. package/themes/mist.css +166 -166
  75. package/themes/nord.css +107 -107
  76. package/themes/one-dark.css +106 -106
  77. package/themes/paper.css +174 -174
  78. package/themes/rose-pine-dawn.css +114 -114
  79. package/themes/sakura.css +166 -166
  80. package/themes/solarized-light.css +114 -114
  81. package/themes/tokyo-night.css +115 -115
  82. package/themes/translucent.css +85 -85
  83. package/themes/transparent.css +116 -116
  84. package/themes/vs-code-dark.css +147 -147
  85. package/themes/wallpaper-flow.css +382 -382
  86. package/themes/wallpaper-obsidian.css +74 -74
  87. package/themes/white.css +164 -164
  88. package/themes/zhujian-dark.css +115 -115
  89. package/themes/zhujian.css +114 -114
  90. package/themes/zhupi-dark.css +115 -115
  91. package/themes/zhupi.css +114 -114
  92. package/web/dist/.build-assets.json +1 -1
  93. package/web/dist/assets/{BgTasksModal-BcXJ20RO.js → BgTasksModal-BIlQ89vr.js} +1 -1
  94. package/web/dist/assets/{BgTasksModal-DjQmiKnE.js → BgTasksModal-Ck2sjlPM.js} +1 -1
  95. package/web/dist/assets/{CanvasStudio-PI9pid0Y.js → CanvasStudio-B3W6b_rA.js} +1 -1
  96. package/web/dist/assets/{CanvasStudio-nf5-HxLM.js → CanvasStudio-Csv1Sj1-.js} +1 -1
  97. package/web/dist/assets/{DeviceCenter-CYttJw2a.js → DeviceCenter-BQdDcO8A.js} +1 -1
  98. package/web/dist/assets/{DeviceCenter-DPe4sz74.js → DeviceCenter-CHRKL0Vy.js} +1 -1
  99. package/web/dist/assets/{FilePreview-C9Ut4Lq6.js → FilePreview-B9xoU6ON.js} +1 -1
  100. package/web/dist/assets/{FilePreview-CvK3ZzX5.js → FilePreview-DUQpVZkH.js} +1 -1
  101. package/web/dist/assets/{GlobalSearchModal-C5e-OCw2.js → GlobalSearchModal-BXEGvUZq.js} +1 -1
  102. package/web/dist/assets/{GlobalSearchModal-H7pFK2UC.js → GlobalSearchModal-CnVPmfOI.js} +1 -1
  103. package/web/dist/assets/{GroupConversation-C2wNM0dQ.js → GroupConversation-CyIpQzDd.js} +1 -1
  104. package/web/dist/assets/{GroupConversation-ChN3TWQK.js → GroupConversation-DgYV3uYS.js} +1 -1
  105. package/web/dist/assets/{SCMPanel-buTGziDB.js → SCMPanel-imYI2Ecw.js} +1 -1
  106. package/web/dist/assets/{SCMPanel-kx-SCL2s.js → SCMPanel-sVZcV7dR.js} +1 -1
  107. package/web/dist/assets/{SettingsModal-BsUF8jqr.js → SettingsModal-Xw1Yoi3_.js} +1 -1
  108. package/web/dist/assets/{SettingsModal-D357Ky7P.js → SettingsModal-mb4e34-0.js} +1 -1
  109. package/web/dist/assets/{TerminalPanel-BBuM_Sez.js → TerminalPanel-CLkJJvxg.js} +1 -1
  110. package/web/dist/assets/{TerminalPanel-D6x6xz8Q.js → TerminalPanel-DpcIellm.js} +1 -1
  111. package/web/dist/assets/{TuiOverlayModal-CdbGV3Za.js → TuiOverlayModal-4-fFAZe7.js} +1 -1
  112. package/web/dist/assets/{TuiOverlayModal-d6x9u25n.js → TuiOverlayModal-DCu01lks.js} +1 -1
  113. package/web/dist/assets/{index-D6u8xH0o.js → index-Cdh3sibd.js} +4 -4
  114. package/web/dist/assets/{index-BPvpea8t.js → index-DWw_SxRq.js} +4 -4
  115. package/web/dist/index.html +29 -29
  116. package/web/dist/sw.js +179 -179
  117. package/web/public/sw.js +179 -179
@@ -1,210 +1,210 @@
1
- /**
2
- * import-check.mjs — 插件目录的静态 import 自检(纯 ESM、零依赖)。
3
- *
4
- * 为什么需要:宿主**只暴露 `/plugins/<id>/client/*`**(`server/plugins.ts` 的
5
- * `resolvePluginClientFile` 把根钉在 `client/`)。客户端代码里任何解析到 `client/`
6
- * 之外的相对 import,浏览器都会以
7
- *
8
- * Failed to fetch dynamically imported module: /plugins/<id>/client/entry.mjs
9
- *
10
- * 整体失败(**bundle 一行都不执行**,不是只坏那一条 import),而服务端完全看不出来
11
- * —— manifest 校验 0 错、插件 `active:true`、`error:null`(issue #546)。
12
- *
13
- * 脚手架(`pi-web-ui plugin create`)生成后用它自检;插件作者也可以对自己的插件跑一遍:
14
- *
15
- * node --input-type=module -e "const m = await import('./sdk/import-check.mjs');
16
- * console.log(m.checkPluginImports(process.cwd()))"
17
- *
18
- * 只做**字面量**匹配(静态 import/export-from + `import("...")` 字面量),不引 AST 依赖:
19
- * 插件代码的 import 目标都是字符串字面量,够用且零成本。注释里的示例代码先被词法扫描
20
- * 屏蔽(不是真 import),模板字面量内的 import 不识别(要引依赖请在顶层静态写)。
21
- */
22
- import { readdirSync, readFileSync, statSync } from "node:fs";
23
- import { join, relative, resolve, sep } from "node:path";
24
-
25
- /** 扫描的源码扩展名。 */
26
- const SCAN_EXT = [".mjs", ".js"];
27
- /** 不进入的目录(依赖/版本库)。 */
28
- const SKIP_DIRS = new Set(["node_modules", ".git"]);
29
-
30
- /** 静态 import / export-from / 字面量动态 import 的目标(作用在屏蔽过注释的骨架上)。 */
31
- const SPEC_PATTERNS = [
32
- /(?:^|[\s;{}()])import\s+[^;'"`]*?from\s*["'](S\d+)["']/g, // import x from "S0" / import { y } from "S0"
33
- /(?:^|[\s;{}()])export\s+[^;'"`]*?from\s*["'](S\d+)["']/g, // export { x } from "S0" / export * from "S0"
34
- /(?:^|[\s;{}()])import\s*["'](S\d+)["']/g, // 副作用 import "S0"
35
- /(?:^|[\s;{}()])import\s*\(\s*["'](S\d+)["']/g, // import("S0")
36
- ];
37
-
38
- /**
39
- * 极简词法扫描:把注释抹成空白、把字符串/模板字面量换成占位符 `S<n>`(引号保留),
40
- * 返回 `{ skeleton, literals }`。这样后续正则只在真代码上匹配,且能从占位符取回原文
41
- * —— 注释里的 `import ... from "..."`(SDK 文件头就是这种示例)不会被误判成真依赖。
42
- */
43
- function skeletonize(src) {
44
- const out = [];
45
- const literals = [];
46
- let mode = "code";
47
- let i = 0;
48
- while (i < src.length) {
49
- const c = src[i];
50
- if (mode === "code") {
51
- if (c === "/" && src[i + 1] === "/") {
52
- mode = "line";
53
- out.push(" ", " ");
54
- i += 2;
55
- continue;
56
- }
57
- if (c === "/" && src[i + 1] === "*") {
58
- mode = "block";
59
- out.push(" ", " ");
60
- i += 2;
61
- continue;
62
- }
63
- if (c === '"' || c === "'" || c === "`") {
64
- let j = i + 1;
65
- let buf = "";
66
- while (j < src.length) {
67
- if (src[j] === "\\") {
68
- buf += src[j + 1] ?? "";
69
- j += 2;
70
- continue;
71
- }
72
- if (src[j] === c) break;
73
- buf += src[j];
74
- j++;
75
- }
76
- const id = literals.push(buf) - 1;
77
- out.push(c, `S${id}`, c);
78
- i = j + 1;
79
- continue;
80
- }
81
- out.push(c);
82
- i++;
83
- continue;
84
- }
85
- if (mode === "line") {
86
- if (c === "\n") {
87
- mode = "code";
88
- out.push("\n");
89
- } else out.push(" ");
90
- i++;
91
- continue;
92
- }
93
- // block comment
94
- if (c === "*" && src[i + 1] === "/") {
95
- mode = "code";
96
- out.push(" ", " ");
97
- i += 2;
98
- continue;
99
- }
100
- out.push(c === "\n" ? "\n" : " ");
101
- i++;
102
- }
103
- return { skeleton: out.join(""), literals };
104
- }
105
-
106
- /** 提取源码里的 import 目标(去重、保序;注释里的示例不算)。 */
107
- export function staticImportSpecifiers(src) {
108
- const { skeleton, literals } = skeletonize(src);
109
- const out = [];
110
- const seen = new Set();
111
- for (const re of SPEC_PATTERNS) {
112
- re.lastIndex = 0;
113
- let m;
114
- while ((m = re.exec(skeleton)) !== null) {
115
- const spec = literals[Number(m[1].slice(1))];
116
- if (spec === undefined || spec === "" || seen.has(spec)) continue;
117
- seen.add(spec);
118
- out.push(spec);
119
- }
120
- }
121
- return out;
122
- }
123
-
124
- /** 递归列出目录里待扫描的模块(相对 root 的 posix 路径,排序稳定)。 */
125
- export function listPluginModules(root) {
126
- const out = [];
127
- const walk = (dir) => {
128
- let entries;
129
- try {
130
- entries = readdirSync(dir, { withFileTypes: true });
131
- } catch {
132
- return;
133
- }
134
- for (const e of entries) {
135
- if (e.isDirectory()) {
136
- if (!SKIP_DIRS.has(e.name)) walk(join(dir, e.name));
137
- continue;
138
- }
139
- if (e.isFile() && SCAN_EXT.some((ext) => e.name.endsWith(ext)))
140
- out.push(relative(root, join(dir, e.name)).split(sep).join("/"));
141
- }
142
- };
143
- walk(root);
144
- return out.sort();
145
- }
146
-
147
- /** 是否为「相对路径 import」(`./x`、`../x`);裸包名、`node:`、URL 都不算。 */
148
- function isRelativeSpec(spec) {
149
- return spec.startsWith("./") || spec.startsWith("../");
150
- }
151
-
152
- /**
153
- * 扫整个插件目录的相对 import(其余 specifier 原样跳过)。
154
- *
155
- * 返回 `[{ file, spec, target, missing, client, escapesClient }]`:
156
- * - `file` / `target` 都是相对 root 的 posix 路径(跨平台稳定;target 已去 query/hash)
157
- * - `client`:import 的发起方位于 `client/` 内
158
- * - `escapesClient`:`client/` 内的文件 import 到了 `client/` 之外 —— 浏览器必然加载失败
159
- * - `missing`:目标文件不存在(拼错 / 忘拷依赖,如 `sdk/index.mjs` re-export 的
160
- * `client-utils.mjs` —— 少它连服务端 `import()` 都会 ERR_MODULE_NOT_FOUND)
161
- */
162
- export function scanPluginImports(root) {
163
- const clientRoot = resolve(root, "client");
164
- const rows = [];
165
- for (const file of listPluginModules(root)) {
166
- let src;
167
- try {
168
- src = readFileSync(join(root, file), "utf8");
169
- } catch {
170
- continue;
171
- }
172
- const absFile = resolve(root, file);
173
- const isClient = absFile === clientRoot || absFile.startsWith(clientRoot + sep);
174
- for (const spec of staticImportSpecifiers(src)) {
175
- if (!isRelativeSpec(spec)) continue;
176
- const abs = resolve(resolve(absFile, ".."), spec.replace(/[?#].*$/, ""));
177
- let missing = true;
178
- try {
179
- missing = !statSync(abs).isFile();
180
- } catch {
181
- missing = true;
182
- }
183
- rows.push({
184
- file,
185
- spec,
186
- target: relative(root, abs).split(sep).join("/"),
187
- missing,
188
- client: isClient,
189
- escapesClient: isClient && abs !== clientRoot && !abs.startsWith(clientRoot + sep),
190
- });
191
- }
192
- }
193
- return rows;
194
- }
195
-
196
- /**
197
- * 自检结论:`{ scanned, problems }`。`kind` 为 `"escapes-client"`(客户端越界,打不开
198
- * 插件页的致命伤)或 `"missing"`(目标不存在);越界排前面。
199
- */
200
- export function checkPluginImports(root) {
201
- const scanned = listPluginModules(root);
202
- const problems = [];
203
- for (const row of scanPluginImports(root)) {
204
- if (row.escapesClient)
205
- problems.push({ kind: "escapes-client", file: row.file, spec: row.spec, target: row.target });
206
- else if (row.missing) problems.push({ kind: "missing", file: row.file, spec: row.spec, target: row.target });
207
- }
208
- const rank = (p) => (p.kind === "escapes-client" ? 0 : 1);
209
- return { scanned, problems: problems.sort((a, b) => rank(a) - rank(b)) };
210
- }
1
+ /**
2
+ * import-check.mjs — 插件目录的静态 import 自检(纯 ESM、零依赖)。
3
+ *
4
+ * 为什么需要:宿主**只暴露 `/plugins/<id>/client/*`**(`server/plugins.ts` 的
5
+ * `resolvePluginClientFile` 把根钉在 `client/`)。客户端代码里任何解析到 `client/`
6
+ * 之外的相对 import,浏览器都会以
7
+ *
8
+ * Failed to fetch dynamically imported module: /plugins/<id>/client/entry.mjs
9
+ *
10
+ * 整体失败(**bundle 一行都不执行**,不是只坏那一条 import),而服务端完全看不出来
11
+ * —— manifest 校验 0 错、插件 `active:true`、`error:null`(issue #546)。
12
+ *
13
+ * 脚手架(`pi-web-ui plugin create`)生成后用它自检;插件作者也可以对自己的插件跑一遍:
14
+ *
15
+ * node --input-type=module -e "const m = await import('./sdk/import-check.mjs');
16
+ * console.log(m.checkPluginImports(process.cwd()))"
17
+ *
18
+ * 只做**字面量**匹配(静态 import/export-from + `import("...")` 字面量),不引 AST 依赖:
19
+ * 插件代码的 import 目标都是字符串字面量,够用且零成本。注释里的示例代码先被词法扫描
20
+ * 屏蔽(不是真 import),模板字面量内的 import 不识别(要引依赖请在顶层静态写)。
21
+ */
22
+ import { readdirSync, readFileSync, statSync } from "node:fs";
23
+ import { join, relative, resolve, sep } from "node:path";
24
+
25
+ /** 扫描的源码扩展名。 */
26
+ const SCAN_EXT = [".mjs", ".js"];
27
+ /** 不进入的目录(依赖/版本库)。 */
28
+ const SKIP_DIRS = new Set(["node_modules", ".git"]);
29
+
30
+ /** 静态 import / export-from / 字面量动态 import 的目标(作用在屏蔽过注释的骨架上)。 */
31
+ const SPEC_PATTERNS = [
32
+ /(?:^|[\s;{}()])import\s+[^;'"`]*?from\s*["'](S\d+)["']/g, // import x from "S0" / import { y } from "S0"
33
+ /(?:^|[\s;{}()])export\s+[^;'"`]*?from\s*["'](S\d+)["']/g, // export { x } from "S0" / export * from "S0"
34
+ /(?:^|[\s;{}()])import\s*["'](S\d+)["']/g, // 副作用 import "S0"
35
+ /(?:^|[\s;{}()])import\s*\(\s*["'](S\d+)["']/g, // import("S0")
36
+ ];
37
+
38
+ /**
39
+ * 极简词法扫描:把注释抹成空白、把字符串/模板字面量换成占位符 `S<n>`(引号保留),
40
+ * 返回 `{ skeleton, literals }`。这样后续正则只在真代码上匹配,且能从占位符取回原文
41
+ * —— 注释里的 `import ... from "..."`(SDK 文件头就是这种示例)不会被误判成真依赖。
42
+ */
43
+ function skeletonize(src) {
44
+ const out = [];
45
+ const literals = [];
46
+ let mode = "code";
47
+ let i = 0;
48
+ while (i < src.length) {
49
+ const c = src[i];
50
+ if (mode === "code") {
51
+ if (c === "/" && src[i + 1] === "/") {
52
+ mode = "line";
53
+ out.push(" ", " ");
54
+ i += 2;
55
+ continue;
56
+ }
57
+ if (c === "/" && src[i + 1] === "*") {
58
+ mode = "block";
59
+ out.push(" ", " ");
60
+ i += 2;
61
+ continue;
62
+ }
63
+ if (c === '"' || c === "'" || c === "`") {
64
+ let j = i + 1;
65
+ let buf = "";
66
+ while (j < src.length) {
67
+ if (src[j] === "\\") {
68
+ buf += src[j + 1] ?? "";
69
+ j += 2;
70
+ continue;
71
+ }
72
+ if (src[j] === c) break;
73
+ buf += src[j];
74
+ j++;
75
+ }
76
+ const id = literals.push(buf) - 1;
77
+ out.push(c, `S${id}`, c);
78
+ i = j + 1;
79
+ continue;
80
+ }
81
+ out.push(c);
82
+ i++;
83
+ continue;
84
+ }
85
+ if (mode === "line") {
86
+ if (c === "\n") {
87
+ mode = "code";
88
+ out.push("\n");
89
+ } else out.push(" ");
90
+ i++;
91
+ continue;
92
+ }
93
+ // block comment
94
+ if (c === "*" && src[i + 1] === "/") {
95
+ mode = "code";
96
+ out.push(" ", " ");
97
+ i += 2;
98
+ continue;
99
+ }
100
+ out.push(c === "\n" ? "\n" : " ");
101
+ i++;
102
+ }
103
+ return { skeleton: out.join(""), literals };
104
+ }
105
+
106
+ /** 提取源码里的 import 目标(去重、保序;注释里的示例不算)。 */
107
+ export function staticImportSpecifiers(src) {
108
+ const { skeleton, literals } = skeletonize(src);
109
+ const out = [];
110
+ const seen = new Set();
111
+ for (const re of SPEC_PATTERNS) {
112
+ re.lastIndex = 0;
113
+ let m;
114
+ while ((m = re.exec(skeleton)) !== null) {
115
+ const spec = literals[Number(m[1].slice(1))];
116
+ if (spec === undefined || spec === "" || seen.has(spec)) continue;
117
+ seen.add(spec);
118
+ out.push(spec);
119
+ }
120
+ }
121
+ return out;
122
+ }
123
+
124
+ /** 递归列出目录里待扫描的模块(相对 root 的 posix 路径,排序稳定)。 */
125
+ export function listPluginModules(root) {
126
+ const out = [];
127
+ const walk = (dir) => {
128
+ let entries;
129
+ try {
130
+ entries = readdirSync(dir, { withFileTypes: true });
131
+ } catch {
132
+ return;
133
+ }
134
+ for (const e of entries) {
135
+ if (e.isDirectory()) {
136
+ if (!SKIP_DIRS.has(e.name)) walk(join(dir, e.name));
137
+ continue;
138
+ }
139
+ if (e.isFile() && SCAN_EXT.some((ext) => e.name.endsWith(ext)))
140
+ out.push(relative(root, join(dir, e.name)).split(sep).join("/"));
141
+ }
142
+ };
143
+ walk(root);
144
+ return out.sort();
145
+ }
146
+
147
+ /** 是否为「相对路径 import」(`./x`、`../x`);裸包名、`node:`、URL 都不算。 */
148
+ function isRelativeSpec(spec) {
149
+ return spec.startsWith("./") || spec.startsWith("../");
150
+ }
151
+
152
+ /**
153
+ * 扫整个插件目录的相对 import(其余 specifier 原样跳过)。
154
+ *
155
+ * 返回 `[{ file, spec, target, missing, client, escapesClient }]`:
156
+ * - `file` / `target` 都是相对 root 的 posix 路径(跨平台稳定;target 已去 query/hash)
157
+ * - `client`:import 的发起方位于 `client/` 内
158
+ * - `escapesClient`:`client/` 内的文件 import 到了 `client/` 之外 —— 浏览器必然加载失败
159
+ * - `missing`:目标文件不存在(拼错 / 忘拷依赖,如 `sdk/index.mjs` re-export 的
160
+ * `client-utils.mjs` —— 少它连服务端 `import()` 都会 ERR_MODULE_NOT_FOUND)
161
+ */
162
+ export function scanPluginImports(root) {
163
+ const clientRoot = resolve(root, "client");
164
+ const rows = [];
165
+ for (const file of listPluginModules(root)) {
166
+ let src;
167
+ try {
168
+ src = readFileSync(join(root, file), "utf8");
169
+ } catch {
170
+ continue;
171
+ }
172
+ const absFile = resolve(root, file);
173
+ const isClient = absFile === clientRoot || absFile.startsWith(clientRoot + sep);
174
+ for (const spec of staticImportSpecifiers(src)) {
175
+ if (!isRelativeSpec(spec)) continue;
176
+ const abs = resolve(resolve(absFile, ".."), spec.replace(/[?#].*$/, ""));
177
+ let missing = true;
178
+ try {
179
+ missing = !statSync(abs).isFile();
180
+ } catch {
181
+ missing = true;
182
+ }
183
+ rows.push({
184
+ file,
185
+ spec,
186
+ target: relative(root, abs).split(sep).join("/"),
187
+ missing,
188
+ client: isClient,
189
+ escapesClient: isClient && abs !== clientRoot && !abs.startsWith(clientRoot + sep),
190
+ });
191
+ }
192
+ }
193
+ return rows;
194
+ }
195
+
196
+ /**
197
+ * 自检结论:`{ scanned, problems }`。`kind` 为 `"escapes-client"`(客户端越界,打不开
198
+ * 插件页的致命伤)或 `"missing"`(目标不存在);越界排前面。
199
+ */
200
+ export function checkPluginImports(root) {
201
+ const scanned = listPluginModules(root);
202
+ const problems = [];
203
+ for (const row of scanPluginImports(root)) {
204
+ if (row.escapesClient)
205
+ problems.push({ kind: "escapes-client", file: row.file, spec: row.spec, target: row.target });
206
+ else if (row.missing) problems.push({ kind: "missing", file: row.file, spec: row.spec, target: row.target });
207
+ }
208
+ const rank = (p) => (p.kind === "escapes-client" ? 0 : 1);
209
+ return { scanned, problems: problems.sort((a, b) => rank(a) - rank(b)) };
210
+ }