← Commit history
AI Flow 0.2.92: solidAt on repeated pads, silk-only place verify, background capture open (#220 #221 #222)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
9 files changed
+197−19
Cargo.lock+10−10@@ -4,7 +4,7 @@ version = 4 [[package]] name = "adom-aiflow"-version = "0.2.91"+version = "0.2.92" dependencies = [ "aiflow-analyze", "aiflow-board",@@ -25,7 +25,7 @@ dependencies = [ [[package]] name = "aiflow-analyze"-version = "0.2.91"+version = "0.2.92" dependencies = [ "aiflow-board", "serde",@@ -35,7 +35,7 @@ dependencies = [ [[package]] name = "aiflow-board"-version = "0.2.91"+version = "0.2.92" dependencies = [ "roxmltree", "serde",@@ -44,7 +44,7 @@ dependencies = [ [[package]] name = "aiflow-bridge"-version = "0.2.91"+version = "0.2.92" dependencies = [ "aiflow-board", "serde",@@ -53,7 +53,7 @@ dependencies = [ [[package]] name = "aiflow-copper"-version = "0.2.91"+version = "0.2.92" dependencies = [ "aiflow-board", "aiflow-grid",@@ -63,7 +63,7 @@ dependencies = [ [[package]] name = "aiflow-grid"-version = "0.2.91"+version = "0.2.92" dependencies = [ "aiflow-board", "serde",@@ -72,7 +72,7 @@ dependencies = [ [[package]] name = "aiflow-place"-version = "0.2.91"+version = "0.2.92" dependencies = [ "aiflow-board", "serde",@@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "aiflow-pours"-version = "0.2.91"+version = "0.2.92" dependencies = [ "aiflow-board", "aiflow-copper",@@ -91,7 +91,7 @@ dependencies = [ [[package]] name = "aiflow-router"-version = "0.2.91"+version = "0.2.92" dependencies = [ "aiflow-board", "aiflow-grid",@@ -101,7 +101,7 @@ dependencies = [ [[package]] name = "aiflow-run"-version = "0.2.91"+version = "0.2.92" dependencies = [ "serde", "serde_json",
Cargo.toml+1−1@@ -14,7 +14,7 @@ members = [ ] [workspace.package]-version = "0.2.91"+version = "0.2.92" edition = "2021" license = "MIT" repository = "https://wiki.adom.inc/adom/adom-aiflow"
bin/adom-aiflow⋯ 1 unchanged line ⋯
crates/adom-aiflow/src/placement_verify.rs+23−1@@ -129,7 +129,12 @@ pub fn check_with_spec(board: &Board, before: &Value, validation: &Value, after: if validation["success"]!=true || validation["source"]!="live-editor" || validation["stale"]!=false || validation["revision"]!=revision || validation["currentRevision"]!=revision { return Err("native placement validation failed or changed revision".into()); }- let native_clear = drc["placementClean"]==true && drc["placementViolationCount"].as_u64()==Some(0) && drc["errors"].as_u64()==Some(0);+ // issue #221 (Sven Claar): silkscreen findings are advisories here as in gate and finish (silk_policy, issue #92):+ // a complete report whose only violations are silkscreen ones is clear unless the board makes silk blocking+ let silk_only = drc["errors"].as_u64()==Some(0) && drc["violationReportMayBeTruncated"]==false+ && drc["placementViolations"].as_array().is_some_and(|v| !v.is_empty() && Some(v.len() as u64)==drc["placementViolationCount"].as_u64() && v.iter().all(aiflow_copper::is_silk))+ && !crate::silk_policy::blocking(spec, &board.path);+ let native_clear = (drc["placementClean"]==true && drc["placementViolationCount"].as_u64()==Some(0) && drc["errors"].as_u64()==Some(0)) || silk_only; let reviewed_contacts_only = crate::assembly_contacts::native_contacts_only(&contacts, drc, spec, revision, remote); if drc["available"]!=true || drc["source"]!="live-editor-snapshot" || (!native_clear && !reviewed_contacts_only) || drc["violationReportMayBeTruncated"]!=false { return Err("complete native placement DRC is required".into());@@ -228,6 +233,23 @@ mod tests { let mut bad=v.clone();bad["drc"][key]=value;assert!(check(&b,&s,&bad,&s,"board").is_err()); } }+ /// Issue #221: silkscreen warnings alone are advisories, as in gate and finish; fab.silkBlocking makes them count.+ #[test]+ fn silkscreen_warnings_alone_do_not_fail_place_verify() {+ let (b,s,v)=fixture();+ let mut silk=v.clone();+ silk["drc"]["placementClean"]=json!(false);+ silk["drc"]["placementViolationCount"]=json!(2);+ silk["drc"]["placementViolations"]=json!([{"type":"silk_edge_clearance","severity":"warning"},{"type":"silk_overlap","severity":"warning"}]);+ assert_eq!(check(&b,&s,&silk,&s,"board").unwrap(),1);+ assert!(check_with_spec(&b,&s,&silk,&s,"board",&json!({"fab":{"silkBlocking":true}})).is_err(), "silkBlocking makes silk count");+ let mut mixed=silk.clone();+ mixed["drc"]["placementViolations"]=json!([{"type":"silk_edge_clearance","severity":"warning"},{"type":"courtyards_overlap","severity":"error"}]);+ mixed["drc"]["errors"]=json!(1);+ assert!(check(&b,&s,&mixed,&s,"board").is_err(), "a real placement error still fails");+ let mut partial=silk.clone();partial["drc"]["placementViolationCount"]=json!(3);+ assert!(check(&b,&s,&partial,&s,"board").is_err(), "a list shorter than the count is not complete");+ } #[test] fn bounded_edge_connector_keeps_copper_and_native_gates() { let (_,mut state,mut native)=fixture();
crates/aiflow-bridge/src/lib.rs+82−2@@ -500,11 +500,38 @@ impl Bridge { /// `raise` (screen `allowed`, a test box): in front, maximised. Otherwise (issues #132, #135) the /// board opens without focus or maximise, and a KiCad window Windows put in front anyway (a newly /// launched process gets the foreground) goes to the bottom, the human's window back in front.+ /// Issue #222 (Sven Claar): the PCB editor window already showing this board, from KiCad's own editor list+ /// (`kicad_status`), else the desktop's window list. A board opened in the background is found this way, and+ /// a retry reuses the window instead of starting a second pcbnew that finds the board locked.+ pub fn board_window(&self, remote_board: &str) -> Option<i64> {+ board_window_in(&self.raw_call("kicad_status", &json!({})), &self.raw_call("desktop_list_windows", &json!({})), &board_stem(remote_board))+ }++ /// After `kicad_open_board` answered without a window handle (a background open says so in+ /// `_foregroundHint`), the board's window as it appears, polled for up to a minute.+ fn wait_board_window(&self, remote_board: &str, reply: &Value) -> Option<i64> {+ if !opened_without_handle(reply) { return None; }+ for _ in 0..20 {+ if let Some(h) = self.board_window(remote_board) { return Some(h); }+ std::thread::sleep(std::time::Duration::from_secs(3));+ }+ None+ }+ pub fn open_board(&self, remote_board: &str, reason: &str, raise: bool) -> Result<(i64, String), Value> {+ // issue #222: a board already open (an earlier try, a background open) is reused: never a second pcbnew+ if let Some(hwnd) = self.board_window(remote_board) {+ if raise {+ self.call("desktop_ui_window", &json!({"hwnd": hwnd, "action": "maximize", "reason": "aiflow capture: fill the monitor"}));+ self.call("desktop_bring_to_front", &json!({"hwnd": hwnd, "reason": "aiflow capture: keep the PCB editor on screen on the test box"}));+ }+ self.call("kicad_send_key", &json!({"hwnd": hwnd, "menu": "Zoom to Fit"}));+ return Ok((hwnd, format!("already open in KiCad (window {hwnd}): reused, no second pcbnew started{}", if raise { ", maximised" } else { "" })));+ } if !raise { let before = self.foreground(); let r = self.call("kicad_open_board", &json!({"filePath": remote_board, "foreground": false}));- let Some(hwnd) = r.get("hwnd").and_then(|h| h.as_i64()) else { return Err(r) };+ let Some(hwnd) = r.get("hwnd").and_then(|h| h.as_i64()).or_else(|| self.wait_board_window(remote_board, &r)) else { return Err(r) }; let mut done: Vec<String> = self.keep_behind(hwnd, before.as_ref()).into_iter().collect(); std::thread::sleep(std::time::Duration::from_secs(40)); // KiCad can come forward again when the board finishes loading@@ -515,7 +542,7 @@ impl Bridge { return Ok((hwnd, format!("opened in the background, not maximised (screen hands-off), zoomed to fit; {what}"))); } let r = self.call("kicad_open_board", &json!({"filePath": remote_board, "foreground": true, "foregroundReason": reason}));- let Some(hwnd) = r.get("hwnd").and_then(|h| h.as_i64()) else { return Err(r) };+ let Some(hwnd) = r.get("hwnd").and_then(|h| h.as_i64()).or_else(|| self.wait_board_window(remote_board, &r)) else { return Err(r) }; self.call("desktop_ui_window", &json!({"hwnd": hwnd, "action": "maximize", "reason": "aiflow capture: fill the monitor"})); std::thread::sleep(std::time::Duration::from_secs(40)); self.call("desktop_bring_to_front", &json!({"hwnd": hwnd, "reason": "aiflow capture: keep the PCB editor on screen on the test box"}));@@ -1294,3 +1321,56 @@ mod live_socket_tests { assert_eq!(read_socket_args("kicad_routing_state", &args, Some("r"))["socketPath"], "r"); } }++/// The board's file name without extension, from a desktop path (either slash).+pub fn board_stem(remote_board: &str) -> String {+ let n = remote_board.rsplit(['/', '\\']).next().unwrap_or(remote_board);+ n.rsplit_once('.').map(|(a, _)| a).unwrap_or(n).to_string()+}++/// A `kicad_open_board` reply with no window handle that is not a failure: KiCad opened the board in the+/// background (`_foregroundHint`), or the reply says it succeeded.+pub fn opened_without_handle(reply: &Value) -> bool {+ let d = reply.get("data").unwrap_or(reply);+ reply["success"] != false && (reply["success"] == true || reply.get("_foregroundHint").is_some() || d.get("_foregroundHint").is_some()+ || reply["error"].as_str().is_some_and(|e| e.contains("BACKGROUND")))+}++/// The PCB editor window naming `stem`: KiCad's editor list first (kind pcb), else a desktop window titled+/// "... PCB Editor" or of pcbnew that names the board.+pub fn board_window_in(status: &Value, windows: &Value, stem: &str) -> Option<i64> {+ if stem.is_empty() { return None; }+ let st = status.get("data").unwrap_or(status);+ let from_kicad = st["editors"].as_array().into_iter().flatten().find(|e| e["kind"].as_str().unwrap_or("").to_ascii_lowercase().contains("pcb")+ && crate::eda::names_board(e["title"].as_str().unwrap_or(""), stem)).and_then(|e| e["hwnd"].as_i64());+ if from_kicad.is_some() { return from_kicad; }+ let out = windows.get("output").and_then(|o| o.as_str()).and_then(|t| serde_json::from_str::<Value>(t).ok()).unwrap_or_else(|| windows.clone());+ let list = out["data"]["windows"].as_array().or(out["windows"].as_array()).cloned().unwrap_or_default();+ list.iter().find(|w| {+ let t = w["title"].as_str().unwrap_or("");+ let img = w["image"].as_str().or(w["process"].as_str()).unwrap_or("").to_ascii_lowercase();+ crate::eda::names_board(t, stem) && (t.contains("PCB Editor") || img.contains("pcbnew"))+ }).and_then(|w| w["hwnd"].as_i64()).filter(|h| *h > 0)+}++#[cfg(test)]+mod board_window_tests {+ use super::*;++ /// Issue #222: a board opened in the background is found by its window; a retry reuses it.+ #[test]+ fn the_board_window_is_found_and_a_background_open_is_not_a_failure() {+ assert_eq!(board_stem("C:\\work\\breakout.kicad_pcb"), "breakout");+ assert_eq!(board_stem("C:/work/rev2.board.kicad_pcb"), "rev2.board");+ let status = json!({"data": {"editors": [{"kind": "schematic", "title": "breakout — Schematic Editor", "hwnd": 11}, {"kind": "pcb", "title": "breakout — PCB Editor", "hwnd": 22}]}});+ assert_eq!(board_window_in(&status, &json!({}), "breakout"), Some(22));+ assert_eq!(board_window_in(&status, &json!({}), "breakout-v2"), None, "another board's editor is not this one");+ let wins = json!({"output": "{\"data\":{\"windows\":[{\"hwnd\":5,\"title\":\"notes.txt - Notepad\"},{\"hwnd\":33,\"title\":\"*breakout — PCB Editor\",\"image\":\"pcbnew.exe\"}]}}"});+ assert_eq!(board_window_in(&json!({}), &wins, "breakout"), Some(33));+ assert!(opened_without_handle(&json!({"_foregroundHint": "Window opened in the BACKGROUND (screen hands-off)"})));+ assert!(opened_without_handle(&json!({"success": true})));+ assert!(!opened_without_handle(&json!({"success": false, "error": "file not found"})));+ assert!(!opened_without_handle(&json!({"errorCode": "kicad_not_running"})));+ }+}+
crates/aiflow-pours/src/lib.rs+62−3@@ -329,11 +329,38 @@ pub fn build_with(board: &Board, spec: &Value, plan: Option<&Value>, planned: &[ check_settings(&Value::Object(z.clone())).map_err(|e| format!("pour {net}: {e}"))?; zones.push(Value::Object(z)); }+ // issue #220 (Sven Claar): a key a footprint repeats (a USB-C receptacle's four `SH` shield tabs) means every+ // pad with that key; patches of one net that overlap become one zone (two same-net zones at one priority+ // that overlap are a zones_intersect in KiCad's DRC) for key in strs(spec.get("solidAt")) {- if let Some(p) = board.pad_by_key(&key) {- let layers: Vec<&str> = if p.thru { vec!["F.Cu", "B.Cu"] } else if p.on_f { vec!["F.Cu"] } else { vec!["B.Cu"] };+ let mut patches: Vec<(String, Vec<&'static str>, [f64; 4])> = Vec::new();+ for p in board.pads_with_key(&key) {+ let layers: Vec<&'static str> = if p.thru { vec!["F.Cu", "B.Cu"] } else if p.on_f { vec!["F.Cu"] } else { vec!["B.Cu"] }; let r = if p.thru { p.half_long.max(p.half_short) + 0.6 } else { 0.9 };- zones.push(json!({"net": p.net, "layers": layers, "polygon": rect(p.x - r, p.y - r, p.x + r, p.y + r), "priority": 1, "connection": "solid", "clearance": clearance, "minThickness": 0.25, "name": format!("{} solid joint at {key}", p.net)}));+ patches.push((p.net.clone(), layers, [p.x - r, p.y - r, p.x + r, p.y + r]));+ }+ // merge overlapping patches of the same net until none overlap+ loop {+ let mut merged = false;+ 'outer: for i in 0..patches.len() {+ for j in i + 1..patches.len() {+ let (a, b) = (&patches[i], &patches[j]);+ if a.0 == b.0 && a.2[0] <= b.2[2] && b.2[0] <= a.2[2] && a.2[1] <= b.2[3] && b.2[1] <= a.2[3] {+ let bb = patches.remove(j);+ let a = &mut patches[i];+ a.2 = [a.2[0].min(bb.2[0]), a.2[1].min(bb.2[1]), a.2[2].max(bb.2[2]), a.2[3].max(bb.2[3])];+ for l in bb.1 { if !a.1.contains(&l) { a.1.push(l); } }+ merged = true;+ break 'outer;+ }+ }+ }+ if !merged { break; }+ }+ let n = patches.len();+ for (k, (net, layers, b)) in patches.into_iter().enumerate() {+ let name = if n > 1 { format!("{net} solid joint at {key} ({})", k + 1) } else { format!("{net} solid joint at {key}") };+ zones.push(json!({"net": net, "layers": layers, "polygon": rect(b[0], b[1], b[2], b[3]), "priority": 1, "connection": "solid", "clearance": clearance, "minThickness": 0.25, "name": name})); } } let blockers = plan.map(plan_blockers).unwrap_or_default();@@ -902,4 +929,36 @@ mod issue90_tests { assert!(silk[0].distance((x, y)) >= 0.3 + 0.1 - 1e-6, "via at ({x}, {y}) under the label"); } }++#[cfg(test)]+mod solid_at_tests {+ use super::*;+ use serde_json::json;++ /// Issue #220: `solidAt` on a key a footprint repeats covers every pad with that key; overlapping patches merge.+ #[test]+ fn a_repeated_pad_key_gets_a_solid_patch_on_every_pad() {+ let t = r#"(kicad_pcb (version 20240108) (generator "t")+ (layers (0 "F.Cu" signal) (2 "B.Cu" signal) (25 "Edge.Cuts" user))+ (net 0 "") (net 1 "GND")+ (gr_rect (start 0 0) (end 30 20) (layer "Edge.Cuts") (stroke (width 0.1) (type default)))+ (footprint "USB_C" (layer "F.Cu") (at 15 10) (property "Reference" "J1" (at 0 0) (layer "F.SilkS"))+ (pad "SH" thru_hole oval (at -4.3 -3) (size 1 2) (drill 0.6) (layers "*.Cu") (net 1 "GND"))+ (pad "SH" thru_hole oval (at 4.3 -3) (size 1 2) (drill 0.6) (layers "*.Cu") (net 1 "GND"))+ (pad "SH" thru_hole oval (at -4.3 1) (size 1 2) (drill 0.6) (layers "*.Cu") (net 1 "GND"))+ (pad "SH" thru_hole oval (at -4.3 1.6) (size 1 2) (drill 0.6) (layers "*.Cu") (net 1 "GND"))))"#;+ let b = Board::from_text("t.kicad_pcb", t.to_string()).unwrap();+ let (zones, _, _) = build(&b, &json!({"solidAt": ["J1.SH"]}), None).unwrap();+ let solid: Vec<&Value> = zones.iter().filter(|z| z["connection"] == "solid").collect();+ // four tabs, the two close ones on the left (-4.3, 1) and (-4.3, 1.6) overlap: three patches+ assert_eq!(solid.len(), 3, "{solid:#?}");+ assert!(solid.iter().all(|z| z["net"] == "GND" && z["name"].as_str().unwrap().starts_with("GND solid joint at J1.SH (")), "{solid:#?}");+ let one = Board::from_text("t.kicad_pcb", t.replacen(r#"(pad "SH" thru_hole oval (at 4.3 -3)"#, r#"(pad "X" thru_hole oval (at 4.3 -3)"#, 1).replace(r#"(pad "SH" thru_hole oval (at -4.3 1) (size 1 2) (drill 0.6) (layers "*.Cu") (net 1 "GND"))"#, "").replace(r#"(pad "SH" thru_hole oval (at -4.3 1.6) (size 1 2) (drill 0.6) (layers "*.Cu") (net 1 "GND"))"#, "")).unwrap();+ let (zones, _, _) = build(&one, &json!({"solidAt": ["J1.SH"]}), None).unwrap();+ let solid: Vec<&Value> = zones.iter().filter(|z| z["connection"] == "solid").collect();+ assert_eq!(solid.len(), 1);+ assert_eq!(solid[0]["name"], "GND solid joint at J1.SH", "a single pad keeps its name");+ }+}+ }
docs/release-0.2.92.mdadded+17@@ -0,0 +1,17 @@+# AI Flow 0.2.92++Three fixes from Sven Claar's run.++- **`solidAt` covers every pad with the key** (#220). A key a footprint repeats (a USB-C receptacle's four `SH`+ shield tabs) used to get one solid patch at whichever pad the index held; the others kept thermal spokes and KiCad+ refused the pour (`starved_thermal`). Every pad with the key now gets its patch, and patches of one net that+ overlap become one zone (two overlapping same-net zones at one priority are a `zones_intersect`).+- **`place verify` treats silkscreen warnings as advisories** (#221), as `gate` and `finish` already do: a complete+ placement DRC whose only findings are silkscreen ones (`silk_edge_clearance`, `silk_over_copper`, `silk_overlap`,+ ...) is clear, unless the board makes silk blocking (`fab.silkBlocking`).+- **`capture open` and a board opened in the background** (#222). KiCad's background open answers with no window+ handle, which read as "could not open the board", and a retry started a second pcbnew. AI Flow now finds the+ board's window (KiCad's editor list, else the desktop's windows), and reuses a board that is already open instead of+ launching it again. The KiCad first-run wizard is the KiCad bridge's to handle.++Tests added for each.
package.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow", "type": "app",- "version": "0.2.91",+ "version": "0.2.92", "title": "AI Flow", "description": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. One Rust binary with a crate per step (placement helpers, a grid router with Kelvin taps, pours with keepouts, KiCad's DRC gate, live landing through the KiCad Bridge, copper measurement, current and thermal analysis) and a finish line that refuses an unfinished board. Every command answers with hints for the AI; every turn, its thinking time and every rework loop go into run.jsonl, so Claude, Codex and any other engine are compared on the same flow. KiCad, Fusion 360 and Altium Designer today (the same steps and gates through each tool's bridge); Adom's own web apps next.", "summary": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. The AI thinks its way from placement through routing, pours, current and thermal analysis to a delivered video; the binary does the fast, deterministic parts of every step, hands back hints, and keeps a ledger of every turn, every return to an earlier step, and the clock from the prompt to done.",
page.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow", "type": "app",- "version": "0.2.91",+ "version": "0.2.92", "title": "AI Flow", "description": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. One Rust binary with a crate per step (placement helpers, a grid router with Kelvin taps, pours with keepouts, KiCad's DRC gate, live landing through the KiCad Bridge, copper measurement, current and thermal analysis) and a finish line that refuses an unfinished board. Every command answers with hints for the AI; every turn, its thinking time and every rework loop go into run.jsonl, so Claude, Codex and any other engine are compared on the same flow. KiCad, Fusion 360 and Altium Designer today (the same steps and gates through each tool's bridge); Adom's own web apps next.", "summary": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. The AI thinks its way from placement through routing, pours, current and thermal analysis to a delivered video; the binary does the fast, deterministic parts of every step, hands back hints, and keeps a ledger of every turn, every return to an earlier step, and the clock from the prompt to done.",