dsh-remote 1.3.0 → 1.4.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 +2 -0
- package/README.md +2 -0
- package/lib/client.js +290 -11
- package/lib/deck-bridge.js +17 -0
- package/lib/errors.js +5 -2
- package/lib/main.js +19 -0
- package/lib/openssh.js +119 -5
- package/lib/pool.js +46 -4
- package/lib/update.js +163 -34
- package/lib/workspace-files-remote.js +479 -0
- package/package.json +4 -3
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
// dsh-remote — serve the core `workspaceFiles` Remote from the REMOTE origin
|
|
2
|
+
// for mirror sessions (issue #194).
|
|
3
|
+
//
|
|
4
|
+
// The core service (@deepseek-ai/dsh-api-workspace-files) resolves every
|
|
5
|
+
// read/readBytes/stat/list against the session header's cwd. For a remote
|
|
6
|
+
// Session that cwd is the LOCAL MIRROR, so the core file surfaces answered
|
|
7
|
+
// from the mirror — silently stale whenever the remote changed outside this
|
|
8
|
+
// plugin's own writes, and `list` showed a tree that could lag arbitrarily
|
|
9
|
+
// behind the real workspace. The two surfaces the plugin already owns
|
|
10
|
+
// (NATIVE_LINK file links and the sidebar explorer) never had the bug; this
|
|
11
|
+
// closes the remaining consumers: the `file` resource provider's stat/read,
|
|
12
|
+
// byte windows, workspace listings, and any third-party Remote client.
|
|
13
|
+
//
|
|
14
|
+
// There is no provider vocabulary on this service (unlike `skills`): a second
|
|
15
|
+
// cordis Service under the same name throws, and the wire descriptor stays
|
|
16
|
+
// bound to the core instance. The Gateway resolves methods with Reflect.get on
|
|
17
|
+
// the LIVE service at call time, so the supported seam is an instance-method
|
|
18
|
+
// wrapper — installed inject-scoped, keyed strictly on the mirror binding, and
|
|
19
|
+
// exactly reversible on dispose:
|
|
20
|
+
//
|
|
21
|
+
// • only read / readBytes / stat / list are wrapped. `changes` keeps the
|
|
22
|
+
// core's local watcher: a remote has no inotify over SFTP, and today's
|
|
23
|
+
// local-mirror watch still fires for every write this plugin makes (it
|
|
24
|
+
// syncs the mirror), so remote-external edits remain the only misses —
|
|
25
|
+
// the same trade the file tab already makes. See the issue for the
|
|
26
|
+
// upstream polling vocabulary this would need.
|
|
27
|
+
// • a call is served remotely ONLY when its workspaceFileScope resolves to
|
|
28
|
+
// a usable mirror binding (meta-recorded host/port/user; a mirror whose
|
|
29
|
+
// meta is missing is skipped, never guessed — the resolveMirror rule).
|
|
30
|
+
// Every other scope falls through to the core implementation untouched.
|
|
31
|
+
// • errors propagate with the core's `workspace-file/*` codes — no silent
|
|
32
|
+
// fallback to the stale mirror, which is exactly the bug being fixed.
|
|
33
|
+
// RemoteError is constructed STRUCTURALLY (isDSHRemoteError marker), the
|
|
34
|
+
// same cross-bundle identification the protocol itself uses, so no new
|
|
35
|
+
// peer dependency on the typert package is required.
|
|
36
|
+
// • path mapping reuses resolveRemoteWorkspacePath, the rw_* tools' proven
|
|
37
|
+
// rule: workspace-relative paths join onto the mirror's remotePath, a
|
|
38
|
+
// local path INSIDE the mirror maps to the same remote file, any other
|
|
39
|
+
// absolute path is a path in the session's execution world (the remote).
|
|
40
|
+
//
|
|
41
|
+
// The remote side enforces the same caps the core deployment configures
|
|
42
|
+
// (read off the live service instance when present): maxBytes per page,
|
|
43
|
+
// maxLines per page, maxFileBytes for complete reads, maxEntries per listing.
|
|
44
|
+
// One deliberate addition: paging to a far line requires scanning from byte 0,
|
|
45
|
+
// cheap on a local disk but a slow SFTP round-trip stream remotely — the scan
|
|
46
|
+
// is bounded by maxFileBytes, so an offset deep into a giant file fails fast
|
|
47
|
+
// with `workspace-file/too-large` instead of grinding the connection.
|
|
48
|
+
|
|
49
|
+
import { listDirStructured } from './remote-fs.js'
|
|
50
|
+
import { missingRemoteFile } from './remote-write.js'
|
|
51
|
+
import {
|
|
52
|
+
normalizeRemotePath, joinRemoteRel, remoteDirname, relPathUnder, resolveRemoteWorkspacePath,
|
|
53
|
+
} from './paths.js'
|
|
54
|
+
|
|
55
|
+
// Defaults mirror dsh-api-workspace-files' Config so behavior holds even when
|
|
56
|
+
// the live instance hides its config (a future host build may).
|
|
57
|
+
const DEFAULT_CAPS = Object.freeze({
|
|
58
|
+
maxBytes: 2 * 1024 * 1024,
|
|
59
|
+
maxFileBytes: 32 * 1024 * 1024,
|
|
60
|
+
maxLines: 5000,
|
|
61
|
+
maxEntries: 2000,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
/** Structural RemoteError — see the header; never `instanceof` across bundles. */
|
|
65
|
+
function remoteError(code, message, details = {}) {
|
|
66
|
+
return Object.assign(new Error(message), {
|
|
67
|
+
name: 'RemoteError', isDSHRemoteError: true, code, details,
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const badRequest = (message) => remoteError('gateway/bad-request', message, {})
|
|
72
|
+
const notFound = (path) => remoteError('workspace-file/not-found', `no entry at "${path}"`, { path })
|
|
73
|
+
const notRegularFile = (path, kind) =>
|
|
74
|
+
remoteError('workspace-file/not-regular-file', `"${path}" is a ${kind}`, { path, kind })
|
|
75
|
+
const notText = (path) =>
|
|
76
|
+
remoteError('workspace-file/not-text', `"${path}" is not UTF-8 text`, { path })
|
|
77
|
+
const tooLarge = (path, message, limit) =>
|
|
78
|
+
remoteError('workspace-file/too-large', message, { path, limit })
|
|
79
|
+
const notDirectory = (path, kind) =>
|
|
80
|
+
remoteError('workspace-file/not-directory', `"${path}" is a ${kind}`, { path, kind })
|
|
81
|
+
const outsideWorkspace = (path) =>
|
|
82
|
+
remoteError('workspace-file/outside-workspace', `"${path}" is outside the workspace`, { path })
|
|
83
|
+
|
|
84
|
+
const NUL = String.fromCharCode(0)
|
|
85
|
+
const isMissingError = (error) =>
|
|
86
|
+
missingRemoteFile(error) || /no such file|not found|does not exist|enoent|not a directory|enotdir/i.test(String((error && error.message) || error))
|
|
87
|
+
|
|
88
|
+
function throwIfAborted(signal) {
|
|
89
|
+
if (!signal || signal.aborted !== true) return
|
|
90
|
+
throw signal.reason || Object.assign(new Error('remote workspace file read aborted'), { name: 'AbortError' })
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** ssh2 Stats → the core's entry vocabulary ('symlink' is the link itself). */
|
|
94
|
+
function attrKind(attrs) {
|
|
95
|
+
if (!attrs || typeof attrs !== 'object') return 'other'
|
|
96
|
+
if (typeof attrs.isDirectory === 'function' && attrs.isDirectory()) return 'directory'
|
|
97
|
+
if (typeof attrs.isSymbolicLink === 'function' && attrs.isSymbolicLink()) return 'symlink'
|
|
98
|
+
if (typeof attrs.isFile === 'function' && attrs.isFile()) return 'file'
|
|
99
|
+
return 'other'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Opaque freshness token for one remote stat. mtime has second resolution on
|
|
104
|
+
* plain SFTP, so two same-size writes within one second share a version — the
|
|
105
|
+
* client then skips one re-stat of an already-superseded preview. Coarser than
|
|
106
|
+
* the local backend's token, but the honest remote identity available without
|
|
107
|
+
* hashing the whole file.
|
|
108
|
+
*/
|
|
109
|
+
function versionOf(attrs) {
|
|
110
|
+
const mtime = typeof attrs?.mtime === 'number' ? attrs.mtime : 0
|
|
111
|
+
const size = typeof attrs?.size === 'number' ? attrs.size : 0
|
|
112
|
+
return `sftp:${mtime}:${size}`
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Caps of the live core service, falling back to the core defaults. */
|
|
116
|
+
function capsOf(service) {
|
|
117
|
+
const config = service && typeof service === 'object' ? service.config : undefined
|
|
118
|
+
if (!config || typeof config !== 'object') return DEFAULT_CAPS
|
|
119
|
+
const pick = (key) => Number.isFinite(Number(config[key])) && Number(config[key]) > 0 ? Number(config[key]) : DEFAULT_CAPS[key]
|
|
120
|
+
return { maxBytes: pick('maxBytes'), maxFileBytes: pick('maxFileBytes'), maxLines: pick('maxLines'), maxEntries: pick('maxEntries') }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Map one incoming path onto the session's remote execution world. Returns the
|
|
125
|
+
* absolute remote path (rw_* semantics, see the header); an EMPTY input is an
|
|
126
|
+
* error the caller reports before mapping.
|
|
127
|
+
*/
|
|
128
|
+
function remoteTargetOf(binding, path) {
|
|
129
|
+
const raw = String(path ?? '')
|
|
130
|
+
if (!raw) throw badRequest('path is required')
|
|
131
|
+
if (raw.includes(NUL)) throw badRequest('path must not contain NUL')
|
|
132
|
+
return resolveRemoteWorkspacePath(binding.remotePath, raw, binding.mirrorDir)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The mirror binding for one wire scope, or null when the scope is not ours. */
|
|
136
|
+
function bindingOf(resolveBinding, scope) {
|
|
137
|
+
if (!scope || typeof scope !== 'object' || typeof scope.workspaceRoot !== 'string' || !scope.workspaceRoot) return null
|
|
138
|
+
let binding = null
|
|
139
|
+
try { binding = resolveBinding(scope.workspaceRoot) || null } catch { binding = null }
|
|
140
|
+
if (!binding || !binding.machine || !binding.remotePath || !binding.mirrorDir) return null
|
|
141
|
+
return binding
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function sftpFor(poolForMachine, binding) {
|
|
145
|
+
return poolForMachine(binding.machine).sftp()
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** lstat the final component (the core refuses to read through a symlink). */
|
|
149
|
+
async function lstatEntry(sftp, remote, path) {
|
|
150
|
+
try {
|
|
151
|
+
return await sftp.lstat(remote)
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (isMissingError(error)) throw notFound(path)
|
|
154
|
+
throw error
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** stat (follows links) for identity, size and version. */
|
|
159
|
+
async function statEntry(sftp, remote, path) {
|
|
160
|
+
try {
|
|
161
|
+
return await sftp.stat(remote)
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (isMissingError(error)) throw notFound(path)
|
|
164
|
+
throw error
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The core's locateFile gates: lstat must see a regular file, stat confirms. */
|
|
169
|
+
async function locateRemoteFile(sftp, remote, path) {
|
|
170
|
+
const entry = await lstatEntry(sftp, remote, path)
|
|
171
|
+
if (attrKind(entry) !== 'file') throw notRegularFile(path, attrKind(entry))
|
|
172
|
+
const attrs = await statEntry(sftp, remote, path)
|
|
173
|
+
if (attrKind(attrs) !== 'file') throw notRegularFile(path, attrKind(attrs))
|
|
174
|
+
return attrs
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Page defaults and caps, the core's resolvePage rules. */
|
|
178
|
+
function resolvePage(range, caps) {
|
|
179
|
+
const rawOffset = range?.offset
|
|
180
|
+
const offset = rawOffset === undefined ? 1 : Math.trunc(Number(rawOffset))
|
|
181
|
+
if (rawOffset !== undefined && (!Number.isFinite(offset) || offset < 1 || Number(rawOffset) !== offset)) {
|
|
182
|
+
throw badRequest('offset must be a positive integer')
|
|
183
|
+
}
|
|
184
|
+
const rawLimit = range?.limit
|
|
185
|
+
const limit = rawLimit === undefined ? caps.maxLines : Math.trunc(Number(rawLimit))
|
|
186
|
+
if (rawLimit !== undefined && (!Number.isFinite(limit) || limit < 1 || Number(rawLimit) !== limit)) {
|
|
187
|
+
throw badRequest('limit must be a positive integer')
|
|
188
|
+
}
|
|
189
|
+
if (limit > caps.maxLines) throw badRequest(`limit must be at most ${caps.maxLines}`)
|
|
190
|
+
return { offset, limit }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Byte-window defaults and cap, the core's resolveWindow rules. */
|
|
194
|
+
function resolveWindow(range, caps, path) {
|
|
195
|
+
const rawOffset = range?.offset
|
|
196
|
+
const offset = rawOffset === undefined ? 0 : Math.trunc(Number(rawOffset))
|
|
197
|
+
const rawLength = range?.length
|
|
198
|
+
const length = rawLength === undefined ? caps.maxBytes : Math.trunc(Number(rawLength))
|
|
199
|
+
if (rawOffset !== undefined && (!Number.isFinite(offset) || offset < 0 || Number(rawOffset) !== offset)) throw badRequest('offset must be a non-negative integer')
|
|
200
|
+
if (rawLength !== undefined && (!Number.isFinite(length) || length < 1 || Number(rawLength) !== length)) throw badRequest('length must be a positive integer')
|
|
201
|
+
if (offset + length > Number.MAX_SAFE_INTEGER) throw badRequest('offset plus length must stay a safe integer')
|
|
202
|
+
if (length > caps.maxBytes) throw tooLarge(path, `${length} bytes of "${path}" exceed the ${caps.maxBytes} byte cap`, caps.maxBytes)
|
|
203
|
+
return { offset, length }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Decoded remote text as a chunk stream: SFTP windows fed through an incremental
|
|
208
|
+
* fatal UTF-8 decoder, so the file is never held whole and invalid sequences
|
|
209
|
+
* fail as `workspace-file/not-text` exactly like the core's streamText.
|
|
210
|
+
*/
|
|
211
|
+
async function* remoteTextChunks(sftp, remote, size, { chunkBytes = 128 * 1024, maxScanBytes } = {}) {
|
|
212
|
+
const decoder = new TextDecoder('utf-8', { fatal: true })
|
|
213
|
+
let offset = 0
|
|
214
|
+
let scanned = 0
|
|
215
|
+
while (offset < size) {
|
|
216
|
+
const length = Math.min(chunkBytes, size - offset)
|
|
217
|
+
const buf = await sftp.readPartial(remote, offset, length)
|
|
218
|
+
if (!buf || buf.length === 0) break
|
|
219
|
+
offset += buf.length
|
|
220
|
+
scanned += buf.length
|
|
221
|
+
if (maxScanBytes && scanned > maxScanBytes) {
|
|
222
|
+
throw tooLarge(remote, `scanning "${remote}" past ${maxScanBytes} bytes while seeking a page exceeds the full-file cap`, maxScanBytes)
|
|
223
|
+
}
|
|
224
|
+
let text
|
|
225
|
+
try {
|
|
226
|
+
text = decoder.decode(buf, { stream: true })
|
|
227
|
+
} catch {
|
|
228
|
+
throw notText(remote)
|
|
229
|
+
}
|
|
230
|
+
if (text) yield text
|
|
231
|
+
}
|
|
232
|
+
let tail
|
|
233
|
+
try {
|
|
234
|
+
tail = decoder.decode()
|
|
235
|
+
} catch {
|
|
236
|
+
throw notText(remote)
|
|
237
|
+
}
|
|
238
|
+
if (tail) yield tail
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Cut lines offset..offset+limit-1 from decoded chunks. A port of the core's
|
|
243
|
+
* cutPage: lines before the page are counted, not kept; the page is refused the
|
|
244
|
+
* moment its bytes exceed maxBytes (a giant line cannot grow memory past the
|
|
245
|
+
* cap either); the loop stops at the first character past the page.
|
|
246
|
+
*/
|
|
247
|
+
async function cutPage(chunks, offset, limit, maxBytes, path) {
|
|
248
|
+
const last = offset + limit - 1
|
|
249
|
+
const lines = []
|
|
250
|
+
let current = ''
|
|
251
|
+
let bytes = 0
|
|
252
|
+
let lineNumber = 1
|
|
253
|
+
const admit = (size) => {
|
|
254
|
+
bytes += size
|
|
255
|
+
if (bytes > maxBytes) {
|
|
256
|
+
throw tooLarge(path, `lines ${offset}-${last} of "${path}" exceed the ${maxBytes} byte cap`, maxBytes)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const complete = () => {
|
|
260
|
+
if (lines.length > 0) admit(1)
|
|
261
|
+
lines.push(current)
|
|
262
|
+
current = ''
|
|
263
|
+
}
|
|
264
|
+
for await (const chunk of chunks) {
|
|
265
|
+
let position = 0
|
|
266
|
+
while (position < chunk.length) {
|
|
267
|
+
if (lineNumber > last) return { text: lines.join('\n'), lines: lines.length, eof: false }
|
|
268
|
+
const newline = chunk.indexOf('\n', position)
|
|
269
|
+
const segment = newline === -1 ? chunk.slice(position) : chunk.slice(position, newline)
|
|
270
|
+
if (lineNumber >= offset) {
|
|
271
|
+
admit(Buffer.byteLength(segment, 'utf8'))
|
|
272
|
+
current += segment
|
|
273
|
+
}
|
|
274
|
+
if (newline === -1) break
|
|
275
|
+
if (lineNumber >= offset) complete()
|
|
276
|
+
lineNumber += 1
|
|
277
|
+
position = newline + 1
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (current.length > 0) complete()
|
|
281
|
+
return { text: lines.join('\n'), lines: lines.length, eof: true }
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** The four remote implementations. Each takes (binding, args-after-scope, service, deps). */
|
|
285
|
+
const remoteImpl = {
|
|
286
|
+
async read(binding, [path, range, signal], service, deps) {
|
|
287
|
+
const caps = capsOf(service)
|
|
288
|
+
const { offset, limit } = resolvePage(range, caps)
|
|
289
|
+
throwIfAborted(signal)
|
|
290
|
+
const sftp = await sftpFor(deps.poolForMachine, binding)
|
|
291
|
+
const remote = remoteTargetOf(binding, path)
|
|
292
|
+
const attrs = await locateRemoteFile(sftp, remote, path)
|
|
293
|
+
throwIfAborted(signal)
|
|
294
|
+
const page = await cutPage(
|
|
295
|
+
remoteTextChunks(sftp, remote, typeof attrs.size === 'number' ? attrs.size : 0, { maxScanBytes: caps.maxFileBytes }),
|
|
296
|
+
offset, limit, caps.maxBytes, path,
|
|
297
|
+
)
|
|
298
|
+
if (page.text.includes(NUL)) throw notText(path)
|
|
299
|
+
return {
|
|
300
|
+
absolutePath: remote,
|
|
301
|
+
version: versionOf(attrs),
|
|
302
|
+
...(typeof attrs.size === 'number' ? { bytes: attrs.size } : {}),
|
|
303
|
+
offset,
|
|
304
|
+
text: page.text,
|
|
305
|
+
lines: page.lines,
|
|
306
|
+
eof: page.eof,
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
async readBytes(binding, [path, options, signal], service, deps) {
|
|
311
|
+
const caps = capsOf(service)
|
|
312
|
+
options = options || {}
|
|
313
|
+
throwIfAborted(signal)
|
|
314
|
+
const sftp = await sftpFor(deps.poolForMachine, binding)
|
|
315
|
+
let target = path
|
|
316
|
+
if (options.baseFile !== undefined) {
|
|
317
|
+
// The core resolves a relative target against the BASE file's directory,
|
|
318
|
+
// and the base file must itself be a locatable regular file.
|
|
319
|
+
const base = remoteTargetOf(binding, options.baseFile)
|
|
320
|
+
await locateRemoteFile(sftp, base, options.baseFile)
|
|
321
|
+
const raw = String(path ?? '')
|
|
322
|
+
if (!raw) throw badRequest('path is required')
|
|
323
|
+
if (raw.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(raw) || /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(raw)) {
|
|
324
|
+
throw badRequest('path must be relative when baseFile is provided')
|
|
325
|
+
}
|
|
326
|
+
target = normalizeRemotePath(joinRemoteRel(remoteDirname(base), raw))
|
|
327
|
+
}
|
|
328
|
+
const remote = remoteTargetOf(binding, target)
|
|
329
|
+
const attrs = await locateRemoteFile(sftp, remote, path)
|
|
330
|
+
throwIfAborted(signal)
|
|
331
|
+
if (options.range === undefined) {
|
|
332
|
+
const limit = caps.maxFileBytes
|
|
333
|
+
if (typeof attrs.size === 'number' && attrs.size > limit) {
|
|
334
|
+
throw tooLarge(path, `"${path}" exceeds the ${limit} byte full-file cap`, limit)
|
|
335
|
+
}
|
|
336
|
+
const want = typeof attrs.size === 'number' ? attrs.size : 0
|
|
337
|
+
const data = want > 0 ? await sftp.readPartial(remote, 0, want) : Buffer.alloc(0)
|
|
338
|
+
return {
|
|
339
|
+
absolutePath: remote,
|
|
340
|
+
version: versionOf(attrs),
|
|
341
|
+
...(typeof attrs.size === 'number' ? { bytes: attrs.size } : {}),
|
|
342
|
+
offset: 0,
|
|
343
|
+
data: data || Buffer.alloc(0),
|
|
344
|
+
eof: true,
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const { offset, length } = resolveWindow(options.range, caps, path)
|
|
348
|
+
const data = await sftp.readPartial(remote, offset, length)
|
|
349
|
+
const got = data ? data.length : 0
|
|
350
|
+
const eof = typeof attrs.size === 'number' ? offset + got >= attrs.size : got < length
|
|
351
|
+
return {
|
|
352
|
+
absolutePath: remote,
|
|
353
|
+
version: versionOf(attrs),
|
|
354
|
+
...(typeof attrs.size === 'number' ? { bytes: attrs.size } : {}),
|
|
355
|
+
offset,
|
|
356
|
+
data: data || Buffer.alloc(0),
|
|
357
|
+
eof,
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
async stat(binding, [path, signal], service, deps) {
|
|
362
|
+
throwIfAborted(signal)
|
|
363
|
+
const sftp = await sftpFor(deps.poolForMachine, binding)
|
|
364
|
+
const remote = remoteTargetOf(binding, path)
|
|
365
|
+
const attrs = await locateRemoteFile(sftp, remote, path)
|
|
366
|
+
return {
|
|
367
|
+
absolutePath: remote,
|
|
368
|
+
version: versionOf(attrs),
|
|
369
|
+
...(typeof attrs.size === 'number' ? { bytes: attrs.size } : {}),
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
async list(binding, [path, signal], service, deps) {
|
|
374
|
+
const caps = capsOf(service)
|
|
375
|
+
throwIfAborted(signal)
|
|
376
|
+
const sftp = await sftpFor(deps.poolForMachine, binding)
|
|
377
|
+
const remote = remoteTargetOf(binding, path)
|
|
378
|
+
// Directories stay workspace-scoped, exactly like the core's confine().
|
|
379
|
+
const workspacePath = relPathUnder(binding.remotePath, remote)
|
|
380
|
+
if (workspacePath === null) throw outsideWorkspace(path)
|
|
381
|
+
const entry = await lstatEntry(sftp, remote, path)
|
|
382
|
+
const kind = attrKind(entry)
|
|
383
|
+
if (kind !== 'directory' && kind !== 'symlink') throw notDirectory(path, kind)
|
|
384
|
+
if (kind === 'symlink') {
|
|
385
|
+
const attrs = await statEntry(sftp, remote, path)
|
|
386
|
+
if (attrKind(attrs) !== 'directory') throw notDirectory(path, 'symlink')
|
|
387
|
+
}
|
|
388
|
+
throwIfAborted(signal)
|
|
389
|
+
const listing = await listDirStructured(sftp, remote)
|
|
390
|
+
if (!listing || listing.missing) throw notFound(path)
|
|
391
|
+
const entries = [...listing.items]
|
|
392
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
393
|
+
.map((item) => ({
|
|
394
|
+
name: item.name,
|
|
395
|
+
type: item.type === 'dir' ? 'directory' : 'file',
|
|
396
|
+
// listDirStructured already resolved symlinks to their destination's
|
|
397
|
+
// type and degrades dangling links to 'file'; sockets/devices also
|
|
398
|
+
// report 'file' (the core's 'other' bucket) — an approximation that
|
|
399
|
+
// only affects display, never read authority.
|
|
400
|
+
...(item.type === 'file' && typeof item.size === 'number' ? { size: item.size } : {}),
|
|
401
|
+
}))
|
|
402
|
+
return {
|
|
403
|
+
path: workspacePath,
|
|
404
|
+
entries: entries.slice(0, caps.maxEntries),
|
|
405
|
+
truncated: entries.length > caps.maxEntries,
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** Methods wrapped, and the wire's positional arguments after the scope. */
|
|
411
|
+
const WRAPPED_METHODS = ['read', 'readBytes', 'stat', 'list']
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Wrap the core `workspaceFiles` service so mirror sessions are served from
|
|
415
|
+
* their remote origin. Inert (returns a no-op handle) when the service is
|
|
416
|
+
* absent or exposes none of the expected methods — a composition without the
|
|
417
|
+
* file service keeps whatever behavior it already had.
|
|
418
|
+
*
|
|
419
|
+
* @param {object} ctx - host plugin context.
|
|
420
|
+
* @param {object} opts
|
|
421
|
+
* @param {(local: string) => {mirrorDir: string|null, remotePath: string, machine: object|null}} opts.resolveBinding
|
|
422
|
+
* @param {(machine: object) => object} opts.poolForMachine
|
|
423
|
+
* @param {object} [opts.logger]
|
|
424
|
+
* @returns {{dispose: () => void}}
|
|
425
|
+
*/
|
|
426
|
+
export function installWorkspaceFilesRemote(ctx, opts = {}) {
|
|
427
|
+
const { resolveBinding, poolForMachine } = opts
|
|
428
|
+
const noop = { dispose() {} }
|
|
429
|
+
if (typeof ctx?.inject !== 'function' || typeof resolveBinding !== 'function' || typeof poolForMachine !== 'function') return noop
|
|
430
|
+
let installed = null
|
|
431
|
+
let unregistered = false
|
|
432
|
+
ctx.inject(['workspaceFiles'], (scope) => {
|
|
433
|
+
const service = typeof scope?.get === 'function' ? scope.get('workspaceFiles') : scope?.workspaceFiles
|
|
434
|
+
if (!service || typeof service !== 'object' || unregistered) return
|
|
435
|
+
const wrapped = new Map()
|
|
436
|
+
for (const name of WRAPPED_METHODS) {
|
|
437
|
+
const original = service[name]
|
|
438
|
+
if (typeof original !== 'function') continue
|
|
439
|
+
const hadOwn = Object.hasOwn(service, name)
|
|
440
|
+
const routed = (...args) => routeRemote(name, service, original, args, { resolveBinding, poolForMachine })
|
|
441
|
+
try {
|
|
442
|
+
service[name] = routed
|
|
443
|
+
wrapped.set(name, { original, routed, hadOwn })
|
|
444
|
+
} catch {
|
|
445
|
+
// A frozen or readonly service face (an older host build): leave it be.
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (!wrapped.size) return
|
|
449
|
+
const restore = () => {
|
|
450
|
+
for (const [name, { original, routed, hadOwn }] of wrapped) {
|
|
451
|
+
if (service[name] !== routed) continue // someone else replaced it; theirs wins
|
|
452
|
+
if (hadOwn) service[name] = original
|
|
453
|
+
else delete service[name]
|
|
454
|
+
}
|
|
455
|
+
wrapped.clear()
|
|
456
|
+
}
|
|
457
|
+
installed = { restore }
|
|
458
|
+
if (typeof scope.effect === 'function') {
|
|
459
|
+
scope.effect(() => {
|
|
460
|
+
unregistered = true
|
|
461
|
+
restore()
|
|
462
|
+
})
|
|
463
|
+
}
|
|
464
|
+
})
|
|
465
|
+
return {
|
|
466
|
+
dispose() {
|
|
467
|
+
unregistered = true
|
|
468
|
+
if (installed) installed.restore()
|
|
469
|
+
installed = null
|
|
470
|
+
},
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** One gateway call: mirror binding → remote implementation, else the core's. */
|
|
475
|
+
async function routeRemote(name, service, original, args, deps) {
|
|
476
|
+
const binding = bindingOf(deps.resolveBinding, args[0])
|
|
477
|
+
if (!binding) return Reflect.apply(original, service, args)
|
|
478
|
+
return remoteImpl[name](binding, args.slice(1), service, deps)
|
|
479
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "SSH remote workspaces for DeepSeek Harness: parallel projects across hosts, remote file browsing and editing, recursive search, terminals, Git diffs, and workspace-bound Agent tools to edit, build and test remotely. Optional IDE layout.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "flymysql <flyphp@outlook.com>",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
".": "./lib/boot.js",
|
|
33
33
|
"./client": "./lib/client.js",
|
|
34
34
|
"./package.json": "./package.json",
|
|
35
|
-
"./cordis.patch.yml": "./cordis.patch.yml"
|
|
35
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
36
|
+
"./deck-bridge": "./lib/deck-bridge.js"
|
|
36
37
|
},
|
|
37
38
|
"files": [
|
|
38
39
|
"lib",
|
|
@@ -102,6 +103,6 @@
|
|
|
102
103
|
"test:coverage": "node scripts/coverage-union.mjs",
|
|
103
104
|
"test:coverage:gate": "node scripts/coverage-union.mjs --gate 70 --file-gate 60"
|
|
104
105
|
},
|
|
105
|
-
"readme": "[English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md) · **中文**\n\n# dsh-remote\n\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n[](https://github.com/topics/dsh-plugin)\n\n由 [@flymysql](https://github.com/flymysql) 维护 · [主页](https://flymysql.github.io/dsh-remote/) · [用量统计](https://flymysql.github.io/dsh-remote/stats/) · [博客](https://gitpull.cn) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [Issue](https://github.com/flymysql/dsh-remote/issues) · [English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md)\n\n\n\n在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中,把 SSH 主机变成日常开发工作区:管理多主机项目,浏览和编辑远程文件、递归搜索文件与内容、使用终端、查看 Git 差异、建立本地/反向端口隧道;让 Agent 在所属远程工作区中读写文件、执行命令、构建和测试。多个工作区可独立并行。\n\n可按习惯使用普通布局,或切换 **IDE 三栏布局**,并排查看远程文件、编辑器与原生 Agent 会话;切换时保留任务和未保存编辑。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-ide.png\" alt=\"DSH 远程工作区 IDE 模式:远程文件树、代码编辑器和原生 Agent 会话三栏\" width=\"1200\"/>\n\n## 安装\n\n```bash\ndsh plugin --profile web add dsh-remote\n```\n\n安装或升级后,重启 DSH Web 并刷新页面。自动更新状态在设置 → 远程工作区 → 插件偏好中查看。\n\n## 3 步开始\n\n1. **配置主机**:设置 → 远程工作区,编辑 SSH 配置或保存主机凭据;直接写在 `~/.ssh/config` 里的 Host 会出现在主机列表中,点该行的「…」菜单 →「编辑」即可保存成机器并填写登录密码(保存前后入口都是同一个「…」菜单)。打开设置会自动检查连通性,无需手动“连接”。\n2. **创建工作区**:添加工作区 → 远程,选择主机与目录。每个工作区独立绑定主机,设置页不选目录或“当前远程机”。\n3. **开始开发**:打开工作区文件或切换 IDE 模式,文件打开即可编辑并显示语法高亮,在远端搜索、运行命令并与 Agent 协作。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workspace-picker-browse.png\" alt=\"选择远程目录:固定路径与确认栏,目录列表占据弹窗主要区域\" width=\"720\"/>\n\n## 本地工作区也能用\n\n打开普通本地项目后,点击 **IDE 模式** 或 **工作区文件**,即可使用同一套文件树、高亮编辑、递归搜索、Git 差异与本地终端。无需配置 SSH;Agent 继续使用宿主原生文件和命令工具,多个本地、远程项目可并行工作。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-local.png\" alt=\"本地工作区:文件搜索、高亮编辑和原生 Agent 会话,Agent 已实际完成本地构建\" width=\"1200\"/>\n\n## 日常开发\n\n### 搜索远端文件与内容\n\n文件、目录和内容递归搜索,无需先展开目录或同步镜像。默认界面只显示搜索范围与进度摘要;按需展开搜索选项、扫描详情,支持大小写、忽略项、停止与重试。点击结果进入目录或文件对应行。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-search-results.png\" alt=\"简洁远程搜索:名称搜索结果包含嵌套目录与文件\" width=\"675\"/>\n\n### 查看远端 Git 改动\n\n分别查看工作区和已暂存 diff,筛选文件,点击改动行定位源码。面板只读,不提交或修改暂存区。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-git.png\" alt=\"远端 Git 工作区与已暂存改动、文件列表和源码 diff\" width=\"675\"/>\n\n### 在远端运行终端\n\n终端进入当前会话的远程目录;像素鱼欢迎图后接真实 SSH shell。已保存凭据可自动应答,支持多终端并行。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-terminal.png\" alt=\"DSH 远程终端:像素鱼欢迎图与实际 SSH 命令输出\" width=\"1000\"/>\n\n### 端口转发(SSH 隧道)\n\n谁要发起访问,就在谁那边开监听口:监听口开在本机是本地转发(`ssh -L`),开在远端是远程转发(`ssh -R`)。可同时运行多条;添加转发时可以选择「主机」,每条转发只属于一台机器——给还没连接的主机也能先存下转发,连上后再启动。每条转发都可以点「编辑」调整方向、端口、目标或所属主机,运行中的会先停止、保存后按新配置重新启动。每行能直接勾选「自动重连」——只恢复上次运行中的转发,且按机器隔离,反向转发首次勾选会提示远端监听风险。\n\n从旧版本升级:旧版没有 `lastActive` 的「自动重连」配置会暂停,行上显示「需重新确认」;重新勾选后才会参与自动恢复(反向转发需重新确认远端监听)。\n\n<img src=\"docs/shots/port-forwards.png\" alt=\"端口转发面板:本地/反向方向、自动重连勾选框与添加转发表单\" width=\"900\"/>\n\n### 与 Agent 一起修改和构建\n\n工具卡展示已应用改动、实际退出码和构建输出,编译诊断可跳转源码。编辑器保存会检测远端冲突、保留 CRLF,并保护保存期间继续输入的内容。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-applied-diff.png\" alt=\"Agent 远程编辑成功后的已应用 diff、路径与增删行数\" width=\"485\"/>\n\n## 兼容与边界\n\n- 主要面向 **DSH Web 0.2.x**;0.2.2 需要 **Node.js ≥24.9**。旧版宿主回退、Desktop/TUI 与 Agent diff 差异见[兼容说明](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md#dsh-版本兼容性)。\n- 文件栏直接访问远端;镜像按需同步。草稿在当前页面内存,崩溃或强制退出仍可能丢失。\n- 不提供远端语言服务、扩展宿主或调试器。Agent 使用配置的 SSH 身份执行命令,请只配置可信主机。\n\n## 文档与社区\n\n[完整工具与配置参考](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md) · [排障](https://github.com/flymysql/dsh-remote/blob/main/docs/troubleshooting.md) · [自更新修复](https://github.com/flymysql/dsh-remote/blob/main/docs/self-heal.md) · [升级指南](https://github.com/flymysql/dsh-remote/blob/main/docs/migration-1.0.md) · [更新记录](https://github.com/flymysql/dsh-remote/blob/main/CHANGELOG.md)\n\n[主页](https://flymysql.github.io/dsh-remote/) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [反馈问题](https://github.com/flymysql/dsh-remote/issues) · [贡献指南](https://github.com/flymysql/dsh-remote/blob/main/CONTRIBUTING.md) · [贡献者与致谢](#贡献者与致谢)\n\n由 [@flymysql](https://github.com/flymysql) 与社区共同维护 · [MIT](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n\n### 贡献者与致谢\n\n感谢每一位让这个项目更好的朋友(头像可点进主页;按提交数排序,机器人不计):\n\n<p align=\"left\">\n <a href=\"https://github.com/flymysql\"><img src=\"https://avatars.githubusercontent.com/u/37113068?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@flymysql\" title=\"@flymysql\" /></a>\n <a href=\"https://github.com/baiseraku\"><img src=\"https://avatars.githubusercontent.com/u/139727690?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@baiseraku\" title=\"@baiseraku\" /></a>\n <a href=\"https://github.com/glzhangzhi\"><img src=\"https://avatars.githubusercontent.com/u/36995275?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@glzhangzhi\" title=\"@glzhangzhi\" /></a>\n <a href=\"https://github.com/hjwsm1989\"><img src=\"https://avatars.githubusercontent.com/u/1067541?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@hjwsm1989\" title=\"@hjwsm1989\" /></a>\n <a href=\"https://github.com/j10ha0\"><img src=\"https://avatars.githubusercontent.com/u/72346906?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@j10ha0\" title=\"@j10ha0\" /></a>\n <a href=\"https://github.com/FoolishWiser\"><img src=\"https://avatars.githubusercontent.com/u/104308087?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@FoolishWiser\" title=\"@FoolishWiser\" /></a>\n <a href=\"https://github.com/kakaa-nju\"><img src=\"https://avatars.githubusercontent.com/u/79886619?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@kakaa-nju\" title=\"@kakaa-nju\" /></a>\n <a href=\"https://github.com/4FMTWRV\"><img src=\"https://avatars.githubusercontent.com/u/190457700?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@4FMTWRV\" title=\"@4FMTWRV\" /></a>\n <a href=\"https://github.com/dahaipeng\"><img src=\"https://avatars.githubusercontent.com/u/25660610?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@dahaipeng\" title=\"@dahaipeng\" /></a>\n <a href=\"https://github.com/davidlin2k\"><img src=\"https://avatars.githubusercontent.com/u/17074619?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@davidlin2k\" title=\"@davidlin2k\" /></a>\n <a href=\"https://github.com/FlintyLemming\"><img src=\"https://avatars.githubusercontent.com/u/19165511?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@FlintyLemming\" title=\"@FlintyLemming\" /></a>\n <a href=\"https://github.com/GDWhisper\"><img src=\"https://avatars.githubusercontent.com/u/129148123?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@GDWhisper\" title=\"@GDWhisper\" /></a>\n <a href=\"https://github.com/YiHui-Liu\"><img src=\"https://avatars.githubusercontent.com/u/30190271?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@YiHui-Liu\" title=\"@YiHui-Liu\" /></a>\n <a href=\"https://github.com/Minggle\"><img src=\"https://avatars.githubusercontent.com/u/35053182?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@Minggle\" title=\"@Minggle\" /></a>\n <a href=\"https://github.com/nekomona\"><img src=\"https://avatars.githubusercontent.com/u/25474483?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@nekomona\" title=\"@nekomona\" /></a>\n <a href=\"https://github.com/shis23\"><img src=\"https://avatars.githubusercontent.com/u/189869650?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@shis23\" title=\"@shis23\" /></a>\n</p>\n\n<details>\n<summary>贡献记录与早期贡献者</summary>\n\n近期的亮点贡献(欢迎随时加入这个名单):\n\n| 贡献者 | 做了什么 |\n| --- | --- |\n| [@baiseraku](https://github.com/baiseraku) | 整个 dsh-tui 适配层([#92](https://github.com/flymysql/dsh-remote/pull/92))+ 底栏机器名修正([#98](https://github.com/flymysql/dsh-remote/pull/98)) |\n| [@hjwsm1989](https://github.com/hjwsm1989) | 远程 .md 渲染连环两道:memo 守卫([#102](https://github.com/flymysql/dsh-remote/pull/102))+ labels 契约([#107](https://github.com/flymysql/dsh-remote/pull/107)) |\n| [@shis23](https://github.com/shis23) | rw_sync 路径映射纠偏 + SFTP 超时韧性([#105](https://github.com/flymysql/dsh-remote/pull/105)) |\n| [@davidlin2k](https://github.com/davidlin2k) | 无凭据机器走用户自有 ssh([#100](https://github.com/flymysql/dsh-remote/pull/100)) |\n| [@GDWhisper](https://github.com/GDWhisper) | 目录补全逐字符重连修复([#42](https://github.com/flymysql/dsh-remote/pull/42),issue #41) |\n| [@glzhangzhi](https://github.com/glzhangzhi) | 多远端会话的连接池隔离(issue #25 的主体修复) |\n\n早期已合并 PR 的贡献者(考古名单):\n\n\n\n[@dahaipeng](https://github.com/dahaipeng) (#31) ·\n[@YiHui-Liu](https://github.com/YiHui-Liu) (#28) ·\n[@nekomona](https://github.com/nekomona) (#24) ·\n[@zhz1667](https://github.com/zhz1667) (#43) ·\n[FoolishWiser](https://github.com/FoolishWiser) (#17) ·\n[@jace1cch](https://github.com/jace1cch) (#16) ·\n[@Minggle](https://github.com/Minggle) (#10) ·\n[4FMTWRV](https://github.com/4FMTWRV) (#6) ·\n[glzhangzhi](https://github.com/glzhangzhi)(per-session SSH 连接池修复)\n\n> 名单随版本更新;头像墙之外的每一份 issue 报告、复现步骤、根因线索同样珍贵——\n> 本仓库近半修复的起点都是一条写清楚的 issue。\n\n</details>\n",
|
|
106
|
+
"readme": "[English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md) · **中文**\n\n# dsh-remote\n\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n[](https://github.com/topics/dsh-plugin)\n\n由 [@flymysql](https://github.com/flymysql) 维护 · [主页](https://flymysql.github.io/dsh-remote/) · [用量统计](https://flymysql.github.io/dsh-remote/stats/) · [博客](https://gitpull.cn) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [Issue](https://github.com/flymysql/dsh-remote/issues) · [English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md)\n\n\n\n在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中,把 SSH 主机变成日常开发工作区:管理多主机项目,浏览和编辑远程文件、递归搜索文件与内容、使用终端、查看 Git 差异、建立本地/反向端口隧道;让 Agent 在所属远程工作区中读写文件、执行命令、构建和测试。多个工作区可独立并行。\n\n可按习惯使用普通布局,或切换 **IDE 三栏布局**,并排查看远程文件、编辑器与原生 Agent 会话;切换时保留任务和未保存编辑。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-ide.png\" alt=\"DSH 远程工作区 IDE 模式:远程文件树、代码编辑器和原生 Agent 会话三栏\" width=\"1200\"/>\n\n## 安装\n\n```bash\ndsh plugin --profile web add dsh-remote\n```\n\n安装或升级后,重启 DSH Web 并刷新页面。自动更新状态在设置 → 远程工作区 → 插件偏好中查看。\n\n[1.4.0 更新说明](https://github.com/flymysql/dsh-remote/blob/main/docs/release/1.4.0.md):镜像会话文件预览直读远端、Markdown 插图渲染、OpenSSH 建连超时重试、工作区选择器恢复。\n\n## 3 步开始\n\n1. **配置主机**:设置 → 远程工作区,编辑 SSH 配置或保存主机凭据;直接写在 `~/.ssh/config` 里的 Host 会出现在主机列表中,点该行的「…」菜单 →「编辑」即可保存成机器并填写登录密码(保存前后入口都是同一个「…」菜单)。打开设置会自动检查连通性,无需手动“连接”。\n2. **创建工作区**:添加工作区 → 远程,选择主机与目录。每个工作区独立绑定主机,设置页不选目录或“当前远程机”。\n3. **开始开发**:打开工作区文件或切换 IDE 模式,文件打开即可编辑并显示语法高亮,在远端搜索、运行命令并与 Agent 协作。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workspace-picker-browse.png\" alt=\"选择远程目录:固定路径与确认栏,目录列表占据弹窗主要区域\" width=\"720\"/>\n\n## 本地工作区也能用\n\n打开普通本地项目后,点击 **IDE 模式** 或 **工作区文件**,即可使用同一套文件树、高亮编辑、递归搜索、Git 差异与本地终端。无需配置 SSH;Agent 继续使用宿主原生文件和命令工具,多个本地、远程项目可并行工作。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-local.png\" alt=\"本地工作区:文件搜索、高亮编辑和原生 Agent 会话,Agent 已实际完成本地构建\" width=\"1200\"/>\n\n## 日常开发\n\n### 搜索远端文件与内容\n\n文件、目录和内容递归搜索,无需先展开目录或同步镜像。默认界面只显示搜索范围与进度摘要;按需展开搜索选项、扫描详情,支持大小写、忽略项、停止与重试。点击结果进入目录或文件对应行。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-search-results.png\" alt=\"简洁远程搜索:名称搜索结果包含嵌套目录与文件\" width=\"675\"/>\n\n### 查看远端 Git 改动\n\n分别查看工作区和已暂存 diff,筛选文件,点击改动行定位源码。面板只读,不提交或修改暂存区。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-git.png\" alt=\"远端 Git 工作区与已暂存改动、文件列表和源码 diff\" width=\"675\"/>\n\n### 在远端运行终端\n\n终端进入当前会话的远程目录;像素鱼欢迎图后接真实 SSH shell。已保存凭据可自动应答,支持多终端并行。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-terminal.png\" alt=\"DSH 远程终端:像素鱼欢迎图与实际 SSH 命令输出\" width=\"1000\"/>\n\n### 端口转发(SSH 隧道)\n\n谁要发起访问,就在谁那边开监听口:监听口开在本机是本地转发(`ssh -L`),开在远端是远程转发(`ssh -R`)。可同时运行多条;添加转发时可以选择「主机」,每条转发只属于一台机器——给还没连接的主机也能先存下转发,连上后再启动。每条转发都可以点「编辑」调整方向、端口、目标或所属主机,运行中的会先停止、保存后按新配置重新启动。每行能直接勾选「自动重连」——只恢复上次运行中的转发,且按机器隔离,反向转发首次勾选会提示远端监听风险。\n\n从旧版本升级:旧版没有 `lastActive` 的「自动重连」配置会暂停,行上显示「需重新确认」;重新勾选后才会参与自动恢复(反向转发需重新确认远端监听)。\n\n<img src=\"docs/shots/port-forwards.png\" alt=\"端口转发面板:本地/反向方向、自动重连勾选框与添加转发表单\" width=\"900\"/>\n\n### 与 Agent 一起修改和构建\n\n工具卡展示已应用改动、实际退出码和构建输出,编译诊断可跳转源码。编辑器保存会检测远端冲突、保留 CRLF,并保护保存期间继续输入的内容。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-applied-diff.png\" alt=\"Agent 远程编辑成功后的已应用 diff、路径与增删行数\" width=\"485\"/>\n\n## 兼容与边界\n\n- 主要面向 **DSH Web 0.2.x**;0.2.2 需要 **Node.js ≥24.9**。旧版宿主回退、Desktop/TUI 与 Agent diff 差异见[兼容说明](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md#dsh-版本兼容性)。\n- 文件栏直接访问远端;镜像按需同步。草稿在当前页面内存,崩溃或强制退出仍可能丢失。\n- 不提供远端语言服务、扩展宿主或调试器。Agent 使用配置的 SSH 身份执行命令,请只配置可信主机。\n\n## 文档与社区\n\n[完整工具与配置参考](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md) · [排障](https://github.com/flymysql/dsh-remote/blob/main/docs/troubleshooting.md) · [自更新修复](https://github.com/flymysql/dsh-remote/blob/main/docs/self-heal.md) · [升级指南](https://github.com/flymysql/dsh-remote/blob/main/docs/migration-1.0.md) · [更新记录](https://github.com/flymysql/dsh-remote/blob/main/CHANGELOG.md)\n\n[主页](https://flymysql.github.io/dsh-remote/) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [反馈问题](https://github.com/flymysql/dsh-remote/issues) · [贡献指南](https://github.com/flymysql/dsh-remote/blob/main/CONTRIBUTING.md) · [贡献者与致谢](#贡献者与致谢)\n\n由 [@flymysql](https://github.com/flymysql) 与社区共同维护 · [MIT](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n\n### 贡献者与致谢\n\n感谢每一位让这个项目更好的朋友(头像可点进主页;按提交数排序,机器人不计):\n\n<p align=\"left\">\n <a href=\"https://github.com/flymysql\"><img src=\"https://avatars.githubusercontent.com/u/37113068?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@flymysql\" title=\"@flymysql\" /></a>\n <a href=\"https://github.com/baiseraku\"><img src=\"https://avatars.githubusercontent.com/u/139727690?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@baiseraku\" title=\"@baiseraku\" /></a>\n <a href=\"https://github.com/glzhangzhi\"><img src=\"https://avatars.githubusercontent.com/u/36995275?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@glzhangzhi\" title=\"@glzhangzhi\" /></a>\n <a href=\"https://github.com/hjwsm1989\"><img src=\"https://avatars.githubusercontent.com/u/1067541?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@hjwsm1989\" title=\"@hjwsm1989\" /></a>\n <a href=\"https://github.com/j10ha0\"><img src=\"https://avatars.githubusercontent.com/u/72346906?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@j10ha0\" title=\"@j10ha0\" /></a>\n <a href=\"https://github.com/FoolishWiser\"><img src=\"https://avatars.githubusercontent.com/u/104308087?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@FoolishWiser\" title=\"@FoolishWiser\" /></a>\n <a href=\"https://github.com/kakaa-nju\"><img src=\"https://avatars.githubusercontent.com/u/79886619?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@kakaa-nju\" title=\"@kakaa-nju\" /></a>\n <a href=\"https://github.com/4FMTWRV\"><img src=\"https://avatars.githubusercontent.com/u/190457700?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@4FMTWRV\" title=\"@4FMTWRV\" /></a>\n <a href=\"https://github.com/dahaipeng\"><img src=\"https://avatars.githubusercontent.com/u/25660610?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@dahaipeng\" title=\"@dahaipeng\" /></a>\n <a href=\"https://github.com/davidlin2k\"><img src=\"https://avatars.githubusercontent.com/u/17074619?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@davidlin2k\" title=\"@davidlin2k\" /></a>\n <a href=\"https://github.com/FlintyLemming\"><img src=\"https://avatars.githubusercontent.com/u/19165511?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@FlintyLemming\" title=\"@FlintyLemming\" /></a>\n <a href=\"https://github.com/GDWhisper\"><img src=\"https://avatars.githubusercontent.com/u/129148123?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@GDWhisper\" title=\"@GDWhisper\" /></a>\n <a href=\"https://github.com/YiHui-Liu\"><img src=\"https://avatars.githubusercontent.com/u/30190271?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@YiHui-Liu\" title=\"@YiHui-Liu\" /></a>\n <a href=\"https://github.com/Minggle\"><img src=\"https://avatars.githubusercontent.com/u/35053182?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@Minggle\" title=\"@Minggle\" /></a>\n <a href=\"https://github.com/nekomona\"><img src=\"https://avatars.githubusercontent.com/u/25474483?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@nekomona\" title=\"@nekomona\" /></a>\n <a href=\"https://github.com/shis23\"><img src=\"https://avatars.githubusercontent.com/u/189869650?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@shis23\" title=\"@shis23\" /></a>\n</p>\n\n<details>\n<summary>贡献记录与早期贡献者</summary>\n\n近期的亮点贡献(欢迎随时加入这个名单):\n\n| 贡献者 | 做了什么 |\n| --- | --- |\n| [@baiseraku](https://github.com/baiseraku) | 整个 dsh-tui 适配层([#92](https://github.com/flymysql/dsh-remote/pull/92))+ 底栏机器名修正([#98](https://github.com/flymysql/dsh-remote/pull/98)) |\n| [@hjwsm1989](https://github.com/hjwsm1989) | 远程 .md 渲染连环两道:memo 守卫([#102](https://github.com/flymysql/dsh-remote/pull/102))+ labels 契约([#107](https://github.com/flymysql/dsh-remote/pull/107)) |\n| [@shis23](https://github.com/shis23) | rw_sync 路径映射纠偏 + SFTP 超时韧性([#105](https://github.com/flymysql/dsh-remote/pull/105)) |\n| [@davidlin2k](https://github.com/davidlin2k) | 无凭据机器走用户自有 ssh([#100](https://github.com/flymysql/dsh-remote/pull/100)) |\n| [@GDWhisper](https://github.com/GDWhisper) | 目录补全逐字符重连修复([#42](https://github.com/flymysql/dsh-remote/pull/42),issue #41) |\n| [@glzhangzhi](https://github.com/glzhangzhi) | 多远端会话的连接池隔离(issue #25 的主体修复) |\n\n早期已合并 PR 的贡献者(考古名单):\n\n\n\n[@dahaipeng](https://github.com/dahaipeng) (#31) ·\n[@YiHui-Liu](https://github.com/YiHui-Liu) (#28) ·\n[@nekomona](https://github.com/nekomona) (#24) ·\n[@zhz1667](https://github.com/zhz1667) (#43) ·\n[FoolishWiser](https://github.com/FoolishWiser) (#17) ·\n[@jace1cch](https://github.com/jace1cch) (#16) ·\n[@Minggle](https://github.com/Minggle) (#10) ·\n[4FMTWRV](https://github.com/4FMTWRV) (#6) ·\n[glzhangzhi](https://github.com/glzhangzhi)(per-session SSH 连接池修复)\n\n> 名单随版本更新;头像墙之外的每一份 issue 报告、复现步骤、根因线索同样珍贵——\n> 本仓库近半修复的起点都是一条写清楚的 issue。\n\n</details>\n",
|
|
106
107
|
"readmeFilename": "README.md"
|
|
107
108
|
}
|