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>
234 lines
7.3 KiB
Go
234 lines
7.3 KiB
Go
package dolt
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
"github.com/steveyegge/beads/internal/storage/issueops"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// SearchIssues finds issues matching query and filters.
|
|
// Delegates to issueops.SearchIssuesInTx for shared query logic.
|
|
func (s *DoltStore) SearchIssues(ctx context.Context, query string, filter types.IssueFilter) ([]*types.Issue, error) {
|
|
var result []*types.Issue
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.SearchIssuesInTx(ctx, tx, query, filter)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
func (s *DoltStore) SearchIssuesWithCounts(ctx context.Context, query string, filter types.IssueFilter) ([]*types.IssueWithCounts, error) {
|
|
var result []*types.IssueWithCounts
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.SearchIssuesWithCountsInTx(ctx, tx, query, filter)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
func (s *DoltStore) GetReadyWork(ctx context.Context, filter types.WorkFilter) ([]*types.Issue, error) {
|
|
var result []*types.Issue
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.GetReadyWorkInTx(ctx, tx, filter)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
func (s *DoltStore) GetReadyWorkWithCounts(ctx context.Context, filter types.WorkFilter) ([]*types.IssueWithCounts, error) {
|
|
var result []*types.IssueWithCounts
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.GetReadyWorkWithCountsInTx(ctx, tx, filter)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
func (s *DoltStore) GetBlockedIssues(ctx context.Context, filter types.WorkFilter) ([]*types.BlockedIssue, error) {
|
|
var result []*types.BlockedIssue
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.GetBlockedIssuesInTx(ctx, tx, filter)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
// GetEpicsEligibleForClosure returns epics whose children are all closed
|
|
func (s *DoltStore) GetEpicsEligibleForClosure(ctx context.Context) ([]*types.EpicStatus, error) {
|
|
var result []*types.EpicStatus
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.GetEpicsEligibleForClosureInTx(ctx, tx)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
// GetStaleIssues returns issues that haven't been updated recently
|
|
func (s *DoltStore) GetStaleIssues(ctx context.Context, filter types.StaleFilter) ([]*types.Issue, error) {
|
|
var result []*types.Issue
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.GetStaleIssuesInTx(ctx, tx, filter)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
// GetStatistics returns summary statistics
|
|
func (s *DoltStore) GetStatistics(ctx context.Context) (*types.Statistics, error) {
|
|
stats := &types.Statistics{}
|
|
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
return issueops.ScanIssueCountsInTx(ctx, tx, stats)
|
|
})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get statistics: %w", err)
|
|
}
|
|
|
|
var blockedCount int
|
|
if err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
return tx.QueryRowContext(ctx, `
|
|
SELECT COUNT(*) FROM issues
|
|
WHERE is_blocked = 1 AND status <> 'closed' AND status <> 'pinned'
|
|
`).Scan(&blockedCount)
|
|
}); err != nil {
|
|
return nil, fmt.Errorf("failed to count blocked issues: %w", err)
|
|
}
|
|
stats.BlockedIssues = blockedCount
|
|
|
|
stats.ReadyIssues = stats.OpenIssues - blockedCount
|
|
if stats.ReadyIssues < 0 {
|
|
stats.ReadyIssues = 0
|
|
}
|
|
|
|
return stats, nil
|
|
}
|
|
|
|
// GetMoleculeProgress returns progress stats for a molecule
|
|
func (s *DoltStore) GetMoleculeProgress(ctx context.Context, moleculeID string) (*types.MoleculeProgressStats, error) {
|
|
stats := &types.MoleculeProgressStats{
|
|
MoleculeID: moleculeID,
|
|
}
|
|
|
|
// Route to correct table based on whether molecule is a wisp (bd-w2w)
|
|
issueTable := "issues"
|
|
depTable := "dependencies"
|
|
parentCol := "depends_on_issue_id"
|
|
if s.isActiveWisp(ctx, moleculeID) {
|
|
issueTable = "wisps"
|
|
depTable = "wisp_dependencies"
|
|
parentCol = "depends_on_wisp_id"
|
|
}
|
|
|
|
// Get molecule title
|
|
var title sql.NullString
|
|
//nolint:gosec // G201: issueTable is hardcoded to "issues" or "wisps"
|
|
err := s.db.QueryRowContext(ctx, fmt.Sprintf("SELECT title FROM %s WHERE id = ?", issueTable), moleculeID).Scan(&title)
|
|
if err == nil && title.Valid {
|
|
stats.MoleculeTitle = title.String
|
|
}
|
|
|
|
// Step 1: Get child issue IDs from dependencies table (single-table scan)
|
|
//nolint:gosec // G201: depTable and parentCol are hardcoded
|
|
depRows, err := s.queryContext(ctx, fmt.Sprintf(`
|
|
SELECT issue_id FROM %s
|
|
WHERE %s = ? AND type = 'parent-child'
|
|
`, depTable, parentCol), moleculeID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get molecule children: %w", err)
|
|
}
|
|
var childIDs []string
|
|
for depRows.Next() {
|
|
var id string
|
|
if err := depRows.Scan(&id); err != nil {
|
|
_ = depRows.Close() // Best effort cleanup on error path
|
|
return nil, wrapScanError("get molecule progress: scan child", err)
|
|
}
|
|
childIDs = append(childIDs, id)
|
|
}
|
|
_ = depRows.Close() // Redundant close for safety (rows already iterated)
|
|
|
|
// Step 2: Batch-fetch status for all children (batched IN clauses to avoid full table scans).
|
|
// Children of a wisp molecule are also wisps, so use the same table.
|
|
if len(childIDs) > 0 {
|
|
type childInfo struct {
|
|
status string
|
|
}
|
|
childMap := make(map[string]childInfo)
|
|
for start := 0; start < len(childIDs); start += queryBatchSize {
|
|
end := start + queryBatchSize
|
|
if end > len(childIDs) {
|
|
end = len(childIDs)
|
|
}
|
|
batch := childIDs[start:end]
|
|
placeholders, args := doltBuildSQLInClause(batch)
|
|
// nolint:gosec // G201: issueTable is hardcoded, placeholders contains only ? markers
|
|
query := fmt.Sprintf("SELECT id, status FROM %s WHERE id IN (%s)", issueTable, placeholders)
|
|
statusRows, err := s.queryContext(ctx, query, args...)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to batch-fetch child statuses: %w", err)
|
|
}
|
|
for statusRows.Next() {
|
|
var id, status string
|
|
if err := statusRows.Scan(&id, &status); err != nil {
|
|
_ = statusRows.Close()
|
|
return nil, wrapScanError("get molecule progress: scan status", err)
|
|
}
|
|
childMap[id] = childInfo{status: status}
|
|
}
|
|
_ = statusRows.Close()
|
|
}
|
|
|
|
for _, childID := range childIDs {
|
|
info, ok := childMap[childID]
|
|
if !ok {
|
|
continue
|
|
}
|
|
stats.Total++
|
|
switch types.Status(info.status) {
|
|
case types.StatusClosed:
|
|
stats.Completed++
|
|
case types.StatusInProgress:
|
|
stats.InProgress++
|
|
if stats.CurrentStepID == "" {
|
|
stats.CurrentStepID = childID
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return stats, nil
|
|
}
|
|
|
|
// GetMoleculeLastActivity returns the most recent activity timestamp for a molecule.
|
|
func (s *DoltStore) GetMoleculeLastActivity(ctx context.Context, moleculeID string) (*types.MoleculeLastActivity, error) {
|
|
var result *types.MoleculeLastActivity
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
result, err = issueops.GetMoleculeLastActivityInTx(ctx, tx, moleculeID)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
// GetNextChildID returns the next available child ID for a parent.
|
|
// Delegates SQL work to issueops.GetNextChildIDTx.
|
|
func (s *DoltStore) GetNextChildID(ctx context.Context, parentID string) (string, error) {
|
|
var childID string
|
|
err := s.withRetryTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
childID, err = issueops.GetNextChildIDTx(ctx, tx, parentID)
|
|
return err
|
|
})
|
|
return childID, err
|
|
}
|