@wrongstack/core 0.8.2 → 0.8.5

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.
@@ -11,7 +11,7 @@ import { J as JournalEntry } from '../goal-store-C7jcumEh.js';
11
11
  import { A as AgentFactory } from '../agent-subagent-runner-Cav3yEJM.js';
12
12
  import { f as DispatchClassifier, d as DefaultMultiAgentCoordinator } from '../multi-agent-coordinator-IQKrMfXz.js';
13
13
  import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-CxuWrsKK.js';
14
- import { a as WstackPaths } from '../wstack-paths-gCrJ631C.js';
14
+ import { a as WstackPaths } from '../wstack-paths-Bxik3CsK.js';
15
15
  import '../retry-policy-OwtKNxo8.js';
16
16
  import '../models-registry-BcYJDKLm.js';
17
17
  import '../logger-DDd5C--Z.js';
@@ -204,10 +204,16 @@ declare class AutoCompactionMiddleware {
204
204
  private readonly failureMode;
205
205
  private readonly policyProvider?;
206
206
  /**
207
- * Overhead factor applied to the rough message-token estimate to produce a
208
- * figure comparable to the real API request size (system prompt + tool defs).
209
- * Without this factor, raw message tokens undercount real load by 15-50% in
210
- * short conversations, causing premature compaction triggers.
207
+ * Calibration factor applied to the estimator output. The estimator is now
208
+ * expected to already include messages + system prompt + tool definitions
209
+ * (see `estimateRequestTokens.total`), so no overhead boost is needed. Kept
210
+ * as a constant so a future calibration against real provider tokenization
211
+ * (BPE vs the chars/3.5 rough estimator) can dial this without touching the
212
+ * threshold-check math.
213
+ *
214
+ * Historical note: was 1.3 when the estimator only counted messages — that
215
+ * double-counted system+tools once the estimator was upgraded, firing
216
+ * compaction ~30% earlier than intended (e.g. real 56% load showed as 73%).
211
217
  */
212
218
  private static readonly OVERHEAD_FACTOR;
213
219
  /**
@@ -1019,12 +1019,18 @@ var AutoCompactionMiddleware = class _AutoCompactionMiddleware {
1019
1019
  failureMode;
1020
1020
  policyProvider;
1021
1021
  /**
1022
- * Overhead factor applied to the rough message-token estimate to produce a
1023
- * figure comparable to the real API request size (system prompt + tool defs).
1024
- * Without this factor, raw message tokens undercount real load by 15-50% in
1025
- * short conversations, causing premature compaction triggers.
1022
+ * Calibration factor applied to the estimator output. The estimator is now
1023
+ * expected to already include messages + system prompt + tool definitions
1024
+ * (see `estimateRequestTokens.total`), so no overhead boost is needed. Kept
1025
+ * as a constant so a future calibration against real provider tokenization
1026
+ * (BPE vs the chars/3.5 rough estimator) can dial this without touching the
1027
+ * threshold-check math.
1028
+ *
1029
+ * Historical note: was 1.3 when the estimator only counted messages — that
1030
+ * double-counted system+tools once the estimator was upgraded, firing
1031
+ * compaction ~30% earlier than intended (e.g. real 56% load showed as 73%).
1026
1032
  */
1027
- static OVERHEAD_FACTOR = 1.3;
1033
+ static OVERHEAD_FACTOR = 1;
1028
1034
  /**
1029
1035
  * Once a compaction attempt reduces nothing (preserveK protects everything,
1030
1036
  * no oversized tool_results remain to elide), retrying on every iteration
@@ -1234,7 +1240,7 @@ var ToolExecutor = class {
1234
1240
  return { result, tool, durationMs: Date.now() - start };
1235
1241
  }
1236
1242
  if (hasMalformedArguments(use.input)) {
1237
- const result = this.malformedInputResult(use);
1243
+ const result = this.malformedInputResult(use, extractMalformedRaw(use.input));
1238
1244
  budget = this.decrementBudget(result, budget);
1239
1245
  return { result, tool, durationMs: Date.now() - start };
1240
1246
  }
@@ -1441,11 +1447,18 @@ var ToolExecutor = class {
1441
1447
  is_error: true
1442
1448
  };
1443
1449
  }
1444
- malformedInputResult(use) {
1450
+ malformedInputResult(use, raw) {
1451
+ let content = `Tool "${use.name}" received arguments that were not a valid JSON object, so they could not be parsed. Re-issue the call with the arguments encoded as a single well-formed JSON object matching the tool's input schema.`;
1452
+ if (raw) {
1453
+ const max = 800;
1454
+ const excerpt = raw.length > max ? `${raw.slice(0, max)}\u2026 (truncated, ${raw.length} chars total)` : raw;
1455
+ content += ` Common cause: a string field (e.g. code in old_string/new_string) contains literal newlines, quotes, or backslashes that must be JSON-escaped, or the payload was cut off mid-stream. The raw arguments received were:
1456
+ ${excerpt}`;
1457
+ }
1445
1458
  return {
1446
1459
  type: "tool_result",
1447
1460
  tool_use_id: use.id,
1448
- content: `Tool "${use.name}" received arguments that were not a valid JSON object, so they could not be parsed. Re-issue the call with the arguments encoded as a single well-formed JSON object matching the tool's input schema.`,
1461
+ content,
1449
1462
  is_error: true
1450
1463
  };
1451
1464
  }
@@ -1501,6 +1514,18 @@ function hasMalformedArguments(input) {
1501
1514
  const keys = Object.keys(obj);
1502
1515
  return keys.length === 1 && MALFORMED_ARG_MARKERS.includes(keys[0]);
1503
1516
  }
1517
+ function extractMalformedRaw(input) {
1518
+ if (!hasMalformedArguments(input)) return void 0;
1519
+ const obj = input;
1520
+ const value = obj[Object.keys(obj)[0]];
1521
+ if (value === void 0 || value === null) return void 0;
1522
+ if (typeof value === "string") return value;
1523
+ try {
1524
+ return JSON.stringify(value);
1525
+ } catch {
1526
+ return String(value);
1527
+ }
1528
+ }
1504
1529
 
1505
1530
  // src/utils/regex-guard.ts
1506
1531
  var MAX_PATTERN_LEN = 512;