@kruschdev/pascal-mep-kernel 0.1.0 → 0.1.1

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.
@@ -2,7 +2,7 @@ import {
2
2
  INCHES_TO_METERS2,
3
3
  METERS_TO_FEET2,
4
4
  round32
5
- } from "./chunk-jfzqztgh.js";
5
+ } from "./chunk-yd3hcm7n.js";
6
6
 
7
7
  // src/rules/evaluator.ts
8
8
  var OUTDOOR_ROOM_TOKENS = new Set([
@@ -55,9 +55,9 @@ function makeViolation(rule, candidate, message) {
55
55
  nodeIds: candidate.id ? [candidate.id] : []
56
56
  };
57
57
  }
58
- function candidateY(candidate) {
58
+ function candidateFiniteY(candidate) {
59
59
  const y = candidate.pos[1];
60
- return Number.isFinite(y) ? y : 0;
60
+ return typeof y === "number" && Number.isFinite(y) ? y : null;
61
61
  }
62
62
  function evaluateProhibitedZone(rule, candidate, mode) {
63
63
  const { params } = rule;
@@ -75,11 +75,15 @@ function evaluateProhibitedZone(rule, candidate, mode) {
75
75
  violations.push(makeViolation(rule, candidate, `${candidate.kind} with NEMA rating "${candidate.nemaRating}" is forbidden outdoors (${rule.codeRef}).`));
76
76
  }
77
77
  if (params.requireBelowCeilingForAttic) {
78
- if (candidate.ceilingHeightM !== undefined && Number.isFinite(candidate.ceilingHeightM)) {
79
- const y = candidateY(candidate);
80
- const maxAllowedY = resolveThreshold(candidate.ceilingHeightM, rule.placementMarginM, "max", mode);
81
- if (y > maxAllowedY) {
82
- violations.push(makeViolation(rule, candidate, `${candidate.kind} elevation ${round32(y)}m exceeds ceiling limit ${round32(maxAllowedY)}m (${rule.codeRef}).`));
78
+ if (candidate.ceilingHeightM !== undefined) {
79
+ if (!Number.isFinite(candidate.ceilingHeightM)) {
80
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} has non-finite ceiling height (${String(candidate.ceilingHeightM)}) and fails attic/ceiling check (${rule.codeRef}).`));
81
+ } else {
82
+ const y = candidateFiniteY(candidate);
83
+ const maxAllowedY = resolveThreshold(candidate.ceilingHeightM, rule.placementMarginM, "max", mode);
84
+ if (y === null || y > maxAllowedY) {
85
+ violations.push(makeViolation(rule, candidate, y === null ? `${candidate.kind} has non-finite elevation (${String(candidate.pos[1])}) and fails ceiling limit ${round32(maxAllowedY)}m (${rule.codeRef}).` : `${candidate.kind} elevation ${round32(y)}m exceeds ceiling limit ${round32(maxAllowedY)}m (${rule.codeRef}).`));
86
+ }
83
87
  }
84
88
  } else if (roomNorm === "attic" && !roomProhibited) {
85
89
  violations.push(makeViolation(rule, candidate, `${candidate.kind} is prohibited in attic space above the ceiling (${rule.codeRef}).`));
@@ -95,34 +99,38 @@ function evaluateFixtureKeepout(rule, candidate, mode) {
95
99
  const nearFixtures = candidate.nearFixtures;
96
100
  if (!nearFixtures || nearFixtures.length === 0)
97
101
  return [];
98
- const y = candidateY(candidate);
102
+ const y = candidateFiniteY(candidate);
99
103
  const effMinH = resolveThreshold(params.minHorizontalM, rule.placementMarginM, "min", mode);
100
- if (params.verticalBandM) {
101
- const [bandLow, bandHigh] = params.verticalBandM;
102
- const effLow = resolveThreshold(bandLow, rule.placementMarginM, "max", mode);
103
- const effHigh = resolveThreshold(bandHigh, rule.placementMarginM, "min", mode);
104
- if (y < effLow || y > effHigh)
105
- return [];
106
- }
107
- if (params.minVerticalM !== undefined && Number.isFinite(params.minVerticalM)) {
108
- const effMinV = resolveThreshold(params.minVerticalM, rule.placementMarginM, "max", mode);
109
- if (y < effMinV)
110
- return [];
111
- }
112
- if (params.maxVerticalM !== undefined && Number.isFinite(params.maxVerticalM)) {
113
- const effMaxV = resolveThreshold(params.maxVerticalM, rule.placementMarginM, "min", mode);
114
- if (y > effMaxV)
115
- return [];
104
+ if (y !== null) {
105
+ if (params.verticalBandM) {
106
+ const [bandLow, bandHigh] = params.verticalBandM;
107
+ const effLow = resolveThreshold(bandLow, rule.placementMarginM, "max", mode);
108
+ const effHigh = resolveThreshold(bandHigh, rule.placementMarginM, "min", mode);
109
+ if (y < effLow || y > effHigh)
110
+ return [];
111
+ }
112
+ if (params.minVerticalM !== undefined && Number.isFinite(params.minVerticalM)) {
113
+ const effMinV = resolveThreshold(params.minVerticalM, rule.placementMarginM, "max", mode);
114
+ if (y < effMinV)
115
+ return [];
116
+ }
117
+ if (params.maxVerticalM !== undefined && Number.isFinite(params.maxVerticalM)) {
118
+ const effMaxV = resolveThreshold(params.maxVerticalM, rule.placementMarginM, "min", mode);
119
+ if (y > effMaxV)
120
+ return [];
121
+ }
116
122
  }
117
123
  const violations = [];
118
124
  for (const fx of nearFixtures) {
119
125
  if (!matchesAnyToken(fx.kind, params.fixtureKinds))
120
126
  continue;
121
- if (!Number.isFinite(fx.horizontalDistM))
122
- continue;
123
127
  if (params.respectWallSeparation && (fx.separatedByWall === true || candidate.wallSeparated === true)) {
124
128
  continue;
125
129
  }
130
+ if (!Number.isFinite(fx.horizontalDistM)) {
131
+ violations.push(makeViolation(rule, candidate, `${candidate.role ?? candidate.kind} has non-finite distance (${String(fx.horizontalDistM)}) from "${fx.kind}" (minimum required ${round32(effMinH)}m, ${rule.codeRef}).`));
132
+ continue;
133
+ }
126
134
  const violatesHorizontal = effMinH <= 0 ? fx.horizontalDistM <= 0 : fx.horizontalDistM < effMinH;
127
135
  if (violatesHorizontal) {
128
136
  violations.push(makeViolation(rule, candidate, `${candidate.role ?? candidate.kind} is ${round32(fx.horizontalDistM)}m from "${fx.kind}" (minimum required ${round32(effMinH)}m, ${rule.codeRef}).`));
@@ -147,13 +155,13 @@ function evaluateOpeningKeepout(rule, candidate, mode) {
147
155
  if (clearHorizontally)
148
156
  return [];
149
157
  }
150
- const y = candidateY(candidate);
158
+ const y = candidateFiniteY(candidate);
151
159
  const hasSill = candidate.openingSillYM !== undefined && Number.isFinite(candidate.openingSillYM);
152
160
  const hasHead = candidate.openingHeadYM !== undefined && Number.isFinite(candidate.openingHeadYM);
153
161
  if (params.floorToCeilingSillThresholdM !== undefined && Number.isFinite(params.floorToCeilingSillThresholdM) && hasSill) {
154
162
  const effSillThreshold = resolveThreshold(params.floorToCeilingSillThresholdM, rule.placementMarginM, "min", mode);
155
163
  const maxHeadY = hasHead ? candidate.openingHeadYM + effTrim : Number.POSITIVE_INFINITY;
156
- if (candidate.openingSillYM <= effSillThreshold && y <= maxHeadY) {
164
+ if (candidate.openingSillYM <= effSillThreshold && (y === null || y <= maxHeadY)) {
157
165
  return [
158
166
  makeViolation(rule, candidate, `${candidate.role ?? candidate.kind} falls within floor-to-ceiling ${candidate.openingKind} glazing (sill ${round32(candidate.openingSillYM)}m <= ${round32(effSillThreshold)}m, ${rule.codeRef}).`)
159
167
  ];
@@ -162,9 +170,9 @@ function evaluateOpeningKeepout(rule, candidate, mode) {
162
170
  if (hasSill || hasHead) {
163
171
  const lowY = hasSill ? candidate.openingSillYM - effTrim : Number.NEGATIVE_INFINITY;
164
172
  const highY = hasHead ? candidate.openingHeadYM + effTrim : Number.POSITIVE_INFINITY;
165
- if (y >= lowY && y <= highY) {
173
+ if (y === null || y >= lowY && y <= highY) {
166
174
  return [
167
- makeViolation(rule, candidate, `${candidate.role ?? candidate.kind} at y=${round32(y)}m intersects ${candidate.openingKind} opening/trim keepout [${hasSill ? round32(lowY) : "-inf"}m, ${hasHead ? round32(highY) : "+inf"}m] (${rule.codeRef}).`)
175
+ makeViolation(rule, candidate, y === null ? `${candidate.role ?? candidate.kind} has non-finite elevation (${String(candidate.pos[1])}) and fails ${candidate.openingKind} keepout [${hasSill ? round32(lowY) : "-inf"}m, ${hasHead ? round32(highY) : "+inf"}m] (${rule.codeRef}).` : `${candidate.role ?? candidate.kind} at y=${round32(y)}m intersects ${candidate.openingKind} opening/trim keepout [${hasSill ? round32(lowY) : "-inf"}m, ${hasHead ? round32(highY) : "+inf"}m] (${rule.codeRef}).`)
168
176
  ];
169
177
  }
170
178
  return [];
@@ -179,7 +187,21 @@ function evaluateElevationBand(rule, candidate, mode) {
179
187
  return [];
180
188
  }
181
189
  const violations = [];
182
- const y = candidateY(candidate);
190
+ const y = candidateFiniteY(candidate);
191
+ if (y === null) {
192
+ const hasExplicitHandleY = candidate.handleHeightM !== undefined && Number.isFinite(candidate.handleHeightM);
193
+ const needsPosY = params.minYM !== undefined && Number.isFinite(params.minYM) || params.maxYM !== undefined && Number.isFinite(params.maxYM) || params.minAboveFloodRimM !== undefined && Number.isFinite(params.minAboveFloodRimM) && candidate.floodRimM !== undefined || params.maxHandleHeightM !== undefined && Number.isFinite(params.maxHandleHeightM) && !hasExplicitHandleY || params.roofMarginM !== undefined && Number.isFinite(params.roofMarginM) && candidate.roofSurfaceYM !== undefined || params.atticThresholdOffsetM !== undefined && Number.isFinite(params.atticThresholdOffsetM) && candidate.ceilingHeightM !== undefined;
194
+ if (needsPosY) {
195
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} has non-finite elevation (${String(candidate.pos[1])}) and fails elevation-band check (${rule.codeRef}).`));
196
+ }
197
+ if (params.maxHandleHeightM !== undefined && Number.isFinite(params.maxHandleHeightM) && hasExplicitHandleY) {
198
+ const effMaxHandle = resolveThreshold(params.maxHandleHeightM, rule.placementMarginM, "max", mode);
199
+ if (candidate.handleHeightM > effMaxHandle) {
200
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} handle height ${round32(candidate.handleHeightM)}m exceeds maximum ${round32(effMaxHandle)}m (${rule.codeRef}).`));
201
+ }
202
+ }
203
+ return violations;
204
+ }
183
205
  if (params.minYM !== undefined && Number.isFinite(params.minYM)) {
184
206
  const effMinY = resolveThreshold(params.minYM, rule.placementMarginM, "min", mode);
185
207
  if (y < effMinY) {
@@ -192,32 +214,48 @@ function evaluateElevationBand(rule, candidate, mode) {
192
214
  violations.push(makeViolation(rule, candidate, `${candidate.kind} elevation ${round32(y)}m exceeds maximum ${round32(effMaxY)}m (${rule.codeRef}).`));
193
215
  }
194
216
  }
195
- if (params.minAboveFloodRimM !== undefined && Number.isFinite(params.minAboveFloodRimM) && candidate.floodRimM !== undefined && Number.isFinite(candidate.floodRimM)) {
196
- const effClearance = resolveThreshold(params.minAboveFloodRimM, rule.placementMarginM, "min", mode);
197
- const requiredY = candidate.floodRimM + effClearance;
198
- if (y < requiredY) {
199
- violations.push(makeViolation(rule, candidate, `${candidate.kind} elevation ${round32(y)}m is below flood-rim minimum ${round32(requiredY)}m (${round32(candidate.floodRimM)}m + ${round32(effClearance)}m, ${rule.codeRef}).`));
217
+ if (params.minAboveFloodRimM !== undefined && Number.isFinite(params.minAboveFloodRimM) && candidate.floodRimM !== undefined) {
218
+ if (!Number.isFinite(candidate.floodRimM)) {
219
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} has non-finite flood-rim elevation (${String(candidate.floodRimM)}) (${rule.codeRef}).`));
220
+ } else {
221
+ const effClearance = resolveThreshold(params.minAboveFloodRimM, rule.placementMarginM, "min", mode);
222
+ const requiredY = candidate.floodRimM + effClearance;
223
+ if (y < requiredY) {
224
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} elevation ${round32(y)}m is below flood-rim minimum ${round32(requiredY)}m (${round32(candidate.floodRimM)}m + ${round32(effClearance)}m, ${rule.codeRef}).`));
225
+ }
200
226
  }
201
227
  }
202
228
  if (params.maxHandleHeightM !== undefined && Number.isFinite(params.maxHandleHeightM)) {
203
- const handleY = candidate.handleHeightM !== undefined && Number.isFinite(candidate.handleHeightM) ? candidate.handleHeightM : y;
204
- const effMaxHandle = resolveThreshold(params.maxHandleHeightM, rule.placementMarginM, "max", mode);
205
- if (handleY > effMaxHandle) {
206
- violations.push(makeViolation(rule, candidate, `${candidate.kind} handle height ${round32(handleY)}m exceeds maximum ${round32(effMaxHandle)}m (${rule.codeRef}).`));
229
+ if (candidate.handleHeightM !== undefined && !Number.isFinite(candidate.handleHeightM)) {
230
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} has non-finite handle height (${String(candidate.handleHeightM)}) (${rule.codeRef}).`));
231
+ } else {
232
+ const handleY = candidate.handleHeightM !== undefined ? candidate.handleHeightM : y;
233
+ const effMaxHandle = resolveThreshold(params.maxHandleHeightM, rule.placementMarginM, "max", mode);
234
+ if (handleY > effMaxHandle) {
235
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} handle height ${round32(handleY)}m exceeds maximum ${round32(effMaxHandle)}m (${rule.codeRef}).`));
236
+ }
207
237
  }
208
238
  }
209
- if (params.roofMarginM !== undefined && Number.isFinite(params.roofMarginM) && candidate.roofSurfaceYM !== undefined && Number.isFinite(candidate.roofSurfaceYM)) {
210
- const effRoofMargin = resolveThreshold(params.roofMarginM, rule.placementMarginM, "min", mode);
211
- const maxAllowedY = candidate.roofSurfaceYM - effRoofMargin;
212
- if (y > maxAllowedY) {
213
- violations.push(makeViolation(rule, candidate, `${candidate.kind} elevation ${round32(y)}m encroaches on roof surface ${round32(candidate.roofSurfaceYM)}m (required margin ${round32(effRoofMargin)}m, ${rule.codeRef}).`));
239
+ if (params.roofMarginM !== undefined && Number.isFinite(params.roofMarginM) && candidate.roofSurfaceYM !== undefined) {
240
+ if (!Number.isFinite(candidate.roofSurfaceYM)) {
241
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} has non-finite roof surface elevation (${String(candidate.roofSurfaceYM)}) (${rule.codeRef}).`));
242
+ } else {
243
+ const effRoofMargin = resolveThreshold(params.roofMarginM, rule.placementMarginM, "min", mode);
244
+ const maxAllowedY = candidate.roofSurfaceYM - effRoofMargin;
245
+ if (y > maxAllowedY) {
246
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} elevation ${round32(y)}m encroaches on roof surface ${round32(candidate.roofSurfaceYM)}m (required margin ${round32(effRoofMargin)}m, ${rule.codeRef}).`));
247
+ }
214
248
  }
215
249
  }
216
- if (params.atticThresholdOffsetM !== undefined && Number.isFinite(params.atticThresholdOffsetM) && candidate.ceilingHeightM !== undefined && Number.isFinite(candidate.ceilingHeightM)) {
217
- const atticBoundary = candidate.ceilingHeightM + params.atticThresholdOffsetM;
218
- const effBoundary = resolveThreshold(atticBoundary, rule.placementMarginM, "max", mode);
219
- if (y > effBoundary) {
220
- violations.push(makeViolation(rule, candidate, `${candidate.kind} elevation ${round32(y)}m exceeds attic threshold ${round32(effBoundary)}m (${rule.codeRef}).`));
250
+ if (params.atticThresholdOffsetM !== undefined && Number.isFinite(params.atticThresholdOffsetM) && candidate.ceilingHeightM !== undefined) {
251
+ if (!Number.isFinite(candidate.ceilingHeightM)) {
252
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} has non-finite ceiling height (${String(candidate.ceilingHeightM)}) (${rule.codeRef}).`));
253
+ } else {
254
+ const atticBoundary = candidate.ceilingHeightM + params.atticThresholdOffsetM;
255
+ const effBoundary = resolveThreshold(atticBoundary, rule.placementMarginM, "max", mode);
256
+ if (y > effBoundary) {
257
+ violations.push(makeViolation(rule, candidate, `${candidate.kind} elevation ${round32(y)}m exceeds attic threshold ${round32(effBoundary)}m (${rule.codeRef}).`));
258
+ }
221
259
  }
