@bman654/clodex 2.2.1 → 2.2.2

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.
package/dist/cli.js CHANGED
@@ -218,7 +218,7 @@ import { join } from "path";
218
218
  // package.json
219
219
  var package_default = {
220
220
  name: "@bman654/clodex",
221
- version: "2.2.1",
221
+ version: "2.2.2",
222
222
  publishConfig: {
223
223
  access: "public"
224
224
  },
@@ -4237,6 +4237,17 @@ function sanitizeMessage(message) {
4237
4237
  return line;
4238
4238
  }
4239
4239
 
4240
+ // src/tool-input-sanitize.ts
4241
+ function sanitizeToolInput(input, requiredProps) {
4242
+ const out = /* @__PURE__ */ Object.create(null);
4243
+ for (const [k, v] of Object.entries(input)) {
4244
+ if (v === null) continue;
4245
+ if (Array.isArray(v) && v.length === 0 && !requiredProps?.has(k)) continue;
4246
+ out[k] = v;
4247
+ }
4248
+ return out;
4249
+ }
4250
+
4240
4251
  // src/oauth/responses-websocket.ts
4241
4252
  var RESPONSES_LITE_HEADER = "x-openai-internal-codex-responses-lite";
4242
4253
  var TERMINAL_EVENT_TYPES = /* @__PURE__ */ new Set(["response.completed", "response.failed", "response.incomplete"]);
@@ -4520,9 +4531,27 @@ function continuationMismatchDetails(entry, payload, log12, warnOnGap = false) {
4520
4531
  } : {}
4521
4532
  };
4522
4533
  }
