diff --git a/src/api/blackboard_routes.py b/src/api/blackboard_routes.py index 028aa44..0eb6ab6 100644 --- a/src/api/blackboard_routes.py +++ b/src/api/blackboard_routes.py @@ -119,12 +119,20 @@ async def create_task(project_id: str, body: Dict[str, Any]): desc = body.get("description", "") or "" title = await _generate_title(desc) or ((desc[:30] + "…") if len(desc) > 30 else (desc or "新军令")) + # #04: assignee 由 @mention 推断 + description_text = body.get("description") or "" + description_mentions = _extract_mentions(description_text) + assignee = description_mentions[0] if description_mentions else None + # 兼容:显式传 assignee 且无 @mention 时保留(deprecated) + if not assignee and body.get("assignee"): + assignee = body.get("assignee") + task = Task( id=task_id, title=title, description=body.get("description"), task_type=body.get("task_type", "coding"), priority=body.get("priority", 5), - assignee=body.get("assignee"), + assignee=assignee, assigned_by=body.get("assigned_by", "user"), depends_on=json.dumps(body["depends_on"]) if "depends_on" in body else None, parent_task=body.get("parent_task"), @@ -288,24 +296,27 @@ async def get_comments(project_id: str, task_id: str, async def add_comment(project_id: str, task_id: str, body: Dict[str, Any]): bb = _bb(project_id) mentions_raw = body.get("mentions") - cid = bb.add_comment(task_id, body["author"], body["body"], + comment_body = body["body"] + + # #04: 自动从 body 提取 @mention,与显式传的 mentions 取并集 + auto_mentions = _extract_mentions(comment_body) + if isinstance(mentions_raw, str): + try: + explicit_mentions = json.loads(mentions_raw) + except Exception: + explicit_mentions = [] + elif isinstance(mentions_raw, list): + explicit_mentions = mentions_raw + else: + explicit_mentions = [] + merged_mentions = list(set(explicit_mentions + auto_mentions)) + + cid = bb.add_comment(task_id, body["author"], comment_body, comment_type=body.get("comment_type", "general"), - mentions=mentions_raw) - # v2.9 #01: 写入 mention_queue - if mentions_raw: - if isinstance(mentions_raw, str): - import json as _json - try: - mentions_list = _json.loads(mentions_raw) - except Exception: - mentions_list = [] - elif isinstance(mentions_raw, list): - mentions_list = mentions_raw - else: - mentions_list = [] - if mentions_list: - bb.record_mentions(cid, task_id, mentions_list) - return {"ok": True, "comment_id": cid} + mentions=merged_mentions) + if merged_mentions: + bb.record_mentions(cid, task_id, merged_mentions) + return {"ok": True, "comment_id": cid, "mentions": merged_mentions} # --- Outputs ---