22bool g_hasRuntimeWorld =
false;
24Result<void> knownFields(
const Value::Object&
object,
const std::set<std::string>& allowed,
25 std::string_view
path) {
28 if (!allowed.contains(
name))
39 return Result<std::vector<std::string>>::failure(
41 std::vector<std::string>
out;
42 out.reserve(array->size());
44 if (!(*array)[
index].isString())
48 out.push_back((*array)[
index].asString());
50 return Result<std::vector<std::string>>::success(std::move(
out));
53Result<std::string> optionalStringField(
const Value::Object&
object, std::string_view
name,
54 std::string_view
path, std::string*
out) {
55 const auto found =
object.find(std::string(
name));
57 if (!
found->second.isString())
60 std::string(
path) +
"." + std::string(
name)));
65Value encodeStrings(
const std::vector<std::string>&
values) {
67 array.reserve(
values.size());
69 return Value(std::move(array));
72std::vector<std::string> uniqueSorted(std::vector<std::string>
values) {
81 const SQInteger
top = sq_gettop(
vm);
83 sq_pushstring(
vm,
name, -1);
84 if (SQ_FAILED(sq_get(
vm, -2))) {
89 script::SquirrelValueOptions
options;
99 std::vector<std::string>*
out) {
100 const auto found =
object.find(
key);
101 if (
found ==
object.
end() || !
found->second.isArray())
return;
103 if (entry.isString() && !entry.asString().empty())
out->push_back(entry.asString());
114 auto known = knownFields(*
object,
115 {
"dimensions",
"genre",
"perspective",
"summary",
"systems",
"tags",
"title"},
122 std::string dimensions;
123 std::string perspective;
124 auto titleResult = optionalStringField(*
object,
"title",
"world", &
title);
126 auto summaryResult = optionalStringField(*
object,
"summary",
"world", &summary);
128 auto dimensionsResult = optionalStringField(*
object,
"dimensions",
"world", &dimensions);
130 auto perspectiveResult = optionalStringField(*
object,
"perspective",
"world", &perspective);
133 if (!dimensions.empty() && dimensions !=
"2d" && dimensions !=
"3d" && dimensions !=
"hybrid")
137 if (!
title.empty()) normalized.emplace(
"title",
Value(std::move(
title)));
138 if (!summary.empty()) normalized.emplace(
"summary",
Value(std::move(summary)));
139 if (!dimensions.empty()) normalized.emplace(
"dimensions",
Value(std::move(dimensions)));
140 if (!perspective.empty()) normalized.emplace(
"perspective",
Value(std::move(perspective)));
142 for (
const char*
key : {
"genre",
"tags",
"systems"}) {
143 const auto found =
object->find(
key);
145 auto array = stringArray(
found->second, std::string(
"world.") +
key);
147 normalized.emplace(
key, encodeStrings(uniqueSorted(std::move(array).takeValue())));
150 const bool hasIdentity = normalized.contains(
"title") || normalized.contains(
"summary") ||
151 normalized.contains(
"genre") || normalized.contains(
"systems");
155 "world requires at least one of title, summary, genre, or systems",
"world"));
163 g_runtimeWorld = std::move(parsed).takeValue();
164 g_hasRuntimeWorld =
true;
169 g_runtimeWorld =
Value{};
170 g_hasRuntimeWorld =
false;
176 return g_hasRuntimeWorld ? &g_runtimeWorld :
nullptr;
181 const bool hasRuntime = runtime && runtime->isObject();
187 std::string
source =
"none";
192 if (!merged.contains(
"title") && !
input.configTitle.empty())
193 merged.emplace(
"title",
Value(
input.configTitle));
194 world =
Value(std::move(merged));
195 }
else if (!
input.configTitle.empty()) {
203 {
"contractLoaded",
Value(
input.contractLoaded)},
204 {
"domains", encodeStrings(uniqueSorted(
input.domains))},
205 {
"configuredModules", encodeStrings(uniqueSorted(
input.configuredModules))},
206 {
"liveModules", encodeStrings(uniqueSorted(
input.liveModules))}};
210 if (world.isObject())
snapshot.emplace(
"world", std::move(world));
216 auto config = readRootMember(
vm,
"config");
217 if (!config || !config.value().isObject()) {
218 if (config) config.ignore();
222 const auto found =
object->find(
"title");
230 std::vector<std::string> modules;
231 auto config = readRootMember(
vm,
"config");
232 if (!config || !config.value().isObject()) {
233 if (config) config.ignore();
237 appendStringArrayField(*
object,
"modules", &modules);
238 appendStringArrayField(*
object,
"optionalModules", &modules);
240 return uniqueSorted(std::move(modules));
244 std::vector<std::string>
live;
247 const SQInteger
top = sq_gettop(
vm);
248 sq_pushroottable(
vm);
249 sq_pushstring(
vm, _SC(
"eve"), -1);
250 if (SQ_FAILED(sq_get(
vm, -2)) || sq_gettype(
vm, -1) != OT_TABLE) {
254 sq_pushstring(
vm, _SC(
"moduleList"), -1);
255 if (SQ_FAILED(sq_get(
vm, -2)) || sq_gettype(
vm, -1) != OT_ARRAY) {
260 const SQInteger
count = sq_getsize(
vm, -1);
263 if (SQ_FAILED(sq_get(
vm, -2)) || sq_gettype(
vm, -1) != OT_TABLE) {
264 if (sq_gettop(
vm) >
top + 3) sq_poptop(
vm);
267 sq_pushstring(
vm, _SC(
"slot"), -1);
268 std::string slotName;
269 if (SQ_SUCCEEDED(sq_get(
vm, -2))) {
270 if (sq_gettype(
vm, -1) == OT_STRING) {
271 const SQChar*
slot =
nullptr;
272 sq_getstring(
vm, -1, &
slot);
280 if (slotName.empty())
continue;
282 sq_pushroottable(
vm);
283 sq_pushstring(
vm, slotName.c_str(), -1);
284 const bool present = SQ_SUCCEEDED(sq_get(
vm, -2)) && sq_gettype(
vm, -1) == OT_INSTANCE;
285 sq_settop(
vm,
top + 3);
289 return uniqueSorted(std::move(
live));
299 eve::cap::forEach<IGameplayControlProvider>([&](
auto* candidate) {
300 if (candidate)
input.domains.emplace_back(candidate->gameplayDomain());
304 std::filesystem::path
root =
input.gameRoot;
307 root = std::filesystem::current_path(ec);
310 const auto path =
root /
"game.agent.json";
312 if (std::filesystem::is_regular_file(
path, ec)) {
313 std::ifstream in(
path, std::ios::binary);
315 std::ostringstream contents;
316 contents << in.rdbuf();
318 if (parsed && parsed.value().isObject()) {
319 input.contractLoaded =
true;
321 const auto id =
object->find(
"id");
322 if (
id !=
object->end() &&
id->second.isString())
input.contractId =
id->second.asString();
std::vector< std::unique_ptr< ScriptClimbingEventSink > > live
struct SQVM * HSQUIRRELVM
Runtime game-world Discover snapshot for MCP / Play Host.
Host-neutral player-equivalent command and observation protocol.
std::set< std::string > values
const SquirrelValueOptions & options
The single Squirrel projection for common Result, Status and Value.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
The canonical owning dynamic value used by data-facing protocols.
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
std::map< std::string, Value > Object
std::vector< Value > Array
static Debugger & instance()
const std::string & gameRoot() const
static McpServer & instance()
Value stringArray(const std::vector< std::string > &values)
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
std::vector< std::string > readConfiguredModules(HSQUIRRELVM vm)
Read config.modules / optionalModules from the attached VM root.
Result< Value > buildGameWorldSnapshot(const GameWorldSnapshotInput &input)
Assemble runtime world brief plus live system lists.
constexpr std::int64_t kGameWorldSchemaVersion
Schema version for the game-world snapshot.
constexpr std::string_view kGameWorldSchemaId
Schema id for the game-world snapshot returned to agents.
std::string readConfigTitle(HSQUIRRELVM vm)
Read config.title from the attached VM root.
Result< Value > liveGameWorldSnapshot()
Build the Discover snapshot against the live engine.
void clearWorldContext()
Drop the runtime world brief (soft restart with script reload).
std::vector< std::string > readLiveModules(HSQUIRRELVM vm)
List instantiated module slots declared in eve.moduleList.
Result< Value > parseWorldObject(const Value &world)
Validate one runtime-published world object.
const Value * runtimeWorldContext() noexcept
Current runtime brief, or null when none is published. @ownership Borrowed; valid until the next publ...
Result< void > publishWorldContext(Value world)
Replace the runtime world brief published by the live game script.
bool hasWorldContext() noexcept
Whether a runtime brief is currently published.
Result< Value > valueFromSquirrel(HSQUIRRELVM vm, SQInteger index, const SquirrelValueOptions &options)
Convert one Squirrel value into the canonical owning Value tree.
enum EVENGINE_API_FOUNDATION Array
OT_ARRAY (editable via Runtime array APIs / ReflectedPropertyModel).