Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/architecture/cross-package-and-mirrors.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ When you change `packages/polycss` or `packages/core` in a way that affects the

The DOM snapshot exporter is the current exception to mirrored React/Vue public exports: `exportPolySceneSnapshot` lives in `@layoutit/polycss` because it is browser DOM serialization, not component API. React/Vue callers import it from `@layoutit/polycss` and pass the rendered `.polycss-camera` / `.polycss-scene` element.

**Renderer-owned browser glue.** The canvas atlas pipeline (`buildAtlasPages` + helpers), browser-feature detection (`isBorderShapeSupported`, `isSolidTriangleSupported`, `resolveSolidTrianglePrimitive`), direct voxel renderer (`voxelRenderer.ts`), and the base stylesheet injector (`styles.ts`) exist as **independent copies** across the three renderers. This includes `packages/polycss/src/render/atlas/`, `packages/react/src/scene/atlas/`, `packages/vue/src/scene/atlas/`, the three renderer-local `voxelRenderer.ts` files, and the three sibling `styles.ts` files. This is deliberate — each renderer is self-contained on its dep graph (React/Vue do not import from the `polycss` package). The trade-off is that a bug fix in any of these files MUST be mirrored into the other two. Coverage is pinned per copy by the co-located test files.
**Single renderer runtime.** All DOM/CSS rendering — the canvas atlas pipeline, browser feature detection, direct voxel renderer, shadow orchestrator, base stylesheet (`styles.ts`), render stats, and camera/control engines — lives once in `@layoutit/polycss` and is exported through the side-effect-free `@layoutit/polycss/runtime` subpath. React and Vue are thin Adopt-DOM bindings (`createPolyScene(..., { elements: { cameraEl, sceneEl } })`, `scene.add(..., { wrapper })`, `injectPolyBaseStyles` re-export) rather than parallel renderer implementations.

