use std::ffi::OsString;
use std::path::PathBuf;
use clap::{Args, Subcommand, ValueEnum};
use super::{PassthroughArgs, TopArgs};
#[derive(Clone, Debug, Default, Args)]
pub(crate) struct CodeArgs {
#[command(subcommand)]
pub command: Option<CodeCommand>,
}
#[derive(Clone, Debug, Subcommand)]
pub(crate) enum CodeCommand {
Exec(CodeExecArgs),
Resume(CodeResumeArgs),
#[command(alias = "deepresearch", alias = "deep-research")]
Research(CodeResearchArgs),
Session(CodeSessionArgs),
Agent(AgentArgs),
Mcp(McpArgs),
Skill(SkillArgs),
Flow(FlowArgs),
Okf(OkfArgs),
Kb(KbArgs),
#[command(alias = "ctx")]
Context(ContextArgs),
#[command(alias = "mem")]
Memory(MemoryArgs),
#[command(name = "login", hide = true)]
LegacyLogin(LegacyLoginArgs),
#[command(name = "logout", hide = true)]
LegacyLogout,
#[command(name = "auth", hide = true)]
LegacyAuth(PassthroughArgs),
#[command(name = "config", hide = true)]
LegacyConfig(PassthroughArgs),
#[command(name = "dirs", hide = true)]
LegacyDirs,
#[command(name = "models", hide = true)]
LegacyModels,
#[command(name = "model", hide = true)]
LegacyModel(PassthroughArgs),
#[command(name = "top", hide = true)]
LegacyTop(TopArgs),
#[command(name = "update", hide = true)]
LegacyUpdate,
#[command(name = "serve", hide = true)]
RemovedServe(PassthroughArgs),
}
#[derive(Clone, Debug, Default, Args)]
pub(crate) struct CodeExecArgs {
#[arg(value_name = "PROMPT", conflicts_with = "prompt_file")]
pub prompt: Option<String>,
#[arg(long, value_name = "PATH", conflicts_with = "prompt")]
pub prompt_file: Option<PathBuf>,
#[arg(long, value_enum, default_value_t = CodeMode::Default)]
pub mode: CodeMode,
#[arg(long, value_name = "PROVIDER/MODEL")]
pub model: Option<String>,
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, ValueEnum)]
pub(crate) enum CodeMode {
Plan,
#[default]
Default,
Auto,
}
#[derive(Clone, Debug, Default, Args)]
pub(crate) struct CodeResumeArgs {
#[arg(value_name = "SESSION_ID")]
pub session_id: Option<String>,
}
#[derive(Clone, Debug, Args)]
pub(crate) struct CodeResearchArgs {
#[arg(value_name = "QUERY", required = true)]
pub query: Vec<String>,
#[arg(long, conflicts_with = "web")]
pub local_only: bool,
#[arg(long, conflicts_with = "local_only")]
pub web: bool,
#[arg(long, value_name = "PATH")]
pub report_dir: Option<PathBuf>,
}
#[derive(Clone, Debug, Args)]
#[command(subcommand_required = true, arg_required_else_help = true)]
pub(crate) struct CodeSessionArgs {
#[command(subcommand)]
pub command: CodeSessionCommand,
}
#[derive(Clone, Debug, Subcommand)]
pub(crate) enum CodeSessionCommand {
List,
Show(SessionIdArgs),
Export(SessionExportArgs),
Delete(SessionDeleteArgs),
}
#[derive(Clone, Debug, Args)]
pub(crate) struct SessionIdArgs {
#[arg(value_name = "SESSION_ID")]
pub session_id: String,
}
#[derive(Clone, Debug, Args)]
pub(crate) struct SessionExportArgs {
#[arg(value_name = "SESSION_ID")]
pub session_id: String,
#[arg(long, value_name = "PATH")]
pub output_file: Option<PathBuf>,
}
#[derive(Clone, Debug, Args)]
pub(crate) struct SessionDeleteArgs {
#[arg(value_name = "SESSION_ID")]
pub session_id: String,
#[arg(long)]
pub yes: bool,
}
#[derive(Clone, Debug, Args)]
#[command(subcommand_required = true, arg_required_else_help = true)]
pub(crate) struct AgentArgs {
#[command(subcommand)]
pub command: AgentCommand,
}
#[derive(Clone, Debug, Subcommand)]
pub(crate) enum AgentCommand {
List(AssetListArgs),
Clone(AssetCloneArgs),
Review(AssetPathArgs),
Activity(AssetQueryArgs),
Publish(AgentPublishArgs),
Run(AgentActionArgs),
Deploy(AssetPathArgs),
Open(AgentActionArgs),
Logs(AgentActionArgs),
Status(AgentActionArgs),
}
#[derive(Clone, Debug, Args)]
pub(crate) struct AgentPublishArgs {
#[arg(value_name = "PATH")]
pub path: Option<PathBuf>,
#[arg(long, value_enum)]
pub kind: AgentKind,
}
#[derive(Clone, Debug, Default, Args)]
pub(crate) struct AgentActionArgs {
#[arg(value_name = "PATH")]
pub path: Option<PathBuf>,
#[arg(long, value_enum)]
pub kind: Option<AgentKind>,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub(crate) enum AgentKind {
Agentic,
Application,
Tool,
}
macro_rules! asset_family {
($args:ident, $command:ident, [$($verb:ident),+ $(,)?]) => {
#[derive(Clone, Debug, Args)]
#[command(subcommand_required = true, arg_required_else_help = true)]
pub(crate) struct $args {
#[command(subcommand)]
pub command: $command,
}
#[derive(Clone, Debug, Subcommand)]
pub(crate) enum $command {
List(AssetListArgs),
Clone(AssetCloneArgs),
Review(AssetPathArgs),
Activity(AssetQueryArgs),
$($verb(AssetPathArgs)),+
}
};
}
asset_family!(
McpArgs,
McpCommand,
[Publish, Run, Test, Deploy, Open, Logs, Status]
);
asset_family!(SkillArgs, SkillCommand, [Publish, Deploy, Open, Status]);
asset_family!(
FlowArgs,
FlowCommand,
[Publish, Run, Deploy, Open, Logs, Status]
);
asset_family!(OkfArgs, OkfCommand, [Publish, Deploy, Status]);
#[derive(Clone, Debug, Args)]
pub(crate) struct AssetListArgs {
#[arg(long, value_enum)]
pub location: AssetLocation,
#[arg(value_name = "QUERY")]
pub query: Option<String>,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub(crate) enum AssetLocation {
Local,
Os,
All,
}
#[derive(Clone, Debug, Args)]
pub(crate) struct AssetCloneArgs {
#[arg(value_name = "GIT_URL")]
pub git_url: String,
}
#[derive(Clone, Debug, Default, Args)]
pub(crate) struct AssetPathArgs {
#[arg(value_name = "PATH")]
pub path: Option<PathBuf>,
}
#[derive(Clone, Debug, Default, Args)]
pub(crate) struct AssetQueryArgs {
#[arg(value_name = "QUERY")]
pub query: Option<String>,
}
#[derive(Clone, Debug, Args)]
#[command(subcommand_required = true, arg_required_else_help = true)]
pub(crate) struct KbArgs {
#[command(subcommand)]
pub command: KbCommand,
}
#[derive(Clone, Debug, Subcommand)]
pub(crate) enum KbCommand {
Stats,
Add(KbTextArgs),
Import(KbImportArgs),
Search(KbTextArgs),
Path,
}
#[derive(Clone, Debug, Args)]
pub(crate) struct KbTextArgs {
#[arg(value_name = "TEXT")]
pub text: String,
}
#[derive(Clone, Debug, Args)]
pub(crate) struct KbImportArgs {
#[arg(value_name = "FILE_OR_DIRECTORY")]
pub path: PathBuf,
}
#[derive(Clone, Debug, Args)]
#[command(subcommand_required = true, arg_required_else_help = true)]
pub(crate) struct ContextArgs {
#[command(subcommand)]
pub command: ContextCommand,
}
#[derive(Clone, Debug, Subcommand)]
pub(crate) enum ContextCommand {
Search(ContextQueryArgs),
Show(ContextShowArgs),
}
#[derive(Clone, Debug, Args)]
pub(crate) struct ContextQueryArgs {
#[arg(value_name = "QUERY")]
pub query: String,
}
#[derive(Clone, Debug, Args)]
#[command(subcommand_required = true, arg_required_else_help = true)]
pub(crate) struct ContextShowArgs {
#[command(subcommand)]
pub command: ContextShowCommand,
}
#[derive(Clone, Debug, Subcommand)]
pub(crate) enum ContextShowCommand {
Event(ContextEventArgs),
Session(SessionIdArgs),
}
#[derive(Clone, Debug, Args)]
pub(crate) struct ContextEventArgs {
#[arg(value_name = "EVENT_ID")]
pub event_id: String,
#[arg(long, default_value_t = 3)]
pub window: usize,
}
#[derive(Clone, Debug, Args)]
#[command(subcommand_required = true, arg_required_else_help = true)]
pub(crate) struct MemoryArgs {
#[command(subcommand)]
pub command: MemoryCommand,
}
#[derive(Clone, Debug, Subcommand)]
pub(crate) enum MemoryCommand {
List(MemoryListArgs),
Stats,
Path,
}
#[derive(Clone, Debug, Default, Args)]
pub(crate) struct MemoryListArgs {
#[arg(value_name = "QUERY")]
pub query: Option<String>,
}
#[derive(Clone, Debug, Default, Args)]
pub(crate) struct LegacyLoginArgs {
#[arg(value_name = "LEGACY_TOKEN", hide = true)]
pub values: Vec<OsString>,
}