dsh-git-push 2.20.19 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/README.md +3 -2
  2. package/cli-tool.mjs +2 -4
  3. package/cli.mjs +7 -1
  4. package/lib/app/apply.js +4 -4
  5. package/lib/app/command-registry.js +22 -17
  6. package/lib/app/handlers/meta.js +2 -2
  7. package/lib/app/handlers/preprocess.js +107 -0
  8. package/lib/app/handlers/repo-actions.js +2 -2
  9. package/lib/app/http-handlers.js +13 -42
  10. package/lib/app/index.js +2 -1
  11. package/lib/app/inject-text.js +3 -3
  12. package/lib/app/preprocess-client.js +136 -0
  13. package/lib/app/repo-ownership.js +1 -1
  14. package/lib/app/schema.js +3 -3
  15. package/lib/app/severity.js +14 -0
  16. package/lib/app/slash-commands.js +5 -164
  17. package/lib/app/tool-call.js +73 -144
  18. package/lib/cli/commands-preprocess.mjs +74 -0
  19. package/lib/cli/commands-tool.mjs +3 -2
  20. package/lib/cli/commands-vcs.mjs +4 -4
  21. package/lib/cli/shared.mjs +35 -9
  22. package/lib/commit-push/pre-commit-engine.js +57 -10
  23. package/lib/commit-push.js +71 -27
  24. package/lib/{exempt/index.js → git/exempt-markers.js} +8 -1
  25. package/lib/git/ignore.js +1 -1
  26. package/lib/git/repos.js +2 -2
  27. package/lib/git/sensitive.js +1 -1
  28. package/lib/npm/publish.js +20 -5
  29. package/lib/plugin/auto-push.js +2 -2
  30. package/lib/preprocess/providers.js +191 -0
  31. package/lib/self/index.js +1 -1
  32. package/lib/skip-dirs.js +14 -55
  33. package/package.json +29 -37
  34. package/scripts/build-client.mjs +2 -0
  35. package/scripts/check.mjs +4 -2
  36. package/scripts/local-registry.mjs +2 -1
  37. package/cli-audit.mjs +0 -141
  38. package/lib/app/audit-api.js +0 -173
  39. package/lib/app/handlers/audit.js +0 -150
  40. package/lib/app/host-doc-checks.js +0 -25
  41. package/lib/app/scope-check.js +0 -69
  42. package/lib/ast/brace.js +0 -120
  43. package/lib/ast/callgraph.js +0 -135
  44. package/lib/ast/code-lines.js +0 -175
  45. package/lib/ast/consts.js +0 -12
  46. package/lib/ast/control-flow.js +0 -470
  47. package/lib/ast/credential.js +0 -315
  48. package/lib/ast/dataflow.js +0 -391
  49. package/lib/ast/dup-code.js +0 -165
  50. package/lib/ast/fs-hotspots.js +0 -154
  51. package/lib/ast/index.js +0 -38
  52. package/lib/ast/io-risk-const.js +0 -95
  53. package/lib/ast/io-risk-fn.js +0 -208
  54. package/lib/ast/io-risk-loop.js +0 -308
  55. package/lib/ast/io-risk.js +0 -314
  56. package/lib/ast/lang.js +0 -156
  57. package/lib/ast/line-count.js +0 -52
  58. package/lib/ast/magic-number.js +0 -272
  59. package/lib/ast/naming.js +0 -292
  60. package/lib/ast/perf.js +0 -488
  61. package/lib/ast/scope-collisions.js +0 -228
  62. package/lib/ast/scope.js +0 -241
  63. package/lib/ast/shell.js +0 -131
  64. package/lib/ast/size.js +0 -448
  65. package/lib/ast/symbol-index.js +0 -399
  66. package/lib/ast/tokenizer.js +0 -421
  67. package/lib/ast/treesitter.js +0 -413
  68. package/lib/audit/analysis-coverage.js +0 -98
  69. package/lib/audit/audit-file.js +0 -205
  70. package/lib/audit/auditignore-rules.js +0 -148
  71. package/lib/audit/checks.js +0 -17
  72. package/lib/audit/client-entry.js +0 -93
  73. package/lib/audit/collector.js +0 -610
  74. package/lib/audit/ext-runner.js +0 -80
  75. package/lib/audit/file-context.js +0 -391
  76. package/lib/audit/finding.js +0 -101
  77. package/lib/audit/gitignore-match.js +0 -113
  78. package/lib/audit/glob.js +0 -63
  79. package/lib/audit/history-report.js +0 -100
  80. package/lib/audit/history.js +0 -126
  81. package/lib/audit/ignore-blind.js +0 -102
  82. package/lib/audit/index.js +0 -33
  83. package/lib/audit/orchestrate.js +0 -672
  84. package/lib/audit/public.js +0 -24
  85. package/lib/audit/repo-level.js +0 -30
  86. package/lib/audit/report-yaml.js +0 -90
  87. package/lib/audit/scope-policy.js +0 -110
  88. package/lib/audit/slot.js +0 -66
  89. package/lib/audit-rules/audit-rules-comment.yml +0 -199
  90. package/lib/audit-rules/audit-rules-cpp.yml +0 -114
  91. package/lib/audit-rules/audit-rules-csharp.yml +0 -82
  92. package/lib/audit-rules/audit-rules-docs.yml +0 -32
  93. package/lib/audit-rules/audit-rules-dsh.yml +0 -177
  94. package/lib/audit-rules/audit-rules-filehealth.yml +0 -42
  95. package/lib/audit-rules/audit-rules-folder.yml +0 -99
  96. package/lib/audit-rules/audit-rules-frontend.yml +0 -335
  97. package/lib/audit-rules/audit-rules-go.yml +0 -103
  98. package/lib/audit-rules/audit-rules-i18n.yml +0 -45
  99. package/lib/audit-rules/audit-rules-java.yml +0 -105
  100. package/lib/audit-rules/audit-rules-nodejs.yml +0 -662
  101. package/lib/audit-rules/audit-rules-npm.yml +0 -187
  102. package/lib/audit-rules/audit-rules-paths.yml +0 -98
  103. package/lib/audit-rules/audit-rules-performance.yml +0 -245
  104. package/lib/audit-rules/audit-rules-php.yml +0 -101
  105. package/lib/audit-rules/audit-rules-private.yml +0 -24
  106. package/lib/audit-rules/audit-rules-python.yml +0 -106
  107. package/lib/audit-rules/audit-rules-robustness.yml +0 -31
  108. package/lib/audit-rules/audit-rules-rust.yml +0 -109
  109. package/lib/audit-rules/audit-rules-structure.yml +0 -158
  110. package/lib/audit-rules/audit-rules-swift.yml +0 -99
  111. package/lib/audit-rules/audit-rules-template.yml +0 -108
  112. package/lib/audit-ui-sdk/contract.js +0 -117
  113. package/lib/audit-ui-sdk/index.js +0 -17
  114. package/lib/checks/button-bind.js +0 -347
  115. package/lib/checks/common.js +0 -170
  116. package/lib/checks/credential-file.js +0 -43
  117. package/lib/checks/dataflow.js +0 -40
  118. package/lib/checks/dispatch.js +0 -117
  119. package/lib/checks/dup-code.js +0 -69
  120. package/lib/checks/dup-const.js +0 -232
  121. package/lib/checks/file-health.js +0 -150
  122. package/lib/checks/filter.js +0 -137
  123. package/lib/checks/folder.js +0 -173
  124. package/lib/checks/fs-scanner.js +0 -57
  125. package/lib/checks/hardcoded-path.js +0 -98
  126. package/lib/checks/index.js +0 -49
  127. package/lib/checks/io.js +0 -66
  128. package/lib/checks/magic-number.js +0 -42
  129. package/lib/checks/npm-json.js +0 -273
  130. package/lib/checks/private.js +0 -64
  131. package/lib/checks/regex.js +0 -298
  132. package/lib/checks/scope-collision.js +0 -68
  133. package/lib/checks/semantic.js +0 -134
  134. package/lib/checks/structural.js +0 -281
  135. package/lib/cli/commands-audit.mjs +0 -142
  136. package/lib/cli/commands-doc.mjs +0 -127
  137. package/lib/client-parts/audit/audit.js +0 -301
  138. package/lib/exempt/tool.js +0 -198
  139. package/lib/git/module-splitter.js +0 -47
  140. package/lib/link-check/index.js +0 -187
  141. package/lib/lint-adapter/detect.js +0 -161
  142. package/lib/lint-adapter/index.js +0 -50
  143. package/lib/lint-adapter/runner.js +0 -133
  144. package/lib/preprocess/audit.js +0 -98
  145. package/lib/preprocess/index.js +0 -78
  146. package/lib/rule/compilers/credential.js +0 -62
  147. package/lib/rule/compilers/dataflow.js +0 -38
  148. package/lib/rule/compilers/file-health.js +0 -75
  149. package/lib/rule/compilers/frontend.js +0 -86
  150. package/lib/rule/compilers/func.js +0 -35
  151. package/lib/rule/compilers/helpers.js +0 -71
  152. package/lib/rule/compilers/index.js +0 -29
  153. package/lib/rule/compilers/link-semantic.js +0 -45
  154. package/lib/rule/compilers/list-kinds.js +0 -12
  155. package/lib/rule/compilers/numeric-kinds.js +0 -73
  156. package/lib/rule/compilers/regex.js +0 -78
  157. package/lib/rule/compilers/structure.js +0 -107
  158. package/lib/rule/compilers.js +0 -17
  159. package/lib/rule/homoglyph.js +0 -45
  160. package/lib/rule/loader.js +0 -274
  161. package/lib/rule/registry.js +0 -122
  162. package/lib/rule/scope.js +0 -67
  163. package/lib/score/docs-score.js +0 -166
  164. package/lib/score/index.js +0 -234
  165. package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
  166. package/scripts/audit-ext/_example-readme-present.mjs +0 -34
  167. package/scripts/audit-ext/dsh-inject-declarations.mjs +0 -209
  168. package/scripts/audit-ext/variable-min-length.mjs +0 -102
  169. package/scripts/audit-gate.mjs +0 -235
  170. package/scripts/audit-runner.mjs +0 -35
  171. package/scripts/audit-runtime-check.mjs +0 -129
  172. package/scripts/browser-page-probe.mjs +0 -271
  173. package/scripts/check-js-scope.mjs +0 -87
  174. package/scripts/clean-date-comments.py +0 -102
  175. package/scripts/cpu-sample.mjs +0 -188
  176. package/scripts/doc-drift.mjs +0 -200
  177. package/scripts/hot-path-probe-cjs.cjs +0 -71
  178. package/scripts/hot-path-probe-fs-shim.mjs +0 -28
  179. package/scripts/hot-path-probe-fsp-shim.mjs +0 -31
  180. package/scripts/hot-path-probe.mjs +0 -153
  181. package/scripts/module-splitter.py +0 -800
  182. package/scripts/picker-repro.mjs +0 -115
  183. package/scripts/platform-scan.mjs +0 -168
  184. package/scripts/probe-recheck.mjs +0 -47
  185. package/scripts/rename-locator.mjs +0 -97
  186. package/scripts/rule-switch.mjs +0 -97
  187. package/scripts/rules-solo-audit.mjs +0 -173
  188. package/scripts/scan-file-io.mjs +0 -717
  189. package/scripts/scan-fs-hotspots.mjs +0 -107
  190. package/scripts/symbol-index.mjs +0 -85
  191. package/scripts/verify-prestep.mjs +0 -100
  192. package/skills/dev/audit-rule-authoring.md +0 -58
  193. package/skills/guide/guide-audit.md +0 -270
  194. /package/lib/{audit → app}/ownership.js +0 -0
  195. /package/lib/app/{schema-audit.js → schema-preprocess.js} +0 -0
  196. /package/lib/{audit-defaults.js → git/defaults.js} +0 -0
