@calliopelabs/cli 0.8.20 → 2.0.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 (402) hide show
  1. package/dist/agents/agent-config-loader.d.ts +60 -0
  2. package/dist/agents/agent-config-loader.d.ts.map +1 -0
  3. package/dist/agents/agent-config-loader.js +402 -0
  4. package/dist/agents/agent-config-loader.js.map +1 -0
  5. package/dist/agents/agent-config-presets.d.ts +10 -0
  6. package/dist/agents/agent-config-presets.d.ts.map +1 -0
  7. package/dist/agents/agent-config-presets.js +940 -0
  8. package/dist/agents/agent-config-presets.js.map +1 -0
  9. package/dist/agents/agent-config-types.d.ts +145 -0
  10. package/dist/agents/agent-config-types.d.ts.map +1 -0
  11. package/dist/agents/agent-config-types.js +12 -0
  12. package/dist/agents/agent-config-types.js.map +1 -0
  13. package/dist/{agterm → agents}/agent-detection.d.ts +1 -1
  14. package/dist/{agterm → agents}/agent-detection.d.ts.map +1 -1
  15. package/dist/{agterm → agents}/agent-detection.js +21 -5
  16. package/dist/agents/agent-detection.js.map +1 -0
  17. package/dist/agents/aggregator.d.ts +19 -0
  18. package/dist/agents/aggregator.d.ts.map +1 -0
  19. package/dist/agents/aggregator.js +141 -0
  20. package/dist/agents/aggregator.js.map +1 -0
  21. package/dist/{agterm → agents}/cli-backend.d.ts +1 -1
  22. package/dist/{agterm → agents}/cli-backend.d.ts.map +1 -1
  23. package/dist/{agterm → agents}/cli-backend.js +90 -12
  24. package/dist/agents/cli-backend.js.map +1 -0
  25. package/dist/agents/council-types.d.ts +113 -0
  26. package/dist/agents/council-types.d.ts.map +1 -0
  27. package/dist/agents/council-types.js +81 -0
  28. package/dist/agents/council-types.js.map +1 -0
  29. package/dist/agents/council.d.ts +107 -0
  30. package/dist/agents/council.d.ts.map +1 -0
  31. package/dist/agents/council.js +586 -0
  32. package/dist/agents/council.js.map +1 -0
  33. package/dist/agents/decomposer.d.ts +33 -0
  34. package/dist/agents/decomposer.d.ts.map +1 -0
  35. package/dist/agents/decomposer.js +138 -0
  36. package/dist/agents/decomposer.js.map +1 -0
  37. package/dist/agents/dynamic-tools.d.ts +52 -0
  38. package/dist/agents/dynamic-tools.d.ts.map +1 -0
  39. package/dist/agents/dynamic-tools.js +395 -0
  40. package/dist/agents/dynamic-tools.js.map +1 -0
  41. package/dist/agents/index.d.ts +29 -0
  42. package/dist/agents/index.d.ts.map +1 -0
  43. package/dist/agents/index.js +29 -0
  44. package/dist/agents/index.js.map +1 -0
  45. package/dist/agents/installer.d.ts +39 -0
  46. package/dist/agents/installer.d.ts.map +1 -0
  47. package/dist/agents/installer.js +205 -0
  48. package/dist/agents/installer.js.map +1 -0
  49. package/dist/{agterm → agents}/orchestrator.d.ts +7 -2
  50. package/dist/agents/orchestrator.d.ts.map +1 -0
  51. package/dist/{agterm → agents}/orchestrator.js +22 -2
  52. package/dist/agents/orchestrator.js.map +1 -0
  53. package/dist/agents/sdk-backend.d.ts +63 -0
  54. package/dist/agents/sdk-backend.d.ts.map +1 -0
  55. package/dist/agents/sdk-backend.js +489 -0
  56. package/dist/agents/sdk-backend.js.map +1 -0
  57. package/dist/agents/swarm-types.d.ts +83 -0
  58. package/dist/agents/swarm-types.d.ts.map +1 -0
  59. package/dist/agents/swarm-types.js +20 -0
  60. package/dist/agents/swarm-types.js.map +1 -0
  61. package/dist/agents/swarm.d.ts +74 -0
  62. package/dist/agents/swarm.d.ts.map +1 -0
  63. package/dist/agents/swarm.js +307 -0
  64. package/dist/agents/swarm.js.map +1 -0
  65. package/dist/{agterm → agents}/tools.d.ts +7 -5
  66. package/dist/agents/tools.d.ts.map +1 -0
  67. package/dist/agents/tools.js +776 -0
  68. package/dist/agents/tools.js.map +1 -0
  69. package/dist/{agterm → agents}/types.d.ts +14 -2
  70. package/dist/agents/types.d.ts.map +1 -0
  71. package/dist/{agterm → agents}/types.js +2 -2
  72. package/dist/agents/types.js.map +1 -0
  73. package/dist/api-server.d.ts +26 -0
  74. package/dist/api-server.d.ts.map +1 -0
  75. package/dist/api-server.js +230 -0
  76. package/dist/api-server.js.map +1 -0
  77. package/dist/auto-checkpoint.d.ts +35 -0
  78. package/dist/auto-checkpoint.d.ts.map +1 -0
  79. package/dist/auto-checkpoint.js +143 -0
  80. package/dist/auto-checkpoint.js.map +1 -0
  81. package/dist/auto-compressor.d.ts +44 -0
  82. package/dist/auto-compressor.d.ts.map +1 -0
  83. package/dist/auto-compressor.js +145 -0
  84. package/dist/auto-compressor.js.map +1 -0
  85. package/dist/background-jobs.d.ts +45 -0
  86. package/dist/background-jobs.d.ts.map +1 -0
  87. package/dist/background-jobs.js +122 -0
  88. package/dist/background-jobs.js.map +1 -0
  89. package/dist/bin.d.ts +6 -2
  90. package/dist/bin.d.ts.map +1 -1
  91. package/dist/bin.js +127 -24
  92. package/dist/bin.js.map +1 -1
  93. package/dist/checkpoint.d.ts +49 -0
  94. package/dist/checkpoint.d.ts.map +1 -0
  95. package/dist/checkpoint.js +219 -0
  96. package/dist/checkpoint.js.map +1 -0
  97. package/dist/circuit-breaker/breaker.d.ts +80 -0
  98. package/dist/circuit-breaker/breaker.d.ts.map +1 -0
  99. package/dist/circuit-breaker/breaker.js +408 -0
  100. package/dist/circuit-breaker/breaker.js.map +1 -0
  101. package/dist/circuit-breaker/defaults.d.ts +8 -0
  102. package/dist/circuit-breaker/defaults.d.ts.map +1 -0
  103. package/dist/circuit-breaker/defaults.js +35 -0
  104. package/dist/circuit-breaker/defaults.js.map +1 -0
  105. package/dist/circuit-breaker/index.d.ts +9 -0
  106. package/dist/circuit-breaker/index.d.ts.map +1 -0
  107. package/dist/circuit-breaker/index.js +8 -0
  108. package/dist/circuit-breaker/index.js.map +1 -0
  109. package/dist/circuit-breaker/types.d.ts +77 -0
  110. package/dist/circuit-breaker/types.d.ts.map +1 -0
  111. package/dist/circuit-breaker/types.js +8 -0
  112. package/dist/circuit-breaker/types.js.map +1 -0
  113. package/dist/circuit-breaker.d.ts +8 -0
  114. package/dist/circuit-breaker.d.ts.map +1 -0
  115. package/dist/circuit-breaker.js +7 -0
  116. package/dist/circuit-breaker.js.map +1 -0
  117. package/dist/cli/agent.d.ts +9 -0
  118. package/dist/cli/agent.d.ts.map +1 -0
  119. package/dist/cli/agent.js +262 -0
  120. package/dist/cli/agent.js.map +1 -0
  121. package/dist/cli/commands.d.ts +12 -0
  122. package/dist/cli/commands.d.ts.map +1 -0
  123. package/dist/{cli.js → cli/commands.js} +285 -422
  124. package/dist/cli/commands.js.map +1 -0
  125. package/dist/cli/index.d.ts +8 -0
  126. package/dist/cli/index.d.ts.map +1 -0
  127. package/dist/cli/index.js +222 -0
  128. package/dist/cli/index.js.map +1 -0
  129. package/dist/cli/types.d.ts +30 -0
  130. package/dist/cli/types.d.ts.map +1 -0
  131. package/dist/cli/types.js +20 -0
  132. package/dist/cli/types.js.map +1 -0
  133. package/dist/companions.d.ts +54 -0
  134. package/dist/companions.d.ts.map +1 -0
  135. package/dist/companions.js +440 -0
  136. package/dist/companions.js.map +1 -0
  137. package/dist/config.d.ts +23 -1
  138. package/dist/config.d.ts.map +1 -1
  139. package/dist/config.js +95 -22
  140. package/dist/config.js.map +1 -1
  141. package/dist/diff.d.ts +27 -0
  142. package/dist/diff.d.ts.map +1 -1
  143. package/dist/diff.js +415 -10
  144. package/dist/diff.js.map +1 -1
  145. package/dist/errors.d.ts.map +1 -1
  146. package/dist/errors.js +20 -11
  147. package/dist/errors.js.map +1 -1
  148. package/dist/git-status.d.ts +23 -0
  149. package/dist/git-status.d.ts.map +1 -0
  150. package/dist/git-status.js +92 -0
  151. package/dist/git-status.js.map +1 -0
  152. package/dist/headless.d.ts +25 -0
  153. package/dist/headless.d.ts.map +1 -0
  154. package/dist/headless.js +182 -0
  155. package/dist/headless.js.map +1 -0
  156. package/dist/hud/api.d.ts +35 -0
  157. package/dist/hud/api.d.ts.map +1 -0
  158. package/dist/hud/api.js +448 -0
  159. package/dist/hud/api.js.map +1 -0
  160. package/dist/hud/palettes.d.ts +9 -0
  161. package/dist/hud/palettes.d.ts.map +1 -0
  162. package/dist/hud/palettes.js +280 -0
  163. package/dist/hud/palettes.js.map +1 -0
  164. package/dist/hud/skins.d.ts +12 -0
  165. package/dist/hud/skins.d.ts.map +1 -0
  166. package/dist/hud/skins.js +365 -0
  167. package/dist/hud/skins.js.map +1 -0
  168. package/dist/hud/theme-packs/api.d.ts +51 -0
  169. package/dist/hud/theme-packs/api.d.ts.map +1 -0
  170. package/dist/hud/theme-packs/api.js +145 -0
  171. package/dist/hud/theme-packs/api.js.map +1 -0
  172. package/dist/hud/theme-packs/index.d.ts +18 -0
  173. package/dist/hud/theme-packs/index.d.ts.map +1 -0
  174. package/dist/hud/theme-packs/index.js +38 -0
  175. package/dist/hud/theme-packs/index.js.map +1 -0
  176. package/dist/hud/theme-packs/types.d.ts +29 -0
  177. package/dist/hud/theme-packs/types.d.ts.map +1 -0
  178. package/dist/hud/theme-packs/types.js +9 -0
  179. package/dist/hud/theme-packs/types.js.map +1 -0
  180. package/dist/hud/types.d.ts +182 -0
  181. package/dist/hud/types.d.ts.map +1 -0
  182. package/dist/hud/types.js +7 -0
  183. package/dist/hud/types.js.map +1 -0
  184. package/dist/idle-eviction.d.ts +34 -0
  185. package/dist/idle-eviction.d.ts.map +1 -0
  186. package/dist/idle-eviction.js +78 -0
  187. package/dist/idle-eviction.js.map +1 -0
  188. package/dist/index.d.ts +9 -3
  189. package/dist/index.d.ts.map +1 -1
  190. package/dist/index.js +9 -3
  191. package/dist/index.js.map +1 -1
  192. package/dist/iteration-ledger.d.ts +105 -0
  193. package/dist/iteration-ledger.d.ts.map +1 -0
  194. package/dist/iteration-ledger.js +237 -0
  195. package/dist/iteration-ledger.js.map +1 -0
  196. package/dist/markdown.d.ts.map +1 -1
  197. package/dist/markdown.js +1 -27
  198. package/dist/markdown.js.map +1 -1
  199. package/dist/mcp.d.ts +35 -0
  200. package/dist/mcp.d.ts.map +1 -1
  201. package/dist/mcp.js +291 -7
  202. package/dist/mcp.js.map +1 -1
  203. package/dist/memory.d.ts.map +1 -1
  204. package/dist/memory.js +12 -2
  205. package/dist/memory.js.map +1 -1
  206. package/dist/model-detection.d.ts +5 -0
  207. package/dist/model-detection.d.ts.map +1 -1
  208. package/dist/model-detection.js +278 -10
  209. package/dist/model-detection.js.map +1 -1
  210. package/dist/model-router.d.ts.map +1 -1
  211. package/dist/model-router.js +33 -11
  212. package/dist/model-router.js.map +1 -1
  213. package/dist/plugins.d.ts +8 -0
  214. package/dist/plugins.d.ts.map +1 -1
  215. package/dist/plugins.js +97 -6
  216. package/dist/plugins.js.map +1 -1
  217. package/dist/providers/anthropic.d.ts +10 -0
  218. package/dist/providers/anthropic.d.ts.map +1 -0
  219. package/dist/providers/anthropic.js +221 -0
  220. package/dist/providers/anthropic.js.map +1 -0
  221. package/dist/providers/bedrock.d.ts +17 -0
  222. package/dist/providers/bedrock.d.ts.map +1 -0
  223. package/dist/providers/bedrock.js +574 -0
  224. package/dist/providers/bedrock.js.map +1 -0
  225. package/dist/providers/compat.d.ts +13 -0
  226. package/dist/providers/compat.d.ts.map +1 -0
  227. package/dist/providers/compat.js +202 -0
  228. package/dist/providers/compat.js.map +1 -0
  229. package/dist/providers/google.d.ts +10 -0
  230. package/dist/providers/google.d.ts.map +1 -0
  231. package/dist/providers/google.js +203 -0
  232. package/dist/providers/google.js.map +1 -0
  233. package/dist/providers/index.d.ts +23 -0
  234. package/dist/providers/index.d.ts.map +1 -0
  235. package/dist/providers/index.js +145 -0
  236. package/dist/providers/index.js.map +1 -0
  237. package/dist/providers/ollama.d.ts +17 -0
  238. package/dist/providers/ollama.d.ts.map +1 -0
  239. package/dist/providers/ollama.js +289 -0
  240. package/dist/providers/ollama.js.map +1 -0
  241. package/dist/providers/openai.d.ts +121 -0
  242. package/dist/providers/openai.d.ts.map +1 -0
  243. package/dist/providers/openai.js +485 -0
  244. package/dist/providers/openai.js.map +1 -0
  245. package/dist/providers/types.d.ts +63 -0
  246. package/dist/providers/types.d.ts.map +1 -0
  247. package/dist/providers/types.js +164 -0
  248. package/dist/providers/types.js.map +1 -0
  249. package/dist/sandbox-native.d.ts +59 -0
  250. package/dist/sandbox-native.d.ts.map +1 -0
  251. package/dist/sandbox-native.js +292 -0
  252. package/dist/sandbox-native.js.map +1 -0
  253. package/dist/sandbox.d.ts +2 -2
  254. package/dist/sandbox.d.ts.map +1 -1
  255. package/dist/sandbox.js +59 -13
  256. package/dist/sandbox.js.map +1 -1
  257. package/dist/scope.d.ts +3 -1
  258. package/dist/scope.d.ts.map +1 -1
  259. package/dist/scope.js +13 -1
  260. package/dist/scope.js.map +1 -1
  261. package/dist/session-timeout.d.ts +31 -0
  262. package/dist/session-timeout.d.ts.map +1 -0
  263. package/dist/session-timeout.js +100 -0
  264. package/dist/session-timeout.js.map +1 -0
  265. package/dist/setup.d.ts.map +1 -1
  266. package/dist/setup.js +29 -17
  267. package/dist/setup.js.map +1 -1
  268. package/dist/smart-router.d.ts +73 -0
  269. package/dist/smart-router.d.ts.map +1 -0
  270. package/dist/smart-router.js +332 -0
  271. package/dist/smart-router.js.map +1 -0
  272. package/dist/storage.d.ts +19 -0
  273. package/dist/storage.d.ts.map +1 -1
  274. package/dist/storage.js +164 -1
  275. package/dist/storage.js.map +1 -1
  276. package/dist/streaming.d.ts +4 -0
  277. package/dist/streaming.d.ts.map +1 -1
  278. package/dist/streaming.js +12 -0
  279. package/dist/streaming.js.map +1 -1
  280. package/dist/styles.d.ts +32 -0
  281. package/dist/styles.d.ts.map +1 -1
  282. package/dist/styles.js +91 -0
  283. package/dist/styles.js.map +1 -1
  284. package/dist/summarization.d.ts +1 -1
  285. package/dist/summarization.js +4 -4
  286. package/dist/summarization.js.map +1 -1
  287. package/dist/terminal-image.d.ts +115 -0
  288. package/dist/terminal-image.d.ts.map +1 -0
  289. package/dist/terminal-image.js +766 -0
  290. package/dist/terminal-image.js.map +1 -0
  291. package/dist/terminal-recording.d.ts +55 -0
  292. package/dist/terminal-recording.d.ts.map +1 -0
  293. package/dist/terminal-recording.js +182 -0
  294. package/dist/terminal-recording.js.map +1 -0
  295. package/dist/themes.d.ts +19 -35
  296. package/dist/themes.d.ts.map +1 -1
  297. package/dist/themes.js +101 -210
  298. package/dist/themes.js.map +1 -1
  299. package/dist/tmux.d.ts +35 -0
  300. package/dist/tmux.d.ts.map +1 -0
  301. package/dist/tmux.js +106 -0
  302. package/dist/tmux.js.map +1 -0
  303. package/dist/tools.d.ts +3 -3
  304. package/dist/tools.d.ts.map +1 -1
  305. package/dist/tools.js +587 -45
  306. package/dist/tools.js.map +1 -1
  307. package/dist/trust.d.ts +53 -0
  308. package/dist/trust.d.ts.map +1 -0
  309. package/dist/trust.js +154 -0
  310. package/dist/trust.js.map +1 -0
  311. package/dist/types.d.ts +7 -3
  312. package/dist/types.d.ts.map +1 -1
  313. package/dist/types.js +70 -32
  314. package/dist/types.js.map +1 -1
  315. package/dist/ui/agent.d.ts +61 -0
  316. package/dist/ui/agent.d.ts.map +1 -0
  317. package/dist/ui/agent.js +768 -0
  318. package/dist/ui/agent.js.map +1 -0
  319. package/dist/ui/chat-input.d.ts +32 -0
  320. package/dist/ui/chat-input.d.ts.map +1 -0
  321. package/dist/ui/chat-input.js +355 -0
  322. package/dist/ui/chat-input.js.map +1 -0
  323. package/dist/ui/commands.d.ts +92 -0
  324. package/dist/ui/commands.d.ts.map +1 -0
  325. package/dist/ui/commands.js +3006 -0
  326. package/dist/ui/commands.js.map +1 -0
  327. package/dist/ui/completions.d.ts +22 -0
  328. package/dist/ui/completions.d.ts.map +1 -0
  329. package/dist/ui/completions.js +215 -0
  330. package/dist/ui/completions.js.map +1 -0
  331. package/dist/ui/components.d.ts +38 -0
  332. package/dist/ui/components.d.ts.map +1 -0
  333. package/dist/ui/components.js +422 -0
  334. package/dist/ui/components.js.map +1 -0
  335. package/dist/ui/context.d.ts +12 -0
  336. package/dist/ui/context.d.ts.map +1 -0
  337. package/dist/ui/context.js +102 -0
  338. package/dist/ui/context.js.map +1 -0
  339. package/dist/ui/error-boundary.d.ts +33 -0
  340. package/dist/ui/error-boundary.d.ts.map +1 -0
  341. package/dist/ui/error-boundary.js +94 -0
  342. package/dist/ui/error-boundary.js.map +1 -0
  343. package/dist/ui/frame.d.ts +13 -0
  344. package/dist/ui/frame.d.ts.map +1 -0
  345. package/dist/ui/frame.js +89 -0
  346. package/dist/ui/frame.js.map +1 -0
  347. package/dist/ui/index.d.ts +12 -0
  348. package/dist/ui/index.d.ts.map +1 -0
  349. package/dist/ui/index.js +928 -0
  350. package/dist/ui/index.js.map +1 -0
  351. package/dist/ui/messages.d.ts +19 -0
  352. package/dist/ui/messages.d.ts.map +1 -0
  353. package/dist/ui/messages.js +181 -0
  354. package/dist/ui/messages.js.map +1 -0
  355. package/dist/ui/modals.d.ts +52 -0
  356. package/dist/ui/modals.d.ts.map +1 -0
  357. package/dist/ui/modals.js +204 -0
  358. package/dist/ui/modals.js.map +1 -0
  359. package/dist/ui/pack-picker.d.ts +12 -0
  360. package/dist/ui/pack-picker.d.ts.map +1 -0
  361. package/dist/ui/pack-picker.js +101 -0
  362. package/dist/ui/pack-picker.js.map +1 -0
  363. package/dist/ui/status-bar.d.ts +20 -0
  364. package/dist/ui/status-bar.d.ts.map +1 -0
  365. package/dist/ui/status-bar.js +41 -0
  366. package/dist/ui/status-bar.js.map +1 -0
  367. package/dist/ui/theme-picker.d.ts +24 -0
  368. package/dist/ui/theme-picker.d.ts.map +1 -0
  369. package/dist/ui/theme-picker.js +190 -0
  370. package/dist/ui/theme-picker.js.map +1 -0
  371. package/dist/ui/types.d.ts +62 -0
  372. package/dist/ui/types.d.ts.map +1 -0
  373. package/dist/ui/types.js +7 -0
  374. package/dist/ui/types.js.map +1 -0
  375. package/dist/version-check.d.ts.map +1 -1
  376. package/dist/version-check.js +1 -9
  377. package/dist/version-check.js.map +1 -1
  378. package/package.json +8 -3
  379. package/dist/agterm/agent-detection.js.map +0 -1
  380. package/dist/agterm/cli-backend.js.map +0 -1
  381. package/dist/agterm/index.d.ts +0 -12
  382. package/dist/agterm/index.d.ts.map +0 -1
  383. package/dist/agterm/index.js +0 -15
  384. package/dist/agterm/index.js.map +0 -1
  385. package/dist/agterm/orchestrator.d.ts.map +0 -1
  386. package/dist/agterm/orchestrator.js.map +0 -1
  387. package/dist/agterm/tools.d.ts.map +0 -1
  388. package/dist/agterm/tools.js +0 -278
  389. package/dist/agterm/tools.js.map +0 -1
  390. package/dist/agterm/types.d.ts.map +0 -1
  391. package/dist/agterm/types.js.map +0 -1
  392. package/dist/cli.d.ts +0 -14
  393. package/dist/cli.d.ts.map +0 -1
  394. package/dist/cli.js.map +0 -1
  395. package/dist/providers.d.ts +0 -51
  396. package/dist/providers.d.ts.map +0 -1
  397. package/dist/providers.js +0 -1146
  398. package/dist/providers.js.map +0 -1
  399. package/dist/ui-cli.d.ts +0 -17
  400. package/dist/ui-cli.d.ts.map +0 -1
  401. package/dist/ui-cli.js +0 -3730
  402. package/dist/ui-cli.js.map +0 -1
