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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/openfang-api/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,7 @@ pub async fn get_agent_session(
let filtered_messages: Vec<&openfang_types::message::Message> = session
.messages
.iter()
.filter(|m| {
include_system || m.role != openfang_types::message::Role::System
})
.filter(|m| include_system || m.role != openfang_types::message::Role::System)
.collect();

// Two-pass approach: ToolUse blocks live in Assistant messages while
Expand Down
5 changes: 4 additions & 1 deletion crates/openfang-api/tests/api_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ async fn test_agent_session_filters_system_messages() {
let messages = body["messages"].as_array().unwrap();
assert_eq!(messages.len(), 3, "include_system=true should return all 3");
assert_eq!(messages[0]["role"], "System");
assert_eq!(messages[0]["content"], "INTERNAL SYSTEM PROMPT — must not leak to UI");
assert_eq!(
messages[0]["content"],
"INTERNAL SYSTEM PROMPT — must not leak to UI"
);
assert_eq!(body["message_count"], 3);
assert_eq!(body["raw_message_count"], 3);
}
Expand Down
5 changes: 5 additions & 0 deletions crates/openfang-channels/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ fn default_output_format_for_channel(channel_type: &str) -> OutputFormat {
"telegram" => OutputFormat::TelegramHtml,
"slack" => OutputFormat::SlackMrkdwn,
"wecom" => OutputFormat::PlainText,
"signal" => OutputFormat::PlainText,
_ => OutputFormat::Markdown,
}
}
Expand Down Expand Up @@ -1932,6 +1933,10 @@ mod tests {
default_output_format_for_channel("discord"),
OutputFormat::Markdown
);
assert_eq!(
default_output_format_for_channel("signal"),
OutputFormat::PlainText
)
}

#[tokio::test]
Expand Down
5 changes: 4 additions & 1 deletion crates/openfang-channels/src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,10 @@ mod tests {
assert!(payload["d"].is_null());
let s = serde_json::to_string(&payload).unwrap();
let parsed: serde_json::Value = serde_json::from_str(&s).unwrap();
assert_eq!(parsed, serde_json::json!({"op": 1, "d": serde_json::Value::Null}));
assert_eq!(
parsed,
serde_json::json!({"op": 1, "d": serde_json::Value::Null})
);
}

