@wrongstack/core 0.141.0 → 0.148.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.
@@ -5,8 +5,8 @@ export { A as AuditLevel, S as SessionEventBridge, b as SessionEventBridgeOption
5
5
  export { a as DirectorStateCheckpoint, D as DirectorStateSnapshot, b as DirectorSubagentState, c as DirectorTaskState, l as loadDirectorState } from '../director-state-BfeCUbmk.js';
6
6
  export { D as DefaultSecretScrubber, a as DefaultSecretVault, S as SecretVaultOptions, d as decryptConfigSecrets, e as encryptConfigSecrets, m as migratePlaintextSecrets, r as rewriteConfigEncrypted } from '../secret-vault-BTcC_T5v.js';
7
7
  export { A as AutoApprovePermissionPolicy, D as DefaultPermissionPolicy, P as PermissionPolicyOptions } from '../permission-policy-8-6zBmfA.js';
8
- export { C as CompactorOptions, D as DefaultErrorHandler, a as DefaultRetryPolicy, E as EternalAutonomyEngine, b as EternalAutonomyOptions, c as EternalEngineState, H as HybridCompactor, I as IterationStage, P as ParallelEngineState, d as ParallelEternalEngine, e as ParallelEternalOptions, f as ParallelIterationStage, T as ToolExecutor } from '../parallel-eternal-engine-Dj2SYzha.js';
9
- export { A as AutoCompactionMiddleware, a as AutonomousRunner, b as AutonomousRunnerOptions, c as AutonomyPromptContributorOptions, C as CompactorStrategy, D as DefaultSkillLoader, d as DoneCheckResult, e as DoneConditionChecker, I as IntelligentCompactor, f as IntelligentCompactorOptions, S as SelectiveCompactor, g as SelectiveCompactorOptions, h as SkillLoaderOptions, i as StrategyCompactorOptions, j as buildGoalPreamble, k as createStrategyCompactor, m as makeAutonomyPromptContributor } from '../goal-preamble-iuIUTQwk.js';
8
+ export { C as CompactorOptions, D as DefaultErrorHandler, a as DefaultRetryPolicy, E as EternalAutonomyEngine, b as EternalAutonomyOptions, c as EternalEngineState, H as HybridCompactor, I as IterationStage, P as ParallelEngineState, d as ParallelEternalEngine, e as ParallelEternalOptions, f as ParallelIterationStage, T as ToolExecutor } from '../parallel-eternal-engine-C75QuhAI.js';
9
+ export { A as AutoCompactionMiddleware, a as AutonomousRunner, b as AutonomousRunnerOptions, c as AutonomyPromptContributorOptions, C as CompactorStrategy, D as DefaultSkillLoader, d as DoneCheckResult, e as DoneConditionChecker, I as IntelligentCompactor, f as IntelligentCompactorOptions, S as SelectiveCompactor, g as SelectiveCompactorOptions, h as SkillLoaderOptions, i as StrategyCompactorOptions, j as buildGoalPreamble, k as createStrategyCompactor, m as makeAutonomyPromptContributor } from '../goal-preamble-CYJLg0wk.js';
10
10
  import { P as ProviderRunner, R as RunProviderOptions } from '../provider-runner-BNpuIyOL.js';
11
11
  import { b as Response } from '../context-C7G_MtLV.js';
12
12
  export { a as AGENTS_BY_PHASE, b as AGENT_CATALOG, c as ALL_AGENT_DEFINITIONS, d as ALL_FLEET_AGENTS, e as AUDIT_LOG_AGENT, f as AutoExtendCeiling, g as AutoExtendPolicy, B as BUG_HUNTER_AGENT, n as CreateDelegateToolOptions, D as DEFAULT_DIRECTOR_PREAMBLE, q as DEFAULT_SUBAGENT_BASELINE, r as DelegateHost, s as Director, w as DirectorPromptParts, x as DirectorSessionFactory, y as DirectorSessionFactoryOptions, F as FLEET_ROSTER, z as FLEET_ROSTER_BUDGETS, J as FleetRosterBudget, K as FleetSpawnBudgetError, L as ICoordinator, M as IFleetManager, O as NULL_FLEET_BUS, R as REFACTOR_PLANNER_AGENT, S as SECURITY_SCANNER_AGENT, V as SubagentPromptParts, W as applyRosterBudget, X as attachAutoExtend, Y as composeDirectorPrompt, Z as composeSubagentPrompt, _ as createDelegateTool, $ as getAgentDefinition, a1 as makeAskTool, a2 as makeAssignTool, a3 as makeAwaitTasksTool, a4 as makeCollabDebugTool, a5 as makeDirectorSessionFactory, a6 as makeFleetEmitTool, a7 as makeFleetHealthTool, a8 as makeFleetSessionTool, a9 as makeFleetStatusTool, aa as makeFleetUsageTool, ab as makeRollUpTool, ac as makeSpawnTool, ad as makeTerminateTool, af as rosterSummaryFromConfigs } from '../null-fleet-bus-BUyfqh23.js';
@@ -757,7 +757,7 @@ var DefaultSessionStore = class _DefaultSessionStore {
757
757
  let toolErrorCount = 0;
758
758
  let fileChangeCount = 0;
759
759
  const toolBreakdown = {};
760
- let outcome = void 0;
760
+ let outcome;
761
761
  const lastEvent = data.events[data.events.length - 1];
762
762
  for (const e of data.events) {
763
763
  if (e.type === "in_flight_start") iterationCount++;
@@ -4318,7 +4318,7 @@ var DefaultPermissionPolicy = class {
4318
4318
  subjectFor(toolName, input, subjectKey) {
4319
4319
  if (!input || typeof input !== "object") return void 0;
4320
4320
  const obj = input;
4321
- const globChars = /[*?\[\]]/g;
4321
+ const globChars = /[*?[\]]/g;
4322
4322
  const escapeGlob = (s) => s.replace(globChars, (c) => `\\${c}`);
4323
4323
  const normalizePath = (s) => escapeGlob(s.replace(/\\/g, "/"));
4324
4324
  if (subjectKey) {
@@ -5343,8 +5343,8 @@ function findPreserveStart(messages, preserveK) {
5343
5343
  for (let i = preserveStart; i < messages.length; i++) {
5344
5344
  const m = messages[i];
5345
5345
  if (!m || typeof m.content === "string" || !Array.isArray(m.content)) continue;
5346
- const hasToolUse2 = m.content.some((b) => b.type === "tool_use");
5347
- if (hasToolUse2 && i + 1 < messages.length) {
5346
+ const hasToolUse3 = m.content.some((b) => b.type === "tool_use");
5347
+ if (hasToolUse3 && i + 1 < messages.length) {
5348
5348
  const next = messages[i + 1];
5349
5349
  if (next && next.role === "user" && typeof next.content !== "string" && Array.isArray(next.content) && next.content.some((b) => b.type === "tool_result")) {
5350
5350
  preserveStart = i + 1;
@@ -5408,6 +5408,127 @@ function buildLosslessDigest(messages) {
5408
5408
  }
5409
5409
  return lines.join("\n");
5410
5410
  }
5411
+ function extractText(m) {
5412
+ if (typeof m.content === "string") return m.content;
5413
+ return m.content.filter(isTextBlock).map((b) => b.text).join(" ");
5414
+ }
5415
+ function hasToolUse2(m) {
5416
+ if (typeof m.content === "string") return false;
5417
+ return m.content.some((b) => b.type === "tool_use");
5418
+ }
5419
+ function hasLargeToolResult(m, threshold = 3e3) {
5420
+ if (typeof m.content === "string") return false;
5421
+ return m.content.some(
5422
+ (b) => b.type === "tool_result" && b.content && (typeof b.content === "string" ? b.content.length : JSON.stringify(b.content).length) > threshold
5423
+ );
5424
+ }
5425
+ function scoreMessage(m, context) {
5426
+ const text = extractText(m).toLowerCase();
5427
+ if (text.trim().length === 0 && (hasToolUse2(m) || typeof m.content !== "string")) {
5428
+ const hasResult = typeof m.content !== "string" && m.content.some((b) => b.type === "tool_result");
5429
+ if (hasToolUse2(m) || hasResult) return 0;
5430
+ }
5431
+ if (context?.failureCounts && m.role === "user" && hasToolUse2(m) === false) {
5432
+ const isFailure = /error|fail|exception|timeout|enonet|eacces|eperm|enoent|abort/i.test(text);
5433
+ if (isFailure) {
5434
+ const errKey = /(error|fail|exception|timeout|enonet|eacces|eperm|enoent|abort)/i.exec(text)?.[0]?.toLowerCase() ?? "error";
5435
+ const count = (context.failureCounts.get(errKey) ?? 0) + 1;
5436
+ context.failureCounts.set(errKey, count);
5437
+ if (count >= 5) return 0;
5438
+ if (count >= 3) return 1;
5439
+ }
5440
+ }
5441
+ if (m.role === "user") {
5442
+ if (/\b(wrong|no\b|stop\b|don'?t\b|actually|fix that|undo|revert|forget|ignore|skip)\b/i.test(
5443
+ text
5444
+ )) {
5445
+ return 5;
5446
+ }
5447
+ }
5448
+ if (/\b(error|exception|fatal|critical|crash|panic|abort|segfault|core dump|undefined is not|null pointer|typeerror|referenceerror|syntaxerror)\b/i.test(
5449
+ text
5450
+ )) {
5451
+ return 5;
5452
+ }
5453
+ if (/\b(security|vulnerability|injection|xss|csrf|secret|apikey|api.key|hardcoded|leak|exploit|cve)\b/i.test(
5454
+ text
5455
+ )) {
5456
+ return 5;
5457
+ }
5458
+ if (m.role === "assistant" && /\b(architecture|design|approach|strategy|pattern|refactor|migrate|restructure|decision|trade.?off)\b/i.test(
5459
+ text
5460
+ )) {
5461
+ return 5;
5462
+ }
5463
+ if (hasLargeToolResult(m)) return 1;
5464
+ if (m.role === "user" && !hasToolUse2(m) && /\b(files_with_matches|count|found \d+ match|directory tree|\.\.\. and \d+ more)\b/i.test(text)) {
5465
+ return 1;
5466
+ }
5467
+ return 3;
5468
+ }
5469
+ function buildSmartDigest(messages) {
5470
+ const lines = [];
5471
+ const failureCounts = /* @__PURE__ */ new Map();
5472
+ let noiseCount = 0;
5473
+ for (const m of messages) {
5474
+ const score = scoreMessage(m, { failureCounts });
5475
+ const text = extractText(m);
5476
+ const toolCount = countToolBlocks(m);
5477
+ if (score === 0) {
5478
+ noiseCount++;
5479
+ continue;
5480
+ }
5481
+ const marker = toolCount > 0 ? ` [${toolCount} tool call(s)]` : "";
5482
+ let display;
5483
+ switch (score) {
5484
+ case 5:
5485
+ display = text.trim();
5486
+ break;
5487
+ case 3:
5488
+ display = firstSentence(text);
5489
+ break;
5490
+ case 1:
5491
+ display = oneLineSummary(m, text);
5492
+ break;
5493
+ default:
5494
+ display = firstSentence(text);
5495
+ }
5496
+ if (display.length === 0 && toolCount === 0) continue;
5497
+ lines.push(`[${m.role}]: ${display}${marker}`);
5498
+ }
5499
+ if (noiseCount > 0) {
5500
+ lines.push(`[system]: ${noiseCount} low-importance turn(s) collapsed (repeated failures / pure tool I/O)`);
5501
+ }
5502
+ return lines.join("\n");
5503
+ }
5504
+ function countToolBlocks(m) {
5505
+ if (typeof m.content === "string") return 0;
5506
+ return m.content.filter(
5507
+ (b) => b.type === "tool_use" || b.type === "tool_result"
5508
+ ).length;
5509
+ }
5510
+ function firstSentence(text) {
5511
+ const trimmed = text.trim();
5512
+ if (trimmed.length === 0) return "";
5513
+ const dot = trimmed.indexOf(". ");
5514
+ if (dot === -1) return trimmed.length > 150 ? `${trimmed.slice(0, 147)}\u2026` : trimmed;
5515
+ const sentence = trimmed.slice(0, dot + 1);
5516
+ return sentence.length > 150 ? `${sentence.slice(0, 147)}\u2026` : sentence;
5517
+ }
5518
+ function oneLineSummary(m, text) {
5519
+ const trimmed = text.trim();
5520
+ if (trimmed.length === 0) {
5521
+ if (typeof m.content !== "string") {
5522
+ const results = m.content.filter((b) => b.type === "tool_result");
5523
+ if (results.length > 0) {
5524
+ return `[${results.length} tool result(s) \u2014 see session log]`;
5525
+ }
5526
+ }
5527
+ return "[no text content]";
5528
+ }
5529
+ const firstLine = trimmed.split("\n")[0] ?? "";
5530
+ return firstLine.length > 100 ? `${firstLine.slice(0, 97)}\u2026` : firstLine;
5531
+ }
5411
5532
  function findSafeBoundary(messages, from, to) {
5412
5533
  for (let i = to; i >= from; i--) {
5413
5534
  const m = messages[i];
@@ -5423,8 +5544,8 @@ function findExchangeStart(messages, userIndex) {
5423
5544
  const m = messages[i];
5424
5545
  if (!m) continue;
5425
5546
  if (m.role === "assistant") {
5426
- const hasToolUse2 = Array.isArray(m.content) ? m.content.some((b) => b.type === "tool_use") : false;
5427
- if (!hasToolUse2) return i + 1;
5547
+ const hasToolUse3 = Array.isArray(m.content) ? m.content.some((b) => b.type === "tool_use") : false;
5548
+ if (!hasToolUse3) return i + 1;
5428
5549
  } else if (m.role === "user") {
5429
5550
  return i;
5430
5551
  }
@@ -5436,9 +5557,11 @@ function findExchangeStart(messages, userIndex) {
5436
5557
  var HybridCompactor = class {
5437
5558
  preserveK;
5438
5559
  eliseThreshold;
5560
+ smart;
5439
5561
  constructor(opts = {}) {
5440
5562
  this.preserveK = opts.preserveK ?? 5;
5441
5563
  this.eliseThreshold = opts.eliseThreshold ?? 2e3;
5564
+ this.smart = opts.smart ?? false;
5442
5565
  }
5443
5566
  async compact(ctx, opts = {}) {
5444
5567
  const beforeTokens = estimateMessages(ctx.messages);
@@ -5510,7 +5633,7 @@ var HybridCompactor = class {
5510
5633
  if (boundary <= 0) return { saved: 0 };
5511
5634
  const removed = messages.slice(0, boundary);
5512
5635
  const removedTokens = estimateMessages(removed);
5513
- const digest = buildLosslessDigest(removed) || `${removed.length} earlier turns (no textual content; tool I/O omitted \u2014 see session log)`;
5636
+ const digest = this.smart ? buildSmartDigest(removed) || `${removed.length} earlier turns (no textual content; tool I/O omitted \u2014 see session log)` : buildLosslessDigest(removed) || `${removed.length} earlier turns (no textual content; tool I/O omitted \u2014 see session log)`;
5514
5637
  const summaryMsg = {
5515
5638
  role: "system",
5516
5639
  content: `[prior_turns_digest: ${digest}]`
@@ -6034,7 +6157,8 @@ function createStrategyCompactor(opts = {}) {
6034
6157
  }
6035
6158
  return new HybridCompactor({
6036
6159
  preserveK: opts.preserveK,
6037
- eliseThreshold: opts.eliseThreshold
6160
+ eliseThreshold: opts.eliseThreshold,
6161
+ smart: opts.smart
6038
6162
  });
6039
6163
  }
6040
6164
  var ProviderBackedCompactor = class {
@@ -6766,7 +6890,7 @@ ${excerpt}`;
6766
6890
  subjectFor(toolName, input, subjectKey) {
6767
6891
  if (!input || typeof input !== "object") return void 0;
6768
6892
  const obj = input;
6769
- const globChars = /[*?\[\]]/g;
6893
+ const globChars = /[*?[\]]/g;
6770
6894
  const escapeGlob = (s) => s.replace(globChars, (c) => `\\${c}`);
6771
6895
  const normalizePath = (s) => escapeGlob(s.replace(/\\/g, "/"));
6772
6896
  if (subjectKey) {
@@ -7102,7 +7226,7 @@ function appendJournal(goal, entry) {
7102
7226
  };
7103
7227
  }
7104
7228
  function parseProgressFromText(text) {
7105
- const re = /\[progress:\s*(\d{1,3})%\]\s*(?:[—\-]\s*(.+))?/i;
7229
+ const re = /\[progress:\s*(\d{1,3})%\]\s*(?:[—-]\s*(.+))?/i;
7106
7230
  const m = text.match(re);
7107
7231
  if (!m) return null;
7108
7232
  const progress = Math.min(100, Math.max(0, Number.parseInt(m[1] ?? "0", 10)));
@@ -12849,7 +12973,7 @@ async function expandGlob(pattern) {
12849
12973
  } catch {
12850
12974
  return;
12851
12975
  }
12852
- const firstGlob = pat.search(/[*?[\[]/);
12976
+ const firstGlob = pat.search(/[*?[[]/);
12853
12977
  if (firstGlob < 0) {
12854
12978
  const re = globToRegex(pat);
12855
12979
  for (const e of entries) {
@@ -12909,7 +13033,7 @@ var CollabSession = class extends EventEmitter {
12909
13033
  bugs = /* @__PURE__ */ new Map();
12910
13034
  plans = /* @__PURE__ */ new Map();
12911
13035
  evaluations = /* @__PURE__ */ new Map();
12912
- disposers = new Array();
13036
+ disposers = [];
12913
13037
  settled = false;
12914
13038
  timeoutMs;
12915
13039
  cancelled = false;
@@ -14117,7 +14241,7 @@ var FleetUsageAggregator = class {
14117
14241
  metaLookup;
14118
14242
  perSubagent = /* @__PURE__ */ new Map();
14119
14243
  total = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
14120
- unsub = new Array();
14244
+ unsub = [];
14121
14245
  /**
14122
14246
  * Remove a terminated subagent's data from the aggregator and subtract its
14123
14247
  * contribution from the running totals. Call this when a subagent is removed