dsh-git-push 3.0.0 → 3.1.0

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 (65) hide show
  1. package/README.md +76 -48
  2. package/cli.mjs +4 -3
  3. package/lib/app/apply.js +11 -9
  4. package/lib/app/command-registry.js +4 -2
  5. package/lib/app/handlers/http-constants.js +8 -0
  6. package/lib/app/handlers/preprocess.js +3 -6
  7. package/lib/app/handlers/repo-actions.js +0 -1
  8. package/lib/app/handlers/repos.js +137 -10
  9. package/lib/app/handlers/settings.js +34 -15
  10. package/lib/app/index.js +1 -1
  11. package/lib/app/inject-text.js +3 -18
  12. package/lib/app/schema.js +20 -10
  13. package/lib/app/settings-bridge.js +60 -8
  14. package/lib/app/tool-call.js +26 -22
  15. package/lib/cli/commands-vcs.mjs +35 -1
  16. package/lib/cli/shared.mjs +1 -1
  17. package/lib/client/index.js +11 -16
  18. package/lib/client-parts/git/account.js +21 -12
  19. package/lib/client-parts/git/actions.js +23 -77
  20. package/lib/client-parts/git/apply.js +8 -2
  21. package/lib/client-parts/git/browser.js +1 -1
  22. package/lib/client-parts/git/const.js +33 -1
  23. package/lib/client-parts/git/controller.js +175 -176
  24. package/lib/client-parts/git/icons.js +1 -1
  25. package/lib/client-parts/git/loader.js +1 -1
  26. package/lib/client-parts/git/npm.js +56 -37
  27. package/lib/client-parts/git/page.js +53 -1
  28. package/lib/client-parts/git/repo.js +8 -1
  29. package/lib/client-parts/git/settings.js +13 -1
  30. package/lib/client-parts/git/state.js +237 -0
  31. package/lib/client-parts/git/utils.js +1 -1
  32. package/lib/client.js +631 -312
  33. package/lib/commit-push/pre-commit-engine.js +584 -32
  34. package/lib/commit-push.js +63 -47
  35. package/lib/context/index.js +7 -5
  36. package/lib/core/config.js +1 -27
  37. package/lib/core/exec.js +2 -11
  38. package/lib/git/identity-rewrite.js +1 -1
  39. package/lib/git/index.js +1 -1
  40. package/lib/git/push.js +2 -17
  41. package/lib/git/repo-index.js +8 -3
  42. package/lib/npm/install.js +1 -1
  43. package/lib/npm/registry.js +2 -2
  44. package/lib/plugin/auto-push.js +3 -6
  45. package/lib/preprocess/providers.js +5 -1
  46. package/lib/self/index.js +1 -1
  47. package/package.json +4 -7
  48. package/skills/dev/dsh-git-push.md +9 -9
  49. package/skills/guide/guide-commit-push.md +11 -13
  50. package/skills/workflow/README.md +0 -1
  51. package/skills/workflow/task-completion-report.md +2 -2
  52. package/.auditignore +0 -30
  53. package/.gitignore +0 -43
  54. package/lib/BUGFIX-NOTES-2026-09-14.md +0 -278
  55. package/lib/app/schema-preprocess.js +0 -42
  56. package/lib/user-requirements.json +0 -15
  57. package/scripts/build-client.mjs +0 -133
  58. package/scripts/bump-version.mjs +0 -178
  59. package/scripts/check.mjs +0 -205
  60. package/scripts/doc-func.mjs +0 -212
  61. package/scripts/doc-tree.mjs +0 -458
  62. package/scripts/doc-version.mjs +0 -149
  63. package/scripts/local-registry.mjs +0 -38
  64. package/scripts/scan-version.mjs +0 -125
  65. package/scripts/version-source.mjs +0 -173
