@proposit/proposit-core 0.12.3 → 1.0.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.
Files changed (125) hide show
  1. package/README.md +104 -93
  2. package/dist/cli/commands/premises.d.ts.map +1 -1
  3. package/dist/cli/commands/premises.js +28 -24
  4. package/dist/cli/commands/premises.js.map +1 -1
  5. package/dist/cli/commands/repair.d.ts.map +1 -1
  6. package/dist/cli/commands/repair.js +4 -2
  7. package/dist/cli/commands/repair.js.map +1 -1
  8. package/dist/cli/commands/validate.d.ts.map +1 -1
  9. package/dist/cli/commands/validate.js +7 -1
  10. package/dist/cli/commands/validate.js.map +1 -1
  11. package/dist/cli/engine.d.ts.map +1 -1
  12. package/dist/cli/engine.js +7 -25
  13. package/dist/cli/engine.js.map +1 -1
  14. package/dist/cli/import.d.ts.map +1 -1
  15. package/dist/cli/import.js +66 -28
  16. package/dist/cli/import.js.map +1 -1
  17. package/dist/lib/core/argument-engine.d.ts +275 -10
  18. package/dist/lib/core/argument-engine.d.ts.map +1 -1
  19. package/dist/lib/core/argument-engine.js +442 -82
  20. package/dist/lib/core/argument-engine.js.map +1 -1
  21. package/dist/lib/core/argument-library.d.ts +5 -1
  22. package/dist/lib/core/argument-library.d.ts.map +1 -1
  23. package/dist/lib/core/argument-library.js +7 -3
  24. package/dist/lib/core/argument-library.js.map +1 -1
  25. package/dist/lib/core/expression-manager.d.ts +68 -73
  26. package/dist/lib/core/expression-manager.d.ts.map +1 -1
  27. package/dist/lib/core/expression-manager.js +272 -771
  28. package/dist/lib/core/expression-manager.js.map +1 -1
  29. package/dist/lib/core/fork.d.ts +5 -1
  30. package/dist/lib/core/fork.d.ts.map +1 -1
  31. package/dist/lib/core/fork.js +16 -6
  32. package/dist/lib/core/fork.js.map +1 -1
  33. package/dist/lib/core/interfaces/argument-engine.interfaces.d.ts +68 -7
  34. package/dist/lib/core/interfaces/argument-engine.interfaces.d.ts.map +1 -1
  35. package/dist/lib/core/interfaces/library.interfaces.d.ts +8 -3
  36. package/dist/lib/core/interfaces/library.interfaces.d.ts.map +1 -1
  37. package/dist/lib/core/interfaces/premise-engine.interfaces.d.ts +50 -47
  38. package/dist/lib/core/interfaces/premise-engine.interfaces.d.ts.map +1 -1
  39. package/dist/lib/core/premise-engine.d.ts +80 -11
  40. package/dist/lib/core/premise-engine.d.ts.map +1 -1
  41. package/dist/lib/core/premise-engine.js +245 -83
  42. package/dist/lib/core/premise-engine.js.map +1 -1
  43. package/dist/lib/core/proposit-core.d.ts.map +1 -1
  44. package/dist/lib/core/proposit-core.js +13 -3
  45. package/dist/lib/core/proposit-core.js.map +1 -1
  46. package/dist/lib/grammar/an-rules.d.ts +158 -0
  47. package/dist/lib/grammar/an-rules.d.ts.map +1 -0
  48. package/dist/lib/grammar/an-rules.js +778 -0
  49. package/dist/lib/grammar/an-rules.js.map +1 -0
  50. package/dist/lib/grammar/auto-normalize.d.ts +14 -0
  51. package/dist/lib/grammar/auto-normalize.d.ts.map +1 -0
  52. package/dist/lib/grammar/auto-normalize.js +35 -0
  53. package/dist/lib/grammar/auto-normalize.js.map +1 -0
  54. package/dist/lib/grammar/bounded-subtree.d.ts +30 -0
  55. package/dist/lib/grammar/bounded-subtree.d.ts.map +1 -0
  56. package/dist/lib/grammar/bounded-subtree.js +74 -0
  57. package/dist/lib/grammar/bounded-subtree.js.map +1 -0
  58. package/dist/lib/grammar/naked-q.d.ts +20 -0
  59. package/dist/lib/grammar/naked-q.d.ts.map +1 -0
  60. package/dist/lib/grammar/naked-q.js +58 -0
  61. package/dist/lib/grammar/naked-q.js.map +1 -0
  62. package/dist/lib/grammar/normalize.d.ts +12 -0
  63. package/dist/lib/grammar/normalize.d.ts.map +1 -0
  64. package/dist/lib/grammar/normalize.js +45 -0
  65. package/dist/lib/grammar/normalize.js.map +1 -0
  66. package/dist/lib/grammar/populate-from.d.ts +25 -0
  67. package/dist/lib/grammar/populate-from.d.ts.map +1 -0
  68. package/dist/lib/grammar/populate-from.js +252 -0
  69. package/dist/lib/grammar/populate-from.js.map +1 -0
  70. package/dist/lib/grammar/repair.d.ts +65 -0
  71. package/dist/lib/grammar/repair.d.ts.map +1 -0
  72. package/dist/lib/grammar/repair.js +251 -0
  73. package/dist/lib/grammar/repair.js.map +1 -0
  74. package/dist/lib/grammar/types.d.ts +17 -0
  75. package/dist/lib/grammar/types.d.ts.map +1 -0
  76. package/dist/lib/grammar/types.js +82 -0
  77. package/dist/lib/grammar/types.js.map +1 -0
  78. package/dist/lib/grammar/validate.d.ts +4 -0
  79. package/dist/lib/grammar/validate.d.ts.map +1 -0
  80. package/dist/lib/grammar/validate.js +28 -0
  81. package/dist/lib/grammar/validate.js.map +1 -0
  82. package/dist/lib/grammar/validators/context.d.ts +11 -0
  83. package/dist/lib/grammar/validators/context.d.ts.map +1 -0
  84. package/dist/lib/grammar/validators/context.js +5 -0
  85. package/dist/lib/grammar/validators/context.js.map +1 -0
  86. package/dist/lib/grammar/validators/derivable.d.ts +63 -0
  87. package/dist/lib/grammar/validators/derivable.d.ts.map +1 -0
  88. package/dist/lib/grammar/validators/derivable.js +502 -0
  89. package/dist/lib/grammar/validators/derivable.js.map +1 -0
  90. package/dist/lib/grammar/validators/evaluable.d.ts +48 -0
  91. package/dist/lib/grammar/validators/evaluable.d.ts.map +1 -0
  92. package/dist/lib/grammar/validators/evaluable.js +226 -0
  93. package/dist/lib/grammar/validators/evaluable.js.map +1 -0
  94. package/dist/lib/grammar/validators/presentable.d.ts +45 -0
  95. package/dist/lib/grammar/validators/presentable.d.ts.map +1 -0
  96. package/dist/lib/grammar/validators/presentable.js +231 -0
  97. package/dist/lib/grammar/validators/presentable.js.map +1 -0
  98. package/dist/lib/grammar/validators/structural.d.ts +103 -0
  99. package/dist/lib/grammar/validators/structural.d.ts.map +1 -0
  100. package/dist/lib/grammar/validators/structural.js +602 -0
  101. package/dist/lib/grammar/validators/structural.js.map +1 -0
  102. package/dist/lib/index.d.ts +4 -3
  103. package/dist/lib/index.d.ts.map +1 -1
  104. package/dist/lib/index.js +2 -2
  105. package/dist/lib/index.js.map +1 -1
  106. package/dist/lib/parsing/argument-parser.d.ts.map +1 -1
  107. package/dist/lib/parsing/argument-parser.js +52 -10
  108. package/dist/lib/parsing/argument-parser.js.map +1 -1
  109. package/dist/lib/types/evaluation.d.ts +1 -1
  110. package/dist/lib/types/evaluation.d.ts.map +1 -1
  111. package/dist/lib/types/fork.d.ts +12 -3
  112. package/dist/lib/types/fork.d.ts.map +1 -1
  113. package/dist/lib/types/validation.d.ts +0 -6
  114. package/dist/lib/types/validation.d.ts.map +1 -1
  115. package/dist/lib/types/validation.js +23 -6
  116. package/dist/lib/types/validation.js.map +1 -1
  117. package/package.json +1 -1
  118. package/dist/lib/core/managed-derivation-premise-engine.d.ts +0 -172
  119. package/dist/lib/core/managed-derivation-premise-engine.d.ts.map +0 -1
  120. package/dist/lib/core/managed-derivation-premise-engine.js +0 -550
  121. package/dist/lib/core/managed-derivation-premise-engine.js.map +0 -1
  122. package/dist/lib/types/grammar.d.ts +0 -83
  123. package/dist/lib/types/grammar.d.ts.map +0 -1
  124. package/dist/lib/types/grammar.js +0 -24
  125. package/dist/lib/types/grammar.js.map +0 -1
