dsh-git-push 2.20.19 → 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.
- package/README.md +3 -2
- package/cli-tool.mjs +2 -4
- package/cli.mjs +7 -1
- package/lib/app/apply.js +4 -4
- package/lib/app/command-registry.js +22 -17
- package/lib/app/handlers/meta.js +2 -2
- package/lib/app/handlers/preprocess.js +107 -0
- package/lib/app/handlers/repo-actions.js +2 -2
- package/lib/app/http-handlers.js +13 -42
- package/lib/app/index.js +2 -1
- package/lib/app/inject-text.js +3 -3
- package/lib/app/preprocess-client.js +136 -0
- package/lib/app/repo-ownership.js +1 -1
- package/lib/app/schema.js +3 -3
- package/lib/app/severity.js +14 -0
- package/lib/app/slash-commands.js +5 -164
- package/lib/app/tool-call.js +73 -144
- package/lib/cli/commands-preprocess.mjs +74 -0
- package/lib/cli/commands-tool.mjs +3 -2
- package/lib/cli/commands-vcs.mjs +4 -4
- package/lib/cli/shared.mjs +35 -9
- package/lib/commit-push/pre-commit-engine.js +57 -10
- package/lib/commit-push.js +71 -27
- package/lib/{exempt/index.js → git/exempt-markers.js} +8 -1
- package/lib/git/ignore.js +1 -1
- package/lib/git/repos.js +2 -2
- package/lib/git/sensitive.js +1 -1
- package/lib/npm/publish.js +20 -5
- package/lib/plugin/auto-push.js +2 -2
- package/lib/preprocess/providers.js +191 -0
- package/lib/self/index.js +1 -1
- package/lib/skip-dirs.js +14 -55
- package/package.json +29 -37
- package/scripts/build-client.mjs +2 -0
- package/scripts/check.mjs +4 -2
- package/scripts/local-registry.mjs +2 -1
- package/cli-audit.mjs +0 -141
- package/lib/app/audit-api.js +0 -173
- package/lib/app/handlers/audit.js +0 -150
- package/lib/app/host-doc-checks.js +0 -25
- package/lib/app/scope-check.js +0 -69
- package/lib/ast/brace.js +0 -120
- package/lib/ast/callgraph.js +0 -135
- package/lib/ast/code-lines.js +0 -175
- package/lib/ast/consts.js +0 -12
- package/lib/ast/control-flow.js +0 -470
- package/lib/ast/credential.js +0 -315
- package/lib/ast/dataflow.js +0 -391
- package/lib/ast/dup-code.js +0 -165
- package/lib/ast/fs-hotspots.js +0 -154
- package/lib/ast/index.js +0 -38
- package/lib/ast/io-risk-const.js +0 -95
- package/lib/ast/io-risk-fn.js +0 -208
- package/lib/ast/io-risk-loop.js +0 -308
- package/lib/ast/io-risk.js +0 -314
- package/lib/ast/lang.js +0 -156
- package/lib/ast/line-count.js +0 -52
- package/lib/ast/magic-number.js +0 -272
- package/lib/ast/naming.js +0 -292
- package/lib/ast/perf.js +0 -488
- package/lib/ast/scope-collisions.js +0 -228
- package/lib/ast/scope.js +0 -241
- package/lib/ast/shell.js +0 -131
- package/lib/ast/size.js +0 -448
- package/lib/ast/symbol-index.js +0 -399
- package/lib/ast/tokenizer.js +0 -421
- package/lib/ast/treesitter.js +0 -413
- package/lib/audit/analysis-coverage.js +0 -98
- package/lib/audit/audit-file.js +0 -205
- package/lib/audit/auditignore-rules.js +0 -148
- package/lib/audit/checks.js +0 -17
- package/lib/audit/client-entry.js +0 -93
- package/lib/audit/collector.js +0 -610
- package/lib/audit/ext-runner.js +0 -80
- package/lib/audit/file-context.js +0 -391
- package/lib/audit/finding.js +0 -101
- package/lib/audit/gitignore-match.js +0 -113
- package/lib/audit/glob.js +0 -63
- package/lib/audit/history-report.js +0 -100
- package/lib/audit/history.js +0 -126
- package/lib/audit/ignore-blind.js +0 -102
- package/lib/audit/index.js +0 -33
- package/lib/audit/orchestrate.js +0 -672
- package/lib/audit/public.js +0 -24
- package/lib/audit/repo-level.js +0 -30
- package/lib/audit/report-yaml.js +0 -90
- package/lib/audit/scope-policy.js +0 -110
- package/lib/audit/slot.js +0 -66
- package/lib/audit-rules/audit-rules-comment.yml +0 -199
- package/lib/audit-rules/audit-rules-cpp.yml +0 -114
- package/lib/audit-rules/audit-rules-csharp.yml +0 -82
- package/lib/audit-rules/audit-rules-docs.yml +0 -32
- package/lib/audit-rules/audit-rules-dsh.yml +0 -177
- package/lib/audit-rules/audit-rules-filehealth.yml +0 -42
- package/lib/audit-rules/audit-rules-folder.yml +0 -99
- package/lib/audit-rules/audit-rules-frontend.yml +0 -335
- package/lib/audit-rules/audit-rules-go.yml +0 -103
- package/lib/audit-rules/audit-rules-i18n.yml +0 -45
- package/lib/audit-rules/audit-rules-java.yml +0 -105
- package/lib/audit-rules/audit-rules-nodejs.yml +0 -662
- package/lib/audit-rules/audit-rules-npm.yml +0 -187
- package/lib/audit-rules/audit-rules-paths.yml +0 -98
- package/lib/audit-rules/audit-rules-performance.yml +0 -245
- package/lib/audit-rules/audit-rules-php.yml +0 -101
- package/lib/audit-rules/audit-rules-private.yml +0 -24
- package/lib/audit-rules/audit-rules-python.yml +0 -106
- package/lib/audit-rules/audit-rules-robustness.yml +0 -31
- package/lib/audit-rules/audit-rules-rust.yml +0 -109
- package/lib/audit-rules/audit-rules-structure.yml +0 -158
- package/lib/audit-rules/audit-rules-swift.yml +0 -99
- package/lib/audit-rules/audit-rules-template.yml +0 -108
- package/lib/audit-ui-sdk/contract.js +0 -117
- package/lib/audit-ui-sdk/index.js +0 -17
- package/lib/checks/button-bind.js +0 -347
- package/lib/checks/common.js +0 -170
- package/lib/checks/credential-file.js +0 -43
- package/lib/checks/dataflow.js +0 -40
- package/lib/checks/dispatch.js +0 -117
- package/lib/checks/dup-code.js +0 -69
- package/lib/checks/dup-const.js +0 -232
- package/lib/checks/file-health.js +0 -150
- package/lib/checks/filter.js +0 -137
- package/lib/checks/folder.js +0 -173
- package/lib/checks/fs-scanner.js +0 -57
- package/lib/checks/hardcoded-path.js +0 -98
- package/lib/checks/index.js +0 -49
- package/lib/checks/io.js +0 -66
- package/lib/checks/magic-number.js +0 -42
- package/lib/checks/npm-json.js +0 -273
- package/lib/checks/private.js +0 -64
- package/lib/checks/regex.js +0 -298
- package/lib/checks/scope-collision.js +0 -68
- package/lib/checks/semantic.js +0 -134
- package/lib/checks/structural.js +0 -281
- package/lib/cli/commands-audit.mjs +0 -142
- package/lib/cli/commands-doc.mjs +0 -127
- package/lib/client-parts/audit/audit.js +0 -301
- package/lib/exempt/tool.js +0 -198
- package/lib/git/module-splitter.js +0 -47
- package/lib/link-check/index.js +0 -187
- package/lib/lint-adapter/detect.js +0 -161
- package/lib/lint-adapter/index.js +0 -50
- package/lib/lint-adapter/runner.js +0 -133
- package/lib/preprocess/audit.js +0 -98
- package/lib/preprocess/index.js +0 -78
- package/lib/rule/compilers/credential.js +0 -62
- package/lib/rule/compilers/dataflow.js +0 -38
- package/lib/rule/compilers/file-health.js +0 -75
- package/lib/rule/compilers/frontend.js +0 -86
- package/lib/rule/compilers/func.js +0 -35
- package/lib/rule/compilers/helpers.js +0 -71
- package/lib/rule/compilers/index.js +0 -29
- package/lib/rule/compilers/link-semantic.js +0 -45
- package/lib/rule/compilers/list-kinds.js +0 -12
- package/lib/rule/compilers/numeric-kinds.js +0 -73
- package/lib/rule/compilers/regex.js +0 -78
- package/lib/rule/compilers/structure.js +0 -107
- package/lib/rule/compilers.js +0 -17
- package/lib/rule/homoglyph.js +0 -45
- package/lib/rule/loader.js +0 -274
- package/lib/rule/registry.js +0 -122
- package/lib/rule/scope.js +0 -67
- package/lib/score/docs-score.js +0 -166
- package/lib/score/index.js +0 -234
- package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
- package/scripts/audit-ext/_example-readme-present.mjs +0 -34
- package/scripts/audit-ext/dsh-inject-declarations.mjs +0 -209
- package/scripts/audit-ext/variable-min-length.mjs +0 -102
- package/scripts/audit-gate.mjs +0 -235
- package/scripts/audit-runner.mjs +0 -35
- package/scripts/audit-runtime-check.mjs +0 -129
- package/scripts/browser-page-probe.mjs +0 -271
- package/scripts/check-js-scope.mjs +0 -87
- package/scripts/clean-date-comments.py +0 -102
- package/scripts/cpu-sample.mjs +0 -188
- package/scripts/doc-drift.mjs +0 -200
- package/scripts/hot-path-probe-cjs.cjs +0 -71
- package/scripts/hot-path-probe-fs-shim.mjs +0 -28
- package/scripts/hot-path-probe-fsp-shim.mjs +0 -31
- package/scripts/hot-path-probe.mjs +0 -153
- package/scripts/module-splitter.py +0 -800
- package/scripts/picker-repro.mjs +0 -115
- package/scripts/platform-scan.mjs +0 -168
- package/scripts/probe-recheck.mjs +0 -47
- package/scripts/rename-locator.mjs +0 -97
- package/scripts/rule-switch.mjs +0 -97
- package/scripts/rules-solo-audit.mjs +0 -173
- package/scripts/scan-file-io.mjs +0 -717
- package/scripts/scan-fs-hotspots.mjs +0 -107
- package/scripts/symbol-index.mjs +0 -85
- package/scripts/verify-prestep.mjs +0 -100
- package/skills/dev/audit-rule-authoring.md +0 -58
- package/skills/guide/guide-audit.md +0 -270
- /package/lib/{audit → app}/ownership.js +0 -0
- /package/lib/app/{schema-audit.js → schema-preprocess.js} +0 -0
- /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
|
|
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
|
|
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
|
-
|
|
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';
|
|
@@ -51,9 +52,13 @@ const HELP = `git-sluice v${VERSION} — ${CLI_ENTRIES[CLI_GIT].intro}
|
|
|
51
52
|
git-sluice commit <仓库> --message "msg" ③ 提交推送(自动过审计门禁)
|
|
52
53
|
git-sluice help 全部命令与参数
|
|
53
54
|
|
|
55
|
+
预处理(可插拔扩展:从所有在位 provider 的声明里找能力,审计只是其中之一):
|
|
56
|
+
git-sluice preprocess 列出当前可用的预处理动作
|
|
57
|
+
git-sluice preprocess <action> ... 转发到声明该动作的 provider(如 audit / io_scan / link_check)
|
|
58
|
+
|
|
54
59
|
其它 CLI(本入口不含,敲错会给出替代命令):
|
|
55
|
-
audit-sluice 审计/规则/静态检查: audit ruleset file-io link-check scope-check functions tree-doc
|
|
56
60
|
tool-sluice 工具链: module-splitter yaml-template readme-template self-check
|
|
61
|
+
注:审计 CLI 已随审计能力独立成包(audit-sluice),不再由本插件提供。
|
|
57
62
|
|
|
58
63
|
用法(每行写的参数就是该命令真实接受的写法,照抄即可):
|
|
59
64
|
git-sluice version 查看版本
|
|
@@ -128,6 +133,7 @@ export function renderHelp(cfg = {}, hasBuiltinEngine) {
|
|
|
128
133
|
}
|
|
129
134
|
|
|
130
135
|
export const COMMANDS = new Map([
|
|
136
|
+
['preprocess', cmdPreprocess],
|
|
131
137
|
['repos', parseVia((flags, positional) => cmdRepos(positional[0] || '.', flags))],
|
|
132
138
|
['index', parseVia((flags, positional) => cmdIndex(positional[0] || '.', flags))],
|
|
133
139
|
// `git` 必须走这里而不是注册表:注册表只认声明过的参数,会把 git 自己的 flag
|
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 {
|
|
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';
|
|
@@ -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
|
-
// **同一个 handler 注册两个前缀**:/api/git-push(git+共享)与 /api/
|
|
165
|
+
// **同一个 handler 注册两个前缀**:/api/git-push(git+共享)与 /api/preprocess(预处理,审计是其第一个 provider)。
|
|
166
166
|
// 为什么不另写一个 handler:鉴权(checkOrigin/checkBodySize/写确认)在 handleHttp 的
|
|
167
167
|
// switch 之前统一执行,复用同一入口才自动继承门禁;另起入口就是一个无门禁的裸端点。
|
|
168
168
|
const httpHandler = (req, res) => adaptHttpHandler(req, res, { ...env, jobs }, cfg);
|
|
169
169
|
const httpWired = registerHttp(ctx, { path: '/api/git-push', handler: httpHandler, log });
|
|
170
|
-
const
|
|
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-
|
|
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,6 +1,20 @@
|
|
|
1
1
|
// 审计预处理的「参数 / 可用性判据」真源在 lib/preprocess/audit.js(与 renderResult 同处一处);
|
|
2
2
|
// 本文件只消费它们,并按历史路径 re-export(外部 import { auditPreprocessAvailable } 不受影响)。
|
|
3
|
-
import {
|
|
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
|
|
|
@@ -136,7 +150,7 @@ export const TOOL_REGISTRY = [
|
|
|
136
150
|
],
|
|
137
151
|
},
|
|
138
152
|
{
|
|
139
|
-
name: 'io_scan',
|
|
153
|
+
name: 'io_scan', description: 'I/O 风险扫描(AST 四级分级 high/medium/low/safe——与审计 io-risk 同标准)。repo=目标(默认工作区)、writeOnly=只看写操作',
|
|
140
154
|
params: [
|
|
141
155
|
{ flag: 'repo', type: 'string', positional: 0, desc: '扫描目标(默认工作区)' },
|
|
142
156
|
{ flag: 'writeOnly', type: 'boolean', desc: '只看写操作' },
|
|
@@ -154,7 +168,7 @@ export const TOOL_REGISTRY = [
|
|
|
154
168
|
},
|
|
155
169
|
{
|
|
156
170
|
name: 'npm_publish', cli: 'npm-publish',
|
|
157
|
-
description: 'npm 发包(后台 job + dryRun
|
|
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',
|
|
158
172
|
params: [
|
|
159
173
|
{ flag: 'dir', type: 'string', positional: 0, desc: '目标包目录(缺省工作区)' },
|
|
160
174
|
{ flag: 'dryRun', type: 'boolean', desc: '只预演(默认 true,不写 registry)' },
|
|
@@ -165,7 +179,7 @@ export const TOOL_REGISTRY = [
|
|
|
165
179
|
{ flag: 'waitVisible', type: 'boolean', desc: '发布后等待 registry 可见(默认 false:上传成功即为成功,可见延迟是已知现象;true 时每分钟查一次、最多 5 分钟)' },
|
|
166
180
|
{ flag: 'json', type: 'boolean', desc: 'JSON 输出(CLI 用;与其它工具同口径)' },
|
|
167
181
|
{ flag: 'skipSmoke', type: 'boolean', desc: '跳过发布前冒烟(默认跑:pack→干净目录安装→import 公开面→解析依赖;关掉会失去“装得上”这层门禁)' },
|
|
168
|
-
{ flag: 'localPreview', type: 'boolean', desc: '本地 registry
|
|
182
|
+
{ flag: 'localPreview', type: 'boolean', desc: '本地 registry 彩排(默认关):起本机 registry,publish → install → 加载公开面全走它,**全程不碰公网**(连版本占用查询也不走公网)。分钟级,发版前建议开一次' },
|
|
169
183
|
],
|
|
170
184
|
},
|
|
171
185
|
{
|
|
@@ -176,7 +190,7 @@ export const TOOL_REGISTRY = [
|
|
|
176
190
|
],
|
|
177
191
|
},
|
|
178
192
|
{
|
|
179
|
-
name: 'link_check',
|
|
193
|
+
name: 'link_check', description: '检查文档链接有效性(md/txt 内 URL——只报 warning 不拦截提交)。path=文件或目录(默认工作区)',
|
|
180
194
|
params: [
|
|
181
195
|
{ flag: 'path', type: 'string', positional: 0, desc: '文件或目录(默认工作区)' },
|
|
182
196
|
],
|
|
@@ -193,15 +207,6 @@ export const TOOL_REGISTRY = [
|
|
|
193
207
|
{ flag: 'json', type: 'boolean', desc: 'JSON 输出(CLI:git-sluice identity-rewrite --json)' },
|
|
194
208
|
],
|
|
195
209
|
},
|
|
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
210
|
{
|
|
206
211
|
name: 'git_account_check', cli: 'account-check', description: '校验 GitHub 账号与凭据:token 在线校验 + SSH 公钥指纹——返回登录态/用户名/公钥数/套餐。token 不传自动解析;sshPub 非空顺带持久化',
|
|
207
212
|
params: [
|
|
@@ -227,16 +232,16 @@ export const TOOL_REGISTRY = [
|
|
|
227
232
|
],
|
|
228
233
|
},
|
|
229
234
|
{
|
|
230
|
-
name: 'git_api', cli: 'api', description: '直接调用本插件的 HTTP API(36 条接口,与浏览器/CLI 同源实现:内部走 handleHttp 同一条代码路径)。path=接口名:git/共享接口传短名(如 status / settings-get
|
|
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 等)内部调用按本机同源放行。',
|
|
231
236
|
params: [
|
|
232
|
-
{ flag: 'path', type: 'string', positional: 0, desc: '接口名(缺省 =
|
|
237
|
+
{ flag: 'path', type: 'string', positional: 0, desc: '接口名(缺省 = 列出全部接口);预处理接口推荐 preprocess/<接口> 前缀相对写法,也接受 /api/preprocess/… 全路径' },
|
|
233
238
|
{ flag: 'method', type: 'string', desc: 'HTTP 方法(默认 GET;写操作传 POST)' },
|
|
234
239
|
{ flag: 'query', type: 'string', desc: '查询参数 JSON 字符串,如 {"mode":"full"}' },
|
|
235
240
|
{ flag: 'body', type: 'string', desc: 'POST 请求体 JSON 字符串' },
|
|
236
241
|
],
|
|
237
242
|
},
|
|
238
243
|
{
|
|
239
|
-
name: 'scope_check',
|
|
244
|
+
name: 'scope_check', description: '检查 JS 拼接产物的作用域撞名(多段 JS 拼进同一作用域时,同帧内 var/function 同名会让后者静默顶掉前者、运行时毫无报错线索)。判定按真实作用域帧——两个不同函数里的同名局部变量不算撞名。默认只查「同一函数帧内重名」(通用,任何项目可用);被查项目在 package.json 的 dshScopeCheck 声明了 files/prefix/allowlist/topLevelMustBeEmpty 时,按**项目自己的契约**追加查「顶层零声明 + 共享作用域命名前缀」,没声明就不查前缀(不拿本项目的 dshgp_ 要求别人)。files 缺省取项目 dshScopeCheck.files',
|
|
240
245
|
params: [
|
|
241
246
|
{ flag: 'files', type: 'string', positional: 0, desc: '目标文件(逗号分隔;缺省读项目 package.json 的 dshScopeCheck.files)' },
|
|
242
247
|
{ flag: 'repo', type: 'string', desc: '仓库根(缺省当前工作目录)' },
|
package/lib/app/handlers/meta.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* HTTP 处理层 · git/共享元信息与只读端点(status/scan/browse/tools/tool-probes)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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,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 {
|
|
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(
|
|
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,
|
package/lib/app/http-handlers.js
CHANGED
|
@@ -11,10 +11,10 @@ import { defaultConfig } from '../client/index.js';
|
|
|
11
11
|
import {
|
|
12
12
|
handleStatus, handleScan, handleBrowse, handleTools, handleToolProbes,
|
|
13
13
|
} from './handlers/meta.js';
|
|
14
|
-
//
|
|
14
|
+
// 预处理 handler 已独立成文件(走 /api/preprocess 前缀):git 侧路由不再 import 预处理实现
|
|
15
15
|
import {
|
|
16
16
|
listRuleSlots, handleRuleSlots, handleRuleDetail, handleAudit, handleToggleRule, handleExemptHint,
|
|
17
|
-
} from './handlers/
|
|
17
|
+
} from './handlers/preprocess.js';
|
|
18
18
|
import {
|
|
19
19
|
handleReposLocal, handleReposLocalScan, handleReposLocalScanWait, handleReposLocalRefresh, handleReposCloud,
|
|
20
20
|
} from './handlers/repos.js';
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
import { handleNpmAccount, handleNpmCheck, handleNpmOwned, handleNpmPackages, handleNpmInstall, handleNpmPublish, handleNpmInstallProgress } from './handlers/npm.js';
|
|
37
37
|
import { appendHttpRejectLog } from './settings-bridge.js';
|
|
38
38
|
/** 规则槽位清单对外导出(实现迁至 handlers/meta.js)。 */
|
|
39
|
-
export { listRuleSlots } from './handlers/
|
|
39
|
+
export { listRuleSlots } from './handlers/preprocess.js';
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* HTTP 适配:DSH webServer 原生 (req, res) ↔ v2 纯函数 handleHttp({status, body})。
|
|
@@ -89,35 +89,10 @@ function buildCtx(req, method, env, cfg, query, body, path) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/** 审计侧 HTTP 前缀(与 git 侧 `/api/git-push` 物理分开;git 侧 25 条路径一个字未改)。 */
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
['/api/git-push/audit', `${AUDIT_API_PREFIX}/audit`],
|
|
97
|
-
['/api/git-push/rule-slots', `${AUDIT_API_PREFIX}/rule-slots`],
|
|
98
|
-
['/api/git-push/rule-detail', `${AUDIT_API_PREFIX}/rule-detail`],
|
|
99
|
-
['/api/git-push/toggle-rule', `${AUDIT_API_PREFIX}/toggle-rule`],
|
|
100
|
-
['/api/git-push/exempt-hint', `${AUDIT_API_PREFIX}/exempt-hint`],
|
|
101
|
-
]);
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 给「旧路径转发」的响应补上废弃标记。
|
|
105
|
-
* 为什么用响应头而不是错误:旧路径仍然**能用**(兼容一版),只是要在自动化能看见的地方留痕,
|
|
106
|
-
* 将来移除时才有人能拿出「谁还在调」的证据。`Link: rel="successor-version"` 是 RFC 5829 的标准写法。
|
|
107
|
-
* @param {object} result handler 返回值 { status, body, headers? }
|
|
108
|
-
* @param {string} successorPath 新路径
|
|
109
|
-
* @returns {object}
|
|
110
|
-
*/
|
|
111
|
-
function withDeprecation(result, successorPath) {
|
|
112
|
-
return {
|
|
113
|
-
...result,
|
|
114
|
-
headers: {
|
|
115
|
-
...(result?.headers || {}),
|
|
116
|
-
Deprecation: 'true',
|
|
117
|
-
Link: `<${successorPath}>; rel="successor-version"`,
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
}
|
|
92
|
+
// 通用预处理前缀(审计只是第一个 provider)。
|
|
93
|
+
// 路由形如 /api/preprocess/<action>,action 来自各 provider 的 manifest 声明;
|
|
94
|
+
// 宿主不写死具体实现名,新增 provider 不需要改这里。
|
|
95
|
+
export const PREPROCESS_API_PREFIX = '/api/preprocess';
|
|
121
96
|
|
|
122
97
|
/**
|
|
123
98
|
* HTTP 端点分发(鉴权前置:Origin/CSRF → 413 → 写确认 → switch 路由)。
|
|
@@ -179,18 +154,14 @@ export async function handleHttp(req = {}, env = {}, cfg = defaultConfig()) {
|
|
|
179
154
|
case '/api/git-push/tools': return handleTools(ctx);
|
|
180
155
|
case '/api/git-push/tool-probes': return handleToolProbes(ctx);
|
|
181
156
|
// ── 审计侧(新前缀):规则包 / 审计结果聚合 / 规则启停 / 豁免提示 ──
|
|
182
|
-
case '/api/
|
|
183
|
-
case '/api/
|
|
184
|
-
case '/api/
|
|
185
|
-
case '/api/
|
|
157
|
+
case '/api/preprocess/rule-slots': return handleRuleSlots(ctx);
|
|
158
|
+
case '/api/preprocess/rule-detail': return handleRuleDetail(ctx);
|
|
159
|
+
case '/api/preprocess/audit': return await handleAudit(ctx);
|
|
160
|
+
case '/api/preprocess/toggle-rule': return handleToggleRule(ctx);
|
|
186
161
|
// 豁免标记查询(只读):供外部工具推导「该写哪个 dsh-skip-*」,避免复制标记注册表
|
|
187
|
-
case '/api/
|
|
162
|
+
case '/api/preprocess/exempt-hint': return handleExemptHint(ctx);
|
|
188
163
|
// ── 旧前缀(兼容一版):转发到同一 handler + Deprecation 头 ──
|
|
189
|
-
|
|
190
|
-
case '/api/git-push/rule-detail': return withDeprecation(handleRuleDetail(ctx), `${AUDIT_API_PREFIX}/rule-detail`);
|
|
191
|
-
case '/api/git-push/audit': return withDeprecation(await handleAudit(ctx), `${AUDIT_API_PREFIX}/audit`);
|
|
192
|
-
case '/api/git-push/toggle-rule': return withDeprecation(handleToggleRule(ctx), `${AUDIT_API_PREFIX}/toggle-rule`);
|
|
193
|
-
case '/api/git-push/exempt-hint': return withDeprecation(handleExemptHint(ctx), `${AUDIT_API_PREFIX}/exempt-hint`);
|
|
164
|
+
// 历史调用方(脚本/文档/AI 记忆里的旧地址)不该因为改前缀就 404。
|
|
194
165
|
case '/api/git-push/account-status': return handleAccountStatus(ctx);
|
|
195
166
|
case '/api/git-push/npm-account': return await handleNpmAccount(ctx);
|
|
196
167
|
case '/api/git-push/npm-check': return await handleNpmCheck(ctx);
|
package/lib/app/index.js
CHANGED
|
@@ -24,7 +24,8 @@ export { README_CHECK_HINT, buildRequirementsInjectionText, formatAuditBlock } f
|
|
|
24
24
|
export { callTool } from './tool-call.js';
|
|
25
25
|
export { adaptHttpHandler, listRuleSlots, handleHttp } from './http-handlers.js';
|
|
26
26
|
export { apply } from './apply.js';
|
|
27
|
-
|
|
27
|
+
// 审计斜杠命令(/git-audit /git-io-scan /link-check)随审计能力迁出宿主,只剩 git 侧命令
|
|
28
|
+
export { sessionCwdOf, findGitRoot, registerSlashCommands } from './slash-commands.js';
|
|
28
29
|
|
|
29
30
|
import { routeRequest, readJsonBody } from '../http/index.js';
|
|
30
31
|
export { routeRequest, readJsonBody };
|
package/lib/app/inject-text.js
CHANGED
|
@@ -106,7 +106,7 @@ export function buildRequirementsInjectionText() {
|
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* 审计输出公共函数:只输出「级别数量 + 评分 + API 查询用法」——
|
|
109
|
-
* 审计结果改由聚合 API 查询(/api/
|
|
109
|
+
* 审计结果改由聚合 API 查询(/api/preprocess/audit —— 通用预处理前缀),不再内联输出审计内容。
|
|
110
110
|
* code_audit 工具 / git_commit_push 提交后统一调用,避免各处输出漂移。
|
|
111
111
|
* @param {string} repo 仓库路径
|
|
112
112
|
* @param {object} [opts] { scope?: 'full'|'diff', summary?, quality? }
|
|
@@ -139,8 +139,8 @@ export function buildAuditApiGuide(repo = '', opts = {}) {
|
|
|
139
139
|
const scope = (opts.scope || 'full') === 'full' ? 'full' : 'diff';
|
|
140
140
|
// 参数自动填充:repo 实际路径(encode)、scope 实际值、groupBy 默认 rule、severity 默认全级别
|
|
141
141
|
const qs = `repo=${encodeURIComponent(repo || '')}&scope=${scope}&groupBy=${opts.groupBy || 'rule'}`;
|
|
142
|
-
//
|
|
143
|
-
const base = `http://${detectHostIp()}:30800/api/
|
|
142
|
+
// 预处理侧走通用前缀(/api/preprocess):这里的 URL 是给用户/AI 直接复制去 curl 的,必须同步
|
|
143
|
+
const base = `http://${detectHostIp()}:30800/api/preprocess/audit`;
|
|
144
144
|
const L = [];
|
|
145
145
|
L.push(`审计:${repo || ''}(${scope === 'full' ? '全量' : '变动'})`);
|
|
146
146
|
L.push(`评分 ${quality.score ?? '?'}/${quality.level ?? '?'} · ${s.blocker ?? 0} 拦截 / ${s.warning ?? 0} 警告 / ${s.notice ?? 0} 提示`);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 预处理实现客户端(宿主侧唯一入口)
|
|
3
|
+
*
|
|
4
|
+
* 拆包后审计实现住在 `audit-sluice`,宿主**不再自己实现**判定,只负责:解析包位置 →
|
|
5
|
+
* 调它的公开面 → 把结果转给 AI/前端。本文件就是那个「调」的位置:
|
|
6
|
+
* · 包位置解析复用 pre-commit-engine 的同一套规则(env → node_modules → 平级目录),
|
|
7
|
+
* 保证「工具调用」与「提交门禁」永远指向**同一个**包(否则两处行为会分叉);
|
|
8
|
+
* · 用**动态 import**(不是子进程):工具调用要返回结构化对象,进程内调用省掉序列化与启动开销,
|
|
9
|
+
* 且包的公开面(`lib/index.js`)本来就是给 library 形态准备的。
|
|
10
|
+
*
|
|
11
|
+
* 为什么集中在一个文件:宿主里有 5 个工具 + 若干 handler 要用审计能力,
|
|
12
|
+
* 各自 `import(...)` 会让「包路径怎么找」散成 N 处(一处改了漏另一处 ⇒ 有的工具悄悄用旧实现)。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { existsSync } from 'node:fs';
|
|
16
|
+
import { dirname, join, resolve } from 'node:path';
|
|
17
|
+
import { pathToFileURL } from 'node:url';
|
|
18
|
+
|
|
19
|
+
import { resolveGateProvider } from '../commit-push/pre-commit-engine.js';
|
|
20
|
+
|
|
21
|
+
/** 已加载的包模块(进程内单例:包是纯函数集合,重复加载只浪费内存)。 */
|
|
22
|
+
let cachedModule = null;
|
|
23
|
+
let cachedHostApi = null;
|
|
24
|
+
let cachedRoot = '';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 解析预处理实现根目录(CLI 入口所在目录)。
|
|
28
|
+
* @returns {{ok: true, root: string, source: string} | {ok: false, error: string}}
|
|
29
|
+
*/
|
|
30
|
+
export function resolvePreprocessProviderRoot() {
|
|
31
|
+
const entry = resolveGateProvider();
|
|
32
|
+
if (!entry.ok) return entry;
|
|
33
|
+
return { ok: true, root: dirname(entry.path), source: entry.source };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 取预处理实现模块(懒加载 + 缓存)。
|
|
38
|
+
* 失败时抛出**可诊断**的错误:调用方(工具层)会把它转成 `{ ok:false, error }` 给 AI 看。
|
|
39
|
+
* @returns {Promise<object>}
|
|
40
|
+
*/
|
|
41
|
+
export async function loadPreprocessProvider() {
|
|
42
|
+
// 热插拔支持:每次先重新解析入口,只有「解析结果与上次一致」才复用缓存。
|
|
43
|
+
// 为什么要这样:包可能被**换版本**(路径变了)、被**拔掉**(路径失效)、
|
|
44
|
+
// 或在另一个位置重新插上;只认 cachedModule 会让宿主一直用旧实现或继续用已删除的包。
|
|
45
|
+
// resolveGateProvider 只是几次 existsSync,成本可忽略。
|
|
46
|
+
const resolvedRoot = resolvePreprocessProviderRoot();
|
|
47
|
+
if (!resolvedRoot.ok) {
|
|
48
|
+
cachedModule = null;
|
|
49
|
+
cachedRoot = '';
|
|
50
|
+
throw new Error(resolvedRoot.error);
|
|
51
|
+
}
|
|
52
|
+
if (cachedModule && cachedRoot === resolvedRoot.root) return cachedModule;
|
|
53
|
+
const entryFile = join(resolvedRoot.root, 'lib', 'index.js');
|
|
54
|
+
if (!existsSync(entryFile)) {
|
|
55
|
+
cachedModule = null;
|
|
56
|
+
cachedRoot = '';
|
|
57
|
+
throw new Error(`预处理实现缺少公开面 ${entryFile}(包根 ${resolvedRoot.root})——检查 audit-sluice 是否完整`);
|
|
58
|
+
}
|
|
59
|
+
const loaded = await import(pathToFileURL(entryFile).href);
|
|
60
|
+
cachedModule = loaded;
|
|
61
|
+
cachedRoot = resolvedRoot.root;
|
|
62
|
+
return cachedModule;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 当前已加载的包根(未加载时为空串;供状态/排查展示)。 */
|
|
66
|
+
export function preprocessProviderRoot() {
|
|
67
|
+
return cachedRoot;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 供测试重置缓存(改 DSH_AUDIT_SLUICE_CLI 后要能重新解析)。 */
|
|
71
|
+
export function resetPreprocessProviderCache() {
|
|
72
|
+
cachedModule = null;
|
|
73
|
+
cachedHostApi = null;
|
|
74
|
+
cachedRoot = '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 宿主对接面(规则包/聚合/豁免提示/预处理参数与文案)——从预处理实现 `lib/host-api.js` 取。
|
|
79
|
+
* 包的对接面**只提供已完成的中立能力,不含宿主策略**;宿主策略(job、缓存、路由整形)留在这里。
|
|
80
|
+
* @returns {Promise<object>}
|
|
81
|
+
*/
|
|
82
|
+
export async function hostApi() {
|
|
83
|
+
if (cachedHostApi) return cachedHostApi;
|
|
84
|
+
const resolvedRoot = resolvePreprocessProviderRoot();
|
|
85
|
+
if (!resolvedRoot.ok) throw new Error(resolvedRoot.error);
|
|
86
|
+
const entryFile = join(resolvedRoot.root, 'lib', 'capabilities.js');
|
|
87
|
+
if (!existsSync(entryFile)) throw new Error(`预处理实现缺少能力出口 ${entryFile}`);
|
|
88
|
+
cachedHostApi = await import(pathToFileURL(entryFile).href);
|
|
89
|
+
return cachedHostApi;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 跑审计报告(`code_audit` 工具的实体)。
|
|
94
|
+
* @param {object} options 见 audit-sluice `auditReport`
|
|
95
|
+
* @returns {Promise<object>}
|
|
96
|
+
*/
|
|
97
|
+
export async function auditReport(options = {}) {
|
|
98
|
+
const pkg = await loadPreprocessProvider();
|
|
99
|
+
return pkg.auditReport({ ...options, repo: resolve(String(options.repo || '.')) });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 历史审计(按 commit 区间逐版本审计 + 报告)。 */
|
|
103
|
+
export async function auditHistory(options = {}) {
|
|
104
|
+
const pkg = await loadPreprocessProvider();
|
|
105
|
+
return pkg.auditHistory({ ...options, repo: resolve(String(options.repo || '.')) });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** IO 风险扫描。 */
|
|
109
|
+
export async function ioScan(options = {}) {
|
|
110
|
+
const pkg = await loadPreprocessProvider();
|
|
111
|
+
return pkg.ioScan({ ...options, ...(options.root ? { root: resolve(String(options.root)) } : {}) });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 链接检查。 */
|
|
115
|
+
export async function linkCheck(options = {}) {
|
|
116
|
+
const pkg = await loadPreprocessProvider();
|
|
117
|
+
return pkg.linkCheck({ ...options, ...(options.path ? { path: resolve(String(options.path)) } : {}) });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** 拼接产物作用域撞名检查。 */
|
|
121
|
+
export async function scopeCheck(options = {}) {
|
|
122
|
+
const pkg = await loadPreprocessProvider();
|
|
123
|
+
return pkg.scopeCheck({ ...options });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 注释豁免标注(add/remove/list/check)。 */
|
|
127
|
+
export async function exemptAction(options = {}) {
|
|
128
|
+
const pkg = await loadPreprocessProvider();
|
|
129
|
+
return pkg.exemptAction({ ...options });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 聚合查询维度清单(宿主 HTTP/工具提示共用;从包取,不在宿主里再写一份)。 */
|
|
133
|
+
export async function groupByKeys() {
|
|
134
|
+
const pkg = await loadPreprocessProvider();
|
|
135
|
+
return pkg.GROUP_BY_KEYS;
|
|
136
|
+
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { listRemotes, parseGithubUrl } from '../git/remote-resolve.js';
|
|
19
19
|
import { readAccountStatus } from '../git/account-status.js';
|
|
20
|
-
import { classifyOwnership } from '
|
|
20
|
+
import { classifyOwnership } from './ownership.js';
|
|
21
21
|
|
|
22
22
|
/** 同一仓库只探一次(remote 与账号快照都是磁盘读,逐文件审计时重复开销明显)。 */
|
|
23
23
|
const CACHE = new Map();
|