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.
Files changed (118) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +227 -2
  3. package/README.zh-CN.md +201 -0
  4. package/client.js +8645 -0
  5. package/cordis.patch.yml +6 -0
  6. package/icon.svg +19 -0
  7. package/index.js +701 -0
  8. package/lib/api.js +1452 -0
  9. package/lib/bash-result.js +93 -0
  10. package/lib/connection.js +1133 -0
  11. package/lib/delete.js +199 -0
  12. package/lib/drafts.js +299 -0
  13. package/lib/encoding.js +247 -0
  14. package/lib/file-edit.js +339 -0
  15. package/lib/file-ops.js +402 -0
  16. package/lib/forwards.js +186 -0
  17. package/lib/fs-actions.js +235 -0
  18. package/lib/guide.js +162 -0
  19. package/lib/metrics.js +523 -0
  20. package/lib/remote-shells.js +320 -0
  21. package/lib/remote-terminal.js +427 -0
  22. package/lib/routing.js +695 -0
  23. package/lib/ssh-config.js +118 -0
  24. package/lib/terminal.js +123 -0
  25. package/lib/tool-forward.js +185 -0
  26. package/lib/transfer.js +235 -0
  27. package/lib/upload-chunks.js +306 -0
  28. package/lib/util.js +154 -0
  29. package/locale/README.md +160 -0
  30. package/locale/en-ui.json +477 -0
  31. package/locale/en.json +6 -0
  32. package/locale/zh.json +6 -0
  33. package/package.json +63 -4
  34. package/vendor/codemirror/LICENSE +21 -0
  35. package/vendor/codemirror/README.md +18 -0
  36. package/vendor/codemirror/addon/edit/closebrackets.min.js +8 -0
  37. package/vendor/codemirror/addon/edit/matchbrackets.min.js +8 -0
  38. package/vendor/codemirror/addon/search/search.min.js +8 -0
  39. package/vendor/codemirror/addon/search/searchcursor.min.js +8 -0
  40. package/vendor/codemirror/addon/selection/active-line.min.js +8 -0
  41. package/vendor/codemirror/lib/codemirror.css +344 -0
  42. package/vendor/codemirror/lib/codemirror.min.js +8 -0
  43. package/vendor/codemirror/mode/clike/clike.min.js +8 -0
  44. package/vendor/codemirror/mode/css/css.min.js +8 -0
  45. package/vendor/codemirror/mode/go/go.min.js +8 -0
  46. package/vendor/codemirror/mode/htmlmixed/htmlmixed.min.js +8 -0
  47. package/vendor/codemirror/mode/javascript/javascript.min.js +8 -0
  48. package/vendor/codemirror/mode/markdown/markdown.min.js +8 -0
  49. package/vendor/codemirror/mode/python/python.min.js +8 -0
  50. package/vendor/codemirror/mode/rust/rust.min.js +8 -0
  51. package/vendor/codemirror/mode/shell/shell.min.js +8 -0
  52. package/vendor/codemirror/mode/xml/xml.min.js +8 -0
  53. package/vendor/codemirror/mode/yaml/yaml.min.js +8 -0
  54. package/vendor/node_modules/asn1/Jenkinsfile +65 -0
  55. package/vendor/node_modules/asn1/LICENSE +19 -0
  56. package/vendor/node_modules/asn1/README.md +50 -0
  57. package/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
  58. package/vendor/node_modules/asn1/lib/ber/index.js +27 -0
  59. package/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
  60. package/vendor/node_modules/asn1/lib/ber/types.js +36 -0
  61. package/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
  62. package/vendor/node_modules/asn1/lib/index.js +20 -0
  63. package/vendor/node_modules/asn1/package.json +31 -0
  64. package/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
  65. package/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
  66. package/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
  67. package/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
  68. package/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
  69. package/vendor/node_modules/safer-buffer/LICENSE +21 -0
  70. package/vendor/node_modules/safer-buffer/Porting-Buffer.md +268 -0
  71. package/vendor/node_modules/safer-buffer/Readme.md +156 -0
  72. package/vendor/node_modules/safer-buffer/dangerous.js +58 -0
  73. package/vendor/node_modules/safer-buffer/package.json +34 -0
  74. package/vendor/node_modules/safer-buffer/safer.js +77 -0
  75. package/vendor/node_modules/safer-buffer/tests.js +406 -0
  76. package/vendor/node_modules/ssh2/LICENSE +19 -0
  77. package/vendor/node_modules/ssh2/README.md +1529 -0
  78. package/vendor/node_modules/ssh2/SFTP.md +413 -0
  79. package/vendor/node_modules/ssh2/lib/Channel.js +295 -0
  80. package/vendor/node_modules/ssh2/lib/agent.js +1123 -0
  81. package/vendor/node_modules/ssh2/lib/client.js +2176 -0
  82. package/vendor/node_modules/ssh2/lib/http-agents.js +84 -0
  83. package/vendor/node_modules/ssh2/lib/index.js +44 -0
  84. package/vendor/node_modules/ssh2/lib/keygen.js +582 -0
  85. package/vendor/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
  86. package/vendor/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
  87. package/vendor/node_modules/ssh2/lib/protocol/constants.js +356 -0
  88. package/vendor/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
  89. package/vendor/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
  90. package/vendor/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
  91. package/vendor/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
  92. package/vendor/node_modules/ssh2/lib/protocol/handlers.js +16 -0
  93. package/vendor/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
  94. package/vendor/node_modules/ssh2/lib/protocol/kex.js +1908 -0
  95. package/vendor/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
  96. package/vendor/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
  97. package/vendor/node_modules/ssh2/lib/protocol/utils.js +356 -0
  98. package/vendor/node_modules/ssh2/lib/protocol/zlib.js +255 -0
  99. package/vendor/node_modules/ssh2/lib/server.js +1380 -0
  100. package/vendor/node_modules/ssh2/lib/utils.js +336 -0
  101. package/vendor/node_modules/ssh2/package.json +49 -0
  102. package/vendor/node_modules/tweetnacl/AUTHORS.md +28 -0
  103. package/vendor/node_modules/tweetnacl/CHANGELOG.md +221 -0
  104. package/vendor/node_modules/tweetnacl/LICENSE +24 -0
  105. package/vendor/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
  106. package/vendor/node_modules/tweetnacl/README.md +459 -0
  107. package/vendor/node_modules/tweetnacl/nacl-fast.js +2388 -0
  108. package/vendor/node_modules/tweetnacl/nacl-fast.min.js +2 -0
  109. package/vendor/node_modules/tweetnacl/nacl.d.ts +98 -0
  110. package/vendor/node_modules/tweetnacl/nacl.js +1175 -0
  111. package/vendor/node_modules/tweetnacl/nacl.min.js +1 -0
  112. package/vendor/node_modules/tweetnacl/package.json +58 -0
  113. package/vendor/xterm/LICENSE.addon-fit +19 -0
  114. package/vendor/xterm/LICENSE.xterm +21 -0
  115. package/vendor/xterm/README.md +9 -0
  116. package/vendor/xterm/addon-fit.js +2 -0
  117. package/vendor/xterm/xterm.css +218 -0
  118. 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
+ }