@rulecad/cad 0.8.0 → 0.9.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.
Files changed (83) hide show
  1. package/AGENTS.md +24 -10
  2. package/CHANGELOG.md +404 -0
  3. package/EXAMPLES.md +40 -38
  4. package/README.md +193 -67
  5. package/TUTORIAL.md +2 -2
  6. package/bin/cad.mjs +2250 -512
  7. package/lib/animate.mjs +173 -49
  8. package/lib/assembly.mjs +1847 -434
  9. package/lib/beams.mjs +256 -52
  10. package/lib/belts.mjs +66 -15
  11. package/lib/board-work.mjs +12 -0
  12. package/lib/bought.mjs +309 -53
  13. package/lib/buildpage.mjs +179 -29
  14. package/lib/carried.mjs +201 -0
  15. package/lib/clone.mjs +194 -42
  16. package/lib/design.mjs +649 -121
  17. package/lib/drive.mjs +187 -63
  18. package/lib/edit.mjs +899 -191
  19. package/lib/errors.mjs +16 -3
  20. package/lib/explain.mjs +62 -13
  21. package/lib/fasten.mjs +2702 -507
  22. package/lib/fittings.mjs +715 -121
  23. package/lib/fixings.mjs +21 -9
  24. package/lib/framebuild.mjs +790 -175
  25. package/lib/framecheck.mjs +1901 -368
  26. package/lib/framegen.mjs +100 -22
  27. package/lib/frameheat.mjs +225 -42
  28. package/lib/frameprint.mjs +513 -108
  29. package/lib/frames.mjs +81 -17
  30. package/lib/framesize.mjs +792 -120
  31. package/lib/frametip.mjs +235 -0
  32. package/lib/gait.mjs +135 -23
  33. package/lib/grip.mjs +62 -13
  34. package/lib/guides.mjs +1403 -230
  35. package/lib/host.mjs +123 -21
  36. package/lib/inplace.mjs +171 -36
  37. package/lib/jigs.mjs +360 -78
  38. package/lib/joins.mjs +697 -118
  39. package/lib/jsonedit.mjs +88 -26
  40. package/lib/kept.mjs +84 -0
  41. package/lib/kit.mjs +438 -68
  42. package/lib/layout.mjs +2 -1
  43. package/lib/links.mjs +149 -42
  44. package/lib/list.mjs +326 -64
  45. package/lib/live-guard.mjs +68 -0
  46. package/lib/live-shape.mjs +96 -24
  47. package/lib/live.mjs +189 -59
  48. package/lib/loads.mjs +579 -130
  49. package/lib/machine.mjs +372 -74
  50. package/lib/magnets.mjs +162 -44
  51. package/lib/measured.mjs +417 -94
  52. package/lib/mesh.mjs +526 -119
  53. package/lib/meshcmd.mjs +215 -60
  54. package/lib/motors.mjs +1021 -213
  55. package/lib/motorsvg.mjs +114 -32
  56. package/lib/names.mjs +3 -1
  57. package/lib/optimise.mjs +978 -283
  58. package/lib/order.mjs +519 -112
  59. package/lib/panels.mjs +482 -94
  60. package/lib/parts.mjs +78 -23
  61. package/lib/pins.mjs +163 -44
  62. package/lib/plates.mjs +223 -35
  63. package/lib/player.mjs +37 -9
  64. package/lib/power.mjs +64 -13
  65. package/lib/preview.mjs +83 -16
  66. package/lib/profilemeasure.mjs +572 -129
  67. package/lib/rules.mjs +15 -5
  68. package/lib/sandbox-hooks.mjs +77 -19
  69. package/lib/sandbox-run.mjs +117 -18
  70. package/lib/sandbox.mjs +509 -60
  71. package/lib/schema.mjs +42 -11
  72. package/lib/seats.mjs +227 -49
  73. package/lib/services.mjs +261 -52
  74. package/lib/sheet.mjs +851 -178
  75. package/lib/slotnuts.mjs +213 -34
  76. package/lib/targets/gist.mjs +4 -1
  77. package/lib/targets.mjs +22 -4
  78. package/lib/task.mjs +376 -79
  79. package/lib/versions.mjs +111 -28
  80. package/lib/wires.mjs +228 -45
  81. package/lib/workspace.mjs +197 -12
  82. package/package.json +19 -19
  83. package/schemas/assembly.schema.json +2 -2
package/lib/sandbox.mjs CHANGED
@@ -17,16 +17,22 @@
17
17
  // from. The autorouter's results come back the same way as a lamina's stages, for the tool to keep.
18
18
  import fs from 'node:fs';
19
19
  import path from 'node:path';
20
- import { spawn } from 'node:child_process';
20
+ import { spawn, execFile } from 'node:child_process';
21
+ import { constants as bufferConstants } from 'node:buffer';
21
22
  import * as nodeModule from 'node:module';
22
23
  import { pathToFileURL, fileURLToPath } from 'node:url';
23
- import { WS, TOOL, config, paths, trusted } from './workspace.mjs';
24
+ import { WS, TOOL, config, trusted, DESIGN_TIMEOUT, DESIGN_MEMORY, ownFile } from './workspace.mjs';
24
25
  import { fromFaces } from './parts.mjs';
25
26
  import { located } from './errors.mjs';
27
+ import { STAGES_MOST, ROUTES_MOST } from './kept.mjs';
26
28
 
27
29
  const flag = (() => {
28
30
  const f = process.allowedNodeEnvironmentFlags;
29
- return f.has('--permission') ? '--permission' : f.has('--experimental-permission') ? '--experimental-permission' : null;
31
+ return f.has('--permission')
32
+ ? '--permission'
33
+ : f.has('--experimental-permission')
34
+ ? '--experimental-permission'
35
+ : null;
30
36
  })();
31
37
 
32
38
  const inThread = typeof nodeModule.registerHooks === 'function'; // import hooks in this thread; older Node needs a worker for them
@@ -36,18 +42,64 @@ const inThread = typeof nodeModule.registerHooks === 'function'; // import hooks
36
42
  export const sandboxed = () => !!flag && process.env.CAD_TRUST !== '1' && !(config.sandbox === false && trusted());
37
43
 
38
44
  // What the sandbox may read: the workspace, and the packages designs and the runner load (wherever npm put them), and