222
260
  }
223
261
  return violations;
@@ -228,28 +266,28 @@ function evaluateWorkingSpace(rule, candidate, mode) {
228
266
  return [];
229
267
  }
230
268
  const violations = [];
231
- if (candidate.workingSpaceWidthM !== undefined && Number.isFinite(candidate.workingSpaceWidthM)) {
269
+ if (candidate.workingSpaceWidthM !== undefined) {
232
270
  const effW = resolveThreshold(params.widthM, rule.placementMarginM, "min", mode);
233
- if (candidate.workingSpaceWidthM < effW) {
234
- violations.push(makeViolation(rule, candidate, `${candidate.kind} working space width ${round32(candidate.workingSpaceWidthM)}m is below required ${round32(effW)}m (${rule.codeRef}).`));
271
+ if (!Number.isFinite(candidate.workingSpaceWidthM) || candidate.workingSpaceWidthM < effW) {
272
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.workingSpaceWidthM) ? `${candidate.kind} has non-finite working space width (${String(candidate.workingSpaceWidthM)}) (required ${round32(effW)}m, ${rule.codeRef}).` : `${candidate.kind} working space width ${round32(candidate.workingSpaceWidthM)}m is below required ${round32(effW)}m (${rule.codeRef}).`));
235
273
  }
