返回 CodeWhale
lane.rs
根目录 / crates / commands / src / fleet_lane / lane.rs
1 use codewhale_command_contract::fleet_lane::ControlOperationHelp;
2 use codewhale_command_contract::handler::{CommandCapabilities, CommandContexts, CommandHandler};
3 use codewhale_command_contract::metadata::{CommandInfo, RegisterCommand};
4 use codewhale_command_contract::outcome::CommandResult;
5
6 const COMMAND_INFO: CommandInfo = CommandInfo {
7 name: "lane",
8 aliases: &["lanes"],
9 usage: "/lane [list|status <lane-id>|interrupt <lane-id>|restart <lane-id>|resume <lane-id>]",
10 description_key: "cmd_lane_description",
11 };
12
13 pub struct LaneCmd;
14
15 impl<A> RegisterCommand<CommandResult<A>> for LaneCmd {
16 fn info() -> &'static CommandInfo {
17 &COMMAND_INFO
18 }
19
20 fn handler() -> CommandHandler<CommandResult<A>> {
21 CommandHandler::Contextual {
22 capabilities: CommandCapabilities::LANE,
23 handler: lane,
24 }
25 }
26 }
27
28 fn split_verb(arg: Option<&str>) -> (&str, Option<&str>) {
29 let Some(rest) = arg.map(str::trim).filter(|value| !value.is_empty()) else {
30 return ("list", None);
31 };
32 match rest.split_once(char::is_whitespace) {
33 Some((verb, tail)) => (verb, Some(tail.trim())),
34 None => (rest, None),
35 }
36 }
37
38 fn help_text(operations: &[ControlOperationHelp]) -> String {
39 let mut out = String::from(
40 "Usage: /lane [list|status <lane-id>|interrupt <lane-id>|restart <lane-id>|resume <lane-id>]\n\n\
41 A Lane is one running Workflow; Runtime owns where/how it runs. These verbs act on the \
42 durable Lane registry under $CODEWHALE_HOME/lanes/, the same records `codewhale lane` \
43 reads. Append @<lifecycle-seq> to a lane id to fence a write to the exact generation you \
44 observed.\n\n\
45 Reads here do not reconcile: folding a finished Runtime exit into the record means \
46 probing tmux and taking a lock, which would block the composer. Statuses are as last \
47 recorded — `codewhale lane list` reconciles. Interrupt is submitted to an off-loop \
48 worker and answered immediately with a queued receipt and a ticket; the terminal \
49 result (transitioned, no_change, or conflict) arrives under that ticket.\n",
50 );
51 for descriptor in operations {
52 out.push_str(&format!(
53 "\n {:<28} {:<6} {}\n CLI: {}\n",
54 descriptor.slash_invocation,
55 descriptor.authority,
56 descriptor.summary,
57 descriptor.cli_invocation
58 ));
59 }
60 out
61 }
62
63 fn lane<A>(mut contexts: CommandContexts<'_>, arg: Option<&str>) -> CommandResult<A> {
64 let (verb, target) = split_verb(arg);
65 let Some(lane_ctx) = contexts.take_lane() else {
66 return CommandResult::error("Command capability unavailable: lane");
67 };
68 if matches!(verb, "help" | "?") {
69 return CommandResult::message(help_text(&lane_ctx.control_operations()));
70 }
71 let Some(operation) = lane_ctx.resolve_control_verb(verb) else {
72 return CommandResult::error(format!(
73 "Unknown /lane verb '{verb}'. Use list, status, interrupt, restart, or resume."
74 ));
75 };
76 let receipt = lane_ctx.execute_control(operation, target);
77 if receipt.is_error {
78 CommandResult::error(receipt.rendered)
79 } else {
80 CommandResult::message(receipt.rendered)
81 }
82 }
83
83 lines RUST