@danmoisan/drm-copilot-mcp 0.0.1 → 0.0.6

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.
Files changed (183) hide show
  1. package/out/mcp-server.js +98 -21
  2. package/package.json +21 -5
  3. package/resources/claude-customizations/.claude/agent-memory/orchestrator/MEMORY.md +15 -3
  4. package/resources/claude-customizations/.claude/agent-memory/orchestrator/feedback_branch_base_check_unmerged_pr_deps.md +16 -0
  5. package/resources/claude-customizations/.claude/agent-memory/orchestrator/feedback_every_change_through_lifecycle.md +15 -0
  6. package/resources/claude-customizations/.claude/agent-memory/orchestrator/feedback_policy_compliance_not_optional.md +18 -0
  7. package/resources/claude-customizations/.claude/agent-memory/orchestrator/feedback_potential_to_issue_creates_github_issue.md +13 -0
  8. package/resources/claude-customizations/.claude/agent-memory/orchestrator/feedback_remediation_plan_em_dash_required.md +13 -0
  9. package/resources/claude-customizations/.claude/agent-memory/orchestrator/feedback_small_bug_uses_minor_audit.md +13 -0
  10. package/resources/claude-customizations/.claude/agent-memory/orchestrator/feedback_test_files_count_against_500_cap.md +13 -0
  11. package/resources/claude-customizations/.claude/agents/atomic-executor.md +7 -7
  12. package/resources/claude-customizations/.claude/agents/csharp-typed-engineer.md +4 -5
  13. package/resources/claude-customizations/.claude/agents/feature-review.md +7 -3
  14. package/resources/claude-customizations/.claude/agents/orchestrator.md +22 -3
  15. package/resources/claude-customizations/.claude/agents/powershell-typed-engineer.md +1 -1
  16. package/resources/claude-customizations/.claude/agents/pr-author.md +78 -0
  17. package/resources/claude-customizations/.claude/agents/task-researcher.md +10 -6
  18. package/resources/claude-customizations/.claude/hooks/enforce-checkpoint-monotonic.ps1 +303 -0
  19. package/resources/claude-customizations/.claude/hooks/enforce-completion-consistency.ps1 +300 -0
  20. package/resources/claude-customizations/.claude/hooks/enforce-evidence-locations.ps1 +40 -14
  21. package/resources/claude-customizations/.claude/hooks/enforce-feature-folder-order.ps1 +148 -0
  22. package/resources/claude-customizations/.claude/hooks/enforce-orchestration-preimplementation-gate.ps1 +210 -0
  23. package/resources/claude-customizations/.claude/hooks/enforce-pr-author-skill.ps1 +333 -0
  24. package/resources/claude-customizations/.claude/hooks/enforce-prd-feature-before-planner.ps1 +216 -0
  25. package/resources/claude-customizations/.claude/hooks/enforce-promotion-mcp-only.ps1 +84 -15
  26. package/resources/claude-customizations/.claude/hooks/validate-executor-output.ps1 +1 -1
  27. package/resources/claude-customizations/.claude/hooks/validate-feature-review-coverage.ps1 +75 -5
  28. package/resources/claude-customizations/.claude/hooks/validate-orchestrator-output.ps1 +93 -0
  29. package/resources/claude-customizations/.claude/hooks/validate-pr-author-output.ps1 +136 -0
  30. package/resources/claude-customizations/.claude/hooks/validate-task-researcher-output.ps1 +90 -6
  31. package/resources/claude-customizations/.claude/rules/architecture-boundaries.md +46 -0
  32. package/resources/claude-customizations/.claude/rules/benchmark-baselines.md +35 -0
  33. package/resources/claude-customizations/.claude/rules/ci-workflows.md +36 -0
  34. package/resources/claude-customizations/.claude/rules/csharp.md +62 -16
  35. package/resources/claude-customizations/.claude/rules/general-code-change.md +12 -3
  36. package/resources/claude-customizations/.claude/rules/general-unit-test.md +47 -2
  37. package/resources/claude-customizations/.claude/rules/orchestrator-state.md +39 -0
  38. package/resources/claude-customizations/.claude/rules/powershell.md +5 -5
  39. package/resources/claude-customizations/.claude/rules/python.md +4 -3
  40. package/resources/claude-customizations/.claude/rules/quality-tiers.md +51 -0
  41. package/resources/claude-customizations/.claude/rules/typescript.md +37 -8
  42. package/resources/claude-customizations/.claude/settings.json +59 -12
  43. package/resources/claude-customizations/.claude/skills/atomic-plan-contract/SKILL.md +2 -2
  44. package/resources/claude-customizations/.claude/skills/csharp-qa-gate/SKILL.md +25 -10
  45. package/resources/claude-customizations/.claude/skills/evidence-and-timestamp-conventions/SKILL.md +0 -1
  46. package/resources/claude-customizations/.claude/skills/execute-hard-lock/SKILL.md +6 -6
  47. package/resources/claude-customizations/.claude/skills/feature-promotion-lifecycle/SKILL.md +8 -8
  48. package/resources/claude-customizations/.claude/skills/feature-review-workflow/SKILL.md +17 -6
  49. package/resources/claude-customizations/.claude/skills/human-exception-runbook/SKILL.md +52 -0
  50. package/resources/claude-customizations/.claude/skills/human-exception-runbook/example.runbook.md +36 -0
  51. package/resources/claude-customizations/.claude/skills/invoke-csharp-engineer/SKILL.md +4 -4
  52. package/resources/claude-customizations/.claude/skills/orchestrate/SKILL.md +172 -5
  53. package/resources/claude-customizations/.claude/skills/policy-audit-template-usage/SKILL.md +3 -3
  54. package/resources/claude-customizations/.claude/skills/powershell-qa-gate/SKILL.md +4 -4
  55. package/resources/claude-customizations/.claude/skills/pr-base-branch-merge-base/SKILL.md +3 -3
  56. package/resources/claude-customizations/.claude/skills/python-qa-gate/SKILL.md +1 -1
  57. package/resources/claude-customizations/.claude/skills/remediation-handoff-atomic-planner/SKILL.md +90 -17
  58. package/resources/claude-customizations/.claude/skills/research-issue/SKILL.md +5 -3
  59. package/resources/claude-customizations/.claude-variants/csharp-legacy/agents/csharp-typed-engineer.md +69 -0
  60. package/resources/claude-customizations/.claude-variants/csharp-legacy/rules/csharp.md +96 -0
  61. package/resources/claude-customizations/.claude-variants/csharp-legacy/skills/csharp-qa-gate/SKILL.md +77 -0
  62. package/resources/claude-customizations/.claude-variants/csharp-legacy/skills/invoke-csharp-engineer/SKILL.md +64 -0
  63. package/resources/claude-customizations/pack-manifests/core.json +65 -0
  64. package/resources/claude-customizations/pack-manifests/csharp-legacy.json +11 -0
  65. package/resources/claude-customizations/pack-manifests/csharp-modern.json +12 -0
  66. package/resources/claude-customizations/pack-manifests/powershell.json +14 -0
  67. package/resources/claude-customizations/pack-manifests/python.json +14 -0
  68. package/resources/claude-customizations/pack-manifests/typescript.json +9 -0
  69. package/resources/claude-dir-customizations/.mcp.json +3 -3
  70. package/resources/codex-and-agents-customizations/.agents/README.md +1 -1
  71. package/resources/codex-and-agents-customizations/.agents/skills/acceptance-criteria-tracking/SKILL.md +0 -5
  72. package/resources/codex-and-agents-customizations/.agents/skills/architecture-boundaries/SKILL.md +52 -0
  73. package/resources/codex-and-agents-customizations/.agents/skills/atomic-plan-contract/SKILL.md +16 -8
  74. package/resources/codex-and-agents-customizations/.agents/skills/benchmark-baselines/SKILL.md +44 -0
  75. package/resources/codex-and-agents-customizations/.agents/skills/ci-workflows/SKILL.md +45 -0
  76. package/resources/codex-and-agents-customizations/.agents/skills/commit-message/SKILL.md +3 -11
  77. package/resources/codex-and-agents-customizations/.agents/skills/csharp/SKILL.md +1 -5
  78. package/resources/codex-and-agents-customizations/.agents/skills/csharp-change-budget-router/SKILL.md +1 -6
  79. package/resources/codex-and-agents-customizations/.agents/skills/csharp-orchestration-state-machine/SKILL.md +0 -5
  80. package/resources/codex-and-agents-customizations/.agents/skills/csharp-qa-gate/SKILL.md +0 -5
  81. package/resources/codex-and-agents-customizations/.agents/skills/evidence-and-timestamp-conventions/SKILL.md +0 -5
  82. package/resources/codex-and-agents-customizations/.agents/skills/execute-hard-lock/SKILL.md +8 -17
  83. package/resources/codex-and-agents-customizations/.agents/skills/feature-promotion-lifecycle/SKILL.md +41 -25
  84. package/resources/codex-and-agents-customizations/.agents/skills/feature-review-workflow/SKILL.md +1 -6
  85. package/resources/codex-and-agents-customizations/.agents/skills/fill-feature-docs/SKILL.md +0 -5
  86. package/resources/codex-and-agents-customizations/.agents/skills/general-code-change/SKILL.md +86 -0
  87. package/resources/codex-and-agents-customizations/.agents/skills/general-unit-test/SKILL.md +111 -0
  88. package/resources/codex-and-agents-customizations/.agents/skills/human-exception-runbook/SKILL.md +57 -0
  89. package/resources/codex-and-agents-customizations/.agents/skills/human-exception-runbook/example.runbook.md +36 -0
  90. package/resources/codex-and-agents-customizations/.agents/skills/invoke-csharp-engineer/SKILL.md +0 -9
  91. package/resources/codex-and-agents-customizations/.agents/skills/invoke-powershell-engineer/SKILL.md +0 -9
  92. package/resources/codex-and-agents-customizations/.agents/skills/invoke-python-engineer/SKILL.md +0 -9
  93. package/resources/codex-and-agents-customizations/.agents/skills/make-skill-template/SKILL.md +0 -5
  94. package/resources/codex-and-agents-customizations/.agents/skills/orchestrate/SKILL.md +206 -18
  95. package/resources/codex-and-agents-customizations/.agents/skills/orchestrator-state/SKILL.md +48 -0
  96. package/resources/codex-and-agents-customizations/.agents/skills/orchestrator-workflow/SKILL.md +94 -10
  97. package/resources/codex-and-agents-customizations/.agents/skills/policy-audit-template-usage/SKILL.md +3 -8
  98. package/resources/codex-and-agents-customizations/.agents/skills/policy-compliance-order/SKILL.md +0 -10
  99. package/resources/codex-and-agents-customizations/.agents/skills/powershell/SKILL.md +4 -8
  100. package/resources/codex-and-agents-customizations/.agents/skills/powershell-change-budget-router/SKILL.md +1 -6
  101. package/resources/codex-and-agents-customizations/.agents/skills/powershell-orchestration-state-machine/SKILL.md +0 -5
  102. package/resources/codex-and-agents-customizations/.agents/skills/powershell-qa-gate/SKILL.md +3 -9
  103. package/resources/codex-and-agents-customizations/.agents/skills/pr-author/SKILL.md +1 -9
  104. package/resources/codex-and-agents-customizations/.agents/skills/pr-base-branch-merge-base/SKILL.md +4 -9
  105. package/resources/codex-and-agents-customizations/.agents/skills/pr-context-artifacts/SKILL.md +0 -5
  106. package/resources/codex-and-agents-customizations/.agents/skills/python/SKILL.md +1 -5
  107. package/resources/codex-and-agents-customizations/.agents/skills/python-change-budget-router/SKILL.md +1 -6
  108. package/resources/codex-and-agents-customizations/.agents/skills/python-qa-gate/SKILL.md +0 -5
  109. package/resources/codex-and-agents-customizations/.agents/skills/python-suppressions/SKILL.md +2 -6
  110. package/resources/codex-and-agents-customizations/.agents/skills/quality-tiers/SKILL.md +57 -0
  111. package/resources/codex-and-agents-customizations/.agents/skills/remediation-handoff-atomic-planner/SKILL.md +0 -5
  112. package/resources/codex-and-agents-customizations/.agents/skills/repo-automation-adapter/SKILL.md +96 -72
  113. package/resources/codex-and-agents-customizations/.agents/skills/repo-automation-adapter/agents/openai.yaml +1 -1
  114. package/resources/codex-and-agents-customizations/.agents/skills/research-issue/SKILL.md +0 -10
  115. package/resources/codex-and-agents-customizations/.agents/skills/review-epic/SKILL.md +0 -5
  116. package/resources/codex-and-agents-customizations/.agents/skills/review-feature/SKILL.md +0 -5
  117. package/resources/codex-and-agents-customizations/.agents/skills/review-staged/SKILL.md +0 -5
  118. package/resources/codex-and-agents-customizations/.agents/skills/self-explanatory-code-commenting/SKILL.md +2 -6
  119. package/resources/codex-and-agents-customizations/.agents/skills/skill-canonical-location-audit/SKILL.md +0 -5
  120. package/resources/codex-and-agents-customizations/.agents/skills/tonality/SKILL.md +86 -0
  121. package/resources/codex-and-agents-customizations/.agents/skills/translate-claude-to-codex/SKILL.md +297 -0
  122. package/resources/codex-and-agents-customizations/.agents/skills/translate-copilot-to-claude/SKILL.md +0 -22
  123. package/resources/codex-and-agents-customizations/.agents/skills/typescript/SKILL.md +1 -5
  124. package/resources/codex-and-agents-customizations/.agents/skills/typescript-suppressions/SKILL.md +2 -6
  125. package/resources/codex-and-agents-customizations/.agents/skills/update-status/SKILL.md +0 -5
  126. package/resources/codex-and-agents-customizations/.codex/agents/atomic-executor.toml +5 -5
  127. package/resources/codex-and-agents-customizations/.codex/agents/orchestrator.toml +91 -63
  128. package/resources/codex-and-agents-customizations/.codex/agents/powershell-atomic-executor.toml +1 -1
  129. package/resources/codex-and-agents-customizations/.codex/agents/powershell-typed-engineer.toml +1 -1
  130. package/resources/codex-and-agents-customizations/.codex/config.toml +111 -137
  131. package/resources/codex-and-agents-customizations/.codex/hooks/enforce-checkpoint-monotonic.ps1 +303 -0
  132. package/resources/codex-and-agents-customizations/.codex/hooks/enforce-completion-consistency.ps1 +300 -0
  133. package/resources/codex-and-agents-customizations/.codex/hooks/enforce-orchestration-preimplementation-gate.ps1 +148 -0
  134. package/resources/codex-and-agents-customizations/.codex/hooks/enforce-pr-author-skill.ps1 +336 -0
  135. package/resources/codex-and-agents-customizations/.codex/hooks/enforce-promotion-mcp-only.ps1 +84 -18
  136. package/resources/codex-and-agents-customizations/.codex/prompts/orchestrate-work.md +4 -3
  137. package/resources/codex-and-agents-customizations/.codex/scripts/post-codex-worktree-session.ps1 +5 -0
  138. package/resources/codex-and-agents-customizations/.github/workflows/_validate-orchestrator-state.yml +68 -0
  139. package/resources/codex-and-agents-customizations/.github/workflows/validate-orchestrator-state.yml +15 -0
  140. package/resources/config/orchestration-routing.json +76 -0
  141. package/resources/customizations/.github/agents/Powershell DI Unit Test Engineer.agent.md +1 -1
  142. package/resources/customizations/.github/agents/atomic_executor.agent.md +1 -1
  143. package/resources/customizations/.github/agents/atomic_planning.agent.md +10 -10
  144. package/resources/customizations/.github/agents/csharp-orchestrator.agent.md +6 -2
  145. package/resources/customizations/.github/agents/feature-review.agent.md +2 -2
  146. package/resources/customizations/.github/agents/orchestrator.agent.md +6 -2
  147. package/resources/customizations/.github/agents/powershell-atomic-executor.agent.md +4 -4
  148. package/resources/customizations/.github/agents/powershell-atomic-planning.agent.md +10 -10
  149. package/resources/customizations/.github/agents/powershell-orchestrator.agent.md +6 -2
  150. package/resources/customizations/.github/agents/powershell-typed-engineer.agent.md +2 -2
  151. package/resources/customizations/.github/agents/pr-author.agent.md +25 -0
  152. package/resources/customizations/.github/agents/python-orchestrator.agent.md +6 -2
  153. package/resources/customizations/.github/agents/staged-review.agent.md +1 -1
  154. package/resources/customizations/.github/agents/task-researcher.agent.md +4 -4
  155. package/resources/customizations/.github/instructions/powershell-code-change.instructions.md +6 -6
  156. package/resources/customizations/.github/prompts/fillout-prd-feature.prompt.md +1 -1
  157. package/resources/customizations/.github/prompts/generate-commit-message-repo.prompt.md +1 -1
  158. package/resources/customizations/.github/prompts/orchestrate-csharp-work.prompt.md +5 -3
  159. package/resources/customizations/.github/prompts/orchestrate-work.prompt.md +5 -3
  160. package/resources/customizations/.github/prompts/research-issue.prompt.md +4 -3
  161. package/resources/customizations/.github/skills/atomic-plan-contract/SKILL.md +14 -1
  162. package/resources/customizations/.github/skills/feature-promotion-lifecycle/SKILL.md +11 -7
  163. package/resources/customizations/.github/skills/feature-review-workflow/SKILL.md +10 -1
  164. package/resources/customizations/.github/skills/pr-base-branch-merge-base/SKILL.md +2 -2
  165. package/resources/customizations/.github/skills/remediation-handoff-atomic-planner/SKILL.md +5 -0
  166. package/resources/powershell/PoshQC/settings/pester.runsettings.psd1 +7 -0
  167. package/resources/scripts/dev_tools/_orchestrator_state_human_interaction.py +127 -0
  168. package/resources/scripts/dev_tools/_orchestrator_state_routing.py +216 -0
  169. package/resources/scripts/dev_tools/push_down_claude_customizations.py +276 -61
  170. package/resources/scripts/dev_tools/push_down_claude_filesystem.py +472 -0
  171. package/resources/scripts/dev_tools/push_down_claude_pack_selection.py +401 -0
  172. package/resources/scripts/dev_tools/validate_orchestration_artifacts.py +103 -411
  173. package/resources/scripts/dev_tools/validate_orchestration_review_artifacts.py +107 -0
  174. package/resources/scripts/dev_tools/validate_orchestrator_state.py +505 -0
  175. package/resources/scripts/dev_tools/validate_policy_audit_artifact.py +472 -0
  176. package/resources/templates/push_down_claude_customizations.py +162 -117
  177. package/resources/claude-customizations/.claude/agent-memory/orchestrator/feedback_repo_root_is_source_of_truth.md +0 -11
  178. package/resources/claude-customizations/.claude/agent-memory/orchestrator/feedback_vsce_verify_package_location.md +0 -19
  179. package/resources/claude-customizations/.claude/agent-memory/orchestrator/project_extension_location.md +0 -11
  180. package/resources/claude-customizations/.claude/agent-memory/prd-feature/MEMORY.md +0 -1
  181. package/resources/claude-customizations/.claude/agent-memory/prd-feature/project_push_down_pattern.md +0 -13
  182. package/resources/claude-customizations/.claude/agent-memory/task-researcher/MEMORY.md +0 -3
  183. package/resources/claude-customizations/.claude/agent-memory/task-researcher/project_push_down_claude_dir.md +0 -11
