Forward-declare McpServer/AiPanel in DevTool.hpp, bridge MCP away from DevTool.hpp inside DebugAdapter's TU, emit tools/resources/prompts lists as static JSON (fewer Poco template exports), and drop the ImGuiBackend AI drawer that instantiated more imgui inlines under WINDOWS_EXPORT_ALL_SYMBOLS. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com>
121 lines
4.2 KiB
C++
121 lines
4.2 KiB
C++
#pragma once
|
|
|
|
#include "common/Export.h"
|
|
#include "devtools/CallGraph.hpp"
|
|
#include "devtools/DebugAdapter.hpp"
|
|
#include "devtools/Debugger.hpp"
|
|
#include "devtools/RenderFlow.hpp"
|
|
#include "devtools/Snapshot.hpp"
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
struct SQVM;
|
|
typedef struct SQVM* HSQUIRRELVM;
|
|
|
|
namespace ssq {
|
|
class VM;
|
|
}
|
|
|
|
namespace eve::dev {
|
|
|
|
class McpServer;
|
|
class AiPanel;
|
|
|
|
/**
|
|
* Platform-level script + render debugger / dynamic slicer front-end.
|
|
*
|
|
* When attached (typically via `eve run --debug`):
|
|
* - Squirrel: debug hook → CallGraph (call stack + Def/Use data-flow)
|
|
* - Breakpoints / watches / pause-step via Debugger
|
|
* - Optional DAP TCP server for the VS Code eve-debug extension
|
|
* - Optional MCP TCP server for AI agents (tools/resources/prompts)
|
|
* - Script-state Snapshot (engine treated as stateless)
|
|
* - Render: installs RenderFlow as eve::debug::IRenderTracer
|
|
* - on errors: Weiser-style backward slice for script and/or render pipeline
|
|
* - AI panel: session log + optional ImGui "AI / MCP" window
|
|
*
|
|
* Not shipped on Android/iOS trimmed runtimes (EVDevTools is desktop-only).
|
|
*/
|
|
class EVENGINE_API DevTool {
|
|
public:
|
|
static DevTool& instance();
|
|
|
|
DevTool(const DevTool&) = delete;
|
|
DevTool& operator=(const DevTool&) = delete;
|
|
|
|
/** Attach script tracer to VM and enable render tracing. */
|
|
void attach(ssq::VM& vm, bool sampleLocals = true);
|
|
void attach(HSQUIRRELVM vm, bool sampleLocals = true);
|
|
/** Enable render-flow tracing without a Squirrel VM (C++ / unit tests). */
|
|
void enableRenderTrace(bool on = true);
|
|
void detach();
|
|
|
|
/** Expose `eve.dev` script API (pause/breakpoint/watch/snapshot/AI). */
|
|
void exposeScriptApi(ssq::VM& vm);
|
|
|
|
/** Start DAP server; returns bound port (0 on failure). */
|
|
int startDap(uint16_t port);
|
|
void stopDap();
|
|
/** Start MCP server for AI tooling; returns bound port (0 on failure). */
|
|
int startMcp(uint16_t port);
|
|
void stopMcp();
|
|
void poll();
|
|
|
|
/** Draw DevTools AI ImGui panel when visible (call from UI/frame loop). */
|
|
void drawAiPanel();
|
|
|
|
bool isAttached() const { return vm_ != nullptr; }
|
|
bool renderTraceEnabled() const { return renderTraceEnabled_; }
|
|
bool sampleLocals() const { return sampleLocals_; }
|
|
void setSampleLocals(bool on) { sampleLocals_ = on; }
|
|
|
|
CallGraph& graph() { return graph_; }
|
|
const CallGraph& graph() const { return graph_; }
|
|
RenderFlow& renderFlow() { return renderFlow_; }
|
|
const RenderFlow& renderFlow() const { return renderFlow_; }
|
|
Debugger& debugger() { return Debugger::instance(); }
|
|
Snapshot& snapshot() { return Snapshot::instance(); }
|
|
DebugAdapter& dap() { return DebugAdapter::instance(); }
|
|
McpServer& mcp();
|
|
AiPanel& ai();
|
|
|
|
SliceResult analyzeError(const std::string& errorMessage,
|
|
const std::vector<std::string>& hintVars = {}) const;
|
|
|
|
std::string formatError(const std::string& errorMessage,
|
|
const std::vector<std::string>& hintVars = {}) const;
|
|
|
|
const std::string& lastReport() const { return lastReport_; }
|
|
|
|
/** Record an error; includes script slice and render-pipeline slice when enabled. */
|
|
std::string notifyError(const std::string& errorMessage,
|
|
const std::vector<std::string>& hintVars = {});
|
|
|
|
void handleDebugEvent(HSQUIRRELVM vm, int type, const char* source, int line,
|
|
const char* funcname);
|
|
|
|
private:
|
|
DevTool() = default;
|
|
|
|
void sampleFrameLocals(HSQUIRRELVM vm, const SourceLoc& loc);
|
|
void markErrorUses(const SourceLoc& loc, const std::vector<std::string>& hintVars);
|
|
void installRenderTracer();
|
|
void uninstallRenderTracer();
|
|
/** DAP poll + in-engine F5/F8/F10/F11 while blocked in a script pause. */
|
|
void pumpWhilePaused();
|
|
void handleDebugHotkey(const std::string& key);
|
|
|
|
HSQUIRRELVM vm_ = nullptr;
|
|
bool sampleLocals_ = true;
|
|
bool renderTraceEnabled_ = false;
|
|
CallGraph graph_;
|
|
RenderFlow renderFlow_;
|
|
std::string lastReport_;
|
|
|
|
std::unordered_map<int, std::unordered_map<std::string, std::string>> localSnap_;
|
|
};
|
|
|
|
} // namespace eve::dev
|