236
274
  }
237
- if (candidate.workingSpaceDepthM !== undefined && Number.isFinite(candidate.workingSpaceDepthM)) {
275
+ if (candidate.workingSpaceDepthM !== undefined) {
238
276
  const effD = resolveThreshold(params.depthM, rule.placementMarginM, "min", mode);
239
- if (candidate.workingSpaceDepthM < effD) {
240
- violations.push(makeViolation(rule, candidate, `${candidate.kind} working space depth ${round32(candidate.workingSpaceDepthM)}m is below required ${round32(effD)}m (${rule.codeRef}).`));
277
+ if (!Number.isFinite(candidate.workingSpaceDepthM) || candidate.workingSpaceDepthM < effD) {
278
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.workingSpaceDepthM) ? `${candidate.kind} has non-finite working space depth (${String(candidate.workingSpaceDepthM)}) (required ${round32(effD)}m, ${rule.codeRef}).` : `${candidate.kind} working space depth ${round32(candidate.workingSpaceDepthM)}m is below required ${round32(effD)}m (${rule.codeRef}).`));
241
279
  }
242
280
  }
243
- if (candidate.workingSpaceHeightM !== undefined && Number.isFinite(candidate.workingSpaceHeightM)) {
281
+ if (candidate.workingSpaceHeightM !== undefined) {
244
282
  const effH = resolveThreshold(params.heightM, rule.placementMarginM, "min", mode);
245
- if (candidate.workingSpaceHeightM < effH) {
246
- violations.push(makeViolation(rule, candidate, `${candidate.kind} working space headroom ${round32(candidate.workingSpaceHeightM)}m is below required ${round32(effH)}m (${rule.codeRef}).`));
283
+ if (!Number.isFinite(candidate.workingSpaceHeightM) || candidate.workingSpaceHeightM < effH) {
284
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.workingSpaceHeightM) ? `${candidate.kind} has non-finite working space headroom (${String(candidate.workingSpaceHeightM)}) (required ${round32(effH)}m, ${rule.codeRef}).` : `${candidate.kind} working space headroom ${round32(candidate.workingSpaceHeightM)}m is below required ${round32(effH)}m (${rule.codeRef}).`));
247
285
  }
