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

114 lines
3.1 KiB
Go

package issueops
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/steveyegge/beads/internal/types"
)
// GetMoleculeProgressInTx returns progress stats for a molecule within an
// existing transaction. Routes to the correct table (issues/wisps) automatically.
//
//nolint:gosec // G201: table names come from WispTableRouting (hardcoded constants)
func GetMoleculeProgressInTx(ctx context.Context, tx *sql.Tx, moleculeID string) (*types.MoleculeProgressStats, error) {
stats := &types.MoleculeProgressStats{
MoleculeID: moleculeID,
}
isWisp := IsActiveWispInTx(ctx, tx, moleculeID)
issueTable, _, _, depTable := WispTableRouting(isWisp)
parentCol := "depends_on_issue_id"
if isWisp {
parentCol = "depends_on_wisp_id"
}
// Get molecule title.
var title sql.NullString
err := tx.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.
depRows, err := tx.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()
return nil, fmt.Errorf("get molecule progress: scan child: %w", err)
}
childIDs = append(childIDs, id)
}
_ = depRows.Close()
if err := depRows.Err(); err != nil {
return nil, fmt.Errorf("get molecule progress: child rows: %w", err)
}
// Step 2: Batch-fetch status for all children.
// 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 := make([]string, len(batch))
args := make([]any, len(batch))
for i, id := range batch {
placeholders[i] = "?"
args[i] = id
}
inClause := strings.Join(placeholders, ",")
query := fmt.Sprintf("SELECT id, status FROM %s WHERE id IN (%s)", issueTable, inClause)
statusRows, err := tx.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, fmt.Errorf("get molecule progress: scan status: %w", 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
}