dsh-git-push 2.20.11 → 2.20.17

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 (58) hide show
  1. package/README.md +10 -6
  2. package/cli-audit.mjs +141 -0
  3. package/cli-tool.mjs +86 -0
  4. package/cli.mjs +114 -335
  5. package/lib/app/command-registry.js +3 -2
  6. package/lib/app/constants.js +9 -0
  7. package/lib/app/handlers/clone.js +12 -3
  8. package/lib/app/handlers/http-constants.js +11 -2
  9. package/lib/app/handlers/npm.js +4 -2
  10. package/lib/app/handlers/repos.js +10 -1
  11. package/lib/app/handlers/settings.js +9 -1
  12. package/lib/app/http-handlers.js +24 -3
  13. package/lib/app/schema-audit.js +42 -0
  14. package/lib/app/schema.js +19 -19
  15. package/lib/app/settings-bridge.js +51 -0
  16. package/lib/app/tool-call.js +7 -5
  17. package/lib/audit-rules/audit-rules-paths.yml +7 -1
  18. package/lib/audit-ui-sdk/contract.js +117 -0
  19. package/lib/audit-ui-sdk/index.js +17 -0
  20. package/lib/checks/regex.js +6 -1
  21. package/lib/cli/commands-audit.mjs +12 -17
  22. package/lib/cli/commands-tool.mjs +93 -0
  23. package/lib/cli/commands-vcs.mjs +2 -1
  24. package/lib/cli/shared.mjs +448 -0
  25. package/lib/client-parts/{account.js → git/account.js} +1 -1
  26. package/lib/client-parts/{actions.js → git/actions.js} +26 -11
  27. package/lib/client-parts/{apply.js → git/apply.js} +1 -1
  28. package/lib/client-parts/{browser.js → git/browser.js} +1 -1
  29. package/lib/client-parts/{const.js → git/const.js} +6 -1
  30. package/lib/client-parts/{controller.js → git/controller.js} +23 -11
  31. package/lib/client-parts/{icons.js → git/icons.js} +1 -1
  32. package/lib/client-parts/{loader.js → git/loader.js} +1 -1
  33. package/lib/client-parts/{npm.js → git/npm.js} +1 -1
  34. package/lib/client-parts/{page.js → git/page.js} +11 -21
  35. package/lib/client-parts/{repo.js → git/repo.js} +1 -1
  36. package/lib/client-parts/{settings.js → git/settings.js} +1 -1
  37. package/lib/client-parts/{utils.js → git/utils.js} +1 -1
  38. package/lib/client.js +75 -354
  39. package/lib/commit-push/pre-commit-engine.js +388 -0
  40. package/lib/commit-push.js +42 -20
  41. package/lib/git/transport.js +31 -10
  42. package/lib/http/index.js +82 -10
  43. package/lib/npm/npmrc.js +22 -5
  44. package/lib/self/index.js +1 -1
  45. package/package.json +6 -2
  46. package/scripts/audit-gate.mjs +235 -0
  47. package/scripts/build-client.mjs +15 -8
  48. package/scripts/check.mjs +12 -3
  49. package/scripts/scan-file-io.mjs +5 -1
  50. package/scripts/scan-version.mjs +10 -7
  51. package/skills/dev/dsh-git-push.md +62 -0
  52. package/skills/guide/guide-audit.md +11 -11
  53. package/skills/guide/guide-cli-scripts.md +3 -3
  54. package/skills/guide/guide-commit-push.md +2 -2
  55. package/skills/guide/guide-inject-ui.md +0 -16
  56. package/assets/start.sh +0 -396
  57. package/scripts/scan-hardcoded-paths.mjs +0 -125
  58. /package/lib/client-parts/{audit.js → audit/audit.js} +0 -0
