dsh-remote-vs 0.15.1 → 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.
- package/README.en.md +18 -10
- package/README.md +18 -10
- package/lib/client.js +1581 -18
- package/lib/index.js +692 -5
- package/lib/types/client/PortsView.d.ts +30 -0
- package/lib/types/client/ai-review.d.ts +116 -0
- package/lib/types/client/api.d.ts +29 -1
- package/lib/types/client/composer.d.ts +15 -0
- package/lib/types/client/drag-expand.d.ts +78 -0
- package/lib/types/client/store.d.ts +1 -1
- package/lib/types/forward.d.ts +114 -0
- package/lib/types/listen-ports.d.ts +56 -0
- package/lib/types/pool.d.ts +18 -0
- package/lib/types/protocol.d.ts +72 -0
- package/lib/types/routes.d.ts +7 -0
- package/package.json +1 -1
- package/src/client/PortsView.tsx +850 -0
- package/src/client/RemoteExplorer.tsx +201 -16
- package/src/client/RemoteRoot.tsx +7 -1
- package/src/client/ai-review.ts +428 -0
- package/src/client/api.ts +38 -0
- package/src/client/composer.ts +18 -0
- package/src/client/drag-expand.ts +128 -0
- package/src/client/i18n.ts +78 -0
- package/src/client/scm/CommitPane.tsx +71 -0
- package/src/client/scm/DiffView.tsx +85 -1
- package/src/client/store.tsx +2 -2
- package/src/client/vsc/vsc.css +183 -0
- package/src/forward.ts +445 -0
- package/src/index.ts +40 -1
- package/src/listen-ports.ts +241 -0
- package/src/pool.ts +63 -0
- package/src/protocol.ts +76 -0
- package/src/routes.ts +125 -0
|
@@ -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;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/** Largest complete diff we inline into the prompt, in BYTES (≈8–10k tokens). */
|
|
2
|
+
export declare const AI_REVIEW_MAX_BYTES: number;
|
|
3
|
+
/** How many `@@` headers a summary prompt enumerates before it stops. */
|
|
4
|
+
export declare const AI_REVIEW_MAX_HUNKS = 40;
|
|
5
|
+
/** How much of the diff the prompt carries. */
|
|
6
|
+
export type ReviewMode = 'full' | 'summary' | 'pathOnly';
|
|
7
|
+
/** Which revision range the diff describes (the SCM view's three diff tabs). */
|
|
8
|
+
export type ReviewScope = 'worktree' | 'staged' | 'commit';
|
|
9
|
+
/** Prompt language. Follows the UI language (`store.lang`), no separate setting. */
|
|
10
|
+
export type ReviewLang = 'zh' | 'en';
|
|
11
|
+
/** Everything the prompt template needs, all of it already in the caller's hands. */
|
|
12
|
+
export interface ReviewPromptInput {
|
|
13
|
+
/** SSH host alias the diff was read from (named in the prompt, no secrets). */
|
|
14
|
+
alias: string;
|
|
15
|
+
/** Repository root on that host (absolute POSIX path). */
|
|
16
|
+
root: string;
|
|
17
|
+
/** Repository-relative path of the file. */
|
|
18
|
+
rel: string;
|
|
19
|
+
/** Absolute remote path of the file. */
|
|
20
|
+
fullPath: string;
|
|
21
|
+
scope: ReviewScope;
|
|
22
|
+
/** The commit the diff was drilled down from, for `scope: 'commit'`. */
|
|
23
|
+
commitRef?: string;
|
|
24
|
+
/** Unified diff text (`tab.diff.diff`), possibly empty for untracked/binary. */
|
|
25
|
+
diff: string;
|
|
26
|
+
mode: ReviewMode;
|
|
27
|
+
/** The diff is a `GIT_CAP`-capped PREFIX (the host truncated it silently). */
|
|
28
|
+
capped: boolean;
|
|
29
|
+
lang: ReviewLang;
|
|
30
|
+
}
|
|
31
|
+
/** UTF-8 byte length — the unit `head -c` and therefore `GIT_CAP` count. */
|
|
32
|
+
export declare function diffByteLength(diff: string): number;
|
|
33
|
+
/**
|
|
34
|
+
* Which revision range a diff tab shows.
|
|
35
|
+
*
|
|
36
|
+
* `ref` wins over `staged`, and that order is load-bearing: a commit drill-down
|
|
37
|
+
* tab is BOTH `staged: true` and `ref: hash` (`store.openCommitFile`), so asking
|
|
38
|
+
* `staged` first would label a commit's diff as "staged changes" and point the
|
|
39
|
+
* model at the index instead of the commit.
|
|
40
|
+
*/
|
|
41
|
+
export declare function reviewScopeOf(staged: boolean, ref: string | undefined): ReviewScope;
|
|
42
|
+
/**
|
|
43
|
+
* Which prompt shape this diff gets.
|
|
44
|
+
*
|
|
45
|
+
* Order matters. `pathOnly` answers "there is no diff text at all" (untracked /
|
|
46
|
+
* binary / failed read) and outranks the rest because it needs no budget.
|
|
47
|
+
* `capped` outranks the size test: a 1 KiB prefix of a 2 MB patch is not a
|
|
48
|
+
* small diff, it is a CUT one. Only a complete, small diff earns `full`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function pickReviewMode(input: {
|
|
51
|
+
bytes: number;
|
|
52
|
+
hasDiff: boolean;
|
|
53
|
+
capped: boolean;
|
|
54
|
+
}): ReviewMode;
|
|
55
|
+
/** Longest unbroken run of backticks in `text` (0 when there is none). */
|
|
56
|
+
export declare function longestBacktickRun(text: string): number;
|
|
57
|
+
/**
|
|
58
|
+
* A code fence `diff` itself cannot close: one backtick longer than the longest
|
|
59
|
+
* run inside it, never shorter than the usual three.
|
|
60
|
+
*/
|
|
61
|
+
export declare function diffFence(diff: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* The `@@ … @@` hunk headers of a unified diff, in order.
|
|
64
|
+
*
|
|
65
|
+
* A line starting with `@@` can only be a header: every content line of a
|
|
66
|
+
* unified diff begins with ' ', '+' or '-', and the file-level lines begin with
|
|
67
|
+
* `diff --git`, `index`, `---`, `+++`, `new file` or `deleted file`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function hunkHeaders(diff: string): string[];
|
|
70
|
+
/**
|
|
71
|
+
* The prompt that goes into the composer draft.
|
|
72
|
+
*
|
|
73
|
+
* `mode` is what the caller decided (see {@link pickReviewMode}), but an empty
|
|
74
|
+
* diff is normalized to `pathOnly` here as well: an empty file is not an empty
|
|
75
|
+
* CHANGE, and an empty fenced block would answer the wrong question.
|
|
76
|
+
*/
|
|
77
|
+
export declare function buildReviewPrompt(input: ReviewPromptInput): string;
|
|
78
|
+
/** How many changed files a commit prompt enumerates before it stops. */
|
|
79
|
+
export declare const AI_REVIEW_MAX_FILES = 100;
|
|
80
|
+
/** One `git show --name-status` row, as the prompt needs it. */
|
|
81
|
+
export interface CommitFileLike {
|
|
82
|
+
/** Single letter (`R`/`C` for renames/copies). */
|
|
83
|
+
status: string;
|
|
84
|
+
path: string;
|
|
85
|
+
/** Rename/copy source. */
|
|
86
|
+
origPath?: string;
|
|
87
|
+
}
|
|
88
|
+
/** Everything a whole-commit prompt needs — all of it already on the history pane. */
|
|
89
|
+
export interface CommitReviewInput {
|
|
90
|
+
/** SSH host alias the commit was read from (named, no secrets). */
|
|
91
|
+
alias: string;
|
|
92
|
+
/** Repository root on that host (absolute POSIX path). */
|
|
93
|
+
root: string;
|
|
94
|
+
hash: string;
|
|
95
|
+
subject: string;
|
|
96
|
+
/** Message body below the subject ('' when there is none). */
|
|
97
|
+
body: string;
|
|
98
|
+
/** Files the commit touched (`git show --name-status`); empty when unread. */
|
|
99
|
+
files: readonly CommitFileLike[];
|
|
100
|
+
/** Raw `git show --patch` text ('' when the commit has no textual diff). */
|
|
101
|
+
patch: string;
|
|
102
|
+
mode: ReviewMode;
|
|
103
|
+
/** The patch is a `GIT_CAP`-capped PREFIX (`loadCommitPatch.truncated`). */
|
|
104
|
+
capped: boolean;
|
|
105
|
+
lang: ReviewLang;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The prompt for reviewing a WHOLE commit from the history pane (F6 v2).
|
|
109
|
+
*
|
|
110
|
+
* Same byte discipline as the single-file prompt (a capped `git show --patch`
|
|
111
|
+
* must never be presented as the complete change), but the shape differs: a
|
|
112
|
+
* commit is a set of files, so the facts list the files and the model is told
|
|
113
|
+
* how to fetch the patch. `mode` is what the caller decided; an empty patch is
|
|
114
|
+
* normalized to `pathOnly` here as well.
|
|
115
|
+
*/
|
|
116
|
+
export declare function buildCommitReviewPrompt(input: CommitReviewInput): string;
|
|
@@ -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[]>;
|
|
@@ -135,6 +135,21 @@ export declare function foldClipboardOffset(draft: string, occurrences: readonly
|
|
|
135
135
|
* and `insertCommand` inserts the separator as its own text node.
|
|
136
136
|
*/
|
|
137
137
|
export declare function appendOffset(snapshot: InputSnapshot): number | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Whether this session has a usable draft-insert channel right now.
|
|
140
|
+
*
|
|
141
|
+
* A PREFLIGHT for surfaces that must not offer an action they cannot complete
|
|
142
|
+
* (the diff view's "review this diff with AI" button): the conversation service
|
|
143
|
+
* is a soft, version-dependent read (see {@link conversationOf}), so on a host
|
|
144
|
+
* that does not expose it the button has to say so up front instead of failing
|
|
145
|
+
* on click with a message about a busy composer — a wrong cause is worse than no
|
|
146
|
+
* button.
|
|
147
|
+
*
|
|
148
|
+
* Read-only and side-effect free on purpose: it never calls
|
|
149
|
+
* `input.for()` (resolving the facade could materialise a per-session input
|
|
150
|
+
* shell), so it can run on every render of the owning view.
|
|
151
|
+
*/
|
|
152
|
+
export declare function canInsertDraft(ctx: Context, sessionId: string): boolean;
|
|
138
153
|
/**
|
|
139
154
|
* Mint one reference chip through the host's public `insertReference` facade —
|
|
140
155
|
* the same method the native `@` picker's event listener calls, so the
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spring-loaded directory expansion during a drag.
|
|
3
|
+
*
|
|
4
|
+
* A file manager opens a folder when a dragged item RESTS on it for a moment
|
|
5
|
+
* ("spring-loaded folder", macOS Finder / VS Code behaviour): without it the
|
|
6
|
+
* user has to remember the target path, drop, then find the file again inside
|
|
7
|
+
* the freshly opened tree. The editor's drop path already lands a drop on the
|
|
8
|
+
* row under the pointer (`RemoteExplorer` `dropDirFromEvent`), so opening the
|
|
9
|
+
* row mid-drag is what makes the gesture a single movement instead of two.
|
|
10
|
+
*
|
|
11
|
+
* Why this is a module of its own with an INJECTED scheduler
|
|
12
|
+
* ---------------------------------------------------------
|
|
13
|
+
* The rule that matters is timing, and timing is exactly what a jsdom/node gate
|
|
14
|
+
* cannot observe through `window.setTimeout` without waiting real seconds. The
|
|
15
|
+
* scheduler seam lets `scripts/check-drag-expand.mjs` drive a fake clock and
|
|
16
|
+
* pin every transition; the view passes `window`'s functions in. Nothing here
|
|
17
|
+
* touches the DOM, React or a browser global.
|
|
18
|
+
*
|
|
19
|
+
* Why ONE candidate
|
|
20
|
+
* -----------------
|
|
21
|
+
* There is one pointer and one drag. Keeping a set would let two directories
|
|
22
|
+
* open from a single path if `dragleave` were ever missed, and the second open
|
|
23
|
+
* would move the row the user is aiming at.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* How long the pointer must rest on a closed directory before it opens, in ms.
|
|
27
|
+
*
|
|
28
|
+
* Long enough that a drag ACROSS the tree does not flash every folder open on
|
|
29
|
+
* the way; short enough that a deliberate pause feels like the folder was
|
|
30
|
+
* waiting. 650 ms is a common file-manager value (Finder uses ~0.5 s) and sits
|
|
31
|
+
* well above `PREFETCH_HOVER_MS` (150 ms), so the listing warm-up still starts
|
|
32
|
+
* first and the expand usually paints from the warmed cache.
|
|
33
|
+
*/
|
|
34
|
+
export declare const DRAG_EXPAND_DELAY_MS = 650;
|
|
35
|
+
/**
|
|
36
|
+
* The timer functions the expander needs.
|
|
37
|
+
*
|
|
38
|
+
* Injected rather than imported so the gate can run on a fake clock; the view
|
|
39
|
+
* passes `window.setTimeout` / `window.clearTimeout` (they return numbers in a
|
|
40
|
+
* browser, which is why the handle is a number).
|
|
41
|
+
*/
|
|
42
|
+
export interface DragExpandScheduler {
|
|
43
|
+
set(callback: () => void, ms: number): number;
|
|
44
|
+
clear(handle: number): void;
|
|
45
|
+
}
|
|
46
|
+
/** The handle the view talks to (one per mounted tree). */
|
|
47
|
+
export interface DragExpander {
|
|
48
|
+
/**
|
|
49
|
+
* The pointer is resting on `dir`: open it after the delay.
|
|
50
|
+
*
|
|
51
|
+
* Idempotent for the same directory on purpose. `dragover` fires repeatedly
|
|
52
|
+
* (every few hundred ms at least) while a drag stays still, and restarting
|
|
53
|
+
* the countdown on every event would mean it never completes.
|
|
54
|
+
*/
|
|
55
|
+
hover(dir: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* The pointer left `dir`.
|
|
58
|
+
*
|
|
59
|
+
* Cancels only when `dir` is the current candidate: React delivers a leave
|
|
60
|
+
* for rows the pointer merely passed through, and one late leave from a row
|
|
61
|
+
* the pointer already left must not cancel the timer armed on the row it now
|
|
62
|
+
* rests on.
|
|
63
|
+
*/
|
|
64
|
+
leave(dir: string): void;
|
|
65
|
+
/** Cancel any pending open (drop, dragend, binding change, unmount). */
|
|
66
|
+
reset(): void;
|
|
67
|
+
/** The directory a countdown is running for, or undefined. Test seam. */
|
|
68
|
+
pending(): string | undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build one expander.
|
|
72
|
+
*
|
|
73
|
+
* @param onExpand - called ONCE per rest, after the delay, with the directory
|
|
74
|
+
* that was still hovered when the timer fired.
|
|
75
|
+
* @param scheduler - timer implementation (see {@link DragExpandScheduler}).
|
|
76
|
+
* @param delayMs - rest time; defaults to {@link DRAG_EXPAND_DELAY_MS}.
|
|
77
|
+
*/
|
|
78
|
+
export declare function createDragExpander(onExpand: (dir: string) => void, scheduler: DragExpandScheduler, delayMs?: number): DragExpander;
|
|
@@ -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;
|
package/lib/types/pool.d.ts
CHANGED
|
@@ -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
|
/**
|
package/lib/types/protocol.d.ts
CHANGED
|
@@ -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
|
+
}
|
package/lib/types/routes.d.ts
CHANGED
|
@@ -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.
|
|
4
|
+
"version": "0.17.0",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"dsh",
|