dino-spec 9.9.0 → 9.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +10 -2
  2. package/dist/core/agents/circuit-breaker.d.ts +116 -0
  3. package/dist/core/agents/circuit-breaker.d.ts.map +1 -0
  4. package/dist/core/agents/circuit-breaker.js +260 -0
  5. package/dist/core/agents/circuit-breaker.js.map +1 -0
  6. package/dist/core/agents/circuit-registry.d.ts +101 -0
  7. package/dist/core/agents/circuit-registry.d.ts.map +1 -0
  8. package/dist/core/agents/circuit-registry.js +291 -0
  9. package/dist/core/agents/circuit-registry.js.map +1 -0
  10. package/dist/core/agents/index.d.ts +2 -0
  11. package/dist/core/agents/index.d.ts.map +1 -1
  12. package/dist/core/agents/index.js +17 -0
  13. package/dist/core/agents/index.js.map +1 -1
  14. package/dist/core/context-repl/types.d.ts +2 -2
  15. package/dist/core/errors/index.d.ts +25 -0
  16. package/dist/core/errors/index.d.ts.map +1 -1
  17. package/dist/core/errors/index.js +62 -0
  18. package/dist/core/errors/index.js.map +1 -1
  19. package/dist/core/memory/index.d.ts +8 -1
  20. package/dist/core/memory/index.d.ts.map +1 -1
  21. package/dist/core/memory/index.js +13 -1
  22. package/dist/core/memory/index.js.map +1 -1
  23. package/dist/core/memory/memory-capture-agent.d.ts +56 -0
  24. package/dist/core/memory/memory-capture-agent.d.ts.map +1 -0
  25. package/dist/core/memory/memory-capture-agent.js +331 -0
  26. package/dist/core/memory/memory-capture-agent.js.map +1 -0
  27. package/dist/core/memory/memory-retrieval-agent.d.ts +40 -0
  28. package/dist/core/memory/memory-retrieval-agent.d.ts.map +1 -0
  29. package/dist/core/memory/memory-retrieval-agent.js +411 -0
  30. package/dist/core/memory/memory-retrieval-agent.js.map +1 -0
  31. package/dist/core/memory/memory-store.d.ts +37 -1
  32. package/dist/core/memory/memory-store.d.ts.map +1 -1
  33. package/dist/core/memory/memory-store.js +245 -59
  34. package/dist/core/memory/memory-store.js.map +1 -1
  35. package/dist/core/memory/semantic-recall.d.ts +40 -2
  36. package/dist/core/memory/semantic-recall.d.ts.map +1 -1
  37. package/dist/core/memory/semantic-recall.js +155 -1
  38. package/dist/core/memory/semantic-recall.js.map +1 -1
  39. package/dist/core/memory/types.d.ts +157 -1
  40. package/dist/core/memory/types.d.ts.map +1 -1
  41. package/dist/core/memory/types.js +33 -1
  42. package/dist/core/memory/types.js.map +1 -1
  43. package/dist/core/traces/context-transitions.d.ts +113 -0
  44. package/dist/core/traces/context-transitions.d.ts.map +1 -0
  45. package/dist/core/traces/context-transitions.js +482 -0
  46. package/dist/core/traces/context-transitions.js.map +1 -0
  47. package/dist/core/traces/execution-tree.d.ts +149 -0
  48. package/dist/core/traces/execution-tree.d.ts.map +1 -0
  49. package/dist/core/traces/execution-tree.js +452 -0
  50. package/dist/core/traces/execution-tree.js.map +1 -0
  51. package/dist/core/traces/index.d.ts +16 -0
  52. package/dist/core/traces/index.d.ts.map +1 -0
  53. package/dist/core/traces/index.js +49 -0
  54. package/dist/core/traces/index.js.map +1 -0
  55. package/dist/core/traces/memory-access-log.d.ts +114 -0
  56. package/dist/core/traces/memory-access-log.d.ts.map +1 -0
  57. package/dist/core/traces/memory-access-log.js +400 -0
  58. package/dist/core/traces/memory-access-log.js.map +1 -0
  59. package/dist/core/traces/trace-exporter.d.ts +33 -0
  60. package/dist/core/traces/trace-exporter.d.ts.map +1 -0
  61. package/dist/core/traces/trace-exporter.js +807 -0
  62. package/dist/core/traces/trace-exporter.js.map +1 -0
  63. package/dist/core/traces/types.d.ts +304 -0
  64. package/dist/core/traces/types.d.ts.map +1 -0
  65. package/dist/core/traces/types.js +34 -0
  66. package/dist/core/traces/types.js.map +1 -0
  67. package/dist/mcp/server.d.ts.map +1 -1
  68. package/dist/mcp/server.js +503 -1
  69. package/dist/mcp/server.js.map +1 -1
  70. package/package.json +1 -1
package/README.md CHANGED
@@ -10,11 +10,12 @@
10
10
  <__|-|__|
11
11
  ```
12
12
 
13
- **dino-spec** brings structured, context-aware development to [Claude Code](https://claude.ai/code). It automatically maintains session state, provides 33 MCP tools, and enables intelligent context retrieval with real-time statusline display.
13
+ **dino-spec** brings structured, context-aware development to [Claude Code](https://claude.ai/code). It automatically maintains session state, provides 47 MCP tools, and enables intelligent context retrieval with real-time statusline display.
14
14
 
15
15
  ## Features
16
16
 
17
- - **MCP Integration** - 33 tools + 19 resources auto-configured during init
17
+ - **MCP Integration** - 47 tools + 29 resources auto-configured during init
18
+ - **Enhanced Observability** - Execution tree, memory access log, context transitions with HTML/JSON export (v9.10.0)
18
19
  - **Session State** - Automatic tracking of focus, test/build/lint status, blockers
19
20
  - **Persistent Memory** - Decisions, patterns, learnings survive across sessions
20
21
  - **Interactive Memory Browser** - TUI for browsing memories with vim-style navigation (v9.0.0)
@@ -106,6 +107,10 @@ Access via `@dino://` in Claude Code:
106
107
  | `@dino://handoff` | Agent handoff context |
107
108
  | `@dino://memories/summary` | All memories overview |
108
109
  | `@dino://retrieval/ranked` | Session-relevant files |
110
+ | `@dino://traces/tree` | Execution tree overview (v9.10.0) |
111
+ | `@dino://traces/memory-access` | Memory access log (v9.10.0) |
112
+ | `@dino://traces/context-graph` | Context transition graph (v9.10.0) |
113
+ | `@dino://traces/overview` | Combined trace overview (v9.10.0) |
109
114
 
110
115
  ## MCP Tools
111
116
 
@@ -134,6 +139,9 @@ Key tools available via Claude Code:
134
139
  | `dino_chunk_file` | AST-based semantic chunking |
135
140
  | `dino_chunk_analyze` | Chunking analysis |
136
141
  | `dino_effort_recommend` | Recommend effort level based on task complexity (v9.9.0) |
142
+ | `dino_trace_export` | Export execution traces to JSON or HTML (v9.10.0) |
143
+ | `dino_memory_access_stats` | View memory operation statistics (v9.10.0) |
144
+ | `dino_context_transitions` | View context transition history (v9.10.0) |
137
145
 
138
146
  ## Specialized Agents
