/**
 * The text the LLM sees as a synthetic user message after an
 * overflow-driven auto-compaction. Tuned to be imperative and brief:
 *
 *   - "Continue the task in progress" — open-ended about what the
 *     next step is. The agent may need to call a tool, write a
 *     final answer, ask a follow-up question, or anything else the
 *     task requires. We don't prescribe the shape; we just say
 *     keep going.
 *   - "Do not write a summary of what you were doing" — names the
 *     observed failure mode (model paraphrases the summary's
 *     "Next Steps" instead of acting).
 *   - "Pick up from where you left off" — frames the summary as
 *     reference material, not as a fresh prompt addressed to the
 *     model.
 *
 * Kept under 250 characters so the addition to LLM input is
 * negligible (~50 tokens).
 */
export const NUDGE_MESSAGE = "[continuation] Continue the task in progress — pick up from where you left off " +
    "based on the summary above. Do not write a status update or summary of what you " +
    "were doing; just proceed with the next action the task requires.";
/**
 * Inspect a messages array and decide whether the post-compaction
 * nudge should be appended. Exported separately so the unit test can
 * exercise the boundary cases (empty, only summary, summary then user
 * prompt, summary then assistant turn) without booting a full SDK
 * session.
 */
export function shouldNudgeAfterCompaction(messages) {
    const last = messages[messages.length - 1];
    if (last === undefined)
        return false;
    return last.role === "compactionSummary";
}
/**
 * Build the synthetic user message used as the nudge. Timestamp is
 * `Date.now()` so the message sorts after any prior content if a
 * downstream consumer ever inspects timestamps; in practice the SDK
 * doesn't reorder by timestamp at LLM-call time, but it costs nothing
 * to keep monotonic ordering.
 */
function buildNudgeMessage() {
    return {
        role: "user",
        content: [{ type: "text", text: NUDGE_MESSAGE }],
        timestamp: Date.now(),
    };
}
/**
 * Pi extension factory. Registered via `DefaultResourceLoader`'s
 * `extensionFactories` option in `agent-resource-loader.ts`. No I/O,
 * no async setup — just registers the handler and returns.
 */
export const compactionContinuationExtension = (pi) => {
    pi.on("context", (event) => {
        if (!shouldNudgeAfterCompaction(event.messages)) {
            return undefined;
        }
        return {
            messages: [...event.messages, buildNudgeMessage()],
        };
    });
};
//# sourceMappingURL=compaction-continuation.js.map