(user_message, history, yolo=False, use_plan=False, no_plan=False, _in_subtask=False, _plan_rag_block="")
| 611 | |
| 612 | |
| 613 | def run_agent(user_message, history, yolo=False, use_plan=False, no_plan=False, _in_subtask=False, _plan_rag_block=""): |
| 614 | # Reset streaming flag at start of each agent turn |
| 615 | import core.inference_v2 as _inf_mod |
| 616 | _inf_mod._last_was_streamed = False |
| 617 | |
| 618 | # Learn preferences from natural language in the user's message |
| 619 | _get_learning().learn_from_message(user_message) |
| 620 | |
| 621 | # ── Explicit peer delegation ────────────────────────────────────────────── |
| 622 | # Handle: "ask gemini to X", "have claude do X", etc. |
| 623 | # The peer runs, its output is injected as context, then the agent applies it. |
| 624 | if not _in_subtask: |
| 625 | _peer_name, _peer_task = _detect_peer_delegation(user_message) |
| 626 | if _peer_name and _peer_task: |
| 627 | from core.peer_cli import get_peer_cli_manager |
| 628 | _mgr = get_peer_cli_manager() |
| 629 | _by_name = {c.name: c for c in _mgr.available()} |
| 630 | if _peer_name in _by_name: |
| 631 | _cli = _by_name[_peer_name] |
| 632 | |
| 633 | # For review/check/verify tasks, build rich context with current file contents |
| 634 | # so the peer actually has something to review. |
| 635 | _REVIEW_KW = { |
| 636 | "check", "review", "verify", "test", "examine", |
| 637 | "correct", "validate", "look at", "is it right", "did i" |
| 638 | } |
| 639 | _is_review = any(k in _peer_task.lower() for k in _REVIEW_KW) |
| 640 | |
| 641 | # ── Design-only phase detection ─────────────────────────────── |
| 642 | # When the peer is asked to "design / plan / spec / outline" |
| 643 | # without any implement/build/code verb, we use prose instructions |
| 644 | # and save the output as a .md design document instead of trying |
| 645 | # to extract code blocks — which would corrupt the pipeline. |
| 646 | _STRONG_DESIGN = re.compile( |
| 647 | r'\b(design|plan|spec(?:ify)?|specification|outline|blueprint|' |
| 648 | r'architecture|feature\s+list|roadmap|requirements?)\b', |
| 649 | re.IGNORECASE, |
| 650 | ) |
| 651 | _STRONG_IMPLEMENT = re.compile( |
| 652 | r'\b(implement|build|code|develop|program|write\s+(?:code|it|the)|' |
| 653 | r'make\s+it\s+work|working\s+version)\b', |
| 654 | re.IGNORECASE, |
| 655 | ) |
| 656 | _is_design_only = ( |
| 657 | not _is_review # review tasks always use code output format |
| 658 | and bool(_STRONG_DESIGN.search(_peer_task)) |
| 659 | and not bool(_STRONG_IMPLEMENT.search(_peer_task)) |
| 660 | ) |
| 661 | |
| 662 | # Output format instructions — Codey extracts code blocks to write files. |
| 663 | # Claude -p returns plain text; without explicit format instructions it |
| 664 | # asks for permission or returns prose instead of extractable code. |
| 665 | _FORMAT_INSTRUCTIONS = ( |
| 666 | "\n\nOUTPUT FORMAT (required — Codey will parse this automatically):\n" |
| 667 | "You are responding to an automated system. Do NOT ask for permission.\n" |
| 668 | "Do NOT ask clarifying questions. Act immediately.\n" |
| 669 | "For each file to create or modify, output it using this exact format:\n\n" |
| 670 | "**`filename.py`**\n" |
no test coverage detected