返回 CodeWhale
mod.rs
根目录 / crates / tui / src / commands / groups / session / mod.rs
1 //! Portable session command group. Host observations, registration and action
2 //! execution live outside this complete source closure.
3
4 use codewhale_command_contract::handler::CommandHandler;
5 use codewhale_command_contract::metadata::{CommandInfo, RegisterCommand};
6 use codewhale_command_contract::outcome::SessionCommandResult as CommandResult;
7
8 pub(in crate::commands) mod branch;
9 pub(in crate::commands) mod color;
10 pub(in crate::commands) mod compact;
11 pub(in crate::commands) mod export;
12 pub(in crate::commands) mod export_html;
13 pub(in crate::commands) mod export_json;
14 pub(in crate::commands) mod fork;
15 pub(in crate::commands) mod load;
16 pub(in crate::commands) mod new;
17 pub(in crate::commands) mod purge;
18 pub(in crate::commands) mod relay;
19 pub(in crate::commands) mod remote_control;
20 pub(in crate::commands) mod remote_env;
21 pub(in crate::commands) mod rename;
22 pub(in crate::commands) mod resume;
23 pub(in crate::commands) mod save;
24 pub(in crate::commands) mod sessions;
25 pub(in crate::commands) mod structcopy;
26 pub(in crate::commands) mod title;
27 pub(in crate::commands) mod tree;
28 // Documentation-only child, retained with the established source topology.
29 #[allow(clippy::module_inception)]
30 mod session;
31
32 pub(in crate::commands) const MAX_TITLE_LEN: usize = 100;
33
34 /// The one way the lifecycle commands report a closed transition gate: the
35 /// verb, the named blockers, and the exits that actually clear them.
36 pub(in crate::commands) fn transition_blocked_message(verb: &str, blockers: &[String]) -> String {
37 let mut message = format!("Cannot {verb} while runtime work is active");
38 if blockers.is_empty() {
39 message.push('.');
40 } else {
41 message.push(':');
42 for blocker in blockers {
43 message.push_str("\n • ");
44 message.push_str(blocker);
45 }
46 }
47 // `/jobs cancel-all` only kills shell processes and answers "No running
48 // commands to cancel." for everything else, so it must not read as the
49 // exit for a turn, dispatch, compaction, or cleanup blocker. Name both
50 // exits with the scope each one actually clears.
51 message.push_str(
52 "\n\nWait for the work to finish, or stop what you can: \
53 Ctrl+C stops a running turn, and /jobs cancel-all cancels running shell jobs.",
54 );
55 message
56 }
57
58 /// Promote the no-action structcopy result to the group's action vocabulary.
59 /// The leaf itself retains its narrower, impossible-action return type.
60 pub(in crate::commands) struct StructcopyRegistration;
61 impl RegisterCommand<CommandResult> for StructcopyRegistration {
62 fn info() -> &'static CommandInfo {
63 structcopy::StructcopyCmd::info()
64 }
65 fn handler() -> CommandHandler<CommandResult> {
66 CommandHandler::Contextual {
67 capabilities: structcopy::CAPABILITIES,
68 handler: |contexts, args| {
69 let result = structcopy::execute_structcopy(contexts, args);
70 CommandResult {
71 message: result.message,
72 action: result.action.map(|impossible| match impossible {}),
73 is_error: result.is_error,
74 }
75 },
76 }
77 }
78 }
79
80 /// Complete group inventory, used by the host and independent compilation proof.
81 pub fn portable_handlers() -> [(&'static CommandInfo, CommandHandler<CommandResult>); 18] {
82 [
83 (rename::RenameCmd::info(), rename::RenameCmd::handler()),
84 (title::TitleCmd::info(), title::TitleCmd::handler()),
85 (color::ColorCmd::info(), color::ColorCmd::handler()),
86 (save::SaveCmd::info(), save::SaveCmd::handler()),
87 (fork::ForkCmd::info(), fork::ForkCmd::handler()),
88 (new::NewCmd::info(), new::NewCmd::handler()),
89 (
90 sessions::SessionsCmd::info(),
91 sessions::SessionsCmd::handler(),
92 ),
93 (load::LoadCmd::info(), load::LoadCmd::handler()),
94 (resume::ResumeCmd::info(), resume::ResumeCmd::handler()),
95 (tree::TreeCmd::info(), tree::TreeCmd::handler()),
96 (branch::BranchCmd::info(), branch::BranchCmd::handler()),
97 (compact::CompactCmd::info(), compact::CompactCmd::handler()),
98 (purge::PurgeCmd::info(), purge::PurgeCmd::handler()),
99 (relay::RelayCmd::info(), relay::RelayCmd::handler()),
100 (
101 remote_control::RemoteControlCmd::info(),
102 remote_control::RemoteControlCmd::handler(),
103 ),
104 (
105 remote_env::RemoteEnvCmd::info(),
106 remote_env::RemoteEnvCmd::handler(),
107 ),
108 (export::ExportCmd::info(), export::ExportCmd::handler()),
109 (
110 StructcopyRegistration::info(),
111 StructcopyRegistration::handler(),
112 ),
113 ]
114 }
115
116 #[cfg(test)]
117 mod control_test_support;
118 #[cfg(test)]
119 mod lifecycle_portable_tests;
120 #[cfg(test)]
121 mod lifecycle_test_support;
122
122 lines RUST