Loading files
## Context
Everything under `src/pcb` was built and measured for two copper layers (B1 to B4, ADRs 0001 to 0010). Facts on the reference machine that shape this design:
- KiCad writes two copper numberings. The golden boards (generated by `bench/golden/generate.ts`) and most PCBench files carry the legacy one: F.Cu 0, In1.Cu 1 … B.Cu 31. KiCad 10 writes F.Cu 0, B.Cu 2, In1.Cu 4, In2.Cu 6, In3.Cu 8 … (the `cm5_minima` and `kit-dev-coldfire` demos). `layerTable()` in `import.ts` sorts copper by number, which puts B.Cu second on a KiCad 10 four-layer board; `emitDsn` uses file order; `svg.ts` draws a hard-coded `['B.Cu', 'F.Cu']`.
- `connectivity.ts` gives a via the layers `[from, to]` only. A through via on a four-layer board therefore never joins In1.Cu or In2.Cu copper: Freerouting's four-layer `completion` run reported 0 unrouted and the verifier 17 %.
- `returnpath.ts` finds the bottom copper by `side === 'back'` and measures signal length on it; the scoring profile weights `bottom_signal_length_nm` and `pour_largest_share` at 0.15 each. On a four-layer board with internal planes those terms measure the wrong thing.
- Fabrication data: kicad-tools' `jlcpcb.yaml` (vendored source of ADR 0006) carries `4_layer` and `6_layer` values for clearance (0.1016 mm, 0.0889 mm), minimum track (0.1016 mm 1 oz, 0.0889 mm), and via drill (0.2 mm at four layers and up); everything else (edge and hole clearances, mask, silk, annular ring) is shared.
- kicad-tools `kct route` takes `--layers {2,4,4-sig,4-all,6}`; the adapter passes `2`. Freerouting reads every `(layer …)` in the DSN and honours per-layer `layer_rule` directions. OrthoRoute (ADR 0010) routes only on inner layers, `minLayers: 4`.
## Goals / Non-Goals
**Goals:**
- Any two-, four-, or six-layer board with through vias goes through import, placement, routing, verification, scoring, evidence, and rendering with the same guarantees the two-layer path has, and every two-layer number reproduces byte for byte.
- One source of truth for the copper stack, consumed everywhere.
- Fail closed on what is not supported: more than six layers, blind or buried vias, a profile that disagrees with the board.
- Multilayer golden boards with seeded faults and a bench suite, so the claim is measured, not asserted.
**Non-Goals:**
- Blind and buried vias, microvias, via-in-pad on multilayer.
- Per-layer track widths, impedance, stackup materials, plane splitting, layer-pair assignment by net class.
- A multilayer placer: placement is layer-agnostic and stays so.
- Changing the two-layer scoring profile or any two-layer expectation.
## Decisions
**D1. The stack is derived from layer names, not numbers.** `copperStack(design)` returns `[F.Cu, In1.Cu … InN.Cu, B.Cu]` by matching the canonical names (`F.Cu`, `In(\d+).Cu`, `B.Cu`) and sorting inner layers by their index; numbers are kept on `LayerDefinition.ordinal` for the exporter only. Alternative considered: mapping both numberings to a canonical index. Rejected because a third numbering (or a user-renamed layer) would break silently, while names are what every other tool in the chain (KiCad, Specctra, kicad-tools, OrthoRoute) keys on. A copper layer whose name matches neither pattern makes pre-flight refuse the board (`preflight.stack`), as does a stack longer than six.
**D2. Via span is explicit and through-only.** `Via.layers` stays `[from, to]` in the IR (that is what KiCad stores) and a helper `viaSpan(via, stack)` expands it to the stack slice; connectivity unions on the slice, geometry requires the slice to be the whole stack on this change (`geom.via-layers` otherwise), and `candidateFromRouting` maps any engine via to the outer pair, so an engine cannot smuggle a buried via into a candidate: if an engine result carries a via whose ends are not the outer layers the runner marks the invocation `INVALID_OUTPUT` with the via named. Alternative: accept blind/buried as declared by `capabilities.blindBuriedVias`. Deferred: no profile carries the cost or rules for them yet, and no wrapped engine produces them under our DSN.
**D3. Profiles are selected by copper count and disagree loudly.** `loadProfileFor(design)` returns the configured profile when one is named and its `layers` equals the stack length; refuses at pre-flight (`preflight.profile`) when they differ; and defaults to `jlcpcb-{2,4,6}layer` by count. The two new profiles are typed copies vendored beside the JSON with the same provenance block as `jlcpcb-2layer`, values taken from the `4_layer` / `6_layer` keys, and the shared values copied unchanged; the existing equality test covers them. Alternative: one profile parameterised by layer count. Rejected: the profile is the fabricator's published capability table, and JLCPCB publishes them per stackup; a derived profile would hide which numbers were checked against the source.
**D4. Scoring on four and six layers drops the bottom-layer terms and renormalises.** `default-low-speed-4-layer` and `-6-layer` are the two-layer profile without `bottom_signal_length_nm` and `pour_largest_share`, weights renormalised to sum to one, `higherIsBetter` reduced accordingly; `returnpath.ts` emits its metrics only when the stack has two layers, so the checker's metrics stay honest rather than measuring signal on a plane layer. Selection by stack length in `routeBoard`/`placeBoard` unless `--scoring` names one. Alternative: a plane-integrity metric (fragment count of the inner plane fills). Named as the next step; not built here because no wrapped engine pours inner planes and the metric would read zero everywhere.
**D5. Engines get the layer count from the stack, and a default inner-layer strategy.** kicad-tools: `--layers` from the stack length (2, 4, 6; the `4-sig`/`4-all` variants are not used, kct decides plane use itself). Freerouting: no DSN change beyond the stack order; `defaultStagedPlan` gains a default `layers` strategy for four and six layers, inner layers alternating `horizontal`/`vertical` starting horizontal on In1.Cu, outer layers with no preference, overridden by `routing.layers` in the intent file (already parsed as `layerPreferences`). OrthoRoute: eligible by its manifest; nothing else. Reference router: `maxLayers: 2` added to its manifest so the harness fixture never pretends. Alternative: let each adapter count layers itself. Rejected: the stack helper is the single source (D1).
**D6. The renderer draws the stack bottom-up.** Inner layers get fixed colours (In1 green-ish, In2 violet, In3 teal, In4 brown), drawn after B.Cu and before F.Cu at lower opacity, through-hole pads drawn once, and the legend lists the layers present. Thumbnails unchanged in size.
**D7. Golden multilayer cases use the KiCad 10 numbering and seed one fault each.** `generate.ts` takes `layers: 2 | 4 | 6` per case, emits the new numbering for four and six (`(2 "B.Cu")`, `(4 "In1.Cu")` …), keeps the legacy numbering for the existing two-layer cases so their bytes do not change, and writes the `.kicad_pro` with the matching profile name. Cases: `four-layer` (the `completion` netlist on four layers, expected PASS with inner copper allowed), `six-layer` (the `congestion` netlist on six layers, expected PASS: the channel is no longer a bottleneck), `via-span` (four layers with a seeded `In1.Cu`-`In2.Cu` via, expected REFUSE with `geom.via-layers`). Expected DRC recorded from `kicad-cli` like the others.
**D8. Corpus.** `bench/corpora/pcbench.sh` gains a `pcbench-4layer` suite: the permissively licensed four-layer PCBench boards that upgrade and pass KiCad 10 DRC (the sweep in ADR 0003 counted 126 four-layer boards before licensing); the suite JSON records the sweep the way `pcbench-qual` does. Routing bench only (track B); placement and repair on multilayer are measured later.
## Risks / Trade-offs
- [Two-layer regressions from the stack refactor] → every two-layer golden expectation, the B1/B2 bench numbers on `microboards`, and the DSN byte-compare fixture (`test/fixtures/pcb/*.dsn`) must reproduce; the stack helper is unit-tested on both numberings and on a two-layer legacy board.
- [Freerouting behaves differently with four layers on small boards] → the four-layer `completion` run already showed it fans out through vias it does not need (10 extra vias); the scoring's via weight keeps that visible; if it costs a golden PASS the case's expectation records the fact rather than hiding it.
- [kicad-tools' `--layers 4` assigns planes itself and may pour inner planes] → its `fills` are informational already; verification runs KiCad DRC on the exported board, so a pour it adds is checked like any other copper.
- [Profile values for 4/6 layers are vendored from one source] → same provenance discipline as ADR 0006; the JSON and the typed copy are held equal by test; values are the fabricator's published minimums, and the board's own rules still take precedence where stricter.
- [Six-layer boards in the corpus are few] → the six-layer case is synthetic; the claim for six layers is "the harness handles the stack", not "measured on real boards", and the report says so.
## Migration Plan
No data migration: the IR schema version does not change (the stack is derived, not stored). Snapshot hashes of two-layer boards are unchanged. Roll back by reverting the change; no persisted artefact depends on it.
## Open Questions
- Whether `pcbench-4layer` should be part of the qualification pool for B-series numbers or reported separately. Default: separately, until 30 held-out boards exist for either.
- Whether the default inner-layer direction should come from the fabricator profile rather than the plan. Default: the plan, overridable by intent.
f88a83cd7This file is pinned to the selected release. Download the original to open it in your design tool.