| from __future__ import annotations | |
| from core.schemas import CourtRunResult, SiegeRunResult | |
| def export_markdown(result: SiegeRunResult) -> str: | |
| report = result.aggregated_report | |
| summary = report.summary | |
| lines = [ | |
| "# Siege Report", | |
| "", | |
| ] | |
| if result.website_intent is not None: | |
| intent = result.website_intent | |
| lines.extend( | |
| [ | |
| "## Website Intent", | |
| "", | |
| f"- URL: {intent.url}", | |
| f"- Inferred purpose: {intent.inferred_purpose}", | |
| f"- Inferred audience: {intent.inferred_audience}", | |
| f"- Primary action: {intent.primary_action}", | |
| f"- Confidence: {intent.confidence}", | |
| ] | |
| ) | |
| if intent.stated_outcome: | |
| lines.append(f"- Stated outcome: {intent.stated_outcome}") | |
| if intent.intent_drift_warnings: | |
| lines.extend(["", "### Intent Drift", ""]) | |
| lines.extend(f"- {warning}" for warning in intent.intent_drift_warnings) | |
| if intent.mismatch_warnings: | |
| lines.extend(["", "### Frontend Warnings", ""]) | |
| lines.extend(f"- {warning}" for warning in intent.mismatch_warnings) | |
| lines.append("") | |
| lines.extend( | |
| [ | |
| "## Summary", | |
| "", | |
| f"- Completed: {summary.completed}/{summary.valid_personas}", | |
| f"- Success rate: {summary.success_rate:.0%}", | |
| f"- Average confusion: {summary.avg_confusion:.2f}", | |
| f"- Average trust: {summary.avg_trust:.2f}", | |
| f"- Excluded Personas: {summary.excluded}", | |
| ] | |
| ) | |
| if report.deadliest_step is not None: | |
| lines.append( | |
| f"- Deadliest step: {report.deadliest_step.label} " | |
| f"({report.deadliest_step.primary_reason})" | |
| ) | |
| lines.extend(["", "## Top Issues", ""]) | |
| if report.top_issues: | |
| lines.extend( | |
| f"- {issue.issue}: {issue.frequency} mentions, {issue.severity} severity" | |
| for issue in report.top_issues | |
| ) | |
| else: | |
| lines.append("- No major issues detected.") | |
| lines.extend(["", "## Brutal Quotes", ""]) | |
| if report.brutal_quotes: | |
| for quote in report.brutal_quotes: | |
| lines.extend( | |
| [ | |
| f"> {quote.quote}", | |
| f"> - {quote.persona} ({quote.archetype})", | |
| "", | |
| ] | |
| ) | |
| else: | |
| lines.append("- No failing Persona quotes.") | |
| lines.extend(["", "## Quick Wins", ""]) | |
| if result.redesign_suggestion.quick_wins: | |
| lines.extend(f"- {quick_win}" for quick_win in result.redesign_suggestion.quick_wins) | |
| else: | |
| lines.append("- No quick wins generated.") | |
| return "\n".join(lines).strip() + "\n" | |
| def export_court_markdown(result: CourtRunResult) -> str: | |
| lines = [ | |
| "# Model Court Report", | |
| "", | |
| f"## {result.case_title}", | |
| "", | |
| f"- Domain: {result.domain.replace('_', ' ')}", | |
| f"- Question: {result.decision_question}", | |
| f"- Verdict: {result.verdict.decision.replace('_', ' ').title()}", | |
| f"- Confidence: {result.verdict.confidence:.0%}", | |
| f"- Exposure: {result.verdict.estimated_exposure}", | |
| "", | |
| "## Verdict Summary", | |
| "", | |
| result.verdict.summary, | |
| "", | |
| "## Rationale", | |
| "", | |
| ] | |
| lines.extend(f"- {item}" for item in result.verdict.rationale) | |
| lines.extend(["", "## Evidence", ""]) | |
| lines.extend( | |
| ( | |
| f"- **{item.evidence_id}** [{item.supports}, {item.strength}] " | |
| f"{item.fact} _(source: {item.source})_" | |
| ) | |
| for item in result.evidence | |
| ) | |
| lines.extend(["", "## Agent Arguments", ""]) | |
| for argument in result.arguments: | |
| lines.extend( | |
| [ | |
| f"### {argument.role.replace('_', ' ').title()}", | |
| "", | |
| f"- Stance: {argument.stance}", | |
| f"- Confidence: {argument.confidence:.0%}", | |
| f"- Evidence cited: {', '.join(argument.evidence_cited)}", | |
| f"- Recommended action: {argument.recommended_action}", | |
| ] | |
| ) | |
| lines.extend(f"- Claim: {claim}" for claim in argument.claims) | |
| if argument.objections: | |
| lines.extend(f"- Objection: {objection}" for objection in argument.objections) | |
| lines.append("") | |
| lines.extend(["## Cross-Examination", ""]) | |
| lines.extend( | |
| ( | |
| f"- **{item.examiner_role} -> {item.target_role}:** {item.challenge} " | |
| f"Response: {item.target_response} " | |
| f"Unresolved risk: {item.unresolved_risk}" | |
| ) | |
| for item in result.cross_examination | |
| ) | |
| if result.agreement_map is not None: | |
| lines.extend(["", "## Agreement Map", "", result.agreement_map.summary, ""]) | |
| lines.extend( | |
| ( | |
| f"- **{item.status.title()}**: {item.point} " | |
| f"_(roles: {', '.join(item.roles)}; " | |
| f"evidence: {', '.join(item.evidence_cited) or 'none'})_" | |
| ) | |
| for item in result.agreement_map.items | |
| ) | |
| if result.verdict.decision_ranking: | |
| lines.extend(["", "## Decision Ranking", ""]) | |
| lines.extend( | |
| ( | |
| f"{item.rank}. **{item.decision.replace('_', ' ').title()}** - " | |
| f"{item.reason} _(evidence: {', '.join(item.evidence_cited) or 'none'})_" | |
| ) | |
| for item in sorted(result.verdict.decision_ranking, key=lambda entry: entry.rank) | |
| ) | |
| lines.extend( | |
| [ | |
| "", | |
| "## Dissent", | |
| "", | |
| result.verdict.dissenting_opinion, | |
| "", | |
| "## Required Next Steps", | |
| "", | |
| ] | |
| ) | |
| lines.extend(f"- {step}" for step in result.verdict.required_next_steps) | |
| lines.extend(["", "## Audit Flags", ""]) | |
| lines.extend(f"- {flag}" for flag in result.audit_flags) | |
| lines.extend(["", "## AMD + Qwen Story", "", result.amd_story]) | |
| lines.extend( | |
| [ | |
| "", | |
| "## Execution", | |
| "", | |
| f"- Profile: {result.execution_profile}", | |
| f"- Mode: `{result.inference_mode}`", | |
| ] | |
| ) | |
| if result.wave_latency_seconds: | |
| lines.extend(["", "### Wave Latency", ""]) | |
| labels = [ | |
| "Evidence Clerk", | |
| "First-wave Role Agents", | |
| "Domain Expert", | |
| "Cross-Examination", | |
| "Agreement Clerk", | |
| "Judge", | |
| ] | |
| for index, duration in enumerate(result.wave_latency_seconds): | |
| label = labels[index] if index < len(labels) else f"Wave {index + 1}" | |
| lines.append(f"- {label}: {duration:.3f}s") | |
| if result.benchmark is not None: | |
| benchmark = result.benchmark | |
| lines.extend( | |
| [ | |
| "", | |
| "## AMD Parallel Benchmark", | |
| "", | |
| f"- Model: `{benchmark.model_name}`", | |
| f"- Endpoint mode: `{benchmark.endpoint_mode}`", | |
| f"- First-wave speedup: {benchmark.first_wave_speedup:.2f}x", | |
| f"- Full Tribunal speedup: {benchmark.full_tribunal_speedup:.2f}x", | |
| f"- Sequential total: {benchmark.sequential.total_seconds:.3f}s", | |
| f"- Parallel total: {benchmark.parallel.total_seconds:.3f}s", | |
| ] | |
| ) | |
| return "\n".join(lines).strip() + "\n" | |