@agentproto/driver-agent-cli 2.6.0 → 2.6.2

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.
@@ -713,6 +713,23 @@ function listProcesses() {
713
713
  });
714
714
  });
715
715
  }
716
+ function isWindowsBatchFile(exe, deps) {
717
+ if ((process.platform) !== "win32") return false;
718
+ return /\.(?:bat|cmd)$/i.test(exe);
719
+ }
720
+ function windowsBatchShellOption(exe, deps) {
721
+ if (isWindowsBatchFile(exe)) return { shell: true };
722
+ return {};
723
+ }
724
+ function resolveWindowsBatchSpawn(bin, args, deps) {
725
+ if ((process.platform) !== "win32") return void 0;
726
+ if (!isWindowsBatchFile(bin)) return void 0;
727
+ const stem = basename(bin).replace(/\.(?:bat|cmd)$/i, "");
728
+ if (stem !== "npx" && stem !== "npm") return void 0;
729
+ const script = join(dirname(bin), "node_modules", "npm", "bin", `${stem}-cli.js`);
730
+ if (!(existsSync)(script)) return void 0;
731
+ return { bin: process.execPath, args: [script, ...args] };
732
+ }
716
733
  function defaultToolchainWritePaths() {
717
734
  const home = homedir();
718
735
  return [
@@ -784,12 +801,12 @@ async function wrapAgentCliSpawn(bin, args, opts) {
784
801
 
785
802
  // src/protocol/print-arm.ts
786
803
  function printModelMismatch(requested, reported) {
787
- const basename2 = (id) => {
804
+ const basename3 = (id) => {
788
805
  const noSuffix = id.split("@")[0] ?? id;
789
806
  const segs = noSuffix.split("/");
790
807
  return (segs[segs.length - 1] ?? noSuffix).trim().toLowerCase();
791
808
  };
792
- return basename2(requested) !== basename2(reported);
809
+ return basename3(requested) !== basename3(reported);
793
810
  }
794
811
  var DEFAULT_OUTPUT = ["--output-format", "stream-json"];
795
812
  var DEFAULT_PRE_PROMPT = ["--no-interactive"];
@@ -835,7 +852,12 @@ function createPrintSession(opts) {
835
852
  const child = spawn(execBin, execArgs, {
836
853
  cwd: opts.cwd,
837
854
  env: opts.env,
838
- stdio: ["ignore", "pipe", "pipe"]
855
+ stdio: ["ignore", "pipe", "pipe"],
856
+ // Win32: only reached for a `.cmd`/`.bat` bin that
857
+ // `resolveWindowsBatchSpawn` couldn't rewrite to its node entry
858
+ // (see `win32-spawn.ts` — Node refuses direct batch spawning,
859
+ // CVE-2024-27980, the recap-10 `spawn EINVAL`). POSIX: `{}`.
860
+ ...windowsBatchShellOption(execBin)
839
861
  });
840
862
  activeChild = child;
841
863
  let spawnFailure;
@@ -2042,6 +2064,9 @@ function createAgentCliRuntime(definition) {
2042
2064
  }
2043
2065
  const spawnBin = npxFast?.bin ?? resolvedBin;
2044
2066
  const spawnArgs = npxFast?.args ?? composed.binArgs;
2067
+ const batchRewrite = resolveWindowsBatchSpawn(spawnBin, spawnArgs);
2068
+ const finalBin = batchRewrite?.bin ?? spawnBin;
2069
+ const finalArgs = batchRewrite?.args ?? spawnArgs;
2045
2070
  if (opts?.additionalReadPaths?.length) {
2046
2071
  env.AGENTPROTO_ADDITIONAL_READ_PATHS = JSON.stringify(opts.additionalReadPaths);
2047
2072
  }
@@ -2097,8 +2122,8 @@ function createAgentCliRuntime(definition) {
2097
2122
  if (definition.protocol === "print") {
2098
2123
  const printModel = config?.options?.model;
2099
2124
  return createPrintSession({
2100
- bin: spawnBin,
2101
- baseArgs: spawnArgs,
2125
+ bin: finalBin,
2126
+ baseArgs: finalArgs,
2102
2127
  cwd,
2103
2128
  env,
2104
2129
  ...opts?.resumeSessionId ? { resumeSessionId: opts.resumeSessionId } : {},
@@ -2116,8 +2141,8 @@ function createAgentCliRuntime(definition) {
2116
2141
  const stderrBuf = [];
2117
2142
  if (definition.protocol !== "proprietary") {
2118
2143
  const [execBin, execArgs] = await wrapAgentCliSpawn(
2119
- spawnBin,
2120
- spawnArgs,
2144
+ finalBin,
2145
+ finalArgs,
2121
2146
  {
2122
2147
  mode: opts?.commandSandbox,
2123
2148
  cwd,
@@ -2133,7 +2158,12 @@ function createAgentCliRuntime(definition) {
2133
2158
  cwd,
2134
2159
  env,
2135
2160
  stdio: ["pipe", "pipe", "pipe"],
2136
- signal: opts?.signal
2161
+ signal: opts?.signal,
2162
+ // Win32: a `.cmd`/`.bat` bin that `resolveWindowsBatchSpawn`
2163
+ // couldn't rewrite to its node entry needs the shell — Node
2164
+ // refuses to spawn batch files directly (CVE-2024-27980, the
2165
+ // recap-10 `spawn EINVAL`). POSIX: `{}` — unchanged.
2166
+ ...windowsBatchShellOption(execBin)
2137
2167
  });
2138
2168
  child = spawned;
2139
2169
  let spawnFailure;
@@ -2351,5 +2381,5 @@ function derivedModelRefusalError(definition, requested, reason) {
2351
2381
  }
2352
2382
 
2353
2383
  export { LEGACY_GATEWAY_MODE_IDS, LEGACY_POSTURE_MODE_IDS, RuntimeConfigError, agentCliFrontmatterSchema, agentCliSupportsHostContextIsolation, applyModelCommand, autoAllowPermissionHandler, composeSpawn, createAcpProtocolArm, createAgentCliRuntime, createArmSessionControls, createJcodeMapperState, createMastraMapperState, createPrintSession, createProprietaryProtocolArm, defineAgentCli, hostContextExcludes, inferLegacyModeKind, isLegacyExtractedModeId, isModelSwitchAcknowledgement, mapJcodeEvent, mapMastraEvent, parseModelSwitchCommand, planModePermissionHandler, promptTurn, resolveContinuationStrategy, runtimeConfigSchema, toFileBasedMcpServers };
2354
- //# sourceMappingURL=chunk-SCR7UF3T.mjs.map
2355
- //# sourceMappingURL=chunk-SCR7UF3T.mjs.map
2384
+ //# sourceMappingURL=chunk-E32LOGAM.mjs.map
2385
+ //# sourceMappingURL=chunk-E32LOGAM.mjs.map