Switch to double quotes and reformat codebase with Biome

This commit is contained in:
Mohamed Boudra
2026-03-21 20:22:15 +07:00
parent ab40786882
commit f6579dbeb4
805 changed files with 38132 additions and 40175 deletions
+61 -56
View File
@@ -1,123 +1,128 @@
import type { Command } from 'commander'
import { connectToDaemon, getDaemonHost } from '../../utils/client.js'
import type { CommandOptions, SingleResult, OutputSchema, CommandError } from '../../output/index.js'
import type { Command } from "commander";
import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
import type {
CommandOptions,
SingleResult,
OutputSchema,
CommandError,
} from "../../output/index.js";
/** Result type for agent stop command */
export interface StopResult {
stoppedCount: number
agentIds: string[]
stoppedCount: number;
agentIds: string[];
}
/** Schema for stop command output */
export const stopSchema: OutputSchema<StopResult> = {
// For quiet mode, output the stopped agent IDs (one per line)
idField: (item) => item.agentIds.join('\n'),
columns: [{ header: 'INTERRUPTED', field: 'stoppedCount' }],
}
idField: (item) => item.agentIds.join("\n"),
columns: [{ header: "INTERRUPTED", field: "stoppedCount" }],
};
export interface AgentStopOptions extends CommandOptions {
all?: boolean
cwd?: string
all?: boolean;
cwd?: string;
}
export type AgentStopResult = SingleResult<StopResult>
export type AgentStopResult = SingleResult<StopResult>;
export async function runStopCommand(
id: string | undefined,
options: AgentStopOptions,
_command: Command
_command: Command,
): Promise<AgentStopResult> {
const host = getDaemonHost({ host: options.host as string | undefined })
const host = getDaemonHost({ host: options.host as string | undefined });
// Validate arguments - need either an id, --all, or --cwd
if (!id && !options.all && !options.cwd) {
const error: CommandError = {
code: 'MISSING_ARGUMENT',
message: 'Agent ID required unless --all or --cwd is specified',
details: 'Usage: paseo agent stop <id> | --all | --cwd <path>',
}
throw error
code: "MISSING_ARGUMENT",
message: "Agent ID required unless --all or --cwd is specified",
details: "Usage: paseo agent stop <id> | --all | --cwd <path>",
};
throw error;
}
let client
let client;
try {
client = await connectToDaemon({ host: options.host as string | undefined })
client = await connectToDaemon({ host: options.host as string | undefined });
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: 'DAEMON_NOT_RUNNING',
code: "DAEMON_NOT_RUNNING",
message: `Cannot connect to daemon at ${host}: ${message}`,
details: 'Start the daemon with: paseo daemon start',
}
throw error
details: "Start the daemon with: paseo daemon start",
};
throw error;
}
try {
const fetchPayload = await client.fetchAgents({ filter: { includeArchived: true } })
let agents = fetchPayload.entries.map((entry) => entry.agent)
const stoppedIds: string[] = []
const fetchPayload = await client.fetchAgents({ filter: { includeArchived: true } });
let agents = fetchPayload.entries.map((entry) => entry.agent);
const stoppedIds: string[] = [];
if (options.all) {
// Stop all agents (not archived)
agents = agents.filter((a) => !a.archivedAt)
agents = agents.filter((a) => !a.archivedAt);
} else if (options.cwd) {
// Stop agents in directory
const filterCwd = options.cwd
const filterCwd = options.cwd;
agents = agents.filter((a) => {
if (a.archivedAt) return false
const agentCwd = a.cwd.replace(/\/$/, '')
const targetCwd = filterCwd.replace(/\/$/, '')
return agentCwd === targetCwd || agentCwd.startsWith(targetCwd + '/')
})
if (a.archivedAt) return false;
const agentCwd = a.cwd.replace(/\/$/, "");
const targetCwd = filterCwd.replace(/\/$/, "");
return agentCwd === targetCwd || agentCwd.startsWith(targetCwd + "/");
});
} else if (id) {
// Stop specific agent
const fetchResult = await client.fetchAgent(id)
const fetchResult = await client.fetchAgent(id);
if (!fetchResult) {
const error: CommandError = {
code: 'AGENT_NOT_FOUND',
code: "AGENT_NOT_FOUND",
message: `No agent found matching: ${id}`,
details: 'Use `paseo ls` to list available agents',
}
throw error
details: "Use `paseo ls` to list available agents",
};
throw error;
}
agents = [fetchResult.agent]
agents = [fetchResult.agent];
}
// Interrupt each running agent. Idle agents are a no-op.
for (const agent of agents) {
try {
if (agent.status === 'running') {
await client.cancelAgent(agent.id)
stoppedIds.push(agent.id)
if (agent.status === "running") {
await client.cancelAgent(agent.id);
stoppedIds.push(agent.id);
}
} catch (err) {
// Continue interrupting other agents even if one fails
const message = err instanceof Error ? err.message : String(err)
console.error(`Warning: Failed to stop agent ${agent.id.slice(0, 7)}: ${message}`)
const message = err instanceof Error ? err.message : String(err);
console.error(`Warning: Failed to stop agent ${agent.id.slice(0, 7)}: ${message}`);
}
}
await client.close()
await client.close();
return {
type: 'single',
type: "single",
data: {
stoppedCount: stoppedIds.length,
agentIds: stoppedIds,
},
schema: stopSchema,
}
};
} catch (err) {
await client.close().catch(() => {})
await client.close().catch(() => {});
// Re-throw if it's already a CommandError
if (err && typeof err === 'object' && 'code' in err) {
throw err
if (err && typeof err === "object" && "code" in err) {
throw err;
}
const message = err instanceof Error ? err.message : String(err)
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: 'STOP_AGENT_FAILED',
code: "STOP_AGENT_FAILED",
message: `Failed to stop agent(s): ${message}`,
}
throw error
};
throw error;
}
}