@wrongstack/core 0.6.1 → 0.6.3

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 (38) hide show
  1. package/dist/{agent-bridge-DaCvA_uK.d.ts → agent-bridge-eb7qnNrd.d.ts} +1 -1
  2. package/dist/coordination/index.d.ts +5 -5
  3. package/dist/coordination/index.js +5 -33
  4. package/dist/coordination/index.js.map +1 -1
  5. package/dist/defaults/index.d.ts +8 -8
  6. package/dist/defaults/index.js +62 -39
  7. package/dist/defaults/index.js.map +1 -1
  8. package/dist/{events-CzkeaVVl.d.ts → events-BHuIHekD.d.ts} +19 -2
  9. package/dist/execution/index.d.ts +4 -4
  10. package/dist/execution/index.js +56 -5
  11. package/dist/execution/index.js.map +1 -1
  12. package/dist/extension/index.d.ts +2 -2
  13. package/dist/{index-BkKLQjea.d.ts → index-BOn9NK7D.d.ts} +1 -1
  14. package/dist/{index-i9rPR53g.d.ts → index-CPcDqvZh.d.ts} +4 -4
  15. package/dist/index.d.ts +11 -11
  16. package/dist/index.js +62 -39
  17. package/dist/index.js.map +1 -1
  18. package/dist/infrastructure/index.d.ts +2 -2
  19. package/dist/infrastructure/index.js +1 -1
  20. package/dist/infrastructure/index.js.map +1 -1
  21. package/dist/kernel/index.d.ts +2 -2
  22. package/dist/kernel/index.js.map +1 -1
  23. package/dist/{multi-agent-MfI6dmv-.d.ts → multi-agent-CxSb-9dQ.d.ts} +1 -1
  24. package/dist/observability/index.d.ts +1 -1
  25. package/dist/observability/index.js +1 -1
  26. package/dist/observability/index.js.map +1 -1
  27. package/dist/{path-resolver-CWINz5XR.d.ts → path-resolver-CMGNadvq.d.ts} +1 -1
  28. package/dist/{plan-templates-Bne1pB4d.d.ts → plan-templates-BJflQY2i.d.ts} +1 -1
  29. package/dist/{provider-runner-CZYIzeBp.d.ts → provider-runner-BFgNXpaP.d.ts} +1 -1
  30. package/dist/sdd/index.d.ts +2 -2
  31. package/dist/storage/index.d.ts +2 -2
  32. package/dist/{tool-executor-40Q6shR-.d.ts → tool-executor-FoxBjULX.d.ts} +1 -1
  33. package/dist/types/index.d.ts +7 -7
  34. package/dist/types/index.js +14 -3
  35. package/dist/types/index.js.map +1 -1
  36. package/dist/utils/index.js +1 -1
  37. package/dist/utils/index.js.map +1 -1
  38. package/package.json +1 -1
@@ -204,8 +204,25 @@ interface EventMap {
204
204
  removedMessages: number;
205
205
  };
206
206
  'compaction.fired': {
207
- before: number;
208
- after: number;
207
+ /** Threshold level that triggered compaction (warn / soft / hard). */
208
+ level: 'warn' | 'soft' | 'hard';
209
+ /** Tokens estimated before compaction ran. */
210
+ tokens: number;
211
+ /** Fraction of maxContext at the time compaction fired. */
212
+ load: number;
213
+ /** Provider's max context window in tokens. */
214
+ maxContext: number;
215
+ /** Full compaction report from the compactor. */
216
+ report: {
217
+ before: number;
218
+ after: number;
219
+ reductions: {
220
+ phase: string;
221
+ saved: number;
222
+ }[];
223
+ };
224
+ /** Whether aggressive (summary) mode was used. */
225
+ aggressive: boolean;
209
226
  };
210
227
  /**
211
228
  * Fired when the auto-compaction middleware's compactor.compact() call
@@ -1,12 +1,12 @@
1
- export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-40Q6shR-.js';
1
+ export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-FoxBjULX.js';
2
2
  import { g as Provider, a2 as Context } from '../context-CDRyrkKQ.js';
3
3
  import { a as Compactor, C as CompactReport } from '../compactor-RIPuTtWK.js';
4
4
  import { M as MessageSelector } from '../selector-C7HqnZJU.js';
5
- import { E as EventBus } from '../events-CzkeaVVl.js';
5
+ import { E as EventBus } from '../events-BHuIHekD.js';
6
6
  import { c as MiddlewareHandler } from '../system-prompt-Dl2QY1_B.js';
7
7
  import { e as ContextWindowAggressiveOn, i as ContextWindowPolicy } from '../config-BGGuP_Ar.js';
8
- import { r as Agent, R as RunResult, j as SystemPromptContributor } from '../index-BkKLQjea.js';
9
- import { D as DoneCondition } from '../multi-agent-MfI6dmv-.js';
8
+ import { r as Agent, R as RunResult, j as SystemPromptContributor } from '../index-BOn9NK7D.js';
9
+ import { D as DoneCondition } from '../multi-agent-CxSb-9dQ.js';
10
10
  import { J as JournalEntry } from '../goal-store-DVCfj7Ff.js';
11
11
  import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-CxuWrsKK.js';
12
12
  import { W as WstackPaths } from '../wstack-paths-86YPFktR.js';
@@ -5,7 +5,7 @@ import * as path from 'path';
5
5
  import { randomBytes } from 'crypto';
6
6
 
7
7
  // src/utils/token-estimate.ts
8
- var RoughTokenEstimate = (text) => Math.max(1, Math.ceil(text.length / 4));
8
+ var RoughTokenEstimate = (text, charsPerToken = 3.5) => Math.max(1, Math.ceil(text.length / charsPerToken));
9
9
  var ESTIMATE_CACHE = /* @__PURE__ */ new Map();
