diff --git a/Cargo.lock b/Cargo.lock index 053a430..48a851e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3063,7 +3063,7 @@ dependencies = [ [[package]] name = "sparkplane" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "arc-swap", @@ -3118,7 +3118,7 @@ dependencies = [ [[package]] name = "sparkplane-core" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "sd-notify", @@ -3132,7 +3132,7 @@ dependencies = [ [[package]] name = "sparkplane-ipc" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 5b05824..6dfc6b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [".", "crates/sparkplane-core", "crates/sparkplane-ipc"] resolver = "3" [workspace.package] -version = "0.1.5" +version = "0.1.6" edition = "2024" rust-version = "1.95" license = "MIT" @@ -22,8 +22,8 @@ tracing = "0.1" tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt", "json", "registry", "std"] } metrics = "0.24" tempfile = "3" -sparkplane-core = { path = "crates/sparkplane-core", version = "=0.1.5" } -sparkplane-ipc = { path = "crates/sparkplane-ipc", version = "=0.1.5" } +sparkplane-core = { path = "crates/sparkplane-core", version = "=0.1.6" } +sparkplane-ipc = { path = "crates/sparkplane-ipc", version = "=0.1.6" } [package] name = "sparkplane" diff --git a/README.md b/README.md index 18cf2cd..b71db0f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ cargo build --locked --release ./target/release/sparkplane --help ./target/release/sparkplane dgx-spark status --json ./target/release/sparkplane dgx-spark serve qwen3.8:flash-next --dry-run --json -./target/release/sparkplane dgx-spark launch codex --allow-network -- --sandbox workspace-write +./target/release/sparkplane dgx-spark launch codex ``` Use the pinned Rust 1.95.0 toolchain (selected automatically by rustup), a @@ -19,10 +19,10 @@ Install the Minisign executable for the encrypted release-signing tests. The client runs on Linux x86-64/ARM64; the appliance targets Linux ARM64 with NVIDIA GB10, Docker and the NVIDIA container toolkit already installed. -Enable sandboxed internet access with `launch --allow-network`; -[agent-specific network controls](docs/reference/spark.md#internet-access-for-development) -leave filesystem and approval policies intact. Without the flag, agents retain -their existing permissions. +Agent launches default to `--mode auto`: full filesystem and network access +without action approval prompts. Use `--mode inherit` to keep the agent's own +permission settings. In inherit mode, `--allow-network` grants network access +within a supported sandbox. See [launch permissions](docs/reference/spark.md#internet-access-for-development). ## Architecture diff --git a/docs/how-to/serve-a-model-on-spark.md b/docs/how-to/serve-a-model-on-spark.md index 9475452..b324def 100644 --- a/docs/how-to/serve-a-model-on-spark.md +++ b/docs/how-to/serve-a-model-on-spark.md @@ -73,7 +73,7 @@ healthy, and confirm the OpenAI-compatible gateway path answers. ```bash sparkplane dgx-spark launch codex --model ornith-1.5:9b - sparkplane dgx-spark launch claude --model ornith-1.5:9b -- --permission-mode plan + sparkplane dgx-spark launch claude --mode inherit --model ornith-1.5:9b -- --permission-mode plan sparkplane dgx-spark launch opencode --model ornith-1.5:9b ``` @@ -84,11 +84,12 @@ healthy, and confirm the OpenAI-compatible gateway path answers. remediation. `launch` does not edit the primary Claude/OpenCode config or the main Codex config. - Add `--allow-network` when development commands need internet access: + Launches default to full access without approvals (`--mode auto`). To retain + agent sandbox settings while allowing internet access, use inherit mode: ```bash - sparkplane dgx-spark launch codex --allow-network -- --sandbox workspace-write - sparkplane dgx-spark launch claude --allow-network + sparkplane dgx-spark launch codex --mode inherit --allow-network -- --sandbox workspace-write + sparkplane dgx-spark launch claude --mode inherit --allow-network ``` This is a per-launch opt-in, also available as diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 3cfebe1..97343dd 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -139,7 +139,7 @@ sparkplane dgx-spark token create --name reader --scope models:read \ --scope operations:read --detach --json sparkplane dgx-spark client-config ornith --client codex sparkplane dgx-spark launch codex --model ornith-1.5:9b -sparkplane dgx-spark launch claude --model ornith-1.5:9b -- --permission-mode plan +sparkplane dgx-spark launch claude --mode inherit --model ornith-1.5:9b -- --permission-mode plan sparkplane dgx-spark launch opencode --model ornith-1.5:9b ``` diff --git a/docs/reference/spark.md b/docs/reference/spark.md index 2643591..928ec4c 100644 --- a/docs/reference/spark.md +++ b/docs/reference/spark.md @@ -37,7 +37,7 @@ sparkplane status --json sparkplane doctor --json sparkplane qualify --manifest --signature (--dry-run | --yes) [--detach] [--json] sparkplane serve [--name ] [--detach] [--dry-run] [--json] -sparkplane launch [--model ] [--allow-network] [--config] [--restore] [-y] [-- ...] +sparkplane launch [--mode auto|inherit] [--model ] [--allow-network] [--config] [--restore] [-y] [-- ...] sparkplane ls [--json] sparkplane ps [--json] sparkplane logs [--limit N] @@ -255,18 +255,35 @@ catalog, and OpenCode uses process-local `OPENCODE_CONFIG_CONTENT`. ### Internet access for development -Use `--allow-network` (or `SPARKPLANE_LAUNCH_ALLOW_NETWORK=true`) when the +Launches default to `--mode auto` (`SPARKPLANE_LAUNCH_MODE=auto`): full +filesystem and network access without action approval prompts. This applies +to the launched local agent session. It is not saved to agent configuration. + +| Agent | Auto mode | +| --- | --- | +| Codex | `approval_policy="never"`, `sandbox_mode="danger-full-access"` | +| Claude Code | `bypassPermissions`, sandbox disabled, bypass onboarding prompt skipped | +| OpenCode | All tool permissions allowed in the generated session configuration | + +Use `--mode inherit` to keep the agent's own permissions. Forwarded sandbox, +approval, or Claude settings options require inherit mode to avoid conflicting +policies. Managed agent restrictions still apply. Sparkplane's auto mode is +distinct from an agent's similarly named automatic-review mode. +`--dry-run --json` includes `mode`; `--config` and `--restore` never launch an +agent or change its permission settings. + +In inherit mode, use `--allow-network` (or `SPARKPLANE_LAUNCH_ALLOW_NETWORK=true`) when the agent needs to download dependencies, fetch documentation or use remote APIs: ```bash -sparkplane dgx-spark launch codex --allow-network -sparkplane dgx-spark launch claude --allow-network +sparkplane dgx-spark launch codex --mode inherit --allow-network +sparkplane dgx-spark launch claude --mode inherit --allow-network ``` The grant applies only to this invocation. It is not saved in launch state or agent configuration, and cannot be combined with `--config` or `--restore`. `--dry-run --json` reports the requested `allow_network` value without changing -anything. Without the flag, the agent's existing permissions remain unchanged; +anything. In inherit mode without the flag, the agent's existing permissions remain unchanged; Sparkplane does not impose its own workstation sandbox. | Agent | Effect of `--allow-network` | @@ -305,7 +322,7 @@ appliance's private engine networking. Agent controls are documented in the ```bash sparkplane dgx-spark serve ornith-1.5:9b --dry-run --json sparkplane dgx-spark launch codex --model ornith-1.5:9b -sparkplane dgx-spark launch claude --model ornith-1.5:9b -- --permission-mode plan +sparkplane dgx-spark launch claude --mode inherit --model ornith-1.5:9b -- --permission-mode plan sparkplane dgx-spark launch opencode --model ornith-1.5:9b sparkplane dgx-spark serve ornith-1.5:9b --name ornith sparkplane dgx-spark ps --json diff --git a/src/spark/cli.rs b/src/spark/cli.rs index 0d82ca5..43ea0a3 100644 --- a/src/spark/cli.rs +++ b/src/spark/cli.rs @@ -123,7 +123,7 @@ pub enum SparkCommand { Serve(ServeArgs), /// Configure and launch a local coding agent against a managed Spark model. #[command( - after_help = "Examples:\n sparkplane dgx-spark launch codex --model ornith-1.5:35b\n sparkplane dgx-spark launch codex --allow-network -- --sandbox workspace-write\n sparkplane dgx-spark launch claude --model ornith-1.5:35b -- --permission-mode plan\n sparkplane dgx-spark launch opencode --config --model ornith-1.5:35b\n sparkplane dgx-spark launch codex --model ornith-1.5:35b --dry-run --json\n\nArguments after `--` are passed directly to the selected local agent without a shell. The Spark administrator credential is never given to the child process.\n\n--allow-network requests invocation-only network access: Codex workspace-write networking, or Claude sandbox domains. OpenCode already has network access; its tool permissions remain unchanged. Filesystem sandboxing and approval policies are not disabled. Managed restrictions still apply. Claude --settings cannot be forwarded with this flag.\n\nEnvironment:\n SPARKPLANE_LAUNCH_MODEL, SPARKPLANE_LAUNCH_ALLOW_NETWORK, SPARKPLANE_LAUNCH_CONFIG, SPARKPLANE_LAUNCH_RESTORE, SPARKPLANE_YES, SPARKPLANE_DRY_RUN, SPARKPLANE_JSON, SPARKPLANE_CONFIG_DIR" + after_help = "Examples:\n sparkplane dgx-spark launch codex --model ornith-1.5:35b\n sparkplane dgx-spark launch codex --mode inherit --allow-network -- --sandbox workspace-write\n sparkplane dgx-spark launch claude --mode inherit --model ornith-1.5:35b -- --permission-mode plan\n sparkplane dgx-spark launch opencode --config --model ornith-1.5:35b\n sparkplane dgx-spark launch codex --model ornith-1.5:35b --dry-run --json\n\nArguments after `--` are passed directly to the selected local agent without a shell. The Spark administrator credential is never given to the child process.\n\nAuto mode (default) gives agents full access without action approvals. Use --mode inherit to retain agent permissions. --allow-network requests invocation-only network access: Codex workspace-write networking, or Claude sandbox domains. OpenCode already has network access; its tool permissions remain unchanged. Filesystem sandboxing and approval policies are not disabled. Managed restrictions still apply. Claude --settings cannot be forwarded with this flag.\n\nEnvironment:\n SPARKPLANE_LAUNCH_MODE, SPARKPLANE_LAUNCH_MODEL, SPARKPLANE_LAUNCH_ALLOW_NETWORK, SPARKPLANE_LAUNCH_CONFIG, SPARKPLANE_LAUNCH_RESTORE, SPARKPLANE_YES, SPARKPLANE_DRY_RUN, SPARKPLANE_JSON, SPARKPLANE_CONFIG_DIR" )] Launch(LaunchArgs), /// List currently active managed model processes. @@ -427,6 +427,9 @@ impl LaunchIntegration { pub struct LaunchArgs { #[arg(value_enum)] pub integration: LaunchIntegration, + /// Agent permissions: auto grants full access without action approvals; inherit keeps agent settings. + #[arg(long, default_value = "auto", value_parser = ["auto", "inherit"], env = "SPARKPLANE_LAUNCH_MODE")] + pub mode: String, /// Allow this agent session's sandbox network access; keep filesystem and approval policies. #[arg(long, env = "SPARKPLANE_LAUNCH_ALLOW_NETWORK", conflicts_with_all = ["configure", "restore"])] pub allow_network: bool, @@ -2737,6 +2740,40 @@ mod tests { }; assert_eq!(args.extra_args, ["--sandbox", "workspace-write"]); assert!(args.allow_network); + assert_eq!(args.mode, "auto"); + } + + #[test] + fn launch_permission_mode_accepts_inherit_and_rejects_unknown() { + #[derive(clap::Parser)] + struct TestCli { + #[command(flatten)] + spark: super::SparkCli, + } + let parsed = TestCli::try_parse_from([ + "sparkplane", + "dgx-spark", + "launch", + "codex", + "--mode", + "inherit", + ]) + .unwrap(); + let super::SparkCommand::Launch(args) = parsed.spark.command else { + panic!("expected launch") + }; + assert_eq!(args.mode, "inherit"); + assert!( + TestCli::try_parse_from([ + "sparkplane", + "dgx-spark", + "launch", + "codex", + "--mode", + "unknown" + ]) + .is_err() + ); } #[test] diff --git a/src/spark/launch.rs b/src/spark/launch.rs index 5bc91c4..638269b 100644 --- a/src/spark/launch.rs +++ b/src/spark/launch.rs @@ -44,6 +44,7 @@ struct LaunchPlan { token_id: Option, extra_argument_count: usize, allow_network: bool, + mode: String, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -180,6 +181,7 @@ pub fn run(host: &str, config_dir: &Path, args: LaunchArgs) -> Result<(), Client token_id: None, extra_argument_count: args.extra_args.len(), allow_network: args.allow_network, + mode: args.mode.clone(), }, args.json, ); @@ -254,6 +256,7 @@ pub fn run(host: &str, config_dir: &Path, args: LaunchArgs) -> Result<(), Client token_id: Some(token_id), extra_argument_count: args.extra_args.len(), allow_network: args.allow_network, + mode: args.mode.clone(), }; if args.configure { return render_plan(&plan, args.json); @@ -265,7 +268,9 @@ pub fn run(host: &str, config_dir: &Path, args: LaunchArgs) -> Result<(), Client model.canonical, instance.name ); - if args.allow_network { + if args.mode == "auto" { + eprintln!("Auto mode: full agent access with no action approvals."); + } else if args.allow_network { eprintln!( "Network access requested for this invocation; filesystem and approval policies are unchanged." ); @@ -274,6 +279,7 @@ pub fn run(host: &str, config_dir: &Path, args: LaunchArgs) -> Result<(), Client args.integration, args.yes, args.allow_network, + &args.mode, ReadyLaunch { config_dir, host, @@ -286,6 +292,28 @@ pub fn run(host: &str, config_dir: &Path, args: LaunchArgs) -> Result<(), Client } fn validate_args(args: &LaunchArgs) -> Result<(), ClientError> { + if args.mode == "auto" + && args.extra_args.iter().any(|arg| { + let flag = arg.split('=').next().unwrap_or(arg); + matches!( + flag, + "--settings" + | "--permission-mode" + | "--sandbox" + | "-s" + | "--ask-for-approval" + | "-a" + | "--full-auto" + | "--dangerously-bypass-approvals-and-sandbox" + | "--dangerously-skip-permissions" + ) || arg.contains("approval_policy") + || arg.contains("sandbox_mode") + }) + { + return Err(usage( + "custom agent permission settings require --mode inherit", + )); + } if args.allow_network && (args.configure || args.restore) { return Err(usage( "--allow-network is invocation-only; it cannot be combined with --config or --restore", @@ -654,16 +682,62 @@ fn configure_network_access(command: &mut Command, integration: LaunchIntegratio } } +fn configure_launch_permissions( + command: &mut Command, + integration: LaunchIntegration, + mode: &str, + allow_network: bool, +) -> Result<(), ClientError> { + if mode == "inherit" { + configure_network_access(command, integration, allow_network); + return Ok(()); + } + match integration { + LaunchIntegration::Codex => { + command.args([ + "-c", + "approval_policy=\"never\"", + "-c", + "sandbox_mode=\"danger-full-access\"", + ]); + } + LaunchIntegration::Claude => { + command.args([ + "--permission-mode", + "bypassPermissions", + "--settings", + r#"{"sandbox":{"enabled":false},"skipDangerousModePermissionPrompt":true}"#, + ]); + } + LaunchIntegration::Opencode => { + let content = command + .get_envs() + .find(|(key, _)| *key == "OPENCODE_CONFIG_CONTENT") + .and_then(|(_, value)| value) + .ok_or_else(|| usage("missing OpenCode launch configuration"))?; + let mut config: Value = serde_json::from_str(&content.to_string_lossy()) + .map_err(|_| usage("invalid OpenCode launch configuration"))?; + config["permission"] = serde_json::json!({"*": "allow"}); + command.env("OPENCODE_CONFIG_CONTENT", config.to_string()); + command.env("OPENCODE_PERMISSION", r#"{"*":"allow"}"#); + } + } + Ok(()) +} + fn launch_child( integration: LaunchIntegration, yes: bool, allow_network: bool, + mode: &str, launch: ReadyLaunch<'_>, extra_args: &[String], ) -> Result<(), ClientError> { let executable = ensure_executable(integration, yes)?; let mut command = Command::new(executable); - configure_network_access(&mut command, integration, allow_network); + if integration != LaunchIntegration::Opencode { + configure_launch_permissions(&mut command, integration, mode, allow_network)?; + } command .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) @@ -697,6 +771,9 @@ fn launch_child( extra_args, )?, } + if integration == LaunchIntegration::Opencode { + configure_launch_permissions(&mut command, integration, mode, allow_network)?; + } let status = command .status() .map_err(|_| usage(format!("could not start {}", integration.as_str())))?; @@ -1173,13 +1250,16 @@ fn render_plan(plan: &LaunchPlan, json: bool) -> Result<(), ClientError> { ); } else { println!( - "{} {} with {} on {} ({}; network={})", + "{} {} with {} on {} ({}; mode={}; network={})", plan.action, plan.integration, plan.model, plan.instance, plan.host, - if plan.allow_network { + plan.mode, + if plan.mode == "auto" { + "full-access" + } else if plan.allow_network { "requested" } else { "agent-default" @@ -1291,6 +1371,70 @@ mod tests { assert_eq!(args, ["-c", "sandbox_workspace_write.network_access=true"]); } + #[test] + fn auto_mode_grants_codex_full_access_without_approvals() { + let mut command = Command::new("codex"); + configure_launch_permissions(&mut command, LaunchIntegration::Codex, "auto", false) + .unwrap(); + assert_eq!( + command.get_args().collect::>(), + [ + "-c", + "approval_policy=\"never\"", + "-c", + "sandbox_mode=\"danger-full-access\"" + ] + ); + } + + #[test] + fn auto_mode_grants_claude_full_access_without_approvals() { + let mut command = Command::new("claude"); + configure_launch_permissions(&mut command, LaunchIntegration::Claude, "auto", true) + .unwrap(); + assert_eq!( + command.get_args().collect::>(), + [ + "--permission-mode", + "bypassPermissions", + "--settings", + r#"{"sandbox":{"enabled":false},"skipDangerousModePermissionPrompt":true}"# + ] + ); + } + + #[test] + fn auto_mode_preserves_opencode_provider_and_allows_tools() { + let mut command = Command::new("opencode"); + command.env( + "OPENCODE_CONFIG_CONTENT", + r#"{"provider":{"sparkplane":{}},"model":"sparkplane/test"}"#, + ); + configure_launch_permissions(&mut command, LaunchIntegration::Opencode, "auto", false) + .unwrap(); + let content = command_env(&command, "OPENCODE_CONFIG_CONTENT") + .unwrap() + .unwrap(); + let config: Value = serde_json::from_str(&content).unwrap(); + assert_eq!(config["permission"]["*"], "allow"); + assert_eq!(config["model"], "sparkplane/test"); + assert!(config["provider"]["sparkplane"].is_object()); + } + + #[test] + fn inherit_mode_preserves_agent_permissions() { + for integration in [ + LaunchIntegration::Codex, + LaunchIntegration::Claude, + LaunchIntegration::Opencode, + ] { + let mut command = Command::new(integration.as_str()); + configure_launch_permissions(&mut command, integration, "inherit", false).unwrap(); + assert_eq!(command.get_args().count(), 0); + assert_eq!(command.get_envs().count(), 0); + } + } + #[test] fn network_opt_in_only_changes_claude_domain_allowlist() { let mut command = Command::new("claude"); @@ -1650,6 +1794,7 @@ mod tests { fn restore_flags_cannot_be_combined() { let args = LaunchArgs { integration: LaunchIntegration::Codex, + mode: "auto".into(), allow_network: false, model: Some("ornith".into()), configure: false, diff --git a/tests/standalone_cli.rs b/tests/standalone_cli.rs index a42e615..316cf41 100644 --- a/tests/standalone_cli.rs +++ b/tests/standalone_cli.rs @@ -7,6 +7,27 @@ fn launch_help_exposes_opt_in_network_access() { .output() .unwrap(); assert!(String::from_utf8_lossy(&output.stdout).contains("--allow-network")); + assert!(String::from_utf8_lossy(&output.stdout).contains("--mode")); + assert!(String::from_utf8_lossy(&output.stdout).contains("[default: auto]")); +} + +#[test] +fn auto_mode_rejects_conflicting_agent_settings_before_contacting_spark() { + for (agent, flag, value) in [ + ("codex", "--sandbox", "read-only"), + ("claude", "--permission-mode", "plan"), + ] { + let root = tempfile::tempdir().unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_sparkplane")) + .env_clear() + .env("SPARKPLANE_CONFIG_DIR", root.path()) + .args(["dgx-spark", "launch", agent, "--", flag, value]) + .output() + .unwrap(); + assert_eq!(output.status.code(), Some(2)); + assert!(String::from_utf8_lossy(&output.stderr).contains("--mode inherit")); + assert_eq!(std::fs::read_dir(root.path()).unwrap().count(), 0); + } } #[test] @@ -19,6 +40,8 @@ fn network_opt_in_rejects_shadowing_claude_settings_before_contacting_spark() { "dgx-spark", "launch", "claude", + "--mode", + "inherit", "--allow-network", "--", "--settings",