sshRemoteAgentHostService.ts ×15

Frontier kind: Code frontier

unlabeled · c_e982680c3970

40 tests · 10686 LOC · 48 files · introduces 0 tests · 76 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges76 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1592 ranges10686 lines · 48 files · Browse complete extent
All tests (intent)
40 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 76 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/sshRemoteAgentHostService.ts 76 introduced LOC · 15 ranges

Open complete file

270 }
271
272 > function sshExec(client: SSHClient, command: string, opts?: { ignoreExitCode?: boolean }): Promise<{ stdout: string; stderr: string; code: number }> { sshRemoteAgentHostService.ts
273 > return new Promise<{ stdout: string; stderr: string; code: number }>((resolve, reject) => {
274 > client.exec(command, (err: Error | undefined, stream: SSHChannel) => {
275 > if (err) {
276 reject(err);
277 return;
278 }
280 > let stdout = '';
281 > let stderr = '';
282 > let settled = false;
283 >
284 > const finish = (error: Error | undefined, code: number | undefined) => {
285 > if (settled) {
286 return;
287 }
288 > settled = true; sshRemoteAgentHostService.ts
289 > if (error) {
290 reject(error);
291 return;
292 }
293 > if (code !== 0 && !opts?.ignoreExitCode) { sshRemoteAgentHostService.ts
294 reject(new Error(`SSH command failed (exit ${code}): ${command}\nstderr: ${stderr}`));
296 > resolve({ stdout, stderr, code: code ?? 0 });
297 > }
298 > };
299 >
300 > stream.on('data', (data: Buffer) => { stdout += data.toString(); });
301 > stream.stderr.on('data', (data: Buffer) => { stderr += data.toString(); });
302 > stream.on('error', (streamErr: Error) => finish(streamErr, undefined));
303 > stream.on('close', (code: number) => finish(undefined, code));
304 > });
305 > });
306 > }
307
308 /** Create a bound exec function for the given SSH client. */
309 > function bindSshExec(client: SSHClient): (command: string, opts?: { ignoreExitCode?: boolean }) => Promise<{ stdout: string; stderr: string; code: number }> { sshRemoteAgentHostService.ts
310 > return (command, opts) => sshExec(client, command, opts);
311 > }
312
313 function startRemoteAgentHost(
612
613 async connect(config: ISSHAgentHostConfig, replaceRelay?: boolean): Promise<ISSHConnectResult> {
614 > const connectionKey = config.sshConfigHost sshRemoteAgentHostService.ts
615 ? `ssh:${config.sshConfigHost}`
616 : `${config.username}@${config.host}:${config.port ?? 22}`;
618 > const existing = this._connections.get(connectionKey);
619 > if (existing) {
620 if (replaceRelay) {
621 // Tear down the old relay and create a fresh one, following
696 };
697 }
699 > this._logService.info(`${LOG_PREFIX} ${replaceRelay ? 'Reconnecting' : 'Connecting'} to ${connectionKey}`);
700 > let sshClient: SSHClient | undefined;
701 >
702 > try {
703 > const reportProgress = (message: string) => {
704 > this._onDidReportConnectProgress.fire({ connectionKey, message });
705 > };
706 >
707 > // 1. Establish SSH connection
708 > reportProgress(localize('sshProgressConnecting', "Establishing SSH connection..."));
709 > sshClient = await this._connectSSH(config, connectionKey);
710 >
711 > let cliBin: string | undefined;
712 > let cliResolved = false;
713 > // Resolve the remote CLI lazily: platform detection and CLI
714 > // install/refresh only run when we're actually about to spawn
715 > // an agent host. Reconnects that reuse a live AH via the
716 > // lockfile skip this work entirely, since the running AH was
717 > // spawned from whatever CLI was current at the time.
718 > const ensureCliResolved = async (): Promise<void> => {
719 if (cliResolved) {
720 return;
735 cliBin = await this._ensureCLIInstalled(sshClient!, platform, reportProgress);
736 };
738 > // 2. Check for an already-running agent host on the remote first.
739 > // This prevents accumulating orphaned processes when the SSH
740 > // connection drops and we reconnect — and avoids paying for
741 > // platform detection + CLI install on every reconnect.
742 > let remoteHost: string = '127.0.0.1';
743 > let remotePort: number | undefined;
744 > let connectionToken: string | undefined;
745 > let agentStream: SSHChannel | undefined;
746 >
747 > reportProgress(localize('sshProgressCheckingAgent', "Checking for existing agent host..."));
748 > const exec = bindSshExec(sshClient);
749 > const existingAH = await findRunningAgentHost(exec, this._logService, this._serverDataFolderName, this._quality);
750 > if (existingAH.kind === 'compatible') {
751 remoteHost = existingAH.host;
752 remotePort = existingAH.port;
753 connectionToken = existingAH.connectionToken;
754 }
756 > if (remotePort === undefined) {
757 // 3. Need to spawn fresh: resolve the CLI now.
758 await ensureCliResolved();
1353
1354 private get _quality(): string {
1355 > return this._productService.quality || 'insider'; sshRemoteAgentHostService.ts
1356 > }
1357
1358 private get _serverDataFolderName(): string {
1359 > return this._productService.serverDataFolderName ?? '.vscode-server-oss'; sshRemoteAgentHostService.ts
1360 > }
1361
1362 private get _commit(): string | undefined {