Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: stop the swept-path gate reporting correct builds, and catch a notched straight spike
[._.]/ Adam Eivy315f67770ac3
diff --git a/server/lib/threejsModel.js b/server/lib/threejsModel.jsindex 72756809e5..734c3e6317 100644--- a/server/lib/threejsModel.js+++ b/server/lib/threejsModel.js@@ -1510,19 +1510,33 @@ const SWEPT_PATH_MIN_SAGITTA_RATIO = 0.05;// its outer boundary sweeps, so the outline threshold is the arc threshold.export const CURVED_OUTLINE_MIN_CONCAVE_TURN_DEGREES = 25;+// Concavity has to be SUSTAINED, not merely present. Summed over the whole ring,+// a single deep V-notch at the base of an otherwise straight spike buys hundreds+// of degrees, and serrated, stepped, and slotted silhouettes are common — so the+// gate would pass exactly the straight claw it exists to catch. A run of concave+// vertices only counts when the boundary it governs is a real stretch of the+// outline rather than a nick in it.+const CONCAVE_RUN_MIN_LENGTH_RATIO = 0.25;+// Tokens that declare a form which has to bend to read as itself. Deliberately-// narrow: a token earns a place here only when a STRAIGHT version of the part-// would be wrong, which is why "pipe", "rod", and "trunk" are absent — those are-// straight far more often than not, and only qualify through a "bent"/"curved"-// modifier that is itself on the list. Bare "arc" and "hoop" are absent for the-// opposite reason: an "arcReactor" is a disc, and a hoop authored as an extruded-// ring has a convex outline with the curve in its HOLE, so both would report a-// correct build as the defect.+// narrow, because this text is fed back into the next refinement pass: a false+// positive does not merely add noise, it TELLS the provider to bend a part that+// was right to be straight.+//+// So a noun earns a bare place here only when a straight version of the part+// would be wrong. "pipe", "rod", "trunk", "tail", "whisker", "bow", and "barb"+// are all absent — a tail boom runs down a fuselage, a tail fin is a flat plate,+// and a whisker is a straight bristle — and they declare a curve only through a+// modifier that is itself on the list, which is why "curved tail" and "coiled+// tail" still match. Bare "arc" and "hoop" are absent for a different reason: an+// "arcReactor" is a disc, and a hoop authored as an extruded ring has a convex+// outline with the curve in its HOLE, so both would report a correct build as+// the defect.const CURVED_FORM_TOKENS = new Set(['horn', 'antler', 'tusk', 'fang', 'claw', 'talon', 'pincer', 'mandible',- 'tail', 'tentacle', 'whisker', 'hook', 'crook', 'barb',+ 'tentacle', 'hook', 'crook','curve', 'curved', 'curving', 'curl', 'curled', 'coil', 'coiled', 'spiral',- 'bend', 'bent', 'arced', 'arch', 'arched', 'bow', 'bowed',+ 'bend', 'bent', 'arced', 'arch', 'arched', 'bowed','crescent', 'scythe', 'sickle', 'elbow',]);@@ -1766,8 +1780,11 @@ export function evaluateSweptArcCurvature(points) {}/**- * How much of a closed outline's turning is concave, in degrees. A convex ring- * returns 0; a crescent returns roughly the arc its inner boundary sweeps.+ * The largest SUSTAINED concave turn in a closed outline, in degrees: the+ * longest unbroken run of concave vertices whose stretch of boundary is a real+ * fraction of the outline's own size. A convex ring returns 0; a crescent+ * returns roughly the arc its inner boundary sweeps; a notch or a serration in+ * an otherwise straight silhouette returns 0 however deep it is cut.** @param {Array<number[]>} ring ordered `[x, y]` outline points*/@@ -1775,6 +1792,11 @@ export function measureOutlineConcaveTurn(ring) {const points = (Array.isArray(ring) ? ring : []).filter((point) => Array.isArray(point) && point.length === 2 && point.every(Number.isFinite));if (points.length < 3) return 0;+ const segmentLength = (index) => {+ const current = points[index];+ const next = points[(index + 1) % points.length];+ return Math.hypot(next[0] - current[0], next[1] - current[1]);+ };const turns = points.map((current, index) => {const previous = points[(index - 1 + points.length) % points.length];const next = points[(index + 1) % points.length];@@ -1789,8 +1811,34 @@ export function measureOutlineConcaveTurn(ring) {// total is its winding — measured from the turns themselves rather than from a// signed area, so the two can never disagree about which side is concave.const winding = turns.reduce((total, turn) => total + turn, 0) >= 0 ? 1 : -1;- const concave = turns.reduce((total, turn) => total + Math.max(0, -turn * winding), 0);- return (concave * 180) / Math.PI;+ const xs = points.map(([x]) => x);+ const ys = points.map(([, y]) => y);+ const extent = Math.hypot(Math.max(...xs) - Math.min(...xs), Math.max(...ys) - Math.min(...ys));+ if (!(extent > 0)) return 0;++ // Walked over two laps so a run straddling the start of the array is measured+ // whole rather than split into two short ones.+ let runTurn = 0;+ let runLength = 0;+ let widest = 0;+ for (let step = 0; step < points.length * 2; step += 1) {+ const index = step % points.length;+ const concave = -turns[index] * winding;+ if (concave > 0) {+ // The boundary a concave vertex governs runs from the segment arriving at+ // it to the segment leaving it, so a run picks up its leading segment once.+ if (runTurn === 0) runLength += segmentLength((index - 1 + points.length) % points.length);+ runTurn += concave;+ runLength += segmentLength(index);+ if (runLength >= extent * CONCAVE_RUN_MIN_LENGTH_RATIO) {+ widest = Math.max(widest, runTurn);+ }+ } else {+ runTurn = 0;+ runLength = 0;+ }+ }+ return (widest * 180) / Math.PI;}/**@@ -1808,6 +1856,11 @@ export function evaluateSweptGeometryCurvature(geometry) {return { kind: 'tube', straight: curvature.straight, arcSpanDegrees: curvature.arcSpanDegrees };}if (geometry?.type === 'extrude') {+ // A ring, an arch, and a slotted plate all put their curve in a HOLE, and a+ // hole leaves the outline convex, so an outline measurement would report the+ // canonical build as the defect. There is no measurement here that separates+ // those from a straight spike with a cutout, so the gate declines to speak.+ if ((geometry.holes || []).length > 0) return null;const concaveTurnDegrees = measureOutlineConcaveTurn(geometry.outline);return {kind: 'extrude',@@ -1828,8 +1881,10 @@ export function evaluateSweptGeometryCurvature(geometry) {* several parts — a tail of five tapered segments, a horn split into a base and* a tip — curves by ARRANGEMENT, and every piece of it is legitimately straight,* so measuring the pieces would report the correct build as the defect. That is- * why a segment nested under an already-declared part is skipped, and why a- * feature implementing itself with more than one sweep is skipped too.+ * why a segment nested under an already-declared part is skipped, why a part+ * that owns sweep-carrying children is skipped even when it carries a sweep of+ * its own (its geometry is the base of an assembly, not the whole curve), and+ * why a feature implementing itself with more than one sweep is skipped too.*/export function collectDeclaredCurvedParts(spec) {const declared = new Map();@@ -1837,12 +1892,15 @@ export function collectDeclaredCurvedParts(spec) {const declare = (partId, declaredBy) => {if (!declared.has(partId)) declared.set(partId, declaredBy);};+ const hasSweepDescendant = (part) => (part.children || []).some((child) => (+ evaluateSweptGeometryCurvature(child.geometry) || hasSweepDescendant(child)+ ));const walk = (parts, ancestorDeclared) => {for (const part of parts || []) {byId.set(part.id, part);const name = part.name || part.id;const isDeclared = namesCurvedForm(name);- if (isDeclared && !ancestorDeclared) declare(part.id, name);+ if (isDeclared && !ancestorDeclared && !hasSweepDescendant(part)) declare(part.id, name);walk(part.children, ancestorDeclared || isDeclared);}};diff --git a/server/lib/threejsModel.test.js b/server/lib/threejsModel.test.jsindex c570c50d3c..b275cde4fd 100644--- a/server/lib/threejsModel.test.js+++ b/server/lib/threejsModel.test.js@@ -1520,6 +1520,20 @@ describe('measureOutlineConcaveTurn', () => {expect(measureOutlineConcaveTurn([...crescent()].reverse())).toBeCloseTo(measureOutlineConcaveTurn(crescent()), 6);});++ // Summed over the whole ring, one deep notch buys hundreds of degrees and lets+ // a straight spike through the gate that exists to catch it. Only a SUSTAINED+ // run — one governing a real stretch of boundary — counts.+ it('ignores a notch cut into an otherwise straight silhouette', () => {+ const notchedSpike = [[0, 0], [0.45, 0], [0.5, 0.3], [0.55, 0], [1, 0], [0.5, 6]];+ expect(measureOutlineConcaveTurn(notchedSpike)).toBeCloseTo(0, 6);+ });++ // The same rule must not throw away the crescent: its inner boundary is one+ // long run, not a nick.+ it('still reports a crescent whose concavity is one sustained run', () => {+ expect(measureOutlineConcaveTurn(crescent())).toBeGreaterThan(100);+ });});describe('evaluateSweptGeometryCurvature', () => {@@ -1541,6 +1555,21 @@ describe('evaluateSweptGeometryCurvature', () => {path: [[0, 0, 0], [1, 0, 0], [1, 1, 0]],})).toBeNull();});++ // An arch, a ring, and a slotted plate all put the curve in the HOLE and leave+ // the outline convex, so measuring the outline would report the canonical+ // build as the defect.+ it('declines to measure an extrude whose curve can live in a hole', () => {+ expect(evaluateSweptGeometryCurvature({+ type: 'extrude',+ outline: [[-1, 0], [1, 0], [1, 2], [-1, 2]],+ holes: [Array.from({ length: 12 }, (_, index) => {+ const angle = Math.PI * (index / 11);+ return [0.8 * Math.cos(angle), 0.8 * Math.sin(angle)];+ })],+ depth: 0.3,+ })).toBeNull();+ });});describe('collectDeclaredCurvedParts', () => {@@ -1558,23 +1587,42 @@ describe('collectDeclaredCurvedParts', () => {expect([...declared.entries()]).toEqual([['horn', 'Left Horn'], ['part_17', 'curved brass conduit']]);});- // A tail of five straight segments arranged along an arc is the CORRECT build,+ // A horn of five straight segments arranged along an arc is the CORRECT build,// and every segment of it is straight — so an assembly is never measured piece- // by piece, from either declaration source.+ // by piece, from either declaration source, and not through its parent either+ // even when the parent carries a sweep of its own.it('skips an assembly that can curve by arrangement', () => {const declared = collectDeclaredCurvedParts({parts: [{- id: 'tail',- name: 'Tail',+ id: 'horn',+ name: 'Horn',+ geometry: tube,children: [- { id: 'tail-a', name: 'Tail Segment A', geometry: tube },- { id: 'tail-b', name: 'Tail Segment B', geometry: tube },+ { id: 'horn-a', name: 'Horn Segment A', geometry: tube },+ { id: 'horn-b', name: 'Horn Segment B', geometry: tube },],},],- detailInventory: [{ feature: 'curved tail', implementationPartIds: ['tail-a', 'tail-b'] }],+ detailInventory: [{ feature: 'curved horn', implementationPartIds: ['horn-a', 'horn-b'] }],+ });+ expect([...declared.keys()]).toEqual([]);+ });++ // These read as curved about as often as they read as straight — a tail boom+ // runs down a fuselage, a whisker is a bristle — and the finding text steers+ // the next refinement pass, so a bare noun must not tell it to bend them.+ it('needs a curve modifier before an ambiguous noun declares anything', () => {+ const bare = collectDeclaredCurvedParts({+ parts: [+ { id: 'boom', name: 'Tail Boom', geometry: tube },+ { id: 'bristle', name: 'whiskerLeft', geometry: tube },+ ],+ });+ expect([...bare.keys()]).toEqual([]);+ const modified = collectDeclaredCurvedParts({+ parts: [{ id: 'boom', name: 'Curled Tail', geometry: tube }],});- expect([...declared.keys()]).toEqual(['tail']);+ expect([...modified.keys()]).toEqual(['boom']);});});diff --git a/server/lib/threejsModelPhysicalAudit.js b/server/lib/threejsModelPhysicalAudit.jsindex d5113822d4..fd2e3f50a1 100644--- a/server/lib/threejsModelPhysicalAudit.js+++ b/server/lib/threejsModelPhysicalAudit.js@@ -807,11 +807,6 @@ function buildBilateralChiralityFindings({ pairs, chains, volumes }) {return findings;}-/**- * @param {object|null} spec a validated Three.js scene spec- * @returns {{findings: Array, errorCount: number, warningCount: number, noteCount: number,- * evaluatedPartCount: number, evaluatedPoseCount: number}}- */const formatDegrees = (value) => `${Math.round(value)}°`;/**@@ -846,6 +841,11 @@ const buildSweptPathCurvatureFindings = (spec, parts) => {return findings;};+/**+ * @param {object|null} spec a validated Three.js scene spec+ * @returns {{findings: Array, errorCount: number, warningCount: number, noteCount: number,+ * evaluatedPartCount: number, evaluatedPoseCount: number}}+ */export function evaluateThreejsPhysicalAudit(spec) {if (!spec || !Array.isArray(spec.parts)) {return {