import type { CommandOutput } from './output' import type { ArgDefinition, FlagDefinition, ICommand, InferArgs, InferFlags, OptionalArgValueType, } from './types' import { setVerbose } from './context' import { hasBooleanFlag, parseArgv, VERBOSE_CHAR, VERBOSE_FLAG } from './flags' // What invoking a command does to remote/persistent state. Drives the skill's // safety section and the `effect` bit in machine-readable help. Defaults to // `read`; write/destructive commands must opt in explicitly. export type CommandEffect = 'read' | 'write' | 'destructive' export type CommandConstructor = { new (): Command description?: string flags?: Record> args?: Record> examples?: string[] hidden?: boolean deprecated?: string effect?: CommandEffect } type InferCommandArgs = C['args'] extends Record> ? InferArgs : Record type InferCommandFlags = C['flags'] extends Record> ? InferFlags : Record type ParseResult = { args: InferCommandArgs flags: InferCommandFlags } export abstract class Command implements ICommand { static description?: string static flags: Record> = {} static args: Record> = {} static examples: string[] = [] static effect: CommandEffect = 'read' abstract run(argv: string[]): Promise processGlobalFlags(argv: readonly string[]): void { setVerbose(hasBooleanFlag(argv, VERBOSE_FLAG, VERBOSE_CHAR)) } protected parse(ctor: C, argv: string[]): ParseResult { const meta = { flags: ctor.flags ?? {}, args: ctor.args ?? {}, } return parseArgv(argv, meta) as ParseResult } error(message: string, opts?: { exit?: number }): never { process.stderr.write(`${message}\n`) process.exit(opts?.exit ?? 1) } agentGuide(): string { return '' } }