fix(memory): implement GetReadyWork/GetBlockedIssues + child counters
Fixes #543, #544, #545, #546 (no-db mode regressions) Memory backend fixes: - GetReadyWork now properly excludes issues with open blocks dependencies - GetBlockedIssues now includes issues with status=blocked (even with 0 blockers) - LoadFromIssues initializes hierarchical child counters from existing IDs so repeated --parent creates bd-xxx.1, bd-xxx.2, etc. JSONL path discovery: - findJSONLPath works in no-db mode when dbPath is empty - Honors BEADS_JSONL environment variable override - Falls back to locating .beads directory Based on PR #547 by @joelklabo - cherry-picked core fixes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -98,6 +98,14 @@ func (m *MemoryStorage) LoadFromIssues(issues []*types.Issue) error {
|
||||
m.counters[prefix] = num
|
||||
}
|
||||
}
|
||||
|
||||
// Update hierarchical child counters based on issue ID
|
||||
// e.g. "bd-a3f8e9.2" -> parent "bd-a3f8e9" counter 2
|
||||
if parentID, childNum, ok := extractParentAndChildNumber(issue.ID); ok {
|
||||
if m.counters[parentID] < childNum {
|
||||
m.counters[parentID] = childNum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -157,6 +165,25 @@ func extractPrefixAndNumber(id string) (string, int) {
|
||||
return prefix, num
|
||||
}
|
||||
|
||||
// extractParentAndChildNumber extracts the parent ID and numeric child counter from an issue ID like
|
||||
// "bd-a3f8e9.2" -> ("bd-a3f8e9", 2, true).
|
||||
func extractParentAndChildNumber(id string) (string, int, bool) {
|
||||
lastDot := strings.LastIndex(id, ".")
|
||||
if lastDot == -1 {
|
||||
return "", 0, false
|
||||
}
|
||||
|
||||
parentID := id[:lastDot]
|
||||
suffix := id[lastDot+1:]
|
||||
|
||||
var num int
|
||||
if _, err := fmt.Sscanf(suffix, "%d", &num); err != nil {
|
||||
return "", 0, false
|
||||
}
|
||||
|
||||
return parentID, num, true
|
||||
}
|
||||
|
||||
// CreateIssue creates a new issue
|
||||
func (m *MemoryStorage) CreateIssue(ctx context.Context, issue *types.Issue, actor string) error {
|
||||
m.mu.Lock()
|
||||
@@ -867,16 +894,219 @@ func (m *MemoryStorage) GetIssuesByLabel(ctx context.Context, label string) ([]*
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// Stub implementations for other required methods
|
||||
// GetReadyWork returns issues that are ready to work on (no open blockers)
|
||||
func (m *MemoryStorage) GetReadyWork(ctx context.Context, filter types.WorkFilter) ([]*types.Issue, error) {
|
||||
// Simplified: return open issues with no blocking dependencies
|
||||
return m.SearchIssues(ctx, "", types.IssueFilter{
|
||||
Status: func() *types.Status { s := types.StatusOpen; return &s }(),
|
||||
})
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
var results []*types.Issue
|
||||
|
||||
for _, issue := range m.issues {
|
||||
// Status filtering: default to open OR in_progress if not specified
|
||||
if filter.Status == "" {
|
||||
if issue.Status != types.StatusOpen && issue.Status != types.StatusInProgress {
|
||||
continue
|
||||
}
|
||||
} else if issue.Status != filter.Status {
|
||||
continue
|
||||
}
|
||||
|
||||
// Priority filtering
|
||||
if filter.Priority != nil && issue.Priority != *filter.Priority {
|
||||
continue
|
||||
}
|
||||
|
||||
// Unassigned takes precedence over Assignee filter
|
||||
if filter.Unassigned {
|
||||
if issue.Assignee != "" {
|
||||
continue
|
||||
}
|
||||
} else if filter.Assignee != nil {
|
||||
if issue.Assignee != *filter.Assignee {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Label filtering (AND semantics)
|
||||
if len(filter.Labels) > 0 {
|
||||
issueLabels := m.labels[issue.ID]
|
||||
hasAllLabels := true
|
||||
for _, reqLabel := range filter.Labels {
|
||||
found := false
|
||||
for _, label := range issueLabels {
|
||||
if label == reqLabel {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
hasAllLabels = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasAllLabels {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Label filtering (OR semantics)
|
||||
if len(filter.LabelsAny) > 0 {
|
||||
issueLabels := m.labels[issue.ID]
|
||||
hasAnyLabel := false
|
||||
for _, reqLabel := range filter.LabelsAny {
|
||||
for _, label := range issueLabels {
|
||||
if label == reqLabel {
|
||||
hasAnyLabel = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if hasAnyLabel {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasAnyLabel {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Skip issues with any open 'blocks' dependencies
|
||||
if len(m.getOpenBlockers(issue.ID)) > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
issueCopy := *issue
|
||||
if deps, ok := m.dependencies[issue.ID]; ok {
|
||||
issueCopy.Dependencies = deps
|
||||
}
|
||||
if labels, ok := m.labels[issue.ID]; ok {
|
||||
issueCopy.Labels = labels
|
||||
}
|
||||
if comments, ok := m.comments[issue.ID]; ok {
|
||||
issueCopy.Comments = comments
|
||||
}
|
||||
|
||||
results = append(results, &issueCopy)
|
||||
}
|
||||
|
||||
// Default to hybrid sort for backwards compatibility
|
||||
sortPolicy := filter.SortPolicy
|
||||
if sortPolicy == "" {
|
||||
sortPolicy = types.SortPolicyHybrid
|
||||
}
|
||||
|
||||
switch sortPolicy {
|
||||
case types.SortPolicyOldest:
|
||||
sort.Slice(results, func(i, j int) bool {
|
||||
return results[i].CreatedAt.Before(results[j].CreatedAt)
|
||||
})
|
||||
case types.SortPolicyPriority:
|
||||
sort.Slice(results, func(i, j int) bool {
|
||||
if results[i].Priority != results[j].Priority {
|
||||
return results[i].Priority < results[j].Priority
|
||||
}
|
||||
return results[i].CreatedAt.Before(results[j].CreatedAt)
|
||||
})
|
||||
case types.SortPolicyHybrid:
|
||||
fallthrough
|
||||
default:
|
||||
cutoff := time.Now().Add(-48 * time.Hour)
|
||||
sort.Slice(results, func(i, j int) bool {
|
||||
iRecent := results[i].CreatedAt.After(cutoff)
|
||||
jRecent := results[j].CreatedAt.After(cutoff)
|
||||
if iRecent != jRecent {
|
||||
return iRecent // recent first
|
||||
}
|
||||
if iRecent {
|
||||
if results[i].Priority != results[j].Priority {
|
||||
return results[i].Priority < results[j].Priority
|
||||
}
|
||||
}
|
||||
return results[i].CreatedAt.Before(results[j].CreatedAt)
|
||||
})
|
||||
}
|
||||
|
||||
// Apply limit
|
||||
if filter.Limit > 0 && len(results) > filter.Limit {
|
||||
results = results[:filter.Limit]
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// getOpenBlockers returns the IDs of blockers that are currently open/in_progress/blocked.
|
||||
// The caller must hold at least a read lock.
|
||||
func (m *MemoryStorage) getOpenBlockers(issueID string) []string {
|
||||
deps := m.dependencies[issueID]
|
||||
if len(deps) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
blockers := make([]string, 0)
|
||||
for _, dep := range deps {
|
||||
if dep.Type != types.DepBlocks {
|
||||
continue
|
||||
}
|
||||
blocker, ok := m.issues[dep.DependsOnID]
|
||||
if !ok {
|
||||
// If the blocker is missing, treat it as still blocking (data is incomplete)
|
||||
blockers = append(blockers, dep.DependsOnID)
|
||||
continue
|
||||
}
|
||||
switch blocker.Status {
|
||||
case types.StatusOpen, types.StatusInProgress, types.StatusBlocked:
|
||||
blockers = append(blockers, blocker.ID)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Strings(blockers)
|
||||
return blockers
|
||||
}
|
||||
|
||||
// GetBlockedIssues returns issues that are blocked by other issues
|
||||
func (m *MemoryStorage) GetBlockedIssues(ctx context.Context) ([]*types.BlockedIssue, error) {
|
||||
return nil, nil
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
var results []*types.BlockedIssue
|
||||
|
||||
for _, issue := range m.issues {
|
||||
// Only consider non-closed, non-tombstone issues
|
||||
if issue.Status == types.StatusClosed || issue.Status == types.StatusTombstone {
|
||||
continue
|
||||
}
|
||||
|
||||
blockers := m.getOpenBlockers(issue.ID)
|
||||
if issue.Status != types.StatusBlocked && len(blockers) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
issueCopy := *issue
|
||||
if deps, ok := m.dependencies[issue.ID]; ok {
|
||||
issueCopy.Dependencies = deps
|
||||
}
|
||||
if labels, ok := m.labels[issue.ID]; ok {
|
||||
issueCopy.Labels = labels
|
||||
}
|
||||
if comments, ok := m.comments[issue.ID]; ok {
|
||||
issueCopy.Comments = comments
|
||||
}
|
||||
|
||||
results = append(results, &types.BlockedIssue{
|
||||
Issue: issueCopy,
|
||||
BlockedByCount: len(blockers),
|
||||
BlockedBy: blockers,
|
||||
})
|
||||
}
|
||||
|
||||
// Match SQLite behavior: order by priority ascending
|
||||
sort.Slice(results, func(i, j int) bool {
|
||||
if results[i].Priority != results[j].Priority {
|
||||
return results[i].Priority < results[j].Priority
|
||||
}
|
||||
return results[i].CreatedAt.Before(results[j].CreatedAt)
|
||||
})
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (m *MemoryStorage) GetEpicsEligibleForClosure(ctx context.Context) ([]*types.EpicStatus, error) {
|
||||
|
||||
Reference in New Issue
Block a user