dsh-remote 0.8.72 → 0.8.74

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.
Files changed (44) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +470 -389
  3. package/README.md +529 -462
  4. package/cordis.patch.yml +9 -9
  5. package/lib/binding.js +172 -172
  6. package/lib/client.js +4039 -4022
  7. package/lib/credential.js +263 -263
  8. package/lib/errors.js +141 -141
  9. package/lib/exec-job.js +235 -235
  10. package/lib/file-reference.js +457 -457
  11. package/lib/forwards.js +258 -258
  12. package/lib/host-api.js +808 -0
  13. package/lib/hostkey.js +108 -108
  14. package/lib/http-transport.js +196 -196
  15. package/lib/ignore.js +202 -202
  16. package/lib/index.js +4923 -4541
  17. package/lib/instructions-dynamic.js +415 -415
  18. package/lib/openssh.js +879 -879
  19. package/lib/paths.js +252 -252
  20. package/lib/pool.js +963 -893
  21. package/lib/registry.js +296 -293
  22. package/lib/remote-fs.js +173 -173
  23. package/lib/remote-sandbox.js +183 -183
  24. package/lib/remote-shell-child.cjs +344 -305
  25. package/lib/remote-shell.js +542 -518
  26. package/lib/routes-fs.js +245 -245
  27. package/lib/routes-term.js +169 -169
  28. package/lib/search.js +235 -235
  29. package/lib/sftp-surface.js +119 -119
  30. package/lib/sshconfig.js +779 -705
  31. package/lib/sync.js +275 -275
  32. package/lib/tasks.js +95 -95
  33. package/lib/telemetry.js +213 -213
  34. package/lib/terminal.js +205 -205
  35. package/lib/tui/flow.js +130 -0
  36. package/lib/tui/format.js +332 -0
  37. package/lib/tui/i18n.js +344 -0
  38. package/lib/tui/index.js +322 -0
  39. package/lib/tui/provider.js +327 -0
  40. package/lib/tui/scene.js +996 -0
  41. package/lib/update.js +472 -472
  42. package/lib/web-attach.js +850 -850
  43. package/lib/workspace-cleanup.js +337 -0
  44. package/package.json +100 -99
