dsh-git-push 0.0.0-stage → 2.8.4

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 (278) hide show
  1. package/.auditignore +30 -0
  2. package/.gitignore +39 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1482 -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 +262 -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 +191 -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 +662 -0
  32. package/lib/app/tools.js +40 -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 +207 -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 +131 -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 +144 -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 +470 -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 +167 -0
  190. package/lib/npm/registry.js +147 -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 +193 -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/doc-drift.mjs +200 -0
  231. package/scripts/doc-func.mjs +212 -0
  232. package/scripts/doc-tree.mjs +456 -0
  233. package/scripts/doc-version.mjs +220 -0
  234. package/scripts/frontend-preview-check.mjs +124 -0
  235. package/scripts/hot-path-probe-cjs.cjs +71 -0
  236. package/scripts/hot-path-probe-fs-shim.mjs +28 -0
  237. package/scripts/hot-path-probe-fsp-shim.mjs +31 -0
  238. package/scripts/hot-path-probe.mjs +153 -0
  239. package/scripts/module-splitter.py +800 -0
  240. package/scripts/platform-scan.mjs +168 -0
  241. package/scripts/preview-gen.mjs +489 -0
  242. package/scripts/preview-local-runner.mjs +55 -0
  243. package/scripts/preview-server-direct.mjs +116 -0
  244. package/scripts/preview-server.mjs +305 -0
  245. package/scripts/preview-slot-data.mjs +123 -0
  246. package/scripts/probe-recheck.mjs +47 -0
  247. package/scripts/readme-gen.mjs +268 -0
  248. package/scripts/rename-locator.mjs +97 -0
  249. package/scripts/rule-switch.mjs +97 -0
  250. package/scripts/rules-solo-audit.mjs +173 -0
  251. package/scripts/scan-file-io.mjs +713 -0
  252. package/scripts/scan-hardcoded-paths.mjs +125 -0
  253. package/scripts/scan-repos.mjs +167 -0
  254. package/scripts/scan-version.mjs +122 -0
  255. package/scripts/scrub-user-wording.mjs +420 -0
  256. package/scripts/symbol-index.mjs +85 -0
  257. package/scripts/sync-plugin-install.mjs +223 -0
  258. package/scripts/sync-plugin.mjs +279 -0
  259. package/scripts/verify-prestep.mjs +100 -0
  260. package/skills/dev/audit-rule-authoring.md +58 -0
  261. package/skills/dev/dsh-git-push.md +323 -0
  262. package/skills/dev/git-push-live-fix.md +45 -0
  263. package/skills/dsh-repo-index.md +35 -0
  264. package/skills/guide/guide-audit.md +167 -0
  265. package/skills/guide/guide-cli-scripts.md +104 -0
  266. package/skills/guide/guide-clone-repos.md +173 -0
  267. package/skills/guide/guide-commit-push.md +156 -0
  268. package/skills/guide/guide-inject-ui.md +166 -0
  269. package/skills/guide/guide-slash-completion.md +118 -0
  270. package/skills/workflow/README.md +21 -0
  271. package/skills/workflow/git-commit-discipline.md +68 -0
  272. package/skills/workflow/git-project-startup.md +85 -0
  273. package/skills/workflow/git-rebuild-process.md +57 -0
  274. package/skills/workflow/github-operations.md +91 -0
  275. package/skills/workflow/readme-sync-git-md.md +28 -0
  276. package/skills/workflow/task-completion-report.md +73 -0
  277. package/skills/workflow/tool-json-add-ask.md +35 -0
  278. package/skills/workflow/versioning-rule.md +211 -0
