MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / SSHKaos

Class SSHKaos

packages/kaos/src/ssh.ts:435–945  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

433 * A KAOS implementation that interacts with a remote machine via SSH and SFTP.
434 */
435export class SSHKaos implements Kaos {
436 readonly name: string = 'ssh';
437
438 private _client: Client;
439 private _sftp: SFTPWrapper;
440 private _home: string;
441 private _cwd: string;
442 private readonly _envLayers: readonly Record<string, string>[];
443
444 // Stub: real wiring (probing the remote host via `uname` / `$SHELL` over the
445 // SSH transport) is deferred.
446 get osEnv(): Environment {
447 throw new KaosError(
448 'SSHKaos.osEnv is not yet wired — remote environment probing is not implemented.',
449 );
450 }
451
452 private constructor(
453 client: Client,
454 sftp: SFTPWrapper,
455 home: string,
456 cwd: string,
457 envLayers: readonly Record<string, string>[] = [],
458 ) {
459 this._client = client;
460 this._sftp = sftp;
461 this._home = home;
462 this._cwd = cwd;
463 this._envLayers = envLayers;
464 }
465
466 withCwd(cwd: string): SSHKaos {
467 return new SSHKaos(this._client, this._sftp, this._home, cwd, this._envLayers);
468 }
469
470 withEnv(env: Record<string, string>): SSHKaos {
471 return new SSHKaos(this._client, this._sftp, this._home, this._cwd, [...this._envLayers, env]);
472 }
473
474 private _resolvePath(path: string): string {
475 if (isAbsolute(path)) return path;
476 return join(this._cwd, path);
477 }
478
479 /**
480 * Factory method to create an SSHKaos instance.
481 * Establishes the SSH connection and SFTP session.
482 */
483 static async create(options: SSHKaosOptions): Promise<SSHKaos> {
484 // Start from extraOptions (advanced ssh2 options) so our managed fields
485 // below take precedence.
486 const config: ConnectConfig = {
487 ...options.extraOptions,
488 host: options.host,
489 port: options.port ?? 22,
490 username: options.username,
491 };
492

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected