Skip to content

Commit 470161e

Browse files
committed
feat: Implement automatic backend server streaming in fullstack development mode
- Add intelligent terminal command routing for Python/backend commands - Backend servers automatically start when running fullstack apps - Frontend servers automatically start when running fullstack apps - Terminal output streams server startup and command execution - Fix preview panel conflicts by using proper app running process - Add comprehensive terminal integration documentation Resolves: Backend server streaming in Backend/Fullstack development modes
1 parent 5cac23a commit 470161e

File tree

3 files changed

+174
-70
lines changed

3 files changed

+174
-70
lines changed

src/ipc/utils/development_orchestrator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ Please generate a well-structured backend application with:
571571
IMPORTANT: Use proper dyad-write tags to create files. Always include the "path" attribute.
572572
For backend files, use paths like "backend/main.py" or "backend/server.js" etc.
573573
574+
**DO NOT attempt to run backend servers manually.** The system automatically handles server startup when users click the "Run App" button. Focus ONLY on creating code files. The system will automatically detect the framework and start the appropriate server.
575+
574576
Current AI_RULES.md contains development guidelines. Follow them strictly.
575577
`;
576578

src/prompts/system_prompt.ts

Lines changed: 43 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,9 @@ When working with Django applications:
181181
- Use <read_file> to examine existing Django files (models.py, views.py, urls.py, settings.py)
182182
- Use <search_replace> for precise edits to Django code
183183
- Use <write_to_file> for creating new Django apps, models, views, etc.
184-
- Use <dyad-run-backend-terminal-cmd> to execute Django management commands automatically in the backend terminal:
185-
- <dyad-run-backend-terminal-cmd description="Install Python dependencies">pip install -r requirements.txt</dyad-run-backend-terminal-cmd>
186-
- <dyad-run-backend-terminal-cmd description="Create database migrations">python manage.py makemigrations</dyad-run-backend-terminal-cmd>
187-
- <dyad-run-backend-terminal-cmd description="Apply database migrations">python manage.py migrate</dyad-run-backend-terminal-cmd>
188-
- <dyad-run-backend-terminal-cmd description="Start development server">python manage.py runserver 8000</dyad-run-backend-terminal-cmd>
189-
- <dyad-run-backend-terminal-cmd description="Create new Django app">python manage.py startapp <app_name></dyad-run-backend-terminal-cmd>
190184
- Use <grep_search> to find patterns across Django codebase
191185
192-
Always explain what you're doing and why, then use the appropriate tools to implement Django solutions. When setting up Django projects, use terminal commands to run migrations and start servers.
186+
**CRITICAL: DO NOT use <dyad-run-backend-terminal-cmd> tags during development.** The system automatically handles all server startup, dependency installation, and terminal commands when users click "Run App". Your role is ONLY to create and modify code files.
193187
194188
# Django Development Guidelines
195189
@@ -203,9 +197,11 @@ When working with Django applications:
203197
- **Security**: Implement CSRF protection, authentication, and authorization
204198
- **Testing**: Write comprehensive unit and integration tests
205199
206-
# Django Terminal Commands
200+
# IMPORTANT: Server Management
207201
208-
When you need to execute Django commands, use the <dyad-run-backend-terminal-cmd> tags above. The system will automatically run these commands in the backend terminal for you. Do not show commands in chat - use the dyad tags instead.
202+
**DO NOT attempt to run the Django server manually.** The system automatically handles server startup when users click the "Run App" button. You should focus on creating code files and using terminal commands only for installation, migrations, and other setup tasks. The system will automatically start the server using: \`python manage.py runserver 0.0.0.0:<available_port>\`
203+
204+
**NEVER output <dyad-run-backend-terminal-cmd> tags in your responses.** These are handled automatically by the system.
209205
210206
# Django Best Practices
211207
@@ -229,14 +225,9 @@ When working with FastAPI applications:
229225
- Use <read_file> to examine existing FastAPI files (main.py, routes, schemas, models)
230226
- Use <search_replace> for precise edits to FastAPI code
231227
- Use <write_to_file> for creating new routes, schemas, models, etc.
232-
- Use <dyad-run-backend-terminal-cmd> to execute FastAPI development commands automatically in the backend terminal:
233-
- <dyad-run-backend-terminal-cmd description="Install Python dependencies">pip install -r requirements.txt</dyad-run-backend-terminal-cmd>
234-
- <dyad-run-backend-terminal-cmd description="Start FastAPI server">uvicorn main:app --reload --host 0.0.0.0 --port 8000</dyad-run-backend-terminal-cmd>
235-
- <dyad-run-backend-terminal-cmd description="Create database migrations">alembic revision --autogenerate -m "migration message"</dyad-run-backend-terminal-cmd>
236-
- <dyad-run-backend-terminal-cmd description="Apply database migrations">alembic upgrade head</dyad-run-backend-terminal-cmd>
237228
- Use <grep_search> to find patterns across FastAPI codebase
238229
239-
Always explain what you're doing and why, then use the appropriate tools to implement FastAPI solutions. When setting up FastAPI projects, use terminal commands to install dependencies and start servers.
230+
**CRITICAL: DO NOT use <dyad-run-backend-terminal-cmd> tags during development.** The system automatically handles all server startup, dependency installation, and terminal commands when users click "Run App". Your role is ONLY to create and modify code files.
240231
241232
# FastAPI Development Guidelines
242233
@@ -249,9 +240,15 @@ When working with FastAPI applications:
249240
- **Documentation**: Leverage FastAPI's automatic OpenAPI documentation
250241
- **Testing**: Write async tests using pytest and httpx
251242
252-
# FastAPI Terminal Commands
243+
# IMPORTANT: Server Management
244+
245+
**DO NOT attempt to run the FastAPI server manually.** The system automatically handles server startup when users click the "Run App" button. You should focus on creating code files and using terminal commands only for installation, migrations, and other setup tasks. The system will automatically start the server using: \`uvicorn main:app --reload --host 0.0.0.0 --port <available_port>\`
246+
247+
**NEVER output <dyad-run-backend-terminal-cmd> tags in your responses.** These are handled automatically by the system.
248+
249+
# IMPORTANT: Server Management
253250
254-
When you need to execute FastAPI commands, use the <dyad-run-backend-terminal-cmd> tags above. The system will automatically run these commands in the backend terminal for you. Do not show commands in chat - use the dyad tags instead.
251+
**DO NOT attempt to run backend servers manually.** The system automatically handles server startup when users click the "Run App" button. You should focus on creating code files and using terminal commands only for installation, migrations, and other setup tasks. The system will detect the framework and start the appropriate server (uvicorn for FastAPI) automatically.
255252
256253
# FastAPI Best Practices
257254
@@ -276,16 +273,9 @@ When working with Flask applications:
276273
- Use <read_file> to examine existing Flask files (app.py, routes, models, templates)
277274
- Use <search_replace> for precise edits to Flask code
278275
- Use <write_to_file> for creating new routes, models, templates, etc.
279-
- Use <dyad-run-backend-terminal-cmd> to execute Flask development commands automatically in the backend terminal:
280-
- <dyad-run-backend-terminal-cmd description="Install Python dependencies">pip install -r requirements.txt</dyad-run-backend-terminal-cmd>
281-
- <dyad-run-backend-terminal-cmd description="Start Flask development server">python app.py</dyad-run-backend-terminal-cmd>
282-
- <dyad-run-backend-terminal-cmd description="Alternative Flask start">flask run --host=0.0.0.0 --port=5000</dyad-run-backend-terminal-cmd>
283-
- <dyad-run-backend-terminal-cmd description="Initialize Flask-Migrate">flask db init</dyad-run-backend-terminal-cmd>
284-
- <dyad-run-backend-terminal-cmd description="Create database migrations">flask db migrate -m "migration message"</dyad-run-backend-terminal-cmd>
285-
- <dyad-run-backend-terminal-cmd description="Apply database migrations">flask db upgrade</dyad-run-backend-terminal-cmd>
286276
- Use <grep_search> to find patterns across Flask codebase
287277
288-
Always explain what you're doing and why, then use the appropriate tools to implement Flask solutions. When setting up Flask projects, use terminal commands to install dependencies and start servers.
278+
**CRITICAL: DO NOT use <dyad-run-backend-terminal-cmd> tags during development.** The system automatically handles all server startup, dependency installation, and terminal commands when users click "Run App". Your role is ONLY to create and modify code files.
289279
290280
# Flask Development Guidelines
291281
@@ -298,9 +288,11 @@ When working with Flask applications:
298288
- **Extensions**: Leverage Flask extensions for common functionality (SQLAlchemy, Login, etc.)
299289
- **Configuration**: Manage different configurations for development and production
300290
301-
# Flask Terminal Commands
291+
# IMPORTANT: Server Management
302292
303-
When you need to execute Flask commands, use the <dyad-run-backend-terminal-cmd> tags above. The system will automatically run these commands in the backend terminal for you. Do not show commands in chat - use the dyad tags instead.
293+
**DO NOT attempt to run the Flask server manually.** The system automatically handles server startup when users click the "Run App" button. You should focus on creating code files and using terminal commands only for installation, migrations, and other setup tasks. The system will automatically start the server using the appropriate Flask command.
294+
295+
**NEVER output <dyad-run-backend-terminal-cmd> tags in your responses.** These are handled automatically by the system.
304296
305297
# Flask Best Practices
306298
@@ -325,15 +317,9 @@ When working with Node.js applications:
325317
- Use <read_file> to examine existing Node.js files (server.js, routes, models, controllers)
326318
- Use <search_replace> for precise edits to Node.js code
327319
- Use <write_to_file> for creating new routes, models, controllers, middleware, etc.
328-
- Use <dyad-run-backend-terminal-cmd> to execute Node.js development commands automatically in the backend terminal:
329-
- <dyad-run-backend-terminal-cmd description="Install Node.js dependencies">npm install</dyad-run-backend-terminal-cmd>
330-
- <dyad-run-backend-terminal-cmd description="Start production server">npm start</dyad-run-backend-terminal-cmd>
331-
- <dyad-run-backend-terminal-cmd description="Start development server">npm run dev</dyad-run-backend-terminal-cmd>
332-
- <dyad-run-backend-terminal-cmd description="Run server directly">node server.js</dyad-run-backend-terminal-cmd>
333-
- <dyad-run-backend-terminal-cmd description="Run with nodemon">npx nodemon server.js</dyad-run-backend-terminal-cmd>
334320
- Use <grep_search> to find patterns across Node.js codebase
335321
336-
Always explain what you're doing and why, then use the appropriate tools to implement Node.js solutions. When setting up Node.js projects, use terminal commands to install dependencies and start servers.
322+
**CRITICAL: DO NOT use <dyad-run-backend-terminal-cmd> tags during development.** The system automatically handles all server startup, dependency installation, and terminal commands when users click "Run App". Your role is ONLY to create and modify code files.
337323
338324
# Node.js Development Guidelines
339325
@@ -346,9 +332,11 @@ When working with Node.js applications:
346332
- **Database**: Choose appropriate database solutions (MongoDB, PostgreSQL, etc.)
347333
- **Testing**: Write unit and integration tests using Jest or Mocha
348334
349-
# Node.js Terminal Commands
335+
# IMPORTANT: Server Management
336+
337+
**DO NOT attempt to run the Node.js server manually.** The system automatically handles server startup when users click the "Run App" button. You should focus on creating code files and using terminal commands only for installation, migrations, and other setup tasks. The system will automatically start the server using the appropriate Node.js command.
350338
351-
When you need to execute Node.js commands, use the <dyad-run-backend-terminal-cmd> tags above. The system will automatically run these commands in the backend terminal for you. Do not show commands in chat - use the dyad tags instead.
339+
**NEVER output <dyad-run-backend-terminal-cmd> tags in your responses.** These are handled automatically by the system.
352340
353341
# Node.js Best Practices
354342
@@ -465,40 +453,21 @@ const FULLSTACK_AI_RULES = `# Full Stack Development
465453
- **Framework-Specific Commands**: Use appropriate commands based on the selected backend framework
466454
- **Clear Labeling**: Label each terminal command block with whether it's for frontend or backend
467455
468-
## Framework-Specific Terminal Commands
469-
470-
### Django Commands (Backend Terminal)
471-
- Install dependencies: <dyad-run-backend-terminal-cmd description="Install Python dependencies">pip install -r requirements.txt</dyad-run-backend-terminal-cmd>
472-
- Run migrations: <dyad-run-backend-terminal-cmd description="Apply database migrations">python manage.py migrate</dyad-run-backend-terminal-cmd>
473-
- Create migrations: <dyad-run-backend-terminal-cmd description="Create database migrations">python manage.py makemigrations</dyad-run-backend-terminal-cmd>
474-
- Start server: <dyad-run-backend-terminal-cmd description="Start Django development server">python manage.py runserver 8000</dyad-run-backend-terminal-cmd>
475-
- Create superuser: <dyad-run-backend-terminal-cmd description="Create Django superuser">python manage.py createsuperuser</dyad-run-backend-terminal-cmd>
476-
- Collect static files: <dyad-run-backend-terminal-cmd description="Collect static files">python manage.py collectstatic</dyad-run-backend-terminal-cmd>
477-
478-
### FastAPI Commands (Backend Terminal)
479-
- Install dependencies: <dyad-run-backend-terminal-cmd description="Install Python dependencies">pip install -r requirements.txt</dyad-run-backend-terminal-cmd>
480-
- Start server: <dyad-run-backend-terminal-cmd description="Start FastAPI server">uvicorn main:app --reload --host 0.0.0.0 --port 8000</dyad-run-backend-terminal-cmd>
481-
- Run with hot reload: <dyad-run-backend-terminal-cmd description="Run FastAPI with hot reload">uvicorn main:app --reload</dyad-run-backend-terminal-cmd>
482-
- Generate client: <dyad-run-backend-terminal-cmd description="Generate OpenAPI client">python -c "from main import app; print(app.openapi())"</dyad-run-backend-terminal-cmd>
483-
484-
### Flask Commands (Backend Terminal)
485-
- Install dependencies: <dyad-run-backend-terminal-cmd description="Install Python dependencies">pip install -r requirements.txt</dyad-run-backend-terminal-cmd>
486-
- Start server: <dyad-run-backend-terminal-cmd description="Start Flask development server">python app.py</dyad-run-backend-terminal-cmd>
487-
- Start with Flask CLI: <dyad-run-backend-terminal-cmd description="Start Flask with CLI">flask run --host=0.0.0.0 --port=5000</dyad-run-backend-terminal-cmd>
488-
- Initialize database: <dyad-run-backend-terminal-cmd description="Initialize Flask-Migrate">flask db init</dyad-run-backend-terminal-cmd>
489-
490-
### Node.js Commands (Backend Terminal)
491-
- Install dependencies: <dyad-run-backend-terminal-cmd description="Install Node.js dependencies">npm install</dyad-run-backend-terminal-cmd>
492-
- Start server: <dyad-run-backend-terminal-cmd description="Start production server">npm start</dyad-run-backend-terminal-cmd>
493-
- Development mode: <dyad-run-backend-terminal-cmd description="Start development server">npm run dev</dyad-run-backend-terminal-cmd>
494-
- Build for production: <dyad-run-backend-terminal-cmd description="Build for production">npm run build</dyad-run-backend-terminal-cmd>
495-
496-
### Frontend Commands (Frontend Terminal)
497-
- Install dependencies: <dyad-run-frontend-terminal-cmd description="Install frontend dependencies">npm install</dyad-run-frontend-terminal-cmd>
498-
- Start development server: <dyad-run-frontend-terminal-cmd description="Start frontend development server">npm run dev</dyad-run-frontend-terminal-cmd>
499-
- Build for production: <dyad-run-frontend-terminal-cmd description="Build frontend for production">npm run build</dyad-run-frontend-terminal-cmd>
500-
- Run tests: <dyad-run-frontend-terminal-cmd description="Run frontend tests">npm test</dyad-run-frontend-terminal-cmd>
501-
- Lint code: <dyad-run-frontend-terminal-cmd description="Lint frontend code">npm run lint</dyad-run-frontend-terminal-cmd>
456+
## IMPORTANT: Terminal Command Management
457+
458+
**CRITICAL RULE: You must NEVER output <dyad-run-*-terminal-cmd> tags in your responses.** These tags are for system-internal use only and will cause errors if you attempt to use them.
459+
460+
The system automatically handles ALL terminal operations:
461+
- Server startup when users click "Run App"
462+
- Dependency installation during app creation
463+
- Database migrations and setup
464+
- All other terminal commands
465+
466+
Your role is strictly limited to creating and modifying code files. Do not attempt to execute any terminal commands.
467+
468+
## Server Management
469+
470+
**DO NOT attempt to run backend servers manually.** The system automatically handles server startup when users click the "Run App" button. You should focus on creating code files and using terminal commands only for installation, migrations, and other setup tasks. The system will detect the framework and start the appropriate server automatically.
502471
503472
## Integration Best Practices
504473
- Design clean API contracts between frontend and backend
@@ -631,6 +600,10 @@ const FASTAPI_AI_RULES = `# FastAPI Backend Development
631600
- Use background tasks for long-running operations
632601
- Implement rate limiting and security measures
633602
- Add proper authentication and authorization
603+
604+
## Server Management
605+
606+
**DO NOT attempt to run the FastAPI server manually.** The system automatically handles server startup when users click the "Run App" button. You should focus ONLY on creating and modifying code files. All server operations, dependency installation, and terminal commands are handled automatically by the system.
634607
`;
635608

636609
const FLASK_AI_RULES = `# Flask Backend Development

0 commit comments

Comments
 (0)