Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
.venv
__pycache__
.beads
.entity-manager
.coverage
coverage.xml
htmlcov/
*.pyc
*.pyo
*.egg-info/
dist/
build/
.pytest_cache/
AGENTS.md
@AGENTS.md
.gitattributes
7 changes: 7 additions & 0 deletions src/entity_manager/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Backend implementations for entity manager."""

from entity_manager.backends.beads import BeadsBackend
from entity_manager.backends.github import GitHubBackend
from entity_manager.backends.notion import NotionBackend

__all__ = ["BeadsBackend", "GitHubBackend", "NotionBackend"]
46 changes: 31 additions & 15 deletions src/entity_manager/backends/beads.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _bead_to_entity(self, bead: dict[str, Any]) -> Entity:
labels[label] = ""

entity = Entity(
id=str(bead["id"]), # Using the hash ID directly (bd-a1b2 format), converted to str
id=str(bead["id"]), # Using the bead ID directly (e.g., "entity-manager-abc" or "bd-a1b2")
title=bead.get("title", ""),
description=bead.get("description", ""),
labels=labels,
Expand All @@ -116,14 +116,11 @@ def _entity_id_to_bead_id(self, entity_id: str) -> str:
entity_id: Entity ID (string)

Returns:
Beads ID string (bd-xxxx format)
Beads ID string (project-prefix-hash format)
"""
# If already in beads format, return as-is
if entity_id.startswith("bd-"):
return entity_id

# Otherwise, assume it's a bead hash ID without the bd- prefix
return f"bd-{entity_id}"
# Beads IDs are already in the correct format (e.g., "entity-manager-abc" or "bd-a1b2")
# No conversion needed - return as-is
return entity_id

def create(
self,
Expand Down Expand Up @@ -162,7 +159,11 @@ def read(self, entity_id: str) -> Entity:
logger.info("Reading beads issue", entity_id=bead_id)

result = self._run_bd_command(["show", bead_id, "--json"])
if isinstance(result, dict):
if isinstance(result, list) and len(result) > 0:
entity = self._bead_to_entity(result[0])
logger.debug("Beads issue read successfully", entity_id=bead_id)
return entity
elif isinstance(result, dict):
entity = self._bead_to_entity(result)
logger.debug("Beads issue read successfully", entity_id=bead_id)
return entity
Expand Down Expand Up @@ -268,9 +269,16 @@ def add_link(self, source_id: str, target_ids: list[str], link_type: str) -> Non

# Map entity manager link types to beads dependency types
# beads supports: blocks, related, parent-child, discovered-from
beads_type = link_type
if link_type == "relates_to":
beads_type = "related"
link_type_lower = link_type.lower().replace("_", "-").replace(" ", "-")
beads_type_map = {
"relates-to": "related",
"blocked-by": "blocks",
"blocking": "blocks", # Inverse relationship
"parent": "parent-child",
"child": "parent-child",
"children": "parent-child",
}
beads_type = beads_type_map.get(link_type_lower, link_type_lower)

for target_id in target_ids:
target_bead_id = self._entity_id_to_bead_id(target_id)
Expand All @@ -288,9 +296,17 @@ def remove_link(self, source_id: str, target_ids: list[str], link_type: str, rec
link_type=link_type,
)

beads_type = link_type
if link_type == "relates_to":
beads_type = "related"
# Map entity manager link types to beads dependency types
link_type_lower = link_type.lower().replace("_", "-").replace(" ", "-")
beads_type_map = {
"relates-to": "related",
"blocked-by": "blocks",
"blocking": "blocks", # Inverse relationship
"parent": "parent-child",
"child": "parent-child",
"children": "parent-child",
}
beads_type = beads_type_map.get(link_type_lower, link_type_lower)

for target_id in target_ids:
target_bead_id = self._entity_id_to_bead_id(target_id)
Expand Down
4 changes: 3 additions & 1 deletion src/entity_manager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ def update(
@app.command
def delete(*entity_ids: str) -> None:
"""Delete one or more entities."""
import builtins

backend = get_backend()
backend.delete(list(entity_ids))
backend.delete(builtins.list(entity_ids))
print(f"Deleted {len(entity_ids)} entity(ies)")


Expand Down
Loading