dsh-git-push 0.0.0-stage → 2.8.4
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/.auditignore +30 -0
- package/.gitignore +39 -0
- package/LICENSE +21 -0
- package/README.md +1482 -2
- package/cli.mjs +360 -0
- package/cordis.patch.yml +14 -0
- package/lib/ARCHITECTURE.md +34 -0
- package/lib/BUGFIX-NOTES-2026-09-14.md +278 -0
- package/lib/app/apply.js +275 -0
- package/lib/app/audit-api.js +158 -0
- package/lib/app/command-registry.js +262 -0
- package/lib/app/constants.js +16 -0
- package/lib/app/handlers/account.js +166 -0
- package/lib/app/handlers/clone.js +168 -0
- package/lib/app/handlers/http-constants.js +9 -0
- package/lib/app/handlers/identity-rewrite.js +94 -0
- package/lib/app/handlers/meta.js +175 -0
- package/lib/app/handlers/npm.js +169 -0
- package/lib/app/handlers/repo-actions.js +143 -0
- package/lib/app/handlers/repos.js +231 -0
- package/lib/app/handlers/settings.js +62 -0
- package/lib/app/host-doc-checks.js +25 -0
- package/lib/app/http-handlers.js +131 -0
- package/lib/app/index.js +30 -0
- package/lib/app/inject-text.js +191 -0
- package/lib/app/scan-root.js +23 -0
- package/lib/app/schema.js +150 -0
- package/lib/app/settings-bridge.js +167 -0
- package/lib/app/slash-commands.js +395 -0
- package/lib/app/slot-stats.js +35 -0
- package/lib/app/tool-call.js +662 -0
- package/lib/app/tools.js +40 -0
- package/lib/ast/brace.js +105 -0
- package/lib/ast/callgraph.js +135 -0
- package/lib/ast/code-lines.js +114 -0
- package/lib/ast/consts.js +12 -0
- package/lib/ast/control-flow.js +461 -0
- package/lib/ast/credential.js +199 -0
- package/lib/ast/dataflow.js +274 -0
- package/lib/ast/dup-code.js +165 -0
- package/lib/ast/index.js +36 -0
- package/lib/ast/io-risk-const.js +95 -0
- package/lib/ast/io-risk-fn.js +208 -0
- package/lib/ast/io-risk-loop.js +308 -0
- package/lib/ast/io-risk.js +314 -0
- package/lib/ast/lang.js +156 -0
- package/lib/ast/line-count.js +52 -0
- package/lib/ast/magic-number.js +272 -0
- package/lib/ast/naming.js +284 -0
- package/lib/ast/perf.js +472 -0
- package/lib/ast/scope.js +241 -0
- package/lib/ast/shell.js +131 -0
- package/lib/ast/size.js +378 -0
- package/lib/ast/symbol-index.js +399 -0
- package/lib/ast/tokenizer.js +341 -0
- package/lib/audit/analysis-coverage.js +98 -0
- package/lib/audit/audit-file.js +182 -0
- package/lib/audit/checks.js +17 -0
- package/lib/audit/client-entry.js +93 -0
- package/lib/audit/collector.js +477 -0
- package/lib/audit/ext-runner.js +80 -0
- package/lib/audit/file-context.js +138 -0
- package/lib/audit/finding.js +50 -0
- package/lib/audit/gitignore-match.js +113 -0
- package/lib/audit/glob.js +63 -0
- package/lib/audit/history-report.js +100 -0
- package/lib/audit/history.js +126 -0
- package/lib/audit/ignore-blind.js +101 -0
- package/lib/audit/index.js +33 -0
- package/lib/audit/orchestrate.js +476 -0
- package/lib/audit/public.js +24 -0
- package/lib/audit/repo-level.js +30 -0
- package/lib/audit/report-yaml.js +86 -0
- package/lib/audit/slot.js +65 -0
- package/lib/audit-defaults.js +18 -0
- package/lib/audit-rules/audit-rules-comment.yml +247 -0
- package/lib/audit-rules/audit-rules-cpp.yml +22 -0
- package/lib/audit-rules/audit-rules-docs.yml +32 -0
- package/lib/audit-rules/audit-rules-dsh.yml +162 -0
- package/lib/audit-rules/audit-rules-filehealth.yml +42 -0
- package/lib/audit-rules/audit-rules-folder.yml +99 -0
- package/lib/audit-rules/audit-rules-frontend.yml +335 -0
- package/lib/audit-rules/audit-rules-go.yml +22 -0
- package/lib/audit-rules/audit-rules-i18n.yml +45 -0
- package/lib/audit-rules/audit-rules-java.yml +105 -0
- package/lib/audit-rules/audit-rules-nodejs.yml +647 -0
- package/lib/audit-rules/audit-rules-npm.yml +187 -0
- package/lib/audit-rules/audit-rules-paths.yml +92 -0
- package/lib/audit-rules/audit-rules-performance.yml +207 -0
- package/lib/audit-rules/audit-rules-php.yml +22 -0
- package/lib/audit-rules/audit-rules-private.yml +24 -0
- package/lib/audit-rules/audit-rules-python.yml +106 -0
- package/lib/audit-rules/audit-rules-robustness.yml +27 -0
- package/lib/audit-rules/audit-rules-rust.yml +22 -0
- package/lib/audit-rules/audit-rules-structure.yml +159 -0
- package/lib/audit-rules/audit-rules-swift.yml +22 -0
- package/lib/audit-rules/audit-rules-template.yml +108 -0
- package/lib/checks/button-bind.js +276 -0
- package/lib/checks/common.js +170 -0
- package/lib/checks/credential-file.js +43 -0
- package/lib/checks/dataflow.js +40 -0
- package/lib/checks/dispatch.js +112 -0
- package/lib/checks/dup-code.js +69 -0
- package/lib/checks/dup-const.js +232 -0
- package/lib/checks/file-health.js +150 -0
- package/lib/checks/filter.js +131 -0
- package/lib/checks/folder.js +173 -0
- package/lib/checks/hardcoded-path.js +98 -0
- package/lib/checks/index.js +46 -0
- package/lib/checks/io.js +66 -0
- package/lib/checks/magic-number.js +42 -0
- package/lib/checks/npm-json.js +273 -0
- package/lib/checks/private.js +63 -0
- package/lib/checks/regex.js +256 -0
- package/lib/checks/semantic.js +134 -0
- package/lib/checks/structural.js +274 -0
- package/lib/cli/commands-account.mjs +107 -0
- package/lib/cli/commands-audit.mjs +144 -0
- package/lib/cli/commands-doc.mjs +127 -0
- package/lib/cli/commands-vcs.mjs +175 -0
- package/lib/client/index.js +162 -0
- package/lib/client-parts/00-loader.js +33 -0
- package/lib/client-parts/01-const.js +207 -0
- package/lib/client-parts/02-utils.js +62 -0
- package/lib/client-parts/03-icons.js +12 -0
- package/lib/client-parts/10-account.js +83 -0
- package/lib/client-parts/11-browser.js +95 -0
- package/lib/client-parts/20-repo.js +374 -0
- package/lib/client-parts/21-audit.js +301 -0
- package/lib/client-parts/22-settings.js +146 -0
- package/lib/client-parts/23-npm.js +383 -0
- package/lib/client-parts/30-page.js +56 -0
- package/lib/client-parts/40-controller.js +1092 -0
- package/lib/client-parts/41-actions.js +279 -0
- package/lib/client-parts/99-apply.js +72 -0
- package/lib/client.js +3195 -0
- package/lib/commit-push.js +144 -0
- package/lib/context/index.js +363 -0
- package/lib/core/atomic-json.js +98 -0
- package/lib/core/config.js +40 -0
- package/lib/core/credentials.js +274 -0
- package/lib/core/endpoints.js +109 -0
- package/lib/core/exec.js +162 -0
- package/lib/exempt/index.js +292 -0
- package/lib/fs/edit-after-read.js +103 -0
- package/lib/fsx.js +87 -0
- package/lib/git/account-status.js +140 -0
- package/lib/git/account.js +233 -0
- package/lib/git/api.js +136 -0
- package/lib/git/atomic-json.js +6 -0
- package/lib/git/browse.js +38 -0
- package/lib/git/clone-download.js +397 -0
- package/lib/git/clone-history-mode.js +143 -0
- package/lib/git/clone-history.js +175 -0
- package/lib/git/clone-jobs.js +250 -0
- package/lib/git/clone-replay-io.js +172 -0
- package/lib/git/clone-replay.js +275 -0
- package/lib/git/clone.js +445 -0
- package/lib/git/cloud.js +46 -0
- package/lib/git/commit-message.js +141 -0
- package/lib/git/config.js +6 -0
- package/lib/git/cred-env.js +88 -0
- package/lib/git/credentials.js +6 -0
- package/lib/git/endpoints.js +6 -0
- package/lib/git/exec.js +6 -0
- package/lib/git/identity-rewrite.js +297 -0
- package/lib/git/identity.js +150 -0
- package/lib/git/ignore.js +69 -0
- package/lib/git/index.js +41 -0
- package/lib/git/module-splitter.js +47 -0
- package/lib/git/post-push.js +101 -0
- package/lib/git/push-diagnose.js +142 -0
- package/lib/git/push.js +470 -0
- package/lib/git/remote-resolve.js +146 -0
- package/lib/git/remote.js +128 -0
- package/lib/git/repo-index.js +512 -0
- package/lib/git/repos.js +235 -0
- package/lib/git/scan-runner.js +159 -0
- package/lib/git/sensitive.js +134 -0
- package/lib/git/transport.js +430 -0
- package/lib/git/visibility.js +35 -0
- package/lib/git/wrapped-git.js +68 -0
- package/lib/http/index.js +170 -0
- package/lib/index.js +24 -0
- package/lib/link-check/index.js +187 -0
- package/lib/npm/account.js +64 -0
- package/lib/npm/install.js +211 -0
- package/lib/npm/npmrc.js +56 -0
- package/lib/npm/publish.js +167 -0
- package/lib/npm/registry.js +147 -0
- package/lib/plugin/auto-detect.js +92 -0
- package/lib/plugin/auto-push.js +154 -0
- package/lib/plugin/index.js +250 -0
- package/lib/readme-templates/readme.yml +38 -0
- package/lib/rule/compilers/credential.js +62 -0
- package/lib/rule/compilers/dataflow.js +38 -0
- package/lib/rule/compilers/file-health.js +75 -0
- package/lib/rule/compilers/frontend.js +86 -0
- package/lib/rule/compilers/func.js +35 -0
- package/lib/rule/compilers/helpers.js +71 -0
- package/lib/rule/compilers/index.js +29 -0
- package/lib/rule/compilers/link-semantic.js +45 -0
- package/lib/rule/compilers/list-kinds.js +12 -0
- package/lib/rule/compilers/numeric-kinds.js +66 -0
- package/lib/rule/compilers/regex.js +78 -0
- package/lib/rule/compilers/structure.js +80 -0
- package/lib/rule/compilers.js +17 -0
- package/lib/rule/homoglyph.js +45 -0
- package/lib/rule/loader.js +270 -0
- package/lib/rule/registry.js +115 -0
- package/lib/rule/scope.js +67 -0
- package/lib/score/docs-score.js +166 -0
- package/lib/score/index.js +140 -0
- package/lib/self/index.js +193 -0
- package/lib/skip-dirs.js +64 -0
- package/lib/tool-probes.json +50 -0
- package/lib/user-requirements.json +14 -0
- package/lib/vendor/js-yaml/LICENSE +21 -0
- package/lib/vendor/js-yaml/js-yaml.mjs +3073 -0
- package/package.json +95 -4
- package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
- package/scripts/audit-ext/_example-readme-present.mjs +34 -0
- package/scripts/audit-ext/variable-min-length.mjs +102 -0
- package/scripts/audit-runner.mjs +35 -0
- package/scripts/audit-runtime-check.mjs +129 -0
- package/scripts/browser-page-probe.mjs +271 -0
- package/scripts/build-client.mjs +119 -0
- package/scripts/check.mjs +88 -0
- package/scripts/clean-date-comments.py +102 -0
- package/scripts/doc-drift.mjs +200 -0
- package/scripts/doc-func.mjs +212 -0
- package/scripts/doc-tree.mjs +456 -0
- package/scripts/doc-version.mjs +220 -0
- package/scripts/frontend-preview-check.mjs +124 -0
- package/scripts/hot-path-probe-cjs.cjs +71 -0
- package/scripts/hot-path-probe-fs-shim.mjs +28 -0
- package/scripts/hot-path-probe-fsp-shim.mjs +31 -0
- package/scripts/hot-path-probe.mjs +153 -0
- package/scripts/module-splitter.py +800 -0
- package/scripts/platform-scan.mjs +168 -0
- package/scripts/preview-gen.mjs +489 -0
- package/scripts/preview-local-runner.mjs +55 -0
- package/scripts/preview-server-direct.mjs +116 -0
- package/scripts/preview-server.mjs +305 -0
- package/scripts/preview-slot-data.mjs +123 -0
- package/scripts/probe-recheck.mjs +47 -0
- package/scripts/readme-gen.mjs +268 -0
- package/scripts/rename-locator.mjs +97 -0
- package/scripts/rule-switch.mjs +97 -0
- package/scripts/rules-solo-audit.mjs +173 -0
- package/scripts/scan-file-io.mjs +713 -0
- package/scripts/scan-hardcoded-paths.mjs +125 -0
- package/scripts/scan-repos.mjs +167 -0
- package/scripts/scan-version.mjs +122 -0
- package/scripts/scrub-user-wording.mjs +420 -0
- package/scripts/symbol-index.mjs +85 -0
- package/scripts/sync-plugin-install.mjs +223 -0
- package/scripts/sync-plugin.mjs +279 -0
- package/scripts/verify-prestep.mjs +100 -0
- package/skills/dev/audit-rule-authoring.md +58 -0
- package/skills/dev/dsh-git-push.md +323 -0
- package/skills/dev/git-push-live-fix.md +45 -0
- package/skills/dsh-repo-index.md +35 -0
- package/skills/guide/guide-audit.md +167 -0
- package/skills/guide/guide-cli-scripts.md +104 -0
- package/skills/guide/guide-clone-repos.md +173 -0
- package/skills/guide/guide-commit-push.md +156 -0
- package/skills/guide/guide-inject-ui.md +166 -0
- package/skills/guide/guide-slash-completion.md +118 -0
- package/skills/workflow/README.md +21 -0
- package/skills/workflow/git-commit-discipline.md +68 -0
- package/skills/workflow/git-project-startup.md +85 -0
- package/skills/workflow/git-rebuild-process.md +57 -0
- package/skills/workflow/github-operations.md +91 -0
- package/skills/workflow/readme-sync-git-md.md +28 -0
- package/skills/workflow/task-completion-report.md +73 -0
- package/skills/workflow/tool-json-add-ask.md +35 -0
- package/skills/workflow/versioning-rule.md +211 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 跨平台可移植性扫描器(独立工具,可对**任意仓库**跑)
|
|
3
|
+
*
|
|
4
|
+
* 定位:找出「只在 Linux/macOS 能跑」与「只在 Windows 能跑」的代码,并区分
|
|
5
|
+
* **代码**(会真炸)与**注释**(只是说明,降级为提示);同时统计已做平台分支的位置。
|
|
6
|
+
*
|
|
7
|
+
* 用法:
|
|
8
|
+
* node scripts/platform-scan.mjs <目标目录> [--json] [--strict] [--top N] [--ext .js,.mjs,.ts]
|
|
9
|
+
* --json 机器可读输出(file/line/rule/category/severity/snippet)
|
|
10
|
+
* --strict 发现「代码里的平台专属写法」时以退出码 1 结束(可用于 CI 门禁)
|
|
11
|
+
* --top N 文本输出里每类最多列几个文件(默认 8)
|
|
12
|
+
*
|
|
13
|
+
* 判据来源:把实测踩过的坑固化成规则 —— 例如 `process.env.PATH.split(':')`(Windows 用 ';',
|
|
14
|
+
* 会永远找不到可执行文件,却报成「找不到 git」这种看起来像环境问题的误导结论)、
|
|
15
|
+
* 硬编码 `/tmp`、`sh -c`、`C:\Windows` 断言、`cmd /c` 等。
|
|
16
|
+
*
|
|
17
|
+
* 说明:正则判据是「线索」不是「判决」——例如夹具字符串里的 `/tmp` 也会命中(本工具按
|
|
18
|
+
* 注释/代码分层给出提示,最终由人判断)。跨平台**正确**的写法(`os.tmpdir()`、`path.join`、
|
|
19
|
+
* `path.delimiter`、`process.platform` 分支)不会被判为问题,只计入「已平台分支」。
|
|
20
|
+
*/
|
|
21
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
22
|
+
import { dirname, extname, join, relative, resolve } from 'node:path';
|
|
23
|
+
import { fileURLToPath } from 'node:url';
|
|
24
|
+
|
|
25
|
+
import { tokenize } from '../lib/ast/tokenizer.js';
|
|
26
|
+
|
|
27
|
+
const SKIP_DIRS = new Set(['.git', 'node_modules', '.trash', '.codegraph', 'dist', 'build', '__pycache__', '.test-cache', '.archify']);
|
|
28
|
+
/** 报告里每条命中回显的最大字符数(避免超长行把报告撑爆)。 */
|
|
29
|
+
const SNIPPET_MAX = 120;
|
|
30
|
+
const DEFAULT_EXTS = ['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.sh', '.ps1', '.bat', '.cmd', '.py'];
|
|
31
|
+
|
|
32
|
+
/** 规则表:id / 类别 / 严重级 / 判据 / 为什么。 */
|
|
33
|
+
const RULES = [
|
|
34
|
+
// ── 只在 POSIX(Linux/macOS)成立 ──
|
|
35
|
+
{ id: 'posix-tmp', category: 'posix-only', severity: 'warning', re: /['"`]\/tmp\//, why: "硬编码 /tmp:Windows 无此路径(应 os.tmpdir())" },
|
|
36
|
+
{ id: 'posix-devnull', category: 'posix-only', severity: 'warning', re: /['"`]\/dev\/null/, why: '硬编码 /dev/null:Windows 用 NUL' },
|
|
37
|
+
{ id: 'posix-shell', category: 'posix-only', severity: 'warning', re: /(\/bin\/(sh|bash)|\bsh\s+-c\b|\bbash\s+-c\b|#!\/bin\/(sh|bash)|(exec(File)?Sync|spawn(Sync)?)\(\s*['"](sh|bash|zsh|fish)['"])/, why: '依赖 POSIX shell:Windows 无 sh/bash(应走 execFile 数组参数)' },
|
|
38
|
+
{ id: 'posix-cmd', category: 'posix-only', severity: 'warning', re: /(exec(File)?Sync|spawn(Sync)?)\(\s*['"](chmod|chown|readlink|sed|awk|grep|which|stat|kill|df|du|uname)['"]/, why: '调用 POSIX 专有命令' },
|
|
39
|
+
{ id: 'path-split-colon', category: 'posix-only', severity: 'warning', re: /PATH[^\n]*\.split\(\s*['"]:['"]\s*\)|\.split\(\s*['"]:['"]\s*\)[^\n]*PATH/, why: "PATH 用 ':' 切分:Windows 是 ';'(应 path.delimiter)" },
|
|
40
|
+
{ id: 'posix-abs', category: 'posix-only', severity: 'notice', re: /['"`]\/(usr|etc|var|opt|bin|sbin|proc|sys)\//, why: '硬编码 POSIX 系统路径(Windows 无对应位置)' },
|
|
41
|
+
{ id: 'posix-symlink', category: 'posix-only', severity: 'notice', re: /\b(symlinkSync|symlink)\s*\(/, why: '符号链接:Windows 需特权/开发者模式(应提供降级)' },
|
|
42
|
+
{ id: 'posix-sudo', category: 'posix-only', severity: 'notice', re: /\bsudo\s+/, why: 'sudo:Windows 无此命令' },
|
|
43
|
+
{ id: 'posix-tilde-ssh', category: 'posix-only', severity: 'notice', re: /['"`]~\/\.ssh\//, why: '~/.ssh 字面量:Windows 家目录形式不同(应 os.homedir())' },
|
|
44
|
+
// ── 只在 Windows 成立 ──
|
|
45
|
+
{ id: 'win-drive', category: 'windows-only', severity: 'warning', re: /['"`][A-Za-z]:[\\/]/, why: '硬编码盘符路径:Linux/macOS 不存在(应 path.parse/os.homedir)' },
|
|
46
|
+
{ id: 'win-cmd', category: 'windows-only', severity: 'warning', re: /(cmd(\.exe)?\s+\/c\b|powershell(\.exe)?\b|\bstart\s+['"]{2}|(exec(File)?Sync|spawn(Sync)?)\(\s*['"](cmd|cmd\.exe|powershell|powershell\.exe)['"])/, why: '调用 Windows 专有 shell(cmd/powershell)' },
|
|
47
|
+
{ id: 'win-exe', category: 'windows-only', severity: 'notice', re: /['"][^'"\n]*\.(exe|bat|cmd)['"]/, why: '硬编码 .exe/.bat/.cmd:POSIX 上无扩展名(应探测候选名)' },
|
|
48
|
+
{ id: 'win-where', category: 'windows-only', severity: 'notice', re: /\b(where|tasklist|wmic|reg\s+query)\b\s+/, why: 'Windows 专有命令(POSIX 对应 which/ps)' },
|
|
49
|
+
{ id: 'win-env', category: 'windows-only', severity: 'notice', re: /%[A-Z_]+%/, why: '%VAR% 环境变量写法:仅 Windows cmd 展开' },
|
|
50
|
+
{ id: 'win-path32', category: 'windows-only', severity: 'notice', re: /path\.win32\b/, why: '显式使用 Windows 路径语义(若未做平台分支则在 POSIX 上错误)' },
|
|
51
|
+
// ── 已做平台分支(正确做法,仅统计) ──
|
|
52
|
+
{ id: 'platform-gated', category: 'gated', severity: 'info', re: /process\.platform\s*[!=]==?\s*['"](win32|linux|darwin)['"]|os\.platform\(\)|os\.tmpdir\(\)|path\.delimiter|path\.(join|resolve|sep)\b/, why: '已使用跨平台写法/平台分支' },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/** 递归收集待扫描文件(相对路径)。 */
|
|
56
|
+
function collectFiles(root, exts, dir = root, out = []) {
|
|
57
|
+
let entries = [];
|
|
58
|
+
try { entries = readdirSync(dir); } catch { return out; }
|
|
59
|
+
for (const name of entries) {
|
|
60
|
+
if (SKIP_DIRS.has(name)) continue;
|
|
61
|
+
const full = join(dir, name);
|
|
62
|
+
let st = null;
|
|
63
|
+
try { st = statSync(full); } catch { continue; }
|
|
64
|
+
if (st.isDirectory()) collectFiles(root, exts, full, out);
|
|
65
|
+
else if (exts.includes(extname(name))) out.push(relative(root, full).replace(/\\/g, '/'));
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 该行是否位于注释里(用 tokenizer 判定,避免把注释当代码)。 */
|
|
71
|
+
function commentLineSet(text) {
|
|
72
|
+
const set = new Set();
|
|
73
|
+
try {
|
|
74
|
+
for (const t of tokenize(text)) {
|
|
75
|
+
if (t.type === 'comment') for (let l = t.line; l <= t.line + (String(t.value).split('\n').length - 1); l++) set.add(l);
|
|
76
|
+
}
|
|
77
|
+
} catch { /* tokenize 失败就当没有注释信息 */ }
|
|
78
|
+
return set;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 扫描一个仓库。
|
|
83
|
+
* @param {string} root 目标目录
|
|
84
|
+
* @param {{exts?:string[]}} [opts]
|
|
85
|
+
* @returns {{findings:Array, summary:object}}
|
|
86
|
+
*/
|
|
87
|
+
export function scanPlatformCode(root, { exts = DEFAULT_EXTS } = {}) {
|
|
88
|
+
const files = collectFiles(root, exts);
|
|
89
|
+
const findings = [];
|
|
90
|
+
for (const rel of files) {
|
|
91
|
+
let text = '';
|
|
92
|
+
try { text = readFileSync(join(root, rel), 'utf8'); } catch { continue; }
|
|
93
|
+
const comments = commentLineSet(text);
|
|
94
|
+
const lines = text.split('\n');
|
|
95
|
+
for (let i = 0; i < lines.length; i++) {
|
|
96
|
+
const line = lines[i];
|
|
97
|
+
if (line.length > 400) continue; // 压缩产物行:跳过(噪声)
|
|
98
|
+
for (const rule of RULES) {
|
|
99
|
+
if (!rule.re.test(line)) continue;
|
|
100
|
+
// 注释里的命中降级为 info(说明性文字,不是可执行代码)
|
|
101
|
+
const inComment = comments.has(i + 1);
|
|
102
|
+
const severity = rule.category === 'gated' ? 'info' : (inComment ? 'info' : rule.severity);
|
|
103
|
+
findings.push({
|
|
104
|
+
file: rel, line: i + 1, rule: rule.id, category: rule.category, severity,
|
|
105
|
+
inComment, why: rule.why, snippet: line.trim().slice(0, SNIPPET_MAX),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const byCategory = {};
|
|
111
|
+
for (const f of findings) byCategory[f.category] = (byCategory[f.category] || 0) + 1;
|
|
112
|
+
const actionable = findings.filter((f) => f.category !== 'gated' && !f.inComment && f.severity !== 'info');
|
|
113
|
+
const filesAffected = [...new Set(actionable.map((f) => f.file))];
|
|
114
|
+
return { root, files: files.length, findings, summary: { total: findings.length, byCategory, actionable: actionable.length, filesAffected: filesAffected.length } };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** 解析命令行参数。 */
|
|
118
|
+
function parseArgs(argv) {
|
|
119
|
+
const args = { exts: DEFAULT_EXTS, json: false, strict: false, top: 8 };
|
|
120
|
+
const positional = [];
|
|
121
|
+
for (let i = 0; i < argv.length; i++) {
|
|
122
|
+
const a = argv[i];
|
|
123
|
+
if (a === '--json') args.json = true;
|
|
124
|
+
else if (a === '--strict') args.strict = true;
|
|
125
|
+
else if (a === '--top') args.top = Number(argv[++i] || 8);
|
|
126
|
+
else if (a === '--ext') args.exts = String(argv[++i] || '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
127
|
+
else if (a.startsWith('--')) throw new Error(`未知参数: ${a}`);
|
|
128
|
+
else positional.push(a);
|
|
129
|
+
}
|
|
130
|
+
args.root = positional[0];
|
|
131
|
+
return args;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** 文本输出(按类别分组 + 每类文件 top)。 */
|
|
135
|
+
function printReport(result, top) {
|
|
136
|
+
const { summary, findings } = result;
|
|
137
|
+
console.log(`目标: ${result.root}(扫描 ${result.files} 个文件)`);
|
|
138
|
+
console.log(`命中 ${summary.total} 条|其中「代码里的平台专属写法」${summary.actionable} 条,涉及 ${summary.filesAffected} 个文件`);
|
|
139
|
+
console.log(`分类: ${JSON.stringify(summary.byCategory)}`);
|
|
140
|
+
for (const [cat, title] of [['posix-only', '只在 POSIX(Linux/macOS)成立'], ['windows-only', '只在 Windows 成立'], ['gated', '已做平台分支/跨平台写法(正面)']]) {
|
|
141
|
+
const rows = findings.filter((f) => f.category === cat);
|
|
142
|
+
if (!rows.length) continue;
|
|
143
|
+
console.log(`\n── ${title}:${rows.length} 条`);
|
|
144
|
+
const byFile = new Map();
|
|
145
|
+
for (const r of rows) byFile.set(r.file, (byFile.get(r.file) || 0) + 1);
|
|
146
|
+
for (const [file, n] of [...byFile.entries()].sort((a, b) => b[1] - a[1]).slice(0, top)) {
|
|
147
|
+
console.log(` ${file}(${n} 条)`);
|
|
148
|
+
for (const r of rows.filter((x) => x.file === file).slice(0, 3)) {
|
|
149
|
+
console.log(` :${r.line} [${r.rule}]${r.inComment ? '(注释)' : ''} ${r.snippet}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ── CLI 入口 ──
|
|
156
|
+
// 注意:必须用 fileURLToPath(路径含中文/空格时 new URL().pathname 会变成 %XX 编码,比较恒不相等)
|
|
157
|
+
const isMain = process.argv[1] && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url));
|
|
158
|
+
if (isMain) {
|
|
159
|
+
const args = parseArgs(process.argv.slice(2));
|
|
160
|
+
if (!args.root) {
|
|
161
|
+
console.error('用法: node scripts/platform-scan.mjs <目标目录> [--json] [--strict] [--top N] [--ext .js,.mjs]');
|
|
162
|
+
process.exit(2);
|
|
163
|
+
}
|
|
164
|
+
const result = scanPlatformCode(resolve(args.root), { exts: args.exts });
|
|
165
|
+
if (args.json) console.log(JSON.stringify(result, null, 2));
|
|
166
|
+
else printReport(result, args.top);
|
|
167
|
+
process.exit(args.strict && result.summary.actionable > 0 ? 1 : 0);
|
|
168
|
+
}
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成 assets/preview.html —— 侧边栏交互模拟页(假数据、全部可点)。
|
|
3
|
+
*
|
|
4
|
+
* 跑的是真 client.js(不是手抄 mockup),只垫片宿主环境,所以界面与真实插件一致,
|
|
5
|
+
* 且能发现真实渲染/交互缺陷。生成物单文件自包含(内联 React UMD),双击即开、离线可用。
|
|
6
|
+
*
|
|
7
|
+
* 用法:node assets/preview-gen.mjs
|
|
8
|
+
*
|
|
9
|
+
* 路径解析(重写):
|
|
10
|
+
* 项目根 projectRoot = 本文件所在目录的上一级。
|
|
11
|
+
* DSH 安装根不能靠相对路径推导(数据目录与安装目录不同源),改为探测:
|
|
12
|
+
* 判据「含 node_modules/ 与 package.json」,顺序 DSH_ROOT > 常见安装位 > 上溯兜底。
|
|
13
|
+
* React UMD 取该根 pnpm store;react-dom 常未安装,缺失时自动下载单文件 UMD 到
|
|
14
|
+
* <DSH_HOME>/cache/react-umd/(不入库、断网可复用)。
|
|
15
|
+
* 需要时可覆盖:DSH_ROOT / REACT_UMD_DIR / REACT_DOM_UMD_DIR。
|
|
16
|
+
*/
|
|
17
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync } from 'node:fs';
|
|
18
|
+
import { spawnSync } from 'node:child_process';
|
|
19
|
+
import { tmpdir } from 'node:os';
|
|
20
|
+
import { dirname, join, resolve } from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
import { listRuleSlots } from '../lib/app/http-handlers.js';
|
|
23
|
+
// 合并(2026-10-13):数据段生成 / 漂移 check 的纯函数来自 scripts/preview-slot-data.mjs
|
|
24
|
+
// (原 scripts/gen-preview.mjs),并由本文件**再导出** ⇒ 统一入口 = 本文件,
|
|
25
|
+
// 调用方(test-rule-slots-render.mjs、文档)只认这一个路径。
|
|
26
|
+
import {
|
|
27
|
+
buildPreviewSlotData,
|
|
28
|
+
readPreviewSlotData,
|
|
29
|
+
ensurePreviewHtml,
|
|
30
|
+
readPreviewHtmlText,
|
|
31
|
+
genPreview,
|
|
32
|
+
checkPreviewDrift,
|
|
33
|
+
} from './preview-slot-data.mjs';
|
|
34
|
+
export {
|
|
35
|
+
buildPreviewSlotData,
|
|
36
|
+
readPreviewSlotData,
|
|
37
|
+
ensurePreviewHtml,
|
|
38
|
+
readPreviewHtmlText,
|
|
39
|
+
genPreview,
|
|
40
|
+
checkPreviewDrift,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const projectRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
44
|
+
// 字节 → MB 换算:1 MB = 1024 × 1024 字节
|
|
45
|
+
const BYTES_PER_MB = 1024 * 1024;
|
|
46
|
+
/**
|
|
47
|
+
* 定位 DSH 安装根(修)。
|
|
48
|
+
*
|
|
49
|
+
* 为什么不能靠相对路径:本机**数据目录与安装目录不同源**——
|
|
50
|
+
* 工作区在 /volume1/@appdata/DeepSeekHarness-NAS/<版本>/工作区/<项目>(@appdata),
|
|
51
|
+
* DSH 却装在 /volume1/@appstore/DeepSeekHarness-NAS(@appstore),两者不在同一棵树下,
|
|
52
|
+
* 上溯任意级都到不了。原实现写死上溯三级,在本机必然报「找不到 react UMD」。
|
|
53
|
+
* 判据:安装根的标志 = 同时存在 node_modules/ 与 package.json。
|
|
54
|
+
* 顺序:DSH_ROOT 显式指定 → 常见安装位置 → 从工作区上溯兜底。
|
|
55
|
+
*/
|
|
56
|
+
function findDshRoot() {
|
|
57
|
+
if (process.env.DSH_ROOT) return process.env.DSH_ROOT;
|
|
58
|
+
const isRoot = (d) => d && existsSync(join(d, 'package.json')) && existsSync(join(d, 'node_modules'));
|
|
59
|
+
for (const c of ['/volume1/@appstore/DeepSeekHarness-NAS', '/opt/DeepSeekHarness-NAS', '/usr/local/DeepSeekHarness-NAS']) {
|
|
60
|
+
if (isRoot(c)) return c;
|
|
61
|
+
}
|
|
62
|
+
let cur = resolve(projectRoot);
|
|
63
|
+
for (let i = 0; i < 6; i++) {
|
|
64
|
+
const up = resolve(cur, '..');
|
|
65
|
+
if (up === cur) break;
|
|
66
|
+
cur = up;
|
|
67
|
+
if (isRoot(cur)) return cur;
|
|
68
|
+
}
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const DSH = findDshRoot();
|
|
73
|
+
if (!DSH) {
|
|
74
|
+
console.error('找不到 DSH 安装根(标志:含 node_modules/ 与 package.json)。用 DSH_ROOT 显式指定,例如:\n DSH_ROOT=/volume1/@appstore/DeepSeekHarness-NAS node assets/preview-gen.mjs');
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
// React UMD 解析(整理 2026-10-13):原实现写死 `store/react@18.3.1`,而本机**安装根根本没有 react**
|
|
78
|
+
// (react 实际装在数据目录的 profile 里:<DSH_HOME>/profiles/<profile>/node_modules/react)
|
|
79
|
+
// ⇒ 必然报「找不到 react UMD」。改为多候选探测 + 校验**目标文件**(不是只看 umd 目录,
|
|
80
|
+
// 否则会把 react-dom 的 umd 误当成 react 的)+ 不再写死版本号。
|
|
81
|
+
// 候选顺序:env 显式 → DSH_HOME 缓存 → DSH_PROFILE_DIR/node_modules → 各 profile/node_modules
|
|
82
|
+
// → 安装根 node_modules → 安装根 .pnpm/<pkg>@*(任意版本)
|
|
83
|
+
function pickUmdDir(pkg) {
|
|
84
|
+
const envVar = pkg === 'react' ? 'REACT_UMD_DIR' : 'REACT_DOM_UMD_DIR';
|
|
85
|
+
const want = join('umd', pkg === 'react' ? 'react.development.js' : 'react-dom.development.js');
|
|
86
|
+
const has = (d) => Boolean(d) && existsSync(join(d, want));
|
|
87
|
+
if (process.env[envVar] && has(process.env[envVar])) return process.env[envVar];
|
|
88
|
+
const dshHome = process.env.DSH_HOME || '';
|
|
89
|
+
const cands = [];
|
|
90
|
+
if (dshHome) {
|
|
91
|
+
cands.push(join(dshHome, 'cache', 'react-umd', pkg)); // 缓存按包名分目录(若有)
|
|
92
|
+
cands.push(join(dshHome, 'cache', 'react-umd')); // 兼容:umd/ 直接铺在缓存根
|
|
93
|
+
const profDir = process.env.DSH_PROFILE_DIR || '';
|
|
94
|
+
if (profDir) cands.push(join(profDir, 'node_modules', pkg));
|
|
95
|
+
try {
|
|
96
|
+
for (const p of readdirSync(join(dshHome, 'profiles'))) {
|
|
97
|
+
cands.push(join(dshHome, 'profiles', p, 'node_modules', pkg));
|
|
98
|
+
}
|
|
99
|
+
} catch { /* 无 profiles 目录 */ }
|
|
100
|
+
}
|
|
101
|
+
cands.push(join(DSH, 'node_modules', pkg));
|
|
102
|
+
try {
|
|
103
|
+
const pnpm = join(DSH, 'node_modules', '.pnpm');
|
|
104
|
+
for (const d of readdirSync(pnpm)) {
|
|
105
|
+
if (d === pkg || d.startsWith(`${pkg}@`)) cands.push(join(pnpm, d, 'node_modules', pkg));
|
|
106
|
+
}
|
|
107
|
+
} catch { /* 无 .pnpm 或不可读 */ }
|
|
108
|
+
for (const c of cands) if (has(c)) return c;
|
|
109
|
+
return process.env[envVar] || '';
|
|
110
|
+
}
|
|
111
|
+
// 原实现(保留供追溯):写死 .pnpm/react@18.3.1 与 react-dom@18.3.1_react@18.3.1
|
|
112
|
+
// const store = join(DSH, 'node_modules', '.pnpm');
|
|
113
|
+
// const reactUmdDir = process.env.REACT_UMD_DIR || join(store, 'react@18.3.1', 'node_modules', 'react');
|
|
114
|
+
// const RD = process.env.REACT_DOM_UMD_DIR || join(store, 'react-dom@18.3.1_react@18.3.1', 'node_modules', 'react-dom');
|
|
115
|
+
const reactUmdDir = pickUmdDir('react');
|
|
116
|
+
const RD = pickUmdDir('react-dom');
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 确保 react-dom UMD 就位(修)。
|
|
120
|
+
*
|
|
121
|
+
* react-dom **常未随 DSH 安装**(本机实测全盘缺失,DSH 只装了 react),
|
|
122
|
+
* 而 UMD 是单文件自包含(约 1MB)、不依赖包管理器,因此缺失时直接下载即可,
|
|
123
|
+
* 不该为此要求用户去装依赖。缓存放 DSH_HOME(数据目录,不入库),命中即复用、断网可重跑。
|
|
124
|
+
* @returns {string} 含 umd/react-dom.development.js 的目录
|
|
125
|
+
*/
|
|
126
|
+
function ensureReactDomUmd(dir) {
|
|
127
|
+
if (existsSync(join(dir, 'umd', 'react-dom.development.js'))) return dir;
|
|
128
|
+
if (process.env.REACT_DOM_UMD_DIR) return dir; // 显式指定时不擅自改写
|
|
129
|
+
const cache = join(process.env.DSH_HOME || join(tmpdir(), 'dsh-git-push'), 'cache', 'react-umd');
|
|
130
|
+
const cached = join(cache, 'umd', 'react-dom.development.js');
|
|
131
|
+
try {
|
|
132
|
+
mkdirSync(join(cache, 'umd'), { recursive: true });
|
|
133
|
+
if (!existsSync(cached)) {
|
|
134
|
+
console.log(`react-dom 未安装,下载单文件 UMD → ${cached}`);
|
|
135
|
+
const r = spawnSync('curl', ['-sSL', '--max-time', '180', '-o', cached, 'https://unpkg.com/react-dom@18.3.1/umd/react-dom.development.js'], { stdio: 'inherit' });
|
|
136
|
+
if (r.status !== 0 || !existsSync(cached)) {
|
|
137
|
+
console.error(`下载失败,可手动放置到:${cached}`);
|
|
138
|
+
return dir;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return cache;
|
|
142
|
+
} catch (e) {
|
|
143
|
+
console.error(`准备 react-dom UMD 失败:${e?.message || e}`);
|
|
144
|
+
return dir;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const reactDomDir = ensureReactDomUmd(RD);
|
|
149
|
+
|
|
150
|
+
for (const [label, dir] of [['react', reactUmdDir], ['react-dom', reactDomDir]]) {
|
|
151
|
+
if (!existsSync(join(dir, 'umd'))) {
|
|
152
|
+
console.error(`找不到 ${label} UMD:${dir}\n(DSH 根推导为 ${DSH};可用 DSH_ROOT / ${label === 'react' ? 'REACT_UMD_DIR' : 'REACT_DOM_UMD_DIR'} 指定)`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ---------- 统一 CLI 分发(合并 2026-10-13)----------
|
|
158
|
+
// 默认 = 整体生成预览页(本文件余下流程)
|
|
159
|
+
// --data-only = 只重写 __SLOTS__/__FAKE__ 数据段(原 scripts/gen-preview.mjs --write)
|
|
160
|
+
// check = 漂移门禁:产物数据 vs 真实 listRuleSlots(原 scripts/gen-preview.mjs check)
|
|
161
|
+
// --watch = 监听源码变更自动重生成(原 scripts/watch-preview.mjs)
|
|
162
|
+
const CLI_ARGS = process.argv.slice(2);
|
|
163
|
+
const CLI_MODE = CLI_ARGS.includes('check')
|
|
164
|
+
? 'check'
|
|
165
|
+
: CLI_ARGS.includes('--data-only')
|
|
166
|
+
? 'data'
|
|
167
|
+
: CLI_ARGS.includes('--watch')
|
|
168
|
+
? 'watch'
|
|
169
|
+
: 'gen';
|
|
170
|
+
|
|
171
|
+
if (CLI_MODE === 'check') {
|
|
172
|
+
const r = checkPreviewDrift();
|
|
173
|
+
console.log(r.ok ? `✅ ${r.message}` : `❌ ${r.message}`);
|
|
174
|
+
process.exit(r.ok ? 0 : 1);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (CLI_MODE === 'data') {
|
|
178
|
+
const r = genPreview({ write: true });
|
|
179
|
+
if (!r.ok) { console.error(r.error); process.exit(1); }
|
|
180
|
+
console.log(`✅ 已写盘(仅数据段):${r.metaCount} 槽位 / order ${r.order.length} 项${r.drift ? '(原数据有漂移,已更新)' : ''}`);
|
|
181
|
+
process.exit(0);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (CLI_MODE === 'watch') {
|
|
185
|
+
const { watch } = await import('node:fs');
|
|
186
|
+
const SELF = fileURLToPath(import.meta.url);
|
|
187
|
+
const targets = [join(projectRoot, 'lib', 'client.js'), join(projectRoot, 'lib', 'client', 'index.js'), SELF];
|
|
188
|
+
const regen = () => {
|
|
189
|
+
const t0 = Date.now();
|
|
190
|
+
const r = spawnSync(process.execPath, [SELF], { cwd: projectRoot, stdio: 'inherit', timeout: 300_000 });
|
|
191
|
+
if (r.status !== 0) console.error(`[watch] 重新生成失败(exit ${r.status})`);
|
|
192
|
+
else console.log(`[watch] ${new Date().toTimeString().slice(0, 8)} 已重新生成预览页(${Date.now() - t0}ms)`);
|
|
193
|
+
};
|
|
194
|
+
let timer = null;
|
|
195
|
+
for (const f of targets) {
|
|
196
|
+
watch(f, { persistent: true }, () => {
|
|
197
|
+
if (timer) clearTimeout(timer);
|
|
198
|
+
timer = setTimeout(() => { timer = null; regen(); }, 300);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
console.log('[watch] 监听中:lib/client.js · lib/client/index.js · 本文件;Ctrl+C 停止');
|
|
202
|
+
regen();
|
|
203
|
+
// 常驻:watcher 已在事件循环里;永不 resolve,避免继续执行下面的整体生成
|
|
204
|
+
await new Promise(() => {});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const clientSrc = readFileSync(`${projectRoot}/lib/client.js`, 'utf8');
|
|
208
|
+
const reactUmd = readFileSync(`${reactUmdDir}/umd/react.development.js`, 'utf8');
|
|
209
|
+
const domUmd = readFileSync(`${reactDomDir}/umd/react-dom.development.js`, 'utf8');
|
|
210
|
+
|
|
211
|
+
// 槽位数据取自真实规则文件(动态发现 audit-rules-<名>.yml),不再手写清单——
|
|
212
|
+
// 手写清单会与真实规则包脱节:曾只手写 6 个,预览里就只显示 6 个槽位,
|
|
213
|
+
// 被误当成「只显示 6 个」的回归。读取真实数据后预览与真实实例恒等。
|
|
214
|
+
// 第三参传 null = 未审计过,stats 走「规则条数」口径(与真实实例重启后的初始态一致)。
|
|
215
|
+
const realSlots = listRuleSlots(undefined, [], null);
|
|
216
|
+
const SLOT_ORDER = realSlots.order.filter((slot) => slot !== 'template');
|
|
217
|
+
const SLOT_META = realSlots.meta;
|
|
218
|
+
|
|
219
|
+
/** 演示配置的全量扫描文件上限(与默认配置一致)。 */
|
|
220
|
+
const DEMO_MAX_SCAN_FILES = 3000;
|
|
221
|
+
|
|
222
|
+
// 假数据:可变(点开关/调序会真的改它,UI 才反映结果,而不是点完回弹)
|
|
223
|
+
const FAKE = {
|
|
224
|
+
// 改为演示「父开关关闭 + 子开关已勾选」——正是可勾选/只置灰/不生效的验证场景
|
|
225
|
+
auditEnabled: false,
|
|
226
|
+
injectRequirements: true,
|
|
227
|
+
// injectFullSkill / injectRepoIndexFull 已废弃移除,改为注入总开关(默认开)
|
|
228
|
+
injectSystemPrompt: true,
|
|
229
|
+
auditScanScope: 'diff',
|
|
230
|
+
maxScanFiles: DEMO_MAX_SCAN_FILES,
|
|
231
|
+
weightOverrides: '',
|
|
232
|
+
githubToken: 'ghp_ExampleToken1234567890abcdefGHIJ',
|
|
233
|
+
sshPub: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExamplePublicKeyForDemoOnly eightfs@example.com',
|
|
234
|
+
_order: SLOT_ORDER,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// 规则包元数据(SLOT_META)现在来自真实规则文件,见文件上方 realSlots。
|
|
238
|
+
// 仍只作为 /rule-slots 的接口假数据,**不放进快照**——放进快照会掩盖
|
|
239
|
+
// 「客户端被空 ruleSlotMeta 覆盖」这类 bug(真实宿主从不提供该字段)。
|
|
240
|
+
|
|
241
|
+
const harness = `
|
|
242
|
+
window.__ERRORS__ = [];
|
|
243
|
+
function __err(kind, msg) {
|
|
244
|
+
window.__ERRORS__.push(kind + ': ' + msg);
|
|
245
|
+
var errEl = document.getElementById('__err');
|
|
246
|
+
if (!errEl) {
|
|
247
|
+
errEl = document.createElement('pre');
|
|
248
|
+
errEl.id = '__err';
|
|
249
|
+
errEl.style.cssText = 'color:#f87171;white-space:pre-wrap;font-size:12px;'
|
|
250
|
+
+ 'border:1px solid #f87171;padding:8px;margin:0 0 12px';
|
|
251
|
+
document.body.insertBefore(errEl, document.body.firstChild);
|
|
252
|
+
}
|
|
253
|
+
errEl.textContent += kind + ': ' + msg + String.fromCharCode(10);
|
|
254
|
+
}
|
|
255
|
+
window.addEventListener('error', function (e) { __err('error', e.message); });
|
|
256
|
+
window.addEventListener('unhandledrejection', function (e) { __err('reject', String((e.reason && e.reason.stack) || e.reason)); });
|
|
257
|
+
var __oerr = console.error;
|
|
258
|
+
console.error = function () { __err('console', Array.prototype.map.call(arguments, function (x) { return String((x && x.stack) || x); }).join(' ')); __oerr.apply(console, arguments); };
|
|
259
|
+
|
|
260
|
+
window.__FAKE__ = ${JSON.stringify(FAKE)};
|
|
261
|
+
window.__CAPTURED__ = null;
|
|
262
|
+
window.__ModuleLoader__ = { load: function (m) { window.__CAPTURED__ = m; } };
|
|
263
|
+
|
|
264
|
+
// jsx-runtime → createElement:key 走 props、children 走独立实参(否则 children 会被覆盖成空)
|
|
265
|
+
window.__jsxRuntime = {
|
|
266
|
+
Fragment: React.Fragment,
|
|
267
|
+
jsx: function (type, props, key) {
|
|
268
|
+
var p = props || {}, children = p.children, rest = {};
|
|
269
|
+
for (var k in p) if (k !== 'children') rest[k] = p[k];
|
|
270
|
+
if (key !== undefined) rest.key = key;
|
|
271
|
+
var args = children === undefined ? [rest] : [rest].concat(Array.isArray(children) ? children : [children]);
|
|
272
|
+
return React.createElement.apply(React, [type].concat(args));
|
|
273
|
+
},
|
|
274
|
+
jsxs: function (type, props, key) { return window.__jsxRuntime.jsx(type, props, key); },
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
window.__requireShim = function (name) {
|
|
278
|
+
if (name === 'react') return React;
|
|
279
|
+
if (name === 'react/jsx-runtime') return window.__jsxRuntime;
|
|
280
|
+
if (name === '@deepseek-ai/dsh-client-store') {
|
|
281
|
+
return { createSnapshotStore: function (initial) {
|
|
282
|
+
var cur = initial, subs = [];
|
|
283
|
+
return {
|
|
284
|
+
set: function (v) { cur = v; subs.forEach(function (f) { f(); }); },
|
|
285
|
+
getSnapshot: function () { return cur; },
|
|
286
|
+
subscribe: function (f) { subs.push(f); return function () {}; },
|
|
287
|
+
};
|
|
288
|
+
} };
|
|
289
|
+
}
|
|
290
|
+
throw new Error('未垫片的 require: ' + name);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// 宿主 settingsScope:真内存 store,set 后通知 → 界面真的跟着变
|
|
294
|
+
window.__SLOTS__ = ${JSON.stringify(SLOT_META)};
|
|
295
|
+
window.__scopeSubs = [];
|
|
296
|
+
window.__scopeMock = {
|
|
297
|
+
getSnapshot: function () { return { status: 'ready', writable: true, value: window.__FAKE__ }; },
|
|
298
|
+
subscribe: function (cb) { window.__scopeSubs.push(cb); return function () {}; },
|
|
299
|
+
set: function (key, value) {
|
|
300
|
+
window.__FAKE__[key] = value;
|
|
301
|
+
window.__scopeSubs.forEach(function (f) { f(); });
|
|
302
|
+
return Promise.resolve();
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// 接真实后端(完全真实数据版):
|
|
307
|
+
// · 默认(无参数):同源相对路径 /api/git-push/* 直接放行——在 preview-server.mjs 反代服务下
|
|
308
|
+
// 打开时请求落到真实 DSH 后端,预览数据完全真实(账号/仓库/规则/审计/设置)。
|
|
309
|
+
// · URL 传 ?backend=http://127.0.0.1:PORT → 转发到所给后端(preview-server 直连实测)。
|
|
310
|
+
// · ?mock=1 → 走下方假数据(离线调试兜底,默认不再用假数据)。
|
|
311
|
+
var __PRE_REAL__ = window.fetch;
|
|
312
|
+
window.__dshgpScript = window.__dshgpScript || [];
|
|
313
|
+
window.__realFetch = __PRE_REAL__;
|
|
314
|
+
// backend 转发:?backend= 或 window.__DSHGP_BACKEND__(preview-server 注入)→ 转发指定后端
|
|
315
|
+
function forwardBackend(urlStr, init) {
|
|
316
|
+
var b = (location.search.match(/[?&]backend=([^&]+)/) || [])[1] || window.__DSHGP_BACKEND__ || '';
|
|
317
|
+
if (!b) return '';
|
|
318
|
+
return __PRE_REAL__(b + urlStr, {
|
|
319
|
+
method: ((init && init.method) || 'GET'),
|
|
320
|
+
headers: { 'Content-Type': 'application/json' },
|
|
321
|
+
body: (init && init.body) || undefined,
|
|
322
|
+
}).then(function (raw) {
|
|
323
|
+
return raw.json().then(function (data) {
|
|
324
|
+
return { ok: true, status: raw.status, json: function () { return Promise.resolve(data); } };
|
|
325
|
+
});
|
|
326
|
+
}).catch(function () { return { ok: true, status: 502, json: function () { return Promise.resolve({ ok: false, error: '后端未启动: ' + b }); } }; });
|
|
327
|
+
}
|
|
328
|
+
// 同源放行:preview-server.mjs 反代到 DSH 真实后端(完全真实数据);
|
|
329
|
+
// 仅显式 ?mock=1 才走下方假数据(离线调试)。
|
|
330
|
+
function passthroughFetch(urlStr, init) {
|
|
331
|
+
if (!/[?&]mock=1/.test(location.search)) {
|
|
332
|
+
// 修复:**file:// 双击打开**时相对 URL(/api/git-push/*)无 http 基址,
|
|
333
|
+
// fetch 直接抛「Failed to parse URL」——自动回退本机 preview 服务(start.sh 缺省
|
|
334
|
+
// 端口 30999;--port 错开或用 ?backend= 指定则覆盖)。连不上给清晰指引而非裸报错。
|
|
335
|
+
if (location.protocol === 'file:') {
|
|
336
|
+
var fileBase = window.__DSHGP_BACKEND__ || 'http://127.0.0.1:30999';
|
|
337
|
+
return __PRE_REAL__(fileBase + urlStr, init).catch(function () {
|
|
338
|
+
return {
|
|
339
|
+
ok: true, status: 502,
|
|
340
|
+
json: function () {
|
|
341
|
+
return Promise.resolve({
|
|
342
|
+
ok: false,
|
|
343
|
+
error: '后端未启动或端口不符(双击打开 preview.html:请先 assets/start.sh start 起服务经 http://<IP>:<端口> 访问;端口错开时给 URL 加 ?backend=http://127.0.0.1:<实际端口>;或加 ?mock=1 用离线假数据)',
|
|
344
|
+
});
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
return __PRE_REAL__(urlStr, init);
|
|
350
|
+
}
|
|
351
|
+
return '';
|
|
352
|
+
}
|
|
353
|
+
function mockFetch(urlStr, init) { // dsh-skip-complexity: mock 路由表(8 路由 if/else 为结构必然,各路由是独立假数据)
|
|
354
|
+
var body = { ok: true };
|
|
355
|
+
// 演示目录根(mock 假数据用;browse/repos-local 共用)
|
|
356
|
+
var DEMO_HOME = '/home/user/项目';
|
|
357
|
+
// /toggle-rule 必须真改假数据:toggleDisabled 本地翻转后会 loadSlots 对账,
|
|
358
|
+
// 假数据不改就会被拉回原状(表现为「点完回弹」)。
|
|
359
|
+
if (urlStr.indexOf('toggle-rule') >= 0) {
|
|
360
|
+
try {
|
|
361
|
+
var req = JSON.parse((init && init.body) || '{}');
|
|
362
|
+
var meta = window.__SLOTS__[req.slot];
|
|
363
|
+
if (meta) meta.disabled = !!req.disabled;
|
|
364
|
+
} catch (e) { /* 假数据解析失败不影响预览 */ }
|
|
365
|
+
return Promise.resolve({ ok: true, status: 200, json: function () { return Promise.resolve({ ok: true }); } });
|
|
366
|
+
}
|
|
367
|
+
if (urlStr.indexOf('rule-slots') >= 0) {
|
|
368
|
+
body = { ok: true, slots: { order: window.__FAKE__._order.slice(), meta: window.__SLOTS__, forced: ['private'] } };
|
|
369
|
+
} else if (urlStr.indexOf('account-check') >= 0) {
|
|
370
|
+
body = { ok: true, loggedIn: true, block: '✅ 已登录 GitHub:EIGHTfs(Public 仓库 12 个 / 私有 3 个)' };
|
|
371
|
+
} else if (urlStr.indexOf('gen-ssh-key') >= 0) {
|
|
372
|
+
body = { ok: true, pub: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINewlyGeneratedDemoKeyForPreview eightfs@example.com' };
|
|
373
|
+
// 账号卡片(本地/云端)假数据:结构与真实端点一致,点按钮能真的出列表/弹窗
|
|
374
|
+
} else if (urlStr.indexOf('browse') >= 0) {
|
|
375
|
+
// 目录浏览:mock 按请求 path 返回真实层级(点目录真切换,与真实 browseDir 行为一致)
|
|
376
|
+
var queryStr = String(urlStr).split('?')[1] || '';
|
|
377
|
+
var p = '';
|
|
378
|
+
try { p = decodeURIComponent(String(queryStr).replace(/^path=/, '')); } catch (e) { /* 忽略 */ }
|
|
379
|
+
if (!p) p = DEMO_HOME;
|
|
380
|
+
var parent = p.replace(/\\/[^/]+$/, '') || '/';
|
|
381
|
+
var dirs;
|
|
382
|
+
if (p === DEMO_HOME + '/dsh-git-push-v2/lib') dirs = ['app', 'ast', 'audit', 'checks', 'git', 'rule', 'self', 'client', 'context'];
|
|
383
|
+
else if (p === DEMO_HOME + '/dsh-git-push-v2') dirs = ['lib', 'scripts', 'docs', 'test', 'assets', 'tool'];
|
|
384
|
+
else if (p === DEMO_HOME + '/gamebanana-mods-downloader') dirs = ['server', 'crx', 'docs', 'scripts', 'test', 'mapping'];
|
|
385
|
+
else if (p === DEMO_HOME + '/ai-work-archive') dirs = ['skills', '开发者文档', '任务'];
|
|
386
|
+
else if (p === DEMO_HOME) dirs = ['dsh-git-push-v2', 'gamebanana-mods-downloader', 'iwara-downloader', 'ai-work-archive', '任务', '数据', '用户'];
|
|
387
|
+
else if (p === '/home/user') dirs = ['项目'];
|
|
388
|
+
else dirs = ['src', 'docs', 'build', 'scripts'];
|
|
389
|
+
body = { ok: true, path: p, parent: parent, dirs: dirs };
|
|
390
|
+
} else if (urlStr.indexOf('repos-local') >= 0) {
|
|
391
|
+
// 服务端已过滤:只保留登录同作者(EIGHTfs)的仓库。
|
|
392
|
+
// ①领先+干净→push 可点 ②有未提交→push 禁用;其他作者/无 remote 的都被过滤不显示
|
|
393
|
+
body = {
|
|
394
|
+
ok: true, root: '/home/user/项目', count: 2, owner: 'EIGHTfs', indexedAvailable: true,
|
|
395
|
+
repos: [
|
|
396
|
+
{
|
|
397
|
+
path: DEMO_HOME + '/dsh-git-push-v2', branch: 'master', remote: 'origin', changed: 0,
|
|
398
|
+
lastCommit: 'a1b2c3d 账号卡片:本地/云端', hasRemote: true, upstream: 'origin/master', ahead: 3, behind: 0,
|
|
399
|
+
indexed: { owner: 'EIGHTfs', repo: 'dsh-git-push', repoUrl: 'https://api.github.com/repos/EIGHTfs/dsh-git-push', visibility: '公开' },
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
path: DEMO_HOME + '/gamebanana-mods-downloader', branch: 'main', remote: 'origin', changed: 5,
|
|
403
|
+
lastCommit: 'f0e9d8c 修复下载器', hasRemote: true, upstream: 'origin/main', ahead: 1, behind: 0,
|
|
404
|
+
indexed: { owner: 'EIGHTfs', repo: 'gamebanana-mods-downloader', repoUrl: 'https://api.github.com/repos/EIGHTfs/gamebanana-mods-downloader', visibility: '私有' },
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
};
|
|
408
|
+
} else if (urlStr.indexOf('repos-cloud') >= 0) {
|
|
409
|
+
body = {
|
|
410
|
+
ok: true, loggedIn: true, count: 4,
|
|
411
|
+
repos: [
|
|
412
|
+
{ fullName: 'EIGHTfs/dsh-git-push', private: false, defaultBranch: 'master', pushedAt: '2026-09-14T10:00:00Z', description: 'DSH git 提交推送插件' },
|
|
413
|
+
{ fullName: 'EIGHTfs/dsh-git-rescue', private: true, defaultBranch: 'master', pushedAt: '2026-09-13T08:30:00Z', description: 'DSH 救援恢复插件' },
|
|
414
|
+
{ fullName: 'EIGHTfs/dsh-session-conductor', private: false, defaultBranch: 'main', pushedAt: '2026-09-12T15:20:00Z', description: '会话指挥家' },
|
|
415
|
+
{ fullName: 'EIGHTfs/iwara-downloader', private: false, defaultBranch: 'main', pushedAt: '2026-09-10T11:00:00Z', description: 'iwara 下载器' },
|
|
416
|
+
],
|
|
417
|
+
};
|
|
418
|
+
} else if (urlStr.indexOf('repo-push') >= 0) {
|
|
419
|
+
body = { ok: true, pushed: true, branch: 'master', ahead: 0 };
|
|
420
|
+
} else if (urlStr.indexOf('repo-clone') >= 0) {
|
|
421
|
+
body = { ok: true, dest: '/home/user/项目/dsh-git-push' };
|
|
422
|
+
}
|
|
423
|
+
return Promise.resolve({ ok: true, status: 200, json: function () { return Promise.resolve(body); } });
|
|
424
|
+
}
|
|
425
|
+
window.fetch = function (url, init) {
|
|
426
|
+
var urlStr = String(url);
|
|
427
|
+
var forwarded = forwardBackend(urlStr, init);
|
|
428
|
+
if (forwarded) return forwarded;
|
|
429
|
+
var passed = passthroughFetch(urlStr, init);
|
|
430
|
+
if (passed) return passed;
|
|
431
|
+
return mockFetch(urlStr, init);
|
|
432
|
+
};
|
|
433
|
+
`;
|
|
434
|
+
|
|
435
|
+
const post = `
|
|
436
|
+
try {
|
|
437
|
+
var mod = window.__CAPTURED__.factory(window.__requireShim);
|
|
438
|
+
var renderSection = null;
|
|
439
|
+
var ctx = {
|
|
440
|
+
settingsScope: { bind: function () { return window.__scopeMock; } },
|
|
441
|
+
slots: { inject: function (n, cb) { cb(); }, register: function (spec, render) { renderSection = render; } },
|
|
442
|
+
};
|
|
443
|
+
mod.apply(ctx);
|
|
444
|
+
if (!renderSection) throw new Error('settings.section 未注册');
|
|
445
|
+
ReactDOM.flushSync(function () {
|
|
446
|
+
ReactDOM.createRoot(document.getElementById('root')).render(
|
|
447
|
+
React.createElement(function () {
|
|
448
|
+
var el = renderSection();
|
|
449
|
+
return el || React.createElement('div', null, '(state.available=false)');
|
|
450
|
+
}, null)
|
|
451
|
+
);
|
|
452
|
+
});
|
|
453
|
+
window.__ready = true;
|
|
454
|
+
} catch (e) {
|
|
455
|
+
__err('harness', (e && e.message) || String(e));
|
|
456
|
+
}
|
|
457
|
+
`;
|
|
458
|
+
|
|
459
|
+
const html = `<!doctype html>
|
|
460
|
+
<html lang="zh-CN"><head><meta charset="utf-8">
|
|
461
|
+
<title>dsh-git-push 侧边栏预览(真实后端数据)</title>
|
|
462
|
+
<style>
|
|
463
|
+
:root{
|
|
464
|
+
--dsw-alias-label-primary:#e8eaf0;--dsw-alias-label-secondary:#a0a6b4;--dsw-alias-label-tertiary:#6b7280;
|
|
465
|
+
--dsw-alias-bg-layer-1:#14161d;--dsw-alias-bg-layer-2:#1a1d26;--dsw-alias-bg-layer-3:#20242e;
|
|
466
|
+
--dsw-alias-border-l2:rgba(255,255,255,.08);--dsw-alias-border-l4:rgba(255,255,255,.14);
|
|
467
|
+
}
|
|
468
|
+
*{box-sizing:border-box}
|
|
469
|
+
body{margin:0;padding:20px;background:#0f1117;color:#e8eaf0;
|
|
470
|
+
font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif}
|
|
471
|
+
.banner{max-width:520px;margin:0 0 14px;padding:10px 12px;border:1px dashed rgba(255,255,255,.18);
|
|
472
|
+
border-radius:10px;color:#a0a6b4;font-size:12px}
|
|
473
|
+
.banner b{color:#e8eaf0}
|
|
474
|
+
#root{max-width:520px}
|
|
475
|
+
#__err{max-width:520px}
|
|
476
|
+
</style></head><body>
|
|
477
|
+
<div class="banner"><b>打开方式</b>:本地双击(file://)会自动连 <b>http://127.0.0.1:30999</b>(start.sh 缺省端口)——请先 <b>assets/start.sh start</b> 起服务经 http://<本机IP>:<端口> 访问,端口不符给 URL 加 <b>?backend=http://127.0.0.1:端口</b>(或 ?mock=1 离线);经服务打开时数据完全来自真实后端。 <hr style="border-color:rgba(255,255,255,.12);margin:8px 0">这是<b>真实后端数据预览</b>:跑的是仓库里真实的 <b>client.js</b>(垫片宿主环境);默认在
|
|
478
|
+
<b>start.sh 起的预览服务</b>下打开,账号/仓库/规则/审计/设置全部来自 <b>DSH 真实后端</b>(读写都真实)。
|
|
479
|
+
离线调试可用 <b>?mock=1</b> 切回内置假数据(改动只留页面内、不写文件);跨后端实测用 <b>?backend=http://127.0.0.1:端口</b>。</div>
|
|
480
|
+
<div id="root"></div>
|
|
481
|
+
<script>${reactUmd}</script>
|
|
482
|
+
<script>${domUmd}</script>
|
|
483
|
+
<script>${harness}</script>
|
|
484
|
+
<script>${clientSrc}</script>
|
|
485
|
+
<script>${post}</script>
|
|
486
|
+
</body></html>`;
|
|
487
|
+
|
|
488
|
+
writeFileSync(`${projectRoot}/assets/preview.html`, html);
|
|
489
|
+
console.log('生成 assets/preview.html', (html.length / BYTES_PER_MB).toFixed(2), 'MB');
|