dsh-git-push 2.9.3 → 2.9.9
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 +22 -25
- package/lib/app/apply.js +8 -1
- package/lib/app/audit-api.js +4 -1
- package/lib/app/command-registry.js +17 -11
- package/lib/app/handlers/meta.js +38 -0
- package/lib/app/handlers/repo-actions.js +3 -1
- package/lib/app/handlers/settings.js +0 -0
- package/lib/app/http-handlers.js +3 -1
- package/lib/app/schema.js +0 -0
- package/lib/app/settings-bridge.js +0 -0
- package/lib/app/tool-call.js +26 -21
- package/lib/ast/control-flow.js +12 -3
- package/lib/ast/size.js +5 -2
- package/lib/audit/audit-file.js +4 -2
- package/lib/audit/file-context.js +89 -0
- package/lib/audit/finding.js +45 -2
- package/lib/audit/index.js +2 -2
- package/lib/audit/orchestrate.js +6 -1
- package/lib/checks/button-bind.js +25 -2
- package/lib/checks/regex.js +7 -3
- package/lib/commit-push.js +20 -2
- package/lib/core/exec.js +6 -4
- package/lib/exempt/index.js +72 -26
- package/lib/exempt/tool.js +198 -0
- package/lib/git/clone-history-mode.js +24 -5
- package/lib/git/push.js +28 -13
- package/lib/git/transport.js +49 -17
- package/lib/git/visibility.js +93 -9
- package/lib/npm/publish.js +27 -0
- package/lib/npm/registry.js +5 -2
- package/lib/self/index.js +1 -1
- package/package.json +2 -4
- package/skills/dev/dsh-git-push.md +1 -2
- package/skills/guide/guide-cli-scripts.md +3 -3
- package/skills/guide/guide-inject-ui.md +4 -4
- package/assets/minihost.sh +0 -35
- package/assets/preview.html +0 -36703
- package/lib/fs/edit-after-read.js +0 -142
- package/scripts/frontend-preview-check.mjs +0 -124
- package/scripts/preview-gen.mjs +0 -489
- package/scripts/preview-local-runner.mjs +0 -55
- package/scripts/preview-server-direct.mjs +0 -116
- package/scripts/preview-server.mjs +0 -305
- package/scripts/preview-slot-data.mjs +0 -123
- package/scripts/sync-plugin-install.mjs +0 -286
- package/scripts/sync-plugin.mjs +0 -284
|
@@ -33,6 +33,95 @@ export function hasMkdirInSameFunction(lines, lineIdx) {
|
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* 写目标是否「来自调用方」——若是,则目录创建责任不在本函数,mkdir-before-write 应豁免。
|
|
38
|
+
*
|
|
39
|
+
* 背景(2026-10-17 ZipCalm 反馈:robustness 槽位 4 条里 3 条跨界误报):
|
|
40
|
+
* 上一档 hasMkdirInSameFunction 只看**同函数**,而这些站点把写目标交给调用方准备:
|
|
41
|
+
* · store.js `const tmpPath = `${ctx.historyFile}.tmp`; fs.writeFile(tmpPath, …)`
|
|
42
|
+
* · writer.js `fs.createWriteStream(ctx.tempPath)`
|
|
43
|
+
* · tarFamily.js `fs.createWriteStream(plannedEntry.targetPath)`
|
|
44
|
+
* · zip/index.js `openArchivePipeline(tempPath, level)` ⇒ `fs.createWriteStream(tempPath)`
|
|
45
|
+
* 目标要么是**形参**、要么是形参的成员/由形参派生的临时路径 ⇒ 目录由调用方(或临时目录
|
|
46
|
+
* 提供方)负责建 ⇒ 规则说的「直接 writeFile 而不 mkdir ⇒ ENOENT」在本站点**不成立**
|
|
47
|
+
* (判错事实 = 真误报 ✓,不是"不想改")。
|
|
48
|
+
*
|
|
49
|
+
* 判据(保守,只认能静态确认的归属):
|
|
50
|
+
* ① 取下写调用的首参表达式,取它的**根标识符**;
|
|
51
|
+
* ② 根标识符若在**所属函数的形参列表**里 ⇒ 外来目标 ⇒ 豁免;
|
|
52
|
+
* ③ 根标识符是局部变量时,看它的赋值 RHS 是否**以形参为根**(如 `${ctx.x}.tmp`)⇒ 豁免;
|
|
53
|
+
* ④ 其余(本地字面量 / join(...) 现场拼路径 / 无赋值可查)⇒ **不豁免**,交给同函数档判定 ✓
|
|
54
|
+
* @param {string[]} lines 文件全部行
|
|
55
|
+
* @param {number} lineIdx 命中行索引(0 基)
|
|
56
|
+
* @returns {boolean} true=写目标来自调用方(应豁免)
|
|
57
|
+
*/
|
|
58
|
+
export function hasForeignWriteTarget(lines, lineIdx) {
|
|
59
|
+
const line = String(lines[lineIdx] || '');
|
|
60
|
+
// 取写调用的首参(到第一个逗号/右括号为止;模板串与成员链都吃)
|
|
61
|
+
const m = line.match(/(?:writeFile|writeFileSync|createWriteStream|appendFile|appendFileSync|createWriteStreamSync)\s*\(\s*([^,)]+)/);
|
|
62
|
+
if (!m) return false;
|
|
63
|
+
const target = m[1].trim();
|
|
64
|
+
const rootMatch = target.match(/^[$A-Za-z_][\w$]*/);
|
|
65
|
+
if (!rootMatch) return false;
|
|
66
|
+
const root = rootMatch[0];
|
|
67
|
+
const params = enclosingParams(lines, lineIdx);
|
|
68
|
+
if (params.has(root)) return true;
|
|
69
|
+
// 局部变量:查它的赋值 RHS 是否以形参为根(`${ctx.historyFile}.tmp` 这类临时路径)
|
|
70
|
+
const assignRe = new RegExp(`(?:const|let|var)\\s+${root}\\s*=\\s*([^;]+)`);
|
|
71
|
+
for (let i = lineIdx - 1; i >= Math.max(0, lineIdx - 40); i--) {
|
|
72
|
+
const mm = String(lines[i] || '').match(assignRe);
|
|
73
|
+
if (!mm) continue;
|
|
74
|
+
const rhs = mm[1];
|
|
75
|
+
// ⚠️ 只认「同目录派生」:模板串/字符串拼接(`${ctx.x}.tmp`、x + '.tmp')与成员传递;
|
|
76
|
+
// join(...) / resolve(...) 会**新增路径段**(join(dir,'sub','a.json'))⇒ 目录可能还没建,
|
|
77
|
+
// 仍由本函数负责 ⇒ 不豁免 ✓(否则会把真命中一起修掉 ✗,实测过一轮)
|
|
78
|
+
if (/\bjoin\s*\(|\bresolve\s*\(/.test(rhs)) return false;
|
|
79
|
+
const ids = rhs.match(/[$A-Za-z_][\w$]*/g) || [];
|
|
80
|
+
return ids.some((id) => params.has(id)); // 由形参派生 ⇒ 目录由调用方负责
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 取「所属函数」的形参名集合(向上找最近的函数签名;找不到返回空集)。
|
|
87
|
+
* 支持 function 声明/表达式、方法简写、箭头函数与 async 变体;
|
|
88
|
+
* 默认值、类型注解、解构都做保守处理(解构里的标识符也算形参 ✓)。
|
|
89
|
+
* @param {string[]} lines 文件全部行
|
|
90
|
+
* @param {number} lineIdx 命中行索引(0 基)
|
|
91
|
+
* @returns {Set<string>} 形参名集合
|
|
92
|
+
*/
|
|
93
|
+
function enclosingParams(lines, lineIdx) {
|
|
94
|
+
const out = new Set();
|
|
95
|
+
// ⚠️ 控制流行不是函数签名:`if (cond) {` / `for (…) {` / `while (…) {` / `catch (e) {` 等
|
|
96
|
+
// 都能被 `(…)\s*{` 匹配上 ⇒ 会把判定用的花括号误当函数体、参数集取成条件里的标识符 ✗
|
|
97
|
+
// (2026-10-17 实测:正是这一条让 hasForeignWriteTarget 对 ZipCalm 三处全部返回 false)
|
|
98
|
+
const CTRL_RE = /^\s*(?:\}\s*)?(?:if|for|while|switch|catch|do|else|return|with)\b/;
|
|
99
|
+
// ⚠️ 第二个实测坑:**行内回调**里的 `=>` 也会被当成函数头 ✗
|
|
100
|
+
// store.js 的 `const body = … ? \`${entries.map((item) => JSON.stringify(item))…` 与
|
|
101
|
+
// writer.js 的 `createThrottledReporter(ctx.onProgress || (() => {}), {`
|
|
102
|
+
// 都被扫成"签名" ⇒ 参数集 {item} / 空 ⇒ ctx 不在其中 ⇒ 判不出来 ✓(已修:箭头必须**以 => 结尾**)
|
|
103
|
+
// ③ 嵌套回调里写的目标,其目录往往由**外层函数**的形参决定(tarFamily 的 planned 来自外层)⇒
|
|
104
|
+
// 向外收集多层作用域的形参并集(上限 4 层,避免过度收集削弱规则)
|
|
105
|
+
const MAX_SCOPE_HEADS = 4;
|
|
106
|
+
for (let i = lineIdx, heads = 0; i >= Math.max(0, lineIdx - FUNC_START_SCAN_BACK) && heads < MAX_SCOPE_HEADS; i--) {
|
|
107
|
+
const text = String(lines[i] || '');
|
|
108
|
+
if (CTRL_RE.test(text)) continue;
|
|
109
|
+
const isDecl = /(?:^|\s)(?:async\s+)?function\b/.test(text);
|
|
110
|
+
const isArrowHead = /(?:\([^()]*\)|[$A-Za-z_][\w$]*)\s*=>\s*\{?\s*$/.test(text);
|
|
111
|
+
const isMethod = !/=>/.test(text) && /^\s*(?:export\s+)?(?:async\s+)?[$A-Za-z_][\w$]*\s*\([^)]*\)\s*\{/.test(text);
|
|
112
|
+
if (!isDecl && !isArrowHead && !isMethod) continue;
|
|
113
|
+
const sig = text.match(/(?:function\s*[$A-Za-z_][\w$]*\s*|(?:async\s+)?)(\([^)]*\))/)
|
|
114
|
+
|| (isArrowHead ? text.match(/(\([^)]*\))\s*=>/) : null);
|
|
115
|
+
if (!sig) continue;
|
|
116
|
+
for (const part of sig[1].replace(/[()]/g, '').split(',')) {
|
|
117
|
+
const name = (part.split(/[=:]/)[0].match(/[$A-Za-z_][\w$]*/g) || []).pop();
|
|
118
|
+
if (name) out.add(name);
|
|
119
|
+
}
|
|
120
|
+
heads += 1;
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
|
|
36
125
|
/**
|
|
37
126
|
* 外部 API 调用超时语义豁免:
|
|
38
127
|
* robustness/timeout-on-external-api 规则用纯 regex 匹配 `fetch(`/`axios.(` 等调用,
|
package/lib/audit/finding.js
CHANGED
|
@@ -1,8 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
import { exemptHintForFinding, exemptMarkerCovers } from '../exempt/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 是否「拦截级」finding —— **统一定义**(severity 为 blocker 或 error)。
|
|
5
|
+
*
|
|
6
|
+
* 为什么必须有这个函数(2026-10-17 由反馈「summary.blocker(10) vs 枚举(7)」触发):
|
|
7
|
+
* summarize 把 error 计入 blocker(见下方 1.1.0 修复),但各处枚举 blocked[] 只筛
|
|
8
|
+
* `severity === 'blocker'` ⇒ 同一个「拦截级」两套口径 ⇒ 出现 10 vs 7 的差额
|
|
9
|
+
* (差的正是 3 条 error 级:圈复杂度等)。凡需要枚举/判定拦截级的地方一律调本函数 ✓
|
|
10
|
+
*/
|
|
11
|
+
export function isBlockerFinding(f) {
|
|
12
|
+
const sev = (f && f.severity) || 'warning';
|
|
13
|
+
return sev === 'blocker' || sev === 'error';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 统一问题对象构造器(所有审计检查的出口)。 */
|
|
2
18
|
export function makeFinding({ file, line, rule, kind, severity = 'warning', message, dimensions = [], exemptHint = '', scoreImpact = 0 }) {
|
|
3
19
|
return { file, line, rule, kind, severity, message, dimensions, exemptHint, scoreImpact };
|
|
4
20
|
}
|
|
5
21
|
|
|
22
|
+
/**
|
|
23
|
+
* 豁免提示「可信化」:把每个 finding 的 exemptHint 校正为**真能豁免它**的标记。
|
|
24
|
+
*
|
|
25
|
+
* 背景(2026-10-17 由「有人反应文件头豁免措辞无效」触发):exemptHint 是各检查器里**写死**的
|
|
26
|
+
* 字符串,而能否生效取决于 lib/exempt/index.js 的 blocked/细分清单。两者不一致时,用户照
|
|
27
|
+
* 提示写了文件头标记**仍然照报**(全量自证实测 24 种组合,如 readability/vague-function-name
|
|
28
|
+
* 提示 dsh-skip-residue、maintainability/max-cyclomatic-complexity 提示 dsh-skip-quality)。
|
|
29
|
+
* 做法:统一在这一处(所有 finding 的汇集点)用注册表反查校正——
|
|
30
|
+
* · 原提示的标记确实覆盖 ⇒ **保留**(不打扰已熟悉的措辞与既有豁免统计)
|
|
31
|
+
* · 不覆盖 ⇒ 换成真能豁免的标记 + 该标记的官方 hint
|
|
32
|
+
* · 一个都没有 ⇒ 如实说明「当前无可用标记」(不再给一个写了不生效的 ✗)
|
|
33
|
+
* 幂等:同一 finding 反复校正结果不变;对新规则同样生效(无需逐个检查器去改提示)。
|
|
34
|
+
* @param {Array} findings 统一问题对象数组(原地修正 exemptHint)
|
|
35
|
+
*/
|
|
36
|
+
export function normalizeExemptHints(findings = []) {
|
|
37
|
+
const MARKER_RE = /dsh-skip-[a-z-]+/;
|
|
38
|
+
for (const f of findings) {
|
|
39
|
+
if (!f) continue;
|
|
40
|
+
const hit = String(f.exemptHint || '').match(MARKER_RE);
|
|
41
|
+
if (hit && exemptMarkerCovers(hit[0], f)) continue; // 原提示有效 ⇒ 保留
|
|
42
|
+
const truth = exemptHintForFinding(f);
|
|
43
|
+
if (truth) f.exemptHint = `${truth.marker}(${truth.hint})`;
|
|
44
|
+
else if (hit) f.exemptHint = '(当前无可用豁免标记:该 kind 不在任何 dsh-skip-* 的 blocked 清单里)';
|
|
45
|
+
}
|
|
46
|
+
return findings;
|
|
47
|
+
}
|
|
48
|
+
|
|
6
49
|
/**
|
|
7
50
|
* 扫描智能提示(1.0.8):对 warning/blocker 且文件路径或文件名带 test 特征的 finding,
|
|
8
51
|
* 在 message 末尾附加「测试文件夹可用 .test 空文件豁免」提示(告知而非自动豁免——
|
|
@@ -39,7 +82,7 @@ export function summarize(findings = []) {
|
|
|
39
82
|
let blocker = 0, warning = 0, notice = 0;
|
|
40
83
|
for (const f of findings) {
|
|
41
84
|
const sev = f.severity || 'warning';
|
|
42
|
-
if (
|
|
85
|
+
if (isBlockerFinding(f)) blocker++; // error=拦截级(凭据泄露/语法错误等)
|
|
43
86
|
else if (sev === 'notice' || sev === 'info') notice++;
|
|
44
87
|
else warning++;
|
|
45
88
|
}
|
package/lib/audit/index.js
CHANGED
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
|
|
25
25
|
import '../rule/compilers.js'; // 副作用:注册 13 种编译函数
|
|
26
26
|
|
|
27
|
-
export { makeFinding, decorateTestExemptHint, summarize, CODE_EXTS } from './finding.js';
|
|
27
|
+
export { makeFinding, decorateTestExemptHint, normalizeExemptHints, isBlockerFinding, summarize, CODE_EXTS } from './finding.js';
|
|
28
28
|
export { slotStatsFromFindings, buildRuleSlotMap, countRulesBySlot } from './slot.js';
|
|
29
29
|
export { repoLevelSemanticRuleIds, pickRepoLevelAnchorFile } from './repo-level.js';
|
|
30
|
-
export { hasMkdirInSameFunction, hasExternalCallTimeout, detectRepoJsYamlImport, isVersionInPathContext } from './file-context.js';
|
|
30
|
+
export { hasMkdirInSameFunction, hasForeignWriteTarget, hasExternalCallTimeout, detectRepoJsYamlImport, isVersionInPathContext } from './file-context.js';
|
|
31
31
|
export { auditFile } from './audit-file.js';
|
|
32
32
|
export { capScanFiles, auditFull, auditChanged, auditWithScope } from './orchestrate.js';
|
|
33
33
|
export { findingsToYaml } from './report-yaml.js';
|
package/lib/audit/orchestrate.js
CHANGED
|
@@ -9,7 +9,7 @@ import { compileAllRules } from '../rule/registry.js';
|
|
|
9
9
|
import { auditFile } from './audit-file.js';
|
|
10
10
|
import { grammarForExt, parseText, makeSyncConfirmer } from '../ast/treesitter.js';
|
|
11
11
|
import { detectRepoJsYamlImport } from './file-context.js';
|
|
12
|
-
import { decorateTestExemptHint, makeFinding, summarize } from './finding.js';
|
|
12
|
+
import { decorateTestExemptHint, makeFinding, summarize, normalizeExemptHints } from './finding.js';
|
|
13
13
|
import { pickRepoLevelAnchorFile, repoLevelSemanticRuleIds } from './repo-level.js';
|
|
14
14
|
import { checkDocsScore } from '../score/docs-score.js';
|
|
15
15
|
import { runAuditExt } from './ext-runner.js';
|
|
@@ -285,6 +285,11 @@ async function auditFiles(repoPath, files, opts = {}) {
|
|
|
285
285
|
try {
|
|
286
286
|
findings.push(...(await runAuditExt(repoPath, { dir: opts.auditExtDir, log: opts.log })));
|
|
287
287
|
} catch (e) { log?.warn?.(`审计扩展执行失败:${e?.message || e}`); }
|
|
288
|
+
// 豁免提示可信化(2026-10-17)—— **必须放在所有 finding 追加完之后**:
|
|
289
|
+
// 此前放在文件循环附近,后面还有 tree-doc/func-doc/split-docs/ignore/ext 五处追加 ⇒
|
|
290
|
+
// 那些 finding 绕过校正,自证里仍能看到「提示 dsh-skip-quality 却没有标记能豁免」✗。
|
|
291
|
+
// 统一校正为「真能豁免该 finding」的标记(提示与判定口径分离曾致 24 种组合写了不生效)。
|
|
292
|
+
normalizeExemptHints(findings);
|
|
288
293
|
// 按规则包聚合命中数(侧边栏规则包列表的「拦截/警告/通过」= 实际命中数)
|
|
289
294
|
const slotStats = slotStatsFromFindings(findings, buildRuleSlotMap(compiled), countRulesBySlot(compiled));
|
|
290
295
|
// 文档加分制(0 分起、上限 10)——结构信号 + 交叉验证,**不进 findings**
|
|
@@ -159,6 +159,14 @@ export function checkButtonBindings({ file, text, rules }) {
|
|
|
159
159
|
const btnRe = /<button\b([^>]*)>([\s\S]*?)<\/button\s*>|<input\b[^>]*type\s*=\s*['"](?:button|submit)['"][^>]*>/gi;
|
|
160
160
|
// JSX/React 事件属性(onClick=/onChange= 等驼峰 on[A-Z])→ 声明式绑定,视为已绑定(防 React 代码误报 unbound)
|
|
161
161
|
const jsxEventRe = /\bon[A-Z][\w]*\s*=\s*[\{'"`]/;
|
|
162
|
+
// Vue/声明式模板事件属性:@click / @click.self|stop|prevent|once / v-on:click(含修饰符)/ @[click]
|
|
163
|
+
// 2026-10-17 由 ZipCalm 反馈修复:该项目的 .vue 按钮**全部**写作
|
|
164
|
+
// `<button … data-testid="compress-close" @click="emit('close')">关闭</button>`,
|
|
165
|
+
// 而旧判据只认 React 的 onClick ⇒ 同一元素上的绑定看不见 ⇒ 16 条全部误报
|
|
166
|
+
// (判据说"未找到绑定证据",但绑定就写在按钮元素自己身上 ✗ 属判错事实)。
|
|
167
|
+
// 注意只认 click 类事件:Vue 的 @click 是绑定证据,与 HTML 字符串里的 inline onclick 不同,
|
|
168
|
+
// 不产生 button/inline-binding-in-string 提示(那是 DOM0 内联写法的问题)。
|
|
169
|
+
const vueEventRe = /(?:@click(?:\.\w+)*|v-on:click(?:\.\w+)*|@\[click\])\s*=/;
|
|
162
170
|
for (const chunk of htmlChunks.concat(tplChunks)) {
|
|
163
171
|
let bm;
|
|
164
172
|
while ((bm = btnRe.exec(chunk.html)) !== null) {
|
|
@@ -171,6 +179,11 @@ export function checkButtonBindings({ file, text, rules }) {
|
|
|
171
179
|
text: (bm[2] || '').replace(/<[^>]*>/g, '').trim().slice(0, 30),
|
|
172
180
|
hasInline: /\bonclick\s*=/.test(attrs),
|
|
173
181
|
jsxBound: jsxEventRe.test(attrs), // React 声明式事件(onClick 等驼峰)
|
|
182
|
+
vueBound: vueEventRe.test(attrs), // Vue 声明式事件(@click / v-on:click)
|
|
183
|
+
// 静态 disabled 按钮:永远不会被点击 ⇒ 无需绑定(2026-10-17 ZipCalm 反馈:
|
|
184
|
+
// `<button type="button" disabled title="任务未结束…">删除</button>` 被判 unbound 属
|
|
185
|
+
// 判据不适配 ✓)。只认静态属性:`:disabled="cond"` 是动态的,可能可点 ⇒ 不在此列 ✓
|
|
186
|
+
staticDisabled: /(?:^|\s)disabled(?:\s|$)/.test(attrs),
|
|
174
187
|
});
|
|
175
188
|
}
|
|
176
189
|
}
|
|
@@ -228,7 +241,9 @@ export function checkButtonBindings({ file, text, rules }) {
|
|
|
228
241
|
// 3b. HTML 字符串里的按钮
|
|
229
242
|
for (const btn of btns) {
|
|
230
243
|
// JSX/React 声明式事件:onClick 等驼峰属性 = 已绑定(React 虚拟 DOM 内声明式,非油猴场景)
|
|
231
|
-
|
|
244
|
+
// Vue 同理:@click / v-on:click 写在按钮元素上 = 已绑定(2026-10-17 修复,见 vueEventRe 注释)
|
|
245
|
+
if (btn.jsxBound || btn.vueBound) continue;
|
|
246
|
+
if (btn.staticDisabled) continue; // 静态禁用按钮:不可点 ⇒ 无绑定诉求 ✓
|
|
232
247
|
// inline onclick:有绑定但建议改(info)
|
|
233
248
|
if (btn.hasInline) {
|
|
234
249
|
findings.push(makeFinding({
|
|
@@ -272,5 +287,13 @@ export function checkButtonBindings({ file, text, rules }) {
|
|
|
272
287
|
dimensions: ['可维护性'], exemptHint: HINT_QUALITY, scoreImpact: 1,
|
|
273
288
|
}));
|
|
274
289
|
}
|
|
275
|
-
|
|
290
|
+
// 去重:同一按钮可能被多路提取命中(innerHTML 片段 + 反引号模板 + JSX 工厂)⇒ 同一行只留一条
|
|
291
|
+
// (2026-10-17 实测:`el.innerHTML = \`<button…>\`` 会同时进 htmlChunks 与 tplChunks ⇒ 重复报 2 条 ✗)
|
|
292
|
+
const seenKey = new Set();
|
|
293
|
+
return findings.filter((f) => {
|
|
294
|
+
const k = `${f.rule}|${f.line}`;
|
|
295
|
+
if (seenKey.has(k)) return false;
|
|
296
|
+
seenKey.add(k);
|
|
297
|
+
return true;
|
|
298
|
+
});
|
|
276
299
|
}
|
package/lib/checks/regex.js
CHANGED
|
@@ -38,15 +38,19 @@ export function pickExemptHint(rule) {
|
|
|
38
38
|
}
|
|
39
39
|
if (hit(residue.residueRules)) return 'dsh-skip-residue(行尾=本行)';
|
|
40
40
|
if (hit(style.styleRules)) return 'dsh-skip-style(文件头=整文件)';
|
|
41
|
-
//
|
|
42
|
-
|
|
41
|
+
// 三套清单都没命中:**不能**再沿用一个写了不生效的标记 ✗(2026-10-17「措辞无效」的根因之一:
|
|
42
|
+
// 这里原样返回 dsh-skip-residue,而 residue 只管 debugger/todo/console/io-risk 等窄集合,
|
|
43
|
+
// 其余 regex 规则(vague-function-name / timeout-on-external-api …)写了完全不生效)。
|
|
44
|
+
// 改为按注册表反查:真能豁免给出真标记,否则如实留空(由 finding 出口统一校正兜底)。
|
|
45
|
+
const truth = exemptHintForFinding({ kind: kind || 'regex', rule: id });
|
|
46
|
+
return truth ? `${truth.marker}(${truth.hint})` : '';
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
import { makeFinding } from '../audit/index.js';
|
|
46
50
|
import { safeRe } from '../rule/compilers.js';
|
|
47
51
|
import { capSeverity } from './common.js';
|
|
48
52
|
// 豁免提示按规则名前缀选关键词——分类清单复用豁免注册表(单一来源,避免两处各写一份清单)
|
|
49
|
-
import { EXEMPT_MARKERS } from '../exempt/index.js';
|
|
53
|
+
import { EXEMPT_MARKERS, exemptHintForFinding } from '../exempt/index.js';
|
|
50
54
|
import { credentialValueLines, placeholderCredentialLines, shortFuncNameLines, smallFileReadLines, consoleLogJsonLines, loopFullCollectionLines, repeatIdenticalCallLines, loopNoFallbackReturnLines, loopFullRewriteCallLines, nestedLinearScanLines, longSyncLoopLines, smartHitLines, shellCdDynamicLines, writeIntoGitignoredLines, ioRiskLines, ioRiskDetail } from './common.js';
|
|
51
55
|
|
|
52
56
|
/** 检查文本是否符合 regex 型规则(regex / secret / credential-ref)。
|
package/lib/commit-push.js
CHANGED
|
@@ -30,7 +30,7 @@ import { resolveRepoVisibility } from './git/index.js';
|
|
|
30
30
|
* (README「④ 私有库豁免」);缺省按 origin 探测,探测失败按 unknown(保守拦截)。
|
|
31
31
|
* 显式传入可免网络探测(测试/已知场景)。
|
|
32
32
|
*/
|
|
33
|
-
export async function runAudit({ repoPath = '', audit, rulesetDir, slots, cfg: extCfg, visibility: extVisibility } = {}) {
|
|
33
|
+
export async function runAudit({ repoPath = '', audit, rulesetDir, slots, cfg: extCfg, visibility: extVisibility, exemptPaths = [], exemptReason = '' } = {}) {
|
|
34
34
|
const cfg = extCfg || defaultConfig();
|
|
35
35
|
const doAudit = audit ?? cfg.auditEnabled;
|
|
36
36
|
if (!doAudit) return { ok: true, audit: null };
|
|
@@ -58,9 +58,27 @@ export async function runAudit({ repoPath = '', audit, rulesetDir, slots, cfg: e
|
|
|
58
58
|
// 审计输出改为「级别数量 + 评分 + API 查询用法」——审计明细由聚合 API
|
|
59
59
|
// (/api/git-push/audit)查询,不再内联 findings 全文;blocked 摘要保留(拦截必需)。
|
|
60
60
|
auditOut.apiGuide = buildAuditApiGuide(repoPath, { scope: auditRes.scope, summary: auditRes.summary, quality: auditOut.quality });
|
|
61
|
+
// 本次提交的按文件临时豁免(auditExemptPaths):列入的文件 finding 一律不参与拦截判定(含 blocker),
|
|
62
|
+
// 仅本次有效、不落盘、不改 .auditignore;评分仍用全量 findings(豁免不影响打分基数)。
|
|
63
|
+
// 语义按需求方定稿:豁免即豁免,不设「只允许 warning/notice」的限制,也不按规则类别过滤。
|
|
64
|
+
const exemptSet = new Set((Array.isArray(exemptPaths) ? exemptPaths : [])
|
|
65
|
+
.map((p) => String(p || '').replace(/\\/g, '/').replace(/^\.\//, '').trim())
|
|
66
|
+
.filter(Boolean));
|
|
67
|
+
const isExemptFile = (f) => exemptSet.size > 0 && exemptSet.has(String(f.file || '').replace(/\\/g, '/').replace(/^\.\//, ''));
|
|
68
|
+
const exemptFindings = exemptSet.size ? auditRes.findings.filter((f) => isExemptFile(f)) : [];
|
|
61
69
|
// 只算非示例目录的 blocker(示例目录内的 blocker 是规则演示,不拦真实提交)
|
|
62
|
-
const blocked = auditRes.findings.filter((f) => f.severity === 'blocker' && !isSampleExemptDir(repoPath || '.', f.file));
|
|
70
|
+
const blocked = auditRes.findings.filter((f) => f.severity === 'blocker' && !isSampleExemptDir(repoPath || '.', f.file) && !isExemptFile(f));
|
|
63
71
|
auditOut.blocked = blocked.map((f) => ({ file: f.file, line: f.line, rule: f.rule, message: (f.message || '').slice(0, MAX_MSG_PREVIEW) }));
|
|
72
|
+
if (exemptSet.size) {
|
|
73
|
+
// 回显(记录而非判断):本次豁免了哪些文件、命中哪些规则、共几条 finding
|
|
74
|
+
auditOut.exempt = {
|
|
75
|
+
files: [...exemptSet],
|
|
76
|
+
count: exemptFindings.length,
|
|
77
|
+
rules: [...new Set(exemptFindings.map((f) => f.rule).filter(Boolean))],
|
|
78
|
+
...(exemptReason ? { reason: String(exemptReason) } : {}),
|
|
79
|
+
note: '本次提交临时豁免(不落盘、不影响后续提交);评分仍按全量 findings 计算',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
64
82
|
if (blocked.length > 0) {
|
|
65
83
|
// 【修复】私有库豁免(README「④ 私有库豁免」):远端可见性 = private → 审计只报告不拦截。
|
|
66
84
|
// 修复背景:私有库被拦的回归——
|
package/lib/core/exec.js
CHANGED
|
@@ -84,14 +84,15 @@ export const GIT_READ_VERBS = new Set(['fetch', 'clone', 'pull', 'ls-remote', 's
|
|
|
84
84
|
export const GIT_GLOBAL_ARGS = ['-c', 'safe.directory=*', '-c', 'core.filemode=false', '-c', 'core.quotepath=false'];
|
|
85
85
|
|
|
86
86
|
/** 统一 git 执行(数组参数,零注入面;stderr 保留供排障)。 */
|
|
87
|
-
export function runGit(args, { cwd = '', timeoutMs = 120_000, env = {} } = {}) {
|
|
87
|
+
export function runGit(args, { cwd = '', timeoutMs = 120_000, env = {}, noMirror = false } = {}) {
|
|
88
88
|
const base = GIT_GLOBAL_ARGS;
|
|
89
89
|
const bin = resolveGitBin();
|
|
90
90
|
if (!bin) return { ok: false, stdout: '', stderr: GIT_MISSING_MSG };
|
|
91
91
|
// 只读的网络动词注入镜像(与 http 层同口径:默认走 gh-proxy);
|
|
92
92
|
// 写操作(push 等)不在集合里 ⇒ 不注入 ⇒ 推送一律直连(凭据与写入不经第三方)。
|
|
93
|
+
// noMirror:调用方已判定目标仓库是私有/未知 ⇒ 不注入——镜像看不到私有库,注入必失败。
|
|
93
94
|
const mirrorEnv = {};
|
|
94
|
-
if (GIT_READ_VERBS.has(String(args[0] || ''))) mirrorGitConfigEnv(mirrorEnv, { mode: 'read' });
|
|
95
|
+
if (!noMirror && GIT_READ_VERBS.has(String(args[0] || ''))) mirrorGitConfigEnv(mirrorEnv, { mode: 'read' });
|
|
95
96
|
try {
|
|
96
97
|
const out = execFileSync(bin, cwd ? base.concat(['-C', cwd], args) : base.concat(args), {
|
|
97
98
|
encoding: 'utf8',
|
|
@@ -139,14 +140,15 @@ export function gitRaw(args, { cwd = '', timeoutMs = 600_000 } = {}) {
|
|
|
139
140
|
* 实测 6 仓「并发」仍要 13s(≈ 串行)。改用本函数后各 worker 的子进程才能真正并行等待。
|
|
140
141
|
* 语义与 runGit 保持一致:stdout 同样 trim,失败返回 {ok:false, error} 而不抛。
|
|
141
142
|
*/
|
|
142
|
-
export function runGitAsync(args, { cwd = '', timeoutMs = 120_000, env = {} } = {}) {
|
|
143
|
+
export function runGitAsync(args, { cwd = '', timeoutMs = 120_000, env = {}, noMirror = false } = {}) {
|
|
143
144
|
const base = GIT_GLOBAL_ARGS;
|
|
144
145
|
const bin = resolveGitBin();
|
|
145
146
|
if (!bin) return Promise.resolve({ ok: false, stdout: '', stderr: GIT_MISSING_MSG });
|
|
146
147
|
// 与 runGit 同口径:只读网络动词注入镜像,push 等写操作不注入(见 GIT_READ_VERBS)。
|
|
147
148
|
// 此前只有同步版注入,异步版仍直连 ⇒ 并发探测远端那类调用绕过镜像。
|
|
149
|
+
// noMirror:目标仓库私有/未知时不注入(镜像看不到私有库)。
|
|
148
150
|
const mirrorEnv = {};
|
|
149
|
-
if (GIT_READ_VERBS.has(String(args[0] || ''))) mirrorGitConfigEnv(mirrorEnv, { mode: 'read' });
|
|
151
|
+
if (!noMirror && GIT_READ_VERBS.has(String(args[0] || ''))) mirrorGitConfigEnv(mirrorEnv, { mode: 'read' });
|
|
150
152
|
return new Promise((resolve) => {
|
|
151
153
|
execFile(bin, cwd ? base.concat(['-C', cwd], args) : base.concat(args), {
|
|
152
154
|
encoding: 'utf8',
|
package/lib/exempt/index.js
CHANGED
|
@@ -14,7 +14,10 @@ import { statSync } from 'node:fs';
|
|
|
14
14
|
export const EXEMPT_MARKERS = {
|
|
15
15
|
'dsh-skip-sensitive': {
|
|
16
16
|
dimensions: ['安全性'],
|
|
17
|
-
|
|
17
|
+
// 2026-10-17 补 'semantic':security/* 的语义类 finding(如 security/no-path-traversal)
|
|
18
|
+
// 此前既不在 sensitive.blocked、又被 quality 的安全排除挡掉 ⇒ 任何标记都豁免不了 ✗
|
|
19
|
+
// (自证第 24 种)。细分词表同时作用于 semantic(见 markerCovers)。
|
|
20
|
+
blocked: ['[FUNC]', 'credential-file', 'credential-ref', 'path-regex', 'regex', 'semantic'], // path-regex 含私钥路径类;regex 是宽声明(安全类按 rule 名细分)
|
|
18
21
|
// regex 宽声明:security/* 规则带 pattern 字段编译成 regex kind,
|
|
19
22
|
// 需按 rule 名细分(含 security/credential/secret/password/hardcoded 等安全词才算敏感类)
|
|
20
23
|
sensitiveRules: ['security', 'credential', 'credref', 'credfile', 'secret', 'password', 'hardcoded'],
|
|
@@ -66,8 +69,17 @@ export const EXEMPT_MARKERS = {
|
|
|
66
69
|
// comment-density / file-health:这两类 finding 一直提示 dsh-skip-quality,
|
|
67
70
|
// 但它们的 kind 也不在任何标记的 blocked 里(同 blacklist/magic-number-smart 一类 bug:
|
|
68
71
|
// 提示写了不生效)⇒ 一并补进本条(注释密度与文件健康度都属「质量评分」语义)。
|
|
72
|
+
// 2026-10-17 补齐(起因:「有人反应文件头豁免措辞无效」⇒ 全量自证查出 24 种组合
|
|
73
|
+
// **按 finding 提示写了文件头标记仍照报** ✗)。两类缺口:
|
|
74
|
+
// ① semantic / dataflow / duplicate-const / repeated-string —— 此前**没有任何标记**
|
|
75
|
+
// 能豁免这些 kind,而规则自身却提示用 dsh-skip-quality ⇒ 写了不生效;
|
|
76
|
+
// ② regex —— 兜底覆盖**非安全类**的 regex finding(安全类由 excludeRules 排除,
|
|
77
|
+
// 仍必须写 dsh-skip-sensitive,避免用质量标记顺手静默掉安全问题 ✗)。
|
|
69
78
|
blocked: ['func-lines', 'empty-catch', 'sync-fs', 'magic-number-smart', 'blacklist',
|
|
70
|
-
'comment-density', 'file-health'
|
|
79
|
+
'comment-density', 'file-health',
|
|
80
|
+
'semantic', 'dataflow', 'duplicate-const', 'repeated-string', 'regex'],
|
|
81
|
+
// regex 兜底时**排除**安全类规则名(这些必须走 dsh-skip-sensitive,不能靠质量标记吞掉)
|
|
82
|
+
excludeRules: ['security', 'credential', 'credref', 'credfile', 'secret', 'password', 'hardcoded'],
|
|
71
83
|
lineLevel: false,
|
|
72
84
|
hint: '文件头=整文件免质量评分(func-lines/empty-catch/sync-fs/magic-number-smart/blacklist 措辞/comment-density/file-health)',
|
|
73
85
|
},
|
|
@@ -84,7 +96,11 @@ export const EXEMPT_MARKERS = {
|
|
|
84
96
|
},
|
|
85
97
|
'dsh-skip-style': {
|
|
86
98
|
dimensions: ['可读性'],
|
|
87
|
-
|
|
99
|
+
// 需按 rule 前缀细分(style-* 数值风格规则);min-occurrences 是 lib/audit/orchestrate.js 分体文档提示用的非 regex kind。
|
|
100
|
+
// 2026-10-17 补 min-length / max-lines / max-complexity / max-depth / repeated-string 这些**直接 kind**:
|
|
101
|
+
// styleRules 里本来就列了它们(文档表也写「style-* 数值风格(min-length/max-lines/max-complexity/max-depth)→ 只能文件头」),
|
|
102
|
+
// 但 blocked 只列了 'min-occurrences' ⇒ kind=min-length 等 finding 提示 dsh-skip-quality 时**无任何标记可豁免** ✗(自证抓到)。
|
|
103
|
+
blocked: ['regex', 'min-occurrences', 'min-length', 'max-lines', 'max-complexity', 'max-depth', 'repeated-string'],
|
|
88
104
|
styleRules: ['min-length', 'max-lines', 'max-complexity', 'max-depth', 'min-occurrences', 'repeated-string'],
|
|
89
105
|
lineLevel: false,
|
|
90
106
|
hint: '文件头=整文件免全部 styleRules',
|
|
@@ -136,11 +152,62 @@ export function isCategoryExempt(finding = {}) {
|
|
|
136
152
|
return false;
|
|
137
153
|
}
|
|
138
154
|
|
|
155
|
+
/**
|
|
156
|
+
* 单个标记是否覆盖该 kind/rule —— **唯一判定口径**(exemptForFinding 与反查提示共用)。
|
|
157
|
+
*
|
|
158
|
+
* 为什么抽出来:此前「判定是否豁免」与「生成 exemptHint」两处各写一套口径 ⇒
|
|
159
|
+
* 提示的标记与实际能否豁免会不一致(2026-10-17 全量自证实测 24 种组合:
|
|
160
|
+
* 用户按 finding 提示写了文件头标记仍然照报,即「措辞无效」✗)。
|
|
161
|
+
*/
|
|
162
|
+
function markerCovers(meta, kind, rule) {
|
|
163
|
+
if (!meta || !Array.isArray(meta.blocked) || !meta.blocked.includes(kind)) return false;
|
|
164
|
+
const r = String(rule || '').toLowerCase();
|
|
165
|
+
const has = (a) => Array.isArray(a) && a.length > 0;
|
|
166
|
+
// 残留/风格/国际化:只对 regex 宽声明做「规则名细分」
|
|
167
|
+
if (kind === 'regex') {
|
|
168
|
+
if (has(meta.residueRules)) return meta.residueRules.some((w) => r.includes(w));
|
|
169
|
+
if (has(meta.styleRules)) return meta.styleRules.some((w) => r.includes(w));
|
|
170
|
+
if (has(meta.i18nRules)) return meta.i18nRules.some((w) => r.includes(w));
|
|
171
|
+
}
|
|
172
|
+
// 安全类细分:regex 与 semantic 两类**宽 kind** 都要按词表判;
|
|
173
|
+
// ⚠️ 不可推广到 path-regex / [FUNC] / credential-* —— 那些是**直接 kind 命中**,
|
|
174
|
+
// 不受规则名词表约束(原语义;扩展 semantic 时曾误伤 path-private-key-location ⇒ 回归)。
|
|
175
|
+
if ((kind === 'regex' || kind === 'semantic') && has(meta.sensitiveRules)) {
|
|
176
|
+
return meta.sensitiveRules.some((w) => r.includes(w));
|
|
177
|
+
}
|
|
178
|
+
// 质量兜底对 regex 的覆盖:排除安全类(安全 finding 不许被质量标记吞掉 ✗)
|
|
179
|
+
if (kind === 'regex' && has(meta.excludeRules)) return !meta.excludeRules.some((w) => r.includes(w));
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** 指定标记是否覆盖该 finding(供提示校正判断「原提示是否仍然有效」)。 */
|
|
184
|
+
export function exemptMarkerCovers(marker, finding = {}) {
|
|
185
|
+
return markerCovers(EXEMPT_MARKERS[marker], finding.kind || '', finding.rule || '');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 反查「真能豁免该 finding 的标记」——按与 exemptForFinding **同一口径**判定。
|
|
190
|
+
* 优先级:先非 dsh-skip-quality(专用标记更贴切),最后才是质量类兜底。
|
|
191
|
+
* @param {object} finding 需含 kind/rule
|
|
192
|
+
* @returns {{marker:string, hint:string}|null} 无可豁免标记时返回 null(调用方应如实提示)
|
|
193
|
+
*/
|
|
194
|
+
export function exemptHintForFinding(finding = {}) {
|
|
195
|
+
const kind = finding.kind || '';
|
|
196
|
+
const rule = finding.rule || '';
|
|
197
|
+
const pinned = ['dsh-skip-quality'];
|
|
198
|
+
const order = [...Object.keys(EXEMPT_MARKERS).filter((m) => !pinned.includes(m)), ...pinned];
|
|
199
|
+
for (const marker of order) {
|
|
200
|
+
const meta = EXEMPT_MARKERS[marker];
|
|
201
|
+
if (markerCovers(meta, kind, rule)) return { marker, hint: meta.hint };
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
|
|
139
206
|
/**
|
|
140
207
|
* 判定单个 finding 是否被豁免。
|
|
141
208
|
* 整文件豁免(文件头前 3 行含标记)→ 该 finding 的 kind 命中 blocked 即豁免;
|
|
142
209
|
* 行级豁免(finding.line 所在行含标记,且标记支持 lineLevel)→ 豁免。
|
|
143
|
-
* residue/style 走 rule
|
|
210
|
+
* residue/style/i18n/sensitive 走 rule 前缀细分(口径统一在 markerCovers)。
|
|
144
211
|
* @param {object} finding 统一问题对象
|
|
145
212
|
* @param {string} text 文件全文(用于取文件头与行)
|
|
146
213
|
* @returns {boolean} true=豁免(应丢弃该 finding)
|
|
@@ -152,28 +219,7 @@ export function exemptForFinding(finding, text = '') { // dsh-skip-complexity:
|
|
|
152
219
|
const kind = finding.kind || '';
|
|
153
220
|
const rule = finding.rule || '';
|
|
154
221
|
for (const [marker, meta] of Object.entries(EXEMPT_MARKERS)) {
|
|
155
|
-
|
|
156
|
-
// residue/style:blocked 里的 'regex' 是**宽声明**,需按 rule 前缀细分;
|
|
157
|
-
// 但细分支必须只在 kind === 'regex' 时生效——否则 blocked 里直接列的非 regex kind
|
|
158
|
-
// (如 style 的 'min-occurrences',orchestrate.js 的分体文档提示用它做 kind)
|
|
159
|
-
// 会被 rule 名细分误杀:规则名不含 styleRules 词 ⇒ 写了标记也不豁免(实测复现)。
|
|
160
|
-
// sensitive/i18n 两个分支本就带 kind === 'regex' 前置,这里补齐一致。
|
|
161
|
-
let kindHit = blockedHit;
|
|
162
|
-
if (kind === 'regex' && blockedHit && meta.residueRules && meta.residueRules.length) {
|
|
163
|
-
kindHit = meta.residueRules.some((r) => rule.toLowerCase().includes(r));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (kind === 'regex' && blockedHit && meta.styleRules && meta.styleRules.length) {
|
|
167
|
-
kindHit = meta.styleRules.some((r) => rule.toLowerCase().includes(r));
|
|
168
|
-
}
|
|
169
|
-
if (kind === 'regex' && meta.i18nRules && meta.i18nRules.length) {
|
|
170
|
-
kindHit = meta.i18nRules.some((r) => rule.toLowerCase().includes(r));
|
|
171
|
-
}
|
|
172
|
-
// sensitive 细分只在 regex 宽声明时生效(直接 kind 命中如 [FUNC]/credential-*/path-regex 不受 rule 名约束)
|
|
173
|
-
if (kind === 'regex' && meta.sensitiveRules && meta.sensitiveRules.length) {
|
|
174
|
-
kindHit = meta.sensitiveRules.some((r) => rule.toLowerCase().includes(r));
|
|
175
|
-
}
|
|
176
|
-
if (!kindHit) continue;
|
|
222
|
+
if (!markerCovers(meta, kind, rule)) continue;
|
|
177
223
|
// 整文件豁免(文件头前 3 行)
|
|
178
224
|
if (hasHeaderExempt(lines.slice(0, 3).join('\n'), marker)) return true;
|
|
179
225
|
// 行级豁免(支持 lineLevel 且本行含标记)
|