import { promises as fs } from "node:fs";
import path from "node:path";
import { walk } from "./walker.js";
import { mirrorInReflex, REFLEX_DIR, REFLEX_IGNORE } from "./paths.js";
/** Collect a snapshot of files visible under `scope` (honoring .reflexignore). */
export async function snapshotScope(args) {
    const root = path.resolve(args.root);
    const scope = path.resolve(args.scope);
    const relScope = path.relative(root, scope);
    if (relScope.startsWith("..")) {
        throw new Error(`Scope ${scope} is outside root ${root}`);
    }
    const reflexScope = relScope
        ? mirrorInReflex(root, relScope)
        : path.join(root, REFLEX_DIR);
    const files = [];
    for await (const entry of walk(scope)) {
        if (entry.rel === ".")
            continue;
        if (!entry.isDir)
            files.push(entry.rel);
    }
    return { root, scope, reflexScope, files };
}
export async function ensureReflexIgnoreTemplate(root) {
    const target = path.join(root, REFLEX_IGNORE);
    try {
        await fs.access(target);
        return;
    }
    catch {
        // not present — write a sane default
    }
    const body = [
        "# .reflexignore — gitignore syntax",
        "# Patterns listed here are excluded from Reflex's analysis and watchers.",
        "",
        "node_modules/",
        "dist/",
        "build/",
        ".venv/",
        "__pycache__/",
        "*.log",
        "",
    ].join("\n");
    await fs.writeFile(target, body, "utf8");
}
//# sourceMappingURL=kb.js.map