@proposit/proposit-core 0.10.0 → 0.11.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.
Files changed (67) hide show
  1. package/README.md +88 -9
  2. package/dist/cli/commands/premises.d.ts.map +1 -1
  3. package/dist/cli/commands/premises.js +82 -5
  4. package/dist/cli/commands/premises.js.map +1 -1
  5. package/dist/cli/commands/render.d.ts.map +1 -1
  6. package/dist/cli/commands/render.js +2 -1
  7. package/dist/cli/commands/render.js.map +1 -1
  8. package/dist/cli/engine.d.ts.map +1 -1
  9. package/dist/cli/engine.js +3 -0
  10. package/dist/cli/engine.js.map +1 -1
  11. package/dist/cli/import.d.ts.map +1 -1
  12. package/dist/cli/import.js +70 -13
  13. package/dist/cli/import.js.map +1 -1
  14. package/dist/cli/storage/migrate-v0.11.d.ts +15 -0
  15. package/dist/cli/storage/migrate-v0.11.d.ts.map +1 -0
  16. package/dist/cli/storage/migrate-v0.11.js +125 -0
  17. package/dist/cli/storage/migrate-v0.11.js.map +1 -0
  18. package/dist/extensions/basics/schemata.d.ts +11 -1
  19. package/dist/extensions/basics/schemata.d.ts.map +1 -1
  20. package/dist/lib/consts.d.ts.map +1 -1
  21. package/dist/lib/consts.js +6 -1
  22. package/dist/lib/consts.js.map +1 -1
  23. package/dist/lib/core/argument-engine.d.ts +39 -1
  24. package/dist/lib/core/argument-engine.d.ts.map +1 -1
  25. package/dist/lib/core/argument-engine.js +202 -11
  26. package/dist/lib/core/argument-engine.js.map +1 -1
  27. package/dist/lib/core/interfaces/argument-engine.interfaces.d.ts +132 -7
  28. package/dist/lib/core/interfaces/argument-engine.interfaces.d.ts.map +1 -1
  29. package/dist/lib/core/interfaces/library.interfaces.d.ts +13 -0
  30. package/dist/lib/core/interfaces/library.interfaces.d.ts.map +1 -1
  31. package/dist/lib/core/managed-derivation-premise-engine.d.ts +155 -0
  32. package/dist/lib/core/managed-derivation-premise-engine.d.ts.map +1 -0
  33. package/dist/lib/core/managed-derivation-premise-engine.js +517 -0
  34. package/dist/lib/core/managed-derivation-premise-engine.js.map +1 -0
  35. package/dist/lib/core/premise-engine.d.ts +6 -5
  36. package/dist/lib/core/premise-engine.d.ts.map +1 -1
  37. package/dist/lib/core/premise-engine.js +5 -3
  38. package/dist/lib/core/premise-engine.js.map +1 -1
  39. package/dist/lib/core/proposit-core.d.ts.map +1 -1
  40. package/dist/lib/core/proposit-core.js +14 -0
  41. package/dist/lib/core/proposit-core.js.map +1 -1
  42. package/dist/lib/index.d.ts +3 -0
  43. package/dist/lib/index.d.ts.map +1 -1
  44. package/dist/lib/index.js +2 -0
  45. package/dist/lib/index.js.map +1 -1
  46. package/dist/lib/schemata/import.d.ts +39 -2
  47. package/dist/lib/schemata/import.d.ts.map +1 -1
  48. package/dist/lib/schemata/import.js +22 -1
  49. package/dist/lib/schemata/import.js.map +1 -1
  50. package/dist/lib/schemata/propositional.d.ts +32 -1
  51. package/dist/lib/schemata/propositional.d.ts.map +1 -1
  52. package/dist/lib/schemata/propositional.js +17 -2
  53. package/dist/lib/schemata/propositional.js.map +1 -1
  54. package/dist/lib/types/evaluation.d.ts +1 -1
  55. package/dist/lib/types/evaluation.d.ts.map +1 -1
  56. package/dist/lib/types/validation.d.ts +10 -0
  57. package/dist/lib/types/validation.d.ts.map +1 -1
  58. package/dist/lib/types/validation.js +11 -0
  59. package/dist/lib/types/validation.js.map +1 -1
  60. package/dist/lib/utils/derivation-validation.d.ts +24 -0
  61. package/dist/lib/utils/derivation-validation.d.ts.map +1 -0
  62. package/dist/lib/utils/derivation-validation.js +107 -0
  63. package/dist/lib/utils/derivation-validation.js.map +1 -0
  64. package/dist/lib/utils/lookup.d.ts.map +1 -1
  65. package/dist/lib/utils/lookup.js +1 -0
  66. package/dist/lib/utils/lookup.js.map +1 -1
  67. package/package.json +1 -1