package/cordis.patch.yml CHANGED
@@ -1,9 +1,9 @@
1
- # dsh-remote bundle patch: inserts only this plugin into a profile's layer stack.
2
- #
3
- # dsh-better-sidebar is deliberately not mounted here and is not a dependency.
4
- # Users who want that optional Web UI can install its bundle separately;
5
- # lib/client.js discovers the betterSidebar service dynamically and adds the
6
- # remote explorer/editor tabs when it is present.
7
- - insert:
8
- - id: dsh-remote
9
- name: 'dsh-remote'
1
+ # dsh-remote bundle patch: inserts only this plugin into a profile's layer stack.
2
+ #
3
+ # dsh-better-sidebar is deliberately not mounted here and is not a dependency.
4
+ # Users who want that optional Web UI can install its bundle separately;
5
+ # lib/client.js discovers the betterSidebar service dynamically and adds the
6
+ # remote explorer/editor tabs when it is present.
7
+ - insert:
8
+ - id: dsh-remote
9
+ name: 'dsh-remote'
package/lib/binding.js CHANGED
@@ -1,172 +1,172 @@
1
- // Session → remote-binding resolution.
2
- //
3
- // A session's remote target is derived from its own workspace mirror, never
4
- // from the plugin's mutable active-machine state. That is what keeps concurrent
5
- // sessions on different hosts independent: with a single shared connection and
6
- // a single shared workspace value, one session switching machines redirected
7
- // every other session's commands to the wrong host (issue #25).
8
- //
9
- // The mirror directory is the durable record of that binding: `ensureMirror()`
10
- // writes `.dsh-remote-meta.json` with the remote origin (`host`/`port`/
11
- // `username`/`remotePath`) when the workspace is picked, so a session's cwd
12
- // alone identifies both the machine to connect to and the workspace root.
13
-
14
- import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
15
- import path from 'node:path'
16
- import zlib from 'node:zlib'
17
-
18
- /** Strip trailing separators so a mirror root and a path inside it compare cleanly. */
19
- const norm = (p) => path.resolve(String(p || '')).replace(/[\\/]+$/, '') || ''
20
-
21
- /** Whether `base` is `dir` itself or nested under it (separator-aware, so
22
- * `/a/mirror-2` is NOT treated as living inside `/a/mirror`). */
23
- const isUnder = (base, dir) => base === dir || base.startsWith(dir + path.sep) || base.startsWith(dir + '/')
24
-
25
- /**
26
- * Resolve which remote workspace a LOCAL path belongs to by scanning the mirror
27
- * registry for the mirror that contains it.
28
- *
29
- * Mirrors live exactly one level under the registry root as
30
- * `<host>-<user>-<port>/<basename>`, and `mirrorDirFor()` appends a short hash
31
- * when two remote paths share a basename, so containment is unambiguous. The
32
- * longest containing path still wins, which keeps the result stable if a
33
- * future layout ever nests them.
34
- *
35
- * A mirror whose meta is missing, unparsable, or has no `host` is skipped
36
- * rather than guessed at: reporting no binding makes the caller refuse loudly,
37
- * while guessing would send commands to an unintended host.
38
- *
39
- * @param {string} local - absolute local path, typically a session's cwd.
40
- * @param {string} root - the mirror registry root (`$DSH_HOME/remote-workspaces`).
41
- * @returns {{mirrorDir: string|null, remotePath: string, machine: {host: string, port: number, username: string, alias: string}|null}}
42
- * `machine` is the mirror-recorded origin (`alias` is the ~/.ssh/config alias
43
- * it was created through, '' when the machine uses literal values), or null
44
- * when `local` is not inside a usable mirror (in which case `remotePath` is
45
- * empty too).
46
- */
47
- export function resolveMirror(local, root) {
48
- let mirrorDir = null
49
- let remotePath = ''
50
- let machine = null
51
- if (!local || !root || !existsSync(root)) return { mirrorDir, remotePath, machine }
52
- const base = norm(local)
53
- let hostDirs
54
- try {
55
- hostDirs = readdirSync(root)
56
- } catch {
57
- return { mirrorDir, remotePath, machine }
58
- }
59
- for (const hostDir of hostDirs) {
60
- const hostPath = path.join(root, hostDir)
61
- if (!statSync(hostPath, { throwIfNoEntry: false })?.isDirectory?.()) continue
62
- let entries
63
- try {
64
- entries = readdirSync(hostPath)
65
- } catch {
66
- continue
67
- }
68
- for (const entry of entries) {
69
- const metaPath = path.join(hostPath, entry, '.dsh-remote-meta.json')
70
- if (!existsSync(metaPath)) continue
71
- const mirrorAbs = norm(path.join(hostPath, entry))
72
- if (!isUnder(base, mirrorAbs)) continue
73
- // Deepest match wins; an equal-length path cannot occur twice.
74
- if (mirrorDir && mirrorAbs.length <= mirrorDir.length) continue
75
- try {
76
- const meta = JSON.parse(readFileSync(metaPath, 'utf8'))
77
- if (!meta || !meta.host) continue
78
- mirrorDir = mirrorAbs
79
- remotePath = String(meta.remotePath || '')
80
- machine = {
81
- host: String(meta.host),
82
- port: Number(meta.port) || 22,
83
- username: String(meta.username || ''),
84
- // The ~/.ssh/config alias this mirror was created through, when the
85
- // machine was saved as one (issue #38): it keeps the mirror bound to
86
- // its machine even if that alias's HostName/port later change.
87
- alias: String(meta.alias || ''),
88
- }
89
- } catch { /* unparsable meta → not a usable binding */ }
90
- }
91
- }
92
- return { mirrorDir, remotePath, machine }
93
- }
94
-
95
- /**
96
- * Stable pool key for a remote identity. Two sessions on the same machine
97
- * produce the same key and therefore share one SSH connection; sessions on
98
- * different machines never collide.
99
- * @param {{host: string, port?: number|string, username?: string}} m - the remote identity.
100
- * @returns {string} the canonical `user@host:port` key.
101
- */
102
- export function poolKey(m) {
103
- return `${(m && m.username) || ''}@${(m && m.host) || ''}:${Number(m && m.port) || 22}`
104
- }
105
-
106
- /** Safe path segment for a session id (mirrors DSH's encodeSegment). */
107
- export function encodeSegmentSafe(id) {
108
- const s = String(id || '').replace(/[^A-Za-z0-9._-]/g, '_')
109
- return s || 'session'
110
- }
111
-
112
- /** Read the cwd from a session log header (JSONL / .gz / zstd first frame). */
113
- export function readSessionHeaderCwd(file) {
114
- try {
115
- let buf = readFileSync(file)
116
- if (/\.zstd$/.test(file)) buf = zlib.zstdDecompressSync(buf)
117
- else if (/\.gz$/.test(file)) buf = zlib.gunzipSync(buf)
118
- const nl = buf.indexOf(10)
119
- if (nl < 0) return ''
120
- const head = JSON.parse(buf.subarray(0, nl).toString('utf8'))
121
- return typeof head.cwd === 'string' ? head.cwd : ''
122
- } catch {
123
- return ''
124
- }
125
- }
126
-
127
- /**
128
- * Resolve a session's workspace cwd from the live sessions service, then from
129
- * durable session logs under `$DSH_HOME/sessions`.
130
- */
131
- export function lookupSessionCwd(sessionId, { sessions, dshHome } = {}) {
132
- if (!sessionId) return ''
133
- try {
134
- if (sessions && typeof sessions.get === 'function') {
135
- const s = sessions.get(sessionId)
136
- const cwd = s && s.header && s.header.cwd
137
- if (cwd) return String(cwd)
138
- }
139
- } catch { /* sessions service unavailable */ }
140
- if (!dshHome) return ''
141
- try {
142
- const sessionsRoot = path.join(dshHome, 'sessions')
143
- if (!existsSync(sessionsRoot)) return ''
144
- const targetDir = encodeSegmentSafe(sessionId)
145
- for (const projDir of readdirSync(sessionsRoot)) {
146
- const projPath = path.join(sessionsRoot, projDir)
147
- if (!statSync(projPath, { throwIfNoEntry: false })?.isDirectory?.()) continue
148
- const sessDir = path.join(projPath, targetDir)
149
- if (!statSync(sessDir, { throwIfNoEntry: false })?.isDirectory?.()) continue
150
- const logFile = ['session.jsonl.zstd', 'session.jsonl', 'session.jsonl.gz']
151
- .map((n) => path.join(sessDir, n)).find((p) => existsSync(p))
152
- if (!logFile) continue
153
- const cwd = readSessionHeaderCwd(logFile)
154
- if (cwd) return cwd
155
- }
156
- } catch { /* session log scan failed */ }
157
- return ''
158
- }
159
-
160
- /** Pull sessionId / local from a JSON HTTP request (query string + body). */
161
- export function requestSessionHint(req, body = {}) {
162
- let sessionId = ''
163
- let local = ''
164
- try {
165
- const q = new URL(req.url || '', 'http://localhost').searchParams
166
- sessionId = q.get('sessionId') ? decodeURIComponent(q.get('sessionId')) : ''
167
- local = q.get('local') ? decodeURIComponent(q.get('local')) : ''
168
- } catch { /* malformed url */ }
169
- if (!sessionId && body && body.sessionId) sessionId = String(body.sessionId)
170
- if (!local && body && body.local) local = String(body.local)
171
- return { sessionId: String(sessionId || '').trim(), local: String(local || '').trim() }
172
- }
1
+ // Session → remote-binding resolution.
2
+ //
3
+ // A session's remote target is derived from its own workspace mirror, never
4
+ // from the plugin's mutable active-machine state. That is what keeps concurrent
5
+ // sessions on different hosts independent: with a single shared connection and
6
+ // a single shared workspace value, one session switching machines redirected
7
+ // every other session's commands to the wrong host (issue #25).
8
+ //
9
+ // The mirror directory is the durable record of that binding: `ensureMirror()`
10
+ // writes `.dsh-remote-meta.json` with the remote origin (`host`/`port`/
11
+ // `username`/`remotePath`) when the workspace is picked, so a session's cwd
12
+ // alone identifies both the machine to connect to and the workspace root.
13
+
14
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
15
+ import path from 'node:path'
16
+ import zlib from 'node:zlib'
17
+
18
+ /** Strip trailing separators so a mirror root and a path inside it compare cleanly. */
19
+ const norm = (p) => path.resolve(String(p || '')).replace(/[\\/]+$/, '') || ''
20
+
21
+ /** Whether `base` is `dir` itself or nested under it (separator-aware, so
22
+ * `/a/mirror-2` is NOT treated as living inside `/a/mirror`). */
23
+ const isUnder = (base, dir) => base === dir || base.startsWith(dir + path.sep) || base.startsWith(dir + '/')
24
+
25
+ /**
26
+ * Resolve which remote workspace a LOCAL path belongs to by scanning the mirror
27
+ * registry for the mirror that contains it.
28
+ *
29
+ * Mirrors live exactly one level under the registry root as
30
+ * `<host>-<user>-<port>/<basename>`, and `mirrorDirFor()` appends a short hash
31
+ * when two remote paths share a basename, so containment is unambiguous. The
32
+ * longest containing path still wins, which keeps the result stable if a
33
+ * future layout ever nests them.
34
+ *
35
+ * A mirror whose meta is missing, unparsable, or has no `host` is skipped
36
+ * rather than guessed at: reporting no binding makes the caller refuse loudly,
37
+ * while guessing would send commands to an unintended host.
38
+ *
39
+ * @param {string} local - absolute local path, typically a session's cwd.
40
+ * @param {string} root - the mirror registry root (`$DSH_HOME/remote-workspaces`).
41
+ * @returns {{mirrorDir: string|null, remotePath: string, machine: {host: string, port: number, username: string, alias: string}|null}}
42
+ * `machine` is the mirror-recorded origin (`alias` is the ~/.ssh/config alias
43
+ * it was created through, '' when the machine uses literal values), or null
44
+ * when `local` is not inside a usable mirror (in which case `remotePath` is
45
+ * empty too).
46
+ */
47
+ export function resolveMirror(local, root) {
48
+ let mirrorDir = null
49
+ let remotePath = ''
50
+ let machine = null
51
+ if (!local || !root || !existsSync(root)) return { mirrorDir, remotePath, machine }
52
+ const base = norm(local)
53
+ let hostDirs
54
+ try {
55
+ hostDirs = readdirSync(root)
56
+ } catch {
57
+ return { mirrorDir, remotePath, machine }
58
+ }
59
+ for (const hostDir of hostDirs) {
60
+ const hostPath = path.join(root, hostDir)
61
+ if (!statSync(hostPath, { throwIfNoEntry: false })?.isDirectory?.()) continue
62
+ let entries
63
+ try {
64
+ entries = readdirSync(hostPath)
65
+ } catch {
66
+ continue
67
+ }
68
+ for (const entry of entries) {
69
+ const metaPath = path.join(hostPath, entry, '.dsh-remote-meta.json')
70
+ if (!existsSync(metaPath)) continue
71
+ const mirrorAbs = norm(path.join(hostPath, entry))
72
+ if (!isUnder(base, mirrorAbs)) continue
73
+ // Deepest match wins; an equal-length path cannot occur twice.
74
+ if (mirrorDir && mirrorAbs.length <= mirrorDir.length) continue
75
+ try {
76
+ const meta = JSON.parse(readFileSync(metaPath, 'utf8'))
77
+ if (!meta || !meta.host) continue
78
+ mirrorDir = mirrorAbs
79
+ remotePath = String(meta.remotePath || '')
80
+ machine = {
81
+ host: String(meta.host),
82
+ port: Number(meta.port) || 22,
83
+ username: String(meta.username || ''),
84
+ // The ~/.ssh/config alias this mirror was created through, when the
85
+ // machine was saved as one (issue #38): it keeps the mirror bound to
86
+ // its machine even if that alias's HostName/port later change.
87
+ alias: String(meta.alias || ''),
88
+ }
89
+ } catch { /* unparsable meta → not a usable binding */ }
90
+ }
91
+ }
92
+ return { mirrorDir, remotePath, machine }
93
+ }
94
+
95
+ /**
96
+ * Stable pool key for a remote identity. Two sessions on the same machine
97
+ * produce the same key and therefore share one SSH connection; sessions on
98
+ * different machines never collide.
99
+ * @param {{host: string, port?: number|string, username?: string}} m - the remote identity.
100
+ * @returns {string} the canonical `user@host:port` key.
101
+ */
102
+ export function poolKey(m) {
103
+ return `${(m && m.username) || ''}@${(m && m.host) || ''}:${Number(m && m.port) || 22}`
104
+ }
105
+
106
+ /** Safe path segment for a session id (mirrors DSH's encodeSegment). */
107
+ export function encodeSegmentSafe(id) {
108
+ const s = String(id || '').replace(/[^A-Za-z0-9._-]/g, '_')
109
+ return s || 'session'
110
+ }
111
+
112
+ /** Read the cwd from a session log header (JSONL / .gz / zstd first frame). */
113
+ export function readSessionHeaderCwd(file) {
114
+ try {
115
+ let buf = readFileSync(file)
116
+ if (/\.zstd$/.test(file)) buf = zlib.zstdDecompressSync(buf)
117
+ else if (/\.gz$/.test(file)) buf = zlib.gunzipSync(buf)
118
+ const nl = buf.indexOf(10)
119
+ if (nl < 0) return ''
120
+ const head = JSON.parse(buf.subarray(0, nl).toString('utf8'))
121
+ return typeof head.cwd === 'string' ? head.cwd : ''
122
+ } catch {
123
+ return ''
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Resolve a session's workspace cwd from the live sessions service, then from
129
+ * durable session logs under `$DSH_HOME/sessions`.
130
+ */
131
+ export function lookupSessionCwd(sessionId, { sessions, dshHome } = {}) {
132
+ if (!sessionId) return ''
133
+ try {
134
+ if (sessions && typeof sessions.get === 'function') {
135
+ const s = sessions.get(sessionId)
136
+ const cwd = s && s.header && s.header.cwd
137
+ if (cwd) return String(cwd)
138
+ }
139
+ } catch { /* sessions service unavailable */ }
140
+ if (!dshHome) return ''
141
+ try {
142
+ const sessionsRoot = path.join(dshHome, 'sessions')
143
+ if (!existsSync(sessionsRoot)) return ''
144
+ const targetDir = encodeSegmentSafe(sessionId)
145
+ for (const projDir of readdirSync(sessionsRoot)) {
146
+ const projPath = path.join(sessionsRoot, projDir)
147
+ if (!statSync(projPath, { throwIfNoEntry: false })?.isDirectory?.()) continue
148
+ const sessDir = path.join(projPath, targetDir)
149
+ if (!statSync(sessDir, { throwIfNoEntry: false })?.isDirectory?.()) continue
150
+ const logFile = ['session.jsonl.zstd', 'session.jsonl', 'session.jsonl.gz']
151
+ .map((n) => path.join(sessDir, n)).find((p) => existsSync(p))
152
+ if (!logFile) continue
153
+ const cwd = readSessionHeaderCwd(logFile)
154
+ if (cwd) return cwd
155
+ }
156
+ } catch { /* session log scan failed */ }
157
+ return ''
158
+ }
159
+
160
+ /** Pull sessionId / local from a JSON HTTP request (query string + body). */
161
+ export function requestSessionHint(req, body = {}) {
162
+ let sessionId = ''
163
+ let local = ''
164
+ try {
165
+ const q = new URL(req.url || '', 'http://localhost').searchParams
166
+ sessionId = q.get('sessionId') ? decodeURIComponent(q.get('sessionId')) : ''
167
+ local = q.get('local') ? decodeURIComponent(q.get('local')) : ''
168
+ } catch { /* malformed url */ }
169
+ if (!sessionId && body && body.sessionId) sessionId = String(body.sessionId)
170
+ if (!local && body && body.local) local = String(body.local)
171
+ return { sessionId: String(sessionId || '').trim(), local: String(local || '').trim() }
172
+ }