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(&mut self, amount: f64, currency: CommandCurrency, route_receipt: bool);
43}
44
45/// Operating mode, approval posture, shell access, and policy lock.
46pub trait CommandModePolicyContext {
47    fn mode(&self) -> CommandMode;
48    fn set_mode(&mut self, mode: CommandMode);
49    fn approval_mode(&self) -> CommandApprovalMode;
50    fn allow_shell(&self) -> bool;
51    fn set_shell_access(&mut self, allow: bool);
52    fn policy_locked(&self) -> bool;
53}
54
55/// Read access to the effective system prompt.
56pub trait CommandSystemPromptContext {
57    fn system_prompt(&self) -> Option<SystemPrompt>;
58}
59
60/// Active skill identity and skill-cache refresh.
61pub trait CommandSkillsContext {
62    fn active_skill(&self) -> Option<String>;
63    fn active_skill_provenance(&self) -> Option<String>;
64    fn refresh_skill_cache(&mut self);
65}
66
67/// Workspace path and a bounded serialized work-state snapshot.
68pub trait CommandWorkspaceContext {
69    fn workspace(&self) -> PathBuf;
70    fn work_state_snapshot(&self) -> Result<Option<String>, String>;
71}