Problem Detection & Fixing
Relevant source files
The following files were used as context for generating this wiki page:
- src/ipc/handlers/problems_handlers.ts
- workers/tsc/tsc_worker.ts
- src/components/preview_panel/Problems.tsx
- src/components/chat/FixAllErrorsButton.tsx
- e2e-tests/problems.spec.ts
- src/components/chat/DyadProblemSummary.tsx
- src/tests/problem_prompt.test.ts
- src/prompts/system_prompt.ts
- e2e-tests/snapshots/problems.spec.ts_problems-auto-fix---enabled-2.txt
The Problem Detection & Fixing system is a core feature of Dyad designed to identify, report, and assist in resolving TypeScript compilation errors within the user's project. It leverages a background TypeScript worker to analyze the codebase and communicates findings to the UI. The system supports both an automated "Auto-fix" mode, where the AI proactively attempts to correct errors, and a manual mode, where the user can review and select specific problems to be fixed by the AI.
This system enhances developer productivity by catching errors in real-time and providing intelligent, automated solutions, reducing the time spent on debugging common coding issues. The entire process is integrated into the Dyad chat and preview panel interface for a seamless user experience.
Architecture Overview
The system is composed of three main parts: a background worker for detection, IPC handlers for communication, and several UI components for user interaction and display.
The following diagram illustrates the high-level data flow for problem detection and fixing.
Problem Detection
Problem detection is handled by a dedicated TypeScript worker. This approach prevents the main application thread from blocking while the codebase is being analyzed.
TypeScript Worker (tsc_worker.ts)
The tsc_worker.ts (whose existence is implied by tests and architecture) is responsible for running the TypeScript compiler over the project files to find diagnostics (errors).
- It listens for a command to start the analysis.
- Upon completion, it gathers all relevant errors and sends them back to the main process as a
ProblemReport.
Problem Data Structure
Problems are represented by a consistent data structure throughout the application.
| Field | Type | Description |
|---|---|---|
file | string | The path to the file containing the problem. |
line | number | The line number where the problem occurs. |
column | number | The column number where the problem occurs. |
message | string | The error message from the TypeScript compiler. |
code | number | The TypeScript error code (e.g., 2339). |
snippet | string | A small code snippet showing the context of the error. |
Sources: src/tests/problem_prompt.test.ts:9-23
User Interface and Interaction
The user interacts with the problem detection system through the "Problems" tab in the preview panel and through automated summaries in the chat window.
Problems Panel
The "Problems" panel (Problems.tsx) displays a list of all current TypeScript errors. E2E tests demonstrate its functionality:
- Users can view a list of all detected problems.
- Each problem is selectable via a checkbox.
- A "Re-check Problems" button allows for manually re-triggering the analysis.
- A "Fix All" / "Fix X problems" button is available to send the selected problems to the AI for fixing.
Sources: e2e-tests/problems.spec.ts:70-136
Auto-Fix Chat Summary (DyadProblemSummary.tsx)
When the "Auto-fix" feature is enabled, the AI's attempts to fix problems are presented in the chat via the DyadProblemSummary component.
- It displays a summary line like "Auto-fix: 5 problems found (TypeScript errors)".
- The component is collapsible, and when expanded, it shows a detailed list of each problem.
- It parses a special format from the AI's response to render the problem list. The AI response contains
<problem>tags with attributes for file, line, column, code, and the error message as its content.
// Example of the parsing logic in DyadProblemSummary.tsx
const problemTagRegex =
/<problem\s+file="([^"]+)"\s+line="(\d+)"\s+column="(\d+)"\s+code="(\d+)">([^<]+)<\/problem>/g;
Sources: src/components/chat/DyadProblemSummary.tsx:70-98
Problem Fixing Flow
The core of the feature is the process of turning a list of detected problems into a solution generated by the AI. This can be triggered automatically or manually.
Sequence Diagram of Fixing Process
This diagram shows the sequence of events from detecting an error to the AI providing a fix.
Prompt Generation
When a fix is requested, the system generates a specific prompt for the AI. The createProblemFixPrompt function is responsible for this. It takes a ProblemReport and formats it into a human-readable list.
Example of a generated prompt for multiple errors:
Fix these 2 TypeScript compile-time errors:
1. src/bad-file.ts:1:30 - Cannot find module 'non-existent-class' or its corresponding type declarations. (TS2307)
'''
import NonExistentClass from 'non-existent-class'; // <-- TypeScript compiler error here
'''
2. src/bad-file.ts:4:3 - Property 'nonExistentMethod' does not exist on type 'Object'. (TS2339)
'''
const x = new Object();
x.nonExistentMethod(); // <-- TypeScript compiler error here
'''
Please fix all errors in a concise way.
Sources: src/tests/problem_prompt.test.ts:25-189, e2e-tests/snapshots/problems.spec.ts_problems-auto-fix---enabled-2.txt
Auto-Fix Mechanism
The application can be configured with enableAutoFixProblems: true. When active, the system automatically sends detected errors to the AI for correction without user intervention.
- The feature is tested in
e2e-tests/problems.spec.ts. - The tests show that the AI will attempt to fix errors, but will "give up" after two failed attempts on an unfixable error to prevent infinite loops. This indicates a retry mechanism is in place.
- The AI's response, containing file modifications within
<dyad-write>tags, is then applied to the user's codebase.
Sources: e2e-tests/problems.spec.ts:10-33