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/commit-push.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-git-push —
|
|
2
|
+
* dsh-git-push — 提交总入口(提交前预处理门禁 + commit + push)
|
|
3
3
|
* dsh-skip-i18n: 插件为中文零依赖,用户可见文案硬编码为产品设计
|
|
4
4
|
*
|
|
5
5
|
* git_commit_push 工具的核心逻辑抽成独立函数:
|
|
@@ -11,20 +11,22 @@
|
|
|
11
11
|
// 审计的结果文案改由「预处理能力」渲染(lib/preprocess/):git 侧只留兜底逻辑与中性默认文案。
|
|
12
12
|
// 为什么 git 侧不再自己生成这份指引:那是**审计措辞**(查询用哪个 API、明细去哪看),
|
|
13
13
|
// 属于审计预处理自己的语义,搬进 lib/preprocess/audit.js 的 renderResult 里。
|
|
14
|
-
import
|
|
14
|
+
import * as auditClient from './app/preprocess-client.js';
|
|
15
15
|
|
|
16
16
|
// 审计内核(auditWithScope / scoreQuality)不再在本文件直接 import —— 提交门禁改为
|
|
17
17
|
// 调「可配置的审计引擎子进程」(lib/commit-push/pre-commit-engine.js),这是解耦点:
|
|
18
18
|
// 换引擎(含换语言重写)只改配置,git 侧零改动。
|
|
19
|
-
// ⚠️
|
|
19
|
+
// ⚠️ 文档漂移检查器的接线也随之搬进引擎入口(审计包 CLI 里 import 一次);
|
|
20
20
|
// 宿主自己的工具/HTTP 侧仍由 lib/app/tool-call.js 接线,不依赖本文件。
|
|
21
|
-
import {
|
|
21
|
+
import { runPreCommitPipeline, resolvePreCommitEnabled } from './commit-push/pre-commit-engine.js';
|
|
22
22
|
import { commitAndPush } from './git/index.js';
|
|
23
23
|
import { defaultConfig } from './client/index.js';
|
|
24
|
-
import { MAX_MSG_PREVIEW } from './app/constants.js';
|
|
25
|
-
import { isSampleExemptDir } from './exempt/index.js';
|
|
26
24
|
import { resolveRepoVisibility } from './git/index.js';
|
|
27
25
|
|
|
26
|
+
/** 拦截清单里单条 message 的截断长度(字符):回执要短,完整内容仍在 audit.findings 里。 */
|
|
27
|
+
const BLOCKED_MESSAGE_PREVIEW_CHARS = 80;
|
|
28
|
+
|
|
29
|
+
|
|
28
30
|
/**
|
|
29
31
|
* 预处理渲染的**兜底文案**(刻意留在 git 侧)。
|
|
30
32
|
*
|
|
@@ -53,52 +55,91 @@ export function defaultPreprocessRender(ctx = {}) {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
|
-
*
|
|
58
|
+
* 同步执行提交前预处理门禁(不跑 git)。供 git_commit_push 后台化方案复用:门禁同步即时
|
|
57
59
|
* 拦截,通过后再把 commit+push 丢后台。返回 { ok, blocked?, error?, audit }。
|
|
58
|
-
*
|
|
60
|
+
* 命名说明:本函数是**预处理通用入口**(审计只是当前唯一的 provider),
|
|
61
|
+
* 返回里的 `audit` 字段是该 provider 的结果体,字段名沿用既有对外契约。
|
|
62
|
+
* @param {object} p { repoPath, audit?, rulesetDir?, cfg?, visibility?, auditExemptPaths?, auditExemptReason? }
|
|
59
63
|
* (删除 auditLevel——审计固定完整流程,不留强度参数)
|
|
60
64
|
* visibility:远端可见性(private|public|unknown)——private 时审计只报告不拦截
|
|
61
65
|
* (README「④ 私有库豁免」);缺省按 origin 探测,探测失败按 unknown(保守拦截)。
|
|
62
66
|
* 显式传入可免网络探测(测试/已知场景)。
|
|
63
67
|
*/
|
|
64
|
-
export async function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// 现在只保留显式传入的 slots(API/工具级白名单);配置里的顺序不再当白名单(禁用请用 auditDisabledSlots ✓)。
|
|
74
|
-
const slotOrder = Array.isArray(slots) && slots.length ? slots : undefined;
|
|
75
|
-
// 修复:提交前审计同样消费侧边栏权重覆盖(cfg.weightOverrides,config.json 回读),
|
|
76
|
-
// 与 code_audit 工具同源——此前传空权重,评分恒用默认权重表(侧边栏权重设置对提交审计无效)。
|
|
77
|
-
// 权重在 git 侧解析(配置语义留在插件侧),再序列化传给引擎:引擎只做「解析 → 用」。
|
|
78
|
-
let auditWeights = {};
|
|
79
|
-
if (typeof cfg.weightOverrides === 'string' && cfg.weightOverrides.trim()) {
|
|
80
|
-
try { auditWeights = JSON.parse(cfg.weightOverrides) || {}; } catch { /* 非法 JSON 回退默认 */ }
|
|
68
|
+
export async function runPreprocess({
|
|
69
|
+
repoPath = '', audit, rulesetDir, cfg: extCfg, visibility: extVisibility,
|
|
70
|
+
auditExemptPaths = [], auditExemptReason = '',
|
|
71
|
+
stages = null, // 本次调用的预处理链(覆盖配置)
|
|
72
|
+
...unknownKeys // 未知参数一律报错:
|
|
73
|
+
}) { // 参数名与工具参数(auditExemptPaths 等)曾不一致,
|
|
74
|
+
const unknown = Object.keys(unknownKeys); // 传错名过去是**静默无效且不报错**(实测踩到),
|
|
75
|
+
if (unknown.length) { // 这个校验把它变成立刻可见的错误。
|
|
76
|
+
throw new Error(`runPreprocess 收到未知参数:${unknown.join(', ')}(可用:repoPath/audit/rulesetDir/cfg/visibility/auditExemptPaths/auditExemptReason/stages)`);
|
|
81
77
|
}
|
|
78
|
+
const cfg = extCfg || defaultConfig();
|
|
79
|
+
// 跑不跑预处理是**宿主自己的门禁策略**(preCommit.enabled);旧版开关键由
|
|
80
|
+
// resolvePreCommitEnabled 一次性读回并标注来源,避免「本来开着的门禁悄悄关掉」。
|
|
81
|
+
const switchState = resolvePreCommitEnabled(cfg);
|
|
82
|
+
const doAudit = audit ?? switchState.enabled;
|
|
83
|
+
// 沿用旧配置键时把来源透出:否则「配置里写着开、实际按新键缺省关」这种偏差
|
|
84
|
+
// 只能靠用户自己发现。只在真的沿用了旧键时才带这个字段(正常路径返回值不变)。
|
|
85
|
+
const preprocessSwitchMeta = switchState.source === 'legacy'
|
|
86
|
+
? { enabledFrom: 'legacy', note: '本次沿用旧版开关键的值;新键为 preCommit.enabled,迁移后旧键可删除' }
|
|
87
|
+
: null;
|
|
88
|
+
if (!doAudit) return { ok: true, audit: null, ...(preprocessSwitchMeta ? { preprocessSwitch: preprocessSwitchMeta } : {}) };
|
|
82
89
|
// ── 解耦点:审计与评分不再在进程内跑,改为调配置化引擎子进程 ──
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
|
|
90
|
+
// 这次调用只传「宿主才知道的调用上下文」:仓库路径 / 可见性 / 本次临时豁免。
|
|
91
|
+
// **不传审计自己的配置**(扫描范围 / 权重 / 规则槽位 / 文件数上限)——
|
|
92
|
+
// 那些已随分家搬进预处理实现自己的 config.json,由它读自己的配置当默认值。
|
|
93
|
+
// 宿主一旦还替它传,就等于两包仍在共享一份配置(耦合),只是换了个字段名而已。
|
|
94
|
+
const engineRes = await runPreCommitPipeline({
|
|
87
95
|
repoPath: repoPath || '.',
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
rulesetDir: rulesetDir || '', // 调用方显式指定的规则目录(工具 ruleset 参数),不是配置
|
|
97
|
+
// 可见性:显式传入时直接给引擎;未传则留空(引擎按 unknown 保守处理,gitpush 稍后按需探测)
|
|
98
|
+
visibility: extVisibility,
|
|
99
|
+
// 临时豁免:**参数名映射**(工具参数 auditExemptPaths → 审计包 --exempt-paths)
|
|
100
|
+
exemptPaths: Array.isArray(auditExemptPaths) ? auditExemptPaths : [],
|
|
101
|
+
exemptReason: auditExemptReason || '',
|
|
102
|
+
stages: Array.isArray(stages) && stages.length ? stages : null, // 调用参数 > 配置(见 resolveStages)
|
|
94
103
|
cfg,
|
|
95
104
|
});
|
|
96
105
|
// 引擎不可用(崩/超时/退出码 2/输出不合契约)一律 fail-closed:拒绝提交并给出可诊断原因。
|
|
97
106
|
// 绝不在这里「当作没有 blocker 放行」——那等于把红线交给「恰好没跑起来」。
|
|
98
|
-
|
|
107
|
+
// 例外:预处理实现不在位(preprocessSkipped)——那是「扩展没插」,不是「引擎坏了」。
|
|
108
|
+
// 按热插拔语义放行主流程,但必须把「本次未做预处理」透出给调用方(不静默)。
|
|
109
|
+
// 字段名刻意用 preprocess* 而不是 audit*:预处理是通用机制,审计只是它的一个实现。
|
|
110
|
+
// 阶段链的 additive 回执(只有配了 preCommit.stages 才会有这两个字段;
|
|
111
|
+
// 单命令/单阶段模式不追加任何字段 ⇒ 与升级前逐字段一致)
|
|
112
|
+
const stageMeta = {
|
|
113
|
+
...(Array.isArray(engineRes.preprocessStages) ? { preprocessStages: engineRes.preprocessStages } : {}),
|
|
114
|
+
...(Array.isArray(engineRes.preprocessWarnings) && engineRes.preprocessWarnings.length
|
|
115
|
+
? { preprocessWarnings: engineRes.preprocessWarnings } : {}),
|
|
116
|
+
};
|
|
117
|
+
if (!engineRes.ok) {
|
|
118
|
+
return {
|
|
119
|
+
ok: false,
|
|
120
|
+
blocked: false,
|
|
121
|
+
error: engineRes.error,
|
|
122
|
+
audit: null,
|
|
123
|
+
// 失败在被拦的那个阶段之前可能已经跑过几个阶段(例如 format 成功、audit 崩了):
|
|
124
|
+
// 把已跑阶段的回执带上,用户才知道"哪些阶段做过事"
|
|
125
|
+
...(Object.keys(stageMeta).length ? { preprocessStages: stageMeta.preprocessStages || [], ...(stageMeta.preprocessWarnings ? { preprocessWarnings: stageMeta.preprocessWarnings } : {}) } : {}),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (engineRes.preprocessSkipped) {
|
|
129
|
+
return {
|
|
130
|
+
ok: true,
|
|
131
|
+
blocked: false,
|
|
132
|
+
audit: null,
|
|
133
|
+
preprocessSkipped: engineRes.preprocessSkipped,
|
|
134
|
+
skipReason: engineRes.skipReason || '',
|
|
135
|
+
...stageMeta,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
99
138
|
const engineAudit = engineRes.audit || {};
|
|
100
139
|
const findings = Array.isArray(engineAudit.findings) ? engineAudit.findings : [];
|
|
101
140
|
const auditOut = {
|
|
141
|
+
// 阶段链回执(additive):每个阶段跑了多久、成败、onFail 语义、跳过的原因
|
|
142
|
+
...stageMeta,
|
|
102
143
|
summary: engineAudit.summary,
|
|
103
144
|
quality: engineAudit.quality,
|
|
104
145
|
// 引擎溯源(新增字段,只增不改):出问题时能一眼看到「用的哪个引擎、退出码几」,
|
|
@@ -109,27 +150,47 @@ export async function runAudit({ repoPath = '', audit, rulesetDir, slots, cfg: e
|
|
|
109
150
|
blocked: engineRes.engine?.exitCode === 1,
|
|
110
151
|
},
|
|
111
152
|
};
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
153
|
+
// ── 拦截结论:**直接用审计包的**(拆包后它才是权威)──
|
|
154
|
+
// 豁免四类(代码标记 / 测试夹具 / 示例目录 / 临时豁免)加私有库降级都在包内完成,
|
|
155
|
+
// gitpush 这层不再重复实现一遍 —— 两份实现并存时最危险的是「某一天两边算得不一样」,
|
|
156
|
+
// 而那时门禁到底拦不拦取决于走了哪条分支,几乎无法排查。
|
|
157
|
+
// 拦截结论**只认审计包的**:宿主不再有第二套豁免/拦截实现
|
|
158
|
+
auditOut.blocked = Array.isArray(engineAudit.blocked) ? engineAudit.blocked : [];
|
|
159
|
+
// 示例目录豁免条数(summary.blocker 与 blocked 的差值来源之一),原样透传供排查
|
|
160
|
+
if (Number.isFinite(Number(engineAudit.sampleExemptCount))) auditOut.sampleExemptCount = Number(engineAudit.sampleExemptCount);
|
|
161
|
+
// exempt 回显:审计包自己给;它没给时这里按同一语义构造(记录而非判断:
|
|
162
|
+
// 豁免了哪些文件、命中哪些规则、共几条 finding),保证回显字段不因实现更换而消失。
|
|
163
|
+
if (engineAudit.exempt) {
|
|
164
|
+
auditOut.exempt = engineAudit.exempt;
|
|
165
|
+
} else {
|
|
166
|
+
const exemptSet = new Set((Array.isArray(auditExemptPaths) ? auditExemptPaths : [])
|
|
167
|
+
.map((value) => String(value || '').replace(/\\/g, '/').replace(/^\.\//, '').trim())
|
|
168
|
+
.filter(Boolean));
|
|
169
|
+
if (exemptSet.size) {
|
|
170
|
+
const isExemptFile = (finding) => exemptSet.has(String(finding.file || '').replace(/\\/g, '/').replace(/^\.\//, ''));
|
|
171
|
+
const exemptFindings = findings.filter(isExemptFile);
|
|
172
|
+
auditOut.exempt = {
|
|
173
|
+
files: [...exemptSet],
|
|
174
|
+
count: exemptFindings.length,
|
|
175
|
+
rules: [...new Set(exemptFindings.map((finding) => finding.rule).filter(Boolean))],
|
|
176
|
+
...(auditExemptReason ? { reason: String(auditExemptReason) } : {}),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (engineAudit.privateExempt) {
|
|
181
|
+
auditOut.privateExempt = engineAudit.privateExempt;
|
|
182
|
+
// 私有库时审计包把结论归零(blocked: [],理由见批 B 契约);但**对外形态保持旧样**:
|
|
183
|
+
// `audit.blocked` 历来是「报告用的原始清单」(audit-api / code_audit / 报告都读它),
|
|
184
|
+
// 归零会让这些消费方以为「这个私有库一条问题都没有」,丢掉「本来有几条会拦」的可观测性。
|
|
185
|
+
// 拦截结论由 `ok` / `blocked` 布尔表达(私有库恒 false/true),清单只作报告。
|
|
186
|
+
if (!Array.isArray(engineAudit.blocked) || engineAudit.blocked.length === 0) {
|
|
187
|
+
// 私有库时包把 blocked 归零,但报告形态仍给原始清单(租户侧读取 audit.blocked 展示)
|
|
188
|
+
auditOut.blocked = findings.filter((f) => f.severity === 'blocker' || f.severity === 'error')
|
|
189
|
+
.map((f) => ({ file: f.file, line: f.line, rule: f.rule, message: String(f.message || '').slice(0, BLOCKED_MESSAGE_PREVIEW_CHARS) }));
|
|
190
|
+
}
|
|
132
191
|
}
|
|
192
|
+
const blocked = auditOut.blocked;
|
|
193
|
+
|
|
133
194
|
// ── 结果文案:交给「可用预处理」渲染,git 侧只保留兜底 ──
|
|
134
195
|
// 数据契约(ctx):repoPath + audit{summary,quality,findings,scope,files} + blocked + exempt
|
|
135
196
|
// 兜底:预处理不可用 / 没实现 renderResult / 渲染抛错 时用中性默认(defaultRenderResult),
|
|
@@ -147,11 +208,11 @@ export async function runAudit({ repoPath = '', audit, rulesetDir, slots, cfg: e
|
|
|
147
208
|
...(auditOut.exempt ? { exempt: auditOut.exempt } : {}),
|
|
148
209
|
};
|
|
149
210
|
const fallbackRender = defaultPreprocessRender(renderCtx);
|
|
150
|
-
const rendered =
|
|
211
|
+
const rendered = await (async () => { try { const api = await auditClient.hostApi(); return api.renderAuditResult(renderCtx, cfg); } catch { return undefined; } })();
|
|
151
212
|
auditOut.apiGuide = rendered?.apiGuide ?? fallbackRender.apiGuide;
|
|
152
213
|
if (auditOut.exempt) auditOut.exempt.note = rendered?.notes?.exempt ?? fallbackRender.notes.exempt;
|
|
153
214
|
|
|
154
|
-
if (blocked.length > 0) {
|
|
215
|
+
if (blocked.length > 0 && !auditOut.privateExempt) {
|
|
155
216
|
// 【修复】私有库豁免(README「④ 私有库豁免」):远端可见性 = private → 审计只报告不拦截。
|
|
156
217
|
// 修复背景:私有库被拦的回归——
|
|
157
218
|
// 此前拦截判定只看「示例目录」、没有可见性分级,
|
|
@@ -192,7 +253,7 @@ export async function runAudit({ repoPath = '', audit, rulesetDir, slots, cfg: e
|
|
|
192
253
|
* 带审计门禁的提交推送(git_commit_push 工具旧同步实现,仍保留供外部插件/批量复用)。
|
|
193
254
|
* @param {object} p
|
|
194
255
|
* { repoPath, message, push?, dryRun?, audit?, rulesetDir? }
|
|
195
|
-
* audit
|
|
256
|
+
* audit 缺省取预处理开关(preCommit.enabled);rulesetDir 只认显式传参。
|
|
196
257
|
* @returns {Promise<object>} 审计放行 → commitAndPush 结果(含 audit 摘要);
|
|
197
258
|
* blocker 命中 → { ok:false, blocked:true, audit },不执行 git 操作
|
|
198
259
|
*/
|
|
@@ -203,36 +264,35 @@ export async function commitWithAudit({
|
|
|
203
264
|
dryRun = false,
|
|
204
265
|
audit,
|
|
205
266
|
rulesetDir,
|
|
206
|
-
slots,
|
|
207
267
|
customIgnorePatterns = '',
|
|
208
|
-
requirementsConfirmed = false,
|
|
209
268
|
force = false,
|
|
210
269
|
pushMethod,
|
|
211
270
|
pushGate = false,
|
|
212
271
|
pushConfirmed = false,
|
|
213
272
|
paths = '', // 精确 add 路径(逗号分隔,相对 repoPath);空 = git add -A
|
|
273
|
+
stages = null, // 本次调用的预处理链(覆盖配置里的 preCommit.stages)
|
|
214
274
|
} = {}) {
|
|
215
275
|
const cfg = defaultConfig();
|
|
216
|
-
const a = await
|
|
217
|
-
// blocked 用
|
|
276
|
+
const a = await runPreprocess({ repoPath, audit, rulesetDir, stages });
|
|
277
|
+
// blocked 用 runPreprocess 的真实结论(缺省仍按拦截处理):
|
|
218
278
|
// 审计判定拦截 = true;引擎不可用 = false(那是「没跑起来」,不是「审计不通过」,
|
|
219
279
|
// 工具侧据此显示「未完成:<原因>」而不是「推送被拦截」)。
|
|
220
280
|
if (!a.ok) return { ok: false, blocked: a.blocked ?? true, error: a.error, audit: a.audit };
|
|
221
281
|
// 推送通道缺省取插件配置(默认 ssh:推本地 HEAD、远端 sha 与本地一致)
|
|
222
|
-
const r = await commitAndPush({ repoPath, message, push, dryRun, customIgnorePatterns,
|
|
282
|
+
const r = await commitAndPush({ repoPath, message, push, dryRun, customIgnorePatterns, force, pushMethod: pushMethod || cfg.pushMethod || 'ssh', pushGate, pushConfirmed, paths });
|
|
223
283
|
return { ok: r.ok !== false, ...r, audit: a.audit };
|
|
224
284
|
}
|
|
225
285
|
|
|
226
286
|
/**
|
|
227
287
|
* 批量提交推送(D16 commitMany):对每个仓库依次 commitAndPush,返回逐仓结果数组。
|
|
228
288
|
* 注意:仅做提交推送(不含审计门禁)——审计请用 commitWithAudit 逐仓调用。
|
|
229
|
-
* @param {{repos: string[], message: string, push?: boolean, dryRun?: boolean,
|
|
289
|
+
* @param {{repos: string[], message: string, push?: boolean, dryRun?: boolean, customIgnorePatterns?: string}} opts
|
|
230
290
|
* @returns {Promise<Array<{repo: string, ...commitAndPush 结果}>>}
|
|
231
291
|
*/
|
|
232
|
-
export async function commitMany({ repos = [], message = '', push = true, dryRun = false,
|
|
292
|
+
export async function commitMany({ repos = [], message = '', push = true, dryRun = false, customIgnorePatterns = '' } = {}) {
|
|
233
293
|
const results = [];
|
|
234
294
|
for (const repoPath of repos) {
|
|
235
|
-
results.push({ repo: repoPath, ...(await commitAndPush({ repoPath, message, push, dryRun, customIgnorePatterns
|
|
295
|
+
results.push({ repo: repoPath, ...(await commitAndPush({ repoPath, message, push, dryRun, customIgnorePatterns })) });
|
|
236
296
|
}
|
|
237
297
|
return results;
|
|
238
298
|
}
|
package/lib/context/index.js
CHANGED
|
@@ -22,12 +22,14 @@ const PROBE_TIMEOUT_MS = 8000; // 工具路径/版本探测子进程超时
|
|
|
22
22
|
const VERSION_MAX_LEN = 120; // 版本串截断长度
|
|
23
23
|
|
|
24
24
|
/** 默认工具清单(探测失败时的静态兜底;探测成功以实测路径为准)。 */
|
|
25
|
+
// 静态兜底清单(探测失败时用):只写**命令名**,不写任何安装位置 ——
|
|
26
|
+
// 写死的绝对路径换机即失效,且在 Windows/容器里根本不存在。
|
|
25
27
|
export const DEFAULT_TOOLS = {
|
|
26
|
-
git: '
|
|
27
|
-
node: '
|
|
28
|
-
npm: '
|
|
29
|
-
python3: '
|
|
30
|
-
curl: '
|
|
28
|
+
git: 'git',
|
|
29
|
+
node: 'node',
|
|
30
|
+
npm: 'npm',
|
|
31
|
+
python3: 'python3',
|
|
32
|
+
curl: 'curl',
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
/** 默认探测的工具清单(名称 → 版本参数;null 表示只查路径)。 */
|
package/lib/core/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Git 执行层 · 路径与配置
|
|
3
3
|
*
|
|
4
|
-
* 职责:插件根目录定位(PLUGIN_ROOT
|
|
4
|
+
* 职责:插件根目录定位(PLUGIN_ROOT)。
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { existsSync, readFileSync } from 'node:fs';
|
|
@@ -12,29 +12,3 @@ import { credentialsDir } from './credentials.js';
|
|
|
12
12
|
/** 插件根(lib/git/index.js → lib → 插件根;requirements.json 内置清单定位用)。 */
|
|
13
13
|
export const PLUGIN_ROOT = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* 开发者特殊要求清单(D13):
|
|
17
|
-
* 三来源依次尝试(首个有效即返回):
|
|
18
|
-
* 1) credentialsDir()/requirements.json(用户外挂)
|
|
19
|
-
* 2) PLUGIN_ROOT/lib/user-requirements.json(内置默认清单)
|
|
20
|
-
* 3) PLUGIN_ROOT/user-requirements.json
|
|
21
|
-
* 返回 { user, found, items, files };无清单时 found:false(门禁放行)。
|
|
22
|
-
*/
|
|
23
|
-
export function loadRequirements() {
|
|
24
|
-
const candidates = [
|
|
25
|
-
join(credentialsDir(), 'requirements.json'),
|
|
26
|
-
join(PLUGIN_ROOT, 'lib', 'user-requirements.json'),
|
|
27
|
-
join(PLUGIN_ROOT, 'user-requirements.json'),
|
|
28
|
-
];
|
|
29
|
-
for (const f of candidates) {
|
|
30
|
-
try {
|
|
31
|
-
if (!f || !existsSync(f)) continue;
|
|
32
|
-
const parsed = JSON.parse(readFileSync(f, 'utf8'));
|
|
33
|
-
const items = Array.isArray(parsed?.items) ? parsed.items.map((x) => String(x).trim()).filter(Boolean) : [];
|
|
34
|
-
if (items.length) {
|
|
35
|
-
return { user: String(parsed.user || '') || '默认开发者', found: true, items, files: [{ file: f, items }] };
|
|
36
|
-
}
|
|
37
|
-
} catch { /* 坏 JSON 换下一来源 */ }
|
|
38
|
-
}
|
|
39
|
-
return { user: '默认开发者', found: false, items: [], files: [] };
|
|
40
|
-
}
|
package/lib/core/exec.js
CHANGED
|
@@ -22,14 +22,6 @@ import { delimiter as pathDelimiter, join } from 'node:path';
|
|
|
22
22
|
* 改为显式解析 + 明确的缺失提示,避免同类误诊。
|
|
23
23
|
* 优先级:DSH_GIT_BIN 环境变量 → PATH 各目录 → 常见绝对路径。
|
|
24
24
|
*/
|
|
25
|
-
const GIT_CANDIDATES = [
|
|
26
|
-
// POSIX 常见位置
|
|
27
|
-
'/var/packages/git/target/bin/git', '/usr/local/bin/git', '/usr/bin/git', '/bin/git',
|
|
28
|
-
// Windows 常见安装位置(Git for Windows 的 cmd\ 目录;PATH 未配置时兜底)
|
|
29
|
-
'C:\\Program Files\\Git\\cmd\\git.exe',
|
|
30
|
-
'C:\\Program Files (x86)\\Git\\cmd\\git.exe',
|
|
31
|
-
];
|
|
32
|
-
|
|
33
25
|
/**
|
|
34
26
|
* 组装「到哪找 git」的搜索计划(纯函数,便于跨平台单测)。
|
|
35
27
|
*
|
|
@@ -63,9 +55,8 @@ export function resolveGitBin() {
|
|
|
63
55
|
try { if (existsSync(p) && statSync(p).isFile()) { _gitBin = p; return _gitBin; } } catch { /* 继续找 */ }
|
|
64
56
|
}
|
|
65
57
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
58
|
+
// 刻意**不写死**任何安装位置:写死的路径在换机/换平台后必然失效,还会悄悄指向错的可执行文件。
|
|
59
|
+
// 找不到就返回空串,由 GIT_MISSING_MSG 给出可操作的修复方式(加入 PATH 或用 DSH_GIT_BIN 指定)。
|
|
69
60
|
_gitBin = '';
|
|
70
61
|
return _gitBin;
|
|
71
62
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 豁免标记与目录判定的**宿主侧快照**(权威定义在审计包 lib/exempt/index.js)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要快照:git 侧的 .gitignore 与敏感文件扫描在**同步**路径上要判「某标记能否豁免该 finding」
|
|
5
|
+
* 以及「该目录是否示例/测试夹具」,而审计包只能异步加载。整文件复制而非零散搬运——
|
|
6
|
+
* 零散搬运漏一个私有辅助函数就会在运行时炸(本文件第一版就因为漏了缓存辅助而报错)。
|
|
7
|
+
* 由 test/git/test-exempt-markers-parity.mjs 对拍:包与快照行为分叉即红。
|
|
8
|
+
*/
|
|
2
9
|
import { join, resolve, dirname, sep } from 'node:path';
|
|
3
10
|
import { statSync } from 'node:fs';
|
|
4
11
|
/**
|
|
@@ -239,7 +239,7 @@ export function rewriteIdentities(repoPaths = [], opts = {}) {
|
|
|
239
239
|
* 仓库历史里**遗留的**非规范身份统计(只报告,不改任何东西)。
|
|
240
240
|
*
|
|
241
241
|
* 用途:提交时顺带提醒「以前」留下的身份问题 —— 自动提交只要带正确身份即可,
|
|
242
|
-
*
|
|
242
|
+
* 历史是否统一属于使用者的判断,所以这里只给出「还有多少条、都是谁」,不做任何改写。
|
|
243
243
|
* @param {string} repoPath 仓库路径
|
|
244
244
|
* @param {{runGit:Function, wrongEmails?:string[], branch?:string}} opts
|
|
245
245
|
* @returns {{count:number, emails:string[]}}
|
package/lib/git/ignore.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
|
-
import { isSampleExemptDir } from '
|
|
9
|
+
import { isSampleExemptDir } from './exempt-markers.js';
|
|
10
10
|
import { scanSensitiveFiles } from './sensitive.js';
|
|
11
11
|
|
|
12
12
|
/**
|
package/lib/git/index.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
export { runGit, runGitAsync, gitRaw } from './exec.js';
|
|
25
|
-
export { PLUGIN_ROOT
|
|
25
|
+
export { PLUGIN_ROOT } from './config.js';
|
|
26
26
|
export { credentialsDir, resolveSshKey, resolveToken, maskToken, readSshPub, persistGithubToken, persistSshPub, persistNpmToken, readNpmToken, generateSshKey } from './credentials.js';
|
|
27
27
|
export { GH_API, githubFetch, parseGithubOwnerRepo, isBadCredentials, detectRepoVisibility } from './api.js';
|
|
28
28
|
export { resolveRepoVisibility } from './visibility.js';
|
package/lib/git/push.js
CHANGED
|
@@ -11,7 +11,6 @@ import { waitForCi } from './ci.js';
|
|
|
11
11
|
import { existsSync } from 'node:fs';
|
|
12
12
|
import { join } from 'node:path';
|
|
13
13
|
import { autoTagDSHProject, ensureAuxSshRemote, readPkgVersion, updateRemoteTrackingRef } from './post-push.js';
|
|
14
|
-
import { loadRequirements } from './config.js';
|
|
15
14
|
import { resolveSshKeys, resolveToken } from './credentials.js';
|
|
16
15
|
import { runGit } from './exec.js';
|
|
17
16
|
import { buildWrappedGitEnv } from './wrapped-git.js';
|
|
@@ -58,12 +57,12 @@ import { resolveRepoVisibility, cachedVisibility } from './visibility.js';
|
|
|
58
57
|
*/
|
|
59
58
|
export async function commitAndPush({
|
|
60
59
|
repoPath = '', message = '', messageItems = null, push = true, dryRun = false, token = '',
|
|
61
|
-
customIgnorePatterns = '',
|
|
60
|
+
customIgnorePatterns = '', force = false, pushMethod = 'ssh',
|
|
62
61
|
pushGate = false, pushConfirmed = false, paths = '', remote = '',
|
|
63
62
|
// 推送后是否等 CI 结果(默认不等:多数推送不需要阻塞);ciTimeoutSec 为等待上限
|
|
64
63
|
waitCi = false, ciTimeoutSec = 900,
|
|
65
64
|
// 敏感文件扫描是否执行:**与审计同一开关**(audit 关 ⇒ 不扫),不再享有「强制全仓」特权。
|
|
66
|
-
// 缺省 true
|
|
65
|
+
// 缺省 true 供直接调用方(CLI/测试)使用;工具路径由 tool-call 按预处理开关显式传入。
|
|
67
66
|
scanSensitive = true,
|
|
68
67
|
} = {}) {
|
|
69
68
|
const steps = [];
|
|
@@ -80,20 +79,6 @@ export async function commitAndPush({
|
|
|
80
79
|
const built = buildCommitMessage(msgInput);
|
|
81
80
|
if (!built.ok) return { ok: false, steps: ['预检'], error: built.error };
|
|
82
81
|
const commitMessage = built.message;
|
|
83
|
-
// D13 开发者要求门禁(commitPushPreflight 语义):要求清单存在且未核对 → 拦截。
|
|
84
|
-
// 清单来源:credentialsDir()/requirements.json(外挂)→ PLUGIN_ROOT/lib/user-requirements.json(内置)。
|
|
85
|
-
const userReqs = loadRequirements();
|
|
86
|
-
if (userReqs.found && userReqs.items?.length && !requirementsConfirmed) {
|
|
87
|
-
return {
|
|
88
|
-
ok: false,
|
|
89
|
-
blocked: true,
|
|
90
|
-
code: 'USER_REQUIREMENTS',
|
|
91
|
-
steps: ['预检'],
|
|
92
|
-
error: '开发者特殊要求未核对:AI 需先逐条核对要求全部达标,再带 requirementsConfirmed:true 重新调用',
|
|
93
|
-
requirements: userReqs,
|
|
94
|
-
repo: repoPath,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
82
|
// D14 detached HEAD 防护(commitPushPreflight 语义):HEAD 处于 detached 状态时拒绝提交,
|
|
98
83
|
// 避免在无分支的游离 HEAD 上 commit 后无法推送(v1: 'HEAD 处于 detached 状态,请先 checkout 分支')
|
|
99
84
|
// ⚠ 必须区分「git 调用失败」与「真的是游离 HEAD」:此前只看 stdout,git 因 PATH 缺 git /
|
package/lib/git/repo-index.js
CHANGED
|
@@ -72,6 +72,8 @@ export function readRepoIndexMap(workspaceRoot) {
|
|
|
72
72
|
remoteHeadAt: r.remoteHeadAt || '',
|
|
73
73
|
synced: !!r.synced,
|
|
74
74
|
remoteStateAt: r.remoteStateAt || '',
|
|
75
|
+
// 本地状态快照(分支/未提交数/最近提交 + 采集时间)——列表请求的零 spawn 数据源
|
|
76
|
+
localState: (r.localState && typeof r.localState === 'object') ? r.localState : null,
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
79
|
return map;
|
|
@@ -369,14 +371,14 @@ function mergeFreshIntoExisting(existing, freshContent) {
|
|
|
369
371
|
* syncTarget, offline, maxRepos, mode, cloudRepos, repoName, remoteState }
|
|
370
372
|
* @returns {Promise<{ok:boolean, indexUpdated:boolean, target?:string, updated?:number, error?:string}>}
|
|
371
373
|
*/
|
|
372
|
-
export async function updateRepoIndex({ workspaceRoot = '', token = '', owner = 'EIGHTfs', depth = 20, extraRepos = [], extraReposFile = '', syncTarget = '', offline = false, maxRepos = 200, mode = 'rebuild', cloudRepos = [], repoName = '', remoteState = {} } = {}) {
|
|
374
|
+
export async function updateRepoIndex({ workspaceRoot = '', token = '', owner = 'EIGHTfs', depth = 20, extraRepos = [], extraReposFile = '', syncTarget = '', offline = false, maxRepos = 200, mode = 'rebuild', cloudRepos = [], repoName = '', remoteState = {}, localState = null } = {}) {
|
|
373
375
|
try {
|
|
374
376
|
if (mode === 'merge-cloud') {
|
|
375
377
|
const r = mergeCloudReposIntoIndex({ workspaceRoot, owner, cloudRepos, syncTarget });
|
|
376
378
|
return { ...r, indexUpdated: r.ok === true };
|
|
377
379
|
}
|
|
378
380
|
if (mode === 'single') {
|
|
379
|
-
const r = updateRepoRemoteStateInIndex({ workspaceRoot, repoName, remoteState, syncTarget });
|
|
381
|
+
const r = updateRepoRemoteStateInIndex({ workspaceRoot, repoName, remoteState, localState, syncTarget });
|
|
380
382
|
return { ...r, indexUpdated: r.ok === true };
|
|
381
383
|
}
|
|
382
384
|
// rebuild(默认):全量重建 → 与现有索引合并(不全量覆盖)
|
|
@@ -494,7 +496,7 @@ export function mergeCloudReposIntoIndex({ workspaceRoot = '', owner = 'EIGHTfs'
|
|
|
494
496
|
* visibility 传空/未传 = 不改动既有值(避免把已知可见性抹成「未知」)
|
|
495
497
|
* @returns {{ok:boolean, target?:string, error?}}
|
|
496
498
|
*/
|
|
497
|
-
export function updateRepoRemoteStateInIndex({ workspaceRoot = '', repoName = '', remoteState = {}, syncTarget = '' } = {}) {
|
|
499
|
+
export function updateRepoRemoteStateInIndex({ workspaceRoot = '', repoName = '', remoteState = {}, localState = null, syncTarget = '' } = {}) {
|
|
498
500
|
try {
|
|
499
501
|
const target = syncTarget || locateRepoIndex(workspaceRoot) || join(credentialsDir({ workspaceRoot: workspaceRoot || '' }), INDEX_FILE);
|
|
500
502
|
let index = null;
|
|
@@ -514,6 +516,9 @@ export function updateRepoRemoteStateInIndex({ workspaceRoot = '', repoName = ''
|
|
|
514
516
|
// 直接写会把云端扫描/手工标注得到的好值抹掉。
|
|
515
517
|
if (visibility) hit.visibility = visibility;
|
|
516
518
|
hit.remoteStateAt = new Date().toISOString();
|
|
519
|
+
// 本地状态(分支/未提交数/最近提交)一并缓存:列表请求据此零 spawn 渲染,
|
|
520
|
+
// 不必每仓 describeRepo + git log(CIFS 上每仓 ≈4 次慢 spawn)。
|
|
521
|
+
if (localState && typeof localState === 'object') hit.localState = localState;
|
|
517
522
|
index.generatedAt = new Date().toISOString();
|
|
518
523
|
const written = syncRepoIndex({ content: serializeIndex(index), workspaceRoot, owner: index.owner || 'EIGHTfs', syncTarget });
|
|
519
524
|
return { ok: true, ...written };
|
package/lib/git/repos.js
CHANGED
|
@@ -11,8 +11,8 @@ import { runGit, runGitAsync } from './exec.js';
|
|
|
11
11
|
|
|
12
12
|
/* ───────── 仓库扫描常量 ───────── */
|
|
13
13
|
const LS_IGNORED_TIMEOUT_MS = 15_000; // git ls-files --ignored 超时
|
|
14
|
-
// 扫描下钻深度默认值:与 lib/plugin/auto-push.js 共用同一来源(lib/
|
|
15
|
-
import { DEFAULT_SCAN_DEPTH } from '
|
|
14
|
+
// 扫描下钻深度默认值:与 lib/plugin/auto-push.js 共用同一来源(lib/git/defaults.js)
|
|
15
|
+
import { DEFAULT_SCAN_DEPTH } from './defaults.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* 扫描目录下的 git 仓库(1.0.0 接线:git_scan 工具用)。
|
package/lib/git/sensitive.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
|
-
import { isTestExemptDir } from '
|
|
11
|
+
import { isTestExemptDir } from './exempt-markers.js';
|
|
12
12
|
import { getSkipSet } from '../skip-dirs.js';
|
|
13
13
|
|
|
14
14
|
/* ───────────────────────── 敏感文件自动 .gitignore ───────────────────────── */
|
package/lib/npm/install.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* npm 安装编排(Step 3):校验 → 加锁 → 调 npm install → 回执 + 日志留痕。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 安全默认:**默认加 `--ignore-scripts`**(装包会执行 postinstall 任意代码),
|
|
5
5
|
* UI 必须显式勾选才关闭;默认**不全局**(避免污染宿主 node 环境),全局需显式勾选;
|
|
6
6
|
* registry 与凭据一律走我们自己的 npmrc(--userconfig),不碰用户全局配置。
|
|
7
7
|
*/
|
package/lib/npm/publish.js
CHANGED
|
@@ -7,12 +7,13 @@
|
|
|
7
7
|
* ③ 真发前先体检:`private:true` 拦截、同名版本占用检测、`npm pack --dry-run` 文件清单。
|
|
8
8
|
* 凭据:一律 `--userconfig` 指向插件物化的 0600 npmrc(不碰用户全局 ~/.npmrc、token 不进仓库)。
|
|
9
9
|
*/
|
|
10
|
-
import { appendFileSync, existsSync, readFileSync, statSync } from 'node:fs';
|
|
10
|
+
import { appendFileSync, existsSync, mkdtempSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { tmpdir } from 'node:os';
|
|
11
12
|
import { join } from 'node:path';
|
|
12
13
|
|
|
13
14
|
import { credentialsDir, readNpmToken } from '../core/credentials.js';
|
|
14
15
|
import { DEFAULT_REGISTRY, NPM_TIMEOUT_MS, normalizeRegistry, runNpm } from './registry.js';
|
|
15
|
-
import { npmArgs, writeNpmrc } from './npmrc.js';
|
|
16
|
+
import { npmArgs, npmrcText, writeNpmrc } from './npmrc.js';
|
|
16
17
|
import { smokeTestPackage, entrySpecsOf, isBrowserEntry, classifyPackageForm } from './smoke.js';
|
|
17
18
|
import { runLocalPreview } from './local-registry.js';
|
|
18
19
|
|
|
@@ -109,7 +110,14 @@ export function parsePackOutput(text = '', { maxCandidates = 200 } = {}) {
|
|
|
109
110
|
export function packDryRun({ dir, registry = DEFAULT_REGISTRY, workspaceRoot = '', token = '', timeoutMs = PUBLISH_TIMEOUT_MS } = {}) {
|
|
110
111
|
try {
|
|
111
112
|
const merged = { ...process.env };
|
|
112
|
-
|
|
113
|
+
// **不能写真实凭据目录的 npmrc**:writeNpmrc 写的是 credentialsDir 下的**持久**文件,
|
|
114
|
+
// 而本函数只是「预演」——用预演覆盖真实 npmrc 会把用户的真 token 冲掉。
|
|
115
|
+
// 实测事故:本地彩排跑完后 npmrc 变成临时 token(11 字符)⇒ 之后所有 npm 命令 401。
|
|
116
|
+
// 预演只需要一份**临时** npmrc,写到临时目录、用完即弃。
|
|
117
|
+
const tempDir = mkdtempSync(join(tmpdir(), 'dshgp-pack-'));
|
|
118
|
+
const tempRc = join(tempDir, '.npmrc');
|
|
119
|
+
writeFileSync(tempRc, npmrcText({ registry, token }), { mode: 0o600 });
|
|
120
|
+
const rc = { ok: true, file: tempRc };
|
|
113
121
|
if (!rc.ok) return { ok: false, error: rc.error || 'npmrc 写入失败' };
|
|
114
122
|
// cwd 必须显式给:npm pack 以「工作目录」为目标包,继承宿主 cwd 会去错目录
|
|
115
123
|
// (实测:宿主 cwd 无 package.json ⇒ ENOENT;有 ⇒ 打包整棵树 ⇒ ENOBUFS)
|
|
@@ -184,8 +192,15 @@ export async function publishPackage({
|
|
|
184
192
|
// 体检①:private:true 会被 npm 拒绝(提前给结论,省一次网络)
|
|
185
193
|
if (info.private) return { ok: false, blocked: 'private-true', name: info.name, version: info.version, error: 'package.json 标了 private:true ⇒ npm publish 会被拒绝(去掉该字段或改用私有 registry)' };
|
|
186
194
|
// 体检②:同名版本是否已存在
|
|
187
|
-
|
|
188
|
-
|
|
195
|
+
// **网络边界**:这一步是 GET 真实上游 registry(只读,不写入)。
|
|
196
|
+
// localPreview=true 时**跳过**——本地 registry 是空的,「版本占用」无从判断也无意义;
|
|
197
|
+
// 跳过之后整条链路(publish → install → 加载)全程不碰公网。
|
|
198
|
+
let versionTaken = false;
|
|
199
|
+
let pub = { ok: false, versions: [] };
|
|
200
|
+
if (!localPreview) {
|
|
201
|
+
pub = await fetchPublishedVersions({ name: info.name, registry: reg, timeoutMs: NPM_TIMEOUT_MS });
|
|
202
|
+
versionTaken = pub.ok && pub.versions.includes(info.version);
|
|
203
|
+
}
|
|
189
204
|
if (versionTaken) {
|
|
190
205
|
return { ok: false, blocked: 'version-taken', name: info.name, version: info.version, versions: pub.versions, error: `${info.name}@${info.version} 已存在于 registry ⇒ 先升版本号再发` };
|
|
191
206
|
}
|
package/lib/npm/registry.js
CHANGED
|
@@ -42,12 +42,12 @@ export function resolveNpmBin({ env = process.env } = {}) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
const nodeDir = dirname(String(process.execPath || ''));
|
|
45
|
+
// 只查「node 可执行文件旁边」这些位置:node 装在哪,npm 就在哪附近 —— 这比写死
|
|
46
|
+
// /usr/bin、/usr/local/bin 更可靠(换机/容器/Windows 都成立)。
|
|
45
47
|
const candidates = [
|
|
46
48
|
join(nodeDir, 'npm'),
|
|
47
49
|
join(nodeDir, '..', '.local', 'bin', 'npm'),
|
|
48
50
|
join(nodeDir, '..', 'bin', 'npm'),
|
|
49
|
-
'/usr/local/bin/npm',
|
|
50
|
-
'/usr/bin/npm',
|
|
51
51
|
];
|
|
52
52
|
for (const p of candidates) if (probe(p)) return p;
|
|
53
53
|
return 'npm';
|