-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.cpp
More file actions
76 lines (70 loc) · 3.47 KB
/
Copy pathkernel.cpp
File metadata and controls
76 lines (70 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "kernel.h"
#include <iostream>
#include "surgery.h"
#include "telemetry.h"
#include "memory.h"
GodBrainKernel::GodBrainKernel() {
// Initialize system state
}
bool GodBrainKernel::validate_sovereignty(const std::string& command_type, const json& payload) {
if (command_type == "execute_godbrain_script" ||
command_type == "propose_sovereign_architect_change" ||
command_type == "record_godbrain_skill_run" ||
command_type == "promote_godbrain_skill") {
if (!payload.contains("reasoning") || !payload["reasoning"].is_string()) {
std::cout << "[KERNEL SECURITY] High risk command rejected: No reasoning provided." << std::endl;
return false;
}
const std::string& reasoning = payload["reasoning"].get_ref<const std::string&>();
bool is_blank = reasoning.find_first_not_of(" \t\r\n") == std::string::npos;
if (is_blank) {
std::cout << "[KERNEL SECURITY] High risk command rejected: reasoning is empty/whitespace." << std::endl;
return false;
}
}
return true;
}
json GodBrainKernel::dispatch(const std::string& command_type, const json& payload) {
std::cout << "[KERNEL] Intercepting Command: " << command_type << std::endl;
if (!validate_sovereignty(command_type, payload)) {
return {{"status", "error"}, {"message", "Sovereignty check failed: Action exceeds current authority or lacks reasoning."}};
}
try {
json result;
if (command_type == "execute_godbrain_script") {
result = surgery::execute_self_command(payload.value("command", ""));
} else if (command_type == "save_godbrain_thought") {
result = memory::save_thought(payload);
} else if (command_type == "query_recent_thoughts" ||
command_type == "query_constellation") {
const std::string query = payload.value("query", "");
if (!query.empty()) {
result = memory::search_verified(query, payload.value("limit", 8));
} else {
result = memory::get_recent(payload.value("limit", 5));
}
} else if (command_type == "set_godbrain_status") {
result = memory::set_status(payload);
} else if (command_type == "record_godbrain_skill_run") {
result = memory::record_skill_run(payload);
} else if (command_type == "promote_godbrain_skill") {
result = memory::promote_skill(payload);
} else if (command_type == "query_godbrain_skills") {
result = memory::query_skills(payload);
} else if (command_type == "get_system_telemetry") {
result = telemetry::get_current_state();
} else if (command_type == "observe_godbrain_host") {
result = memory::observe_host();
} else if (command_type == "promote_godbrain_claim") {
result = memory::promote_claim(payload);
} else if (command_type == "propose_sovereign_architect_change") {
result = surgery::execute_self_command(payload.value("proposal_script", ""));
} else {
return {{"status", "error"}, {"message", "Unknown command: " + command_type}};
}
return {{"status", "success"}, {"data", result}};
} catch (const std::exception& e) {
std::cout << "[KERNEL ERROR] " << e.what() << std::endl;
return {{"status", "error"}, {"message", e.what()}};
}
}