@@ -0,0 +1,155 @@
1
+ import { type TCoreArgument, type TCoreLogicalOperatorType, type TCorePremise, type TCorePropositionalExpression, type TCorePropositionalVariable, type TOptionalChecksum, type TClaimBoundVariable } from "../schemata/index.js";
2
+ import { PremiseEngine, type TPremiseEngineSnapshot } from "./premise-engine.js";
3
+ import { VariableManager } from "./variable-manager.js";
4
+ import { type TLogicEngineOptions } from "./argument-engine.js";
5
+ /**
6
+ * Minimal structural interface needed by `populateFromCitations`. Using a
7
+ * structural type rather than the concrete `ArgumentEngine<…>` class prevents
8
+ * generic-parameter variance errors when the caller uses default type params.
9
+ */
10
+ export type TVariableMaterializer = {
11
+ ensureClaimBoundVariable(claimId: string): TClaimBoundVariable;
12
+ };
13
+ import { type TGrammarConfig } from "../types/grammar.js";
14
+ import type { TExpressionInput, TExpressionWithoutPosition, TExpressionUpdate } from "./expression-manager.js";
15
+ import type { TCoreMutationResult } from "../types/mutation.js";
16
+ import type { ClaimCitationLibrary } from "./claim-citation-library.js";
17
+ /**
18
+ * A managed engine for derivation premises that enforces structural rules
19
+ * from the v0.11.0 spec on construction and on snapshot restoration.
20
+ *
21
+ * Construction validates the premise type (`DERIVATION_TYPE_MISMATCH` if the
22
+ * premise isn't `type: "derivation"`). Full expression-tree structural
23
+ * validation (`DERIVATION_STRUCTURE_INVALID`) runs in `fromSnapshot` — after
24
+ * expressions are loaded — and will be called from mutation overrides in
25
+ * Task 6.
26
+ *
27
+ * Note: The constructor only validates the premise type, not the expression
28
+ * tree, because `PremiseEngine` is always constructed before expressions are
29
+ * loaded (expressions are added separately via mutations or `loadExpressions`).
30
+ * Structural validation at the end of `fromSnapshot` catches tampered
31
+ * snapshots, and Task 6 mutation overrides will enforce it on every change.
32
+ *
33
+ * The classic `PremiseEngine` is permissive and allows mutations that leave a
34
+ * derivation premise temporarily or permanently invalid. The managed engine
35
+ * wraps it for safe, structurally-enforced editing.
36
+ *
37
+ * Use `ManagedDerivationPremiseEngine.fromSnapshot(...)` to restore from a
38
+ * serialized snapshot — the validation pass catches tampered snapshots.
39
+ */
40
+ export declare class ManagedDerivationPremiseEngine<TArg extends TCoreArgument = TCoreArgument, TPremise extends TCorePremise = TCorePremise, TExpr extends TCorePropositionalExpression = TCorePropositionalExpression, TVar extends TCorePropositionalVariable = TCorePropositionalVariable> extends PremiseEngine<TArg, TPremise, TExpr, TVar> {
41
+ /**
42
+ * Captured from `config.generateId` (or the default UUID generator) for
43
+ * use in `populateFromCitations`, which needs to mint new expression IDs.
44
+ * Stored separately because `PremiseEngine`'s generateId is private.
45
+ * Not `readonly` because `fromSnapshot` re-injects it after the prototype
46
+ * upgrade.
47
+ */
48
+ private generateIdFn;
49
+ constructor(premise: TOptionalChecksum<TPremise>, deps: {
50
+ argument: TOptionalChecksum<TArg>;
51
+ variables: VariableManager<TVar>;
52
+ expressionIndex?: Map<string, string>;
53
+ }, config?: TLogicEngineOptions);
54
+ /**
55
+ * Restore a `ManagedDerivationPremiseEngine` from a serialized snapshot,
56
+ * applying both derivation-type and structural validation. Throws on
57
+ * tampered or structurally invalid snapshots.
58
+ *
59
+ * Delegates to `PremiseEngine.fromSnapshot` for the full restoration logic
60
+ * (including the private `rebuildVariableIndex` pass), then upgrades the
61
+ * prototype and validates. TypeScript's static methods do not support
62
+ * `super`, so the parent is called by name and the result is recast.
63
+ */
64
+ static fromSnapshot<TArg extends TCoreArgument = TCoreArgument, TPremise extends TCorePremise = TCorePremise, TExpr extends TCorePropositionalExpression = TCorePropositionalExpression, TVar extends TCorePropositionalVariable = TCorePropositionalVariable>(snapshot: TPremiseEngineSnapshot<TPremise, TExpr>, argument: TOptionalChecksum<TArg>, variables: VariableManager<TVar>, expressionIndex?: Map<string, string>, grammarConfig?: TGrammarConfig, generateId?: () => string): ManagedDerivationPremiseEngine<TArg, TPremise, TExpr, TVar>;
65
+ /**
66
+ * Validate that the wrapped premise has `type === "derivation"`.
67
+ * @throws InvariantViolationError with code `DERIVATION_TYPE_MISMATCH`
68
+ */
69
+ protected assertDerivationType(): void;
70
+ /**
71
+ * Validate that the expression tree conforms to the derivation rules from
72
+ * the v0.11.0 spec (naked-Q or IMPLIES/IFF with Q as consequent).
73
+ * @throws InvariantViolationError with code `DERIVATION_STRUCTURE_INVALID`
74
+ */
75
+ protected assertWellFormed(): void;
76
+ addExpression(expression: TExpressionInput<TExpr>): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
77
+ appendExpression(parentId: string | null, expression: TExpressionWithoutPosition<TExpr>): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
78
+ addExpressionRelative(siblingId: string, relativePosition: "before" | "after", expression: TExpressionWithoutPosition<TExpr>): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
79
+ updateExpression(expressionId: string, updates: TExpressionUpdate): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
80
+ removeExpression(expressionId: string, deleteSubtree: boolean): TCoreMutationResult<TExpr | undefined, TExpr, TVar, TPremise, TArg>;
81
+ insertExpression(expression: TExpressionInput<TExpr>, leftNodeId?: string, rightNodeId?: string): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
82
+ toggleNegation(expressionId: string, extraFields?: Partial<TExpr>): TCoreMutationResult<TExpr | null, TExpr, TVar, TPremise, TArg>;
83
+ wrapExpression(operator: TExpressionWithoutPosition<TExpr>, newSibling: TExpressionWithoutPosition<TExpr>, leftNodeId?: string, rightNodeId?: string): TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>;
84
+ changeOperator(expressionId: string, newOperator: TCoreLogicalOperatorType, sourceChildId?: string, targetChildId?: string, extraFields?: Partial<TExpr>): TCoreMutationResult<TExpr | null, TExpr, TVar, TPremise, TArg>;
85
+ normalizeExpressions(): TCoreMutationResult<void, TExpr, TVar, TPremise, TArg>;
86
+ loadExpressions(expressions: TExpressionInput<TExpr>[]): void;
87
+ /**
88
+ * One-shot snapshot helper that builds the antecedent of this derivation
89
+ * premise from the current global citations of the derived claim.
90
+ *
91
+ * Behavior by citation count:
92
+ * - n = 0: no change. Premise stays in its current form (typically
93
+ * naked-Q, indicating "no support given").
94
+ * - n = 1: produces `IMPLIES(VariableExpression(S1), VariableExpression(Q))`.
95
+ * - n ≥ 2: produces `IMPLIES(OR(VariableExpression(S1), …,
96
+ * VariableExpression(Sn)), VariableExpression(Q))`.
97
+ *
98
+ * Materializes a claim-bound variable for each cited source via
99
+ * `argumentEngine.ensureClaimBoundVariable(citation.sourceClaimId)`.
100
+ *
101
+ * **Tree construction approach:** Mutations are performed via `super.*`
102
+ * calls, bypassing this class's overrides (which call `assertWellFormed()`
103
+ * after every mutation and would reject intermediate states during
104
+ * multi-step construction). For n ≥ 2 the grammar is temporarily switched
105
+ * to `PERMISSIVE_GRAMMAR_CONFIG` so that the OR operator can sit directly
106
+ * under IMPLIES without triggering an auto-inserted formula buffer. The
107
+ * grammar is restored and `assertWellFormed()` is called at the end to
108
+ * validate the final state.
109
+ *
110
+ * @throws InvariantViolationError(DERIVATION_ANTECEDENT_NON_EMPTY) when the
111
+ * derivation premise already has a non-empty antecedent (i.e., the
112
+ * root is `implies`/`iff` with a position-0 child). The caller
113
+ * decides whether to delete and re-create the premise.
114
+ *
115
+ * @since 0.11.0
116
+ */
117
+ populateFromCitations(citationLib: ClaimCitationLibrary, argumentEngine: TVariableMaterializer): void;
118
+ /**
119
+ * Returns the ID of the consequent expression, or `undefined` if the tree
120
+ * has no root yet.
121
+ *
122
+ * - Naked form (root is a variable expression): the root IS the consequent.
123
+ * - Implication/biconditional form (root is `implies`/`iff`): the position-1
124
+ * child of the root is the consequent.
125
+ */
126
+ private getConsequentExpressionId;
127
+ /**
128
+ * Reject an `insertExpression` call that would place a new node into the
129
+ * consequent slot of the root `implies`/`iff`.
130
+ *
131
+ * Detection is by parentId + position on the input: we block when
132
+ * `expression.parentId === rootId` AND `expression.position >= consequent.position`.
133
+ * For `implies`/`iff` the consequent sits at position 1, so this blocks
134
+ * insertions into position 1 (which would displace the consequent) and
135
+ * positions beyond (which would exceed arity 2). Insertions at position 0
136
+ * (antecedent slot) pass through.
137
+ */
138
+ private assertNotConsequentSlot;
139
+ /**
140
+ * Reject `removeExpression` and `toggleNegation` calls on the consequent
141
+ * expression.
142
+ */
143
+ private assertNotConsequentExpression;
144
+ /**
145
+ * Reject `updateExpression` calls that change the consequent's `variableId`
146
+ * or `type`.
147
+ */
148
+ private assertConsequentNotMutated;
149
+ /**
150
+ * Reject `changeOperator` calls that would swap the root `implies`/`iff`
151
+ * to a non-implication operator (`and`, `or`, `not`).
152
+ */
153
+ private assertRootOperatorChangeValid;
154
+ }
155
+ //# sourceMappingURL=managed-derivation-premise-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managed-derivation-premise-engine.d.ts","sourceRoot":"","sources":["../../../src/lib/core/managed-derivation-premise-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,aAAa,EAElB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAC3B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,aAAa,EAAE,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAEH,KAAK,mBAAmB,EAC3B,MAAM,sBAAsB,CAAA;AAE7B;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAChC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CAAA;CACjE,CAAA;AACD,OAAO,EAEH,KAAK,cAAc,EACtB,MAAM,qBAAqB,CAAA;AAU5B,OAAO,KAAK,EACR,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EACpB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAEvE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,8BAA8B,CACvC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