@aiden-ade/sandbox-agent 0.1.15 → 0.1.16

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 (42) hide show
  1. package/dist/aiden-system-prompt.d.ts +6 -0
  2. package/dist/aiden-system-prompt.d.ts.map +1 -0
  3. package/dist/aiden-system-prompt.js +6 -0
  4. package/dist/aiden-system-prompt.js.map +1 -0
  5. package/dist/core-agent.d.ts +33 -0
  6. package/dist/core-agent.d.ts.map +1 -0
  7. package/dist/core-agent.js +218 -0
  8. package/dist/core-agent.js.map +1 -0
  9. package/dist/index.cjs +332 -42
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +53 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/runtime-backends.d.ts +2 -0
  15. package/dist/runtime-backends.d.ts.map +1 -0
  16. package/dist/runtime-backends.js +2 -0
  17. package/dist/runtime-backends.js.map +1 -0
  18. package/dist/sandbox.d.ts +25 -0
  19. package/dist/sandbox.d.ts.map +1 -0
  20. package/dist/sandbox.js +185 -0
  21. package/dist/sandbox.js.map +1 -0
  22. package/dist/types.d.ts +6 -0
  23. package/dist/types.d.ts.map +1 -0
  24. package/dist/types.js +6 -0
  25. package/dist/types.js.map +1 -0
  26. package/dist/updater.d.ts +15 -0
  27. package/dist/updater.d.ts.map +1 -0
  28. package/dist/updater.js +50 -0
  29. package/dist/updater.js.map +1 -0
  30. package/dist/version.d.ts +2 -0
  31. package/dist/version.d.ts.map +1 -0
  32. package/dist/version.js +2 -0
  33. package/dist/version.js.map +1 -0
  34. package/dist/web-presenter.d.ts +33 -0
  35. package/dist/web-presenter.d.ts.map +1 -0
  36. package/dist/web-presenter.js +100 -0
  37. package/dist/web-presenter.js.map +1 -0
  38. package/dist/ws-client.d.ts +79 -0
  39. package/dist/ws-client.d.ts.map +1 -0
  40. package/dist/ws-client.js +74 -0
  41. package/dist/ws-client.js.map +1 -0
  42. package/package.json +11 -12
