dsh-remote-go 0.2.0 → 0.3.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 (134) hide show
  1. package/README.md +11 -3
  2. package/{client.js → dist/client.js} +7710 -8182
  3. package/dist/index.js +4 -0
  4. package/dist/src/admission.js +46 -0
  5. package/dist/src/api.js +442 -0
  6. package/dist/src/atomic-json.js +235 -0
  7. package/dist/src/bootstrap.js +106 -0
  8. package/dist/src/connect/attach.js +43 -0
  9. package/dist/src/connect/bootstrap.js +14 -0
  10. package/dist/src/connect/failures.js +44 -0
  11. package/dist/src/connect/guards.js +31 -0
  12. package/dist/src/connect/launch.js +80 -0
  13. package/dist/src/connect/links.js +70 -0
  14. package/dist/src/connect/ownership.js +220 -0
  15. package/dist/src/connect/pipeline.js +473 -0
  16. package/dist/src/connect/reattach.js +215 -0
  17. package/dist/src/connect/registry.js +11 -0
  18. package/dist/src/connect/repair.js +126 -0
  19. package/dist/src/connect/restart.js +316 -0
  20. package/dist/src/connect/stop.js +198 -0
  21. package/dist/src/connect/transport.js +109 -0
  22. package/dist/src/connect/verify.js +39 -0
  23. package/dist/src/connect/watchdog.js +76 -0
  24. package/dist/src/connect-log.js +162 -0
  25. package/dist/src/connect-progress.js +142 -0
  26. package/{src → dist/src}/constants.js +30 -56
  27. package/dist/src/context.js +117 -0
  28. package/dist/src/diagnostics.js +102 -0
  29. package/dist/src/download-jobs.js +230 -0
  30. package/dist/src/errors.js +243 -0
  31. package/dist/src/events.js +390 -0
  32. package/dist/src/host-lifecycle.js +504 -0
  33. package/dist/src/host-registry.js +232 -0
  34. package/dist/src/host-runtime.js +86 -0
  35. package/dist/src/host-view.js +75 -0
  36. package/dist/src/index.js +216 -0
  37. package/dist/src/kernel-adapter.js +434 -0
  38. package/dist/src/key-files.js +52 -0
  39. package/dist/src/known-hosts.js +125 -0
  40. package/dist/src/layout.js +43 -0
  41. package/dist/src/local-download.js +380 -0
  42. package/dist/src/local-ssh.js +30 -0
  43. package/dist/src/local-version.js +101 -0
  44. package/dist/src/node/download.js +160 -0
  45. package/dist/src/node-runtime.js +346 -0
  46. package/dist/src/probe.js +96 -0
  47. package/dist/src/prompts.js +270 -0
  48. package/dist/src/proxy/cookies.js +136 -0
  49. package/dist/src/proxy/headers.js +262 -0
  50. package/dist/src/proxy/http.js +142 -0
  51. package/dist/src/proxy/index.js +135 -0
  52. package/dist/src/proxy/limits.js +8 -0
  53. package/dist/src/proxy/routes.js +39 -0
  54. package/dist/src/proxy/upgrade.js +175 -0
  55. package/dist/src/redact.js +104 -0
  56. package/dist/src/remote-files.js +72 -0
  57. package/dist/src/remote-path.js +123 -0
  58. package/dist/src/remote-proc.js +339 -0
  59. package/dist/src/remote-web/registry.js +147 -0
  60. package/dist/src/remote-web/resolve.js +310 -0
  61. package/dist/src/remote-web/start.js +227 -0
  62. package/dist/src/remote-web/stop.js +93 -0
  63. package/dist/src/request-trust.js +87 -0
  64. package/dist/src/runtime/dispatch.js +310 -0
  65. package/dist/src/runtime/effects.js +91 -0
  66. package/dist/src/runtime/events.js +35 -0
  67. package/dist/src/runtime/fsm.js +120 -0
  68. package/dist/src/runtime/rules.js +565 -0
  69. package/dist/src/secrets.js +142 -0
  70. package/dist/src/service.js +406 -0
  71. package/dist/src/settings.js +144 -0
  72. package/dist/src/ssh-config.js +276 -0
  73. package/dist/src/ssh-failures.js +122 -0
  74. package/dist/src/ssh-port.js +4 -0
  75. package/dist/src/ssh-sftp.js +297 -0
  76. package/dist/src/ssh.js +477 -0
  77. package/dist/src/store.js +191 -0
  78. package/dist/src/tool-shared.js +181 -0
  79. package/dist/src/tools-exec-policy.js +167 -0
  80. package/dist/src/tools-exec.js +371 -0
  81. package/dist/src/tools-report.js +424 -0
  82. package/dist/src/tools.js +411 -0
  83. package/dist/src/tunnel.js +129 -0
  84. package/dist/src/util.js +149 -0
  85. package/dist/src/version.js +114 -0
  86. package/dist/src/watchdog-bus.js +29 -0
  87. package/dist/src/watchdog.js +156 -0
  88. package/index.js +5 -4
  89. package/locale/en.json +1 -1
  90. package/locale/zh.json +1 -1
  91. package/package.json +37 -19
  92. package/src/admission.js +0 -43
  93. package/src/api.js +0 -536
  94. package/src/atomic-json.js +0 -225
  95. package/src/bootstrap.js +0 -113
  96. package/src/connect-log.js +0 -176
  97. package/src/connect-pipeline.js +0 -1900
  98. package/src/connect-progress.js +0 -155
  99. package/src/diagnostics.js +0 -160
  100. package/src/download-jobs.js +0 -234
  101. package/src/errors.js +0 -412
  102. package/src/host-lifecycle.js +0 -604
  103. package/src/host-registry.js +0 -217
  104. package/src/host-runtime.js +0 -127
  105. package/src/host-view.js +0 -75
  106. package/src/index.js +0 -206
  107. package/src/key-files.js +0 -54
  108. package/src/known-hosts.js +0 -133
  109. package/src/layout.js +0 -53
  110. package/src/local-download.js +0 -381
  111. package/src/local-ssh.js +0 -27
  112. package/src/local-version.js +0 -88
  113. package/src/node-runtime.js +0 -521
  114. package/src/probe.js +0 -101
  115. package/src/prompts.js +0 -229
  116. package/src/redact.js +0 -68
  117. package/src/remote-files.js +0 -71
  118. package/src/remote-path.js +0 -137
  119. package/src/remote-proc.js +0 -343
  120. package/src/remote-proxy.js +0 -815
  121. package/src/remote-web.js +0 -751
  122. package/src/request-trust.js +0 -89
  123. package/src/secrets.js +0 -109
  124. package/src/service.js +0 -459
  125. package/src/settings.js +0 -163
  126. package/src/ssh-config.js +0 -271
  127. package/src/ssh.js +0 -731
  128. package/src/store.js +0 -193
  129. package/src/tools.js +0 -386
  130. package/src/tunnel.js +0 -132
  131. package/src/util.js +0 -153
  132. package/src/version.js +0 -103
  133. package/src/webapp.js +0 -43
  134. /package/{vendor → dist/vendor}/ssh2.bundle.cjs +0 -0
