Replies: 3 comments 1 reply
-
|
Though this seems interesting, I don't want to talk with an AI in this discussion forum |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Inspired by playright and chrome debugger protocol, I make claude to write a demo in ebiten, maybe it worth a try? |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
had you considered using functional options instead of a struct? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
RFC: Ebitengine Debug Protocol (EDP) — Engine Observability for AI Agents
Summary
This proposal introduces the Ebitengine Debug Protocol (EDP), a built-in HTTP JSON API that exposes engine runtime state to external tools. The primary motivation is to enable AI coding agents (e.g., LLM-based copilots) to observe and verify the correctness of game code they generate — effectively giving AI "eyes" into a running Ebitengine game.
Motivation
The Problem
AI coding assistants are increasingly capable of generating game code, but they face a fundamental limitation: they cannot see the result. After generating Ebitengine code, an AI agent can verify that the code compiles, but has no way to answer:
This is analogous to a blind programmer writing UI code — the compiler says it's fine, but the visual result is entirely unknown.
The Opportunity
Ebitengine's architecture is uniquely well-suited for this kind of observability:
Gameinterface is a natural interception point —Update()/Draw()/Layout()can be wrapped without modifying user code.net/httpand goroutines make it trivial to run an HTTP server alongside the game loop with zero external dependencies.internal/debug,imageDumper,DebugInfo, andebitenutil.DebugPrintshow that the engine already values debuggability.Prior Art
No existing game engine provides a debug protocol specifically designed for AI agent consumption. EDP would be the first.
Design
Architecture: Two-Layer Observability
EDP operates at two layers to provide comprehensive coverage:
User-layer (
exp/debug/wrapper.go): Wraps theGameinterface. Detects issues in user game logic — wrong rendering, broken input handling, etc.Engine-layer (
internal/debugger): Instruments engine internals. Detects issues in the engine itself — frame scheduling anomalies, draw call explosion, command merging failures, etc.Protocol Design
EDP uses HTTP JSON (no external dependencies). Two access patterns are supported:
curl-friendly access for quick queries/debug/rpc) — Structured access for programmatic useProtocol Domains
getState,setTPS,pause,resumegetStategetState,simulateKeygetFrameStats,getRecentFrames,getCumulativeStatsGET /debug/screenshotExample Interactions
User-Facing API
Enabling EDP requires one line of code and zero configuration:
Zero-Cost When Disabled
internal/debuggercollector checksenabled.Load()(atomic bool) at the top of every recording function. When disabled, the overhead is a single atomic load per call — effectively zero.exp/debugpackage is opt-in. If not imported, no HTTP server is started and noGamewrapping occurs.Implementation
New Files
exp/debug/server.goexp/debug/domains.goexp/debug/wrapper.goGameWrapperthat wrapsGameinterface for user-layer observationexp/debug/image.goimage.Imagefor PNG encodinginternal/debugger/debugger.goModified Files
internal/ui/context.godebugger.BeginFrame/EndFrameinupdateFrame, Update/Draw timing inupdateFrameImplinternal/graphicscommand/commandqueue.godebugger.RecordDrawCall/RecordMergedDrawCall/RecordVerticesAndIndicesinEnqueueDrawTrianglesCommandKey Design Decisions
HTTP instead of WebSocket for MVP: Simpler, works with
curl, no external dependencies. WebSocket can be added later for event push (e.g., real-time FPS streaming).exp/debugpackage location: Placed underexp/to signal experimental status, consistent withexp/textinput.internal/debuggervs extendinginternal/debug: Created a separate package to avoid conflating compile-time debug logging (internal/debug, gated by build tags) with runtime statistics collection (internal/debugger, gated by atomic bool).Screenshot via channel synchronization:
ReadPixelsmust be called from the Draw goroutine. The wrapper uses an atomic flag + channel to request a screenshot from the HTTP handler and wait for the Draw goroutine to fulfill it.Ring buffer for frame history: Fixed-size (120 frames ≈ 2 seconds at 60 FPS) to bound memory usage while providing enough history for trend analysis.
Future Work
The following features are intentionally deferred from the MVP but are natural extensions:
Near-Term
audio.Playerstate (playing, position, volume) via a registered player registryLong-Term
Compatibility
net/http,encoding/json,image/png).ebitenginedebugbuild tag.Open Questions
Package location: Should this live under
exp/debugor directly underdebug? Theexp/prefix signals instability but may discourage adoption.Default port: 9222 is chosen as a nod to Chrome DevTools Protocol. Is there a risk of conflict?
Security: The HTTP server binds to all interfaces by default. Should it default to
localhostonly? Should there be an authentication mechanism?Performance budget: The atomic bool check adds ~1ns per instrumentation point. Is this acceptable for the engine's performance goals, even when EDP is not enabled?
internal/debuggernaming: The namedebuggermay conflict with Go'sruntime/debugin developer mental models. Alternatives:internal/edp,internal/enginestats,internal/observe.References
Beta Was this translation helpful? Give feedback.
All reactions