dsh-ris-ide 1.8.1 → 1.8.2
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.
- package/README.md +2 -2
- package/lib/client.js +311 -72
- package/lib/debug/vendor/README.md +14 -0
- package/lib/debug/vendor/jdwp/client.js +9 -4
- package/lib/debug/vendor/src/jdwp/client.ts +12 -5
- package/lib/index.js +794 -48
- package/lib/redirector.js +42 -2
- package/lib/risd/lifecycle.js +9 -3
- package/lib/risd/server.js +308 -13
- package/lib/risd/ui.js +149 -112
- package/lib/risd-client.js +4 -1
- package/lib/startup.js +27 -7
- package/package.json +2 -2
- package/test/client-viewer.test.mjs +188 -95
- package/test/clipboard.test.mjs +259 -0
- package/test/debug-engine.test.mjs +3 -1
- package/test/dsh-origin.test.mjs +4 -11
- package/test/dsh-window-refresh.test.mjs +166 -1
- package/test/harness.test.mjs +1 -1
- package/test/helpers/cmd.mjs +29 -0
- package/test/helpers/tgz.mjs +71 -0
- package/test/host-search.test.mjs +18 -11
- package/test/host-tail.test.mjs +119 -24
- package/test/proxy-route.test.mjs +61 -0
- package/test/proxy-window.test.mjs +5 -0
- package/test/proxy.test.mjs +13 -1
- package/test/proxybridge-bundle.test.mjs +1 -59
- package/test/redirector-bundle.test.mjs +21 -67
- package/test/redirector.test.mjs +41 -4
- package/test/risd-api.test.mjs +81 -28
- package/test/risd-bridge-degrade.test.mjs +3 -29
- package/test/risd-engine.test.mjs +13 -50
- package/test/risd-entry.test.mjs +0 -37
- package/test/risd-follow-start.test.mjs +101 -0
- package/test/risd-git.test.mjs +7 -5
- package/test/risd-handoff.test.mjs +6 -50
- package/test/risd-helpers.mjs +150 -3
- package/test/risd-host-p2.test.mjs +2 -30
- package/test/risd-lifecycle.test.mjs +25 -0
- package/test/risd-programs.test.mjs +4 -34
- package/test/risd-review-p2.test.mjs +0 -13
- package/test/risd-shutdown.test.mjs +5 -38
- package/test/risd-teardown.test.mjs +8 -27
- package/test/risd-ui.test.mjs +169 -13
- package/test/risd-write.test.mjs +2 -1
- package/test/startup-reconcile.test.mjs +44 -8
- 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,
|
|
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
|
//
|
|
@@ -209,21 +209,21 @@ export function risdUiHtml(options) {
|
|
|
209
209
|
<h2>生命周期 <span class="sub">只配置是否跟随 dsh;所有资源强制跟随 daemon(停止 daemon 时一并停止)</span></h2>
|
|
210
210
|
<div id="lifecycle-rows">
|
|
211
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
|
|
212
|
+
<label class="life"><b>代理引擎</b><input type="checkbox" data-life="proxy.followDsh"><span class="muted">跟随 dsh:dsh 接入时启动引擎,没有 dsh 租约时拆除隧道(含系统层拦截);拦截需要 root 时不会自动弹窗</span></label>
|
|
213
213
|
<label class="life"><b>程序(JVM)</b><input type="checkbox" data-life="programs.followDsh"><span class="muted">跟随 dsh:最后一个窗口退出后停止程序</span></label>
|
|
214
214
|
<label class="life"><b>调试会话</b><input type="checkbox" data-life="debug.followDsh"><span class="muted">跟随 dsh:最后一个窗口退出后断开调试</span></label>
|
|
215
215
|
</div>
|
|
216
216
|
<div class="row" style="margin-top:10px">
|
|
217
|
+
<span class="muted">勾选即自动保存,不用点按钮</span>
|
|
217
218
|
<span class="grow"></span>
|
|
218
219
|
<span class="muted" id="lifecycle-note"></span>
|
|
219
|
-
<button id="lifecycle-save">保存生命周期</button>
|
|
220
220
|
</div>
|
|
221
221
|
</section>
|
|
222
222
|
</div>
|
|
223
223
|
|
|
224
224
|
<div class="view" id="view-proxy" hidden>
|
|
225
225
|
<section>
|
|
226
|
-
<h2>ProxyBridge 组件 <span class="sub"
|
|
226
|
+
<h2>ProxyBridge 组件 <span class="sub">系统层拦截所需;按需下载,缓存复用</span></h2>
|
|
227
227
|
<div class="row">
|
|
228
228
|
<span id="bridge-pill" class="pill off">未知</span>
|
|
229
229
|
<span class="muted grow" id="bridge-detail"></span>
|
|
@@ -234,7 +234,7 @@ export function risdUiHtml(options) {
|
|
|
234
234
|
<div class="row" style="margin-top:8px">
|
|
235
235
|
<span id="bridge-health-pill" class="pill off">未检查</span>
|
|
236
236
|
<span class="muted grow" id="bridge-health-text"></span>
|
|
237
|
-
<button id="bridge-
|
|
237
|
+
<button id="bridge-fix" hidden>启动系统层拦截(可能提权)</button>
|
|
238
238
|
<button id="bridge-health-stop" hidden>停止拦截</button>
|
|
239
239
|
</div>
|
|
240
240
|
<div id="bridge-elevate-note" hidden></div>
|
|
@@ -245,18 +245,18 @@ export function risdUiHtml(options) {
|
|
|
245
245
|
<div class="muted" id="bridge-hint" style="margin-top:6px"></div>
|
|
246
246
|
</section>
|
|
247
247
|
<section>
|
|
248
|
-
<h2>规则表 <span class="sub"
|
|
248
|
+
<h2>规则表 <span class="sub">全局规则:按机器生效、不区分工作区</span></h2>
|
|
249
249
|
<div class="row" style="margin-bottom:10px">
|
|
250
250
|
<span class="pill off" id="proxy-engine-pill">未知</span>
|
|
251
251
|
<span class="grow"></span>
|
|
252
|
-
<button id="proxy-engine-toggle" disabled>启动</button>
|
|
253
252
|
<span class="muted" id="proxy-revision"></span>
|
|
253
|
+
<button id="proxy-engine-toggle" disabled>启动</button>
|
|
254
254
|
</div>
|
|
255
255
|
<div class="row" style="margin-bottom:10px">
|
|
256
256
|
<label class="muted">SOCKS 主机</label><input id="proxy-socks-host" class="narrow" placeholder="host">
|
|
257
257
|
<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
258
|
<label class="muted">监听端口</label><input id="proxy-listen" class="narrow" placeholder="11081">
|
|
259
|
+
<span id="proxy-ping" class="pill off" role="status" title="">检测中…</span>
|
|
260
260
|
</div>
|
|
261
261
|
<div id="proxy-banner"></div>
|
|
262
262
|
<table>
|
|
@@ -268,7 +268,6 @@ export function risdUiHtml(options) {
|
|
|
268
268
|
<div class="row" style="margin-top:10px">
|
|
269
269
|
<button id="proxy-add">+ 添加规则</button>
|
|
270
270
|
<span class="grow"></span>
|
|
271
|
-
<button id="bridge-restart" hidden>重启系统层拦截(可能提权)</button>
|
|
272
271
|
<button id="proxy-log-toggle">代理日志</button>
|
|
273
272
|
</div>
|
|
274
273
|
<pre id="proxy-log" hidden></pre>
|
|
@@ -313,7 +312,7 @@ export function risdUiHtml(options) {
|
|
|
313
312
|
var PAGE_INSTANCE = ${uiInstance};
|
|
314
313
|
var initialCwd = '';
|
|
315
314
|
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,
|
|
315
|
+
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
316
|
};
|
|
318
317
|
// The drift banner's current message and the message the user closed: a closed
|
|
319
318
|
// hint must not pop back every 5 s, but a NEW kind of drift still has to warn.
|
|
@@ -524,15 +523,49 @@ export function risdUiHtml(options) {
|
|
|
524
523
|
return policy;
|
|
525
524
|
}
|
|
526
525
|
|
|
527
|
-
|
|
526
|
+
// 勾选即保存(没有保存按钮):一次勾选就是一次配置修改,不该再多一步确认。
|
|
527
|
+
// 300 ms 防抖合并连点;请求在飞时只记一个「还有一次」,避免两个 POST 互相覆盖。
|
|
528
|
+
var lifecycleTimer = null;
|
|
529
|
+
var lifecycleSave = null;
|
|
530
|
+
var lifecycleQueued = false;
|
|
531
|
+
|
|
532
|
+
function scheduleLifecycleSave() {
|
|
533
|
+
// Mark it dirty right away: the 4 s refresh must not refill the boxes from the
|
|
534
|
+
// daemon while the save is still being debounced (review C-P2-3).
|
|
535
|
+
state.lifecycleDirty = true;
|
|
536
|
+
if (lifecycleTimer !== null) clearTimeout(lifecycleTimer);
|
|
537
|
+
lifecycleTimer = setTimeout(function () { lifecycleTimer = null; saveLifecycle(true); }, 300);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function saveLifecycle(auto) {
|
|
541
|
+
if (lifecycleSave !== null) { lifecycleQueued = true; return lifecycleSave; }
|
|
528
542
|
var policy = lifecycleFromBoxes();
|
|
529
|
-
|
|
543
|
+
var run = api('/v1/config', { method: 'POST', body: { lifecycle: policy } }).then(function (body) {
|
|
530
544
|
state.lifecycle = body.lifecycle || policy;
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
545
|
+
// Another toggle landed while this POST was in flight: keep the form as the
|
|
546
|
+
// user left it (refilling from the daemon would undo that toggle) and let the
|
|
547
|
+
// queued save carry it; dirty stays set so the 4 s refresh leaves it alone.
|
|
548
|
+
var queued = lifecycleQueued === true;
|
|
549
|
+
if (queued !== true) state.lifecycleDirty = false;
|
|
550
|
+
return (queued === true ? Promise.resolve() : loadLifecycle()).then(function () {
|
|
551
|
+
el('lifecycle-note').textContent = auto === true ? '已自动保存' : '已保存';
|
|
552
|
+
setTimeout(function () { if (el('lifecycle-note')) el('lifecycle-note').textContent = ''; }, 2500);
|
|
553
|
+
});
|
|
554
|
+
}).catch(function (error) {
|
|
555
|
+
// Keep lifecycleDirty so the refresh loop cannot silently revert the toggle;
|
|
556
|
+
// the next click retries the whole form.
|
|
557
|
+
el('lifecycle-note').textContent = '保存失败:' + error.message + '(再勾一次重试)';
|
|
558
|
+
});
|
|
559
|
+
lifecycleSave = run.then(function (value) {
|
|
560
|
+
lifecycleSave = null;
|
|
561
|
+
if (lifecycleQueued === true) { lifecycleQueued = false; scheduleLifecycleSave(); }
|
|
562
|
+
return value;
|
|
563
|
+
}, function (error) {
|
|
564
|
+
lifecycleSave = null;
|
|
565
|
+
if (lifecycleQueued === true) { lifecycleQueued = false; scheduleLifecycleSave(); }
|
|
566
|
+
throw error;
|
|
567
|
+
});
|
|
568
|
+
return lifecycleSave;
|
|
536
569
|
}
|
|
537
570
|
|
|
538
571
|
function refreshOverview() {
|
|
@@ -600,17 +633,14 @@ export function risdUiHtml(options) {
|
|
|
600
633
|
}
|
|
601
634
|
|
|
602
635
|
/**
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
*
|
|
636
|
+
* Remember whether the last save left a stale enforcement behind. The reason is
|
|
637
|
+
* only trusted when it names a real failure; a normal "reloading in the
|
|
638
|
+
* background" note must not light the button up.
|
|
606
639
|
*/
|
|
607
640
|
function setBridgeStale(reason) {
|
|
608
641
|
var stale = /未重载|旧规则|需要提权|未能重载|未重启|未能停止/.test(String(reason || ''));
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
button.title = stale
|
|
612
|
-
? '为什么要重启:' + reason + '(点一下会停止系统层拦截并按当前规则表重新启动;Windows 会弹一次 UAC,本侧需要 sudo)'
|
|
613
|
-
: '';
|
|
642
|
+
state.bridgeStaleReason = stale ? String(reason) : '';
|
|
643
|
+
paintBridgeFix();
|
|
614
644
|
}
|
|
615
645
|
|
|
616
646
|
function renderProxyTab(view) {
|
|
@@ -686,17 +716,11 @@ export function risdUiHtml(options) {
|
|
|
686
716
|
}
|
|
687
717
|
|
|
688
718
|
/** 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
719
|
/**
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
720
|
+
* 「勾选的配置不为空、有效就自动保存」:editing is the save. A partially filled row
|
|
721
|
+
* is not an error the user must dismiss, so the banner explains what is still
|
|
722
|
+
* missing and the save happens once it is complete. Saving never starts the engine
|
|
723
|
+
* (m13920) — only the button, or the dsh-start policy, does.
|
|
700
724
|
*/
|
|
701
725
|
var autoSaveTimer = null;
|
|
702
726
|
// Rapid edits can outrun a POST: the second write would carry the revision of the
|
|
@@ -722,35 +746,6 @@ export function risdUiHtml(options) {
|
|
|
722
746
|
saveRules({ auto: true });
|
|
723
747
|
}
|
|
724
748
|
|
|
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
749
|
function loadProxyTab() {
|
|
755
750
|
// The rule table is machine-wide: no workspace picker. The workspace only tags
|
|
756
751
|
// rows for bookkeeping, so the daemon falls back to its own home when omitted.
|
|
@@ -810,10 +805,17 @@ export function risdUiHtml(options) {
|
|
|
810
805
|
state.proxyDirty = false;
|
|
811
806
|
// Reload first, then show the outcome: loadProxyTab clears the banner itself.
|
|
812
807
|
return loadProxyTab().then(function () {
|
|
813
|
-
|
|
808
|
+
// Saving is not starting (m13920): editing the table used to bring the engine
|
|
809
|
+
// up as a side effect, so 「保存即启动」 came as a surprise and the policy
|
|
810
|
+
// checkbox was not the only way to end up with a running engine. A save now
|
|
811
|
+
// only reloads an engine that is already up (switchEnforcement) and names the
|
|
812
|
+
// button that starts one.
|
|
813
|
+
var engineDown = !state.view || state.view.running !== true;
|
|
814
|
+
var hint = engineDown ? ';引擎未启动(保存不会启动它,点「启动」或组件区的「启动系统层拦截」)' : '';
|
|
815
|
+
el('proxy-banner').innerHTML = banner(result.reloadNote ? 'warn' : (engineDown ? 'warn' : 'ok'),
|
|
814
816
|
(auto ? '已自动保存' : '已保存') + '(revision ' + result.revision + ')' +
|
|
815
|
-
(result.reloadNote ? ' · ' + result.reloadNote : ''));
|
|
816
|
-
return
|
|
817
|
+
(result.reloadNote ? ' · ' + result.reloadNote : '') + hint);
|
|
818
|
+
return null;
|
|
817
819
|
});
|
|
818
820
|
});
|
|
819
821
|
saveInFlight = run.then(function (value) {
|
|
@@ -982,7 +984,6 @@ export function risdUiHtml(options) {
|
|
|
982
984
|
var sides = (health && health.sides) || {}
|
|
983
985
|
var interception = (health && health.interception) || { linux: false, windows: false }
|
|
984
986
|
var names = { linux: 'Linux', windows: 'Windows' }
|
|
985
|
-
var elevate = el('bridge-health-elevate')
|
|
986
987
|
stop.hidden = !isStray
|
|
987
988
|
// A request in flight owns its button: the 10 s health poll must not re-enable
|
|
988
989
|
// it, or a second click fires another stop/elevation while the first is still
|
|
@@ -991,11 +992,10 @@ export function risdUiHtml(options) {
|
|
|
991
992
|
var missingNow = ['linux', 'windows'].filter(function (key) {
|
|
992
993
|
return sides[key] && sides[key].applicable !== false && interception[key] !== true
|
|
993
994
|
})
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
}
|
|
995
|
+
state.bridgeEngineRunning = engineRunning === true
|
|
996
|
+
state.bridgeStray = isStray
|
|
997
|
+
state.bridgeMissing = missingNow
|
|
998
|
+
paintBridgeFix()
|
|
999
999
|
var lines = []
|
|
1000
1000
|
function notes(message) { if (message) lines.push(message) }
|
|
1001
1001
|
function planNotes() {
|
|
@@ -1012,7 +1012,7 @@ export function risdUiHtml(options) {
|
|
|
1012
1012
|
})
|
|
1013
1013
|
if (missing.length === 0) return
|
|
1014
1014
|
var command = commands[0] || (degrade && degrade.command)
|
|
1015
|
-
if (command) notes(missing.map(function (key) { return names[key] }).join('、') + ' 侧系统层拦截需要 root
|
|
1015
|
+
if (command) notes(missing.map(function (key) { return names[key] }).join('、') + ' 侧系统层拦截需要 root:点「启动系统层拦截」弹终端输密码,或自行打开终端执行:' + command)
|
|
1016
1016
|
if (degrade && degrade.jvmArgs) {
|
|
1017
1017
|
notes('降级可用(不经系统层拦截):')
|
|
1018
1018
|
notes(' JVM 程序:' + degrade.jvmArgs.join(' '))
|
|
@@ -1069,19 +1069,46 @@ export function risdUiHtml(options) {
|
|
|
1069
1069
|
}
|
|
1070
1070
|
renderElevateNote(health)
|
|
1071
1071
|
}
|
|
1072
|
+
/**
|
|
1073
|
+
* The component card owns ONE recovery button (m13910). After a failed reload the
|
|
1074
|
+
* old design showed 「重启系统层拦截」 next to 「提权启动」, but revoke() had already
|
|
1075
|
+
* stopped the bridge, so both did stop+start and both asked for the same password:
|
|
1076
|
+
* two buttons for one action. Visibility is exclusive now — the stale reload wins
|
|
1077
|
+
* (it needs the stop first), otherwise a missing side means 「启动」.
|
|
1078
|
+
*/
|
|
1079
|
+
function paintBridgeFix() {
|
|
1080
|
+
var button = el('bridge-fix')
|
|
1081
|
+
if (!button) return
|
|
1082
|
+
var missing = state.bridgeMissing || []
|
|
1083
|
+
var stale = state.bridgeStaleReason !== ''
|
|
1084
|
+
var show = state.bridgeEngineRunning === true && state.bridgeStray !== true && (stale || missing.length > 0)
|
|
1085
|
+
button.hidden = !show
|
|
1086
|
+
button.disabled = state.fixBusy === true
|
|
1087
|
+
if (state.fixBusy === true) { button.textContent = stale ? '重启中…' : '启动中…'; return }
|
|
1088
|
+
button.textContent = stale ? '重启系统层拦截(可能提权)' : '启动系统层拦截(可能提权)'
|
|
1089
|
+
button.title = stale
|
|
1090
|
+
? '为什么要重启:' + state.bridgeStaleReason + '(点一下会停止系统层拦截并按当前规则表重新启动;Windows 会弹一次 UAC,本侧可能需要 sudo)'
|
|
1091
|
+
: missing.map(function (key) { return key === 'linux' ? 'Linux' : 'Windows' }).join('、') +
|
|
1092
|
+
' 侧系统层拦截未启动(点一下会尝试提权启动;Windows 会弹一次 UAC,本侧可能需要 sudo)'
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1072
1095
|
// m12606: ask for elevation from the page. sudo is tried first (passwordless),
|
|
1073
1096
|
// then pkexec (a real polkit dialog where the desktop has an agent); when neither
|
|
1074
1097
|
// can, the banner names the command from 说明 so it can be pasted into a terminal.
|
|
1075
|
-
function
|
|
1076
|
-
var button = el('bridge-
|
|
1077
|
-
if (state.
|
|
1078
|
-
state.
|
|
1079
|
-
|
|
1098
|
+
function fixBridge() {
|
|
1099
|
+
var button = el('bridge-fix')
|
|
1100
|
+
if (state.fixBusy === true) return
|
|
1101
|
+
state.fixBusy = true
|
|
1102
|
+
// A stale reload must stop the old profile before starting the new one; a
|
|
1103
|
+
// purely missing side is enough with a plain start. Only this click sets interactive.
|
|
1104
|
+
var action = state.bridgeStaleReason !== '' ? 'redirector-restart' : 'start'
|
|
1105
|
+
paintBridgeFix()
|
|
1080
1106
|
var outcome = { kind: 'warn', text: '' }
|
|
1081
|
-
api('/v1/action', { method: 'POST', body: { action:
|
|
1082
|
-
// /v1/action answers {ok, action, result}; the payload is one level down
|
|
1107
|
+
api('/v1/action', { method: 'POST', body: { action: action, cwd: state.cwd, interactive: true } }).then(function (response) {
|
|
1108
|
+
// /v1/action answers {ok, action, result}; the payload is one level down for
|
|
1109
|
+
// the start action, while redirector-restart answers {stopped,started,skipped}.
|
|
1083
1110
|
var result = (response && response.result) || {};
|
|
1084
|
-
var redirector = result.redirector ||
|
|
1111
|
+
var redirector = result.redirector || result;
|
|
1085
1112
|
var started = Array.isArray(redirector.started) ? redirector.started : [];
|
|
1086
1113
|
var skipped = Array.isArray(redirector.skipped) ? redirector.skipped : [];
|
|
1087
1114
|
if (started.length > 0) {
|
|
@@ -1109,8 +1136,9 @@ export function risdUiHtml(options) {
|
|
|
1109
1136
|
}).catch(function (error) {
|
|
1110
1137
|
outcome = { kind: 'err', text: '提权启动失败:' + error.message }
|
|
1111
1138
|
}).then(function () {
|
|
1112
|
-
state.
|
|
1113
|
-
if (
|
|
1139
|
+
state.fixBusy = false
|
|
1140
|
+
if (outcome.kind === 'ok') state.bridgeStaleReason = ''
|
|
1141
|
+
paintBridgeFix()
|
|
1114
1142
|
// The note belongs to the component card, not the rule-table banner (m12923):
|
|
1115
1143
|
// a terminal may still be waiting for a password, so the message has to live
|
|
1116
1144
|
// next to the component it is about.
|
|
@@ -1302,14 +1330,25 @@ export function risdUiHtml(options) {
|
|
|
1302
1330
|
var parts = String(cwd || '').split('/').filter(Boolean);
|
|
1303
1331
|
return parts.length > 0 ? parts[parts.length - 1] : String(cwd || '');
|
|
1304
1332
|
}
|
|
1305
|
-
/**
|
|
1306
|
-
|
|
1333
|
+
/** Folder-name label (parent folder when two collide) — the fallback for a host
|
|
1334
|
+
* that has no workspace registry to give us the sidebar title. */
|
|
1335
|
+
function workspacePathLabel(cwd, windows) {
|
|
1307
1336
|
var base = workspaceBase(cwd);
|
|
1308
1337
|
var same = windows.filter(function (win) { return workspaceBase(win.cwd) === base; }).length;
|
|
1309
1338
|
if (same <= 1) return base || '(未知工作区)';
|
|
1310
1339
|
var parts = String(cwd || '').split('/').filter(Boolean);
|
|
1311
1340
|
return parts.slice(-2).join('/');
|
|
1312
1341
|
}
|
|
1342
|
+
/**
|
|
1343
|
+
* The dsh sidebar's label, when the plugin could resolve one (m13800): a rename
|
|
1344
|
+
* changes the title and nothing else, so the panel must re-label the SAME row.
|
|
1345
|
+
* Missing title (older host) falls back to the folder name.
|
|
1346
|
+
*/
|
|
1347
|
+
function workspaceLabel(win, windows) {
|
|
1348
|
+
var title = typeof win.title === 'string' ? win.title : '';
|
|
1349
|
+
if (title !== '') return title;
|
|
1350
|
+
return workspacePathLabel(win.cwd, windows);
|
|
1351
|
+
}
|
|
1313
1352
|
|
|
1314
1353
|
function focusIdeFrame() {
|
|
1315
1354
|
var frame = el('ide-frame');
|
|
@@ -1372,10 +1411,13 @@ export function risdUiHtml(options) {
|
|
|
1372
1411
|
function renderIde(windows, current) {
|
|
1373
1412
|
var selected = current || windows[0];
|
|
1374
1413
|
el('ide-ws-list').innerHTML = windows.map(function (win) {
|
|
1375
|
-
var label = workspaceLabel(win
|
|
1414
|
+
var label = workspaceLabel(win, windows);
|
|
1376
1415
|
// Non-live entries stay clickable: dsh may still have the session, the iframe
|
|
1377
1416
|
// shows the real result (m08268).
|
|
1378
|
-
|
|
1417
|
+
// Two different hints: "未活跃" is a remembered window nobody touched for a
|
|
1418
|
+
// while, "无会话" is a workspace with no live dsh session at all. Both stay
|
|
1419
|
+
// clickable — the window page boots on the cwd when the session is gone (m00186).
|
|
1420
|
+
var suffix = win.live === false ? '(未活跃)' : (win.active === false ? '(无会话)' : '');
|
|
1379
1421
|
return '<li><button type="button" data-cwd="' + esc(win.cwd || '') + '" title="' + esc((win.cwd || '') + (suffix ? ' ' + suffix : '')) + '">' +
|
|
1380
1422
|
esc(label + suffix) + '</button></li>';
|
|
1381
1423
|
}).join('');
|
|
@@ -1402,8 +1444,11 @@ export function risdUiHtml(options) {
|
|
|
1402
1444
|
el('ide-ws-list').innerHTML = '';
|
|
1403
1445
|
var frame = el('ide-frame');
|
|
1404
1446
|
if (frame) frame.hidden = true;
|
|
1405
|
-
|
|
1406
|
-
|
|
1447
|
+
var note = 'IDE 界面由 dsh 提供;启动 dsh(工作区在 dsh 侧栏里)后,这里会自动可用。';
|
|
1448
|
+
// dsh may be alive and yet unreachable (still starting, no origin yet): naming the
|
|
1449
|
+
// workspaces it did report separates that from "dsh is not running" (m00186).
|
|
1450
|
+
if (body.knownWorkspaces > 0) note += '(已发现 ' + body.knownWorkspaces + ' 个 dsh 工作区)';
|
|
1451
|
+
ideMessage('warn', 'IDE 不可用:' + (body.reason || 'dsh 未运行'), note);
|
|
1407
1452
|
applySide();
|
|
1408
1453
|
}
|
|
1409
1454
|
|
|
@@ -1455,8 +1500,12 @@ export function risdUiHtml(options) {
|
|
|
1455
1500
|
function dshWindowSignature(body) {
|
|
1456
1501
|
// Liveness is part of the rendering state: a window going 未活跃 must repaint
|
|
1457
1502
|
// the hint bar even though cwd/sessionId did not change.
|
|
1503
|
+
// The title belongs to the signature: a rename must repaint the labels even
|
|
1504
|
+
// though cwd and sessionId did not move (m13800).
|
|
1458
1505
|
return (body.windows || []).map(function (win) {
|
|
1459
|
-
return (win.cwd || '') + '|' + (win.sessionId || '') + '|' + (win.live === false ? 'stale' : 'live')
|
|
1506
|
+
return (win.cwd || '') + '|' + (win.sessionId || '') + '|' + (win.live === false ? 'stale' : 'live') +
|
|
1507
|
+
'|' + (typeof win.title === 'string' ? win.title : '') +
|
|
1508
|
+
'|' + (win.active === false ? 'idle' : 'active');
|
|
1460
1509
|
}).sort().join('\\n');
|
|
1461
1510
|
}
|
|
1462
1511
|
|
|
@@ -1604,7 +1653,11 @@ export function risdUiHtml(options) {
|
|
|
1604
1653
|
engineBusy = true;
|
|
1605
1654
|
engineBusyAction = action;
|
|
1606
1655
|
paintEngineButtons();
|
|
1607
|
-
|
|
1656
|
+
// A click is the one place allowed to ask for elevation (m13910); the
|
|
1657
|
+
// save-triggered auto-start calls the same route without the flag.
|
|
1658
|
+
var body = { action: action, cwd: state.cwd };
|
|
1659
|
+
if (action === 'start') body.interactive = true;
|
|
1660
|
+
api('/v1/action', { method: 'POST', body: body })
|
|
1608
1661
|
.then(function (response) {
|
|
1609
1662
|
var result = (response && response.result) || {};
|
|
1610
1663
|
var redirector = result.redirector || {};
|
|
@@ -1613,7 +1666,7 @@ export function risdUiHtml(options) {
|
|
|
1613
1666
|
paintEngineButtons();
|
|
1614
1667
|
// Write the elevation warning AFTER the refresh: loadProxyTab empties
|
|
1615
1668
|
// #proxy-banner, so a message written before it vanished in the same frame
|
|
1616
|
-
// (评审 20261109-2326 客户端 P2).
|
|
1669
|
+
// (评审 20261109-2326 客户端 P2).
|
|
1617
1670
|
// A stop that the OS refused (root-owned CLI) or that lost a race with
|
|
1618
1671
|
// an in-flight start must not look like a clean stop (review B-P1-2/B-P1-5).
|
|
1619
1672
|
var stopBlocked = action === 'stop' && redirector.stopped === false
|
|
@@ -1640,11 +1693,10 @@ export function risdUiHtml(options) {
|
|
|
1640
1693
|
el('engine-toggle').onclick = toggleProxyEngine;
|
|
1641
1694
|
el('proxy-engine-toggle').onclick = toggleProxyEngine;
|
|
1642
1695
|
el('bridge-health-stop').onclick = stopStrayBridge;
|
|
1643
|
-
el('bridge-
|
|
1644
|
-
el('lifecycle-save').onclick = saveLifecycle;
|
|
1696
|
+
el('bridge-fix').onclick = fixBridge;
|
|
1645
1697
|
// 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',
|
|
1698
|
+
// until the save succeeds (review C-P2-3). Toggling is the save (m13960).
|
|
1699
|
+
el('lifecycle-rows').addEventListener('change', scheduleLifecycleSave);
|
|
1648
1700
|
|
|
1649
1701
|
// Re-probe while the user edits host/port: 800 ms after the last keystroke, and
|
|
1650
1702
|
// only on the proxy tab (the inputs are hidden elsewhere).
|
|
@@ -1671,21 +1723,6 @@ export function risdUiHtml(options) {
|
|
|
1671
1723
|
renderProxyTab(Object.assign({}, state.view || {}, { rules: rules }));
|
|
1672
1724
|
scheduleProxySave();
|
|
1673
1725
|
};
|
|
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
1726
|
el('bridge-download').onclick = downloadBundle;
|
|
1690
1727
|
el('bridge-upload').onclick = function () { el('bridge-file').click(); };
|
|
1691
1728
|
el('bridge-file').onchange = function (event) {
|
package/lib/risd-client.js
CHANGED
|
@@ -205,10 +205,13 @@ export function saveProxy(state, { cwd, config, revision, gitHost } = {}) {
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
/** Run one of the three-layer actions (engine + bridge + git) in the daemon. */
|
|
208
|
-
export function proxyAction(state, { cwd, action, gitHost, ruleId } = {}) {
|
|
208
|
+
export function proxyAction(state, { cwd, action, gitHost, ruleId, interactive } = {}) {
|
|
209
209
|
const body = { cwd, action }
|
|
210
210
|
if (typeof gitHost === 'string' && gitHost !== '') body.gitHost = gitHost
|
|
211
211
|
if (typeof ruleId === 'string' && ruleId !== '') body.ruleId = ruleId
|
|
212
|
+
// Only an explicit click sets this: a password dialog must never be a side
|
|
213
|
+
// effect of saving rules or of dsh starting (m13910).
|
|
214
|
+
if (interactive === true) body.interactive = true
|
|
212
215
|
return risdRequest(state, '/v1/action', { method: 'POST', body })
|
|
213
216
|
}
|
|
214
217
|
|
package/lib/startup.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// @module dsh-ris-ide/startup
|
|
15
15
|
import { existsSync, rmSync } from 'node:fs'
|
|
16
16
|
import { proxyPid, proxyPidPath, proxyStatus, readProxyConfig } from './proxy.js'
|
|
17
|
-
import { reloadFailedPath, readWindowsServiceState, redirectorStatusCached, restoreWindowsService } from './redirector.js'
|
|
17
|
+
import { clearWindowsServiceState, reloadFailedPath, readWindowsServiceState, redirectorStatusCached, restoreWindowsService } from './redirector.js'
|
|
18
18
|
import { clearGitProxy, enabledGitRuleHost, readGitProxyState, syncGitProxy } from './risd/git.js'
|
|
19
19
|
import { readRisdState, removeRisdState } from './risd/state.js'
|
|
20
20
|
import { risdHealth } from './risd-client.js'
|
|
@@ -22,11 +22,27 @@ import { risdHealth } from './risd-client.js'
|
|
|
22
22
|
/**
|
|
23
23
|
* Bring the machine back in line with the current rules.
|
|
24
24
|
*
|
|
25
|
-
* @param {
|
|
26
|
-
*
|
|
25
|
+
* @param {object} [options] - workspace hint (legacy paths), a logger, and the two
|
|
26
|
+
* bridge probes. The probes are injectable on purpose: `redirectorStatusCached()`
|
|
27
|
+
* shells out to PowerShell on WSL/Windows (seconds, and only accurate while the
|
|
28
|
+
* probe of the moment answers) and `restoreWindowsService()` really runs
|
|
29
|
+
* `Set-Service`/`Start-Service`. A test that called them directly was (a) slow,
|
|
30
|
+
* (b) flaky — a bridge that happened to be running silently changed the branch —
|
|
31
|
+
* and (c) able to restart the developer's own ProxyBridgeSvc.
|
|
32
|
+
* @param {string} [options.cwd] - workspace hint, only used to resolve legacy paths.
|
|
33
|
+
* @param {(message: string) => void} [options.log] - logger.
|
|
34
|
+
* @param {() => {running?: boolean}} [options.status] - bridge status probe.
|
|
35
|
+
* @param {() => {restored?: boolean, reason?: string}} [options.restore] - service restore.
|
|
36
|
+
* @param {number|null} [options.ownPid] - this process, so its own state is never removed.
|
|
27
37
|
* @returns {Promise<{ok: boolean, notes: string[]}>} what was cleaned (empty = clean).
|
|
28
38
|
*/
|
|
29
|
-
export async function reconcileStartupLeftovers({
|
|
39
|
+
export async function reconcileStartupLeftovers({
|
|
40
|
+
cwd = '',
|
|
41
|
+
log = () => {},
|
|
42
|
+
ownPid = null,
|
|
43
|
+
status = redirectorStatusCached,
|
|
44
|
+
restore = restoreWindowsService,
|
|
45
|
+
} = {}) {
|
|
30
46
|
const notes = []
|
|
31
47
|
const note = (message) => {
|
|
32
48
|
notes.push(message)
|
|
@@ -85,15 +101,19 @@ export async function reconcileStartupLeftovers({ cwd = '', log = () => {}, ownP
|
|
|
85
101
|
|
|
86
102
|
// A reload failure marker from the previous run describes a bridge that is not
|
|
87
103
|
// running any more; keeping it makes the panel warn about nothing.
|
|
88
|
-
if (existsSync(reloadFailedPath()) &&
|
|
104
|
+
if (existsSync(reloadFailedPath()) && status().running !== true) {
|
|
89
105
|
rmSync(reloadFailedPath(), { force: true })
|
|
90
106
|
note('清掉了上次遗留的桥接重载失败标记')
|
|
91
107
|
}
|
|
92
108
|
|
|
93
109
|
const serviceState = readWindowsServiceState()
|
|
94
110
|
if (serviceState !== null && serviceState.stoppedByUs === true) {
|
|
95
|
-
if (
|
|
96
|
-
const restored =
|
|
111
|
+
if (status().running !== true) {
|
|
112
|
+
const restored = restore()
|
|
113
|
+
// `restoreWindowsService()` clears the record itself; with an injected
|
|
114
|
+
// `restore` (tests) nothing would, so clear here too — the record describes a
|
|
115
|
+
// service that is no longer parked either way.
|
|
116
|
+
if (restored.restored === true) clearWindowsServiceState()
|
|
97
117
|
note(restored.restored === true
|
|
98
118
|
? '已恢复上次被停用的 ProxyBridgeSvc'
|
|
99
119
|
: `ProxyBridgeSvc 未能自动恢复:${restored.reason ?? '未知原因'}(可手动把启动类型改回 Automatic)`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ris-ide",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "RIS-IDE local dev panel for the DSH web GUI: live log tail, one-click start/stop of workspace programs, JDWP debugging, file tree + editor, and a standalone IDE window that carries no session history. · DSH 右侧栏本地开发面板:日志实时跟随、一键启停本地程序、Java 断点调试、文件树与编辑器、独立 IDE 窗口。",
|
|
6
6
|
"keywords": [
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
|
-
"test": "node --test \"test/*.test.mjs\"",
|
|
78
|
+
"test": "node --test --test-timeout=120000 \"test/*.test.mjs\"",
|
|
79
79
|
"build": "tsdown --config tsdown.config.mjs",
|
|
80
80
|
"check:listing": "node bin/check-listing.mjs"
|
|
81
81
|
},
|