const COMPACTION_CHECKPOINT_MARKER=`Summary of our conversation so far:`,COMPACTION_SYSTEM_PROMPT=`You are performing a CONTEXT CHECKPOINT COMPACTION. Create a handoff summary for another LLM that will resume the task.

Include:

- Current progress and key decisions made
- Important context, constraints, or user preferences
- What remains to be done, with clear next steps
- Any critical data, examples, or references needed to continue

Be concise, structured, and focused on helping the next LLM seamlessly continue the work. Write in the same language as the conversation. Do not continue the conversation, answer its questions, or invent facts. Only output the handoff summary.`,COMPACTION_PROMPT_ENVELOPE={prompt:formatCompactionPrompt({previousCheckpoint:``,transcript:``}),system:COMPACTION_SYSTEM_PROMPT};function createCompactionPrompt(e){let n=e.messages.map(e=>({content:summarizeCompactionMessageContent(e),role:e.role}));return{prompt:formatCompactionPrompt({previousCheckpoint:e.previousCheckpoint?.trim()??`(none)`,transcript:formatCompactionTranscript(n)}),system:COMPACTION_SYSTEM_PROMPT}}function formatCompactionPrompt(e){return`<previous-checkpoint>
${e.previousCheckpoint}
</previous-checkpoint>

<conversation>
Conversation transcript:
${e.transcript}
</conversation>

Update the previous checkpoint with the newer information in the conversation. If there is no previous checkpoint, create one from the conversation.

Make completed work explicit so the next model does not repeat it. Keep completed work separate from current and remaining work, and do not describe completed work as pending unless later messages show it must be redone. Preserve exact file paths, function names, commands, error messages, identifiers, and measured values when they are needed to continue.`}function formatCompactionTranscript(e){let t=e.filter(e=>e.content.trim().length>0).map(e=>`### ${e.role}\n${e.content.trim()}`);return t.length===0?`(empty)`:t.join(`

`)}function summarizeCompactionMessageContent(e){return typeof e.content==`string`?summarizeText(e.content):e.content.map(e=>summarizeCompactionContentPart(e)).filter(e=>e.length>0).join(`
`).trim()}function summarizeCompactionContentPart(e){switch(e.type){case`text`:return summarizeText(e.text);case`reasoning`:return``;case`file`:return e.filename?`Attached file ${e.filename} (${e.mediaType})`:`Attached file attachment (${e.mediaType})`;case`tool-call`:return summarizeToolCallPart(e);case`tool-result`:return summarizeToolResultPart(e);default:return``}}function summarizeToolCallPart(e){let t=e.input===void 0?``:summarizeCompactValue(e.input);return t?`Called ${e.toolName} with ${t}`:`Called ${e.toolName}`}function summarizeToolResultPart(e){let t=e.output===void 0?``:summarizeCompactValue(e.output),n=e.isError?`errored`:`returned`;return t?`Tool ${e.toolName} ${n} ${t}`:`Tool ${e.toolName} ${n}`}function summarizeCompactValue(e,t=0){if(e===null)return`null`;if(e===void 0)return``;if(typeof e==`string`)return summarizeText(e);if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);if(Array.isArray(e)){if(e.length===0)return`array(0)`;if(t>=2)return`array(${e.length})`;let n=e.slice(0,3).map(e=>summarizeCompactValue(e,t+1)),r=e.length>3?`, …`:``;return`array(${e.length}: ${n.join(`, `)}${r})`}if(typeof e==`object`){let n=Object.entries(e);if(n.length===0)return`object(0)`;if(t>=2)return`object(${n.length} keys)`;let r=n.slice(0,3).map(([e,n])=>`${e}=${summarizeCompactValue(n,t+1)}`),i=n.length>3?`, …`:``;return`object(${r.join(`, `)}${i})`}return``}function summarizeText(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=280?t:`${t.slice(0,280).trimEnd()}…`}export{COMPACTION_CHECKPOINT_MARKER,COMPACTION_PROMPT_ENVELOPE,createCompactionPrompt};