Skip to content

Define RuntimeTool trait for code-execution backends (Python, Node, dotnet, go, rustc) #1822

@aboimpinto

Description

@aboimpinto

Parent: #1802 — Pluggable Tool Registry

Sub-issue 3 of the Pluggable Tool Registry tracking issue.


Goal

Define a RuntimeTool trait that makes code-execution backends (Python, Node.js, dotnet, go, rustc) pluggable through a shared interface compatible with the ToolSpec trait and the ExternalTool abstraction (PR #1821).

Today code_execution hardcodes Python, js_execution hardcodes Node. Adding dotnet (already implemented as DotNet ExternalTool in PR #1821) requires touching the tool catalog, the dispatcher, and the execution path.

After RuntimeTool:

  • Each runtime implements one trait.
  • The catalog auto-discovers available runtimes.
  • Adding go or rustc is ~15 lines of impl RuntimeTool.
  • The model sees code_execution with a runtime parameter (or separate tool names per runtime — TBD).

Design sketch

/// A code-execution backend discoverable via ExternalTool + ToolSpec.
#[async_trait]
pub trait RuntimeTool: ExternalTool + Send + Sync {
    /// Human-readable runtime name (e.g. "Python", "Node.js", "dotnet").
    fn runtime_name() -> &'static str;

    /// File extension for this runtime (e.g. "py", "js", "cs").
    fn file_extension() -> &'static str;

    /// Default code template — wraps user code for this runtime.
    fn wrap_code(code: &str) -> String;

    /// Execute code with this runtime. Returns stdout/stderr/exit code.
    async fn execute(code: &str, timeout: Duration, cwd: &Path) -> RuntimeResult;
}

Callers (tool catalog, dispatcher) interact through the trait, not through individual Command::new("python3") / Command::new("node") calls.


Backends to implement

Runtime Status Notes
Python Already exists (Python ExternalTool + code_execution.rs) Refactor to impl RuntimeTool
Node.js Already exists (Node ExternalTool + js_execution.rs) Refactor to impl RuntimeTool
dotnet DotNet ExternalTool in PR #1821, dotnet_execution.rs tool Refactor to impl RuntimeTool
Go Done New: go run via RuntimeTool
Rust (rustc) Done New: rustc with temp project
TypeScript Done New: tsx/ts-node/deno via RuntimeTool

Dependencies


Delivery

PR #1845 delivers:

  • RuntimeTool trait in crates/tui/src/tools/runtime_tool.rs
  • go_execution — Go sandbox via go run file.go
  • ts_execution — TypeScript sandbox (tsx/tsx.cmd/ts-node/deno)
  • rust_execution — Rust sandbox via rustc compile-then-run
  • Windows .cmd probe fix for npm global installs
  • All existing tools continue working

Closes #1822

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttoolsTool execution, tool schemas, tool UX, and built-in tool behaviorv0.9.0Targeting v0.9.0

    Projects

    Status
    In progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions