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
package/README.md CHANGED
@@ -1,32 +1,39 @@
1
1
  # dsh-git-push
2
2
 
3
- DSH 的 git 提交推送与代码审计插件:提交前自动过审计门禁,提交、推送、发包一条命令完成。
3
+ DSH 的 **git 提交推送插件**:提交、推送、克隆、账号校验、仓库扫描与 npm 发布,一个工具搞定。
4
+
5
+ 提交前可选跑「预处理门禁」:本插件只负责"跑一个命令、按退出码决定放行还是拦截",
6
+ 检查内容由可插拔的 provider 决定(审计由独立包 `audit-sluice` 提供)。
4
7
 
5
8
  ## 功能
6
9
 
7
10
  | 功能 | 做什么 | 入口 |
8
11
  |---|---|---|
9
- | 提交推送 | 审计通过后提交并推送,支持 dry-run / force / 指定 remote | `git_commit_push` / `commit` |
12
+ | 提交推送 | 提交并推送;支持 dry-run / force / 指定 remote / 精确路径 | `git_commit_push` / `commit` |
10
13
  | 仓库扫描 | 列出仓库的未提交、未推送、分叉与近期活动 | `git_scan` / `scan` |
11
- | 代码审计 | 静态检查 + 质量评分,diff 或全量两种范围 | `code_audit` / `audit` / `/git-audit` |
12
- | 历史提交审计 | 逐提交回放审计并落盘报告 | `code_audit --history` / `audit --history` |
13
14
  | 克隆仓库 | 按 owner/repo 克隆到指定目录 | `git_clone` / `clone` |
14
15
  | 克隆预演 | 只看将拉取什么,不落盘 | `git_clone_preview` / `clone-preview` |
15
16
  | 建远端仓 | 给本地仓库建远端并设置 origin | `git_remote_create` / `remote-create` |
16
17
  | 可见性 | 切换仓库 public / private | `git_set_visibility` / `set-visibility` |
17
18
  | 改名 | 给远程仓库改名(dryRun 默认开,列出旧名出现位置) | `git_remote_rename` / `rename` |
18
- | 凭据与账号 | 校验 GitHub token 与 SSH 公钥、生成密钥对 | `git_account_check` / `git_gen_ssh_key` |
19
+ | 凭据与账号 | 校验 GitHub token 与 SSH 公钥、生成密钥对、导出凭据环境变量 | `git_account_check` / `git_gen_ssh_key` / `git_cred_env` |
19
20
  | 身份改写 | 把历史提交身份统一成登录账号 | `git_identity_rewrite` / `identity-rewrite` |
20
21
  | 发布 | 发布 npm 包(dryRun 默认只体检;凭据由插件托管,无需 npm login) | `npm_publish` / `npm-publish` |
21
22
  | 撤包 | 从 registry 撤版本(默认 dryRun 预检,不可逆) | `npm_unpublish` / `unpublish` |
22
- | 豁免标记 | 给文件加/删豁免注释并校验是否真生效 | `exempt` |
23
- | I/O 风险扫描 | 扫描读写操作的风险分级 | `io_scan` / `file-io` |
24
- | 链接检查 | 检查文档里的 URL 是否有效 | `link_check` / `link-check` |
25
- | 拼接产物作用域 | 查分片拼成单文件后同一作用域内的重名(后者静默顶掉前者) | `scope_check` / `scope-check` |
26
- | 巨型文件拆分 | 按顶层块拆分单文件并校验导出一致 | `module_splitter` / `module-splitter` |
27
23
  | git 透传 | 执行任意 git 命令,凭据自动注入 | `git_sluice` / `git` |
28
- | HTTP 接口直调 | 调用本插件的全部 HTTP 接口 | `git_api` / `api` |
29
- | 审计结果查询 | 按规则/文件/严重级/规则包聚合审计结果 | `GET /api/git-push/audit` |
24
+ | HTTP 接口直调 | 调用本插件的 HTTP 接口 | `git_api` / `api` |
25
+ | 预处理动作 | 转发到声明该动作的 provider(审计/静态检查等) | `git-sluice preprocess <action>` |
26
+ | 静态检查类工具 | `code_audit`(含 `history=true` 逐提交回放)/ `io_scan` / `link_check` / `scope_check` / `exempt`——**实现由 `audit-sluice` 提供,需安装** | 同名工具 |
27
+
28
+ ## 提交前检查(可选,独立包实现)
29
+
30
+ 检查逻辑不在本插件里——由独立包 **`audit-sluice`** 提供(`npm install audit-sluice`)。
31
+ 装上后本插件自动发现它;**不装也能正常用**,只是不做提交前检查,返回值里会标注"预处理未执行"。
32
+
33
+ ```bash
34
+ audit-sluice audit --repo <路径> --scope diff --json # 也能脱离本插件独立跑:stdout 单行 JSON,exit 0|1|2
35
+ audit-sluice config # 它的配置(扫描范围/文件上限/禁用规则包/权重)
36
+ ```
30
37
 
31
38
  ## 环境要求
32
39
 
@@ -38,81 +45,103 @@ DSH 的 git 提交推送与代码审计插件:提交前自动过审计门禁
38
45
 
39
46
  ### 侧边栏面板
40
47
 
41
- - **账号信息**:GitHub 与 npm 账号状态、凭据与 SSH 公钥
42
- - **审计面板**:规则包启停、排序、命中数
43
- - **设置**:审计开关、扫描范围、评分权重、自动推送开关
48
+ - **账号信息**:GitHub 与 npm 账号状态、凭据与 SSH 公钥、本地/云端仓库列表
49
+ - **设置**:凭据与密钥、推送通道、推送门禁、自动推送、**提交前预处理开关**(其余审计项归 `audit-sluice` 自己的配置)
44
50
 
45
51
  ### 聊天框指令
46
52
 
47
53
  ```
48
- /git-audit # 审计当前仓库(默认 diff 范围)
49
- /git-audit --full # 全量审计
50
- /link-check # 检查文档里的链接
54
+ /git-scan # 扫描工作区里的 git 仓库
55
+ /git-account # 校验 GitHub 账号与凭据
56
+ /git-clone-preview <owner/repo> # 克隆预演
51
57
  ```
52
58
 
53
59
  ### AI 工具
54
60
 
