@orcalang/orca-lang 0.1.18 → 0.1.19

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.
Files changed (45) hide show
  1. package/dist/compiler/dt-compiler.d.ts +23 -0
  2. package/dist/compiler/dt-compiler.d.ts.map +1 -0
  3. package/dist/compiler/dt-compiler.js +183 -0
  4. package/dist/compiler/dt-compiler.js.map +1 -0
  5. package/dist/health-check.d.ts +3 -0
  6. package/dist/health-check.d.ts.map +1 -0
  7. package/dist/health-check.js +235 -0
  8. package/dist/health-check.js.map +1 -0
  9. package/dist/parser/ast.d.ts +2 -0
  10. package/dist/parser/ast.d.ts.map +1 -1
  11. package/dist/parser/dt-ast.d.ts +43 -0
  12. package/dist/parser/dt-ast.d.ts.map +1 -0
  13. package/dist/parser/dt-ast.js +3 -0
  14. package/dist/parser/dt-ast.js.map +1 -0
  15. package/dist/parser/dt-parser.d.ts +40 -0
  16. package/dist/parser/dt-parser.d.ts.map +1 -0
  17. package/dist/parser/dt-parser.js +240 -0
  18. package/dist/parser/dt-parser.js.map +1 -0
  19. package/dist/parser/markdown-parser.d.ts.map +1 -1
  20. package/dist/parser/markdown-parser.js +29 -4
  21. package/dist/parser/markdown-parser.js.map +1 -1
  22. package/dist/skills.d.ts +49 -1
  23. package/dist/skills.d.ts.map +1 -1
  24. package/dist/skills.js +223 -0
  25. package/dist/skills.js.map +1 -1
  26. package/dist/tools.d.ts.map +1 -1
  27. package/dist/tools.js +49 -0
  28. package/dist/tools.js.map +1 -1
  29. package/dist/verifier/dt-verifier.d.ts +5 -0
  30. package/dist/verifier/dt-verifier.d.ts.map +1 -0
  31. package/dist/verifier/dt-verifier.js +499 -0
  32. package/dist/verifier/dt-verifier.js.map +1 -0
  33. package/dist/verifier/types.d.ts +4 -0
  34. package/dist/verifier/types.d.ts.map +1 -1
  35. package/package.json +3 -2
  36. package/src/compiler/dt-compiler.ts +232 -0
  37. package/src/health-check.ts +273 -0
  38. package/src/parser/ast.ts +3 -0
  39. package/src/parser/dt-ast.ts +40 -0
  40. package/src/parser/dt-parser.ts +289 -0
  41. package/src/parser/markdown-parser.ts +32 -5
  42. package/src/skills.ts +274 -1
  43. package/src/tools.ts +53 -0
  44. package/src/verifier/dt-verifier.ts +562 -0
  45. package/src/verifier/types.ts +4 -0
@@ -0,0 +1,562 @@
1
+ // Decision Table Verifier
2
+ // Checks: completeness, consistency, redundancy, and structural integrity
3
+
4
+ import { DecisionTableDef, ConditionDef, CellValue, Rule } from '../parser/dt-ast.js';
5
+ import { VerificationError, VerificationResult, Severity } from './types.js';
6
+
7
+ // Helper to get all values for a condition
8
+ function getConditionValues(condition: ConditionDef): string[] {
9
+ if (condition.type === 'bool') {
10
+ return condition.values.length > 0 ? condition.values : ['true', 'false'];
11
+ }
12
+ return condition.values;
13
+ }
14
+
15
+ // Check if a cell matches a given value
16
+ function cellMatches(cell: CellValue, value: string): boolean {
17
+ switch (cell.kind) {
18
+ case 'any':
19
+ return true;
20
+ case 'exact':
21
+ return cell.value === value;
22
+ case 'negated':
23
+ return cell.value !== value;
24
+ case 'set':
25
+ return cell.values.includes(value);
26
+ }
27
+ }
28
+
29
+ // Check if a rule's conditions cover a specific input combination
30
+ function ruleMatchesInput(rule: Rule, conditionDefs: ConditionDef[], input: Map<string, string>): boolean {
31
+ for (const cond of conditionDefs) {
32
+ const cell = rule.conditions.get(cond.name);
33
+ if (!cell) continue; // No condition for this column means "any"
34
+ const expectedValue = input.get(cond.name);
35
+ if (!cellMatches(cell, expectedValue || '')) {
36
+ return false;
37
+ }
38
+ }
39
+ return true;
40
+ }
41
+
42
+ // Check if two rules overlap (can match the same input)
43
+ function rulesOverlap(rule1: Rule, rule2: Rule, conditionDefs: ConditionDef[]): boolean {
44
+ for (const cond of conditionDefs) {
45
+ const cell1 = rule1.conditions.get(cond.name);
46
+ const cell2 = rule2.conditions.get(cond.name);
47
+
48
+ // If either rule doesn't constrain this condition, they overlap on it
49
+ if (!cell1 || cell1.kind === 'any') continue;
50
+ if (!cell2 || cell2.kind === 'any') continue;
51
+
52
+ // Check if cells intersect
53
+ if (!cellsIntersect(cell1, cell2)) {
54
+ return false; // No overlap on this condition means no overall overlap
55
+ }
56
+ }
57
+ return true; // All constrained conditions intersect
58
+ }
59
+
60
+ // Check if two cells intersect (can match the same value)
61
+ function cellsIntersect(cell1: CellValue, cell2: CellValue): boolean {
62
+ // Any intersects with everything
63
+ if (cell1.kind === 'any' || cell2.kind === 'any') return true;
64
+
65
+ // Exact vs Exact
66
+ if (cell1.kind === 'exact' && cell2.kind === 'exact') {
67
+ return cell1.value === cell2.value;
68
+ }
69
+
70
+ // Exact vs Negated
71
+ if (cell1.kind === 'exact' && cell2.kind === 'negated') {
72
+ return cell2.value !== cell1.value;
73
+ }
74
+ if (cell1.kind === 'negated' && cell2.kind === 'exact') {
75
+ return cell1.value !== cell2.value;
76
+ }
77
+
78
+ // Exact vs Set
79
+ if (cell1.kind === 'exact' && cell2.kind === 'set') {
80
+ return cell2.values.includes(cell1.value);
81
+ }
82
+ if (cell1.kind === 'set' && cell2.kind === 'exact') {
83
+ return cell1.values.includes(cell2.value);
84
+ }
85
+
86
+ // Negated vs Negated
87
+ if (cell1.kind === 'negated' && cell2.kind === 'negated') {
88
+ return cell1.value !== cell2.value;
89
+ }
90
+
91
+ // Negated vs Set
92
+ if (cell1.kind === 'negated' && cell2.kind === 'set') {
93
+ return !cell2.values.includes(cell1.value);
94
+ }
95
+ if (cell1.kind === 'set' && cell2.kind === 'negated') {
96
+ return !cell1.values.includes(cell2.value);
97
+ }
98
+
99
+ // Set vs Set
100
+ if (cell1.kind === 'set' && cell2.kind === 'set') {
101
+ return cell1.values.some(v => cell2.values.includes(v));
102
+ }
103
+
104
+ return true;
105
+ }
106
+
107
+ // Generate all possible combinations of condition values
108
+ function generateCombinations(conditionDefs: ConditionDef[]): Map<string, string>[] {
109
+ const combinations: Map<string, string>[] = [];
110
+ const values = conditionDefs.map(c => getConditionValues(c));
111
+
112
+ function* cartesian(index: number, current: Map<string, string>): Generator<Map<string, string>> {
113
+ if (index === conditionDefs.length) {
114
+ yield new Map(current);
115
+ return;
116
+ }
117
+ const condName = conditionDefs[index].name;
118
+ for (const val of values[index]) {
119
+ current.set(condName, val);
120
+ yield* cartesian(index + 1, current);
121
+ current.delete(condName);
122
+ }
123
+ }
124
+
125
+ return [...cartesian(0, new Map())];
126
+ }
127
+
128
+ // Find which rules match a given input
129
+ function findMatchingRules(dt: DecisionTableDef, input: Map<string, string>): Rule[] {
130
+ return dt.rules.filter(rule => ruleMatchesInput(rule, dt.conditions, input));
131
+ }
132
+
133
+ // Check if two rules produce the same action outputs
134
+ function actionsMatch(rule1: Rule, rule2: Rule, actionNames: string[]): boolean {
135
+ for (const actionName of actionNames) {
136
+ const val1 = rule1.actions.get(actionName);
137
+ const val2 = rule2.actions.get(actionName);
138
+ if (val1 !== val2) return false;
139
+ }
140
+ return true;
141
+ }
142
+
143
+ // ============================================================
144
+ // Structural Checks
145
+ // ============================================================
146
+
147
+ function checkStructural(dt: DecisionTableDef): VerificationError[] {
148
+ const errors: VerificationError[] = [];
149
+
150
+ // DT_NO_CONDITIONS
151
+ if (dt.conditions.length === 0) {
152
+ errors.push({
153
+ code: 'DT_NO_CONDITIONS',
154
+ message: 'Decision table has no conditions declared',
155
+ severity: 'error',
156
+ location: { decisionTable: dt.name },
157
+ suggestion: 'Add a ## conditions section with at least one condition',
158
+ });
159
+ }
160
+
161
+ // DT_NO_ACTIONS
162
+ if (dt.actions.length === 0) {
163
+ errors.push({
164
+ code: 'DT_NO_ACTIONS',
165
+ message: 'Decision table has no actions declared',
166
+ severity: 'error',
167
+ location: { decisionTable: dt.name },
168
+ suggestion: 'Add an ## actions section with at least one action',
169
+ });
170
+ }
171
+
172
+ // DT_EMPTY_RULES
173
+ if (dt.rules.length === 0) {
174
+ errors.push({
175
+ code: 'DT_EMPTY_RULES',
176
+ message: 'Decision table has no rules',
177
+ severity: 'warning',
178
+ location: { decisionTable: dt.name },
179
+ suggestion: 'Add rules to the ## rules section',
180
+ });
181
+ return errors; // No point checking rule content if there are no rules
182
+ }
183
+
184
+ const conditionNames = new Set(dt.conditions.map(c => c.name));
185
+ const actionNames = new Set(dt.actions.map(a => a.name));
186
+ const ruleConditionNames = new Set<string>();
187
+ const ruleActionNames = new Set<string>();
188
+
189
+ // Check each rule
190
+ for (let ruleIdx = 0; ruleIdx < dt.rules.length; ruleIdx++) {
191
+ const rule = dt.rules[ruleIdx];
192
+ const ruleNum = rule.number ?? ruleIdx + 1;
193
+
194
+ // Check condition columns
195
+ for (const [condName] of rule.conditions) {
196
+ ruleConditionNames.add(condName);
197
+
198
+ // DT_UNKNOWN_CONDITION_COLUMN
199
+ if (!conditionNames.has(condName)) {
200
+ errors.push({
201
+ code: 'DT_UNKNOWN_CONDITION_COLUMN',
202
+ message: `Rule ${ruleNum} has unknown condition column "${condName}"`,
203
+ severity: 'warning',
204
+ location: { decisionTable: dt.name, rule: ruleNum, condition: condName },
205
+ suggestion: `Remove or rename the column to match a declared condition`,
206
+ });
207
+ } else {
208
+ // DT_UNKNOWN_CONDITION_VALUE
209
+ const cond = dt.conditions.find(c => c.name === condName)!;
210
+ const cell = rule.conditions.get(condName)!;
211
+
212
+ // Skip value validation for int_range — values are ranges, not enum values
213
+ if (cell.kind !== 'any' && cond.type !== 'string' && cond.type !== 'int_range') {
214
+ const validValues = getConditionValues(cond);
215
+ if (cell.kind === 'exact' && !validValues.includes(cell.value)) {
216
+ errors.push({
217
+ code: 'DT_UNKNOWN_CONDITION_VALUE',
218
+ message: `Rule ${ruleNum} condition "${condName}" has value "${cell.value}" not in declared values`,
219
+ severity: 'error',
220
+ location: { decisionTable: dt.name, rule: ruleNum, condition: condName },
221
+ suggestion: `Change to one of: ${validValues.join(', ')}`,
222
+ });
223
+ } else if (cell.kind === 'negated' && !validValues.includes(cell.value)) {
224
+ errors.push({
225
+ code: 'DT_UNKNOWN_CONDITION_VALUE',
226
+ message: `Rule ${ruleNum} condition "${condName}" negates "${cell.value}" which is not in declared values`,
227
+ severity: 'error',
228
+ location: { decisionTable: dt.name, rule: ruleNum, condition: condName },
229
+ suggestion: `Change to negate one of: ${validValues.join(', ')}`,
230
+ });
231
+ } else if (cell.kind === 'set') {
232
+ for (const v of cell.values) {
233
+ if (!validValues.includes(v)) {
234
+ errors.push({
235
+ code: 'DT_UNKNOWN_CONDITION_VALUE',
236
+ message: `Rule ${ruleNum} condition "${condName}" has value "${v}" not in declared values`,
237
+ severity: 'error',
238
+ location: { decisionTable: dt.name, rule: ruleNum, condition: condName },
239
+ suggestion: `Change to one of: ${validValues.join(', ')}`,
240
+ });
241
+ }
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
247
+
248
+ // Check action columns
249
+ for (const [actionName] of rule.actions) {
250
+ ruleActionNames.add(actionName);
251
+
252
+ // DT_UNKNOWN_ACTION_COLUMN
253
+ if (!actionNames.has(actionName)) {
254
+ errors.push({
255
+ code: 'DT_UNKNOWN_ACTION_COLUMN',
256
+ message: `Rule ${ruleNum} has unknown action column "${actionName}"`,
257
+ severity: 'warning',
258
+ location: { decisionTable: dt.name, rule: ruleNum, action: actionName },
259
+ suggestion: `Remove or rename the column to match a declared action`,
260
+ });
261
+ } else {
262
+ // DT_UNKNOWN_ACTION_VALUE
263
+ const action = dt.actions.find(a => a.name === actionName)!;
264
+ const value = rule.actions.get(actionName)!;
265
+
266
+ if (action.type === 'enum' && action.values) {
267
+ if (!action.values.includes(value)) {
268
+ errors.push({
269
+ code: 'DT_UNKNOWN_ACTION_VALUE',
270
+ message: `Rule ${ruleNum} action "${actionName}" has value "${value}" not in declared values`,
271
+ severity: 'error',
272
+ location: { decisionTable: dt.name, rule: ruleNum, action: actionName },
273
+ suggestion: `Change to one of: ${action.values.join(', ')}`,
274
+ });
275
+ }
276
+ }
277
+ }
278
+ }
279
+ }
280
+
281
+ // DT_MISSING_CONDITION_COLUMN
282
+ for (const condName of conditionNames) {
283
+ if (!ruleConditionNames.has(condName)) {
284
+ errors.push({
285
+ code: 'DT_MISSING_CONDITION_COLUMN',
286
+ message: `Condition "${condName}" is declared but has no column in the rules table`,
287
+ severity: 'warning',
288
+ location: { decisionTable: dt.name, condition: condName },
289
+ suggestion: `Add a "${condName}" column to the rules table`,
290
+ });
291
+ }
292
+ }
293
+
294
+ // DT_MISSING_ACTION_COLUMN
295
+ for (const actionName of actionNames) {
296
+ if (!ruleActionNames.has(actionName)) {
297
+ errors.push({
298
+ code: 'DT_MISSING_ACTION_COLUMN',
299
+ message: `Action "${actionName}" is declared but has no corresponding column in the rules table`,
300
+ severity: 'warning',
301
+ location: { decisionTable: dt.name, action: actionName },
302
+ suggestion: `Add a "→ ${actionName}" column to the rules table`,
303
+ });
304
+ }
305
+ }
306
+
307
+ // DT_DUPLICATE_RULE
308
+ for (let i = 0; i < dt.rules.length; i++) {
309
+ for (let j = i + 1; j < dt.rules.length; j++) {
310
+ const rule1 = dt.rules[i];
311
+ const rule2 = dt.rules[j];
312
+
313
+ // Check if conditions are identical
314
+ let identical = true;
315
+ if (rule1.conditions.size !== rule2.conditions.size) {
316
+ identical = false;
317
+ } else {
318
+ for (const [name, cell1] of rule1.conditions) {
319
+ const cell2 = rule2.conditions.get(name);
320
+ if (!cell2 || !cellsEqual(cell1, cell2)) {
321
+ identical = false;
322
+ break;
323
+ }
324
+ }
325
+ }
326
+
327
+ if (identical) {
328
+ const rule1Num = rule1.number ?? i + 1;
329
+ const rule2Num = rule2.number ?? j + 1;
330
+ errors.push({
331
+ code: 'DT_DUPLICATE_RULE',
332
+ message: `Rule ${rule1Num} and Rule ${rule2Num} have identical condition patterns`,
333
+ severity: 'warning',
334
+ location: { decisionTable: dt.name, rule: rule2Num },
335
+ suggestion: `Remove or modify one of the duplicate rules`,
336
+ });
337
+ }
338
+ }
339
+ }
340
+
341
+ return errors;
342
+ }
343
+
344
+ function cellsEqual(cell1: CellValue, cell2: CellValue): boolean {
345
+ if (cell1.kind !== cell2.kind) return false;
346
+ // Now cell1 and cell2 have the same kind, narrow both
347
+ const kind = cell1.kind;
348
+ if (kind === 'any') return true;
349
+ if (kind === 'exact') {
350
+ return (cell1 as { kind: 'exact'; value: string }).value === (cell2 as { kind: 'exact'; value: string }).value;
351
+ }
352
+ if (kind === 'negated') {
353
+ return (cell1 as { kind: 'negated'; value: string }).value === (cell2 as { kind: 'negated'; value: string }).value;
354
+ }
355
+ if (kind === 'set') {
356
+ const s1 = cell1 as { kind: 'set'; values: string[] };
357
+ const s2 = cell2 as { kind: 'set'; values: string[] };
358
+ return s1.values.length === s2.values.length && s1.values.every(v => s2.values.includes(v));
359
+ }
360
+ return true;
361
+ }
362
+
363
+ // ============================================================
364
+ // Completeness Check
365
+ // ============================================================
366
+
367
+ function checkCompleteness(dt: DecisionTableDef): VerificationError[] {
368
+ const errors: VerificationError[] = [];
369
+
370
+ if (dt.conditions.length === 0) return errors; // Already reported in structural
371
+
372
+ // int_range conditions cannot be exhaustively enumerated — skip completeness check
373
+ if (dt.conditions.some(c => c.type === 'int_range')) {
374
+ errors.push({
375
+ code: 'DT_COMPLETENESS_SKIPPED',
376
+ message: 'Completeness check skipped: int_range conditions cannot be exhaustively enumerated',
377
+ severity: 'warning',
378
+ location: { decisionTable: dt.name },
379
+ suggestion: 'Manually verify that all numeric ranges are covered without gaps',
380
+ });
381
+ return errors;
382
+ }
383
+
384
+ // Calculate total combinations for enum/bool conditions
385
+ let totalCombinations = 1;
386
+ for (const cond of dt.conditions) {
387
+ const values = getConditionValues(cond);
388
+ if (values.length === 0) {
389
+ totalCombinations = Infinity;
390
+ break;
391
+ }
392
+ totalCombinations *= values.length;
393
+ if (totalCombinations > 4096) break;
394
+ }
395
+
396
+ if (totalCombinations > 4096) {
397
+ errors.push({
398
+ code: 'DT_COMPLETENESS_SKIPPED',
399
+ message: `Completeness check skipped: ${totalCombinations} combinations exceed limit of 4096`,
400
+ severity: 'warning',
401
+ location: { decisionTable: dt.name },
402
+ suggestion: 'Consider simplifying conditions or using wildcards to reduce combination count',
403
+ });
404
+ return errors;
405
+ }
406
+
407
+ // Generate all combinations and check coverage
408
+ const combinations = generateCombinations(dt.conditions);
409
+ const actionNames = dt.actions.map(a => a.name);
410
+
411
+ for (const combo of combinations) {
412
+ const matchingRules = findMatchingRules(dt, combo);
413
+
414
+ if (matchingRules.length === 0) {
415
+ const comboDesc = [...combo.entries()].map(([k, v]) => `${k}=${v}`).join(', ');
416
+ errors.push({
417
+ code: 'DT_INCOMPLETE',
418
+ message: `Missing coverage for: ${comboDesc}`,
419
+ severity: 'error',
420
+ location: { decisionTable: dt.name },
421
+ suggestion: `Add a rule to cover this condition combination`,
422
+ });
423
+ }
424
+ }
425
+
426
+ return errors;
427
+ }
428
+
429
+ // ============================================================
430
+ // Consistency Check
431
+ // ============================================================
432
+
433
+ function checkConsistency(dt: DecisionTableDef): VerificationError[] {
434
+ const errors: VerificationError[] = [];
435
+ const isAllMatch = dt.policy === 'all-match';
436
+
437
+ for (let i = 0; i < dt.rules.length; i++) {
438
+ for (let j = i + 1; j < dt.rules.length; j++) {
439
+ const rule1 = dt.rules[i];
440
+ const rule2 = dt.rules[j];
441
+
442
+ // Check if rules overlap
443
+ if (!rulesOverlap(rule1, rule2, dt.conditions)) continue;
444
+
445
+ // Rules overlap - check if actions agree
446
+ const actionNames = dt.actions.map(a => a.name);
447
+ const actionsAgree = actionsMatch(rule1, rule2, actionNames);
448
+
449
+ if (!actionsAgree) {
450
+ const rule1Num = rule1.number ?? i + 1;
451
+ const rule2Num = rule2.number ?? j + 1;
452
+ const severity: Severity = isAllMatch ? 'error' : 'warning';
453
+ const code = isAllMatch ? 'DT_INCONSISTENT' : 'DT_INCONSISTENT';
454
+
455
+ const overlappingConditions: string[] = [];
456
+ for (const cond of dt.conditions) {
457
+ const cell1 = rule1.conditions.get(cond.name);
458
+ const cell2 = rule2.conditions.get(cond.name);
459
+ if (cell1 && cell2 && cellsIntersect(cell1, cell2)) {
460
+ overlappingConditions.push(cond.name);
461
+ }
462
+ }
463
+
464
+ errors.push({
465
+ code,
466
+ message: `Rules ${rule1Num} and ${rule2Num} can match the same input but produce different results`,
467
+ severity,
468
+ location: { decisionTable: dt.name, rule: rule2Num },
469
+ suggestion: `For ${isAllMatch ? 'all-match' : 'first-match'} policy: review overlapping rules on conditions: ${overlappingConditions.join(', ')}`,
470
+ });
471
+ }
472
+ }
473
+ }
474
+
475
+ return errors;
476
+ }
477
+
478
+ // ============================================================
479
+ // Redundancy Check
480
+ // ============================================================
481
+
482
+ function checkRedundancy(dt: DecisionTableDef): VerificationError[] {
483
+ const errors: VerificationError[] = [];
484
+
485
+ // For each rule, check if it's fully covered by earlier rules with same actions
486
+ for (let ruleIdx = 1; ruleIdx < dt.rules.length; ruleIdx++) {
487
+ const rule = dt.rules[ruleIdx];
488
+ const ruleNum = rule.number ?? ruleIdx + 1;
489
+ const actionNames = dt.actions.map(a => a.name);
490
+
491
+ // A rule is redundant if at least one earlier rule overlaps it AND all overlapping
492
+ // earlier rules produce the same actions (meaning first-match would always hit them first
493
+ // with an identical result, so this rule can never change the outcome).
494
+ let hasOverlappingPredecessor = false;
495
+ let allOverlappingHaveSameActions = true;
496
+
497
+ for (let prevIdx = 0; prevIdx < ruleIdx; prevIdx++) {
498
+ const prevRule = dt.rules[prevIdx];
499
+
500
+ if (!rulesOverlap(prevRule, rule, dt.conditions)) continue;
501
+
502
+ hasOverlappingPredecessor = true;
503
+
504
+ if (!actionsMatch(prevRule, rule, actionNames)) {
505
+ allOverlappingHaveSameActions = false;
506
+ break;
507
+ }
508
+ }
509
+
510
+ if (hasOverlappingPredecessor && allOverlappingHaveSameActions) {
511
+ errors.push({
512
+ code: 'DT_REDUNDANT',
513
+ message: `Rule ${ruleNum} is redundant — earlier rules cover all its cases with the same actions`,
514
+ severity: 'warning',
515
+ location: { decisionTable: dt.name, rule: ruleNum },
516
+ suggestion: `Remove this rule or make it more specific`,
517
+ });
518
+ }
519
+ }
520
+
521
+ return errors;
522
+ }
523
+
524
+ // ============================================================
525
+ // Main Verifier
526
+ // ============================================================
527
+
528
+ export function verifyDecisionTable(dt: DecisionTableDef): VerificationResult {
529
+ const errors: VerificationError[] = [];
530
+
531
+ // Run structural checks first
532
+ errors.push(...checkStructural(dt));
533
+
534
+ // Run semantic checks (only if basic structure is valid)
535
+ const hasNoConditions = dt.conditions.length === 0;
536
+ const hasNoActions = dt.actions.length === 0;
537
+
538
+ if (!hasNoConditions && !hasNoActions) {
539
+ errors.push(...checkCompleteness(dt));
540
+ errors.push(...checkConsistency(dt));
541
+ errors.push(...checkRedundancy(dt));
542
+ }
543
+
544
+ return {
545
+ valid: !errors.some(e => e.severity === 'error'),
546
+ errors,
547
+ };
548
+ }
549
+
550
+ export function verifyDecisionTables(dts: DecisionTableDef[]): VerificationResult {
551
+ const allErrors: VerificationError[] = [];
552
+
553
+ for (const dt of dts) {
554
+ const result = verifyDecisionTable(dt);
555
+ allErrors.push(...result.errors);
556
+ }
557
+
558
+ return {
559
+ valid: !allErrors.some(e => e.severity === 'error'),
560
+ errors: allErrors,
561
+ };
562
+ }
@@ -10,6 +10,10 @@ export interface VerificationError {
10
10
  state?: string;
11
11
  event?: string;
12
12
  transition?: Transition;
13
+ rule?: number; // NEW - rule number (1-based)
14
+ condition?: string; // NEW - condition name
15
+ action?: string; // NEW - action name
16
+ decisionTable?: string; // NEW - decision table name
13
17
  };
14
18
  suggestion?: string;
15
19
  }