import type { NapiConfig } from '@ast-grep/napi'; import { Lang } from '@ast-grep/napi'; /** ast-grep pattern: either a simple string or a full NapiConfig rule object */ export type AstGrepRule = string | NapiConfig; export interface AstGrepMatch { lineNumber: number; lineText: string; /** * Suppression anchor: the matched construct's start line text and the line * immediately above it. The inline-directive convention (mmnto-ai/totem#1889) * attaches `// totem-ignore` / `// totem-context:` to the construct's start * line or the line above it, but `lineNumber` is the first *added* line * within the node's range — under diff scope it can drift into the construct * body, off the start line, so a directive on the start line is otherwise * missed (mmnto-ai/totem#2214). Consumers check this anchor in addition to * the reported line. */ startLineText: string; startPrecedingLineText: string | null; } /** * Map a file extension to the ast-grep dispatch language label. Registry- * backed via `extensionToLanguage` from ast-classifier.ts (mmnto-ai/totem#1653, * #1654) — built-in extensions map to napi `Lang` enum values; pack- * registered extensions map to their NapiLang custom string per * ADR-097 § 10. */ export declare function extensionToLang(ext: string): Lang | string | undefined; /** * Trailing-extension capture for glob/path strings (`/foo/bar.rs` → `rs`). * Exported so compile-smoke-gate.ts shares the single source of truth for * extracting target extensions out of `fileGlobs` (mmnto-ai/totem#1654). */ export declare const TRAILING_EXT_RE: RegExp; /** * Resolve the ast-grep Lang dispatch list for a rule's `fileGlobs`. Used by * the compile-time pattern validator (`validateAstGrepPattern`) to parse * the pattern under the rule's actual target grammar instead of always * defaulting to TSX (mmnto-ai/totem#1654). * * Returns the deduplicated list of registered Lang values mapped from each * positive glob's trailing extension. Negation globs are skipped (they * describe files the rule should NOT match). When no positive glob carries * a registered extension — including the unscoped-rule case where * `fileGlobs` is undefined or empty — falls back to `[Lang.Tsx]` to * preserve the legacy permissive-default behavior. Lang.Tsx remains the * "unscoped" parser because it is the broadest TS/JS superset and many * pre-1.16 rules ship without globs. */ export declare function resolveAstGrepLangs(fileGlobs?: readonly string[]): (Lang | string)[]; /** * Per-rule failure sink. Invoked when `findAll` throws inside a batch. The * index is the position of the failing query in the original input array so * the caller can map the failure back to a `CompiledRule`. Introduced in * mmnto/totem#1408 to fulfil spike finding G-7: one malformed compound rule * must not blast-radius the whole file's ast-grep pass. */ export type OnRuleFailure = (index: number, err: Error) => void; /** * Run an ast-grep pattern against file content, filtering to added lines. * Accepts either a string pattern or a NapiConfig rule object (compound rules). */ export declare function matchAstGrepPattern(content: string, ext: string, pattern: AstGrepRule, addedLineNumbers: number[]): AstGrepMatch[]; /** * Parse a file once and run multiple ast-grep rules against it. * O(M + N) - file parsed exactly once regardless of rule count. * Returns results indexed by position in the input array. * * When `onRuleFailure` is passed, each per-rule `findAll` call runs inside * its own try/catch (spike finding G-7, mmnto/totem#1408): a malformed * compound rule emits a failure event, yields an empty result array for * that index, and the remaining rules continue to execute. Without the * sink, the legacy fail-closed behavior holds - the first per-rule failure * aborts the whole batch via `TotemParseError`. * * The parse-time failure (invalid source, unsupported language) still * escapes via `rethrowAsParseError` regardless of the sink, because a parse * error affects every query on the file and there is no way to produce * honest per-rule results from a broken tree. */ export declare function matchAstGrepPatternsBatch(content: string, ext: string, queries: Array<{ rule: AstGrepRule; addedLineNumbers: number[]; }>, onRuleFailure?: OnRuleFailure): AstGrepMatch[][]; //# sourceMappingURL=ast-grep-query.d.ts.map