Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
away: approval items carry the live event's tool_name and details
Lin (kwant bot)2cf0b4cdc98a
diff --git a/src/server/away.rs b/src/server/away.rsindex 14565a60..edeb4342 100644--- a/src/server/away.rs+++ b/src/server/away.rs@@ -57,7 +57,18 @@ pub fn summarize(text: &str) -> String {.map(|l| l.trim().trim_start_matches(['#', '>', '*', '-', ' ']).trim()).find(|l| !l.is_empty()).unwrap_or_default();- let line = mask_credentials(line);+ let joined = mask_words(line);+ if joined.chars().count() > SUMMARY_CHARS {+ let cut: String = joined.chars().take(SUMMARY_CHARS - 1).collect();+ format!("{}…", cut.trim_end())+ } else {+ joined+ }+}++/// `text` with free-text credentials and any word that has a key-like part masked.+fn mask_words(text: &str) -> String {+ let line = mask_credentials(text);let masked: Vec<&str> = line.split_whitespace().map(|w| {@@ -68,12 +79,44 @@ pub fn summarize(text: &str) -> String {}}).collect();- let joined = masked.join(" ");- if joined.chars().count() > SUMMARY_CHARS {- let cut: String = joined.chars().take(SUMMARY_CHARS - 1).collect();- format!("{}…", cut.trim_end())- } else {- joined+ masked.join(" ")+}++/// An approval's stored details in the live `approval_required` event's shape. The tool's+/// `arguments` get the summary's masking (sensitive-named fields, credentials, key-like words),+/// as the feed never carries secrets; the rest (source, tool, ids, cwd) is kwnt's own.+fn masked_details(details: Value) -> Value {+ let mut details = details;+ if let Some(args) = details.get_mut("arguments") {+ *args = masked_arguments(args);+ }+ details+}++fn masked_arguments(v: &Value) -> Value {+ match v {+ Value::Object(map) => Value::Object(+ map.iter()+ .map(|(k, v)| {+ let lower = k.to_ascii_lowercase();+ let shown = match SECRET_ARG_HINTS.iter().any(|h| lower.contains(h)) {+ true => json!("[redacted]"),+ false => masked_arguments(v),+ };+ (k.clone(), shown)+ })+ .collect(),+ ),+ Value::Array(items) => Value::Array(items.iter().map(masked_arguments).collect()),+ // Untouched strings keep their line breaks; masked ones come back on one line+ Value::String(s) => {+ let masked = mask_words(s);+ match masked == s.split_whitespace().collect::<Vec<_>>().join(" ") {+ true => v.clone(),+ false => json!(masked),+ }+ }+ other => other.clone(),}}@@ -166,6 +209,13 @@ fn item(row: AwayRow) -> Value {"direct_kwant_id": row.direct_kwant_id,},});+ if row.kind == "approval" {+ // The live `approval_required` event's fields, so an approval opened from here renders+ // like one that arrived over SSE; secret values are masked, as everywhere in the feed.+ v["tool_name"] = json!(row.title);+ let details: Value = row.body.as_deref().and_then(|b| serde_json::from_str(b).ok()).unwrap_or(Value::Null);+ v["details"] = masked_details(details);+ }if row.kind == "question" {v["choices"] = row.choicesdiff --git a/tests/away_test.rs b/tests/away_test.rsindex 6b902911..9d224c30 100644--- a/tests/away_test.rs+++ b/tests/away_test.rs@@ -235,6 +235,14 @@ async fn away_lists_every_kind_filters_caps_and_marks_seen() {let body = v.to_string();assert!(!body.contains(SECRET) && !body.contains("hidden-value") && !body.contains("hunter2"), "secret leaked: {body}");+ // The approval carries the live event's fields, masked like the rest of the feed+ let ai0 = find(&v["waiting"], &live.id);+ assert_eq!(ai0["tool_name"], "mcp__mail__send");+ assert_eq!(ai0["details"]["server"], "mail");+ assert_eq!(ai0["details"]["arguments"]["api_key"], "[redacted]");+ assert_eq!(ai0["details"]["arguments"]["to"], "[email protected]");+ assert_eq!(ai0["details"]["arguments"]["command"], "mysql -u bob password=[redacted]");+// Waiting ignores since; the stale ticket and the answered question aren't thereassert_eq!(ids(&v["waiting"]), vec![live.id.clone(), q.id.clone()]);let qi = find(&v["waiting"], &q.id);@@ -388,6 +396,7 @@ async fn live_approval_link(app: &Router, state: &AppState, kwant: &kwnt::db::mo.header("content-type", "application/json").body(Body::from(ask.to_string())).unwrap();+ let mut events = state.event_sender.subscribe();let prompt = tokio::spawn(app.clone().oneshot(req));let mut item = None;@@ -401,6 +410,18 @@ async fn live_approval_link(app: &Router, state: &AppState, kwant: &kwnt::db::mo}let item = item.expect("the approval never showed up under waiting");assert_eq!(state.db.get_approval(item["id"].as_str().unwrap()).await.unwrap().unwrap().turn_id, turn_id);+ // The item carries what the live event did, so the client can render it the same way.+ let (tool_name, details) = loop {+ match events.try_recv() {+ Ok(kwnt::drivers::events::RuntimeEvent::ApprovalRequired { id, tool_name, details }) if id == item["id"] => break (tool_name, details),+ Ok(_) => continue,+ Err(e) => panic!("no approval_required event for the item: {e:?}"),+ }+ };+ assert_eq!(item["tool_name"], tool_name);+ assert_eq!(tool_name, "mcp__echo__echo");+ assert_eq!(item["details"], details);+ assert!(details.is_object() && details != json!({}), "{details}");assert!(state.broker.resolve(item["id"].as_str().unwrap(), ApprovalDecision::AllowOnce).await);let resp = prompt.await.unwrap().unwrap();