dsh-git-push 2.20.18 → 3.0.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 (198) hide show
  1. package/README.md +3 -2
  2. package/cli-tool.mjs +2 -4
  3. package/cli.mjs +36 -2
  4. package/lib/app/apply.js +9 -9
  5. package/lib/app/command-registry.js +44 -20
  6. package/lib/app/handlers/meta.js +7 -142
  7. package/lib/app/handlers/npm.js +18 -1
  8. package/lib/app/handlers/preprocess.js +107 -0
  9. package/lib/app/handlers/repo-actions.js +2 -2
  10. package/lib/app/http-handlers.js +25 -12
  11. package/lib/app/index.js +2 -1
  12. package/lib/app/inject-text.js +3 -2
  13. package/lib/app/preprocess-client.js +136 -0
  14. package/lib/app/repo-ownership.js +1 -1
  15. package/lib/app/schema.js +3 -3
  16. package/lib/app/severity.js +14 -0
  17. package/lib/app/slash-commands.js +5 -164
  18. package/lib/app/tool-call.js +75 -140
  19. package/lib/app/tools.js +13 -6
  20. package/lib/cli/commands-preprocess.mjs +74 -0
  21. package/lib/cli/commands-tool.mjs +3 -2
  22. package/lib/cli/commands-vcs.mjs +4 -4
  23. package/lib/cli/shared.mjs +42 -13
  24. package/lib/client-parts/git/controller.js +2 -2
  25. package/lib/client.js +2 -2
  26. package/lib/commit-push/pre-commit-engine.js +57 -10
  27. package/lib/commit-push.js +125 -36
  28. package/lib/{exempt/index.js → git/exempt-markers.js} +8 -1
  29. package/lib/git/ignore.js +1 -1
  30. package/lib/git/repos.js +2 -2
  31. package/lib/git/sensitive.js +1 -1
  32. package/lib/npm/publish.js +20 -5
  33. package/lib/plugin/auto-push.js +2 -2
  34. package/lib/preprocess/providers.js +191 -0
  35. package/lib/self/index.js +1 -1
  36. package/lib/skip-dirs.js +14 -55
  37. package/package.json +29 -37
  38. package/scripts/build-client.mjs +2 -0
  39. package/scripts/check.mjs +4 -2
  40. package/scripts/local-registry.mjs +2 -1
  41. package/skills/dev/dsh-git-push.md +5 -0
  42. package/cli-audit.mjs +0 -141
  43. package/lib/app/audit-api.js +0 -173
  44. package/lib/app/host-doc-checks.js +0 -25
  45. package/lib/app/scope-check.js +0 -69
  46. package/lib/ast/brace.js +0 -120
  47. package/lib/ast/callgraph.js +0 -135
  48. package/lib/ast/code-lines.js +0 -175
  49. package/lib/ast/consts.js +0 -12
  50. package/lib/ast/control-flow.js +0 -470
  51. package/lib/ast/credential.js +0 -315
  52. package/lib/ast/dataflow.js +0 -391
  53. package/lib/ast/dup-code.js +0 -165
  54. package/lib/ast/fs-hotspots.js +0 -154
  55. package/lib/ast/index.js +0 -38
  56. package/lib/ast/io-risk-const.js +0 -95
  57. package/lib/ast/io-risk-fn.js +0 -208
  58. package/lib/ast/io-risk-loop.js +0 -308
  59. package/lib/ast/io-risk.js +0 -314
  60. package/lib/ast/lang.js +0 -156
  61. package/lib/ast/line-count.js +0 -52
  62. package/lib/ast/magic-number.js +0 -272
  63. package/lib/ast/naming.js +0 -292
  64. package/lib/ast/perf.js +0 -488
  65. package/lib/ast/scope-collisions.js +0 -228
  66. package/lib/ast/scope.js +0 -241
  67. package/lib/ast/shell.js +0 -131
  68. package/lib/ast/size.js +0 -448
  69. package/lib/ast/symbol-index.js +0 -399
  70. package/lib/ast/tokenizer.js +0 -421
  71. package/lib/ast/treesitter.js +0 -413
  72. package/lib/audit/analysis-coverage.js +0 -98
  73. package/lib/audit/audit-file.js +0 -205
  74. package/lib/audit/auditignore-rules.js +0 -148
  75. package/lib/audit/checks.js +0 -17
  76. package/lib/audit/client-entry.js +0 -93
  77. package/lib/audit/collector.js +0 -610
  78. package/lib/audit/ext-runner.js +0 -80
  79. package/lib/audit/file-context.js +0 -391
  80. package/lib/audit/finding.js +0 -101
  81. package/lib/audit/gitignore-match.js +0 -113
  82. package/lib/audit/glob.js +0 -63
  83. package/lib/audit/history-report.js +0 -100
  84. package/lib/audit/history.js +0 -126
  85. package/lib/audit/ignore-blind.js +0 -102
  86. package/lib/audit/index.js +0 -33
  87. package/lib/audit/orchestrate.js +0 -672
  88. package/lib/audit/public.js +0 -24
  89. package/lib/audit/repo-level.js +0 -30
  90. package/lib/audit/report-yaml.js +0 -90
  91. package/lib/audit/scope-policy.js +0 -110
  92. package/lib/audit/slot.js +0 -66
  93. package/lib/audit-rules/audit-rules-comment.yml +0 -199
  94. package/lib/audit-rules/audit-rules-cpp.yml +0 -114
  95. package/lib/audit-rules/audit-rules-csharp.yml +0 -82
  96. package/lib/audit-rules/audit-rules-docs.yml +0 -32
  97. package/lib/audit-rules/audit-rules-dsh.yml +0 -177
  98. package/lib/audit-rules/audit-rules-filehealth.yml +0 -42
  99. package/lib/audit-rules/audit-rules-folder.yml +0 -99
  100. package/lib/audit-rules/audit-rules-frontend.yml +0 -335
  101. package/lib/audit-rules/audit-rules-go.yml +0 -103
  102. package/lib/audit-rules/audit-rules-i18n.yml +0 -45
  103. package/lib/audit-rules/audit-rules-java.yml +0 -105
  104. package/lib/audit-rules/audit-rules-nodejs.yml +0 -662
  105. package/lib/audit-rules/audit-rules-npm.yml +0 -187
  106. package/lib/audit-rules/audit-rules-paths.yml +0 -98
  107. package/lib/audit-rules/audit-rules-performance.yml +0 -245
  108. package/lib/audit-rules/audit-rules-php.yml +0 -101
  109. package/lib/audit-rules/audit-rules-private.yml +0 -24
  110. package/lib/audit-rules/audit-rules-python.yml +0 -106
  111. package/lib/audit-rules/audit-rules-robustness.yml +0 -31
  112. package/lib/audit-rules/audit-rules-rust.yml +0 -109
  113. package/lib/audit-rules/audit-rules-structure.yml +0 -158
  114. package/lib/audit-rules/audit-rules-swift.yml +0 -99
  115. package/lib/audit-rules/audit-rules-template.yml +0 -108
  116. package/lib/audit-ui-sdk/contract.js +0 -117
  117. package/lib/audit-ui-sdk/index.js +0 -17
  118. package/lib/checks/button-bind.js +0 -347
  119. package/lib/checks/common.js +0 -170
  120. package/lib/checks/credential-file.js +0 -43
  121. package/lib/checks/dataflow.js +0 -40
  122. package/lib/checks/dispatch.js +0 -117
  123. package/lib/checks/dup-code.js +0 -69
  124. package/lib/checks/dup-const.js +0 -232
  125. package/lib/checks/file-health.js +0 -150
  126. package/lib/checks/filter.js +0 -137
  127. package/lib/checks/folder.js +0 -173
  128. package/lib/checks/fs-scanner.js +0 -57
  129. package/lib/checks/hardcoded-path.js +0 -98
  130. package/lib/checks/index.js +0 -49
  131. package/lib/checks/io.js +0 -66
  132. package/lib/checks/magic-number.js +0 -42
  133. package/lib/checks/npm-json.js +0 -273
  134. package/lib/checks/private.js +0 -64
  135. package/lib/checks/regex.js +0 -298
  136. package/lib/checks/scope-collision.js +0 -68
  137. package/lib/checks/semantic.js +0 -134
  138. package/lib/checks/structural.js +0 -281
  139. package/lib/cli/commands-audit.mjs +0 -142
  140. package/lib/cli/commands-doc.mjs +0 -127
  141. package/lib/client-parts/audit/audit.js +0 -301
  142. package/lib/exempt/tool.js +0 -198
  143. package/lib/git/module-splitter.js +0 -47
  144. package/lib/link-check/index.js +0 -187
  145. package/lib/lint-adapter/detect.js +0 -161
  146. package/lib/lint-adapter/index.js +0 -50
  147. package/lib/lint-adapter/runner.js +0 -133
  148. package/lib/rule/compilers/credential.js +0 -62
  149. package/lib/rule/compilers/dataflow.js +0 -38
  150. package/lib/rule/compilers/file-health.js +0 -75
  151. package/lib/rule/compilers/frontend.js +0 -86
  152. package/lib/rule/compilers/func.js +0 -35
  153. package/lib/rule/compilers/helpers.js +0 -71
  154. package/lib/rule/compilers/index.js +0 -29
  155. package/lib/rule/compilers/link-semantic.js +0 -45
  156. package/lib/rule/compilers/list-kinds.js +0 -12
  157. package/lib/rule/compilers/numeric-kinds.js +0 -73
  158. package/lib/rule/compilers/regex.js +0 -78
  159. package/lib/rule/compilers/structure.js +0 -107
  160. package/lib/rule/compilers.js +0 -17
  161. package/lib/rule/homoglyph.js +0 -45
  162. package/lib/rule/loader.js +0 -274
  163. package/lib/rule/registry.js +0 -122
  164. package/lib/rule/scope.js +0 -67
  165. package/lib/score/docs-score.js +0 -166
  166. package/lib/score/index.js +0 -234
  167. package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
  168. package/scripts/audit-ext/_example-readme-present.mjs +0 -34
  169. package/scripts/audit-ext/dsh-inject-declarations.mjs +0 -209
  170. package/scripts/audit-ext/variable-min-length.mjs +0 -102
  171. package/scripts/audit-gate.mjs +0 -235
  172. package/scripts/audit-runner.mjs +0 -35
  173. package/scripts/audit-runtime-check.mjs +0 -129
  174. package/scripts/browser-page-probe.mjs +0 -271
  175. package/scripts/check-js-scope.mjs +0 -87
  176. package/scripts/clean-date-comments.py +0 -102
  177. package/scripts/cpu-sample.mjs +0 -188
  178. package/scripts/doc-drift.mjs +0 -200
  179. package/scripts/hot-path-probe-cjs.cjs +0 -71
  180. package/scripts/hot-path-probe-fs-shim.mjs +0 -28
  181. package/scripts/hot-path-probe-fsp-shim.mjs +0 -31
  182. package/scripts/hot-path-probe.mjs +0 -153
  183. package/scripts/module-splitter.py +0 -800
  184. package/scripts/picker-repro.mjs +0 -115
  185. package/scripts/platform-scan.mjs +0 -168
  186. package/scripts/probe-recheck.mjs +0 -47
  187. package/scripts/rename-locator.mjs +0 -97
  188. package/scripts/rule-switch.mjs +0 -97
  189. package/scripts/rules-solo-audit.mjs +0 -173
  190. package/scripts/scan-file-io.mjs +0 -717
  191. package/scripts/scan-fs-hotspots.mjs +0 -107
  192. package/scripts/symbol-index.mjs +0 -85
  193. package/scripts/verify-prestep.mjs +0 -100
  194. package/skills/dev/audit-rule-authoring.md +0 -58
  195. package/skills/guide/guide-audit.md +0 -270
  196. /package/lib/{audit → app}/ownership.js +0 -0
  197. /package/lib/app/{schema-audit.js → schema-preprocess.js} +0 -0
  198. /package/lib/{audit-defaults.js → git/defaults.js} +0 -0
