[PR #6659] feat(debug): add debug tools for instrumentation and log analysis #12022

Closed
opened 2026-02-16 18:16:57 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6659

State: closed
Merged: No


my attempt at making a debug tool similar to cursors new debug tool

  • Introduced DebugInstrumentTool for adding logging to code.
  • Added DebugWatchTool for collecting and aggregating logs.
  • Implemented DebugCleanupTool to remove instrumentation after debugging.
  • Created DebugServer to manage debug sessions and log entries.
  • Added debug logging capabilities to the agent and server.
  • Included a new debug prompt for guiding users through the debugging process.
  • Updated tool registry to include new debug tools.

The Problem: When something breaks in the browser (UI bugs, API issues, state problems), the AI can't see what's happening at runtime. It can only read static code. The Solution: Inject logging code that sends runtime data back to opencode.

  1. AI calls debug_instrument
  2. Tool returns a snippet (logging functions)
  3. AI uses Edit to add snippet to your file
  4. AI adds __oc_log() calls in key spots (useEffect, handlers, etc.)
  5. You run your app and reproduce the bug
  6. Browser code sends logs → localhost:4096 → opencode server
  7. AI calls debug_watch to collect logs
  8. Server returns AGGREGATED SUMMARY
  9. AI analyzes summary to find the actual issue
  10. AI calls debug_cleanup to remove instrumentation

what the ai sees after:
=== Debug Summary (156 logs over 8.2s) ===

  • "POST /api/chat" status: 200 → 500, ms: 45 → 890
  • "FloatingChatbot" count: 1 → 47
  • "Cannot read property 'scroll' of null"
    Instead of guessing, the AI now has actual runtime data to debug with.
image
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6659 **State:** closed **Merged:** No --- my attempt at making a debug tool similar to cursors new debug tool - Introduced DebugInstrumentTool for adding logging to code. - Added DebugWatchTool for collecting and aggregating logs. - Implemented DebugCleanupTool to remove instrumentation after debugging. - Created DebugServer to manage debug sessions and log entries. - Added debug logging capabilities to the agent and server. - Included a new debug prompt for guiding users through the debugging process. - Updated tool registry to include new debug tools. The Problem: When something breaks in the browser (UI bugs, API issues, state problems), the AI can't see what's happening at runtime. It can only read static code. The Solution: Inject logging code that sends runtime data back to opencode. 1. AI calls debug_instrument ↓ 2. Tool returns a snippet (logging functions) ↓ 3. AI uses Edit to add snippet to your file ↓ 4. AI adds __oc_log() calls in key spots (useEffect, handlers, etc.) ↓ 5. You run your app and reproduce the bug ↓ 6. Browser code sends logs → localhost:4096 → opencode server ↓ 7. AI calls debug_watch to collect logs ↓ 8. Server returns AGGREGATED SUMMARY ↓ 9. AI analyzes summary to find the actual issue ↓ 10. AI calls debug_cleanup to remove instrumentation what the ai sees after: === Debug Summary (156 logs over 8.2s) === [NET]: 12x - "POST /api/chat" status: 200 → 500, ms: 45 → 890 [RENDER]: 47x - "FloatingChatbot" count: 1 → 47 [ERROR]: 1x - "Cannot read property 'scroll' of null" Instead of guessing, the AI now has actual runtime data to debug with. <img width="770" height="858" alt="image" src="https://github.com/user-attachments/assets/6414ef08-79fd-4da0-812f-ffb6ae5212d2" />
yindo added the pull-request label 2026-02-16 18:16:57 -05:00
yindo closed this issue 2026-02-16 18:16:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12022