foundry-mcp 0.8.22__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of foundry-mcp might be problematic. Click here for more details.

Files changed (153) hide show
  1. foundry_mcp/__init__.py +13 -0
  2. foundry_mcp/cli/__init__.py +67 -0
  3. foundry_mcp/cli/__main__.py +9 -0
  4. foundry_mcp/cli/agent.py +96 -0
  5. foundry_mcp/cli/commands/__init__.py +37 -0
  6. foundry_mcp/cli/commands/cache.py +137 -0
  7. foundry_mcp/cli/commands/dashboard.py +148 -0
  8. foundry_mcp/cli/commands/dev.py +446 -0
  9. foundry_mcp/cli/commands/journal.py +377 -0
  10. foundry_mcp/cli/commands/lifecycle.py +274 -0
  11. foundry_mcp/cli/commands/modify.py +824 -0
  12. foundry_mcp/cli/commands/plan.py +640 -0
  13. foundry_mcp/cli/commands/pr.py +393 -0
  14. foundry_mcp/cli/commands/review.py +667 -0
  15. foundry_mcp/cli/commands/session.py +472 -0
  16. foundry_mcp/cli/commands/specs.py +686 -0
  17. foundry_mcp/cli/commands/tasks.py +807 -0
  18. foundry_mcp/cli/commands/testing.py +676 -0
  19. foundry_mcp/cli/commands/validate.py +982 -0
  20. foundry_mcp/cli/config.py +98 -0
  21. foundry_mcp/cli/context.py +298 -0
  22. foundry_mcp/cli/logging.py +212 -0
  23. foundry_mcp/cli/main.py +44 -0
  24. foundry_mcp/cli/output.py +122 -0
  25. foundry_mcp/cli/registry.py +110 -0
  26. foundry_mcp/cli/resilience.py +178 -0
  27. foundry_mcp/cli/transcript.py +217 -0
  28. foundry_mcp/config.py +1454 -0
  29. foundry_mcp/core/__init__.py +144 -0
  30. foundry_mcp/core/ai_consultation.py +1773 -0
  31. foundry_mcp/core/batch_operations.py +1202 -0
  32. foundry_mcp/core/cache.py +195 -0
  33. foundry_mcp/core/capabilities.py +446 -0
  34. foundry_mcp/core/concurrency.py +898 -0
  35. foundry_mcp/core/context.py +540 -0
  36. foundry_mcp/core/discovery.py +1603 -0
  37. foundry_mcp/core/error_collection.py +728 -0
  38. foundry_mcp/core/error_store.py +592 -0
  39. foundry_mcp/core/health.py +749 -0
  40. foundry_mcp/core/intake.py +933 -0
  41. foundry_mcp/core/journal.py +700 -0
  42. foundry_mcp/core/lifecycle.py +412 -0
  43. foundry_mcp/core/llm_config.py +1376 -0
  44. foundry_mcp/core/llm_patterns.py +510 -0
  45. foundry_mcp/core/llm_provider.py +1569 -0
  46. foundry_mcp/core/logging_config.py +374 -0
  47. foundry_mcp/core/metrics_persistence.py +584 -0
  48. foundry_mcp/core/metrics_registry.py +327 -0
  49. foundry_mcp/core/metrics_store.py +641 -0
  50. foundry_mcp/core/modifications.py +224 -0
  51. foundry_mcp/core/naming.py +146 -0
  52. foundry_mcp/core/observability.py +1216 -0
  53. foundry_mcp/core/otel.py +452 -0
  54. foundry_mcp/core/otel_stubs.py +264 -0
  55. foundry_mcp/core/pagination.py +255 -0
  56. foundry_mcp/core/progress.py +387 -0
  57. foundry_mcp/core/prometheus.py +564 -0
  58. foundry_mcp/core/prompts/__init__.py +464 -0
  59. foundry_mcp/core/prompts/fidelity_review.py +691 -0
  60. foundry_mcp/core/prompts/markdown_plan_review.py +515 -0
  61. foundry_mcp/core/prompts/plan_review.py +627 -0
  62. foundry_mcp/core/providers/__init__.py +237 -0
  63. foundry_mcp/core/providers/base.py +515 -0
  64. foundry_mcp/core/providers/claude.py +472 -0
  65. foundry_mcp/core/providers/codex.py +637 -0
  66. foundry_mcp/core/providers/cursor_agent.py +630 -0
  67. foundry_mcp/core/providers/detectors.py +515 -0
  68. foundry_mcp/core/providers/gemini.py +426 -0
  69. foundry_mcp/core/providers/opencode.py +718 -0
  70. foundry_mcp/core/providers/opencode_wrapper.js +308 -0
  71. foundry_mcp/core/providers/package-lock.json +24 -0
  72. foundry_mcp/core/providers/package.json +25 -0
  73. foundry_mcp/core/providers/registry.py +607 -0
  74. foundry_mcp/core/providers/test_provider.py +171 -0
  75. foundry_mcp/core/providers/validation.py +857 -0
  76. foundry_mcp/core/rate_limit.py +427 -0
  77. foundry_mcp/core/research/__init__.py +68 -0
  78. foundry_mcp/core/research/memory.py +528 -0
  79. foundry_mcp/core/research/models.py +1234 -0
  80. foundry_mcp/core/research/providers/__init__.py +40 -0
  81. foundry_mcp/core/research/providers/base.py +242 -0
  82. foundry_mcp/core/research/providers/google.py +507 -0
  83. foundry_mcp/core/research/providers/perplexity.py +442 -0
  84. foundry_mcp/core/research/providers/semantic_scholar.py +544 -0
  85. foundry_mcp/core/research/providers/tavily.py +383 -0
  86. foundry_mcp/core/research/workflows/__init__.py +25 -0
  87. foundry_mcp/core/research/workflows/base.py +298 -0
  88. foundry_mcp/core/research/workflows/chat.py +271 -0
  89. foundry_mcp/core/research/workflows/consensus.py +539 -0
  90. foundry_mcp/core/research/workflows/deep_research.py +4142 -0
  91. foundry_mcp/core/research/workflows/ideate.py +682 -0
  92. foundry_mcp/core/research/workflows/thinkdeep.py +405 -0
  93. foundry_mcp/core/resilience.py +600 -0
  94. foundry_mcp/core/responses.py +1624 -0
  95. foundry_mcp/core/review.py +366 -0
  96. foundry_mcp/core/security.py +438 -0
  97. foundry_mcp/core/spec.py +4119 -0
  98. foundry_mcp/core/task.py +2463 -0
  99. foundry_mcp/core/testing.py +839 -0
  100. foundry_mcp/core/validation.py +2357 -0
  101. foundry_mcp/dashboard/__init__.py +32 -0
  102. foundry_mcp/dashboard/app.py +119 -0
  103. foundry_mcp/dashboard/components/__init__.py +17 -0
  104. foundry_mcp/dashboard/components/cards.py +88 -0
  105. foundry_mcp/dashboard/components/charts.py +177 -0
  106. foundry_mcp/dashboard/components/filters.py +136 -0
  107. foundry_mcp/dashboard/components/tables.py +195 -0
  108. foundry_mcp/dashboard/data/__init__.py +11 -0
  109. foundry_mcp/dashboard/data/stores.py +433 -0
  110. foundry_mcp/dashboard/launcher.py +300 -0
  111. foundry_mcp/dashboard/views/__init__.py +12 -0
  112. foundry_mcp/dashboard/views/errors.py +217 -0
  113. foundry_mcp/dashboard/views/metrics.py +164 -0
  114. foundry_mcp/dashboard/views/overview.py +96 -0
  115. foundry_mcp/dashboard/views/providers.py +83 -0
  116. foundry_mcp/dashboard/views/sdd_workflow.py +255 -0
  117. foundry_mcp/dashboard/views/tool_usage.py +139 -0
  118. foundry_mcp/prompts/__init__.py +9 -0
  119. foundry_mcp/prompts/workflows.py +525 -0
  120. foundry_mcp/resources/__init__.py +9 -0
  121. foundry_mcp/resources/specs.py +591 -0
  122. foundry_mcp/schemas/__init__.py +38 -0
  123. foundry_mcp/schemas/intake-schema.json +89 -0
  124. foundry_mcp/schemas/sdd-spec-schema.json +414 -0
  125. foundry_mcp/server.py +150 -0
  126. foundry_mcp/tools/__init__.py +10 -0
  127. foundry_mcp/tools/unified/__init__.py +92 -0
  128. foundry_mcp/tools/unified/authoring.py +3620 -0
  129. foundry_mcp/tools/unified/context_helpers.py +98 -0
  130. foundry_mcp/tools/unified/documentation_helpers.py +268 -0
  131. foundry_mcp/tools/unified/environment.py +1341 -0
  132. foundry_mcp/tools/unified/error.py +479 -0
  133. foundry_mcp/tools/unified/health.py +225 -0
  134. foundry_mcp/tools/unified/journal.py +841 -0
  135. foundry_mcp/tools/unified/lifecycle.py +640 -0
  136. foundry_mcp/tools/unified/metrics.py +777 -0
  137. foundry_mcp/tools/unified/plan.py +876 -0
  138. foundry_mcp/tools/unified/pr.py +294 -0
  139. foundry_mcp/tools/unified/provider.py +589 -0
  140. foundry_mcp/tools/unified/research.py +1283 -0
  141. foundry_mcp/tools/unified/review.py +1042 -0
  142. foundry_mcp/tools/unified/review_helpers.py +314 -0
  143. foundry_mcp/tools/unified/router.py +102 -0
  144. foundry_mcp/tools/unified/server.py +565 -0
  145. foundry_mcp/tools/unified/spec.py +1283 -0
  146. foundry_mcp/tools/unified/task.py +3846 -0
  147. foundry_mcp/tools/unified/test.py +431 -0
  148. foundry_mcp/tools/unified/verification.py +520 -0
  149. foundry_mcp-0.8.22.dist-info/METADATA +344 -0
  150. foundry_mcp-0.8.22.dist-info/RECORD +153 -0
  151. foundry_mcp-0.8.22.dist-info/WHEEL +4 -0
  152. foundry_mcp-0.8.22.dist-info/entry_points.txt +3 -0
  153. foundry_mcp-0.8.22.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,691 @@