@@ -0,0 +1,226 @@
1
+ // Evaluable-tier validators (E-1, E-3..E-7). Code 'E-2' is reserved — see
2
+ // spec §4.2 (formula non-emptiness was promoted to Structural as S-13).
3
+ //
4
+ // E-1 variadic operator arity floor (and/or have ≥ 2 children)
5
+ // E-3 variable binding resolves
6
+ // E-4 axiomatic-binding constraint (runtime guard; AST-level no-op,
7
+ // documented in JSDoc)
8
+ // E-5 derivation premise consequent present
9
+ // E-6 claim-derivation pairing (≤ 1 derivation premise per normal claim)
10
+ // E-7 argument has conclusion premise
11
+ import { isClaimBound, isPremiseBound } from "../../schemata/propositional.js";
12
+ /**
13
+ * Build a Map<parentId, child-count> view of the expression tree.
14
+ * Used by the variadic-arity validator E-1.
15
+ */
16
+ function childCounts(expressions) {
17
+ const out = new Map();
18
+ for (const e of expressions) {
19
+ if (e.parentId === null)
20
+ continue;
21
+ out.set(e.parentId, (out.get(e.parentId) ?? 0) + 1);
22
+ }
23
+ return out;
24
+ }
25
+ /**
26
+ * E-1 — Variadic operator arity floor. `and` and `or` each have at least
27
+ * two children. (Unary `not`/`formula` are constrained Structurally per
28
+ * S-12/S-13; binary `implies`/`iff` per S-8.)
29
+ */
30
+ export function validateE1(ctx) {
31
+ const violations = [];
32
+ const counts = childCounts(ctx.expressions);
33
+ for (const e of ctx.expressions) {
34
+ if (e.type !== "operator")
35
+ continue;
36
+ if (e.operator !== "and" && e.operator !== "or")
37
+ continue;
38
+ const count = counts.get(e.id) ?? 0;
39
+ if (count < 2) {
40
+ violations.push({
41
+ tier: "evaluable",
42
+ code: "E-1",
43
+ message: `${e.operator} expression ${e.id} has ${count} children (variadic operator requires ≥ 2)`,
44
+ argumentId: ctx.argument.id,
45
+ premiseId: e.premiseId,
46
+ expressionId: e.id,
47
+ });
48
+ }
49
+ }
50
+ return violations;
51
+ }
52
+ // 'E-2' reserved — not used.
53
+ /**
54
+ * E-3 — Variable binding resolves. Every variable's claim or premise
55
+ * reference points at an existing target. External premise bindings
56
+ * (`boundArgumentId !== argument.id`) resolve in a different argument
57
+ * and are out of scope here — those targets aren't in this context.
58
+ */
59
+ export function validateE3(ctx) {
60
+ const violations = [];
61
+ const premiseIds = new Set(ctx.premises.map((p) => p.id));
62
+ const claimIds = new Set(ctx.claims.map((c) => c.id));
63
+ for (const v of ctx.variables) {
64
+ const variableId = v.id;
65
+ if (isClaimBound(v)) {
66
+ if (!claimIds.has(v.claimId)) {
67
+ violations.push({
68
+ tier: "evaluable",
69
+ code: "E-3",
70
+ message: `variable ${variableId} claim binding ${v.claimId} does not resolve`,
71
+ argumentId: ctx.argument.id,
72
+ variableId,
73
+ claimId: v.claimId,
74
+ });
75
+ }
76
+ }
77
+ else if (isPremiseBound(v)) {
78
+ if (v.boundArgumentId === ctx.argument.id &&
79
+ !premiseIds.has(v.boundPremiseId)) {
80
+ violations.push({
81
+ tier: "evaluable",
82
+ code: "E-3",
83
+ message: `variable ${variableId} premise binding ${v.boundPremiseId} does not resolve`,
84
+ argumentId: ctx.argument.id,
85
+ variableId,
86
+ premiseId: v.boundPremiseId,
87
+ });
88
+ }
89
+ }
90
+ }
91
+ return violations;
92
+ }
93
+ /**
94
+ * E-4 — Axiomatic-binding constraint. Axiomatic-bound variables must not
95
+ * be assigned in the caller's evaluation input. This is a **runtime
96
+ * guard** on caller-supplied input, not an AST invariant — the check
97
+ * runs inside `ArgumentEngine.evaluate` / `.checkValidity` and rejects
98
+ * pre-flight with the engine-error code `AXIOM_VARIABLE_ASSIGNMENT_FORBIDDEN`.
99
+ * The AST-level validator cannot detect E-4 from the argument tree alone
100
+ * and intentionally returns an empty array.
101
+ */
102
+ export function validateE4(_ctx) {
103
+ return [];
104
+ }
105
+ /**
106
+ * E-5 — Derivation premise consequent present. Every `type='derivation'`
107
+ * premise's expression tree includes a variable bound to its
108
+ * `derivedClaimId`. Naked-Q satisfies this (the lone variable at the
109
+ * root *is* the consequent).
110
+ */
111
+ export function validateE5(ctx) {
112
+ const violations = [];
113
+ // Build variable lookup: variableId → claimId (for claim-bound only).
114
+ const varToClaim = new Map();
115
+ for (const v of ctx.variables) {
116
+ if (isClaimBound(v))
117
+ varToClaim.set(v.id, v.claimId);
118
+ }
119
+ // Group expressions by premise.
120
+ const exprsByPremise = new Map();
121
+ for (const e of ctx.expressions) {
122
+ const list = exprsByPremise.get(e.premiseId) ?? [];
123
+ list.push(e);
124
+ exprsByPremise.set(e.premiseId, list);
125
+ }
126
+ for (const p of ctx.premises) {
127
+ if (p.type !== "derivation")
128
+ continue;
129
+ const exprs = exprsByPremise.get(p.id) ?? [];
130
+ const hasConsequent = exprs.some((e) => e.type === "variable" &&
131
+ varToClaim.get(e.variableId) === p.derivedClaimId);
132
+ if (!hasConsequent) {
133
+ violations.push({
134
+ tier: "evaluable",
135
+ code: "E-5",
136
+ message: `derivation premise ${p.id} has no variable bound to derivedClaimId ${p.derivedClaimId}`,
137
+ argumentId: ctx.argument.id,
138
+ premiseId: p.id,
139
+ claimId: p.derivedClaimId,
140
+ });
141
+ }
142
+ }
143
+ return violations;
144
+ }
145
+ /**
146
+ * E-6 — Claim-derivation pairing. For every `type='normal'` claim
147
+ * referenced in the argument, at most one `type='derivation'` premise
148
+ * exists with `derivedClaimId` matching that claim. Zero is valid (the
149
+ * post-publish-pruning state); two or more is the violation.
150
+ */
151
+ export function validateE6(ctx) {
152
+ const violations = [];
153
+ const byDerivedClaim = new Map();
154
+ for (const p of ctx.premises) {
155
+ if (p.type !== "derivation")
156
+ continue;
157
+ const list = byDerivedClaim.get(p.derivedClaimId) ?? [];
158
+ list.push(p.id);
159
+ byDerivedClaim.set(p.derivedClaimId, list);
160
+ }
161
+ for (const [claimId, premiseIds] of byDerivedClaim) {
162
+ if (premiseIds.length > 1) {
163
+ // Every premise in a >1-group is in violation — "at most one"
164
+ // has no canonical "first" that's correct and the rest wrong.
165
+ // Consumers wanting first-wins can dedupe by claimId at the UI
166
+ // layer. Matches the parallel decision in S-5 (root-only
167
+ // IMPLIES/IFF) from the B1 review polish.
168
+ for (const offendingId of premiseIds) {
169
+ violations.push({
170
+ tier: "evaluable",
171
+ code: "E-6",
172
+ message: `claim ${claimId} has ${premiseIds.length} derivation premises (expected ≤ 1; offender: ${offendingId})`,
173
+ argumentId: ctx.argument.id,
174
+ premiseId: offendingId,
175
+ claimId,
176
+ });
177
+ }
178
+ }
179
+ }
180
+ return violations;
181
+ }
182
+ /**
183
+ * E-7 — Argument has conclusion premise. An argument that has at least
184
+ * one premise has exactly one premise designated as the conclusion via
185
+ * `roleState.conclusionPremiseId`. A brand-new argument with zero
186
+ * premises is exempt.
187
+ */
188
+ export function validateE7(ctx) {
189
+ if (ctx.premises.length === 0)
190
+ return [];
191
+ const conclusionId = ctx.roleState.conclusionPremiseId;
192
+ if (conclusionId === undefined) {
193
+ return [
194
+ {
195
+ tier: "evaluable",
196
+ code: "E-7",
197
+ message: "argument has premises but no conclusion designated",
198
+ argumentId: ctx.argument.id,
199
+ },
200
+ ];
201
+ }
202
+ const found = ctx.premises.some((p) => p.id === conclusionId);
203
+ if (!found) {
204
+ return [
205
+ {
206
+ tier: "evaluable",
207
+ code: "E-7",
208
+ message: `conclusionPremiseId ${conclusionId} does not match any premise`,
209
+ argumentId: ctx.argument.id,
210
+ premiseId: conclusionId,
211
+ },
212
+ ];
213
+ }
214
+ return [];
215
+ }
216
+ export function validateEvaluable(ctx) {
217
+ return [
218
+ ...validateE1(ctx),
219
+ ...validateE3(ctx),
220
+ ...validateE4(ctx),
221
+ ...validateE5(ctx),
222
+ ...validateE6(ctx),
223
+ ...validateE7(ctx),
224
+ ];
225
+ }
226
+ //# sourceMappingURL=evaluable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluable.js","sourceRoot":"","sources":["../../../../src/lib/grammar/validators/evaluable.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wEAAwE;AACxE,EAAE;AACF,gEAAgE;AAChE,iCAAiC;AACjC,qEAAqE;AACrE,4BAA4B;AAC5B,6CAA6C;AAC7C,0EAA0E;AAC1E,uCAAuC;AAIvC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAE9E;;;GAGG;AACH,SAAS,WAAW,CAChB,WAAgE;IAEhE,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAA;IACrC,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAC1B,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI;YAAE,SAAQ;QACjC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACvD,CAAC;IACD,OAAO,GAAG,CAAA;AACd,CAAC;AAED;;;;GAIG;AACH,M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/**
4
+ * P-1 — Formula buffer between operators. A non-`not` operator (`and`,
5
+ * `or`, `implies`, `iff`) is never a direct child of another operator
6
+ * expression. `not` is exempt — it can be a direct child of any
7
+ * operator.
8
+ *
9
+ * Reports the inner (child) operator that breaks the rule, with the
10
+ * outer (parent) operator referenced in the message.
11
+ */
12
+ export declare function validateP1(ctx: TValidatorContext): readonly TViolation[];
13
+ /**
14
+ * P-2 — No double negation. `not(not(x))` does not appear in the tree.
15
+ * Reports the outer NOT.
16
+ */
17
+ export declare function validateP2(ctx: TValidatorContext): readonly TViolation[];
18
+ /**
19
+ * P-3 — Formula has operator descendant. A `formula` node's bounded
20
+ * subtree (stopping at the next nested formula) contains at least one
21
+ * binary operator (`and` or `or`). Formulas wrapping a leaf or a single
22
+ * `not` chain are not Presentable.
23
+ */
24
+ export declare function validateP3(ctx: TValidatorContext): readonly TViolation[];
25
+ /**
26
+ * P-4 — No single-child binary operator. `and` / `or` with exactly one
27
+ * child is not Presentable. Largely redundant with E-1 (variadic arity
28
+ * ≥ 2), kept for clarity in the rule inventory.
29
+ */
30
+ export declare function validateP4(ctx: TValidatorContext): readonly TViolation[];
31
+ /**
32
+ * P-5 — No operator-of-same-type adjacency through a formula. When a
33
+ * parent operator (`and` / `or`) has a `formula` child whose only
34
+ * descendant operator (after peeling through transparent formula
35
+ * buffers) is the same operator, the inner operator should be absorbed
36
+ * into the parent.
37
+ *
38
+ * Example: `AND(formula(AND(b, c)), d)` should be `AND(b, c, d)`.
39
+ *
40
+ * The rule applies to `and` / `or` only — `implies` / `iff` are root-
41
+ * only per S-5 and cannot appear as a child operator.
42
+ */
43
+ export declare function validateP5(ctx: TValidatorContext): readonly TViolation[];
44
+ export declare function validatePresentable(ctx: TValidatorContext): readonly TViolation[];
45
+ //# sourceMappingURL=presentable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentable.d.ts","sourceRoot":"","sources":["../../../../src/lib/grammar/validators/presentable.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAqCrD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAoBxE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAoBxE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAwBxE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAmBxE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAuBxE;AA8BD,wBAAgB,mBAAmB,CAC/B,GAAG,EAAE,iBAAiB,GACvB,SAAS,UAAU,EAAE,CAQvB"}
@@ -0,0 +1,231 @@
1
+ // Presentable-tier validators (P-1..P-5).
2
+ //
3
+ // P-1 formula buffer between operators
4
+ // P-2 no double negation
5
+ // P-3 formula has operator descendant
6
+ // P-4 no single-child binary operator (largely redundant with E-1, kept
7
+ // for clarity in the rule inventory)
8
+ // P-5 no operator-of-same-type adjacency through a formula
9
+ import { hasBinaryOperatorInBoundedSubtree } from "../bounded-subtree.js";
10
+ /**
11
+ * Build a Map<parentId, children-sorted-by-position> view of the
12
+ * expression tree.
13
+ */
14
+ function buildChildMap(expressions) {
15
+ const out = new Map();
16
+ for (const e of expressions) {
17
+ if (e.parentId === null)
18
+ continue;
19
+ const list = out.get(e.parentId) ?? [];
20
+ list.push(e);
21
+ out.set(e.parentId, list);
22
+ }
23
+ for (const list of out.values()) {
24
+ list.sort((a, b) => a.position - b.position);
25
+ }
26
+ return out;
27
+ }
28
+ /**
29
+ * Map<expressionId, expression> view for quick lookup.
30
+ */
31
+ function buildExpressionsById(expressions) {
32
+ const out = new Map();
33
+ for (const e of expressions)
34
+ out.set(e.id, e);
35
+ return out;
36
+ }
37
+ /**
38
+ * P-1 — Formula buffer between operators. A non-`not` operator (`and`,
39
+ * `or`, `implies`, `iff`) is never a direct child of another operator
40
+ * expression. `not` is exempt — it can be a direct child of any
41
+ * operator.
42
+ *
43
+ * Reports the inner (child) operator that breaks the rule, with the
44
+ * outer (parent) operator referenced in the message.
45
+ */
46
+ export function validateP1(ctx) {
47
+ const violations = [];
48
+ const byId = buildExpressionsById(ctx.expressions);
49
+ for (const e of ctx.expressions) {
50
+ if (e.type !== "operator")
51
+ continue;
52
+ if (e.operator === "not")
53
+ continue;
54
+ if (e.parentId === null)
55
+ continue;
56
+ const parent = byId.get(e.parentId);
57
+ if (parent === undefined)
58
+ continue;
59
+ if (parent.type !== "operator")
60
+ continue;
61
+ violations.push({
62
+ tier: "presentable",
63
+ code: "P-1",
64
+ message: `${e.operator} expression ${e.id} is a direct child of operator ${parent.operator} ${parent.id} (formula buffer required)`,
65
+ argumentId: ctx.argument.id,
66
+ premiseId: e.premiseId,
67
+ expressionId: e.id,
68
+ });
69
+ }
70
+ return violations;
71
+ }
72
+ /**
73
+ * P-2 — No double negation. `not(not(x))` does not appear in the tree.
74
+ * Reports the outer NOT.
75
+ */
76
+ export function validateP2(ctx) {
77
+ const violations = [];
78
+ const children = buildChildMap(ctx.expressions);
79
+ for (const outer of ctx.expressions) {
80
+ if (outer.type !== "operator" || outer.operator !== "not")
81
+ continue;
82
+ const kids = children.get(outer.id) ?? [];
83
+ if (kids.length !== 1)
84
+ continue;
85
+ const child = kids[0];
86
+ if (child.type === "operator" && child.operator === "not") {
87
+ violations.push({
88
+ tier: "presentable",
89
+ code: "P-2",
90
+ message: `not expression ${outer.id} wraps another not (${child.id})`,
91
+ argumentId: ctx.argument.id,
92
+ premiseId: outer.premiseId,
93
+ expressionId: outer.id,
94
+ });
95
+ }
96
+ }
97
+ return violations;
98
+ }
99
+ /**
100
+ * P-3 — Formula has operator descendant. A `formula` node's bounded
101
+ * subtree (stopping at the next nested formula) contains at least one
102
+ * binary operator (`and` or `or`). Formulas wrapping a leaf or a single
103
+ * `not` chain are not Presentable.
104
+ */
105
+ export function validateP3(ctx) {
106
+ const violations = [];
107
+ const children = buildChildMap(ctx.expressions);
108
+ const exprById = new Map();
109
+ for (const e of ctx.expressions)
110
+ exprById.set(e.id, e);
111
+ const lookup = (id) => children.get(id) ?? [];
112
+ const getExpression = (id) => exprById.get(id);
113
+ for (const f of ctx.expressions) {
114
+ if (f.type !== "formula")
115
+ continue;
116
+ if (!hasBinaryOperatorInBoundedSubtree(f.id, lookup, getExpression)) {
117
+ violations.push({
118
+ tier: "presentable",
119
+ code: "P-3",
120
+ message: `formula ${f.id} has no binary operator (and/or) descendant in its bounded subtree`,
121
+ argumentId: ctx.argument.id,
122
+ premiseId: f.premiseId,
123
+ expressionId: f.id,
124
+ });
125
+ }
126
+ }
127
+ return violations;
128
+ }
129
+ /**
130
+ * P-4 — No single-child binary operator. `and` / `or` with exactly one
131
+ * child is not Presentable. Largely redundant with E-1 (variadic arity
132
+ * ≥ 2), kept for clarity in the rule inventory.
133
+ */
134
+ export function validateP4(ctx) {
135
+ const violations = [];
136
+ const children = buildChildMap(ctx.expressions);
137
+ for (const e of ctx.expressions) {
138
+ if (e.type !== "operator")
139
+ continue;
140
+ if (e.operator !== "and" && e.operator !== "or")
141
+ continue;
142
+ const count = (children.get(e.id) ?? []).length;
143
+ if (count === 1) {
144
+ violations.push({
145
+ tier: "presentable",
146
+ code: "P-4",
147
+ message: `${e.operator} expression ${e.id} has a single child`,
148
+ argumentId: ctx.argument.id,
149
+ premiseId: e.premiseId,
150
+ expressionId: e.id,
151
+ });
152
+ }
153
+ }
154
+ return violations;
155
+ }
156
+ /**
157
+ * P-5 — No operator-of-same-type adjacency through a formula. When a
158
+ * parent operator (`and` / `or`) has a `formula` child whose only
159
+ * descendant operator (after peeling through transparent formula
160
+ * buffers) is the same operator, the inner operator should be absorbed
161
+ * into the parent.
162
+ *
163
+ * Example: `AND(formula(AND(b, c)), d)` should be `AND(b, c, d)`.
164
+ *
165
+ * The rule applies to `and` / `or` only — `implies` / `iff` are root-
166
+ * only per S-5 and cannot appear as a child operator.
167
+ */
168
+ export function validateP5(ctx) {
169
+ const violations = [];
170
+ const children = buildChildMap(ctx.expressions);
171
+ for (const parent of ctx.expressions) {
172
+ if (parent.type !== "operator")
173
+ continue;
174
+ if (parent.operator !== "and" && parent.operator !== "or")
175
+ continue;
176
+ const parentOp = parent.operator;
177
+ for (const child of children.get(parent.id) ?? []) {
178
+ if (child.type !== "formula")
179
+ continue;
180
+ const innerOp = singleOperatorInsideFormula(child, children);
181
+ if (innerOp === parentOp) {
182
+ violations.push({
183
+ tier: "presentable",
184
+ code: "P-5",
185
+ message: `${parentOp} expression ${parent.id} has a formula child ${child.id} whose inner operator is the same (${innerOp}); absorb`,
186
+ argumentId: ctx.argument.id,
187
+ premiseId: parent.premiseId,
188
+ expressionId: child.id,
189
+ });
190
+ }
191
+ }
192
+ }
193
+ return violations;
194
+ }
195
+ /**
196
+ * Returns the operator kind (`and` / `or` / `implies` / `iff`) of the
197
+ * single operator expression inside a `formula`'s bounded subtree —
198
+ * stopping at any nested formula. Returns `undefined` if the formula
199
+ * contains no operator, or more than one operator at the same level,
200
+ * or contains a `not` operator anywhere (different shape; not the
201
+ * absorption case P-5 targets).
202
+ *
203
+ * This is a deliberate simplification: P-5 fires on the canonical
204
+ * `parent(formula(sameOp(...)))` shape where the formula immediately
205
+ * wraps a single operator of the same kind as the parent. More complex
206
+ * mixed-operator-under-formula shapes are not the absorbable case.
207
+ */
208
+ function singleOperatorInsideFormula(formula, children) {
209
+ const kids = children.get(formula.id) ?? [];
210
+ if (kids.length !== 1)
211
+ return undefined;
212
+ const inner = kids[0];
213
+ if (inner.type !== "operator")
214
+ return undefined;
215
+ // Exclude `not` — P-5 targets the absorption case where the parent
216
+ // and inner operators are the same `and` / `or` / `implies` / `iff`
217
+ // kind. A NOT inside the formula is a different shape (not absorbable).
218
+ if (inner.operator === "not")
219
+ return undefined;
220
+ return inner.operator;
221
+ }
222
+ export function validatePresentable(ctx) {
223
+ return [
224
+ ...validateP1(ctx),
225
+ ...validateP2(ctx),
226
+ ...validateP3(ctx),
227
+ ...validateP4(ctx),
228
+ ...validateP5(ctx),
229
+ ];
230
+ }
231
+ //# sourceMappingURL=presentable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentable.js","sourceRoot":"","sources":["../../../../src/lib/grammar/validators/presentable.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,uCAAuC;AACvC,yBAAyB;AACzB,sCAAsC;AACtC,wEAAwE;AACxE,yCAAyC;AACzC,2DAA2D;AAK3D,OAAO,EAAE,iCAAiC,EAAE,MAAM,uBAAuB,CAAA;AAIzE;;;GAGG;AACH,SAAS,aAAa,CAClB,WAAoD;IAEpD,MAAM,GAAG,GAAc,IAAI,GAAG,EAAE,CAAA;IAChC,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAC1B,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI;YAAE,SAAQ;QACjC,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;QACtC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACZ,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IAC7B,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;QAC9B,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAA;IAChD,CAAC;IACD,OAAO,GAAG,CAAA;AACd,CAAC;AAED;;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GAAG,QAAQ,eAAe,MAAM,CAAC,EAAE,wBAAwB,KAAK,CAAC,EAAE,sCAAsC,OAAO,WAAW;oBACpI,UAAU,EAAE,GAAG,CAAC,QAAQ,CAAC,EAAE;oBAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;oBAC3B,YAAY,EAAE,KAAK,CAAC,EAAE;iBACzB,CAAC,CAAA;YACN,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,UAAU,CAAA;AACrB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,2BAA2B,CAChC,OAAqC,EACrC,QAAmB;IAEnB,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;IAC3C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IACvC,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACrB,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,SAAS,CAAA;IAC/C,mEAAmE;IACnE,oEAAoE;IACpE,wEAAwE;IACxE,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK;QAAE,OAAO,SAAS,CAAA;IAC9C,OAAO,KAAK,CAAC,QAAQ,CAAA;AACzB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAC/B,GAAsB;IAEtB,OAAO;QACH,GAAG,UAAU,CAAC,GAAG,CAAC;QAClB,GAAG,UAAU,CAAC,GAAG,CAAC;QAClB,GAAG,UAAU,CAAC,GAAG,CAAC;QAClB,GAAG,UAAU,CAAC,GAAG,CAAC;QAClB,GAAG,UAAU,CAAC,GAAG,CAAC;KACrB,CAAA;AACL,CAAC"}
@@ -0,0 +1,103 @@
1
+ import type { TViolation } from "../types.js";
2
+ import type { TValidatorContext } from "./context.js";
3
+ /**
4
+ * S-1 — FK soundness.
5
+ *
6
+ * For every entity in the context, check that its foreign-key fields
7
+ * resolve to an existing target:
8
+ * - `expression.parentId` (when non-null) resolves to another expression
9
+ * in the context.
10
+ * - Claim-bound variable's `claimId` resolves to a claim in the context.
11
+ * - Premise-bound variable's `boundPremiseId` resolves to a premise in the
12
+ * context **only when** the binding is internal
13
+ * (`boundArgumentId === argument.id`); externally-bound variables
14
+ * resolve in a different argument and are not S-1's concern.
15
+ *
16
+ * Premise `argumentId`/`argumentVersion` matching its container argument
17
+ * is checked here too (same-FK-soundness umbrella).
18
+ */
19
+ export declare function validateS1(ctx: TValidatorContext): readonly TViolation[];
20
+ /**
21
+ * S-2 — Operator types. Every expression's `type` is one of `variable`,
22
+ * `operator`, `formula`. For operator-typed expressions, the `operator`
23
+ * field is one of `not`, `and`, `or`, `implies`, `iff`.
24
+ */
25
+ export declare function validateS2(ctx: TValidatorContext): readonly TViolation[];
26
+ /**
27
+ * S-3 — Variable required reference. Every variable has either a claim ref
28
+ * or a premise ref, not both, not neither.
29
+ */
30
+ export declare function validateS3(ctx: TValidatorContext): readonly TViolation[];
31
+ /**
32
+ * S-4 — No cycles. The expression tree of every premise (parent-pointer
33
+ * graph) is acyclic.
34
+ */
35
+ export declare function validateS4(ctx: TValidatorContext): readonly TViolation[];
36
+ /**
37
+ * S-5 — Root-only IMPLIES/IFF. Within a single premise's AST, `implies`
38
+ * and `iff` may appear at most once and only at the root (parentId === null).
39
+ */
40
+ export declare function validateS5(ctx: TValidatorContext): readonly TViolation[];
41
+ /**
42
+ * S-6 — Premise type discriminator consistency. `type='derivation'`
43
+ * premises have a non-null `derivedClaimId`; `type='freeform'` premises
44
+ * have no `derivedClaimId` (or it is null/undefined).
45
+ *
46
+ * `TCoreFreeformPremise` and `TCoreDerivationPremise` are both
47
+ * `additionalProperties: true` in their TypeBox schemas, so a freeform
48
+ * premise CAN carry a stray `derivedClaimId` field at runtime even
49
+ * though the TS shape doesn't surface it. We use the `in` operator and
50
+ * a narrow shape cast to read the field as `unknown` rather than the
51
+ * earlier `as unknown` double-cast.
52
+ */
53
+ export declare function validateS6(ctx: TValidatorContext): readonly TViolation[];
54
+ /**
55
+ * S-7 — Claim type immutability. Creation-time invariant enforced by
56
+ * `ClaimLibrary.update()` via the engine-error code `CLAIM_TYPE_IMMUTABLE`.
57
+ * The AST-level validator is intentionally a no-op; callers cannot
58
+ * observe a type-mutation event from a static argument snapshot.
59
+ */
60
+ export declare function validateS7(_ctx: TValidatorContext): readonly TViolation[];
61
+ /**
62
+ * S-8 — Binary operator arity + positions. `implies` and `iff` have
63
+ * exactly 2 children, at positions `0` and `1`.
64
+ *
65
+ * One violation per binary expression. When arity is wrong the position
66
+ * check is skipped — position invariants are only meaningful for an
67
+ * exactly-2-child shape; reporting both would noise the violation list
68
+ * with the same structural problem.
69
+ */
70
+ export declare function validateS8(ctx: TValidatorContext): readonly TViolation[];
71
+ /**
72
+ * S-9 — Sibling position uniqueness. Within a single parent's children,
73
+ * no two siblings share the same `position`.
74
+ */
75
+ export declare function validateS9(ctx: TValidatorContext): readonly TViolation[];
76
+ /**
77
+ * S-10 — Entity ID uniqueness. Within an argument, premises, expressions,
78
+ * and variables each have unique IDs in their respective collection.
79
+ */
80
+ export declare function validateS10(ctx: TValidatorContext): readonly TViolation[];
81
+ /**
82
+ * S-11 — Variable symbol uniqueness. Within a single argument, no two
83
+ * variables share the same `symbol`.
84
+ */
85
+ export declare function validateS11(ctx: TValidatorContext): readonly TViolation[];
86
+ /**
87
+ * S-12 — NOT unary arity. Every `not` expression has exactly one child.
88
+ */
89
+ export declare function validateS12(ctx: TValidatorContext): readonly TViolation[];
90
+ /**
91
+ * S-13 — Formula unary arity. Every `formula` expression has exactly one
92
+ * child.
93
+ */
94
+ export declare function validateS13(ctx: TValidatorContext): readonly TViolation[];
95
+ /**
96
+ * S-14 — Derivation premise root operator. Every `type='derivation'`
97
+ * premise's root expression is one of `variable`, `implies`, or `iff`.
98
+ * (`iff` is Structurally allowed; D-1 narrows the populated form to
99
+ * `implies` only — Derivable concern.)
100
+ */
101
+ export declare function validateS14(ctx: TValidatorContext): readonly TViolation[];
102
+ export declare function validateStructural(ctx: TValidatorContext): readonly TViolation[];
103
+ //# sourceMappingURL=structural.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural.d.ts","sourceRoot":"","sources":["../../../../src/lib/grammar/validators/structural.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAGrD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAqExE;AAQD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAiCxE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CA6BxE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CA+BxE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CA8CxE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAkCxE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAEzE;AAqBD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CA+BxE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAkCxE;AAiBD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,UAAU,E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