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
33 changes: 15 additions & 18 deletions crates/aiwar-ingest/src/encounter_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ pub fn confidence_for_file(filename: &str) -> f64 {
fn version_for_file(filename: &str) -> u32 {
// Check for explicit version numbers v31..v99
let re = Regex::new(r"v(\d{2,})").expect("valid regex");
if let Some(caps) = re.captures(filename) {
if let Ok(v) = caps[1].parse::<u32>() {
return v;
}
if let Some(caps) = re.captures(filename)
&& let Ok(v) = caps[1].parse::<u32>()
{
return v;
}
if filename.contains("aiwar_full") {
0
Expand Down Expand Up @@ -273,10 +273,7 @@ pub fn load_encounter_rounds(cypher_dir: &Path) -> Result<Vec<EncounterRound>, s
let confidence = confidence_for_file(&filename);
let (nodes, edges) = parse_cypher(&text);

let name = filename
.trim_end_matches(".cypher")
.replace('_', " ")
.to_string();
let name = filename.trim_end_matches(".cypher").replace('_', " ");

rounds.push(EncounterRound {
version,
Expand Down Expand Up @@ -358,8 +355,8 @@ mod tests {
assert_eq!(edges.len(), 0);
assert_eq!(nodes[0].id, "Maven");
assert_eq!(nodes[0].labels, vec!["System"]);
assert_eq!(nodes[0].properties.get("name").unwrap(), "Project Maven");
assert_eq!(nodes[0].properties.get("year").unwrap(), "2017");
assert_eq!(&nodes[0].properties["name"], "Project Maven");
assert_eq!(&nodes[0].properties["year"], "2017");
}

#[test]
Expand All @@ -383,7 +380,7 @@ mod tests {
assert_eq!(edges[0].source, "A");
assert_eq!(edges[0].target, "B");
assert_eq!(edges[0].rel_type, "DEVELOPED_BY");
assert_eq!(edges[0].properties.get("weight").unwrap(), "3");
assert_eq!(&edges[0].properties["weight"], "3");
// both endpoints were also declared as nodes
assert_eq!(nodes.len(), 2);
}
Expand Down Expand Up @@ -442,25 +439,25 @@ mod tests {
assert_eq!(full_edges[0].target, "Hegseth");
assert_eq!(full_edges[0].rel_type, "PERSON_LINK");
assert_eq!(
full_edges[0].properties.get("label").unwrap(),
&full_edges[0].properties["label"],
"appointed SecDef"
);
}

#[test]
fn test_parse_property_block() {
let props = parse_property_block("id: 'test', name: 'Hello World', weight: 42");
assert_eq!(props.get("id").unwrap(), "test");
assert_eq!(props.get("name").unwrap(), "Hello World");
assert_eq!(props.get("weight").unwrap(), "42");
assert_eq!(&props["id"], "test");
assert_eq!(&props["name"], "Hello World");
assert_eq!(&props["weight"], "42");
}

#[test]
fn test_parse_set_clause() {
let props = parse_set_clause("r.label='test edge', r.weight=5, r.source='Reuters'");
assert_eq!(props.get("label").unwrap(), "test edge");
assert_eq!(props.get("weight").unwrap(), "5");
assert_eq!(props.get("source").unwrap(), "Reuters");
assert_eq!(&props["label"], "test edge");
assert_eq!(&props["weight"], "5");
assert_eq!(&props["source"], "Reuters");
}

#[test]
Expand Down
28 changes: 14 additions & 14 deletions crates/aiwar-ingest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,17 @@ pub fn load_with_enrichment(
cypher_dir: &Path,
) -> Result<AiWarGraph, IngestError> {
let mut graph = load_from_file(graph_json_path)?;
if cypher_dir.is_dir() {
if let Ok(rounds) = encounter_round::load_encounter_rounds(cypher_dir) {
for round in &rounds {
graph.apply_round(round);
}
tracing::info!(
"aiwar-ingest: applied {} enrichment rounds from {}",
rounds.len(),
cypher_dir.display()
);
if cypher_dir.is_dir()
&& let Ok(rounds) = encounter_round::load_encounter_rounds(cypher_dir)
{
for round in &rounds {
graph.apply_round(round);
}
tracing::info!(
"aiwar-ingest: applied {} enrichment rounds from {}",
rounds.len(),
cypher_dir.display()
);
}
tracing::info!(
"aiwar-ingest: loaded {} nodes, {} edges",
Expand Down Expand Up @@ -406,11 +406,11 @@ mod tests {
assert_eq!(maven.label, "Project Maven");
// non id/name fields preserved verbatim
assert_eq!(
maven.properties.get("year").unwrap(),
&maven.properties["year"],
&serde_json::json!(2017)
);
assert_eq!(
maven.properties.get("MLTask").unwrap(),
&maven.properties["MLTask"],
&serde_json::json!("object-detection")
);

Expand All @@ -433,7 +433,7 @@ mod tests {
assert_eq!(dev.target, "Palantir");
assert_eq!(dev.weight, 3.0);
assert_eq!(
dev.properties.get("label").unwrap(),
&dev.properties["label"],
&serde_json::json!("builds")
);

Expand Down Expand Up @@ -553,6 +553,6 @@ mod tests {
assert_eq!(g.node_count(), 4);
let maven = g.nodes.iter().find(|n| n.id == "Maven").unwrap();
// a real number is preserved verbatim (sanitizer only touches non-finite).
assert_eq!(maven.properties.get("year").unwrap(), &serde_json::json!(2017));
assert_eq!(&maven.properties["year"], &serde_json::json!(2017));
}
}
33 changes: 16 additions & 17 deletions crates/cockpit-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::sync::Arc;
use std::time::Duration;

use axum::extract::State;
use axum::http::{StatusCode, header};
use axum::http::StatusCode;
use axum::response::sse::{Event, Sse};
use axum::response::{Html, IntoResponse, Response};
use axum::routing::{get, post};
Expand Down Expand Up @@ -1015,7 +1015,7 @@ async fn style_handler(
async fn strategy_check_handler() -> Json<serde_json::Value> {
// Run in a blocking thread since strategy checks may be CPU-intensive
let result =
tokio::task::spawn_blocking(|| notebook_query::diagnostics::run_strategy_checks()).await;
tokio::task::spawn_blocking(notebook_query::diagnostics::run_strategy_checks).await;

match result {
Ok(matrix) => Json(serde_json::to_value(matrix).unwrap_or_default()),
Expand Down Expand Up @@ -1345,19 +1345,18 @@ async fn orchestrator_step_handler(
let mut orch = get_orchestrator().lock().unwrap();

// If quality is provided, record the outcome of the previous step.
if let Some(Json(body)) = body {
if let Some(quality) = body.get("quality").and_then(|v| v.as_f64()) {
if let Some(style_name) = body.get("style").and_then(|v| v.as_str()) {
let style = match style_name {
"plan" => notebook_query::orchestrator::AgentStyle::Plan,
"act" => notebook_query::orchestrator::AgentStyle::Act,
"explore" => notebook_query::orchestrator::AgentStyle::Explore,
"reflex" => notebook_query::orchestrator::AgentStyle::Reflex,
_ => notebook_query::orchestrator::AgentStyle::Plan,
};
orch.record_outcome(style, quality as f32);
}
}
if let Some(Json(body)) = body
&& let Some(quality) = body.get("quality").and_then(|v| v.as_f64())
&& let Some(style_name) = body.get("style").and_then(|v| v.as_str())
{
let style = match style_name {
"plan" => notebook_query::orchestrator::AgentStyle::Plan,
"act" => notebook_query::orchestrator::AgentStyle::Act,
"explore" => notebook_query::orchestrator::AgentStyle::Explore,
"reflex" => notebook_query::orchestrator::AgentStyle::Reflex,
_ => notebook_query::orchestrator::AgentStyle::Plan,
};
orch.record_outcome(style, quality as f32);
}

let result = orch.select_next();
Expand Down Expand Up @@ -1414,7 +1413,7 @@ async fn analyst_analyze_handler(

/// Run all 6 analysis buckets.
async fn analyst_full_handler() -> Json<serde_json::Value> {
let result = tokio::task::spawn_blocking(|| notebook_query::analyst::full_analysis()).await;
let result = tokio::task::spawn_blocking(notebook_query::analyst::full_analysis).await;

match result {
Ok(analyses) => Json(serde_json::to_value(analyses).unwrap_or_default()),
Expand Down Expand Up @@ -1465,7 +1464,7 @@ async fn data_status_handler() -> Json<serde_json::Value> {
.map(|entries| {
entries
.filter_map(|e| e.ok())
.filter(|e| e.path().extension().map_or(false, |ext| ext == "cypher"))
.filter(|e| e.path().extension().is_some_and(|ext| ext == "cypher"))
.count()
})
.unwrap_or(0);
Expand Down
6 changes: 3 additions & 3 deletions crates/cockpit-server/src/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ async fn create_chat_completion(
.iter()
.filter(|m| m.role == "user")
.filter_map(|m| m.content.as_deref())
.last()
.next_back()
.unwrap_or("");

Json(ChatCompletionResp {
Expand Down Expand Up @@ -417,7 +417,7 @@ async fn create_chat_completion(
}

async fn create_embedding(
State(state): State<SharedOpenAiState>,
State(_state): State<SharedOpenAiState>,
Json(req): Json<EmbeddingReq>,
) -> Json<EmbeddingResp> {
let model = req.model.unwrap_or_else(|| "gpt2".into());
Expand All @@ -441,7 +441,7 @@ async fn create_embedding(
}

async fn create_image(
State(state): State<SharedOpenAiState>,
State(_state): State<SharedOpenAiState>,
Json(req): Json<ImageGenReq>,
) -> Json<ImageGenResp> {
let n = req.n.unwrap_or(1);
Expand Down
28 changes: 14 additions & 14 deletions crates/cockpit-server/src/osint_gotham.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,11 @@ fn theme_stem(source_file: &str) -> String {
s = t.to_string();
continue;
}
if let Some((head, tail)) = s.rsplit_once('_') {
if is_version_token(tail) {
s = head.to_string();
continue;
}
if let Some((head, tail)) = s.rsplit_once('_')
&& is_version_token(tail)
{
s = head.to_string();
continue;
}
break;
}
Expand Down Expand Up @@ -1125,10 +1125,10 @@ pub fn osint_soa_bytes(graph: &AiWarGraph, rounds: &[EncounterRound]) -> Vec<u8>
// — no synthetic hub, no self-loop on the anchor itself.
for (i, r) in rows.iter().enumerate() {
let basin = (r.key.family_v2() & 0xFF) as u8;
if let Some(&a) = anchor_idx.get(&basin) {
if a != i {
push_edge(&mut edges, i, a, rel_code("member-of"));
}
if let Some(&a) = anchor_idx.get(&basin)
&& a != i
{
push_edge(&mut edges, i, a, rel_code("member-of"));
}
let ifaces: std::collections::BTreeSet<u8> = r
.edges
Expand All @@ -1139,10 +1139,10 @@ pub fn osint_soa_bytes(graph: &AiWarGraph, rounds: &[EncounterRound]) -> Vec<u8>
.filter(|&b| b != 0 && b != basin)
.collect();
for b in ifaces {
if let Some(&a) = anchor_idx.get(&b) {
if a != i {
push_edge(&mut edges, i, a, rel_code("interfaces"));
}
if let Some(&a) = anchor_idx.get(&b)
&& a != i
{
push_edge(&mut edges, i, a, rel_code("interfaces"));
}
}
}
Expand All @@ -1154,7 +1154,7 @@ pub fn osint_soa_bytes(graph: &AiWarGraph, rounds: &[EncounterRound]) -> Vec<u8>
// foveal view can show "Fortify", not just a class. Old readers stop after
// `edges`; new readers consume this tail.
let mut labels: Vec<u8> = Vec::new();
let mut push_label = |buf: &mut Vec<u8>, s: &str| {
let push_label = |buf: &mut Vec<u8>, s: &str| {
let b = s.as_bytes();
let l = b.len().min(255);
buf.push(l as u8);
Expand Down
24 changes: 12 additions & 12 deletions crates/cockpit-server/src/osm_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,11 @@ fn feature_ordinals(bytes: &[u8], idx: usize) -> (Vec<u32>, Vec<u32>, Vec<u32>)
let mut key_ordinals = Vec::new();
let mut value_ordinals = Vec::new();
for (_slot, facet) in osm_soa_bake::cluster::facets(row) {
if let osm_soa_bake::cluster::Facet::Tag { member, key, value } = facet {
if member == ordinal {
key_ordinals.push(key);
value_ordinals.push(value);
}
if let osm_soa_bake::cluster::Facet::Tag { member, key, value } = facet
&& member == ordinal
{
key_ordinals.push(key);
value_ordinals.push(value);
}
}
(vec![ordinal], key_ordinals, value_ordinals)
Expand Down Expand Up @@ -1647,11 +1647,11 @@ async fn tile_sources<'a>(
};
ordinals.push(ordinal);
for (_slot, facet) in osm_soa_bake::cluster::facets(&rows[i]) {
if let osm_soa_bake::cluster::Facet::Tag { member, key, value } = facet {
if member == ordinal {
key_ordinals.push(key);
value_ordinals.push(value);
}
if let osm_soa_bake::cluster::Facet::Tag { member, key, value } = facet
&& member == ordinal
{
key_ordinals.push(key);
value_ordinals.push(value);
}
}
}
Expand Down Expand Up @@ -1938,7 +1938,7 @@ mod tests {
let books_path = dir.path().join("region.books");
{
use lance_graph_contract::identity_quad::IdentityCodebook;
use osm_soa_bake::codebook::{Books, Header};
use osm_soa_bake::codebook::Books;
let books = Books {
identities: IdentityCodebook::try_new(vec!["node/1".into()]).unwrap(),
tag_keys: IdentityCodebook::try_new(vec!["highway".into()]).unwrap(),
Expand Down Expand Up @@ -2465,7 +2465,7 @@ mod tests {
///
/// What went wrong, recorded so it is not repeated: the first fix replaced
/// head-truncation with stride sampling and asserted the result covered
/// >=95% of the tile's EXTENT. That assertion is unfalsifiable for this
/// \>=95% of the tile's EXTENT. That assertion is unfalsifiable for this
/// defect. A uniform stride covers ~100% of a bounding box at ANY stride —
/// measured on this very fixture shape, the >=0.95 assertion passes while
/// keeping 25% of rows, and still passes while keeping 5.9%. It certified
Expand Down
18 changes: 9 additions & 9 deletions crates/cockpit-server/src/osm_lance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ pub async fn ensure_lance_local(slab_path: &Path) -> Option<PathBuf> {
// the stale directory cannot be removed, do NOT write into it (that
// is exactly how a 4-file `data/` happens) — keep serving from the
// `.soa` unchanged.
if dest.exists() {
if let Err(e) = remove_stale_dataset(&dest) {
tracing::error!(
path = %dest.display(), error = %e,
"osm lance: cannot remove the stale dataset; refusing to write \
into it — the raw .soa slab keeps serving the map"
);
return None;
}
if dest.exists()
&& let Err(e) = remove_stale_dataset(&dest)
{
tracing::error!(
path = %dest.display(), error = %e,
"osm lance: cannot remove the stale dataset; refusing to write \
into it — the raw .soa slab keeps serving the map"
);
return None;
}

tracing::info!(
Expand Down
4 changes: 1 addition & 3 deletions crates/cockpit-server/src/osm_slab_hydrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ pub async fn ensure_slab_local() -> Option<PathBuf> {

crate::osm_region_catalogue::publish(catalogue, active);

let Some(slab) = active_path else {
return None;
};
let slab = active_path?;
tracing::info!(path = %slab.display(), "osm slab: hydrated and verified");
Some(slab)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cockpit-server/src/osm_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ mod tests {
// Asserting `== y` directly would fail; asserting the *raw* recovered
// value equals some constant would pass against a key that mirrors the
// world about the equator. Neither is what we want to pin.
let (z, x, y) = (HHTL_DEPTH, 0x00AB_12u32, 0x00CD_34u32);
let (z, x, y) = (HHTL_DEPTH, 0x0000_AB12_u32, 0x0000_CD34_u32);
let h = tile_to_hhtl(z, x, y);
let code = (u64::from(h.heel) << 48)
| (u64::from(h.hip) << 32)
Expand Down
2 changes: 1 addition & 1 deletion crates/cockpit-server/src/shader_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use serde::Serialize;
use tokio::sync::RwLock;

use lance_graph_contract::cognitive_shader::{
CognitiveShaderDriver, ShaderBus, ShaderCrystal, ShaderDispatch, ShaderResonance, ShaderSink,
CognitiveShaderDriver, ShaderBus, ShaderCrystal, ShaderResonance, ShaderSink,
};
use lance_graph_contract::cycle_accumulator::{AccumulatorAction, CycleAccumulator};

Expand Down
Loading