From c05e83ec753d2f85a90ef6ea1150a80d19461b85 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 17 Feb 2026 21:50:51 -0700 Subject: [PATCH] Step 647: self-modification safety guard --- editor/CMakeLists.txt | 9 ++++++++ editor/src/SelfModificationSafetyGuard.h | 28 ++++++++++++++++++++++++ editor/tests/step647_test.cpp | 25 +++++++++++++++++++++ progress.md | 24 ++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 editor/src/SelfModificationSafetyGuard.h create mode 100644 editor/tests/step647_test.cpp diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 904f7cf..4d9bd56 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -4702,4 +4702,13 @@ target_link_libraries(step646_test PRIVATE tree_sitter_javascript tree_sitter_typescript tree_sitter_java tree_sitter_rust tree_sitter_go) +add_executable(step647_test tests/step647_test.cpp) +target_include_directories(step647_test PRIVATE src) +target_link_libraries(step647_test PRIVATE + nlohmann_json::nlohmann_json + unofficial::tree-sitter::tree-sitter + tree_sitter_python tree_sitter_cpp tree_sitter_elisp + tree_sitter_javascript tree_sitter_typescript + tree_sitter_java tree_sitter_rust tree_sitter_go) + # Step 12: Dear ImGui shell scaffolding created (main.cpp exists but not built due to dependencies) diff --git a/editor/src/SelfModificationSafetyGuard.h b/editor/src/SelfModificationSafetyGuard.h new file mode 100644 index 0000000..51e158f --- /dev/null +++ b/editor/src/SelfModificationSafetyGuard.h @@ -0,0 +1,28 @@ +#pragma once +// Step 647: Self-modification safety guard + +#include +#include + +class SelfModificationSafetyGuard { +public: + static bool isLiveBinaryPath(const std::string& filePath, + const std::vector& liveRoots) { + for (const auto& root : liveRoots) { + if (!root.empty() && filePath.rfind(root, 0) == 0) return true; + } + return false; + } + + static bool allowMutation(const std::string& filePath, + const std::vector& liveRoots, + std::string* reason) { + if (!reason) return false; + reason->clear(); + if (isLiveBinaryPath(filePath, liveRoots)) { + *reason = "Cannot mutate live binary - use a build/restart cycle."; + return false; + } + return true; + } +}; diff --git a/editor/tests/step647_test.cpp b/editor/tests/step647_test.cpp new file mode 100644 index 0000000..da5960d --- /dev/null +++ b/editor/tests/step647_test.cpp @@ -0,0 +1,25 @@ +// Step 647: Self-modification safety guard (12 tests) + +#include "SelfModificationSafetyGuard.h" +#include + +static int p=0,f=0; +#define T(n) { std::cout<<" "<<#n<<"... "; } +#define P() { std::cout<<"PASS\n"; ++p; } +#define F(m) { std::cout<<"FAIL: "<