dsh-remote-vs 0.25.0 → 0.27.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 +12 -15
- package/README.md +11 -12
- package/THIRD-PARTY-NOTICES.md +193 -0
- package/lib/client.js +7313 -79961
- package/lib/index.js +1529 -964
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +22 -0
- package/lib/types/client/OutlinePanel.d.ts +22 -0
- package/lib/types/client/ProcessesSection.d.ts +19 -0
- package/lib/types/client/RemoteExplorer.d.ts +53 -0
- package/lib/types/client/api.d.ts +42 -3
- package/lib/types/client/blame-model.d.ts +77 -0
- package/lib/types/client/changes/review-state.d.ts +19 -0
- package/lib/types/client/connection.d.ts +16 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/outline-model.d.ts +59 -0
- package/lib/types/client/request-gate.d.ts +110 -0
- package/lib/types/client/scm/DiffView.d.ts +45 -7
- package/lib/types/client/scm/actions.d.ts +43 -4
- package/lib/types/client/store.d.ts +71 -0
- package/lib/types/client/vsc/FindWidget.d.ts +6 -0
- package/lib/types/client/vsc/blame.d.ts +19 -0
- package/lib/types/client/vsc/change-marks.d.ts +16 -6
- package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
- package/lib/types/client/vsc/kit.d.ts +11 -2
- package/lib/types/client/vsc/preview-document.d.ts +46 -0
- package/lib/types/client/vsc/preview-model.d.ts +31 -0
- package/lib/types/client/vsc/preview-services.d.ts +24 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +21 -0
- package/lib/types/client/vsc/terminal-theme.d.ts +28 -2
- package/lib/types/forward.d.ts +12 -0
- package/lib/types/fs-ops.d.ts +42 -0
- package/lib/types/git-ops.d.ts +18 -0
- package/lib/types/http.d.ts +2 -0
- package/lib/types/keygen.d.ts +9 -0
- package/lib/types/monitor.d.ts +8 -0
- package/lib/types/notices.d.ts +16 -1
- package/lib/types/p2/helper-rpc.d.ts +45 -0
- package/lib/types/processes.d.ts +43 -0
- package/lib/types/protocol.d.ts +34 -0
- package/lib/types/routes.d.ts +2 -0
- package/lib/types/store.d.ts +7 -0
- package/lib/types/terminal.d.ts +8 -0
- package/lib/types/view-settings.d.ts +5 -0
- package/lib/{worlds-B7gEDBzC.js → worlds-RG8K5eom.js} +113 -15
- package/package.json +3 -1
- package/src/client/CodeEditor.tsx +194 -9
- package/src/client/DirectoryFlow.tsx +16 -0
- package/src/client/DoctorPanel.tsx +70 -7
- package/src/client/EditorPane.tsx +574 -42
- package/src/client/HostsView.tsx +12 -3
- package/src/client/MonitorView.tsx +16 -5
- package/src/client/OutlinePanel.tsx +287 -0
- package/src/client/ProcessesSection.tsx +292 -0
- package/src/client/RemoteDirectoryPicker.tsx +12 -0
- package/src/client/RemoteExplorer.tsx +929 -40
- package/src/client/RemoteRoot.tsx +147 -22
- package/src/client/SearchView.tsx +8 -0
- package/src/client/TerminalSnippets.tsx +83 -8
- package/src/client/api.ts +114 -13
- package/src/client/blame-model.ts +242 -0
- package/src/client/changes/ChangesDock.tsx +188 -6
- package/src/client/changes/changes.css +10 -3
- package/src/client/changes/review-state.ts +34 -0
- package/src/client/connection.ts +29 -0
- package/src/client/downloads.ts +49 -4
- package/src/client/i18n.ts +276 -8
- package/src/client/index.tsx +4 -0
- package/src/client/outline-model.ts +775 -0
- package/src/client/request-gate.ts +221 -0
- package/src/client/scm/CommitPane.tsx +20 -2
- package/src/client/scm/DiffView.tsx +343 -117
- package/src/client/scm/HistoryPanel.tsx +61 -3
- package/src/client/scm/RepoPicker.tsx +1 -1
- package/src/client/scm/ScmPanel.tsx +391 -87
- package/src/client/scm/actions.ts +150 -14
- package/src/client/store.tsx +426 -14
- package/src/client/ui.tsx +4 -0
- package/src/client/vsc/FindWidget.tsx +24 -9
- package/src/client/vsc/blame.ts +147 -0
- package/src/client/vsc/breadcrumb.tsx +91 -3
- package/src/client/vsc/change-marks.ts +93 -44
- package/src/client/vsc/editor-keymap.ts +59 -1
- package/src/client/vsc/file-icons.tsx +17 -3
- package/src/client/vsc/kit.tsx +29 -20
- package/src/client/vsc/preview-document.tsx +323 -0
- package/src/client/vsc/preview-model.ts +216 -0
- package/src/client/vsc/preview-services.ts +118 -0
- package/src/client/vsc/save-shortcut.ts +47 -1
- package/src/client/vsc/terminal-theme.ts +44 -18
- package/src/client/vsc/vsc.css +6509 -5458
- package/src/forward.ts +47 -9
- package/src/fs-ops.ts +124 -4
- package/src/git-ops.ts +54 -3
- package/src/http.ts +35 -4
- package/src/keygen.ts +55 -4
- package/src/monitor.ts +13 -0
- package/src/notices.ts +23 -1
- package/src/p2/helper-rpc.ts +113 -7
- package/src/p2/worlds.ts +14 -1
- package/src/processes.ts +177 -0
- package/src/protocol.ts +37 -0
- package/src/routes.ts +330 -43
- package/src/sftp.ts +51 -14
- package/src/store.ts +10 -0
- package/src/terminal.ts +73 -26
- package/src/view-settings.ts +50 -10
- package/lib/types/client/Dialog.d.ts +0 -14
- package/src/client/Dialog.tsx +0 -76
package/src/terminal.ts
CHANGED
|
@@ -31,6 +31,20 @@ interface Session {
|
|
|
31
31
|
*/
|
|
32
32
|
outBuffer: string
|
|
33
33
|
outTimer: ReturnType<typeof setTimeout> | undefined
|
|
34
|
+
/**
|
|
35
|
+
* Recent output already flushed to sockets, replayed to a REATTACHING socket.
|
|
36
|
+
*
|
|
37
|
+
* A PTY lives for ten minutes after its last socket, but the screen state
|
|
38
|
+
* (the prompt, the last command's output) lives only in xterm on the client.
|
|
39
|
+
* When a session switch remounts the sidebar, the new XTerm attaches to the
|
|
40
|
+
* still-running shell and used to start BLANK — the shell was at its prompt,
|
|
41
|
+
* but the prompt had been printed before the socket existed. Keeping the tail
|
|
42
|
+
* of the stream lets `attach` hand the newcomer the screen it missed.
|
|
43
|
+
*
|
|
44
|
+
* Bounded: `REPLAY_MAX_CHARS` is enough for a prompt plus a screenful or two;
|
|
45
|
+
* a `cat` of a huge file must not double the host's memory per session.
|
|
46
|
+
*/
|
|
47
|
+
replay: string
|
|
34
48
|
/**
|
|
35
49
|
* When the last `out` frame went out.
|
|
36
50
|
*
|
|
@@ -124,6 +138,15 @@ const OUT_COALESCE_CHARS = 64 * 1024
|
|
|
124
138
|
*/
|
|
125
139
|
const OUT_ECHO_IDLE_MS = 24
|
|
126
140
|
|
|
141
|
+
/**
|
|
142
|
+
* How much recent output a reattaching socket receives (see `Session.replay`).
|
|
143
|
+
*
|
|
144
|
+
* 128 Ki UTF-16 units is a few screens of logs plus the prompt line; the buffer
|
|
145
|
+
* may grow to twice this between trims, so one terminal costs at most ~512 KiB
|
|
146
|
+
* of the host's memory in replay state.
|
|
147
|
+
*/
|
|
148
|
+
const REPLAY_MAX_CHARS = 128 * 1024
|
|
149
|
+
|
|
127
150
|
/** Construction options (the terminal gate drives the registry directly). */
|
|
128
151
|
export interface TerminalRegistryOptions {
|
|
129
152
|
/**
|
|
@@ -194,6 +217,7 @@ export class TerminalSessionRegistry {
|
|
|
194
217
|
paused: false,
|
|
195
218
|
outBuffer: '',
|
|
196
219
|
outTimer: undefined,
|
|
220
|
+
replay: '',
|
|
197
221
|
lastFlushAt: 0,
|
|
198
222
|
outstanding: new Map(),
|
|
199
223
|
reap: undefined,
|
|
@@ -252,6 +276,13 @@ export class TerminalSessionRegistry {
|
|
|
252
276
|
const session = this.sessions.get(id)
|
|
253
277
|
if (session === undefined || !session.alive) return false
|
|
254
278
|
this.hookSocket(session, ws)
|
|
279
|
+
// Hand the newcomer the output this session produced before it attached
|
|
280
|
+
// (the shell's prompt, the previous command's screen). It goes through the
|
|
281
|
+
// same per-socket accounting as live output, so a huge replay cannot slip
|
|
282
|
+
// past the backpressure ceiling.
|
|
283
|
+
if (session.replay !== '') {
|
|
284
|
+
this.sendOutTo(session, ws, JSON.stringify({ t: 'out', d: session.replay }))
|
|
285
|
+
}
|
|
255
286
|
// Deliver anything the coalescing window still holds to the newcomer too,
|
|
256
287
|
// before its `ready`: it is output the shell already produced.
|
|
257
288
|
this.flushOut(session)
|
|
@@ -422,6 +453,11 @@ export class TerminalSessionRegistry {
|
|
|
422
453
|
if (session.outBuffer === '') return
|
|
423
454
|
const text = session.outBuffer
|
|
424
455
|
session.outBuffer = ''
|
|
456
|
+
// Remember what was already delivered: a later reattach replays this.
|
|
457
|
+
session.replay += text
|
|
458
|
+
if (session.replay.length > REPLAY_MAX_CHARS * 2) {
|
|
459
|
+
session.replay = session.replay.slice(-REPLAY_MAX_CHARS)
|
|
460
|
+
}
|
|
425
461
|
session.lastFlushAt = Date.now()
|
|
426
462
|
this.broadcast(session, { t: 'out', d: text })
|
|
427
463
|
}
|
|
@@ -447,35 +483,46 @@ export class TerminalSessionRegistry {
|
|
|
447
483
|
|
|
448
484
|
private broadcast(session: Session, frame: TerminalServerFrame): void {
|
|
449
485
|
const text = JSON.stringify(frame)
|
|
486
|
+
for (const socket of session.sockets) {
|
|
487
|
+
this.sendOutTo(session, socket, text)
|
|
488
|
+
}
|
|
489
|
+
if (session.pending > OUT_HIGH_WATER) this.setPaused(session, true)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Send one already-stringified `out` frame to ONE socket with accounting.
|
|
494
|
+
*
|
|
495
|
+
* Shared by `broadcast` and by the replay on `attach`; the byte count must be
|
|
496
|
+
* counted once per socket so the session's brake reflects every socket's
|
|
497
|
+
* backlog (see `Session.pending`).
|
|
498
|
+
*/
|
|
499
|
+
private sendOutTo(session: Session, socket: WebSocket, text: string): void {
|
|
450
500
|
// Bytes, not UTF-16 code units: CJK and emoji output would otherwise be
|
|
451
501
|
// undercounted by up to 3x and the brake would come on too late.
|
|
452
502
|
const size = Buffer.byteLength(text, 'utf8')
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
done()
|
|
477
|
-
}
|
|
503
|
+
let settled = false
|
|
504
|
+
// The send callback fires once the frame is on the wire. It is the only
|
|
505
|
+
// public signal for "this socket has caught up", and it avoids relying on
|
|
506
|
+
// ws internals (bufferedAmount does not report the socket write queue).
|
|
507
|
+
const done = (): void => {
|
|
508
|
+
if (settled) return
|
|
509
|
+
settled = true
|
|
510
|
+
// A socket that detached already had its outstanding bytes released
|
|
511
|
+
// (its late callback must not decrement them a second time).
|
|
512
|
+
const left = session.outstanding.get(socket)
|
|
513
|
+
if (left === undefined) return
|
|
514
|
+
const remaining = Math.max(0, left - size)
|
|
515
|
+
if (remaining === 0) session.outstanding.delete(socket)
|
|
516
|
+
else session.outstanding.set(socket, remaining)
|
|
517
|
+
session.pending = Math.max(0, session.pending - size)
|
|
518
|
+
if (session.pending <= OUT_LOW_WATER) this.setPaused(session, false)
|
|
519
|
+
}
|
|
520
|
+
session.pending += size
|
|
521
|
+
session.outstanding.set(socket, (session.outstanding.get(socket) ?? 0) + size)
|
|
522
|
+
try {
|
|
523
|
+
socket.send(text, done)
|
|
524
|
+
} catch {
|
|
525
|
+
done()
|
|
478
526
|
}
|
|
479
|
-
if (session.pending > OUT_HIGH_WATER) this.setPaused(session, true)
|
|
480
527
|
}
|
|
481
528
|
}
|
package/src/view-settings.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* keys are ignored — the browser is the only writer, and a stale tab must not be
|
|
19
19
|
* able to corrupt the file with an extra key).
|
|
20
20
|
*/
|
|
21
|
-
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, writeSync } from 'node:fs'
|
|
21
|
+
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, statSync, writeSync } from 'node:fs'
|
|
22
22
|
import { dirname } from 'node:path'
|
|
23
23
|
import {
|
|
24
24
|
REMOTE_VIEW_SETTINGS_DEFAULTS,
|
|
@@ -39,6 +39,26 @@ function defaults(): RemoteViewSettings {
|
|
|
39
39
|
return { ...REMOTE_VIEW_SETTINGS_DEFAULTS }
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** Identity of the settings file at one point in time; `null` = the file is absent. */
|
|
43
|
+
type FileStamp = { mtimeMs: number; size: number } | null
|
|
44
|
+
|
|
45
|
+
/** Same file identity (both absent counts as same). */
|
|
46
|
+
function sameStamp(left: FileStamp, right: FileStamp): boolean {
|
|
47
|
+
if (left === null || right === null) return left === right
|
|
48
|
+
return left.mtimeMs === right.mtimeMs && left.size === right.size
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Replays one read-modify-write before giving up.
|
|
53
|
+
*
|
|
54
|
+
* Desktop and `dsh web` share `$DSH_HOME/dsh-remote-view.json` by design, and
|
|
55
|
+
* every patch rewrites the WHOLE document: a plain read-merge-write let the last
|
|
56
|
+
* window win and silently dropped the other one's preference. A stamp re-check
|
|
57
|
+
* right before the write turns that into a replay on fresh content; a third
|
|
58
|
+
* failed attempt fails loud instead of losing a setting.
|
|
59
|
+
*/
|
|
60
|
+
const PATCH_ATTEMPTS = 3
|
|
61
|
+
|
|
42
62
|
/** A finite width share, clamped into the allowed band; anything else is a miss. */
|
|
43
63
|
function readWidthRatio(value: unknown): number | undefined {
|
|
44
64
|
if (typeof value !== 'number' || !Number.isFinite(value)) return undefined
|
|
@@ -95,16 +115,36 @@ export class RemoteViewSettingsStore {
|
|
|
95
115
|
* @returns the settings as stored.
|
|
96
116
|
*/
|
|
97
117
|
patch(patch: Record<string, unknown>): RemoteViewSettings {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
118
|
+
for (let attempt = 0; attempt < PATCH_ATTEMPTS; attempt += 1) {
|
|
119
|
+
// Stamp BEFORE the read: a write landing in between leaves the older stamp
|
|
120
|
+
// behind, so the re-check below catches it and replays on the new content.
|
|
121
|
+
const before = this.stampOf()
|
|
122
|
+
const current = this.get()
|
|
123
|
+
const next: RemoteViewSettings = {
|
|
124
|
+
autoOpenRemoteWorkspace: typeof patch.autoOpenRemoteWorkspace === 'boolean'
|
|
125
|
+
? patch.autoOpenRemoteWorkspace
|
|
126
|
+
: current.autoOpenRemoteWorkspace,
|
|
127
|
+
remoteWorkspaceWidthRatio: readWidthRatio(patch.remoteWorkspaceWidthRatio)
|
|
128
|
+
?? current.remoteWorkspaceWidthRatio,
|
|
129
|
+
}
|
|
130
|
+
if (!sameStamp(before, this.stampOf())) continue
|
|
131
|
+
this.save(next)
|
|
132
|
+
return next
|
|
133
|
+
}
|
|
134
|
+
throw new Error(`${this.file}: another process keeps editing the view settings; retry the operation`)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* File identity right now; `null` when the file is absent (or cannot be
|
|
139
|
+
* statted — `get()` fails loud on that case anyway).
|
|
140
|
+
*/
|
|
141
|
+
private stampOf(): FileStamp {
|
|
142
|
+
try {
|
|
143
|
+
const stat = statSync(this.file, { throwIfNoEntry: false })
|
|
144
|
+
return stat === undefined ? null : { mtimeMs: stat.mtimeMs, size: stat.size }
|
|
145
|
+
} catch {
|
|
146
|
+
return null
|
|
105
147
|
}
|
|
106
|
-
this.save(next)
|
|
107
|
-
return next
|
|
108
148
|
}
|
|
109
149
|
|
|
110
150
|
/** Write one document atomically: a crash never leaves a half-written file. */
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Small inline input dialog (new file / folder / rename). Rendered as a
|
|
3
|
-
* fixed overlay card; Enter confirms, Escape cancels.
|
|
4
|
-
*/
|
|
5
|
-
import { type ReactNode } from 'react';
|
|
6
|
-
export declare function InputDialog(props: {
|
|
7
|
-
title: string;
|
|
8
|
-
label: string;
|
|
9
|
-
initial?: string;
|
|
10
|
-
placeholder?: string;
|
|
11
|
-
okText?: string;
|
|
12
|
-
onOk: (value: string) => void;
|
|
13
|
-
onCancel: () => void;
|
|
14
|
-
}): ReactNode;
|
package/src/client/Dialog.tsx
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Small inline input dialog (new file / folder / rename). Rendered as a
|
|
3
|
-
* fixed overlay card; Enter confirms, Escape cancels.
|
|
4
|
-
*/
|
|
5
|
-
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
|
6
|
-
import { Btn, inputStyle } from './ui.tsx'
|
|
7
|
-
|
|
8
|
-
export function InputDialog(props: {
|
|
9
|
-
title: string
|
|
10
|
-
label: string
|
|
11
|
-
initial?: string
|
|
12
|
-
placeholder?: string
|
|
13
|
-
okText?: string
|
|
14
|
-
onOk: (value: string) => void
|
|
15
|
-
onCancel: () => void
|
|
16
|
-
}): ReactNode {
|
|
17
|
-
const [value, setValue] = useState(props.initial ?? '')
|
|
18
|
-
const inputRef = useRef<HTMLInputElement>(null)
|
|
19
|
-
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
inputRef.current?.focus()
|
|
22
|
-
inputRef.current?.select()
|
|
23
|
-
}, [])
|
|
24
|
-
|
|
25
|
-
const commit = (): void => {
|
|
26
|
-
const trimmed = value.trim()
|
|
27
|
-
if (trimmed === '') return
|
|
28
|
-
props.onOk(trimmed)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div
|
|
33
|
-
style={{
|
|
34
|
-
position: 'fixed',
|
|
35
|
-
inset: 0,
|
|
36
|
-
zIndex: 1000,
|
|
37
|
-
background: 'rgba(0,0,0,.45)',
|
|
38
|
-
display: 'flex',
|
|
39
|
-
alignItems: 'center',
|
|
40
|
-
justifyContent: 'center',
|
|
41
|
-
}}
|
|
42
|
-
onClick={props.onCancel}
|
|
43
|
-
>
|
|
44
|
-
<div
|
|
45
|
-
style={{
|
|
46
|
-
minWidth: 320,
|
|
47
|
-
maxWidth: '90vw',
|
|
48
|
-
background: 'Canvas',
|
|
49
|
-
color: 'CanvasText',
|
|
50
|
-
border: '1px solid rgba(127,127,127,.4)',
|
|
51
|
-
borderRadius: 8,
|
|
52
|
-
padding: 14,
|
|
53
|
-
}}
|
|
54
|
-
onClick={(e) => e.stopPropagation()}
|
|
55
|
-
onKeyDown={(e) => {
|
|
56
|
-
if (e.key === 'Enter') commit()
|
|
57
|
-
else if (e.key === 'Escape') props.onCancel()
|
|
58
|
-
}}
|
|
59
|
-
>
|
|
60
|
-
<div style={{ fontWeight: 600, marginBottom: 8 }}>{props.title}</div>
|
|
61
|
-
<div style={{ fontSize: 12, opacity: 0.75, marginBottom: 4 }}>{props.label}</div>
|
|
62
|
-
<input
|
|
63
|
-
ref={inputRef}
|
|
64
|
-
value={value}
|
|
65
|
-
placeholder={props.placeholder}
|
|
66
|
-
onChange={(e) => setValue(e.target.value)}
|
|
67
|
-
style={inputStyle}
|
|
68
|
-
/>
|
|
69
|
-
<div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end', marginTop: 12 }}>
|
|
70
|
-
<Btn onClick={props.onCancel}>取消 / Cancel</Btn>
|
|
71
|
-
<Btn kind="primary" onClick={commit}>{props.okText ?? '确定 / OK'}</Btn>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
)
|
|
76
|
-
}
|