feat(ready,blocked): Add --parent flag for scoping by epic/bead desce… (#743)
* feat(ready,blocked): Add --parent flag for scoping by epic/bead descendants
Add --parent flag to `bd ready` and `bd blocked` CLI commands and MCP tools
to filter results to all descendants of a specific epic or bead.
## Backward Compatibility
- CLI: New optional --parent flag; existing usage unchanged
- RPC: New `blocked` operation added (was missing); existing operations unchanged
- MCP: New optional `parent` parameter; existing calls work as before
- Storage interface: GetBlockedIssues signature changed to accept WorkFilter
- All callers updated to pass empty filter for existing behavior
- Empty WorkFilter{} returns identical results to previous implementation
## Implementation Details
SQLite uses recursive CTE to traverse parent-child hierarchy:
WITH RECURSIVE descendants AS (
SELECT issue_id FROM dependencies
WHERE type = 'parent-child' AND depends_on_id = ?
UNION ALL
SELECT d.issue_id FROM dependencies d
JOIN descendants dt ON d.depends_on_id = dt.issue_id
WHERE d.type = 'parent-child'
)
SELECT issue_id FROM descendants
MemoryStorage implements equivalent recursive traversal with visited-set
cycle protection via collectDescendants helper.
Parent filter composes with existing filters (priority, labels, assignee, etc.)
as an additional WHERE clause - all filters are AND'd together.
## RPC Blocked Support
MCP beads_blocked() existed but daemon client raised NotImplementedError.
Added OpBlocked and handleBlocked to enable daemon RPC path, which was
previously broken. Now both CLI and daemon clients work for blocked queries.
## Changes
- internal/types/types.go: Add ParentID *string to WorkFilter
- internal/storage/sqlite/ready.go: Add recursive CTE for parent filtering
- internal/storage/memory/memory.go: Add getAllDescendants/collectDescendants
- internal/storage/storage.go: Update GetBlockedIssues interface signature
- cmd/bd/ready.go: Add --parent flag to ready and blocked commands
- internal/rpc/protocol.go: Add OpBlocked constant and BlockedArgs type
- internal/rpc/server_issues_epics.go: Add handleBlocked RPC handler
- internal/rpc/client.go: Add Blocked client method
- integrations/beads-mcp/: Add BlockedParams model and parent parameter
## Usage
bd ready --parent bd-abc # All ready descendants
bd ready --parent bd-abc --priority 1 # Combined with other filters
bd blocked --parent bd-abc # All blocked descendants
## Testing
Added 4 test cases for parent filtering:
- TestParentIDFilterDescendants: Verifies recursive traversal (grandchildren)
- TestParentIDWithOtherFilters: Verifies composition with priority filter
- TestParentIDWithBlockedDescendants: Verifies blocked issues excluded from ready
- TestParentIDEmptyParent: Verifies empty result for childless parent
* fix: Correct blockedCmd indentation and suppress gosec false positive
- Fix syntax error from incorrect indentation in blockedCmd Run function
- Add nolint:gosec comment for GetBlockedIssues SQL formatting (G201)
The filterSQL variable contains only parameterized WHERE clauses with
? placeholders, not user input
This commit is contained in:
@@ -12,6 +12,7 @@ from .config import load_config
|
||||
from .models import (
|
||||
AddDependencyParams,
|
||||
BlockedIssue,
|
||||
BlockedParams,
|
||||
CloseIssueParams,
|
||||
CreateIssueParams,
|
||||
InitParams,
|
||||
@@ -126,7 +127,7 @@ class BdClientBase(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def blocked(self) -> List[BlockedIssue]:
|
||||
async def blocked(self, params: Optional[BlockedParams] = None) -> List[BlockedIssue]:
|
||||
"""Get blocked issues."""
|
||||
pass
|
||||
|
||||
@@ -395,6 +396,8 @@ class BdCliClient(BdClientBase):
|
||||
args.append("--unassigned")
|
||||
if params.sort_policy:
|
||||
args.extend(["--sort", params.sort_policy])
|
||||
if params.parent_id:
|
||||
args.extend(["--parent", params.parent_id])
|
||||
|
||||
data = await self._run_command(*args)
|
||||
if not isinstance(data, list):
|
||||
@@ -664,13 +667,21 @@ class BdCliClient(BdClientBase):
|
||||
|
||||
return Stats.model_validate(data)
|
||||
|
||||
async def blocked(self) -> list[BlockedIssue]:
|
||||
async def blocked(self, params: BlockedParams | None = None) -> list[BlockedIssue]:
|
||||
"""Get blocked issues.
|
||||
|
||||
Args:
|
||||
params: Query parameters
|
||||
|
||||
Returns:
|
||||
List of blocked issues with blocking information
|
||||
"""
|
||||
data = await self._run_command("blocked")
|
||||
params = params or BlockedParams()
|
||||
args = ["blocked"]
|
||||
if params.parent_id:
|
||||
args.extend(["--parent", params.parent_id])
|
||||
|
||||
data = await self._run_command(*args)
|
||||
if not isinstance(data, list):
|
||||
return []
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ from .bd_client import BdClientBase, BdError
|
||||
from .models import (
|
||||
AddDependencyParams,
|
||||
BlockedIssue,
|
||||
BlockedParams,
|
||||
CloseIssueParams,
|
||||
CreateIssueParams,
|
||||
InitParams,
|
||||
@@ -432,6 +433,9 @@ class BdDaemonClient(BdClientBase):
|
||||
args["sort_policy"] = params.sort_policy
|
||||
if params.limit:
|
||||
args["limit"] = params.limit
|
||||
# Parent filtering (descendants of a bead/epic)
|
||||
if params.parent_id:
|
||||
args["parent_id"] = params.parent_id
|
||||
|
||||
data = await self._send_request("ready", args)
|
||||
issues_data = json.loads(data) if isinstance(data, str) else data
|
||||
@@ -451,18 +455,25 @@ class BdDaemonClient(BdClientBase):
|
||||
stats_data = {}
|
||||
return Stats(**stats_data)
|
||||
|
||||
async def blocked(self) -> List[BlockedIssue]:
|
||||
async def blocked(self, params: Optional[BlockedParams] = None) -> List[BlockedIssue]:
|
||||
"""Get blocked issues.
|
||||
|
||||
Args:
|
||||
params: Query parameters (optional)
|
||||
|
||||
Returns:
|
||||
List of blocked issues with their blockers
|
||||
|
||||
Note:
|
||||
This operation may not be implemented in daemon RPC yet
|
||||
"""
|
||||
# Note: blocked operation may not be in RPC protocol yet
|
||||
# This is a placeholder for when it's added
|
||||
raise NotImplementedError("Blocked operation not yet supported via daemon")
|
||||
params = params or BlockedParams()
|
||||
args: Dict[str, Any] = {}
|
||||
if params.parent_id:
|
||||
args["parent_id"] = params.parent_id
|
||||
|
||||
data = await self._send_request("blocked", args)
|
||||
issues_data = json.loads(data) if isinstance(data, str) else data
|
||||
if issues_data is None:
|
||||
return []
|
||||
return [BlockedIssue(**issue) for issue in issues_data]
|
||||
|
||||
async def inspect_migration(self) -> dict[str, Any]:
|
||||
"""Get migration plan and database state for agent analysis.
|
||||
|
||||
@@ -209,6 +209,13 @@ class ReadyWorkParams(BaseModel):
|
||||
labels_any: list[str] | None = None # OR: must have at least one
|
||||
unassigned: bool = False # Filter to only unassigned issues
|
||||
sort_policy: str | None = None # hybrid, priority, oldest
|
||||
parent_id: str | None = None # Filter to descendants of this bead/epic
|
||||
|
||||
|
||||
class BlockedParams(BaseModel):
|
||||
"""Parameters for querying blocked issues."""
|
||||
|
||||
parent_id: str | None = None # Filter to descendants of this bead/epic
|
||||
|
||||
|
||||
class ListIssuesParams(BaseModel):
|
||||
|
||||
@@ -18,6 +18,7 @@ if TYPE_CHECKING:
|
||||
from .models import (
|
||||
AddDependencyParams,
|
||||
BlockedIssue,
|
||||
BlockedParams,
|
||||
CloseIssueParams,
|
||||
CreateIssueParams,
|
||||
DependencyType,
|
||||
@@ -309,11 +310,14 @@ async def beads_ready_work(
|
||||
labels_any: Annotated[list[str] | None, "Filter by labels (OR: must have at least one)"] = None,
|
||||
unassigned: Annotated[bool, "Filter to only unassigned issues"] = False,
|
||||
sort_policy: Annotated[str | None, "Sort policy: hybrid (default), priority, oldest"] = None,
|
||||
parent: Annotated[str | None, "Filter to descendants of this bead/epic"] = None,
|
||||
) -> list[Issue]:
|
||||
"""Find issues with no blocking dependencies that are ready to work on.
|
||||
|
||||
Ready work = status is 'open' AND no blocking dependencies.
|
||||
Perfect for agents to claim next work!
|
||||
|
||||
Use 'parent' to filter to all descendants of an epic/bead.
|
||||
"""
|
||||
client = await _get_client()
|
||||
params = ReadyWorkParams(
|
||||
@@ -324,6 +328,7 @@ async def beads_ready_work(
|
||||
labels_any=labels_any,
|
||||
unassigned=unassigned,
|
||||
sort_policy=sort_policy,
|
||||
parent_id=parent,
|
||||
)
|
||||
return await client.ready(params)
|
||||
|
||||
@@ -535,13 +540,18 @@ async def beads_stats() -> Stats:
|
||||
return await client.stats()
|
||||
|
||||
|
||||
async def beads_blocked() -> list[BlockedIssue]:
|
||||
async def beads_blocked(
|
||||
parent: Annotated[str | None, "Filter to descendants of this bead/epic"] = None,
|
||||
) -> list[BlockedIssue]:
|
||||
"""Get blocked issues.
|
||||
|
||||
Returns issues that have blocking dependencies, showing what blocks them.
|
||||
|
||||
Use 'parent' to filter to all descendants of an epic/bead.
|
||||
"""
|
||||
client = await _get_client()
|
||||
return await client.blocked()
|
||||
params = BlockedParams(parent_id=parent)
|
||||
return await client.blocked(params)
|
||||
|
||||
|
||||
async def beads_inspect_migration() -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user