55
61
  ```js
56
62
  git_scan({ root }) // root 可空:空=自动识别家目录
57
- code_audit({ repo, scope, includeFindings }) // repo 必填;scope 可空(空=full);includeFindings 可空(空=精简输出)
58
- git_commit_push({ message, repo, push, dryRun }) // message 必填;repo 可空(空=当前目录);push 可空(空=推送);dryRun 可空(空=真提交)
59
- git_clone({ target, dest, branch, history }) // target 必填(owner/repo 或完整 URL);dest 可空(空=工作区根);history 可空(空=整树快照)
60
- git_clone_preview({ target, branch }) // target 必填;branch 可空(空=默认分支)
61
- git_api({ path, method, query, body }) // path 可空(空=列出全部接口);method 可空(空=GET)
63
+ git_commit_push({ repo, message, push, dryRun }) // repo/message 必填;其余可空
64
+ git_clone({ target, dest, branch, history }) // target 必填(owner/repo 或完整 URL)
65
+ git_clone_preview({ target, branch }) // target 必填;branch 可空
66
+ git_api({ path, method, query, body }) // path 可空(空=列出全部接口)
62
67
  git_sluice({ args }) // args 必填:与 git 一致的参数串
63
68
  git_account_check({ token, sshPub }) // 两者都可空:不传则自动解析本机凭据
64
- git_gen_ssh_key({ email, force }) // email 必填;force 可空(空=已存在时不覆盖)
65
- git_identity_rewrite({ paths, dryRun, write, push }) // 全可空:dryRun 默认只报告,write 才改写
66
- git_remote_create({ repo, visibility, dryRun }) // repo 必填;visibility 可空(空=private)
69
+ git_cred_env({}) // 输出凭据环境变量前缀(不含明文)
70
+ git_gen_ssh_key({ email, force }) // email 必填
71
+ git_identity_rewrite({ paths, dryRun, write, push }) // 全可空:dryRun 默认只报告
72
+ git_remote_create({ repo, visibility, dryRun }) // repo 必填
67
73
  git_set_visibility({ repo, visibility }) // 两者必填
68
- npm_publish({ dir, dryRun, confirm, tag, otp }) // dryRun 默认 true(只体检);真发需 confirm=true 且 dryRun=false
69
- exempt({ action, rule, path, scope, line, reason }) // action 与 rule 必填;path 可数组;scope=header(文件头)或 line
70
- io_scan({ repo, writeOnly }) // 两者都可空:writeOnly 空=读写都看
71
- link_check({ path }) // path 可空:空=整个工作区
72
- scope_check({ files, repo, prefix, allowlist, topLevelMustBeEmpty }) // 全可空:files 空=读项目 dshScopeCheck.files;prefix 空=按项目契约
73
- module_splitter({ command, file, plan, dryRun }) // command 必填(analyze/split/verify);dryRun 可空
74
+ npm_publish({ dir, dryRun, confirm, tag, otp }) // dryRun 默认 true(只体检,不写 registry)
75
+ npm_unpublish({ name, version, dryRun, confirm }) // dryRun 默认 true
76
+ // 以下需安装 audit-sluice(未装时返回可诊断错误,不影响其他工具)
77
+ code_audit({ repo, scope, includeFindings })
78
+ io_scan({ repo, writeOnly })
79
+ link_check({ path })
80
+ scope_check({ files, repo, prefix, allowlist, topLevelMustBeEmpty })
81
+ exempt({ action, rule, path, scope, line, reason })
74
82
  ```
75
83
 
76
- ### 独立 CLI(git-sluice)
84
+ ### 提交前预处理链(可选)
85
+
86
+ `preCommit.stages` 按数组顺序跑多个阶段(如"先格式化、再审计");也可以**按次**用工具参数
87
+ `preprocessStages` 覆盖配置(优先级更高):
88
+
89
+ ```js
90
+ git_commit_push({
91
+ repo, message,
92
+ preprocessStages: [
93
+ { command: 'node', args: ['tools/fmt.mjs', '{filesFile}'], onFail: 'warn' },
94
+ { provider: 'audit', onFail: 'block' },
95
+ ],
96
+ })
97
+ ```
98
+
99
+ 每阶段可用 `{repo}` / `{filesFile}` / `{filesCount}` / `{stage}` 占位符,宿主同时注入
100
+ `PREPROCESS_REPO` / `PREPROCESS_CHANGED_FILES` 等环境变量。回执里 `preprocessStages` / `preprocessChanges` /
101
+ `stagesSource` 如实反映"哪个阶段改了什么、本次链来自参数还是配置"。契约见 [docs/SPEC.md](docs/SPEC.md) 第十七章。
102
+
103
+ ### 独立 CLI
77
104
 
78
105
  ```
79
106
  git-sluice account-check # 校验本机 GitHub 凭据
80
107
  git-sluice scan <目录> # 列出该目录下的 git 仓库
81
- git-sluice commit <仓库> --message "msg" # 提交并推送(自动过审计门禁)
108
+ git-sluice commit <仓库> --message "msg" # 提交(默认只 commit;--push 推远端)
109
+ git-sluice preprocess <action> ... # 转发到 provider(如 audit / io_scan / link_check)
82
110
  git-sluice help # git 侧全部命令
83
111
 
84
- audit-sluice audit <仓库> --full # 全量审计(加 --json 拿明细)
85
- audit-sluice scope-check [文件] # 查拼接产物同帧重名(无参数时读项目 dshScopeCheck.files)
86
- tool-sluice self-check # 三入口 HELP/参数/命令集一致性自检
112
+ tool-sluice self-check # 两入口 HELP/参数/命令集一致性自检
87
113
  ```
88
114
 
89
115
  ## API
90
116
 
91
- 38 个端点,统一前缀 `/api/git-push/`。常用:
117
+ 统一前缀 `/api/git-push/`(git 侧与共享),预处理侧统一前缀 `/api/preprocess/`。常用:
92
118
 
93
119
  | 端点 | 做什么 |
94
120
  |---|---|
95
121
  | `GET /api/git-push/status` | 插件状态与配置概览 |
96
122
  | `GET /api/git-push/scan` | 仓库扫描结果 |
97
- | `GET /api/git-push/audit` | 审计结果(支持 scope / groupBy / severity / top) |
98
- | `GET /api/git-push/repos` | 本地仓库列表 |
123
+ | `GET /api/git-push/repos-local` | 本地仓库列表(默认只读索引快照,毫秒级;`?live=1` 才同步探测远端) |
99
124
  | `GET /api/git-push/account-status` | 账号状态快照 |
100
- | `POST /api/git-push/credentials` | 写入凭据 |
125
+ | `POST /api/git-push/settings-set` | 写单个设置键 |
101
126
  | `GET /api/git-push/tools` | 工具清单 |
127
+ | `GET /api/preprocess/<action>` | 预处理端点(动作清单来自各 provider 的 manifest) |
102
128
 
