/**
 * C8: Produce a structured HandoffContext from the current session state.
 * Includes completed work, decisions, file ownership, pending tasks, and a summary.
 */
export function generateHandoff(sessionContext) {
    const sessionSummary = buildSessionSummary(sessionContext);
    return {
        fromAgent: sessionContext.fromAgent,
        toAgent: sessionContext.toAgent,
        completedWork: [...sessionContext.completedWork],
        decisions: sessionContext.decisions.map((d) => ({ ...d })),
        fileOwnershipMap: { ...sessionContext.fileOwnershipMap },
        pendingWork: sessionContext.pendingWork.map((p) => ({ ...p })),
        sessionSummary,
    };
}
/**
 * C11: Validate that a receiving agent can reconstruct enough context from the handoff
 * without needing to read the full session history.
 *
 * Returns a validation result with any missing fields listed.
 */
export function reconstructContext(handoff) {
    const missingFields = [];
    if (handoff.fromAgent.trim() === '') {
        missingFields.push('fromAgent');
    }
    if (handoff.toAgent.trim() === '') {
        missingFields.push('toAgent');
    }
    if (handoff.completedWork.length === 0) {
        missingFields.push('completedWork');
    }
    if (handoff.sessionSummary.trim() === '') {
        missingFields.push('sessionSummary');
    }
    if (Object.keys(handoff.fileOwnershipMap).length === 0 && handoff.pendingWork.length === 0) {
        // Must have at least one of: file ownership or pending work to be actionable
        missingFields.push('fileOwnershipMap or pendingWork');
    }
    const isValid = missingFields.length === 0;
    const summary = isValid
        ? `Handoff from ${handoff.fromAgent} to ${handoff.toAgent} is complete and actionable.`
        : `Handoff is incomplete. Missing: ${missingFields.join(', ')}.`;
    return { isValid, missingFields, summary };
}
// ---------------------------------------------------------------------------
// Internal helpers
// ---------------------------------------------------------------------------
function buildSessionSummary(ctx) {
    const parts = [];
    parts.push(`Agent ${ctx.fromAgent} completed ${ctx.completedWork.length} task(s).`);
    if (ctx.decisions.length > 0) {
        parts.push(`${ctx.decisions.length} architectural decision(s) made.`);
    }
    const fileCount = Object.keys(ctx.fileOwnershipMap).length;
    if (fileCount > 0) {
        parts.push(`${fileCount} file(s) modified.`);
    }
    if (ctx.pendingWork.length > 0) {
        parts.push(`${ctx.pendingWork.length} task(s) remain for ${ctx.toAgent}.`);
    }
    else {
        parts.push(`No pending work for ${ctx.toAgent}.`);
    }
    return parts.join(' ');
}
//# sourceMappingURL=handoff-generator.js.map