| 1 | //! `/purge` command. |
| 2 | |
| 3 | use super::CommandResult; |
| 4 | |
| 5 | pub(in crate::commands) struct PurgeCmd; |
| 6 | |
| 7 | // --------------------------------------------------------------------------- |
| 8 | // FEAT-023 Phase 4 (D3/D6): portable pure registration. `/purge` emits the |
| 9 | // existing receipt + action with no host context bundle; any argument is |
| 10 | // ignored exactly like the baseline. |
| 11 | // --------------------------------------------------------------------------- |
| 12 | |
| 13 | use codewhale_command_contract::handler::CommandHandler; |
| 14 | use codewhale_command_contract::metadata::{ |
| 15 | CommandInfo as ContractInfo, RegisterCommand as ContractRegisterCommand, |
| 16 | }; |
| 17 | |
| 18 | use crate::tui::app::AppAction; |
| 19 | |
| 20 | pub(in crate::commands) const CONTRACT_INFO: ContractInfo = ContractInfo { |
| 21 | name: "purge", |
| 22 | aliases: &["qingchu"], |
| 23 | usage: "/purge", |
| 24 | description_key: "cmd_purge_description", |
| 25 | }; |
| 26 | |
| 27 | impl ContractRegisterCommand<CommandResult> for PurgeCmd { |
| 28 | fn info() -> &'static ContractInfo { |
| 29 | &CONTRACT_INFO |
| 30 | } |
| 31 | |
| 32 | fn handler() -> CommandHandler<CommandResult> { |
| 33 | CommandHandler::Pure(purge_pure) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /// Pure `/purge` — byte-identical to the baseline `session::purge`. |
| 38 | pub(in crate::commands) fn purge_pure(_arg: Option<&str>) -> CommandResult { |
| 39 | CommandResult::with_message_and_action( |
| 40 | "Agent context purge triggered...".to_string(), |
| 41 | AppAction::PurgeContext, |
| 42 | ) |
| 43 | } |
| 44 | |
| 45 | #[cfg(test)] |
| 46 | mod tests { |
| 47 | use super::*; |
| 48 | use crate::tui::app::AppAction; |
| 49 | |
| 50 | #[test] |
| 51 | fn pure_purge_matches_baseline_receipt() { |
| 52 | let result = purge_pure(Some("ignored")); |
| 53 | assert_eq!( |
| 54 | result.message.as_deref(), |
| 55 | Some("Agent context purge triggered...") |
| 56 | ); |
| 57 | assert!(matches!(result.action, Some(AppAction::PurgeContext))); |
| 58 | assert!(!result.is_error); |
| 59 | } |
| 60 | } |
| 61 |