package/src/settings.js DELETED
@@ -1,163 +0,0 @@
1
- /**
2
- * Plugin settings: defaults, validation and sanitization; unknown or invalid fields fall back to defaults instead of failing activation.
3
- */
4
- import {
5
- DEFAULT_IDLE_MINUTES,
6
- DEFAULT_KEY_PATH,
7
- DEFAULT_REMOTE_PROFILE,
8
- REMOTE_HEARTBEAT_DEFAULT_SEC,
9
- REMOTE_HEARTBEAT_MAX_SEC,
10
- REMOTE_HEARTBEAT_MIN_SEC,
11
- SSH_READY_TIMEOUT_MS,
12
- } from './constants.js'
13
- import { clamp, deepMerge, isPlainObject, parseSshDestination } from './util.js'
14
-
15
- export function defaultSettings() {
16
- return {
17
- defaultPort: 22,
18
- // Only a key file (or a one-time password) is supported: there is no SSH
19
- // agent path any more, so the default is the key file the wizard pre-fills.
20
- defaultAuth: 'key',
21
- defaultKeyPath: DEFAULT_KEY_PATH,
22
- connectTimeoutSec: Math.round(SSH_READY_TIMEOUT_MS / 1000),
23
- autoReconnect: { enabled: true, maxAttempts: 5, baseDelayMs: 800 },
24
- /**
25
- * Light liveness probe of a connected host's remote UI. Two consecutive
26
- * failures re-read the remote and re-attach; one failed request never does.
27
- */
28
- remoteHeartbeat: { enabled: true, intervalSec: REMOTE_HEARTBEAT_DEFAULT_SEC },
29
- hostKeyPolicy: 'first-use',
30
- saveTokens: false,
31
- language: 'auto',
32
- logLevel: 'info',
33
- bootstrap: {
34
- profile: DEFAULT_REMOTE_PROFILE,
35
- },
36
- }
37
- }
38
-
39
- /**
40
- * A profile name DSH can boot: one safe path segment, and never `desktop`
41
- * (the Electron app reserves that profile and the CLI refuses it).
42
- */
43
- function normalizeProfileName(value) {
44
- const text = typeof value === 'string' ? value.trim() : ''
45
- if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(text)) return null
46
- if (text.toLowerCase() === 'desktop') return null
47
- return text
48
- }
49
-
50
- function oneOf(value, allowed, fallback) {
51
- return allowed.includes(value) ? value : fallback
52
- }
53
-
54
- function numberIn(value, min, max, fallback) {
55
- const num = typeof value === 'number' ? value : Number(value)
56
- if (!Number.isFinite(num)) return fallback
57
- return clamp(Math.round(num), min, max)
58
- }
59
-
60
- function boolean(value, fallback) {
61
- return typeof value === 'boolean' ? value : fallback
62
- }
63
-
64
- export function sanitizeSettings(raw) {
65
- const defaults = defaultSettings()
66
- if (!isPlainObject(raw)) return defaults
67
- const input = deepMerge(defaults, raw)
68
- const autoReconnect = isPlainObject(input.autoReconnect) ? input.autoReconnect : defaults.autoReconnect
69
- const remoteHeartbeat = isPlainObject(input.remoteHeartbeat) ? input.remoteHeartbeat : defaults.remoteHeartbeat
70
- const bootstrap = isPlainObject(input.bootstrap) ? input.bootstrap : defaults.bootstrap
71
- const profile = normalizeProfileName(bootstrap.profile) ?? defaults.bootstrap.profile
72
- return {
73
- defaultPort: numberIn(input.defaultPort, 1, 65535, defaults.defaultPort),
74
- // The retired "agent" choice migrates to key-file auth instead of silently
75
- // resetting, because key files are the only non-interactive option left.
76
- defaultAuth:
77
- input.defaultAuth === 'agent' ? 'key' : oneOf(input.defaultAuth, ['key', 'password'], defaults.defaultAuth),
78
- defaultKeyPath:
79
- typeof input.defaultKeyPath === 'string' && input.defaultKeyPath.trim() !== ''
80
- ? input.defaultKeyPath.trim()
81
- : defaults.defaultKeyPath,
82
- connectTimeoutSec: numberIn(input.connectTimeoutSec, 5, 300, defaults.connectTimeoutSec),
83
- autoReconnect: {
84
- enabled: boolean(autoReconnect.enabled, defaults.autoReconnect.enabled),
85
- maxAttempts: numberIn(autoReconnect.maxAttempts, 0, 20, defaults.autoReconnect.maxAttempts),
86
- baseDelayMs: numberIn(autoReconnect.baseDelayMs, 100, 30_000, defaults.autoReconnect.baseDelayMs),
87
- },
88
- remoteHeartbeat: {
89
- enabled: boolean(remoteHeartbeat.enabled, defaults.remoteHeartbeat.enabled),
90
- intervalSec: numberIn(
91
- remoteHeartbeat.intervalSec,
92
- REMOTE_HEARTBEAT_MIN_SEC,
93
- REMOTE_HEARTBEAT_MAX_SEC,
94
- defaults.remoteHeartbeat.intervalSec,
95
- ),
96
- },
97
- hostKeyPolicy: oneOf(input.hostKeyPolicy, ['first-use', 'strict'], defaults.hostKeyPolicy),
98
- saveTokens: boolean(input.saveTokens, defaults.saveTokens),
99
- language: oneOf(input.language, ['auto', 'zh', 'en'], defaults.language),
100
- logLevel: oneOf(input.logLevel, ['error', 'warn', 'info', 'debug'], defaults.logLevel),
101
- bootstrap: {
102
- profile,
103
- },
104
- }
105
- }
106
-
107
- /** The only id shape this plugin issues: `randomId('h')` (docs/api.md `HostView.id`). */
108
- export const HOST_ID_RE = /^h_[a-z0-9]{1,32}$/
109
-
110
- export function sanitizeHostEntry(raw, options = {}) {
111
- const settings = options.settings ?? defaultSettings()
112
- const existing = options.existing ?? null
113
- if (!isPlainObject(raw)) throw new Error('host entry must be an object')
114
- const name = typeof raw.name === 'string' && raw.name.trim() !== '' ? raw.name.trim().slice(0, 120) : ''
115
- const address = typeof raw.address === 'string' ? raw.address.trim() : ''
116
- if (address === '') throw new Error('address is required')
117
- const destination = parseSshDestination(address)
118
- if (!destination.host) throw new Error('address is invalid')
119
- const userInput = typeof raw.username === 'string' ? raw.username.trim() : ''
120
- const username = userInput || existing?.username || destination.user || ''
121
- const authType =
122
- raw.auth && isPlainObject(raw.auth)
123
- ? raw.auth.type === 'agent'
124
- ? 'key'
125
- : oneOf(raw.auth.type, ['key', 'password'], settings.defaultAuth)
126
- : (existing?.auth?.type ?? settings.defaultAuth)
127
- const keyPathInput =
128
- raw.auth && isPlainObject(raw.auth) && typeof raw.auth.keyPath === 'string' ? raw.auth.keyPath.trim() : ''
129
- const keyPath = keyPathInput || existing?.auth?.keyPath || (authType === 'key' ? settings.defaultKeyPath : '')
130
- const keepAlive = oneOf(raw.keepAlive, ['keep', 'stop', 'idle'], existing?.keepAlive ?? 'keep')
131
- const hostKeyPolicy = oneOf(
132
- raw.hostKeyPolicy,
133
- ['first-use', 'strict'],
134
- existing?.hostKeyPolicy ?? settings.hostKeyPolicy,
135
- )
136
- return {
137
- // A malformed or over-long id is never echoed: an id names the secrets entry, the proxy
138
- // route and the client's host link, so only the shape this plugin issues is accepted.
139
- id: typeof raw.id === 'string' && HOST_ID_RE.test(raw.id) ? raw.id : (existing?.id ?? undefined),
140
- name: name || destination.host || destination.alias || 'remote',
141
- address,
142
- port: numberIn(raw.port ?? destination.port ?? existing?.port, 1, 65535, settings.defaultPort),
143
- username: username || null,
144
- auth: { type: authType, ...(keyPath ? { keyPath } : {}) },
145
- jumpHost:
146
- typeof raw.jumpHost === 'string'
147
- ? raw.jumpHost.trim() !== ''
148
- ? raw.jumpHost.trim()
149
- : null
150
- : (existing?.jumpHost ?? null),
151
- keepAlive,
152
- idleMinutes: numberIn(raw.idleMinutes ?? existing?.idleMinutes, 1, 24 * 60, DEFAULT_IDLE_MINUTES),
153
- autoReconnect: boolean(raw.autoReconnect, existing?.autoReconnect ?? settings.autoReconnect.enabled),
154
- hostKeyPolicy,
155
- pinnedFingerprint:
156
- typeof raw.pinnedFingerprint === 'string' && raw.pinnedFingerprint.startsWith('SHA256:')
157
- ? raw.pinnedFingerprint
158
- : (existing?.pinnedFingerprint ?? null),
159
- createdAt: existing?.createdAt ?? new Date().toISOString(),
160
- updatedAt: new Date().toISOString(),
161
- lastOpenedAt: existing?.lastOpenedAt ?? null,
162
- }
163
- }
package/src/ssh-config.js DELETED
@@ -1,271 +0,0 @@
1
- /**
2
- * Read-only `~/.ssh/config` parsing and alias discovery for the subset `ssh_config(5)` defines; `Include`, `Match` and `ProxyCommand` are reported, not guessed.
3
- */
4
-
5
- const KNOWN_OPTIONS = new Set([
6
- 'hostname',
7
- 'user',
8
- 'port',
9
- 'identityfile',
10
- 'certificatefile',
11
- 'proxyjump',
12
- 'proxycommand',
13
- 'serveraliveinterval',
14
- 'serveralivecountmax',
15
- 'connecttimeout',
16
- 'identitiesonly',
17
- 'preferredauthentications',
18
- ])
19
-
20
- function parseLine(line) {
21
- const trimmed = line.trim()
22
- if (trimmed === '' || trimmed.startsWith('#')) return null
23
- const eq = trimmed.indexOf('=')
24
- const space = trimmed.search(/\s/)
25
- let keyword
26
- let value
27
- if (eq >= 0 && (space < 0 || eq < space)) {
28
- keyword = trimmed.slice(0, eq)
29
- value = trimmed.slice(eq + 1)
30
- } else if (space >= 0) {
31
- keyword = trimmed.slice(0, space)
32
- value = trimmed.slice(space + 1)
33
- } else {
34
- keyword = trimmed
35
- value = ''
36
- }
37
- value = value.trim()
38
- if (
39
- (value.startsWith('"') && value.endsWith('"') && value.length >= 2) ||
40
- (value.startsWith("'") && value.endsWith("'") && value.length >= 2)
41
- ) {
42
- value = value.slice(1, -1)
43
- }
44
- return { keyword: keyword.trim(), value }
45
- }
46
-
47
- function splitPatterns(value) {
48
- const patterns = []
49
- const negated = []
50
- for (const token of value.split(/\s+/)) {
51
- if (token === '') continue
52
- if (token.startsWith('!')) negated.push(token.slice(1))
53
- else patterns.push(token)
54
- }
55
- return { patterns, negated }
56
- }
57
-
58
- export function parseSshConfig(text) {
59
- const entries = []
60
- const globals = {}
61
- const unsupported = []
62
- const malformed = []
63
- let current = null
64
-
65
- const lines = String(text ?? '').split(/\r?\n/)
66
- for (let index = 0; index < lines.length; index += 1) {
67
- const lineNo = index + 1
68
- const parsed = parseLine(lines[index])
69
- if (!parsed) continue
70
- const keyword = parsed.keyword.toLowerCase()
71
- if (keyword === 'host') {
72
- const { patterns, negated } = splitPatterns(parsed.value)
73
- current = { patterns, negated, options: {}, line: lineNo }
74
- if (patterns.length === 0) malformed.push({ line: lineNo, text: lines[index] })
75
- else entries.push(current)
76
- continue
77
- }
78
- if (keyword === 'match') {
79
- unsupported.push({ line: lineNo, keyword: 'Match' })
80
- // Options inside a Match block only apply under conditions we cannot
81
- // evaluate; skip them until the next Host block.
82
- current = { patterns: ['__dsh_remote_go_match_block__'], negated: [], options: {}, line: lineNo }
83
- entries.push(current)
84
- continue
85
- }
86
- if (keyword === 'include') {
87
- unsupported.push({ line: lineNo, keyword: 'Include' })
88
- continue
89
- }
90
- if (!KNOWN_OPTIONS.has(keyword)) {
91
- // Unknown-but-harmless options are ignored; only flag keywords that would
92
- // change meaning if misread.
93
- if (keyword === 'proxycommand' || keyword === 'certificatefile')
94
- unsupported.push({ line: lineNo, keyword: parsed.keyword })
95
- continue
96
- }
97
- if (parsed.value === '') {
98
- malformed.push({ line: lineNo, text: lines[index] })
99
- continue
100
- }
101
- if (current) {
102
- current.options[keyword] = current.options[keyword] ?? []
103
- current.options[keyword].push(parsed.value)
104
- } else {
105
- globals[keyword] = globals[keyword] ?? []
106
- globals[keyword].push(parsed.value)
107
- }
108
- }
109
- return { entries, globals, unsupported, malformed }
110
- }
111
-
112
- export function matchHostPattern(pattern, value) {
113
- if (pattern === '*') return true
114
- const escaped = pattern
115
- .replace(/[.+^${}()|[\]\\]/g, '\\$&')
116
- .replace(/\*/g, '.*')
117
- .replace(/\?/g, '.')
118
- return new RegExp(`^${escaped}$`, 'i').test(value)
119
- }
120
-
121
- export function entryMatches(entry, alias) {
122
- if (entry.patterns.includes('__dsh_remote_go_match_block__')) return false
123
- const positive = entry.patterns.some((pattern) => matchHostPattern(pattern, alias))
124
- if (!positive) return false
125
- return !entry.negated.some((pattern) => matchHostPattern(pattern, alias))
126
- }
127
-
128
- const ADDITIVE_OPTIONS = new Set(['identityfile', 'certificatefile'])
129
-
130
- function effectiveOptions(globals, entries, alias, tokens) {
131
- const out = {}
132
- const apply = (/** @type {Record<string, string[]>} */ options) => {
133
- for (const [key, values] of Object.entries(options)) {
134
- const expanded = values.map((value) => expandTokens(value, tokens))
135
- if (ADDITIVE_OPTIONS.has(key)) {
136
- out[key] = [...(out[key] ?? []), ...expanded]
137
- continue
138
- }
139
- if (out[key] !== undefined) continue
140
- out[key] = expanded
141
- }
142
- }
143
- apply(globals)
144
- for (const entry of entries) {
145
- if (entryMatches(entry, alias)) apply(entry.options)
146
- }
147
- return out
148
- }
149
-
150
- export function expandTokens(value, tokens) {
151
- return String(value).replace(/%([hprd%])/g, (match, token) => {
152
- if (token === '%') return '%'
153
- return tokens[token] ?? match
154
- })
155
- }
156
-
157
- function expandTilde(value, home) {
158
- if (value === '~') return home
159
- if (value.startsWith('~/')) return `${home.replace(/[\\/]+$/, '')}/${value.slice(2)}`
160
- return value
161
- }
162
-
163
- export function resolveSshAlias(parsed, alias, options = {}) {
164
- const home = options.home ?? '~'
165
- const baseTokens = { h: alias, r: '~', p: '22', d: home }
166
- const firstPass = effectiveOptions(parsed.globals, parsed.entries, alias, baseTokens)
167
- const host = firstPass.hostname?.[0] ?? alias
168
- const user = firstPass.user?.[0] ?? null
169
- const rawPort = firstPass.port?.[0] ?? '22'
170
- const port = /^\d+$/.test(rawPort) ? Number(rawPort) : 22
171
- const tokens = { h: host, r: user ?? '~', p: String(port), d: home }
172
- const resolved = effectiveOptions(parsed.globals, parsed.entries, alias, tokens)
173
- const identityFiles = (resolved.identityfile ?? []).map((value) => expandTilde(value, home))
174
- const proxyJump = resolved.proxyjump?.[0] ?? null
175
- return {
176
- alias,
177
- host,
178
- user,
179
- port,
180
- identityFiles,
181
- proxyJump,
182
- source: 'config',
183
- }
184
- }
185
-
186
- /**
187
- * List concrete, manually-dialable aliases from the config. Wildcard patterns
188
- * (`*`, `?`) and negations are skipped because they cannot be resolved without
189
- * a concrete target.
190
- */
191
- export function discoverSshAliases(parsed, options = {}) {
192
- const out = []
193
- const seen = new Set()
194
- for (const entry of parsed.entries) {
195
- for (const pattern of entry.patterns) {
196
- if (pattern.includes('*') || pattern.includes('?') || pattern.startsWith('__dsh_remote_go_')) continue
197
- if (seen.has(pattern)) continue
198
- seen.add(pattern)
199
- const resolved = resolveSshAlias(parsed, pattern, options)
200
- out.push({ alias: pattern, host: resolved.host, user: resolved.user, port: resolved.port, source: 'config' })
201
- }
202
- }
203
- return out
204
- }
205
-
206
- export function resolveDestination(destination, options = {}) {
207
- const text = String(destination ?? '').trim()
208
- const literal = parseDestinationLiteral(text)
209
- const parsed = parseSshConfig(options.configText ?? '')
210
- const home = options.home ?? '~'
211
- const aliases = discoverSshAliases(parsed, { home })
212
- const alias = aliases.find((item) => item.alias === text)
213
- if (alias) {
214
- const resolved = resolveSshAlias(parsed, text, { home })
215
- return {
216
- input: text,
217
- alias: text,
218
- host: resolved.host,
219
- user: literal.user ?? resolved.user,
220
- port: literal.port ?? resolved.port,
221
- identityFiles: resolved.identityFiles,
222
- proxyJump: resolved.proxyJump,
223
- source: 'config',
224
- }
225
- }
226
- // Literal destination: inherit globals (e.g. a global IdentityFile) but not
227
- // Host blocks that do not match the literal text.
228
- const tokens = { h: literal.host, r: literal.user ?? '~', p: String(literal.port ?? 22), d: home }
229
- const globals = effectiveOptions(parsed.globals, [], text, tokens)
230
- const identityFiles = (globals.identityfile ?? []).map((value) => expandTilde(value, home))
231
- return {
232
- input: text,
233
- alias: null,
234
- host: literal.host,
235
- user: literal.user,
236
- port: literal.port ?? 22,
237
- identityFiles,
238
- proxyJump: globals.proxyjump?.[0] ?? null,
239
- source: 'manual',
240
- }
241
- }
242
-
243
- function parseDestinationLiteral(text) {
244
- let user = null
245
- let rest = text
246
- const at = rest.lastIndexOf('@')
247
- if (at >= 0) {
248
- user = rest.slice(0, at)
249
- rest = rest.slice(at + 1)
250
- }
251
- let host = rest
252
- let port = null
253
- if (rest.startsWith('[')) {
254
- const close = rest.indexOf(']')
255
- if (close > 0) {
256
- host = rest.slice(1, close)
257
- const tail = rest.slice(close + 1)
258
- if (/^:\d+$/.test(tail)) port = Number(tail.slice(1))
259
- }
260
- } else {
261
- const colon = rest.lastIndexOf(':')
262
- if (colon > 0 && rest.indexOf(':') === colon) {
263
- const maybePort = rest.slice(colon + 1)
264
- if (/^\d{1,5}$/.test(maybePort)) {
265
- host = rest.slice(0, colon)
266
- port = Number(maybePort)
267
- }
268
- }
269
- }
270
- return { user: user || null, host, port }
271
- }