Implement Tier 1 compaction logic (bd-257)

- Add Compactor with CompactTier1 and CompactTier1Batch methods
- Single issue and batch compaction with 5 concurrent workers
- Dry-run mode for testing without API calls
- Smart size checking: keeps original if summary is longer
- Improved Haiku prompts to emphasize compression
- Add ApplyCompaction method for setting compaction metadata
- Comprehensive tests including API integration tests
- All tests passing
This commit is contained in:
Steve Yegge
2025-10-15 23:31:43 -07:00
parent 5f6aac5fb1
commit 0da81371b4
5 changed files with 683 additions and 5 deletions

View File

@@ -450,3 +450,24 @@ func (s *SQLiteStorage) GetSnapshots(ctx context.Context, issueID string) ([]*Sn
return snapshots, nil
}
// ApplyCompaction updates the compaction metadata for an issue after successfully compacting it.
// This sets compaction_level, compacted_at, and original_size fields.
func (s *SQLiteStorage) ApplyCompaction(ctx context.Context, issueID string, level int, originalSize int) error {
now := time.Now().UTC()
_, err := s.db.ExecContext(ctx, `
UPDATE issues
SET compaction_level = ?,
compacted_at = ?,
original_size = ?,
updated_at = ?
WHERE id = ?
`, level, now, originalSize, now, issueID)
if err != nil {
return fmt.Errorf("failed to apply compaction metadata: %w", err)
}
return nil
}