package/README.md CHANGED
@@ -17,7 +17,7 @@ DSH 的 git 提交推送与代码审计插件:提交前自动过审计门禁
17
17
  | 改名 | 给远程仓库改名(dryRun 默认开,列出旧名出现位置) | `git_remote_rename` / `rename` |
18
18
  | 凭据与账号 | 校验 GitHub token 与 SSH 公钥、生成密钥对 | `git_account_check` / `git_gen_ssh_key` |
19
19
  | 身份改写 | 把历史提交身份统一成登录账号 | `git_identity_rewrite` / `identity-rewrite` |
20
- | 发布 | 发布 npm 包(dryRun 默认只体检;凭据由插件托管,无需 npm login) | `npm_publish` / `npm-publish` |
20
+ | 发布 | 发布 npm 包(dryRun 默认只体检;凭据由插件托管,无需 npm login)。**网络边界**:dryRun 会 GET 真实上游查版本占用(只读),但绝不写入公共 registry;`localPreview=true` 全程不碰公网 | `npm_publish` / `npm-publish` |
21
21
  | 撤包 | 从 registry 撤版本(默认 dryRun 预检,不可逆) | `npm_unpublish` / `unpublish` |
22
22
  | 豁免标记 | 给文件加/删豁免注释并校验是否真生效 | `exempt` |
23
23
  | I/O 风险扫描 | 扫描读写操作的风险分级 | `io_scan` / `file-io` |
