@aiden-ade/sandbox-agent 0.1.12 → 0.1.14

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/dist/index.cjs +150 -29
  2. package/package.json +12 -11
package/dist/index.cjs CHANGED
@@ -5304,17 +5304,39 @@ function buildPlanModePrefix(promptText) {
5304
5304
  promptText
5305
5305
  ].join("\n");
5306
5306
  }
5307
- function spawnCli(command, args, context) {
5307
+ function planCliSpawn(command, args, env = process.env) {
5308
5308
  const isWindows = process.platform === "win32";
5309
- return (0, import_child_process.spawn)(command, args, {
5309
+ const comSpec = env.ComSpec ?? process.env.ComSpec ?? "cmd.exe";
5310
+ if (isWindows && /\.(cmd|bat)$/i.test(command)) {
5311
+ return {
5312
+ file: comSpec,
5313
+ args: ["/d", "/s", "/c", command, ...args],
5314
+ shell: false,
5315
+ windowsHide: true
5316
+ };
5317
+ }
5318
+ if (isWindows && /[\\/]/.test(command) && /\.exe$/i.test(command)) {
5319
+ return { file: command, args, shell: false, windowsHide: true };
5320
+ }
5321
+ return {
5322
+ file: command,
5323
+ args,
5324
+ shell: isWindows,
5325
+ windowsHide: isWindows ? true : void 0
5326
+ };
5327
+ }
5328
+ function spawnCli(command, args, context) {
5329
+ const plan = planCliSpawn(command, args, context.env);
5330
+ return (0, import_child_process.spawn)(plan.file, plan.args, {
5310
5331
  cwd: context.cwd,
5311
5332
  env: context.env,
5312
5333
  stdio: ["pipe", "pipe", "pipe"],
5313
- shell: isWindows,
5334
+ shell: plan.shell,
5335
+ windowsHide: plan.windowsHide,
5314
5336
  // Detached on Unix creates a new process group so we can kill the entire tree
5315
5337
  // (CLI tools spawn child processes for tool execution that would otherwise be orphaned).
5316
5338
  // On Windows, detached opens a new console — shell mode handles grouping instead.
5317
- detached: !isWindows
5339
+ detached: process.platform !== "win32"
5318
5340
  });
5319
5341
  }
5320
5342
  function createGenericCliBackend(options) {
@@ -7186,20 +7208,84 @@ var import_node_os2 = require("os");
7186
7208
 
7187
7209
  // src/cli-executable.ts
7188
7210
  var import_node_fs = require("fs");
7211
+ var import_node_child_process = require("child_process");
7189
7212
  var import_node_os = require("os");
7190
7213
  var import_node_path = require("path");
7191
7214
  var PROVIDER_CLI_COMMANDS = {
7192
7215
  claude_cli: { provider: "claude_cli", command: "claude", envVar: "AIDEN_CLAUDE_PATH" },
7193
- codex: { provider: "codex", command: "codex", envVar: "AIDEN_CODEX_PATH" },
7194
- gemini: { provider: "gemini", command: "gemini", envVar: "AIDEN_GEMINI_PATH" }
7216
+ codex_app_server: { provider: "codex_app_server", command: "codex", envVar: "AIDEN_CODEX_PATH" },
7217
+ copilot_cli: { provider: "copilot_cli", command: "copilot", envVar: "AIDEN_COPILOT_PATH" },
7218
+ cursor_agent_cli: { provider: "cursor_agent_cli", command: "cursor-agent", envVar: "AIDEN_CURSOR_AGENT_PATH" },
7219
+ gemini_cli: { provider: "gemini_cli", command: "gemini", envVar: "AIDEN_GEMINI_PATH" },
7220
+ kimi_cli: { provider: "kimi_cli", command: "kimi", envVar: "AIDEN_KIMI_PATH" },
7221
+ opencode_cli: { provider: "opencode_cli", command: "opencode", envVar: "AIDEN_OPENCODE_PATH" },
7222
+ droid_cli: { provider: "droid_cli", command: "droid", envVar: "AIDEN_DROID_PATH" }
7223
+ };
7224
+ var DISCOVERABLE_PROVIDER_KINDS = Object.keys(PROVIDER_CLI_COMMANDS);
7225
+ var PROVIDER_ALIASES = {
7226
+ codex: "codex_app_server",
7227
+ gemini: "gemini_cli"
7195
7228
  };
7196
7229
  var BACKEND_CLI_COMMANDS = {
7197
7230
  claude_cli: "claude",
7198
7231
  codex: "codex",
7199
7232
  codex_app_server: "codex",
7233
+ copilot_cli: "copilot",
7234
+ cursor_agent_cli: "cursor-agent",
7200
7235
  gemini_cli: "gemini",
7201
- gemini: "gemini"
7236
+ gemini: "gemini",
7237
+ kimi_cli: "kimi",
7238
+ opencode_cli: "opencode",
7239
+ droid_cli: "droid"
7202
7240
  };
7241
+ var resolvedCliCache = /* @__PURE__ */ new Map();
7242
+ function getDaemonCliEnvironment() {
7243
+ return augmentCliPath(process.env);
7244
+ }
7245
+ function cacheResolvedCli(command, resolvedPath) {
7246
+ resolvedCliCache.set(command, resolvedPath);
7247
+ }
7248
+ function getCachedResolvedCli(command) {
7249
+ return resolvedCliCache.get(command);
7250
+ }
7251
+ function resolveViaWhere(command, env) {
7252
+ if ((0, import_node_os.platform)() !== "win32") return null;
7253
+ const whereExe = (0, import_node_path.join)(env.SystemRoot ?? process.env.SystemRoot ?? "C:\\Windows", "System32", "where.exe");
7254
+ if (!(0, import_node_fs.existsSync)(whereExe)) return null;
7255
+ const result = (0, import_node_child_process.spawnSync)(whereExe, [command], {
7256
+ encoding: "utf8",
7257
+ env,
7258
+ windowsHide: true,
7259
+ timeout: 3e3
7260
+ });
7261
+ if (result.error || result.status !== 0) return null;
7262
+ for (const line of result.stdout.split(/\r?\n/)) {
7263
+ const trimmed = line.trim();
7264
+ if (!trimmed) continue;
7265
+ if (isRunnableFile(trimmed)) return trimmed;
7266
+ }
7267
+ return null;
7268
+ }
7269
+ function runCliVersionProbe(executable, env, args = ["--version"]) {
7270
+ const isWin = (0, import_node_os.platform)() === "win32";
7271
+ if (isWin && /\.(cmd|bat)$/i.test(executable)) {
7272
+ const comSpec = env.ComSpec ?? process.env.ComSpec ?? "cmd.exe";
7273
+ return (0, import_node_child_process.spawnSync)(comSpec, ["/d", "/s", "/c", executable, ...args], {
7274
+ encoding: "utf8",
7275
+ timeout: 3e3,
7276
+ env,
7277
+ windowsHide: true
7278
+ });
7279
+ }
7280
+ const useShell = isWin && !/[\\/]/.test(executable);
7281
+ return (0, import_node_child_process.spawnSync)(executable, args, {
7282
+ encoding: "utf8",
7283
+ timeout: 3e3,
7284
+ env,
7285
+ shell: useShell,
7286
+ windowsHide: isWin ? true : void 0
7287
+ });
7288
+ }
7203
7289
  function pathSeparator() {
7204
7290
  return (0, import_node_os.platform)() === "win32" ? ";" : ":";
7205
7291
  }
@@ -7251,9 +7337,15 @@ function augmentCliPath(env) {
7251
7337
  PATH: missing.length > 0 ? `${missing.join(pathSeparator())}${pathSeparator()}${basePath}` : basePath
7252
7338
  };
7253
7339
  }
7254
- function resolveCliExecutable(command, env = process.env) {
7340
+ function resolveCliExecutable(command, env = getDaemonCliEnvironment()) {
7255
7341
  const trimmed = command.trim();
7256
7342
  if (!trimmed) return null;
7343
+ const cached = resolvedCliCache.get(trimmed);
7344
+ if (cached && isRunnableFile(cached)) return cached;
7345
+ if ((trimmed.includes("/") || trimmed.includes("\\")) && isRunnableFile(trimmed)) {
7346
+ resolvedCliCache.set(trimmed, trimmed);
7347
+ return trimmed;
7348
+ }
7257
7349
  const enriched = augmentCliPath(env);
7258
7350
  const home = enriched.HOME || enriched.USERPROFILE || (0, import_node_os.homedir)();
7259
7351
  const isWin = (0, import_node_os.platform)() === "win32";
@@ -7282,24 +7374,50 @@ function resolveCliExecutable(command, env = process.env) {
7282
7374
  for (const candidate of candidates) {
7283
7375
  if (seen.has(candidate)) continue;
7284
7376
  seen.add(candidate);
7285
- if (isRunnableFile(candidate)) return candidate;
7377
+ if (isRunnableFile(candidate)) {
7378
+ resolvedCliCache.set(trimmed, candidate);
7379
+ return candidate;
7380
+ }
7381
+ }
7382
+ const viaWhere = resolveViaWhere(trimmed, enriched);
7383
+ if (viaWhere) {
7384
+ resolvedCliCache.set(trimmed, viaWhere);
7385
+ return viaWhere;
7286
7386
  }
7287
7387
  return null;
7288
7388
  }
7289
- function resolveProviderCliCommand(provider) {
7290
- const spec = PROVIDER_CLI_COMMANDS[provider];
7389
+ function normalizeDiscoverableProvider(provider) {
7390
+ const alias = PROVIDER_ALIASES[provider];
7391
+ if (alias) return alias;
7392
+ if (provider in PROVIDER_CLI_COMMANDS) {
7393
+ return provider;
7394
+ }
7395
+ return null;
7396
+ }
7397
+ function resolveProviderCliCommand(provider, env = getDaemonCliEnvironment()) {
7398
+ const normalized = normalizeDiscoverableProvider(provider);
7399
+ if (!normalized) return null;
7400
+ const spec = PROVIDER_CLI_COMMANDS[normalized];
7291
7401
  const override = process.env[spec.envVar]?.trim();
7292
7402
  if (override) {
7293
- return resolveCliExecutable(override) ?? (isRunnableFile(override) ? override : null);
7403
+ const resolved2 = resolveCliExecutable(override, env) ?? (isRunnableFile(override) ? override : null);
7404
+ if (resolved2) cacheResolvedCli(spec.command, resolved2);
7405
+ return resolved2;
7294
7406
  }
7295
- return resolveCliExecutable(spec.command);
7407
+ const resolved = resolveCliExecutable(spec.command, env);
7408
+ if (resolved) cacheResolvedCli(spec.command, resolved);
7409
+ return resolved;
7296
7410
  }
7297
- function resolveBackendRuntimeCommand(backendKind, env = process.env) {
7411
+ function resolveBackendRuntimeCommand(backendKind, env = getDaemonCliEnvironment()) {
7298
7412
  if (!backendKind) return void 0;
7299
7413
  const command = BACKEND_CLI_COMMANDS[backendKind];
7300
7414
  if (!command) return void 0;
7301
- const envOverride = command === "codex" ? env.AIDEN_CODEX_PATH : command === "claude" ? env.AIDEN_CLAUDE_PATH : command === "gemini" ? env.AIDEN_GEMINI_PATH : void 0;
7415
+ const cached = getCachedResolvedCli(command);
7416
+ if (cached && isRunnableFile(cached)) return cached;
7417
+ const spec = Object.values(PROVIDER_CLI_COMMANDS).find((entry) => entry.command === command);
7418
+ const envOverride = spec ? env[spec.envVar] : void 0;
7302
7419
  const resolved = resolveCliExecutable(envOverride?.trim() || command, env);
7420
+ if (resolved) cacheResolvedCli(command, resolved);
7303
7421
  return resolved ?? void 0;
7304
7422
  }
7305
7423
 
@@ -7434,7 +7552,7 @@ var CoreAgent = class _CoreAgent extends BaseMachineAgent {
7434
7552
  for (const [key, value2] of Object.entries(process.env)) {
7435
7553
  if (value2 !== void 0) env[key] = value2;
7436
7554
  }
7437
- const augmented = augmentCliPath(env);
7555
+ const augmented = getDaemonCliEnvironment();
7438
7556
  if ((0, import_node_os2.platform)() !== "win32") {
7439
7557
  const home = augmented.HOME ?? "/home/user";
7440
7558
  const extraPaths = [`${home}/.local/node/bin`, `${home}/.local/bin`];
@@ -11269,7 +11387,7 @@ var WSClient = class {
11269
11387
  };
11270
11388
 
11271
11389
  // src/version.ts
11272
- var AGENT_VERSION = "0.1.12";
11390
+ var AGENT_VERSION = "0.1.14";
11273
11391
 
11274
11392
  // src/sandbox.ts
11275
11393
  async function runSandbox(config) {
@@ -11450,7 +11568,6 @@ var import_node_http = __toESM(require("http"), 1);
11450
11568
  var import_node_crypto = require("crypto");
11451
11569
  var import_node_os3 = require("os");
11452
11570
  var import_node_path2 = require("path");
11453
- var import_node_child_process = require("child_process");
11454
11571
  var PRODUCTION_API_URL = "https://api.aiden-platform.com";
11455
11572
  var PRODUCTION_WS_URL = "wss://ws.aiden-platform.com";
11456
11573
  var LOCAL_API_URL = "http://localhost:8400";
@@ -11519,12 +11636,18 @@ function sleep(ms) {
11519
11636
  return new Promise((resolve2) => setTimeout(resolve2, ms));
11520
11637
  }
11521
11638
  function commandVersion(command, args = ["--version"]) {
11522
- const executable = resolveCliExecutable(command) ?? command;
11523
- const result = (0, import_node_child_process.spawnSync)(executable, args, {
11524
- encoding: "utf8",
11525
- timeout: 3e3,
11526
- env: augmentCliPath(process.env)
11527
- });
11639
+ const env = getDaemonCliEnvironment();
11640
+ const executable = resolveCliExecutable(command, env);
11641
+ if (!executable) return void 0;
11642
+ const result = runCliVersionProbe(executable, env, args);
11643
+ if (result.error || result.status !== 0) return void 0;
11644
+ return (result.stdout || result.stderr).split("\n")[0]?.trim() || void 0;
11645
+ }
11646
+ function commandVersionForProvider(provider) {
11647
+ const env = getDaemonCliEnvironment();
11648
+ const executable = resolveProviderCliCommand(provider, env);
11649
+ if (!executable) return void 0;
11650
+ const result = runCliVersionProbe(executable, env, ["--version"]);
11528
11651
  if (result.error || result.status !== 0) return void 0;
11529
11652
  return (result.stdout || result.stderr).split("\n")[0]?.trim() || void 0;
11530
11653
  }
@@ -11534,11 +11657,9 @@ function normalizeBackendKind(backendKind) {
11534
11657
  }
11535
11658
  function discoverCapabilities() {
11536
11659
  const now = (/* @__PURE__ */ new Date()).toISOString();
11537
- const providers = ["claude_cli", "codex", "gemini"];
11538
11660
  return {
11539
- agents: providers.map((provider) => {
11540
- const executable = resolveProviderCliCommand(provider);
11541
- const version = executable ? commandVersion(executable) : void 0;
11661
+ agents: DISCOVERABLE_PROVIDER_KINDS.map((provider) => {
11662
+ const version = commandVersionForProvider(provider);
11542
11663
  return {
11543
11664
  provider,
11544
11665
  available: Boolean(version),
@@ -11795,7 +11916,7 @@ async function startDaemon(args) {
11795
11916
  if (!runtimeCommand && backendKind) {
11796
11917
  socket.emit("agent.rejected", {
11797
11918
  runId: payload.runId,
11798
- message: `CLI command not found for ${backendKind}. Install it or set the full path via AIDEN_CODEX_PATH / AIDEN_CLAUDE_PATH / AIDEN_GEMINI_PATH.`
11919
+ message: `CLI command not found for ${backendKind}. Install the provider CLI and restart the daemon.`
11799
11920
  });
11800
11921
  return;
11801
11922
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiden-ade/sandbox-agent",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "aiden-agent": "./dist/index.cjs"
@@ -11,21 +11,22 @@
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "dev": "tsx src/index.ts",
17
+ "prepack": "pnpm build",
18
+ "test": "vitest run",
19
+ "type-check": "tsc --noEmit"
20
+ },
14
21
  "dependencies": {},
15
22
  "devDependencies": {
23
+ "@aiden/agent-core": "workspace:*",
24
+ "@aiden/shared": "workspace:*",
16
25
  "socket.io-client": "^4.8.0",
17
26
  "socket.io": "^4.8.0",
18
27
  "@types/node": "^22.0.0",
19
28
  "tsup": "^8.5.1",
20
29
  "tsx": "^4.19.0",
21
- "typescript": "~5.9.3",
22
- "@aiden/agent-core": "0.1.0",
23
- "@aiden/shared": "0.1.0"
24
- },
25
- "scripts": {
26
- "build": "tsup",
27
- "dev": "tsx src/index.ts",
28
- "test": "vitest run",
29
- "type-check": "tsc --noEmit"
30
+ "typescript": "~5.9.3"
30
31
  }
31
- }
32
+ }