@wrongstack/cli 0.24.0 → 0.32.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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import * as path24 from 'path';
3
3
  import * as fsp3 from 'fs/promises';
4
- import { color, DefaultPathResolver, TOKENS, DefaultSystemPromptBuilder, makeAutonomyPromptContributor, ToolRegistry, createContextManagerTool, EventBus, SlashCommandRegistry, createDelegateTool, FLEET_ROSTER, createMcpControlTool, EternalAutonomyEngine, DefaultLogger, DefaultModelsRegistry, runProviderWithRetry, ReplayLogStore, ReplayProviderRunner, ProviderRegistry, InMemoryMetricsSink, wireMetricsToEvents, DefaultHealthRegistry, startMetricsServer, RecoveryLock, DefaultAttachmentStore, QueueStore, Context, loadTodosCheckpoint, attachTodosCheckpoint, loadDirectorState, loadPlan, createDefaultPipelines, AutoCompactionMiddleware, estimateRequestTokens, Agent, loadPlugins, FleetManager, makeDirectorSessionFactory, Director, makeFleetEmitTool, makeFleetStatusTool, AutoApprovePermissionPolicy, PhaseStore, AutoPhasePlanner, PhaseGraphBuilder, WorktreeManager, PhaseOrchestrator, makeLLMClassifier, resolveWstackPaths, DefaultSecretVault, migratePlaintextSecrets, DefaultConfigLoader, DefaultSessionReader, ToolAuditLog, DefaultSessionRewinder, DefaultSessionStore, atomicWrite, DefaultPluginAPI, makeAgentSubagentRunner, NULL_FLEET_BUS, buildChildEnv, formatContextWindowModeList, repairToolUseAdjacency, getContextWindowMode, resolveContextWindowPolicy, AGENTS_BY_PHASE, dispatchAgent, formatTodosList, SpecStore, TaskGraphStore, analyzeCriticalPath, getTemplate, listTemplates, templateToMarkdown, SpecParser, renderSpecAnalysis, AISpecBuilder, DefaultTaskStore, TaskTracker, renderProgress, renderTaskGraph, SessionRecovery, loadGoal, goalFilePath, summarizeUsage, saveGoal, emptyGoal, buildGoalPreamble, formatGoal, pendingBtwCount, setBtwNote, decryptConfigSecrets, encryptConfigSecrets as encryptConfigSecrets$1, InputBuilder, FsError, ERROR_CODES, SpecVersioning, ParallelEternalEngine, allServers as allServers$1 } from '@wrongstack/core';
4
+ import { color, DefaultPathResolver, TOKENS, DefaultSystemPromptBuilder, makeAutonomyPromptContributor, ToolRegistry, createContextManagerTool, EventBus, SlashCommandRegistry, createDelegateTool, FLEET_ROSTER, createMcpControlTool, EternalAutonomyEngine, DefaultLogger, DefaultModelsRegistry, runProviderWithRetry, ReplayLogStore, ReplayProviderRunner, ProviderRegistry, InMemoryMetricsSink, wireMetricsToEvents, DefaultHealthRegistry, startMetricsServer, RecoveryLock, DefaultAttachmentStore, QueueStore, Context, loadTodosCheckpoint, attachTodosCheckpoint, loadDirectorState, loadPlan, createDefaultPipelines, AutoCompactionMiddleware, estimateRequestTokensCalibrated, Agent, loadPlugins, FleetManager, makeDirectorSessionFactory, Director, makeFleetEmitTool, makeFleetStatusTool, AutoApprovePermissionPolicy, PhaseStore, AutoPhasePlanner, PhaseGraphBuilder, WorktreeManager, PhaseOrchestrator, makeLLMClassifier, resolveWstackPaths, DefaultSecretVault, migratePlaintextSecrets, DefaultConfigLoader, DefaultSessionReader, ToolAuditLog, DefaultSessionRewinder, DefaultSessionStore, atomicWrite, DefaultPluginAPI, makeAgentSubagentRunner, NULL_FLEET_BUS, buildChildEnv, formatContextWindowModeList, repairToolUseAdjacency, getContextWindowMode, resolveContextWindowPolicy, AGENTS_BY_PHASE, dispatchAgent, formatTodosList, SpecStore, TaskGraphStore, analyzeCriticalPath, getTemplate, listTemplates, templateToMarkdown, SpecParser, renderSpecAnalysis, AISpecBuilder, DefaultTaskStore, TaskTracker, renderProgress, renderTaskGraph, SessionRecovery, loadGoal, goalFilePath, summarizeUsage, saveGoal, emptyGoal, buildGoalPreamble, formatGoal, pendingBtwCount, setBtwNote, decryptConfigSecrets, encryptConfigSecrets as encryptConfigSecrets$1, InputBuilder, FsError, ERROR_CODES, SpecVersioning, ParallelEternalEngine, allServers as allServers$1 } from '@wrongstack/core';
5
5
  import { createRequire } from 'module';