#[test]
Expand Down
5 changes: 1 addition & 4 deletions crates/openfang-cli/src/tui/screens/hands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ impl HandsState {
if let Some(sel) = self.marketplace_list.selected() {
if sel < self.definitions.len() {
// TODO: add text-input modal for custom instance names (#878 follow-up)
return HandsAction::ActivateHand(
self.definitions[sel].id.clone(),
None,
);
return HandsAction::ActivateHand(self.definitions[sel].id.clone(), None);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/openfang-hands/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,7 @@ metrics = []
fn test_activate_same_hand_unnamed_twice_still_rejects() {
let reg = test_registry_with_dummy_hand("test-hand");
reg.activate("test-hand", HashMap::new(), None).unwrap();
let err = reg
.activate("test-hand", HashMap::new(), None)
.unwrap_err();
let err = reg.activate("test-hand", HashMap::new(), None).unwrap_err();
assert!(matches!(err, HandError::AlreadyActive(_)));
}
}
13 changes: 6 additions & 7 deletions crates/openfang-kernel/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,12 +898,12 @@ impl OpenFangKernel {
// Auto-detect embedding provider by checking API key env vars in
// priority order. First match wins.
const API_KEY_PROVIDERS: &[(&str, &str)] = &[
("OPENAI_API_KEY", "openai"),
("GROQ_API_KEY", "groq"),
("MISTRAL_API_KEY", "mistral"),
("TOGETHER_API_KEY", "together"),
("OPENAI_API_KEY", "openai"),
("GROQ_API_KEY", "groq"),
("MISTRAL_API_KEY", "mistral"),
("TOGETHER_API_KEY", "together"),
("FIREWORKS_API_KEY", "fireworks"),
("COHERE_API_KEY", "cohere"),
("COHERE_API_KEY", "cohere"),
];

let detected_from_key = API_KEY_PROVIDERS
Expand Down Expand Up @@ -1144,8 +1144,7 @@ impl OpenFangKernel {
!= entry.manifest.tool_allowlist
|| disk_manifest.tool_blocklist
!= entry.manifest.tool_blocklist
|| disk_manifest.skills
!= entry.manifest.skills
|| disk_manifest.skills != entry.manifest.skills
|| disk_manifest.mcp_servers
!= entry.manifest.mcp_servers;
if changed {
Expand Down
4 changes: 2 additions & 2 deletions crates/openfang-runtime/src/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ impl McpConnection {

// rmcp 1.3+ marks StreamableHttpClientTransportConfig as #[non_exhaustive].
// Use the official builder API (credit: @jefflower, PR #986).
let config = StreamableHttpClientTransportConfig::with_uri(url)
.custom_headers(custom_headers);
let config =
StreamableHttpClientTransportConfig::with_uri(url).custom_headers(custom_headers);

let transport = StreamableHttpClientTransport::from_config(config);

Expand Down
6 changes: 5 additions & 1 deletion crates/openfang-runtime/src/session_repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,11 @@ mod tests {
is_error,
content,
..
} => tool_use_id == "memory_store:0" && *is_error && content.contains("interrupted"),
} => {
tool_use_id == "memory_store:0"
&& *is_error
&& content.contains("interrupted")
}
_ => false,
})
} else {
Expand Down
3 changes: 1 addition & 2 deletions crates/openfang-runtime/src/tool_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3141,8 +3141,7 @@ async fn tool_process_start(
// shared validate_command_allowlist handles Deny / Full / Allowlist and
// falls through to allow commands listed in safe_bins or allowed_commands.
if let Some(policy) = exec_policy {
if let Err(reason) =
crate::subprocess_sandbox::validate_command_allowlist(command, policy)
if let Err(reason) = crate::subprocess_sandbox::validate_command_allowlist(command, policy)
{
return Err(format!(
"process_start blocked: {reason}. Current exec_policy.mode = '{:?}'. \
Expand Down
8 changes: 6 additions & 2 deletions crates/openfang-runtime/src/web_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,19 @@ mod tests {
assert!(check_ssrf("http://169.254.169.254/latest/meta-data/", &allow).is_err());
// Also verify hostname-based metadata blocks
let allow2 = vec!["metadata.google.internal".to_string()];
assert!(check_ssrf("http://metadata.google.internal/computeMetadata/v1/", &allow2).is_err());
assert!(check_ssrf(
"http://metadata.google.internal/computeMetadata/v1/",
&allow2
)
.is_err());
}

#[test]
fn test_ssrf_allowlist_wildcard_domain() {
let allow = vec!["*.example.com".to_string()];
assert!(check_ssrf("http://api.example.com", &allow).is_ok());
// Non-matching domain should still go through normal checks
assert!(is_host_allowed("other.net", &allow) == false);
assert!(!is_host_allowed("other.net", &allow));
}

#[test]
Expand Down
10 changes: 8 additions & 2 deletions crates/openfang-runtime/src/web_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ impl WebSearchEngine {

let resp = self
.client
.get(format!("{}/search", self.config.searxng.url.trim_end_matches('/')))
.get(format!(
"{}/search",
self.config.searxng.url.trim_end_matches('/')
))
.query(&[
("q", query),
("format", "json"),
Expand Down Expand Up @@ -451,7 +454,10 @@ impl WebSearchEngine {

let resp = self
.client
.get(format!("{}/config", self.config.searxng.url.trim_end_matches('/')))
.get(format!(
"{}/config",
self.config.searxng.url.trim_end_matches('/')
))
.header("User-Agent", "Mozilla/5.0 (compatible; OpenFangAgent/0.1)")
.send()
.await
Expand Down