@vfarcic/dot-ai 0.4.9 → 0.5.1

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 (145) hide show
  1. package/.claude/commands/context-load.md +11 -0
  2. package/.claude/commands/context-save.md +16 -0
  3. package/.claude/commands/prd-done.md +115 -0
  4. package/.claude/commands/prd-get.md +25 -0
  5. package/.claude/commands/prd-start.md +87 -0
  6. package/.claude/commands/task-done.md +77 -0
  7. package/.claude/commands/tests-reminder.md +32 -0
  8. package/.claude/settings.local.json +20 -0
  9. package/.eslintrc.json +25 -0
  10. package/.github/workflows/ci.yml +170 -0
  11. package/.prettierrc.json +10 -0
  12. package/.teller.yml +8 -0
  13. package/CLAUDE.md +162 -0
  14. package/assets/images/logo.png +0 -0
  15. package/bin/dot-ai.ts +47 -0
  16. package/destroy.sh +45 -0
  17. package/devbox.json +13 -0
  18. package/devbox.lock +225 -0
  19. package/docs/API.md +449 -0
  20. package/docs/CONTEXT.md +49 -0
  21. package/docs/DEVELOPMENT.md +203 -0
  22. package/docs/NEXT_STEPS.md +97 -0
  23. package/docs/STAGE_BASED_API.md +97 -0
  24. package/docs/cli-guide.md +798 -0
  25. package/docs/design.md +750 -0
  26. package/docs/discovery-engine.md +515 -0
  27. package/docs/error-handling.md +429 -0
  28. package/docs/function-registration.md +157 -0
  29. package/docs/mcp-guide.md +416 -0
  30. package/package.json +2 -123
  31. package/renovate.json +51 -0
  32. package/setup.sh +111 -0
  33. package/{dist/cli.js → src/cli.ts} +26 -19
  34. package/src/core/claude.ts +280 -0
  35. package/src/core/deploy-operation.ts +127 -0
  36. package/src/core/discovery.ts +900 -0
  37. package/src/core/error-handling.ts +562 -0
  38. package/src/core/index.ts +143 -0
  39. package/src/core/kubernetes-utils.ts +218 -0
  40. package/src/core/memory.ts +148 -0
  41. package/src/core/schema.ts +830 -0
  42. package/src/core/session-utils.ts +97 -0
  43. package/src/core/workflow.ts +234 -0
  44. package/src/index.ts +18 -0
  45. package/src/interfaces/cli.ts +872 -0
  46. package/src/interfaces/mcp.ts +183 -0
  47. package/src/mcp/server.ts +131 -0
  48. package/src/tools/answer-question.ts +807 -0
  49. package/src/tools/choose-solution.ts +169 -0
  50. package/src/tools/deploy-manifests.ts +94 -0
  51. package/src/tools/generate-manifests.ts +502 -0
  52. package/src/tools/index.ts +41 -0
  53. package/src/tools/recommend.ts +370 -0
  54. package/tests/__mocks__/@kubernetes/client-node.ts +106 -0
  55. package/tests/build-system.test.ts +345 -0
  56. package/tests/configuration.test.ts +226 -0
  57. package/tests/core/deploy-operation.test.ts +38 -0
  58. package/tests/core/discovery.test.ts +1648 -0
  59. package/tests/core/error-handling.test.ts +632 -0
  60. package/tests/core/schema.test.ts +1658 -0
  61. package/tests/core/session-utils.test.ts +245 -0
  62. package/tests/core.test.ts +439 -0
  63. package/tests/fixtures/configmap-no-labels.yaml +8 -0
  64. package/tests/fixtures/crossplane-app-configuration.yaml +6 -0
  65. package/tests/fixtures/crossplane-providers.yaml +45 -0
  66. package/tests/fixtures/crossplane-rbac.yaml +48 -0
  67. package/tests/fixtures/invalid-configmap.yaml +8 -0
  68. package/tests/fixtures/invalid-deployment.yaml +17 -0
  69. package/tests/fixtures/test-deployment.yaml +28 -0
  70. package/tests/fixtures/valid-configmap.yaml +15 -0
  71. package/tests/infrastructure.test.ts +426 -0
  72. package/tests/interfaces/cli.test.ts +1036 -0
  73. package/tests/interfaces/mcp.test.ts +139 -0
  74. package/tests/kubernetes-utils.test.ts +200 -0
  75. package/tests/mcp/server.test.ts +126 -0
  76. package/tests/setup.ts +31 -0
  77. package/tests/tools/answer-question.test.ts +367 -0
  78. package/tests/tools/choose-solution.test.ts +481 -0
  79. package/tests/tools/deploy-manifests.test.ts +185 -0
  80. package/tests/tools/generate-manifests.test.ts +441 -0
  81. package/tests/tools/index.test.ts +111 -0
  82. package/tests/tools/recommend.test.ts +180 -0
  83. package/tsconfig.json +34 -0
  84. package/dist/cli.d.ts +0 -3
  85. package/dist/cli.d.ts.map +0 -1
  86. package/dist/core/claude.d.ts +0 -42
  87. package/dist/core/claude.d.ts.map +0 -1
  88. package/dist/core/claude.js +0 -229
  89. package/dist/core/deploy-operation.d.ts +0 -38
  90. package/dist/core/deploy-operation.d.ts.map +0 -1
  91. package/dist/core/deploy-operation.js +0 -101
  92. package/dist/core/discovery.d.ts +0 -162
  93. package/dist/core/discovery.d.ts.map +0 -1
  94. package/dist/core/discovery.js +0 -758
  95. package/dist/core/error-handling.d.ts +0 -167
  96. package/dist/core/error-handling.d.ts.map +0 -1
  97. package/dist/core/error-handling.js +0 -399
  98. package/dist/core/index.d.ts +0 -42
  99. package/dist/core/index.d.ts.map +0 -1
  100. package/dist/core/index.js +0 -123
  101. package/dist/core/kubernetes-utils.d.ts +0 -38
  102. package/dist/core/kubernetes-utils.d.ts.map +0 -1
  103. package/dist/core/kubernetes-utils.js +0 -177
  104. package/dist/core/memory.d.ts +0 -45
  105. package/dist/core/memory.d.ts.map +0 -1
  106. package/dist/core/memory.js +0 -113
  107. package/dist/core/schema.d.ts +0 -187
  108. package/dist/core/schema.d.ts.map +0 -1
  109. package/dist/core/schema.js +0 -655
  110. package/dist/core/session-utils.d.ts +0 -29
  111. package/dist/core/session-utils.d.ts.map +0 -1
  112. package/dist/core/session-utils.js +0 -121
  113. package/dist/core/workflow.d.ts +0 -70
  114. package/dist/core/workflow.d.ts.map +0 -1
  115. package/dist/core/workflow.js +0 -161
  116. package/dist/index.d.ts +0 -15
  117. package/dist/index.d.ts.map +0 -1
  118. package/dist/index.js +0 -32
  119. package/dist/interfaces/cli.d.ts +0 -74
  120. package/dist/interfaces/cli.d.ts.map +0 -1
  121. package/dist/interfaces/cli.js +0 -769
  122. package/dist/interfaces/mcp.d.ts +0 -30
  123. package/dist/interfaces/mcp.d.ts.map +0 -1
  124. package/dist/interfaces/mcp.js +0 -105
  125. package/dist/mcp/server.d.ts +0 -9
  126. package/dist/mcp/server.d.ts.map +0 -1
  127. package/dist/mcp/server.js +0 -151
  128. package/dist/tools/answer-question.d.ts +0 -27
  129. package/dist/tools/answer-question.d.ts.map +0 -1
  130. package/dist/tools/answer-question.js +0 -696
  131. package/dist/tools/choose-solution.d.ts +0 -23
  132. package/dist/tools/choose-solution.d.ts.map +0 -1
  133. package/dist/tools/choose-solution.js +0 -171
  134. package/dist/tools/deploy-manifests.d.ts +0 -25
  135. package/dist/tools/deploy-manifests.d.ts.map +0 -1
  136. package/dist/tools/deploy-manifests.js +0 -74
  137. package/dist/tools/generate-manifests.d.ts +0 -23
  138. package/dist/tools/generate-manifests.d.ts.map +0 -1
  139. package/dist/tools/generate-manifests.js +0 -424
  140. package/dist/tools/index.d.ts +0 -11
  141. package/dist/tools/index.d.ts.map +0 -1
  142. package/dist/tools/index.js +0 -34
  143. package/dist/tools/recommend.d.ts +0 -23
  144. package/dist/tools/recommend.d.ts.map +0 -1
  145. package/dist/tools/recommend.js +0 -332