6
6
  import * as os3 from 'os';
7
7
  import os3__default from 'os';
@@ -10420,6 +10420,13 @@ async function runRepl(opts) {
10420
10420
  activeCtrl = runCtrl2;
10421
10421
  try {
10422
10422
  const runResult = await opts.agent.run(runBlocks, { signal: runCtrl2.signal });
10423
+ opts.onAgentIterationComplete?.(
10424
+ estimateRequestTokensCalibrated(
10425
+ opts.agent.ctx.messages,
10426
+ opts.agent.ctx.systemPrompt,
10427
+ opts.agent.ctx.tools ?? []
10428
+ ).total
10429
+ );
10423
10430
  if (runResult.status === "done" && runResult.finalText) {
10424
10431
  const specSaved = await trySaveSpecFromAIOutput(runResult.finalText);
10425
10432
  if (specSaved) {
@@ -10549,6 +10556,13 @@ ${taskList}`;
10549
10556
  );
10550
10557
  }
10551
10558
  const result = await opts.agent.run(routed.blocks, { signal: runCtrl.signal });
10559
+ opts.onAgentIterationComplete?.(
10560
+ estimateRequestTokensCalibrated(
10561
+ opts.agent.ctx.messages,
10562
+ opts.agent.ctx.systemPrompt,
10563
+ opts.agent.ctx.tools ?? []
10564
+ ).total
10565
+ );
10552
10566
  if (result.status === "aborted") {
10553
10567
  opts.renderer.writeWarning("Aborted.");
10554
10568
  } else if (result.status === "failed") {
@@ -10647,6 +10661,13 @@ ${color.dim(
10647
10661
  activeCtrl = nextCtrl;
10648
10662
  try {
10649
10663
  const nextResult = await opts.agent.run(nextBlocks, { signal: nextCtrl.signal });
10664
+ opts.onAgentIterationComplete?.(
10665
+ estimateRequestTokensCalibrated(
10666
+ opts.agent.ctx.messages,
10667
+ opts.agent.ctx.systemPrompt,
10668
+ opts.agent.ctx.tools ?? []
10669
+ ).total
10670
+ );
10650
10671
  if (nextResult.status === "done" && nextResult.finalText?.trim() === "DONE") {
10651
10672
  opts.renderer.write(color.dim("\n \u21B3 [autonomy] agent reports task complete.\n"));
10652
10673
  }
@@ -10666,6 +10687,13 @@ ${color.dim(
10666
10687
  activeCtrl = suggestCtrl;
10667
10688
  try {
10668
10689
  const suggestResult = await opts.agent.run(suggestBlocks, { signal: suggestCtrl.signal });
10690
+ opts.onAgentIterationComplete?.(
10691
+ estimateRequestTokensCalibrated(
10692
+ opts.agent.ctx.messages,
10693
+ opts.agent.ctx.systemPrompt,
10694
+ opts.agent.ctx.tools ?? []
10695
+ ).total
10696
+ );
10669
10697
  if (suggestResult.status === "done" && suggestResult.finalText) {
10670
10698
  opts.renderer.write(
10671
10699
  `
@@ -11196,7 +11224,10 @@ async function execute(deps) {
11196
11224
  getParallelEngine,
11197
11225
  skillLoader,
11198
11226
  agentsMonitorController,
11199
- fleetStreamController
11227
+ fleetStreamController,
11228
+ // Report context pressure to the Director after each iteration so
11229
+ // the spawn pre-check (maxLeaderContextLoad) stays accurate.
11230
+ onAgentIterationComplete: director ? (tokens) => director.setLeaderContextPressure(tokens) : void 0
11200
11231
  });
11201
11232
  } finally {
11202
11233
  await webuiPromise.catch(() => void 0);
@@ -11220,7 +11251,8 @@ async function execute(deps) {
11220
11251
  getParallelEngine,
11221
11252
  skillLoader,
11222
11253
  agentsMonitorController,
11223
- fleetStreamController
11254
+ fleetStreamController,
11255
+ onAgentIterationComplete: director ? (tokens) => director.setLeaderContextPressure(tokens) : void 0
11224
11256
  });
11225
11257
  }
11226
11258
  } finally {
@@ -11373,6 +11405,16 @@ var MultiAgentHost = class {
11373
11405
  maxContext: payload.maxContext
11374
11406
  });