248
286
  }
249
- if (params.dedicatedOverheadHeightM !== undefined && Number.isFinite(params.dedicatedOverheadHeightM) && candidate.dedicatedOverheadClearHeightM !== undefined && Number.isFinite(candidate.dedicatedOverheadClearHeightM)) {
287
+ if (params.dedicatedOverheadHeightM !== undefined && Number.isFinite(params.dedicatedOverheadHeightM) && candidate.dedicatedOverheadClearHeightM !== undefined) {
250
288
  const effOverhead = resolveThreshold(params.dedicatedOverheadHeightM, rule.placementMarginM, "min", mode);
251
- if (candidate.dedicatedOverheadClearHeightM < effOverhead) {
252
- violations.push(makeViolation(rule, candidate, `${candidate.kind} dedicated overhead clearance ${round32(candidate.dedicatedOverheadClearHeightM)}m is below required ${round32(effOverhead)}m (${rule.codeRef}).`));
289
+ if (!Number.isFinite(candidate.dedicatedOverheadClearHeightM) || candidate.dedicatedOverheadClearHeightM < effOverhead) {
290
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.dedicatedOverheadClearHeightM) ? `${candidate.kind} has non-finite dedicated overhead clearance (${String(candidate.dedicatedOverheadClearHeightM)}) (required ${round32(effOverhead)}m, ${rule.codeRef}).` : `${candidate.kind} dedicated overhead clearance ${round32(candidate.dedicatedOverheadClearHeightM)}m is below required ${round32(effOverhead)}m (${rule.codeRef}).`));
253
291
  }
