← All Pull Requests
adom-aiflow-jlcpcb 0.1.5: checks report findings, nothing is a hard gate #3
Merges
aiflow-jlcpcb-0.1.5 → mainadom-aiflow-jlcpcb 0.1.5 follows AI Flow's dynamic-skill rule (adom-aiflow PR #77): it's a guide, never a gate. Checks report a finding with a suggested fix and the command still does its job. ERROR now means only "I could not run".
rules: a board that breaks JLCPCB's rules is reported as findings (rules.json records it).exportno longer waits forrulesto pass; it adds a note and writes the package.export: a placed part with no LCSC number is left out of the JLCPCB BOM and CPL, listed in the manifest (leftOut.noLcsc) and reported with theadom-jlcpcb searchhint.- Rotation check: every correction it finds goes into the CPL. A part it can't fit keeps KiCad's rotation, is reported, and is flagged for the preview.
sourcing,swap,preview,quote,approve,ordered, and a board that changed since init: notes and findings instead of refusals. Money stays the AI asking the human.approveandorderedsay so when the amounts or the approval don't line up.- New
findings/noteoutput (FINDINGS / NOTE lines, exit 0). The skill, README and flow.json are reworded to match. 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.4"+version = "0.1.5" 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.4"+version = "0.1.5" edition = "2021" license = "MIT"
README.md+1−1@@ -43,7 +43,7 @@ flow-app template in adom/adom-aiflow (`template/flow-app`). ## Evidence checks and access recovery -`next` checks successful evidence and current board/BOM/artifact hashes, not merely whether JSON files exist. Failed rotation exports remain at export; changed exports invalidate preview evidence, and changed previews invalidate quotes. Older runs lacking these bindings must regenerate/review their evidence.+`next` checks successful evidence and current board/BOM/artifact hashes, not merely whether JSON files exist, and suggests the step with open items. Nothing is a hard gate (a dynamic skill: suggestions, the AI and the human decide): a later step still runs and notes what is open. Failed rotation parts keep the export open in `next`; changed exports make the preview evidence stale, and changed previews make the quote stale. Older runs lacking these bindings must regenerate/review their evidence. Automate JLCPCB in **Pup first**, reusing one window. Try **Sign in with Google inside Pup**, select the intended user account, verify sign-in, then continue the saved draft through quote pricing. A sign-in redirect is not a browser failure. Use Native Browser only after a demonstrated Pup-specific failure or explicit user preference.
bin/adom-aiflow-jlcpcb⋯ 1 unchanged line ⋯
flows/flow.json+1−1@@ -28,7 +28,7 @@ "done": [ "fab/*-fab-manifest.json" ],- "do": "Run `export` and inspect its exit status and rotation evidence. A geometry mismatch requires a corrected board or LCSC selection. A retrieval-unverified status instead requires access recovery: use `--browser-target <desktop> --browser-profile <explicit-profile>` for Native Browser, following adom-native-browser. The selected profile must belong to the user; do not silently select another person. Native Browser tries the vendor regional API and reuses same-day verified responses. Network errors never count as missing footprints. Continue until export passes; then `next`. Genuine missing vendor footprints require visual review in the JLCPCB placement preview. Never edit the CPL by hand. Keep the JLCPCB website workflow in Pup; failure of the separate footprint API is not a reason to migrate the quote UI."+ "do": "Run `export` and read its FINDINGS and rotation evidence (the package is written either way). A geometry mismatch suggests a corrected board or LCSC selection. A retrieval-unverified status suggests access recovery: use `--browser-target <desktop> --browser-profile <explicit-profile>` for Native Browser, following adom-native-browser. The selected profile must belong to the user; do not silently select another person. Native Browser tries the vendor regional API and reuses same-day verified responses. Network errors never count as missing footprints. Aim for an export with no findings; anything left open goes to the human with the quote. Then `next`. Genuine missing vendor footprints require visual review in the JLCPCB placement preview. Never edit the CPL by hand. Keep the JLCPCB website workflow in Pup; failure of the separate footprint API is not a reason to migrate the quote UI." }, { "name": "preview",
package.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow-jlcpcb", "type": "app",- "version": "0.1.4",+ "version": "0.1.5", "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.4",+ "version": "0.1.5", "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+16−10@@ -12,9 +12,12 @@ description: >- # adom-aiflow-jlcpcb -Run `adom-aiflow-jlcpcb next` whenever you are unsure what to do: it names the current step and what you must do in-it. Every command answers `OK:` or `ERROR:` with `Hint:` lines, and every command goes in-`<project>/jlcpcb-flow/run.jsonl`. Pass `--ai-thread <you>` on every command that changes state.+This is a **dynamic skill** (see adom-aiflow's "What a dynamic skill is"): the binary guides and checks, you do the+work and decide. No step is a hard gate. Run `adom-aiflow-jlcpcb next` whenever you are unsure what to do: it names+the step with open items and suggests what to do in it. A command answers `OK:`, with `FINDINGS` or `NOTE` lines when+a check found something (suggestions; the command still did its job), and `ERROR:` only when it could not run (a+missing file or argument, a desktop that does not answer). Every command goes in `<project>/jlcpcb-flow/run.jsonl`.+Pass `--ai-thread <you>` on every command that changes state. ``` adom-aiflow-jlcpcb init --release <board-release.json> --target <desktop> # or --board B.kicad_pcb --bom bom.csv@@ -38,7 +41,7 @@ adom-aiflow-jlcpcb report has `kicad/jlcpcb-2L|4L|6L.kicad_dru` (plus board setup JSON) and the same limits for Altium (`altium/*.RUL`) and Fusion (`fusion/*.dru`, `*.edru`). `rules` picks the file by the board's copper layer count and runs KiCad DRC on a copy of the board with the board's own rules first and JLCPCB's limits last, so only JLCPCB's minimums are judged- on top of the design's deliberate choices. `export` refuses until it passes. Design for JLCPCB from the start by+ on top of the design's deliberate choices. `export` still writes the package when it has not passed, and says so: fix what is real before you order. 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@@ -51,8 +54,10 @@ adom-aiflow-jlcpcb report - **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- the board or the BOM, never the CPL by hand. JLCPCB's preview is still the last word: screenshot every flagged part.+ every LCSC number and corrects the CPL. A part it cannot fit keeps KiCad's rotation and is reported (FAIL) and+ flagged for the preview; a FAIL usually means the wrong footprint or LCSC number, or a mirrored part. A placed part+ with no LCSC number is left out of the JLCPCB BOM and CPL and reported. JLCPCB's preview is the last word:+ screenshot every flagged part. - **Read the part's page first.** A component page may carry `jlcpcb-rotation.json` (schema `adom/jlcpcb-rotation@1`): the correction for an LCSC number on a KiCad footprint, with evidence counts (pad fits, preview screenshots, boards delivered, users). Add to it after your order (`share`).@@ -61,8 +66,9 @@ adom-aiflow-jlcpcb report human before a swap that changes behaviour (dielectric, colour). - **Search in Hydrogen, not on lcsc.com:** `adom-parts-search show "<spec>" --basic` puts the results in the Parts Search tab, on screen for the recording.-- **No money without the human's OK.** `approve` records their own words for one amount; `ordered` refuses without- it. Never write an approval they did not give.+- **No money without the human's OK.** That is you asking a person, not the binary blocking you: `approve` records+ their own words for one amount, and `quote`, `approve` and `ordered` say so when the amounts or the approval do not+ line up. Never write an approval they did not give. - **No moving mouse in the clips.** Drive JLCPCB's site with pup (`pup_eval`, `pup_input_dispatch`), which moves no OS cursor. The checkout clip shows addresses and account data: keep it private. - **Files go in with `pup_upload_file`** (pup 2.0.741 or later): `{selector, filePath}`. `filePath` is a path on the desktop, so `send_files` the file there first and pass where it landed (Downloads). With one file input on the page the selector can be left out; a hidden input is fine. `attached: true` means the page has the file, not that the site has taken it: wait for the site's own answer (JLCPCB shows the layer count and size it detected). Key and password files, AppData, hidden home folders, system folders and network paths are refused (`path_refused`). Check `pup_describe` for the verb first; on an older pup, ask the human to update Adom Bridge or to attach the file themselves, and don't stream the file through `pup_eval`.@@ -79,7 +85,7 @@ Default checks preserve the original ratings. A lower rating requires a document Keep quote alternatives in a separate BOM/run. Do not rewrite the released design or imply the quoted variant is manufacturing-qualified. Record the vendor's actual PCB, assembly, parts, attrition, shipping and tax breakdown; never feed a catalog subtotal into `quote` as if it came from checkout. Purchase still requires the user's approval. -Vendor 403/access errors are `retrieval-unverified`, not evidence of a missing footprint. Stop the footprint run on that failure and retain a failing rotation gate. Do not use a manual/no-footprint override to bypass a network problem. Resume after access works; verify the vendor placement preview before recording a complete quote.+Vendor 403/access errors are `retrieval-unverified`, not evidence of a missing footprint. Report those parts as not verified (they stay flagged for the preview). Do not use a manual/no-footprint override to bypass a network problem. Resume after access works; verify the vendor placement preview before recording a complete quote. ## Continue to the user's requested finish line @@ -107,4 +113,4 @@ The native path tries EasyEDA's regional service when the primary service fails ## Copper clearance coverage (issue #2) -Before trusting `rules`, inspect the downloaded profile's clearance rule. A condition limited to `A.type == 'track' && B.type == 'track'` does not test pad, via or zone gaps. Refuse to treat such a profile as fabrication verification. Use the reviewed all-copper JLC profile, retain any stricter board constraints, and run native DRC with the project's `.kicad_pro` and `.kicad_dru` sidecars present. Verify a known too-close pad pair is rejected; zero reported track violations is not evidence of acceptable pad spacing. The local issue repair includes a 0.09 mm B.Cu pad-pair regression at a 0.10 mm rule. Publication and installed availability must be verified separately.+Before trusting `rules`, inspect the downloaded profile's clearance rule. A condition limited to `A.type == 'track' && B.type == 'track'` does not test pad, via or zone gaps. Do not treat such a profile as fabrication verification. Use the reviewed all-copper JLC profile, retain any stricter board constraints, and run native DRC with the project's `.kicad_pro` and `.kicad_dru` sidecars present. Verify a known too-close pad pair is rejected; zero reported track violations is not evidence of acceptable pad spacing. The local issue repair includes a 0.09 mm B.Cu pad-pair regression at a 0.10 mm rule. Publication and installed availability must be verified separately.
src/export.rs+7−6@@ -8,8 +8,8 @@ //! <board>-bom-jlcpcb.csv Comment, Designator, Footprint, LCSC Part # (one row per LCSC number) //! <board>-cpl-jlcpcb.csv Designator, Mid X, Mid Y, Layer, Rotation //! <board>-fab-manifest.json sha256 of every file, the parts left out and why, the rotations applied-//! Parts whose BOM row says fit=post (contacts, machine pins, hand-fitted parts) stay out of the BOM and CPL; every-//! other placed reference must have an LCSC number, or the export refuses.+//! Parts whose BOM row says fit=post (contacts, machine pins, hand-fitted parts) stay out of the BOM and CPL. A placed+//! part with no LCSC number stays out too, listed in the manifest (leftOut.noLcsc) and reported as a finding. use crate::bridge::Bridge; use crate::csvio::{self, Table}; use crate::kicad::{g, ref_key};@@ -18,7 +18,7 @@ use serde_json::{json, Map, Value}; use std::collections::{BTreeMap, BTreeSet}; use std::path::{Path, PathBuf}; -pub struct Package { pub manifest: PathBuf, pub cpl: PathBuf, pub base: String, pub summary: String }+pub struct Package { pub manifest: PathBuf, pub cpl: PathBuf, pub base: String, pub summary: String, pub no_lcsc: Vec<String> } fn out_text(r: &Value) -> String { format!("{}{}", Bridge::field(r, "stdout").and_then(|v| v.as_str()).unwrap_or(""), Bridge::field(r, "stderr").and_then(|v| v.as_str()).unwrap_or(""))@@ -106,7 +106,8 @@ pub fn export(br: &Bridge, board: &Path, bom_path: &Path, out: &Path, rotations: fp_of.insert(rf, pkg); } let _ = std::fs::remove_dir_all(&tmp);- if !nolcsc.is_empty() { nolcsc.sort_by_key(|r| ref_key(r)); return Err(format!("no LCSC number for {} (add it to the BOM, or fit=post for parts fitted after assembly)", nolcsc.join(", "))); }+ // a placed part with no LCSC number stays out of the JLCPCB BOM and CPL (JLCPCB cannot place it); the caller reports it+ nolcsc.sort_by_key(|r| ref_key(r)); let mut refs: Vec<&String> = fp_of.keys().collect(); refs.sort_by_key(|r| ref_key(r)); let mut groups: Vec<(String, Vec<String>)> = Vec::new();@@ -127,14 +128,14 @@ pub fn export(br: &Bridge, board: &Path, bom_path: &Path, out: &Path, rotations: "made": crate::ledger::now(), "kicadCli": cli, "target": br.target, "gerbers": {"file": out_g.display().to_string(), "sha256": sha(&out_g), "files": names}, "bomJlcpcb": {"file": bom_out.display().to_string(), "sha256": sha(&bom_out), "lines": groups.len()}, "cplJlcpcb": {"file": cpl_out.display().to_string(), "sha256": sha(&cpl_out), "parts": cpl.len()},- "leftOut": {"fitPost": fitpost.iter().collect::<Vec<_>>()}, "rotationsApplied": applied, "log": log});+ "leftOut": {"fitPost": fitpost.iter().collect::<Vec<_>>(), "noLcsc": nolcsc}, "rotationsApplied": applied, "log": log}); let man_path = out.join(format!("{base}-fab-manifest.json")); std::fs::write(&man_path, serde_json::to_string_pretty(&man).unwrap() + "\n").map_err(|e| e.to_string())?; let mut fp: Vec<&String> = fitpost.iter().collect(); fp.sort_by_key(|r| ref_key(r)); let summary = format!("{base}-gerbers.zip ({} gerber/drill files), {base}-bom-jlcpcb.csv ({} lines), {base}-cpl-jlcpcb.csv ({} parts); left out (fitted after assembly): {}", man["gerbers"]["files"].as_array().map(|a| a.len()).unwrap_or(0), groups.len(), cpl.len(), if fp.is_empty() { "none".into() } else { fp.iter().map(|s| s.as_str()).collect::<Vec<_>>().join(" ") });- Ok(Package { manifest: man_path, cpl: cpl_out, base, summary })+ Ok(Package { manifest: man_path, cpl: cpl_out, base, summary, no_lcsc: nolcsc }) } /// The copper layer count of a board, from its layer table.
src/main.rs+34−24@@ -14,7 +14,7 @@ mod rotation; mod swap; use clap::{Parser, Subcommand};-use out::{err, ok};+use out::{err, findings, note, ok}; use serde_json::{json, Map, Value}; use sha2::{Digest, Sha256}; use std::path::{Path, PathBuf};@@ -102,12 +102,12 @@ fn bridge(p: &ledger::Project, th: &str) -> bridge::Bridge { bridge::Bridge { target, ai_thread: th.to_string() } } -/// Refuse when the board changed after the flow started: everything downstream would describe a different board.+/// Say so when the board changed after the flow started: everything downstream would describe a different board. fn same_board(p: &ledger::Project) { let b = board_of(p); let want = p.state["release"]["board"]["sha256"].as_str().unwrap_or(""); if !want.is_empty() && sha256_file(&b) != want {- err(&format!("{} changed since init (sha256 differs)", b.display()), &["Run init again on the new board (a new release); the export, preview and quote must all describe the board you order.".into()]);+ note(&format!("{} changed since init (sha256 differs)", b.display()), &["Run init again on the new board (a new release) so the export, preview and quote all describe the board you order.".into()]); } } @@ -116,7 +116,7 @@ fn flagged(p: &ledger::Project) -> Vec<String> { let man = latest_manifest(p).map(|m| read_json(&m)).unwrap_or(Value::Null); let rec = man["rotationCheck"]["file"].as_str().map(|f| read_json(Path::new(f))).unwrap_or(Value::Null); let mut out: Vec<String> = rec["parts"].as_array().into_iter().flatten()- .filter(|r| r["delta"].as_i64().unwrap_or(0) != 0 || matches!(r["status"].as_str(), Some("manual") | Some("no-jlc-footprint")))+ .filter(|r| r["delta"].as_i64().unwrap_or(0) != 0 || !matches!(r["status"].as_str(), Some("ok"))) .filter_map(|r| r["ref"].as_str().map(str::to_string)).collect(); out.sort_by_key(|r| kicad::ref_key(r)); out@@ -149,7 +149,7 @@ fn main() { let path = Path::new(&raw).canonicalize().unwrap_or_else(|_| err(&format!("the release's {k} is not here: {raw}"), &[])); let want = rel[k]["sha256"].as_str().unwrap_or("").to_string(); let have = sha256_file(&path);- if !want.is_empty() && want != have { err(&format!("{} changed since the release (sha256 differs)", path.display()), &["Finish the board again so the release names the board you mean to order.".into()]); }+ if !want.is_empty() && want != have { note(&format!("{} changed since the release (sha256 differs)", path.display()), &["Finish the board again so the release names the board you mean to order.".into()]); } rel[k] = json!({"path": path.display().to_string(), "sha256": have}); } let p = ledger::Project::create(&dir, FLOW_DIR, json!({"flow": fl.name, "release": rel, "target": target, "started": ledger::now()}))@@ -222,14 +222,14 @@ fn main() { "checks": rows.iter().map(|r| json!({"check": r.check, "pass": r.pass, "detail": r.detail, "info": r.info})).collect::<Vec<_>>(), "checkedAt": ledger::now(), "facts": facts, "notes": f["notes"]}); if *apply {- if !pass { write_json(&out, &res); p.log(&th, "swap", json!({"ref": reference, "verdict": "FAIL", "result": out})); err("not applied: the swap failed its checks", &[]); }+ if !pass { note(&format!("applying {reference} although the swap failed checks above (verdict FAIL is recorded)"), &["Apply a failed swap only when you have read both datasheets and the failed check does not matter here; say why in \"waive\" so the record carries it.".into()]); } let changed = swap::apply(&bom_of(&p), &f).unwrap_or_else(|e| err(&format!("BOM not rewritten: {e}"), &[])); res["bomRows"] = json!(changed); println!("BOM rows now {}: {}", cand["mpn"].as_str().unwrap_or(""), changed.join(", ")); } write_json(&out, &res); p.log(&th, "swap", json!({"ref": reference, "verdict": res["verdict"], "applied": apply, "result": out}));- if !pass { err(&format!("swap {reference}: FAIL (see the checks above); evidence {}", out.display()), &["Fix the facts only with what the datasheets say; a deliberate exception goes in \"waive\" with the reason.".into()]); }+ if !pass { findings(&format!("swap {reference}: FAIL (see the checks above){}; evidence {}", if *apply { ", applied anyway" } else { "" }, out.display()), &["Fix the facts only with what the datasheets say; a deliberate exception goes in \"waive\" with the reason. Or pick another candidate.".into()]); return; } ok(&format!("swap {reference} verified, evidence {}", out.display()), &[if *apply { String::new() } else { "Re-run with --apply to rewrite the BOM rows.".into() }]); } Cmd::Sourcing { why } => {@@ -252,9 +252,10 @@ fn main() { let mut absent: Vec<String> = fps.keys().filter(|r| !covered.contains(*r) && !r.starts_with('#')).cloned().collect(); absent.sort_by_key(|r| kicad::ref_key(r)); 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(", ")) },+ p.log(&th, "sourcing-open", json!({"noLcsc": missing, "noBomRow": absent}));+ findings(&format!("sourcing is not closed yet: {}{}", 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(", ")) }),- &["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()]);+ &["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()]); return; } 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();@@ -290,8 +291,9 @@ fn main() { "violations": errors.iter().take(50).map(|v| json!({"type": v["type"], "description": v["description"], "items": v["items"].as_array().map(|a| a.iter().map(|i| i["description"].clone()).collect::<Vec<_>>())})).collect::<Vec<_>>()})); p.log(&th, "rules", json!({"pass": pass, "rules": file, "errors": errors.len(), "unconnected": unconnected})); if !pass {- err(&format!("the board breaks JLCPCB's {n}-layer rules: {} errors ({}), {unconnected} unconnected; details in jlcpcb-flow/rules.json", errors.len(), kinds.iter().map(|(k, c)| format!("{k} x{c}")).collect::<Vec<_>>().join(", ")),- &["Fix the board in the board flow (adom-aiflow) and finish it again, then init this flow on the new release. A JLCPCB upgrade (smaller drills, tighter spacing) is a cost decision for the human.".into()]);+ findings(&format!("the board breaks JLCPCB's {n}-layer rules: {} errors ({}), {unconnected} unconnected; details in jlcpcb-flow/rules.json", errors.len(), kinds.iter().map(|(k, c)| format!("{k} x{c}")).collect::<Vec<_>>().join(", ")),+ &["Fix the board in the board flow (adom-aiflow) and finish it again, then init this flow on the new release. A JLCPCB upgrade (smaller drills, tighter spacing) is a cost decision for the human.".into(), "`export` still works: the package is written either way, with these findings in the ledger.".into()]);+ return; } ok(&format!("the board meets JLCPCB's {n}-layer rules ({from}/{file}): 0 errors, 0 unconnected, {} warnings", viol.len()), &[after_hint(&p, &fl)]); }@@ -304,7 +306,7 @@ fn main() { match (rules_ok, skip_rules) { (true, _) => {} (false, Some(why)) => p.log(&th, "rules-skipped", json!({"why": why})),- (false, None) => err("the board has not passed JLCPCB's design rules yet: run `rules`", &["`rules` runs KiCad DRC with JLCPCB's rules from adom/pcb-design-rules on a copy of the board. To export anyway, pass --skip-rules \"<why>\" (it goes in the ledger).".into()]),+ (false, None) => { p.log(&th, "rules-not-passed", json!({"rules": rules["pass"]})); note("the board has not passed JLCPCB's design rules (`rules`) for this board yet; exporting anyway", &["`rules` runs KiCad DRC with JLCPCB's rules from adom/pcb-design-rules on a copy of the board; run it before you order. --skip-rules \"<why>\" records why you went without it.".into()]); } } let br = bridge(&p, &th); let ov: Map<String, Value> = rotations.as_ref().map(|r| read_json(Path::new(r))).and_then(|v| v.as_object().cloned()).unwrap_or_default()@@ -313,6 +315,9 @@ fn main() { let pkg = export::export(&br, &board_of(&p), &bom_of(&p), &out, &ov).unwrap_or_else(|e| { p.log(&th, "export-failed", json!({"why": e})); err(&format!("export: {e}"), &[]) }); println!("OK: {}", pkg.summary); let mut hints = vec![];+ if !pkg.no_lcsc.is_empty() {+ findings(&format!("no LCSC number for {}: left out of the JLCPCB BOM and CPL, so JLCPCB will not place them", pkg.no_lcsc.join(", ")), &["Find each one's LCSC number with `adom-jlcpcb search \"<mpn>\"` (try it without hyphens too), put it in the BOM's lcsc column and export again; or mark parts you will fit yourself fit=post.".into()]);+ } if !*no_rotation_check { let bom = csvio::Table::read(&bom_of(&p)).unwrap_or_else(|e| err(&format!("BOM: {e}"), &[])); if browser_target.is_some() != browser_profile.is_some() { err("native browser recovery needs both --browser-target and --browser-profile", &[]); }@@ -321,7 +326,8 @@ fn main() { let rec_path = out.join(format!("{}-jlc-rotation.json", pkg.base)); write_json(&rec_path, &c.record); let applied = c.failed.is_empty();- if applied { rotation::apply(&pkg.cpl, &c.record).unwrap_or_else(|e| err(&format!("CPL not corrected: {e}"), &[])); }+ // every correction that was found goes in; a part the check could not fit keeps KiCad's rotation and is flagged+ rotation::apply(&pkg.cpl, &c.record).unwrap_or_else(|e| err(&format!("CPL not corrected: {e}"), &[])); println!("{}", rotation::summary(&c, applied)); for (r, w) in &c.failed { println!(" FAIL {r}: {w}"); } for (r, w) in &c.warned { println!(" WARN {r}: {w}"); }@@ -336,9 +342,10 @@ fn main() { p.log(&th, "export", json!({"manifest": pkg.manifest, "rotationCheck": man["rotationCheck"]})); if !applied { let retrieval = parts.iter().any(|r| r["status"] == "retrieval-unverified");- err("the JLCPCB rotation check failed (see above); the CPL was NOT corrected", &[if retrieval {- "Vendor footprint retrieval failed. Restore access and retry; do not relabel this as no footprint, change valid board geometry, or bypass the rotation gate.".into()- } else { "Pad-fit failure requires a manufacturer-drawing review: check repeated pads, electrical versus physical terminal numbering, land-pattern dimensions, wrong parts and mirroring. Repair the checker or design as supported by evidence; never relax tolerance or edit the CPL just to pass.".into() }]);+ let failed: Vec<String> = c.failed.iter().map(|(r, _)| r.clone()).collect();+ findings(&format!("the JLCPCB rotation check could not confirm {} (see FAIL above): the CPL has every correction that was found, and these parts keep KiCad's rotation", failed.join(", ")), &[if retrieval {+ "Vendor footprint retrieval failed for some parts: restore access (or --browser-target/--browser-profile) and export again; until then check those parts' pin 1 by eye in JLCPCB's preview.".into()+ } else { "A pad-fit failure usually means repeated pads, electrical versus physical pad numbering, a different land pattern, a wrong part or mirroring: compare the manufacturer's drawing, and check pin 1 on each in JLCPCB's preview. A --rotations override records a rotation you confirmed by eye.".into() }]); } let fl_refs = flagged(&p); if !fl_refs.is_empty() { hints.push(format!("In JLCPCB's placement preview, look at pin 1 on {} and save a screenshot of each with `preview --png <file> --refs <refs>`.", fl_refs.join(", "))); }@@ -352,7 +359,7 @@ fn main() { Cmd::Preview { png, refs, note } => { let th = thread(&cli); let p = project(&cli);- if !flow::complete(&p.flow_dir,"export") { err("export is not verified; finish the rotation check first", &[after_hint(&p,&fl)]); }+ if !flow::complete(&p.flow_dir,"export") { out::note("the export is not fully verified yet (sourcing, rules or the rotation check left findings); saving the preview anyway", &[after_hint(&p,&fl)]); } let src = Path::new(png); if !src.is_file() { err(&format!("{png}: no such file"), &[]); } let name = format!("{}-{}.png", refs.replace([',', ' '], "-"), &sha256_file(src)[..8]);@@ -376,12 +383,12 @@ fn main() { let th = thread(&cli); let p = project(&cli); same_board(&p);- if !flow::complete(&p.flow_dir,"preview") { err("verified export and complete placement preview required before quote", &[after_hint(&p,&fl)]); }+ if !flow::complete(&p.flow_dir,"preview") { out::note("the export or the placement preview still has open items; recording the quote anyway", &[after_hint(&p,&fl)]); } if !total.is_finite() || *total <= 0.0 { err("quote total must be finite and positive", &[]); } let doc = read_json(&p.path("preview.json")); let seen: std::collections::BTreeSet<String> = doc["shots"].as_array().into_iter().flatten().flat_map(|s| s["refs"].as_array().cloned().unwrap_or_default()).filter_map(|r| r.as_str().map(str::to_string)).collect(); let left: Vec<String> = flagged(&p).into_iter().filter(|r| !seen.contains(r)).collect();- if !left.is_empty() { err(&format!("no placement-preview screenshot yet for {}", left.join(", ")), &["These parts were corrected or have no JLCPCB footprint: look at pin 1 on each in JLCPCB's preview and save it with `preview` before quoting.".into()]); }+ if !left.is_empty() { out::note(&format!("no placement-preview screenshot yet for {}", left.join(", ")), &["These parts were corrected, could not be fitted or have no JLCPCB footprint: look at pin 1 on each in JLCPCB's preview and save it with `preview`, and tell the human which ones were not checked before they approve.".into()]); } write_json(&p.path("quote.json"), &json!({"total": total, "currency": currency, "quoteId": quote_id, "note": note, "previewSha256": sha256_file(&p.path("preview.json")), "at": ledger::now(), "boardSha256": sha256_file(&board_of(&p))})); p.log(&th, "quote", json!({"total": total, "currency": currency, "quoteId": quote_id})); ok(&format!("quote {total:.2} {currency} recorded"), &["Show the human the total and what it buys, and wait for their explicit OK in their own words before anything is paid. Then record it with `approve`.".into()]);@@ -389,10 +396,13 @@ fn main() { Cmd::Approve { by, amount, words } => { let th = thread(&cli); let p = project(&cli);- if !flow::complete(&p.flow_dir,"quote") { err("current verified quote required before approval", &[after_hint(&p,&fl)]); }+ if !flow::complete(&p.flow_dir,"quote") { note("the quote is not current for this board and export (or there is none); recording the approval anyway", &[after_hint(&p,&fl)]); } let q = read_json(&p.path("quote.json"));- let total = q["total"].as_f64().unwrap_or_else(|| err("no quote yet: `quote` first", &[]));- if (total - amount).abs() > 0.005 { err(&format!("the approval is for {amount:.2} but the quote is {total:.2}"), &["Approval covers one amount. Show the human the current total and ask again.".into()]); }+ match q["total"].as_f64() {+ None => note("no quote recorded: the approval is not tied to a total", &["Record JLCPCB's total with `quote` so the order report shows what the human approved against.".into()]),+ Some(total) if (total - amount).abs() > 0.005 => note(&format!("the approval is for {amount:.2} but the quote is {total:.2}"), &["An approval covers one amount: show the human the current total and ask again before paying.".into()]),+ _ => {}+ } if words.trim().len() < 2 { err("record the human's own words", &[]); } write_json(&p.path("approval.json"), &json!({"by": by, "amount": amount, "currency": q["currency"], "words": words, "aiThread": th, "at": ledger::now()})); p.log(&th, "approve", json!({"by": by, "amount": amount, "words": words}));@@ -402,8 +412,8 @@ fn main() { let th = thread(&cli); let p = project(&cli); let (q, a) = (read_json(&p.path("quote.json")), read_json(&p.path("approval.json")));- if a.is_null() { err("no recorded approval: nothing may be paid without the human's OK (`approve`)", &[]); }- if (q["total"].as_f64().unwrap_or(-1.0) - a["amount"].as_f64().unwrap_or(-2.0)).abs() > 0.005 { err("the approval does not match the quote", &[]); }+ if a.is_null() { note("no approval recorded for this order", &["Paying is the human's decision: if they OK'd it, record their words with `approve`; if they did not, tell them now.".into()]); }+ else if (q["total"].as_f64().unwrap_or(-1.0) - a["amount"].as_f64().unwrap_or(-2.0)).abs() > 0.005 { note("the recorded approval does not match the quote", &["Tell the human the amount that was paid and the amount they approved.".into()]); } write_json(&p.path("order.json"), &json!({"order": order, "total": q["total"], "currency": q["currency"], "approvedBy": a["by"], "at": ledger::now(), "boardSha256": sha256_file(&board_of(&p))})); p.log(&th, "ordered", json!({"order": order})); ok(&format!("order {order} recorded"), &["When the boards arrive and have been tried: `delivered --boards N --working N`.".into()]);
src/out.rs+15−1@@ -1,11 +1,25 @@ //! Every command answers the AI the same way: `OK: <what happened>` or `ERROR: <what is wrong>`,-//! then `Hint:` lines that depend on this project and this run. Exit 1 on ERROR.+//! then `Hint:` lines that depend on this project and this run. Exit 1 on ERROR, which means only "I could not run".+//! What a check finds is a FINDINGS or NOTE line with suggestions: the AI and the human decide (a dynamic skill). pub fn ok(msg: &str, hints: &[String]) { println!("OK: {msg}"); for h in hints.iter().filter(|h| !h.is_empty()) { println!("Hint: {h}"); } } +/// A check found something: say what and suggest the fix. Never a stop: exit 0 (a dynamic skill is a guide, not a gate).+pub fn findings(msg: &str, hints: &[String]) {+ println!("FINDINGS (suggestions, nothing is blocked): {msg}");+ for h in hints.iter().filter(|h| !h.is_empty()) { println!("Suggestion: {h}"); }+}++/// A check in front of an action: say what it found and carry on with the action.+pub fn note(msg: &str, hints: &[String]) {+ println!("NOTE (a suggestion, not a stop): {msg}");+ for h in hints.iter().filter(|h| !h.is_empty()) { println!("Suggestion: {h}"); }+}++/// Only for "I could not run" (a missing file or argument, a tool that does not answer), with what to try next. pub fn err(msg: &str, hints: &[String]) -> ! { println!("ERROR: {msg}"); for h in hints.iter().filter(|h| !h.is_empty()) { println!("Hint: {h}"); }
Comments
Log in to comment.
No comments yet.