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.
Files changed (278) hide show
  1. package/.auditignore +30 -0
  2. package/.gitignore +39 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1482 -2
  5. package/cli.mjs +360 -0
  6. package/cordis.patch.yml +14 -0
  7. package/lib/ARCHITECTURE.md +34 -0
  8. package/lib/BUGFIX-NOTES-2026-09-14.md +278 -0
  9. package/lib/app/apply.js +275 -0
  10. package/lib/app/audit-api.js +158 -0
  11. package/lib/app/command-registry.js +262 -0
  12. package/lib/app/constants.js +16 -0
  13. package/lib/app/handlers/account.js +166 -0
  14. package/lib/app/handlers/clone.js +168 -0
  15. package/lib/app/handlers/http-constants.js +9 -0
  16. package/lib/app/handlers/identity-rewrite.js +94 -0
  17. package/lib/app/handlers/meta.js +175 -0
  18. package/lib/app/handlers/npm.js +169 -0
  19. package/lib/app/handlers/repo-actions.js +143 -0
  20. package/lib/app/handlers/repos.js +231 -0
  21. package/lib/app/handlers/settings.js +62 -0
  22. package/lib/app/host-doc-checks.js +25 -0
  23. package/lib/app/http-handlers.js +131 -0
  24. package/lib/app/index.js +30 -0
  25. package/lib/app/inject-text.js +191 -0
  26. package/lib/app/scan-root.js +23 -0
  27. package/lib/app/schema.js +150 -0
  28. package/lib/app/settings-bridge.js +167 -0
  29. package/lib/app/slash-commands.js +395 -0
  30. package/lib/app/slot-stats.js +35 -0
  31. package/lib/app/tool-call.js +662 -0
  32. package/lib/app/tools.js +40 -0
  33. package/lib/ast/brace.js +105 -0
  34. package/lib/ast/callgraph.js +135 -0
  35. package/lib/ast/code-lines.js +114 -0
  36. package/lib/ast/consts.js +12 -0
  37. package/lib/ast/control-flow.js +461 -0
  38. package/lib/ast/credential.js +199 -0
  39. package/lib/ast/dataflow.js +274 -0
  40. package/lib/ast/dup-code.js +165 -0
  41. package/lib/ast/index.js +36 -0
  42. package/lib/ast/io-risk-const.js +95 -0
  43. package/lib/ast/io-risk-fn.js +208 -0
  44. package/lib/ast/io-risk-loop.js +308 -0
  45. package/lib/ast/io-risk.js +314 -0
  46. package/lib/ast/lang.js +156 -0
  47. package/lib/ast/line-count.js +52 -0
  48. package/lib/ast/magic-number.js +272 -0
  49. package/lib/ast/naming.js +284 -0
  50. package/lib/ast/perf.js +472 -0
  51. package/lib/ast/scope.js +241 -0
  52. package/lib/ast/shell.js +131 -0
  53. package/lib/ast/size.js +378 -0
  54. package/lib/ast/symbol-index.js +399 -0
  55. package/lib/ast/tokenizer.js +341 -0
  56. package/lib/audit/analysis-coverage.js +98 -0
  57. package/lib/audit/audit-file.js +182 -0
  58. package/lib/audit/checks.js +17 -0
  59. package/lib/audit/client-entry.js +93 -0
  60. package/lib/audit/collector.js +477 -0
  61. package/lib/audit/ext-runner.js +80 -0
  62. package/lib/audit/file-context.js +138 -0
  63. package/lib/audit/finding.js +50 -0
  64. package/lib/audit/gitignore-match.js +113 -0
  65. package/lib/audit/glob.js +63 -0
  66. package/lib/audit/history-report.js +100 -0
  67. package/lib/audit/history.js +126 -0
  68. package/lib/audit/ignore-blind.js +101 -0
  69. package/lib/audit/index.js +33 -0
  70. package/lib/audit/orchestrate.js +476 -0
  71. package/lib/audit/public.js +24 -0
  72. package/lib/audit/repo-level.js +30 -0
  73. package/lib/audit/report-yaml.js +86 -0
  74. package/lib/audit/slot.js +65 -0
  75. package/lib/audit-defaults.js +18 -0
  76. package/lib/audit-rules/audit-rules-comment.yml +247 -0
  77. package/lib/audit-rules/audit-rules-cpp.yml +22 -0
  78. package/lib/audit-rules/audit-rules-docs.yml +32 -0
  79. package/lib/audit-rules/audit-rules-dsh.yml +162 -0
  80. package/lib/audit-rules/audit-rules-filehealth.yml +42 -0
  81. package/lib/audit-rules/audit-rules-folder.yml +99 -0
  82. package/lib/audit-rules/audit-rules-frontend.yml +335 -0
  83. package/lib/audit-rules/audit-rules-go.yml +22 -0
  84. package/lib/audit-rules/audit-rules-i18n.yml +45 -0
  85. package/lib/audit-rules/audit-rules-java.yml +105 -0
  86. package/lib/audit-rules/audit-rules-nodejs.yml +647 -0
  87. package/lib/audit-rules/audit-rules-npm.yml +187 -0
  88. package/lib/audit-rules/audit-rules-paths.yml +92 -0
  89. package/lib/audit-rules/audit-rules-performance.yml +207 -0
  90. package/lib/audit-rules/audit-rules-php.yml +22 -0
  91. package/lib/audit-rules/audit-rules-private.yml +24 -0
  92. package/lib/audit-rules/audit-rules-python.yml +106 -0
  93. package/lib/audit-rules/audit-rules-robustness.yml +27 -0
  94. package/lib/audit-rules/audit-rules-rust.yml +22 -0
  95. package/lib/audit-rules/audit-rules-structure.yml +159 -0
  96. package/lib/audit-rules/audit-rules-swift.yml +22 -0
  97. package/lib/audit-rules/audit-rules-template.yml +108 -0
  98. package/lib/checks/button-bind.js +276 -0
  99. package/lib/checks/common.js +170 -0
  100. package/lib/checks/credential-file.js +43 -0
  101. package/lib/checks/dataflow.js +40 -0
  102. package/lib/checks/dispatch.js +112 -0
  103. package/lib/checks/dup-code.js +69 -0
  104. package/lib/checks/dup-const.js +232 -0
  105. package/lib/checks/file-health.js +150 -0
  106. package/lib/checks/filter.js +131 -0
  107. package/lib/checks/folder.js +173 -0
  108. package/lib/checks/hardcoded-path.js +98 -0
  109. package/lib/checks/index.js +46 -0
  110. package/lib/checks/io.js +66 -0
  111. package/lib/checks/magic-number.js +42 -0
  112. package/lib/checks/npm-json.js +273 -0
  113. package/lib/checks/private.js +63 -0
  114. package/lib/checks/regex.js +256 -0
  115. package/lib/checks/semantic.js +134 -0
  116. package/lib/checks/structural.js +274 -0
  117. package/lib/cli/commands-account.mjs +107 -0
  118. package/lib/cli/commands-audit.mjs +144 -0
  119. package/lib/cli/commands-doc.mjs +127 -0
  120. package/lib/cli/commands-vcs.mjs +175 -0
  121. package/lib/client/index.js +162 -0
  122. package/lib/client-parts/00-loader.js +33 -0
  123. package/lib/client-parts/01-const.js +207 -0
  124. package/lib/client-parts/02-utils.js +62 -0
  125. package/lib/client-parts/03-icons.js +12 -0
  126. package/lib/client-parts/10-account.js +83 -0
  127. package/lib/client-parts/11-browser.js +95 -0
  128. package/lib/client-parts/20-repo.js +374 -0
  129. package/lib/client-parts/21-audit.js +301 -0
  130. package/lib/client-parts/22-settings.js +146 -0
  131. package/lib/client-parts/23-npm.js +383 -0
  132. package/lib/client-parts/30-page.js +56 -0
  133. package/lib/client-parts/40-controller.js +1092 -0
  134. package/lib/client-parts/41-actions.js +279 -0
  135. package/lib/client-parts/99-apply.js +72 -0
  136. package/lib/client.js +3195 -0
  137. package/lib/commit-push.js +144 -0
  138. package/lib/context/index.js +363 -0
  139. package/lib/core/atomic-json.js +98 -0
  140. package/lib/core/config.js +40 -0
  141. package/lib/core/credentials.js +274 -0
  142. package/lib/core/endpoints.js +109 -0
  143. package/lib/core/exec.js +162 -0
  144. package/lib/exempt/index.js +292 -0
  145. package/lib/fs/edit-after-read.js +103 -0
  146. package/lib/fsx.js +87 -0
  147. package/lib/git/account-status.js +140 -0
  148. package/lib/git/account.js +233 -0
  149. package/lib/git/api.js +136 -0
  150. package/lib/git/atomic-json.js +6 -0
  151. package/lib/git/browse.js +38 -0
  152. package/lib/git/clone-download.js +397 -0
  153. package/lib/git/clone-history-mode.js +143 -0
  154. package/lib/git/clone-history.js +175 -0
  155. package/lib/git/clone-jobs.js +250 -0
  156. package/lib/git/clone-replay-io.js +172 -0
  157. package/lib/git/clone-replay.js +275 -0
  158. package/lib/git/clone.js +445 -0
  159. package/lib/git/cloud.js +46 -0
  160. package/lib/git/commit-message.js +141 -0
  161. package/lib/git/config.js +6 -0
  162. package/lib/git/cred-env.js +88 -0
  163. package/lib/git/credentials.js +6 -0
  164. package/lib/git/endpoints.js +6 -0
  165. package/lib/git/exec.js +6 -0
  166. package/lib/git/identity-rewrite.js +297 -0
  167. package/lib/git/identity.js +150 -0
  168. package/lib/git/ignore.js +69 -0
  169. package/lib/git/index.js +41 -0
  170. package/lib/git/module-splitter.js +47 -0
  171. package/lib/git/post-push.js +101 -0
  172. package/lib/git/push-diagnose.js +142 -0
  173. package/lib/git/push.js +470 -0
  174. package/lib/git/remote-resolve.js +146 -0
  175. package/lib/git/remote.js +128 -0
  176. package/lib/git/repo-index.js +512 -0
  177. package/lib/git/repos.js +235 -0
  178. package/lib/git/scan-runner.js +159 -0
  179. package/lib/git/sensitive.js +134 -0
  180. package/lib/git/transport.js +430 -0
  181. package/lib/git/visibility.js +35 -0
  182. package/lib/git/wrapped-git.js +68 -0
  183. package/lib/http/index.js +170 -0
  184. package/lib/index.js +24 -0
  185. package/lib/link-check/index.js +187 -0
  186. package/lib/npm/account.js +64 -0
  187. package/lib/npm/install.js +211 -0
  188. package/lib/npm/npmrc.js +56 -0
  189. package/lib/npm/publish.js +167 -0
  190. package/lib/npm/registry.js +147 -0
  191. package/lib/plugin/auto-detect.js +92 -0
  192. package/lib/plugin/auto-push.js +154 -0
  193. package/lib/plugin/index.js +250 -0
  194. package/lib/readme-templates/readme.yml +38 -0
  195. package/lib/rule/compilers/credential.js +62 -0
  196. package/lib/rule/compilers/dataflow.js +38 -0
  197. package/lib/rule/compilers/file-health.js +75 -0
  198. package/lib/rule/compilers/frontend.js +86 -0
  199. package/lib/rule/compilers/func.js +35 -0
  200. package/lib/rule/compilers/helpers.js +71 -0
  201. package/lib/rule/compilers/index.js +29 -0
  202. package/lib/rule/compilers/link-semantic.js +45 -0
  203. package/lib/rule/compilers/list-kinds.js +12 -0
  204. package/lib/rule/compilers/numeric-kinds.js +66 -0
  205. package/lib/rule/compilers/regex.js +78 -0
  206. package/lib/rule/compilers/structure.js +80 -0
  207. package/lib/rule/compilers.js +17 -0
  208. package/lib/rule/homoglyph.js +45 -0
  209. package/lib/rule/loader.js +270 -0
  210. package/lib/rule/registry.js +115 -0
  211. package/lib/rule/scope.js +67 -0
  212. package/lib/score/docs-score.js +166 -0
  213. package/lib/score/index.js +140 -0
  214. package/lib/self/index.js +193 -0
  215. package/lib/skip-dirs.js +64 -0
  216. package/lib/tool-probes.json +50 -0
  217. package/lib/user-requirements.json +14 -0
  218. package/lib/vendor/js-yaml/LICENSE +21 -0
  219. package/lib/vendor/js-yaml/js-yaml.mjs +3073 -0
  220. package/package.json +95 -4
  221. package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
  222. package/scripts/audit-ext/_example-readme-present.mjs +34 -0
  223. package/scripts/audit-ext/variable-min-length.mjs +102 -0
  224. package/scripts/audit-runner.mjs +35 -0
  225. package/scripts/audit-runtime-check.mjs +129 -0
  226. package/scripts/browser-page-probe.mjs +271 -0
  227. package/scripts/build-client.mjs +119 -0
  228. package/scripts/check.mjs +88 -0
  229. package/scripts/clean-date-comments.py +102 -0
  230. package/scripts/doc-drift.mjs +200 -0
  231. package/scripts/doc-func.mjs +212 -0
  232. package/scripts/doc-tree.mjs +456 -0
  233. package/scripts/doc-version.mjs +220 -0
  234. package/scripts/frontend-preview-check.mjs +124 -0
  235. package/scripts/hot-path-probe-cjs.cjs +71 -0
  236. package/scripts/hot-path-probe-fs-shim.mjs +28 -0
  237. package/scripts/hot-path-probe-fsp-shim.mjs +31 -0
  238. package/scripts/hot-path-probe.mjs +153 -0
  239. package/scripts/module-splitter.py +800 -0
  240. package/scripts/platform-scan.mjs +168 -0
  241. package/scripts/preview-gen.mjs +489 -0
  242. package/scripts/preview-local-runner.mjs +55 -0
  243. package/scripts/preview-server-direct.mjs +116 -0
  244. package/scripts/preview-server.mjs +305 -0
  245. package/scripts/preview-slot-data.mjs +123 -0
  246. package/scripts/probe-recheck.mjs +47 -0
  247. package/scripts/readme-gen.mjs +268 -0
  248. package/scripts/rename-locator.mjs +97 -0
  249. package/scripts/rule-switch.mjs +97 -0
  250. package/scripts/rules-solo-audit.mjs +173 -0
  251. package/scripts/scan-file-io.mjs +713 -0
  252. package/scripts/scan-hardcoded-paths.mjs +125 -0
  253. package/scripts/scan-repos.mjs +167 -0
  254. package/scripts/scan-version.mjs +122 -0
  255. package/scripts/scrub-user-wording.mjs +420 -0
  256. package/scripts/symbol-index.mjs +85 -0
  257. package/scripts/sync-plugin-install.mjs +223 -0
  258. package/scripts/sync-plugin.mjs +279 -0
  259. package/scripts/verify-prestep.mjs +100 -0
  260. package/skills/dev/audit-rule-authoring.md +58 -0
  261. package/skills/dev/dsh-git-push.md +323 -0
  262. package/skills/dev/git-push-live-fix.md +45 -0
  263. package/skills/dsh-repo-index.md +35 -0
  264. package/skills/guide/guide-audit.md +167 -0
  265. package/skills/guide/guide-cli-scripts.md +104 -0
  266. package/skills/guide/guide-clone-repos.md +173 -0
  267. package/skills/guide/guide-commit-push.md +156 -0
  268. package/skills/guide/guide-inject-ui.md +166 -0
  269. package/skills/guide/guide-slash-completion.md +118 -0
  270. package/skills/workflow/README.md +21 -0
  271. package/skills/workflow/git-commit-discipline.md +68 -0
  272. package/skills/workflow/git-project-startup.md +85 -0
  273. package/skills/workflow/git-rebuild-process.md +57 -0
  274. package/skills/workflow/github-operations.md +91 -0
  275. package/skills/workflow/readme-sync-git-md.md +28 -0
  276. package/skills/workflow/task-completion-report.md +73 -0
  277. package/skills/workflow/tool-json-add-ask.md +35 -0
  278. package/skills/workflow/versioning-rule.md +211 -0
