[Constraint 2.0 / D] Project-wide shared-variable table (.scadforge.json) #12

Closed
opened 2026-08-03 16:30:11 +00:00 by Mark · 0 comments
Owner

Project-wide shared-variable table (depends on sub-issues #B #C)

Why: // @sf:param and // @sf:equal today operate by string name within and across files, but there's no central registry — names are resolved by lookup at solve time. To support // @sf:equal to=motor.bore_dia (a dotted path to a deeper shared) and to make cross-file links provable in CI, we need a real table.

Spec:

  • .scadforge.json (already the project manifest) gains a "shared_params" array:
    {
      "shared_params": [
        { "name": "plate_length", "unit": "mm", "default": 200, "min": 10, "max": 1000 },
        { "name": "wall_thickness", "unit": "mm", "default": 4 }
      ]
    }
    
  • // @sf:export annotation (new) marks a local assignment for inclusion in this table:
    plate_length = 200; // @sf:export
    
    On first parse of the file, the parser adds an entry to .scadforge.json if missing. On re-parse, the comment presence keeps the entry (refresh default from current value).
  • // @sf:equal to=plate_length now resolves via the table first, falling back to local-symbol lookup (back-compat).
  • Min/max bounds from the table are enforced during solve — out-of-range values produce a UI warning badge in ConstraintPanel.tsx, not a hard error (so legacy constraints with stale defaults still render).

Files to change:

  • src/lib/vfs.ts (the merge seam) — add SharedParam to the project manifest schema, export from Project.
  • src/lib/scad/constraints.ts — new export kind case + table lookup in equal.
  • src/lib/scad/parser.ts — capture @sf:export comment position.
  • src/lib/scad/solver.ts — table-fed scope.
  • src/pages/SettingsModal.tsx — add a Shared-Parameters tab to view/edit the table, with min/max validation.

Acceptance:

  • A .scadforge.json with two shared params round-trips: create via UI, save, reload project, params still there.
  • // @sf:equal to=plate_length from any file resolves correctly.
  • Editing plate_length default in the UI updates dependent parts in the viewport within one frame.
  • Lint clean, tsc clean, build clean.

Out of scope: imports from external .scadforge.json packages, versioned shared-param namespaces.

Labels: enhancement


Part of epic #8.

## Project-wide shared-variable table (depends on sub-issues #B #C) **Why:** `// @sf:param` and `// @sf:equal` today operate by string name within and across files, but there's no central registry — names are resolved by lookup at solve time. To support `// @sf:equal to=motor.bore_dia` (a dotted path to a deeper shared) and to make cross-file links provable in CI, we need a real table. **Spec:** - `.scadforge.json` (already the project manifest) gains a `"shared_params"` array: ```json { "shared_params": [ { "name": "plate_length", "unit": "mm", "default": 200, "min": 10, "max": 1000 }, { "name": "wall_thickness", "unit": "mm", "default": 4 } ] } ``` - `// @sf:export` annotation (new) marks a local assignment for inclusion in this table: ```scad plate_length = 200; // @sf:export ``` On first parse of the file, the parser adds an entry to `.scadforge.json` if missing. On re-parse, the comment presence keeps the entry (refresh default from current value). - `// @sf:equal to=plate_length` now resolves via the table first, falling back to local-symbol lookup (back-compat). - Min/max bounds from the table are enforced during solve — out-of-range values produce a UI warning badge in `ConstraintPanel.tsx`, not a hard error (so legacy constraints with stale defaults still render). **Files to change:** - `src/lib/vfs.ts` (the merge seam) — add `SharedParam` to the project manifest schema, export from `Project`. - `src/lib/scad/constraints.ts` — new `export` kind case + table lookup in `equal`. - `src/lib/scad/parser.ts` — capture `@sf:export` comment position. - `src/lib/scad/solver.ts` — table-fed scope. - `src/pages/SettingsModal.tsx` — add a Shared-Parameters tab to view/edit the table, with min/max validation. **Acceptance:** - A `.scadforge.json` with two shared params round-trips: create via UI, save, reload project, params still there. - `// @sf:equal to=plate_length` from any file resolves correctly. - Editing `plate_length` default in the UI updates dependent parts in the viewport within one frame. - Lint clean, tsc clean, build clean. **Out of scope:** imports from external `.scadforge.json` packages, versioned shared-param namespaces. **Labels:** enhancement --- Part of epic #8.
Mark closed this issue 2026-08-03 16:30:11 +00:00
Sign in to join this conversation.
No description provided.