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
@@ -0,0 +1,279 @@
1
+ setStatus(msg) {
2
+ this.statusMsg = String(msg || '');
3
+ if (this.statusTimer) clearTimeout(this.statusTimer);
4
+ this.statusTimer = setTimeout(() => {
5
+ this.statusMsg = '';
6
+ this.publish();
7
+ }, dshgp_SAVED_MSG_MS);
8
+ }
9
+
10
+ /** 上下调整规则包次序(下覆盖上)。 */
11
+ moveSlot(slot, dir) {
12
+ const arr = [...this.ruleOrder];
13
+ const i = arr.indexOf(slot);
14
+ const j = i + dir;
15
+ if (i < 0 || j < 0 || j >= arr.length) return;
16
+ [arr[i], arr[j]] = [arr[j], arr[i]];
17
+ this.ruleOrder = arr;
18
+ this.publish();
19
+ // 次序持久化走 HTTP settings-set(写插件私有 config.json)。
20
+ // 不再 scope.set——scope.set 会把 auditRuleOrder 写进公共 settings.yaml
21
+ // (跨实例锁竞争 + isLoopback=memory 陷阱,见 settings-bridge.js 头部说明)。
22
+ this.persistSetting('auditRuleOrder', arr);
23
+ this.setStatus('✅ 规则包次序已保存:' + arr.join(' → '));
24
+ }
25
+
26
+ /**
27
+ * 前端设置写入通用入口(抽公共函数消除 toggle 系列重复)。
28
+ * 统一四件套:标记 editedKeys(防 loadSettingsFromHttp 异步 GET 旧值覆盖弹回)
29
+ * → publish(UI 立即反映)→ persistSetting(HTTP 落盘 config.json + loopback scope 双通道)。
30
+ * @param {string} key 设置键
31
+ * @param {unknown} value 值
32
+ * @param {string} okMsg flashSaved 成功文案(空=静默)
33
+ */
34
+ commitSetting(key, value, okMsg = '') {
35
+ this.editedKeys.add(key);
36
+ this.publish();
37
+ this.persistSetting(key, value, okMsg);
38
+ }
39
+
40
+ /** 审计开关(写回 auditEnabled)。 */
41
+ toggleAudit(checked) {
42
+ this.auditEnabled = !!checked;
43
+ // 交互修正:关闭父开关时**不再**把子开关的勾选抹掉。
44
+ // 子开关的勾选是用户偏好,父开关只管「此刻生不生效」(host 侧注入由
45
+ // cfg.auditEnabled && cfg.injectRequirements 门控)。原实现静默清勾选,
46
+ // 用户重开父开关时还得再点一遍子开关,且看不出勾选是被谁清掉的。
47
+ this.commitSetting('auditEnabled', this.auditEnabled, this.auditEnabled
48
+ ? '✅ 已开启:提交前自动审计'
49
+ : '✅ 已关闭:提交前不审计');
50
+ }
51
+
52
+ /**
53
+ * 设置持久化统一入口(**零 scope.set**,单通道走 host HTTP /settings-set → 写插件私有
54
+ * config.json)。彻底移除 scope.set:
55
+ * ① scope.set 会把设置写进公共 settings.yaml(跨实例写锁竞争 + isLoopback=memory 陷阱);
56
+ * ② loopback 直连时 scope.set 会写公共 yaml、反代时 memory 不落盘——两条路都不对,
57
+ * HTTP settings-set 与访问方式无关、无宿主锁竞争、重启从文件读回,是唯一可靠通道。
58
+ * @param {string} key 设置键
59
+ * @param {unknown} value 值
60
+ * @param {string} okMsg flashSaved 成功文案(空=静默)
61
+ */
62
+ persistSetting(key, value, okMsg = '') {
63
+ // 凭据防线(第三层):凭据键**绝不发送脱敏值/空值**——防止把回显用的
64
+ // 「ghp_…XYZ」这类打码串写回 config.json 覆盖真凭据(服务端 persistGithubToken/
65
+ // persistSshPub 另有 isMaskedValue 拦截,这里是 UI 侧提前拦住不发请求)。
66
+ if (key === 'githubToken' || key === 'sshPub') {
67
+ const sv = String(value ?? '').trim();
68
+ if (!sv) return; // 空值:不动该键(留空=保持不变)
69
+ if (sv.includes('…') || sv.includes('****') || /^gh[pous]_…/.test(sv)) {
70
+ this.failed = true;
71
+ this.flashSaved('❌ 拒绝写入:这是脱敏显示值,请输入完整凭据');
72
+ this.publish();
73
+ return;
74
+ }
75
+ }
76
+ // UI 提交调试日志(浏览器控制台可见;服务端另有 settings-ui.log 持久留痕)
77
+ if (typeof console !== 'undefined' && console.debug) {
78
+ try { console.debug('[dsh-git-push] UI 提交', key, '=', String(value).slice(0, dshgp_LOG_TRUNCATE) + (String(value).length > dshgp_LOG_TRUNCATE ? '…' : '')); } catch { /* 控制台不可用时跳过调试输出 */ }
79
+ }
80
+ void dshgp_postJson('/api/git-push/settings-set', { key, value }).then((data) => {
81
+ if (data && data.ok) {
82
+ if (okMsg) this.flashSaved(okMsg);
83
+ } else {
84
+ this.failed = true;
85
+ this.publish();
86
+ }
87
+ }).catch(() => {
88
+ this.failed = true;
89
+ this.publish();
90
+ });
91
+ }
92
+
93
+ /**
94
+ * 注入开发者要求清单开关(auditEnabled 的子开关)。
95
+ * 父开关关闭时**仍可勾选**(保留偏好、只置灰、不注入)——原实现在这里直接 return,
96
+ * 用户点了没任何反应,必须先开父开关再点一次(两遍)。
97
+ */
98
+ toggleInjectRequirements(checked) {
99
+ this.injectRequirements = !!checked;
100
+ this.commitSetting('injectRequirements', this.injectRequirements, this.injectRequirements
101
+ ? (this.auditEnabled ? '✅ 已开启:注入开发者要求清单' : '✅ 已勾选:待开启「提交前自动审计」后生效')
102
+ : '✅ 已关闭:不注入要求清单');
103
+ }
104
+
105
+ /**
106
+ * 注入总开关(写回 injectSystemPrompt;默认开)。
107
+ * 关 = host 侧 systemPrompt 段全部返回空串 + 上下文注入不注入;
108
+ * 开 = 功能用法/README 提醒/要求清单走系统提示词,环境(工作区/工具/skill 入口)走上下文首条注入。
109
+ * 注入段里的「开发者要求清单」仍受 auditEnabled + injectRequirements 双重门控。
110
+ */
111
+ toggleInjectSystemPrompt(checked) {
112
+ this.injectSystemPrompt = !!checked;
113
+ // 走 commitSetting 公共入口(自动含 editedKeys 标记 + publish + persistSetting);
114
+ // 此前漏了 editedKeys 标记,loadSettingsFromHttp 异步 GET 可能用旧值把它覆盖回去
115
+ this.commitSetting('injectSystemPrompt', this.injectSystemPrompt, this.injectSystemPrompt
116
+ ? '✅ 已开启:注入系统提示词/上下文'
117
+ : '✅ 已关闭:不注入');
118
+ }
119
+
120
+ /**
121
+ * 审计扫描范围切换:diff=仅本次变动(auditChanged,默认)/ full=全量(auditFull)。
122
+ * 按钮式单击切换;持久化走 host HTTP(persistence=memory 陷阱绕开方案,见 settings-bridge.js)。
123
+ */
124
+ toggleAuditScanScope(scope) {
125
+ const next = scope === 'full' ? 'full' : 'diff';
126
+ if (this.auditScanScope === next) return;
127
+ this.auditScanScope = next;
128
+ this.commitSetting('auditScanScope', next, next === 'full'
129
+ ? '✅ 已切换:审计扫描范围 = 全量(auditFull)'
130
+ : '✅ 已切换:审计扫描范围 = 部分(auditChanged,仅本次变动)');
131
+ }
132
+
133
+ /** 权重维度编辑(合并写回 weightOverrides JSON)。 */
134
+ editWeight(key, value) {
135
+ this.weightValues = { ...(this.weightValues || {}), [key]: value };
136
+ const json = JSON.stringify(this.weightValues);
137
+ this.commitSetting('weightOverrides', json, '✅ 权重已保存(合计 ' + dshgp_DIMENSIONS.reduce((a, d) => a + (this.weightValues[d.key] != null ? this.weightValues[d.key] : d.def), 0) + '),下次审计生效');
138
+ }
139
+
140
+ /**
141
+ * 新增 / 收敛:审计进阶 / 推送通道设置项通用提交。
142
+ * 更新本地镜像 → 走 commitSetting(HTTP settings-set → config.json)→ 即时反馈。
143
+ * @param {string} key maxScanFiles|pushMethod
144
+ * @param {unknown} value 新值
145
+ */
146
+ setAdvanced(key, value) {
147
+ const ok = /^(maxScanFiles|maxCloneFileMB|cloneConcurrency|pushMethod|pushGate|autoPushEnabled|autoPushTriggerText|autoPushScope)$/.test(key);
148
+ if (!ok) { this.setStatus('❌ 未知设置键: ' + key); return; }
149
+ const numKeys = { maxScanFiles: 1, maxCloneFileMB: 1, cloneConcurrency: 1 };
150
+ const boolKeys = { pushGate: 1, autoPushEnabled: 1 };
151
+ const enumKeys = { pushMethod: ['ssh', 'api', 'auto'], autoPushScope: ['session', 'all'] };
152
+ let v = value;
153
+ if (boolKeys[key]) v = value === true;
154
+ else if (numKeys[key]) v = Number(value) || 0;
155
+ else if (enumKeys[key]) {
156
+ const allowed = enumKeys[key];
157
+ v = allowed.includes(value) ? value : this[key];
158
+ if (v !== value) { this.setStatus('❌ 非法取值: ' + value); return; }
159
+ } else v = String(value ?? '');
160
+ this[key] = v;
161
+ this.commitSetting(key, v, '✅ ' + key + ' 已保存,下次生效');
162
+ }
163
+
164
+ edit(text) { this.text = String(text || ''); this.failed = false; this.publish(); }
165
+ editSsh(text) { this.sshPub = String(text || ''); this.failed = false; this.publish(); }
166
+ editEmail(text) { this.sshEmail = String(text || ''); this.failed = false; this.publish(); }
167
+
168
+ /** 保存 token / 公钥到插件配置(settingsScope)。 */
169
+ async save() {
170
+ const raw = this.text.trim();
171
+ const pub = this.sshPub.trim();
172
+ if ((!raw && !pub) || this.saving) return;
173
+ this.saving = true;
174
+ this.failed = false;
175
+ this.publish();
176
+ try {
177
+ // 凭据持久化走 persistSetting(纯 HTTP /settings-set → 服务端
178
+ // writeSettingsKey 写 config.json + persistGithubToken/persistSshPub 落插件目录,
179
+ // 不 scope.set——scope.set 会把凭据写进公共 settings.yaml 明文,反代下还不落盘)。
180
+ if (raw) this.persistSetting('githubToken', raw);
181
+ if (pub) this.persistSetting('sshPub', pub);
182
+ this.text = '';
183
+ this.sshPub = '';
184
+ this.saving = false;
185
+ // 保存后**刷新凭据与密钥的「已填写」状态**——此前只在写入 token 时本地置位
186
+ // tokenConfigured、sshConfigured 从不置位(保存公钥后徽标仍显示未填写),且本地置位
187
+ // 无法反映服务端规范化/落盘失败。统一走 refresh('account') 从 account-status 真源读回。
188
+ // 顺序:先弹「已保存」提示,再异步读回状态(读回过程不遮挡保存成功的反馈)。
189
+ this.flashSaved('✅ 凭据已保存');
190
+ await this.refresh('account');
191
+ } catch (_e) {
192
+ this.saving = false;
193
+ this.failed = true;
194
+ }
195
+ this.publish();
196
+ }
197
+
198
+ discard() { this.text = ''; this.sshPub = ''; this.failed = false; this.publish(); }
199
+
200
+ /** 一键生成 SSH 密钥对(/gen-ssh-key):公钥保存到 sshkey 并复制。 */
201
+ async genKey() {
202
+ const email = this.sshEmail.trim();
203
+ if (!email || this.genKeying) return;
204
+ this.genKeying = true;
205
+ this.genKeyError = '';
206
+ this.publish();
207
+ try {
208
+ const genRes = await dshgp_postJson('/api/git-push/gen-ssh-key', { email });
209
+ if (genRes && genRes.ok && genRes.pub) {
210
+ this.sshPub = genRes.pub;
211
+ this.publish();
212
+ await dshgp_copyText(genRes.pub);
213
+ this.genKeying = false;
214
+ this.flashSaved('✅ 公钥已生成:已填入 SSH 公钥框并复制到剪贴板');
215
+ } else {
216
+ this.genKeying = false;
217
+ this.genKeyError = (genRes && genRes.error) || '生成失败';
218
+ this.publish();
219
+ }
220
+ } catch (e) {
221
+ this.genKeying = false;
222
+ this.genKeyError = '生成失败: ' + (e && e.message || e);
223
+ this.publish();
224
+ }
225
+ }
226
+
227
+ /** 挂到槽系统的 hooks(供组件注入)。 */
228
+ inject() {
229
+ return {
230
+ hooks: { gitPushCard: this.store },
231
+ edit: (text) => this.edit(text),
232
+ editSsh: (text) => this.editSsh(text),
233
+ editEmail: (text) => this.editEmail(text),
234
+ save: () => { void this.save(); },
235
+ discard: () => this.discard(),
236
+ genKey: () => { void this.genKey(); },
237
+ toggleAudit: (checked) => this.toggleAudit(checked),
238
+ // 子开关动作必须在这里暴露:页面 props 来自 inject(),漏了会让 onChange 调到 undefined
239
+ toggleInjectRequirements: (checked) => this.toggleInjectRequirements(checked),
240
+ toggleInjectSystemPrompt: (checked) => this.toggleInjectSystemPrompt(checked),
241
+ toggleAuditScanScope: (scope) => this.toggleAuditScanScope(scope),
242
+ editWeight: (key, value) => this.editWeight(key, value),
243
+ setAdvanced: (key, value) => this.setAdvanced(key, value),
244
+ moveSlot: (slot, dir) => this.moveSlot(slot, dir),
245
+ toggleDisabled: (slot) => { void this.toggleDisabled(slot); },
246
+ // 统一刷新入口(参数控制刷哪部分)——设置 / 账号 / 本地仓库 / 云端 / 槽位
247
+ refresh: (parts, opts) => { void this.refresh(parts, opts); },
248
+ refreshAccount: () => { void this.refresh('account'); }, // 离线读 json(启动/push后/渲染)
249
+ recheckAccount: () => { void this.recheckAccount(); }, // 在线校验写 json(「重新检测」)
250
+ // npm 账号:与 GitHub 账号**同一套注入与语义**(离线刷新 / 在线校验 / 名下包列表)
251
+ refreshNpmAccount: () => { void this.refreshNpmAccount(); },
252
+ recheckNpmAccount: () => { void this.recheckNpmAccount(); },
253
+ refreshNpmOwned: () => { void this.loadNpmOwned(); },
254
+ installNpmPackage: (opts) => { void this.installNpmPackage(opts); },
255
+ // 安装交互四段(入口/选择/进度/回执)——与 GitHub 克隆同款注入
256
+ openInstallFlow: (pkg) => this.openInstallFlow(pkg),
257
+ chooseInstallDir: () => this.chooseInstallDir(),
258
+ confirmInstallGlobal: () => this.confirmInstallGlobal(),
259
+ cancelInstallDialog: () => this.cancelInstallDialog(),
260
+ // 账号卡片:本地/云端 动作
261
+ scanLocalRepos: (path, rebuild) => { void this.refresh('repos', { path, rebuild }); },
262
+ startScan: (path) => { void this.startScan(path); }, // 扫描按钮:独立进程后台扫描 + 逐条追加
263
+ loadCloudRepos: () => { void this.refresh('cloud'); },
264
+ pushLocalRepo: (path) => { void this.pushLocalRepo(path); },
265
+ commitLocalRepo: (path) => { void this.commitLocalRepo(path); }, // 本地 commit(复用提交审计)
266
+ cloneFlow: (repo) => this.cloneFlow(repo),
267
+ requestVisSwitch: (fullName, target) => this.requestVisSwitch(fullName, target), // 弹独立确认面板(1.5.4)
268
+ confirmVisSwitch: () => { void this.confirmVisSwitch(); },
269
+ cancelVisSwitch: () => { this.cancelVisSwitch(); },
270
+ cloneConfirmed: () => { void this.cloneConfirmed(); }, // 预览确认框「开始克隆」
271
+ // 预览框勾选「带真实历史」:只改本地选择并重绘,真正的参数在提交时随 history 一起发出
272
+ setCloneHistory: (v) => { this.cloneHistory = (v === true); this.publish(); },
273
+ cancelPreview: () => { this.cancelPreview(); }, // 预览确认框「取消」
274
+ };
275
+ }
276
+ }
277
+
278
+ const inject = ['slots'];
279
+
@@ -0,0 +1,72 @@
1
+ function apply(ctx) {
2
+ // 【常驻诊断 · 前端接线失败可见化】apply 整体包一层 try/catch,把真实异常打到控制台。
3
+ // 背景:cordis 只把失败的 client entry 标成 failed(页面仅显示
4
+ // `web boot: 1 entry did not activate` / `dsh-git-push: failed`),真实异常既不进页面、
5
+ // 也不进宿主日志——本次 0.2.0 适配就是靠这层 console.error 才定位到
6
+ // `cannot get property "settingsScope" without inject`(读未 inject 的服务属性会抛)。
7
+ // 保留为常驻诊断(不是临时探针):任何未来的接线异常都会直接出现在浏览器控制台。
8
+ try {
9
+ // 版本兼容自动切换(2.3.0):DSH 0.2.0 移除了 client 注入服务 settingsScope,
10
+ // 声明依赖会导致 entry pending(waiting for service: settingsScope)→ 插件不激活。
11
+ // git-push 设置/凭据真源早已全链路走 HTTP(settings-bridge → config.json),
12
+ // scope 仅剩「订阅 + 初值兜底」(零 scope.set),故特性检测自动切换:
13
+ // 有真 scope(0.1.6)用它;没有(0.2.0)用空 fallback(快照空 → 全走 HTTP,行为一致)。
14
+ // 【2.3.0 修复】必须用 ctx.get() 防御式读取:cordis 里「读未 inject 的服务属性」会直接抛
15
+ // `cannot get property "settingsScope" without inject`(实测:直接写 ctx.settingsScope
16
+ // 会让 0.2.0 上 client entry 激活失败 → 页面报 web boot: dsh-git-push: failed)。
17
+ // 外面再包一层 try/catch:ctx.get 本身在个别宿主实现里也可能抛(1.0.10 回归不变量:
18
+ // 「ctx.get 抛错不崩」),两层防护保证任何宿主形态下 apply 都不因此中断。
19
+ let settingsScope;
20
+ try {
21
+ settingsScope = typeof ctx.get === 'function' ? ctx.get('settingsScope') : undefined;
22
+ } catch {
23
+ settingsScope = undefined;
24
+ }
25
+ const scope = settingsScope
26
+ ? settingsScope.bind({ namespace: SETTINGS_NS })
27
+ : { subscribe: () => () => {}, getSnapshot: () => ({ value: undefined }) };
28
+ const controller = new dshgp_Controller(scope);
29
+ const store = controller.store;
30
+ // (修复「重启后不预读」):**每次进设置页都预读**账号信息 + 本地仓库列表
31
+ // (读 account-status.json / dsh-repo-index.json,本地文件幂等便宜)——此前的模块级
32
+ // `dshgp_startupLoaded` 标记在 DSH bundle 常驻(浏览器不刷新)时保持 true,
33
+ // 导致「第一次预读后,重启/重进设置页不再预读」。改为每次 apply 都读,跟随最新 json。
34
+ // 后续仍可手动「重新检测 / 扫描」在线刷新。
35
+ // 读取复用「本地仓库列表选择的路径」(localStorage dshgp-scan-path,本地面板扫描时写入);
36
+ // 没选过则空 → 后端自动识别 DSH 家根。
37
+ let savedPath = dshgp_localGet('dshgp-scan-path');
38
+ void controller.refreshAccount();
39
+ void controller.scanLocalRepos(savedPath, false); // 只读索引(不重建,读 json)
40
+ // uSES 桥:SnapshotStore 是裸 observable,用 useSyncExternalStore 自建 selector hook
41
+ const useCardState = (selector) => {
42
+ const snap = react.useSyncExternalStore(store.subscribe, store.getSnapshot);
43
+ return selector ? selector(snap) : snap;
44
+ };
45
+ // 统一 props:组件层不感知 controller,全走 store + 动作注入
46
+ const makeProps = (state) => Object.assign({ state, useGitPushCard: useCardState }, controller.inject());
47
+ function SectionPage() {
48
+ const state = useCardState((s) => s);
49
+ if (!state.available) return null;
50
+ const props = makeProps(state);
51
+ return jsx.jsx(dshgp_GitPushPage, props);
52
+ }
53
+ // 只注册 settings.section(独立侧边栏页);settings.plugin.item(插件配置卡)已删除
54
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
55
+ name: 'settings.section',
56
+ id: 'dsh-git-push',
57
+ order: 40,
58
+ label: () => 'Git 提交推送',
59
+ }, () => react.createElement(SectionPage, null)));
60
+ } catch (e) {
61
+ // 【常驻诊断】真实异常进控制台(页面只显示 "dsh-git-push: failed",看不出原因)
62
+ console.error('[dsh-git-push] client apply 失败:', (e && (e.stack || e.message)) || String(e));
63
+ throw e;
64
+ }
65
+ }
66
+
67
+ exports.NS = NS;
68
+ exports.apply = apply;
69
+ exports.inject = inject;
70
+ return module.exports;
71
+ },
72
+ });