import { type TCoreArgument, type TCoreLogicalOperatorType, type TCorePremise, type TCorePropositionalExpression, type TCorePropositionalVariable, type TOptionalChecksum } from "../schemata/index.js"; import { type TCorePositionConfig } from "../utils/position.js"; import { HierarchicalChecksumCache } from "./checksum-cache.js"; import type { TCoreQuadrivalentValue, TCoreResolvedAssignment, TCorePremiseEvaluationResult, TCoreValidationResult } from "../types/evaluation.js"; import type { TCoreMutationResult } from "../types/mutation.js"; import type { TInvariantValidationResult } from "../types/validation.js"; import { type TLogicEngineOptions } from "./argument-engine.js"; import type { TExpressionInput, TExpressionManagerSnapshot, TExpressionWithoutPosition, TExpressionUpdate } from "./expression-manager.js"; import { ExpressionManager } from "./expression-manager.js"; import { VariableManager } from "./variable-manager.js"; import type { TExpressionMutations, TExpressionQueries, TVariableReferences, TPremiseClassification, TPremiseEvaluation, TPremiseLifecycle, TPremiseIdentity, TFormulaTreeVisitor, TFormulaTreeWalking, TDisplayable, THierarchicalChecksummable } from "./interfaces/index.js"; export type TPremiseEngineSnapshot = { premise: TOptionalChecksum; rootExpressionId?: string; expressions: TExpressionManagerSnapshot; config?: TLogicEngineOptions; }; export declare class PremiseEngine extends HierarchicalChecksumCache implements TExpressionMutations, TExpressionQueries, TVariableReferences, TPremiseClassification, TPremiseEvaluation, TPremiseLifecycle, TPremiseIdentity, TDisplayable, TFormulaTreeWalking, THierarchicalChecksummable<"expressions"> { protected premise: TOptionalChecksum; protected rootExpressionId: string | undefined; protected variables: VariableManager; protected expressions: ExpressionManager; private expressionsByVariableId; private argument; private checksumConfig?; private expressionIndex?; private generateId; private onMutate?; private circularityCheck?; private emptyBoundPremiseCheck?; private variableIdsCallback?; private argumentValidateCallback?; private insideValidation; constructor(premise: TOptionalChecksum, deps: { argument: TOptionalChecksum; variables: VariableManager; expressionIndex?: Map; }, config?: TLogicEngineOptions); /** * Returns the position config in effect for this premise engine. * Used by in-package helpers (notably the native AN-4 absorption * pass in `src/lib/grammar/an-rules.ts`) that need the position * range boundaries when computing target positions for absorbed * children. * * @internal */ getPositionConfig(): TCorePositionConfig; setOnMutate(callback: (() => void) | undefined): void; setCircularityCheck(check: ((variableId: string, premiseId: string) => boolean) | undefined): void; setEmptyBoundPremiseCheck(check: ((variableId: string) => boolean) | undefined): void; setVariableIdsCallback(callback: (() => Set) | undefined): void; setArgumentValidateCallback(callback: (() => TInvariantValidationResult) | undefined): void; private premiseSnapshot; private restoreFromPremiseSnapshot; protected withValidation(fn: () => T): T; /** * Wraps a single expression mutation: opens a ChangeCollector, binds it * to the ExpressionManager for the duration of `body`, then finalizes * (checksum flush + index sync + onMutate) and returns the standard * `{ result, changes }` shape. The whole thing runs inside * `withValidation`, so Structural violations roll back and throw while * higher-tier issues surface via `validate(tier)`. */ private withExpressionMutation; deleteExpressionsUsingVariable(variableId: string): TCoreMutationResult; addExpression(expression: TExpressionInput): TCoreMutationResult; appendExpression(parentId: string | null, expression: TExpressionWithoutPosition): TCoreMutationResult; addExpressionRelative(siblingId: string, relativePosition: "before" | "after", expression: TExpressionWithoutPosition): TCoreMutationResult; updateExpression(expressionId: string, updates: TExpressionUpdate): TCoreMutationResult; removeExpression(expressionId: string, deleteSubtree: boolean): TCoreMutationResult; insertExpression(expression: TExpressionInput, leftNodeId?: string, rightNodeId?: string): TCoreMutationResult; wrapExpression(operator: TExpressionWithoutPosition, newSibling: TExpressionWithoutPosition, leftNodeId?: string, rightNodeId?: string): TCoreMutationResult; /** * Reparent an existing expression onto a new parent at the given * position. Bundled-composite mutation per spec §8 — the parent * reference, position field, and checksum-dirty propagation update * atomically in a single call. No transient orphan state is * externally observable. * * Enforces Structural rules only (S-1 FK soundness, S-4 no-cycles, * entity-not-found, and S-9 logical sibling-position uniqueness at * the bundled-composite level — same-position collisions with the * moved expression's own prior slot are tolerated as transient, * since the move atomically frees that slot). Higher-tier violations * never throw here — Evaluable/Derivable/Presentable issues surface * through `validate(tier)` per spec §7.1. * * Used by the native AN-1 (formula-buffer insertion) and AN-4 * (same-operator absorption) passes in `src/lib/grammar/an-rules.ts`, * and available to repair primitives and future composite ops that * need a public reparent surface (e.g. `removeOrphanOperators`). * * @throws If `expressionId` or `newParentId` does not exist in this * premise. * @throws S-1: if `newParent` is not an `operator` or `formula` (a * variable cannot be a parent — parity with `addExpression` * at em.ts:418-422). * @throws S-1: arity — if reparenting would push `newParent`'s * child count past its operator-specific limit (unary `not` * max 1; binary `implies`/`iff` max 2). Same-parent moves * leave count unchanged and bypass this check. * @throws S-4: if `newParentId === expressionId` or `newParentId` is * a descendant of `expressionId`. * @throws S-9: if another sibling (NOT the expression being moved) * already occupies `newPosition` under `newParentId`. * * @since 1.0.0 */ reparentExpression(expressionId: string, newParentId: string, newPosition: number): TCoreMutationResult; /** * Wrap an existing expression in a freshly-minted `formula` node * atomically. The formula takes the child's original parent slot * (parentId + position); the child becomes the formula's sole * child at position 0. Bundled-composite mutation per spec §8. * * Used by the native AN-1 (formula-buffer insertion) pass in * `src/lib/grammar/an-rules.ts`. Composing this from * `addExpression` + `reparentExpression` is not possible: the * intermediate state would either (a) violate S-9 with the child * still occupying the formula's target slot, or (b) trip the * parent's `assertChildLimit` (unary `not`, binary * `implies`/`iff`) even though the *net* child count of the parent * is unchanged after the wrap. * * The new formula's id is minted via the engine's `idGenerator` * accessor and returned in the mutation result. Argument fields * (`argumentId`, `argumentVersion`, `premiseId`) are inherited * from the source child. * * @throws If `childId` does not exist in this premise. * @throws If `childId` is at the root (no parent to insert a * buffer beneath). * @throws S-10: if `formulaId` is already used by an existing * expression in this premise (entity-ID uniqueness). * * @since 1.0.0 */ wrapInFormula(childId: string, formulaId: string): TCoreMutationResult; /** * Returns true iff `candidateId` is a descendant of `ancestorId` in * this premise's expression tree. Used by `reparentExpression` for * the S-4 no-cycles check. */ private isDescendantOf; toggleNegation(expressionId: string, extraFields?: Partial): TCoreMutationResult; changeOperator(expressionId: string, newOperator: TCoreLogicalOperatorType, sourceChildId?: string, targetChildId?: string, extraFields?: Partial): TCoreMutationResult; getExpression(id: string): TExpr | undefined; /** * Internal helper: mutates an expression in place and marks it dirty. * Used by `ArgumentEngine.patchExpressionAppFields` to implement the * atomic patch-and-mark contract without reaching into internals from * outside the engine. * * @internal */ patchAndMarkExpression(expressionId: string, fields: Partial): void; getId(): string; getExtras(): Record; setExtras(extras: Record): TCoreMutationResult, TExpr, TVar, TPremise, TArg>; updateExtras(updates: Record): TCoreMutationResult, TExpr, TVar, TPremise, TArg>; getRootExpressionId(): string | undefined; getRootExpression(): TExpr | undefined; getVariables(): TVar[]; getExpressions(): TExpr[]; getChildExpressions(parentId: string | null): TExpr[]; getPremiseType(): string; isInference(): boolean; isConstraint(): boolean; validateEvaluability(): TCoreValidationResult; evaluate(assignment: TCoreResolvedAssignment, options?: { strictUnknownKeys?: boolean; requireExactCoverage?: boolean; resolver?: (variableId: string) => TCoreQuadrivalentValue; }): TCorePremiseEvaluationResult; toDisplayString(): string; walkFormulaTree(visitor: TFormulaTreeVisitor): T; getDecidableOperatorExpressions(): TExpr[]; getReferencedVariableIds(): Set; toPremiseData(): TPremise; getCollectionChecksum(_name: "expressions"): string | null; flushChecksums(): void; validate(): TInvariantValidationResult; /** * Loads expressions in BFS order with the nesting check bypassed. * Bypasses all PremiseEngine validation (ownership, variable existence, circularity) * since restoration paths trust existing data completely. */ loadExpressions(expressions: TExpressionInput[]): void; markDirty(): void; /** * Re-reads the single root from ExpressionManager after any operation * that may have caused operator collapse to silently change the root. */ private syncRootExpressionId; private collectSubtree; private assertBelongsToArgument; private assertVariableExpressionValid; private renderExpression; private walkExpression; private operatorSymbol; snapshot(): TPremiseEngineSnapshot; /** Creates a new PremiseEngine from a previously captured snapshot. */ static fromSnapshot(snapshot: TPremiseEngineSnapshot, argument: TOptionalChecksum, variables: VariableManager, expressionIndex?: Map, generateId?: () => string): PremiseEngine; /** * Flushes hierarchical expression checksums and rebuilds the changeset * so that added/modified expressions carry correct `descendantChecksum` * and `combinedChecksum` values (rather than the stale ones captured * at mutation time by the ChangeCollector). */ private finalizeExpressionMutation; private flushAndBuildChangeset; private syncExpressionIndex; /** * Records a newly-added variable expression in the by-variable index. * No-op for non-variable expressions. Mirrors the per-variable entry * that `rebuildVariableIndex` produces on bulk load. */ private indexVariableExpression; private rebuildVariableIndex; } //# sourceMappingURL=premise-engine.d.ts.map