@wrongstack/core 0.24.0 → 0.31.1

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.
@@ -9,7 +9,7 @@ import { e as ContextWindowAggressiveOn, i as ContextWindowPolicy } from '../con
9
9
  import { c as Agent, R as RunResult, w as SystemPromptContributor } from '../index-ysfO_DlX.js';
10
10
  import { D as DoneCondition } from '../multi-agent-C8Z1i__e.js';
11
11
  import { A as AgentFactory } from '../agent-subagent-runner-DpZTLdBe.js';
12
- import { f as DispatchClassifier, d as DefaultMultiAgentCoordinator } from '../multi-agent-coordinator-Dcsc5t4-.js';
12
+ import { f as DispatchClassifier, d as DefaultMultiAgentCoordinator } from '../multi-agent-coordinator-DOXSgtom.js';
13
13
  import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-CxuWrsKK.js';
14
14
  import { a as WstackPaths } from '../wstack-paths-eMXnY1_X.js';
15
15
  import '../retry-policy-KF18W4dg.js';
@@ -80,13 +80,18 @@ function estimateRequestTokens(messages, systemPrompt, tools) {
80
80
  for (const t of tools) {
81
81
  toolsTokens += estimateToolDefTokens(t);
82
82
  }
83
+ const total = messagesTokens + systemTokens + toolsTokens;
83
84
  return {
84
85
  messages: messagesTokens,
85
86
  systemPrompt: systemTokens,
86
87
  tools: toolsTokens,
87
- total: messagesTokens + systemTokens + toolsTokens
88
+ total
88
89
  };
89
90
  }
91
+ function estimateRequestTokensCalibrated(messages, systemPrompt, tools) {
92
+ const result = estimateRequestTokens(messages, systemPrompt, tools);
93
+ return result;
94
+ }
90
95
 
91
96
  // src/utils/message-invariants.ts
