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.
- package/README.md +76 -47
- package/cli-tool.mjs +2 -4
- package/cli.mjs +11 -4
- package/lib/app/apply.js +15 -13
- package/lib/app/command-registry.js +26 -19
- package/lib/app/handlers/http-constants.js +8 -0
- package/lib/app/handlers/meta.js +2 -2
- package/lib/app/handlers/preprocess.js +104 -0
- package/lib/app/handlers/repo-actions.js +2 -3
- package/lib/app/handlers/repos.js +137 -10
- package/lib/app/handlers/settings.js +34 -15
- package/lib/app/http-handlers.js +13 -42
- package/lib/app/index.js +3 -2
- package/lib/app/inject-text.js +6 -21
- package/lib/app/preprocess-client.js +136 -0
- package/lib/app/repo-ownership.js +1 -1
- package/lib/app/schema.js +20 -10
- package/lib/app/settings-bridge.js +60 -8
- package/lib/app/severity.js +14 -0
- package/lib/app/slash-commands.js +5 -164
- package/lib/app/tool-call.js +96 -163
- package/lib/cli/commands-preprocess.mjs +74 -0
- package/lib/cli/commands-tool.mjs +3 -2
- package/lib/cli/commands-vcs.mjs +39 -5
- package/lib/cli/shared.mjs +36 -10
- package/lib/client/index.js +11 -16
- package/lib/client-parts/git/account.js +21 -12
- package/lib/client-parts/git/actions.js +23 -77
- package/lib/client-parts/git/apply.js +8 -2
- package/lib/client-parts/git/browser.js +1 -1
- package/lib/client-parts/git/const.js +33 -1
- package/lib/client-parts/git/controller.js +175 -176
- package/lib/client-parts/git/icons.js +1 -1
- package/lib/client-parts/git/loader.js +1 -1
- package/lib/client-parts/git/npm.js +56 -37
- package/lib/client-parts/git/page.js +53 -1
- package/lib/client-parts/git/repo.js +8 -1
- package/lib/client-parts/git/settings.js +13 -1
- package/lib/client-parts/git/state.js +237 -0
- package/lib/client-parts/git/utils.js +1 -1
- package/lib/client.js +631 -312
- package/lib/commit-push/pre-commit-engine.js +629 -30
- package/lib/commit-push.js +127 -67
- package/lib/context/index.js +7 -5
- package/lib/core/config.js +1 -27
- package/lib/core/exec.js +2 -11
- package/lib/{exempt/index.js → git/exempt-markers.js} +8 -1
- package/lib/git/identity-rewrite.js +1 -1
- package/lib/git/ignore.js +1 -1
- package/lib/git/index.js +1 -1
- package/lib/git/push.js +2 -17
- package/lib/git/repo-index.js +8 -3
- package/lib/git/repos.js +2 -2
- package/lib/git/sensitive.js +1 -1
- package/lib/npm/install.js +1 -1
- package/lib/npm/publish.js +20 -5
- package/lib/npm/registry.js +2 -2
- package/lib/plugin/auto-push.js +5 -8
- package/lib/preprocess/providers.js +195 -0
- package/lib/self/index.js +1 -1
- package/lib/skip-dirs.js +14 -55
- package/package.json +31 -42
- package/skills/dev/dsh-git-push.md +9 -9
- package/skills/guide/guide-commit-push.md +11 -13
- package/skills/workflow/README.md +0 -1
- package/skills/workflow/task-completion-report.md +2 -2
- package/.auditignore +0 -30
- package/.gitignore +0 -43
- package/cli-audit.mjs +0 -141
- package/lib/BUGFIX-NOTES-2026-09-14.md +0 -278
- 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/schema-audit.js +0 -42
- 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/lib/user-requirements.json +0 -15
- 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/build-client.mjs +0 -131
- package/scripts/bump-version.mjs +0 -178
- package/scripts/check-js-scope.mjs +0 -87
- package/scripts/check.mjs +0 -203
- package/scripts/clean-date-comments.py +0 -102
- package/scripts/cpu-sample.mjs +0 -188
- package/scripts/doc-drift.mjs +0 -200
- package/scripts/doc-func.mjs +0 -212
- package/scripts/doc-tree.mjs +0 -458
- package/scripts/doc-version.mjs +0 -149
- 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/local-registry.mjs +0 -37
- 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/scan-version.mjs +0 -125
- package/scripts/symbol-index.mjs +0 -85
- package/scripts/verify-prestep.mjs +0 -100
- package/scripts/version-source.mjs +0 -173
- 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/{audit-defaults.js → git/defaults.js} +0 -0
package/lib/app/tool-call.js
CHANGED
|
@@ -13,27 +13,26 @@ import { access } from 'node:fs/promises';
|
|
|
13
13
|
import { join, resolve, dirname } from 'node:path';
|
|
14
14
|
import { fileURLToPath } from 'node:url';
|
|
15
15
|
import { spawnSync } from 'node:child_process';
|
|
16
|
-
|
|
17
|
-
import { auditWithScope, auditFull, summarize, isBlockerFinding } from '../audit/index.js';
|
|
18
|
-
import { formatAnalysisCoverageLine } from '../audit/analysis-coverage.js';
|
|
19
|
-
import { scoreQuality } from '../score/index.js';
|
|
16
|
+
// 评分统一经中间层(唯一调用 scoreQuality 的地方);工具侧只传权重覆盖
|
|
20
17
|
import {
|
|
21
18
|
pushInitialContent,
|
|
22
19
|
cloneViaApi, previewClone, resolveMaxCloneFileMB, ensureRemoteRepo, setVisibility, renameRepo, maintainRepoIndex, updateRepoIndex, resolveToken, commitAndPush,
|
|
23
20
|
scanReposAsync, scanRepos, checkGithubAccount, formatGithubAccountBlock, generateSshKey, persistSshPub,
|
|
24
21
|
refreshAccountStatus,
|
|
25
22
|
} from '../git/index.js';
|
|
26
|
-
import {
|
|
23
|
+
import { runPreprocess } from '../commit-push.js';
|
|
24
|
+
// 提交前预处理开关(preCommit.enabled,含旧版开关键的一次性兼容读取)
|
|
25
|
+
import { resolvePreCommitEnabled } from '../commit-push/pre-commit-engine.js';
|
|
26
|
+
// 审计能力统一经客户端调审计包(拆包后审计实现不在本仓库;此处只做参数映射与结果转交)
|
|
27
|
+
import * as auditClient from './preprocess-client.js';
|
|
27
28
|
|
|
28
29
|
/* ───────── 工具调用常量 ───────── */
|
|
29
30
|
import { defaultConfig } from '../client/index.js';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
|
|
32
|
+
/** 等 CI 结果的默认超时(秒):GitHub Actions 常见 3~8 分钟,15 分钟是安全上界。 */
|
|
33
|
+
const CI_WAIT_TIMEOUT_SEC_DEFAULT = 900;
|
|
33
34
|
import { callIdentityRewrite } from './handlers/identity-rewrite.js';
|
|
34
35
|
import { MSG_REPO_REQUIRED } from './constants.js';
|
|
35
|
-
import { buildAuditApiGuide } from './inject-text.js';
|
|
36
|
-
import { exemptStatsOf, GROUP_BY_KEYS } from './audit-api.js';
|
|
37
36
|
import { setLastSlotHitStats } from './slot-stats.js';
|
|
38
37
|
import { getDefaultScanRoot } from './scan-root.js';
|
|
39
38
|
import { probeRepoOwnership } from './repo-ownership.js';
|
|
@@ -63,7 +62,6 @@ async function pushWithPostSteps(args, env, cfg) {
|
|
|
63
62
|
push: args.push !== false,
|
|
64
63
|
dryRun: args.dryRun === true,
|
|
65
64
|
customIgnorePatterns: args.ignorePatterns || '',
|
|
66
|
-
requirementsConfirmed: args.requirementsConfirmed === true,
|
|
67
65
|
force: args.force === true,
|
|
68
66
|
pushMethod: cfg.pushMethod || 'ssh',
|
|
69
67
|
// 推送目标 remote(多 remote/fork 场景;缺省 origin);推送与核验使用同一 remote
|
|
@@ -74,11 +72,12 @@ async function pushWithPostSteps(args, env, cfg) {
|
|
|
74
72
|
// 推送后等 CI 结果(默认不等):按推到远端的那个 sha 查 Actions,
|
|
75
73
|
// 全绿=通过、任一失败=ciFailed、超时/无 CI 如实回报(都不改变推送本身成功的事实)
|
|
76
74
|
waitCi: args.waitCi === true || cfg.waitCi === true,
|
|
77
|
-
ciTimeoutSec: Number(args.ciTimeoutSec) > 0 ? Number(args.ciTimeoutSec) :
|
|
75
|
+
ciTimeoutSec: Number(args.ciTimeoutSec) > 0 ? Number(args.ciTimeoutSec) : CI_WAIT_TIMEOUT_SEC_DEFAULT,
|
|
78
76
|
// 精确 add 路径(逗号分隔,相对 repo);空 = git add -A 全量
|
|
79
77
|
paths: String(args.paths || ''),
|
|
80
|
-
//
|
|
81
|
-
|
|
78
|
+
// 敏感文件扫描与「提交前预处理」同一个开关:预处理关闭 ⇒ 不扫。
|
|
79
|
+
// 扫描属提交门禁的一部分,随门禁一起开关,不单独占一个配置位。
|
|
80
|
+
scanSensitive: resolvePreCommitEnabled(cfg).enabled,
|
|
82
81
|
});
|
|
83
82
|
// ── 鼓励使用结构化提交信息(messageItems):提醒 + 采用率留痕 ──────────────────
|
|
84
83
|
// 为什么需要:默认路径(单串 message)更省事,结构化参数长期无人用 ⇒ 两件事互补:
|
|
@@ -232,7 +231,7 @@ function startHostJob(jobs, spec, owner) {
|
|
|
232
231
|
}
|
|
233
232
|
|
|
234
233
|
/**
|
|
235
|
-
* git_clone
|
|
234
|
+
* git_clone 工具实现:clone 注册宿主后台 job。
|
|
236
235
|
* 大仓库下载注册为宿主官方后台 job(ctx.jobs)——工具立即返回 jobId(如 git-clone-1),
|
|
237
236
|
* AI 用宿主 job_output/job_list/job_kill 查询/中止;宿主无 job 控制器时同步执行保底。
|
|
238
237
|
* clone 是只读操作无需审计门禁(与 git_commit_push 的差异点)。
|
|
@@ -310,7 +309,7 @@ async function callNpmPublishJob(args = {}, jobs, exec, log, env = {}, cfg = {})
|
|
|
310
309
|
/**
|
|
311
310
|
* 把发包结果映射成宿主 job 的 {status, detail, output} —— **成功也必须给 detail**。
|
|
312
311
|
*
|
|
313
|
-
*
|
|
312
|
+
* 注意:成功分支也必须写 `detail`(曾只写 `output`,`job_output` 读出来是「(no new output)」)。
|
|
314
313
|
* ⇒ 宿主 job 的完成回执里没有可读结果,`job_output` 读出来是「(no new output)」✗,
|
|
315
314
|
* 只能去翻插件日志与 registry 侧面确认(clone / commit+push 都有 detail ⇒ 只有 npm 空 ✗)。
|
|
316
315
|
*
|
|
@@ -400,18 +399,21 @@ async function callCommitPush(args, env, cfg, log, jobs, exec) {
|
|
|
400
399
|
// blocker 命中 → 立即返回拦截、不执行任何 git 操作;审计通过 → commit+push
|
|
401
400
|
// +索引重建注册为宿主官方后台 job(ctx.jobs,dsh-jobs-local),工具立即返回
|
|
402
401
|
// jobId(如 git-push-1),AI 用宿主自带 job_output/job_list/job_kill 查询。
|
|
403
|
-
const
|
|
402
|
+
const preprocessGate = await runPreprocess({
|
|
404
403
|
repoPath: repo,
|
|
405
404
|
audit: args.audit,
|
|
406
405
|
// 不再透传 auditLevel——审计固定走完整流程(正则初筛 + AST 语义检查)
|
|
407
406
|
rulesetDir: args.ruleset,
|
|
408
|
-
|
|
407
|
+
// 扫描范围/权重/规则槽位/文件上限不再从宿主配置取:它们是预处理实现自己的配置,
|
|
408
|
+
// 由审计包读自己的 config.json 当默认值(本工具参数里的显式值仍优先)。
|
|
409
409
|
cfg,
|
|
410
410
|
// 本次提交的按文件临时豁免(不落盘):列入的文件 finding 不参与拦截判定(含 blocker)
|
|
411
|
-
|
|
412
|
-
|
|
411
|
+
auditExemptPaths: Array.isArray(args.auditExemptPaths) ? args.auditExemptPaths : [],
|
|
412
|
+
auditExemptReason: args.auditExemptReason,
|
|
413
|
+
// 本次调用的预处理链(优先级 > 配置文件里的 stages)
|
|
414
|
+
stages: Array.isArray(args.preprocessStages) && args.preprocessStages.length ? args.preprocessStages : null,
|
|
413
415
|
});
|
|
414
|
-
if (!
|
|
416
|
+
if (!preprocessGate.ok) return preprocessGate; // { ok:false, blocked:true, audit }
|
|
415
417
|
const doPush = () => pushWithPostSteps(args, env, cfg);
|
|
416
418
|
// 宿主未提供 ctx.jobs(如脱离 DSH 的 CLI/测试环境)→ 同步执行保底
|
|
417
419
|
if (!jobs || typeof jobs.start !== 'function') {
|
|
@@ -438,12 +440,12 @@ async function callCommitPush(args, env, cfg, log, jobs, exec) {
|
|
|
438
440
|
return { ok: true, async: false, jobFallback: true, jobFallbackReason: started.error, result: r };
|
|
439
441
|
}
|
|
440
442
|
}
|
|
441
|
-
return { ok: true, async: true, jobId, audit:
|
|
443
|
+
return { ok: true, async: true, jobId, audit: preprocessGate.audit, hint: '已注册宿主后台 job(结果完成会自动返回,无需特意查询);如需主动查:job_output ' + jobId };
|
|
442
444
|
}
|
|
443
445
|
|
|
444
446
|
/**
|
|
445
447
|
* code_audit 工具实现(从 callTool switch 抽出):
|
|
446
|
-
* 权重 =
|
|
448
|
+
* 权重 = 显式传参(未传则用审计包自己的配置);history 走宿主后台 job(无控制器同步降级);
|
|
447
449
|
* 结果带 block 可读总结 + slotStats 供侧边栏规则包命中数。
|
|
448
450
|
*/
|
|
449
451
|
/**
|
|
@@ -454,9 +456,8 @@ function buildAuditOpts(args, cfg, scope) {
|
|
|
454
456
|
return {
|
|
455
457
|
scope,
|
|
456
458
|
rulesetDir: args.ruleset || '',
|
|
457
|
-
maxScanFiles
|
|
458
|
-
|
|
459
|
-
disabledSlots: Array.isArray(cfg.auditDisabledSlots) ? cfg.auditDisabledSlots : [],
|
|
459
|
+
// maxScanFiles / disabledSlots / slots 刻意不传:它们归审计包自己的配置
|
|
460
|
+
// (lib/config/load.js),宿主再传一份就等于两个包共享同一份配置。
|
|
460
461
|
includeIgnored: args.includeIgnored === true,
|
|
461
462
|
// 分析覆盖率信息项(默认开;coverage:false 关闭——大仓库省一次读取+解析)
|
|
462
463
|
coverage: args.coverage !== false,
|
|
@@ -472,13 +473,15 @@ function buildAuditOpts(args, cfg, scope) {
|
|
|
472
473
|
*/
|
|
473
474
|
async function runHistoryAuditTool(args, env, cfg, jobs, exec, weights) {
|
|
474
475
|
const repo = args.repo;
|
|
475
|
-
|
|
476
|
-
const { resolveReportDir } = await import('../audit/history-report.js');
|
|
476
|
+
// 历史审计的遍历与评分都在审计包内;宿主只决定「是否起后台 job / 报告目录」
|
|
477
477
|
const auditOpts = buildAuditOpts(args, cfg, 'full');
|
|
478
|
-
|
|
478
|
+
let reportDir = '';
|
|
479
479
|
const doHistory = async () => {
|
|
480
|
-
const r = await
|
|
481
|
-
|
|
480
|
+
const r = await withAuditPackage(() => auditClient.auditHistory({
|
|
481
|
+
repo, since: args.since, until: args.until, outDir: args.outDir || '', auditOpts, weights,
|
|
482
|
+
}));
|
|
483
|
+
reportDir = r?.reportDir || '';
|
|
484
|
+
return { status: r?.ok ? 'completed' : 'failed', detail: r?.ok ? 'history audit done' : String(r?.error || 'failed'), output: JSON.stringify(r) };
|
|
482
485
|
};
|
|
483
486
|
if (!jobs || typeof jobs.start !== 'function') {
|
|
484
487
|
const r = await doHistory();
|
|
@@ -501,9 +504,9 @@ async function runHistoryAuditTool(args, env, cfg, jobs, exec, weights) {
|
|
|
501
504
|
async function callCodeAudit(args, env, cfg, log, jobs, exec) {
|
|
502
505
|
const repo = args.repo;
|
|
503
506
|
if (!repo) return { ok: false, error: MSG_REPO_REQUIRED };
|
|
504
|
-
//
|
|
505
|
-
//
|
|
506
|
-
const weightSrc = args.weights ||
|
|
507
|
+
// 权重来源 = 工具参数显式传参;未传则交给审计包(它读自己的权重覆盖配置)。
|
|
508
|
+
// 宿主不再持有审计权重:那属于「怎么审」,归审计包配置。
|
|
509
|
+
const weightSrc = args.weights || '';
|
|
507
510
|
let weights = {};
|
|
508
511
|
if (weightSrc) {
|
|
509
512
|
try { weights = JSON.parse(weightSrc); } catch { /* 非法 JSON 回退默认权重 */ }
|
|
@@ -512,48 +515,23 @@ async function callCodeAudit(args, env, cfg, log, jobs, exec) {
|
|
|
512
515
|
return runStandardAuditTool(args, env, cfg, log, weights);
|
|
513
516
|
}
|
|
514
517
|
|
|
515
|
-
/** standard 模式:diff/full 审计 + 评分 + block
|
|
518
|
+
/** standard 模式:diff/full 审计 + 评分 + block 总结(审计与报告整形都在审计包内)。 */
|
|
516
519
|
async function runStandardAuditTool(args, env, cfg, log, weights) {
|
|
517
520
|
const repo = args.repo;
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
//
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
// 统一口径:error 也属拦截级(与 summarize 一致)。此前只筛 'blocker' ⇒
|
|
533
|
-
// 出现「summary.blocker=10 但这里只枚举 7」的差额(差的正是 error 级)✗
|
|
534
|
-
.filter(isBlockerFinding)
|
|
535
|
-
.map((f) => ({ file: f.file, line: f.line, rule: f.rule, message: String(f.message || '').slice(0, MAX_MSG_PREVIEW) }));
|
|
536
|
-
// 审计输出改为「级别数量 + 评分 + API 查询用法」——审计明细由聚合 API
|
|
537
|
-
// (/api/git-push/audit)查询,不再内联输出 findings/审计内容(有聚合 API 消费审计结果)。
|
|
538
|
-
const apiGuide = buildAuditApiGuide(repo, { scope: auditResult.scope, summary, quality, exemptStats, blocked, groupByTypes: GROUP_BY_KEYS });
|
|
539
|
-
// 分析覆盖率由审计编排层统一计算(CLI 与工具同一口径,见 lib/audit/orchestrate.js),这里只做透传与展示。
|
|
540
|
-
const analysisCoverage = auditResult.analysisCoverage || null;
|
|
541
|
-
// 缓存按规则包命中数供给 HTTP /rule-slots(侧边栏规则包列表显示实际命中数)
|
|
542
|
-
if (auditResult.slotStats) setLastSlotHitStats(auditResult.slotStats, repo);
|
|
543
|
-
log?.info?.(`code_audit ${repo} → ${quality.emptyResult ? '未评分(0 文件)' : quality.score + '/' + quality.level}(blocker ${summary.blocker} / warning ${summary.warning} / notice ${summary.notice})`);
|
|
544
|
-
// 默认**返回全量审计结果**(findings + yaml):调用方(AI/脚本)拿到的就该是能直接读的问题明细,
|
|
545
|
-
// 而不是只有分数再自己去查聚合 API —— 多一跳就多一次漏看的可能。
|
|
546
|
-
// 需要精简(大仓库结果过大、或只要结论)时显式传 includeFindings=false / summaryOnly=true。
|
|
547
|
-
const withFindings = args.includeFindings !== false && args.summaryOnly !== true;
|
|
548
|
-
const out = { ok: true, scope: auditResult.scope, files: auditResult.files, summary, quality, exemptStats, blocked, groupByTypes: GROUP_BY_KEYS, apiGuide, slotStats: auditResult.slotStats };
|
|
549
|
-
if (analysisCoverage) {
|
|
550
|
-
out.analysisCoverage = analysisCoverage;
|
|
551
|
-
out.apiGuide = `${apiGuide}\n${formatAnalysisCoverageLine(analysisCoverage)}`;
|
|
552
|
-
}
|
|
553
|
-
if (withFindings) {
|
|
554
|
-
out.findings = auditResult.findings;
|
|
555
|
-
if (auditResult.yaml) out.yaml = auditResult.yaml;
|
|
556
|
-
}
|
|
521
|
+
// 审计包的 auditReport 已按同样口径处理「非 git 目录退化成 full」与「0 文件不评分」
|
|
522
|
+
const out = await withAuditPackage(() => auditClient.auditReport({
|
|
523
|
+
repo,
|
|
524
|
+
scope: args.scope === 'full' ? 'full' : 'diff',
|
|
525
|
+
weights,
|
|
526
|
+
rulesetDir: args.rulesetDir || '',
|
|
527
|
+
includeFindings: args.includeFindings !== false && args.summaryOnly !== true,
|
|
528
|
+
// 覆盖率是信息项(不影响 summary/quality);工具参数 coverage:false 时关掉
|
|
529
|
+
...(args.coverage === false ? { coverage: false } : {}),
|
|
530
|
+
}));
|
|
531
|
+
if (out?.ok === false) return out;
|
|
532
|
+
// 宿主侧副作用:缓存按规则包命中数,供 HTTP /rule-slots 在侧边栏显示实际命中数
|
|
533
|
+
if (out.slotStats) setLastSlotHitStats(out.slotStats, repo);
|
|
534
|
+
log?.info?.(`code_audit ${repo} → ${out.quality?.emptyResult ? '未评分(0 文件)' : `${out.quality?.score}/${out.quality?.level}`}(blocker ${out.summary?.blocker} / warning ${out.summary?.warning} / notice ${out.summary?.notice})`);
|
|
557
535
|
return out;
|
|
558
536
|
}
|
|
559
537
|
|
|
@@ -574,20 +552,18 @@ export async function callTool(toolName, args = {}, env = {}, cfg = defaultConfi
|
|
|
574
552
|
case 'git_commit_push':
|
|
575
553
|
return callCommitPush(args, env, cfg, log, jobs, exec);
|
|
576
554
|
case 'exempt': {
|
|
577
|
-
// 注释豁免工具:add/remove/list/check
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
if (action === 'check') return checkExempt({ repoPath });
|
|
590
|
-
return { ok: false, error: `未知 action:${action || '(空)'}(add/remove/list/check)` };
|
|
555
|
+
// 注释豁免工具:add/remove/list/check —— 实现归审计包(标记映射与审计判定同源)
|
|
556
|
+
return withAuditPackage(() => auditClient.exemptAction({
|
|
557
|
+
action: String(args.action || ''),
|
|
558
|
+
repo: String(args.repo || process.cwd()),
|
|
559
|
+
path: args.path,
|
|
560
|
+
line: args.line,
|
|
561
|
+
scope: args.scope,
|
|
562
|
+
rule: args.rule,
|
|
563
|
+
marker: args.marker,
|
|
564
|
+
reason: args.reason,
|
|
565
|
+
dryRun: args.dryRun === true,
|
|
566
|
+
}));
|
|
591
567
|
}
|
|
592
568
|
case 'code_audit':
|
|
593
569
|
return callCodeAudit(args, env, cfg, log, jobs, exec);
|
|
@@ -597,7 +573,7 @@ export async function callTool(toolName, args = {}, env = {}, cfg = defaultConfi
|
|
|
597
573
|
}
|
|
598
574
|
case 'git_clone': {
|
|
599
575
|
if (!args.target) return { ok: false, error: 'target 必填' };
|
|
600
|
-
//
|
|
576
|
+
// clone 注册宿主后台 job(同 git_commit_push)——大仓库下载
|
|
601
577
|
// 不阻塞工具调用,立即返回 jobId;宿主 job 完成自动回传。宿主无 job 控制器时同步执行保底。
|
|
602
578
|
// env/cfg 必须传下去:clone 要按仓库解析 token(否则走匿名 API,私有库失败、公开库吃限流)
|
|
603
579
|
// 与统一体积上限(与 HTTP 路径同口径)。
|
|
@@ -652,18 +628,10 @@ export async function callTool(toolName, args = {}, env = {}, cfg = defaultConfi
|
|
|
652
628
|
dryRun: args.dryRun !== false, updateRemotes: args.updateRemotes !== false,
|
|
653
629
|
});
|
|
654
630
|
case 'io_scan': {
|
|
655
|
-
//
|
|
656
|
-
// 不在此另写扫描逻辑,避免两套判定漂移。
|
|
631
|
+
// IO 风险扫描:实现在审计包(AST 四级分级,与 robustness/io-risk 同一份)
|
|
657
632
|
const root = args.repo || env.workspaceRoot;
|
|
658
633
|
if (!root) return { ok: false, error: 'repo 必填(或用会话工作区)' };
|
|
659
|
-
|
|
660
|
-
targets: [root],
|
|
661
|
-
writeOnly: args.writeOnly === true,
|
|
662
|
-
});
|
|
663
|
-
const byRisk = { high: 0, medium: 0, low: 0, safe: 0 };
|
|
664
|
-
for (const hit of hits) if (byRisk[hit.risk] != null) byRisk[hit.risk] += 1;
|
|
665
|
-
const sync = hits.filter((hit) => hit.type === 'sync').length;
|
|
666
|
-
return { ok: true, root, total: hits.length, sync, byRisk, items: hits };
|
|
634
|
+
return withAuditPackage(() => auditClient.ioScan({ root, writeOnly: args.writeOnly === true }));
|
|
667
635
|
}
|
|
668
636
|
case 'git_clone_preview': {
|
|
669
637
|
if (!args.target) return { ok: false, error: 'target 必填' };
|
|
@@ -676,22 +644,7 @@ export async function callTool(toolName, args = {}, env = {}, cfg = defaultConfi
|
|
|
676
644
|
}
|
|
677
645
|
case 'link_check': {
|
|
678
646
|
const path = args.path || env.workspaceRoot;
|
|
679
|
-
|
|
680
|
-
return { ok: true, count: links.length, penalty: sumLinkPenalty(links), findings: links };
|
|
681
|
-
}
|
|
682
|
-
case 'module_splitter': {
|
|
683
|
-
// 巨型单文件拆分(复用 scripts/module-splitter.py,python3 零依赖)。
|
|
684
|
-
// python3 调用逻辑抽到 lib/git/module-splitter.js(与 cli cmdModuleSplitter 共用),
|
|
685
|
-
// 此处只做参数映射与结果返回。
|
|
686
|
-
const command = String(args.command || '').trim();
|
|
687
|
-
const target = String((command === 'analyze' ? args.file : args.plan) || '').trim();
|
|
688
|
-
if (!target) {
|
|
689
|
-
return { ok: false, error: command === 'analyze' ? 'analyze 需要 file(待拆 .js 路径)' : `${command} 需要 plan(plan.json 文件路径)` };
|
|
690
|
-
}
|
|
691
|
-
if (!existsSync(target)) return { ok: false, error: `目标不存在:${target}` };
|
|
692
|
-
const r = runModuleSplitter({ sub: command, target, dryRun: args.dryRun === true });
|
|
693
|
-
if (!r.ok) return { ok: false, error: r.error };
|
|
694
|
-
return { ok: true, command: r.sub, target: r.target, dryRun: r.dryRun, output: r.output };
|
|
647
|
+
return withAuditPackage(() => auditClient.linkCheck({ path }));
|
|
695
648
|
}
|
|
696
649
|
case 'git_account_check': {
|
|
697
650
|
if (args.sshPub) persistSshPub(String(args.sshPub), { workspaceRoot: env.workspaceRoot });
|
|
@@ -730,13 +683,13 @@ export async function callTool(toolName, args = {}, env = {}, cfg = defaultConfi
|
|
|
730
683
|
const endpoints = [...new Set(src.match(/case '\/api\/git-push\/[A-Za-z0-9/_-]+'/g) || [])]
|
|
731
684
|
.map((s) => s.replace("case '/api/git-push/", '').replace(/'$/, ''))
|
|
732
685
|
.sort();
|
|
733
|
-
// path
|
|
734
|
-
// ① 短名 `rule-slots`
|
|
735
|
-
// ② 前缀相对 `
|
|
736
|
-
// ③ 完整路径 `/api/
|
|
686
|
+
// path 三种写法都认(AI 面契约:短名不写死前缀,也别让调用方记全路径):
|
|
687
|
+
// ① 短名 `rule-slots` → 走 /api/git-push/rule-slots(git/共享侧)
|
|
688
|
+
// ② 前缀相对 `preprocess/rule-slots` → /api/preprocess/rule-slots(预处理侧,推荐写法)
|
|
689
|
+
// ③ 完整路径 `/api/preprocess/rule-slots` → 原样
|
|
737
690
|
const rawPath = String(args.path || '').trim();
|
|
738
691
|
const ep = rawPath.replace(/^\/+/, '').replace(/^api\//, '');
|
|
739
|
-
if (!ep) return { ok: true, count: endpoints.length, endpoints, note: '传 path 调用具体接口(如 path=status
|
|
692
|
+
if (!ep) return { ok: true, count: endpoints.length, endpoints, note: '传 path 调用具体接口(如 path=status;预处理接口推荐 path=preprocess/audit)' };
|
|
740
693
|
const method = String(args.method || 'GET').toUpperCase();
|
|
741
694
|
let query = {};
|
|
742
695
|
let body;
|
|
@@ -750,8 +703,8 @@ export async function callTool(toolName, args = {}, env = {}, cfg = defaultConfi
|
|
|
750
703
|
const bodyText = body === undefined ? '' : JSON.stringify(body);
|
|
751
704
|
const out = await handleHttp({
|
|
752
705
|
method,
|
|
753
|
-
// 已带前缀(
|
|
754
|
-
url: `/api/${/^(
|
|
706
|
+
// 已带前缀(preprocess/… 或 git-push/…)就用它;短名默认走 git-push(git/共享侧)
|
|
707
|
+
url: `/api/${/^(preprocess|git-push)\//.test(ep) ? ep : `git-push/${ep}`}${qs ? '?' + qs : ''}`,
|
|
755
708
|
origin: 'http://localhost', // 内部调用 = 本机同源(写类接口的 CSRF 门禁据此放行)
|
|
756
709
|
headers: { host: 'localhost', 'content-length': String(bodyText.length) },
|
|
757
710
|
body: bodyText,
|
|
@@ -759,55 +712,35 @@ export async function callTool(toolName, args = {}, env = {}, cfg = defaultConfi
|
|
|
759
712
|
return { ok: out?.status === 200 && out?.body?.ok !== false, status: out?.status, endpoint: ep, result: out?.body };
|
|
760
713
|
}
|
|
761
714
|
case 'scope_check': {
|
|
762
|
-
//
|
|
763
|
-
//
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
const repoRoot = resolve(String(args.repo || env.workspaceRoot || process.cwd()));
|
|
768
|
-
const splitList = (value) => String(value || '').split(/[,;\s]+/).map((s) => s.trim()).filter(Boolean);
|
|
769
|
-
let targets = splitList(args.files).map((f) => resolve(repoRoot, f));
|
|
770
|
-
if (!targets.length) {
|
|
771
|
-
// 缺省取项目自己声明的产物清单(dshScopeCheck.files)——不猜文件名,
|
|
772
|
-
// 否则「哪些文件是拼接产物」这件事会散成两处判断(本文件 + package.json)。
|
|
773
|
-
const policy = readProjectScopePolicy(join(repoRoot, 'package.json'));
|
|
774
|
-
const base = policy.configPath ? dirname(policy.configPath) : repoRoot;
|
|
775
|
-
targets = policy.files.map((f) => resolve(base, f));
|
|
776
|
-
if (!targets.length) {
|
|
777
|
-
return { ok: false, error: `未指定 files,且 ${join(repoRoot, 'package.json')} 未声明 dshScopeCheck.files` };
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
const result = runScopeCheck({
|
|
781
|
-
files: targets,
|
|
715
|
+
// 拼接产物作用域撞名:判定(ast/scope-collisions)+ 契约(engine/scope-policy)都在审计包,
|
|
716
|
+
// 本处只做参数映射与错误包装。
|
|
717
|
+
return withAuditPackage(() => auditClient.scopeCheck({
|
|
718
|
+
repo: String(args.repo || env.workspaceRoot || process.cwd()),
|
|
719
|
+
files: args.files,
|
|
782
720
|
prefix: String(args.prefix || ''),
|
|
783
|
-
allowlist:
|
|
721
|
+
allowlist: args.allowlist,
|
|
784
722
|
...(typeof args.topLevelMustBeEmpty === 'boolean' ? { topLevelMustBeEmpty: args.topLevelMustBeEmpty } : {}),
|
|
785
|
-
});
|
|
786
|
-
const lines = result.policySources.map((src) => `策略来源:${src}`);
|
|
787
|
-
for (const report of result.reports) {
|
|
788
|
-
const rel = report.file.startsWith(`${repoRoot}/`) ? report.file.slice(repoRoot.length + 1) : report.file;
|
|
789
|
-
if (report.ok) {
|
|
790
|
-
lines.push(`✔ ${rel}:${(report.declarations || []).length} 个声明,无同帧重名`);
|
|
791
|
-
continue;
|
|
792
|
-
}
|
|
793
|
-
lines.push(`✗ ${rel}:`);
|
|
794
|
-
for (const violation of report.violations || []) lines.push(` - ${violation}`);
|
|
795
|
-
}
|
|
796
|
-
const violationCount = result.reports.reduce((sum, report) => sum + (report.violations || []).length, 0);
|
|
797
|
-
return {
|
|
798
|
-
ok: result.ok,
|
|
799
|
-
count: result.reports.length,
|
|
800
|
-
violations: violationCount,
|
|
801
|
-
policySources: result.policySources,
|
|
802
|
-
reports: result.reports,
|
|
803
|
-
lines,
|
|
804
|
-
};
|
|
723
|
+
}));
|
|
805
724
|
}
|
|
806
725
|
default:
|
|
807
726
|
return { ok: false, error: `未知工具: ${toolName}` };
|
|
808
727
|
}
|
|
809
728
|
}
|
|
810
729
|
|
|
730
|
+
/**
|
|
731
|
+
* 调审计包的统一包装:把「包加载失败」变成工具可见的 `{ ok:false, error }`。
|
|
732
|
+
* 为什么不在每处 try/catch:五个工具用同一份错误格式,AI 才能一致地判读失败原因。
|
|
733
|
+
* @param {Function} call 实际调用(返回 Promise 或值)
|
|
734
|
+
* @returns {Promise<object>}
|
|
735
|
+
*/
|
|
736
|
+
async function withAuditPackage(call) {
|
|
737
|
+
try {
|
|
738
|
+
return await call();
|
|
739
|
+
} catch (e) {
|
|
740
|
+
return { ok: false, error: `审计包不可用:${e?.message || e}` };
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
811
744
|
/** 按 shell 规则拆分参数串(支持单双引号包裹含空格的路径)。 */
|
|
812
745
|
function shellSplit(input) {
|
|
813
746
|
const out = [];
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI 命令 · 预处理域(从「所有在位 provider 的声明」里找能力并转发)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么不是写死 `audit`:预处理是通用机制,审计只是第一个实现。
|
|
5
|
+
* 本命令只做三件事:① 问 providers 层「谁声明了这个 action」 ② 找不到就说清有哪些可用
|
|
6
|
+
* ③ 找到就 spawn 那个 provider 的 CLI 并把退出码原样透传(脚本可判定失败)。
|
|
7
|
+
*
|
|
8
|
+
* HTTP 侧(/api/preprocess/<action>)用的是同一个查找函数(findActionProvider / findEndpointProvider),
|
|
9
|
+
* 所以 CLI 与 HTTP 的能力面天然一致,不会一边有、一边没有。
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from 'node:child_process';
|
|
12
|
+
|
|
13
|
+
import { findActionProvider, listDeclaredCapabilities, resolveProvider } from '../preprocess/providers.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 列出当前可用的预处理能力(供 help / 报错提示)。
|
|
17
|
+
* @returns {Promise<string>} 多行文本
|
|
18
|
+
*/
|
|
19
|
+
export async function describePreprocessCapabilities() {
|
|
20
|
+
const caps = await listDeclaredCapabilities();
|
|
21
|
+
const lines = [];
|
|
22
|
+
if (caps.actions.length === 0) {
|
|
23
|
+
lines.push('当前没有任何在位 provider 声明 action(预处理扩展未安装)');
|
|
24
|
+
} else {
|
|
25
|
+
lines.push('可用预处理动作:');
|
|
26
|
+
for (const action of caps.actions) {
|
|
27
|
+
const params = Array.isArray(action.params) ? action.params.length : 0;
|
|
28
|
+
lines.push(` ${action.action} [${action.provider}] ${params} 个参数 ${action.desc || ''}`.trimEnd());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const miss of caps.missing) {
|
|
32
|
+
lines.push(` · ${miss.provider.id} 不可用:${miss.reason}`);
|
|
33
|
+
}
|
|
34
|
+
return lines.join('\n');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 执行一次预处理转发。
|
|
39
|
+
* @param {string[]} positional 命令名之后的参数:第一个是 action,其余原样转发
|
|
40
|
+
* @returns {Promise<number>} 退出码(0 成功 / 1 被拦 / 2 参数或执行错误)
|
|
41
|
+
*/
|
|
42
|
+
export async function cmdPreprocess(positional = []) {
|
|
43
|
+
const [action, ...forwardArgs] = positional;
|
|
44
|
+
if (!action) {
|
|
45
|
+
console.error(await describePreprocessCapabilities());
|
|
46
|
+
console.error('\n用法:preprocess <action> [参数…]');
|
|
47
|
+
return 2;
|
|
48
|
+
}
|
|
49
|
+
const hit = await findActionProvider(action);
|
|
50
|
+
if (!hit) {
|
|
51
|
+
const caps = await listDeclaredCapabilities();
|
|
52
|
+
const known = caps.actions.map((item) => item.action);
|
|
53
|
+
console.error(`没有 provider 声明动作「${action}」${known.length ? `(可用:${known.join(' / ')})` : '(当前没有任何 provider 在位)'}`);
|
|
54
|
+
console.error(await describePreprocessCapabilities());
|
|
55
|
+
return 2;
|
|
56
|
+
}
|
|
57
|
+
const resolved = resolveProvider(hit.provider.id);
|
|
58
|
+
if (!resolved.ok) {
|
|
59
|
+
console.error(resolved.error);
|
|
60
|
+
return 2;
|
|
61
|
+
}
|
|
62
|
+
// 转发:provider 自己的 CLI 认得同样的 action 名(声明与实现同名,避免映射表漂移)
|
|
63
|
+
const child = spawn(process.execPath, [resolved.path, action, ...forwardArgs], { stdio: 'inherit' });
|
|
64
|
+
return await new Promise((resolvePromise) => {
|
|
65
|
+
child.on('error', (error) => {
|
|
66
|
+
console.error(`启动预处理实现失败:${error?.message || error}`);
|
|
67
|
+
resolvePromise(2);
|
|
68
|
+
});
|
|
69
|
+
child.on('close', (code, signal) => {
|
|
70
|
+
if (signal) { console.error(`预处理实现被信号中断:${signal}`); resolvePromise(2); return; }
|
|
71
|
+
resolvePromise(typeof code === 'number' ? code : 2);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -13,9 +13,10 @@ import { readFileSync } from 'node:fs';
|
|
|
13
13
|
import { CLI_ENTRIES, allCommands, parseEntrySourceMeta, readEntrySource } from './shared.mjs';
|
|
14
14
|
|
|
15
15
|
/** 入口文件清单(bin → 源文件)。自检逐个核对。 */
|
|
16
|
+
// 审计 CLI 已随审计能力独立成包(audit-sluice),本插件只剩 git / tool 两侧,
|
|
17
|
+
// 故自检不再遍历 audit 入口(文件已不存在)。
|
|
16
18
|
export const ENTRY_FILES = [
|
|
17
19
|
{ cliName: 'git-sluice', file: 'cli.mjs' },
|
|
18
|
-
{ cliName: 'audit-sluice', file: 'cli-audit.mjs' },
|
|
19
20
|
{ cliName: 'tool-sluice', file: 'cli-tool.mjs' },
|
|
20
21
|
];
|
|
21
22
|
|
|
@@ -87,7 +88,7 @@ export function cmdSelfCheck() {
|
|
|
87
88
|
// 一次性并入(不在循环里逐条 push:既少一层循环,也让「失败清单来自一处」更好读)
|
|
88
89
|
failures.push(...entryFailures);
|
|
89
90
|
for (const failure of entryFailures) console.error(` ✗ ${failure}`);
|
|
90
|
-
if (!entryFailures.length) console.log(` ✓
|
|
91
|
+
if (!entryFailures.length) console.log(` ✓ 命令覆盖:各入口共 ${allCommands().length} 个命令都有用法行`);
|
|
91
92
|
process.exitCode = failures.length > 0 ? 1 : 0;
|
|
92
93
|
return failures.length > 0 ? 1 : 0;
|
|
93
94
|
}
|
package/lib/cli/commands-vcs.mjs
CHANGED
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
* (与插件工具同源)。
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
12
13
|
import { scanRepos } from '../git/repos.js';
|
|
13
14
|
import { updateRepoIndex } from '../git/repo-index.js';
|
|
14
15
|
import { runWrappedGit } from '../git/wrapped-git.js';
|
|
15
16
|
import { commitWithAudit } from '../commit-push.js';
|
|
16
|
-
|
|
17
|
-
import
|
|
17
|
+
|
|
18
|
+
import * as auditClient from '../app/preprocess-client.js';
|
|
18
19
|
import { cloneViaApi, previewClone } from '../git/clone.js';
|
|
19
20
|
import { DEFAULT_MAX_FILE_MB } from '../git/clone-download.js';
|
|
20
21
|
import { resolveToken } from '../git/credentials.js';
|
|
@@ -87,11 +88,43 @@ export async function cmdGit(args = []) {
|
|
|
87
88
|
return r.ok ? 0 : (typeof r.status === 'number' ? r.status : 1);
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
/**
|
|
92
|
+
* 解析 `--preprocess-stages` 的取值:内联 JSON 或 `@路径.json`。
|
|
93
|
+
*
|
|
94
|
+
* 为什么支持 @文件:阶段链带 args 数组,命令行里容易超长/被 shell 改写;写文件更稳。
|
|
95
|
+
* 解析失败立刻报错(在任何 git 操作之前),错误信息指出第几项哪个字段不对。
|
|
96
|
+
* @param {string} raw 原始取值
|
|
97
|
+
* @returns {{stages: Array|null, error?: string}}
|
|
98
|
+
*/
|
|
99
|
+
function parsePreprocessStagesFlag(raw) {
|
|
100
|
+
const text = String(raw == null ? '' : raw).trim();
|
|
101
|
+
if (!text) return { stages: null };
|
|
102
|
+
let json = text;
|
|
103
|
+
if (text.startsWith('@')) {
|
|
104
|
+
const file = text.slice(1).trim();
|
|
105
|
+
try { json = readFileSync(file, 'utf8'); } catch (e) { return { stages: null, error: `读不到 --preprocess-stages 文件:${file}(${e && e.message ? e.message : e})` }; }
|
|
106
|
+
}
|
|
107
|
+
let parsed;
|
|
108
|
+
try { parsed = JSON.parse(json); } catch (e) { return { stages: null, error: `--preprocess-stages 不是合法 JSON:${e && e.message ? e.message : e}` }; }
|
|
109
|
+
if (!Array.isArray(parsed)) return { stages: null, error: '--preprocess-stages 需要是数组(每项 {command,args?} 或 {provider})' };
|
|
110
|
+
for (let i = 0; i < parsed.length; i += 1) {
|
|
111
|
+
const stageEntry = parsed[i];
|
|
112
|
+
if (!stageEntry || typeof stageEntry !== 'object') return { stages: null, error: `--preprocess-stages 第 ${i + 1} 项不是对象` };
|
|
113
|
+
const hasProvider = !!String(stageEntry.provider || '').trim();
|
|
114
|
+
const hasCommand = !!String(stageEntry.command || '').trim();
|
|
115
|
+
if (hasProvider === hasCommand) return { stages: null, error: `--preprocess-stages 第 ${i + 1} 项必须且只能给 provider 或 command 之一` };
|
|
116
|
+
}
|
|
117
|
+
return { stages: parsed };
|
|
118
|
+
}
|
|
119
|
+
|
|
90
120
|
/** 子命令:commit — 审计门禁 → 提交(默认只 commit 不 push;--push 推远端;--force 强推)。 */
|
|
91
121
|
export async function cmdCommit(root, flags) {
|
|
92
122
|
const repo = root || '';
|
|
93
123
|
if (!repo || !(await pathExists(join(repo, '.git')))) { console.error(`不是 git 仓库: ${repo || '(空)'}`); return 1; }
|
|
94
124
|
if (!String(flags.message || '').trim()) { console.error('缺少 -m <commit message>'); return 1; }
|
|
125
|
+
// 阶段链参数先校验(配置写错要在动 git 之前失败)
|
|
126
|
+
const stageFlag = parsePreprocessStagesFlag(flags.preprocessStages);
|
|
127
|
+
if (stageFlag.error) { console.error(stageFlag.error); return 2; }
|
|
95
128
|
// 推送门禁开关取插件配置(config.json pushGate,与侧边栏同一真源);CLI 未确认时会被拦截
|
|
96
129
|
const cfg = cliPluginConfig();
|
|
97
130
|
// 审计门禁:blocker 拦截(v2 审计独立调用——与 DSH 工具 git_commit_push 同一实现 commitWithAudit)
|
|
@@ -100,13 +133,14 @@ export async function cmdCommit(root, flags) {
|
|
|
100
133
|
message: flags.message,
|
|
101
134
|
push: flags.push === true,
|
|
102
135
|
dryRun: flags.dryRun === true,
|
|
103
|
-
requirementsConfirmed: flags.reqConfirm === true,
|
|
104
136
|
force: flags.force === true,
|
|
105
137
|
// 推送门禁(设置侧边栏开关)——CLI 对应 --push-gate-confirmed(用户已确认)
|
|
106
138
|
pushGate: cfg.pushGate === true,
|
|
107
139
|
pushConfirmed: flags.pushGateConfirmed === true,
|
|
108
140
|
// 精确 add 路径(逗号分隔,相对 repo);空 = git add -A
|
|
109
141
|
paths: String(flags.paths || ''),
|
|
142
|
+
// 本次调用的预处理链(覆盖配置文件里的 preCommit.stages)
|
|
143
|
+
stages: stageFlag.stages,
|
|
110
144
|
});
|
|
111
145
|
if (commitOutcome.blocked) {
|
|
112
146
|
console.error(`审计拦截(${commitOutcome.error || 'blocker'}),提交中止:`);
|
|
@@ -123,10 +157,10 @@ export async function cmdCommit(root, flags) {
|
|
|
123
157
|
|
|
124
158
|
/** 子命令:link-check — 检查文本文件的链接有效性(只 warning,不拦提交)。 */
|
|
125
159
|
export async function cmdLinkCheck(root = '.') {
|
|
126
|
-
const files = (await collectTextFiles(root, { depth: 5 })).filter((f) => /\.(md|markdown|txt)$/i.test(f.path));
|
|
160
|
+
const files = (await await (await auditClient.hostApi()).collectTextFiles(root, { depth: 5 })).filter((f) => /\.(md|markdown|txt)$/i.test(f.path));
|
|
127
161
|
const all = [];
|
|
128
162
|
for (const f of files) {
|
|
129
|
-
const findings = await checkLinks({ file: f.path, text: readText(f.full) });
|
|
163
|
+
const findings = await checkLinks({ file: f.path, text: await (await auditClient.hostApi()).readText(f.full) });
|
|
130
164
|
if (findings.length) all.push(...findings);
|
|
131
165
|
}
|
|
132
166
|
console.log(`链接检查 ${root}(${files.length} 个文档)`);
|