package/docs/API.md ADDED
@@ -0,0 +1,449 @@
1
+ # API Reference
2
+
3
+ ## Programmatic Usage
4
+
5
+ ### Discovery Engine
6
+
7
+ ```typescript
8
+ import { KubernetesDiscovery } from './src/core/discovery';
9
+
10
+ const discovery = new KubernetesDiscovery({
11
+ kubeconfigPath: './kubeconfig.yaml'
12
+ });
13
+
14
+ await discovery.connect();
15
+
16
+ // Discover all available resources
17
+ const resources = await discovery.getAPIResources();
18
+ console.log(`Found ${resources.length} resources`);
19
+
20
+ // Get cluster fingerprint
21
+ const fingerprint = await discovery.fingerprintCluster();
22
+ console.log(`Cluster: ${fingerprint.platform} v${fingerprint.version}`);
23
+
24
+ // Analyze resource schema
25
+ const podSchema = await discovery.explainResource('Pod');
26
+ console.log(`Pod has ${podSchema.fields.length} fields`);
27
+ ```
28
+
29
+ ### AI-Powered Recommendations (Legacy - Use MCP Tools)
30
+
31
+ **Note: Direct programmatic access is available but the recommended approach is via MCP tools for conversational workflows.**
32
+
33
+ ```typescript
34
+ import { ResourceRecommender } from './src/core/schema';
35
+
36
+ // Get AI-powered resource recommendations (legacy approach)
37
+ const recommender = new ResourceRecommender({ claudeApiKey: 'your-key' });
38
+ const solutions = await recommender.findBestSolutions(
39
+ 'deploy a web application with scaling',
40
+ () => discovery.discoverResources(),
41
+ (resource) => discovery.explainResource(resource)
42
+ );
43
+
44
+ console.log(`Found ${solutions.length} solutions`);
45
+ console.log(`Best solution: ${solutions[0].description} (score: ${solutions[0].score})`);
46
+
47
+ // For interactive deployment, use MCP tools:
48
+ // recommend → chooseSolution → answerQuestion → generateManifests
49
+ ```
50
+
51
+ ## TypeScript Interfaces
52
+
53
+ ### Discovery Engine
54
+
55
+ ```typescript
56
+ class KubernetesDiscovery {
57
+ // Connection management
58
+ async connect(): Promise<void>
59
+ isConnected(): boolean
60
+
61
+ // Resource discovery
62
+ async getAPIResources(): Promise<EnhancedResource[]>
63
+ async discoverCRDs(): Promise<EnhancedCRD[]>
64
+ async discoverResources(): Promise<ResourceMap>
65
+
66
+ // Schema introspection
67
+ async explainResource(resource: string): Promise<ResourceExplanation>
68
+
69
+ // Cluster analysis
70
+ async getClusterInfo(): Promise<ClusterInfo>
71
+ async fingerprintCluster(): Promise<ClusterFingerprint>
72
+
73
+ // Configuration
74
+ getKubeconfigPath(): string
75
+ setKubeconfigPath(path: string): void
76
+ }
77
+ ```
78
+
79
+ ### Resource Recommendation
80
+
81
+ ```typescript
82
+ class ResourceRecommender {
83
+ constructor(config: AIRankingConfig)
84
+
85
+ async findBestSolutions(
86
+ intent: string,
87
+ discoverResourcesFn: () => Promise<any>,
88
+ explainResourceFn: (resource: string) => Promise<any>
89
+ ): Promise<ResourceSolution[]>
90
+ }
91
+
92
+ interface ResourceSolution {
93
+ id: string;
94
+ type: 'single' | 'combination';
95
+ resources: ResourceSchema[];
96
+ score: number;
97
+ description: string;
98
+ reasons: string[];
99
+ analysis: string;
100
+ questions: QuestionGroup;
101
+ }
102
+ ```
103
+
104
+ ### Stage-Based Workflow (Current)
105
+
106
+ ```typescript
107
+ // New stage-based workflow via MCP tools:
108
+ // 1. recommend: Get solutions
109
+ // 2. chooseSolution: Select preferred solution
110
+ // 3. answerQuestion: Progressive configuration (required → basic → advanced → open)
111
+ // 4. generateManifests: AI-generated Kubernetes YAML
112
+
113
+ // Legacy SolutionEnhancer (see /src/legacy/ directory for reference)
114
+ ```
115
+
116
+ interface QuestionGroup {
117
+ required: Question[];
118
+ basic: Question[];
119
+ advanced: Question[];
120
+ open: {
121
+ question: string;
122
+ placeholder: string;
123
+ answer?: string;
124
+ };
125
+ }
126
+ ```
127
+
128
+ ### Data Structures
129
+
130
+ ```typescript
131
+ interface EnhancedResource {
132
+ kind: string;
133
+ group: string;
134
+ version: string;
135
+ apiVersion: string;
136
+ namespaced: boolean;
137
+ verbs: string[];
138
+ shortNames?: string[];
139
+ categories?: string[];
140
+ }
141
+
142
+ interface EnhancedCRD {
143
+ name: string;
144
+ group: string;
145
+ version: string;
146
+ kind: string;
147
+ scope: 'Namespaced' | 'Cluster';
148
+ versions: Array<{
149
+ name: string;
150
+ served: boolean;
151
+ storage: boolean;
152
+ schema?: any;
153
+ }>;
154
+ }
155
+
156
+ interface ResourceExplanation {
157
+ kind: string;
158
+ version: string;
159
+ group: string;
160
+ description: string;
161
+ fields: Array<{
162
+ name: string;
163
+ type: string;
164
+ description: string;
165
+ required: boolean;
166
+ }>;
167
+ }
168
+
169
+ interface ClusterFingerprint {
170
+ version: string;
171
+ platform: string;
172
+ nodes: {
173
+ count: number;
174
+ architecture: string[];
175
+ operatingSystem: string[];
176
+ };
177
+ networking: {
178
+ cni: string;
179
+ serviceCIDR: string;
180
+ podCIDR: string;
181
+ };
182
+ storage: {
183
+ classes: string[];
184
+ defaultClass: string;
185
+ };
186
+ features: string[];
187
+ operators: string[];
188
+ }
189
+ ```
190
+
191
+ ## CLI Integration
192
+
193
+ ### Building CLI Applications
194
+
195
+ ```typescript
196
+ import { CliInterface } from './src/interfaces/cli';
197
+ import { DotAI } from './src/core';
198
+
199
+ const dotAI = new DotAI();
200
+ const cli = new CliInterface(dotAI);
201
+
202
+ // Execute commands programmatically
203
+ const result = await cli.executeCommand('discover', {
204
+ output: 'json'
205
+ });
206
+
207
+ if (result.success) {
208
+ console.log('Discovery results:', result.data);
209
+ } else {
210
+ console.error('Error:', result.error);
211
+ }
212
+ ```
213
+
214
+ ### Custom Command Handling
215
+
216
+ ```typescript
217
+ // Add custom command handling
218
+ cli.addCustomCommand('my-command', async (options) => {
219
+ const discovery = new KubernetesDiscovery();
220
+ await discovery.connect();
221
+
222
+ // Custom logic here
223
+ return {
224
+ success: true,
225
+ data: { message: 'Custom command executed' }
226
+ };
227
+ });
228
+ ```
229
+
230
+ ## MCP Server Integration
231
+
232
+ ### Starting MCP Server
233
+
234
+ ```typescript
235
+ import { McpInterface } from './src/interfaces/mcp';
236
+
237
+ const mcpServer = new McpInterface();
238
+ await mcpServer.start();
239
+
240
+ // Server provides discovery capabilities as structured tools
241
+ // Compatible with Cursor, Claude Code, and other MCP clients
242
+ ```
243
+
244
+ ### MCP Tools Available
245
+
246
+ **Stage-Based Deployment Workflow:**
247
+ - `recommend`: AI-powered resource recommendations based on intent
248
+ - `chooseSolution`: Select a solution and get configuration questions
249
+ - `answerQuestion`: Answer configuration questions progressively by stage
250
+ - `generateManifests`: Generate final Kubernetes YAML manifests
251
+
252
+ **Cluster Discovery:**
253
+ - `discover_resources`: Discover all cluster resources
254
+ - `explain_resource`: Get detailed resource schema
255
+ - `fingerprint_cluster`: Analyze cluster capabilities
256
+
257
+ ## Error Handling
258
+
259
+ ### Common Error Patterns
260
+
261
+ ```typescript
262
+ try {
263
+ const discovery = new KubernetesDiscovery();
264
+ await discovery.connect();
265
+ } catch (error) {
266
+ if (error.message.includes('ENOTFOUND')) {
267
+ console.error('Cannot connect to cluster - check kubeconfig');
268
+ } else if (error.message.includes('Unauthorized')) {
269
+ console.error('Authentication failed - check credentials');
270
+ } else {
271
+ console.error('Discovery failed:', error.message);
272
+ }
273
+ }
274
+ ```
275
+
276
+ ### Graceful Degradation
277
+
278
+ ```typescript
279
+ // Handle partial failures gracefully
280
+ const results = await discovery.discoverResources();
281
+
282
+ if (results.resources.length === 0) {
283
+ console.warn('No standard resources found');
284
+ }
285
+
286
+ if (results.custom.length === 0) {
287
+ console.warn('No custom resources found - limited operator support');
288
+ }
289
+
290
+ // Continue with available resources
291
+ ```
292
+
293
+ ## Stage-Based Deployment Workflow
294
+
295
+ ### Interactive Deployment Process
296
+
297
+ The new stage-based workflow provides a conversational approach to application deployment through progressive question answering.
298
+
299
+ #### Step 1: Get AI Recommendations
300
+
301
+ ```bash
302
+ # Start MCP server
303
+ npm run mcp:start
304
+
305
+ # Use MCP tools for conversational workflow
306
+ # recommend: Get AI-powered deployment recommendations
307
+ ```
308
+
309
+ **MCP Tool**: `recommend`
310
+ ```typescript
311
+ // Via MCP client (Claude Code, Cursor, etc.)
312
+ recommend({
313
+ intent: "deploy a web application with database"
314
+ })
315
+ // Returns: Array of ranked solutions with scores and descriptions
316
+ ```
317
+
318
+ #### Step 2: Choose Solution
319
+
320
+ ```typescript
321
+ // Select your preferred solution
322
+ chooseSolution({
323
+ solutionId: "sol_2025-07-01T123456_abc123def456"
324
+ })
325
+ // Returns: Configuration questions for the selected solution
326
+ ```
327
+
328
+ #### Step 3: Progressive Configuration
329
+
330
+ Answer questions in stages to build your deployment configuration:
331
+
332
+ **Required Stage:**
333
+ ```typescript
334
+ answerQuestion({
335
+ solutionId: "sol_2025-07-01T123456_abc123def456",
336
+ stage: "required",
337
+ answers: {
338
+ "name": "my-web-app",
339
+ "namespace": "production",
340
+ "image": "nginx:1.21",
341
+ "replicas": 3
342
+ }
343
+ })
344
+ ```
345
+
346
+ **Basic Stage:**
347
+ ```typescript
348
+ answerQuestion({
349
+ solutionId: "sol_2025-07-01T123456_abc123def456",
350
+ stage: "basic",
351
+ answers: {
352
+ "port": 8080,
353
+ "service-type": "ClusterIP",
354
+ "storage-size": "10Gi"
355
+ }
356
+ })
357
+ ```
358
+
359
+ **Advanced Stage:**
360
+ ```typescript
361
+ answerQuestion({
362
+ solutionId: "sol_2025-07-01T123456_abc123def456",
363
+ stage: "advanced",
364
+ answers: {
365
+ "scaling-enabled": true,
366
+ "resource-requests-cpu": "500m",
367
+ "resource-requests-memory": "512Mi"
368
+ }
369
+ })
370
+ ```
371
+
372
+ **Open Requirements:**
373
+ ```typescript
374
+ answerQuestion({
375
+ solutionId: "sol_2025-07-01T123456_abc123def456",
376
+ stage: "open",
377
+ answers: {
378
+ "open": "I need PostgreSQL database with 1000 RPS capacity and SSL termination"
379
+ }
380
+ })
381
+ ```
382
+
383
+ #### Step 4: Generate Manifests
384
+
385
+ ```typescript
386
+ generateManifests({
387
+ solutionId: "sol_2025-07-01T123456_abc123def456"
388
+ })
389
+ // Returns: Production-ready Kubernetes YAML manifests
390
+ ```
391
+
392
+ ### Benefits of Stage-Based Approach
393
+
394
+ **Progressive Disclosure:**
395
+ - Questions presented in logical order (required → basic → advanced → open)
396
+ - Users can skip stages they don't need to configure
397
+ - No overwhelming JSON construction required
398
+
399
+ **Better Error Recovery:**
400
+ - Clear guidance at each stage
401
+ - Validation happens per stage
402
+ - Easy to retry with corrections
403
+
404
+ **Conversational Flow:**
405
+ - Natural interaction pattern
406
+ - AI can provide context and suggestions
407
+ - Supports iterative refinement through open requirements
408
+
409
+ ### Session Management
410
+
411
+ Each deployment session is identified by a unique `solutionId` that maintains state across the workflow:
412
+
413
+ ```typescript
414
+ // Session data stored in DOT_AI_SESSION_DIR
415
+ // Contains solution configuration, answers, and generated manifests
416
+ // Enables resuming interrupted workflows
417
+ ```
418
+
419
+ ## Environment Configuration
420
+
421
+ ### Required Environment Variables
422
+
423
+ ```bash
424
+ # Optional: Custom kubeconfig location
425
+ export KUBECONFIG=/path/to/your/kubeconfig.yaml
426
+
427
+ # Required for AI features: Claude AI API key
428
+ export ANTHROPIC_API_KEY=your_api_key_here
429
+
430
+ # Optional: Debug logging
431
+ export DEBUG=dot-ai:*
432
+ ```
433
+
434
+ ### Configuration Options
435
+
436
+ ```typescript
437
+ interface DiscoveryConfig {
438
+ kubeconfigPath?: string;
439
+ timeout?: number;
440
+ retries?: number;
441
+ namespace?: string;
442
+ }
443
+
444
+ interface AIRankingConfig {
445
+ claudeApiKey: string;
446
+ model?: string;
447
+ timeout?: number;
448
+ }
449
+ ```
@@ -0,0 +1,49 @@
1
+ # Quick Context for New Sessions
2
+
3
+ ## Project: DevOps AI Toolkit - Kubernetes Application Management
4
+
5
+ **Core Concept**: Dual-mode AI agent (CLI + MCP) that deploys applications to ANY Kubernetes cluster through dynamic discovery.
6
+
7
+ ## Key Architectural Decisions Made
8
+
9
+ 1. **Discovery-Driven**: No hardcoded platforms - discovers CRDs + core K8s resources via `kubectl explain`
10
+ 2. **Resource-Agnostic**: Works with ANY Kubernetes resources (AppClaim, CloudRun, Knative, standard K8s, custom CRDs, etc.)
11
+ 3. **Dual-Mode**: Same intelligence, two interfaces:
12
+ - **Direct Mode**: `dot-ai` CLI for direct user interaction
13
+ - **MCP Mode**: `dot-ai-mcp` server for AI agent integration
14
+ 4. **Claude Code SDK**: Powers both modes with intelligent conversation and JSON output
15
+ 5. **Memory-Enhanced**: Learns from deployments, stores lessons in JSON files
16
+
17
+ ## Workflow (Both Modes)
18
+ 1. **Cluster Discovery** - `kubectl get crd`, `kubectl explain`, `kubectl api-resources`
19
+ 2. **Strategy Selection** - Choose best available resource type based on discovery
20
+ 3. **Configuration Gathering** - Dynamic questions based on resource schemas + user intent
21
+ 4. **Manifest Generation** - Generate using schemas + apply memory lessons
22
+ 5. **Deployment & Monitoring** - Deploy and track until success/failure
23
+
24
+ ## MCP Functions to Specify
25
+ - `create_application` - Entry point, returns discovery + initial guidance
26
+ - `continue_workflow` - Progress based on user input
27
+ - `deploy_application` - Execute deployment
28
+ - `get_deployment_status` - Monitor progress
29
+ - Plus any additional functions needed
30
+
31
+ ## Critical Principles
32
+ - **Questions are schema-driven**: `kubectl explain <resource>` → generate contextual questions
33
+ - **User intent matters**: "web app with scaling" vs "batch job" → different question focus
34
+ - **Universal extensibility**: Must work with ANY CRDs without code changes
35
+ - **Memory integration**: Learn from patterns, failures, successes
36
+
37
+ ## Files Available
38
+ - `design.md` - Complete architecture and examples
39
+ - `ORIGINAL_INSPIRATION.md` - The original prompt that started this project (for reference only)
40
+ - `NEXT_STEPS.md` - Detailed action plan for immediate next development tasks
41
+ - This `CONTEXT.md` - Quick reference for new sessions
42
+
43
+ ## Next Task: API Specifications
44
+ Define detailed JSON schemas and examples for all MCP functions, focusing on:
45
+ 1. Input/output schemas for each function
46
+ 2. Error handling patterns
47
+ 3. Workflow state management
48
+ 4. Discovery result structures
49
+ 5. Memory lesson formats
@@ -0,0 +1,203 @@
1
+ # Development Guide
2
+
3
+ ## Architecture
4
+
5
+ ### Core Components
6
+
7
+ - **Discovery Engine** (`src/core/discovery.ts`): Comprehensive Kubernetes cluster discovery and analysis
8
+ - **AI Integration** (`src/core/claude.ts`): Claude AI integration for intelligent application construction
9
+ - **Schema Parser** (`src/core/schema.ts`): Resource schema parsing, validation, and AI-powered recommendations
10
+ - **Stage-Based Workflow Tools** (`src/tools/`): MCP tools for progressive configuration (recommend, chooseSolution, answerQuestion, generateManifests)
11
+ - **Memory System** (`src/core/memory.ts`): Persistent memory for learning and context retention
12
+ - **Workflow Engine** (`src/core/workflow.ts`): Orchestrates the application construction process
13
+ - **CLI Interface** (`src/interfaces/cli.ts`): Command-line interface for direct usage
14
+ - **MCP Interface** (`src/interfaces/mcp.ts`): Model Context Protocol server for tool integration
15
+
16
+ ### Data Structures
17
+
18
+ The discovery engine provides comprehensive, unfiltered data through well-defined TypeScript interfaces:
19
+
20
+ - **`EnhancedResource`**: Standard Kubernetes resources with metadata
21
+ - **`EnhancedCRD`**: Custom Resource Definitions with version and schema info
22
+ - **`ResourceExplanation`**: Detailed field-level schema information
23
+ - **`ClusterFingerprint`**: Comprehensive cluster capabilities and configuration
24
+ - **`ResourceMap`**: Container for all discovered resources
25
+
26
+ ## Development Workflow
27
+
28
+ ### Prerequisites
29
+ - Node.js 18+
30
+ - TypeScript
31
+ - kubectl configured with cluster access
32
+ - Access to a Kubernetes cluster (local or remote)
33
+
34
+ ### Setup
35
+
36
+ ```bash
37
+ # Clone and install
38
+ git clone https://github.com/vfarcic/node dist/cli.js.git
39
+ cd node dist/cli.js
40
+ npm install
41
+
42
+ # Build the project
43
+ npm run build
44
+
45
+ # Set up environment variables
46
+ cp .env.example .env
47
+ # Edit .env with your API keys
48
+ ```
49
+
50
+ ### Making Changes
51
+
52
+ 1. **Make changes** to source files in `src/`
53
+ 2. **Build** the project: `npm run build`
54
+ 3. **Run tests** to ensure functionality: `npm test`
55
+ 4. **Test manually** with real cluster: `node dist/cli.js discover --kubeconfig kubeconfig.yaml`
56
+ 5. **Commit changes** with descriptive messages
57
+
58
+ ### Testing
59
+
60
+ ```bash
61
+ # Run all tests
62
+ npm test
63
+
64
+ # Run tests with coverage
65
+ npm test -- --coverage
66
+
67
+ # Run specific test suite
68
+ npm test -- tests/core.test.ts
69
+
70
+ # Run tests matching pattern
71
+ npm test -- --testNamePattern="generateManifests"
72
+ ```
73
+
74
+ ### Test Coverage
75
+
76
+ The project maintains comprehensive test coverage:
77
+ - **Unit Tests**: Core functionality and error conditions
78
+ - **Integration Tests**: Real cluster connectivity using kind cluster
79
+ - **TDD Tests**: Error handling and graceful degradation scenarios
80
+ - **Manual Validation**: CLI output verification and data structure validation
81
+
82
+ Current coverage: **69%+ overall** with **565+ tests** across 21 test suites, including comprehensive tests for the stage-based workflow functionality.
83
+
84
+ ### Code Quality
85
+
86
+ - **TypeScript**: Maintain strict type safety
87
+ - **ESLint**: Follow existing linting rules
88
+ - **Testing**: Write tests for new functionality
89
+ - **Documentation**: Update docs for API changes
90
+ - **Error Handling**: Follow patterns in [Error Handling Guide](error-handling.md)
91
+
92
+ ## Contributing
93
+
94
+ ### Development Guidelines
95
+
96
+ - **Write tests** for new functionality
97
+ - **Maintain** TypeScript type safety
98
+ - **Follow** existing code patterns and conventions
99
+ - **Update documentation** for API changes
100
+ - **Test manually** with real clusters when possible
101
+
102
+ ### Pull Request Process
103
+
104
+ 1. **Fork** the repository
105
+ 2. **Create** a feature branch: `git checkout -b feature/amazing-feature`
106
+ 3. **Make** your changes with tests
107
+ 4. **Ensure** all tests pass: `npm test`
108
+ 5. **Commit** your changes: `git commit -m 'Add amazing feature'`
109
+ 6. **Push** to the branch: `git push origin feature/amazing-feature`
110
+ 7. **Open** a Pull Request
111
+
112
+ ## CI/CD Integration
113
+
114
+ ### GitHub Actions
115
+
116
+ ```yaml
117
+ # Example GitHub Actions workflow
118
+ - name: Test cluster discovery
119
+ run: |
120
+ # Start kind cluster
121
+ kind create cluster --config kind-config.yaml
122
+
123
+ # Test discovery
124
+ node dist/cli.js discover --kubeconfig ~/.kube/config
125
+
126
+ # Run full test suite
127
+ npm test
128
+ ```
129
+
130
+ ### Local Testing with Kind
131
+
132
+ ```bash
133
+ # Create test cluster
134
+ kind create cluster --name node dist/cli.js-test
135
+
136
+ # Run integration tests
137
+ export KUBECONFIG=$(kind get kubeconfig-path --name node dist/cli.js-test)
138
+ npm test -- tests/integration
139
+
140
+ # Cleanup
141
+ kind delete cluster --name node dist/cli.js-test
142
+ ```
143
+
144
+ ## Debugging
145
+
146
+ ### Common Issues
147
+
148
+ **Connection Errors**
149
+ - Verify kubeconfig path and permissions
150
+ - Check cluster connectivity: `kubectl cluster-info`
151
+ - Ensure proper RBAC permissions for discovery operations
152
+
153
+ **API Discovery Failures**
154
+ - Some resources may require specific cluster configurations
155
+ - CRD discovery depends on installed operators
156
+ - Permission issues may limit resource visibility
157
+
158
+ **AI Integration Issues**
159
+ - Verify `ANTHROPIC_API_KEY` environment variable
160
+ - Check API rate limits and quotas
161
+ - Review error logs for specific AI service issues
162
+
163
+ ### Debug Logging
164
+
165
+ ```bash
166
+ # Enable verbose logging
167
+ DEBUG=node dist/cli.js:* node dist/cli.js discover
168
+
169
+ # Specific module debugging
170
+ DEBUG=node dist/cli.js:discovery node dist/cli.js discover
171
+ DEBUG=node dist/cli.js:schema node dist/cli.js recommend --intent "test"
172
+
173
+ # MCP server debugging
174
+ DEBUG=node dist/cli.js:* npm run mcp:start
175
+ ```
176
+
177
+ ## Performance Considerations
178
+
179
+ - **Resource Discovery**: Can be slow in large clusters with many CRDs
180
+ - **AI Operations**: Network latency affects recommendation speed
181
+ - **Session Management**: generateManifests can take 30-45 seconds for complex deployments
182
+ - **Memory Usage**: Large cluster discoveries may consume significant memory
183
+ - **MCP Server**: Designed for persistent connection with multiple tool calls
184
+ - **Caching**: Consider implementing caching for repeated operations
185
+
186
+ ## Roadmap
187
+
188
+ - [x] **Stage-Based Workflow**: Completed conversational deployment via MCP tools
189
+ - [x] **AI-Generated Manifests**: Schema-aware YAML generation with validation
190
+ - [ ] **Enhanced AI Integration**: More sophisticated application construction strategies
191
+ - [ ] **Multi-Cluster Support**: Discovery and deployment across multiple clusters
192
+ - [ ] **Operator Marketplace**: Integration with operator catalogs and marketplaces
193
+ - [ ] **Visual Interface**: Web-based cluster visualization and application designer
194
+ - [ ] **GitOps Integration**: Automated deployment pipeline integration
195
+ - [ ] **Policy Engine**: Security and compliance policy validation
196
+
197
+ ## Legacy Code
198
+
199
+ Legacy components are archived in `/src/legacy/` directory:
200
+ - **Solution Enhancer** (`src/legacy/core/solution-enhancer.ts`): Original JSON-based enhancement approach
201
+ - **Enhance Tool** (`src/legacy/tools/enhance-solution.ts`): CLI enhancement command
202
+
203
+ These are kept for reference and can be safely removed after 6 months of new architecture stability.