MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / run_bash_mode_command

Function run_bash_mode_command

src/services/bash_mode.py:49–93  ·  view source on GitHub ↗

Execute ``command`` via the direct Bash path; never raises.

(command: str, tool_context: Any)

Source from the content-addressed store, hash-verified

47
48
49def run_bash_mode_command(command: str, tool_context: Any) -> BashModeOutcome:
50 """Execute ``command`` via the direct Bash path; never raises."""
51
52 command = (command or "").strip()
53 if not command:
54 return BashModeOutcome(
55 command="", ok=False, error="Usage: !<shell command>"
56 )
57
58 input_text = f"<{BASH_INPUT_TAG}>{command}</{BASH_INPUT_TAG}>"
59 try:
60 from src.tool_system.tools.bash.bash_tool import _bash_call
61
62 result = _bash_call({"command": command}, tool_context)
63 output = result.output if isinstance(result.output, dict) else {}
64 stdout = str(output.get("stdout", "") or "")
65 stderr = str(output.get("stderr", "") or "")
66 exit_code = int(output.get("exit_code", 0) or 0)
67 ok = not bool(result.is_error) and exit_code == 0
68 out_text = (
69 f"<{BASH_STDOUT_TAG}>{escape(stdout)}</{BASH_STDOUT_TAG}>"
70 f"<{BASH_STDERR_TAG}>{escape(stderr)}</{BASH_STDERR_TAG}>"
71 )
72 return BashModeOutcome(
73 command=command,
74 stdout=stdout,
75 stderr=stderr,
76 exit_code=exit_code,
77 ok=ok,
78 conversation_texts=(input_text, out_text),
79 )
80 except Exception as exc:
81 # TS error path: `<bash-stderr>Command failed: …</bash-stderr>`.
82 message = f"Command failed: {exc}"
83 out_text = (
84 f"<{BASH_STDERR_TAG}>{escape(message)}</{BASH_STDERR_TAG}>"
85 )
86 return BashModeOutcome(
87 command=command,
88 stderr=message,
89 exit_code=-1,
90 ok=False,
91 error=str(exc),
92 conversation_texts=(input_text, out_text),
93 )
94
95
96__all__ = [

Callers

nothing calls this directly

Calls 3

_bash_callFunction · 0.90
BashModeOutcomeClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected