@claude-flow/cli 3.0.0-alpha.79 → 3.0.0-alpha.80

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 (41) hide show
  1. package/dist/src/index.d.ts +10 -0
  2. package/dist/src/index.d.ts.map +1 -1
  3. package/dist/src/index.js +6 -0
  4. package/dist/src/index.js.map +1 -1
  5. package/dist/src/mcp-client.d.ts.map +1 -1
  6. package/dist/src/mcp-client.js +2 -0
  7. package/dist/src/mcp-client.js.map +1 -1
  8. package/dist/src/mcp-tools/claims-tools.d.ts +12 -0
  9. package/dist/src/mcp-tools/claims-tools.d.ts.map +1 -0
  10. package/dist/src/mcp-tools/claims-tools.js +732 -0
  11. package/dist/src/mcp-tools/claims-tools.js.map +1 -0
  12. package/dist/src/mcp-tools/index.d.ts +1 -0
  13. package/dist/src/mcp-tools/index.d.ts.map +1 -1
  14. package/dist/src/mcp-tools/index.js +1 -0
  15. package/dist/src/mcp-tools/index.js.map +1 -1
  16. package/dist/src/production/circuit-breaker.d.ts +101 -0
  17. package/dist/src/production/circuit-breaker.d.ts.map +1 -0
  18. package/dist/src/production/circuit-breaker.js +241 -0
  19. package/dist/src/production/circuit-breaker.js.map +1 -0
  20. package/dist/src/production/error-handler.d.ts +92 -0
  21. package/dist/src/production/error-handler.d.ts.map +1 -0
  22. package/dist/src/production/error-handler.js +299 -0
  23. package/dist/src/production/error-handler.js.map +1 -0
  24. package/dist/src/production/index.d.ts +23 -0
  25. package/dist/src/production/index.d.ts.map +1 -0
  26. package/dist/src/production/index.js +18 -0
  27. package/dist/src/production/index.js.map +1 -0
  28. package/dist/src/production/monitoring.d.ts +161 -0
  29. package/dist/src/production/monitoring.d.ts.map +1 -0
  30. package/dist/src/production/monitoring.js +356 -0
  31. package/dist/src/production/monitoring.js.map +1 -0
  32. package/dist/src/production/rate-limiter.d.ts +80 -0
  33. package/dist/src/production/rate-limiter.d.ts.map +1 -0
  34. package/dist/src/production/rate-limiter.js +201 -0
  35. package/dist/src/production/rate-limiter.js.map +1 -0
  36. package/dist/src/production/retry.d.ts +48 -0
  37. package/dist/src/production/retry.d.ts.map +1 -0
  38. package/dist/src/production/retry.js +179 -0
  39. package/dist/src/production/retry.js.map +1 -0
  40. package/dist/tsconfig.tsbuildinfo +1 -1
  41. package/package.json +1 -1
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Production Retry Mechanisms
3
+ *
4
+ * Provides retry with:
5
+ * - Exponential backoff
6
+ * - Jitter
7
+ * - Per-error-type configuration
8
+ * - Circuit breaker integration
9
+ *
10
+ * @module @claude-flow/cli/production/retry
11
+ */
12
+ export interface RetryConfig {
13
+ maxAttempts: number;
14
+ initialDelayMs: number;
15
+ maxDelayMs: number;
16
+ backoffMultiplier: number;
17
+ jitter: number;
18
+ nonRetryableErrors: string[];
19
+ shouldRetry?: (error: Error, attempt: number) => boolean;
20
+ onRetry?: (error: Error, attempt: number, delayMs: number) => void;
21
+ }
22
+ export interface RetryResult<T> {
23
+ success: boolean;
24
+ result?: T;
25
+ error?: Error;
26
+ attempts: number;
27
+ totalTimeMs: number;
28
+ retryHistory: Array<{
29
+ attempt: number;
30
+ error: string;
31
+ delayMs: number;
32
+ }>;
33
+ }
34
+ export type RetryStrategy = 'exponential' | 'linear' | 'constant' | 'fibonacci';
35
+ /**
36
+ * Execute a function with retry logic
37
+ */
38
+ export declare function withRetry<T>(fn: () => Promise<T>, config?: Partial<RetryConfig>, strategy?: RetryStrategy): Promise<RetryResult<T>>;
39
+ /**
40
+ * Create a retryable version of a function
41
+ */
42
+ export declare function makeRetryable<T extends (...args: unknown[]) => Promise<unknown>>(fn: T, config?: Partial<RetryConfig>, strategy?: RetryStrategy): (...args: Parameters<T>) => Promise<RetryResult<Awaited<ReturnType<T>>>>;
43
+ /**
44
+ * Retry decorator for class methods
45
+ */
46
+ export declare function Retryable(config?: Partial<RetryConfig>, strategy?: RetryStrategy): (_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
47
+ export default withRetry;
48
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/production/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,MAAM,WAAW,WAAW;IAE1B,WAAW,EAAE,MAAM,CAAC;IAEpB,cAAc,EAAE,MAAM,CAAC;IAEvB,UAAU,EAAE,MAAM,CAAC;IAEnB,iBAAiB,EAAE,MAAM,CAAC;IAE1B,MAAM,EAAE,MAAM,CAAC;IAEf,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAE7B,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAEzD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpE;AAED,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC1E;AAED,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CAAC;AA4GhF;;GAEG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,EACjC,QAAQ,GAAE,aAA6B,GACtC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CA+DzB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,EAC9E,EAAE,EAAE,CAAC,EACL,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,EACjC,QAAQ,GAAE,aAA6B,GACtC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAI1E;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,EACjC,QAAQ,GAAE,aAA6B,IAGrC,SAAS,OAAO,EAChB,cAAc,MAAM,EACpB,YAAY,kBAAkB,wBAoBjC;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Production Retry Mechanisms
3
+ *
4
+ * Provides retry with:
5
+ * - Exponential backoff
6
+ * - Jitter
7
+ * - Per-error-type configuration
8
+ * - Circuit breaker integration
9
+ *
10
+ * @module @claude-flow/cli/production/retry
11
+ */
12
+ // ============================================================================
13
+ // Default Configuration
14
+ // ============================================================================
15
+ const DEFAULT_CONFIG = {
16
+ maxAttempts: 3,
17
+ initialDelayMs: 1000,
18
+ maxDelayMs: 30000,
19
+ backoffMultiplier: 2,
20
+ jitter: 0.1,
21
+ nonRetryableErrors: [
22
+ 'validation',
23
+ 'authentication',
24
+ 'authorization',
25
+ 'not_found',
26
+ ],
27
+ };
28
+ // ============================================================================
29
+ // Retry Implementation
30
+ // ============================================================================
31
+ /**
32
+ * Calculate delay for a given attempt
33
+ */
34
+ function calculateDelay(attempt, config, strategy = 'exponential') {
35
+ let delay;
36
+ switch (strategy) {
37
+ case 'linear':
38
+ delay = config.initialDelayMs * attempt;
39
+ break;
40
+ case 'constant':
41
+ delay = config.initialDelayMs;
42
+ break;
43
+ case 'fibonacci':
44
+ delay = config.initialDelayMs * fibonacci(attempt);
45
+ break;
46
+ case 'exponential':
47
+ default:
48
+ delay = config.initialDelayMs * Math.pow(config.backoffMultiplier, attempt - 1);
49
+ }
50
+ // Apply max delay cap
51
+ delay = Math.min(delay, config.maxDelayMs);
52
+ // Apply jitter
53
+ if (config.jitter > 0) {
54
+ const jitterRange = delay * config.jitter;
55
+ delay += (Math.random() - 0.5) * 2 * jitterRange;
56
+ }
57
+ return Math.round(Math.max(0, delay));
58
+ }
59
+ /**
60
+ * Fibonacci helper for fibonacci backoff
61
+ */
62
+ function fibonacci(n) {
63
+ if (n <= 1)
64
+ return 1;
65
+ let a = 1, b = 1;
66
+ for (let i = 2; i <= n; i++) {
67
+ [a, b] = [b, a + b];
68
+ }
69
+ return b;
70
+ }
71
+ /**
72
+ * Check if an error should be retried
73
+ */
74
+ function shouldRetryError(error, attempt, config) {
75
+ // Check custom retry function
76
+ if (config.shouldRetry) {
77
+ return config.shouldRetry(error, attempt);
78
+ }
79
+ // Check non-retryable error patterns
80
+ const message = error.message.toLowerCase();
81
+ for (const pattern of config.nonRetryableErrors) {
82
+ if (message.includes(pattern.toLowerCase())) {
83
+ return false;
84
+ }
85
+ }
86
+ // Default: retry if we haven't exceeded max attempts
87
+ return attempt < config.maxAttempts;
88
+ }
89
+ /**
90
+ * Sleep for a given number of milliseconds
91
+ */
92
+ function sleep(ms) {
93
+ return new Promise(resolve => setTimeout(resolve, ms));
94
+ }
95
+ /**
96
+ * Execute a function with retry logic
97
+ */
98
+ export async function withRetry(fn, config = {}, strategy = 'exponential') {
99
+ const finalConfig = { ...DEFAULT_CONFIG, ...config };
100
+ const startTime = Date.now();
101
+ const retryHistory = [];
102
+ let lastError;
103
+ let attempt = 0;
104
+ while (attempt < finalConfig.maxAttempts) {
105
+ attempt++;
106
+ try {
107
+ const result = await fn();
108
+ return {
109
+ success: true,
110
+ result,
111
+ attempts: attempt,
112
+ totalTimeMs: Date.now() - startTime,
113
+ retryHistory,
114
+ };
115
+ }
116
+ catch (error) {
117
+ lastError = error;
118
+ // Check if we should retry
119
+ if (!shouldRetryError(lastError, attempt, finalConfig)) {
120
+ return {
121
+ success: false,
122
+ error: lastError,
123
+ attempts: attempt,
124
+ totalTimeMs: Date.now() - startTime,
125
+ retryHistory,
126
+ };
127
+ }
128
+ // Calculate delay
129
+ const delay = calculateDelay(attempt, finalConfig, strategy);
130
+ // Record retry
131
+ retryHistory.push({
132
+ attempt,
133
+ error: lastError.message,
134
+ delayMs: delay,
135
+ });
136
+ // Call retry callback
137
+ if (finalConfig.onRetry) {
138
+ finalConfig.onRetry(lastError, attempt, delay);
139
+ }
140
+ // Wait before retrying
141
+ if (attempt < finalConfig.maxAttempts) {
142
+ await sleep(delay);
143
+ }
144
+ }
145
+ }
146
+ return {
147
+ success: false,
148
+ error: lastError,
149
+ attempts: attempt,
150
+ totalTimeMs: Date.now() - startTime,
151
+ retryHistory,
152
+ };
153
+ }
154
+ /**
155
+ * Create a retryable version of a function
156
+ */
157
+ export function makeRetryable(fn, config = {}, strategy = 'exponential') {
158
+ return async (...args) => {
159
+ return withRetry(() => fn(...args), config, strategy);
160
+ };
161
+ }
162
+ /**
163
+ * Retry decorator for class methods
164
+ */
165
+ export function Retryable(config = {}, strategy = 'exponential') {
166
+ return function (_target, _propertyKey, descriptor) {
167
+ const originalMethod = descriptor.value;
168
+ descriptor.value = async function (...args) {
169
+ const result = await withRetry(() => originalMethod.apply(this, args), config, strategy);
170
+ if (result.success) {
171
+ return result.result;
172
+ }
173
+ throw result.error;
174
+ };
175
+ return descriptor;
176
+ };
177
+ }
178
+ export default withRetry;
179
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../src/production/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoCH,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E,MAAM,cAAc,GAAgB;IAClC,WAAW,EAAE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