App Management
Relevant source files
The following files were used as context for generating this wiki page:
- src/prompts/system_prompt.ts
- e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
- e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---default-build-mode-1.txt
- e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---dump-request-2.txt
- e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
- e2e-tests/snapshots/mention_app.spec.ts_mention-app-without-pro-1.txt
The Dyad AI's behavior is governed by a dynamic system of prompts and rules. This system defines the AI's role, capabilities, constraints, and output format. It is designed to be adaptable, allowing for different operational modes and project-specific instructions through a customizable AI_RULES.md file. This architecture ensures the AI can function as a code generator, a technical advisor, or a specialized agent depending on the user's needs.
Sources: src/prompts/system_prompt.ts
Core Concepts
The foundation of the AI's instruction set is built from several components that are combined at runtime.
Prompt Composition
The final system prompt is constructed by injecting project-specific rules into a template. The BUILD_SYSTEM_PROMPT constant defines this structure, which includes a prefix, a postfix, and a placeholder [[AI_RULES]] that gets replaced with the actual rules.
This diagram illustrates how the final prompt is assembled.
Sources: src/prompts/system_prompt.ts:317-323
The AI_RULES.md File
Each Dyad application can contain an AI_RULES.md file in its root directory. This file provides project-specific context, such as the tech stack, library usage guidelines, and coding conventions. The readAiRules function is responsible for reading this file. If the file is not found or an error occurs, it falls back to a DEFAULT_AI_RULES constant.
The following diagram shows the logic for loading AI rules.
Sources: src/prompts/system_prompt.ts:468-477
The default rules define a standard environment for a React application using TypeScript, React Router, and Shadcn/UI components.
Sources: src/prompts/system_prompt.ts:325-350
Operational Modes
The system supports multiple operational modes, each with a distinct system prompt that dictates the AI's behavior. The constructSystemPrompt function selects the appropriate prompt based on the chatMode.
Sources: src/prompts/system_prompt.ts:442-454
| Mode | Prompt Constant | Purpose |
|---|---|---|
build | BUILD_SYSTEM_PROMPT | The default mode for generating and modifying code using <dyad-*> tags. |
ask | ASK_MODE_SYSTEM_PROMPT | A conversational mode for answering questions and providing explanations without writing any code. |
agent | AGENT_MODE_SYSTEM_PROMPT | An analysis mode to determine necessary tools and resources before starting development. |
local-agent | constructLocalAgentPrompt() | A specialized agent mode for executing local tool calls. |
Sources: src/prompts/system_prompt.ts:456-466, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt, e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---dump-request-2.txt
Build Mode
This is the primary mode for software development. The AI is instructed to act as an "AI editor" that modifies web applications. It uses a set of XML-like tags to perform file operations.
Key instructions for Build Mode include:
- Use
<dyad-write>for creating/updating files. - Use
<dyad-rename>for renaming files. - Use
<dyad-delete>for deleting files. - Use
<dyad-add-dependency>for installing npm packages. - Provide a concise, non-technical summary of changes.
- Never use Markdown code blocks for code output.
Sources: src/prompts/system_prompt.ts:49-110
Ask Mode
In "Ask Mode," the AI is strictly prohibited from generating code. Its role is to be a helpful assistant for web development concepts, best practices, and technical guidance.
The "ABSOLUTE PRIMARY DIRECTIVE" for this mode is: YOU MUST NOT, UNDER ANY CIRCUMSTANCES, WRITE OR GENERATE CODE. This includes a ban on all <dyad-*> tags and Markdown code blocks.
Sources: src/prompts/system_prompt.ts:352-439, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
Agent Mode
This mode is designed for the initial phase of a request. The AI's goal is to analyze the user's request and determine what tools, APIs, or external resources are needed. It does not generate code but prepares for the development phase. If no tools are needed, it responds with a specific phrase: "Ok, looks like I don't need any tools, I can start building."
Sources: src/prompts/system_prompt.ts:404-440
Security Review Mode
A specialized prompt is used for security reviews. The AI acts as a security expert to identify vulnerabilities. It uses a custom <dyad-security-finding> tag to structure its output, detailing the vulnerability, risk, potential solutions, and relevant files.
Sources: e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
Key Directives and Tags
The AI uses a custom XML-like syntax to perform actions and structure its responses. These tags are interpreted by the Dyad application to execute file system operations, manage dependencies, and control the UI.
| Tag | Attributes | Description | Source File |
|---|---|---|---|
<dyad-write> | path, description | Creates a new file or overwrites an existing one with the provided content. | src/prompts/system_prompt.ts:90-93 |
<dyad-rename> | from, to | Renames a file or directory. | src/prompts/system_prompt.ts:200-200 |
<dyad-delete> | path | Deletes a file. | src/prompts/system_prompt.ts:229-229 |
<dyad-add-dependency> | packages | Installs one or more npm packages (space-separated). | src/prompts/system_prompt.ts:102-105 |
<dyad-command> | type | Suggests a UI command for the user to execute (e.g., rebuild, restart). | src/prompts/system_prompt.ts:63-67 |
<dyad-chat-summary> | - | Sets the title for the current chat session. Must be included in every response. | src/prompts/system_prompt.ts:83-84 |
<dyad-add-integration> | provider | Displays a button to allow the user to add an integration like Supabase. | e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---default-build-mode-1.txt |
<dyad-security-finding> | title, level | Formats a security vulnerability report with details on risk and solutions. | e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt |
Prompt Construction Logic
The constructSystemPrompt function is the central point for assembling the final prompt sent to the AI model.
// src/prompts/system_prompt.ts:442-454
export const constructSystemPrompt = ({
aiRules,
chatMode = "build",
enableTurboEditsV2,
}: {
aiRules: string | undefined;
chatMode?: "build" | "ask" | "agent" | "local-agent";
enableTurboEditsV2: boolean;
}) => {
if (chatMode === "local-agent") {
return constructLocalAgentPrompt(aiRules);
}
const systemPrompt = getSystemPromptForChatMode({
chatMode,
enableTurboEditsV2,
});
return systemPrompt.replace("[[AI_RULES]]", aiRules ?? DEFAULT_AI_RULES);
};
Sources: src/prompts/system_prompt.ts:442-454
This function first checks for the special local-agent mode. Otherwise, it retrieves the base prompt for the given chatMode and injects the aiRules (either from AI_RULES.md or the default) into the [[AI_RULES]] placeholder. This modular approach allows for clear separation between the AI's core instructions and project-specific context.
Sources: src/prompts/system_prompt.ts:456-466, src/prompts/system_prompt.ts:468-477