@vfarcic/dot-ai 0.5.1 → 0.6.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.
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/{src/cli.ts → dist/cli.js} +19 -26
- package/dist/core/claude.d.ts +42 -0
- package/dist/core/claude.d.ts.map +1 -0
- package/dist/core/claude.js +229 -0
- package/dist/core/deploy-operation.d.ts +38 -0
- package/dist/core/deploy-operation.d.ts.map +1 -0
- package/dist/core/deploy-operation.js +101 -0
- package/dist/core/discovery.d.ts +162 -0
- package/dist/core/discovery.d.ts.map +1 -0
- package/dist/core/discovery.js +758 -0
- package/dist/core/error-handling.d.ts +167 -0
- package/dist/core/error-handling.d.ts.map +1 -0
- package/dist/core/error-handling.js +399 -0
- package/dist/core/index.d.ts +42 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +123 -0
- package/dist/core/kubernetes-utils.d.ts +38 -0
- package/dist/core/kubernetes-utils.d.ts.map +1 -0
- package/dist/core/kubernetes-utils.js +177 -0
- package/dist/core/memory.d.ts +45 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +113 -0
- package/dist/core/schema.d.ts +187 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +655 -0
- package/dist/core/session-utils.d.ts +29 -0
- package/dist/core/session-utils.d.ts.map +1 -0
- package/dist/core/session-utils.js +121 -0
- package/dist/core/workflow.d.ts +70 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +161 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/interfaces/cli.d.ts +74 -0
- package/dist/interfaces/cli.d.ts.map +1 -0
- package/dist/interfaces/cli.js +769 -0
- package/dist/interfaces/mcp.d.ts +30 -0
- package/dist/interfaces/mcp.d.ts.map +1 -0
- package/dist/interfaces/mcp.js +105 -0
- package/dist/mcp/server.d.ts +9 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +151 -0
- package/dist/tools/answer-question.d.ts +27 -0
- package/dist/tools/answer-question.d.ts.map +1 -0
- package/dist/tools/answer-question.js +696 -0
- package/dist/tools/choose-solution.d.ts +23 -0
- package/dist/tools/choose-solution.d.ts.map +1 -0
- package/dist/tools/choose-solution.js +171 -0
- package/dist/tools/deploy-manifests.d.ts +25 -0
- package/dist/tools/deploy-manifests.d.ts.map +1 -0
- package/dist/tools/deploy-manifests.js +74 -0
- package/dist/tools/generate-manifests.d.ts +23 -0
- package/dist/tools/generate-manifests.d.ts.map +1 -0
- package/dist/tools/generate-manifests.js +424 -0
- package/dist/tools/index.d.ts +11 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +34 -0
- package/dist/tools/recommend.d.ts +23 -0
- package/dist/tools/recommend.d.ts.map +1 -0
- package/dist/tools/recommend.js +332 -0
- package/package.json +124 -2
- package/.claude/commands/context-load.md +0 -11
- package/.claude/commands/context-save.md +0 -16
- package/.claude/commands/prd-done.md +0 -115
- package/.claude/commands/prd-get.md +0 -25
- package/.claude/commands/prd-start.md +0 -87
- package/.claude/commands/task-done.md +0 -77
- package/.claude/commands/tests-reminder.md +0 -32
- package/.claude/settings.local.json +0 -20
- package/.eslintrc.json +0 -25
- package/.github/workflows/ci.yml +0 -170
- package/.prettierrc.json +0 -10
- package/.teller.yml +0 -8
- package/CLAUDE.md +0 -162
- package/assets/images/logo.png +0 -0
- package/bin/dot-ai.ts +0 -47
- package/bin.js +0 -19
- package/destroy.sh +0 -45
- package/devbox.json +0 -13
- package/devbox.lock +0 -225
- package/docs/API.md +0 -449
- package/docs/CONTEXT.md +0 -49
- package/docs/DEVELOPMENT.md +0 -203
- package/docs/NEXT_STEPS.md +0 -97
- package/docs/STAGE_BASED_API.md +0 -97
- package/docs/cli-guide.md +0 -798
- package/docs/design.md +0 -750
- package/docs/discovery-engine.md +0 -515
- package/docs/error-handling.md +0 -429
- package/docs/function-registration.md +0 -157
- package/docs/mcp-guide.md +0 -416
- package/renovate.json +0 -51
- package/setup.sh +0 -111
- package/src/core/claude.ts +0 -280
- package/src/core/deploy-operation.ts +0 -127
- package/src/core/discovery.ts +0 -900
- package/src/core/error-handling.ts +0 -562
- package/src/core/index.ts +0 -143
- package/src/core/kubernetes-utils.ts +0 -218
- package/src/core/memory.ts +0 -148
- package/src/core/schema.ts +0 -830
- package/src/core/session-utils.ts +0 -97
- package/src/core/workflow.ts +0 -234
- package/src/index.ts +0 -18
- package/src/interfaces/cli.ts +0 -872
- package/src/interfaces/mcp.ts +0 -183
- package/src/mcp/server.ts +0 -131
- package/src/tools/answer-question.ts +0 -807
- package/src/tools/choose-solution.ts +0 -169
- package/src/tools/deploy-manifests.ts +0 -94
- package/src/tools/generate-manifests.ts +0 -502
- package/src/tools/index.ts +0 -41
- package/src/tools/recommend.ts +0 -370
- package/tests/__mocks__/@kubernetes/client-node.ts +0 -106
- package/tests/build-system.test.ts +0 -345
- package/tests/configuration.test.ts +0 -226
- package/tests/core/deploy-operation.test.ts +0 -38
- package/tests/core/discovery.test.ts +0 -1648
- package/tests/core/error-handling.test.ts +0 -632
- package/tests/core/schema.test.ts +0 -1658
- package/tests/core/session-utils.test.ts +0 -245
- package/tests/core.test.ts +0 -439
- package/tests/fixtures/configmap-no-labels.yaml +0 -8
- package/tests/fixtures/crossplane-app-configuration.yaml +0 -6
- package/tests/fixtures/crossplane-providers.yaml +0 -45
- package/tests/fixtures/crossplane-rbac.yaml +0 -48
- package/tests/fixtures/invalid-configmap.yaml +0 -8
- package/tests/fixtures/invalid-deployment.yaml +0 -17
- package/tests/fixtures/test-deployment.yaml +0 -28
- package/tests/fixtures/valid-configmap.yaml +0 -15
- package/tests/infrastructure.test.ts +0 -426
- package/tests/interfaces/cli.test.ts +0 -1036
- package/tests/interfaces/mcp.test.ts +0 -139
- package/tests/kubernetes-utils.test.ts +0 -200
- package/tests/mcp/server.test.ts +0 -126
- package/tests/setup.ts +0 -31
- package/tests/tools/answer-question.test.ts +0 -367
- package/tests/tools/choose-solution.test.ts +0 -481
- package/tests/tools/deploy-manifests.test.ts +0 -185
- package/tests/tools/generate-manifests.test.ts +0 -441
- package/tests/tools/index.test.ts +0 -111
- package/tests/tools/recommend.test.ts +0 -180
- package/tsconfig.json +0 -34
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Kubernetes Utilities
|
|
3
|
-
*
|
|
4
|
-
* Common functions for interacting with Kubernetes clusters
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { exec } from 'child_process';
|
|
8
|
-
import { promisify } from 'util';
|
|
9
|
-
|
|
10
|
-
const execAsync = promisify(exec);
|
|
11
|
-
|
|
12
|
-
// Enhanced interfaces for kubectl-based discovery
|
|
13
|
-
export interface KubectlConfig {
|
|
14
|
-
context?: string;
|
|
15
|
-
namespace?: string;
|
|
16
|
-
kubeconfig?: string;
|
|
17
|
-
timeout?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Execute kubectl command with proper configuration
|
|
22
|
-
*/
|
|
23
|
-
export async function executeKubectl(args: string[], config?: KubectlConfig): Promise<string> {
|
|
24
|
-
const command = buildKubectlCommand(args, config);
|
|
25
|
-
const timeout = config?.timeout || 30000;
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
const { stdout, stderr } = await execAsync(command, {
|
|
29
|
-
timeout,
|
|
30
|
-
maxBuffer: 100 * 1024 * 1024 // 100MB buffer for large clusters with 1000+ CRDs
|
|
31
|
-
});
|
|
32
|
-
if (stderr && !stderr.includes('Warning')) {
|
|
33
|
-
throw new Error(`kubectl command failed: ${stderr}`);
|
|
34
|
-
}
|
|
35
|
-
return stdout.trim();
|
|
36
|
-
} catch (error: any) {
|
|
37
|
-
if (error.code === 'ENOENT') {
|
|
38
|
-
throw new Error('kubectl binary not found. Please install kubectl and ensure it\'s in your PATH.');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Use error classification for better error messages
|
|
42
|
-
const classified = ErrorClassifier.classifyError(error);
|
|
43
|
-
throw new Error(classified.enhancedMessage);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Build kubectl command string with proper flags
|
|
49
|
-
*/
|
|
50
|
-
export function buildKubectlCommand(args: string[], config?: KubectlConfig): string {
|
|
51
|
-
let command = 'kubectl';
|
|
52
|
-
|
|
53
|
-
if (config?.kubeconfig) {
|
|
54
|
-
command += ` --kubeconfig=${config.kubeconfig}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (config?.context) {
|
|
58
|
-
command += ` --context=${config.context}`;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (config?.namespace) {
|
|
62
|
-
command += ` --namespace=${config.namespace}`;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
command += ` ${args.join(' ')}`;
|
|
66
|
-
return command;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Enhanced Error Classification System
|
|
70
|
-
export class ErrorClassifier {
|
|
71
|
-
static classifyError(error: Error): { type: string; enhancedMessage: string } {
|
|
72
|
-
const originalMessage = error.message;
|
|
73
|
-
|
|
74
|
-
// Connection and Network Errors
|
|
75
|
-
if (this.isNetworkError(originalMessage)) {
|
|
76
|
-
return {
|
|
77
|
-
type: 'network',
|
|
78
|
-
enhancedMessage: this.enhanceNetworkError(originalMessage)
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Authentication Errors
|
|
83
|
-
if (this.isAuthenticationError(originalMessage)) {
|
|
84
|
-
return {
|
|
85
|
-
type: 'authentication',
|
|
86
|
-
enhancedMessage: this.enhanceAuthenticationError(originalMessage)
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Authorization/RBAC Errors
|
|
91
|
-
if (this.isAuthorizationError(originalMessage)) {
|
|
92
|
-
return {
|
|
93
|
-
type: 'authorization',
|
|
94
|
-
enhancedMessage: this.enhanceAuthorizationError(originalMessage)
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// API Availability Errors
|
|
99
|
-
if (this.isAPIAvailabilityError(originalMessage)) {
|
|
100
|
-
return {
|
|
101
|
-
type: 'api-availability',
|
|
102
|
-
enhancedMessage: this.enhanceAPIAvailabilityError(originalMessage)
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Kubeconfig Validation Errors
|
|
107
|
-
if (this.isKubeconfigError(originalMessage)) {
|
|
108
|
-
return {
|
|
109
|
-
type: 'kubeconfig',
|
|
110
|
-
enhancedMessage: this.enhanceKubeconfigError(originalMessage)
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Version Compatibility Errors
|
|
115
|
-
if (this.isVersionCompatibilityError(originalMessage)) {
|
|
116
|
-
return {
|
|
117
|
-
type: 'version',
|
|
118
|
-
enhancedMessage: this.enhanceVersionCompatibilityError(originalMessage)
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Default: return original message with basic enhancement
|
|
123
|
-
return {
|
|
124
|
-
type: 'unknown',
|
|
125
|
-
enhancedMessage: `${originalMessage}\n\nTroubleshooting steps:\n- Run 'kubectl cluster-info' to verify cluster connectivity\n- Check your kubeconfig with 'kubectl config view'\n- Verify cluster endpoint accessibility`
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private static isNetworkError(message: string): boolean {
|
|
130
|
-
return /getaddrinfo ENOTFOUND|timeout|ECONNREFUSED|ENOTFOUND|network|unreachable/i.test(message);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private static isAuthenticationError(message: string): boolean {
|
|
134
|
-
return /unauthorized|invalid bearer token|certificate|auth|authentication/i.test(message);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
private static isAuthorizationError(message: string): boolean {
|
|
138
|
-
return /forbidden|cannot list|cannot get|cannot create|RBAC|permission denied/i.test(message);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private static isAPIAvailabilityError(message: string): boolean {
|
|
142
|
-
return /server could not find|resource type.*not found|doesn't have a resource type|no matches for kind/i.test(message);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private static isKubeconfigError(message: string): boolean {
|
|
146
|
-
// Be more specific - don't match "path does not exist" errors which are about manifest files
|
|
147
|
-
return /context.*does not exist|kubeconfig.*not found|invalid.*kubeconfig|config.*not found|no Auth Provider/i.test(message) &&
|
|
148
|
-
!/the path.*does not exist/.test(message);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
private static isVersionCompatibilityError(message: string): boolean {
|
|
152
|
-
return /server version|version.*old|unsupported.*version|api.*version/i.test(message);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
private static enhanceNetworkError(message: string): string {
|
|
156
|
-
if (message.includes('getaddrinfo ENOTFOUND')) {
|
|
157
|
-
return `DNS resolution failed: Cannot resolve cluster endpoint hostname.\n\nTroubleshooting steps:\n- Check cluster endpoint in kubeconfig: kubectl config view\n- Verify network connectivity and DNS settings\n- Confirm cluster is running and accessible\n- Check VPN connection if using private cluster\n\nOriginal error: ${message}`;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (message.includes('timeout')) {
|
|
161
|
-
return `Connection timeout: Unable to reach cluster within timeout period.\n\nTroubleshooting steps:\n- Check network latency to cluster endpoint\n- Increase timeout value if needed\n- Verify cluster is responsive: kubectl get nodes\n- Check firewall and proxy settings\n\nOriginal error: ${message}`;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return `Network connectivity issue detected.\n\nTroubleshooting steps:\n- Verify cluster endpoint accessibility\n- Run 'kubectl cluster-info' to test connectivity\n- Check network and firewall settings\n- Confirm cluster is running\n\nOriginal error: ${message}`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
private static enhanceAuthenticationError(message: string): string {
|
|
168
|
-
if (message.includes('invalid bearer token')) {
|
|
169
|
-
return `Token may be expired: Bearer token authentication failed.\n\nTroubleshooting steps:\n- Token may be expired - refresh credentials\n- Check token format in kubeconfig\n- Re-authenticate with cluster: kubectl auth login\n- Verify service account token if applicable\n\nOriginal error: ${message}`;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (message.includes('certificate')) {
|
|
173
|
-
return `Certificate authentication failed: Client certificate validation error.\n\nTroubleshooting steps:\n- Verify certificate path in kubeconfig\n- Check certificate expiration date\n- Ensure certificate authority (CA) bundle is correct\n- Re-generate client certificates if needed\n\nOriginal error: ${message}`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (message.includes('no Auth Provider found')) {
|
|
177
|
-
return `Authentication provider not available: Required auth plugin missing.\n\nTroubleshooting steps:\n- Install required authentication plugin (e.g., OIDC)\n- Check kubectl config for auth provider configuration\n- Verify authentication method compatibility\n- Consult cluster administrator for auth setup\n\nOriginal error: ${message}`;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return `Authentication failed: Invalid or missing credentials.\n\nTroubleshooting steps:\n- Verify credentials in kubeconfig\n- Re-authenticate with cluster\n- Check authentication method configuration\n- Contact cluster administrator if needed\n\nOriginal error: ${message}`;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
private static enhanceAuthorizationError(message: string): string {
|
|
184
|
-
if (message.includes('customresourcedefinitions')) {
|
|
185
|
-
return `CRD discovery requires cluster-level permissions: Insufficient RBAC permissions.\n\nTroubleshooting steps:\n- CRD discovery requires admin privileges\n- Request cluster-admin role or CRD read permissions\n- Contact cluster administrator for permission escalation\n- Use 'kubectl auth can-i list customresourcedefinitions' to check permissions\n\nOriginal error: ${message}`;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (message.includes('forbidden')) {
|
|
189
|
-
return `Insufficient permissions: RBAC restrictions prevent this operation.\n\nTroubleshooting steps:\n- RBAC role required for resource access\n- Request appropriate permissions from cluster administrator\n- Check current permissions: kubectl auth can-i list <resource>\n- Consider using cluster-admin role for discovery operations\n\nOriginal error: ${message}`;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return `Permission denied: Insufficient RBAC permissions for cluster access.\n\nTroubleshooting steps:\n- Request appropriate RBAC permissions\n- Check current access: kubectl auth can-i list <resource>\n- Contact cluster administrator for role assignment\n- Verify service account permissions if applicable\n\nOriginal error: ${message}`;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
private static enhanceAPIAvailabilityError(message: string): string {
|
|
196
|
-
if (message.includes('apps/v1beta1')) {
|
|
197
|
-
return `API version not supported: Cluster doesn't support requested API version.\n\nTroubleshooting steps:\n- Try different API version (e.g., apps/v1 instead of apps/v1beta1)\n- Check available API versions: kubectl api-versions\n- Verify Kubernetes cluster version compatibility\n- Consult API migration guides for version changes\n\nOriginal error: ${message}`;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return `API resource not available: Requested resource type not found in cluster.\n\nTroubleshooting steps:\n- Check available resources: kubectl api-resources\n- Verify cluster supports required resource types\n- Check Kubernetes version compatibility\n- Confirm cluster configuration and enabled APIs\n\nOriginal error: ${message}`;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private static enhanceKubeconfigError(message: string): string {
|
|
204
|
-
if (message.includes('context') && message.includes('does not exist')) {
|
|
205
|
-
return `Context not found: Specified context doesn't exist in kubeconfig.\n\nTroubleshooting steps:\n- List available contexts: kubectl config get-contexts\n- Set correct context: kubectl config use-context <context-name>\n- Verify kubeconfig file contains required context\n- Check context name spelling and case sensitivity\n\nOriginal error: ${message}`;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (message.includes('not found')) {
|
|
209
|
-
return `Kubeconfig file not found: Cannot locate configuration file.\n\nTroubleshooting steps:\n- Check file path exists and is accessible\n- Verify kubeconfig file permissions\n- Set KUBECONFIG environment variable if needed\n- Create kubeconfig file or copy from cluster administrator\n\nOriginal error: ${message}`;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return `Invalid kubeconfig format: Configuration file has syntax or format errors.\n\nTroubleshooting steps:\n- Validate YAML syntax in kubeconfig file\n- Check file structure: kubectl config view\n- Restore from backup or re-download from cluster\n- Verify all required sections (clusters, contexts, users)\n\nOriginal error: ${message}`;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private static enhanceVersionCompatibilityError(message: string): string {
|
|
216
|
-
return `Kubernetes version compatibility issue: Version mismatch detected.\n\nTroubleshooting steps:\n- Check cluster and client versions: kubectl version\n- Verify supported Kubernetes versions for this tool\n- Update kubectl client if needed\n- Consult compatibility matrix for version support\n\nOriginal error: ${message}`;
|
|
217
|
-
}
|
|
218
|
-
}
|
package/src/core/memory.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory System Module
|
|
3
|
-
*
|
|
4
|
-
* Handles learning, context management, and recommendation storage
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export interface SuccessPattern {
|
|
8
|
-
type: string;
|
|
9
|
-
config: any;
|
|
10
|
-
timestamp: Date;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface FailurePattern {
|
|
14
|
-
type: string;
|
|
15
|
-
config: any;
|
|
16
|
-
error: string;
|
|
17
|
-
timestamp: Date;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface Recommendation {
|
|
21
|
-
suggestion: string;
|
|
22
|
-
confidence: number;
|
|
23
|
-
based_on: string[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class MemorySystem {
|
|
27
|
-
private storage: Map<string, any> = new Map();
|
|
28
|
-
private successPatterns: Map<string, SuccessPattern[]> = new Map();
|
|
29
|
-
private failurePatterns: Map<string, FailurePattern[]> = new Map();
|
|
30
|
-
private context: Map<string, any> = new Map();
|
|
31
|
-
private initialized: boolean = false;
|
|
32
|
-
|
|
33
|
-
async initialize(): Promise<void> {
|
|
34
|
-
// Initialize storage (in production, this would connect to persistent storage)
|
|
35
|
-
this.initialized = true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async store(key: string, data: any): Promise<void> {
|
|
39
|
-
this.storage.set(key, data);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async retrieve(key: string): Promise<any> {
|
|
43
|
-
return this.storage.get(key) || null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async learnSuccess(type: string, config: any): Promise<void> {
|
|
47
|
-
const pattern: SuccessPattern = {
|
|
48
|
-
type,
|
|
49
|
-
config,
|
|
50
|
-
timestamp: new Date()
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const existing = this.successPatterns.get(type) || [];
|
|
54
|
-
existing.push(pattern);
|
|
55
|
-
this.successPatterns.set(type, existing);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async learnFailure(type: string, config: any, error: string): Promise<void> {
|
|
59
|
-
const pattern: FailurePattern = {
|
|
60
|
-
type,
|
|
61
|
-
config,
|
|
62
|
-
error,
|
|
63
|
-
timestamp: new Date()
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const existing = this.failurePatterns.get(type) || [];
|
|
67
|
-
existing.push(pattern);
|
|
68
|
-
this.failurePatterns.set(type, existing);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async getSuccessPatterns(type: string): Promise<SuccessPattern[]> {
|
|
72
|
-
return this.successPatterns.get(type) || [];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async getFailurePatterns(type: string): Promise<FailurePattern[]> {
|
|
76
|
-
return this.failurePatterns.get(type) || [];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async getRecommendations(type: string, partialConfig: any): Promise<Recommendation[]> {
|
|
80
|
-
const successPatterns = await this.getSuccessPatterns(type);
|
|
81
|
-
const recommendations: Recommendation[] = [];
|
|
82
|
-
|
|
83
|
-
// Simple recommendation algorithm
|
|
84
|
-
for (const pattern of successPatterns) {
|
|
85
|
-
const similarity = this.calculateSimilarity(partialConfig, pattern.config);
|
|
86
|
-
if (similarity >= 0.5) {
|
|
87
|
-
recommendations.push({
|
|
88
|
-
suggestion: `Consider using configuration similar to successful ${type}`,
|
|
89
|
-
confidence: similarity,
|
|
90
|
-
based_on: [`Success pattern from ${pattern.timestamp.toISOString()}`]
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return recommendations;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async storePattern(type: string, pattern: any): Promise<void> {
|
|
99
|
-
// Store pattern as a success by default
|
|
100
|
-
await this.learnSuccess(type, pattern);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async retrievePattern(type: string): Promise<any[]> {
|
|
104
|
-
const patterns = await this.getSuccessPatterns(type);
|
|
105
|
-
return patterns.map(p => p.config);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async storeLessons(type: string, lessons: any): Promise<void> {
|
|
109
|
-
// Store lessons in the general storage
|
|
110
|
-
await this.store(`lessons-${type}`, lessons);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private calculateSimilarity(config1: any, config2: any): number {
|
|
114
|
-
// Simple similarity calculation
|
|
115
|
-
const keys1 = Object.keys(config1);
|
|
116
|
-
const keys2 = Object.keys(config2);
|
|
117
|
-
const commonKeys = keys1.filter(key => keys2.includes(key));
|
|
118
|
-
|
|
119
|
-
if (keys1.length === 0 && keys2.length === 0) return 1;
|
|
120
|
-
if (keys1.length === 0 || keys2.length === 0) return 0;
|
|
121
|
-
|
|
122
|
-
return commonKeys.length / Math.max(keys1.length, keys2.length);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async setContext(key: string, value: any): Promise<void> {
|
|
126
|
-
this.context.set(key, value);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async getContext(): Promise<Record<string, any>> {
|
|
130
|
-
const result: Record<string, any> = {};
|
|
131
|
-
for (const [key, value] of this.context.entries()) {
|
|
132
|
-
result[key] = value;
|
|
133
|
-
}
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async clearContext(key?: string): Promise<void> {
|
|
138
|
-
if (key) {
|
|
139
|
-
this.context.delete(key);
|
|
140
|
-
} else {
|
|
141
|
-
this.context.clear();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
isInitialized(): boolean {
|
|
146
|
-
return this.initialized;
|
|
147
|
-
}
|
|
148
|
-
}
|