@kruschdev/pascal-mep-kernel 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Layer 3 — Single-Source Declarative Building/MEP Code Rule Schema (`@kruschdev/pascal-mep-kernel/rules`).
3
+ *
4
+ * Enforces `INV-MEP-01` (pure zero-dependency TypeScript) and `INV-MEP-08` (single-source
5
+ * rule tables consumed by both placement/routing generators and post-hoc code auditors, with
6
+ * non-negative `placementMarginM >= 0` so placement is never looser than audit).
7
+ */
8
+ import type { TradeId, Vec3 } from '../types';
9
+ export type RuleSeverity = 'error' | 'warning' | 'info';
10
+ export type RuleEvaluationMode = 'placement' | 'audit';
11
+ export type DeclarativeRuleKind = 'prohibited-zone' | 'fixture-keepout' | 'opening-keepout' | 'elevation-band' | 'working-space' | 'material-policy' | 'routing-constraint' | 'wall-cavity-fit' | 'wind-seismic-threshold';
12
+ export type DeclarativeRuleBase = {
13
+ readonly id: string;
14
+ readonly trade: TradeId;
15
+ readonly codeRef: string;
16
+ readonly severity: RuleSeverity;
17
+ readonly category: string;
18
+ readonly title: string;
19
+ readonly suggestedFix: string;
20
+ /**
21
+ * Optional non-negative cushion (meters) applied ONLY during `'placement'` mode so
22
+ * generated placements are strictly at least as conservative as `'audit'` thresholds.
23
+ * Clamped `>= 0` via `effectivePlacementThreshold` (`INV-MEP-08`).
24
+ */
25
+ readonly placementMarginM?: number;
26
+ };
27
+ export type ProhibitedZoneParams = {
28
+ readonly targetKinds: readonly string[];
29
+ readonly prohibitedRoomCategories: readonly string[];
30
+ readonly forbiddenNemaOutdoors?: readonly string[];
31
+ readonly requireBelowCeilingForAttic?: boolean;
32
+ };
33
+ export type ProhibitedZoneRule = DeclarativeRuleBase & {
34
+ readonly kind: 'prohibited-zone';
35
+ readonly params: ProhibitedZoneParams;
36
+ };
37
+ export type FixtureKeepoutParams = {
38
+ readonly targetRoles: readonly string[];
39
+ readonly fixtureKinds: readonly string[];
40
+ readonly minHorizontalM: number;
41
+ readonly maxVerticalM?: number;
42
+ readonly minVerticalM?: number;
43
+ readonly verticalBandM?: readonly [number, number];
44
+ readonly respectWallSeparation?: boolean;
45
+ };
46
+ export type FixtureKeepoutRule = DeclarativeRuleBase & {
47
+ readonly kind: 'fixture-keepout';
48
+ readonly params: FixtureKeepoutParams;
49
+ };
50
+ export type OpeningKeepoutParams = {
51
+ readonly targetRoles: readonly string[];
52
+ readonly blockDoors: boolean;
53
+ readonly blockWindows: boolean;
54
+ readonly floorToCeilingSillThresholdM?: number;
55
+ readonly trimClearanceM: number;
56
+ };
57
+ export type OpeningKeepoutRule = DeclarativeRuleBase & {
58
+ readonly kind: 'opening-keepout';
59
+ readonly params: OpeningKeepoutParams;
60
+ };
61
+ export type ElevationBandParams = {
62
+ readonly targetKinds: readonly string[];
63
+ readonly minYM?: number;
64
+ readonly maxYM?: number;
65
+ readonly minAboveFloodRimM?: number;
66
+ readonly maxHandleHeightM?: number;
67
+ readonly roofMarginM?: number;
68
+ readonly atticThresholdOffsetM?: number;
69
+ };
70
+ export type ElevationBandRule = DeclarativeRuleBase & {
71
+ readonly kind: 'elevation-band';
72
+ readonly params: ElevationBandParams;
73
+ };
74
+ export type WorkingSpaceParams = {
75
+ readonly targetKinds: readonly string[];
76
+ readonly widthM: number;
77
+ readonly depthM: number;
78
+ readonly heightM: number;
79
+ readonly dedicatedOverheadHeightM?: number;
80
+ };
81
+ export type WorkingSpaceRule = DeclarativeRuleBase & {
82
+ readonly kind: 'working-space';
83
+ readonly params: WorkingSpaceParams;
84
+ };
85
+ export type MaterialPolicyParams = {
86
+ readonly targetSystems: readonly string[];
87
+ readonly forbiddenMaterials?: readonly string[];
88
+ readonly requiredMaterials?: readonly string[];
89
+ readonly forbiddenInCommercial?: boolean;
90
+ readonly forbiddenInPlenum?: boolean;
91
+ readonly forbiddenInWetCrawlspace?: boolean;
92
+ };
93
+ export type MaterialPolicyRule = DeclarativeRuleBase & {
94
+ readonly kind: 'material-policy';
95
+ readonly params: MaterialPolicyParams;
96
+ };
97
+ export type RoutingConstraintParams = {
98
+ readonly targetSystems: readonly string[];
99
+ readonly maxBendDegrees?: number;
100
+ readonly minSlopeInPerFt?: number;
101
+ /**
102
+ * Optional non-negative slope cushion (in/ft) applied ONLY during `'placement'` mode so
103
+ * generated runs enforce `slopeInPerFt >= minSlopeInPerFt + placementSlopeMarginInPerFt`
104
+ * in honest `in/ft` units (`INV-MEP-08`).
105
+ */
106
+ readonly placementSlopeMarginInPerFt?: number;
107
+ readonly maxEffectiveLengthFt?: number;
108
+ readonly maxLengthFtWithoutCleanout?: number;
109
+ readonly minNominalSizeIn?: number;
110
+ };
111
+ export type RoutingConstraintRule = DeclarativeRuleBase & {
112
+ readonly kind: 'routing-constraint';
113
+ readonly params: RoutingConstraintParams;
114
+ };
115
+ export type WallCavityFitParams = {
116
+ readonly minPipeNominalIn: number;
117
+ readonly minWallThicknessM: number;
118
+ readonly max2x4WallThicknessM: number;
119
+ };
120
+ export type WallCavityFitRule = DeclarativeRuleBase & {
121
+ readonly kind: 'wall-cavity-fit';
122
+ readonly params: WallCavityFitParams;
123
+ };
124
+ export type WindSeismicThresholdParams = {
125
+ readonly roofTieWindMph: number;
126
+ readonly strapWindMph: number;
127
+ readonly heavyStrapWindMph: number;
128
+ readonly holdDownWindMph: number;
129
+ readonly highSeismicCategories: readonly string[];
130
+ readonly sillBoltSeismicCategories: readonly string[];
131
+ readonly minFootingWidthIn: number;
132
+ readonly minBearingToleranceIn: number;
133
+ /**
134
+ * Optional statutory minimum bearing length in inches (e.g., `1.5` per IRC R502.6).
135
+ * When set, `'audit'` mode allows `Math.max(0, minBearingLengthIn - minBearingToleranceIn)`
136
+ * while `'placement'` mode requires `minBearingLengthIn + marginIn` (`INV-MEP-08`).
137
+ */
138
+ readonly minBearingLengthIn?: number;
139
+ };
140
+ export type WindSeismicThresholdRule = DeclarativeRuleBase & {
141
+ readonly kind: 'wind-seismic-threshold';
142
+ readonly params: WindSeismicThresholdParams;
143
+ };
144
+ export type DeclarativeRule = ProhibitedZoneRule | FixtureKeepoutRule | OpeningKeepoutRule | ElevationBandRule | WorkingSpaceRule | MaterialPolicyRule | RoutingConstraintRule | WallCavityFitRule | WindSeismicThresholdRule;
145
+ export type DeclarativeRuleByKind<K extends DeclarativeRuleKind> = Extract<DeclarativeRule, {
146
+ readonly kind: K;
147
+ }>;
148
+ export type NearFixtureMeasurement = {
149
+ readonly kind: string;
150
+ readonly horizontalDistM: number;
151
+ readonly separatedByWall?: boolean;
152
+ };
153
+ export type PlacementCandidate = {
154
+ readonly id?: string;
155
+ readonly kind: string;
156
+ readonly role?: string;
157
+ readonly pos: Vec3;
158
+ readonly roomCategory?: string;
159
+ readonly wallThicknessM?: number;
160
+ readonly nominalSizeIn?: number;
161
+ readonly material?: string;
162
+ readonly system?: string;
163
+ readonly nemaRating?: string;
164
+ readonly floodRimM?: number;
165
+ readonly bendDegrees?: number;
166
+ readonly slopeInPerFt?: number;
167
+ readonly effectiveLengthFt?: number;
168
+ readonly occupancy?: 'residential' | 'commercial';
169
+ readonly inPlenum?: boolean;
170
+ readonly inWetCrawlspace?: boolean;
171
+ readonly openingSillYM?: number;
172
+ readonly openingHeadYM?: number;
173
+ readonly openingKind?: 'door' | 'window';
174
+ readonly nearFixtures?: readonly NearFixtureMeasurement[];
175
+ readonly wallSeparated?: boolean;
176
+ readonly isOutdoors?: boolean;
177
+ readonly ceilingHeightM?: number;
178
+ readonly roofSurfaceYM?: number;
179
+ readonly handleHeightM?: number;
180
+ readonly openingHorizontalDistM?: number;
181
+ readonly workingSpaceWidthM?: number;
182
+ readonly workingSpaceDepthM?: number;
183
+ readonly workingSpaceHeightM?: number;
184
+ readonly dedicatedOverheadClearHeightM?: number;
185
+ readonly hasCleanout?: boolean;
186
+ readonly runLengthFt?: number;
187
+ readonly designWindMph?: number;
188
+ readonly seismicDesignCategory?: string;
189
+ readonly hasRoofTie?: boolean;
190
+ readonly hasStrap?: boolean;
191
+ readonly hasHeavyStrap?: boolean;
192
+ readonly hasHoldDown?: boolean;
193
+ readonly hasSillBolt?: boolean;
194
+ readonly footingWidthIn?: number;
195
+ readonly bearingIn?: number;
196
+ };
197
+ export type RuleViolation = {
198
+ readonly ruleId: string;
199
+ readonly codeRef: string;
200
+ readonly severity: RuleSeverity;
201
+ readonly category: string;
202
+ readonly title: string;
203
+ readonly message: string;
204
+ readonly suggestedFix: string;
205
+ readonly nodeIds: readonly string[];
206
+ };
207
+ export type CandidateEvaluationResult = {
208
+ readonly legal: boolean;
209
+ readonly violations: readonly RuleViolation[];
210
+ };
211
+ /** Backwards-compatible alias for `CandidateEvaluationResult` (`CON-K23-03`). */
212
+ export type CandidateCheckResult = CandidateEvaluationResult;
213
+ export type RuleEvaluationSummary = {
214
+ readonly ok: boolean;
215
+ readonly tool: string;
216
+ readonly summary: string;
217
+ readonly data: {
218
+ readonly trade: TradeId;
219
+ readonly rulesEvaluated: number;
220
+ readonly violationCount: number;
221
+ readonly violations: readonly RuleViolation[];
222
+ };
223
+ };
224
+ export type RuleTableValidationResult = {
225
+ readonly valid: boolean;
226
+ readonly errors: string[];
227
+ };
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Canonical zero-dependency types & unit helpers for `@kruschdev/pascal-mep-kernel`.
3
+ * Shared across Structural (IRC), Plumbing (IPC), HVAC (IMC), and Electrical (NEC) Pascal plugins.
4
+ */
5
+ export type Vec2 = readonly [number, number];
6
+ export type Vec3 = readonly [number, number, number];
7
+ export type TradeId = 'structural' | 'plumbing' | 'hvac' | 'electrical';
8
+ export type TradePriorityRank = 1 | 2 | 3 | 4;
9
+ export declare const TRADE_PRIORITY_RANK: Readonly<Record<TradeId, TradePriorityRank>>;
10
+ export declare const INCHES_TO_METERS = 0.0254;
11
+ export declare const METERS_TO_FEET = 3.280839895013123;
12
+ export declare const FEET_TO_METERS = 0.3048;
13
+ export declare const SQM_TO_SQFT = 10.763910416709722;
14
+ /**
15
+ * Superset Pascal scene-graph node interface accepted by all 4 trade plugins.
16
+ */
17
+ export type SceneNodeLike = {
18
+ readonly id: string;
19
+ readonly type: string;
20
+ readonly parentId?: string | null;
21
+ readonly name?: string;
22
+ readonly visible?: boolean;
23
+ readonly position?: readonly number[] | Vec3;
24
+ readonly rotation?: number | readonly number[] | Vec3;
25
+ readonly scale?: readonly number[] | Vec3;
26
+ readonly start?: readonly number[] | Vec2 | Vec3;
27
+ readonly end?: readonly number[] | Vec2 | Vec3;
28
+ readonly height?: number;
29
+ readonly thickness?: number;
30
+ readonly width?: number;
31
+ readonly depth?: number;
32
+ readonly length?: number;
33
+ readonly elevation?: number;
34
+ readonly baseElevation?: number;
35
+ readonly elevationY?: number;
36
+ readonly level?: number;
37
+ readonly index?: number;
38
+ readonly pitch?: number;
39
+ readonly roofType?: string;
40
+ readonly wallHeight?: number;
41
+ readonly polygon?: ReadonlyArray<Vec2>;
42
+ readonly holes?: ReadonlyArray<ReadonlyArray<Vec2>>;
43
+ readonly path?: ReadonlyArray<Vec3>;
44
+ readonly children?: readonly string[];
45
+ readonly category?: string;
46
+ readonly roomCategory?: string;
47
+ readonly wallId?: string;
48
+ readonly offset?: number;
49
+ readonly asset?: {
50
+ readonly id?: string;
51
+ readonly name?: string;
52
+ readonly category?: string;
53
+ readonly dimensions?: readonly number[];
54
+ readonly offset?: readonly number[];
55
+ };
56
+ readonly [key: string]: unknown;
57
+ };
58
+ /**
59
+ * Flat canonical 3D axis-aligned bounding box (matches HVAC & Plumbing directly;
60
+ * use `toTupleAabb3` / `fromTupleAabb3` for Electrical's `{ min: Vec3, max: Vec3 }` contract).
61
+ */
62
+ export type Aabb3 = {
63
+ readonly minX: number;
64
+ readonly minY: number;
65
+ readonly minZ: number;
66
+ readonly maxX: number;
67
+ readonly maxY: number;
68
+ readonly maxZ: number;
69
+ };
70
+ /** Tuple-based AABB used by `pascal-plugin-electrical`'s public API. */
71
+ export type TupleAabb3 = {
72
+ readonly min: Vec3;
73
+ readonly max: Vec3;
74
+ };
75
+ /** 2D XZ bounding box. */
76
+ export type XzBounds2D = {
77
+ readonly minX: number;
78
+ readonly maxX: number;
79
+ readonly minZ: number;
80
+ readonly maxZ: number;
81
+ };
82
+ /**
83
+ * Y-axis-aligned oriented 3D prism (2D rotated rectangle in XZ extruded along [yMin, yMax]),
84
+ * paired with its world-space AABB for O(1) broad-phase culling.
85
+ */
86
+ export type OrientedPrismY = {
87
+ readonly centerX: number;
88
+ readonly centerZ: number;
89
+ readonly cos: number;
90
+ readonly sin: number;
91
+ readonly lxMin: number;
92
+ readonly lxMax: number;
93
+ readonly lzMin: number;
94
+ readonly lzMax: number;
95
+ readonly yMin: number;
96
+ readonly yMax: number;
97
+ readonly aabb: Aabb3;
98
+ };
99
+ export declare function isVec3(v: unknown): v is Vec3;
100
+ export declare function toTupleAabb3(box: Aabb3): TupleAabb3;
101
+ export declare function fromTupleAabb3(box: TupleAabb3): Aabb3;
102
+ export declare function expandAabb3(box: Aabb3, margin: number | Vec3): Aabb3;
103
+ export declare function aabb3Intersects(a: Aabb3, b: Aabb3): boolean;
104
+ /**
105
+ * Exact Kay-Kajiya 3D segment-vs-AABB intersection test with optional scalar or
106
+ * anisotropic `[mx, my, mz]` margin and endpoint tolerance `eps`.
107
+ */
108
+ export declare function segmentIntersectsAabb3(a: Vec3, b: Vec3, box: Aabb3, margin?: number | Vec3, eps?: number): boolean;
109
+ /** Build an `OrientedPrismY` with precomputed world-space AABB. */
110
+ export declare function createOrientedPrismY(params: {
111
+ centerX: number;
112
+ centerZ: number;
113
+ cos: number;
114
+ sin: number;
115
+ lxMin: number;
116
+ lxMax: number;
117
+ lzMin: number;
118
+ lzMax: number;
119
+ yMin: number;
120
+ yMax: number;
121
+ }): OrientedPrismY;
122
+ /** Exact 3D segment vs Y-oriented prism intersection (local slab test + AABB broadphase). */
123
+ export declare function segmentIntersectsOrientedPrismY(a: Vec3, b: Vec3, prism: OrientedPrismY, padM?: number | Vec3, eps?: number): boolean;
124
+ /** Exact 2D SAT in XZ + Y-overlap test between a Y-oriented prism and a world AABB. */
125
+ export declare function orientedPrismIntersectsAabb3(prism: OrientedPrismY, box: Aabb3): boolean;
126
+ /** Extract scalar yaw angle (radians) from either a numeric or 3-tuple Euler rotation field. */
127
+ export declare function extractNodeYawRad(rotation: unknown): number;
128
+ export declare function polylineLengthM(path: ReadonlyArray<Vec3>): number;
129
+ export declare function polylineHorizontalLengthM(path: ReadonlyArray<Vec3>): number;
130
+ export declare function countPathBendDegrees(path: ReadonlyArray<Vec3>): number;
131
+ export declare function countPathElbows(path: ReadonlyArray<Vec3>): {
132
+ elbows90: number;
133
+ elbows45: number;
134
+ };
135
+ export declare function round2(n: number): number;
136
+ export declare function round3(n: number): number;
137
+ export declare function round4(n: number): number;
package/dist/types.js ADDED
@@ -0,0 +1,48 @@
1
+ import {
2
+ TRADE_PRIORITY_RANK2,
3
+ INCHES_TO_METERS2,
4
+ METERS_TO_FEET2,
5
+ FEET_TO_METERS2,
6
+ SQM_TO_SQFT2,
7
+ isVec32,
8
+ toTupleAabb32,
9
+ fromTupleAabb32,
10
+ expandAabb32,
11
+ aabb3Intersects2,
12
+ segmentIntersectsAabb32,
13
+ createOrientedPrismY2,
14
+ segmentIntersectsOrientedPrismY2,
15
+ orientedPrismIntersectsAabb32,
16
+ extractNodeYawRad2,
17
+ polylineLengthM2,
18
+ polylineHorizontalLengthM2,
19
+ countPathBendDegrees2,
20
+ countPathElbows2,
21
+ round22,
22
+ round32,
23
+ round42
24
+ } from "./chunk-jfzqztgh.js";
25
+ export {
26
+ FEET_TO_METERS2 as FEET_TO_METERS,
27
+ INCHES_TO_METERS2 as INCHES_TO_METERS,
28
+ METERS_TO_FEET2 as METERS_TO_FEET,
29
+ SQM_TO_SQFT2 as SQM_TO_SQFT,
30
+ TRADE_PRIORITY_RANK2 as TRADE_PRIORITY_RANK,
31
+ aabb3Intersects2 as aabb3Intersects,
32
+ countPathBendDegrees2 as countPathBendDegrees,
33
+ countPathElbows2 as countPathElbows,
34
+ createOrientedPrismY2 as createOrientedPrismY,
35
+ expandAabb32 as expandAabb3,
36
+ extractNodeYawRad2 as extractNodeYawRad,
37
+ fromTupleAabb32 as fromTupleAabb3,
38
+ isVec32 as isVec3,
39
+ orientedPrismIntersectsAabb32 as orientedPrismIntersectsAabb3,
40
+ polylineHorizontalLengthM2 as polylineHorizontalLengthM,
41
+ polylineLengthM2 as polylineLengthM,
42
+ round22 as round2,
43
+ round32 as round3,
44
+ round42 as round4,
45
+ segmentIntersectsAabb32 as segmentIntersectsAabb3,
46
+ segmentIntersectsOrientedPrismY2 as segmentIntersectsOrientedPrismY,
47
+ toTupleAabb32 as toTupleAabb3
48
+ };
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@kruschdev/pascal-mep-kernel",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Shared zero-dependency 3-layer spatial anatomy, legal-cavity MEP routing graph, and single-source declarative code constraint engine for Pascal Editor plugins.",
5
+ "author": "Kevin Ruschman <kruschdev@users.noreply.github.com>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/kruschdev/pascal-mep-kernel.git"
10
+ },
11
+ "homepage": "https://github.com/kruschdev/pascal-mep-kernel",
12
+ "bugs": {
13
+ "url": "https://github.com/kruschdev/pascal-mep-kernel/issues"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "./types": {
26
+ "types": "./dist/types.d.ts",
27
+ "import": "./dist/types.js",
28
+ "default": "./dist/types.js"
29
+ },
30
+ "./anatomy": {
31
+ "types": "./dist/anatomy/index.d.ts",
32
+ "import": "./dist/anatomy/index.js",
33
+ "default": "./dist/anatomy/index.js"
34
+ },
35
+ "./router": {
36
+ "types": "./dist/router/index.d.ts",
37
+ "import": "./dist/router/index.js",
38
+ "default": "./dist/router/index.js"
39
+ },
40
+ "./rules": {
41
+ "types": "./dist/rules/index.d.ts",
42
+ "import": "./dist/rules/index.js",
43
+ "default": "./dist/rules/index.js"
44
+ },
45
+ "./package.json": "./package.json"
46
+ },
47
+ "files": [
48
+ "dist",
49
+ "README.md",
50
+ "LICENSE"
51
+ ],
52
+ "scripts": {
53
+ "build": "bun scripts/build-dist.ts",
54
+ "check-types": "tsc --noEmit",
55
+ "test": "bun test src",
56
+ "check:purity": "bun scripts/check-purity.ts",
57
+ "check": "bun run check-types && bun run test && bun run check:purity && bun run build"
58
+ },
59
+ "devDependencies": {
60
+ "@types/bun": "^1.3.5",
61
+ "typescript": "^5.9.3"
62
+ },
63
+ "keywords": [
64
+ "pascal",
65
+ "mep",
66
+ "bim",
67
+ "aeco",
68
+ "nec",
69
+ "ipc",
70
+ "imc",
71
+ "irc",
72
+ "spatial-kernel",
73
+ "routing"
74
+ ]
75
+ }