@@ -1,4 +1,4 @@
1
- /* ─── 第 11/13 片 · Controller(状态机 + 数据加载 + 动作注入) ─────────────────── */
1
+ /* ─── 第 12/14 片 · Controller(状态机 + 数据加载 + 动作注入) ─────────────────── */
2
2
  class dshgp_Controller {
3
3
  constructor(scope) {
4
4
  this.scope = scope;
@@ -9,23 +9,9 @@
9
9
  this.failed = false;
10
10
  this.savedMsg = '';
11
11
  this.savedTimer = null;
12
- this.auditEnabled = false;
13
- this.injectRequirements = false;
14
- // 注入总开关(默认开;新增, 扩展为系统提示词+上下文)
15
- this.injectSystemPrompt = true;
16
- // 审计扫描范围(diff|full)——设置持久化走 host HTTP,前端本地字段镜像
17
- this.auditScanScope = 'diff';
18
- this.ruleOrder = [];
19
- this.slotMeta = {};
20
- this.weightValues = {};
21
- // 补齐:以下键此前只有 schema 声明与 HTTP 白名单,前端**没有 UI 控件**
22
- // (只能看不能改)→ 设置「基本都没真正保存」的根源。这里补状态镜像 + 提交 + 回读。
23
- this.maxScanFiles = 3000; // 全量审计文件数上限(0=不限)
24
- this.pushMethod = 'ssh'; // ssh | api | auto
25
- this.pushGate = false; // 推送门禁(开启后 push 需显式放行)
26
- // defaultScanRoot/commitMessage 设置移除——默认扫描路径复用本地仓库
27
- // 列表选择路径(localStorage dshgp-scan-path),提交信息留空由调用方/AI 生成。
28
- // 禁用态不再前端变量存储,以 yml 顶层 disabled 为准(listRuleSlots 解析)
12
+ // 设置类字段的默认值统一来自 dshgp_DEFAULT_SETTINGS(§五:默认值只有一个来源),
13
+ // 这里不再逐行手写 —— 手写就等于在分片里又存了一份默认值。
14
+ Object.assign(this, dshgp_DEFAULT_SETTINGS);
29
15
  this.statusMsg = '';
30
16
  this.statusTimer = null;
31
17
  // 账号信息(纯展示)
@@ -73,8 +59,6 @@
73
59
  this.cloneHistory = null; // 预览框「带真实历史」勾选:null=未表态(跟随后端默认 true)、true/false=用户显式选择
74
60
  this.clonePending = { repo: '', dir: '' }; // 预览后待确认的上下文
75
61
  this.visConfirm = null; // 1.5.4:待确认的可见性切换({fullName, target, cur},命中则弹独立确认面板)
76
- this.maxCloneFileMB = 10; // clone 单文件体积上限(MB);0=不限
77
- this.cloneConcurrency = 6; // clone 并发下载数
78
62
  this.repoFeedback = {}; // { path: {ok, msg} } push 结果反馈(成功绿/失败红)
79
63
  // 规则包加载
80
64
  this.slotLoading = false;
@@ -96,12 +80,6 @@
96
80
  // 公共 settings.yaml 已零写入(scope.set 全移除),snap.value 里这些键恒缺省,
97
81
  // 此前把 sshConfigured 覆盖成 !!snap.value.sshPub(恒 false)导致「配置了却显示
98
82
  // 未配置」,且每次 scope 发布都弹回,与 loadSettingsFromHttp 拉回的真值互相打架。
99
- // 修复「规则包统计全是 0」:slotMeta 与 ruleOrder 同理,也不再从 scope 覆盖。
100
- // snap.value.ruleSlotMeta 是 schema 里声明为「host 启动填充」的字段,但**宿主从未写入**,
101
- // 于是每次 scope 发布都把它(空对象)赋给 slotMeta,刚由 loadSlots() 拉到的真实统计被清空,
102
- // 所有规则包行回退到 {blocker:0,warning:0,pass:0,total:0} 兜底值 → 列表里数字全是 0。
103
- // 权威来源 = loadSlots() 的后端结果(动态发现全部 yml 并带 stats);启停的即时反馈由
104
- // toggleDisabled 自己改 slotMeta、随后 loadSlots 对账。
105
83
  }
106
84
  this.publish();
107
85
  });
@@ -111,24 +89,49 @@
111
89
  // refreshAccount(/account-check 读凭据文件真源)与 loadSettingsFromHttp 刷新。
112
90
  const snap0 = this.scope.getSnapshot();
113
91
  if (snap0 && snap0.value) {
114
- if (typeof snap0.value.auditEnabled === 'boolean') this.auditEnabled = snap0.value.auditEnabled;
115
- if (typeof snap0.value.injectRequirements === 'boolean') this.injectRequirements = snap0.value.injectRequirements;
116
92
  if (typeof snap0.value.injectSystemPrompt === 'boolean') this.injectSystemPrompt = snap0.value.injectSystemPrompt;
117
- if (typeof snap0.value.auditScanScope === 'string') this.auditScanScope = snap0.value.auditScanScope;
118
- const wo0 = String(snap0.value.weightOverrides || '');
119
- if (wo0.trim()) { try { this.weightValues = JSON.parse(wo0) || {}; } catch { /* 忽略 */ } }
120
93
  }
