dsh-remote-vs 0.16.0 → 0.17.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.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Ports view: the `ssh -L` tunnels this client owns, plus a way to make more.
3
+ *
4
+ * Why a panel instead of a hidden command: a forward the panel does not show is
5
+ * invisible state. The listener lives in the HOST process, so closing the
6
+ * sidebar, switching hosts or reloading the page must not look like "the tunnel
7
+ * is gone" while it still holds a local port. The list is therefore the Host's
8
+ * own answer (a local-only read, polled), the rules the user created are
9
+ * remembered by the BROWSER, and a reload restores them — the listener belongs
10
+ * to the Host, the memory of why it exists belongs here.
11
+ *
12
+ * Two costs shape the polling: the forward list is a local JSON read (cheap, so
13
+ * every 4 s while visible), whereas the listening-port probe runs a remote
14
+ * command (`ss`/`netstat`) and is therefore rare: on mount, on an explicit
15
+ * refresh, and once every 30 s.
16
+ */
17
+ import { type ReactNode } from 'react';
18
+ import type { RemoteHostSummary } from '../protocol.ts';
19
+ /**
20
+ * Rail icon: a plug. Kept here rather than in `vsc/kit.tsx` because it is the
21
+ * only screen that draws one, and the shared icon set is a curated list.
22
+ */
23
+ export declare function IconPlug(props: {
24
+ size?: number;
25
+ }): ReactNode;
26
+ export declare function PortsView(props: {
27
+ t: (key: string) => string;
28
+ hosts: RemoteHostSummary[];
29
+ visible: boolean;
30
+ }): ReactNode;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Typed fetch wrapper over the /api/dsh-remote JSON API (full P0 surface).
3
3
  */