@@ -0,0 +1,472 @@
1
+ """Validate policy-audit orchestration review artifacts.
2
+
3
+ Purpose:
4
+ Hold the policy-audit specific parsing helpers and substantive validation
5
+ checks so the review-artifact validator stays cohesive and below the
6
+ repository file-size limit.
7
+
8
+ Usage:
9
+ Import ``validate_policy_audit_text`` from this module when a caller needs
10
+ only policy-audit validation, or through
11
+ ``scripts.dev_tools.validate_orchestration_artifacts`` for the stable CLI
12
+ entrypoint contract.
13
+
14
+ Flow:
15
+ 1. Parse the coverage table, checklist lines, and per-language comparison
16
+ bullets from the policy-audit document.
17
+ 2. Reject placeholder, malformed, or non-numeric coverage evidence when the
18
+ repository policy requires explicit percentages.
19
+ 3. Return a list of contract violations for the caller to surface.
20
+
21
+ Invariants / Constraints:
22
+ - Placeholder markers are treated as failures.
23
+ - Coverage rows must retain numeric evidence unless the field is marked N/A.
24
+ - The public validator functions return lists of error strings and do not
25
+ print or mutate files.
26
+
27
+ Side Effects:
28
+ None.
29
+ """
30
+
31
+ from __future__ import annotations
32
+
33
+ import re
34
+
35
+ COVERAGE_PERCENT_RE = re.compile(r"\b\d+(?:\.\d+)?%")
36
+ POLICY_AUDIT_REQUIRED_HEADINGS = (
37
+ "## Executive Summary",
38
+ "## 1. General Unit Test Policy Compliance",
39
+ "## 2. General Code Change Policy Compliance",
40
+ "## 3. Language-Specific Code Change Policy Compliance",
41
+ "## 4. Language-Specific Unit Test Policy Compliance",
42
+ "## 5. Test Coverage Detail",
43
+ "## 6. Test Execution Metrics",
44
+ "## 7. Code Quality Checks",
45
+ "## 8. Gaps and Exceptions",
46
+ "## 9. Summary of Changes",
47
+ "## 10. Compliance Verdict",
48
+ "## Appendix A: Test Inventory",
49
+ "## Appendix B: Toolchain Commands Reference",
50
+ )
51
+ POLICY_AUDIT_REQUIRED_CHECKLIST_LABELS = (
52
+ "TypeScript baseline coverage artifact:",
53
+ "TypeScript post-change coverage artifact:",
54
+ "PowerShell baseline coverage artifact:",
55
+ "PowerShell post-change coverage artifact:",
56
+ "Per-language comparison summary:",
57
+ )
58
+ POLICY_AUDIT_COMPARISON_HEADING = "### 1.2.1 Per-Language Coverage Comparison"
59
+ PLACEHOLDER_MARKERS = (
60
+ "[n]",
61
+ "[path",
62
+ "[artifact",
63
+ "[section reference",
64
+ "[language]",
65
+ "tbd",
66
+ "unverified",
67
+ "missing",
68
+ )
69
+ TEMPLATE_RESOLVER_TOOL = "resolve_policy_audit_template_asset"
70
+ TEMPLATE_RESOLVER_MISSING_MARKERS = (
71
+ "not exposed",
72
+ "was not exposed",
73
+ "missing resolver exposure",
74
+ "fallback template",
75
+ "fallback-template",
76
+ )
77
+
78
+
79
+ def _has_numeric_coverage(value: str) -> bool:
80
+ """Return True when a coverage field contains a numeric percentage.
81
+
82
+ Purpose:
83
+ Identify whether a coverage field satisfies the policy requirement for
84
+ explicit numeric evidence.
85
+
86
+ Args:
87
+ value (str): Raw coverage field text extracted from an audit artifact.
88
+
89
+ Returns:
90
+ bool: True when the value contains at least one percentage token.
91
+
92
+ Raises:
93
+ None.
94
+
95
+ Side Effects:
96
+ None.
97
+ """
98
+
99
+ return COVERAGE_PERCENT_RE.search(value) is not None
100
+
101
+
102
+ def _is_na_value(value: str) -> bool:
103
+ """Return True when an audit field explicitly records not-applicable.
104
+
105
+ Purpose:
106
+ Allow the validator to distinguish missing numeric evidence from fields
107
+ that are intentionally marked not applicable.
108
+
109
+ Args:
110
+ value (str): Raw field text to inspect.
111
+
112
+ Returns:
113
+ bool: True when the value begins with an N/A marker.
114
+
115
+ Raises:
116
+ None.
117
+
118
+ Side Effects:
119
+ None.
120
+ """
121
+
122
+ return value.strip().lower().startswith("n/a")
123
+
124
+
125
+ def _has_placeholder_marker(value: str) -> bool:
126
+ """Return True when a field still contains template placeholder text.
127
+
128
+ Purpose:
129
+ Fail closed when a review artifact still includes unfinished template or
130
+ draft markers.
131
+
132
+ Args:
133
+ value (str): Raw field text to inspect.
134
+
135
+ Returns:
136
+ bool: True when the field includes a known placeholder marker.
137
+
138
+ Raises:
139
+ None.
140
+
141
+ Side Effects:
142
+ None.
143
+ """
144
+
145
+ lowered = value.lower()
146
+ return any(marker in lowered for marker in PLACEHOLDER_MARKERS)
147
+
148
+
149
+ def _reports_missing_template_resolver_success(text: str) -> bool:
150
+ """Return True for fallback-template artifacts that still claim success."""
151
+
152
+ lowered = text.lower()
153
+ if TEMPLATE_RESOLVER_TOOL not in lowered:
154
+ return False
155
+ if not any(marker in lowered for marker in TEMPLATE_RESOLVER_MISSING_MARKERS):
156
+ return False
157
+ return re.search(r"\b(pass|ready|readiness)\b", lowered) is not None
158
+
159
+
160
+ def _extract_policy_audit_coverage_rows(text: str) -> list[dict[str, str]]:
161
+ """Parse the policy-audit coverage table into named row dictionaries.
162
+
163
+ Purpose:
164
+ Normalize coverage table rows so later validation checks can reason
165
+ about baseline, post-change, and new-code evidence by language.
166
+
167
+ Args:
168
+ text (str): Full policy-audit artifact text.
169
+
170
+ Returns:
171
+ list[dict[str, str]]: Parsed coverage rows keyed by canonical column
172
+ names.
173
+
174
+ Raises:
175
+ None.
176
+
177
+ Side Effects:
178
+ None.
179
+ """
180
+
181
+ rows: list[dict[str, str]] = []
182
+
183
+ # Interpret only the seven-column coverage table rows and ignore headers or
184
+ # separator rows.
185
+ for line in text.splitlines():
186
+ if not line.startswith("|"):
187
+ continue
188
+ cells = [cell.strip() for cell in line.split("|")[1:-1]]
189
+ if len(cells) != 7:
190
+ continue
191
+ language = cells[0]
192
+ if language in {"Language", "----------"} or not language:
193
+ continue
194
+ if set(language) == {"-"}:
195
+ continue
196
+ rows.append(
197
+ {
198
+ "Language": language,
199
+ "Files Changed": cells[1],
200
+ "Tests": cells[2],
201
+ "Test Result": cells[3],
202
+ "Baseline Coverage": cells[4],
203
+ "Post-Change Coverage": cells[5],
204
+ "New Code Coverage": cells[6],
205
+ }
206
+ )
207
+
208
+ return rows
209
+
210
+
211
+ def _find_policy_audit_checklist_line(text: str, label: str) -> str | None:
212
+ """Return the checklist line containing a required label.
213
+
214
+ Purpose:
215
+ Locate required evidence checklist entries without assuming a fixed line
216
+ number or surrounding context.
217
+
218
+ Args:
219
+ text (str): Full policy-audit artifact text.
220
+ label (str): Required checklist label to locate.
221
+
222
+ Returns:
223
+ str | None: The matching checklist line, if present.
224
+
225
+ Raises:
226
+ None.
227
+
228
+ Side Effects:
229
+ None.
230
+ """
231
+
232
+ # Search only checklist bullets because the same label text may appear in
233
+ # narrative prose elsewhere in the document.
234
+ for line in text.splitlines():
235
+ stripped = line.strip()
236
+ if stripped.startswith("- ") and label in stripped:
237
+ return stripped
238
+ return None
239
+
240
+
241
+ def _extract_policy_audit_comparison_lines(text: str) -> dict[str, str]:
242
+ """Return per-language comparison lines keyed by normalized language name.
243
+
244
+ Purpose:
245
+ Capture the explicit comparison bullets under the per-language coverage
246
+ section so downstream checks can verify each language summary is present.
247
+
248
+ Args:
249
+ text (str): Full policy-audit artifact text.
250
+
251
+ Returns:
252
+ dict[str, str]: Mapping of lowercase language name to the matching
253
+ comparison bullet.
254
+
255
+ Raises:
256
+ None.
257
+
258
+ Side Effects:
259
+ None.
260
+ """
261
+
262
+ in_section = False
263
+ comparison_lines: dict[str, str] = {}
264
+
265
+ # Limit parsing to the per-language coverage section so unrelated bullets do
266
+ # not satisfy the evidence checks accidentally.
267
+ for line in text.splitlines():
268
+ stripped = line.strip()
269
+ if stripped == POLICY_AUDIT_COMPARISON_HEADING:
270
+ in_section = True
271
+ continue
272
+ if in_section and stripped.startswith("### "):
273
+ break
274
+ if not in_section or not stripped.startswith("- "):
275
+ continue
276
+ language, separator, _ = stripped[2:].partition(":")
277
+ if not separator:
278
+ continue
279
+ comparison_lines[language.strip().lower()] = stripped
280
+
281
+ return comparison_lines
282
+
283
+
284
+ def _comparison_line_has_labelled_percentage(line: str, label: str) -> bool:
285
+ """Return True when the comparison line includes a labelled percentage.
286
+
287
+ Purpose:
288
+ Verify that each comparison bullet records numeric evidence after the
289
+ expected label, rather than narrative text alone.
290
+
291
+ Args:
292
+ line (str): Comparison bullet text.
293
+ label (str): Required label to anchor the percentage search.
294
+
295
+ Returns:
296
+ bool: True when the labelled numeric evidence is present.
297
+
298
+ Raises:
299
+ None.
300
+
301
+ Side Effects:
302
+ None.
303
+ """
304
+
305
+ pattern = re.compile(rf"{re.escape(label)}.*?\d+(?:\.\d+)?%")
306
+ return pattern.search(line) is not None
307
+
308
+
309
+ def validate_policy_audit_substantive_requirements(text: str) -> list[str]:
310
+ """Validate policy-audit evidence requirements beyond headings.
311
+
312
+ Purpose:
313
+ Enforce the numeric coverage and evidence checklist requirements that
314
+ turn the review template into an auditable artifact.
315
+
316
+ Args:
317
+ text (str): Full policy-audit artifact text.
318
+
319
+ Returns:
320
+ list[str]: Validation errors describing each missing or malformed
321
+ evidence element.
322
+
323
+ Raises:
324
+ None.
325
+
326
+ Side Effects:
327
+ None.
328
+ """
329
+
330
+ errors: list[str] = []
331
+
332
+ # Require every checklist line to exist and remain free of unresolved
333
+ # placeholders before the audit can report a passing verdict.
334
+ for label in POLICY_AUDIT_REQUIRED_CHECKLIST_LABELS:
335
+ line = _find_policy_audit_checklist_line(text, label)
336
+ if line is None:
337
+ errors.append(f"Policy audit missing required checklist line: {label}")
338
+ continue
339
+ if _has_placeholder_marker(line):
340
+ errors.append(
341
+ f"Policy audit checklist line still contains placeholder text: {label}"
342
+ )
343
+
344
+ coverage_rows = _extract_policy_audit_coverage_rows(text)
345
+ if not coverage_rows:
346
+ errors.append("Policy audit missing coverage metrics table rows.")
347
+
348
+ if POLICY_AUDIT_COMPARISON_HEADING not in text:
349
+ errors.append(
350
+ "Policy audit missing required heading: "
351
+ f"{POLICY_AUDIT_COMPARISON_HEADING}"
352
+ )
353
+
354
+ comparison_lines = _extract_policy_audit_comparison_lines(text)
355
+
356
+ # Validate each language row against the comparison summary so baseline,
357
+ # post-change, and changed-code evidence remain synchronized.
358
+ for row in coverage_rows:
359
+ language = row["Language"]
360
+ baseline = row["Baseline Coverage"]
361
+ post_change = row["Post-Change Coverage"]
362
+ new_code = row["New Code Coverage"]
363
+ requires_coverage_comparison = any(
364
+ not _is_na_value(value) for value in (baseline, post_change, new_code)
365
+ )
366
+
367
+ if not _is_na_value(baseline) and not _has_numeric_coverage(baseline):
368
+ errors.append(
369
+ f"Policy audit missing numeric baseline coverage for {language}."
370
+ )
371
+ if not _is_na_value(post_change) and not _has_numeric_coverage(post_change):
372
+ errors.append(
373
+ f"Policy audit missing numeric post-change coverage for {language}."
374
+ )
375
+ if not _is_na_value(new_code) and not _has_numeric_coverage(new_code):
376
+ errors.append(
377
+ "Policy audit missing numeric new/changed-code coverage for "
378
+ f"{language}."
379
+ )
380
+
381
+ if not requires_coverage_comparison:
382
+ continue
383
+
384
+ comparison_line = comparison_lines.get(language.lower())
385
+ if comparison_line is None:
386
+ errors.append(
387
+ f"Policy audit missing per-language comparison line for {language}."
388
+ )
389
+ continue
390
+
391
+ if not _comparison_line_has_labelled_percentage(comparison_line, "Baseline:"):
392
+ errors.append(
393
+ f"Policy audit comparison line missing numeric baseline for {language}."
394
+ )
395
+ if not _comparison_line_has_labelled_percentage(
396
+ comparison_line, "Post-change:"
397
+ ):
398
+ errors.append(
399
+ "Policy audit comparison line missing numeric post-change "
400
+ f"coverage for {language}."
401
+ )
402
+ if "Change:" not in comparison_line:
403
+ errors.append(
404
+ "Policy audit comparison line missing explicit change text for "
405
+ f"{language}."
406
+ )
407
+ if (
408
+ re.search(
409
+ r"Disposition:\s*(PASS|FAIL|N/A|INCOMPLETE|BLOCKED)",
410
+ comparison_line,
411
+ )
412
+ is None
413
+ ):
414
+ errors.append(
415
+ f"Policy audit comparison line missing disposition for {language}."
416
+ )
417
+ if not _is_na_value(new_code) and not _comparison_line_has_labelled_percentage(
418
+ comparison_line, "New/changed-code coverage:"
419
+ ):
420
+ errors.append(
421
+ "Policy audit comparison line missing numeric new/changed-code "
422
+ f"coverage for {language}."
423
+ )
424
+ if "Evidence:" not in comparison_line:
425
+ errors.append(
426
+ "Policy audit comparison line missing evidence reference for "
427
+ f"{language}."
428
+ )
429
+ elif _has_placeholder_marker(comparison_line):
430
+ errors.append(
431
+ "Policy audit comparison line still contains placeholder text for "
432
+ f"{language}."
433
+ )
434
+
435
+ return errors
436
+
437
+
438
+ def validate_policy_audit_text(text: str) -> list[str]:
439
+ """Validate template-derived policy-audit structure.
440
+
441
+ Purpose:
442
+ Enforce the required policy-audit headings and substantive evidence
443
+ checks for repository review artifacts.
444
+
445
+ Args:
446
+ text (str): Full policy-audit artifact text.
447
+
448
+ Returns:
449
+ list[str]: Validation errors for missing headings or evidence.
450
+
451
+ Raises:
452
+ None.
453
+
454
+ Side Effects:
455
+ None.
456
+ """
457
+
458
+ errors: list[str] = []
459
+ if "Template Usage Instructions" in text:
460
+ errors.append("Policy audit still contains the template instruction block.")
461
+ if "[Component Name]" in text:
462
+ errors.append("Policy audit still contains placeholder component text.")
463
+ if _reports_missing_template_resolver_success(text):
464
+ errors.append(
465
+ "Policy audit cannot report PASS or READY when "
466
+ f"{TEMPLATE_RESOLVER_TOOL} is reported as missing or not exposed."
467
+ )
468
+ for heading in POLICY_AUDIT_REQUIRED_HEADINGS:
469
+ if heading not in text:
470
+ errors.append(f"Policy audit missing required heading: {heading}")
471
+ errors.extend(validate_policy_audit_substantive_requirements(text))
472
+ return errors