Add compacted_at_commit field and git commit capture during compaction

- Add compacted_at_commit field to Issue type (bd-405)
- Add database schema and migration for new field
- Create GetCurrentCommitHash() helper function
- Update ApplyCompaction to store git commit hash (bd-395)
- Update compaction calls to capture current commit
- Update tests to verify commit hash storage
- All tests passing

Amp-Thread-ID: https://ampcode.com/threads/T-5518cccb-7fc9-4dcd-ba5a-e22cd10e45d7
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-16 17:43:27 -07:00
parent b17fcdbb2a
commit 65f59e6b01
8 changed files with 81 additions and 12 deletions

View File

@@ -114,7 +114,8 @@ func (c *Compactor) CompactTier1(ctx context.Context, issueID string) error {
return fmt.Errorf("failed to update issue: %w", err)
}
if err := c.store.ApplyCompaction(ctx, issueID, 1, originalSize, compactedSize); err != nil {
commitHash := GetCurrentCommitHash()
if err := c.store.ApplyCompaction(ctx, issueID, 1, originalSize, compactedSize, commitHash); err != nil {
return fmt.Errorf("failed to set compaction level: %w", err)
}
@@ -257,7 +258,8 @@ func (c *Compactor) compactSingleWithResult(ctx context.Context, issueID string,
return fmt.Errorf("failed to update issue: %w", err)
}
if err := c.store.ApplyCompaction(ctx, issueID, 1, result.OriginalSize, result.CompactedSize); err != nil {
commitHash := GetCurrentCommitHash()
if err := c.store.ApplyCompaction(ctx, issueID, 1, result.OriginalSize, result.CompactedSize, commitHash); err != nil {
return fmt.Errorf("failed to set compaction level: %w", err)
}

21
internal/compact/git.go Normal file
View File

@@ -0,0 +1,21 @@
package compact
import (
"bytes"
"os/exec"
"strings"
)
// GetCurrentCommitHash returns the current git HEAD commit hash.
// Returns empty string if not in a git repository or if git command fails.
func GetCurrentCommitHash() string {
cmd := exec.Command("git", "rev-parse", "HEAD")
var out bytes.Buffer
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
return ""
}
return strings.TrimSpace(out.String())
}