// Comprehensive guide for working with Debug Adapter Protocol in AIDB
| name | dap-protocol-guide |
| description | Comprehensive guide for working with Debug Adapter Protocol in AIDB |
| version | 1.0.0 |
| tags | ["dap","protocol","debugging","requests","responses"] |
This skill provides comprehensive guidance for working with the Debug Adapter Protocol (DAP) in AIDB. Use this when implementing features that interact with debug adapters, analyzing DAP message flows, or troubleshooting protocol-level issues.
The Debug Adapter Protocol (DAP) is a standardized protocol for communication between development tools and debug adapters. AIDB provides a fully-typed, authoritative implementation in src/aidb/dap/protocol/.
For system-wide DAP architecture, see docs/developer-guide/overview.md which includes:
src/aidb/dap/protocol/ is THE authoritative reference for all DAP types and messages.
This package contains:
types.py - DAP data types (Breakpoint, StackFrame, Variable, etc.)requests.py - All request message classesresponses.py - All response message classesevents.py - All event message classesbodies.py - Request arguments and response bodiesbase.py - Base classes (Request, Response, Event, ProtocolMessage)# Import protocol types
from aidb.dap.protocol import (
InitializeRequest,
LaunchRequest,
SetBreakpointsRequest,
StackTraceRequest,
ScopesRequest,
VariablesRequest,
ContinueRequest,
)
from aidb.dap.protocol.types import Source, SourceBreakpoint
from aidb.dap.protocol.bodies import (
InitializeRequestArguments,
LaunchRequestArguments,
SetBreakpointsArguments,
StackTraceArguments,
)
# Get next sequence number
seq = await client.get_next_seq()
# Build a request
request = SetBreakpointsRequest(
seq=seq,
arguments=SetBreakpointsArguments(
source=Source(path="/path/to/file.py"),
breakpoints=[
SourceBreakpoint(line=10, condition="x > 5")
]
)
)
# Send request and await response
response = await client.send_request(request)
Always use constants from src/aidb/dap/client/constants.py:
from aidb.dap.client.constants import (
CommandType,
EventType,
StopReason,
)
# Check event type
if event.event == EventType.STOPPED.value:
# Handle stopped event
pass
# Check stop reason
if stopped_body.reason == StopReason.BREAKPOINT.value:
# Handle breakpoint
pass
Client โ Initialize Request
โ Initialize Response (capabilities)
โ Initialized Event
Client โ SetBreakpoints (optional, multiple)
Client โ SetExceptionBreakpoints (optional)
Client โ ConfigurationDone Request
โ ConfigurationDone Response
Client โ Launch/Attach Request
โ Launch/Attach Response
[Debug session active]
โ Stopped Event
Client โ Threads Request
โ Threads Response
Client โ StackTrace Request (threadId)
โ StackTrace Response (stackFrames)
Client โ Scopes Request (frameId)
โ Scopes Response (scopes)
Client โ Variables Request (variablesReference)
โ Variables Response (variables)
Client โ Continue/Next/StepIn/StepOut Request
โ Response (acknowledgement)
โ Stopped Event (when execution stops again)
This skill is organized into focused resource files, each under 500 lines:
launch or attach request typesjustMyCode controls whether to step into library codeshowReturnValue optionconsole option controls console API redirectionBefore writing new DAP code, check these locations:
Protocol Types: src/aidb/dap/protocol/types.py
Request/Response Classes: src/aidb/dap/protocol/requests.py, responses.py
Event Classes: src/aidb/dap/protocol/events.py
Client Constants: src/aidb/dap/client/constants.py
Adapter Implementations:
src/aidb/adapters/lang/python/python.pysrc/aidb/adapters/lang/javascript/javascript.pysrc/aidb/adapters/lang/java/java.pySession Management: src/aidb/session/
# โ Bad: reusing or hardcoding seq
request = InitializeRequest(seq=1, arguments=args)
# โ
Good: always get fresh seq
seq = await client.get_next_seq()
request = InitializeRequest(seq=seq, arguments=args)
# โ Bad: missing required fields
breakpoint = SourceBreakpoint(line=10) # Error if other required fields
# โ
Good: use protocol types correctly
from aidb.dap.protocol.types import SourceBreakpoint
breakpoint = SourceBreakpoint(line=10) # All defaults handled
# โ Bad: launching before configuration
await client.connect()
await client.send_request(LaunchRequest(...)) # Will fail
# โ
Good: follow proper sequence
await client.connect()
await client.send_request(InitializeRequest(...))
# Wait for initialized event
await client.send_request(SetBreakpointsRequest(...))
await client.send_request(ConfigurationDoneRequest(...))
await client.send_request(LaunchRequest(...))
# โ Bad: assuming all adapters work the same
launch_config = {"program": "/path/to/file"}
# โ
Good: use language-specific configuration
# Note: Launch arguments are implementation-specific dicts, not typed objects
# Adapters provide get_launch_configuration() that returns language-specific config
from aidb_common.constants import Language
if language == Language.PYTHON:
# Python adapter provides debugpy-specific configuration
launch_config = adapter.get_launch_configuration()
# Typically includes: program, justMyCode, console, etc.
elif language == Language.JAVASCRIPT:
# JavaScript adapter provides vscode-js-debug configuration
launch_config = adapter.get_launch_configuration()
# Typically includes: program, runtimeExecutable, console, etc.
elif language == Language.JAVA:
# Java adapter provides java-debug-server configuration
launch_config = adapter.get_launch_configuration()
# Typically includes: mainClass, classpath, vmArgs, etc.
# โ Bad: manual dictionary construction
source = {"path": "/path/to/file.py"} # Type unsafe, error prone
# โ
Good: use protocol types
from aidb.dap.protocol.types import Source
source = Source(path="/path/to/file.py") # Type safe, IDE support
Invoke this skill ONLY when working directly with:
src/aidb/dap/protocol/src/aidb/dap/client/DO NOT use for:
adapter-development skill instead)adapter-development skill)adapter-development skill)adapter-development skill)Rule of thumb: If you're working in src/aidb/dap/protocol/ or src/aidb/dap/client/, use this skill. Otherwise, use adapter-development.
When working with DAP protocol, you may also need:
Internal Documentation:
docs/developer-guide/overview.md - Overall system architecture with DAP layer detailssrc/aidb/adapters/base/ - Base adapter classessrc/aidb/session/ - Session lifecyclesrc/tests/aidb/ - Example usage patternsExternal References:
To verify the code examples in this skill are current and accurate, check these files:
src/aidb/dap/protocol/ - Authoritative source for all typessrc/aidb/dap/client/client.py - Client methods and signaturessrc/aidb/session/connector.py - Production initialization sequencessrc/aidb/session/session_breakpoints.py - Production breakpoint patternssrc/tests/frameworks/python/pytest/e2e/test_pytest_debugging.pysrc/tests/frameworks/javascript/jest/e2e/test_jest_debugging.pysrc/tests/frameworks/java/junit/e2e/test_junit_debugging.pyNote: This is a conceptual example showing the typical request sequence. For working examples, see the framework tests listed in "Verifying This Skill" above.
from aidb.dap.protocol import (
InitializeRequest,
LaunchRequest,
SetBreakpointsRequest,
ConfigurationDoneRequest,
ContinueRequest,
StackTraceRequest,
ScopesRequest,
VariablesRequest,
)
from aidb.dap.protocol.types import Source, SourceBreakpoint
from aidb.dap.protocol.bodies import (
InitializeRequestArguments,
SetBreakpointsArguments,
StackTraceArguments,
ScopesArguments,
VariablesArguments,
ContinueArguments,
)
# 1. Initialize
seq = await client.get_next_seq()
init_response = await client.send_request(
InitializeRequest(
seq=seq,
arguments=InitializeRequestArguments(
clientID="aidb",
adapterID="python",
linesStartAt1=True,
columnsStartAt1=True,
)
)
)
# 2. Wait for initialized event
await client.wait_for_event("initialized")
# 3. Set breakpoints
seq = await client.get_next_seq()
bp_response = await client.send_request(
SetBreakpointsRequest(
seq=seq,
arguments=SetBreakpointsArguments(
source=Source(path="/path/to/file.py"),
breakpoints=[SourceBreakpoint(line=10)]
)
)
)
# 4. Configuration done
seq = await client.get_next_seq()
await client.send_request(ConfigurationDoneRequest(seq=seq))
# 5. Launch
seq = await client.get_next_seq()
launch_response = await client.send_request(
LaunchRequest(seq=seq, arguments=launch_args)
)
# 6. Wait for stopped event
await client.wait_for_event(EventType.STOPPED.value)
thread_id = client.state.current_thread_id
# 7. Get stack trace
seq = await client.get_next_seq()
stack_response = await client.send_request(
StackTraceRequest(
seq=seq,
arguments=StackTraceArguments(threadId=thread_id)
)
)
frame_id = stack_response.body.stackFrames[0].id
# 8. Get scopes
seq = await client.get_next_seq()
scopes_response = await client.send_request(
ScopesRequest(
seq=seq,
arguments=ScopesArguments(frameId=frame_id)
)
)
vars_ref = scopes_response.body.scopes[0].variablesReference
# 9. Get variables
seq = await client.get_next_seq()
vars_response = await client.send_request(
VariablesRequest(
seq=seq,
arguments=VariablesArguments(variablesReference=vars_ref)
)
)
# 10. Continue execution
seq = await client.get_next_seq()
await client.send_request(
ContinueRequest(
seq=seq,
arguments=ContinueArguments(threadId=thread_id)
)
)
This skill provides comprehensive DAP protocol guidance for AIDB development. Always:
src/aidb/dap/protocol/client/constants.pyFor deep dives into specific operations, see the resource files listed above.