返回 CodeWhale
rlm.rs
根目录 / crates / tui / src / commands / groups / core / rlm.rs
1 //! `/rlm` command.
2
3 use codewhale_command_contract::handler::{CommandCapabilities, CommandContexts, CommandHandler};
4 use codewhale_command_contract::metadata::{CommandInfo, RegisterCommand};
5 use codewhale_command_contract::navigation::WorkspaceTarget;
6 use codewhale_command_contract::outcome::{CommandResult, CoreAction};
7
8 const COMMAND_INFO: CommandInfo = CommandInfo {
9 name: "rlm",
10 aliases: &["recursive", "digui"],
11 usage: "/rlm [N] <file_or_text>",
12 description_key: "cmd_rlm_description",
13 };
14
15 pub(super) struct RlmCmd;
16
17 impl<A: From<CoreAction>> RegisterCommand<CommandResult<A>> for RlmCmd {
18 fn info() -> &'static CommandInfo {
19 &COMMAND_INFO
20 }
21
22 fn handler() -> CommandHandler<CommandResult<A>> {
23 CommandHandler::Contextual {
24 capabilities: CommandCapabilities::WORKSPACE,
25 handler: rlm,
26 }
27 }
28 }
29
30 fn rlm<A: From<CoreAction>>(contexts: CommandContexts<'_>, arg: Option<&str>) -> CommandResult<A> {
31 let (_legacy_depth, target) = match super::util::parse_depth_prefixed_arg(arg, 1) {
32 Ok(parsed) => parsed,
33 Err(message) => return CommandResult::error(message),
34 };
35 let target = match target {
36 Some(p) if !p.trim().is_empty() => p.trim().to_string(),
37 _ => {
38 return CommandResult::error(
39 "Usage: /rlm [N] <file_or_text>\n\n\
40 Works through a large file or block of text in a context that \
41 stays loaded for the rest of the session."
42 .to_string(),
43 );
44 }
45 };
46
47 let Some(workspace) = contexts.into_parts().workspace else {
48 return CommandResult::error("Command capability unavailable: workspace");
49 };
50 let candidate = workspace.workspace().join(&target);
51 let source = if workspace.inspect_workspace_target(&candidate) == WorkspaceTarget::File {
52 format!("the workspace file `{target}`")
53 } else {
54 format!("this text: {target:?}")
55 };
56 let message = format!(
57 "Call the `rlm` tool for this request. Work on {source}: call `open` with `file_path` or `content`, inspect it with `eval`, and finish with `close`."
58 );
59
60 CommandResult::with_message_and_action(
61 "Loading that into a persistent working context...".to_string(),
62 CoreAction::SendMessage(message).into(),
63 )
64 }
65
65 lines RUST