zeptoclaw 0.6.2

Ultra-lightweight personal AI assistant
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
//! Binary plugin tool adapter for ZeptoClaw.
//!
//! Executes standalone plugin binaries via JSON-RPC 2.0 over stdin/stdout.
//! Each tool call spawns the binary, writes a request to stdin, reads the
//! response from stdout, and returns the result. The binary is expected
//! to exit after producing a single response.

use std::path::PathBuf;
use std::time::Duration;

use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tracing::warn;

use crate::error::{Result, ZeptoError};
use crate::plugins::types::PluginToolDef;
use crate::tools::{Tool, ToolCategory, ToolContext, ToolOutput};

// ---- JSON-RPC 2.0 types (local, not coupled to MCP) ----

#[derive(Serialize)]
struct PluginJsonRpcRequest {
    jsonrpc: String,
    id: u64,
    method: String,
    params: PluginExecuteParams,
}

#[derive(Serialize)]
struct PluginExecuteParams {
    tool: String,
    args: Value,
}

#[derive(Deserialize)]
struct PluginJsonRpcResponse {
    #[allow(dead_code)]
    jsonrpc: String,
    #[allow(dead_code)]
    id: Option<u64>,
    result: Option<PluginJsonRpcResult>,
    error: Option<PluginJsonRpcError>,
}

#[derive(Deserialize)]
struct PluginJsonRpcResult {
    output: String,
}

#[derive(Deserialize)]
struct PluginJsonRpcError {
    code: i64,
    message: String,
    #[allow(dead_code)]
    data: Option<Value>,
}

// ---- BinaryPluginTool ----

/// A tool adapter that executes a binary plugin via JSON-RPC 2.0 over stdin/stdout.
///
/// The binary is spawned on-demand for each tool call, communicating via a
/// single JSON-RPC request/response exchange. The binary is expected to:
/// 1. Read a JSON-RPC request from stdin
/// 2. Write a JSON-RPC response to stdout
/// 3. Exit
pub struct BinaryPluginTool {
    def: PluginToolDef,
    plugin_name: String,
    binary_path: PathBuf,
    timeout: Duration,
}

impl BinaryPluginTool {
    /// Create a new binary plugin tool.
    ///
    /// # Arguments
    /// * `def` - The tool definition from the plugin manifest
    /// * `plugin_name` - Name of the parent plugin
    /// * `binary_path` - Absolute, validated path to the binary
    /// * `timeout_secs` - Execution timeout in seconds
    pub fn new(
        def: PluginToolDef,
        plugin_name: impl Into<String>,
        binary_path: PathBuf,
        timeout_secs: u64,
    ) -> Self {
        Self {
            def,
            plugin_name: plugin_name.into(),
            binary_path,
            timeout: Duration::from_secs(timeout_secs),
        }
    }
}

impl std::fmt::Debug for BinaryPluginTool {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("BinaryPluginTool")
            .field("name", &self.def.name)
            .field("plugin", &self.plugin_name)
            .field("binary", &self.binary_path)
            .finish()
    }
}

#[async_trait]
impl Tool for BinaryPluginTool {
    fn name(&self) -> &str {
        &self.def.name
    }

    fn description(&self) -> &str {
        &self.def.description
    }

    fn compact_description(&self) -> &str {
        self.description()
    }

    fn category(&self) -> ToolCategory {
        ToolCategory::Shell
    }

    fn parameters(&self) -> Value {
        self.def.parameters.clone()
    }

