dsh-git-push 2.20.19 → 3.1.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 (239) hide show
  1. package/README.md +76 -47
  2. package/cli-tool.mjs +2 -4
  3. package/cli.mjs +11 -4
  4. package/lib/app/apply.js +15 -13
  5. package/lib/app/command-registry.js +26 -19
  6. package/lib/app/handlers/http-constants.js +8 -0
  7. package/lib/app/handlers/meta.js +2 -2
  8. package/lib/app/handlers/preprocess.js +104 -0
  9. package/lib/app/handlers/repo-actions.js +2 -3
  10. package/lib/app/handlers/repos.js +137 -10
  11. package/lib/app/handlers/settings.js +34 -15
  12. package/lib/app/http-handlers.js +13 -42
  13. package/lib/app/index.js +3 -2
  14. package/lib/app/inject-text.js +6 -21
  15. package/lib/app/preprocess-client.js +136 -0
  16. package/lib/app/repo-ownership.js +1 -1
  17. package/lib/app/schema.js +20 -10
  18. package/lib/app/settings-bridge.js +60 -8
  19. package/lib/app/severity.js +14 -0
  20. package/lib/app/slash-commands.js +5 -164
  21. package/lib/app/tool-call.js +96 -163
  22. package/lib/cli/commands-preprocess.mjs +74 -0
  23. package/lib/cli/commands-tool.mjs +3 -2
  24. package/lib/cli/commands-vcs.mjs +39 -5
  25. package/lib/cli/shared.mjs +36 -10
  26. package/lib/client/index.js +11 -16
  27. package/lib/client-parts/git/account.js +21 -12
  28. package/lib/client-parts/git/actions.js +23 -77
  29. package/lib/client-parts/git/apply.js +8 -2
  30. package/lib/client-parts/git/browser.js +1 -1
  31. package/lib/client-parts/git/const.js +33 -1
  32. package/lib/client-parts/git/controller.js +175 -176
  33. package/lib/client-parts/git/icons.js +1 -1
  34. package/lib/client-parts/git/loader.js +1 -1
  35. package/lib/client-parts/git/npm.js +56 -37
  36. package/lib/client-parts/git/page.js +53 -1
  37. package/lib/client-parts/git/repo.js +8 -1
  38. package/lib/client-parts/git/settings.js +13 -1
  39. package/lib/client-parts/git/state.js +237 -0
  40. package/lib/client-parts/git/utils.js +1 -1
  41. package/lib/client.js +631 -312
  42. package/lib/commit-push/pre-commit-engine.js +629 -30
  43. package/lib/commit-push.js +127 -67
  44. package/lib/context/index.js +7 -5
  45. package/lib/core/config.js +1 -27
  46. package/lib/core/exec.js +2 -11
  47. package/lib/{exempt/index.js → git/exempt-markers.js} +8 -1
  48. package/lib/git/identity-rewrite.js +1 -1
  49. package/lib/git/ignore.js +1 -1
  50. package/lib/git/index.js +1 -1
  51. package/lib/git/push.js +2 -17
  52. package/lib/git/repo-index.js +8 -3
  53. package/lib/git/repos.js +2 -2
  54. package/lib/git/sensitive.js +1 -1
  55. package/lib/npm/install.js +1 -1
  56. package/lib/npm/publish.js +20 -5
  57. package/lib/npm/registry.js +2 -2
  58. package/lib/plugin/auto-push.js +5 -8
  59. package/lib/preprocess/providers.js +195 -0
  60. package/lib/self/index.js +1 -1
  61. package/lib/skip-dirs.js +14 -55
  62. package/package.json +31 -42
  63. package/skills/dev/dsh-git-push.md +9 -9
  64. package/skills/guide/guide-commit-push.md +11 -13
  65. package/skills/workflow/README.md +0 -1
  66. package/skills/workflow/task-completion-report.md +2 -2
  67. package/.auditignore +0 -30
  68. package/.gitignore +0 -43
  69. package/cli-audit.mjs +0 -141
  70. package/lib/BUGFIX-NOTES-2026-09-14.md +0 -278
  71. package/lib/app/audit-api.js +0 -173
  72. package/lib/app/handlers/audit.js +0 -150
  73. package/lib/app/host-doc-checks.js +0 -25
  74. package/lib/app/schema-audit.js +0 -42
  75. package/lib/app/scope-check.js +0 -69
  76. package/lib/ast/brace.js +0 -120
  77. package/lib/ast/callgraph.js +0 -135
  78. package/lib/ast/code-lines.js +0 -175
  79. package/lib/ast/consts.js +0 -12
  80. package/lib/ast/control-flow.js +0 -470
  81. package/lib/ast/credential.js +0 -315
  82. package/lib/ast/dataflow.js +0 -391
  83. package/lib/ast/dup-code.js +0 -165
  84. package/lib/ast/fs-hotspots.js +0 -154
  85. package/lib/ast/index.js +0 -38
  86. package/lib/ast/io-risk-const.js +0 -95
  87. package/lib/ast/io-risk-fn.js +0 -208
  88. package/lib/ast/io-risk-loop.js +0 -308
  89. package/lib/ast/io-risk.js +0 -314
  90. package/lib/ast/lang.js +0 -156
  91. package/lib/ast/line-count.js +0 -52
  92. package/lib/ast/magic-number.js +0 -272
  93. package/lib/ast/naming.js +0 -292
  94. package/lib/ast/perf.js +0 -488
  95. package/lib/ast/scope-collisions.js +0 -228
  96. package/lib/ast/scope.js +0 -241
  97. package/lib/ast/shell.js +0 -131
  98. package/lib/ast/size.js +0 -448
  99. package/lib/ast/symbol-index.js +0 -399
  100. package/lib/ast/tokenizer.js +0 -421
  101. package/lib/ast/treesitter.js +0 -413
  102. package/lib/audit/analysis-coverage.js +0 -98
  103. package/lib/audit/audit-file.js +0 -205
  104. package/lib/audit/auditignore-rules.js +0 -148
  105. package/lib/audit/checks.js +0 -17
  106. package/lib/audit/client-entry.js +0 -93
  107. package/lib/audit/collector.js +0 -610
  108. package/lib/audit/ext-runner.js +0 -80
  109. package/lib/audit/file-context.js +0 -391
  110. package/lib/audit/finding.js +0 -101
  111. package/lib/audit/gitignore-match.js +0 -113
  112. package/lib/audit/glob.js +0 -63
  113. package/lib/audit/history-report.js +0 -100
  114. package/lib/audit/history.js +0 -126
  115. package/lib/audit/ignore-blind.js +0 -102
  116. package/lib/audit/index.js +0 -33
  117. package/lib/audit/orchestrate.js +0 -672
  118. package/lib/audit/public.js +0 -24
  119. package/lib/audit/repo-level.js +0 -30
  120. package/lib/audit/report-yaml.js +0 -90
  121. package/lib/audit/scope-policy.js +0 -110
  122. package/lib/audit/slot.js +0 -66
  123. package/lib/audit-rules/audit-rules-comment.yml +0 -199
  124. package/lib/audit-rules/audit-rules-cpp.yml +0 -114
  125. package/lib/audit-rules/audit-rules-csharp.yml +0 -82
  126. package/lib/audit-rules/audit-rules-docs.yml +0 -32
  127. package/lib/audit-rules/audit-rules-dsh.yml +0 -177
  128. package/lib/audit-rules/audit-rules-filehealth.yml +0 -42
  129. package/lib/audit-rules/audit-rules-folder.yml +0 -99
  130. package/lib/audit-rules/audit-rules-frontend.yml +0 -335
  131. package/lib/audit-rules/audit-rules-go.yml +0 -103
  132. package/lib/audit-rules/audit-rules-i18n.yml +0 -45
  133. package/lib/audit-rules/audit-rules-java.yml +0 -105
  134. package/lib/audit-rules/audit-rules-nodejs.yml +0 -662
  135. package/lib/audit-rules/audit-rules-npm.yml +0 -187
  136. package/lib/audit-rules/audit-rules-paths.yml +0 -98
  137. package/lib/audit-rules/audit-rules-performance.yml +0 -245
  138. package/lib/audit-rules/audit-rules-php.yml +0 -101
  139. package/lib/audit-rules/audit-rules-private.yml +0 -24
  140. package/lib/audit-rules/audit-rules-python.yml +0 -106
  141. package/lib/audit-rules/audit-rules-robustness.yml +0 -31
  142. package/lib/audit-rules/audit-rules-rust.yml +0 -109
  143. package/lib/audit-rules/audit-rules-structure.yml +0 -158
  144. package/lib/audit-rules/audit-rules-swift.yml +0 -99
  145. package/lib/audit-rules/audit-rules-template.yml +0 -108
  146. package/lib/audit-ui-sdk/contract.js +0 -117
  147. package/lib/audit-ui-sdk/index.js +0 -17
  148. package/lib/checks/button-bind.js +0 -347
  149. package/lib/checks/common.js +0 -170
  150. package/lib/checks/credential-file.js +0 -43
  151. package/lib/checks/dataflow.js +0 -40
  152. package/lib/checks/dispatch.js +0 -117
  153. package/lib/checks/dup-code.js +0 -69
  154. package/lib/checks/dup-const.js +0 -232
  155. package/lib/checks/file-health.js +0 -150
  156. package/lib/checks/filter.js +0 -137
  157. package/lib/checks/folder.js +0 -173
  158. package/lib/checks/fs-scanner.js +0 -57
  159. package/lib/checks/hardcoded-path.js +0 -98
  160. package/lib/checks/index.js +0 -49
  161. package/lib/checks/io.js +0 -66
  162. package/lib/checks/magic-number.js +0 -42
  163. package/lib/checks/npm-json.js +0 -273
  164. package/lib/checks/private.js +0 -64
  165. package/lib/checks/regex.js +0 -298
  166. package/lib/checks/scope-collision.js +0 -68
  167. package/lib/checks/semantic.js +0 -134
  168. package/lib/checks/structural.js +0 -281
  169. package/lib/cli/commands-audit.mjs +0 -142
  170. package/lib/cli/commands-doc.mjs +0 -127
  171. package/lib/client-parts/audit/audit.js +0 -301
  172. package/lib/exempt/tool.js +0 -198
  173. package/lib/git/module-splitter.js +0 -47
  174. package/lib/link-check/index.js +0 -187
  175. package/lib/lint-adapter/detect.js +0 -161
  176. package/lib/lint-adapter/index.js +0 -50
  177. package/lib/lint-adapter/runner.js +0 -133
  178. package/lib/preprocess/audit.js +0 -98
  179. package/lib/preprocess/index.js +0 -78
  180. package/lib/rule/compilers/credential.js +0 -62
  181. package/lib/rule/compilers/dataflow.js +0 -38
  182. package/lib/rule/compilers/file-health.js +0 -75
  183. package/lib/rule/compilers/frontend.js +0 -86
  184. package/lib/rule/compilers/func.js +0 -35
  185. package/lib/rule/compilers/helpers.js +0 -71
  186. package/lib/rule/compilers/index.js +0 -29
  187. package/lib/rule/compilers/link-semantic.js +0 -45
  188. package/lib/rule/compilers/list-kinds.js +0 -12
  189. package/lib/rule/compilers/numeric-kinds.js +0 -73
  190. package/lib/rule/compilers/regex.js +0 -78
  191. package/lib/rule/compilers/structure.js +0 -107
  192. package/lib/rule/compilers.js +0 -17
  193. package/lib/rule/homoglyph.js +0 -45
  194. package/lib/rule/loader.js +0 -274
  195. package/lib/rule/registry.js +0 -122
  196. package/lib/rule/scope.js +0 -67
  197. package/lib/score/docs-score.js +0 -166
  198. package/lib/score/index.js +0 -234
  199. package/lib/user-requirements.json +0 -15
  200. package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
  201. package/scripts/audit-ext/_example-readme-present.mjs +0 -34
  202. package/scripts/audit-ext/dsh-inject-declarations.mjs +0 -209
  203. package/scripts/audit-ext/variable-min-length.mjs +0 -102
  204. package/scripts/audit-gate.mjs +0 -235
  205. package/scripts/audit-runner.mjs +0 -35
  206. package/scripts/audit-runtime-check.mjs +0 -129
  207. package/scripts/browser-page-probe.mjs +0 -271
  208. package/scripts/build-client.mjs +0 -131
  209. package/scripts/bump-version.mjs +0 -178
  210. package/scripts/check-js-scope.mjs +0 -87
  211. package/scripts/check.mjs +0 -203
  212. package/scripts/clean-date-comments.py +0 -102
  213. package/scripts/cpu-sample.mjs +0 -188
  214. package/scripts/doc-drift.mjs +0 -200
  215. package/scripts/doc-func.mjs +0 -212
  216. package/scripts/doc-tree.mjs +0 -458
  217. package/scripts/doc-version.mjs +0 -149
  218. package/scripts/hot-path-probe-cjs.cjs +0 -71
  219. package/scripts/hot-path-probe-fs-shim.mjs +0 -28
  220. package/scripts/hot-path-probe-fsp-shim.mjs +0 -31
  221. package/scripts/hot-path-probe.mjs +0 -153
  222. package/scripts/local-registry.mjs +0 -37
  223. package/scripts/module-splitter.py +0 -800
  224. package/scripts/picker-repro.mjs +0 -115
  225. package/scripts/platform-scan.mjs +0 -168
  226. package/scripts/probe-recheck.mjs +0 -47
  227. package/scripts/rename-locator.mjs +0 -97
  228. package/scripts/rule-switch.mjs +0 -97
  229. package/scripts/rules-solo-audit.mjs +0 -173
  230. package/scripts/scan-file-io.mjs +0 -717
  231. package/scripts/scan-fs-hotspots.mjs +0 -107
  232. package/scripts/scan-version.mjs +0 -125
  233. package/scripts/symbol-index.mjs +0 -85
  234. package/scripts/verify-prestep.mjs +0 -100
  235. package/scripts/version-source.mjs +0 -173
  236. package/skills/dev/audit-rule-authoring.md +0 -58
  237. package/skills/guide/guide-audit.md +0 -270
  238. /package/lib/{audit → app}/ownership.js +0 -0
  239. /package/lib/{audit-defaults.js → git/defaults.js} +0 -0
