408
return;
409
}
411
>
const stateFile = getAgentHostLockfile(serverDataFolderName, quality);
412
>
const state = createRemoteAgentHostState({ pid, port, connectionToken, quality });
413
>
const json = JSON.stringify(state);
414
>
// Remove any existing file first so `>` creates a fresh inode with the
415
>
// new umask (overwriting an existing file preserves its old permissions).
416
>
// Use a subshell with restrictive umask (077) so the file is created with
417
>
// owner-only permissions (0600), protecting the connection token.
418
>
// The CLI itself stores its token file with the same permissions.
419
>
const result = await exec(`mkdir -p $(dirname ${stateFile}) && rm -f ${stateFile} && (umask 077 && printf %s ${shellEscape(json)} > ${stateFile})`, { ignoreExitCode: true });
420
>
if (result.code !== 0) {
421
logService.warn(`${LOG_PREFIX} Failed to write agent host state to ${stateFile} (exit code ${result.code})${result.stderr ? `: ${result.stderr.trim()}` : ''}`);
422
return;