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>
225 lines
8.1 KiB
Go
225 lines
8.1 KiB
Go
//go:build cgo
|
|
|
|
package embeddeddolt
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/storage/issueops"
|
|
"github.com/steveyegge/beads/internal/storage/versioncontrolops"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// RunInTransaction executes a function within a database transaction.
|
|
// After the SQL transaction commits, dirty tables are selectively staged
|
|
// and a Dolt version commit is created with the given message.
|
|
func (s *EmbeddedDoltStore) RunInTransaction(ctx context.Context, commitMsg string, fn func(tx storage.Transaction) error) error {
|
|
var tracker versioncontrolops.DirtyTableTracker
|
|
|
|
if err := s.withConn(ctx, true, func(tx *sql.Tx) error {
|
|
return fn(&embeddedTransaction{tx: tx, dirty: &tracker})
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Create a Dolt version commit from the working set changes.
|
|
if commitMsg != "" && len(tracker.DirtyTables()) > 0 {
|
|
return s.withMutatingDBConn(ctx, func(db versioncontrolops.DBConn) error {
|
|
return versioncontrolops.StageAndCommit(ctx, db, tracker.DirtyTables(), commitMsg, commitAuthor)
|
|
})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type embeddedTransaction struct {
|
|
tx *sql.Tx
|
|
dirty *versioncontrolops.DirtyTableTracker
|
|
}
|
|
|
|
func (t *embeddedTransaction) CreateIssue(ctx context.Context, issue *types.Issue, actor string) error {
|
|
bc, err := issueops.NewBatchContext(ctx, t.tx, storage.BatchCreateOptions{SkipPrefixValidation: true})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
result, err := issueops.CreateIssueInTxWithResult(ctx, t.tx, bc, issue, actor)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for table := range issueops.CreateIssueDirtyTables(ctx, issue, result) {
|
|
t.dirty.MarkDirty(table)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (t *embeddedTransaction) CreateIssues(ctx context.Context, issues []*types.Issue, actor string) error {
|
|
result, err := issueops.CreateIssuesInTxWithResult(ctx, t.tx, issues, actor, storage.BatchCreateOptions{
|
|
OrphanHandling: storage.OrphanAllow,
|
|
SkipPrefixValidation: true,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for table := range issueops.CreateIssuesDirtyTables(ctx, issues, result) {
|
|
t.dirty.MarkDirty(table)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (t *embeddedTransaction) UpdateIssue(ctx context.Context, id string, updates map[string]interface{}, actor string) error {
|
|
t.dirty.MarkDirty("issues")
|
|
t.dirty.MarkDirty("events")
|
|
_, err := issueops.UpdateIssueInTx(ctx, t.tx, id, updates, actor)
|
|
return err
|
|
}
|
|
|
|
func (t *embeddedTransaction) CloseIssue(ctx context.Context, id string, reason string, actor string, session string) error {
|
|
t.dirty.MarkDirty("issues")
|
|
t.dirty.MarkDirty("events")
|
|
_, err := issueops.CloseIssueInTx(ctx, t.tx, id, reason, actor, session)
|
|
return err
|
|
}
|
|
|
|
func (t *embeddedTransaction) DeleteIssue(ctx context.Context, id string) error {
|
|
t.dirty.MarkDirty("issues")
|
|
t.dirty.MarkDirty("dependencies")
|
|
t.dirty.MarkDirty("labels")
|
|
t.dirty.MarkDirty("comments")
|
|
t.dirty.MarkDirty("events")
|
|
return issueops.DeleteIssueInTx(ctx, t.tx, id)
|
|
}
|
|
|
|
func (t *embeddedTransaction) GetIssue(ctx context.Context, id string) (*types.Issue, error) {
|
|
return issueops.GetIssueInTx(ctx, t.tx, id)
|
|
}
|
|
|
|
func (t *embeddedTransaction) SearchIssues(ctx context.Context, query string, filter types.IssueFilter) ([]*types.Issue, error) {
|
|
return issueops.SearchIssuesInTx(ctx, t.tx, query, filter)
|
|
}
|
|
|
|
func (t *embeddedTransaction) AddDependency(ctx context.Context, dep *types.Dependency, actor string) error {
|
|
return t.AddDependencyWithOptions(ctx, dep, actor, storage.DependencyAddOptions{})
|
|
}
|
|
|
|
func (t *embeddedTransaction) AddDependencyWithOptions(ctx context.Context, dep *types.Dependency, actor string, addOpts storage.DependencyAddOptions) error {
|
|
_, _, _, depTable := issueops.WispTableRouting(issueops.IsActiveWispInTx(ctx, t.tx, dep.IssueID))
|
|
if err := issueops.AddDependencyInTx(ctx, t.tx, dep, actor, issueops.AddDependencyOpts{
|
|
IsCrossPrefix: types.ExtractPrefix(dep.IssueID) != types.ExtractPrefix(dep.DependsOnID),
|
|
SkipCycleCheck: addOpts.SkipCycleCheck,
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
t.dirty.MarkDirty(depTable)
|
|
return nil
|
|
}
|
|
|
|
// CycleThroughEdges reports a blocking cycle through one of the new edges,
|
|
// including the transaction's own uncommitted dependency writes
|
|
// (bd-6dnrw.8, bd-578h9.9).
|
|
func (t *embeddedTransaction) CycleThroughEdges(ctx context.Context, edges [][2]string) (string, error) {
|
|
graph := make(map[string][]string)
|
|
if err := issueops.AppendBlockingGraphInTx(ctx, t.tx, []string{"dependencies", "wisp_dependencies"}, graph); err != nil {
|
|
return "", err
|
|
}
|
|
return issueops.CycleThroughEdgesInGraph(graph, edges), nil
|
|
}
|
|
|
|
func (t *embeddedTransaction) RemoveDependency(ctx context.Context, issueID, dependsOnID string, actor string) error {
|
|
t.dirty.MarkDirty("dependencies")
|
|
return issueops.RemoveDependencyInTx(ctx, t.tx, issueID, dependsOnID)
|
|
}
|
|
|
|
func (t *embeddedTransaction) GetDependencyRecords(ctx context.Context, issueID string) ([]*types.Dependency, error) {
|
|
m, err := issueops.GetDependencyRecordsForIssuesInTx(ctx, t.tx, []string{issueID})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m[issueID], nil
|
|
}
|
|
|
|
func (t *embeddedTransaction) AddLabel(ctx context.Context, issueID, label, actor string) error {
|
|
t.dirty.MarkDirty("labels")
|
|
return issueops.AddLabelInTx(ctx, t.tx, "", "", issueID, label, actor)
|
|
}
|
|
|
|
func (t *embeddedTransaction) RemoveLabel(ctx context.Context, issueID, label, actor string) error {
|
|
t.dirty.MarkDirty("labels")
|
|
return issueops.RemoveLabelInTx(ctx, t.tx, "", "", issueID, label, actor)
|
|
}
|
|
|
|
func (t *embeddedTransaction) GetLabels(ctx context.Context, issueID string) ([]string, error) {
|
|
return issueops.GetLabelsInTx(ctx, t.tx, "", issueID)
|
|
}
|
|
|
|
func (t *embeddedTransaction) SetConfig(ctx context.Context, key, value string) error {
|
|
t.dirty.MarkDirty("config")
|
|
if err := issueops.SetConfigInTx(ctx, t.tx, key, value); err != nil {
|
|
return err
|
|
}
|
|
// Sync normalized tables when config keys change
|
|
switch key {
|
|
case "status.custom":
|
|
t.dirty.MarkDirty("custom_statuses")
|
|
if err := issueops.SyncCustomStatusesTable(ctx, t.tx, value); err != nil {
|
|
return fmt.Errorf("syncing custom_statuses table: %w", err)
|
|
}
|
|
case "types.custom":
|
|
t.dirty.MarkDirty("custom_types")
|
|
if err := issueops.SyncCustomTypesTable(ctx, t.tx, value); err != nil {
|
|
return fmt.Errorf("syncing custom_types table: %w", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (t *embeddedTransaction) GetConfig(ctx context.Context, key string) (string, error) {
|
|
return issueops.GetConfigInTx(ctx, t.tx, key)
|
|
}
|
|
|
|
func (t *embeddedTransaction) SetMetadata(ctx context.Context, key, value string) error {
|
|
t.dirty.MarkDirty("metadata")
|
|
return issueops.SetMetadataInTx(ctx, t.tx, key, value)
|
|
}
|
|
|
|
func (t *embeddedTransaction) GetMetadata(ctx context.Context, key string) (string, error) {
|
|
return issueops.GetMetadataInTx(ctx, t.tx, key)
|
|
}
|
|
|
|
func (t *embeddedTransaction) SetLocalMetadata(ctx context.Context, key, value string) error {
|
|
return issueops.SetLocalMetadataInTx(ctx, t.tx, key, value)
|
|
}
|
|
|
|
func (t *embeddedTransaction) GetLocalMetadata(ctx context.Context, key string) (string, error) {
|
|
return issueops.GetLocalMetadataInTx(ctx, t.tx, key)
|
|
}
|
|
|
|
func (t *embeddedTransaction) AddComment(ctx context.Context, issueID, actor, comment string) error {
|
|
return fmt.Errorf("embeddedTransaction: AddComment not implemented")
|
|
}
|
|
|
|
func (t *embeddedTransaction) ImportIssueComment(ctx context.Context, issueID, author, text string, createdAt time.Time) (*types.Comment, error) {
|
|
return nil, fmt.Errorf("embeddedTransaction: ImportIssueComment not implemented")
|
|
}
|
|
|
|
func (t *embeddedTransaction) GetIssueComments(ctx context.Context, issueID string) ([]*types.Comment, error) {
|
|
return nil, fmt.Errorf("embeddedTransaction: GetIssueComments not implemented")
|
|
}
|
|
|
|
func (t *embeddedTransaction) CreateIssueImport(ctx context.Context, issue *types.Issue, actor string, skipPrefixValidation bool) error {
|
|
bc, err := issueops.NewBatchContext(ctx, t.tx, storage.BatchCreateOptions{SkipPrefixValidation: skipPrefixValidation})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
result, err := issueops.CreateIssueInTxWithResult(ctx, t.tx, bc, issue, actor)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for table := range issueops.CreateIssueDirtyTables(ctx, issue, result) {
|
|
t.dirty.MarkDirty(table)
|
|
}
|
|
return nil
|
|
}
|