@wrongstack/core 0.6.7 → 0.7.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.
Files changed (52) hide show
  1. package/dist/{agent-bridge-BCVxmrOn.d.ts → agent-bridge-CrQpYjM7.d.ts} +1 -1
  2. package/dist/{compactor-BUJ8550X.d.ts → compactor-CWV1u-IU.d.ts} +1 -1
  3. package/dist/{config-BHkYGzUT.d.ts → config-C34JRwl4.d.ts} +1 -1
  4. package/dist/{context-C8mBUzBv.d.ts → context-bmR0YgBm.d.ts} +71 -3
  5. package/dist/coordination/index.d.ts +11 -11
  6. package/dist/coordination/index.js +53 -9
  7. package/dist/coordination/index.js.map +1 -1
  8. package/dist/default-config-DvRSTELf.d.ts +20 -0
  9. package/dist/defaults/index.d.ts +20 -19
  10. package/dist/defaults/index.js +130 -32
  11. package/dist/defaults/index.js.map +1 -1
  12. package/dist/{events-DounT6pP.d.ts → events-CEKFTmIY.d.ts} +1 -1
  13. package/dist/execution/index.d.ts +19 -13
  14. package/dist/execution/index.js +94 -22
  15. package/dist/execution/index.js.map +1 -1
  16. package/dist/extension/index.d.ts +6 -6
  17. package/dist/extension/index.js +3 -1
  18. package/dist/extension/index.js.map +1 -1
  19. package/dist/{index-DiIGZh5I.d.ts → index-BJIFLGII.d.ts} +5 -5
  20. package/dist/{index-BlVITqm-.d.ts → index-CZR0HjxM.d.ts} +12 -105
  21. package/dist/index.d.ts +27 -26
  22. package/dist/index.js +184 -53
  23. package/dist/index.js.map +1 -1
  24. package/dist/infrastructure/index.d.ts +6 -6
  25. package/dist/kernel/index.d.ts +9 -9
  26. package/dist/kernel/index.js +8 -4
  27. package/dist/kernel/index.js.map +1 -1
  28. package/dist/{mcp-servers-CXFfDN_d.d.ts → mcp-servers-BRJicm5o.d.ts} +3 -3
  29. package/dist/models/index.d.ts +2 -2
  30. package/dist/{multi-agent-Iy8YUe3v.d.ts → multi-agent-Cm1wYSrw.d.ts} +7 -2
  31. package/dist/{agent-subagent-runner-BTloSwjE.d.ts → multi-agent-coordinator-CCupVFqv.d.ts} +117 -4
  32. package/dist/observability/index.d.ts +2 -2
  33. package/dist/{path-resolver-DwJO5XBn.d.ts → path-resolver-CfT7e_HT.d.ts} +2 -2
  34. package/dist/{plan-templates-CG_pInJV.d.ts → plan-templates-Q78an-GJ.d.ts} +4 -4
  35. package/dist/{provider-runner-DoohzfyD.d.ts → provider-runner-WDj28o7J.d.ts} +3 -3
  36. package/dist/{retry-policy-DOnwHAyz.d.ts → retry-policy-Dpxp4SET.d.ts} +1 -1
  37. package/dist/sdd/index.d.ts +3 -3
  38. package/dist/{secret-scrubber-C9UJxFCJ.d.ts → secret-scrubber-C2YCYtkn.d.ts} +1 -1
  39. package/dist/{secret-scrubber-DcTK9JHC.d.ts → secret-scrubber-CowtdEF8.d.ts} +1 -1
  40. package/dist/security/index.d.ts +3 -3
  41. package/dist/{selector-DVo3eT-P.d.ts → selector-CP39HhCe.d.ts} +1 -1
  42. package/dist/{session-reader-BXWxFAhS.d.ts → session-reader-Dwjn4WZR.d.ts} +1 -1
  43. package/dist/storage/index.d.ts +5 -5
  44. package/dist/storage/index.js +93 -10
  45. package/dist/storage/index.js.map +1 -1
  46. package/dist/{system-prompt-BBGles-N.d.ts → system-prompt-CfgXqyv2.d.ts} +1 -1
  47. package/dist/{tool-executor-CwpjhwHC.d.ts → tool-executor-D5NFi_LV.d.ts} +5 -5
  48. package/dist/types/index.d.ts +16 -15
  49. package/dist/types/index.js +101 -20
  50. package/dist/types/index.js.map +1 -1
  51. package/dist/utils/index.d.ts +1 -1
  52. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { U as Usage, a2 as Context, z as ToolProgressEvent, v as Tool } from './context-C8mBUzBv.js';