121
- // 若 loadSlots 尚未返回,先用已发现的槽位做占位显示(不含 private/template)
122
- if (!this.ruleOrder.length && Object.keys(this.slotMeta).length) {
123
- this.ruleOrder = Object.keys(this.slotMeta).filter((s) => s !== 'private' && s !== 'template');
124
- }
125
- // 改走统一刷新入口(一次调用刷设置与槽位;账号仍按需在页面 mount 时刷)
126
- void this.refresh(['settings', 'slots']);
127
- // 账号状态改由「首次打开账号信息页」时(dshgp_AccountTab 的 mount effect)
128
- // 触发 refreshAccount,避免构造阶段与页面打开重复拉取;此处不再自动刷新。
129
- // 设置持久化走 HTTP 读宿主 scope(绕开 client isLoopback=memory 陷阱——
130
- // 反代访问时 scope 快照恒 unavailable,从宿主侧读已落盘设置,重启后开关保持勾选)
131
- // 该读取已并入上方 this.refresh(['settings','slots']),此处不再重复请求。
94
+ // ── UI 状态工厂(单一真相源)──
95
+ // 读、状态、重放都收在这一层;本类的同名字段只是它的**派生投影**(R1)。
96
+ // 注册顺序 = 首屏依赖顺序:设置/账号/npm 决定首屏,列表自己带加载态。
97
+ this.uiState = dshgp_createUiState({ onChange: () => this.publish() });
98
+ this.uiState
99
+ .register('settings', { load: () => dshgp_getJson('/api/git-push/settings-get') })
100
+ .register('account', { load: () => dshgp_getJson('/api/git-push/account-status') })
101
+ .register('npm', { load: () => dshgp_getJson('/api/git-push/npm-account') })
102
+ // 列表:后端已改为「只读索引快照(毫秒级)」,远端状态由后台补(见 task-23 M3)
103
+ .register('repos', { load: (arg) => this.loadReposPayload(arg), timeoutMs: 15_000 })
104
+ // npm 子页的「已装依赖」也是数据(曾由组件自己 useState + fetch,形成第二份真相)
105
+ .register('npmPackages', { load: (arg) => this.loadNpmPackagesPayload(arg) });
106
+ // 渲染器 = 幂等的「按值刷显示」(R3);面板重建后由 markRebuilt 重放(§三)
107
+ this.uiState
108
+ .setRenderer('settings', (payload) => this.applySettingsPayload(payload))
109
+ .setRenderer('account', (payload) => this.applyAccountPayload(payload))
110
+ .setRenderer('npm', (payload) => this.applyNpmPayload(payload))
111
+ .setRenderer('repos', (payload) => this.applyReposPayload(payload));
112
+ // 首屏门禁只等「快的三个」:列表自己显示加载态,不能把首屏拖成 30s 空白
113
+ this.uiFirstPaintNames = ['settings', 'account', 'npm'];
114
+ // R2:读回早于首次渲染 —— 由 apply.js 的 loadAll() 驱动,读完才放开骨架
115
+ }
116
+
117
+ /**
118
+ * 首屏是否已可渲染真实内容(R2 门禁)。
119
+ * 只判断首屏必需资源:settings/account/npm。**不是**「全都读完」——
120
+ * 列表可能仍在读,它自己有加载态;把列表并进门禁会让首屏退化成骨架。
121
+ * @returns {{ready: boolean, pending: string[]}}
122
+ */
123
+ uiReadyInfo() {
124
+ // 构造期 project() 先于状态工厂创建(store 的初始快照就是在构造里取的)⇒ 这里必须容忍
125
+ if (!this.uiState) return { ready: false, pending: (this.uiFirstPaintNames || []).slice() };
126
+ const pending = (this.uiFirstPaintNames || []).filter((name) => this.uiState.status(name).state === 'loading'
127
+ || (this.uiState.value(name) === undefined && this.uiState.status(name).state !== 'error'));
128
+ return { ready: pending.length === 0, pending: pending };
129
+ }
130
+
131
+ /** 某资源的界面状态(组件按它分支渲染占位/错误/内容,不再靠值真假猜)。 */
132
+ uiStatus(name) {
133
+ if (!this.uiState) return { state: 'idle', loading: false, error: '', at: 0, hasValue: false };
134
+ return this.uiState.status(name);
132
135
  }
