← Commit history
Merge PR #698: 0.2.157: adopt KiCad Bridge 1.1.18 lock handling (#296) (aiflow-1118 -> main) merge
Showing changes introduced by the merge (against its first parent).
10 files changed
+66−21
Cargo.lock+11−11@@ -4,7 +4,7 @@ version = 4 [[package]] name = "adom-aiflow"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-analyze", "aiflow-board",@@ -28,7 +28,7 @@ dependencies = [ [[package]] name = "aiflow-analyze"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-board", "aiflow-sys",@@ -39,7 +39,7 @@ dependencies = [ [[package]] name = "aiflow-board"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-sys", "roxmltree",@@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aiflow-bridge"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-board", "aiflow-sys",@@ -59,7 +59,7 @@ dependencies = [ [[package]] name = "aiflow-copper"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-board", "aiflow-grid",@@ -70,7 +70,7 @@ dependencies = [ [[package]] name = "aiflow-grid"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-board", "serde",@@ -79,7 +79,7 @@ dependencies = [ [[package]] name = "aiflow-place"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-board", "aiflow-sys",@@ -89,7 +89,7 @@ dependencies = [ [[package]] name = "aiflow-pours"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-board", "aiflow-copper",@@ -100,7 +100,7 @@ dependencies = [ [[package]] name = "aiflow-router"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-board", "aiflow-grid",@@ -111,7 +111,7 @@ dependencies = [ [[package]] name = "aiflow-run"-version = "0.2.156"+version = "0.2.157" dependencies = [ "aiflow-sys", "serde",@@ -120,7 +120,7 @@ dependencies = [ [[package]] name = "aiflow-sys"-version = "0.2.156"+version = "0.2.157" dependencies = [ "serde_json", ]
Cargo.toml+1−1@@ -15,7 +15,7 @@ members = [ ] [workspace.package]-version = "0.2.156"+version = "0.2.157" edition = "2021" license = "MIT" repository = "https://wiki.adom.inc/adom/adom-aiflow"
bin/adom-aiflow⋯ 1 unchanged line ⋯
crates/adom-aiflow/src/main.rs+3−3@@ -7624,7 +7624,7 @@ fn main() { let why = reason.clone().unwrap_or_else(|| format!("aiflow run {engine}: the run's own editor")); let iso = br.open_isolated(&rb, &why, raise, kicad_version.as_deref()).unwrap_or_else(|f| { use aiflow_bridge::isolated::Refusal; match f { Refusal::KicadVersion(m) => err(&format!("the KiCad bridge did not open that KiCad: {m}"), &[format!("{}The live verbs refuse a 10.99 development editor; open with a stable install (the default, or `--kicad-version <installed stable version>`).", kicad_version.as_deref().map(|v| format!("--kicad-version {v} is not an installed KiCad: give one the desktop has, or leave it out for the newest stable release. ")).unwrap_or_default())]),- Refusal::BoardLocked(m) => err(&format!("another KiCad has {rb} open, so the bridge refused a second editor: {m}"), &["Work on a copy: copy the board (with its .kicad_pro and .kicad_dru) to a new name, `adom-aiflow start` on the copy, then `capture open --isolated`. Never close the other editor.".into()]),+ Refusal::Held(m) | Refusal::BoardLocked(m) => err(&format!("another KiCad has {rb} open, so the bridge refused a second editor: {m}"), &["Work on a copy: copy the board (with its .kicad_pro and .kicad_dru) to a new name, `adom-aiflow start` on the copy, then `capture open --isolated`. Never close the other editor.".into()]), Refusal::Unsupported(m) => err(&format!("the KiCad bridge did not open an isolated editor: {m}"), &["Update the KiCad bridge to 1.1.5 or newer (`adom-bridge bridge_update '{\"name\":\"kicad\"}'`), or use `capture open` (the shared editor).".into()]), Refusal::UnsavedChanges(m) | Refusal::Other(m) => err(&format!("could not open the board in an isolated editor: {m}"), &[]), }});@@ -7638,7 +7638,7 @@ fn main() { if revision.is_none() { err(&format!("the isolated editor opened (hwnd {}) but its pipe does not answer for {rb} yet: {} {}", iso.hwnd.map(|h| h.to_string()).unwrap_or("?".into()), reply["errorCode"], reply["error"]), &["Read capture-open-ipc.json; run `capture open --isolated` again in a minute (the same board answers the same editor).".into()]); }- ok(&format!("board open in the run's own KiCad editor (hwnd {}, pid {}), pipe {}; every live call of this run goes to it", iso.hwnd.map(|h| h.to_string()).unwrap_or("?".into()), iso.pid.map(|p| p.to_string()).unwrap_or("?".into()), iso.socket),+ ok(&format!("board open in the run's own KiCad editor (hwnd {}, pid {}), pipe {}; every live call of this run goes to it{}", iso.hwnd.map(|h| h.to_string()).unwrap_or("?".into()), iso.pid.map(|p| p.to_string()).unwrap_or("?".into()), iso.socket, run_editor::cleared_line(&iso)), &["Next: declare your first step (`step intake`, `step placement`); its clip starts by itself.".into(), "Edit live; after an offline edit to the file use `capture reload`, never a relaunch. Before closing: `capture close` (saves, then closes only this editor).".into(), if raise { String::new() } else { "On a hands-off machine AI Flow sends KiCad behind the person's window once when the open says they are working and KiCad came in front (KiCad Bridge 1.1.7+); nobody at the machine, it stays.".into() }]);@@ -7788,7 +7788,7 @@ fn main() { } Err(Refusal::UnsavedChanges(m)) => err(&format!("the editor has unsaved edits, so it was not reloaded: {m}"), &["Save them first (`adom-bridge kicad_save_board` with the board's filePath and, for an isolated editor, its socketPath), or `capture reload --discard` to drop them.".into()]), Err(Refusal::KicadVersion(m)) => err(&format!("could not reload the board: {m}"), &["The live verbs refuse a 10.99 development editor (KiCad Bridge 1.1.11): close it, then `capture open --isolated` with a stable KiCad.".into()]),- Err(Refusal::BoardLocked(m) | Refusal::Unsupported(m) | Refusal::Other(m)) => err(&format!("could not reload the board: {m}"), &["`kicad_reload_board` needs KiCad Bridge 1.1.5 or newer.".into()]),+ Err(Refusal::Held(m) | Refusal::BoardLocked(m) | Refusal::Unsupported(m) | Refusal::Other(m)) => err(&format!("could not reload the board: {m}"), &["`kicad_reload_board` needs KiCad Bridge 1.1.5 or newer.".into()]), } } "close" => {
crates/adom-aiflow/src/run_editor.rs+11−2@@ -41,18 +41,27 @@ pub fn reviver(dir: PathBuf) -> revive::Reviver { // the command holds its own copy of run.json: its later saves write the new editor, not the gone one aiflow_run::pin("kicadIsolated", now_rec); r.save()?;- crate::note(&format!("{} was no longer running; reopened it (pid {}, pipe {}) and the call went on", who(&rec), iso.pid.map(|p| p.to_string()).unwrap_or("?".into()), iso.socket), &[]);+ crate::note(&format!("{} was no longer running; reopened it (pid {}, pipe {}) and the call went on{}", who(&rec), iso.pid.map(|p| p.to_string()).unwrap_or("?".into()), iso.socket, cleared_line(&iso)), &[]); Ok(iso.socket) } // a KiCad that was ended rather than closed leaves its lock files beside the board: with no editor showing the // board, the lock is that one's, not another editor's- Err(Refusal::BoardLocked(m)) if br.board_window_any(&board, None).is_none() => Err(format!("{gone}, and a new one was refused as locked ({m}), but no KiCad editor shows the board: the lock is most likely left over from the editor that exited. Delete {} beside the board (KiCad's lock files), then `adom-aiflow capture open --isolated`.", lock_files(&board))),+ // KiCad Bridge 1.1.18+ clears a lock it is sure is stale; one it refuses is really held: never delete it+ Err(Refusal::Held(m)) => Err(format!("{gone}, and a new one was refused: the board is {m}. Keep working in that editor with `adom-aiflow capture open` (the run then forgets its own), or close it (on that machine, for another machine's lock) and run `adom-aiflow capture open --isolated`. Do not delete its lock files.")),+ // a bridge before 1.1.18 refuses a lock an ended KiCad left behind as well: with no editor showing the board here+ Err(Refusal::BoardLocked(m)) if br.board_window_any(&board, None).is_none() => Err(format!("{gone}, and a new one was refused as locked ({m}), but no KiCad editor shows the board: the lock is most likely left over from the editor that exited. If nobody on another machine has the board open, delete {} beside the board (KiCad's lock files), then `adom-aiflow capture open --isolated`; KiCad Bridge 1.1.18 or newer clears a stale lock itself (`adom-bridge bridge_update '{{\"name\":\"kicad\"}}'`).", lock_files(&board))), Err(Refusal::BoardLocked(m)) => Err(format!("{gone}, and a new one was refused because another KiCad has the board open ({m}). Keep working in that editor with `adom-aiflow capture open` (the run then forgets its own), or save and close it and run `adom-aiflow capture open --isolated`.")), Err(Refusal::KicadVersion(m) | Refusal::Unsupported(m) | Refusal::UnsavedChanges(m) | Refusal::Other(m)) => Err(format!("{gone}; opening it again failed: {m}. `adom-aiflow capture open --isolated` starts it again.")), } }) } +/// "; the KiCad bridge cleared stale lock files: ..." when the open did (KiCad Bridge 1.1.18+), else nothing.+pub fn cleared_line(iso: &aiflow_bridge::isolated::Isolated) -> String {+ if iso.stale_locks_cleared.is_empty() { return String::new(); }+ format!("; the KiCad bridge cleared lock files an ended KiCad had left: {}", iso.stale_locks_cleared.join(", "))+}+ /// KiCad's lock files for a board: `~b.kicad_pcb.lck` and `~b.kicad_pro.lck` in the board's folder. fn lock_files(board: &str) -> String { let name = board.rsplit(['/', '\\']).next().unwrap_or(board);
crates/aiflow-bridge/src/isolated.rs+28−1@@ -12,6 +12,9 @@ pub struct Isolated { pub title: String, pub pid: Option<i64>, pub temp_dir: String,+ /// KiCad Bridge 1.1.18 (adom-aiflow#296): lock files an ended KiCad left behind, cleared by the open+ /// (`staleLocksCleared [{lockFile, why}]`), as "<lockFile> (<why>)".+ pub stale_locks_cleared: Vec<String>, } impl Isolated {@@ -24,8 +27,12 @@ impl Isolated { /// Why an isolated open or a reload did not happen, sorted so the hint can say what to do. #[derive(Debug, Clone, PartialEq)] pub enum Refusal {- /// Another KiCad holds the board's lock: work on a copy.+ /// Another KiCad holds the board's lock: work on a copy. A bridge before 1.1.18 says so for a lock left+ /// behind by an ended KiCad too (it does not tell them apart). BoardLocked(String),+ /// KiCad Bridge 1.1.18+: a KiCad really holds the board (`staleLock: false`; `heldBy` names its window,+ /// `lockHost` another machine). Its lock files are never to be deleted.+ Held(String), /// The editor shows unsaved edits: save first, or reload with discardUnsaved. UnsavedChanges(String), /// The bridge does not know `isolated` (older than 1.1.5) or answered no socket.@@ -52,6 +59,15 @@ fn refusal(reply: &Value) -> Refusal { let code = reply["errorCode"].as_str().or(d["errorCode"].as_str()).unwrap_or("").to_ascii_lowercase(); let m = message(reply); match code.as_str() {+ "board_locked" if d.get("staleLock").or(reply.get("staleLock")) == Some(&Value::Bool(false)) => {+ let pick = |k: &str| d[k].as_str().or(reply[k].as_str()).filter(|v| !v.trim().is_empty()).map(str::to_string);+ let who = match (pick("heldBy"), pick("lockHost")) {+ (Some(w), _) => format!("held by the KiCad window \"{w}\""),+ (None, Some(h)) => format!("locked from another machine ({h})"),+ (None, None) => "held by a running KiCad".to_string(),+ };+ Refusal::Held(format!("{who}: {m}"))+ } "board_locked" => Refusal::BoardLocked(m), "unsaved_changes" => Refusal::UnsavedChanges(m), "unknown_verb" | "unknown_parameter" | "invalid_args" | "not_supported" => Refusal::Unsupported(m),@@ -80,6 +96,10 @@ pub fn isolated_of(reply: &Value) -> Result<Isolated, Refusal> { title: pick("title").as_str().unwrap_or("").to_string(), pid: pick("pid").as_i64(), temp_dir: pick("tempDir").as_str().unwrap_or("").to_string(),+ stale_locks_cleared: pick("staleLocksCleared").as_array().into_iter().flatten().filter_map(|l| {+ let f = l["lockFile"].as_str().or(l.as_str())?;+ Some(match l["why"].as_str().filter(|w| !w.trim().is_empty()) { Some(w) => format!("{f} ({w})"), None => f.to_string() })+ }).collect(), }) } @@ -138,6 +158,13 @@ mod tests { fn locked_board_and_old_bridge_are_told_apart() { let locked = json!({"success": false, "errorCode": "board_locked", "error": "another KiCad has it open"}); assert!(matches!(isolated_of(&locked), Err(Refusal::BoardLocked(m)) if m.contains("another KiCad")));+ // KiCad Bridge 1.1.18: a lock a KiCad really holds, named, and a stale pair the open cleared+ let held = json!({"success": false, "errorCode": "board_locked", "error": "b.kicad_pcb is locked", "staleLock": false, "heldBy": "b — PCB Editor"});+ assert!(matches!(isolated_of(&held), Err(Refusal::Held(m)) if m.contains("b — PCB Editor")));+ let remote = json!({"success": false, "data": {"errorCode": "board_locked", "staleLock": false, "lockHost": "OTHER-PC"}});+ assert!(matches!(isolated_of(&remote), Err(Refusal::Held(m)) if m.contains("OTHER-PC")));+ let cleared = json!({"success": true, "socketPath": "ipc://x", "staleLocksCleared": [{"lockFile": "C:/b/~b.kicad_pcb.lck", "why": "no KiCad running"}]});+ assert_eq!(isolated_of(&cleared).unwrap().stale_locks_cleared, vec!["C:/b/~b.kicad_pcb.lck (no KiCad running)".to_string()]); // an older bridge opens the board in the shared editor and answers no socket let old = json!({"success": true, "hwnd": 9, "title": "b — PCB Editor"}); assert!(matches!(isolated_of(&old), Err(Refusal::Unsupported(_))));
docs/release-0.2.157.mdadded+9@@ -0,0 +1,9 @@+# adom-aiflow 0.2.157++Adopts KiCad Bridge 1.1.18 (issue #296 follow-up).++- **A lock KiCad really holds is never called stale.** KiCad Bridge 1.1.18 clears a lock file it is sure an ended KiCad left behind, and its `board_locked` then means a KiCad holds the board (`staleLock: false`). AI Flow now names who holds it (the window, or the other machine) and says to keep working there or close it. It never suggests deleting those lock files.+- **Cleared locks are reported.** When the open cleared stale lock files (`staleLocksCleared`), `capture open --isolated` and the automatic reopen from 0.2.156 list them.+- On a bridge before 1.1.18, the 0.2.156 fallback stays: with no editor showing the board, AI Flow suggests deleting the two lock files, but only if nobody on another machine has the board open. It also points to the bridge update.++Tested on Windows 11 with KiCad 10.0.8 and KiCad Bridge 1.1.18: the run's editor was ended and left its lock files; `measure` reopened it, the bridge cleared the locks, the NOTE named them, and the copper was read.
package.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow", "type": "app",- "version": "0.2.156",+ "version": "0.2.157", "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.156",+ "version": "0.2.157", "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.",
skills/adom-aiflow/SKILL.md+1−1@@ -402,7 +402,7 @@ The AI's time on a run is the sum of its sessions: one per human prompt, from th ## When the run's own editor has closed -A run's own KiCad editor (`capture open --isolated`) that was closed or exited is reopened by the first live call that finds its pipe gone: a NOTE says so with the new pid, run.json records it, and the command goes on. When it cannot be reopened the error says why and what to do: another KiCad has the board open (keep working there with `capture open`, which forgets the gone editor, or close it and `capture open --isolated`), or KiCad left its lock files (`~<board>.kicad_pcb.lck`, `~<board>.kicad_pro.lck`) behind after being ended, with no editor showing the board (delete them, then `capture open --isolated`).+A run's own KiCad editor (`capture open --isolated`) that was closed or exited is reopened by the first live call that finds its pipe gone: a NOTE says so with the new pid, run.json records it, and the command goes on. When it cannot be reopened the error says why and what to do: another KiCad has the board open (keep working there with `capture open`, which forgets the gone editor, or close it and `capture open --isolated`), or, on a KiCad bridge before 1.1.18, KiCad left its lock files (`~<board>.kicad_pcb.lck`, `~<board>.kicad_pro.lck`) behind after being ended, with no editor showing the board (if nobody on another machine has the board open, delete them, then `capture open --isolated`). KiCad Bridge 1.1.18 clears a lock it is sure is stale and the open lists it; a lock it still refuses is really held (by a window it names, or another machine): never delete that one. ## Reload after an offline edit