/**
 * Diff-preview helpers — worker context and knowledge-fabric snapshot rendering.
 */
/** Renders a WorkerContextPacket as Markdown for context files / artifacts. */
export function renderWorkerContextMarkdown(context) {
    return [
        `# Worker Context`,
        '',
        `- Runtime: ${context.runtimeId}`,
        `- Run: ${context.runId}`,
        `- Worker: ${context.workerId}`,
        `- Role: ${context.role}`,
        `- Strategy: ${context.strategy}`,
        context.selectedCrew ? `- Crew: ${context.selectedCrew.name}` : '',
        '',
        '## Goal',
        context.goal,
        '',
        '## Specialist',
        context.specialist.name ? `- Name: ${context.specialist.name}` : '- Name: unassigned',
        context.specialist.mission ? `- Mission: ${context.specialist.mission}` : '',
        context.specialist.rules.length ? `- Rules: ${context.specialist.rules.join(' | ')}` : '',
        context.specialist.workflow.length ? `- Workflow: ${context.specialist.workflow.join(' | ')}` : '',
        context.specialist.deliverables.length ? `- Deliverables: ${context.specialist.deliverables.join(' | ')}` : '',
        '',
        '## Active Skills',
        ...(context.activeSkills.length
            ? context.activeSkills.map((skill) => `- ${skill.name} (${skill.riskClass})${skill.toolBindings.length ? ` [${skill.toolBindings.map((binding) => binding.type).join(', ')}]` : ''}`)
            : ['- none']),
        '',
        '## Active Workflows',
        ...(context.activeWorkflows.length
            ? context.activeWorkflows.map((workflow) => `- ${workflow.name}: ${workflow.description}`)
            : ['- none']),
        '',
        '## Review Gates',
        ...(context.reviewGates.length
            ? context.reviewGates.map((gate) => `- ${gate.gate}: ${gate.status} (${gate.owner})`)
            : ['- none']),
        '',
        '## Phase Additions',
        ...(context.phasePackets.length
            ? context.phasePackets.map((packet) => `- ${packet.trigger}: skills=${packet.addedSkillNames.join(', ') || 'none'} workflows=${packet.addedWorkflowNames.join(', ') || 'none'} bindings=${packet.addedBindings.join(', ') || 'none'}`)
            : ['- none']),
    ].filter(Boolean).join('\n');
}
/** Projects a KnowledgeFabricBundle down to its snapshot shape. */
export function toKnowledgeFabricSnapshot(bundle) {
    return {
        runtimeId: bundle.runtimeId,
        sessionId: bundle.sessionId,
        generatedAt: bundle.generatedAt,
        task: bundle.task,
        stage: bundle.stage,
        cache: bundle.cache,
        sourceMix: bundle.sourceMix,
        tokenBudget: bundle.tokenBudget,
        attachedCollections: bundle.rag.attachedCollections,
        patternHits: bundle.patterns.selected.map((pattern) => ({
            patternId: pattern.patternId,
            name: pattern.name,
            score: pattern.score,
        })),
        selectedFiles: bundle.repo.selectedFiles,
        candidateFiles: bundle.repo.candidateFiles,
        recommendations: bundle.recommendations,
        modelTierPolicy: bundle.modelTierPolicy,
        modelTierTrace: bundle.modelTierTrace,
        provenance: bundle.provenance,
        summary: bundle.summary,
    };
}
