aipack 0.8.22

Command Agent runner to accelerate production coding with genai.
//! The executor command
//! Note: For now, the content of the variant of the ExecCommand often contain the CliArgs,
//!       but this will eventual change to have it's own

use crate::exec::cli::{
	CheckKeysArgs, CreateGitignoreArgs, InitArgs, InstallArgs, ListArgs, NewArgs, PackArgs, RunArgs, UnpackArgs,
	XelfSetupArgs, XelfUpdateArgs,
};
use crate::model::Id;
use crate::run::RunSubAgentParams;
use derive_more::From;

/// Executor Action Event that needs to be performed
///
/// When a system part needs to perform an action, it should send one of these events.
///
/// For now, there are split in 3 categories
/// - The cli commands
/// - The interactive commands (when pressing in the "cli interface")
/// - The agent commands (when Lua is asking to execute an agent agent)
///
/// NOTE: This is not the `ExecStateEvent` which is sent to the hub.
#[derive(Debug, strum::IntoStaticStr, From)]
pub enum ExecActionEvent {
	// -- CLI Commands
	/// This will init the workspace with `.aipack/`
	/// and the base with `~/.aipack-base`
	CmdInit(InitArgs),
	/// This will init only the base
	CmdInitBase,

	CmdList(ListArgs),
	CmdPack(PackArgs),
	CmdInstall(InstallArgs),
	CmdUnpack(UnpackArgs),
	/// Check for API keys in the environment
	CmdCheckKeys(CheckKeysArgs),
	/// Create a .gitignore file from template
	CmdCreateGitignore(CreateGitignoreArgs),
	/// Perform `self setup` action
	CmdXelfSetup(XelfSetupArgs),
	/// Preform `self update`
	CmdXelfUpdate(XelfUpdateArgs),
	/// Trigger an agent run (either from CLI or UI)
	Run(RunArgs),

	// -- Interactive Commands
	OpenAgent,

	// -- Run Commands
	/// When press r
	Redo,
	/// When called from
	#[from]
	RunSubAgent(RunSubAgentParams),

	CancelRun,

	// -- Work Lifecycle
	WorkConfirm(Id),
	WorkCancel(Id),

	// -- New Agent
	CmdNew(NewArgs),
}

impl ExecActionEvent {
	pub fn as_str(&self) -> &'static str {
		// thanks to strum::IntoStaticStr
		self.into()
	}

	/// Return true if this event is part of a TUI
	/// NOTE: this is for the executor, but we might want to change this eventually
	pub fn is_tui(&self) -> bool {
		match self {
			ExecActionEvent::Run(run_args) => run_args.is_tui(),
			ExecActionEvent::Redo
			| ExecActionEvent::CancelRun
			| ExecActionEvent::WorkConfirm(_)
			| ExecActionEvent::WorkCancel(_)
			| ExecActionEvent::OpenAgent => true,
			// TODO: Those need to be handled
			// (might not be an issue for now, because this is for error handling
			// and error that are not run related happen at start)
			// ExecActionEvent::RunSubAgent(run_sub_agent_params) => todo!(),
			_ => false,
		}
	}
}