MCPcopy Create free account
hub / github.com/Work-Fisher/code-claw / run_command

Method run_command

claw-code/rust/crates/runtime/src/hooks.rs:152–205  ·  view source on GitHub ↗
(
        &self,
        command: &str,
        event: HookEvent,
        tool_name: &str,
        tool_input: &str,
        tool_output: Option<&str>,
        is_error: bool,
        payload: &str,
 

Source from the content-addressed store, hash-verified

150 }
151
152 fn run_command(
153 &self,
154 command: &str,
155 event: HookEvent,
156 tool_name: &str,
157 tool_input: &str,
158 tool_output: Option<&str>,
159 is_error: bool,
160 payload: &str,
161 ) -> HookCommandOutcome {
162 let mut child = shell_command(command);
163 child.stdin(std::process::Stdio::piped());
164 child.stdout(std::process::Stdio::piped());
165 child.stderr(std::process::Stdio::piped());
166 child.env("HOOK_EVENT", event.as_str());
167 child.env("HOOK_TOOL_NAME", tool_name);
168 child.env("HOOK_TOOL_INPUT", tool_input);
169 child.env("HOOK_TOOL_IS_ERROR", if is_error { "1" } else { "0" });
170 if let Some(tool_output) = tool_output {
171 child.env("HOOK_TOOL_OUTPUT", tool_output);
172 }
173
174 match child.output_with_stdin(payload.as_bytes()) {
175 Ok(output) => {
176 let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
177 let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
178 let message = (!stdout.is_empty()).then_some(stdout);
179 match output.status.code() {
180 Some(0) => HookCommandOutcome::Allow { message },
181 Some(2) => HookCommandOutcome::Deny { message },
182 Some(code) => HookCommandOutcome::Warn {
183 message: format_hook_warning(
184 command,
185 code,
186 message.as_deref(),
187 stderr.as_str(),
188 ),
189 },
190 None => HookCommandOutcome::Warn {
191 message: format!(
192 "{} hook `{command}` terminated by signal while handling `{tool_name}`",
193 event.as_str()
194 ),
195 },
196 }
197 }
198 Err(error) => HookCommandOutcome::Warn {
199 message: format!(
200 "{} hook `{command}` failed to start for `{tool_name}`: {error}",
201 event.as_str()
202 ),
203 },
204 }
205 }
206}
207
208enum HookCommandOutcome {

Callers 1

run_commandsMethod · 0.80

Calls 8

shell_commandFunction · 0.85
format_hook_warningFunction · 0.85
stdinMethod · 0.80
stdoutMethod · 0.80
stderrMethod · 0.80
envMethod · 0.80
output_with_stdinMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected