Files
orca/src/main/ssh/vscode-ssh-authority.ts
T
Jinjing adc020393e feat(ssh): open SSH workspaces in VS Code Remote-SSH (#10005)
Allow the existing "Open in" entries to launch a configured VS Code
launcher against an SSH-backed worktree via Remote-SSH:

    code --remote ssh-remote+<authority> <remote-path>

- Split the blanket SSH/runtime block into a capability model: file
  managers and non-VS Code launchers stay local-only (disabled with
  "Local only" metadata); a recognized VS Code command is enabled and
  forwarded with connectionId over a typed object IPC.
- Main process stays authoritative: rejects active/owned runtimes,
  resolves the SshTarget from the persisted Store, derives the authority
  (config alias, or username@host on port 22, or ssh-alias-required on a
  non-default port), validates POSIX/Windows absolute remote paths without
  local stat/normalize, and rejects non-VS Code and compound commands
  before spawn.
- Authority and remote path are passed as separate argv; getSpawnArgsForWindows
  remains the cmd/bat shim boundary and fails closed on metacharacters.
- Same capability rules across the worktree menu, Explorer overflow, and
  the source-control entry context menu.

Refs STA-2386
Closes #9999
2026-07-22 17:17:59 -07:00

43 lines
1.4 KiB
TypeScript

import type { SshTarget } from '../../shared/ssh-types'
import { isOpenSshConfigBackedTarget } from './system-ssh-args'
export type VsCodeSshAuthorityResult =
| { ok: true; authority: string }
| { ok: false; reason: 'ssh-target-invalid' }
| { ok: false; reason: 'ssh-alias-required'; host: string; port: number }
function isValidAuthorityPart(value: string): boolean {
return (
value.length > 0 &&
!Array.from(value).some((character) => {
const codePoint = character.codePointAt(0) ?? 0
return codePoint <= 0x1f || codePoint === 0x7f
})
)
}
export function resolveVsCodeSshAuthority(target: SshTarget): VsCodeSshAuthorityResult {
if (isOpenSshConfigBackedTarget(target)) {
const configHost = target.configHost?.trim() ?? ''
return isValidAuthorityPart(configHost)
? { ok: true, authority: configHost }
: { ok: false, reason: 'ssh-target-invalid' }
}
const host = target.host.trim()
const username = target.username.trim()
if (
!isValidAuthorityPart(host) ||
!isValidAuthorityPart(username) ||
!Number.isInteger(target.port) ||
target.port < 1 ||
target.port > 65_535
) {
return { ok: false, reason: 'ssh-target-invalid' }
}
if (target.port !== 22) {
return { ok: false, reason: 'ssh-alias-required', host, port: target.port }
}
return { ok: true, authority: `${username}@${host}` }
}