mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-23 16:36:23 +00:00
The SSH modules predate the stricter lint config that landed on main (curly, no-empty, perfectionist sorting, prettier). Mechanical lint:fix + fmt pass, empty catch blocks filled with the codebase's void-0 convention, and inline no-control-regex disables on the three deliberate control-char patterns (same pattern as lib/ansi.ts).
43 lines
954 B
TypeScript
43 lines
954 B
TypeScript
type SshHostState = {
|
|
sshHost: string
|
|
sshUser: string
|
|
sshPort: number | null
|
|
sshKeyPath: string
|
|
sshRemoteHermesPath: string
|
|
}
|
|
|
|
type ResolvedSshHost = {
|
|
identityFile?: string | null
|
|
port?: number | null
|
|
user?: string | null
|
|
}
|
|
|
|
function selectSshHost<T extends SshHostState>(state: T, host: string): T {
|
|
if (host === state.sshHost) {
|
|
return state
|
|
}
|
|
|
|
return {
|
|
...state,
|
|
sshHost: host,
|
|
sshUser: '',
|
|
sshPort: null,
|
|
sshKeyPath: '',
|
|
sshRemoteHermesPath: ''
|
|
}
|
|
}
|
|
|
|
function enrichSelectedSshHost<T extends SshHostState>(state: T, host: string, resolved: ResolvedSshHost): T {
|
|
if (state.sshHost !== host) {
|
|
return state
|
|
}
|
|
|
|
return {
|
|
...state,
|
|
sshUser: state.sshUser || resolved.user || '',
|
|
sshPort: state.sshPort ?? (resolved.port === 22 ? null : (resolved.port ?? null)),
|
|
sshKeyPath: state.sshKeyPath || resolved.identityFile || ''
|
|
}
|
|
}
|
|
|
|
export { enrichSelectedSshHost, selectSshHost }
|