Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [".", "crates/sparkplane-core", "crates/sparkplane-ipc"]
members = [".", "crates/sparkplane-core", "crates/sparkplane-ipc", "crates/sparkplane-rtk"]
resolver = "3"

[workspace.package]
Expand Down Expand Up @@ -37,7 +37,7 @@ publish = false

[features]
default = []
appliance = ["dep:axum", "dep:axum-server", "dep:hmac", "dep:governor", "dep:rcgen", "dep:rusqlite", "dep:rusqlite_migration", "dep:rustls", "dep:secrecy", "dep:tower", "dep:utoipa", "dep:x509-parser", "dep:bollard", "dep:http-body-util", "dep:hyper", "dep:hyper-util", "dep:hf-hub", "dep:image", "dep:arc-swap", "dep:sparkplane-ipc", "dep:tempfile"]
appliance = ["dep:axum", "dep:axum-server", "dep:hmac", "dep:governor", "dep:rcgen", "dep:rusqlite", "dep:rusqlite_migration", "dep:rustls", "dep:secrecy", "dep:tower", "dep:utoipa", "dep:x509-parser", "dep:bollard", "dep:hf-hub", "dep:image", "dep:arc-swap", "dep:sparkplane-ipc", "dep:tempfile"]

[dependencies]
anyhow.workspace = true
Expand All @@ -52,6 +52,8 @@ futures-util.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
sparkplane-core.workspace = true
sparkplane-rtk = { path = "crates/sparkplane-rtk", version = "=0.49.0" }
shlex = "1"
sparkplane-ipc = { workspace = true, optional = true }
tempfile = { workspace = true, optional = true }
clap = { version = "4", features = ["derive", "env"] }
Expand All @@ -62,7 +64,7 @@ reqwest = { version = "0.12", default-features = false, features = ["blocking",
sha2 = "0.10"
base64 = "0.22"
minisign-verify = "0.2"
nix = { version = "0.29", features = ["fs"] }
nix = { version = "0.29", features = ["fs", "signal", "process"] }
uuid = { version = "1", features = ["v4"] }
zstd = "0.13"
walkdir = "2"
Expand All @@ -81,9 +83,9 @@ rusqlite = { version = "0.40.0", default-features = false, features = ["backup",
rusqlite_migration = { version = "2.6.0", default-features = false, optional = true }
governor = { version = "0.10.4", default-features = false, features = ["dashmap", "std"], optional = true }
bollard = { version = "0.21.1", default-features = false, features = ["pipe"], optional = true }
http-body-util = { version = "0.1", optional = true }
hyper = { version = "1", default-features = false, features = ["client", "http1"], optional = true }
hyper-util = { version = "0.1", default-features = false, features = ["tokio"], optional = true }
http-body-util = { version = "0.1" }
hyper = { version = "1", default-features = false, features = ["client", "server", "http1"] }
hyper-util = { version = "0.1", default-features = false, features = ["tokio"] }
hf-hub = { version = "1.0.0", default-features = false, features = ["rustls-tls"], optional = true }
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp"], optional = true }
arc-swap = { version = "1", optional = true }
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ 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).

Launches also default to `--eco-mode=max`, using RTK filters embedded in the
Sparkplane executable. Use `--eco-mode=none` to disable compression. When the
coding session exits, Sparkplane prints token usage and public cloud price
comparisons; `sparkplane <host> economics --json` reads the latest retained report.
See [session economics](docs/reference/spark.md#eco-mode-and-session-economics).

Vision launches also retain recent images automatically and archive older
originals for reopening. A private local adapter prunes historical image payloads
before upload, while the gateway enforces the qualified model limits. See
[image history and gateway limits](docs/reference/spark.md#image-history-and-upload-limits).

## Architecture

The unprivileged HTTPS agent owns state and protocol translation. A separate,
Expand Down
8 changes: 8 additions & 0 deletions configs/sparkplane/agent.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ allowed_client_cidrs = ["10.1.30.0/24"]
plain_http_loopback_only = true
executor_socket = "/run/sparkplane/executor.sock"

[gateway]
# Public uploads are normalized to the selected engine's stricter image policy.
request_body_bytes = 33554432
image_bytes = 16777216
image_pixels = 32000000 # Total source pixels across the request.
image_dimension = 16384
max_parallel_requests = 2

[models]
cache_root = "/var/lib/sparkplane/huggingface"
endpoint = "https://huggingface.co"
Expand Down
3 changes: 2 additions & 1 deletion configs/sparkplane/engines/vllm-qwen38-mmap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ arguments = [
"--speculative-config", "{\"method\":\"mtp\",\"num_speculative_tokens\":3}",
]
capabilities = ["text_generation", "tool_calling", "vision"]
vision = { processor_sha256 = "27225450ac9c6529872ee1924fcb0962ff5634834f817040f444118116f4e516", media_types = ["image/jpeg", "image/png", "image/webp"], max_bytes = 524288, max_total_bytes = 524288, max_count = 1, max_width = 4096, max_height = 4096, health_media_type = "image/png", health_image_base64 = "iVBORw0KGgoAAAANSUhEUgAAAOAAAADgAQAAAAAyVldMAAAAHUlEQVRYw+3BMQEAAADCoPVPbQZ/oAAAAAAAAHgMGWAAAct2tnAAAAAASUVORK5CYII=", health_image_sha256 = "1b8ab2918e9fb346d8ff5b7579372510b0d8b1566d590dac31aea311fff15fc6", health_prompt = "Name the single dominant color using one lowercase word.", health_expected_text = "black", health_max_tokens = 32, health_disable_thinking = true }
# Multi-frame requests retain the same total byte and dimension budgets.
vision = { processor_sha256 = "27225450ac9c6529872ee1924fcb0962ff5634834f817040f444118116f4e516", media_types = ["image/jpeg", "image/png", "image/webp"], max_bytes = 524288, max_total_bytes = 524288, max_count = 16, max_width = 4096, max_height = 4096, health_media_type = "image/png", health_image_base64 = "iVBORw0KGgoAAAANSUhEUgAAAOAAAADgAQAAAAAyVldMAAAAHUlEQVRYw+3BMQEAAADCoPVPbQZ/oAAAAAAAAHgMGWAAAct2tnAAAAAASUVORK5CYII=", health_image_sha256 = "1b8ab2918e9fb346d8ff5b7579372510b0d8b1566d590dac31aea311fff15fc6", health_prompt = "Name the single dominant color using one lowercase word.", health_expected_text = "black", health_max_tokens = 32, health_disable_thinking = true }
startup_protocol_probe = true
sampling = { temperature = 1.0, top_p = 0.95, top_k = 20, min_p = 0.0, presence_penalty = 0.0, repetition_penalty = 1.0, thinking_token_budget = 8192, reasoning_effort_map = { low = "low", medium = "medium", high = "xhigh", max = "xhigh" } }
280 changes: 280 additions & 0 deletions crates/sparkplane-rtk/ADAPTATION.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
--- upstream/src/core/toml_filter.rs
+++ src/core/toml_filter.rs
@@ -29,7 +29,7 @@
use std::sync::LazyLock;

// Built-in filters: concatenated from src/filters/*.toml by build.rs at compile time.
-const BUILTIN_TOML: &str = include_str!(concat!(env!("OUT_DIR"), "/builtin_filters.toml"));
+const BUILTIN_TOML: &str = include_str!("builtin_filters.toml");

// ---------------------------------------------------------------------------
// Deserialization types (TOML schema)
@@ -188,38 +188,12 @@
fn load() -> Self {
let mut filters = Vec::new();

- for path in crate::hooks::trust::gated_filter_paths() {
- Self::extend_with_trusted(&mut filters, &path);
- }
-
match Self::parse_and_compile(BUILTIN_TOML, "builtin") {
Ok(f) => filters.extend(f),
Err(e) => eprintln!("[rtk] warning: builtin filters: {}", e),
}

TomlFilterRegistry { filters }
- }
-
- fn extend_with_trusted(filters: &mut Vec<CompiledFilter>, path: &std::path::Path) {
- if !path.exists() {
- return;
- }
- let label = path.display().to_string();
- let (status, content) = crate::hooks::trust::check_trust_with_content(path)
- .unwrap_or((crate::hooks::trust::TrustStatus::Untrusted, None));
- match status {
- crate::hooks::trust::TrustStatus::Trusted
- | crate::hooks::trust::TrustStatus::EnvOverride => {
- if let Some(content) = content {
- match Self::parse_and_compile(&content, &label) {
- Ok(f) => filters.extend(f),
- Err(e) => eprintln!("[rtk] warning: {}: {}", label, e),
- }
- }
- }
- crate::hooks::trust::TrustStatus::Untrusted
- | crate::hooks::trust::TrustStatus::ContentChanged { .. } => {}
- }
}

fn parse_and_compile(content: &str, source: &str) -> Result<Vec<CompiledFilter>, String> {
@@ -447,24 +421,7 @@
}

fn collect_match_patterns() -> Vec<String> {
- let mut patterns: Vec<String> = Vec::new();
- for path in crate::hooks::trust::gated_filter_paths() {
- if !path.exists() {
- continue;
- }
- let (status, content) = crate::hooks::trust::check_trust_with_content(&path)
- .unwrap_or((crate::hooks::trust::TrustStatus::Untrusted, None));
- if matches!(
- status,
- crate::hooks::trust::TrustStatus::Trusted
- | crate::hooks::trust::TrustStatus::EnvOverride
- ) && let Some(content) = content
- {
- patterns.extend(match_patterns_in(&content));
- }
- }
- patterns.extend(match_patterns_in(BUILTIN_TOML));
- patterns
+ match_patterns_in(BUILTIN_TOML)
}

/// Strip a leading inline-flag group such as `(?i)` so the anchor check sees the
@@ -722,131 +679,6 @@
///
/// - `filter_name_opt`: if `Some`, only run tests for that filter name.
/// - Returns `VerifyResults` with all outcomes and filters that have no tests.
-pub fn run_filter_tests(filter_name_opt: Option<&str>) -> VerifyResults {
- let mut outcomes = Vec::new();
- let mut all_filter_names: Vec<String> = Vec::new();
- let mut tested_filter_names: std::collections::HashSet<String> =
- std::collections::HashSet::new();
-
- let builtin = BUILTIN_TOML;
- collect_test_outcomes(
- builtin,
- filter_name_opt,
- &mut outcomes,
- &mut all_filter_names,
- &mut tested_filter_names,
- );
-
- // Trust-gated: only verify project-local filters if trusted (SA-2025-RTK-002)
- let project_path = std::path::Path::new(".rtk/filters.toml");
- if project_path.exists() {
- let (trust_status, verified_content) =
- crate::hooks::trust::check_trust_with_content(project_path)
- .unwrap_or((crate::hooks::trust::TrustStatus::Untrusted, None));
- match trust_status {
- crate::hooks::trust::TrustStatus::Trusted
- | crate::hooks::trust::TrustStatus::EnvOverride => {
- if let Some(content) = verified_content {
- collect_test_outcomes(
- &content,
- filter_name_opt,
- &mut outcomes,
- &mut all_filter_names,
- &mut tested_filter_names,
- );
- }
- }
- _ => {
- eprintln!("[rtk] WARNING: untrusted project filters skipped in verify");
- }
- }
- }
-
- let filters_without_tests = all_filter_names
- .into_iter()
- .filter(|name| {
- // When a specific filter is requested, only report that one as missing tests
- filter_name_opt.is_none_or(|f| name == f)
- })
- .filter(|name| !tested_filter_names.contains(name))
- .collect();
-
- VerifyResults {
- outcomes,
- filters_without_tests,
- }
-}
-
-fn collect_test_outcomes(
- content: &str,
- filter_name_opt: Option<&str>,
- outcomes: &mut Vec<TestOutcome>,
- all_filter_names: &mut Vec<String>,
- tested_filter_names: &mut std::collections::HashSet<String>,
-) {
- let file: TomlFilterFile = match toml::from_str(content) {
- Ok(f) => f,
- Err(e) => {
- eprintln!("[rtk] warning: TOML parse error during verify: {}", e);
- return;
- }
- };
-
- // Compile all filters and track their names
- let mut compiled_filters: BTreeMap<String, CompiledFilter> = BTreeMap::new();
- for (name, def) in file.filters {
- all_filter_names.push(name.clone());
- match compile_filter(name.clone(), def) {
- Ok(f) => {
- compiled_filters.insert(name, f);
- }
- Err(e) => eprintln!("[rtk] warning: filter '{}' compilation error: {}", name, e),
- }
- }
-
- // Run tests
- for (filter_name, tests) in file.tests {
- if let Some(name) = filter_name_opt
- && filter_name != name
- {
- continue;
- }
-
- tested_filter_names.insert(filter_name.clone());
-
- let compiled = match compiled_filters.get(&filter_name) {
- Some(f) => f,
- None => {
- eprintln!(
- "[rtk] warning: [[tests.{}]] references unknown filter",
- filter_name
- );
- continue;
- }
- };
-
- for test in tests {
- let actual = apply_filter(compiled, &test.input);
- // Trim trailing newlines: TOML multiline strings end with a newline
- let actual_cmp = actual.trim_end_matches('\n').to_string();
- let expected_cmp = test.expected.trim_end_matches('\n').to_string();
- outcomes.push(TestOutcome {
- filter_name: filter_name.clone(),
- test_name: test.name,
- passed: actual_cmp == expected_cmp,
- actual: actual_cmp,
- expected: expected_cmp,
- });
- }
- }
-}
-
-// ---------------------------------------------------------------------------
-// Convenience wrapper (uses singleton — for run_fallback)
-// ---------------------------------------------------------------------------
-
-/// Find a matching filter from the global registry. Initialises the registry
-/// lazily on first call. Returns `None` if no filter matches.
pub fn find_matching_filter(command: &str) -> Option<&'static CompiledFilter> {
if std::env::var("RTK_TOML_DEBUG").is_ok() {
eprintln!(
@@ -2227,3 +2059,71 @@
assert_eq!(found.unwrap().name, "my-new-tool");
}
}
+
+pub fn registry() -> &'static TomlFilterRegistry {
+ &REGISTRY
+}
+
+fn collect_test_outcomes(
+ content: &str,
+ filter_name_opt: Option<&str>,
+ outcomes: &mut Vec<TestOutcome>,
+ all_filter_names: &mut Vec<String>,
+ tested_filter_names: &mut std::collections::HashSet<String>,
+) {
+ let file: TomlFilterFile = match toml::from_str(content) {
+ Ok(f) => f,
+ Err(e) => {
+ eprintln!("[rtk] warning: TOML parse error during verify: {}", e);
+ return;
+ }
+ };
+
+ // Compile all filters and track their names
+ let mut compiled_filters: BTreeMap<String, CompiledFilter> = BTreeMap::new();
+ for (name, def) in file.filters {
+ all_filter_names.push(name.clone());
+ match compile_filter(name.clone(), def) {
+ Ok(f) => {
+ compiled_filters.insert(name, f);
+ }
+ Err(e) => eprintln!("[rtk] warning: filter '{}' compilation error: {}", name, e),
+ }
+ }
+
+ // Run tests
+ for (filter_name, tests) in file.tests {
+ if let Some(name) = filter_name_opt
+ && filter_name != name
+ {
+ continue;
+ }
+
+ tested_filter_names.insert(filter_name.clone());
+
+ let compiled = match compiled_filters.get(&filter_name) {
+ Some(f) => f,
+ None => {
+ eprintln!(
+ "[rtk] warning: [[tests.{}]] references unknown filter",
+ filter_name
+ );
+ continue;
+ }
+ };
+
+ for test in tests {
+ let actual = apply_filter(compiled, &test.input);
+ // Trim trailing newlines: TOML multiline strings end with a newline
+ let actual_cmp = actual.trim_end_matches('\n').to_string();
+ let expected_cmp = test.expected.trim_end_matches('\n').to_string();
+ outcomes.push(TestOutcome {
+ filter_name: filter_name.clone(),
+ test_name: test.name,
+ passed: actual_cmp == expected_cmp,
+ actual: actual_cmp,
+ expected: expected_cmp,
+ });
+ }
+ }
+}
Loading
Loading