pub use crate::config_policy::{CommandConfigStatusContext, CommandPermissionsContext};
use std::path::{Path, PathBuf};
mod session_structcopy;
pub use session_structcopy::*;
mod debug_operations;
pub mod debug_receipts;
pub use debug_operations::*;
pub use debug_receipts::*;
mod diagnostics_report;
mod diagnostics_tools;
pub use diagnostics_report::*;
pub use diagnostics_tools::*;
use codewhale_protocol::request::{Message, SystemPrompt};
use serde_json::Value;
use crate::types::{CommandApprovalMode, CommandCurrency, CommandMode, CommandProviderId};
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 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;
fn select_mode(&mut self, mode: CommandMode) -> CommandModeSelection;
fn select_yolo_compat(&mut self) -> CommandModeSelection;
fn mode_startup_default_receipt(&self, mode: CommandMode) -> String;
fn setting_locked_mode_message(&self) -> String;
fn mode_label(&self, mode: CommandMode) -> String;
fn yolo_compat_label(&self) -> String;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandModeSelection {
Changed,
PersistedSame,
Refused,
}
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 effective_home_dir(&self) -> Option<PathBuf>;
fn inspect_workspace_target(&self, candidate: &Path) -> crate::navigation::WorkspaceTarget;
fn read_anchor_document(&self) -> Result<Option<String>, String>;
fn append_anchor_bytes(
&mut self,
parts: &[&[u8]],
) -> Result<PathBuf, crate::navigation::AnchorWriteError>;
fn replace_anchor_document(&mut self, bytes: &[u8]) -> Result<(), String>;
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>;
fn language_name(&self) -> &'static str {
"English"
}
}
#[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, PartialEq, Eq)]
pub struct DebugBalanceProjection {
pub provider_display_name: String,
pub supports_balance_api: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DebugSystemPrompt {
None,
Text(String),
Blocks(Vec<String>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DebugSystemProjection {
pub mode_label: String,
pub prompt: DebugSystemPrompt,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DebugTokenProjection {
pub active_context_used: usize,
pub context_window: u32,
pub last_input: Option<u32>,
pub last_output: Option<u32>,
pub cache_hit: Option<u32>,
pub cache_miss: Option<u32>,
pub total_tokens: u64,
pub cache_write_tokens: u64,
pub api_message_count: usize,
pub chat_message_count: usize,
pub model: String,
pub cost: DebugCostProjection,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DebugCostProjection {
pub currency: CommandCurrency,
pub total: f64,
pub parent_turns: f64,
pub subagents: f64,
pub display_floor: f64,
pub priced_turns: u32,
pub unpriced_turns: u32,
pub legacy_coverage_unknown: bool,
pub user_declared_estimates: bool,
pub itemized_turns: u32,
pub route_amounts: Vec<DebugRouteCost>,
pub turn_history_capacity: usize,
pub unpriced_reason_labels: Vec<String>,
pub unpriced_classes: Vec<String>,
pub pricing_provenances: Vec<String>,
pub live_pricing_defects: Vec<String>,
pub unusable_pricing_defects: Vec<String>,
pub route_receipts: Vec<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DebugRouteCost {
pub route: String,
pub amount: f64,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct DebugPromptLayer {
pub name: String,
pub stability: DebugPromptLayerStability,
pub char_len: usize,
pub byte_len: usize,
pub token_estimate: usize,
pub sha256: String,
pub tool_result: Option<DebugToolResultInspection>,
pub turn_meta: Option<DebugTurnMetaInspection>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
pub enum DebugPromptLayerStability {
Static,
History,
Dynamic,
}
impl DebugPromptLayerStability {
pub const fn label(self) -> &'static str {
match self {
Self::Static => "static",
Self::History => "history",
Self::Dynamic => "dynamic",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct DebugToolResultInspection {
pub original_chars: usize,
pub sent_chars: usize,
pub truncated: bool,
pub deduplicated: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct DebugTurnMetaInspection {
pub original_chars: usize,
pub sent_chars: usize,
pub deduplicated: bool,
pub sha256: String,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct DebugPromptInspection {
pub base_static_prefix_hash: String,
pub full_request_prefix_hash: String,
pub tool_catalog_hash: String,
pub layers: Vec<DebugPromptLayer>,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct DebugWarmupKey {
pub provider: String,
pub model: String,
pub base_url: String,
pub static_prefix_hash: String,
pub tool_catalog_hash: String,
pub project_pack_hash: String,
pub skills_hash: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DebugCacheInspectionObservation {
pub current: DebugPromptInspection,
pub previous: Option<DebugPromptInspection>,
pub current_warmup_key: DebugWarmupKey,
pub last_warmup_key: Option<DebugWarmupKey>,
pub current_warmup_hash_short: String,
pub last_warmup_hash_short: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DebugCacheInspectionUnavailable {
NoConcreteRoute,
MissingCapturedEndpoint,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DebugCacheTurn {
pub provider: Option<String>,
pub provider_identity: Option<String>,
pub model: Option<String>,
pub auto_model: bool,
pub input_tokens: u32,
pub output_tokens: u32,
pub cache_hit_tokens: Option<u32>,
pub cache_miss_tokens: Option<u32>,
pub cache_write_tokens: Option<u32>,
pub reasoning_tokens: Option<u32>,
pub reasoning_replay_tokens: Option<u32>,
pub priced_amount: Option<f64>,
pub unpriced_reason_key: Option<String>,
pub unpriced_reason_sort_rank: Option<u8>,
pub unpriced_classes: Vec<String>,
pub priced_cache_read: u64,
pub priced_cache_miss: u64,
pub priced_cache_write: u64,
pub age_seconds: u64,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct DebugCacheRates {
pub parent: Option<u8>,
pub agents: Option<u8>,
pub combined: Option<u8>,
}
impl DebugCacheRates {
#[must_use]
pub fn labelled(&self, parent: &str, agents: &str, combined: &str) -> Option<String> {
match (self.parent, self.agents) {
(Some(pct), None) => Some(format!("{pct}%")),
(None, None) => None,
_ => Some(
[
(parent, self.parent),
(agents, self.agents),
(combined, self.combined),
]
.into_iter()
.filter_map(|(word, pct)| pct.map(|pct| format!("{word} {pct}%")))
.collect::<Vec<_>>()
.join(" · "),
),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct DebugCacheTelemetry {
pub model: String,
pub session_cache_rates: DebugCacheRates,
pub history: Vec<DebugCacheTurn>,
pub history_capacity: usize,
pub prefix_stability_pct: Option<u32>,
pub prefix_checks_total: u64,
pub prefix_change_count: u64,
pub prefix_drift_count: u64,
pub prefix_context_updates: u64,
pub prefix_pin_reason: Option<String>,
pub prefix_last_miss_reason: Option<String>,
pub last_prefix_change_desc: Option<String>,
pub last_pinned_prefix_hash: Option<String>,
pub api_message_count: usize,
pub non_system_message_count: usize,
}
pub trait CommandDebugDiagnosticsContext {
fn balance_projection(&self) -> DebugBalanceProjection;
fn system_projection(&self) -> DebugSystemProjection;
fn token_projection(&self) -> DebugTokenProjection;
fn cost_projection(&self) -> DebugCostProjection;
fn cache_telemetry(&self) -> DebugCacheTelemetry;
fn context_source_map(&self) -> DebugPromptSourceMap;
fn prompt_context(&self) -> DebugPromptContext;
fn tool_snapshot(&self) -> Option<DebugToolSnapshot>;
fn inspect_cache(
&self,
) -> Result<DebugCacheInspectionObservation, DebugCacheInspectionUnavailable>;
fn remember_cache_inspection(&mut self, inspection: DebugPromptInspection);
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ProjectGoalStatus {
#[default]
Active,
Paused,
Complete,
Blocked,
}
#[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 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>,
pub diagnostics: Vec<PluginDiagnostic>,
}
#[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 struct PluginDshPreview {
pub package_path: PathBuf,
pub plugin_name: String,
pub source_package: Option<String>,
pub source_version: Option<String>,
pub content_hash: String,
pub skills: Vec<String>,
pub remote_servers: Vec<String>,
pub local_servers: Vec<String>,
pub network_hosts: Vec<String>,
pub native_rows: Vec<String>,
pub requires_node: bool,
pub manual_ports: Vec<String>,
pub diagnostics: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PluginMarketplaceInstallPlan {
Supported { spec: String, source_kind: String },
AlreadyPresent { selector: String, reason: 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,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct PluginSuggestionDismissals {
pub persisted: Vec<String>,
pub session: Vec<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 dsh_preview(&self, package: &Path) -> Result<PluginDshPreview, String> {
let _ = package;
Err("DeepSeek Harness import is not available in this host.".to_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>;
fn suggestion_dismissals(&self) -> Result<PluginSuggestionDismissals, String>;
fn reset_suggestion_dismissals(&mut self, name: Option<&str>) -> Result<Vec<String>, 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>,
},
InvocationRejected {
name: String,
reason: 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;
}
#[derive(Clone, Debug, PartialEq)]
pub struct SessionSyncPayload {
pub session_id: Option<String>,
pub messages: Vec<Message>,
pub system_prompt: Option<SystemPrompt>,
pub model: String,
pub workspace: PathBuf,
pub mode: CommandMode,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SessionBranchOutcome {
pub leaf_display: String,
pub journal_entries_before: usize,
pub sync: SessionSyncPayload,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SessionForkReceipt {
pub parent_label: String,
pub fork_label: String,
pub sync: SessionSyncPayload,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SessionForkFromReceipt {
pub parent_label: String,
pub fork_label: String,
pub spawn_depth: u64,
pub sync: SessionSyncPayload,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SessionSaveReceipt {
pub display_path: String,
pub truncated_id: String,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SessionNewReceipt {
pub truncated_id: String,
pub sync: SessionSyncPayload,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SessionArchiveReceipt {
pub truncated_id: String,
pub title: String,
}
#[derive(Clone, Debug, PartialEq)]
pub enum TreeBodyProjection {
Journal {
rendered: String,
},
Linear {
rendered: String,
},
EmptySession,
NoSession,
}
pub trait CommandSessionLifecycleContext {
fn transition_blocked(&self) -> bool;
fn transition_blockers(&self) -> Vec<String>;
fn branch_current_leaf_hint(&self) -> Option<String>;
fn branch_to(&mut self, entry_id: &str) -> Result<SessionBranchOutcome, String>;
fn tree_body(&self) -> Result<TreeBodyProjection, String>;
fn save_session(&mut self, explicit_path: Option<String>)
-> Result<SessionSaveReceipt, String>;
fn fork_active(&mut self) -> Result<SessionForkReceipt, String>;
fn fork_from(&mut self, session_id_or_prefix: &str) -> Result<SessionForkFromReceipt, String>;
fn fresh_session(&mut self, force: bool) -> Result<SessionNewReceipt, String>;
fn load_session(&mut self, path: &str) -> Result<PathBuf, String>;
fn open_picker(&mut self, preselected: Option<String>);
fn set_archived(
&mut self,
session_id: &str,
archived: bool,
) -> Result<SessionArchiveReceipt, String>;
fn prune_sessions(&mut self, days: u64) -> Result<usize, String>;
}
#[derive(Clone, Debug, PartialEq)]
pub struct RelayProjection {
pub compact_template: String,
pub handoff_path: String,
pub workspace: String,
pub mode: String,
pub model: String,
pub goal_objective: Option<String>,
pub goal_token_budget: Option<u32>,
pub todos: TodoProjection,
pub plan: PlanProjection,
}
#[derive(Clone, Debug, PartialEq)]
pub enum TodoProjection {
Body(String),
Unavailable,
Absent,
}
#[derive(Clone, Debug, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum PlanProjection {
Sections(PlanSections),
Busy,
Absent,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct PlanSections {
pub title: Option<String>,
pub objective: Option<String>,
pub context_summary: Option<String>,
pub explanation: Option<String>,
pub sources_used: Vec<String>,
pub critical_files: Vec<String>,
pub constraints: Vec<String>,
pub recommended_approach: Option<String>,
pub verification_plan: Option<String>,
pub risks_and_unknowns: Option<String>,
pub handoff_packet: Option<String>,
pub items: Vec<PlanStep>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PlanStepStatus {
Pending,
InProgress,
Completed,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PlanStep {
pub status: PlanStepStatus,
pub text: String,
}
#[derive(Clone, Debug, PartialEq)]
pub enum ResumeSource {
File(PathBuf),
Session {
load_path: Option<PathBuf>,
truncated_id: String,
title: String,
},
Imported(ResumeImportReceipt),
NotFound { raw: String, error: String },
}
#[derive(Clone, Debug, PartialEq)]
pub struct ResumeImportReceipt {
pub truncated_id: String,
pub entry_count: usize,
pub leaf_display: String,
pub sync: SessionSyncPayload,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SessionTitleReceipt {
pub title: String,
}
#[derive(Clone, Debug, PartialEq)]
pub struct TitleReport {
pub effective: String,
pub source: TitleSource,
}
#[derive(Clone, Debug, PartialEq)]
pub enum TitleSource {
Session,
ConfigDefault,
None,
}
#[derive(Clone, Debug, PartialEq)]
pub struct RemoteLink {
pub url: String,
pub computer_url: Option<String>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum RemoteOpenOutcome {
NoLink,
Opened { url: String },
LaunchFailed { url: String },
}
#[derive(Clone, Debug, PartialEq)]
pub struct RemoteStartInfo {
pub connecting: bool,
}
#[derive(Clone, Debug, PartialEq)]
pub struct HostedWorkTarget {
pub url: String,
pub repo: String,
pub branch: String,
}
pub trait CommandSessionControlContext {
fn transition_blocked(&self) -> bool;
fn transition_blockers(&self) -> Vec<String>;
fn relay_projection(&self) -> RelayProjection;
fn open_resume_picker(&mut self);
fn resolve_resume_source(&mut self, raw: &str) -> Result<ResumeSource, String>;
fn import_session_file(&mut self, path: PathBuf) -> Result<ResumeImportReceipt, String>;
fn sanitize_session_title(&self, raw_title: &str) -> String;
fn rename_session(&mut self, title: &str) -> Result<SessionTitleReceipt, String>;
fn title_report(&self) -> TitleReport;
fn set_window_title(&mut self, title: String) -> Result<(), String>;
fn clear_window_title(&mut self) -> Result<(), String>;
fn composer_color(&self) -> Option<String>;
fn set_composer_color(&mut self, color: Option<String>) -> Result<(), String>;
fn remote_status(&self) -> String;
fn remote_link(&self) -> Option<RemoteLink>;
fn remote_browser_open(&self) -> RemoteOpenOutcome;
fn remote_start_info(&self) -> RemoteStartInfo;
fn remote_stop_refusal(&self) -> Option<String>;
fn resolve_hosted_work_target(&self) -> Option<HostedWorkTarget>;
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ExportMetadata {
pub session_label: String,
pub provider: String,
pub model: String,
pub mode: String,
pub workspace_name: String,
pub message_count: usize,
pub exported_at_unix: i64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ToolCallerProjection {
pub caller_type: String,
pub tool_id: Option<String>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum ExportBlock {
Text {
text: String,
},
ImageReference {
url: String,
},
ImageOmitted,
InternalReasoning,
ToolCall {
id: String,
name: String,
caller: Option<ToolCallerProjection>,
input: Value,
},
ToolResult {
tool_use_id: String,
content: String,
is_error: bool,
structured: Option<Value>,
},
ServerToolCall {
id: String,
name: String,
input: Value,
},
ToolSearchResult {
tool_use_id: String,
content: Value,
},
CodeExecutionResult {
tool_use_id: String,
content: Value,
},
}
#[derive(Clone, Debug, PartialEq)]
pub struct ExportMessage {
pub role: String,
pub is_user_role: bool,
pub blocks: Vec<ExportBlock>,
pub prompt_snippet: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum HistoryEntry {
Sanitized { role: String, body: String },
Literal { role: String, body: String },
}
#[derive(Clone, Debug, PartialEq)]
pub enum TranscriptProjection {
Authoritative(Vec<ExportMessage>),
HistoryFallback(Vec<HistoryEntry>),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RestoreSnapshot {
pub id: String,
pub label: String,
pub timestamp_unix: i64,
pub kind: String,
pub sequence: Option<u64>,
pub prompt_snippet: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum RestorePointProjection {
None,
Unreadable { reason: String },
Recorded { snapshots: Vec<RestoreSnapshot> },
}
#[derive(Clone, Debug, PartialEq)]
pub struct ConversationExportProjection {
pub metadata: ExportMetadata,
pub transcript: TranscriptProjection,
pub restore_points: RestorePointProjection,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TurnHandoffProjection {
pub markdown: String,
pub workspace_path: String,
}
pub trait CommandSessionExportContext {
fn conversation_projection(&self) -> ConversationExportProjection;
fn turn_handoff_projection(&self) -> TurnHandoffProjection;
fn clipboard_requires_terminal_paste(&self) -> bool;
fn write_recovery_copy(&self, markdown: &str) -> Option<PathBuf>;
fn write_clipboard(&self, markdown: &str) -> Result<(), String>;
fn resolve_export_path(&self, raw: &str) -> Result<PathBuf, String>;
fn write_export_file(&self, path: &Path, contents: &[u8], force: bool) -> Result<(), String>;
}