103
129
  ```bash
104
- # 审计一个仓库(按规则聚合)
105
- curl "http://<本机IP>:<端口>/api/git-push/audit?repo=<仓库绝对路径>&scope=diff&groupBy=rule"
106
-
107
- # 列出全部可用接口
130
+ # 预处理动作清单
108
131
  curl "http://<本机IP>:<端口>/api/git-push/api"
132
+
133
+ # 审计结果(需安装 audit-sluice)
134
+ curl "http://<本机IP>:<端口>/api/preprocess/audit?repo=<仓库绝对路径>&scope=diff&groupBy=rule"
109
135
  ```
110
136
 
111
137
  ## 文档索引
112
138
 
113
- - [docs/SPEC.md](docs/SPEC.md) — 规格唯一入口(工具、接口、设置键、数据文件、规则体系)
114
- - [docs/功能-审计引擎.md](docs/功能-审计引擎.md) — 审计引擎(规则体系、判定、评分、委托层、豁免)
139
+ - [docs/SPEC.md](docs/SPEC.md) — 规格唯一入口(工具、接口、设置键、数据文件、与 audit-sluice 的耦合面)
115
140
  - [docs/功能-发布与工具链.md](docs/功能-发布与工具链.md) — 提交推送、克隆、npm 发布、仓库索引、文档生成
141
+ - [docs/PERF-BASELINE.md](docs/PERF-BASELINE.md) — git 侧性能基线
142
+ - [docs/PLAN-UI状态工厂.md](docs/PLAN-UI状态工厂.md) — UI 状态层改造计划与交付记录
116
143
  - [docs/FILE-TREE.md](docs/FILE-TREE.md) — 目录结构(自动生成)
117
144
  - [docs/CHANGELOG.md](docs/CHANGELOG.md) — 版本列表(自动生成)
118
145
  - [docs/FUNCTIONS.md](docs/FUNCTIONS.md) — 函数列表(自动生成)
146
+
147
+ 审计实现文档(规则体系、评分、豁免、性能基线)属独立包,见 `audit-sluice` 仓库的 `docs/`。
package/cli-tool.mjs CHANGED
@@ -15,9 +15,6 @@
15
15
  */
16
16
  import { VERSION } from './lib/self/index.js';
17
17
 
18
- import {
19
- cmdModuleSplitter,
20
- } from './lib/cli/commands-doc.mjs';
21
18
  import { cmdReadmeTemplate, cmdSelfCheck, cmdYamlTemplate } from './lib/cli/commands-tool.mjs';
22
19
  import { CLI_TOOL, CLI_ENTRIES, cliPluginConfig, runAsEntry, runCli } from './lib/cli/shared.mjs';
23
20
 
