feat: multi-project routing — project_name in bridge, per-project channels, extension filtering

This commit is contained in:
2026-03-07 14:07:40 +09:00
parent 2a4ef8d0d9
commit 2c56fc7607
4 changed files with 153 additions and 166 deletions

View File

@@ -43,6 +43,7 @@ class ApprovalRequest:
timestamp: float
status: str = "pending"
discord_message_id: int = 0
project_name: str = "" # Project routing key
@dataclass
@@ -72,11 +73,14 @@ class BridgeProtocol:
def get_pending_requests(self) -> list[ApprovalRequest]:
"""Read all pending approval requests."""
requests = []
fields = {f.name for f in ApprovalRequest.__dataclass_fields__.values()}
for f in self.pending_dir.glob("*.json"):
try:
data = json.loads(f.read_text(encoding="utf-8-sig"))
if data.get("status") == "pending":
requests.append(ApprovalRequest(**data))
# Filter to known fields only
filtered = {k: v for k, v in data.items() if k in fields}
requests.append(ApprovalRequest(**filtered))
except (json.JSONDecodeError, TypeError, OSError) as e:
logger.warning(f"Bad pending request {f.name}: {e}")
return requests
@@ -106,7 +110,7 @@ class BridgeProtocol:
except (json.JSONDecodeError, OSError):
pass
def write_command(self, conversation_id: str, text: str):
def write_command(self, conversation_id: str, text: str, *, project_name: str = ""):
"""Write a user text command for Antigravity to consume."""
cmd_id = f"{int(time.time() * 1000)}"
filepath = self.commands_dir / f"{cmd_id}.json"
@@ -114,6 +118,7 @@ class BridgeProtocol:
data = {
"id": cmd_id,
"conversation_id": conversation_id,
"project_name": project_name,
"text": text,
"timestamp": time.time(),
"consumed": False,
@@ -123,5 +128,5 @@ class BridgeProtocol:
json.dumps(data, ensure_ascii=False, indent=2),
encoding="utf-8"
)
logger.info(f"Command written: {cmd_id} for {conversation_id[:8]}")
logger.info(f"Command written: {cmd_id} → project={project_name}")
return cmd_id