dsh-remote-deck 0.0.0-stage → 1.46.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/LICENSE +21 -0
- package/README.md +227 -2
- package/README.zh-CN.md +201 -0
- package/client.js +8645 -0
- package/cordis.patch.yml +6 -0
- package/icon.svg +19 -0
- package/index.js +701 -0
- package/lib/api.js +1452 -0
- package/lib/bash-result.js +93 -0
- package/lib/connection.js +1133 -0
- package/lib/delete.js +199 -0
- package/lib/drafts.js +299 -0
- package/lib/encoding.js +247 -0
- package/lib/file-edit.js +339 -0
- package/lib/file-ops.js +402 -0
- package/lib/forwards.js +186 -0
- package/lib/fs-actions.js +235 -0
- package/lib/guide.js +162 -0
- package/lib/metrics.js +523 -0
- package/lib/remote-shells.js +320 -0
- package/lib/remote-terminal.js +427 -0
- package/lib/routing.js +695 -0
- package/lib/ssh-config.js +118 -0
- package/lib/terminal.js +123 -0
- package/lib/tool-forward.js +185 -0
- package/lib/transfer.js +235 -0
- package/lib/upload-chunks.js +306 -0
- package/lib/util.js +154 -0
- package/locale/README.md +160 -0
- package/locale/en-ui.json +477 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +63 -4
- package/vendor/codemirror/LICENSE +21 -0
- package/vendor/codemirror/README.md +18 -0
- package/vendor/codemirror/addon/edit/closebrackets.min.js +8 -0
- package/vendor/codemirror/addon/edit/matchbrackets.min.js +8 -0
- package/vendor/codemirror/addon/search/search.min.js +8 -0
- package/vendor/codemirror/addon/search/searchcursor.min.js +8 -0
- package/vendor/codemirror/addon/selection/active-line.min.js +8 -0
- package/vendor/codemirror/lib/codemirror.css +344 -0
- package/vendor/codemirror/lib/codemirror.min.js +8 -0
- package/vendor/codemirror/mode/clike/clike.min.js +8 -0
- package/vendor/codemirror/mode/css/css.min.js +8 -0
- package/vendor/codemirror/mode/go/go.min.js +8 -0
- package/vendor/codemirror/mode/htmlmixed/htmlmixed.min.js +8 -0
- package/vendor/codemirror/mode/javascript/javascript.min.js +8 -0
- package/vendor/codemirror/mode/markdown/markdown.min.js +8 -0
- package/vendor/codemirror/mode/python/python.min.js +8 -0
- package/vendor/codemirror/mode/rust/rust.min.js +8 -0
- package/vendor/codemirror/mode/shell/shell.min.js +8 -0
- package/vendor/codemirror/mode/xml/xml.min.js +8 -0
- package/vendor/codemirror/mode/yaml/yaml.min.js +8 -0
- package/vendor/node_modules/asn1/Jenkinsfile +65 -0
- package/vendor/node_modules/asn1/LICENSE +19 -0
- package/vendor/node_modules/asn1/README.md +50 -0
- package/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
- package/vendor/node_modules/asn1/lib/ber/index.js +27 -0
- package/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
- package/vendor/node_modules/asn1/lib/ber/types.js +36 -0
- package/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
- package/vendor/node_modules/asn1/lib/index.js +20 -0
- package/vendor/node_modules/asn1/package.json +31 -0
- package/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
- package/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
- package/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
- package/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
- package/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
- package/vendor/node_modules/safer-buffer/LICENSE +21 -0
- package/vendor/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/vendor/node_modules/safer-buffer/Readme.md +156 -0
- package/vendor/node_modules/safer-buffer/dangerous.js +58 -0
- package/vendor/node_modules/safer-buffer/package.json +34 -0
- package/vendor/node_modules/safer-buffer/safer.js +77 -0
- package/vendor/node_modules/safer-buffer/tests.js +406 -0
- package/vendor/node_modules/ssh2/LICENSE +19 -0
- package/vendor/node_modules/ssh2/README.md +1529 -0
- package/vendor/node_modules/ssh2/SFTP.md +413 -0
- package/vendor/node_modules/ssh2/lib/Channel.js +295 -0
- package/vendor/node_modules/ssh2/lib/agent.js +1123 -0
- package/vendor/node_modules/ssh2/lib/client.js +2176 -0
- package/vendor/node_modules/ssh2/lib/http-agents.js +84 -0
- package/vendor/node_modules/ssh2/lib/index.js +44 -0
- package/vendor/node_modules/ssh2/lib/keygen.js +582 -0
- package/vendor/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
- package/vendor/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
- package/vendor/node_modules/ssh2/lib/protocol/constants.js +356 -0
- package/vendor/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
- package/vendor/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
- package/vendor/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
- package/vendor/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
- package/vendor/node_modules/ssh2/lib/protocol/handlers.js +16 -0
- package/vendor/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
- package/vendor/node_modules/ssh2/lib/protocol/kex.js +1908 -0
- package/vendor/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
- package/vendor/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
- package/vendor/node_modules/ssh2/lib/protocol/utils.js +356 -0
- package/vendor/node_modules/ssh2/lib/protocol/zlib.js +255 -0
- package/vendor/node_modules/ssh2/lib/server.js +1380 -0
- package/vendor/node_modules/ssh2/lib/utils.js +336 -0
- package/vendor/node_modules/ssh2/package.json +49 -0
- package/vendor/node_modules/tweetnacl/AUTHORS.md +28 -0
- package/vendor/node_modules/tweetnacl/CHANGELOG.md +221 -0
- package/vendor/node_modules/tweetnacl/LICENSE +24 -0
- package/vendor/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
- package/vendor/node_modules/tweetnacl/README.md +459 -0
- package/vendor/node_modules/tweetnacl/nacl-fast.js +2388 -0
- package/vendor/node_modules/tweetnacl/nacl-fast.min.js +2 -0
- package/vendor/node_modules/tweetnacl/nacl.d.ts +98 -0
- package/vendor/node_modules/tweetnacl/nacl.js +1175 -0
- package/vendor/node_modules/tweetnacl/nacl.min.js +1 -0
- package/vendor/node_modules/tweetnacl/package.json +58 -0
- package/vendor/xterm/LICENSE.addon-fit +19 -0
- package/vendor/xterm/LICENSE.xterm +21 -0
- package/vendor/xterm/README.md +9 -0
- package/vendor/xterm/addon-fit.js +2 -0
- package/vendor/xterm/xterm.css +218 -0
- package/vendor/xterm/xterm.js +2 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for the remote bash tool: working-directory resolution and result
|
|
3
|
+
* rendering. Kept in lib/ so both index.js and the unit tests share one
|
|
4
|
+
* implementation (see docs/DESIGN in the workspace for the contract).
|
|
5
|
+
*/
|
|
6
|
+
import { isPosixPath, normalizeRemotePath } from './util.js'
|
|
7
|
+
|
|
8
|
+
const WINDOWS_PATH = /^[A-Za-z]:[\\/]/
|
|
9
|
+
const DEFAULT_MAX_BYTES = 4 * 1024 * 1024
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the effective remote working directory.
|
|
13
|
+
* - omitted -> session workspace
|
|
14
|
+
* - absolute POSIX -> normalized as-is
|
|
15
|
+
* - relative POSIX -> resolved against the session workspace
|
|
16
|
+
* - Windows path / backslashes -> hard error (never guess)
|
|
17
|
+
*
|
|
18
|
+
* @param {unknown} workdir raw tool argument
|
|
19
|
+
* @param {string} sessionPath remote workspace path
|
|
20
|
+
* @returns {{ cwd: string } | { error: string }}
|
|
21
|
+
*/
|
|
22
|
+
export function resolveWorkdir(workdir, sessionPath) {
|
|
23
|
+
const raw = typeof workdir === 'string' ? workdir.trim() : ''
|
|
24
|
+
if (raw.length === 0) return { cwd: normalizeRemotePath(sessionPath) }
|
|
25
|
+
if (raw.startsWith('~')) {
|
|
26
|
+
return { error: `remote-deck: workdir must be a remote POSIX path, not a home-relative path: ${JSON.stringify(raw)}` }
|
|
27
|
+
}
|
|
28
|
+
if (WINDOWS_PATH.test(raw) || raw.includes('\\')) {
|
|
29
|
+
return { error: `remote-deck: workdir must be a POSIX path on the remote host: ${JSON.stringify(raw)}` }
|
|
30
|
+
}
|
|
31
|
+
if (isPosixPath(raw)) return { cwd: normalizeRemotePath(raw) }
|
|
32
|
+
const base = normalizeRemotePath(sessionPath).replace(/\/+$/, '')
|
|
33
|
+
return { cwd: normalizeRemotePath(`${base}/${raw}`) }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Render one command result for the model.
|
|
38
|
+
* Explicit markers keep truncation, transport failures and signals
|
|
39
|
+
* distinguishable from a normal non-zero exit code.
|
|
40
|
+
*
|
|
41
|
+
* @param {{
|
|
42
|
+
* stdout?: string, stderr?: string, code?: number|null, signal?: string|null,
|
|
43
|
+
* truncatedOut?: boolean, truncatedErr?: boolean, transportError?: string|null,
|
|
44
|
+
* }} result
|
|
45
|
+
* @param {{ maxBytes?: number }} [options]
|
|
46
|
+
* @returns {{ text: string, exitCode: number }}
|
|
47
|
+
*/
|
|
48
|
+
export function renderBashResult(result, options) {
|
|
49
|
+
const cap = options?.maxBytes ?? DEFAULT_MAX_BYTES
|
|
50
|
+
const parts = []
|
|
51
|
+
if (typeof result.stdout === 'string' && result.stdout.length > 0) parts.push(result.stdout)
|
|
52
|
+
if (typeof result.stderr === 'string' && result.stderr.trim().length > 0) parts.push(`[stderr]\n${result.stderr}`)
|
|
53
|
+
if (result.truncatedOut === true || result.truncatedErr === true) {
|
|
54
|
+
parts.push(`[output truncated; first ${cap} bytes captured]`)
|
|
55
|
+
}
|
|
56
|
+
if (typeof result.transportError === 'string' && result.transportError.length > 0) {
|
|
57
|
+
parts.push(`[transport error: ${result.transportError}]`)
|
|
58
|
+
}
|
|
59
|
+
const code = typeof result.code === 'number' ? result.code : -1
|
|
60
|
+
const transportFailed = typeof result.transportError === 'string' && result.transportError.length > 0
|
|
61
|
+
if (typeof result.signal === 'string' && result.signal.length > 0) {
|
|
62
|
+
parts.push(`[killed by signal: ${result.signal}]`)
|
|
63
|
+
} else if (!transportFailed && code !== 0) {
|
|
64
|
+
parts.push(`[exit code: ${code}]`)
|
|
65
|
+
}
|
|
66
|
+
return { text: parts.filter((part) => part.length > 0).join('\n').trimEnd(), exitCode: code }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Render an in-flight job read for a promoted foreground call, matching the
|
|
71
|
+
* official bash prompt: output so far, a lossy notice, then the job pointer.
|
|
72
|
+
*
|
|
73
|
+
* @param {{ chunks?: Array<{ text?: string, channel?: string }>, lossy?: boolean }} read
|
|
74
|
+
* @param {string} jobId
|
|
75
|
+
* @param {number} timeoutMs
|
|
76
|
+
* @returns {{ text: string, exitCode: null, jobId: string }}
|
|
77
|
+
*/
|
|
78
|
+
export function renderPromoted(read, jobId, timeoutMs) {
|
|
79
|
+
const chunks = Array.isArray(read?.chunks) ? read.chunks : []
|
|
80
|
+
let stdout = ''
|
|
81
|
+
let stderr = ''
|
|
82
|
+
for (const chunk of chunks) {
|
|
83
|
+
const value = typeof chunk?.text === 'string' ? chunk.text : ''
|
|
84
|
+
if (chunk?.channel === 'stderr') stderr += value
|
|
85
|
+
else stdout += value
|
|
86
|
+
}
|
|
87
|
+
const parts = []
|
|
88
|
+
if (stdout.length > 0) parts.push(stdout)
|
|
89
|
+
if (stderr.trim().length > 0) parts.push(`[stderr]\n${stderr}`)
|
|
90
|
+
if (read?.lossy === true) parts.push('[some output was dropped from memory; continue with job_output]')
|
|
91
|
+
parts.push(`[still running after ${timeoutMs}ms; moved to background job ${jobId}; use job_output to read output, job_kill to stop]`)
|
|
92
|
+
return { text: parts.filter((part) => part.length > 0).join('\n').trimEnd(), exitCode: null, jobId }
|
|
93
|
+
}
|