dsh-remote-vs 0.23.0 → 0.25.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 +49 -15
- package/README.md +40 -14
- package/lib/client.js +45978 -43338
- package/lib/index.js +388 -90
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +17 -0
- package/lib/types/client/EditorPane.d.ts +16 -5
- package/lib/types/client/FloatingPlaceholder.d.ts +16 -5
- package/lib/types/client/RemoteEditorView.d.ts +13 -10
- package/lib/types/client/RemoteRoot.d.ts +5 -5
- package/lib/types/client/SettingsHosts.d.ts +3 -0
- package/lib/types/client/TerminalSnippets.d.ts +36 -0
- package/lib/types/client/TerminalView.d.ts +1 -1
- package/lib/types/client/XTerm.d.ts +33 -0
- package/lib/types/client/api.d.ts +4 -1
- package/lib/types/client/auto-open-remote.d.ts +41 -0
- package/lib/types/client/editor-capability.d.ts +27 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/store.d.ts +59 -4
- package/lib/types/client/terminal-input.d.ts +23 -0
- package/lib/types/client/terminal-snippets.d.ts +86 -0
- package/lib/types/client/use-remote-chat-target.d.ts +2 -0
- package/lib/types/client/view-settings.d.ts +40 -0
- package/lib/types/client/vsc/breadcrumb.d.ts +30 -0
- package/lib/types/client/vsc/editor-caret.d.ts +32 -0
- package/lib/types/client/vsc/editor-langs.d.ts +9 -0
- package/lib/types/client/vsc/editor-settings.d.ts +55 -0
- package/lib/types/client/vsc/image-preview.d.ts +36 -0
- package/lib/types/client/vsc/kit.d.ts +2 -0
- package/lib/types/client/vsc/terminal-clipboard.d.ts +15 -0
- package/lib/types/client/vsc/terminal-line.d.ts +25 -0
- package/lib/types/client/vsc/terminal-links.d.ts +62 -0
- package/lib/types/client/vsc/terminal-theme.d.ts +22 -0
- package/lib/types/client/vsc/terminal-writer.d.ts +52 -0
- package/lib/types/paths.d.ts +9 -0
- package/lib/types/pool.d.ts +25 -0
- package/lib/types/protocol.d.ts +35 -0
- package/lib/types/routes.d.ts +7 -0
- package/lib/types/terminal.d.ts +25 -1
- package/lib/types/view-settings.d.ts +26 -0
- package/lib/{worlds-DXdP4SMn.js → worlds-B7gEDBzC.js} +13 -1
- package/package.json +36 -36
- package/src/client/CodeEditor.tsx +54 -2
- package/src/client/EditorPane.tsx +485 -107
- package/src/client/FloatingPlaceholder.tsx +34 -5
- package/src/client/RemoteEditorView.tsx +14 -11
- package/src/client/RemoteRoot.tsx +20 -125
- package/src/client/SettingsHosts.tsx +81 -3
- package/src/client/TerminalSnippets.tsx +357 -0
- package/src/client/TerminalView.tsx +50 -1
- package/src/client/XTerm.tsx +228 -58
- package/src/client/api.ts +7 -0
- package/src/client/auto-open-remote.ts +439 -0
- package/src/client/editor-capability.ts +42 -0
- package/src/client/i18n.ts +158 -6
- package/src/client/index.tsx +30 -6
- package/src/client/store.tsx +165 -13
- package/src/client/terminal-input.ts +44 -0
- package/src/client/terminal-snippets.ts +216 -0
- package/src/client/use-remote-chat-target.ts +1 -1
- package/src/client/view-settings.ts +99 -0
- package/src/client/vsc/breadcrumb.tsx +251 -0
- package/src/client/vsc/editor-caret.ts +30 -0
- package/src/client/vsc/editor-langs.ts +20 -0
- package/src/client/vsc/editor-settings.ts +146 -0
- package/src/client/vsc/editor-theme.ts +4 -5
- package/src/client/vsc/image-preview.tsx +110 -0
- package/src/client/vsc/kit.tsx +20 -1
- package/src/client/vsc/terminal-clipboard.ts +19 -0
- package/src/client/vsc/terminal-line.ts +101 -0
- package/src/client/vsc/terminal-links.ts +166 -0
- package/src/client/vsc/terminal-theme.ts +71 -0
- package/src/client/vsc/terminal-writer.ts +112 -0
- package/src/client/vsc/vsc.css +687 -48
- package/src/index.ts +6 -0
- package/src/paths.ts +13 -0
- package/src/pool.ts +99 -27
- package/src/protocol.ts +45 -0
- package/src/routes.ts +47 -0
- package/src/terminal.ts +160 -6
- package/src/view-settings.ts +133 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable store for the two client view preferences: `$DSH_HOME/dsh-remote-view.json`.
|
|
3
|
+
*
|
|
4
|
+
* Why a file of its own (and not the routing store, nor a browser-local key):
|
|
5
|
+
* - the settings describe how the PLUGIN behaves in the right panel, and they
|
|
6
|
+
* must apply to every Web/Desktop window of this profile — the browser's
|
|
7
|
+
* localStorage is per origin/per machine and would drift;
|
|
8
|
+
* - they are GUI behaviour, not routing facts: keeping them out of
|
|
9
|
+
* `dsh-remote.json` means a hand-edited preference can never break the store
|
|
10
|
+
* the routers read on every remote operation.
|
|
11
|
+
*
|
|
12
|
+
* Shape of the file (`version: 1`), written atomically (tmp + rename, 0600):
|
|
13
|
+
*
|
|
14
|
+
* { "version": 1, "autoOpenRemoteWorkspace": false, "remoteWorkspaceWidthRatio": 0.45 }
|
|
15
|
+
*
|
|
16
|
+
* Field-by-field validation with defaults on READ (so a missing, older or
|
|
17
|
+
* half-edited field costs only that field), and a flat PATCH on write (unknown
|
|
18
|
+
* keys are ignored — the browser is the only writer, and a stale tab must not be
|
|
19
|
+
* able to corrupt the file with an extra key).
|
|
20
|
+
*/
|
|
21
|
+
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, writeSync } from 'node:fs'
|
|
22
|
+
import { dirname } from 'node:path'
|
|
23
|
+
import {
|
|
24
|
+
REMOTE_VIEW_SETTINGS_DEFAULTS,
|
|
25
|
+
clampViewWidthRatio,
|
|
26
|
+
type RemoteViewSettings,
|
|
27
|
+
} from './protocol.ts'
|
|
28
|
+
import { viewSettingsPath } from './paths.ts'
|
|
29
|
+
|
|
30
|
+
/** On-disk document shape. */
|
|
31
|
+
interface ViewSettingsDoc {
|
|
32
|
+
version: 1
|
|
33
|
+
autoOpenRemoteWorkspace: boolean
|
|
34
|
+
remoteWorkspaceWidthRatio: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Defaults as a fresh copy (callers may own the object). */
|
|
38
|
+
function defaults(): RemoteViewSettings {
|
|
39
|
+
return { ...REMOTE_VIEW_SETTINGS_DEFAULTS }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A finite width share, clamped into the allowed band; anything else is a miss. */
|
|
43
|
+
function readWidthRatio(value: unknown): number | undefined {
|
|
44
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) return undefined
|
|
45
|
+
return clampViewWidthRatio(value)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class RemoteViewSettingsStore {
|
|
49
|
+
private readonly file: string
|
|
50
|
+
|
|
51
|
+
constructor(file: string = viewSettingsPath()) {
|
|
52
|
+
this.file = file
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The current preferences (a missing file answers the defaults).
|
|
57
|
+
*
|
|
58
|
+
* Read from disk on every call: the file is tiny, GET hands it to a page load,
|
|
59
|
+
* and two processes sharing `$DSH_HOME` (desktop + `dsh web`) must see each
|
|
60
|
+
* other's edit without a restart.
|
|
61
|
+
*/
|
|
62
|
+
get(): RemoteViewSettings {
|
|
63
|
+
if (!existsSync(this.file)) return defaults()
|
|
64
|
+
let parsed: unknown
|
|
65
|
+
try {
|
|
66
|
+
parsed = JSON.parse(readFileSync(this.file, 'utf8'))
|
|
67
|
+
} catch (error) {
|
|
68
|
+
throw new Error(`cannot parse ${this.file}: ${error instanceof Error ? error.message : String(error)}`)
|
|
69
|
+
}
|
|
70
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
71
|
+
throw new Error(`${this.file}: root must be an object`)
|
|
72
|
+
}
|
|
73
|
+
const doc = parsed as Partial<ViewSettingsDoc>
|
|
74
|
+
if (doc.version !== undefined && doc.version !== 1) {
|
|
75
|
+
throw new Error(`${this.file}: unsupported version ${String(doc.version)}`)
|
|
76
|
+
}
|
|
77
|
+
// Field by field: an unknown/future key, or one bad value, keeps the rest.
|
|
78
|
+
return {
|
|
79
|
+
autoOpenRemoteWorkspace: typeof doc.autoOpenRemoteWorkspace === 'boolean'
|
|
80
|
+
? doc.autoOpenRemoteWorkspace
|
|
81
|
+
: REMOTE_VIEW_SETTINGS_DEFAULTS.autoOpenRemoteWorkspace,
|
|
82
|
+
remoteWorkspaceWidthRatio: readWidthRatio(doc.remoteWorkspaceWidthRatio)
|
|
83
|
+
?? REMOTE_VIEW_SETTINGS_DEFAULTS.remoteWorkspaceWidthRatio,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Merge one flat patch into the stored preferences and persist the result.
|
|
89
|
+
*
|
|
90
|
+
* Unknown keys are ignored and an unusable value of a known field keeps the
|
|
91
|
+
* stored one: the browser's controls only ever send valid values, so a bad
|
|
92
|
+
* field means a stale client, not something the user should be told about.
|
|
93
|
+
*
|
|
94
|
+
* @param patch - a partial document straight from the POST body.
|
|
95
|
+
* @returns the settings as stored.
|
|
96
|
+
*/
|
|
97
|
+
patch(patch: Record<string, unknown>): RemoteViewSettings {
|
|
98
|
+
const current = this.get()
|
|
99
|
+
const next: RemoteViewSettings = {
|
|
100
|
+
autoOpenRemoteWorkspace: typeof patch.autoOpenRemoteWorkspace === 'boolean'
|
|
101
|
+
? patch.autoOpenRemoteWorkspace
|
|
102
|
+
: current.autoOpenRemoteWorkspace,
|
|
103
|
+
remoteWorkspaceWidthRatio: readWidthRatio(patch.remoteWorkspaceWidthRatio)
|
|
104
|
+
?? current.remoteWorkspaceWidthRatio,
|
|
105
|
+
}
|
|
106
|
+
this.save(next)
|
|
107
|
+
return next
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Write one document atomically: a crash never leaves a half-written file. */
|
|
111
|
+
private save(settings: RemoteViewSettings): void {
|
|
112
|
+
const doc: ViewSettingsDoc = { version: 1, ...settings }
|
|
113
|
+
const payload = `${JSON.stringify(doc, null, 2)}\n`
|
|
114
|
+
const dir = dirname(this.file)
|
|
115
|
+
// A fresh $DSH_HOME may not exist yet: the first save must not ENOENT.
|
|
116
|
+
mkdirSync(dir, { recursive: true })
|
|
117
|
+
const tmp = `${this.file}.${process.pid}.tmp`
|
|
118
|
+
const fd = openSync(tmp, 'w', 0o600)
|
|
119
|
+
try {
|
|
120
|
+
writeSync(fd, payload)
|
|
121
|
+
// Flush before the rename (best effort): the next boot must never load an
|
|
122
|
+
// empty file, but an OS refusing fsync must not fail the save.
|
|
123
|
+
try {
|
|
124
|
+
fsyncSync(fd)
|
|
125
|
+
} catch {
|
|
126
|
+
// Durability is improved, not guaranteed.
|
|
127
|
+
}
|
|
128
|
+
} finally {
|
|
129
|
+
closeSync(fd)
|
|
130
|
+
}
|
|
131
|
+
renameSync(tmp, this.file)
|
|
132
|
+
}
|
|
133
|
+
}
|