@orchagent/cli 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/run.js +62 -22
- package/package.json +1 -1
package/dist/commands/run.js
CHANGED
|
@@ -289,7 +289,9 @@ async function unzipBundle(zipPath, destDir) {
|
|
|
289
289
|
});
|
|
290
290
|
});
|
|
291
291
|
}
|
|
292
|
-
async function executeBundleAgent(config, org, agentName, version, agentData, args) {
|
|
292
|
+
async function executeBundleAgent(config, org, agentName, version, agentData, args, inputOption) {
|
|
293
|
+
// Capture the user's working directory before we change anything
|
|
294
|
+
const userCwd = process.cwd();
|
|
293
295
|
// Create temp directory for the bundle
|
|
294
296
|
const tempDir = path_1.default.join(os_1.default.tmpdir(), `orchagent-${agentName}-${Date.now()}`);
|
|
295
297
|
await promises_1.default.mkdir(tempDir, { recursive: true });
|
|
@@ -331,30 +333,50 @@ async function executeBundleAgent(config, org, agentName, version, agentData, ar
|
|
|
331
333
|
catch {
|
|
332
334
|
throw new errors_1.CliError(`Entrypoint not found: ${entrypoint}`);
|
|
333
335
|
}
|
|
334
|
-
// Build input JSON from args
|
|
335
|
-
// The first arg should be the input (file path or JSON string)
|
|
336
|
+
// Build input JSON from --input option or positional args
|
|
336
337
|
let inputJson = '{}';
|
|
337
|
-
if (
|
|
338
|
+
if (inputOption) {
|
|
339
|
+
// --input was provided, use it directly (should be valid JSON)
|
|
340
|
+
try {
|
|
341
|
+
// Parse and re-stringify to validate JSON
|
|
342
|
+
const parsed = JSON.parse(inputOption);
|
|
343
|
+
// Resolve any relative paths in the input to absolute paths
|
|
344
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
345
|
+
for (const key of ['path', 'directory', 'file_path']) {
|
|
346
|
+
if (typeof parsed[key] === 'string' && !path_1.default.isAbsolute(parsed[key])) {
|
|
347
|
+
parsed[key] = path_1.default.resolve(userCwd, parsed[key]);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
inputJson = JSON.stringify(parsed);
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
throw new errors_1.CliError('Invalid JSON in --input option');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else if (args.length > 0) {
|
|
338
358
|
const firstArg = args[0];
|
|
359
|
+
// Resolve to absolute path relative to user's working directory
|
|
360
|
+
const resolvedArg = path_1.default.isAbsolute(firstArg) ? firstArg : path_1.default.resolve(userCwd, firstArg);
|
|
339
361
|
// Check if it's a file path
|
|
340
362
|
try {
|
|
341
|
-
const stat = await promises_1.default.stat(
|
|
363
|
+
const stat = await promises_1.default.stat(resolvedArg);
|
|
342
364
|
if (stat.isFile()) {
|
|
343
365
|
// Read file content as input
|
|
344
|
-
const fileContent = await promises_1.default.readFile(
|
|
366
|
+
const fileContent = await promises_1.default.readFile(resolvedArg, 'utf-8');
|
|
345
367
|
// Check if it's already JSON
|
|
346
368
|
try {
|
|
347
369
|
JSON.parse(fileContent);
|
|
348
370
|
inputJson = fileContent;
|
|
349
371
|
}
|
|
350
372
|
catch {
|
|
351
|
-
// Wrap as file_path in JSON
|
|
352
|
-
inputJson = JSON.stringify({ file_path:
|
|
373
|
+
// Wrap as file_path in JSON (use absolute path)
|
|
374
|
+
inputJson = JSON.stringify({ file_path: resolvedArg });
|
|
353
375
|
}
|
|
354
376
|
}
|
|
355
377
|
else if (stat.isDirectory()) {
|
|
356
|
-
// Pass directory path
|
|
357
|
-
inputJson = JSON.stringify({ directory:
|
|
378
|
+
// Pass directory path (use absolute path)
|
|
379
|
+
inputJson = JSON.stringify({ directory: resolvedArg });
|
|
358
380
|
}
|
|
359
381
|
}
|
|
360
382
|
catch {
|
|
@@ -364,7 +386,7 @@ async function executeBundleAgent(config, org, agentName, version, agentData, ar
|
|
|
364
386
|
inputJson = firstArg;
|
|
365
387
|
}
|
|
366
388
|
catch {
|
|
367
|
-
// Treat as a simple string input
|
|
389
|
+
// Treat as a simple string input (could be a URL)
|
|
368
390
|
inputJson = JSON.stringify({ input: firstArg });
|
|
369
391
|
}
|
|
370
392
|
}
|
|
@@ -390,29 +412,47 @@ async function executeBundleAgent(config, org, agentName, version, agentData, ar
|
|
|
390
412
|
stderr += text;
|
|
391
413
|
process.stderr.write(text);
|
|
392
414
|
});
|
|
393
|
-
await new Promise((resolve
|
|
415
|
+
const exitCode = await new Promise((resolve) => {
|
|
394
416
|
proc.on('close', (code) => {
|
|
395
|
-
|
|
396
|
-
reject(new errors_1.CliError(`Agent exited with code ${code}`));
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
resolve();
|
|
400
|
-
}
|
|
417
|
+
resolve(code ?? 1);
|
|
401
418
|
});
|
|
402
419
|
proc.on('error', (err) => {
|
|
403
|
-
|
|
420
|
+
process.stderr.write(`Error running agent: ${err.message}\n`);
|
|
421
|
+
resolve(1);
|
|
404
422
|
});
|
|
405
423
|
});
|
|
406
|
-
//
|
|
424
|
+
// Handle output - check for errors in stdout even on failure
|
|
407
425
|
if (stdout.trim()) {
|
|
408
426
|
try {
|
|
409
427
|
const result = JSON.parse(stdout.trim());
|
|
428
|
+
// Check if it's an error response
|
|
429
|
+
if (exitCode !== 0 && typeof result === 'object' && result !== null && 'error' in result) {
|
|
430
|
+
throw new errors_1.CliError(`Agent error: ${result.error}`);
|
|
431
|
+
}
|
|
432
|
+
if (exitCode !== 0) {
|
|
433
|
+
// Non-zero exit but output isn't an error object - show it and fail
|
|
434
|
+
(0, output_1.printJson)(result);
|
|
435
|
+
throw new errors_1.CliError(`Agent exited with code ${exitCode}`);
|
|
436
|
+
}
|
|
437
|
+
// Success - print result
|
|
410
438
|
(0, output_1.printJson)(result);
|
|
411
439
|
}
|
|
412
|
-
catch {
|
|
440
|
+
catch (err) {
|
|
441
|
+
if (err instanceof errors_1.CliError)
|
|
442
|
+
throw err;
|
|
413
443
|
// Not JSON, print as-is
|
|
414
444
|
process.stdout.write(stdout);
|
|
445
|
+
if (exitCode !== 0) {
|
|
446
|
+
throw new errors_1.CliError(`Agent exited with code ${exitCode}`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
else if (exitCode !== 0) {
|
|
451
|
+
// No stdout, check stderr
|
|
452
|
+
if (stderr.trim()) {
|
|
453
|
+
throw new errors_1.CliError(`Agent error: ${stderr.trim()}`);
|
|
415
454
|
}
|
|
455
|
+
throw new errors_1.CliError(`Agent exited with code ${exitCode} (no output)`);
|
|
416
456
|
}
|
|
417
457
|
}
|
|
418
458
|
finally {
|
|
@@ -518,7 +558,7 @@ function registerRunCommand(program) {
|
|
|
518
558
|
return;
|
|
519
559
|
}
|
|
520
560
|
// Execute the bundle-based code agent locally
|
|
521
|
-
await executeBundleAgent(resolved, org, parsed.agent, parsed.version, agentData, args);
|
|
561
|
+
await executeBundleAgent(resolved, org, parsed.agent, parsed.version, agentData, args, options.input);
|
|
522
562
|
return;
|
|
523
563
|
}
|
|
524
564
|
// Check for pip/source-based local execution (legacy)
|