1
+ import { U as Usage, a5 as Context, D as ToolProgressEvent, x as Tool } from './context-bmR0YgBm.js';
2
2
 
3
3
  /**
4
4
  * EventBus — observe-only typed event bus.
@@ -1,21 +1,22 @@
1
- export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-CwpjhwHC.js';
2
- import { g as Provider, a2 as Context } from '../context-C8mBUzBv.js';
3
- import { a as Compactor, C as CompactReport } from '../compactor-BUJ8550X.js';
4
- import { M as MessageSelector } from '../selector-DVo3eT-P.js';
5
- import { E as EventBus } from '../events-DounT6pP.js';
6
- import { c as MiddlewareHandler } from '../system-prompt-BBGles-N.js';
7
- import { e as ContextWindowAggressiveOn, i as ContextWindowPolicy } from '../config-BHkYGzUT.js';
8
- import { A as Agent, R as RunResult, j as SystemPromptContributor } from '../index-DiIGZh5I.js';
9
- import { D as DoneCondition } from '../multi-agent-Iy8YUe3v.js';
1
+ export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-D5NFi_LV.js';
2
+ import { i as Provider, a5 as Context } from '../context-bmR0YgBm.js';
3
+ import { a as Compactor, C as CompactReport } from '../compactor-CWV1u-IU.js';
4
+ import { M as MessageSelector } from '../selector-CP39HhCe.js';
5
+ import { E as EventBus } from '../events-CEKFTmIY.js';
6
+ import { c as MiddlewareHandler } from '../system-prompt-CfgXqyv2.js';
7
+ import { e as ContextWindowAggressiveOn, i as ContextWindowPolicy } from '../config-C34JRwl4.js';
8
+ import { A as Agent, R as RunResult, j as SystemPromptContributor } from '../index-BJIFLGII.js';
9
+ import { D as DoneCondition } from '../multi-agent-Cm1wYSrw.js';
10
10
  import { J as JournalEntry } from '../goal-store-HHgaq5ue.js';
11
- import { A as AgentFactory } from '../agent-subagent-runner-BTloSwjE.js';
11
+ import { A as AgentFactory, D as DefaultMultiAgentCoordinator } from '../multi-agent-coordinator-CCupVFqv.js';
12
12
  import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-CxuWrsKK.js';
13
13
  import { W as WstackPaths } from '../wstack-paths-86YPFktR.js';
14
- import '../retry-policy-DOnwHAyz.js';
14
+ import '../retry-policy-Dpxp4SET.js';
15
15
  import '../models-registry-Y2xbog0E.js';
16
16
  import '../logger-BMQgxvdy.js';
17
17
  import '../observability-BhnVLBLS.js';
18
- import '../secret-scrubber-C9UJxFCJ.js';
18
+ import '../secret-scrubber-C2YCYtkn.js';
19
+ import 'node:events';
19
20
 
20
21
  interface SkillLoaderOptions {
21
22
  paths: WstackPaths;
@@ -301,7 +302,8 @@ interface EternalAutonomyOptions {
301
302
  * Maximum number of internal agent.run iterations the engine grants per
302
303
  * eternal-loop tick. The engine sets `autonomousContinue: true` so the
303
304
  * agent can run multi-step tasks end-to-end within one tick instead of
304
- * bouncing back to the engine after every single tool call. Default 50.
305
+ * bouncing back to the engine after every single tool call. Default 500.
306
+ * Previous 50 was far too low — agents hit the limit and restart constantly.
305
307
  */
306
308
  iterationMaxAgentSteps?: number;
307
309
  /**
@@ -573,6 +575,10 @@ declare class ParallelEternalEngine {
573
575
  private agentFactory;
574
576
  constructor(opts: ParallelEternalOptions);
575
577
  get currentState(): ParallelEngineState;
578
+ /**
579
+ * Get the underlying coordinator for stats/monitoring.
580
+ */
581
+ getCoordinator(): DefaultMultiAgentCoordinator | null;
576
582
  stop(): void;