    async fn execute(&self, args: Value, ctx: &ToolContext) -> Result<ToolOutput> {
        use tokio::io::AsyncWriteExt;
        use tokio::process::Command;

        // Build JSON-RPC request
        let request = PluginJsonRpcRequest {
            jsonrpc: "2.0".to_string(),
            id: 1,
            method: "execute".to_string(),
            params: PluginExecuteParams {
                tool: self.def.name.clone(),
                args,
            },
        };

        let request_json = serde_json::to_string(&request).map_err(|e| {
            ZeptoError::Tool(format!("Failed to serialize JSON-RPC request: {}", e))
        })?;

        // Spawn binary — no shell
        let mut cmd = Command::new(&self.binary_path);
        cmd.stdin(std::process::Stdio::piped())
            .stdout(std::process::Stdio::piped())
            .stderr(std::process::Stdio::piped());

        // Set working directory from context
        if let Some(workspace) = &ctx.workspace {
            cmd.current_dir(workspace);
        }

        // Set environment variables from tool def
        if let Some(env_vars) = &self.def.env {
            for (key, value) in env_vars {
                cmd.env(key, value);
            }
        }

        let mut child = cmd.spawn().map_err(|e| {
            ZeptoError::Tool(format!(
                "Failed to spawn binary plugin '{}' ({}): {}",
                self.plugin_name,
                self.binary_path.display(),
                e
            ))
        })?;

        // Write request to stdin and close
        if let Some(mut stdin) = child.stdin.take() {
            stdin
                .write_all(request_json.as_bytes())
                .await
                .map_err(|e| {
                    ZeptoError::Tool(format!(
                        "Failed to write to binary plugin '{}' stdin: {}",
                        self.plugin_name, e
                    ))
                })?;
            stdin.write_all(b"\n").await.ok();
            // stdin is dropped here, closing the pipe
        }

        // Wait for output with timeout
        let output = match tokio::time::timeout(self.timeout, child.wait_with_output()).await {
            Ok(Ok(output)) => output,
            Ok(Err(e)) => {
                return Err(ZeptoError::Tool(format!(
                    "Binary plugin '{}' failed: {}",
                    self.plugin_name, e
                )));
            }
            Err(_) => {
                // Timeout — the child was consumed by wait_with_output's future
                // which was dropped. Tokio drops the child handle which sends SIGKILL.
                return Err(ZeptoError::Tool(format!(
                    "Binary plugin '{}' timed out after {}s",
                    self.plugin_name,
                    self.timeout.as_secs()
                )));
            }
        };

        let stdout = String::from_utf8_lossy(&output.stdout);
        let stderr = String::from_utf8_lossy(&output.stderr);

        // Check exit code
        if !output.status.success() {
            let code = output.status.code().unwrap_or(-1);
            let err_detail = if stderr.is_empty() {
                stdout.to_string()
            } else {
                stderr.to_string()
            };
            return Err(ZeptoError::Tool(format!(
                "Binary plugin '{}' exited with code {}: {}",
                self.plugin_name,
                code,
                err_detail.trim()
            )));
        }

        // Parse JSON-RPC response from the last non-empty line of stdout
        let response_line = stdout
            .lines()
            .rev()
            .find(|line| !line.trim().is_empty())
            .unwrap_or("");

        if response_line.is_empty() {
            return Err(ZeptoError::Tool(format!(
                "Binary plugin '{}' produced no output",
                self.plugin_name
            )));
        }

        let response: PluginJsonRpcResponse = serde_json::from_str(response_line).map_err(|e| {
            ZeptoError::Tool(format!(
                "Binary plugin '{}' returned invalid JSON-RPC: {} (raw: {})",
                self.plugin_name,
                e,
                &crate::utils::string::preview(response_line, 200)
            ))
        })?;

        // Check for JSON-RPC error
        if let Some(err) = response.error {
            warn!(
                plugin = %self.plugin_name,
                code = err.code,
                "Binary plugin returned error"
            );
            return Err(ZeptoError::Tool(format!(
                "Binary plugin '{}' error (code {}): {}",
                self.plugin_name, err.code, err.message
            )));
        }

        // Extract result
        match response.result {
            Some(result) => Ok(ToolOutput::llm_only(result.output)),
            None => Err(ZeptoError::Tool(format!(
                "Binary plugin '{}' returned neither result nor error",
                self.plugin_name
            ))),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde_json::json;

    /// Returns true when running as UID 0 (root).
    ///
    /// Root bypasses file-permission execute checks on Linux, which causes
    /// permission-based tests to behave differently inside Docker containers.
    #[cfg(unix)]
    fn is_root() -> bool {
        std::process::Command::new("id")
            .arg("-u")
            .output()
            .ok()
            .and_then(|o| String::from_utf8(o.stdout).ok())
            .is_some_and(|s| s.trim() == "0")
    }

    // ---- JSON-RPC serialization tests ----

    #[test]
    fn test_jsonrpc_request_serialization() {
        let req = PluginJsonRpcRequest {
            jsonrpc: "2.0".to_string(),
            id: 1,
            method: "execute".to_string(),
            params: PluginExecuteParams {
                tool: "my_tool".to_string(),
                args: json!({"limit": 10}),
            },
        };
        let json = serde_json::to_value(&req).unwrap();
        assert_eq!(json["jsonrpc"], "2.0");
        assert_eq!(json["id"], 1);
        assert_eq!(json["method"], "execute");
        assert_eq!(json["params"]["tool"], "my_tool");
        assert_eq!(json["params"]["args"]["limit"], 10);
    }

    #[test]
    fn test_jsonrpc_response_success_deser() {
        let json_str = r#"{"jsonrpc":"2.0","result":{"output":"payment list..."},"id":1}"#;
        let resp: PluginJsonRpcResponse = serde_json::from_str(json_str).unwrap();
        assert!(resp.result.is_some());
        assert!(resp.error.is_none());
        assert_eq!(resp.result.unwrap().output, "payment list...");
    }

    #[test]
    fn test_jsonrpc_response_error_deser() {
        let json_str =
            r#"{"jsonrpc":"2.0","error":{"code":-1,"message":"API key not configured"},"id":1}"#;
        let resp: PluginJsonRpcResponse = serde_json::from_str(json_str).unwrap();
        assert!(resp.result.is_none());
        assert!(resp.error.is_some());
        let err = resp.error.unwrap();
        assert_eq!(err.code, -1);
        assert_eq!(err.message, "API key not configured");
        assert!(err.data.is_none());
    }

    #[test]
    fn test_jsonrpc_response_missing_result() {
        let json_str = r#"{"jsonrpc":"2.0","id":1}"#;
        let resp: PluginJsonRpcResponse = serde_json::from_str(json_str).unwrap();
        assert!(resp.result.is_none());
        assert!(resp.error.is_none());
    }

    #[test]
    fn test_jsonrpc_response_with_error_data() {
        let json_str = r#"{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid Request","data":{"details":"missing field"}},"id":1}"#;
        let resp: PluginJsonRpcResponse = serde_json::from_str(json_str).unwrap();
        let err = resp.error.unwrap();
        assert_eq!(err.code, -32600);
        assert!(err.data.is_some());
    }

    // ---- Tool trait tests ----

    fn test_tool_def() -> PluginToolDef {
        PluginToolDef {
            name: "my_tool".to_string(),
            description: "My test tool".to_string(),
            parameters: json!({"type": "object", "properties": {"x": {"type": "string"}}}),
            command: String::new(),
            working_dir: None,
            timeout_secs: None,
            env: None,
        }
    }

    #[test]
    fn test_tool_name() {
        let tool = BinaryPluginTool::new(
            test_tool_def(),
            "test-plugin",
            PathBuf::from("/bin/echo"),
            30,
        );
        assert_eq!(tool.name(), "my_tool");
    }

    #[test]
    fn test_tool_description() {
        let tool = BinaryPluginTool::new(
            test_tool_def(),
            "test-plugin",
            PathBuf::from("/bin/echo"),
            30,
        );
        assert_eq!(tool.description(), "My test tool");
    }

    #[test]
    fn test_tool_parameters() {
        let tool = BinaryPluginTool::new(
            test_tool_def(),
            "test-plugin",
            PathBuf::from("/bin/echo"),
            30,
        );
        let params = tool.parameters();
        assert_eq!(params["type"], "object");
        assert!(params["properties"]["x"].is_object());
    }

    // ---- Execute tests with real processes ----
    //
    // These tests create shell scripts and execute them as binary plugins.
    // We use a TempDir + explicit script file rather than NamedTempFile to
    // ensure the script is in a directory that allows execution (some CI
    // environments mount /tmp with noexec).

    #[cfg(unix)]
    fn create_test_script(content: &str) -> (tempfile::TempDir, PathBuf) {
        use std::os::unix::fs::PermissionsExt;

        let dir = tempfile::TempDir::new().unwrap();
        let script_path = dir.path().join("plugin.sh");
        std::fs::write(&script_path, format!("#!/bin/sh\n{}", content)).unwrap();
        std::fs::set_permissions(&script_path, std::fs::Permissions::from_mode(0o755)).unwrap();
        (dir, script_path)
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_success() {
        let (_dir, script_path) = create_test_script(
            r#"read input
echo '{"jsonrpc":"2.0","result":{"output":"hello world"},"id":1}'"#,
        );
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({"x": "test"}), &ctx).await;
        assert!(result.is_ok(), "Expected Ok, got: {:?}", result);
        assert_eq!(result.unwrap().for_llm, "hello world");
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_error_response() {
        let (_dir, script_path) = create_test_script(
            r#"read input
echo '{"jsonrpc":"2.0","error":{"code":-1,"message":"something broke"},"id":1}'"#,
        );
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_err());
        let err = result.unwrap_err().to_string();
        assert!(err.contains("something broke"), "err was: {}", err);
        assert!(err.contains("code -1"), "err was: {}", err);
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_non_zero_exit() {
        let (_dir, script_path) = create_test_script("cat > /dev/null\nexit 1");
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_err());
        let err = result.unwrap_err().to_string();
        assert!(err.contains("exited with code 1"), "err was: {}", err);
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_timeout() {
        let (_dir, script_path) = create_test_script("sleep 10");
        let tool = BinaryPluginTool::new(
            test_tool_def(),
            "test-plugin",
            script_path,
            1, // 1 second timeout
        );
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_err());
        let err = result.unwrap_err().to_string();
        assert!(err.contains("timed out"), "err was: {}", err);
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_malformed_json() {
        let (_dir, script_path) = create_test_script("cat > /dev/null\necho 'not json at all'");
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_err());
        let err = result.unwrap_err().to_string();
        assert!(err.contains("invalid JSON-RPC"), "err was: {}", err);
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_empty_stdout() {
        let (_dir, script_path) = create_test_script("cat > /dev/null\n# produces nothing");
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_err());
        let err = result.unwrap_err().to_string();
        assert!(err.contains("no output"), "err was: {}", err);
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_spawn_failure() {
        let tool = BinaryPluginTool::new(
            test_tool_def(),
            "test-plugin",
            PathBuf::from("/nonexistent/binary"),
            30,
        );
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_err());
        let err = result.unwrap_err().to_string();
        // Accept either our wrapped message or the OS-level error text,
        // since error propagation can differ across Docker/act environments.
        assert!(
            err.contains("Failed to spawn") || err.contains("No such file"),
            "err was: {}",
            err
        );
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_with_args() {
        let (_dir, script_path) = create_test_script(
            r#"read input
if echo "$input" | grep -q '"x"'; then
    echo '{"jsonrpc":"2.0","result":{"output":"args received"},"id":1}'
else
    echo '{"jsonrpc":"2.0","error":{"code":-1,"message":"no args"},"id":1}'
fi"#,
        );
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({"x": "hello"}), &ctx).await;
        assert!(result.is_ok(), "Expected Ok, got: {:?}", result);
        assert_eq!(result.unwrap().for_llm, "args received");
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_with_workspace() {
        let workspace = tempfile::TempDir::new().unwrap();
        let (_dir, script_path) = create_test_script(
            r#"read input
cwd=$(pwd)
echo "{\"jsonrpc\":\"2.0\",\"result\":{\"output\":\"cwd: $cwd\"},\"id\":1}""#,
        );
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new().with_workspace(workspace.path().to_str().unwrap());
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_ok(), "Expected Ok, got: {:?}", result);
        let output = result.unwrap().for_llm;
        assert!(output.contains("cwd:"), "output was: {}", output);
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_with_env() {
        let (_dir, script_path) = create_test_script(
            r#"read input
echo "{\"jsonrpc\":\"2.0\",\"result\":{\"output\":\"FOO=$MY_TEST_VAR\"},\"id\":1}""#,
        );

        let mut env = std::collections::HashMap::new();
        env.insert("MY_TEST_VAR".to_string(), "bar_value".to_string());

        let mut def = test_tool_def();
        def.env = Some(env);

        let tool = BinaryPluginTool::new(def, "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_ok(), "Expected Ok, got: {:?}", result);
        assert_eq!(result.unwrap().for_llm, "FOO=bar_value");
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_stderr_on_failure() {
        let (_dir, script_path) = create_test_script(
            r#"cat > /dev/null
echo "error details" >&2
exit 1"#,
        );
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_err());
        let err = result.unwrap_err().to_string();
        assert!(err.contains("error details"), "err was: {}", err);
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_binary_not_executable() {
        // Root (UID 0) bypasses file execute permission checks on Linux,
        // so this test cannot verify permission-denied behaviour inside
        // Docker containers where processes typically run as root.
        if is_root() {
            eprintln!("skipping test_execute_binary_not_executable: running as root");
            return;
        }

        let dir = tempfile::TempDir::new().unwrap();
        let script_path = dir.path().join("plugin.sh");
        std::fs::write(&script_path, "#!/bin/sh\necho ok").unwrap();
        // Do NOT set execute permission — leave default (0o644 on most systems)
        use std::os::unix::fs::PermissionsExt;
        std::fs::set_permissions(&script_path, std::fs::Permissions::from_mode(0o644)).unwrap();

        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_err());
        let err = result.unwrap_err().to_string();
        assert!(err.contains("Failed to spawn"), "err was: {}", err);
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_large_output() {
        let (_dir, script_path) = create_test_script(
            r#"read input
large=$(python3 -c "print('x' * 10000)" 2>/dev/null || printf 'x%.0s' $(seq 1 10000))
echo "{\"jsonrpc\":\"2.0\",\"result\":{\"output\":\"$large\"},\"id\":1}""#,
        );
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_ok(), "Expected Ok, got: {:?}", result);
        assert!(result.unwrap().for_llm.len() >= 10000);
    }

    #[cfg(unix)]
    #[tokio::test]
    async fn test_execute_extra_stdout_ignored() {
        let (_dir, script_path) = create_test_script(
            r#"read input
echo "debug: starting up"
echo "debug: processing"
echo '{"jsonrpc":"2.0","result":{"output":"final answer"},"id":1}'"#,
        );
        let tool = BinaryPluginTool::new(test_tool_def(), "test-plugin", script_path, 30);
        let ctx = ToolContext::new();
        let result = tool.execute(json!({}), &ctx).await;
        assert!(result.is_ok(), "Expected Ok, got: {:?}", result);
        assert_eq!(result.unwrap().for_llm, "final answer");
    }
}