/**
 * Memory Management Section
 * Provides guidance on session memory operations (SET/DELETE) with dynamic status
 */

/**
 * Memory status information for prompt generation
 */
export interface MemoryStatus {
  sessionMemoryKeys: number
  sessionMemoryLimit: number
  historyPercent: number
}

/**
 * Builds the memory management section of the system prompt
 * Includes SET/DELETE operations, memory status, and persistence guidance
 *
 * @param memoryStatus - Current memory usage statistics
 * @param preferences - Optional agent-specific memory preferences (string)
 * @returns Memory management prompt section
 */
export function buildMemoryPrompt(memoryStatus: MemoryStatus, preferences?: string): string {
  return `## Memory Management

You have control over session memory. Use memoryOps to manage critical information:

**SET critical information:**
\`\`\`json
{
  "memoryOps": {
    "set": {
      "customer_account": "Account #12345, Premium tier, expires 2026-03-15",
      "original_request": "Fix broken widget"
    }
  }
}
\`\`\`

**DELETE outdated information:**
\`\`\`json
{
  "memoryOps": {
    "delete": ["old_address", "cancelled_order"]
  }
}
\`\`\`

**When to persist:**
- Memory at ${memoryStatus.historyPercent}%: ${memoryStatus.historyPercent >= 80 ? 'Proactively persist important context NOW (auto-compaction at 100%)' : 'Normal operation'}
- Session keys at ${memoryStatus.sessionMemoryKeys}/${memoryStatus.sessionMemoryLimit}: Delete outdated keys before adding new ones
- Always: Persist critical data that should survive memory compaction

**IMPORTANT - System-Managed Memory:**
Do NOT update these keys via memoryOps (managed automatically by tools/actions):
- notion-pages-cache (managed by Notion tools)
- knowledge-map-state (managed by navigate-knowledge)

Attempting to update system-managed keys will be rejected. Use tools to update their caches.
${preferences ? `\n**Agent-Specific Guidance:**\n${preferences}\n` : ''}
Framework auto-compacts history at 100% token budget.
You control WHAT to remember. Framework controls HOW compaction works.

`
}