@@ -1,178 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * dsh-git-push — 一键版本升版(bump-version)
4
- *
5
- * 为什么要有这个脚本:版本号散在三处手工同步,每次发版都要手改
6
- * ① `package.json` 的 version
7
- * ② `lib/self/index.js` 的 `export const VERSION = '<v>'; // <v>:说明。历史:…`
8
- * ③ `docs/releases.json` 新增一条 `<v>: "说明"`
9
- * 少改一处就会被 doc-version / version-drift 门禁判为漂移,而这两处还各带长文本
10
- * (VERSION 行还挂着历史链),手改既慢又容易写坏引号、破坏 JSON。
11
- * 第 4 处(README 版本表 / CHANGELOG)已由 doc-version.mjs 从上面两处生成,无需手改。
12
- *
13
- * 用法:
14
- * node scripts/bump-version.mjs --message "本次做了什么" # 预览(默认 dry-run)
15
- * node scripts/bump-version.mjs --message "…" --apply # 真写盘
16
- * node scripts/bump-version.mjs --to 2.11.0 --message "…" --apply # 指定版本(默认 patch +1)
17
- * node scripts/bump-version.mjs --message-file /tmp/msg.txt --apply
18
- * node scripts/bump-version.mjs --message "…" --comment "VERSION 行用的短摘要(可选)" --apply
19
- *
20
- * 约定:
21
- * · **默认 dry-run**——只打印将要改动的三处(旧值 → 新值),不落盘;确认无误再加 --apply。
22
- * (与 npm_publish / install-plugin 同口径:有副作用的动作先看预览再执行)
23
- * · `--message` 必填:发版说明不能凭空生成,属于「人写内容」,脚本只负责把它同步到三处。
24
- * · VERSION 行的历史链保留最近 2 个版本摘要,避免注释无限变长(沿用既有风格)。
25
- * · 写完自动重生成版本文档(doc-version apply / doc-func apply / doc-tree sync+apply),
26
- * 因为版本号一变,CHANGELOG 与函数索引必须跟着走,否则门禁立刻报漂移。
27
- */
28
- import { readFileSync, writeFileSync } from 'node:fs';
29
- import { join, dirname } from 'node:path';
30
- import { fileURLToPath } from 'node:url';
31
- import { execFileSync } from 'node:child_process';
32
-
33
- const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
34
- const PKG = join(ROOT, 'package.json');
35
- const SELF = join(ROOT, 'lib', 'self', 'index.js');
36
- const RELEASES = join(ROOT, 'docs', 'releases.json');
37
-
38
- /** 解析命令行参数(只认 --flag value 与布尔 --apply)。 */
39
- function parseArgs(argv) {
40
- const out = { apply: false, to: '', message: '', messageFile: '', comment: '' };
41
- for (let i = 0; i < argv.length; i++) {
42
- const a = argv[i];
43
- if (a === '--apply') { out.apply = true; continue; }
44
- if (a === '--message' || a === '-m') { out.message = argv[++i] || ''; continue; }
45
- if (a === '--message-file') { out.messageFile = argv[++i] || ''; continue; }
46
- if (a === '--to') { out.to = argv[++i] || ''; continue; }
47
- if (a === '--comment') { out.comment = argv[++i] || ''; continue; }
48
- }
49
- return out;
50
- }
51
-
52
- const fail = (msg) => { console.error('✗ ' + msg); process.exit(1); };
53
-
54
- /** 语义化版本比较:a < b 返回负。只支持 x.y.z。 */
55
- function cmpVer(a, b) {
56
- const pa = String(a).split('.').map(Number);
57
- const pb = String(b).split('.').map(Number);
58
- for (let i = 0; i < 3; i++) if ((pa[i] || 0) !== (pb[i] || 0)) return (pa[i] || 0) - (pb[i] || 0);
59
- return 0;
60
- }
61
-
62
- /** patch +1:默认每次提交升第三位(version-discipline 的既有口径)。 */
63
- function bumpPatch(v) {
64
- const [x, y, z] = String(v).split('.').map(Number);
65
- return `${x}.${y}.${(z || 0) + 1}`;
66
- }
67
-
68
- function readJson(p) {
69
- try { return JSON.parse(readFileSync(p, 'utf8')); } catch (e) { fail(`${p} 解析失败:${e.message}`); }
70
- }
71
-
72
- /**
73
- * 拼新的 VERSION 行。
74
- * 旧注释形如:`2.10.4:本次说明。历史:2.10.3:更早说明。` → 把「本次说明」降级进历史链,
75
- * 只保留最近 2 条,避免每版都把整串历史再抄一遍(实测 2.9.x 之后该行已接近不可读)。
76
- *
77
- * ⚠️ **行注释必须单行**:`--message-file` 常带多段落,若原样写进 `//` 后面的注释,
78
- * 换行会把文件撕成多行 → 整个 lib/self/index.js 语法错误(ESM 加载期就炸,
79
- * `node cli.mjs` 直接 TypeError)。故此处按「首段首句」压成一行摘要,
80
- * 正文完整内容仍原样进 docs/releases.json(那边是 JSON 字符串,换行合法)。
81
- * 需要更长摘要时用 `--comment` 显式给。
82
- */
83
- function buildVersionLine(oldLine, newVer, oldVer, message, commentOverride = '') {
84
- const m = /export const VERSION = '([^']+)';\s*\/\/(.*)$/.exec(oldLine);
85
- const oldComment = m ? m[2].trim() : '';
86
- // 旧版本的「本次说明」= 历史链之前的那一段
87
- const histIdx = oldComment.indexOf('历史:');
88
- const oldMain = (histIdx >= 0 ? oldComment.slice(0, histIdx) : oldComment).replace(/^[\d.]+\s*[::]\s*/, '').trim();
89
- const oldHist = histIdx >= 0 ? oldComment.slice(histIdx + '历史:'.length).trim() : '';
90
- // 历史链:新压入的旧版摘要 + 原有最近 1 条
91
- const prev = oldMain ? [`${oldVer}:${oldMain}`] : [];
92
- const kept = oldHist ? oldHist.split(/。\s*(?=[\d.]+:)/).slice(0, 1).map((s) => s.replace(/。$/, '')) : [];
93
- const chain = prev.length || kept.length ? [...prev, ...kept].join('。').replace(/。+/g, '。') : '';
94
- // 本轮摘要:显式覆盖优先;否则取首段首句,超长截断
95
- const oneLine = String(commentOverride || message).replace(/\s+/g, ' ').trim();
96
- const firstSentence = oneLine.split(/。/)[0].trim();
97
- const summary = firstSentence.length > 160 ? `${firstSentence.slice(0, 160)}…` : firstSentence;
98
- const comment = `${newVer}:${summary}。` + (chain ? `历史:${chain}。` : '');
99
- return `export const VERSION = '${newVer}'; // ${comment}`;
100
- }
101
-
102
- const args = parseArgs(process.argv.slice(2));
103
- const pkg = readJson(PKG);
104
- const cur = String(pkg.version || '');
105
- const target = args.to || bumpPatch(cur);
106
- let message = args.message;
107
- if (args.messageFile) {
108
- try { message = readFileSync(args.messageFile, 'utf8').trim(); } catch (e) { fail(`--message-file 读取失败:${e.message}`); }
109
- }
110
- if (!/^\d+\.\d+\.\d+$/.test(target)) fail(`版本号必须为 x.y.z:${target}`);
111
- if (cmpVer(target, cur) <= 0) fail(`目标版本 ${target} 必须大于当前 ${cur}`);
112
- if (!message) fail('缺少 --message(发版说明需人写;或从 --message-file 读取)');
113
-
114
- const releases = readJson(RELEASES);
115
- if (releases[target]) fail(`docs/releases.json 已存在 ${target} 条目(不要重复升版)`);
116
-
117
- const selfSrc = readFileSync(SELF, 'utf8');
118
- const selfLines = selfSrc.split('\n');
119
- const vi = selfLines.findIndex((l) => /^export const VERSION = '/.test(l));
120
- if (vi < 0) fail('lib/self/index.js 未找到 VERSION 行');
121
- const oldLine = selfLines[vi];
122
- const newLine = buildVersionLine(oldLine, target, cur, message, args.comment);
123
- // 硬门禁:行注释一旦带换行就把整个 lib/self/index.js 撕成多行(ESM 加载期直接抛
124
- // "Invalid or unexpected token",cli.mjs / 插件入口全部起不来)。宁可在写盘前失败。
125
- if (/[\r\n]/.test(newLine)) fail('VERSION 行必须是单行(注释里的换行会破坏整个模块语法)');
126
-
127
- // ── 预览(默认 dry-run)
128
- console.log(`升版:${cur} → ${target}${args.apply ? '(--apply 真写盘)' : '(dry-run,未写盘)'}`);
129
- console.log('\n① package.json');
130
- console.log(` - "version": "${cur}"`);
131
- console.log(` + "version": "${target}"`);
132
- console.log('\n② lib/self/index.js(VERSION 行)');
133
- console.log(` - ${oldLine.slice(0, 90)}…`);
134
- console.log(` + ${newLine.slice(0, 90)}…`);
135
- console.log('\n③ docs/releases.json');
136
- console.log(` + "${target}": "${message.slice(0, 70)}${message.length > 70 ? '…' : ''}"`);
137
- console.log('\n④ 随后自动重生成:docs/CHANGELOG.md(doc-version)、docs/FUNCTIONS.md(doc-func)、tree-doc.json(doc-tree)');
138
-
139
- if (!args.apply) {
140
- console.log('\n确认无误后追加 --apply 才会写盘。');
141
- process.exit(0);
142
- }
143
-
144
- // ── 写盘
145
- // 注意:本仓库在 CIFS 挂载上,write/edit 工具会因 chmod 报 EPERM;脚本用 fs 直接写
146
- // 普通文件(不触发 chmod),这正是把它脚本化的额外收益。
147
- const newPkgText = readFileSync(PKG, 'utf8').replace(
148
- /("version"\s*:\s*")[^"]+(")/,
149
- `$1${target}$2`,
150
- );
151
- if (newPkgText === readFileSync(PKG, 'utf8')) fail('package.json 的 version 未替换成功(正则未命中)');
152
- writeFileSync(PKG, newPkgText);
153
-
154
- selfLines[vi] = newLine;
155
- writeFileSync(SELF, selfLines.join('\n'));
156
-
157
- const merged = { ...releases };
158
- merged[target] = message;
159
- // 按语义化版本排序,保持文件可读(原文件即按版本升序)
160
- const sorted = {};
161
- for (const k of Object.keys(merged).sort(cmpVer)) sorted[k] = merged[k];
162
- writeFileSync(RELEASES, JSON.stringify(sorted, null, 2) + '\n');
163
-
164
- console.log('\n✔ 三处已写入,重生成派生文档…');
165
- for (const cmd of [
166
- ['scripts/doc-version.mjs', ['apply']],
167
- ['scripts/doc-func.mjs', ['apply']],
168
- ['scripts/doc-tree.mjs', ['sync']],
169
- ['scripts/doc-tree.mjs', ['apply']],
170
- ]) {
171
- try {
172
- execFileSync(process.execPath, [join(ROOT, cmd[0]), ...cmd[1]], { cwd: ROOT, stdio: 'pipe', encoding: 'utf8' });
173
- console.log(` ✔ ${cmd[0]} ${cmd[1].join(' ')}`);
174
- } catch (e) {
175
- console.error(` ✗ ${cmd[0]} 失败:${String(e?.stdout || e?.stderr || e).split('\n')[0]}`);
176
- }
177
- }
178
- console.log(`\n完成:${cur} → ${target}。请跑 node scripts/doc-version.mjs check 与全量回归确认门禁绿。`);
@@ -1,87 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * 拼接产物作用域撞名检查(独立 CLI;判定与策略逻辑在 lib/,与 `git-sluice scope-check` 同一份)。
4
- *
5
- * 用法:
6
- * node scripts/check-js-scope.mjs <file.js> [...] [--prefix=dshgp_] [--allowlist=a,b] [--top=true|false] [--json]
7
- * node scripts/check-js-scope.mjs --config package.json # 读该 package.json 的 dshScopeCheck.files
8
- *
9
- * 参数名与 `git-sluice scope-check` 对齐(allowlist,旧写法 --allow 仍认)。
10
- * 约定按**文件所属项目**取:别人项目没声明 dshScopeCheck 时只查「同帧重名」,
11
- * 不会拿本项目的 dshgp_ 前缀去要求它(实测:那会刷一屏与它无关的告警)。
12
- */
13
- import { readFileSync, existsSync } from 'node:fs';
14
- import { dirname, join, resolve } from 'node:path';
15
- import { fileURLToPath } from 'node:url';
16
-
17
- import { runScopeCheck } from '../lib/app/scope-check.js';
18
-
19
- const HERE = dirname(fileURLToPath(import.meta.url));
20
- const argv = process.argv.slice(2);
21
- const VALUE_FLAGS = new Set(['config', 'prefix', 'allowlist', 'allow', 'top']);
22
-
23
- const { flags, positional } = (() => {
24
- const out = { flags: new Map(), positional: [] };
25
- for (let i = 0; i < argv.length; i += 1) {
26
- const token = argv[i];
27
- if (!token.startsWith('--')) { out.positional.push(token); continue; }
28
- const body = token.slice(2);
29
- if (body.includes('=')) {
30
- const [k, ...rest] = body.split('=');
31
- out.flags.set(k, rest.join('='));
32
- continue;
33
- }
34
- if (VALUE_FLAGS.has(body) && i + 1 < argv.length && !argv[i + 1].startsWith('--')) {
35
- out.flags.set(body, argv[i + 1]);
36
- i += 1;
37
- continue;
38
- }
39
- out.flags.set(body, 'true');
40
- }
41
- return out;
42
- })();
43
- const wantJson = flags.has('json');
44
-
45
- /** --config 指定的项目:只用它的 files 列表,**不**把它的 prefix 套给别的项目文件。 */
46
- function filesFromConfig(path) {
47
- if (!path || !existsSync(path)) return [];
48
- try {
49
- const cfg = JSON.parse(readFileSync(path, 'utf8'))?.dshScopeCheck;
50
- const base = dirname(resolve(path));
51
- return Array.isArray(cfg?.files) ? cfg.files.map((f) => resolve(base, f)) : [];
52
- } catch { return []; }
53
- }
54
-
55
- const configPath = flags.get('config') || '';
56
- const targets = positional.length ? positional.map((f) => resolve(f)) : filesFromConfig(configPath);
57
- if (!targets.length) {
58
- console.error('用法:node scripts/check-js-scope.mjs <file.js> [...] [--prefix=dshgp_] [--allowlist=a,b] [--json]');
59
- console.error(' 或 node scripts/check-js-scope.mjs --config package.json(读 dshScopeCheck.files)');
60
- process.exit(2);
61
- }
62
-
63
- const topFlag = flags.get('top');
64
- const result = runScopeCheck({
65
- files: targets,
66
- prefix: flags.get('prefix') || '',
67
- // allowlist 为主名(与 git-sluice scope-check 对齐),allow 是旧写法别名
68
- allowlist: String(flags.get('allowlist') || flags.get('allow') || '').split(',').map((x) => x.trim()).filter(Boolean),
69
- ...(topFlag === 'true' || topFlag === 'false' ? { topLevelMustBeEmpty: topFlag === 'true' } : {}),
70
- });
71
-
72
- if (wantJson) {
73
- console.log(JSON.stringify(result, null, 2));
74
- } else {
75
- // 输出头自证策略来源:避免「继承了本项目默认值」被误读成对方的约定
76
- for (const src of result.policySources) console.log(`策略来源:${src}`);
77
- for (const r of result.reports) {
78
- const rel = r.file.replace(process.cwd() + '/', '');
79
- if (r.ok) {
80
- console.log(`✔ ${rel}:${r.declarations.length} 个声明,无同帧重名`);
81
- } else {
82
- console.error(`✗ ${rel}:`);
83
- for (const v of r.violations) console.error(` - ${v}`);
84
- }
85
- }
86
- }
87
- process.exit(result.ok ? 0 : 1);
package/scripts/check.mjs DELETED
@@ -1,203 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * 语法检查脚本(npm run check)
4
- * 递归检查 lib/****.js + cli.mjs 语法;任一失败退出 1(checkSyncInAsync 的脚本侧实现)。
5
- *
6
- * 2026-10-09(任务.md C8 分片改造)新增两条:
7
- * ① **跳过 `lib/client-parts/`**:那是客户端**分片源码**——单个分片是片段(首片开 `factory`、
8
- * 尾片收尾),单独 `node --check` 必然失败;语法检查只对**产物** `lib/client.js` 做。
9
- * ② **产物新鲜度门禁**:`lib/client.js` 必须与分片按 PART_ORDER 拼出来的一致,
10
- * 防止有人直接手改产物(下次构建就被覆盖,改动静默丢失)。
11
- */
12
- import { execFileSync } from 'node:child_process';
13
- import { readdirSync, statSync, readFileSync } from 'node:fs';
14
- import { join, dirname } from 'node:path';
15
- import { fileURLToPath } from 'node:url';
16
- import { buildClient } from './build-client.mjs';
17
-
18
- const __dirname = dirname(fileURLToPath(import.meta.url));
19
- const ROOT = join(__dirname, '..');
20
-
21
- /** 递归收集 .js 文件(跳过 node_modules、点开头目录,以及分片目录 client-parts)。 */
22
- function collectJs(dir, acc = []) {
23
- for (const name of readdirSync(dir)) {
24
- if (name === 'node_modules' || name.startsWith('.')) continue;
25
- if (name === 'client-parts') continue; // 分片是片段,见文件头 ①
26
- const p = join(dir, name);
27
- if (statSync(p).isDirectory()) collectJs(p, acc);
28
- else if (name.endsWith('.js')) acc.push(p);
29
- }
30
- return acc;
31
- }
32
-
33
- /** 递归收集 .json(同样的跳过规则,但不跳过 client-parts——那里没有 .json)。 */
34
- function collectJson(dir, acc = []) {
35
- for (const name of readdirSync(dir)) {
36
- if (name === 'node_modules' || name.startsWith('.')) continue;
37
- const p = join(dir, name);
38
- if (statSync(p).isDirectory()) collectJson(p, acc);
39
- else if (name.endsWith('.json')) acc.push(p);
40
- }
41
- return acc;
42
- }
43
-
44
- // 三个 CLI 入口都要做语法检查:它们不是 lib/ 下的文件,靠 collectJs 收不到——
45
- // 漏检的后果是「新入口语法错,但门禁全绿」(与被拆出来的入口一起构成盲区)。
46
- const CLI_ENTRIES = ['cli.mjs', 'cli-audit.mjs', 'cli-tool.mjs'].map((name) => join(ROOT, name));
47
- const files = [...collectJs(join(ROOT, 'lib')), ...CLI_ENTRIES];
48
- // docs/*.json 也必须能解析:版本表与发版说明直接依赖 docs/releases.json,
49
- // 而它曾在 2.8.4 因一个尾随逗号变成非法 JSON 却**四项门禁全绿**(缺口)——这类错误必须在门禁里变红 ✗
50
- const jsonFiles = [...collectJson(join(ROOT, 'lib')), ...collectJson(join(ROOT, 'docs'))];
51
- let fail = 0;
52
- let jsonFail = 0;
53
- for (const f of files) {
54
- try {
55
- execFileSync(process.execPath, ['--check', f], { stdio: 'pipe', encoding: 'utf8' });
56
- console.log(`✔ ${f.replace(ROOT + '/', '')}`);
57
- } catch (e) {
58
- fail++;
59
- console.error(`✗ ${f.replace(ROOT + '/', '')}: ${String(e?.stderr || e).trim().split('\n')[0]}`);
60
- }
61
- }
62
-
63
- // JSON 可解析性门禁(独立计数,不并入上面的语法通过率)
64
- for (const f of jsonFiles) {
65
- try {
66
- JSON.parse(readFileSync(f, 'utf8'));
67
- console.log(`✔ ${f.replace(ROOT + '/', '')}`);
68
- } catch (e) {
69
- jsonFail++;
70
- console.error(`✗ ${f.replace(ROOT + '/', '')}: JSON 解析失败——${String(e?.message || e).split('\n')[0]}`);
71
- }
72
- }
73
-
74
- // 产物新鲜度:client.js 必须是分片构建出来的那一份
75
- try {
76
- const built = buildClient();
77
- const current = readFileSync(join(ROOT, 'lib', 'client.js'), 'utf8');
78
- if (built === current) {
79
- console.log('✔ lib/client.js 与分片一致(构建产物新鲜)');
80
- } else {
81
- fail++;
82
- console.error('✗ lib/client.js 与分片不一致——请运行 node scripts/build-client.mjs 重新生成(不要手改产物)');
83
- }
84
- } catch (e) {
85
- fail++;
86
- console.error(`✗ 分片构建校验失败:${e.message}`);
87
- }
88
-
89
- // ── 拼接产物作用域门禁(2026-11-05)───────────────────────────────────
90
- // 背景:lib/client-parts/*.js 是**平铺拼接**的片段,14 个分片最终落在**同一个 factory
91
- // 函数作用域**里。JS 的 var/function 提升规则是「同名后者覆盖前者且不报错」——
92
- // 一处重名就让某分片功能在运行时静默失效,且没有任何报错可查。
93
- // 构建脚本头部早写了「顶层零声明 + dshgp_ 前缀」两条铁律,但此前**只是注释**:
94
- // 新鲜度门禁只保证「产物 == 分片拼接」,保证不了「拼出来的不撞名」。
95
- // 检查项(通用实现在 lib/ast/scope-collisions.js,项目差异走 package.json 的 dshScopeCheck):
96
- // ① 同作用域重名(var/function 静默覆盖的触发条件,始终检查);
97
- // ② 文件顶层零声明;③ 共享作用域命名前缀。
98
- try {
99
- const { analyzeScopeCollisions } = await import('../lib/ast/scope-collisions.js');
100
- const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
101
- const cfg = pkg?.dshScopeCheck;
102
- const files = Array.isArray(cfg?.files) && cfg.files.length ? cfg.files : [];
103
- if (!files.length) {
104
- console.log('✔ 拼接产物作用域:未配置 dshScopeCheck.files,跳过');
105
- }
106
- for (const rel of files) {
107
- const abs = join(ROOT, rel);
108
- const scope = analyzeScopeCollisions(readFileSync(abs, 'utf8'), {
109
- prefix: String(cfg.prefix || ''),
110
- allowlist: Array.isArray(cfg.allowlist) ? cfg.allowlist.map(String) : [],
111
- topLevelMustBeEmpty: cfg.topLevelMustBeEmpty !== false,
112
- });
113
- if (scope.ok) {
114
- console.log(`✔ ${rel} 作用域契约(顶层零声明 · 共享作用域 ${scope.declarations.filter((d) => d.frameId === scope.sharedFrameId).length} 个声明均合规 · 无同帧重名)`);
115
- } else {
116
- fail += 1;
117
- for (const v of scope.violations) console.error(`✗ ${rel} 作用域:${v}`);
118
- }
119
- }
120
- } catch (e) {
121
- fail += 1;
122
- console.error(`✗ 拼接产物作用域检查失败:${e.message}`);
123
- }
124
-
125
- // ── 层边界门禁(2026-10-24)────────────────────────────────────────────
126
- // 背景:审计引擎与提交推送**决定不拆成两个 npm 包**(拆包的持续成本——双包版本同步、
127
- // 固定发布顺序、依赖范围——换不到真实收益:外部使用者要的是「提交前拦截」这个整体,
128
- // 而「脱离 DSH 跑审计」已由 cli.mjs 的独立 CLI 覆盖)。
129
- // 但不拆包不等于放弃边界:审计层对 git 层是**实测零依赖**,这个事实一旦被顺手 import
130
- // 侵蚀就再也回不来(历史包袱太重 = 不可逆)。所以把它钉成门禁。
131
- // 不变量:
132
- // ① 审计层任何文件都不得 import git/npm/commit-push 层(方向唯一:git → audit);
133
- // ② 反向接缝数量有预算上限——允许存在(提交门禁必须调审计),但要能看见它在膨胀。
134
- // lint-adapter(外部 linter 委托层)纳入审计层口径:编排层(audit)直接依赖它 ⇒ 它属于审计子图,
135
- // 同样不得伸手 git 层(委托层只读项目文件 + 跑外部二进制,不需要凭据/git)。
136
- const AUDIT_DIRS = new Set(['ast', 'audit', 'audit-rules', 'checks', 'exempt', 'rule', 'score', 'lint-adapter']);
137
- const GIT_DIRS = new Set(['git', 'npm']);
138
- const GIT_TOP = new Set(['commit-push.js']);
139
- const AUDIT_TOP = new Set(['audit-defaults.js', 'skip-dirs.js']);
140
- /**
141
- * 反向接缝预算:实测 **5 处**;上调需写明理由。
142
- *
143
- * 2026-11-13 从 7 降到 5:提交前预处理解耦后,`lib/commit-push.js` 不再 import `audit/index.js` 与
144
- * `score/index.js`(改调外部引擎子进程),只剩 `exempt/index.js` 这一条(示例目录豁免要用)。
145
- * 预算跟着实收紧,是为了让这个成果**被门禁钉住**——以后谁再往 git 侧加审计 import,5→6 就会红。
146
- */
147
- const SEAM_BUDGET = 5;
148
-
149
- const layerOf = (rel) => {
150
- const top = rel.split('/')[0];
151
- if (rel.includes('/') && AUDIT_DIRS.has(top)) return 'AUDIT';
152
- if (rel.includes('/') && GIT_DIRS.has(top)) return 'GIT';
153
- if (!rel.includes('/') && GIT_TOP.has(rel)) return 'GIT';
154
- if (!rel.includes('/') && AUDIT_TOP.has(rel)) return 'AUDIT';
155
- return 'OTHER';
156
- };
157
-
158
- let boundaryViolations = 0;
159
- const seams = [];
160
- for (const f of files) {
161
- const rel = f.replace(ROOT + '/', '');
162
- if (!rel.startsWith('lib/')) continue;
163
- const inner = rel.slice('lib/'.length);
164
- if (layerOf(inner) !== 'AUDIT') continue;
165
- let src = '';
166
- try { src = readFileSync(f, 'utf8'); } catch { continue; }
167
- for (const m of src.matchAll(/from\s+['"](\.[^'"]+)['"]/g)) {
168
- const target = join(dirname(f), m[1]).replace(ROOT + '/lib/', '');
169
- if (layerOf(target) === 'GIT') {
170
- boundaryViolations++;
171
- console.error(`✗ 层边界违规:审计层 lib/${inner} import 了 git 层 ${m[1]}(审计引擎解耦)`);
172
- }
173
- }
174
- }
175
- // 反向接缝统计(允许,但要可见)
176
- for (const f of files) {
177
- const rel = f.replace(ROOT + '/', '');
178
- if (!rel.startsWith('lib/')) continue;
179
- const inner = rel.slice('lib/'.length);
180
- if (layerOf(inner) !== 'GIT') continue;
181
- let src = '';
182
- try { src = readFileSync(f, 'utf8'); } catch { continue; }
183
- for (const m of src.matchAll(/from\s+['"](\.[^'"]+)['"]/g)) {
184
- const target = join(dirname(f), m[1]).replace(ROOT + '/lib/', '');
185
- if (layerOf(target) === 'AUDIT') seams.push(`${inner} → ${target}`);
186
- }
187
- }
188
- if (boundaryViolations) {
189
- fail += boundaryViolations;
190
- console.error(`✗ 层边界:${boundaryViolations} 处违规——审计层不得依赖 git/npm/commit-push`);
191
- } else {
192
- console.log(`✔ 层边界:审计层对 git 层 0 依赖(解耦成立)`);
193
- }
194
- if (seams.length > SEAM_BUDGET) {
195
- fail++;
196
- console.error(`✗ 反向接缝 ${seams.length} 处 > 预算 ${SEAM_BUDGET}:提交门禁调审计是必需的,但膨胀说明边界在糊掉——要么收敛,要么改预算并写明理由`);
197
- } else {
198
- console.log(`✔ 反向接缝(git → audit,唯一耦合面):${seams.length}/${SEAM_BUDGET} 处`);
199
- }
200
-
201
- console.log(`\n${files.length - fail}/${files.length} 文件语法通过`);
202
- console.log(`${jsonFiles.length - jsonFail}/${jsonFiles.length} 个 JSON 可解析`);
203
- process.exitCode = (fail > 0 || jsonFail > 0) ? 1 : 0;
@@ -1,102 +0,0 @@
1
- #!/usr/bin/env python3
2
- """清理代码注释里的日期(YYYY-MM-DD),保留解释文字。
3
- 用法:python3 clean-date-comments.py <root> [--dry-run] [--write]
4
- 规则(2026-10-05 扩展:注释内任意位置的标准日期都清,注释/字符串正文不动):
5
- 1. 行首注释日期前缀:^(\s*)(//|#|\*|/\*)\s*202\d[-/]\d{1,2}[-/]\d{1,2}\s*[::]?\s* → $1$2
6
- 2. 行内注释日期前缀:(//)\s*202\d... → $1
7
- 3. 行首注释内括号括注日期:(2026-09-13 修)→(修);(2026-09-13)→ 删括号
8
- 安全:
9
- - 只在注释行处理(行首 // # *,或行内含 // 的代码行尾注释);正文 "2026-01-01" 字符串不动
10
- - 只删注释里的日期;正文里的日期(数据值/版本号)不动
11
- - dry-run 默认(只统计不写盘)
12
- """
13
- import os
14
- import re
15
- import sys
16
-
17
- # 行首注释日期前缀(//、#、*、/* 后紧跟日期)
18
- LEADING_RE = re.compile(r'^(\s*)(//|#|\*|/\*)\s*20\d{2}[-/]\d{1,2}[-/]\d{1,2}\s*[::]?\s*')
19
- # 行内注释日期前缀(代码后 // 日期)
20
- INLINE_RE = re.compile(r'(//)\s*20\d{2}[-/]\d{1,2}[-/]\d{1,2}\s*[::]?\s*')
21
- # 行首注释内的括号括注日期(增):(修)→(修);→ 删括号
22
- PAREN_DATE = re.compile(r'[((]\s*20\d{2}[-/.]\d{1,2}[-/.]\d{1,2}\s*[))]') # (2026-09-13)
23
- PAREN_DATE_W = re.compile(r'[((]\s*(20\d{2}[-/.]\d{1,2}[-/.]\d{1,2})[,,、\s]+([^))]*?)\s*[))]') # (2026-09-13 修)/ (2026-10-02,非 dsh 插件误报消除)
24
- # 文件级豁免:这些文件允许日期(变更记录/版权)
25
- EXEMPT_FILES = {'CHANGELOG.md', 'LICENSE', 'README.md', 'FUNCTIONS.md'}
26
-
27
-
28
- def clean_line(line):
29
- changed = False
30
- new = line
31
- # 行首注释(独占注释行或行首)
32
- new, n1 = LEADING_RE.subn(r'\g<1>\g<2> ', new)
33
- changed = changed or n1 > 0
34
- if not changed:
35
- # 行内注释(代码行尾)——只在非行首位置找 // 日期
36
- new, n2 = INLINE_RE.subn(r'\g<1> ', new)
37
- changed = changed or n2 > 0
38
- # 行首注释里的括号括注日期(增:规则 comment/no-date-in-comment 匹配注释内任意日期)
39
- if new.lstrip().startswith(('//', '#', '*', '/*')):
40
- new3, n3 = PAREN_DATE_W.subn(r'(\2)', new)
41
- new3, n3b = PAREN_DATE_W.subn(r'(\2)', new3)
42
- new3, n4 = PAREN_DATE.subn('', new3)
43
- new3, n4b = PAREN_DATE.subn('', new3)
44
- if n3 + n3b + n4 + n4b > 0:
45
- new3 = re.sub(r'\s{2,}', ' ', new3).replace('( ', '(').replace('( ', '(')
46
- new = new3
47
- changed = True
48
- return new, changed
49
-
50
-
51
- def main():
52
- root = sys.argv[1] if len(sys.argv) > 1 else '.'
53
- dry_run = '--dry-run' in sys.argv or '--write' not in sys.argv
54
- write = '--write' in sys.argv
55
- total = 0
56
- changed_files = 0
57
- skipped = 0
58
- if os.path.isfile(root):
59
- # 单文件模式:直接处理该文件(不限扩展名白名单,方便单测)
60
- entries = [(os.path.dirname(root), [os.path.basename(root)])]
61
- else:
62
- entries = []
63
- for dirpath, dirnames, filenames in os.walk(root):
64
- dirnames[:] = [d for d in dirnames if d not in ('.git', 'node_modules', '.trash', 'dist', 'build')]
65
- entries.append((dirpath, filenames))
66
- for dirpath, filenames in entries:
67
- for fn in filenames:
68
- if not os.path.isfile(os.path.join(dirpath, fn)):
69
- continue
70
- if not (os.path.isfile(root) or fn.endswith(('.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.py'))):
71
- continue
72
- if fn in EXEMPT_FILES:
73
- continue
74
- full = os.path.join(dirpath, fn)
75
- try:
76
- with open(full, 'r', encoding='utf-8') as f:
77
- lines = f.readlines()
78
- except (UnicodeDecodeError, PermissionError):
79
- skipped += 1
80
- continue
81
- new_lines = []
82
- file_changed = 0
83
- for line in lines:
84
- nl, c = clean_line(line)
85
- if c:
86
- file_changed += 1
87
- total += 1
88
- new_lines.append(nl)
89
- if file_changed:
90
- changed_files += 1
91
- if write:
92
- with open(full, 'w', encoding='utf-8') as f:
93
- f.writelines(new_lines)
94
- else:
95
- print(f' {full}: {file_changed} 处')
96
- print(f'{"[dry-run] " if dry_run else ""}共 {total} 处日期前缀,{changed_files} 个文件(跳过 {skipped} 不可读)')
97
- if dry_run:
98
- print('dry-run 未写盘;加 --write 应用')
99
-
100
-
101
- if __name__ == '__main__':
102
- main()