MCPcopy Create free account
hub / github.com/agenticsorg/edge-agents / modifyCommand

Function modifyCommand

scripts/sparc2/src/cli/cli.ts:130–176  ·  view source on GitHub ↗

* Modify command action

(
  args: Record<string, any>,
  options: Record<string, any>,
)

Source from the content-addressed store, hash-verified

128 * Modify command action
129 */
130async 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

Callers

nothing calls this directly

Calls 2

initMethod · 0.95
planAndExecuteMethod · 0.95

Tested by

no test coverage detected