@@ -0,0 +1,408 @@
1
+ /**
2
+ * Circuit Breaker
3
+ *
4
+ * Framework-agnostic circuit breaker that monitors agent loop iterations
5
+ * and trips on bad behavior patterns. State machine: closed → open → half-open.
6
+ *
7
+ * When tripped (open), the agent loop should pause and notify the user.
8
+ * User can resume (half-open) which runs at reduced thresholds (50%).
9
+ */
10
+ import { DEFAULT_CIRCUIT_BREAKER_CONFIG } from './defaults.js';
11
+ // ============================================================================
12
+ // Tool Call Fingerprinting
13
+ // ============================================================================
14
+ function fingerprint(toolCall) {
15
+ const sortedArgs = Object.keys(toolCall.arguments)
16
+ .sort()
17
+ .map(k => `${k}=${JSON.stringify(toolCall.arguments[k])}`)
18
+ .join('&');
19
+ return `${toolCall.name}:${sortedArgs}`;
20
+ }
21
+ // ============================================================================
22
+ // CircuitBreaker Class
23
+ // ============================================================================
24
+ export class CircuitBreaker {
25
+ config;
26
+ // Per-breaker state
27
+ states = new Map();
28
+ tripCounts = new Map();
29
+ lastTripped = new Map();
30
+ lastEvents = new Map();
31
+ // Tracking data
32
+ consecutiveErrors = 0;
33
+ totalTokens = 0;
34
+ totalCost = 0;
35
+ idleCount = 0;
36
+ costWindow = [];
37
+ toolCallHistory = []; // fingerprints
38
+ startTime;
39
+ lastIterationStart = 0;
40
+ constructor(config) {
41
+ // Deep clone defaults to avoid shared state between instances
42
+ this.config = {
43
+ ...DEFAULT_CIRCUIT_BREAKER_CONFIG,
44
+ ...config,
45
+ breakers: {
46
+ 'repeated-failure': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['repeated-failure'] },
47
+ 'cost-runaway': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['cost-runaway'] },
48
+ 'infinite-loop': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['infinite-loop'] },
49
+ 'token-burn': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['token-burn'] },
50
+ 'stall': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['stall'] },
51
+ 'wall-clock': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['wall-clock'] },
52
+ ...(config?.breakers ? {
53
+ ...(config.breakers['repeated-failure'] ? { 'repeated-failure': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['repeated-failure'], ...config.breakers['repeated-failure'] } } : {}),
54
+ ...(config.breakers['cost-runaway'] ? { 'cost-runaway': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['cost-runaway'], ...config.breakers['cost-runaway'] } } : {}),
55
+ ...(config.breakers['infinite-loop'] ? { 'infinite-loop': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['infinite-loop'], ...config.breakers['infinite-loop'] } } : {}),
56
+ ...(config.breakers['token-burn'] ? { 'token-burn': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['token-burn'], ...config.breakers['token-burn'] } } : {}),
57
+ ...(config.breakers['stall'] ? { 'stall': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['stall'], ...config.breakers['stall'] } } : {}),
58
+ ...(config.breakers['wall-clock'] ? { 'wall-clock': { ...DEFAULT_CIRCUIT_BREAKER_CONFIG.breakers['wall-clock'], ...config.breakers['wall-clock'] } } : {}),
59
+ } : {}),
60
+ },
61
+ };
62
+ this.startTime = Date.now();
63
+ // Initialize all breakers to closed
64
+ const types = ['repeated-failure', 'cost-runaway', 'infinite-loop', 'token-burn', 'stall', 'wall-clock'];
65
+ for (const type of types) {
66
+ this.states.set(type, 'closed');
67
+ this.tripCounts.set(type, 0);
68
+ }
69
+ }
70
+ // ============================================================================
71
+ // Public API
72
+ // ============================================================================
73
+ /**
74
+ * Check all breakers against iteration data. Returns the first trip found.
75
+ */
76
+ check(data) {
77
+ if (!this.config.enabled) {
78
+ return { tripped: false };
79
+ }
80
+ // Update tracking state
81
+ this.updateTracking(data);
82
+ // Check each breaker (skip if already open)
83
+ const checks = [
84
+ () => this.checkRepeatedFailure(data),
85
+ () => this.checkCostRunaway(data),
86
+ () => this.checkInfiniteLoop(data),
87
+ () => this.checkTokenBurn(data),
88
+ () => this.checkStall(data),
89
+ () => this.checkWallClock(data),
90
+ ];
91
+ for (const check of checks) {
92
+ const result = check();
93
+ if (result.tripped) {
94
+ return result;
95
+ }
96
+ }
97
+ return { tripped: false };
98
+ }
99
+ /**
100
+ * Resume a tripped breaker (moves to half-open state with 50% thresholds).
101
+ */
102
+ resume(type) {
103
+ if (type) {
104
+ if (this.states.get(type) === 'open') {
105
+ this.states.set(type, 'half-open');
106
+ }
107
+ }
108
+ else {
109
+ // Resume all open breakers
110
+ for (const [t, state] of this.states) {
111
+ if (state === 'open') {
112
+ this.states.set(t, 'half-open');
113
+ }
114
+ }
115
+ }
116
+ }
117
+ /**
118
+ * Reset a specific breaker or all breakers to closed.
119
+ */
120
+ reset(type) {
121
+ if (type) {
122
+ this.states.set(type, 'closed');
123
+ this.resetTrackingForBreaker(type);
124
+ }
125
+ else {
126
+ for (const t of this.states.keys()) {
127
+ this.states.set(t, 'closed');
128
+ }
129
+ this.resetAllTracking();
130
+ }
131
+ }
132
+ /**
133
+ * Update thresholds for a specific breaker at runtime.
134
+ */
135
+ adjust(type, thresholds) {
136
+ const current = this.config.breakers[type];
137
+ this.config.breakers[type] = { ...current, ...thresholds };
138
+ }
139
+ /**
140
+ * Get status of all breakers.
141
+ */
142
+ getStatus() {
143
+ const types = ['repeated-failure', 'cost-runaway', 'infinite-loop', 'token-burn', 'stall', 'wall-clock'];
144
+ return types.map(type => ({
145
+ type,
146
+ state: this.states.get(type) || 'closed',
147
+ tripCount: this.tripCounts.get(type) || 0,
148
+ lastTripped: this.lastTripped.get(type),
149
+ lastEvent: this.lastEvents.get(type),
150
+ }));
151
+ }
152
+ /**
153
+ * Get overall health: 'ok' | 'warning' | 'tripped'
154
+ */
155
+ getHealth() {
156
+ let hasHalfOpen = false;
157
+ for (const state of this.states.values()) {
158
+ if (state === 'open')
159
+ return 'tripped';
160
+ if (state === 'half-open')
161
+ hasHalfOpen = true;
162
+ }
163
+ return hasHalfOpen ? 'warning' : 'ok';
164
+ }
165
+ /**
166
+ * Check if any breaker is currently tripped (open state).
167
+ */
168
+ isTripped() {
169
+ for (const state of this.states.values()) {
170
+ if (state === 'open')
171
+ return true;
172
+ }
173
+ return false;
174
+ }
175
+ /**
176
+ * Get the current config.
177
+ */
178
+ getConfig() {
179
+ return { ...this.config };
180
+ }
181
+ /**
182
+ * Get tracking stats for display.
183
+ */
184
+ getTrackingStats() {
185
+ return {
186
+ consecutiveErrors: this.consecutiveErrors,
187
+ totalTokens: this.totalTokens,
188
+ totalCost: this.totalCost,
189
+ idleCount: this.idleCount,
190
+ recentToolCalls: this.toolCallHistory.length,
191
+ };
192
+ }
193
+ // ============================================================================
194
+ // Tracking Updates
195
+ // ============================================================================
196
+ updateTracking(data) {
197
+ const now = data.timestamp?.getTime() ?? Date.now();
198
+ // Consecutive errors
199
+ if (data.error) {
200
+ this.consecutiveErrors++;
201
+ }
202
+ else {
203
+ this.consecutiveErrors = 0;
204
+ }
205
+ // Token tracking
206
+ const iterationTokens = (data.inputTokens || 0) + (data.outputTokens || 0);
207
+ this.totalTokens += iterationTokens;
208
+ // Cost tracking
209
+ if (data.cost && data.cost > 0) {
210
+ this.totalCost += data.cost;
211
+ this.costWindow.push({ cost: data.cost, timestamp: now });
212
+ // Prune old entries outside window
213
+ const windowMs = this.config.breakers['cost-runaway'].windowSizeMs;
214
+ this.costWindow = this.costWindow.filter(e => now - e.timestamp < windowMs);
215
+ }
216
+ // Tool call fingerprinting
217
+ if (data.toolCalls && data.toolCalls.length > 0) {
218
+ for (const tc of data.toolCalls) {
219
+ this.toolCallHistory.push(fingerprint(tc));
220
+ }
221
+ // Keep only recent history
222
+ const maxHistory = this.config.breakers['infinite-loop'].windowSize * 2;
223
+ if (this.toolCallHistory.length > maxHistory) {
224
+ this.toolCallHistory = this.toolCallHistory.slice(-maxHistory);
225
+ }
226
+ this.idleCount = 0; // Tool calls = not idle
227
+ }
228
+ else if (data.content && data.content.trim().length > 0) {
229
+ this.idleCount = 0; // Content = not idle
230
+ }
231
+ else if (!data.error) {
232
+ this.idleCount++;
233
+ }
234
+ }
235
+ resetTrackingForBreaker(type) {
236
+ switch (type) {
237
+ case 'repeated-failure':
238
+ this.consecutiveErrors = 0;
239
+ break;
240
+ case 'cost-runaway':
241
+ this.costWindow = [];
242
+ break;
243
+ case 'infinite-loop':
244
+ this.toolCallHistory = [];
245
+ break;
246
+ case 'token-burn':
247
+ this.totalTokens = 0;
248
+ break;
249
+ case 'stall':
250
+ this.idleCount = 0;
251
+ break;
252
+ case 'wall-clock':
253
+ this.lastIterationStart = 0;
254
+ break;
255
+ }
256
+ }
257
+ resetAllTracking() {
258
+ this.consecutiveErrors = 0;
259
+ this.totalTokens = 0;
260
+ this.totalCost = 0;
261
+ this.idleCount = 0;
262
+ this.costWindow = [];
263
+ this.toolCallHistory = [];
264
+ this.startTime = Date.now();
265
+ this.lastIterationStart = 0;
266
+ }
267
+ // ============================================================================
268
+ // Individual Breaker Checks
269
+ // ============================================================================
270
+ trip(type, message, data) {
271
+ this.states.set(type, 'open');
272
+ this.tripCounts.set(type, (this.tripCounts.get(type) || 0) + 1);
273
+ this.lastTripped.set(type, new Date());
274
+ const event = { type, timestamp: new Date(), message, data };
275
+ this.lastEvents.set(type, event);
276
+ return { tripped: true, breaker: type, message, data };
277
+ }
278
+ getThresholdMultiplier(type) {
279
+ // Half-open state uses 50% more generous thresholds
280
+ return this.states.get(type) === 'half-open' ? 1.5 : 1.0;
281
+ }
282
+ checkRepeatedFailure(_data) {
283
+ const type = 'repeated-failure';
284
+ if (this.states.get(type) === 'open')
285
+ return { tripped: false };
286
+ const thresholds = this.config.breakers[type];
287
+ const limit = Math.ceil(thresholds.maxConsecutiveErrors * this.getThresholdMultiplier(type));
288
+ if (this.consecutiveErrors >= limit) {
289
+ return this.trip(type, `${this.consecutiveErrors} consecutive errors detected. The agent may be stuck in an error loop.`, { consecutiveErrors: this.consecutiveErrors, limit });
290
+ }
291
+ return { tripped: false };
292
+ }
293
+ checkCostRunaway(_data) {
294
+ const type = 'cost-runaway';
295
+ if (this.states.get(type) === 'open')
296
+ return { tripped: false };
297
+ const thresholds = this.config.breakers[type];
298
+ const multiplier = this.getThresholdMultiplier(type);
299
+ // Check session ceiling
300
+ const sessionLimit = thresholds.maxSessionCost * multiplier;
301
+ if (this.totalCost >= sessionLimit) {
302
+ return this.trip(type, `Session cost $${this.totalCost.toFixed(2)} exceeded limit of $${sessionLimit.toFixed(2)}.`, { totalCost: this.totalCost, limit: sessionLimit });
303
+ }
304
+ // Check spend rate (sliding window)
305
+ if (this.costWindow.length > 0) {
306
+ const windowCost = this.costWindow.reduce((sum, e) => sum + e.cost, 0);
307
+ const rateLimit = thresholds.maxCostPerMinute * multiplier;
308
+ if (windowCost >= rateLimit) {
309
+ return this.trip(type, `Spend rate $${windowCost.toFixed(2)}/min exceeded limit of $${rateLimit.toFixed(2)}/min.`, { windowCost, rateLimit });
310
+ }
311
+ }
312
+ return { tripped: false };
313
+ }
314
+ checkInfiniteLoop(_data) {
315
+ const type = 'infinite-loop';
316
+ if (this.states.get(type) === 'open')
317
+ return { tripped: false };
318
+ const thresholds = this.config.breakers[type];
319
+ const multiplier = this.getThresholdMultiplier(type);
320
+ const history = this.toolCallHistory;
321
+ if (history.length < 2)
322
+ return { tripped: false };
323
+ // Check for identical tool calls in window
324
+ const window = history.slice(-thresholds.windowSize);
325
+ const fingerCounts = new Map();
326
+ for (const fp of window) {
327
+ fingerCounts.set(fp, (fingerCounts.get(fp) || 0) + 1);
328
+ }
329
+ const identicalLimit = Math.ceil(thresholds.maxIdenticalInWindow * multiplier);
330
+ for (const [fp, count] of fingerCounts) {
331
+ if (count >= identicalLimit) {
332
+ const toolName = fp.split(':')[0];
333
+ return this.trip(type, `Tool "${toolName}" called ${count} times with identical arguments in last ${thresholds.windowSize} calls.`, { fingerprint: fp, count, limit: identicalLimit });
334
+ }
335
+ }
336
+ // Check for A-B-A-B oscillation pattern
337
+ if (thresholds.detectOscillation && history.length >= 4) {
338
+ const recent = history.slice(-4);
339
+ if (recent[0] === recent[2] && recent[1] === recent[3] && recent[0] !== recent[1]) {
340
+ const toolA = recent[0].split(':')[0];
341
+ const toolB = recent[1].split(':')[0];
342
+ return this.trip(type, `Oscillation detected: "${toolA}" and "${toolB}" alternating repeatedly.`, { pattern: 'A-B-A-B', toolA, toolB });
343
+ }
344
+ }
345
+ return { tripped: false };
346
+ }
347
+ checkTokenBurn(data) {
348
+ const type = 'token-burn';
349
+ if (this.states.get(type) === 'open')
350
+ return { tripped: false };
351
+ const thresholds = this.config.breakers[type];
352
+ const multiplier = this.getThresholdMultiplier(type);
353
+ // Check per-iteration token usage
354
+ const iterationTokens = (data.inputTokens || 0) + (data.outputTokens || 0);
355
+ const iterLimit = Math.ceil(thresholds.maxTokensPerIteration * multiplier);
356
+ if (iterationTokens > iterLimit) {
357
+ return this.trip(type, `Iteration used ${iterationTokens.toLocaleString()} tokens, exceeding limit of ${iterLimit.toLocaleString()}.`, { iterationTokens, limit: iterLimit });
358
+ }
359
+ // Check cumulative token usage
360
+ const totalLimit = Math.ceil(thresholds.maxTotalTokens * multiplier);
361
+ if (this.totalTokens > totalLimit) {
362
+ return this.trip(type, `Total token usage ${this.totalTokens.toLocaleString()} exceeded limit of ${totalLimit.toLocaleString()}.`, { totalTokens: this.totalTokens, limit: totalLimit });
363
+ }
364
+ return { tripped: false };
365
+ }
366
+ checkStall(_data) {
367
+ const type = 'stall';
368
+ if (this.states.get(type) === 'open')
369
+ return { tripped: false };
370
+ const thresholds = this.config.breakers[type];
371
+ const limit = Math.ceil(thresholds.maxIdleIterations * this.getThresholdMultiplier(type));
372
+ if (this.idleCount >= limit) {
373
+ return this.trip(type, `Agent idle for ${this.idleCount} iterations (no tool calls or meaningful content).`, { idleCount: this.idleCount, limit });
374
+ }
375
+ return { tripped: false };
376
+ }
377
+ checkWallClock(_data) {
378
+ const type = 'wall-clock';
379
+ if (this.states.get(type) === 'open')
380
+ return { tripped: false };
381
+ const thresholds = this.config.breakers[type];
382
+ const multiplier = this.getThresholdMultiplier(type);
383
+ const now = Date.now();
384
+ // Check session duration (0 = no cap)
385
+ if (thresholds.maxSessionDurationMs > 0) {
386
+ const sessionDuration = now - this.startTime;
387
+ const sessionLimit = Math.ceil(thresholds.maxSessionDurationMs * multiplier);
388
+ if (sessionDuration >= sessionLimit) {
389
+ const minutes = Math.round(sessionDuration / 60_000);
390
+ const limitMinutes = Math.round(sessionLimit / 60_000);
391
+ return this.trip(type, `Session running for ${minutes} minutes, exceeded limit of ${limitMinutes} minutes.`, { sessionDurationMs: sessionDuration, limitMs: sessionLimit });
392
+ }
393
+ }
394
+ // Check iteration duration (using timestamp from iteration data vs last check)
395
+ if (this.lastIterationStart > 0) {
396
+ const iterDuration = now - this.lastIterationStart;
397
+ const iterLimit = Math.ceil(thresholds.maxIterationDurationMs * multiplier);
398
+ if (iterDuration >= iterLimit) {
399
+ const seconds = Math.round(iterDuration / 1000);
400
+ const limitSeconds = Math.round(iterLimit / 1000);
401
+ return this.trip(type, `Single iteration took ${seconds}s, exceeded limit of ${limitSeconds}s.`, { iterationDurationMs: iterDuration, limitMs: iterLimit });
402
+ }
403
+ }
404
+ this.lastIterationStart = now;
405
+ return { tripped: false };
406
+ }
407
+ }
408
+ //# sourceMappingURL=breaker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breaker.js","sourceRoot":"","sources":["../../src/circuit-breaker/breaker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAWH,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAE/D,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E,SAAS,WAAW,CAAC,QAA8D;IACjF,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;SAC/C,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SACzD,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,QAAQ,CAAC,IAAI,IAAI,UAAU,EAAE,CAAC;AAC1C,CAAC;AAED,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E,MAAM,OAAO,cAAc;IACjB,MAAM,CAAuB;IAErC,oBAAoB;IACZ,MAAM,GAAmC,IAAI,GAAG,EAAE,CAAC;IACnD,UAAU,GAA6B,IAAI,GAAG,EAAE,CAAC;IACjD,WAAW,GAA2B,IAAI,GAAG,EAAE,CAAC;IAChD,UAAU,GAAmC,IAAI,GAAG,EAAE,CAAC;IAE/D,gBAAgB;IACR,iBAAiB,GAAG,CAAC,CAAC;IACtB,WAAW,GAAG,CAAC,CAAC;IAChB,SAAS,GAAG,CAAC,CAAC;IACd,SAAS,GAAG,CAAC,CAAC;IACd,UAAU,GAA+C,EAAE,CAAC;IAC5D,eAAe,G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AAC;YAC5E,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;gBAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;gBAChD,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;gBAClD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EACnB,yBAAyB,OAAO,wBAAwB,YAAY,IAAI,EACxE,EAAE,mBAAmB,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,CAC1D,CAAC;YACJ,CAAC;QACH,CAAC;QACD,IAAI,CAAC,kBAAkB,GAAG,GAAG,CAAC;QAE9B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Circuit Breaker Defaults
3
+ *
4
+ * Default threshold configurations for all 5 breakers.
5
+ */
6
+ import type { CircuitBreakerConfig } from './types.js';
7
+ export declare const DEFAULT_CIRCUIT_BREAKER_CONFIG: CircuitBreakerConfig;
8
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/circuit-breaker/defaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,eAAO,MAAM,8BAA8B,EAAE,oBA4B5C,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Circuit Breaker Defaults
3
+ *
4
+ * Default threshold configurations for all 5 breakers.
5
+ */
6
+ export const DEFAULT_CIRCUIT_BREAKER_CONFIG = {
7
+ enabled: true,
8
+ breakers: {
9
+ 'repeated-failure': {
10
+ maxConsecutiveErrors: 3,
11
+ },
12
+ 'cost-runaway': {
13
+ maxSessionCost: 5.0, // $5 per session
14
+ maxCostPerMinute: 1.0, // $1/min sustained spend rate
15
+ windowSizeMs: 60_000, // 1 minute sliding window
16
+ },
17
+ 'infinite-loop': {
18
+ maxIdenticalInWindow: 3, // 3 identical tool calls in window
19
+ windowSize: 6, // Check last 6 tool calls
20
+ detectOscillation: true, // Detect A-B-A-B patterns
21
+ },
22
+ 'token-burn': {
23
+ maxTokensPerIteration: 200_000,
24
+ maxTotalTokens: 5_000_000,
25
+ },
26
+ 'stall': {
27
+ maxIdleIterations: 5,
28
+ },
29
+ 'wall-clock': {
30
+ maxSessionDurationMs: 0, // 0 = no session cap
31
+ maxIterationDurationMs: 10 * 60 * 1000, // 10 minutes per iteration
32
+ },
33
+ },
34
+ };
35
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/circuit-breaker/defaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,CAAC,MAAM,8BAA8B,GAAyB;IAClE,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE;QACR,kBAAkB,EAAE;YAClB,oBAAoB,EAAE,CAAC;SACxB;QACD,cAAc,EAAE;YACd,cAAc,EAAE,GAAG,EAAS,iBAAiB;YAC7C,gBAAgB,EAAE,GAAG,EAAO,8BAA8B;YAC1D,YAAY,EAAE,MAAM,EAAQ,0BAA0B;SACvD;QACD,eAAe,EAAE;YACf,oBAAoB,EAAE,CAAC,EAAK,mCAAmC;YAC/D,UAAU,EAAE,CAAC,EAAe,0BAA0B;YACtD,iBAAiB,EAAE,IAAI,EAAK,0BAA0B;SACvD;QACD,YAAY,EAAE;YACZ,qBAAqB,EAAE,OAAO;YAC9B,cAAc,EAAE,SAAS;SAC1B;QACD,OAAO,EAAE;YACP,iBAAiB,EAAE,CAAC;SACrB;QACD,YAAY,EAAE;YACZ,oBAAoB,EAAE,CAAC,EAAmB,qBAAqB;YAC/D,sBAAsB,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAI,2BAA2B;SACtE;KACF;CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Circuit Breaker Module
3
+ *
4
+ * Barrel export for the circuit breaker system.
5
+ */
6
+ export type { BreakerType, BreakerState, BreakerStatus, BreakerEvent, BreakerCheckResult, CircuitBreakerConfig, IterationData, RepeatedFailureThresholds, CostRunawayThresholds, InfiniteLoopThresholds, TokenBurnThresholds, StallThresholds, BreakerThresholds, } from './types.js';
7
+ export { DEFAULT_CIRCUIT_BREAKER_CONFIG } from './defaults.js';
8
+ export { CircuitBreaker } from './breaker.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/circuit-breaker/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Circuit Breaker Module
3
+ *
4
+ * Barrel export for the circuit breaker system.
5
+ */
6
+ export { DEFAULT_CIRCUIT_BREAKER_CONFIG } from './defaults.js';
7
+ export { CircuitBreaker } from './breaker.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/circuit-breaker/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Circuit Breaker Types
3
+ *
4
+ * Type definitions for the circuit breaker system that replaces
5
+ * hard iteration caps with intelligent pause-on-bad-behavior.
6
+ */
7
+ export type BreakerType = 'repeated-failure' | 'cost-runaway' | 'infinite-loop' | 'token-burn' | 'stall' | 'wall-clock';
8
+ export type BreakerState = 'closed' | 'open' | 'half-open';
9
+ export interface RepeatedFailureThresholds {
10
+ maxConsecutiveErrors: number;
11
+ }
12
+ export interface CostRunawayThresholds {
13
+ maxSessionCost: number;
14
+ maxCostPerMinute: number;
15
+ windowSizeMs: number;
16
+ }
17
+ export interface InfiniteLoopThresholds {
18
+ maxIdenticalInWindow: number;
19
+ windowSize: number;
20
+ detectOscillation: boolean;
21
+ }
22
+ export interface TokenBurnThresholds {
23
+ maxTokensPerIteration: number;
24
+ maxTotalTokens: number;
25
+ }
26
+ export interface StallThresholds {
27
+ maxIdleIterations: number;
28
+ }
29
+ export interface WallClockThresholds {
30
+ maxSessionDurationMs: number;
31
+ maxIterationDurationMs: number;
32
+ }
33
+ export type BreakerThresholds = RepeatedFailureThresholds | CostRunawayThresholds | InfiniteLoopThresholds | TokenBurnThresholds | StallThresholds | WallClockThresholds;
34
+ export interface BreakerEvent {
35
+ type: BreakerType;
36
+ timestamp: Date;
37
+ message: string;
38
+ data?: Record<string, unknown>;
39
+ }
40
+ export interface BreakerStatus {
41
+ type: BreakerType;
42
+ state: BreakerState;
43
+ tripCount: number;
44
+ lastTripped?: Date;
45
+ lastEvent?: BreakerEvent;
46
+ }
47
+ export interface CircuitBreakerConfig {
48
+ enabled: boolean;
49
+ breakers: {
50
+ 'repeated-failure': RepeatedFailureThresholds;
51
+ 'cost-runaway': CostRunawayThresholds;
52
+ 'infinite-loop': InfiniteLoopThresholds;
53
+ 'token-burn': TokenBurnThresholds;
54
+ 'stall': StallThresholds;
55
+ 'wall-clock': WallClockThresholds;
56
+ };
57
+ }
58
+ export interface IterationData {
59
+ iteration: number;
60
+ error?: string;
61
+ toolCalls?: Array<{
62
+ name: string;
63
+ arguments: Record<string, unknown>;
64
+ }>;
65
+ inputTokens?: number;
66
+ outputTokens?: number;
67
+ cost?: number;
68
+ content?: string;
69
+ timestamp?: Date;
70
+ }
71
+ export interface BreakerCheckResult {
72
+ tripped: boolean;
73
+ breaker?: BreakerType;
74
+ message?: string;
75
+ data?: Record<string, unknown>;
76
+ }
77
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/circuit-breaker/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,MAAM,WAAW,GACnB,kBAAkB,GAClB,cAAc,GACd,eAAe,GACf,YAAY,GACZ,OAAO,GACP,YAAY,CAAC;AAEjB,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAM3D,MAAM,WAAW,yBAAyB;IACxC,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAClC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,MAAM,iBAAiB,GACzB,yBAAyB,GACzB,qBAAqB,GACrB,sBAAsB,GACtB,mBAAmB,GACnB,eAAe,GACf,mBAAmB,CAAC;AAMxB,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,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C;CAChC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Circuit Breaker Types
3
+ *
4
+ * Type definitions for the circuit breaker system that replaces
5
+ * hard iteration caps with intelligent pause-on-bad-behavior.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/circuit-breaker/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Circuit Breaker - Top-level barrel
3
+ *
4
+ * Re-exports from src/circuit-breaker/ for clean imports.
5
+ */
6
+ export { CircuitBreaker, DEFAULT_CIRCUIT_BREAKER_CONFIG, } from './circuit-breaker/index.js';
7
+ export type { BreakerType, BreakerState, BreakerStatus, BreakerEvent, BreakerCheckResult, CircuitBreakerConfig, IterationData, RepeatedFailureThresholds, CostRunawayThresholds, InfiniteLoopThresholds, TokenBurnThresholds, StallThresholds, BreakerThresholds, } from './circuit-breaker/index.js';
8
+ //# sourceMappingURL=circuit-breaker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../src/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,cAAc,EACd,8BAA8B,GAC/B,MAAM,4BAA4B,CAAC;AAEpC,YAAY,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Circuit Breaker - Top-level barrel
3
+ *
4
+ * Re-exports from src/circuit-breaker/ for clean imports.
5
+ */
6
+ export { CircuitBreaker, DEFAULT_CIRCUIT_BREAKER_CONFIG, } from './circuit-breaker/index.js';
7
+ //# sourceMappingURL=circuit-breaker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../src/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,cAAc,EACd,8BAA8B,GAC/B,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * CLI Agent Loop & Display
3
+ *
4
+ * Agent execution, autonomous loop, and tool output formatting.
5
+ */
6
+ import type { CLIState } from './types.js';
7
+ export declare function runAgent(prompt: string, state: CLIState): Promise<string>;
8
+ export declare function startLoop(args: string, state: CLIState): Promise<void>;
9
+ //# sourceMappingURL=agent.d.ts.map