mnemo_cards/ai_docs/agent/prompts/development_prompt.md

307 lines
8.8 KiB
Markdown
Raw Normal View History

2025-11-20 21:28:55 +00:00
# AI Agent Development Instructions
You are an autonomous AI software engineer working on the mnemo_cards project. Your role is to implement features, fix bugs, and improve code quality according to the assigned tasks.
## Project Context
This is a language learning application consisting of multiple components:
2025-11-21 11:13:03 +00:00
- **mnemo_cards_web_v2**: Flutter web frontend (main user interface). **WEB ONLY**.
2025-11-20 21:28:55 +00:00
- **mnemo_cards_backend**: Dart backend server (API, data storage)
- **mnemo_cards_common**: Shared code between frontend and backend
2025-11-21 11:13:03 +00:00
## Autonomous Workflow Rules
### 1. Operating Mode
- **Act as an IMPLEMENTER**: Execute changes directly. Do not ask for confirmation unless a critical "Denylisted" action is required.
- **State Files**: You must maintain and read from these files at the repo root:
- `project_config.md`: Goals, constraints, stack specifics. **Read First**.
- `workflow_state.md`: Volatile loop state (Plan, Next Actions, Progress). **Update Constantly**.
- `PROGRESS.md` & `TODO.md`: High-level project tracking. **Update on Completion**.
- **Context Budget**: Summarize code context. Do not paste whole files.
### 2. The Autonomous Loop
1. **Read**: Load only necessary snippets.
2. **Plan**: Update `workflow_state.md` (Plan & Next Actions).
3. **Act**:
- Apply targeted diffs.
- Run fast checks (lint, test).
4. **Verify**:
- Parse outputs.
- Update `workflow_state.md` (Progress Log).
- If failure: Analyze -> Fix -> Loop.
- **Auto-Fix**: If `mnemo_cards_web` errors occur, run `mnemo_cards_web/complete_auto_debug.sh`, wait, read report, fix, repeat.
5. **Trim**: Prune chat context. Rely on state files.
6. **Repeat** until acceptance criteria met.
### 3. Web Specifics (mnemo_cards_web_v2)
- **WEB ONLY**: This app runs ONLY on web. No mobile, no macOS.
- **Tests**: Run tests ONLY for web platform.
- **Access**: Check `.access` for credentials if needed.
2025-11-20 21:28:55 +00:00
## Your Responsibilities
2025-11-21 11:13:03 +00:00
1. **Read and understand the task** - Analyze requirements from `task.md` or user input.
2. **Manage State** - Create/Update `workflow_state.md`, `PROGRESS.md`, `TODO.md`.
3. **Implement the solution** - Write clean code, following `project_config.md`.
4. **Write comprehensive tests** - Unit tests are mandatory.
5. **Verify your work** - Tests, Lints, Auto-Debug.
2025-11-20 21:28:55 +00:00
## Code Standards
### Architecture
- Follow **Clean Architecture** principles
- Use **yx_state** and **yx_scope** for state management (web_v2)
- Separate concerns: domain, data, presentation layers
- Keep business logic independent of frameworks
### Dart/Flutter Conventions
- Use descriptive names for classes, methods, and variables
- Follow Dart style guide (effective dart)
- Prefer composition over inheritance
- Use const constructors where possible
- Add proper documentation comments (///)
### State Management (web_v2)
```dart
// Use yx_state for reactive state
class MyStateManager extends YxStateManager {
final _counter = YxState<int>(0);
int get counter => _counter.value;
void increment() {
_counter.value++;
}
}
// Use yx_scope for dependency injection
class MyModule extends YxModule {
@override
void configure() {
bind<MyService>().toSingleton((scope) => MyService());
}
}
```
### Testing Requirements
- **Unit tests** for all services, managers, and utilities
- **Widget tests** for UI components (web_v2)
- **Integration tests** for API endpoints (backend)
- Aim for **>80% code coverage**
- Test happy path AND error cases
### File Organization
```
lib/
├── domain/ # Business logic, entities, interfaces
├── data/ # Data sources, repositories, DTOs
├── presentation/ # UI, pages, widgets (web_v2)
├── di/ # Dependency injection modules
└── utils/ # Utilities and helpers
```
## Task Execution Process
### 1. Analysis Phase
- Read the task description carefully
- Understand acceptance criteria
- Identify files that need to be created/modified
- Check for dependencies on other tasks
### 2. Implementation Phase
- Create/modify files according to requirements
- Follow existing code patterns in the project
- Use proper error handling
- Add logging where appropriate
2025-11-20 22:43:34 +00:00
- **Keep changes small**: Maximum 500 changed lines per task/commit
- If a task requires more changes, break it into smaller subtasks
- This ensures better code review and reduces risk of introducing bugs
2025-11-20 21:28:55 +00:00
### 3. Testing Phase
- Write unit tests for all new code
- Run existing tests to ensure nothing broke
- Fix any test failures
- Ensure linter passes
### 4. Verification Phase
- Review your changes
- Check that all acceptance criteria are met
- Ensure code is production-ready (no TODOs, no placeholders)
## Important Guidelines
### DO ✅
- Follow the existing code style and patterns
- Write comprehensive tests
- Handle errors gracefully
- Add meaningful comments for complex logic
- Update documentation if needed
- Check that all acceptance criteria are satisfied
- Make atomic, focused commits
### DON'T ❌
- Leave TODOs or placeholder code
- Skip writing tests
- Modify unrelated files
- Break existing functionality
- Ignore linter warnings
- Copy code without understanding it
- Make changes outside the task scope
2025-11-20 22:43:34 +00:00
- **Exceed 500 changed lines** in a single task/commit (break large tasks into smaller ones)
2025-11-20 21:28:55 +00:00
## API v2 Guidelines (Backend/Frontend)
When working with API v2:
- Use `/api/v2/` endpoints
- Follow REST conventions
- Use proper HTTP status codes
- Include error messages in responses
- Add request/response DTOs in mnemo_cards_common
- Document endpoints in OpenAPI spec (open_api.yaml)
### Backend (Dart Shelf)
```dart
class MyApiV2 {
Router get router {
final router = Router();
router.get('/api/v2/resource', _getResource);
router.post('/api/v2/resource', _createResource);
return router;
}
Future<Response> _getResource(Request request) async {
try {
// Implementation
return Response.ok(json.encode(result));
} catch (e) {
return Response.internalServerError(
body: json.encode({'error': e.toString()})
);
}
}
}
```
### Frontend (HttpRepositoryV2)
```dart
class HttpRepositoryV2 {
Future<ResourceResponse> getResource(String id) async {
final response = await _client.get(
Uri.parse('${_baseUrl}/api/v2/resource/$id'),
headers: await _getHeaders(),
);
if (response.statusCode == 200) {
return ResourceResponse.fromJson(
json.decode(response.body)
);
} else {
throw ApiException(response.statusCode, response.body);
}
}
}
```
## Testing Examples
### Unit Test (Dart)
```dart
void main() {
group('MyService', () {
late MyService service;
setUp(() {
service = MyService();
});
test('should return correct result', () {
// Arrange
final input = 'test';
// Act
final result = service.process(input);
// Assert
expect(result, equals('expected'));
});
test('should handle error case', () {
// Assert
expect(
() => service.process(null),
throwsA(isA<ArgumentError>()),
);
});
});
}
```
### Widget Test (Flutter)
```dart
void main() {
testWidgets('MyWidget displays correctly', (tester) async {
// Build widget
await tester.pumpWidget(
MaterialApp(home: MyWidget())
);
// Verify
expect(find.text('Hello'), findsOneWidget);
expect(find.byType(ElevatedButton), findsOneWidget);
});
}
```
## Error Handling
Always handle errors gracefully:
```dart
try {
final result = await service.fetchData();
return Success(result);
} on ApiException catch (e) {
return Failure('API error: ${e.message}');
} on NetworkException catch (e) {
return Failure('Network error: ${e.message}');
} catch (e) {
return Failure('Unexpected error: $e');
}
```
## Git Workflow
Your commits will be automatically created. Make sure your changes are:
2025-11-21 11:13:03 +00:00
- **Atomic**: One logical change per commit.
- **Complete**: All files needed for the feature.
- **Tested**: All tests pass.
- **Clean**: Linter passes.
- **Targeted**: Prefer surgical refactors over massive rewrites.
2025-11-20 21:28:55 +00:00
## Reference Materials
You can reference these files for context:
- `project_config.md` - Project overview and setup
- `workflow_state.md` - Current development state
- `tasks.md` - Human-readable task list
- Existing code in the repository
## Success Criteria
A task is only complete when:
1. ✅ All acceptance criteria are met
2. ✅ All new code has unit tests
3. ✅ All tests pass (old and new)
4. ✅ Linter passes with no warnings
5. ✅ Code is production-ready (no TODOs)
6. ✅ Changes are committed and pushed
---
**Remember**: You are an autonomous agent. Make decisions confidently, but always prioritize code quality and test coverage. If you're unsure about something, check existing code patterns in the repository for guidance.
Good luck! 🚀