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>
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package issueops
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// GetStaleIssuesInTx returns issues that haven't been updated within the
|
|
// given number of days. Only non-ephemeral issues are considered. When
|
|
// filter.Status is empty, open and in_progress issues are returned.
|
|
// Results are ordered by updated_at ascending (stalest first).
|
|
//
|
|
// nolint:gosec // G201: statusClause contains only literal SQL or a single ? placeholder
|
|
func GetStaleIssuesInTx(ctx context.Context, tx *sql.Tx, filter types.StaleFilter) ([]*types.Issue, error) {
|
|
cutoff := time.Now().UTC().AddDate(0, 0, -filter.Days)
|
|
|
|
statusClause := "status IN ('open', 'in_progress')"
|
|
if filter.Status != "" {
|
|
statusClause = "status = ?"
|
|
}
|
|
|
|
query := fmt.Sprintf(`
|
|
SELECT id FROM issues
|
|
WHERE updated_at < ?
|
|
AND %s
|
|
AND (ephemeral = 0 OR ephemeral IS NULL)
|
|
ORDER BY updated_at ASC
|
|
`, statusClause)
|
|
args := []interface{}{cutoff}
|
|
if filter.Status != "" {
|
|
args = append(args, filter.Status)
|
|
}
|
|
|
|
if filter.Limit > 0 {
|
|
query += fmt.Sprintf(" LIMIT %d", filter.Limit)
|
|
}
|
|
|
|
rows, err := tx.QueryContext(ctx, query, args...)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get stale issues: %w", err)
|
|
}
|
|
|
|
// Collect IDs first, then batch-fetch full issues.
|
|
// Close rows explicitly before the nested fetch — MySQL/Dolt drivers
|
|
// can't handle multiple active result sets on one connection.
|
|
var ids []string
|
|
for rows.Next() {
|
|
var id string
|
|
if err := rows.Scan(&id); err != nil {
|
|
rows.Close()
|
|
return nil, fmt.Errorf("failed to scan stale issue id: %w", err)
|
|
}
|
|
ids = append(ids, id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
rows.Close()
|
|
return nil, fmt.Errorf("stale issues rows: %w", err)
|
|
}
|
|
rows.Close()
|
|
|
|
if len(ids) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
// GetIssuesByIDsInTx returns issues in arbitrary order (WHERE IN),
|
|
// so re-order to preserve the updated_at ASC ordering from the query.
|
|
issues, err := GetIssuesByIDsInTx(ctx, tx, ids, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
issueByID := make(map[string]*types.Issue, len(issues))
|
|
for _, iss := range issues {
|
|
if iss != nil {
|
|
issueByID[iss.ID] = iss
|
|
}
|
|
}
|
|
|
|
ordered := make([]*types.Issue, 0, len(ids))
|
|
for _, id := range ids {
|
|
if iss, ok := issueByID[id]; ok {
|
|
ordered = append(ordered, iss)
|
|
}
|
|
}
|
|
|
|
return ordered, nil
|
|
}
|