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

Function executeCommand

scripts/sparc2/src/cli/cli.ts:181–243  ·  view source on GitHub ↗

* Execute command action

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

Source from the content-addressed store, hash-verified

179 * Execute command action
180 */
181async function executeCommand(
182 args: Record<string, any>,
183 options: Record<string, any>,
184): Promise<void> {
185 try {
186 // Read file content if file is provided
187 let code: string;
188 if (options.file) {
189 code = await Deno.readTextFile(options.file);
190 } else if (options.code) {
191 code = options.code;
192 } else {
193 throw new Error("Either --file or --code is required");
194 }
195
196 // Determine language from file extension if not specified
197 let language = options.language;
198 if (!language && options.file) {
199 const extension = options.file.split(".").pop()?.toLowerCase();
200 if (extension === "py") {
201 language = "python";
202 } else if (extension === "js") {
203 language = "javascript";
204 } else if (extension === "ts") {
205 language = "typescript";
206 }
207 }
208
209 // Execute code
210 const result = await executeCode(code, {
211 language,
212 stream: options.stream,
213 timeout: options.timeout,
214 });
215
216 // Output results
217 console.log("Execution Results:");
218 console.log(result.text);
219
220 if (result.logs.stdout.length > 0) {
221 console.log("\nStandard Output:");
222 for (const line of result.logs.stdout) {
223 console.log(line);
224 }
225 }
226
227 if (result.logs.stderr.length > 0) {
228 console.error("\nStandard Error:");
229 for (const line of result.logs.stderr) {
230 console.error(line);
231 }
232 }
233
234 if (result.error) {
235 console.error("\nError:", result.error.value);
236 Deno.exit(1);
237 }
238 } catch (error: unknown) {

Callers

nothing calls this directly

Calls 1

executeCodeFunction · 0.90

Tested by

no test coverage detected