dsh-git-push 0.0.0-stage → 2.8.6

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 (279) hide show
  1. package/.auditignore +30 -0
  2. package/.gitignore +39 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1486 -2
  5. package/cli.mjs +360 -0
  6. package/cordis.patch.yml +14 -0
  7. package/lib/ARCHITECTURE.md +34 -0
  8. package/lib/BUGFIX-NOTES-2026-09-14.md +278 -0
  9. package/lib/app/apply.js +275 -0
  10. package/lib/app/audit-api.js +158 -0
  11. package/lib/app/command-registry.js +266 -0
  12. package/lib/app/constants.js +16 -0
  13. package/lib/app/handlers/account.js +166 -0
  14. package/lib/app/handlers/clone.js +168 -0
  15. package/lib/app/handlers/http-constants.js +9 -0
  16. package/lib/app/handlers/identity-rewrite.js +94 -0
  17. package/lib/app/handlers/meta.js +175 -0
  18. package/lib/app/handlers/npm.js +169 -0
  19. package/lib/app/handlers/repo-actions.js +143 -0
  20. package/lib/app/handlers/repos.js +231 -0
  21. package/lib/app/handlers/settings.js +62 -0
  22. package/lib/app/host-doc-checks.js +25 -0
  23. package/lib/app/http-handlers.js +131 -0
  24. package/lib/app/index.js +30 -0
  25. package/lib/app/inject-text.js +192 -0
  26. package/lib/app/scan-root.js +23 -0
  27. package/lib/app/schema.js +150 -0
  28. package/lib/app/settings-bridge.js +167 -0
  29. package/lib/app/slash-commands.js +395 -0
  30. package/lib/app/slot-stats.js +35 -0
  31. package/lib/app/tool-call.js +672 -0
  32. package/lib/app/tools.js +34 -0
  33. package/lib/ast/brace.js +105 -0
  34. package/lib/ast/callgraph.js +135 -0
  35. package/lib/ast/code-lines.js +114 -0
  36. package/lib/ast/consts.js +12 -0
  37. package/lib/ast/control-flow.js +461 -0
  38. package/lib/ast/credential.js +199 -0
  39. package/lib/ast/dataflow.js +274 -0
  40. package/lib/ast/dup-code.js +165 -0
  41. package/lib/ast/index.js +36 -0
  42. package/lib/ast/io-risk-const.js +95 -0
  43. package/lib/ast/io-risk-fn.js +208 -0
  44. package/lib/ast/io-risk-loop.js +308 -0
  45. package/lib/ast/io-risk.js +314 -0
  46. package/lib/ast/lang.js +156 -0
  47. package/lib/ast/line-count.js +52 -0
  48. package/lib/ast/magic-number.js +272 -0
  49. package/lib/ast/naming.js +284 -0
  50. package/lib/ast/perf.js +472 -0
  51. package/lib/ast/scope.js +241 -0
  52. package/lib/ast/shell.js +131 -0
  53. package/lib/ast/size.js +378 -0
  54. package/lib/ast/symbol-index.js +399 -0
  55. package/lib/ast/tokenizer.js +341 -0
  56. package/lib/audit/analysis-coverage.js +98 -0
  57. package/lib/audit/audit-file.js +182 -0
  58. package/lib/audit/checks.js +17 -0
  59. package/lib/audit/client-entry.js +93 -0
  60. package/lib/audit/collector.js +477 -0
  61. package/lib/audit/ext-runner.js +80 -0
  62. package/lib/audit/file-context.js +138 -0
  63. package/lib/audit/finding.js +50 -0
  64. package/lib/audit/gitignore-match.js +113 -0
  65. package/lib/audit/glob.js +63 -0
  66. package/lib/audit/history-report.js +100 -0
  67. package/lib/audit/history.js +126 -0
  68. package/lib/audit/ignore-blind.js +101 -0
  69. package/lib/audit/index.js +33 -0
  70. package/lib/audit/orchestrate.js +476 -0
  71. package/lib/audit/public.js +24 -0
  72. package/lib/audit/repo-level.js +30 -0
  73. package/lib/audit/report-yaml.js +86 -0
  74. package/lib/audit/slot.js +65 -0
  75. package/lib/audit-defaults.js +18 -0
  76. package/lib/audit-rules/audit-rules-comment.yml +247 -0
  77. package/lib/audit-rules/audit-rules-cpp.yml +22 -0
  78. package/lib/audit-rules/audit-rules-docs.yml +32 -0
  79. package/lib/audit-rules/audit-rules-dsh.yml +162 -0
  80. package/lib/audit-rules/audit-rules-filehealth.yml +42 -0
  81. package/lib/audit-rules/audit-rules-folder.yml +99 -0
  82. package/lib/audit-rules/audit-rules-frontend.yml +335 -0
  83. package/lib/audit-rules/audit-rules-go.yml +22 -0
  84. package/lib/audit-rules/audit-rules-i18n.yml +45 -0
  85. package/lib/audit-rules/audit-rules-java.yml +105 -0
  86. package/lib/audit-rules/audit-rules-nodejs.yml +647 -0
  87. package/lib/audit-rules/audit-rules-npm.yml +187 -0
  88. package/lib/audit-rules/audit-rules-paths.yml +92 -0
  89. package/lib/audit-rules/audit-rules-performance.yml +215 -0
  90. package/lib/audit-rules/audit-rules-php.yml +22 -0
  91. package/lib/audit-rules/audit-rules-private.yml +24 -0
  92. package/lib/audit-rules/audit-rules-python.yml +106 -0
  93. package/lib/audit-rules/audit-rules-robustness.yml +27 -0
  94. package/lib/audit-rules/audit-rules-rust.yml +22 -0
  95. package/lib/audit-rules/audit-rules-structure.yml +159 -0
  96. package/lib/audit-rules/audit-rules-swift.yml +22 -0
  97. package/lib/audit-rules/audit-rules-template.yml +108 -0
  98. package/lib/checks/button-bind.js +276 -0
  99. package/lib/checks/common.js +170 -0
  100. package/lib/checks/credential-file.js +43 -0
  101. package/lib/checks/dataflow.js +40 -0
  102. package/lib/checks/dispatch.js +112 -0
  103. package/lib/checks/dup-code.js +69 -0
  104. package/lib/checks/dup-const.js +232 -0
  105. package/lib/checks/file-health.js +150 -0
  106. package/lib/checks/filter.js +137 -0
  107. package/lib/checks/folder.js +173 -0
  108. package/lib/checks/hardcoded-path.js +98 -0
  109. package/lib/checks/index.js +46 -0
  110. package/lib/checks/io.js +66 -0
  111. package/lib/checks/magic-number.js +42 -0
  112. package/lib/checks/npm-json.js +273 -0
  113. package/lib/checks/private.js +63 -0
  114. package/lib/checks/regex.js +256 -0
  115. package/lib/checks/semantic.js +134 -0
  116. package/lib/checks/structural.js +274 -0
  117. package/lib/cli/commands-account.mjs +107 -0
  118. package/lib/cli/commands-audit.mjs +144 -0
  119. package/lib/cli/commands-doc.mjs +127 -0
  120. package/lib/cli/commands-vcs.mjs +175 -0
  121. package/lib/client/index.js +162 -0
  122. package/lib/client-parts/00-loader.js +33 -0
  123. package/lib/client-parts/01-const.js +207 -0
  124. package/lib/client-parts/02-utils.js +62 -0
  125. package/lib/client-parts/03-icons.js +12 -0
  126. package/lib/client-parts/10-account.js +83 -0
  127. package/lib/client-parts/11-browser.js +95 -0
  128. package/lib/client-parts/20-repo.js +374 -0
  129. package/lib/client-parts/21-audit.js +301 -0
  130. package/lib/client-parts/22-settings.js +146 -0
  131. package/lib/client-parts/23-npm.js +383 -0
  132. package/lib/client-parts/30-page.js +56 -0
  133. package/lib/client-parts/40-controller.js +1092 -0
  134. package/lib/client-parts/41-actions.js +279 -0
  135. package/lib/client-parts/99-apply.js +72 -0
  136. package/lib/client.js +3195 -0
  137. package/lib/commit-push.js +148 -0
  138. package/lib/context/index.js +363 -0
  139. package/lib/core/atomic-json.js +98 -0
  140. package/lib/core/config.js +40 -0
  141. package/lib/core/credentials.js +274 -0
  142. package/lib/core/endpoints.js +109 -0
  143. package/lib/core/exec.js +162 -0
  144. package/lib/exempt/index.js +292 -0
  145. package/lib/fs/edit-after-read.js +103 -0
  146. package/lib/fsx.js +87 -0
  147. package/lib/git/account-status.js +140 -0
  148. package/lib/git/account.js +233 -0
  149. package/lib/git/api.js +136 -0
  150. package/lib/git/atomic-json.js +6 -0
  151. package/lib/git/browse.js +38 -0
  152. package/lib/git/clone-download.js +397 -0
  153. package/lib/git/clone-history-mode.js +143 -0
  154. package/lib/git/clone-history.js +175 -0
  155. package/lib/git/clone-jobs.js +250 -0
  156. package/lib/git/clone-replay-io.js +172 -0
  157. package/lib/git/clone-replay.js +275 -0
  158. package/lib/git/clone.js +445 -0
  159. package/lib/git/cloud.js +46 -0
  160. package/lib/git/commit-message.js +141 -0
  161. package/lib/git/config.js +6 -0
  162. package/lib/git/cred-env.js +88 -0
  163. package/lib/git/credentials.js +6 -0
  164. package/lib/git/endpoints.js +6 -0
  165. package/lib/git/exec.js +6 -0
  166. package/lib/git/identity-rewrite.js +297 -0
  167. package/lib/git/identity.js +150 -0
  168. package/lib/git/ignore.js +69 -0
  169. package/lib/git/index.js +41 -0
  170. package/lib/git/module-splitter.js +47 -0
  171. package/lib/git/post-push.js +101 -0
  172. package/lib/git/push-diagnose.js +142 -0
  173. package/lib/git/push.js +476 -0
  174. package/lib/git/remote-resolve.js +146 -0
  175. package/lib/git/remote.js +128 -0
  176. package/lib/git/repo-index.js +512 -0
  177. package/lib/git/repos.js +235 -0
  178. package/lib/git/scan-runner.js +159 -0
  179. package/lib/git/sensitive.js +134 -0
  180. package/lib/git/transport.js +430 -0
  181. package/lib/git/visibility.js +35 -0
  182. package/lib/git/wrapped-git.js +68 -0
  183. package/lib/http/index.js +170 -0
  184. package/lib/index.js +24 -0
  185. package/lib/link-check/index.js +187 -0
  186. package/lib/npm/account.js +64 -0
  187. package/lib/npm/install.js +211 -0
  188. package/lib/npm/npmrc.js +56 -0
  189. package/lib/npm/publish.js +171 -0
  190. package/lib/npm/registry.js +168 -0
  191. package/lib/plugin/auto-detect.js +92 -0
  192. package/lib/plugin/auto-push.js +154 -0
  193. package/lib/plugin/index.js +250 -0
  194. package/lib/readme-templates/readme.yml +38 -0
  195. package/lib/rule/compilers/credential.js +62 -0
  196. package/lib/rule/compilers/dataflow.js +38 -0
  197. package/lib/rule/compilers/file-health.js +75 -0
  198. package/lib/rule/compilers/frontend.js +86 -0
  199. package/lib/rule/compilers/func.js +35 -0
  200. package/lib/rule/compilers/helpers.js +71 -0
  201. package/lib/rule/compilers/index.js +29 -0
  202. package/lib/rule/compilers/link-semantic.js +45 -0
  203. package/lib/rule/compilers/list-kinds.js +12 -0
  204. package/lib/rule/compilers/numeric-kinds.js +66 -0
  205. package/lib/rule/compilers/regex.js +78 -0
  206. package/lib/rule/compilers/structure.js +80 -0
  207. package/lib/rule/compilers.js +17 -0
  208. package/lib/rule/homoglyph.js +45 -0
  209. package/lib/rule/loader.js +270 -0
  210. package/lib/rule/registry.js +115 -0
  211. package/lib/rule/scope.js +67 -0
  212. package/lib/score/docs-score.js +166 -0
  213. package/lib/score/index.js +140 -0
  214. package/lib/self/index.js +196 -0
  215. package/lib/skip-dirs.js +64 -0
  216. package/lib/tool-probes.json +50 -0
  217. package/lib/user-requirements.json +14 -0
  218. package/lib/vendor/js-yaml/LICENSE +21 -0
  219. package/lib/vendor/js-yaml/js-yaml.mjs +3073 -0
  220. package/package.json +95 -4
  221. package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
  222. package/scripts/audit-ext/_example-readme-present.mjs +34 -0
  223. package/scripts/audit-ext/variable-min-length.mjs +102 -0
  224. package/scripts/audit-runner.mjs +35 -0
  225. package/scripts/audit-runtime-check.mjs +129 -0
  226. package/scripts/browser-page-probe.mjs +271 -0
  227. package/scripts/build-client.mjs +119 -0
  228. package/scripts/check.mjs +88 -0
  229. package/scripts/clean-date-comments.py +102 -0
  230. package/scripts/cpu-sample.mjs +188 -0
  231. package/scripts/doc-drift.mjs +200 -0
  232. package/scripts/doc-func.mjs +212 -0
  233. package/scripts/doc-tree.mjs +456 -0
  234. package/scripts/doc-version.mjs +220 -0
  235. package/scripts/frontend-preview-check.mjs +124 -0
  236. package/scripts/hot-path-probe-cjs.cjs +71 -0
  237. package/scripts/hot-path-probe-fs-shim.mjs +28 -0
  238. package/scripts/hot-path-probe-fsp-shim.mjs +31 -0
  239. package/scripts/hot-path-probe.mjs +153 -0
  240. package/scripts/module-splitter.py +800 -0
  241. package/scripts/platform-scan.mjs +168 -0
  242. package/scripts/preview-gen.mjs +489 -0
  243. package/scripts/preview-local-runner.mjs +55 -0
  244. package/scripts/preview-server-direct.mjs +116 -0
  245. package/scripts/preview-server.mjs +305 -0
  246. package/scripts/preview-slot-data.mjs +123 -0
  247. package/scripts/probe-recheck.mjs +47 -0
  248. package/scripts/readme-gen.mjs +268 -0
  249. package/scripts/rename-locator.mjs +97 -0
  250. package/scripts/rule-switch.mjs +97 -0
  251. package/scripts/rules-solo-audit.mjs +173 -0
  252. package/scripts/scan-file-io.mjs +713 -0
  253. package/scripts/scan-hardcoded-paths.mjs +125 -0
  254. package/scripts/scan-repos.mjs +167 -0
  255. package/scripts/scan-version.mjs +122 -0
  256. package/scripts/scrub-user-wording.mjs +420 -0
  257. package/scripts/symbol-index.mjs +85 -0
  258. package/scripts/sync-plugin-install.mjs +223 -0
  259. package/scripts/sync-plugin.mjs +279 -0
  260. package/scripts/verify-prestep.mjs +100 -0
  261. package/skills/dev/audit-rule-authoring.md +58 -0
  262. package/skills/dev/dsh-git-push.md +323 -0
  263. package/skills/dev/git-push-live-fix.md +45 -0
  264. package/skills/dsh-repo-index.md +35 -0
  265. package/skills/guide/guide-audit.md +167 -0
  266. package/skills/guide/guide-cli-scripts.md +104 -0
  267. package/skills/guide/guide-clone-repos.md +173 -0
  268. package/skills/guide/guide-commit-push.md +156 -0
  269. package/skills/guide/guide-inject-ui.md +166 -0
  270. package/skills/guide/guide-slash-completion.md +118 -0
  271. package/skills/workflow/README.md +21 -0
  272. package/skills/workflow/git-commit-discipline.md +68 -0
  273. package/skills/workflow/git-project-startup.md +85 -0
  274. package/skills/workflow/git-rebuild-process.md +57 -0
  275. package/skills/workflow/github-operations.md +91 -0
  276. package/skills/workflow/readme-sync-git-md.md +28 -0
  277. package/skills/workflow/task-completion-report.md +73 -0
  278. package/skills/workflow/tool-json-add-ask.md +35 -0
  279. package/skills/workflow/versioning-rule.md +211 -0
