Files
manual_slop/conductor_tech_lead.py
Ed_ 8d9f25d0ce feat(mma): Phase 1 — source_tier tagging at emission
- ai_client: add current_tier module var; stamp source_tier on every _append_comms entry
- multi_agent_conductor: set current_tier='Tier 3' around send(), clear in finally
- conductor_tech_lead: set current_tier='Tier 2' around send(), clear in finally
- gui_2: _on_tool_log captures current_tier; _append_tool_log stores dict with source_tier
- tests: 8 new tests covering current_tier, source_tier in comms, tool log dict format
2026-03-02 16:18:00 -05:00

80 lines
2.6 KiB
Python

import json
import ai_client
import mma_prompts
import re
def generate_tickets(track_brief: str, module_skeletons: str) -> list[dict]:
"""
Tier 2 (Tech Lead) call.
Breaks down a Track Brief and module skeletons into discrete Tier 3 Tickets.
"""
# 1. Set Tier 2 Model (Tech Lead - Flash)
# 2. Construct Prompt
system_prompt = mma_prompts.PROMPTS.get("tier2_sprint_planning")
user_message = (
f"### TRACK BRIEF:\n{track_brief}\n\n"
f"### MODULE SKELETONS:\n{module_skeletons}\n\n"
"Please generate the implementation tickets for this track."
)
# Set custom system prompt for this call
old_system_prompt = ai_client._custom_system_prompt
ai_client.set_custom_system_prompt(system_prompt)
ai_client.current_tier = "Tier 2"
try:
# 3. Call Tier 2 Model
response = ai_client.send(
md_content="",
user_message=user_message
)
# 4. Parse JSON Output
# Extract JSON array from markdown code blocks if present
json_match = response.strip()
if "```json" in json_match:
json_match = json_match.split("```json")[1].split("```")[0].strip()
elif "```" in json_match:
json_match = json_match.split("```")[1].split("```")[0].strip()
# If it's still not valid JSON, try to find a [ ... ] block
if not (json_match.startswith('[') and json_match.endswith(']')):
match = re.search(r'\[\s*\{.*\}\s*\]', json_match, re.DOTALL)
if match:
json_match = match.group(0)
tickets = json.loads(json_match)
return tickets
except Exception as e:
print(f"Error parsing Tier 2 response: {e}")
return []
finally:
# Restore old system prompt and clear tier tag
ai_client.set_custom_system_prompt(old_system_prompt)
ai_client.current_tier = None
from dag_engine import TrackDAG
from models import Ticket
def topological_sort(tickets: list[dict]) -> list[dict]:
"""
Sorts a list of tickets based on their 'depends_on' field.
Raises ValueError if a circular dependency or missing internal dependency is detected.
"""
# 1. Convert to Ticket objects for TrackDAG
ticket_objs = []
for t_data in tickets:
ticket_objs.append(Ticket.from_dict(t_data))
# 2. Use TrackDAG for validation and sorting
dag = TrackDAG(ticket_objs)
try:
sorted_ids = dag.topological_sort()
except ValueError as e:
raise ValueError(f"DAG Validation Error: {e}")
# 3. Return sorted dictionaries
ticket_map = {t['id']: t for t in tickets}
return [ticket_map[tid] for tid in sorted_ids]
if __name__ == "__main__":
# Quick test if run directly
test_brief = "Implement a new feature."
test_skeletons = "class NewFeature: pass"
tickets = generate_tickets(test_brief, test_skeletons)
print(json.dumps(tickets, indent=2))