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,
_command: Command,
): Promise<AgentDeleteResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
if (!id && !options.all && !options.cwd) {
const error: CommandError = {
@@ -52,7 +52,7 @@ export async function runDeleteCommand(
let client: DaemonClient;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
+2 -2
View File
@@ -86,7 +86,7 @@ export async function runLogsCommand(
options: AgentLogsOptions,
_command: Command,
): Promise<AgentLogsResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
if (!id) {
console.error("Error: Agent ID required");
@@ -96,7 +96,7 @@ export async function runLogsCommand(
let client: DaemonClient;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
console.error(`Error: Cannot connect to daemon at ${host}: ${message}`);
+2 -2
View File
@@ -168,11 +168,11 @@ export async function runLsCommand(
options: AgentLsOptions,
_command: Command,
): Promise<AgentLsResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
let client;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
+2 -2
View File
@@ -55,7 +55,7 @@ export async function runModeCommand(
_command: Command,
): Promise<AgentModeResult> {
const normalizedMode = mode?.trim();
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
// Validate arguments
if (!options.list && !normalizedMode) {
@@ -64,7 +64,7 @@ export async function runModeCommand(
let client: Awaited<ReturnType<typeof connectToDaemon>> | undefined;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
const fetchResult = await client.fetchAgent(id);
if (!fetchResult) {
const error: CommandError = {
+2 -2
View File
@@ -358,7 +358,7 @@ export async function runRunCommand(
options: AgentRunOptions,
_command: Command,
): 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;
validateRunOptions(prompt, options, outputSchema);
@@ -367,7 +367,7 @@ export async function runRunCommand(
const resolvedProviderModel = resolveProviderAndModel(options);
const resolvedTitle = options.title ?? options.name;
const client = await connectToDaemonOrThrow(options.host as string | undefined, host);
const client = await connectToDaemonOrThrow(options.host, host);
try {
// Resolve working directory
+2 -2
View File
@@ -166,7 +166,7 @@ export async function runSendCommand(
options: AgentSendOptions,
_command: Command,
): Promise<SingleResult<AgentSendResult>> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
// Validate arguments
if (!agentIdArg || agentIdArg.trim().length === 0) {
@@ -186,7 +186,7 @@ export async function runSendCommand(
let client;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
+2 -2
View File
@@ -42,7 +42,7 @@ export async function runStopCommand(
options: AgentStopOptions,
_command: Command,
): 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
if (!id && !options.all && !options.cwd) {
@@ -56,7 +56,7 @@ export async function runStopCommand(
let client: DaemonClient;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
+2 -2
View File
@@ -83,11 +83,11 @@ export async function runLoopInspectCommand(
options: LoopInspectOptions,
_command: Command,
): Promise<LoopInspectResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
let client;
try {
client = (await connectToDaemon({
host: options.host as string | undefined,
host: options.host,
})) as unknown as LoopDaemonClient;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
+2 -2
View File
@@ -42,12 +42,12 @@ export async function runLoopLogsCommand(
options: LoopLogsOptions,
_command: Command,
): Promise<void> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
const pollInterval = parsePollInterval(options.pollInterval ?? "1000");
let client: LoopDaemonClient;
try {
client = (await connectToDaemon({
host: options.host as string | undefined,
host: options.host,
})) as unknown as LoopDaemonClient;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
+2 -2
View File
@@ -47,11 +47,11 @@ export async function runLoopLsCommand(
options: LoopLsOptions,
_command: Command,
): Promise<LoopLsResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
let client;
try {
client = (await connectToDaemon({
host: options.host as string | undefined,
host: options.host,
})) as unknown as LoopDaemonClient;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
+2 -2
View File
@@ -153,12 +153,12 @@ export async function runLoopRunCommand(
options: LoopRunOptions,
_command: Command,
): Promise<LoopRunResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
const input = buildLoopRunInput(prompt, options);
let client;
try {
client = (await connectToDaemon({
host: options.host as string | undefined,
host: options.host,
})) as unknown as LoopDaemonClient;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
+2 -2
View File
@@ -44,11 +44,11 @@ export async function runLoopStopCommand(
options: LoopStopOptions,
_command: Command,
): Promise<LoopStopResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
let client;
try {
client = (await connectToDaemon({
host: options.host as string | undefined,
host: options.host,
})) as unknown as LoopDaemonClient;
} catch (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 */
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;
}