/**
 * context-pack.ts — Assembles the ContextPack fed to each invoker.
 *
 * Draws from:
 *   - memory.recallWithMetadata()  — top-N relevant memories
 *   - orchestrator.discoverCandidateFiles() — token-optimised file list
 *   - (optional) cr-graph structural context, if available
 *
 * All sources are best-effort: if any fails the pack is still returned with
 * whatever data was available.
 */
export function buildContextPack(opts) {
    return {
        goal: opts.goal,
        memories: (opts.memories ?? []).slice(0, opts.memoryLimit),
        files: (opts.files ?? []).slice(0, opts.fileLimit),
        crGraphContext: opts.crGraphContext ?? null,
        repoRoot: opts.repoRoot,
        repoName: opts.repoName,
    };
}
/** Formats a ContextPack as a compact Markdown string for logging/debugging. */
export function summariseContextPack(pack) {
    return [
        `Goal: ${pack.goal.slice(0, 120)}`,
        `Memories: ${pack.memories.length}`,
        `Files: ${pack.files.length}`,
        `CrGraph: ${pack.crGraphContext ? 'yes' : 'no'}`,
        `Repo: ${pack.repoName}`,
    ].join(' | ');
}