**CI enforces this and the package boundaries.** `pnpm check:boundaries` (`.github/scripts/check-boundaries.mjs`) fails on any import that violates the package dependency boundaries in [AGENTS.md](../../AGENTS.md), on deep imports into another package's `src` (`DEEP_IMPORT_ALLOWLIST` is empty), and on node builtins outside the Node-only surfaces. It scans `.ts`/`.tsx`/`.mts`/`.cts` **and** `.mjs`/`.cjs`/`.js` sources (so the `packages/skills` CLI is covered). Specifiers are read by a single-pass **lexer**, not a regex over raw source, because pattern-matching is wrong in both directions: it misses valid imports (a comment between the keyword and the specifier, `import(\`x\`)`, a statement split across lines) and matches text that is not code (a commented-out import, an import-shaped string). The lexer skips comments, tracks single/double-quoted strings, template literals including `${}` nesting, and regex literals, and yields `import`/`export … from`, bare `import "x"`, `import()` and `require()` specifiers; a template WITH a substitution is not a static specifier and is ignored rather than crashed on. Quoted strings and regex literals may never span a newline, so a mis-lex in TSX (JSX apostrophes, `</div>`) recovers on the next line instead of swallowing code. The same allow-list is applied to each package's manifest: a `dependencies`, `optionalDependencies`, or `peerDependencies` entry outside the package's allow-list fails even when nothing imports it yet. `devDependencies` are tooling and are not constrained. The allow-list is applied to the RESOLVED dependency, not the manifest key, because the key is not what gets installed. Resolved forms: `npm:<name>[@range]` aliases; `link:`/`file:`/`portal:` local paths and `workspace:<path>` targets (both read through the target directory's own `package.json` name); and `workspace:<name>[@range]` aliases, versioned or not. So `"@layoutit/polycss-core": "npm:@layoutit/polycss@0.2.0"`, `"workspace:@layoutit/polycss"` and `"workspace:../polycss"` all fail in React under the allowed key. Only bare ranges and dist-tags (`^0.2.0`, `*`, `latest`, `workspace:^`, `workspace:*`, `workspace:1.2.3`) leave the key standing. Everything else is a **violation, not a pass**: a local or workspace target whose manifest cannot be read, an empty or non-string specifier, and every form whose install target is not determinable from the repo — `catalog:` (the target lives in `pnpm-workspace.yaml`), git specs (`github:`/`gitlab:`/`bitbucket:`/`git+…`/the bare `owner/repo` shorthand), remote tarball URLs, `jsr:` (which installs under a rewritten `@jsr/…` name), and any unrecognised `protocol:`. Falling back to the key for an unresolvable specifier is exactly the bypass, so a package that needs one of those forms must declare it in a shape the checker can see through.
**CI enforces this and the package boundaries.** `pnpm check:boundaries` (`.github/scripts/check-boundaries.mjs`) fails on any import that violates the package dependency boundaries in [AGENTS.md](../../AGENTS.md), on deep imports into another package's `src` (`DEEP_IMPORT_ALLOWLIST` is empty), and on node builtins outside the Node-only surfaces. It scans `.ts`/`.tsx`/`.mts`/`.cts` **and** `.mjs`/`.cjs`/`.js` sources (so the `packages/skills` CLI is covered). Specifiers are read by a single-pass **lexer**, not a regex over raw source, because pattern-matching is wrong in both directions: it misses valid imports (a comment between the keyword and the specifier, `import(\`x\`)`, a statement split across lines) and matches text that is not code (a commented-out import, an import-shaped string). The lexer skips comments, tracks single/double-quoted strings, template literals including `${}` nesting, and regex literals, and yields `import`/`export … from`, bare `import "x"`, `import()` and `require()` specifiers; a template WITH a substitution is not a static specifier and is ignored rather than crashed on. Quoted strings and regex literals may never span a newline, so a mis-lex in TSX (JSX apostrophes, `</div>`) recovers on the next line instead of swallowing code. The same allow-list is applied to each package's manifest: a `dependencies`, `optionalDependencies`, or `peerDependencies` entry outside the package's allow-list fails even when nothing imports it yet. `devDependencies` are tooling and are not constrained. The allow-list is applied to the RESOLVED dependency, not the manifest key, because the key is not what gets installed. Resolved forms: `npm:<name>[@range]` aliases; `link:`/`file:`/`portal:` local paths and `workspace:<path>` targets (both read through the target directory's own `package.json` name); and `workspace:<name>[@range]` aliases, versioned or not. So `"@layoutit/polycss-core": "npm:@layoutit/polycss-vue@0.2.0"`, `"workspace:@layoutit/polycss-vue"` and `"workspace:../vue"` all fail in React under the allowed key. Only bare ranges and dist-tags (`^0.2.0`, `*`, `latest`, `workspace:^`, `workspace:*`, `workspace:1.2.3`) leave the key standing. Everything else is a **violation, not a pass**: a local or workspace target whose manifest cannot be read, an empty or non-string specifier, and every form whose install target is not determinable from the repo — `catalog:` (the target lives in `pnpm-workspace.yaml`), git specs (`github:`/`gitlab:`/`bitbucket:`/`git+…`/the bare `owner/repo` shorthand), remote tarball URLs, `jsr:` (which installs under a rewritten `@jsr/…` name), and any unrecognised `protocol:`. Falling back to the key for an unresolvable specifier is exactly the bypass, so a package that needs one of those forms must declare it in a shape the checker can see through.

