|
| 1 | +# AI Agent Integration for GGcode Editor |
| 2 | + |
| 3 | +This document describes the AI agent capabilities that allow the AI to read, analyze, and modify the GGcode editor content. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The AI agent integration provides a set of functions that allow the AI to interact with the GGcode editor, including reading content, making modifications, and analyzing code for optimization opportunities. |
| 8 | + |
| 9 | +## Client-Side Functions |
| 10 | + |
| 11 | +The following functions are available globally for the AI to use: |
| 12 | + |
| 13 | +### Basic Editor Functions |
| 14 | + |
| 15 | +1. `getGGcodeContent()` - Get the entire content of the GGcode editor |
| 16 | +2. `setGGcodeContent(content)` - Replace the entire content of the GGcode editor |
| 17 | +3. `insertGGcodeText(text)` - Insert text at the current cursor position |
| 18 | +4. `replaceSelectedText(newText)` - Replace the currently selected text |
| 19 | +5. `getSelectedText()` - Get the currently selected text |
| 20 | +6. `getCursorPosition()` - Get the current cursor position |
| 21 | + |
| 22 | +### Advanced Editor Functions |
| 23 | + |
| 24 | +1. `getLineContent(lineNumber)` - Get content from a specific line |
| 25 | +2. `getLinesContent(startLine, endLine)` - Get content from a range of lines |
| 26 | +3. `replaceRange(startLine, startColumn, endLine, endColumn, newText)` - Replace content in a specific range |
| 27 | +4. `insertAtPosition(lineNumber, column, text)` - Insert text at a specific position |
| 28 | + |
| 29 | +### Analysis Functions |
| 30 | + |
| 31 | +1. `analyzeGGcode(code)` - Analyze GGcode for optimization opportunities |
| 32 | + |
| 33 | +## Server-Side Commands |
| 34 | + |
| 35 | +The AI can use special commands in its responses to trigger actions: |
| 36 | + |
| 37 | +1. `/ai:write [new content]` - Replace the entire GGcode content |
| 38 | +2. `/ai:insert [text to insert]` - Insert text at the cursor position |
| 39 | +3. `/ai:replace [new text]` - Replace selected text |
| 40 | +4. `/ai:analyze` - Analyze the GGcode |
| 41 | +5. `/ai:getlines [startLine-endLine]` - Get content from specific lines |
| 42 | +6. `/ai:replacerange [startLine,startColumn,endLine,endColumn,newText]` - Replace content in a specific range |
| 43 | +7. `/ai:insertat [lineNumber,column,text]` - Insert text at a specific position |
| 44 | + |
| 45 | +## Usage Examples |
| 46 | + |
| 47 | +### Example 1: Optimizing G-code |
| 48 | + |
| 49 | +``` |
| 50 | +User: "Can you optimize this G-code?" |
| 51 | +AI: "I'll analyze your G-code to identify optimization opportunities. /ai:analyze" |
| 52 | +[Analysis results appear] |
| 53 | +AI: "I've found several areas for optimization. I'll implement changes to improve feed rates and reduce rapid moves. /ai:write [optimized code]" |
| 54 | +``` |
| 55 | + |
| 56 | +### Example 2: Inserting Comments |
| 57 | + |
| 58 | +``` |
| 59 | +User: "Can you add comments to explain what this code does?" |
| 60 | +AI: "I'll add comments to explain the G-code operations. /ai:insertat 1,1,// This is a comment explaining the code\n" |
| 61 | +``` |
| 62 | + |
| 63 | +### Example 3: Replacing a Section |
| 64 | + |
| 65 | +``` |
| 66 | +User: "Can you replace the feed rate in this section?" |
| 67 | +AI: "I'll replace the feed rate in lines 10-15. /ai:replacerange 10,1,15,10,F500" |
| 68 | +``` |
| 69 | + |
| 70 | +## Best Practices |
| 71 | + |
| 72 | +1. Always explain what you're doing before using a command |
| 73 | +2. Show the user the changes you're making |
| 74 | +3. Only make changes when explicitly requested or when it would be helpful to demonstrate a solution |
| 75 | +4. Be careful not to overwrite the user's work without permission |
| 76 | +5. Provide feedback to the user after executing commands |
0 commit comments