@@ -1,125 +0,0 @@
1
- #!/usr/bin/env node
2
- // dsh-skip-i18n: CLI 输出硬编码中文为产品行为(无 i18n 需求)
3
- /**
4
- * scan-hardcoded-paths.mjs — 硬编码绝对路径的 dry-run 展示与改写(**调用审计引擎**)
5
- *
6
- * ⚠️ 本脚本**不含任何检测逻辑**(曾自带一份 PATTERNS,已删除 ✗ —— 同一事实两份实现必然分叉)。
7
- * 检测的唯一来源是审计引擎:
8
- * · 规则声明(正则初筛):lib/audit-rules/audit-rules-paths.yml → paths/hardcoded-absolute-path
9
- * · 精筛实现(fs 可访问性 + 相对路径换算):lib/checks/hardcoded-path.js
10
- * 本脚本只做三件事:① 跑引擎拿 findings(确认哪些文件/行被规则判为硬编码路径);
11
- * ② 展示 dry-run 表(可访问 ⇒ 附相对路径;不可访问 ⇒ 仅警告);③ `--write` 时才改写。
12
- *
13
- * 用法:
14
- * node scripts/scan-hardcoded-paths.mjs [--root <目录>] [--write] [--json] [--quiet]
15
- * --write 才写盘(默认 dry-run);--json 机器可读。
16
- */
17
- import { readFileSync, writeFileSync, existsSync } from 'node:fs';
18
- import { resolve, relative, join } from 'node:path';
19
- import { fileURLToPath } from 'node:url';
20
- import { hardcodedAbsPathHits, describeHardcodedAbsPath } from '../lib/checks/hardcoded-path.js';
21
- import { auditFull } from '../lib/audit/orchestrate.js';
22
-
23
- /** 本脚本只服务这一条规则(口径与引擎一致)。 */
24
- export const RULE_ID = 'paths/hardcoded-absolute-path';
25
-
26
- const argv = process.argv.slice(2);
27
- const has = (f) => argv.includes(f);
28
- const val = (f, d = '') => { const i = argv.indexOf(f); return i >= 0 && argv[i + 1] ? argv[i + 1] : d; };
29
-
30
- /**
31
- * 跑审计引擎,取本规则的 findings(**引擎是检测的唯一来源**)。
32
- * @returns {Promise<Array<{file:string,line:number,message:string}>>}
33
- */
34
- export async function engineFindings(root) {
35
- const abs = resolve(root);
36
- const res = await auditFull(abs, { scope: 'full' });
37
- const out = [];
38
- const walk = (x) => {
39
- if (Array.isArray(x)) return x.forEach(walk);
40
- if (x && typeof x === 'object') {
41
- const id = x.ruleId || x.id || x.rule;
42
- if (id && String(id).includes('hardcoded-absolute-path')) {
43
- out.push({ file: String(x.file || ''), line: Number(x.line) || 0, message: String(x.message || '') });
44
- }
45
- Object.values(x).forEach(walk);
46
- }
47
- };
48
- walk(res?.findings || res);
49
- return out;
50
- }
51
-
52
- /**
53
- * 组装 dry-run 报告:以**引擎 findings** 判定"哪些行是问题",用**引擎精筛实现**取详情
54
- * (可访问性 + 相对路径),两者同源 ⇒ 不会出现"脚本说有问题、审计说没问题"的分叉。
55
- */
56
- export async function scanHardcodedPaths(root) {
57
- const abs = resolve(root);
58
- const findings = await engineFindings(abs);
59
- const byFile = new Map();
60
- for (const f of findings) {
61
- const p = f.file ? (f.file.startsWith('/') ? f.file : join(abs, f.file)) : '';
62
- if (!p || !existsSync(p)) continue;
63
- if (!byFile.has(p)) byFile.set(p, new Set());
64
- byFile.get(p).add(f.line);
65
- }
66
- const hits = [];
67
- for (const [file, lines] of byFile) {
68
- const text = readFileSync(file, 'utf8');
69
- // 同一行可能被多条模式命中(如 `file:///volume9/x` 同时命中 file-url 与 posix)⇒
70
- // 同一行只保留**最具体**(raw 最长)的那条,避免一行报两次、计数虚高。
71
- const byLine = new Map();
72
- for (const h of hardcodedAbsPathHits(text, file, abs)) {
73
- if (!lines.has(h.line)) continue;
74
- const prev = byLine.get(h.line);
75
- if (!prev || h.raw.length > prev.raw.length) byLine.set(h.line, h);
76
- }
77
- for (const h of byLine.values()) hits.push({ ...h, file, relFile: relative(abs, file) || file });
78
- }
79
- return { root: abs, findings: findings.length, hits };
80
- }
81
-
82
- /** CLI 主流程。 */
83
- async function main() {
84
- const ROOT = resolve(val('--root', process.cwd()));
85
- const WRITE = has('--write');
86
- const JSON_OUT = has('--json');
87
- const QUIET = has('--quiet');
88
- const { hits } = await scanHardcodedPaths(ROOT);
89
- const accessible = hits.filter((h) => h.accessible);
90
- const inaccessible = hits.filter((h) => !h.accessible);
91
- const byOs = hits.reduce((a, h) => ((a[h.os] = (a[h.os] || 0) + 1), a), {});
92
-
93
- if (JSON_OUT) {
94
- console.log(JSON.stringify({ ok: hits.length === 0, root: ROOT, total: hits.length, accessible: accessible.length, inaccessible: inaccessible.length, byOs, hits }, null, 2));
95
- process.exit(hits.length ? 1 : 0);
96
- }
97
- if (!QUIET) console.log(`扫描根:${ROOT}(检测来源:审计引擎 ${RULE_ID})`);
98
- if (!hits.length) { console.log('硬编码绝对路径 ✅ 未发现'); process.exit(0); }
99
- for (const h of hits) {
100
- console.log(`⚠️ ${h.relFile}:${h.line} [${h.os}] ${h.raw}`);
101
- console.log(` ${h.accessible ? '→ 可访问 ⇒ dry-run 相对路径:' + (h.relative || '.') : '(本机不可访问 ⇒ 仅警告,无法换算)'}`);
102
- }
103
- console.log(`\n汇总:命中 ${hits.length} · 可访问 ${accessible.length} · 不可访问 ${inaccessible.length} · 分类 ${JSON.stringify(byOs)}`);
104
- if (!WRITE) { console.log('(dry-run:未写入任何文件;要真改加 --write)'); process.exit(hits.length ? 1 : 0); }
105
-
106
- let changed = 0;
107
- const byFile = new Map();
108
- for (const h of accessible) if (h.relative) { if (!byFile.has(h.file)) byFile.set(h.file, []); byFile.get(h.file).push(h); }
109
- for (const [file, list] of byFile) {
110
- let text = readFileSync(file, 'utf8');
111
- for (const h of list) {
112
- if (!text.includes(h.raw)) continue;
113
- console.log(` 改写 ${relative(ROOT, file)}: ${h.raw} → ${h.relative} (${describeHardcodedAbsPath(h)})`);
114
- text = text.split(h.raw).join(h.relative);
115
- changed += 1;
116
- }
117
- writeFileSync(file, text, 'utf8');
118
- }
119
- console.log(`✅ --write 完成:改写 ${changed} 处`);
120
- process.exit(0);
121
- }
122
-
123
- // ⚠️ 入口判断必须用 fileURLToPath:`new URL(...).pathname` 是 URL 编码的(含中文路径时是 %E5%B7%A5…),
124
- // 与 process.argv[1] 永不相等 ⇒ main() 静默不执行(实测踩到)。
125
- if (process.argv[1] && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url))) main();
File without changes