4523
- function continuationMismatchSummary(entry, payload, log12) {
4534
+ function continuationMismatchSummary(entry, payload, log12, mismatchDump = false) {
4524
4535
  const details = continuationMismatchDetails(entry, payload, log12, true);
4525
- return `full_items=${details.fullItems} expected_prefix_items=${details.expectedPrefixItems} first_mismatch=${details.firstMismatch} expected=${details.expectedKind} actual=${details.actualKind}`;
4536
+ let summary = `full_items=${details.fullItems} expected_prefix_items=${details.expectedPrefixItems} first_mismatch=${details.firstMismatch} expected=${details.expectedKind} actual=${details.actualKind}`;
4537
+ if (details.expectedHash || details.actualHash) {
4538
+ summary += ` expected_hash=${details.expectedHash ?? "none"} actual_hash=${details.actualHash ?? "none"}`;
4539
+ if (mismatchDump && log12) {
4540
+ const full = inputArray(payload);
4541
+ const prefix = [...entry.requestInput ?? [], ...entry.expectedAssistant ?? []];
4542
+ const index = details.firstMismatch;
4543
+ log12(`mismatch dump expected[${index}]: ${mismatchDumpLine(prefix, index)}`);
4544
+ log12(`mismatch dump actual[${index}]: ${mismatchDumpLine(full, index)}`);
4545
+ }
4546
+ }
4547
+ return summary;
4548
+ }
4549
+ function mismatchDumpLine(items, index) {
4550
+ if (index >= items.length) return "(absent)";
4551
+ const line = canonicalJson(normalizeToolCallJson(items[index]));
4552
+ const max = 2e3;
4553
+ const marker = " [truncated]";
4554
+ return line.length <= max ? line : line.slice(0, max - marker.length) + marker;
4526
4555
  }
4527
4556
  function canonicalItemStrings(items) {
4528
4557
  return items.map((item) => canonicalJson(normalizeToolCallJson([item])));
@@ -4831,8 +4860,42 @@ function withoutEphemeralFields(item) {
4831
4860
  }
4832
4861
  return out;
4833
4862
  }
4863
+ function requiredToolProps(payload) {
4864
+ const map = /* @__PURE__ */ new Map();
4865
+ const add = (tool3) => {
4866
+ if (!tool3 || typeof tool3 !== "object") return;
4867
+ const record = tool3;
4868
+ if (record.type === "namespace" && Array.isArray(record.tools)) {
4869
+ for (const nested of record.tools) add(nested);
4870
+ return;
4871
+ }
4872
+ if (record.type !== "function" || typeof record.name !== "string") return;
4873
+ const parameters = record.parameters;
4874
+ const required = parameters && typeof parameters === "object" && Array.isArray(parameters.required) ? parameters.required : [];
4875
+ map.set(record.name, new Set(required.filter((p13) => typeof p13 === "string")));
4876
+ };
4877
+ if (Array.isArray(payload.tools)) for (const tool3 of payload.tools) add(tool3);
4878
+ return map;
4879
+ }
4880
+ function sanitizedCallArguments(item, requiredProps) {
4881
+ if (typeof item.arguments !== "string") return item;
4882
+ const raw = item.arguments.trim();
4883
+ let parsed;
4884
+ try {
4885
+ parsed = raw === "" ? {} : JSON.parse(raw);
4886
+ } catch {
4887
+ return item;
4888
+ }
4889
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return item;
4890
+ const required = requiredProps.get(typeof item.name === "string" ? item.name : "");
4891
+ return {
4892
+ ...item,
4893
+ arguments: JSON.stringify(sanitizeToolInput(parsed, required))
4894
+ };
4895
+ }
4834
4896
  function expectedAssistantItems(ctx) {
4835
4897
  const output = [];
4898
+ const requiredProps = requiredToolProps(ctx.originalPayload);
4836
4899
  for (const [, accumulator] of [...ctx.outputByIndex.entries()].sort(([left], [right]) => left - right)) {
4837
4900
  const done = accumulator.done ?? {};
4838
4901
  const type = accumulator.type ?? (typeof done.type === "string" ? done.type : void 0);
@@ -4847,7 +4910,11 @@ function expectedAssistantItems(ctx) {
4847
4910
  output.push({ ...withoutEphemeralFields(done), type: "reasoning", summary });
4848
4911
  continue;
4849
4912
  }
4850
- if (type === "function_call" || type === "custom_tool_call") {
4913
+ if (type === "function_call") {
4914
+ output.push({ ...sanitizedCallArguments(withoutEphemeralFields(done), requiredProps), type });
4915
+ continue;
4916
+ }
4917
+ if (type === "custom_tool_call") {
4851
4918
  output.push({ ...withoutEphemeralFields(done), type });
4852
4919
  }
4853
4920
  }
@@ -5294,6 +5361,7 @@ function createResponsesWebSocketFetch(wsUrl, log12, options = {}) {
5294
5361
  } catch {
5295
5362
  }
5296
5363
  };
5364
+ const mismatchDump = process.env.CLODEX_MISMATCH_DUMP === "1";
5297
5365
  const resolvedOptions = {
5298
5366
  hardTtlMs: options.hardTtlMs ?? RESPONSES_WS_HARD_TTL_MS,
5299
5367
  idleTtlMs: options.idleTtlMs ?? RESPONSES_WS_IDLE_TTL_MS,
@@ -5372,7 +5440,7 @@ function createResponsesWebSocketFetch(wsUrl, log12, options = {}) {
5372
5440
  debug("parallel request using an isolated socket");
5373
5441
  } else if (diagnosticEntry) {
5374
5442
  debug(
5375
- `history mismatch starting an additional chain; retained ${candidates.length} existing head(s) (${continuationMismatchSummary(diagnosticEntry, payload, debug)})`
5443
+ `history mismatch starting an additional chain; retained ${candidates.length} existing head(s) (${continuationMismatchSummary(diagnosticEntry, payload, debug, mismatchDump)})`
5376
5444
  );
5377
5445
  decision = "history_mismatch_new_head";
5378
5446
  } else if (partitionKey) {
@@ -10035,15 +10103,6 @@ function translateMessages(messages, npm, openAiPromptCacheBreakpoints = false)
10035
10103
  }
10036
10104
  return out;
10037
10105
  }
10038
- function sanitizeToolInput(input, requiredProps) {
10039
- const out = {};
10040
- for (const [k, v] of Object.entries(input)) {
10041
- if (v === null) continue;
10042
- if (Array.isArray(v) && v.length === 0 && !requiredProps?.has(k)) continue;
10043
- out[k] = v;
10044
- }
10045
- return out;
10046
- }
10047
10106
  function toolRequiredProps(tools) {
10048
10107
  const map = /* @__PURE__ */ new Map();
10049
10108
  for (const [name, t] of Object.entries(tools ?? {})) {