|
| 1 | +# Run GraphAI Tool Implementation Plan |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document outlines the implementation plan for adding a `run_graphai` tool to Roo Code. The tool will execute GraphAI workflow files when they are in the context, similar to how the reference GraphAI debugger VS Code extension works. |
| 6 | + |
| 7 | +## Background Analysis |
| 8 | + |
| 9 | +### Current Roo Code Architecture |
| 10 | + |
| 11 | +- Tools are defined in [`src/shared/tools.ts`](../src/shared/tools.ts) |
| 12 | +- Tool implementations are in [`src/core/tools/`](../src/core/tools/) |
| 13 | +- Tools are organized into groups: read, edit, browser, command, mcp, modes |
| 14 | +- The [`execute_command`](../src/core/tools/executeCommandTool.ts) tool provides a good template for CLI-based tools |
| 15 | + |
| 16 | +### GraphAI File Structure |
| 17 | + |
| 18 | +GraphAI files use YAML or JSON format with this structure: |
| 19 | +```yaml |
| 20 | +agents: |
| 21 | + node_name: |
| 22 | + agent: agent_type |
| 23 | + name: "Display Name" |
| 24 | + description: "Node description" |
| 25 | + inputs: |
| 26 | + input_name: ":source_node" |
| 27 | +``` |
| 28 | +
|
| 29 | +### Reference Implementation |
| 30 | +
|
| 31 | +The GraphAI debugger extension executes GraphAI files using: |
| 32 | +- CLI command: `graphai <filepath>` |
| 33 | +- File validation for `.yaml`, `.yml`, `.json` extensions |
| 34 | +- Error handling with LLM analysis |
| 35 | +- Interactive webview for output display |
| 36 | + |
| 37 | +## Implementation Plan |
| 38 | + |
| 39 | +### Phase 1: Core Tool Registration |
| 40 | + |
| 41 | +```mermaid |
| 42 | +graph TD |
| 43 | + A[Add run_graphai to ToolName type] --> B[Create RunGraphaiToolUse interface] |
| 44 | + B --> C[Add tool to TOOL_DISPLAY_NAMES] |
| 45 | + C --> D[Add tool to command group] |
| 46 | + D --> E[Create runGraphaiTool.ts implementation] |
| 47 | + E --> F[Register tool in presentAssistantMessage.ts] |
| 48 | + F --> G[Add tool description] |
| 49 | +``` |
| 50 | + |
| 51 | +### Phase 2: File Changes Required |
| 52 | + |
| 53 | +#### 1. `src/shared/tools.ts` |
| 54 | +- Add `run_graphai: "run graphai workflows"` to `TOOL_DISPLAY_NAMES` |
| 55 | +- Create `RunGraphaiToolUse` interface: |
| 56 | +```typescript |
| 57 | +export interface RunGraphaiToolUse extends ToolUse { |
| 58 | + name: "run_graphai" |
| 59 | + params: Partial<Pick<Record<ToolParamName, string>, "path">> |
| 60 | +} |
| 61 | +``` |
| 62 | +- Add to `command` tool group alongside `execute_command` |
| 63 | + |
| 64 | +#### 2. `src/core/tools/runGraphaiTool.ts` (NEW FILE) |
| 65 | +- Similar structure to `executeCommandTool.ts` |
| 66 | +- Validate GraphAI file format (`.yaml`, `.yml`, `.json`) |
| 67 | +- Execute `graphai <filepath>` command using existing terminal infrastructure |
| 68 | +- Handle GraphAI-specific error patterns |
| 69 | +- Provide enhanced error messages for common GraphAI issues |
| 70 | + |
| 71 | +#### 3. `src/core/assistant-message/presentAssistantMessage.ts` |
| 72 | +- Add case for `"run_graphai"` in tool execution switch |
| 73 | +- Add tool name display logic |
| 74 | + |
| 75 | +#### 4. `src/core/prompts/tools/run-graphai.ts` (NEW FILE) |
| 76 | +- Create tool description following existing patterns |
| 77 | +- Add to `src/core/prompts/tools/index.ts` |
| 78 | + |
| 79 | +### Phase 3: Tool Implementation Details |
| 80 | + |
| 81 | +#### File Validation Logic |
| 82 | +```typescript |
| 83 | +function isValidGraphAIFile(filePath: string): boolean { |
| 84 | + const ext = path.extname(filePath).toLowerCase() |
| 85 | + return ['.yaml', '.yml', '.json'].includes(ext) |
| 86 | +} |
| 87 | +
|
| 88 | +function validateGraphAIContent(content: string, filePath: string): boolean { |
| 89 | + // Parse and validate GraphAI structure |
| 90 | + // Check for required sections (agents/nodes) |
| 91 | + // Return validation result |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +#### Command Execution |
| 96 | +```typescript |
| 97 | +// Similar to executeCommandTool but with GraphAI-specific handling |
| 98 | +const command = `graphai "${filePath}"` |
| 99 | +// Execute using existing terminal infrastructure |
| 100 | +// Parse GraphAI-specific output and errors |
| 101 | +``` |
| 102 | + |
| 103 | +#### Tool Description Format |
| 104 | +```markdown |
| 105 | +## run_graphai |
| 106 | +Description: Execute a GraphAI workflow file. This tool runs GraphAI YAML or JSON files using the graphai CLI command. GraphAI files define agent workflows with nodes and connections for AI-powered data processing pipelines. |
| 107 | + |
| 108 | +Parameters: |
| 109 | +- path: (required) Path to the GraphAI YAML or JSON file to execute |
| 110 | + |
| 111 | +Usage: |
| 112 | +<run_graphai> |
| 113 | +<path>path/to/workflow.yaml</path> |
| 114 | +</run_graphai> |
| 115 | + |
| 116 | +Example: Running a GraphAI workflow |
| 117 | +<run_graphai> |
| 118 | +<path>./workflows/data-processing.yaml</path> |
| 119 | +</run_graphai> |
| 120 | +``` |
| 121 | + |
| 122 | +### Phase 4: Enhanced Features |
| 123 | + |
| 124 | +#### GraphAI-Specific Enhancements |
| 125 | +1. **File Validation** |
| 126 | + - Check if file is a valid GraphAI YAML/JSON |
| 127 | + - Validate basic GraphAI structure (has `agents` or `nodes` section) |
| 128 | + - Provide helpful error messages for invalid files |
| 129 | + |
| 130 | +2. **Context Awareness** |
| 131 | + - Auto-detect GraphAI files in workspace |
| 132 | + - Suggest running GraphAI when GraphAI files are in context |
| 133 | + - Integration with file reading tools |
| 134 | + |
| 135 | +3. **Error Handling** |
| 136 | + - Parse GraphAI-specific error messages |
| 137 | + - Provide suggestions for common GraphAI issues |
| 138 | + - Integration with existing error handling patterns |
| 139 | + |
| 140 | +## Implementation Strategy |
| 141 | + |
| 142 | +### Step 1: Basic Tool Registration |
| 143 | +1. Add tool definition to shared types |
| 144 | +2. Create basic tool implementation |
| 145 | +3. Register in tool execution pipeline |
| 146 | + |
| 147 | +### Step 2: CLI Integration |
| 148 | +1. Implement GraphAI CLI execution |
| 149 | +2. Handle file validation |
| 150 | +3. Process command output |
| 151 | + |
| 152 | +### Step 3: Error Handling |
| 153 | +1. Add GraphAI-specific error parsing |
| 154 | +2. Implement helpful error messages |
| 155 | +3. Integration with existing error patterns |
| 156 | + |
| 157 | +### Step 4: Context Integration |
| 158 | +1. Auto-detection of GraphAI files |
| 159 | +2. Smart suggestions when GraphAI files are present |
| 160 | +3. Integration with file reading tools |
| 161 | + |
| 162 | +## Integration Points |
| 163 | + |
| 164 | +### With Existing Tools |
| 165 | +- `read_file` for reading GraphAI files |
| 166 | +- `execute_command` for CLI execution patterns |
| 167 | +- `list_files` for discovering GraphAI files |
| 168 | + |
| 169 | +### With Tool Groups |
| 170 | +- Add to `command` group alongside `execute_command` |
| 171 | +- Consider creating a new `graphai` group if more GraphAI tools are planned |
| 172 | + |
| 173 | +### With Error Handling |
| 174 | +- Leverage existing error handling infrastructure |
| 175 | +- Add GraphAI-specific error patterns and suggestions |
| 176 | + |
| 177 | +## Future Enhancements |
| 178 | + |
| 179 | +### Advanced GraphAI Integration |
| 180 | +- Direct npm package usage for better control |
| 181 | +- GraphAI workflow visualization |
| 182 | +- Interactive debugging capabilities |
| 183 | + |
| 184 | +### Workflow Management |
| 185 | +- GraphAI workflow templates |
| 186 | +- Workflow validation and linting |
| 187 | +- Performance monitoring |
| 188 | + |
| 189 | +### AI-Powered Features |
| 190 | +- Automatic workflow generation |
| 191 | +- Error analysis and suggestions |
| 192 | +- Workflow optimization recommendations |
| 193 | + |
| 194 | +## Testing Strategy |
| 195 | + |
| 196 | +### Unit Tests |
| 197 | +- Test file validation logic |
| 198 | +- Test command execution |
| 199 | +- Test error handling |
| 200 | + |
| 201 | +### Integration Tests |
| 202 | +- Test with sample GraphAI files |
| 203 | +- Test error scenarios |
| 204 | +- Test tool registration |
| 205 | + |
| 206 | +### Manual Testing |
| 207 | +- Test with reference GraphAI files |
| 208 | +- Test error handling with invalid files |
| 209 | +- Test integration with other tools |
| 210 | + |
| 211 | +## Success Criteria |
| 212 | + |
| 213 | +1. ✅ Tool successfully registered in Roo Code |
| 214 | +2. ✅ Can execute valid GraphAI YAML/JSON files |
| 215 | +3. ✅ Provides helpful error messages for invalid files |
| 216 | +4. ✅ Integrates seamlessly with existing tool ecosystem |
| 217 | +5. ✅ Follows Roo Code coding patterns and conventions |
| 218 | +6. ✅ Includes comprehensive documentation and tests |
| 219 | + |
| 220 | +## Implementation Notes |
| 221 | + |
| 222 | +- Follow existing patterns from `executeCommandTool.ts` |
| 223 | +- Ensure proper error handling and user feedback |
| 224 | +- Maintain consistency with Roo Code's tool architecture |
| 225 | +- Consider future extensibility for advanced GraphAI features |
| 226 | +- Leverage existing terminal and command execution infrastructure |
| 227 | + |
| 228 | +This implementation will provide a solid foundation for GraphAI workflow execution within Roo Code while maintaining consistency with existing patterns and allowing for future enhancements. |
0 commit comments