@@ -65,7 +65,8 @@ git_gen_ssh_key({ email, force }) // email 必填;force 可
65
65
  git_identity_rewrite({ paths, dryRun, write, push }) // 全可空:dryRun 默认只报告,write 才改写
66
66
  git_remote_create({ repo, visibility, dryRun }) // repo 必填;visibility 可空(空=private)
67
67
  git_set_visibility({ repo, visibility }) // 两者必填
68
- npm_publish({ dir, dryRun, confirm, tag, otp }) // dryRun 默认 true(只体检);真发需 confirm=true 且 dryRun=false
68
+ npm_publish({ dir, dryRun, confirm, tag, otp }) // dryRun 默认 true(只体检,不写 registry)
69
+ npm_publish({ dir, localPreview: true }) // 本地 registry 彩排:publish→install→加载全走本机,全程不碰公网
69
70
  exempt({ action, rule, path, scope, line, reason }) // action 与 rule 必填;path 可数组;scope=header(文件头)或 line
70
71
  io_scan({ repo, writeOnly }) // 两者都可空:writeOnly 空=读写都看
71
72
  link_check({ path }) // path 可空:空=整个工作区
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
@@ -14,6 +14,7 @@
14
14
  */
15
15
  import { VERSION } from './lib/self/index.js';
16
16
  import { runWrappedGit } from './lib/git/wrapped-git.js';
17
+ import { auditPreprocessAvailable } from './lib/app/command-registry.js';
17
18
 
18
19
  // 具名 import 而非 `export ... from`:COMMANDS 表直接引用 cmdXxx 变量名,
19
20
  // re-export 不建立本模块作用域绑定,会 ReferenceError。
@@ -21,6 +22,7 @@ import {
21
22
  cmdAccountCheck, cmdCredEnv, cmdRemoteCreate, cmdSetVisibility, cmdGenSshKey,
22
23
  } from './lib/cli/commands-account.mjs';
23
24
  import { cmdRepos, cmdIndex, cmdCommit, cmdClone } from './lib/cli/commands-vcs.mjs';
25
+ import { cmdPreprocess } from './lib/cli/commands-preprocess.mjs';
24
26
  import {
25
27
  CLI_GIT, CLI_ENTRIES, cliPluginConfig, parseArgv, parseVia, printToolResult, runAsEntry, runCli,
26
28
  } from './lib/cli/shared.mjs';
@@ -50,9 +52,13 @@ const HELP = `git-sluice v${VERSION} — ${CLI_ENTRIES[CLI_GIT].intro}
50
52
  git-sluice commit <仓库> --message "msg" ③ 提交推送(自动过审计门禁)
51
53
  git-sluice help 全部命令与参数
52
54
 
55
+ 预处理(可插拔扩展:从所有在位 provider 的声明里找能力,审计只是其中之一):
56
+ git-sluice preprocess 列出当前可用的预处理动作
57
+ git-sluice preprocess <action> ... 转发到声明该动作的 provider(如 audit / io_scan / link_check)
58
+
53
59
  其它 CLI(本入口不含,敲错会给出替代命令):
54
- audit-sluice 审计/规则/静态检查: audit ruleset file-io link-check scope-check functions tree-doc
55
60
  tool-sluice 工具链: module-splitter yaml-template readme-template self-check
61
+ 注:审计 CLI 已随审计能力独立成包(audit-sluice),不再由本插件提供。
56
62
 
57
63
  用法(每行写的参数就是该命令真实接受的写法,照抄即可):
58
64
  git-sluice version 查看版本
@@ -99,7 +105,35 @@ const HELP = `git-sluice v${VERSION} — ${CLI_ENTRIES[CLI_GIT].intro}
99
105
 
100
106
  /** 命令表(本侧独有的 COMMANDS;注册表驱动的命令由 shared 的 resolveDispatch 处理)。
101
107
  * 注:`git` 不用登记——注册表(git_sluice)已覆盖它,旧 cli.mjs 里那条 COMMANDS['git'] 是死代码。 */
