# discussion-architect - Systems architect participant for discussions # Usage: cat discussion.md | discussion-architect --callout "Review the API design" name: discussion-architect description: Systems architect participant for discussions category: Discussion meta: display_name: AI-Architect alias: architect type: voting expertise: - System design - Scalability - Technical debt - Architectural patterns - API design concerns: - "How does this fit the overall architecture?" - "Will this scale to 10x current load?" - "What's the long-term maintenance burden?" - "Are we creating unnecessary coupling?" arguments: - flag: --callout variable: callout default: "" description: Specific question or @mention context - flag: --templates-dir variable: templates_dir default: "templates" description: Path to templates directory - flag: --diagrams-dir variable: diagrams_dir default: "diagrams" description: Path to save diagrams - flag: --log-file variable: log_file default: "" description: Path to log file for progress updates steps: # Step 1: Extract phase context from template - type: code code: | import re import os phase_match = re.search(r'', input, re.IGNORECASE) template_match = re.search(r'', input, re.IGNORECASE) current_phase = phase_match.group(1) if phase_match else "initial_feedback" template_name = template_match.group(1) if template_match else "feature" template_path = os.path.join(templates_dir, template_name + ".yaml") phase_goal = "Provide architectural feedback" phase_instructions = "Review the proposal and raise any architectural concerns." if os.path.exists(template_path): import yaml with open(template_path, 'r') as f: template = yaml.safe_load(f) phases = template.get("phases", {}) phase_info = phases.get(current_phase, {}) phase_goal = phase_info.get("goal", phase_goal) phase_instructions = phase_info.get("instructions", phase_instructions) phase_context = "Current Phase: " + current_phase + "\n" phase_context += "Phase Goal: " + phase_goal + "\n" phase_context += "Phase Instructions:\n" + phase_instructions output_var: phase_context, current_phase # Step 2: Prepare diagram path - type: code code: | import re import os title_match = re.search(r'', input) discussion_name = "discussion" if title_match: discussion_name = title_match.group(1).strip().lower() discussion_name = re.sub(r'[^a-z0-9]+', '-', discussion_name) os.makedirs(diagrams_dir, exist_ok=True) existing = [] if os.path.exists(diagrams_dir): for f in os.listdir(diagrams_dir): if f.startswith(discussion_name): existing.append(f) next_num = len(existing) + 1 diagram_path = diagrams_dir + "/" + discussion_name + "_" + str(next_num) + ".puml" output_var: diagram_path # Step 3: Check if this is a sketch phase - type: code code: | should_diagram = "false" if current_phase in ["sketch", "detailed_review"]: should_diagram = "true" output_var: should_diagram # Step 4: Log progress before AI call - type: code code: | import sys import datetime as dt timestamp = dt.datetime.now().strftime("%H:%M:%S") for msg in [f"Phase: {current_phase}", "Calling AI provider..."]: line = f"[{timestamp}] [architect] {msg}" print(line, file=sys.stderr) sys.stderr.flush() if log_file: with open(log_file, 'a') as f: f.write(line + "\n") f.flush() output_var: _progress1 # Step 5: Generate response - type: prompt prompt: | You are AI-Architect (also known as Chen), a senior systems architect with deep expertise in distributed systems, design patterns, and long-term technical strategy. ## Your Role - Think in systems, patterns, and architectural principles - Consider scalability, maintainability, and evolution over time - Identify architectural risks and technical debt implications - Suggest well-established patterns and proven approaches - Balance ideal architecture with practical constraints ## Your Perspective - Think 2-5 years ahead, not just the immediate implementation - Value modularity, separation of concerns, and clean boundaries - Prefer boring, proven technology over cutting-edge experiments - Call out when shortcuts will create architectural debt ## Phase Context {phase_context} ## Diagrams When creating diagrams, you MUST include a reference marker in your comment. Diagram path to use: {diagram_path} IMPORTANT: When you create a diagram, your comment MUST include: DIAGRAM: {diagram_path} This marker makes the diagram discoverable. Example comment structure: "Here's my analysis of the architecture... [Your detailed analysis] DIAGRAM: {diagram_path}" ## Current Discussion {input} ## Your Task {callout} Follow the phase instructions. Analyze from an architectural perspective. ## Response Format Respond with valid JSON only. Use \n for newlines in strings (not literal newlines): {{ "comment": "Line 1\nLine 2\nLine 3", "vote": "READY" or "CHANGES" or "REJECT" or null, "diagram": "@startuml\nA -> B\n@enduml" }} Important: The diagram field must use \n for newlines, not actual line breaks. If you have nothing meaningful to add, respond: {{"sentinel": "NO_RESPONSE"}} provider: claude-sonnet output_var: response # Step 6: Log progress after AI call - type: code code: | import sys import datetime as dt timestamp = dt.datetime.now().strftime("%H:%M:%S") line = f"[{timestamp}] [architect] AI response received" print(line, file=sys.stderr) sys.stderr.flush() if log_file: with open(log_file, 'a') as f: f.write(line + "\n") f.flush() output_var: _progress2 # Step 7: Extract JSON from response (may be wrapped in markdown code block) - type: code code: | import re json_text = response.strip() code_block = re.search(r'```(?:json)?\s*(.*?)```', json_text, re.DOTALL) if code_block: json_text = code_block.group(1).strip() output_var: json_text # Step 6: Parse JSON - type: code code: | import json try: parsed = json.loads(json_text) except json.JSONDecodeError as e: # AI often returns literal newlines in JSON strings - escape them fixed = json_text.replace('\n', '\\n') try: parsed = json.loads(fixed) except json.JSONDecodeError: # Last resort: try to extract just the fields we need via regex import re comment_match = re.search(r'"comment"\s*:\s*"(.*?)"(?=\s*[,}])', json_text, re.DOTALL) vote_match = re.search(r'"vote"\s*:\s*("?\w+"?|null)', json_text) diagram_match = re.search(r'"diagram"\s*:\s*"(.*?)"(?=\s*[,}])', json_text, re.DOTALL) parsed = { "comment": comment_match.group(1).replace('\n', ' ') if comment_match else "Parse error", "vote": vote_match.group(1).strip('"') if vote_match else None, "diagram": diagram_match.group(1) if diagram_match else None } if parsed["vote"] == "null": parsed["vote"] = None comment = parsed.get("comment", "") vote = parsed.get("vote") diagram_content = parsed.get("diagram") has_diagram = "true" if diagram_content else "false" output_var: comment, vote, diagram_content, has_diagram # Step 7: Save diagram if present - type: code code: | if has_diagram == "true" and diagram_content: with open(diagram_path, 'w') as f: f.write(diagram_content) saved_diagram = diagram_path else: saved_diagram = "" output_var: saved_diagram # Step 8: Build final response - type: code code: | import json result = {"comment": comment, "vote": vote} if saved_diagram: result["diagram_file"] = saved_diagram final_response = json.dumps(result) output_var: final_response output: "{final_response}"