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
9 changes: 8 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,15 @@ test-all:
echo "=== 2/8 Rust format check ==="
just with-lld cargo fmt --all -- --check
echo ""
echo "=== GPU bench Rust feature check ==="
MESH_LLM_GPU_BENCH_RUST_ONLY=1 just with-lld cargo check -p mesh-llm-gpu-bench --features cuda,hip,intel
echo ""
echo "=== 3/8 Clippy ==="
just with-lld cargo clippy -p mesh-llm -- -D warnings
mapfile -t clippy_crates < <(bash scripts/plan-clippy-batches.sh --all --bins 1 | jq -r '.[].crates[]')
for crate in "${clippy_crates[@]}"; do
echo "--- $crate ---"
just with-lld cargo clippy -p "$crate" --all-targets -- -D warnings
done
echo ""
echo "=== 4/8 Rust tests ==="
echo "--- mesh-llm-host-runtime lib ---"
Expand Down
8 changes: 4 additions & 4 deletions crates/llama-spec-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,10 @@ fn prompt_cases(args: &Args) -> Result<Vec<PromptCase>> {
.is_file()
.then(|| PathBuf::from(DEFAULT_CORPUS))
});
if prompts.is_empty() {
if let Some(path) = corpus.as_ref() {
prompts.extend(read_prompt_corpus(path)?);
}
if prompts.is_empty()
&& let Some(path) = corpus.as_ref()
{
prompts.extend(read_prompt_corpus(path)?);
}
if prompts.is_empty() {
prompts.push(PromptCase {
Expand Down
22 changes: 11 additions & 11 deletions crates/mesh-client/src/network/http_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,10 @@ fn translate_responses_content_item(item: &serde_json::Value) -> Result<serde_js
}

fn collapse_blocks_if_text_only(blocks: Vec<serde_json::Value>) -> serde_json::Value {
if blocks.len() == 1 {
if let Some(text) = blocks[0].get("text").and_then(|value| value.as_str()) {
return serde_json::Value::String(text.to_string());
}
if blocks.len() == 1
&& let Some(text) = blocks[0].get("text").and_then(|value| value.as_str())
{
return serde_json::Value::String(text.to_string());
}
serde_json::Value::Array(blocks)
}
Expand Down Expand Up @@ -632,13 +632,13 @@ fn translate_openai_responses_input(
let mut messages = Vec::new();

if let Some(instructions_value) = object.remove("instructions") {
if let Some(instructions) = instructions_value.as_str().map(str::trim) {
if !instructions.is_empty() {
messages.push(serde_json::json!({
"role": "system",
"content": instructions,
}));
}
if let Some(instructions) = instructions_value.as_str().map(str::trim)
&& !instructions.is_empty()
{
messages.push(serde_json::json!({
"role": "system",
"content": instructions,
}));
}
changed = true;
}
Expand Down
16 changes: 8 additions & 8 deletions crates/mesh-client/src/network/nostr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ pub async fn discover(
.and_then(|t| t.as_slice().get(1))
.and_then(|s| s.parse::<u64>().ok());

if let Some(exp) = expires_at {
if exp < now {
continue;
}
if let Some(exp) = expires_at
&& exp < now
{
continue;
}

let listing: MeshListing = match serde_json::from_str(&event.content) {
Expand Down Expand Up @@ -316,10 +316,10 @@ pub fn score_mesh(mesh: &DiscoveredMesh, _now_secs: u64, last_mesh_id: Option<&s
}
}

if let (Some(last_id), Some(mesh_id)) = (last_mesh_id, &mesh.listing.mesh_id) {
if last_id == mesh_id {
score += 500;
}
if let (Some(last_id), Some(mesh_id)) = (last_mesh_id, &mesh.listing.mesh_id)
&& last_id == mesh_id
{
score += 500;
}

if mesh.listing.max_clients > 0 {
Expand Down
38 changes: 19 additions & 19 deletions crates/mesh-client/src/network/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,28 @@ pub async fn relay_with_rewrite(
.to_string();

// Parse port from endpoint string like "127.0.0.1:49502"
if let Some(port_str) = endpoint_str.rsplit(':').next() {
if let Ok(remote_port) = port_str.parse::<u16>() {
let map = port_map.read().await;
if let Some(&local_port) = map.get(&remote_port) {
// Rewrite endpoint field
let new_endpoint = format!("127.0.0.1:{local_port}");
let mut new_endpoint_bytes = [0u8; 128];
let copy_len = new_endpoint.len().min(127);
new_endpoint_bytes[..copy_len]
.copy_from_slice(&new_endpoint.as_bytes()[..copy_len]);
payload[4..132].copy_from_slice(&new_endpoint_bytes);
if let Some(port_str) = endpoint_str.rsplit(':').next()
&& let Ok(remote_port) = port_str.parse::<u16>()
{
let map = port_map.read().await;
if let Some(&local_port) = map.get(&remote_port) {
// Rewrite endpoint field
let new_endpoint = format!("127.0.0.1:{local_port}");
let mut new_endpoint_bytes = [0u8; 128];
let copy_len = new_endpoint.len().min(127);
new_endpoint_bytes[..copy_len]
.copy_from_slice(&new_endpoint.as_bytes()[..copy_len]);
payload[4..132].copy_from_slice(&new_endpoint_bytes);

tracing::info!(
"Rewrote REGISTER_PEER: peer_id={peer_id} \
tracing::info!(
"Rewrote REGISTER_PEER: peer_id={peer_id} \
{endpoint_str} → 127.0.0.1:{local_port}"
);
} else {
tracing::warn!(
"REGISTER_PEER: no rewrite mapping for port {remote_port} \
);
} else {
tracing::warn!(
"REGISTER_PEER: no rewrite mapping for port {remote_port} \
(peer_id={peer_id}, endpoint={endpoint_str}), passing through"
);
}
);
}
}

Expand Down
16 changes: 7 additions & 9 deletions crates/mesh-client/src/network/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,13 @@ pub fn classify(body: &Value) -> Classification {
let mut system_code = false;
if let Some(messages) = body.get("messages").and_then(|m| m.as_array()) {
for msg in messages {
if msg.get("role").and_then(|r| r.as_str()) == Some("system") {
if let Some(content) = msg.get("content").and_then(|c| c.as_str()) {
let sys = content.to_lowercase();
if sys.contains("developer")
|| sys.contains("coding")
|| sys.contains("programmer")
{
system_code = true;
}
if msg.get("role").and_then(|r| r.as_str()) == Some("system")
&& let Some(content) = msg.get("content").and_then(|c| c.as_str())
{
let sys = content.to_lowercase();
if sys.contains("developer") || sys.contains("coding") || sys.contains("programmer")
{
system_code = true;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/mesh-llm-gpu-bench/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
fn main() {
println!("cargo:rerun-if-env-changed=MESH_LLM_GPU_BENCH_RUST_ONLY");
if std::env::var_os("MESH_LLM_GPU_BENCH_RUST_ONLY").is_some() {
return;
}

if target_os_is("macos") {
build_metal();
}
Expand Down
2 changes: 1 addition & 1 deletion crates/mesh-llm-gpu-bench/src/cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{BenchmarkOutput, capture::capture_stdout, parse_benchmark_output};
use anyhow::{Context, Result};
use std::ffi::c_int;

extern "C" {
unsafe extern "C" {
fn mesh_llm_gpu_bench_cuda_main() -> c_int;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/mesh-llm-gpu-bench/src/hip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{BenchmarkOutput, capture::capture_stdout, parse_benchmark_output};
use anyhow::{Context, Result};
use std::ffi::c_int;

extern "C" {
unsafe extern "C" {
fn mesh_llm_gpu_bench_hip_main() -> c_int;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/mesh-llm-gpu-bench/src/intel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{BenchmarkOutput, capture::capture_stdout, parse_benchmark_output};
use anyhow::{Context, Result};
use std::ffi::c_int;

extern "C" {
unsafe extern "C" {
fn mesh_llm_gpu_bench_intel_main() -> c_int;
}

Expand Down
19 changes: 13 additions & 6 deletions crates/mesh-llm-gpu-bench/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use crate::BenchmarkOutput;
use anyhow::{Result, anyhow};
use anyhow::Result;
#[cfg(any(
not(target_os = "macos"),
not(feature = "cuda"),
not(feature = "hip"),
not(feature = "intel")
))]
use anyhow::anyhow;
use std::time::Duration;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -74,11 +81,11 @@ pub fn parse_benchmark_output(stdout: &[u8]) -> Option<Vec<BenchmarkOutput>> {
None
}
Err(err) => {
if let Ok(val) = serde_json::from_slice::<serde_json::Value>(stdout) {
if let Some(msg) = val.get("error").and_then(|v| v.as_str()) {
tracing::warn!("benchmark reported error: {msg}");
return None;
}
if let Ok(val) = serde_json::from_slice::<serde_json::Value>(stdout)
&& let Some(msg) = val.get("error").and_then(|v| v.as_str())
{
tracing::warn!("benchmark reported error: {msg}");
return None;
}
tracing::warn!("failed to parse benchmark output: {err}");
None
Expand Down
11 changes: 5 additions & 6 deletions crates/mesh-llm-guardrails/src/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,12 @@ fn is_tool_result_message(message: &Value) -> bool {
fn strip_reasoning_fields(messages: &mut [Value]) -> usize {
let mut dropped = 0;
for message in messages {
if let Some(object) = message.as_object_mut() {
if object.remove("reasoning_content").is_some()
if let Some(object) = message.as_object_mut()
&& (object.remove("reasoning_content").is_some()
|| object.remove("reasoning").is_some()
|| object.remove("thinking").is_some()
{
dropped += 1;
}
|| object.remove("thinking").is_some())
{
dropped += 1;
}
}
dropped
Expand Down
8 changes: 4 additions & 4 deletions crates/mesh-llm-guardrails/src/structured.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ fn validate_object_schema(object: &Map<String, Value>) -> Result<(), Unsupported
}
}
}
if let Some(additional_properties) = object.get("additionalProperties") {
if !additional_properties.is_boolean() {
return Err(UnsupportedStructuredSchema);
}
if let Some(additional_properties) = object.get("additionalProperties")
&& !additional_properties.is_boolean()
{
return Err(UnsupportedStructuredSchema);
}
if let Some(properties) = properties {
for schema in properties.values() {
Expand Down
8 changes: 4 additions & 4 deletions crates/mesh-llm-guardrails/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ pub fn model_param_size_b(name: &str) -> Option<f32> {
if unit != b'b' && unit != b'B' {
continue;
}
if let Some(&after) = bytes.get(end + 1) {
if after.is_ascii_digit() {
continue;
}
if let Some(&after) = bytes.get(end + 1)
&& after.is_ascii_digit()
{
continue;
}

let number = std::str::from_utf8(&bytes[i..end])
Expand Down
12 changes: 6 additions & 6 deletions crates/mesh-llm-host-runtime/src/cli/commands/blackboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ pub(crate) async fn run_blackboard(
.get(format!("{base}/api/blackboard/feed?limit=1"))
.send()
.await;
if let Ok(resp) = feed_check {
if resp.status().as_u16() == 404 {
eprintln!("Mesh is running but blackboard is disabled on that node.");
eprintln!("Re-enable it in the mesh config if you want to use the blackboard plugin.");
std::process::exit(1);
}
if let Ok(resp) = feed_check
&& resp.status().as_u16() == 404
{
eprintln!("Mesh is running but blackboard is disabled on that node.");
eprintln!("Re-enable it in the mesh config if you want to use the blackboard plugin.");
std::process::exit(1);
}

let default_hours = 24.0;
Expand Down
40 changes: 20 additions & 20 deletions crates/mesh-llm-host-runtime/src/cli/commands/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,14 @@ async fn fetch_model_context_lengths(
) -> std::collections::HashMap<String, Option<u32>> {
let mut context_map = std::collections::HashMap::new();

if let Ok(resp) = client.get(management_models_url).send().await {
if let Ok(body) = resp.json::<serde_json::Value>().await {
for model in body["mesh_models"].as_array().unwrap_or(&vec![]) {
let name = model["name"].as_str().map(String::from);
let ctx_len = model["context_length"].as_u64().map(|v| v as u32);
if let Some(n) = name {
context_map.insert(n, ctx_len);
}
if let Ok(resp) = client.get(management_models_url).send().await
&& let Ok(body) = resp.json::<serde_json::Value>().await
{
for model in body["mesh_models"].as_array().unwrap_or(&vec![]) {
let name = model["name"].as_str().map(String::from);
let ctx_len = model["context_length"].as_u64().map(|v| v as u32);
if let Some(n) = name {
context_map.insert(n, ctx_len);
}
}
}
Expand Down Expand Up @@ -774,18 +774,18 @@ async fn write_opencode_config_to_path(

// Merge schema if needed (for display in ordered format)
let mut merged_config = existing_config.clone();
if merged_config.get("$schema").is_none() {
if let Some(schema) = config_value.get("$schema") {
merged_config
.as_object_mut()
.ok_or_else(|| {
anyhow::anyhow!(
"Expected {} to contain a JSON object",
config_path.display()
)
})?
.insert("$schema".to_string(), schema.clone());
}
if merged_config.get("$schema").is_none()
&& let Some(schema) = config_value.get("$schema")
{
merged_config
.as_object_mut()
.ok_or_else(|| {
anyhow::anyhow!(
"Expected {} to contain a JSON object",
config_path.display()
)
})?
.insert("$schema".to_string(), schema.clone());
}

merge_mesh_provider(&mut merged_config, mesh_provider.clone(), config_path)?;
Expand Down
Loading
Loading