dsh-ris-ide 1.8.1 → 1.8.3

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 (50) hide show
  1. package/README.md +2 -2
  2. package/lib/client.js +569 -98
  3. package/lib/debug/vendor/README.md +14 -0
  4. package/lib/debug/vendor/jdwp/client.js +9 -4
  5. package/lib/debug/vendor/src/jdwp/client.ts +12 -5
  6. package/lib/index.js +963 -64
  7. package/lib/redirector.js +76 -4
  8. package/lib/risd/lifecycle.js +54 -10
  9. package/lib/risd/ping.js +136 -17
  10. package/lib/risd/server.js +424 -22
  11. package/lib/risd/ui.js +218 -129
  12. package/lib/risd-client.js +4 -1
  13. package/lib/startup.js +27 -7
  14. package/package.json +2 -2
  15. package/test/client-viewer.test.mjs +268 -93
  16. package/test/clipboard.test.mjs +259 -0
  17. package/test/debug-engine.test.mjs +3 -1
  18. package/test/dsh-origin.test.mjs +4 -11
  19. package/test/dsh-window-refresh.test.mjs +166 -1
  20. package/test/harness.test.mjs +1 -1
  21. package/test/helpers/cmd.mjs +29 -0
  22. package/test/helpers/tgz.mjs +71 -0
  23. package/test/host-search.test.mjs +18 -11
  24. package/test/host-tail.test.mjs +190 -25
  25. package/test/proxy-route.test.mjs +61 -0
  26. package/test/proxy-window.test.mjs +5 -0
  27. package/test/proxy.test.mjs +40 -11
  28. package/test/proxybridge-bundle.test.mjs +1 -59
  29. package/test/redirector-bundle.test.mjs +21 -67
  30. package/test/redirector.test.mjs +71 -4
  31. package/test/risd-api.test.mjs +83 -29
  32. package/test/risd-bridge-degrade.test.mjs +3 -29
  33. package/test/risd-cli-home.test.mjs +41 -4
  34. package/test/risd-engine.test.mjs +13 -50
  35. package/test/risd-entry.test.mjs +0 -37
  36. package/test/risd-follow-start.test.mjs +102 -0
  37. package/test/risd-git.test.mjs +7 -5
  38. package/test/risd-handoff.test.mjs +6 -50
  39. package/test/risd-helpers.mjs +150 -3
  40. package/test/risd-host-p2.test.mjs +2 -30
  41. package/test/risd-lifecycle.test.mjs +203 -33
  42. package/test/risd-ping.test.mjs +77 -1
  43. package/test/risd-programs.test.mjs +4 -34
  44. package/test/risd-review-p2.test.mjs +0 -13
  45. package/test/risd-shutdown.test.mjs +5 -38
  46. package/test/risd-teardown.test.mjs +8 -27
  47. package/test/risd-ui.test.mjs +205 -14
  48. package/test/risd-write.test.mjs +2 -1
  49. package/test/startup-reconcile.test.mjs +44 -8
  50. package/test/proxy-restart.test.mjs +0 -39
package/lib/risd/ui.js CHANGED
@@ -5,7 +5,7 @@
5
5
  // Phase 2-lite follow-up: the page now has three top tabs —
6
6
  // 概览 · proxy state + running programs grouped by workspace + debug sessions
7
7
  // 代理 · the machine-wide rule table (independent of dsh: CAS save via /v1/proxy,
8
- // engine start/stop, bridge restart, proxy log tail)
8
+ // engine start/stop, one enforcement button, auto-start policy, log tail)
9
9
  // IDE · embeds the dsh IDE window when a dsh window is answering, greyed out
10
10
  // with the reason otherwise (GET /v1/dsh reads dsh-window.json)
11
11
  //
