@wrongstack/core 0.6.7 → 0.7.2

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 (56) hide show
  1. package/dist/{agent-bridge-BCVxmrOn.d.ts → agent-bridge-Bji75Iv9.d.ts} +1 -1
  2. package/dist/{compactor-BUJ8550X.d.ts → compactor-BFKGzKd5.d.ts} +1 -1
  3. package/dist/{config-BHkYGzUT.d.ts → config-BXAhlqJb.d.ts} +1 -1
  4. package/dist/{context-C8mBUzBv.d.ts → context-BwxhvyW8.d.ts} +75 -3
  5. package/dist/coordination/index.d.ts +42 -12
  6. package/dist/coordination/index.js +2573 -40
  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 +21 -20
  10. package/dist/defaults/index.js +2896 -243
  11. package/dist/defaults/index.js.map +1 -1
  12. package/dist/{director-state-BmYi3DGA.d.ts → director-state-BUB7JRUr.d.ts} +1 -1
  13. package/dist/{events-DounT6pP.d.ts → events-AjrvHJ9V.d.ts} +25 -1
  14. package/dist/execution/index.d.ts +42 -13
  15. package/dist/execution/index.js +2497 -40
  16. package/dist/execution/index.js.map +1 -1
  17. package/dist/extension/index.d.ts +6 -6
  18. package/dist/extension/index.js +3 -1
  19. package/dist/extension/index.js.map +1 -1
  20. package/dist/{index-DiIGZh5I.d.ts → index-B2WWETRP.d.ts} +6 -6
  21. package/dist/index.d.ts +36 -27
  22. package/dist/index.js +2863 -137
  23. package/dist/index.js.map +1 -1
  24. package/dist/infrastructure/index.d.ts +6 -6
  25. package/dist/infrastructure/index.js +12 -0
  26. package/dist/infrastructure/index.js.map +1 -1
  27. package/dist/kernel/index.d.ts +9 -9
  28. package/dist/kernel/index.js +20 -4
  29. package/dist/kernel/index.js.map +1 -1
  30. package/dist/{mcp-servers-CXFfDN_d.d.ts → mcp-servers-BDM2Leff.d.ts} +3 -3
  31. package/dist/models/index.d.ts +2 -2
  32. package/dist/{multi-agent-Iy8YUe3v.d.ts → multi-agent-DenFfUv5.d.ts} +11 -3
  33. package/dist/multi-agent-coordinator-DGUn-5Bb.d.ts +448 -0
  34. package/dist/{index-BlVITqm-.d.ts → null-fleet-bus-DJMbqYhL.d.ts} +105 -107
  35. package/dist/observability/index.d.ts +2 -2
  36. package/dist/{path-resolver-DwJO5XBn.d.ts → path-resolver-C1NM67-u.d.ts} +2 -2
  37. package/dist/{plan-templates-CG_pInJV.d.ts → plan-templates-CNY6f82B.d.ts} +4 -4
  38. package/dist/{provider-runner-DoohzfyD.d.ts → provider-runner-Cmuevptw.d.ts} +3 -3
  39. package/dist/{retry-policy-DOnwHAyz.d.ts → retry-policy-mEBn5qpv.d.ts} +1 -1
  40. package/dist/sdd/index.d.ts +3 -3
  41. package/dist/{secret-scrubber-DcTK9JHC.d.ts → secret-scrubber-BmiGszvl.d.ts} +1 -1
  42. package/dist/{secret-scrubber-C9UJxFCJ.d.ts → secret-scrubber-bZ5AyhwJ.d.ts} +1 -1
  43. package/dist/security/index.d.ts +3 -3
  44. package/dist/{selector-DVo3eT-P.d.ts → selector-BmUma5iG.d.ts} +1 -1
  45. package/dist/{session-reader-BXWxFAhS.d.ts → session-reader-g-FKCyBw.d.ts} +1 -1
  46. package/dist/storage/index.d.ts +6 -6
  47. package/dist/storage/index.js +101 -14
  48. package/dist/storage/index.js.map +1 -1
  49. package/dist/{system-prompt-BBGles-N.d.ts → system-prompt-BKrzd_ci.d.ts} +1 -1
  50. package/dist/{tool-executor-CwpjhwHC.d.ts → tool-executor-BoM0U0qn.d.ts} +6 -5
  51. package/dist/types/index.d.ts +16 -15
  52. package/dist/types/index.js +130 -20
  53. package/dist/types/index.js.map +1 -1
  54. package/dist/utils/index.d.ts +1 -1
  55. package/package.json +1 -1
  56. package/dist/agent-subagent-runner-BTloSwjE.d.ts +0 -174
package/dist/index.js CHANGED
@@ -106,6 +106,53 @@ var init_atomic_write = __esm({
106
106
  });
107
107
 
108
108
  // src/types/errors.ts
109
+ var ERROR_CODES = {
110
+ // Provider
111
+ PROVIDER_RATE_LIMITED: "PROVIDER_RATE_LIMITED",
112
+ PROVIDER_AUTH_FAILED: "PROVIDER_AUTH_FAILED",
113
+ PROVIDER_OVERLOADED: "PROVIDER_OVERLOADED",
114
+ PROVIDER_INVALID_REQUEST: "PROVIDER_INVALID_REQUEST",
115
+ PROVIDER_SERVER_ERROR: "PROVIDER_SERVER_ERROR",
116
+ PROVIDER_NETWORK_ERROR: "PROVIDER_NETWORK_ERROR",
117
+ PROVIDER_CONTEXT_OVERFLOW: "PROVIDER_CONTEXT_OVERFLOW",
118
+ // Tool
119
+ TOOL_NOT_FOUND: "TOOL_NOT_FOUND",
120
+ TOOL_PERMISSION_DENIED: "TOOL_PERMISSION_DENIED",
121
+ TOOL_EXECUTION_FAILED: "TOOL_EXECUTION_FAILED",
122
+ TOOL_TIMEOUT: "TOOL_TIMEOUT",
123
+ TOOL_INPUT_INVALID: "TOOL_INPUT_INVALID",
124
+ // Config
125
+ CONFIG_INVALID: "CONFIG_INVALID",
126
+ CONFIG_NOT_FOUND: "CONFIG_NOT_FOUND",
127
+ CONFIG_PARSE_FAILED: "CONFIG_PARSE_FAILED",
128
+ CONFIG_MIGRATION_NEEDED: "CONFIG_MIGRATION_NEEDED",
129
+ // Plugin
130
+ PLUGIN_LOAD_FAILED: "PLUGIN_LOAD_FAILED",
131
+ PLUGIN_API_MISMATCH: "PLUGIN_API_MISMATCH",
132
+ PLUGIN_MISSING_DEPENDENCY: "PLUGIN_MISSING_DEPENDENCY",
133
+ // Agent
134
+ AGENT_ITERATION_LIMIT: "AGENT_ITERATION_LIMIT",
135
+ AGENT_CONTEXT_OVERFLOW: "AGENT_CONTEXT_OVERFLOW",
136
+ AGENT_ABORTED: "AGENT_ABORTED",
137
+ AGENT_RUN_FAILED: "AGENT_RUN_FAILED",
138
+ // Session
139
+ SESSION_NOT_FOUND: "SESSION_NOT_FOUND",
140
+ SESSION_CORRUPTED: "SESSION_CORRUPTED",
141
+ SESSION_WRITE_FAILED: "SESSION_WRITE_FAILED",
142
+ // Container / Registry
143
+ CONTAINER_TOKEN_ALREADY_BOUND: "CONTAINER_TOKEN_ALREADY_BOUND",
144
+ CONTAINER_TOKEN_NOT_BOUND: "CONTAINER_TOKEN_NOT_BOUND",
145
+ REGISTRY_DUPLICATE: "REGISTRY_DUPLICATE",
146
+ REGISTRY_NOT_FOUND: "REGISTRY_NOT_FOUND",
147
+ // File system
148
+ FS_READ_FAILED: "FS_READ_FAILED",
149
+ FS_WRITE_FAILED: "FS_WRITE_FAILED",
150
+ FS_MKDIR_FAILED: "FS_MKDIR_FAILED",
151
+ FS_DELETE_FAILED: "FS_DELETE_FAILED",
152
+ FS_ATOMIC_WRITE_FAILED: "FS_ATOMIC_WRITE_FAILED",
153
+ // General
154
+ UNKNOWN: "UNKNOWN"
155
+ };
109
156
  var WrongStackError = class extends Error {
110
157
  code;
111
158
  subsystem;
@@ -171,7 +218,7 @@ var PluginError = class extends WrongStackError {
171
218
  code: opts.code,
172
219
  subsystem: "plugin",
173
220
  severity: "error",
174
- recoverable: opts.code === "PLUGIN_MISSING_DEPENDENCY",
221
+ recoverable: opts.code === ERROR_CODES.PLUGIN_MISSING_DEPENDENCY,
175
222
  context: { plugin: opts.pluginName, ...opts.context },
176
223
  cause: opts.cause
177
224
  });
@@ -185,20 +232,20 @@ var AgentError = class extends WrongStackError {
185
232
  message: opts.message,
186
233
  code: opts.code,
187
234
  subsystem: "agent",
188
- severity: opts.code === "AGENT_ABORTED" ? "warning" : "error",
189
- recoverable: opts.recoverable ?? opts.code === "AGENT_ITERATION_LIMIT",
235
+ severity: opts.code === ERROR_CODES.AGENT_ABORTED ? "warning" : "error",
236
+ recoverable: opts.recoverable ?? opts.code === ERROR_CODES.AGENT_ITERATION_LIMIT,
190
237
  context: opts.context,
191
238
  cause: opts.cause
192
239
  });
193
240
  this.name = "AgentError";
194
241
  }
195
242
  };
196
- function toWrongStackError(err, code = "AGENT_RUN_FAILED") {
243
+ function toWrongStackError(err, code = ERROR_CODES.AGENT_RUN_FAILED) {
197
244
  if (err instanceof WrongStackError) return err;
198
245
  const message = err instanceof Error ? err.message : String(err);
199
246
  return new AgentError({
200
247
  message,
201
- code: code === "UNKNOWN" ? "AGENT_RUN_FAILED" : code,
248
+ code: code === "UNKNOWN" ? ERROR_CODES.AGENT_RUN_FAILED : code,
202
249
  cause: err
203
250
  });
204
251
  }
@@ -209,8 +256,8 @@ var SessionError = class extends WrongStackError {
209
256
  message: opts.message,
210
257
  code: opts.code,
211
258
  subsystem: "session",
212
- severity: opts.code === "SESSION_WRITE_FAILED" ? "error" : "warning",
213
- recoverable: opts.code !== "SESSION_CORRUPTED",
259
+ severity: opts.code === ERROR_CODES.SESSION_WRITE_FAILED ? "error" : "warning",
260
+ recoverable: opts.code !== ERROR_CODES.SESSION_CORRUPTED,
214
261
  context: { sessionId: opts.sessionId, ...opts.context },
215
262
  cause: opts.cause
216
263
  });
@@ -218,6 +265,22 @@ var SessionError = class extends WrongStackError {
218
265
  this.sessionId = opts.sessionId;
219
266
  }
220
267
  };
268
+ var FsError = class extends WrongStackError {
269
+ path;
270
+ constructor(opts) {
271
+ super({
272
+ message: opts.message,
273
+ code: opts.code,
274
+ subsystem: "fs",
275
+ severity: "error",
276
+ recoverable: opts.code !== ERROR_CODES.FS_READ_FAILED,
277
+ context: { path: opts.path, ...opts.context },
278
+ cause: opts.cause
279
+ });
280
+ this.name = "FsError";
281
+ this.path = opts.path;
282
+ }
283
+ };
221
284
  function isWrongStackError(err) {
222
285
  return err instanceof WrongStackError;
223
286
  }
