dsh-remote-vs 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@ import { applyConnectionStatuses, isConnectionRecovery, setActiveConnectionAlias
16
16
  import { EditorPane } from './EditorPane.tsx'
17
17
  import { FloatingEditorPlaceholder } from './FloatingPlaceholder.tsx'
18
18
  import { DownloadDock } from './DownloadDock.tsx'
19
+ import { PortsView, IconPlug } from './PortsView.tsx'
19
20
  import { QuickOpen } from './QuickOpen.tsx'
20
21
  import { RemoteExplorer } from './RemoteExplorer.tsx'
21
22
  import { SearchView } from './SearchView.tsx'
@@ -37,7 +38,7 @@ import {
37
38
  MiniSpinner,
38
39
  } from './vsc/kit.tsx'
39
40
 
40
- type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'workspaces'
41
+ type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'ports' | 'workspaces'
41
42
 
42
43
  const SPLIT_KEY = 'dsh-remote-vs.split'
43
44
  const HIDDEN_KEY = 'dsh-remote-vs.showHidden'
@@ -429,6 +430,10 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
429
430
  // The terminal draws its own header + tab strip, so it takes the whole
430
431
  // slot (no extra padding wrapper).
431
432
  return <TerminalView t={t} hosts={store.hosts} visible={panelLive('terminal')} request={store.terminalRequest} />
433
+ case 'ports':
434
+ // Same shape as the terminal: its own header (host picker + refresh) and
435
+ // its own scroller, so no viewpad wrapper either.
436
+ return <PortsView t={t} hosts={store.hosts} visible={panelLive('ports')} />
432
437
  case 'workspaces':
433
438
  return (
434
439
  <div className="rvs-viewpad" style={{ height: '100%' }}>
@@ -515,6 +520,7 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
515
520
  {editorInStack && store.tabs.length > 0
516
521
  && railButton('editor', store.activeTab?.rel.split('/').pop() ?? t('tab.editor'), <IconDiff size={17} />, store.tabs.length)}
517
522
  {railButton('terminal', t('tab.terminal'), <IconTerminal size={17} />)}
523
+ {railButton('ports', t('tab.ports'), <IconPlug size={17} />)}
518
524
  {railButton('workspaces', t('tab.workspaces'), <IconServer size={17} />, store.workspaces.length)}
519
525
  </div>
520
526
  <div className="rvs-column" ref={columnRef}>
package/src/client/api.ts CHANGED
@@ -16,7 +16,10 @@ import {
16
16
  type RemoteDeployState,
17
17
  type RemoteExecResult,
18
18
  type RemoteFileEntry,
19
+ type RemoteForwardRequest,
20
+ type RemoteForwardState,
19
21
  type RemoteHostSummary,
22
+ type RemoteListenPortsResult,
20
23
  type RemotePluginMeta,
21
24
  type RemoteProbe,
22
25
  type RemoteRead,
@@ -568,6 +571,41 @@ export const api = {
568
571
  importDshSsh: () => post<ImportReport>(REMOTE_API.importDshSsh, {}),
569
572
  // -- terminal
570
573
  terminalClose: (id: string) => post<{ ok: boolean }>(REMOTE_API.terminalClose, { id }),
574
+ // -- port forwards (the port panel's `ssh -L` tunnels)
575
+ /**
576
+ * Live forwards, narrowed to one host when an alias is given.
577
+ *
578
+ * A purely LOCAL read: the Host already holds the tunnels, so the panel can
579
+ * poll this every few seconds without spending a single remote command.
580
+ */
581
+ forwards: (alias?: string) =>
582
+ call<{ forwards: RemoteForwardState[] }>(
583
+ alias === undefined || alias === ''
584
+ ? REMOTE_API.forwards
585
+ : `${REMOTE_API.forwards}?alias=${encodeURIComponent(alias)}`,
586
+ ).then(r => r.forwards),
587
+ /**
588
+ * Open one forward.
589
+ *
590
+ * 400 = the request is not a valid rule, 409 = the local port is taken, 502 =
591
+ * the tunnel could not be established (a refused `direct-tcpip` included) —
592
+ * all three arrive as a `RemoteApiError` whose `message` is the Host's own
593
+ * explanation, which is what the panel shows.
594
+ */
595
+ startForward: (request: RemoteForwardRequest) =>
596
+ post<{ forward: RemoteForwardState }>(REMOTE_API.forwards, request).then(r => r.forward),
597
+ /** Close one forward by its rule id. */
598
+ stopForward: (id: string) =>
599
+ call<{ ok: boolean }>(`${REMOTE_API.forwards}?id=${encodeURIComponent(id)}`, { method: 'DELETE' }),
600
+ /**
601
+ * One bounded probe of the remote host's listening TCP sockets.
602
+ *
603
+ * Costs one remote exec, so the panel asks rarely; `tool: 'none' | 'unknown'`
604
+ * is an honest "cannot enumerate" answer and must not be rendered as "none
605
+ * found" (see `RemoteListenPortsResult`).
606
+ */
607
+ listenPorts: (alias: string) =>
608
+ call<RemoteListenPortsResult>(`${REMOTE_API.listenPorts}?alias=${encodeURIComponent(alias)}`),
571
609
  // -- git (over the exec route; parsed in the browser, no host changes)
572
610
  // Timeouts come from the effective setting: status/log on a huge cold tree
573
611
  // routinely exceed the old fixed 120 s, and the client deadline used to cut
@@ -71,6 +71,7 @@ const zh: Record<string, string> = {
71
71
  'tab.workspaces': '工作区',
72
72
  'tab.files': '文件',
73
73
  'tab.terminal': '终端',
74
+ 'tab.ports': '端口',
74
75
  'tab.remote': '远程',
75
76
  'tab.remoteDesc': '远端文件、终端与 Git',
76
77
  'hosts.title': '远程主机',
@@ -611,12 +612,39 @@ const zh: Record<string, string> = {
611
612
  'quickopen.noResults': '没有匹配的文件',
612
613
  'quickopen.more': '匹配过多,请继续输入',
613
614
  'quickopen.noWorkspace': '没有选定的远端工作区',
615
+ // -- 端口转发(ssh -L):把远端监听的端口映射到本机 127.0.0.1
616
+ 'ports.selectHost': '选择主机',
617
+ 'ports.refresh': '刷新',
618
+ 'ports.remoteHost': '远端地址',
619
+ 'ports.remotePort': '远端端口',
620
+ 'ports.localPort': '本地端口(留空自动分配)',
621
+ 'ports.add': '转发',
622
+ 'ports.active': '已建转发',
623
+ 'ports.listening': '远端监听端口',
624
+ 'ports.emptyForwards': '还没有转发规则:上面的表单新建一条,或从下面的监听端口一键转发。',
625
+ 'ports.noHosts': '还没有主机,请先去「设置 → 远程主机」配置。',
626
+ 'ports.copyUrl': '复制本地 URL',
627
+ 'ports.copied': '已复制',
628
+ 'ports.open': '在浏览器中打开',
629
+ 'ports.stop': '停止转发',
630
+ 'ports.forward': '转发到本地',
631
+ 'ports.stateListening': '监听中',
632
+ 'ports.stateError': '连接失败',
633
+ 'ports.connections': '{count} 个连接',
634
+ 'ports.emptyListen': '远端没有列出监听端口。',
635
+ 'ports.listenUnavailable': '无法枚举远端端口:远端既没有 ss 也没有 netstat。',
636
+ 'ports.listenUnknown': '无法枚举远端端口:探测没有返回结果。',
637
+ 'ports.badPort': '端口必须是 1–65535 的整数;本地端口留空表示自动分配。',
638
+ 'ports.restoreFailed': '{count} 条已保存的转发规则未能恢复:本地端口可能被占用,或已超过每台主机的规则上限。',
639
+ 'ports.forgetFailed': '移除这些规则',
640
+ 'ports.remoteHostHint': '目标地址由远端主机拨号,可访问远端内网;本地监听只绑定 127.0.0.1。',
614
641
  }
615
642
 
616
643
  const en: Record<string, string> = {
617
644
  'tab.workspaces': 'Workspaces',
618
645
  'tab.files': 'Files',
619
646
  'tab.terminal': 'Terminal',
647
+ 'tab.ports': 'Ports',
620
648
  'tab.remote': 'Remote',
621
649
  'tab.remoteDesc': 'Remote files, terminal and Git',
622
650
  'hosts.title': 'Remote hosts',
@@ -1157,6 +1185,32 @@ const en: Record<string, string> = {
1157
1185
  'quickopen.noResults': 'No matching file',
1158
1186
  'quickopen.more': 'Too many matches — keep typing',
1159
1187
  'quickopen.noWorkspace': 'No remote workspace is selected',
1188
+ // -- Port forwards (ssh -L): map a remote listening port onto this machine
1189
+ 'ports.selectHost': 'Select host',
1190
+ 'ports.refresh': 'Refresh',
1191
+ 'ports.remoteHost': 'Remote address',
1192
+ 'ports.remotePort': 'Remote port',
1193
+ 'ports.localPort': 'Local port (empty = auto)',
1194
+ 'ports.add': 'Forward',
1195
+ 'ports.active': 'Forwards',
1196
+ 'ports.listening': 'Listening on the remote host',
1197
+ 'ports.emptyForwards': 'No forwards yet — add one above, or forward a listening port below.',
1198
+ 'ports.noHosts': 'No hosts yet. Configure one under Settings → Remote hosts first.',
1199
+ 'ports.copyUrl': 'Copy local URL',
1200
+ 'ports.copied': 'Copied',
1201
+ 'ports.open': 'Open in browser',
1202
+ 'ports.stop': 'Stop forward',
1203
+ 'ports.forward': 'Forward to local',
1204
+ 'ports.stateListening': 'Listening',
1205
+ 'ports.stateError': 'Connection failed',
1206
+ 'ports.connections': '{count} connection(s)',
1207
+ 'ports.emptyListen': 'The remote host listed no listening ports.',
1208
+ 'ports.listenUnavailable': 'Cannot enumerate remote ports: neither ss nor netstat is available on the host.',
1209
+ 'ports.listenUnknown': 'Cannot enumerate remote ports: the probe did not answer.',
1210
+ 'ports.badPort': 'Port must be an integer between 1 and 65535; leave the local port empty to auto-assign.',
1211
+ 'ports.restoreFailed': '{count} saved forward(s) could not be restored — the local port may be taken, or the per-host rule limit reached.',
1212
+ 'ports.forgetFailed': 'Forget these rules',
1213
+ 'ports.remoteHostHint': 'The target is dialed from the remote host, so it can reach that host’s private network; the local listener binds 127.0.0.1 only.',
1160
1214
  }
1161
1215
 
1162
1216
  export type Lang = 'zh' | 'en'
@@ -219,7 +219,7 @@ interface State {
219
219
  }
220
220
 
221
221
  /** The sidebar rail destinations. */
222
- export type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'workspaces'
222
+ export type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'ports' | 'workspaces'
223
223
 
224
224
  /** One "search this folder" request coming from the tree. */
225
225
  export interface SearchRequest {
@@ -415,7 +415,7 @@ function readStoredView(): RailView {
415
415
  try {
416
416
  const saved = localStorage.getItem(VIEW_KEY)
417
417
  if (saved === 'explorer' || saved === 'search' || saved === 'scm' || saved === 'history'
418
- || saved === 'editor' || saved === 'terminal' || saved === 'workspaces') {
418
+ || saved === 'editor' || saved === 'terminal' || saved === 'ports' || saved === 'workspaces') {
419
419
  return saved
420
420
  }
421
421
  } catch {
@@ -3982,6 +3982,188 @@ body[data-ds-dark-theme] .rvs-execpanel {
3982
3982
 
3983
3983
 
3984
3984
 
3985
+ /* ------------------------------------------------------------ port forwards */
3986
+
3987
+ /**
3988
+ * The port panel: one form above two lists, all inside the sidebar column.
3989
+ *
3990
+ * The column can be dragged very narrow, so nothing here may assume a width: an
3991
+ * address/URL is ONE unbreakable token (`overflow-wrap: anywhere`), the action
3992
+ * row wraps instead of overflowing, and the form stacks vertically — a
3993
+ * three-input row is unusable at the panel's default width.
3994
+ */
3995
+ .rvs-ports-body {
3996
+ flex: 1;
3997
+ min-height: 0;
3998
+ overflow: auto;
3999
+ padding: 8px 8px 14px;
4000
+ }
4001
+
4002
+ /**
4003
+ * The restore-failure banner: one sentence plus the "forget these rules"
4004
+ * action, side by side when there is room and stacked when the column is very
4005
+ * narrow (the action must never squeeze the explanation into a sliver).
4006
+ */
4007
+ .rvs-ports-restore {
4008
+ display: flex;
4009
+ align-items: center;
4010
+ flex-wrap: wrap;
4011
+ gap: 6px;
4012
+ }
4013
+
4014
+ .rvs-ports-form {
4015
+ display: flex;
4016
+ flex-direction: column;
4017
+ gap: 6px;
4018
+ padding: 8px;
4019
+ border: 1px solid var(--rvs-border2);
4020
+ border-radius: 8px;
4021
+ }
4022
+
4023
+ .rvs-ports-field {
4024
+ display: flex;
4025
+ flex-direction: column;
4026
+ gap: 3px;
4027
+ min-width: 0;
4028
+ }
4029
+
4030
+ .rvs-ports-label {
4031
+ color: var(--rvs-fg3);
4032
+ font-size: 11px;
4033
+ }
4034
+
4035
+ /* `.rvs-input` carries `flex: 1`; in a COLUMN flex parent that would stretch
4036
+ the field's HEIGHT, so the input fills the width and keeps its own height. */
4037
+ .rvs-ports-input {
4038
+ flex: none;
4039
+ width: 100%;
4040
+ box-sizing: border-box;
4041
+ }
4042
+
4043
+ .rvs-ports-form-actions {
4044
+ display: flex;
4045
+ justify-content: flex-end;
4046
+ }
4047
+
4048
+ .rvs-ports-section {
4049
+ margin-top: 12px;
4050
+ border-top: 1px solid var(--rvs-border);
4051
+ }
4052
+
4053
+ .rvs-ports-sec-head {
4054
+ display: flex;
4055
+ align-items: center;
4056
+ gap: 6px;
4057
+ height: 26px;
4058
+ padding: 0 4px;
4059
+ color: var(--rvs-fg2);
4060
+ font-size: 11px;
4061
+ font-weight: 700;
4062
+ letter-spacing: .04em;
4063
+ text-transform: uppercase;
4064
+ user-select: none;
4065
+ }
4066
+
4067
+ .rvs-ports-count {
4068
+ padding: 0 6px;
4069
+ border-radius: 999px;
4070
+ background: var(--rvs-hover);
4071
+ color: var(--rvs-fg3);
4072
+ font-size: 10.5px;
4073
+ letter-spacing: 0;
4074
+ }
4075
+
4076
+ .rvs-ports-row {
4077
+ display: flex;
4078
+ flex-direction: column;
4079
+ gap: 3px;
4080
+ min-width: 0;
4081
+ padding: 6px 6px 7px;
4082
+ border-radius: 6px;
4083
+ }
4084
+
4085
+ .rvs-ports-row:hover {
4086
+ background: var(--rvs-hover);
4087
+ }
4088
+
4089
+ .rvs-ports-line {
4090
+ display: flex;
4091
+ align-items: baseline;
4092
+ gap: 6px;
4093
+ min-width: 0;
4094
+ }
4095
+
4096
+ .rvs-ports-addr {
4097
+ flex: 1;
4098
+ min-width: 0;
4099
+ overflow-wrap: anywhere;
4100
+ color: var(--rvs-fg);
4101
+ font-family: var(--rvs-mono);
4102
+ font-size: 11.5px;
4103
+ line-height: 1.45;
4104
+ }
4105
+
4106
+ .rvs-ports-proc {
4107
+ flex: 0 1 auto;
4108
+ min-width: 0;
4109
+ overflow: hidden;
4110
+ text-overflow: ellipsis;
4111
+ white-space: nowrap;
4112
+ color: var(--rvs-fg3);
4113
+ font-size: 11px;
4114
+ }
4115
+
4116
+ /* State is never colour-only: the dot carries the state word as its label. */
4117
+ .rvs-ports-dot {
4118
+ flex: none;
4119
+ width: 7px;
4120
+ height: 7px;
4121
+ border-radius: 50%;
4122
+ background: var(--rvs-fg3);
4123
+ }
4124
+
4125
+ .rvs-ports-dot.listening {
4126
+ background: var(--rvs-ok, #2ea043);
4127
+ }
4128
+
4129
+ .rvs-ports-dot.error {
4130
+ background: var(--rvs-danger);
4131
+ }
4132
+
4133
+ .rvs-ports-conn {
4134
+ color: var(--rvs-fg3);
4135
+ font-size: 11px;
4136
+ white-space: nowrap;
4137
+ }
4138
+
4139
+ .rvs-ports-err {
4140
+ color: var(--rvs-danger);
4141
+ font-size: 11px;
4142
+ line-height: 1.45;
4143
+ overflow-wrap: anywhere;
4144
+ }
4145
+
4146
+ .rvs-ports-actions {
4147
+ display: flex;
4148
+ align-items: center;
4149
+ flex-wrap: wrap;
4150
+ gap: 2px;
4151
+ min-width: 0;
4152
+ }
4153
+
4154
+ /* The "open" affordance is a real link styled as a header button. */
4155
+ .rvs-ports-open {
4156
+ text-decoration: none;
4157
+ }
4158
+
4159
+ .rvs-ports-hint {
4160
+ margin-top: 4px;
4161
+ color: var(--rvs-fg3);
4162
+ font-size: 11px;
4163
+ line-height: 1.45;
4164
+ overflow-wrap: anywhere;
4165
+ }
4166
+
3985
4167
  /* ------------------------------------------------------ Ctrl+P quick open */
3986
4168
 
3987
4169
  .rvs-qo-mask {
@@ -4147,3 +4329,4 @@ body[data-ds-dark-theme] .rvs-execpanel {
4147
4329
  .rvs-qo-note.warn {
4148
4330
  color: var(--rvs-git-m);
4149
4331
  }
4332
+