Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
3bc2a49
mcp: check floor procedural-item footprints in collision checks (#1255)
kruschdev Nov 22, 2026
35af300
mcp: skip wall-side drafts and honor designedTogether on procedural i…
kruschdev Nov 22, 2026
5676d7d
core: unify procedural rug underlay and category-gated pairRole checks
kruschdev Nov 22, 2026
f280175
core: preserve ceiling mounting origin and elevation across host chains
kruschdev Nov 22, 2026
8f4847b
mcp: address review feedback on recipe access and wall-hosted skip re…
kruschdev Nov 23, 2026
63c611f
fix(core): compute swept reach heights for non-recessed ceiling proce…
kruschdev Nov 23, 2026
a736fa6
fix(core): exclude ceiling- and wall-hosted descendants from floorOnl…
kruschdev Nov 23, 2026
ee7b870
fix(core): rebuild procedural level poses on nodeLevelFrame and resol…
kruschdev Dec 3, 2026
71a9220
fix(core,mcp): fix procedural plan corner winding, wallId inspection,…
kruschdev Dec 3, 2026
a77b31b
fix(core): check attached children against procedural host parts abov…
kruschdev Dec 3, 2026
5fdc85c
fix(core): align planarRotation tolerance (1e-6) with MCP plan footpr…
kruschdev Dec 3, 2026
46ce24e
fix(core): resolve hosted script-item manifest bounds through host fr…
kruschdev Dec 4, 2026
b8c98ce
fix(core): handle nested procedural attachments, floor finishes, movi…
kruschdev Dec 4, 2026
e8b192b
fix(core): harden procedural rotation checks, prototype safety, and f…
kruschdev Dec 4, 2026
e2cd9e8
fix(core,mcp): sweep procedural descendants on named surfaces and uni…
kruschdev Dec 5, 2026
e7c1406
fix(core): preserve level-parented attachTo heights and piecewise flo…
kruschdev Dec 5, 2026
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
166 changes: 152 additions & 14 deletions packages/core/src/agent-operations/door-clearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getDoorOpeningSize } from '../lib/door-opening'

import { isVehicleDoorType } from '../lib/door-operation'
import { area, intersection } from '../lib/polygon-boolean'
import type { Vec3 } from '../procedural-items/recipe'
import { evaluateRecipe, type Vec3 } from '../procedural-items/recipe'
import { boxCorners, rotateVector } from '../procedural-items/spatial'
import { type AnyNode, getScaledDimensions } from '../schema'
import { DEFAULT_WALL_THICKNESS } from '../systems/wall/wall-footprint'
Expand Down Expand Up @@ -220,7 +220,7 @@ export function itemNodePlanCorners(node: Extract<AnyNode, { type: 'item' }>): V
node.position[0] + lx * Math.cos(yaw) + lz * Math.sin(yaw),
node.position[2] - lx * Math.sin(yaw) + lz * Math.cos(yaw),
]
const bounds = node.source?.manifest.bounds
const bounds = node.source?.manifest?.bounds
if (!bounds) {
const [width, , depth] = node.asset.dimensions
return [-width / 2, width / 2].flatMap((x) =>
Expand All @@ -240,16 +240,23 @@ export function itemNodePlanCorners(node: Extract<AnyNode, { type: 'item' }>): V
})
}

export const PLANAR_ROTATION_EPSILON = 1e-6

export function hasNonFloorItemAttachment(node: Extract<AnyNode, { type: 'item' }>): boolean {
const attach = node.asset?.attachTo
return (
attach === 'wall' ||
attach === 'wall-side' ||
attach === 'ceiling' ||
Boolean(node.roofSegmentId || node.roofFace || node.blockFaceId)
)
}

