* Modify command action
( args: Record<string, any>, options: Record<string, any>, )
| 128 | * Modify command action |
| 129 | */ |
| 130 | async function modifyCommand( |
| 131 | args: Record<string, any>, |
| 132 | options: Record<string, any>, |
| 133 | ): Promise<void> { |
| 134 | try { |
| 135 | // Parse file paths |
| 136 | const filePaths = options.files.split(",").map((f: string) => f.trim()); |
| 137 | |
| 138 | // Read file contents |
| 139 | const files: FileToProcess[] = []; |
| 140 | for (const path of filePaths) { |
| 141 | const content = await Deno.readTextFile(path); |
| 142 | files.push({ |
| 143 | path, |
| 144 | originalContent: content, |
| 145 | }); |
| 146 | } |
| 147 | |
| 148 | // Read suggestions |
| 149 | let suggestions = options.suggestions; |
| 150 | if (suggestions.endsWith(".txt") || suggestions.endsWith(".md")) { |
| 151 | suggestions = await Deno.readTextFile(suggestions); |
| 152 | } |
| 153 | |
| 154 | // Initialize agent |
| 155 | const agent = new SPARC2Agent({ |
| 156 | model: options.model, |
| 157 | mode: options.mode, |
| 158 | diffMode: options["diff-mode"], |
| 159 | processing: options.processing, |
| 160 | }); |
| 161 | await agent.init(); |
| 162 | |
| 163 | // Apply changes |
| 164 | const results = await agent.planAndExecute(suggestions, files); |
| 165 | |
| 166 | // Output results |
| 167 | console.log(`Modification completed. Modified ${results.length} files:`); |
| 168 | for (const result of results) { |
| 169 | console.log(`- ${result.path} ${result.commitHash ? `(commit: ${result.commitHash})` : ""}`); |
| 170 | } |
| 171 | } catch (error: unknown) { |
| 172 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 173 | console.error(`Error: ${errorMessage}`); |
| 174 | Deno.exit(1); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Execute command action |
nothing calls this directly
no test coverage detected