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
package/lib/client.js CHANGED
@@ -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 键值对字典,用户可见文案直接硬编码中文(产品设计)。
@@ -32,7 +32,7 @@ window.__ModuleLoader__.load({
32
32
  const NS = 'git-push';
33
33
  const SETTINGS_NS = 'git-push';
34
34
 
35
- /* ─── 第 2/13 片 · 常量区(NS/维度表/样式串) ─────────────────── */
35
+ /* ─── 第 2/14 片 · 常量区(NS/维度表/样式串) ─────────────────── */
36
36
  // 面板「忙碌中」状态键的前缀(clone / vis / push 三类操作共用**同一出处**)。
37
37
  // 此前这三个字面量散落在组件与类方法里各写一遍,改一处不会同步另一处;
38
38
  // 命名带 dshgp_ 前缀,符合本文件的形态铁律(防 combo 拼接撞名)。
@@ -68,6 +68,29 @@ window.__ModuleLoader__.load({
68
68
  const dshgp_SAVED_MSG_MS = 4000; // 「已保存」提示显示时长
69
69
  const dshgp_LOG_TRUNCATE = 40; // 调试日志 value 截断长度
70
70
 
71
+ /**
72
+ * 设置类字段的默认值 —— **客户端分片内的唯一来源**(§五)。
73
+ *
74
+ * 为什么收在这里:这些值此前在 controller 构造函数里逐行手写(maxCloneFileMB=10、
75
+ * cloneConcurrency=6、pushMethod='ssh'…),而 lib/client/index.js 的 SETTINGS_SCHEMA
76
+ * 里还有一份,两处靠人眼保持一致。改一处漏另一处就会出现「首帧显示 10、读回变 20」
77
+ * 这种谁也说不清的现象。现在 controller 直接 Object.assign 这份,
78
+ * 测试再断言它与 SETTINGS_SCHEMA 逐键一致(两处都要有,缺一即红)。
79
+ */
80
+ const dshgp_DEFAULT_SETTINGS = {
81
+ preCommitEnabled: false, // 提交前预处理开关(默认关)
82
+ injectSystemPrompt: true, // 注入总开关(默认开)
83
+ maxCloneFileMB: 10, // clone 单文件体积上限(MB);0=不限
84
+ cloneConcurrency: 6, // clone 并发下载数
85
+ pushMethod: 'ssh', // 推送通道:ssh | api | auto
86
+ pushGate: false, // 推送门禁(开启后 push 需显式放行)
87
+ // 任务完成自动推送(SETTINGS_SCHEMA 里声明了,首帧也必须给值 ——
88
+ // 否则勾选框/文本框读到 undefined,显示为空而不是默认值)
89
+ autoPushEnabled: false,
90
+ autoPushTriggerText: '✅任务完成',
91
+ autoPushScope: 'session',
92
+ };
93
+
71
94
  const dshgp_css = [
72
95
  // 选项卡条(对齐插件市场)
73
96
  '.dshgp_tabs{display:flex;align-items:flex-end;gap:2px;border-bottom:1px solid var(--dsw-alias-border-l2);margin:0 0 12px}',
@@ -248,9 +271,18 @@ window.__ModuleLoader__.load({
248
271
  '.dshgp_browsedir:hover{background:color-mix(in srgb,var(--dsw-alias-brand-primary) 12%,transparent)}',
249
272
  '.dshgp_browsehint{font-size:12px;color:var(--dsw-alias-label-tertiary);padding:8px}',
250
273
  '.dshgp_browsefoot{display:flex;justify-content:flex-end}',
274
+ // 首屏骨架(R2 门禁等待期)+ 资源状态条(读取中/失败可重试/过期同步中)
275
+ '.dshgp_skel{display:flex;flex-direction:column;gap:10px;padding:4px 2px}',
276
+ '.dshgp_skelblock{border-radius:10px;padding:14px;background:color-mix(in srgb,var(--dsw-alias-label-primary) 6%,transparent)}',
277
+ '.dshgp_skelline{height:10px;border-radius:6px;background:color-mix(in srgb,var(--dsw-alias-label-primary) 13%,transparent);margin:6px 0}',
278
+ '.dshgp_skelline_s{width:38%}',
279
+ '.dshgp_skelline_m{width:62%}',
280
+ '.dshgp_resstatus{font-size:12px;padding:6px 10px;border-radius:8px;margin:6px 0}',
281
+ '.dshgp_resstatus_err{background:color-mix(in srgb,var(--dsw-alias-label-danger,#d33) 12%,transparent);color:var(--dsw-alias-label-primary)}',
282
+ '.dshgp_resstatus_stale{background:color-mix(in srgb,var(--dsw-alias-label-primary) 7%,transparent);color:var(--dsw-alias-label-secondary)}',
251
283
  ].join('');
252
284
 
253
- /* ─── 第 3/13 片 · 工具区(ensureCss/getJson/postJson/tokenConfigured/copyText) ─────────────────── */
285
+ /* ─── 第 3/14 片 · 工具区(ensureCss/getJson/postJson/tokenConfigured/copyText) ─────────────────── */
254
286
  function dshgp_ensureCss() {
255
287
  if (typeof document === 'undefined') return;
256
288
  if (document.querySelector('style[data-plugin-css="dsh-git-push"]')) return;
@@ -312,7 +344,244 @@ window.__ModuleLoader__.load({
312
344
  return Promise.resolve();
313
345
  }
314
346
 
315
- /* ─── 第 4/13 片 · 图标区(ghIcon/refreshIcon) ─────────────────── */
347
+ /* ─── 第 4/14 片 · UI 状态工厂(单一真相源 + 读回早于首帧 + 重建重放) ─────────────────── */
348
+ // 这一层存在的原因:数据读取此前散在各处各写一份状态(controller 字段 + 组件 useState),
349
+ // 于是「没读到」与「读到了但是空」在界面上无法区分(实测:npm 从未被请求,界面却显示
350
+ // 「未配置 npm token」);读取还都是一次性 fire-and-forget,面板重建后既不重读也不重放。
351
+ //
352
+ // 六条契约(对齐 ui-state 参考实现):
353
+ // R1 单一真相源:一个资源只存这里一份;控制器字段是**派生投影**,组件只读投影,禁止各留副本
354
+ // R2 读回早于首次渲染:loadAll() 完成前 UI 只渲染骨架(由 uiReady 门禁),不渲染"像数据的空值"
355
+ // R3 apply/render 分离:renderer 只把当前值刷到已挂载的显示态,幂等、可重放
356
+ // §三 面板重建后:markRebuilt() → 所有 renderer 按当前值重放一次
357
+ // §四 读失败/不支持 ⇒ **保留上次值**并标 stale/error,绝不回落默认值
358
+ // §五 默认值唯一来源 = SETTINGS_SCHEMA / 后端返回;本模块只派生,不另写一份
359
+ const dshgp_UI_DEFAULT_TIMEOUT_MS = 10_000; // 单资源读超时(列表另有预算,由后端保证)
360
+ const dshgp_UI_RETRY_BACKOFF_MS = 800; // 失败重试退避(一次就够:网络抖动可救,真坏不硬耗)
361
+ const dshgp_UI_DEFAULT_RETRY = 1;
362
+
363
+ /**
364
+ * 工厂内部上下文(不对外:调用方只拿 api 对象)。
365
+ * @param {Function} onChange 任一资源状态/值变化时回调(用于 publish)
366
+ * @returns {{onChange: Function, resources: Map, renderers: Map, inflight: Map}}
367
+ */
368
+ function dshgp_uiCtx(onChange) {
369
+ return {
370
+ onChange: onChange || function () {},
371
+ resources: new Map(), // name → {load, timeoutMs, retry, staleAfterMs, value, at, state, error}
372
+ renderers: new Map(), // name → 幂等渲染函数
373
+ inflight: new Map(), // name → 进行中的 Promise(单飞)
374
+ };
375
+ }
376
+
377
+ /** 取资源声明;未注册立即抛(拼错的资源名必须当场可见,不能静默无数据)。 */
378
+ function dshgp_uiEnsure(ctx, name) {
379
+ const res = ctx.resources.get(String(name));
380
+ if (!res) throw new Error('未注册的 UI 资源:' + name);
381
+ return res;
382
+ }
383
+
384
+ /** 通知订阅者(订阅者异常不得打断状态机)。 */
385
+ function dshgp_uiEmit(ctx) {
386
+ try { ctx.onChange(); } catch (e) { /* 订阅者异常忽略 */ }
387
+ }
388
+
389
+ /**
390
+ * 某资源的状态快照。界面**必须按 state 分支渲染**,不能只看 value 真假:
391
+ * idle/loading ⇒ 还没读到(渲染占位,别说"未配置")
392
+ * ready ⇒ 有值且新鲜
393
+ * stale ⇒ 有值但过期(照常显示 + 标"同步中")
394
+ * error ⇒ 读失败;value 可能是上一次成功值(§四:不清空)
395
+ */
396
+ function dshgp_uiStatusOf(ctx, name) {
397
+ const r = ctx.resources.get(String(name));
398
+ if (!r) return { state: 'idle', loading: false, error: '', at: 0, hasValue: false };
399
+ let state = r.state;
400
+ if (state === 'ready' && r.staleAfterMs > 0 && r.at && (Date.now() - r.at) > r.staleAfterMs) state = 'stale';
401
+ return { state: state, loading: state === 'loading', error: r.error, at: r.at, hasValue: r.value !== undefined };
402
+ }
403
+
404
+ /** 把某个资源的当前值刷到显示态(R3;渲染异常不影响状态位)。 */
405
+ function dshgp_uiRenderOne(ctx, name, payload) {
406
+ const fn = ctx.renderers.get(String(name));
407
+ if (!fn) return false;
408
+ try { fn(payload); return true; } catch (e) { return false; }
409
+ }
410
+
411
+ /**
412
+ * 按当前值重放渲染(R3/§三),幂等。面板重建后反复调是安全的。
413
+ * @returns {{rendered: string[], skipped: string[]}}
414
+ */
415
+ function dshgp_uiApplyAll(ctx, names) {
416
+ const only = Array.isArray(names) ? new Set(names.map(String)) : null;
417
+ const rendered = [];
418
+ const skipped = [];
419
+ for (const [name, r] of ctx.resources) {
420
+ if (only && !only.has(name)) continue;
421
+ if (r.value === undefined || !ctx.renderers.has(name)) { skipped.push(name); continue; }
422
+ if (dshgp_uiRenderOne(ctx, name, r.value)) rendered.push(name); else skipped.push(name);
423
+ }
424
+ return { rendered: rendered, skipped: skipped };
425
+ }
426
+
427
+ /** 带超时的单次读取(超时用 Promise.race,不依赖 fetch 自身的 signal 语义)。 */
428
+ function dshgp_uiReadOnce(resource, arg) {
429
+ return Promise.race([
430
+ Promise.resolve(resource.load(arg)),
431
+ new Promise((_, reject) => setTimeout(
432
+ () => reject(new Error('超时(>' + resource.timeoutMs + 'ms)')), resource.timeoutMs,
433
+ )),
434
+ ]);
435
+ }
436
+
437
+ /**
438
+ * 读一个资源(含一次退避重试)。失败**保留旧值**,只改状态位(§四)。
439
+ * @returns {Promise<{ok: boolean, name: string, value?: unknown, error?: string}>}
440
+ */
441
+ async function dshgp_uiLoadOne(ctx, name, arg, attempt) {
442
+ const r = dshgp_uiEnsure(ctx, name);
443
+ const tries = Number.isFinite(attempt) ? attempt : 0;
444
+ r.state = 'loading';
445
+ r.error = '';
446
+ dshgp_uiEmit(ctx);
447
+ try {
448
+ const payload = await dshgp_uiReadOnce(r, arg);
449
+ r.value = payload;
450
+ r.at = Date.now();
451
+ r.state = 'ready';
452
+ r.error = '';
453
+ dshgp_uiRenderOne(ctx, name, payload); // 读到就立刻刷一次显示(与重放同一条路径)
454
+ dshgp_uiEmit(ctx);
455
+ return { ok: true, name: String(name), value: payload };
456
+ } catch (e) {
457
+ const msg = String((e && e.message) || e);
458
+ if (tries < r.retry) {
459
+ await new Promise((resolve) => setTimeout(resolve, dshgp_UI_RETRY_BACKOFF_MS));
460
+ ctx.inflight.delete(String(name));
461
+ return dshgp_uiLoadOne(ctx, name, arg, tries + 1);
462
+ }
463
+ // §四:不清空 value —— 有上一次成功值就继续显示,仅状态降级
464
+ r.state = 'error';
465
+ r.error = msg;
466
+ dshgp_uiEmit(ctx);
467
+ return { ok: false, name: String(name), error: msg };
468
+ } finally {
469
+ ctx.inflight.delete(String(name));
470
+ }
471
+ }
472
+
473
+ /** 单飞重读:进行中则复用同一个 Promise(防切 tab/多组件同时触发造成请求风暴)。 */
474
+ function dshgp_uiReload(ctx, name, arg) {
475
+ const key = String(name);
476
+ if (ctx.inflight.has(key)) return ctx.inflight.get(key);
477
+ const p = dshgp_uiLoadOne(ctx, key, arg).finally(() => { ctx.inflight.delete(key); });
478
+ ctx.inflight.set(key, p);
479
+ return p;
480
+ }
481
+
482
+ /**
483
+ * 并发读多个资源(R2 的落点:调用方在首帧前等它读完,再放开渲染门禁)。
484
+ * @returns {Promise<{ok: boolean, failed: string[], loaded: string[]}>}
485
+ */
486
+ async function dshgp_uiLoadAll(ctx, opts) {
487
+ const o = opts || {};
488
+ const names = Array.isArray(o.names) ? o.names.map(String) : [...ctx.resources.keys()];
489
+ const results = await Promise.all(names.map((name) => {
490
+ const r = ctx.resources.get(name);
491
+ if (!r) return Promise.resolve({ ok: false, name: name, error: '未注册' });
492
+ if (!o.force && r.state === 'ready' && r.value !== undefined) return Promise.resolve({ ok: true, name: name, cached: true });
493
+ return dshgp_uiReload(ctx, name);
494
+ }));
495
+ return {
496
+ ok: results.every((x) => x.ok),
497
+ failed: results.filter((x) => !x.ok).map((x) => x.name),
498
+ loaded: results.filter((x) => x.ok).map((x) => x.name),
499
+ };
500
+ }
501
+
502
+ /**
503
+ * 按需补读(面板挂载/切 tab 用):只读「没读过」或「已过期/上次失败」的资源。
504
+ * 幂等且不制造请求风暴 —— 这正是"切 tab 就重挂载"场景需要的语义。
505
+ */
506
+ function dshgp_uiEnsureFresh(ctx, names) {
507
+ const list = Array.isArray(names) ? names.map(String) : [String(names)];
508
+ const todo = list.filter((name) => {
509
+ const r = ctx.resources.get(name);
510
+ if (!r) return false;
511
+ if (r.state === 'ready' && r.value !== undefined) return false; // 有新鲜值:不读
512
+ return !ctx.inflight.has(name);
513
+ });
514
+ if (!todo.length) return Promise.resolve({ ok: true, failed: [], loaded: [] });
515
+ return dshgp_uiLoadAll(ctx, { names: todo, force: true });
516
+ }
517
+
518
+ /** 是否所有指定资源都已"有值可用"(ready/stale/error 但留有旧值都算)。 */
519
+ function dshgp_uiAllReady(ctx, names) {
520
+ const list = Array.isArray(names) ? names.map(String) : [...ctx.resources.keys()];
521
+ return list.every((name) => {
522
+ const r = ctx.resources.get(name);
523
+ return !!r && r.value !== undefined;
524
+ });
525
+ }
526
+
527
+ /** 是否还有资源在首次读取中(骨架期判断)。 */
528
+ function dshgp_uiAnyLoading(ctx) {
529
+ for (const r of ctx.resources.values()) if (r.state === 'loading') return true;
530
+ return false;
531
+ }
532
+
533
+ /**
534
+ * 建一个 UI 状态仓库(对外唯一入口)。
535
+ *
536
+ * 用法(装配期注册资源,运行期读):
537
+ * const ui = dshgp_createUiState({ onChange: () => this.publish() });
538
+ * ui.register('npm', { load: () => dshgp_getJson('/api/git-push/npm-account') });
539
+ * ui.setRenderer('npm', (payload) => this.applyNpmPayload(payload));
540
+ * await ui.loadAll(); // R2:读完再放开首帧
541
+ * ui.markRebuilt(); // §三:面板重建后重放
542
+ *
543
+ * @param {{onChange?: Function}} [options] onChange:任一资源状态/值变化时回调(用于 publish)
544
+ * @returns {object} 仓库实例
545
+ */
546
+ function dshgp_createUiState(options) {
547
+ const ctx = dshgp_uiCtx(options && options.onChange);
548
+ const api = {
549
+ register: function (name, spec) {
550
+ if (typeof (spec && spec.load) !== 'function') throw new Error('资源 ' + name + ' 缺少 load()');
551
+ ctx.resources.set(String(name), {
552
+ name: String(name),
553
+ load: spec.load,
554
+ timeoutMs: Number(spec.timeoutMs) > 0 ? Number(spec.timeoutMs) : dshgp_UI_DEFAULT_TIMEOUT_MS,
555
+ retry: Number.isFinite(Number(spec.retry)) ? Number(spec.retry) : dshgp_UI_DEFAULT_RETRY,
556
+ staleAfterMs: Number(spec.staleAfterMs) > 0 ? Number(spec.staleAfterMs) : 0,
557
+ value: undefined,
558
+ at: 0,
559
+ state: 'idle',
560
+ error: '',
561
+ });
562
+ return api;
563
+ },
564
+ setRenderer: function (name, render) {
565
+ if (typeof render !== 'function') throw new Error('renderer 必须是函数:' + name);
566
+ ctx.renderers.set(String(name), render);
567
+ return api;
568
+ },
569
+ value: function (name) { return ctx.resources.has(String(name)) ? ctx.resources.get(String(name)).value : undefined; },
570
+ values: function () { const out = {}; for (const [k, r] of ctx.resources) out[k] = r.value; return out; },
571
+ status: function (name) { return dshgp_uiStatusOf(ctx, name); },
572
+ reload: function (name, arg) { return dshgp_uiReload(ctx, name, arg); },
573
+ loadAll: function (opts) { return dshgp_uiLoadAll(ctx, opts); },
574
+ ensureFresh: function (names) { return dshgp_uiEnsureFresh(ctx, names); },
575
+ applyAll: function (opts) { return dshgp_uiApplyAll(ctx, opts && opts.names); },
576
+ // §三:面板重建完成 ⇒ 按当前值重放全部显示态(不触发任何请求)
577
+ markRebuilt: function () { const r = dshgp_uiApplyAll(ctx, null); dshgp_uiEmit(ctx); return r; },
578
+ allReady: function (names) { return dshgp_uiAllReady(ctx, names); },
579
+ anyLoading: function () { return dshgp_uiAnyLoading(ctx); },
580
+ has: function (name) { return ctx.resources.has(String(name)); },
581
+ };
582
+ return api;
583
+ }
584
+ /* ─── 第 5/14 片 · 图标区(ghIcon/refreshIcon) ─────────────────── */
316
585
  /* ═══════════════════ 选项卡一:账号信息(美化版:渐变卡片 + GitHub 图标 + 状态徽标) ═══════════════════ */
317
586
  const dshgp_ghIcon = jsx.jsx('svg', {
318
587
  width: '22', height: '22', viewBox: '0 0 24 24', fill: 'none',
@@ -324,7 +593,7 @@ window.__ModuleLoader__.load({
324
593
  stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round',
325
594
  children: jsx.jsx('path', { d: 'M21 12a9 9 0 1 1-2.64-6.36M21 3v6h-6' }),
326
595
  });
327
- /* ─── 第 5/13 片 · 账号信息 Tab(AcctHead/AccountCard/AccountTab) ─────────────────── */
596
+ /* ─── 第 6/14 片 · 账号信息 Tab(AcctHead/AccountCard/AccountTab) ─────────────────── */
328
597
  /** 账号卡片头部:GitHub 图标 + 标题 + 状态徽标。 */
329
598
  function dshgp_AcctHead(props) {
330
599
  return jsx.jsxs('div', {
@@ -346,13 +615,19 @@ window.__ModuleLoader__.load({
346
615
  function dshgp_AccountCard(props) {
347
616
  const s = props.state;
348
617
  const loggedIn = !!s.accountLoggedIn;
349
- const loading = !!s.accountLoading;
350
- const statCls = loggedIn ? 'dshgp_acctstat_ok' : (loading ? 'dshgp_acctstat_warn' : 'dshgp_acctstat_err');
351
- const statTxt = loggedIn ? '已连接' : (loading ? '检测中' : '未连接');
352
- const blockCls = loggedIn ? 'dshgp_acctblock2_ok' : (loading ? 'dshgp_acctblock2_loading' : 'dshgp_acctblock2_err');
618
+ // 「还没读 / 读失败」必须与「读到了、确实没配」分开:前者不能渲染成确定性的否定结论
619
+ const info = (s.uiStatus && s.uiStatus.account) || { state: 'idle', error: '' };
620
+ const unread = info.state === 'idle' || info.state === 'loading';
621
+ const errored = info.state === 'error';
622
+ const loading = !!s.accountLoading || unread;
623
+ const statCls = errored ? 'dshgp_acctstat_warn' : (loggedIn ? 'dshgp_acctstat_ok' : (loading ? 'dshgp_acctstat_warn' : 'dshgp_acctstat_err'));
624
+ const statTxt = errored ? '读取失败' : (loading ? '检测中' : (loggedIn ? '已连接' : '未连接'));
625
+ const blockCls = loggedIn ? 'dshgp_acctblock2_ok' : (loading || errored ? 'dshgp_acctblock2_loading' : 'dshgp_acctblock2_err');
353
626
  const blockBody = s.accountBlock
354
627
  ? s.accountBlock
355
- : (loading ? '正在检测 Token / SSH 公钥…' : '未配置 Token / SSH 公钥——请到「设置」选项卡填写凭据');
628
+ : (unread ? '正在读取账号状态…'
629
+ : (errored ? '账号状态读取失败(可点下方「重试」)'
630
+ : '未配置 Token / SSH 公钥——请到「设置」选项卡填写凭据'));
356
631
  // 两条凭据各自独立——Token 与 SSH 可以是**不同 GitHub 用户**;明细(用户名/校验时间/
357
632
  // 配额)统一由凭据块(block,后端生成)逐行给出,页面不再另列重复的分项行。
358
633
  // 两凭据属不同用户时如实提示:推送实际走 SSH 通道
@@ -362,6 +637,11 @@ window.__ModuleLoader__.load({
362
637
  className: 'dshgp_acctpanel',
363
638
  children: [
364
639
  jsx.jsx(dshgp_AcctHead, { statCls, statTxt }),
640
+ jsx.jsx(dshgp_ResourceNotice, {
641
+ info: info,
642
+ what: '账号状态',
643
+ onRetry: errored && props.retryResource ? () => props.retryResource('account') : null,
644
+ }),
365
645
  jsx.jsx('pre', { className: 'dshgp_acctblock2 ' + blockCls, children: blockBody }),
366
646
  // Token / SSH 公钥的登录名与校验时间已在**凭据块内**逐行给出(Token 那行还带 API 配额后缀),
367
647
  // 此处不再另列一遍分项行——同一份登录信息展示两遍正是之前的重复问题。
@@ -391,12 +671,10 @@ window.__ModuleLoader__.load({
391
671
 
392
672
  /** 选项卡一:账号信息(拆卡片:渐变面板 AccountCard + 本地/云端 RepoManagerCard)。 */
393
673
  function dshgp_AccountTab(props) {
394
- // 账号信息/本地仓库列表的读取时机已收敛到三种(不再每次切 tab 重读):
395
- // ①插件启动时(apply 里一次性读:refreshAccount + scanLocalRepos)
396
- // ②云端 push 完成时(pushLocalRepo 成功后顺延重读)
397
- // ③本地仓库手动「扫描」完成索引重建后(扫描按钮 rebuild=true 自带重读)
398
- // 因此这里**不再**挂载时刷新——条件渲染(tab==='account')每次切回都重挂载,
399
- // 若在此触发会「一直刷新」;读取全部改由 Controller 层显式调用。
674
+ // §三:条件渲染(tab==='account')每切回都重挂载 ⇒ 挂载即视为「面板重建」:
675
+ // 补读没读过/已过期的资源(幂等,不产生重复请求)+ 按当前值重放显示态。
676
+ // 这样「切 tab 回来看到空数据」不再需要用户手动点刷新。
677
+ react.useEffect(() => { if (props.panelRebuilt) props.panelRebuilt(); }, []);
400
678
  return jsx.jsxs('div', {
401
679
  className: 'dshgp_section',
402
680
  children: [
@@ -407,7 +685,7 @@ window.__ModuleLoader__.load({
407
685
  });
408
686
  }
409
687
 
410
- /* ─── 第 6/13 片 · 目录选择器(browseEnsureDom/browseLoad/browseOpen/browseClose/browseAttach) ─────────────────── */
688
+ /* ─── 第 7/14 片 · 目录选择器(browseEnsureDom/browseLoad/browseOpen/browseClose/browseAttach) ─────────────────── */
411
689
  let dshgp_browseTarget = null; // 当前打开的输入框(null = 走 onPick 回调)
412
690
  // 移植 gamebanana-mods-downloader 的 path-picker 小模块:一行接入 📂 按钮 // 当前打开的输入框(null = 走 onPick 回调)
413
691
  let dshgp_browseOpt = null; // { onPick } 确认回调(clone 场景)
@@ -513,7 +791,7 @@ window.__ModuleLoader__.load({
513
791
  }
514
792
 
515
793
  /* ═══════════════════ 账号卡片:本地/云端 仓库管理 ═══════════════════ */
516
- /* ─── 第 7/13 片 · 仓库管理卡(RepoManagerCard/RepoLocalPane/RepoCloudPane) ─────────────────── */
794
+ /* ─── 第 8/14 片 · 仓库管理卡(RepoManagerCard/RepoLocalPane/RepoCloudPane) ─────────────────── */
517
795
  function dshgp_RepoManagerCard(props) {
518
796
  const s = props.state;
519
797
  const [view, setView] = react.useState('local');
@@ -664,6 +942,13 @@ window.__ModuleLoader__.load({
664
942
  }),
665
943
  ],
666
944
  }),
945
+ // 列表读取的「状态」单独表达(读取中/失败可重试/过期同步中):
946
+ // 旧实现把失败文案塞进 localMsg,还顺手把列表清空 —— 于是"读失败"看起来像"你没有仓库"。
947
+ jsx.jsx(dshgp_ResourceNotice, {
948
+ info: (s.uiStatus && s.uiStatus.repos) || { state: 'idle', error: '' },
949
+ what: '本地仓库列表',
950
+ onRetry: props.retryResource ? () => props.retryResource('repos') : null,
951
+ }),
667
952
  jsx.jsx('p', { className: 'dshgp_repomsg', children: s.localMsg || '扫描目录下的 git 仓库;仓库「领先远端(有未推送提交)」时可手动 push(工作树未提交改动不影响 push,推的是已提交内容)' }),
668
953
  rows.length ? jsx.jsxs('div', { className: 'dshgp_replist', children: rows }) : null,
669
954
  ],
@@ -888,7 +1173,7 @@ window.__ModuleLoader__.load({
888
1173
  }
889
1174
 
890
1175
  // dsh-skip-func-length: NPM 子页为自包含组件(自有 useState/useEffect,不依赖 controller),拆分会改动 hook 顺序与状态归属,风险高于收益
891
- /* ─── 第 8/13 片 · NPM 面板(账号卡 + 装包表单 + 已装列表 + npm 凭据字段) ───────────────────
1176
+ /* ─── 第 9/14 片 · NPM 面板(账号卡 + 装包表单 + 已装列表 + npm 凭据字段) ───────────────────
892
1177
  * 设计取舍:完全自包含(自己 useState/useEffect + 直接走 HTTP),不碰 40-controller(884 行)与 41-actions,
893
1178
  * 把 Step 4 的改动面压到最小;数据源:/npm-account、/npm-packages、/npm-install、/settings-set、/status。
894
1179
  * 安全默认与后端一致:`ignore-scripts` 默认勾选(不执行 postinstall)、默认非全局、**安装需二次确认**。
@@ -898,20 +1183,27 @@ window.__ModuleLoader__.load({
898
1183
  /** npm 账号卡(与 GitHub 账号卡**同款**:渐变面板 + 图标块 + 状态徽标 + 勾选明细块 + 底部操作)。 */
899
1184
  function dshgp_NpmAccountCard(props) {
900
1185
  const a = props.acct || {};
901
- const busy = !!props.busy;
1186
+ // 「还没读 / 读失败」与「读到了、确实没配」必须分开:
1187
+ // 旧实现用 configured=false 覆盖了前两种情况,于是从未加载也会断言「未配置 npm token」(假话)。
1188
+ const info = props.info || { state: 'idle', error: '' };
1189
+ const unread = info.state === 'idle' || info.state === 'loading';
1190
+ const errored = info.state === 'error';
1191
+ const busy = !!props.busy || unread;
902
1192
  const okState = !!(a.configured && a.loggedIn);
903
- // 三态与 GitHub 卡同规格:已连接(ok)/ 读取中或凭据未过校验(warn)/ 未配置(err)
904
- const statCls = okState ? 'dshgp_acctstat_ok' : (busy || a.configured ? 'dshgp_acctstat_warn' : 'dshgp_acctstat_err');
905
- const statTxt = okState ? '已连接' : (busy ? '读取中' : (a.configured ? '校验未过' : '未配置'));
906
- const blockCls = okState ? 'dshgp_acctblock2_ok' : (busy ? 'dshgp_acctblock2_loading' : 'dshgp_acctblock2_err');
907
- // 明细逐行给出(成功 ✅ / 缺配置或失败 ⚠️),与 GitHub 卡那几行 ✅ 同一形态
908
- const blockBody = busy
1193
+ const statCls = okState ? 'dshgp_acctstat_ok'
1194
+ : (unread || errored || a.configured ? 'dshgp_acctstat_warn' : 'dshgp_acctstat_err');
1195
+ const statTxt = okState ? '已连接'
1196
+ : (unread ? '读取中' : (errored ? '读取失败' : (a.configured ? '校验未过' : '未配置')));
1197
+ const blockCls = okState ? 'dshgp_acctblock2_ok' : (unread || errored ? 'dshgp_acctblock2_loading' : 'dshgp_acctblock2_err');
1198
+ const blockBody = unread
909
1199
  ? '正在读取 npm 登录态…'
910
- : (okState
911
- ? `✅ 凭据可用\n✅ npm token:${a.user}|registry ${a.registry || ''}\n✅ 登录态:npm whoami 通过${a.maskedToken ? `(${a.maskedToken})` : ''}`
912
- : (a.configured
913
- ? `⚠️ npm token 已配置但校验未通过\n⚠️ registry:${a.registry || ''}\n⚠️ 原因:${a.error || '未知'}`
914
- : `⚠️ 未配置 npm token\n⚠️ registry:${a.registry || ''}\n⚠️ 到「设置 → 凭据与密钥」填写 npm token 后可显示登录态`));
1200
+ : (errored
1201
+ ? 'npm 登录态读取失败(可点下方「刷新」重试;上方提示条有失败原因)'
1202
+ : (okState
1203
+ ? `✅ 凭据可用\n✅ npm token:${a.user}|registry ${a.registry || ''}\n✅ 登录态:npm whoami 通过${a.maskedToken ? `(${a.maskedToken})` : ''}`
1204
+ : (a.configured
1205
+ ? `⚠️ npm token 已配置但校验未通过\n⚠️ registry:${a.registry || ''}\n⚠️ 原因:${a.error || '未知'}`
1206
+ : `⚠️ 未配置 npm token\n⚠️ registry:${a.registry || ''}\n⚠️ 到「设置 → 凭据与密钥」填写 npm token 后可显示登录态`)));
915
1207
  return jsx.jsxs('div', {
916
1208
  className: 'dshgp_acctpanel',
917
1209
  children: [
@@ -932,6 +1224,11 @@ window.__ModuleLoader__.load({
932
1224
  jsx.jsxs('span', { className: 'dshgp_acctstat ' + statCls, children: [jsx.jsx('span', { className: 'dshgp_acctdot' }), statTxt] }),
933
1225
  ],
934
1226
  }),
1227
+ jsx.jsx(dshgp_ResourceNotice, {
1228
+ info: info,
1229
+ what: 'npm 账号状态',
1230
+ onRetry: errored && props.onRetry ? props.onRetry : null,
1231
+ }),
935
1232
  jsx.jsx('pre', { className: 'dshgp_acctblock2 ' + blockCls, children: blockBody }),
936
1233
  jsx.jsxs('div', {
937
1234
  className: 'dshgp_acctfoot',
@@ -1016,8 +1313,10 @@ window.__ModuleLoader__.load({
1016
1313
  /** NPM 子页:登录账号名下的包列表(与 GitHub 云端仓库列表**同款行**)+ 手动安装框。 */
1017
1314
  function dshgp_NpmPanel(props) {
1018
1315
  const s = (props && props.state) || {};
1019
- const [acct, setAcct] = react.useState(null);
1020
- const [pkgs, setPkgs] = react.useState(null);
1316
+ // 数据(账号态 / 已装依赖)一律取自状态工厂(R1:组件不留显示副本);
1317
+ // 这里只保留**纯表单交互状态**(输入框内容、勾选、忙碌标记)。
1318
+ const pkgs = s.npmPackages || null;
1319
+ const pkgsStatus = (s.uiStatus && s.uiStatus.npmPackages) || { state: 'idle', error: '' };
1021
1320
  const [dir, setDir] = react.useState('');
1022
1321
  const [names, setNames] = react.useState('');
1023
1322
  const [global, setGlobal] = react.useState(false);
@@ -1027,24 +1326,17 @@ window.__ModuleLoader__.load({
1027
1326
  const [result, setResult] = react.useState(null);
1028
1327
  const [err, setErr] = react.useState('');
1029
1328
 
1030
- /** 读账号态 + 已装依赖;d 为空时沿用当前目录(服务端默认工作区)。 */
1329
+ /** 读「已装依赖」:交给状态工厂(单飞、有状态、失败不清空),组件只负责触发。 */
1031
1330
  const load = react.useCallback(async (d) => {
1032
1331
  setBusy(true);
1033
- try {
1034
- const a = await dshgp_getJson('/api/git-push/npm-account');
1035
- const p = await dshgp_getJson('/api/git-push/npm-packages' + (d ? '?dir=' + encodeURIComponent(d) : ''));
1036
- setAcct(a || null);
1037
- setPkgs(p || null);
1038
- if (p && p.dir) setDir(p.dir);
1039
- setErr('');
1040
- } catch (e) {
1041
- setErr(String((e && e.message) || e));
1042
- } finally {
1043
- setBusy(false);
1044
- }
1332
+ if (props.reloadNpmPackages) props.reloadNpmPackages(d || '');
1333
+ setBusy(false);
1334
+ }, [props]);
1335
+ // 挂载时按需补读(已读过则不重复请求 —— ensureFresh 的语义就在这里)
1336
+ react.useEffect(() => {
1337
+ if (props.panelRebuilt) props.panelRebuilt();
1338
+ if (props.reloadNpmPackages) props.reloadNpmPackages('');
1045
1339
  }, []);
1046
- // 只在挂载时读一次(与既有 tab 的读取时机约定一致:不在每次切 tab 时重复触发)
1047
- react.useEffect(() => { load(''); }, [load]);
1048
1340
 
1049
1341
  const doInstall = async () => {
1050
1342
  setBusy(true);
@@ -1064,6 +1356,11 @@ window.__ModuleLoader__.load({
1064
1356
  }
1065
1357
  };
1066
1358
 
1359
+ // 服务端返回的目录回填到输入框(数据来自工厂,避免组件自己记一份)
1360
+ react.useEffect(() => {
1361
+ if (pkgs && pkgs.dir && !dir) setDir(pkgs.dir);
1362
+ }, [pkgs]);
1363
+
1067
1364
  const st = {
1068
1365
  names, setNames, dir, setDir, global, setGlobal, ignoreScripts, setIgnoreScripts,
1069
1366
  confirming, setConfirming, busy, result, doInstall,
@@ -1072,10 +1369,8 @@ window.__ModuleLoader__.load({
1072
1369
  return jsx.jsxs('div', {
1073
1370
  className: 'dshgp_section',
1074
1371
  children: [
1075
- // 账号卡已上移到顶部账号区(与 GitHub 卡**同位置、滑动切换**)⇒ 这里不再重复渲染
1076
- // 说明:原先自创的「安装包」表单(包名输入 + 目录输入 + 两个复选框)已**停用**——
1077
- // 改为照 GitHub 的四段交互:行内「安装」→ 选择目录 / 全局安装 → 进度轮询 → 回执。
1078
- // 组件 dshgp_NpmInstallForm 的源码暂留备查,不再渲染(comment-not-delete:只停用不删代码)。
1372
+ // 账号卡在顶部账号区(与 GitHub 卡同位置、滑动切换),这里只列已装依赖;
1373
+ // 安装交互走 GitHub 同款四段:行内「安装」→ 选目录/全局 → 进度轮询 → 回执。
1079
1374
  jsx.jsxs('div', {
1080
1375
  className: 'dshgp_block',
1081
1376
  children: [
@@ -1083,7 +1378,10 @@ window.__ModuleLoader__.load({
1083
1378
  pkgs && pkgs.hasPackageJson === false
1084
1379
  ? jsx.jsx('p', { className: 'dshgp_hint', children: '该目录没有 package.json —— 安装会在目录下新建依赖树(建议先初始化)。' })
1085
1380
  : null,
1086
- jsx.jsx('p', { className: 'dshgp_hint', children: 'node_modules:' + (pkgs && pkgs.nodeModules ? '已存在' : '不存在') + ' · 依赖 ' + deps.length + ' 个' }),
1381
+ jsx.jsx(dshgp_ResourceNotice, { info: pkgsStatus, what: '已装依赖' }),
1382
+ jsx.jsx('p', { className: 'dshgp_hint', children: pkgs
1383
+ ? 'node_modules:' + (pkgs.nodeModules ? '已存在' : '不存在') + ' · 依赖 ' + deps.length + ' 个'
1384
+ : '依赖清单读取中…' }),
1087
1385
  deps.length
1088
1386
  ? jsx.jsx('div', { className: 'dshgp_field', children: deps.map((d) => jsx.jsx('div', { key: d.name, className: 'dshgp_hint', children: d.name + ' ' + d.range })) })
1089
1387
  : jsx.jsx('p', { className: 'dshgp_hint', children: '(无已装依赖)' }),
@@ -1095,7 +1393,8 @@ window.__ModuleLoader__.load({
1095
1393
  jsx.jsxs('div', {
1096
1394
  style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px', marginBottom: '8px' },
1097
1395
  children: [
1098
- jsx.jsx('p', { className: 'dshgp_h2', style: { margin: 0 }, children: '我的包(' + (s.npmAccountUser || '未登录') + ')' }),
1396
+ jsx.jsx('p', { className: 'dshgp_h2', style: { margin: 0 }, children: '我的包(' + (s.npmAccountUser
1397
+ || ((s.uiStatus && s.uiStatus.npm && ['idle', 'loading'].includes(s.uiStatus.npm.state)) ? '读取中…' : '未登录')) + ')' }),
1099
1398
  jsx.jsx('button', { type: 'button', className: 'dshgp_keybtn', disabled: !!s.npmOwnedLoading, onClick: () => props.refreshNpmOwned(), children: s.npmOwnedLoading ? '读取中…' : '刷新列表' }),
1100
1399
  ],
1101
1400
  }),
@@ -1194,6 +1493,7 @@ window.__ModuleLoader__.load({
1194
1493
  block,
1195
1494
  error: '',
1196
1495
  };
1496
+ const npmInfo = (s.uiStatus && s.uiStatus.npm) || { state: 'idle', error: '' };
1197
1497
  return jsx.jsxs('div', {
1198
1498
  children: [
1199
1499
  jsx.jsx('div', {
@@ -1212,7 +1512,11 @@ window.__ModuleLoader__.load({
1212
1512
  children: [
1213
1513
  which === 'github'
1214
1514
  ? jsx.jsx(dshgp_AccountCard, props)
1215
- : jsx.jsx(dshgp_NpmAccountCard, { acct: npmAcct, busy: !!s.npmAccountLoading, onRefresh: props.recheckNpmAccount }),
1515
+ : jsx.jsx(dshgp_NpmAccountCard, {
1516
+ acct: npmAcct, busy: !!s.npmAccountLoading, info: npmInfo,
1517
+ onRefresh: props.recheckNpmAccount,
1518
+ onRetry: () => { if (props.retryResource) props.retryResource('npm'); },
1519
+ }),
1216
1520
  ],
1217
1521
  }),
1218
1522
  ],
@@ -1271,7 +1575,7 @@ window.__ModuleLoader__.load({
1271
1575
  });
1272
1576
  }
1273
1577
 
1274
- /* ─── 第 9/13 片 · 设置 Tab(SettingsTab) ─────────────────── */
1578
+ /* ─── 第 10/14 片 · 设置 Tab(SettingsTab) ─────────────────── */
1275
1579
  function dshgp_CredentialBlock(props) {
1276
1580
  const s = props.state;
1277
1581
  return jsx.jsxs('div', {
@@ -1348,6 +1652,16 @@ window.__ModuleLoader__.load({
1348
1652
  className: 'dshgp_block',
1349
1653
  children: [
1350
1654
  jsx.jsx('p', { className: 'dshgp_h2', children: '推送与默认值' }),
1655
+ // 提交前预处理总开关:本插件唯一的门禁开关。
1656
+ // 具体审什么(扫描范围/权重/规则包)归预处理实现自己的配置,这里不放那些项。
1657
+ jsx.jsxs('div', { className: 'dshgp_field', children: [
1658
+ jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-precommit', children: '提交前预处理' }),
1659
+ jsx.jsx('input', {
1660
+ id: 'dshgp-precommit', type: 'checkbox', className: 'dshgp_check',
1661
+ checked: !!s.preCommitEnabled, onChange: (ev) => props.setAdvanced('preCommitEnabled', ev.target.checked),
1662
+ }),
1663
+ jsx.jsx('p', { className: 'dshgp_hint', children: '开启后提交前调用预处理实现做检查(默认关)。检查范围、规则包与权重属于预处理实现自己的配置,在本页不做设置。' }),
1664
+ ] }),
1351
1665
  jsx.jsxs('div', { className: 'dshgp_field', children: [
1352
1666
  jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-pushmethod', children: '推送通道' }),
1353
1667
  // 下拉标签带括号注释(选项 value 仍是 ssh/api/auto,不改值——
@@ -1407,6 +1721,8 @@ window.__ModuleLoader__.load({
1407
1721
  }
1408
1722
 
1409
1723
  function dshgp_SettingsTab(props) {
1724
+ // §三:与账号页同一约定——面板重建后补读没读过/已过期的资源并重放显示态。
1725
+ react.useEffect(() => { if (props.panelRebuilt) props.panelRebuilt(); }, []);
1410
1726
  const s = props.state;
1411
1727
  return jsx.jsxs('div', {
1412
1728
  className: 'dshgp_section',
@@ -1417,7 +1733,59 @@ window.__ModuleLoader__.load({
1417
1733
  });
1418
1734
  }
1419
1735
 
1420
- /* ─── 第 10/13 片 · 页面装配(GitPushPage:两选项卡聚合;审计 Tab 已移出构建) ─── */
1736
+ /* ─── 第 11/14 片 · 页面装配(GitPushPage:两选项卡聚合;审计 Tab 已移出构建) ─── */
1737
+ /**
1738
+ * 资源状态提示条(§四:失败/过期如实说,且**不清空**已有内容)。
1739
+ *
1740
+ * 关键点:只有"真的读到了确定结论"才允许说否定结论(未配置/未连接)。
1741
+ * idle/loading ⇒ 「读取中…」;error ⇒ 「读取失败(可重试)」;
1742
+ * stale ⇒ 「显示的是上次结果,正在同步」。
1743
+ * @param {{info: object, onRetry?: Function, what?: string}} props info = uiStatus(name)
1744
+ * @returns {object|null} 无提示时返回 null(内容照常显示)
1745
+ */
1746
+ function dshgp_ResourceNotice(props) {
1747
+ const info = props.info || {};
1748
+ const what = props.what || '数据';
1749
+ if (info.state === 'idle' || info.state === 'loading') {
1750
+ return jsx.jsx('p', { className: 'dshgp_resstatus dshgp_resstatus_stale', children: '正在读取' + what + '…' });
1751
+ }
1752
+ if (info.state === 'error') {
1753
+ return jsx.jsxs('div', { className: 'dshgp_resstatus dshgp_resstatus_err', children: [
1754
+ jsx.jsx('span', { children: '读取' + what + '失败:' + (info.error || '未知原因') }),
1755
+ props.onRetry
1756
+ ? jsx.jsx('button', { type: 'button', className: 'dshgp_keybtn', onClick: props.onRetry, style: { marginLeft: '8px' }, children: '重试' })
1757
+ : null,
1758
+ ] });
1759
+ }
1760
+ if (info.state === 'stale') {
1761
+ return jsx.jsx('p', { className: 'dshgp_resstatus dshgp_resstatus_stale', children: '显示的是上次读取结果,正在后台同步…' });
1762
+ }
1763
+ return null;
1764
+ }
1765
+
1766
+ /**
1767
+ * 首屏骨架(R2:读回早于渲染)。
1768
+ *
1769
+ * 为什么必须有它:读回是异步的,若首帧直接渲染"真内容",那内容里的字段全是默认值 ——
1770
+ * 用户看到的就成了「未配置」「未连接」这类**确定性的否定结论**,而事实是"还没读"。
1771
+ * 骨架明确表达"正在读",读完由 ready 门禁切到真内容。
1772
+ */
1773
+ function dshgp_LoadingSkeleton() {
1774
+ const block = (key) => jsx.jsxs('div', { className: 'dshgp_skelblock', children: [
1775
+ jsx.jsx('div', { className: 'dshgp_skelline dshgp_skelline_m' }),
1776
+ jsx.jsx('div', { className: 'dshgp_skelline' }),
1777
+ jsx.jsx('div', { className: 'dshgp_skelline dshgp_skelline_s' }),
1778
+ ] }, key);
1779
+ return jsx.jsxs('div', {
1780
+ className: 'dshgp_skeleton',
1781
+ children: [
1782
+ jsx.jsxs('h2', { style: { margin: '0 0 10px', fontSize: '14px' }, children: ['Git 提交推送'] }),
1783
+ jsx.jsx('p', { className: 'dshgp_hint', children: '正在读取插件状态…' }),
1784
+ jsx.jsxs('div', { className: 'dshgp_skel', children: [block('a'), block('b')] }),
1785
+ ],
1786
+ });
1787
+ }
1788
+
1421
1789
  function dshgp_GitPushPage(props) {
1422
1790
  dshgp_ensureCss();
1423
1791
  const [tab, setTab] = react.useState('account');
@@ -1463,7 +1831,7 @@ window.__ModuleLoader__.load({
1463
1831
  });
1464
1832
  }
1465
1833
 
1466
- /* ─── 第 11/13 片 · Controller(状态机 + 数据加载 + 动作注入) ─────────────────── */
1834
+ /* ─── 第 12/14 片 · Controller(状态机 + 数据加载 + 动作注入) ─────────────────── */
1467
1835
  class dshgp_Controller {
1468
1836
  constructor(scope) {
1469
1837
  this.scope = scope;
@@ -1474,23 +1842,9 @@ window.__ModuleLoader__.load({
1474
1842
  this.failed = false;
1475
1843
  this.savedMsg = '';
1476
1844
  this.savedTimer = null;
1477
- this.auditEnabled = false;
1478
- this.injectRequirements = false;
1479
- // 注入总开关(默认开;新增, 扩展为系统提示词+上下文)
1480
- this.injectSystemPrompt = true;
1481
- // 审计扫描范围(diff|full)——设置持久化走 host HTTP,前端本地字段镜像
1482
- this.auditScanScope = 'diff';
1483
- this.ruleOrder = [];
1484
- this.slotMeta = {};
1485
- this.weightValues = {};
1486
- // 补齐:以下键此前只有 schema 声明与 HTTP 白名单,前端**没有 UI 控件**
1487
- // (只能看不能改)→ 设置「基本都没真正保存」的根源。这里补状态镜像 + 提交 + 回读。
1488
- this.maxScanFiles = 3000; // 全量审计文件数上限(0=不限)
1489
- this.pushMethod = 'ssh'; // ssh | api | auto
1490
- this.pushGate = false; // 推送门禁(开启后 push 需显式放行)
1491
- // defaultScanRoot/commitMessage 设置移除——默认扫描路径复用本地仓库
1492
- // 列表选择路径(localStorage dshgp-scan-path),提交信息留空由调用方/AI 生成。
1493
- // 禁用态不再前端变量存储,以 yml 顶层 disabled 为准(listRuleSlots 解析)
1845
+ // 设置类字段的默认值统一来自 dshgp_DEFAULT_SETTINGS(§五:默认值只有一个来源),
1846
+ // 这里不再逐行手写 —— 手写就等于在分片里又存了一份默认值。
1847
+ Object.assign(this, dshgp_DEFAULT_SETTINGS);
1494
1848
  this.statusMsg = '';
1495
1849
  this.statusTimer = null;
1496
1850
  // 账号信息(纯展示)
@@ -1538,8 +1892,6 @@ window.__ModuleLoader__.load({
1538
1892
  this.cloneHistory = null; // 预览框「带真实历史」勾选:null=未表态(跟随后端默认 true)、true/false=用户显式选择
1539
1893
  this.clonePending = { repo: '', dir: '' }; // 预览后待确认的上下文
1540
1894
  this.visConfirm = null; // 1.5.4:待确认的可见性切换({fullName, target, cur},命中则弹独立确认面板)
1541
- this.maxCloneFileMB = 10; // clone 单文件体积上限(MB);0=不限
1542
- this.cloneConcurrency = 6; // clone 并发下载数
1543
1895
  this.repoFeedback = {}; // { path: {ok, msg} } push 结果反馈(成功绿/失败红)
1544
1896
  // 规则包加载
1545
1897
  this.slotLoading = false;
@@ -1561,12 +1913,6 @@ window.__ModuleLoader__.load({
1561
1913
  // 公共 settings.yaml 已零写入(scope.set 全移除),snap.value 里这些键恒缺省,
1562
1914
  // 此前把 sshConfigured 覆盖成 !!snap.value.sshPub(恒 false)导致「配置了却显示
1563
1915
  // 未配置」,且每次 scope 发布都弹回,与 loadSettingsFromHttp 拉回的真值互相打架。
1564
- // 修复「规则包统计全是 0」:slotMeta 与 ruleOrder 同理,也不再从 scope 覆盖。
1565
- // snap.value.ruleSlotMeta 是 schema 里声明为「host 启动填充」的字段,但**宿主从未写入**,
1566
- // 于是每次 scope 发布都把它(空对象)赋给 slotMeta,刚由 loadSlots() 拉到的真实统计被清空,
1567
- // 所有规则包行回退到 {blocker:0,warning:0,pass:0,total:0} 兜底值 → 列表里数字全是 0。
1568
- // 权威来源 = loadSlots() 的后端结果(动态发现全部 yml 并带 stats);启停的即时反馈由
1569
- // toggleDisabled 自己改 slotMeta、随后 loadSlots 对账。
1570
1916
  }
1571
1917
  this.publish();
1572
1918
  });
@@ -1576,24 +1922,49 @@ window.__ModuleLoader__.load({
1576
1922
  // refreshAccount(/account-check 读凭据文件真源)与 loadSettingsFromHttp 刷新。
1577
1923
  const snap0 = this.scope.getSnapshot();
1578
1924
  if (snap0 && snap0.value) {
1579
- if (typeof snap0.value.auditEnabled === 'boolean') this.auditEnabled = snap0.value.auditEnabled;
1580
- if (typeof snap0.value.injectRequirements === 'boolean') this.injectRequirements = snap0.value.injectRequirements;
1581
1925
  if (typeof snap0.value.injectSystemPrompt === 'boolean') this.injectSystemPrompt = snap0.value.injectSystemPrompt;
1582
- if (typeof snap0.value.auditScanScope === 'string') this.auditScanScope = snap0.value.auditScanScope;
1583
- const wo0 = String(snap0.value.weightOverrides || '');
1584
- if (wo0.trim()) { try { this.weightValues = JSON.parse(wo0) || {}; } catch { /* 忽略 */ } }
1585
- }
1586
- // 若 loadSlots 尚未返回,先用已发现的槽位做占位显示(不含 private/template)
1587
- if (!this.ruleOrder.length && Object.keys(this.slotMeta).length) {
1588
- this.ruleOrder = Object.keys(this.slotMeta).filter((s) => s !== 'private' && s !== 'template');
1589
1926
  }
1590
- // 改走统一刷新入口(一次调用刷设置与槽位;账号仍按需在页面 mount 时刷)
1591
- void this.refresh(['settings', 'slots']);
1592
- // 账号状态改由「首次打开账号信息页」时(dshgp_AccountTab 的 mount effect)
1593
- // 触发 refreshAccount,避免构造阶段与页面打开重复拉取;此处不再自动刷新。
1594
- // 设置持久化走 HTTP 读宿主 scope(绕开 client isLoopback=memory 陷阱——
1595
- // 反代访问时 scope 快照恒 unavailable,从宿主侧读已落盘设置,重启后开关保持勾选)
1596
- // 该读取已并入上方 this.refresh(['settings','slots']),此处不再重复请求。
1927
+ // ── UI 状态工厂(单一真相源)──
1928
+ // 读、状态、重放都收在这一层;本类的同名字段只是它的**派生投影**(R1)。
1929
+ // 注册顺序 = 首屏依赖顺序:设置/账号/npm 决定首屏,列表自己带加载态。
1930
+ this.uiState = dshgp_createUiState({ onChange: () => this.publish() });
1931
+ this.uiState
1932
+ .register('settings', { load: () => dshgp_getJson('/api/git-push/settings-get') })
1933
+ .register('account', { load: () => dshgp_getJson('/api/git-push/account-status') })
1934
+ .register('npm', { load: () => dshgp_getJson('/api/git-push/npm-account') })
1935
+ // 列表:后端已改为「只读索引快照(毫秒级)」,远端状态由后台补(见 task-23 M3)
1936
+ .register('repos', { load: (arg) => this.loadReposPayload(arg), timeoutMs: 15_000 })
1937
+ // npm 子页的「已装依赖」也是数据(曾由组件自己 useState + fetch,形成第二份真相)
1938
+ .register('npmPackages', { load: (arg) => this.loadNpmPackagesPayload(arg) });
1939
+ // 渲染器 = 幂等的「按值刷显示」(R3);面板重建后由 markRebuilt 重放(§三)
1940
+ this.uiState
1941
+ .setRenderer('settings', (payload) => this.applySettingsPayload(payload))
1942
+ .setRenderer('account', (payload) => this.applyAccountPayload(payload))
1943
+ .setRenderer('npm', (payload) => this.applyNpmPayload(payload))
1944
+ .setRenderer('repos', (payload) => this.applyReposPayload(payload));
1945
+ // 首屏门禁只等「快的三个」:列表自己显示加载态,不能把首屏拖成 30s 空白
1946
+ this.uiFirstPaintNames = ['settings', 'account', 'npm'];
1947
+ // R2:读回早于首次渲染 —— 由 apply.js 的 loadAll() 驱动,读完才放开骨架
1948
+ }
1949
+
1950
+ /**
1951
+ * 首屏是否已可渲染真实内容(R2 门禁)。
1952
+ * 只判断首屏必需资源:settings/account/npm。**不是**「全都读完」——
1953
+ * 列表可能仍在读,它自己有加载态;把列表并进门禁会让首屏退化成骨架。
1954
+ * @returns {{ready: boolean, pending: string[]}}
1955
+ */
1956
+ uiReadyInfo() {
1957
+ // 构造期 project() 先于状态工厂创建(store 的初始快照就是在构造里取的)⇒ 这里必须容忍
1958
+ if (!this.uiState) return { ready: false, pending: (this.uiFirstPaintNames || []).slice() };
1959
+ const pending = (this.uiFirstPaintNames || []).filter((name) => this.uiState.status(name).state === 'loading'
1960
+ || (this.uiState.value(name) === undefined && this.uiState.status(name).state !== 'error'));
1961
+ return { ready: pending.length === 0, pending: pending };
1962
+ }
1963
+
1964
+ /** 某资源的界面状态(组件按它分支渲染占位/错误/内容,不再靠值真假猜)。 */
1965
+ uiStatus(name) {
1966
+ if (!this.uiState) return { state: 'idle', loading: false, error: '', at: 0, hasValue: false };
1967
+ return this.uiState.status(name);
1597
1968
  }
1598
1969
  project() {
1599
1970
  // 恒可用/恒可写:数据与写入全走 HTTP(settings-get/settings-set/account-check/rule-slots),
@@ -1601,21 +1972,15 @@ window.__ModuleLoader__.load({
1601
1972
  // persistence——反代/非 loopback 访问时恒 memory 模式、status 恒 unavailable、
1602
1973
  // writable 恒 false(isLoopback=memory 陷阱)。若仍以快照判 available,设置侧边栏
1603
1974
  // 在反代访问下会整页空白(SectionPage return null)且输入框全禁用,故绕开快照判定。
1975
+ const readyInfo = this.uiReadyInfo();
1604
1976
  return {
1605
1977
  available: true,
1606
1978
  writable: true,
1607
1979
  text: this.text,
1608
1980
  sshPub: this.sshPub,
1609
1981
  sshEmail: this.sshEmail,
1610
- auditEnabled: this.auditEnabled,
1611
- injectRequirements: this.injectRequirements,
1982
+ preCommitEnabled: this.preCommitEnabled,
1612
1983
  injectSystemPrompt: this.injectSystemPrompt,
1613
- auditScanScope: this.auditScanScope,
1614
- ruleOrder: this.ruleOrder,
1615
- slotMeta: this.slotMeta,
1616
- weightValues: this.weightValues,
1617
- // 补齐:审计进阶 / 推送默认值状态镜像(供 UI 渲染)
1618
- maxScanFiles: this.maxScanFiles,
1619
1984
  pushMethod: this.pushMethod,
1620
1985
  pushGate: this.pushGate, // 推送门禁(开启后 push 需显式放行)
1621
1986
  // defaultScanRoot/commitMessage 状态镜像移除(设置已删除)
@@ -1640,8 +2005,6 @@ window.__ModuleLoader__.load({
1640
2005
  npmInstallResult: this.npmInstallResult,
1641
2006
  npmInstallDialog: this.npmInstallDialog,
1642
2007
  npmInstallProgress: this.npmInstallProgress,
1643
- slotLoading: this.slotLoading,
1644
- slotError: this.slotError,
1645
2008
  refreshError: this.refreshError, // 统一刷新入口的部分级错误
1646
2009
  statusMsg: this.statusMsg,
1647
2010
  genKeying: this.genKeying,
@@ -1662,6 +2025,18 @@ window.__ModuleLoader__.load({
1662
2025
  maxCloneFileMB: this.maxCloneFileMB,
1663
2026
  cloneConcurrency: this.cloneConcurrency,
1664
2027
  repoFeedback: this.repoFeedback,
2028
+ // UI 状态工厂门禁与状态位(组件据此分支:骨架 / 内容 / 失败可重试)
2029
+ uiReady: readyInfo.ready,
2030
+ uiPending: readyInfo.pending,
2031
+ uiStatus: {
2032
+ settings: this.uiStatus('settings'),
2033
+ account: this.uiStatus('account'),
2034
+ npm: this.uiStatus('npm'),
2035
+ repos: this.uiStatus('repos'),
2036
+ npmPackages: this.uiStatus('npmPackages'),
2037
+ },
2038
+ // npm 子页「已装依赖」数据:单一真相在状态工厂,组件只读这里(禁止再自己 useState 一份)
2039
+ npmPackages: this.uiState ? this.uiState.value('npmPackages') : null,
1665
2040
  dirty: this.text.trim().length > 0 || this.sshPub.trim().length > 0,
1666
2041
  saving: this.saving,
1667
2042
  failed: this.failed,
@@ -1711,7 +2086,7 @@ window.__ModuleLoader__.load({
1711
2086
  * await this.refresh('repos', { rebuild: true }); // 重建索引后刷本地列表
1712
2087
  */
1713
2088
  async refresh(parts = 'all', opts = {}) {
1714
- const PARTS = ['settings', 'account', 'npm', 'repos', 'cloud', 'slots'];
2089
+ const PARTS = ['settings', 'account', 'npm', 'repos', 'cloud'];
1715
2090
  let list;
1716
2091
  if (parts === 'all' || parts === undefined || parts === null) list = PARTS.slice();
1717
2092
  else list = (Array.isArray(parts) ? parts : [parts])
@@ -1732,7 +2107,6 @@ window.__ModuleLoader__.load({
1732
2107
  }
1733
2108
  else if (p === 'repos') await this.scanLocalRepos(opts.path, opts.rebuild, { silent: opts.silent });
1734
2109
  else if (p === 'cloud') await this.loadCloudRepos({ silent: opts.silent });
1735
- else if (p === 'slots') await this.loadSlots({ silent: opts.silent });
1736
2110
  } catch (e) {
1737
2111
  // 单个部分失败不影响其余部分:记录到统一错误位,继续刷下一个
1738
2112
  this.refreshError = `${p}: ` + (e && e.message || e);
@@ -1792,79 +2166,65 @@ window.__ModuleLoader__.load({
1792
2166
  }, 1000);
1793
2167
  }
1794
2168
 
2169
+ /** 设置读回:**薄壳**(读与状态由 UI 状态工厂负责,本方法只保留"重读"语义)。 */
1795
2170
  async loadSettingsFromHttp() {
1796
- try {
1797
- const settingsRes = await dshgp_getJson('/api/git-push/settings-get');
1798
- if (!settingsRes || !settingsRes.ok || !settingsRes.settings) return;
1799
- const v = settingsRes.settings;
1800
- if (typeof v.auditEnabled === 'boolean' && !this.editedKeys.has('auditEnabled')) this.auditEnabled = v.auditEnabled;
1801
- if (typeof v.injectRequirements === 'boolean' && !this.editedKeys.has('injectRequirements')) this.injectRequirements = v.injectRequirements;
2171
+ return this.uiState.reload('settings');
2172
+ }
2173
+
2174
+ /**
2175
+ * 把 /settings-get 的返回投影到本类字段(幂等)。
2176
+ * 用户正在编辑的键跳过(editedKeys):GET 是异步的,回来的是旧值,
2177
+ * 直接覆盖会把刚点的勾选弹回默认。
2178
+ */
2179
+ applySettingsPayload(payload) {
2180
+ const v = (payload && payload.settings) || null;
2181
+ if (!v) return;
2182
+ {
2183
+ // 预处理开关在 config.json 里是嵌套的 preCommit.enabled(与引擎 command/args 同块)
2184
+ if (v.preCommit && typeof v.preCommit.enabled === 'boolean' && !this.editedKeys.has('preCommitEnabled')) {
2185
+ this.preCommitEnabled = v.preCommit.enabled;
2186
+ }
1802
2187
  if (typeof v.injectSystemPrompt === 'boolean' && !this.editedKeys.has('injectSystemPrompt')) this.injectSystemPrompt = v.injectSystemPrompt;
1803
- if (typeof v.auditScanScope === 'string' && !this.editedKeys.has('auditScanScope')) this.auditScanScope = v.auditScanScope;
1804
- // 补齐回读:新增 UI 的 7 键(advanced),重启后从 config.json 恢复勾选/取值
1805
- if (typeof v.maxScanFiles === 'number' && !this.editedKeys.has('maxScanFiles')) this.maxScanFiles = v.maxScanFiles;
2188
+ // 补齐回读:advanced 键,重启后从 config.json 恢复勾选/取值
1806
2189
  if (typeof v.maxCloneFileMB === 'number' && !this.editedKeys.has('maxCloneFileMB')) this.maxCloneFileMB = v.maxCloneFileMB;
1807
2190
  if (typeof v.cloneConcurrency === 'number' && !this.editedKeys.has('cloneConcurrency')) this.cloneConcurrency = v.cloneConcurrency;
1808
2191
  if (typeof v.pushMethod === 'string' && !this.editedKeys.has('pushMethod')) this.pushMethod = v.pushMethod;
1809
2192
  // 补漏:pushGate(推送门禁)此前**不在回读列表**——构造函数默认 false,
1810
2193
  // 打开/刷新设置页时不被宿主真值覆盖,界面永远显示未勾选(实测:勾了门禁、重开页面又变未勾选)。
1811
2194
  if (typeof v.pushGate === 'boolean' && !this.editedKeys.has('pushGate')) this.pushGate = v.pushGate;
1812
- // defaultScanRoot/commitMessage 不再作为设置键回读(已在 UI/白名单移除)
1813
- if (typeof v.weightOverrides === 'string' && v.weightOverrides.trim() && !this.editedKeys.has('weightOverrides')) {
1814
- try { this.weightValues = JSON.parse(v.weightOverrides) || {}; } catch { /* 忽略 */ }
1815
- }
1816
2195
  // 凭据布尔位不受编辑守卫影响:只读派生标记,无回弹风险
1817
2196
  if (typeof v.tokenConfigured === 'boolean') this.tokenConfigured = v.tokenConfigured;
1818
2197
  if (typeof v.sshConfigured === 'boolean') this.sshConfigured = v.sshConfigured;
1819
- this.publish();
1820
- } catch (_e) { /* 端点不可用/未注册时沿用 scope 兜底 */ }
1821
- }
1822
-
1823
- /** 加载规则包清单(/rule-slots,动态发现 yml)。 */
1824
- // 重构:原 loadCredentialFlags(/status 只刷 tokenConfigured)删除——
1825
- // 凭据标志统一由 refreshAccount(/account-check,读凭据文件真源)刷新,避免第三条链路打架。
1826
- async loadSlots({ silent = false } = {}) {
1827
- if (!silent) { this.slotLoading = true; }
1828
- this.slotError = '';
1829
- this.publish();
1830
- try {
1831
- const slotsRes = await dshgp_getJson('/api/git-audit/rule-slots');
1832
- if (slotsRes && slotsRes.ok && slotsRes.slots) {
1833
- const meta = slotsRes.slots.meta || {};
1834
- // 用后端返回的生效顺序;private 恒末尾
1835
- const list = Array.isArray(slotsRes.slots.order) ? slotsRes.slots.order : [];
1836
- const order = list.filter((s) => s !== 'template');
1837
- const forced = Array.isArray(slotsRes.slots.forced) ? slotsRes.slots.forced : [];
1838
- this.slotMeta = meta;
1839
- this.ruleOrder = order;
1840
- if (forced.includes('private') && !this.ruleOrder.includes('private')) this.ruleOrder.push('private');
1841
- } else {
1842
- this.slotError = (slotsRes && slotsRes.message) || '规则包加载失败';
1843
- }
1844
- } catch (e) {
1845
- this.slotError = '规则包加载失败: ' + (e && e.message || e);
1846
2198
  }
1847
- this.slotLoading = false;
1848
- this.publish();
2199
+ // 读失败不再被 try/catch 吞掉:状态工厂会把它记成 error 状态,
2200
+ // 界面按 uiStatus('settings') 渲染"读取失败(可重试)",而不是照常显示默认值却像"已保存"。
1849
2201
  }
1850
2202
 
1851
- /** 离线读 npm 账号态(/npm-account,秒级不联网);与 refreshAccount 完全同构。 */
2203
+ /**
2204
+ * npm 账号态:**薄壳**(读由 UI 状态工厂负责,本方法只保留"重读"语义与加载标记)。
2205
+ *
2206
+ * 为什么必须薄:此前 npm 与 GitHub 两套各写字段、各吞错误,于是「没读到」与「读到了但为空」
2207
+ * 在界面上长得一样(实测:从未请求过 /npm-account,界面却断言「未配置 npm token」)。
2208
+ * 现在值只存在状态工厂里,本类的 npm* 字段是它的派生投影(R1)。
2209
+ */
1852
2210
  async refreshNpmAccount({ silent = false } = {}) {
1853
- if (!silent) { this.npmAccountLoading = true; }
1854
- this.publish();
1855
- try {
1856
- const res = await dshgp_getJson('/api/git-push/npm-account');
1857
- this.npmAccountBlock = (res && res.block) || '(无 npm 账号记录,点「刷新」在线校验)';
1858
- this.npmAccountLoggedIn = !!(res && res.loggedIn);
1859
- this.npmAccountUser = (res && res.user) || '';
1860
- this.npmConfigured = !!(res && res.configured);
1861
- } catch (e) {
1862
- this.npmAccountBlock = '读取失败: ' + ((e && e.message) || e);
1863
- this.npmAccountLoggedIn = false;
1864
- this.npmAccountUser = '';
1865
- }
2211
+ if (!silent) { this.npmAccountLoading = true; this.publish(); }
2212
+ const r = await this.uiState.reload('npm');
1866
2213
  this.npmAccountLoading = false;
1867
2214
  this.publish();
2215
+ return r;
2216
+ }
2217
+
2218
+ /** 把 /npm-account 的返回投影到本类字段(幂等;只读 payload,不做任何默认值编造)。 */
2219
+ applyNpmPayload(payload) {
2220
+ const p = (payload && typeof payload === 'object') ? payload : null;
2221
+ if (!p) return;
2222
+ // 后端 block 是"人话结论"(含 ✅/⚠️ 与原因);为空就保持为空 ——
2223
+ // 界面按 uiStatus('npm') 分支渲染"读取中/读取失败",绝不把"没读"写成"未配置"。
2224
+ this.npmAccountBlock = String(p.block || '');
2225
+ this.npmAccountLoggedIn = !!p.loggedIn;
2226
+ this.npmAccountUser = String(p.user || '');
2227
+ this.npmConfigured = !!p.configured;
1868
2228
  }
1869
2229
 
1870
2230
  /** 在线校验 npm 登录态并写快照(/npm-check);与 recheckAccount 完全同构。 */
@@ -1879,7 +2239,8 @@ window.__ModuleLoader__.load({
1879
2239
  this.npmAccountUser = (res && res.user) || '';
1880
2240
  this.npmConfigured = !!(res && res.configured);
1881
2241
  } catch (e) {
1882
- this.npmAccountBlock = '⏳ 在线校验失败(网络超时或未配置),可稍后重试:' + ((e && e.message) || e);
2242
+ // 只报事实:在线校验没成功、原因是什么。不在没证据时断言「未配置」。
2243
+ this.npmAccountBlock = '⏳ 在线校验未完成(可稍后重试):' + ((e && e.message) || e);
1883
2244
  this.npmAccountLoggedIn = false;
1884
2245
  }
1885
2246
  this.npmAccountLoading = false;
@@ -2028,27 +2389,28 @@ window.__ModuleLoader__.load({
2028
2389
  /** 离线读账号状态(秒级,不触发任何网络):读 account-status.json 快照 + 凭据文件。
2029
2390
  * 插件启动 / push 后重读 / 账号卡片渲染全用它。「重新检测」才走在线(recheckAccount)。 */
2030
2391
  async refreshAccount({ silent = false } = {}) {
2031
- if (!silent) { this.accountLoading = true; }
2032
- this.publish();
2033
- try {
2034
- const accountRes = await dshgp_getJson('/api/git-push/account-status');
2035
- this.accountBlock = (accountRes && accountRes.block) || '(无账号状态记录,点击「重新检测」在线校验)';
2036
- this.accountLoggedIn = !!(accountRes && accountRes.loggedIn);
2037
- this.tokenConfigured = !!(accountRes && accountRes.tokenConfigured);
2038
- this.sshConfigured = !!(accountRes && accountRes.sshConfigured);
2039
- this.tokenStatus = (accountRes && accountRes.tokenStatus) || null;
2040
- this.sshStatus = (accountRes && accountRes.sshStatus) || null;
2041
- this.apiQuota = (accountRes && accountRes.apiQuota) || null;
2042
- } catch (e) {
2043
- this.accountBlock = '读取失败: ' + (e && e.message || e);
2044
- this.accountLoggedIn = false;
2045
- }
2392
+ if (!silent) { this.accountLoading = true; this.publish(); }
2393
+ const r = await this.uiState.reload('account');
2046
2394
  this.accountLoading = false;
2047
2395
  this.publish();
2048
2396
  // token 配额刷新(异步、不阻塞凭据显示):查 /api-quota(后端写回快照)→ 按
2049
2397
  // statusUpdated 标志重读 account-status,使凭据块 Token 行出现「(配额剩余 N/h)」。
2050
- // 查询本身失败不影响凭据展示;落盘失败由 quotaError 记录(不再静默)。
2051
- this.refreshApiQuota();
2398
+ // 只在账号态读成功时做:失败时连发配额请求只会把错误面搅浑。
2399
+ if (r && r.ok) this.refreshApiQuota();
2400
+ return r;
2401
+ }
2402
+
2403
+ /** 把 /account-status 的返回投影到本类字段(幂等;失败路径**不调用**它 ⇒ 旧值保留,§四)。 */
2404
+ applyAccountPayload(payload) {
2405
+ const p = (payload && typeof payload === 'object') ? payload : null;
2406
+ if (!p) return;
2407
+ this.accountBlock = String(p.block || '');
2408
+ this.accountLoggedIn = !!p.loggedIn;
2409
+ this.tokenConfigured = !!p.tokenConfigured;
2410
+ this.sshConfigured = !!p.sshConfigured;
2411
+ this.tokenStatus = p.tokenStatus || null;
2412
+ this.sshStatus = p.sshStatus || null;
2413
+ if (p.apiQuota) this.apiQuota = p.apiQuota;
2052
2414
  }
2053
2415
 
2054
2416
  // 刷新 token 的 GitHub API 配额(异步):查 /api/git-push/api-quota → 按收口标志重读快照。
@@ -2102,36 +2464,67 @@ window.__ModuleLoader__.load({
2102
2464
  * rebuild=true:**离线重建索引**(扫描本地 .git,author 与离线账号 json 一致的登记,
2103
2465
  * 含本地新增,全程不联网)后再读回;缺省:直接读索引返回(不复扫、不联网)。 */
2104
2466
  async scanLocalRepos(path, rebuild, { silent = false } = {}) {
2105
- if (!silent) { this.localLoading = true; }
2106
- this.localMsg = '';
2107
- this.publish();
2108
- try {
2109
- const p = String(path || '').trim();
2110
- dshgp_localSet('dshgp-scan-path', p);
2111
- const qs = '?rebuild=' + (rebuild ? '1' : '0') + (p ? '&path=' + encodeURIComponent(p) : '');
2112
- const localRes = await dshgp_getJson('/api/git-push/repos-local' + qs);
2113
- if (localRes && localRes.ok) {
2114
- this.localPath = localRes.root || p;
2115
- this.localRepos = Array.isArray(localRes.repos) ? localRes.repos : [];
2116
- this.localMsg = this.localRepos.length
2117
- ? (rebuild ? '已重建索引,读取到 ' : '读取到 ') + this.localRepos.length + ' 个仓库(' + (localRes.root || '') + ')'
2118
- : '索引中没有本账号仓库: ' + (localRes.root || '');
2119
- } else {
2120
- this.localRepos = [];
2121
- this.localMsg = '❌ ' + ((localRes && localRes.error) || '读取失败');
2122
- }
2123
- } catch (e) {
2124
- this.localRepos = [];
2125
- this.localMsg = '❌ 读取失败: ' + (e && e.message || e);
2126
- }
2467
+ if (!silent) { this.localLoading = true; this.publish(); }
2468
+ const r = await this.uiState.reload('repos', { path: path, rebuild: rebuild === true });
2127
2469
  this.localLoading = false;
2128
2470
  this.publish();
2471
+ // 列表先出(毫秒级快照),远端状态由后端后台补 —— 这里按 stale 自动重拉一次,
2472
+ // 用户不必手动刷新。只在 stale 时排一次,且同一时刻只排一个(防轮询风暴)。
2473
+ const payload = (r && r.ok) ? r.value : null;
2474
+ if (payload && payload.stale === true) this.scheduleReposReload();
2129
2475
  // 读取/扫描收尾后**自动补查未知远端状态**——列表里 liveSkipped(本地列表预算/
2130
2476
  // 熔断导致 SSH 探测跳过)的仓库,串行向后端补查(SSH 真源),结果追加写回索引,
2131
2477
  // 同时刷新本地列表的远端状态(remoteHead/ahead/behind/remoteHeadAt/synced)。
2132
2478
  void this.refreshUnknownRemote();
2133
2479
  }
2134
2480
 
2481
+ /**
2482
+ * 远端状态过期时,约一个后台补查周期后再拉一次列表(拿到 ahead/behind/分支)。
2483
+ * 只排一次:后端补查是单飞的,前端多排几次只会重复请求同一份快照。
2484
+ * @param {number} [delayMs] 延迟(默认 8s:覆盖一次 27 仓后台补查的常见耗时)
2485
+ */
2486
+ scheduleReposReload(delayMs) {
2487
+ if (this._reposReloadTimer) return;
2488
+ const wait = Number.isFinite(Number(delayMs)) && Number(delayMs) >= 0 ? Number(delayMs) : 8000;
2489
+ this._reposReloadTimer = setTimeout(() => {
2490
+ this._reposReloadTimer = null;
2491
+ void this.uiState.reload('repos');
2492
+ }, wait);
2493
+ }
2494
+
2495
+ /** 读「已装依赖」面板数据(供状态工厂调用;组件不再自己 fetch)。 */
2496
+ loadNpmPackagesPayload(arg) {
2497
+ const dir = String((arg && arg.dir) || '').trim();
2498
+ return dshgp_getJson('/api/git-push/npm-packages' + (dir ? '?dir=' + encodeURIComponent(dir) : ''));
2499
+ }
2500
+
2501
+ /** 读本地仓库列表(供状态工厂调用;不做字段写入,字段由 applyReposPayload 投影)。 */
2502
+ loadReposPayload(arg) {
2503
+ const a = arg || {};
2504
+ const p = String(a.path || '').trim();
2505
+ dshgp_localSet('dshgp-scan-path', p);
2506
+ const qs = '?rebuild=' + (a.rebuild ? '1' : '0') + (p ? '&path=' + encodeURIComponent(p) : '');
2507
+ return dshgp_getJson('/api/git-push/repos-local' + qs);
2508
+ }
2509
+
2510
+ /**
2511
+ * 把 /repos-local 的返回投影到本类字段(幂等)。
2512
+ * 失败路径**不调用**它 ⇒ 上一次的列表继续显示(§四:失败不清空)。
2513
+ * 文案也只描述"读到了什么",不再把失败写成 `❌ 读取失败: …` 塞进同一个字段 ——
2514
+ * 失败由 uiStatus('repos') 表达,界面据此渲染可重试的错误条。
2515
+ */
2516
+ applyReposPayload(payload) {
2517
+ const p = (payload && typeof payload === 'object') ? payload : null;
2518
+ if (!p) return;
2519
+ if (!p.ok) return; // 后端明确失败:保留旧列表,状态位由工厂记 error
2520
+ this.localPath = String(p.root || this.localPath || '');
2521
+ this.localRepos = Array.isArray(p.repos) ? p.repos : [];
2522
+ this.localMsg = this.localRepos.length
2523
+ ? (p.stale ? '读取到 ' : '读取到 ') + this.localRepos.length + ' 个仓库(' + (p.root || '') + ')'
2524
+ + (p.stale ? ';远端状态同步中…' : '')
2525
+ : '索引中没有本账号仓库: ' + (p.root || '');
2526
+ }
2527
+
2135
2528
  /** 自动补查 liveSkipped(未知远端状态)仓库:串行走 /repos-local-refresh,更新列表条目。 */
2136
2529
  async refreshUnknownRemote() {
2137
2530
  if (this.refreshingRemote) return; // 防重入
@@ -2540,34 +2933,8 @@ window.__ModuleLoader__.load({
2540
2933
  }
2541
2934
  }
2542
2935
 
2543
- /** 单击规则包行:切换禁用/启用(改为写 yml 顶层 disabled,不存 scope 变量)。 */
2544
- async toggleDisabled(slot) {
2545
- if (slot === 'nodejs' || slot === 'private') {
2546
- this.setStatus('⚠️ nodejs/private 安全红线槽位不可禁用');
2547
- return;
2548
- }
2549
- const meta = (this.slotMeta && this.slotMeta[slot]) || {};
2550
- const nowDisabled = !!(meta.disabled);
2551
- // 即时反馈:先本地翻转(行绿/红 + 顶部提示),不等后端响应
2552
- this.slotMeta = { ...(this.slotMeta || {}), [slot]: { ...meta, disabled: !nowDisabled } };
2553
- this.setStatus(!nowDisabled ? '✅ 已禁用 ' + slot + '(该槽位规则不再加载)' : '✅ 已启用 ' + slot);
2554
- this.publish();
2555
- try {
2556
- const toggleRes = await dshgp_postJson('/api/git-audit/toggle-rule', { slot, disabled: !nowDisabled });
2557
- if (toggleRes && toggleRes.ok) {
2558
- void this.loadSlots(); // 后台重载对账(yml 解析结果)
2559
- } else {
2560
- this.setStatus('❌ 切换失败:' + ((toggleRes && toggleRes.error) || '未知错误'));
2561
- this.loadSlots();
2562
- }
2563
- } catch (e) {
2564
- this.setStatus('❌ 切换失败:' + (e && e.message || e));
2565
- void this.loadSlots(); // 恢复 yml 真实状态
2566
- }
2567
- }
2568
-
2569
2936
  /** 审计 tab 顶部即时反馈(区别于设置 tab 的 flashSaved)。 */
2570
- /* ─── 第 12/13 片 · Controller 动作注入(接 controller.js 的类体,方法声明不可拆出类外) ─────────────────── */
2937
+ /* ─── 第 13/14 片 · Controller 动作注入(接 controller.js 的类体,方法声明不可拆出类外) ─────────────────── */
2571
2938
  setStatus(msg) {
2572
2939
  this.statusMsg = String(msg || '');
2573
2940
  if (this.statusTimer) clearTimeout(this.statusTimer);
@@ -2577,26 +2944,10 @@ window.__ModuleLoader__.load({
2577
2944
  }, dshgp_SAVED_MSG_MS);
2578
2945
  }
2579
2946
 
2580
- /** 上下调整规则包次序(下覆盖上)。 */
2581
- moveSlot(slot, dir) {
2582
- const arr = [...this.ruleOrder];
2583
- const i = arr.indexOf(slot);
2584
- const j = i + dir;
2585
- if (i < 0 || j < 0 || j >= arr.length) return;
2586
- [arr[i], arr[j]] = [arr[j], arr[i]];
2587
- this.ruleOrder = arr;
2588
- this.publish();
2589
- // 次序持久化走 HTTP settings-set(写插件私有 config.json)。
2590
- // 不再 scope.set——scope.set 会把 auditRuleOrder 写进公共 settings.yaml
2591
- // (跨实例锁竞争 + isLoopback=memory 陷阱,见 settings-bridge.js 头部说明)。
2592
- this.persistSetting('auditRuleOrder', arr);
2593
- this.setStatus('✅ 规则包次序已保存:' + arr.join(' → '));
2594
- }
2595
2947
 
2596
2948
  /**
2597
- * 前端设置写入通用入口(抽公共函数消除 toggle 系列重复)。
2598
- * 统一四件套:标记 editedKeys(防 loadSettingsFromHttp 异步 GET 旧值覆盖弹回)
2599
- * → publish(UI 立即反映)→ persistSetting(HTTP 落盘 config.json + loopback scope 双通道)。
2949
+ * 前端设置写入通用入口(统一三件事:标记 editedKeys 防异步 GET 旧值弹回
2950
+ * → publish 让 UI 立即反映 → persistSetting 走 HTTP 落盘 config.json)。
2600
2951
  * @param {string} key 设置键
2601
2952
  * @param {unknown} value 值
2602
2953
  * @param {string} okMsg flashSaved 成功文案(空=静默)
@@ -2607,18 +2958,6 @@ window.__ModuleLoader__.load({
2607
2958
  this.persistSetting(key, value, okMsg);
2608
2959
  }
2609
2960
 
2610
- /** 审计开关(写回 auditEnabled)。 */
2611
- toggleAudit(checked) {
2612
- this.auditEnabled = !!checked;
2613
- // 交互修正:关闭父开关时**不再**把子开关的勾选抹掉。
2614
- // 子开关的勾选状态独立保存,父开关只管「此刻生不生效」(host 侧注入由
2615
- // cfg.auditEnabled && cfg.injectRequirements 门控)。原实现静默清勾选,
2616
- // 重开父开关时还得再点一遍子开关,且看不出勾选是被谁清掉的。
2617
- this.commitSetting('auditEnabled', this.auditEnabled, this.auditEnabled
2618
- ? '✅ 已开启:提交前自动审计'
2619
- : '✅ 已关闭:提交前不审计');
2620
- }
2621
-
2622
2961
  /**
2623
2962
  * 设置持久化统一入口(**零 scope.set**,单通道走 host HTTP /settings-set → 写插件私有
2624
2963
  * config.json)。彻底移除 scope.set:
@@ -2666,22 +3005,11 @@ window.__ModuleLoader__.load({
2666
3005
  }
2667
3006
 
2668
3007
  /**
2669
- * 注入开发者要求清单开关(auditEnabled 的子开关)。
2670
- * 父开关关闭时**仍可勾选**(保留偏好、只置灰、不注入)——原实现在这里直接 return,
2671
- * 用户点了没任何反应,必须先开父开关再点一次(两遍)。
2672
- */
2673
- toggleInjectRequirements(checked) {
2674
- this.injectRequirements = !!checked;
2675
- this.commitSetting('injectRequirements', this.injectRequirements, this.injectRequirements
2676
- ? (this.auditEnabled ? '✅ 已开启:注入开发者要求清单' : '✅ 已勾选:待开启「提交前自动审计」后生效')
2677
- : '✅ 已关闭:不注入要求清单');
2678
- }
2679
3008
 
2680
3009
  /**
2681
3010
  * 注入总开关(写回 injectSystemPrompt;默认开)。
2682
3011
  * 关 = host 侧 systemPrompt 段全部返回空串 + 上下文注入不注入;
2683
- * 开 = 功能用法/README 提醒/要求清单走系统提示词,环境(工作区/工具/skill 入口)走上下文首条注入。
2684
- * 注入段里的「开发者要求清单」仍受 auditEnabled + injectRequirements 双重门控。
3012
+ * 开 = 功能用法/README 提醒走系统提示词,环境(工作区/工具/skill 入口)走上下文首条注入。
2685
3013
  */
2686
3014
  toggleInjectSystemPrompt(checked) {
2687
3015
  this.injectSystemPrompt = !!checked;
@@ -2693,36 +3021,16 @@ window.__ModuleLoader__.load({
2693
3021
  }
2694
3022
 
2695
3023
  /**
2696
- * 审计扫描范围切换:diff=仅本次变动(auditChanged,默认)/ full=全量(auditFull)。
2697
- * 按钮式单击切换;持久化走 host HTTP(persistence=memory 陷阱绕开方案,见 settings-bridge.js)。
2698
- */
2699
- toggleAuditScanScope(scope) {
2700
- const next = scope === 'full' ? 'full' : 'diff';
2701
- if (this.auditScanScope === next) return;
2702
- this.auditScanScope = next;
2703
- this.commitSetting('auditScanScope', next, next === 'full'
2704
- ? '✅ 已切换:审计扫描范围 = 全量(auditFull)'
2705
- : '✅ 已切换:审计扫描范围 = 部分(auditChanged,仅本次变动)');
2706
- }
2707
-
2708
- /** 权重维度编辑(合并写回 weightOverrides JSON)。 */
2709
- editWeight(key, value) {
2710
- this.weightValues = { ...(this.weightValues || {}), [key]: value };
2711
- const json = JSON.stringify(this.weightValues);
2712
- this.commitSetting('weightOverrides', json, '✅ 权重已保存(合计 ' + dshgp_DIMENSIONS.reduce((a, d) => a + (this.weightValues[d.key] != null ? this.weightValues[d.key] : d.def), 0) + '),下次审计生效');
2713
- }
2714
-
2715
- /**
2716
- * 新增 / 收敛:审计进阶 / 推送通道设置项通用提交。
3024
+ * 设置项的通用提交入口(下拉/数字/开关都走这里)。
2717
3025
  * 更新本地镜像 → 走 commitSetting(HTTP settings-set → config.json)→ 即时反馈。
2718
- * @param {string} key maxScanFiles|pushMethod
3026
+ * @param {string} key preCommitEnabled|pushMethod|pushGate|maxCloneFileMB|cloneConcurrency|autoPush*
2719
3027
  * @param {unknown} value 新值
2720
3028
  */
2721
3029
  setAdvanced(key, value) {
2722
- const ok = /^(maxScanFiles|maxCloneFileMB|cloneConcurrency|pushMethod|pushGate|autoPushEnabled|autoPushTriggerText|autoPushScope)$/.test(key);
3030
+ const ok = /^(preCommitEnabled|maxCloneFileMB|cloneConcurrency|pushMethod|pushGate|autoPushEnabled|autoPushTriggerText|autoPushScope)$/.test(key);
2723
3031
  if (!ok) { this.setStatus('❌ 未知设置键: ' + key); return; }
2724
- const numKeys = { maxScanFiles: 1, maxCloneFileMB: 1, cloneConcurrency: 1 };
2725
- const boolKeys = { pushGate: 1, autoPushEnabled: 1 };
3032
+ const numKeys = { maxCloneFileMB: 1, cloneConcurrency: 1 };
3033
+ const boolKeys = { pushGate: 1, autoPushEnabled: 1, preCommitEnabled: 1 };
2726
3034
  const enumKeys = { pushMethod: ['ssh', 'api', 'auto'], autoPushScope: ['session', 'all'] };
2727
3035
  let v = value;
2728
3036
  if (boolKeys[key]) v = value === true;
@@ -2819,17 +3127,22 @@ window.__ModuleLoader__.load({
2819
3127
  save: () => { void this.save(); },
2820
3128
  discard: () => this.discard(),
2821
3129
  genKey: () => { void this.genKey(); },
2822
- toggleAudit: (checked) => this.toggleAudit(checked),
2823
- // 子开关动作必须在这里暴露:页面 props 来自 inject(),漏了会让 onChange 调到 undefined
2824
- toggleInjectRequirements: (checked) => this.toggleInjectRequirements(checked),
3130
+ // 动作必须在这里暴露:页面 props 来自 inject(),漏了会让 onChange 调到 undefined
3131
+ togglePreCommit: (checked) => this.setAdvanced('preCommitEnabled', checked === true),
2825
3132
  toggleInjectSystemPrompt: (checked) => this.toggleInjectSystemPrompt(checked),
2826
- toggleAuditScanScope: (scope) => this.toggleAuditScanScope(scope),
2827
- editWeight: (key, value) => this.editWeight(key, value),
2828
3133
  setAdvanced: (key, value) => this.setAdvanced(key, value),
2829
- moveSlot: (slot, dir) => this.moveSlot(slot, dir),
2830
- toggleDisabled: (slot) => { void this.toggleDisabled(slot); },
2831
- // 统一刷新入口(参数控制刷哪部分)——设置 / 账号 / 本地仓库 / 云端 / 槽位
3134
+ // 统一刷新入口(参数控制刷哪部分)——设置 / 账号 / 本地仓库 / 云端
2832
3135
  refresh: (parts, opts) => { void this.refresh(parts, opts); },
3136
+ // §三:面板重建(切 tab 重挂载)后——①补读"没读过/已过期"的资源(幂等,不制造请求风暴)
3137
+ // ②按当前值重放显示态(R3)。两个动作都不产生重复请求。
3138
+ panelRebuilt: () => {
3139
+ void this.uiState.ensureFresh(['settings', 'account', 'npm']);
3140
+ this.uiState.markRebuilt();
3141
+ },
3142
+ // §四:某资源读取失败后的重试入口(不清空已有内容,只重读它)
3143
+ retryResource: (name) => { void this.uiState.reload(name); },
3144
+ // npm 子页「已装依赖」:按目录重读(数据归工厂,组件不再自己 fetch)
3145
+ reloadNpmPackages: (dir) => { void this.uiState.reload('npmPackages', { dir: dir || '' }); },
2833
3146
  refreshAccount: () => { void this.refresh('account'); }, // 离线读 json(启动/push后/渲染)
2834
3147
  recheckAccount: () => { void this.recheckAccount(); }, // 在线校验写 json(「重新检测」)
2835
3148
  // npm 账号:与 GitHub 账号**同一套注入与语义**(离线刷新 / 在线校验 / 名下包列表)
@@ -2847,7 +3160,7 @@ window.__ModuleLoader__.load({
2847
3160
  startScan: (path) => { void this.startScan(path); }, // 扫描按钮:独立进程后台扫描 + 逐条追加
2848
3161
  loadCloudRepos: () => { void this.refresh('cloud'); },
2849
3162
  pushLocalRepo: (path) => { void this.pushLocalRepo(path); },
2850
- commitLocalRepo: (path) => { void this.commitLocalRepo(path); }, // 本地 commit(复用提交审计)
3163
+ commitLocalRepo: (path) => { void this.commitLocalRepo(path); }, // 本地 commit(走 commitAndPush 门禁链路)
2851
3164
  cloneFlow: (repo) => this.cloneFlow(repo),
2852
3165
  requestVisSwitch: (fullName, target) => this.requestVisSwitch(fullName, target), // 弹独立确认面板(1.5.4)
2853
3166
  confirmVisSwitch: () => { void this.confirmVisSwitch(); },
@@ -2862,7 +3175,7 @@ window.__ModuleLoader__.load({
2862
3175
 
2863
3176
  const inject = ['slots'];
2864
3177
 
2865
- /* ─── 第 13/13 片 · 收尾:注册 settings.section + factory 返回(必须末片) ─────────────────── */
3178
+ /* ─── 第 14/14 片 · 收尾:注册 settings.section + factory 返回(必须末片) ─────────────────── */
2866
3179
  function apply(ctx) {
2867
3180
  // 【常驻诊断 · 前端接线失败可见化】apply 整体包一层 try/catch,把真实异常打到控制台。
2868
3181
  // 背景:cordis 只把失败的 client entry 标成 failed(页面仅显示
@@ -2900,7 +3213,11 @@ window.__ModuleLoader__.load({
2900
3213
  // 读取复用「本地仓库列表选择的路径」(localStorage dshgp-scan-path,本地面板扫描时写入);
2901
3214
  // 没选过则空 → 后端自动识别 DSH 家根。
2902
3215
  let savedPath = dshgp_localGet('dshgp-scan-path');
2903
- void controller.refreshAccount();
3216
+ // ── R2:读回早于首次渲染 ──
3217
+ // 首屏必需资源(设置/账号/npm)由状态工厂 loadAll 一次读齐;读齐前 SectionPage
3218
+ // 渲染骨架而不是"默认值当成事实"的内容。列表单独读(它自带加载态,不拖首屏)。
3219
+ // 仍然不 await:cordis apply 有激活超时预算,长 await 会让整个插件激活失败。
3220
+ void controller.uiState.loadAll({ names: controller.uiFirstPaintNames });
2904
3221
  void controller.scanLocalRepos(savedPath, false); // 只读索引(不重建,读 json)
2905
3222
  // uSES 桥:SnapshotStore 是裸 observable,用 useSyncExternalStore 自建 selector hook
2906
3223
  const useCardState = (selector) => {
@@ -2912,6 +3229,8 @@ window.__ModuleLoader__.load({
2912
3229
  function SectionPage() {
2913
3230
  const state = useCardState((s) => s);
2914
3231
  if (!state.available) return null;
3232
+ // R2 门禁:首屏必需资源未读齐 ⇒ 骨架(明确"正在读"),绝不渲染默认值冒充事实
3233
+ if (!state.uiReady) return jsx.jsx(dshgp_LoadingSkeleton, {});
2915
3234
  const props = makeProps(state);
2916
3235
  return jsx.jsx(dshgp_GitPushPage, props);
2917
3236
  }