fix(fleet): harden operator sends for release (#565)
This commit was merged in pull request #565.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { constants } from 'node:fs';
|
||||
import { access, copyFile, mkdir, readFile, writeFile } from 'node:fs/promises';
|
||||
import { homedir } from 'node:os';
|
||||
import { homedir, hostname } from 'node:os';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { spawn } from 'node:child_process';
|
||||
@@ -158,11 +158,14 @@ export function buildAgentSendCommand(
|
||||
agentName: string,
|
||||
message: string,
|
||||
socketName = DEFAULT_SOCKET_NAME,
|
||||
sourceLabel = getDefaultOperatorSourceLabel(),
|
||||
): string[] {
|
||||
return [
|
||||
join(paths.tmuxToolsDir, 'agent-send.sh'),
|
||||
'-L',
|
||||
socketName,
|
||||
'-S',
|
||||
sourceLabel,
|
||||
'-s',
|
||||
agentName,
|
||||
'-m',
|
||||
@@ -170,6 +173,11 @@ export function buildAgentSendCommand(
|
||||
];
|
||||
}
|
||||
|
||||
export function getDefaultOperatorSourceLabel(): string {
|
||||
const shortHostname = hostname().split('.')[0] || 'localhost';
|
||||
return `${shortHostname}:operator`;
|
||||
}
|
||||
|
||||
export function buildAgentResetCommand(
|
||||
paths: FleetPaths,
|
||||
agentName: string,
|
||||
@@ -384,15 +392,22 @@ export function registerFleetAgentCommands(
|
||||
.command('send <agent>')
|
||||
.description('Send a message to a local fleet agent')
|
||||
.requiredOption('--message <text>', 'Message text')
|
||||
.action(async (agent: string, opts: { message: string }) => {
|
||||
const roster = await loadRosterFromAgentCommand(agentCommand, deps.mosaicHome);
|
||||
getRosterAgent(roster, agent);
|
||||
const paths = resolveFleetPaths(resolveMosaicHomeFromCommand(agentCommand, deps.mosaicHome));
|
||||
await runChecked(
|
||||
runner,
|
||||
buildAgentSendCommand(paths, agent, opts.message, roster.tmux.socketName),
|
||||
);
|
||||
});
|
||||
.option('--source-label <label>', 'Source label for the message preamble')
|
||||
.option('--source <label>', 'Alias for --source-label')
|
||||
.action(
|
||||
async (agent: string, opts: { message: string; sourceLabel?: string; source?: string }) => {
|
||||
const roster = await loadRosterFromAgentCommand(agentCommand, deps.mosaicHome);
|
||||
getRosterAgent(roster, agent);
|
||||
const paths = resolveFleetPaths(
|
||||
resolveMosaicHomeFromCommand(agentCommand, deps.mosaicHome),
|
||||
);
|
||||
const sourceLabel = opts.sourceLabel ?? opts.source ?? getDefaultOperatorSourceLabel();
|
||||
await runChecked(
|
||||
runner,
|
||||
buildAgentSendCommand(paths, agent, opts.message, roster.tmux.socketName, sourceLabel),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
agentCommand
|
||||
.command('reset <agent>')
|
||||
|
||||
Reference in New Issue
Block a user