replicas-engine 0.1.342 → 0.1.344

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/src/index.js +80 -3
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -295,7 +295,7 @@ var WORKSPACE_SIZES = ["small", "large"];
295
295
  var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
296
296
 
297
297
  // ../shared/src/e2b.ts
298
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-24-v1";
298
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-25-v2";
299
299
 
300
300
  // ../shared/src/runtime-env.ts
301
301
  function parsePosixEnvFile(content) {
@@ -7577,7 +7577,7 @@ var AspClient = class {
7577
7577
  // src/managers/codex-asp/app-server-process.ts
7578
7578
  var DEFAULT_CODEX_BINARY = "codex";
7579
7579
  var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
7580
- var ENGINE_PACKAGE_VERSION = "0.1.342";
7580
+ var ENGINE_PACKAGE_VERSION = "0.1.344";
7581
7581
  var INITIALIZE_METHOD = "initialize";
7582
7582
  var INITIALIZED_NOTIFICATION = "initialized";
7583
7583
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -9349,9 +9349,20 @@ var CodexAspManager = class extends CodingAgentManager {
9349
9349
  import { mkdir as mkdir11 } from "fs/promises";
9350
9350
  import { dirname as dirname5, join as join15 } from "path";
9351
9351
  import { Agent as CursorAgent } from "@cursor/sdk";
9352
+ var CURSOR_COMPOSER_CONTEXT_WINDOW = 2e5;
9353
+ var CURSOR_CATEGORY_COLORS = {
9354
+ input: "#3eeba3",
9355
+ cacheRead: "#61afef",
9356
+ cacheWrite: "#e5c07b",
9357
+ output: "#56b6c2"
9358
+ };
9359
+ function finiteNumber(value) {
9360
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
9361
+ }
9352
9362
  var CursorManager = class extends CodingAgentManager {
9353
9363
  agent = null;
9354
9364
  activeRun = null;
9365
+ activeModel = null;
9355
9366
  historyFilePath;
9356
9367
  historyFile;
9357
9368
  constructor(options) {
@@ -9398,15 +9409,17 @@ var CursorManager = class extends CodingAgentManager {
9398
9409
  try {
9399
9410
  const agent = await this.ensureAgent(request);
9400
9411
  const message = await this.toCursorMessage(request);
9412
+ const model = request.model ?? DEFAULT_CURSOR_MODEL;
9401
9413
  this.recordHistoryEvent("event_msg", {
9402
9414
  type: "user_message",
9403
9415
  message: request.message
9404
9416
  }, this.historyFile);
9405
9417
  const run = await agent.send(message, {
9406
- model: { id: request.model ?? DEFAULT_CURSOR_MODEL },
9418
+ model: { id: model },
9407
9419
  mode: request.planMode ? "plan" : "agent"
9408
9420
  });
9409
9421
  this.activeRun = run;
9422
+ this.activeModel = model;
9410
9423
  for await (const event of run.stream()) {
9411
9424
  this.recordCursorEvent(event);
9412
9425
  }
@@ -9425,6 +9438,7 @@ var CursorManager = class extends CodingAgentManager {
9425
9438
  }, this.historyFile);
9426
9439
  } finally {
9427
9440
  this.activeRun = null;
9441
+ this.activeModel = null;
9428
9442
  await this.historyFile.flush();
9429
9443
  await this.onTurnComplete();
9430
9444
  }
@@ -9444,6 +9458,69 @@ var CursorManager = class extends CodingAgentManager {
9444
9458
  }
9445
9459
  recordCursorEvent(event) {
9446
9460
  this.recordHistoryEvent(`cursor-${event.type}`, event, this.historyFile);
9461
+ const usage = this.buildCursorContextUsagePayload(event);
9462
+ if (!usage) return;
9463
+ this.historyFile.append(this.emitContextUsage(usage));
9464
+ }
9465
+ buildCursorContextUsagePayload(event) {
9466
+ if (!event || typeof event !== "object" || !("type" in event) || event.type !== "turn-ended") {
9467
+ return null;
9468
+ }
9469
+ const usage = "usage" in event && event.usage && typeof event.usage === "object" ? event.usage : null;
9470
+ if (!usage) return null;
9471
+ const inputTokens = finiteNumber("inputTokens" in usage ? usage.inputTokens : null);
9472
+ const cacheReadTokens = finiteNumber("cacheReadTokens" in usage ? usage.cacheReadTokens : null);
9473
+ const cacheWriteTokens = finiteNumber("cacheWriteTokens" in usage ? usage.cacheWriteTokens : null);
9474
+ const outputTokens = finiteNumber("outputTokens" in usage ? usage.outputTokens : null);
9475
+ const rawTotalTokens = inputTokens + cacheReadTokens + cacheWriteTokens + outputTokens;
9476
+ if (rawTotalTokens <= 0) return null;
9477
+ const maxTokens = CURSOR_COMPOSER_CONTEXT_WINDOW;
9478
+ const { totalTokens, totalProcessedTokens } = clampTokensToWindow(rawTotalTokens, maxTokens);
9479
+ const categories = [
9480
+ {
9481
+ name: "Input",
9482
+ tokens: inputTokens,
9483
+ percentage: percentage(inputTokens, maxTokens),
9484
+ color: CURSOR_CATEGORY_COLORS.input
9485
+ },
9486
+ {
9487
+ name: "Cache read",
9488
+ tokens: cacheReadTokens,
9489
+ percentage: percentage(cacheReadTokens, maxTokens),
9490
+ color: CURSOR_CATEGORY_COLORS.cacheRead
9491
+ },
9492
+ {
9493
+ name: "Cache write",
9494
+ tokens: cacheWriteTokens,
9495
+ percentage: percentage(cacheWriteTokens, maxTokens),
9496
+ color: CURSOR_CATEGORY_COLORS.cacheWrite
9497
+ },
9498
+ {
9499
+ name: "Output",
9500
+ tokens: outputTokens,
9501
+ percentage: percentage(outputTokens, maxTokens),
9502
+ color: CURSOR_CATEGORY_COLORS.output
9503
+ }
9504
+ ].filter((category) => category.tokens > 0);
9505
+ return {
9506
+ provider: "cursor",
9507
+ source: "provider_usage",
9508
+ model: this.activeModel,
9509
+ totalTokens,
9510
+ ...totalProcessedTokens !== void 0 ? { totalProcessedTokens } : {},
9511
+ maxTokens,
9512
+ rawMaxTokens: maxTokens,
9513
+ percentage: percentage(totalTokens, maxTokens),
9514
+ compactsAutomatically: true,
9515
+ categories,
9516
+ apiUsage: {
9517
+ inputTokens,
9518
+ outputTokens,
9519
+ cacheReadInputTokens: cacheReadTokens,
9520
+ cacheCreationInputTokens: cacheWriteTokens
9521
+ },
9522
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
9523
+ };
9447
9524
  }
9448
9525
  };
9449
9526
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.342",
3
+ "version": "0.1.344",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",