/** Longest last-assistant excerpt carried into the seed — enough to convey intent
 * without pasting a wall of text (decision: Recap, not Full digest). */
const LAST_LINE_CAP = 400;
/** Collapse whitespace and cap length so a multi-paragraph final message becomes
 * one scannable recap line. */
function trimLastLine(text) {
    const collapsed = text.replace(/\s+/g, ' ').trim();
    if (collapsed.length <= LAST_LINE_CAP)
        return collapsed;
    return `${collapsed.slice(0, LAST_LINE_CAP).trimEnd()}…`;
}
/** Resolve the human display label the caller passes in from a raw SessionMeta. */
export function forkLabelFor(session) {
    return session.label || session.topic || session.shortId;
}
/**
 * Build the recap-seed prompt handed to the forked sibling as its opening input.
 *
 * Pure and deterministic (unit-tested) — no filesystem, no spawn — so the launch
 * orchestration in `commands/fork.ts` stays the only side-effecting layer.
 */
export function buildForkRecap(input) {
    const lines = [];
    lines.push(`Continue a prior ${input.agent} session ("${input.label}"). Pick up where it left off — do not restart it.`);
    if (input.cwd)
        lines.push(`Working directory: ${input.cwd}`);
    if (input.ticketId)
        lines.push(`Ticket: ${input.ticketId}`);
    const last = input.lastAssistant ? trimLastLine(input.lastAssistant) : '';
    if (last)
        lines.push(`It last said: "${last}"`);
    const chg = input.changes;
    if (chg && (chg.created || chg.modified || chg.deleted)) {
        lines.push(`Changes so far: +${chg.created} ~${chg.modified} -${chg.deleted}.`);
    }
    const origin = input.machine ? ` on ${input.machine}` : '';
    lines.push(`Source session ${input.shortId}${origin} — run \`/continue ${input.id}\` if you need the full transcript.`);
    return lines.join('\n');
}
