use std::path::{Path, PathBuf};
use codewhale_core::request::{Message, SystemPrompt};
use crate::types::{
CommandApprovalMode, CommandCurrency, CommandMode, CommandProviderId, CommandReasoningEffort,
};
pub trait CommandSessionContext {
fn session_id(&self) -> Option<String>;
fn api_messages(&self) -> Vec<Message>;
fn add_message(&mut self, message: Message);
fn queued_message_count(&self) -> usize;
fn remove_queued_message(&mut self, index: usize) -> Result<(), String>;
fn total_tokens(&self) -> u64;
}
pub trait CommandModelContext {
fn current_model(&self) -> String;
fn auto_model(&self) -> bool;
fn set_model_selection(&mut self, model: String, provider: Option<CommandProviderId>);
fn reasoning_effort(&self) -> CommandReasoningEffort;
fn provider_identity(&self) -> Option<CommandProviderId>;
fn fallback_chain(&self) -> Vec<CommandProviderId>;
}
pub trait CommandCostContext {
fn display_currency(&self) -> CommandCurrency;
fn session_cost_for_currency(&self, currency: CommandCurrency) -> f64;
fn subagent_cost_for_currency(&self, currency: CommandCurrency) -> f64;
fn accrue_cost_estimate(&mut self, amount: f64, currency: CommandCurrency);
fn record_turn_cost(
&mut self,
amount: f64,
currency: CommandCurrency,
route_receipt: Option<String>,
);
}
pub trait CommandModePolicyContext {
fn mode(&self) -> CommandMode;
fn set_mode(&mut self, mode: CommandMode);
fn approval_mode(&self) -> CommandApprovalMode;
fn allow_shell(&self) -> bool;
fn set_shell_access(&mut self, allow: bool);
fn policy_locked(&self) -> bool;
}
pub trait CommandSystemPromptContext {
fn system_prompt(&self) -> Option<SystemPrompt>;
}
pub trait CommandSkillsContext {
fn active_skill(&self) -> Option<String>;
fn active_skill_provenance(&self) -> Option<String>;
fn refresh_skill_cache(&mut self);
}
pub trait CommandWorkspaceContext {
fn workspace(&self) -> PathBuf;
fn work_state_snapshot(&self) -> Result<Option<String>, String>;
fn operation_digest(&mut self) -> Result<String, String>;
}
pub trait CommandPresentationContext {
fn translate(&self, key: &str, replacements: &[(&str, &str)]) -> Result<String, String>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MediaAttachmentReceipt {
pub kind: String,
pub path: std::path::PathBuf,
}
pub trait CommandMediaContext {
fn attach_media(&mut self, resolved_path: &Path) -> Result<MediaAttachmentReceipt, String>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ProjectGoalStatus {
#[default]
Active,
Paused,
Complete,
Blocked,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProjectShareProjection {
pub history_is_empty: bool,
pub history_len: usize,
pub model: String,
pub mode_label: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProjectGoalState {
pub objective: Option<String>,
pub status: ProjectGoalStatus,
pub pause_reason: Option<String>,
pub started_at_elapsed_seconds: Option<u64>,
pub time_used_seconds: u64,
pub token_budget: Option<u32>,
pub tokens_used: u64,
pub session_total_tokens: u32,
pub continuation_count: u32,
pub pending_controls: bool,
pub last_known_objective: Option<String>,
pub last_known_status: Option<ProjectGoalStatus>,
pub conversation_present: bool,
pub is_loading: bool,
pub goal_continuation_waiting: bool,
}
pub trait CommandProjectContext {
fn lsp_enabled(&self) -> bool;
fn lsp_set(&mut self, enabled: bool) -> Result<(), String>;
fn share_projection(&self) -> ProjectShareProjection;
fn goal_state(&self) -> ProjectGoalState;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MemoryHit {
pub source: PathBuf,
pub line_start: usize,
pub line_end: usize,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MemoryStatus {
pub root: PathBuf,
pub source: PathBuf,
pub index: PathBuf,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MemoryRemembered {
pub source: PathBuf,
pub line_start: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MemoryImportOutcome {
Imported { destination: PathBuf },
Skipped,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MemoryGetOutcome {
Found(MemoryHit),
NotFound,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MemoryExport {
pub content: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MemoryReindex {
pub entry_count: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct MemoryDelete;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MemoryRememberTarget {
Global,
Workspace { workspace_id: String },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MemoryDeleteScope {
All,
Global,
}
pub trait CommandMemoryContext {
fn memory_path(&self) -> PathBuf;
fn memory_enabled(&self) -> bool;
fn status(&self) -> Result<MemoryStatus, String>;
fn path(&self) -> Result<PathBuf, String>;
fn workspace_id(&self, workspace: &Path) -> Result<String, String>;
fn search(&self, workspace: &Path, query: &str, limit: usize)
-> Result<Vec<MemoryHit>, String>;
fn remember(
&self,
target: MemoryRememberTarget,
note: &str,
) -> Result<MemoryRemembered, String>;
fn import(&self) -> Result<MemoryImportOutcome, String>;
fn get(&self, workspace: &Path, id: i64) -> Result<MemoryGetOutcome, String>;
fn export(&self) -> Result<MemoryExport, String>;
fn reindex(&self) -> Result<MemoryReindex, String>;
fn delete(&self, scope: MemoryDeleteScope) -> Result<MemoryDelete, String>;
fn delete_workspace(&self, workspace: &Path) -> Result<MemoryDelete, String>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PluginDiagnosticLevel {
Warning,
Error,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginDiagnostic {
pub level: PluginDiagnosticLevel,
pub code: String,
pub message: String,
pub path: Option<PathBuf>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PluginMcpTransport {
Stdio,
Http,
Invalid,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginMcpServerDetail {
pub name: String,
pub transport: PluginMcpTransport,
pub command: Option<String>,
pub argv: Vec<String>,
pub cwd: Option<PathBuf>,
pub env: Vec<(String, String)>,
pub url: Option<String>,
pub env_headers: Vec<(String, String)>,
pub bearer_token_env_var: Option<String>,
pub connect_timeout_secs: Option<u64>,
pub execute_timeout_secs: Option<u64>,
pub read_timeout_secs: Option<u64>,
pub required: bool,
pub enabled_tools: Vec<String>,
pub disabled_tools: Vec<String>,
pub enabled: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginSummary {
pub name: String,
pub id: String,
pub state_label: String,
pub scope: String,
pub trust_status: String,
pub compatibility: String,
pub inventory: String,
pub active: bool,
pub trusted: bool,
pub enabled: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginDetail {
pub inventory_summary: String,
pub name: String,
pub id: String,
pub version: String,
pub origin: String,
pub scope: String,
pub state_label: String,
pub trust_status: String,
pub compatibility: String,
pub content_hash: String,
pub capability_hash: String,
pub canonical_root: PathBuf,
pub active: bool,
pub trusted: bool,
pub enabled: bool,
pub unsupported_labels: Vec<String>,
pub supported_labels: Vec<String>,
pub skills: Vec<String>,
pub filesystem_roots: Vec<String>,
pub network_hosts: Vec<String>,
pub stdio_mcp_servers: usize,
pub lifecycle_mutation: bool,
pub mcp_servers: Vec<PluginMcpServerDetail>,
pub diagnostics: Vec<PluginDiagnostic>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PluginMutationOutcome {
Installed,
Updated,
NoChange,
Uninstalled,
NeedsApproval(String),
NetworkDenied(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginMutationReceipt {
pub name: String,
pub path: Option<PathBuf>,
pub content_hash: Option<String>,
pub installed_content_hash: Option<String>,
pub outcome: PluginMutationOutcome,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginExportReceipt {
pub exported_name: String,
pub target: PathBuf,
pub display_name: Option<String>,
pub wrote_mcp_json: bool,
pub files_copied: u64,
pub skills_normalized: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginLegacyTool {
pub name: String,
pub description: String,
pub approval: String,
pub input_schema: Option<String>,
pub path: PathBuf,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginLegacyScan {
pub dir: PathBuf,
pub tools: Vec<PluginLegacyTool>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginManagedCandidate {
pub name: String,
pub version: String,
pub license: Option<String>,
pub canonical_path: PathBuf,
pub content_hash: String,
pub capability_hash: String,
pub inventory: String,
pub applicable: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginManagedScan {
pub root: PathBuf,
pub candidates: Vec<PluginManagedCandidate>,
pub rejected: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PluginMarketplaceInstallPlan {
Supported { spec: String, source_kind: String },
Unsupported { reason: String },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginMarketplaceCandidate {
pub name: String,
pub display_name: Option<String>,
pub version: Option<String>,
pub tier: String,
pub compatibility: Option<String>,
pub install_plan: PluginMarketplaceInstallPlan,
pub description: Option<String>,
pub homepage: Option<String>,
pub repository: Option<String>,
pub author: Option<String>,
pub license: Option<String>,
pub keywords: Vec<String>,
pub when: Option<String>,
pub diagnostics: Vec<PluginDiagnostic>,
pub has_errors: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginMarketplaceCatalog {
pub id: String,
pub source_path: Option<String>,
pub display_name: Option<String>,
pub description: Option<String>,
pub format: String,
pub tier: String,
pub publisher: Option<String>,
pub total_candidates: usize,
pub warning_count: usize,
pub candidates: Vec<PluginMarketplaceCandidate>,
pub diagnostics: Vec<PluginDiagnostic>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginMarketplaceAddReceipt {
pub name: String,
pub candidate_count: usize,
pub warning_count: usize,
pub catalog: PluginMarketplaceCatalog,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginMarketplaceState {
pub official: Option<PluginMarketplaceCatalog>,
pub stored: Vec<PluginMarketplaceCatalog>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginSuggestion {
pub name: String,
pub state_label: String,
pub description: String,
pub why: Vec<String>,
pub next_step: String,
}
pub trait CommandPluginContext {
fn summaries(&self) -> Result<Vec<PluginSummary>, String>;
fn detail(&self, selector: &str) -> Result<PluginDetail, String>;
fn registry_diagnostics(&self) -> Vec<PluginDiagnostic>;
fn validation_is_clean(&self) -> bool;
fn len(&self) -> usize;
fn reload(&mut self) -> Result<usize, String>;
fn is_empty(&self) -> bool;
fn reload_nudge(&mut self) -> Option<String>;
fn state_path(&self) -> Option<PathBuf>;
fn suggest(&self, task: &str) -> Result<Vec<PluginSuggestion>, String>;
fn trust(&mut self, selector: &str, token: &str) -> Result<(), String>;
fn enable(&mut self, selector: &str) -> Result<(), String>;
fn disable(&mut self, selector: &str) -> Result<(), String>;
fn revoke_trust(&mut self, selector: &str) -> Result<(), String>;
fn install(
&mut self,
source: &str,
expected_content_hash: Option<&str>,
) -> Result<PluginMutationReceipt, String>;
fn update(&mut self, selector: &str) -> Result<PluginMutationReceipt, String>;
fn uninstall(&mut self, selector: &str) -> Result<PluginMutationReceipt, String>;
fn uninstall_path(&mut self, name: &str, plugins_dir: &Path) -> Result<(), String>;
fn export(&self, selector: &str, target: &Path) -> Result<PluginExportReceipt, String>;
fn legacy_scan(&self) -> Result<Option<PluginLegacyScan>, String>;
fn managed_scan(&self, home_override: Option<&Path>) -> Result<PluginManagedScan, String>;
fn managed_install(
&mut self,
canonical_path: &Path,
expected_content_hash: &str,
) -> Result<PluginMutationReceipt, String>;
fn marketplace_state(&self) -> Result<PluginMarketplaceState, String>;
fn marketplace_add(
&mut self,
name: &str,
path: &Path,
) -> Result<PluginMarketplaceAddReceipt, String>;
fn marketplace_remove(&mut self, name: &str) -> Result<bool, String>;
fn marketplace_install(
&mut self,
catalog: &str,
candidate: &str,
) -> Result<PluginMutationReceipt, String>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SkillSourceKind {
Native,
Plugin {
plugin_name: String,
plugin_id: String,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SkillBundledTier {
CoreAgentic,
FormatTooling,
}
impl SkillBundledTier {
#[must_use]
pub fn heading(self) -> &'static str {
match self {
Self::CoreAgentic => "Core agentic",
Self::FormatTooling => "Format & tooling",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkillEntry {
pub name: String,
pub description: String,
pub source: SkillSourceKind,
pub path: Option<String>,
pub bundled_tier: Option<SkillBundledTier>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkillRegistryProjection {
pub workspace: String,
pub skills_dir: String,
pub mode_label: String,
pub dirs: Vec<String>,
pub entries: Vec<SkillEntry>,
pub warnings: Vec<String>,
pub total: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SkillTargetScope {
Project,
Global,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SkillMutationOutcome {
Installed,
Updated,
NoChange,
Removed,
Trusted,
Imported,
AlreadyPresent,
NeedsApproval(String),
NetworkDenied(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkillMutationReceipt {
pub name: String,
pub safe_target_path: String,
pub outcome: SkillMutationOutcome,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RemoteSkillEntry {
pub name: String,
pub description: Option<String>,
pub source: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RemoteRegistryOutcome {
Loaded { entries: Vec<RemoteSkillEntry> },
NeedsApproval(String),
Denied(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkillRecommendation {
pub name: String,
pub description: Option<String>,
pub matched_terms: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SkillSyncEntry {
Downloaded { name: String, path: String },
Fresh { name: String },
Failed { name: String, reason: String },
Denied { name: String, host: String },
NeedsApproval { name: String, host: String },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SkillSyncOutcome {
Done {
total: usize,
downloaded: usize,
fresh: usize,
failed: usize,
entries: Vec<SkillSyncEntry>,
},
RegistryNeedsApproval(String),
RegistryDenied(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkillActivationOutcome {
pub name: String,
pub description: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SkillActivationError {
NotFound {
requested: String,
available: Vec<String>,
warnings: Vec<String>,
},
PluginRejected {
name: String,
reason: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ReviewOutcome {
Ready,
NotFound {
skills_dir: String,
global_dir: String,
warnings: Vec<String>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SnapshotEntry {
pub id: String,
pub label: String,
pub timestamp: i64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CommandApprovalState {
pub yolo: bool,
pub trust_mode: bool,
}
pub trait CommandSkillGroupContext {
fn skill_registry_projection(&self) -> SkillRegistryProjection;
fn activate_skill(
&mut self,
name: &str,
) -> Result<SkillActivationOutcome, SkillActivationError>;
fn install_skill(
&mut self,
scope: Option<SkillTargetScope>,
spec: &str,
) -> Result<SkillMutationReceipt, String>;
fn update_skill(
&mut self,
scope: Option<SkillTargetScope>,
name: &str,
) -> Result<SkillMutationReceipt, String>;
fn uninstall_skill(
&mut self,
scope: Option<SkillTargetScope>,
name: &str,
) -> Result<SkillMutationReceipt, String>;
fn trust_skill(
&mut self,
scope: Option<SkillTargetScope>,
name: &str,
) -> Result<SkillMutationReceipt, String>;
fn fetch_remote_registry(&mut self) -> Result<RemoteRegistryOutcome, String>;
fn recommend_skills(&mut self, task: &str) -> Result<Vec<SkillRecommendation>, String>;
fn sync_registry(&mut self) -> Result<SkillSyncOutcome, String>;
fn run_review(&mut self) -> Result<ReviewOutcome, String>;
fn snapshot_list(&mut self, limit: usize) -> Result<Vec<SnapshotEntry>, String>;
fn restore_snapshot(&mut self, id: &str) -> Result<(), String>;
fn approval_state(&self) -> CommandApprovalState;
}