diff --git a/editor/src/CostPolicyGuard.h b/editor/src/CostPolicyGuard.h index e91a879..6d60d79 100644 --- a/editor/src/CostPolicyGuard.h +++ b/editor/src/CostPolicyGuard.h @@ -4,6 +4,8 @@ #include #include +#include "PolicyDecisionUtil.h" + struct CostPolicyInput { int stepTokens = 0; int workflowTokens = 0; @@ -30,8 +32,7 @@ public: input.workflowTokens > input.workflowTokenCeiling; if (!stepOver && !workflowOver) { - out.allowed = true; - out.action = "allow"; + setPolicyAction(out.allowed, out.requiresEscalation, out.action, "allow"); return out; } @@ -39,22 +40,18 @@ public: if (workflowOver) out.violations.push_back("workflow_token_ceiling_exceeded"); if (!input.hasRationale) { - out.allowed = false; - out.action = "request_rationale"; + setPolicyAction(out.allowed, out.requiresEscalation, out.action, "request_rationale"); return out; } // With rationale, require explicit escalation approval for overage execution. if (!input.hasEscalationApproval) { - out.allowed = false; - out.requiresEscalation = true; - out.action = "escalate"; + setPolicyAction(out.allowed, out.requiresEscalation, out.action, "escalate"); return out; } - out.allowed = true; + setPolicyAction(out.allowed, out.requiresEscalation, out.action, "allow"); out.requiresEscalation = true; - out.action = "allow"; return out; } }; diff --git a/editor/src/PolicyDecisionUtil.h b/editor/src/PolicyDecisionUtil.h new file mode 100644 index 0000000..1a076a2 --- /dev/null +++ b/editor/src/PolicyDecisionUtil.h @@ -0,0 +1,27 @@ +#pragma once +// Sprint 29 refactor: shared policy decision helpers + +#include +#include + +inline void setEscalateDecision(bool& requiresHumanReview, + std::string& decision, + std::vector& reasons, + const std::string& reason) { + requiresHumanReview = true; + decision = "escalate_review"; + if (!reason.empty()) reasons.push_back(reason); +} + +inline void setPolicyAction(bool& allowed, + bool& requiresEscalation, + std::string& action, + const std::string& nextAction) { + action = nextAction; + if (nextAction == "allow") { + allowed = true; + return; + } + allowed = false; + requiresEscalation = (nextAction == "escalate"); +} diff --git a/editor/src/ReviewGatePolicyRefinement.h b/editor/src/ReviewGatePolicyRefinement.h index a77ad49..c1adf48 100644 --- a/editor/src/ReviewGatePolicyRefinement.h +++ b/editor/src/ReviewGatePolicyRefinement.h @@ -4,6 +4,8 @@ #include #include +#include "PolicyDecisionUtil.h" + struct ReviewGateInput { bool safetyCritical = false; bool securitySensitive = false; @@ -33,17 +35,15 @@ public: } if (input.safetyCritical || input.securitySensitive) { - out.requiresHumanReview = true; - out.decision = "escalate_review"; + setEscalateDecision(out.requiresHumanReview, out.decision, out.reasons, ""); if (input.safetyCritical) out.reasons.push_back("safety_critical_change"); if (input.securitySensitive) out.reasons.push_back("security_sensitive_change"); return out; } if (input.postApplyFailureStreak >= 3) { - out.requiresHumanReview = true; - out.decision = "escalate_review"; - out.reasons.push_back("repeated_post_apply_failures"); + setEscalateDecision(out.requiresHumanReview, out.decision, out.reasons, + "repeated_post_apply_failures"); return out; } @@ -61,8 +61,7 @@ public: return out; } - out.requiresHumanReview = true; - out.decision = "escalate_review"; + setEscalateDecision(out.requiresHumanReview, out.decision, out.reasons, ""); if (input.highCostOverage) out.reasons.push_back("high_cost_overage"); if (input.confidenceScore < 70) out.reasons.push_back("low_confidence"); return out; diff --git a/progress.md b/progress.md index e9dd012..7aa3aa1 100644 --- a/progress.md +++ b/progress.md @@ -9733,3 +9733,39 @@ into phase-level and sprint-level outcomes with closure diagnostics. - **New tests in this sprint plan:** 112/112 passing - **Phase 29a (544-548):** 56/56 passing - **Phase 29b (549-553):** 56/56 passing + +## Sprint 29 End Refactor Pass (Architecture Compliance) + +Performed a dedicated post-sprint refactor pass to reduce policy-guard +duplication and re-validate architecture constraints without behavior changes. + +**Refactors applied:** +- `editor/src/PolicyDecisionUtil.h` + - added shared helpers for policy decision transitions + - centralized common escalation/action state assignment logic +- `editor/src/ReviewGatePolicyRefinement.h` + - switched repeated escalation decision branches to shared helper usage + - removed duplicated inline escalation state mutation +- `editor/src/CostPolicyGuard.h` + - switched repeated action/allow/escalation transitions to shared helper usage + - removed duplicated inline action-state assignments + +**Architecture compliance audit:** +- Header size gate (`<=600` lines): PASS across Sprint 29 modules + - largest audited header: `editor/src/ConstrainedConfidenceCalibrator.h` (`97` lines) +- `goto` usage in Sprint 29 runtime path: PASS (none) +- Stale TODO markers in Sprint 29 modules: PASS (none) +- Header-only pattern for Sprint 29 additions: PASS + +**Refactor verification run:** +- `cmake --build editor/build-native --target step544_test step545_test step546_test step547_test step548_test step549_test step550_test step551_test step552_test step553_test` - PASS +- `./editor/build-native/step544_test` - PASS (12/12) +- `./editor/build-native/step545_test` - PASS (12/12) +- `./editor/build-native/step546_test` - PASS (12/12) +- `./editor/build-native/step547_test` - PASS (12/12) +- `./editor/build-native/step548_test` - PASS (8/8) +- `./editor/build-native/step549_test` - PASS (12/12) +- `./editor/build-native/step550_test` - PASS (12/12) +- `./editor/build-native/step551_test` - PASS (12/12) +- `./editor/build-native/step552_test` - PASS (12/12) +- `./editor/build-native/step553_test` - PASS (8/8)