92
97
  function repairToolUseAdjacency(messages) {
@@ -1159,7 +1164,7 @@ var AutoCompactionMiddleware = class _AutoCompactionMiddleware {
1159
1164
  }
1160
1165
  handler() {
1161
1166
  return async (ctx, next) => {
1162
- const tokens = this._estimator ? this._estimator(ctx) : estimateRequestTokens(ctx.messages, ctx.systemPrompt, ctx.tools ?? []).total;
1167
+ const tokens = this._estimator ? this._estimator(ctx) : estimateRequestTokensCalibrated(ctx.messages, ctx.systemPrompt, ctx.tools ?? []).total;
1163
1168
  const load = tokens / this._maxContext;
1164
1169
  const policy = this.policyProvider?.(ctx);
1165
1170
  const thresholds = policy?.thresholds ?? {
@@ -5648,6 +5653,10 @@ var NICKNAME_POOL = {
5648
5653
  "pasteur": { name: "Pasteur", domain: "biology" },
5649
5654
  "hawking": { name: "Hawking", domain: "cosmology" },
5650
5655
  "sagan": { name: "Sagan", domain: "cosmology" },
5656
+ // Exploration & navigation
5657
+ "columbus": { name: "Columbus", domain: "exploration" },
5658
+ "polo": { name: "Polo", domain: "exploration" },
5659
+ "magellan": { name: "Magellan", domain: "exploration" },
5651
5660
  // Chemistry / materials
5652
5661
  "lavoisier": { name: "Lavoisier", domain: "chemistry" },
5653
5662
  "mendeleev": { name: "Mendeleev", domain: "chemistry" }
@@ -5702,7 +5711,7 @@ function formatRole(role) {
5702
5711
  }
5703
5712
 
5704
5713
  // src/coordination/multi-agent-coordinator.ts
5705
- var DefaultMultiAgentCoordinator = class extends EventEmitter {
5714
+ var DefaultMultiAgentCoordinator = class _DefaultMultiAgentCoordinator extends EventEmitter {
5706
5715
  coordinatorId;
5707
5716
  config;
5708
5717
  runner;
@@ -5717,8 +5726,12 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5717
5726
  * names) to memorable ones here — that's what surfaces in the fleet monitor.
5718
5727
  */
5719
5728
  usedNicknames = /* @__PURE__ */ new Set();
5729
+ /** Maps subagentId → nickname key (e.g. 'einstein'). Used to free the slot on remove(). */
5730
+ subagentNicknames = /* @__PURE__ */ new Map();
5720
5731
  pendingTasks = [];
5721
5732
  completedResults = [];
5733
+ /** Prevents completedResults from growing unbounded in long-running coordinators. */
5734
+ static MAX_COMPLETED_RESULTS = 1e4;
5722
5735
  totalIterations = 0;
5723
5736
  inFlight = 0;
5724
5737
  /**
@@ -5773,7 +5786,7 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5773
5786
  * Explicit, human-chosen names — including nicknames already assigned by
5774
5787
  * `Director.spawn()` — are left untouched, so this never double-assigns.
5775
5788
  */
5776
- withNickname(subagent) {
5789
+ withNickname(subagent, subagentId) {
5777
5790
  const role = subagent.role ?? "subagent";
5778
5791
  const name = subagent.name?.trim() ?? "";
5779
5792
  const isPlaceholder = name === "" || name.toLowerCase() === role.toLowerCase() || name === "subagent" || name === "adhoc" || name === "generic" || /^slot-/.test(name);
@@ -5781,11 +5794,12 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
5781
5794
  const nickname = assignNickname(role, this.usedNicknames);
5782
5795
  const baseKey = nickname.split(" ")[0].toLowerCase().replace(/[^a-z0-9-]/g, "-");
5783
5796
  this.usedNicknames.add(baseKey);
5797
+ this.subagentNicknames.set(subagentId, baseKey);
5784
5798
  return { ...subagent, name: nickname };
5785
5799
  }
5786
5800
  async spawn(subagent) {
5787
- subagent = this.withNickname(subagent);
5788
5801
  const id = subagent.id || randomUUID();
5802
+ subagent = this.withNickname(subagent, id);
5789
5803
  if (this.subagents.has(id)) {
5790
5804
  throw new Error(`Subagent id "${id}" already exists \u2014 refusing to overwrite`);
5791
5805
  }
@@ -6227,6 +6241,12 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
6227
6241
  }
6228
6242
  recordCompletion(result) {
6229
6243
  this.completedResults.push(result);
6244
+ if (this.completedResults.length > _DefaultMultiAgentCoordinator.MAX_COMPLETED_RESULTS) {
6245
+ this.completedResults.splice(
6246
+ 0,
6247
+ this.completedResults.length - _DefaultMultiAgentCoordinator.MAX_COMPLETED_RESULTS
6248
+ );
6249
+ }
6230
6250
  this.totalIterations += result.iterations;
6231
6251
  if (this.inFlight > 0) {
6232
6252
  this.inFlight--;
@@ -6296,7 +6316,29 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
6296
6316
  }
6297
6317
  this.subagents.delete(subagentId);
6298
6318
  this.terminating.delete(subagentId);
6319
+ const nicknameKey = this.subagentNicknames.get(subagentId);
6320
+ if (nicknameKey) {
6321
+ this.usedNicknames.delete(nicknameKey);
6322
+ this.subagentNicknames.delete(subagentId);
6323
+ }
6324
+ const orphaned = this.pendingTasks.filter((t) => t.subagentId === subagentId);
6299
6325
  this.pendingTasks = this.pendingTasks.filter((t) => t.subagentId !== subagentId);
6326
+ for (const t of orphaned) {
6327
+ const synthetic = {
6328
+ subagentId,
6329
+ taskId: t.id,
6330
+ status: "stopped",
6331
+ error: {
6332
+ kind: "aborted_by_parent",
6333
+ message: `Subagent "${subagentId}" was removed while task "${t.id}" was pending`,
6334
+ retryable: false
6335
+ },
6336
+ iterations: 0,
6337
+ toolCalls: 0,
6338
+ durationMs: 0
6339
+ };
6340
+ this.recordCompletion(synthetic);
6341
+ }
6300
6342
  this.fleetBus?.emit({
6301
6343
  subagentId,
6302
6344
  ts: Date.now(),