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,143 @@
1
+ /**
2
+ * HTTP 处理层 · 仓库动作端点(repo-visibility / repo-push / repo-commit)
3
+ *
4
+ * 从 http-handlers.js 的 handleHttp 拆分而来。
5
+ * 统一签名:handleXxx(ctx) → { status, body };ctx = { req, query, body, env, cfg, path, method }。
6
+ */
7
+ import { join } from 'node:path';
8
+ import { pushCurrentBranch, resolveToken, githubFetch, setVisibility, refreshAccountStatus, detectRepoVisibility, runGit, parseGithubOwnerRepo } from '../../git/index.js';
9
+ import { updateRepoIndex } from '../../git/repo-index.js';
10
+ import { commitWithAudit } from '../../commit-push.js';
11
+
12
+ /* ───────── 仓库动作常量 ───────── */
13
+ const COMMIT_SHA_MAX_LEN = 40; // commit sha 展示截断长度
14
+
15
+ /** GET|POST /api/git-push/repo-visibility —— 云端仓库私有/公开切换(GET 只读查状态)。 */
16
+ export async function handleRepoVisibility(ctx) {
17
+ const method = String(ctx.req?.method || 'GET').toUpperCase();
18
+ // 按方法分派到两个分支函数:原先两段(只读查询 / 切换写入)挤在一个函数里,
19
+ // 圈复杂度 22(阈值 10,自审 max-cyclomatic-complexity 高风险)——拆开后各自只做一件事。
20
+ return method === 'GET' ? handleVisibilityGet(ctx) : handleVisibilityPost(ctx);
21
+ }
22
+
23
+ /** GET 分支:只读查云端仓库当前可见性(不改任何状态)。 */
24
+ async function handleVisibilityGet({ query, env }) {
25
+ const owner = String(query.owner || '').trim();
26
+ const repo = String(query.repo || '').trim();
27
+ if (!owner || !repo) return { status: 400, body: { ok: false, code: 'BAD_INPUT', message: '缺 owner/repo' } };
28
+ const tok = resolveToken({ workspaceRoot: env.workspaceRoot }).token;
29
+ if (!tok) return { status: 400, body: { ok: false, code: 'NO_TOKEN', message: '未配置 token' } };
30
+ const res = await githubFetch(`/repos/${owner}/${repo}`, { token: tok, method: 'GET' });
31
+ if (res.status !== 200) return { status: 400, body: { ok: false, error: res.json?.message || res.error || `HTTP ${res.status}` } };
32
+ return { status: 200, body: { ok: true, owner, repo, visibility: res.json?.private ? 'private' : 'public' } };
33
+ }
34
+
35
+ /** POST 分支:切换云端仓库可见性(public/private)。 */
36
+ async function handleVisibilityPost({ body, env }) {
37
+ const owner = String((body && body.owner) || '').trim();
38
+ const repo = String((body && body.repo) || '').trim();
39
+ const visibility = String((body && body.visibility) || '').toLowerCase();
40
+ if (!owner || !repo) return { status: 400, body: { ok: false, code: 'BAD_INPUT', message: '缺 owner/repo' } };
41
+ if (!['public', 'private'].includes(visibility)) return { status: 400, body: { ok: false, code: 'BAD_VIS', message: 'visibility 必须为 public 或 private' } };
42
+ const r = await setVisibility({ owner, repo, visibility, token: resolveToken({ workspaceRoot: env.workspaceRoot }).token });
43
+ if (!r.ok) return { status: 400, body: { ok: false, code: 'VIS_FAIL', error: r.error } };
44
+ return { status: 200, body: { ok: true, owner: r.owner, repo: r.repo, visibility: r.visibility } };
45
+ }
46
+
47
+ /** POST /api/git-push/repo-push —— 手动推送(领先 + 工作树干净才允许)。 */
48
+ export async function handleRepoPush(ctx) {
49
+ const { body, env, cfg } = ctx;
50
+ const path = String(body.path || '').trim();
51
+ if (!path) return { status: 400, body: { ok: false, error: '缺少仓库路径 path' } };
52
+ const r = await pushCurrentBranch({ repoPath: path, pushMethod: cfg.pushMethod || 'ssh' });
53
+ if (r.ok) {
54
+ const repoName = String(path).split('/').filter(Boolean).pop() || '';
55
+ // 索引更新串行:全量重建在前,精确回写在后;SSH 无 commitSha 时回退本地 HEAD
56
+ (async () => {
57
+ // token 只解析一次:resolveToken 要读插件 config.json(磁盘 I/O),
58
+ // 同一流程里重复调用纯属浪费(性能规则 performance/repeat-identical-call 命中)
59
+ const token = resolveToken({ workspaceRoot: env.workspaceRoot }).token;
60
+ await updateRepoIndex({
61
+ workspaceRoot: env.workspaceRoot,
62
+ token,
63
+ owner: r.push?.owner || 'EIGHTfs',
64
+ mode: 'rebuild',
65
+ }).catch(() => { /* fire-and-forget */ });
66
+ let visibility = '';
67
+ try {
68
+ const dv = await detectRepoVisibility({ repoPath: path, token });
69
+ if (dv.visibility === 'private') visibility = '私有';
70
+ else if (dv.visibility === 'public') visibility = '公开';
71
+ } catch { /* 可见性查不到不覆盖 */ }
72
+ const localHead = runGit(['rev-parse', 'HEAD'], { cwd: path }).stdout.trim();
73
+ const headSha = String(r.push?.commitSha || '').slice(0, COMMIT_SHA_MAX_LEN) || localHead;
74
+ updateRepoIndex({
75
+ workspaceRoot: env.workspaceRoot,
76
+ repoName,
77
+ remoteState: {
78
+ remoteHead: headSha,
79
+ ahead: 0,
80
+ behind: 0,
81
+ remoteHeadAt: new Date().toISOString(),
82
+ synced: true,
83
+ visibility,
84
+ },
85
+ mode: 'single',
86
+ });
87
+ })().catch(() => { /* 索引更新失败不阻断 */ });
88
+ refreshAccountStatus({ workspaceRoot: env.workspaceRoot }).catch(() => { /* 账号状态刷新失败不阻断主流程 */ });
89
+ }
90
+ const error = r.error || r.push?.reason || undefined;
91
+ return { status: r.ok ? 200 : 400, body: { ...r, error, repoIndex: r.ok ? 'updating' : undefined, indexUpdated: r.ok === true } };
92
+ }
93
+
94
+ /** POST /api/git-push/repo-commit —— UI 手动提交(只 commit 不 push,走审计门禁)。 */
95
+ export async function handleRepoCommit(ctx) {
96
+ const { body, path: _path, cfg } = ctx;
97
+ const path = String(body.path || '').trim();
98
+ const message = String(body.message || '').trim();
99
+ if (!path) return { status: 400, body: { ok: false, error: '缺少仓库路径 path' } };
100
+ if (!message) return { status: 400, body: { ok: false, error: '缺少 commit message(先输入提交说明)' } };
101
+ const r = await commitWithAudit({
102
+ repoPath: path,
103
+ message,
104
+ push: false,
105
+ audit: true,
106
+ requirementsConfirmed: true,
107
+ pushMethod: cfg.pushMethod || 'ssh',
108
+ pushGate: false,
109
+ pushConfirmed: true,
110
+ });
111
+ if (!r.ok) {
112
+ const findings = r.audit?.findings || [];
113
+ const blockers = findings.filter((f) => f.severity === 'blocker').slice(0, 3)
114
+ .map((f) => `${f.file}:${f.line} ${f.rule}`);
115
+ return {
116
+ status: 200,
117
+ body: {
118
+ ok: false,
119
+ blocked: !!r.blocked,
120
+ error: r.error || '提交失败',
121
+ summary: r.audit?.summary,
122
+ blockers,
123
+ warnings: [],
124
+ warningCount: 0,
125
+ commitSha: '',
126
+ },
127
+ };
128
+ }
129
+ const findings = r.audit?.findings || [];
130
+ const warnings = findings.filter((f) => f.severity === 'warning');
131
+ return {
132
+ status: 200,
133
+ body: {
134
+ ok: true,
135
+ blocked: false,
136
+ commitSha: String(r.commitSha || '').slice(0, 7),
137
+ summary: r.audit?.summary,
138
+ blockers: [],
139
+ warningCount: warnings.length,
140
+ warnings: warnings.slice(0, 3).map((f) => `${f.file}:${f.line} ${f.rule}`),
141
+ },
142
+ };
143
+ }
@@ -0,0 +1,231 @@
1
+ /**
2
+ * HTTP 处理层 · 仓库列表/扫描端点(repos-local / repos-local-scan / -wait / -refresh / repos-cloud)
3
+ *
4
+ * 从 http-handlers.js 的 handleHttp 拆分而来。
5
+ * 统一签名:handleXxx(ctx) → { status, body };ctx = { req, query, body, env, cfg, path, method }。
6
+ */
7
+ import { existsSync } from 'node:fs';
8
+ import { access } from 'node:fs/promises';
9
+ import { join } from 'node:path';
10
+ import {
11
+ readAccountStatus, runGit, liveRemoteHead, liveRemoteHeadAsync, listCloudRepos,
12
+ resolveToken, describeRepo,
13
+ } from '../../git/index.js';
14
+ import {
15
+ readRepoIndexMap, updateRepoIndex,
16
+ } from '../../git/repo-index.js';
17
+ import { runScan, waitScanDelta } from '../../git/index.js';
18
+ import { getDefaultScanRoot } from '../scan-root.js';
19
+ import { LIST_LIVE_BUDGET_MS, PROBE_CONCURRENCY, SCAN_WAIT_TIMEOUT_MS } from './http-constants.js';
20
+
21
+ /** GET/POST /api/git-push/repos-local —— 本地仓库列表(读索引 + live 并发探测远端)。 */
22
+ /** 构建本地仓库列表(读索引 → 本地路径探测 → 标记待 remote live 探测)。 */
23
+ function buildLocalList(indexMap, root, deadline) {
24
+ return Object.keys(indexMap).map((name) => {
25
+ const entry = indexMap[name];
26
+ const local = entry.path || join(root, name);
27
+ const exists = existsSync(local);
28
+ const out = {
29
+ name,
30
+ path: exists ? local : '',
31
+ exists,
32
+ hasRemote: !!entry.repoUrl,
33
+ remote: entry.repoUrl || '',
34
+ indexed: entry,
35
+ visibility: entry.visibility || '未知',
36
+ defaultBranch: entry.defaultBranch || '',
37
+ cloudPushedAt: entry.pushedAt || '',
38
+ cloudOnly: !!entry.cloudOnly,
39
+ branch: '', ahead: null, behind: null, changed: 0, lastCommit: '',
40
+ };
41
+ if (exists) {
42
+ try {
43
+ const repoState = describeRepo(local);
44
+ out.branch = repoState.branch || '';
45
+ out.changed = repoState.changed || 0;
46
+ out.lastCommit = repoState.lastCommit || '';
47
+ out.localHead = repoState.lastCommit || '';
48
+ out.__needLive = Date.now() < deadline;
49
+ const lc = runGit(['log', '-1', '--format=%cI'], { cwd: local });
50
+ out.localHeadAt = lc.ok ? (lc.stdout || '').trim() : '';
51
+ } catch { /* 非 git 目录 */ }
52
+ }
53
+ return out;
54
+ });
55
+ }
56
+
57
+ /** 并发 live 探测远端(预算内限流),把 ahead/behind/remoteHead 合并回 list。 */
58
+ async function applyLiveRemote(list, deadline) {
59
+ const toProbe = list.filter((r) => r.__needLive && r.path && r.branch);
60
+ if (!toProbe.length) {
61
+ for (const r of list) {
62
+ delete r.__needLive;
63
+ if (r.hasRemote && r.path) {
64
+ r.ahead = null; r.behind = null; r.remoteHead = ''; r.remoteHeadAt = '';
65
+ r.synced = false; r.liveSkipped = true;
66
+ }
67
+ }
68
+ return list;
69
+ }
70
+ const results = new Map();
71
+ let cursor = 0;
72
+ const probeStart = Date.now();
73
+ const workers = Array.from({ length: Math.min(PROBE_CONCURRENCY, toProbe.length) }, async () => {
74
+ while (cursor < toProbe.length) {
75
+ const repoProbe = toProbe[cursor]; cursor += 1;
76
+ if (Date.now() > probeStart + deadline) { results.set(repoProbe.name, { live: { ok: false, sha: '' }, elapsed: -1 }); continue; }
77
+ const t0 = Date.now();
78
+ let live = { ok: false, sha: '' };
79
+ try { live = await liveRemoteHeadAsync({ repoPath: repoProbe.path, branch: repoProbe.branch || '' }); } catch { /* 忽略 */ }
80
+ results.set(repoProbe.name, { live, elapsed: Date.now() - t0 });
81
+ }
82
+ });
83
+ await Promise.all(workers);
84
+ for (const r of list) {
85
+ delete r.__needLive;
86
+ if (!r.path) continue;
87
+ const hit = results.get(r.name);
88
+ if (!hit) { if (!r.hasRemote) { /* 无远端 */ } continue; }
89
+ const { live } = hit;
90
+ if (live.ok && live.sha) {
91
+ r.remoteHead = live.sha.slice(0, 7);
92
+ const rc = runGit(['rev-list', '--left-right', '--count', `HEAD...${live.sha}`], { cwd: r.path });
93
+ if (rc.ok) {
94
+ const parts = (rc.stdout || '').trim().split(/\s+/).map(Number);
95
+ r.ahead = Number(parts[0]) || 0;
96
+ r.behind = Number(parts[1]) || 0;
97
+ } else {
98
+ r.ahead = null; r.behind = null; r.remoteHead = '';
99
+ }
100
+ const lt = runGit(['log', '-1', '--format=%cI', live.sha], { cwd: r.path });
101
+ r.remoteHeadAt = lt.ok ? (lt.stdout || '').trim() : '';
102
+ r.synced = r.ahead === 0 && r.behind === 0;
103
+ } else {
104
+ r.ahead = null; r.behind = null; r.remoteHead = ''; r.remoteHeadAt = '';
105
+ r.synced = false; r.liveSkipped = true;
106
+ }
107
+ }
108
+ return list;
109
+ }
110
+
111
+ /** GET/POST /api/git-push/repos-local —— 本地仓库列表(读索引 + live 并发探测远端)。 */
112
+ export async function handleReposLocal(ctx) {
113
+ const { query, env, cfg } = ctx;
114
+ const rebuild = query.rebuild === '1' || query.rebuild === 'true';
115
+ const path = String(query.path || '').trim() || getDefaultScanRoot(env, { defaultScanRoot: String(cfg.defaultScanRoot || '') });
116
+ const acct = readAccountStatus({ workspaceRoot: env.workspaceRoot });
117
+ const owner = (acct && acct.username) || '';
118
+ let rebuildIndexUpdated = false;
119
+ if (rebuild) {
120
+ const r = await updateRepoIndex({ workspaceRoot: path, token: '', owner: owner || 'EIGHTfs', extraRepos: env.extraRepos, extraReposFile: env.extraReposFile, offline: true, mode: 'rebuild' });
121
+ if (!r.ok) return { status: 500, body: { ok: false, error: '索引重建失败: ' + (r.error || '') } };
122
+ rebuildIndexUpdated = r.indexUpdated === true;
123
+ }
124
+ const indexMap = readRepoIndexMap(env.workspaceRoot);
125
+ let list = [];
126
+ if (indexMap) {
127
+ const deadline = Date.now() + LIST_LIVE_BUDGET_MS;
128
+ list = buildLocalList(indexMap, path, deadline);
129
+ await applyLiveRemote(list, deadline);
130
+ if (owner) list = list.filter((r) => (r.indexed?.owner === owner) || !r.indexed?.owner);
131
+ }
132
+ return { status: 200, body: { ok: true, root: path, count: list.length, repos: list, owner: owner || null, indexedAvailable: !!indexMap, indexUpdated: rebuildIndexUpdated === true } };
133
+ }
134
+
135
+ export function handleReposLocalScan(ctx) {
136
+ const { body, env, cfg } = ctx;
137
+ const acct = readAccountStatus({ workspaceRoot: env.workspaceRoot });
138
+ const scanOwner = (acct && acct.username) || 'EIGHTfs';
139
+ const scanRoot = String((body && body.path) || '').trim() || getDefaultScanRoot(env, { defaultScanRoot: String(cfg.defaultScanRoot || '') });
140
+ const r = runScan({ root: scanRoot, owner: scanOwner, workspaceRoot: env.workspaceRoot });
141
+ if (r.ok === false) return { status: 500, body: { ok: false, error: r.error || '扫描启动失败' } };
142
+ if (r.alreadyRunning) return { status: 200, body: { ok: false, running: true, error: '扫描进行中,不能重复扫描' } };
143
+ return { status: 200, body: { ok: true, started: true, scanId: r.scanId, running: true } };
144
+ }
145
+
146
+ /** GET|POST /api/git-push/repos-local-scan-wait —— 挂起等待新仓库 diff。 */
147
+ export async function handleReposLocalScanWait(ctx) {
148
+ const { query, body, env } = ctx;
149
+ const from = Number((query && query.from) || (body && body.from) || 0);
150
+ const scanDelta = await waitScanDelta({ from, timeoutMs: SCAN_WAIT_TIMEOUT_MS, workspaceRoot: env.workspaceRoot });
151
+ return { status: 200, body: { ok: true, newest: scanDelta.newest, version: scanDelta.version, done: scanDelta.done, running: scanDelta.running, timeout: scanDelta.timeout } };
152
+ }
153
+
154
+ /**
155
+ * 补查单个仓库的远端状态并回写索引 → 返回要并入响应的条目;name 为空时返回 null(跳过)。
156
+ * 抽出以降低 handleReposLocalRefresh 的嵌套深度(原为 for→try→if→if 四层)。
157
+ */
158
+ async function refreshOneTarget(t, env) {
159
+ const name = String(t && t.name || '').trim();
160
+ const repoPath = String(t && t.path || '').trim();
161
+ if (!name) return null;
162
+ try {
163
+ const branch = String(t && t.branch || '') || runGit(['branch', '--show-current'], { cwd: repoPath }).stdout.trim();
164
+ const live = await liveRemoteHead({ repoPath, branch });
165
+ const state = { remoteHead: '', ahead: null, behind: null, remoteHeadAt: '', synced: false };
166
+ if (live.ok && live.sha) {
167
+ state.remoteHead = live.sha.slice(0, 7);
168
+ state.remoteKnown = true;
169
+ const rc = runGit(['rev-list', '--left-right', '--count', `HEAD...${live.sha}`], { cwd: repoPath });
170
+ if (rc.ok) {
171
+ const parts = (rc.stdout || '').trim().split(/\s+/).map(Number);
172
+ state.ahead = Number(parts[0]) || 0;
173
+ state.behind = Number(parts[1]) || 0;
174
+ state.compareOk = true;
175
+ } else {
176
+ state.compareOk = false;
177
+ state.compareHint = '本地缺少远端提交对象,执行 git fetch 后即可比较领先/落后';
178
+ }
179
+ const lt = runGit(['log', '-1', '--format=%cI', live.sha], { cwd: repoPath });
180
+ state.remoteHeadAt = lt.ok ? (lt.stdout || '').trim() : '';
181
+ state.synced = state.ahead === 0 && state.behind === 0;
182
+ } else {
183
+ state.remoteKnown = false;
184
+ state.compareOk = false;
185
+ state.error = live.error || '远端不可达';
186
+ }
187
+ const up = updateRepoIndex({ workspaceRoot: env.workspaceRoot, repoName: name, remoteState: state, mode: 'single' });
188
+ return { name, ok: true, remoteState: state, indexUpdated: up.ok, error: up.error };
189
+ } catch (e) {
190
+ return { name, ok: false, error: String(e?.message || e) };
191
+ }
192
+ }
193
+
194
+ /** POST /api/git-push/repos-local-refresh —— 对 liveSkipped 仓库串行补查远端状态。 */
195
+ export async function handleReposLocalRefresh(ctx) {
196
+ const { body, env } = ctx;
197
+ const targets = Array.isArray((body && body.repos)) ? body.repos : [];
198
+ const refreshed = [];
199
+ for (const t of targets) {
200
+ const r = await refreshOneTarget(t, env);
201
+ if (r) refreshed.push(r);
202
+ }
203
+ return { status: 200, body: { ok: true, count: refreshed.length, refreshed } };
204
+ }
205
+
206
+ /** GET /api/git-push/repos-cloud —— 云端仓库列表 + 本地存在标记 + 索引合并。 */
207
+ export async function handleReposCloud(ctx) {
208
+ const { env, cfg } = ctx;
209
+ const r = await listCloudRepos({ token: resolveToken({ workspaceRoot: env.workspaceRoot }).token });
210
+ let indexUpdated = 0;
211
+ if (r && r.ok && Array.isArray(r.repos)) {
212
+ const indexMap = readRepoIndexMap(env.workspaceRoot);
213
+ const root = getDefaultScanRoot(env, { defaultScanRoot: String(cfg.defaultScanRoot || '') });
214
+ await Promise.all(r.repos.map(async (repo) => {
215
+ const repoName = String(repo.name || '').trim();
216
+ let local = indexMap && indexMap[repoName] ? (indexMap[repoName].path || '') : '';
217
+ if (!local && repoName) local = join(root, repoName);
218
+ let localExists = false;
219
+ if (local) {
220
+ try { await access(local); localExists = true; } catch { localExists = false; }
221
+ }
222
+ repo.localExists = localExists;
223
+ repo.localPath = localExists ? local : '';
224
+ }));
225
+ const acct = readAccountStatus({ workspaceRoot: env.workspaceRoot });
226
+ const cloudOwner = (acct && acct.username) || String(r.repos[0]?.fullName || '').split('/')[0] || 'EIGHTfs';
227
+ const merged = await updateRepoIndex({ workspaceRoot: env.workspaceRoot, owner: cloudOwner, cloudRepos: r.repos, mode: 'merge-cloud' });
228
+ if (merged.ok) indexUpdated = merged.updated || 0;
229
+ }
230
+ return { status: 200, body: { ...r, indexUpdated } };
231
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * HTTP 处理层 · 设置读写端点(settings-get / settings-set)
3
+ *
4
+ * 从 http-handlers.js 的 handleHttp 拆分而来。
5
+ * 统一签名:handleXxx(ctx) → { status, body };ctx = { req, query, body, env, cfg, path, method }。
6
+ * 设置读写走插件私有 config.json(不写公共 settings.yaml,见 settings-bridge.js 说明)。
7
+ */
8
+ import { redactConfig } from '../schema.js';
9
+ import { readSettings, writeSettingsKey, applySettingsToCfg, appendSettingsLog } from '../settings-bridge.js';
10
+ import { persistSshPub, persistGithubToken, persistNpmToken } from '../../git/index.js';
11
+
12
+ /** GET /api/git-push/settings-get —— 读插件 config.json 设置快照(token/ssh 掩码)。 */
13
+ export function handleSettingsGet(ctx) {
14
+ const { env } = ctx;
15
+ const snap = readSettings({ workspaceRoot: env.workspaceRoot });
16
+ // 同步 apply 后 cfg(settings-set 写盘后内存 cfg 即时更新;读侧也对齐
17
+ // ——部分字段如 auditEnabled 在 status/settings-get 都读 cfg,需与内存一致)
18
+ return { status: 200, body: { ok: true, settings: redactConfig(snap || {}) } };
19
+ }
20
+
21
+ /** POST /api/git-push/settings-set —— 写单个设置键(白名单防越权)。 */
22
+ export async function handleSettingsSet(ctx) {
23
+ const { body, env, cfg } = ctx;
24
+ const log = ctx.cfg?.log || ctx.log || { warn: () => {} };
25
+ const key = String(body.key || '');
26
+ // 白名单:仅允许前端设置卡片声明的键(凭据走这里 + 下方同步 cfg)
27
+ const allowedKeys = new Set([
28
+ 'auditEnabled', 'injectRequirements', 'injectSystemPrompt', 'auditScanScope',
29
+ 'maxScanFiles', 'weightOverrides',
30
+ 'maxCloneFileMB', 'cloneConcurrency',
31
+ 'pushMethod', 'auditRuleOrder', 'auditDisabledSlots',
32
+ 'githubToken', 'sshPub', 'pushGate',
33
+ 'npmToken', 'npmRegistry',
34
+ 'autoPushEnabled', 'autoPushTriggerText', 'autoPushScope', 'autoPushMessage',
35
+ ]);
36
+ if (!allowedKeys.has(key)) return { status: 400, body: { ok: false, error: `不支持的设置键: ${key || '(空)'}` } };
37
+ // 凭据落插件目录(github-token / *.pub / npmToken 一律 0600,绝不入库)
38
+ if (key === 'githubToken') {
39
+ const r = persistGithubToken(body.value, { workspaceRoot: env.workspaceRoot });
40
+ if (!r.ok) return { status: 400, body: { ok: false, error: `token 持久化失败: ${r.error || '未知错误'}` } };
41
+ } else if (key === 'sshPub') {
42
+ const r = persistSshPub(body.value, { workspaceRoot: env.workspaceRoot });
43
+ if (!r.ok) return { status: 400, body: { ok: false, error: `公钥持久化失败: ${r.error || '未知错误'}` } };
44
+ } else if (key === 'npmToken') {
45
+ // npmToken 与 githubToken 落在同一个 config.json:persistNpmToken 内部走 updateJsonAtomic(原子读改写),
46
+ // 不会覆盖 githubToken / sshPub(禁止「先读整份再写整份」的两步写)。
47
+ const r = persistNpmToken(body.value, { workspaceRoot: env.workspaceRoot });
48
+ if (!r.ok) return { status: 400, body: { ok: false, error: `npm token 持久化失败: ${r.error || '未知错误'}` } };
49
+ }
50
+ const r = await writeSettingsKey(key, body.value, { workspaceRoot: env.workspaceRoot });
51
+ appendSettingsLog({ key, value: body.value, via: 'http-settings-set', ok: r.ok, error: r.error }, { workspaceRoot: env.workspaceRoot });
52
+ if (!r.ok) {
53
+ return { status: r.code === 'BAD_KEY' ? 400 : 500, body: { ok: false, code: r.code || 'SETTINGS_WRITE', error: r.error } };
54
+ }
55
+ // 写盘成功后同步内存 cfg(即时生效;config.json 才是真源)
56
+ try {
57
+ applySettingsToCfg(cfg, { [key]: body.value });
58
+ } catch (e) {
59
+ log?.warn?.(`settings-set cfg 同步跳过:${e?.message || e}`);
60
+ }
61
+ return { status: 200, body: { ok: true, key, value: body.value, note: '设置已写入插件私有配置(config.json)' } };
62
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 宿主文档漂移检查器的接线模块(审计包边界,2026-10-13)。
3
+ *
4
+ * 边界规则:`lib/audit/**` 与 `lib/core/**` 不得 import 仓库脚本(`scripts/**`)——
5
+ * 「目录树漂移 / 函数列表漂移」这两个检查器属于**宿主侧**能力,由宿主在加载时注入给审计(见
6
+ * lib/audit/orchestrate.js 的 setHostDocChecks)。
7
+ *
8
+ * 用法:宿主入口加一行 `import '<相对路径>/host-doc-checks.js';` 即完成接线(本模块导入即安装,幂等)。
9
+ * 当前三处宿主入口:lib/app/tool-call.js(插件工具调用)、lib/commit-push.js(提交门禁)、cli.mjs(独立 CLI)。
10
+ * 未接线的环境(例如别人只依赖审计子路径):审计自动跳过这两类漂移 finding,其余检查不受影响。
11
+ */
12
+ import { checkDrift, findMarkedHostMd } from '../../scripts/doc-tree.mjs';
13
+ import { checkFuncDrift } from '../../scripts/doc-func.mjs';
14
+ import { setHostDocChecks } from '../audit/orchestrate.js';
15
+
16
+ /** 本宿主提供的检查器集合(供测试直接比对)。 */
17
+ export const HOST_DOC_CHECKS = { checkDrift, findMarkedHostMd, checkFuncDrift };
18
+
19
+ /** 显式接线(默认已由模块导入自动执行;单独调用用于测试或自定义注入)。 */
20
+ export function installHostDocChecks(checks = HOST_DOC_CHECKS) {
21
+ setHostDocChecks(checks);
22
+ return true;
23
+ }
24
+
25
+ installHostDocChecks();
@@ -0,0 +1,131 @@
1
+ /**
2
+ * 插件入口层 · HTTP 处理
3
+ *
4
+ * handleHttp(路由分发)、listRuleSlots(规则包列表端点)、
5
+ * adaptHttpHandler(把 handler 适配成宿主 HTTP 形态)。
6
+ * 与工具调用分开:HTTP 走 host 的路由与状态码,工具走结构化返回。
7
+ */
8
+
9
+ import { checkOrigin, checkBodySize, checkWriteConfirm, readJsonBody } from '../http/index.js';
10
+ import { defaultConfig } from '../client/index.js';
11
+ import {
12
+ handleStatus, handleScan, handleBrowse, handleTools, handleToolProbes,
13
+ handleRuleSlots, handleRuleDetail, handleAudit, handleToggleRule,
14
+ } from './handlers/meta.js';
15
+ import {
16
+ handleReposLocal, handleReposLocalScan, handleReposLocalScanWait, handleReposLocalRefresh, handleReposCloud,
17
+ } from './handlers/repos.js';
18
+ import {
19
+ handleRepoVisibility, handleRepoPush, handleRepoCommit,
20
+ } from './handlers/repo-actions.js';
21
+ import {
22
+ handleRepoClone, handleCloneLogs, handleCloneAbort, handleClonePreview, handleCloneProgress,
23
+ } from './handlers/clone.js';
24
+ import {
25
+ handleAccountStatus, handleAccountCheck, handleGenSshKey, handleApiQuota,
26
+ } from './handlers/account.js';
27
+ import {
28
+ handleSettingsGet, handleSettingsSet,
29
+ } from './handlers/settings.js';
30
+ import {
31
+ handleNpmAccount, handleNpmCheck, handleNpmOwned, handleNpmPackages, handleNpmInstall, handleNpmPublish,
32
+ } from './handlers/npm.js';
33
+ /** 规则槽位清单对外导出(实现迁至 handlers/meta.js)。 */
34
+ export { listRuleSlots } from './handlers/meta.js';
35
+
36
+ /**
37
+ * HTTP 适配:DSH webServer 原生 (req, res) ↔ v2 纯函数 handleHttp({status, body})。
38
+ * 返回 undefined 表示「非本插件路由 → 放行」(与旧版 handler 语义一致)。
39
+ */
40
+ export async function adaptHttpHandler(req, res, env, cfg) {
41
+ let body;
42
+ if (String(req?.method || 'GET').toUpperCase() === 'POST') {
43
+ // readJsonBody 是 callback 风格(非 Promise):包一层 Promise 等待完成
44
+ body = await new Promise((resolve) => readJsonBody(req, resolve));
45
+ }
46
+ const httpResult = await handleHttp(
47
+ { method: req?.method, url: req?.url, origin: req?.headers?.origin, headers: req?.headers, body },
48
+ env,
49
+ cfg,
50
+ );
51
+ if (!httpResult) return undefined;
52
+ try {
53
+ res.writeHead(httpResult.status, { 'Content-Type': 'application/json; charset=utf-8' });
54
+ res.end(JSON.stringify(httpResult.body, null, 2));
55
+ } catch { /* 响应已开始或连接已断:忽略 */ }
56
+ return httpResult;
57
+ }
58
+
59
+ /** POST JSON 体:只接受非数组对象,其它一律当空对象。 */
60
+ function readBody(req) {
61
+ const raw = req && req['body'];
62
+ return (raw && typeof raw === 'object' && !Array.isArray(raw)) ? raw : {};
63
+ }
64
+
65
+ /** 统一构造 handler 上下文(各 handler 签名 handleXxx(ctx))。 */
66
+ function buildCtx(req, method, env, cfg, query, body, path) {
67
+ return { req, method, env, cfg, query, body, path };
68
+ }
69
+
70
+ /**
71
+ * HTTP 端点分发(鉴权前置:Origin/CSRF → 413 → 写确认 → switch 路由)。
72
+ * 各端点实现已拆到 lib/app/handlers/ 模块(meta/repos/repo-actions/clone/account/settings)。
73
+ * @param {object} req { method, url, origin, headers, body? }
74
+ * @param {object} env
75
+ * @param {object} cfg
76
+ * @returns {Promise<{status:number, body:object}>}
77
+ */
78
+ export async function handleHttp(req = {}, env = {}, cfg = defaultConfig()) {
79
+ const method = String(req.method || 'GET').toUpperCase();
80
+ const originCheck = checkOrigin(method, req.origin, undefined, req.headers?.host);
81
+ if (!originCheck.ok) return { status: originCheck.status, body: { ok: false, ...originCheck } };
82
+ const sizeCheck = checkBodySize(Number(req.headers?.['content-length']) || 0);
83
+ if (!sizeCheck.ok) return { status: sizeCheck.status, body: { ok: false, ...sizeCheck } };
84
+ const path = String(req.url || '/').split('?')[0];
85
+ const query = Object.fromEntries(new URLSearchParams(String(req.url || '/').split('?')[1] || ''));
86
+ const body = readBody(req);
87
+ const writeConfirmOps = ['/api/git-push/rebuild', '/api/git-push/rollback', '/api/git-push/repo-push', '/api/git-push/repo-commit', '/api/git-push/repo-clone', '/api/git-push/repo-visibility'];
88
+ if (writeConfirmOps.includes(path)) {
89
+ const confirm = checkWriteConfirm(body);
90
+ if (!confirm.ok) return { status: confirm.status, body: { ok: false, ...confirm } };
91
+ }
92
+ const ctx = buildCtx(req, method, env, cfg, query, body, path);
93
+ switch (path) {
94
+ case '/api/git-push/status': return await handleStatus(ctx);
95
+ case '/api/git-push/scan': return handleScan(ctx);
96
+ case '/api/git-push/browse': return handleBrowse(ctx);
97
+ case '/api/git-push/repos-local': return await handleReposLocal(ctx);
98
+ case '/api/git-push/repos-local-scan': return handleReposLocalScan(ctx);
99
+ case '/api/git-push/repos-local-scan-wait': return await handleReposLocalScanWait(ctx);
100
+ case '/api/git-push/repos-local-refresh': return await handleReposLocalRefresh(ctx);
101
+ case '/api/git-push/repos-cloud': return await handleReposCloud(ctx);
102
+ case '/api/git-push/repo-visibility': return await handleRepoVisibility(ctx);
103
+ case '/api/git-push/repo-push': return await handleRepoPush(ctx);
104
+ case '/api/git-push/repo-commit': return await handleRepoCommit(ctx);
105
+ case '/api/git-push/repo-clone': return await handleRepoClone(ctx);
106
+ case '/api/git-push/clone-logs': return handleCloneLogs(ctx);
107
+ case '/api/git-push/clone-abort': return handleCloneAbort(ctx);
108
+ case '/api/git-push/clone-preview': return await handleClonePreview(ctx);
109
+ case '/api/git-push/clone-progress': return handleCloneProgress(ctx);
110
+ case '/api/git-push/tools': return handleTools(ctx);
111
+ case '/api/git-push/tool-probes': return handleToolProbes(ctx);
112
+ case '/api/git-push/rule-slots': return handleRuleSlots(ctx);
113
+ case '/api/git-push/rule-detail': return handleRuleDetail(ctx);
114
+ case '/api/git-push/audit': return await handleAudit(ctx);
115
+ case '/api/git-push/toggle-rule': return handleToggleRule(ctx);
116
+ case '/api/git-push/account-status': return handleAccountStatus(ctx);
117
+ case '/api/git-push/npm-account': return await handleNpmAccount(ctx);
118
+ case '/api/git-push/npm-check': return await handleNpmCheck(ctx);
119
+ case '/api/git-push/npm-owned': return await handleNpmOwned(ctx);
120
+ case '/api/git-push/npm-packages': return handleNpmPackages(ctx);
121
+ case '/api/git-push/npm-install': return handleNpmInstall(ctx);
122
+ case '/api/git-push/npm-publish': return await handleNpmPublish(ctx);
123
+ case '/api/git-push/account-check': return await handleAccountCheck(ctx);
124
+ case '/api/git-push/api-quota': return await handleApiQuota(ctx);
125
+ case '/api/git-push/gen-ssh-key': return handleGenSshKey(ctx);
126
+ case '/api/git-push/settings-get': return handleSettingsGet(ctx);
127
+ case '/api/git-push/settings-set': return await handleSettingsSet(ctx);
128
+ default:
129
+ return { status: 404, body: { ok: false, code: 'NOT_FOUND', message: `无此端点: ${method} ${path}` } };
130
+ }
131
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * dsh-git-push · 插件入口(宿主 main 指向本文件)
3
+ *
4
+ * 本文件只做再导出:实现全在 lib/app/*.js,本文件不含实现。
5
+ * 宿主要的是 name / Config / apply 这几个符号,再导出对 ESM 完全透明——
6
+ * 但**不要**把本文件写成空壳之外的东西:宿主 main 指向它,加载失败整插件不生效。
7
+ *
8
+ * lib/app/ 模块划分:
9
+ * schema.js 配置 schema(含宿主无 schemastery 时的最小兜底)
10
+ * constants.js 插件名 / 设置命名空间 / 统一提示常量
11
+ * slot-stats.js 槽位命中统计(模块级可变状态集中处)
12
+ * tools.js 暴露给宿主的工具声明
13
+ * inject-text.js 注入文本(开发者要求清单 / 审计结果块 / README 提醒)
14
+ * tool-call.js 工具调用分发(含读文件兜底)
15
+ * http-handlers.js HTTP 路由与规则包列表
16
+ * apply.js 插件装载入口(注册编排)
17
+ */
18
+
19
+ export { Config } from './schema.js';
20
+ export { MSG_REPO_REQUIRED, name, GIT_PUSH_SETTINGS_NS } from './constants.js';
21
+ export { setLastSlotHitStats, getLastSlotHitStats, getLastSlotHitMeta } from './slot-stats.js';
22
+ export { listTools } from './tools.js';
23
+ export { README_CHECK_HINT, buildRequirementsInjectionText, formatAuditBlock } from './inject-text.js';
24
+ export { callTool } from './tool-call.js';
25
+ export { adaptHttpHandler, listRuleSlots, handleHttp } from './http-handlers.js';
26
+ export { apply } from './apply.js';
27
+ export { parseGitAuditInput, sessionCwdOf, findGitRoot, resolveAuditRepo, runGitAuditCommand, registerSlashCommands } from './slash-commands.js';
28
+
29
+ import { routeRequest, readJsonBody } from '../http/index.js';
30
+ export { routeRequest, readJsonBody };