From fdead0e9e5f12dccd38b6f3520591565a7972a69 Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 2 Oct 2025 14:29:53 -0400 Subject: [PATCH] feat: Enable conditional compilation for Policy Evaluation Framework in yaze target --- docs/z3ed/POLICY-IMPLEMENTATION-SUMMARY.md | 33 ++++++++++++++++++++-- src/app/app.cmake | 3 ++ src/app/editor/system/proposal_drawer.cc | 15 +++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/docs/z3ed/POLICY-IMPLEMENTATION-SUMMARY.md b/docs/z3ed/POLICY-IMPLEMENTATION-SUMMARY.md index cde2481d..5292e8eb 100644 --- a/docs/z3ed/POLICY-IMPLEMENTATION-SUMMARY.md +++ b/docs/z3ed/POLICY-IMPLEMENTATION-SUMMARY.md @@ -48,7 +48,10 @@ The Policy Evaluation Framework enables safe AI-driven ROM modifications by gati - Added `cli/service/policy_evaluator.cc` to: - `src/cli/z3ed.cmake` (z3ed CLI target) - - `src/app/app.cmake` (yaze GUI target, both macOS and Windows/Linux) + - `src/app/app.cmake` (yaze GUI target, with `YAZE_ENABLE_POLICY_FRAMEWORK=1`) +- **Conditional Compilation**: Policy framework only enabled in main `yaze` target + - `yaze_emu` (emulator) builds without policy support + - Uses `#ifdef YAZE_ENABLE_POLICY_FRAMEWORK` to wrap optional code - Clean build with no errors (warnings only for Abseil version mismatch) ## Code Changes @@ -93,15 +96,38 @@ The Policy Evaluation Framework enables safe AI-driven ROM modifications by gati - Added: `cli/service/policy_evaluator.cc` to z3ed sources 4. **src/app/app.cmake** - - Added: `cli/service/policy_evaluator.cc` to yaze sources (macOS + Windows/Linux) + - Added: `cli/service/policy_evaluator.cc` to yaze sources + - Added: `YAZE_ENABLE_POLICY_FRAMEWORK=1` compile definition + - Note: `yaze_emu` target does NOT include policy framework (optional feature) -5. **docs/z3ed/E6-z3ed-implementation-plan.md** +5. **src/app/editor/system/proposal_drawer.cc** + - Wrapped policy code with `#ifdef YAZE_ENABLE_POLICY_FRAMEWORK` + - Gracefully degrades when policy framework disabled + +6. **docs/z3ed/E6-z3ed-implementation-plan.md** - Updated: AW-04 status from "📋 Next" to "✅ Done" - Updated: Active phase to Policy Framework complete - Updated: Time investment to 28.5 hours total ## Technical Details +### Conditional Compilation + +The policy framework uses conditional compilation to allow building without policy support: + +```cpp +#ifdef YAZE_ENABLE_POLICY_FRAMEWORK + auto& policy_eval = cli::PolicyEvaluator::GetInstance(); + auto policy_result = policy_eval.EvaluateProposal(p.id); + // ... policy evaluation logic ... +#endif +``` + +**Build Targets**: +- `yaze` (main editor): Policy framework **enabled** ✅ +- `yaze_emu` (emulator): Policy framework **disabled** (not needed) +- `z3ed` (CLI): Policy framework **enabled** ✅ + ### API Usage Patterns **StatusOr Error Handling**: @@ -132,6 +158,7 @@ PolicyResult result = evaluator.EvaluateProposal(proposal_id); 2. **StatusOr API**: Used `.ok()` and `.value()` instead of `.has_value()` 3. **String Numbers**: Added `#include "absl/strings/numbers.h"` for SimpleAtoi 4. **String View**: Explicit `std::string()` cast for all absl::StripAsciiWhitespace() calls +5. **Conditional Compilation**: Wrapped policy code with `YAZE_ENABLE_POLICY_FRAMEWORK` to fix yaze_emu build ## Testing Plan diff --git a/src/app/app.cmake b/src/app/app.cmake index 498349a4..c47fdc07 100644 --- a/src/app/app.cmake +++ b/src/app/app.cmake @@ -131,6 +131,9 @@ target_link_libraries( ImGui ) +# Enable policy framework in main yaze target +target_compile_definitions(yaze PRIVATE YAZE_ENABLE_POLICY_FRAMEWORK=1) + # Increase stack size on Windows to prevent stack overflow during asset loading # Windows default is 1MB, macOS/Linux is typically 8MB # LoadAssets() loads 223 graphics sheets and initializes multiple editors diff --git a/src/app/editor/system/proposal_drawer.cc b/src/app/editor/system/proposal_drawer.cc index 55cad157..0a68066b 100644 --- a/src/app/editor/system/proposal_drawer.cc +++ b/src/app/editor/system/proposal_drawer.cc @@ -9,7 +9,11 @@ #include "imgui/imgui.h" #include "app/gui/icons.h" #include "cli/service/rom_sandbox_manager.h" -#include "cli/service/policy_evaluator.h" // NEW: Policy evaluation support + +// Policy evaluation support (optional, only in main yaze build) +#ifdef YAZE_ENABLE_POLICY_FRAMEWORK +#include "cli/service/policy_evaluator.h" +#endif namespace yaze { namespace editor { @@ -93,6 +97,7 @@ void ProposalDrawer::Draw() { ImGui::EndPopup(); } +#ifdef YAZE_ENABLE_POLICY_FRAMEWORK // Policy override dialog (NEW) if (show_override_dialog_) { ImGui::OpenPopup("Override Policy"); @@ -122,6 +127,8 @@ void ProposalDrawer::Draw() { } ImGui::EndPopup(); } +#endif // YAZE_ENABLE_POLICY_FRAMEWORK + } void ProposalDrawer::DrawProposalList() { @@ -251,7 +258,9 @@ void ProposalDrawer::DrawProposalDetail() { } // Policy Status section (NEW) +#ifdef YAZE_ENABLE_POLICY_FRAMEWORK DrawPolicyStatus(); +#endif // Action buttons ImGui::Separator(); @@ -270,6 +279,7 @@ void ProposalDrawer::DrawStatusFilter() { } void ProposalDrawer::DrawPolicyStatus() { +#ifdef YAZE_ENABLE_POLICY_FRAMEWORK if (!selected_proposal_) return; const auto& p = *selected_proposal_; @@ -362,6 +372,7 @@ void ProposalDrawer::DrawPolicyStatus() { } } } +#endif // YAZE_ENABLE_POLICY_FRAMEWORK } void ProposalDrawer::DrawActionButtons() { @@ -374,6 +385,7 @@ void ProposalDrawer::DrawActionButtons() { bool can_accept = true; bool needs_override = false; +#ifdef YAZE_ENABLE_POLICY_FRAMEWORK if (is_pending) { auto& policy_eval = cli::PolicyEvaluator::GetInstance(); if (policy_eval.IsEnabled()) { @@ -385,6 +397,7 @@ void ProposalDrawer::DrawActionButtons() { } } } +#endif // YAZE_ENABLE_POLICY_FRAMEWORK // Accept button (only for pending proposals, gated by policy) if (is_pending) {