Type CLI command host/json options at the source

The CommandOptions interface in packages/cli/src/output/with-output.ts had
an open `[key: string]: unknown` indexer, so every consumer of the global
--host and --json options had to cast `options.host as string | undefined`
at the call site. Add `host?: string` and `json?: boolean` to the interface
and remove 29 redundant casts across 12 command files.
This commit is contained in:
Mohamed Boudra
2026-05-05 19:56:26 +07:00
parent 4cd9e76bd2
commit 5feaa7a101
13 changed files with 28 additions and 24 deletions
+2 -2
View File
@@ -39,7 +39,7 @@ export async function runDeleteCommand(
options: AgentDeleteOptions, options: AgentDeleteOptions,
_command: Command, _command: Command,
): Promise<AgentDeleteResult> { ): Promise<AgentDeleteResult> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
if (!id && !options.all && !options.cwd) { if (!id && !options.all && !options.cwd) {
const error: CommandError = { const error: CommandError = {
@@ -52,7 +52,7 @@ export async function runDeleteCommand(
let client: DaemonClient; let client: DaemonClient;
try { try {
client = await connectToDaemon({ host: options.host as string | undefined }); client = await connectToDaemon({ host: options.host });
} catch (err) { } catch (err) {
const message = err instanceof Error ? err.message : String(err); const message = err instanceof Error ? err.message : String(err);
const error: CommandError = { const error: CommandError = {
+2 -2
View File
@@ -86,7 +86,7 @@ export async function runLogsCommand(
options: AgentLogsOptions, options: AgentLogsOptions,
_command: Command, _command: Command,
): Promise<AgentLogsResult> { ): Promise<AgentLogsResult> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
if (!id) { if (!id) {
console.error("Error: Agent ID required"); console.error("Error: Agent ID required");
@@ -96,7 +96,7 @@ export async function runLogsCommand(
let client: DaemonClient; let client: DaemonClient;
try { try {
client = await connectToDaemon({ host: options.host as string | undefined }); client = await connectToDaemon({ host: options.host });
} catch (err) { } catch (err) {
const message = err instanceof Error ? err.message : String(err); const message = err instanceof Error ? err.message : String(err);
console.error(`Error: Cannot connect to daemon at ${host}: ${message}`); console.error(`Error: Cannot connect to daemon at ${host}: ${message}`);
+2 -2
View File
@@ -168,11 +168,11 @@ export async function runLsCommand(
options: AgentLsOptions, options: AgentLsOptions,
_command: Command, _command: Command,
): Promise<AgentLsResult> { ): Promise<AgentLsResult> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
let client; let client;
try { try {
client = await connectToDaemon({ host: options.host as string | undefined }); client = await connectToDaemon({ host: options.host });
} catch (err) { } catch (err) {
const message = err instanceof Error ? err.message : String(err); const message = err instanceof Error ? err.message : String(err);
const error: CommandError = { const error: CommandError = {
+2 -2
View File
@@ -55,7 +55,7 @@ export async function runModeCommand(
_command: Command, _command: Command,
): Promise<AgentModeResult> { ): Promise<AgentModeResult> {
const normalizedMode = mode?.trim(); const normalizedMode = mode?.trim();
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
// Validate arguments // Validate arguments
if (!options.list && !normalizedMode) { if (!options.list && !normalizedMode) {
@@ -64,7 +64,7 @@ export async function runModeCommand(
let client: Awaited<ReturnType<typeof connectToDaemon>> | undefined; let client: Awaited<ReturnType<typeof connectToDaemon>> | undefined;
try { try {
client = await connectToDaemon({ host: options.host as string | undefined }); client = await connectToDaemon({ host: options.host });
const fetchResult = await client.fetchAgent(id); const fetchResult = await client.fetchAgent(id);
if (!fetchResult) { if (!fetchResult) {
const error: CommandError = { const error: CommandError = {
+2 -2
View File
@@ -358,7 +358,7 @@ export async function runRunCommand(
options: AgentRunOptions, options: AgentRunOptions,
_command: Command, _command: Command,
): Promise<SingleResult<AgentRunResult>> { ): Promise<SingleResult<AgentRunResult>> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
const outputSchema = options.outputSchema ? loadOutputSchema(options.outputSchema) : undefined; const outputSchema = options.outputSchema ? loadOutputSchema(options.outputSchema) : undefined;
validateRunOptions(prompt, options, outputSchema); validateRunOptions(prompt, options, outputSchema);
@@ -367,7 +367,7 @@ export async function runRunCommand(
const resolvedProviderModel = resolveProviderAndModel(options); const resolvedProviderModel = resolveProviderAndModel(options);
const resolvedTitle = options.title ?? options.name; const resolvedTitle = options.title ?? options.name;
const client = await connectToDaemonOrThrow(options.host as string | undefined, host); const client = await connectToDaemonOrThrow(options.host, host);
try { try {
// Resolve working directory // Resolve working directory
+2 -2
View File
@@ -166,7 +166,7 @@ export async function runSendCommand(
options: AgentSendOptions, options: AgentSendOptions,
_command: Command, _command: Command,
): Promise<SingleResult<AgentSendResult>> { ): Promise<SingleResult<AgentSendResult>> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
// Validate arguments // Validate arguments
if (!agentIdArg || agentIdArg.trim().length === 0) { if (!agentIdArg || agentIdArg.trim().length === 0) {
@@ -186,7 +186,7 @@ export async function runSendCommand(
let client; let client;
try { try {
client = await connectToDaemon({ host: options.host as string | undefined }); client = await connectToDaemon({ host: options.host });
} catch (err) { } catch (err) {
const message = err instanceof Error ? err.message : String(err); const message = err instanceof Error ? err.message : String(err);
const error: CommandError = { const error: CommandError = {
+2 -2
View File
@@ -42,7 +42,7 @@ export async function runStopCommand(
options: AgentStopOptions, options: AgentStopOptions,
_command: Command, _command: Command,
): Promise<AgentStopResult> { ): Promise<AgentStopResult> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
// Validate arguments - need either an id, --all, or --cwd // Validate arguments - need either an id, --all, or --cwd
if (!id && !options.all && !options.cwd) { if (!id && !options.all && !options.cwd) {
@@ -56,7 +56,7 @@ export async function runStopCommand(
let client: DaemonClient; let client: DaemonClient;
try { try {
client = await connectToDaemon({ host: options.host as string | undefined }); client = await connectToDaemon({ host: options.host });
} catch (err) { } catch (err) {
const message = err instanceof Error ? err.message : String(err); const message = err instanceof Error ? err.message : String(err);
const error: CommandError = { const error: CommandError = {
+2 -2
View File
@@ -83,11 +83,11 @@ export async function runLoopInspectCommand(
options: LoopInspectOptions, options: LoopInspectOptions,
_command: Command, _command: Command,
): Promise<LoopInspectResult> { ): Promise<LoopInspectResult> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
let client; let client;
try { try {
client = (await connectToDaemon({ client = (await connectToDaemon({
host: options.host as string | undefined, host: options.host,
})) as unknown as LoopDaemonClient; })) as unknown as LoopDaemonClient;
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error); const message = error instanceof Error ? error.message : String(error);
+2 -2
View File
@@ -42,12 +42,12 @@ export async function runLoopLogsCommand(
options: LoopLogsOptions, options: LoopLogsOptions,
_command: Command, _command: Command,
): Promise<void> { ): Promise<void> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
const pollInterval = parsePollInterval(options.pollInterval ?? "1000"); const pollInterval = parsePollInterval(options.pollInterval ?? "1000");
let client: LoopDaemonClient; let client: LoopDaemonClient;
try { try {
client = (await connectToDaemon({ client = (await connectToDaemon({
host: options.host as string | undefined, host: options.host,
})) as unknown as LoopDaemonClient; })) as unknown as LoopDaemonClient;
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error); const message = error instanceof Error ? error.message : String(error);
+2 -2
View File
@@ -47,11 +47,11 @@ export async function runLoopLsCommand(
options: LoopLsOptions, options: LoopLsOptions,
_command: Command, _command: Command,
): Promise<LoopLsResult> { ): Promise<LoopLsResult> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
let client; let client;
try { try {
client = (await connectToDaemon({ client = (await connectToDaemon({
host: options.host as string | undefined, host: options.host,
})) as unknown as LoopDaemonClient; })) as unknown as LoopDaemonClient;
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error); const message = error instanceof Error ? error.message : String(error);
+2 -2
View File
@@ -153,12 +153,12 @@ export async function runLoopRunCommand(
options: LoopRunOptions, options: LoopRunOptions,
_command: Command, _command: Command,
): Promise<LoopRunResult> { ): Promise<LoopRunResult> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
const input = buildLoopRunInput(prompt, options); const input = buildLoopRunInput(prompt, options);
let client; let client;
try { try {
client = (await connectToDaemon({ client = (await connectToDaemon({
host: options.host as string | undefined, host: options.host,
})) as unknown as LoopDaemonClient; })) as unknown as LoopDaemonClient;
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error); const message = error instanceof Error ? error.message : String(error);
+2 -2
View File
@@ -44,11 +44,11 @@ export async function runLoopStopCommand(
options: LoopStopOptions, options: LoopStopOptions,
_command: Command, _command: Command,
): Promise<LoopStopResult> { ): Promise<LoopStopResult> {
const host = getDaemonHost({ host: options.host as string | undefined }); const host = getDaemonHost({ host: options.host });
let client; let client;
try { try {
client = (await connectToDaemon({ client = (await connectToDaemon({
host: options.host as string | undefined, host: options.host,
})) as unknown as LoopDaemonClient; })) as unknown as LoopDaemonClient;
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error); const message = error instanceof Error ? error.message : String(error);
+4
View File
@@ -10,6 +10,10 @@ import { render, renderError, toCommandError, defaultOutputOptions } from "./ren
/** Options that include output settings from global options */ /** Options that include output settings from global options */
export interface CommandOptions extends Partial<OutputOptions> { export interface CommandOptions extends Partial<OutputOptions> {
/** Daemon host target from --host option */
host?: string;
/** JSON output flag from --json option */
json?: boolean;
[key: string]: unknown; [key: string]: unknown;
} }