Skip to main content

codewhale_command_contract/
facets.rs

1//! Independent, object-safe capability shapes for staged command migration.
2//!
3//! FEAT-014 publishes these interfaces without implementing them for the TUI
4//! or changing an existing command. Later work adopts them inside
5//! `codewhale-tui` one command group at a time. Only after every group uses
6//! these shapes will groups move physically into a commands crate.
7
8use std::path::PathBuf;
9
10use codewhale_core::request::{Message, SystemPrompt};
11
12use crate::types::{
13    CommandApprovalMode, CommandCurrency, CommandMode, CommandProviderId, CommandReasoningEffort,
14};
15
16/// Session identity, messages, queue operations, and token totals.
17pub trait CommandSessionContext {
18    fn session_id(&self) -> Option<String>;
19    fn api_messages(&self) -> Vec<Message>;
20    fn add_message(&mut self, message: Message);
21    fn queued_message_count(&self) -> usize;
22    fn remove_queued_message(&mut self, index: usize) -> Result<(), String>;
23    fn total_tokens(&self) -> u64;
24}
25
26/// Model selection, provider identity, effort, and fallback chain.
27pub trait CommandModelContext {
28    fn current_model(&self) -> String;
29    fn auto_model(&self) -> bool;
30    fn set_model_selection(&mut self, model: String, provider: Option<CommandProviderId>);
31    fn reasoning_effort(&self) -> CommandReasoningEffort;
32    fn provider_identity(&self) -> Option<CommandProviderId>;
33    fn fallback_chain(&self) -> Vec<CommandProviderId>;
34}
35
36/// Cost display and accounting operations.
37pub trait CommandCostContext {
38    fn display_currency(&self) -> CommandCurrency;
39    fn session_cost_for_currency(&self, currency: CommandCurrency) -> f64;
40    fn subagent_cost_for_currency(&self, currency: CommandCurrency) -> f64;
41    fn accrue_cost_estimate(&mut self, amount: f64, currency: CommandCurrency);
42    fn record_turn_cost(
43        &mut self,
44        amount: f64,
45        currency: CommandCurrency,
46        route_receipt: Option<String>,
47    );
48}
49
50/// Operating mode, approval posture, shell access, and policy lock.
51pub trait CommandModePolicyContext {
52    fn mode(&self) -> CommandMode;
53    fn set_mode(&mut self, mode: CommandMode);
54    fn approval_mode(&self) -> CommandApprovalMode;
55    fn allow_shell(&self) -> bool;
56    fn set_shell_access(&mut self, allow: bool);
57    fn policy_locked(&self) -> bool;
58}
59
60/// Read access to the effective system prompt.
61pub trait CommandSystemPromptContext {
62    fn system_prompt(&self) -> Option<SystemPrompt>;
63}
64
65/// Active skill identity and skill-cache refresh.
66pub trait CommandSkillsContext {
67    fn active_skill(&self) -> Option<String>;
68    fn active_skill_provenance(&self) -> Option<String>;
69    fn refresh_skill_cache(&mut self);
70}
71
72/// Workspace path and a bounded serialized work-state snapshot.
73pub trait CommandWorkspaceContext {
74    fn workspace(&self) -> PathBuf;
75    fn work_state_snapshot(&self) -> Result<Option<String>, String>;
76}