139
147
 
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Circuit Breaker Pattern - v9.10.0
3
+ *
4
+ * Prevents repeated failures from wasting context budget.
5
+ * Implements exponential backoff [1s, 2s, 4s, 8s] and human escalation
6
+ * after persistent failures.
7
+ *
8
+ * State machine:
9
+ * - CLOSED → OPEN: After failureThreshold consecutive failures
10
+ * - OPEN → HALF-OPEN: After backoff duration expires
11
+ * - HALF-OPEN → CLOSED: On success
12
+ * - HALF-OPEN → OPEN: On failure (with increased backoff)
13
+ */
14
+ export type CircuitState = 'closed' | 'open' | 'half-open';
15
+ export interface CircuitBreakerConfig {
16
+ /** Number of failures before opening circuit. Default: 3 */
17
+ failureThreshold: number;
18
+ /** Number of successes in half-open to close. Default: 1 */
19
+ successThreshold: number;
20
+ /** Base duration for open state in ms. Default: 1000 */
21
+ openDurationMs: number;
22
+ /** Backoff multiplier for repeated failures. Default: 2 */
23
+ backoffMultiplier: number;
24
+ /** Maximum backoff duration in ms. Default: 8000 */
25
+ maxBackoffMs: number;
26
+ /** Failures before requiring human intervention. Default: 5 */
27
+ humanEscalationThreshold: number;
28
+ /** Time in ms before resetting failure count. Default: 60000 */
29
+ resetTimeoutMs: number;
30
+ }
31
+ export interface CircuitStats {
32
+ state: CircuitState;
33
+ consecutiveFailures: number;
34
+ consecutiveSuccesses: number;
35
+ totalFailures: number;
36
+ totalSuccesses: number;
37
+ lastFailureTime: number | null;
38
+ lastSuccessTime: number | null;
39
+ currentBackoffMs: number;
40
+ openUntil: number | null;
41
+ escalationRequired: boolean;
42
+ recentErrors: string[];
43
+ }
44
+ export interface CircuitResult<T> {
45
+ success: boolean;
46
+ data?: T;
47
+ error?: Error;
48
+ circuitState: CircuitState;
49
+ wasBlocked: boolean;
50
+ backoffMs?: number;
51
+ }
52
+ export declare const DEFAULT_CONFIG: CircuitBreakerConfig;
53
+ /**
54
+ * Circuit breaker implementation with state machine
55
+ */
56
+ export declare class CircuitBreaker {
57
+ private state;
58
+ private consecutiveFailures;
59
+ private consecutiveSuccesses;
60
+ private totalFailures;
61
+ private totalSuccesses;
62
+ private lastFailureTime;
63
+ private lastSuccessTime;
64
+ private currentBackoffMs;
65
+ private openUntil;
66
+ private recentErrors;
67
+ private readonly config;
68
+ readonly operationId: string;
69
+ constructor(operationId: string, config?: Partial<CircuitBreakerConfig>);
70
+ /**
71
+ * Execute an operation with circuit breaker protection
72
+ */
73
+ execute<T>(operation: () => Promise<T>): Promise<CircuitResult<T>>;
74
+ /**
75
+ * Record a successful operation
76
+ */
77
+ recordSuccess(): void;
78
+ /**
79
+ * Record a failed operation
80
+ */
81
+ recordFailure(error: Error): void;
82
+ /**
83
+ * Get current circuit state
84
+ */
85
+ getState(): CircuitState;
86
+ /**
87
+ * Get detailed circuit statistics
88
+ */
89
+ getStats(): CircuitStats;
90
+ /**
91
+ * Check if human escalation is required
92
+ */
93
+ requiresHumanEscalation(): boolean;
94
+ /**
95
+ * Reset circuit breaker to initial state
96
+ */
97
+ reset(): void;
98
+ /**
99
+ * Get remaining backoff time if circuit is open
100
+ */
101
+ getRemainingBackoffMs(): number;
102
+ /**
103
+ * Check if the circuit allows operations
104
+ */
105
+ isAllowingRequests(): boolean;
106
+ private transitionToOpen;
107
+ private transitionToHalfOpen;
108
+ private transitionToClosed;
109
+ private increaseBackoff;
110
+ private checkResetTimeout;
111
+ }
112
+ /**
113
+ * Format circuit stats for display
114
+ */
115
+ export declare function formatCircuitStats(stats: CircuitStats): string;
116
+ //# sourceMappingURL=circuit-breaker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../../src/core/agents/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,4DAA4D;IAC5D,gBAAgB,EAAE,MAAM,CAAC;IACzB,4DAA4D;IAC5D,gBAAgB,EAAE,MAAM,CAAC;IACzB,wDAAwD;IACxD,cAAc,EAAE,MAAM,CAAC;IACvB,2DAA2D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;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAEjB,WAAW,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,CAAC,oBAAoB,CAAM;IAM3E;;OAEG;IACG,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAyCxE;;OAEG;IACH,aAAa,IAAI,IAAI;IAarB;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAuBjC;;OAEG;IACH,QAAQ,IAAI,YAAY;IAKxB;;OAEG;IACH,QAAQ,IAAI,YAAY;IAiBxB;;OAEG;IACH,uBAAuB,IAAI,OAAO;IAIlC;;OAEG;IACH,KAAK,IAAI,IAAI;IAab;;OAEG;IACH,qBAAqB,IAAI,MAAM;IAO/B;;OAEG;IACH,kBAAkB,IAAI,OAAO;IAe7B,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,iBAAiB;CAW1B;AAMD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAsB9D"}
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Circuit Breaker Pattern - v9.10.0
3
+ *
4
+ * Prevents repeated failures from wasting context budget.
5
+ * Implements exponential backoff [1s, 2s, 4s, 8s] and human escalation
6
+ * after persistent failures.
7
+ *
8
+ * State machine:
9
+ * - CLOSED → OPEN: After failureThreshold consecutive failures
10
+ * - OPEN → HALF-OPEN: After backoff duration expires
11
+ * - HALF-OPEN → CLOSED: On success
12
+ * - HALF-OPEN → OPEN: On failure (with increased backoff)
13
+ */
14
+ // =============================================================================
15
+ // Constants
16
+ // =============================================================================
17
+ export const DEFAULT_CONFIG = {
18
+ failureThreshold: 3,
19
+ successThreshold: 1,
20
+ openDurationMs: 1000,
21
+ backoffMultiplier: 2,
22
+ maxBackoffMs: 8000,
23
+ humanEscalationThreshold: 5,
24
+ resetTimeoutMs: 60000,
25
+ };
26
+ const MAX_RECENT_ERRORS = 5;
27
+ // =============================================================================
28
+ // Circuit Breaker Class
29
+ // =============================================================================
30
+ /**
31
+ * Circuit breaker implementation with state machine
32
+ */
33
+ export class CircuitBreaker {
34
+ state = 'closed';
35
+ consecutiveFailures = 0;
36
+ consecutiveSuccesses = 0;
37
+ totalFailures = 0;
38
+ totalSuccesses = 0;
39
+ lastFailureTime = null;
40
+ lastSuccessTime = null;
41
+ currentBackoffMs;
42
+ openUntil = null;
43
+ recentErrors = [];
44
+ config;
45
+ operationId;
46
+ constructor(operationId, config = {}) {
47
+ this.operationId = operationId;
48
+ this.config = { ...DEFAULT_CONFIG, ...config };
49
+ this.currentBackoffMs = this.config.openDurationMs;
50
+ }
51
+ /**
52
+ * Execute an operation with circuit breaker protection
53
+ */
54
+ async execute(operation) {
55
+ // Check if we need to reset due to timeout
56
+ this.checkResetTimeout();
57
+ // Check if circuit is open
58
+ if (this.state === 'open') {
59
+ const now = Date.now();
60
+ if (this.openUntil && now < this.openUntil) {
61
+ return {
62
+ success: false,
63
+ circuitState: this.state,
64
+ wasBlocked: true,
65
+ backoffMs: this.openUntil - now,
66
+ };
67
+ }
68
+ // Transition to half-open
69
+ this.transitionToHalfOpen();
70
+ }
71
+ try {
72
+ const data = await operation();
73
+ this.recordSuccess();
74
+ return {
75
+ success: true,
76
+ data,
77
+ circuitState: this.state,
78
+ wasBlocked: false,
79
+ };
80
+ }
81
+ catch (error) {
82
+ const err = error instanceof Error ? error : new Error(String(error));
83
+ this.recordFailure(err);
84
+ return {
85
+ success: false,
86
+ error: err,
87
+ circuitState: this.state,
88
+ wasBlocked: false,
89
+ backoffMs: this.state === 'open' ? this.currentBackoffMs : undefined,
90
+ };
91
+ }
92
+ }
93
+ /**
94
+ * Record a successful operation
95
+ */
96
+ recordSuccess() {
97
+ this.consecutiveSuccesses++;
98
+ this.consecutiveFailures = 0;
99
+ this.totalSuccesses++;
100
+ this.lastSuccessTime = Date.now();
101
+ if (this.state === 'half-open') {
102
+ if (this.consecutiveSuccesses >= this.config.successThreshold) {
103
+ this.transitionToClosed();
104
+ }
105
+ }
106
+ }
107
+ /**
108
+ * Record a failed operation
109
+ */
110
+ recordFailure(error) {
111
+ this.consecutiveFailures++;
112
+ this.consecutiveSuccesses = 0;
113
+ this.totalFailures++;
114
+ this.lastFailureTime = Date.now();
115
+ // Store recent error
116
+ this.recentErrors.push(error.message);
117
+ if (this.recentErrors.length > MAX_RECENT_ERRORS) {
118
+ this.recentErrors.shift();
119
+ }
120
+ if (this.state === 'closed') {
121
+ if (this.consecutiveFailures >= this.config.failureThreshold) {
122
+ this.transitionToOpen();
123
+ }
124
+ }
125
+ else if (this.state === 'half-open') {
126
+ // Failed in half-open, go back to open with increased backoff
127
+ this.increaseBackoff();
128
+ this.transitionToOpen();
129
+ }
130
+ }
131
+ /**
132
+ * Get current circuit state
133
+ */
134
+ getState() {
135
+ this.checkResetTimeout();
136
+ return this.state;
137
+ }
138
+ /**
139
+ * Get detailed circuit statistics
140
+ */
141
+ getStats() {
142
+ this.checkResetTimeout();
143
+ return {
144
+ state: this.state,
145
+ consecutiveFailures: this.consecutiveFailures,
146
+ consecutiveSuccesses: this.consecutiveSuccesses,
147
+ totalFailures: this.totalFailures,
148
+ totalSuccesses: this.totalSuccesses,
149
+ lastFailureTime: this.lastFailureTime,
150
+ lastSuccessTime: this.lastSuccessTime,
151
+ currentBackoffMs: this.currentBackoffMs,
152
+ openUntil: this.openUntil,
153
+ escalationRequired: this.requiresHumanEscalation(),
154
+ recentErrors: [...this.recentErrors],
155
+ };
156
+ }
157
+ /**
158
+ * Check if human escalation is required
159
+ */
160
+ requiresHumanEscalation() {
161
+ return this.totalFailures >= this.config.humanEscalationThreshold;
162
+ }
163
+ /**
164
+ * Reset circuit breaker to initial state
165
+ */
166
+ reset() {
167
+ this.state = 'closed';
168
+ this.consecutiveFailures = 0;
169
+ this.consecutiveSuccesses = 0;
170
+ this.totalFailures = 0;
171
+ this.totalSuccesses = 0;
172
+ this.lastFailureTime = null;
173
+ this.lastSuccessTime = null;
174
+ this.currentBackoffMs = this.config.openDurationMs;
175
+ this.openUntil = null;
176
+ this.recentErrors = [];
177
+ }
178
+ /**
179
+ * Get remaining backoff time if circuit is open
180
+ */
181
+ getRemainingBackoffMs() {
182
+ if (this.state !== 'open' || !this.openUntil) {
183
+ return 0;
184
+ }
185
+ return Math.max(0, this.openUntil - Date.now());
186
+ }
187
+ /**
188
+ * Check if the circuit allows operations
189
+ */
190
+ isAllowingRequests() {
191
+ this.checkResetTimeout();
192
+ if (this.state === 'closed')
193
+ return true;
194
+ if (this.state === 'half-open')
195
+ return true;
196
+ if (this.state === 'open' && this.openUntil && Date.now() >= this.openUntil) {
197
+ this.transitionToHalfOpen();
198
+ return true;
199
+ }
200
+ return false;
201
+ }
202
+ // ===========================================================================
203
+ // Private Methods
204
+ // ===========================================================================
205
+ transitionToOpen() {
206
+ this.state = 'open';
207
+ this.openUntil = Date.now() + this.currentBackoffMs;
208
+ this.consecutiveSuccesses = 0;
209
+ }
210
+ transitionToHalfOpen() {
211
+ this.state = 'half-open';
212
+ this.openUntil = null;
213
+ this.consecutiveSuccesses = 0;
214
+ }
215
+ transitionToClosed() {
216
+ this.state = 'closed';
217
+ this.openUntil = null;
218
+ this.consecutiveFailures = 0;
219
+ // Reset backoff on successful recovery
220
+ this.currentBackoffMs = this.config.openDurationMs;
221
+ }
222
+ increaseBackoff() {
223
+ this.currentBackoffMs = Math.min(this.currentBackoffMs * this.config.backoffMultiplier, this.config.maxBackoffMs);
224
+ }
225
+ checkResetTimeout() {
226
+ // Reset failure count if enough time has passed since last failure
227
+ if (this.lastFailureTime &&
228
+ Date.now() - this.lastFailureTime > this.config.resetTimeoutMs &&
229
+ this.state === 'closed') {
230
+ this.consecutiveFailures = 0;
231
+ this.recentErrors = [];
232
+ }
233
+ }
234
+ }
235
+ // =============================================================================
236
+ // Utility Functions
237
+ // =============================================================================
238
+ /**
239
+ * Format circuit stats for display
240
+ */
241
+ export function formatCircuitStats(stats) {
242
+ const lines = [
243
+ `State: ${stats.state}`,
244
+ `Consecutive failures: ${stats.consecutiveFailures}`,
245
+ `Total: ${stats.totalSuccesses} successes, ${stats.totalFailures} failures`,
246
+ ];
247
+ if (stats.state === 'open' && stats.openUntil) {
248
+ const remaining = Math.max(0, stats.openUntil - Date.now());
249
+ lines.push(`Retry in: ${Math.ceil(remaining / 1000)}s`);
250
+ }
251
+ if (stats.escalationRequired) {
252
+ lines.push(`⚠️ Human escalation required`);
253
+ }
254
+ if (stats.recentErrors.length > 0) {
255
+ lines.push(`Recent errors:`);
256
+ stats.recentErrors.forEach((e, i) => lines.push(` ${i + 1}. ${e}`));
257
+ }
258
+ return lines.join('\n');
259
+ }
260
+ //# sourceMappingURL=circuit-breaker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../../../src/core/agents/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAgDH,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,MAAM,CAAC,MAAM,cAAc,GAAyB;IAClD,gBAAgB,EAAE,CAAC;IACnB,gBAAgB,EAAE,CAAC;IACnB,cAAc,EAAE,IAAI;IACpB,iBAAiB,EAAE,CAAC;IACpB,YAAY,EAAE,IAAI;IAClB,wBAAwB,EAAE,CAAC;IAC3B,cAAc,EAAE,KAAK;CACtB,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,OAAO,cAAc;IACjB,KAAK,GAAiB,QAAQ,CAAC;IAC/B,mBAAmB,GAAG,CAAC,CAAC;IACxB,oBAAoB,G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UAAU,kBAAkB,CAAC,KAAmB;IACpD,MAAM,KAAK,GAAG;QACZ,UAAU,KAAK,CAAC,KAAK,EAAE;QACvB,yBAAyB,KAAK,CAAC,mBAAmB,EAAE;QACpD,UAAU,KAAK,CAAC,cAAc,eAAe,KAAK,CAAC,aAAa,WAAW;KAC5E,CAAC;IAEF,IAAI,KAAK,CAAC,KAAK,KAAK,MAAM,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAC5D,KAAK,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC7B,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Circuit Breaker Registry - v9.10.0
3
+ *
4
+ * Central registry managing multiple circuit breakers by operation ID.
5
+ * Provides singleton access pattern matching budgetManager.
6
+ *
7
+ * Categories with different defaults:
8
+ * - mcp-tool: MCP tool calls (threshold: 3, escalation: 5)
9
+ * - agent: Sub-agent spawning (threshold: 2, escalation: 4)
10
+ * - memory: Memory/retrieval operations (threshold: 4, escalation: 6)
11
+ * - external: External API calls (threshold: 3, escalation: 5)
12
+ */
13
+ import { CircuitBreaker, CircuitStats, CircuitBreakerConfig } from './circuit-breaker.js';
14
+ export type BreakerCategory = 'mcp-tool' | 'agent' | 'memory' | 'external';
15
+ export interface CategoryConfig extends Partial<CircuitBreakerConfig> {
16
+ /** Description of this category */
17
+ description: string;
18
+ }
19
+ export interface RegistryStats {
20
+ totalBreakers: number;
21
+ openBreakers: number;
22
+ halfOpenBreakers: number;
23
+ closedBreakers: number;
24
+ escalationsRequired: number;
25
+ byCategory: Record<BreakerCategory, number>;
26
+ }
27
+ export interface OpenCircuitInfo {
28
+ operationId: string;
29
+ category: BreakerCategory;
30
+ stats: CircuitStats;
31
+ remainingMs: number;
32
+ }
33
+ export declare const CATEGORY_CONFIGS: Record<BreakerCategory, CategoryConfig>;
34
+ /**
35
+ * Registry managing multiple circuit breakers
36
+ */
37
+ export declare class CircuitBreakerRegistry {
38
+ private breakers;
39
+ private categories;
40
+ /**
41
+ * Get or create a circuit breaker for an operation
42
+ */
43
+ getBreaker(operationId: string, category: BreakerCategory): CircuitBreaker;
44
+ /**
45
+ * Get all open circuits with their info
46
+ */
47
+ getOpenCircuits(): OpenCircuitInfo[];
48
+ /**
49
+ * Get circuits requiring human escalation
50
+ */
51
+ getEscalationRequired(): OpenCircuitInfo[];
52
+ /**
53
+ * Get registry statistics
54
+ */
55
+ getStats(): RegistryStats;
56
+ /**
57
+ * Reset a specific circuit breaker
58
+ */
59
+ resetBreaker(operationId: string): boolean;
60
+ /**
61
+ * Reset all circuit breakers
62
+ */
63
+ resetAll(): void;
64
+ /**
65
+ * Remove a circuit breaker from registry
66
+ */
67
+ removeBreaker(operationId: string): boolean;
68
+ /**
69
+ * Clear all circuit breakers from registry
70
+ */
71
+ clear(): void;
72
+ /**
73
+ * Get a breaker's stats if it exists
74
+ */
75
+ getBreakerStats(operationId: string): CircuitStats | null;
76
+ /**
77
+ * List all operation IDs
78
+ */
79
+ listOperations(): string[];
80
+ /**
81
+ * List operations by category
82
+ */
83
+ listByCategory(category: BreakerCategory): string[];
84
+ }
85
+ /**
86
+ * Global circuit breaker registry singleton
87
+ */
88
+ export declare const circuitRegistry: CircuitBreakerRegistry;
89
+ /**
90
+ * Wrap an async function with circuit breaker protection
91
+ */
92
+ export declare function withCircuitBreaker<T>(fn: () => Promise<T>, operationId: string, category: BreakerCategory): Promise<T>;
93
+ /**
94
+ * Format registry stats for display
95
+ */
96
+ export declare function formatRegistryStats(stats: RegistryStats): string;
97
+ /**
98
+ * Format open circuits for display
99
+ */
100
+ export declare function formatOpenCircuits(circuits: OpenCircuitInfo[]): string;
101
+ //# sourceMappingURL=circuit-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circuit-registry.d.ts","sourceRoot":"","sources":["../../../src/core/agents/circuit-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,cAAc,EACd,YAAY,EACZ,oBAAoB,EAGrB,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE3E,MAAM,WAAW,cAAe,SAAQ,OAAO,CAAC,oBAAoB,CAAC;IACnE,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,KAAK,EAAE,YAAY,CAAC;IACpB,WAAW,EA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