A 1.2 MB pure-Rust rewrite of headless Blender built for AI agents — 3D B-rep modeling engine, CLI, and MCP server
fix: harden merged bugfix PRs, speed up T-junction repair, and rebuild WASM
wrong-nebulab8e926fd5496
diff --git a/crates/forma-core/src/boolean.rs b/crates/forma-core/src/boolean.rsindex 6882710..da4a790 100644--- a/crates/forma-core/src/boolean.rs+++ b/crates/forma-core/src/boolean.rs@@ -1336,13 +1336,119 @@ fn collect_bad_verts(mesh: &PolyMesh) -> Vec<usize> {bad}-/// X-sorted sweep T-junction resolver: splits triangle edges passing through boundary vertices.+struct PtBvhNode {+ aabb: Aabb,+ left: u32,+ right: u32,+ count: u32,+}++/// Compact 3D point-BVH over boundary vertex indices for O(log B + k) T-junction queries.+struct PointBvh {+ nodes: Vec<PtBvhNode>,+ verts: Vec<usize>,+}++impl PointBvh {+ fn build(positions: &[Vec3], indices: &[usize]) -> Self {+ let mut verts = indices.to_vec();+ let mut nodes = Vec::with_capacity(verts.len() / 4 + 1);+ if !verts.is_empty() {+ let len = verts.len();+ Self::build_node(positions, &mut verts, 0, len, &mut nodes);+ }+ Self { nodes, verts }+ }++ fn build_node(+ positions: &[Vec3],+ verts: &mut [usize],+ start: usize,+ end: usize,+ nodes: &mut Vec<PtBvhNode>,+ ) -> u32 {+ let mut aabb = Aabb::empty();+ for &vi in &verts[start..end] {+ aabb.include(positions[vi]);+ }+ let node_idx = nodes.len() as u32;+ let count = end - start;+ if count <= 8 {+ nodes.push(PtBvhNode {+ aabb,+ left: start as u32,+ right: 0,+ count: count as u32,+ });+ return node_idx;+ }+ let ext = aabb.size();+ let axis = if ext.x >= ext.y && ext.x >= ext.z {+ 0+ } else if ext.y >= ext.z {+ 1+ } else {+ 2+ };+ let mid = start + count / 2;+ verts[start..end].select_nth_unstable_by(mid - start, |&a, &b| {+ let pa = positions[a];+ let pb = positions[b];+ let (ca, cb) = match axis {+ 0 => (pa.x, pb.x),+ 1 => (pa.y, pb.y),+ _ => (pa.z, pb.z),+ };+ ca.total_cmp(&cb).then_with(|| a.cmp(&b))+ });+ nodes.push(PtBvhNode {+ aabb,+ left: 0,+ right: 0,+ count: 0,+ });+ let left = Self::build_node(positions, verts, start, mid, nodes);+ let right = Self::build_node(positions, verts, mid, end, nodes);+ nodes[node_idx as usize].left = left;+ nodes[node_idx as usize].right = right;+ node_idx+ }++ fn query_aabb(&self, q: &Aabb, pad: f64, out: &mut Vec<usize>) {+ out.clear();+ if self.nodes.is_empty() {+ return;+ }+ let mut stack: SmallVec<[u32; 64]> = SmallVec::new();+ stack.push(0);+ while let Some(ni) = stack.pop() {+ let node = &self.nodes[ni as usize];+ if !node.aabb.overlaps(q, pad) {+ continue;+ }+ if node.count > 0 {+ let s = node.left as usize;+ let e = s + node.count as usize;+ out.extend_from_slice(&self.verts[s..e]);+ } else {+ stack.push(node.left);+ stack.push(node.right);+ }+ }+ }+}++/// 3D point-BVH incremental T-junction resolver: splits triangle edges passing through boundary vertices.fn eliminate_t_junctions(mesh: &mut PolyMesh, seg_tol: f64) {let seg_tol_sq = seg_tol * seg_tol;let end_tol_sq = (seg_tol * 0.25).max(1e-6).powi(2);let pad = seg_tol.max(1e-4);let max_faces = (mesh.faces.len() * 4 + 2048).min(250_000);- for _pass in 0..8 {+ let mut prev_bverts: Vec<usize> = Vec::new();+ let mut face_is_new: Vec<bool> = vec![true; mesh.faces.len()];+ let mut cand_verts: Vec<usize> = Vec::with_capacity(32);++ for pass in 0..8 {if mesh.faces.len() >= max_faces {return;}@@ -1350,36 +1456,54 @@ fn eliminate_t_junctions(mesh: &mut PolyMesh, seg_tol: f64) {if bverts.is_empty() {return;}- // Sort boundary vertices by X coordinate for binary-search windowing!- let mut bx: Vec<(f64, usize)> = bverts.iter().map(|&vi| (mesh.verts[vi].x, vi)).collect();- bx.sort_by(|a, b| a.0.total_cmp(&b.0).then_with(|| a.1.cmp(&b.1)));+ let bvh_all = PointBvh::build(&mesh.verts, &bverts);+ let bvh_new = if pass > 0 {+ let new_bv: Vec<usize> = bverts+ .iter()+ .copied()+ .filter(|vi| prev_bverts.binary_search(vi).is_err())+ .collect();+ if new_bv.is_empty() {+ None+ } else {+ Some(PointBvh::build(&mesh.verts, &new_bv))+ }+ } else {+ None+ };let mut new_faces: Vec<Face> = Vec::with_capacity(mesh.faces.len() + 64);+ let mut next_is_new: Vec<bool> = Vec::with_capacity(mesh.faces.len() + 64);let mut did_split = false;- for f in mesh.faces.drain(..) {+ for (fi_old, f) in mesh.faces.drain(..).enumerate() {+ let is_new = face_is_new.get(fi_old).copied().unwrap_or(true);if f.verts.len() != 3 || new_faces.len() >= max_faces {new_faces.push(f);+ next_is_new.push(false);continue;}+ let bvh = if is_new {+ &bvh_all+ } else if let Some(ref bn) = bvh_new {+ bn+ } else {+ new_faces.push(f);+ next_is_new.push(false);+ continue;+ };let tri = [f.verts[0], f.verts[1], f.verts[2]];let p0 = mesh.verts[tri[0]];let p1 = mesh.verts[tri[1]];let p2 = mesh.verts[tri[2]];- let min_x = p0.x.min(p1.x).min(p2.x) - pad;- let max_x = p0.x.max(p1.x).max(p2.x) + pad;- let min_y = p0.y.min(p1.y).min(p2.y) - pad;- let max_y = p0.y.max(p1.y).max(p2.y) + pad;- let min_z = p0.z.min(p1.z).min(p2.z) - pad;- let max_z = p0.z.max(p1.z).max(p2.z) + pad;-- let lo = bx.partition_point(|&(x, _)| x < min_x);- let mut hi = lo;- while hi < bx.len() && bx[hi].0 <= max_x {- hi += 1;- }- if lo == hi {+ let tri_bb = Aabb {+ min: p0.min(p1).min(p2),+ max: p0.max(p1).max(p2),+ };+ bvh.query_aabb(&tri_bb, pad, &mut cand_verts);+ if cand_verts.is_empty() {new_faces.push(f);+ next_is_new.push(false);continue;}@@ -1387,6 +1511,7 @@ fn eliminate_t_junctions(mesh: &mut PolyMesh, seg_tol: f64) {let orig_area2_sq = n_orig.len_sq();if orig_area2_sq < 1e-24 {new_faces.push(f);+ next_is_new.push(false);continue;}let min_dot = 1e-10 * orig_area2_sq;@@ -1401,16 +1526,18 @@ fn eliminate_t_junctions(mesh: &mut PolyMesh, seg_tol: f64) {if ab_len_sq < end_tol_sq * 4.0 {continue;}+ let e_min = a.min(b) - Vec3::splat(pad);+ let e_max = a.max(b) + Vec3::splat(pad);// Endpoint exclusion as a fraction of the edge, capped to an absolute length so a// very long edge (large part, small cutter) still accepts seam vertices near its ends.let t_eps = (1e-5_f64).min(1e-5 / ab_len_sq.sqrt());let mut hits: SmallVec<[(f64, usize); 4]> = SmallVec::new();- for &(_, bv) in &bx[lo..hi] {+ for &bv in &cand_verts {if bv == tri[0] || bv == tri[1] || bv == tri[2] {continue;}let q = mesh.verts[bv];- if q.y < min_y || q.y > max_y || q.z < min_z || q.z > max_z {+ if q.x < e_min.x || q.x > e_max.x || q.y < e_min.y || q.y > e_max.y || q.z < e_min.z || q.z > e_max.z {continue;}// Reject vertices already within snap distance of edge endpoints (prevents sliver cascades!)@@ -1426,7 +1553,7 @@ fn eliminate_t_junctions(mesh: &mut PolyMesh, seg_tol: f64) {}}if !hits.is_empty() {- hits.sort_by(|x, y| x.0.total_cmp(&y.0));+ hits.sort_by(|x, y| x.0.total_cmp(&y.0).then_with(|| x.1.cmp(&y.1)));// Deduplicate hits that are too close together along the edgelet mut filtered: SmallVec<[(f64, usize); 4]> = SmallVec::new();for &(t, bv) in &hits {@@ -1469,16 +1596,21 @@ fn eliminate_t_junctions(mesh: &mut PolyMesh, seg_tol: f64) {let mut nf = f.clone();nf.verts = SmallVec::from_slice(&[prev, bv, c]);new_faces.push(nf);+ next_is_new.push(true);prev = bv;}let mut last_f = f;last_f.verts = SmallVec::from_slice(&[prev, b, c]);new_faces.push(last_f);+ next_is_new.push(true);} else {new_faces.push(f);+ next_is_new.push(false);}}mesh.faces = new_faces;+ face_is_new = next_is_new;+ prev_bverts = bverts;if !did_split {break;}@@ -1487,10 +1619,17 @@ fn eliminate_t_junctions(mesh: &mut PolyMesh, seg_tol: f64) {fn repair_seam_micro_edges(mesh: &mut PolyMesh) {for &snap_tol in &[5e-6_f64, 2e-5_f64, 8e-5_f64, 2e-4_f64] {- let blist = collect_bad_verts(mesh);+ let mut blist = collect_bad_verts(mesh);if blist.is_empty() {return;}+ // Sort by X for O(B log B) spatial sweep instead of O(B^2) pairwise checks+ blist.sort_unstable_by(|&a, &b| {+ mesh.verts[a]+ .x+ .total_cmp(&mesh.verts[b].x)+ .then_with(|| a.cmp(&b))+ });let mut remap: Vec<usize> = (0..mesh.verts.len()).collect();let tol_sq = snap_tol * snap_tol;let mut merged_any = false;@@ -1500,7 +1639,11 @@ fn repair_seam_micro_edges(mesh: &mut PolyMesh) {continue;}let pi = mesh.verts[vi];+ let max_x = pi.x + snap_tol;for &vj in &blist[(i + 1)..] {+ if mesh.verts[vj].x > max_x {+ break;+ }if remap[vj] != vj {continue;}@@ -1925,10 +2068,6 @@ fn boolean_op_unchecked(});}- // Normalize both operands to a unit cube around their combined AABB center whenever- // the geometry is far from unit scale or far from the origin, keeping all boolean- // tolerances scale-invariant while avoiding unnecessary floating-point churn at unit scale.- let needs_norm = scale < 0.25 || scale > 8.0 || center.len() > 1e3;// The kernel's weld/coplanarity tolerances are absolute in normalized space, so they must// be small against the smallest operand feature, not against the combined extent: a 2 mm// cutter in a 10 m part normalized to the part would fall below them and be dropped whole.@@ -1946,11 +2085,15 @@ fn boolean_op_unchecked(}f};- let scale = if scale > BOOL_FEATURE_RATIO * feature {+ let extreme_ratio = scale > BOOL_FEATURE_RATIO * feature;+ let scale = if extreme_ratio {(feature * BOOL_FEATURE_RATIO).max(scale / BOOL_MAX_NORM_EXTENT)} else {scale};+ // Normalize both operands around their combined AABB center whenever the geometry is far+ // from unit scale, far from the origin, or has an extreme part/tool feature ratio.+ let needs_norm = scale < 0.25 || scale > 8.0 || center.len() > 1e3 || extreme_ratio;let (an_buf, bn_buf);let (a_ref, b_ref): (&PolyMesh, &PolyMesh) = if needs_norm {let inv_scale = 1.0 / scale;diff --git a/crates/forma-core/src/invariants.rs b/crates/forma-core/src/invariants.rsindex 6b56c4e..4d72d63 100644--- a/crates/forma-core/src/invariants.rs+++ b/crates/forma-core/src/invariants.rs@@ -212,7 +212,12 @@ impl MeshInvariants {/// floor such as `1e-12` cubic units would refuse it, and so do a long thin bar and copies far apart,/// which a floor on the bounding box would refuse.pub fn has_negligible_volume(&self) -> bool {- !(self.signed_volume.is_finite() && self.surface_area > 0.0 && self.compactness() > MIN_COMPACTNESS)+ let c = self.compactness();+ !(self.signed_volume.is_finite()+ && self.surface_area.is_finite()+ && self.surface_area > 0.0+ && c.is_finite()+ && c > MIN_COMPACTNESS)}pub fn is_valid_solid(&self) -> bool {diff --git a/crates/forma-core/src/ops.rs b/crates/forma-core/src/ops.rsindex 0532af0..8aace12 100644--- a/crates/forma-core/src/ops.rs+++ b/crates/forma-core/src/ops.rs@@ -639,6 +639,7 @@ fn try_bevel_vertical_prism(let n = poly.len();let mut rounded: Vec<(f64, f64)> = Vec::with_capacity(n * (segments + 1));let cos_sharp_thresh = 20.0_f64.to_radians().cos();+ let mut beveled_any = false;for i in 0..n {let prev = poly[(i + n - 1) % n];@@ -659,6 +660,7 @@ fn try_bevel_vertical_prism(rounded.push(curr);continue;}+ beveled_any = true;let d = radius.min(l1 * 0.45).min(l2 * 0.45);let p_start = (curr.0 + u1.0 * d, curr.1 + u1.1 * d);@@ -700,6 +702,9 @@ fn try_bevel_vertical_prism(}}}+ if !beveled_any {+ return None;+ }let rounded = simplify_collinear_2d(&rounded, 1e-8);if rounded.len() < 3 || poly_has_self_intersection_2d(&rounded) {return None;@@ -1493,6 +1498,18 @@ pub fn shell_solid(if !loops_disjoint_and_contained(&inner_outer, &ih) {return Err("shell thickness exceeds wall clearance around hole".into());}+ for prev in &inner_holes {+ let overlap = prev.iter().any(|&p| point_in_poly_2d(p, &ih))+ || ih.iter().any(|&p| point_in_poly_2d(p, prev))+ || (0..prev.len()).any(|i| {+ let a = prev[i];+ let b = prev[(i + 1) % prev.len()];+ (0..ih.len()).any(|j| segs_properly_intersect(a, b, ih[j], ih[(j + 1) % ih.len()]))+ });+ if overlap {+ return Err("shell thickness exceeds clearance between adjacent holes".into());+ }+ }inner_holes.push(ih);}let z_floor = z0 + thickness;@@ -1537,6 +1554,17 @@ pub fn array_linear(step: Vec3,union_all: bool,op_id: u32,+) -> Result<PolyMesh, String> {+ array_linear_bounded(mesh, count, step, union_all, 0, op_id)+}++pub(crate) fn array_linear_bounded(+ mesh: &PolyMesh,+ count: usize,+ step: Vec3,+ union_all: bool,+ max_faces: usize,+ op_id: u32,) -> Result<PolyMesh, String> {if count == 0 {return Err("array count must be >= 1".into());@@ -1562,8 +1590,20 @@ pub fn array_linear());}acc = boolean_op(&acc, &inst, BoolOp::Union, None, op_id)?;+ if max_faces > 0 && acc.faces.len() > max_faces {+ return Err(format!(+ "array union exceeded face limit ({} > {max_faces}); reduce count or simplify input",+ acc.faces.len()+ ));+ }} else {acc.append_mesh(&inst);+ if max_faces > 0 && acc.faces.len() > max_faces {+ return Err(format!(+ "array exceeded face limit ({} > {max_faces}); reduce count or simplify input",+ acc.faces.len()+ ));+ }}inst_bbs.push(ibb);}@@ -1581,6 +1621,18 @@ pub fn array_radial_ex(axis: char,union_all: bool,op_id: u32,+) -> Result<PolyMesh, String> {+ array_radial_ex_bounded(mesh, count, radius, axis, union_all, 0, op_id)+}++pub(crate) fn array_radial_ex_bounded(+ mesh: &PolyMesh,+ count: usize,+ radius: f64,+ axis: char,+ union_all: bool,+ max_faces: usize,+ op_id: u32,) -> Result<PolyMesh, String> {if count == 0 {return Err("radial array count must be >= 1".into());@@ -1627,8 +1679,20 @@ pub fn array_radial_ex());}acc = boolean_op(&acc, &inst, BoolOp::Union, None, op_id)?;+ if max_faces > 0 && acc.faces.len() > max_faces {+ return Err(format!(+ "radial array union exceeded face limit ({} > {max_faces}); reduce count or simplify input",+ acc.faces.len()+ ));+ }} else {acc.append_mesh(&inst);+ if max_faces > 0 && acc.faces.len() > max_faces {+ return Err(format!(+ "radial array exceeded face limit ({} > {max_faces}); reduce count or simplify input",+ acc.faces.len()+ ));+ }}inst_bbs.push(ibb);}diff --git a/crates/forma-core/src/scene.rs b/crates/forma-core/src/scene.rsindex 47a4792..40b7245 100644--- a/crates/forma-core/src/scene.rs+++ b/crates/forma-core/src/scene.rs@@ -572,14 +572,16 @@ impl Scene {pub fn array_linear(&mut self, target: &str, count: usize, step: Vec3, union_all: bool) -> Result<MeshInvariants, SceneError> {let m = Arc::clone(self.get_part(target)?);let op = self.next_op();- let res = ops::array_linear(&m, count, step, union_all, op).map_err(SceneError::OpFailed)?;+ let res = ops::array_linear_bounded(&m, count, step, union_all, self.max_faces_per_part, op)+ .map_err(SceneError::OpFailed)?;self.set_part(target, res)}pub fn array_radial(&mut self, target: &str, count: usize, union_all: bool) -> Result<MeshInvariants, SceneError> {let m = Arc::clone(self.get_part(target)?);let op = self.next_op();- let res = ops::array_radial(&m, count, union_all, op).map_err(SceneError::OpFailed)?;+ let res = ops::array_radial_ex_bounded(&m, count, 0.0, 'z', union_all, self.max_faces_per_part, op)+ .map_err(SceneError::OpFailed)?;self.set_part(target, res)}diff --git a/crates/forma-core/tests/issue_regressions.rs b/crates/forma-core/tests/issue_regressions.rsindex d215460..fe4bb6b 100644--- a/crates/forma-core/tests/issue_regressions.rs+++ b/crates/forma-core/tests/issue_regressions.rs@@ -81,8 +81,10 @@ fn issue17_overlap_check_is_near_linear_on_thousands_of_shells() {assert_eq!(r2, OverlapCheck::Clear, "jittered grid shells do not overlap");println!("issue17: 8000 slivers {dt_sliver:.3}s, 6000 loose shells {dt_loose:.3}s");- assert!(dt_sliver < 1.0, "8000 slivers took {dt_sliver:.2}s (was ~35 s)");- assert!(dt_loose < 1.0, "6000 loose shells took {dt_loose:.2}s");+ let sliver_limit = if cfg!(debug_assertions) { 5.0 } else { 1.0 };+ let loose_limit = if cfg!(debug_assertions) { 5.0 } else { 1.0 };+ assert!(dt_sliver < sliver_limit, "8000 slivers took {dt_sliver:.2}s (was ~35 s)");+ assert!(dt_loose < loose_limit, "6000 loose shells took {dt_loose:.2}s");}#[test]@@ -95,7 +97,8 @@ fn issue17_strict_eval_path_on_slivers_is_fast_and_ok() {let dt = t0.elapsed().as_secs_f64();assert_eq!(inv.components, 4000);assert!(obs.warnings.iter().all(|w| !w.contains("overlap")), "{:?}", obs.warnings);- assert!(dt < 2.0, "strict set_part + observe on 4000 slivers took {dt:.2}s (was ~7 s)");+ let eval_limit = if cfg!(debug_assertions) { 15.0 } else { 2.0 };+ assert!(dt < eval_limit, "strict set_part + observe on 4000 slivers took {dt:.2}s (was ~7 s)");}#[test]diff --git a/crates/forma-core/tests/kernel_tests.rs b/crates/forma-core/tests/kernel_tests.rsindex 5dd6102..8e32ccd 100644--- a/crates/forma-core/tests/kernel_tests.rs+++ b/crates/forma-core/tests/kernel_tests.rs@@ -1092,3 +1092,29 @@ fn test_snapshot_restores_last_modified_and_mesh_materials() {let step = String::from_utf8(forma_core::export::write_step_bytes(&poly).unwrap()).unwrap();assert!(!step.contains("DIRECTION('',(0.00000000,0.00000000,0.00000000))"), "zero DIRECTION in STEP");}++#[test]+fn test_audit_hardening_unit_scale_tiny_hole_and_close_shell_holes() {+ // 1. Unit-scale box (scale=5.0 inside 0.25..8.0) with a 0.0005 radius cutter must normalize to feature scale+ let mut s = Scene::new();+ s.strict_manifold = true;+ s.add_box("plate", 5.0, 5.0, 5.0, Vec3::ZERO).unwrap();+ s.add_cyl("pinhole", 0.0005, 10.0, 16, Vec3::ZERO, 'z').unwrap();+ let inv = s.boolean_parts("plate", "pinhole", BoolOp::Difference, false).unwrap();+ assert!(inv.is_valid_solid() && inv.genus == 1, "unit-scale box with tiny hole failed: {inv:?}");++ // 2. Shelling a prism with two closely spaced holes whose expanded walls overlap must error cleanly+ let mut s2 = Scene::new();+ s2.strict_manifold = true;+ s2.add_box("blk", 4.0, 4.0, 1.0, Vec3::ZERO).unwrap();+ s2.add_cyl("h1", 0.4, 2.0, 24, Vec3::new(-0.5, 0.0, 0.0), 'z').unwrap();+ s2.boolean_parts("blk", "h1", BoolOp::Difference, false).unwrap();+ s2.add_cyl("h2", 0.4, 2.0, 24, Vec3::new(0.5, 0.0, 0.0), 'z').unwrap();+ s2.boolean_parts("blk", "h2", BoolOp::Difference, false).unwrap();+ // Gap between holes is 0.2 -> wall thickness 0.15 per hole (0.30 total) collides+ let err = s2.shell("blk", 0.15, true).unwrap_err();+ assert!(+ format!("{err}").contains("between adjacent holes"),+ "expected adjacent-hole clearance error, got {err}"+ );+}diff --git a/crates/forma-lang/src/compact.rs b/crates/forma-lang/src/compact.rsindex 28cb20e..115b34a 100644--- a/crates/forma-lang/src/compact.rs+++ b/crates/forma-lang/src/compact.rs@@ -320,7 +320,6 @@ pub fn eval_compact(scene: &mut Scene, src: &str) -> Result<(), String> {// Trailing tokens on fixed-arity commands used to be dropped silently.let fixed_arity: Option<(usize, &str)> = match cmd {"bev" => Some((5, "bev ID edge_sel w [segs]")),- "fil" => Some((5, "fil ID edge_sel r [segs]")),"shl" => Some((4, "shl ID t [open|closed]")),"ext" => Some((4, "ext ID face_sel d")),"ins" => Some((5, "ins ID face_sel a [d]")),@@ -334,6 +333,7 @@ pub fn eval_compact(scene: &mut Scene, src: &str) -> Result<(), String> {"ckpt" => Some((2, "ckpt ID")),"rb" => Some((2, "rb ID")),"undo" => Some((1, "undo")),+ "units" => Some((2, "units m|cm|mm|um|in|ft")),_ => None,};if let Some((max_tokens, usage)) = fixed_arity {@@ -350,7 +350,7 @@ pub fn eval_compact(scene: &mut Scene, src: &str) -> Result<(), String> {if cmd == "mir" && tokens.len() > 2 && !matches!(tokens[2], "x" | "y" | "z") {return Err(format!("line {line}: mir: invalid axis '{}' (usage: mir ID x|y|z)", tokens[2]));}- if matches!(cmd, "bev" | "fil" | "subdiv") {+ if matches!(cmd, "bev" | "subdiv") {let (idx, what) = if cmd == "subdiv" { (2, "n") } else { (4, "segs") };if let Some(tok) = tokens.get(idx) {let v = parse_f(tok, line)?;@@ -519,7 +519,7 @@ pub fn eval_compact(scene: &mut Scene, src: &str) -> Result<(), String> {}other => {return Err(format!(- "line {line}: unknown command '{other}' (accepted: new, add, sub, int, bev, fil, shl, ext, ins, subdiv, mov, rot, scl, z0, mir, del, ckpt, rb, undo)"+ "line {line}: unknown command '{other}' (accepted: new, add, sub, int, bev, shl, ext, ins, subdiv, mov, rot, scl, z0, mir, del, ckpt, rb, undo, units)"))}}diff --git a/crates/forma-lang/src/pipeline.rs b/crates/forma-lang/src/pipeline.rsindex b57f56b..29a1402 100644--- a/crates/forma-lang/src/pipeline.rs+++ b/crates/forma-lang/src/pipeline.rs@@ -304,7 +304,7 @@ fn max_call_positional(name: &str) -> Option<usize> {"bezier" => 2,"nurbs" | "bspline" => 3,"clearance" | "section" => 2,- "checkpoint" | "rollback" | "del" | "remove" => 1,+ "checkpoint" | "rollback" | "del" | "remove" | "units" | "unit" => 1,"undo" => 0,"box" => 3,"cyl" | "cylinder" | "prism" => 4,@@ -339,8 +339,8 @@ fn max_pipe_positional(op_name: &str) -> Option<usize> {"mat" | "material" => 4,"mirror" => 2,"pattern_linear" | "array" | "pattern_radial" | "radial" => 3,- "decimate" | "lod" | "textures" | "tex" | "paint" | "remesh" => 1,- "lit" | "flat" => 0,+ "decimate" | "lod" | "remesh" => 1,+ "flat" => 0,"smooth" | "unwrap" | "uv" => 2,"solidify" | "deform" | "bisect" => 3,_ => return None,@@ -362,15 +362,15 @@ fn check_positional_count(n: usize, max: Option<usize>, allowed_kw: Option<&[&stconst CALL_NAMES: &[&str] = &["box", "cyl", "cylinder", "prism", "cone", "frustum", "sphere", "torus", "revolve", "arc_tube", "tube", "extrude2d","pipe", "hollow_cyl", "loft", "thread", "helix", "sweep", "text3d", "text", "load", "import", "bezier", "nurbs",- "bspline", "clearance", "section", "checkpoint", "rollback", "undo", "del", "remove", "sqrt", "sin", "cos", "asin",- "acos", "abs", "deg", "rad",+ "bspline", "clearance", "section", "checkpoint", "rollback", "undo", "units", "del", "remove", "sqrt", "sin",+ "cos", "asin", "acos", "abs", "deg", "rad",];const PIPE_OP_NAMES: &[&str] = &["add", "union", "cut", "sub", "diff", "intersect", "bevel", "shell", "extrude", "inset", "subsurf","subdiv", "move", "translate", "rot", "rotate", "scale", "align_z0", "align", "on", "place_on", "mat", "material",- "color", "mirror", "pattern_linear", "array", "pattern_radial", "radial", "decimate", "lod", "textures", "tex",- "paint", "lit", "smooth", "flat", "solidify", "deform", "unwrap", "uv", "remesh", "bisect",+ "color", "mirror", "pattern_linear", "array", "pattern_radial", "radial", "decimate", "lod", "smooth", "flat",+ "solidify", "deform", "unwrap", "uv", "remesh", "bisect",];/// " — did you mean 'x'?" for the closest known name, plus the full list of accepted names.diff --git a/crates/forma-server/src/main.rs b/crates/forma-server/src/main.rsindex 562712a..4f2954e 100644--- a/crates/forma-server/src/main.rs+++ b/crates/forma-server/src/main.rs@@ -392,6 +392,7 @@ fn handle_connection(mut stream: TcpStream, workers: usize) {let path = target.split('?').next().unwrap_or(target);let mut headers: HashMap<String, String> = HashMap::new();+ let mut header_lines = 0usize;loop {let mut line = String::new();match read_line_limited(&mut reader, &mut line, MAX_HEADER_LINE_BYTES) {@@ -406,6 +407,11 @@ fn handle_connection(mut stream: TcpStream, workers: usize) {if trimmed.is_empty() {break;}+ header_lines += 1;+ if header_lines > 128 {+ HttpResponse::json(431, "Request Header Fields Too Large", json!({ "error": "too many headers" })).write_to(&mut stream);+ return;+ }if let Some((k, v)) = trimmed.split_once(':') {headers.insert(k.trim().to_ascii_lowercase(), v.trim().to_string());}diff --git a/grammar/forma_pipe.gbnf b/grammar/forma_pipe.gbnfindex 9f7610c..6aa6832 100644--- a/grammar/forma_pipe.gbnf+++ b/grammar/forma_pipe.gbnf@@ -61,7 +61,7 @@ kw-name ::= "sx" | "sy" | "sz" | "r" | "h" | "r0" | "r1" | "R" | "segs" | "se| "normal" | "offset" | "clear_inner" | "ratio" | "target_faces"| "degree" | "deg" | "weights" | "sections" | "profiles"| "r_out" | "ro" | "outer" | "r_in" | "ri" | "inner" | "r_minor" | "r_min" | "r_major" | "r_maj"- | "pitch" | "p" | "turns" | "file" | "yup" | "text" | "height" | "radius" | "major" | "minor"+ | "pitch" | "p" | "turns" | "file" | "yup" | "text" | "height" | "radius" | "major" | "minor" | "unit"bool-lit ::= "true" | "false"ident ::= [a-zA-Z_] [a-zA-Z0-9_]*diff --git a/wasm/forma.wasm b/wasm/forma.wasmindex 34ef319..091302e 100755Binary files a/wasm/forma.wasm and b/wasm/forma.wasm differ