caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
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>
2026-06-23 14:14:09 +03:00

112 lines
3.9 KiB
Go

//go:build cgo
package embeddeddolt
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/issueops"
"github.com/steveyegge/beads/internal/types"
)
// ClaimIssue atomically claims an issue using compare-and-swap semantics.
// Delegates SQL work to issueops; EmbeddedDolt auto-commits the transaction.
func (s *EmbeddedDoltStore) ClaimIssue(ctx context.Context, id string, actor string) error {
return s.withConn(ctx, true, func(tx *sql.Tx) error {
_, err := issueops.ClaimIssueInTx(ctx, tx, id, actor)
return err
})
}
// ClaimReadyIssue atomically claims the first ready issue matching filter.
func (s *EmbeddedDoltStore) ClaimReadyIssue(ctx context.Context, filter types.WorkFilter, actor string) (*types.Issue, error) {
var claimed *types.Issue
err := s.withConn(ctx, true, func(tx *sql.Tx) error {
var err error
claimed, err = issueops.ClaimReadyIssueInTx(ctx, tx, filter, actor)
return err
})
return claimed, err
}
// UpdateIssue updates fields on an issue.
// Delegates SQL work to issueops; EmbeddedDolt auto-commits the transaction.
func (s *EmbeddedDoltStore) UpdateIssue(ctx context.Context, id string, updates map[string]interface{}, actor string) error {
// Validate metadata against schema before routing.
if rawMeta, ok := updates["metadata"]; ok {
metadataStr, err := storage.NormalizeMetadataValue(rawMeta)
if err != nil {
return fmt.Errorf("invalid metadata: %w", err)
}
if err := issueops.ValidateMetadataIfConfigured(json.RawMessage(metadataStr)); err != nil {
return err
}
}
return s.withConn(ctx, true, func(tx *sql.Tx) error {
_, err := issueops.UpdateIssueInTx(ctx, tx, id, updates, actor)
return err
})
}
// ReopenIssue reopens a closed issue, setting status to open and clearing
// closed_at and defer_until. If reason is non-empty, it is recorded as a comment.
// Wraps UpdateIssue; EmbeddedDolt auto-commits the transaction.
func (s *EmbeddedDoltStore) ReopenIssue(ctx context.Context, id string, reason string, actor string) error {
updates := map[string]interface{}{
"status": string(types.StatusOpen),
"defer_until": nil,
}
if err := s.UpdateIssue(ctx, id, updates, actor); err != nil {
return err
}
if reason != "" {
if err := s.AddComment(ctx, id, actor, reason); err != nil {
return fmt.Errorf("reopen comment: %w", err)
}
}
return nil
}
// UpdateIssueType changes the issue_type field of an issue.
// Wraps UpdateIssue; EmbeddedDolt auto-commits the transaction.
func (s *EmbeddedDoltStore) UpdateIssueType(ctx context.Context, id string, issueType string, actor string) error {
return s.UpdateIssue(ctx, id, map[string]interface{}{"issue_type": issueType}, actor)
}
// CloseIssue closes an issue with a reason.
// Delegates SQL work to issueops; EmbeddedDolt auto-commits the transaction.
func (s *EmbeddedDoltStore) CloseIssue(ctx context.Context, id string, reason string, actor string, session string) error {
return s.withConn(ctx, true, func(tx *sql.Tx) error {
_, err := issueops.CloseIssueInTx(ctx, tx, id, reason, actor, session)
return err
})
}
// IsBlocked checks if an issue is blocked by active dependencies.
func (s *EmbeddedDoltStore) IsBlocked(ctx context.Context, issueID string) (bool, []string, error) {
var blocked bool
var blockers []string
err := s.withConn(ctx, false, func(tx *sql.Tx) error {
var err error
blocked, blockers, err = issueops.IsBlockedInTx(ctx, tx, issueID)
return err
})
return blocked, blockers, err
}
// GetNewlyUnblockedByClose finds issues that become unblocked when closedIssueID is closed.
func (s *EmbeddedDoltStore) GetNewlyUnblockedByClose(ctx context.Context, closedIssueID string) ([]*types.Issue, error) {
var result []*types.Issue
err := s.withConn(ctx, false, func(tx *sql.Tx) error {
var err error
result, err = issueops.GetNewlyUnblockedByCloseInTx(ctx, tx, closedIssueID)
return err
})
return result, err
}