/**
 * knowledge-pack-builder.ts — assembles the bundled olam knowledge pack.
 *
 * The knowledge pack is a single Markdown string concatenating a curated set
 * of repo docs (README, onboarding, top-level architecture overviews) plus a
 * generated CLI command reference. It is produced at BUILD time by
 * `scripts/gen-knowledge-pack.mjs` (which calls {@link buildKnowledgePack})
 * and emitted into `src/ask/knowledge-pack.generated.ts` so the published
 * `@pleri/olam-cli` tarball ships the pack inline — no repo checkout needed
 * at runtime (the `npx` install case).
 *
 * Why a build-time pack and not runtime file reads alone: outside an olam
 * checkout (installed via `npx`) there is no repo to read, yet operators still
 * ask setup questions. The bundled pack guarantees a useful baseline answer.
 * Inside a checkout, `olam ask` ADDITIONALLY lets the SDK read live repo files
 * (via the Claude Code preset's Read/Grep tools) for fresher, precise answers.
 *
 * This module is pure: callers inject the repo root + a file reader so the
 * generator script and its unit tests share one code path (Rule 9 — the test
 * asserts the assembled shape without touching the real filesystem).
 */
/**
 * Curated source list. Ordered most-foundational first so truncation (if a
 * future cap is added) drops the least-essential docs last. Kept small and
 * overview-grade on purpose: the pack is the SDK system prompt, not a full
 * doc dump — bloating it wastes the operator's local-subscription tokens and
 * dilutes answer precision.
 */
export const DEFAULT_PACK_SOURCES = [
    { path: 'README.md', label: 'Olam — README (overview, substrates, scope)' },
    {
        path: 'docs/ONBOARDING.md',
        label: 'Onboarding (first-run, install, getting started)',
        optional: true,
    },
    {
        path: 'docs/onboarding/fresh-machine-setup.md',
        label: 'Setup — fresh machine',
        optional: true,
    },
    {
        path: 'docs/onboarding/k3s-mode-setup.md',
        label: 'Setup — k3d/k3s mode (default substrate, port 19001)',
        optional: true,
    },
    {
        path: 'docs/architecture/01-problem.md',
        label: 'Architecture — the problem olam solves',
        optional: true,
    },
    {
        path: 'docs/architecture/03-system.md',
        label: 'Architecture — system overview',
        optional: true,
    },
    {
        path: 'docs/architecture/04-lifecycle.md',
        label: 'Architecture — world lifecycle',
        optional: true,
    },
];
/** A simple, self-describing header so the model knows what it's reading. */
const PACK_HEADER = `# Olam knowledge pack

The sections below are curated excerpts from the olam repository's own
documentation, bundled into the CLI at build time. Treat them as the
authoritative source for olam usage, setup, and CLI behaviour. When a section
conflicts with your prior knowledge, the section wins.`;
/**
 * Assemble the knowledge pack string from the curated sources + command
 * reference. Pure: no I/O of its own — all filesystem access flows through the
 * injected `readFile`/`fileExists`. Missing REQUIRED docs throw (the build
 * must fail loudly per Rule 12); missing OPTIONAL docs are skipped with an
 * inline note so the pack stays coherent.
 */
export function buildKnowledgePack(input) {
    const sources = input.sources ?? DEFAULT_PACK_SOURCES;
    const parts = [PACK_HEADER];
    for (const src of sources) {
        const abs = input.join(input.repoRoot, src.path);
        if (!input.fileExists(abs)) {
            if (src.optional) {
                parts.push(`## ${src.label}\n\n_(source \`${src.path}\` not present in this build — skipped)_`);
                continue;
            }
            throw new Error(`buildKnowledgePack: required source missing: ${src.path} (resolved ${abs})`);
        }
        const body = input.readFile(abs).trim();
        parts.push(`## ${src.label}\n\nSource: \`${src.path}\`\n\n${body}`);
    }
    if (input.commandReference && input.commandReference.trim().length > 0) {
        parts.push(`## CLI command reference\n\n${input.commandReference.trim()}`);
    }
    return parts.join('\n\n---\n\n') + '\n';
}
//# sourceMappingURL=knowledge-pack-builder.js.map