@vfarcic/dot-ai 0.80.0 → 0.82.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/core/schema.js
CHANGED
|
@@ -821,7 +821,7 @@ class ResourceRecommender {
|
|
|
821
821
|
if (this.policyService) {
|
|
822
822
|
try {
|
|
823
823
|
const resourceContext = solution.resources.map(r => `${r.kind} ${r.description}`).join(' ');
|
|
824
|
-
const policyResults = await this.policyService.searchPolicyIntents(`${intent} ${resourceContext}`, { limit:
|
|
824
|
+
const policyResults = await this.policyService.searchPolicyIntents(`${intent} ${resourceContext}`, { limit: 50 });
|
|
825
825
|
relevantPolicyResults = policyResults.map(result => ({
|
|
826
826
|
policy: result.data,
|
|
827
827
|
score: result.score,
|
|
@@ -839,7 +839,7 @@ Please try again or modify your policy description.`,
|
|
|
839
839
|
const capabilityService = new capability_vector_service_1.CapabilityVectorService();
|
|
840
840
|
// Use existing searchCapabilities function - no fallback, let it throw if it fails
|
|
841
841
|
const searchResults = await capabilityService.searchCapabilities(searchQuery, {
|
|
842
|
-
limit:
|
|
842
|
+
limit: 50 // Higher limit to get more relevant resources - aligns with recommendation tool
|
|
843
843
|
});
|
|
844
844
|
if (searchResults.length === 0) {
|
|
845
845
|
throw new Error(`No relevant capabilities found for policy description: "${policyDescription}"`);
|
|
@@ -5,7 +5,7 @@ import { z } from 'zod';
|
|
|
5
5
|
import { DotAI } from '../core/index';
|
|
6
6
|
import { Logger } from '../core/error-handling';
|
|
7
7
|
export declare const RECOMMEND_TOOL_NAME = "recommend";
|
|
8
|
-
export declare const RECOMMEND_TOOL_DESCRIPTION = "Deploy, create, setup, install, or run applications, infrastructure, and services on Kubernetes with AI recommendations. Describe what you want to deploy.";
|
|
8
|
+
export declare const RECOMMEND_TOOL_DESCRIPTION = "Deploy, create, setup, install, or run applications, infrastructure, and services on Kubernetes with AI recommendations. Describe what you want to deploy. Does NOT handle policy creation, organizational patterns, or resource capabilities - use manageOrgData for those.";
|
|
9
9
|
export declare const RECOMMEND_TOOL_INPUT_SCHEMA: {
|
|
10
10
|
intent: z.ZodString;
|
|
11
11
|
final: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recommend.d.ts","sourceRoot":"","sources":["../../src/tools/recommend.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAQhD,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAC/C,eAAO,MAAM,0BAA0B
|
|
1
|
+
{"version":3,"file":"recommend.d.ts","sourceRoot":"","sources":["../../src/tools/recommend.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAQhD,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAC/C,eAAO,MAAM,0BAA0B,iRAAiR,CAAC;AAGzT,eAAO,MAAM,2BAA2B;;;CAGvC,CAAC;AA2EF;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,EACzC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,CAAC,CAoQxD"}
|
package/dist/tools/recommend.js
CHANGED
|
@@ -49,7 +49,7 @@ const crypto = __importStar(require("crypto"));
|
|
|
49
49
|
const session_utils_1 = require("../core/session-utils");
|
|
50
50
|
// Tool metadata for direct MCP registration
|
|
51
51
|
exports.RECOMMEND_TOOL_NAME = 'recommend';
|
|
52
|
-
exports.RECOMMEND_TOOL_DESCRIPTION = 'Deploy, create, setup, install, or run applications, infrastructure, and services on Kubernetes with AI recommendations. Describe what you want to deploy.';
|
|
52
|
+
exports.RECOMMEND_TOOL_DESCRIPTION = 'Deploy, create, setup, install, or run applications, infrastructure, and services on Kubernetes with AI recommendations. Describe what you want to deploy. Does NOT handle policy creation, organizational patterns, or resource capabilities - use manageOrgData for those.';
|
|
53
53
|
// Zod schema for MCP registration
|
|
54
54
|
exports.RECOMMEND_TOOL_INPUT_SCHEMA = {
|
|
55
55
|
intent: zod_1.z.string().min(1).max(1000).describe('What the user wants to deploy, create, setup, install, or run on Kubernetes. Examples: "deploy web application", "create PostgreSQL database", "setup Redis cache", "install Prometheus monitoring", "configure Ingress controller", "provision storage volumes", "launch MongoDB operator", "run Node.js API", "setup CI/CD pipeline", "create load balancer", "install Grafana dashboard", "deploy React frontend"'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vfarcic/dot-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.82.0",
|
|
4
4
|
"description": "AI-powered development productivity platform that enhances software development workflows through intelligent automation and AI-driven assistance",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,18 +27,72 @@ You are a Kubernetes governance expert specializing in Kyverno policy generation
|
|
|
27
27
|
**RETRY CONTEXT**: If this is a retry attempt (indicated by previous attempt details above), analyze the validation errors carefully and fix the specific issues identified. Common validation failures include:
|
|
28
28
|
- Invalid YAML syntax
|
|
29
29
|
- Invalid CEL expressions using `request.object` instead of `object`
|
|
30
|
+
- **Invalid message template variables** - Kyverno has strict limits on variable substitution in messages
|
|
30
31
|
- References to non-existent fields in resource schemas
|
|
31
32
|
- Incorrect resource kind/apiVersion combinations
|
|
32
33
|
- Using invalid Kyverno match fields like `apiGroups`, `versions`, or `apiVersions` (use Group/Version/Kind format in kinds array)
|
|
33
34
|
- kubectl dry-run server-side validation failures
|
|
34
35
|
- CEL compilation errors at runtime due to undefined fields
|
|
35
36
|
|
|
37
|
+
## ⚠️ **CRITICAL MESSAGE TEMPLATE RULES**
|
|
38
|
+
|
|
39
|
+
**IMPORTANT**: Kyverno message templates have strict variable validation requirements. Follow these rules to avoid validation failures:
|
|
40
|
+
|
|
41
|
+
**❌ NEVER use these patterns in messages:**
|
|
42
|
+
```yaml
|
|
43
|
+
# These will cause validation failures:
|
|
44
|
+
message: "Current region: {{ object.spec.forProvider.region || 'not specified' }}"
|
|
45
|
+
message: "Field value: {{ object.spec.field || 'missing' }}"
|
|
46
|
+
message: "Invalid image: {{ object.spec.container.image }}"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**✅ ALWAYS use static descriptive messages:**
|
|
50
|
+
```yaml
|
|
51
|
+
# These will work correctly:
|
|
52
|
+
message: "Resources must be deployed in the us-east1 region for compliance"
|
|
53
|
+
message: "Container images must not use the 'latest' tag"
|
|
54
|
+
message: "All pods must define resource limits"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Rule**: Keep error messages **static and descriptive** without dynamic field references. Focus on explaining the policy requirement clearly rather than showing current values.
|
|
58
|
+
|
|
59
|
+
## 🔧 **CEL EXPRESSION BEST PRACTICES**
|
|
60
|
+
|
|
61
|
+
**Critical patterns for robust CEL expressions:**
|
|
62
|
+
|
|
63
|
+
**✅ Always check field existence before accessing:**
|
|
64
|
+
```yaml
|
|
65
|
+
# CORRECT - Check field exists first
|
|
66
|
+
expression: >-
|
|
67
|
+
has(object.spec) && has(object.spec.forProvider) &&
|
|
68
|
+
has(object.spec.forProvider.region) &&
|
|
69
|
+
object.spec.forProvider.region == 'us-east1'
|
|
70
|
+
|
|
71
|
+
# CORRECT - Alternative safe pattern
|
|
72
|
+
expression: >-
|
|
73
|
+
!has(object.spec.forProvider.region) ||
|
|
74
|
+
object.spec.forProvider.region == 'us-east1'
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**❌ Never access fields without checking existence:**
|
|
78
|
+
```yaml
|
|
79
|
+
# WRONG - Will fail if fields don't exist
|
|
80
|
+
expression: object.spec.forProvider.region == 'us-east1'
|
|
81
|
+
expression: object.spec.initProvider.region == 'us-east1'
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Field Existence Patterns:**
|
|
85
|
+
- **Required fields**: Use `has(object.spec.field) && object.spec.field == 'value'`
|
|
86
|
+
- **Optional fields**: Use `!has(object.spec.field) || object.spec.field == 'value'`
|
|
87
|
+
- **Nested fields**: Check each level: `has(object.spec) && has(object.spec.nested) && has(object.spec.nested.field)`
|
|
88
|
+
|
|
36
89
|
## 🛡️ KYVERNO POLICY GENERATION PRINCIPLES
|
|
37
90
|
|
|
38
91
|
**Core Requirements:**
|
|
39
92
|
- **Single ClusterPolicy** - Generate one ClusterPolicy with multiple rules if needed to handle different resource schemas
|
|
40
93
|
- **CEL Expressions Only** - Use CEL (Common Expression Language) for all validation logic, never JMESPath patterns
|
|
41
94
|
- **Intelligent Resource Selection** - Only target resource types where the policy intent logically applies
|
|
95
|
+
- **Provider-Aware Filtering** - Only include resources matching the provider context from the policy intent
|
|
42
96
|
- **Schema-Accurate Targeting** - Only reference fields that actually exist in the targeted resource schemas
|
|
43
97
|
- **Multiple Rules for Different Schemas** - Use separate rules when different resource types have different field structures
|
|
44
98
|
- **New Resource Targeting** - Set `background: false` to apply only to new/updated resources
|
|
@@ -114,22 +168,63 @@ Create a mental checklist for EVERY schema provided:
|
|
|
114
168
|
- NO SHORTCUTS: Don't skip resources because they're custom or unfamiliar
|
|
115
169
|
- FIELD-BASED DECISIONS ONLY: Base inclusion solely on presence of relevant fields
|
|
116
170
|
|
|
117
|
-
**VALIDATION CHECK**: Before finalizing the policy, verify that you have generated rules for ALL resources with policy-relevant fields. If any resource with relevant fields lacks a rule, the policy is INCOMPLETE and INVALID.
|
|
171
|
+
**VALIDATION CHECK**: Before finalizing the policy, verify that you have generated rules for ALL resources with policy-relevant fields AND matching provider context. If any resource with relevant fields and matching provider lacks a rule, the policy is INCOMPLETE and INVALID.
|
|
172
|
+
|
|
173
|
+
## 🌐 UNIVERSAL PROVIDER FILTERING
|
|
174
|
+
|
|
175
|
+
**CRITICAL**: If the policy intent mentions ANY provider context (cloud providers, deployment targets), you MUST filter resources to include ONLY those matching the specified context.
|
|
176
|
+
|
|
177
|
+
### Provider Context Extraction
|
|
178
|
+
|
|
179
|
+
**Extract provider/deployment context from policy intent:**
|
|
180
|
+
|
|
181
|
+
- **Cloud Providers**: "AWS", "GCP", "Azure", "UpCloud", "DigitalOcean", etc.
|
|
182
|
+
- **Multi-Cloud**: "multi-cloud", "AWS and Azure", "across providers"
|
|
183
|
+
- **Kubernetes-Native**: "in Kubernetes", "Kubernetes cluster", "native", "in-cluster"
|
|
184
|
+
- **External Services**: "cloud services", "managed services"
|
|
185
|
+
|
|
186
|
+
### Resource Provider Detection
|
|
187
|
+
|
|
188
|
+
**Analyze each resource schema to determine provider affiliation:**
|
|
189
|
+
|
|
190
|
+
1. **CRD Description**: Look for provider names in main description
|
|
191
|
+
2. **Field Descriptions**: Check field docs for provider mentions/regions/limitations
|
|
192
|
+
3. **Provider Sections**: Look for `spec.aws`, `spec.gcp`, `spec.upcloud` etc.
|
|
193
|
+
4. **API Groups**: Use domain patterns as fallback (`*.gcp.`, `*.upcloud.com`)
|
|
194
|
+
5. **Core Resources**: Pod, Service, etc. are always Kubernetes-native
|
|
195
|
+
|
|
196
|
+
### Resource Classification
|
|
197
|
+
|
|
198
|
+
- **External Cloud Services**: Provision services in cloud providers (RDS, Cloud SQL, etc.)
|
|
199
|
+
- **Kubernetes-Native**: Run workloads inside cluster (CNPG, core resources, etc.)
|
|
200
|
+
- **Multi-Cloud**: Support multiple providers
|
|
201
|
+
|
|
202
|
+
### Provider Filtering Rules
|
|
203
|
+
|
|
204
|
+
- **Cloud Provider Intent**: Include resources that support the specified provider
|
|
205
|
+
- **Kubernetes-Native Intent**: Include resources that run in-cluster
|
|
206
|
+
- **Provider-Agnostic Intent**: Include all relevant resources
|
|
118
207
|
|
|
119
208
|
## 🔍 EXPLICIT RESOURCE ANALYSIS REQUIREMENT
|
|
120
209
|
|
|
121
210
|
**MANDATORY SCHEMA ACCOUNTING**: Before generating the policy, you MUST explicitly account for EVERY schema provided. Include this analysis as YAML comments at the top of the generated policy.
|
|
122
211
|
|
|
123
212
|
**For EVERY schema in the "Available Resource Schemas" section above:**
|
|
124
|
-
Include a concise comment line
|
|
213
|
+
Include a concise comment line explaining why each resource is included or skipped, considering BOTH field relevance AND provider context.
|
|
214
|
+
|
|
215
|
+
**Comment Format Examples:**
|
|
216
|
+
- `ResourceName: HAS field.path + supports GCP → MUST generate rule`
|
|
217
|
+
- `ResourceName: NO relevant fields → Can skip`
|
|
218
|
+
- `ResourceName: HAS field.path but UpCloud only → Can skip (provider mismatch)`
|
|
219
|
+
- `ResourceName: HAS field.path + Kubernetes-native → Can skip (cloud services intent)`
|
|
220
|
+
- `ResourceName: HAS field.path + multi-cloud → MUST generate rule`
|
|
125
221
|
|
|
126
|
-
**CRITICAL
|
|
127
|
-
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
- If analyzing a resource with only networking fields → Can skip (for non-networking policies)
|
|
222
|
+
**CRITICAL ANALYSIS** (adapt to your actual policy and intent):
|
|
223
|
+
- **Field Relevance**: Does the resource have fields matching the policy requirements?
|
|
224
|
+
- **Provider Context**: Does the resource support the providers/deployment targets mentioned in the intent?
|
|
225
|
+
- **Both Required**: Resource needs BOTH relevant fields AND matching provider context to require a rule
|
|
131
226
|
|
|
132
|
-
**FAILURE TO ANALYZE = INVALID POLICY**: If you generate a policy without systematically considering every schema, the policy is incomplete and violates the requirements.
|
|
227
|
+
**FAILURE TO ANALYZE = INVALID POLICY**: If you generate a policy without systematically considering every schema for both field relevance and provider context, the policy is incomplete and violates the requirements.
|
|
133
228
|
|
|
134
229
|
**OUTPUT FORMAT**: Include your systematic schema analysis as YAML comments at the beginning of the policy file, followed by the clean YAML manifest.
|
|
135
230
|
|
|
@@ -152,7 +247,7 @@ Include a concise comment line in format: `ResourceName: HAS field.path → MUST
|
|
|
152
247
|
**CRITICAL CEL SYNTAX RULES:**
|
|
153
248
|
- ✅ **CORRECT**: `object.spec.containers` - Use `object` to reference the resource being validated
|
|
154
249
|
- ❌ **WRONG**: `request.object.spec.containers` - Do NOT use `request.object` prefix
|
|
155
|
-
- ✅ **CORRECT**: `
|
|
250
|
+
- ✅ **CORRECT**: `'app' in object.metadata.labels`
|
|
156
251
|
- ❌ **WRONG**: `has(request.object.metadata.labels['app'])`
|
|
157
252
|
|
|
158
253
|
**KYVERNO MATCH SCHEMA RULES:**
|
|
@@ -304,11 +399,12 @@ spec:
|
|
|
304
399
|
**OUTPUT FORMAT EXAMPLE**:
|
|
305
400
|
# MANDATORY SCHEMA-BY-SCHEMA ANALYSIS
|
|
306
401
|
#
|
|
307
|
-
#
|
|
308
|
-
#
|
|
402
|
+
# sqls.devopstoolkit.live: HAS spec.region + supports GCP → MUST generate rule
|
|
403
|
+
# manageddatabasemysqls.database.upcloud.com: HAS spec.region but UpCloud only → Can skip (provider mismatch)
|
|
404
|
+
# Pod: HAS spec.containers[].image + Kubernetes-native → Can skip (cloud services intent)
|
|
309
405
|
# ConfigMap: NO relevant fields → Can skip
|
|
310
406
|
#
|
|
311
|
-
# RESOURCES REQUIRING VALIDATION RULES:
|
|
407
|
+
# RESOURCES REQUIRING VALIDATION RULES: sqls.devopstoolkit.live
|
|
312
408
|
#
|
|
313
409
|
apiVersion: kyverno.io/v1
|
|
314
410
|
kind: ClusterPolicy
|