@rulecad/cad 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -135,11 +135,13 @@ The workspace is `$CAD_WORKSPACE`, else the nearest folder at or above the curre
135
135
  else the current folder:
136
136
 
137
137
  ```json
138
- { "printer": "x1c", "viewUrl": "https://…/", "targets": { "show": "targets/show.mjs", "shorten": "gist" } }
138
+ { "printer": "x1c", "engine": "manifold", "viewUrl": "https://…/", "targets": { "show": "targets/show.mjs", "shorten": "gist" } }
139
139
  ```
140
140
 
141
141
  - `printer`: the rule set prints are checked against (bed, overhang, layer, bridge, support_gap); a project.json's
142
142
  `printer` wins. Either is a rule set's plain name (letters, digits, `-` and `_`; see Variables).
143
+ - `engine`: optional. The boolean engine for every design's `v.ops` whose object names none: `"manifold"` (a new
144
+ workspace's, with `manifold-3d` installed beside the cad command) or `"jscad"` (the default). See Engines.
143
145
  - `designTimeout` and `designMemory`: optional. How long a design may run in the sandbox, in seconds (3600, an hour, if
144
146
  left out), and how much memory its JavaScript may hold, in megabytes (4096). A design past either is stopped with
145
147
  `design.time` or `design.memory` (see Sandbox). `CAD_DESIGN_TIMEOUT` and `CAD_DESIGN_MEMORY` set them for one run.
@@ -153,6 +155,9 @@ else the current folder:
153
155
  - Designs are ES modules that import JSCAD themselves, so the workspace needs `"type": "module"` and
154
156
  `@jscad/modeling`. Circuit boards need `@rulecad/pcb` as well.
155
157
  - Previews need Chrome or Chromium: `$CAD_CHROME`, else the usual install paths.
158
+ cad shows that Chrome the page from a small server on this computer for the few seconds a picture takes. The
159
+ server answers only to this computer's own names and addresses, so a web page open in your browser can't read the
160
+ part from it.
156
161
  - Designs are code: run only designs you trust. Links and rule files are data and never run.
157
162
 
158
163
  ### Your copies of the kit's rule sets
@@ -279,7 +284,13 @@ so in one line (on stderr), so that a workspace from elsewhere can't send your l
279
284
  from its `.kicad_pcb` (a file, or a GitHub link: pinned to the commit, with the repository's licence). A board's code
280
285
  reads it as `v.sea_picro.circuit` and builds from it with @rulecad/pcb's `clone`. Its rules (`width`, `height`,
281
286
  `thickness`, `layers`) are `kind: derived`, with the source and its licence. A reciprocal licence (CERN-OHL-S,
282
- share-alike) carries over to boards made from it: keep such a rule set apart from your others.
287
+ share-alike) carries over to boards made from it: keep such a rule set apart from your others. It reads up to 64 MB
288
+ for the board and for each 3D model of its parts, from a file or downloaded: a larger board is refused, and a larger
289
+ model is left out with a note that names it by its path in the board's folder or repository (`note: no 3D model for
290
+ hw/lib/usb.wrl: its .wrl file is more than the 64 MB cad clone reads`). A model of more than 2 million triangles is
291
+ left out the same way. Only a file is read: a board that is a folder, a device or a pipe is refused, and a model
292
+ that is one is left out with a note. A character in a model's name that doesn't print (a bell, an escape code) is
293
+ written in its note as its code, `\u{7}`.
283
294
  - An object or rule set named with a hyphen (`mx-switch`) is read with an underscore in expressions (`mx_switch.housing_top`),
284
295
  since a hyphen there is a minus.
285
296
  - Rule-set, project, object, layout, problem and assembly names are plain: letters, digits, `-` and `_`, starting
@@ -288,9 +299,10 @@ so in one line (on stderr), so that a workspace from elsewhere can't send your l
288
299
  was read from (`projects/p/project.json: the "printer" field "../x" is not a plain name`): a workspace's own files
289
300
  cannot make the tool read or write anywhere but where it means to. In `"uses"`, another object is
290
301
  `<project>/<object>`, optionally with `:<variant>` and `@<version>`, never a path to a file.
291
- - Rules carry `kind`: spec (manufacturer), default (slicer), community (rule of thumb), estimate (a reasoned guess
292
- nobody has measured yet), derived (worked out from other figures, such as a board's size read from its design file)
293
- or measured (your own test print, which beats the rest), plus `source` and `checked`. `cad check` warns
302
+ - Rules carry `kind`: spec (the maker's or a standard's own document), default (slicer), community (a widely used
303
+ figure from anyone else, such as a shop's listing or a wiki), estimate (a reasoned guess nobody has measured yet),
304
+ derived (worked out from other figures, such as a board's size read from its design file) or measured (your own test
305
+ print, which beats the rest), plus `source` and `checked`; the rules README says what each means. `cad check` warns
294
306
  (`rules.estimate`) when an object or an assembly rests on an estimate: a rule it reads, or a seat drawn to an
295
307
  estimated fit (a press-fit `shaftBore`), naming each one to measure.
296
308
 
@@ -426,8 +438,12 @@ To fit something someone else made (a maker's connector, a part from a model sit
426
438
  guessing, then check your design against it.
427
439
 
428
440
  `cad measure <model.stl|model.3mf>` (and `cad match`) reads a model from anywhere as data, up to 2,000,000 triangles,
429
- a 3MF's zip up to 512 MB unpacked and its objects placed up to 100,000 times: a file past a limit, a corner that is not
430
- three numbers, or a 3MF triangle naming a corner its object hasn't got is refused, naming what is wrong. It finds the stretches along the model's longest axis (or `--along y`) where its
441
+ a 3MF's zip up to 512 MB unpacked, its objects placed up to 100,000 times and held up to 16 levels deep inside each
442
+ other: a file past a limit, a corner that is not three numbers, a 3MF triangle naming a corner its object hasn't got,
443
+ a 3MF object that holds itself, or a damaged zip (a size or place in it that points past the file's end) is refused,
444
+ naming the file and what is wrong (`part.3mf: a damaged zip file: entry 2 (3D/3dmodel.model) runs past the end of the
445
+ file`). So is a file of more than 2 GB, a text STL or a 3MF's model file of more than 511 MB of text (the most Node
446
+ holds), and a folder given for a file. It finds the stretches along the model's longest axis (or `--along y`) where its
431
447
  cross-section stays the same, numbers the distinct sections (a section seen again gets the same letter), and describes
432
448
  each one: its extent and its height bands, the heights over which it has the same pieces across, split again at steps.
433
449
  It draws every distinct section in `.preview/measure/`. `--line 0.6,2.5` reports where a line along the axis is inside
@@ -494,8 +510,23 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
494
510
  "fits": [ { "a": "cap.cap", "b": "switch.stem", "min": "-x1c.hole_comp", "max": "x1c.fit", "note": "Slot over the stem" } ] }
495
511
  ```
