attocode 0.1.2 → 0.1.4

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 (175) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/README.md +180 -0
  3. package/dist/src/agent.d.ts +78 -1
  4. package/dist/src/agent.d.ts.map +1 -1
  5. package/dist/src/agent.js +639 -36
  6. package/dist/src/agent.js.map +1 -1
  7. package/dist/src/analysis/feedback-loop.d.ts +115 -0
  8. package/dist/src/analysis/feedback-loop.d.ts.map +1 -0
  9. package/dist/src/analysis/feedback-loop.js +226 -0
  10. package/dist/src/analysis/feedback-loop.js.map +1 -0
  11. package/dist/src/analysis/index.d.ts +9 -0
  12. package/dist/src/analysis/index.d.ts.map +1 -0
  13. package/dist/src/analysis/index.js +9 -0
  14. package/dist/src/analysis/index.js.map +1 -0
  15. package/dist/src/analysis/prompt-templates.d.ts +36 -0
  16. package/dist/src/analysis/prompt-templates.d.ts.map +1 -0
  17. package/dist/src/analysis/prompt-templates.js +198 -0
  18. package/dist/src/analysis/prompt-templates.js.map +1 -0
  19. package/dist/src/analysis/trace-summary.d.ts +56 -0
  20. package/dist/src/analysis/trace-summary.d.ts.map +1 -0
  21. package/dist/src/analysis/trace-summary.js +261 -0
  22. package/dist/src/analysis/trace-summary.js.map +1 -0
  23. package/dist/src/commands/agents-commands.d.ts +24 -0
  24. package/dist/src/commands/agents-commands.d.ts.map +1 -0
  25. package/dist/src/commands/agents-commands.js +284 -0
  26. package/dist/src/commands/agents-commands.js.map +1 -0
  27. package/dist/src/commands/handler.d.ts.map +1 -1
  28. package/dist/src/commands/handler.js +329 -21
  29. package/dist/src/commands/handler.js.map +1 -1
  30. package/dist/src/commands/init-commands.d.ts +35 -0
  31. package/dist/src/commands/init-commands.d.ts.map +1 -0
  32. package/dist/src/commands/init-commands.js +187 -0
  33. package/dist/src/commands/init-commands.js.map +1 -0
  34. package/dist/src/commands/skills-commands.d.ts +26 -0
  35. package/dist/src/commands/skills-commands.d.ts.map +1 -0
  36. package/dist/src/commands/skills-commands.js +309 -0
  37. package/dist/src/commands/skills-commands.js.map +1 -0
  38. package/dist/src/commands/types.d.ts +13 -2
  39. package/dist/src/commands/types.d.ts.map +1 -1
  40. package/dist/src/config.d.ts +3 -0
  41. package/dist/src/config.d.ts.map +1 -1
  42. package/dist/src/config.js.map +1 -1
  43. package/dist/src/defaults.d.ts +31 -2
  44. package/dist/src/defaults.d.ts.map +1 -1
  45. package/dist/src/defaults.js +69 -2
  46. package/dist/src/defaults.js.map +1 -1
  47. package/dist/src/errors/index.d.ts +233 -0
  48. package/dist/src/errors/index.d.ts.map +1 -0
  49. package/dist/src/errors/index.js +427 -0
  50. package/dist/src/errors/index.js.map +1 -0
  51. package/dist/src/integrations/agent-registry.d.ts +68 -2
  52. package/dist/src/integrations/agent-registry.d.ts.map +1 -1
  53. package/dist/src/integrations/agent-registry.js +230 -23
  54. package/dist/src/integrations/agent-registry.js.map +1 -1
  55. package/dist/src/integrations/auto-compaction.d.ts +33 -0
  56. package/dist/src/integrations/auto-compaction.d.ts.map +1 -1
  57. package/dist/src/integrations/auto-compaction.js +47 -3
  58. package/dist/src/integrations/auto-compaction.js.map +1 -1
  59. package/dist/src/integrations/cancellation.d.ts +5 -0
  60. package/dist/src/integrations/cancellation.d.ts.map +1 -1
  61. package/dist/src/integrations/cancellation.js +7 -0
  62. package/dist/src/integrations/cancellation.js.map +1 -1
  63. package/dist/src/integrations/capabilities.d.ts +160 -0
  64. package/dist/src/integrations/capabilities.d.ts.map +1 -0
  65. package/dist/src/integrations/capabilities.js +426 -0
  66. package/dist/src/integrations/capabilities.js.map +1 -0
  67. package/dist/src/integrations/context-engineering.d.ts +6 -1
  68. package/dist/src/integrations/context-engineering.d.ts.map +1 -1
  69. package/dist/src/integrations/context-engineering.js +7 -0
  70. package/dist/src/integrations/context-engineering.js.map +1 -1
  71. package/dist/src/integrations/dead-letter-queue.d.ts +208 -0
  72. package/dist/src/integrations/dead-letter-queue.d.ts.map +1 -0
  73. package/dist/src/integrations/dead-letter-queue.js +458 -0
  74. package/dist/src/integrations/dead-letter-queue.js.map +1 -0
  75. package/dist/src/integrations/health-check.d.ts +218 -0
  76. package/dist/src/integrations/health-check.d.ts.map +1 -0
  77. package/dist/src/integrations/health-check.js +400 -0
  78. package/dist/src/integrations/health-check.js.map +1 -0
  79. package/dist/src/integrations/index.d.ts +11 -2
  80. package/dist/src/integrations/index.d.ts.map +1 -1
  81. package/dist/src/integrations/index.js +19 -2
  82. package/dist/src/integrations/index.js.map +1 -1
  83. package/dist/src/integrations/mcp-client.d.ts +9 -0
  84. package/dist/src/integrations/mcp-client.d.ts.map +1 -1
  85. package/dist/src/integrations/mcp-client.js +49 -7
  86. package/dist/src/integrations/mcp-client.js.map +1 -1
  87. package/dist/src/integrations/openrouter-pricing.d.ts +28 -3
  88. package/dist/src/integrations/openrouter-pricing.d.ts.map +1 -1
  89. package/dist/src/integrations/openrouter-pricing.js +57 -16
  90. package/dist/src/integrations/openrouter-pricing.js.map +1 -1
  91. package/dist/src/integrations/retry.d.ts +131 -0
  92. package/dist/src/integrations/retry.d.ts.map +1 -0
  93. package/dist/src/integrations/retry.js +233 -0
  94. package/dist/src/integrations/retry.js.map +1 -0
  95. package/dist/src/integrations/skill-executor.d.ts +113 -0
  96. package/dist/src/integrations/skill-executor.d.ts.map +1 -0
  97. package/dist/src/integrations/skill-executor.js +270 -0
  98. package/dist/src/integrations/skill-executor.js.map +1 -0
  99. package/dist/src/integrations/skills.d.ts +98 -7
  100. package/dist/src/integrations/skills.d.ts.map +1 -1
  101. package/dist/src/integrations/skills.js +210 -11
  102. package/dist/src/integrations/skills.js.map +1 -1
  103. package/dist/src/integrations/sqlite-store.d.ts +42 -0
  104. package/dist/src/integrations/sqlite-store.d.ts.map +1 -1
  105. package/dist/src/integrations/sqlite-store.js +111 -0
  106. package/dist/src/integrations/sqlite-store.js.map +1 -1
  107. package/dist/src/main.js +88 -7
  108. package/dist/src/main.js.map +1 -1
  109. package/dist/src/modes/repl.d.ts.map +1 -1
  110. package/dist/src/modes/repl.js +37 -1
  111. package/dist/src/modes/repl.js.map +1 -1
  112. package/dist/src/modes/tui.d.ts.map +1 -1
  113. package/dist/src/modes/tui.js +46 -5
  114. package/dist/src/modes/tui.js.map +1 -1
  115. package/dist/src/modes.d.ts.map +1 -1
  116. package/dist/src/modes.js +10 -3
  117. package/dist/src/modes.js.map +1 -1
  118. package/dist/src/persistence/schema.d.ts +4 -0
  119. package/dist/src/persistence/schema.d.ts.map +1 -1
  120. package/dist/src/persistence/schema.js +49 -0
  121. package/dist/src/persistence/schema.js.map +1 -1
  122. package/dist/src/providers/adapters/anthropic.d.ts +24 -2
  123. package/dist/src/providers/adapters/anthropic.d.ts.map +1 -1
  124. package/dist/src/providers/adapters/anthropic.js +184 -0
  125. package/dist/src/providers/adapters/anthropic.js.map +1 -1
  126. package/dist/src/tools/bash.d.ts.map +1 -1
  127. package/dist/src/tools/bash.js +7 -4
  128. package/dist/src/tools/bash.js.map +1 -1
  129. package/dist/src/tools/file.d.ts.map +1 -1
  130. package/dist/src/tools/file.js +31 -10
  131. package/dist/src/tools/file.js.map +1 -1
  132. package/dist/src/tools/permission.d.ts +12 -0
  133. package/dist/src/tools/permission.d.ts.map +1 -1
  134. package/dist/src/tools/permission.js +136 -0
  135. package/dist/src/tools/permission.js.map +1 -1
  136. package/dist/src/tools/registry.d.ts +23 -1
  137. package/dist/src/tools/registry.d.ts.map +1 -1
  138. package/dist/src/tools/registry.js +77 -17
  139. package/dist/src/tools/registry.js.map +1 -1
  140. package/dist/src/tools/standard.d.ts.map +1 -1
  141. package/dist/src/tools/standard.js +8 -0
  142. package/dist/src/tools/standard.js.map +1 -1
  143. package/dist/src/tools/types.d.ts +20 -1
  144. package/dist/src/tools/types.d.ts.map +1 -1
  145. package/dist/src/tools/types.js.map +1 -1
  146. package/dist/src/tracing/trace-collector.d.ts +198 -2
  147. package/dist/src/tracing/trace-collector.d.ts.map +1 -1
  148. package/dist/src/tracing/trace-collector.js +315 -3
  149. package/dist/src/tracing/trace-collector.js.map +1 -1
  150. package/dist/src/tracing/types.d.ts +470 -2
  151. package/dist/src/tracing/types.d.ts.map +1 -1
  152. package/dist/src/tracing/types.js +25 -0
  153. package/dist/src/tracing/types.js.map +1 -1
  154. package/dist/src/tui/app.d.ts.map +1 -1
  155. package/dist/src/tui/app.js +292 -18
  156. package/dist/src/tui/app.js.map +1 -1
  157. package/dist/src/tui/index.d.ts +1 -0
  158. package/dist/src/tui/index.d.ts.map +1 -1
  159. package/dist/src/tui/index.js +2 -0
  160. package/dist/src/tui/index.js.map +1 -1
  161. package/dist/src/tui/transparency-aggregator.d.ts +100 -0
  162. package/dist/src/tui/transparency-aggregator.d.ts.map +1 -0
  163. package/dist/src/tui/transparency-aggregator.js +234 -0
  164. package/dist/src/tui/transparency-aggregator.js.map +1 -0
  165. package/dist/src/types.d.ts +129 -0
  166. package/dist/src/types.d.ts.map +1 -1
  167. package/package.json +6 -3
  168. package/dist/src/hello.d.ts +0 -2
  169. package/dist/src/hello.d.ts.map +0 -1
  170. package/dist/src/hello.js +0 -4
  171. package/dist/src/hello.js.map +0 -1
  172. package/dist/src/test-sqlite.d.ts +0 -2
  173. package/dist/src/test-sqlite.d.ts.map +0 -1
  174. package/dist/src/test-sqlite.js +0 -114
  175. package/dist/src/test-sqlite.js.map +0 -1
