@openagents-org/agent-connector 0.1.7 → 0.1.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/daemon.js +34 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openagents-org/agent-connector",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Agent management CLI and library for OpenAgents — install, configure, and run AI coding agents",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/daemon.js CHANGED
@@ -475,6 +475,35 @@ class Daemon {
475
475
  * Build workspace context preamble for CLI agents.
476
476
  * Teaches the agent about shared workspace APIs (browser, files).
477
477
  */
478
+ /**
479
+ * On Windows, resolve a .cmd shim to the underlying node script
480
+ * so we can spawn directly with node (avoiding cmd.exe argument limits).
481
+ */
482
+ _resolveWindowsBinary(binary, env) {
483
+ const { execSync } = require('child_process');
484
+ try {
485
+ // Find the .cmd shim
486
+ const cmdPath = execSync(`where ${binary}`, {
487
+ encoding: 'utf-8', timeout: 5000, env,
488
+ }).split(/\r?\n/)[0].trim();
489
+
490
+ if (cmdPath.endsWith('.cmd')) {
491
+ // Read the .cmd file to find the target JS script
492
+ const cmdContent = fs.readFileSync(cmdPath, 'utf-8');
493
+ // npm .cmd shims have: "%~dp0\node_modules\...\bin\cli.js" %*
494
+ // or: @IF EXIST "%~dp0\node.exe" ... "%~dp0\node_modules\...\cli.js" %*
495
+ const match = cmdContent.match(/"([^"]+\.js)"/);
496
+ if (match) {
497
+ const jsPath = match[1].replace('%~dp0\\', path.dirname(cmdPath) + '\\');
498
+ return { binary: process.execPath, prefix: [jsPath] };
499
+ }
500
+ }
501
+ } catch {}
502
+
503
+ // Fallback: use cmd.exe /C (may truncate long args)
504
+ return { binary: process.env.COMSPEC || 'cmd.exe', prefix: ['/C', binary] };
505
+ }
506
+
478
507
  _buildWorkspaceContext(agentCfg, network) {
479
508
  const baseUrl = 'https://workspace-endpoint.openagents.org';
480
509
  const h = `Authorization: Bearer ${network.token}`;
@@ -534,9 +563,6 @@ class Daemon {
534
563
  }
535
564
  }
536
565
 
537
- // On Windows, .cmd shims need shell:true but that breaks argument
538
- // quoting. Use execFileSync-style approach: resolve the .cmd to its
539
- // target and run directly, or use spawn without shell and full path.
540
566
  let spawnBinary = binary;
541
567
  let spawnArgs = args;
542
568
  const spawnOpts = {
@@ -546,11 +572,11 @@ class Daemon {
546
572
  };
547
573
 
548
574
  if (IS_WINDOWS) {
549
- // Find the actual .cmd shim and invoke via cmd.exe /C with proper quoting
550
- spawnBinary = process.env.COMSPEC || 'cmd.exe';
551
- // Wrap argument containing spaces in double quotes for cmd.exe
552
- const quotedArgs = args.map((a) => a.includes(' ') ? `"${a}"` : a);
553
- spawnArgs = ['/C', binary, ...quotedArgs];
575
+ // Resolve .cmd shim to actual node script to avoid cmd.exe
576
+ // argument mangling and length limits
577
+ const resolved = this._resolveWindowsBinary(binary, spawnEnv);
578
+ spawnBinary = resolved.binary;
579
+ spawnArgs = [...resolved.prefix, ...args];
554
580
  }
555
581
 
556
582
  const proc = spawn(spawnBinary, spawnArgs, spawnOpts);