open-agreements
Version:
Open-source legal template filling CLI and library
66 lines • 2.77 kB
TypeScript
export interface BracketNormalizationStats {
unbracketedSegments: number;
removedSegments: number;
removedParagraphs: number;
normalizedParagraphs: number;
formattingFallbackCount: number;
declarativeRuleApplications: number;
declarativeRuleMatchCounts: Record<string, number>;
declarativeRuleMutationCounts: Record<string, number>;
declarativeRuleExpectationFailures: string[];
declarativeRuleExamples: Array<{
rule_id: string;
heading: string;
before: string;
after: string;
}>;
}
export interface DeclarativeParagraphNormalizeRule {
id: string;
section_heading: string;
section_heading_any?: string[];
ignore_heading?: boolean;
paragraph_contains: string;
paragraph_end_contains?: string;
replacements?: Record<string, string>;
trim_unmatched_trailing_bracket?: boolean;
expected_min_matches?: number;
expected_max_matches?: number;
}
export interface DeclarativeNormalizeConfig {
paragraph_rules: DeclarativeParagraphNormalizeRule[];
}
export interface BracketNormalizationOptions {
rules?: DeclarativeParagraphNormalizeRule[];
fieldValues?: Record<string, unknown>;
blankPlaceholder?: string;
}
/**
* Normalize residual bracket artifacts in generated fieldSelector documents.
*
* Only operates when declarative rules are provided (via normalize.json).
* Without declarative rules, returns zero-change stats (no-op).
* Uses formatting-preserving replaceParagraphTextRange for all text mutations.
*/
export declare function normalizeBracketArtifacts(inputPath: string, outputPath: string, options?: BracketNormalizationOptions): Promise<BracketNormalizationStats>;
/** A single disjoint edit: replace oldText[start, end) with `replacement`. */
export interface EditHunk {
start: number;
end: number;
replacement: string;
}
/**
* Return exact deletion hunks when `newText` is a subsequence of `oldText`.
* The leftmost embedding is deterministic and, unlike a wide replacement,
* never crosses text that survives the transformation (including REF field
* results). The caller still verifies the reconstructed text before mutation.
*/
export declare function computeDeletionHunks(oldText: string, newText: string, offset?: number): EditHunk[] | null;
/**
* Compute DISJOINT edit hunks turning `oldText` into `newText`, in ascending
* `start` order. Exact codepoint LCS retains even one-character interior anchors;
* returned offsets remain UTF-16 offsets for the DOCX mutation API. Ties prefer
* deletion, making repeated-text alignment deterministic.
*/
export declare function computeEditHunks(oldText: string, newText: string, offset?: number): EditHunk[];
//# sourceMappingURL=bracket-normalizer.d.ts.map