import type { CompiledRule, DiffAddition, FailSoftAttestation, RuleEventCallback, Violation } from './compiler-schema.js'; import { fileMatchesGlobs, matchesGlob } from './sys/glob.js'; export { fileMatchesGlobs, matchesGlob }; /** * Detect whether a rule is a production-only Rust rule. * A rule is production-only Rust if it applies to `.rs` files and explicitly * excludes tests, or does not explicitly target tests. */ export declare function isProductionRustRule(rule: CompiledRule): boolean; /** * Parses Rust content to find line ranges (spans) for inline `#[cfg(test)]` modules. * Returns an array of `{ startLine: number; endLine: number }` representing the spans. */ export declare function getRustTestSpans(content: string): { startLine: number; endLine: number; }[]; /** Injectable logger for core library diagnostics. */ export interface CoreLogger { warn(message: string): void; } /** * Per-invocation execution context for the rule engine (mmnto/totem#1441). * Replaces module-level `coreLogger` + `shieldContextDeprecationWarned` state * so concurrent / federated rule evaluations cannot bleed logger configuration * or deprecation-warning latching across each other. Callers instantiate one * ctx per linting invocation; the engine threads it through every helper that * can reach the legacy `shield-context:` directive path. */ export interface RuleEngineContext { logger: CoreLogger; state: { hasWarnedShieldContext: boolean; }; } export declare function isSuppressed(ctx: RuleEngineContext, line: string, precedingLine: string | null): boolean; /** * Extract justification text from totem-context: directives. * Checks both the current line and the preceding line. * Returns empty string for plain totem-ignore (no justification). * * @param ctx - Per-invocation rule engine context. Required so that the legacy * `shield-context:` deprecation path (reached via `matchContextDirective`) * uses the caller's logger and per-ctx latch instead of module state. * @param line - The line being evaluated. * @param precedingLine - The line immediately before, or null at start of file. * @returns The justification text, or empty string if the line carries a plain * `totem-ignore` or no directive at all. */ export declare function extractJustification(ctx: RuleEngineContext, line: string, precedingLine: string | null): string; /** * Parse a `// totem-context:` justification as a Tenet-4 shape-2 fail-soft * attestation. Returns null unless the justification LEADS with `fail-soft`. * A leading `fail-soft` with a non-empty `backstop=` yields the named * backstop; a leading `fail-soft` with no/empty backstop yields * `{ backstop: null }` (malformed — callers surface a non-blocking WARN, never * block: the lint establishes token-PRESENCE only, loudness + accounting are * verified at review/ADR level — Tenet 13/19). */ export declare function parseFailSoftAttestation(justification: string): FailSoftAttestation | null; /** * Apply compiled regex-engine rules against pre-extracted diff additions. * Skips additions with non-code AST context (strings, comments, regex). * * @param ctx - Per-invocation rule engine context. Replaces the module-level * logger / deprecation-warning latch that existed pre-#1441. Callers build * one ctx per linting invocation: `{ logger, state: { hasWarnedShieldContext: false } }`. * @param rules - The full rule list. This function filters to regex-engine * rules internally. * @param additions - The diff additions to evaluate. * @param onRuleEvent - Optional observability callback for metrics collection * on trigger / suppress / failure events. * @param workingDirectory - Optional working directory for resolving files on disk * when parsing spans. * @param readFileText - Optional SYNC reader for whole-file content, consulted * only by a Prop 310 `requires: {scope: file}` check. Returns `null` when the * file cannot be resolved; when omitted, the disk is read directly. * * SYNC, unlike the ast path's async `readStrategy`, because this function is * synchronous and four shipped callers depend on that. The async staged reader * is threaded instead through `applyRulesToAdditionsBounded`, which is the * dispatcher `totem lint` actually uses for regex rules and is already async — * so the staged guarantee lands where staged mode exists (falsification round, * 2026-08-21). * @returns All regex-based violations found. */ export declare function applyRulesToAdditions(ctx: RuleEngineContext, rules: CompiledRule[], additions: DiffAddition[], onRuleEvent?: RuleEventCallback, workingDirectory?: string, readFileText?: (filePath: string) => string | null): Violation[]; /** * Apply AST-engine compiled rules against pre-extracted diff additions. * Handles both Tree-sitter S-expression ('ast') and ast-grep ('ast-grep') engines. * Async because it reads files and runs Tree-sitter queries. * Handles fileGlobs filtering and suppression same as regex rules. * * @param ctx - Per-invocation rule engine context (see {@link RuleEngineContext}). * @param rules - The full rule list. This function filters to ast / ast-grep * rules internally. * @param additions - The diff additions to evaluate. * @param workingDirectory - Absolute path used to resolve file reads. Callers * must pass the repo root, not `process.cwd()` (#1304). * @param onRuleEvent - Optional observability callback for trigger / suppress * / failure events. * @param onWarn - Optional AST-path warning sink ("AST query skipped", * "Skipped file outside project", etc.). Follow-up #1552 tracks consolidating * this into `ctx.logger.warn`. * @param readStrategy - Optional async reader for staged / virtual file * content. When omitted, reads from disk. * @returns All AST-based violations found. */ export declare function applyAstRulesToAdditions(ctx: RuleEngineContext, rules: CompiledRule[], additions: DiffAddition[], workingDirectory: string, onRuleEvent?: RuleEventCallback, onWarn?: (msg: string) => void, readStrategy?: (filePath: string) => Promise): Promise; /** * Apply **regex-engine** compiled rules against added lines from a diff. * This is a convenience wrapper that only handles 'regex' engine rules. * For 'ast' and 'ast-grep' rules, call `applyAstRulesToAdditions` separately. * * @param ctx - Per-invocation rule engine context (see {@link RuleEngineContext}). * @param rules - The full list of compiled rules. This function filters to regex rules. * @param diff - The unified diff string. * @param excludeFiles - File paths to skip (e.g., compiled-rules.json to avoid self-matches). * @returns All regex-based violations found. */ export declare function applyRules(ctx: RuleEngineContext, rules: CompiledRule[], diff: string, excludeFiles?: string[]): Violation[]; //# sourceMappingURL=rule-engine.d.ts.map