133
136
  project() {
134
137
  // 恒可用/恒可写:数据与写入全走 HTTP(settings-get/settings-set/account-check/rule-slots),
@@ -136,21 +139,15 @@
136
139
  // persistence——反代/非 loopback 访问时恒 memory 模式、status 恒 unavailable、
137
140
  // writable 恒 false(isLoopback=memory 陷阱)。若仍以快照判 available,设置侧边栏
138
141
  // 在反代访问下会整页空白(SectionPage return null)且输入框全禁用,故绕开快照判定。
142
+ const readyInfo = this.uiReadyInfo();
139
143
  return {
140
144
  available: true,
141
145
  writable: true,
142
146
  text: this.text,
143
147
  sshPub: this.sshPub,
144
148
  sshEmail: this.sshEmail,
145
- auditEnabled: this.auditEnabled,
146
- injectRequirements: this.injectRequirements,
149
+ preCommitEnabled: this.preCommitEnabled,
147
150
  injectSystemPrompt: this.injectSystemPrompt,
148
- auditScanScope: this.auditScanScope,
149
- ruleOrder: this.ruleOrder,
150
- slotMeta: this.slotMeta,
151
- weightValues: this.weightValues,
152
- // 补齐:审计进阶 / 推送默认值状态镜像(供 UI 渲染)
153
- maxScanFiles: this.maxScanFiles,
154
151
  pushMethod: this.pushMethod,
155
152
  pushGate: this.pushGate, // 推送门禁(开启后 push 需显式放行)
156
153
  // defaultScanRoot/commitMessage 状态镜像移除(设置已删除)
@@ -175,8 +172,6 @@
175
172
  npmInstallResult: this.npmInstallResult,
176
173
  npmInstallDialog: this.npmInstallDialog,
177
174
  npmInstallProgress: this.npmInstallProgress,
178
- slotLoading: this.slotLoading,
179
- slotError: this.slotError,
180
175
  refreshError: this.refreshError, // 统一刷新入口的部分级错误
181
176
  statusMsg: this.statusMsg,
182
177
  genKeying: this.genKeying,
@@ -197,6 +192,18 @@
197
192
  maxCloneFileMB: this.maxCloneFileMB,
198
193
  cloneConcurrency: this.cloneConcurrency,
199
194
  repoFeedback: this.repoFeedback,
195
+ // UI 状态工厂门禁与状态位(组件据此分支:骨架 / 内容 / 失败可重试)
196
+ uiReady: readyInfo.ready,
197
+ uiPending: readyInfo.pending,
198
+ uiStatus: {
199
+ settings: this.uiStatus('settings'),
200
+ account: this.uiStatus('account'),
201
+ npm: this.uiStatus('npm'),
202
+ repos: this.uiStatus('repos'),
203
+ npmPackages: this.uiStatus('npmPackages'),
204
+ },
205
+ // npm 子页「已装依赖」数据:单一真相在状态工厂,组件只读这里(禁止再自己 useState 一份)
206
+ npmPackages: this.uiState ? this.uiState.value('npmPackages') : null,
200
207
  dirty: this.text.trim().length > 0 || this.sshPub.trim().length > 0,
201
208
  saving: this.saving,
202
209
  failed: this.failed,
@@ -246,7 +253,7 @@
246
253
  * await this.refresh('repos', { rebuild: true }); // 重建索引后刷本地列表
247
254
  */
248
255
  async refresh(parts = 'all', opts = {}) {
249
- const PARTS = ['settings', 'account', 'npm', 'repos', 'cloud', 'slots'];
256
+ const PARTS = ['settings', 'account', 'npm', 'repos', 'cloud'];
250
257
  let list;
251
258
  if (parts === 'all' || parts === undefined || parts === null) list = PARTS.slice();
252
259
  else list = (Array.isArray(parts) ? parts : [parts])
@@ -267,7 +274,6 @@
267
274
  }
268
275
  else if (p === 'repos') await this.scanLocalRepos(opts.path, opts.rebuild, { silent: opts.silent });
269
276
  else if (p === 'cloud') await this.loadCloudRepos({ silent: opts.silent });
270
- else if (p === 'slots') await this.loadSlots({ silent: opts.silent });
271
277
  } catch (e) {
272
278
  // 单个部分失败不影响其余部分:记录到统一错误位,继续刷下一个
273
279
  this.refreshError = `${p}: ` + (e && e.message || e);
@@ -327,79 +333,65 @@
327
333
  }, 1000);
328
334
  }
329
335
 