4
- import { type GitBranch, type GitCommit, type GitShow, type GitStatus, type HelperAvailability, type ImportReport, type RemoteChangesDiff, type RemoteChangesSummary, type RemoteConnectionStatus, type RemoteDeployState, type RemoteExecResult, type RemoteFileEntry, type RemoteHostSummary, type RemotePluginMeta, type RemoteProbe, type RemoteRead, type RemoteRoutingStatus, type RemoteTimeouts, type RemoteWorkspaceBinding, type RemoteWriteConflict, type RemoteWriteResult } from '../protocol.ts';
4
+ import { type GitBranch, type GitCommit, type GitShow, type GitStatus, type HelperAvailability, type ImportReport, type RemoteChangesDiff, type RemoteChangesSummary, type RemoteConnectionStatus, type RemoteDeployState, type RemoteExecResult, type RemoteFileEntry, type RemoteForwardRequest, type RemoteForwardState, type RemoteHostSummary, type RemoteListenPortsResult, type RemotePluginMeta, type RemoteProbe, type RemoteRead, type RemoteRoutingStatus, type RemoteTimeouts, type RemoteWorkspaceBinding, type RemoteWriteConflict, type RemoteWriteResult } from '../protocol.ts';
5
5
  export declare class RemoteApiError extends Error {
6
6
  readonly status: number;
7
7
  /**
@@ -229,6 +229,34 @@ export declare const api: {
229
229
  terminalClose: (id: string) => Promise<{
230
230
  ok: boolean;
231
231
  }>;
232
+ /**
233
+ * Live forwards, narrowed to one host when an alias is given.
234
+ *
235
+ * A purely LOCAL read: the Host already holds the tunnels, so the panel can
236
+ * poll this every few seconds without spending a single remote command.
237
+ */
238
+ forwards: (alias?: string) => Promise<RemoteForwardState[]>;
239
+ /**
240
+ * Open one forward.
241
+ *
242
+ * 400 = the request is not a valid rule, 409 = the local port is taken, 502 =
243
+ * the tunnel could not be established (a refused `direct-tcpip` included) —
244
+ * all three arrive as a `RemoteApiError` whose `message` is the Host's own
245
+ * explanation, which is what the panel shows.
246
+ */
247
+ startForward: (request: RemoteForwardRequest) => Promise<RemoteForwardState>;
248
+ /** Close one forward by its rule id. */
249
+ stopForward: (id: string) => Promise<{
250
+ ok: boolean;
251
+ }>;
252
+ /**
253
+ * One bounded probe of the remote host's listening TCP sockets.
254
+ *
255
+ * Costs one remote exec, so the panel asks rarely; `tool: 'none' | 'unknown'`
256
+ * is an honest "cannot enumerate" answer and must not be rendered as "none
257
+ * found" (see `RemoteListenPortsResult`).
258
+ */
259
+ listenPorts: (alias: string) => Promise<RemoteListenPortsResult>;
232
260
  git: {
233
261
  status(alias: string, path: string): Promise<GitStatus>;
234
262
  log(alias: string, path: string, max: number, branch?: string): Promise<GitCommit[]>;
@@ -117,7 +117,7 @@ export interface HeadInfo {
117
117
  behind: number;
118
118
  }
119
119
  /** The sidebar rail destinations. */
120
- export type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'workspaces';
120
+ export type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'ports' | 'workspaces';
121
121
  /** One "search this folder" request coming from the tree. */
122
122
  export interface SearchRequest {
123
123
  /** Monotonic id so a repeated request still re-triggers the view. */
@@ -0,0 +1,114 @@
1
+ import type { ClientChannel } from 'ssh2';
2
+ import type { RemoteForwardRequest, RemoteForwardState } from './protocol.ts';
3
+ /** Most simultaneous forward rules one host may carry. */
4
+ export declare const FORWARD_MAX_PER_ALIAS = 16;
5
+ /** Most TCP connections one rule accepts at once (browsers open several). */
6
+ export declare const FORWARD_MAX_CONNECTIONS = 32;
7
+ /**
8
+ * The pool surface the manager needs.
9
+ *
10
+ * Structural on purpose: the gate drives a fake pool without an SSH server, and
11
+ * the manager never reaches into the pool beyond one call.
12
+ */
13
+ export interface ForwardPoolLike {
14
+ forwardOut(alias: string, dstHost: string, dstPort: number, srcPort?: number): Promise<ClientChannel>;
15
+ }
16
+ export interface ForwardManagerDeps {
17
+ pool: ForwardPoolLike;
18
+ /** Diagnostic sink; defaults to a no-op (the Host wires its logger). */
19
+ log?: (level: 'info' | 'warn', message: string) => void;
20
+ /** Test seam: bound rules per alias. */
21
+ maxPerAlias?: number;
22
+ /** Test seam: concurrent connections per rule. */
23
+ maxConnections?: number;
24
+ }
25
+ /** One validated rule request. */
26
+ export type ForwardValidation = {
27
+ ok: true;
28
+ value: RemoteForwardRequest;
29
+ } | {
30
+ ok: false;
31
+ error: string;
32
+ };
33
+ /**
34
+ * Validate one request from the browser.
35
+ *
36
+ * `localPort` deliberately accepts 0 = "let the OS pick": the panel defaults to
37
+ * auto-assignment because a fixed port invites EADDRINUSE from whatever else
38
+ * the developer runs locally.
39
+ */
40
+ export declare function validateForwardRequest(input: unknown): ForwardValidation;
41
+ /**
42
+ * Stable rule identity.
43
+ *
44
+ * `localPort` is the port the CALLER asked for (0 = auto), not the one the OS
45
+ * assigned: asking twice for the same automatic rule must return the running
46
+ * forward instead of opening a second listener on a second random port.
47
+ */
48
+ export declare function forwardIdOf(alias: string, remoteHost: string, remotePort: number, localPort: number): string;
49
+ /** What the panel copies / opens for one forward. */
50
+ export declare function forwardLocalUrl(localPort: number): string;
51
+ /** Listens on loopback and proxies every accepted connection over SSH. */
52
+ export declare class ForwardManager {
53
+ private readonly deps;
54
+ private readonly forwards;
55
+ /**
56
+ * Rules whose listener is still BINDING.
57
+ *
58
+ * Two clicks (or a restore racing the panel's own poll) must share one bind:
59
+ * without this map the second call binds a SECOND listener on a different
60
+ * automatic port, overwrites the first entry in `forwards`, and leaves the
61
+ * first listener orphaned — unreachable from the panel and never closed.
62
+ */
63
+ private readonly starting;
64
+ /** Set on unload so a bind that settles afterwards closes itself. */
65
+ private disposed;
66
+ constructor(deps: ForwardManagerDeps);
67
+ /**
68
+ * Start one rule (idempotent for the same requested tuple).
69
+ *
70
+ * Resolves with the state once the local listener is BOUND; a bind failure
71
+ * (EADDRINUSE, permission) rejects, which the route maps to a caller-visible
72
+ * status. A remote-side failure cannot be known yet — the first connection
73
+ * discovers it and records it on the rule.
74
+ */
75
+ start(request: RemoteForwardRequest): Promise<RemoteForwardState>;
76
+ /** Stop one rule. Returns false when the id is unknown (already stopped). */
77
+ stop(id: string): boolean;
78
+ /**
79
+ * Stop every rule for one host alias (the host was deleted).
80
+ *
81
+ * A deleted host disappears from the panel — there is no row left to press
82
+ * "stop" on — so leaving its listeners bound would squat the local ports
83
+ * until the Host restarts. Returns how many rules were closed.
84
+ */
85
+ stopAlias(alias: string): number;
86
+ /**
87
+ * Stop every rule but keep the manager alive (plugin disabled).
88
+ *
89
+ * `dispose()` is the unload path and flips a flag that makes later binds
90
+ * throw; a settings toggle needs the listeners gone without burning the
91
+ * instance, because re-enabling the plugin must be able to start rules again.
92
+ */
93
+ stopAll(): number;
94
+ /** Every rule, optionally narrowed to one host alias. */
95
+ list(alias?: string): RemoteForwardState[];
96
+ /** Close every listener and every proxied connection (plugin unload). */
97
+ dispose(): void;
98
+ /** Bind the loopback listener. Split out so the error path is one place. */
99
+ private bindForward;
100
+ /** One accepted local TCP connection: bound, or refused when the rule is full. */
101
+ private accept;
102
+ /**
103
+ * Open one direct-tcpip channel for a local socket and pipe both ways.
104
+ *
105
+ * The channel is opened through the pool, so a dropped SSH connection is
106
+ * re-dialed per new local connection; an in-flight one fails with the pool's
107
+ * reason and is recorded on the rule.
108
+ */
109
+ private connect;
110
+ /** Tear one rule down: listener, then every proxied connection. */
111
+ private closeForward;
112
+ private stateOf;
113
+ private log;
114
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Remote listening-TCP-socket enumeration for the port panel.
3
+ *
4
+ * One bounded POSIX one-liner does the work: `ss` (iproute2, every modern
5
+ * Linux) first, `netstat` as the fallback (older Linux, and macOS with a
6
+ * different address spelling), and an explicit `none` when neither exists. The
7
+ * answer is a POOL of three facts the panel must keep apart:
8
+ *
9
+ * - `none` / `unknown` are "cannot enumerate", never "no ports are open";
10
+ * - a tool that ran but produced nothing recognizable is a parse failure, not
11
+ * an empty machine;
12
+ * - process names are only visible for the invoking user's own processes
13
+ * (`ss -p` is allowed for everyone, but the kernel hides other users'
14
+ * sockets), so a missing name is UNKNOWN, not "not a service".
15
+ *
16
+ * Pure functions only (command builder + parser) so the gate can feed real
17
+ * sample outputs; the route owns the exec round trip and its deadline.
18
+ */
19
+ import type { RemoteListenPortsResult } from './protocol.ts';
20
+ /** Prefix of every control line the probe prints (also the "did it answer" proof). */
21
+ export declare const LISTEN_PORTS_MARK = "@@RVS-PORTS";
22
+ /**
23
+ * Budget for the whole probe. A handful of local commands over one channel; if
24
+ * `ss` hangs (a stuck kernel table), the route answers with the exec deadline
25
+ * instead of holding the panel's refresh forever.
26
+ */
27
+ export declare const LISTEN_PORTS_TIMEOUT_MS = 15000;
28
+ /**
29
+ * Most listeners one probe reports. A container host or a dev box running a
30
+ * port scanner can have thousands; the panel is a picker, not an inventory.
31
+ */
32
+ export declare const LISTEN_PORTS_MAX = 500;
33
+ /**
34
+ * The remote probe line.
35
+ *
36
+ * `if/elif/fi` rather than `a && b || c` chains: the shell's operator
37
+ * precedence would make a failing `ss` fall through into `netstat`'s branch in
38
+ * ways that depend on the last command's status, and one missing tool would be
39
+ * indistinguishable from a tool that ran and failed.
40
+ *
41
+ * `-p` is requested first and silently degrades to `-n`: it only ADDS process
42
+ * names, and it is allowed for a non-root user (the kernel just omits other
43
+ * users' sockets). `netstat -an` is the last resort for macOS, whose `-l` is
44
+ * not the Linux spelling; the parser understands both the colon and the dotted
45
+ * `addr.port` form.
46
+ */
47
+ export declare function listenPortsCommand(): string;
48
+ /**
49
+ * Parse one probe's stdout into the panel's result.
50
+ *
51
+ * @param stdout - the probe's standard output (both tools plus markers).
52
+ * @param exitCode - the exec exit code; a non-zero run with no `end` marker is
53
+ * reported as `unknown`, because an interrupted probe proves nothing about
54
+ * the ports it never reached.
55
+ */
56
+ export declare function parseListenPorts(stdout: string, exitCode: number | null): RemoteListenPortsResult;
@@ -129,6 +129,24 @@ export declare class RemotePool {
129
129
  shell(alias: string, opts?: ShellOptions): Promise<ClientChannel>;
130
130
  /** Open one exec channel. The caller owns the channel lifecycle. */
131
131
  execChannel(alias: string, command: string): Promise<ClientChannel>;
132
+ /**
133
+ * Open one direct-tcpip channel to a TCP target reachable FROM the remote
134
+ * host (`ssh -L` semantics). The caller owns the channel lifecycle.
135
+ *
136
+ * Deliberately NOT routed through `acquireSlot`: that table bounds the pool's
137
+ * own request channels (exec / SFTP) and its ceiling leaves room for the
138
+ * long-lived channels the pool does not count (PTY terminals, the subprocess
139
+ * runtime, the helper). A local forward is the same kind of long-lived
140
+ * channel, so the port panel keeps its own per-alias budget instead.
141
+ *
142
+ * A channel-open failure is NOT a connection failure: sshd answers
143
+ * "administratively prohibited" when forwarding is forbidden and "connect
144
+ * failed" when the remote port is closed — both on a perfectly healthy link,
145
+ * and painting the connection chip red for either would send the user to
146
+ * debug their network. Real transport failures still arrive through the
147
+ * pooled connection's own close/error events.
148
+ */
149
+ forwardOut(alias: string, dstHost: string, dstPort: number, srcPort?: number): Promise<ClientChannel>;
132
150
  /** Run one callback with a fresh SFTP session (closed afterwards). */
133
151
  withSftp<T>(alias: string, fn: (sftp: SFTPWrapper) => Promise<T>, opts?: SftpOptions): Promise<T>;
134
152
  /**
@@ -33,6 +33,10 @@ export declare const REMOTE_API: {
33
33
  readonly sessionCwd: "/api/dsh-remote/session-cwd";
34
34
  /** What one live session changed on its remote host (the review panel). */
35
35
  readonly changes: "/api/dsh-remote/changes";
36
+ /** Local TCP forwards (`ssh -L` semantics) for the port panel. */
37
+ readonly forwards: "/api/dsh-remote/forwards";
38
+ /** Remote listening TCP sockets for the port panel (one bounded probe). */
39
+ readonly listenPorts: "/api/dsh-remote/listen-ports";
36
40
  };
37
41
  /**
38
42
  * Most entries one multi-selection download may archive. The selection rides in
@@ -550,3 +554,71 @@ export interface GitShow {
550
554
  body: string;
551
555
  stat: string;
552
556
  }
557
+ /**
558
+ * One request to forward a local TCP port to a target reachable from the
559
+ * remote host — the port panel's manual rule and its one-click "forward this
560
+ * discovered port" button both send exactly this shape.
561
+ *
562
+ * The local listener is ALWAYS bound to 127.0.0.1 (never 0.0.0.0): a forward is
563
+ * `ssh -L`, so anything the user's machine can reach through it is what ssh -L
564
+ * grants — exposing it on the LAN is not part of this feature.
565
+ */
566
+ export interface RemoteForwardRequest {
567
+ /** Host alias the tunnel runs through. */
568
+ alias: string;
569
+ /** Target address AS THE REMOTE HOST RESOLVES IT (`127.0.0.1` by default). */
570
+ remoteHost: string;
571
+ /** Target port on that address. */
572
+ remotePort: number;
573
+ /**
574
+ * Requested local port, or 0/omitted to let the OS assign one.
575
+ *
576
+ * The panel asks for 0 by default: picking a fixed port invites EADDRINUSE
577
+ * from whatever else the developer runs locally.
578
+ */
579
+ localPort?: number;
580
+ }
581
+ /** One live local forward, as the port panel renders it. */
582
+ export interface RemoteForwardState {
583
+ /** Stable rule id (`alias|remoteHost|remotePort|localPort-as-requested`). */
584
+ id: string;
585
+ alias: string;
586
+ remoteHost: string;
587
+ remotePort: number;
588
+ /** The port actually bound (resolved when the request asked for 0). */
589
+ localPort: number;
590
+ /** URL to copy / open; loopback HTTP is the overwhelmingly common case. */
591
+ localUrl: string;
592
+ /** `error` means the last connection attempt failed; the listener is alive. */
593
+ state: 'listening' | 'error';
594
+ /** Currently open TCP connections through this rule. */
595
+ connections: number;
596
+ /** Cumulative bytes in each direction (diagnostic, not a quota). */
597
+ bytesIn: number;
598
+ bytesOut: number;
599
+ /** Last connect/bind failure, human-readable. */
600
+ lastError?: string;
601
+ startedAt: number;
602
+ }
603
+ /** One listening TCP socket on the remote host. */
604
+ export interface RemoteListenPort {
605
+ /** Bind address exactly as the remote tool printed it (`0.0.0.0`, `::`, `*`, `127.0.0.1`). */
606
+ addr: string;
607
+ port: number;
608
+ /** Process name when the remote tool revealed it (usually only own processes). */
609
+ process?: string;
610
+ }
611
+ /**
612
+ * The remote listening-port probe's answer.
613
+ *
614
+ * `tool` says what actually ran: `none` means the host has neither `ss` nor
615
+ * `netstat` (an honest "cannot enumerate", not "no ports"), and `unknown`
616
+ * means the probe did not answer at all. The panel must render those as an
617
+ * explanation, never as an empty list.
618
+ */
619
+ export interface RemoteListenPortsResult {
620
+ tool: 'ss' | 'netstat' | 'none' | 'unknown';
621
+ ports: RemoteListenPort[];
622
+ /** Why the probe could not be used, when it could not. */
623
+ error?: string;
624
+ }
@@ -5,6 +5,7 @@ import type { RemoteStore } from './store.ts';
5
5
  import type { RemotePool } from './pool.ts';
6
6
  import type { RemoteWorlds } from './p2/worlds.ts';
7
7
  import { TerminalSessionRegistry } from './terminal.ts';
8
+ import { ForwardManager } from './forward.ts';
8
9
  import type { SessionChanges } from './changes/recorder.ts';
9
10
  /**
10
11
  * Wrap one archive command in a remote-side deadline.
@@ -37,6 +38,12 @@ export interface RemoteRoutesDeps {
37
38
  timeouts?: () => RemoteTimeouts;
38
39
  /** Session change ledger, when the host half mounted one. */
39
40
  changes?: SessionChanges;
41
+ /**
42
+ * Live local port forwards. Absent only in route-only probes (the gates build
43
+ * `makeRoutes` with the minimum they need): the port routes then answer 503
44
+ * instead of pretending the feature exists.
45
+ */
46
+ forwards?: ForwardManager;
40
47
  }
41
48
  export declare function makeRoutes(deps: RemoteRoutesDeps): {
42
49
  routes: WebRoute[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-remote-vs",
3
3
  "description": "VSCode-style remote development for DSH: SSH host manager (key/password), helper deploy pipeline with version check, remote file explorer + editor + terminal in dsh-better-sidebar.",
4
- "version": "0.16.0",
4
+ "version": "0.17.0",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
7
7
  "dsh",