`pnpm check:mirrors` (`.github/scripts/check-mirrors.mjs`) keeps the copy discipline honest without any static hash lock file, in two ways: react↔vue clones in `IDENTICAL_GROUPS` must stay byte-identical; and every structurally-divergent mirror set (14 sets covering 100% of `packages/react/src` and `packages/vue/src`, plus the vanilla atlas, `voxelRenderer.ts`, and `styles.ts` mirrors) is checked for filesystem structure and diffed against a base ref (`--base`, else `origin/$GITHUB_BASE_REF`, else `origin/main`, else local `main`) at two granularities. Per mirrored **pair**: same-named files across the lanes the set declares in `pairLanes` (`useReceiverShadows.tsx` ↔ `useReceiverShadows.ts`), each validated independently — if one member moved, its counterpart must move in the same diff. Per **cross-lane group** (`crossLaneGroups`), for units whose files do not match by name or cardinality across lanes (with optional `coreDelegations` when a lane delegates directly to `packages/core/src/...`, e.g. vanilla `solid-triangle-leaf` delegating to `packages/core/src/atlas/solidTrianglePlan.ts`).
`pnpm check:mirrors` (`.github/scripts/check-mirrors.mjs`) keeps React↔Vue adapter parity honest without any static hash lock file, in two ways: react↔vue identical files in `IDENTICAL_GROUPS` (`styles.ts`, `renderStats.ts`, `three/index.ts`, `PolyCamera`, `helpers/index.ts`) must stay byte-identical; and every structurally-divergent mirror set (12 sets covering 100% of `packages/react/src` and `packages/vue/src`) is checked for filesystem structure and diffed against a base ref (`--base`, else `origin/$GITHUB_BASE_REF`, else `origin/main`, else local `main`) at two granularities. Per mirrored **pair**: same-named files across the lanes the set declares in `pairLanes` (`useMeshGeometry.ts` ↔ `useMeshGeometry.ts`), each validated independently — if one member moved, its counterpart must move in the same diff. Per **cross-lane group** (`crossLaneGroups`), for units whose files do not match by name or cardinality across lanes (`controls` where `TransformControls.tsx` ↔ `PolyTransformControls.ts` and `sharedControls.ts` lives on React; `select` where `Select.tsx` ↔ `PolySelect.ts`).

Pairing is **declared per set**, not inferred across every lane, because a shared file name is not proof of a counterpart. `atlas-pipeline` pairs react↔vue by basename and uses `crossLaneGroups` for vanilla↔framework; `voxel-renderer` and `base-styles` pair all three; `controls` and `select` use `crossLaneGroups` for React↔Vue where file splits differ (`TransformControls.tsx` ↔ `PolyTransformControls.ts`, `Select.tsx` ↔ `PolySelect.ts`); and `mesh-modules`, `scene-components`, `three-adapters`, `animation`, `camera`, `helpers`, `shapes`, `store`, and `package-root` pair react↔vue by basename.

The vanilla↔framework direction is **not** left to the coarse lane check. `atlas-pipeline` declares an explicit correspondence table, `crossLaneGroups`: each entry names one semantic unit of the pipeline and, per lane, the file(s) that implement it, at whatever cardinality the code actually has. If any file in a group changed, **every lane represented in that group must have changed** — so a vanilla-only atlas fix now fails even when other vanilla-lane files moved in the same diff (the bypass it closes). The current groups are `rasterisation` (vanilla `rasterise.ts` ↔ framework `buildAtlasPages.ts`), `capability-detection-and-plan-filtering` (vanilla `strategy.ts` ↔ `detection.ts` + `filterPlans.ts`), `packing`, `plan-construction-and-orchestration` (vanilla `plan.ts` + `renderPolygons.ts` ↔ `paintDefaults.ts` + `useTextureAtlas.ts`), `leaf-emission-and-solid-paint` (vanilla `emit.ts` + `paintDefaults.ts` ↔ `atlasPoly` + `borderShape` + `cornerShapeSolid` + `projectiveSolid`), `solid-triangle-leaf` (vanilla `solidTrianglePlan.ts` + `stableTriangle.ts` + core delegation `packages/core/src/atlas/solidTrianglePlan.ts` ↔ `solidTriangleStyle.ts` + `stableTriangleDom.ts` + `triangle`), and `barrel`. Two same-name pairs are **false friends** and the table says so: framework `paintDefaults.ts` mirrors vanilla `plan.ts`/`renderPolygons.ts`, not vanilla `paintDefaults.ts`; only `packing.ts` is a genuine same-name counterpart across all three. The table is validated against the filesystem on every run: every declared file (and `coreDelegations` path) must exist, each group must span at least two lanes, no file may sit in two groups, and a set that declares groups must place **every** member in exactly one of them. Because a group divergence is narrower than a lane divergence, a waiver's `expectedLanes` is matched against the lanes of the diverging **unit**, not the set-wide lane summary.