336
+ /** 设置读回:**薄壳**(读与状态由 UI 状态工厂负责,本方法只保留"重读"语义)。 */
330
337
  async loadSettingsFromHttp() {
331
- try {
332
- const settingsRes = await dshgp_getJson('/api/git-push/settings-get');
333
- if (!settingsRes || !settingsRes.ok || !settingsRes.settings) return;
334
- const v = settingsRes.settings;
335
- if (typeof v.auditEnabled === 'boolean' && !this.editedKeys.has('auditEnabled')) this.auditEnabled = v.auditEnabled;
336
- if (typeof v.injectRequirements === 'boolean' && !this.editedKeys.has('injectRequirements')) this.injectRequirements = v.injectRequirements;
338
+ return this.uiState.reload('settings');
339
+ }
340
+
341
+ /**
342
+ * 把 /settings-get 的返回投影到本类字段(幂等)。
343
+ * 用户正在编辑的键跳过(editedKeys):GET 是异步的,回来的是旧值,
344
+ * 直接覆盖会把刚点的勾选弹回默认。
345
+ */
346
+ applySettingsPayload(payload) {
347
+ const v = (payload && payload.settings) || null;
348
+ if (!v) return;
349
+ {
350
+ // 预处理开关在 config.json 里是嵌套的 preCommit.enabled(与引擎 command/args 同块)
351
+ if (v.preCommit && typeof v.preCommit.enabled === 'boolean' && !this.editedKeys.has('preCommitEnabled')) {
352
+ this.preCommitEnabled = v.preCommit.enabled;
353
+ }
337
354
  if (typeof v.injectSystemPrompt === 'boolean' && !this.editedKeys.has('injectSystemPrompt')) this.injectSystemPrompt = v.injectSystemPrompt;
338
- if (typeof v.auditScanScope === 'string' && !this.editedKeys.has('auditScanScope')) this.auditScanScope = v.auditScanScope;
339
- // 补齐回读:新增 UI 的 7 键(advanced),重启后从 config.json 恢复勾选/取值
340
- if (typeof v.maxScanFiles === 'number' && !this.editedKeys.has('maxScanFiles')) this.maxScanFiles = v.maxScanFiles;
355
+ // 补齐回读:advanced 键,重启后从 config.json 恢复勾选/取值
341
356
  if (typeof v.maxCloneFileMB === 'number' && !this.editedKeys.has('maxCloneFileMB')) this.maxCloneFileMB = v.maxCloneFileMB;
342
357
  if (typeof v.cloneConcurrency === 'number' && !this.editedKeys.has('cloneConcurrency')) this.cloneConcurrency = v.cloneConcurrency;
343
358
  if (typeof v.pushMethod === 'string' && !this.editedKeys.has('pushMethod')) this.pushMethod = v.pushMethod;
344
359
  // 补漏:pushGate(推送门禁)此前**不在回读列表**——构造函数默认 false,
345
360
  // 打开/刷新设置页时不被宿主真值覆盖,界面永远显示未勾选(实测:勾了门禁、重开页面又变未勾选)。
346
361
  if (typeof v.pushGate === 'boolean' && !this.editedKeys.has('pushGate')) this.pushGate = v.pushGate;
347
- // defaultScanRoot/commitMessage 不再作为设置键回读(已在 UI/白名单移除)
348
- if (typeof v.weightOverrides === 'string' && v.weightOverrides.trim() && !this.editedKeys.has('weightOverrides')) {
349
- try { this.weightValues = JSON.parse(v.weightOverrides) || {}; } catch { /* 忽略 */ }
350
- }
351
362
  // 凭据布尔位不受编辑守卫影响:只读派生标记,无回弹风险
352
363
  if (typeof v.tokenConfigured === 'boolean') this.tokenConfigured = v.tokenConfigured;
353
364
  if (typeof v.sshConfigured === 'boolean') this.sshConfigured = v.sshConfigured;
354
- this.publish();
355
- } catch (_e) { /* 端点不可用/未注册时沿用 scope 兜底 */ }
356
- }
357
-
358
- /** 加载规则包清单(/rule-slots,动态发现 yml)。 */
359
- // 重构:原 loadCredentialFlags(/status 只刷 tokenConfigured)删除——
360
- // 凭据标志统一由 refreshAccount(/account-check,读凭据文件真源)刷新,避免第三条链路打架。
361
- async loadSlots({ silent = false } = {}) {
362
- if (!silent) { this.slotLoading = true; }
363
- this.slotError = '';
364
- this.publish();
365
- try {
366
- const slotsRes = await dshgp_getJson('/api/git-audit/rule-slots');
367
- if (slotsRes && slotsRes.ok && slotsRes.slots) {
368
- const meta = slotsRes.slots.meta || {};
369
- // 用后端返回的生效顺序;private 恒末尾
370
- const list = Array.isArray(slotsRes.slots.order) ? slotsRes.slots.order : [];
371
- const order = list.filter((s) => s !== 'template');
372
- const forced = Array.isArray(slotsRes.slots.forced) ? slotsRes.slots.forced : [];
373
- this.slotMeta = meta;
374
- this.ruleOrder = order;
375
- if (forced.includes('private') && !this.ruleOrder.includes('private')) this.ruleOrder.push('private');
376
- } else {
377
- this.slotError = (slotsRes && slotsRes.message) || '规则包加载失败';
378
- }
379
- } catch (e) {
380
- this.slotError = '规则包加载失败: ' + (e && e.message || e);
381
365
  }
382
- this.slotLoading = false;
383
- this.publish();
366
+ // 读失败不再被 try/catch 吞掉:状态工厂会把它记成 error 状态,
367
+ // 界面按 uiStatus('settings') 渲染"读取失败(可重试)",而不是照常显示默认值却像"已保存"。
384
368
  }
385
369
 
386
- /** 离线读 npm 账号态(/npm-account,秒级不联网);与 refreshAccount 完全同构。 */
370
+ /**
371
+ * npm 账号态:**薄壳**(读由 UI 状态工厂负责,本方法只保留"重读"语义与加载标记)。
372
+ *
373
+ * 为什么必须薄:此前 npm 与 GitHub 两套各写字段、各吞错误,于是「没读到」与「读到了但为空」
374
+ * 在界面上长得一样(实测:从未请求过 /npm-account,界面却断言「未配置 npm token」)。
375
+ * 现在值只存在状态工厂里,本类的 npm* 字段是它的派生投影(R1)。
376
+ */
387
377
  async refreshNpmAccount({ silent = false } = {}) {
388
- if (!silent) { this.npmAccountLoading = true; }
389
- this.publish();
390
- try {
391
- const res = await dshgp_getJson('/api/git-push/npm-account');
392
- this.npmAccountBlock = (res && res.block) || '(无 npm 账号记录,点「刷新」在线校验)';
393
- this.npmAccountLoggedIn = !!(res && res.loggedIn);
394
- this.npmAccountUser = (res && res.user) || '';
395
- this.npmConfigured = !!(res && res.configured);
396
- } catch (e) {
397
- this.npmAccountBlock = '读取失败: ' + ((e && e.message) || e);
398
- this.npmAccountLoggedIn = false;
399
- this.npmAccountUser = '';
400
- }
378
+ if (!silent) { this.npmAccountLoading = true; this.publish(); }
379
+ const r = await this.uiState.reload('npm');
401
380
  this.npmAccountLoading = false;
402
381
  this.publish();
382
+ return r;
383
+ }
384
+
385
+ /** 把 /npm-account 的返回投影到本类字段(幂等;只读 payload,不做任何默认值编造)。 */
386
+ applyNpmPayload(payload) {
387
+ const p = (payload && typeof payload === 'object') ? payload : null;
388
+ if (!p) return;
389
+ // 后端 block 是"人话结论"(含 ✅/⚠️ 与原因);为空就保持为空 ——
390
+ // 界面按 uiStatus('npm') 分支渲染"读取中/读取失败",绝不把"没读"写成"未配置"。
391
+ this.npmAccountBlock = String(p.block || '');
392
+ this.npmAccountLoggedIn = !!p.loggedIn;
393
+ this.npmAccountUser = String(p.user || '');
394
+ this.npmConfigured = !!p.configured;
403
395
  }
404
396
 
405
397
  /** 在线校验 npm 登录态并写快照(/npm-check);与 recheckAccount 完全同构。 */
@@ -414,7 +406,8 @@
414
406
  this.npmAccountUser = (res && res.user) || '';
415
407
  this.npmConfigured = !!(res && res.configured);
416
408
  } catch (e) {
417
- this.npmAccountBlock = '⏳ 在线校验失败(网络超时或未配置),可稍后重试:' + ((e && e.message) || e);
409
+ // 只报事实:在线校验没成功、原因是什么。不在没证据时断言「未配置」。
410
+ this.npmAccountBlock = '⏳ 在线校验未完成(可稍后重试):' + ((e && e.message) || e);
418
411
  this.npmAccountLoggedIn = false;
419
412
  }