@@ -143,6 +143,8 @@ export function risdUiHtml(options) {
143
143
  .life { display:flex; align-items:center; gap:10px; padding:6px 0; font-size:13px; }
144
144
  .life b { min-width:96px; font-weight:600; }
145
145
  .life input { margin:0; }
146
+ .life-col { width:132px; display:flex; align-items:center; gap:6px; }
147
+ .life-head { padding:0 0 2px; font-size:12px; }
146
148
  .modal { position:fixed; inset:0; display:flex; align-items:center; justify-content:center; background:rgba(17,24,39,.45); z-index:50; }
147
149
  .modal[hidden] { display:none; }
148
150
  .modal-card { width:440px; max-width:calc(100% - 32px); background:#fff; border-radius:12px; padding:20px 22px; box-shadow:0 24px 48px rgba(17,24,39,.22); }
@@ -194,7 +196,7 @@ export function risdUiHtml(options) {
194
196
  <span class="pill" id="proxy-pill">未知</span>
195
197
  <span class="muted" id="proxy-detail"></span>
196
198
  <span class="grow"></span>
197
- <button id="engine-toggle" disabled>启动</button>
199
+ <button id="engine-toggle" disabled>启动引擎</button>
198
200
  </div>
199
201
  </section>
200
202
  <section>
@@ -206,24 +208,37 @@ export function risdUiHtml(options) {
206
208
  <div id="debugs"><p class="empty">加载中…</p></div>
207
209
  </section>
208
210
  <section>
209
- <h2>生命周期 <span class="sub">只配置是否跟随 dsh;所有资源强制跟随 daemon(停止 daemon 时一并停止)</span></h2>
211
+ <h2>生命周期</h2>
210
212
  <div id="lifecycle-rows">
211
- <label class="life"><b>守护进程</b><input type="checkbox" data-life="daemon.followDsh"><span class="muted">跟随 dsh:最后一个 dsh 窗口退出后,空闲 10 分钟自动退出;关掉则一直运行到手动停止</span></label>
212
- <label class="life"><b>代理引擎</b><input type="checkbox" data-life="proxy.followDsh"><span class="muted">跟随 dsh:没有 dsh 租约时拆除隧道(含系统层拦截)</span></label>
213
- <label class="life"><b>程序(JVM)</b><input type="checkbox" data-life="programs.followDsh"><span class="muted">跟随 dsh:最后一个窗口退出后停止程序</span></label>
214
- <label class="life"><b>调试会话</b><input type="checkbox" data-life="debug.followDsh"><span class="muted">跟随 dsh:最后一个窗口退出后断开调试</span></label>
213
+ <div class="life life-head"><b></b><span class="life-col">跟随 dsh 启动</span><span class="life-col">跟随 dsh 停止</span></div>
214
+ <label class="life"><b>守护进程</b>
215
+ <span class="life-col"><input type="checkbox" data-life="daemon.startWithDsh" checked disabled title="dsh 需要时按需拉起守护进程(强制,不可关)"></span>
216
+ <span class="life-col"><input type="checkbox" data-life="daemon.stopWithDsh" title="最后一个 dsh 窗口退出后,空闲 10 分钟自动退出;关掉则一直运行到手动停止"></span>
217
+ </label>
218
+ <label class="life"><b>代理引擎</b>
219
+ <span class="life-col"><input type="checkbox" data-life="proxy.startWithDsh" title="dsh 接入时启动引擎(自动启动不会弹提权框,需要 root 的桥接只在组件卡里提示)"></span>
220
+ <span class="life-col"><input type="checkbox" data-life="proxy.stopWithDsh" title="没有 dsh 租约时拆除隧道(含系统层拦截)"></span>
221
+ </label>
222
+ <label class="life"><b>程序(JVM)</b>
223
+ <span class="life-col"><input type="checkbox" data-life="programs.startWithDsh" title="dsh 接入时恢复上次 daemon 退出时仍在运行的程序"></span>
224
+ <span class="life-col"><input type="checkbox" data-life="programs.stopWithDsh" title="最后一个 dsh 窗口退出后停止程序"></span>
225
+ </label>
226
+ <label class="life"><b>调试会话</b>
227
+ <span class="life-col"><input type="checkbox" data-life="debug.startWithDsh" disabled title="调试会话没有可自动启动的对象"></span>
228
+ <span class="life-col"><input type="checkbox" data-life="debug.stopWithDsh" title="最后一个 dsh 窗口退出后断开调试"></span>
229
+ </label>
215
230
  </div>
216
231
  <div class="row" style="margin-top:10px">
232
+ <span class="muted">勾选即自动保存,不用点按钮</span>
217
233
  <span class="grow"></span>
218
234
  <span class="muted" id="lifecycle-note"></span>
219
- <button id="lifecycle-save">保存生命周期</button>
220
235
  </div>
221
236
  </section>
222
237
  </div>
223
238
 
224
239
  <div class="view" id="view-proxy" hidden>
225
240
  <section>
226
- <h2>ProxyBridge 组件 <span class="sub">系统层拦截所需;按需下载,缓存复用,不随插件打包</span></h2>
241
+ <h2>ProxyBridge 组件 <span class="sub">系统层拦截所需;按需下载,缓存复用</span></h2>
227
242
  <div class="row">
228
243
  <span id="bridge-pill" class="pill off">未知</span>
229
244
  <span class="muted grow" id="bridge-detail"></span>
@@ -234,7 +249,7 @@ export function risdUiHtml(options) {
234
249
  <div class="row" style="margin-top:8px">
235
250
  <span id="bridge-health-pill" class="pill off">未检查</span>
236
251
  <span class="muted grow" id="bridge-health-text"></span>
237
- <button id="bridge-health-elevate" hidden>提权启动</button>
252
+ <button id="bridge-fix" hidden>启动系统层拦截(可能提权)</button>
238
253
  <button id="bridge-health-stop" hidden>停止拦截</button>
239
254
  </div>
240
255
  <div id="bridge-elevate-note" hidden></div>
@@ -245,18 +260,18 @@ export function risdUiHtml(options) {
245
260
  <div class="muted" id="bridge-hint" style="margin-top:6px"></div>
246
261
  </section>
247
262
  <section>
248
- <h2>规则表 <span class="sub">全局规则:按机器生效、不区分工作区;保存经 daemon 的 CAS,多窗口同时改不会互相覆盖</span></h2>
263
+ <h2>规则表 <span class="sub">全局规则:按机器生效、不区分工作区</span></h2>
249
264
  <div class="row" style="margin-bottom:10px">
250
265
  <span class="pill off" id="proxy-engine-pill">未知</span>
251
266
  <span class="grow"></span>
252
- <button id="proxy-engine-toggle" disabled>启动</button>
253
267
  <span class="muted" id="proxy-revision"></span>
268
+ <button id="proxy-engine-toggle" disabled>启动引擎</button>
254
269
  </div>
255
270
  <div class="row" style="margin-bottom:10px">
256
271
  <label class="muted">SOCKS 主机</label><input id="proxy-socks-host" class="narrow" placeholder="host">
257
272
  <label class="muted">端口</label><input id="proxy-socks-port" class="narrow" placeholder="1080">
258
- <span id="proxy-ping" class="pill off" role="status" title="">检测中…</span>
259
273
  <label class="muted">监听端口</label><input id="proxy-listen" class="narrow" placeholder="11081">
274
+ <span id="proxy-ping" class="pill off" role="status" title="">检测中…</span>
260
275
  </div>
261
276
  <div id="proxy-banner"></div>
262
277
  <table>
@@ -268,7 +283,6 @@ export function risdUiHtml(options) {
268
283
  <div class="row" style="margin-top:10px">
269
284
  <button id="proxy-add">+ 添加规则</button>
270
285
  <span class="grow"></span>
271
- <button id="bridge-restart" hidden>重启系统层拦截(可能提权)</button>
272
286
  <button id="proxy-log-toggle">代理日志</button>
273
287
  </div>
274
288
  <pre id="proxy-log" hidden></pre>
@@ -313,7 +327,7 @@ export function risdUiHtml(options) {
313
327
  var PAGE_INSTANCE = ${uiInstance};
314
328
  var initialCwd = '';
315
329
  try { initialCwd = new URLSearchParams(location.search).get('cwd') || ''; } catch { /* no URL API */ }
316
- var state = { tab: 'overview', cwd: initialCwd || localStorage.getItem('risd.cwd') || '', view: null, logOn: false, logTimer: null, pollTimer: null, pingTimer: null, pingSeq: 0, healthTimer: null, elevateNote: null, dsh: null, dshAvailable: null, lifecycleDirty: false, proxyDirty: false, proxyRunning: false, stopBusy: false, elevateBusy: false, summary: { proxyRunning: false, programs: 0, debugs: 0 }, staleDismissed: {},
330
+ var state = { tab: 'overview', cwd: initialCwd || localStorage.getItem('risd.cwd') || '', view: null, logOn: false, logTimer: null, pollTimer: null, pingTimer: null, pingSeq: 0, healthTimer: null, elevateNote: null, dsh: null, dshAvailable: null, lifecycleDirty: false, proxyDirty: false, proxyRunning: false, stopBusy: false, fixBusy: false, bridgeStaleReason: '', bridgeMissing: [], bridgeEngineRunning: false, bridgeStray: false, summary: { proxyRunning: false, programs: 0, debugs: 0 }, staleDismissed: {},
317
331
  };
318
332
  // The drift banner's current message and the message the user closed: a closed
319
333
  // hint must not pop back every 5 s, but a NEW kind of drift still has to warn.
@@ -517,6 +531,9 @@ export function risdUiHtml(options) {
517
531
  function lifecycleFromBoxes() {
518
532
  var policy = { daemon: {}, proxy: {}, programs: {}, debug: {} };
519
533
  document.querySelectorAll('#lifecycle-rows input[data-life]').forEach(function (box) {
534
+ // A disabled half is not part of the policy (the daemon start is forced, the
535
+ // debug start does not exist) — sending it would be rejected as unknown.
536
+ if (box.disabled === true) return;
520
537
  var parts = box.getAttribute('data-life').split('.');
521
538
  if (policy[parts[0]] === undefined) policy[parts[0]] = {};
522
539
  policy[parts[0]][parts[1]] = box.checked;
@@ -524,15 +541,49 @@ export function risdUiHtml(options) {
524
541
  return policy;
525
542
  }
526
543
 
527
- function saveLifecycle() {
544
+ // 勾选即保存(没有保存按钮):一次勾选就是一次配置修改,不该再多一步确认。
545
+ // 300 ms 防抖合并连点;请求在飞时只记一个「还有一次」,避免两个 POST 互相覆盖。
546
+ var lifecycleTimer = null;
547
+ var lifecycleSave = null;
548
+ var lifecycleQueued = false;
549
+
550
+ function scheduleLifecycleSave() {
551
+ // Mark it dirty right away: the 4 s refresh must not refill the boxes from the
552
+ // daemon while the save is still being debounced (review C-P2-3).
553
+ state.lifecycleDirty = true;
554
+ if (lifecycleTimer !== null) clearTimeout(lifecycleTimer);
555
+ lifecycleTimer = setTimeout(function () { lifecycleTimer = null; saveLifecycle(true); }, 300);
556
+ }
557
+
558
+ function saveLifecycle(auto) {
559
+ if (lifecycleSave !== null) { lifecycleQueued = true; return lifecycleSave; }
528
560
  var policy = lifecycleFromBoxes();
529
- return api('/v1/config', { method: 'POST', body: { lifecycle: policy } }).then(function (body) {
561
+ var run = api('/v1/config', { method: 'POST', body: { lifecycle: policy } }).then(function (body) {
530
562
  state.lifecycle = body.lifecycle || policy;
531
- state.lifecycleDirty = false;
532
- el('lifecycle-note').textContent = '已保存';
533
- setTimeout(function () { if (el('lifecycle-note')) el('lifecycle-note').textContent = ''; }, 2500);
534
- return loadLifecycle();
535
- }).catch(function (error) { el('lifecycle-note').textContent = '保存失败:' + error.message; });
563
+ // Another toggle landed while this POST was in flight: keep the form as the
564
+ // user left it (refilling from the daemon would undo that toggle) and let the
565
+ // queued save carry it; dirty stays set so the 4 s refresh leaves it alone.
566
+ var queued = lifecycleQueued === true;
567
+ if (queued !== true) state.lifecycleDirty = false;
568
+ return (queued === true ? Promise.resolve() : loadLifecycle()).then(function () {
569
+ el('lifecycle-note').textContent = auto === true ? '已自动保存' : '已保存';
570
+ setTimeout(function () { if (el('lifecycle-note')) el('lifecycle-note').textContent = ''; }, 2500);
571
+ });
572
+ }).catch(function (error) {
573
+ // Keep lifecycleDirty so the refresh loop cannot silently revert the toggle;
574
+ // the next click retries the whole form.
575
+ el('lifecycle-note').textContent = '保存失败:' + error.message + '(再勾一次重试)';
576
+ });
577
+ lifecycleSave = run.then(function (value) {
578
+ lifecycleSave = null;
579
+ if (lifecycleQueued === true) { lifecycleQueued = false; scheduleLifecycleSave(); }
580
+ return value;
581
+ }, function (error) {
582
+ lifecycleSave = null;
583
+ if (lifecycleQueued === true) { lifecycleQueued = false; scheduleLifecycleSave(); }
584
+ throw error;
585
+ });
586
+ return lifecycleSave;
536
587
  }
537
588
 
538
589
  function refreshOverview() {
@@ -600,17 +651,14 @@ export function risdUiHtml(options) {
600
651
  }
601
652
 
602
653
  /**
603
- * The restart button is noise when nothing is stale, and the whole point when
604
- * something is: show it only for a failed/incomplete reload and put the reason in
605
- * the tooltip (a click costs a UAC prompt on Windows and sudo on this side).
654
+ * Remember whether the last save left a stale enforcement behind. The reason is
655
+ * only trusted when it names a real failure; a normal "reloading in the
656
+ * background" note must not light the button up.
606
657
  */
607
658
  function setBridgeStale(reason) {
608
659
  var stale = /未重载|旧规则|需要提权|未能重载|未重启|未能停止/.test(String(reason || ''));
609
- var button = el('bridge-restart');
610
- button.hidden = !stale;
611
- button.title = stale
612
- ? '为什么要重启:' + reason + '(点一下会停止系统层拦截并按当前规则表重新启动;Windows 会弹一次 UAC,本侧需要 sudo)'
613
- : '';
660
+ state.bridgeStaleReason = stale ? String(reason) : '';
661
+ paintBridgeFix();
614
662
  }
615
663
 
616
664
  function renderProxyTab(view) {
@@ -686,17 +734,11 @@ export function risdUiHtml(options) {
686
734
  }
687
735
 
688
736
  /** A complete, enabled row is what makes starting the engine worth doing. */
689
- function hasActionableRule(view) {
690
- return (view && view.rules || []).some(function (rule) {
691
- return rule.enabled !== false && String(rule.program || '').trim() !== '' &&
692
- String(rule.hosts || '').trim() !== '' && portSpecOk(rule.ports);
693
- });
694
- }
695
-
696
737
  /**
697
- * 「勾选的配置不为空、有效就自动保存并启动」:editing is the save. A partially
698
- * filled row is not an error the user must dismiss, so the banner explains what is
699
- * still missing and the save happens once it is complete.
738
+ * 「勾选的配置不为空、有效就自动保存」:editing is the save. A partially filled row
739
+ * is not an error the user must dismiss, so the banner explains what is still
740
+ * missing and the save happens once it is complete. Saving never starts the engine
741
+ * (m13920) — only the button, or the dsh-start policy, does.
700
742
  */
701
743
  var autoSaveTimer = null;
702
744
  // Rapid edits can outrun a POST: the second write would carry the revision of the
@@ -722,35 +764,6 @@ export function risdUiHtml(options) {
722
764
  saveRules({ auto: true });
723
765
  }
724
766
 
725
- /**
726
- * After a successful save, bring the tunnel up — that is the 「并启动」 half. A
727
- * bridge that needs elevation is reported as a note (the restart button appears
728
- * from setBridgeStale), never as a silent failure.
729
- */
730
- function maybeStartProxy(view) {
731
- if (!view || view.running === true || hasActionableRule(view) === false) return Promise.resolve(null);
732
- var version = state.editVersion || 0;
733
- el('proxy-banner').innerHTML = banner('ok', '规则已保存,正在启动代理…');
734
- return api('/v1/action', { method: 'POST', body: { action: 'start', cwd: state.cwd } }).then(function (response) {
735
- var result = (response && response.result) || {};
736
- var redirector = result.redirector || {};
737
- var skipped = Array.isArray(redirector.skipped) ? redirector.skipped : [];
738
- var note = skipped.length > 0
739
- ? '系统层拦截需要提权:' + skipped.map(function (item) { return item.side + ':' + item.reason; }).join(';')
740
- : (typeof result.reloadNote === 'string' ? result.reloadNote : '');
741
- state.lastReloadNote = note;
742
- if ((state.editVersion || 0) !== version) return null;
743
- return loadProxyTab().then(function () {
744
- el('proxy-banner').innerHTML = note
745
- ? banner('warn', '规则已保存;' + note + '(可点「重启系统层拦截」重试)')
746
- : banner('ok', '规则已保存并已启动代理');
747
- });
748
- }).catch(function (error) {
749
- el('proxy-banner').innerHTML = banner('warn', '规则已保存,但代理启动失败:' + error.message);
750
- return null;
751
- });
752
- }
753
-
754
767
  function loadProxyTab() {
755
768
  // The rule table is machine-wide: no workspace picker. The workspace only tags
756
769
  // rows for bookkeeping, so the daemon falls back to its own home when omitted.
@@ -810,10 +823,17 @@ export function risdUiHtml(options) {
810
823
  state.proxyDirty = false;
811
824
  // Reload first, then show the outcome: loadProxyTab clears the banner itself.
812
825
  return loadProxyTab().then(function () {
813
- el('proxy-banner').innerHTML = banner(result.reloadNote ? 'warn' : 'ok',
826
+ // Saving is not starting (m13920): editing the table used to bring the engine
827
+ // up as a side effect, so 「保存即启动」 came as a surprise and the policy
828
+ // checkbox was not the only way to end up with a running engine. A save now
829
+ // only reloads an engine that is already up (switchEnforcement) and names the
830
+ // button that starts one.
831
+ var engineDown = !state.view || state.view.running !== true;
832
+ var hint = engineDown ? ';引擎未启动(保存不会启动它,点「启动」或组件区的「启动系统层拦截」)' : '';
833
+ el('proxy-banner').innerHTML = banner(result.reloadNote ? 'warn' : (engineDown ? 'warn' : 'ok'),
814
834
  (auto ? '已自动保存' : '已保存') + '(revision ' + result.revision + ')' +
815
- (result.reloadNote ? ' · ' + result.reloadNote : ''));
816
- return maybeStartProxy(state.view);
835
+ (result.reloadNote ? ' · ' + result.reloadNote : '') + hint);
836
+ return null;
817
837
  });
818
838
  });
819
839
  saveInFlight = run.then(function (value) {
@@ -982,7 +1002,6 @@ export function risdUiHtml(options) {
982
1002
  var sides = (health && health.sides) || {}
983
1003
  var interception = (health && health.interception) || { linux: false, windows: false }
984
1004
  var names = { linux: 'Linux', windows: 'Windows' }
985
- var elevate = el('bridge-health-elevate')
986
1005
  stop.hidden = !isStray
987
1006
  // A request in flight owns its button: the 10 s health poll must not re-enable
988
1007
  // it, or a second click fires another stop/elevation while the first is still
@@ -991,11 +1010,10 @@ export function risdUiHtml(options) {
991
1010
  var missingNow = ['linux', 'windows'].filter(function (key) {
992
1011
  return sides[key] && sides[key].applicable !== false && interception[key] !== true
993
1012
  })
994
- if (elevate) {
995
- elevate.hidden = !(engineRunning === true && isStray !== true && missingNow.length > 0)
996
- elevate.disabled = state.elevateBusy === true
997
- if (state.elevateBusy !== true) elevate.textContent = '提权启动'
998
- }
1013
+ state.bridgeEngineRunning = engineRunning === true
1014
+ state.bridgeStray = isStray
1015
+ state.bridgeMissing = missingNow
1016
+ paintBridgeFix()
999
1017
  var lines = []
1000
1018
  function notes(message) { if (message) lines.push(message) }
1001
1019
  function planNotes() {
@@ -1012,7 +1030,7 @@ export function risdUiHtml(options) {
1012
1030
  })
1013
1031
  if (missing.length === 0) return
1014
1032
  var command = commands[0] || (degrade && degrade.command)
1015
- if (command) notes(missing.map(function (key) { return names[key] }).join('、') + ' 侧系统层拦截需要 root:点「提权启动」弹终端输密码,或自行打开终端执行:' + command)
1033
+ if (command) notes(missing.map(function (key) { return names[key] }).join('、') + ' 侧系统层拦截需要 root:点「启动系统层拦截」弹终端输密码,或自行打开终端执行:' + command)
1016
1034
  if (degrade && degrade.jvmArgs) {
1017
1035
  notes('降级可用(不经系统层拦截):')
1018
1036
  notes(' JVM 程序:' + degrade.jvmArgs.join(' '))
@@ -1069,19 +1087,46 @@ export function risdUiHtml(options) {
1069
1087
  }
1070
1088
  renderElevateNote(health)
1071
1089
  }
1090
+ /**
1091
+ * The component card owns ONE recovery button (m13910). After a failed reload the
1092
+ * old design showed 「重启系统层拦截」 next to 「提权启动」, but revoke() had already
1093
+ * stopped the bridge, so both did stop+start and both asked for the same password:
1094
+ * two buttons for one action. Visibility is exclusive now — the stale reload wins
1095
+ * (it needs the stop first), otherwise a missing side means 「启动」.
1096
+ */
1097
+ function paintBridgeFix() {
1098
+ var button = el('bridge-fix')
1099
+ if (!button) return
1100
+ var missing = state.bridgeMissing || []
1101
+ var stale = state.bridgeStaleReason !== ''
1102
+ var show = state.bridgeEngineRunning === true && state.bridgeStray !== true && (stale || missing.length > 0)
1103
+ button.hidden = !show
1104
+ button.disabled = state.fixBusy === true
1105
+ if (state.fixBusy === true) { button.textContent = stale ? '重启中…' : '启动中…'; return }
1106
+ button.textContent = stale ? '重启系统层拦截(可能提权)' : '启动系统层拦截(可能提权)'
1107
+ button.title = stale
1108
+ ? '为什么要重启:' + state.bridgeStaleReason + '(点一下会停止系统层拦截并按当前规则表重新启动;Windows 会弹一次 UAC,本侧可能需要 sudo)'
1109
+ : missing.map(function (key) { return key === 'linux' ? 'Linux' : 'Windows' }).join('、') +
1110
+ ' 侧系统层拦截未启动(点一下会尝试提权启动;Windows 会弹一次 UAC,本侧可能需要 sudo)'
1111
+ }
1112
+
1072
1113
  // m12606: ask for elevation from the page. sudo is tried first (passwordless),
1073
1114
  // then pkexec (a real polkit dialog where the desktop has an agent); when neither
1074
1115
  // can, the banner names the command from 说明 so it can be pasted into a terminal.
1075
- function elevateBridge() {
1076
- var button = el('bridge-health-elevate')
1077
- if (state.elevateBusy === true) return
1078
- state.elevateBusy = true
1079
- if (button) { button.disabled = true; button.textContent = '提权中…' }
1116
+ function fixBridge() {
1117
+ var button = el('bridge-fix')
1118
+ if (state.fixBusy === true) return
1119
+ state.fixBusy = true
1120
+ // A stale reload must stop the old profile before starting the new one; a
1121
+ // purely missing side is enough with a plain start. Only this click sets interactive.
1122
+ var action = state.bridgeStaleReason !== '' ? 'redirector-restart' : 'start'
1123
+ paintBridgeFix()
1080
1124
  var outcome = { kind: 'warn', text: '' }
1081
- api('/v1/action', { method: 'POST', body: { action: 'start', cwd: state.cwd } }).then(function (response) {
1082
- // /v1/action answers {ok, action, result}; the payload is one level down.
1125
+ api('/v1/action', { method: 'POST', body: { action: action, cwd: state.cwd, interactive: true } }).then(function (response) {
1126
+ // /v1/action answers {ok, action, result}; the payload is one level down for
1127
+ // the start action, while redirector-restart answers {stopped,started,skipped}.
1083
1128
  var result = (response && response.result) || {};
1084
- var redirector = result.redirector || {};
1129
+ var redirector = result.redirector || result;
1085
1130
  var started = Array.isArray(redirector.started) ? redirector.started : [];
1086
1131
  var skipped = Array.isArray(redirector.skipped) ? redirector.skipped : [];
1087
1132
  if (started.length > 0) {
@@ -1109,8 +1154,9 @@ export function risdUiHtml(options) {
1109
1154
  }).catch(function (error) {
1110
1155
  outcome = { kind: 'err', text: '提权启动失败:' + error.message }
1111
1156
  }).then(function () {
1112
- state.elevateBusy = false
1113
- if (button) { button.disabled = false; button.textContent = '提权启动' }
1157
+ state.fixBusy = false
1158
+ if (outcome.kind === 'ok') state.bridgeStaleReason = ''
1159
+ paintBridgeFix()
1114
1160
  // The note belongs to the component card, not the rule-table banner (m12923):
1115
1161
  // a terminal may still be waiting for a password, so the message has to live
1116
1162
  // next to the component it is about.
@@ -1232,16 +1278,24 @@ export function risdUiHtml(options) {
1232
1278
  if (result === null || result === undefined) { cls += ' busy'; text = '检测中…'; }
1233
1279
  // 没填 SOCKS 地址不是故障:灰色「未配置」,别用红点吓人(review C3-P2-9)。
1234
1280
  else if (result.configured === false) { cls += ' off'; text = '未配置'; }
1235
- else if (result.ok === true) { cls += ' on'; text = '连通 ' + ((result.ms || 0) + ' ms'); }
1236
- else if (result.socks === true) { cls += ' warn'; text = '需认证'; }
1281
+ else if (result.ok === true && result.usable === true) { cls += ' on'; text = '可用 ' + ((result.ms || 0) + ' ms'); }
1282
+ // m03429: nothing concrete to dial — the greeting is all the evidence there is.
1283
+ else if (result.ok === true) { cls += ' on'; text = '握手正常'; }
1284
+ else if (result.socks === true) { cls += ' warn'; text = /认证/.test(String(result.error || '')) ? '需认证' : '无法转发'; }
1237
1285
  else { cls += ' err'; text = '无法连接'; }
1286
+ var target = result === null || result === undefined ? null : result.target;
1287
+ var targetText = target === null || target === undefined ? '' : ' → ' + target.host + ':' + target.port;
1238
1288
  chip.className = cls;
1239
1289
  chip.textContent = text;
1240
1290
  chip.title = result === null || result === undefined
1241
1291
  ? '正在检测代理服务器连通性…'
1242
1292
  : (result.configured === false
1243
1293
  ? '还没有填写代理服务器地址'
1244
- : (result.ok === true ? '代理服务器可达(' + (result.host || '') + ':' + (result.port || '') + ',' + result.at + ')' : String(result.error || '连接失败')));
1294
+ : (result.ok === true
1295
+ ? (result.usable === true
1296
+ ? '代理服务器可用(' + (result.host || '') + ':' + (result.port || '') + targetText + ',' + result.ms + ' ms)'
1297
+ : 'SOCKS5 握手正常(' + (result.host || '') + ':' + (result.port || '') + ');配置里没有可验证的转发目标,只确认了协议')
1298
+ : String(result.error || '连接失败')));
1245
1299
  }
1246
1300
  function refreshPing() {
1247
1301
  var host = el('proxy-socks-host').value.trim();
@@ -1302,14 +1356,25 @@ export function risdUiHtml(options) {
1302
1356
  var parts = String(cwd || '').split('/').filter(Boolean);
1303
1357
  return parts.length > 0 ? parts[parts.length - 1] : String(cwd || '');
1304
1358
  }
1305
- /** A short, stable label: the folder name, with the parent when two collide. */
1306
- function workspaceLabel(cwd, windows) {
1359
+ /** Folder-name label (parent folder when two collide) — the fallback for a host
1360
+ * that has no workspace registry to give us the sidebar title. */
1361
+ function workspacePathLabel(cwd, windows) {
1307
1362
  var base = workspaceBase(cwd);
1308
1363
  var same = windows.filter(function (win) { return workspaceBase(win.cwd) === base; }).length;
1309
1364
  if (same <= 1) return base || '(未知工作区)';
1310
1365
  var parts = String(cwd || '').split('/').filter(Boolean);
1311
1366
  return parts.slice(-2).join('/');
1312
1367
  }
1368
+ /**
1369
+ * The dsh sidebar's label, when the plugin could resolve one (m13800): a rename
1370
+ * changes the title and nothing else, so the panel must re-label the SAME row.
1371
+ * Missing title (older host) falls back to the folder name.
1372
+ */
1373
+ function workspaceLabel(win, windows) {
1374
+ var title = typeof win.title === 'string' ? win.title : '';
1375
+ if (title !== '') return title;
1376
+ return workspacePathLabel(win.cwd, windows);
1377
+ }
1313
1378
 
1314
1379
  function focusIdeFrame() {
1315
1380
  var frame = el('ide-frame');
@@ -1317,7 +1382,12 @@ export function risdUiHtml(options) {
1317
1382
  }
1318
1383
 
1319
1384
  function selectIdeWindow(windows, cwd) {
1320
- var win = windows.filter(function (row) { return (row.cwd || '') === cwd; })[0] || windows[0];
1385
+ var win = windows.filter(function (row) { return (row.cwd || '') === cwd; })[0];
1386
+ // The pane may show a workspace dsh no longer mirrors (the user opened it
1387
+ // earlier and dsh has since switched): keep that row instead of jumping to
1388
+ // whatever dsh switched to (m04873).
1389
+ if (!win && cwd) win = { cwd: cwd, live: false, active: false };
1390
+ if (!win) win = windows[0];
1321
1391
  if (!win) return;
1322
1392
  var key = win.cwd || '';
1323
1393
  if (win.live !== false) delete state.staleDismissed[key];
@@ -1369,13 +1439,38 @@ export function risdUiHtml(options) {
1369
1439
  }
1370
1440
  }
1371
1441
 
1442
+ /**
1443
+ * Which workspace the IDE pane shows.
1444
+ *
1445
+ * This page keeps its OWN choice (state.cwd, persisted as risd.cwd): dsh
1446
+ * switching workspace must not move the IDE embedded here, and this page must
1447
+ * not move the dsh sidebar console either (m04873). So when the remembered
1448
+ * workspace is no longer in dsh's mirror the pane KEEPS it instead of falling
1449
+ * back to whatever dsh switched to — the iframe URL does not change, so the
1450
+ * embedded document (and its unsaved edits) survives.
1451
+ * @param {Array<object>} windows - rows from /v1/dsh.
1452
+ * @returns {object|undefined} the row to render, or a cwd-only stub.
1453
+ */
1454
+ function pickIdeWindow(windows) {
1455
+ var preferred = state.cwd;
1456
+ if (preferred) {
1457
+ var match = windows.filter(function (win) { return (win.cwd || '') === preferred; })[0];
1458
+ if (match) return match;
1459
+ return { cwd: preferred, live: false, active: false };
1460
+ }
1461
+ return windows.filter(function (win) { return win.live !== false; })[0] || windows[0];
1462
+ }
1463
+
1372
1464
  function renderIde(windows, current) {
1373
1465
  var selected = current || windows[0];
1374
1466
  el('ide-ws-list').innerHTML = windows.map(function (win) {
1375
- var label = workspaceLabel(win.cwd, windows);
1467
+ var label = workspaceLabel(win, windows);
1376
1468
  // Non-live entries stay clickable: dsh may still have the session, the iframe
1377
1469
  // shows the real result (m08268).
1378
- var suffix = win.live === false ? '(未活跃)' : '';
1470
+ // Two different hints: "未活跃" is a remembered window nobody touched for a
1471
+ // while, "无会话" is a workspace with no live dsh session at all. Both stay
1472
+ // clickable — the window page boots on the cwd when the session is gone (m00186).
1473
+ var suffix = win.live === false ? '(未活跃)' : (win.active === false ? '(无会话)' : '');
1379
1474
  return '<li><button type="button" data-cwd="' + esc(win.cwd || '') + '" title="' + esc((win.cwd || '') + (suffix ? ' ' + suffix : '')) + '">' +
1380
1475
  esc(label + suffix) + '</button></li>';
1381
1476
  }).join('');
@@ -1402,8 +1497,11 @@ export function risdUiHtml(options) {
1402
1497
  el('ide-ws-list').innerHTML = '';
1403
1498
  var frame = el('ide-frame');
1404
1499
  if (frame) frame.hidden = true;
1405
- ideMessage('warn', 'IDE 不可用:' + (body.reason || 'dsh 未运行'),
1406
- 'IDE 界面由 dsh 提供;启动 dsh 并打开一次 RIS-IDE 面板后,这里会自动可用。');
1500
+ var note = 'IDE 界面由 dsh 提供;启动 dsh(工作区在 dsh 侧栏里)后,这里会自动可用。';
1501
+ // dsh may be alive and yet unreachable (still starting, no origin yet): naming the
1502
+ // workspaces it did report separates that from "dsh is not running" (m00186).
1503
+ if (body.knownWorkspaces > 0) note += '(已发现 ' + body.knownWorkspaces + ' 个 dsh 工作区)';
1504
+ ideMessage('warn', 'IDE 不可用:' + (body.reason || 'dsh 未运行'), note);
1407
1505
  applySide();
1408
1506
  }
1409
1507
 
@@ -1420,9 +1518,7 @@ export function risdUiHtml(options) {
1420
1518
  ideUnavailable(body);
1421
1519
  return;
1422
1520
  }
1423
- var preferred = state.cwd;
1424
- var selected = windows.filter(function (win) { return (win.cwd || '') === preferred; })[0] ||
1425
- windows.filter(function (win) { return win.live !== false; })[0] || windows[0];
1521
+ var selected = pickIdeWindow(windows);
1426
1522
  renderIde(windows, selected);
1427
1523
  }).catch(function (error) {
1428
1524
  ideMessage('err', 'IDE 状态读取失败:' + error.message);
@@ -1443,9 +1539,7 @@ export function risdUiHtml(options) {
1443
1539
  ideUnavailable(body);
1444
1540
  return;
1445
1541
  }
1446
- var preferred = state.cwd;
1447
- var selected = windows.filter(function (win) { return (win.cwd || '') === preferred; })[0] ||
1448
- windows.filter(function (win) { return win.live !== false; })[0] || windows[0];
1542
+ var selected = pickIdeWindow(windows);
1449
1543
  renderIde(windows, selected);
1450
1544
  }).catch(function (error) {
1451
1545
  ideMessage('err', 'IDE 状态读取失败:' + error.message);
@@ -1455,8 +1549,12 @@ export function risdUiHtml(options) {
1455
1549
  function dshWindowSignature(body) {
1456
1550
  // Liveness is part of the rendering state: a window going 未活跃 must repaint
1457
1551
  // the hint bar even though cwd/sessionId did not change.
1552
+ // The title belongs to the signature: a rename must repaint the labels even
1553
+ // though cwd and sessionId did not move (m13800).
1458
1554
  return (body.windows || []).map(function (win) {
1459
- return (win.cwd || '') + '|' + (win.sessionId || '') + '|' + (win.live === false ? 'stale' : 'live');
1555
+ return (win.cwd || '') + '|' + (win.sessionId || '') + '|' + (win.live === false ? 'stale' : 'live') +
1556
+ '|' + (typeof win.title === 'string' ? win.title : '') +
1557
+ '|' + (win.active === false ? 'idle' : 'active');
1460
1558
  }).sort().join('\\n');
1461
1559
  }
1462
1560
 
@@ -1588,11 +1686,14 @@ export function risdUiHtml(options) {
1588
1686
  }
1589
1687
  button.removeAttribute('aria-busy');
1590
1688
  button.disabled = false;
1591
- button.textContent = running ? '停止' : '启动';
1689
+ button.textContent = running ? '停止' : '启动引擎';
1592
1690
  button.className = running ? 'danger' : '';
1691
+ // m05590: starting the engine never asks for a password. The system-layer
1692
+ // component is a separate click (bridge-fix), so a dialog can only appear
1693
+ // after the user asked for it by name.
1593
1694
  button.title = running
1594
1695
  ? '停止引擎、系统层拦截与 git 代理'
1595
- : '按当前规则表启动代理引擎(系统层拦截可能需要提权)';
1696
+ : '按当前规则表启动代理引擎(不需要 root;系统层拦截起来后再单独点「启动系统层拦截」)';
1596
1697
  });
1597
1698
  }
1598
1699
  function toggleProxyEngine() {
@@ -1604,7 +1705,11 @@ export function risdUiHtml(options) {
1604
1705
  engineBusy = true;
1605
1706
  engineBusyAction = action;
1606
1707
  paintEngineButtons();
1607
- api('/v1/action', { method: 'POST', body: { action: action, cwd: state.cwd } })
1708
+ // m05590: this click starts the ENGINE only and therefore never asks for a
1709
+ // password. Elevation lives on the separate 「启动系统层拦截」button (fixBridge),
1710
+ // so no dialog can appear as a side effect of starting or stopping the engine.
1711
+ var body = { action: action, cwd: state.cwd };
1712
+ api('/v1/action', { method: 'POST', body: body })
1608
1713
  .then(function (response) {
1609
1714
  var result = (response && response.result) || {};
1610
1715
  var redirector = result.redirector || {};
@@ -1613,7 +1718,7 @@ export function risdUiHtml(options) {
1613
1718
  paintEngineButtons();
1614
1719
  // Write the elevation warning AFTER the refresh: loadProxyTab empties
1615
1720
  // #proxy-banner, so a message written before it vanished in the same frame
1616
- // (评审 20261109-2326 客户端 P2). maybeStartProxy already orders it so.
1721
+ // (评审 20261109-2326 客户端 P2).
1617
1722
  // A stop that the OS refused (root-owned CLI) or that lost a race with
1618
1723
  // an in-flight start must not look like a clean stop (review B-P1-2/B-P1-5).
1619
1724
  var stopBlocked = action === 'stop' && redirector.stopped === false
@@ -1640,11 +1745,10 @@ export function risdUiHtml(options) {
1640
1745
  el('engine-toggle').onclick = toggleProxyEngine;
1641
1746
  el('proxy-engine-toggle').onclick = toggleProxyEngine;
1642
1747
  el('bridge-health-stop').onclick = stopStrayBridge;
1643
- el('bridge-health-elevate').onclick = elevateBridge;
1644
- el('lifecycle-save').onclick = saveLifecycle;
1748
+ el('bridge-fix').onclick = fixBridge;
1645
1749
  // Any toggle means "this form is mine now": the 4 s refresh stops refilling it
1646
- // until the save succeeds (review C-P2-3).
1647
- el('lifecycle-rows').addEventListener('change', function () { state.lifecycleDirty = true; });
1750
+ // until the save succeeds (review C-P2-3). Toggling is the save (m13960).
1751
+ el('lifecycle-rows').addEventListener('change', scheduleLifecycleSave);
1648
1752
 
1649
1753
  // Re-probe while the user edits host/port: 800 ms after the last keystroke, and
1650
1754
  // only on the proxy tab (the inputs are hidden elsewhere).
@@ -1671,21 +1775,6 @@ export function risdUiHtml(options) {
1671
1775
  renderProxyTab(Object.assign({}, state.view || {}, { rules: rules }));
1672
1776
  scheduleProxySave();
1673
1777
  };
1674
- el('bridge-restart').onclick = function () {
1675
- api('/v1/action', { method: 'POST', body: { action: 'redirector-restart', cwd: state.cwd } })
1676
- .then(function (response) {
1677
- // The action result lives under result: reading response.started always
1678
- // found nothing and reported "需要提权" even after a successful restart
1679
- // (review C-P1-3).
1680
- var result = (response && response.result) || {};
1681
- var skipped = Array.isArray(result.skipped) ? result.skipped : [];
1682
- var started = Array.isArray(result.started) ? result.started : [];
1683
- var text = started.length > 0
1684
- ? '已按新规则重启(' + started.join(',') + ')'
1685
- : '需要提权:' + JSON.stringify(skipped.length > 0 ? skipped : (result.stopped || {}));
1686
- el('proxy-banner').innerHTML = banner(started.length > 0 ? 'ok' : 'warn', text);
1687
- }).catch(function (error) { el('proxy-banner').innerHTML = banner('err', error.message); });
1688
- };
1689
1778
  el('bridge-download').onclick = downloadBundle;
1690
1779
  el('bridge-upload').onclick = function () { el('bridge-file').click(); };
1691
1780
  el('bridge-file').onchange = function (event) {