This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
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

122 lines
3.2 KiB
Go

package issueops
import (
"context"
"database/sql"
"fmt"
"strings"
)
// SQLQuerier is the subset of *sql.Tx / *sql.DB needed by the commit helpers.
type SQLQuerier interface {
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
// HasPendingChanges checks whether there are any committable changes in the
// Dolt working set, excluding tables matched by dolt_ignore.
func HasPendingChanges(ctx context.Context, db SQLQuerier) (bool, error) {
var count int
err := db.QueryRowContext(ctx, `
SELECT COUNT(*) FROM dolt_status s
WHERE NOT EXISTS (
SELECT 1 FROM dolt_ignore di
WHERE di.ignored = 1
AND s.table_name LIKE di.pattern
)`).Scan(&count)
if err != nil {
return false, fmt.Errorf("failed to check status: %w", err)
}
return count > 0, nil
}
// BuildBatchCommitMessage generates a descriptive commit message summarizing
// what changed since the last commit by querying dolt_diff against HEAD.
// It reports issue-level create/update/delete counts and lists any other
// tables (labels, comments, events, etc.) that have uncommitted changes.
func BuildBatchCommitMessage(ctx context.Context, db SQLQuerier, actor string) string {
if actor == "" {
actor = "bd"
}
var added, modified, removed int
rows, err := db.QueryContext(ctx, `
SELECT diff_type, COUNT(*) as cnt
FROM dolt_diff('HEAD', 'WORKING', 'issues')
GROUP BY diff_type
`)
if err == nil {
defer rows.Close()
for rows.Next() {
var diffType string
var count int
if scanErr := rows.Scan(&diffType, &count); scanErr == nil {
switch diffType {
case "added":
added = count
case "modified":
modified = count
case "removed":
removed = count
}
}
}
_ = rows.Err()
}
var otherTables []string
statusRows, statusErr := db.QueryContext(ctx, `
SELECT table_name FROM dolt_status s
WHERE table_name != 'issues'
AND NOT EXISTS (
SELECT 1 FROM dolt_ignore di
WHERE di.ignored = 1
AND s.table_name LIKE di.pattern
)`)
if statusErr == nil {
defer statusRows.Close()
for statusRows.Next() {
var table string
if scanErr := statusRows.Scan(&table); scanErr == nil {
otherTables = append(otherTables, table)
}
}
_ = statusRows.Err()
}
msg := fmt.Sprintf("bd: batch commit by %s", actor)
var parts []string
if added > 0 {
parts = append(parts, fmt.Sprintf("%d created", added))
}
if modified > 0 {
parts = append(parts, fmt.Sprintf("%d updated", modified))
}
if removed > 0 {
parts = append(parts, fmt.Sprintf("%d deleted", removed))
}
if len(parts) > 0 {
msg += " — " + strings.Join(parts, ", ")
}
if len(otherTables) > 0 {
msg += fmt.Sprintf(" (+ %s)", strings.Join(otherTables, ", "))
}
return msg
}
// IsNothingToCommitError returns true if the error indicates there was nothing
// to commit (Dolt may report this even when dolt_status showed changes).
func IsNothingToCommitError(err error) bool {
if err == nil {
return false
}
s := strings.ToLower(err.Error())
if strings.Contains(s, "nothing to commit") {
return true
}
if strings.Contains(s, "no changes") && strings.Contains(s, "commit") {
return true
}
return false
}