Configuration
Relevant source files
The following files were used as context for generating this wiki page:
- src/prompts/system_prompt.ts
- src/prompts/security_review_prompt.ts
- e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
- e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
- e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---dump-request-2.txt
- e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---default-build-mode-1.txt
The system prompt is a foundational component that defines the AI's behavior, rules, and capabilities within the Dyad application. It is dynamically constructed based on the selected operational mode (chatMode) and project-specific rules, ensuring the AI assistant acts appropriately for tasks like code generation, technical guidance, or security analysis. The configuration is designed to be modular, allowing different sets of instructions to be combined to form a cohesive and context-aware prompt.
The core logic for assembling these prompts resides in src/prompts/system_prompt.ts. This module exports functions and constants that define the persona, guidelines, and output formats for various AI modes. The primary function, constructSystemPrompt, orchestrates the assembly of the final prompt sent to the AI model.
System Prompt Architecture
The system prompt is not a single static string but is composed of several parts that are combined at runtime. This allows for flexibility and specialization based on the task at hand. The main components are the base prompt for the selected mode and a set of project-specific rules.
The following diagram illustrates the process of constructing the final system prompt.
This diagram shows how constructSystemPrompt selects a base prompt based on chatMode, injects the project-specific aiRules, and optionally appends additional prompts before producing the final system prompt.
Sources: src/prompts/system_prompt.ts:466-486
Operational Modes
The system supports several distinct operational modes, each with a specialized system prompt to guide the AI's behavior. The mode is determined by the chatMode parameter passed to constructSystemPrompt.
| Mode | Constant/Function | Purpose |
|---|---|---|
build | BUILD_SYSTEM_PROMPT | Code generation and modification. Instructs the AI to use <dyad-*> tags for file operations. |
ask | ASK_MODE_SYSTEM_PROMPT | Provides technical guidance and explanations without writing any code. |
agent | AGENT_MODE_SYSTEM_PROMPT | Gathers information and analyzes requirements before coding begins. Does not generate code. |
local-agent | constructLocalAgentPrompt | Interacts with the local environment using a specific set of tools. |
security-review | SECURITY_REVIEW_SYSTEM_PROMPT | Analyzes code for security vulnerabilities and reports them in a structured format. |
Sources: src/prompts/system_prompt.ts:488-505, src/prompts/security_review_prompt.ts
Build Mode
This is the primary mode for generating and modifying code. The BUILD_SYSTEM_PROMPT instructs the AI to act as an "AI editor" that assists users by making real-time code changes.
Key instructions include:
- File Operations: Use of specific XML-like tags for file manipulation:
<dyad-write path="..." description="...">: Creates or overwrites a file.<dyad-rename from="..." to="...">: Renames a file.<dyad-delete path="...">: Deletes a file.<dyad-add-dependency packages="...">: Adds npm dependencies.
- Commands: Suggesting UI commands like
Rebuild,Restart, orRefreshusing<dyad-command type="...">. - Code Style: Writing complete, functional, and simple code. It is explicitly told not to over-engineer solutions.
- Constraints: A critical rule is to never use Markdown code blocks for code output, enforcing the use of
<dyad-write>tags exclusively.
Sources: src/prompts/system_prompt.ts:65-247, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---default-build-mode-1.txt
Ask Mode
In ask mode, the AI acts as a helpful assistant for technical guidance, strictly prohibited from producing any code. The ASK_MODE_SYSTEM_PROMPT enforces this with an "ABSOLUTE PRIMARY DIRECTIVE".
Key instructions include:
- NO CODE PRODUCTION: The most important rule is to never write, generate, or produce any code snippets, examples, or implementations.
- Conceptual Explanations: Focus on explaining concepts, best practices, and problem-solving approaches in plain language.
- Forbidden Tags: Prohibits the use of any
<dyad-*>tags. - Role: The AI's role is to be a "knowledgeable, helpful companion" that provides explanations, not code.
Sources: src/prompts/system_prompt.ts:285-381, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
Agent Mode
The agent mode is designed for an initial analysis phase. The AI's role is to determine the tools, APIs, and resources needed to fulfill a user's request without writing any code.
Key instructions include:
- Tool Usage Framework: Decide whether external tools/APIs are needed.
- No Code Generation: Explicitly forbidden from writing any code or providing implementation details.
- Output: If no tools are needed, it must respond with a specific phrase:
"Ok, looks like I don't need any tools, I can start building."Otherwise, it provides a summary of information gathered.
Sources: src/prompts/system_prompt.ts:383-443
Local Agent Mode
The local-agent mode uses a distinct prompt constructed by constructLocalAgentPrompt. This prompt is tailored for scenarios where the AI uses a set of tools to interact with the local file system and environment. It emphasizes reading files before writing and using tools to gather information instead of guessing.
Sources: src/prompts/system_prompt.ts:473-475, e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---dump-request-2.txt
Security Review Mode
This special-purpose mode is triggered to perform security analysis on the codebase. The SECURITY_REVIEW_SYSTEM_PROMPT defines the AI as a security expert looking for specific types of vulnerabilities.
Key instructions include:
- Focus Areas: Prioritizes issues like Authentication, Injection Attacks, API Security, and Client-Side Secrets.
- Output Format: Mandates a structured output using the
<dyad-security-finding>tag withtitleandlevelattributes. - Severity Levels: Defines
critical,high,medium, andlowseverity levels.
The structure of a security finding is as follows:
<dyad-security-finding title="Brief title" level="critical|high|medium|low">
**What**: Plain-language explanation
**Risk**: Data exposure impact
**Potential Solutions**: Ranked options
**Relevant Files**: File paths
</dyad-security-finding>
Sources: src/prompts/security_review_prompt.ts:1-55, e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
AI Rules
A crucial part of the prompt configuration is the [[AI_RULES]] placeholder. This is dynamically replaced with project-specific guidelines, typically loaded from an AI_RULES.md file in the user's project directory.
Loading AI Rules
The readAiRules function is responsible for loading these rules. It attempts to read AI_RULES.md from the project path. If the file is not found or an error occurs, it falls back to DEFAULT_AI_RULES.
This diagram shows the logic of the readAiRules function, including its fallback mechanism.
Sources: src/prompts/system_prompt.ts:507-517
Default AI Rules
When a project-specific AI_RULES.md is not available, a default set of rules is used. DEFAULT_AI_RULES defines a standard tech stack for a React application.
Key default rules include:
- Tech Stack: React, TypeScript, React Router.
- File Structure:
src/pages/,src/components/. - UI/Styling: Strong preference for
shadcn/uiand Tailwind CSS. - Available Packages: Notes that
lucide-reactandshadcn/uicomponents are pre-installed.
Sources: src/prompts/system_prompt.ts:260-283