420
413
  this.npmAccountLoading = false;
@@ -563,27 +556,28 @@
563
556
  /** 离线读账号状态(秒级,不触发任何网络):读 account-status.json 快照 + 凭据文件。
564
557
  * 插件启动 / push 后重读 / 账号卡片渲染全用它。「重新检测」才走在线(recheckAccount)。 */
565
558
  async refreshAccount({ silent = false } = {}) {
566
- if (!silent) { this.accountLoading = true; }
567
- this.publish();
568
- try {
569
- const accountRes = await dshgp_getJson('/api/git-push/account-status');
570
- this.accountBlock = (accountRes && accountRes.block) || '(无账号状态记录,点击「重新检测」在线校验)';
571
- this.accountLoggedIn = !!(accountRes && accountRes.loggedIn);
572
- this.tokenConfigured = !!(accountRes && accountRes.tokenConfigured);
573
- this.sshConfigured = !!(accountRes && accountRes.sshConfigured);
574
- this.tokenStatus = (accountRes && accountRes.tokenStatus) || null;
575
- this.sshStatus = (accountRes && accountRes.sshStatus) || null;
576
- this.apiQuota = (accountRes && accountRes.apiQuota) || null;
577
- } catch (e) {
578
- this.accountBlock = '读取失败: ' + (e && e.message || e);
579
- this.accountLoggedIn = false;
580
- }
559
+ if (!silent) { this.accountLoading = true; this.publish(); }
560
+ const r = await this.uiState.reload('account');
581
561
  this.accountLoading = false;
582
562
  this.publish();
583
563
  // token 配额刷新(异步、不阻塞凭据显示):查 /api-quota(后端写回快照)→ 按
584
564
  // statusUpdated 标志重读 account-status,使凭据块 Token 行出现「(配额剩余 N/h)」。
585
- // 查询本身失败不影响凭据展示;落盘失败由 quotaError 记录(不再静默)。
586
- this.refreshApiQuota();
565
+ // 只在账号态读成功时做:失败时连发配额请求只会把错误面搅浑。
566
+ if (r && r.ok) this.refreshApiQuota();
567
+ return r;
568
+ }
569
+
570
+ /** 把 /account-status 的返回投影到本类字段(幂等;失败路径**不调用**它 ⇒ 旧值保留,§四)。 */
571
+ applyAccountPayload(payload) {
572
+ const p = (payload && typeof payload === 'object') ? payload : null;
573
+ if (!p) return;
574
+ this.accountBlock = String(p.block || '');
575
+ this.accountLoggedIn = !!p.loggedIn;
576
+ this.tokenConfigured = !!p.tokenConfigured;
577
+ this.sshConfigured = !!p.sshConfigured;
578
+ this.tokenStatus = p.tokenStatus || null;
579
+ this.sshStatus = p.sshStatus || null;
580
+ if (p.apiQuota) this.apiQuota = p.apiQuota;
587
581
  }
