Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"name": "shapeitup",
"description": "CAD scripting toolkit: create/modify .shape.ts files, validate geometry, check collisions, export STEP/STL/3MF via Replicad + OpenCascade. Runs headless; live 3D preview available if the ShapeItUp VS Code extension is installed.",
"version": "1.29.4",
"version": "1.29.5",
"author": {
"name": "Asbjorn Rorvik",
"email": "rorvik.asbjorn@gmail.com"
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ Releases 1.17.0–1.24.0 are described only in their
Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); the
project follows semantic versioning at the extension level.

## [1.29.5] - 2026-09-23

Extension `1.29.5` / mcp-server `1.29.5`.

### Fixed
- **Stdlib helpers no longer warn about their own internals.**
`holes.counterbore` used through `patterns.cutAt` printed
"fuse #N: fuse produced no new material" once per placement, and `placeOn`
raised the extrude-plane hint whose recommended fix is `placeOn` itself.
The hint told user code from stdlib code by looking for `/stdlib/` in the
call stack, which is only true when core runs from source. Once bundled
(the worker, the MCP server, the website), every helper looked like user
code. Stdlib construction now runs inside an explicit internal scope that
the no-op fuse guard, the extrude-plane hint and the pen-axis advisory
respect. It covers `placeOn`, `extrudeCentered`, `holes.counterbore`,
`holes.teardrop`, `bearings.seat` and the motor mount plates. Internal fuses
no longer use up the user's `fuse #N` numbers.
- **`holes.counterbore` on a plate too thin for the head.** When the head
pocket is as deep as the plate (M4 in 4 mm: the pocket is 4.2 mm deep), the
pocket cuts straight through and the screw head has nothing to seat on. It
now says that once, instead of emitting a no-op fuse warning per hole. The
cut geometry is unchanged.

## [1.29.4] - 2026-09-23

Extension `1.29.4` / mcp-server `1.29.4` — a face op no longer writes a line
Expand Down
23 changes: 22 additions & 1 deletion packages/core/src/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
__resetCutPatchedForTests,
__resetFusePatchedForTests,
} from "./index";
import { drainRuntimeWarnings, resetRuntimeWarnings } from "./stdlib/warnings";
import { asStdlibInternal, drainRuntimeWarnings, resetRuntimeWarnings } from "./stdlib/warnings";

// ---------------------------------------------------------------------------
// Mocks
Expand Down Expand Up @@ -1169,6 +1169,27 @@ describe("patchShapeFuseNoOpGuard — warns when fuse adds zero material", () =>
expect(warnings[0]).toMatch(/fully contained in the target/);
});

