1
>
/*---------------------------------------------------------------------------------------------
agentHostLockfile.ts
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');
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> {
35
let raw: string;