| 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"] |
DAP Protocol Guide for AIDB
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.
Overview
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:
- Complete data flow diagrams
- DAP client layer details
- Integration with adapters and session management
Key Principles
- Always use existing protocol types - Don't create dictionaries manually
- Follow established patterns - Check adapter implementations before creating new request sequences
- Handle errors properly - DAP has specific error response patterns
- Respect initialization sequence - Initialize → Launch/Attach → ConfigurationDone
- Consider language differences - Python, JavaScript, and Java adapters have different behaviors
Authoritative Source
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 classes
responses.py - All response message classes
events.py - All event message classes
bodies.py - Request arguments and response bodies
base.py - Base classes (Request, Response, Event, ProtocolMessage)
Quick Reference
Common DAP Operations
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,
)
seq = await client.get_next_seq()
request = SetBreakpointsRequest(
seq=seq,
arguments=SetBreakpointsArguments(
source=Source(path="/path/to/file.py"),
breakpoints=[
SourceBreakpoint(line=10, condition="x > 5")
]
)
)
response = await client.send_request(request)
Client Constants
Always use constants from src/aidb/dap/client/constants.py:
from aidb.dap.client.constants import (
CommandType,
EventType,
StopReason,
)
if event.event == EventType.STOPPED.value:
pass
if stopped_body.reason == StopReason.BREAKPOINT.value:
pass
Protocol Flow Overview
Standard Initialization Sequence
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]
Introspection Flow
← 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)
Execution Control
Client → Continue/Next/StepIn/StepOut Request
← Response (acknowledgement)
← Stopped Event (when execution stops again)
Resource Files
This skill is organized into focused resource files, each under 500 lines:
Core Protocol Operations
Patterns & Best Practices
Language-Specific Differences
Python (debugpy)
- Uses
launch or attach request types
justMyCode controls whether to step into library code
- Variable inspection is straightforward
- Stack frames include Python-specific metadata
- Supports
showReturnValue option
JavaScript/TypeScript (vscode-js-debug)
- Uses child sessions for subprocess debugging
- Source maps for TypeScript
- Async stack traces supported
console option controls console API redirection
- Runtime executable can be node, npm, yarn, pnpm
Java (java-debug-server)
- Requires classpath or module path configuration
- May use Eclipse JDT LS for code intelligence
- Main class specification required
- Can auto-compile .java files
- Supports JVM arguments (vmargs)
Code Reuse Checklist
Before writing new DAP code, check these locations:
-
Protocol Types: src/aidb/dap/protocol/types.py
- Breakpoint, StackFrame, Variable, Source, Thread, Scope, etc.
-
Request/Response Classes: src/aidb/dap/protocol/requests.py, responses.py
- All request and response types fully typed
-
Event Classes: src/aidb/dap/protocol/events.py
- StoppedEvent, ThreadEvent, BreakpointEvent, etc.
-
Client Constants: src/aidb/dap/client/constants.py
- CommandType, EventType, StopReason enums
-
Adapter Implementations:
- Python:
src/aidb/adapters/lang/python/python.py
- JavaScript:
src/aidb/adapters/lang/javascript/javascript.py
- Java:
src/aidb/adapters/lang/java/java.py
-
Session Management: src/aidb/session/
- connector.py - Connection sequences
- session_breakpoints.py - Breakpoint management
- child_manager.py - Child session patterns
Common Pitfalls
1. Wrong Sequence Number
request = InitializeRequest(seq=1, arguments=args)
seq = await client.get_next_seq()
request = InitializeRequest(seq=seq, arguments=args)
2. Missing Required Fields
breakpoint = SourceBreakpoint(line=10)
from aidb.dap.protocol.types import SourceBreakpoint
breakpoint = SourceBreakpoint(line=10)
3. Ignoring Initialization Sequence
await client.connect()
await client.send_request(LaunchRequest(...))
await client.connect()
await client.send_request(InitializeRequest(...))
await client.send_request(SetBreakpointsRequest(...))
await client.send_request(ConfigurationDoneRequest(...))
await client.send_request(LaunchRequest(...))
4. Not Handling Language Differences
launch_config = {"program": "/path/to/file"}
from aidb_common.constants import Language
if language == Language.PYTHON:
launch_config = adapter.get_launch_configuration()
elif language == Language.JAVASCRIPT:
launch_config = adapter.get_launch_configuration()
elif language == Language.JAVA:
launch_config = adapter.get_launch_configuration()
5. Creating Dictionaries Instead of Using Protocol Types
source = {"path": "/path/to/file.py"}
from aidb.dap.protocol.types import Source
source = Source(path="/path/to/file.py")
When to Use This Skill
Invoke this skill ONLY when working directly with:
- DAP Protocol Types - Creating/modifying protocol message classes in
src/aidb/dap/protocol/
- DAP Client - Implementing DAP client message handling in
src/aidb/dap/client/
- Protocol Specification - Understanding DAP spec, message flows, sequence numbers
- Protocol-Level Debugging - Issues with DAP message encoding/decoding/parsing
DO NOT use for:
- Adapter implementation (use
adapter-development skill instead)
- Breakpoint logic in adapters (use
adapter-development skill)
- Session management (use
adapter-development skill)
- General debugging questions (use
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.
Related Skills
When working with DAP protocol, you may also need:
- adapter-development - Adapters implement language-specific DAP patterns
- mcp-tools-development - MCP tools use DAP types for all debugging operations
- testing-strategy - Framework tests validate DAP flows end-to-end
Related Documentation
Internal Documentation:
- Architecture:
docs/developer-guide/overview.md - Overall system architecture with DAP layer details
- Adapter Base:
src/aidb/adapters/base/ - Base adapter classes
- Session Management:
src/aidb/session/ - Session lifecycle
- Testing:
src/tests/aidb/ - Example usage patterns
External References:
Verifying This Skill
To verify the code examples in this skill are current and accurate, check these files:
- Protocol definitions:
src/aidb/dap/protocol/ - Authoritative source for all types
- Client implementation:
src/aidb/dap/client/client.py - Client methods and signatures
- Real initialization flows:
src/aidb/session/connector.py - Production initialization sequences
- Real breakpoint handling:
src/aidb/session/session_breakpoints.py - Production breakpoint patterns
- Framework tests: Working examples of complete flows:
- Python:
src/tests/frameworks/python/pytest/e2e/test_pytest_debugging.py
- JavaScript:
src/tests/frameworks/javascript/jest/e2e/test_jest_debugging.py
- Java:
src/tests/frameworks/java/junit/e2e/test_junit_debugging.py
Example: Complete Debugging Flow
Note: 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,
)
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,
)
)
)
await client.wait_for_event("initialized")
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)]
)
)
)
seq = await client.get_next_seq()
await client.send_request(ConfigurationDoneRequest(seq=seq))
seq = await client.get_next_seq()
launch_response = await client.send_request(
LaunchRequest(seq=seq, arguments=launch_args)
)
await client.wait_for_event(EventType.STOPPED.value)
thread_id = client.state.current_thread_id
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
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
seq = await client.get_next_seq()
vars_response = await client.send_request(
VariablesRequest(
seq=seq,
arguments=VariablesArguments(variablesReference=vars_ref)
)
)
seq = await client.get_next_seq()
await client.send_request(
ContinueRequest(
seq=seq,
arguments=ContinueArguments(threadId=thread_id)
)
)
Summary
This skill provides comprehensive DAP protocol guidance for AIDB development. Always:
- Use protocol types from
src/aidb/dap/protocol/
- Check adapter implementations for patterns
- Follow initialization sequences
- Handle language-specific differences
- Use constants from
client/constants.py
- Refer to resource files for detailed guidance
For deep dives into specific operations, see the resource files listed above.