@aiden-ade/sandbox-agent 0.1.11 → 0.1.12

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 +184 -40
  2. package/package.json +11 -12
package/dist/index.cjs CHANGED
@@ -7181,6 +7181,128 @@ Prefer relative paths and keep your work scoped to this project.`
7181
7181
  }
7182
7182
  };
7183
7183
 
7184
+ // src/core-agent.ts
7185
+ var import_node_os2 = require("os");
7186
+
7187
+ // src/cli-executable.ts
7188
+ var import_node_fs = require("fs");
7189
+ var import_node_os = require("os");
7190
+ var import_node_path = require("path");
7191
+ var PROVIDER_CLI_COMMANDS = {
7192
+ 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" }
7195
+ };
7196
+ var BACKEND_CLI_COMMANDS = {
7197
+ claude_cli: "claude",
7198
+ codex: "codex",
7199
+ codex_app_server: "codex",
7200
+ gemini_cli: "gemini",
7201
+ gemini: "gemini"
7202
+ };
7203
+ function pathSeparator() {
7204
+ return (0, import_node_os.platform)() === "win32" ? ";" : ":";
7205
+ }
7206
+ function splitPath(pathValue) {
7207
+ if (!pathValue) return [];
7208
+ return pathValue.split(pathSeparator()).filter(Boolean);
7209
+ }
7210
+ function isRunnableFile(path) {
7211
+ if (!(0, import_node_fs.existsSync)(path)) return false;
7212
+ if ((0, import_node_os.platform)() === "win32") return true;
7213
+ try {
7214
+ (0, import_node_fs.accessSync)(path, import_node_fs.constants.X_OK);
7215
+ return true;
7216
+ } catch {
7217
+ return false;
7218
+ }
7219
+ }
7220
+ function windowsCommandCandidates(command, pathExt) {
7221
+ const trimmed = command.trim();
7222
+ if (!trimmed) return [];
7223
+ const hasExtension = /\.[a-z0-9]+$/i.test(trimmed);
7224
+ if (hasExtension) return [trimmed];
7225
+ const extensions = pathExt.split(";").map((ext) => ext.trim()).filter(Boolean);
7226
+ return [trimmed, ...extensions.map((ext) => `${trimmed}${ext}`)];
7227
+ }
7228
+ function augmentCliPath(env) {
7229
+ const home = env.HOME || env.USERPROFILE || (0, import_node_os.homedir)();
7230
+ const isWin = (0, import_node_os.platform)() === "win32";
7231
+ const extraPaths = isWin ? [
7232
+ (0, import_node_path.join)(home, "AppData", "Roaming", "npm"),
7233
+ (0, import_node_path.join)(home, "AppData", "Local", "Programs", "Microsoft", "WindowsApps"),
7234
+ (0, import_node_path.join)(home, ".local", "bin"),
7235
+ "C:\\Program Files\\nodejs",
7236
+ "C:\\Program Files\\Git\\cmd"
7237
+ ] : [
7238
+ (0, import_node_path.join)(home, ".local", "bin"),
7239
+ (0, import_node_path.join)(home, ".local", "node", "bin"),
7240
+ (0, import_node_path.join)(home, ".bun", "bin"),
7241
+ (0, import_node_path.join)(home, ".cargo", "bin"),
7242
+ "/opt/homebrew/bin",
7243
+ "/usr/local/bin"
7244
+ ];
7245
+ const basePath = env.PATH ?? "";
7246
+ const existing = new Set(splitPath(basePath));
7247
+ const missing = extraPaths.filter((dir) => !existing.has(dir));
7248
+ if (missing.length === 0) return env;
7249
+ return {
7250
+ ...env,
7251
+ PATH: missing.length > 0 ? `${missing.join(pathSeparator())}${pathSeparator()}${basePath}` : basePath
7252
+ };
7253
+ }
7254
+ function resolveCliExecutable(command, env = process.env) {
7255
+ const trimmed = command.trim();
7256
+ if (!trimmed) return null;
7257
+ const enriched = augmentCliPath(env);
7258
+ const home = enriched.HOME || enriched.USERPROFILE || (0, import_node_os.homedir)();
7259
+ const isWin = (0, import_node_os.platform)() === "win32";
7260
+ const pathExt = enriched.PATHEXT ?? (isWin ? ".EXE;.CMD;.BAT;.COM" : "");
7261
+ const names = isWin ? windowsCommandCandidates(trimmed, pathExt) : [trimmed];
7262
+ const candidates = [];
7263
+ for (const name of names) {
7264
+ if (name.includes("/") || name.includes("\\")) {
7265
+ candidates.push(name);
7266
+ continue;
7267
+ }
7268
+ for (const dir of splitPath(enriched.PATH)) {
7269
+ candidates.push((0, import_node_path.join)(dir, name));
7270
+ }
7271
+ candidates.push(
7272
+ (0, import_node_path.join)(home, ".local", "bin", name),
7273
+ (0, import_node_path.join)(home, ".local", "node", "bin", name)
7274
+ );
7275
+ if (!isWin) {
7276
+ candidates.push((0, import_node_path.join)("/opt/homebrew/bin", name), (0, import_node_path.join)("/usr/local/bin", name));
7277
+ } else {
7278
+ candidates.push((0, import_node_path.join)(home, "AppData", "Roaming", "npm", name));
7279
+ }
7280
+ }
7281
+ const seen = /* @__PURE__ */ new Set();
7282
+ for (const candidate of candidates) {
7283
+ if (seen.has(candidate)) continue;
7284
+ seen.add(candidate);
7285
+ if (isRunnableFile(candidate)) return candidate;
7286
+ }
7287
+ return null;
7288
+ }
7289
+ function resolveProviderCliCommand(provider) {
7290
+ const spec = PROVIDER_CLI_COMMANDS[provider];
7291
+ const override = process.env[spec.envVar]?.trim();
7292
+ if (override) {
7293
+ return resolveCliExecutable(override) ?? (isRunnableFile(override) ? override : null);
7294
+ }
7295
+ return resolveCliExecutable(spec.command);
7296
+ }
7297
+ function resolveBackendRuntimeCommand(backendKind, env = process.env) {
7298
+ if (!backendKind) return void 0;
7299
+ const command = BACKEND_CLI_COMMANDS[backendKind];
7300
+ 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;
7302
+ const resolved = resolveCliExecutable(envOverride?.trim() || command, env);
7303
+ return resolved ?? void 0;
7304
+ }
7305
+
7184
7306
  // src/core-agent.ts
7185
7307
  var CoreAgent = class _CoreAgent extends BaseMachineAgent {
7186
7308
  childProcess = null;
@@ -7308,18 +7430,23 @@ var CoreAgent = class _CoreAgent extends BaseMachineAgent {
7308
7430
  };
7309
7431
  }
7310
7432
  async buildCliEnvironment() {
7311
- const loginEnv = process.env;
7312
7433
  const env = {};
7313
- for (const [key, value2] of Object.entries(loginEnv)) {
7434
+ for (const [key, value2] of Object.entries(process.env)) {
7314
7435
  if (value2 !== void 0) env[key] = value2;
7315
7436
  }
7316
- const home = env.HOME ?? "/home/user";
7317
- const extraPaths = [`${home}/.local/node/bin`, `${home}/.local/bin`];
7318
- const basePath = env.PATH ?? "";
7319
- const existingSegments = new Set(basePath.split(":").filter(Boolean));
7320
- const missing = extraPaths.filter((p) => !existingSegments.has(p));
7321
- env.PATH = missing.length > 0 ? `${missing.join(":")}:${basePath}` : basePath;
7322
- return env;
7437
+ const augmented = augmentCliPath(env);
7438
+ if ((0, import_node_os2.platform)() !== "win32") {
7439
+ const home = augmented.HOME ?? "/home/user";
7440
+ const extraPaths = [`${home}/.local/node/bin`, `${home}/.local/bin`];
7441
+ const separator = ":";
7442
+ const basePath = augmented.PATH ?? "";
7443
+ const existingSegments = new Set(basePath.split(separator).filter(Boolean));
7444
+ const missing = extraPaths.filter((p) => !existingSegments.has(p));
7445
+ if (missing.length > 0) {
7446
+ augmented.PATH = `${missing.join(separator)}${separator}${basePath}`;
7447
+ }
7448
+ }
7449
+ return augmented;
7323
7450
  }
7324
7451
  buildExtraSystemPromptParts(config) {
7325
7452
  const parts2 = [];
@@ -11142,7 +11269,7 @@ var WSClient = class {
11142
11269
  };
11143
11270
 
11144
11271
  // src/version.ts
11145
- var AGENT_VERSION = "0.1.11";
11272
+ var AGENT_VERSION = "0.1.12";
11146
11273
 
11147
11274
  // src/sandbox.ts
11148
11275
  async function runSandbox(config) {
@@ -11318,44 +11445,44 @@ async function runSandbox(config) {
11318
11445
  }
11319
11446
 
11320
11447
  // src/daemon.ts
11321
- var import_node_fs = require("fs");
11448
+ var import_node_fs2 = require("fs");
11322
11449
  var import_node_http = __toESM(require("http"), 1);
11323
11450
  var import_node_crypto = require("crypto");
11324
- var import_node_os = require("os");
11325
- var import_node_path = require("path");
11451
+ var import_node_os3 = require("os");
11452
+ var import_node_path2 = require("path");
11326
11453
  var import_node_child_process = require("child_process");
11327
11454
  var PRODUCTION_API_URL = "https://api.aiden-platform.com";
11328
11455
  var PRODUCTION_WS_URL = "wss://ws.aiden-platform.com";
11329
11456
  var LOCAL_API_URL = "http://localhost:8400";
11330
11457
  var LOCAL_WS_URL = "ws://localhost:8401";
11331
11458
  function getConfigPath() {
11332
- return process.env.AIDEN_AGENT_CONFIG_PATH ?? (0, import_node_path.join)((0, import_node_os.homedir)(), ".aiden", "agent", "config.json");
11459
+ return process.env.AIDEN_AGENT_CONFIG_PATH ?? (0, import_node_path2.join)((0, import_node_os3.homedir)(), ".aiden", "agent", "config.json");
11333
11460
  }
11334
11461
  function getEndpointDefaultsPath() {
11335
- return process.env.AIDEN_AGENT_ENDPOINTS_PATH ?? (0, import_node_path.join)((0, import_node_path.dirname)(getConfigPath()), "endpoints.json");
11462
+ return process.env.AIDEN_AGENT_ENDPOINTS_PATH ?? (0, import_node_path2.join)((0, import_node_path2.dirname)(getConfigPath()), "endpoints.json");
11336
11463
  }
11337
11464
  function readConfig() {
11338
11465
  const configPath = getConfigPath();
11339
- if (!(0, import_node_fs.existsSync)(configPath)) return {};
11340
- return JSON.parse((0, import_node_fs.readFileSync)(configPath, "utf8"));
11466
+ if (!(0, import_node_fs2.existsSync)(configPath)) return {};
11467
+ return JSON.parse((0, import_node_fs2.readFileSync)(configPath, "utf8"));
11341
11468
  }
11342
11469
  function readEndpointDefaults() {
11343
11470
  const endpointsPath = getEndpointDefaultsPath();
11344
- if (!(0, import_node_fs.existsSync)(endpointsPath)) return {};
11471
+ if (!(0, import_node_fs2.existsSync)(endpointsPath)) return {};
11345
11472
  try {
11346
- return JSON.parse((0, import_node_fs.readFileSync)(endpointsPath, "utf8"));
11473
+ return JSON.parse((0, import_node_fs2.readFileSync)(endpointsPath, "utf8"));
11347
11474
  } catch {
11348
11475
  return {};
11349
11476
  }
11350
11477
  }
11351
11478
  function writeConfig(config) {
11352
11479
  const configPath = getConfigPath();
11353
- (0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(configPath), { recursive: true, mode: 448 });
11354
- (0, import_node_fs.writeFileSync)(configPath, JSON.stringify(config, null, 2), { mode: 384 });
11480
+ (0, import_node_fs2.mkdirSync)((0, import_node_path2.dirname)(configPath), { recursive: true, mode: 448 });
11481
+ (0, import_node_fs2.writeFileSync)(configPath, JSON.stringify(config, null, 2), { mode: 384 });
11355
11482
  }
11356
11483
  function removeConfig() {
11357
11484
  const configPath = getConfigPath();
11358
- if ((0, import_node_fs.existsSync)(configPath)) (0, import_node_fs.rmSync)(configPath, { force: true });
11485
+ if ((0, import_node_fs2.existsSync)(configPath)) (0, import_node_fs2.rmSync)(configPath, { force: true });
11359
11486
  }
11360
11487
  function argValue(args, name) {
11361
11488
  const index = args.indexOf(name);
@@ -11392,20 +11519,26 @@ function sleep(ms) {
11392
11519
  return new Promise((resolve2) => setTimeout(resolve2, ms));
11393
11520
  }
11394
11521
  function commandVersion(command, args = ["--version"]) {
11395
- const result = (0, import_node_child_process.spawnSync)(command, args, { encoding: "utf8", timeout: 3e3 });
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
+ });
11396
11528
  if (result.error || result.status !== 0) return void 0;
11397
11529
  return (result.stdout || result.stderr).split("\n")[0]?.trim() || void 0;
11398
11530
  }
11531
+ function normalizeBackendKind(backendKind) {
11532
+ if (backendKind === "codex") return "codex_app_server";
11533
+ return backendKind;
11534
+ }
11399
11535
  function discoverCapabilities() {
11400
11536
  const now = (/* @__PURE__ */ new Date()).toISOString();
11401
- const providers = [
11402
- { provider: "claude_cli", command: process.env.AIDEN_CLAUDE_PATH ?? "claude" },
11403
- { provider: "codex", command: process.env.AIDEN_CODEX_PATH ?? "codex" },
11404
- { provider: "gemini", command: process.env.AIDEN_GEMINI_PATH ?? "gemini" }
11405
- ];
11537
+ const providers = ["claude_cli", "codex", "gemini"];
11406
11538
  return {
11407
- agents: providers.map(({ provider, command }) => {
11408
- const version = commandVersion(command);
11539
+ agents: providers.map((provider) => {
11540
+ const executable = resolveProviderCliCommand(provider);
11541
+ const version = executable ? commandVersion(executable) : void 0;
11409
11542
  return {
11410
11543
  provider,
11411
11544
  available: Boolean(version),
@@ -11494,7 +11627,7 @@ async function setupDaemon(args) {
11494
11627
  const teamId = argValue(args, "--team") ?? process.env.AIDEN_TEAM_ID;
11495
11628
  const setupToken = argValue(args, "--setup-token") ?? process.env.AIDEN_RUNTIME_SETUP_TOKEN;
11496
11629
  const token = argValue(args, "--token") ?? process.env.AIDEN_SETUP_TOKEN;
11497
- const displayName = argValue(args, "--name") ?? (0, import_node_os.hostname)();
11630
+ const displayName = argValue(args, "--name") ?? (0, import_node_os3.hostname)();
11498
11631
  const legacyLocalMachineId = argValue(args, "--legacy-local-machine-id") ?? process.env.AIDEN_LEGACY_LOCAL_MACHINE_ID;
11499
11632
  const scope = argValue(args, "--scope") ?? process.env.AIDEN_RUNTIME_SCOPE ?? "team";
11500
11633
  if (scope !== "team" && scope !== "user") {
@@ -11515,7 +11648,7 @@ async function setupDaemon(args) {
11515
11648
  ...teamId ? { teamId } : {},
11516
11649
  ...setupToken ? { setupToken } : {},
11517
11650
  displayName,
11518
- hostname: (0, import_node_os.hostname)(),
11651
+ hostname: (0, import_node_os3.hostname)(),
11519
11652
  ...legacyLocalMachineId ? { legacyLocalMachineId } : {},
11520
11653
  runtimeKind: "machine",
11521
11654
  managementKind: "user_managed",
@@ -11525,8 +11658,8 @@ async function setupDaemon(args) {
11525
11658
  visibility: scope,
11526
11659
  capabilities: discoverCapabilities(),
11527
11660
  metadata: {
11528
- platform: (0, import_node_os.platform)(),
11529
- arch: (0, import_node_os.arch)(),
11661
+ platform: (0, import_node_os3.platform)(),
11662
+ arch: (0, import_node_os3.arch)(),
11530
11663
  agentVersion: AGENT_VERSION
11531
11664
  }
11532
11665
  })
@@ -11550,18 +11683,18 @@ async function setupDaemon(args) {
11550
11683
  }
11551
11684
  async function loginWithDeviceCode(args) {
11552
11685
  const { apiUrl, wsUrl, endpointProfile } = resolveEndpoints(args);
11553
- const displayName = argValue(args, "--name") ?? (0, import_node_os.hostname)();
11686
+ const displayName = argValue(args, "--name") ?? (0, import_node_os3.hostname)();
11554
11687
  const maxPolls = Number.parseInt(argValue(args, "--max-polls") ?? "300", 10);
11555
11688
  const start = await fetch(`${apiUrl}/public/runtimes/device-authorizations`, {
11556
11689
  method: "POST",
11557
11690
  headers: { "content-type": "application/json" },
11558
11691
  body: JSON.stringify({
11559
11692
  displayName,
11560
- hostname: (0, import_node_os.hostname)(),
11693
+ hostname: (0, import_node_os3.hostname)(),
11561
11694
  capabilities: discoverCapabilities(),
11562
11695
  metadata: {
11563
- platform: (0, import_node_os.platform)(),
11564
- arch: (0, import_node_os.arch)(),
11696
+ platform: (0, import_node_os3.platform)(),
11697
+ arch: (0, import_node_os3.arch)(),
11565
11698
  agentVersion: AGENT_VERSION
11566
11699
  }
11567
11700
  })
@@ -11657,11 +11790,21 @@ async function startDaemon(args) {
11657
11790
  socket.emit("agent.rejected", { runId: payload.runId, message: "Run is already active" });
11658
11791
  return;
11659
11792
  }
11793
+ const backendKind = normalizeBackendKind(payload.backendKind);
11794
+ const runtimeCommand = resolveBackendRuntimeCommand(backendKind ?? payload.backendKind);
11795
+ if (!runtimeCommand && backendKind) {
11796
+ socket.emit("agent.rejected", {
11797
+ 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.`
11799
+ });
11800
+ return;
11801
+ }
11660
11802
  socket.emit("agent.accepted", { runId: payload.runId });