108
+ /**
109
+ * HELP 文本里与「提交前审计预处理」绑定的片段。
110
+ * 为什么要有这张表:参数表(command-registry 的 params)已经是**动态**的——
111
+ * 审计引擎不可用时 `--audit*` 不入签名(传了报「未知参数」);但 HELP 是**手写快照**,
112
+ * 不跟着动态就会在审计剥离后仍宣传一个不存在的参数。审计不可用时按这张表把片段从渲染结果里剔掉。
113
+ * 漂移防护:test/tool/test-cli.mjs 断言「每个片段都真的出现在 HELP 里」——改了 HELP 忘改表会变红。
114
+ */
115
+ export const AUDIT_HELP_SNIPPETS = Object.freeze([
116
+ ' [--audit]',
117
+ ' [--audit-exempt-paths <文件,...>]',
118
+ ' [--audit-exempt-reason <理由>]',
119
+ ';--audit-exempt-paths 本次提交按文件临时豁免审计',
120
+ ]);
121
+
122
+ /**
123
+ * 渲染本侧 HELP(按当前配置决定审计参数出不出现)。
124
+ * @param {object} [cfg] 插件配置
125
+ * @param {boolean} [hasBuiltinEngine] 仅供测试注入「内置引擎是否存在」
126
+ * @returns {string}
127
+ */
128
+ export function renderHelp(cfg = {}, hasBuiltinEngine) {
129
+ if (auditPreprocessAvailable(cfg, hasBuiltinEngine)) return HELP;
130
+ let text = HELP;
131
+ for (const snippet of AUDIT_HELP_SNIPPETS) text = text.split(snippet).join('');
132
+ return text;
133
+ }
134
+
102
135
  export const COMMANDS = new Map([
136
+ ['preprocess', cmdPreprocess],
103
137
  ['repos', parseVia((flags, positional) => cmdRepos(positional[0] || '.', flags))],
104
138
  ['index', parseVia((flags, positional) => cmdIndex(positional[0] || '.', flags))],
105
139
  // `git` 必须走这里而不是注册表:注册表只认声明过的参数,会把 git 自己的 flag
@@ -132,7 +166,7 @@ export async function main(argv = process.argv.slice(2)) {
132
166
  cliName: CLI_GIT,
133
167
  argv,
134
168
  commands: COMMANDS,
135
- helpText: HELP,
169
+ helpText: () => renderHelp(cliPluginConfig()),
136
170
  passthroughGit,
137
171
  getConfig: cliPluginConfig,
138
172
  });
package/lib/app/apply.js CHANGED
@@ -18,7 +18,7 @@ import { loadDefineTool, registerTools, registerContext, registerHttp, registerP
18
18
  // 两个 import 仍需保留。按 comment-not-delete 保留原行注释,便于回退与对照。
19
19
  // 【原代码】import { GIT_PUSH_SETTINGS_NS, name } from './constants.js';
20
20
  import { GIT_PUSH_SETTINGS_NS } from './constants.js';
21
- import { adaptHttpHandler } from './http-handlers.js';
21
+ import { PREPROCESS_API_PREFIX, adaptHttpHandler } from './http-handlers.js';
22
22
  import { readSettings, applySettingsToCfg, writeSettingsKey } from './settings-bridge.js';
23
23
  import { FUNCTION_USAGE_HINT, README_CHECK_HINT, buildRequirementsInjectionText } from './inject-text.js';
24
24
  // 【原代码】import { Config } from './schema.js';
@@ -79,7 +79,7 @@ export async function apply(ctx, config = {}) {
79
79
  } catch { fsCtx = null; }
80
80
  const toolCount = registerTools(ctx, {
81
81
  defineTool,
82
- tools: listTools(),
82
+ tools: listTools(cfg), // 传 cfg:函数形态的 params 按当前配置求值
83
83
  // 透传 exec(宿主执行工具时注入 exec.agent)——callTool 用它作 jobs.start 的
84
84
  // owner(owner 对上了 scoped job 控制器才会放行,否则 start 抛 no controller serves)。
85
85
  // 末位透传 fsCtx:工具成功后据此补发 fs/observed(actor=本次 exec ✓)
@@ -162,12 +162,12 @@ export async function apply(ctx, config = {}) {
162
162
  const preStepWired = registerPreStepInjection(ctx, { envInjectText, log });
163
163
 
164
164
  // 3) HTTP API:ctx.inject(['webServer']) → register({kind:'prefix', path, handler})
165
- const httpWired = registerHttp(ctx, {
166
- path: '/api/git-push',
167
- // 把宿主 jobs 传进 env(repos-local 等重端点用它做后台扫描,避免卡前台)
168
- handler: (req, res) => adaptHttpHandler(req, res, { ...env, jobs }, cfg),
169
- log,
170
- });
165
+ // **同一个 handler 注册两个前缀**:/api/git-push(git+共享)与 /api/preprocess(预处理,审计是其第一个 provider)。
166
+ // 为什么不另写一个 handler:鉴权(checkOrigin/checkBodySize/写确认)在 handleHttp 的
167
+ // switch 之前统一执行,复用同一入口才自动继承门禁;另起入口就是一个无门禁的裸端点。
168
+ const httpHandler = (req, res) => adaptHttpHandler(req, res, { ...env, jobs }, cfg);
169
+ const httpWired = registerHttp(ctx, { path: '/api/git-push', handler: httpHandler, log });
170
+ const preprocessHttpWired = registerHttp(ctx, { path: PREPROCESS_API_PREFIX, handler: httpHandler, log });
171
171
 
172
172
  // 4) 设置命名空间:settings.register('git-push') —— Host 必须注册命名空间,
173
173
  // 配置卡(settings.plugin.item key=git-push)才会与 Host 命名空间相交显示
@@ -267,7 +267,7 @@ export async function apply(ctx, config = {}) {
267
267
  console.error('[dsh-git-push] settings 接线失败:', e);
268
268
  }
269
269
 
270
- // 5) 用户输入框斜杠命令:ctx.inject(['commands']) → /git-audit(人直接跑审计,不进模型)
270
+ // 5) 用户输入框斜杠命令:ctx.inject(['commands']) → /git-scan 等(人直接跑,不进模型)
271
271
  const slashCount = registerSlashCommands(ctx, { env, cfg, log });
272
272
 
273
273
  // 5.5) 任务完成自动推送(内置自 dsh-task-completion):监听回合结束,
@@ -1,3 +1,36 @@
1
+ // 审计预处理的「参数 / 可用性判据」真源在 lib/preprocess/audit.js(与 renderResult 同处一处);
2
+ // 本文件只消费它们,并按历史路径 re-export(外部 import { auditPreprocessAvailable } 不受影响)。
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 };
18
+
19
+ export { AUDIT_COMMIT_PARAMS, auditPreprocessAvailable };
20
+
21
+ /**
22
+ * 解析注册表条目的 params(支持数组与函数两种形态)。
23
+ * 函数形态用于「参数按当前配置动态组装」——本意是 git 侧不写死审计层参数。
24
+ * @param {{params: Array|Function}} entry
25
+ * @param {object} [cfg] 当前插件配置(函数形态时传入)
26
+ * @returns {Array} 参数 schema 数组
27
+ */
28
+ export function resolveEntryParams(entry, cfg, hasBuiltinEngine) {
29
+ const raw = entry && entry.params;
30
+ // 第三个参数只为「测试可注入内置引擎可用性」而存在:生产调用不传 ⇒ 走真实文件存在性判断
31
+ return typeof raw === 'function' ? (raw(cfg || {}, hasBuiltinEngine) || []) : (raw || []);
32
+ }
33
+
1
34
  /**
2
35
  * 工具命令注册表(方案 B——命令注册表元数据驱动,免维护 CLI)
3
36
  *
@@ -24,7 +57,8 @@ export const TOOL_REGISTRY = [
24
57
  },
25
58
  {
26
59
  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 只模拟',
27
- params: [
60
+ // params 用函数形态:git 侧不写死审计层参数,审计可用时由预处理贡献(见文件头 AUDIT_COMMIT_PARAMS)
61
+ params: (cfg, hasBuiltinEngine) => [
28
62
  { flag: 'repo', type: 'string', positional: 0, required: true, desc: '仓库绝对路径' },
29
63
  { flag: 'message', type: 'string', required: true, desc: 'commit message(字符串,必填):可写整条提交信息;要传结构化多条目请用 messageItems(它会作为要点与正文)' },
30
64
  // ⚠️ 数组/对象形态**必须走独立参数**:宿主在进插件之前先按工具 JSON schema 校验参数,
@@ -32,18 +66,17 @@ export const TOOL_REGISTRY = [
32
66
  // 都被读成 string ✗,报 invalid arguments: "message" must be a string ⇒ 非字符串根本到不了插件 ✓)
33
67
  { flag: 'messageItems', type: 'array', desc: '结构化条目数组:元素为字符串,或 {what,type?,scope?,why?,verify?,refs?};仅 what 必填,type/scope/why/verify/refs 可空' },
34
68
  { flag: 'push', type: 'boolean', default: true, desc: '是否推送(默认 true)' },
35
- { flag: 'audit', type: 'boolean', desc: '提交前审计(默认取配置)' },
36
69
  { flag: 'dryRun', type: 'boolean', desc: 'dry-run 只模拟不写入' },
37
70
  { flag: 'force', type: 'boolean', desc: 'force 强推(谨慎)' },
38
71
  { flag: 'ignorePatterns', type: 'string', desc: '自定义忽略 pattern(追加 .gitignore)' },
39
72
  { flag: 'requirementsConfirmed', type: 'boolean', desc: '已核对开发者要求' },
40
73
  { flag: 'pushConfirmed', type: 'boolean', desc: '推送门禁放行' },
41
74
  { flag: 'paths', type: 'string', desc: '精确 add 路径(逗号分隔)' },
42
- { flag: 'auditExemptPaths', type: 'array', desc: '本次提交按文件临时豁免审计(数组,相对仓库根):所列文件的 finding 不参与拦截判定(含 blocker);仅本次有效,不落盘、不改 .auditignore' },
43
- { flag: 'auditExemptReason', type: 'string', desc: '豁免理由(可选,仅回显,不作拦截条件)' },
44
75
  { flag: 'remote', type: 'string', desc: '推送目标 remote(多 remote / fork 场景;缺省 origin)。推送与核验使用同一 remote' },
45
76
  { flag: 'waitCi', type: 'boolean', desc: '推送后等 CI 结果(默认不等):按推送的 sha 查 GitHub Actions,全绿=通过、任一失败=ciFailed、超时/无 CI 如实回报' },
46
77
  { flag: 'ciTimeoutSec', type: 'number', desc: '等 CI 的上限秒数(默认 900)' },
78
+ // 审计预处理贡献的参数(不可用时这里为空 ⇒ 传了会报「未知参数」,而不是静默忽略)
79
+ ...(auditPreprocess.enabled(cfg, hasBuiltinEngine) ? auditPreprocess.params : []),
47
80
  ],
48
81
  },
49
82
  {
@@ -117,7 +150,7 @@ export const TOOL_REGISTRY = [
117
150
  ],
118
151
  },
119
152
  {
120
- name: 'io_scan', cli: 'file-io', description: 'I/O 风险扫描(AST 四级分级 high/medium/low/safe——与审计 io-risk 同标准)。repo=目标(默认工作区)、writeOnly=只看写操作',
153
+ name: 'io_scan', description: 'I/O 风险扫描(AST 四级分级 high/medium/low/safe——与审计 io-risk 同标准)。repo=目标(默认工作区)、writeOnly=只看写操作',
121
154
  params: [
122
155
  { flag: 'repo', type: 'string', positional: 0, desc: '扫描目标(默认工作区)' },
123
156
  { flag: 'writeOnly', type: 'boolean', desc: '只看写操作' },
@@ -135,7 +168,7 @@ export const TOOL_REGISTRY = [
135
168
  },
136
169
  {
137
170
  name: 'npm_publish', cli: 'npm-publish',
138
- 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;缺凭据时工具会明确报错',
171
+ 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',
139
172
  params: [
140
173
  { flag: 'dir', type: 'string', positional: 0, desc: '目标包目录(缺省工作区)' },
141
174
  { flag: 'dryRun', type: 'boolean', desc: '只预演(默认 true,不写 registry)' },
@@ -146,7 +179,7 @@ export const TOOL_REGISTRY = [
146
179
  { flag: 'waitVisible', type: 'boolean', desc: '发布后等待 registry 可见(默认 false:上传成功即为成功,可见延迟是已知现象;true 时每分钟查一次、最多 5 分钟)' },
147
180
  { flag: 'json', type: 'boolean', desc: 'JSON 输出(CLI 用;与其它工具同口径)' },
148
181
  { flag: 'skipSmoke', type: 'boolean', desc: '跳过发布前冒烟(默认跑:pack→干净目录安装→import 公开面→解析依赖;关掉会失去“装得上”这层门禁)' },
149
- { flag: 'localPreview', type: 'boolean', desc: '本地 registry 彩排(默认关):真实 publish 到本机 registry 再从它安装并加载公开面,不写公网;分钟级,发版前建议开一次' },
182
+ { flag: 'localPreview', type: 'boolean', desc: '本地 registry 彩排(默认关):起本机 registry,publish → install → 加载公开面全走它,**全程不碰公网**(连版本占用查询也不走公网)。分钟级,发版前建议开一次' },
150
183
  ],
151
184
  },
152
185
  {
@@ -157,7 +190,7 @@ export const TOOL_REGISTRY = [
157
190
  ],
158
191
  },
159
192
  {
160
- name: 'link_check', cli: 'link-check', description: '检查文档链接有效性(md/txt 内 URL——只报 warning 不拦截提交)。path=文件或目录(默认工作区)',
193
+ name: 'link_check', description: '检查文档链接有效性(md/txt 内 URL——只报 warning 不拦截提交)。path=文件或目录(默认工作区)',
161
194
  params: [
162
195
  { flag: 'path', type: 'string', positional: 0, desc: '文件或目录(默认工作区)' },
163
196
  ],
@@ -174,15 +207,6 @@ export const TOOL_REGISTRY = [
174
207
  { flag: 'json', type: 'boolean', desc: 'JSON 输出(CLI:git-sluice identity-rewrite --json)' },
175
208
  ],
176
209
  },
177
- {
178
- name: 'module_splitter', cli: 'module-splitter', description: '巨型单文件按顶层块拆分:analyze(先分析依赖)→ split(切分)→ verify(校验导出一致)。command=子命令、file/plan=目标 .js/plan.json、dryRun 预演',
179
- params: [
180
- { flag: 'command', type: 'string', enum: ['analyze', 'split', 'verify'], positional: 0, required: true, desc: '子命令' },
181
- { flag: 'file', type: 'string', desc: 'analyze 的待拆 .js 路径' },
182
- { flag: 'plan', type: 'string', desc: 'split/verify 的 plan.json 路径' },
183
- { flag: 'dryRun', type: 'boolean', desc: '只预演不落盘' },
184
- ],
185
- },
186
210
  {
187
211
  name: 'git_account_check', cli: 'account-check', description: '校验 GitHub 账号与凭据:token 在线校验 + SSH 公钥指纹——返回登录态/用户名/公钥数/套餐。token 不传自动解析;sshPub 非空顺带持久化',
188
212
  params: [
@@ -208,16 +232,16 @@ export const TOOL_REGISTRY = [
208
232
  ],
209
233
  },
210
234
  {
211
- name: 'git_api', cli: 'api', description: '直接调用本插件的 HTTP API(36 条接口,与浏览器/CLI 同源实现:内部走 handleHttp 同一条代码路径)。path=接口名(去掉 /api/git-push/ 前缀,如 status / rule-slots / audit / settings-get);method 默认 GET;query=查询参数 JSON(如 {"mode":"full"});body=POST 请求体 JSON;不传 path 则列出全部可用接口。写类接口(settings-set / repo-push 等)内部调用按本机同源放行。',
235
+ 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 等)内部调用按本机同源放行。',
212
236
  params: [
213
- { flag: 'path', type: 'string', positional: 0, desc: '接口名(缺省 = 列出全部接口)' },
237
+ { flag: 'path', type: 'string', positional: 0, desc: '接口名(缺省 = 列出全部接口);预处理接口推荐 preprocess/<接口> 前缀相对写法,也接受 /api/preprocess/… 全路径' },
214
238
  { flag: 'method', type: 'string', desc: 'HTTP 方法(默认 GET;写操作传 POST)' },
215
239
  { flag: 'query', type: 'string', desc: '查询参数 JSON 字符串,如 {"mode":"full"}' },
216
240
  { flag: 'body', type: 'string', desc: 'POST 请求体 JSON 字符串' },
217
241
  ],
218
242
  },
219
243
  {
220
- name: 'scope_check', cli: 'scope-check', description: '检查 JS 拼接产物的作用域撞名(多段 JS 拼进同一作用域时,同帧内 var/function 同名会让后者静默顶掉前者、运行时毫无报错线索)。判定按真实作用域帧——两个不同函数里的同名局部变量不算撞名。默认只查「同一函数帧内重名」(通用,任何项目可用);被查项目在 package.json 的 dshScopeCheck 声明了 files/prefix/allowlist/topLevelMustBeEmpty 时,按**项目自己的契约**追加查「顶层零声明 + 共享作用域命名前缀」,没声明就不查前缀(不拿本项目的 dshgp_ 要求别人)。files 缺省取项目 dshScopeCheck.files',
244
+ name: 'scope_check', description: '检查 JS 拼接产物的作用域撞名(多段 JS 拼进同一作用域时,同帧内 var/function 同名会让后者静默顶掉前者、运行时毫无报错线索)。判定按真实作用域帧——两个不同函数里的同名局部变量不算撞名。默认只查「同一函数帧内重名」(通用,任何项目可用);被查项目在 package.json 的 dshScopeCheck 声明了 files/prefix/allowlist/topLevelMustBeEmpty 时,按**项目自己的契约**追加查「顶层零声明 + 共享作用域命名前缀」,没声明就不查前缀(不拿本项目的 dshgp_ 要求别人)。files 缺省取项目 dshScopeCheck.files',
221
245
  params: [
222
246
  { flag: 'files', type: 'string', positional: 0, desc: '目标文件(逗号分隔;缺省读项目 package.json 的 dshScopeCheck.files)' },
223
247
  { flag: 'repo', type: 'string', desc: '仓库根(缺省当前工作目录)' },
@@ -1,21 +1,20 @@
1
1
  /**
2
- * HTTP 处理层 · 元信息/只读端点(status/scan/browse/tools/tool-probes/rule-slots/rule-detail/audit/toggle-rule)
2
+ * HTTP 处理层 · git/共享元信息与只读端点(status/scan/browse/tools/tool-probes)
3
+ *
4
+ * 预处理侧(rule-slots / rule-detail / audit / toggle-rule / exempt-hint)已搬到 handlers/preprocess.js,
5
+ * 走 /api/preprocess 前缀——本文件不再 import 任何预处理实现。
3
6
  *
4
7
  * 从 http-handlers.js 的 handleHttp 巨型 switch 拆分而来。
5
8
  * 统一签名:handleXxx(ctx) → { status, body };ctx = { req, query, body, env, cfg, path, method }。
6
9
  */
7
10
  import { VERSION } from '../../self/index.js';
8
11
  import { scanRepos, browseDir } from '../../git/index.js';
9
- import { getDefaultScanRoot } from '../scan-root.js';
10
12
  import { collectToolPaths } from '../../context/index.js';
11
13
  import { redactConfig } from '../schema.js';
12
- import { getLastSlotHitStats } from '../slot-stats.js';
13
14
  import { listTools } from '../tools.js';
14
- import { discoverRuleSlots, loadYamlRuleFile, resolveSlotOrder, setSlotDisabled, RULE_YAML_DIR } from '../../rule/loader.js';
15
15
  import { name } from '../constants.js';
16
16
  import { readAccountStatus } from '../../git/account-status.js';
17
17
  import { identityHintText, resolveCommitIdentity } from '../../git/identity.js';
18
- import { exemptHintForFinding, exemptMarkerCovers, EXEMPT_MARKERS } from '../../exempt/index.js';
19
18
 
20
19
  /**
21
20
  * 当前提交身份(未配身份的仓库会用到的那个):登录账号可用 → 账号身份;
@@ -68,146 +67,12 @@ export function handleBrowse(ctx) {
68
67
  }
69
68
 
70
69
  /** GET /api/git-push/tools —— 插件自身工具定义清单(agent 工具)。 */
71
- export function handleTools() {
72
- return { status: 200, body: { ok: true, tools: listTools() } };
70
+ export function handleTools(ctx = {}) {
71
+ // 传 cfg:函数形态的 params 按当前配置求值(未启用的预处理参数不出现在清单里)
72
+ return { status: 200, body: { ok: true, tools: listTools(ctx.cfg) } };
73
73
  }
74
74
 
75
75
  /** GET /api/git-push/tool-probes —— 本机各工具实测路径/版本(真实探测)。 */
76
76
  export function handleToolProbes() {
77
77
  return { status: 200, body: { ok: true, probes: collectToolPaths(null) } };
78
78
  }
79
-
80
- /**
81
- * 由规则包 yml 解析结果算该槽位的规则条数统计。
82
- *
83
- * 为什么单独成函数:这段(rules 过滤 + private_files 计数 + pass 推导)原先内联在
84
- * listRuleSlots 的循环里,与「槽位元数据组装」混在一起,把该函数圈复杂度推到 15
85
- * (阈值 10,自审 max-cyclomatic-complexity)——拆开后统计口径可单独阅读与复用。
86
- * 清单驱动槽位(private)用 private_files 条目数计(它们不在 rules 数组里)。
87
- */
88
- function ruleSlotStats(r) {
89
- const rules = Array.isArray(r.data.rules) ? r.data.rules : [];
90
- const listed = Array.isArray(r.data.private_files) ? r.data.private_files.length : 0;
91
- const total = rules.length + listed;
92
- const blocker = rules.filter((x) => x && (x.severity === 'blocker' || x.severity === 'error')).length + listed;
93
- const warning = rules.filter((x) => x && x.severity === 'warning').length;
94
- return { blocker, warning, pass: Math.max(0, total - blocker - warning), total, source: 'rules' };
95
- }
96
-
97
- /** 规则包清单(按规则条数统计;hitStats 参数保留兼容但不再参与计算)。 */
98
- export function listRuleSlots(order, disabledSlots = [], hitStats = null) {
99
- const discovered = discoverRuleSlots(RULE_YAML_DIR);
100
- const slotMeta = {};
101
- for (const slot of discovered) {
102
- const r = loadYamlRuleFile(slot, RULE_YAML_DIR);
103
- if (r.ok && r.data?.metadata) {
104
- slotMeta[slot] = {
105
- name: r.data.metadata.name || slot,
106
- description: r.data.metadata.description || '',
107
- author: r.data.metadata.author || '',
108
- stats: ruleSlotStats(r),
109
- disabled: r.data.disabled === true || disabledSlots.includes(slot),
110
- };
111
- } else {
112
- slotMeta[slot] = { name: slot, description: '', author: '', stats: { blocker: 0, warning: 0, pass: 0, total: 0, source: 'rules' }, disabled: disabledSlots.includes(slot) };
113
- }
114
- }
115
- const eff = resolveSlotOrder(order && order.length ? order : undefined, { dir: RULE_YAML_DIR });
116
- return { discovered, order: eff, meta: slotMeta, forced: ['private'] };
117
- }
118
-
119
- /** GET /api/git-push/rule-slots —— 规则包按包规则条数统计。 */
120
- export function handleRuleSlots(ctx) {
121
- const { cfg } = ctx;
122
- return { status: 200, body: { ok: true, slots: listRuleSlots(cfg.auditRuleOrder, Array.isArray(cfg.auditDisabledSlots) ? cfg.auditDisabledSlots : [], getLastSlotHitStats()) } };
123
- }
124
-
125
- /** GET /api/git-push/rule-detail —— 单个规则包的规则明细 + severity 统计。 */
126
- export function handleRuleDetail(ctx) {
127
- const { query } = ctx;
128
- const slot = String(query.slot || '');
129
- if (!slot) return { status: 400, body: { ok: false, code: 'SLOT_REQUIRED', error: '缺少规则包名 slot' } };
130
- const r = loadYamlRuleFile(slot, RULE_YAML_DIR);
131
- if (!r.ok) return { status: 404, body: { ok: false, code: 'SLOT_NOT_FOUND', error: r.error } };
132
- const rules = Array.isArray(r.data?.rules) ? r.data.rules : [];
133
- const detail = rules.map((rule) => ({
134
- id: rule.id || '',
135
- name: rule.name || rule.id || '',
136
- category: rule.category || '',
137
- severity: rule.severity || 'notice',
138
- description: rule.description || '',
139
- author: rule.author || r.data.metadata?.author || '',
140
- }));
141
- const count = (sev) => detail.filter((x) => x.severity === sev).length;
142
- const stats = {
143
- blocker: count('blocker') + count('error'),
144
- warning: count('warning'),
145
- pass: rules.length - count('blocker') - count('error') - count('warning'),
146
- total: rules.length,
147
- };
148
- return { status: 200, body: { ok: true, slot, meta: { name: r.data?.metadata?.name || slot, description: r.data?.metadata?.description || '', author: r.data?.metadata?.author || '' }, stats, rules: detail } };
149
- }
150
-
151
- /** POST/GET /api/git-push/audit —— 审计结果 API(请求时聚合)。 */
152
- export async function handleAudit(ctx) {
153
- const { query, body, env, cfg } = ctx;
154
- const { runAuditApi } = await import('../audit-api.js');
155
- const params = { ...query, ...body };
156
- const repo = String(params.repo || '').trim()
157
- || getDefaultScanRoot(env, { defaultScanRoot: String(cfg.defaultScanRoot || '') });
158
- if (!repo) return { status: 400, body: { ok: false, code: 'REPO_REQUIRED', error: '缺 repo 参数且无法推断默认扫描根' } };
159
- try {
160
- const r = await runAuditApi(repo, params, cfg);
161
- return { status: 200, body: r };
162
- } catch (e) {
163
- return { status: 500, body: { ok: false, code: 'AUDIT_FAIL', error: `审计失败: ${e?.message || e}` } };
164
- }
165
- }
166
-
167
- /** POST /api/git-push/toggle-rule —— 启用/禁用规则包(改 yml disabled)。 */
168
- export function handleToggleRule(ctx) {
169
- const { body } = ctx;
170
- const slot = String(body.slot || '');
171
- const want = body.disabled === true;
172
- if (!slot) return { status: 400, body: { ok: false, code: 'SLOT_REQUIRED', error: '缺少规则包名 slot' } };
173
- const r = setSlotDisabled(slot, want);
174
- if (!r.ok) return { status: 400, body: { ok: false, code: 'SLOT_TOGGLE_FAIL', error: r.error || '切换失败' } };
175
- return { status: 200, body: { ok: true, slot, disabled: r.disabled, message: want ? '已禁用' : '已启用' } };
176
- }
177
-
178
- /**
179
- * GET /api/git-push/exempt-hint —— 豁免标记查询(只读)。
180
- *
181
- * 入参 query:rule(规则名,如 maintainability/max-complexity)、kind(可选 finding kind)。
182
- * 出参:{ ok, rule, kind, marker, hint, lineLevel, candidates }。
183
- *
184
- * 为什么要有这个端点:豁免标记注册表(EXEMPT_MARKERS)是**单一真源**,外部工具(如
185
- * dsh-useful-tools 的 exempt 工具)需要「该写哪个标记」时来查,而不是复制一份注册表
186
- * ——复制必然漂移(历史上「提示与实际行为不符」的 24 种组合就是这么来的)。
187
- */
188
- export function handleExemptHint(ctx) {
189
- const rule = String(ctx.query?.rule || '').trim();
190
- const kind = String(ctx.query?.kind || '').trim();
191
- const finding = { rule, kind };
192
- const hit = exemptHintForFinding(finding);
193
- const meta = hit ? EXEMPT_MARKERS[hit.marker] : null;
194
- const candidates = Object.entries(EXEMPT_MARKERS).map(([marker, m]) => ({
195
- marker,
196
- lineLevel: m.lineLevel === true,
197
- dimensions: m.dimensions || [],
198
- hint: m.hint || '',
199
- covers: Boolean(rule || kind) && exemptMarkerCovers(marker, finding),
200
- }));
201
- return {
202
- status: 200,
203
- body: {
204
- ok: true,
205
- rule,
206
- kind,
207
- marker: hit ? hit.marker : null,
208
- hint: hit ? hit.hint : '无任何标记可豁免该 finding(应改代码,或走 .auditignore / 豁免槽位)',
209
- lineLevel: meta ? meta.lineLevel === true : false,
210
- candidates,
211
- },
212
- };
213
- }
@@ -10,7 +10,7 @@ import { join } from 'node:path';
10
10
  import { readNpmToken, maskToken } from '../../core/credentials.js';
11
11
  import { normalizeRegistry, whoami, listOwnedPackages } from '../../npm/registry.js';
12
12
  import { npmArgs, writeNpmrc } from '../../npm/npmrc.js';
13
- import { installPackages, startInstall, validateDest } from '../../npm/install.js';
13
+ import { installPackages, startInstall, installProgress, validateDest } from '../../npm/install.js';
14
14
  import { publishPackage } from '../../npm/publish.js';
15
15
  import { readNpmAccountStatus, writeNpmAccountStatus, buildNpmAccountStatus, renderNpmAccountBlock } from '../../npm/account.js';
16
16
 
@@ -149,6 +149,23 @@ export function handleNpmInstall(ctx) {
149
149
  * `/npm-publish`:发包。**默认 dry-run**(只体检 + `npm publish --dry-run`,不写 registry ✗);
150
150
  * 真发必须同时 `confirm:true` **且** `dryRun:false`(双闸门,防误发不可撤销)。
151
151
  */
152
+ /**
153
+ * 异步安装进度(对应 GitHub 克隆的 `/clone-progress`)。
154
+ *
155
+ * 为什么补这条:前端 `controller.js` 的 `pollInstallProgress()` 一直在 POST 这个路径轮询,
156
+ * 但路由 switch 里从来没有这个 case ⇒ 每次轮询 404,进度框永远拿不到进度(既有 bug)。
157
+ * 实现(`installProgress`)本来就在 `lib/npm/install.js`,只是路由漏了。
158
+ *
159
+ * 返回结构与前端消费对齐:`installProgress()` 返回 `{ ok, progress }`(运行中/终态)
160
+ * 或 `{ ok, state: 'idle' }`(无任务)——前端读 `st.progress`,无 progress 就直接 return,安全。
161
+ */
162
+ export function handleNpmInstallProgress(ctx) {
163
+ const { body = {}, query = {} } = ctx;
164
+ const consume = body.consume === true || body.consume === 'true'
165
+ || query.consume === '1' || query.consume === 'true';
166
+ return { status: 200, body: installProgress({ consume }) };
167
+ }
168
+
152
169
  export async function handleNpmPublish(ctx) {
153
170
  const { env, cfg, body } = ctx;
154
171
  const dryRun = body?.dryRun !== false;
@@ -0,0 +1,107 @@
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
+ const { cfg } = ctx;
38
+ return withHostApi(async (api) => ({
39
+ status: 200,
40
+ body: {
41
+ ok: true,
42
+ slots: api.listRuleSlots(
43
+ cfg.auditRuleOrder,
44
+ Array.isArray(cfg.auditDisabledSlots) ? cfg.auditDisabledSlots : [],
45
+ api.getLastSlotHitStats(),
46
+ ),
47
+ },
48
+ }));
49
+ }
50
+
51
+ /** GET /api/preprocess/rule-detail */
52
+ export async function handleRuleDetail(ctx) {
53
+ const slot = String(ctx.query.slot || '');
54
+ if (!slot) return { status: 400, body: { ok: false, error: 'slot 必填(规则包名,如 nodejs)' } };
55
+ return withHostApi(async (api) => {
56
+ const detail = api.ruleDetail(slot);
57
+ if (!detail) return { status: 404, body: { ok: false, error: `规则包不存在:${slot}` } };
58
+ return { status: 200, body: { ok: true, slot, ...detail } };
59
+ });
60
+ }
61
+
62
+ /** GET|POST /api/preprocess/audit(请求时聚合,不落盘) */
63
+ export async function handleAudit(ctx) {
64
+ const { query, body, env, method } = ctx;
65
+ const params = method === 'POST' ? { ...query, ...(body || {}) } : query;
66
+ const repo = String(params.repo || getDefaultScanRoot(env, { defaultScanRoot: '' }));
67
+ if (!repo) return { status: 400, body: { ok: false, error: 'repo 必填(仓库绝对路径)' } };
68
+ return withHostApi(async (api) => {
69
+ const result = await api.auditAggregate({
70
+ repo,
71
+ scope: params.scope === 'diff' ? 'diff' : 'full',
72
+ groupBy: String(params.groupBy || 'rule'),
73
+ severity: String(params.severity || ''),
74
+ top: Number(params.top) || 20,
75
+ });
76
+ if (result?.ok === false) return { status: 400, body: { ok: false, error: result.error } };
77
+ return { status: 200, body: result };
78
+ });
79
+ }
80
+
81
+ /** POST /api/preprocess/toggle-rule */
82
+ export async function handleToggleRule(ctx) {
83
+ const slot = String(ctx.body?.slot || '');
84
+ if (!slot) return { status: 400, body: { ok: false, error: 'slot 必填' } };
85
+ return withHostApi(async (api) => ({
86
+ status: 200,
87
+ body: { ok: true, slot, disabled: api.toggleRule(slot, ctx.body?.disabled === true) },
88
+ }));
89
+ }
90
+
91
+ /** GET /api/preprocess/exempt-hint */
92
+ export async function handleExemptHint(ctx) {
93
+ const { query } = ctx;
94
+ const finding = { rule: String(query.rule || ''), kind: String(query.kind || ''), file: String(query.file || ''), line: Number(query.line) || 0 };
95
+ if (!finding.rule && !finding.kind) return { status: 400, body: { ok: false, error: 'rule 或 kind 必填(用于推导豁免标记)' } };
96
+ return withHostApi(async (api) => ({
97
+ status: 200,
98
+ body: {
99
+ ok: true,
100
+ rule: finding.rule,
101
+ kind: finding.kind,
102
+ marker: (api.exemptHintForFinding(finding) || {}).marker || null,
103
+ hint: (api.exemptHintForFinding(finding) || {}).hint || '无任何标记可豁免该 finding(应改代码,或走 .auditignore / 豁免槽位)',
104
+ candidates: Object.keys(api.EXEMPT_MARKERS).map((marker) => ({ marker, covers: api.exemptMarkerCovers(marker, finding) })),
105
+ },
106
+ }));
107
+ }
@@ -8,7 +8,7 @@ import { join } from 'node:path';
8
8
  import { pushCurrentBranch, resolveToken, githubFetch, setVisibility, refreshAccountStatus, detectRepoVisibility, runGit, parseGithubOwnerRepo } from '../../git/index.js';
9
9
  import { updateRepoIndex } from '../../git/repo-index.js';
10
10
  import { commitWithAudit } from '../../commit-push.js';
11
- import { isBlockerFinding } from '../../audit/index.js';
11
+ import { isBlockerSeverity } from '../severity.js';
12
12
 
13
13
  /* ───────── 仓库动作常量 ───────── */
14
14
  const COMMIT_SHA_MAX_LEN = 40; // commit sha 展示截断长度
@@ -112,7 +112,7 @@ export async function handleRepoCommit(ctx) {
112
112
  if (!r.ok) {
113
113
  const findings = r.audit?.findings || [];
114
114
  // 统一口径:error 也属拦截级(与 summarize 一致,此前只筛 'blocker' ⇒ 枚举少于 summary)
115
- const blockers = findings.filter(isBlockerFinding).slice(0, 3)
115
+ const blockers = findings.filter(isBlockerSeverity).slice(0, 3)
116
116
  .map((f) => `${f.file}:${f.line} ${f.rule}`);
117
117
  return {
118
118
  status: 200,