**Set structure is checked off the filesystem before any base ref is resolved.** Lane parity can only compare files that exist and are declared, which leaves it blind to a NEW module added to one lane or a DELETED counterpart. Each sync set therefore declares `laneRoots` — the directories it owns — and three rules run against the tree itself: every non-test source file under those roots must be declared; every declared member must still exist; and every pair key must be present in every one of the set's `pairLanes`. Deliberately lane-local files are declared in a set's `unmirrored` map with a reason, and each entry must still point at a real file so the exemption list cannot go stale (currently vanilla `atlas/types.ts`, React/Vue `styles/index.ts`, and React `shapes/types.ts`).
**Set structure is checked off the filesystem before any base ref is resolved.** Lane parity can only compare files that exist and are declared, which leaves it blind to a NEW module added to one lane or a DELETED counterpart. Each sync set therefore declares `laneRoots` — the directories it owns — and three rules run against the tree itself: every non-test source file under those roots must be declared; every declared member must still exist; and every pair key must be present in every one of the set's `pairLanes`. Deliberately lane-local files are declared in a set's `unmirrored` map with a reason, and each entry must still point at a real file so the exemption list cannot go stale (currently React `shapes/types.ts`).

**What the mirror check can and cannot prove.** It proves mechanical parity: both sides of a pair or a declared cross-lane group changed in the same diff, both still exist, neither side is a pure deletion, and no module joined a mirrored directory in one lane only. It does **not** prove the two changes are the SAME change. **Touch parity is not semantic parity** — semantic equivalence is a review responsibility and is further checked by `pnpm check:ir` and `pnpm bench:gate:parity`. Co-located tests are excluded from mirror discovery because test filenames diverge across lanes by convention.

Expand All @@ -46,8 +42,7 @@ Before opening a PR:
- [ ] If I touched a Vue component/composable, the React component/hook matches.
- [ ] If I added an option to a `polycss` factory, both bindings expose it.
- [ ] If I renamed a `core` export, every package that imports it is updated.
- [ ] If I touched the canvas atlas pipeline (`rasterise.ts` / `buildAtlasPages.ts`), browser-feature detection, or direct voxel renderer in ONE renderer, the same fix lands in the other two renderers (`polycss` + react + vue) in this PR.
- [ ] If I touched any of the three `styles.ts` files (`packages/polycss/src/styles/styles.ts`, `packages/react/src/styles/styles.ts`, `packages/vue/src/styles/styles.ts`), the CSS rules cover every emitted tag for both lighting modes and shared properties like `will-change: transform` on `.polycss-scene` hold across all three renderers.
- [ ] If I touched `packages/polycss/src/styles/styles.ts`, the CSS rules cover every emitted tag for both lighting modes and shared properties like `will-change: transform` on `.polycss-scene`.
- [ ] Website docs (`website/src/content/docs/**`) and READMEs reflect any user-visible change.
- [ ] If a user-visible change contradicts the agent skill, `packages/skills/skill/**` is updated and `pnpm sync:skill` has been run (see [docs-and-skill-eval.md](./docs-and-skill-eval.md)).
- [ ] If I edited a `<!-- polycss:shared:* -->` block, I edited it in the ROOT `README.md` and ran `pnpm sync:readmes` (see [docs-and-skill-eval.md](./docs-and-skill-eval.md)).
Expand Down
Loading
Loading