@@ -236,6 +299,9 @@ function isSessionError(err) {
236
299
  function isAgentError(err) {
237
300
  return err instanceof AgentError;
238
301
  }
302
+ function isFsError(err) {
303
+ return err instanceof FsError;
304
+ }
239
305
 
240
306
  // src/kernel/container.ts
241
307
  var Container = class {
@@ -244,7 +310,7 @@ var Container = class {
244
310
  if (this.entries.has(token)) {
245
311
  throw new WrongStackError({
246
312
  message: `Container: token "${token.description ?? "unknown"}" already bound`,
247
- code: "CONTAINER_TOKEN_ALREADY_BOUND",
313
+ code: ERROR_CODES.CONTAINER_TOKEN_ALREADY_BOUND,
248
314
  subsystem: "container",
249
315
  context: { token: token.description }
250
316
  });
@@ -261,7 +327,7 @@ var Container = class {
261
327
  if (!existing) {
262
328
  throw new WrongStackError({
263
329
  message: `Container: cannot override "${token.description ?? "unknown"}" \u2014 not bound`,
264
- code: "CONTAINER_TOKEN_NOT_BOUND",
330
+ code: ERROR_CODES.CONTAINER_TOKEN_NOT_BOUND,
265
331
  subsystem: "container",
266
332
  context: { token: token.description }
267
333
  });
@@ -278,7 +344,7 @@ var Container = class {
278
344
  if (!existing) {
279
345
  throw new WrongStackError({
280
346
  message: `Container: cannot decorate "${token.description ?? "unknown"}" \u2014 not bound`,
281
- code: "CONTAINER_TOKEN_NOT_BOUND",
347
+ code: ERROR_CODES.CONTAINER_TOKEN_NOT_BOUND,
282
348
  subsystem: "container",
283
349
  context: { token: token.description }
284
350
  });
@@ -292,7 +358,7 @@ var Container = class {
292
358
  if (!entry) {
293
359
  throw new WrongStackError({
294
360
  message: `Container: token "${token.description ?? "unknown"}" not bound`,
295
- code: "CONTAINER_TOKEN_NOT_BOUND",
361
+ code: ERROR_CODES.CONTAINER_TOKEN_NOT_BOUND,
296
362
  subsystem: "container",
297
363
  context: { token: token.description }
298
364
  });
@@ -600,6 +666,18 @@ var EventBus = class {
600
666
  wildcardCount() {
601
667
  return this.wildcards.length;
602
668
  }
669
+ /**
670
+ * True if anything would receive an emit for `event` — a named listener
671
+ * OR a wildcard/regex pattern that matches the event name. Unlike
672
+ * `listenerCount`, this DOES account for wildcards, so callers that gate
673
+ * behavior on "is anyone listening?" (e.g. SubagentBudget deciding whether
674
+ * to negotiate a soft limit vs hard-stop) don't misfire when the only
675
+ * subscriber is a pattern listener like the FleetBus's `onPattern('*')`.
676
+ */
677
+ hasListenerFor(event) {
678
+ if ((this.listeners.get(event)?.size ?? 0) > 0) return true;
679
+ return this.wildcards.some((w) => w.match(event));
680
+ }
603
681
  };
604
682
  var ScopedEventBus = class extends EventBus {
605
683
  // Track registrations by a unique counter key so that EventBus.once()'s
@@ -895,16 +973,30 @@ function truncate(s, n) {
895
973
  return s.length <= n ? s : `${s.slice(0, n - 1)}\u2026`;
896
974
  }
897
975
  function providerStatusToCode(status, type) {
898
- if (status === 0) return "PROVIDER_NETWORK_ERROR";
899
- if (type === "rate_limit_error" || status === 429) return "PROVIDER_RATE_LIMITED";
900
- if (type === "authentication_error" || status === 401) return "PROVIDER_AUTH_FAILED";
901
- if (type === "overloaded_error" || status === 529) return "PROVIDER_OVERLOADED";
902
- if (type === "invalid_request_error" || status === 400) return "PROVIDER_INVALID_REQUEST";
903
- if (status === 408) return "PROVIDER_NETWORK_ERROR";
904
- if (status >= 500) return "PROVIDER_SERVER_ERROR";
905
- return "PROVIDER_INVALID_REQUEST";
976
+ if (status === 0) return ERROR_CODES.PROVIDER_NETWORK_ERROR;
977
+ if (type === "rate_limit_error" || status === 429) return ERROR_CODES.PROVIDER_RATE_LIMITED;
978
+ if (type === "authentication_error" || status === 401) return ERROR_CODES.PROVIDER_AUTH_FAILED;
979
+ if (type === "overloaded_error" || status === 529) return ERROR_CODES.PROVIDER_OVERLOADED;
980
+ if (type === "invalid_request_error" || status === 400) return ERROR_CODES.PROVIDER_INVALID_REQUEST;
981
+ if (status === 408) return ERROR_CODES.PROVIDER_NETWORK_ERROR;
982
+ if (status >= 500) return ERROR_CODES.PROVIDER_SERVER_ERROR;
983
+ return ERROR_CODES.PROVIDER_INVALID_REQUEST;
906
984
  }
907
985
 
986
+ // src/types/default-config.ts
987
+ var DEFAULT_TOOLS_CONFIG = Object.freeze({
988
+ defaultExecutionStrategy: "smart",
989
+ maxIterations: 100,
990
+ iterationTimeoutMs: 3e5,
991
+ sessionTimeoutMs: 18e5,
992
+ perIterationOutputCapBytes: 1e5,
993
+ autoExtendLimit: true
994
+ });
995
+ var DEFAULT_CONTEXT_CONFIG = Object.freeze({
996
+ preserveK: 10,
997
+ eliseThreshold: 2e3
998
+ });
999
+
908
1000
  // src/types/secret-vault.ts
909
1001
  var ENCRYPTED_PREFIX = "enc:v1:";
910
1002
 
@@ -1230,6 +1322,7 @@ function formatCtx(ctx) {
1230
1322
  }
1231
1323
 
1232
1324
  // src/infrastructure/token-counter.ts
1325
+ var PRICE_CACHE_MAX_SIZE = 100;
1233
1326
  var DefaultTokenCounter = class {
1234
1327
  input = 0;
1235
1328
  output = 0;
@@ -1260,6 +1353,10 @@ var DefaultTokenCounter = class {
1260
1353
  if (price) {
1261
1354
  this.applyPrice(usage, price);
1262
1355
  } else if (this.registry && this.providerId && model) {
1356
+ if (this.priceCache.size >= PRICE_CACHE_MAX_SIZE) {
1357
+ const keys = [...this.priceCache.keys()];
1358
+ this.priceCache.delete(keys[0]);
1359
+ }
1263
1360
  void this.registry.getModel(this.providerId, model).then((m) => {
1264
1361
  if (m) {
1265
1362
  const p = priceFromModel(m);
@@ -1281,6 +1378,10 @@ var DefaultTokenCounter = class {
1281
1378
  this.lastInput = usage.input;
1282
1379
  this.lastCacheRead = usage.cacheRead ?? 0;
1283
1380
  const price = priceFromModel(resolved);
1381
+ if (this.priceCache.size >= PRICE_CACHE_MAX_SIZE) {
1382
+ const keys = [...this.priceCache.keys()];
1383
+ this.priceCache.delete(keys[0]);
1384
+ }
1284
1385
  this.priceCache.set(resolved.modelId, price);
1285
1386
  this.applyPrice(usage, price);
1286
1387
  }
@@ -1736,9 +1837,11 @@ var DefaultPathResolver = class {
1736
1837
  }
1737
1838
  };
1738
1839
 
1840
+ // src/execution/regex-patterns.ts
1841
+ var NETWORK_ERR_RE = /ECONN|ETIMEDOUT|ETIME|ENOTFOUND|EAI_AGAIN|fetch failed/i;
1842
+
1739
1843
  // src/execution/error-handler.ts
1740
1844
  var CONTEXT_OVERFLOW_RE = /context|too long|tokens/i;
1741
- var NETWORK_ERR_RE = /ECONN|ETIMEDOUT|ETIME|ENOTFOUND|EAI_AGAIN|fetch failed/i;
1742
1845
  function buildRecoveryStrategies(opts) {
1743
1846
  return [
1744
1847
  {
@@ -1845,15 +1948,14 @@ var DefaultErrorHandler = class {
1845
1948
  };
1846
1949
 
1847
1950
  // src/execution/retry-policy.ts
1848
- var DefaultRetryPolicy = class _DefaultRetryPolicy {
1849
- static NETWORK_ERR_RE = /ECONN|ETIMEDOUT|ETIME|ENOTFOUND|EAI_AGAIN|fetch failed/i;
1951
+ var DefaultRetryPolicy = class {
1850
1952
  shouldRetry(err, attempt) {
1851
1953
  if (err instanceof ProviderError) {
1852
1954
  if (!err.retryable) return false;
1853
1955
  return attempt < this.maxAttempts(err);
1854
1956
  }
1855
1957
  const msg = err.message ?? "";
1856
- const isNetwork = _DefaultRetryPolicy.NETWORK_ERR_RE.test(msg);
1958
+ const isNetwork = NETWORK_ERR_RE.test(msg);
1857
1959
  if (isNetwork) return attempt < 2;
1858
1960
  return false;
1859
1961
  }
@@ -2789,6 +2891,11 @@ var ToolExecutor = class {
2789
2891
  budget = this.decrementBudget(result, budget);
2790
2892
  return { result, tool, durationMs: Date.now() - start };
2791
2893
  }
2894
+ if (hasMalformedArguments(use.input)) {
2895
+ const result = this.malformedInputResult(use);
2896
+ budget = this.decrementBudget(result, budget);
2897
+ return { result, tool, durationMs: Date.now() - start };
2898
+ }
2792
2899
  const decision = await this.opts.permissionPolicy.evaluate(tool, use.input, ctx);
2793
2900
  if (decision.permission === "deny") {
2794
2901
  const result = this.deniedResult(use, decision.reason);
@@ -2992,6 +3099,14 @@ var ToolExecutor = class {
2992
3099
  is_error: true
2993
3100
  };
2994
3101
  }
3102
+ malformedInputResult(use) {
3103
+ return {
3104
+ type: "tool_result",
3105
+ tool_use_id: use.id,
3106
+ content: `Tool "${use.name}" received arguments that were not a valid JSON object, so they could not be parsed. Re-issue the call with the arguments encoded as a single well-formed JSON object matching the tool's input schema.`,
3107
+ is_error: true
3108
+ };
3109
+ }
2995
3110
  deniedResult(use, reason) {
2996
3111
  return {
2997
3112
  type: "tool_result",
@@ -3037,6 +3152,13 @@ var ToolExecutor = class {
3037
3152
  return void 0;
3038
3153
  }
3039
3154
  };
3155
+ var MALFORMED_ARG_MARKERS = ["__raw", "__raw_arguments", "_raw"];
3156
+ function hasMalformedArguments(input) {
3157
+ if (!input || typeof input !== "object" || Array.isArray(input)) return false;
3158
+ const obj = input;
3159
+ const keys = Object.keys(obj);
3160
+ return keys.length === 1 && MALFORMED_ARG_MARKERS.includes(keys[0]);
3161
+ }
3040
3162
 
3041
3163
  // src/utils/regex-guard.ts
3042
3164
  var MAX_PATTERN_LEN = 512;
@@ -3922,8 +4044,16 @@ var DefaultSessionStore = class {
3922
4044
  }
3923
4045
  }
3924
4046
  async resume(id) {
3925
- const data = await this.load(id);
3926
4047
  const file = path6.join(this.dir, `${id}.jsonl`);
4048
+ try {
4049
+ await fsp2.access(file, fsp2.constants.R_OK);
4050
+ } catch {
4051
+ throw new Error(
4052
+ `Session "${id}" not found \u2014 the session file does not exist or was deleted.`,
4053
+ { cause: new Error("ENOENT") }
4054
+ );
4055
+ }
4056
+ const data = await this.load(id);
3927
4057
  let handle;
3928
4058
  try {
3929
4059
  handle = await fsp2.open(file, "a", 384);
@@ -4820,16 +4950,16 @@ var BEHAVIOR_DEFAULTS = {
4820
4950
  softThreshold: 0.75,
4821
4951
  hardThreshold: 0.9,
4822
4952
  autoCompact: true,
4823
- preserveK: 10,
4824
- eliseThreshold: 2e3
4953
+ preserveK: DEFAULT_CONTEXT_CONFIG.preserveK,
4954
+ eliseThreshold: DEFAULT_CONTEXT_CONFIG.eliseThreshold
4825
4955
  },
4826
4956
  tools: {
4827
- defaultExecutionStrategy: "smart",
4828
- maxIterations: 100,
4829
- iterationTimeoutMs: 3e5,
4830
- sessionTimeoutMs: 18e5,
4831
- perIterationOutputCapBytes: 1e5,
4832
- autoExtendLimit: true
4957
+ defaultExecutionStrategy: DEFAULT_TOOLS_CONFIG.defaultExecutionStrategy,
4958
+ maxIterations: DEFAULT_TOOLS_CONFIG.maxIterations,
4959
+ iterationTimeoutMs: DEFAULT_TOOLS_CONFIG.iterationTimeoutMs,
4960
+ sessionTimeoutMs: DEFAULT_TOOLS_CONFIG.sessionTimeoutMs,
4961
+ perIterationOutputCapBytes: DEFAULT_TOOLS_CONFIG.perIterationOutputCapBytes,
4962
+ autoExtendLimit: DEFAULT_TOOLS_CONFIG.autoExtendLimit
4833
4963
  },
4834
4964
  log: { level: "info" },
4835
4965
  features: {
@@ -4843,19 +4973,23 @@ var BEHAVIOR_DEFAULTS = {
4843
4973
  var ENV_MAP = {
4844
4974
  WRONGSTACK_PROVIDER: (c, v) => {
4845
4975
  c.provider = v;
4846
- (c._envSource ??= /* @__PURE__ */ new Set()).add("provider");
4976
+ if (c._envSource === void 0) c._envSource = /* @__PURE__ */ new Set();
4977
+ c._envSource.add("provider");
4847
4978
  },
4848
4979
  WRONGSTACK_MODEL: (c, v) => {
4849
4980
  c.model = v;
4850
- (c._envSource ??= /* @__PURE__ */ new Set()).add("model");
4981
+ if (c._envSource === void 0) c._envSource = /* @__PURE__ */ new Set();
4982
+ c._envSource.add("model");
4851
4983
  },
4852
4984
  WRONGSTACK_API_KEY: (c, v) => {
4853
4985
  c.apiKey = v;
4854
- (c._envSource ??= /* @__PURE__ */ new Set()).add("apiKey");
4986
+ if (c._envSource === void 0) c._envSource = /* @__PURE__ */ new Set();
4987
+ c._envSource.add("apiKey");
4855
4988
  },
4856
4989
  WRONGSTACK_BASE_URL: (c, v) => {
4857
4990
  c.baseUrl = v;
4858
- (c._envSource ??= /* @__PURE__ */ new Set()).add("baseUrl");
4991
+ if (c._envSource === void 0) c._envSource = /* @__PURE__ */ new Set();
4992
+ c._envSource.add("baseUrl");
4859
4993
  },
4860
4994
  WRONGSTACK_LOG_LEVEL: (c, v) => {
4861
4995
  if (!c.log) c.log = { level: "info" };
@@ -6521,7 +6655,8 @@ var IntelligentCompactor = class {
6521
6655
  } catch {
6522
6656
  const toolNames = /* @__PURE__ */ new Set();
6523
6657
  const filePaths = /* @__PURE__ */ new Set();
6524
- let userTurns = 0, assistantTurns = 0;
6658
+ let userTurns = 0;
6659
+ let assistantTurns = 0;
6525
6660
  for (const m of toSummarize) {
6526
6661
  if (m.role === "user") userTurns++;
6527
6662
  else if (m.role === "assistant") {
@@ -7079,12 +7214,12 @@ Summarize the following message range:`;
7079
7214
  return total;
7080
7215
  }
7081
7216
  roughTokenEstimate(text) {
7082
- return Math.max(1, Math.ceil(text.length / 4));
7217
+ return Math.max(1, Math.ceil(text.length / 3.5));
7083
7218
  }
7084
7219
  };
7085
7220
 
7086
7221
  // src/execution/auto-compaction-middleware.ts
7087
- var AutoCompactionMiddleware = class {
7222
+ var AutoCompactionMiddleware = class _AutoCompactionMiddleware {
7088
7223
  name = "AutoCompaction";
7089
7224
  compactor;
7090
7225
  estimator;
@@ -7097,6 +7232,13 @@ var AutoCompactionMiddleware = class {
7097
7232
  events;
7098
7233
  failureMode;
7099
7234
  policyProvider;
7235
+ /**
7236
+ * Overhead factor applied to the rough message-token estimate to produce a
7237
+ * figure comparable to the real API request size (system prompt + tool defs).
7238
+ * Without this factor, raw message tokens undercount real load by 15-50% in
7239
+ * short conversations, causing premature compaction triggers.
7240
+ */
7241
+ static OVERHEAD_FACTOR = 1.3;
7100
7242
  /**
7101
7243
  * @param compactor Compactor to use for compaction.
7102
7244
  * @param maxContext Provider's max context window in tokens.
@@ -7128,7 +7270,8 @@ var AutoCompactionMiddleware = class {
7128
7270
  }
7129
7271
  handler() {
7130
7272
  return async (ctx, next) => {
7131
- const tokens = this.estimator(ctx);
7273
+ const rawTokens = this.estimator(ctx);
7274
+ const tokens = Math.ceil(rawTokens * _AutoCompactionMiddleware.OVERHEAD_FACTOR);
7132
7275
  const load = tokens / this._maxContext;
7133
7276
  const policy = this.policyProvider?.(ctx);
7134
7277
  const thresholds = policy?.thresholds ?? {
@@ -7158,6 +7301,7 @@ var AutoCompactionMiddleware = class {
7158
7301
  report,
7159
7302
  aggressive
7160
7303
  });
7304
+ ctx.clearFileTracking();
7161
7305
  } catch (err) {
7162
7306
  const error = err instanceof Error ? err : new Error(String(err));
7163
7307
  const fatal = this.failureMode === "throw" || this.failureMode === "throw_on_hard" && pressure.level === "hard";
@@ -7173,7 +7317,7 @@ var AutoCompactionMiddleware = class {
7173
7317
  if (fatal) {
7174
7318
  throw new AgentError({
7175
7319
  message: `Auto-compaction failed at ${pressure.level} threshold`,
7176
- code: "AGENT_CONTEXT_OVERFLOW",
7320
+ code: ERROR_CODES.AGENT_CONTEXT_OVERFLOW,
7177
7321
  recoverable: true,
7178
7322
  context: {
7179
7323
  level: pressure.level,
@@ -7376,7 +7520,16 @@ async function loadGoal(filePath) {
7376
7520
  }
7377
7521
  }
7378
7522
  async function saveGoal(filePath, goal) {
7379
- await atomicWrite(filePath, JSON.stringify(goal, null, 2), { mode: 384 });
7523
+ try {
7524
+ await atomicWrite(filePath, JSON.stringify(goal, null, 2), { mode: 384 });
7525
+ } catch (err) {
7526
+ throw new FsError({
7527
+ message: err instanceof Error ? err.message : String(err),
7528
+ code: ERROR_CODES.FS_ATOMIC_WRITE_FAILED,
7529
+ path: filePath,
7530
+ cause: err
7531
+ });
7532
+ }
7380
7533
  }
7381
7534
  function emptyGoal(goal) {
7382
7535
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -7591,7 +7744,7 @@ var EternalAutonomyEngine = class {
7591
7744
  // Cap the inner loop so a runaway agent.run can't burn through
7592
7745
  // the iteration timeout — the engine's own outer loop is the
7593
7746
  // long-running thing, each tick should be bounded.
7594
- maxIterations: this.opts.iterationMaxAgentSteps ?? 50
7747
+ maxIterations: this.opts.iterationMaxAgentSteps ?? 500
7595
7748
  }
7596
7749
  );
7597
7750
  if (result.status === "aborted") {
@@ -7927,7 +8080,7 @@ ${recentJournal}` : "No prior iterations.",
7927
8080
  const cap = this.opts.transientBackoffMaxMs ?? 6e4;
7928
8081
  if (base <= 0) return 0;
7929
8082
  const exponent = Math.max(0, this.consecutiveTransientRetries - 1);
7930
- return Math.min(cap, base * Math.pow(2, exponent));
8083
+ return Math.min(cap, base * 2 ** exponent);
7931
8084
  }
7932
8085
  /**
7933
8086
  * Sleep that wakes early if `stopRequested` flips. Polls every 250 ms
@@ -8096,7 +8249,7 @@ var SubagentBudget = class _SubagentBudget {
8096
8249
  this._onThreshold = fn;
8097
8250
  }
8098
8251
  constructor(limits = {}) {
8099
- this.limits = Object.freeze({ ...limits });
8252
+ this.limits = { ...limits };
8100
8253
  }
8101
8254
  start() {
8102
8255
  this.startTime = Date.now();
@@ -8122,7 +8275,7 @@ var SubagentBudget = class _SubagentBudget {
8122
8275
  throw new BudgetExceededError(kind, limit, used);
8123
8276
  }
8124
8277
  const bus = this._events;
8125
- if (!bus || bus.listenerCount("budget.threshold_reached") === 0) {
8278
+ if (!bus || !bus.hasListenerFor("budget.threshold_reached")) {
8126
8279
  throw new BudgetExceededError(kind, limit, used);
8127
8280
  }
8128
8281
  if (this.pendingExtensions.has(kind)) return;
@@ -8153,7 +8306,7 @@ var SubagentBudget = class _SubagentBudget {
8153
8306
  // Director would leave the budget permanently in "asking" state.
8154
8307
  requestDecision: () => {
8155
8308
  const bus = this._events;
8156
- if (!bus || bus.listenerCount("budget.threshold_reached") === 0) {
8309
+ if (!bus || !bus.hasListenerFor("budget.threshold_reached")) {
8157
8310
  return Promise.resolve("stop");
8158
8311
  }
8159
8312
  return new Promise((resolve5) => {
@@ -8393,47 +8546,2345 @@ function makeAgentSubagentRunner(opts) {
8393
8546
  }
8394
8547
  }
8395
8548
  }
8396
- if (budgetError) {
8397
- if ("decision" in budgetError) {
8398
- const decision = await budgetError.decision;
8399
- if (decision === "stop") {
8400
- budgetError = new BudgetExceededError(
8401
- budgetError.kind,
8402
- budgetError.limit,
8403
- budgetError.used
8404
- );
8405
- } else {
8406
- budgetError = null;
8407
- }
8408
- }
8409
- if (budgetError) throw budgetError;
8549
+ if (budgetError) {
8550
+ if ("decision" in budgetError) {
8551
+ const decision = await budgetError.decision;
8552
+ if (decision === "stop") {
8553
+ budgetError = new BudgetExceededError(
8554
+ budgetError.kind,
8555
+ budgetError.limit,
8556
+ budgetError.used
8557
+ );
8558
+ } else {
8559
+ budgetError = null;
8560
+ }
8561
+ }
8562
+ if (budgetError) throw budgetError;
8563
+ }
8564
+ if (result.status === "failed") {
8565
+ throw result.error instanceof Error ? result.error : new Error(String(result.error ?? "agent failed"));
8566
+ }
8567
+ if (result.status === "aborted") {
8568
+ throw new Error("agent aborted");
8569
+ }
8570
+ if (result.status === "max_iterations") {
8571
+ throw new Error("agent exhausted iteration limit");
8572
+ }
8573
+ const usage = ctx.budget.usage();
8574
+ const finalText = (result.finalText ?? "").trim();
8575
+ if (finalText.length === 0 && usage.toolCalls === 0) {
8576
+ throw new Error("empty response");
8577
+ }
8578
+ if (finalText.length === 0 && lastToolFailed !== null) {
8579
+ throw new Error(`tool failed: ${lastToolFailed}`);
8580
+ }
8581
+ return {
8582
+ result: result.finalText,
8583
+ iterations: result.iterations,
8584
+ toolCalls: usage.toolCalls
8585
+ };
8586
+ };
8587
+ }
8588
+ function defaultFormatTaskInput(task) {
8589
+ return task.description ?? "";
8590
+ }
8591
+
8592
+ // src/coordination/agents/types.ts
8593
+ var HOUR = 60 * 60 * 1e3;
8594
+ var LIGHT_BUDGET = {
8595
+ timeoutMs: 3 * HOUR,
8596
+ maxIterations: 3e3,
8597
+ maxToolCalls: 8e3
8598
+ };
8599
+ var MEDIUM_BUDGET = {
8600
+ timeoutMs: 5 * HOUR,
8601
+ maxIterations: 5e3,
8602
+ maxToolCalls: 14e3
8603
+ };
8604
+ var HEAVY_BUDGET = {
8605
+ timeoutMs: 10 * HOUR,
8606
+ maxIterations: 8e3,
8607
+ maxToolCalls: 2e4
8608
+ };
8609
+ var TOOLS = {
8610
+ /** Pure read/inspect — safe for analysis and review agents. */
8611
+ read: ["read", "grep", "glob", "search", "tree"],
8612
+ /** Read + structured inspection (logs, diffs, json, dependency audit). */
8613
+ inspect: ["read", "grep", "glob", "search", "tree", "json", "diff", "logs", "audit"],
8614
+ /** Read + edit (no shell). For agents that write code/docs but don't run it. */
8615
+ write: ["read", "grep", "glob", "search", "tree", "write", "edit", "replace", "patch"],
8616
+ /** Full build loop: edit + run (lint/format/typecheck/test/bash). */
8617
+ build: [
8618
+ "read",
8619
+ "grep",
8620
+ "glob",
8621
+ "search",
8622
+ "tree",
8623
+ "write",
8624
+ "edit",
8625
+ "replace",
8626
+ "patch",
8627
+ "bash",
8628
+ "exec",
8629
+ "lint",
8630
+ "format",
8631
+ "typecheck",
8632
+ "test"
8633
+ ],
8634
+ /** Version control. */
8635
+ vcs: ["read", "grep", "glob", "git", "diff"],
8636
+ /** Dependency management + CVE audit. */
8637
+ deps: ["read", "grep", "glob", "install", "outdated", "audit", "json"],
8638
+ /** Documentation authoring. */
8639
+ docs: ["read", "grep", "glob", "search", "tree", "write", "edit", "document"],
8640
+ /** Web research. */
8641
+ research: ["read", "grep", "glob", "search", "fetch"]
8642
+ };
8643
+
8644
+ // src/coordination/agents/phase1-discovery.ts
8645
+ var DISCOVERY_AGENTS = [
8646
+ {
8647
+ config: {
8648
+ id: "explore",
8649
+ name: "Explore",
8650
+ role: "explore",
8651
+ tools: [...TOOLS.read],
8652
+ prompt: `You are the Explore agent. Your job is to map an unfamiliar codebase
8653
+ and report its structure, entry points, and architecture \u2014 fast and read-only.
8654
+
8655
+ Scope:
8656
+ - Locate entry points, build config, package boundaries, and dependency direction
8657
+ - Identify the dominant patterns (DI, event bus, layering) and where they live
8658
+ - Trace how a feature flows across files without modifying anything
8659
+ - Surface the 5-10 files most relevant to a given question
8660
+
8661
+ Input format you accept:
8662
+ { "task": "map | locate | trace", "question": "<what to find>", "scope": ["packages/core"] }
8663
+
8664
+ Output: Markdown map with sections:
8665
+ - ## Overview (one paragraph: what this codebase is)
8666
+ - ## Key Files (table: file:line \u2014 role)
8667
+ - ## Flow (how the relevant feature moves across files)
8668
+ - ## Open Questions (anything that needs the user to clarify)
8669
+
8670
+ Working rules:
8671
+ - Read-only \u2014 never edit, write, or run shell commands
8672
+ - Always cite file:line; never describe code you haven't read
8673
+ - Prefer breadth first (glob/tree), then depth (read) on the hottest files
8674
+ - If the question is ambiguous, state your interpretation before answering`
8675
+ },
8676
+ budget: MEDIUM_BUDGET,
8677
+ capability: {
8678
+ phase: "discovery",
8679
+ summary: "Maps unfamiliar codebases: entry points, structure, architecture, feature flow (read-only).",
8680
+ keywords: [
8681
+ "explore",
8682
+ "map",
8683
+ "understand",
8684
+ "where is",
8685
+ "how does",
8686
+ "codebase",
8687
+ "architecture",
8688
+ "structure",
8689
+ "overview",
8690
+ "find file",
8691
+ "entry point",
8692
+ "orient"
8693
+ ]
8694
+ }
8695
+ },
8696
+ {
8697
+ config: {
8698
+ id: "search",
8699
+ name: "Search",
8700
+ role: "search",
8701
+ tools: [...TOOLS.read],
8702
+ prompt: `You are the Search agent. Your job is semantic and lexical code search
8703
+ across one or many repositories: find every place a concept, symbol, or pattern
8704
+ appears and rank the hits by relevance.
8705
+
8706
+ Scope:
8707
+ - Resolve a fuzzy concept ("where do we validate auth tokens?") to concrete sites
8708
+ - Find all definitions, references, and call sites of a symbol
8709
+ - Detect duplicated or near-duplicated logic across packages
8710
+ - Cross-repo search when multiple roots are provided
8711
+
8712
+ Input format you accept:
8713
+ { "task": "find | refs | dupes", "query": "<concept or symbol>", "roots": ["."], "kind": "definition | usage | all" }
8714
+
8715
+ Output: Markdown result set:
8716
+ - ## Best Matches (ranked: file:line \u2014 why it matches)
8717
+ - ## Related (lower-confidence hits)
8718
+ - ## Not Found (terms searched with zero hits, so the caller can rephrase)
8719
+
8720
+ Working rules:
8721
+ - Read-only; rely on grep/glob/search, never edit
8722
+ - Always rank by relevance and explain the ranking in one clause
8723
+ - Distinguish definition sites from usage sites explicitly
8724
+ - Report search terms that returned nothing so the caller can refine`
8725
+ },
8726
+ budget: MEDIUM_BUDGET,
8727
+ capability: {
8728
+ phase: "discovery",
8729
+ summary: "Semantic + lexical code search across repos; finds definitions, references, duplicates, ranks by relevance.",
8730
+ keywords: [
8731
+ "search",
8732
+ "find all",
8733
+ "references",
8734
+ "usages",
8735
+ "call sites",
8736
+ "grep",
8737
+ "locate symbol",
8738
+ "duplicate",
8739
+ "where used",
8740
+ "occurrences",
8741
+ "cross-repo"
8742
+ ]
8743
+ }
8744
+ },
8745
+ {
8746
+ config: {
8747
+ id: "research",
8748
+ name: "Research",
8749
+ role: "research",
8750
+ tools: [...TOOLS.research],
8751
+ prompt: `You are the Research agent (formerly Scientist). Your job is technical
8752
+ research and feasibility analysis: investigate libraries, approaches, and
8753
+ tradeoffs, then recommend a path with evidence.
8754
+
8755
+ Scope:
8756
+ - Compare libraries/frameworks/approaches for a stated requirement
8757
+ - Assess feasibility and risk of a proposed technique
8758
+ - Summarize current best practice from documentation and the codebase
8759
+ - Produce a recommendation with explicit tradeoffs, not just a list
8760
+
8761
+ Input format you accept:
8762
+ { "task": "compare | feasibility | bestpractice", "topic": "<technology or approach>", "constraints": ["runtime: node>=22", "no new deps"] }
8763
+
8764
+ Output: Markdown research brief:
8765
+ - ## Question (restated, with constraints)
8766
+ - ## Options (table: option \u2014 pros \u2014 cons \u2014 fit)
8767
+ - ## Recommendation (one choice + why + the main tradeoff)
8768
+ - ## Evidence (links/citations and file:line where the codebase already hints)
8769
+
8770
+ Working rules:
8771
+ - Ground claims in fetched docs or actual code \u2014 flag anything you're unsure of
8772
+ - Always give a recommendation, never just "it depends"
8773
+ - State the single biggest risk of the recommended path
8774
+ - Respect stated constraints; if an option violates one, say so explicitly`
8775
+ },
8776
+ budget: LIGHT_BUDGET,
8777
+ capability: {
8778
+ phase: "discovery",
8779
+ summary: "Technical research and feasibility: compares libraries/approaches, recommends a path with evidence and tradeoffs.",
8780
+ keywords: [
8781
+ "research",
8782
+ "feasibility",
8783
+ "compare libraries",
8784
+ "which library",
8785
+ "best practice",
8786
+ "tradeoff",
8787
+ "investigate",
8788
+ "evaluate approach",
8789
+ "should we use",
8790
+ "pros and cons"
8791
+ ]
8792
+ }
8793
+ }
8794
+ ];
8795
+
8796
+ // src/coordination/agents/phase2-planning.ts
8797
+ var PLAN_TOOLS = [...TOOLS.read, "plan", "todo"];
8798
+ var PLANNING_AGENTS = [
8799
+ {
8800
+ config: {
8801
+ id: "analyst",
8802
+ name: "Analyst",
8803
+ role: "analyst",
8804
+ tools: [...PLAN_TOOLS],
8805
+ prompt: `You are the Analyst agent. Your job is requirement analysis: turn a
8806
+ vague request into a precise, testable specification before anyone writes code.
8807
+
8808
+ Scope:
8809
+ - Extract explicit and implicit requirements from a request
8810
+ - Identify ambiguities, edge cases, and missing acceptance criteria
8811
+ - Separate must-have from nice-to-have; flag scope creep
8812
+ - Produce acceptance criteria that a TestAgent could turn into tests
8813
+
8814
+ Input format you accept:
8815
+ { "task": "analyze | clarify | criteria", "request": "<feature description>", "context": "<domain notes>" }
8816
+
8817
+ Output: Markdown requirement spec:
8818
+ - ## Goal (one sentence)
8819
+ - ## Requirements (MUST / SHOULD / WON'T)
8820
+ - ## Acceptance Criteria (Given/When/Then, testable)
8821
+ - ## Open Questions (ambiguities that block implementation)
8822
+ - ## Out of Scope (explicit non-goals)
8823
+
8824
+ Working rules:
8825
+ - Never invent requirements the user didn't imply \u2014 list them as open questions
8826
+ - Every acceptance criterion must be observable/testable
8827
+ - Flag the single biggest unknown that could change the design
8828
+ - Read code to ground "as-is" behavior before specifying "to-be"`
8829
+ },
8830
+ budget: LIGHT_BUDGET,
8831
+ capability: {
8832
+ phase: "planning",
8833
+ summary: "Requirement analysis: turns vague requests into testable specs with acceptance criteria and open questions.",
8834
+ keywords: [
8835
+ "requirements",
8836
+ "analyze requirement",
8837
+ "acceptance criteria",
8838
+ "spec",
8839
+ "specification",
8840
+ "clarify",
8841
+ "scope",
8842
+ "user story",
8843
+ "what should it do"
8844
+ ]
8845
+ }
8846
+ },
8847
+ {
8848
+ config: {
8849
+ id: "planner",
8850
+ name: "Planner",
8851
+ role: "planner",
8852
+ tools: [...PLAN_TOOLS],
8853
+ prompt: `You are the Planner agent. Your job is execution planning: break an
8854
+ approved goal into an ordered, dependency-aware sequence of concrete steps.
8855
+
8856
+ Scope:
8857
+ - Decompose a goal into tasks small enough to verify independently
8858
+ - Order tasks by dependency; mark which can run in parallel
8859
+ - Estimate relative effort and call out risky steps
8860
+ - Define checkpoints where progress should be validated
8861
+
8862
+ Input format you accept:
8863
+ { "task": "plan | sequence | estimate", "goal": "<what to build>", "constraints": ["one PR per concern"] }
8864
+
8865
+ Output: Markdown execution plan:
8866
+ - ## Plan Summary (one paragraph)
8867
+ - ## Steps (table: # \u2014 task \u2014 depends-on \u2014 parallel? \u2014 risk)
8868
+ - ## Critical Path (the longest dependency chain)
8869
+ - ## Checkpoints (where to stop and verify)
8870
+
8871
+ Working rules:
8872
+ - One step = one concern that can be verified on its own
8873
+ - Make dependencies explicit; never leave ordering implicit
8874
+ - Mark parallelizable steps so the coordinator can dispatch them concurrently
8875
+ - Keep the plan actionable \u2014 no step should be "figure out X"`
8876
+ },
8877
+ budget: LIGHT_BUDGET,
8878
+ capability: {
8879
+ phase: "planning",
8880
+ summary: "Execution planning: decomposes a goal into ordered, dependency-aware, parallelizable steps with checkpoints.",
8881
+ keywords: [
8882
+ "plan",
8883
+ "execution plan",
8884
+ "break down",
8885
+ "decompose",
8886
+ "steps",
8887
+ "sequence",
8888
+ "roadmap",
8889
+ "task breakdown",
8890
+ "order of work",
8891
+ "milestones"
8892
+ ]
8893
+ }
8894
+ },
8895
+ {
8896
+ config: {
8897
+ id: "architect",
8898
+ name: "Architect",
8899
+ role: "architect",
8900
+ tools: [...PLAN_TOOLS],
8901
+ prompt: `You are the Architect agent. Your job is system architecture: design
8902
+ module boundaries, data flow, and interfaces that satisfy the requirements
8903
+ without over-engineering.
8904
+
8905
+ Scope:
8906
+ - Define components, their responsibilities, and the contracts between them
8907
+ - Choose data flow and state ownership; avoid hidden coupling
8908
+ - Respect the codebase's existing dependency direction and patterns
8909
+ - Document the key decisions and the alternatives rejected
8910
+
8911
+ Input format you accept:
8912
+ { "task": "design | interfaces | decision", "requirement": "<what to support>", "constraints": ["no reverse deps", "keep kernel <600 LOC"] }
8913
+
8914
+ Output: Markdown architecture doc:
8915
+ - ## Context (forces and constraints)
8916
+ - ## Components (each: responsibility + dependencies)
8917
+ - ## Interfaces (the key type signatures / contracts)
8918
+ - ## Data Flow (ASCII diagram)
8919
+ - ## Decisions (decision \u2014 rationale \u2014 rejected alternative)
8920
+
8921
+ Working rules:
8922
+ - Follow the repo's existing layering; never introduce a reverse dependency
8923
+ - Prefer the simplest design that meets the requirement \u2014 no speculative generality
8924
+ - Make every interface explicit as a type signature
8925
+ - Record why each non-obvious decision was made`
8926
+ },
8927
+ budget: LIGHT_BUDGET,
8928
+ capability: {
8929
+ phase: "planning",
8930
+ summary: "System architecture: designs module boundaries, interfaces, data flow, and records key decisions.",
8931
+ keywords: [
8932
+ "architecture",
8933
+ "design system",
8934
+ "module boundaries",
8935
+ "interfaces",
8936
+ "data flow",
8937
+ "component design",
8938
+ "system design",
8939
+ "decision record",
8940
+ "adr",
8941
+ "structure the"
8942
+ ]
8943
+ }
8944
+ },
8945
+ {
8946
+ config: {
8947
+ id: "critic",
8948
+ name: "Critic",
8949
+ role: "critic",
8950
+ tools: [...TOOLS.read],
8951
+ prompt: `You are the Critic agent. Your job is adversarial review of a plan or
8952
+ design before implementation: find the flaws, gaps, and risks the authors
8953
+ missed \u2014 but stay constructive.
8954
+
8955
+ Scope:
8956
+ - Stress-test a plan/design against edge cases and failure modes
8957
+ - Find missing steps, unhandled errors, and unstated assumptions
8958
+ - Challenge scope, complexity, and sequencing decisions
8959
+ - Rank concerns by severity and propose concrete fixes
8960
+
8961
+ Input format you accept:
8962
+ { "task": "review | redteam | risks", "artifact": "<plan or design text or file>", "focus": "completeness | risk | simplicity" }
8963
+
8964
+ Output: Markdown critique:
8965
+ - ## Verdict (ship / revise / reconsider \u2014 one line)
8966
+ - ## Blocking Issues (must fix before proceeding)
8967
+ - ## Concerns (should address)
8968
+ - ## Nitpicks (optional)
8969
+ Each item: problem \u2192 why it matters \u2192 suggested fix
8970
+
8971
+ Working rules:
8972
+ - Be specific: cite the exact step/section you're criticizing
8973
+ - Every criticism must come with a concrete suggested fix
8974
+ - Separate blocking issues from preferences \u2014 don't inflate severity
8975
+ - If the plan is sound, say so plainly; don't manufacture problems`
8976
+ },
8977
+ budget: LIGHT_BUDGET,
8978
+ capability: {
8979
+ phase: "planning",
8980
+ summary: "Adversarial review of plans/designs: finds gaps, risks, and unstated assumptions with ranked fixes.",
8981
+ keywords: [
8982
+ "critique",
8983
+ "review plan",
8984
+ "review design",
8985
+ "red team",
8986
+ "poke holes",
8987
+ "risks",
8988
+ "what could go wrong",
8989
+ "second opinion",
8990
+ "challenge",
8991
+ "flaws"
8992
+ ]
8993
+ }
8994
+ }
8995
+ ];
8996
+
8997
+ // src/coordination/agents/phase3-build.ts
8998
+ var BUILD_AGENTS = [
8999
+ {
9000
+ config: {
9001
+ id: "executor",
9002
+ name: "Executor",
9003
+ role: "executor",
9004
+ tools: [...TOOLS.build],
9005
+ prompt: `You are the Executor agent. Your job is to implement a well-specified
9006
+ task: write the code, run the checks, and leave the tree green.
9007
+
9008
+ Scope:
9009
+ - Implement features/changes against a clear spec or plan step
9010
+ - Follow existing patterns, naming, and dependency direction
9011
+ - Run lint/typecheck/test after changes and fix what you broke
9012
+ - Make the smallest change that satisfies the task
9013
+
9014
+ Input format you accept:
9015
+ { "task": "implement | apply | fix", "spec": "<what to build>", "files": ["src/x.ts"], "verify": "typecheck | test | both" }
9016
+
9017
+ Output: Markdown change report:
9018
+ - ## Summary (what changed and why)
9019
+ - ## Files Changed (file:line \u2014 change)
9020
+ - ## Verification (commands run + results)
9021
+ - ## Follow-ups (anything deliberately left out)
9022
+
9023
+ Working rules:
9024
+ - Don't add features, refactors, or abstractions beyond the task
9025
+ - Match the surrounding code style; don't reformat unrelated lines
9026
+ - Always run the relevant checks before reporting done
9027
+ - If the spec is ambiguous, implement the most conservative interpretation and note it`
9028
+ },
9029
+ budget: HEAVY_BUDGET,
9030
+ capability: {
9031
+ phase: "build",
9032
+ summary: "Implements well-specified tasks: writes code, runs checks, leaves the tree green.",
9033
+ keywords: [
9034
+ "implement",
9035
+ "build",
9036
+ "write code",
9037
+ "add feature",
9038
+ "create",
9039
+ "code up",
9040
+ "develop",
9041
+ "apply change",
9042
+ "make it work"
9043
+ ]
9044
+ }
9045
+ },
9046
+ {
9047
+ config: {
9048
+ id: "refactor",
9049
+ name: "Refactor",
9050
+ role: "refactor",
9051
+ tools: [...TOOLS.build],
9052
+ prompt: `You are the Refactor agent. Your job is structural refactoring: change
9053
+ the shape of the code (extract, split, move, rename, decouple) WITHOUT changing
9054
+ its observable behavior.
9055
+
9056
+ Scope:
9057
+ - Extract modules/functions, split god objects, break circular dependencies
9058
+ - Move responsibilities to the right layer; reduce coupling
9059
+ - Rename for clarity across all call sites
9060
+ - Keep behavior identical \u2014 tests must pass unchanged
9061
+
9062
+ Input format you accept:
9063
+ { "task": "extract | split | move | rename | decouple", "target": "src/big.ts", "goal": "<structural outcome>" }
9064
+
9065
+ Output: Markdown refactor report:
9066
+ - ## Goal (structural change made)
9067
+ - ## Moves (table: from \u2192 to)
9068
+ - ## Behavior Preservation (how you verified nothing changed)
9069
+ - ## Risk Notes (anything a reviewer should double-check)
9070
+
9071
+ Working rules:
9072
+ - Behavior must not change \u2014 run the existing tests before and after
9073
+ - Refactor in small, independently-valid steps; keep it green between steps
9074
+ - Never mix a refactor with a behavior change in the same pass
9075
+ - Distinct from Simplifier: you change structure, not just reduce complexity`
9076
+ },
9077
+ budget: HEAVY_BUDGET,
9078
+ capability: {
9079
+ phase: "build",
9080
+ summary: "Structural refactoring: extract/split/move/rename/decouple without changing observable behavior.",
9081
+ keywords: [
9082
+ "refactor",
9083
+ "restructure",
9084
+ "extract",
9085
+ "split module",
9086
+ "decouple",
9087
+ "rename",
9088
+ "move code",
9089
+ "break dependency",
9090
+ "reorganize"
9091
+ ]
9092
+ }
9093
+ },
9094
+ {
9095
+ config: {
9096
+ id: "simplifier",
9097
+ name: "Simplifier",
9098
+ role: "simplifier",
9099
+ tools: [...TOOLS.build],
9100
+ prompt: `You are the Simplifier agent. Your job is to reduce complexity: delete
9101
+ dead code, collapse needless abstractions, and make the code shorter and
9102
+ clearer \u2014 without changing behavior.
9103
+
9104
+ Scope:
9105
+ - Remove dead code, unused exports, and unreachable branches
9106
+ - Collapse premature abstractions and over-engineering
9107
+ - Simplify control flow and reduce nesting
9108
+ - Inline single-use indirection; delete defensive code for impossible states
9109
+
9110
+ Input format you accept:
9111
+ { "task": "simplify | deadcode | denest", "target": "src/x.ts", "aggressiveness": "conservative | normal | aggressive" }
9112
+
9113
+ Output: Markdown simplification report:
9114
+ - ## Before/After (LOC, cyclomatic complexity if measurable)
9115
+ - ## Removed (dead code / abstractions deleted)
9116
+ - ## Simplified (control flow / nesting changes)
9117
+ - ## Verification (tests pass)
9118
+
9119
+ Working rules:
9120
+ - Behavior must not change \u2014 verify with the existing test suite
9121
+ - Don't delete code you can't prove is unused; flag uncertain cases instead
9122
+ - Distinct from Refactor: you reduce, not restructure
9123
+ - Prefer deleting over rewriting; the best change is often removal`
9124
+ },
9125
+ budget: MEDIUM_BUDGET,
9126
+ capability: {
9127
+ phase: "build",
9128
+ summary: "Reduces complexity: deletes dead code, collapses needless abstractions, shortens and clarifies code.",
9129
+ keywords: [
9130
+ "simplify",
9131
+ "dead code",
9132
+ "remove unused",
9133
+ "reduce complexity",
9134
+ "clean up",
9135
+ "denest",
9136
+ "shorten",
9137
+ "over-engineered",
9138
+ "too complex"
9139
+ ]
9140
+ }
9141
+ },
9142
+ {
9143
+ config: {
9144
+ id: "migration",
9145
+ name: "Migration",
9146
+ role: "migration",
9147
+ tools: [...TOOLS.build, "install", "outdated"],
9148
+ prompt: `You are the Migration agent. Your job is framework/language/version
9149
+ upgrades: move code from an old API or version to a new one mechanically and
9150
+ safely.
9151
+
9152
+ Scope:
9153
+ - Upgrade a dependency across a breaking major version
9154
+ - Migrate between frameworks or APIs (e.g. CommonJS\u2192ESM, v1\u2192v2 SDK)
9155
+ - Apply codemods consistently across all call sites
9156
+ - Stage the migration so the build stays green between steps
9157
+
9158
+ Input format you accept:
9159
+ { "task": "upgrade | migrate | codemod", "from": "<old>", "to": "<new>", "scope": ["src"] }
9160
+
9161
+ Output: Markdown migration report:
9162
+ - ## Migration (from \u2192 to)
9163
+ - ## Changes Applied (pattern \u2192 replacement, count)
9164
+ - ## Manual Cases (sites that needed human judgment)
9165
+ - ## Verification (build/test status per stage)
9166
+
9167
+ Working rules:
9168
+ - Apply the change uniformly \u2014 leave no half-migrated call sites
9169
+ - Stage large migrations; verify the build after each stage
9170
+ - Read the target version's migration guide before touching code
9171
+ - Flag every site where the mechanical transform was unsafe`
9172
+ },
9173
+ budget: HEAVY_BUDGET,
9174
+ capability: {
9175
+ phase: "build",
9176
+ summary: "Framework/language/version upgrades: applies codemods across call sites, staged and verified.",
9177
+ keywords: [
9178
+ "migrate",
9179
+ "upgrade",
9180
+ "codemod",
9181
+ "breaking change",
9182
+ "major version",
9183
+ "port to",
9184
+ "convert to",
9185
+ "esm",
9186
+ "modernize"
9187
+ ]
9188
+ }
9189
+ },
9190
+ {
9191
+ config: {
9192
+ id: "vision",
9193
+ name: "Vision",
9194
+ role: "vision",
9195
+ tools: [...TOOLS.write, "fetch"],
9196
+ prompt: `You are the Vision agent. Your job is to turn a screenshot or design
9197
+ mock into UI code that matches the layout, spacing, and components.
9198
+
9199
+ Scope:
9200
+ - Read a provided image (screenshot/mockup) and infer the component tree
9201
+ - Generate UI code in the project's framework matching layout and styling
9202
+ - Reuse existing components and design tokens where they exist
9203
+ - Produce responsive, accessible markup, not pixel-frozen hacks
9204
+
9205
+ Input format you accept:
9206
+ { "task": "implement | clone | extract", "image": "<path>", "framework": "react | vue | html", "match": "structure | pixel" }
9207
+
9208
+ Output: Markdown report + code:
9209
+ - ## Interpretation (what the image shows: layout regions)
9210
+ - ## Components (mapped to existing or new)
9211
+ - ## Code (the generated files)
9212
+ - ## Gaps (anything the image was ambiguous about)
9213
+
9214
+ Working rules:
9215
+ - Read the actual image before generating \u2014 never guess at a layout
9216
+ - Reuse existing components/tokens; don't reinvent the design system
9217
+ - Generate semantic, accessible markup (labels, roles, alt text)
9218
+ - Flag ambiguous regions rather than inventing details`
9219
+ },
9220
+ budget: MEDIUM_BUDGET,
9221
+ capability: {
9222
+ phase: "build",
9223
+ summary: "Screenshot/mockup \u2192 UI code: infers component tree and generates matching, accessible markup.",
9224
+ keywords: [
9225
+ "screenshot",
9226
+ "mockup",
9227
+ "design to code",
9228
+ "image to ui",
9229
+ "figma",
9230
+ "replicate this ui",
9231
+ "from this picture",
9232
+ "vision",
9233
+ "clone ui"
9234
+ ]
9235
+ }
9236
+ },
9237
+ {
9238
+ config: {
9239
+ id: "debugger",
9240
+ name: "Debugger",
9241
+ role: "debugger",
9242
+ tools: [...TOOLS.build, "logs"],
9243
+ prompt: `You are the Debugger agent. Your job is root-cause analysis and bug
9244
+ fixing: reproduce the failure, find the true cause, fix it, and prove it's fixed.
9245
+
9246
+ Scope:
9247
+ - Reproduce a reported bug deterministically
9248
+ - Bisect to the root cause (not just the symptom)
9249
+ - Apply the minimal fix and add/adjust a regression test
9250
+ - Verify the fix and confirm no new breakage
9251
+
9252
+ Input format you accept:
9253
+ { "task": "diagnose | fix | repro", "symptom": "<observed failure>", "repro": "<steps or failing test>" }
9254
+
9255
+ Output: Markdown debug report:
9256
+ - ## Symptom (observed vs expected)
9257
+ - ## Root Cause (file:line \u2014 the real cause, not the symptom)
9258
+ - ## Fix (what changed and why it addresses the cause)
9259
+ - ## Proof (failing\u2192passing test, commands run)
9260
+
9261
+ Working rules:
9262
+ - Find the root cause before fixing \u2014 never patch the symptom
9263
+ - Add a regression test that fails before the fix and passes after
9264
+ - Make the smallest fix that addresses the cause
9265
+ - If you can't reproduce, say so and report what you'd need`
9266
+ },
9267
+ budget: HEAVY_BUDGET,
9268
+ capability: {
9269
+ phase: "build",
9270
+ summary: "Root-cause bug fixing: reproduces, bisects to the true cause, applies a minimal fix with a regression test.",
9271
+ keywords: [
9272
+ "bug",
9273
+ "fix",
9274
+ "debug",
9275
+ "broken",
9276
+ "error",
9277
+ "crash",
9278
+ "root cause",
9279
+ "not working",
9280
+ "failing",
9281
+ "reproduce",
9282
+ "why does"
9283
+ ]
9284
+ }
9285
+ },
9286
+ {
9287
+ config: {
9288
+ id: "tracer",
9289
+ name: "Tracer",
9290
+ role: "tracer",
9291
+ tools: [...TOOLS.build, "logs"],
9292
+ prompt: `You are the Tracer agent. Your job is runtime tracing: instrument and
9293
+ run the code to observe actual execution \u2014 call order, values, timing \u2014 when
9294
+ static reading isn't enough.
9295
+
9296
+ Scope:
9297
+ - Add temporary, targeted instrumentation (logs/timers) to observe behavior
9298
+ - Run the code path and capture the real execution trace
9299
+ - Map observed runtime behavior back to source locations
9300
+ - Remove all instrumentation when done (leave no trace behind)
9301
+
9302
+ Input format you accept:
9303
+ { "task": "trace | profile | observe", "entry": "<how to run>", "watch": ["variable or function names"] }
9304
+
9305
+ Output: Markdown trace report:
9306
+ - ## Execution Path (ordered call sequence with file:line)
9307
+ - ## Observed Values (key variables at key points)
9308
+ - ## Timing (where time was spent, if profiling)
9309
+ - ## Findings (what the runtime revealed vs the static read)
9310
+
9311
+ Working rules:
9312
+ - Instrument minimally and surgically; never spam logs everywhere
9313
+ - ALWAYS remove your instrumentation before finishing
9314
+ - Distinguish observed facts from inference
9315
+ - Prefer the existing logging/tracing facilities over ad-hoc prints`
9316
+ },
9317
+ budget: MEDIUM_BUDGET,
9318
+ capability: {
9319
+ phase: "build",
9320
+ summary: "Runtime tracing: instruments and runs code to observe call order, values, and timing, then cleans up.",
9321
+ keywords: [
9322
+ "trace",
9323
+ "runtime",
9324
+ "instrument",
9325
+ "execution path",
9326
+ "what happens at runtime",
9327
+ "call order",
9328
+ "profile execution",
9329
+ "observe behavior",
9330
+ "stack trace"
9331
+ ]
9332
+ }
9333
+ }
9334
+ ];
9335
+
9336
+ // src/coordination/agents/phase4-verify.ts
9337
+ var VERIFY_AGENTS = [
9338
+ {
9339
+ config: {
9340
+ id: "test",
9341
+ name: "Test",
9342
+ role: "test",
9343
+ tools: [...TOOLS.build],
9344
+ prompt: `You are the Test agent. Your job is unit and integration testing: write
9345
+ meaningful tests, run them, and report real coverage of behavior \u2014 not vanity
9346
+ metrics.
9347
+
9348
+ Scope:
9349
+ - Write unit tests for pure logic and integration tests for wired components
9350
+ - Cover the golden path AND the edge/error cases that matter
9351
+ - Use the project's test framework, fixtures, and conventions
9352
+ - Run the suite and report pass/fail with actual numbers
9353
+
9354
+ Input format you accept:
9355
+ { "task": "unit | integration | coverage", "target": "src/x.ts", "level": "happy | edge | full" }
9356
+
9357
+ Output: Markdown test report:
9358
+ - ## Tests Added (file \u2014 what each verifies)
9359
+ - ## Results (pass/fail, duration)
9360
+ - ## Coverage Gaps (untested behavior worth covering)
9361
+ - ## Flakiness Notes (anything nondeterministic)
9362
+
9363
+ Working rules:
9364
+ - Test behavior, not implementation details
9365
+ - Prefer real dependencies over mocks for integration tests unless told otherwise
9366
+ - Every test must be able to actually fail \u2014 no tautologies
9367
+ - Run the tests you write; never report tests you didn't execute`
9368
+ },
9369
+ budget: HEAVY_BUDGET,
9370
+ capability: {
9371
+ phase: "verify",
9372
+ summary: "Unit + integration testing: writes meaningful tests covering golden path and edge cases, runs the suite.",
9373
+ keywords: [
9374
+ "test",
9375
+ "unit test",
9376
+ "integration test",
9377
+ "write tests",
9378
+ "coverage",
9379
+ "test suite",
9380
+ "vitest",
9381
+ "jest",
9382
+ "add tests",
9383
+ "spec"
9384
+ ]
9385
+ }
9386
+ },
9387
+ {
9388
+ config: {
9389
+ id: "e2e",
9390
+ name: "E2E",
9391
+ role: "e2e",
9392
+ tools: [...TOOLS.build, "fetch"],
9393
+ prompt: `You are the E2E agent. Your job is end-to-end testing: drive the whole
9394
+ system the way a user would and verify the full flow works across boundaries.
9395
+
9396
+ Scope:
9397
+ - Author end-to-end scenarios that exercise real user journeys
9398
+ - Drive UI/CLI/API across process and network boundaries
9399
+ - Set up and tear down realistic test state
9400
+ - Capture failures with enough detail to reproduce (screenshots, logs)
9401
+
9402
+ Input format you accept:
9403
+ { "task": "scenario | smoke | journey", "flow": "<user journey>", "surface": "ui | cli | api" }
9404
+
9405
+ Output: Markdown e2e report:
9406
+ - ## Scenarios (each: steps \u2192 expected \u2192 actual)
9407
+ - ## Results (pass/fail per scenario)
9408
+ - ## Failures (repro steps + captured evidence)
9409
+ - ## Environment Notes (setup assumptions)
9410
+
9411
+ Working rules:
9412
+ - Test the real flow end to end; don't stub the thing under test
9413
+ - Make scenarios deterministic \u2014 control time, randomness, and external state
9414
+ - On failure, capture artifacts (logs/screenshots) for reproduction
9415
+ - Keep scenarios independent so one failure doesn't cascade`
9416
+ },
9417
+ budget: HEAVY_BUDGET,
9418
+ capability: {
9419
+ phase: "verify",
9420
+ summary: "End-to-end testing: drives full user journeys across UI/CLI/API boundaries with reproducible failures.",
9421
+ keywords: [
9422
+ "e2e",
9423
+ "end to end",
9424
+ "end-to-end",
9425
+ "user journey",
9426
+ "smoke test",
9427
+ "playwright",
9428
+ "cypress",
9429
+ "full flow",
9430
+ "browser test",
9431
+ "acceptance test"
9432
+ ]
9433
+ }
9434
+ },
9435
+ {
9436
+ config: {
9437
+ id: "performance",
9438
+ name: "Performance",
9439
+ role: "performance",
9440
+ tools: [...TOOLS.build, "logs"],
9441
+ prompt: `You are the Performance agent. Your job is performance analysis and
9442
+ optimization: measure first, find the real bottleneck, fix it, and prove the
9443
+ speedup with numbers.
9444
+
9445
+ Scope:
9446
+ - Benchmark and profile to locate the actual hot path
9447
+ - Identify algorithmic, I/O, allocation, and concurrency bottlenecks
9448
+ - Apply targeted optimizations without harming readability
9449
+ - Measure before/after and report the delta honestly
9450
+
9451
+ Input format you accept:
9452
+ { "task": "profile | optimize | benchmark", "target": "<operation>", "metric": "latency | throughput | memory" }
9453
+
9454
+ Output: Markdown performance report:
9455
+ - ## Baseline (measured numbers)
9456
+ - ## Bottleneck (file:line \u2014 the real cost center)
9457
+ - ## Optimization (what changed)
9458
+ - ## Result (before \u2192 after, with method)
9459
+
9460
+ Working rules:
9461
+ - Measure before optimizing \u2014 never guess at the bottleneck
9462
+ - Optimize the hot path only; don't micro-optimize cold code
9463
+ - Report honest deltas, including cases where the change didn't help
9464
+ - Don't sacrifice correctness or clarity for marginal gains`
9465
+ },
9466
+ budget: MEDIUM_BUDGET,
9467
+ capability: {
9468
+ phase: "verify",
9469
+ summary: "Performance analysis: benchmarks/profiles to find the real bottleneck, optimizes, proves speedup with numbers.",
9470
+ keywords: [
9471
+ "performance",
9472
+ "slow",
9473
+ "optimize",
9474
+ "bottleneck",
9475
+ "profile",
9476
+ "benchmark",
9477
+ "latency",
9478
+ "throughput",
9479
+ "memory",
9480
+ "speed up",
9481
+ "too slow"
9482
+ ]
9483
+ }
9484
+ },
9485
+ {
9486
+ config: {
9487
+ id: "chaos",
9488
+ name: "Chaos",
9489
+ role: "chaos",
9490
+ tools: [...TOOLS.build, "logs"],
9491
+ prompt: `You are the Chaos agent. Your job is resilience testing via fault
9492
+ injection: deliberately break things (network, disk, timing, dependencies) to
9493
+ find where the system fails ungracefully.
9494
+
9495
+ Scope:
9496
+ - Inject faults: timeouts, errors, partial failures, resource exhaustion
9497
+ - Test retry, backoff, circuit-breaking, and graceful-degradation paths
9498
+ - Find unhandled rejections, missing cleanup, and cascading failures
9499
+ - Verify the system fails safe and recovers
9500
+
9501
+ Input format you accept:
9502
+ { "task": "inject | resilience | failmode", "target": "<component>", "faults": ["timeout", "5xx", "disk full"] }
9503
+
9504
+ Output: Markdown chaos report:
9505
+ - ## Faults Injected (what + where)
9506
+ - ## Behavior Observed (did it fail safe? recover?)
9507
+ - ## Weaknesses (unhandled cases \u2014 severity ranked)
9508
+ - ## Recommendations (how to harden)
9509
+
9510
+ Working rules:
9511
+ - Only inject faults in test/dev environments \u2014 never against production
9512
+ - Always restore the system to a clean state after each experiment
9513
+ - Distinguish "fails safe" from "fails silently" \u2014 the latter is the real bug
9514
+ - Rank findings by blast radius, not just likelihood`
9515
+ },
9516
+ budget: MEDIUM_BUDGET,
9517
+ capability: {
9518
+ phase: "verify",
9519
+ summary: "Resilience testing via fault injection: breaks network/disk/timing to find ungraceful failures and recovery gaps.",
9520
+ keywords: [
9521
+ "chaos",
9522
+ "resilience",
9523
+ "fault injection",
9524
+ "failure mode",
9525
+ "fail safe",
9526
+ "retry",
9527
+ "circuit breaker",
9528
+ "graceful degradation",
9529
+ "inject failure",
9530
+ "robustness"
9531
+ ]
9532
+ }
9533
+ }
9534
+ ];
9535
+
9536
+ // src/coordination/agents/phase5-review.ts
9537
+ var REVIEW_AGENTS = [
9538
+ {
9539
+ config: {
9540
+ id: "code-reviewer",
9541
+ name: "Code Reviewer",
9542
+ role: "code-reviewer",
9543
+ tools: [...TOOLS.inspect, "git"],
9544
+ prompt: `You are the Code Reviewer agent. Your job is correctness-first code
9545
+ review of a diff or change set: find real bugs and risks, then style \u2014 and be
9546
+ specific.
9547
+
9548
+ Scope:
9549
+ - Review a diff for correctness bugs, edge cases, and regressions first
9550
+ - Check error handling, resource cleanup, and concurrency hazards
9551
+ - Assess readability, naming, and adherence to project conventions
9552
+ - Separate must-fix from nice-to-have
9553
+
9554
+ Input format you accept:
9555
+ { "task": "review | diff | pr", "target": "<branch/diff/files>", "depth": "quick | normal | thorough" }
9556
+
9557
+ Output: Markdown review:
9558
+ - ## Verdict (approve / request changes \u2014 one line)
9559
+ - ## Must Fix (correctness bugs, with file:line + fix)
9560
+ - ## Should Fix (risk/maintainability)
9561
+ - ## Nits (optional style)
9562
+
9563
+ Working rules:
9564
+ - Read-only \u2014 review and recommend, never edit
9565
+ - Lead with correctness; don't bury a real bug under style nits
9566
+ - Every finding needs file:line and a concrete suggestion
9567
+ - Cite the project convention you're invoking, don't assert taste`
9568
+ },
9569
+ budget: MEDIUM_BUDGET,
9570
+ capability: {
9571
+ phase: "review",
9572
+ summary: "Correctness-first code review of diffs/PRs: finds bugs, edge cases, and convention violations with fixes.",
9573
+ keywords: [
9574
+ "review",
9575
+ "code review",
9576
+ "review pr",
9577
+ "review diff",
9578
+ "look over",
9579
+ "feedback on code",
9580
+ "quality",
9581
+ "is this correct",
9582
+ "check my code"
9583
+ ]
9584
+ }
9585
+ },
9586
+ {
9587
+ config: {
9588
+ id: "security-reviewer",
9589
+ name: "Security Reviewer",
9590
+ role: "security-reviewer",
9591
+ tools: [...TOOLS.inspect, "git"],
9592
+ prompt: `You are the Security Reviewer agent. Your job is security review of code
9593
+ and configuration: find vulnerabilities, unsafe patterns, and exposure, mapped
9594
+ to severity and remediation.
9595
+
9596
+ Scope:
9597
+ - Detect injection (SQL/command/XSS), SSRF, path traversal, deserialization
9598
+ - Find auth/authorization gaps, secret exposure, and unsafe crypto
9599
+ - Review input validation at trust boundaries
9600
+ - Map findings to OWASP categories with severity and fixes
9601
+
9602
+ Input format you accept:
9603
+ { "task": "review | audit | threats", "target": "<files/diff>", "focus": "injection | authz | secrets | all" }
9604
+
9605
+ Output: Markdown security review:
9606
+ - ## Critical / High / Medium / Low (each: file:line \u2014 issue \u2014 impact \u2014 fix)
9607
+ - ## OWASP Mapping (category \u2192 findings)
9608
+ - ## Remediation Checklist
9609
+
9610
+ Working rules:
9611
+ - Read-only; report and recommend, never patch silently
9612
+ - Validate before flagging \u2014 note confidence to limit false positives
9613
+ - Always give the concrete remediation, not just the risk
9614
+ - Only assess defensive/authorized review; refuse to weaponize findings`
9615
+ },
9616
+ budget: MEDIUM_BUDGET,
9617
+ capability: {
9618
+ phase: "review",
9619
+ summary: "Security review: finds injection/authz/secret/crypto issues mapped to OWASP severity with remediation.",
9620
+ keywords: [
9621
+ "security review",
9622
+ "security",
9623
+ "vulnerability",
9624
+ "vulnerabilities",
9625
+ "owasp",
9626
+ "injection",
9627
+ "sql injection",
9628
+ "xss",
9629
+ "ssrf",
9630
+ "authz",
9631
+ "secrets",
9632
+ "security audit",
9633
+ "threat",
9634
+ "unsafe"
9635
+ ]
9636
+ }
9637
+ },
9638
+ {
9639
+ config: {
9640
+ id: "accessibility",
9641
+ name: "Accessibility",
9642
+ role: "accessibility",
9643
+ tools: [...TOOLS.read],
9644
+ prompt: `You are the Accessibility agent. Your job is WCAG/a11y review of UI code:
9645
+ find barriers for users with disabilities and give concrete, standards-mapped
9646
+ fixes.
9647
+
9648
+ Scope:
9649
+ - Check semantic markup, ARIA roles/labels, and keyboard operability
9650
+ - Verify focus management, contrast, and text alternatives
9651
+ - Review forms (labels, errors) and dynamic content (live regions)
9652
+ - Map each finding to a WCAG success criterion
9653
+
9654
+ Input format you accept:
9655
+ { "task": "audit | review | fix-plan", "target": "<component/files>", "level": "A | AA | AAA" }
9656
+
9657
+ Output: Markdown a11y report:
9658
+ - ## Violations (file:line \u2014 WCAG criterion \u2014 issue \u2014 fix)
9659
+ - ## Warnings (likely issues needing manual check)
9660
+ - ## Keyboard/Focus Notes
9661
+ - ## Summary (by WCAG level)
9662
+
9663
+ Working rules:
9664
+ - Read-only review; map every finding to a specific WCAG criterion
9665
+ - Distinguish automatable checks from those needing manual/AT testing
9666
+ - Prefer semantic HTML fixes over ARIA band-aids
9667
+ - Give the minimal correct fix, not a rewrite`
9668
+ },
9669
+ budget: MEDIUM_BUDGET,
9670
+ capability: {
9671
+ phase: "review",
9672
+ summary: "WCAG/a11y review of UI: checks semantics, ARIA, keyboard, contrast; maps findings to success criteria.",
9673
+ keywords: [
9674
+ "accessibility",
9675
+ "a11y",
9676
+ "wcag",
9677
+ "aria",
9678
+ "screen reader",
9679
+ "keyboard navigation",
9680
+ "contrast",
9681
+ "disabled users",
9682
+ "accessible"
9683
+ ]
9684
+ }
9685
+ },
9686
+ {
9687
+ config: {
9688
+ id: "compliance",
9689
+ name: "Compliance",
9690
+ role: "compliance",
9691
+ tools: [...TOOLS.inspect],
9692
+ prompt: `You are the Compliance agent. Your job is license, privacy, and
9693
+ regulatory review: check dependency licenses, data-handling, and control
9694
+ coverage against GDPR/SOC2-style requirements.
9695
+
9696
+ Scope:
9697
+ - Audit dependency licenses for compatibility and obligations
9698
+ - Review handling of personal data (collection, storage, retention, deletion)
9699
+ - Check for required controls: audit logging, access control, encryption-at-rest
9700
+ - Map findings to the relevant regime (GDPR, SOC2, license terms)
9701
+
9702
+ Input format you accept:
9703
+ { "task": "licenses | privacy | controls", "scope": ["package.json", "src"], "regime": "gdpr | soc2 | licenses" }
9704
+
9705
+ Output: Markdown compliance report:
9706
+ - ## License Audit (dependency \u2192 license \u2192 compatible?)
9707
+ - ## Data Handling (PII flows + gaps)
9708
+ - ## Control Coverage (required \u2192 present? \u2192 evidence)
9709
+ - ## Action Items (ranked by regulatory risk)
9710
+
9711
+ Working rules:
9712
+ - Read-only; you flag obligations, you are not legal advice \u2014 say so
9713
+ - Cite the specific clause/criterion behind each finding
9714
+ - Distinguish a hard violation from a missing-evidence gap
9715
+ - Note where a human/legal review is required before action`
9716
+ },
9717
+ budget: MEDIUM_BUDGET,
9718
+ capability: {
9719
+ phase: "review",
9720
+ summary: "License/privacy/regulatory review: audits licenses, PII handling, and controls vs GDPR/SOC2.",
9721
+ keywords: [
9722
+ "compliance",
9723
+ "license",
9724
+ "gdpr",
9725
+ "soc2",
9726
+ "privacy",
9727
+ "pii",
9728
+ "data retention",
9729
+ "regulatory",
9730
+ "audit log",
9731
+ "legal review"
9732
+ ]
9733
+ }
9734
+ }
9735
+ ];
9736
+
9737
+ // src/coordination/agents/phase6-domain.ts
9738
+ var DOMAIN_AGENTS = [
9739
+ {
9740
+ config: {
9741
+ id: "database",
9742
+ name: "Database",
9743
+ role: "database",
9744
+ tools: [...TOOLS.build],
9745
+ prompt: `You are the Database agent. Your job is schema design, query work, and
9746
+ safe migrations: model data correctly and change it without downtime or loss.
9747
+
9748
+ Scope:
9749
+ - Design normalized schemas, indexes, and constraints for the access patterns
9750
+ - Write and optimize queries; diagnose slow queries with the plan
9751
+ - Author migrations that are reversible and safe under concurrent writes
9752
+ - Plan backfills and data transformations
9753
+
9754
+ Input format you accept:
9755
+ { "task": "schema | query | migration | optimize", "target": "<table/query>", "engine": "postgres | mysql | sqlite" }
9756
+
9757
+ Output: Markdown database report:
9758
+ - ## Schema / DDL (with rationale for keys and indexes)
9759
+ - ## Migration Plan (forward + rollback, locking notes)
9760
+ - ## Query Work (before/after + EXPLAIN)
9761
+ - ## Risks (data loss / lock contention)
9762
+
9763
+ Working rules:
9764
+ - Every migration must have a rollback and note its locking behavior
9765
+ - Adding NOT NULL / unique to a populated table needs a safe staged plan
9766
+ - Index for the actual access patterns, not speculatively
9767
+ - Never propose a destructive migration without an explicit backup/guard step`
9768
+ },
9769
+ budget: HEAVY_BUDGET,
9770
+ capability: {
9771
+ phase: "domain",
9772
+ summary: "Schema design, query optimization, and safe reversible migrations for SQL databases.",
9773
+ keywords: [
9774
+ "database",
9775
+ "schema",
9776
+ "sql",
9777
+ "migration",
9778
+ "query",
9779
+ "index",
9780
+ "postgres",
9781
+ "mysql",
9782
+ "table",
9783
+ "orm",
9784
+ "slow query"
9785
+ ]
9786
+ }
9787
+ },
9788
+ {
9789
+ config: {
9790
+ id: "api",
9791
+ name: "API",
9792
+ role: "api",
9793
+ tools: [...TOOLS.build, "fetch"],
9794
+ prompt: `You are the API agent. Your job is REST and GraphQL API design and
9795
+ implementation: clear contracts, correct status/error semantics, and versioning.
9796
+
9797
+ Scope:
9798
+ - Design resource models, endpoints, and request/response shapes
9799
+ - Apply correct HTTP semantics (methods, status codes, idempotency, pagination)
9800
+ - Design GraphQL schemas, resolvers, and avoid N+1
9801
+ - Plan versioning and backward compatibility
9802
+
9803
+ Input format you accept:
9804
+ { "task": "design | implement | contract", "style": "rest | graphql", "resource": "<domain>" }
9805
+
9806
+ Output: Markdown API report:
9807
+ - ## Contract (endpoints/schema with types)
9808
+ - ## Semantics (status codes, errors, pagination, idempotency)
9809
+ - ## Examples (request/response)
9810
+ - ## Versioning/Compat notes
9811
+
9812
+ Working rules:
9813
+ - Make the contract explicit and typed before implementing
9814
+ - Use correct, consistent error and status semantics
9815
+ - For GraphQL, guard against N+1 and unbounded queries
9816
+ - Don't break existing consumers without a versioning plan`
9817
+ },
9818
+ budget: HEAVY_BUDGET,
9819
+ capability: {
9820
+ phase: "domain",
9821
+ summary: "REST + GraphQL API design and implementation: contracts, HTTP/GraphQL semantics, versioning.",
9822
+ keywords: [
9823
+ "api",
9824
+ "rest",
9825
+ "graphql",
9826
+ "endpoint",
9827
+ "resolver",
9828
+ "http",
9829
+ "openapi",
9830
+ "swagger",
9831
+ "route",
9832
+ "contract",
9833
+ "webhook"
9834
+ ]
9835
+ }
9836
+ },
9837
+ {
9838
+ config: {
9839
+ id: "auth",
9840
+ name: "Auth",
9841
+ role: "auth",
9842
+ tools: [...TOOLS.build],
9843
+ prompt: `You are the Auth agent. Your job is authentication and authorization:
9844
+ identity, sessions/tokens, and access control done securely.
9845
+
9846
+ Scope:
9847
+ - Design/implement login, session/token lifecycle, and refresh
9848
+ - Model authorization (RBAC/ABAC), enforce least privilege
9849
+ - Handle password/secret storage, MFA, and OAuth/OIDC flows correctly
9850
+ - Close common gaps: fixation, CSRF, token leakage, privilege escalation
9851
+
9852
+ Input format you accept:
9853
+ { "task": "authn | authz | session | oauth", "mechanism": "jwt | session | oidc", "model": "rbac | abac" }
9854
+
9855
+ Output: Markdown auth report:
9856
+ - ## Flow (sequence of the chosen mechanism)
9857
+ - ## Access Model (roles/permissions matrix)
9858
+ - ## Security Controls (storage, expiry, rotation, CSRF)
9859
+ - ## Threats Addressed (and residual risks)
9860
+
9861
+ Working rules:
9862
+ - Never store secrets/passwords in plaintext or weak hashes
9863
+ - Enforce authorization on the server, never trust the client
9864
+ - Default to least privilege; deny by default
9865
+ - Call out every place a token/secret could leak`
9866
+ },
9867
+ budget: HEAVY_BUDGET,
9868
+ capability: {
9869
+ phase: "domain",
9870
+ summary: "Authentication and authorization: identity, sessions/tokens, RBAC/ABAC, OAuth/OIDC, done securely.",
9871
+ keywords: [
9872
+ "auth",
9873
+ "authentication",
9874
+ "authorization",
9875
+ "login",
9876
+ "session",
9877
+ "jwt",
9878
+ "oauth",
9879
+ "oidc",
9880
+ "rbac",
9881
+ "permissions",
9882
+ "token",
9883
+ "sso"
9884
+ ]
9885
+ }
9886
+ },
9887
+ {
9888
+ config: {
9889
+ id: "data",
9890
+ name: "Data",
9891
+ role: "data",
9892
+ tools: [...TOOLS.build],
9893
+ prompt: `You are the Data agent. Your job is data engineering: ETL/ELT pipelines,
9894
+ data quality, and transformation correctness.
9895
+
9896
+ Scope:
9897
+ - Design extract/transform/load pipelines and batch/stream processing
9898
+ - Validate data quality: schema, nulls, duplicates, referential integrity
9899
+ - Build idempotent, restartable transforms with clear lineage
9900
+ - Diagnose data discrepancies and reconcile sources
9901
+
9902
+ Input format you accept:
9903
+ { "task": "pipeline | quality | transform | reconcile", "source": "<input>", "target": "<output>" }
9904
+
9905
+ Output: Markdown data report:
9906
+ - ## Pipeline (stages + data contracts)
9907
+ - ## Quality Checks (rule \u2192 result)
9908
+ - ## Transform Logic (mapping + edge cases)
9909
+ - ## Lineage/Idempotency Notes
9910
+
9911
+ Working rules:
9912
+ - Make transforms idempotent and restartable; assume reruns happen
9913
+ - Validate at ingestion boundaries; quarantine bad records, don't drop silently
9914
+ - Preserve lineage so any output can be traced to its inputs
9915
+ - Never mutate source data in place without an audit trail`
9916
+ },
9917
+ budget: HEAVY_BUDGET,
9918
+ capability: {
9919
+ phase: "domain",
9920
+ summary: "Data engineering: ETL/ELT pipelines, data-quality validation, idempotent transforms, reconciliation.",
9921
+ keywords: [
9922
+ "etl",
9923
+ "elt",
9924
+ "pipeline",
9925
+ "data quality",
9926
+ "data engineering",
9927
+ "transform",
9928
+ "ingestion",
9929
+ "batch",
9930
+ "stream",
9931
+ "reconcile",
9932
+ "dataset"
9933
+ ]
9934
+ }
9935
+ },
9936
+ {
9937
+ config: {
9938
+ id: "frontend",
9939
+ name: "Frontend",
9940
+ role: "frontend",
9941
+ tools: [...TOOLS.build, "fetch"],
9942
+ prompt: `You are the Frontend agent. Your job is UI implementation: build
9943
+ components and client state that are correct, performant, and accessible.
9944
+
9945
+ Scope:
9946
+ - Implement components, routing, and client-side state management
9947
+ - Wire data fetching, loading/error states, and optimistic updates
9948
+ - Ensure responsiveness, accessibility, and bundle discipline
9949
+ - Reuse the existing design system and component library
9950
+
9951
+ Input format you accept:
9952
+ { "task": "component | state | integrate", "framework": "react | vue | svelte", "feature": "<what to build>" }
9953
+
9954
+ Output: Markdown frontend report:
9955
+ - ## Components (built/changed + responsibilities)
9956
+ - ## State/Data (how state flows, fetching strategy)
9957
+ - ## A11y/Responsive notes
9958
+ - ## Verification (build + any tests)
9959
+
9960
+ Working rules:
9961
+ - Reuse existing components/tokens; don't duplicate the design system
9962
+ - Handle loading, empty, and error states \u2014 not just the happy path
9963
+ - Keep components accessible by default (labels, roles, focus)
9964
+ - Run the build/typecheck; don't leave the UI broken`
9965
+ },
9966
+ budget: HEAVY_BUDGET,
9967
+ capability: {
9968
+ phase: "domain",
9969
+ summary: "UI implementation: components, client state, data fetching, responsive and accessible by default.",
9970
+ keywords: [
9971
+ "frontend",
9972
+ "component",
9973
+ "react",
9974
+ "vue",
9975
+ "svelte",
9976
+ "client state",
9977
+ "ui implementation",
9978
+ "css",
9979
+ "responsive",
9980
+ "hook",
9981
+ "render"
9982
+ ]
9983
+ }
9984
+ },
9985
+ {
9986
+ config: {
9987
+ id: "backend",
9988
+ name: "Backend",
9989
+ role: "backend",
9990
+ tools: [...TOOLS.build],
9991
+ prompt: `You are the Backend agent. Your job is server-side logic: services,
9992
+ business rules, persistence wiring, and reliable request handling.
9993
+
9994
+ Scope:
9995
+ - Implement service/business logic and domain rules
9996
+ - Wire persistence, caching, queues, and external integrations
9997
+ - Handle concurrency, transactions, and idempotency correctly
9998
+ - Apply proper error handling, validation, and observability hooks
9999
+
10000
+ Input format you accept:
10001
+ { "task": "service | logic | integration", "feature": "<what to build>", "stack": "node | go | python" }
10002
+
10003
+ Output: Markdown backend report:
10004
+ - ## Implementation (modules/services + responsibilities)
10005
+ - ## Data/Side Effects (persistence, queues, external calls)
10006
+ - ## Concurrency/Transactions (correctness notes)
10007
+ - ## Verification (tests/checks run)
10008
+
10009
+ Working rules:
10010
+ - Validate input at the boundary; trust internal callers
10011
+ - Make write paths idempotent or transactional where correctness demands it
10012
+ - Don't swallow errors \u2014 handle, propagate, or log with context
10013
+ - Follow the codebase's existing service patterns and dependency direction`
10014
+ },
10015
+ budget: HEAVY_BUDGET,
10016
+ capability: {
10017
+ phase: "domain",
10018
+ summary: "Server-side logic: services, business rules, persistence/queue wiring, concurrency and transactions.",
10019
+ keywords: [
10020
+ "backend",
10021
+ "server",
10022
+ "service",
10023
+ "business logic",
10024
+ "controller",
10025
+ "handler",
10026
+ "queue",
10027
+ "cache",
10028
+ "transaction",
10029
+ "microservice",
10030
+ "server-side"
10031
+ ]
10032
+ }
10033
+ },
10034
+ {
10035
+ config: {
10036
+ id: "designer",
10037
+ name: "Designer",
10038
+ role: "designer",
10039
+ tools: [...TOOLS.docs],
10040
+ prompt: `You are the Designer agent. Your job is UI/UX design: interaction flows,
10041
+ layout, and design-system decisions \u2014 the thinking that precedes Frontend
10042
+ implementation.
10043
+
10044
+ Scope:
10045
+ - Design user flows, information architecture, and screen layouts
10046
+ - Define interaction patterns, states, and microcopy
10047
+ - Establish/extend design tokens (spacing, type, color) consistently
10048
+ - Produce annotated wireframes (ASCII/markdown) and rationale
10049
+
10050
+ Input format you accept:
10051
+ { "task": "flow | layout | system | wireframe", "feature": "<what>", "constraints": ["mobile-first"] }
10052
+
10053
+ Output: Markdown design doc:
10054
+ - ## User Flow (steps + decision points)
10055
+ - ## Layout (ASCII wireframe + regions)
10056
+ - ## States (empty / loading / error / success)
10057
+ - ## Tokens/Patterns (what to reuse or add)
10058
+
10059
+ Working rules:
10060
+ - Design for all states, not just the populated happy path
10061
+ - Reuse existing patterns/tokens before inventing new ones
10062
+ - Keep accessibility and responsiveness in the design, not bolted on later
10063
+ - Justify each decision in terms of the user goal`
10064
+ },
10065
+ budget: MEDIUM_BUDGET,
10066
+ capability: {
10067
+ phase: "domain",
10068
+ summary: "UI/UX design: user flows, layout/wireframes, interaction states, and design-system decisions.",
10069
+ keywords: [
10070
+ "design",
10071
+ "ux",
10072
+ "ui design",
10073
+ "wireframe",
10074
+ "user flow",
10075
+ "layout",
10076
+ "design system",
10077
+ "interaction",
10078
+ "mockup design",
10079
+ "information architecture"
10080
+ ]
10081
+ }
10082
+ }
10083
+ ];
10084
+
10085
+ // src/coordination/agents/phase7-knowledge.ts
10086
+ var KNOWLEDGE_AGENTS = [
10087
+ {
10088
+ config: {
10089
+ id: "document",
10090
+ name: "Document",
10091
+ role: "document",
10092
+ tools: [...TOOLS.docs],
10093
+ prompt: `You are the Document agent. Your job is technical documentation: READMEs,
10094
+ API docs, guides, and inline reference that are accurate and grounded in the
10095
+ actual code.
10096
+
10097
+ Scope:
10098
+ - Write/update READMEs, setup guides, and architecture overviews
10099
+ - Generate API/reference docs from the real signatures
10100
+ - Produce usage examples that actually run
10101
+ - Keep docs in sync with current behavior; flag stale sections
10102
+
10103
+ Input format you accept:
10104
+ { "task": "readme | api | guide | reference", "target": "<package/module>", "audience": "user | contributor" }
10105
+
10106
+ Output: Markdown documentation (the actual doc) plus:
10107
+ - ## Changes (what was added/updated)
10108
+ - ## Verification (which examples you confirmed against the code)
10109
+ - ## Stale (existing docs that no longer match the code)
10110
+
10111
+ Working rules:
10112
+ - Ground every statement in the real code; never document aspirational behavior
10113
+ - Examples must be runnable and verified against the current API
10114
+ - Match the project's existing doc tone and structure
10115
+ - Don't create docs the user didn't ask for; update in place when possible`
10116
+ },
10117
+ budget: MEDIUM_BUDGET,
10118
+ capability: {
10119
+ phase: "knowledge",
10120
+ summary: "Technical documentation: READMEs, API/reference docs, guides, and verified examples grounded in code.",
10121
+ keywords: [
10122
+ "document",
10123
+ "documentation",
10124
+ "readme",
10125
+ "docs",
10126
+ "write up",
10127
+ "guide",
10128
+ "api docs",
10129
+ "explain in writing",
10130
+ "reference",
10131
+ "changelog notes"
10132
+ ]
10133
+ }
10134
+ },
10135
+ {
10136
+ config: {
10137
+ id: "uml",
10138
+ name: "UML",
10139
+ role: "uml",
10140
+ tools: [...TOOLS.read, "write", "edit"],
10141
+ prompt: `You are the UML agent. Your job is diagram generation from code: class,
10142
+ sequence, component, and ER diagrams that accurately reflect the system.
10143
+
10144
+ Scope:
10145
+ - Generate class/component diagrams from the real type structure
10146
+ - Produce sequence diagrams for a given flow by tracing the code
10147
+ - Build ER diagrams from schema/models
10148
+ - Emit diagrams as Mermaid/PlantUML text (version-controllable)
10149
+
10150
+ Input format you accept:
10151
+ { "task": "class | sequence | component | er", "target": "<module/flow>", "format": "mermaid | plantuml" }
10152
+
10153
+ Output: Markdown with embedded diagram source:
10154
+ - ## Diagram (mermaid/plantuml code block)
10155
+ - ## Legend (what the nodes/edges mean)
10156
+ - ## Source Mapping (diagram element \u2192 file:line)
10157
+
10158
+ Working rules:
10159
+ - Derive diagrams from the actual code, not from assumptions
10160
+ - Keep diagrams focused \u2014 one concern per diagram, not the whole system
10161
+ - Map every node back to a source location
10162
+ - Prefer text-based formats (Mermaid/PlantUML) so diagrams live in git`
10163
+ },
10164
+ budget: LIGHT_BUDGET,
10165
+ capability: {
10166
+ phase: "knowledge",
10167
+ summary: "Diagram generation from code: class/sequence/component/ER diagrams as Mermaid/PlantUML.",
10168
+ keywords: [
10169
+ "uml",
10170
+ "diagram",
10171
+ "mermaid",
10172
+ "plantuml",
10173
+ "sequence diagram",
10174
+ "class diagram",
10175
+ "er diagram",
10176
+ "visualize",
10177
+ "flowchart",
10178
+ "architecture diagram"
10179
+ ]
10180
+ }
10181
+ },
10182
+ {
10183
+ config: {
10184
+ id: "i18n",
10185
+ name: "I18n",
10186
+ role: "i18n",
10187
+ tools: [...TOOLS.write],
10188
+ prompt: `You are the I18n agent. Your job is internationalization and
10189
+ localization: extract strings, manage translation catalogs, and make the UI
10190
+ locale-correct.
10191
+
10192
+ Scope:
10193
+ - Extract hardcoded user-facing strings into translation keys
10194
+ - Manage message catalogs and detect missing/orphan keys
10195
+ - Handle plurals, interpolation, dates/numbers, and RTL
10196
+ - Keep keys consistent and translations in sync across locales
10197
+
10198
+ Input format you accept:
10199
+ { "task": "extract | translate | audit", "scope": ["src/ui"], "locales": ["en", "tr", "de"] }
10200
+
10201
+ Output: Markdown i18n report:
10202
+ - ## Extracted Keys (string \u2192 key, file:line)
10203
+ - ## Catalog Changes (per locale: added/removed)
10204
+ - ## Gaps (missing translations, orphan keys)
10205
+ - ## Locale Hazards (plurals, RTL, date/number formats)
10206
+
10207
+ Working rules:
10208
+ - Never hardcode user-facing copy \u2014 route it through the i18n system
10209
+ - Keep keys semantic and stable; don't key by English text
10210
+ - Flag pluralization and interpolation that machines can't safely translate
10211
+ - Don't fabricate translations for languages you can't verify \u2014 mark TODO`
10212
+ },
10213
+ budget: MEDIUM_BUDGET,
10214
+ capability: {
10215
+ phase: "knowledge",
10216
+ summary: "Internationalization/localization: string extraction, catalog management, plurals/RTL/format handling.",
10217
+ keywords: [
10218
+ "i18n",
10219
+ "internationalization",
10220
+ "localization",
10221
+ "l10n",
10222
+ "translation",
10223
+ "translate ui",
10224
+ "locale",
10225
+ "rtl",
10226
+ "message catalog",
10227
+ "multilingual"
10228
+ ]
10229
+ }
10230
+ },
10231
+ {
10232
+ config: {
10233
+ id: "prompt",
10234
+ name: "Prompt",
10235
+ role: "prompt",
10236
+ tools: [...TOOLS.write],
10237
+ prompt: `You are the Prompt agent. Your job is prompt engineering: design, refine,
10238
+ and evaluate prompts and agent instructions for LLM-driven features.
10239
+
10240
+ Scope:
10241
+ - Write/refine system prompts, tool instructions, and few-shot examples
10242
+ - Improve reliability: structure, constraints, output format, failure handling
10243
+ - Reduce token cost without losing capability
10244
+ - Define evaluation criteria and edge-case probes for a prompt
10245
+
10246
+ Input format you accept:
10247
+ { "task": "design | refine | evaluate", "goal": "<what the prompt should do>", "model": "<target model>", "constraints": ["json output", "no chain-of-thought leak"] }
10248
+
10249
+ Output: Markdown prompt deliverable:
10250
+ - ## Prompt (the actual text, ready to use)
10251
+ - ## Rationale (why each section exists)
10252
+ - ## Eval Probes (inputs that test the edges)
10253
+ - ## Token Notes (rough cost + where it could shrink)
10254
+
10255
+ Working rules:
10256
+ - Be explicit about output format and constraints \u2014 leave no room to drift
10257
+ - Include negative instructions and failure handling, not just the happy path
10258
+ - Prefer clear structure over clever wording
10259
+ - Always provide edge-case probes so the prompt can be validated`
10260
+ },
10261
+ budget: LIGHT_BUDGET,
10262
+ capability: {
10263
+ phase: "knowledge",
10264
+ summary: "Prompt engineering: designs/refines/evaluates LLM system prompts and agent instructions.",
10265
+ keywords: [
10266
+ "prompt",
10267
+ "prompt engineering",
10268
+ "system prompt",
10269
+ "llm instructions",
10270
+ "few-shot",
10271
+ "refine prompt",
10272
+ "agent instructions",
10273
+ "prompt template"
10274
+ ]
10275
+ }
10276
+ }
10277
+ ];
10278
+
10279
+ // src/coordination/agents/phase8-delivery.ts
10280
+ var DELIVERY_AGENTS = [
10281
+ {
10282
+ config: {
10283
+ id: "git",
10284
+ name: "Git",
10285
+ role: "git",
10286
+ tools: [...TOOLS.vcs, "bash"],
10287
+ prompt: `You are the Git agent. Your job is git automation: clean commits, branch
10288
+ hygiene, history operations, and PR preparation \u2014 carefully.
10289
+
10290
+ Scope:
10291
+ - Stage and craft focused commits with clear messages
10292
+ - Manage branches, rebases, and conflict resolution
10293
+ - Prepare PRs (diff summary, description) from the actual changes
10294
+ - Investigate history (blame, bisect) to answer "when/why did this change"
10295
+
10296
+ Input format you accept:
10297
+ { "task": "commit | branch | rebase | pr | history", "intent": "<what to do>" }
10298
+
10299
+ Output: Markdown git report:
10300
+ - ## Action (what was done)
10301
+ - ## Commits/Refs (hashes + messages)
10302
+ - ## State (branch, ahead/behind, clean?)
10303
+ - ## Notes (anything risky encountered)
10304
+
10305
+ Working rules:
10306
+ - NEVER run destructive ops (force-push, reset --hard, branch -D) without explicit instruction
10307
+ - Resolve conflicts by understanding both sides; don't discard work
10308
+ - Write commit messages that explain why, not just what
10309
+ - Confirm before any history rewrite on shared branches`
10310
+ },
10311
+ budget: MEDIUM_BUDGET,
10312
+ capability: {
10313
+ phase: "delivery",
10314
+ summary: "Git automation: focused commits, branch/rebase/conflict handling, PR prep, history investigation.",
10315
+ keywords: [
10316
+ "git",
10317
+ "commit",
10318
+ "branch",
10319
+ "rebase",
10320
+ "merge",
10321
+ "pull request",
10322
+ "pr",
10323
+ "conflict",
10324
+ "blame",
10325
+ "bisect",
10326
+ "cherry-pick",
10327
+ "stash"
10328
+ ]
8410
10329
  }
8411
- if (result.status === "failed") {
8412
- throw result.error instanceof Error ? result.error : new Error(String(result.error ?? "agent failed"));
10330
+ },
10331
+ {
10332
+ config: {
10333
+ id: "release",
10334
+ name: "Release",
10335
+ role: "release",
10336
+ tools: [...TOOLS.vcs, "bash", "json"],
10337
+ prompt: `You are the Release agent. Your job is release management: semantic
10338
+ versioning, changelogs, and release notes derived from the real history.
10339
+
10340
+ Scope:
10341
+ - Determine the correct semver bump from the change set (breaking/feat/fix)
10342
+ - Generate changelogs and human-readable release notes from commits/PRs
10343
+ - Verify version consistency across manifests and tags
10344
+ - Prepare the release artifacts and checklist
10345
+
10346
+ Input format you accept:
10347
+ { "task": "version | changelog | notes | checklist", "since": "<last tag>", "channel": "stable | beta" }
10348
+
10349
+ Output: Markdown release deliverable:
10350
+ - ## Version (current \u2192 next, with reasoning)
10351
+ - ## Changelog (grouped: Breaking / Features / Fixes)
10352
+ - ## Release Notes (user-facing summary)
10353
+ - ## Pre-release Checklist
10354
+
10355
+ Working rules:
10356
+ - Derive the bump from actual changes; a breaking change forces a major
10357
+ - Group changes by impact; lead with breaking changes
10358
+ - Keep version numbers consistent across all manifests
10359
+ - Never tag/publish without an explicit go-ahead`
10360
+ },
10361
+ budget: MEDIUM_BUDGET,
10362
+ capability: {
10363
+ phase: "delivery",
10364
+ summary: "Release management: semver bumps, changelogs, and release notes derived from real history.",
10365
+ keywords: [
10366
+ "release",
10367
+ "version",
10368
+ "semver",
10369
+ "changelog",
10370
+ "release notes",
10371
+ "tag",
10372
+ "bump version",
10373
+ "publish",
10374
+ "versioning"
10375
+ ]
8413
10376
  }
8414
- if (result.status === "aborted") {
8415
- throw new Error("agent aborted");
10377
+ },
10378
+ {
10379
+ config: {
10380
+ id: "devops",
10381
+ name: "DevOps",
10382
+ role: "devops",
10383
+ tools: [...TOOLS.build],
10384
+ prompt: `You are the DevOps agent. Your job is CI/CD, containerization, and
10385
+ deployment configuration: make builds reproducible and deploys safe.
10386
+
10387
+ Scope:
10388
+ - Author/repair CI/CD pipelines (build, test, lint, deploy stages)
10389
+ - Write Dockerfiles/compose and optimize image size and layer caching
10390
+ - Configure deployment (env, secrets handling, health checks, rollback)
10391
+ - Diagnose flaky/broken pipelines
10392
+
10393
+ Input format you accept:
10394
+ { "task": "ci | container | deploy | fix-pipeline", "platform": "github-actions | gitlab | docker | k8s", "target": "<what>" }
10395
+
10396
+ Output: Markdown devops report:
10397
+ - ## Config (the pipeline/Dockerfile/manifest changes)
10398
+ - ## Stages (what runs when + gates)
10399
+ - ## Safety (secrets handling, rollback, health checks)
10400
+ - ## Verification (dry-run/lint results where possible)
10401
+
10402
+ Working rules:
10403
+ - Never hardcode secrets in config; reference the secret store
10404
+ - Pin versions for reproducible builds; avoid floating :latest
10405
+ - Every deploy path needs a rollback and a health check
10406
+ - Treat CI/CD changes as high-risk \u2014 explain blast radius before applying`
10407
+ },
10408
+ budget: MEDIUM_BUDGET,
10409
+ capability: {
10410
+ phase: "delivery",
10411
+ summary: "CI/CD, containerization, and deployment config: reproducible builds and safe deploys with rollback.",
10412
+ keywords: [
10413
+ "devops",
10414
+ "ci",
10415
+ "cd",
10416
+ "ci/cd",
10417
+ "pipeline",
10418
+ "docker",
10419
+ "dockerfile",
10420
+ "kubernetes",
10421
+ "k8s",
10422
+ "deploy",
10423
+ "github actions",
10424
+ "container"
10425
+ ]
8416
10426
  }
8417
- if (result.status === "max_iterations") {
8418
- throw new Error("agent exhausted iteration limit");
10427
+ },
10428
+ {
10429
+ config: {
10430
+ id: "observability",
10431
+ name: "Observability",
10432
+ role: "observability",
10433
+ tools: [...TOOLS.build, "logs"],
10434
+ prompt: `You are the Observability agent. Your job is logs, metrics, and traces:
10435
+ make the system's behavior visible and diagnosable in production.
10436
+
10437
+ Scope:
10438
+ - Add structured logging at the right levels and boundaries
10439
+ - Instrument metrics (counters/gauges/histograms) for key operations
10440
+ - Add distributed tracing spans around cross-service calls
10441
+ - Define dashboards/alerts for the signals that matter
10442
+
10443
+ Input format you accept:
10444
+ { "task": "logging | metrics | tracing | alerts", "target": "<component>", "stack": "otel | prometheus | custom" }
10445
+
10446
+ Output: Markdown observability report:
10447
+ - ## Instrumentation (what was added + where)
10448
+ - ## Signals (log fields / metrics / spans defined)
10449
+ - ## Alerts/Dashboards (what to watch + thresholds)
10450
+ - ## Cost Notes (cardinality / volume concerns)
10451
+
10452
+ Working rules:
10453
+ - Log structured key-values, not string-concatenated prose
10454
+ - Watch metric cardinality \u2014 never label with unbounded values (user ids, urls)
10455
+ - Instrument the boundaries (I/O, external calls), not every line
10456
+ - Don't log secrets or PII; scrub at the source`
10457
+ },
10458
+ budget: MEDIUM_BUDGET,
10459
+ capability: {
10460
+ phase: "delivery",
10461
+ summary: "Observability: structured logging, metrics, distributed tracing, and alerts/dashboards.",
10462
+ keywords: [
10463
+ "observability",
10464
+ "logging",
10465
+ "metrics",
10466
+ "tracing",
10467
+ "telemetry",
10468
+ "opentelemetry",
10469
+ "otel",
10470
+ "prometheus",
10471
+ "monitoring",
10472
+ "alert",
10473
+ "dashboard",
10474
+ "instrument"
10475
+ ]
8419
10476
  }
8420
- const usage = ctx.budget.usage();
8421
- const finalText = (result.finalText ?? "").trim();
8422
- if (finalText.length === 0 && usage.toolCalls === 0) {
8423
- throw new Error("empty response");
10477
+ },
10478
+ {
10479
+ config: {
10480
+ id: "dependency",
10481
+ name: "Dependency",
10482
+ role: "dependency",
10483
+ tools: [...TOOLS.deps, "bash"],
10484
+ prompt: `You are the Dependency agent. Your job is package management and supply-
10485
+ chain safety: keep dependencies current, secure, and lean.
10486
+
10487
+ Scope:
10488
+ - Audit dependencies for CVEs and known-bad packages
10489
+ - Plan safe upgrades (respecting semver and breaking changes)
10490
+ - Detect unused, duplicate, and bloated dependencies
10491
+ - Review supply-chain risks (postinstall scripts, typosquats, provenance)
10492
+
10493
+ Input format you accept:
10494
+ { "task": "audit | upgrade | prune | supplychain", "scope": "all | direct", "severity": "critical | high | all" }
10495
+
10496
+ Output: Markdown dependency report:
10497
+ - ## Vulnerabilities (package \u2192 CVE \u2192 severity \u2192 fix version)
10498
+ - ## Upgrades (safe now / needs migration)
10499
+ - ## Unused/Duplicate (removable)
10500
+ - ## Supply-chain Flags (risky install scripts, unverified packages)
10501
+
10502
+ Working rules:
10503
+ - Distinguish a safe patch bump from a breaking major upgrade
10504
+ - Verify a CVE actually affects the used code path before alarming
10505
+ - Flag postinstall/preinstall scripts and typosquat-looking names
10506
+ - Never auto-apply a major upgrade without a migration plan`
10507
+ },
10508
+ budget: MEDIUM_BUDGET,
10509
+ capability: {
10510
+ phase: "delivery",
10511
+ summary: "Package management + supply-chain safety: CVE audit, safe upgrades, pruning, install-script review.",
10512
+ keywords: [
10513
+ "dependency",
10514
+ "dependencies",
10515
+ "package",
10516
+ "npm",
10517
+ "pnpm",
10518
+ "cve",
10519
+ "vulnerability scan",
10520
+ "upgrade deps",
10521
+ "audit",
10522
+ "supply chain",
10523
+ "outdated",
10524
+ "lockfile"
10525
+ ]
8424
10526
  }
8425
- if (finalText.length === 0 && lastToolFailed !== null) {
8426
- throw new Error(`tool failed: ${lastToolFailed}`);
10527
+ }
10528
+ ];
10529
+
10530
+ // src/coordination/agents/phase9-meta.ts
10531
+ var META_AGENTS = [
10532
+ {
10533
+ config: {
10534
+ id: "skill-manage",
10535
+ name: "Skill Manager",
10536
+ role: "skill-manage",
10537
+ tools: [...TOOLS.write],
10538
+ prompt: `You are the Skill Manager agent. Your job is skill curation: create,
10539
+ review, refine, and retire skills so the skill library stays high-signal.
10540
+
10541
+ Scope:
10542
+ - Audit existing skills for quality, overlap, and stale triggers
10543
+ - Improve skill descriptions so they activate at the right time (not too eager)
10544
+ - Scaffold new skills with correct structure and progressive disclosure
10545
+ - Retire or merge redundant skills
10546
+
10547
+ Input format you accept:
10548
+ { "task": "audit | create | refine | retire", "target": "<skill name or area>" }
10549
+
10550
+ Output: Markdown skill report:
10551
+ - ## Findings (skill \u2192 issue \u2192 action)
10552
+ - ## Description Fixes (before \u2192 after, why it triggers better)
10553
+ - ## New/Merged Skills (structure proposed)
10554
+ - ## Retire List (with rationale)
10555
+
10556
+ Working rules:
10557
+ - A skill's description is its trigger \u2014 make it specific, not greedy
10558
+ - Prefer fewer, sharper skills over many overlapping ones
10559
+ - Follow the project's skill structure and progressive-disclosure conventions
10560
+ - Don't delete a skill without confirming nothing depends on it`
10561
+ },
10562
+ budget: LIGHT_BUDGET,
10563
+ capability: {
10564
+ phase: "meta",
10565
+ summary: "Skill curation: audits, refines descriptions/triggers, scaffolds, and retires skills.",
10566
+ keywords: [
10567
+ "skill",
10568
+ "skills",
10569
+ "curate skill",
10570
+ "skill description",
10571
+ "create skill",
10572
+ "skill library",
10573
+ "skill trigger",
10574
+ "manage skills"
10575
+ ]
10576
+ }
10577
+ },
10578
+ {
10579
+ config: {
10580
+ id: "self-improving",
10581
+ name: "Self-Improving",
10582
+ role: "self-improving",
10583
+ tools: [...TOOLS.inspect],
10584
+ prompt: `You are the Self-Improving agent. Your job is to learn from past
10585
+ executions: mine session logs and outcomes to find recurring failures and
10586
+ propose concrete improvements to prompts, tools, or workflows.
10587
+
10588
+ Scope:
10589
+ - Analyze session/agent execution logs for failure and inefficiency patterns
10590
+ - Correlate outcomes with prompts, tool usage, and budgets
10591
+ - Propose specific changes (prompt edits, budget tweaks, new guardrails)
10592
+ - Track whether prior recommendations actually helped
10593
+
10594
+ Input format you accept:
10595
+ { "task": "analyze | propose | evaluate", "logs": "<session path/dir>", "focus": "failures | efficiency | cost" }
10596
+
10597
+ Output: Markdown improvement report:
10598
+ - ## Patterns (recurring failure/inefficiency + frequency)
10599
+ - ## Root Causes (why, with evidence from logs)
10600
+ - ## Proposed Changes (concrete edits, ranked by expected impact)
10601
+ - ## Validation Plan (how to confirm the change helped)
10602
+
10603
+ Working rules:
10604
+ - Ground every recommendation in observed log evidence, not intuition
10605
+ - Quantify the problem (how often, how costly) before proposing a fix
10606
+ - Propose the smallest change that addresses the root cause
10607
+ - Mark recommendations that need A/B validation before adoption`
10608
+ },
10609
+ budget: MEDIUM_BUDGET,
10610
+ capability: {
10611
+ phase: "meta",
10612
+ summary: "Learns from execution logs: mines recurring failures/inefficiencies and proposes evidence-based improvements.",
10613
+ keywords: [
10614
+ "self-improving",
10615
+ "learn from",
10616
+ "session logs",
10617
+ "execution analysis",
10618
+ "recurring failure",
10619
+ "improve agents",
10620
+ "post-mortem",
10621
+ "retrospective",
10622
+ "meta-analysis"
10623
+ ]
10624
+ }
10625
+ },
10626
+ {
10627
+ config: {
10628
+ id: "context",
10629
+ name: "Context",
10630
+ role: "context",
10631
+ tools: [...TOOLS.inspect, "remember", "forget"],
10632
+ prompt: `You are the Context agent. Your job is memory and context-window
10633
+ management: decide what to keep, compact, or recall so the working context
10634
+ stays high-signal and within budget.
10635
+
10636
+ Scope:
10637
+ - Summarize/compact long histories without losing load-bearing detail
10638
+ - Decide what belongs in durable memory vs. ephemeral context
10639
+ - Recall the right prior context for the current task
10640
+ - Detect and prune redundant or stale context
10641
+
10642
+ Input format you accept:
10643
+ { "task": "compact | recall | curate | budget", "target": "<session/context>", "limit": "<token budget>" }
10644
+
10645
+ Output: Markdown context report:
10646
+ - ## Kept (what stays in context + why it's load-bearing)
10647
+ - ## Compacted (summarized away, with the summary)
10648
+ - ## Recalled (durable memory surfaced for this task)
10649
+ - ## Pruned (removed as stale/redundant)
10650
+
10651
+ Working rules:
10652
+ - Never compact away a fact the current task depends on
10653
+ - Prefer summarizing over dropping; keep a pointer to the source
10654
+ - Distinguish durable memory (cross-session) from ephemeral context
10655
+ - Respect the token budget; report when you can't fit the essentials`
10656
+ },
10657
+ budget: LIGHT_BUDGET,
10658
+ capability: {
10659
+ phase: "meta",
10660
+ summary: "Memory + context-window management: compaction, recall, and curation within a token budget.",
10661
+ keywords: [
10662
+ "context",
10663
+ "context window",
10664
+ "memory",
10665
+ "compact",
10666
+ "summarize history",
10667
+ "recall",
10668
+ "token budget",
10669
+ "prune context",
10670
+ "remember",
10671
+ "dfmt"
10672
+ ]
8427
10673
  }
10674
+ },
10675
+ {
10676
+ config: {
10677
+ id: "cost",
10678
+ name: "Cost",
10679
+ role: "cost",
10680
+ tools: [...TOOLS.inspect],
10681
+ prompt: `You are the Cost agent. Your job is token and cloud cost optimization:
10682
+ find where money/tokens are burned and cut waste without losing capability.
10683
+
10684
+ Scope:
10685
+ - Analyze token spend by model, prompt, and tool usage
10686
+ - Identify expensive patterns: oversized prompts, redundant calls, wrong model tier
10687
+ - Recommend model routing (cheap model for cheap tasks, premium where it pays)
10688
+ - Estimate savings of each recommendation
10689
+
10690
+ Input format you accept:
10691
+ { "task": "analyze | optimize | route | estimate", "scope": "<session/feature>", "lever": "tokens | model | calls" }
10692
+
10693
+ Output: Markdown cost report:
10694
+ - ## Spend Breakdown (by model / prompt / tool)
10695
+ - ## Waste (the costly patterns, with $ impact)
10696
+ - ## Recommendations (ranked by savings, with risk)
10697
+ - ## Estimated Savings (per recommendation)
10698
+
10699
+ Working rules:
10700
+ - Quantify in tokens AND dollars; don't hand-wave "it's expensive"
10701
+ - Recommend the cheapest model that still meets the quality bar
10702
+ - Prefer caching and prompt trimming before downgrading models
10703
+ - Flag any optimization that risks correctness or capability`
10704
+ },
10705
+ budget: LIGHT_BUDGET,
10706
+ capability: {
10707
+ phase: "meta",
10708
+ summary: "Token/cloud cost optimization: finds spend waste, recommends model routing and trimming with $ estimates.",
10709
+ keywords: [
10710
+ "cost",
10711
+ "token cost",
10712
+ "optimize cost",
10713
+ "spend",
10714
+ "cheaper",
10715
+ "model routing",
10716
+ "budget",
10717
+ "expensive",
10718
+ "reduce tokens",
10719
+ "pricing",
10720
+ "cloud cost"
10721
+ ]
10722
+ }
10723
+ }
10724
+ ];
10725
+
10726
+ // src/coordination/agents/index.ts
10727
+ var ALL_AGENT_DEFINITIONS = [
10728
+ ...DISCOVERY_AGENTS,
10729
+ ...PLANNING_AGENTS,
10730
+ ...BUILD_AGENTS,
10731
+ ...VERIFY_AGENTS,
10732
+ ...REVIEW_AGENTS,
10733
+ ...DOMAIN_AGENTS,
10734
+ ...KNOWLEDGE_AGENTS,
10735
+ ...DELIVERY_AGENTS,
10736
+ ...META_AGENTS
10737
+ ];
10738
+ var AGENTS_BY_PHASE = {
10739
+ discovery: DISCOVERY_AGENTS,
10740
+ planning: PLANNING_AGENTS,
10741
+ build: BUILD_AGENTS,
10742
+ verify: VERIFY_AGENTS,
10743
+ review: REVIEW_AGENTS,
10744
+ domain: DOMAIN_AGENTS,
10745
+ knowledge: KNOWLEDGE_AGENTS,
10746
+ delivery: DELIVERY_AGENTS,
10747
+ meta: META_AGENTS
10748
+ };
10749
+ var AGENT_CATALOG = (() => {
10750
+ const map = {};
10751
+ for (const def of ALL_AGENT_DEFINITIONS) {
10752
+ const role = def.config.role;
10753
+ if (!role) {
10754
+ throw new Error(`Agent "${def.config.name}" is missing a role`);
10755
+ }
10756
+ if (map[role]) {
10757
+ throw new Error(`Duplicate agent role in catalog: "${role}"`);
10758
+ }
10759
+ map[role] = def;
10760
+ }
10761
+ return map;
10762
+ })();
10763
+ function getAgentDefinition(role) {
10764
+ return AGENT_CATALOG[role];
10765
+ }
10766
+
10767
+ // src/coordination/dispatcher.ts
10768
+ var DEFAULT_DISPATCH_ROLE = "executor";
10769
+ function normalize2(text) {
10770
+ return ` ${text.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim()} `;
10771
+ }
10772
+ function scoreAgents(task, catalog = AGENT_CATALOG) {
10773
+ const hay = normalize2(task);
10774
+ const out = [];
10775
+ for (const def of Object.values(catalog)) {
10776
+ const role = def.config.role;
10777
+ if (!role) continue;
10778
+ let score = 0;
10779
+ const matched = [];
10780
+ for (const kw of def.capability.keywords) {
10781
+ const needle = normalize2(kw);
10782
+ if (hay.includes(needle.trimEnd() + " ") || hay.includes(" " + needle.trimStart())) {
10783
+ const words = kw.trim().split(/\s+/).length;
10784
+ score += words;
10785
+ matched.push(kw);
10786
+ }
10787
+ }
10788
+ if (score > 0) {
10789
+ out.push({ role, name: def.config.name, score, matched });
10790
+ }
10791
+ }
10792
+ out.sort((a, b) => b.score - a.score);
10793
+ return out;
10794
+ }
10795
+ function heuristicConfidence(candidates) {
10796
+ if (candidates.length === 0) return 0;
10797
+ const top = candidates[0].score;
10798
+ const second = candidates[1]?.score ?? 0;
10799
+ const strength = Math.min(1, top / 3);
10800
+ const margin = (top - second + 1) / (top + 1);
10801
+ return Math.min(1, strength * margin);
10802
+ }
10803
+ async function dispatchAgent(task, opts = {}) {
10804
+ const catalog = opts.catalog ?? AGENT_CATALOG;
10805
+ const threshold = opts.confidenceThreshold ?? 0.4;
10806
+ const maxCandidates = opts.maxCandidates ?? 6;
10807
+ const candidates = scoreAgents(task, catalog);
10808
+ const confidence = heuristicConfidence(candidates);
10809
+ const top = candidates[0];
10810
+ if (top && confidence >= threshold) {
8428
10811
  return {
8429
- result: result.finalText,
8430
- iterations: result.iterations,
8431
- toolCalls: usage.toolCalls
10812
+ role: top.role,
10813
+ definition: catalog[top.role],
10814
+ confidence,
10815
+ method: "heuristic",
10816
+ reason: `Matched keywords: ${top.matched.slice(0, 4).join(", ")}`,
10817
+ alternatives: candidates.slice(1, maxCandidates)
10818
+ };
10819
+ }
10820
+ if (opts.classifier) {
10821
+ const pool = (candidates.length > 0 ? candidates.slice(0, maxCandidates).map((c) => catalog[c.role]) : ALL_AGENT_DEFINITIONS).map((d) => ({
10822
+ role: d.config.role,
10823
+ name: d.config.name,
10824
+ summary: d.capability.summary
10825
+ }));
10826
+ try {
10827
+ const choice = await opts.classifier(task, pool);
10828
+ if (choice && catalog[choice.role]) {
10829
+ return {
10830
+ role: choice.role,
10831
+ definition: catalog[choice.role],
10832
+ confidence: 1,
10833
+ method: "llm",
10834
+ reason: choice.reason ?? "Selected by LLM classifier",
10835
+ alternatives: candidates.slice(0, maxCandidates).filter((c) => c.role !== choice.role)
10836
+ };
10837
+ }
10838
+ } catch {
10839
+ }
10840
+ }
10841
+ if (top) {
10842
+ return {
10843
+ role: top.role,
10844
+ definition: catalog[top.role],
10845
+ confidence,
10846
+ method: "heuristic",
10847
+ reason: `Weak match (${top.matched.slice(0, 3).join(", ") || "low signal"})`,
10848
+ alternatives: candidates.slice(1, maxCandidates)
8432
10849
  };
10850
+ }
10851
+ const fallbackRole = catalog[DEFAULT_DISPATCH_ROLE] ? DEFAULT_DISPATCH_ROLE : Object.keys(catalog)[0];
10852
+ return {
10853
+ role: fallbackRole,
10854
+ definition: catalog[fallbackRole],
10855
+ confidence: 0,
10856
+ method: "fallback",
10857
+ reason: "No keyword signal; defaulting to the generalist Executor",
10858
+ alternatives: []
8433
10859
  };
8434
10860
  }
8435
- function defaultFormatTaskInput(task) {
8436
- return task.description ?? "";
10861
+ function makeLLMClassifier(complete) {
10862
+ return async (task, candidates) => {
10863
+ const list = candidates.map((c, i) => `${i + 1}. ${c.role} \u2014 ${c.summary}`).join("\n");
10864
+ const prompt = `You are an agent router. Pick the single best agent for the task.
10865
+
10866
+ Task:
10867
+ ${task}
10868
+
10869
+ Agents:
10870
+ ${list}
10871
+
10872
+ Reply with ONLY a compact JSON object: {"role":"<one role id from the list>","reason":"<short why>"}.
10873
+ Do not add prose, markdown, or code fences.`;
10874
+ const raw = (await complete(prompt)).trim();
10875
+ const match = raw.match(/\{[\s\S]*\}/);
10876
+ if (!match) return null;
10877
+ try {
10878
+ const parsed = JSON.parse(match[0]);
10879
+ if (typeof parsed.role !== "string") return null;
10880
+ const role = parsed.role.trim();
10881
+ const valid = candidates.some((c) => c.role === role);
10882
+ if (!valid) return null;
10883
+ return { role, reason: typeof parsed.reason === "string" ? parsed.reason : void 0 };
10884
+ } catch {
10885
+ return null;
10886
+ }
10887
+ };
8437
10888
  }
8438
10889
 
8439
10890
  // src/coordination/fleet.ts
@@ -8606,13 +11057,19 @@ var FLEET_ROSTER = {
8606
11057
  "audit-log": AUDIT_LOG_AGENT,
8607
11058
  "bug-hunter": BUG_HUNTER_AGENT,
8608
11059
  "refactor-planner": REFACTOR_PLANNER_AGENT,
8609
- "security-scanner": SECURITY_SCANNER_AGENT
11060
+ "security-scanner": SECURITY_SCANNER_AGENT,
11061
+ ...Object.fromEntries(
11062
+ ALL_AGENT_DEFINITIONS.map((d) => [d.config.role, d.config])
11063
+ )
8610
11064
  };
8611
11065
  var FLEET_ROSTER_BUDGETS = {
8612
11066
  "audit-log": { timeoutMs: 7.5 * 60 * 60 * 1e3, maxIterations: 5e3, maxToolCalls: 15e3 },
8613
11067
  "bug-hunter": { timeoutMs: 10 * 60 * 60 * 1e3, maxIterations: 8e3, maxToolCalls: 2e4 },
8614
11068
  "refactor-planner": { timeoutMs: 7.5 * 60 * 60 * 1e3, maxIterations: 6e3, maxToolCalls: 18e3 },
8615
- "security-scanner": { timeoutMs: 10 * 60 * 60 * 1e3, maxIterations: 8e3, maxToolCalls: 2e4 }
11069
+ "security-scanner": { timeoutMs: 10 * 60 * 60 * 1e3, maxIterations: 8e3, maxToolCalls: 2e4 },
11070
+ ...Object.fromEntries(
11071
+ ALL_AGENT_DEFINITIONS.map((d) => [d.config.role, d.budget])
11072
+ )
8616
11073
  };
8617
11074
  var GENERIC_SUBAGENT_BUDGET = {
8618
11075
  timeoutMs: 3 * 60 * 60 * 1e3,
@@ -8633,6 +11090,67 @@ function applyRosterBudget(cfg) {
8633
11090
  };
8634
11091
  }
8635
11092
  var ALL_FLEET_AGENTS = Object.values(FLEET_ROSTER);
11093
+ var CLINE_AGENT = {
11094
+ id: "cline",
11095
+ name: "Cline",
11096
+ role: "cline",
11097
+ prompt: `You are Cline, a coding agent. You help write, edit, and navigate code.
11098
+ You operate by receiving tasks via ACP and returning results.
11099
+ When asked to code, make focused changes and explain them briefly.`,
11100
+ provider: "acp"
11101
+ };
11102
+ var GEMINI_CLI_AGENT = {
11103
+ id: "gemini-cli",
11104
+ name: "Gemini CLI",
11105
+ role: "gemini-cli",
11106
+ prompt: `You are Gemini CLI, a coding agent powered by Google's Gemini model.
11107
+ You help with code generation, editing, debugging, and best practices.
11108
+ You operate by receiving tasks via ACP and returning results.`,
11109
+ provider: "acp"
11110
+ };
11111
+ var COPILOT_AGENT = {
11112
+ id: "copilot",
11113
+ name: "GitHub Copilot",
11114
+ role: "copilot",
11115
+ prompt: `You are GitHub Copilot, an AI coding assistant.
11116
+ You help write, explain, refactor, and review code.
11117
+ You operate by receiving tasks via ACP and returning results.`,
11118
+ provider: "acp"
11119
+ };
11120
+ var OPENHANDS_AGENT = {
11121
+ id: "openhands",
11122
+ name: "OpenHands",
11123
+ role: "openhands",
11124
+ prompt: `You are OpenHands, an AI coding agent that can use tools to interact
11125
+ with files, terminals, browsers, and other resources.
11126
+ You operate by receiving tasks via ACP and returning results.`,
11127
+ provider: "acp"
11128
+ };
11129
+ var GOOSE_AGENT = {
11130
+ id: "goose",
11131
+ name: "Goose",
11132
+ role: "goose",
11133
+ prompt: `You are Goose, an AI agent that helps with coding tasks.
11134
+ You operate by receiving tasks via ACP and returning results.
11135
+ Focus on writing high-quality, well-tested code.`,
11136
+ provider: "acp"
11137
+ };
11138
+ var ACP_AGENTS = [
11139
+ CLINE_AGENT,
11140
+ GEMINI_CLI_AGENT,
11141
+ COPILOT_AGENT,
11142
+ OPENHANDS_AGENT,
11143
+ GOOSE_AGENT
11144
+ ];
11145
+ FLEET_ROSTER_BUDGETS["cline"] = { timeoutMs: 10 * 60 * 60 * 1e3, maxIterations: 8e3, maxToolCalls: 2e4 };
11146
+ FLEET_ROSTER_BUDGETS["gemini-cli"] = { timeoutMs: 10 * 60 * 60 * 1e3, maxIterations: 8e3, maxToolCalls: 2e4 };
11147
+ FLEET_ROSTER_BUDGETS["copilot"] = { timeoutMs: 10 * 60 * 60 * 1e3, maxIterations: 8e3, maxToolCalls: 2e4 };
11148
+ FLEET_ROSTER_BUDGETS["openhands"] = { timeoutMs: 10 * 60 * 60 * 1e3, maxIterations: 8e3, maxToolCalls: 2e4 };
11149
+ FLEET_ROSTER_BUDGETS["goose"] = { timeoutMs: 10 * 60 * 60 * 1e3, maxIterations: 8e3, maxToolCalls: 2e4 };
11150
+ ({
11151
+ ...FLEET_ROSTER,
11152
+ ...Object.fromEntries(ACP_AGENTS.map((a) => [a.role, a]))
11153
+ });
8636
11154
 
8637
11155
  // src/coordination/multi-agent-coordinator.ts
8638
11156
  var DefaultMultiAgentCoordinator = class extends EventEmitter {
@@ -8739,6 +11257,32 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
8739
11257
  this.drainPendingAsAborted("Coordinator stopAll() drained the pending queue");
8740
11258
  await Promise.allSettled([...this.subagents.keys()].map((id) => this.stop(id)));
8741
11259
  }
11260
+ async remove(subagentId) {
11261
+ await this.stop(subagentId);
11262
+ this.subagents.delete(subagentId);
11263
+ }
11264
+ /**
11265
+ * Get current coordinator stats for monitoring/debugging.
11266
+ */
11267
+ getStats() {
11268
+ let running = 0;
11269
+ let idle = 0;
11270
+ let stopped = 0;
11271
+ for (const [, entry] of this.subagents) {
11272
+ if (entry.status === "running") running++;
11273
+ else if (entry.status === "idle") idle++;
11274
+ else stopped++;
11275
+ }
11276
+ return {
11277
+ total: this.subagents.size,
11278
+ running,
11279
+ idle,
11280
+ stopped,
11281
+ inFlight: this.inFlight,
11282
+ pending: this.pendingTasks.length,
11283
+ completed: this.completedResults.length
11284
+ };
11285
+ }
8742
11286
  getStatus() {
8743
11287
  return {
8744
11288
  coordinatorId: this.coordinatorId,
@@ -9187,6 +11731,8 @@ var ParallelEternalEngine = class {
9187
11731
  this.goalPath = goalFilePath(opts.projectRoot);
9188
11732
  this.slots = Math.min(16, Math.max(1, opts.parallelSlots ?? 4));
9189
11733
  this.timeoutMs = opts.iterationTimeoutMs ?? 3e5;
11734
+ this.dispatchEnabled = opts.dispatch !== false;
11735
+ this.dispatchClassifier = opts.dispatchClassifier;
9190
11736
  this.agentFactory = opts.subagentFactory ?? (async (config) => ({
9191
11737
  agent: this.opts.agent,
9192
11738
  events: this.opts.agent.events
@@ -9203,9 +11749,17 @@ var ParallelEternalEngine = class {
9203
11749
  timeoutMs;
9204
11750
  coordinator = null;
9205
11751
  agentFactory;
11752
+ dispatchEnabled;
11753
+ dispatchClassifier;
9206
11754
  get currentState() {
9207
11755
  return this.state;
9208
11756
  }
11757
+ /**
11758
+ * Get the underlying coordinator for stats/monitoring.
11759
+ */
11760
+ getCoordinator() {
11761
+ return this.coordinator;
11762
+ }
9209
11763
  stop() {
9210
11764
  this.stopRequested = true;
9211
11765
  void this.persistState("stopped").catch(() => {
@@ -9285,9 +11839,10 @@ var ParallelEternalEngine = class {
9285
11839
  fanOut.goalComplete ? "[GOAL_COMPLETE]" : "",
9286
11840
  fanOut.partialOutput ? `Output: ${fanOut.partialOutput.slice(0, 120)}` : ""
9287
11841
  ].filter(Boolean).join(" | ");
11842
+ const routeSummary = fanOut.routes.length > 0 ? fanOut.routes.slice(0, 3).map((r) => `${r.role}\u2192${r.task.slice(0, 28)}`).join(", ") : tasks.slice(0, 3).join(", ");
9288
11843
  await this.appendIterationEntry({
9289
11844
  source: "parallel",
9290
- task: `parallel:${tasks.length} slots \u2014 ${tasks.slice(0, 3).join(", ")}${tasks.length > 3 ? "..." : ""}`,
11845
+ task: `parallel:${tasks.length} slots \u2014 ${routeSummary}${tasks.length > 3 ? "..." : ""}`,
9291
11846
  status,
9292
11847
  note
9293
11848
  });
@@ -9304,6 +11859,11 @@ var ParallelEternalEngine = class {
9304
11859
  async fanOut(goal, tasks) {
9305
11860
  const coordinator = this.coordinator;
9306
11861
  const slotCount = Math.min(this.slots, tasks.length);
11862
+ const routes = this.dispatchEnabled ? await Promise.all(
11863
+ tasks.slice(0, slotCount).map(
11864
+ (t2) => dispatchAgent(t2, { classifier: this.dispatchClassifier }).catch(() => null)
11865
+ )
11866
+ ) : [];
9307
11867
  const recentJournal = goal.journal.slice(-5).map((e) => ` #${e.iteration} [${e.status}] ${e.task}${e.note ? ` \u2014 ${e.note.slice(0, 80)}` : ""}`).join("\n");
9308
11868
  const directivePreamble = [
9309
11869
  "\u2550\u2550\u2550 ETERNAL AUTONOMY \u2014 parallel task slot \u2550\u2550\u2550",
@@ -9323,29 +11883,48 @@ ${recentJournal}` : "No prior iterations.",
9323
11883
  ].join("\n");
9324
11884
  const taskIds = [];
9325
11885
  const subagentIds = [];
11886
+ const routeInfo = [];
9326
11887
  const spawnPromises = [];
9327
11888
  for (let i = 0; i < slotCount; i++) {
9328
11889
  const task = tasks[i];
11890
+ const route = routes[i] ?? null;
9329
11891
  const subagentId = `parallel-${this.iterations}-${i}`;
9330
11892
  const taskId = randomUUID();
11893
+ const personaLine = route ? `Acting agent: ${route.definition.config.name} \u2014 ${route.definition.capability.summary}
11894
+ ` : "";
9331
11895
  const spec = {
9332
11896
  id: taskId,
9333
11897
  description: `${directivePreamble}
9334
11898
 
9335
11899
  \u2500\u2500 SLOT ${i + 1}/${slotCount} \u2500\u2500
9336
- Task: ${task}
11900
+ ${personaLine}Task: ${task}
9337
11901
  `,
9338
11902
  subagentId
9339
11903
  };
11904
+ routeInfo.push({
11905
+ slot: i,
11906
+ task,
11907
+ role: route?.role ?? "generic",
11908
+ method: route?.method ?? "none"
11909
+ });
9340
11910
  spawnPromises.push((async () => {
9341
11911
  try {
9342
- await coordinator.spawn({
9343
- id: subagentId,
9344
- name: `slot-${subagentId.slice(-6)}`,
9345
- maxIterations: 50,
9346
- maxToolCalls: 200,
9347
- timeoutMs: this.timeoutMs
9348
- });
11912
+ await coordinator.spawn(
11913
+ route ? {
11914
+ id: subagentId,
11915
+ name: route.definition.config.name,
11916
+ role: route.role,
11917
+ tools: route.definition.config.tools,
11918
+ systemPromptOverride: route.definition.config.prompt,
11919
+ timeoutMs: this.timeoutMs
11920
+ } : {
11921
+ id: subagentId,
11922
+ name: `slot-${subagentId.slice(-6)}`,
11923
+ // Let the coordinator apply its default budget (roster or generic).
11924
+ // Hardcoding low limits here defeats the x10 budget improvement.
11925
+ timeoutMs: this.timeoutMs
11926
+ }
11927
+ );
9349
11928
  subagentIds.push(subagentId);
9350
11929
  taskIds.push(taskId);
9351
11930
  await coordinator.assign(spec);
@@ -9355,12 +11934,12 @@ Task: ${task}
9355
11934
  }
9356
11935
  await Promise.all(spawnPromises);
9357
11936
  if (taskIds.length === 0) {
9358
- return { results: [], allSuccessful: false, goalComplete: false, partialOutput: "" };
11937
+ return { results: [], allSuccessful: false, goalComplete: false, partialOutput: "", routes: routeInfo };
9359
11938
  }
9360
11939
  let results = [];
9361
11940
  try {
9362
11941
  const ctrl = new AbortController();
9363
- const timer = setTimeout(() => ctrl.abort(), this.timeoutMs + 6e4);
11942
+ const timer = setTimeout(() => ctrl.abort(), Math.max(this.timeoutMs * 2, 72e5));
9364
11943
  try {
9365
11944
  results = await coordinator.awaitTasks(taskIds);
9366
11945
  } finally {
@@ -9374,7 +11953,7 @@ Task: ${task}
9374
11953
  (r) => r.status === "success" && typeof r.result === "string" && GOAL_COMPLETE_MARKER2.test(r.result)
9375
11954
  );
9376
11955
  const partialOutput = results.map((r) => typeof r.result === "string" ? r.result : "").filter(Boolean).join("\n\n");
9377
- return { results, allSuccessful, goalComplete, partialOutput };
11956
+ return { results, allSuccessful, goalComplete, partialOutput, routes: routeInfo };
9378
11957
  }
9379
11958
  // -------------------------------------------------------------------------
9380
11959
  // Goal decomposition
@@ -10246,6 +12825,9 @@ var Director = class {
10246
12825
  /** Snapshot of which subagent owns each task — drives state-checkpoint
10247
12826
  * status updates without re-walking the manifest. */
10248
12827
  taskOwners = /* @__PURE__ */ new Map();
12828
+ /** Cumulative auto-extension grants per subagent (all budget kinds). Lets
12829
+ * /fleet render "⚡ extended ×N" without replaying the event stream. */
12830
+ extendTotals = /* @__PURE__ */ new Map();
10249
12831
  /**
10250
12832
  * Handle to the coordinator-side `task.completed` listener so we can
10251
12833
  * unsubscribe in `shutdown()`. Without this, repeated Director
@@ -10341,8 +12923,28 @@ var Director = class {
10341
12923
  };
10342
12924
  this.coordinator.on("task.completed", this.taskCompletedListener);
10343
12925
  const extendCounts = /* @__PURE__ */ new Map();
12926
+ const progressBySubagent = /* @__PURE__ */ new Map();
12927
+ const lastTimeoutProgress = /* @__PURE__ */ new Map();
12928
+ this.fleet.filter("tool.executed", (e) => {
12929
+ progressBySubagent.set(e.subagentId, (progressBySubagent.get(e.subagentId) ?? 0) + 1);
12930
+ });
10344
12931
  this.fleet.filter("budget.threshold_reached", (e) => {
10345
12932
  const payload = e.payload;
12933
+ if (payload.kind === "timeout") {
12934
+ const progress = progressBySubagent.get(e.subagentId) ?? 0;
12935
+ const lastProgress = lastTimeoutProgress.get(e.subagentId) ?? -1;
12936
+ if (progress <= lastProgress) {
12937
+ payload.deny();
12938
+ return;
12939
+ }
12940
+ lastTimeoutProgress.set(e.subagentId, progress);
12941
+ setImmediate(() => {
12942
+ const newLimit = Math.min(Math.ceil(payload.limit * 2), 24 * 60 * 6e4);
12943
+ this.recordExtension(e.subagentId, e.taskId, "timeout", newLimit);
12944
+ payload.extend({ timeoutMs: newLimit });
12945
+ });
12946
+ return;
12947
+ }
10346
12948
  const guardKey = `${e.subagentId}:${payload.kind}`;
10347
12949
  const prior = extendCounts.get(guardKey) ?? 0;
10348
12950
  if (prior >= this.maxBudgetExtensions) {
@@ -10353,27 +12955,52 @@ var Director = class {
10353
12955
  extendCounts.set(guardKey, prior + 1);
10354
12956
  setImmediate(() => {
10355
12957
  const extra = {};
12958
+ const base = Math.max(payload.limit, payload.used);
12959
+ const grow = (ceiling) => Math.min(Math.ceil(base * 1.5), ceiling);
12960
+ let newLimit = base;
10356
12961
  switch (payload.kind) {
10357
12962
  case "iterations":
10358
- extra.maxIterations = Math.min(payload.used + 100, 800);
12963
+ newLimit = grow(5e4);
12964
+ extra.maxIterations = newLimit;
10359
12965
  break;
10360
12966
  case "tool_calls":
10361
- extra.maxToolCalls = Math.min(Math.ceil(payload.limit * 2), 1500);
12967
+ newLimit = grow(1e5);
12968
+ extra.maxToolCalls = newLimit;
10362
12969
  break;
10363
12970
  case "tokens":
10364
- extra.maxTokens = Math.min(Math.ceil(payload.limit * 2), 8e5);
12971
+ newLimit = grow(5e6);
12972
+ extra.maxTokens = newLimit;
10365
12973
  break;
10366
12974
  case "cost":
10367
- extra.maxCostUsd = Math.min(payload.limit * 2, 25);
10368
- break;
10369
- case "timeout":
10370
- extra.timeoutMs = Math.min(Math.ceil(payload.limit * 2), 2 * 60 * 6e4);
12975
+ newLimit = Math.min(base * 1.5, 100);
12976
+ extra.maxCostUsd = newLimit;
10371
12977
  break;
10372
12978
  }
12979
+ this.recordExtension(e.subagentId, e.taskId, payload.kind, newLimit);
10373
12980
  payload.extend(extra);
10374
12981
  });
10375
12982
  });
10376
12983
  }
12984
+ /**
12985
+ * Record a granted budget extension and broadcast it on the FleetBus so
12986
+ * the host can re-emit `subagent.budget_extended` for live UI badges.
12987
+ * Called from both the timeout heartbeat path and the per-kind grant path.
12988
+ */
12989
+ recordExtension(subagentId, taskId, kind, newLimit) {
12990
+ const total = (this.extendTotals.get(subagentId) ?? 0) + 1;
12991
+ this.extendTotals.set(subagentId, total);
12992
+ this.fleet.emit({
12993
+ subagentId,
12994
+ taskId,
12995
+ ts: Date.now(),
12996
+ type: "budget.extended",
12997
+ payload: { kind, newLimit, totalExtensions: total }
12998
+ });
12999
+ }
13000
+ /** Cumulative auto-extension count for one subagent (0 when never extended). */
13001
+ extensionsFor(subagentId) {
13002
+ return this.extendTotals.get(subagentId) ?? 0;
13003
+ }
10377
13004
  /** Best-effort session-writer append. Swallows failures — the director
10378
13005
  * must not break a fleet run because the session JSONL handle closed. */
10379
13006
  async appendSessionEvent(event) {
@@ -10427,11 +13054,7 @@ var Director = class {
10427
13054
  }
10428
13055
  }
10429
13056
  let result;
10430
- try {
10431
- result = await this.coordinator.spawn(config);
10432
- } catch (err) {
10433
- throw err;
10434
- }
13057
+ result = await this.coordinator.spawn(config);
10435
13058
  if (this.fleetManager) {
10436
13059
  this.fleetManager.recordSpawn(result.subagentId, config, priceLookup);
10437
13060
  } else {
@@ -10699,8 +13322,18 @@ var Director = class {
10699
13322
  async terminateAll() {
10700
13323
  await this.coordinator.stopAll();
10701
13324
  }
13325
+ async remove(subagentId) {
13326
+ await this.coordinator.remove(subagentId);
13327
+ }
10702
13328
  status() {
10703
- return this.coordinator.getStatus();
13329
+ const base = this.coordinator.getStatus();
13330
+ return {
13331
+ ...base,
13332
+ subagents: base.subagents.map((s) => ({
13333
+ ...s,
13334
+ extensions: this.extendTotals.get(s.id) ?? 0
13335
+ }))
13336
+ };
10704
13337
  }
10705
13338
  /**
10706
13339
  * Subscribe to coordinator events. Currently only `task.completed` is
@@ -10984,9 +13617,8 @@ function createDelegateTool(opts) {
10984
13617
  cfg.maxToolCalls = i.maxToolCalls;
10985
13618
  }
10986
13619
  const SUBAGENT_TIMEOUT_BUFFER_MS = opts.subagentTimeoutBufferMs ?? 6e4;
10987
- const desiredSubTimeout = Math.max(3e4, timeoutMs - SUBAGENT_TIMEOUT_BUFFER_MS);
10988
- if (!cfg.timeoutMs || cfg.timeoutMs > desiredSubTimeout) {
10989
- cfg.timeoutMs = desiredSubTimeout;
13620
+ if (!cfg.timeoutMs) {
13621
+ cfg.timeoutMs = Math.max(3e4, timeoutMs - SUBAGENT_TIMEOUT_BUFFER_MS);
10990
13622
  }
10991
13623
  const subagentId = await director.spawn(cfg);
10992
13624
  const taskId = await director.assign({
@@ -10994,15 +13626,30 @@ function createDelegateTool(opts) {
10994
13626
  description: i.task,
10995
13627
  subagentId
10996
13628
  });
10997
- const result = await Promise.race([
10998
- director.awaitTasks([taskId]).then((r) => {
10999
- if (!r[0]) throw new Error(`Task "${taskId}" not found in completed results`);
11000
- return r[0];
11001
- }),
11002
- new Promise(
11003
- (resolve5) => setTimeout(() => resolve5({ __timeout: true }), timeoutMs)
11004
- )
11005
- ]);
13629
+ const dir = director;
13630
+ const result = await new Promise((resolve5) => {
13631
+ let settled = false;
13632
+ let timer;
13633
+ const finish = (value) => {
13634
+ if (settled) return;
13635
+ settled = true;
13636
+ if (timer) clearTimeout(timer);
13637
+ offTool();
13638
+ offIter();
13639
+ resolve5(value);
13640
+ };
13641
+ const arm = () => {
13642
+ if (timer) clearTimeout(timer);
13643
+ timer = setTimeout(() => finish({ __timeout: true }), timeoutMs);
13644
+ };
13645
+ const bump = (e) => {
13646
+ if (e.subagentId === subagentId) arm();
13647
+ };
13648
+ const offTool = dir.fleet.filter("tool.executed", bump);
13649
+ const offIter = dir.fleet.filter("iteration.started", bump);
13650
+ arm();
13651
+ dir.awaitTasks([taskId]).then((r) => finish(r[0] ?? { __timeout: true })).catch(() => finish({ __timeout: true }));
13652
+ });
11006
13653
  if ("__timeout" in result) {
11007
13654
  const partial2 = await readSubagentPartial(opts, subagentId);
11008
13655
  return {
@@ -11206,6 +13853,64 @@ function makeDirectorSessionFactory(opts) {
11206
13853
  };
11207
13854
  }
11208
13855
 
13856
+ // src/coordination/auto-extend.ts
13857
+ var DEFAULT_CEILING = {
13858
+ maxIterations: 5e4,
13859
+ maxToolCalls: 1e5,
13860
+ maxTokens: 5e6,
13861
+ maxCostUsd: 100,
13862
+ timeoutMs: 24 * 60 * 60 * 1e3
13863
+ };
13864
+ var FIELD_BY_KIND = {
13865
+ iterations: "maxIterations",
13866
+ tool_calls: "maxToolCalls",
13867
+ tokens: "maxTokens",
13868
+ cost: "maxCostUsd",
13869
+ timeout: "timeoutMs"
13870
+ };
13871
+ function attachAutoExtend(events, policy = {}) {
13872
+ const factor = policy.factor ?? 0.5;
13873
+ const maxPerKind = policy.maxExtensionsPerKind ?? 8;
13874
+ const ceiling = { ...DEFAULT_CEILING, ...policy.ceiling };
13875
+ const extendCounts = /* @__PURE__ */ new Map();
13876
+ let progress = 0;
13877
+ let lastTimeoutProgress = -1;
13878
+ const unsubs = [
13879
+ events.on("tool.executed", () => {
13880
+ progress++;
13881
+ }),
13882
+ events.on("iteration.started", () => {
13883
+ progress++;
13884
+ }),
13885
+ events.on("budget.threshold_reached", (e) => {
13886
+ const { kind, limit, extend, deny } = e;
13887
+ if (kind === "timeout") {
13888
+ if (progress > lastTimeoutProgress) {
13889
+ lastTimeoutProgress = progress;
13890
+ const next2 = Math.min(Math.ceil(limit * (1 + factor)), ceiling.timeoutMs);
13891
+ extend({ timeoutMs: next2 });
13892
+ } else {
13893
+ deny();
13894
+ }
13895
+ return;
13896
+ }
13897
+ const count = extendCounts.get(kind) ?? 0;
13898
+ if (count >= maxPerKind) {
13899
+ deny();
13900
+ return;
13901
+ }
13902
+ extendCounts.set(kind, count + 1);
13903
+ const field = FIELD_BY_KIND[kind];
13904
+ const cap = ceiling[field];
13905
+ const next = Math.min(Math.ceil(limit * (1 + factor)), cap);
13906
+ extend({ [field]: next });
13907
+ })
13908
+ ];
13909
+ return () => {
13910
+ for (const u of unsubs) u();
13911
+ };
13912
+ }
13913
+
11209
13914
  // src/coordination/null-fleet-bus.ts
11210
13915
  var NULL_FLEET_BUS = new FleetBus();
11211
13916
 
@@ -14445,6 +17150,7 @@ function createContextManagerTool(opts = {}) {
14445
17150
  };
14446
17151
  }
14447
17152
  const report = await opts.compactor.compact(ctx);
17153
+ ctx.clearFileTracking();
14448
17154
  const repair = applyMessages([...ctx.messages]);
14449
17155
  const afterTokens = repair.changed ? roughEstimate(ctx.messages) : report.after;
14450
17156
  const repaired = report.repaired ?? (repair.changed ? repair : void 0);
@@ -14473,6 +17179,7 @@ function createContextManagerTool(opts = {}) {
14473
17179
  }
14474
17180
  const copy = [...messages];
14475
17181
  const removed = copy.splice(from, to - from + 1);
17182
+ ctx.clearFileTracking();
14476
17183
  const repair = applyMessages(copy);
14477
17184
  const afterTokens = roughEstimate(ctx.messages);
14478
17185
  return {
@@ -14530,6 +17237,7 @@ function createContextManagerTool(opts = {}) {
14530
17237
  };
14531
17238
  const copy = [...messages];
14532
17239
  copy.splice(from, to - from + 1, summaryMsg);
17240
+ ctx.clearFileTracking();
14533
17241
  const repair = applyMessages(copy);
14534
17242
  const afterTokens = roughEstimate(ctx.messages);
14535
17243
  return {
@@ -15527,7 +18235,7 @@ var TechStackDetector = class {
15527
18235
  }
15528
18236
  for (const stack of stacks) {
15529
18237
  const indicators = MONOREPO_INDICATORS[stack.packageManager];
15530
- if (indicators && indicators.some((ind) => files.includes(ind) || dirs.includes(ind))) {
18238
+ if (indicators?.some((ind) => files.includes(ind) || dirs.includes(ind))) {
15531
18239
  return true;
15532
18240
  }
15533
18241
  }
@@ -16284,8 +18992,10 @@ var ReportGenerator = class {
16284
18992
  groupByCategory(findings) {
16285
18993
  const groups = {};
16286
18994
  for (const finding of findings) {
16287
- const group = groups[finding.category] ?? (groups[finding.category] = []);
16288
- group.push(finding);
18995
+ if (groups[finding.category] === void 0) {
18996
+ groups[finding.category] = [];
18997
+ }
18998
+ groups[finding.category].push(finding);
16289
18999
  }
16290
19000
  return groups;
16291
19001
  }
@@ -16425,7 +19135,6 @@ var defaultGitignoreUpdater = new GitignoreUpdater();
16425
19135
 
16426
19136
  // src/security-scanner/orchestrator.ts
16427
19137
  init_atomic_write();
16428
- var NETWORK_ERR_RE2 = /ECONN|ETIMEDOUT|ETIME|ENOTFOUND|EAI_AGAIN|fetch failed/i;
16429
19138
  var SecurityScannerOrchestrator = class {
16430
19139
  constructor(retryPolicy, errorHandler) {
16431
19140
  this.retryPolicy = retryPolicy;
@@ -16448,7 +19157,7 @@ var SecurityScannerOrchestrator = class {
16448
19157
  const isProviderErr = err instanceof ProviderError;
16449
19158
  const policy = this.retryPolicy;
16450
19159
  const errAsErr = isProviderErr ? err : err instanceof Error ? err : new Error(String(err));
16451
- if (!policy || !isProviderErr && !NETWORK_ERR_RE2.test(errAsErr.message)) {
19160
+ if (!policy || !isProviderErr && !NETWORK_ERR_RE.test(errAsErr.message)) {
16452
19161
  throw err;
16453
19162
  }
16454
19163
  const canRetry = policy.shouldRetry(errAsErr, attempt);
@@ -17104,8 +19813,8 @@ ${list}
17104
19813
 
17105
19814
  Use \`/security report <number>\` to view a specific report.` };
17106
19815
  }
17107
- const index = parseInt(reportId, 10) - 1;
17108
- if (!isNaN(index) && reports[index]) {
19816
+ const index = Number.parseInt(reportId, 10) - 1;
19817
+ if (!Number.isNaN(index) && reports[index]) {
17109
19818
  const { readFile: readFile30 } = await import('fs/promises');
17110
19819
  const content = await readFile30(join(reportsDir, reports[index]), "utf-8");
17111
19820
  return { message: `# Security Report
@@ -17645,7 +20354,7 @@ var ExtensionRegistry = class {
17645
20354
  if (this.extensions.some((e) => e.name === ext.name)) {
17646
20355
  throw new WrongStackError({
17647
20356
  message: `Extension "${ext.name}" already registered`,
17648
- code: "REGISTRY_DUPLICATE",
20357
+ code: ERROR_CODES.REGISTRY_DUPLICATE,
17649
20358
  subsystem: "container",
17650
20359
  context: { extension: ext.name }
17651
20360
  });
@@ -18651,6 +21360,13 @@ var Context = class {
18651
21360
  this.readFiles.add(absPath);
18652
21361
  this.fileMtimes.set(absPath, mtimeMs);
18653
21362
  }
21363
+ /** Clear accumulated file-read metadata after compaction or at boundaries
21364
+ * where stale read history could cause tools to skip legitimate re-reads.
21365
+ * The agent re-populates this naturally on the next file access. */
21366
+ clearFileTracking() {
21367
+ this.readFiles.clear();
21368
+ this.fileMtimes.clear();
21369
+ }
18654
21370
  hasRead(absPath) {
18655
21371
  return this.readFiles.has(absPath);
18656
21372
  }
@@ -18743,6 +21459,16 @@ var InputBuilder = class {
18743
21459
  this.refs.push(ref);
18744
21460
  return placeholder;
18745
21461
  }
21462
+ /**
21463
+ * Whether `appendPaste(text)` would collapse the text to a placeholder
21464
+ * (rather than inlining it). Lets a frontend decide where to route a paste
21465
+ * — e.g. collapsed pastes become a pill, while inlined ones can be shown
21466
+ * in the editable input row — without calling `appendPaste` first (which
21467
+ * mutates the display buffer).
21468
+ */
21469
+ wouldCollapse(text) {
21470
+ return this.shouldCollapse(text);
21471
+ }
18746
21472
  /** Reset display and ref list. Does NOT clear the store itself. */
18747
21473
  reset() {
18748
21474
  this.display = "";
@@ -19210,7 +21936,7 @@ var ToolRegistry = class _ToolRegistry {
19210
21936
  if (this.tools.has(tool.name)) {
19211
21937
  throw new WrongStackError({
19212
21938
  message: `Tool "${tool.name}" already registered`,
19213
- code: "REGISTRY_DUPLICATE",
21939
+ code: ERROR_CODES.REGISTRY_DUPLICATE,
19214
21940
  subsystem: "container",
19215
21941
  context: { tool: tool.name }
19216
21942
  });
@@ -19262,7 +21988,7 @@ var ToolRegistry = class _ToolRegistry {
19262
21988
  if (!this.tools.has(name)) {
19263
21989
  throw new WrongStackError({
19264
21990
  message: `Tool "${name}" not registered; cannot override`,
19265
- code: "REGISTRY_NOT_FOUND",
21991
+ code: ERROR_CODES.REGISTRY_NOT_FOUND,
19266
21992
  subsystem: "container",
19267
21993
  context: { tool: name }
19268
21994
  });
@@ -19285,7 +22011,7 @@ var ToolRegistry = class _ToolRegistry {
19285
22011
  if (!entry) {
19286
22012
  throw new WrongStackError({
19287
22013
  message: `Tool "${name}" not registered; cannot wrap`,
19288
- code: "REGISTRY_NOT_FOUND",
22014
+ code: ERROR_CODES.REGISTRY_NOT_FOUND,
19289
22015
  subsystem: "container",
19290
22016
  context: { tool: name }
19291
22017
  });
@@ -19667,7 +22393,7 @@ function topoSort(plugins) {
19667
22393
  if (visiting.has(p.name)) {
19668
22394
  throw new PluginError({
19669
22395
  message: `Plugin dependency cycle: ${[...stack, p.name].join(" -> ")}`,
19670
- code: "PLUGIN_LOAD_FAILED",
22396
+ code: ERROR_CODES.PLUGIN_LOAD_FAILED,
19671
22397
  pluginName: p.name
19672
22398
  });
19673
22399
  }
@@ -19678,7 +22404,7 @@ function topoSort(plugins) {
19678
22404
  if (!d) {
19679
22405
  throw new PluginError({
19680
22406
  message: `Plugin "${p.name}" depends on missing plugin "${dep.name}"`,
19681
- code: "PLUGIN_MISSING_DEPENDENCY",
22407
+ code: ERROR_CODES.PLUGIN_MISSING_DEPENDENCY,
19682
22408
  pluginName: p.name,
19683
22409
  context: { dependency: dep.name }
19684
22410
  });
@@ -19686,7 +22412,7 @@ function topoSort(plugins) {
19686
22412
  if (dep.version && d.version && !satisfies(dep.version, d.version)) {
19687
22413
  throw new PluginError({
19688
22414
  message: `Plugin "${p.name}" requires "${dep.name}@${dep.version}", found ${d.version}`,
19689
- code: "PLUGIN_LOAD_FAILED",
22415
+ code: ERROR_CODES.PLUGIN_LOAD_FAILED,
19690
22416
  pluginName: p.name,
19691
22417
  context: { dependency: dep.name, required: dep.version, found: d.version }
19692
22418
  });
@@ -19700,7 +22426,7 @@ function topoSort(plugins) {
19700
22426
  if (dep.version && d.version && !satisfies(dep.version, d.version)) {
19701
22427
  throw new PluginError({
19702
22428
  message: `Plugin "${p.name}" optional dep "${dep.name}@${dep.version}" found ${d.version}`,
19703
- code: "PLUGIN_LOAD_FAILED",
22429
+ code: ERROR_CODES.PLUGIN_LOAD_FAILED,
19704
22430
  pluginName: p.name,
19705
22431
  context: { dependency: dep.name, required: dep.version, found: d.version }
19706
22432
  });
@@ -19725,7 +22451,7 @@ async function loadPlugins(plugins, opts) {
19725
22451
  if (names.has(c)) {
19726
22452
  throw new PluginError({
19727
22453
  message: `Plugin "${p.name}" conflicts with loaded plugin "${c}"`,
19728
- code: "PLUGIN_LOAD_FAILED",
22454
+ code: ERROR_CODES.PLUGIN_LOAD_FAILED,
19729
22455
  pluginName: p.name,
19730
22456
  context: { conflictsWith: c }
19731
22457
  });
@@ -19743,7 +22469,7 @@ async function loadPlugins(plugins, opts) {
19743
22469
  if (!satisfies(plugin.apiVersion, kernelVersion)) {
19744
22470
  const err = new PluginError({
19745
22471
  message: `Plugin "${plugin.name}" requires apiVersion ${plugin.apiVersion}; kernel is ${kernelVersion}`,
19746
- code: "PLUGIN_API_MISMATCH",
22472
+ code: ERROR_CODES.PLUGIN_API_MISMATCH,
19747
22473
  pluginName: plugin.name,
19748
22474
  context: { required: plugin.apiVersion, kernel: kernelVersion }
19749
22475
  });
@@ -19765,7 +22491,7 @@ async function loadPlugins(plugins, opts) {
19765
22491
  const detail = firstErr ? `${firstErr.path}: ${firstErr.message}` : "config invalid";
19766
22492
  const err = new PluginError({
19767
22493
  message: `Plugin "${plugin.name}" config invalid \u2014 ${detail}`,
19768
- code: "PLUGIN_LOAD_FAILED",
22494
+ code: ERROR_CODES.PLUGIN_LOAD_FAILED,
19769
22495
  pluginName: plugin.name,
19770
22496
  context: { errors: result.errors }
19771
22497
  });
@@ -19815,7 +22541,7 @@ function wrapApiForCapabilityCheck(plugin, api, log, enforce = false) {
19815
22541
  if (enforce) {
19816
22542
  throw new PluginError({
19817
22543
  message: msg,
19818
- code: "PLUGIN_LOAD_FAILED",
22544
+ code: ERROR_CODES.PLUGIN_LOAD_FAILED,
19819
22545
  pluginName: plugin.name,
19820
22546
  context: { subsystem, detail }
19821
22547
  });
@@ -19888,6 +22614,6 @@ function wrapApiForCapabilityCheck(plugin, api, log, enforce = false) {
19888
22614
  });
19889
22615
  }
19890
22616
 
19891
- export { AISpecBuilder, ALL_FLEET_AGENTS, AUDIT_LOG_AGENT, Agent, AgentError, AutoApprovePermissionPolicy, AutoCompactionMiddleware, AutoExecutor, AutonomousRunner, BUG_HUNTER_AGENT, BudgetExceededError, CONTEXT_WINDOW_MODES, ConfigError, ConfigMigrationError, Container, Context, ConversationState, DEFAULT_CONFIG_MIGRATIONS, DEFAULT_CONTEXT_WINDOW_MODE_ID, DEFAULT_DIRECTOR_PREAMBLE, DEFAULT_MAX_ITERATIONS, DEFAULT_MODES, DEFAULT_RECOVERY_STRATEGIES, DEFAULT_SPEC_TEMPLATE, DEFAULT_SUBAGENT_BASELINE, DefaultAttachmentStore, DefaultConfigLoader, DefaultConfigStore, DefaultErrorHandler, DefaultHealthRegistry, DefaultLogger, DefaultMemoryStore, DefaultModeStore, DefaultModelsRegistry, DefaultMultiAgentCoordinator, DefaultPathResolver, DefaultPermissionPolicy, DefaultPluginAPI, DefaultProviderRunner, DefaultRetryPolicy, DefaultSecretScrubber, DefaultSecretVault, DefaultSessionReader, DefaultSessionRewinder, DefaultSessionStore, DefaultSkillLoader, DefaultSystemPromptBuilder, DefaultTaskStore, DefaultTokenCounter, Director, DirectorStateCheckpoint, DoneConditionChecker, EternalAutonomyEngine, EventBus, ExtensionRegistry, FLEET_ROSTER, FLEET_ROSTER_BUDGETS, FleetBus, FleetManager, FleetSpawnBudgetError, FleetUsageAggregator, GitignoreUpdater, HybridCompactor, InMemoryAgentBridge, InMemoryBridgeTransport, InMemoryMetricsSink, InputBuilder, IntelligentCompactor, KERNEL_API_VERSION, LAYER_1_IDENTITY, LLMSelector, MAX_JOURNAL_ENTRIES, NULL_FLEET_BUS, NoopMetricsSink, NoopTracer, OTelTracer, PROMETHEUS_CONTENT_TYPE, ParallelEternalEngine, Pipeline, PluginError, ProviderError, ProviderRegistry, QueueStore, REFACTOR_PLANNER_AGENT, RecoveryLock, ReportGenerator, RunController, SECURITY_SCANNER_AGENT, SPEC_TEMPLATES, ScopedEventBus, SecurityScanner, SecurityScannerOrchestrator, SelectiveCompactor, SessionAnalyzer, SessionError, SkillGenerator, SkillInstaller, SkillManifestStore, SlashCommandRegistry, SpecDrivenDev, SpecParser, SpecStore, SpecVersioning, SubagentBudget, TOKENS, TaskFlow, TaskGenerator, TaskGraphStore, TaskTracker, TechStackDetector, ToolError, ToolExecutor, ToolRegistry, WrongStackError, addPlanItem, allServers, analyzeCriticalPath, appendJournal, applyRosterBudget, asBlocks, asText, atomicWrite, attachPlanCheckpoint, attachTodosCheckpoint, awsServer, blockServer, braveSearchServer, buildChildEnv, buildGoalPreamble, buildOtlpMetricsRequest, buildOtlpTracesRequest, buildRecoveryStrategies, classifyFamily, clearPlan, color, compileGlob, compileUserRegex, composeDirectorPrompt, composeSubagentPrompt, computeTaskProgress, context7Server, contextManagerTool, createAutoExecutor, createContextManagerTool, createDefaultPipelines, createDelegateTool, createMcpControlTool, createMessage, createSecuritySlashCommand, createToolOutputSerializer, decryptConfigSecrets, defaultGitignoreUpdater, defaultOrchestrator, defaultReportGenerator, defaultSecurityScanner, defaultSkillGenerator, defaultTechStackDetector, deriveTodosFromPlanItem, detectNewlineStyle, downloadGitHubTarball, emptyGoal, emptyPlan, encryptConfigSecrets, ensureDir, estimateRequestTokens, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, everArtServer, extractRunEnv, filesystemServer, findCriticalPath, formatContextWindowModeList, formatGoal, formatPlan, formatPlanTemplates, formatTodosList, getContextWindowMode, getPlanTemplate, getTemplate, githubServer, goalFilePath, googleMapsServer, isAgentError, isConfigError, isContextWindowModeId, isImageBlock, isPluginError, isSessionError, isTextBlock, isThinkingBlock, isToolError, isToolResultBlock, isToolUseBlock, isWrongStackError, listContextWindowModes, listPlanTemplates, listTemplates, loadDirectorState, loadGoal, loadPlan, loadPlugins, loadProjectModes, loadTodosCheckpoint, loadUserModes, makeAgentSubagentRunner, makeAutonomyPromptContributor, makeContinueToNextIterationTool, makeDirectorSessionFactory, matchAny, matchGlob, migratePlaintextSecrets, miniMaxVisionServer, normalizeToLf, parseContinueDirective, parseSkillRef, projectHash, removePlanItem, renderProgress, renderPrometheus, renderSpecAnalysis, renderTaskGraph, renderTaskList, repairToolUseAdjacency, resolveContextWindowPolicy, resolveWstackPaths, rewriteConfigEncrypted, rosterSummaryFromConfigs, runConfigMigrations, safeParse, safeStringify, sanitizeJsonString, saveGoal, savePlan, saveTodosCheckpoint, securitySlashCommand, sentinelServer, setPlanItemStatus, slackServer, startMetricsServer, startOtlpMetricsExporter, startOtlpTraceExporter, stripAnsi, summarizeUsage, templateToMarkdown, toStyle, toWrongStackError, topologicalSort, unifiedDiff, unloadPlugins, validateAgainstSchema, wireMetricsToEvents, wrapAsState, zaiVisionServer };
22617
+ export { AGENTS_BY_PHASE, AGENT_CATALOG, AISpecBuilder, ALL_AGENT_DEFINITIONS, ALL_FLEET_AGENTS, AUDIT_LOG_AGENT, Agent, AgentError, AutoApprovePermissionPolicy, AutoCompactionMiddleware, AutoExecutor, AutonomousRunner, BUG_HUNTER_AGENT, BudgetExceededError, CONTEXT_WINDOW_MODES, ConfigError, ConfigMigrationError, Container, Context, ConversationState, DEFAULT_CONFIG_MIGRATIONS, DEFAULT_CONTEXT_CONFIG, DEFAULT_CONTEXT_WINDOW_MODE_ID, DEFAULT_DIRECTOR_PREAMBLE, DEFAULT_DISPATCH_ROLE, DEFAULT_MAX_ITERATIONS, DEFAULT_MODES, DEFAULT_RECOVERY_STRATEGIES, DEFAULT_SPEC_TEMPLATE, DEFAULT_SUBAGENT_BASELINE, DEFAULT_TOOLS_CONFIG, DefaultAttachmentStore, DefaultConfigLoader, DefaultConfigStore, DefaultErrorHandler, DefaultHealthRegistry, DefaultLogger, DefaultMemoryStore, DefaultModeStore, DefaultModelsRegistry, DefaultMultiAgentCoordinator, DefaultPathResolver, DefaultPermissionPolicy, DefaultPluginAPI, DefaultProviderRunner, DefaultRetryPolicy, DefaultSecretScrubber, DefaultSecretVault, DefaultSessionReader, DefaultSessionRewinder, DefaultSessionStore, DefaultSkillLoader, DefaultSystemPromptBuilder, DefaultTaskStore, DefaultTokenCounter, Director, DirectorStateCheckpoint, DoneConditionChecker, ERROR_CODES, EternalAutonomyEngine, EventBus, ExtensionRegistry, FLEET_ROSTER, FLEET_ROSTER_BUDGETS, FleetBus, FleetManager, FleetSpawnBudgetError, FleetUsageAggregator, FsError, GitignoreUpdater, HybridCompactor, InMemoryAgentBridge, InMemoryBridgeTransport, InMemoryMetricsSink, InputBuilder, IntelligentCompactor, KERNEL_API_VERSION, LAYER_1_IDENTITY, LLMSelector, MAX_JOURNAL_ENTRIES, NULL_FLEET_BUS, NoopMetricsSink, NoopTracer, OTelTracer, PROMETHEUS_CONTENT_TYPE, ParallelEternalEngine, Pipeline, PluginError, ProviderError, ProviderRegistry, QueueStore, REFACTOR_PLANNER_AGENT, RecoveryLock, ReportGenerator, RunController, SECURITY_SCANNER_AGENT, SPEC_TEMPLATES, ScopedEventBus, SecurityScanner, SecurityScannerOrchestrator, SelectiveCompactor, SessionAnalyzer, SessionError, SkillGenerator, SkillInstaller, SkillManifestStore, SlashCommandRegistry, SpecDrivenDev, SpecParser, SpecStore, SpecVersioning, SubagentBudget, TOKENS, TaskFlow, TaskGenerator, TaskGraphStore, TaskTracker, TechStackDetector, ToolError, ToolExecutor, ToolRegistry, WrongStackError, addPlanItem, allServers, analyzeCriticalPath, appendJournal, applyRosterBudget, asBlocks, asText, atomicWrite, attachAutoExtend, attachPlanCheckpoint, attachTodosCheckpoint, awsServer, blockServer, braveSearchServer, buildChildEnv, buildGoalPreamble, buildOtlpMetricsRequest, buildOtlpTracesRequest, buildRecoveryStrategies, classifyFamily, clearPlan, color, compileGlob, compileUserRegex, composeDirectorPrompt, composeSubagentPrompt, computeTaskProgress, context7Server, contextManagerTool, createAutoExecutor, createContextManagerTool, createDefaultPipelines, createDelegateTool, createMcpControlTool, createMessage, createSecuritySlashCommand, createToolOutputSerializer, decryptConfigSecrets, defaultGitignoreUpdater, defaultOrchestrator, defaultReportGenerator, defaultSecurityScanner, defaultSkillGenerator, defaultTechStackDetector, deriveTodosFromPlanItem, detectNewlineStyle, dispatchAgent, downloadGitHubTarball, emptyGoal, emptyPlan, encryptConfigSecrets, ensureDir, estimateRequestTokens, estimateTextTokens, estimateToolDefTokens, estimateToolInputTokens, estimateToolResultTokens, everArtServer, extractRunEnv, filesystemServer, findCriticalPath, formatContextWindowModeList, formatGoal, formatPlan, formatPlanTemplates, formatTodosList, getAgentDefinition, getContextWindowMode, getPlanTemplate, getTemplate, githubServer, goalFilePath, googleMapsServer, isAgentError, isConfigError, isContextWindowModeId, isFsError, isImageBlock, isPluginError, isSessionError, isTextBlock, isThinkingBlock, isToolError, isToolResultBlock, isToolUseBlock, isWrongStackError, listContextWindowModes, listPlanTemplates, listTemplates, loadDirectorState, loadGoal, loadPlan, loadPlugins, loadProjectModes, loadTodosCheckpoint, loadUserModes, makeAgentSubagentRunner, makeAutonomyPromptContributor, makeContinueToNextIterationTool, makeDirectorSessionFactory, makeLLMClassifier, matchAny, matchGlob, migratePlaintextSecrets, miniMaxVisionServer, normalizeToLf, parseContinueDirective, parseSkillRef, projectHash, removePlanItem, renderProgress, renderPrometheus, renderSpecAnalysis, renderTaskGraph, renderTaskList, repairToolUseAdjacency, resolveContextWindowPolicy, resolveWstackPaths, rewriteConfigEncrypted, rosterSummaryFromConfigs, runConfigMigrations, safeParse, safeStringify, sanitizeJsonString, saveGoal, savePlan, saveTodosCheckpoint, scoreAgents, securitySlashCommand, sentinelServer, setPlanItemStatus, slackServer, startMetricsServer, startOtlpMetricsExporter, startOtlpTraceExporter, stripAnsi, summarizeUsage, templateToMarkdown, toStyle, toWrongStackError, topologicalSort, unifiedDiff, unloadPlugins, validateAgainstSchema, wireMetricsToEvents, wrapAsState, zaiVisionServer };
19892
22618
  //# sourceMappingURL=index.js.map
19893
22619
  //# sourceMappingURL=index.js.map