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

63 lines
1.8 KiB
Go

package issueops
import (
"context"
"database/sql"
"fmt"
)
func GetNextChildIDTx(ctx context.Context, tx *sql.Tx, parentID string) (string, error) {
counterTable, issueTable := "child_counters", "issues"
if IsActiveWispInTx(ctx, tx, parentID) {
counterTable, issueTable = "wisp_child_counters", "wisps"
}
var lastChild int
//nolint:gosec // G201: counterTable is one of two hardcoded constants.
err := tx.QueryRowContext(ctx,
fmt.Sprintf("SELECT last_child FROM %s WHERE parent_id = ?", counterTable),
parentID).Scan(&lastChild)
if err == sql.ErrNoRows {
lastChild = 0
} else if err != nil {
return "", fmt.Errorf("get next child ID: read counter: %w", err)
}
//nolint:gosec // G201: issueTable is one of two hardcoded constants.
rows, err := tx.QueryContext(ctx, fmt.Sprintf(`
SELECT id FROM %s
WHERE id LIKE CONCAT(?, '.%%')
AND id NOT LIKE CONCAT(?, '.%%.%%')
`, issueTable), parentID, parentID)
if err != nil {
return "", fmt.Errorf("get next child ID: query existing children: %w", err)
}
defer rows.Close()
for rows.Next() {
var id string
if err := rows.Scan(&id); err != nil {
return "", fmt.Errorf("get next child ID: scan child row: %w", err)
}
_, childNum, ok := ParseHierarchicalID(id)
if ok && childNum > lastChild {
lastChild = childNum
}
}
if err := rows.Err(); err != nil {
return "", fmt.Errorf("get next child ID: iterate children: %w", err)
}
nextChild := lastChild + 1
//nolint:gosec // G201: counterTable is one of two hardcoded constants.
if _, err := tx.ExecContext(ctx, fmt.Sprintf(`
INSERT INTO %s (parent_id, last_child) VALUES (?, ?)
ON DUPLICATE KEY UPDATE last_child = ?
`, counterTable), parentID, nextChild, nextChild); err != nil {
return "", fmt.Errorf("get next child ID: update counter: %w", err)
}
return fmt.Sprintf("%s.%d", parentID, nextChild), nil
}