fix: TransferEncodingError on task extraction failure

- brain.py: unwrap JSON array responses from Claude (occasional array
  instead of object caused AttributeError → broken chunked stream)
- main.py: wrap extract_task_fields() in try/except so any extraction
  failure gracefully falls back to regex — generator always completes
- tools.py: _resolve_project() uses alphanumeric-stripped matching so
  "Generaladm" resolves to General/Admin via identifier prefix match.
  Word-overlap fallback added. Default changed from Agent Ecosystem to
  General/Admin (correct catch-all bucket)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-02 06:09:45 +00:00
parent 6cb29d94e6
commit 4a09def6dc
3 changed files with 33 additions and 5 deletions
+22 -3
View File
@@ -147,14 +147,33 @@ async def get_plane_issues(project_hint: str) -> tuple[str, list[dict]]:
def _resolve_project(projects: list[dict], hint: str | None) -> dict:
import re as _re
if hint:
hint_lower = hint.lower()
hint_alpha = _re.sub(r"[^a-z0-9]", "", hint_lower) # "generaladm" from "Generaladm"
for p in projects:
if hint_lower in p["name"].lower():
name_lower = p["name"].lower()
ident_lower = p.get("identifier", "").lower()
name_alpha = _re.sub(r"[^a-z0-9]", "", name_lower) # "generaladmin"
# Exact or substring name match
if hint_lower in name_lower or name_lower in hint_lower:
return p
# Default: Agent Ecosystem
# Identifier match (e.g. "generaladm" == "generaladm")
if hint_alpha == ident_lower or hint_alpha == _re.sub(r"[^a-z0-9]", "", ident_lower):
return p
# Stripped prefix match (e.g. "generaladm" starts "generaladmin")
if name_alpha.startswith(hint_alpha) or hint_alpha.startswith(name_alpha):
return p
# Word overlap fallback — any significant word of hint in project name
hint_words = {w for w in hint_lower.split() if len(w) > 2}
for p in projects:
if hint_words & set(p["name"].lower().split()):
return p
# Default: General / Admin (catch-all bucket)
for p in projects:
if "agent" in p["name"].lower():
if "general" in p["name"].lower():
return p
return projects[0]