@insureco/cli 0.1.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 (174) hide show
  1. package/README.md +168 -0
  2. package/dist/commands/backup.d.ts +11 -0
  3. package/dist/commands/backup.d.ts.map +1 -0
  4. package/dist/commands/backup.js +112 -0
  5. package/dist/commands/backup.js.map +1 -0
  6. package/dist/commands/config.d.ts +10 -0
  7. package/dist/commands/config.d.ts.map +1 -0
  8. package/dist/commands/config.js +41 -0
  9. package/dist/commands/config.js.map +1 -0
  10. package/dist/commands/deploy.d.ts +16 -0
  11. package/dist/commands/deploy.d.ts.map +1 -0
  12. package/dist/commands/deploy.js +219 -0
  13. package/dist/commands/deploy.js.map +1 -0
  14. package/dist/commands/destroy.d.ts +12 -0
  15. package/dist/commands/destroy.d.ts.map +1 -0
  16. package/dist/commands/destroy.js +62 -0
  17. package/dist/commands/destroy.js.map +1 -0
  18. package/dist/commands/env.d.ts +7 -0
  19. package/dist/commands/env.d.ts.map +1 -0
  20. package/dist/commands/env.js +42 -0
  21. package/dist/commands/env.js.map +1 -0
  22. package/dist/commands/init-ai.d.ts +7 -0
  23. package/dist/commands/init-ai.d.ts.map +1 -0
  24. package/dist/commands/init-ai.js +257 -0
  25. package/dist/commands/init-ai.js.map +1 -0
  26. package/dist/commands/init.d.ts +8 -0
  27. package/dist/commands/init.d.ts.map +1 -0
  28. package/dist/commands/init.js +228 -0
  29. package/dist/commands/init.js.map +1 -0
  30. package/dist/commands/link.d.ts +10 -0
  31. package/dist/commands/link.d.ts.map +1 -0
  32. package/dist/commands/link.js +193 -0
  33. package/dist/commands/link.js.map +1 -0
  34. package/dist/commands/login.d.ts +8 -0
  35. package/dist/commands/login.d.ts.map +1 -0
  36. package/dist/commands/login.js +164 -0
  37. package/dist/commands/login.js.map +1 -0
  38. package/dist/commands/logs.d.ts +16 -0
  39. package/dist/commands/logs.d.ts.map +1 -0
  40. package/dist/commands/logs.js +362 -0
  41. package/dist/commands/logs.js.map +1 -0
  42. package/dist/commands/preflight.d.ts +8 -0
  43. package/dist/commands/preflight.d.ts.map +1 -0
  44. package/dist/commands/preflight.js +188 -0
  45. package/dist/commands/preflight.js.map +1 -0
  46. package/dist/commands/program.d.ts +7 -0
  47. package/dist/commands/program.d.ts.map +1 -0
  48. package/dist/commands/program.js +59 -0
  49. package/dist/commands/program.js.map +1 -0
  50. package/dist/commands/push.d.ts +12 -0
  51. package/dist/commands/push.d.ts.map +1 -0
  52. package/dist/commands/push.js +171 -0
  53. package/dist/commands/push.js.map +1 -0
  54. package/dist/commands/register.d.ts +7 -0
  55. package/dist/commands/register.d.ts.map +1 -0
  56. package/dist/commands/register.js +124 -0
  57. package/dist/commands/register.js.map +1 -0
  58. package/dist/commands/rollback.d.ts +11 -0
  59. package/dist/commands/rollback.d.ts.map +1 -0
  60. package/dist/commands/rollback.js +172 -0
  61. package/dist/commands/rollback.js.map +1 -0
  62. package/dist/commands/sample.d.ts +11 -0
  63. package/dist/commands/sample.d.ts.map +1 -0
  64. package/dist/commands/sample.js +114 -0
  65. package/dist/commands/sample.js.map +1 -0
  66. package/dist/commands/services.d.ts +13 -0
  67. package/dist/commands/services.d.ts.map +1 -0
  68. package/dist/commands/services.js +95 -0
  69. package/dist/commands/services.js.map +1 -0
  70. package/dist/commands/status.d.ts +9 -0
  71. package/dist/commands/status.d.ts.map +1 -0
  72. package/dist/commands/status.js +170 -0
  73. package/dist/commands/status.js.map +1 -0
  74. package/dist/commands/troubleshoot.d.ts +19 -0
  75. package/dist/commands/troubleshoot.d.ts.map +1 -0
  76. package/dist/commands/troubleshoot.js +465 -0
  77. package/dist/commands/troubleshoot.js.map +1 -0
  78. package/dist/commands/versions.d.ts +16 -0
  79. package/dist/commands/versions.d.ts.map +1 -0
  80. package/dist/commands/versions.js +162 -0
  81. package/dist/commands/versions.js.map +1 -0
  82. package/dist/index.d.ts +3 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +294 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/lib/ai/client.d.ts +36 -0
  87. package/dist/lib/ai/client.d.ts.map +1 -0
  88. package/dist/lib/ai/client.js +140 -0
  89. package/dist/lib/ai/client.js.map +1 -0
  90. package/dist/lib/ai/generator.d.ts +17 -0
  91. package/dist/lib/ai/generator.d.ts.map +1 -0
  92. package/dist/lib/ai/generator.js +338 -0
  93. package/dist/lib/ai/generator.js.map +1 -0
  94. package/dist/lib/ai/prompts.d.ts +47 -0
  95. package/dist/lib/ai/prompts.d.ts.map +1 -0
  96. package/dist/lib/ai/prompts.js +247 -0
  97. package/dist/lib/ai/prompts.js.map +1 -0
  98. package/dist/lib/ai/scanner.d.ts +50 -0
  99. package/dist/lib/ai/scanner.d.ts.map +1 -0
  100. package/dist/lib/ai/scanner.js +237 -0
  101. package/dist/lib/ai/scanner.js.map +1 -0
  102. package/dist/lib/api.d.ts +18 -0
  103. package/dist/lib/api.d.ts.map +1 -0
  104. package/dist/lib/api.js +67 -0
  105. package/dist/lib/api.js.map +1 -0
  106. package/dist/lib/builder.d.ts +34 -0
  107. package/dist/lib/builder.d.ts.map +1 -0
  108. package/dist/lib/builder.js +132 -0
  109. package/dist/lib/builder.js.map +1 -0
  110. package/dist/lib/config.d.ts +20 -0
  111. package/dist/lib/config.d.ts.map +1 -0
  112. package/dist/lib/config.js +124 -0
  113. package/dist/lib/config.js.map +1 -0
  114. package/dist/lib/output.d.ts +12 -0
  115. package/dist/lib/output.d.ts.map +1 -0
  116. package/dist/lib/output.js +39 -0
  117. package/dist/lib/output.js.map +1 -0
  118. package/dist/lib/scaffold.d.ts +29 -0
  119. package/dist/lib/scaffold.d.ts.map +1 -0
  120. package/dist/lib/scaffold.js +166 -0
  121. package/dist/lib/scaffold.js.map +1 -0
  122. package/dist/lib/troubleshoot/analyzer.d.ts +14 -0
  123. package/dist/lib/troubleshoot/analyzer.d.ts.map +1 -0
  124. package/dist/lib/troubleshoot/analyzer.js +541 -0
  125. package/dist/lib/troubleshoot/analyzer.js.map +1 -0
  126. package/dist/lib/troubleshoot/auto-fix.d.ts +29 -0
  127. package/dist/lib/troubleshoot/auto-fix.d.ts.map +1 -0
  128. package/dist/lib/troubleshoot/auto-fix.js +373 -0
  129. package/dist/lib/troubleshoot/auto-fix.js.map +1 -0
  130. package/dist/lib/troubleshoot/index.d.ts +5 -0
  131. package/dist/lib/troubleshoot/index.d.ts.map +1 -0
  132. package/dist/lib/troubleshoot/index.js +6 -0
  133. package/dist/lib/troubleshoot/index.js.map +1 -0
  134. package/dist/lib/troubleshoot/log-fetcher.d.ts +43 -0
  135. package/dist/lib/troubleshoot/log-fetcher.d.ts.map +1 -0
  136. package/dist/lib/troubleshoot/log-fetcher.js +431 -0
  137. package/dist/lib/troubleshoot/log-fetcher.js.map +1 -0
  138. package/dist/lib/troubleshoot/redactor.d.ts +35 -0
  139. package/dist/lib/troubleshoot/redactor.d.ts.map +1 -0
  140. package/dist/lib/troubleshoot/redactor.js +208 -0
  141. package/dist/lib/troubleshoot/redactor.js.map +1 -0
  142. package/dist/lib/validators/catalog-validator.d.ts +3 -0
  143. package/dist/lib/validators/catalog-validator.d.ts.map +1 -0
  144. package/dist/lib/validators/catalog-validator.js +205 -0
  145. package/dist/lib/validators/catalog-validator.js.map +1 -0
  146. package/dist/lib/validators/dockerfile-validator.d.ts +4 -0
  147. package/dist/lib/validators/dockerfile-validator.d.ts.map +1 -0
  148. package/dist/lib/validators/dockerfile-validator.js +262 -0
  149. package/dist/lib/validators/dockerfile-validator.js.map +1 -0
  150. package/dist/lib/validators/env-validator.d.ts +3 -0
  151. package/dist/lib/validators/env-validator.d.ts.map +1 -0
  152. package/dist/lib/validators/env-validator.js +268 -0
  153. package/dist/lib/validators/env-validator.js.map +1 -0
  154. package/dist/lib/validators/git-validator.d.ts +3 -0
  155. package/dist/lib/validators/git-validator.d.ts.map +1 -0
  156. package/dist/lib/validators/git-validator.js +236 -0
  157. package/dist/lib/validators/git-validator.js.map +1 -0
  158. package/dist/lib/validators/health-detector.d.ts +4 -0
  159. package/dist/lib/validators/health-detector.d.ts.map +1 -0
  160. package/dist/lib/validators/health-detector.js +159 -0
  161. package/dist/lib/validators/health-detector.js.map +1 -0
  162. package/dist/lib/validators/index.d.ts +7 -0
  163. package/dist/lib/validators/index.d.ts.map +1 -0
  164. package/dist/lib/validators/index.js +7 -0
  165. package/dist/lib/validators/index.js.map +1 -0
  166. package/dist/lib/validators/route-validator.d.ts +3 -0
  167. package/dist/lib/validators/route-validator.d.ts.map +1 -0
  168. package/dist/lib/validators/route-validator.js +238 -0
  169. package/dist/lib/validators/route-validator.js.map +1 -0
  170. package/dist/types/index.d.ts +455 -0
  171. package/dist/types/index.d.ts.map +1 -0
  172. package/dist/types/index.js +37 -0
  173. package/dist/types/index.js.map +1 -0
  174. package/package.json +58 -0