it("ignores a no-op fuse a stdlib helper performs on its own behalf, and doesn't number it", () => {
// holes.counterbore fusing a shaft that lies inside its pocket is not the
// user's fuse. Reporting it read as "you made a mistake" once per cutAt
// placement, and spending an ordinal on it made "fuse #N" point at the
// wrong line of the user's script.
const { replicad, volumeMap, _3DShape } = makeFakeReplicad();
patchShapeFuseNoOpGuard(replicad);

const cutter: any = new _3DShape();
volumeMap.set(cutter, 175.79);
asStdlibInternal(() => cutter.fuse(new _3DShape()));
expect(drainRuntimeWarnings()).toEqual([]);

const target: any = new _3DShape();
volumeMap.set(target, 2500);
target.fuse(new _3DShape());
const warnings = drainRuntimeWarnings();
expect(warnings).toHaveLength(1);
expect(warnings[0]).toMatch(/^fuse #1:/);
});

it("names the disjoint axis and suggests a translate when the operands' AABBs don't touch", () => {
// P2-3 from knitting-printer v8: the cut guard's axis-disjoint hint
// (`Cutter is RIGHT-OF target, translate by N mm on X`) saved real
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
drainCutAtOutcomes,
drainExtrudeHints,
drainRuntimeWarnings,
inStdlibInternal,
nextCutCallIndex,
nextFuseCallIndex,
pushRuntimeWarning,
Expand Down Expand Up @@ -692,10 +693,15 @@ export function patchShapeFuseNoOpGuard(replicad: any): boolean {
}
const originalFuse = proto.fuse;
proto.fuse = function patchedFuse(this: any, other: any, options?: any) {
// Consume a call ordinal on every .fuse(), mirroring the cut guard —
// Consume a call ordinal on every user .fuse(), mirroring the cut guard —
// when a user has several .fuse() calls in one script and one silently
// produces no new material, identical warnings make the offender
// impossible to locate.
// A stdlib helper fusing its own cutter pieces is not the user's fuse:
// don't measure it, and don't spend one of the user's "fuse #N" ordinals
// on it either, or the numbers in their warnings stop matching the
// .fuse() calls they can see.
if (inStdlibInternal()) return originalFuse.call(this, other, options);
const callIdx = nextFuseCallIndex();
const inputVolume = readVolumeSafe(this, replicad);
// Snapshot AABBs before the fuse so the axis-disjoint hint can describe
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { assertPositiveFinite } from "./stdlib/standards";
import {
claimNonXYPlaneHint,
enqueueExtrudeHint,
inStdlibInternal,
shiftPendingExtrudeHint,
pushRuntimeWarning,
type PendingExtrudeHint,
Expand Down Expand Up @@ -1058,9 +1059,11 @@ function validateSketchOnPlane(self: any, planeName: unknown): void {
// axis-mapping warning would just be noise. If the blueprint or its bbox
// can't be read (e.g. a unit-test stub without `.blueprint`), we fall back
// to firing the hint — preserving the prior behaviour for non-replicad
// receivers.
// receivers. A stdlib helper sketching its own profile is skipped too: the
// user never drew with that pen.
if (
planeName !== "XY" &&
!inStdlibInternal() &&
typeof self === "object" &&
self !== null &&
PEN_AXIS_DRAWINGS.has(self) &&
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/stdlib/bearings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { makeCylinder, type Shape3D } from "replicad";
import { BALL_BEARING, LINEAR_BEARING, CUT_EPSILON } from "./standards";
import { applyAxis, resolveHoleAxis, type HoleAxis } from "./holes";
import { asStdlibInternal } from "./warnings";

/** Clearance behind the bearing back so the cut-tool doesn't coplanar-fail. */
const POCKET_BACK_CLEARANCE = 0.2;
Expand Down Expand Up @@ -173,7 +174,7 @@ export function seat(
[0, 0, 1]
);

const tool = pocket.fuse(relief);
const tool = asStdlibInternal(() => pocket.fuse(relief));
return applyAxis(tool, axis);
}

Expand Down
68 changes: 67 additions & 1 deletion packages/core/src/stdlib/holes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect, beforeAll } from "vitest";
import * as holes from "./holes";
import { applyAxis, type HoleAxis } from "./holes";
import { initCore } from "../index.js";
import { loadOCCTForTest } from "../testing/occt.js";

// ---------------------------------------------------------------------------
// Pin the public API surface of `holes`. OCCT is not required for these
Expand Down Expand Up @@ -326,3 +328,67 @@ describe("holes.slot — length vs travel input forms", () => {
).toThrow(/travel.*width.*avoid the inequality/);
});
});

// ---------------------------------------------------------------------------
// counterbore must not report its own construction as the user's mistake.
//
// The cutter is a pocket fused to a shaft. On a plate no thicker than the
// pocket is deep (M4 in 4 mm: pocket 4.2 mm) the shaft sits wholly inside the
// pocket, the fuse adds nothing, and the no-op fuse guard used to print
// "fuse #N: fuse produced no new material" once per patterns.cutAt placement —
// about a fuse the user never wrote. What IS wrong is that the pocket goes
// straight through, so that is what should be said, once.
// ---------------------------------------------------------------------------

describe("holes.counterbore warnings (real OCCT)", () => {
let core: Awaited<ReturnType<typeof initCore>>;

beforeAll(async () => {
core = await initCore(loadOCCTForTest);
}, 120_000);

async function plateWithCounterbores(thickness: number, extra = "") {
const r = await core.execute(`
const { drawRoundedRectangle } = __replicad__;
const { holes, patterns, shape3d } = __shapeitup__;
function main() {
let plate = shape3d(drawRoundedRectangle(100, 80, 6).sketchOnPlane("XY").extrude(${thickness}));
${extra}
return patterns.cutAt(
plate,
() => holes.counterbore("M4", { plateThickness: ${thickness} }).translate(0, 0, ${thickness}),
patterns.grid(2, 2, 86, 66),
);
}
`, undefined, { partStats: "full" });
return r;
}

it("says once that the pocket leaves no seat, and nothing about a fuse, when the plate is too thin", async () => {
const { warnings } = await plateWithCounterbores(4);
expect(warnings.filter((w) => /fuse/.test(w))).toEqual([]);
const seat = warnings.filter((w) => /no seat for the screw head/.test(w));
expect(seat).toHaveLength(1);
expect(seat[0]).toMatch(/holes\.counterbore\("M4", \{ plateThickness: 4 \}\)/);
});

it("is silent on a plate thick enough to seat the head, and still cuts pocket + shaft", async () => {
const { warnings, parts } = await plateWithCounterbores(6);
expect(warnings).toEqual([]);
const pocket = Math.PI * 3.65 ** 2 * 4.2; // Ø7.3 x 4.2
const shaft = Math.PI * 2.2 ** 2 * (6 - 4.2); // Ø4.4 (M4 + clearance fit) below the pocket
const plate = (parts[0] as any).volume;
const solid = 100 * 80 * 6 - (4 - Math.PI) * 6 * 6 * 6; // rounded corners r=6
expect(solid - plate).toBeCloseTo(4 * (pocket + shaft), 0);
});

it("keeps the user's own fuse numbering: a no-op fuse they wrote is still #1", async () => {
const { warnings } = await plateWithCounterbores(
6,
`plate = plate.fuse(drawRoundedRectangle(10, 10, 1).sketchOnPlane("XY").extrude(2));`,
);
const fuse = warnings.filter((w) => /fuse produced no new material/.test(w));
expect(fuse).toHaveLength(1);
expect(fuse[0]).toMatch(/^fuse #1:/);
});
});
79 changes: 52 additions & 27 deletions packages/core/src/stdlib/holes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ import {
assertPositiveFinite,
assertSupportedSize,
} from "./standards";
import { pushRuntimeWarning, claimAmbiguousRawWarning } from "./warnings";
import {
asStdlibInternal,
claimAmbiguousRawWarning,
pushRuntimeWarning,
pushRuntimeWarningOnce,
} from "./warnings";

/**
* Raw diameters that equal a nominal metric size (M3, M4, M5, M6, M8, M10, M12).
Expand Down Expand Up @@ -390,13 +395,29 @@ export function counterbore(
// CUT_EPSILON so coincident faces don't produce non-manifold geometry. The
// original overlap into the pocket is preserved by starting at -plateThickness.
const eps = opts.strict ? 0 : CUT_EPSILON;
const shaftLength = plateThickness + eps;
// When the pocket is at least as deep as the shaft is long, the shaft lies
// wholly inside it: fusing would add nothing, and would trip the no-op
// fuse guard with a warning about an operation the user never wrote. The
// real problem is the one worth saying — the pocket reaches through the
// plate, so there is nothing left for the screw head to seat on.
if (shaftLength <= pocketH) {
pushRuntimeWarningOnce(
`holes.counterbore("${spec}", { plateThickness: ${plateThickness} }): the ` +
`${size} head pocket (Ø${pocketD.toFixed(1)} × ${pocketH.toFixed(1)} mm) is as deep as ` +
`the plate, so it cuts straight through and leaves no seat for the screw head. ` +
`Use a plate thicker than ${pocketH.toFixed(1)} mm, or holes.countersink / ` +
`holes.through for a plate this thin.`,
);
return applyAxis(pocket, axis);
}
const shaft = makeCylinder(
shaftD / 2,
plateThickness + eps,
[0, 0, -plateThickness - eps],
shaftLength,
[0, 0, -shaftLength],
[0, 0, 1]
);
const tool = pocket.fuse(shaft);
const tool = asStdlibInternal(() => pocket.fuse(shaft));
return applyAxis(tool, axis);
}

Expand Down Expand Up @@ -642,31 +663,35 @@ export function teardrop(
// axis = "+X" → sketch on YZ, extrude along +X. Local X → world Y, local Y → world Z.
const plane = axis === "+Y" ? "XZ" : "YZ";

const circleSolid = drawCircle(r)
.sketchOnPlane(plane)
.extrude(totalDepth)
.asShape3D();
// Internal: these non-XY extrudes and the fuse are the cutter's own
// construction, not the user's, so neither may raise a hint against them.
return asStdlibInternal(() => {
const circleSolid = drawCircle(r)
.sketchOnPlane(plane)
.extrude(totalDepth)
.asShape3D();

// Triangle: apex at (0, 2r), base corners DELIBERATELY below the circle's
// equator at (±r, -r). The lower half of this triangle is hidden inside
// the circle, so the visible silhouette is still a clean teardrop — but
// the 3D fuse now has a volumetric overlap instead of two shared boundary
// points. OCCT's boolean robustness drops sharply on shapes that only
// touch at points, which is why the earlier shared-equator variants
// produced shapes the downstream cut couldn't process.
const triangleSolid = draw([r, -r])
.lineTo([0, 2 * r])
.lineTo([-r, -r])
.close()
.sketchOnPlane(plane)
.extrude(totalDepth)
.asShape3D();
// Triangle: apex at (0, 2r), base corners DELIBERATELY below the circle's
// equator at (±r, -r). The lower half of this triangle is hidden inside
// the circle, so the visible silhouette is still a clean teardrop — but
// the 3D fuse now has a volumetric overlap instead of two shared boundary
// points. OCCT's boolean robustness drops sharply on shapes that only
// touch at points, which is why the earlier shared-equator variants
// produced shapes the downstream cut couldn't process.
const triangleSolid = draw([r, -r])
.lineTo([0, 2 * r])
.lineTo([-r, -r])
.close()
.sketchOnPlane(plane)
.extrude(totalDepth)
.asShape3D();

const fused = circleSolid.fuse(triangleSolid);
// Translate by -eps along the extrude axis so the cutter spans
// [-eps, depth+eps] — overshooting both the near and far faces.
if (eps === 0) return fused;
return axis === "+Y" ? fused.translate(0, -eps, 0) : fused.translate(-eps, 0, 0);
const fused = circleSolid.fuse(triangleSolid);
// Translate by -eps along the extrude axis so the cutter spans
// [-eps, depth+eps] — overshooting both the near and far faces.
if (eps === 0) return fused;
return axis === "+Y" ? fused.translate(0, -eps, 0) : fused.translate(-eps, 0, 0);
});
}

/**
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/stdlib/motors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { drawRectangle } from "replicad";
import { Part, type Axis, normalizeAxis } from "./parts";
import { shape3d } from "./placement";
import { cylinder } from "./cylinder";
import { asStdlibInternal } from "./warnings";
import {
NEMA17,
NEMA23,
Expand Down Expand Up @@ -306,7 +307,7 @@ function buildNemaMountPlate(
length: holeLength,
diameter: boltClearanceDia,
});
tool = tool.fuse(bolt);
tool = asStdlibInternal(() => tool.fuse(bolt));
}
if (opts.boss === true) {
const bossDepth = opts.bossDepth ?? 2;
Expand All @@ -324,7 +325,10 @@ function buildNemaMountPlate(
length: bossDepth + overcut,
diameter: spec.pilotDia,
});
tool = tool.fuse(boss);
// The boss is the pilot bore's own diameter and lies inside it, so this
// fuse adds nothing today; scoped internal so it never reads as the
// user's no-op fuse.
tool = asStdlibInternal(() => tool.fuse(boss));
}

// Axis routing — same rotation table as holes.applyAxis. Inlined here to
Expand Down
Loading
Loading