ccem 2.81.1 → 2.83.0

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.js +39 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -830,7 +830,7 @@ var __filename = fileURLToPath(import.meta.url);
830
830
  var __dirname = path2.dirname(__filename);
831
831
  var CLAUDE_PROJECTS_DIR = path2.join(os2.homedir(), ".claude", "projects");
832
832
  var CCEM_DIR = path2.join(os2.homedir(), ".ccem");
833
- var CACHE_VERSION = 1;
833
+ var CACHE_VERSION = 2;
834
834
  var getCachePath = () => path2.join(CCEM_DIR, "usage-cache.json");
835
835
  var getPricesPath = () => path2.join(CCEM_DIR, "model-prices.json");
836
836
  async function ensureCcemDir2() {
@@ -1028,6 +1028,7 @@ async function saveCacheAsync(cache) {
1028
1028
  }
1029
1029
  async function parseJSONLFileAsync(filePath, prices, signal) {
1030
1030
  const entries = [];
1031
+ const messageEntryIndexes = /* @__PURE__ */ new Map();
1031
1032
  try {
1032
1033
  const fileStream = fs2.createReadStream(filePath, { encoding: "utf-8" });
1033
1034
  const rl = readline.createInterface({
@@ -1061,11 +1062,23 @@ async function parseJSONLFileAsync(filePath, prices, signal) {
1061
1062
  };
1062
1063
  const price = getModelPrice(model, prices);
1063
1064
  const cost = calculateCost(usage, price);
1064
- entries.push({
1065
+ const statsEntry = {
1065
1066
  timestamp: entry.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
1066
1067
  model,
1067
1068
  usage: { ...usage, cost }
1068
- });
1069
+ };
1070
+ const messageId = entry.message.id;
1071
+ if (typeof messageId === "string" && messageId.length > 0) {
1072
+ const index = messageEntryIndexes.get(messageId);
1073
+ if (index !== void 0) {
1074
+ entries[index] = statsEntry;
1075
+ } else {
1076
+ messageEntryIndexes.set(messageId, entries.length);
1077
+ entries.push(statsEntry);
1078
+ }
1079
+ } else {
1080
+ entries.push(statsEntry);
1081
+ }
1069
1082
  } catch {
1070
1083
  }
1071
1084
  }
@@ -2467,6 +2480,22 @@ import path7 from "path";
2467
2480
  // src/desktopControl.ts
2468
2481
  import fs7 from "fs";
2469
2482
  import path6 from "path";
2483
+ function validateDesktopTaskModel(provider, model) {
2484
+ if (model === void 0 || model === null) return void 0;
2485
+ if (provider !== "codex") {
2486
+ throw new Error("MODEL_PROVIDER_UNSUPPORTED: task model selection is only available for Codex sessions.");
2487
+ }
2488
+ if (typeof model !== "string" || model !== model.trim() || !/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,255}$/.test(model)) {
2489
+ throw new Error("MODEL_INVALID: expected a model identifier (1-256 ASCII letters, digits, dots, underscores, colons, slashes or hyphens; starting with a letter or digit).");
2490
+ }
2491
+ return model;
2492
+ }
2493
+ function requireTaskModelCapability(health) {
2494
+ const capability = health?.capabilities?.taskModelSelection;
2495
+ if (capability?.version !== 1 || !Array.isArray(capability.providers) || !capability.providers.includes("codex")) {
2496
+ throw new Error("MODEL_SELECTION_UNSUPPORTED: this Desktop does not advertise Codex task model selection v1. No session was created.");
2497
+ }
2498
+ }
2470
2499
  var DEFAULT_REQUEST_TIMEOUT_MS = 5e3;
2471
2500
  var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
2472
2501
  var ENDPOINT_UNREACHABLE_CODES = /* @__PURE__ */ new Set([
@@ -6138,12 +6167,16 @@ desktopCmd.command("health").description("Check the running CCEM Desktop control
6138
6167
  const result = await requestDesktopControl("ccem.health");
6139
6168
  outputDesktopResult(result, opts);
6140
6169
  });
6141
- desktopCmd.command("create").description("Create a workspace session in the running CCEM Desktop app").requiredOption("--provider <provider>", "Agent provider: claude or codex").requiredOption("--cwd <path>", "Working directory").requiredOption("--prompt <text>", "Initial prompt").option("--env <name>", "Environment name").option("--perm <mode>", "Permission mode").option("--runtime-perm <mode>", "Runtime permission mode").option("--provider-session-id <id>", "Provider session id to continue").option("--effort <level>", "Codex effort level").option("--open <value>", "Open the created session in Desktop (true/false)").option("--route <key=env>", "Add a session route binding (repeatable)", collectDesktopRoute, []).option("--routes-json <json>", "Session route bindings as a JSON object").option("--json", "Output JSON").action(async function() {
6170
+ desktopCmd.command("create").description("Create a workspace session in the running CCEM Desktop app").requiredOption("--provider <provider>", "Agent provider: claude or codex").requiredOption("--cwd <path>", "Working directory").requiredOption("--prompt <text>", "Initial prompt").option("--env <name>", "Environment name").option("--perm <mode>", "Permission mode").option("--runtime-perm <mode>", "Runtime permission mode").option("--provider-session-id <id>", "Provider session id to continue").option("--effort <level>", "Codex effort level").option("--model <model>", "Requested task model (Codex only)").option("--open <value>", "Open the created session in Desktop (true/false)").option("--route <key=env>", "Add a session route binding (repeatable)", collectDesktopRoute, []).option("--routes-json <json>", "Session route bindings as a JSON object").option("--json", "Output JSON").action(async function() {
6142
6171
  const opts = this.opts();
6143
6172
  const provider = String(opts.provider).trim().toLowerCase();
6144
6173
  if (provider !== "claude" && provider !== "codex") {
6145
6174
  throw new Error("Unsupported provider. Use 'claude' or 'codex'.");
6146
6175
  }
6176
+ const model = validateDesktopTaskModel(provider, opts.model);
6177
+ const descriptor = model === void 0 ? void 0 : resolveDesktopControlDescriptor();
6178
+ const request = descriptor === void 0 ? requestDesktopControl : (method, params) => requestDesktopControl(method, params, descriptor);
6179
+ if (model !== void 0) requireTaskModelCapability(await request("ccem.health"));
6147
6180
  const hasRouteOptions = opts.route.length > 0 || opts.routesJson !== void 0;
6148
6181
  const routes = provider === "claude" ? parseDesktopRoutes(opts.route, opts.routesJson) : void 0;
6149
6182
  if (provider === "codex" && hasRouteOptions) {
@@ -6151,7 +6184,7 @@ desktopCmd.command("create").description("Create a workspace session in the runn
6151
6184
  "Warning: Codex sessions do not support routing; --route and --routes-json were ignored."
6152
6185
  ));
6153
6186
  }
6154
- const result = await requestDesktopControl("ccem.workspace.createSession", {
6187
+ const result = await request("ccem.workspace.createSession", {
6155
6188
  provider,
6156
6189
  cwd: opts.cwd,
6157
6190
  prompt: opts.prompt,
@@ -6160,6 +6193,7 @@ desktopCmd.command("create").description("Create a workspace session in the runn
6160
6193
  runtimePermissionMode: opts.runtimePerm ?? null,
6161
6194
  providerSessionId: opts.providerSessionId ?? null,
6162
6195
  effort: opts.effort ?? null,
6196
+ ...model === void 0 ? {} : { model },
6163
6197
  open: parseOptionalBoolean(opts.open),
6164
6198
  ...routes === void 0 ? {} : { routes }
6165
6199
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccem",
3
- "version": "2.81.1",
3
+ "version": "2.83.0",
4
4
  "type": "module",
5
5
  "description": "Claude Code Environment Manager",
6
6
  "repository": {