Implement hierarchical child ID generation (bd-171)

- Add GetNextChildID to storage interface for generating child IDs
- Implement in SQLiteStorage with atomic counter using child_counters table
- Implement in MemoryStorage with in-memory counter
- Add --parent flag to bd create command
- Support hierarchical IDs (bd-a3f8e9.1, bd-a3f8e9.1.5) in CreateIssue
- Validate parent exists when creating hierarchical issues
- Enforce max depth of 3 levels
- Update ID validation to accept hierarchical IDs with dots
- Add comprehensive tests for child ID generation
- Manual testing confirms: sequential children, nested hierarchies, depth enforcement
This commit is contained in:
Steve Yegge
2025-10-30 14:42:08 -07:00
parent 6c31329ef8
commit 3ed2aa07cb
6 changed files with 319 additions and 13 deletions

View File

@@ -827,6 +827,32 @@ func (m *MemoryStorage) ClearDirtyIssuesByID(ctx context.Context, issueIDs []str
return nil
}
// ID Generation
func (m *MemoryStorage) GetNextChildID(ctx context.Context, parentID string) (string, error) {
m.mu.Lock()
defer m.mu.Unlock()
// Validate parent exists
if _, exists := m.issues[parentID]; !exists {
return "", fmt.Errorf("parent issue %s does not exist", parentID)
}
// Calculate depth (count dots)
depth := strings.Count(parentID, ".")
if depth >= 3 {
return "", fmt.Errorf("maximum hierarchy depth (3) exceeded for parent %s", parentID)
}
// Get or initialize counter for this parent
counter := m.counters[parentID]
counter++
m.counters[parentID] = counter
// Format as parentID.counter
childID := fmt.Sprintf("%s.%d", parentID, counter)
return childID, nil
}
// Config
func (m *MemoryStorage) SetConfig(ctx context.Context, key, value string) error {
m.mu.Lock()