496
512
 
497
- - **fit** assemblies check how parts go together: no overlaps (unless a fit allows a press fit with a negative
498
- `min`), and the closest gap for each `fit` within its range. Supports are left out: they're snipped off first.
513
+ - **fit** assemblies check how parts go together: no overlaps, and the closest gap for each `fit` within its range,
514
+ from `min` to `max` in millimetres; a gap outside it fails (within 1 µm of a bound passes). A negative `min` is a
515
+ press fit: the two may run into each other no deeper than that, measured as a depth (the volume they share over the
516
+ area where they meet), so a knob 1 mm into a block fails a fit whose `min` is -0.05. A negative `max` asks for at
517
+ least that depth, for a press fit that must grip. Round a pin pressed into its hole the depth reads a little deeper
518
+ than the interference (0.33 mm for 0.3 mm round a 3 mm pin). A `min` below -1 is
519
+ refused as deeper than any press fit, and a `min` above its `max` is refused (`fit.range`), on a fit of any kind
520
+ (a gap, an `engage`, a `seat`, a `shaft`). Where two parts may overlap by any amount (a rod through a part, an end
521
+ cap's pegs in a beam, a reference part drawn into another), say so with `"overlap": "allowed"` in place of the
522
+ `min`. Supports are left out: they're snipped off first.
523
+ Overlaps are measured by Manifold where it is installed and can read both parts; else by JSCAD, whose unions can
524
+ leave seams open (a flat face of no thickness across a bore). Such a face measures nothing, by itself or beside a
525
+ real overlap, which fails by its own volume. An overlap under 0.5 mm³ that only JSCAD measured is a warning that
526
+ says how to measure it with Manifold, not a failure (in the overlap check and in a fit it puts out of range), and
527
+ `--sweep` through one warns that the parts "may hit".
528
+ Where JSCAD finds faces that close into no solid and are no flat film, the overlap still fails, its volume given as
529
+ "about", with the same advice.
499
530
  Objects with `"role": "reference"` (the MX switch) model things you don't print: drawn faint, never exported.
500
531
  - **Hosts:** the core (resolve, build, check) reads and writes through a host (`lib/host.mjs`): Node's file system
501
532
  for the CLI, or `memoryHost(files)`, a workspace in memory (reading the tool's own packages from disk), for tests
@@ -503,8 +534,12 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
503
534
  page (`motionData`) are in the library too, so other programs make the same links without the CLI:
504
535
  `import { memoryHost, useHost } from '@rulecad/cad/host'`, and likewise `/design`, `/assembly`, `/links`, `/edit`,
505
536
  `/explain`, `/schema`, `/errors`, `/optimise`, `/rules`, `/workspace`, `/versions`, `/layout`, `/preview`, `/targets`, `/threemf`.
506
- - **Engines:** designs get `v.ops` (union, subtract, intersect): JSCAD's booleans by default, Manifold's (faster,
507
- watertight; `npm install manifold-3d`) with `"engine": "manifold"` in the object's JSON or `CAD_ENGINE=manifold`.
537
+ - **Engines:** designs get `v.ops` (union, subtract, intersect): Manifold's (faster, watertight; `npm install
538
+ manifold-3d`) with `"engine": "manifold"` in the object's JSON, `CAD_ENGINE=manifold` for one run, or `"engine":
539
+ "manifold"` in cad.config.json for the workspace (a new workspace has it, and manifold-3d in its package.json);
540
+ JSCAD's otherwise. Where the workspace asks for Manifold and manifold-3d isn't installed, designs are built with
541
+ JSCAD and cad says so once; an object that asks for it by name is refused until it is installed. An object's
542
+ `"engine": "jscad"` keeps it on JSCAD in a Manifold workspace (`CAD_ENGINE` still sets every design for one run).
508
543
  - **Sandbox:** a design (a board design's too) runs in a separate Node process under Node's permission model, with
509
544
  none of your environment (no tokens), and an import hook on top to keep it to making shapes. What it can do there
510
545
  depends on the Node it runs on:
@@ -535,7 +570,8 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
535
570
  elsewhere, which a workspace cloned from someone else can hold) is refused before the design runs, and whenever
536
571
  rulecad reads one of the workspace's own files, with `workspace.outside` and the link's name, so no file of yours
537
572
  elsewhere is read into a build or a model link; a kept result in `.cache/` that is such a link is not read but made
538
- afresh. To share a file between workspaces, copy it into each, or put it in a package and install that (the
573
+ afresh, and a link anywhere in `.versions/` (where a released version is unpacked to build it) stops the command,
574
+ named, with nothing written or removed through it. To share a file between workspaces, copy it into each, or put it in a package and install that (the
539
575
  workspace's own `node_modules` is the packages', and may link anywhere). A target named in cad.config.json is held
540
576
  to the same, by its real path. An import of a package must lead inside that package: a file of it is named by its
541
577
  path there (`@jscad/modeling/src/primitives/index.js`), never with `..`, `.`, `node_modules`, a backslash, `%` or
@@ -553,7 +589,12 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
553
589
  (a stage that goes is worked out again next time). A design may run for an hour (3600 s) and its JavaScript may hold 4096 MB, its process 512 MB
554
590
  more in all (Node itself, typed arrays, WebAssembly memory, output not yet sent): past any limit its process is
555
591
  stopped and the build fails with `design.time` or `design.memory`, naming the design, so a design that loops for
556
- ever or fills memory without end can't hang the command or take the machine down with it. What a design sends back
592
+ ever or fills memory without end can't hang the command or take the machine down with it. If the command
593
+ itself is stopped from outside (its terminal closed, its job cancelled), a small guard process it starts ends the
594
+ design's process with it, so no design is left running. A command that comes to its own end, pass or fail, first
595
+ waits until the design's process and the guard have gone: nothing of it is left in the workspace's folder, which a
596
+ script can move or remove the moment the command returns (Windows refuses while a process still sits in a folder).
597
+ What a design sends back
557
598
  is kept only up to its memory limit, and what it prints only its last megabyte, so it can't fill the tool's own
558
599
  process either. A slow design that needs more raises them in cad.config.json (`"designTimeout"` in seconds,
559
600
  `"designMemory"` in megabytes; above the defaults, once the workspace is trusted with `cad trust`) or with
@@ -580,6 +621,23 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
580
621
  same sandbox, through the host's `runDesign` (a copy of the design's project in a temporary folder, removed after),
581
622
  and in the tool's own process only when `build` is called with `{ trusted: true }`. (`test/sandbox.test.mjs`,
582
623
  `test/target-trust.test.mjs`, `test/board-trust.test.mjs` and `test/sandbox-limits.test.mjs` try each of these.)
624
+ - **Programs cad starts:** cad itself starts a few of your computer's programs: git (for versions: `status`, `link`,
625
+ `show`, `history`, `diff`, `compare` and `release`, and `check` or `build` of a release such as `home/tray@1.2.3`),
626
+ `gh` (short links through a GitHub Gist) and the file browser (`open`, `explorer` or `xdg-open`, for `--open`). It
627
+ finds each in the folders on your PATH and starts it by the full path it found, never through a shell: never from the
628
+ workspace's own folder (where Windows looks first for a program named without its folder), never from a folder of
629
+ PATH inside the workspace (npm puts the workspace's `node_modules/.bin` there), and never from a PATH entry that is
630
+ not a full path, such as `.`. On Windows only a `.com` or `.exe` is taken. If one is not found, cad says which, and
631
+ that it should be installed or its folder added to PATH. A workspace that comes with its `.git` folder (in an
632
+ archive, or copied) brings git's settings and hooks with it, and those can name programs for git to run. The git
633
+ commands cad runs to read a workspace (its releases, what has changed since) run none of them: each is started with
634
+ git's file system monitor off, its hooks looked for where there are none, no pager, nothing written back to git's
635
+ index, and every filter and diff program git's settings name switched off. A release is different: `cad release`
636
+ commits, tags and pushes as `git commit`, `git tag` and `git push` do by hand, so the repository's own hooks (such as
637
+ pre-commit), filters, signing and push settings run, as they do for your own commits. So before you release in a
638
+ workspace that came from someone else with its `.git` folder, look at its settings (`git config --list
639
+ --show-origin`) and its `.git/hooks` folder, or start its git afresh (move `.git` aside, then `git init`).
640
+ (`test/workspace-programs.test.mjs` tries each of these.)
583
641
  - **Mistakes are named:** a design that reads a variable that isn't there (`v.widht`) stops with the name it
584
642
  probably meant, not a shape drawn from `undefined`; errors in a design carry its file and line.
585
643
  - **Units:** `cad check` warns where an expression mixes units (millimetres added to degrees, a sine of a length) or
@@ -680,8 +738,9 @@ paste: `{ "screw": "M2 cap", "through": ["pcb.board"], "into": "case.body", "hol
680
738
  read from the fit's `fastener` (`M2x6`), else from a thread set the holes fit's `depth` names (`m2.insert_length`),
681
739
  else from the board's holes as drawn: the largest metric thread narrower than the narrowest hole. `cad add fasten
682
740
  <project>/<assembly> --from-fits` writes it in their place: the holes fit goes, the fit that fastens keeps its gap
683
- range (`min`, `max`) with `fastens`, `fastener` and `count` taken off, or goes too where it had no range. `--screw "M2x8
684
- countersunk"` gives another screw. Screws driven from below (`"direction": "up"`) are left for you to write.
741
+ range (`min`, `max`) and its `"overlap": "allowed"` with `fastens`, `fastener` and `count` taken off, or goes too where
742
+ it had neither. `--screw "M2x8 countersunk"` gives another screw. Screws driven from below (`"direction": "up"`) are
743
+ left for you to write.
685
744
 
686
745
  `cad list` counts every fixing (`fasten.count`): each screw, nut, washer and insert a `fasten` placed (a component's
687
746
  too), a motor's mounting screws where a fit that `fastens` holds it (as many as its holes, at the length its mount
@@ -783,9 +842,12 @@ then y, then z, as `rotate` does.
783
842
  wrong height or on the wrong step of a compound gear would. This overlap rule covers spur, internal and rack meshes;
784
843
  worms and bevels are placed by their own checks. Both gears' axes sit on
785
844
  one part, or on parts held still; planets on a carrier are a `planetary`.
786
- - **Worms and bevels:** `"worm": true` (or `{ "diameter", "hand" }`) in a mesh makes the driving joint a worm and
787
- this one its wheel, `teeth` [starts, the wheel's], the axes crossed at right angles; the check says the ratio,
788
- whether it locks, and the centre distance. `"bevel": true` makes the two bevel gears, their axes meeting at the
845
+ - **Worms and bevels:** `"worm": true` (or `{ "diameter", "hand", "flanks", "overhang" }`) in a mesh makes the
846
+ driving joint a worm and this one its wheel, `teeth` [starts, the wheel's], the axes crossed at right angles; the
847
+ check says the ratio, whether it locks, and the centre distance. A worm is drawn to print standing, the flank of its
848
+ thread that faces down laid back, so the check also says which flank drives and its contact ratio (`worm.flanks`):
849
+ give the mesh the `"flanks"` (`"standard"` for the full thread) and `"overhang"` the object gives `v.gears.worm`,
850
+ where it gives any. `"bevel": true` makes the two bevel gears, their axes meeting at the
789
851
  shaft angle; the cones must share their apex (`mesh.bevel`). Both follow in phase, so `--sweep` turns them clean.
790
852
  - **Planetary gearboxes:** `"planetary": [{ "sun": "sun", "carrier": "carrier", "ring": "ring", "planets": ["p0", "p1",
791
853
  "p2"], "drive": "carrier", "module": 1, "teeth": ["sun.teeth", "p0.teeth", "ring.teeth"] }]` names the items. One of
@@ -968,8 +1030,9 @@ address stands for the faces near it, as `item@anchor` does (`"within"`, 10 mm b
968
1030
  (`"at": "x1.a"`); its anchor `b1` is its screw's, and its `ops` say the tap the end needs. In a mechanism, hold it
969
1031
  as anything else is held: a foot by a `fasten` of its screw into the beam (`{ "screw": "M5 cap", "through": ["foot1"],
970
1032
  "into": "p1", "at": ["foot1.b1"] }`, the beam's end tapped as its `ops` say), and an end cap by a fit that fastens,
971
- its pegs a press fit (`"min": -5`). The overlap check measures an end cap without its pegs, which stand in the beam,
972
- and an in-slot panel edge or a slot cover by what stands above the face alone: the rest lies in the slot by design.
1033
+ its pegs standing in the beam (`"overlap": "allowed"`). The overlap check measures an end cap without its pegs, which
1034
+ stand in the beam, and an in-slot panel edge or a slot cover by what stands above the face alone: the rest lies in the
1035
+ slot by design.
973
1036
  A panel item (below) holds its sheet with clips; a panel corner or an in-slot edge is placed by hand as an item.
974
1037
  - A `bracket`, `gusset`, `splice`, `hidden` or `anchor` join with a bought fitting's set by name (`"fitting":
975
1038
  "fitting-motedis-bracket-20-b6"`, @rulecad/frames' README, Bought fittings) adds that fitting as an item placed
@@ -1086,6 +1149,13 @@ address stands for the faces near it, as `item@anchor` does (`"within"`, 10 mm b
1086
1149
  `estimate` while any join's spring is one, even where the springs change no figure; `measured` when every join's
1087
1150
  is; `beams` with no joins); the rigid figure is the least the sag can be. The limit is a rail's own parallelism
1088
1151
  under a guide, else `"frame": { "limit": 0.2 }`, else the task's accuracy, else the beam's span over 360. Over it fails.
1152
+ Every beam is held to its own span over 360 too (or `frame.limit` where given; never the task's accuracy), by its
1153
+ worst sag anywhere along its length (each element's stations, not only its ends and joins), loaded or not: each beam
1154
+ over it fails, and where none is, the beam nearest its limit is said as the one pass. That sag is the beam's own
1155
+ bending, measured from the line through where it is held (its supports, and its joins to beams that reach a support
1156
+ without passing through it), so a short beam hanging from the middle of a long rail is not failed for the rail's
1157
+ sag; a beam held at one end only keeps its tip's whole drop, whatever hangs from it. A 3 m rail of MISUMI 2020 held at its ends sags about 9.96 mm on its own weight (Roark, table 8.1:
1158
+ 5 w L⁴ / 384 E I), against 8.33 mm, and fails.
1089
1159
  A sag is given in mm to three places, or to three figures under 0.1 mm (0.00123 mm, 0.000352 mm). Where a beam of
1090
1160
  the frame is drawn printed, each sag is given after creep too: the frame solved again with the joins' springs, each
1091
1161
  printed beam bending as if at half its modulus (`PRINTED_DEFAULTS.creep_modulus`, an estimate), under every case but
@@ -1268,13 +1338,15 @@ a brace in both bays that way about 240 times ("frame checks: an open cube racks
1268
1338
  nuts and the join, and `cad order` and the build page list them as the step before the one that makes it
1269
1339
  (`5. Load 2 × slot-nut-6-misumi-m4-slide-in into y1's top slot through its end a, for plate2, before the blind join
1270
1340
  of y1.a to p1.top@170 closes it`).
1271
- - `frame.square`: each bay of the frame (four beams joined in a rectangle in one plane), with its two diagonals,
1341
+ - `frame.square`: each bay of the frame (four beams round a rectangle in one plane, each neighbouring pair joined to each
1342
+ other or both joined to one beam there, as the top and bottom rings of a corner-post box meet through its posts: one
1343
+ finder, `lib/bays.mjs`, for this, the frame's solve, `frame.rack`, `cad order` and the build page), with its two diagonals,
1272
1344
  inside corner to inside corner, and the difference between them to accept, stacked from its parts as an arm's
1273
1345
  error budget stacks its joints (`squareness` in `@rulecad/frames`). Each beam of the bay whose end butts another
1274
- beam of the bay sets the opening along it by its cut length: cut t long or short, it moves one diagonal against the
1346
+ beam of the bay, or the post its corner meets through, sets the opening along it by its cut length: cut t long or short, it moves one diagonal against the
1275
1347
  other by t × span / d (span the opening along that beam, d the diagonal). Each join of the bay's beams lets the end
1276
1348
  of `a` sit off by its play s along `b` (`JOIN_PLAY`, an estimate for every kind): s × span / d, span the opening
1277
- along `b`. The difference to accept is their sum, the worst case, with their root-sum-square beside it, and the
1349
+ along `b` (a join to a post slips along the post, out of a ring's plane, so it adds nothing to the ring's). The difference to accept is their sum, the worst case, with their root-sum-square beside it, and the
1278
1350
  finding lists each term. The cut tolerance is the assembly's `"frame": { "cut": { "tolerance": 1 } }` where given
1279
1351
  (this workshop's saw, also taken by the cut list), else the profile's `cut_tolerance`, else 0.5 mm. A 260 × 200 mm
1280
1352
  opening of MISUMI 2020 (d = 328.02 mm) with its two rails butting the posts and four blind joins: 2 × 0.5 × 260 / d
@@ -1434,7 +1506,8 @@ joins' springs, the loads and mounted items):
1434
1506
  heavier profile's stiffer joins, nor refused a heavier profile on a lighter one's softer joins.
1435
1507
  - `"limits"`: in place of the checks' own. Left out, each is the check's: the sag at each load, named point and guide
1436
1508
  as `frame.deflection` holds it (a guide's rail parallelism, `frame.limit`, the task's accuracy, else the span over
1437
- 360; a load that moves with a joint anywhere along its beam), each beam's stress with the joins' springs and with
1509
+ 360; a load that moves with a joint anywhere along its beam), and every beam's own sag along its length (its bending, from where it is held) against
1510
+ its span over 360, each beam's stress with the joins' springs and with
1438
1511
  them rigid against its alloy's strength `frame.margin` (2) times over, the frame's first buckling factor and each
1439
1512
  grouped beam's Euler load (K 1) the same, and the lowest mode at twice the task's moves where it has a task.
1440
1513
  `"deflection"` (mm, at every load, point and guide), `"stress"` and `"buckling"` (margins), `"frequency"` (Hz) and
@@ -1513,7 +1586,9 @@ Once an assembly is checked, these say how to make it. They all read the assembl
1513
1586
  3. **Sides built flat**: each bay that shares no beam with a side already chosen is built on the bench, beam by beam,
1514
1587
  each beam's joins with their screws, key and torque, left snug (`Snug for now: tightened to its torque at step 8,
1515
1588
  once square`), then squared by its diagonals and its joins tightened. Of
1516
- two bays that share a post, the first found is a side and the other is squared once the frame is joined.
1589
+ two bays that share a post, the first found is a side and the other is squared once the frame is joined. A bay
1590
+ whose beams meet only through a post (the top and bottom rings of a corner-post box) is never a side, and is
1591
+ squared with the rest once every join is made, so the box is square in plan as well as on its upright faces.
1517
1592
  4. **Nuts to load, heads slid in**: every blind join's head and every slot nut needs a way into its slot at the
1518
1593
  step that puts it there: an end of the slot that nothing has closed yet (a join on that end, or an item placed
1519
1594
  there) and nothing already in the slot between it and that end (a head, a nut). A beam going on slides along the
@@ -1645,7 +1720,9 @@ slotted face, its holes read from its own rule set (@rulecad/frames' README, Ser
1645
1720
  table fixed on it.
1646
1721
  - `cad check` says `guide.holes` (the holes, their pitch and the end distance; `guide.end` where an end is past half
1647
1722
  the pitch), `guide.travel`, `guide.fit` (the rail on the face, a slot nut for its screws, its ends on the beam and
1648
- clear of a beam joined across its face), `guide.budget` (what it adds to an error budget) and `guide.jig` (a
1723
+ clear of a beam joined across its face), `guide.budget` (what it adds to an error budget: said after the frame is
1724
+ solved, its beam sag the frame's own figure under the rail, the one `frame.deflection` gives, and the rail's estimate
1725
+ only where the frame is not solved) and `guide.jig` (a
1649
1726
  printed jig that centres the rail while it is screwed down, as a `rail-jig` fitting item).
1650
1727
  - Each carriage's loads are held to its ratings at every pose (`joint.moment`): the weight of all it carries and the
1651
1728
  masses of `"loads"` hung on it, as a force and a moment about its middle on the rail's top, in its own frame.
@@ -1950,7 +2027,7 @@ surface is also kept within the printer's overhang limit: faces smoothing tipped
1950
2027
  The surface is drawn with many small triangles, and `cad optimise` thins them by default: the surface stays within
1951
2028
  0.1 mm of where it was drawn (a quarter of an X1C's print line), closed, with no more overhang and no new tips, and
1952
2029
  `cad optimise` says how many triangles it had and has. On the bracket bench's printable result that takes 75,592
1953
- triangles to 21,124 and 27.808 cm³ to 27.806 cm³ (35.04 g of PLA at 1.26 g/cm³ either way, 0.003 g apart), a quarter
2030
+ triangles to 21,124 and 27.808 cm³ to 27.806 cm³ (34.48 g of PLA at 1.24 g/cm³ either way, 0.003 g apart), a quarter
1954
2031
  of the size in a file or a link. `"outline": { "reduce": 0.05 }` keeps the surface closer (31,154 triangles on the
1955
2032
  bracket), and `"outline": { "reduce": false }` keeps every triangle it was drawn with.
1956
2033
 
package/bin/cad.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  // cad: make, check, preview, export and show rule-driven designs. Run `cad help`.
3
+ // First of all: on a Node older than cad runs on, one plain line and exit 1 (lib/node-version.mjs), before the rest loads
4
+ import '../lib/node-version.mjs';
3
5
  import fs from 'node:fs';
4
6
  import path from 'node:path';
5
- import { execFileSync } from 'node:child_process';
7
+ import { runProgram } from '../lib/programs.mjs';
6
8
  import { fmt, loadRuleSet, insideWorkspace } from '../lib/rules.mjs';
7
9
  import { estimatesFinding } from '../lib/estimates.mjs';
8
10
  import { WS, TOOL, paths, configError, printerOf, asks, trust } from '../lib/workspace.mjs';
@@ -24,6 +26,7 @@ import {
24
26
  } from '../lib/design.mjs';
25
27
  import {
26
28
  git,
29
+ gitAsByHand,
27
30
  tags,
28
31
  bump,
29
32
  bigger,
@@ -86,6 +89,7 @@ import { threemf, slotOf } from '../lib/threemf.mjs';
86
89
  import { liveView, recorder, endOnly } from '../lib/live.mjs';
87
90
  import { checkSets, drawSet, draftSet, draftPart, draftParts, updateSet } from '../lib/sheet.mjs';
88
91
  import { filaments, slots, linkTo, objectModel, assemblyModel, VIEW, viewNote } from '../lib/links.mjs';
92
+ import { endSandbox } from '../lib/sandbox.mjs';
89
93
 
90
94
  // What the print file asks of the AMS: which filament each kind of part prints in
91
95
  function filamentNotes(parts, fil) {
@@ -104,11 +108,19 @@ function filamentNotes(parts, fil) {
104
108
  ];
105
109
  }
106
110
 
107
- // --open: the 3MF in Bambu Studio (macOS), else whatever opens .3mf files
111
+ // --open: the 3MF in Bambu Studio (macOS), else whatever opens .3mf files (each found on PATH, never in the workspace:
112
+ // lib/programs.mjs)
108
113
  const openInSlicer = (f) =>
109
114
  process.platform === 'darwin'
110
- ? execFileSync('open', ['-a', 'Bambu Studio', f])
111
- : execFileSync(process.platform === 'win32' ? 'explorer' : 'xdg-open', [f]);
115
+ ? runProgram('open', ['-a', 'Bambu Studio', f], {}, 'open, which opens the file in Bambu Studio,')
116
+ : runProgram(
117
+ process.platform === 'win32' ? 'explorer' : 'xdg-open',
118
+ [f],
119
+ {},
120
+ process.platform === 'win32'
121
+ ? "explorer, Windows' file browser,"
122
+ : 'xdg-open, which opens a file in its program,',
123
+ );
112
124
 
113
125
  const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
114
126
 
@@ -1246,10 +1258,12 @@ async function main() {
1246
1258
  }
1247
1259
 
1248
1260
  if (cmd === 'agents') {
1249
- // the notes for AI agents, into this workspace (AGENTS.md, and CLAUDE.md pointing at it)
1250
- const to = path.join(WS, 'AGENTS.md'),
1261
+ // the notes for AI agents, into this workspace (AGENTS.md, and CLAUDE.md pointing at it): neither written through
1262
+ // a link, which in a workspace from someone else could lead to a file of the user's elsewhere (rules.mjs)
1263
+ const to = insideWorkspace(path.join(WS, 'AGENTS.md')),
1251
1264
  ours = fs.readFileSync(path.join(TOOL, 'AGENTS.md'), 'utf8'),
1252
1265
  record = paths.cache('agents.md');
1266
+ insideWorkspace(path.join(WS, 'CLAUDE.md'));
1253
1267
  // An AGENTS.md as cad agents last wrote it (or, with no record of that, one that is an earlier copy of ours) is
1254
1268
  // brought up to date; one edited here is kept, unless --force
1255
1269
  const mine = fs.existsSync(to) ? fs.readFileSync(to, 'utf8') : null,
@@ -2436,7 +2450,9 @@ async function since(d) {
2436
2450
  function onlyChanged(allowed) {
2437
2451
  let porcelain, prefix;
2438
2452
  try {
2439
- porcelain = git('status', '--porcelain', '--untracked-files=all', '--', '.');
2453
+ // (--ignore-submodules=dirty: a submodule's own git, with its own settings, is not asked what changed in it; a
2454
+ // submodule moved to another commit still counts)
2455
+ porcelain = git('status', '--porcelain', '--untracked-files=all', '--ignore-submodules=dirty', '--', '.');
2440
2456
  prefix = git('rev-parse', '--show-prefix');
2441
2457
  } catch (e) {
2442
2458
  if (/not a git repository/.test(e.stderr || e.message)) return; // (a dry run outside git: a release is refused first)
@@ -2507,10 +2523,18 @@ function commitAndTag(paths, subject, tag, message, kept) {
2507
2523
  }
2508
2524
  let step = 'commit';
2509
2525
  try {
2510
- git('add', '--', ...paths);
2511
- git('commit', '-q', '-m', subject, ...(opt('trailer') ? ['--trailer', opt('trailer')] : []), '--', ...paths); // only these, whatever else is staged
2526
+ gitAsByHand('add', '--', ...paths);
2527
+ gitAsByHand(
2528
+ 'commit',
2529
+ '-q',
2530
+ '-m',
2531
+ subject,
2532
+ ...(opt('trailer') ? ['--trailer', opt('trailer')] : []),
2533
+ '--',
2534
+ ...paths,
2535
+ ); // only these, whatever else is staged
2512
2536
  step = 'tag';
2513
- git('tag', '-a', tag, '-m', message);
2537
+ gitAsByHand('tag', '-a', tag, '-m', message);
2514
2538
  } catch (e) {
2515
2539
  let undone = true;
2516
2540
  try {
@@ -2532,8 +2556,8 @@ function commitAndTag(paths, subject, tag, message, kept) {
2532
2556
  }
2533
2557
  if (opt('push'))
2534
2558
  try {
2535
- git('push', '-q', 'origin', 'HEAD');
2536
- git('push', '-q', 'origin', tag);
2559
+ gitAsByHand('push', '-q', 'origin', 'HEAD');
2560
+ gitAsByHand('push', '-q', 'origin', tag);
2537
2561
  } catch (e) {
2538
2562
  throw new Error(
2539
2563
  `released and tagged ${tag} here, but not pushed: git said ${gitSaid(e)}. Push it when you can: git push --follow-tags`,
@@ -3521,7 +3545,7 @@ function printed(d) {
3521
3545
  console.log(`logged in ${path.relative(WS, printsFile(d))}: ${d.name}@${version} ${result}`);
3522
3546
  }
3523
3547
 
3524
- main().catch((e) => {
3548
+ main().catch(async (e) => {
3525
3549
  if (opt('json'))
3526
3550
  console.log(
3527
3551
  JSON.stringify(
@@ -3534,5 +3558,9 @@ main().catch((e) => {
3534
3558
  console.error(
3535
3559
  `${e.message}${e.file ? ` (${path.relative(WS, e.file)}${e.line ? `:${e.line}` : ''}${e.path ? `: ${e.path}` : ''})` : ''}`,
3536
3560
  );
3561
+ // Nothing of this command is left running in the workspace once it returns (a script may move or remove the folder
3562
+ // straight after, which Windows refuses while a process sits in it): a command that ends by itself waits in
3563
+ // sandbox.mjs; this one exits here, so it waits here
3564
+ await endSandbox();
3537
3565
  process.exit(1);
3538
3566
  });