Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
11b8da784This file is pinned to the selected release. Download the original to open it in your design tool.
#!/usr/bin/env python3
"""Build the packet our experts audit before we release the app.
Run: scripts/review-packet [--out review-packet]
## What this is, and what it is not
**It is not a step in the product.** Autonomous Circuit produces fab-ready
boards with no human in the loop: a user describes a gadget and orders the
result, and no engineer signs anything along the way. That is the point of the
tool, and this packet does not change it.
This is a one-time **audit of our engineering before launch** — our experts read
what we built and say whether it is fit to put in front of strangers. It is the
same shape as reviewing a compiler before shipping it: you audit the standard
library once, at build time. You do not station a human beside every compile.
## The question the reviewers are answering
One question, in the end: *would you let a non-engineer use this unsupervised
and order the boards it produces?*
Everything here is evidence for or against that. The golden blocks carry the
most weight, for two reasons. They are the foundation every generated board
inherits — and they hold the one class of error our automated checking provably
cannot see, because a wrong value or a mirrored pinout looks identical to a
correct one in every render, export and DRC report, all of which derive from the
same source. Auditing them once is how that foundation earns its trust. After
that they are frozen, and no user ever touches them.
## The shape of the ask
A reviewer asked "does this look right?" writes back "looks good", which is
worth nothing and is the question's fault. So every sheet asks questions that
can come back **no**, each naming a specific thing to check against a specific
authority: a datasheet, the fab's published capability table, a measurement.
"""
from __future__ import annotations
import argparse
import json
import shutil
import sys
from collections import Counter
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
BLOCKS_DIR = REPO / "packages" / "golden-blocks" / "blocks"
EXAMPLES_DIR = REPO / "examples"
# Per-board artifacts copied into the packet, and why an EE needs each one.
BOARD_ARTIFACTS = {
"main_fab/gerbers.zip": "what the fab actually builds",
"main_fab/bom.csv": "every line, with LCSC part numbers",
"main_fab/cpl.csv": "placement and rotation for assembly",
"main_fab/kicad-project.zip": "open it in KiCad and run your own DRC",
"main_fab/board.glb": "3D, for enclosure fit",
"main_review/_schematic.png": "the schematic",
"main_review/_pcb.png": "the layout",
}
def load_sidecar(board_dir: Path) -> dict:
try:
return json.loads((board_dir / "main.board.json").read_text())
except Exception:
return {}
def blocking(sidecar: dict) -> list[dict]:
warnings = sidecar.get("validation", {}).get("warnings", [])
return [w for w in warnings if w.get("severity") == "error"]
def block_sheet(block_id: str, block_md: str) -> str:
"""The per-block sign-off. This is the important one."""
return f"""# Block sign-off — `{block_id}`
**This block goes into every board a user generates that needs it**, unchanged —
the AI composes blocks, it never edits them. So an error here is not one bad
board, it is a bad board every time. It is also the specific class of error our
automated checks provably cannot catch, which is why this sheet matters more
than any individual board in the packet. Anything you find gets fixed once and
is then right forever.
Source: [`{block_id}.tsx`](./{block_id}.tsx) · Datasheet: [`BLOCK.md`](./BLOCK.md)
## Check these against the part datasheets, not against our documentation
Our `BLOCK.md` and our source can be wrong in the same way at the same time —
they were written together. Please check against the manufacturer's datasheet
and the LCSC listing.
| # | Question | Verdict |
|---|---|---|
| 1 | Is **every component value** correct for this circuit — not merely plausible? | pass / **fail** |
| 2 | Is **every polarity** right? Diodes, electrolytics, ICs. | pass / **fail** |
| 3 | Does **every pin number** match the datasheet's pinout, in the datasheet's own numbering? | pass / **fail** |
| 4 | Is the **land pattern** right for the package actually ordered (IPC density, thermal pad, paste)? | pass / **fail** |
| 5 | Is each **LCSC part** the right part — and a sane choice for cost, stock and lifecycle? | pass / **fail** |
| 6 | Is the **decoupling** adequate in value, count and placement? | pass / **fail** |
| 7 | Does the block behave at its **stated limits** — the rail budget and current draw in `BLOCK.md`? | pass / **fail** |
| 8 | What does this block do that is **wrong at the edges** — brown-out, inrush, hot-plug, ESD, thermal? | notes |
## Anything you would have done differently
Not a defect, but worth recording — if it is a real preference we should encode
it as a default, because a user will never know to ask for it.
```
```
## Verdict
- [ ] **Approved** — safe to compose into user boards as-is
- [ ] **Approved with changes** — listed above, must land before release
- [ ] **Rejected** — do not release with this block in the catalog
Reviewer: ______________________ Date: ____________
---
## The block's own datasheet, for reference
{block_md}
"""
def board_sheet(name: str, sidecar: dict, errors: list[dict]) -> str:
fab = sidecar.get("fab", {})
ready = fab.get("ready")
warnings = sidecar.get("validation", {}).get("warnings", [])
kinds = Counter(w.get("kind", "?") for w in warnings)
if errors:
status = (
f"**Not orderable — {len(errors)} blocking finding"
f"{'s' if len(errors) != 1 else ''}.**\n\n"
+ "\n".join(
f"- `{e.get('kind')}` — {e.get('part') or 'board'}: {e.get('detail')}"
for e in errors
)
+ "\n\nWe already know about these, so there is nothing to approve "
"here yet. What we want from you is whether the blocking list is "
"**complete** — a defect we are missing is worth far more to us "
"than one we have already found."
)
else:
status = (
"**The tool says this board is orderable:** zero error-severity "
"findings, and gerbers independently produced by `kicad-cli` from "
"the same file KiCad ran DRC against.\n\nThat is our claim. This "
"review is where it gets tested by someone who did not build it."
)
top = "\n".join(
f"| `{kind}` | {count} |" for kind, count in kinds.most_common(8)
) or "| (none) | 0 |"
return f"""# Board sign-off — {name}
{status}
## What is in this folder
| File | What it is |
|---|---|
{chr(10).join(f'| [`{rel}`](boards/{rel}) | {why} |' for rel, why in BOARD_ARTIFACTS.items())}
Also here: [`boards/main.tsx`](boards/main.tsx) (the board, as code) and
[`findings.json`](findings.json) (every finding, in full).
**Start with [`kicad-project.zip`](boards/main_fab/kicad-project.zip).** Open it in KiCad, run DRC with your own
rules, and look at the board in a tool we did not write. If our checks and
yours disagree, that disagreement is the most valuable output of this review.
## All findings by kind
`fab.ready = {ready}` · {len(warnings)} findings total, {len(errors)} blocking.
| Kind | Count |
|---|---|
{top}
Non-blocking findings are in `findings.json` here, in full. Some are noise from
our own converter and are labelled as such — **please challenge that labelling**
if any of it looks like a real defect we have talked ourselves out of.
## Questions
| # | Question | Verdict |
|---|---|---|
| 1 | Would you let a **non-engineer** order this unsupervised? | yes / **no** |
| 2 | When it arrives, will it **power up**? Rails, sequencing, brown-out, boot straps. | yes / **no** |
| 3 | Can it be **brought up and debugged** — test points, reset access, an LED that proves power? | yes / **no** |
| 4 | Will the **assembly house** build it right first time — rotations, polarity marks, part availability? | yes / **no** |
| 5 | Does the **layout** hold up — return paths, decoupling placement, trace widths, thermals? | yes / **no** |
| 6 | Does it **fit the product** — connector positions, mounting, enclosure interface? | yes / **no** |
| 7 | What did our checks **miss**? | notes |
Question 7 is the one we most want answered.
## Verdict
- [ ] **Approved to manufacture**
- [ ] **Approved after listed changes**
- [ ] **Rejected**
Reviewer: ______________________ Date: ____________
"""
def approval_doc(boards: list[tuple[str, int]], block_ids: list[str]) -> str:
board_rows = "\n".join(
f"| [{name}]({name}/REVIEW.md) | "
+ (f"{n} blocking" if n else "clean")
+ " |"
for name, n in boards
)
block_rows = "\n".join(
f"| [`{b}`](../packages/golden-blocks/blocks/{b}/REVIEW.md) | frozen · composed into user boards unchanged |"
for b in block_ids
)
return f"""# Autonomous Circuit — expert review before we release the app
We built a tool that lets people who are not electrical engineers design a
circuit board by describing it, and order the result. **It runs with no engineer
in the loop** — that is the product, not a gap in it. A user types what they
want, approves a plan, and receives a fab packet.
We are asking you to audit that work before we put it in front of strangers.
## The question
> **Would you let a non-engineer use this unsupervised and order the boards it
> produces?**
Everything below is evidence for or against that one question. A "no" with a
reason is the most useful thing you can send back.
To be explicit about what this review is *not*: it is not a step in the product,
and nobody is proposing an engineer sign off on user boards. This is the same
shape as reviewing a compiler before shipping it — you audit the standard
library once, at build time; you do not station a human beside every compile.
## Five things to look at, in order of how much they matter
### 1. The nine golden blocks ← the foundation
| Block | Role |
|---|---|
{block_rows}
**Why these carry the most weight.** No deterministic check catches a wrong
resistor value, a mirrored pinout, or swapped SDA/SCL — every representation we
produce (schematic, PCB render, 3D, gerbers, DRC report) derives from the same
source, so when the source is wrong they all agree with each other, confidently.
The board looks perfect and does not work, and you find out in two weeks.
Our answer to that class of error is that these values are never generated. They
live in nine frozen blocks the AI composes and never edits, so the risk
concentrates here instead of spreading across every board. **That design is only
as good as this audit** — which is why the blocks come before the boards.
Whatever you find gets fixed once and is then correct in every board the tool
ever produces.
Each folder has the source, the block's datasheet, and a sign-off sheet asking
specific questions against the manufacturer's datasheet. Please check against
the datasheet rather than our documentation — our docs and our source were
written together and can be wrong together.
### 2. The rules the tool enforces
[`docs/review/fab-limits.md`](../docs/review/fab-limits.md) is every number our DFM gate
checks, with the value and what it is checked against. If one of these numbers
is wrong, every board the tool ever produces is graded against a wrong rule.
Please check them against JLCPCB's published capabilities.
[`docs/review/safety-envelope.md`](../docs/review/safety-envelope.md) is what the tool refuses
to design, at planning time, before anything is built.
### 3. Three boards the tool produced
| Board | State |
|---|---|
{board_rows}
These are evidence, not deliverables — nobody is asking you to approve three
boards. They are here because they are the only way to see what the tool
actually emits, end to end, on real products we intend to build.
Each folder has gerbers, BOM, CPL, a KiCad project you can open and run your own
DRC on, and the full finding list. **Please run your own DRC.** Where your tool
disagrees with ours is the single most valuable thing this review can produce,
because it means one of us has a bug and we currently think it is not us.
### 4. Whether it holds for boards nobody has designed
Three good boards prove the tool works three times. Releasing it as an app is a
claim about the boards a stranger will ask for next week, and that claim rests
on two measured numbers rather than on these examples:
- **Composition closure** — the share of legal block combinations that build
clean, each as a real board through the real pipeline. Every block passes
alone; this asks whether they pass *together*.
- **First-build fab-ready rate** — the tool given briefs it has never seen, an
empty directory each, no human turn.
Current values are in [`docs/lessons.md`](../docs/lessons.md) and the night logs, and move daily. The
question for you: **what would those numbers have to be before you would
release this?** We would rather have your threshold now than argue about ours
later.
### 5. The claim we make to users
The tool tells a user a board is "ready to order" when it has zero
error-severity findings and gerbers independently produced by `kicad-cli` from
the file KiCad checked. Is that bar high enough to put in front of someone who
cannot evaluate a board themselves? If not, what is missing from it?
## What we are not asking
- Not asking you to design anything, or to fix what you find. Finding it is the
work; we will fix it.
- Not asking you to read our code. Judge the engineering, not the
implementation — the pipeline, the agents and the tests are our problem.
- Not asking for a rubber stamp. **A block you reject is a better outcome for us
than a block you wave through**, because the first costs a week and the second
ships in every board a stranger orders.
- Not asking you to be in the loop afterwards. Once this is fixed and released,
the tool runs without an engineer, which is the entire point.
## How to record a verdict
Fill in the sheets in place — each has a verdict block at the bottom — or reply
with the block or board id and your notes, whichever is faster. Findings routed
back to us as "must fix before launch" versus "should fix later" is the
distinction we most need.
## What we do with it
Everything you find becomes structural, not advice. A wrong value gets fixed in
the block and pinned with your name and the date. A rule you correct gets fixed
in the fab profile, which is the single place every board is graded against. A
defect class you point out that we cannot currently catch becomes a new check
plus a permanent entry in the failure corpus, paired with the legal geometry
just the other side of the line, so it cannot regress quietly.
If you would have done something differently but it is not a defect, say so
anyway. A preference an expert holds and a user will never know to ask for is
exactly what should become a default.
"""
def fab_limits_doc() -> str:
"""Read the limits out of the fab profile so the doc cannot drift from code."""
sys.path.insert(0, str(REPO / "packages" / "circuitpy" / "src"))
try:
from circuitpy import fab as fab_mod # type: ignore
profile = fab_mod.get_profile("jlcpcb")
# Numbers only. Output filenames live on the same profile object and
# are not rules — asking an EE to check `bom.csv` wastes the attention
# we want on `min_pth_to_copper_mm`.
fields = [
(name, getattr(profile, name))
for name in sorted(dir(profile))
if not name.startswith("_")
and isinstance(getattr(profile, name, None), (int, float))
and not isinstance(getattr(profile, name, None), bool)
]
rows = "\n".join(f"| `{n}` | {v} |" for n, v in fields)
source = "Read live from `circuitpy.fab.get_profile('jlcpcb')`."
except Exception as exc: # pragma: no cover - packet must still build
rows = "| (could not load the profile) | |"
source = f"Could not import the fab profile: {exc}"
return f"""# The rules the tool enforces
{source} These are the numbers every board is graded against — if one is wrong,
every board the tool produces is graded against a wrong rule, including boards
nobody has designed yet.
**Please check these against JLCPCB's published capability table**, not against
our documentation.
| Rule | Value |
|---|---|
{rows}
Two-band by design: `min_*` blocks a board from being called orderable, `warn_*`
is a preference we surface but do not enforce. If you think something currently
in the warn band should block — or the reverse — that is exactly the kind of
call we want from you.
One we already know is subtle: a copper pour cuts a 32-sided polygon around each
hole, so a nominal 0.2mm margin measures 0.1976mm at the chord midpoints and the
fab's own DRC calls it a violation. The tool now derives a safe default from the
segment count. Please sanity-check that reasoning.
"""
SAFETY_DOC = """# The safety envelope
Refused at planning time — in the plan, before any toolchain process runs, so a
refused design never becomes files on disk.
- **No mains voltage, ever.** Low-voltage DC, 24V or less, only.
- **Battery power only through a sealed, validated charge/protect block.** No
such block exists yet, so the tool currently refuses battery designs outright.
The slot is deliberately empty rather than filled with something plausible —
lithium charging is a fire risk and we would rather refuse than guess.
- **Radio only as pre-certified modules.** No discrete RF design.
## Questions
| # | Question | Verdict |
|---|---|---|
| 1 | Is this envelope **tight enough** to put in front of a non-engineer? | yes / **no** |
| 2 | What should be **added** to it? | notes |
| 3 | Is anything here **too strict** — refusing work we could do safely? | notes |
| 4 | When a battery block does exist, what must it prove before it ships? | notes |
Question 4 is the one we would like answered before we build that block, rather
than after.
"""
def main() -> int:
"""Write the review sheets in place, so a GitHub link is the packet.
An earlier version built a separate directory and zipped it. Dee wanted a
link he can send, and a zip is not a link — so the sheets now live beside
the thing they review. `examples/<project>/REVIEW.md` sits next to that
board's own gerbers, BOM and KiCad project; each block's sheet sits next to
its source. Nothing is copied, so nothing can go stale against the original.
"""
ap = argparse.ArgumentParser(description=__doc__)
ap.parse_args()
# --- one sheet per block, beside its source ---
block_ids = sorted(d.name for d in BLOCKS_DIR.iterdir() if d.is_dir())
for bid in block_ids:
src = BLOCKS_DIR / bid
md_path = src / "BLOCK.md"
md = md_path.read_text() if md_path.exists() else ""
(src / "REVIEW.md").write_text(block_sheet(bid, md))
# --- one sheet per board, beside its artifacts ---
boards: list[tuple[str, int]] = []
for ex in sorted(p for p in EXAMPLES_DIR.iterdir() if p.is_dir()):
board_dir = ex / "boards"
if not (board_dir / "main.board.json").exists():
continue
sidecar = load_sidecar(board_dir)
errors = blocking(sidecar)
boards.append((ex.name, len(errors)))
(ex / "REVIEW.md").write_text(board_sheet(ex.name, sidecar, errors))
(ex / "findings.json").write_text(
json.dumps(sidecar.get("validation", {}).get("warnings", []), indent=2)
)
rules = REPO / "docs" / "review"
rules.mkdir(parents=True, exist_ok=True)
(rules / "fab-limits.md").write_text(fab_limits_doc())
(rules / "safety-envelope.md").write_text(SAFETY_DOC)
(EXAMPLES_DIR / "README.md").write_text(approval_doc(boards, block_ids))
n_unready = sum(1 for _, n in boards if n)
print(f" {len(block_ids)} block sheets -> packages/golden-blocks/blocks/*/REVIEW.md")
print(f" {len(boards)} board sheets -> examples/*/REVIEW.md")
print(f" rules -> docs/review/")
print(f"\n SHARE THIS → https://github.com/autonomous-ai/autonomous-circuit/tree/main/examples")
if n_unready:
print(
f"\n WARNING: {n_unready} board(s) still have blocking findings. "
"Not ready to share."
)
return 0
if __name__ == "__main__":
raise SystemExit(main())