39
- // what those load in turn (@rulecad/frames sizes a beam's operations through @rulecad/fixings)
45
+ // what those load in turn (@rulecad/frames sizes a beam's operations through @rulecad/fixings). Node's permission
46
+ // model follows a link inside these folders wherever it leads, so a link in the design's project or rules/ that leads
47
+ // out of the workspace is refused before the sandbox starts (workspace.mjs noLinksOut, from design.mjs).
40
48
  function readable({ board = false, extra = [] } = {}) {
41
- const real = (p) => { try { return fs.realpathSync(p); } catch { return null; } };
42
- const pkgDir = (name, from) => { // the package's folder: from its entry up to its package.json (exports may hide that file)
43
- try { let d = path.dirname(nodeModule.createRequire(from).resolve(name)); while (!fs.existsSync(path.join(d, 'package.json')) && path.dirname(d) !== d) d = path.dirname(d); return d; } catch { return null; }
49
+ const real = (p) => {
50
+ try {
51
+ return fs.realpathSync(p);
52
+ } catch {
53
+ return null;
54
+ }
44
55
  };
45
- const fromWs = path.join(WS, 'package.json'), fromTool = path.join(TOOL, 'package.json');
56
+ const pkgDir = (name, from) => {
57
+ // the package's folder: from its entry up to its package.json (exports may hide that file)
58
+ try {
59
+ let d = path.dirname(nodeModule.createRequire(from).resolve(name));
60
+ while (!fs.existsSync(path.join(d, 'package.json')) && path.dirname(d) !== d) d = path.dirname(d);
61
+ return d;
62
+ } catch {
63
+ return null;
64
+ }
65
+ };
66
+ const fromWs = path.join(WS, 'package.json'),
67
+ fromTool = path.join(TOOL, 'package.json');
46
68
  // Every node_modules above the workspace and the tool (package lookups read their links), and where links lead
47
- const up = (dir) => { const out = []; for (let d = dir; ; d = path.dirname(d)) { out.push(path.join(d, 'node_modules')); if (path.dirname(d) === d) return out; } };
48
- const dirs = [WS, TOOL, ...[...up(WS), ...up(TOOL)].filter((d) => fs.existsSync(d)),
49
- ...['@jscad/modeling', '@rulecad/shapes', '@rulecad/flexures', '@rulecad/gears', '@rulecad/motors', '@rulecad/frames', '@rulecad/fixings', '@rulecad/rules/x1c.json', '@rulecad/fea', '@rulecad/variables', 'manifold-3d'].flatMap((n) => [pkgDir(n, fromWs), pkgDir(n, fromTool)]), ...extra];
50
- const out = [...new Set(dirs.filter(Boolean).flatMap((d) => [d, real(d)]).filter(Boolean))];
69
+ const up = (dir) => {
70
+ const out = [];
71
+ for (let d = dir; ; d = path.dirname(d)) {
72
+ out.push(path.join(d, 'node_modules'));
73
+ if (path.dirname(d) === d) return out;
74
+ }
75
+ };
76
+ const dirs = [
77
+ WS,
78
+ TOOL,
79
+ ...[...up(WS), ...up(TOOL)].filter((d) => fs.existsSync(d)),
80
+ ...[
81
+ '@jscad/modeling',
82
+ '@rulecad/shapes',
83
+ '@rulecad/flexures',
84
+ '@rulecad/gears',
85
+ '@rulecad/motors',
86
+ '@rulecad/frames',
87
+ '@rulecad/fixings',
88
+ '@rulecad/rules/x1c.json',
89
+ '@rulecad/fea',
90
+ '@rulecad/variables',
91
+ 'manifold-3d',
92
+ ].flatMap((n) => [pkgDir(n, fromWs), pkgDir(n, fromTool)]),
93
+ ...extra,
94
+ ];
95
+ const out = [
96
+ ...new Set(
97
+ dirs
98
+ .filter(Boolean)
99
+ .flatMap((d) => [d, real(d)])
100
+ .filter(Boolean),
101
+ ),
102
+ ];
51
103
  // A board's engine loads tscircuit's packages and @rulecad's own (smooth, rules, fixings): what it depends on, and
52
104
  // what they do in turn, wherever each really is. Most are in a node_modules listed above; a package linked in from
53
105
  // elsewhere (a workspace of packages, as rulecad's own repository is) is added by its real folder.
@@ -63,20 +115,52 @@ const PACKAGE_NAME = /^(@[a-z0-9][\w.~-]*\/)?[a-z0-9][\w.~-]*$/i;
63
115
  // "dependencies" that lead out of it (a link, a path) would have the sandbox read wherever they lead. Each dependency is
64
116
  // a package name, and its folder one whose package.json has that name.
65
117
  function engineFolders(out, real, pkgDir, from) {
66
- const found = [], seen = new Set(), under = (d) => out.some((o) => d === o || d.startsWith(o + path.sep));
67
- const named = (d, n) => { try { return JSON.parse(fs.readFileSync(path.join(d, 'package.json'), 'utf8')).name === n; } catch { return false; } };
118
+ const found = [],
119
+ seen = new Set(),
120
+ under = (d) => out.some((o) => d === o || d.startsWith(o + path.sep));
121
+ const named = (d, n) => {
122
+ try {
123
+ return JSON.parse(fs.readFileSync(path.join(d, 'package.json'), 'utf8')).name === n;
124
+ } catch {
125
+ return false;
126
+ }
127
+ };
68
128
  // (the folder found, or the one above it of that name: by its entry, a package's dist/package.json may be found first,
69
129
  // but never above the node_modules it is in)
70
- const own = (d, n) => { for (; d && path.basename(d) !== 'node_modules' && path.dirname(d) !== d; d = path.dirname(d)) if (named(d, n)) return d; return null; };
71
- const add = (d, n) => { d = d && own(d, n); if (!d || seen.has(d)) return; seen.add(d); if (!under(d)) found.push(d); walk(d); };
72
- const find = (n, dir) => { // (findPackageJSON where Node has it: exports that hide a package's entry from require don't hide this)
130
+ const own = (d, n) => {
131
+ for (; d && path.basename(d) !== 'node_modules' && path.dirname(d) !== d; d = path.dirname(d))
132
+ if (named(d, n)) return d;
133
+ return null;
134
+ };
135
+ const add = (d, n) => {
136
+ d = d && own(d, n);
137
+ if (!d || seen.has(d)) return;
138
+ seen.add(d);
139
+ if (!under(d)) found.push(d);
140
+ walk(d);
141
+ };
142
+ const find = (n, dir) => {
143
+ // (findPackageJSON where Node has it: exports that hide a package's entry from require don't hide this)
73
144
  const at = path.join(dir, 'package.json');
74
- try { if (nodeModule.findPackageJSON) { const f = nodeModule.findPackageJSON(n, pathToFileURL(at)); if (f) return real(path.dirname(f)); } } catch { /* by its entry, below */ }
145
+ try {
146
+ if (nodeModule.findPackageJSON) {
147
+ const f = nodeModule.findPackageJSON(n, pathToFileURL(at));
148
+ if (f) return real(path.dirname(f));
149
+ }
150
+ } catch {
151
+ /* by its entry, below */
152
+ }
75
153
  return real(pkgDir(n, at) || '');
76
154
  };
77
155
  function walk(dir) {
78
- let j; try { j = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')); } catch { return; }
79
- for (const n of Object.keys({ ...j.dependencies, ...j.optionalDependencies, ...j.peerDependencies })) if (PACKAGE_NAME.test(n)) add(find(n, dir), n);
156
+ let j;
157
+ try {
158
+ j = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
159
+ } catch {
160
+ return;
161
+ }
162
+ for (const n of Object.keys({ ...j.dependencies, ...j.optionalDependencies, ...j.peerDependencies }))
163
+ if (PACKAGE_NAME.test(n)) add(find(n, dir), n);
80
164
  }
81
165
  add(real(pkgDir('@rulecad/pcb', from) || ''), '@rulecad/pcb');
82
166
  return found;
@@ -87,7 +171,14 @@ function engineFolders(out, real, pkgDir, from) {
87
171
  // are reached through a node_modules link spelled through it, which the sandbox follows by its real path and may not.
88
172
  function refused(e) {
89
173
  if (e.code !== 'design.sandbox' || !e.resource) return e.message;
90
- const res = e.resource, to = (() => { try { return fs.lstatSync(res).isSymbolicLink() ? fs.realpathSync(res) : null; } catch { return null; } })();
174
+ const res = e.resource,
175
+ to = (() => {
176
+ try {
177
+ return fs.lstatSync(res).isSymbolicLink() ? fs.realpathSync(res) : null;
178
+ } catch {
179
+ return null;
180
+ }
181
+ })();
91
182
  const trust = 'or trust the workspace ("sandbox": false in cad.config.json, then cad trust)';
92
183
  return to
93
184
  ? `the design's sandbox was refused ${res}, a link to ${to}: something the design loads is reached through it (a node_modules link spelled through ${res}, most likely). Make that link with its real path (ln -s "$(pwd -P)/node_modules"), ${trust}`
@@ -98,27 +189,58 @@ function refused(e) {
98
189
  // stdout the reply is read from, and end the process before the runner prints the real one. So every field is checked
99
190
  // before it is used (checkReply), and the only thing written from it is a stage of the cache: under a key of the form
100
191
  // the stage cache makes (@rulecad/flexures cache.mjs: `${name}-${sha256 hex}`, a name such as "physics" or "flood
101
- // probe"), as a file directly in the stages folder (stageFile). A reply that is not one the runner makes is refused
192
+ // probe"), as a file directly in the design's own stages folder (stageFile), which only that design reads: a key is a
193
+ // hash anyone can work out, so a stage handed back under another design's key must never be read by that design. A
194
+ // reply that is not one the runner makes, or that hands back more stages than a build makes (STAGES_MOST), is refused
102
195
  // whole, with nothing written.
103
196
 
197
+ // A cache folder the sandbox reads (the stages, the routes): one of the workspace's only where it really is inside it.
198
+ // A cloned workspace's .cache/ that is a link to a folder elsewhere is not read from (null: every stage a miss), and the
199
+ // runner reads a file of the folder only where it really is in it (sandbox-run.mjs fromFolder).
200
+ const ownFolder = (dir) => {
201
+ try {
202
+ return ownFile(dir);
203
+ } catch (e) {
204
+ if (e.code === 'workspace.outside') return null;
205
+ throw e;
206
+ }
207
+ };
208
+
104
209
  /** The form of a stage's key, as the stage cache makes it: a stage's name, a dash and the 64 hex digits of a SHA-256. */
105
210
  export const STAGE_KEY = /^[a-z][a-z0-9 _-]{0,39}-[0-9a-f]{64}$/;
106
211
 
212
+ // How many stages one reply may hand back, and how much text in all (kept.mjs, which the runner keeps to): a reply past
213
+ // either is refused whole, since it would fill the disk, or push the design's honest stages out of its folder of the
214
+ // cache. Routes likewise.
215
+ export { STAGES_MOST, ROUTES_MOST };
216
+ // What is wrong with a reply's stages or routes past its cap, or null
217
+ const overCap = (o, most, what) => {
218
+ const all = Object.values(o),
219
+ bytes = all.reduce((n, text) => n + Buffer.byteLength(text, 'utf8'), 0);
220
+ if (all.length > most.count) return `it hands back ${all.length} ${what}, more than the ${most.count} a build makes`;
221
+ if (bytes > most.bytes) return `it hands back ${bytes} bytes of ${what}, more than the ${most.bytes} a build makes`;
222
+ return null;
223
+ };
224
+
107
225
  /**
108
226
  * The file a stage of the cache is kept in, or null when its key would put it anywhere but directly in `dir`.
109
227
  * @param {string} dir the stages folder @param {unknown} key @returns {string | null}
110
228
  */
111
229
  export function stageFile(dir, key) {
112
230
  if (typeof key !== 'string' || !key) return null;
113
- const file = path.resolve(dir, `${key}.json`), rel = path.relative(path.resolve(dir), file);
231
+ const file = path.resolve(dir, `${key}.json`),
232
+ rel = path.relative(path.resolve(dir), file);
114
233
  return rel && !path.isAbsolute(rel) && !rel.split(/[\\/]/).includes('..') && path.basename(rel) === rel ? file : null;
115
234
  }
116
235
 
117
- const plain = (x) => x !== null && typeof x === 'object' && !Array.isArray(x) && Object.getPrototypeOf(x) === Object.prototype;
236
+ const plain = (x) =>
237
+ x !== null && typeof x === 'object' && !Array.isArray(x) && Object.getPrototypeOf(x) === Object.prototype;
118
238
  const point = (p) => Array.isArray(p) && p.length === 3 && p.every((n) => typeof n === 'number' && Number.isFinite(n));
119
239
  const faceList = (x) => Array.isArray(x) && x.every((f) => Array.isArray(f) && f.every(point));
120
- const PART = { name: 'string', role: 'string', label: 'string', filament: 'string', mirror: 'boolean' }, PART_FACES = ['solid', 'polygons', 'triangles'];
121
- const REPLY = ['parts', 'read', 'mechanism', 'fixings', 'stages', 'board', 'mounted', 'routes'], ERROR = { message: 'string', code: 'string', line: 'number', syntax: 'boolean', resource: 'string' };
240
+ const PART = { name: 'string', role: 'string', label: 'string', filament: 'string', mirror: 'boolean' },
241
+ PART_FACES = ['solid', 'polygons', 'triangles'];
242
+ const REPLY = ['parts', 'read', 'mechanism', 'fixings', 'stages', 'board', 'mounted', 'routes'],
243
+ ERROR = { message: 'string', code: 'string', line: 'number', syntax: 'boolean', resource: 'string' };
122
244
  const fields = (o, kinds) => Object.entries(o).find(([k, x]) => !(k in kinds) || typeof x !== kinds[k]);
123
245
 
124
246
  /** The form of a route's key, as @rulecad/pcb's route cache makes it: the 64 hex digits of a SHA-256. */
@@ -138,9 +260,10 @@ function checkBoard(b) {
138
260
  if (!plain(b)) return 'its board is not an object';
139
261
  const extra = Object.keys(b).find((k) => !['circuit', 'matrix', 'source'].includes(k));
140
262
  if (extra) return `its board has a field "${extra}" the runner doesn't send`;
141
- if (!Array.isArray(b.circuit) || !b.circuit.length || !b.circuit.every((e) => plain(e) && typeof e.type === 'string')) return 'its board\'s circuit is not a list of circuit elements';
142
- if (b.matrix != null && !(plain(b.matrix) || Array.isArray(b.matrix))) return 'its board\'s matrix is not an object';
143
- if (b.source != null && !plain(b.source)) return 'its board\'s source is not an object';
263
+ if (!Array.isArray(b.circuit) || !b.circuit.length || !b.circuit.every((e) => plain(e) && typeof e.type === 'string'))
264
+ return "its board's circuit is not a list of circuit elements";
265
+ if (b.matrix != null && !(plain(b.matrix) || Array.isArray(b.matrix))) return "its board's matrix is not an object";
266
+ if (b.source != null && !plain(b.source)) return "its board's source is not an object";
144
267
  if (polluting(b)) return 'its board has a field named __proto__';
145
268
  return null;
146
269
  }
@@ -148,40 +271,58 @@ function checkBoard(b) {
148
271
  /**
149
272
  * What is wrong with a reply from the sandbox's runner, in a few words, or null when it is one the runner makes:
150
273
  * `{ parts, read, mechanism?, fixings?, stages? }`, a board design's `{ parts: [], read, board: { circuit, matrix?,
151
- * source? }, mounted?, fixings?, routes? }`, or `{ error }`.
152
- * @param {unknown} r the child's stdout, parsed @returns {string | null}
274
+ * source? }, mounted?, fixings?, routes? }`, or `{ error }`. Its stages no more than `stagesMost` (STAGES_MOST), its
275
+ * routes no more than ROUTES_MOST.
276
+ * @param {unknown} r the child's stdout, parsed
277
+ * @param {{ count: number, bytes: number }} [stagesMost] @returns {string | null}
153
278
  */
154
- export function checkReply(r) {
279
+ export function checkReply(r, stagesMost = STAGES_MOST) {
155
280
  if (!plain(r)) return 'it is not an object';
156
281
  if ('error' in r) {
157
282
  if (Object.keys(r).length !== 1 || !plain(r.error)) return 'its error is not one the runner makes';
158
283
  const bad = fields(r.error, ERROR);
159
- return bad ? `its error's ${bad[0]} is not one the runner makes` : typeof r.error.message !== 'string' ? 'its error has no message' : null;
284
+ return bad
285
+ ? `its error's ${bad[0]} is not one the runner makes`
286
+ : typeof r.error.message !== 'string'
287
+ ? 'its error has no message'
288
+ : null;
160
289
  }
161
290
  const extra = Object.keys(r).find((k) => !REPLY.includes(k));
162
291
  if (extra) return `it has a field "${extra}" the runner doesn't send`;
163
292
  if (!Array.isArray(r.parts)) return 'it has no list of parts';
164
293
  for (const p of r.parts) {
165
294
  if (!plain(p)) return 'a part is not an object';
166
- const bad = Object.entries(p).find(([k, x]) => !(PART_FACES.includes(k) ? faceList(x) : k in PART && typeof x === PART[k]));
295
+ const bad = Object.entries(p).find(
296
+ ([k, x]) => !(PART_FACES.includes(k) ? faceList(x) : k in PART && typeof x === PART[k]),
297
+ );
167
298
  if (bad) return `a part's ${bad[0]} is not one the runner makes`;
168
299
  if (typeof p.name !== 'string' || PART_FACES.some((k) => !(k in p))) return 'a part has no name or no faces';
169
300
  }
170
- if (!Array.isArray(r.read) || !r.read.every((n) => typeof n === 'string')) return 'what it read is not a list of names';
301
+ if (!Array.isArray(r.read) || !r.read.every((n) => typeof n === 'string'))
302
+ return 'what it read is not a list of names';
171
303
  if (r.mechanism != null && !plain(r.mechanism)) return 'its mechanism is not an object';
172
- if (r.fixings != null && !(Array.isArray(r.fixings) && r.fixings.every(plain))) return 'its fixings are not a list of findings';
304
+ if (r.fixings != null && !(Array.isArray(r.fixings) && r.fixings.every(plain)))
305
+ return 'its fixings are not a list of findings';
173
306
  if (r.stages != null) {
174
307
  if (!plain(r.stages)) return 'its stages are not an object';
175
308
  const bad = Object.entries(r.stages).find(([k, text]) => !STAGE_KEY.test(k) || typeof text !== 'string');
176
- if (bad) return STAGE_KEY.test(bad[0]) ? 'a stage is not text' : 'a stage\'s key is not one the stage cache makes';
309
+ if (bad) return STAGE_KEY.test(bad[0]) ? 'a stage is not text' : "a stage's key is not one the stage cache makes";
310
+ const over = overCap(r.stages, stagesMost, 'slow stages');
311
+ if (over) return over;
312
+ }
313
+ if (r.board != null) {
314
+ const bad = checkBoard(r.board);
315
+ if (bad) return bad;
316
+ if (r.parts.length) return "a board's reply has parts of its own";
177
317
  }
178
- if (r.board != null) { const bad = checkBoard(r.board); if (bad) return bad; if (r.parts.length) return 'a board\'s reply has parts of its own'; }
179
318
  if (r.mounted != null && typeof r.mounted !== 'boolean') return 'its "mounted" is not true or false';
180
319
  if (r.routes != null) {
181
320
  if (r.board == null) return 'it has routes but no board';
182
321
  if (!plain(r.routes)) return 'its routes are not an object';
183
322
  const bad = Object.entries(r.routes).find(([k, text]) => !ROUTE_KEY.test(k) || typeof text !== 'string');
184
- if (bad) return ROUTE_KEY.test(bad[0]) ? 'a route is not text' : 'a route\'s key is not one the route cache makes';
323
+ if (bad) return ROUTE_KEY.test(bad[0]) ? 'a route is not text' : "a route's key is not one the route cache makes";
324
+ const over = overCap(r.routes, ROUTES_MOST, 'routes');
325
+ if (over) return over;
185
326
  }
186
327
  if (r.mechanism != null && polluting(r.mechanism)) return 'its mechanism has a field named __proto__';
187
328
  return null;
@@ -190,6 +331,146 @@ export function checkReply(r) {
190
331
  /** Whether designs can be sandboxed here at all: Node has the permission model. */
191
332
  export const canSandbox = () => !!flag;
192
333
 
334
+ // How long a design may run and how much memory it may use, in the sandbox. A design with an endless loop would
335
+ // otherwise hang every command that builds it, with no word said, and one that fills memory without end would grow
336
+ // until the system stopped it, taking other work with it. Past either limit the design's process is stopped, and the
337
+ // build fails with design.time or design.memory, naming the design. The time limit was set from the kit's slowest
338
+ // example built from nothing: the launcher's in-line action (examples/projects/launcher, its physics and flooded
339
+ // frame) took 2210 s, 1766 s of it working, on an 8 GB laptop shared with other work (November 2026), so an hour
340
+ // leaves room; the memory limit is the most the design's JavaScript may hold, and its process as a whole may hold
341
+ // MEMORY_ROOM more (Node itself, and what lies outside the JavaScript: typed arrays, WebAssembly memory, output not
342
+ // yet sent), watched from here. What the design sends back or prints is kept here only up to a bound, so it can't
343
+ // fill this process instead. A workspace's cad.config.json that raises a limit above the default is used once the
344
+ // workspace is trusted (cad trust), as "sandbox": false is: until then the default holds. A trusted workspace
345
+ // ("sandbox": false) runs its designs in the tool's own process, without either limit.
346
+ export { DESIGN_TIMEOUT, DESIGN_MEMORY };
347
+ /** How much more than the design's memory limit its process as a whole may hold, in megabytes. */
348
+ export const MEMORY_ROOM = 512;
349
+
350
+ /**
351
+ * The time and memory limits a design runs under in the sandbox: CAD_DESIGN_TIMEOUT (seconds) and CAD_DESIGN_MEMORY
352
+ * (megabytes) if set, else cad.config.json's "designTimeout" and "designMemory", else 3600 s and 4096 MB. A value that
353
+ * is not a number above nothing is refused, with what to write, rather than left to run without a limit. A value in
354
+ * cad.config.json above the default is used only once the workspace is trusted; until then the default is, and held
355
+ * says what the workspace asked for.
356
+ * @param {Record<string, string | undefined>} [env] @param {{ designTimeout?: unknown, designMemory?: unknown }} [cfg]
357
+ * @param {() => boolean} [ok] whether the workspace is trusted for what it asks
358
+ * @returns {{ timeout: number, memory: number, held?: { timeout?: number, memory?: number } }} timeout in seconds, memory in megabytes
359
+ */
360
+ export function designLimits(env = process.env, cfg = config, ok = () => trusted(cfg)) {
361
+ const held = {};
362
+ const one = (name, key, fallback, unit, least, which) => {
363
+ const fromEnv = env[name] != null && env[name] !== '';
364
+ const raw = fromEnv ? env[name] : cfg[key];
365
+ if (raw == null) return fallback;
366
+ const n = typeof raw === 'number' ? raw : typeof raw === 'string' && raw.trim() ? Number(raw) : NaN;
367
+ if (Number.isFinite(n) && n >= least) {
368
+ if (fromEnv || n <= fallback || ok()) return n;
369
+ held[which] = n; // (a cloned workspace can't take the limits away by itself: cad trust)
370
+ return fallback;
371
+ }
372
+ const where = fromEnv ? name : `"${key}" in cad.config.json`;
373
+ throw Object.assign(
374
+ new Error(
375
+ `${where} is ${JSON.stringify(raw)}: it should be a number of ${unit} (at least ${least}), as ${fallback}, the default`,
376
+ ),
377
+ { code: 'design.limit', ...(fromEnv ? {} : { file: 'cad.config.json', path: key }) },
378
+ );
379
+ };
380
+ const timeout = one('CAD_DESIGN_TIMEOUT', 'designTimeout', DESIGN_TIMEOUT, 'seconds', 0.1, 'timeout'),
381
+ memory = Math.round(one('CAD_DESIGN_MEMORY', 'designMemory', DESIGN_MEMORY, 'megabytes', 16, 'memory'));
382
+ return { timeout, memory, ...(Object.keys(held).length ? { held } : {}) };
383
+ }
384
+ // What a workspace's raised limit, held back until it is trusted, adds to the message of a design stopped at the limit
385
+ const heldBack = (n, unit) =>
386
+ n != null
387
+ ? ` (this workspace's cad.config.json asks for ${n} ${unit}: that is used once you trust it, with cad trust)`
388
+ : '';
389
+
390
+ /**
391
+ * The memory a process holds, in bytes (its resident set: what it has in the machine's memory), or null where that
392
+ * can't be told. Read from /proc on Linux, from ps on other Unix systems and from tasklist on Windows.
393
+ * @param {number} pid @returns {Promise<number | null>}
394
+ */
395
+ export function processMemory(pid) {
396
+ return new Promise((resolve) => {
397
+ if (process.platform === 'linux') {
398
+ try {
399
+ const m = /VmRSS:\s*(\d+)\s*kB/.exec(fs.readFileSync(`/proc/${pid}/status`, 'utf8'));
400
+ return resolve(m ? Number(m[1]) * 1024 : null);
401
+ } catch {
402
+ return resolve(null);
403
+ }
404
+ }
405
+ const [cmd, args, read] =
406
+ process.platform === 'win32'
407
+ ? [
408
+ 'tasklist',
409
+ ['/FI', `PID eq ${pid}`, '/FO', 'CSV', '/NH'],
410
+ (t) => /"([\d.,\s\u00a0]+)\s*K"\s*$/m.exec(t)?.[1],
411
+ ]
412
+ : ['ps', ['-o', 'rss=', '-p', String(pid)], (t) => /^\s*(\d+)\s*$/.exec(t)?.[1]];
413
+ execFile(cmd, args, { windowsHide: true, timeout: 5000 }, (e, text) => {
414
+ const kb = e ? null : read(String(text));
415
+ resolve(kb ? Number(kb.replace(/\D/g, '')) * 1024 : null);
416
+ });
417
+ });
418
+ }
419
+ // How often the design's process's memory is looked at, in milliseconds
420
+ const WATCH_EVERY = 250;
421
+ // On a Mac, memory the system has squeezed (compressed) or set aside on disk leaves the resident set, so a process can
422
+ // hold far more than ps says once the machine is short of memory: footprint (the Mac's own tool) counts it, once a
423
+ // second as it runs
424
+ const FOOTPRINT = '/usr/bin/footprint';
425
+ /**
426
+ * Look at a process's memory until told to stop, and call over() once it holds more than most bytes.
427
+ * @param {number} pid @param {number} most @param {() => void} over @returns {() => void} stops looking
428
+ */
429
+ function watchMemory(pid, most, over) {
430
+ let looking = false,
431
+ ended = false;
432
+ const past = (held) => {
433
+ if (!ended && held != null && held > most) {
434
+ ended = true;
435
+ over();
436
+ }
437
+ };
438
+ const every = setInterval(() => {
439
+ if (looking || ended) return;
440
+ looking = true;
441
+ processMemory(pid).then((held) => {
442
+ looking = false;
443
+ past(held);
444
+ });
445
+ }, WATCH_EVERY);
446
+ every.unref();
447
+ let deep = null;
448
+ if (process.platform === 'darwin' && fs.existsSync(FOOTPRINT)) {
449
+ deep = spawn(FOOTPRINT, ['--sample', '1', '--noCategories', '-f', 'bytes', '-p', String(pid)], {
450
+ stdio: ['ignore', 'pipe', 'ignore'],
451
+ });
452
+ deep.on('error', () => {}); // (without it, ps alone)
453
+ let text = '';
454
+ deep.stdout.on('data', (b) => {
455
+ text += b;
456
+ const lines = text.split('\n');
457
+ text = lines.pop();
458
+ for (const l of lines) past(Number(/^\s*phys_footprint:\s*(\d+)\s*B/.exec(l)?.[1] ?? NaN) || null);
459
+ });
460
+ deep.unref();
461
+ deep.stdout.unref?.();
462
+ }
463
+ return () => {
464
+ ended = true;
465
+ clearInterval(every);
466
+ if (deep && deep.exitCode == null) deep.kill();
467
+ };
468
+ }
469
+ // The most of what the design prints that is kept, to pass on after it (its last lines: a crash's own words are there)
470
+ const PRINT_KEPT = 1 << 20;
471
+ // What Node prints as it stops a process whose JavaScript ran out of the memory it may hold (V8's own words)
472
+ const HEAP_DEATH = /JavaScript heap out of memory|Reached heap limit|Ineffective mark-compacts near heap limit/;
473
+
193
474
  /**
194
475
  * Run a design's main(values) in the sandbox: { parts, read, mechanism, fixings } as the build makes them, and for a
195
476
  * board design (board set) its { board: { circuit, matrix?, source? }, mounted } too, parts empty: the tool makes the
@@ -201,41 +482,209 @@ export const canSandbox = () => !!flag;
201
482
  * @param {object} request.values @param {object} request.meta the .json's parts
202
483
  * @param {'jscad' | 'manifold'} [request.engine] v.ops's booleans
203
484
  * @param {string[]} [request.optional] names main may read that aren't among the values (the display's own inputs)
204
- * @param {{ salt: string, get: (k: string) => string | undefined, put: (k: string, text: string) => void } | null} [request.stages] where a lamina's slow stages are kept: the child reads them from the cache (it may read the workspace) and hands back what it made, which is written here
485
+ * @param {{ dir: string, salt: string, get: (k: string) => string | undefined, put: (k: string, text: string) => void } | null} [request.stages] where a lamina's slow stages are kept: the child reads them from this design's own folder of the cache, dir (it may read the workspace), and hands back what it made, which is written there
205
486
  * @param {{ frames?: object, fixings?: { sets?: object, printer?: object, material?: string | null } | null }} [request.bound] what the design's helpers are bound to: frames, the workspace's profile sets (lib/frames.mjs framesContext); fixings, what v.fixings is bound to (design.mjs fixingsContext), whose calls come back as fixings. A board's v.pcb.mount reads fixings.sets too
206
- * @param {{ routes?: { dir: string, put: (k: string, text: string) => void } | null } | null} [request.board] set for a board design (engine pcb): routes, where the autorouter's results are kept (the child reads the folder; what it routes is handed back and put here)
487
+ * @param {{ routes?: { dir: string, shared?: string | null, put: (k: string, text: string) => void } | null } | null} [request.board] set for a board design (engine pcb): routes, where the autorouter's results are kept (the child reads this design's own folder, dir, then the route cache the tool's own process writes, shared; what it routes is handed back and put in dir only)
207
488
  * @param {string[]} [request.read] more folders the sandbox may read (a copy of a workspace held in memory)
208
489
  * @returns {Promise<{ parts: object[], read: Set<string>, mechanism: object | null, fixings: object[] | null, board?: { circuit: object[], matrix?: object, source?: object }, mounted?: boolean }>}
209
490
  */
210
- export function runSandboxed({ d, values, meta, engine = 'jscad', optional = [], stages = null, bound = {}, board = null, read: more = [] }) {
491
+ export function runSandboxed({
492
+ d,
493
+ values,
494
+ meta,
495
+ engine = 'jscad',
496
+ optional = [],
497
+ stages = null,
498
+ bound = {},
499
+ board = null,
500
+ read: more = [],
501
+ }) {
211
502
  const here = path.dirname(fileURLToPath(import.meta.url));
212
- const routes = board?.routes?.dir ? [path.resolve(board.routes.dir)] : []; // (a route cache the user put outside the workspace, RULECAD_ROUTE_CACHE: read there, or every build routes again)
213
- const args = [flag, ...readable({ board: !!board, extra: [...more, ...routes] }).map((p) => `--allow-fs-read=${p}`), ...(inThread ? [] : ['--allow-worker']), '--import', pathToFileURL(path.join(here, 'sandbox-preload.mjs')).href, path.join(here, 'sandbox-run.mjs')];
503
+ const routes = board?.routes?.shared ? [path.resolve(board.routes.shared)] : []; // (a route cache the user put outside the workspace, RULECAD_ROUTE_CACHE: read there, or every build routes again)
504
+ let limits;
505
+ try {
506
+ limits = designLimits();
507
+ } catch (e) {
508
+ return Promise.reject(located(e, d.js, 'design.limit'));
509
+ }
510
+ const args = [
511
+ flag,
512
+ `--max-old-space-size=${limits.memory}`,
513
+ ...readable({ board: !!board, extra: [...more, ...routes] }).map((p) => `--allow-fs-read=${p}`),
514
+ ...(inThread ? [] : ['--allow-worker']),
515
+ '--import',
516
+ pathToFileURL(path.join(here, 'sandbox-preload.mjs')).href,
517
+ path.join(here, 'sandbox-run.mjs'),
518
+ ];
214
519
  // (real paths: Node names an imported file by where it really is, so a workspace reached through a link still matches)
215
- const js = fs.realpathSync(d.js), project = pathToFileURL(path.dirname(path.dirname(js)) + path.sep).href, stagesDir = paths.cache('stages');
520
+ const js = fs.realpathSync(d.js),
521
+ project = pathToFileURL(path.dirname(path.dirname(js)) + path.sep).href;
216
522
  // The child gets none of this process's environment but what Node needs to start: tokens and keys stay out of it
217
- const env = Object.fromEntries(['PATH', 'SystemRoot', 'windir', 'TMPDIR', 'TEMP', 'TMP', 'LANG', 'LC_ALL', 'PHYS_DEBUG', 'LAMINA_TIMES'].filter((k) => process.env[k] != null).map((k) => [k, process.env[k]]));
523
+ const env = Object.fromEntries(
524
+ ['PATH', 'SystemRoot', 'windir', 'TMPDIR', 'TEMP', 'TMP', 'LANG', 'LC_ALL', 'PHYS_DEBUG', 'LAMINA_TIMES']
525
+ .filter((k) => process.env[k] != null)
526
+ .map((k) => [k, process.env[k]]),
527
+ );
218
528
  return new Promise((resolve, reject) => {
219
- const child = spawn(process.execPath, args, { stdio: ['pipe', 'pipe', 'pipe'], env: { ...env, CAD_SANDBOX_PROJECT: project, NODE_NO_WARNINGS: '1' } }); // (its stderr is passed on: what the design prints, not Node's notes on its own flags)
220
- const out = [], err = [];
221
- child.stdout.on('data', (b) => out.push(b));
222
- child.stderr.on('data', (b) => err.push(b));
223
- child.on('error', reject);
529
+ const child = spawn(process.execPath, args, {
530
+ stdio: ['pipe', 'pipe', 'pipe'],
531
+ env: { ...env, CAD_SANDBOX_PROJECT: project, NODE_NO_WARNINGS: '1' },
532
+ }); // (its stderr is passed on: what the design prints, not Node's notes on its own flags)
533
+ const MB = 1024 * 1024,
534
+ memoryMessage = (what) =>
535
+ `the design ${what}, so it was stopped: it may make shapes or lists without end. If it needs more, raise the limit: "designMemory" (megabytes) in cad.config.json, or CAD_DESIGN_MEMORY${heldBack(limits.held?.memory, 'MB')}`;
536
+ // What it sends back is kept up to what its JavaScript could hold (a reply is made there), and never past the
537
+ // longest text this process can read; what it prints, only its last PRINT_KEPT bytes
538
+ const replyMost = Math.min(limits.memory * MB, bufferConstants.MAX_STRING_LENGTH);
539
+ const out = [],
540
+ err = [];
541
+ let sent = 0,
542
+ kept = 0,
543
+ dropped = 0,
544
+ over = null; // (why the process was stopped: 'time', 'memory', 'reply')
545
+ const stop = (why) => {
546
+ if (over) return;
547
+ over = why;
548
+ child.kill('SIGKILL');
549
+ };
550
+ child.stdout.on('data', (b) => {
551
+ if (over) return;
552
+ sent += b.length;
553
+ if (sent > replyMost) return stop('reply');
554
+ out.push(b);
555
+ });
556
+ child.stderr.on('data', (b) => {
557
+ err.push(b);
558
+ kept += b.length;
559
+ while (kept - err[0].length >= PRINT_KEPT) {
560
+ kept -= err[0].length;
561
+ dropped += err.shift().length;
562
+ }
563
+ });
564
+ // The time limit: past it the process is stopped outright (a design can't catch SIGKILL, nor delay it with a loop)
565
+ // (a timer holds at most about 24 days: a longer limit would fire at once, so it waits that long instead)
566
+ const timer = setTimeout(() => stop('time'), Math.min(limits.timeout * 1000, 2 ** 31 - 1));
567
+ // The memory of the process as a whole, looked at from here (the design can't stop that)
568
+ const unwatch = watchMemory(child.pid, (limits.memory + MEMORY_ROOM) * MB, () => stop('memory'));
569
+ const done = () => {
570
+ clearTimeout(timer);
571
+ unwatch();
572
+ };
573
+ // Why the process was stopped from here, said as an error naming the design and the limit
574
+ const stopped = (why) =>
575
+ why === 'time'
576
+ ? located(
577
+ new Error(
578
+ `the design ran for longer than ${limits.timeout} s, so it was stopped: it may loop for ever. If it is only slow, raise the limit: "designTimeout" (seconds) in cad.config.json, or CAD_DESIGN_TIMEOUT${heldBack(limits.held?.timeout, 's')}`,
579
+ ),
580
+ d.js,
581
+ 'design.time',
582
+ )
583
+ : located(
584
+ new Error(
585
+ memoryMessage(
586
+ why === 'memory'
587
+ ? `held more than ${limits.memory + MEMORY_ROOM} MB in all (${limits.memory} MB for its JavaScript, and ${MEMORY_ROOM} MB more for the rest: typed arrays, WebAssembly memory, output)`
588
+ : `sent back more than ${Math.floor(replyMost / MB)} MB, more than a reply it could make`,
589
+ ),
590
+ ),
591
+ d.js,
592
+ 'design.memory',
593
+ );
594
+ child.on('error', (e) => {
595
+ done();
596
+ reject(e);
597
+ });
224
598
  child.on('close', () => {
599
+ done();
600
+ if (over) return reject(stopped(over));
225
601
  let r;
226
- try { r = JSON.parse(Buffer.concat(out).toString('utf8')); } catch {
227
- return reject(located(new Error(`the design's sandbox stopped: ${Buffer.concat(err).toString('utf8').trim().split('\n').slice(-3).join(' ') || 'no output'}`), d.js, 'design.sandbox'));
602
+ try {
603
+ r = JSON.parse(Buffer.concat(out).toString('utf8'));
604
+ } catch {
605
+ // No reply: the process stopped before it gave one. Node's own words say whether it ran out of memory
606
+ const said = Buffer.concat(err).toString('utf8');
607
+ if (HEAP_DEATH.test(said))
608
+ return reject(
609
+ located(
610
+ new Error(memoryMessage(`used more than the ${limits.memory} MB of memory it may`)),
611
+ d.js,
612
+ 'design.memory',
613
+ ),
614
+ );
615
+ return reject(
616
+ located(
617
+ new Error(`the design's sandbox stopped: ${said.trim().split('\n').slice(-3).join(' ') || 'no output'}`),
618
+ d.js,
619
+ 'design.sandbox',
620
+ ),
621
+ );
228
622
  }
623
+ if (dropped) process.stderr.write(`(the design printed ${dropped} bytes more before this, not kept)\n`);
229
624
  if (err.length) process.stderr.write(Buffer.concat(err)); // what the design printed
230
- const wrong = checkReply(r) || (!board && r.board != null ? 'it has a board, and the design is not one' : board && r.board == null && !r.error ? 'a board design\'s reply has no board' : null); // (every field is untrusted: see checkReply)
231
- if (wrong) return reject(located(new Error(`the design's reply was not one rulecad makes (${wrong}), so none of it was used and nothing it sent was written. A design gives back its shapes from main(v); one that writes to the process's output itself or ends the process is refused`), d.js, 'design.sandbox'));
232
- if (r.error) return reject(located(Object.assign(new Error(refused(r.error)), { code: r.error.code, ...(r.error.line ? { line: r.error.line } : {}), ...(r.error.syntax ? { name: 'SyntaxError' } : {}) }), d.js, r.error.code || 'design.run'));
625
+ const wrong =
626
+ checkReply(r) ||
627
+ (!board && r.board != null
628
+ ? 'it has a board, and the design is not one'
629
+ : board && r.board == null && !r.error
630
+ ? "a board design's reply has no board"
631
+ : null); // (every field is untrusted: see checkReply)
632
+ if (wrong)
633
+ return reject(
634
+ located(
635
+ new Error(
636
+ `the design's reply was not one rulecad makes (${wrong}), so none of it was used and nothing it sent was written. A design gives back its shapes from main(v); one that writes to the process's output itself or ends the process is refused`,
637
+ ),
638
+ d.js,
639
+ 'design.sandbox',
640
+ ),
641
+ );
642
+ if (r.error)
643
+ return reject(
644
+ located(
645
+ Object.assign(new Error(refused(r.error)), {
646
+ code: r.error.code,
647
+ ...(r.error.line ? { line: r.error.line } : {}),
648
+ ...(r.error.syntax ? { name: 'SyntaxError' } : {}),
649
+ }),
650
+ d.js,
651
+ r.error.code || 'design.run',
652
+ ),
653
+ );
233
654
  if (stages) for (const [k, text] of Object.entries(r.stages || {})) stages.put(k, text);
234
655
  if (board?.routes) for (const [k, text] of Object.entries(r.routes || {})) board.routes.put(k, text);
235
- resolve({ parts: r.parts.map(({ solid, ...p }) => ({ ...p, geometry: fromFaces(solid) })), read: new Set(r.read), mechanism: r.mechanism || null, fixings: r.fixings || null,
236
- ...(board ? { board: r.board, mounted: r.mounted === true } : {}) });
656
+ resolve({
657
+ parts: r.parts.map(({ solid, ...p }) => ({ ...p, geometry: fromFaces(solid) })),
658
+ read: new Set(r.read),
659
+ mechanism: r.mechanism || null,
660
+ fixings: r.fixings || null,
661
+ ...(board ? { board: r.board, mounted: r.mounted === true } : {}),
662
+ });
237
663
  });
238
- child.stdin.end(JSON.stringify({ js: `${pathToFileURL(js).href}?t=${fs.statSync(js).mtimeMs}`, values, meta, engine, optional, ...(stages ? { stages: { dir: stagesDir, salt: stages.salt } } : {}), bound,
239
- ...(board ? { board: { ...(board.routes ? { routes: path.resolve(board.routes.dir) } : {}) } } : {}) }));
664
+ child.stdin.end(
665
+ JSON.stringify({
666
+ js: `${pathToFileURL(js).href}?t=${fs.statSync(js).mtimeMs}`,
667
+ values,
668
+ meta,
669
+ engine,
670
+ optional,
671
+ ...(stages ? { stages: { dir: ownFolder(path.resolve(stages.dir)), salt: stages.salt } } : {}),
672
+ bound,
673
+ ...(board
674
+ ? {
675
+ board: {
676
+ ...(board.routes
677
+ ? {
678
+ routes: [board.routes.dir, board.routes.shared]
679
+ .filter(Boolean)
680
+ .map((dir) => ownFolder(path.resolve(dir)))
681
+ .filter(Boolean),
682
+ }
683
+ : {}),
684
+ },
685
+ }
686
+ : {}),
687
+ }),
688
+ );
240
689
  });
241
690
  }