Metadata-Version: 2.4
Name: cadrecon
Version: 0.1.2
Summary: Dataset pipeline, geometric scorer, and verifiers-environment core for 2D-technical-drawing → 3D-CAD reconstruction
Project-URL: Homepage, https://github.com/anon-dot-com/flange
Author-email: Anon <hardik@anon.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: build123d,cad,reinforcement-learning,step,technical-drawing,verifiers
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Requires-Dist: build123d>=0.9
Requires-Dist: ezdxf>=1.3
Requires-Dist: httpx>=0.27
Requires-Dist: jsonschema>=4.21
Requires-Dist: matplotlib>=3.11.0
Requires-Dist: numpy>=2.0
Requires-Dist: pillow>=10.0
Requires-Dist: pydantic>=2.7
Requires-Dist: pyyaml>=6.0
Requires-Dist: scipy>=1.13
Requires-Dist: trimesh>=4.0
Requires-Dist: typer>=0.12
Provides-Extra: data
Requires-Dist: gdown>=5.2; extra == 'data'
Provides-Extra: prime
Requires-Dist: prime-sandboxes>=0.2.30; extra == 'prime'
Description-Content-Type: text/markdown

# cadrecon

An RL environment and evaluation harness for a task frontier models are
measurably bad at: reconstructing a 3D CAD solid from a 2D technical drawing
plus sparse specs.

An agent under test receives orthographic drawing views (a rasterized PNG,
plus optionally the vector DXF) and a small spec table, and writes free-form
`build123d` Python in a hardened Docker sandbox to construct the part. It
submits a STEP file, which is scored geometrically against a ground-truth
STEP file. The interesting signal is in the execute-then-score loop over
direct geometry code — not in regressing a mesh.

## Design in one screen

- **Direct geometry over program synthesis.** The action space is free-form
  `build123d` Python, executed turn-by-turn in a sandboxed container
  (`run_python(code)` / `submit()`); ground truth is the *solid*, not any
  particular code, since many programs yield the same shape. (An earlier
  custom CAD DSL/interpreter was removed in favor of this sandboxed-code
  action space.)
- **Dense, geometry-grounded reward.** Exact-match rewards don't train. The
  scorer gives partial credit via continuous geometric similarity (Chamfer
  distance, tolerant volumetric IoU, F-score) plus a validity term.
- **Real distribution, not synthetic inverses.** Data comes from purpose-built
  CAD-ML research datasets — DeepCAD, ABC, and Fusion 360 Reconstruction — the
  standard benchmarks for this direction. Raw third-party CAD files stay out of
  the repo; a loader script fetches them locally.

## Install

```bash
uv sync --all-packages   # core (loaders, task builder, scorer, CLI) + the
                          # environments/cadrecon_env workspace member (the
                          # verifiers RL/eval environment); a bare `uv sync`
                          # only installs the root package and the env import
                          # fails
uv sync --extra data      # + real DeepCAD source fetch (gdown)
```

## CLI

`cadrecon` is the single entry point. Every subcommand runs offline.

```bash
uv run cadrecon --help
```

| Command | What it does |
| --- | --- |
| `build` | Load raw loader-format sample files (DeepCAD JSON / ABC STEP) and build a task set (drawings, specs, target STEP + mesh) + manifest |
| `render` | Project a STEP solid to a multiview DXF, and rasterize it to a PNG |
| `score` | Score a candidate STEP against a target and print the full breakdown |
| `validate` | Re-check a built `manifest.jsonl` against the committed JSON Schema |
| `data fetch` | Bounded, resumable, polite download of a registered dataset source |
| `data build` | Build a task-set corpus at scale, from DeepCAD JSON models (`--input`) or any directory of raw STEP files (`--from-step-dir`, BYO CAD vault) |
| `data generate` | Generate a corpus of procedurally-generated, distribution-matched training tasks |
| `data coverage` | Parse-coverage report over a directory of DeepCAD JSON models |
| `data stats` | Compute corpus-wide statistics used as the `data generate` reference distribution |

## Layout

```
src/cadrecon/
  loaders/       DeepCAD / ABC -> common CadModel
  task/          builder: CadModel -> drawings + specs + ground-truth STEP/mesh
  kernel/        geometry kernel (build123d) behind a stable interface
  sandbox/       hardened Docker sandbox that runs agent-submitted build123d code
  scoring/       Chamfer / tolerant-IoU / F-score / validity + reward assembly
  scorer.py      candidate-vs-target scoring entry point
  data/          dataset build, generation, BYO import, coverage, stats, splits
  cli.py         operator entry point
environments/
  cadrecon_env/  the `verifiers` environment package (cadrecon_env.py) that
                 wraps the sandbox + scorer into a multi-turn RL/eval env,
                 runnable via `vf-eval cadrecon-env`
docker/
  sandbox/       Dockerfile for the cadrecon-sandbox image the env runs code in
configs/         vf-eval endpoint config (endpoints.toml)
scripts/         sandbox image build, live smoke test (vf-eval), results summary
schema/          cadrecon_manifest.schema.json
docs/            spec, design report, reward red-team, phase plans
tests/           offline test suite (no live network anywhere)
```

## Tests

```bash
uv run pytest
```

The suite is fully offline (R-TST-1): loaders, fetch, and network paths run
against mocked transports and kernel-authored fixture solids
(`tests/cadrecon_conftest.py`), so no dataset download is required.

## Docs

- `docs/specs/cadrecon-spec.md` — the spec.
- `docs/cadrecon-design-report.md` — design rationale and the project's origin.
- `docs/data-card.md` — dataset sources, licensing posture, and split policy
  (real data for eval, real + generated for train).
- `docs/reward-redteam.md` — adversarial analysis of the reward surface.
- `docs/superpowers/plans/` — phased implementation plans.

## Status

The reusable artifact is the `verifiers` environment (`environments/cadrecon_env`)
plus the dataset pipeline and geometric scorer it wraps. `environments/cadrecon_env/README.md`
covers the environment's observation/action/reward contract and arguments;
`scripts/live_smoke.sh` runs the end-to-end acceptance path (`vf-eval
cadrecon-env` against a real model). Not a training-loop deliverable itself —
training happens by pointing an RL trainer at the `verifiers`/Hub environment.
