#!/bin/bash
# PreCompact hook - save important context before compaction

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

cd "$PROJECT_ROOT"

# Capture current context to memory before it gets compacted
npx tsx -e "
import { saveMemory } from './src/index.js';

// Quick capture of what Claude was working on
const path = require('path');
const content = '[Pre-Compact Context] Preserving before context compression';
saveMemory('session', content, 'context', undefined, {
  importance: 3,
  tags: ['compaction'],
  expiresIn: '1d'
});
console.log('preserved pre-compact state');
" 2>/dev/null || true

exit 0