docs/waves/engine_debug_connector_plan.md
Engine Debug Connector Plan
Status: planning-ready
Owner lane: engine-wasm + browser
Related reference:
docs/waves/ENGINE_DEBUG_CONNECTOR_RESEARCH.md
Purpose
Define an attachable debug connector for the running WML engine so a host-integrated debugger or external tool can observe runtime state and event flow without mutating core engine behavior.
This is a diagnostics surface, not a transport/runtime control plane.
Goals
- Provide a deterministic, structured event stream from engine runtime boundaries.
- Support attach/detach and cursor-based event polling from host or external tooling.
- Expose a stable debug snapshot surface for state inspection and replay triage.
- Preserve strict layer boundaries:
- engine runtime emits events and snapshots
- host brokers access and IPC
- debugger UI/tool remains out-of-process from engine runtime logic
Non-Goals (MVP)
- Remote code execution/control over engine internals.
- Live mutation commands that bypass normal host input/navigation APIs.
- Production telemetry pipeline replacement.
- Protocol/network introspection beyond existing host/transport logs.
Boundary and Ownership
engine-wasm/engine:
- event emission points
- in-memory ring buffer
- snapshot generation
- redaction markers for sensitive fields
engine-wasm/contracts/wml-engine.ts:
- canonical debug contract types
- additive APIs only
browser/src-tauriandbrowser/contracts/*:
- command bridge for open/poll/close
- debugger consumer compatibility
browser/frontend:
- optional first-party debug panel consumer
Proposed Debug Contract Surface (Additive)
openDebugSession(options) -> { sessionId, cursor }
pollDebugEvents({ sessionId, cursor, maxEvents }) -> { events, nextCursor, droppedCount }
getDebugSnapshot({ sessionId }) -> EngineDebugSnapshot
closeDebugSession({ sessionId }) -> { closed: boolean }
MVP posture is read-only.
Event Model (MVP)
All events should include:
seq(monotonic per engine process)kind(stable string enum)tsMs(runtime monotonic timestamp)cardId(optional)payload(small typed object)
Initial event kinds:
deck.loadcard.entercard.exitfocus.changeinput.edit.startinput.edit.draftinput.edit.commitinput.edit.cancelaction.acceptaction.externalnav.intentpostfield.resolvescript.invokescript.traptimer.scheduletimer.firetimer.cancel
Snapshot Model (MVP)
EngineDebugSnapshot should include:
- active card id
- focused link index
- focused input edit name/value (redacted policy applied)
- runtime vars (redacted policy applied)
- pending external navigation intent/request policy
- timer state summary
- trace cursor metadata (
oldestSeq,latestSeq,droppedCount)
Safety and Redaction
- Debug connector disabled by default outside development profiles.
- Sensitive fields (for example
pin, password inputs) masked unless explicit local override is enabled. - Events must not expose raw transport credentials or secrets.
- Session handles are process-local and non-persistent.
Performance Constraints
- Fixed-size ring buffer with drop-oldest semantics.
- No blocking I/O in engine event emission path.
- Event payloads must remain compact and deterministic.
- Debug path must be additive and must not alter runtime ordering or navigation semantics.
Rollout Phases
- Phase D0-01: contract and architecture definition.
- Phase D0-02: engine ring buffer + event/snapshot emission.
- Phase D0-03: tauri host bridge + contract generation wiring.
- Phase D0-04: first-party consumer panel and capture/export workflow.
Acceptance Criteria (Program)
- A running host can attach and poll events without runtime behavior change.
- Event stream captures input/edit/submit boundaries needed for form-debug triage.
- Snapshot + event cursor supports deterministic bug replay investigation.
- Sensitive values are masked by default and policy-tested.
Open Questions
- Should event timestamps be monotonic only, or include wall-clock projection?
- Should session model support multiple concurrent consumers in MVP?
- What is the default ring-buffer size cap for dev mode vs CI mode?
- Should
postfield.resolveinclude resolution source (var|draft|card|fallback) for each field?