|
| 1 | +Here's a comprehensive best practices guide for developing new task types in this system: |
| 2 | + |
| 3 | +# Best Practices Guide for Developing New Task Types |
| 4 | + |
| 5 | +## 1. Task Structure and Inheritance |
| 6 | + |
| 7 | +### Base Classes |
| 8 | +- Extend either `AbstractTask` or one of its specialized subclasses like `AbstractFileTask` or `AbstractAnalysisTask` |
| 9 | +- Use `AbstractFileTask` for tasks that primarily work with files |
| 10 | +- Use `AbstractAnalysisTask` for tasks that analyze code/content and provide recommendations |
| 11 | + |
| 12 | +```kotlin |
| 13 | +class NewTask( |
| 14 | + planSettings: PlanSettings, |
| 15 | + planTask: NewTaskConfigData? |
| 16 | +) : AbstractFileTask<NewTask.NewTaskConfigData>(planSettings, planTask) { |
| 17 | + // Implementation |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +### Configuration Classes |
| 22 | +- Create a nested `ConfigData` class extending appropriate base config class |
| 23 | +- Use descriptive `@Description` annotations for all configuration fields |
| 24 | +- Group related configuration parameters logically |
| 25 | +- Provide sensible defaults where appropriate |
| 26 | + |
| 27 | +```kotlin |
| 28 | +class NewTaskConfigData( |
| 29 | + @Description("Clear description of what this parameter does") |
| 30 | + val parameterName: Type = defaultValue, |
| 31 | + task_description: String? = null, |
| 32 | + task_dependencies: List<String>? = null, |
| 33 | + input_files: List<String>? = null, |
| 34 | + output_files: List<String>? = null, |
| 35 | + state: TaskState? = null |
| 36 | +) : FileTaskConfigBase( |
| 37 | + task_type = TaskType.NewTask.name, |
| 38 | + task_description = task_description, |
| 39 | + task_dependencies = task_dependencies, |
| 40 | + input_files = input_files, |
| 41 | + output_files = output_files, |
| 42 | + state = state |
| 43 | +) |
| 44 | +``` |
| 45 | + |
| 46 | +## 2. Task Registration |
| 47 | + |
| 48 | +### TaskType Registration |
| 49 | +- Add new task type to `TaskType` companion object |
| 50 | +- Provide clear description and detailed tooltipHtml |
| 51 | +- Register constructor in initialization block |
| 52 | +- Define appropriate task settings class |
| 53 | + |
| 54 | +```kotlin |
| 55 | +val NewTask = TaskType( |
| 56 | + "NewTask", |
| 57 | + NewTaskConfigData::class.java, |
| 58 | + TaskSettingsBase::class.java, |
| 59 | + "Clear description of task purpose", |
| 60 | + """ |
| 61 | + Detailed HTML tooltip with: |
| 62 | + <ul> |
| 63 | + <li>Key features</li> |
| 64 | + <li>Use cases</li> |
| 65 | + <li>Important considerations</li> |
| 66 | + </ul> |
| 67 | + """ |
| 68 | +) |
| 69 | + |
| 70 | +init { |
| 71 | + registerConstructor(NewTask) { settings, task -> NewTask(settings, task) } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +## 3. Implementation Best Practices |
| 76 | + |
| 77 | +### Prompt Design |
| 78 | +- Provide clear, detailed prompts for AI interactions |
| 79 | +- Include examples and formatting requirements |
| 80 | +- Specify input/output expectations |
| 81 | +- Document any special considerations |
| 82 | + |
| 83 | +```kotlin |
| 84 | +override val actorPrompt = """ |
| 85 | + Clear instructions for the AI about: |
| 86 | + 1. What needs to be analyzed/generated |
| 87 | + 2. Expected format of response |
| 88 | + 3. Important considerations |
| 89 | + 4. Examples if helpful |
| 90 | +
|
| 91 | + Format requirements: |
| 92 | + - Use specific markdown formatting |
| 93 | + - Include necessary headers |
| 94 | + - Show diffs in specific way |
| 95 | +""".trimIndent() |
| 96 | +``` |
| 97 | + |
| 98 | +### Error Handling |
| 99 | +- Validate configuration in a dedicated method |
| 100 | +- Use descriptive error messages |
| 101 | +- Handle edge cases gracefully |
| 102 | +- Log errors appropriately |
| 103 | + |
| 104 | +```kotlin |
| 105 | +protected fun validateConfig() { |
| 106 | + requireNotNull(taskConfig) { "Task configuration is required" } |
| 107 | + require(!taskConfig.input_files.isNullOrEmpty()) { "At least one input file must be specified" } |
| 108 | + // Additional validation |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +### Resource Management |
| 113 | +- Clean up resources in finally blocks |
| 114 | +- Use appropriate timeouts |
| 115 | +- Handle concurrent operations safely |
| 116 | +- Consider memory usage for large operations |
| 117 | + |
| 118 | +## 4. Output Formatting |
| 119 | + |
| 120 | +### Consistent Formatting |
| 121 | +- Use markdown for structured output |
| 122 | +- Include clear section headers |
| 123 | +- Format code blocks appropriately |
| 124 | +- Use diffs for code changes |
| 125 | + |
| 126 | +```kotlin |
| 127 | +private fun formatResults(results: List<Result>): String = buildString { |
| 128 | + appendLine("# Task Results") |
| 129 | + appendLine() |
| 130 | + results.forEach { result -> |
| 131 | + appendLine("## ${result.title}") |
| 132 | + appendLine("```${result.language}") |
| 133 | + appendLine(result.code) |
| 134 | + appendLine("```") |
| 135 | + appendLine() |
| 136 | + } |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +## 5. Integration Considerations |
| 141 | + |
| 142 | +### Dependencies |
| 143 | +- Clearly specify task dependencies |
| 144 | +- Handle dependency results appropriately |
| 145 | +- Consider parallel execution possibilities |
| 146 | +- Document integration requirements |
| 147 | + |
| 148 | +### State Management |
| 149 | +- Update task state appropriately |
| 150 | +- Handle interruptions gracefully |
| 151 | +- Preserve important state information |
| 152 | +- Clean up temporary state |
| 153 | + |
| 154 | +## 6. Documentation |
| 155 | + |
| 156 | +### Code Documentation |
| 157 | +- Document public APIs thoroughly |
| 158 | +- Explain complex logic |
| 159 | +- Document configuration parameters |
| 160 | +- Include usage examples |
| 161 | + |
| 162 | +### User Documentation |
| 163 | +- Provide clear promptSegment |
| 164 | +- Document configuration options |
| 165 | +- Include example use cases |
| 166 | +- List limitations and requirements |
| 167 | + |
| 168 | +```kotlin |
| 169 | +override fun promptSegment() = """ |
| 170 | + NewTask - Clear description of task purpose |
| 171 | + ** Required configuration item 1 |
| 172 | + ** Required configuration item 2 |
| 173 | + ** Optional configuration items |
| 174 | +""".trimIndent() |
| 175 | +``` |
| 176 | + |
| 177 | +## 7. Testing Considerations |
| 178 | + |
| 179 | +- Test with various input configurations |
| 180 | +- Verify error handling |
| 181 | +- Test resource cleanup |
| 182 | +- Validate output formatting |
| 183 | +- Test integration with other tasks |
| 184 | +- Consider performance implications |
| 185 | + |
| 186 | +## 8. Maintenance |
| 187 | + |
| 188 | +- Keep prompts updated with system capabilities |
| 189 | +- Monitor for AI model changes |
| 190 | +- Update documentation as needed |
| 191 | +- Review and optimize performance |
| 192 | +- Handle deprecated features gracefully |
| 193 | + |
| 194 | +Following these best practices will help ensure new tasks are reliable, maintainable, and integrate well with the existing system. |
0 commit comments