1
+ """
2
+ Prompt templates for fidelity review workflow.
3
+
4
+ This module provides prompts for comparing implementation against
5
+ specifications, identifying deviations, and assessing compliance
6
+ with documented requirements.
7
+
8
+ Prompt IDs (PromptTemplate-based):
9
+ - FIDELITY_REVIEW_V1: Main 6-section fidelity review prompt
10
+ - FIDELITY_DEVIATION_ANALYSIS_V1: Analyze identified deviations
11
+ - FIDELITY_COMPLIANCE_SUMMARY_V1: Generate compliance summary
12
+ - FIDELITY_SYNTHESIS_PROMPT_V1: Multi-model response synthesis
13
+
14
+ Legacy Prompt IDs (string templates for backward compatibility):
15
+ - review_task: Compare task implementation against spec requirements
16
+ - review_phase: Review entire phase for fidelity to spec
17
+ - compare_files: Compare specific files against spec expectations
18
+ - deviation_analysis: Analyze identified deviations for impact
19
+ - compliance_summary: Generate compliance summary report
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ from typing import Any, Dict, List
25
+
26
+ from foundry_mcp.core.prompts import PromptBuilder, PromptTemplate
27
+
28
+
29
+ # =============================================================================
30
+ # Response Schema
31
+ # =============================================================================
32
+
33
+
34
+ # JSON response schema for fidelity reviews - structured format for AI response
35
+ FIDELITY_RESPONSE_SCHEMA = """{
36
+ "verdict": "pass|fail|partial|unknown",
37
+ "summary": "Overall findings (any length).",
38
+ "requirement_alignment": {
39
+ "answer": "yes|no|partial",
40
+ "details": "Explain how implementation aligns or diverges."
41
+ },
42
+ "success_criteria": {
43
+ "met": "yes|no|partial",
44
+ "details": "Call out verification steps passed or missing."
45
+ },
46
+ "deviations": [
47
+ {
48
+ "description": "Describe deviation from the spec.",
49
+ "justification": "Optional rationale or evidence.",
50
+ "severity": "critical|high|medium|low"
51
+ }
52
+ ],
53
+ "test_coverage": {
54
+ "status": "sufficient|insufficient|not_applicable",
55
+ "details": "Summarise test evidence or gaps."
56
+ },
57
+ "code_quality": {
58
+ "issues": ["Describe each notable quality concern."],
59
+ "details": "Optional supporting commentary."
60
+ },
61
+ "documentation": {
62
+ "status": "adequate|inadequate|not_applicable",
63
+ "details": "Note doc updates or omissions."
64
+ },
65
+ "issues": ["Concise list of primary issues for consensus logic."],
66
+ "recommendations": ["Actionable next steps to resolve findings."]
67
+ }"""
68
+
69
+
70
+ # JSON response schema for synthesized multi-model fidelity reviews
71
+ FIDELITY_SYNTHESIZED_RESPONSE_SCHEMA = """{
72
+ "verdict": "pass|fail|partial|unknown",
73
+ "verdict_consensus": {
74
+ "votes": {
75
+ "pass": ["model names that voted pass"],
76
+ "fail": ["model names that voted fail"],
77
+ "partial": ["model names that voted partial"],
78
+ "unknown": ["model names that voted unknown"]
79
+ },
80
+ "agreement_level": "strong|moderate|weak|conflicted",
81
+ "notes": "Explanation of verdict determination"
82
+ },
83
+ "summary": "Synthesized overall findings.",
84
+ "requirement_alignment": {
85
+ "answer": "yes|no|partial",
86
+ "details": "Synthesized alignment assessment.",
87
+ "model_agreement": "unanimous|majority|split"
88
+ },
89
+ "success_criteria": {
90
+ "met": "yes|no|partial",
91
+ "details": "Synthesized verification status.",
92
+ "model_agreement": "unanimous|majority|split"
93
+ },
94
+ "deviations": [
95
+ {
96
+ "description": "Merged deviation description",
97
+ "justification": "Combined rationale",
98
+ "severity": "critical|high|medium|low",
99
+ "identified_by": ["model names that identified this"],
100
+ "agreement": "unanimous|majority|single"
101
+ }
102
+ ],
103
+ "test_coverage": {
104
+ "status": "sufficient|insufficient|not_applicable",
105
+ "details": "Synthesized test assessment",
106
+ "model_agreement": "unanimous|majority|split"
107
+ },
108
+ "code_quality": {
109
+ "issues": ["Merged quality concerns with model attribution"],
110
+ "details": "Synthesized commentary"
111
+ },
112
+ "documentation": {
113
+ "status": "adequate|inadequate|not_applicable",
114
+ "details": "Synthesized doc assessment",
115
+ "model_agreement": "unanimous|majority|split"
116
+ },
117
+ "issues": ["Deduplicated issues with model attribution"],
118
+ "recommendations": ["Prioritized actionable steps"],
119
+ "synthesis_metadata": {
120
+ "models_consulted": ["all model names"],
121
+ "models_succeeded": ["successful model names"],
122
+ "models_failed": ["failed model names"],
123
+ "synthesis_provider": "model that performed synthesis",
124
+ "agreement_level": "strong|moderate|weak|conflicted"
125
+ }
126
+ }"""
127
+
128
+
129
+ # =============================================================================
130
+ # Severity Categorization Keywords
131
+ # =============================================================================
132
+
133
+
134
+ # CRITICAL: Security vulnerabilities, data loss, crashes
135
+ CRITICAL_KEYWORDS = [
136
+ "security",
137
+ "vulnerability",
138
+ "injection",
139
+ "xss",
140
+ "csrf",
141
+ "authentication bypass",
142
+ "unauthorized access",
143
+ "data loss",
144
+ "crash",
145
+ "segfault",
146
+ "memory leak",
147
+ "remote code execution",
148
+ "privilege escalation",
149
+ "buffer overflow",
150
+ ]
151
+
152
+ # HIGH: Incorrect behavior, spec violations, broken functionality
153
+ HIGH_KEYWORDS = [
154
+ "incorrect",
155
+ "wrong",
156
+ "broken",
157
+ "fails",
158
+ "failure",
159
+ "spec violation",
160
+ "requirement not met",
161
+ "does not match",
162
+ "missing required",
163
+ "critical bug",
164
+ "data corruption",
165
+ "logic error",
166
+ "incorrect behavior",
167
+ ]
168
+
169
+ # MEDIUM: Performance issues, missing tests, code quality
170
+ MEDIUM_KEYWORDS = [
171
+ "performance",
172
+ "slow",
173
+ "inefficient",
174
+ "optimization",
175
+ "missing test",
176
+ "no tests",
177
+ "untested",
178
+ "test coverage",
179
+ "code quality",
180
+ "maintainability",
181
+ "complexity",
182
+ "duplication",
183
+ "refactor",
184
+ "improvement needed",
185
+ ]
186
+
187
+ # LOW: Style issues, documentation, minor improvements
188
+ LOW_KEYWORDS = [
189
+ "style",
190
+ "formatting",
191
+ "naming",
192
+ "documentation",
193
+ "comment",
194
+ "typo",
195
+ "whitespace",
196
+ "minor",
197
+ "suggestion",
198
+ "consider",
199
+ "could be better",
200
+ ]
201
+
202
+ # All severity keywords organized by level
203
+ SEVERITY_KEYWORDS = {
204
+ "critical": CRITICAL_KEYWORDS,
205
+ "high": HIGH_KEYWORDS,
206
+ "medium": MEDIUM_KEYWORDS,
207
+ "low": LOW_KEYWORDS,
208
+ }
209
+
210
+
211
+ # =============================================================================
212
+ # PromptTemplate-based Prompts (New Format)
213
+ # =============================================================================
214
+
215
+
216
+ # Main fidelity review prompt - 6-section structure
217
+ FIDELITY_REVIEW_V1 = PromptTemplate(
218
+ id="FIDELITY_REVIEW_V1",
219
+ version="1.0",
220
+ system_prompt="""You are an expert code reviewer performing implementation fidelity analysis.
221
+
222
+ Your role is to compare actual code implementation against specification requirements
223
+ and identify any deviations, issues, or concerns.
224
+
225
+ CRITICAL CONSTRAINTS:
226
+ - This is a READ-ONLY review - you MUST NOT write, create, or modify ANY files
227
+ - Execute code or commands - ANALYSIS ONLY
228
+ - Provide findings as structured JSON in your response
229
+ - Do NOT focus on ownership, responsibility, or team assignment concerns
230
+ - Avoid feedback like "who owns", "who verifies", "who is responsible for"
231
+ - Focus on technical requirements and verification steps themselves, not who performs them
232
+
233
+ Focus on:
234
+ 1. Requirement alignment - Does implementation match spec?
235
+ 2. Success criteria - Are verification steps satisfied?
236
+ 3. Deviations - Any divergences from specification?
237
+ 4. Test coverage - Are tests comprehensive?
238
+ 5. Code quality - Any maintainability concerns?
239
+ 6. Documentation - Is implementation properly documented?""",
240
+ user_template="""# Implementation Fidelity Review
241
+
242
+ ## 1. Context
243
+ **Spec ID:** {spec_id}
244
+ **Spec Title:** {spec_title}
245
+ {spec_description}
246
+ **Review Scope:** {review_scope}
247
+
248
+ ## 2. Specification Requirements
249
+ {spec_requirements}
250
+
251
+ ## 3. Implementation Artifacts
252
+ {implementation_artifacts}
253
+
254
+ ## 4. Test Results
255
+ {test_results}
256
+
257
+ ## 5. Journal Entries
258
+ {journal_entries}
259
+
260
+ ## 6. Review Questions
261
+
262
+ Please evaluate the implementation against the specification:
263
+
264
+ 1. **Requirement Alignment:** Does the implementation match the spec requirements?
265
+ 2. **Success Criteria:** Are all verification steps satisfied?
266
+ 3. **Deviations:** Are there any deviations from the spec? If so, are they justified?
267
+ 4. **Test Coverage:** Are tests comprehensive and passing?
268
+ 5. **Code Quality:** Are there any quality, maintainability, or security concerns?
269
+ 6. **Documentation:** Is the implementation properly documented?
270
+
271
+ ### Required Response Format
272
+
273
+ Respond **only** with valid JSON matching the schema below. Do not include Markdown, prose, or additional commentary outside the JSON object.
274
+
275
+ ```json
276
+ {response_schema}
277
+ ```
278
+
279
+ Rules:
280
+ - Use lowercase values shown for enumerated fields (e.g., `verdict`, status flags)
281
+ - Keep arrays as arrays (use `[]` when a section has nothing to report)
282
+ - Populate `issues` and `recommendations` with key takeaways
283
+ - Feel free to include additional keys if needed, but never omit the ones above
284
+ - Severity levels for deviations: critical, high, medium, low""",
285
+ required_context=[
286
+ "spec_id",
287
+ "spec_title",
288
+ "review_scope",
289
+ "spec_requirements",
290
+ "implementation_artifacts",
291
+ ],
292
+ optional_context=[
293
+ "spec_description",
294
+ "test_results",
295
+ "journal_entries",
296
+ "response_schema",
297
+ ],
298
+ metadata={
299
+ "workflow": "fidelity_review",
300
+ "author": "system",
301
+ "category": "implementation",
302
+ "sections": [
303
+ "Context",
304
+ "Specification Requirements",
305
+ "Implementation Artifacts",
306
+ "Test Results",
307
+ "Journal Entries",
308
+ "Review Questions",
309
+ ],
310
+ "output_format": "json",
311
+ "severity_levels": ["critical", "high", "medium", "low"],
312
+ },
313
+ )
314
+
315
+
316
+ # Deviation analysis prompt - for deep-diving into identified deviations
317
+ FIDELITY_DEVIATION_ANALYSIS_V1 = PromptTemplate(
318
+ id="FIDELITY_DEVIATION_ANALYSIS_V1",
319
+ version="1.0",
320
+ system_prompt="""You are an expert software architect analyzing specification deviations.
321
+
322
+ Your role is to assess the impact of identified deviations between implementation
323
+ and specification, determine risks, and recommend remediation strategies.
324
+
325
+ Focus on:
326
+ - Impact assessment (functional, security, performance, maintenance)
327
+ - Risk analysis and downstream effects
328
+ - Remediation options with effort/risk tradeoffs
329
+ - Prioritized recommendations""",
330
+ user_template="""# Deviation Analysis
331
+
332
+ ## Context
333
+ **Spec ID:** {spec_id}
334
+ **Analysis Scope:** {scope}
335
+
336
+ ## Identified Deviations
337
+ {deviations_json}
338
+
339
+ ## Original Requirements
340
+ {original_requirements}
341
+
342
+ ## Analysis Requirements
343
+
344
+ For each deviation, provide:
345
+ 1. **Impact Assessment**: Functional, security, performance, maintenance impact
346
+ 2. **Risk Analysis**: Risks introduced by this deviation
347
+ 3. **Downstream Effects**: How does this affect dependent components?
348
+ 4. **Remediation Options**: Ways to address with effort/risk tradeoffs
349
+ 5. **Recommendation**: accept|fix_now|fix_later|needs_discussion
350
+
351
+ ### Required Response Format
352
+
353
+ Respond with valid JSON:
354
+
355
+ ```json
356
+ {{
357
+ "analysis_scope": "{scope}",
358
+ "total_deviations": 0,
359
+ "critical_count": 0,
360
+ "deviation_analysis": [
361
+ {{
362
+ "deviation_id": "index or identifier",
363
+ "original_deviation": "brief description",
364
+ "impact_assessment": {{
365
+ "functional_impact": "none|minor|moderate|major",
366
+ "security_impact": "none|minor|moderate|major",
367
+ "performance_impact": "none|minor|moderate|major",
368
+ "maintenance_impact": "none|minor|moderate|major"
369
+ }},
370
+ "affected_components": ["list of affected components"],
371
+ "downstream_effects": ["list of downstream effects"],
372
+ "remediation_options": [
373
+ {{
374
+ "option": "description",
375
+ "effort": "low|medium|high",
376
+ "risk": "low|medium|high"
377
+ }}
378
+ ],
379
+ "recommendation": "accept|fix_now|fix_later|needs_discussion",
380
+ "rationale": "explanation for recommendation"
381
+ }}
382
+ ],
383
+ "overall_risk_level": "low|medium|high|critical",
384
+ "recommended_actions": ["prioritized list of recommended actions"],
385
+ "summary": "overall deviation analysis summary"
386
+ }}
387
+ ```""",
388
+ required_context=["spec_id", "scope", "deviations_json", "original_requirements"],
389
+ optional_context=[],
390
+ metadata={
391
+ "workflow": "fidelity_review",
392
+ "author": "system",
393
+ "category": "analysis",
394
+ "output_format": "json",
395
+ },
396
+ )
397
+
398
+
399
+ # Compliance summary prompt - for generating overall compliance reports
400
+ FIDELITY_COMPLIANCE_SUMMARY_V1 = PromptTemplate(
401
+ id="FIDELITY_COMPLIANCE_SUMMARY_V1",
402
+ version="1.0",
403
+ system_prompt="""You are an expert technical lead generating compliance reports.
404
+
405
+ Your role is to synthesize fidelity review findings into an executive summary
406
+ with clear compliance status, prioritized issues, and sign-off recommendations.
407
+
408
+ Focus on:
409
+ - Overall compliance score and status
410
+ - Phase-by-phase breakdown
411
+ - Critical blocking issues
412
+ - Sign-off readiness assessment""",
413
+ user_template="""# Compliance Summary Report
414
+
415
+ ## Specification
416
+ **Spec ID:** {spec_id}
417
+ **Title:** {spec_title}
418
+ **Total Phases:** {total_phases}
419
+ **Total Tasks:** {total_tasks}
420
+
421
+ ## Fidelity Review Data
422
+ {review_data}
423
+
424
+ ## Summary Requirements
425
+
426
+ Generate a compliance summary addressing:
427
+ 1. **Overall Compliance**: What is the overall compliance level?
428
+ 2. **Phase Breakdown**: Compliance by phase
429
+ 3. **Critical Issues**: List critical compliance issues
430
+ 4. **Recommendations**: Prioritized recommendations
431
+ 5. **Sign-off Status**: Is the implementation ready for approval?
432
+
433
+ ### Required Response Format
434
+
435
+ Respond with valid JSON:
436
+
437
+ ```json
438
+ {{
439
+ "spec_id": "{spec_id}",
440
+ "spec_title": "{spec_title}",
441
+ "overall_compliance": {{
442
+ "score": 0-100,
443
+ "status": "compliant|mostly_compliant|needs_work|non_compliant",
444
+ "tasks_compliant": 0,
445
+ "tasks_partial": 0,
446
+ "tasks_non_compliant": 0
447
+ }},
448
+ "phase_breakdown": [
449
+ {{
450
+ "phase_id": "phase-id",
451
+ "phase_title": "title",
452
+ "compliance_score": 0-100,
453
+ "status": "compliant|partial|non_compliant"
454
+ }}
455
+ ],
456
+ "critical_issues": [
457
+ {{
458
+ "issue": "description",
459
+ "location": "task or phase id",
460
+ "priority": "p0|p1|p2",
461
+ "remediation": "suggested fix"
462
+ }}
463
+ ],
464
+ "recommendations": [
465
+ {{
466
+ "recommendation": "description",
467
+ "priority": "critical|high|medium|low",
468
+ "effort": "low|medium|high"
469
+ }}
470
+ ],
471
+ "sign_off": {{
472
+ "ready": true|false,
473
+ "blocking_issues": ["list of issues that must be resolved"],
474
+ "conditions": ["conditions for approval if any"]
475
+ }},
476
+ "summary": "executive summary of compliance status"
477
+ }}
478
+ ```""",
479
+ required_context=[
480
+ "spec_id",
481
+ "spec_title",
482
+ "total_phases",
483
+ "total_tasks",
484
+ "review_data",
485
+ ],
486
+ optional_context=[],
487
+ metadata={
488
+ "workflow": "fidelity_review",
489
+ "author": "system",
490
+ "category": "reporting",
491
+ "output_format": "json",
492
+ },
493
+ )
494
+
495
+
496
+ # Multi-model synthesis prompt - consolidates multiple fidelity reviews
497
+ FIDELITY_SYNTHESIS_PROMPT_V1 = PromptTemplate(
498
+ id="FIDELITY_SYNTHESIS_PROMPT_V1",
499
+ version="1.0",
500
+ system_prompt="""You are an expert at synthesizing multiple fidelity review results.
501
+ Your task is to consolidate diverse perspectives into actionable consensus while preserving JSON format.
502
+
503
+ Guidelines:
504
+ - Attribute findings to specific models using the identified_by field
505
+ - Merge similar deviations, noting which models identified each
506
+ - Resolve verdict disagreements using majority vote or escalate to "partial" on conflict
507
+ - Preserve unique insights from each model
508
+ - Output valid JSON matching the required schema exactly
509
+ - Do NOT focus on ownership, responsibility, or team assignment concerns
510
+ - Focus on technical requirements and verification steps themselves, not who performs them""",
511
+ user_template="""You are synthesizing {num_models} independent AI fidelity reviews.
512
+
513
+ **Specification:** {spec_title} (`{spec_id}`)
514
+ **Review Scope:** {review_scope}
515
+
516
+ **Your Task:** Read all JSON reviews below and create a unified synthesis.
517
+
518
+ ## Individual Model Reviews
519
+
520
+ {model_reviews}
521
+
522
+ ## Synthesis Requirements
523
+
524
+ 1. **Verdict Consensus:**
525
+ - Count votes for each verdict (pass/fail/partial/unknown)
526
+ - Use majority vote for final verdict
527
+ - If tied or conflicted, use "partial" and note disagreement
528
+ - Record agreement_level: "strong" (all agree), "moderate" (majority agrees), "weak" (slight majority), "conflicted" (tied/split)
529
+
530
+ 2. **Deviation Merging:**
531
+ - Group similar deviations across models by description
532
+ - Use highest severity when models disagree on severity
533
+ - Track which models identified each deviation in identified_by array
534
+ - Mark agreement: "unanimous" (all models), "majority" (>50%), "single" (one model)
535
+
536
+ 3. **Issue Consolidation:**
537
+ - Deduplicate issues across models
538
+ - Preserve unique insights
539
+ - Note model agreement level for each finding
540
+
541
+ 4. **Attribution Rules:**
542
+ - "unanimous" = all successful models agree
543
+ - "majority" = >50% of successful models agree
544
+ - "single" = only one model identified this
545
+
546
+ ### Required Response Format
547
+
548
+ Respond **only** with valid JSON matching the schema below. Do not include Markdown, prose, or additional commentary outside the JSON object.
549
+
550
+ ```json
551
+ {response_schema}
552
+ ```
553
+
554
+ Rules:
555
+ - Use lowercase values for enumerated fields (verdict, status, severity, etc.)
556
+ - Keep arrays as arrays (use [] when empty)
557
+ - Populate identified_by with actual model names from the reviews
558
+ - Never omit required fields from the schema
559
+ - Use the actual provider names from the reviews (e.g., "gemini", "codex", "claude")""",
560
+ required_context=["spec_id", "spec_title", "review_scope", "num_models", "model_reviews"],
561
+ optional_context=["response_schema"],
562
+ metadata={
563
+ "workflow": "fidelity_review",
564
+ "author": "system",
565
+ "category": "synthesis",
566
+ "output_format": "json",
567
+ "description": "Multi-model fidelity review synthesis",
568
+ },
569
+ )
570
+
571
+
572
+ # =============================================================================
573
+ # Template Registry (PromptTemplate-based)
574
+ # =============================================================================
575
+
576
+
577
+ FIDELITY_REVIEW_TEMPLATES: Dict[str, PromptTemplate] = {
578
+ "FIDELITY_REVIEW_V1": FIDELITY_REVIEW_V1,
579
+ "FIDELITY_DEVIATION_ANALYSIS_V1": FIDELITY_DEVIATION_ANALYSIS_V1,
580
+ "FIDELITY_COMPLIANCE_SUMMARY_V1": FIDELITY_COMPLIANCE_SUMMARY_V1,
581
+ "FIDELITY_SYNTHESIS_PROMPT_V1": FIDELITY_SYNTHESIS_PROMPT_V1,
582
+ }
583
+
584
+
585
+ # =============================================================================
586
+ # Legacy Prompt Templates (String-based for backward compatibility)
587
+ # =============================================================================
588
+
589
+ # Legacy templates have been removed. Use FIDELITY_REVIEW_V1 and related prompts.
590
+
591
+
592
+ # =============================================================================
593
+ # Prompt Builder Implementation
594
+ # =============================================================================
595
+
596
+
597
+ class FidelityReviewPromptBuilder(PromptBuilder):
598
+ """
599
+ Prompt builder for fidelity review workflow.
600
+
601
+ Provides templates for comparing implementations against specifications
602
+ and generating compliance reports.
603
+
604
+ Supports PromptTemplate-based prompts (FIDELITY_*_V1).
605
+ """
606
+
607
+ def __init__(self) -> None:
608
+ """Initialize the builder with template registries."""
609
+ self._prompt_templates = FIDELITY_REVIEW_TEMPLATES
610
+
611
+ def build(self, prompt_id: str, context: Dict[str, Any]) -> str:
612
+ """
613
+ Build a fidelity review prompt.
614
+
615
+ Args:
616
+ prompt_id: Template identifier. Supports:
617
+ - PromptTemplate IDs: FIDELITY_REVIEW_V1, FIDELITY_DEVIATION_ANALYSIS_V1,
618
+ FIDELITY_COMPLIANCE_SUMMARY_V1, FIDELITY_SYNTHESIS_PROMPT_V1
619
+ context: Template context variables
620
+
621
+ Returns:
622
+ Rendered prompt string
623
+
624
+ Raises:
625
+ ValueError: If prompt_id is not recognized
626
+ """
627
+ # Check PromptTemplate registry
628
+ if prompt_id in self._prompt_templates:
629
+ template = self._prompt_templates[prompt_id]
630
+
631
+ # Provide defaults for optional context
632
+ render_context = dict(context)
633
+
634
+ # Add response schema default - use synthesized schema for synthesis prompt
635
+ if "response_schema" not in render_context:
636
+ if prompt_id == "FIDELITY_SYNTHESIS_PROMPT_V1":
637
+ render_context["response_schema"] = FIDELITY_SYNTHESIZED_RESPONSE_SCHEMA
638
+ else:
639
+ render_context["response_schema"] = FIDELITY_RESPONSE_SCHEMA
640
+
641
+ # Add empty defaults for optional fields
642
+ if "spec_description" not in render_context:
643
+ render_context["spec_description"] = ""
644
+ if "test_results" not in render_context:
645
+ render_context["test_results"] = "*No test results available*"
646
+ if "journal_entries" not in render_context:
647
+ render_context["journal_entries"] = "*No journal entries found*"
648
+
649
+ return template.render(render_context)
650
+
651
+ # Unknown prompt_id
652
+ available = ", ".join(sorted(self._prompt_templates.keys()))
653
+ raise ValueError(f"Unknown prompt_id '{prompt_id}'. Available: {available}")
654
+
655
+ def list_prompts(self) -> List[str]:
656
+ """Return available prompt IDs for fidelity review."""
657
+ return sorted(list(self._prompt_templates.keys()))
658
+
659
+ def get_severity_keywords(self, level: str) -> List[str]:
660
+ """
661
+ Get severity categorization keywords for a given level.
662
+
663
+ Args:
664
+ level: Severity level (critical, high, medium, low)
665
+
666
+ Returns:
667
+ List of keywords for that severity level
668
+ """
669
+ return SEVERITY_KEYWORDS.get(level.lower(), [])
670
+
671
+
672
+ __all__ = [
673
+ # PromptTemplate instances
674
+ "FIDELITY_REVIEW_V1",
675
+ "FIDELITY_DEVIATION_ANALYSIS_V1",
676
+ "FIDELITY_COMPLIANCE_SUMMARY_V1",
677
+ "FIDELITY_SYNTHESIS_PROMPT_V1",
678
+ # Template registries
679
+ "FIDELITY_REVIEW_TEMPLATES",
680
+ # Response schemas
681
+ "FIDELITY_RESPONSE_SCHEMA",
682
+ "FIDELITY_SYNTHESIZED_RESPONSE_SCHEMA",
683
+ # Severity keywords
684
+ "SEVERITY_KEYWORDS",
685
+ "CRITICAL_KEYWORDS",
686
+ "HIGH_KEYWORDS",
687
+ "MEDIUM_KEYWORDS",
688
+ "LOW_KEYWORDS",
689
+ # Builder
690
+ "FidelityReviewPromptBuilder",
691
+ ]