src/vs/platform/agentHost/node/agentHostLockfile.ts

123 LOC · 121 covered · 2 uncovered · 24 ranges · 23 concepts · 18 introducers · 17 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the fileagentHostLockfile.ts ×1 · 8 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×1 · 3 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×1 · 2 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×1 · 2 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×1 · 3 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×1 · 3 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns notFound when file is corrupt|occurrence=1 · 0 introduced LOCagentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns notFound when file is missing|occurrence=1 · 0 introduced LOCagentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath keys lockfile name on quality|occurrence=1, agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath returns absolute path under home directory|occurrence=1 · 0 introduced LOCagentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath rejects unsafe quality strings|occurrence=1 · 0 introduced LOCagentHostLockfile.test|t…agentHostLockfile.ts ×1 · 6 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×1 · 2 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath rejects unsafe server data folder names|occurrence=1 · 0 introduced LOCagentHostLockfile.test|t…agentHostLockfile.ts ×1 · 2 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×1 · 3 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×1 · 4 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×2 · 4 introduced LOCagentHostLockfile.ts ×2agentHostLockfile.ts ×2 · 5 introduced LOCagentHostLockfile.ts ×2agentHostLockfile.ts ×1 · 5 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×1 · 4 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×2 · 2 introduced LOCagentHostLockfile.ts ×2agentHostLockfile.ts ×1 · 5 introduced LOCagentHostLockfile.ts ×1agentHostLockfile.ts ×4 · 58 introduced LOCagentHostLockfile.ts ×4agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath keys lockfile name on quality|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath keys lockfile name on quality|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath rejects unsafe quality strings|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath rejects unsafe quality strings|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath rejects unsafe server data folder names|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath rejects unsafe server data folder names|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath returns absolute path under home directory|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) getLocalAgentHostLockfilePath returns absolute path under home directory|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) isPidAlive returns false for a clearly nonexistent PID|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) isPidAlive returns false for a clearly nonexistent PID|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) isPidAlive returns false for invalid PIDs|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) isPidAlive returns false for invalid PIDs|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) isPidAlive returns true for the current process|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) isPidAlive returns true for the current process|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns compatible for a live PID with matching protocol|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns compatible for a live PID with matching protocol|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns compatible with undefined token when state has null token|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns compatible with undefined token when state has null token|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns notFound when file is corrupt|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns notFound when file is corrupt|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns notFound when file is missing|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns notFound when file is missing|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns stale when PID is not running|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile returns stale when PID is not running|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile treats newer protocol version as compatible|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readActiveAgentHostFromLockfile treats newer protocol version as compatible|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readLocalAgentHostLockfile parses a valid state file|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readLocalAgentHostLockfile parses a valid state file|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readLocalAgentHostLockfile returns undefined for invalid JSON|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readLocalAgentHostLockfile returns undefined for invalid JSON|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readLocalAgentHostLockfile returns undefined when file does not exist|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readLocalAgentHostLockfile returns undefined when file does not exist|occurrence=1agentHostLockfile.test|t…agentHostLockfile.test|title=Agent Host Lockfile (local) readLocalAgentHostLockfile returns undefined when schema is invalid|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostLockfile.test|title=Agent Host Lockfile (local) readLocalAgentHostLockfile returns undefined when schema is invalid|occurrence=1agentHostLockfile.test|t…Focused file · src/vs/platform/agentHost/node/agentHostLockfile.ts · 123 LOCnode/agentHostLockfile.t…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- agentHostLockfile.ts ×4
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import * as fs from 'fs';
7 > import * as os from 'os';
8 > import { join } from '../../../base/common/path.js';
9 > import { ILogService } from '../../log/common/log.js';
10 > import { IRemoteAgentHostState, parseRemoteAgentHostState } from '../common/remoteAgentHostMetadata.js';
11 > import { dialAgentHostHost, validateShellToken } from './sshRemoteAgentHostHelpers.js';
12 >
13 > const LOG_PREFIX = '[AgentHostLockfile]';
14 >
15 > /**
16 > * Local-filesystem variant of {@link getAgentHostLockfile}. Returns an
17 > * absolute path resolved against the current user's home directory rather
18 > * than the shell-style `~/<...>` path used over SSH. Anchored on
19 > * `serverDataFolderName` so it stays in sync with the Rust CLI (see
20 > * `cli/src/state.rs::agent_host_root`). Both inputs are validated for
21 > * safe characters as defense-in-depth.
22 > */
23 > export function getLocalAgentHostLockfilePath(serverDataFolderName: string, quality: string): string {
24 > const d = validateShellToken(serverDataFolderName, 'server data folder name'); agentHostLockfile.ts ×1
25 > const q = validateShellToken(quality, 'quality');
26 > return join(os.homedir(), d, 'cli', `agent-host-${q}.lock`);
27 > }
29 > /**
30 > * Read and parse the canonical agent-host lockfile from a local path.
31 > * Returns `undefined` if the file does not exist, cannot be read, or
32 > * does not contain a valid {@link IRemoteAgentHostState}.
33 > */
34 > export async function readLocalAgentHostLockfile(lockfilePath: string, logService?: ILogService): Promise<IRemoteAgentHostState | undefined> { agentHostLockfile.ts ×1
35 > let raw: string;
36 > try {
37 > raw = await fs.promises.readFile(lockfilePath, 'utf8');
38 > } catch (err: unknown) {
39 > const code = (err as NodeJS.ErrnoException | undefined)?.code; agentHostLockfile.ts ×2
40 > if (code !== 'ENOENT') {
41 logService?.warn(`${LOG_PREFIX} Failed to read agent host lockfile ${lockfilePath}: ${err}`);
42 }
43 > return undefined; agentHostLockfile.ts ×2
44 > }
46 > let parsed: unknown;
47 > try {
48 > parsed = JSON.parse(raw);
49 > } catch {
50 > logService?.info(`${LOG_PREFIX} Agent host lockfile ${lockfilePath} contains invalid JSON`); agentHostLockfile.ts ×1
51 > return undefined;
52 > }
54 > const state = parseRemoteAgentHostState(parsed);
55 > if (!state) {
56 > logService?.info(`${LOG_PREFIX} Agent host lockfile ${lockfilePath} does not match expected schema`); agentHostLockfile.ts ×1
57 > return undefined;
58 > }
59 > return state; agentHostLockfile.ts ×1
60 > }
62 > /**
63 > * Mirrors the SSH-side {@link FindRunningAgentHostResult}, applied to a local
64 > * lockfile path. PID liveness is tested via `process.kill(pid, 0)`, which
65 > * sends no signal but reports whether the OS has a process with that PID.
66 > */
67 > export type LocalAgentHostLookupResult =
68 > | { readonly kind: 'notFound' }
69 > | { readonly kind: 'stale'; readonly pid: number }
70 > | { readonly kind: 'compatible'; readonly pid: number; readonly host: string; readonly port: number; readonly connectionToken: string | undefined };
71 >
72 > /**
73 > * Read the lockfile and verify the recorded PID is still alive. Returns
74 > * `notFound` on missing/corrupt files, `stale` on dead PIDs, and
75 > * `compatible` for any live process.
76 > *
77 > * The recorded protocol version is intentionally NOT checked here: the
78 > * agent host server is downloaded on demand and may speak a newer
79 > * protocol than the consumer was built with. The renderer↔AH handshake
80 > * surfaces any genuine incompatibility.
81 > */
82 > export async function readActiveAgentHostFromLockfile(lockfilePath: string, logService: ILogService): Promise<LocalAgentHostLookupResult> { agentHostLockfile.ts ×2
83 > const state = await readLocalAgentHostLockfile(lockfilePath, logService);
84 > if (!state) {
85 > return { kind: 'notFound' }; agentHostLockfile.ts ×1
86 > }
88 > if (!isPidAlive(state.pid)) {
89 > logService.info(`${LOG_PREFIX} Stale agent host lockfile ${lockfilePath} (PID ${state.pid} not running)`); agentHostLockfile.ts ×1
90 > return { kind: 'stale', pid: state.pid };
91 > }
93 > logService.info(`${LOG_PREFIX} Found running agent host via ${lockfilePath}: PID ${state.pid}, port ${state.port}`);
94 > return {
95 > kind: 'compatible',
96 > pid: state.pid,
97 > host: dialAgentHostHost(state.host),
98 > port: state.port,
99 > connectionToken: state.connectionToken ?? undefined,
101 > }
103 > /**
104 > * Returns `true` if a process with the given PID exists. Uses signal 0
105 > * which never delivers a signal but performs the existence/permission
106 > * check. EPERM means the process exists but we cannot signal it (still
107 > * counts as alive).
108 > */
109 > export function isPidAlive(pid: number): boolean {
110 > if (!Number.isSafeInteger(pid) || pid <= 0) { agentHostLockfile.ts ×2
111 > return false; agentHostLockfile.ts ×1
112 > }
114 > process.kill(pid, 0);
115 > return true;
116 > } catch (err: unknown) {
117 > const code = (err as NodeJS.ErrnoException | undefined)?.code; agentHostLockfile.ts ×1
118 > // EPERM: process exists but we lack permission to signal it (still alive).
119 > // ESRCH: no such process.
120 > // On Windows, `process.kill` with signal 0 throws ESRCH for missing PIDs.
121 > return code === 'EPERM';
122 > }