11375
11407
  });
11408
+ this.director.fleet.filter("subagent.spawned", (e) => {
11409
+ const payload = e.payload;
11410
+ this.deps.events.emit("subagent.spawned", {
11411
+ subagentId: payload.subagentId,
11412
+ taskId: payload.taskId,
11413
+ name: payload.name,
11414
+ provider: payload.provider,
11415
+ model: payload.model
11416
+ });
11417
+ });
11376
11418
  this.getCoordinator().on(
11377
11419
  "task.assigned",
11378
11420
  ({
@@ -11591,6 +11633,14 @@ var MultiAgentHost = class {
11591
11633
  id: taskId,
11592
11634
  description: task
11593
11635
  });
11636
+ this.deps.events.emit("subagent.spawned", {
11637
+ subagentId,
11638
+ taskId,
11639
+ name: subagentId,
11640
+ provider: "acp",
11641
+ model: void 0,
11642
+ description: task
11643
+ });
11594
11644
  return taskId;
11595
11645
  }
11596
11646
  /** Returns a tool slice for the subagent — full set unless restricted. */
@@ -11624,18 +11674,8 @@ var MultiAgentHost = class {
11624
11674
  model: opts?.model,
11625
11675
  tools: opts?.tools
11626
11676
  };
11627
- const transcriptPath = this.sessionFactory ? path24.join(this.sessionFactory.dir, `${subagentConfig.name}.jsonl`) : void 0;
11628
11677
  const { subagentId, taskId } = await this._spawnAndAssign(subagentConfig);
11629
11678
  this.fleetManager?.addPendingTask(taskId, subagentId, description);
11630
- this.deps.events.emit("subagent.spawned", {
11631
- subagentId,
11632
- taskId,
11633
- name: subagentConfig.name,
11634
- provider: opts?.provider,
11635
- model: opts?.model,
11636
- description,
11637
- transcriptPath
11638
- });
11639
11679
  return { subagentId, taskId };
11640
11680
  }
11641
11681
  /**
@@ -12398,9 +12438,9 @@ async function setupCompaction(params) {
12398
12438
  autoCompactor = new AutoCompactionMiddleware(
12399
12439
  compactor,
12400
12440
  effectiveMaxContext,
12401
- // Use the full API request estimator: messages + system prompt + tool definitions.
12402
- // This matches what the provider actually counts as input tokens.
12403
- (ctx) => estimateRequestTokens(ctx.messages, ctx.systemPrompt, ctx.tools ?? []).total,
12441
+ // Calibrated estimator: recordActualUsage() is called after each API
12442
+ // response so this converges on real token counts for compaction decisions.
12443
+ (ctx) => estimateRequestTokensCalibrated(ctx.messages, ctx.systemPrompt, ctx.tools ?? []).total,
12404
12444
  {
12405
12445
  warn: config.context.warnThreshold,
12406
12446
  soft: config.context.softThreshold,