Getting Started
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 preview. The AI's behavior is governed by a sophisticated system of prompts that define its role, capabilities, and constraints based on the selected interaction mode.
This guide provides an overview of Dyad's core concepts, including its different operational modes and the XML-based command system used for interaction. Understanding these fundamentals is key to effectively using and extending the Dyad platform.
Core Concepts
The behavior of the Dyad AI is determined by a dynamically constructed system prompt. This prompt is tailored based on the selected chatMode and a project-specific AI_RULES.md file, which defines the tech stack and coding conventions.
Sources: src/prompts/system_prompt.ts:470-484
System Prompt Construction
The final system prompt sent to the AI is assembled from several parts, depending on the chat mode. The constructSystemPrompt function manages this process.
The following diagram illustrates the process of constructing the system prompt.
Chat Modes
Dyad operates in several distinct modes, each with a specific purpose and set of rules. The mode determines the AI's persona and capabilities.
| Mode | Persona | Primary Function | Code Generation |
|---|---|---|---|
build | AI Editor | Creates and modifies web applications. | Yes |
ask | Helpful AI Assistant | Provides explanations and technical guidance. | No (Strictly forbidden) |
agent | AI App Builder Agent | Gathers information and analyzes requirements before coding. | No |
local-agent | AI Assistant | Similar to build but uses a different tool-calling prompt structure. | Yes |
security-review | Security Expert | Identifies vulnerabilities in the codebase. | No (Generates findings) |
Sources: src/prompts/system_prompt.ts:470-497, e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
AI Thinking Process
Before responding, the AI is instructed to use a <think> block to outline its plan. This structured process ensures that the AI considers all aspects of a request before taking action.
Example thinking process:
- Identify the user's specific request.
- Examine relevant components in the codebase.
- Diagnose potential causes or implementation paths.
- Plan the approach, including which files to modify.
- Consider improvements beyond the immediate fix.
Sources: src/prompts/system_prompt.ts:8-70
Interaction Model: Dyad XML Tags
Dyad uses a system of custom XML-like tags to perform actions on the codebase. The AI generates these tags in its response, and the Dyad environment interprets them to modify files, manage dependencies, and control the application preview. Markdown code blocks are strictly forbidden for code output.
Sources: src/prompts/system_prompt.ts:316-324
File Operation Tags
These tags are used to manipulate files in the project.
| Tag | Attributes | Description |
|---|---|---|
<dyad-write> | path, description | Creates a new file or completely overwrites an existing one. The entire file content must be provided. |
<dyad-rename> | from, to | Renames a file or directory. |
<dyad-delete> | path | Deletes a file. |
<dyad-search-replace> | path, description | Performs a surgical search-and-replace operation within a file. Used for targeted edits. |
Sources: src/prompts/system_prompt.ts:114-116, src/prompts/system_prompt.ts:117, src/prompts/system_prompt.ts:118, e2e-tests/snapshots/turbo_edits_v2.spec.ts_turbo-edits-v2---search-replace-dump-2.txt
Dependency and Command Tags
These tags handle package management and app server commands.
| Tag | Attributes / Value | Description |
|---|---|---|
<dyad-add-dependency> | packages | Installs one or more npm packages. Package names are space-separated. |
<dyad-command> | type | Suggests a command for the user to run in the UI. Types can be rebuild, restart, or refresh. |
<dyad-chat-summary> | (content) | Sets a short summary for the current chat session. |
<dyad-add-integration> | provider | Shows a button to the user to add an integration, like supabase. |
Sources: src/prompts/system_prompt.ts:119-122, src/prompts/system_prompt.ts:90-96, src/prompts/system_prompt.ts:108-109, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---default-build-mode-1.txt
Chat Modes in Detail
Build Mode
This is the default and primary mode for software development. The AI acts as an editor, directly writing, renaming, and deleting files to fulfill user requests.
Key Guidelines:
- Must not use markdown for code; only
<dyad-write>is allowed. - Must write complete, fully functional code. No placeholders or partial implementations.
- Should create new files for new components, aiming for small, focused files.
- Should not over-engineer solutions and should stick to the user's request.
The following diagram shows the typical workflow in Build Mode.
Ask Mode
In ask mode, the AI's role shifts to that of a helpful assistant. It is strictly prohibited from generating any code. Its purpose is to provide explanations, discuss best practices, and offer conceptual guidance.
Key Principles:
- NO CODE PRODUCTION: The AI must never write code snippets, syntax examples, or file content.
- Conceptual Explanations: Focus on explaining the "why" behind recommendations.
- No
<dyad-*>tags: All file operation tags are forbidden.
Sources: src/prompts/system_prompt.ts:366-372, src/prompts/system_prompt.ts:420-432
Security Review Mode
When triggered (e.g., by the /security-review command), the AI adopts the persona of a security expert. It analyzes the codebase for vulnerabilities and reports them using the <dyad-security-finding> tag.
Output Format:
<dyad-security-finding title="Brief title" level="critical|high|medium|low">
**What**: Plain-language explanation
**Risk**: Data exposure impact
**Potential Solutions**: Options ranked by effectiveness
**Relevant Files**: Relevant file paths
</dyad-security-finding>
The focus is on exploitable vulnerabilities that could lead to data breaches, such as injection attacks and exposed client-side secrets.
Sources: e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
Project Configuration (AI_RULES.md)
The AI_RULES.md file in the root of a project's directory is used to provide project-specific context and rules to the AI. This file typically defines the technology stack, preferred libraries, and coding conventions.
If AI_RULES.md is not found, a default set of rules is used. The readAiRules function is responsible for loading this file.
Sources: src/prompts/system_prompt.ts:499-510
Default AI Rules
The default rules configure the AI for a standard React application with TypeScript, React Router, and Shadcn/UI components.
const DEFAULT_AI_RULES = `# Tech Stack
- You are building a React application.
- Use TypeScript.
- Use React Router. KEEP the routes in src/App.tsx
- Always put source code in the src folder.
- Put pages into src/pages/
- Put components into src/components/
- The main page (default page) is src/pages/Index.tsx
- UPDATE the main page to include the new components. OTHERWISE, the user can NOT see any components!
- ALWAYS try to use the shadcn/ui library.
- Tailwind CSS: always use Tailwind CSS for styling components. Utilize Tailwind classes extensively for layout, spacing, colors, and other design aspects.
Available packages and libraries:
- The lucide-react package is installed for icons.
- You ALREADY have ALL the shadcn/ui components and their dependencies installed. So you don't need to install them again.
- You have ALL the necessary Radix UI components installed.
- Use prebuilt components from the shadcn/ui library after importing them. Note that these files shouldn't be edited, so make new components if you need to change them.
`;
Sources: src/prompts/system_prompt.ts:326-353