@openagents-org/agent-connector 0.1.7 → 0.1.9
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/package.json +1 -1
- package/src/daemon.js +51 -18
package/package.json
CHANGED
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}`;
|
|
@@ -521,10 +550,25 @@ class Daemon {
|
|
|
521
550
|
this._sessionContextSent.add(contextKey);
|
|
522
551
|
}
|
|
523
552
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
553
|
+
// Write message to temp file to avoid cmd.exe argument length limits
|
|
554
|
+
const msgFile = path.join(this.config.configDir, `msg-${Date.now()}.tmp`);
|
|
555
|
+
fs.writeFileSync(msgFile, fullMessage, 'utf-8');
|
|
556
|
+
|
|
557
|
+
// Use a small node wrapper to read the message file and exec openclaw
|
|
558
|
+
// This avoids all cmd.exe quoting/length issues
|
|
559
|
+
const wrapperCode = [
|
|
560
|
+
`const msg = require("fs").readFileSync(${JSON.stringify(msgFile)}, "utf-8");`,
|
|
561
|
+
`const cp = require("child_process");`,
|
|
562
|
+
`const args = ${JSON.stringify(['agent', '--local', '--agent', agentId, '--session-id', sessionKey, '--json'])};`,
|
|
563
|
+
`args.push("--message", msg);`,
|
|
564
|
+
`const r = cp.spawnSync(${JSON.stringify(binary)}, args, { stdio: ["ignore", "pipe", "pipe"], env: process.env, shell: true, timeout: 600000 });`,
|
|
565
|
+
`try { require("fs").unlinkSync(${JSON.stringify(msgFile)}); } catch {}`,
|
|
566
|
+
`if (r.stdout) process.stdout.write(r.stdout);`,
|
|
567
|
+
`if (r.stderr) process.stderr.write(r.stderr);`,
|
|
568
|
+
`process.exit(r.status || 0);`,
|
|
569
|
+
].join('\n');
|
|
570
|
+
|
|
571
|
+
this._log(`${agentCfg.name} CLI: ${binary} agent --local --agent ${agentId} ... (via wrapper, msg ${fullMessage.length} chars)`);
|
|
528
572
|
|
|
529
573
|
const spawnEnv = { ...env };
|
|
530
574
|
if (IS_WINDOWS) {
|
|
@@ -534,25 +578,14 @@ class Daemon {
|
|
|
534
578
|
}
|
|
535
579
|
}
|
|
536
580
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
// target and run directly, or use spawn without shell and full path.
|
|
540
|
-
let spawnBinary = binary;
|
|
541
|
-
let spawnArgs = args;
|
|
581
|
+
const spawnBinary = process.execPath; // node
|
|
582
|
+
const spawnArgs = ['-e', wrapperCode];
|
|
542
583
|
const spawnOpts = {
|
|
543
584
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
544
585
|
env: spawnEnv,
|
|
545
|
-
timeout:
|
|
586
|
+
timeout: 620000,
|
|
546
587
|
};
|
|
547
588
|
|
|
548
|
-
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];
|
|
554
|
-
}
|
|
555
|
-
|
|
556
589
|
const proc = spawn(spawnBinary, spawnArgs, spawnOpts);
|
|
557
590
|
let stdout = '';
|
|
558
591
|
let stderr = '';
|