---
name: drawing-generator
description: Generates architectural SVG drawings and updates the composite dependency manifest.
allowed-tools: Read, Write, Bash
metadata:
  garden_structure_designer:
    consumes:
      - context/staging/structure.json
    produces:
      - outputs/drawing-plan-view.svg
      - outputs/drawing-elevation-view.svg
    validators:
      - plugins/garden-structure-designer/scripts/svg_validator.py
    repair_axes:
      - svg_xml_invalid
      - svg_topology_mismatch
      - svg_coordinate_drift
---

## Deterministic Drawing Regeneration Contract

This skill generates the **authoritative deterministic SVG outputs**. It must not be bypassed by Markdown updates, render-prompt updates, or PNG concept generation.

For any revision touching `outputs/`, this skill MUST regenerate or explicitly validate all of:
```
outputs/drawing-plan-view.svg        outputs/blueprint-plan.svg
outputs/drawing-elevation-view.svg   outputs/blueprint-elevation.svg
outputs/drawing-isometric-view.svg   outputs/blueprint-isometric.svg
outputs/drawing-perspective-view.svg outputs/blueprint-component-isolation.svg
```

All SVG geometry must be derived strictly from:
- `context/staging/structure.json`

All generated SVGs must embed:
```xml
<!-- COORDINATE MAP: {...} -->
<!-- SAW_SETTINGS: {...} -->
```

All structural elements must carry semantic attributes:
```xml
data-role="post"   data-role="beam"   data-role="rafter"
data-role="brace"  data-role="footing"
```

A revision is incomplete unless each SVG passes `svg_validator.py`. Photorealistic PNG images are visual references only and must never substitute for validated SVG geometry.

## Expected Inputs
`context/staging/structure.json` generated by `structural-engine` (includes members, roof, hub, footings, geometry sections).
`context/staging/joinery-model.json`
`context/staging/bracing-model.json`

## Core Responsibilities
1. Read inputs.
2. Run `geometry_engine.py` (if `structure.json` geometry section is missing or out of date).
3. Run `render_drawings.py` to deterministically generate SVG files without hallucination.
4. Run `svg_validator.py` on each output.
5. Update the composite dependency manifest.

## CAD Debuggability — Debug Label Requirement (HARD RULE)

All generated drawings MUST include visible member ID labels. This is a first-class architectural requirement.

### Label Rules
Every primary structural member (post, beam, rafter, hub, brace) MUST carry a visible `→ {ID}` label:
- Placed near the member axis midpoint
- Format: `→ P1`, `→ B3`, `→ R2`, `→ HUB`, `→ Brace2a`
- Must not overlap critical dimension lines
- Must remain readable at print scale

### Label Failure Conditions (→ FAIL)
- Missing labels on any post, beam, or rafter
- Label text does not match `structure.json` member ID
- Duplicate IDs in the same drawing
- Labels present in code but not rendered in browser snapshot

### Machine-Readable Attributes (Required alongside visual labels)
All structural elements MUST embed BOTH:
```xml
<g data-role="beam" data-tag="B3">
  <polygon ... />
  <text data-label="B3">→ B3</text>
</g>
```
`data-role` alone is insufficient. `data-tag` is required for bidirectional traceability.

## Semantic Topology
All generated SVGs MUST embed `data-role` and `data-tag` attributes on structural elements:
`<polygon data-role="post" data-tag="P1" x="..." y="..." fill="#c8a96e" />`

## Execution
```bash
python3 scripts/render_drawings.py context/staging/structure.json
```

## 🚨 Drawing Red-Team Gate — Embedded Enforcement

**This skill MUST NOT claim its own SVG outputs are complete or successful.**

After generating all SVGs, this skill's responsibility ends. It must NOT:
- Set any package status to `PASS`, `READY`, or `DESIGN COMPLETE`.
- Assert that drawings are "builder-meaningful" or "complete."
- Skip or shortcut the Stage 5.75 gate.

The adversarial drawing gate is **mandatory and independent**:

```bash
python3 plugins/garden-structure-designer/scripts/run_drawing_red_team.py \
  --svg-dir outputs \
  --model context/staging/structure.json \
  --report-dir context/staging \
  --md-dir outputs
```

If `context/staging/drawing-red-team-report.json` does not exist or has `may_claim_success: false`,
the package status is **BLOCKED** and this skill has NOT successfully completed the pipeline.

Passing `svg_validator.py` alone is **not** sufficient for pipeline completion.

## Stop-and-Diagnose Before Renderer Rewrite

If generated SVGs fail the red-team gate, this skill must not immediately rewrite drawing logic.

First determine whether the failure is caused by:

- path split between `context/staging` and `plugins/garden-structure-designer/context/staging`;
- stale quality dashboard;
- missing geometry section in `structure.json`;
- missing `schema-validation-report.json`;
- missing `physics-validation-report.json`;
- red-team/content validator correctly rejecting placeholder drawings;
- renderer genuinely lacking required drawing content.

Only rewrite `render_drawings.py` after confirming:

1. the active staging path is known;
2. `structure.json` is current and its geometry section is populated;
3. the quality dashboard reads the same staging path;
4. the red-team/content validator is running against current SVGs;
5. the failure is genuinely renderer output quality.

If the failure is a path/reporting problem, fix the path/reporting problem first.
