Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
109 lines
3.4 KiB
Go
109 lines
3.4 KiB
Go
package dolt
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"strconv"
|
|
|
|
"github.com/steveyegge/beads/internal/storage/issueops"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
const (
|
|
defaultTier1Days = 30
|
|
defaultTier2Days = 90
|
|
)
|
|
|
|
// getCompactDays reads the configured compaction threshold for the given tier,
|
|
// falling back to the default if the config key is missing or unparseable.
|
|
func (s *DoltStore) getCompactDays(ctx context.Context, tier int) int {
|
|
key := "compact_tier1_days"
|
|
def := defaultTier1Days
|
|
if tier == 2 {
|
|
key = "compact_tier2_days"
|
|
def = defaultTier2Days
|
|
}
|
|
val, err := s.GetConfig(ctx, key)
|
|
if err != nil || val == "" {
|
|
return def
|
|
}
|
|
n, err := strconv.Atoi(val)
|
|
if err != nil || n <= 0 {
|
|
return def
|
|
}
|
|
return n
|
|
}
|
|
|
|
// CheckEligibility checks if an issue is eligible for compaction at the given tier.
|
|
func (s *DoltStore) CheckEligibility(ctx context.Context, issueID string, tier int) (bool, string, error) {
|
|
var eligible bool
|
|
var reason string
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
eligible, reason, err = issueops.CheckEligibilityInTx(ctx, tx, issueID, tier)
|
|
return err
|
|
})
|
|
return eligible, reason, err
|
|
}
|
|
|
|
// ApplyCompaction records a compaction result in the database.
|
|
func (s *DoltStore) ApplyCompaction(ctx context.Context, issueID string, tier int, originalSize int, _ int, commitHash string) error {
|
|
return s.withRetryTx(ctx, func(tx *sql.Tx) error {
|
|
return issueops.ApplyCompactionInTx(ctx, tx, issueID, tier, originalSize, commitHash)
|
|
})
|
|
}
|
|
|
|
// SnapshotIssue archives an issue's current text content before a destructive
|
|
// compaction overwrites it. See issueops.SnapshotIssueInTx.
|
|
func (s *DoltStore) SnapshotIssue(ctx context.Context, issueID string, tier int) error {
|
|
return s.withRetryTx(ctx, func(tx *sql.Tx) error {
|
|
return issueops.SnapshotIssueInTx(ctx, tx, issueID, tier)
|
|
})
|
|
}
|
|
|
|
// GetCompactionSnapshot returns the most recent archived snapshot for an issue,
|
|
// or (nil, nil) when none exists.
|
|
func (s *DoltStore) GetCompactionSnapshot(ctx context.Context, issueID string) (*types.IssueSnapshot, error) {
|
|
var snap *types.IssueSnapshot
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
snap, err = issueops.GetLatestSnapshotInTx(ctx, tx, issueID)
|
|
return err
|
|
})
|
|
return snap, err
|
|
}
|
|
|
|
// RestoreFromSnapshot restores an issue's content from its most recent snapshot
|
|
// and steps its compaction level back down. See issueops.RestoreFromSnapshotInTx.
|
|
func (s *DoltStore) RestoreFromSnapshot(ctx context.Context, issueID string) (*types.IssueSnapshot, error) {
|
|
var snap *types.IssueSnapshot
|
|
err := s.withRetryTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
snap, err = issueops.RestoreFromSnapshotInTx(ctx, tx, issueID)
|
|
return err
|
|
})
|
|
return snap, err
|
|
}
|
|
|
|
// GetTier1Candidates returns issues eligible for tier 1 compaction.
|
|
func (s *DoltStore) GetTier1Candidates(ctx context.Context) ([]*types.CompactionCandidate, error) {
|
|
var result []*types.CompactionCandidate
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.GetTier1CandidatesInTx(ctx, tx)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
// GetTier2Candidates returns issues eligible for tier 2 compaction.
|
|
func (s *DoltStore) GetTier2Candidates(ctx context.Context) ([]*types.CompactionCandidate, error) {
|
|
var result []*types.CompactionCandidate
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.GetTier2CandidatesInTx(ctx, tx)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|