package/dist/index.cjs CHANGED
@@ -36,7 +36,7 @@ var require_XMLHttpRequest = __commonJS({
36
36
  "use strict";
37
37
  var fs = require("fs");
38
38
  var Url = require("url");
39
- var spawn2 = require("child_process").spawn;
39
+ var spawn3 = require("child_process").spawn;
40
40
  module2.exports = XMLHttpRequest3;
41
41
  XMLHttpRequest3.XMLHttpRequest = XMLHttpRequest3;
42
42
  function XMLHttpRequest3(opts) {
@@ -332,7 +332,7 @@ var require_XMLHttpRequest = __commonJS({
332
332
  var syncFile = ".node-xmlhttprequest-sync-" + process.pid;
333
333
  fs.writeFileSync(syncFile, "", "utf8");
334
334
  var execString = "var http = require('http'), https = require('https'), fs = require('fs');var doRequest = http" + (ssl ? "s" : "") + ".request;var options = " + JSON.stringify(options) + ";var responseText = '';var responseData = Buffer.alloc(0);var req = doRequest(options, function(response) {response.on('data', function(chunk) { var data = Buffer.from(chunk); responseText += data.toString('utf8'); responseData = Buffer.concat([responseData, data]);});response.on('end', function() {fs.writeFileSync('" + contentFile + "', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText, data: responseData.toString('base64')}}), 'utf8');fs.unlinkSync('" + syncFile + "');});response.on('error', function(error) {fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');fs.unlinkSync('" + syncFile + "');});}).on('error', function(error) {fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');fs.unlinkSync('" + syncFile + "');});" + (data ? "req.write('" + JSON.stringify(data).slice(1, -1).replace(/'/g, "\\'") + "');" : "") + "req.end();";
335
- var syncProc = spawn2(process.argv[0], ["-e", execString]);
335
+ var syncProc = spawn3(process.argv[0], ["-e", execString]);
336
336
  var statusText;
337
337
  while (fs.existsSync(syncFile)) {
338
338
  }
@@ -645,8 +645,8 @@ var require_common = __commonJS({
645
645
  }
646
646
  return debug12;
647
647
  }
648
- function extend(namespace, delimiter) {
649
- const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
648
+ function extend(namespace, delimiter2) {
649
+ const newDebug = createDebug(this.namespace + (typeof delimiter2 === "undefined" ? ":" : delimiter2) + namespace);
650
650
  newDebug.log = this.log;
651
651
  return newDebug;
652
652
  }
@@ -5218,6 +5218,8 @@ var INTERACTIVE_TOOL_NAMES = /* @__PURE__ */ new Set([
5218
5218
  "exitplanmode",
5219
5219
  "enterplanmode"
5220
5220
  ]);
5221
+ var AIDEN_AGENT_WORKOS_USER_ID_PREFIX = "aiden-agent:";
5222
+ var AIDEN_AGENT_WORKOS_USER_ID_LIKE_PATTERN = `${AIDEN_AGENT_WORKOS_USER_ID_PREFIX}%`;
5221
5223
 
5222
5224
  // ../shared/dist/constants/tasks.js
5223
5225
  var STATUS_OPTIONS = [
@@ -7146,17 +7148,11 @@ function buildTaskLifecyclePrompt(config) {
7146
7148
  ] : [];
7147
7149
  return [
7148
7150
  "## Task Lifecycle",
7149
- `This session is attached to taskId "${taskId}". Keep the task status current by calling the Aiden MCP update_task tool as you move through work phases.`,
7151
+ `This session is attached to taskId "${taskId}".`,
7152
+ `Do not change the task status on your own. The user manages this task's status. Only change it by calling the Aiden MCP update_task tool when the user explicitly asks you to (for example: "move this to review" or "mark it done"). Do not update the status proactively as you move through research, implementation, testing, or review phases.`,
7150
7153
  ...statusLines,
7151
7154
  "",
7152
- "Use exact status IDs from the available statuses when provided. Do not invent status IDs.",
7153
- "Lifecycle mapping:",
7154
- "- Research / discovery / code reading / planning: use the best matching status such as research, discovery, planning, or the first active status.",
7155
- "- Implementation / coding / file edits: use the best matching status such as implementing, in_progress, working, or running.",
7156
- "- Local validation / tests / QA: use the best matching status such as localtesting, local_testing, testing, qa, or validation.",
7157
- "- Ready for human review: use the best matching review status such as in_review or review.",
7158
- "- Done: use only when the requested work is fully complete and validated; otherwise leave it in the review/testing phase.",
7159
- "If no suitable status exists for a phase, leave the current status unchanged rather than forcing an unrelated one."
7155
+ "When the user asks you to change the status, use exact status IDs from the available statuses. Do not invent status IDs. If none of the available statuses clearly matches the request, ask which one they mean instead of guessing."
7160
7156
  ].join("\n");
7161
7157
  }
7162
7158
  var BaseMachineAgent = class _BaseMachineAgent {
@@ -7466,6 +7462,9 @@ var BACKEND_CLI_COMMANDS = {
7466
7462
  droid_cli: "droid",
7467
7463
  supatest_cli: "supatest"
7468
7464
  };
7465
+ var CLI_COMMAND_ALIASES = {
7466
+ kimi: ["kimi-cli"]
7467
+ };
7469
7468
  var resolvedCliCache = /* @__PURE__ */ new Map();
7470
7469
  var cachedLoginShellEnv = null;
7471
7470
  function parseEnvOutput(output) {
@@ -7593,7 +7592,8 @@ function resolveCliExecutable(command, env = getDaemonCliEnvironment()) {
7593
7592
  const home = enriched.HOME || enriched.USERPROFILE || (0, import_node_os.homedir)();
7594
7593
  const isWin = (0, import_node_os.platform)() === "win32";
7595
7594
  const pathExt = enriched.PATHEXT ?? (isWin ? ".EXE;.CMD;.BAT;.COM" : "");
7596
- const names = isWin ? windowsCommandCandidates(trimmed, pathExt) : [trimmed];
7595
+ const commandNames = [trimmed, ...CLI_COMMAND_ALIASES[trimmed] ?? []];
7596
+ const names = commandNames.flatMap((name) => isWin ? windowsCommandCandidates(name, pathExt) : [name]);
7597
7597
  const candidates = [];
7598
7598
  for (const name of names) {
7599
7599
  if (name.includes("/") || name.includes("\\")) {
@@ -11635,7 +11635,7 @@ var WSClient = class {
11635
11635
  };
11636
11636
 
11637
11637
  // src/version.ts
11638
- var AGENT_VERSION = "0.1.15";
11638
+ var AGENT_VERSION = "0.1.16";
11639
11639
 
11640
11640
  // src/sandbox.ts
11641
11641
  async function runSandbox(config) {
@@ -11821,11 +11821,285 @@ async function runSandbox(config) {
11821
11821
  }
11822
11822
 
11823
11823
  // src/daemon.ts
11824
- var import_node_fs2 = require("fs");
11824
+ var import_node_fs3 = require("fs");
11825
11825
  var import_node_http = __toESM(require("http"), 1);
11826
11826
  var import_node_crypto = require("crypto");
11827
+ var import_node_os4 = require("os");
11828
+ var import_node_path3 = require("path");
11829
+
11830
+ // ../shared/dist/node/provider-limits.js
11831
+ var import_node_child_process3 = require("child_process");
11832
+ var import_node_fs2 = require("fs");
11827
11833
  var import_node_os3 = require("os");
11828
11834
  var import_node_path2 = require("path");
11835
+ var CACHE_TTL_MS = 6e4;
11836
+ var cachedLimits = null;
11837
+ function numericValue(value2) {
11838
+ if (typeof value2 === "number" && Number.isFinite(value2))
11839
+ return value2;
11840
+ if (typeof value2 === "string" && value2.trim() && Number.isFinite(Number(value2))) {
11841
+ return Number(value2);
11842
+ }
11843
+ return null;
11844
+ }
11845
+ function splitPath2(value2) {
11846
+ return (value2 ?? "").split(import_node_path2.delimiter).filter(Boolean);
11847
+ }
11848
+ function isExecutableFile(path) {
11849
+ try {
11850
+ (0, import_node_fs2.accessSync)(path, import_node_fs2.constants.X_OK);
11851
+ return true;
11852
+ } catch {
11853
+ return false;
11854
+ }
11855
+ }
11856
+ function augmentCliPath2(env) {
11857
+ const home = env.HOME || (0, import_node_os3.homedir)();
11858
+ const extraPaths = [
11859
+ (0, import_node_path2.join)(home, ".local", "bin"),
11860
+ (0, import_node_path2.join)(home, ".local", "node", "bin"),
11861
+ (0, import_node_path2.join)(home, ".bun", "bin"),
11862
+ (0, import_node_path2.join)(home, ".cargo", "bin"),
11863
+ "/opt/homebrew/bin",
11864
+ "/usr/local/bin"
11865
+ ];
11866
+ const existing = new Set(splitPath2(env.PATH));
11867
+ const missing = extraPaths.filter((path) => !existing.has(path));
11868
+ if (missing.length === 0)
11869
+ return env;
11870
+ return {
11871
+ ...env,
11872
+ PATH: `${missing.join(import_node_path2.delimiter)}${import_node_path2.delimiter}${env.PATH ?? ""}`
11873
+ };
11874
+ }
11875
+ function resolveExecutable(command, env, overrideEnvVar) {
11876
+ const override = env[overrideEnvVar]?.trim();
11877
+ if (override && isExecutableFile(override))
11878
+ return override;
11879
+ for (const dir of splitPath2(env.PATH)) {
11880
+ const candidate = (0, import_node_path2.join)(dir, command);
11881
+ if (isExecutableFile(candidate))
11882
+ return candidate;
11883
+ }
11884
+ return null;
11885
+ }
11886
+ function limitLabel(windowMinutes, fallback) {
11887
+ if (windowMinutes === 5 * 60)
11888
+ return "5h";
11889
+ if (windowMinutes === 7 * 24 * 60)
11890
+ return "Weekly";
11891
+ return fallback;
11892
+ }
11893
+ function windowFromUsedPercent(params) {
11894
+ const usedPercent = Math.max(0, Math.min(100, params.usedPercent));
11895
+ return {
11896
+ label: limitLabel(params.windowMinutes, params.fallbackLabel),
11897
+ remaining: Math.max(0, 100 - usedPercent),
11898
+ limit: 100,
11899
+ usedPercent,
11900
+ ...params.windowMinutes !== null ? { windowMinutes: params.windowMinutes } : {},
11901
+ ...params.resetAt ? { resetAt: params.resetAt } : {},
11902
+ source: params.source
11903
+ };
11904
+ }
11905
+ function codexWindow(raw, fallbackLabel) {
11906
+ if (!raw)
11907
+ return null;
11908
+ const usedPercent = numericValue(raw.usedPercent);
11909
+ if (usedPercent === null)
11910
+ return null;
11911
+ const windowMinutes = numericValue(raw.windowDurationMins);
11912
+ const resetSeconds = numericValue(raw.resetsAt);
11913
+ const resetAt = resetSeconds !== null ? new Date(resetSeconds * 1e3).toISOString() : null;
11914
+ return windowFromUsedPercent({
11915
+ usedPercent,
11916
+ windowMinutes,
11917
+ resetAt,
11918
+ fallbackLabel,
11919
+ source: "codex-cli-rpc"
11920
+ });
11921
+ }
11922
+ function claudeWindow(raw, label, windowMinutes) {
11923
+ if (!raw)
11924
+ return null;
11925
+ const usedPercent = numericValue(raw.utilization);
11926
+ if (usedPercent === null)
11927
+ return null;
11928
+ const resetAt = typeof raw.resets_at === "string" && raw.resets_at.trim() ? raw.resets_at.trim() : null;
11929
+ return windowFromUsedPercent({
11930
+ usedPercent,
11931
+ windowMinutes,
11932
+ resetAt,
11933
+ fallbackLabel: label,
11934
+ source: "claude-oauth"
11935
+ });
11936
+ }
11937
+ async function withTimeout(promise, timeoutMs, fallback) {
11938
+ let timer;
11939
+ try {
11940
+ return await Promise.race([
11941
+ promise,
11942
+ new Promise((resolve2) => {
11943
+ timer = setTimeout(() => resolve2(fallback), timeoutMs);
11944
+ })
11945
+ ]);
11946
+ } finally {
11947
+ if (timer)
11948
+ clearTimeout(timer);
11949
+ }
11950
+ }
11951
+ async function collectCodexLimits(env) {
11952
+ const runtimeEnv = augmentCliPath2(env);
11953
+ const codexCommand = resolveExecutable("codex", runtimeEnv, "AIDEN_CODEX_PATH");
11954
+ if (!codexCommand)
11955
+ return [];
11956
+ return withTimeout(new Promise((resolve2) => {
11957
+ const child = (0, import_node_child_process3.spawn)(codexCommand, ["-s", "read-only", "-a", "untrusted", "app-server"], {
11958
+ env: runtimeEnv,
11959
+ stdio: ["pipe", "pipe", "ignore"]
11960
+ });
11961
+ let nextId = 1;
11962
+ let buffer = "";
11963
+ const pending = /* @__PURE__ */ new Map();
11964
+ const finish = (windows = []) => {
11965
+ pending.clear();
11966
+ if (!child.killed)
11967
+ child.kill();
11968
+ resolve2(windows);
11969
+ };
11970
+ const request = (method, params = {}) => {
11971
+ const id = nextId++;
11972
+ child.stdin.write(`${JSON.stringify({ id, method, params })}
11973
+ `);
11974
+ return new Promise((requestResolve) => {
11975
+ pending.set(id, requestResolve);
11976
+ });
11977
+ };
11978
+ child.on("error", () => finish());
11979
+ child.on("exit", () => finish());
11980
+ child.stdout.on("data", (chunk) => {
11981
+ buffer += chunk.toString("utf8");
11982
+ const lines = buffer.split("\n");
11983
+ buffer = lines.pop() ?? "";
11984
+ for (const line of lines) {
11985
+ const trimmed = line.trim();
11986
+ if (!trimmed)
11987
+ continue;
11988
+ let message;
11989
+ try {
11990
+ message = JSON.parse(trimmed);
11991
+ } catch {
11992
+ continue;
11993
+ }
11994
+ const id = numericValue(message.id);
11995
+ if (id === null)
11996
+ continue;
11997
+ const resolver = pending.get(id);
11998
+ if (!resolver)
11999
+ continue;
12000
+ pending.delete(id);
12001
+ resolver(message.error ? null : message.result);
12002
+ }
12003
+ });
12004
+ void (async () => {
12005
+ try {
12006
+ await request("initialize", {
12007
+ clientInfo: { name: "aiden", version: "runtime" }
12008
+ });
12009
+ child.stdin.write(`${JSON.stringify({ method: "initialized", params: {} })}
12010
+ `);
12011
+ const result = await request("account/rateLimits/read");
12012
+ const windows = [
12013
+ codexWindow(result?.rateLimits?.primary, "Primary"),
12014
+ codexWindow(result?.rateLimits?.secondary, "Weekly")
12015
+ ].filter((window2) => Boolean(window2));
12016
+ finish(windows);
12017
+ } catch {
12018
+ finish();
12019
+ }
12020
+ })();
12021
+ }), 4e3, []);
12022
+ }
12023
+ function readClaudeCredentialsPayload() {
12024
+ const path = (0, import_node_path2.join)((0, import_node_os3.homedir)(), ".claude", ".credentials.json");
12025
+ if ((0, import_node_fs2.existsSync)(path)) {
12026
+ try {
12027
+ return JSON.parse((0, import_node_fs2.readFileSync)(path, "utf8"));
12028
+ } catch {
12029
+ return null;
12030
+ }
12031
+ }
12032
+ if (process.platform !== "darwin")
12033
+ return null;
12034
+ try {
12035
+ const raw = (0, import_node_child_process3.execFileSync)("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
12036
+ if (!raw)
12037
+ return null;
12038
+ return JSON.parse(raw);
12039
+ } catch {
12040
+ return null;
12041
+ }
12042
+ }
12043
+ function readClaudeAccessToken() {
12044
+ const parsed = readClaudeCredentialsPayload();
12045
+ if (!parsed)
12046
+ return null;
12047
+ try {
12048
+ const oauth = parsed.claudeAiOauth;
12049
+ if (!oauth || typeof oauth.accessToken !== "string" || !oauth.accessToken.trim())
12050
+ return null;
12051
+ const expiresAt = numericValue(oauth.expiresAt);
12052
+ if (expiresAt !== null && Date.now() >= expiresAt)
12053
+ return null;
12054
+ return oauth.accessToken.trim();
12055
+ } catch {
12056
+ return null;
12057
+ }
12058
+ }
12059
+ async function collectClaudeLimits() {
12060
+ const token = readClaudeAccessToken();
12061
+ if (!token)
12062
+ return [];
12063
+ return withTimeout((async () => {
12064
+ const response = await fetch("https://api.anthropic.com/api/oauth/usage", {
12065
+ headers: {
12066
+ accept: "application/json",
12067
+ authorization: `Bearer ${token}`,
12068
+ "anthropic-beta": "oauth-2025-04-20",
12069
+ "user-agent": "claude-code/2.1.0"
12070
+ }
12071
+ });
12072
+ if (!response.ok)
12073
+ return [];
12074
+ const body = await response.json();
12075
+ return [
12076
+ claudeWindow(body.five_hour, "5h", 5 * 60),
12077
+ claudeWindow(body.seven_day, "Weekly", 7 * 24 * 60)
12078
+ ].filter((window2) => Boolean(window2));
12079
+ })().catch(() => []), 4e3, []);
12080
+ }
12081
+ async function collectLocalAgentProviderLimits(env = process.env) {
12082
+ if (cachedLimits && Object.keys(cachedLimits.value).length > 0 && Date.now() - cachedLimits.collectedAt < CACHE_TTL_MS) {
12083
+ return cachedLimits.value;
12084
+ }
12085
+ const [codex, claude] = await Promise.all([
12086
+ collectCodexLimits(env),
12087
+ collectClaudeLimits()
12088
+ ]);
12089
+ const limits = {};
12090
+ if (codex.length > 0)
12091
+ limits.codex_app_server = codex;
12092
+ if (claude.length > 0)
12093
+ limits.claude_cli = claude;
12094
+ if (Object.keys(limits).length > 0) {
12095
+ cachedLimits = { value: limits, collectedAt: Date.now() };
12096
+ } else {
12097
+ cachedLimits = null;
12098
+ }
12099
+ return limits;
12100
+ }
12101
+
12102
+ // src/daemon.ts
11829
12103
  var PRODUCTION_API_URL = "https://api.aiden-platform.com";
11830
12104
  var PRODUCTION_WS_URL = "wss://ws.aiden-platform.com";
11831
12105
  var LOCAL_API_URL = "http://localhost:8400";
@@ -11851,33 +12125,33 @@ function describeOccupiedLocalDaemon(port) {
11851
12125
  return `local daemon API port ${port} is already in use. If Aiden desktop is open, it manages the daemon automatically. Quit Aiden desktop or stop the existing daemon before starting another.`;
11852
12126
  }
11853
12127
  function getConfigPath() {
11854
- return process.env.AIDEN_AGENT_CONFIG_PATH ?? (0, import_node_path2.join)((0, import_node_os3.homedir)(), ".aiden", "agent", "config.json");
12128
+ return process.env.AIDEN_AGENT_CONFIG_PATH ?? (0, import_node_path3.join)((0, import_node_os4.homedir)(), ".aiden", "agent", "config.json");
11855
12129
  }
11856
12130
  function getEndpointDefaultsPath() {
11857
- return process.env.AIDEN_AGENT_ENDPOINTS_PATH ?? (0, import_node_path2.join)((0, import_node_path2.dirname)(getConfigPath()), "endpoints.json");
12131
+ return process.env.AIDEN_AGENT_ENDPOINTS_PATH ?? (0, import_node_path3.join)((0, import_node_path3.dirname)(getConfigPath()), "endpoints.json");
11858
12132
  }
11859
12133
  function readConfig() {
11860
12134
  const configPath = getConfigPath();
11861
- if (!(0, import_node_fs2.existsSync)(configPath)) return {};
11862
- return JSON.parse((0, import_node_fs2.readFileSync)(configPath, "utf8"));
12135
+ if (!(0, import_node_fs3.existsSync)(configPath)) return {};
12136
+ return JSON.parse((0, import_node_fs3.readFileSync)(configPath, "utf8"));
11863
12137
  }
11864
12138
  function readEndpointDefaults() {
11865
12139
  const endpointsPath = getEndpointDefaultsPath();
11866
- if (!(0, import_node_fs2.existsSync)(endpointsPath)) return {};
12140
+ if (!(0, import_node_fs3.existsSync)(endpointsPath)) return {};
11867
12141
  try {
11868
- return JSON.parse((0, import_node_fs2.readFileSync)(endpointsPath, "utf8"));
12142
+ return JSON.parse((0, import_node_fs3.readFileSync)(endpointsPath, "utf8"));
11869
12143
  } catch {
11870
12144
  return {};
11871
12145
  }
11872
12146
  }
11873
12147
  function writeConfig(config) {
11874
12148
  const configPath = getConfigPath();
11875
- (0, import_node_fs2.mkdirSync)((0, import_node_path2.dirname)(configPath), { recursive: true, mode: 448 });
11876
- (0, import_node_fs2.writeFileSync)(configPath, JSON.stringify(config, null, 2), { mode: 384 });
12149
+ (0, import_node_fs3.mkdirSync)((0, import_node_path3.dirname)(configPath), { recursive: true, mode: 448 });
12150
+ (0, import_node_fs3.writeFileSync)(configPath, JSON.stringify(config, null, 2), { mode: 384 });
11877
12151
  }
11878
12152
  function removeConfig() {
11879
12153
  const configPath = getConfigPath();
11880
- if ((0, import_node_fs2.existsSync)(configPath)) (0, import_node_fs2.rmSync)(configPath, { force: true });
12154
+ if ((0, import_node_fs3.existsSync)(configPath)) (0, import_node_fs3.rmSync)(configPath, { force: true });
11881
12155
  }
11882
12156
  function argValue(args, name) {
11883
12157
  const index = args.indexOf(name);
@@ -11950,27 +12224,38 @@ function abortActiveAgent(entry) {
11950
12224
  entry.agent.kill();
11951
12225
  }
11952
12226
  function collectRuntimeMetadata() {
11953
- const cpuList = (0, import_node_os3.cpus)();
12227
+ const cpuList = (0, import_node_os4.cpus)();
11954
12228
  const metadata = {
11955
- platform: (0, import_node_os3.platform)(),
11956
- arch: (0, import_node_os3.arch)(),
11957
- osVersion: (0, import_node_os3.release)(),
12229
+ platform: (0, import_node_os4.platform)(),
12230
+ arch: (0, import_node_os4.arch)(),
12231
+ osVersion: (0, import_node_os4.release)(),
11958
12232
  agentVersion: AGENT_VERSION,
11959
- memoryBytes: (0, import_node_os3.totalmem)(),
11960
- memoryFreeBytes: (0, import_node_os3.freemem)()
12233
+ memoryBytes: (0, import_node_os4.totalmem)(),
12234
+ memoryFreeBytes: (0, import_node_os4.freemem)()
11961
12235
  };
11962
12236
  if (cpuList.length > 0) {
11963
12237
  metadata.cpuModel = cpuList[0]?.model;
11964
12238
  metadata.cpuCores = cpuList.length;
11965
12239
  }
11966
12240
  try {
11967
- const disk = (0, import_node_fs2.statfsSync)((0, import_node_os3.homedir)());
12241
+ const disk = (0, import_node_fs3.statfsSync)((0, import_node_os4.homedir)());
11968
12242
  metadata.diskFreeBytes = disk.bavail * disk.bsize;
11969
12243
  metadata.diskTotalBytes = disk.blocks * disk.bsize;
11970
12244
  } catch {
11971
12245
  }
11972
12246
  return metadata;
11973
12247
  }
12248
+ async function collectRuntimeMetadataWithProviderLimits() {
12249
+ const metadata = collectRuntimeMetadata();
12250
+ try {
12251
+ const agentProviderLimits = await collectLocalAgentProviderLimits(getDaemonCliEnvironment());
12252
+ if (Object.keys(agentProviderLimits).length > 0) {
12253
+ metadata.agentProviderLimits = agentProviderLimits;
12254
+ }
12255
+ } catch {
12256
+ }
12257
+ return metadata;
12258
+ }
11974
12259
  var RuntimePresenter = class {
11975
12260
  constructor(socket, conversationId, runId) {
11976
12261
  this.socket = socket;
@@ -12046,7 +12331,7 @@ async function setupDaemon(args) {
12046
12331
  const teamId = argValue(args, "--team") ?? process.env.AIDEN_TEAM_ID;
12047
12332
  const setupToken = argValue(args, "--setup-token") ?? process.env.AIDEN_RUNTIME_SETUP_TOKEN;
12048
12333
  const token = argValue(args, "--token") ?? process.env.AIDEN_SETUP_TOKEN;
12049
- const displayName = argValue(args, "--name") ?? (0, import_node_os3.hostname)();
12334
+ const displayName = argValue(args, "--name") ?? (0, import_node_os4.hostname)();
12050
12335
  const legacyLocalMachineId = argValue(args, "--legacy-local-machine-id") ?? process.env.AIDEN_LEGACY_LOCAL_MACHINE_ID;
12051
12336
  const scope = argValue(args, "--scope") ?? process.env.AIDEN_RUNTIME_SCOPE ?? "team";
12052
12337
  if (scope !== "team" && scope !== "user") {
@@ -12067,7 +12352,7 @@ async function setupDaemon(args) {
12067
12352
  ...teamId ? { teamId } : {},
12068
12353
  ...setupToken ? { setupToken } : {},
12069
12354
  displayName,
12070
- hostname: (0, import_node_os3.hostname)(),
12355
+ hostname: (0, import_node_os4.hostname)(),
12071
12356
  ...legacyLocalMachineId ? { legacyLocalMachineId } : {},
12072
12357
  runtimeKind: "machine",
12073
12358
  managementKind: "user_managed",
@@ -12076,7 +12361,7 @@ async function setupDaemon(args) {
12076
12361
  ownerType: scope,
12077
12362
  visibility: scope,
12078
12363
  capabilities: discoverCapabilities(),
12079
- metadata: collectRuntimeMetadata()
12364
+ metadata: await collectRuntimeMetadataWithProviderLimits()
12080
12365
  })
12081
12366
  });
12082
12367
  if (!response.ok) {
@@ -12098,16 +12383,16 @@ async function setupDaemon(args) {
12098
12383
  }
12099
12384
  async function loginWithDeviceCode(args) {
12100
12385
  const { apiUrl, wsUrl, endpointProfile } = resolveEndpoints(args);
12101
- const displayName = argValue(args, "--name") ?? (0, import_node_os3.hostname)();
12386
+ const displayName = argValue(args, "--name") ?? (0, import_node_os4.hostname)();
12102
12387
  const maxPolls = Number.parseInt(argValue(args, "--max-polls") ?? "300", 10);
12103
12388
  const start = await fetch(`${apiUrl}/public/runtimes/device-authorizations`, {
12104
12389
  method: "POST",
12105
12390
  headers: { "content-type": "application/json" },
12106
12391
  body: JSON.stringify({
12107
12392
  displayName,
12108
- hostname: (0, import_node_os3.hostname)(),
12393
+ hostname: (0, import_node_os4.hostname)(),
12109
12394
  capabilities: discoverCapabilities(),
12110
- metadata: collectRuntimeMetadata()
12395
+ metadata: await collectRuntimeMetadataWithProviderLimits()
12111
12396
  })
12112
12397
  });
12113
12398
  if (!start.ok) {
@@ -12157,7 +12442,7 @@ async function startDaemon(args) {
12157
12442
  }
12158
12443
  const activeAgents = /* @__PURE__ */ new Map();
12159
12444
  const currentCapabilities = () => discoverCapabilities();
12160
- const currentMetadata = () => collectRuntimeMetadata();
12445
+ const currentMetadata = () => collectRuntimeMetadataWithProviderLimits();
12161
12446
  const recentLogs = [];
12162
12447
  const pushLog = (message) => {
12163
12448
  recentLogs.push(`${(/* @__PURE__ */ new Date()).toISOString()} ${message}`);
@@ -12179,12 +12464,17 @@ async function startDaemon(args) {
12179
12464
  extraHeaders: { "ngrok-skip-browser-warning": "1" }
12180
12465
  });
12181
12466
  const heartbeat = setInterval(() => {
12182
- if (socket.connected) socket.emit("runtime.heartbeat", { capabilities: currentCapabilities(), metadata: currentMetadata() });
12467
+ if (!socket.connected) return;
12468
+ void currentMetadata().then((metadata) => {
12469
+ socket.emit("runtime.heartbeat", { capabilities: currentCapabilities(), metadata });
12470
+ });
12183
12471
  }, 15e3);
12184
12472
  socket.on("connect", () => {
12185
12473
  pushLog(`connected runtime=${runtimeId}`);
12186
12474
  console.info("[aiden-agent] Daemon connected", { runtimeId, wsUrl, version: AGENT_VERSION });
12187
- socket.emit("runtime.hello", { capabilities: currentCapabilities(), metadata: currentMetadata() });
12475
+ void currentMetadata().then((metadata) => {
12476
+ socket.emit("runtime.hello", { capabilities: currentCapabilities(), metadata });
12477
+ });
12188
12478
  });
12189
12479
  let lastConnectErrorLogAt = 0;
12190
12480
  socket.on("connect_error", (error) => {
@@ -12532,7 +12822,7 @@ async function printDoctor(args = []) {
12532
12822
  authorization: `Bearer ${config.runtimeToken}`,
12533
12823
  "content-type": "application/json"
12534
12824
  },
12535
- body: JSON.stringify({ capabilities, metadata: collectRuntimeMetadata() })
12825
+ body: JSON.stringify({ capabilities, metadata: await collectRuntimeMetadataWithProviderLimits() })
12536
12826
  });
12537
12827
  if (!response.ok) {
12538
12828
  syncError = `${response.status} ${await response.text()}`;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Aiden Sandbox Agent
3
+ * Runs inside E2B sandbox, connects to WS server, executes CoreAgent.
4
+ */
5
+ import { runSandbox } from "./sandbox.js";
6
+ import { AGENT_VERSION } from "./version.js";
7
+ // Support `aiden-agent --version` for version detection without starting the agent
8
+ if (process.argv.includes("--version")) {
9
+ process.stdout.write(`${AGENT_VERSION}\n`);
10
+ process.exit(0);
11
+ }
12
+ const wsUrl = process.env.AIDEN_WS_URL;
13
+ const sessionId = process.env.AIDEN_SESSION_ID;
14
+ const taskId = process.env.AIDEN_TASK_ID;
15
+ const sessionToken = process.env.AIDEN_SESSION_TOKEN;
16
+ const task = process.env.AIDEN_TASK;
17
+ const teamId = process.env.AIDEN_TEAM_ID || undefined;
18
+ const projectPath = process.env.AIDEN_PROJECT_PATH || "/home/user/workspace";
19
+ const backendKind = process.env.AIDEN_BACKEND_KIND || "claude_cli";
20
+ const agentId = process.env.AIDEN_AGENT_ID || undefined;
21
+ const agentPrompt = process.env.AIDEN_AGENT_PROMPT || undefined;
22
+ const mode = process.env.AIDEN_MODE || "agent";
23
+ const model = process.env.AIDEN_MODEL;
24
+ const contextWindow = process.env.AIDEN_CONTEXT_WINDOW || undefined;
25
+ const effortLevel = process.env.AIDEN_EFFORT_LEVEL || undefined;
26
+ const providerSessionId = process.env.AIDEN_PROVIDER_SESSION_ID || undefined;
27
+ if (!wsUrl || !sessionId || !taskId || !sessionToken || task == null) {
28
+ console.error("[aiden-agent] Missing required env vars: AIDEN_WS_URL, AIDEN_SESSION_ID, AIDEN_TASK_ID, AIDEN_SESSION_TOKEN, AIDEN_TASK");
29
+ process.exit(1);
30
+ }
31
+ console.info("[aiden-agent] Starting", { sessionId, taskId, projectPath, backendKind, agentId, mode, model, version: AGENT_VERSION });
32
+ runSandbox({
33
+ wsUrl,
34
+ sessionId,
35
+ taskId,
36
+ sessionToken,
37
+ task,
38
+ teamId,
39
+ projectPath,
40
+ backendKind,
41
+ agentId,
42
+ agentPrompt,
43
+ mode,
44
+ model,
45
+ contextWindow,
46
+ effortLevel,
47
+ providerSessionId,
48
+ maxIterations: 50,
49
+ }).catch((error) => {
50
+ console.error("[aiden-agent] Fatal error:", error);
51
+ process.exit(1);
52
+ });
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,mFAAmF;AACnF,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;IACvC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,aAAa,IAAI,CAAC,CAAC;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;AACvC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;AAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AACzC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;AACrD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;AACpC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,SAAS,CAAC;AACtD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,sBAAsB,CAAC;AAC7E,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,YAAY,CAAC;AACnE,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,SAAS,CAAC;AACxD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,SAAS,CAAC;AAChE,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,OAAO,CAAC;AAC/C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;AACtC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,SAAS,CAAC;AACpE,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,SAAS,CAAC;AAChE,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,SAAS,CAAC;AAE7E,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,IAAI,CAAC,YAAY,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;IACrE,OAAO,CAAC,KAAK,CAAC,yHAAyH,CAAC,CAAC;IACzI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;AAEtI,UAAU,CAAC;IACT,KAAK;IACL,SAAS;IACT,MAAM;IACN,YAAY;IACZ,IAAI;IACJ,MAAM;IACN,WAAW;IACX,WAAW;IACX,OAAO;IACP,WAAW;IACX,IAAI;IACJ,KAAK;IACL,aAAa;IACb,WAAW;IACX,iBAAiB;IACjB,aAAa,EAAE,EAAE;CAClB,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "@aiden/agent-core";
2
+ //# sourceMappingURL=runtime-backends.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-backends.d.ts","sourceRoot":"","sources":["../src/runtime-backends.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "@aiden/agent-core";
2
+ //# sourceMappingURL=runtime-backends.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-backends.js","sourceRoot":"","sources":["../src/runtime-backends.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,25 @@
1
+ export interface SandboxConfig {
2
+ wsUrl: string;
3
+ sessionId: string;
4
+ taskId: string;
5
+ teamId?: string;
6
+ sessionToken: string;
7
+ task: string;
8
+ projectPath: string;
9
+ backendKind?: string;
10
+ agentId?: string;
11
+ agentPrompt?: string;
12
+ mode?: string;
13
+ model?: string;
14
+ contextWindow?: string | null;
15
+ effortLevel?: string | null;
16
+ providerSessionId?: string;
17
+ currentUser?: {
18
+ id: string;
19
+ name: string | null;
20
+ email: string;
21
+ };
22
+ maxIterations?: number;
23
+ }
24
+ export declare function runSandbox(config: SandboxConfig): Promise<void>;
25
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAsB,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CA4LrE"}