588
582
 
589
583
  // 刷新 token 的 GitHub API 配额(异步):查 /api/git-push/api-quota → 按收口标志重读快照。
@@ -637,36 +631,67 @@
637
631
  * rebuild=true:**离线重建索引**(扫描本地 .git,author 与离线账号 json 一致的登记,
638
632
  * 含本地新增,全程不联网)后再读回;缺省:直接读索引返回(不复扫、不联网)。 */
639
633
  async scanLocalRepos(path, rebuild, { silent = false } = {}) {
640
- if (!silent) { this.localLoading = true; }
641
- this.localMsg = '';
642
- this.publish();
643
- try {
644
- const p = String(path || '').trim();
645
- dshgp_localSet('dshgp-scan-path', p);
646
- const qs = '?rebuild=' + (rebuild ? '1' : '0') + (p ? '&path=' + encodeURIComponent(p) : '');
647
- const localRes = await dshgp_getJson('/api/git-push/repos-local' + qs);
648
- if (localRes && localRes.ok) {
649
- this.localPath = localRes.root || p;
650
- this.localRepos = Array.isArray(localRes.repos) ? localRes.repos : [];
651
- this.localMsg = this.localRepos.length
652
- ? (rebuild ? '已重建索引,读取到 ' : '读取到 ') + this.localRepos.length + ' 个仓库(' + (localRes.root || '') + ')'
653
- : '索引中没有本账号仓库: ' + (localRes.root || '');
654
- } else {
655
- this.localRepos = [];
656
- this.localMsg = '❌ ' + ((localRes && localRes.error) || '读取失败');
657
- }
658
- } catch (e) {
659
- this.localRepos = [];
660
- this.localMsg = '❌ 读取失败: ' + (e && e.message || e);
661
- }
634
+ if (!silent) { this.localLoading = true; this.publish(); }
635
+ const r = await this.uiState.reload('repos', { path: path, rebuild: rebuild === true });
662
636
  this.localLoading = false;
663
637
  this.publish();
638
+ // 列表先出(毫秒级快照),远端状态由后端后台补 —— 这里按 stale 自动重拉一次,
639
+ // 用户不必手动刷新。只在 stale 时排一次,且同一时刻只排一个(防轮询风暴)。
640
+ const payload = (r && r.ok) ? r.value : null;
641
+ if (payload && payload.stale === true) this.scheduleReposReload();
664
642
  // 读取/扫描收尾后**自动补查未知远端状态**——列表里 liveSkipped(本地列表预算/
665
643
  // 熔断导致 SSH 探测跳过)的仓库,串行向后端补查(SSH 真源),结果追加写回索引,
666
644
  // 同时刷新本地列表的远端状态(remoteHead/ahead/behind/remoteHeadAt/synced)。
667
645
  void this.refreshUnknownRemote();
668
646
  }
669
647
 