@@ -0,0 +1,125 @@
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();
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dsh-git-push — 本地仓库「独立进程」离线扫描(增量流式)
4
+ *
5
+ * 由 HTTP 端点 `POST /api/git-push/repos-local-scan` 以 child_process.spawn 拉起,
6
+ * 独立于宿主/主进程运行(扫描 CPU 密集,绝不卡前台/拖垮宿主)。
7
+ *
8
+ * 逐仓流式:每扫到一个 owner(账号) 一致的仓库 →
9
+ * ① 增量写 scan-live.json(version 递增、found 追加)——宿主 fs.watchFile 变化即唤醒
10
+ * 前端等待者,前端只追加这一个(不全量重读);
11
+ * ② 把该仓库并入 dsh-repo-index.json(读-改-写追加 entry,不覆盖其他)。
12
+ * 全部扫完 → scan-live.json done:true → 前端收到收尾。
13
+ *
14
+ * 纯离线:只扫本地 .git,owner 用离线账号 json 比对,不联网(可见性回退「未知」)。
15
+ * 性能限制:--depth、--max 防拖垮系统;每仓库打一行 stdout 供宿主导出。
16
+ *
17
+ * 用法:node scripts/scan-repos.mjs --root <root> --owner <owner> [--depth 10] [--max 200]
18
+ * 退出码:0=成功,非0=失败
19
+ */
20
+ import { readFileSync, writeFileSync, renameSync, mkdirSync, existsSync } from 'node:fs';
21
+ import { join, dirname } from 'node:path';
22
+ import { fileURLToPath } from 'node:url';
23
+
24
+ // 以脚本位置解析仓库根:<repo>/scripts/ → <repo>
25
+ const __dir = dirname(fileURLToPath(import.meta.url));
26
+ const REPO_ROOT = join(__dir, '..');
27
+
28
+ const DEFAULT_MAX_REPOS = 200; // --max 默认仓库数上限
29
+
30
+ function arg(name, def) {
31
+ const i = process.argv.indexOf(name);
32
+ return i !== -1 && process.argv[i + 1] ? process.argv[i + 1] : def;
33
+ }
34
+
35
+ function liveFile(wr) { return join(cfgDir(wr), 'scan-live.json'); }
36
+ function indexFile(wr) { return join(cfgDir(wr), 'dsh-repo-index.json'); }
37
+ function cfgDir(wr) { return credentialsDir({ workspaceRoot: wr || REPO_ROOT }); }
38
+ /** 原子写临时文件路径(目标文件 + pid 后缀,写完 rename 到位)。 */
39
+ function tmpPathOf(p) { return `${p}.${process.pid}.tmp`; }
40
+
41
+ let credentialsDir = null;
42
+ let scanRepos = null;
43
+ let parseGithubOwnerRepo = null;
44
+ let readAccountStatus = null;
45
+ let buildRepoListEntry = null;
46
+
47
+ async function main() {
48
+ const root = arg('--root', '');
49
+ const owner = arg('--owner', 'EIGHTfs');
50
+ const depth = Number(arg('--depth', '10')) || 10;
51
+ const max = Number(arg('--max', String(DEFAULT_MAX_REPOS))) || DEFAULT_MAX_REPOS;
52
+ if (!root) { console.error('缺 --root(扫描根路径)'); process.exit(2); }
53
+
54
+ // 顶层懒加载(独立进程 ESM,仅需的模块)
55
+ ({ credentialsDir } = await import(`${REPO_ROOT}/lib/git/credentials.js`));
56
+ ({ scanRepos } = await import(`${REPO_ROOT}/lib/git/repos.js`));
57
+ ({ parseGithubOwnerRepo } = await import(`${REPO_ROOT}/lib/git/api.js`));
58
+ // 可选模块:account-status 缺失或加载失败时,退化为「不做离线 owner 推断」
59
+ // (下面的 if (readAccountStatus) 已兜底),不影响扫描主流程。
60
+ try { ({ readAccountStatus } = await import(`${REPO_ROOT}/lib/git/account-status.js`)); } catch { /* 降级:缺该模块只影响 owner 推断,主流程继续 */ }
61
+
62
+ // 离线段 owner:优先账号 json 快照(不联网);无则参数/默认
63
+ let scanOwner = owner;
64
+ if (readAccountStatus) {
65
+ try {
66
+ const acct = readAccountStatus({ workspaceRoot: REPO_ROOT });
67
+ if (acct && acct.username) scanOwner = acct.username;
68
+ } catch { /* 忽略 */ }
69
+ }
70
+
71
+ process.stdout.write(`SCAN start root=${root} owner=${scanOwner} depth=${depth} max=${max}\n`);
72
+ const repos = scanRepos(root, { depth, maxRepos: max });
73
+ let foundCount = 0;
74
+ const scanned = new Set(); // 本轮扫到的仓库名(用于清理索引残留,见下)
75
+ for (const r of repos) {
76
+ if (!r || !r.remote) continue;
77
+ const pr = parseGithubOwnerRepo(r.remote);
78
+ if (!pr || pr.owner !== scanOwner) continue; // 只登记与离线账号 owner 一致的仓库
79
+ scanned.add(r.name);
80
+ pushLive({ workspaceRoot: REPO_ROOT, found: [r.name], done: false });
81
+ appendIndexEntry({
82
+ workspaceRoot: REPO_ROOT,
83
+ owner: scanOwner,
84
+ entry: {
85
+ name: r.name,
86
+ path: r.path || '',
87
+ repoUrl: `https://api.github.com/repos/${pr.owner}/${pr.repo}`,
88
+ visibility: '未知', // 离线不查 GitHub API,可见性回退未知
89
+ cloneCmd: `git_clone target=${pr.owner}/${pr.repo}`,
90
+ skills: [],
91
+ },
92
+ });
93
+ foundCount += 1;
94
+ process.stdout.write(`SCAN found ${r.name} (${foundCount})\n`);
95
+ }
96
+ // 清理索引残留——此前只「追加/更新」不删除,被 .gitignore 忽略后不再扫到的
97
+ // 仓库(如 DeepSeekHarness-NAS 的 source 构建产物)会永远留在索引里。这里按本轮结果
98
+ // 剔除「owner 一致但本轮未扫到」的条目,保证索引 = 本次扫描结果。
99
+ const removed = pruneIndex({ workspaceRoot: REPO_ROOT, owner: scanOwner, scanned });
100
+ if (removed.length) process.stdout.write(`SCAN pruned ${removed.join(',')}\n`);
101
+ pushLive({ workspaceRoot: REPO_ROOT, found: [], done: true });
102
+ process.stdout.write(`SCAN done ok=true count=${foundCount}\n`);
103
+ process.exit(0);
104
+ }
105
+
106
+ /** 剔除索引中「owner 一致但本轮未扫到」的条目,返回被移除的仓库名(保证索引=扫描结果)。 */
107
+ function pruneIndex({ workspaceRoot, owner, scanned }) {
108
+ const p = indexFile(workspaceRoot);
109
+ let doc = null;
110
+ try { if (existsSync(p)) doc = JSON.parse(readFileSync(p, 'utf8')); } catch { return []; }
111
+ if (!doc || !Array.isArray(doc.repos)) return [];
112
+ const removed = [];
113
+ const kept = doc.repos.filter((r) => {
114
+ if (!r || !r.name) return false;
115
+ if (scanned.has(r.name)) return true;
116
+ // 只清理「本账号所属」的条目(别的 owner 的条目不动,避免误删手动登记的)
117
+ const match = String(r.repoUrl || '').match(/\/repos\/([^/]+)\//);
118
+ const rowOwner = match ? match[1] : '';
119
+ if (rowOwner && rowOwner !== owner) return true;
120
+ removed.push(r.name);
121
+ return false;
122
+ });
123
+ if (!removed.length) return [];
124
+ doc.repos = kept;
125
+ doc.generatedAt = new Date().toISOString();
126
+ const dir = dirname(p); mkdirSync(dir, { recursive: true });
127
+ const tmpPath = tmpPathOf(p);
128
+ writeFileSync(tmpPath, JSON.stringify(doc, null, 2) + '\n', 'utf8');
129
+ renameSync(tmpPath, p);
130
+ return removed;
131
+ }
132
+
133
+ /** 递增写 scan-live.json:version+1、found 追加、done 标记。 */
134
+ function pushLive({ workspaceRoot, found, done }) {
135
+ const p = liveFile(workspaceRoot);
136
+ let cur = { version: 0, found: [], startedAt: '', done: false };
137
+ try { if (existsSync(p)) cur = JSON.parse(readFileSync(p, 'utf8')); } catch { /* 忽略 */ }
138
+ cur.version = (Number(cur.version) || 0) + 1;
139
+ if (Array.isArray(found)) for (const f of found) if (!cur.found.includes(f)) cur.found.push(f);
140
+ cur.done = !!done;
141
+ const dir = dirname(p); mkdirSync(dir, { recursive: true });
142
+ const tmpPath = tmpPathOf(p);
143
+ writeFileSync(tmpPath, JSON.stringify(cur, null, 2) + '\n', 'utf8');
144
+ renameSync(tmpPath, p);
145
+ }
146
+
147
+ /** 把单条仓库 entry 追加进 dsh-repo-index.json(读-改-写,不覆盖其他)。 */
148
+ function appendIndexEntry({ workspaceRoot, entry, owner }) {
149
+ const p = indexFile(workspaceRoot);
150
+ let doc = null;
151
+ try { if (existsSync(p)) doc = JSON.parse(readFileSync(p, 'utf8')); } catch { /* 忽略 */ }
152
+ if (!doc || !Array.isArray(doc.repos)) {
153
+ doc = { name: 'dsh-repo-index', description: '', version: 1, generatedAt: new Date().toISOString(), owner: owner || 'EIGHTfs', repos: [], localOnly: [] };
154
+ }
155
+ const i = doc.repos.findIndex((r) => r && r.name === entry.name);
156
+ if (i >= 0) doc.repos[i] = entry; else doc.repos.push(entry);
157
+ doc.generatedAt = new Date().toISOString();
158
+ const dir = dirname(p); mkdirSync(dir, { recursive: true });
159
+ const tmpPath = tmpPathOf(p);
160
+ writeFileSync(tmpPath, JSON.stringify(doc, null, 2) + '\n', 'utf8');
161
+ renameSync(tmpPath, p);
162
+ }
163
+
164
+ main().catch((e) => {
165
+ console.error('SCAN fail:', e && e.message || e);
166
+ process.exit(4);
167
+ });
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+ // dsh-skip-i18n: CLI 输出硬编码中文为产品行为(无 i18n 需求)
3
+ /**
4
+ * scan-version.mjs — 版本一致性校验(自身总入口 0.1.4)
5
+ *
6
+ * 校验四处版本必须一致:
7
+ * 1) lib/self/index.js 的 VERSION(单一事实源)
8
+ * 2) package.json 的 version
9
+ * 3) cli.mjs HELP 文本里的 v${VERSION}
10
+ * 4) 版本列表宿主里的当前版本(适配分体式:优先 docs/CHANGELOG.md
11
+ * 的 dshgp-version 标记块;无则回退 README「## 版本列表」章节)
12
+ * 任一不一致 → exit 1(版本漂移拦截)。
13
+ *
14
+ * 用法:
15
+ * node scripts/scan-version.mjs # 校验(npm run scan-version)
16
+ * node scripts/scan-version.mjs --json # JSON 输出(机器可读)
17
+ */
18
+ import { readFileSync, existsSync } from 'node:fs';
19
+ import { join, dirname } from 'node:path';
20
+ import { fileURLToPath } from 'node:url';
21
+
22
+ import { VERSION, versionInfo, helpSync } from '../lib/self/index.js';
23
+
24
+ const __dirname = dirname(fileURLToPath(import.meta.url));
25
+ const ROOT = join(__dirname, '..');
26
+ const json = process.argv.includes('--json');
27
+
28
+ /**
29
+ * 从 README 正文提取版本列表里的当前版本(新增)。
30
+ *
31
+ * 策略:①先找「(当前)」标记行的版本(最精确:作者显式标注的当前版本)
32
+ * ②无标记 → 取「## 版本列表 / ## 版本记录 / ## 更新日志」章节内出现的最高版本
33
+ * 返回 { found, version, source };source 说明取值依据(便于排查)。
34
+ * @param {string} text README 全文
35
+ */
36
+ export function readmeVersion(text = '') {
37
+ const src = String(text || '');
38
+ if (!src) return { found: false, version: '', source: '' };
39
+ // ① 显式「当前」标记:| **1.2.3**(当前) | 或 - **1.2.3**(当前)
40
+ const cur = /\*{0,2}(\d+\.\d+\.\d+)\*{0,2}\s*[((]\s*当前\s*[))]/.exec(src);
41
+ if (cur) return { found: true, version: cur[1], source: '(当前)标记行' };
42
+ // ② 版本章节内取最高版本
43
+ const heads = ['## 版本列表', '## 版本记录', '## 版本历史', '## 更新日志', '## Changelog'];
44
+ let section = '';
45
+ for (const head of heads) {
46
+ const i = src.indexOf(head);
47
+ if (i < 0) continue;
48
+ const rest = src.slice(i + head.length);
49
+ const next = rest.indexOf('\n## ');
50
+ section = next >= 0 ? rest.slice(0, next) : rest;
51
+ break;
52
+ }
53
+ const scope = section || src;
54
+ const found = [...scope.matchAll(/\|\s*\*{0,2}(\d+\.\d+\.\d+)\*{0,2}/g)].map((m) => m[1]);
55
+ if (!found.length) return { found: false, version: '', source: '' };
56
+ const cmp = (a, b) => {
57
+ const pa = a.split('.').map(Number);
58
+ const pb = b.split('.').map(Number);
59
+ for (let i = 0; i < 3; i++) {
60
+ if (pa[i] !== pb[i]) return pa[i] - pb[i];
61
+ }
62
+ return 0;
63
+ };
64
+ const max = found.reduce((a, b) => (cmp(b, a) > 0 ? b : a));
65
+ return { found: true, version: max, source: section ? '版本列表章节最高版本' : '全文表格最高版本' };
66
+ }
67
+
68
+ function main() {
69
+ const errors = [];
70
+ // 1) lib/self VERSION(import 已拿) 2) package.json
71
+ const pkgPath = join(ROOT, 'package.json');
72
+ let pkgJson = '';
73
+ try { pkgJson = readFileSync(pkgPath, 'utf8'); } catch (e) { errors.push(`读 package.json 失败: ${e?.message || e}`); }
74
+ const vi = versionInfo(pkgJson);
75
+ if (!vi.ok) errors.push(vi.error);
76
+ // 3) cli.mjs HELP 文本(源码里是 v${VERSION} 模板,运行时渲染为 v<版本>)
77
+ const cliPath = join(ROOT, 'cli.mjs');
78
+ let cliText = '';
79
+ if (existsSync(cliPath)) {
80
+ try { cliText = readFileSync(cliPath, 'utf8'); } catch { /* 忽略 */ }
81
+ }
82
+ if (!cliText.includes('v${VERSION}')) {
83
+ errors.push('cli.mjs HELP 未引用 v${VERSION} 模板(应在 HELP 首行 git-sluice v${VERSION})');
84
+ }
85
+ // 4) 版本列表宿主(适配分体式:优先 docs/CHANGELOG.md 的 dshgp-version
86
+ // 标记块——README 不再内嵌版本表,只有链接引用;无标记块回退 README 章节)
87
+ // 优先认「(当前)」标记行;无标记则取版本列表章节内最高版本。
88
+ const changelogPath = join(ROOT, 'docs', 'CHANGELOG.md');
89
+ const readmePath = join(ROOT, 'README.md');
90
+ let hostText = '';
91
+ let hostLabel = '';
92
+ if (existsSync(changelogPath)) {
93
+ try {
94
+ const cl = readFileSync(changelogPath, 'utf8');
95
+ const vs = cl.indexOf('<!-- dshgp-version:start -->');
96
+ const ve = cl.indexOf('<!-- dshgp-version:end -->');
97
+ if (vs >= 0 && ve > vs) { hostText = cl.slice(vs, ve); hostLabel = 'docs/CHANGELOG.md(dshgp-version 标记块)'; }
98
+ } catch { /* 读失败回退 README */ }
99
+ }
100
+ if (!hostText) {
101
+ try { hostText = readFileSync(readmePath, 'utf8'); hostLabel = 'README.md'; }
102
+ catch (e) { errors.push(`读版本列表宿主失败: ${e?.message || e}`); }
103
+ }
104
+ const rv = readmeVersion(hostText);
105
+ if (!rv.found) {
106
+ errors.push(`${hostLabel} 版本列表未找到版本号(应有「## 版本列表」章节,行形如 | **1.2.3**(当前) | … |)`);
107
+ } else if (rv.version !== vi.pkgVersion) {
108
+ errors.push(`${hostLabel} 版本列表当前版本 ${rv.version}(${rv.source})与 package.json ${vi.pkgVersion} 不一致——发版后须同步版本记录`);
109
+ }
110
+ const ok = errors.length === 0;
111
+ if (json) {
112
+ const report = { ok, selfVersion: VERSION, pkgVersion: vi.pkgVersion, readmeVersion: rv.version || '', readmeSource: rv.source || '', errors };
113
+ console.log(JSON.stringify(report, null, 2));
114
+ } else {
115
+ console.log(`版本一致性 ${ok ? '✅' : '❌'}: lib/self=${VERSION} / package.json=${vi.pkgVersion} / README=${rv.version || '未找到'} / cli HELP 引用 v\${VERSION} 模板`);
116
+ for (const e of errors) console.error(` ✗ ${e}`);
117
+ if (!ok) console.error('\n修法:改 lib/self/index.js 的 VERSION 与 package.json version 同步(单一事实源在 lib/self)');
118
+ }
119
+ process.exitCode = ok ? 0 : 1;
120
+ }
121
+
122
+ main();