@openagents-org/agent-connector 0.1.8 → 0.1.10
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 +33 -15
package/package.json
CHANGED
package/src/daemon.js
CHANGED
|
@@ -550,10 +550,36 @@ class Daemon {
|
|
|
550
550
|
this._sessionContextSent.add(contextKey);
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
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 path = require("path");`,
|
|
563
|
+
`const args = ${JSON.stringify(['agent', '--local', '--agent', agentId, '--session-id', sessionKey, '--json'])};`,
|
|
564
|
+
`args.push("--message", msg);`,
|
|
565
|
+
// Resolve the .cmd shim to find the actual JS entry point
|
|
566
|
+
`let bin = ${JSON.stringify(binary)};`,
|
|
567
|
+
`try {`,
|
|
568
|
+
` const w = cp.execSync("where " + bin, { encoding: "utf-8", timeout: 5000 }).split(/\\r?\\n/)[0].trim();`,
|
|
569
|
+
` if (w.endsWith(".cmd")) {`,
|
|
570
|
+
` const c = require("fs").readFileSync(w, "utf-8");`,
|
|
571
|
+
` const m = c.match(/"([^"]+\\.js)"/);`,
|
|
572
|
+
` if (m) { args.unshift(m[1].replace("%~dp0\\\\", path.dirname(w) + "\\\\")); bin = process.execPath; }`,
|
|
573
|
+
` }`,
|
|
574
|
+
`} catch {}`,
|
|
575
|
+
`const r = cp.spawnSync(bin, args, { stdio: ["ignore", "pipe", "pipe"], env: process.env, timeout: 600000 });`,
|
|
576
|
+
`try { require("fs").unlinkSync(${JSON.stringify(msgFile)}); } catch {}`,
|
|
577
|
+
`if (r.stdout) process.stdout.write(r.stdout);`,
|
|
578
|
+
`if (r.stderr) process.stderr.write(r.stderr);`,
|
|
579
|
+
`process.exit(r.status || 0);`,
|
|
580
|
+
].join('\n');
|
|
581
|
+
|
|
582
|
+
this._log(`${agentCfg.name} CLI: ${binary} agent --local --agent ${agentId} ... (via wrapper, msg ${fullMessage.length} chars)`);
|
|
557
583
|
|
|
558
584
|
const spawnEnv = { ...env };
|
|
559
585
|
if (IS_WINDOWS) {
|
|
@@ -563,22 +589,14 @@ class Daemon {
|
|
|
563
589
|
}
|
|
564
590
|
}
|
|
565
591
|
|
|
566
|
-
|
|
567
|
-
|
|
592
|
+
const spawnBinary = process.execPath; // node
|
|
593
|
+
const spawnArgs = ['-e', wrapperCode];
|
|
568
594
|
const spawnOpts = {
|
|
569
595
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
570
596
|
env: spawnEnv,
|
|
571
|
-
timeout:
|
|
597
|
+
timeout: 620000,
|
|
572
598
|
};
|
|
573
599
|
|
|
574
|
-
if (IS_WINDOWS) {
|
|
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];
|
|
580
|
-
}
|
|
581
|
-
|
|
582
600
|
const proc = spawn(spawnBinary, spawnArgs, spawnOpts);
|
|
583
601
|
let stdout = '';
|
|
584
602
|
let stderr = '';
|