mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-04 03:34:49 +08:00
Compare commits
1 Commits
rcc/update
...
rcc/sandbo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d09bf9961 |
3
rust/Cargo.lock
generated
3
rust/Cargo.lock
generated
@@ -1091,11 +1091,8 @@ dependencies = [
|
||||
"compat-harness",
|
||||
"crossterm",
|
||||
"pulldown-cmark",
|
||||
"reqwest",
|
||||
"runtime",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"syntect",
|
||||
"tokio",
|
||||
"tools",
|
||||
|
||||
@@ -84,15 +84,6 @@ cargo run -p rusty-claude-cli -- logout
|
||||
|
||||
This removes only the stored OAuth credentials and preserves unrelated JSON fields in `credentials.json`.
|
||||
|
||||
### Self-update
|
||||
|
||||
```bash
|
||||
cd rust
|
||||
cargo run -p rusty-claude-cli -- self-update
|
||||
```
|
||||
|
||||
The command checks the latest GitHub release for `instructkr/clawd-code`, compares it to the current binary version, downloads the matching binary asset plus checksum manifest, verifies SHA-256, replaces the current executable, and prints the release changelog. If no published release or matching asset exists, it exits safely with an explanatory message.
|
||||
|
||||
## Usage examples
|
||||
|
||||
### 1) Prompt mode
|
||||
@@ -171,7 +162,6 @@ cargo run -p rusty-claude-cli -- --resume session.json /memory /config
|
||||
- `dump-manifests` — print extracted upstream manifest counts
|
||||
- `bootstrap-plan` — print the current bootstrap skeleton
|
||||
- `system-prompt [--cwd PATH] [--date YYYY-MM-DD]` — render the synthesized system prompt
|
||||
- `self-update` — update the installed binary from the latest GitHub release when a matching asset is available
|
||||
- `--help` / `-h` — show CLI help
|
||||
- `--version` / `-V` — print the CLI version and build info locally (no API call)
|
||||
- `--output-format text|json` — choose non-interactive prompt output rendering
|
||||
|
||||
@@ -51,6 +51,12 @@ const SLASH_COMMAND_SPECS: &[SlashCommandSpec] = &[
|
||||
argument_hint: None,
|
||||
resume_supported: true,
|
||||
},
|
||||
SlashCommandSpec {
|
||||
name: "sandbox",
|
||||
summary: "Show sandbox isolation status",
|
||||
argument_hint: None,
|
||||
resume_supported: true,
|
||||
},
|
||||
SlashCommandSpec {
|
||||
name: "compact",
|
||||
summary: "Compact local session history",
|
||||
@@ -135,6 +141,7 @@ const SLASH_COMMAND_SPECS: &[SlashCommandSpec] = &[
|
||||
pub enum SlashCommand {
|
||||
Help,
|
||||
Status,
|
||||
Sandbox,
|
||||
Compact,
|
||||
Model {
|
||||
model: Option<String>,
|
||||
@@ -179,6 +186,7 @@ impl SlashCommand {
|
||||
Some(match command {
|
||||
"help" => Self::Help,
|
||||
"status" => Self::Status,
|
||||
"sandbox" => Self::Sandbox,
|
||||
"compact" => Self::Compact,
|
||||
"model" => Self::Model {
|
||||
model: parts.next().map(ToOwned::to_owned),
|
||||
@@ -279,6 +287,7 @@ pub fn handle_slash_command(
|
||||
session: session.clone(),
|
||||
}),
|
||||
SlashCommand::Status
|
||||
| SlashCommand::Sandbox
|
||||
| SlashCommand::Model { .. }
|
||||
| SlashCommand::Permissions { .. }
|
||||
| SlashCommand::Clear { .. }
|
||||
@@ -307,6 +316,7 @@ mod tests {
|
||||
fn parses_supported_slash_commands() {
|
||||
assert_eq!(SlashCommand::parse("/help"), Some(SlashCommand::Help));
|
||||
assert_eq!(SlashCommand::parse(" /status "), Some(SlashCommand::Status));
|
||||
assert_eq!(SlashCommand::parse("/sandbox"), Some(SlashCommand::Sandbox));
|
||||
assert_eq!(
|
||||
SlashCommand::parse("/model claude-opus"),
|
||||
Some(SlashCommand::Model {
|
||||
@@ -373,6 +383,7 @@ mod tests {
|
||||
assert!(help.contains("works with --resume SESSION.json"));
|
||||
assert!(help.contains("/help"));
|
||||
assert!(help.contains("/status"));
|
||||
assert!(help.contains("/sandbox"));
|
||||
assert!(help.contains("/compact"));
|
||||
assert!(help.contains("/model [model]"));
|
||||
assert!(help.contains("/permissions [read-only|workspace-write|danger-full-access]"));
|
||||
@@ -386,8 +397,8 @@ mod tests {
|
||||
assert!(help.contains("/version"));
|
||||
assert!(help.contains("/export [file]"));
|
||||
assert!(help.contains("/session [list|switch <session-id>]"));
|
||||
assert_eq!(slash_command_specs().len(), 15);
|
||||
assert_eq!(resume_supported_slash_commands().len(), 11);
|
||||
assert_eq!(slash_command_specs().len(), 16);
|
||||
assert_eq!(resume_supported_slash_commands().len(), 12);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -434,6 +445,7 @@ mod tests {
|
||||
let session = Session::new();
|
||||
assert!(handle_slash_command("/unknown", &session, CompactionConfig::default()).is_none());
|
||||
assert!(handle_slash_command("/status", &session, CompactionConfig::default()).is_none());
|
||||
assert!(handle_slash_command("/sandbox", &session, CompactionConfig::default()).is_none());
|
||||
assert!(
|
||||
handle_slash_command("/model claude", &session, CompactionConfig::default()).is_none()
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::time::Duration;
|
||||
@@ -7,6 +8,12 @@ use tokio::process::Command as TokioCommand;
|
||||
use tokio::runtime::Builder;
|
||||
use tokio::time::timeout;
|
||||
|
||||
use crate::sandbox::{
|
||||
build_linux_sandbox_command, resolve_sandbox_status_for_request, FilesystemIsolationMode,
|
||||
SandboxConfig, SandboxStatus,
|
||||
};
|
||||
use crate::ConfigLoader;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct BashCommandInput {
|
||||
pub command: String,
|
||||
@@ -16,6 +23,14 @@ pub struct BashCommandInput {
|
||||
pub run_in_background: Option<bool>,
|
||||
#[serde(rename = "dangerouslyDisableSandbox")]
|
||||
pub dangerously_disable_sandbox: Option<bool>,
|
||||
#[serde(rename = "namespaceRestrictions")]
|
||||
pub namespace_restrictions: Option<bool>,
|
||||
#[serde(rename = "isolateNetwork")]
|
||||
pub isolate_network: Option<bool>,
|
||||
#[serde(rename = "filesystemMode")]
|
||||
pub filesystem_mode: Option<FilesystemIsolationMode>,
|
||||
#[serde(rename = "allowedMounts")]
|
||||
pub allowed_mounts: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
@@ -45,13 +60,17 @@ pub struct BashCommandOutput {
|
||||
pub persisted_output_path: Option<String>,
|
||||
#[serde(rename = "persistedOutputSize")]
|
||||
pub persisted_output_size: Option<u64>,
|
||||
#[serde(rename = "sandboxStatus")]
|
||||
pub sandbox_status: Option<SandboxStatus>,
|
||||
}
|
||||
|
||||
pub fn execute_bash(input: BashCommandInput) -> io::Result<BashCommandOutput> {
|
||||
let cwd = env::current_dir()?;
|
||||
let sandbox_status = sandbox_status_for_input(&input, &cwd);
|
||||
|
||||
if input.run_in_background.unwrap_or(false) {
|
||||
let child = Command::new("sh")
|
||||
.arg("-lc")
|
||||
.arg(&input.command)
|
||||
let mut child = prepare_command(&input.command, &cwd, &sandbox_status, false);
|
||||
let child = child
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
@@ -72,16 +91,20 @@ pub fn execute_bash(input: BashCommandInput) -> io::Result<BashCommandOutput> {
|
||||
structured_content: None,
|
||||
persisted_output_path: None,
|
||||
persisted_output_size: None,
|
||||
sandbox_status: Some(sandbox_status),
|
||||
});
|
||||
}
|
||||
|
||||
let runtime = Builder::new_current_thread().enable_all().build()?;
|
||||
runtime.block_on(execute_bash_async(input))
|
||||
runtime.block_on(execute_bash_async(input, sandbox_status, cwd))
|
||||
}
|
||||
|
||||
async fn execute_bash_async(input: BashCommandInput) -> io::Result<BashCommandOutput> {
|
||||
let mut command = TokioCommand::new("sh");
|
||||
command.arg("-lc").arg(&input.command);
|
||||
async fn execute_bash_async(
|
||||
input: BashCommandInput,
|
||||
sandbox_status: SandboxStatus,
|
||||
cwd: std::path::PathBuf,
|
||||
) -> io::Result<BashCommandOutput> {
|
||||
let mut command = prepare_tokio_command(&input.command, &cwd, &sandbox_status, true);
|
||||
|
||||
let output_result = if let Some(timeout_ms) = input.timeout {
|
||||
match timeout(Duration::from_millis(timeout_ms), command.output()).await {
|
||||
@@ -102,6 +125,7 @@ async fn execute_bash_async(input: BashCommandInput) -> io::Result<BashCommandOu
|
||||
structured_content: None,
|
||||
persisted_output_path: None,
|
||||
persisted_output_size: None,
|
||||
sandbox_status: Some(sandbox_status),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -136,12 +160,88 @@ async fn execute_bash_async(input: BashCommandInput) -> io::Result<BashCommandOu
|
||||
structured_content: None,
|
||||
persisted_output_path: None,
|
||||
persisted_output_size: None,
|
||||
sandbox_status: Some(sandbox_status),
|
||||
})
|
||||
}
|
||||
|
||||
fn sandbox_status_for_input(input: &BashCommandInput, cwd: &std::path::Path) -> SandboxStatus {
|
||||
let config = ConfigLoader::default_for(cwd).load().map_or_else(
|
||||
|_| SandboxConfig::default(),
|
||||
|runtime_config| runtime_config.sandbox().clone(),
|
||||
);
|
||||
let request = config.resolve_request(
|
||||
input.dangerously_disable_sandbox.map(|disabled| !disabled),
|
||||
input.namespace_restrictions,
|
||||
input.isolate_network,
|
||||
input.filesystem_mode,
|
||||
input.allowed_mounts.clone(),
|
||||
);
|
||||
resolve_sandbox_status_for_request(&request, cwd)
|
||||
}
|
||||
|
||||
fn prepare_command(
|
||||
command: &str,
|
||||
cwd: &std::path::Path,
|
||||
sandbox_status: &SandboxStatus,
|
||||
create_dirs: bool,
|
||||
) -> Command {
|
||||
if create_dirs {
|
||||
prepare_sandbox_dirs(cwd);
|
||||
}
|
||||
|
||||
if let Some(launcher) = build_linux_sandbox_command(command, cwd, sandbox_status) {
|
||||
let mut prepared = Command::new(launcher.program);
|
||||
prepared.args(launcher.args);
|
||||
prepared.current_dir(cwd);
|
||||
prepared.envs(launcher.env);
|
||||
return prepared;
|
||||
}
|
||||
|
||||
let mut prepared = Command::new("sh");
|
||||
prepared.arg("-lc").arg(command).current_dir(cwd);
|
||||
if sandbox_status.filesystem_active {
|
||||
prepared.env("HOME", cwd.join(".sandbox-home"));
|
||||
prepared.env("TMPDIR", cwd.join(".sandbox-tmp"));
|
||||
}
|
||||
prepared
|
||||
}
|
||||
|
||||
fn prepare_tokio_command(
|
||||
command: &str,
|
||||
cwd: &std::path::Path,
|
||||
sandbox_status: &SandboxStatus,
|
||||
create_dirs: bool,
|
||||
) -> TokioCommand {
|
||||
if create_dirs {
|
||||
prepare_sandbox_dirs(cwd);
|
||||
}
|
||||
|
||||
if let Some(launcher) = build_linux_sandbox_command(command, cwd, sandbox_status) {
|
||||
let mut prepared = TokioCommand::new(launcher.program);
|
||||
prepared.args(launcher.args);
|
||||
prepared.current_dir(cwd);
|
||||
prepared.envs(launcher.env);
|
||||
return prepared;
|
||||
}
|
||||
|
||||
let mut prepared = TokioCommand::new("sh");
|
||||
prepared.arg("-lc").arg(command).current_dir(cwd);
|
||||
if sandbox_status.filesystem_active {
|
||||
prepared.env("HOME", cwd.join(".sandbox-home"));
|
||||
prepared.env("TMPDIR", cwd.join(".sandbox-tmp"));
|
||||
}
|
||||
prepared
|
||||
}
|
||||
|
||||
fn prepare_sandbox_dirs(cwd: &std::path::Path) {
|
||||
let _ = std::fs::create_dir_all(cwd.join(".sandbox-home"));
|
||||
let _ = std::fs::create_dir_all(cwd.join(".sandbox-tmp"));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{execute_bash, BashCommandInput};
|
||||
use crate::sandbox::FilesystemIsolationMode;
|
||||
|
||||
#[test]
|
||||
fn executes_simple_command() {
|
||||
@@ -151,10 +251,33 @@ mod tests {
|
||||
description: None,
|
||||
run_in_background: Some(false),
|
||||
dangerously_disable_sandbox: Some(false),
|
||||
namespace_restrictions: Some(false),
|
||||
isolate_network: Some(false),
|
||||
filesystem_mode: Some(FilesystemIsolationMode::WorkspaceOnly),
|
||||
allowed_mounts: None,
|
||||
})
|
||||
.expect("bash command should execute");
|
||||
|
||||
assert_eq!(output.stdout, "hello");
|
||||
assert!(!output.interrupted);
|
||||
assert!(output.sandbox_status.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disables_sandbox_when_requested() {
|
||||
let output = execute_bash(BashCommandInput {
|
||||
command: String::from("printf 'hello'"),
|
||||
timeout: Some(1_000),
|
||||
description: None,
|
||||
run_in_background: Some(false),
|
||||
dangerously_disable_sandbox: Some(true),
|
||||
namespace_restrictions: None,
|
||||
isolate_network: None,
|
||||
filesystem_mode: None,
|
||||
allowed_mounts: None,
|
||||
})
|
||||
.expect("bash command should execute");
|
||||
|
||||
assert!(!output.sandbox_status.expect("sandbox status").enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::json::JsonValue;
|
||||
use crate::sandbox::{FilesystemIsolationMode, SandboxConfig};
|
||||
|
||||
pub const CLAUDE_CODE_SETTINGS_SCHEMA_NAME: &str = "SettingsSchema";
|
||||
|
||||
@@ -40,6 +41,7 @@ pub struct RuntimeFeatureConfig {
|
||||
oauth: Option<OAuthConfig>,
|
||||
model: Option<String>,
|
||||
permission_mode: Option<ResolvedPermissionMode>,
|
||||
sandbox: SandboxConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
@@ -225,6 +227,7 @@ impl ConfigLoader {
|
||||
oauth: parse_optional_oauth_config(&merged_value, "merged settings.oauth")?,
|
||||
model: parse_optional_model(&merged_value),
|
||||
permission_mode: parse_optional_permission_mode(&merged_value)?,
|
||||
sandbox: parse_optional_sandbox_config(&merged_value)?,
|
||||
};
|
||||
|
||||
Ok(RuntimeConfig {
|
||||
@@ -289,6 +292,11 @@ impl RuntimeConfig {
|
||||
pub fn permission_mode(&self) -> Option<ResolvedPermissionMode> {
|
||||
self.feature_config.permission_mode
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn sandbox(&self) -> &SandboxConfig {
|
||||
&self.feature_config.sandbox
|
||||
}
|
||||
}
|
||||
|
||||
impl RuntimeFeatureConfig {
|
||||
@@ -311,6 +319,11 @@ impl RuntimeFeatureConfig {
|
||||
pub fn permission_mode(&self) -> Option<ResolvedPermissionMode> {
|
||||
self.permission_mode
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn sandbox(&self) -> &SandboxConfig {
|
||||
&self.sandbox
|
||||
}
|
||||
}
|
||||
|
||||
impl McpConfigCollection {
|
||||
@@ -445,6 +458,42 @@ fn parse_permission_mode_label(
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_optional_sandbox_config(root: &JsonValue) -> Result<SandboxConfig, ConfigError> {
|
||||
let Some(object) = root.as_object() else {
|
||||
return Ok(SandboxConfig::default());
|
||||
};
|
||||
let Some(sandbox_value) = object.get("sandbox") else {
|
||||
return Ok(SandboxConfig::default());
|
||||
};
|
||||
let sandbox = expect_object(sandbox_value, "merged settings.sandbox")?;
|
||||
let filesystem_mode = optional_string(sandbox, "filesystemMode", "merged settings.sandbox")?
|
||||
.map(parse_filesystem_mode_label)
|
||||
.transpose()?;
|
||||
Ok(SandboxConfig {
|
||||
enabled: optional_bool(sandbox, "enabled", "merged settings.sandbox")?,
|
||||
namespace_restrictions: optional_bool(
|
||||
sandbox,
|
||||
"namespaceRestrictions",
|
||||
"merged settings.sandbox",
|
||||
)?,
|
||||
network_isolation: optional_bool(sandbox, "networkIsolation", "merged settings.sandbox")?,
|
||||
filesystem_mode,
|
||||
allowed_mounts: optional_string_array(sandbox, "allowedMounts", "merged settings.sandbox")?
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_filesystem_mode_label(value: &str) -> Result<FilesystemIsolationMode, ConfigError> {
|
||||
match value {
|
||||
"off" => Ok(FilesystemIsolationMode::Off),
|
||||
"workspace-only" => Ok(FilesystemIsolationMode::WorkspaceOnly),
|
||||
"allow-list" => Ok(FilesystemIsolationMode::AllowList),
|
||||
other => Err(ConfigError::Parse(format!(
|
||||
"merged settings.sandbox.filesystemMode: unsupported filesystem mode {other}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_optional_oauth_config(
|
||||
root: &JsonValue,
|
||||
context: &str,
|
||||
@@ -688,6 +737,7 @@ mod tests {
|
||||
CLAUDE_CODE_SETTINGS_SCHEMA_NAME,
|
||||
};
|
||||
use crate::json::JsonValue;
|
||||
use crate::sandbox::FilesystemIsolationMode;
|
||||
use std::fs;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
@@ -792,6 +842,44 @@ mod tests {
|
||||
fs::remove_dir_all(root).expect("cleanup temp dir");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_sandbox_config() {
|
||||
let root = temp_dir();
|
||||
let cwd = root.join("project");
|
||||
let home = root.join("home").join(".claude");
|
||||
fs::create_dir_all(cwd.join(".claude")).expect("project config dir");
|
||||
fs::create_dir_all(&home).expect("home config dir");
|
||||
|
||||
fs::write(
|
||||
cwd.join(".claude").join("settings.local.json"),
|
||||
r#"{
|
||||
"sandbox": {
|
||||
"enabled": true,
|
||||
"namespaceRestrictions": false,
|
||||
"networkIsolation": true,
|
||||
"filesystemMode": "allow-list",
|
||||
"allowedMounts": ["logs", "tmp/cache"]
|
||||
}
|
||||
}"#,
|
||||
)
|
||||
.expect("write local settings");
|
||||
|
||||
let loaded = ConfigLoader::new(&cwd, &home)
|
||||
.load()
|
||||
.expect("config should load");
|
||||
|
||||
assert_eq!(loaded.sandbox().enabled, Some(true));
|
||||
assert_eq!(loaded.sandbox().namespace_restrictions, Some(false));
|
||||
assert_eq!(loaded.sandbox().network_isolation, Some(true));
|
||||
assert_eq!(
|
||||
loaded.sandbox().filesystem_mode,
|
||||
Some(FilesystemIsolationMode::AllowList)
|
||||
);
|
||||
assert_eq!(loaded.sandbox().allowed_mounts, vec!["logs", "tmp/cache"]);
|
||||
|
||||
fs::remove_dir_all(root).expect("cleanup temp dir");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_typed_mcp_and_oauth_config() {
|
||||
let root = temp_dir();
|
||||
|
||||
@@ -12,6 +12,7 @@ mod oauth;
|
||||
mod permissions;
|
||||
mod prompt;
|
||||
mod remote;
|
||||
mod sandbox;
|
||||
mod session;
|
||||
mod usage;
|
||||
|
||||
@@ -73,6 +74,12 @@ pub use remote::{
|
||||
RemoteSessionContext, UpstreamProxyBootstrap, UpstreamProxyState, DEFAULT_REMOTE_BASE_URL,
|
||||
DEFAULT_SESSION_TOKEN_PATH, DEFAULT_SYSTEM_CA_BUNDLE, NO_PROXY_HOSTS, UPSTREAM_PROXY_ENV_KEYS,
|
||||
};
|
||||
pub use sandbox::{
|
||||
build_linux_sandbox_command, detect_container_environment, detect_container_environment_from,
|
||||
resolve_sandbox_status, resolve_sandbox_status_for_request, ContainerEnvironment,
|
||||
FilesystemIsolationMode, LinuxSandboxCommand, SandboxConfig, SandboxDetectionInputs,
|
||||
SandboxRequest, SandboxStatus,
|
||||
};
|
||||
pub use session::{ContentBlock, ConversationMessage, MessageRole, Session, SessionError};
|
||||
pub use usage::{
|
||||
format_usd, pricing_for_model, ModelPricing, TokenUsage, UsageCostEstimate, UsageTracker,
|
||||
|
||||
@@ -5,6 +5,8 @@ pub enum PermissionMode {
|
||||
ReadOnly,
|
||||
WorkspaceWrite,
|
||||
DangerFullAccess,
|
||||
Prompt,
|
||||
Allow,
|
||||
}
|
||||
|
||||
impl PermissionMode {
|
||||
@@ -14,6 +16,8 @@ impl PermissionMode {
|
||||
Self::ReadOnly => "read-only",
|
||||
Self::WorkspaceWrite => "workspace-write",
|
||||
Self::DangerFullAccess => "danger-full-access",
|
||||
Self::Prompt => "prompt",
|
||||
Self::Allow => "allow",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +94,7 @@ impl PermissionPolicy {
|
||||
) -> PermissionOutcome {
|
||||
let current_mode = self.active_mode();
|
||||
let required_mode = self.required_mode_for(tool_name);
|
||||
if current_mode >= required_mode {
|
||||
if current_mode == PermissionMode::Allow || current_mode >= required_mode {
|
||||
return PermissionOutcome::Allow;
|
||||
}
|
||||
|
||||
@@ -101,8 +105,9 @@ impl PermissionPolicy {
|
||||
required_mode,
|
||||
};
|
||||
|
||||
if current_mode == PermissionMode::WorkspaceWrite
|
||||
&& required_mode == PermissionMode::DangerFullAccess
|
||||
if current_mode == PermissionMode::Prompt
|
||||
|| (current_mode == PermissionMode::WorkspaceWrite
|
||||
&& required_mode == PermissionMode::DangerFullAccess)
|
||||
{
|
||||
return match prompter.as_mut() {
|
||||
Some(prompter) => match prompter.decide(&request) {
|
||||
|
||||
364
rust/crates/runtime/src/sandbox.rs
Normal file
364
rust/crates/runtime/src/sandbox.rs
Normal file
@@ -0,0 +1,364 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum FilesystemIsolationMode {
|
||||
Off,
|
||||
#[default]
|
||||
WorkspaceOnly,
|
||||
AllowList,
|
||||
}
|
||||
|
||||
impl FilesystemIsolationMode {
|
||||
#[must_use]
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Off => "off",
|
||||
Self::WorkspaceOnly => "workspace-only",
|
||||
Self::AllowList => "allow-list",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
pub struct SandboxConfig {
|
||||
pub enabled: Option<bool>,
|
||||
pub namespace_restrictions: Option<bool>,
|
||||
pub network_isolation: Option<bool>,
|
||||
pub filesystem_mode: Option<FilesystemIsolationMode>,
|
||||
pub allowed_mounts: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
pub struct SandboxRequest {
|
||||
pub enabled: bool,
|
||||
pub namespace_restrictions: bool,
|
||||
pub network_isolation: bool,
|
||||
pub filesystem_mode: FilesystemIsolationMode,
|
||||
pub allowed_mounts: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
pub struct ContainerEnvironment {
|
||||
pub in_container: bool,
|
||||
pub markers: Vec<String>,
|
||||
}
|
||||
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
pub struct SandboxStatus {
|
||||
pub enabled: bool,
|
||||
pub requested: SandboxRequest,
|
||||
pub supported: bool,
|
||||
pub active: bool,
|
||||
pub namespace_supported: bool,
|
||||
pub namespace_active: bool,
|
||||
pub network_supported: bool,
|
||||
pub network_active: bool,
|
||||
pub filesystem_mode: FilesystemIsolationMode,
|
||||
pub filesystem_active: bool,
|
||||
pub allowed_mounts: Vec<String>,
|
||||
pub in_container: bool,
|
||||
pub container_markers: Vec<String>,
|
||||
pub fallback_reason: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SandboxDetectionInputs<'a> {
|
||||
pub env_pairs: Vec<(String, String)>,
|
||||
pub dockerenv_exists: bool,
|
||||
pub containerenv_exists: bool,
|
||||
pub proc_1_cgroup: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct LinuxSandboxCommand {
|
||||
pub program: String,
|
||||
pub args: Vec<String>,
|
||||
pub env: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
impl SandboxConfig {
|
||||
#[must_use]
|
||||
pub fn resolve_request(
|
||||
&self,
|
||||
enabled_override: Option<bool>,
|
||||
namespace_override: Option<bool>,
|
||||
network_override: Option<bool>,
|
||||
filesystem_mode_override: Option<FilesystemIsolationMode>,
|
||||
allowed_mounts_override: Option<Vec<String>>,
|
||||
) -> SandboxRequest {
|
||||
SandboxRequest {
|
||||
enabled: enabled_override.unwrap_or(self.enabled.unwrap_or(true)),
|
||||
namespace_restrictions: namespace_override
|
||||
.unwrap_or(self.namespace_restrictions.unwrap_or(true)),
|
||||
network_isolation: network_override.unwrap_or(self.network_isolation.unwrap_or(false)),
|
||||
filesystem_mode: filesystem_mode_override
|
||||
.or(self.filesystem_mode)
|
||||
.unwrap_or_default(),
|
||||
allowed_mounts: allowed_mounts_override.unwrap_or_else(|| self.allowed_mounts.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn detect_container_environment() -> ContainerEnvironment {
|
||||
let proc_1_cgroup = fs::read_to_string("/proc/1/cgroup").ok();
|
||||
detect_container_environment_from(SandboxDetectionInputs {
|
||||
env_pairs: env::vars().collect(),
|
||||
dockerenv_exists: Path::new("/.dockerenv").exists(),
|
||||
containerenv_exists: Path::new("/run/.containerenv").exists(),
|
||||
proc_1_cgroup: proc_1_cgroup.as_deref(),
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn detect_container_environment_from(
|
||||
inputs: SandboxDetectionInputs<'_>,
|
||||
) -> ContainerEnvironment {
|
||||
let mut markers = Vec::new();
|
||||
if inputs.dockerenv_exists {
|
||||
markers.push("/.dockerenv".to_string());
|
||||
}
|
||||
if inputs.containerenv_exists {
|
||||
markers.push("/run/.containerenv".to_string());
|
||||
}
|
||||
for (key, value) in inputs.env_pairs {
|
||||
let normalized = key.to_ascii_lowercase();
|
||||
if matches!(
|
||||
normalized.as_str(),
|
||||
"container" | "docker" | "podman" | "kubernetes_service_host"
|
||||
) && !value.is_empty()
|
||||
{
|
||||
markers.push(format!("env:{key}={value}"));
|
||||
}
|
||||
}
|
||||
if let Some(cgroup) = inputs.proc_1_cgroup {
|
||||
for needle in ["docker", "containerd", "kubepods", "podman", "libpod"] {
|
||||
if cgroup.contains(needle) {
|
||||
markers.push(format!("/proc/1/cgroup:{needle}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
markers.sort();
|
||||
markers.dedup();
|
||||
ContainerEnvironment {
|
||||
in_container: !markers.is_empty(),
|
||||
markers,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn resolve_sandbox_status(config: &SandboxConfig, cwd: &Path) -> SandboxStatus {
|
||||
let request = config.resolve_request(None, None, None, None, None);
|
||||
resolve_sandbox_status_for_request(&request, cwd)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn resolve_sandbox_status_for_request(request: &SandboxRequest, cwd: &Path) -> SandboxStatus {
|
||||
let container = detect_container_environment();
|
||||
let namespace_supported = cfg!(target_os = "linux") && command_exists("unshare");
|
||||
let network_supported = namespace_supported;
|
||||
let filesystem_active =
|
||||
request.enabled && request.filesystem_mode != FilesystemIsolationMode::Off;
|
||||
let mut fallback_reasons = Vec::new();
|
||||
|
||||
if request.enabled && request.namespace_restrictions && !namespace_supported {
|
||||
fallback_reasons
|
||||
.push("namespace isolation unavailable (requires Linux with `unshare`)".to_string());
|
||||
}
|
||||
if request.enabled && request.network_isolation && !network_supported {
|
||||
fallback_reasons
|
||||
.push("network isolation unavailable (requires Linux with `unshare`)".to_string());
|
||||
}
|
||||
if request.enabled
|
||||
&& request.filesystem_mode == FilesystemIsolationMode::AllowList
|
||||
&& request.allowed_mounts.is_empty()
|
||||
{
|
||||
fallback_reasons
|
||||
.push("filesystem allow-list requested without configured mounts".to_string());
|
||||
}
|
||||
|
||||
let active = request.enabled
|
||||
&& (!request.namespace_restrictions || namespace_supported)
|
||||
&& (!request.network_isolation || network_supported);
|
||||
|
||||
let allowed_mounts = normalize_mounts(&request.allowed_mounts, cwd);
|
||||
|
||||
SandboxStatus {
|
||||
enabled: request.enabled,
|
||||
requested: request.clone(),
|
||||
supported: namespace_supported,
|
||||
active,
|
||||
namespace_supported,
|
||||
namespace_active: request.enabled && request.namespace_restrictions && namespace_supported,
|
||||
network_supported,
|
||||
network_active: request.enabled && request.network_isolation && network_supported,
|
||||
filesystem_mode: request.filesystem_mode,
|
||||
filesystem_active,
|
||||
allowed_mounts,
|
||||
in_container: container.in_container,
|
||||
container_markers: container.markers,
|
||||
fallback_reason: (!fallback_reasons.is_empty()).then(|| fallback_reasons.join("; ")),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn build_linux_sandbox_command(
|
||||
command: &str,
|
||||
cwd: &Path,
|
||||
status: &SandboxStatus,
|
||||
) -> Option<LinuxSandboxCommand> {
|
||||
if !cfg!(target_os = "linux")
|
||||
|| !status.enabled
|
||||
|| (!status.namespace_active && !status.network_active)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut args = vec![
|
||||
"--user".to_string(),
|
||||
"--map-root-user".to_string(),
|
||||
"--mount".to_string(),
|
||||
"--ipc".to_string(),
|
||||
"--pid".to_string(),
|
||||
"--uts".to_string(),
|
||||
"--fork".to_string(),
|
||||
];
|
||||
if status.network_active {
|
||||
args.push("--net".to_string());
|
||||
}
|
||||
args.push("sh".to_string());
|
||||
args.push("-lc".to_string());
|
||||
args.push(command.to_string());
|
||||
|
||||
let sandbox_home = cwd.join(".sandbox-home");
|
||||
let sandbox_tmp = cwd.join(".sandbox-tmp");
|
||||
let mut env = vec![
|
||||
("HOME".to_string(), sandbox_home.display().to_string()),
|
||||
("TMPDIR".to_string(), sandbox_tmp.display().to_string()),
|
||||
(
|
||||
"CLAWD_SANDBOX_FILESYSTEM_MODE".to_string(),
|
||||
status.filesystem_mode.as_str().to_string(),
|
||||
),
|
||||
(
|
||||
"CLAWD_SANDBOX_ALLOWED_MOUNTS".to_string(),
|
||||
status.allowed_mounts.join(":"),
|
||||
),
|
||||
];
|
||||
if let Ok(path) = env::var("PATH") {
|
||||
env.push(("PATH".to_string(), path));
|
||||
}
|
||||
|
||||
Some(LinuxSandboxCommand {
|
||||
program: "unshare".to_string(),
|
||||
args,
|
||||
env,
|
||||
})
|
||||
}
|
||||
|
||||
fn normalize_mounts(mounts: &[String], cwd: &Path) -> Vec<String> {
|
||||
let cwd = cwd.to_path_buf();
|
||||
mounts
|
||||
.iter()
|
||||
.map(|mount| {
|
||||
let path = PathBuf::from(mount);
|
||||
if path.is_absolute() {
|
||||
path
|
||||
} else {
|
||||
cwd.join(path)
|
||||
}
|
||||
})
|
||||
.map(|path| path.display().to_string())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn command_exists(command: &str) -> bool {
|
||||
env::var_os("PATH")
|
||||
.is_some_and(|paths| env::split_paths(&paths).any(|path| path.join(command).exists()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
build_linux_sandbox_command, detect_container_environment_from, FilesystemIsolationMode,
|
||||
SandboxConfig, SandboxDetectionInputs,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn detects_container_markers_from_multiple_sources() {
|
||||
let detected = detect_container_environment_from(SandboxDetectionInputs {
|
||||
env_pairs: vec![("container".to_string(), "docker".to_string())],
|
||||
dockerenv_exists: true,
|
||||
containerenv_exists: false,
|
||||
proc_1_cgroup: Some("12:memory:/docker/abc"),
|
||||
});
|
||||
|
||||
assert!(detected.in_container);
|
||||
assert!(detected
|
||||
.markers
|
||||
.iter()
|
||||
.any(|marker| marker == "/.dockerenv"));
|
||||
assert!(detected
|
||||
.markers
|
||||
.iter()
|
||||
.any(|marker| marker == "env:container=docker"));
|
||||
assert!(detected
|
||||
.markers
|
||||
.iter()
|
||||
.any(|marker| marker == "/proc/1/cgroup:docker"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolves_request_with_overrides() {
|
||||
let config = SandboxConfig {
|
||||
enabled: Some(true),
|
||||
namespace_restrictions: Some(true),
|
||||
network_isolation: Some(false),
|
||||
filesystem_mode: Some(FilesystemIsolationMode::WorkspaceOnly),
|
||||
allowed_mounts: vec!["logs".to_string()],
|
||||
};
|
||||
|
||||
let request = config.resolve_request(
|
||||
Some(true),
|
||||
Some(false),
|
||||
Some(true),
|
||||
Some(FilesystemIsolationMode::AllowList),
|
||||
Some(vec!["tmp".to_string()]),
|
||||
);
|
||||
|
||||
assert!(request.enabled);
|
||||
assert!(!request.namespace_restrictions);
|
||||
assert!(request.network_isolation);
|
||||
assert_eq!(request.filesystem_mode, FilesystemIsolationMode::AllowList);
|
||||
assert_eq!(request.allowed_mounts, vec!["tmp"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_linux_launcher_with_network_flag_when_requested() {
|
||||
let config = SandboxConfig::default();
|
||||
let status = super::resolve_sandbox_status_for_request(
|
||||
&config.resolve_request(
|
||||
Some(true),
|
||||
Some(true),
|
||||
Some(true),
|
||||
Some(FilesystemIsolationMode::WorkspaceOnly),
|
||||
None,
|
||||
),
|
||||
Path::new("/workspace"),
|
||||
);
|
||||
|
||||
if let Some(launcher) =
|
||||
build_linux_sandbox_command("printf hi", Path::new("/workspace"), &status)
|
||||
{
|
||||
assert_eq!(launcher.program, "unshare");
|
||||
assert!(launcher.args.iter().any(|arg| arg == "--mount"));
|
||||
assert!(launcher.args.iter().any(|arg| arg == "--net") == status.network_active);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,8 @@ commands = { path = "../commands" }
|
||||
compat-harness = { path = "../compat-harness" }
|
||||
crossterm = "0.28"
|
||||
pulldown-cmark = "0.13"
|
||||
reqwest = { version = "0.12", default-features = false, features = ["blocking", "json", "rustls-tls"] }
|
||||
runtime = { path = "../runtime" }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
sha2 = "0.10"
|
||||
syntect = "5"
|
||||
tokio = { version = "1", features = ["rt-multi-thread", "time"] }
|
||||
tools = { path = "../tools" }
|
||||
|
||||
@@ -3,7 +3,6 @@ mod render;
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::env;
|
||||
use std::fmt::Write as _;
|
||||
use std::fs;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::net::TcpListener;
|
||||
@@ -22,18 +21,15 @@ use commands::{
|
||||
};
|
||||
use compat_harness::{extract_manifest, UpstreamPaths};
|
||||
use render::{Spinner, TerminalRenderer};
|
||||
use reqwest::blocking::Client;
|
||||
use runtime::{
|
||||
clear_oauth_credentials, generate_pkce_pair, generate_state, load_system_prompt,
|
||||
parse_oauth_callback_request_target, save_oauth_credentials, ApiClient, ApiRequest,
|
||||
AssistantEvent, CompactionConfig, ConfigLoader, ConfigSource, ContentBlock,
|
||||
parse_oauth_callback_request_target, resolve_sandbox_status, save_oauth_credentials, ApiClient,
|
||||
ApiRequest, AssistantEvent, CompactionConfig, ConfigLoader, ConfigSource, ContentBlock,
|
||||
ConversationMessage, ConversationRuntime, MessageRole, OAuthAuthorizationRequest,
|
||||
OAuthTokenExchangeRequest, PermissionMode, PermissionPolicy, ProjectContext, RuntimeError,
|
||||
Session, TokenUsage, ToolError, ToolExecutor, UsageTracker,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use sha2::{Digest, Sha256};
|
||||
use tools::{execute_tool, mvp_tool_specs, ToolSpec};
|
||||
|
||||
const DEFAULT_MODEL: &str = "claude-sonnet-4-20250514";
|
||||
@@ -43,18 +39,6 @@ const DEFAULT_OAUTH_CALLBACK_PORT: u16 = 4545;
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
const BUILD_TARGET: Option<&str> = option_env!("TARGET");
|
||||
const GIT_SHA: Option<&str> = option_env!("GIT_SHA");
|
||||
const SELF_UPDATE_REPOSITORY: &str = "instructkr/clawd-code";
|
||||
const SELF_UPDATE_LATEST_RELEASE_URL: &str =
|
||||
"https://api.github.com/repos/instructkr/clawd-code/releases/latest";
|
||||
const SELF_UPDATE_USER_AGENT: &str = "rusty-claude-cli-self-update";
|
||||
const CHECKSUM_ASSET_CANDIDATES: &[&str] = &[
|
||||
"SHA256SUMS",
|
||||
"SHA256SUMS.txt",
|
||||
"sha256sums",
|
||||
"sha256sums.txt",
|
||||
"checksums.txt",
|
||||
"checksums.sha256",
|
||||
];
|
||||
|
||||
type AllowedToolSet = BTreeSet<String>;
|
||||
|
||||
@@ -76,7 +60,6 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
CliAction::BootstrapPlan => print_bootstrap_plan(),
|
||||
CliAction::PrintSystemPrompt { cwd, date } => print_system_prompt(cwd, date),
|
||||
CliAction::Version => print_version(),
|
||||
CliAction::SelfUpdate => run_self_update()?,
|
||||
CliAction::ResumeSession {
|
||||
session_path,
|
||||
commands,
|
||||
@@ -110,7 +93,6 @@ enum CliAction {
|
||||
date: String,
|
||||
},
|
||||
Version,
|
||||
SelfUpdate,
|
||||
ResumeSession {
|
||||
session_path: PathBuf,
|
||||
commands: Vec<String>,
|
||||
@@ -246,7 +228,6 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
"dump-manifests" => Ok(CliAction::DumpManifests),
|
||||
"bootstrap-plan" => Ok(CliAction::BootstrapPlan),
|
||||
"system-prompt" => parse_system_prompt_args(&rest[1..]),
|
||||
"self-update" => Ok(CliAction::SelfUpdate),
|
||||
"login" => Ok(CliAction::Login),
|
||||
"logout" => Ok(CliAction::Logout),
|
||||
"prompt" => {
|
||||
@@ -553,375 +534,6 @@ fn print_version() {
|
||||
println!("{}", render_version_report());
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
struct GitHubRelease {
|
||||
tag_name: String,
|
||||
#[serde(default)]
|
||||
body: String,
|
||||
#[serde(default)]
|
||||
assets: Vec<GitHubReleaseAsset>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
struct GitHubReleaseAsset {
|
||||
name: String,
|
||||
browser_download_url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
struct SelectedReleaseAssets {
|
||||
binary: GitHubReleaseAsset,
|
||||
checksum: GitHubReleaseAsset,
|
||||
}
|
||||
|
||||
fn run_self_update() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(release) = fetch_latest_release()? else {
|
||||
println!(
|
||||
"{}",
|
||||
render_update_report(
|
||||
"No published release available",
|
||||
Some(VERSION),
|
||||
None,
|
||||
Some("GitHub latest release endpoint returned no published release for instructkr/clawd-code."),
|
||||
None,
|
||||
)
|
||||
);
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let latest_version = normalize_version_tag(&release.tag_name);
|
||||
if !is_newer_version(VERSION, &latest_version) {
|
||||
println!(
|
||||
"{}",
|
||||
render_update_report(
|
||||
"Already up to date",
|
||||
Some(VERSION),
|
||||
Some(&latest_version),
|
||||
Some("Current binary already matches the latest published release."),
|
||||
Some(&release.body),
|
||||
)
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let selected = match select_release_assets(&release) {
|
||||
Ok(selected) => selected,
|
||||
Err(message) => {
|
||||
println!(
|
||||
"{}",
|
||||
render_update_report(
|
||||
"Release found, but no installable asset matched this platform",
|
||||
Some(VERSION),
|
||||
Some(&latest_version),
|
||||
Some(&message),
|
||||
Some(&release.body),
|
||||
)
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let client = build_self_update_client()?;
|
||||
let binary_bytes = download_bytes(&client, &selected.binary.browser_download_url)?;
|
||||
let checksum_manifest = download_text(&client, &selected.checksum.browser_download_url)?;
|
||||
let expected_checksum = parse_checksum_for_asset(&checksum_manifest, &selected.binary.name)
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"checksum manifest did not contain an entry for {}",
|
||||
selected.binary.name
|
||||
)
|
||||
})?;
|
||||
let actual_checksum = sha256_hex(&binary_bytes);
|
||||
if actual_checksum != expected_checksum {
|
||||
return Err(format!(
|
||||
"downloaded asset checksum mismatch for {} (expected {}, got {})",
|
||||
selected.binary.name, expected_checksum, actual_checksum
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
replace_current_executable(&binary_bytes)?;
|
||||
|
||||
println!(
|
||||
"{}",
|
||||
render_update_report(
|
||||
"Update installed",
|
||||
Some(VERSION),
|
||||
Some(&latest_version),
|
||||
Some(&format!(
|
||||
"Installed {} from GitHub release assets for {}.",
|
||||
selected.binary.name,
|
||||
current_target()
|
||||
)),
|
||||
Some(&release.body),
|
||||
)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fetch_latest_release() -> Result<Option<GitHubRelease>, Box<dyn std::error::Error>> {
|
||||
let client = build_self_update_client()?;
|
||||
let response = client
|
||||
.get(SELF_UPDATE_LATEST_RELEASE_URL)
|
||||
.header(reqwest::header::ACCEPT, "application/vnd.github+json")
|
||||
.send()?;
|
||||
|
||||
if response.status() == reqwest::StatusCode::NOT_FOUND {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let response = response.error_for_status()?;
|
||||
Ok(Some(response.json()?))
|
||||
}
|
||||
|
||||
fn build_self_update_client() -> Result<Client, reqwest::Error> {
|
||||
Client::builder().user_agent(SELF_UPDATE_USER_AGENT).build()
|
||||
}
|
||||
|
||||
fn download_bytes(client: &Client, url: &str) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
||||
let response = client.get(url).send()?.error_for_status()?;
|
||||
Ok(response.bytes()?.to_vec())
|
||||
}
|
||||
|
||||
fn download_text(client: &Client, url: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let response = client.get(url).send()?.error_for_status()?;
|
||||
Ok(response.text()?)
|
||||
}
|
||||
|
||||
fn normalize_version_tag(version: &str) -> String {
|
||||
version.trim().trim_start_matches('v').to_string()
|
||||
}
|
||||
|
||||
fn is_newer_version(current: &str, latest: &str) -> bool {
|
||||
compare_versions(latest, current).is_gt()
|
||||
}
|
||||
|
||||
fn current_target() -> String {
|
||||
BUILD_TARGET.map_or_else(default_target_triple, str::to_string)
|
||||
}
|
||||
|
||||
fn release_asset_candidates() -> Vec<String> {
|
||||
let mut candidates = target_name_candidates()
|
||||
.into_iter()
|
||||
.flat_map(|target| {
|
||||
let mut names = vec![format!("rusty-claude-cli-{target}")];
|
||||
if env::consts::OS == "windows" {
|
||||
names.push(format!("rusty-claude-cli-{target}.exe"));
|
||||
}
|
||||
names
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
if env::consts::OS == "windows" {
|
||||
candidates.push("rusty-claude-cli.exe".to_string());
|
||||
}
|
||||
candidates.push("rusty-claude-cli".to_string());
|
||||
candidates.sort();
|
||||
candidates.dedup();
|
||||
candidates
|
||||
}
|
||||
|
||||
fn select_release_assets(release: &GitHubRelease) -> Result<SelectedReleaseAssets, String> {
|
||||
let binary = release_asset_candidates()
|
||||
.into_iter()
|
||||
.find_map(|candidate| {
|
||||
release
|
||||
.assets
|
||||
.iter()
|
||||
.find(|asset| asset.name == candidate)
|
||||
.cloned()
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"no binary asset matched target {} (expected one of: {})",
|
||||
current_target(),
|
||||
release_asset_candidates().join(", ")
|
||||
)
|
||||
})?;
|
||||
|
||||
let checksum = CHECKSUM_ASSET_CANDIDATES
|
||||
.iter()
|
||||
.find_map(|candidate| {
|
||||
release
|
||||
.assets
|
||||
.iter()
|
||||
.find(|asset| asset.name == *candidate)
|
||||
.cloned()
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"release did not include a checksum manifest (expected one of: {})",
|
||||
CHECKSUM_ASSET_CANDIDATES.join(", ")
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(SelectedReleaseAssets { binary, checksum })
|
||||
}
|
||||
|
||||
fn parse_checksum_for_asset(manifest: &str, asset_name: &str) -> Option<String> {
|
||||
manifest.lines().find_map(|line| {
|
||||
let trimmed = line.trim();
|
||||
if trimmed.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if let Some((left, right)) = trimmed.split_once(" = ") {
|
||||
return left
|
||||
.strip_prefix("SHA256 (")
|
||||
.and_then(|value| value.strip_suffix(')'))
|
||||
.filter(|file| *file == asset_name)
|
||||
.map(|_| right.to_ascii_lowercase());
|
||||
}
|
||||
let mut parts = trimmed.split_whitespace();
|
||||
let checksum = parts.next()?;
|
||||
let file = parts
|
||||
.next_back()
|
||||
.or_else(|| parts.next())?
|
||||
.trim_start_matches('*');
|
||||
(file == asset_name).then(|| checksum.to_ascii_lowercase())
|
||||
})
|
||||
}
|
||||
|
||||
fn sha256_hex(bytes: &[u8]) -> String {
|
||||
format!("{:x}", Sha256::digest(bytes))
|
||||
}
|
||||
|
||||
fn replace_current_executable(binary_bytes: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let current = env::current_exe()?;
|
||||
replace_executable_at(¤t, binary_bytes)
|
||||
}
|
||||
|
||||
fn replace_executable_at(
|
||||
current: &Path,
|
||||
binary_bytes: &[u8],
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let temp_path = current.with_extension("download");
|
||||
let backup_path = current.with_extension("bak");
|
||||
|
||||
if backup_path.exists() {
|
||||
fs::remove_file(&backup_path)?;
|
||||
}
|
||||
fs::write(&temp_path, binary_bytes)?;
|
||||
copy_executable_permissions(current, &temp_path)?;
|
||||
|
||||
fs::rename(current, &backup_path)?;
|
||||
if let Err(error) = fs::rename(&temp_path, current) {
|
||||
let _ = fs::rename(&backup_path, current);
|
||||
let _ = fs::remove_file(&temp_path);
|
||||
return Err(format!("failed to replace current executable: {error}").into());
|
||||
}
|
||||
|
||||
if let Err(error) = fs::remove_file(&backup_path) {
|
||||
eprintln!(
|
||||
"warning: failed to remove self-update backup {}: {error}",
|
||||
backup_path.display()
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn copy_executable_permissions(
|
||||
source: &Path,
|
||||
destination: &Path,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let mode = fs::metadata(source)?.permissions().mode();
|
||||
fs::set_permissions(destination, fs::Permissions::from_mode(mode))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
fn copy_executable_permissions(
|
||||
_source: &Path,
|
||||
_destination: &Path,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_update_report(
|
||||
result: &str,
|
||||
current_version: Option<&str>,
|
||||
latest_version: Option<&str>,
|
||||
detail: Option<&str>,
|
||||
changelog: Option<&str>,
|
||||
) -> String {
|
||||
let mut report = String::from(
|
||||
"Self-update
|
||||
",
|
||||
);
|
||||
let _ = writeln!(report, " Repository {SELF_UPDATE_REPOSITORY}");
|
||||
let _ = writeln!(report, " Result {result}");
|
||||
if let Some(current_version) = current_version {
|
||||
let _ = writeln!(report, " Current version {current_version}");
|
||||
}
|
||||
if let Some(latest_version) = latest_version {
|
||||
let _ = writeln!(report, " Latest version {latest_version}");
|
||||
}
|
||||
if let Some(detail) = detail {
|
||||
let _ = writeln!(report, " Detail {detail}");
|
||||
}
|
||||
let trimmed = changelog.map(str::trim).filter(|value| !value.is_empty());
|
||||
if let Some(changelog) = trimmed {
|
||||
report.push_str(
|
||||
"
|
||||
Changelog
|
||||
",
|
||||
);
|
||||
report.push_str(changelog);
|
||||
}
|
||||
report.trim_end().to_string()
|
||||
}
|
||||
|
||||
fn compare_versions(left: &str, right: &str) -> std::cmp::Ordering {
|
||||
let left = normalize_version_tag(left);
|
||||
let right = normalize_version_tag(right);
|
||||
let left_parts = version_components(&left);
|
||||
let right_parts = version_components(&right);
|
||||
let max_len = left_parts.len().max(right_parts.len());
|
||||
for index in 0..max_len {
|
||||
let left_part = *left_parts.get(index).unwrap_or(&0);
|
||||
let right_part = *right_parts.get(index).unwrap_or(&0);
|
||||
match left_part.cmp(&right_part) {
|
||||
std::cmp::Ordering::Equal => {}
|
||||
ordering => return ordering,
|
||||
}
|
||||
}
|
||||
std::cmp::Ordering::Equal
|
||||
}
|
||||
|
||||
fn version_components(version: &str) -> Vec<u64> {
|
||||
version
|
||||
.split(['.', '-'])
|
||||
.map(|part| {
|
||||
part.chars()
|
||||
.take_while(char::is_ascii_digit)
|
||||
.collect::<String>()
|
||||
})
|
||||
.filter(|part| !part.is_empty())
|
||||
.filter_map(|part| part.parse::<u64>().ok())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn default_target_triple() -> String {
|
||||
let os = match env::consts::OS {
|
||||
"linux" => "unknown-linux-gnu",
|
||||
"macos" => "apple-darwin",
|
||||
"windows" => "pc-windows-msvc",
|
||||
other => other,
|
||||
};
|
||||
format!("{}-{os}", env::consts::ARCH)
|
||||
}
|
||||
|
||||
fn target_name_candidates() -> Vec<String> {
|
||||
let mut candidates = Vec::new();
|
||||
if let Some(target) = BUILD_TARGET {
|
||||
candidates.push(target.to_string());
|
||||
}
|
||||
candidates.push(default_target_triple());
|
||||
candidates.push(format!("{}-{}", env::consts::ARCH, env::consts::OS));
|
||||
candidates
|
||||
}
|
||||
|
||||
fn resume_session(session_path: &Path, commands: &[String]) {
|
||||
let session = match Session::load_from_path(session_path) {
|
||||
Ok(session) => session,
|
||||
@@ -979,6 +591,7 @@ struct StatusContext {
|
||||
memory_file_count: usize,
|
||||
project_root: Option<PathBuf>,
|
||||
git_branch: Option<String>,
|
||||
sandbox_status: runtime::SandboxStatus,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -1228,6 +841,18 @@ fn run_resume_command(
|
||||
)),
|
||||
})
|
||||
}
|
||||
SlashCommand::Sandbox => {
|
||||
let cwd = env::current_dir()?;
|
||||
let loader = ConfigLoader::default_for(&cwd);
|
||||
let runtime_config = loader.load()?;
|
||||
Ok(ResumeCommandOutcome {
|
||||
session: session.clone(),
|
||||
message: Some(format_sandbox_report(&resolve_sandbox_status(
|
||||
runtime_config.sandbox(),
|
||||
&cwd,
|
||||
))),
|
||||
})
|
||||
}
|
||||
SlashCommand::Cost => {
|
||||
let usage = UsageTracker::from_session(session).cumulative_usage();
|
||||
Ok(ResumeCommandOutcome {
|
||||
@@ -1479,6 +1104,10 @@ impl LiveCli {
|
||||
self.print_status();
|
||||
false
|
||||
}
|
||||
SlashCommand::Sandbox => {
|
||||
Self::print_sandbox_status();
|
||||
false
|
||||
}
|
||||
SlashCommand::Compact => {
|
||||
self.compact()?;
|
||||
false
|
||||
@@ -1550,6 +1179,18 @@ impl LiveCli {
|
||||
);
|
||||
}
|
||||
|
||||
fn print_sandbox_status() {
|
||||
let cwd = env::current_dir().expect("current dir");
|
||||
let loader = ConfigLoader::default_for(&cwd);
|
||||
let runtime_config = loader
|
||||
.load()
|
||||
.unwrap_or_else(|_| runtime::RuntimeConfig::empty());
|
||||
println!(
|
||||
"{}",
|
||||
format_sandbox_report(&resolve_sandbox_status(runtime_config.sandbox(), &cwd))
|
||||
);
|
||||
}
|
||||
|
||||
fn set_model(&mut self, model: Option<String>) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
let Some(model) = model else {
|
||||
println!(
|
||||
@@ -1925,6 +1566,7 @@ fn status_context(
|
||||
let project_context = ProjectContext::discover_with_git(&cwd, DEFAULT_DATE)?;
|
||||
let (project_root, git_branch) =
|
||||
parse_git_status_metadata(project_context.git_status.as_deref());
|
||||
let sandbox_status = resolve_sandbox_status(runtime_config.sandbox(), &cwd);
|
||||
Ok(StatusContext {
|
||||
cwd,
|
||||
session_path: session_path.map(Path::to_path_buf),
|
||||
@@ -1933,6 +1575,7 @@ fn status_context(
|
||||
memory_file_count: project_context.instruction_files.len(),
|
||||
project_root,
|
||||
git_branch,
|
||||
sandbox_status,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1985,6 +1628,7 @@ fn format_status_report(
|
||||
context.discovered_config_files,
|
||||
context.memory_file_count,
|
||||
),
|
||||
format_sandbox_report(&context.sandbox_status),
|
||||
]
|
||||
.join(
|
||||
"
|
||||
@@ -1993,6 +1637,49 @@ fn format_status_report(
|
||||
)
|
||||
}
|
||||
|
||||
fn format_sandbox_report(status: &runtime::SandboxStatus) -> String {
|
||||
format!(
|
||||
"Sandbox
|
||||
Enabled {}
|
||||
Active {}
|
||||
Supported {}
|
||||
In container {}
|
||||
Requested ns {}
|
||||
Active ns {}
|
||||
Requested net {}
|
||||
Active net {}
|
||||
Filesystem mode {}
|
||||
Filesystem active {}
|
||||
Allowed mounts {}
|
||||
Markers {}
|
||||
Fallback reason {}",
|
||||
status.enabled,
|
||||
status.active,
|
||||
status.supported,
|
||||
status.in_container,
|
||||
status.requested.namespace_restrictions,
|
||||
status.namespace_active,
|
||||
status.requested.network_isolation,
|
||||
status.network_active,
|
||||
status.filesystem_mode.as_str(),
|
||||
status.filesystem_active,
|
||||
if status.allowed_mounts.is_empty() {
|
||||
"<none>".to_string()
|
||||
} else {
|
||||
status.allowed_mounts.join(", ")
|
||||
},
|
||||
if status.container_markers.is_empty() {
|
||||
"<none>".to_string()
|
||||
} else {
|
||||
status.container_markers.join(", ")
|
||||
},
|
||||
status
|
||||
.fallback_reason
|
||||
.clone()
|
||||
.unwrap_or_else(|| "<none>".to_string()),
|
||||
)
|
||||
}
|
||||
|
||||
fn render_config_report(section: Option<&str>) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let cwd = env::current_dir()?;
|
||||
let loader = ConfigLoader::default_for(&cwd);
|
||||
@@ -2746,8 +2433,6 @@ fn print_help() {
|
||||
println!(" rusty-claude-cli system-prompt [--cwd PATH] [--date YYYY-MM-DD]");
|
||||
println!(" rusty-claude-cli login");
|
||||
println!(" rusty-claude-cli logout");
|
||||
println!(" rusty-claude-cli self-update");
|
||||
println!(" Update the installed binary from the latest GitHub release");
|
||||
println!();
|
||||
println!("Flags:");
|
||||
println!(" --model MODEL Override the active model");
|
||||
@@ -2774,7 +2459,6 @@ fn print_help() {
|
||||
println!(" rusty-claude-cli --allowedTools read,glob \"summarize Cargo.toml\"");
|
||||
println!(" rusty-claude-cli --resume session.json /status /diff /export notes.txt");
|
||||
println!(" rusty-claude-cli login");
|
||||
println!(" rusty-claude-cli self-update");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -2783,11 +2467,10 @@ mod tests {
|
||||
filter_tool_specs, format_compact_report, format_cost_report, format_init_report,
|
||||
format_model_report, format_model_switch_report, format_permissions_report,
|
||||
format_permissions_switch_report, format_resume_report, format_status_report,
|
||||
format_tool_call_start, format_tool_result, is_newer_version, normalize_permission_mode,
|
||||
normalize_version_tag, parse_args, parse_checksum_for_asset, parse_git_status_metadata,
|
||||
render_config_report, render_init_claude_md, render_memory_report, render_repl_help,
|
||||
render_update_report, resume_supported_slash_commands, select_release_assets,
|
||||
status_context, CliAction, CliOutputFormat, SlashCommand, StatusUsage, DEFAULT_MODEL,
|
||||
format_tool_call_start, format_tool_result, normalize_permission_mode, parse_args,
|
||||
parse_git_status_metadata, render_config_report, render_init_claude_md,
|
||||
render_memory_report, render_repl_help, resume_supported_slash_commands, status_context,
|
||||
CliAction, CliOutputFormat, SlashCommand, StatusUsage, DEFAULT_MODEL,
|
||||
};
|
||||
use runtime::{ContentBlock, ConversationMessage, MessageRole, PermissionMode};
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -2856,64 +2539,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_self_update_subcommand() {
|
||||
assert_eq!(
|
||||
parse_args(&["self-update".to_string()]).expect("self-update should parse"),
|
||||
CliAction::SelfUpdate
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize_version_tag_trims_v_prefix() {
|
||||
assert_eq!(normalize_version_tag("v0.1.0"), "0.1.0");
|
||||
assert_eq!(normalize_version_tag("0.1.0"), "0.1.0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detects_when_latest_version_differs() {
|
||||
assert!(!is_newer_version("0.1.0", "v0.1.0"));
|
||||
assert!(is_newer_version("0.1.0", "v0.2.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_checksum_manifest_for_named_asset() {
|
||||
let manifest = "abc123 *rusty-claude-cli\ndef456 other-file\n";
|
||||
assert_eq!(
|
||||
parse_checksum_for_asset(manifest, "rusty-claude-cli"),
|
||||
Some("abc123".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn select_release_assets_requires_checksum_file() {
|
||||
let release = super::GitHubRelease {
|
||||
tag_name: "v0.2.0".to_string(),
|
||||
body: String::new(),
|
||||
assets: vec![super::GitHubReleaseAsset {
|
||||
name: "rusty-claude-cli".to_string(),
|
||||
browser_download_url: "https://example.invalid/rusty-claude-cli".to_string(),
|
||||
}],
|
||||
};
|
||||
|
||||
let error = select_release_assets(&release).expect_err("missing checksum should error");
|
||||
assert!(error.contains("checksum manifest"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_report_includes_changelog_when_present() {
|
||||
let report = render_update_report(
|
||||
"Already up to date",
|
||||
Some("0.1.0"),
|
||||
Some("0.1.0"),
|
||||
Some("No action taken."),
|
||||
Some("- Added self-update"),
|
||||
);
|
||||
assert!(report.contains("Self-update"));
|
||||
assert!(report.contains("Changelog"));
|
||||
assert!(report.contains("- Added self-update"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_permission_mode_flag() {
|
||||
let args = vec!["--permission-mode=read-only".to_string()];
|
||||
@@ -3051,6 +2676,7 @@ mod tests {
|
||||
assert!(help.contains("REPL"));
|
||||
assert!(help.contains("/help"));
|
||||
assert!(help.contains("/status"));
|
||||
assert!(help.contains("/sandbox"));
|
||||
assert!(help.contains("/model [model]"));
|
||||
assert!(help.contains("/permissions [read-only|workspace-write|danger-full-access]"));
|
||||
assert!(help.contains("/clear [--confirm]"));
|
||||
@@ -3075,8 +2701,8 @@ mod tests {
|
||||
assert_eq!(
|
||||
names,
|
||||
vec![
|
||||
"help", "status", "compact", "clear", "cost", "config", "memory", "init", "diff",
|
||||
"version", "export",
|
||||
"help", "status", "sandbox", "compact", "clear", "cost", "config", "memory",
|
||||
"init", "diff", "version", "export",
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -3194,6 +2820,7 @@ mod tests {
|
||||
memory_file_count: 4,
|
||||
project_root: Some(PathBuf::from("/tmp")),
|
||||
git_branch: Some("main".to_string()),
|
||||
sandbox_status: runtime::SandboxStatus::default(),
|
||||
},
|
||||
);
|
||||
assert!(status.contains("Status"));
|
||||
@@ -3247,7 +2874,7 @@ mod tests {
|
||||
fn status_context_reads_real_workspace_metadata() {
|
||||
let context = status_context(None).expect("status context should load");
|
||||
assert!(context.cwd.is_absolute());
|
||||
assert!(context.discovered_config_files >= 3);
|
||||
assert_eq!(context.discovered_config_files, 5);
|
||||
assert!(context.loaded_config_files <= context.discovered_config_files);
|
||||
}
|
||||
|
||||
@@ -3355,3 +2982,17 @@ mod tests {
|
||||
assert!(done.contains("contents"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod sandbox_report_tests {
|
||||
use super::format_sandbox_report;
|
||||
|
||||
#[test]
|
||||
fn sandbox_report_renders_expected_fields() {
|
||||
let report = format_sandbox_report(&runtime::SandboxStatus::default());
|
||||
assert!(report.contains("Sandbox"));
|
||||
assert!(report.contains("Enabled"));
|
||||
assert!(report.contains("Filesystem mode"));
|
||||
assert!(report.contains("Fallback reason"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,11 @@ pub fn mvp_tool_specs() -> Vec<ToolSpec> {
|
||||
"timeout": { "type": "integer", "minimum": 1 },
|
||||
"description": { "type": "string" },
|
||||
"run_in_background": { "type": "boolean" },
|
||||
"dangerouslyDisableSandbox": { "type": "boolean" }
|
||||
"dangerouslyDisableSandbox": { "type": "boolean" },
|
||||
"namespaceRestrictions": { "type": "boolean" },
|
||||
"isolateNetwork": { "type": "boolean" },
|
||||
"filesystemMode": { "type": "string", "enum": ["off", "workspace-only", "allow-list"] },
|
||||
"allowedMounts": { "type": "array", "items": { "type": "string" } }
|
||||
},
|
||||
"required": ["command"],
|
||||
"additionalProperties": false
|
||||
@@ -2214,6 +2218,7 @@ fn execute_shell_command(
|
||||
structured_content: None,
|
||||
persisted_output_path: None,
|
||||
persisted_output_size: None,
|
||||
sandbox_status: None,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2251,6 +2256,7 @@ fn execute_shell_command(
|
||||
structured_content: None,
|
||||
persisted_output_path: None,
|
||||
persisted_output_size: None,
|
||||
sandbox_status: None,
|
||||
});
|
||||
}
|
||||
if started.elapsed() >= Duration::from_millis(timeout_ms) {
|
||||
@@ -2281,6 +2287,7 @@ Command exceeded timeout of {timeout_ms} ms",
|
||||
structured_content: None,
|
||||
persisted_output_path: None,
|
||||
persisted_output_size: None,
|
||||
sandbox_status: None,
|
||||
});
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
@@ -2307,6 +2314,7 @@ Command exceeded timeout of {timeout_ms} ms",
|
||||
structured_content: None,
|
||||
persisted_output_path: None,
|
||||
persisted_output_size: None,
|
||||
sandbox_status: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user