@@ -5,9 +5,10 @@
5
5
  * for accurate cost estimation.
6
6
  */
7
7
  // =============================================================================
8
- // PRICING CACHE
8
+ // MODEL INFO CACHE
9
9
  // =============================================================================
10
10
  let pricingCache = new Map();
11
+ let contextLengthCache = new Map();
11
12
  let cacheTimestamp = 0;
12
13
  const CACHE_TTL = 3600000; // 1 hour
13
14
  // Default fallback pricing - conservative mid-tier estimate
@@ -19,17 +20,14 @@ const DEFAULT_PRICING = {
19
20
  request: 0,
20
21
  image: 0,
21
22
  };
22
- // =============================================================================
23
- // FETCH PRICING
24
- // =============================================================================
25
23
  /**
26
- * Fetch pricing data from OpenRouter API.
24
+ * Fetch model data (pricing + context lengths) from OpenRouter API.
27
25
  */
28
- export async function fetchOpenRouterPricing() {
26
+ export async function fetchOpenRouterModels() {
29
27
  const apiKey = process.env.OPENROUTER_API_KEY;
30
28
  if (!apiKey) {
31
- console.log('⚠️ No OPENROUTER_API_KEY - using default pricing estimates');
32
- return new Map();
29
+ console.log('⚠️ No OPENROUTER_API_KEY - using default estimates');
30
+ return { pricing: new Map(), contextLengths: new Map() };
33
31
  }
34
32
  try {
35
33
  const response = await fetch('https://openrouter.ai/api/v1/models', {
@@ -43,6 +41,7 @@ export async function fetchOpenRouterPricing() {
43
41
  }
44
42
  const data = await response.json();
45
43
  const pricing = new Map();
44
+ const contextLengths = new Map();
46
45
  for (const model of data.data) {
47
46
  pricing.set(model.id, {
48
47
  prompt: parseFloat(model.pricing.prompt) || 0,
@@ -50,30 +49,48 @@ export async function fetchOpenRouterPricing() {
50
49
  request: parseFloat(model.pricing.request || '0'),
51
50
  image: parseFloat(model.pricing.image || '0'),
52
51
  });
52
+ // Store context length
53
+ if (model.context_length) {
54
+ contextLengths.set(model.id, model.context_length);
55
+ }
53
56
  }
54
- return pricing;
57
+ return { pricing, contextLengths };
55
58
  }
56
59
  catch (error) {
57
- console.log(`⚠️ Failed to fetch OpenRouter pricing: ${error.message}`);
58
- return new Map();
60
+ console.log(`⚠️ Failed to fetch OpenRouter models: ${error.message}`);
61
+ return { pricing: new Map(), contextLengths: new Map() };
59
62
  }
60
63
  }
61
64
  /**
62
- * Initialize or refresh the pricing cache.
65
+ * @deprecated Use fetchOpenRouterModels() instead
63
66
  */
64
- export async function initPricingCache() {
67
+ export async function fetchOpenRouterPricing() {
68
+ const { pricing } = await fetchOpenRouterModels();
69
+ return pricing;
70
+ }
71
+ /**
72
+ * Initialize or refresh the model info cache (pricing + context lengths).
73
+ */
74
+ export async function initModelCache() {
65
75
  const now = Date.now();
66
76
  // Only refresh if cache is stale
67
77
  if (pricingCache.size > 0 && (now - cacheTimestamp) < CACHE_TTL) {
68
78
  return;
69
79
  }
70
- const pricing = await fetchOpenRouterPricing();
80
+ const { pricing, contextLengths } = await fetchOpenRouterModels();
71
81
  if (pricing.size > 0) {
72
82
  pricingCache = pricing;
83
+ contextLengthCache = contextLengths;
73
84
  cacheTimestamp = now;
74
- console.log(`💰 Loaded pricing for ${pricing.size} models from OpenRouter`);
85
+ console.log(`💰 Loaded ${pricing.size} models from OpenRouter (pricing + context limits)`);
75
86
  }
76
87
  }
88
+ /**
89
+ * @deprecated Use initModelCache() instead
90
+ */
91
+ export async function initPricingCache() {
92
+ return initModelCache();
93
+ }
77
94
  // =============================================================================
78
95
  // PRICING LOOKUP
79
96
  // =============================================================================
@@ -95,6 +112,30 @@ export function getModelPricing(modelId) {
95
112
  // Return default
96
113
  return DEFAULT_PRICING;
97
114
  }
115
+ /**
116
+ * Get context length (max tokens) for a specific model.
117
+ * Returns undefined if the model is not in the cache.
118
+ */
119
+ export function getModelContextLength(modelId) {
120
+ // Direct lookup
121
+ if (contextLengthCache.has(modelId)) {
122
+ return contextLengthCache.get(modelId);
123
+ }
124
+ // Try without provider prefix (e.g., "gpt-4" instead of "openai/gpt-4")
125
+ const shortId = modelId.split('/').pop() || modelId;
126
+ for (const [id, contextLength] of contextLengthCache) {
127
+ if (id.endsWith(shortId) || id.includes(shortId)) {
128
+ return contextLength;
129
+ }
130
+ }
131
+ return undefined;
132
+ }
133
+ /**
134
+ * Check if model cache has been initialized.
135
+ */
136
+ export function isModelCacheInitialized() {
137
+ return pricingCache.size > 0;
138
+ }
98
139
  /**
99
140
  * Calculate cost for a completion.
100
141
  */
@@ -120,5 +161,5 @@ export function formatCost(cost) {
120
161
  // =============================================================================
121
162
  // EXPORTS
122
163
  // =============================================================================
123
- export { pricingCache, DEFAULT_PRICING };
164
+ export { pricingCache, contextLengthCache, DEFAULT_PRICING };
124
165
  //# sourceMappingURL=openrouter-pricing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"openrouter-pricing.js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AC,IAAI,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,gCAAgC;IAC7E,CAAC;IACD,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/B,CAAC;AAED,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Generic Retry Utility
3
+ *
4
+ * Provides configurable retry logic with exponential backoff for transient failures.
5
+ * Used by tools, MCP client, and other operations that may encounter temporary errors.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const result = await withRetry(
10
+ * () => fetchData(),
11
+ * {
12
+ * maxAttempts: 3,
13
+ * baseDelayMs: 1000,
14
+ * retryableErrors: ['ETIMEDOUT', 'ECONNRESET'],
15
+ * }
16
+ * );
17
+ * ```
18
+ */
19
+ /**
20
+ * Configuration for retry behavior.
21
+ */
22
+ export interface RetryConfig {
23
+ /** Maximum number of attempts (including initial) */
24
+ maxAttempts: number;
25
+ /** Base delay between retries in milliseconds (default: 1000) */
26
+ baseDelayMs?: number;
27
+ /** Maximum delay between retries in milliseconds (default: 30000) */
28
+ maxDelayMs?: number;
29
+ /** Multiplier for exponential backoff (default: 2) */
30
+ backoffMultiplier?: number;
31
+ /** Add random jitter to delays (default: true) */
32
+ jitter?: boolean;
33
+ /** Error message patterns that are retryable */
34
+ retryableErrors?: string[];
35
+ /** Error codes that are retryable (e.g., 'ETIMEDOUT', 'ECONNRESET') */
36
+ retryableCodes?: string[];
37
+ /** Custom function to determine if error is retryable */
38
+ isRetryable?: (error: Error) => boolean;
39
+ /** Callback on each retry attempt */
40
+ onRetry?: (attempt: number, error: Error, delayMs: number) => void;
41
+ /** Callback when all attempts exhausted */
42
+ onExhausted?: (attempts: number, lastError: Error) => void;
43
+ }
44
+ /**
45
+ * Result of a retry operation.
46
+ */
47
+ export interface RetryResult<T> {
48
+ /** Whether the operation succeeded */
49
+ success: boolean;
50
+ /** The result value (if successful) */
51
+ value?: T;
52
+ /** The error (if failed) */
53
+ error?: Error;
54
+ /** Number of attempts made */
55
+ attempts: number;
56
+ /** Total time spent (including delays) */
57
+ totalTimeMs: number;
58
+ }
59
+ /**
60
+ * Default retryable error patterns.
61
+ * These are common transient errors that often resolve on retry.
62
+ */
63
+ export declare const DEFAULT_RETRYABLE_ERRORS: string[];
64
+ /**
65
+ * Default retryable error codes.
66
+ */
67
+ export declare const DEFAULT_RETRYABLE_CODES: string[];
68
+ /**
69
+ * Execute a function with retry logic.
70
+ *
71
+ * @param fn - The async function to execute
72
+ * @param config - Retry configuration
73
+ * @returns Promise resolving to the result or throwing the last error
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // Basic usage with defaults
78
+ * const data = await withRetry(() => fetchData(), { maxAttempts: 3 });
79
+ *
80
+ * // With custom config
81
+ * const data = await withRetry(
82
+ * () => unreliableApi(),
83
+ * {
84
+ * maxAttempts: 5,
85
+ * baseDelayMs: 500,
86
+ * backoffMultiplier: 1.5,
87
+ * retryableErrors: ['timeout'],
88
+ * onRetry: (attempt, err) => console.log(`Retry ${attempt}: ${err.message}`),
89
+ * }
90
+ * );
91
+ * ```
92
+ */
93
+ export declare function withRetry<T>(fn: () => Promise<T>, config: RetryConfig): Promise<T>;
94
+ /**
95
+ * Execute a function with retry and return detailed result.
96
+ *
97
+ * Unlike withRetry, this never throws - it returns a result object
98
+ * that indicates success or failure.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const result = await withRetryResult(() => unreliableOp(), { maxAttempts: 3 });
103
+ * if (result.success) {
104
+ * console.log('Got:', result.value);
105
+ * } else {
106
+ * console.log('Failed after', result.attempts, 'attempts:', result.error);
107
+ * }
108
+ * ```
109
+ */
110
+ export declare function withRetryResult<T>(fn: () => Promise<T>, config: RetryConfig): Promise<RetryResult<T>>;
111
+ /**
112
+ * Retry config for tool execution.
113
+ * Conservative: 2 attempts, short delays.
114
+ */
115
+ export declare const TOOL_RETRY_CONFIG: Omit<RetryConfig, 'maxAttempts'>;
116
+ /**
117
+ * Retry config for MCP calls.
118
+ * More aggressive: 3 attempts, longer delays.
119
+ */
120
+ export declare const MCP_RETRY_CONFIG: Omit<RetryConfig, 'maxAttempts'>;
121
+ /**
122
+ * Retry config for file operations.
123
+ * Short delays, handles busy files.
124
+ */
125
+ export declare const FILE_RETRY_CONFIG: Omit<RetryConfig, 'maxAttempts'>;
126
+ /**
127
+ * Retry config for network operations.
128
+ * Standard exponential backoff.
129
+ */
130
+ export declare const NETWORK_RETRY_CONFIG: Omit<RetryConfig, 'maxAttempts'>;
131
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/integrations/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IAEpB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,sDAAsD;IACtD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,kDAAkD;IAClD,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,gDAAgD;IAChD,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B,uEAAuE;IACvE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,yDAAyD;IACzD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC;IAExC,qCAAqC;IACrC,OAAO,CAAC,EAAE,CAAC,OA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AC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,IAAI,CAAC,WAAW,EAAE,aAAa,CAMjE,CAAC"}
@@ -0,0 +1,233 @@
1
+ /**
2
+ * Generic Retry Utility
3
+ *
4
+ * Provides configurable retry logic with exponential backoff for transient failures.
5
+ * Used by tools, MCP client, and other operations that may encounter temporary errors.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const result = await withRetry(
10
+ * () => fetchData(),
11
+ * {
12
+ * maxAttempts: 3,
13
+ * baseDelayMs: 1000,
14
+ * retryableErrors: ['ETIMEDOUT', 'ECONNRESET'],
15
+ * }
16
+ * );
17
+ * ```
18
+ */
19
+ /**
20
+ * Default retryable error patterns.
21
+ * These are common transient errors that often resolve on retry.
22
+ */
23
+ export const DEFAULT_RETRYABLE_ERRORS = [
24
+ 'ETIMEDOUT',
25
+ 'ECONNRESET',
26
+ 'ECONNREFUSED',
27
+ 'ENOTFOUND',
28
+ 'EPIPE',
29
+ 'EBUSY',
30
+ 'timeout',
31
+ 'socket hang up',
32
+ 'network error',
33
+ 'temporarily unavailable',
34
+ 'service unavailable',
35
+ 'rate limit',
36
+ ];
37
+ /**
38
+ * Default retryable error codes.
39
+ */
40
+ export const DEFAULT_RETRYABLE_CODES = [
41
+ 'ETIMEDOUT',
42
+ 'ECONNRESET',
43
+ 'ECONNREFUSED',
44
+ 'ENOTFOUND',
45
+ 'EPIPE',
46
+ 'EBUSY',
47
+ 'EAGAIN',
48
+ 'ENETUNREACH',
49
+ 'EHOSTUNREACH',
50
+ ];
51
+ // =============================================================================
52
+ // RETRY IMPLEMENTATION
53
+ // =============================================================================
54
+ /**
55
+ * Execute a function with retry logic.
56
+ *
57
+ * @param fn - The async function to execute
58
+ * @param config - Retry configuration
59
+ * @returns Promise resolving to the result or throwing the last error
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * // Basic usage with defaults
64
+ * const data = await withRetry(() => fetchData(), { maxAttempts: 3 });
65
+ *
66
+ * // With custom config
67
+ * const data = await withRetry(
68
+ * () => unreliableApi(),
69
+ * {
70
+ * maxAttempts: 5,
71
+ * baseDelayMs: 500,
72
+ * backoffMultiplier: 1.5,
73
+ * retryableErrors: ['timeout'],
74
+ * onRetry: (attempt, err) => console.log(`Retry ${attempt}: ${err.message}`),
75
+ * }
76
+ * );
77
+ * ```
78
+ */
79
+ export async function withRetry(fn, config) {
80
+ const { maxAttempts, baseDelayMs = 1000, maxDelayMs = 30000, backoffMultiplier = 2, jitter = true, retryableErrors = DEFAULT_RETRYABLE_ERRORS, retryableCodes = DEFAULT_RETRYABLE_CODES, isRetryable, onRetry, onExhausted, } = config;
81
+ let lastError;
82
+ let attempt = 0;
83
+ while (attempt < maxAttempts) {
84
+ attempt++;
85
+ try {
86
+ return await fn();
87
+ }
88
+ catch (error) {
89
+ lastError = error;
90
+ // Check if this is the last attempt
91
+ if (attempt >= maxAttempts) {
92
+ onExhausted?.(attempt, lastError);
93
+ throw lastError;
94
+ }
95
+ // Check if error is retryable
96
+ if (!shouldRetry(lastError, retryableErrors, retryableCodes, isRetryable)) {
97
+ throw lastError;
98
+ }
99
+ // Calculate delay with exponential backoff
100
+ let delay = Math.min(baseDelayMs * Math.pow(backoffMultiplier, attempt - 1), maxDelayMs);
101
+ // Add jitter (±25%)
102
+ if (jitter) {
103
+ const jitterAmount = delay * 0.25;
104
+ delay += (Math.random() - 0.5) * 2 * jitterAmount;
105
+ delay = Math.max(0, delay);
106
+ }
107
+ onRetry?.(attempt, lastError, delay);
108
+ // Wait before retry
109
+ await sleep(delay);
110
+ }
111
+ }
112
+ // Should never reach here, but TypeScript needs this
113
+ throw lastError ?? new Error('Retry failed');
114
+ }
115
+ /**
116
+ * Execute a function with retry and return detailed result.
117
+ *
118
+ * Unlike withRetry, this never throws - it returns a result object
119
+ * that indicates success or failure.
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const result = await withRetryResult(() => unreliableOp(), { maxAttempts: 3 });
124
+ * if (result.success) {
125
+ * console.log('Got:', result.value);
126
+ * } else {
127
+ * console.log('Failed after', result.attempts, 'attempts:', result.error);
128
+ * }
129
+ * ```
130
+ */
131
+ export async function withRetryResult(fn, config) {
132
+ const startTime = Date.now();
133
+ let attempts = 0;
134
+ try {
135
+ const result = await withRetry(async () => {
136
+ attempts++;
137
+ return await fn();
138
+ }, config);
139
+ return {
140
+ success: true,
141
+ value: result,
142
+ attempts,
143
+ totalTimeMs: Date.now() - startTime,
144
+ };
145
+ }
146
+ catch (error) {
147
+ return {
148
+ success: false,
149
+ error: error,
150
+ attempts,
151
+ totalTimeMs: Date.now() - startTime,
152
+ };
153
+ }
154
+ }
155
+ // =============================================================================
156
+ // HELPERS
157
+ // =============================================================================
158
+ /**
159
+ * Determine if an error should trigger a retry.
160
+ */
161
+ function shouldRetry(error, retryableErrors, retryableCodes, customIsRetryable) {
162
+ // Custom check takes precedence
163
+ if (customIsRetryable) {
164
+ return customIsRetryable(error);
165
+ }
166
+ // Check error code
167
+ const code = error.code;
168
+ if (code && retryableCodes.includes(code)) {
169
+ return true;
170
+ }
171
+ // Check error message patterns
172
+ const message = error.message.toLowerCase();
173
+ for (const pattern of retryableErrors) {
174
+ if (message.includes(pattern.toLowerCase())) {
175
+ return true;
176
+ }
177
+ }
178
+ return false;
179
+ }
180
+ /**
181
+ * Sleep for a specified duration.
182
+ */
183
+ function sleep(ms) {
184
+ return new Promise(resolve => setTimeout(resolve, ms));
185
+ }
186
+ // =============================================================================
187
+ // SPECIALIZED RETRY CONFIGS
188
+ // =============================================================================
189
+ /**
190
+ * Retry config for tool execution.
191
+ * Conservative: 2 attempts, short delays.
192
+ */
193
+ export const TOOL_RETRY_CONFIG = {
194
+ baseDelayMs: 500,
195
+ maxDelayMs: 5000,
196
+ backoffMultiplier: 2,
197
+ retryableCodes: ['ETIMEDOUT', 'ECONNRESET', 'EBUSY', 'EAGAIN'],
198
+ retryableErrors: ['timeout', 'temporarily unavailable'],
199
+ };
200
+ /**
201
+ * Retry config for MCP calls.
202
+ * More aggressive: 3 attempts, longer delays.
203
+ */
204
+ export const MCP_RETRY_CONFIG = {
205
+ baseDelayMs: 1000,
206
+ maxDelayMs: 10000,
207
+ backoffMultiplier: 2,
208
+ retryableCodes: DEFAULT_RETRYABLE_CODES,
209
+ retryableErrors: ['timeout', 'socket hang up', 'connection reset'],
210
+ };
211
+ /**
212
+ * Retry config for file operations.
213
+ * Short delays, handles busy files.
214
+ */
215
+ export const FILE_RETRY_CONFIG = {
216
+ baseDelayMs: 100,
217
+ maxDelayMs: 2000,
218
+ backoffMultiplier: 2,
219
+ retryableCodes: ['EBUSY', 'EAGAIN', 'EMFILE', 'ENFILE'],
220
+ retryableErrors: ['resource busy', 'too many open files'],
221
+ };
222
+ /**
223
+ * Retry config for network operations.
224
+ * Standard exponential backoff.
225
+ */
226
+ export const NETWORK_RETRY_CONFIG = {
227
+ baseDelayMs: 1000,
228
+ maxDelayMs: 30000,
229
+ backoffMultiplier: 2,
230
+ retryableCodes: DEFAULT_RETRYABLE_CODES,
231
+ retryableErrors: DEFAULT_RETRYABLE_ERRORS,
232
+ };
233
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../src/integrations/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA6DH;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,WAAW;IACX,YAAY;IACZ,cAAc;IACd,WAAW;IACX,OAAO;IACP,OAAO;IACP,SAAS;IACT,gBAAgB;IAChB,eAAe;IACf,yBAAyB;IACzB,qBAAqB;IACrB,YAAY;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,WAAW;IACX,YAAY;IACZ,cAAc;IACd,WAAW;IACX,OAAO;IACP,OAAO;IACP,QAAQ;IACR,aAAa;IACb,cAAc;CACf,CAAC;AAEF,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEh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,GAAG;IAChB,UAAU,EAAE,IAAI;IAChB,iBAAiB,EAAE,CAAC;IACpB,cAAc,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC;IACvD,eAAe,EAAE,CAAC,eAAe,EAAE,qBAAqB,CAAC;CAC1D,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAqC;IACpE,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,KAAK;IACjB,iBAAiB,EAAE,CAAC;IACpB,cAAc,EAAE,uBAAuB;IACvC,eAAe,EAAE,wBAAwB;CAC1C,CAAC"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Skill Executor
3
+ *
4
+ * Handles invocation of skills with argument parsing and template substitution.
5
+ * Skills can be invoked like commands: /review --file src/main.ts --focus security
6
+ */
7
+ import type { Skill, SkillManager } from './skills.js';
8
+ /**
9
+ * Parsed arguments from command line input.
10
+ */
11
+ export interface ParsedArgs {
12
+ /** Named arguments (--name value or -n value) */
13
+ named: Record<string, unknown>;
14
+ /** Positional arguments (remaining after named) */
15
+ positional: string[];
16
+ /** Any parsing errors */
17
+ errors: string[];
18
+ }
19
+ /**
20
+ * Context provided during skill execution.
21
+ */
22
+ export interface SkillExecutionContext {
23
+ /** Current working directory */
24
+ cwd: string;
25
+ /** Session ID */
26
+ sessionId?: string;
27
+ /** Current conversation context (for prompt injection) */
28
+ conversationContext?: string;
29
+ /** Callback to run agent with injected prompt */
30
+ runWithPrompt?: (prompt: string) => Promise<SkillExecutionResult>;
31
+ }
32
+ /**
33
+ * Result of skill execution.
34
+ */
35
+ export interface SkillExecutionResult {
36
+ /** Whether execution succeeded */
37
+ success: boolean;
38
+ /** Result message or output */
39
+ output: string;
40
+ /** Injected prompt for the agent (if prompt-injection mode) */
41
+ injectedPrompt?: string;
42
+ /** Error message if failed */
43
+ error?: string;
44
+ }
45
+ /**
46
+ * Skill execution event types.
47
+ */
48
+ export type SkillExecutorEvent = {
49
+ type: 'skill.invoke.start';
50
+ skillName: string;
51
+ args: string[];
52
+ } | {
53
+ type: 'skill.invoke.parsed';
54
+ skillName: string;
55
+ parsed: ParsedArgs;
56
+ } | {
57
+ type: 'skill.invoke.complete';
58
+ skillName: string;
59
+ result: SkillExecutionResult;
60
+ } | {
61
+ type: 'skill.invoke.error';
62
+ skillName: string;
63
+ error: string;
64
+ };
65
+ export type SkillExecutorEventListener = (event: SkillExecutorEvent) => void;
66
+ /**
67
+ * Executes invokable skills with argument parsing and template substitution.
68
+ */
69
+ export declare class SkillExecutor {
70
+ private skillManager;
71
+ private eventListeners;
72
+ constructor(skillManager: SkillManager);
73
+ /**
74
+ * Check if an input string is a potential skill invocation.
75
+ * Returns the skill name if it matches, null otherwise.
76
+ */
77
+ isSkillInvocation(input: string): string | null;
78
+ /**
79
+ * Parse command-line style arguments.
80
+ */
81
+ parseArguments(skill: Skill, rawArgs: string[]): ParsedArgs;
82
+ /**
83
+ * Substitute template variables in skill content.
84
+ * Variables are in the form {{name}} or {{name|default}}.
85
+ */
86
+ substituteTemplate(content: string, args: ParsedArgs): string;
87
+ /**
88
+ * Execute a skill by name with arguments.
89
+ */
90
+ executeSkill(skillName: string, rawArgs: string[], ctx: SkillExecutionContext): Promise<SkillExecutionResult>;
91
+ /**
92
+ * Build the prompt to inject based on skill content and arguments.
93
+ */
94
+ private buildInjectedPrompt;
95
+ /**
96
+ * Format help text for a skill.
97
+ */
98
+ formatSkillHelp(skill: Skill): string;
99
+ /**
100
+ * Get all invokable skills.
101
+ */
102
+ getInvokableSkills(): Skill[];
103
+ /**
104
+ * Subscribe to executor events.
105
+ */
106
+ subscribe(listener: SkillExecutorEventListener): () => void;
107
+ private emit;
108
+ }
109
+ /**
110
+ * Create a skill executor.
111
+ */
112
+ export declare function createSkillExecutor(skillManager: SkillManager): SkillExecutor;
113
+ //# sourceMappingURL=skill-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-executor.d.ts","sourceRoot":"","sources":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