11661
11803
  pushLog(`accepted run=${payload.runId}`);
11662
11804
  const presenter = new RuntimePresenter(socket, payload.conversationId, payload.runId);
11663
11805
  const agent = new CoreAgent(presenter, {
11664
- backendKind: payload.backendKind
11806
+ backendKind,
11807
+ runtimeCommand
11665
11808
  });
11666
11809
  activeAgents.set(payload.runId, agent);
11667
11810
  const cwd = payload.projectPath ?? process.cwd();
@@ -11670,7 +11813,8 @@ async function startDaemon(args) {
11670
11813
  maxIterations: payload.maxIterations ?? 50,
11671
11814
  teamPath: cwd,
11672
11815
  cwd,
11673
- backendKind: payload.backendKind,
11816
+ backendKind,
11817
+ runtimeCommand,
11674
11818
  agentId: payload.agentId,
11675
11819
  agentPrompt: payload.agentPrompt,
11676
11820
  mode: payload.mode ?? "agent",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiden-ade/sandbox-agent",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "aiden-agent": "./dist/index.cjs"
@@ -11,22 +11,21 @@
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
- },
21
14
  "dependencies": {},
22
15
  "devDependencies": {
23
- "@aiden/agent-core": "workspace:*",
24
- "@aiden/shared": "workspace:*",
25
16
  "socket.io-client": "^4.8.0",
26
17
  "socket.io": "^4.8.0",
27
18
  "@types/node": "^22.0.0",
28
19
  "tsup": "^8.5.1",
29
20
  "tsx": "^4.19.0",
30
- "typescript": "~5.9.3"
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"
31
30
  }
32
- }
31
+ }