Welcome to Dyad
Relevant source files
The following files were used as context for generating this wiki page:Dyad is an AI-powered editor designed to create and modify web applications through a conversational interface. It allows users to interact with an AI to make real-time changes to a codebase, with the results visible in a live application preview. The system is built as an Electron app and is designed to be extensible, with different AI "personalities" or modes for various tasks like building code, answering questions, or performing security reviews.
The core of Dyad's functionality lies in its system prompts, which define the AI's role, capabilities, and constraints for each interaction mode. For a deeper technical dive, the project's architecture is detailed in the Architecture Guide and the Agent Architecture Guide.
Sources: README.md, src/prompts/system_prompt.ts:13-17, CONTRIBUTING.md:6-8
AI Interaction Modes
Dyad operates using several distinct chat modes, each with a specific system prompt that tailors the AI's behavior. The mode is determined by the chatMode parameter passed to the constructSystemPrompt function.
Sources: src/prompts/system_prompt.ts:468-474
This diagram illustrates how a system prompt is selected based on the chosen chat mode.
Sources: src/prompts/system_prompt.ts:476-498
Build Mode
This is the primary mode for code generation and modification. The AI acts as an "AI editor" that writes, renames, deletes, and manages dependencies in a web application.
- Role: An AI editor that creates and modifies web applications in real-time.
- Key Behavior: Makes code changes using specific XML-like tags, provides concise explanations, and aims for simple, elegant code.
- Constraints: Must not use markdown for code; all code output is wrapped in
<dyad-*>tags. It must generate fully functional code, not partial implementations.
Sources: src/prompts/system_prompt.ts:70-76, 303-311
Ask Mode
In "Ask Mode," the AI acts as a helpful assistant for web development concepts, providing explanations and guidance without writing any code.
- Role: A helpful AI assistant specializing in web development, programming, and technical guidance.
- Key Behavior: Provides clear explanations, discusses best practices, and explains trade-offs.
- Constraints: There is an absolute prohibition on producing code. The AI must use conceptual explanations and analogies instead of code snippets. It is forbidden from using any
<dyad-*>tags.
Sources: src/prompts/system_prompt.ts:319-322, 366-370, 396-413, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
Agent & Local Agent Modes
These modes are designed for analyzing requests and gathering information before coding begins. The "Local Agent" appears to be a more advanced version with tool-calling capabilities.
- Role: An AI App Builder Agent that determines necessary tools, APIs, and resources.
- Key Behavior: In Agent mode, it decides if external tools are needed. If not, it responds with "Ok, looks like I don't need any tools, I can start building." The Local Agent mode has a more structured approach to tool calling, with best practices like "Read before writing."
- Constraints: Both modes have an absolute constraint against code generation and the use of
<dyad-*>tags. Their job is to perform requirement analysis.
Sources: src/prompts/system_prompt.ts:415-420, 442-446, e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---dump-request-2.txt
The following table outlines the best practices for the Local Agent's tool usage.
| Practice | Description |
|---|---|
| Read before writing | Use read_file and list_files to understand the codebase before making changes. |
Use search_replace for edits | For modifying existing files, prefer search_replace over write_file. |
| Be surgical | Only change what's necessary to accomplish the task. |
| Handle errors gracefully | If a tool fails, explain the issue and suggest alternatives. |
Sources: e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---dump-request-2.txt
Key Features
Code Manipulation Commands
In Build Mode, the AI uses a set of custom XML-like tags to perform filesystem operations.
| Command | Description | Example |
|---|---|---|
<dyad-write> | Creates a new file or overwrites an existing one. Must contain the entire file content. | <dyad-write path="src/App.tsx">...</dyad-write> |
<dyad-rename> | Renames a file. | <dyad-rename from="old.js" to="new.js"></dyad-rename> |
<dyad-delete> | Deletes a file. | <dyad-delete path="src/to-delete.tsx"></dyad-delete> |
<dyad-add-dependency> | Adds one or more npm packages. | <dyad-add-dependency packages="react-hot-toast"></dyad-add-dependency> |
<dyad-command> | Suggests a UI command for the user to run (rebuild, restart, refresh). | <dyad-command type="rebuild"></dyad-command> |
<dyad-chat-summary> | Sets a concise summary for the current chat session. | <dyad-chat-summary>Adding a new component</dyad-chat-summary> |
Sources: src/prompts/system_prompt.ts:88-111, 197-201, 233-235, 266-268
Structured Thinking Process
Before responding to a user, the AI is instructed to use a <think> block to outline its plan. This process is not shown to the user but helps the AI structure its response.
The diagram below shows the flow of the AI's thinking process.
Sources: src/prompts/system_prompt.ts:10-68
Security Review
Dyad includes a specialized /security-review command. When invoked, it uses a security expert persona to analyze the codebase for vulnerabilities.
Findings are reported using the <dyad-security-finding> tag with the following structure:
| Attribute | Description |
|---|---|
title | A brief, descriptive title of the vulnerability. |
level | The severity of the finding: critical, high, medium, or low. |
What | A plain-language explanation of the issue. |
Risk | The potential impact on data or system integrity. |
Potential Solutions | Ranked options to mitigate the vulnerability. |
Relevant Files | A list of file paths where the issue is located. |
Sources: e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
The severity levels are defined as follows:
| Level | Description |
|---|---|
| critical | Actively or trivially exploitable, leading to full system/data compromise. |
| high | Exploitable with some conditions; could lead to significant data exposure or account takeover. |
| medium | Increases exposure or weakens defenses, but exploitation requires multiple steps. |
| low | Low immediate risk; violates best practices without a clear exploitation path. |
Sources: e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
Development and Contribution
The project is an Electron app. To contribute, developers should first open an issue to discuss proposed changes.
The basic development setup involves:
- Install dependencies:
npm install - Create
userDatadirectory:mkdir -p userData - Apply database migrations:
npm run db:generateandnpm run db:push - Run locally:
npm start
The project uses pre-commit hooks for formatting and linting, which can be set up with npm run init-precommit. Unit tests are run with npm test and end-to-end tests with npm run e2e.
Sources: CONTRIBUTING.md:3-37