254
292
  }
255
293
  return violations;
@@ -301,45 +339,50 @@ function evaluateRoutingConstraint(rule, candidate, mode) {
301
339
  }
302
340
  const violations = [];
303
341
  const marginFt = clampNonNegativeMargin(rule.placementMarginM) * METERS_TO_FEET2;
304
- if (params.maxBendDegrees !== undefined && Number.isFinite(params.maxBendDegrees) && candidate.bendDegrees !== undefined && Number.isFinite(candidate.bendDegrees)) {
305
- if (candidate.bendDegrees > params.maxBendDegrees) {
306
- violations.push(makeViolation(rule, candidate, `${systemToken} total bends ${round32(candidate.bendDegrees)}° exceed maximum ${round32(params.maxBendDegrees)}° (${rule.codeRef}).`));
342
+ if (params.maxBendDegrees !== undefined && Number.isFinite(params.maxBendDegrees) && candidate.bendDegrees !== undefined) {
343
+ if (!Number.isFinite(candidate.bendDegrees) || candidate.bendDegrees > params.maxBendDegrees) {
344
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.bendDegrees) ? `${systemToken} has non-finite total bends (${String(candidate.bendDegrees)}) (maximum ${round32(params.maxBendDegrees)}°, ${rule.codeRef}).` : `${systemToken} total bends ${round32(candidate.bendDegrees)}° exceed maximum ${round32(params.maxBendDegrees)}° (${rule.codeRef}).`));
307
345
  }
308
346
  }
