feat(core): Debug mode
What does this PR do?
PR Summary: Debug Mode Feature
This PR introduces a new Debug Agent Mode that enables evidence-based debugging through structured instrumentation, log analysis, and a guided reproduction workflow.
HEAVILY INSPIRED FROM CURSOR DEBUG MODE
Overview
- Adds a dedicated debug agent mode alongside existing modes (e.g. build, explore)
- Enforces a disciplined, multi-phase debugging workflow
- Introduces infrastructure for structured debug logs and reproduction steps
- Integrates debugging flows into the API, UI, and SDK
Key Features
1. New Debug Agent Mode
- Adds a new
debugagent mode - Description: “Evidence-based debugging mode. Use this to generate hypotheses, add runtime instrumentation, analyze logs, and only then implement fixes.”
2. Structured Debug Workflow
The debug prompt (packages/opencode/src/agent/prompt/debug.txt) defines a 7-phase workflow:
- Generate testable hypotheses
- Add instrumentation logs (3–8 logs)
- Reproduce the issue with log clearing
- Analyze logs (NDJSON format)
- Implement fixes (only with supporting evidence)
- Verify with before/after comparison
- Cleanup after confirmation
3. Debug Infrastructure
-
Debug module (
src/debug/index.ts)- Log ingestion
- Config injection
- File management
-
Debug config injection
- Automatically injects a
<debug_config>block into system prompts when using the debug agent
- Automatically injects a
-
Log format
-
NDJSON (one JSON object per line)
-
Required fields:
-
sessionId -
runId -
hypothesisId -
location -
message -
data -
timestamp
-
-
4. Reproduction Steps System
-
New reproduction steps request/response system (
src/debug/repro.ts) -
TUI component (
reproduction-steps.tsx) for user interaction -
Supported actions:
-
proceed -
fixed -
skipped
-
-
Integrated into the session UI with keyboard navigation
5. API Endpoints
-
POST /ingest/:sessionIdIngest debug logs and append them to.opencode/debug.log -
GET /reproduction-stepsList pending reproduction requests -
POST /reproduction-steps/:requestID/replyReply to a reproduction prompt -
POST /reproduction-steps/:requestID/rejectReject a reproduction prompt
6. UI Integration
- Reproduction steps prompt component with visual indicators
- Integrated into the session view with proper priority (shown after permissions and questions)
- Keyboard shortcuts for navigation and confirmation
7. SDK Updates
-
Regenerated JavaScript SDK to include new endpoints
-
Added:
-
Debugclient -
ReproductionStepsclient
-
-
Updated type definitions for all new APIs
8. Testing
- Debug ingestion tests (
debug-ingest.test.ts) - System prompt injection tests (
debug-system-injection.test.ts) - Reproduction steps route tests (
reproduction-steps.test.ts)
Technical Details
- Logs are written to
.opencode/debug.login the worktree root - Instrumentation uses HTTP
POSTrequests to the ingest endpoint (no direct file writes) - Debug logs are isolated per session
- Error handling ensures logging failures do not break the application
How did you verify your code works?
https://github.com/user-attachments/assets/241d9628-ad32-48e8-9e49-a8e44cf9333b
Hey! Your PR title Feat(core): Debug mode doesn't follow conventional commit format.
Please update it to start with one of:
-
feat:orfeat(scope):new feature -
fix:orfix(scope):bug fix -
docs:ordocs(scope):documentation changes -
chore:orchore(scope):maintenance tasks -
refactor:orrefactor(scope):code refactoring -
test:ortest(scope):adding or updating tests
Where scope is the package name (e.g., app, desktop, opencode).
See CONTRIBUTING.md for details.
The following comment was made by an LLM, it may be inaccurate:
No duplicate PRs found
Thanks for your contribution!
This PR doesn't have a linked issue. All PRs must reference an existing issue.
Please:
- Open an issue describing the bug/feature (if one doesn't exist)
- Add
Fixes #<number>orCloses #<number>to this PR description
See CONTRIBUTING.md for details.