"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAutogeneratedByHeader = isAutogeneratedByHeader;
/**
 * D028 extension (2.4.7): auto-generated source-file detection via
 * file headers. Complements `LanguageSupport.autogeneratedSourcePatterns`
 * (basename globs like `*.designer.cs`, `*.pb.go`) by catching the
 * harder case: hand-named generated files that don't match any basename
 * pattern.
 *
 * Motivating case: the .NET WinForms benchmark's SAP Business One integration code
 * includes 30+ files named `OWTQ.cs`, `OPCH.cs`, `ADOC.cs`, etc. —
 * each 11,517 lines, generated by SAP's tool chain. None match the
 * standard csharp autogen patterns (no `.designer.cs` / `.g.cs` /
 * `Reference.cs` suffix), so pre-D028-headers they appeared as
 * legitimate source files. They clutter:
 *   - test-gaps LOW priority (30 × 11K-line "untested files")
 *   - Maintainability "largest file" + "files over 500 lines"
 *   - Code Quality function counts (62,271 → likely ~20,000 real)
 *
 * Header markers cover the de-facto industry conventions:
 *
 *   `<auto-generated>`       .NET MSBuild / WCF / EF Core; appears in
 *                            XML doc on line 2 of generated .cs files
 *   `@generated`             Facebook's universal convention; recognised
 *                            by Phabricator, GitHub's linguist, etc.
 *                            Used by Hack, JS, Python, Java, more
 *   `Code generated by`      Go protobuf / stringer / mockgen / cmd/cgo;
 *                            documented in golang.org/s/generatedcode
 *   `Generated by`           Common across OpenAPI Generator, GraphQL
 *                            codegen, Thrift, Avro, etc.
 *   `DO NOT EDIT`            Near-universal — most autogen tools emit
 *                            this string somewhere in the first few lines
 *   `AUTO-GENERATED`         Variant of DO NOT EDIT
 *
 * Read at most the first 2KB of each file (covers >5 lines for any
 * reasonable language) and apply a single regex over the union.
 *
 * Cost: ~4MB of disk I/O for a 4163-file repo (~1KB read per file
 * via the underlying page cache). Negligible vs. the wc-l pass that
 * already reads every file fully.
 */
const fs = __importStar(require("fs"));
const AUTOGEN_HEADER_RE = /<auto-generated>|@generated\b|Code generated by\b|Generated by\b|DO NOT EDIT|AUTO-GENERATED/i;
/**
 * Probe the first ~2KB of `absPath` for a known auto-generated
 * marker. Returns true on match, false otherwise (including on read
 * errors — over-include is preferable to silently dropping unreadable
 * files).
 */
function isAutogeneratedByHeader(absPath) {
    let fd = null;
    try {
        fd = fs.openSync(absPath, 'r');
        const buf = Buffer.alloc(2048);
        const n = fs.readSync(fd, buf, 0, 2048, 0);
        const head = buf.toString('utf-8', 0, n);
        return AUTOGEN_HEADER_RE.test(head);
    }
    catch {
        return false;
    }
    finally {
        if (fd !== null) {
            try {
                fs.closeSync(fd);
            }
            catch {
                /* ignore */
            }
        }
    }
}
//# sourceMappingURL=autogen-header.js.map