577
583
  prime(): Promise<void>;
578
584
  run(): Promise<void>;
@@ -917,6 +917,22 @@ Summarize the following message range:`;
917
917
  };
918
918
 
919
919
  // src/types/errors.ts
920
+ var ERROR_CODES = {
921
+ // Provider
922
+ PROVIDER_RATE_LIMITED: "PROVIDER_RATE_LIMITED",
923
+ PROVIDER_AUTH_FAILED: "PROVIDER_AUTH_FAILED",
924
+ PROVIDER_OVERLOADED: "PROVIDER_OVERLOADED",
925
+ PROVIDER_INVALID_REQUEST: "PROVIDER_INVALID_REQUEST",
926
+ PROVIDER_SERVER_ERROR: "PROVIDER_SERVER_ERROR",
927
+ PROVIDER_NETWORK_ERROR: "PROVIDER_NETWORK_ERROR",
928
+ // Agent
929
+ AGENT_ITERATION_LIMIT: "AGENT_ITERATION_LIMIT",
930
+ AGENT_CONTEXT_OVERFLOW: "AGENT_CONTEXT_OVERFLOW",
931
+ AGENT_ABORTED: "AGENT_ABORTED",
932
+ AGENT_RUN_FAILED: "AGENT_RUN_FAILED",
933
+ // File system
934
+ FS_READ_FAILED: "FS_READ_FAILED",
935
+ FS_ATOMIC_WRITE_FAILED: "FS_ATOMIC_WRITE_FAILED"};
920
936
  var WrongStackError = class extends Error {
921
937
  code;
922
938
  subsystem;
@@ -951,23 +967,39 @@ var AgentError = class extends WrongStackError {
951
967
  message: opts.message,
952
968
  code: opts.code,
953
969
  subsystem: "agent",
954
- severity: opts.code === "AGENT_ABORTED" ? "warning" : "error",
955
- recoverable: opts.recoverable ?? opts.code === "AGENT_ITERATION_LIMIT",
970
+ severity: opts.code === ERROR_CODES.AGENT_ABORTED ? "warning" : "error",
971
+ recoverable: opts.recoverable ?? opts.code === ERROR_CODES.AGENT_ITERATION_LIMIT,
956
972
  context: opts.context,
957
973
  cause: opts.cause
958
974
  });
959
975
  this.name = "AgentError";
960
976
  }
961
977
  };
962
- function toWrongStackError(err, code = "AGENT_RUN_FAILED") {
978
+ function toWrongStackError(err, code = ERROR_CODES.AGENT_RUN_FAILED) {
963
979
  if (err instanceof WrongStackError) return err;
964
980
  const message = err instanceof Error ? err.message : String(err);
965
981
  return new AgentError({
966
982
  message,
967
- code: code === "UNKNOWN" ? "AGENT_RUN_FAILED" : code,
983
+ code: code === "UNKNOWN" ? ERROR_CODES.AGENT_RUN_FAILED : code,
968
984
  cause: err
969
985
  });
970
986
  }
987
+ var FsError = class extends WrongStackError {
988
+ path;
989
+ constructor(opts) {
990
+ super({
991
+ message: opts.message,
992
+ code: opts.code,
993
+ subsystem: "fs",
994
+ severity: "error",
995
+ recoverable: opts.code !== ERROR_CODES.FS_READ_FAILED,
996
+ context: { path: opts.path, ...opts.context },
997
+ cause: opts.cause
998
+ });
999
+ this.name = "FsError";
1000
+ this.path = opts.path;
1001
+ }
1002
+ };
971
1003
 
972
1004
  // src/execution/auto-compaction-middleware.ts
973
1005
  var AutoCompactionMiddleware = class {
@@ -1059,7 +1091,7 @@ var AutoCompactionMiddleware = class {
1059
1091
  if (fatal) {
1060
1092
  throw new AgentError({
1061
1093
  message: `Auto-compaction failed at ${pressure.level} threshold`,
1062
- code: "AGENT_CONTEXT_OVERFLOW",
1094
+ code: ERROR_CODES.AGENT_CONTEXT_OVERFLOW,
1063
1095
  recoverable: true,
1064
1096
  context: {
1065
1097
  level: pressure.level,
@@ -1688,7 +1720,16 @@ async function loadGoal(filePath) {
1688
1720
  }
1689
1721
  }
1690
1722
  async function saveGoal(filePath, goal) {
1691
- await atomicWrite(filePath, JSON.stringify(goal, null, 2), { mode: 384 });
1723
+ try {
1724
+ await atomicWrite(filePath, JSON.stringify(goal, null, 2), { mode: 384 });
1725
+ } catch (err) {
1726
+ throw new FsError({
1727
+ message: err instanceof Error ? err.message : String(err),
1728
+ code: ERROR_CODES.FS_ATOMIC_WRITE_FAILED,
1729
+ path: filePath,
1730
+ cause: err
1731
+ });
1732
+ }
1692
1733
  }
1693
1734
  function appendJournal(goal, entry) {
1694
1735
  const iteration = goal.iterations + 1;
@@ -1846,7 +1887,7 @@ var EternalAutonomyEngine = class {
1846
1887
  // Cap the inner loop so a runaway agent.run can't burn through
1847
1888
  // the iteration timeout — the engine's own outer loop is the
1848
1889
  // long-running thing, each tick should be bounded.
1849
- maxIterations: this.opts.iterationMaxAgentSteps ?? 50
1890
+ maxIterations: this.opts.iterationMaxAgentSteps ?? 500
1850
1891
  }
1851
1892
  );
1852
1893
  if (result.status === "aborted") {
@@ -2753,14 +2794,14 @@ function truncate(s, n) {
2753
2794
  return s.length <= n ? s : `${s.slice(0, n - 1)}\u2026`;
2754
2795
  }
2755
2796
  function providerStatusToCode(status, type) {
2756
- if (status === 0) return "PROVIDER_NETWORK_ERROR";
2757
- if (type === "rate_limit_error" || status === 429) return "PROVIDER_RATE_LIMITED";
2758
- if (type === "authentication_error" || status === 401) return "PROVIDER_AUTH_FAILED";
2759
- if (type === "overloaded_error" || status === 529) return "PROVIDER_OVERLOADED";
2760
- if (type === "invalid_request_error" || status === 400) return "PROVIDER_INVALID_REQUEST";
2761
- if (status === 408) return "PROVIDER_NETWORK_ERROR";
2762
- if (status >= 500) return "PROVIDER_SERVER_ERROR";
2763
- return "PROVIDER_INVALID_REQUEST";
2797
+ if (status === 0) return ERROR_CODES.PROVIDER_NETWORK_ERROR;
2798
+ if (type === "rate_limit_error" || status === 429) return ERROR_CODES.PROVIDER_RATE_LIMITED;
2799
+ if (type === "authentication_error" || status === 401) return ERROR_CODES.PROVIDER_AUTH_FAILED;
2800
+ if (type === "overloaded_error" || status === 529) return ERROR_CODES.PROVIDER_OVERLOADED;
2801
+ if (type === "invalid_request_error" || status === 400) return ERROR_CODES.PROVIDER_INVALID_REQUEST;
2802
+ if (status === 408) return ERROR_CODES.PROVIDER_NETWORK_ERROR;
2803
+ if (status >= 500) return ERROR_CODES.PROVIDER_SERVER_ERROR;
2804
+ return ERROR_CODES.PROVIDER_INVALID_REQUEST;
2764
2805
  }
2765
2806
  var FLEET_ROSTER_BUDGETS = {
2766
2807
  "audit-log": { timeoutMs: 7.5 * 60 * 60 * 1e3, maxIterations: 5e3, maxToolCalls: 15e3 },
@@ -2892,6 +2933,30 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
2892
2933
  this.drainPendingAsAborted("Coordinator stopAll() drained the pending queue");
2893
2934
  await Promise.allSettled([...this.subagents.keys()].map((id) => this.stop(id)));
2894
2935
  }
2936
+ async remove(subagentId) {
2937
+ await this.stop(subagentId);
2938
+ this.subagents.delete(subagentId);
2939
+ }
2940
+ /**
2941
+ * Get current coordinator stats for monitoring/debugging.
2942
+ */
2943
+ getStats() {
2944
+ let running = 0, idle = 0, stopped = 0;
2945
+ for (const [, entry] of this.subagents) {
2946
+ if (entry.status === "running") running++;
2947
+ else if (entry.status === "idle") idle++;
2948
+ else stopped++;
2949
+ }
2950
+ return {
2951
+ total: this.subagents.size,
2952
+ running,
2953
+ idle,
2954
+ stopped,
2955
+ inFlight: this.inFlight,
2956
+ pending: this.pendingTasks.length,
2957
+ completed: this.completedResults.length
2958
+ };
2959
+ }
2895
2960
  getStatus() {
2896
2961
  return {
2897
2962
  coordinatorId: this.coordinatorId,
@@ -3359,6 +3424,12 @@ var ParallelEternalEngine = class {
3359
3424
  get currentState() {
3360
3425
  return this.state;
3361
3426
  }
3427
+ /**
3428
+ * Get the underlying coordinator for stats/monitoring.
3429
+ */
3430
+ getCoordinator() {
3431
+ return this.coordinator;
3432
+ }
3362
3433
  stop() {
3363
3434
  this.stopRequested = true;
3364
3435
  void this.persistState("stopped").catch(() => {
@@ -3495,8 +3566,8 @@ Task: ${task}
3495
3566
  await coordinator.spawn({
3496
3567
  id: subagentId,
3497
3568
  name: `slot-${subagentId.slice(-6)}`,
3498
- maxIterations: 50,
3499
- maxToolCalls: 200,
3569
+ // Let the coordinator apply its default budget (from roster or generic).
3570
+ // Hardcoding low limits here defeats the x10 budget improvement.
3500
3571
  timeoutMs: this.timeoutMs
3501
3572
  });
3502
3573
  subagentIds.push(subagentId);
@@ -3513,7 +3584,7 @@ Task: ${task}
3513
3584
  let results = [];
3514
3585
  try {
3515
3586
  const ctrl = new AbortController();
3516
- const timer = setTimeout(() => ctrl.abort(), this.timeoutMs + 6e4);
3587
+ const timer = setTimeout(() => ctrl.abort(), Math.max(this.timeoutMs * 2, 72e5));
3517
3588
  try {
3518
3589
  results = await coordinator.awaitTasks(taskIds);
3519
3590
  } finally {
@@ -3787,16 +3858,18 @@ function buildGoalPreamble(goal) {
3787
3858
  ].join("\n");
3788
3859
  }
3789
3860
 
3861
+ // src/execution/regex-patterns.ts
3862
+ var NETWORK_ERR_RE = /ECONN|ETIMEDOUT|ETIME|ENOTFOUND|EAI_AGAIN|fetch failed/i;
3863
+
3790
3864
  // src/execution/retry-policy.ts
3791
- var DefaultRetryPolicy = class _DefaultRetryPolicy {
3792
- static NETWORK_ERR_RE = /ECONN|ETIMEDOUT|ETIME|ENOTFOUND|EAI_AGAIN|fetch failed/i;
3865
+ var DefaultRetryPolicy = class {
3793
3866
  shouldRetry(err, attempt) {
3794
3867
  if (err instanceof ProviderError) {
3795
3868
  if (!err.retryable) return false;
3796
3869
  return attempt < this.maxAttempts(err);
3797
3870
  }
3798
3871
  const msg = err.message ?? "";
3799
- const isNetwork = _DefaultRetryPolicy.NETWORK_ERR_RE.test(msg);
3872
+ const isNetwork = NETWORK_ERR_RE.test(msg);
3800
3873
  if (isNetwork) return attempt < 2;
3801
3874
  return false;
3802
3875
  }
@@ -3819,7 +3892,6 @@ var DefaultRetryPolicy = class _DefaultRetryPolicy {
3819
3892
 
3820
3893
  // src/execution/error-handler.ts
3821
3894
  var CONTEXT_OVERFLOW_RE = /context|too long|tokens/i;
3822
- var NETWORK_ERR_RE = /ECONN|ETIMEDOUT|ETIME|ENOTFOUND|EAI_AGAIN|fetch failed/i;
3823
3895
  function buildRecoveryStrategies(opts) {
3824
3896
  return [
3825
3897
  {