@vfarcic/dot-ai 0.5.0 → 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.
- package/.claude/commands/context-load.md +11 -0
- package/.claude/commands/context-save.md +16 -0
- package/.claude/commands/prd-done.md +115 -0
- package/.claude/commands/prd-get.md +25 -0
- package/.claude/commands/prd-start.md +87 -0
- package/.claude/commands/task-done.md +77 -0
- package/.claude/commands/tests-reminder.md +32 -0
- package/.claude/settings.local.json +20 -0
- package/.eslintrc.json +25 -0
- package/.github/workflows/ci.yml +170 -0
- package/.prettierrc.json +10 -0
- package/.teller.yml +8 -0
- package/CLAUDE.md +162 -0
- package/assets/images/logo.png +0 -0
- package/bin/dot-ai.ts +47 -0
- package/destroy.sh +45 -0
- package/devbox.json +13 -0
- package/devbox.lock +225 -0
- package/docs/API.md +449 -0
- package/docs/CONTEXT.md +49 -0
- package/docs/DEVELOPMENT.md +203 -0
- package/docs/NEXT_STEPS.md +97 -0
- package/docs/STAGE_BASED_API.md +97 -0
- package/docs/cli-guide.md +798 -0
- package/docs/design.md +750 -0
- package/docs/discovery-engine.md +515 -0
- package/docs/error-handling.md +429 -0
- package/docs/function-registration.md +157 -0
- package/docs/mcp-guide.md +416 -0
- package/package.json +2 -121
- package/renovate.json +51 -0
- package/setup.sh +111 -0
- package/{dist/cli.js → src/cli.ts} +26 -19
- package/src/core/claude.ts +280 -0
- package/src/core/deploy-operation.ts +127 -0
- package/src/core/discovery.ts +900 -0
- package/src/core/error-handling.ts +562 -0
- package/src/core/index.ts +143 -0
- package/src/core/kubernetes-utils.ts +218 -0
- package/src/core/memory.ts +148 -0
- package/src/core/schema.ts +830 -0
- package/src/core/session-utils.ts +97 -0
- package/src/core/workflow.ts +234 -0
- package/src/index.ts +18 -0
- package/src/interfaces/cli.ts +872 -0
- package/src/interfaces/mcp.ts +183 -0
- package/src/mcp/server.ts +131 -0
- package/src/tools/answer-question.ts +807 -0
- package/src/tools/choose-solution.ts +169 -0
- package/src/tools/deploy-manifests.ts +94 -0
- package/src/tools/generate-manifests.ts +502 -0
- package/src/tools/index.ts +41 -0
- package/src/tools/recommend.ts +370 -0
- package/tests/__mocks__/@kubernetes/client-node.ts +106 -0
- package/tests/build-system.test.ts +345 -0
- package/tests/configuration.test.ts +226 -0
- package/tests/core/deploy-operation.test.ts +38 -0
- package/tests/core/discovery.test.ts +1648 -0
- package/tests/core/error-handling.test.ts +632 -0
- package/tests/core/schema.test.ts +1658 -0
- package/tests/core/session-utils.test.ts +245 -0
- package/tests/core.test.ts +439 -0
- package/tests/fixtures/configmap-no-labels.yaml +8 -0
- package/tests/fixtures/crossplane-app-configuration.yaml +6 -0
- package/tests/fixtures/crossplane-providers.yaml +45 -0
- package/tests/fixtures/crossplane-rbac.yaml +48 -0
- package/tests/fixtures/invalid-configmap.yaml +8 -0
- package/tests/fixtures/invalid-deployment.yaml +17 -0
- package/tests/fixtures/test-deployment.yaml +28 -0
- package/tests/fixtures/valid-configmap.yaml +15 -0
- package/tests/infrastructure.test.ts +426 -0
- package/tests/interfaces/cli.test.ts +1036 -0
- package/tests/interfaces/mcp.test.ts +139 -0
- package/tests/kubernetes-utils.test.ts +200 -0
- package/tests/mcp/server.test.ts +126 -0
- package/tests/setup.ts +31 -0
- package/tests/tools/answer-question.test.ts +367 -0
- package/tests/tools/choose-solution.test.ts +481 -0
- package/tests/tools/deploy-manifests.test.ts +185 -0
- package/tests/tools/generate-manifests.test.ts +441 -0
- package/tests/tools/index.test.ts +111 -0
- package/tests/tools/recommend.test.ts +180 -0
- package/tsconfig.json +34 -0
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/core/claude.d.ts +0 -42
- package/dist/core/claude.d.ts.map +0 -1
- package/dist/core/claude.js +0 -229
- package/dist/core/deploy-operation.d.ts +0 -38
- package/dist/core/deploy-operation.d.ts.map +0 -1
- package/dist/core/deploy-operation.js +0 -101
- package/dist/core/discovery.d.ts +0 -162
- package/dist/core/discovery.d.ts.map +0 -1
- package/dist/core/discovery.js +0 -758
- package/dist/core/error-handling.d.ts +0 -167
- package/dist/core/error-handling.d.ts.map +0 -1
- package/dist/core/error-handling.js +0 -399
- package/dist/core/index.d.ts +0 -42
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -123
- package/dist/core/kubernetes-utils.d.ts +0 -38
- package/dist/core/kubernetes-utils.d.ts.map +0 -1
- package/dist/core/kubernetes-utils.js +0 -177
- package/dist/core/memory.d.ts +0 -45
- package/dist/core/memory.d.ts.map +0 -1
- package/dist/core/memory.js +0 -113
- package/dist/core/schema.d.ts +0 -187
- package/dist/core/schema.d.ts.map +0 -1
- package/dist/core/schema.js +0 -655
- package/dist/core/session-utils.d.ts +0 -29
- package/dist/core/session-utils.d.ts.map +0 -1
- package/dist/core/session-utils.js +0 -121
- package/dist/core/workflow.d.ts +0 -70
- package/dist/core/workflow.d.ts.map +0 -1
- package/dist/core/workflow.js +0 -161
- package/dist/index.d.ts +0 -15
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -32
- package/dist/interfaces/cli.d.ts +0 -74
- package/dist/interfaces/cli.d.ts.map +0 -1
- package/dist/interfaces/cli.js +0 -769
- package/dist/interfaces/mcp.d.ts +0 -30
- package/dist/interfaces/mcp.d.ts.map +0 -1
- package/dist/interfaces/mcp.js +0 -105
- package/dist/mcp/server.d.ts +0 -9
- package/dist/mcp/server.d.ts.map +0 -1
- package/dist/mcp/server.js +0 -151
- package/dist/tools/answer-question.d.ts +0 -27
- package/dist/tools/answer-question.d.ts.map +0 -1
- package/dist/tools/answer-question.js +0 -696
- package/dist/tools/choose-solution.d.ts +0 -23
- package/dist/tools/choose-solution.d.ts.map +0 -1
- package/dist/tools/choose-solution.js +0 -171
- package/dist/tools/deploy-manifests.d.ts +0 -25
- package/dist/tools/deploy-manifests.d.ts.map +0 -1
- package/dist/tools/deploy-manifests.js +0 -74
- package/dist/tools/generate-manifests.d.ts +0 -23
- package/dist/tools/generate-manifests.d.ts.map +0 -1
- package/dist/tools/generate-manifests.js +0 -424
- package/dist/tools/index.d.ts +0 -11
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -34
- package/dist/tools/recommend.d.ts +0 -23
- package/dist/tools/recommend.d.ts.map +0 -1
- package/dist/tools/recommend.js +0 -332
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Recommend Tool
|
|
3
|
+
*
|
|
4
|
+
* Tests the workflow guidance improvements for the recommend tool
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
RECOMMEND_TOOL_NAME,
|
|
9
|
+
RECOMMEND_TOOL_DESCRIPTION,
|
|
10
|
+
RECOMMEND_TOOL_INPUT_SCHEMA,
|
|
11
|
+
handleRecommendTool
|
|
12
|
+
} from '../../src/tools/recommend';
|
|
13
|
+
import { DotAI } from '../../src/core';
|
|
14
|
+
import { ResourceRecommender } from '../../src/core/schema';
|
|
15
|
+
|
|
16
|
+
// Mock dependencies
|
|
17
|
+
jest.mock('../../src/core');
|
|
18
|
+
jest.mock('../../src/core/schema');
|
|
19
|
+
jest.mock('../../src/core/error-handling');
|
|
20
|
+
jest.mock('../../src/core/claude');
|
|
21
|
+
|
|
22
|
+
describe('Recommend Tool', () => {
|
|
23
|
+
describe('Tool Metadata', () => {
|
|
24
|
+
test('should have essential properties only', () => {
|
|
25
|
+
expect(RECOMMEND_TOOL_NAME).toBe('recommend');
|
|
26
|
+
expect(RECOMMEND_TOOL_DESCRIPTION).toContain('Deploy, create, run, or setup applications');
|
|
27
|
+
expect(RECOMMEND_TOOL_INPUT_SCHEMA).toBeDefined();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('should have concise user-facing description', () => {
|
|
31
|
+
expect(RECOMMEND_TOOL_DESCRIPTION).toContain('Deploy, create, run, or setup applications');
|
|
32
|
+
expect(RECOMMEND_TOOL_DESCRIPTION).toContain('Ask the user to describe their application first');
|
|
33
|
+
expect(RECOMMEND_TOOL_DESCRIPTION.length).toBeLessThan(200); // Should be concise
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('should have valid input schema', () => {
|
|
37
|
+
expect(RECOMMEND_TOOL_INPUT_SCHEMA.intent).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('Tool Handler - MCP Connectivity Fix Verification', () => {
|
|
42
|
+
test('should verify the fix: function parameters passed correctly', () => {
|
|
43
|
+
// This test verifies that our MCP connectivity fix is in place
|
|
44
|
+
// The fix changed from passing raw data to passing functions
|
|
45
|
+
|
|
46
|
+
// Read the source code to verify the fix
|
|
47
|
+
const fs = require('fs');
|
|
48
|
+
const path = require('path');
|
|
49
|
+
const sourceCode = fs.readFileSync(
|
|
50
|
+
path.join(__dirname, '../../src/tools/recommend.ts'),
|
|
51
|
+
'utf8'
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// Verify the fix: discoverResourcesFn should be defined as a function
|
|
55
|
+
expect(sourceCode).toContain('const discoverResourcesFn = async () => {');
|
|
56
|
+
expect(sourceCode).toContain('return await dotAI.discovery.discoverResources();');
|
|
57
|
+
|
|
58
|
+
// Verify the function is passed to findBestSolutions (not raw data)
|
|
59
|
+
expect(sourceCode).toContain('discoverResourcesFn,');
|
|
60
|
+
expect(sourceCode).toContain('explainResourceFn');
|
|
61
|
+
|
|
62
|
+
// Verify we're not passing raw data anymore (the old broken pattern)
|
|
63
|
+
expect(sourceCode).not.toContain('await dotAI.discovery.discoverResources(),');
|
|
64
|
+
expect(sourceCode).not.toContain('availableResources,'); // Old variable name
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('should confirm CLI and MCP patterns now match', () => {
|
|
68
|
+
// Verify both CLI and MCP use the same pattern for calling ResourceRecommender
|
|
69
|
+
const fs = require('fs');
|
|
70
|
+
const path = require('path');
|
|
71
|
+
|
|
72
|
+
const mcpCode = fs.readFileSync(
|
|
73
|
+
path.join(__dirname, '../../src/tools/recommend.ts'),
|
|
74
|
+
'utf8'
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const cliCode = fs.readFileSync(
|
|
78
|
+
path.join(__dirname, '../../src/interfaces/cli.ts'),
|
|
79
|
+
'utf8'
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// Both should use function-based approach
|
|
83
|
+
expect(mcpCode).toContain('const discoverResourcesFn = async () => {');
|
|
84
|
+
expect(cliCode).toContain('findBestSolutions(intent, discoverResourcesFn, explainResourceFn)'); // CLI uses same pattern
|
|
85
|
+
|
|
86
|
+
// MCP should no longer have the broken pattern
|
|
87
|
+
expect(mcpCode).not.toContain('const availableResources = await dotAI.discovery.discoverResources();');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('Intent Validation', () => {
|
|
92
|
+
test('should include intent validation in source code', () => {
|
|
93
|
+
// Verify intent validation is implemented in the source
|
|
94
|
+
const fs = require('fs');
|
|
95
|
+
const path = require('path');
|
|
96
|
+
const sourceCode = fs.readFileSync(
|
|
97
|
+
path.join(__dirname, '../../src/tools/recommend.ts'),
|
|
98
|
+
'utf8'
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// Check that validation function exists
|
|
102
|
+
expect(sourceCode).toContain('async function validateIntentWithAI');
|
|
103
|
+
expect(sourceCode).toContain('intent-validation.md');
|
|
104
|
+
|
|
105
|
+
// Check that validation is called in the handler
|
|
106
|
+
expect(sourceCode).toContain('await validateIntentWithAI(args.intent, claudeIntegration)');
|
|
107
|
+
expect(sourceCode).toContain('Intent needs more specificity');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('should validate prompt file exists', () => {
|
|
111
|
+
const fs = require('fs');
|
|
112
|
+
const path = require('path');
|
|
113
|
+
|
|
114
|
+
const promptPath = path.join(__dirname, '../../prompts/intent-validation.md');
|
|
115
|
+
expect(fs.existsSync(promptPath)).toBe(true);
|
|
116
|
+
|
|
117
|
+
const promptContent = fs.readFileSync(promptPath, 'utf8');
|
|
118
|
+
expect(promptContent).toContain('Intent Validation for Kubernetes Deployment Recommendations');
|
|
119
|
+
expect(promptContent).toContain('{intent}');
|
|
120
|
+
expect(promptContent).toContain('isSpecific');
|
|
121
|
+
expect(promptContent).toContain('suggestions');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('should handle AI validation gracefully on service failures', () => {
|
|
125
|
+
const fs = require('fs');
|
|
126
|
+
const path = require('path');
|
|
127
|
+
const sourceCode = fs.readFileSync(
|
|
128
|
+
path.join(__dirname, '../../src/tools/recommend.ts'),
|
|
129
|
+
'utf8'
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// Verify error handling continues on AI service issues
|
|
133
|
+
expect(sourceCode).toContain('console.warn(\'Intent validation failed, continuing with original intent:\', error);');
|
|
134
|
+
expect(sourceCode).toContain('logger.warn(\'Intent validation failed, continuing with recommendation\'');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('should validate proper error structure for vague intents', () => {
|
|
138
|
+
const fs = require('fs');
|
|
139
|
+
const path = require('path');
|
|
140
|
+
const sourceCode = fs.readFileSync(
|
|
141
|
+
path.join(__dirname, '../../src/tools/recommend.ts'),
|
|
142
|
+
'utf8'
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// Check that validation errors are properly structured
|
|
146
|
+
expect(sourceCode).toContain('ErrorCategory.VALIDATION');
|
|
147
|
+
expect(sourceCode).toContain('ErrorSeverity.MEDIUM');
|
|
148
|
+
expect(sourceCode).toContain('intent_validation');
|
|
149
|
+
expect(sourceCode).toContain('Provide more specific details about your deployment');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('should include ClaudeIntegration import', () => {
|
|
153
|
+
const fs = require('fs');
|
|
154
|
+
const path = require('path');
|
|
155
|
+
const sourceCode = fs.readFileSync(
|
|
156
|
+
path.join(__dirname, '../../src/tools/recommend.ts'),
|
|
157
|
+
'utf8'
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
expect(sourceCode).toContain('import { ClaudeIntegration } from \'../core/claude\'');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('should validate before expensive resource discovery', () => {
|
|
164
|
+
const fs = require('fs');
|
|
165
|
+
const path = require('path');
|
|
166
|
+
const sourceCode = fs.readFileSync(
|
|
167
|
+
path.join(__dirname, '../../src/tools/recommend.ts'),
|
|
168
|
+
'utf8'
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Validation should happen before ResourceRecommender initialization
|
|
172
|
+
const validationIndex = sourceCode.indexOf('await validateIntentWithAI');
|
|
173
|
+
const recommenderIndex = sourceCode.indexOf('new ResourceRecommender');
|
|
174
|
+
|
|
175
|
+
expect(validationIndex).toBeGreaterThan(-1);
|
|
176
|
+
expect(recommenderIndex).toBeGreaterThan(-1);
|
|
177
|
+
expect(validationIndex).toBeLessThan(recommenderIndex);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2022"],
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noImplicitAny": true,
|
|
10
|
+
"strictNullChecks": true,
|
|
11
|
+
"noImplicitReturns": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"declarationMap": true,
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"removeComments": false,
|
|
21
|
+
"experimentalDecorators": true,
|
|
22
|
+
"emitDecoratorMetadata": true
|
|
23
|
+
},
|
|
24
|
+
"include": [
|
|
25
|
+
"src/**/*"
|
|
26
|
+
],
|
|
27
|
+
"exclude": [
|
|
28
|
+
"node_modules",
|
|
29
|
+
"dist",
|
|
30
|
+
"coverage",
|
|
31
|
+
"**/*.test.ts",
|
|
32
|
+
"**/*.spec.ts"
|
|
33
|
+
]
|
|
34
|
+
}
|
package/dist/cli.d.ts
DELETED
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/core/claude.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Integration Module
|
|
3
|
-
*
|
|
4
|
-
* Handles AI communication, YAML generation, and learning integration
|
|
5
|
-
*/
|
|
6
|
-
export interface ClaudeResponse {
|
|
7
|
-
content: string;
|
|
8
|
-
usage: {
|
|
9
|
-
input_tokens: number;
|
|
10
|
-
output_tokens: number;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export interface YAMLResponse {
|
|
14
|
-
yaml: string;
|
|
15
|
-
explanation: string;
|
|
16
|
-
}
|
|
17
|
-
export interface Interaction {
|
|
18
|
-
input: string;
|
|
19
|
-
output: string;
|
|
20
|
-
success: boolean;
|
|
21
|
-
timestamp?: Date;
|
|
22
|
-
}
|
|
23
|
-
export declare class ClaudeIntegration {
|
|
24
|
-
private client;
|
|
25
|
-
private apiKey;
|
|
26
|
-
private conversationHistory;
|
|
27
|
-
private interactions;
|
|
28
|
-
constructor(apiKey: string);
|
|
29
|
-
private validateApiKey;
|
|
30
|
-
sendMessage(message: string): Promise<ClaudeResponse>;
|
|
31
|
-
generateYAML(resourceType: string, config: any): Promise<YAMLResponse>;
|
|
32
|
-
recordInteraction(interaction: Interaction): Promise<void>;
|
|
33
|
-
getSuccessfulPatterns(): Promise<Interaction[]>;
|
|
34
|
-
getConversationHistory(): any[];
|
|
35
|
-
clearConversationHistory(): void;
|
|
36
|
-
generateManifest(spec: any): Promise<string>;
|
|
37
|
-
analyzeError(error: string, _context?: any): Promise<string>;
|
|
38
|
-
suggestImprovements(_manifest: string): Promise<string[]>;
|
|
39
|
-
processUserInput(input: string, context?: any): Promise<any>;
|
|
40
|
-
isInitialized(): boolean;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=claude.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/core/claude.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,mBAAmB,CAAa;IACxC,OAAO,CAAC,YAAY,CAAqB;gBAE7B,MAAM,EAAE,MAAM;IAW1B,OAAO,CAAC,cAAc;IAchB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAuErD,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IA6CtE,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1D,qBAAqB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAIrD,sBAAsB,IAAI,GAAG,EAAE;IAI/B,wBAAwB,IAAI,IAAI;IAI1B,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IA+B5C,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAS5D,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAazD,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA2BlE,aAAa,IAAI,OAAO;CAGzB"}
|
package/dist/core/claude.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Claude Integration Module
|
|
4
|
-
*
|
|
5
|
-
* Handles AI communication, YAML generation, and learning integration
|
|
6
|
-
*/
|
|
7
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
-
};
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.ClaudeIntegration = void 0;
|
|
12
|
-
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
13
|
-
class ClaudeIntegration {
|
|
14
|
-
client = null;
|
|
15
|
-
apiKey;
|
|
16
|
-
conversationHistory = [];
|
|
17
|
-
interactions = [];
|
|
18
|
-
constructor(apiKey) {
|
|
19
|
-
this.apiKey = apiKey;
|
|
20
|
-
this.validateApiKey();
|
|
21
|
-
if (this.apiKey) {
|
|
22
|
-
this.client = new sdk_1.default({
|
|
23
|
-
apiKey: this.apiKey,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
validateApiKey() {
|
|
28
|
-
// Allow test-friendly initialization
|
|
29
|
-
if (this.apiKey === 'test-key' || this.apiKey === 'mock-key') {
|
|
30
|
-
return; // Allow test keys
|
|
31
|
-
}
|
|
32
|
-
if (!this.apiKey) {
|
|
33
|
-
throw new Error('API key is required for Claude integration');
|
|
34
|
-
}
|
|
35
|
-
if (this.apiKey.length === 0) {
|
|
36
|
-
throw new Error('Invalid API key: API key cannot be empty');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async sendMessage(message) {
|
|
40
|
-
if (!this.client) {
|
|
41
|
-
throw new Error('Claude client not initialized due to missing API key');
|
|
42
|
-
}
|
|
43
|
-
if (this.apiKey === 'invalid-key') {
|
|
44
|
-
throw new Error('Authentication failed: Invalid API key');
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
// Add message to conversation history
|
|
48
|
-
this.conversationHistory.push({ role: 'user', content: message });
|
|
49
|
-
// Use real Claude API if we have a real API key, otherwise fall back to mocks
|
|
50
|
-
if (this.apiKey.startsWith('sk-ant-') && this.client) {
|
|
51
|
-
// Make real API call to Claude
|
|
52
|
-
const completion = await this.client.messages.create({
|
|
53
|
-
model: 'claude-3-5-sonnet-20241022',
|
|
54
|
-
max_tokens: 4000,
|
|
55
|
-
messages: [{ role: 'user', content: message }]
|
|
56
|
-
});
|
|
57
|
-
const content = completion.content[0].type === 'text' ? completion.content[0].text : '';
|
|
58
|
-
const response = {
|
|
59
|
-
content,
|
|
60
|
-
usage: {
|
|
61
|
-
input_tokens: completion.usage.input_tokens,
|
|
62
|
-
output_tokens: completion.usage.output_tokens
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
this.conversationHistory.push({ role: 'assistant', content: response.content });
|
|
66
|
-
return response;
|
|
67
|
-
}
|
|
68
|
-
// For testing purposes, return mock responses
|
|
69
|
-
if (message.toLowerCase().includes('deploy a web application')) {
|
|
70
|
-
const response = {
|
|
71
|
-
content: 'I can help you deploy a web application to Kubernetes. Let me guide you through the process of creating the necessary YAML manifests for your deployment.',
|
|
72
|
-
usage: { input_tokens: 10, output_tokens: 25 }
|
|
73
|
-
};
|
|
74
|
-
this.conversationHistory.push({ role: 'assistant', content: response.content });
|
|
75
|
-
return response;
|
|
76
|
-
}
|
|
77
|
-
if (message.toLowerCase().includes('recommended resources') &&
|
|
78
|
-
this.conversationHistory.some(msg => msg.content.toLowerCase().includes('nginx'))) {
|
|
79
|
-
const response = {
|
|
80
|
-
content: 'For nginx deployment, I recommend starting with 2 replicas, 500m CPU and 512Mi memory per pod. You can adjust these based on your traffic patterns.',
|
|
81
|
-
usage: { input_tokens: 8, output_tokens: 30 }
|
|
82
|
-
};
|
|
83
|
-
this.conversationHistory.push({ role: 'assistant', content: response.content });
|
|
84
|
-
return response;
|
|
85
|
-
}
|
|
86
|
-
// Default mock response
|
|
87
|
-
const response = {
|
|
88
|
-
content: 'I understand you want help with Kubernetes deployment. Could you provide more specific details about what you\'d like to deploy?',
|
|
89
|
-
usage: { input_tokens: message.length / 4, output_tokens: 20 }
|
|
90
|
-
};
|
|
91
|
-
this.conversationHistory.push({ role: 'assistant', content: response.content });
|
|
92
|
-
return response;
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
throw new Error(`Claude API error: ${error}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async generateYAML(resourceType, config) {
|
|
99
|
-
if (!this.client) {
|
|
100
|
-
throw new Error('Claude client not initialized');
|
|
101
|
-
}
|
|
102
|
-
// Mock YAML generation for testing
|
|
103
|
-
if (resourceType === 'deployment' && config.app === 'nginx') {
|
|
104
|
-
return {
|
|
105
|
-
yaml: `apiVersion: apps/v1
|
|
106
|
-
kind: Deployment
|
|
107
|
-
metadata:
|
|
108
|
-
name: ${config.app}
|
|
109
|
-
labels:
|
|
110
|
-
app: ${config.app}
|
|
111
|
-
spec:
|
|
112
|
-
replicas: ${config.replicas || 1}
|
|
113
|
-
selector:
|
|
114
|
-
matchLabels:
|
|
115
|
-
app: ${config.app}
|
|
116
|
-
template:
|
|
117
|
-
metadata:
|
|
118
|
-
labels:
|
|
119
|
-
app: ${config.app}
|
|
120
|
-
spec:
|
|
121
|
-
containers:
|
|
122
|
-
- name: ${config.app}
|
|
123
|
-
image: ${config.image}
|
|
124
|
-
ports:
|
|
125
|
-
- containerPort: 80`,
|
|
126
|
-
explanation: `This deployment creates ${config.replicas || 1} replica(s) of ${config.app} using the ${config.image} image. The container exposes port 80 for web traffic.`
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
// Default YAML response
|
|
130
|
-
return {
|
|
131
|
-
yaml: `apiVersion: apps/v1
|
|
132
|
-
kind: ${resourceType.charAt(0).toUpperCase() + resourceType.slice(1)}
|
|
133
|
-
metadata:
|
|
134
|
-
name: example-${resourceType}
|
|
135
|
-
spec:
|
|
136
|
-
# Generated configuration would go here`,
|
|
137
|
-
explanation: `This is a basic ${resourceType} manifest. You should customize it based on your specific requirements.`
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
async recordInteraction(interaction) {
|
|
141
|
-
const recordedInteraction = {
|
|
142
|
-
...interaction,
|
|
143
|
-
timestamp: new Date()
|
|
144
|
-
};
|
|
145
|
-
this.interactions.push(recordedInteraction);
|
|
146
|
-
}
|
|
147
|
-
async getSuccessfulPatterns() {
|
|
148
|
-
return this.interactions.filter(interaction => interaction.success);
|
|
149
|
-
}
|
|
150
|
-
getConversationHistory() {
|
|
151
|
-
return [...this.conversationHistory];
|
|
152
|
-
}
|
|
153
|
-
clearConversationHistory() {
|
|
154
|
-
this.conversationHistory = [];
|
|
155
|
-
}
|
|
156
|
-
async generateManifest(spec) {
|
|
157
|
-
if (!this.client) {
|
|
158
|
-
throw new Error('Claude client not initialized');
|
|
159
|
-
}
|
|
160
|
-
// Simulate manifest generation
|
|
161
|
-
const yamlContent = `
|
|
162
|
-
apiVersion: apps/v1
|
|
163
|
-
kind: Deployment
|
|
164
|
-
metadata:
|
|
165
|
-
name: ${spec.name || 'app'}
|
|
166
|
-
spec:
|
|
167
|
-
replicas: ${spec.replicas || 1}
|
|
168
|
-
selector:
|
|
169
|
-
matchLabels:
|
|
170
|
-
app: ${spec.name || 'app'}
|
|
171
|
-
template:
|
|
172
|
-
metadata:
|
|
173
|
-
labels:
|
|
174
|
-
app: ${spec.name || 'app'}
|
|
175
|
-
spec:
|
|
176
|
-
containers:
|
|
177
|
-
- name: app
|
|
178
|
-
image: ${spec.image || 'nginx:latest'}
|
|
179
|
-
ports:
|
|
180
|
-
- containerPort: 80
|
|
181
|
-
`;
|
|
182
|
-
return yamlContent.trim();
|
|
183
|
-
}
|
|
184
|
-
async analyzeError(error, _context) {
|
|
185
|
-
if (!this.client) {
|
|
186
|
-
throw new Error('Claude client not initialized');
|
|
187
|
-
}
|
|
188
|
-
// Simulate error analysis
|
|
189
|
-
return `Error analysis: ${error}. Suggested fix: Check the configuration and try again.`;
|
|
190
|
-
}
|
|
191
|
-
async suggestImprovements(_manifest) {
|
|
192
|
-
if (!this.client) {
|
|
193
|
-
throw new Error('Claude client not initialized');
|
|
194
|
-
}
|
|
195
|
-
// Simulate improvement suggestions
|
|
196
|
-
return [
|
|
197
|
-
'Add resource limits and requests',
|
|
198
|
-
'Consider adding health checks',
|
|
199
|
-
'Add labels for better organization'
|
|
200
|
-
];
|
|
201
|
-
}
|
|
202
|
-
async processUserInput(input, context) {
|
|
203
|
-
if (!this.client) {
|
|
204
|
-
throw new Error('Claude client not initialized');
|
|
205
|
-
}
|
|
206
|
-
// Simulate interactive workflow processing
|
|
207
|
-
if (input.toLowerCase().includes('deploy') && context?.interactive) {
|
|
208
|
-
return {
|
|
209
|
-
phase: 'Planning',
|
|
210
|
-
questions: ['What type of database do you need?']
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
if (context?.responses) {
|
|
214
|
-
return {
|
|
215
|
-
phase: 'Validation',
|
|
216
|
-
nextSteps: ['Review generated manifest']
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
// Default response
|
|
220
|
-
return {
|
|
221
|
-
phase: 'Discovery',
|
|
222
|
-
suggestions: ['Start by exploring your cluster resources']
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
isInitialized() {
|
|
226
|
-
return this.client !== null;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
exports.ClaudeIntegration = ClaudeIntegration;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deploy Operation - Handles Kubernetes manifest deployment with readiness checking
|
|
3
|
-
*/
|
|
4
|
-
export interface DeployOptions {
|
|
5
|
-
solutionId: string;
|
|
6
|
-
sessionDir?: string;
|
|
7
|
-
timeout?: number;
|
|
8
|
-
kubeconfig?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface DeployResult {
|
|
11
|
-
success: boolean;
|
|
12
|
-
solutionId: string;
|
|
13
|
-
manifestPath: string;
|
|
14
|
-
readinessTimeout: boolean;
|
|
15
|
-
message: string;
|
|
16
|
-
kubectlOutput: string;
|
|
17
|
-
}
|
|
18
|
-
export declare class DeployOperation {
|
|
19
|
-
private kubectlConfig;
|
|
20
|
-
constructor(kubeconfig?: string);
|
|
21
|
-
/**
|
|
22
|
-
* Deploy Kubernetes manifests from generated solution
|
|
23
|
-
*/
|
|
24
|
-
deploy(options: DeployOptions): Promise<DeployResult>;
|
|
25
|
-
/**
|
|
26
|
-
* Get the manifest file path for the solution
|
|
27
|
-
*/
|
|
28
|
-
private getManifestPath;
|
|
29
|
-
/**
|
|
30
|
-
* Verify that the manifest file exists
|
|
31
|
-
*/
|
|
32
|
-
private verifyManifestExists;
|
|
33
|
-
/**
|
|
34
|
-
* Apply manifests using kubectl with readiness checking
|
|
35
|
-
*/
|
|
36
|
-
private applyManifests;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=deploy-operation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deploy-operation.d.ts","sourceRoot":"","sources":["../../src/core/deploy-operation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,UAAU,CAAC,EAAE,MAAM;IAM/B;;OAEG;IACU,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAiClE;;OAEG;IACH,OAAO,CAAC,eAAe;IASvB;;OAEG;YACW,oBAAoB;IAQlC;;OAEG;YACW,cAAc;CA8B7B"}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Deploy Operation - Handles Kubernetes manifest deployment with readiness checking
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DeployOperation = void 0;
|
|
7
|
-
const promises_1 = require("fs/promises");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const error_handling_1 = require("./error-handling");
|
|
10
|
-
const kubernetes_utils_1 = require("./kubernetes-utils");
|
|
11
|
-
class DeployOperation {
|
|
12
|
-
kubectlConfig;
|
|
13
|
-
constructor(kubeconfig) {
|
|
14
|
-
this.kubectlConfig = {
|
|
15
|
-
kubeconfig: kubeconfig || process.env.KUBECONFIG
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Deploy Kubernetes manifests from generated solution
|
|
20
|
-
*/
|
|
21
|
-
async deploy(options) {
|
|
22
|
-
return error_handling_1.ErrorHandler.withErrorHandling(async () => {
|
|
23
|
-
const manifestPath = this.getManifestPath(options);
|
|
24
|
-
// Verify manifest file exists
|
|
25
|
-
await this.verifyManifestExists(manifestPath);
|
|
26
|
-
// Update kubeconfig if provided in options
|
|
27
|
-
const kubectlConfig = {
|
|
28
|
-
...this.kubectlConfig,
|
|
29
|
-
kubeconfig: options.kubeconfig || this.kubectlConfig.kubeconfig
|
|
30
|
-
};
|
|
31
|
-
// Apply manifests with kubectl
|
|
32
|
-
const kubectlOutput = await this.applyManifests(manifestPath, options.timeout || 30, kubectlConfig);
|
|
33
|
-
return {
|
|
34
|
-
success: true,
|
|
35
|
-
solutionId: options.solutionId,
|
|
36
|
-
manifestPath,
|
|
37
|
-
readinessTimeout: false,
|
|
38
|
-
message: 'Deployment completed successfully',
|
|
39
|
-
kubectlOutput
|
|
40
|
-
};
|
|
41
|
-
}, {
|
|
42
|
-
operation: 'deploy',
|
|
43
|
-
component: 'deploy-operation'
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Get the manifest file path for the solution
|
|
48
|
-
*/
|
|
49
|
-
getManifestPath(options) {
|
|
50
|
-
const sessionDir = options.sessionDir || process.env.DOT_AI_SESSION_DIR;
|
|
51
|
-
if (!sessionDir) {
|
|
52
|
-
throw new Error('Session directory not configured. Set DOT_AI_SESSION_DIR environment variable or provide sessionDir parameter.');
|
|
53
|
-
}
|
|
54
|
-
return (0, path_1.join)(sessionDir, `${options.solutionId}.yaml`);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Verify that the manifest file exists
|
|
58
|
-
*/
|
|
59
|
-
async verifyManifestExists(manifestPath) {
|
|
60
|
-
try {
|
|
61
|
-
await (0, promises_1.access)(manifestPath);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
throw new Error(`Manifest file not found: ${manifestPath}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Apply manifests using kubectl with readiness checking
|
|
69
|
-
*/
|
|
70
|
-
async applyManifests(manifestPath, timeout, kubectlConfig) {
|
|
71
|
-
// First, apply the manifests
|
|
72
|
-
const applyResult = await (0, kubernetes_utils_1.executeKubectl)(['apply', '-f', `"${manifestPath}"`], kubectlConfig);
|
|
73
|
-
// Try to wait for deployments to be ready (ignore failures for other resource types)
|
|
74
|
-
let waitOutput = '';
|
|
75
|
-
try {
|
|
76
|
-
const waitResult = await (0, kubernetes_utils_1.executeKubectl)([
|
|
77
|
-
'wait',
|
|
78
|
-
'--for=condition=available',
|
|
79
|
-
'deployments',
|
|
80
|
-
'--all',
|
|
81
|
-
`--timeout=${timeout}s`,
|
|
82
|
-
'--all-namespaces'
|
|
83
|
-
], {
|
|
84
|
-
...kubectlConfig,
|
|
85
|
-
timeout: (timeout + 10) * 1000 // Add 10 seconds buffer for kubectl command itself
|
|
86
|
-
});
|
|
87
|
-
waitOutput = `\n\nWait output:\n${waitResult}`;
|
|
88
|
-
}
|
|
89
|
-
catch (waitError) {
|
|
90
|
-
// If no deployments found or wait fails, that's OK for ConfigMaps, Services, etc.
|
|
91
|
-
if (waitError.message && waitError.message.includes('no matching resources found')) {
|
|
92
|
-
waitOutput = '\n\nWait output: No deployments found to wait for (likely ConfigMaps, Services, etc.)';
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
waitOutput = `\n\nWait output: Warning - ${waitError.message}`;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return `Apply output:\n${applyResult}${waitOutput}`;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.DeployOperation = DeployOperation;
|