@kruschdev/pascal-plugin-plumbing 0.0.0-stage → 0.2.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.
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Layer 3 — Single-Source Declarative IPC / IRC / IFGC Code Rules (`src/ipc/rules.ts`).
3
+ *
4
+ * Encodes plumbing code thresholds ONCE as a validated `DeclarativeRule[]` table consumed by
5
+ * BOTH placement/routing generators (`autopopulate.ts`, `routing.ts`, `sizing.ts`) in `'placement'`
6
+ * mode and the post-hoc compliance auditor (`audit.ts`) in `'audit'` mode (`INV-MEP-08`).
7
+ *
8
+ * Framework-free: zero React, Three.js, `@pascal-app/*`, Next, Zod, or `node:*` imports.
9
+ */
10
+
11
+ import {
12
+ type CandidateEvaluationResult,
13
+ type DeclarativeRule,
14
+ type ElevationBandRule,
15
+ type MaterialPolicyRule,
16
+ type PlacementCandidate,
17
+ type RoutingConstraintRule,
18
+ type RuleEvaluationMode,
19
+ type WallCavityFitRule,
20
+ effectivePlacementThreshold,
21
+ evaluatePlacementCandidate,
22
+ validateRuleTable,
23
+ } from '@kruschdev/pascal-mep-kernel'
24
+
25
+ const IPC_704_1_DRAIN_SLOPE_SMALL_RULE: RoutingConstraintRule = {
26
+ id: 'ipc-704-1-drain-slope-small',
27
+ kind: 'routing-constraint',
28
+ trade: 'plumbing',
29
+ codeRef: 'IPC 704.1',
30
+ severity: 'error',
31
+ category: 'dwv-slope',
32
+ title: 'DWV drain (<= 2-1/2") slope below 1/4" per foot minimum',
33
+ suggestedFix: 'Increase downward pitch to at least 0.25"/ft (2.08%) per IPC Table 704.1.',
34
+ params: {
35
+ targetSystems: ['dwv-drain-small'],
36
+ minSlopeInPerFt: 0.25,
37
+ },
38
+ }
39
+
40
+ const IPC_704_1_DRAIN_SLOPE_LARGE_RULE: RoutingConstraintRule = {
41
+ id: 'ipc-704-1-drain-slope-large',
42
+ kind: 'routing-constraint',
43
+ trade: 'plumbing',
44
+ codeRef: 'IPC 704.1',
45
+ severity: 'error',
46
+ category: 'dwv-slope',
47
+ title: 'DWV drain (>= 3") slope below 1/8" per foot minimum',
48
+ suggestedFix: 'Increase downward pitch to at least 0.125"/ft (1.04%) per IPC Table 704.1.',
49
+ params: {
50
+ targetSystems: ['dwv-drain-large'],
51
+ minSlopeInPerFt: 0.125,
52
+ },
53
+ }
54
+
55
+ const IPC_905_5_DRY_VENT_HEIGHT_RULE: ElevationBandRule = {
56
+ id: 'ipc-905-5-dry-vent-height',
57
+ kind: 'elevation-band',
58
+ trade: 'plumbing',
59
+ codeRef: 'IPC 905.5',
60
+ severity: 'error',
61
+ category: 'dwv-vent',
62
+ title: 'Horizontal dry vent below 6" above fixture flood-level rim',
63
+ suggestedFix:
64
+ 'Rise vertically inside wet wall to at least 6" above fixture flood-level rim before turning horizontal.',
65
+ placementMarginM: 0.04,
66
+ params: {
67
+ targetKinds: ['dwv-vent', 'dwv-dry-vent'],
68
+ minAboveFloodRimM: 0.1524,
69
+ },
70
+ }
71
+
72
+ const IPC_903_1_MAIN_VENT_STACK_RULE: RoutingConstraintRule = {
73
+ id: 'ipc-903-1-main-vent-stack',
74
+ kind: 'routing-constraint',
75
+ trade: 'plumbing',
76
+ codeRef: 'IPC 903.1',
77
+ severity: 'error',
78
+ category: 'dwv-vent',
79
+ title: 'Main vent stack below 3" minimum diameter',
80
+ suggestedFix: 'Upsize the main vent stack through roof to at least 3" per IPC 903.1.',
81
+ params: {
82
+ targetSystems: ['dwv-main-vent-stack'],
83
+ minNominalSizeIn: 3,
84
+ },
85
+ }
86
+
87
+ const IPC_708_1_CLEANOUT_INTERVAL_RULE: RoutingConstraintRule = {
88
+ id: 'ipc-708-1-cleanout-interval',
89
+ kind: 'routing-constraint',
90
+ trade: 'plumbing',
91
+ codeRef: 'IPC 708.1',
92
+ severity: 'warning',
93
+ category: 'dwv-cleanout',
94
+ title: 'Building drain > 100 ft without intermediate cleanout',
95
+ suggestedFix: 'Add an accessible two-way cleanout at <= 100 ft intervals.',
96
+ params: {
97
+ targetSystems: ['dwv-drain', 'dwv-drain-small', 'dwv-drain-large'],
98
+ maxLengthFtWithoutCleanout: 100,
99
+ },
100
+ }
101
+
102
+ const IRC_R602_6_WET_WALL_FIT_RULE: WallCavityFitRule = {
103
+ id: 'irc-r602-6-wet-wall-fit',
104
+ kind: 'wall-cavity-fit',
105
+ trade: 'plumbing',
106
+ codeRef: 'IRC R602.6 / Wet Wall',
107
+ severity: 'error',
108
+ category: 'wet-wall',
109
+ title: 'Wet wall too thin for >= 3" DWV pipe',
110
+ suggestedFix: 'Upgrade this wet wall to 2x6 framing (>= 0.15 m thick) or add a dedicated pipe chase.',
111
+ placementMarginM: 0.005,
112
+ params: {
113
+ minPipeNominalIn: 3,
114
+ minWallThicknessM: 0.14,
115
+ max2x4WallThicknessM: 0.125,
116
+ },
117
+ }
118
+
119
+ const IRC_M1502_4_DRYER_VENT_RULE: RoutingConstraintRule = {
120
+ id: 'irc-m1502-4-dryer-vent',
121
+ kind: 'routing-constraint',
122
+ trade: 'plumbing',
123
+ codeRef: 'IRC M1502.4.5.1',
124
+ severity: 'error',
125
+ category: 'dryer-vent',
126
+ title: 'Dryer vent effective length exceeds 35 ft max',
127
+ suggestedFix:
128
+ 'Shorten exhaust run, eliminate unnecessary 90° elbows, or add a listed dryer exhaust booster fan.',
129
+ params: {
130
+ targetSystems: ['dryer-vent'],
131
+ maxEffectiveLengthFt: 35,
132
+ },
133
+ }
134
+
135
+ const IRC_M1502_4_1_DRYER_VENT_MATERIAL_RULE: MaterialPolicyRule = {
136
+ id: 'irc-m1502-4-1-dryer-vent-material',
137
+ kind: 'material-policy',
138
+ trade: 'plumbing',
139
+ codeRef: 'IRC M1502.4.1',
140
+ severity: 'error',
141
+ category: 'dryer-vent',
142
+ title: 'Dryer exhaust duct must be smooth rigid metal',
143
+ suggestedFix: 'Switch dryer vent material to 4" rigid-aluminum (never vinyl or foil flex).',
144
+ params: {
145
+ targetSystems: ['dryer-vent'],
146
+ requiredMaterials: ['rigid-aluminum'],
147
+ },
148
+ }
149
+
150
+ const IFGC_402_4_FUEL_GAS_MAX_LEN_RULE: RoutingConstraintRule = {
151
+ id: 'ifgc-402-4-fuel-gas-max-len',
152
+ kind: 'routing-constraint',
153
+ trade: 'plumbing',
154
+ codeRef: 'IFGC 402.4',
155
+ severity: 'error',
156
+ category: 'fuel-gas',
157
+ title: 'Fuel gas run exceeds 200 ft IFGC table limit',
158
+ suggestedFix:
159
+ 'Shorten gas piping run, switch to higher-capacity material/size, or design a 2 psi system with line regulators per IFGC 402.4.',
160
+ params: {
161
+ targetSystems: ['fuel-gas'],
162
+ maxEffectiveLengthFt: 200,
163
+ },
164
+ }
165
+
166
+ /**
167
+ * Authoritative single-source IPC / IRC / IFGC declarative code rule table (`INV-MEP-08`).
168
+ */
169
+ export const IPC_DECLARATIVE_RULES: readonly DeclarativeRule[] = Object.freeze([
170
+ IPC_704_1_DRAIN_SLOPE_SMALL_RULE,
171
+ IPC_704_1_DRAIN_SLOPE_LARGE_RULE,
172
+ IPC_905_5_DRY_VENT_HEIGHT_RULE,
173
+ IPC_903_1_MAIN_VENT_STACK_RULE,
174
+ IPC_708_1_CLEANOUT_INTERVAL_RULE,
175
+ IRC_R602_6_WET_WALL_FIT_RULE,
176
+ IRC_M1502_4_DRYER_VENT_RULE,
177
+ IRC_M1502_4_1_DRYER_VENT_MATERIAL_RULE,
178
+ IFGC_402_4_FUEL_GAS_MAX_LEN_RULE,
179
+ ])
180
+
181
+ const ruleValidation = validateRuleTable(IPC_DECLARATIVE_RULES)
182
+ if (!ruleValidation.valid) {
183
+ throw new Error(`Invalid IPC_DECLARATIVE_RULES table: ${ruleValidation.errors.join('; ')}`)
184
+ }
185
+
186
+ export type IpcRuleId =
187
+ | 'ipc-704-1-drain-slope-small'
188
+ | 'ipc-704-1-drain-slope-large'
189
+ | 'ipc-905-5-dry-vent-height'
190
+ | 'ipc-903-1-main-vent-stack'
191
+ | 'ipc-708-1-cleanout-interval'
192
+ | 'irc-r602-6-wet-wall-fit'
193
+ | 'irc-m1502-4-dryer-vent'
194
+ | 'irc-m1502-4-1-dryer-vent-material'
195
+ | 'ifgc-402-4-fuel-gas-max-len'
196
+
197
+ export type IpcRuleByIdMap = {
198
+ readonly 'ipc-704-1-drain-slope-small': RoutingConstraintRule
199
+ readonly 'ipc-704-1-drain-slope-large': RoutingConstraintRule
200
+ readonly 'ipc-905-5-dry-vent-height': ElevationBandRule
201
+ readonly 'ipc-903-1-main-vent-stack': RoutingConstraintRule
202
+ readonly 'ipc-708-1-cleanout-interval': RoutingConstraintRule
203
+ readonly 'irc-r602-6-wet-wall-fit': WallCavityFitRule
204
+ readonly 'irc-m1502-4-dryer-vent': RoutingConstraintRule
205
+ readonly 'irc-m1502-4-1-dryer-vent-material': MaterialPolicyRule
206
+ readonly 'ifgc-402-4-fuel-gas-max-len': RoutingConstraintRule
207
+ }
208
+
209
+ const IPC_RULES_BY_ID: IpcRuleByIdMap = {
210
+ 'ipc-704-1-drain-slope-small': IPC_704_1_DRAIN_SLOPE_SMALL_RULE,
211
+ 'ipc-704-1-drain-slope-large': IPC_704_1_DRAIN_SLOPE_LARGE_RULE,
212
+ 'ipc-905-5-dry-vent-height': IPC_905_5_DRY_VENT_HEIGHT_RULE,
213
+ 'ipc-903-1-main-vent-stack': IPC_903_1_MAIN_VENT_STACK_RULE,
214
+ 'ipc-708-1-cleanout-interval': IPC_708_1_CLEANOUT_INTERVAL_RULE,
215
+ 'irc-r602-6-wet-wall-fit': IRC_R602_6_WET_WALL_FIT_RULE,
216
+ 'irc-m1502-4-dryer-vent': IRC_M1502_4_DRYER_VENT_RULE,
217
+ 'irc-m1502-4-1-dryer-vent-material': IRC_M1502_4_1_DRYER_VENT_MATERIAL_RULE,
218
+ 'ifgc-402-4-fuel-gas-max-len': IFGC_402_4_FUEL_GAS_MAX_LEN_RULE,
219
+ }
220
+
221
+ /**
222
+ * Retrieve a strongly-typed declarative IPC/IRC/IFGC rule by canonical `IpcRuleId`.
223
+ */
224
+ export function getIpcRuleById<K extends IpcRuleId>(id: K): IpcRuleByIdMap[K] {
225
+ return IPC_RULES_BY_ID[id]
226
+ }
227
+
228
+ /**
229
+ * Authoritative single-source numeric thresholds derived directly from `IPC_DECLARATIVE_RULES`.
230
+ * Zero duplicated magic numbers between generators (`'placement'`) and auditors (`'audit'`).
231
+ */
232
+ export const IPC_RULE_THRESHOLDS = Object.freeze({
233
+ drainSlopeSmallInPerFt: IPC_704_1_DRAIN_SLOPE_SMALL_RULE.params.minSlopeInPerFt as 0.25,
234
+ drainSlopeLargeInPerFt: IPC_704_1_DRAIN_SLOPE_LARGE_RULE.params.minSlopeInPerFt as 0.125,
235
+ ventMinAboveFloodRimM: IPC_905_5_DRY_VENT_HEIGHT_RULE.params.minAboveFloodRimM!,
236
+ ventPlacementMarginM: IPC_905_5_DRY_VENT_HEIGHT_RULE.placementMarginM!,
237
+ ventPlacementMinAboveFloodRimM: effectivePlacementThreshold(
238
+ IPC_905_5_DRY_VENT_HEIGHT_RULE.params.minAboveFloodRimM!,
239
+ IPC_905_5_DRY_VENT_HEIGHT_RULE.placementMarginM,
240
+ 'min',
241
+ ),
242
+ mainVentStackMinNominalIn: IPC_903_1_MAIN_VENT_STACK_RULE.params.minNominalSizeIn!,
243
+ cleanoutMaxIntervalFt: IPC_708_1_CLEANOUT_INTERVAL_RULE.params.maxLengthFtWithoutCleanout!,
244
+ wetWallMinPipeNominalIn: IRC_R602_6_WET_WALL_FIT_RULE.params.minPipeNominalIn,
245
+ wetWallMinThicknessM: IRC_R602_6_WET_WALL_FIT_RULE.params.minWallThicknessM,
246
+ wetWallPlacementMinThicknessM: effectivePlacementThreshold(
247
+ IRC_R602_6_WET_WALL_FIT_RULE.params.minWallThicknessM,
248
+ IRC_R602_6_WET_WALL_FIT_RULE.placementMarginM,
249
+ 'min',
250
+ ),
251
+ wetWallMax2x4ThicknessM: IRC_R602_6_WET_WALL_FIT_RULE.params.max2x4WallThicknessM,
252
+ dryerVentMaxEffectiveLengthFt: IRC_M1502_4_DRYER_VENT_RULE.params.maxEffectiveLengthFt!,
253
+ dryerVentRequiredMaterials: IRC_M1502_4_1_DRYER_VENT_MATERIAL_RULE.params.requiredMaterials!,
254
+ fuelGasMaxEffectiveLengthFt: IFGC_402_4_FUEL_GAS_MAX_LEN_RULE.params.maxEffectiveLengthFt!,
255
+ /** Unified IFGC 402.4 minimum sizing table row: 10 ft statutory audit floor, 15 ft conservative placement floor (>= audit). */
256
+ fuelGasMinSizingLengthAuditFt: 10,
257
+ fuelGasMinSizingLengthPlacementFt: 15,
258
+ })
259
+
260
+ /**
261
+ * Evaluate a plumbing candidate against `IPC_DECLARATIVE_RULES` (or a targeted subset)
262
+ * in either `'placement'` (conservative) or `'audit'` (exact statutory) mode.
263
+ */
264
+ export function evaluateIpcRuleCandidate(
265
+ candidate: PlacementCandidate,
266
+ mode: RuleEvaluationMode = 'placement',
267
+ ruleIds?: readonly IpcRuleId[],
268
+ ): CandidateEvaluationResult {
269
+ const rules = ruleIds ? ruleIds.map((id) => IPC_RULES_BY_ID[id]) : IPC_DECLARATIVE_RULES
270
+ return evaluatePlacementCandidate(rules, candidate, mode)
271
+ }