309
- if (params.minSlopeInPerFt !== undefined && Number.isFinite(params.minSlopeInPerFt) && candidate.slopeInPerFt !== undefined && Number.isFinite(candidate.slopeInPerFt)) {
347
+ if (params.minSlopeInPerFt !== undefined && Number.isFinite(params.minSlopeInPerFt) && candidate.slopeInPerFt !== undefined) {
310
348
  const slopeMarginInPerFt = clampNonNegativeMargin(params.placementSlopeMarginInPerFt);
311
349
  const effMinSlope = resolveThreshold(params.minSlopeInPerFt, slopeMarginInPerFt, "min", mode);
312
- if (candidate.slopeInPerFt < effMinSlope) {
313
- violations.push(makeViolation(rule, candidate, `${systemToken} slope ${round32(candidate.slopeInPerFt)} in/ft is below minimum ${round32(effMinSlope)} in/ft (${rule.codeRef}).`));
350
+ if (!Number.isFinite(candidate.slopeInPerFt) || candidate.slopeInPerFt < effMinSlope) {
351
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.slopeInPerFt) ? `${systemToken} has non-finite slope (${String(candidate.slopeInPerFt)}) (minimum ${round32(effMinSlope)} in/ft, ${rule.codeRef}).` : `${systemToken} slope ${round32(candidate.slopeInPerFt)} in/ft is below minimum ${round32(effMinSlope)} in/ft (${rule.codeRef}).`));
314
352
  }
315
353
  }
316
- if (params.maxEffectiveLengthFt !== undefined && Number.isFinite(params.maxEffectiveLengthFt) && candidate.effectiveLengthFt !== undefined && Number.isFinite(candidate.effectiveLengthFt)) {
354
+ if (params.maxEffectiveLengthFt !== undefined && Number.isFinite(params.maxEffectiveLengthFt) && candidate.effectiveLengthFt !== undefined) {
317
355
  const effMaxFt = resolveThreshold(params.maxEffectiveLengthFt, marginFt, "max", mode);
318
- if (candidate.effectiveLengthFt > effMaxFt) {
319
- violations.push(makeViolation(rule, candidate, `${systemToken} effective length ${round32(candidate.effectiveLengthFt)} ft exceeds maximum ${round32(effMaxFt)} ft (${rule.codeRef}).`));
356
+ if (!Number.isFinite(candidate.effectiveLengthFt) || candidate.effectiveLengthFt > effMaxFt) {
357
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.effectiveLengthFt) ? `${systemToken} has non-finite effective length (${String(candidate.effectiveLengthFt)}) (maximum ${round32(effMaxFt)} ft, ${rule.codeRef}).` : `${systemToken} effective length ${round32(candidate.effectiveLengthFt)} ft exceeds maximum ${round32(effMaxFt)} ft (${rule.codeRef}).`));
320
358
  }
321
359
  }
322
360
  if (params.maxLengthFtWithoutCleanout !== undefined && Number.isFinite(params.maxLengthFtWithoutCleanout) && candidate.hasCleanout !== true) {
323
- const runLenFt = candidate.runLengthFt !== undefined && Number.isFinite(candidate.runLengthFt) ? candidate.runLengthFt : candidate.effectiveLengthFt;
324
- if (runLenFt !== undefined && Number.isFinite(runLenFt)) {
361
+ const runLenFt = candidate.runLengthFt !== undefined ? candidate.runLengthFt : candidate.effectiveLengthFt;
362
+ if (runLenFt !== undefined) {
325
363
  const effMaxCleanoutFt = resolveThreshold(params.maxLengthFtWithoutCleanout, marginFt, "max", mode);
326
- if (runLenFt > effMaxCleanoutFt) {
327
- violations.push(makeViolation(rule, candidate, `${systemToken} run length ${round32(runLenFt)} ft exceeds ${round32(effMaxCleanoutFt)} ft without a cleanout (${rule.codeRef}).`));
364
+ if (!Number.isFinite(runLenFt) || runLenFt > effMaxCleanoutFt) {
365
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(runLenFt) ? `${systemToken} has non-finite run length (${String(runLenFt)}) without a cleanout (limit ${round32(effMaxCleanoutFt)} ft, ${rule.codeRef}).` : `${systemToken} run length ${round32(runLenFt)} ft exceeds ${round32(effMaxCleanoutFt)} ft without a cleanout (${rule.codeRef}).`));
328
366
  }
329
367
  }
330
368
  }
331
- if (params.minNominalSizeIn !== undefined && Number.isFinite(params.minNominalSizeIn) && candidate.nominalSizeIn !== undefined && Number.isFinite(candidate.nominalSizeIn)) {
332
- if (candidate.nominalSizeIn < params.minNominalSizeIn) {
333
- violations.push(makeViolation(rule, candidate, `${systemToken} nominal size ${round32(candidate.nominalSizeIn)}" is below minimum ${round32(params.minNominalSizeIn)}" (${rule.codeRef}).`));
369
+ if (params.minNominalSizeIn !== undefined && Number.isFinite(params.minNominalSizeIn) && candidate.nominalSizeIn !== undefined) {
370
+ if (!Number.isFinite(candidate.nominalSizeIn) || candidate.nominalSizeIn < params.minNominalSizeIn) {
371
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.nominalSizeIn) ? `${systemToken} has non-finite nominal size (${String(candidate.nominalSizeIn)}) (minimum ${round32(params.minNominalSizeIn)}", ${rule.codeRef}).` : `${systemToken} nominal size ${round32(candidate.nominalSizeIn)}" is below minimum ${round32(params.minNominalSizeIn)}" (${rule.codeRef}).`));
334
372
  }
