← All Pull Requests
adom-aiflow-jlcpcb 0.1.4: AI Flow's BOM columns; no Mouser number as LCSC #2
Merges
aiflow-jlcpcb-0.1.4 → mainAI Flow: JLCPCB 0.1.4. Reads AI Flow's BOMs as they are, and never takes a Mouser number for an LCSC number (from adom-aiflow#184).
- BOM columns are matched whatever their case, with aliases:
ref/Reference/Designator,lcsc/LCSC Part #,mpn/MPN,value/Comment. - A part's LCSC number comes from
lcsc, or fromvendor_pnonly when it is an LCSC number (C + digits). Before,exportand the rotation check took a fab-profile BOM's Mouservendor_pnas the LCSC number. sourcingnames each part still missing an LCSC number by its MPN, and hintsadom-jlcpcb search "<mpn>"(try it without hyphens too).- The skill documents this. Test:
columns_match_aliases_and_vendor_pn_counts_only_when_it_is_an_lcsc_number; all 10 tests pass.
🤖 Generated with Claude Code
Diff Skip to comments
Cargo.lock+1−1@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "adom-aiflow-jlcpcb"-version = "0.1.3"+version = "0.1.4" dependencies = [ "clap", "regex",
Cargo.toml+1−1@@ -2,7 +2,7 @@ # Copied from adom/adom-aiflow template/flow-app. This copy is yours: change anything, never depend on aiflow. [package] name = "adom-aiflow-jlcpcb"-version = "0.1.3"+version = "0.1.4" edition = "2021" license = "MIT"
bin/adom-aiflow-jlcpcb⋯ 1 unchanged line ⋯
package.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow-jlcpcb", "type": "app",- "version": "0.1.3",+ "version": "0.1.4", "title": "AI Flow: JLCPCB", "description": "The JLCPCB ordering stage of AI Flow: from a finished board to assembled boards from JLCPCB. Part substitutes proven from both datasheets, the gerber zip, BOM and CPL from the desktop's own KiCad, every part's rotation checked against JLCPCB's own footprint and corrected, placement-preview evidence, the quote, the human's recorded OK before payment, and rotation corrections shared on component pages. Open source (MIT): build it with ./build.sh.", "category": "Developer Tools",
page.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow-jlcpcb", "type": "app",- "version": "0.1.3",+ "version": "0.1.4", "title": "AI Flow: JLCPCB", "description": "The JLCPCB ordering stage of AI Flow: from a finished board to assembled boards from JLCPCB. Part substitutes proven from both datasheets, the gerber zip, BOM and CPL from the desktop's own KiCad, every part's rotation checked against JLCPCB's own footprint and corrected, placement-preview evidence, the quote, the human's recorded OK before payment, and rotation corrections shared on component pages. Open source (MIT): build it with ./build.sh.", "category": "Developer Tools",
skills/adom-aiflow-jlcpcb/SKILL.md+8@@ -41,6 +41,14 @@ adom-aiflow-jlcpcb report on top of the design's deliberate choices. `export` refuses until it passes. Design for JLCPCB from the start by loading the same file in the board flow. +- **The BOM `init --bom` takes** is the run's sourcing BOM (AI Flow's `design/bom.csv`). Column names are matched+ whatever their case, with the usual aliases (`ref`/Reference/Designator, `lcsc`/LCSC Part #, `mpn`/MPN,+ `value`/Comment), so AI Flow's own BOMs work as they are. A part's LCSC number comes from the `lcsc` column, or+ from `vendor_pn` only when that is an LCSC number (C + digits): a Mouser number never stands in for one.+ `sourcing` names each part still without an LCSC number by its MPN; `adom-jlcpcb search "<mpn>"` finds it (try+ the MPN without hyphens too: LCSC often drops them). AI Flow's `export` BOM and CPL are review files, never+ JLCPCB's: this stage's `export` writes JLCPCB's.+ - **Rotation is the classic JLCPCB failure.** KiCad's and JLCPCB's footprints often disagree on a package's zero rotation (SOT-23, TSOT, SOIC, QFN, electrolytics). `export` fits JLCPCB's own footprint to the board's pads for every LCSC number and corrects the CPL. A FAIL means the wrong footprint or LCSC number, or a mirrored part: fix
src/csvio.rs+34−1@@ -39,7 +39,30 @@ impl Table { let head = all.remove(0).into_iter().map(|h| h.trim().to_string()).collect(); Ok(Table { head, rows: all.into_iter().filter(|r| !(r.len() == 1 && r[0].is_empty())).collect() }) }- pub fn col(&self, name: &str) -> Option<usize> { self.head.iter().position(|h| h == name) }+ /// A column by name: exact first, then case and punctuation ignored, then the usual aliases+ /// (AI Flow's `export` BOM says Reference and MPN, JLCPCB's says Designator and LCSC Part #).+ pub fn col(&self, name: &str) -> Option<usize> {+ if let Some(i) = self.head.iter().position(|h| h == name) { return Some(i); }+ let norm = |s: &str| s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::<String>().to_ascii_lowercase();+ let aliases: &[&str] = match name {+ "ref" => &["ref", "refs", "reference", "references", "designator", "designators", "refdes"],+ "lcsc" => &["lcsc", "lcscpart", "lcscpartno", "lcscpn", "lcscpartnumber", "jlcpcbpart", "jlcpn"],+ "mpn" => &["mpn", "manufacturerpartnumber", "manufacturerpn", "mfrpn", "partnumber"],+ "value" => &["value", "comment", "val"],+ _ => &[],+ };+ let want: Vec<String> = std::iter::once(norm(name)).chain(aliases.iter().map(|a| a.to_string())).collect();+ want.iter().find_map(|w| self.head.iter().position(|h| &norm(h) == w))+ }+ /// The row's LCSC number: the lcsc column, else vendor_pn only when it is one (C + digits).+ /// A fab-profile BOM's vendor_pn is a Mouser number and must never stand in for LCSC.+ pub fn lcsc(&self, row: &[String]) -> String {+ let is_c = |s: &str| s.len() > 1 && s.starts_with('C') && s[1..].chars().all(|c| c.is_ascii_digit());+ let l = self.get(row, "lcsc").trim();+ if !l.is_empty() { return l.to_string(); }+ let v = self.get(row, "vendor_pn").trim();+ if is_c(v) { v.to_string() } else { String::new() }+ } pub fn get<'a>(&self, row: &'a [String], name: &str) -> &'a str { self.col(name).and_then(|i| row.get(i)).map(|s| s.as_str()).unwrap_or("") }@@ -62,4 +85,14 @@ mod tests { assert_eq!(rows, vec![vec!["a", "b, c", "d \"e\""], vec!["1", "2", "3"]]); assert_eq!(super::write(&rows, "\n"), "a,\"b, c\",\"d \"\"e\"\"\"\n1,2,3\n"); }++ #[test]+ fn columns_match_aliases_and_vendor_pn_counts_only_when_it_is_an_lcsc_number() {+ let t = super::Table { head: ["Reference", "Value", "MPN", "LCSC Part #", "vendor_pn"].map(String::from).to_vec(), rows: vec![] };+ assert_eq!((t.col("ref"), t.col("value"), t.col("mpn"), t.col("lcsc")), (Some(0), Some(1), Some(2), Some(3)));+ let row = |l: &str, v: &str| ["C1", "10u", "X", l, v].map(String::from).to_vec();+ assert_eq!(t.lcsc(&row("C15850", "")), "C15850");+ assert_eq!(t.lcsc(&row("", "C178548")), "C178548");+ assert_eq!(t.lcsc(&row("", "667-EEE-FK1H101P")), ""); // a Mouser number is not an LCSC number+ } }
src/export.rs+1−2@@ -84,8 +84,7 @@ pub fn export(br: &Bridge, board: &Path, bom_path: &Path, out: &Path, rotations: let fit = bom.get(row, "fit").trim().to_lowercase(); for rf in split.split(bom.get(row, "ref")).filter(|s| !s.is_empty()) { if crate::rotation::SKIP_FIT.contains(&fit.as_str()) { fitpost.insert(rf.to_string()); continue; }- let l = bom.get(row, "lcsc").trim();- lcsc_of.insert(rf.to_string(), if l.is_empty() { bom.get(row, "vendor_pn").trim().to_string() } else { l.to_string() });+ lcsc_of.insert(rf.to_string(), bom.lcsc(row)); let v = bom.get(row, "value"); comment_of.insert(rf.to_string(), if v.is_empty() { bom.get(row, "mpn").to_string() } else { v.to_string() }); mpn_of.insert(rf.to_string(), bom.get(row, "mpn").to_string());
src/main.rs+3−3@@ -243,10 +243,10 @@ fn main() { let mut covered = std::collections::BTreeSet::new(); for row in &bom.rows { let fit = bom.get(row, "fit").trim().to_lowercase();- let l = { let l = bom.get(row, "lcsc").trim(); if l.is_empty() { bom.get(row, "vendor_pn").trim() } else { l } };+ let l = bom.lcsc(row); let l = l.as_str(); for rf in split.split(bom.get(row, "ref")).filter(|s| !s.is_empty()) { covered.insert(rf.to_string());- if !rotation::SKIP_FIT.contains(&fit.as_str()) && !re_c.is_match(l) { missing.push(rf.to_string()); }+ if !rotation::SKIP_FIT.contains(&fit.as_str()) && !re_c.is_match(l) { let m = bom.get(row, "mpn").trim(); missing.push(if m.is_empty() { rf.to_string() } else { format!("{rf} ({m})") }); } } } let mut absent: Vec<String> = fps.keys().filter(|r| !covered.contains(*r) && !r.starts_with('#')).cloned().collect();@@ -254,7 +254,7 @@ fn main() { if !missing.is_empty() || !absent.is_empty() { err(&format!("sourcing is not closed: {}{}", if missing.is_empty() { String::new() } else { format!("no LCSC number for {}", missing.join(", ")) }, if absent.is_empty() { String::new() } else { format!("{}board references with no BOM row: {}", if missing.is_empty() { "" } else { "; " }, absent.join(", ")) }),- &["Search in Hydrogen (`adom-parts-search show \"<spec>\" --basic`), prove each substitute with `swap`, or mark parts fitted after assembly fit=post.".into()]);+ &["Find each MPN's LCSC number with `adom-jlcpcb search \"<mpn>\"` (LCSC often lists it without hyphens or with a reel suffix: try those too) and put it in the BOM's lcsc column; for a substitute search in Hydrogen (`adom-parts-search show \"<spec>\" --basic`) and prove it with `swap`; mark parts fitted after assembly fit=post.".into()]); } let swaps: Vec<Value> = std::fs::read_to_string(p.path("run.jsonl")).unwrap_or_default().lines().filter_map(|l| serde_json::from_str::<Value>(l).ok()) .filter(|e| e["ev"] == "swap" && e["data"]["applied"] == true).map(|e| e["data"].clone()).collect();
src/rotation.rs+1−1@@ -148,7 +148,7 @@ pub fn check(br: &Bridge, board: &Path, bom: &Table, overrides: &Map<String, Val let (mut lcsc, mut mpn) = (BTreeMap::new(), BTreeMap::new()); for row in &bom.rows { if SKIP_FIT.contains(&bom.get(row, "fit").trim().to_lowercase().as_str()) { continue; }- let c = { let l = bom.get(row, "lcsc").trim(); if l.is_empty() { bom.get(row, "vendor_pn").trim() } else { l } }.to_string();+ let c = bom.lcsc(row); if !re_c.is_match(&c) { continue; } for rf in split.split(bom.get(row, "ref")).filter(|s| !s.is_empty()) { lcsc.insert(rf.to_string(), c.clone()); mpn.insert(rf.to_string(), bom.get(row, "mpn").to_string()); } }
Comments
Log in to comment.
No comments yet.