The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(tokenjuice): compress exposes all five ContentHint fields\n\n`handle_compress` built `ContentHint { source_tool, ..Default::default() }`,\nso four of the hint's five fields were unreachable and the `compress`\nschema declared only `content` + `tool_name`. The controller exists to\ndry-run the content router, but could not reproduce what the router\nactually does — in particular it could not force a kind via `explicit`,\nthe one field that skips detection entirely.\n\n`mime`, `extension`, `query` and `explicit` are now declared as optional\ninputs and passed through. The mapping is split into\n`compress_hint_from_params` so it can be unit tested without running the\nrouter or loading the module.\n\nAn unrecognised `explicit` is refused rather than ignored — silently\ndetecting when the caller asked for an override is exactly the confusion\nthis controller exists to resolve. Note the accepted spelling is\n`plain_text` (what `ContentKind::from_str` parses), not serde's\n`plainText`; the vendored `from_str` doc calls this out as the trap, and\na test pins it.\n\nThis is part (a) of #6088. Part (b) — whether `log_line_ratio` should\nmeasure failure density or log formatting, and whether the search rule\nshould ignore an `HH:MM:SS` timestamp — is a decision inside\n`vendor/tinyjuice`, not here, and is deliberately not addressed.\n\nCloses #6088\n
M3gA-Mind28473ce9ec71
diff --git a/src/openhuman/inference/tokenjuice/schemas.rs b/src/openhuman/inference/tokenjuice/schemas.rsindex 56cb375329..6897a8d7bf 100644--- a/src/openhuman/inference/tokenjuice/schemas.rs+++ b/src/openhuman/inference/tokenjuice/schemas.rs@@ -11,7 +11,7 @@ use serde_json::{Map, Value};use crate::core::all::{ControllerFuture, RegisteredController};use crate::core::{ControllerSchema, FieldSchema, TypeSchema};-use super::types::ContentHint;+use super::types::{ContentHint, ContentKind};pub fn all_controller_schemas() -> Vec<ControllerSchema> {vec![@@ -114,6 +114,32 @@ pub fn schemas(function: &str) -> ControllerSchema {comment: "Optional producing tool name (prior hint).",required: false,},+ FieldSchema {+ name: "mime",+ ty: TypeSchema::String,+ comment: "Optional MIME type hint (`text/html`, `application/json`, …).",+ required: false,+ },+ FieldSchema {+ name: "extension",+ ty: TypeSchema::String,+ comment: "Optional file extension hint (no dot).",+ required: false,+ },+ FieldSchema {+ name: "query",+ ty: TypeSchema::String,+ comment: "Optional search/query string; the search compressor ranks \+ matches by query-term density.",+ required: false,+ },+ FieldSchema {+ name: "explicit",+ ty: TypeSchema::String,+ comment: "Optional hard override of the detected kind, skipping detection \+ entirely. One of: json, code, log, search, diff, html, plain_text.",+ required: false,+ },],outputs: vec![FieldSchema {name: "result",@@ -238,13 +264,39 @@ fn handle_detect(params: Map<String, Value>) -> ControllerFuture {})}+/// Build a [`ContentHint`] from `compress`'s params.+///+/// All five hint fields are caller-supplied. Before #6088 only `source_tool` was+/// read, so the debug controller could not reproduce what the content router+/// actually does — in particular it could not force a kind via `explicit`, which+/// is the one field that skips detection entirely.+///+/// An unrecognised `explicit` is refused rather than ignored: silently detecting+/// instead of overriding is exactly the confusion this controller exists to+/// resolve.+fn compress_hint_from_params(params: &Map<String, Value>) -> Result<ContentHint, String> {+ let explicit = match str_param(params, "explicit") {+ Some(raw) => Some(raw.parse::<ContentKind>().map_err(|()| {+ format!(+ "invalid 'explicit': {raw:?} — expected one of: \+ json, code, log, search, diff, html, plain_text"+ )+ })?),+ None => None,+ };+ Ok(ContentHint {+ source_tool: str_param(params, "tool_name"),+ mime: str_param(params, "mime"),+ extension: str_param(params, "extension"),+ query: str_param(params, "query"),+ explicit,+ })+}+fn handle_compress(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let content = str_param(¶ms, "content").ok_or("missing 'content'")?;- let hint = ContentHint {- source_tool: str_param(¶ms, "tool_name"),- ..Default::default()- };+ let hint = compress_hint_from_params(¶ms)?;let res = super::compress(content, hint).await?;Ok(serde_json::json!({"applied": res.applied,diff --git a/src/openhuman/inference/tokenjuice/schemas_tests.rs b/src/openhuman/inference/tokenjuice/schemas_tests.rsindex b8702454a6..e8d76d8634 100644--- a/src/openhuman/inference/tokenjuice/schemas_tests.rs+++ b/src/openhuman/inference/tokenjuice/schemas_tests.rs@@ -26,3 +26,124 @@ async fn cache_stats_handler_returns_counts() {let out = handle_cache_stats(Map::new()).await.unwrap();assert!(out["entries"].is_u64());}++// ── #6088: `compress` must expose all five ContentHint fields ────────────────++/// Before #6088 the handler built `ContentHint { source_tool, ..Default::default() }`,+/// so four of the five fields were unreachable and the debug controller could not+/// reproduce what the content router does. These assert the mapping directly —+/// no module, no router — so they run everywhere.+#[test]+fn compress_hint_carries_every_caller_supplied_field() {+ let mut p = Map::new();+ p.insert("tool_name".into(), Value::from("grep"));+ p.insert("mime".into(), Value::from("text/html"));+ p.insert("extension".into(), Value::from("rs"));+ p.insert("query".into(), Value::from("needle"));+ p.insert("explicit".into(), Value::from("search"));++ let hint = compress_hint_from_params(&p).expect("a well-formed hint must parse");+ assert_eq!(+ hint.source_tool.as_deref(),+ Some("grep"),+ "`tool_name` was the only field the old handler read"+ );+ assert_eq!(+ hint.mime.as_deref(),+ Some("text/html"),+ "`mime` must reach the router; it was dropped before #6088"+ );+ assert_eq!(+ hint.extension.as_deref(),+ Some("rs"),+ "`extension` must reach the router; it was dropped before #6088"+ );+ assert_eq!(+ hint.query.as_deref(),+ Some("needle"),+ "`query` must reach the router — the search compressor ranks by it"+ );+ assert_eq!(+ hint.explicit,+ Some(ContentKind::Search),+ "`explicit` is the field that skips detection entirely — without it the \+ controller cannot force a kind, which is the point of the fix"+ );+}++#[test]+fn compress_hint_defaults_every_field_to_none() {+ let mut p = Map::new();+ p.insert("content".into(), Value::from("hello"));+ let hint = compress_hint_from_params(&p).expect("an empty hint must parse");+ assert!(hint.source_tool.is_none());+ assert!(hint.mime.is_none());+ assert!(hint.extension.is_none());+ assert!(hint.query.is_none());+ assert!(hint.explicit.is_none());+}++#[test]+fn compress_hint_refuses_an_unknown_explicit_kind() {+ let mut p = Map::new();+ p.insert("explicit".into(), Value::from("nonsense"));+ let err = compress_hint_from_params(&p)+ .expect_err("an unrecognised kind must be refused, not silently detected");+ assert!(+ err.contains("nonsense") && err.contains("plain_text"),+ "the refusal must quote the bad value and list the accepted set: {err}"+ );+}++/// `plain_text` is the spelling `ContentKind::from_str` accepts; serde renders the+/// same variant as `plainText`. The vendored `from_str` doc calls this out as the+/// exact trap, so pin the spelling the schema advertises.+#[test]+fn compress_hint_accepts_the_documented_plain_text_spelling() {+ let mut p = Map::new();+ p.insert("explicit".into(), Value::from("plain_text"));+ assert_eq!(+ compress_hint_from_params(&p)+ .expect("plain_text must parse")+ .explicit,+ Some(ContentKind::PlainText),+ "`plain_text` is the spelling `ContentKind::from_str` accepts and the one \+ the schema advertises; serde's `plainText` must not be what we parse"+ );+}++#[test]+fn compress_schema_declares_all_five_hint_inputs() {+ let s = schemas("compress");+ for field in [+ "content",+ "tool_name",+ "mime",+ "extension",+ "query",+ "explicit",+ ] {+ assert!(+ s.inputs.iter().any(|f| f.name == field),+ "`compress` must declare `{field}`; a hint field the schema does not \+ name is one a caller cannot discover"+ );+ }+ assert!(+ s.inputs+ .iter()+ .find(|f| f.name == "content")+ .is_some_and(|f| f.required),+ "only `content` is required"+ );+ for optional in ["tool_name", "mime", "extension", "query", "explicit"] {+ assert!(+ !s.inputs+ .iter()+ .find(|f| f.name == optional)+ .unwrap()+ .required,+ "`{optional}` must stay optional"+ );+ }+}