@@ -0,0 +1,541 @@
1
+ import { ClaudeClient } from '../ai/client.js';
2
+ const TROUBLESHOOT_SYSTEM_PROMPT = `You are an AI assistant that helps diagnose and fix issues in the InsurEco Tawa platform. You analyze logs, pod status, and events to identify problems and provide actionable recommendations.
3
+
4
+ ## About IEC Platform
5
+
6
+ The IEC platform is a Kubernetes-based internal developer platform with these key components:
7
+
8
+ 1. **Koko** - Service registry that stores service metadata, routes, and OAuth configurations
9
+ 2. **Janus** - API gateway that proxies requests and handles authentication/authorization
10
+ 3. **Bio-ID** - Authentication/identity provider using OAuth 2.0
11
+ 4. **iec-builder** - CI/CD system that builds and deploys services
12
+ 5. **Helm Charts** - Each service has a Helm chart for Kubernetes deployment
13
+
14
+ ## Common Issues and Solutions
15
+
16
+ ### 1. 403 Forbidden - Missing Scopes
17
+ **Symptoms:** Logs show "insufficient_scope" or "forbidden" errors when calling other services
18
+ **Solution:** Add required scopes to catalog-info.yaml under spec.oauth.scopes, then run \`iec register --force\`
19
+
20
+ ### 2. 404 Not Found - Service Not Registered
21
+ **Symptoms:** Requests to /api/{service}/* return 404, Janus logs show "upstream not found"
22
+ **Solution:** Register the service with \`iec register\` to add it to Koko
23
+
24
+ ### 3. 502/503 Bad Gateway - Upstream Down
25
+ **Symptoms:** Intermittent failures, Janus logs show "connection refused" or "upstream timeout"
26
+ **Solution:** Check if upstream service is running, check pod health, review resource limits
27
+
28
+ ### 4. Connection Refused - DNS Not Propagated
29
+ **Symptoms:** New deployments fail to connect to services, DNS resolution errors
30
+ **Solution:** Wait for DNS propagation, verify service exists in Kubernetes, check namespace
31
+
32
+ ### 5. OOMKilled - Memory Limits Too Low
33
+ **Symptoms:** Pod restarts with reason "OOMKilled", sudden terminations under load
34
+ **Solution:** Increase memory limits in Helm values.yaml
35
+
36
+ ### 6. CrashLoopBackOff - Health Check Failing
37
+ **Symptoms:** Pod continuously restarts, liveness probe failures in events
38
+ **Solution:** Fix /health endpoint, check startup time, adjust probe timings
39
+
40
+ ### 7. Authentication Failure
41
+ **Symptoms:** 401 errors, "invalid_token" or "token_expired" in logs
42
+ **Solution:** Verify OAuth configuration, check token expiration, validate credentials
43
+
44
+ ### 8. Rate Limited
45
+ **Symptoms:** 429 errors, "rate_limit_exceeded" in responses
46
+ **Solution:** Implement backoff, review rate limit configuration in catalog-info.yaml
47
+
48
+ ## Your Task
49
+
50
+ 1. Analyze the provided logs, pod status, and events
51
+ 2. Identify specific issues and their root causes
52
+ 3. Provide actionable recommendations with auto-fix options where possible
53
+ 4. Prioritize recommendations by severity and impact
54
+
55
+ Use the provided tools to report your findings.`;
56
+ const TROUBLESHOOT_TOOLS = [
57
+ {
58
+ name: 'report_issue',
59
+ description: 'Report a detected issue from log analysis',
60
+ input_schema: {
61
+ type: 'object',
62
+ properties: {
63
+ type: {
64
+ type: 'string',
65
+ enum: [
66
+ 'missing_scope',
67
+ 'service_not_registered',
68
+ 'upstream_down',
69
+ 'dns_not_propagated',
70
+ 'oom_killed',
71
+ 'crash_loop',
72
+ 'health_check_failure',
73
+ 'connection_refused',
74
+ 'authentication_failure',
75
+ 'rate_limited',
76
+ 'unknown',
77
+ ],
78
+ description: 'The type of issue detected',
79
+ },
80
+ severity: {
81
+ type: 'string',
82
+ enum: ['critical', 'high', 'medium', 'low'],
83
+ description: 'Severity of the issue',
84
+ },
85
+ title: {
86
+ type: 'string',
87
+ description: 'Short title describing the issue',
88
+ },
89
+ description: {
90
+ type: 'string',
91
+ description: 'Detailed description of the issue and its impact',
92
+ },
93
+ evidence: {
94
+ type: 'array',
95
+ items: { type: 'string' },
96
+ description: 'Log lines or events that support this finding',
97
+ },
98
+ affectedService: {
99
+ type: 'string',
100
+ description: 'Primary service affected by this issue',
101
+ },
102
+ relatedServices: {
103
+ type: 'array',
104
+ items: { type: 'string' },
105
+ description: 'Other services involved in this issue',
106
+ },
107
+ },
108
+ required: ['type', 'severity', 'title', 'description', 'evidence', 'affectedService'],
109
+ },
110
+ },
111
+ {
112
+ name: 'recommend_fix',
113
+ description: 'Recommend a fix for an identified issue',
114
+ input_schema: {
115
+ type: 'object',
116
+ properties: {
117
+ priority: {
118
+ type: 'number',
119
+ description: 'Priority ranking (1 = highest priority)',
120
+ },
121
+ title: {
122
+ type: 'string',
123
+ description: 'Short title for the recommendation',
124
+ },
125
+ description: {
126
+ type: 'string',
127
+ description: 'Detailed explanation of what to do and why',
128
+ },
129
+ actionType: {
130
+ type: 'string',
131
+ enum: [
132
+ 'add_scope',
133
+ 'register_service',
134
+ 'update_catalog',
135
+ 'update_helm_values',
136
+ 'redeploy',
137
+ 'check_upstream',
138
+ 'increase_memory',
139
+ 'fix_health_endpoint',
140
+ 'manual',
141
+ ],
142
+ description: 'Type of fix action',
143
+ },
144
+ actionParams: {
145
+ type: 'object',
146
+ description: 'Parameters specific to the action type',
147
+ },
148
+ autoFixAvailable: {
149
+ type: 'boolean',
150
+ description: 'Whether this fix can be applied automatically',
151
+ },
152
+ estimatedImpact: {
153
+ type: 'string',
154
+ description: 'Expected improvement after applying this fix',
155
+ },
156
+ },
157
+ required: [
158
+ 'priority',
159
+ 'title',
160
+ 'description',
161
+ 'actionType',
162
+ 'autoFixAvailable',
163
+ 'estimatedImpact',
164
+ ],
165
+ },
166
+ },
167
+ {
168
+ name: 'complete_analysis',
169
+ description: 'Signal that analysis is complete and provide overall status',
170
+ input_schema: {
171
+ type: 'object',
172
+ properties: {
173
+ status: {
174
+ type: 'string',
175
+ enum: ['healthy', 'degraded', 'unhealthy'],
176
+ description: 'Overall health status of the service',
177
+ },
178
+ summary: {
179
+ type: 'string',
180
+ description: 'Brief summary of the analysis findings',
181
+ },
182
+ },
183
+ required: ['status', 'summary'],
184
+ },
185
+ },
186
+ ];
187
+ /**
188
+ * Parse tool calls from Claude response into structured results
189
+ */
190
+ function parseToolResults(toolUses) {
191
+ const result = {
192
+ issues: [],
193
+ recommendations: [],
194
+ };
195
+ for (const toolUse of toolUses) {
196
+ const input = toolUse.input;
197
+ switch (toolUse.name) {
198
+ case 'report_issue':
199
+ result.issues.push({
200
+ type: input.type,
201
+ severity: input.severity,
202
+ title: input.title,
203
+ description: input.description,
204
+ evidence: input.evidence,
205
+ affectedService: input.affectedService,
206
+ relatedServices: input.relatedServices,
207
+ });
208
+ break;
209
+ case 'recommend_fix':
210
+ const actionType = input.actionType;
211
+ const actionParams = input.actionParams || {};
212
+ result.recommendations.push({
213
+ id: `rec-${Date.now()}-${result.recommendations.length}`,
214
+ priority: input.priority,
215
+ title: input.title,
216
+ description: input.description,
217
+ action: buildAction(actionType, actionParams),
218
+ autoFixAvailable: input.autoFixAvailable,
219
+ estimatedImpact: input.estimatedImpact,
220
+ });
221
+ break;
222
+ case 'complete_analysis':
223
+ result.status = input.status;
224
+ result.summary = input.summary;
225
+ break;
226
+ }
227
+ }
228
+ // Sort recommendations by priority
229
+ result.recommendations.sort((a, b) => a.priority - b.priority);
230
+ return result;
231
+ }
232
+ /**
233
+ * Build a TroubleshootAction from tool parameters
234
+ */
235
+ function buildAction(actionType, params) {
236
+ switch (actionType) {
237
+ case 'add_scope':
238
+ return {
239
+ type: 'add_scope',
240
+ scope: params.scope || '',
241
+ service: params.service || '',
242
+ };
243
+ case 'register_service':
244
+ return {
245
+ type: 'register_service',
246
+ serviceName: params.serviceName || '',
247
+ };
248
+ case 'update_catalog':
249
+ return {
250
+ type: 'update_catalog',
251
+ field: params.field || '',
252
+ value: params.value,
253
+ };
254
+ case 'update_helm_values':
255
+ return {
256
+ type: 'update_helm_values',
257
+ path: params.path || '',
258
+ value: params.value,
259
+ };
260
+ case 'redeploy':
261
+ return {
262
+ type: 'redeploy',
263
+ environment: params.environment || 'sandbox',
264
+ };
265
+ case 'check_upstream':
266
+ return {
267
+ type: 'check_upstream',
268
+ upstream: params.upstream || '',
269
+ };
270
+ case 'increase_memory':
271
+ return {
272
+ type: 'increase_memory',
273
+ currentLimit: params.currentLimit || '',
274
+ suggestedLimit: params.suggestedLimit || '',
275
+ };
276
+ case 'fix_health_endpoint':
277
+ return {
278
+ type: 'fix_health_endpoint',
279
+ path: params.path || '/health',
280
+ };
281
+ case 'manual':
282
+ default:
283
+ return {
284
+ type: 'manual',
285
+ instructions: params.instructions || 'Review the issue manually',
286
+ };
287
+ }
288
+ }
289
+ /**
290
+ * Format logs timeline for AI analysis
291
+ */
292
+ function formatLogsForAnalysis(timeline) {
293
+ const lines = [];
294
+ lines.push(`## Log Timeline (${timeline.startTime} to ${timeline.endTime})`);
295
+ lines.push(`Services involved: ${timeline.services.join(', ')}`);
296
+ lines.push('');
297
+ // Group by service
298
+ const byService = new Map();
299
+ for (const entry of timeline.entries) {
300
+ const entries = byService.get(entry.service) || [];
301
+ entries.push(entry);
302
+ byService.set(entry.service, entries);
303
+ }
304
+ for (const [service, entries] of byService) {
305
+ lines.push(`### ${service}`);
306
+ // Show only error and warning entries, plus a sample of info
307
+ const significant = entries.filter((e) => e.level === 'error' || e.level === 'fatal' || e.level === 'warn');
308
+ const infoSample = entries
309
+ .filter((e) => e.level === 'info')
310
+ .slice(-10); // Last 10 info entries
311
+ const toShow = [...significant, ...infoSample].sort((a, b) => {
312
+ return new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime();
313
+ });
314
+ for (const entry of toShow) {
315
+ const meta = entry.metadata
316
+ ? ` ${JSON.stringify(entry.metadata)}`
317
+ : '';
318
+ lines.push(`[${entry.timestamp}] ${entry.level.toUpperCase()} ${entry.message}${meta}`);
319
+ }
320
+ lines.push('');
321
+ }
322
+ return lines.join('\n');
323
+ }
324
+ /**
325
+ * Format context for AI analysis
326
+ */
327
+ function formatContextForAnalysis(context) {
328
+ const lines = [];
329
+ lines.push('## Service Context');
330
+ lines.push(`Service: ${context.service.name}`);
331
+ if (context.service.upstream) {
332
+ lines.push(`Upstream: ${context.service.upstream}`);
333
+ }
334
+ if (context.service.routes && context.service.routes.length > 0) {
335
+ lines.push(`Routes: ${context.service.routes.map((r) => r.path).join(', ')}`);
336
+ }
337
+ lines.push('');
338
+ if (context.recentBuilds.length > 0) {
339
+ lines.push('## Recent Builds');
340
+ for (const build of context.recentBuilds) {
341
+ lines.push(`- ${build.id}: ${build.status} (${build.createdAt})`);
342
+ }
343
+ lines.push('');
344
+ }
345
+ if (context.dependencies.length > 0) {
346
+ lines.push(`## Dependencies: ${context.dependencies.join(', ')}`);
347
+ lines.push('');
348
+ }
349
+ if (context.podStatus && context.podStatus.length > 0) {
350
+ lines.push('## Pod Status');
351
+ for (const pod of context.podStatus) {
352
+ const reason = pod.reason ? ` (${pod.reason})` : '';
353
+ lines.push(`- ${pod.name}: ${pod.status}, ready=${pod.ready}, restarts=${pod.restarts}${reason}`);
354
+ }
355
+ lines.push('');
356
+ }
357
+ if (context.recentEvents && context.recentEvents.length > 0) {
358
+ lines.push('## Recent Events');
359
+ for (const event of context.recentEvents) {
360
+ lines.push(`- [${event.type}] ${event.reason}: ${event.message}`);
361
+ }
362
+ lines.push('');
363
+ }
364
+ return lines.join('\n');
365
+ }
366
+ /**
367
+ * Analyze logs and context using Claude
368
+ */
369
+ export async function analyzeLogs(timeline, context, environment) {
370
+ const claude = await ClaudeClient.create();
371
+ // Format data for analysis
372
+ const logsText = formatLogsForAnalysis(timeline);
373
+ const contextText = formatContextForAnalysis(context);
374
+ const userMessage = `Please analyze the following service logs and context to identify issues and provide recommendations.
375
+
376
+ Environment: ${environment}
377
+
378
+ ${contextText}
379
+
380
+ ${logsText}
381
+
382
+ Analyze these logs for:
383
+ 1. Error patterns and their root causes
384
+ 2. Connection or communication issues with other services
385
+ 3. Resource constraints (memory, CPU)
386
+ 4. Health check or startup problems
387
+ 5. Authentication/authorization failures
388
+
389
+ Use the report_issue tool to report each issue found.
390
+ Use the recommend_fix tool to provide actionable recommendations.
391
+ Use the complete_analysis tool when finished to summarize.`;
392
+ claude.addUserMessage(userMessage);
393
+ const response = await claude.sendMessage(TROUBLESHOOT_SYSTEM_PROMPT, TROUBLESHOOT_TOOLS);
394
+ // Process tool uses
395
+ const toolUses = claude.getToolUses(response);
396
+ // If Claude wants to use tools, process them
397
+ if (toolUses.length > 0) {
398
+ // Provide tool results (acknowledge receipt)
399
+ const toolResults = toolUses.map((t) => ({
400
+ toolUseId: t.id,
401
+ result: 'Acknowledged',
402
+ }));
403
+ claude.addToolResults(toolResults);
404
+ // Parse the results
405
+ const analysisResult = parseToolResults(toolUses);
406
+ return {
407
+ timestamp: new Date().toISOString(),
408
+ service: context.service.name,
409
+ environment,
410
+ status: analysisResult.status || determineStatus(analysisResult.issues),
411
+ issues: analysisResult.issues,
412
+ recommendations: analysisResult.recommendations,
413
+ context,
414
+ };
415
+ }
416
+ // Fallback: if no tools were used, return a healthy result
417
+ return {
418
+ timestamp: new Date().toISOString(),
419
+ service: context.service.name,
420
+ environment,
421
+ status: 'healthy',
422
+ issues: [],
423
+ recommendations: [],
424
+ context,
425
+ };
426
+ }
427
+ /**
428
+ * Determine overall status from issues
429
+ */
430
+ function determineStatus(issues) {
431
+ if (issues.length === 0) {
432
+ return 'healthy';
433
+ }
434
+ const hasCritical = issues.some((i) => i.severity === 'critical');
435
+ const hasHigh = issues.some((i) => i.severity === 'high');
436
+ if (hasCritical) {
437
+ return 'unhealthy';
438
+ }
439
+ if (hasHigh) {
440
+ return 'degraded';
441
+ }
442
+ return 'degraded';
443
+ }
444
+ /**
445
+ * Quick analysis without full AI - pattern matching for common issues
446
+ */
447
+ export function quickAnalysis(timeline, context) {
448
+ const issues = [];
449
+ // Check for OOMKilled
450
+ if (context.podStatus) {
451
+ for (const pod of context.podStatus) {
452
+ if (pod.reason === 'OOMKilled') {
453
+ issues.push({
454
+ type: 'oom_killed',
455
+ severity: 'critical',
456
+ title: `Pod ${pod.name} killed due to out of memory`,
457
+ description: 'The container exceeded its memory limit and was terminated by Kubernetes.',
458
+ evidence: [`Pod status: ${pod.status}, reason: ${pod.reason}`],
459
+ affectedService: context.service.name,
460
+ });
461
+ }
462
+ if (pod.restarts > 5) {
463
+ issues.push({
464
+ type: 'crash_loop',
465
+ severity: 'high',
466
+ title: `Pod ${pod.name} has restarted ${pod.restarts} times`,
467
+ description: 'Multiple restarts indicate the application is crashing repeatedly.',
468
+ evidence: [`Restart count: ${pod.restarts}`],
469
+ affectedService: context.service.name,
470
+ });
471
+ }
472
+ }
473
+ }
474
+ // Check for health check failures in events
475
+ if (context.recentEvents) {
476
+ for (const event of context.recentEvents) {
477
+ if (event.reason === 'Unhealthy' &&
478
+ event.message.includes('Liveness probe failed')) {
479
+ issues.push({
480
+ type: 'health_check_failure',
481
+ severity: 'high',
482
+ title: 'Liveness probe failing',
483
+ description: 'The health endpoint is not responding correctly, causing pod restarts.',
484
+ evidence: [event.message],
485
+ affectedService: context.service.name,
486
+ });
487
+ }
488
+ }
489
+ }
490
+ // Check logs for common patterns
491
+ for (const entry of timeline.entries) {
492
+ if (entry.level === 'error' || entry.level === 'fatal') {
493
+ const msg = entry.message.toLowerCase();
494
+ if (msg.includes('insufficient_scope') ||
495
+ msg.includes('missing scope') ||
496
+ msg.includes('forbidden')) {
497
+ const existing = issues.find((i) => i.type === 'missing_scope');
498
+ if (!existing) {
499
+ issues.push({
500
+ type: 'missing_scope',
501
+ severity: 'high',
502
+ title: 'Missing OAuth scopes for cross-service calls',
503
+ description: 'The service is trying to call another service but lacks the required OAuth scopes.',
504
+ evidence: [entry.message],
505
+ affectedService: entry.service,
506
+ });
507
+ }
508
+ }
509
+ if (msg.includes('econnrefused') ||
510
+ msg.includes('connection refused')) {
511
+ const existing = issues.find((i) => i.type === 'connection_refused');
512
+ if (!existing) {
513
+ issues.push({
514
+ type: 'connection_refused',
515
+ severity: 'critical',
516
+ title: 'Connection refused to upstream service',
517
+ description: 'Cannot connect to a required service. It may be down or DNS may not have propagated.',
518
+ evidence: [entry.message],
519
+ affectedService: entry.service,
520
+ });
521
+ }
522
+ }
523
+ if (msg.includes('rate limit') || msg.includes('too many requests')) {
524
+ const existing = issues.find((i) => i.type === 'rate_limited');
525
+ if (!existing) {
526
+ issues.push({
527
+ type: 'rate_limited',
528
+ severity: 'medium',
529
+ title: 'Rate limited by upstream service',
530
+ description: 'Requests are being throttled. Consider implementing backoff or increasing limits.',
531
+ evidence: [entry.message],
532
+ affectedService: entry.service,
533
+ });
534
+ }
535
+ }
536
+ }
537
+ }
538
+ return issues;
539
+ }
540
+ export { TROUBLESHOOT_SYSTEM_PROMPT, TROUBLESHOOT_TOOLS };
541
+ //# sourceMappingURL=analyzer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../../../src/lib/troubleshoot/analyzer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAY9C,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gDAqDa,CAAA;AAEhD,MAAM,kBAAkB,GAAW;IACjC;QACE,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,2CAA2C;QACxD,YAAY,EAAE;YACZ,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE;wBACJ,eAAe;wBACf,wBAAwB;wBACxB,eAAe;wBACf,oB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;wBACpB,QAAQ,EAAE,QAAQ;wBAClB,KAAK,EAAE,kCAAkC;wBACzC,WAAW,EACT,mFAAmF;wBACrF,QAAQ,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;wBACzB,eAAe,EAAE,KAAK,CAAC,OAAO;qBAC/B,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,CAAA"}
@@ -0,0 +1,29 @@
1
+ import type { TroubleshootAction, TroubleshootRecommendation, FixPreview } from '../../types/index.js';
2
+ /**
3
+ * Generate a preview of changes for a fix action
4
+ */
5
+ export declare function previewFix(recommendation: TroubleshootRecommendation, projectDir?: string): Promise<FixPreview>;
6
+ /**
7
+ * Apply a fix after user confirmation
8
+ */
9
+ export declare function applyFix(preview: FixPreview, projectDir?: string): Promise<{
10
+ success: boolean;
11
+ error?: string;
12
+ }>;
13
+ /**
14
+ * Format a fix preview for display
15
+ */
16
+ export declare function formatPreview(preview: FixPreview): string;
17
+ /**
18
+ * Get all auto-fixable recommendations
19
+ */
20
+ export declare function getAutoFixableRecommendations(recommendations: TroubleshootRecommendation[]): TroubleshootRecommendation[];
21
+ /**
22
+ * Explain what a fix will do
23
+ */
24
+ export declare function explainFix(action: TroubleshootAction): string;
25
+ /**
26
+ * Check if we can auto-fix an action type
27
+ */
28
+ export declare function canAutoFix(action: TroubleshootAction): boolean;
29
+ //# sourceMappingURL=auto-fix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-fix.d.ts","sourceRoot":"","sources":["../../../src/lib/troubleshoot/auto-fix.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,kBAAkB,EAClB,0BAA0B,EAC1B,UAAU,EAGX,MAAM,sBAAsB,CAAA;AAU7B;;GAEG;AACH,wBAAsB,UAAU,CAC9B,cAAc,EAAE,0BAA0B,EAC1C,UAAU,GAAE,MAAsB,GACjC,OAAO,CAAC,UAAU,CAAC,CAyErB;AAmLD;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,UAAU,EACnB,UAAU,GAAE,MAAsB,GACjC,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAuC/C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CA4CzD;AAmCD;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,0BAA0B,EAAE,GAC5C,0BAA0B,EAAE,CAE9B;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAgC7D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAkB9D"}