fix: update visualizer to support @AI_Visualizer mentions

- Change MENTION_TOKEN to MENTION_REGEX supporting both @AI_visual and @AI_Visualizer
- Makes it case-insensitive and consistent with other agents (AI_Moderator, AI_Designer)
- Update agent name from AI_Visual to AI_Visualizer
- Update HTML markers from AUTO:VISUAL to AUTO:VISUALIZER
- Update tests to match new naming
- All tests passing
This commit is contained in:
rob 2025-11-04 22:32:57 -04:00
parent e6292fbad4
commit 304400cc85
2 changed files with 18 additions and 15 deletions

View File

@ -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 = "<!-- AUTO:VISUAL START -->"
BLOCK_END = "<!-- AUTO:VISUAL END -->"
# Support multiple mention patterns (case-insensitive)
MENTION_REGEX = re.compile(r"@ai[-_]visual(?:izer)?\s*:?\s*(.+)", re.IGNORECASE)
BLOCK_START = "<!-- AUTO:VISUALIZER START -->"
BLOCK_END = "<!-- AUTO:VISUALIZER 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

View File

@ -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("<!-- AUTO:VISUAL START -->")
end = updated.index("<!-- AUTO:VISUAL END -->", start)
start = updated.index("<!-- AUTO:VISUALIZER START -->")
end = updated.index("<!-- AUTO:VISUALIZER END -->", start)
agent_block = updated[start:end]
assert "VOTE:" not in agent_block