648
+ /**
649
+ * 远端状态过期时,约一个后台补查周期后再拉一次列表(拿到 ahead/behind/分支)。
650
+ * 只排一次:后端补查是单飞的,前端多排几次只会重复请求同一份快照。
651
+ * @param {number} [delayMs] 延迟(默认 8s:覆盖一次 27 仓后台补查的常见耗时)
652
+ */
653
+ scheduleReposReload(delayMs) {
654
+ if (this._reposReloadTimer) return;
655
+ const wait = Number.isFinite(Number(delayMs)) && Number(delayMs) >= 0 ? Number(delayMs) : 8000;
656
+ this._reposReloadTimer = setTimeout(() => {
657
+ this._reposReloadTimer = null;
658
+ void this.uiState.reload('repos');
659
+ }, wait);
660
+ }
661
+
662
+ /** 读「已装依赖」面板数据(供状态工厂调用;组件不再自己 fetch)。 */
663
+ loadNpmPackagesPayload(arg) {
664
+ const dir = String((arg && arg.dir) || '').trim();
665
+ return dshgp_getJson('/api/git-push/npm-packages' + (dir ? '?dir=' + encodeURIComponent(dir) : ''));
666
+ }
667
+
668
+ /** 读本地仓库列表(供状态工厂调用;不做字段写入,字段由 applyReposPayload 投影)。 */
669
+ loadReposPayload(arg) {
670
+ const a = arg || {};
671
+ const p = String(a.path || '').trim();
672
+ dshgp_localSet('dshgp-scan-path', p);
673
+ const qs = '?rebuild=' + (a.rebuild ? '1' : '0') + (p ? '&path=' + encodeURIComponent(p) : '');
674
+ return dshgp_getJson('/api/git-push/repos-local' + qs);
675
+ }
676
+
677
+ /**
678
+ * 把 /repos-local 的返回投影到本类字段(幂等)。
679
+ * 失败路径**不调用**它 ⇒ 上一次的列表继续显示(§四:失败不清空)。
680
+ * 文案也只描述"读到了什么",不再把失败写成 `❌ 读取失败: …` 塞进同一个字段 ——
681
+ * 失败由 uiStatus('repos') 表达,界面据此渲染可重试的错误条。
682
+ */
683
+ applyReposPayload(payload) {
684
+ const p = (payload && typeof payload === 'object') ? payload : null;
685
+ if (!p) return;
686
+ if (!p.ok) return; // 后端明确失败:保留旧列表,状态位由工厂记 error
687
+ this.localPath = String(p.root || this.localPath || '');
688
+ this.localRepos = Array.isArray(p.repos) ? p.repos : [];
689
+ this.localMsg = this.localRepos.length
690
+ ? (p.stale ? '读取到 ' : '读取到 ') + this.localRepos.length + ' 个仓库(' + (p.root || '') + ')'
691
+ + (p.stale ? ';远端状态同步中…' : '')
692
+ : '索引中没有本账号仓库: ' + (p.root || '');
693
+ }
694
+
670
695
  /** 自动补查 liveSkipped(未知远端状态)仓库:串行走 /repos-local-refresh,更新列表条目。 */
671
696
  async refreshUnknownRemote() {
672
697
  if (this.refreshingRemote) return; // 防重入
@@ -1075,30 +1100,4 @@
1075
1100
  }
1076
1101
  }
1077
1102
 
1078
- /** 单击规则包行:切换禁用/启用(改为写 yml 顶层 disabled,不存 scope 变量)。 */
1079
- async toggleDisabled(slot) {
1080
- if (slot === 'nodejs' || slot === 'private') {
1081
- this.setStatus('⚠️ nodejs/private 安全红线槽位不可禁用');
1082
- return;
1083
- }
1084
- const meta = (this.slotMeta && this.slotMeta[slot]) || {};
1085
- const nowDisabled = !!(meta.disabled);
1086
- // 即时反馈:先本地翻转(行绿/红 + 顶部提示),不等后端响应
1087
- this.slotMeta = { ...(this.slotMeta || {}), [slot]: { ...meta, disabled: !nowDisabled } };
1088
- this.setStatus(!nowDisabled ? '✅ 已禁用 ' + slot + '(该槽位规则不再加载)' : '✅ 已启用 ' + slot);
1089
- this.publish();
1090
- try {
1091
- const toggleRes = await dshgp_postJson('/api/git-audit/toggle-rule', { slot, disabled: !nowDisabled });
1092
- if (toggleRes && toggleRes.ok) {
1093
- void this.loadSlots(); // 后台重载对账(yml 解析结果)
1094
- } else {
1095
- this.setStatus('❌ 切换失败:' + ((toggleRes && toggleRes.error) || '未知错误'));
1096
- this.loadSlots();
1097
- }
1098
- } catch (e) {
1099
- this.setStatus('❌ 切换失败:' + (e && e.message || e));
1100
- void this.loadSlots(); // 恢复 yml 真实状态
1101
- }
1102
- }
1103
-
1104
1103
  /** 审计 tab 顶部即时反馈(区别于设置 tab 的 flashSaved)。 */
@@ -1,4 +1,4 @@
1
- /* ─── 第 4/13 片 · 图标区(ghIcon/refreshIcon) ─────────────────── */
1
+ /* ─── 第 5/14 片 · 图标区(ghIcon/refreshIcon) ─────────────────── */
2
2
  /* ═══════════════════ 选项卡一:账号信息(美化版:渐变卡片 + GitHub 图标 + 状态徽标) ═══════════════════ */
3
3
  const dshgp_ghIcon = jsx.jsx('svg', {
4
4
  width: '22', height: '22', viewBox: '0 0 24 24', fill: 'none',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dsh-git-push v2 设置侧边栏(settings.section 独立页)
3
- * 分片顺序锚点:第 1/13 片(顺序唯一权威 = scripts/build-client.mjs 的 PART_ORDER)
3
+ * 分片顺序锚点:第 1/14 片(顺序唯一权威 = scripts/build-client.mjs 的 PART_ORDER)
4
4
  * ============================================================================
5
5
  * 重写(三选项卡版):
6
6
  * - 纯中文:删 zh/en 键值对字典,用户可见文案直接硬编码中文(产品设计)。