Skip to content

Commit 393a9f4

Browse files
authored
Increase sdk function run capabilities (#166)
* normalize virtual CWD paths * add --args-file support to CLI and SDKs to handle large argument lists via temporary files * simplify error mapping using method references in CLI command execution * prioritize current working directory over file path for project root resolution * import standard library networking modules into the capsule package initialization * bump version to 0.8.7 and normalize guest paths in path validator
1 parent 7db31fd commit 393a9f4

19 files changed

Lines changed: 165 additions & 46 deletions

File tree

crates/capsule-cli/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/capsule-cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "capsule-run"
3-
version = "0.8.5"
3+
version = "0.8.7"
44
edition = "2024"
55
description = "Secure WASM runtime to isolate and manage AI agent tasks"
66
license = "Apache-2.0"
@@ -16,7 +16,7 @@ path = "src/main.rs"
1616

1717
[dependencies]
1818
clap = { version = "4.5.53", features = ["derive"] }
19-
capsule-core = { version= "0.8.5", path = "../capsule-core" }
19+
capsule-core = { version= "0.8.7", path = "../capsule-core" }
2020
tokio = { version = "1.48.0", features = ["rt", "rt-multi-thread", "macros"] }
2121
serde_json = "1"
2222
dotenvy = "0.15.7"

crates/capsule-cli/npm/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@capsule-run/cli",
3-
"version": "0.8.5",
3+
"version": "0.8.7",
44
"description": "Secure WASM runtime to isolate and manage AI agent tasks",
55
"bin": {
66
"capsule": "./bin/capsule.js"
@@ -29,9 +29,9 @@
2929
"node": ">=18"
3030
},
3131
"optionalDependencies": {
32-
"@capsule-run/cli-darwin-arm64": "0.8.5",
33-
"@capsule-run/cli-darwin-x64": "0.8.5",
34-
"@capsule-run/cli-linux-x64": "0.8.5",
35-
"@capsule-run/cli-win32-x64": "0.8.5"
32+
"@capsule-run/cli-darwin-arm64": "0.8.7",
33+
"@capsule-run/cli-darwin-x64": "0.8.7",
34+
"@capsule-run/cli-linux-x64": "0.8.7",
35+
"@capsule-run/cli-win32-x64": "0.8.7"
3636
}
3737
}

crates/capsule-cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "capsule-run"
7-
version = "0.8.5"
7+
version = "0.8.7"
88
description = "Secure WASM runtime to isolate and manage AI agent tasks"
99
readme = "docs/README-pypi.md"
1010
license = {text = "Apache-2.0"}

crates/capsule-cli/src/cli.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub enum Commands {
2323
#[arg(long, value_name = "HOST[::GUEST][:ro|:rw]")]
2424
mount: Vec<String>,
2525

26+
#[arg(long, value_name = "FILE", conflicts_with = "args")]
27+
args_file: Option<String>,
28+
2629
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
2730
args: Vec<String>,
2831
},
@@ -44,6 +47,9 @@ pub enum Commands {
4447
#[arg(long, value_name = "HOST[::GUEST][:ro|:rw]")]
4548
mount: Vec<String>,
4649

50+
#[arg(long, value_name = "FILE", conflicts_with = "args")]
51+
args_file: Option<String>,
52+
4753
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
4854
args: Vec<String>,
4955
},

crates/capsule-cli/src/commands/run.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ pub async fn execute(
8383

8484
reporter.start_progress("Initializing runtime");
8585

86-
let project_root = file_path
87-
.canonicalize()
88-
.ok()
89-
.and_then(|p| p.parent().map(|p| p.to_path_buf()))
90-
.unwrap_or_else(|| std::env::current_dir().unwrap_or_default());
86+
let project_root = std::env::current_dir().unwrap_or_else(|_| {
87+
file_path
88+
.canonicalize()
89+
.ok()
90+
.and_then(|p| p.parent().map(|p| p.to_path_buf()))
91+
.unwrap_or_default()
92+
});
9193

9294
load_env_variables(&project_root).map_err(RunError::IoError)?;
9395

crates/capsule-cli/src/commands/shared.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
use std::path::Path;
22

3+
pub fn load_args_file(path: &str) -> Result<Vec<String>, String> {
4+
let content = std::fs::read_to_string(path)
5+
.map_err(|e| format!("Failed to read --args-file '{}': {}", path, e))?;
6+
let args: Vec<String> = serde_json::from_str(&content)
7+
.map_err(|e| format!("Failed to parse --args-file '{}': {}", path, e))?;
8+
Ok(args)
9+
}
10+
311
pub fn load_env_variables(project_root: &Path) -> Result<(), String> {
412
let env_files = [".env", ".env.local", ".env.development", ".env.production"];
513

crates/capsule-cli/src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::fmt;
66
use std::path::Path;
77

88
use cli::{Cli, Commands};
9+
use commands::shared::load_args_file;
910
use commands::{BuildError, ExecError, RunError, build, exec, run};
1011

1112
#[derive(Debug)]
@@ -53,8 +54,13 @@ async fn main() -> Result<(), CliError> {
5354
json,
5455
verbose,
5556
mount,
57+
args_file,
5658
args,
5759
} => {
60+
let args = match args_file {
61+
Some(ref path) => load_args_file(path).map_err(CliError::RunError)?,
62+
None => args,
63+
};
5864
let file_path = file.as_deref().map(Path::new);
5965
let result = run::execute(file_path, args, mount, json, verbose).await?;
6066

@@ -75,8 +81,13 @@ async fn main() -> Result<(), CliError> {
7581
json,
7682
verbose,
7783
mount,
84+
args_file,
7885
args,
7986
} => {
87+
let args = match args_file {
88+
Some(ref path) => load_args_file(path).map_err(CliError::ExecError)?,
89+
None => args,
90+
};
8091
let result = exec::execute(Path::new(&file), args, mount, json, verbose).await?;
8192

8293
if json {

crates/capsule-core/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/capsule-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "capsule-core"
3-
version = "0.8.5"
3+
version = "0.8.7"
44
edition = "2024"
55
description = "Core library for Capsule - WASM runtime for AI agent isolation"
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)