dsh-remote 1.2.0 → 1.2.1

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/lib/client.js CHANGED
@@ -27,7 +27,7 @@ window.__ModuleLoader__.load({
27
27
 
28
28
  const React = require('react')
29
29
  const name = 'dsh-remote'
30
- const CLIENT_VERSION = '1.2.0'
30
+ const CLIENT_VERSION = '1.2.1'
31
31
 
32
32
  // ── optional host primitives ────────────────────────────────────────────
33
33
  // Issue #74: a remote session's .md link must open over SFTP, NOT via the
@@ -432,7 +432,7 @@ window.__ModuleLoader__.load({
432
432
  // 灰按钮必须能解释自己:用户「点了没反应」时唯一能拿到的线索就是 hover 提示。
433
433
  'settings.saveNeedsHost': '先填写主机地址才能保存',
434
434
  'settings.saveHint': '保存这台机器(留空的密码/私钥/passphrase 沿用已保存的值)',
435
- 'settings.fwdNeedsPort': '先填写本地监听端口才能添加转发',
435
+ 'settings.fwdNeedsPort': '先填写监听端口才能添加转发',
436
436
  'settings.fwdAddHint': '添加一条端口转发',
437
437
  'settings.advCollapse': '收起高级配置',
438
438
  'settings.advExpand': '高级配置:认证与连接选项',
@@ -456,15 +456,31 @@ window.__ModuleLoader__.load({
456
456
  'settings.saving': '保存中…',
457
457
  'settings.save': '保存',
458
458
  'settings.forwards': '端口转发(SSH 隧道)',
459
+ 'settings.forwardsHint': '谁要发起访问,就在谁那边开监听口:监听口开在本机就是本地转发(ssh -L),开在远端就是远程转发(ssh -R)。',
460
+ 'settings.fwdLocalHint': '监听口开在本机,连接转发到远端目标。',
461
+ 'settings.fwdSideLocal': '本机 -L',
462
+ 'settings.fwdSideReverse': '远端 -R',
463
+ 'settings.fwdReverseHint': '监听口开在远端,连接转发回本机目标。',
459
464
  'settings.fwdStop': '停止',
460
465
  'settings.fwdStart': '启动',
466
+ 'settings.fwdStarting': '启动中…',
461
467
  'settings.fwdRemove': '删除',
462
- 'settings.fwdDirLocal': '本地→远端',
463
- 'settings.fwdDirReverse': '远端→本地',
468
+ 'settings.fwdDirLocal': '本地 (-L)',
469
+ 'settings.fwdDirReverse': '远程 (-R)',
464
470
  'settings.fwdListen': '监听端口',
465
471
  'settings.fwdTargetHost': '目标主机',
466
472
  'settings.fwdTargetPort': '目标端口',
467
473
  'settings.fwdAuto': '自动重连',
474
+ 'settings.fwdAutoHint': '掉线重连后自动恢复这条转发',
475
+ 'settings.fwdLegacyBadge': '需重新确认',
476
+ 'settings.fwdLegacyHint': '旧版「自动重连」配置已暂停:重新勾选,并在需要时手动启动一次。',
477
+ 'settings.fwdAutoNoticeTitle': '自动重连会做什么?',
478
+ 'settings.fwdAutoNoticeBody': '勾选后,这条转发会记住“上次是否在运行”。\n\ndsh-web 启动时会自动连接当前机器,连上后恢复这条转发。\n\n如果机器连不上、凭据失效或端口被占用,本次恢复会失败,但不影响其他功能。\n\nDSH 重启后,只会恢复上次运行中的转发(从没启动过的不会自动启动)。',
479
+ 'settings.fwdAutoNoticeTitleReverse': '反向转发的自动重连会做什么?',
480
+ 'settings.fwdAutoNoticeBodyReverse': '勾选后,这条反向转发会记住“上次是否在运行”。\n\ndsh-web 启动时会自动连接当前机器,并在这台机器上重新监听端口、把连接转发回你本机;也就是说,重启后它会在远端自动重新打开监听。\n\n只有上次运行中的反向转发会被恢复;如果机器连不上、远端 AllowTcpForwarding 被关闭或端口被占用,本次恢复会失败,但不影响其他功能。\n\n如果不想让远端自动重新监听,请取消勾选或手动停止。',
481
+ 'settings.fwdAutoNoticeConfirm': '仍然勾选',
482
+ 'settings.fwdAutoNoticeCancel': '取消',
483
+ 'settings.fwdAutoNoticeDontShow': '不再提示',
468
484
  'settings.fwdAdd': '添加转发',
469
485
  'settings.cleanup': '工作区清理(本地镜像与对话)',
470
486
  'settings.cleanupRefresh': '刷新',
@@ -1020,7 +1036,7 @@ window.__ModuleLoader__.load({
1020
1036
  'settings.testNeedsHost': 'Fill in the host before testing',
1021
1037
  'settings.saveNeedsHost': 'Fill in the host before saving',
1022
1038
  'settings.saveHint': 'Save this machine (a blank password/key/passphrase keeps the saved one)',
1023
- 'settings.fwdNeedsPort': 'Fill in the local listen port before adding a forward',
1039
+ 'settings.fwdNeedsPort': 'Fill in the listen port before adding a forward',
1024
1040
  'settings.fwdAddHint': 'Add a port forward',
1025
1041
  'settings.advCollapse': 'Hide advanced options',
1026
1042
  'settings.advExpand': 'Advanced authentication and connection options',
@@ -1044,15 +1060,31 @@ window.__ModuleLoader__.load({
1044
1060
  'settings.saving': 'Saving…',
1045
1061
  'settings.save': 'Save',
1046
1062
  'settings.forwards': 'Port forwarding (SSH tunnels)',
1063
+ 'settings.forwardsHint': 'Open the listener on the side that starts the connection: a listener here is a local forward (ssh -L); one on the remote is a reverse forward (ssh -R).',
1064
+ 'settings.fwdLocalHint': 'The listener is on this machine; connections go to the remote target.',
1065
+ 'settings.fwdSideLocal': 'Local -L',
1066
+ 'settings.fwdSideReverse': 'Remote -R',
1067
+ 'settings.fwdReverseHint': 'The listener is on the remote; connections come back to the local target.',
1047
1068
  'settings.fwdStop': 'Stop',
1048
1069
  'settings.fwdStart': 'Start',
1070
+ 'settings.fwdStarting': 'Starting…',
1049
1071
  'settings.fwdRemove': 'Remove',
1050
- 'settings.fwdDirLocal': 'Local → remote',
1051
- 'settings.fwdDirReverse': 'Remote → local',
1072
+ 'settings.fwdDirLocal': 'Local (-L)',
1073
+ 'settings.fwdDirReverse': 'Remote (-R)',
1052
1074
  'settings.fwdListen': 'Listen port',
1053
1075
  'settings.fwdTargetHost': 'Target host',
1054
1076
  'settings.fwdTargetPort': 'Target port',
1055
1077
  'settings.fwdAuto': 'Auto reconnect',
1078
+ 'settings.fwdAutoHint': 'Restore this forward automatically after a reconnect',
1079
+ 'settings.fwdLegacyBadge': 'Re-confirm',
1080
+ 'settings.fwdLegacyHint': 'The legacy auto-reconnect setting was paused: tick it again and start the forward once if needed.',
1081
+ 'settings.fwdAutoNoticeTitle': 'What does Auto reconnect do?',
1082
+ 'settings.fwdAutoNoticeBody': 'When checked, this forward remembers whether it was running.\n\ndsh web connects the current machine on startup and restores the forward once connected.\n\nIf the host is unreachable, credentials fail, or the port is taken, that restore fails without affecting anything else.\n\nAfter a DSH restart only forwards that were running come back (one that was never started stays down).',
1083
+ 'settings.fwdAutoNoticeTitleReverse': 'What does Auto reconnect do for a reverse forward?',
1084
+ 'settings.fwdAutoNoticeBodyReverse': 'When checked, this reverse forward remembers whether it was running.\n\ndsh web connects the current machine on startup and makes the REMOTE listen again, piping connections back to your machine. In other words, it re-opens the remote listener automatically after a restart.\n\nOnly reverse forwards that were running are restored; if the host is unreachable, AllowTcpForwarding was disabled, or the port is taken, that restore fails without affecting anything else.\n\nUncheck this or stop the forward if the remote must not listen again on its own.',
1085
+ 'settings.fwdAutoNoticeConfirm': 'Enable anyway',
1086
+ 'settings.fwdAutoNoticeCancel': 'Cancel',
1087
+ 'settings.fwdAutoNoticeDontShow': "Don't show again",
1056
1088
  'settings.fwdAdd': 'Add forward',
1057
1089
  'settings.cleanup': 'Workspace cleanup (local mirrors & chats)',
1058
1090
  'settings.cleanupRefresh': 'Refresh',
@@ -1825,9 +1857,80 @@ window.__ModuleLoader__.load({
1825
1857
  observer.observe(document.body, { childList: true, subtree: true }); sync()
1826
1858
  return () => { observer.disconnect(); for (const button of marked) button.removeAttribute('data-rw-settings-legacy-icon') }
1827
1859
  }
1828
- function discoveredProbeTargets(hosts, machines) {
1829
- return (hosts || []).filter(host => !machines.some(machine => machine.useSshConfig && machine.host === String(host.alias || host.host))).map(host => ({ key: 'ssh:' + String(host.alias || host.host), body: { host: String(host.alias || host.host), port: Number(host.port) || 22, username: host.user || '', useSshConfig: true }, fingerprint: host }))
1860
+ // A slow probe uses the server's configured connectTimeoutMs; the client
1861
+ // never overrides it. Only a genuine timeout may be retried (never exit -1).
1862
+ const isProbeTimeout = (error) => /\bETIMEDOUT\b|\btimed[\s-]?out\b|\btimeout\b/i.test(String((error && error.message) || error || ''))
1863
+ // dsh-remote-fix4: identity, not alias, is what a probe may dial once, and
1864
+ // what a list row may show once. `dogyun`, `dg` and `dogyun.up2mountain.top`
1865
+ // are one machine; showing or probing them three times was how the same
1866
+ // server came out green, red and green in one sweep.
1867
+ const identityKeyOf = (host, port, username) => String(host || '').trim().toLowerCase() + '|' + (Number(port) || 22) + '|' + String(username || '').trim()
1868
+ /** Resolved identity of a ~/.ssh/config entry — the alias is only a name. */
1869
+ const hostIdentityKey = (h) => identityKeyOf(h && (h.hostName || h.alias || h.host), h && h.port, h && h.user)
1870
+ /** A discovered alias may share a probe only when its effective SSH
1871
+ * connection settings match, not merely when HostName/User/Port match. */
1872
+ const discoveredConfigKey = (h) => JSON.stringify([hostIdentityKey(h), String((h && h.identityFile) || ''), String((h && h.proxyJump) || ''), String((h && h.proxyCommand) || '')])
1873
+ /** Resolved identity of a saved machine (registry values may be stale). */
1874
+ const machineIdentityKey = (m) => identityKeyOf((m && m.sshConfigResolved && m.sshConfigResolved.host) || (m && m.host), (m && m.sshConfigResolved && m.sshConfigResolved.port) || (m && m.port), (m && m.sshConfigResolved && m.sshConfigResolved.username) || (m && m.username))
1875
+ /** Effective SSH settings of a saved alias, in the same key shape as a
1876
+ * discovered entry. Missing metadata never becomes an endpoint fallback. */
1877
+ const machineConfigKey = (m) => {
1878
+ const r = m && m.sshConfigResolved
1879
+ if (!r || !r.matched) return ''
1880
+ return discoveredConfigKey({ hostName: r.host, port: r.port, user: r.username,
1881
+ identityFile: r.identityFile, proxyJump: r.proxyJump, proxyCommand: r.proxyCommand })
1830
1882
  }
1883
+ /** Git-only hosts: SSH works, but there is no shell and no workspace. */
1884
+ const isGitHost = (value) => /(^|\.)github\.com$/i.test(String(value || '').trim())
1885
+ // Saved GitHub rows remain manageable, but a known shell-less endpoint is
1886
+ // not probed as if it were a remote workspace host.
1887
+ const shouldProbeMachine = (m) => !isGitHost(m && m.host) && !isGitHost(m && m.sshConfigResolved && m.sshConfigResolved.host)
1888
+ /**
1889
+ * One entry per resolved identity, preferring the block's canonical name
1890
+ * (the alias that equals HostName) over a short alias.
1891
+ */
1892
+ function dedupeHostEntries(hosts) {
1893
+ const byIdentity = new Map()
1894
+ for (const host of hosts || []) {
1895
+ const name = String((host && (host.alias || host.host)) || '')
1896
+ if (isGitHost(name) || isGitHost(host && host.hostName) || isGitHost(host && host.host)) continue
1897
+ const key = discoveredConfigKey(host)
1898
+ const current = byIdentity.get(key)
1899
+ if (!current) { byIdentity.set(key, host); continue }
1900
+ const currentName = String(current.alias || current.host || '')
1901
+ const canonical = String((host && host.hostName) || '')
1902
+ if (currentName !== String(current.hostName || '') && name === canonical) byIdentity.set(key, host)
1903
+ }
1904
+ return [...byIdentity.values()]
1905
+ }
1906
+
1907
+ /** Saved records keep their own management and probe identity. Only a
1908
+ * resolved SSH identity or an exact alias may suppress a discovered row. */
1909
+ function savedSshIdentitySets(machines) {
1910
+ const resolvedIdentities = new Set(), aliases = new Set()
1911
+ for (const m of machines || []) {
1912
+ if (m && m.sshConfigResolved && m.sshConfigResolved.matched) resolvedIdentities.add(machineConfigKey(m))
1913
+ if (m && m.useSshConfig && m.host) aliases.add(String(m.host))
1914
+ }
1915
+ return { resolvedIdentities, aliases }
1916
+ }
1917
+ function dedupeDiscoveredForSaved(hosts, machines) {
1918
+ const { resolvedIdentities, aliases } = savedSshIdentitySets(machines)
1919
+ const suppressed = new Set(resolvedIdentities)
1920
+ // Resolve an exact saved alias through the discovered config itself. This
1921
+ // suppresses the whole alias group before canonical-name selection, so a
1922
+ // saved short alias cannot reappear under its full HostName sibling.
1923
+ for (const h of hosts || []) {
1924
+ const alias = String((h && (h.alias || h.host)) || '')
1925
+ if (aliases.has(alias)) suppressed.add(discoveredConfigKey(h))
1926
+ }
1927
+ return dedupeHostEntries(hosts).filter((h) => !suppressed.has(discoveredConfigKey(h)))
1928
+ }
1929
+ // dsh-remote-fix4: the old discoveredProbeTargets() built one probe target
1930
+ // per ~/.ssh/config alias and only filtered exact-name duplicates. The sweep
1931
+ // now derives its targets from the deduped lists inside each component, so
1932
+ // keeping a second, differently-deduped builder here would invite the two to
1933
+ // drift apart.
1831
1934
  function RemoteWorkspacePage() {
1832
1935
  const settingsId = React.useId()
1833
1936
  const [settingsTab, setSettingsTab] = React.useState('hosts')
@@ -1877,6 +1980,14 @@ window.__ModuleLoader__.load({
1877
1980
  // push the update/audit cards far down the page for a feature most sessions
1878
1981
  // never touch.
1879
1982
  const [fwdOpen, setFwdOpen] = React.useState(false)
1983
+ // id → true while a start/stop request is in flight; the row shows a
1984
+ // pending label and cannot be clicked twice (a second click used to race
1985
+ // the first one for the same listen port).
1986
+ const [fwdBusy, setFwdBusy] = React.useState({})
1987
+ // First-time explanation for 自动重连. `fwdNotice.target` is either
1988
+ // {kind:'row', id} or {kind:'form'} (the add-forward form's checkbox).
1989
+ const [fwdNotice, setFwdNotice] = React.useState(null)
1990
+ const [fwdNoticeDontShow, setFwdNoticeDontShow] = React.useState(false)
1880
1991
  const [auditOpen, setAuditOpen] = React.useState(false)
1881
1992
  // Issue #96: workspace cleanup on Web/Desktop (the TUI's machine-menu
1882
1993
  // cleanup page has an in-process API; here it is these two routes).
@@ -2200,6 +2311,7 @@ window.__ModuleLoader__.load({
2200
2311
  probeRevision.current++; settingsEditorDraft = null; formBaseline.current = null
2201
2312
  const focusId = settingsId + '-actions-' + form.id
2202
2313
  clearForm(); setErr(''); setMsg(''); setTst(''); setAdvOpen(false)
2314
+ setProbeGeneration(value => value + 1)
2203
2315
  window.setTimeout(() => document.getElementById(focusId)?.focus?.(), 0)
2204
2316
  }
2205
2317
  const clearForm = () => setForm({ name: '', host: '', port: '22', username: 'root', password: '', privateKeyPath: '', passphrase: '', workspace: '', hostKeyMode: '', useAgent: false, keyboardInteractive: false, encryptPassword: false, proxyHost: '', proxyPort: '22', proxyUser: '', proxyPassword: '', proxyKey: '', backend: 'native', sshBinary: '', webAttachCommand: '', webAttachDiscoverCommand: '', id: '', useSshConfig: false, passwordSet: false, passphraseSet: false, proxyPasswordSet: false })
@@ -2271,10 +2383,30 @@ window.__ModuleLoader__.load({
2271
2383
  // Every visible host is tested once on entry/config changes; at most three
2272
2384
  // probes run together. Leaving the page cancels queued work and stale results.
2273
2385
  const [probeGeneration, setProbeGeneration] = React.useState(0)
2274
- const probeTargets = [
2275
- ...discoveredProbeTargets(sshHosts, machines),
2276
- ...machines.map(machine => ({ key: 'machine:' + machine.id, body: { id: machine.id, host: machine.host, port: machine.port, username: machine.username, useSshConfig: !!machine.useSshConfig }, fingerprint: machine })),
2277
- ]
2386
+ // dsh-remote-fix5: derivation hoisted - the probe queue below reads
2387
+ // these lists, so declaring them afterwards is a TDZ crash at render.
2388
+ //
2389
+ // Saved records are NEVER collapsed: the same endpoint can intentionally
2390
+ // use different credentials, backends or proxies. Only discovered rows
2391
+ // are deduped, and explicit saved records (including GitHub) stay visible.
2392
+ const uniqueMachines = machines
2393
+ const discovered = dedupeDiscoveredForSaved(sshHosts || [], machines)
2394
+
2395
+ // Keep row order stable while connectivity results arrive.
2396
+ const sortedMachines = [...uniqueMachines].sort((a, b) => String(a.name || a.host).localeCompare(String(b.name || b.host)))
2397
+ // Every saved machine id gets its own probe (credentials and backend are
2398
+ // record-specific); each discovered effective config gets at most one.
2399
+ const probeTargets = []
2400
+ for (const machine of uniqueMachines) {
2401
+ if (!shouldProbeMachine(machine)) continue
2402
+ const identity = machineIdentityKey(machine)
2403
+ probeTargets.push({ key: 'machine:' + machine.id, identity, body: { id: machine.id, host: machine.host, port: machine.port, username: machine.username, useSshConfig: !!machine.useSshConfig }, fingerprint: machine })
2404
+ }
2405
+ for (const host of discovered) {
2406
+ const identity = discoveredConfigKey(host)
2407
+ const alias = String(host.alias || host.host)
2408
+ probeTargets.push({ key: 'ssh:' + alias, identity, body: { host: alias, port: Number(host.port) || 22, username: host.user || '', useSshConfig: true }, fingerprint: host })
2409
+ }
2278
2410
  probeTargets.sort((a, b) => a.key.localeCompare(b.key))
2279
2411
  const probeSignature = JSON.stringify(probeTargets.map(target => ({ ...target, fingerprint: target.fingerprint && { ...target.fingerprint, connected: undefined, lastConnectedAt: undefined, latencyMs: undefined, recentWorkspaces: undefined, workspace: undefined } })))
2280
2412
  React.useEffect(() => {
@@ -2286,7 +2418,21 @@ window.__ModuleLoader__.load({
2286
2418
  while (queue.length && !controller.signal.aborted) {
2287
2419
  const target = queue.shift()
2288
2420
  try {
2289
- const result = await api('POST', '/dsh-remote/test-connect', { ...target.body, connectTimeoutMs: 5000 }, controller.signal)
2421
+ // Omitting connectTimeoutMs lets the server use its real config.
2422
+ // The route reports failures as 200 + {ok:false,error}, so one
2423
+ // loop handles both throw and payload forms, at most two attempts.
2424
+ const probeBody = target.body
2425
+ let result
2426
+ for (let attempt = 1; attempt <= 2; attempt++) {
2427
+ try {
2428
+ result = await api('POST', '/dsh-remote/test-connect', probeBody, controller.signal)
2429
+ } catch (error) {
2430
+ if (controller.signal.aborted || attempt === 2 || !isProbeTimeout(error)) throw error
2431
+ continue
2432
+ }
2433
+ if (attempt < 2 && !controller.signal.aborted && result && result.ok === false && isProbeTimeout(result.error)) continue
2434
+ break
2435
+ }
2290
2436
  if (!controller.signal.aborted) setRow(target.key, { ok: !!result?.ok, latencyMs: result?.latencyMs, text: result?.ok ? '' : result?.error || tr('settings.connFail') })
2291
2437
  } catch (error) {
2292
2438
  if (!controller.signal.aborted) setRow(target.key, { ok: false, text: String(error.message || error) })
@@ -2294,15 +2440,68 @@ window.__ModuleLoader__.load({
2294
2440
  }
2295
2441
  }
2296
2442
  Promise.all(Array.from({ length: Math.min(3, queue.length) }, () => worker()))
2297
- return () => controller.abort()
2443
+ return () => {
2444
+ controller.abort()
2445
+ // Aborted rows must not remain visually pending forever. Completed
2446
+ // results stay; a new effect will rebuild its own pending queue.
2447
+ setRowState((prev) => Object.fromEntries(Object.entries(prev || {}).filter(([, value]) => !value || !value.pending)))
2448
+ }
2298
2449
  }, [probeSignature, probeGeneration, hostsLoaded, sshHosts === null])
2299
2450
  const refreshHosts = () => { setProbeGeneration(value => value + 1); refresh().catch(error => setErr(String(error.message || error))); loadSshHosts() }
2300
2451
 
2301
2452
  // ── forwards panel ────────────────────────────────────────────────────
2302
- const fwdAction = (action, id) => {
2303
- api('POST', '/dsh-remote/forwards', { action, id })
2304
- .then((r) => { setForwards(r.forwards || []); setErr(''); setMsg('') })
2305
- .catch((e) => setErr(String((e && e.message) || e)))
2453
+ const fwdAction = (action, id, extra) => {
2454
+ setFwdBusy((m) => ({ ...m, [id]: true }))
2455
+ // apiRaw, not api: a failed start still carries the CURRENT list (a
2456
+ // concurrent autoStart pass may have bound the port already), and the UI
2457
+ // must not keep showing 启动 for a tunnel that is listening.
2458
+ apiRaw('POST', '/dsh-remote/forwards', { action, id, ...(extra || {}) })
2459
+ .then(({ status, data }) => {
2460
+ const body = data || {}
2461
+ if (Array.isArray(body.forwards)) setForwards(body.forwards)
2462
+ if (status >= 400 || body.ok === false) {
2463
+ setErr(String(body.error || ('HTTP ' + status)))
2464
+ if (!Array.isArray(body.forwards)) refreshForwards()
2465
+ return
2466
+ }
2467
+ setErr('')
2468
+ setMsg('')
2469
+ })
2470
+ .catch((e) => { setErr(String((e && e.message) || e)); refreshForwards() })
2471
+ .finally(() => setFwdBusy((m) => {
2472
+ if (!m[id]) return m
2473
+ const next = { ...m }
2474
+ delete next[id]
2475
+ return next
2476
+ }))
2477
+ }
2478
+ // The two directions carry different risks, so they are explained (and
2479
+ // remembered) separately: dismissing the local notice must not silence
2480
+ // the reverse-listener warning.
2481
+ const fwdNoticeKey = (direction) => 'dsh-remote.fwd-auto-notice-' + (direction === 'reverse' ? 'reverse' : 'local') + '-v1'
2482
+ const fwdNoticeDismissed = (direction) => {
2483
+ try { return window.localStorage.getItem(fwdNoticeKey(direction)) === '1' } catch { return false }
2484
+ }
2485
+ const dismissFwdNotice = (direction) => {
2486
+ try { window.localStorage.setItem(fwdNoticeKey(direction), '1') } catch { /* private mode */ }
2487
+ }
2488
+ const applyFwdAutoStart = (target, value) => {
2489
+ if (target.kind === 'form') { setFwdForm((form) => ({ ...form, autoStart: !!value })); return }
2490
+ fwdAction('update', target.id, { autoStart: !!value })
2491
+ }
2492
+ // The semantics are not obvious on first use: explain once, with a
2493
+ // "不再提示" opt-out stored in the browser.
2494
+ const requestFwdAutoStart = (target, value, direction) => {
2495
+ if (!value) { applyFwdAutoStart(target, false); return }
2496
+ if (fwdNoticeDismissed(direction)) { applyFwdAutoStart(target, true); return }
2497
+ setFwdNoticeDontShow(false)
2498
+ setFwdNotice({ target, direction })
2499
+ }
2500
+ const confirmFwdNotice = () => {
2501
+ if (!fwdNotice) return
2502
+ if (fwdNoticeDontShow) dismissFwdNotice(fwdNotice.direction)
2503
+ applyFwdAutoStart(fwdNotice.target, true)
2504
+ setFwdNotice(null)
2306
2505
  }
2307
2506
  const fwdDefine = () => {
2308
2507
  if (!fwdForm.listenPort) return
@@ -2334,11 +2533,6 @@ window.__ModuleLoader__.load({
2334
2533
  // first thing the page shows, because that is the whole list a VSCode
2335
2534
  // Remote-SSH user expects. A saved alias machine hides its file entry (the row
2336
2535
  // below it is the same host, with the actions that belong to a saved machine).
2337
- const savedAliases = new Set(machines.filter((m) => m.useSshConfig).map((m) => String(m.host)))
2338
- const discovered = (sshHosts || []).filter((h) => !savedAliases.has(String(h.alias || h.host)))
2339
-
2340
- // Keep row order stable while connectivity results arrive.
2341
- const sortedMachines = [...machines].sort((a, b) => String(a.name || a.host).localeCompare(String(b.name || b.host)))
2342
2536
 
2343
2537
  // One filter box for BOTH halves of the list (ssh-config hosts + saved ones).
2344
2538
  const needle = hostFilter.trim().toLowerCase()
@@ -2360,6 +2554,27 @@ window.__ModuleLoader__.load({
2360
2554
  return React.createElement('div',
2361
2555
  { className: 'dsh-rw-settings', 'data-rw-settings': true, 'aria-label': tr('settings.title'), style: { color: T.label } },
2362
2556
  confirmUi.node,
2557
+ fwdNotice ? React.createElement('div', {
2558
+ style: { position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.45)', display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 3000 },
2559
+ },
2560
+ React.createElement('div', {
2561
+ role: 'dialog', 'aria-modal': 'true',
2562
+ 'aria-label': tr(fwdNotice.direction === 'reverse' ? 'settings.fwdAutoNoticeTitleReverse' : 'settings.fwdAutoNoticeTitle'),
2563
+ className: 'dsh-rw-forward-notice',
2564
+ style: { width: 480, maxWidth: '92vw', background: T.bg, border: '1px solid ' + T.border, borderRadius: 12, padding: '18px 20px', boxShadow: '0 16px 48px rgba(0,0,0,0.35)', color: T.label },
2565
+ },
2566
+ React.createElement('div', { style: { fontSize: 15, fontWeight: 650, letterSpacing: '-0.01em', marginBottom: 10 } }, tr(fwdNotice.direction === 'reverse' ? 'settings.fwdAutoNoticeTitleReverse' : 'settings.fwdAutoNoticeTitle')),
2567
+ React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
2568
+ tr(fwdNotice.direction === 'reverse' ? 'settings.fwdAutoNoticeBodyReverse' : 'settings.fwdAutoNoticeBody').split('\n\n').map((paragraph, index) => React.createElement('div', {
2569
+ key: index,
2570
+ style: { fontSize: 12.5, lineHeight: 1.6, color: index === 0 ? T.label : T.muted },
2571
+ }, paragraph))),
2572
+ React.createElement('label', { style: { display: 'flex', gap: 6, alignItems: 'center', fontSize: 12, marginTop: 16 } },
2573
+ React.createElement('input', { type: 'checkbox', checked: fwdNoticeDontShow, onChange: (e) => setFwdNoticeDontShow(!!e.target.checked) }),
2574
+ tr('settings.fwdAutoNoticeDontShow')),
2575
+ React.createElement('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end', marginTop: 16 } },
2576
+ React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '4px 14px' }, onClick: () => setFwdNotice(null) }, tr('settings.fwdAutoNoticeCancel')),
2577
+ React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: { ...primaryBtnS, padding: '4px 14px' }, onClick: confirmFwdNotice }, tr('settings.fwdAutoNoticeConfirm'))))) : null,
2363
2578
  React.createElement('div', { style: { fontSize: 16, fontWeight: 650, letterSpacing: '-0.01em' } }, tr('settings.pageTitle')),
2364
2579
  React.createElement('div', { style: { fontSize: 12, opacity: 0.8, lineHeight: 1.55 } },
2365
2580
  tr('settings.intro')),
@@ -2628,23 +2843,70 @@ window.__ModuleLoader__.load({
2628
2843
  React.createElement('div', { style: boxS },
2629
2844
  sectionToggle(fwdOpen, setFwdOpen, tr('settings.forwards')),
2630
2845
  fwdOpen ? React.createElement(React.Fragment, null,
2631
- forwards.length ? forwards.map((f) => React.createElement('div', { key: f.id, className: 'dsh-rw-row', style: { display: 'flex', gap: 8, alignItems: 'center', padding: '6px 0', fontSize: 12, fontFamily: 'monospace' } },
2632
- React.createElement('span', { style: { color: f.active ? T.ok : T.muted } }, f.active ? '●' : '○'),
2633
- React.createElement('span', { style: { flex: 1 } }, `${f.direction} 127.0.0.1:${f.listenPort} → ${f.targetHost}:${f.targetPort}${f.autoStart ? ' [auto]' : ''}`),
2634
- f.active
2635
- ? React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px' }, onClick: () => fwdAction('stop', f.id) }, tr('settings.fwdStop'))
2636
- : React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px' }, onClick: () => fwdAction('start', f.id) }, tr('settings.fwdStart')),
2637
- React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px' }, onClick: () => fwdAction('remove', f.id) }, tr('settings.fwdRemove')))) : null,
2638
- React.createElement('div', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 6, flexWrap: 'wrap' } },
2639
- React.createElement('select', { className: 'dsh-rw-input', value: fwdForm.direction, onChange: (e) => setFwdForm({ ...fwdForm, direction: e.target.value }), style: { ...inputS, maxWidth: 110 } },
2640
- React.createElement('option', { value: 'local' }, tr('settings.fwdDirLocal')),
2641
- React.createElement('option', { value: 'reverse' }, tr('settings.fwdDirReverse'))),
2642
- React.createElement('input', { className: 'dsh-rw-input', value: fwdForm.listenPort, onChange: (e) => setFwdForm({ ...fwdForm, listenPort: e.target.value }), placeholder: tr('settings.fwdListen'), style: { ...inputS, maxWidth: 90 } }),
2643
- React.createElement('input', { className: 'dsh-rw-input', value: fwdForm.targetHost, onChange: (e) => setFwdForm({ ...fwdForm, targetHost: e.target.value }), placeholder: tr('settings.fwdTargetHost'), style: { ...inputS, maxWidth: 120 } }),
2644
- React.createElement('input', { className: 'dsh-rw-input', value: fwdForm.targetPort, onChange: (e) => setFwdForm({ ...fwdForm, targetPort: e.target.value }), placeholder: tr('settings.fwdTargetPort'), style: { ...inputS, maxWidth: 90 } }),
2645
- React.createElement('label', { style: { fontSize: 12, display: 'flex', gap: 4, alignItems: 'center' } },
2646
- React.createElement('input', { type: 'checkbox', checked: fwdForm.autoStart, onChange: (e) => setFwdForm({ ...fwdForm, autoStart: e.target.checked }) }), tr('settings.fwdAuto')),
2846
+ React.createElement('div', { style: { opacity: 0.65, fontSize: 11, lineHeight: 1.5, marginBottom: 8 } }, tr('settings.forwardsHint')),
2847
+ forwards.length ? forwards.map((f) => {
2848
+ const busy = !!fwdBusy[f.id]
2849
+ return React.createElement('div', { key: f.id, className: 'dsh-rw-row', style: { display: 'flex', gap: 8, alignItems: 'center', padding: '6px 0', fontSize: 12, fontFamily: 'monospace' } },
2850
+ React.createElement('span', { style: { color: f.active ? T.ok : T.muted } }, f.active ? '●' : '○'),
2851
+ React.createElement('span', {
2852
+ title: f.direction === 'reverse' ? tr('settings.fwdDirReverse') : tr('settings.fwdDirLocal'),
2853
+ style: { flex: '0 0 auto', color: T.muted, opacity: 0.85 },
2854
+ }, f.direction === 'reverse' ? '-R' : '-L'),
2855
+ React.createElement('span', {
2856
+ title: tr(f.direction === 'reverse' ? 'settings.fwdReverseHint' : 'settings.fwdLocalHint'),
2857
+ style: { flex: 1 },
2858
+ }, `127.0.0.1:${f.listenPort} → ${f.targetHost}:${f.targetPort}`),
2859
+ f.needsReconsent ? React.createElement('span', {
2860
+ title: tr('settings.fwdLegacyHint'),
2861
+ style: { fontSize: 10, color: T.warn, border: '1px solid ' + T.border, borderRadius: 4, padding: '0 4px', whiteSpace: 'nowrap' },
2862
+ }, tr('settings.fwdLegacyBadge')) : null,
2863
+ React.createElement('label', {
2864
+ style: { display: 'flex', alignItems: 'center', gap: 4, fontSize: 11, color: T.muted, whiteSpace: 'nowrap' },
2865
+ title: tr('settings.fwdAutoHint'),
2866
+ },
2867
+ React.createElement('input', {
2868
+ type: 'checkbox',
2869
+ checked: !!f.autoStart,
2870
+ disabled: busy,
2871
+ 'aria-label': tr('settings.fwdAuto'),
2872
+ onChange: (e) => requestFwdAutoStart({ kind: 'row', id: f.id }, !!e.target.checked, f.direction),
2873
+ }),
2874
+ tr('settings.fwdAuto')),
2875
+ f.active
2876
+ ? React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px' }, disabled: busy, onClick: () => fwdAction('stop', f.id) }, tr('settings.fwdStop'))
2877
+ : React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px' }, disabled: busy, onClick: () => fwdAction('start', f.id) }, busy ? tr('settings.fwdStarting') : tr('settings.fwdStart')),
2878
+ React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px' }, disabled: busy, onClick: () => fwdAction('remove', f.id) }, tr('settings.fwdRemove')))
2879
+ }) : null,
2880
+ React.createElement('div', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 8, flexWrap: 'wrap' } },
2881
+ React.createElement('div', {
2882
+ role: 'group', 'aria-label': tr('settings.forwards'),
2883
+ style: { display: 'flex', alignItems: 'stretch', flex: '0 0 auto', height: 30, border: '1px solid ' + T.border, borderRadius: T.radius, overflow: 'hidden' },
2884
+ },
2885
+ ['local', 'reverse'].map((value) => React.createElement('button', {
2886
+ key: value, type: 'button',
2887
+ 'aria-pressed': fwdForm.direction === value,
2888
+ onClick: () => setFwdForm({ ...fwdForm, direction: value }),
2889
+ style: {
2890
+ border: 'none', cursor: 'pointer', padding: '0 8px', fontSize: 11, whiteSpace: 'nowrap',
2891
+ background: fwdForm.direction === value ? T.primary : 'transparent',
2892
+ color: fwdForm.direction === value ? T.onPrimary : T.muted,
2893
+ },
2894
+ }, tr(value === 'local' ? 'settings.fwdSideLocal' : 'settings.fwdSideReverse')))),
2895
+ React.createElement('input', { className: 'dsh-rw-input', value: fwdForm.listenPort, onChange: (e) => setFwdForm({ ...fwdForm, listenPort: e.target.value }), placeholder: tr('settings.fwdListen'), style: { ...inputS, flex: '0 0 90px', width: 90, minWidth: 0, boxSizing: 'border-box', padding: '6px 8px' } }),
2896
+ React.createElement('span', { style: { opacity: 0.55, fontSize: 12, flex: '0 0 auto' } }, '→'),
2897
+ React.createElement('input', { className: 'dsh-rw-input', value: fwdForm.targetHost, onChange: (e) => setFwdForm({ ...fwdForm, targetHost: e.target.value }), placeholder: tr('settings.fwdTargetHost'), style: { ...inputS, flex: '1 1 100px', width: 'auto', minWidth: 90, maxWidth: 240, boxSizing: 'border-box', padding: '6px 8px' } }),
2898
+ React.createElement('span', { style: { opacity: 0.55, fontSize: 12, flex: '0 0 auto' } }, ':'),
2899
+ React.createElement('input', { className: 'dsh-rw-input', value: fwdForm.targetPort, onChange: (e) => setFwdForm({ ...fwdForm, targetPort: e.target.value }), placeholder: tr('settings.fwdTargetPort'), style: { ...inputS, flex: '0 0 72px', width: 72, minWidth: 0, boxSizing: 'border-box', padding: '6px 8px' } })),
2900
+ // Fields on their own row, then the option + primary action: this is
2901
+ // the plugin's existing form pattern (.dsh-rw-settings-editor-actions
2902
+ // right-aligns its primary button), and it keeps 添加转发 from sitting
2903
+ // alone on a wrapped third line.
2904
+ React.createElement('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, marginTop: 8 } },
2905
+ React.createElement('label', { style: { fontSize: 12, display: 'flex', gap: 4, alignItems: 'center', whiteSpace: 'nowrap' } },
2906
+ React.createElement('input', { type: 'checkbox', checked: fwdForm.autoStart, onChange: (e) => requestFwdAutoStart({ kind: 'form' }, !!e.target.checked, fwdForm.direction) }), tr('settings.fwdAuto')),
2647
2907
  React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: primaryBtnS, onClick: fwdDefine, disabled: !fwdForm.listenPort, title: fwdForm.listenPort ? tr('settings.fwdAddHint') : tr('settings.fwdNeedsPort') }, tr('settings.fwdAdd'))),
2908
+ React.createElement('div', { style: { opacity: 0.6, fontSize: 11, lineHeight: 1.5, marginTop: 6 } },
2909
+ tr(fwdForm.direction === 'reverse' ? 'settings.fwdReverseHint' : 'settings.fwdLocalHint')),
2648
2910
  ) : null,
2649
2911
  ),
2650
2912
  React.createElement('div', { style: boxS },
@@ -2894,8 +3156,9 @@ window.__ModuleLoader__.load({
2894
3156
  const matches = (...fields) => !needle || fields.some((f) => String(f || '').toLowerCase().includes(needle))
2895
3157
  const sorted = machines.slice().sort((a, b) => (Date.parse(b.lastConnectedAt) || 0) - (Date.parse(a.lastConnectedAt) || 0))
2896
3158
  const recentProjects = sorted.flatMap((m) => (m.recentWorkspaces || []).filter((p) => matches(m.name, m.host, p)).map((path) => ({ machine: m, path })))
2897
- const aliases = new Set(machines.filter((m) => m.useSshConfig).map((m) => m.host))
2898
- const discovered = (hosts || []).filter((h) => !aliases.has(h.alias || h.host) && matches(h.alias, h.hostName, h.host, h.user))
3159
+ // The picker keeps every saved record too; only discovered aliases are
3160
+ // deduped or hidden behind a saved SSH identity / exact alias.
3161
+ const discovered = dedupeDiscoveredForSaved(hosts || [], sorted).filter((h) => matches(h.alias, h.hostName, h.host, h.user))
2899
3162
  const saved = sorted.filter((m) => matches(m.name, m.host, m.username))
2900
3163
  const chooseAlias = async (h) => {
2901
3164
  if (busy || opening) return
@@ -3086,6 +3349,13 @@ window.__ModuleLoader__.load({
3086
3349
  const cands = [{ host: String(m.host || ''), port: Number(m.port) || 22, username: String(m.username || '') }]
3087
3350
  const r = m.sshConfigResolved
3088
3351
  if (r && r.host) cands.push({ host: String(r.host), port: Number(r.port) || 22, username: String(r.username || m.username || '') })
3352
+ // System OpenSSH hands the alias to ssh and deliberately emits no -l/-p.
3353
+ // Its pool echo is therefore alias/22/'' even when the registry and
3354
+ // resolved config name a concrete user and a non-default SSH Port.
3355
+ // Accept that exact transport identity without making '' a wildcard.
3356
+ const aliasOpenssh = String(m.backend || '').toLowerCase() === 'openssh'
3357
+ && (m.useSshConfig || (r && r.matched))
3358
+ if (aliasOpenssh) cands.push({ host: String(m.host || ''), port: 22, username: '' })
3089
3359
  return cands.some((c) => c.host === String(echo.host) && c.port === (Number(echo.port) || 22) && c.username === String(echo.username || ''))
3090
3360
  }
3091
3361
 
@@ -3403,6 +3673,33 @@ window.__ModuleLoader__.load({
3403
3673
  const res = await api('POST', '/dsh-remote/mirror', { path: target, machineId: selectedMachineId, registerWorkspace: registerWorkspace !== false }, signal)
3404
3674
  if (!current()) return
3405
3675
  if (!res || !res.localMirror) throw new Error((res && res.error) || tr('project.failed'))
3676
+ // dsh-remote-fix2: mirror-cache — record the mirror BEFORE the host adopts it.
3677
+ // `localWorkspaceSession()` classifies a session as local when its
3678
+ // cwd is outside every cached mirror, and the host rejects local
3679
+ // requests for a mirror it binds remotely (409 "Workspace execution
3680
+ // context changed"). The registry here is normally loaded once at
3681
+ // startup, so a mirror created a second ago is missing from it: the
3682
+ // first requests of the new session would be misclassified. Adding
3683
+ // the entry now makes the new session remote from request one; the
3684
+ // delayed refresh below then replaces it with the on-disk record.
3685
+ const newMirror = res.machine || {}
3686
+ const newMirrorDir = String(res.localMirror || '')
3687
+ mirrorGeneration += 1 // supersede any registry request started before this mutation
3688
+ if (newMirrorDir && !MIRRORS.list.some((m) => m && sameMirrorDir(m.dir, newMirrorDir))) {
3689
+ MIRRORS.list.push({
3690
+ dir: newMirrorDir,
3691
+ host: String(newMirror.host || ''),
3692
+ port: Number(newMirror.port) || 22,
3693
+ username: String(newMirror.username || ''),
3694
+ remotePath: String(res.path || target),
3695
+ alias: '',
3696
+ name: '',
3697
+ })
3698
+ }
3699
+ // Keep loaded/error tied to the latest authoritative GET. An optimistic
3700
+ // entry is confirmed, but a partial or failed registry is not healthy.
3701
+ notifyMirrors()
3702
+ setTimeout(() => { void refreshMirrors() }, 2000)
3406
3703
  await onPicked(res.localMirror, res.path || target)
3407
3704
  })
3408
3705
  }
@@ -3844,11 +4141,15 @@ window.__ModuleLoader__.load({
3844
4141
  return api('POST', EXPLORER_AUTO_OPEN_ROUTE, { enabled: on }).catch(() => null)
3845
4142
  }
3846
4143
 
3847
- // A loaded registry plus the session's own cwd proves local vs remote.
3848
- // Registry failure never turns an unrecognised mirror into a local project.
4144
+ // A registry read at least once, plus the session's own cwd, proves local vs
4145
+ // remote. `known` rather than `loaded` is deliberate: `refreshMirrors()`
4146
+ // clears `loaded` while /bindings is in flight, and classifying against that
4147
+ // window demoted a local session to "remote with no root" mid-refresh, which
4148
+ // reset the pane and discarded the refresh the user had just asked for.
4149
+ // Registry failure still never turns an unrecognised mirror into local.
3849
4150
  function localWorkspaceSession(sessionId) {
3850
4151
  const cwd = sessionCwdFor(sessionId)
3851
- return !!(cwd && MIRRORS.loaded && !MIRRORS.error && !mirrorForCwd(cwd, MIRRORS.list))
4152
+ return !!(cwd && MIRRORS.known && !MIRRORS.error && !mirrorForCwd(cwd, MIRRORS.list))
3852
4153
  }
3853
4154
  function workspaceText(key, sessionId, params) {
3854
4155
  return tr(localWorkspaceSession(sessionId) && L.en['local.' + key] ? 'local.' + key : key, params)
@@ -3917,9 +4218,13 @@ window.__ModuleLoader__.load({
3917
4218
  // Failure is not fatal and not retried in a loop: no registry means no
3918
4219
  // badge, which is exactly what a user with zero mirrors sees.
3919
4220
 
3920
- const MIRRORS = { list: [], loaded: false, error: '' }
4221
+ // `loaded` is cleared for the duration of a forced refresh; `known` latches
4222
+ // on the first successful read, so "which workspace is this?" does not
4223
+ // depend on a /bindings round-trip being in flight.
4224
+ const MIRRORS = { list: [], loaded: false, known: false, error: '' }
3921
4225
  const mirrorWatchers = new Set()
3922
- let mirrorLoad = null
4226
+ let mirrorLoad = null // { generation, promise } for the current request only
4227
+ let mirrorGeneration = 0
3923
4228
  let mirrorTimer = null
3924
4229
 
3925
4230
  const notifyMirrors = () => {
@@ -3928,26 +4233,52 @@ window.__ModuleLoader__.load({
3928
4233
  /** Load the mirror registry once (concurrent callers share the request). */
3929
4234
  function ensureMirrors() {
3930
4235
  if (MIRRORS.loaded) return Promise.resolve(MIRRORS)
3931
- if (mirrorLoad) return mirrorLoad
3932
- mirrorLoad = api('GET', '/dsh-remote/bindings')
4236
+ if (mirrorLoad && mirrorLoad.generation === mirrorGeneration) return mirrorLoad.promise
4237
+ const generation = ++mirrorGeneration
4238
+ const promise = api('GET', '/dsh-remote/bindings')
3933
4239
  .then((r) => {
4240
+ if (generation !== mirrorGeneration) return MIRRORS
3934
4241
  MIRRORS.list = (r && Array.isArray(r.mirrors)) ? r.mirrors : []
3935
4242
  MIRRORS.error = ''
4243
+ MIRRORS.known = true
4244
+ })
4245
+ .catch((e) => {
4246
+ if (generation === mirrorGeneration) MIRRORS.error = String((e && e.message) || e)
3936
4247
  })
3937
- .catch((e) => { MIRRORS.error = String((e && e.message) || e) })
3938
4248
  .then(() => {
3939
- MIRRORS.loaded = true
3940
- mirrorLoad = null
3941
- notifyMirrors()
4249
+ if (generation === mirrorGeneration) {
4250
+ MIRRORS.loaded = true
4251
+ notifyMirrors()
4252
+ }
4253
+ // An old request must not clear the pointer of a newer one.
4254
+ if (mirrorLoad && mirrorLoad.generation === generation) mirrorLoad = null
3942
4255
  return MIRRORS
3943
4256
  })
3944
- return mirrorLoad
4257
+ mirrorLoad = { generation, promise }
4258
+ return promise
3945
4259
  }
3946
4260
  /** Force a refresh (mirrors appear when a workspace is picked). */
3947
4261
  function refreshMirrors() {
3948
4262
  MIRRORS.loaded = false
4263
+ mirrorGeneration += 1
3949
4264
  return ensureMirrors()
3950
4265
  }
4266
+
4267
+ /** A client-safe path grammar: Windows drive/UNC paths fold case and
4268
+ * separators; POSIX paths keep case and backslashes. */
4269
+ function mirrorPathKey(value) {
4270
+ const raw = String(value || '')
4271
+ if (!raw) return { windows: false, key: '' }
4272
+ // Detect the grammar BEFORE trimming: C:\ and UNC roots must stay
4273
+ // Windows, while POSIX / remains a real root instead of an empty key.
4274
+ const windows = /^(?:[a-z]:[\\/]|[a-z]:$|[\\/]{2})/i.test(raw)
4275
+ const trimmed = raw.replace(/[\\/]+$/, '')
4276
+ return { windows, key: windows ? trimmed.replace(/\\/g, '/').toLowerCase() : (trimmed || '/') }
4277
+ }
4278
+ function sameMirrorDir(a, b) {
4279
+ const left = mirrorPathKey(a), right = mirrorPathKey(b)
4280
+ return !!(left.key && right.key && left.windows === right.windows && left.key === right.key)
4281
+ }
3951
4282
  /**
3952
4283
  * The mirror containing a local path, or null.
3953
4284
  *
@@ -3957,20 +4288,20 @@ window.__ModuleLoader__.load({
3957
4288
  * case-insensitively because the platform does.
3958
4289
  */
3959
4290
  function mirrorForCwd(cwd, mirrors) {
3960
- const raw = String(cwd || '')
3961
- if (!raw) return null
4291
+ const base = mirrorPathKey(cwd)
4292
+ if (!base.key) return null
3962
4293
  const list = Array.isArray(mirrors) ? mirrors : []
3963
- const isWin = raw.includes('\\')
3964
- const sep = isWin ? '\\' : '/'
3965
- const fold = (s) => (isWin ? s.toLowerCase() : s)
3966
- const base = fold(raw.replace(/[\\/]+$/, ''))
3967
- let best = null
4294
+ let best = null, bestKey = ''
3968
4295
  for (const m of list) {
3969
- const dirRaw = String((m && m.dir) || '').replace(/[\\/]+$/, '')
3970
- if (!dirRaw) continue
3971
- const dir = fold(dirRaw)
3972
- if (base !== dir && !base.startsWith(dir + sep) && !base.startsWith(dir + '/')) continue
3973
- if (!best || dir.length > fold(String(best.dir).replace(/[\\/]+$/, '')).length) best = m
4296
+ const dir = mirrorPathKey(m && m.dir)
4297
+ if (!dir.key || dir.windows !== base.windows) continue
4298
+ if (base.key !== dir.key) {
4299
+ // POSIX root contains every absolute child (dir + '/' would be '//').
4300
+ if (dir.key === '/') {
4301
+ if (!base.key.startsWith('/')) continue
4302
+ } else if (!base.key.startsWith(dir.key) || base.key.charAt(dir.key.length) !== '/') continue
4303
+ }
4304
+ if (dir.key.length > bestKey.length) { best = m; bestKey = dir.key }
3974
4305
  }
3975
4306
  return best
3976
4307
  }
@@ -6519,6 +6850,17 @@ window.__ModuleLoader__.load({
6519
6850
  [data-rw-ide-navigation]{display:flex;gap:3px}
6520
6851
  [data-rw-ide-navigation] button[aria-pressed=true]{background:var(--dsw-alias-interactive-bg-hover,#eee);font-weight:600}
6521
6852
  @media(max-width:600px){[data-rw-ide-header]{gap:5px;padding:0 6px}[data-rw-ide-title]{display:none}[data-rw-ide-header] button{font-size:11px!important;padding:4px 6px!important}}
6853
+ /* macOS desktop (titleBarStyle hiddenInset) floats the native traffic lights at
6854
+ * x 16..68 over the window's top strip, which this shell's header covers. That
6855
+ * strip is 48px tall and its chrome sits on the y=25 centre line (28px controls
6856
+ * at top:11), so the header takes the same height and one pixel of top padding
6857
+ * (at 38px the title sat ~6px above the lights, and plain 48px centring left it
6858
+ * ~1px high). Pad the leading edge by the 88px the host keeps for its fullscreen
6859
+ * panels (lights end at 68, then 20px of air). Fullscreen hides the lights, so
6860
+ * the ordinary 38px header and 12px inset return. The selector out-specifies the
6861
+ * narrow-mode shorthand above, which stays in effect for its right inset. */
6862
+ html[data-platform='darwin'] [data-rw-ide-header]{height:48px;min-height:48px;padding-top:1px;padding-left:88px}
6863
+ html[data-platform='darwin'][data-fullscreen] [data-rw-ide-header]{height:38px;min-height:38px;padding-top:0;padding-left:12px}
6522
6864
  /* Reversible IDE-only header adapter for DSH 0.2.1/0.2.2.
6523
6865
  * Uses published slot/DOM markers rather than compiled class names.
6524
6866
  * Removing data-rw-ide-chat restores all native host styles automatically. */