335
373
  }
336
374
  return violations;
337
375
  }
338
376
  function evaluateWallCavityFit(rule, candidate, mode) {
339
377
  const { params } = rule;
340
- if (candidate.nominalSizeIn === undefined || !Number.isFinite(candidate.nominalSizeIn) || candidate.wallThicknessM === undefined || !Number.isFinite(candidate.wallThicknessM)) {
378
+ if (candidate.nominalSizeIn === undefined || candidate.wallThicknessM === undefined) {
341
379
  return [];
342
380
  }
381
+ if (!Number.isFinite(candidate.nominalSizeIn) || !Number.isFinite(candidate.wallThicknessM)) {
382
+ return [
383
+ makeViolation(rule, candidate, `Non-finite wall-cavity-fit measurement (nominalSizeIn=${String(candidate.nominalSizeIn)}, wallThicknessM=${String(candidate.wallThicknessM)}, ${rule.codeRef}).`)
384
+ ];
385
+ }
343
386
  if (candidate.nominalSizeIn < params.minPipeNominalIn) {
344
387
  return [];
345
388
  }
@@ -357,32 +400,38 @@ function evaluateWindSeismicThreshold(rule, candidate, mode) {
357
400
  const { params } = rule;
358
401
  const violations = [];
359
402
  const wind = candidate.designWindMph !== undefined && Number.isFinite(candidate.designWindMph) ? candidate.designWindMph : undefined;
403
+ if (candidate.designWindMph !== undefined && !Number.isFinite(candidate.designWindMph)) {
404
+ violations.push(makeViolation(rule, candidate, `Non-finite design wind speed (${String(candidate.designWindMph)}) (${rule.codeRef}).`));
405
+ }
360
406
  const sdc = candidate.seismicDesignCategory;
361
407
  const isHighSeismic = sdc !== undefined && matchesAnyToken(sdc, params.highSeismicCategories);
362
408
  const isSillBoltSeismic = sdc !== undefined && matchesAnyToken(sdc, params.sillBoltSeismicCategories);
363
409
  const marginIn = clampNonNegativeMargin(rule.placementMarginM) / INCHES_TO_METERS2;
364
- if (candidate.hasRoofTie === false && (wind !== undefined && wind >= params.roofTieWindMph || isHighSeismic)) {
365
- violations.push(makeViolation(rule, candidate, `Roof-to-wall tie required at ${wind !== undefined ? `${round32(wind)} mph` : `SDC ${sdc}`} (${rule.codeRef}).`));
410
+ const roofTieByWind = wind !== undefined && wind >= params.roofTieWindMph;
411
+ if (candidate.hasRoofTie === false && (roofTieByWind || isHighSeismic)) {
412
+ violations.push(makeViolation(rule, candidate, `Roof-to-wall tie required at ${roofTieByWind ? `${round32(wind)} mph` : `SDC ${sdc}`} (${rule.codeRef}).`));
366
413
  }
367
- if (candidate.hasStrap === false && (wind !== undefined && wind >= params.strapWindMph || isHighSeismic)) {
368
- violations.push(makeViolation(rule, candidate, `Uplift strap required at ${wind !== undefined ? `${round32(wind)} mph` : `SDC ${sdc}`} (${rule.codeRef}).`));
414
+ const strapByWind = wind !== undefined && wind >= params.strapWindMph;
415
+ if (candidate.hasStrap === false && (strapByWind || isHighSeismic)) {
416
+ violations.push(makeViolation(rule, candidate, `Uplift strap required at ${strapByWind ? `${round32(wind)} mph` : `SDC ${sdc}`} (${rule.codeRef}).`));
369
417
  }
370
418
  if (candidate.hasHeavyStrap === false && wind !== undefined && wind >= params.heavyStrapWindMph) {
371
419
  violations.push(makeViolation(rule, candidate, `Heavy uplift strap required at ${round32(wind)} mph (>= ${round32(params.heavyStrapWindMph)} mph, ${rule.codeRef}).`));
372
420
  }
373
- if (candidate.hasHoldDown === false && (wind !== undefined && wind >= params.holdDownWindMph || isHighSeismic)) {
374
- violations.push(makeViolation(rule, candidate, `Hold-down connector required at ${wind !== undefined ? `${round32(wind)} mph` : `SDC ${sdc}`} (${rule.codeRef}).`));
421
+ const holdDownByWind = wind !== undefined && wind >= params.holdDownWindMph;
422
+ if (candidate.hasHoldDown === false && (holdDownByWind || isHighSeismic)) {
423
+ violations.push(makeViolation(rule, candidate, `Hold-down connector required at ${holdDownByWind ? `${round32(wind)} mph` : `SDC ${sdc}`} (${rule.codeRef}).`));
375
424
  }
376
425
  if (candidate.hasSillBolt === false && isSillBoltSeismic) {
377
426
  violations.push(makeViolation(rule, candidate, `Seismic sill anchor bolt required in SDC "${sdc}" (${rule.codeRef}).`));
378
427
  }
379
- if (candidate.footingWidthIn !== undefined && Number.isFinite(candidate.footingWidthIn)) {
428
+ if (candidate.footingWidthIn !== undefined) {
380
429
  const effMinFooting = resolveThreshold(params.minFootingWidthIn, marginIn, "min", mode);
381
- if (candidate.footingWidthIn < effMinFooting) {
382
- violations.push(makeViolation(rule, candidate, `Spread footing width ${round32(candidate.footingWidthIn)}" is below minimum ${round32(effMinFooting)}" (${rule.codeRef}).`));
430
+ if (!Number.isFinite(candidate.footingWidthIn) || candidate.footingWidthIn < effMinFooting) {
431
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.footingWidthIn) ? `Non-finite spread footing width (${String(candidate.footingWidthIn)}) (minimum ${round32(effMinFooting)}", ${rule.codeRef}).` : `Spread footing width ${round32(candidate.footingWidthIn)}" is below minimum ${round32(effMinFooting)}" (${rule.codeRef}).`));
383
432
  }
384
433
  }
385
- if (candidate.bearingIn !== undefined && Number.isFinite(candidate.bearingIn)) {
434
+ if (candidate.bearingIn !== undefined) {
386
435
  let effMinBearing;
387
436
  if (params.minBearingLengthIn !== undefined && Number.isFinite(params.minBearingLengthIn)) {
388
437
  const baseMinBearingIn = Math.max(0, params.minBearingLengthIn);
@@ -391,8 +440,8 @@ function evaluateWindSeismicThreshold(rule, candidate, mode) {
391
440
  } else {
392
441
  effMinBearing = resolveThreshold(params.minBearingToleranceIn, marginIn, "min", mode);
393
442
  }
394
- if (candidate.bearingIn < effMinBearing) {
395
- violations.push(makeViolation(rule, candidate, `Bearing length ${round32(candidate.bearingIn)}" is below minimum ${round32(effMinBearing)}" (${rule.codeRef}).`));
443
+ if (!Number.isFinite(candidate.bearingIn) || candidate.bearingIn < effMinBearing) {
444
+ violations.push(makeViolation(rule, candidate, !Number.isFinite(candidate.bearingIn) ? `Non-finite bearing length (${String(candidate.bearingIn)}) (minimum ${round32(effMinBearing)}", ${rule.codeRef}).` : `Bearing length ${round32(candidate.bearingIn)}" is below minimum ${round32(effMinBearing)}" (${rule.codeRef}).`));
396
445
  }
397
446
  }
398
447
  return violations;
@@ -460,9 +509,11 @@ function evaluateDeclarativeRules2(rules, candidates, opts) {
460
509
  }
461
510
  const errorCount = violations.filter((v) => v.severity === "error").length;
462
511
  const warningCount = violations.filter((v) => v.severity === "warning").length;
512
+ const infoCount = violations.length - errorCount - warningCount;
463
513
  const ok = errorCount === 0;
464
514
  const tool = opts.tool ?? "evaluate_declarative_rules";
465
- const summary = violations.length === 0 ? `${opts.trade} audit passed: 0 violations across ${candidates.length} candidate(s) (${activeRules.length} rule(s) evaluated).` : `${opts.trade} audit found ${violations.length} violation(s) (${errorCount} error(s), ${warningCount} warning(s)) across ${candidates.length} candidate(s) (${activeRules.length} rule(s) evaluated).`;
515
+ const infoPart = infoCount > 0 ? `, ${infoCount} info` : "";
516
+ const summary = violations.length === 0 ? `${opts.trade} audit passed: 0 violations across ${candidates.length} candidate(s) (${activeRules.length} rule(s) evaluated).` : `${opts.trade} audit found ${violations.length} violation(s) (${errorCount} error(s), ${warningCount} warning(s)${infoPart}) across ${candidates.length} candidate(s) (${activeRules.length} rule(s) evaluated).`;
466
517
  return {
467
518
  ok,
468
519
  tool,
@@ -481,12 +532,13 @@ function validateRuleTable2(rules) {
481
532
  for (let i = 0;i < rules.length; i++) {
482
533
  const rule = rules[i];
483
534
  const label = rule.id?.trim() ? `rule "${rule.id}" (index ${i})` : `rule at index ${i}`;
484
- if (typeof rule.id !== "string" || rule.id.trim().length === 0) {
535
+ const trimmedId = typeof rule.id === "string" ? rule.id.trim() : "";
536
+ if (trimmedId.length === 0) {
485
537
  errors.push(`${label}: id must be a non-empty string.`);
486
- } else if (seenIds.has(rule.id)) {
487
- errors.push(`${label}: duplicate rule id "${rule.id}".`);
538
+ } else if (seenIds.has(trimmedId)) {
539
+ errors.push(`${label}: duplicate rule id "${trimmedId}".`);
488
540
  } else {
489
- seenIds.add(rule.id);
541
+ seenIds.add(trimmedId);
490
542
  }
491
543
  if (typeof rule.codeRef !== "string" || rule.codeRef.trim().length === 0) {
492
544
  errors.push(`${label}: codeRef must be a non-empty string.`);