package/cli.mjs ADDED
@@ -0,0 +1,360 @@
1
+ #!/usr/bin/env node
2
+ // dsh-skip-i18n: CLI 输出硬编码中文为产品行为(无 i18n 需求)
3
+ /**
4
+ * dsh-git-push 独立 CLI(git-sluice)
5
+ * 不依赖 DSH 运行时,可独立运行。命名/参数与 lib 函数完全一致(外部 API 与函数名一致)。
6
+ */
7
+ import './lib/app/host-doc-checks.js'; // 审计包边界:文档漂移检查器由宿主(独立 CLI)注入
8
+ import { VERSION, readmeTemplate, yamlTemplate, helpSync } from './lib/self/index.js';
9
+ import { loadRuleFiles, discoverRuleSlots } from './lib/rule/loader.js';
10
+ import { compileAllRules } from './lib/rule/registry.js';
11
+ import { runWrappedGit } from './lib/git/wrapped-git.js';
12
+ import { registryByCli, parseRegistryArgs } from './lib/app/command-registry.js';
13
+ import { callTool } from './lib/app/tool-call.js';
14
+ import { readFileSync, realpathSync } from 'node:fs';
15
+
16
+ // 结构化:命令实现按域抽到 lib/cli/commands-*.mjs(audit/account/vcs/doc),
17
+ // 本文件保留入口编排(HELP/parseArgv/命令分发表/运行入口)。
18
+ // 具名 import 而非 `export ... from`:COMMANDS 表直接引用 cmdXxx 变量名,
19
+ // re-export 不建立本模块作用域绑定,会 ReferenceError。
20
+ import {
21
+ cmdAudit, cmdScan, cliPluginConfig, pluginEqualAuditOpts, pluginEqualWeights,
22
+ } from './lib/cli/commands-audit.mjs';
23
+ export { cmdAudit, cmdScan, cliPluginConfig, pluginEqualAuditOpts, pluginEqualWeights };
24
+ import {
25
+ cmdAccountCheck, cmdCredEnv, cmdRemoteCreate, cmdSetVisibility, cmdGenSshKey,
26
+ } from './lib/cli/commands-account.mjs';
27
+ export { cmdAccountCheck, cmdCredEnv, cmdRemoteCreate, cmdSetVisibility, cmdGenSshKey };
28
+ import {
29
+ cmdRepos, cmdIndex, cmdGit, cmdCommit, cmdLinkCheck, cmdClone,
30
+ } from './lib/cli/commands-vcs.mjs';
31
+ export { cmdRepos, cmdIndex, cmdGit, cmdCommit, cmdLinkCheck, cmdClone };
32
+ import {
33
+ cmdFileIo, cmdTreeDoc, cmdFunctions, cmdModuleSplitter,
34
+ } from './lib/cli/commands-doc.mjs';
35
+ export { cmdFileIo, cmdTreeDoc, cmdFunctions, cmdModuleSplitter };
36
+
37
+ /** parseArgv 认识的选项白名单(cli-help-sync 机器比对基准,必须与 HELP 文本一致。
38
+ * 注:-m 是单横线别名(helpSync 只比对 -- 双横线),不列入本表。 */
39
+ export const KNOWN_FLAGS = ['--depth', '--full', '--ruleset', '--weights', '--include-ignored', '--push', '--no-push', '--dry-run', '--force', '--message', '--audit', '--ignore-patterns', '--requirements-confirmed', '--push-confirmed', '--json', '--max', '--owner', '--offline', '--paths', '--history', '--since', '--until', '--out', '--skip-empty',
40
+ // npm 相关(与 command-registry 的 npm_publish 参数对齐:dir / dryRun / tag / otp / confirm)
41
+ '--dir', '--tag', '--otp', '--confirm', '--global', '--ignore-scripts', '--async', '--no-dry-run',
42
+ // file-io 三标签过滤
43
+ '--summary', '--write', '--type', '--kind', '--risk', '--op', '--root', '--readme',
44
+ // identity-rewrite:额外要统一的邮箱
45
+ '--extra-emails',
46
+ // 补齐的 5 个命令(clone / account-check / remote-create / set-visibility / gen-ssh-key)
47
+ '--dest', '--branch', '--preview', '--max-file-mb', '--concurrency', '--visibility', '--email', '--no-check-ssh', '--token'];
48
+
49
+ const HELP = `git-sluice v${VERSION} — dsh-git-push 引擎独立 CLI(脱离 DSH 运行)
50
+
51
+ 快速开始(第一次用——不用查源码):
52
+ git-sluice account-check ① 先校验 GitHub 凭据(token/SSH 是否可用)
53
+ git-sluice scan <目录> ② 看有哪些 git 仓库(分支/未提交/未推送)
54
+ git-sluice audit <仓库> --full ③ 全量审计一个仓库(评分/问题/API 指引)
55
+ git-sluice commit <仓库> --message "msg" ④ 提交推送(自动过审计门禁)
56
+ git-sluice help 全部命令与参数
57
+
58
+ 用法:
59
+ git-sluice version 查看版本
60
+ git-sluice ruleset [槽位...] 编译规则包并输出统计(默认全部槽位)
61
+ git-sluice scan <root> [--depth N] 全量扫描目录(非 git 目录可查)
62
+ git-sluice repos <root> [--depth N] [--max N] [--json]
63
+ 扫描本地 git 仓库(尊重 .gitignore:被忽略目录整棵跳过)
64
+ git-sluice index <root> [--owner <账号>] [--depth N] [--max N] [--offline] [--json]
65
+ 重建仓库索引 dsh-repo-index.json(--offline=纯离线不查 GitHub API)
66
+ git-sluice audit <root> [--full] [--ruleset <目录>] [--weights <JSON>] [--include-ignored] [--history [--since <提交>] [--until <提交>] [--out <目录>]]
67
+ 审计目录(默认 diff 范围;--full=全量;--ruleset=自定规则目录;--weights=权重覆盖 JSON;--include-ignored=连 .gitignore 忽略的文件也扫;--history=历史提交审计——逐提交快照全量审计并落盘报告,--since/--until 起始~结束提交(皆缺省=全部历史、含两端),--out 报告保存目录(缺省=git 根 audit-history/))
68
+ git-sluice commit <repo> --message <msg> [--push|--no-push] [--dry-run] [--force] [--audit] [--ignore-patterns <模式>] [--requirements-confirmed] [--push-confirmed] [--paths <路径1,路径2>] [--json]
69
+ 审计门禁 → 提交(默认只 commit 不 push;--push 推远端;--force 强推覆盖远端历史;--requirements-confirmed 显式核对开发者要求;--push-confirmed 显式放行推送门禁;--paths 精确 add 指定文件替代 add -A)
70
+ git-sluice clone-preview <owner/repo> [--branch <名>] [--json]
71
+ git-sluice file-io [路径...] [--summary] [--write] [--type sync|async] [--kind read|write|delete|rename] [--risk high|medium|low] [--op <操作名>] [--json]
72
+ 文件读写调用扫描(三标签:类型/操作/上下文)——同步 I/O 在异步路径会阻塞;写/删/改名涉及数据安全
73
+ git-sluice link-check <路径> 检查 md/文本中的链接有效性(只 warning,flaky 域名打折)
74
+ git-sluice npm-publish [目录] [--dry-run|--no-dry-run] [--tag <tag>] [--otp <码>] [--confirm] [--json]
75
+ npm 发包(注册为后台 job):默认 dry-run,只体检 + npm publish --dry-run(**不写 registry**);
76
+ 真发必须同时给 --no-dry-run 与 --confirm(不可撤销);体检项:private:true / 同名版本占用 / npm pack 清单
77
+ git-sluice api npm-account [--json] npm 账号(离线快照)
78
+ git-sluice api npm-check npm 账号在线校验(npm whoami,写快照)
79
+ git-sluice api npm-owned 登录账号名下的公开包列表
80
+ git-sluice api npm-packages --dir <目录> 该目录的依赖清单
81
+ git-sluice api npm-install --dir <目录> --confirm [--global] [--async] [--ignore-scripts]
82
+ 安装包(--global=全局;--async=异步 + 用 npm-install-progress 轮询进度;默认不执行安装脚本)
83
+ git-sluice api npm-install-progress 安装进度/终态(consume:true 取走后复位)
84
+ git-sluice api npm-publish --dry-run npm 发包(等价写法:走 api 通道,默认 dry-run)
85
+ git-sluice identity-rewrite [仓库路径...] [--root <目录>] [--write] [--push] [--extra-emails <邮箱...>] [--json]
86
+ 提交身份历史改写:把非规范身份(工具/AI 产生的 agent@dsh.local 等 + 账号 noreply 旧变体)
87
+ 统一成登录账号规范身份;默认 dry-run 只报告,--write 才改(先建备份引用,自检通过才改写),
88
+ --push 再用 force-with-lease 强推;只处理 origin 属于登录账号的仓库
89
+ git-sluice module-splitter <analyze|split|verify> <file|plan> [--dry-run] [--json]
90
+ git-sluice functions <analyze|apply> [目录] [--skip-empty] [--json]
91
+ git-sluice tree-doc <sync|gen|check|apply> [--root <目录>] [--readme <路径>] [--write]
92
+ README 目录结构维护:sync 索引同步(新增自动加键/删除自动删键);gen 生成树;check 检查漂移;apply 覆盖 README 标记块(封装 scripts/tree-doc.mjs)
93
+ 函数索引与函数文档:analyze 生成 functions-index.json(复用 scripts/func-index.js,含签名/注释槽位);apply 读 JSON(人工补 comment 后)生成 docs/函数/*.md(文件删除归档 _archived,注释不丢)
94
+ 巨型单文件按顶层块拆分(python3 零依赖;analyze 先出块/依赖图 → AI 写 plan.json → split 切分 → verify 校验导出面;--dry-run=split 只预演)
95
+ git-sluice git <git 参数...> 浅包装 git:参数与 git 完全一致,凭据自动注入(SSH 私钥 / config.json token),无需传 token/私钥参数
96
+ 例:git-sluice git pull | git clone owner/repo | git fetch origin(stdio 直连,退出码透传)
97
+ git-sluice clone <owner/repo> [dest] [--branch <名>] [--dest <目录>] [--max-file-mb N] [--concurrency N] [--preview] [--json]
98
+ 从 GitHub 克隆仓库(Git Data API 通道,不直连 github.com;--preview=只探测不写盘)
99
+ git-sluice account-check [--token <t>] [--no-check-ssh] [--json]
100
+ 校验 GitHub 账号与凭据(token 在线校验 + SSH 公钥指纹)
101
+ git-sluice cred-env [--json]
102
+ 输出插件保管凭据的环境变量前缀(SSH: GIT_SSH_COMMAND 私钥路径 / HTTPS: GIT_ASKPASS 脚本)——AI 执行任意外部 git 命令时粘贴使用,全程无 token/私钥明文
103
+ git-sluice remote-create <repo> [--owner <账号>] [--visibility public|private] [--dry-run] [--json]
104
+ 按项目文件夹在 GitHub 建远端仓库(已存在则复用),并指向 origin
105
+ git-sluice set-visibility <repo> --visibility public|private [--json]
106
+ 切换仓库公开/私有(public 有敏感信息暴露风险)
107
+ git-sluice gen-ssh-key --email <x@y.z> [--force] [--json]
108
+ 生成 SSH 密钥对(公钥回传,私钥不出本机;--force=先备份再覆盖)
109
+ git-sluice yaml-template 输出规则 yml 模板(含 kind + dimensions 示范)
110
+ git-sluice readme-template 输出 README 模板({{name}} {{version}} 占位符)
111
+ git-sluice self-check 版本一致性 + HELP↔parseArgv 机器比对(自检)
112
+ git-sluice help 显示本帮助
113
+ `;
114
+
115
+ // 导入 compilers 触发注册(副作用:注册 13 种编译函数到 RULE_COMPILERS)
116
+ import './lib/rule/compilers.js';
117
+
118
+ /**
119
+ * 参数解析:白名单必须与 HELP 文本完全一致(cli-help-sync 自检)。
120
+ *
121
+ * 实现用**表驱动**而非 if-else 长链:每加一个 flag 只加一行表项,
122
+ * 函数长度不随 flag 数增长(if-else 版加到第 21 个 flag 时func-lines 即 101 行、
123
+ * 触发自己的 readability/max-function-length blocker)。
124
+ *
125
+ * 自检约束:helpSync 用正则 /--[\w-]+/g 扫本文件全文提取 flag 字面量,
126
+ * 故下表必须**写成 `'--xxx'` 字面量**(拼字符串会让自检扫不到而误报)。
127
+ */
128
+
129
+ /** 布尔开关 flag → flags 字段名(出现即为 true)。 */
130
+ const BOOL_FLAGS = {
131
+ '--full': 'full',
132
+ '--history': 'history',
133
+ '--include-ignored': 'includeIgnored',
134
+ '--dry-run': 'dryRun',
135
+ '--force': 'force',
136
+ '--req-confirm': 'reqConfirm',
137
+ '--push-gate-confirmed': 'pushGateConfirmed',
138
+ '--json': 'json',
139
+ '--offline': 'offline',
140
+ '--summary': 'summary',
141
+ '--write': 'write',
142
+ '--preview': 'preview',
143
+ '--skip-empty': 'skipEmpty',
144
+ '--no-check-ssh': null, // 特殊:置 false 而非 true(见下 applyBool)
145
+ };
146
+
147
+ /** 取值 flag → [flags 字段名, 缺值提示, 转换函数?]。 */
148
+ const VALUE_FLAGS = {
149
+ '--depth': ['depth', '--depth 缺值(用法: --depth N)', Number],
150
+ '--max': ['max', '--max 缺值(用法: --max N)', Number],
151
+ '--owner': ['owner', '--owner 缺值(用法: --owner <账号>)'],
152
+ '--ruleset': ['ruleset', '--ruleset 缺值'],
153
+ '--weights': ['weights', '--weights 缺值'],
154
+ '-m': ['message', '-m 缺值(用法: -m <提交信息>)'],
155
+ '--root': ['root', '--root 缺值(用法: --root <目录>)'],
156
+ '--readme': ['readme', '--readme 缺值(用法: --readme <README路径>)'],
157
+ '--type': ['type', '--type 缺值(用法: --type sync|async)'],
158
+ '--kind': ['kind', '--kind 缺值(用法: --kind read|write|delete|rename)'],
159
+ '--risk': ['risk', '--risk 缺值(用法: --risk high|medium|low)'],
160
+ '--op': ['op', '--op 缺值(用法: --op writeFileSync)'],
161
+ '--dest': ['dest', '--dest 缺值(用法: --dest <目录>)'],
162
+ '--branch': ['branch', '--branch 缺值(用法: --branch <分支名>)'],
163
+ '--max-file-mb': ['maxFileMB', '--max-file-mb 缺值(用法: --max-file-mb N)', Number],
164
+ '--concurrency': ['concurrency', '--concurrency 缺值(用法: --concurrency N)', Number],
165
+ '--visibility': ['visibility', '--visibility 缺值(用法: --visibility public|private)'],
166
+ '--email': ['email', '--email 缺值(用法: --email x@y.z)'],
167
+ '--token': ['token', '--token 缺值(用法: --token <ghp_...>)'],
168
+ '--since': ['since', '--since 缺值(用法: --since <起始提交 sha/ref>)'],
169
+ '--until': ['until', '--until 缺值(用法: --until <结束提交 sha/ref>)'],
170
+ '--out': ['out', '--out 缺值(用法: --out <报告保存目录>)'],
171
+ };
172
+
173
+ /** 默认值(函数内每次调用新建,避免跨调用串状态)。 */
174
+ function defaultFlags() {
175
+ return {
176
+ depth: undefined, full: false, ruleset: undefined, weights: undefined, includeIgnored: false,
177
+ push: undefined, dryRun: false, force: false, reqConfirm: false, pushGateConfirmed: false,
178
+ message: undefined, json: false, max: undefined, owner: undefined, offline: false,
179
+ summary: false, write: false, type: undefined, kind: undefined, risk: undefined, op: undefined,
180
+ dest: undefined, branch: undefined, preview: false, maxFileMB: undefined, concurrency: undefined,
181
+ visibility: undefined, email: undefined, checkSsh: true, token: undefined,
182
+ };
183
+ }
184
+
185
+ /** 布尔开关落值:--no-check-ssh 语义是「关掉」而非「开启」,单独处理。 */
186
+ function applyBoolFlag(flags, a) {
187
+ if (a === '--no-check-ssh') { flags.checkSsh = false; return; }
188
+ // --push / --no-push 是同一字段的两态,不能混进 BOOL_FLAGS 的「出现即 true」
189
+ if (a === '--push') { flags.push = true; return; }
190
+ if (a === '--no-push') { flags.push = false; return; }
191
+ flags[BOOL_FLAGS[a]] = true;
192
+ }
193
+
194
+ /** 取值 flag 落值。 */
195
+ function applyValueFlag(flags, a, v) {
196
+ const [field, , conv] = VALUE_FLAGS[a];
197
+ flags[field] = conv ? conv(v) : v;
198
+ }
199
+
200
+ export function parseArgv(argv) {
201
+ const flags = defaultFlags();
202
+ const positional = [];
203
+ for (let i = 0; i < argv.length; i++) {
204
+ const a = argv[i];
205
+ if (a === '--push' || a === '--no-push' || a === '--no-check-ssh' || a in BOOL_FLAGS) {
206
+ applyBoolFlag(flags, a);
207
+ } else if (a in VALUE_FLAGS) {
208
+ const v = argv[++i];
209
+ if (v === undefined || v.startsWith('--')) return { error: VALUE_FLAGS[a][1] };
210
+ applyValueFlag(flags, a, v);
211
+ } else if (a.startsWith('--')) {
212
+ return { error: `未知参数: ${a}` };
213
+ } else {
214
+ positional.push(a);
215
+ }
216
+ }
217
+ return { flags, positional };
218
+ }
219
+
220
+ /** 子命令:version */
221
+ export function cmdVersion() {
222
+ console.log(`git-sluice v${VERSION} — dsh-git-push(统一函数入口架构)`);
223
+ }
224
+
225
+ /** 子命令:ruleset — 编译规则包输出统计。 */
226
+ export function cmdRuleset(slots) {
227
+ const order = slots.length ? slots : null; // null=动态发现全部槽位
228
+ const { ok, merged, errors, files, order: effective } = loadRuleFiles(order);
229
+ const ctx = { errors: [] };
230
+ const compiled = compileAllRules(merged.rules, ctx);
231
+ if (!ok || ctx.errors.length) {
232
+ console.error('规则编译失败:');
233
+ for (const e of [...errors, ...ctx.errors]) console.error(' ✗ ' + e);
234
+ process.exitCode = 1;
235
+ return;
236
+ }
237
+ console.log(`规则包编译 OK(${effective.join('+')})`);
238
+ console.log(` 文件: ${files.length} 个槽位, 规则条目 ${merged.rules.length}, 编译成功 ${compiled.length}`);
239
+ const byKind = {};
240
+ for (const r of compiled) byKind[r.kind || r.type || 'other'] = (byKind[r.kind || r.type || 'other'] || 0) + 1;
241
+ for (const [k, v] of Object.entries(byKind)) console.log(` ${k}: ${v}`);
242
+ }
243
+
244
+ export function cmdYamlTemplate() {
245
+ console.log(yamlTemplate());
246
+ }
247
+
248
+ /** 子命令:readme-template — 输出 README 模板。 */
249
+ export function cmdReadmeTemplate() {
250
+ console.log(readmeTemplate().template);
251
+ }
252
+
253
+ /** 子命令:self-check — 版本一致性 + HELP↔parseArgv 机器比对。 */
254
+ export function cmdSelfCheck() {
255
+ const helpRes = helpSync(HELP, KNOWN_FLAGS);
256
+ let fail = 0;
257
+ console.log('自身自检:');
258
+ console.log(` version: v${VERSION}`);
259
+ if (!helpRes.ok) {
260
+ fail++;
261
+ console.error(` ✗ cli-help-sync: HELP 与 parseArgv 不一致`);
262
+ for (const f of helpRes.missingInHelp) console.error(` parseArgv 认但 HELP 没写: ${f}`);
263
+ for (const f of helpRes.missingInParse) console.error(` HELP 写了但 parseArgv 不认: ${f}`);
264
+ } else {
265
+ console.log(` ✓ cli-help-sync: HELP 与 parseArgv 一致(${helpRes.helpFlags.join(' ')})`);
266
+ }
267
+ const pkgRes = readPkgJson();
268
+ if (pkgRes && pkgRes.version && pkgRes.version !== VERSION) {
269
+ fail++;
270
+ console.error(` ✗ version: lib/self=${VERSION} vs package.json=${pkgRes.version}`);
271
+ } else {
272
+ console.log(` ✓ version: lib/self = package.json = ${VERSION}`);
273
+ }
274
+ process.exitCode = fail > 0 ? 1 : 0;
275
+ }
276
+
277
+ /** 读 package.json(失败返回 null)。 */
278
+ function readPkgJson() {
279
+ try {
280
+ return JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
281
+ } catch { return null; }
282
+ }
283
+
284
+ /** 命令分发表(重构:main 54 圈复杂度 → 表驱动分发)。
285
+ * 每个条目 [命令名, handler(rest)];统一 parse 模式用 parseVia 包装。 */
286
+
287
+
288
+ /** 注册表工具返回输出(默认文本化 summary/apiGuide;--json 直出完整返回)。 */
289
+ function printRegistryResult(r, json) {
290
+ if (json) { console.log(JSON.stringify(r, null, 2)); return; }
291
+ if (!r) return;
292
+ if (r.error) { console.error(r.error); return; }
293
+ if (r.apiGuide) { console.log(r.apiGuide); return; }
294
+ const L = [];
295
+ if (r.summary) L.push(`summary: ${JSON.stringify(r.summary)}`);
296
+ if (r.quality) L.push(`quality: ${r.quality.score ?? '?'}/${r.quality.level ?? '?'}`);
297
+ if (r.count != null) L.push(`count: ${r.count}`);
298
+ console.log(L.length ? L.join('\n') : JSON.stringify(r));
299
+ }
300
+
301
+ const parseVia = (run) => (rest) => {
302
+ const { flags, positional, error } = parseArgv(rest);
303
+ if (error) return console.error(error);
304
+ return run(flags, positional);
305
+ };
306
+ const COMMANDS = new Map([
307
+ ['ruleset', (rest) => cmdRuleset(rest)],
308
+ ['audit', parseVia((f, p) => cmdAudit(p[0] || '.', f))], // audit 不走注册表——CLI 独立审计需完整 findings(不依赖宿主 API);工具 code_audit 输出 API 指引
309
+ ['repos', parseVia((f, p) => cmdRepos(p[0] || '.', f))],
310
+ ['index', parseVia((f, p) => cmdIndex(p[0] || '.', f))],
311
+ ['functions', parseVia((f, p) => cmdFunctions(p[0] || '', p[1] || '', f))],
312
+ ['tree-doc', parseVia((f, p) => cmdTreeDoc(p[0] || '', f))],
313
+ ['git', (rest) => cmdGit(rest)], // 1.9.0:浅包装 git(自动凭据透传)
314
+ ['yaml-template', () => cmdYamlTemplate()],
315
+ ['readme-template', () => cmdReadmeTemplate()],
316
+ ['self-check', () => cmdSelfCheck()],
317
+ ]);
318
+
319
+ export async function main(argv = process.argv.slice(2)) {
320
+ const [cmd, ...rest] = argv;
321
+ if (!cmd || cmd === 'help' || cmd === '--help' || cmd === '-h') {
322
+ console.log(HELP);
323
+ return;
324
+ }
325
+ if (cmd === 'version' || cmd === '-v' || cmd === '--version') return await cmdVersion();
326
+ // 方案 B:注册表驱动命令优先(工具有对应 → 通用 parseArgs → callTool——
327
+ // CLI 与插件工具同实现,自动对齐;CLI 独立于 DSH 运行:env 自备 + 本地配置)
328
+ const reg = registryByCli(cmd);
329
+ if (reg) {
330
+ const { args, error } = parseRegistryArgs(rest, reg.params);
331
+ if (error) { console.error(error); process.exitCode = 1; return 1; }
332
+ try {
333
+ const r = await callTool(reg.name, args, { workspaceRoot: process.cwd() }, cliPluginConfig(), console, null, null);
334
+ printRegistryResult(r, args.json === true);
335
+ return 0;
336
+ } catch (e) { console.error(String((e && e.message) || e)); process.exitCode = 1; return 1; }
337
+ }
338
+ const handler = COMMANDS.get(cmd);
339
+ if (handler) return await handler(rest);
340
+ // 1.9.0:未知命令透传为浅包装 git(自动凭据)——`git-sluice pull` = `git pull`
341
+ // (git-sluice 是 git 的超集:已知子命令走插件,其余全部交给 git + 插件凭据)
342
+ const wrapped = runWrappedGit([cmd, ...rest]);
343
+ if (wrapped.ok) return 0;
344
+ process.exitCode = typeof wrapped.status === 'number' ? wrapped.status : 1;
345
+ return process.exitCode;
346
+ }
347
+
348
+ // 直接运行时入口(被 import 时不执行)
349
+ // 修:符号链接场景(PATH 里 git-sluice → cli.mjs)下 process.argv[1] 是链接路径、
350
+ // import.meta.url 是真实文件路径,两者字符串不相等 → 入口静默不执行(exit 0 无输出)。
351
+ // 用 realpath 归一化:链接/相对/绝对路径都解析到同一真实路径再比。
352
+ if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('cli.mjs')
353
+ || import.meta.url === `file://${realpathSync(process.argv[1])}`) {
354
+ // 顶层 await:main 已异步,未 await 时 rejection 会变成 unhandled rejection
355
+ // (进程静默退出、退出码不对),故显式 await 并回传退出码。
356
+ // 命令函数(cmdFileIo/cmdModuleSplitter 等)返回业务对象/数组,
357
+ // 只有 number 才赋 exitCode——否则 `process.exitCode = 对象` 抛 ERR_INVALID_ARG_TYPE。
358
+ const mainResult = await main();
359
+ if (typeof mainResult === 'number' && Number.isInteger(mainResult)) process.exitCode = mainResult;
360
+ }
@@ -0,0 +1,14 @@
1
+ # 2026-09-03 修改:原代码注释保留
2
+ # 【原代码】
3
+ # - id: git-push
4
+ # name: dsh-git-push
5
+ # config:
6
+ # enabled: true
7
+ # 【改为】顶层 insert 新建行(第三方 bundle patch 标准写法)
8
+ # 【背景】早期直接改工作区方案;市场报「目标不存在 / patch target not found」
9
+ # 【思路】无 insert 的 - id 是覆盖已有 loader 行;基座没有 git-push,bundle 层打空。与 dsh-cloud-workspaces / dshmarket 同款。
10
+ - insert:
11
+ - id: dsh-git-push
12
+ name: dsh-git-push
13
+ config:
14
+ enabled: true
@@ -0,0 +1,34 @@
1
+ # 三层审计架构 · 分层位置
2
+
3
+ > 本说明块已作为代码注释出现在部分文件头部(lib/ast/*、lib/checks/* 等),此处整理为独立文档随插件发布,
4
+ > 供新增规则/检查时对照落地位置(lib 下每个文件夹对应一层功能,lib/audit/ 只做编排引入)。
5
+
6
+ ```js
7
+ /*
8
+ * 分层位置(三层审计架构):
9
+ * ① 规则声明 → lib/audit-rules/*.yml
10
+ * ② 具体实现 → lib/ast/*(token 级判定)
11
+ * ③ 调用包装 → lib/checks/*(本目录,把判定转成 finding)
12
+ * ④ 编排调度 → lib/audit/*(收集文件、按 kind 调度、汇总)
13
+ */
14
+ ```
15
+
16
+ ## 新增一条审计规则的落地路径(对应上面四层)
17
+
18
+ 1. **规则声明** `lib/audit-rules/<包>.yml`:声明规则条目(`id` / `name` / `severity` / `patterns` 正则初筛;
19
+ 需要语义精筛时加 `astConfirm: true` 或 `astConfirmKind: <名称>`)。
20
+ 2. **token 级判定** `lib/ast/*`:实现精筛函数(如 `lib/ast/credential.js` 的 `credentialValueLines`、
21
+ `lib/ast/dataflow.js` 的「清空后访问」),返回「应报/应豁免的行号集合」。
22
+ 3. **调用包装** `lib/checks/*`:检查器消费精筛集合转成 finding——`lib/checks/regex.js` 的
23
+ `checkRegexRules` 按 `astConfirmKind` 分发(`kindFilter` 集合),`lib/checks/common.js` 集中
24
+ 注册各行精筛函数;新 kind 在此接线。
25
+ 4. **编排调度** `lib/audit/*`:`collector.js` 收文件 → `audit-file.js` 按 kind 调度到各检查器 →
26
+ `orchestrate.js` 汇总、按规则包聚合命中数。`lib/audit/` 不驻留具体判定实现。
27
+
28
+ ## 原则
29
+
30
+ - 规则 yml 只写「声明」,判定逻辑(正则初筛 → token/AST 精筛)全部落在 `lib/ast/` 与 `lib/checks/`。
31
+ - 新增 kind 需要注册编译器时:`lib/rule/compilers/<域>.js`(`registerCompiler` 一行),
32
+ `lib/rule/compilers.js` 只做纯再导出。
33
+ - 仓库级/文件系统上下文类检查(如读 .gitignore、git 命令)不在逐文件检查器里臆测,
34
+ 交给 `lib/audit/` 编排层或 `lib/checks/` 中带上下文参数的入口。