import { createHash } from 'node:crypto';
export const WHOLE_DIFF_TRIVIA_POLICY_VERSION = 1;
const DIRECTIVE_PATTERNS = Object.freeze([
    {
        id: 'typescript-control',
        pattern: String.raw `(?:^|[^\w])@ts-(?:check|nocheck|ignore|expect-error)\b|^\s*///\s*<(?:reference|amd-module|amd-dependency)\b`,
        flags: 'iu',
    },
    {
        id: 'formatter-linter-control',
        pattern: String.raw `(?:eslint|biome|prettier|stylelint|clang-format|rustfmt|ktlint|spotless|swiftlint|formatter)(?:\s*[-:]|\s+(?:disable|enable|ignore|off|on|skip|format)\b|\s+[\w@/-]+\s*:)`,
        flags: 'iu',
    },
    {
        id: 'coverage-control',
        pattern: String.raw `(?:istanbul|c8|nyc|v8)\s+(?:ignore|disable|enable|skip|off|on|next|file|start|stop)\b|coverage\s*:\s*(?:ignore|disable|enable|off|on|next|file|line|start|stop)\b|pragma:\s*no\s*cover\b`,
        flags: 'iu',
    },
    {
        id: 'bundler-purity-control',
        pattern: String.raw `(?:__PURE__|#__PURE__|@__PURE__|__NO_SIDE_EFFECTS__|@__NO_SIDE_EFFECTS__|webpack(?:ChunkName|Mode|Prefetch|Preload|Ignore|FetchPriority|Exports|Include|Exclude)|vite-ignore|rollup(?:Plugin|Ignore)?\b)`,
        flags: 'iu',
    },
    {
        id: 'docblock-pragma-control',
        pattern: String.raw `@jest-environment\b|@jsx(?:Runtime|ImportSource|Frag)?\b|@flow\b`,
        flags: 'iu',
    },
    {
        id: 'c-preprocessor-in-comment',
        pattern: String.raw `#\s*cgo\b|#\s*include\s*[<"]`,
        flags: 'iu',
    },
    {
        id: 'source-location-control',
        pattern: String.raw `[#@]\s*source(?:MappingURL|URL)\s*=`,
        flags: 'iu',
    },
    {
        id: 'go-control',
        pattern: String.raw `^\s*//\s*(?:go:(?:build|generate|embed|linkname|nosplit|noescape|systemstack|uintptrescapes|wasmimport|wasmexport)|\+build)\b`,
        flags: 'iu',
    },
    {
        id: 'python-control',
        pattern: String.raw `(?:^\s*#\s*(?:coding\s*[:=]|-\*-\s*coding\s*:|type\s*:|noqa\b|mypy\s*:|pyright\s*:|pylint\s*:)|#\s*(?:fmt|isort|ruff)\s*:\s*(?:off|on|skip))`,
        flags: 'iu',
    },
    {
        id: 'ruby-control',
        pattern: String.raw `^\s*#\s*(?:encoding|coding|frozen_string_literal|warn_indent|shareable_constant_value|typed)\s*[:=]`,
        flags: 'iu',
    },
    {
        id: 'compiler-tool-control',
        pattern: String.raw `(?:noinspection|spotbugs|checkstyle|sourcery|scalafmt|scalafix|language\s*=|#\s*(?:region|endregion)\b|//\s*(?:region|endregion)\b)`,
        flags: 'iu',
    },
]);
const SAFE_WHITESPACE_GRAMMARS = Object.freeze([
    'c-sharp',
    'go',
    'java',
    'javascript',
    'kotlin',
    'ruby',
    'rust',
    'scala',
    'tsx',
    'typescript',
]);
const UNSAFE_WHITESPACE_GRAMMARS = Object.freeze(['c', 'cpp', 'php', 'swift']);
/**
 * Exact policy carried by `whole-file-cst-v4` receipts.
 *
 * The grammar manifest remains unchanged because entity lineage also consumes
 * it. This separately versioned policy controls only whole-diff trivia
 * admission and can therefore evolve without changing entity cache identity.
 */
export const WHOLE_DIFF_TRIVIA_POLICY = Object.freeze({
    version: WHOLE_DIFF_TRIVIA_POLICY_VERSION,
    proof: 'whole-file-cst-v4',
    whitespace: Object.freeze({
        safeGrammars: SAFE_WHITESPACE_GRAMMARS,
        conditionalGrammars: Object.freeze({ python: 'line-break-and-leading-indent-profile-equal' }),
        unsafeGrammars: UNSAFE_WHITESPACE_GRAMMARS,
    }),
    comments: Object.freeze({
        ordinary: 'cosmetic-change',
        directive: 'unknown',
        directiveScope: 'any-recognized-directive-in-either-revision',
        directiveEffect: 'blocks-cosmetic-admission-only',
        unsafeGrammarAdmission: 'comment-shape-and-all-non-comment-bytes-equal',
    }),
    byteOrderMark: 'change-is-unknown',
    invalidEncoding: 'unknown',
    directivePatterns: DIRECTIVE_PATTERNS,
});
const canonicalPolicy = JSON.stringify(WHOLE_DIFF_TRIVIA_POLICY);
const computedPolicyDigest = createHash('sha256').update(canonicalPolicy, 'utf8').digest('hex');
/** SHA-256 pin for the exact canonical policy copied into every V4 receipt. */
export const WHOLE_DIFF_TRIVIA_POLICY_DIGEST = 'f2c860d9ae2baf453beba15d22d9efb31616bda793ebc6e630c8cd78f51ae370';
if (computedPolicyDigest !== WHOLE_DIFF_TRIVIA_POLICY_DIGEST) {
    throw new Error(`Whole-diff trivia policy digest mismatch: expected ${WHOLE_DIFF_TRIVIA_POLICY_DIGEST}, computed ${computedPolicyDigest}.`);
}
const compiledDirectivePatterns = DIRECTIVE_PATTERNS.map(entry => new RegExp(entry.pattern, entry.flags));
const safeWhitespaceGrammars = new Set(SAFE_WHITESPACE_GRAMMARS);
export function isWholeDiffDirectiveComment(comment) {
    return compiledDirectivePatterns.some(pattern => pattern.test(comment));
}
export function isWholeDiffWhitespaceSafeGrammar(grammar) {
    return safeWhitespaceGrammars.has(grammar);
}
//# sourceMappingURL=trivia-policy.js.map