10
10
  var ESTIMATE_CACHE_MAX_SIZE = 1e4;
11
11
  function getCachedEstimate(key, compute) {
@@ -136,7 +136,7 @@ var HybridCompactor = class {
136
136
  eliseThreshold;
137
137
  estimator;
138
138
  constructor(opts = {}) {
139
- this.preserveK = opts.preserveK ?? 10;
139
+ this.preserveK = opts.preserveK ?? 5;
140
140
  this.eliseThreshold = opts.eliseThreshold ?? 2e3;
141
141
  this.estimator = opts.estimator ?? estimateTextTokens;
142
142
  }
@@ -180,6 +180,17 @@ var HybridCompactor = class {
180
180
  preserveStart = i;
181
181
  }
182
182
  }
183
+ for (let i = preserveStart; i < messages.length; i++) {
184
+ const m = messages[i];
185
+ if (!m || typeof m.content === "string" || !Array.isArray(m.content)) continue;
186
+ const hasToolUse2 = m.content.some((b) => b.type === "tool_use");
187
+ if (hasToolUse2 && i + 1 < messages.length) {
188
+ const next = messages[i + 1];
189
+ if (next && next.role === "user" && typeof next.content !== "string" && Array.isArray(next.content) && next.content.some((b) => b.type === "tool_result")) {
190
+ preserveStart = i + 1;
191
+ }
192
+ }
193
+ }
183
194
  let saved = 0;
184
195
  let changed = false;
185
196
  const nextMessages = new Array(messages.length);
@@ -201,7 +212,7 @@ var HybridCompactor = class {
201
212
  const elided = {
202
213
  type: "tool_result",
203
214
  tool_use_id: b.tool_use_id,
204
- content: `[elided: ~${tokens} tokens removed. Call the tool again if needed.]`,
215
+ content: `[elided: ~${tokens} tokens]`,
205
216
  is_error: b.is_error
206
217
  };
207
218
  return elided;
@@ -340,7 +351,28 @@ var IntelligentCompactor = class {
340
351
  try {
341
352
  summaryText = await this.callSummarizer(toSummarize, ctx);
342
353
  } catch {
343
- summaryText = `[${toSummarize.length} earlier turns omitted \u2014 key decisions and file states preserved in context]`;
354
+ const toolNames = /* @__PURE__ */ new Set();
355
+ const filePaths = /* @__PURE__ */ new Set();
356
+ let userTurns = 0, assistantTurns = 0;
357
+ for (const m of toSummarize) {
358
+ if (m.role === "user") userTurns++;
359
+ else if (m.role === "assistant") {
360
+ assistantTurns++;
361
+ if (Array.isArray(m.content)) {
362
+ for (const b of m.content) {
363
+ if (b.type === "tool_use") toolNames.add(b.name ?? "unknown");
364
+ }
365
+ }
366
+ }
367
+ const text = typeof m.content === "string" ? m.content : "";
368
+ const matches = text.matchAll(/(?:[\w.,\-/@]+\/)*[\w.,\-/@]+\.\w+/g);
369
+ for (const m_ of matches) filePaths.add(m_[0]);
370
+ }
371
+ const parts = [`${toSummarize.length} turns (${userTurns} user, ${assistantTurns} assistant)`];
372
+ if (toolNames.size > 0) parts.push(`tools: ${[...toolNames].join(", ")}`);
373
+ if (filePaths.size > 0) parts.push(`files: ${[...filePaths].slice(0, 10).join(", ")}`);
374
+ summaryText = parts.join(" | ");
375
+ if (!summaryText) summaryText = `${toSummarize.length} earlier turns omitted`;
344
376
  }
345
377
  const summaryMsg = {
346
378
  role: "system",
@@ -424,6 +456,17 @@ var IntelligentCompactor = class {
424
456
  preserveStart = i;
425
457
  }
426
458
  }
459
+ for (let i = preserveStart; i < messages.length; i++) {
460
+ const m = messages[i];
461
+ if (!m || typeof m.content === "string" || !Array.isArray(m.content)) continue;
462
+ const hasToolUse2 = m.content.some((b) => b.type === "tool_use");
463
+ if (hasToolUse2 && i + 1 < messages.length) {
464
+ const next = messages[i + 1];
465
+ if (next && next.role === "user" && typeof next.content !== "string" && Array.isArray(next.content) && next.content.some((b) => b.type === "tool_result")) {
466
+ preserveStart = i + 1;
467
+ }
468
+ }
469
+ }
427
470
  let saved = 0;
428
471
  let changed = false;
429
472
  const nextMessages = new Array(messages.length);
@@ -991,7 +1034,15 @@ var AutoCompactionMiddleware = class {
991
1034
  }
992
1035
  async compact(ctx, aggressive, pressure) {
993
1036
  try {
994
- await this.compactor.compact(ctx, { aggressive });
1037
+ const report = await this.compactor.compact(ctx, { aggressive });
1038
+ this.events?.emit("compaction.fired", {
1039
+ level: pressure.level,
1040
+ tokens: pressure.tokens,
1041
+ load: pressure.load,
1042
+ maxContext: this._maxContext,
1043
+ report,
1044
+ aggressive
1045
+ });
995
1046
  } catch (err) {
996
1047
  const error = err instanceof Error ? err : new Error(String(err));
997
1048
  const fatal = this.failureMode === "throw" || this.failureMode === "throw_on_hard" && pressure.level === "hard";