diff --git a/agents/visualizer.py b/agents/visualizer.py index 05c9bf3..4fdc4b4 100644 --- a/agents/visualizer.py +++ b/agents/visualizer.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 """ -AI_Visual agent. +AI_Visualizer agent. -Generates placeholder PlantUML diagrams on demand when @AI_visual is -mentioned in a discussion. Provides scaffolding for future AI-powered +Generates placeholder PlantUML diagrams on demand when @AI_Visualizer (or @AI_visual) +is mentioned in a discussion. Provides scaffolding for future AI-powered diagram generation. """ from __future__ import annotations import argparse +import re from pathlib import Path -MENTION_TOKEN = "@AI_visual" -BLOCK_START = "" -BLOCK_END = "" +# Support multiple mention patterns (case-insensitive) +MENTION_REGEX = re.compile(r"@ai[-_]visual(?:izer)?\s*:?\s*(.+)", re.IGNORECASE) +BLOCK_START = "" +BLOCK_END = "" def find_next_diagram(diagram_dir: Path) -> Path: @@ -29,7 +31,7 @@ def write_placeholder_plantuml(path: Path, prompt: str) -> None: [ "@startuml", "' Auto-generated scaffold", - "' Requested via @AI_visual", + "' Requested via @AI_Visualizer", f"note as N1", prompt.strip() or "Diagram requested with no additional context.", "end note", @@ -43,7 +45,7 @@ def write_placeholder_plantuml(path: Path, prompt: str) -> None: def append_comment(discussion_path: Path, diagram_rel: Path) -> None: comment = ( f"{BLOCK_START}\n" - "Name: AI_Visual\n" + "Name: AI_Visualizer\n" f"Generated diagram: `{diagram_rel.as_posix()}`\n" "\n" "Let me know if you need an updated view.\n" @@ -56,7 +58,7 @@ def append_comment(discussion_path: Path, diagram_rel: Path) -> None: def main() -> int: - parser = argparse.ArgumentParser(description="AI Visual agent") + parser = argparse.ArgumentParser(description="AI Visualizer agent") parser.add_argument("--repo-root", required=True, help="Repository root path") parser.add_argument("--path", required=True, help="Relative path to discussion file") args = parser.parse_args() @@ -69,16 +71,17 @@ def main() -> int: return 0 text = discussion_path.read_text(encoding="utf-8") - if MENTION_TOKEN not in text: + match = MENTION_REGEX.search(text) + if not match: return 0 # Simple check to avoid re-processing if our comment is already there - if f"Name: AI_Visual" in text and BLOCK_START in text: + if f"Name: AI_Visualizer" in text and BLOCK_START in text: return 0 diagram_dir = discussion_path.parent.parent / "diagrams" diagram_path = find_next_diagram(diagram_dir) - prompt = text.split(MENTION_TOKEN, 1)[1] + prompt = match.group(1) # Extract text after the mention write_placeholder_plantuml(diagram_path, prompt) append_comment(discussion_path, diagram_path.relative_to(repo_root)) return 0 diff --git a/tests/test_workflow.py b/tests/test_workflow.py index 1c12af7..23233f7 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -953,10 +953,10 @@ def test_visualizer_generates_diagram(temp_repo): # Check that a comment was posted updated = discussion.read_text(encoding="utf-8") - assert "Name: AI_Visual" in updated + assert "Name: AI_Visualizer" in updated assert generated[0].relative_to(repo).as_posix() in updated - start = updated.index("") - end = updated.index("", start) + start = updated.index("") + end = updated.index("", start) agent_block = updated[start:end] assert "VOTE:" not in agent_block