export function inspectItemPlanFootprint(
node: Extract<AnyNode, { type: 'item' }>,
options?: { floorOnly?: boolean },
): ItemFootprintInspection {
if (
options?.floorOnly &&
(node.asset.attachTo === 'wall' ||
node.asset.attachTo === 'wall-side' ||
node.asset.attachTo === 'ceiling')
) {
if (options?.floorOnly && hasNonFloorItemAttachment(node)) {
return { ok: false, reason: 'unsupported_attachment' }
}

Expand All @@ -264,14 +271,17 @@ export function inspectItemPlanFootprint(
return { ok: false, reason: 'non_finite_position' }
}

const rotation = Array.isArray(node.rotation) ? node.rotation : [0, 0, 0]
const rotationX = rotation[0] ?? Number.NaN
const rotationY = rotation[1] ?? Number.NaN
const rotationZ = rotation[2] ?? Number.NaN
if (!Array.isArray(node.rotation) || node.rotation.length !== 3) {
return { ok: false, reason: 'non_finite_rotation' }
}
const [rotationX, rotationY, rotationZ] = node.rotation
if (!(Number.isFinite(rotationX) && Number.isFinite(rotationY) && Number.isFinite(rotationZ))) {
return { ok: false, reason: 'non_finite_rotation' }
}
if (Math.abs(rotationX) > 1e-6 || Math.abs(rotationZ) > 1e-6) {
if (
Math.abs(rotationX) > PLANAR_ROTATION_EPSILON ||
Math.abs(rotationZ) > PLANAR_ROTATION_EPSILON
) {
return { ok: false, reason: 'non_planar_rotation' }
}

Expand Down Expand Up @@ -324,6 +334,134 @@ export function inspectItemPlanFootprint(
}
}

export function proceduralNodePlanCorners(
node: Extract<AnyNode, { type: 'procedural-item' }>,
preEvaluated?: ReturnType<typeof evaluateRecipe>,
): Vec2[] | null {
if (!Array.isArray(node.recipe?.parts)) return null
if (!Array.isArray(node.position) || !Array.isArray(node.rotation)) return null
const [px, py, pz] = node.position
const [rx, yaw, rz] = node.rotation
if (![px, py, pz, rx, yaw, rz].every(Number.isFinite)) return null
let evaluated = preEvaluated
if (!evaluated) {
try {
evaluated = evaluateRecipe(node.recipe, node.parameters)
} catch {
return null
}
}
const extent = evaluated.reach ?? evaluated
const [width, height, depth] = evaluated.dimensions
if (
![width, height, depth, ...extent.min, ...extent.max].every(Number.isFinite) ||
width <= 0 ||
depth <= 0
) {
return null
}
const cos = Math.cos(yaw)
const sin = Math.sin(yaw)
const place = (lx: number, lz: number): Vec2 => [
px + lx * cos + lz * sin,
pz - lx * sin + lz * cos,
]
return [
place(extent.min[0], extent.min[2]),
place(extent.max[0], extent.min[2]),
place(extent.max[0], extent.max[2]),
place(extent.min[0], extent.max[2]),
]
}

export function proceduralNodePlanAabb(
node: AnyNode,
preEvaluated?: ReturnType<typeof evaluateRecipe>,
): PlanAabb | null {
if (node.type !== 'procedural-item') return null
const corners = proceduralNodePlanCorners(node, preEvaluated)
if (!corners?.every((corner) => corner.every(Number.isFinite))) return null
return {
minX: Math.min(...corners.map(([x]) => x)),
maxX: Math.max(...corners.map(([x]) => x)),
minZ: Math.min(...corners.map(([, z]) => z)),
maxZ: Math.max(...corners.map(([, z]) => z)),
}
}

export function inspectProceduralItemPlanFootprint(
node: Extract<AnyNode, { type: 'procedural-item' }>,
_options?: { floorOnly?: boolean },
): ItemFootprintInspection {
const attach = node.recipe?.mounting?.attachTo
if (node.wallId || (attach != null && (attach as string) !== 'floor')) {
return { ok: false, reason: 'unsupported_attachment' }
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

const position = node.position
if (!Array.isArray(position)) {
return { ok: false, reason: 'non_finite_position' }
}
const [x, y, z] = position
if (!(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z))) {
return { ok: false, reason: 'non_finite_position' }
}

if (!Array.isArray(node.rotation) || node.rotation.length !== 3) {
return { ok: false, reason: 'non_finite_rotation' }
}
const [rotationX, rotationY, rotationZ] = node.rotation
if (!(Number.isFinite(rotationX) && Number.isFinite(rotationY) && Number.isFinite(rotationZ))) {
return { ok: false, reason: 'non_finite_rotation' }
}
if (
Math.abs(rotationX) > PLANAR_ROTATION_EPSILON ||
Math.abs(rotationZ) > PLANAR_ROTATION_EPSILON
) {
return { ok: false, reason: 'non_planar_rotation' }
}

if (!Array.isArray(node.recipe?.parts)) {
return { ok: false, reason: 'missing_dimensions' }
}
let evaluated: ReturnType<typeof evaluateRecipe>
try {
evaluated = evaluateRecipe(node.recipe, node.parameters)
} catch {
return { ok: false, reason: 'missing_dimensions' }
}

const [width, height, depth] = evaluated.dimensions
if (![width, height, depth, ...evaluated.min, ...evaluated.max].every(Number.isFinite)) {
return { ok: false, reason: 'non_finite_dimensions' }
}
if (width <= 0 || depth <= 0) {
return { ok: false, reason: 'non_positive_plan_dimensions' }
}

const aabb = proceduralNodePlanAabb(node, evaluated)
if (!aabb) return { ok: false, reason: 'non_finite_dimensions' }
const extent = evaluated.reach ?? evaluated
const effectiveDimensions: [number, number, number] = [
extent.max[0] - extent.min[0],
extent.max[1] - extent.min[1],
extent.max[2] - extent.min[2],
]
if (!effectiveDimensions.every(Number.isFinite)) {
return { ok: false, reason: 'non_finite_dimensions' }
}
if (effectiveDimensions[0] <= 0 || effectiveDimensions[2] <= 0) {
return { ok: false, reason: 'non_positive_plan_dimensions' }
}
return {
ok: true,
aabb,
sourceDimensions: [width, height, depth],
effectiveDimensions,
rotationY,
}
}

/**
* Build a rectangular keep-out around a wall door, extruded perpendicular to the wall
* on both faces so either swing side is protected.
Expand Down Expand Up @@ -610,7 +748,7 @@ export function findBlockedDoors(args: {

const aabb = itemPlanAabbInLevel(node, byId)
if (!aabb) continue
const heights = args.heightsOf?.(node) ?? itemLevelHeightRange(node, byId)
const heights = args.heightsOf ? args.heightsOf(node) : itemLevelHeightRange(node, byId)
const solids = args.solidsOf?.(node) ?? null

const vehicle = isVehicle(node)
Expand Down
81 changes: 64 additions & 17 deletions packages/core/src/agent-operations/furniture-kind.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { foldRoomName } from '../building/room-use'
import type { ProceduralItemNode } from '../procedural-items/node'
import { evaluateRecipe } from '../procedural-items/recipe'
import { getScaledDimensions, type ItemNode, LOW_PROFILE_ITEM_SURFACE_MAX_HEIGHT } from '../schema'

/** How a piece of furniture stands in a room, read from what the catalog calls it. */
Expand Down Expand Up @@ -45,31 +47,65 @@ export function isVehicle(item: ItemNode): boolean {
* a rug by what it is filed under (its category: "rug", "rugs", "tapis"), else by what it is called
* in English or French, and in both cases it must lie flat on the floor.
*/
export function isFloorUnderlay(item: ItemNode): boolean {
const category = foldRoomName(item.asset.category ?? '')
export function isFloorUnderlay(node: ItemNode | ProceduralItemNode): boolean {
if (node.type === 'procedural-item') {
if (node.recipe?.mounting || node.wallId || !Array.isArray(node.recipe?.parts)) return false
const category = foldRoomName(node.recipe.classification?.category ?? '').replace(/[-_]+/g, ' ')
const filedAsRug = RUG_CATEGORY.test(category)
const text = foldRoomName(
read({ id: node.recipe.name ?? node.id, name: node.name ?? node.recipe.name }),
)
if (
!(filedAsRug || RUG_WORD.test(text)) ||
(!filedAsRug &&
(WALL.test(text) || CHAIR.test(text) || /table|desk|ottoman|pouf/.test(text))) ||
!Array.isArray(node.position) ||
!Array.isArray(node.rotation) ||
![...node.position, ...node.rotation].every(Number.isFinite) ||
Math.abs(node.position[1]) > 1e-6 ||
Math.abs(node.rotation[0]) > 1e-6 ||
Math.abs(node.rotation[2]) > 1e-6
)
return false
try {
const evaluated = evaluateRecipe(node.recipe, node.parameters)
return (
evaluated.dimensions[0] > 0 &&
evaluated.dimensions[2] > 0 &&
Number.isFinite(evaluated.min[1]) &&
Number.isFinite(evaluated.max[1]) &&
evaluated.min[1] >= -1e-6 &&
evaluated.max[1] >= evaluated.min[1] &&
evaluated.max[1] <= LOW_PROFILE_ITEM_SURFACE_MAX_HEIGHT
)
} catch {
return false
}
}
const category = foldRoomName(node.asset.category ?? '').replace(/[-_]+/g, ' ')
const filedAsRug = RUG_CATEGORY.test(category)
const text = foldRoomName(read(item.asset))
const text = foldRoomName(read(node.asset))
if (
!(filedAsRug || RUG_WORD.test(text)) ||
(!filedAsRug &&
(WALL.test(text) || CHAIR.test(text) || /table|desk|ottoman|pouf/.test(text))) ||
item.asset.attachTo
node.asset.attachTo
)
return false
const dims = getScaledDimensions(item)
const dims = getScaledDimensions(node)
if (
![...item.position, ...item.rotation, ...item.scale, ...dims].every(Number.isFinite) ||
!item.scale.every((value) => value > 0) ||
![...node.position, ...node.rotation, ...node.scale, ...dims].every(Number.isFinite) ||
!node.scale.every((value) => value > 0) ||
dims[0] <= 0 ||
dims[2] <= 0 ||
Math.abs(item.position[1]) > 1e-6 ||
Math.abs(item.rotation[0]) > 1e-6 ||
Math.abs(item.rotation[2]) > 1e-6
Math.abs(node.position[1]) > 1e-6 ||
Math.abs(node.rotation[0]) > 1e-6 ||
Math.abs(node.rotation[2]) > 1e-6
)
return false
const bounds = item.source?.manifest.bounds
const bottom = bounds ? bounds.min[1] * item.scale[1] : 0
const top = bounds ? bounds.max[1] * item.scale[1] : dims[1]
const bounds = node.source?.manifest?.bounds
const bottom = bounds ? bounds.min[1] * node.scale[1] : 0
const top = bounds ? bounds.max[1] * node.scale[1] : dims[1]
return (
Number.isFinite(bottom) &&
Number.isFinite(top) &&
Expand Down Expand Up @@ -126,12 +162,20 @@ const ROLE_NOT: Partial<Record<PairRole, RegExp>> = {
}
const PAIR_ROLES: PairRole[] = ['bedside', 'bed', 'seat', 'sidetable', 'sofa', 'worktop']

function pairRole(item: ItemNode): PairRole | null {
const category = foldRoomName(item.asset.category ?? '').replace(/[-_]+/g, ' ')
function pairRole(node: ItemNode | ProceduralItemNode): PairRole | null {
const rawCategory =
node.type === 'procedural-item'
? (node.recipe?.classification?.category ?? '')
: (node.asset.category ?? '')
const named: Named =
node.type === 'procedural-item'
? { id: node.recipe?.name ?? node.id, name: node.name ?? node.recipe?.name }
: node.asset
const category = foldRoomName(rawCategory).replace(/[-_]+/g, ' ')
const filed = PAIR_ROLES.find((role) => ROLE_CATEGORY[role].test(category))
if (filed) return filed
if (!GENERIC_CATEGORY.test(category)) return null
const text = foldRoomName(read(item.asset))
const text = foldRoomName(read(named))
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
if (ARMCHAIR.test(text)) return null
return (
PAIR_ROLES.find((role) => ROLE_WORDS[role].test(text) && !ROLE_NOT[role]?.test(text)) ?? null
Expand All @@ -150,7 +194,10 @@ const DESIGNED_PAIRS: readonly [PairRole, PairRole][] = [
* the design, not a finding; two of them overlapping is still one. Read from what each is filed
* under (its category), by its words only where the category says nothing.
*/
export function designedTogether(a: ItemNode, b: ItemNode): boolean {
export function designedTogether(
a: ItemNode | ProceduralItemNode,
b: ItemNode | ProceduralItemNode,
): boolean {
const roles = [pairRole(a), pairRole(b)]
return DESIGNED_PAIRS.some(
([first, second]) =>
Expand Down
Loading
Loading