Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(security): move command analysis types into the policy module

Steven Enamakel8a73b6c6fa42
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
index 6fa3972e62..a0245a207c 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
@@ -24,7 +24,7 @@ pub async fn steer(
SteerAccess::Owner(&owner),
text,
lane,
- |metadata, lane, text| async move {
+ |metadata: super::registry::RunningSubagentMetadata, lane: QueueLane, text: String| async move {
metadata
.run_queue
.push(
@@ -77,7 +77,7 @@ pub(crate) async fn steer_control(
SteerAccess::Trusted,
text,
lane,
- |metadata, lane, text| async move {
+ |metadata: super::registry::RunningSubagentMetadata, lane: QueueLane, text: String| async move {
metadata
.run_queue
.push(
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_cancel_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_cancel_tests.rs
index 375232e972..31daede3cf 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_cancel_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_cancel_tests.rs
@@ -1,7 +1,7 @@
//! Cancelling and stopping registered sub-agents: by task, by thread, and all.
use super::*;
-use tinyagents_orchestration::subagent::SteerError;
+use tinyagents_orchestration::steering::SteerError;
/// A finished run stays registered until the terminal sweep, so a late
/// "Cancel" still finds it. It must come back flagged, so the RPC does not
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_steering_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_steering_tests.rs
index 65a5a6c127..7be68e0fc1 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_steering_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_steering_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use tinyagents_orchestration::subagent::SteerError;
+use tinyagents_orchestration::steering::SteerError;
#[tokio::test]
async fn steer_pushes_into_the_subagent_queue() {
@@ -126,7 +126,7 @@ async fn steer_after_terminal_is_rejected() {
QueueLane::Steer
)
.await,
- Err(SteerError::AlreadyDone)
+ Err(SteerError::Unknown)
);
prune("task-term");
}
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
index 0be7ef0aee..3df419cb4f 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
@@ -5,7 +5,7 @@ use crate::agent::orchestration::running_subagents::resolve::{
use crate::core::runtime::DispatchCtx;
use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet, Mode};
use crate::tools::toolpacks::ToolGroups;
-use tinyagents_orchestration::subagent::SteerError;
+use tinyagents_orchestration::steering::SteerError;
const CHILD: &str = "OPENHUMAN_DETACHED_TENANT_TEST_CHILD";
const PARENT: &str = "same-parent-session";
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
index 59b26c3bbc..4e8237baa3 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use tinyagents_orchestration::subagent::SteerError;
+use tinyagents_orchestration::steering::SteerError;
/// The context these tests dispatch under: the calling task's own.
fn cx() -> crate::core::runtime::DispatchCtx {
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
index a29f37f6a5..6279f19d86 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
@@ -86,8 +86,8 @@ use crate::agent::tinyagents::policy_denial::PolicyDenial;
use crate::security::approval::{
redact_args, summarize_action, ApprovalGate, ApprovalTurnContext, GateOutcome,
};
+use crate::security::policy::CommandClass;
use crate::security::policy::{GateDecision as PolicyGateDecision, SecurityPolicy};
-use tinybox_bus::CommandClass;
use tinytools::{PermissionLevel, Tool};
use tinytools::{ToolPolicyAction, ToolPolicySession};
@@ -291,7 +291,7 @@ impl OpenHumanSecurityGate {
args: &serde_json::Value,
analysis: &serde_json::Value,
) -> std::result::Result<PolicyGateDecision, String> {
- let analysis: crate::modules::tinybox::contract::CommandAnalysis =
+ let analysis: crate::security::policy::CommandAnalysis =
serde_json::from_value(analysis.clone())
.map_err(|_| "TinyBox command analysis is invalid".to_owned())?;
let mut class: CommandClass = policy.check_gated_command_analysis(&analysis)?;
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs
index 0997a5fa40..d5450a4b17 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs
@@ -69,7 +69,7 @@ fn req(tool_name: &str, args: serde_json::Value) -> ToolCallRequest {
#[cfg(feature = "modules")]
fn shell_context(
args: &serde_json::Value,
- class: tinybox_bus::CommandClass,
+ class: crate::security::policy::CommandClass,
hidden_execution: bool,
literal_words: &[&str],
) -> serde_json::Value {
@@ -80,11 +80,11 @@ fn shell_context(
fn shell_context_for_args(
request_arguments: &serde_json::Value,
effective_arguments: &serde_json::Value,
- class: tinybox_bus::CommandClass,
+ class: crate::security::policy::CommandClass,
hidden_execution: bool,
literal_words: &[&str],
) -> serde_json::Value {
- use crate::modules::tinybox::contract::{CommandAnalysis, CommandSegment};
+ use crate::security::policy::{CommandAnalysis, CommandSegment};
let analysis = CommandAnalysis {
segments: vec![CommandSegment {
@@ -118,7 +118,7 @@ fn shell_context_for_args(
#[cfg(feature = "modules")]
fn shell_analysis(
- class: tinybox_bus::CommandClass,
+ class: crate::security::policy::CommandClass,
hidden_execution: bool,
literal_words: &[&str],
) -> serde_json::Value {
@@ -227,7 +227,7 @@ async fn a_read_class_shell_command_runs_without_a_prompt() {
&req(SHELL_TOOL, args.clone()),
Some(&shell_context(
&args,
- tinybox_bus::CommandClass::Read,
+ crate::security::policy::CommandClass::Read,
false,
&["ls", "-la"],
)),
@@ -256,7 +256,7 @@ async fn shell_authorization_denies_when_module_facts_are_missing() {
async fn shell_authorization_rejects_facts_bound_to_different_arguments() {
let gate = gate(AutonomyLevel::Full);
let args = json!({"command": "ls -la"});
- let analysis = crate::modules::tinybox::contract::CommandAnalysis {
+ let analysis = crate::security::policy::CommandAnalysis {
segments: vec![],
hidden_execution: false,
redirection: false,
@@ -292,7 +292,7 @@ fn shell_policy_uses_the_effective_arguments_bound_by_the_harness() {
let context = shell_context_for_args(
&request_arguments,
&effective_arguments,
- tinybox_bus::CommandClass::Write,
+ crate::security::policy::CommandClass::Write,
false,
&["touch", "output"],
);
@@ -320,7 +320,7 @@ async fn a_read_class_shell_command_still_runs_in_read_only_mode() {
&req(SHELL_TOOL, args.clone()),
Some(&shell_context(
&args,
- tinybox_bus::CommandClass::Read,
+ crate::security::policy::CommandClass::Read,
false,
&["ls", "-la"],
)),
@@ -339,7 +339,7 @@ async fn a_write_shell_command_is_blocked_outright_in_read_only() {
&req(SHELL_TOOL, args.clone()),
Some(&shell_context(
&args,
- tinybox_bus::CommandClass::Write,
+ crate::security::policy::CommandClass::Write,
false,
&["rm", "-rf", "/tmp/x"],
)),
@@ -364,7 +364,7 @@ async fn hidden_execution_is_blocked_below_the_full_tier() {
&req(SHELL_TOOL, args.clone()),
Some(&shell_context(
&args,
- tinybox_bus::CommandClass::Write,
+ crate::security::policy::CommandClass::Write,
true,
&["echo"],
)),
@@ -386,7 +386,11 @@ fn the_declared_category_can_only_raise_the_command_class() {
OpenHumanSecurityGate::shell_decision(
&full,
&json!({ "command": "touch f" }),
- &shell_analysis(tinybox_bus::CommandClass::Write, false, &["touch", "f"],),
+ &shell_analysis(
+ crate::security::policy::CommandClass::Write,
+ false,
+ &["touch", "f"],
+ ),
),
Ok(PolicyGateDecision::Allow)
);
@@ -395,7 +399,11 @@ fn the_declared_category_can_only_raise_the_command_class() {
OpenHumanSecurityGate::shell_decision(
&full,
&json!({ "command": "touch f", "category": "destructive" }),
- &shell_analysis(tinybox_bus::CommandClass::Write, false, &["touch", "f"],)
+ &shell_analysis(
+ crate::security::policy::CommandClass::Write,
+ false,
+ &["touch", "f"],
+ )
),
Ok(PolicyGateDecision::Prompt)
);
@@ -406,7 +414,7 @@ fn the_declared_category_can_only_raise_the_command_class() {
&full,
&json!({ "command": "curl https://example.invalid", "category": "read" }),
&shell_analysis(
- tinybox_bus::CommandClass::Network,
+ crate::security::policy::CommandClass::Network,
false,
&["curl", "https://example.invalid"],
)
@@ -423,7 +431,7 @@ fn a_missing_command_argument_classifies_as_read_rather_than_panicking() {
OpenHumanSecurityGate::shell_decision(
&supervised,
&json!({}),
- &shell_analysis(tinybox_bus::CommandClass::Read, false, &[],),
+ &shell_analysis(crate::security::policy::CommandClass::Read, false, &[],),
),
Ok(PolicyGateDecision::Allow)
);
diff --git a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs
index a76228e651..411ae107c0 100644
--- a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs
@@ -14,6 +14,8 @@ fn activity(rounds: usize, tools: &[&str]) -> FinishActivity {
FinishActivity {
tool_rounds: rounds,
tools_called: tools.iter().map(|t| (*t).to_string()).collect(),
+ tools_executed: Default::default(),
+ tools_with_side_effects: Default::default(),
}
}
diff --git a/crates/openhuman-core/src/agent_runs/subagent_control.rs b/crates/openhuman-core/src/agent_runs/subagent_control.rs
index 427dee6bd0..0ee37ecef7 100644
--- a/crates/openhuman-core/src/agent_runs/subagent_control.rs
+++ b/crates/openhuman-core/src/agent_runs/subagent_control.rs
@@ -270,7 +270,6 @@ fn handle_subagent_steer(ctx: DispatchCtx, params: Map<String, Value>) -> Contro
Err(err) => {
let reason = match err {
SteerError::Unknown => "unknown",
- SteerError::AlreadyDone => "already_done",
// SaaS user controls check the captured worker profile,
// independently of the caller-supplied task ID.
SteerError::NotOwned => "not_owned",
diff --git a/crates/openhuman-core/src/channels/bus/delivery.rs b/crates/openhuman-core/src/channels/bus/delivery.rs
index f547d05ca7..55391d012a 100644
--- a/crates/openhuman-core/src/channels/bus/delivery.rs
+++ b/crates/openhuman-core/src/channels/bus/delivery.rs
@@ -12,10 +12,12 @@ use tinychannels_bus::{methods, ChannelBackendRequest, ChannelBackendResult};
fn request_channel(request: &ProgressiveTransportRequest) -> &str {
match request {
- ProgressiveTransportRequest::Send { channel, .. }
+ ProgressiveTransportRequest::OutputEvent { channel, .. }
+ | ProgressiveTransportRequest::Send { channel, .. }
+ | ProgressiveTransportRequest::SendTyped { channel, .. }
| ProgressiveTransportRequest::Edit { channel, .. }
| ProgressiveTransportRequest::Delete { channel, .. }
- | ProgressiveTransportRequest::Typing { channel } => channel,
+ | ProgressiveTransportRequest::Typing { channel, .. } => channel,
}
}
diff --git a/crates/openhuman-core/src/channels/bus/delivery_tests.rs b/crates/openhuman-core/src/channels/bus/delivery_tests.rs
index 82b6204df2..947941983f 100644
--- a/crates/openhuman-core/src/channels/bus/delivery_tests.rs
+++ b/crates/openhuman-core/src/channels/bus/delivery_tests.rs
@@ -34,19 +34,35 @@ fn every_transport_operation_carries_the_channel_scoped_by_the_host() {
for request in [
ProgressiveTransportRequest::Send {
channel: "discord:fixture".into(),
+ turn_id: None,
+ channel_ref: None,
+ conversation: None,
+ sequence: None,
+ idempotency_key: None,
message: json!({"text":"hello"}),
},
ProgressiveTransportRequest::Edit {
channel: "discord:fixture".into(),
+ turn_id: None,
+ channel_ref: None,
+ conversation: None,
message_id: "message".into(),
+ receipt: None,
text: "edited".into(),
},
ProgressiveTransportRequest::Delete {
channel: "discord:fixture".into(),
+ turn_id: None,
+ channel_ref: None,
+ conversation: None,
message_id: "message".into(),
+ receipt: None,
},
ProgressiveTransportRequest::Typing {
channel: "discord:fixture".into(),
+ turn_id: None,
+ channel_ref: None,
+ conversation: None,
},
] {
assert_eq!(request_channel(&request), "discord:fixture");
diff --git a/crates/openhuman-core/src/channels/callback_slot_tests.rs b/crates/openhuman-core/src/channels/callback_slot_tests.rs
index f7b3822d8e..2ad06ff6f4 100644
--- a/crates/openhuman-core/src/channels/callback_slot_tests.rs
+++ b/crates/openhuman-core/src/channels/callback_slot_tests.rs
@@ -5,9 +5,12 @@ use tinychannels_bus::module_progressive::{
};
fn typing(channel: &str) -> ChannelBackendRequest {
- ChannelBackendRequest::ProgressiveTransport(ProgressiveTransportRequest::Typing {
+ ChannelBackendRequest::ProgressiveTransport(Box::new(ProgressiveTransportRequest::Typing {
channel: channel.to_string(),
- })
+ turn_id: None,
+ channel_ref: None,
+ conversation: None,
+ }))
}
fn answering(
diff --git a/crates/openhuman-core/src/channels/context_tests.rs b/crates/openhuman-core/src/channels/context_tests.rs
index acb0e96443..43ec85ea46 100644
--- a/crates/openhuman-core/src/channels/context_tests.rs
+++ b/crates/openhuman-core/src/channels/context_tests.rs
@@ -65,6 +65,8 @@ fn channel_message(channel: &str) -> traits::ChannelMessage {
thread_ts: Some("thread-1".into()),
timestamp: 0,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
}
}
diff --git a/crates/openhuman-core/src/channels/host/channel_events.rs b/crates/openhuman-core/src/channels/host/channel_events.rs
index cd9b7ea42e..865a57d98b 100644
--- a/crates/openhuman-core/src/channels/host/channel_events.rs
+++ b/crates/openhuman-core/src/channels/host/channel_events.rs
@@ -7,7 +7,7 @@ use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use tinybus::module::ModuleClient;
use tinybus::EventHandler;
-use tinychannels_bus::{capabilities_for, ChannelMessage};
+use tinychannels_bus::ChannelMessage;
#[derive(Clone)]
struct ReplyContext {
@@ -74,7 +74,11 @@ impl EventHandler<DomainEvent> for ChannelApprovalSurfaceSubscriber {
inbound_envelope,
workspace_dir,
} => {
- if !capabilities_for(channel).chat_approvals {
+ if !self
+ .channels
+ .get(channel)
+ .is_some_and(|channel| channel.capabilities().chat_approvals)
+ {
return;
}
if self
@@ -99,6 +103,8 @@ impl EventHandler<DomainEvent> for ChannelApprovalSurfaceSubscriber {
timestamp: 0,
thread_ts: thread_ts.clone(),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
envelope: inbound_envelope.clone(),
},
@@ -125,7 +131,11 @@ impl EventHandler<DomainEvent> for ChannelApprovalSurfaceSubscriber {
client_id: Some(channel_name),
..
} => {
- if !capabilities_for(channel_name).chat_approvals {
+ if !self
+ .channels
+ .get(channel_name)
+ .is_some_and(|channel| channel.capabilities().chat_approvals)
+ {
return;
}
let reply = self
@@ -178,13 +188,18 @@ impl EventHandler<DomainEvent> for ChannelApprovalSurfaceSubscriber {
/// Projects host turn lifecycle facts into module-owned remote status storage.
pub struct ChannelTurnStateSubscriber {
workspace_dir: PathBuf,
+ channels: Arc<HashMap<String, Arc<dyn Channel>>>,
config: Option<Arc<crate::config::Config>>,
cancellation: tokio_util::sync::CancellationToken,
}
impl ChannelTurnStateSubscriber {
- pub fn with_config(config: Arc<crate::config::Config>) -> Self {
+ pub fn with_config(
+ channels: Arc<HashMap<String, Arc<dyn Channel>>>,
+ config: Arc<crate::config::Config>,
+ ) -> Self {
Self {
workspace_dir: config.workspace_dir.clone(),
+ channels,
config: Some(config),
cancellation: super::super::runtime::session::channel_session(),
}
@@ -193,13 +208,17 @@ impl ChannelTurnStateSubscriber {
pub fn new(workspace_dir: PathBuf) -> Self {
Self {
workspace_dir,
+ channels: Arc::new(HashMap::new()),
config: None,
cancellation: tokio_util::sync::CancellationToken::new(),
}
}
async fn mark(&self, channel: &str, reply_target: &str, event_ws: &PathBuf, busy: bool) {
if self.cancellation.is_cancelled()
- || !capabilities_for(channel).remote_control
+ || !self
+ .channels
+ .get(channel)
+ .is_some_and(|channel| channel.capabilities().remote_control)
|| *event_ws != self.workspace_dir
{
return;
diff --git a/crates/openhuman-core/src/channels/host/channel_events_tests.rs b/crates/openhuman-core/src/channels/host/channel_events_tests.rs
index 2c3608637e..1a601cf7b9 100644
--- a/crates/openhuman-core/src/channels/host/channel_events_tests.rs
+++ b/crates/openhuman-core/src/channels/host/channel_events_tests.rs
@@ -91,6 +91,8 @@ async fn remote_status(ws: &Path, channel: &str, reply_target: &str) -> Option<S
timestamp: 0,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
route: tinychannels_bus::module_remote::RemoteRoute {
provider: "openai".into(),
diff --git a/crates/openhuman-core/src/channels/module_fixture_tests.rs b/crates/openhuman-core/src/channels/module_fixture_tests.rs
index 39d16f0226..38ea3cb9ad 100644
--- a/crates/openhuman-core/src/channels/module_fixture_tests.rs
+++ b/crates/openhuman-core/src/channels/module_fixture_tests.rs
@@ -109,6 +109,8 @@ async fn linked_module_prepares_legacy_inbound_facts_over_confidential_bus_call(
timestamp: 42,
thread_ts: Some("thread/c".into()),
sender_name: Some("Display".into()),
+ reply_to_id: None,
+ topic_id: None,
};
let response: PreparedChannelInbound = client()
.await
diff --git a/crates/openhuman-core/src/channels/providers/relay/params.rs b/crates/openhuman-core/src/channels/providers/relay/params.rs
index f4d1112ddc..4ea16ce77c 100644
--- a/crates/openhuman-core/src/channels/providers/relay/params.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/params.rs
@@ -152,6 +152,8 @@ impl RelayInboundParams {
.sender_name
.clone()
.filter(|name| !name.trim().is_empty()),
+ reply_to_id: None,
+ topic_id: None,
}
}
}
diff --git a/crates/openhuman-core/src/channels/routes.rs b/crates/openhuman-core/src/channels/routes.rs
index d7d51fda4b..635e0bd7a7 100644
--- a/crates/openhuman-core/src/channels/routes.rs
+++ b/crates/openhuman-core/src/channels/routes.rs
@@ -181,6 +181,7 @@ pub(crate) async fn handle_runtime_command_if_needed(
model: current.model,
},
history_len,
+ capabilities: target_channel.map(|channel| Box::new(channel.capabilities())),
providers: provider_descriptors(),
},),
)
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index 3e63402712..2ac424c7a3 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -109,12 +109,15 @@ async fn module_route_help_response(
timestamp: 0,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
}),
route: RemoteRoute {
provider: "openai".into(),
model: "gpt-5".into(),
},
history_len: 0,
+ capabilities: None,
providers,
};
let response: ChannelControlResult = crate::channels::module_fixture::client()
@@ -235,6 +238,8 @@ fn model_command_messages_use_thread_aware_history_keys() {
timestamp: 0,
thread_ts: Some("thread-1".into()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
assert_eq!(
super::super::context::conversation_history_key(&msg),
@@ -321,6 +326,8 @@ async fn handle_runtime_command_unknown_provider_sends_helpful_error() {
timestamp: 0,
thread_ts: Some("thread-1".into()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let handled = handle_runtime_command_if_needed(
@@ -359,6 +366,8 @@ async fn handle_runtime_command_set_model_clears_sender_history_and_persists_rou
timestamp: 0,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let handled = handle_runtime_command_if_needed(
@@ -403,6 +412,8 @@ async fn handle_runtime_command_telegram_status_replies_without_agent() {
timestamp: 0,
thread_ts: Some("42".into()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let handled = handle_runtime_command_if_needed(
@@ -436,6 +447,8 @@ async fn handle_runtime_command_without_target_channel_still_consumes_command()
timestamp: 0,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let handled =
@@ -457,6 +470,8 @@ async fn handle_runtime_command_telegram_help_replies_with_remote_command_list()
timestamp: 0,
thread_ts: Some("42".into()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let handled = handle_runtime_command_if_needed(
@@ -494,6 +509,8 @@ async fn handle_runtime_command_telegram_sessions_reports_empty_store() {
timestamp: 0,
thread_ts: Some("42".into()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let handled = handle_runtime_command_if_needed(
@@ -536,6 +553,8 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
timestamp: 0,
thread_ts: Some("42".into()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
assert!(
handle_runtime_command_if_needed(
@@ -589,6 +608,8 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
timestamp: 0,
thread_ts: Some("42".into()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
assert!(
handle_runtime_command_if_needed(
@@ -609,6 +630,8 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
timestamp: 0,
thread_ts: Some("42".into()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
assert!(
handle_runtime_command_if_needed(
@@ -663,6 +686,8 @@ async fn handle_runtime_command_telegram_new_reports_unavailable_storage() {
timestamp: 0,
thread_ts: Some("42".into()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
assert!(
handle_runtime_command_if_needed(
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs
index 471645f715..23c2c74431 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs
@@ -73,6 +73,8 @@ fn message(text: &str) -> traits::ChannelMessage {
id: "m1".into(),
sender: "alice".into(),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
reply_target: "42".into(),
content: text.into(),
channel: "telegram".into(),
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch_tests.rs
index 8c371b8f64..2396605714 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch_tests.rs
@@ -14,6 +14,8 @@ fn queued(seq: u64, id: &str, timestamp: u64, content: &str) -> QueuedInbound {
timestamp,
thread_ts: Some(format!("thread-{id}")),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
history_key: "telegram_alice_reply".to_string(),
},
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/mod_approval_surface_gating_tests_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/mod_approval_surface_gating_tests_tests.rs
index 3ebb6074da..41b460a24d 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/mod_approval_surface_gating_tests_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/mod_approval_surface_gating_tests_tests.rs
@@ -1,38 +1,16 @@
use super::channel_has_approval_surface;
-
-// Sub-issue 2 of #3098: this gate is what decides whether the dispatch
-// loop sets an `ApprovalChatContext` (→ gate fires for `Prompt`-class
-// tools) versus the legacy bypass (→ tool calls silently allowed).
-// Pin the matrix: every chat channel is served by
-// `ChannelApprovalSurfaceSubscriber`; channels with no conversational reply
-// path must not be scoped, or every parked call would TTL-deny.
-
-#[test]
-fn chat_channels_have_an_approval_surface() {
- for channel in [
- "telegram",
- "discord",
- "slack",
- "imessage",
- "mattermost",
- "signal",
- "whatsapp",
- "irc",
- ] {
- assert!(channel_has_approval_surface(channel), "{channel}");
- }
-}
+use tinychannels_bus::ChannelCapabilities;
#[test]
-fn channels_without_a_reply_path_do_not_have_an_approval_surface() {
- for channel in ["email", "cli", "webhook", "web"] {
- assert!(!channel_has_approval_surface(channel), "{channel}");
- }
+fn configured_instances_with_chat_approvals_have_an_approval_surface() {
+ let mut capabilities = ChannelCapabilities::unknown();
+ capabilities.chat_approvals = true;
+ assert!(channel_has_approval_surface(&capabilities));
}
#[test]
-fn unknown_channel_does_not_have_approval_surface() {
- assert!(!channel_has_approval_surface(""));
- assert!(!channel_has_approval_surface("Telegram")); // case-sensitive on purpose
- assert!(!channel_has_approval_surface("telegram-bot"));
+fn unknown_or_unconfigured_instances_do_not_have_an_approval_surface() {
+ assert!(!channel_has_approval_surface(
+ &ChannelCapabilities::unknown()
+ ));
}
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/admit.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/admit.rs
index a657bfc7eb..21f18ce32c 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/admit.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/admit.rs
@@ -100,7 +100,9 @@ pub(crate) async fn admit_runtime_message(
// A yes/no reply to an approval parked on this conversation decides it;
// a fresh turn would cancel the parked tool call.
- if channel_has_approval_surface(&msg.channel)
+ if target_channel
+ .as_ref()
+ .is_some_and(|channel| channel_has_approval_surface(&channel.capabilities()))
&& try_route_approval_reply(&msg, &history_key).await
{
return None;
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs
index a5216c9832..27beeedd78 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/approval.rs
@@ -16,8 +16,10 @@ use tinychannels_bus as traits;
///
/// [`ApprovalChatContext`]: crate::security::approval::ApprovalChatContext
/// [`ApprovalGate`]: crate::security::approval::ApprovalGate
-pub(crate) fn channel_has_approval_surface(channel: &str) -> bool {
- tinychannels_bus::capabilities_for(channel).chat_approvals
+pub(crate) fn channel_has_approval_surface(
+ capabilities: &tinychannels_bus::ChannelCapabilities,
+) -> bool {
+ capabilities.chat_approvals
}
/// If the inbound message is a yes/no reply for a parked approval on
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index 74c597c27a..337a3e5f32 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -347,7 +347,10 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:
// "no chat context -> allow straight through" branch silently bypasses
// every `Prompt`-class tool call, voiding the `supervised` autonomy tier
// on the channel.
- let approval = if channel_has_approval_surface(&msg.channel) {
+ let approval = if target_channel
+ .as_ref()
+ .is_some_and(|channel| channel_has_approval_surface(&channel.capabilities()))
+ {
crate::security::approval::ApprovalTurnContext::chat(
crate::security::approval::ApprovalChatContext {
thread_id: history_key.clone(),
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch_tests.rs
index 7753814c83..549870ba00 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch_tests.rs
@@ -88,6 +88,8 @@ fn cm(channel: &str, reply_target: &str) -> traits::ChannelMessage {
thread_ts: None,
timestamp: 0,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
}
}
diff --git a/crates/openhuman-core/src/channels/runtime/startup/delivery_import_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/delivery_import_tests.rs
index 19a96a2213..9e7b95e36b 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/delivery_import_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/delivery_import_tests.rs
@@ -8,6 +8,9 @@ fn entry(id: &str, at: u64) -> DeliveryQueueEntry {
id,
ChannelOutboundIntent {
idempotency_key: id.to_owned(),
+ channel_ref: None,
+ conversation_ref: None,
+ turn_id: None,
channel_id: "telegram".into(),
conversation_id: "chat-1".into(),
reply_to_id: None,
@@ -63,6 +66,7 @@ fn legacy_state() -> Value {
id: "done".into(),
intent_fingerprint: "fp".into(),
completed_at_unix_ms: now_unix_ms(),
+ receipt: None,
};
let stale = DeliveryTerminalResult {
id: "old".into(),
diff --git a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
index c8061aa6a6..8ac2a45213 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
@@ -34,7 +34,7 @@ pub(super) struct ModuleChannelRuntime {
struct ModuleChannel {
name: String,
object: ModuleObjectClient,
- interaction: tinychannels_bus::ChannelInteractionInfo,
+ interaction: tinychannels_bus::ChannelInteractionInfoV2,
relay: Option<tinychannels_bus::module_relay::RelayReservation>,
relay_fronted: bool,
}
@@ -302,7 +302,11 @@ impl Channel for ModuleChannel {
}
fn proactive_target(&self) -> Option<String> {
- self.interaction.proactive_target.clone()
+ self.interaction
+ .capabilities
+ .account
+ .proactive_target
+ .clone()
}
async fn send(&self, message: &SendMessage) -> anyhow::Result<()> {
@@ -378,15 +382,7 @@ impl Channel for ModuleChannel {
}
fn capabilities(&self) -> tinychannels_bus::ChannelCapabilities {
- self.interaction.capabilities
- }
-
- fn supports_reactions(&self) -> bool {
- self.interaction.supports_reactions
- }
-
- fn supports_draft_updates(&self) -> bool {
- self.interaction.supports_draft_updates
+ self.interaction.capabilities.clone()
}
async fn send_draft(&self, message: &SendMessage) -> anyhow::Result<Option<String>> {
diff --git a/crates/openhuman-core/src/channels/runtime/startup/relay.rs b/crates/openhuman-core/src/channels/runtime/startup/relay.rs
index d44f29551e..eb657381a2 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/relay.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/relay.rs
@@ -29,7 +29,11 @@ impl tinychannels::relay::RelayInboundHandler for RelayInboundMessageHandler {
"invalid inbound envelope: {error}"
))
})?;
- let msg = tinychannels::legacy_message_from_inbound_envelope(&envelope, 0);
+ let msg = tinychannels::legacy_message_from_inbound_envelope(&envelope, 0).map_err(|error| {
+ tinychannels::relay::RelayTransportError::Handler(format!(
+ "invalid legacy inbound projection: {error}"
+ ))
+ })?;
self.tx
.send(RuntimeChannelMessage::with_inbound_envelope(msg, envelope))
.await
diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
index 4bd704df8c..473621dc38 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
@@ -240,7 +240,10 @@ async fn start_channels_inner(mut config: Config, session: CancellationToken) ->
// Remote-control turn state (`/status` shows "in progress") for every
// channel with the `remote_control` capability.
let _turn_state_handle = bus.subscribe(Arc::new(
- crate::channels::host::ChannelTurnStateSubscriber::with_config(Arc::new(config.clone())),
+ crate::channels::host::ChannelTurnStateSubscriber::with_config(
+ Arc::clone(&channels_by_name),
+ Arc::new(config.clone()),
+ ),
));
// In-chat approvals (sub-issue 2 of #3098) for every channel with the
// `chat_approvals` capability: `Prompt`-class tool calls are gated for the
diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rs
index 536d906ef8..60c78488dd 100644
--- a/crates/openhuman-core/src/channels/runtime/test_support.rs
+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs
@@ -446,6 +446,8 @@ pub async fn run_dispatch_harness(options: DispatchHarnessOptions) -> DispatchHa
timestamp: 1,
thread_ts: options.thread_ts,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
if let Some(inbound_envelope) = options.inbound_envelope {
process_channel_runtime_message(
diff --git a/crates/openhuman-core/src/channels/tests/discord_integration.rs b/crates/openhuman-core/src/channels/tests/discord_integration.rs
index ce700773c3..9ff9480c56 100644
--- a/crates/openhuman-core/src/channels/tests/discord_integration.rs
+++ b/crates/openhuman-core/src/channels/tests/discord_integration.rs
@@ -158,6 +158,8 @@ async fn discord_inbound_dispatches_through_full_pipeline() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -209,6 +211,8 @@ async fn discord_threaded_message_does_not_emit_reaction_ack() {
timestamp: 1,
thread_ts: Some("thread-42".to_string()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -258,6 +262,8 @@ async fn discord_thread_ts_splits_conversation_history_end_to_end() {
timestamp: 1,
thread_ts: Some("thread-A".to_string()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let second = traits::ChannelMessage {
diff --git a/crates/openhuman-core/src/channels/tests/runtime_debounce.rs b/crates/openhuman-core/src/channels/tests/runtime_debounce.rs
index 6fc0794f88..668236b8f7 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_debounce.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_debounce.rs
@@ -142,6 +142,8 @@ impl Running {
timestamp: ts,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
}
}
@@ -157,6 +159,7 @@ impl Running {
message: message.clone(),
envelope: Default::default(),
history_key: history_key.clone(),
+ history_key_ignores_thread: false,
thread_id: history_key.clone(),
client_id: self.channel.to_string(),
session_key: history_key,
diff --git a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
index dd2e0dcd36..dfad7c4afc 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
@@ -159,6 +159,8 @@ async fn message_dispatch_processes_messages_in_parallel() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
}))
.await
.unwrap();
@@ -171,6 +173,8 @@ async fn message_dispatch_processes_messages_in_parallel() {
timestamp: 2,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
}))
.await
.unwrap();
@@ -238,6 +242,8 @@ async fn process_channel_message_cancels_scoped_typing_task() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -328,6 +334,8 @@ async fn dispatch_routes_through_agent_run_turn_bus_handler() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -463,6 +471,8 @@ async fn run_resolved_route_message(message_id: &str, noise_after: usize) {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -585,6 +595,8 @@ async fn process_channel_message_hardens_multimodal_files_against_smuggled_marke
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -668,6 +680,8 @@ async fn process_channel_message_hardens_against_relative_path_markers() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
diff --git a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs
index 979ee7063f..10193fb913 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs
@@ -62,6 +62,8 @@ async fn process_channel_message_executes_native_tool_calls() {
timestamp: 2,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -133,6 +135,8 @@ async fn process_channel_message_handles_models_command_without_llm_call() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let route_key = conversation_history_key(&cmd_msg);
process_channel_message(runtime_ctx.clone(), cmd_msg).await;
@@ -188,6 +192,8 @@ async fn process_channel_message_uses_route_override_provider_and_model() {
timestamp: 2,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let route_key = conversation_history_key(&routed_msg);
let mut route_overrides = HashMap::new();
@@ -289,6 +295,8 @@ async fn process_channel_message_respects_configured_max_tool_iterations_above_d
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -349,6 +357,8 @@ async fn process_channel_message_reports_configured_max_tool_iterations_limit()
timestamp: 2,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
diff --git a/crates/openhuman-core/src/channels/tests/telegram_integration.rs b/crates/openhuman-core/src/channels/tests/telegram_integration.rs
index 684dd48639..b2cc290018 100644
--- a/crates/openhuman-core/src/channels/tests/telegram_integration.rs
+++ b/crates/openhuman-core/src/channels/tests/telegram_integration.rs
@@ -129,6 +129,8 @@ async fn inbound_thread_ts_is_forwarded_to_channel_send() {
timestamp: 1,
thread_ts: Some("99".to_string()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -167,6 +169,8 @@ async fn no_thread_ts_on_inbound_message_results_in_none_on_send() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -205,6 +209,8 @@ async fn reaction_marker_in_llm_response_is_passed_to_channel_send() {
timestamp: 1,
thread_ts: Some("42".to_string()), // message_id the reaction targets
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -257,6 +263,8 @@ async fn typing_indicator_starts_and_stops_once_per_message() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -287,6 +295,8 @@ fn telegram_channel_history_key_ignores_thread_ts() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let msg_with_thread = traits::ChannelMessage {
@@ -381,6 +391,8 @@ async fn telegram_threaded_inbound_emits_ack_reaction_then_reply() {
timestamp: 1,
thread_ts: Some("77".to_string()),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
)
.await;
@@ -447,6 +459,8 @@ fn non_telegram_channel_history_key_includes_thread_ts() {
timestamp: 1,
thread_ts: None,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
};
let msg_in_thread = traits::ChannelMessage {
diff --git a/crates/openhuman-core/src/flows/authoring_host.rs b/crates/openhuman-core/src/flows/authoring_host.rs
index 048de8b5c9..2deb13045b 100644
--- a/crates/openhuman-core/src/flows/authoring_host.rs
+++ b/crates/openhuman-core/src/flows/authoring_host.rs
@@ -122,8 +122,8 @@ impl ApprovalCallbacks {
self.0
.in_context(async move {
use crate::flows::caps_host::classify_composio_action_for_tier;
+ use crate::security::policy::CommandClass;
use crate::security::{GateDecision, SecurityPolicy};
- use tinybox_bus::CommandClass;
use tinyflows_bus::catalog::{ManifestCandidate, ManifestClass};
let security = SecurityPolicy::from_config(
diff --git a/crates/openhuman-core/src/flows/caps_host/code.rs b/crates/openhuman-core/src/flows/caps_host/code.rs
index 2b307277ae..6b180d931a 100644
--- a/crates/openhuman-core/src/flows/caps_host/code.rs
+++ b/crates/openhuman-core/src/flows/caps_host/code.rs
@@ -13,9 +13,9 @@ use serde_json::{json, Value};
use super::*;
use crate::config::Config;
use crate::sandbox::{execute_in_sandbox, resolve_sandbox_policy};
+use crate::security::policy::CommandClass;
use crate::security::SecurityPolicy;
use tinyagents_definition::SandboxMode;
-use tinybox_bus::CommandClass;
/// [`CodeRunner`] adapter running sandboxed user code via
/// `crates/openhuman-core/src/sandbox/ops.rs` (`resolve_sandbox_policy` +
diff --git a/crates/openhuman-core/src/flows/caps_host/http.rs b/crates/openhuman-core/src/flows/caps_host/http.rs
index 0498629015..1031078c76 100644
--- a/crates/openhuman-core/src/flows/caps_host/http.rs
+++ b/crates/openhuman-core/src/flows/caps_host/http.rs
@@ -17,9 +17,9 @@ use super::*;
use crate::config::{Config, HttpRequestConfig};
use crate::modules::tinyflows as module;
use crate::security::credentials::{HttpCredential, HttpCredentialsStore};
+use crate::security::policy::CommandClass;
use crate::security::SecurityPolicy;
use crate::tools::http_request_tool;
-use tinybox_bus::CommandClass;
use tinytools::Tool as _;
use super::{
diff --git a/crates/openhuman-core/src/flows/caps_host/memory.rs b/crates/openhuman-core/src/flows/caps_host/memory.rs
index 2128c8213d..752b3744e5 100644
--- a/crates/openhuman-core/src/flows/caps_host/memory.rs
+++ b/crates/openhuman-core/src/flows/caps_host/memory.rs
@@ -42,11 +42,11 @@ use crate::flows::{
};
use crate::memory::types::{FetchParams, RecallParams};
use crate::security::approval::{redact_args, summarize_action, GateOutcome};
+use crate::security::policy::CommandClass;
#[cfg(test)]
use crate::security::turn_origin;
use crate::security::turn_origin::{AgentTurnOrigin, TrustedAutomationSource};
use crate::security::SecurityPolicy;
-use tinybox_bus::CommandClass;
use tinymemory_api::wrap_untrusted_for_agent;
use tinymemory_api::Error;
use tinymemory_api::{Hit, LearningKind, MemoryMeta, MetaFilter, SourceKind};
diff --git a/crates/openhuman-core/src/flows/caps_host/ops_tier_gate_and_timeouts_tests.rs b/crates/openhuman-core/src/flows/caps_host/ops_tier_gate_and_timeouts_tests.rs
index 5aa889ba78..9698b77802 100644
--- a/crates/openhuman-core/src/flows/caps_host/ops_tier_gate_and_timeouts_tests.rs
+++ b/crates/openhuman-core/src/flows/caps_host/ops_tier_gate_and_timeouts_tests.rs
@@ -1,11 +1,11 @@
use super::super::tier::{escalated_origin_for_nested_harness, escalated_origin_for_prompt};
use super::*;
use crate::config::HttpRequestConfig;
+use crate::security::policy::CommandClass;
use crate::security::GateDecision;
use serde_json::json;
use std::sync::Arc;
use tinyagents_harness::tool::response_fields_from_schema;
-use tinybox_bus::CommandClass;
use tinytools::status::POLICY_BLOCKED_MARKER;
/// The tier gate an `http_request` (Network-class) node calls: BLOCKED under
diff --git a/crates/openhuman-core/src/flows/caps_host/ops_tier_live_config_tests.rs b/crates/openhuman-core/src/flows/caps_host/ops_tier_live_config_tests.rs
index ce5eba9ef2..acb321c5eb 100644
--- a/crates/openhuman-core/src/flows/caps_host/ops_tier_live_config_tests.rs
+++ b/crates/openhuman-core/src/flows/caps_host/ops_tier_live_config_tests.rs
@@ -1,9 +1,9 @@
use super::super::tier::tier_policy_from_config;
use super::*;
+use crate::security::policy::CommandClass;
use crate::security::GateDecision;
use serde_json::json;
use std::sync::Arc;
-use tinybox_bus::CommandClass;
fn live_tier_context(config: &Config) -> crate::core::runtime::DispatchCtx {
let parent = crate::core::runtime::CoreContext::for_test(
diff --git a/crates/openhuman-core/src/flows/caps_host/tier.rs b/crates/openhuman-core/src/flows/caps_host/tier.rs
index 918574c705..5ae72dbf8b 100644
--- a/crates/openhuman-core/src/flows/caps_host/tier.rs
+++ b/crates/openhuman-core/src/flows/caps_host/tier.rs
@@ -8,8 +8,8 @@
use super::{EngineError, Result};
use serde_json::Value;
+use crate::security::policy::CommandClass;
use crate::security::{GateDecision, SecurityPolicy};
-use tinybox_bus::CommandClass;
use tinytools::status::POLICY_BLOCKED_MARKER;
/// Hard autonomy-tier gate for an *acting* flow node (Phase 2).
diff --git a/crates/openhuman-core/src/flows/caps_host/tools/composio.rs b/crates/openhuman-core/src/flows/caps_host/tools/composio.rs
index 3ece7213bf..8cd8eae18d 100644
--- a/crates/openhuman-core/src/flows/caps_host/tools/composio.rs
+++ b/crates/openhuman-core/src/flows/caps_host/tools/composio.rs
@@ -22,7 +22,7 @@ impl FlowCallPolicy for FlowPolicy {
captured: &Config,
live: &Config,
security: &SecurityPolicy,
- class: tinybox_bus::CommandClass,
+ class: crate::security::policy::CommandClass,
) -> std::result::Result<GateDecision, String> {
let policy =
super::super::tier::tier_policy_from_config(dispatch, captured, Some(live), security)
diff --git a/crates/openhuman-core/src/flows/caps_host/tools/mod.rs b/crates/openhuman-core/src/flows/caps_host/tools/mod.rs
index 7a7afd0778..9a7e3125ec 100644
--- a/crates/openhuman-core/src/flows/caps_host/tools/mod.rs
+++ b/crates/openhuman-core/src/flows/caps_host/tools/mod.rs
@@ -40,7 +40,9 @@ use super::{EngineError, Result};
pub(crate) use composio::ComposioToolBackend;
pub(crate) use native::{NativeToolBackend, NATIVE_TOOL_PREFIX};
-pub(crate) async fn classify_composio_action_for_tier(slug: &str) -> tinybox_bus::CommandClass {
+pub(crate) async fn classify_composio_action_for_tier(
+ slug: &str,
+) -> crate::security::policy::CommandClass {
crate::integrations::composio::flow_gate::classify_composio_action_for_tier(slug)
}
diff --git a/crates/openhuman-core/src/flows/caps_host/tools/native.rs b/crates/openhuman-core/src/flows/caps_host/tools/native.rs
index 42d7c827e5..42bdd16a2a 100644
--- a/crates/openhuman-core/src/flows/caps_host/tools/native.rs
+++ b/crates/openhuman-core/src/flows/caps_host/tools/native.rs
@@ -1,9 +1,9 @@
//! Thin TinyFlows registration and error adapter for native OpenHuman tools.
use super::super::{EngineError, Result};
+use crate::security::policy::CommandClass;
use async_trait::async_trait;
use serde_json::Value;
-use tinybox_bus::CommandClass;
use super::{ToolBackend, ToolCallCtx};
diff --git a/crates/openhuman-core/src/flows/caps_host/tools/native_backend.rs b/crates/openhuman-core/src/flows/caps_host/tools/native_backend.rs
index eb127a8a7a..bbcd60799c 100644
--- a/crates/openhuman-core/src/flows/caps_host/tools/native_backend.rs
+++ b/crates/openhuman-core/src/flows/caps_host/tools/native_backend.rs
@@ -5,9 +5,9 @@
use std::sync::Arc;
+use crate::security::policy::CommandClass;
use async_trait::async_trait;
use serde_json::{json, Value};
-use tinybox_bus::CommandClass;
use tinytools::ToolResult;
use crate::{config::Config, security::SecurityPolicy};
diff --git a/crates/openhuman-core/src/inbound/linked_fixture.rs b/crates/openhuman-core/src/inbound/linked_fixture.rs
index 44f4e0ecf9..f2f42e3736 100644
--- a/crates/openhuman-core/src/inbound/linked_fixture.rs
+++ b/crates/openhuman-core/src/inbound/linked_fixture.rs
@@ -239,13 +239,10 @@ impl PinnedAgent for ScriptedAgent {
/// A results store in fresh memory storage.
pub(crate) fn memory_results() -> Results {
- use crate::storage::StorageBackend;
- let storage = crate::storage::MemoryStorage::new();
- Results::over(
- &storage
- .for_scope(&crate::storage::Scope::new("local").unwrap())
- .unwrap(),
- )
+ let storage = tinystoragedrivers_testkit::memory_storage(
+ &crate::storage::Scope::new("local").unwrap(),
+ );
+ Results::over(&storage)
}
/// `[inbound]` with `x:mentions` pinned to `teeny-mentions`, flushing after
diff --git a/crates/openhuman-core/src/inbound/results.rs b/crates/openhuman-core/src/inbound/results.rs
index ecbb0e2093..4ceefc7d6a 100644
--- a/crates/openhuman-core/src/inbound/results.rs
+++ b/crates/openhuman-core/src/inbound/results.rs
@@ -213,8 +213,8 @@ impl Results {
}
#[cfg(test)]
- pub(crate) fn over(scoped: &crate::storage::ScopedStorage) -> Self {
- Self(Repo::over(scoped, DOMAIN, specs))
+ pub(crate) fn over(scoped: &crate::storage::Storage) -> Self {
+ Self(Repo::over(scoped, DOMAIN, collection_specs))
}
/// Record `stored` unless its turn is already recorded; either way, the
diff --git a/crates/openhuman-core/src/inbound/results_tests.rs b/crates/openhuman-core/src/inbound/results_tests.rs
index 423c2b7ef5..f7af0113e6 100644
--- a/crates/openhuman-core/src/inbound/results_tests.rs
+++ b/crates/openhuman-core/src/inbound/results_tests.rs
@@ -1,11 +1,12 @@
//! Tests for the store of pinned-agent results.
use super::*;
-use crate::storage::{MemoryStorage, Scope, StorageBackend};
+use crate::storage::Scope;
+use tinystoragedrivers_testkit::memory_storage;
fn results() -> Results {
- let storage = MemoryStorage::new();
- Results::over(&storage.for_scope(&Scope::new("local").unwrap()).unwrap())
+ let storage = memory_storage(&Scope::new("local").unwrap());
+ Results::over(&storage)
}
fn running(turn_id: &str, source: &str, created_ms: u64) -> Stored {
diff --git a/crates/openhuman-core/src/integrations/composio/flow_backend.rs b/crates/openhuman-core/src/integrations/composio/flow_backend.rs
index adebcd3426..7938358c43 100644
--- a/crates/openhuman-core/src/integrations/composio/flow_backend.rs
+++ b/crates/openhuman-core/src/integrations/composio/flow_backend.rs
@@ -41,7 +41,7 @@ pub(crate) trait FlowCallPolicy: Send + Sync {
captured: &Config,
live: &Config,
security: &SecurityPolicy,
- class: tinybox_bus::CommandClass,
+ class: crate::security::policy::CommandClass,
) -> Result<GateDecision, String>;
async fn approve(
&self,
diff --git a/crates/openhuman-core/src/integrations/composio/flow_gate.rs b/crates/openhuman-core/src/integrations/composio/flow_gate.rs
index 9f6106884f..0e1d0424f1 100644
--- a/crates/openhuman-core/src/integrations/composio/flow_gate.rs
+++ b/crates/openhuman-core/src/integrations/composio/flow_gate.rs
@@ -122,9 +122,11 @@ pub(crate) async fn is_curated_flow_tool(
}
/// Classifies a curated action for the autonomy-tier gate.
-pub(crate) fn classify_composio_action_for_tier(slug: &str) -> tinybox_bus::CommandClass {
+pub(crate) fn classify_composio_action_for_tier(
+ slug: &str,
+) -> crate::security::policy::CommandClass {
use crate::integrations::composio::contract::{curated_scope_for, ToolScope};
- use tinybox_bus::CommandClass;
+ use crate::security::policy::CommandClass;
match curated_scope_for(slug) {
Some(ToolScope::Read) => CommandClass::Read,
Some(ToolScope::Write) | Some(ToolScope::Admin) | None => CommandClass::Network,
diff --git a/crates/openhuman-core/src/integrations/composio/flow_gate_tests.rs b/crates/openhuman-core/src/integrations/composio/flow_gate_tests.rs
index 9a5892e50f..925c6ad70f 100644
--- a/crates/openhuman-core/src/integrations/composio/flow_gate_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/flow_gate_tests.rs
@@ -4,8 +4,8 @@ use crate::integrations::composio::catalog::{
seed_live_catalog_cache, seed_live_catalog_cache_expired, ToolContract,
};
use crate::integrations::composio::{ComposioExecuteResponse, ConnectedIntegration};
+use crate::security::policy::CommandClass;
use serde_json::json;
-use tinybox_bus::CommandClass;
fn integration(
toolkit: &str,
diff --git a/crates/openhuman-core/src/memory/tools_queue_failure_tests.rs b/crates/openhuman-core/src/memory/tools_queue_failure_tests.rs
index 8e91a3ba9d..347a2fa627 100644
--- a/crates/openhuman-core/src/memory/tools_queue_failure_tests.rs
+++ b/crates/openhuman-core/src/memory/tools_queue_failure_tests.rs
@@ -39,5 +39,5 @@ async fn learning_is_durably_queued_even_when_the_backend_refuses_writes() {
assert!(!result.is_error, "{}", result.text());
let value: serde_json::Value = serde_json::from_str(&result.text()).unwrap();
assert_eq!(value["status"], "queued; not yet saved to memory");
- assert_eq!(super::tool_writes::drain(&config).await, 0);
+ assert_eq!(crate::memory::tool_writes::drain(&config).await, 0);
}
diff --git a/crates/openhuman-core/src/modules/channel_runtime_tests.rs b/crates/openhuman-core/src/modules/channel_runtime_tests.rs
index 8539b1b581..2f6796248c 100644
--- a/crates/openhuman-core/src/modules/channel_runtime_tests.rs
+++ b/crates/openhuman-core/src/modules/channel_runtime_tests.rs
@@ -122,7 +122,7 @@ impl TransportFixture {
let tinychannels_bus::ChannelBackendRequest::ProgressiveTransport(request) = request else {
return Err(tinybus::Error::failed("unexpected fixture capability"));
};
- let value = if let ProgressiveTransportRequest::Send { message, .. } = request {
+ let value = if let ProgressiveTransportRequest::Send { message, .. } = *request {
assert!(message["idempotencyKey"].as_str().is_some());
assert_eq!(message["text"].as_str(), Some(self.expected_text.as_str()));
self.sends.fetch_add(1, Ordering::SeqCst);
diff --git a/crates/openhuman-core/src/modules/tinybox/operations.rs b/crates/openhuman-core/src/modules/tinybox/operations.rs
index 443b75d7e9..5b452ce02e 100644
--- a/crates/openhuman-core/src/modules/tinybox/operations.rs
+++ b/crates/openhuman-core/src/modules/tinybox/operations.rs
@@ -35,7 +35,6 @@ const SHUTDOWN: &str = contract::names::SHUTDOWN;
const FORWARD: &str = contract::names::FORWARD;
const CLOSE_FORWARD: &str = contract::names::CLOSE_FORWARD;
const JAIL_STATUS: &str = contract::names::JAIL_STATUS;
-const ANALYZE_COMMAND: &str = contract::names::ANALYZE_COMMAND;
const BEGIN_FILE_READ: &str = contract::names::BEGIN_FILE_READ;
const READ_FILE_CHUNK: &str = contract::names::READ_FILE_CHUNK;
const FINISH_FILE_READ: &str = contract::names::FINISH_FILE_READ;
@@ -360,11 +359,12 @@ pub async fn analyze_shell(
}
/// Ask TinyBox for generic command facts; the caller still decides policy.
-pub async fn analyze_command(
+pub(crate) async fn analyze_command(
config: &Config,
command: String,
-) -> Result<contract::CommandAnalysis, String> {
- call(config, ANALYZE_COMMAND, (command,), false).await
+) -> Result<crate::security::policy::CommandAnalysis, String> {
+ let facts = analyze_shell(config, command).await?;
+ Ok(crate::security::policy::CommandAnalysis::from_shell_analysis(facts))
}
/// Open a bounded workspace file reader.
diff --git a/crates/openhuman-core/src/modules/tinybox/operations_tests.rs b/crates/openhuman-core/src/modules/tinybox/operations_tests.rs
index 3030bcb3c7..08615cbc09 100644
--- a/crates/openhuman-core/src/modules/tinybox/operations_tests.rs
+++ b/crates/openhuman-core/src/modules/tinybox/operations_tests.rs
@@ -60,14 +60,9 @@ impl Interface for MockTinyBox {
spawn_backends: vec!["docker".to_owned()],
})
.map_err(tinybus::Error::from),
- ANALYZE_COMMAND => serde_json::to_value(contract::CommandAnalysis {
- segments: Vec::new(),
- hidden_execution: false,
+ ANALYZE_SHELL => serde_json::to_value(contract::ShellAnalysis {
+ segments: vec!["printf 'hello'".to_owned()],
redirection: false,
- expansion: false,
- tee: false,
- background: false,
- literal_words: vec!["printf".to_owned(), "hello".to_owned()],
})
.map_err(tinybus::Error::from),
DOCKER_STATUS => serde_json::to_value(contract::DockerStatus { available: true })
@@ -154,20 +149,21 @@ fn host_and_module_contract_versions_must_cover_the_full_host_surface() {
}
#[tokio::test]
-async fn command_facts_use_contract_member_and_positional_arguments() {
+async fn command_facts_use_shell_contract_and_host_policy_facts() {
let (_service, client, calls) = mock_client().await;
let command = "printf 'hello'".to_owned();
- let facts: contract::CommandAnalysis =
- call_with_client(&client, ANALYZE_COMMAND, (command.clone(),), false)
+ let raw: contract::ShellAnalysis =
+ call_with_client(&client, ANALYZE_SHELL, (command.clone(),), false)
.await
- .expect("typed command facts");
+ .expect("typed shell facts");
+ let facts = crate::security::policy::CommandAnalysis::from_shell_analysis(raw);
assert_eq!(facts.literal_words, ["printf", "hello"]);
assert_eq!(
calls.lock().expect("call log lock").as_slice(),
[
(CAPABILITIES.to_owned(), json!([])),
- (ANALYZE_COMMAND.to_owned(), json!([command]))
+ (ANALYZE_SHELL.to_owned(), json!([command]))
]
);
}
@@ -456,7 +452,6 @@ fn every_host_operation_is_a_member_of_the_canonical_contract() {
FORWARD,
CLOSE_FORWARD,
JAIL_STATUS,
- ANALYZE_COMMAND,
BEGIN_FILE_READ,
READ_FILE_CHUNK,
FINISH_FILE_READ,
@@ -496,7 +491,6 @@ fn every_member_the_host_calls_is_named_in_the_pinned_contract() {
FORWARD,
CLOSE_FORWARD,
JAIL_STATUS,
- ANALYZE_COMMAND,
BEGIN_FILE_READ,
READ_FILE_CHUNK,
FINISH_FILE_READ,
diff --git a/crates/openhuman-core/src/security/policy/command_checks.rs b/crates/openhuman-core/src/security/policy/command_checks.rs
index a17a2706c8..40ffb8291e 100644
--- a/crates/openhuman-core/src/security/policy/command_checks.rs
+++ b/crates/openhuman-core/src/security/policy/command_checks.rs
@@ -7,31 +7,295 @@ use std::path::{Path, PathBuf};
#[cfg(test)]
use super::types::CommandRiskLevel;
use super::types::{AutonomyLevel, GateDecision, SecurityPolicy};
+use crate::security::policy::CommandClass;
#[cfg(test)]
use crate::util::floor_char_boundary;
-use tinybox_bus::CommandClass;
-#[cfg(test)]
-use tinybox_core::shell::classify::{classify_segment, has_hidden_execution};
-#[cfg(test)]
-use tinybox_core::shell::env_guard::has_dangerous_env_prefix;
-#[cfg(test)]
-use tinybox_core::shell::executor::is_command_executor;
#[cfg(test)]
use tinybox_core::shell::scan::{
- command_basename, contains_unquoted_char, contains_unquoted_single_ampersand,
- has_leading_env_assignment, normalized_command_name, skip_env_assignments,
- split_unquoted_segments, strip_quoted_heredoc_bodies,
+ contains_unquoted_char, split_unquoted_segments, strip_quoted_heredoc_bodies,
};
use tinytools::status::POLICY_BLOCKED_MARKER;
+#[cfg(test)]
+fn command_basename(command: &str) -> &str {
+ command.rsplit(['/', '\\']).next().unwrap_or(command)
+}
+
+#[cfg(test)]
+fn normalized_command_name(command: &str) -> String {
+ command_basename(command.trim_matches(|c: char| matches!(c, '\'' | '"')))
+ .to_ascii_lowercase()
+}
+
+#[cfg(test)]
+fn skip_env_assignments(command: &str) -> &str {
+ let mut rest = command;
+ loop {
+ rest = rest.trim_start();
+ let Some(end) = rest.find(char::is_whitespace) else {
+ return if rest.contains('=') { "" } else { rest };
+ };
+ if !rest[..end].contains('=') {
+ return rest;
+ }
+ rest = &rest[end..];
+ }
+}
+
+#[cfg(test)]
+fn has_leading_env_assignment(command: &str) -> bool {
+ command
+ .split_whitespace()
+ .next()
+ .is_some_and(|word| word.contains('='))
+}
+
+#[cfg(test)]
+fn has_dangerous_env_prefix(command: &str) -> bool {
+ command.split_whitespace().take_while(|word| word.contains('=')).any(|word| {
+ matches!(
+ word.split('=').next().unwrap_or_default().to_ascii_uppercase().as_str(),
+ "LD_PRELOAD" | "LD_LIBRARY_PATH" | "DYLD_INSERT_LIBRARIES" | "DYLD_LIBRARY_PATH" | "PATH"
+ )
+ })
+}
+
+#[cfg(test)]
+fn contains_unquoted_single_ampersand(command: &str) -> bool {
+ contains_unquoted_char(command, '&')
+ && !command.contains("&&")
+ && !command.contains(">&")
+}
+
+#[cfg(test)]
+fn has_hidden_execution(command: &str) -> bool {
+ ["$(", "<(", ">("]
+ .iter()
+ .any(|needle| command.contains(needle))
+ || contains_unquoted_char(command, '`')
+ || contains_unquoted_single_ampersand(command)
+}
+
+#[cfg(test)]
+fn is_command_executor(command: &str) -> bool {
+ matches!(
+ command,
+ "sh" | "bash" | "zsh" | "fish" | "python" | "python2" | "python3" | "node"
+ | "ruby" | "perl" | "php" | "lua" | "awk" | "xargs"
+ )
+}
+
+#[cfg(test)]
+fn classify_segment(base: &str, args: &[String], joined: &str) -> CommandClass {
+ classify_host_command(base, args, joined)
+}
+
+/// Host-owned interpretation of TinyBox's structural shell facts.
+///
+/// TinyBox reports live command segments and redirection only. OpenHuman adds
+/// the policy fields below locally so command permission and autonomy remain
+/// host decisions instead of bus-contract vocabulary.
+#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
+pub(crate) struct CommandAnalysis {
+ pub segments: Vec<CommandSegment>,
+ pub hidden_execution: bool,
+ pub redirection: bool,
+ pub expansion: bool,
+ pub tee: bool,
+ pub background: bool,
+ pub literal_words: Vec<String>,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
+pub(crate) struct CommandSegment {
+ pub source: String,
+ pub command: String,
+ pub basename: String,
+ pub normalized_name: String,
+ pub arguments: Vec<String>,
+ pub class: CommandClass,
+ pub leading_env_assignment: bool,
+ pub dangerous_env_prefix: bool,
+ pub executor: bool,
+}
+
+impl CommandAnalysis {
+ pub(crate) fn from_shell_analysis(facts: tinybox_bus::ShellAnalysis) -> Self {
+ let mut analysis = Self {
+ segments: Vec::new(),
+ hidden_execution: false,
+ redirection: facts.redirection,
+ expansion: false,
+ tee: false,
+ background: false,
+ literal_words: Vec::new(),
+ };
+
+ for source in facts.segments {
+ let words = source.split_whitespace().collect::<Vec<_>>();
+ let Some(raw_command) = words.first().copied() else {
+ continue;
+ };
+ let command = raw_command.trim_matches(|c: char| matches!(c, '\'' | '"'));
+ let basename = command.rsplit(['/', '\\']).next().unwrap_or(command);
+ let normalized_name = basename.to_ascii_lowercase();
+ let arguments = words
+ .iter()
+ .skip(1)
+ .map(|word| {
+ word.trim_matches(|c: char| matches!(c, '\'' | '"'))
+ .to_owned()
+ })
+ .collect::<Vec<_>>();
+ let lower = source.to_ascii_lowercase();
+ let leading_env_assignment = command.contains('=')
+ && command.split_once('=').is_some_and(|(name, _)| {
+ !name.is_empty() && name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')
+ });
+ let dangerous_env_prefix =
+ words
+ .iter()
+ .take_while(|word| word.contains('='))
+ .any(|word| {
+ let name = word
+ .split('=')
+ .next()
+ .unwrap_or_default()
+ .to_ascii_uppercase();
+ matches!(
+ name.as_str(),
+ "LD_PRELOAD"
+ | "LD_LIBRARY_PATH"
+ | "DYLD_INSERT_LIBRARIES"
+ | "DYLD_LIBRARY_PATH"
+ | "PATH"
+ )
+ });
+ let executor = matches!(
+ normalized_name.as_str(),
+ "sh" | "bash"
+ | "zsh"
+ | "fish"
+ | "python"
+ | "python2"
+ | "python3"
+ | "node"
+ | "ruby"
+ | "perl"
+ | "php"
+ | "lua"
+ | "awk"
+ | "xargs"
+ );
+ let class = classify_host_command(&normalized_name, &arguments, &lower);
+ analysis.hidden_execution |= lower.contains("$(")
+ || lower.contains("<(")
+ || lower.contains(">(")
+ || source.contains('`')
+ || has_background_operator(&source);
+ analysis.expansion |= source.contains('$') || source.contains('`');
+ analysis.background |= has_background_operator(&source);
+ analysis.tee |= words
+ .iter()
+ .any(|word| word == &"tee" || word.ends_with("/tee"));
+ analysis.literal_words.extend(
+ words
+ .iter()
+ .map(|word| {
+ word.trim_matches(|c: char| matches!(c, '\'' | '"' | '<' | '>' | '&' | '|'))
+ .to_owned()
+ })
+ .filter(|word| !word.is_empty()),
+ );
+ analysis.segments.push(CommandSegment {
+ source: source.clone(),
+ command: source.clone(),
+ basename: basename.to_owned(),
+ normalized_name,
+ arguments,
+ class,
+ leading_env_assignment,
+ dangerous_env_prefix,
+ executor,
+ });
+ }
+ analysis
+ }
+}
+
+fn has_background_operator(source: &str) -> bool {
+ let bytes = source.as_bytes();
+ bytes.iter().enumerate().any(|(index, byte)| {
+ *byte == b'&'
+ && bytes.get(index + 1) != Some(&b'&')
+ && (index == 0 || bytes[index - 1] != b'&')
+ && (index == 0 || bytes[index - 1] != b'>')
+ })
+}
+
+fn classify_host_command(base: &str, args: &[String], source: &str) -> CommandClass {
+ if matches!(
+ base,
+ "sudo"
+ | "su"
+ | "mkfs"
+ | "dd"
+ | "shutdown"
+ | "reboot"
+ | "halt"
+ | "poweroff"
+ | "useradd"
+ | "userdel"
+ | "usermod"
+ | "passwd"
+ ) || source.contains("rm -rf /")
+ || source.contains("rm -fr /")
+ || source.contains(":(){:|:&};:")
+ {
+ return CommandClass::Destructive;
+ }
+ if matches!(
+ base,
+ "curl" | "wget" | "ssh" | "scp" | "sftp" | "ftp" | "telnet" | "nc" | "ncat" | "netcat"
+ ) {
+ return CommandClass::Network;
+ }
+ let first = args.first().map(String::as_str).unwrap_or_default();
+ if matches!(base, "npm" | "pnpm" | "yarn" | "pip" | "pip3")
+ && matches!(first, "install" | "add" | "remove" | "uninstall" | "update")
+ || base == "cargo" && matches!(first, "add" | "remove" | "install" | "update")
+ {
+ return CommandClass::Install;
+ }
+ if matches!(
+ base,
+ "ls" | "pwd"
+ | "cat"
+ | "head"
+ | "tail"
+ | "grep"
+ | "rg"
+ | "find"
+ | "stat"
+ | "wc"
+ | "sort"
+ | "echo"
+ | "printf"
+ | "whoami"
+ | "date"
+ ) || base == "git" && matches!(first, "status" | "diff" | "log" | "show" | "branch")
+ || base == "cargo" && matches!(first, "check" | "test" | "tree" | "metadata")
+ {
+ return CommandClass::Read;
+ }
+ CommandClass::Write
+}
+
impl SecurityPolicy {
/// Apply the supervised allowlist to parser facts returned by TinyBox.
/// The module owns shell structure; this host owns the permission policy.
#[cfg(feature = "modules")]
- pub fn is_command_allowed_analysis(
- &self,
- analysis: &crate::modules::tinybox::contract::CommandAnalysis,
- ) -> bool {
+ pub(crate) fn is_command_allowed_analysis(&self, analysis: &CommandAnalysis) -> bool {
if !self.enabled {
return true;
}
@@ -75,9 +339,9 @@ impl SecurityPolicy {
/// The module supplies parsing facts, while this host owns path checks,
/// autonomy tiers, and approval decisions.
#[cfg(feature = "modules")]
- pub fn check_gated_command_analysis(
+ pub(crate) fn check_gated_command_analysis(
&self,
- analysis: &crate::modules::tinybox::contract::CommandAnalysis,
+ analysis: &CommandAnalysis,
) -> Result<CommandClass, String> {
self.check_protected_path_words(&analysis.literal_words)?;
diff --git a/crates/openhuman-core/src/security/policy/mod.rs b/crates/openhuman-core/src/security/policy/mod.rs
index c68e431d14..c17558fe69 100644
--- a/crates/openhuman-core/src/security/policy/mod.rs
+++ b/crates/openhuman-core/src/security/policy/mod.rs
@@ -8,6 +8,10 @@ mod path_checks;
mod types;
+pub(crate) use command_checks::CommandAnalysis;
+#[cfg(test)]
+pub(crate) use command_checks::CommandSegment;
+
pub use enforcement::validate_path_within_root;
pub use enforcement::{ensure_openhuman_scratch_dir, openhuman_scratch_dir};
#[cfg(any(feature = "modules", test))]
@@ -17,8 +21,8 @@ pub(crate) use path_checks::{
ALWAYS_FORBIDDEN_PREFIXES, SENSITIVE_COMPONENTS, SENSITIVE_FILES, SENSITIVE_PAIRS,
};
pub use types::{
- tool_result_artifacts_dir, ActionTracker, AutonomyLevel, CommandRiskLevel, GateDecision,
- SecurityPolicy, ToolOperation, TrustedAccess, TrustedRoot,
+ tool_result_artifacts_dir, ActionTracker, AutonomyLevel, CommandClass, CommandRiskLevel,
+ GateDecision, SecurityPolicy, ToolOperation, TrustedAccess, TrustedRoot,
};
#[cfg(test)]
diff --git a/crates/openhuman-core/src/security/policy/policy_allowlist_tests.rs b/crates/openhuman-core/src/security/policy/policy_allowlist_tests.rs
index 0b0b24cdb9..84cd1c3b5c 100644
--- a/crates/openhuman-core/src/security/policy/policy_allowlist_tests.rs
+++ b/crates/openhuman-core/src/security/policy/policy_allowlist_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use tinybox_bus::CommandClass;
+use crate::security::policy::CommandClass;
// -- AutonomyLevel ------------------------------------------------
diff --git a/crates/openhuman-core/src/security/policy/policy_disabled_tests.rs b/crates/openhuman-core/src/security/policy/policy_disabled_tests.rs
index 1cdfe90366..bdc0af8bed 100644
--- a/crates/openhuman-core/src/security/policy/policy_disabled_tests.rs
+++ b/crates/openhuman-core/src/security/policy/policy_disabled_tests.rs
@@ -6,8 +6,8 @@
//! likely to break, so it is asserted here beside the first.
use super::*;
+use crate::security::policy::CommandClass;
use std::path::PathBuf;
-use tinybox_bus::CommandClass;
fn disabled_policy() -> SecurityPolicy {
SecurityPolicy {
diff --git a/crates/openhuman-core/src/security/policy/policy_injection_tests.rs b/crates/openhuman-core/src/security/policy/policy_injection_tests.rs
index c11f7df924..dc634ebbbc 100644
--- a/crates/openhuman-core/src/security/policy/policy_injection_tests.rs
+++ b/crates/openhuman-core/src/security/policy/policy_injection_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use tinybox_bus::CommandClass;
+use crate::security::policy::CommandClass;
#[test]
fn command_injection_background_chain_blocked() {
diff --git a/crates/openhuman-core/src/security/policy/policy_paths_and_risk_tests.rs b/crates/openhuman-core/src/security/policy/policy_paths_and_risk_tests.rs
index d501648f38..e7a790a2c8 100644
--- a/crates/openhuman-core/src/security/policy/policy_paths_and_risk_tests.rs
+++ b/crates/openhuman-core/src/security/policy/policy_paths_and_risk_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use tinybox_bus::CommandClass;
+use crate::security::policy::CommandClass;
#[test]
fn always_forbidden_blocks_core_os_dirs_cross_platform() {
@@ -73,7 +73,7 @@ fn parse_declared_class_maps_known_and_rejects_unknown() {
#[cfg(feature = "modules")]
#[test]
fn tinybox_command_facts_drive_policy_and_keep_the_path_floor_when_disabled() {
- use crate::modules::tinybox::contract::{CommandAnalysis, CommandSegment};
+ use crate::security::policy::{CommandAnalysis, CommandSegment};
let write_segment = CommandSegment {
source: "ls -la".into(),
@@ -154,7 +154,7 @@ fn tinybox_command_facts_drive_policy_and_keep_the_path_floor_when_disabled() {
#[cfg(feature = "modules")]
#[test]
fn tinybox_fact_allowlist_treats_heredoc_as_data_and_unknown_commands_as_writes() {
- use crate::modules::tinybox::contract::{CommandAnalysis, CommandSegment};
+ use crate::security::policy::{CommandAnalysis, CommandSegment};
let policy = SecurityPolicy {
enabled: true,
diff --git a/crates/openhuman-core/src/security/policy/proptest_tests.rs b/crates/openhuman-core/src/security/policy/proptest_tests.rs
index 481deeeeff..17afabd7b0 100644
--- a/crates/openhuman-core/src/security/policy/proptest_tests.rs
+++ b/crates/openhuman-core/src/security/policy/proptest_tests.rs
@@ -6,8 +6,8 @@
//! the hand-enumerated cases in `policy_tests.rs`.
use super::types::SecurityPolicy;
+use crate::security::policy::CommandClass;
use proptest::prelude::*;
-use tinybox_bus::CommandClass;
proptest! {
#![proptest_config(ProptestConfig {
diff --git a/crates/openhuman-core/src/security/policy/types.rs b/crates/openhuman-core/src/security/policy/types.rs
index a2df44d0c1..9aac166ce8 100644
--- a/crates/openhuman-core/src/security/policy/types.rs
+++ b/crates/openhuman-core/src/security/policy/types.rs
@@ -54,6 +54,25 @@ pub enum CommandRiskLevel {
High,
}
+/// OpenHuman's fail-closed classification for an acting command.
+///
+/// This is host policy vocabulary. Module contracts report structural facts;
+/// they do not classify commands or decide which autonomy tier may run them.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum CommandClass {
+ /// No side effects are expected.
+ Read,
+ /// Changes local or remote state.
+ Write,
+ /// Performs a network operation.
+ Network,
+ /// Installs or updates software.
+ Install,
+ /// Performs a destructive or privilege-sensitive operation.
+ Destructive,
+}
+
/// What the harness should do with an acting tool call of a given
/// [`CommandClass`] under the session's [`AutonomyLevel`]. Computed by
/// [`SecurityPolicy::gate_decision`]; the harness translates `Prompt` into an
diff --git a/crates/openhuman-core/src/threads/store/bus.rs b/crates/openhuman-core/src/threads/store/bus.rs
index 8038030836..1a793edefe 100644
--- a/crates/openhuman-core/src/threads/store/bus.rs
+++ b/crates/openhuman-core/src/threads/store/bus.rs
@@ -384,6 +384,8 @@ async fn persist_channel_turn(
timestamp: 0,
thread_ts: descriptor.thread_ts.map(ToOwned::to_owned),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
},
envelope: descriptor.inbound_envelope.cloned(),
},
@@ -393,12 +395,14 @@ async fn persist_channel_turn(
.await
.map_err(|error| error.to_string())?;
let thread_id = format!("channel:{}", prepared.history_key);
+ let history_key_ignores_thread = prepared.history_key_ignores_thread;
let session_key = descriptor.inbound_envelope.map(|_| prepared.session_key);
let title = channel_thread_title(
descriptor.channel,
descriptor.sender,
descriptor.reply_target,
descriptor.thread_ts,
+ history_key_ignores_thread,
);
let created_at = Utc::now().to_rfc3339();
@@ -485,6 +489,8 @@ fn persisted_channel_thread_id(
timestamp: 0,
thread_ts: thread_ts.map(ToOwned::to_owned),
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
});
format!("channel:{key}")
}
@@ -494,13 +500,12 @@ fn channel_thread_title(
sender: &str,
reply_target: &str,
thread_ts: Option<&str>,
+ history_key_ignores_thread: bool,
) -> String {
match thread_ts.and_then(non_empty_trimmed) {
// Providers whose thread_ts is only a reply target (Telegram topics)
// share one conversation, so the title leaves it out too.
- Some(thread_ts)
- if !tinychannels_bus::capabilities_for(channel).history_key_ignores_thread =>
- {
+ Some(thread_ts) if !history_key_ignores_thread => {
format!("{channel} · {sender} · {reply_target} · thread {thread_ts}")
}
_ => format!("{channel} · {sender} · {reply_target}"),
diff --git a/crates/openhuman-core/src/threads/store/bus_tests.rs b/crates/openhuman-core/src/threads/store/bus_tests.rs
index 49f3542930..10cbe48c45 100644
--- a/crates/openhuman-core/src/threads/store/bus_tests.rs
+++ b/crates/openhuman-core/src/threads/store/bus_tests.rs
@@ -29,6 +29,8 @@ async fn persists_inbound_and_processed_turns_into_workspace_thread() {
thread_ts: Some("thread-1".into()),
timestamp: 0,
sender_name: None,
+ reply_to_id: None,
+ topic_id: None,
});
inbound_envelope.conversation.kind = tinychannels_bus::channel::ConversationKind::Channel;
inbound_envelope.conversation.scope_id = Some("T123".into());
@@ -169,11 +171,11 @@ fn persisted_channel_thread_id_ignores_blank_thread_ts() {
#[test]
fn channel_thread_title_uses_thread_suffix_only_for_non_telegram_threads() {
assert_eq!(
- channel_thread_title("slack", "alice", "general", Some(" 123 ")),
+ channel_thread_title("slack", "alice", "general", Some(" 123 "), false),
"slack · alice · general · thread 123"
);
assert_eq!(
- channel_thread_title("telegram", "alice", "chat-1", Some("123")),
+ channel_thread_title("telegram", "alice", "chat-1", Some("123"), true),
"telegram · alice · chat-1"
);
}
diff --git a/crates/openhuman-core/src/tools/impl/filesystem/gate.rs b/crates/openhuman-core/src/tools/impl/filesystem/gate.rs
index 0bfaca8dab..d2c9fdfc4e 100644
--- a/crates/openhuman-core/src/tools/impl/filesystem/gate.rs
+++ b/crates/openhuman-core/src/tools/impl/filesystem/gate.rs
@@ -10,9 +10,9 @@ use std::sync::Arc;
use async_trait::async_trait;
use tinytools_std::filesystem::FsGate;
+use crate::security::policy::CommandClass;
use crate::security::policy::{TrustedAccess, TrustedRoot};
use crate::security::{AutonomyLevel, GateDecision, SecurityPolicy};
-use tinybox_bus::CommandClass;
/// Clone `security` and scope it to `root`, a run's workspace descriptor root.
///
diff --git a/crates/openhuman-core/src/tools/impl/network/gate.rs b/crates/openhuman-core/src/tools/impl/network/gate.rs
index d516e012ec..8d711b0d78 100644
--- a/crates/openhuman-core/src/tools/impl/network/gate.rs
+++ b/crates/openhuman-core/src/tools/impl/network/gate.rs
@@ -10,8 +10,8 @@ use tinytools_std::network::NetGate;
use crate::security::egress::{
emit_external_transfer, local_only_tool_block, DataKind, EgressDescriptor,
};
+use crate::security::policy::CommandClass;
use crate::security::{GateDecision, SecurityPolicy};
-use tinybox_bus::CommandClass;
/// Build the egress descriptor for an outbound HTTP request (privacy epic S2,
/// #4436). The host is the destination; a request body carries tool arguments
diff --git a/crates/openhuman-core/src/tools/impl/system/shell_tests.rs b/crates/openhuman-core/src/tools/impl/system/shell_tests.rs
index a712052e83..48f4df7a16 100644
--- a/crates/openhuman-core/src/tools/impl/system/shell_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/system/shell_tests.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::modules::tinybox::host_runtime::{NativeRuntime, RuntimeAdapter};
+use crate::security::policy::CommandClass;
use crate::security::{AutonomyLevel, SecurityPolicy};
-use tinybox_bus::CommandClass;
fn test_security(autonomy: AutonomyLevel) -> Arc<SecurityPolicy> {
Arc::new(SecurityPolicy {
diff --git a/crates/openhuman-core/src/tools/native_ops.rs b/crates/openhuman-core/src/tools/native_ops.rs
index e38d80a6d8..b25ece2a21 100644
--- a/crates/openhuman-core/src/tools/native_ops.rs
+++ b/crates/openhuman-core/src/tools/native_ops.rs
@@ -5,10 +5,10 @@ use crate::config::Config;
use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
use crate::modules::tinybox::host_runtime::{NativeRuntime, RuntimeAdapter};
+use crate::security::policy::CommandClass;
use crate::security::SecurityPolicy;
use crate::tools;
use crate::tools::native_ops_types::{ExecuteToolOutcome, RuntimeToolSummary};
-use tinybox_bus::CommandClass;
use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolScope};
use tracing::{debug, trace};