← Commit history

0.2.120: schematic check accepts natively bound references (closes #266)

Colby Knox ·e29b5e4f95 · ·parent bd0e830
Co-Authored-By: Claude Opus 5.5 <[email protected]>
9 files changed +67−16
Cargo.lock+10−10
@@ -4,7 +4,7 @@ version = 4  [[package]] name = "adom-aiflow"-version = "0.2.119"+version = "0.2.120" dependencies = [  "aiflow-analyze",  "aiflow-board",@@ -25,7 +25,7 @@ dependencies = [  [[package]] name = "aiflow-analyze"-version = "0.2.119"+version = "0.2.120" dependencies = [  "aiflow-board",  "serde",@@ -35,7 +35,7 @@ dependencies = [  [[package]] name = "aiflow-board"-version = "0.2.119"+version = "0.2.120" dependencies = [  "roxmltree",  "serde",@@ -44,7 +44,7 @@ dependencies = [  [[package]] name = "aiflow-bridge"-version = "0.2.119"+version = "0.2.120" dependencies = [  "aiflow-board",  "serde",@@ -53,7 +53,7 @@ dependencies = [  [[package]] name = "aiflow-copper"-version = "0.2.119"+version = "0.2.120" dependencies = [  "aiflow-board",  "aiflow-grid",@@ -63,7 +63,7 @@ dependencies = [  [[package]] name = "aiflow-grid"-version = "0.2.119"+version = "0.2.120" dependencies = [  "aiflow-board",  "serde",@@ -72,7 +72,7 @@ dependencies = [  [[package]] name = "aiflow-place"-version = "0.2.119"+version = "0.2.120" dependencies = [  "aiflow-board",  "serde",@@ -81,7 +81,7 @@ dependencies = [  [[package]] name = "aiflow-pours"-version = "0.2.119"+version = "0.2.120" dependencies = [  "aiflow-board",  "aiflow-copper",@@ -91,7 +91,7 @@ dependencies = [  [[package]] name = "aiflow-router"-version = "0.2.119"+version = "0.2.120" dependencies = [  "aiflow-board",  "aiflow-grid",@@ -102,7 +102,7 @@ dependencies = [  [[package]] name = "aiflow-run"-version = "0.2.119"+version = "0.2.120" dependencies = [  "serde",  "serde_json",
Cargo.toml+1−1
@@ -14,7 +14,7 @@ members = [ ]  [workspace.package]-version = "0.2.119"+version = "0.2.120" edition = "2021" license = "MIT" repository = "https://wiki.adom.inc/adom/adom-aiflow"
bin/adom-aiflow
⋯ 1 unchanged line ⋯
crates/adom-aiflow/src/main.rs+6−2
@@ -5355,7 +5355,11 @@ fn main() {             let drawn = if off_board.is_empty() { Default::default() } else { schematic_check::drawn_refs(Path::new(sch)) };             let missing: Vec<String> = bom_refs.iter().filter(|rf| !on_sheet.contains_key(*rf) && !(off_board.contains(rf) && drawn.contains(*rf)))                 .map(|rf| if off_board.contains(rf) { format!("{rf} (off-board in the BOM, and no symbol with that reference is drawn)") } else { rf.clone() }).collect();-            let foreign: Vec<String> = match &lib { Some(l) => on_sheet.iter().filter(|(rf, (sl, fp))| bom_refs.contains(rf) && (sl != l || !fp.starts_with(&format!("{l}:")))).map(|(rf, (sl, fp))| format!("{rf} ({sl} / {fp})")).collect(), None => Vec::new() };+            // issue #266: a reference whose complete project-library entry binds it to the native library and footprint+            // the existing schematic uses (provenance.json nativeSourceBindings) is not asked to move to the PCM library+            let part_rows = r.data["outcomes"]["parts"]["parts"].as_array().cloned().unwrap_or_default();+            let bound: Vec<String> = on_sheet.iter().filter(|(rf, (sl, fp))| bom_refs.contains(rf) && project_lib::native_binding_matches(&part_rows, rf, sl, fp)).map(|(rf, _)| rf.clone()).collect();+            let foreign: Vec<String> = match &lib { Some(l) => on_sheet.iter().filter(|(rf, (sl, fp))| bom_refs.contains(rf) && (sl != l || !fp.starts_with(&format!("{l}:"))) && !bound.contains(rf)).map(|(rf, (sl, fp))| format!("{rf} ({sl} / {fp})")).collect(), None => Vec::new() };             let extra: Vec<String> = on_sheet.keys().filter(|rf| !bom_refs.contains(rf)).cloned().collect();             // issue #39: symbol polarity drawings, active-device pin types and readability (schematic_symbols.rs)             let symbols = schematic_symbols::check(Path::new(sch), &spec_soft(&r)).unwrap_or_else(|e| json!({"ok": false, "errors": [format!("could not read the hierarchy: {e}")], "warnings": []}));@@ -5367,7 +5371,7 @@ fn main() {             let pin_hints: Vec<String> = pin_names.iter().map(|(finding, suggestion)| format!("Molecule names: {finding}. {suggestion}")).collect();             let canon = std::fs::canonicalize(sch).map(|p| p.display().to_string()).unwrap_or(sch.clone());             r.outcome("erc", json!({"pass": erc_errors.is_empty(), "errors": erc_errors, "schematic": canon, "sha256": sha256_file(sch), "report": erc.display().to_string(), "source": "schematic check (kicad-cli sch erc)"}));-            r.outcome("schematic", json!({"pass": pass, "schematic": canon, "sha256": sha256_file(sch), "ercErrors": erc_errors, "symbols": on_sheet.len(), "missingRefs": missing, "notFromProjectLibrary": foreign, "notInBom": extra, "library": lib, "moleculeNames": pin_names.iter().map(|(a, b)| json!({"finding": a, "suggestion": b})).collect::<Vec<_>>()}));+            r.outcome("schematic", json!({"pass": pass, "schematic": canon, "sha256": sha256_file(sch), "ercErrors": erc_errors, "symbols": on_sheet.len(), "missingRefs": missing, "notFromProjectLibrary": foreign, "nativeBound": bound, "notInBom": extra, "library": lib, "moleculeNames": pin_names.iter().map(|(a, b)| json!({"finding": a, "suggestion": b})).collect::<Vec<_>>()}));             if pass { r.data["schematic"] = json!(canon); }             r.save().unwrap();             if !pass {
crates/adom-aiflow/src/project_lib.rs+36
@@ -9,6 +9,8 @@ //! "footprint": "QFN-16_3x3", "model": "3dmodels/ABC-123.step"}]} (or {"parts": {"ABC-123": {...}}}). //! symbol defaults to the MPN, footprint to the symbol's Footprint property, model to the footprint's model. //! A wiki page for the same MPN wins unless the entry says "prefer": true (issue #157, `prefer`).+//! An existing project keeping its native libraries binds each reference: "nativeSourceBindings": [{"ref": "U1",+//! "symbolLibrary": "MyLib", "footprint": "MyLib:QFN-48"}] (issue #266, `native_binding_matches`).  use aiflow_board::sx; use serde_json::{json, Value};@@ -175,6 +177,22 @@ pub fn report(parts: &Value) -> Vec<String> {     }).collect() } +/// Issue #266 (Jørgen Lolk Mollerup): an existing project keeps its own native libraries. A reference passes the+/// schematic check's PCM-library naming rule when its part has a complete project-library entry (`projectLib`, the+/// files and provenance `parts` found) whose provenance.json `nativeSourceBindings` names that reference with the exact+/// symbol library and footprint the schematic uses: `[{"ref": "U1", "symbolLibrary": "MyLib", "footprint": "MyLib:QFN-48"}]`.+/// A binding for another reference, library or footprint, or a part with no complete entry, still fails.+pub fn native_binding_matches(parts: &[Value], rf: &str, symbol_lib: &str, footprint: &str) -> bool {+    parts.iter().any(|part| {+        let in_part = part["refs"].as_array().is_some_and(|r| r.iter().any(|v| v.as_str() == Some(rf)));+        let complete = part["projectLib"]["symbolFile"].is_string() && part["projectLib"]["footprintFile"].is_string() && part["projectLib"]["model"].is_string();+        in_part && complete && part["projectLib"]["provenance"]["nativeSourceBindings"].as_array().into_iter().flatten().any(|b| {+            let lib = b["symbolLibrary"].as_str().or_else(|| b["symbol"].as_str().and_then(|s| s.split_once(':').map(|(l, _)| l)));+            b["ref"].as_str() == Some(rf) && lib == Some(symbol_lib) && b["footprint"].as_str() == Some(footprint)+        })+    })+}+ /// Recheck at finish: every project-library part still has its files. pub fn recheck(parts: &Value) -> Vec<String> {     let mut gaps = Vec::new();@@ -322,4 +340,22 @@ mod tests {         assert!(stale(&rec, "gone.csv", None)[0].contains("can no longer be read"));         let _ = std::fs::remove_dir_all(&d);     }++    #[test]+    fn a_native_binding_passes_only_its_own_reference_library_and_footprint() {+        // issue #266 (Jørgen Lolk Mollerup)+        let pl = |bindings: serde_json::Value| json!({"symbolFile": "/p/MyLib.kicad_sym", "footprintFile": "/p/MyLib.pretty/QFN.kicad_mod", "model": "/p/qfn.step",+            "provenance": {"mpn": "ABC", "source": "datasheet", "nativeSourceBindings": bindings}});+        let rows = vec![json!({"refs": ["U1", "U2"], "projectLib": pl(json!([{"ref": "U1", "symbolLibrary": "MyLib", "footprint": "MyLib:QFN"}, {"ref": "U2", "symbol": "MyLib:ABC", "footprint": "MyLib:QFN"}]))})];+        assert!(native_binding_matches(&rows, "U1", "MyLib", "MyLib:QFN"));+        assert!(native_binding_matches(&rows, "U2", "MyLib", "MyLib:QFN"), "the library from a symbol lib id");+        assert!(!native_binding_matches(&rows, "U3", "MyLib", "MyLib:QFN"), "a reference not bound");+        assert!(!native_binding_matches(&rows, "U1", "Other", "MyLib:QFN"), "another symbol library");+        assert!(!native_binding_matches(&rows, "U1", "MyLib", "MyLib:SOIC"), "another footprint");+        let mut incomplete = rows.clone();+        incomplete[0]["projectLib"].as_object_mut().unwrap().remove("model");+        assert!(!native_binding_matches(&incomplete, "U1", "MyLib", "MyLib:QFN"), "an incomplete entry (no model)");+        assert!(!native_binding_matches(&[json!({"refs": ["U1"], "wiki": "adom/abc"})], "U1", "MyLib", "MyLib:QFN"), "a wiki part has no binding");+    }+ }
docs/release-0.2.120.mdadded+11
@@ -0,0 +1,11 @@+# adom-aiflow 0.2.120++## schematic check: an existing project may keep its native libraries (issue #266, Jørgen Lolk Mollerup)++`schematic check` asked every BOM reference to come from the project's PCM library (`PCM_<name>`, from a prior `project-page`). An existing project that keeps its own native libraries failed the naming rule even when ERC and pin-net parity passed and every part had a complete project-library entry. Packaging a library is not the same as migrating an existing schematic to it.++- A part with a complete project-library entry (symbol, footprint, STEP model and provenance, as `parts --project-lib` found it) may bind each reference to the native library and footprint the schematic uses, in its provenance.json entry: `"nativeSourceBindings": [{"ref": "U1", "symbolLibrary": "MyLib", "footprint": "MyLib:QFN-48"}]` (or `"symbol": "MyLib:Part"`). That reference then passes the naming rule.+- A reference not bound, another symbol library, another footprint, or an incomplete entry still fails. ERC, missing references, symbol polarity and pin types are unchanged.+- The `schematic` outcome lists the bound references (`nativeBound`).++The PCM library stays the default for a board drawn from scratch.
package.json+1−1
@@ -1,7 +1,7 @@ {   "slug": "adom-aiflow",   "type": "app",-  "version": "0.2.119",+  "version": "0.2.120",   "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.119",+  "version": "0.2.120",   "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
@@ -349,7 +349,7 @@ A KiCad run that starts with no board (`intake` with no `start --board`) follows 2. **`step parts`, `parts --show`**: every BOM row with an MPN is matched to its Adom wiki component page; one Hydrogen tab ("Parts · <run>") steps through the pages so the viewer sees the parts picked. A part with no page: `part-request <MPN>` asks Adom's part factory for it (or make it with the wiki-component skill: datasheet symbol, footprint, STEP; verified), run `parts --show` again. A refused request gets one retry with a changed input (`--as <orderable MPN>`, `--datasheet <the maker's drawing>`); a part still without a page gets a supply assessment and up to three alternatives (`supply-risk`), and the human chooses (`supply-risk --choose`): aiflow-sourcing, "When a part cannot get a page". Never swap in a similar part to dodge a missing page, and never without the human's choice. 3. **`step project-page`, `project-page --page <owner>/<slug> --create`**: revision 1 of the board's one project page before any EDA work: a README saying what the board is, the component table (references, value, MPN, manufacturer, each part's wiki page) and a KiCad PCM repository of every part (an Adom Cloud Library of the parts, exported and repackaged for KiCad's Plugin and Content Manager, served from the page at `/api/pages/<owner>/<slug>/files/pcm/repository.json`). A new board always gets a new, standalone page (a new slug, `--create`); `project-page` refuses an existing page unless `--existing` says it is this same board's own page. Later revisions update this same page (aiflow-project-page skill); never a second page for the board. 4. **`step library`**: install the parts in KiCad on the test box: `kicad_pcm_add_repository {"url": <repositoryUrl>}`, `kicad_pcm_install {"repositoryUrl": ..., "identifier": ...}` (both printed by `project-page`), restart KiCad, then **`pcm check`** (the package is in `kicad_pcm_list`). The library is `PCM_<slug>`.-5. **`step schematic`**: draw the schematic in KiCad's schematic editor, on camera: `kicad_open_schematic`, `kicad_sch_place_symbol` (symbols from `PCM_<slug>`), `kicad_sch_wire`, `kicad_sch_label`, `kicad_sch_set_property`; save; **`schematic check --sch <project>.kicad_sch`** passes when kicad-cli ERC ran and has no errors (no ERC report is a failure, never a clean ERC), every BOM reference is on the sheet and every part comes from the project library. Never write the `.kicad_sch` with a script of your own: the viewer is meant to see it drawn.+5. **`step schematic`**: draw the schematic in KiCad's schematic editor, on camera: `kicad_open_schematic`, `kicad_sch_place_symbol` (symbols from `PCM_<slug>`), `kicad_sch_wire`, `kicad_sch_label`, `kicad_sch_set_property`; save; **`schematic check --sch <project>.kicad_sch`** passes when kicad-cli ERC ran and has no errors (no ERC report is a failure, never a clean ERC), every BOM reference is on the sheet and every part comes from the project library. An existing project that keeps its own native libraries need not move to `PCM_<slug>`: a part with a complete project-library entry passes when its provenance.json entry binds each reference to the exact native symbol library and footprint the schematic uses, `"nativeSourceBindings": [{"ref": "U1", "symbolLibrary": "MyLib", "footprint": "MyLib:QFN-48"}]` (issue #266); any other reference, library or footprint still fails, and ERC and the symbol checks are unchanged. Never write the `.kicad_sch` with a script of your own: the viewer is meant to see it drawn. 6. Simulate (as in the Fusion lane), then make the board in KiCad (Update PCB from Schematic, the outline), save it and attach it (`start --board ... --spec ...` on the same `--run`), `step components` and on.  **The project page grows with the run.** Once `project-page` names the page, every step the run leaves is pushed as its own sub-readme, `steps/<nn>-<step>/README.md` (what the step does, each visit and why a return came back, the proof the binary recorded, the screenshots and your registered drawings, the AI usage), and the main README keeps a "How this board was built" section between `<!-- aiflow:steps -->` markers: one intro line per step linking to its page. Keep the main README for people: what the board is, the hero, the component table, then those intros; the evidence lives in the sub-readmes. Register your drawings with `artifact` so they land on their step's page. `project-page --page <owner/slug> --sync` pushes every step at once (do it at finish). A page built with `--no-push` or `--local-only` gets no background step pushes: the run stays off the wiki until `--sync`. Step pages name local files by their name inside the run folder, never by an absolute path on this machine.