@@ -78,7 +75,8 @@ export async function main(argv = process.argv.slice(2)) {
78
75
  runAsEntry(import.meta.url, main);
79
76
 
80
77
  // 兼容导出
81
- export { cmdModuleSplitter, cmdYamlTemplate, cmdReadmeTemplate, cmdSelfCheck };
78
+ // module-splitter 已随通用工具迁入 audit-sluice(不再由本插件提供)
79
+ export { cmdYamlTemplate, cmdReadmeTemplate, cmdSelfCheck };
82
80
 
83
81
  /** 子命令:version(三入口同一实现,只有名字不同)。 */
84
82
  export function cmdVersion() {
package/cli.mjs CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  cmdAccountCheck, cmdCredEnv, cmdRemoteCreate, cmdSetVisibility, cmdGenSshKey,
23
23
  } from './lib/cli/commands-account.mjs';
24
24
  import { cmdRepos, cmdIndex, cmdCommit, cmdClone } from './lib/cli/commands-vcs.mjs';
25
+ import { cmdPreprocess } from './lib/cli/commands-preprocess.mjs';
25
26
  import {
26
27
  CLI_GIT, CLI_ENTRIES, cliPluginConfig, parseArgv, parseVia, printToolResult, runAsEntry, runCli,
27
28
  } from './lib/cli/shared.mjs';
@@ -38,7 +39,8 @@ export const KNOWN_FLAGS = [
38
39
  '--confirm', '--depth', '--dest', '--dry-run', '--extra-emails', '--extra-repos-file', '--force', '--history',
39
40
  '--history-depth', '--ignore-patterns', '--json', '--local-preview', '--max', '--message', '--message-items',
40
41
  '--method', '--no-dry-run', '--no-push', '--offline', '--otp', '--owner', '--paths', '--push',
41
- '--push-confirmed', '--push-initial', '--query', '--remote', '--requirements-confirmed', '--root',
42
+ '--push-confirmed', '--push-initial', '--query', '--remote', '--root',
43
+ '--preprocess-stages',
42
44
  '--skip-smoke', '--ssh-pub', '--tag', '--token', '--update-remotes', '--visibility', '--wait-ci',
43
45
  '--wait-visible', '--whole-package', '--write',
44
46
  ];
@@ -51,9 +53,13 @@ const HELP = `git-sluice v${VERSION} — ${CLI_ENTRIES[CLI_GIT].intro}
51
53
  git-sluice commit <仓库> --message "msg" ③ 提交推送(自动过审计门禁)
52
54
  git-sluice help 全部命令与参数
53
55
 
56
+ 预处理(可插拔扩展:从所有在位 provider 的声明里找能力,审计只是其中之一):
57
+ git-sluice preprocess 列出当前可用的预处理动作
58
+ git-sluice preprocess <action> ... 转发到声明该动作的 provider(如 audit / io_scan / link_check)
59
+
54
60
  其它 CLI(本入口不含,敲错会给出替代命令):
55
- audit-sluice 审计/规则/静态检查: audit ruleset file-io link-check scope-check functions tree-doc
56
61
  tool-sluice 工具链: module-splitter yaml-template readme-template self-check
62
+ 注:审计 CLI 已随审计能力独立成包(audit-sluice),不再由本插件提供。
57
63
 
58
64
  用法(每行写的参数就是该命令真实接受的写法,照抄即可):
59
65
  git-sluice version 查看版本
@@ -63,9 +69,9 @@ const HELP = `git-sluice v${VERSION} — ${CLI_ENTRIES[CLI_GIT].intro}
63
69
  同上,可读文本通道(scan 是它的注册表通道,输出更精简)
64
70
  git-sluice index <root> [--owner <账号>] [--depth N] [--max N] [--offline] [--json]
65
71
  重建仓库索引 dsh-repo-index.json(--offline=纯离线不查 GitHub API)
66
- git-sluice commit <repo> --message <msg> [--push|--no-push] [--audit] [--dry-run] [--force] [--ignore-patterns <模式>] [--requirements-confirmed] [--push-confirmed] [--paths <路径1,路径2>] [--message-items <JSON>] [--audit-exempt-paths <文件,...>] [--audit-exempt-reason <理由>] [--remote <名>] [--wait-ci] [--ci-timeout-sec N]
72
+ git-sluice commit <repo> --message <msg> [--push|--no-push] [--audit] [--dry-run] [--force] [--ignore-patterns <模式>] [--push-confirmed] [--paths <路径1,路径2>] [--message-items <JSON>] [--preprocess-stages <JSON|@文件>] [--audit-exempt-paths <文件,...>] [--audit-exempt-reason <理由>] [--remote <名>] [--wait-ci] [--ci-timeout-sec N]
67
73
  审计门禁 → 提交(默认只 commit 不 push;--push 推远端;--force 强推覆盖远端历史;
68
- --requirements-confirmed 显式核对开发者要求;--push-confirmed 显式放行推送门禁;
74
+ --push-confirmed 显式放行推送门禁;
69
75
  --paths 精确 add 指定文件替代 add -A;--audit-exempt-paths 本次提交按文件临时豁免审计)
70
76
  git-sluice clone <owner/repo> [dest] [--dest <目录>] [--branch <名>] [--history] [--history-depth N]
71
77
  从 GitHub 克隆仓库(Git Data API 通道,不直连 github.com;--history=重建真实提交历史)
@@ -128,6 +134,7 @@ export function renderHelp(cfg = {}, hasBuiltinEngine) {
128
134
  }
129
135
 
130
136
  export const COMMANDS = new Map([
137
+ ['preprocess', cmdPreprocess],
131
138
  ['repos', parseVia((flags, positional) => cmdRepos(positional[0] || '.', flags))],
132
139
  ['index', parseVia((flags, positional) => cmdIndex(positional[0] || '.', flags))],
133
140
  // `git` 必须走这里而不是注册表:注册表只认声明过的参数,会把 git 自己的 flag
package/lib/app/apply.js CHANGED
@@ -15,14 +15,13 @@ import { loadDefineTool, registerTools, registerContext, registerHttp, registerP
15
15
  // (settings 服务改为 SettingsForms:describe/update/replace/mutate/configure,命名空间由
16
16
  // Loader 条目派生)。本插件改为「特性检测自动切换」:旧宿主走 register 分支、0.2.0 走
17
17
  // describe 分支,故 GIT_PUSH_SETTINGS_NS(命名空间名)与 Config(旧分支注册用 schema)
18
- // 两个 import 仍需保留。按 comment-not-delete 保留原行注释,便于回退与对照。
19
- // 【原代码】import { GIT_PUSH_SETTINGS_NS, name } from './constants.js';
20
18
  import { GIT_PUSH_SETTINGS_NS } from './constants.js';
21
- import { AUDIT_API_PREFIX, adaptHttpHandler } from './http-handlers.js';
19
+ import { PREPROCESS_API_PREFIX, adaptHttpHandler } from './http-handlers.js';
22
20
  import { readSettings, applySettingsToCfg, writeSettingsKey } from './settings-bridge.js';
23
- import { FUNCTION_USAGE_HINT, README_CHECK_HINT, buildRequirementsInjectionText } from './inject-text.js';
24
- // 【原代码】import { Config } from './schema.js';
21
+ import { FUNCTION_USAGE_HINT, README_CHECK_HINT, buildIdentityInjectionText } from './inject-text.js';
25
22
  import { Config } from './schema.js';
23
+ // 提交前预处理开关的生效值
24
+ import { resolvePreCommitEnabled } from '../commit-push/pre-commit-engine.js';
26
25
  import { callTool } from './tool-call.js';
27
26
  import { listTools } from './tools.js';
28
27
  import { registerSlashCommands } from './slash-commands.js';
@@ -34,7 +33,7 @@ import { join } from 'node:path';
34
33
  // (agent/pre-step,registerPreStepInjection,见下方 2.5 步);systemPrompt 只留三段。
35
34
  const ORDER_USAGE = 990; // 功能用法(工具清单 + 凭据托管说明)
36
35
  const ORDER_README_CHECK = 991; // 提交前必须核对 README 的提醒
37
- const ORDER_REQUIREMENTS = 992; // 开发者要求清单(提交前逐条核对)
36
+ const ORDER_IDENTITY = 992; // 身份告知(避免 AI 猜错项目归属)
38
37
 
39
38
  /**
40
39
  * 插件应用入口(DSH 调用)。
@@ -149,8 +148,8 @@ export async function apply(ctx, config = {}) {
149
148
  // 功能用法(插件每个工具怎么用 + 凭据托管说明)
150
149
  { name: 'dsh-git-push-usage', order: ORDER_USAGE, text: () => (cfg.injectSystemPrompt ? (cfg.injectUsageText || FUNCTION_USAGE_HINT) : '') }, // injectUsageText 配置覆盖默认注入文本
151
150
  { name: 'dsh-git-push-readme-check', order: ORDER_README_CHECK, text: () => (cfg.injectSystemPrompt ? README_CHECK_HINT : '') },
152
- // 开发者要求清单(子开关:注入总开关 且 提交前审计 且 injectRequirements 才注入)
153
- { name: 'dsh-git-push-requirements', order: ORDER_REQUIREMENTS, text: () => (cfg.injectSystemPrompt && cfg.auditEnabled && cfg.injectRequirements ? buildRequirementsInjectionText() : '') },
151
+ // 身份告知注入(只受「注入系统提示词」总开关控制)
152
+ { name: 'dsh-git-push-identity', order: ORDER_IDENTITY, text: () => (cfg.injectSystemPrompt ? buildIdentityInjectionText() : '') },
154
153
  ],
155
154
  log,
156
155
  });
@@ -162,12 +161,12 @@ export async function apply(ctx, config = {}) {
162
161
  const preStepWired = registerPreStepInjection(ctx, { envInjectText, log });
163
162
 
164
163
  // 3) HTTP API:ctx.inject(['webServer']) → register({kind:'prefix', path, handler})
165
- // **同一个 handler 注册两个前缀**:/api/git-push(git+共享)与 /api/git-audit(审计)。
164
+ // **同一个 handler 注册两个前缀**:/api/git-push(git+共享)与 /api/preprocess(预处理,审计是其第一个 provider)。
166
165
  // 为什么不另写一个 handler:鉴权(checkOrigin/checkBodySize/写确认)在 handleHttp 的
167
166
  // switch 之前统一执行,复用同一入口才自动继承门禁;另起入口就是一个无门禁的裸端点。
168
167
  const httpHandler = (req, res) => adaptHttpHandler(req, res, { ...env, jobs }, cfg);
169
168
  const httpWired = registerHttp(ctx, { path: '/api/git-push', handler: httpHandler, log });
170
- const auditHttpWired = registerHttp(ctx, { path: AUDIT_API_PREFIX, handler: httpHandler, log });
169
+ const preprocessHttpWired = registerHttp(ctx, { path: PREPROCESS_API_PREFIX, handler: httpHandler, log });
171
170
 
172
171
  // 4) 设置命名空间:settings.register('git-push') —— Host 必须注册命名空间,
173
172
  // 配置卡(settings.plugin.item key=git-push)才会与 Host 命名空间相交显示
@@ -244,7 +243,7 @@ export async function apply(ctx, config = {}) {
244
243
  if (!next || typeof next !== 'object') return;
245
244
  // watch **只处理凭据**。开关/扫描范围/权重真源是插件私有
246
245
  // config.json(启动 merge + HTTP settings-set)。yaml 缺键时 schema 默认
247
- // injectRequirements=false,若把 yaml 整包灌进 cfg 会把 HTTP 刚写入的
246
+ // injectSystemPrompt=false,若把 yaml 整包灌进 cfg 会把 HTTP 刚写入的
248
247
  // true 盖回去——开关点了不对的根因。
249
248
  if (typeof next.githubToken === 'string' && next.githubToken.trim()) {
250
249
  cfg.githubToken = next.githubToken.trim();
@@ -267,7 +266,7 @@ export async function apply(ctx, config = {}) {
267
266
  console.error('[dsh-git-push] settings 接线失败:', e);
268
267
  }
269
268
 
270
- // 5) 用户输入框斜杠命令:ctx.inject(['commands']) → /git-audit(人直接跑审计,不进模型)
269
+ // 5) 用户输入框斜杠命令:ctx.inject(['commands']) → /git-scan 等(人直接跑,不进模型)
271
270
  const slashCount = registerSlashCommands(ctx, { env, cfg, log });
272
271
 
273
272
  // 5.5) 任务完成自动推送(内置自 dsh-task-completion):监听回合结束,
@@ -287,7 +286,10 @@ export async function apply(ctx, config = {}) {
287
286
  // 6) 客户端(设置卡片/侧边栏)不在 Host 注册:DSH 依据 package.json 的
288
287
  // dsh.client + exports["./client"] 自动发现 client.js。
289
288
 
290
- log?.info?.(`dsh-git-push v${VERSION} 已接线(工具 ${toolCount} 个 / 注入 ${sectionCount} 段 + ${preStepWired ? '上下文注入' : '上下文注入未接'} / HTTP ${httpWired ? '已注册' : '未注册'} / 斜杠 ${slashCount};审计默认${cfg.auditEnabled ? '开' : '关'} / 自动推送${autoPush.enabled ? '开(触发: ' + autoPush.trigger + ')' : '关'})`);
289
+ // 开关状态读生效值(resolvePreCommitEnabled 会把 config.json 里的真值算进来),
290
+ // 不直接读 cfg.preCommit.enabled:那只是 schema 默认值,会把「配置里其实开着」误报成关。
291
+ const preCommitState = resolvePreCommitEnabled(cfg);
292
+ log?.info?.(`dsh-git-push v${VERSION} 已接线(工具 ${toolCount} 个 / 注入 ${sectionCount} 段 + ${preStepWired ? '上下文注入' : '上下文注入未接'} / HTTP ${httpWired ? '已注册' : '未注册'} / 斜杠 ${slashCount};提交前预处理${preCommitState.enabled ? '开' : '关'}${preCommitState.source === 'legacy' ? '(沿用旧版开关键)' : ''} / 自动推送${autoPush.enabled ? '开(触发: ' + autoPush.trigger + ')' : '关'})`);
291
293
  // 【修复 】cordis 的 apply 返回值只能是 disposer 函数 / Promise / undefined;
292
294
  // 返回普通对象会抛 "Invalid effect" 导致插件树加载失败。插件内部注册均走 ctx.inject,
293
295
  // 生命周期由 cordis 管理,因此 apply 返回 undefined(标准写法)。
@@ -1,6 +1,20 @@
1
1
  // 审计预处理的「参数 / 可用性判据」真源在 lib/preprocess/audit.js(与 renderResult 同处一处);
2
2
  // 本文件只消费它们,并按历史路径 re-export(外部 import { auditPreprocessAvailable } 不受影响)。
3
- import { AUDIT_COMMIT_PARAMS, auditPreprocess, auditPreprocessAvailable } from '../preprocess/index.js';
3
+ import { resolveGateProvider } from '../commit-push/pre-commit-engine.js';
4
+
5
+ // 审计可用性判定(同步):包入口存在即「可用」。参数表在宿主侧维护(它们描述的是**宿主工具签名**)。
6
+ const AUDIT_COMMIT_PARAMS = [
7
+ { flag: 'audit', type: 'boolean', desc: '提交前审计(默认取配置)' },
8
+ { flag: 'auditExemptPaths', type: 'array', desc: '本次提交按文件临时豁免审计(数组,相对仓库根):所列文件的 finding 不参与拦截判定(含 blocker);仅本次有效,不落盘、不改 .auditignore' },
9
+ { flag: 'auditExemptReason', type: 'string', desc: '豁免理由(可选,仅回显,不作拦截条件)' },
10
+ ];
11
+ function auditPreprocessAvailable(cfg = {}, hasBuiltinEngine) {
12
+ if (cfg && cfg.preCommit && cfg.preCommit.command) return true;
13
+ const entry = resolveGateProvider();
14
+ const available = entry.ok;
15
+ return typeof hasBuiltinEngine === 'boolean' ? hasBuiltinEngine : available;
16
+ }
17
+ const auditPreprocess = { id: 'audit', params: AUDIT_COMMIT_PARAMS, enabled: auditPreprocessAvailable };
4
18
 
5
19
  export { AUDIT_COMMIT_PARAMS, auditPreprocessAvailable };
6
20
 
@@ -42,7 +56,7 @@ export const TOOL_REGISTRY = [
42
56
  ],
43
57
  },
44
58
  {
45
- name: 'git_commit_push', cli: 'commit', description: '一键提交并推送:一次调用 = 审计(blocker 拦截,可关)→ 有改动才 commit → 有可推内容才 push。零改动是**正常成功路径**:返回 ok:true + committed:false(job 状态 completed,不是失败);远端已最新则 ok:true + pushed:false;本地领先远端的已提交内容照样会推。message 必填(零改动时用不到);requirementsConfirmed=true(开发者要求全部核对达标)——**存在要求清单时任何调用都要带**(与有无改动、是否推送无关);push=false 只提交;dryRun 只模拟',
59
+ name: 'git_commit_push', cli: 'commit', description: '一键提交并推送:一次调用 = 审计(blocker 拦截,可关)→ 有改动才 commit → 有可推内容才 push。零改动是**正常成功路径**:返回 ok:true + committed:false(job 状态 completed,不是失败);远端已最新则 ok:true + pushed:false;本地领先远端的已提交内容照样会推。message 必填(零改动时用不到);push=false 只提交;dryRun 只模拟',
46
60
  // params 用函数形态:git 侧不写死审计层参数,审计可用时由预处理贡献(见文件头 AUDIT_COMMIT_PARAMS)
47
61
  params: (cfg, hasBuiltinEngine) => [
48
62
  { flag: 'repo', type: 'string', positional: 0, required: true, desc: '仓库绝对路径' },
@@ -55,9 +69,11 @@ export const TOOL_REGISTRY = [
55
69
  { flag: 'dryRun', type: 'boolean', desc: 'dry-run 只模拟不写入' },
56
70
  { flag: 'force', type: 'boolean', desc: 'force 强推(谨慎)' },
57
71
  { flag: 'ignorePatterns', type: 'string', desc: '自定义忽略 pattern(追加 .gitignore)' },
58
- { flag: 'requirementsConfirmed', type: 'boolean', desc: '已核对开发者要求' },
59
72
  { flag: 'pushConfirmed', type: 'boolean', desc: '推送门禁放行' },
60
73
  { flag: 'paths', type: 'string', desc: '精确 add 路径(逗号分隔)' },
74
+ // 本次调用的预处理链(覆盖配置文件里的 preCommit.stages)。
75
+ // 元素两种形态:{command,args?,onFail?,timeoutMs?} 跑任意脚本,或 {provider,onFail?,timeoutMs?} 走 provider 解析。
76
+ { flag: 'preprocessStages', type: 'array', desc: '本次调用的预处理阶段链(数组顺序即执行顺序,覆盖配置):元素为 {command,args?,onFail?,timeoutMs?} 或 {provider,onFail?,timeoutMs?};onFail=block|warn|skip(缺省 block);args 支持占位符 {repo}/{filesFile}/{filesCount}/{stage}' },
61
77
  { flag: 'remote', type: 'string', desc: '推送目标 remote(多 remote / fork 场景;缺省 origin)。推送与核验使用同一 remote' },
62
78
  { flag: 'waitCi', type: 'boolean', desc: '推送后等 CI 结果(默认不等):按推送的 sha 查 GitHub Actions,全绿=通过、任一失败=ciFailed、超时/无 CI 如实回报' },
63
79
  { flag: 'ciTimeoutSec', type: 'number', desc: '等 CI 的上限秒数(默认 900)' },
@@ -136,7 +152,7 @@ export const TOOL_REGISTRY = [
136
152
  ],
137
153
  },
138
154
  {
139
- name: 'io_scan', cli: 'file-io', description: 'I/O 风险扫描(AST 四级分级 high/medium/low/safe——与审计 io-risk 同标准)。repo=目标(默认工作区)、writeOnly=只看写操作',
155
+ name: 'io_scan', description: 'I/O 风险扫描(AST 四级分级 high/medium/low/safe——与审计 io-risk 同标准)。repo=目标(默认工作区)、writeOnly=只看写操作',
140
156
  params: [
141
157
  { flag: 'repo', type: 'string', positional: 0, desc: '扫描目标(默认工作区)' },
142
158
  { flag: 'writeOnly', type: 'boolean', desc: '只看写操作' },
@@ -154,7 +170,7 @@ export const TOOL_REGISTRY = [
154
170
  },
155
171
  {
156
172
  name: 'npm_publish', cli: 'npm-publish',
157
- description: 'npm 发包(后台 job + dryRun):默认 dryRun=true 只做体检与 npm publish --dry-run(不写 registry);真发必须同时 confirm=true 且 dryRun=false。dir=目标包目录(缺省工作区)、tag=发布 tag(默认 latest)、otp=2FA 一次性口令(可选)。前置体检:private:true 拦截、同名版本占用检测、npm pack 文件清单。凭据由插件托管(config.json 的 npmToken),无需 npm login、也无需向用户索要 token;缺凭据时工具会明确报错',
173
+ description: 'npm 发包(后台 job + dryRun)。**网络边界(重要)**:dryRun 预演**会查询真实上游 registry**(GET /<包名> 查版本占用,只读);但**绝不会写入公共 registry**(发包必须 confirm=true 且 dryRun=false)。想要全程不碰公网,用 localPreview=true(起本地 registry,publish/install/加载全走本机)。dir=目标包目录、tag=发布 tag(默认 latest)、otp=2FA 口令、localPreview=本地 registry 彩排(默认关)。前置体检:private:true 拦截、同名版本占用检测、npm pack 文件清单。凭据由插件托管(config.json 的 npmToken),无需 npm login',
158
174
  params: [
159
175
  { flag: 'dir', type: 'string', positional: 0, desc: '目标包目录(缺省工作区)' },
160
176
  { flag: 'dryRun', type: 'boolean', desc: '只预演(默认 true,不写 registry)' },
@@ -165,7 +181,7 @@ export const TOOL_REGISTRY = [
165
181
  { flag: 'waitVisible', type: 'boolean', desc: '发布后等待 registry 可见(默认 false:上传成功即为成功,可见延迟是已知现象;true 时每分钟查一次、最多 5 分钟)' },
166
182
  { flag: 'json', type: 'boolean', desc: 'JSON 输出(CLI 用;与其它工具同口径)' },
167
183
  { flag: 'skipSmoke', type: 'boolean', desc: '跳过发布前冒烟(默认跑:pack→干净目录安装→import 公开面→解析依赖;关掉会失去“装得上”这层门禁)' },
168
- { flag: 'localPreview', type: 'boolean', desc: '本地 registry 彩排(默认关):真实 publish 到本机 registry 再从它安装并加载公开面,不写公网;分钟级,发版前建议开一次' },
184
+ { flag: 'localPreview', type: 'boolean', desc: '本地 registry 彩排(默认关):起本机 registry,publish → install → 加载公开面全走它,**全程不碰公网**(连版本占用查询也不走公网)。分钟级,发版前建议开一次' },
169
185
  ],
170
186
  },
171
187
  {
@@ -176,7 +192,7 @@ export const TOOL_REGISTRY = [
176
192
  ],
177
193
  },
178
194
  {
179
- name: 'link_check', cli: 'link-check', description: '检查文档链接有效性(md/txt 内 URL——只报 warning 不拦截提交)。path=文件或目录(默认工作区)',
195
+ name: 'link_check', description: '检查文档链接有效性(md/txt 内 URL——只报 warning 不拦截提交)。path=文件或目录(默认工作区)',
180
196
  params: [
181
197
  { flag: 'path', type: 'string', positional: 0, desc: '文件或目录(默认工作区)' },
182
198
  ],
@@ -193,15 +209,6 @@ export const TOOL_REGISTRY = [
193
209
  { flag: 'json', type: 'boolean', desc: 'JSON 输出(CLI:git-sluice identity-rewrite --json)' },
194
210
  ],
195
211
  },
196
- {
197
- name: 'module_splitter', cli: 'module-splitter', description: '巨型单文件按顶层块拆分:analyze(先分析依赖)→ split(切分)→ verify(校验导出一致)。command=子命令、file/plan=目标 .js/plan.json、dryRun 预演',
198
- params: [
199
- { flag: 'command', type: 'string', enum: ['analyze', 'split', 'verify'], positional: 0, required: true, desc: '子命令' },
200
- { flag: 'file', type: 'string', desc: 'analyze 的待拆 .js 路径' },
201
- { flag: 'plan', type: 'string', desc: 'split/verify 的 plan.json 路径' },
202
- { flag: 'dryRun', type: 'boolean', desc: '只预演不落盘' },
203
- ],
204
- },
205
212
  {
206
213
  name: 'git_account_check', cli: 'account-check', description: '校验 GitHub 账号与凭据:token 在线校验 + SSH 公钥指纹——返回登录态/用户名/公钥数/套餐。token 不传自动解析;sshPub 非空顺带持久化',
207
214
  params: [
@@ -227,16 +234,16 @@ export const TOOL_REGISTRY = [
227
234
  ],
228
235
  },
229
236
  {
230
- name: 'git_api', cli: 'api', description: '直接调用本插件的 HTTP API(36 条接口,与浏览器/CLI 同源实现:内部走 handleHttp 同一条代码路径)。path=接口名:git/共享接口传短名(如 status / settings-get),审计接口推荐前缀相对写法(如 git-audit/audit、git-audit/rule-slots),也接受完整路径(/api/git-audit/…);短名形式的审计接口仍可用(旧前缀转发,响应带 Deprecation 头);method 默认 GET;query=查询参数 JSON(如 {"mode":"full"});body=POST 请求体 JSON;不传 path 则列出全部可用接口。写类接口(settings-set / repo-push 等)内部调用按本机同源放行。',
237
+ name: 'git_api', cli: 'api', description: '直接调用本插件的 HTTP API(36 条接口,与浏览器/CLI 同源实现:内部走 handleHttp 同一条代码路径)。path=接口名:git/共享接口传短名(如 status / settings-get),预处理接口推荐前缀相对写法(如 preprocess/audit、preprocess/rule-slots),也接受完整路径(/api/preprocess/…);短名形式仍可用(走 /api/git-push/*);旧审计前缀 /api/git-audit/* 与 /api/git-push/{那5条} 已完全下线(404);method 默认 GET;query=查询参数 JSON(如 {"mode":"full"});body=POST 请求体 JSON;不传 path 则列出全部可用接口。写类接口(settings-set / repo-push 等)内部调用按本机同源放行。',
231
238
  params: [
232
- { flag: 'path', type: 'string', positional: 0, desc: '接口名(缺省 = 列出全部接口);审计接口推荐 git-audit/<接口> 前缀相对写法' },
239
+ { flag: 'path', type: 'string', positional: 0, desc: '接口名(缺省 = 列出全部接口);预处理接口推荐 preprocess/<接口> 前缀相对写法,也接受 /api/preprocess/… 全路径' },
233
240
  { flag: 'method', type: 'string', desc: 'HTTP 方法(默认 GET;写操作传 POST)' },
234
241
  { flag: 'query', type: 'string', desc: '查询参数 JSON 字符串,如 {"mode":"full"}' },
235
242
  { flag: 'body', type: 'string', desc: 'POST 请求体 JSON 字符串' },
236
243
  ],
237
244
  },
238
245
  {
239
- name: 'scope_check', cli: 'scope-check', description: '检查 JS 拼接产物的作用域撞名(多段 JS 拼进同一作用域时,同帧内 var/function 同名会让后者静默顶掉前者、运行时毫无报错线索)。判定按真实作用域帧——两个不同函数里的同名局部变量不算撞名。默认只查「同一函数帧内重名」(通用,任何项目可用);被查项目在 package.json 的 dshScopeCheck 声明了 files/prefix/allowlist/topLevelMustBeEmpty 时,按**项目自己的契约**追加查「顶层零声明 + 共享作用域命名前缀」,没声明就不查前缀(不拿本项目的 dshgp_ 要求别人)。files 缺省取项目 dshScopeCheck.files',
246
+ name: 'scope_check', description: '检查 JS 拼接产物的作用域撞名(多段 JS 拼进同一作用域时,同帧内 var/function 同名会让后者静默顶掉前者、运行时毫无报错线索)。判定按真实作用域帧——两个不同函数里的同名局部变量不算撞名。默认只查「同一函数帧内重名」(通用,任何项目可用);被查项目在 package.json 的 dshScopeCheck 声明了 files/prefix/allowlist/topLevelMustBeEmpty 时,按**项目自己的契约**追加查「顶层零声明 + 共享作用域命名前缀」,没声明就不查前缀(不拿本项目的 dshgp_ 要求别人)。files 缺省取项目 dshScopeCheck.files',
240
247
  params: [
241
248
  { flag: 'files', type: 'string', positional: 0, desc: '目标文件(逗号分隔;缺省读项目 package.json 的 dshScopeCheck.files)' },
242
249
  { flag: 'repo', type: 'string', desc: '仓库根(缺省当前工作目录)' },
@@ -3,6 +3,14 @@
3
3
  */
4
4
  /** 本地列表 SSH live 探测整表共享预算(并发异步后为**上界**,超预算即跳过标 liveSkipped)。 */
5
5
  export const LIST_LIVE_BUDGET_MS = 15_000;
6
+ /**
7
+ * 远端状态的"新鲜期":超过它就在**后台**补查一次(请求本身只读索引,不联网)。
8
+ *
9
+ * 为什么要有这个数:列表接口把 27 次 SSH 内联在请求里时实测耗时 87s(前端 30s 必超时),
10
+ * 于是"打开本地页"= 报错。现在请求只返回索引快照,远端状态由后台补 —— 这个 TTL
11
+ * 决定"多久需要补一次",取 5 分钟:足够覆盖人工操作节奏,又不会让 ahead/behind 长期陈旧。
12
+ */
13
+ export const LIST_LIVE_TTL_MS = 5 * 60_000;
6
14
  /** 远端探测并发度。与 SSH 默认 MaxSessions 兼容,且不超过 GitHub 连接容忍度。 */
7
15
  export const PROBE_CONCURRENCY = 4;
8
16
  /**
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * HTTP 处理层 · git/共享元信息与只读端点(status/scan/browse/tools/tool-probes)
3
3
  *
4
- * 审计侧(rule-slots / rule-detail / audit / toggle-rule / exempt-hint)已搬到 handlers/audit.js,
5
- * 与 /api/git-audit 前缀同构——本文件不再 import 任何审计实现。
4
+ * 预处理侧(rule-slots / rule-detail / audit / toggle-rule / exempt-hint)已搬到 handlers/preprocess.js,
5
+ * 走 /api/preprocess 前缀——本文件不再 import 任何预处理实现。
6
6
  *
7
7
  * 从 http-handlers.js 的 handleHttp 巨型 switch 拆分而来。
8
8
  * 统一签名:handleXxx(ctx) → { status, body };ctx = { req, query, body, env, cfg, path, method }。
@@ -0,0 +1,104 @@
1
+ /**
2
+ * HTTP 处理器 · 审计侧(规则包 / 审计结果聚合 / 规则启停 / 豁免提示)
3
+ *
4
+ * 拆包后:**审计实现归 audit-sluice**,本文件只做 HTTP 整形(ctx → 包参数 → `{status, body}`)。
5
+ * 判定/聚合/规则加载一律经 `lib/app/preprocess-client.js` 调包;宿主不再持有实现副本。
6
+ * 注意:这些 handler(含 `listRuleSlots`)在本批**改为异步**——预处理实现是动态 import 加载的,
7
+ * 调用方(http-handlers / 外部导出)请 await。
8
+ */
9
+
10
+ import * as auditClient from '../preprocess-client.js';
11
+ import { getDefaultScanRoot } from '../scan-root.js';
12
+
13
+ /** 调预处理实现;包不可用 → 503(HTTP 要给可诊断状态,不是 500 一坨栈)。 */
14
+ async function withHostApi(handler) {
15
+ try {
16
+ const api = await auditClient.hostApi();
17
+ return await handler(api);
18
+ } catch (e) {
19
+ return { status: 503, body: { ok: false, code: 'AUDIT_PACKAGE_UNAVAILABLE', message: `预处理实现不可用:${e?.message || e}` } };
20
+ }
21
+ }
22
+
23
+ /**
24
+ * 规则包清单(按规则条数统计)。**异步**(预处理实现动态加载)。
25
+ * @param {string[]} [order] 规则包顺序
26
+ * @param {string[]} [disabledSlots] 禁用清单
27
+ * @param {object|null} [hitStats] 命中统计(仅回显)
28
+ * @returns {Promise<object>}
29
+ */
30
+ export async function listRuleSlots(order, disabledSlots = [], hitStats = null) {
31
+ const api = await auditClient.hostApi();
32
+ return api.listRuleSlots(order, disabledSlots, hitStats);
33
+ }
34
+
35
+ /** GET /api/preprocess/rule-slots */
36
+ export async function handleRuleSlots(ctx) {
37
+ return withHostApi(async (api) => ({
38
+ status: 200,
39
+ body: {
40
+ ok: true,
41
+ // 顺序与禁用清单都不再由宿主决定:两个参数留空,由审计包按自己的配置/yml 决定。
42
+ // 宿主传空数组会被理解成「显式不禁用任何规则包」,反而覆盖掉用户在包里配的禁用项。
43
+ slots: api.listRuleSlots(undefined, undefined, api.getLastSlotHitStats()),
44
+ },
45
+ }));
46
+ }
47
+
48
+ /** GET /api/preprocess/rule-detail */
49
+ export async function handleRuleDetail(ctx) {
50
+ const slot = String(ctx.query.slot || '');
51
+ if (!slot) return { status: 400, body: { ok: false, error: 'slot 必填(规则包名,如 nodejs)' } };
52
+ return withHostApi(async (api) => {
53
+ const detail = api.ruleDetail(slot);
54
+ if (!detail) return { status: 404, body: { ok: false, error: `规则包不存在:${slot}` } };
55
+ return { status: 200, body: { ok: true, slot, ...detail } };
56
+ });
57
+ }
58
+
59
+ /** GET|POST /api/preprocess/audit(请求时聚合,不落盘) */
60
+ export async function handleAudit(ctx) {
61
+ const { query, body, env, method } = ctx;
62
+ const params = method === 'POST' ? { ...query, ...(body || {}) } : query;
63
+ const repo = String(params.repo || getDefaultScanRoot(env, { defaultScanRoot: '' }));
64
+ if (!repo) return { status: 400, body: { ok: false, error: 'repo 必填(仓库绝对路径)' } };
65
+ return withHostApi(async (api) => {
66
+ const result = await api.auditAggregate({
67
+ repo,
68
+ scope: params.scope === 'diff' ? 'diff' : 'full',
69
+ groupBy: String(params.groupBy || 'rule'),
70
+ severity: String(params.severity || ''),
71
+ top: Number(params.top) || 20,
72
+ });
73
+ if (result?.ok === false) return { status: 400, body: { ok: false, error: result.error } };
74
+ return { status: 200, body: result };
75
+ });
76
+ }
77
+
78
+ /** POST /api/preprocess/toggle-rule */
79
+ export async function handleToggleRule(ctx) {
80
+ const slot = String(ctx.body?.slot || '');
81
+ if (!slot) return { status: 400, body: { ok: false, error: 'slot 必填' } };
82
+ return withHostApi(async (api) => ({
83
+ status: 200,
84
+ body: { ok: true, slot, disabled: api.toggleRule(slot, ctx.body?.disabled === true) },
85
+ }));
86
+ }
87
+
88
+ /** GET /api/preprocess/exempt-hint */
89
+ export async function handleExemptHint(ctx) {
90
+ const { query } = ctx;
91
+ const finding = { rule: String(query.rule || ''), kind: String(query.kind || ''), file: String(query.file || ''), line: Number(query.line) || 0 };
92
+ if (!finding.rule && !finding.kind) return { status: 400, body: { ok: false, error: 'rule 或 kind 必填(用于推导豁免标记)' } };
93
+ return withHostApi(async (api) => ({
94
+ status: 200,
95
+ body: {
96
+ ok: true,
97
+ rule: finding.rule,
98
+ kind: finding.kind,
99
+ marker: (api.exemptHintForFinding(finding) || {}).marker || null,
100
+ hint: (api.exemptHintForFinding(finding) || {}).hint || '无任何标记可豁免该 finding(应改代码,或走 .auditignore / 豁免槽位)',
101
+ candidates: Object.keys(api.EXEMPT_MARKERS).map((marker) => ({ marker, covers: api.exemptMarkerCovers(marker, finding) })),
102
+ },
103
+ }));
104
+ }