package/package.json CHANGED
@@ -1,6 +1,97 @@
1
1
  {
2
2
  "name": "dsh-git-push",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.8.4",
4
+
5
+ "description": "DSH git 自动提交推送插件——统一函数入口架构(规则/审计/git/自身/侧边栏/评分/豁免/上下文/HTTP/测试十大总入口)",
6
+ "type": "module",
7
+ "main": "lib/index.js",
8
+ "exports": {
9
+ ".": "./lib/index.js",
10
+ "./client": "./lib/client.js",
11
+ "./audit": "./lib/audit/public.js",
12
+ "./package.json": "./package.json"
13
+ },
14
+ "files": [
15
+ "lib",
16
+ "skills",
17
+ "scripts",
18
+ "cli.mjs",
19
+ "cordis.patch.yml",
20
+ "README.md",
21
+ "LICENSE",
22
+ ".auditignore",
23
+ ".gitignore"
24
+ ],
25
+ "bin": {
26
+ "git-sluice": "./cli.mjs"
27
+ },
28
+ "dsh": {
29
+ "bundle": {
30
+ "patch": "./cordis.patch.yml"
31
+ },
32
+ "client": {
33
+ "platform": "web",
34
+ "inject": [
35
+ "@deepseek-ai/dsh-client-ui-settings-plugins",
36
+ "@deepseek-ai/dsh-client-ui-settings"
37
+ ]
38
+ },
39
+ "skills": [
40
+ "./skills/dsh-repo-index.md",
41
+ "./skills/dev/dsh-git-push.md",
42
+ "./skills/dev/git-push-live-fix.md",
43
+ "./skills/guide/guide-audit.md",
44
+ "./skills/guide/guide-cli-scripts.md",
45
+ "./skills/guide/guide-clone-repos.md",
46
+ "./skills/guide/guide-commit-push.md",
47
+ "./skills/guide/guide-inject-ui.md",
48
+ "./skills/guide/guide-slash-completion.md",
49
+ "./skills/workflow/README.md",
50
+ "./skills/workflow/git-commit-discipline.md",
51
+ "./skills/workflow/git-project-startup.md",
52
+ "./skills/workflow/git-rebuild-process.md",
53
+ "./skills/workflow/github-operations.md",
54
+ "./skills/workflow/readme-sync-git-md.md",
55
+ "./skills/workflow/task-completion-report.md",
56
+ "./skills/workflow/tool-json-add-ask.md",
57
+ "./skills/workflow/versioning-rule.md"
58
+ ]
59
+ },
60
+ "license": "MIT",
61
+ "author": "EIGHTfs",
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "git+https://github.com/EIGHTfs/dsh-git-push.git"
65
+ },
66
+ "bugs": {
67
+ "url": "https://github.com/EIGHTfs/dsh-git-push/issues"
68
+ },
69
+ "homepage": "https://github.com/EIGHTfs/dsh-git-push#readme",
70
+ "keywords": [
71
+ "dsh",
72
+ "dsh-plugin",
73
+ "deepseek-harness",
74
+ "git",
75
+ "commit",
76
+ "push",
77
+ "audit",
78
+ "cli"
79
+ ],
80
+ "engines": {
81
+ "node": ">=18.0.0"
82
+ },
83
+ "peerDependencies": {
84
+ "@deepseek-ai/dsh-tools": ">=0.1.6-0 <0.3.0-0",
85
+ "@deepseek-ai/schemastery": ">=3.0.0 <4.0.0-0"
86
+ },
87
+ "scripts": {
88
+ "build:client": "node scripts/build-client.mjs",
89
+ "prepare": "node scripts/build-client.mjs",
90
+ "prepack": "node scripts/build-client.mjs",
91
+ "test": "node test/run-tests.mjs",
92
+ "check": "node scripts/check.mjs",
93
+ "scan-version": "node scripts/scan-version.mjs",
94
+ "check:drift": "node scripts/doc-drift.mjs",
95
+ "sync-plugin": "node scripts/sync-plugin.mjs"
96
+ }
97
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 审计扩展契约示例——演示如何写一个自动接入的独立审计脚本。
3
+ *
4
+ * 契约(复制本文件骨架即可新增扩展):
5
+ * export const auditExt = {
6
+ * name: '扩展名', // findings 里 source 标记 `ext:<name>`
7
+ * match: (repo) => true, // 是否适用该仓库(返回 false 跳过)
8
+ * run: async (repo, opts) => [], // 返回 findings 数组
9
+ * };
10
+ *
11
+ * 自动接入:放进 scripts/audit-ext/ 即被统一入口动态加载——
12
+ * auditFull/auditWithScope 自动并入 + `node scripts/audit-runner.mjs <repo>` 独立跑。
13
+ *
14
+ * 本示例:检查仓库根有没有 README.md(找不到给 info 提示)——演示 match/run 用法。
15
+ */
16
+
17
+ export const auditExt = {
18
+ name: 'example-readme-present',
19
+ match: (repo) => Boolean(repo && repo !== '.'),
20
+ run: async (repo) => {
21
+ const { existsSync } = await import('node:fs');
22
+ const { join } = await import('node:path');
23
+ const findings = [];
24
+ if (!existsSync(join(repo, 'README.md'))) {
25
+ findings.push({
26
+ file: 'README.md', line: 1, rule: 'ext/readme-present',
27
+ severity: 'info', scoreImpact: 0,
28
+ message: '仓库根缺 README.md(示例审计扩展:演示契约接入)',
29
+ dimensions: ['文档'],
30
+ });
31
+ }
32
+ return findings;
33
+ },
34
+ };
@@ -0,0 +1,102 @@
1
+ /**
2
+ * 审计扩展:variable-min-length(试点——内置审计规则抽出为独立脚本,统一动态入口)
3
+ *
4
+ * 试点:audit-rules-nodejs.yml 的 readability/variable-min-length 标 external: true
5
+ * ——内置执行链停跑(groupByKind 过滤),本脚本经 runAuditExt 统一加载(auditFull 自动并入)。
6
+ * 复用 lib/ast 检查器函数(checkNameLengthAst)——实现不重复,仅换执行载体。
7
+ * findings 格式与内置 checkMinLength 对齐(file 相对路径 / severity warning / scoreImpact 0)。
8
+ */
9
+
10
+ export const auditExt = {
11
+ name: 'variable-min-length',
12
+ match: (repo) => Boolean(repo && repo !== '.'),
13
+ run: async (repo) => {
14
+ const { checkNameLengthAst } = await import('../../lib/ast/naming.js');
15
+ // external 规则此前是「写了字段也不生效」:run(repo, opts) 只收到仓库路径,收不到规则对象,
16
+ // 于是 min 硬编码 2、yml 里声明的 exceptions 形同虚设(自审实测:i/j/k/n/e/cb 若真出现也会报)。
17
+ // 编排层调用契约改动面大,改为**脚本自己按 external 名查自己的规则**(自包含、不影响其它 ext),
18
+ // 让 yml 声明的 min_length / exceptions / exclude_paths 真正生效。
19
+ let rule = null;
20
+ try {
21
+ const { discoverRuleSlots, loadRuleFiles } = await import('../../lib/rule/loader.js');
22
+ const slots = discoverRuleSlots().map((s) => s.name || s);
23
+ const merged = loadRuleFiles(slots).merged || {};
24
+ rule = (merged.rules || []).find((r) => String(r.external || r.external === true ? (r.external === true ? '' : r.external) : '') === 'variable-min-length') || null;
25
+ } catch { rule = null; }
26
+ const minLength = Number.isFinite(Number(rule?.min_length)) ? Number(rule.min_length) : 2;
27
+ const allow = Array.isArray(rule?.exceptions) ? rule.exceptions.map(String) : [];
28
+ const excludePaths = Array.isArray(rule?.exclude_paths) ? rule.exclude_paths.map(String) : [];
29
+ const isExcludedPath = (rel) => {
30
+ if (!excludePaths.length) return false;
31
+ const norm = String(rel || '').replace(/\\/g, '/').replace(/^\.?\//, '');
32
+ return excludePaths.some((e) => {
33
+ const ee = String(e || '').replace(/\\/g, '/').replace(/^\.?\//, '').replace(/\/+$/, '');
34
+ return ee && (norm === ee || norm.startsWith(ee + '/'));
35
+ });
36
+ };
37
+ // 修复:external 通道必须带内置的构建/混淆产物豁免(isBuildArtifactFile——
38
+ // hash 文件名/单行混淆)——否则单行混淆产物短名密爆(Pawchive hash 产物 5896 条误报)
39
+ const { isBuildArtifactFile } = await import('../../lib/audit/audit-file.js');
40
+ // 修复:external 通道必须尊重 .gitignore/.auditignore——ext 自 walk 文件
41
+ // 不走 collector,此前把被 gitignore 忽略的上游克隆(Pawchive docs/.probe-ktoolbox
42
+ // KToolBox 源码 68607 文件)扫入审计(14 条短名泄漏)。复用内置匹配器判目录忽略。
43
+ const { parseGitignore, isIgnoredByRules } = await import('../../lib/audit/gitignore-match.js');
44
+ const { readFileSync, readdirSync, statSync, existsSync } = await import('node:fs');
45
+ const { join, extname, relative } = await import('node:path');
46
+ const CODE_EXTS = new Set(['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx']);
47
+ // 排除目录(构建产物/依赖/测试/一次性工具——与内置 collector 忽略语义近似;精确忽略留给核心审计)
48
+ const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', 'build', 'output', 'test', 'tests', '__tests__', 'spec', 'tools', 'scripts', '.trash']);
49
+ // gitignore 规则(.gitignore + .auditignore 叠加)——目录级跳过;缺省空 = 不忽略
50
+ let gitignoreRules = null;
51
+ try {
52
+ const giText = [];
53
+ for (const giFile of ['.gitignore', '.auditignore']) {
54
+ const p = join(repo, giFile);
55
+ if (existsSync(p)) giText.push(readFileSync(p, 'utf8'));
56
+ }
57
+ if (giText.length) gitignoreRules = parseGitignore(giText.join('\n'));
58
+ } catch { /* 读忽略文件失败 = 不忽略,保守放行 */ }
59
+ const findings = [];
60
+ const walk = (dir) => {
61
+ for (const f of readdirSync(dir)) {
62
+ const p = join(dir, f);
63
+ let st;
64
+ try { st = statSync(p); } catch { continue; }
65
+ if (st.isDirectory()) {
66
+ if (SKIP_DIRS.has(f)) continue;
67
+ // gitignore 忽略目录(上游克隆/内部数据)跳过——与 collector 目录剪枝同语义
68
+ if (gitignoreRules && isIgnoredByRules(gitignoreRules, relative(repo, p).replace(/\\/g, '/'), true)) continue;
69
+ walk(p);
70
+ } else if (CODE_EXTS.has(extname(f))) {
71
+ try {
72
+ const text = readFileSync(p, 'utf8');
73
+ const rel = relative(repo, p) || p;
74
+ if (isExcludedPath(rel)) continue; // 规则声明的路径白名单外(如 token 级判定层的惯用短名)
75
+ if (isBuildArtifactFile(rel, text)) continue; // 构建/混淆产物跳过(行级规则必然误报)
76
+ for (const hit of checkNameLengthAst(text, { min: minLength, allow })) {
77
+ // 降级(按需求):窄作用域(声明所在块行跨度 ≤ SCOPE_LINES)里的短别名
78
+ // 仍列出来(聚合结果里能查到位置、便于人工核对),但不按 warning 告警——
79
+ // 含义由紧邻上下文决定(c=chunk / h=header / m=method / d=data / q=query),
80
+ // 报成 warning 只会制造噪声;宽作用域仍按 warning 报。
81
+ const narrow = hit.narrowScope === true;
82
+ const what = hit.type === 'function' ? '函数' : '变量';
83
+ findings.push({
84
+ file: rel, line: hit.line,
85
+ rule: 'readability/variable-min-length', kind: 'min-length',
86
+ severity: narrow ? 'notice' : 'warning',
87
+ message: narrow
88
+ ? `${what}名「${hit.name}」过短(< ${minLength})——窄作用域惯用短别名(已降级为提示,位置可查)`
89
+ : `${what}名「${hit.name}」过短(< ${minLength})——应可读命名`,
90
+ dimensions: ['可读性'],
91
+ exemptHint: 'dsh-skip-quality(文件头=整文件)',
92
+ scoreImpact: 0,
93
+ });
94
+ }
95
+ } catch { /* 单文件读取失败跳过 */ }
96
+ }
97
+ }
98
+ };
99
+ try { walk(repo); } catch { /* 仓库不可遍历返回空 */ }
100
+ return findings;
101
+ },
102
+ };
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 审计扩展统一入口(CLI)——独立跑 scripts/audit-ext/ 下全部审计扩展脚本。
4
+ *
5
+ * 用法:
6
+ * node scripts/audit-runner.mjs <repo> [--dir scripts/audit-ext] [--json]
7
+ *
8
+ * 与插件审计的关系:auditFull/auditWithScope 已自动并入 audit-ext 扩展 findings
9
+ * (source 标记 ext:<name>);本脚本用于独立调试/单独跑扩展(不带核心审计)。
10
+ */
11
+
12
+ import { runAuditExt } from '../lib/audit/ext-runner.js';
13
+
14
+ /** findings 预览打印条数(调试输出——完整清单走 --json)。 */
15
+ const PREVIEW_MAX = 20;
16
+
17
+ async function main() {
18
+ const argv = process.argv.slice(2);
19
+ const repo = argv.find((a) => !a.startsWith('--')) || process.cwd();
20
+ const dirIdx = argv.indexOf('--dir');
21
+ const dir = dirIdx >= 0 ? argv[dirIdx + 1] : undefined;
22
+ const json = argv.includes('--json');
23
+
24
+ const findings = await runAuditExt(repo, { dir, log: console });
25
+ if (json) {
26
+ console.log(JSON.stringify({ repo, extFindings: findings.length, findings }, null, 2));
27
+ return;
28
+ }
29
+ console.log(`审计扩展 ${repo} → ${findings.length} 条 findings(source: ext:*)`);
30
+ for (const f of findings.slice(0, PREVIEW_MAX)) {
31
+ console.log(` ${f.source} ${f.file || ''}:${f.line || ''} [${f.severity || 'warning'}] ${(f.message || '').slice(0, 60)}`);
32
+ }
33
+ }
34
+
35
+ main().catch((e) => { console.error('audit-runner 失败:', e); process.exitCode = 1; });
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 三层审计 · L3 运行时检测
4
+ *
5
+ * 职责:兜住静态盲区——L2(AST 同函数数据流)看不到的跨文件引用、闭包捕获、
6
+ * 异步时序(清空在 setTimeout/await 之后、访问在回调里)。本脚本用**运行时实测**
7
+ * 确认「清空后访问」是否真的拿到 undefined / 空值。
8
+ *
9
+ * 用法:
10
+ * node scripts/audit-runtime-check.mjs <被测 js 文件> [--obj 对象名] [--verbose]
11
+ * node scripts/audit-runtime-check.mjs --all <目录> # 目录内所有 js 文件逐个测
12
+ *
13
+ * 原理(在测试沙箱里构造,不改被测文件):
14
+ * ① 动态 import 被测模块(file:// URL),拿到模块导出的对象;
15
+ * ② 若模块顶层有「清空动作」(clear()/reset()/=[]/=null/length=0)对应的方法,
16
+ * 依次调用:先调清空方法,再调访问方法(get/first/peek/[0]),捕获返回值;
17
+ * ③ 返回值是 undefined / null / 空数组 → 命中(L3 确认);否则不命中(L2 疑点排除)。
18
+ *
19
+ * 局限(如实标注):
20
+ * - 只能测「模块导出」的入口;内部闭包/未导出的状态只能靠测试钩子;
21
+ * - 依赖被测文件能安全 import(副作用不能炸进程,如连真 API/写文件);
22
+ * - 异步时序无法在纯同步沙箱复现——异步场景建议用 node:test 写专门用例。
23
+ *
24
+ * 退出码:0 = 全部通过(无运行时命中);1 = 存在运行时命中(L3 确认的 bug);
25
+ * 2 = 无法检测(文件不可 import / 无导出对象 / 用法错误)。
26
+ */
27
+
28
+ import { pathToFileURL } from 'node:url';
29
+ import { statSync, readdirSync } from 'node:fs';
30
+ import { join, resolve, basename } from 'node:path';
31
+
32
+ const args = process.argv.slice(2);
33
+
34
+ /** 解析 CLI 参数。 */
35
+ function parseArgs() {
36
+ const opts = { files: [], obj: null, verbose: false, all: false };
37
+ for (let i = 0; i < args.length; i++) {
38
+ const a = args[i];
39
+ if (a === '--obj') { opts.obj = args[++i] || null; }
40
+ else if (a === '--verbose') opts.verbose = true;
41
+ else if (a === '--all') opts.all = true;
42
+ else opts.files.push(a);
43
+ }
44
+ return opts;
45
+ }
46
+
47
+ /** 收集目录下所有 .js 文件(一层)。 */
48
+ function collectJs(dir) {
49
+ try {
50
+ const st = statSync(dir);
51
+ if (!st.isDirectory()) return [dir];
52
+ return readdirSync(dir).filter((n) => n.endsWith('.js')).map((n) => join(dir, n)); // dsh-skip-residue(自检脚本一次性收集)
53
+ } catch { return []; }
54
+ }
55
+
56
+ /**
57
+ * 对单个文件做运行时检测。
58
+ * @returns {Promise<{file:string, hits:Array<{op:string, result:string}>, error?:string}>}
59
+ */
60
+ async function runFile(file, obj) {
61
+ const out = { file, hits: [], error: null };
62
+ let mod;
63
+ try {
64
+ mod = await import(pathToFileURL(resolve(file)).href);
65
+ } catch (e) {
66
+ out.error = `无法 import(${String(e?.message || e).split('\n')[0]})`;
67
+ return out;
68
+ }
69
+ const exp = mod?.default ?? mod;
70
+ const cands = [];
71
+ // 候选对象:指定 obj → 导出里找;否则导出里「看起来像容器」的值(对象/数组/Map/Set)
72
+ for (const [name, val] of Object.entries(exp || {})) {
73
+ if (typeof val !== 'object' || val === null) continue;
74
+ if (obj && name !== obj) continue;
75
+ cands.push({ name, val });
76
+ }
77
+ if (!cands.length) {
78
+ out.error = '无候选容器对象(导出里没有对象/数组/Map/Set)';
79
+ return out;
80
+ }
81
+ for (const { name, val } of cands) {
82
+ const clearOps = ['clear', 'reset', 'flush', 'purge'].filter((m) => typeof val?.[m] === 'function');
83
+ const accessOps = ['get', 'first', 'last', 'peek', 'head', 'at', 'shift', 'pop'].filter((m) => typeof val?.[m] === 'function');
84
+ if (!clearOps.length) continue; // 无清空方法 → 本对象不适用
85
+ for (const clearOp of clearOps) {
86
+ let clearOk = true;
87
+ try { val[clearOp](); } catch (e) { clearOk = false; out.hits.push({ op: `${name}.${clearOp}()`, result: `调用抛错:${String(e?.message || e).split('\n')[0]}` }); }
88
+ if (!clearOk) continue;
89
+ for (const a of accessOps) {
90
+ let accessResult;
91
+ try { accessResult = val[a](); } catch (e) { accessResult = `抛错:${String(e?.message || e).split('\n')[0]}`; }
92
+ const isBad = accessResult === undefined || accessResult === null || (Array.isArray(accessResult) && accessResult.length === 0);
93
+ if (isBad) out.hits.push({ op: `${name}.${clearOp}() 后 ${name}.${a}()`, result: `${typeof accessResult === 'object' ? JSON.stringify(accessResult) : String(accessResult)}` });
94
+ }
95
+ }
96
+ }
97
+ return out;
98
+ }
99
+
100
+ /** 主流程。 */
101
+ async function main() {
102
+ const opts = parseArgs();
103
+ if (!opts.files.length) {
104
+ console.error('用法: node scripts/audit-runtime-check.mjs <js 文件> [--obj 对象名] [--verbose]');
105
+ console.error(' node scripts/audit-runtime-check.mjs --all <目录>');
106
+ process.exitCode = 2;
107
+ return;
108
+ }
109
+ const files = opts.all ? opts.files.flatMap((d) => collectJs(d)) : opts.files;
110
+ let confirmed = 0;
111
+ for (const f of files) {
112
+ const r = await runFile(f, opts.obj);
113
+ if (r.error) {
114
+ console.log(`— ${f}: ${r.error}`);
115
+ continue;
116
+ }
117
+ if (r.hits.length) {
118
+ confirmed++;
119
+ console.log(`✗ ${f} —— L3 确认「清空后访问」命中 ${r.hits.length} 处:`);
120
+ for (const hit of r.hits) console.log(` ${hit.op} → ${hit.result}`);
121
+ } else if (opts.verbose) {
122
+ console.log(`✔ ${f}: 无运行时命中`);
123
+ }
124
+ }
125
+ console.log(`\nL3 运行时检测完成:${confirmed} 个文件确认命中`);
126
+ if (confirmed > 0) process.exitCode = 1;
127
+ }
128
+
129
+ await main();