@@ -1,173 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * rules-solo-audit —— yml 规则单启控制变量扫描(按需运行,非测试常驻)
4
- *
5
- * 用途:评估每条 audit-rules-*.yml 规则的有效性与局限——「控制变量法」:
6
- * ① 基准:不启用任何规则跑审计(仅剩结构类 finding,如 tree-doc)
7
- * ② 循环:每次只启用**一条**规则跑全量审计(其余规则全部不加载)
8
- * ③ 对比每规则「单独启用」的 findings 数/涉及文件/样例 → 判断该规则:
9
- * 有效(能抓住真问题)/ 误报多(噪音)/ 盲区(该抓的没抓到)——结果需 AI + 人工审。
10
- *
11
- * 实现:auditFull 支持 rulesetDir 整体替换规则目录——为每条规则在临时目录重建
12
- * 「单规则 yml」(命名 audit-rules-nodejs.yml 占默认 slot,FORCE_LOAD_SLOTS 兜底不触发),
13
- * 其余 slot 缺失即不加载 → 审计只跑该规则。规则条目按原 yml 字段格式重建
14
- * (JSON 序列化数组切片会丢 `-` 列表项,已实测不可用;手写字段行可行)。
15
- *
16
- * 用法:
17
- * node scripts/rules-solo-audit.mjs <repo> # 全部规则(107 条,耗时较长)
18
- * node scripts/rules-solo-audit.mjs <repo> --limit 10 # 前 10 条(小样本)
19
- * node scripts/rules-solo-audit.mjs <repo> --ids io-risk,camel # 指定规则(id 子串匹配)
20
- * node scripts/rules-solo-audit.mjs <repo> --out 报告.md [--json]
21
- *
22
- * 输出:默认 <repo>/audit-rules-solo/<时间戳>-<仓库名>.md(表格 + 每规则详情/样例)
23
- */
24
- import { readFileSync, writeFileSync, mkdirSync, rmSync, existsSync, mkdtempSync } from 'node:fs';
25
- import { join, basename, resolve } from 'node:path';
26
- import { fileURLToPath } from 'node:url';
27
- import { tmpdir } from 'node:os';
28
-
29
- const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
30
- import { dirname } from 'node:path';
31
-
32
- /* ───────── 规则单测脚本常量 ───────── */
33
- const DESC_MAX_LEN = 80; // 规则描述截断长度
34
- import { loadRuleFiles } from '../lib/rule/loader.js';
35
-
36
- /** 规则对象 → 单条 yml 条目(保字段,数组/对象 JSON 内联,字符串引号)。 */
37
- function ruleToYmlEntry(r) {
38
- const lines = [];
39
- for (const [k, v] of Object.entries(r)) {
40
- if (k === '__slot' || v === undefined || v === null) continue;
41
- lines.push(` ${k}: ${JSON.stringify(v)}`);
42
- }
43
- return ` - ${lines.join('\n')}`;
44
- }
45
-
46
- /** 临时 ruleset:metadata + 单条/零条规则(命名占 nodejs 默认 slot)。 */
47
- function makeSoloRuleset(ruleOrNull) {
48
- const dir = mkdtempSync(join(tmpdir(), 'dshgp-solo-'));
49
- const rulesBlock = ruleOrNull ? ruleToYmlEntry(ruleOrNull) : ' # 空规则(基准)';
50
- const yml = [
51
- 'metadata:',
52
- ' name: "solo-ruleset"',
53
- ' version: "1.0"',
54
- ' language: "javascript"',
55
- 'rules:',
56
- rulesBlock,
57
- '',
58
- ].join('\n');
59
- writeFileSync(join(dir, 'audit-rules-nodejs.yml'), yml);
60
- return dir;
61
- }
62
-
63
- /** 跑一次全量审计(指定 ruleset),返回 findings 数组。 */
64
- async function auditWithRuleset(repo, rulesetDir) {
65
- await import('../lib/rule/compilers.js');
66
- const { auditFull } = await import('../lib/audit/orchestrate.js');
67
- const r = await auditFull(repo, { rulesetDir });
68
- return (r.findings || []).filter((f) => f.rule && !f.rule.startsWith('structure/'));
69
- }
70
-
71
- /**
72
- * 主流程:基准(空规则)→ 每规则单启 → 报告。
73
- * @param {string} repo 目标仓库
74
- * @param {{limit?: number, ids?: string[], out?: string, json?: boolean}} opts
75
- */
76
- export async function runRulesSoloAudit(repo, opts = {}) {
77
- const rules = loadRuleFiles().merged.rules || [];
78
- const picked = opts.ids && opts.ids.length
79
- ? rules.filter((r) => opts.ids.some((s) => r.id.toLowerCase().includes(s.toLowerCase())))
80
- : rules;
81
- const limited = opts.limit && opts.limit > 0 ? picked.slice(0, opts.limit) : picked;
82
- if (!limited.length) return { ok: false, error: '没有匹配的规则(--ids 子串匹配不到,或规则集为空)' };
83
-
84
- // ① 基准:空规则
85
- const baseDir = makeSoloRuleset(null);
86
- let base = [];
87
- try { base = await auditWithRuleset(repo, baseDir); } finally { rmSync(baseDir, { recursive: true, force: true }); }
88
-
89
- // ② 全量对照(一次全量审计,按规则分组 = 每规则真实命中数,控制变量基准的另一参照)
90
- let fullFindings = [];
91
- try { fullFindings = await auditWithRuleset(repo, ''); } catch { fullFindings = []; }
92
- const fullByRule = new Map();
93
- for (const f of fullFindings) {
94
- if (!fullByRule.has(f.rule)) fullByRule.set(f.rule, []);
95
- fullByRule.get(f.rule).push(f);
96
- }
97
-
98
- // ③ 每规则单启
99
- const rows = [];
100
- for (let i = 0; i < limited.length; i += 1) {
101
- const rule = limited[i];
102
- const dir = makeSoloRuleset(rule);
103
- let solo = [];
104
- try { solo = await auditWithRuleset(repo, dir); } catch (e) { solo = []; }
105
- finally { rmSync(dir, { recursive: true, force: true }); }
106
- const byFile = new Set(solo.map((f) => f.file));
107
- const fullHits = fullByRule.get(rule.id) || [];
108
- rows.push({
109
- id: rule.id, name: rule.name || '', severity: rule.severity || '', category: rule.category || '',
110
- desc: (rule.description || '').slice(0, DESC_MAX_LEN),
111
- findings: solo.length, files: byFile.size,
112
- fullHits: fullHits.length, fullFiles: new Set(fullHits.map((f) => f.file)).size,
113
- baseDelta: solo.length - base.length,
114
- samples: (solo.length ? solo : fullHits).slice(0, 3).map((f) => `${f.file}${f.line ? ':' + f.line : ''} — ${String(f.message || '').slice(0, 70)}`),
115
- });
116
- }
117
-
118
- const report = {
119
- generatedAt: new Date().toISOString(), repo, baseFindings: base.length,
120
- rulesScanned: limited.length, rows,
121
- };
122
- if (opts.json) return { ok: true, ...report };
123
-
124
- // md 报告
125
- const L = [];
126
- L.push(`# 规则单启控制变量审计 · ${basename(repo)}`, '');
127
- L.push(`> 生成:${report.generatedAt} | 基准(无规则)findings:${base.length} | 扫描规则:${report.rulesScanned} 条`);
128
- L.push('> 说明:全量命中 = 完整规则集下该规则的 findings 数(真实命中,可靠参照);单启 = 只启用该规则的审计结果(执行链局限时可能为 0,以全量列为准)。findings 越多噪音越大;0 且该抓的没抓 = 盲区。**需 AI + 人工审有效性与局限**。', '');
129
- L.push('', '| 规则 | severity | 全量命中 | 单启 | vs 基准 | 说明 |');
130
- L.push('|---|---|---|---|---|---|');
131
- for (const r of rows) {
132
- const delta = r.baseDelta > 0 ? `+${r.baseDelta}` : String(r.baseDelta);
133
- L.push(`| ${r.id} | ${r.severity} | ${r.fullHits} | ${r.findings} | ${delta} | ${r.name || r.desc} |`);
134
- }
135
- L.push('');
136
- for (const r of rows) {
137
- L.push(`### ${r.id}(${r.severity})`, '');
138
- L.push(`${r.desc}`, '');
139
- L.push(`全量命中 ${r.fullHits} 条 / 单启 ${r.findings} 条(vs 基准 ${r.baseDelta})`, '');
140
- if (r.findings === 0 && r.fullHits > 0) L.push('> ⚠ 单启未产出(执行链与完整规则集耦合的已知局限)——请以「全量命中」列为准做人工审,并核对样例。', '');
141
- if (r.samples.length) {
142
- L.push('样例:', '');
143
- for (const s of r.samples) L.push(`- \`${s}\``);
144
- } else {
145
- L.push('样例:(无 finding——该规则对当前仓库无命中,需人工判断是「仓库干净」还是「规则盲区」)', '');
146
- }
147
- L.push('');
148
- }
149
- return { ok: true, md: L.join('\n'), rows, baseFindings: base.length, rulesScanned: limited.length };
150
- }
151
-
152
- /* ───────────────────────── CLI(仅直接运行时) ───────────────────────── */
153
- if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
154
- const args = process.argv.slice(2);
155
- const repo = args.find((a) => !a.startsWith('--')) || process.cwd();
156
- const limitArg = args.find((a) => a.startsWith('--limit'));
157
- const idsArg = args.find((a) => a.startsWith('--ids'));
158
- const outArg = args.find((a) => a.startsWith('--out'));
159
- const isJson = args.includes('--json');
160
- const limit = limitArg ? Number(limitArg.split('=')[1] || args[args.indexOf(limitArg) + 1] || 0) : 0;
161
- const ids = idsArg ? (idsArg.split('=')[1] || args[args.indexOf(idsArg) + 1] || '').split(',').map((s) => s.trim()).filter(Boolean) : [];
162
- const out = outArg ? (outArg.split('=')[1] || args[args.indexOf(outArg) + 1] || '') : '';
163
- const r = await runRulesSoloAudit(resolve(repo), { limit, ids, out, json: isJson });
164
- if (!r.ok) { console.error(`❌ ${r.error}`); process.exit(1); }
165
- if (isJson) { console.log(JSON.stringify({ ok: true, repo, baseFindings: r.baseFindings, rulesScanned: r.rulesScanned, rows: r.rows }, null, 2)); process.exit(0); }
166
- const target = out
167
- ? resolve(out)
168
- : join(resolve(repo), 'audit-rules-solo', `${new Date().toISOString().replace(/[:.]/g, '-')}-${basename(repo)}.md`);
169
- mkdirSync(dirname(target), { recursive: true });
170
- writeFileSync(target, r.md, 'utf8');
171
- console.log(`✅ 规则单启审计完成:${r.rulesScanned} 条规则 / 基准 ${r.baseFindings} findings → ${target}`);
172
- console.log('(结果需 AI + 人工审:逐条判断规则有效性与局限)');
173
- }