@vfarcic/dot-ai 0.72.0 → 0.73.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/README.md +36 -1
- package/dist/core/capabilities.d.ts.map +1 -1
- package/dist/core/capabilities.js +6 -51
- package/dist/core/claude.d.ts +2 -0
- package/dist/core/claude.d.ts.map +1 -1
- package/dist/core/claude.js +24 -15
- package/dist/core/doc-testing-session.d.ts.map +1 -1
- package/dist/core/doc-testing-session.js +42 -60
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +4 -3
- package/dist/core/organizational-types.d.ts +43 -0
- package/dist/core/organizational-types.d.ts.map +1 -0
- package/dist/core/organizational-types.js +8 -0
- package/dist/core/pattern-types.d.ts +1 -10
- package/dist/core/pattern-types.d.ts.map +1 -1
- package/dist/core/policy-vector-service.d.ts +28 -0
- package/dist/core/policy-vector-service.d.ts.map +1 -0
- package/dist/core/policy-vector-service.js +64 -0
- package/dist/core/schema.d.ts +3 -5
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +85 -24
- package/dist/core/shared-prompt-loader.d.ts +13 -0
- package/dist/core/shared-prompt-loader.d.ts.map +1 -0
- package/dist/core/shared-prompt-loader.js +64 -0
- package/dist/core/unified-creation-session.d.ts +83 -0
- package/dist/core/unified-creation-session.d.ts.map +1 -0
- package/dist/core/unified-creation-session.js +943 -0
- package/dist/core/unified-creation-types.d.ts +58 -0
- package/dist/core/unified-creation-types.d.ts.map +1 -0
- package/dist/core/unified-creation-types.js +61 -0
- package/dist/core/vector-db-service.d.ts.map +1 -1
- package/dist/core/vector-db-service.js +10 -1
- package/dist/tools/answer-question.d.ts.map +1 -1
- package/dist/tools/answer-question.js +3 -4
- package/dist/tools/generate-manifests.d.ts.map +1 -1
- package/dist/tools/generate-manifests.js +25 -70
- package/dist/tools/organizational-data.d.ts +2 -2
- package/dist/tools/organizational-data.d.ts.map +1 -1
- package/dist/tools/organizational-data.js +650 -62
- package/dist/tools/version.d.ts +30 -3
- package/dist/tools/version.d.ts.map +1 -1
- package/dist/tools/version.js +200 -27
- package/package.json +1 -1
- package/prompts/infrastructure-trigger-expansion.md +26 -0
- package/prompts/infrastructure-triggers.md +11 -0
- package/prompts/kyverno-generation.md +317 -0
- package/prompts/pattern-complete-error.md +1 -0
- package/prompts/pattern-complete-success.md +8 -0
- package/prompts/pattern-created-by.md +1 -0
- package/prompts/pattern-description.md +7 -0
- package/prompts/pattern-rationale.md +1 -0
- package/prompts/pattern-resources.md +1 -0
- package/prompts/pattern-review.md +9 -0
- package/prompts/policy-complete-apply.md +12 -0
- package/prompts/policy-complete-discard.md +5 -0
- package/prompts/policy-complete-error.md +1 -0
- package/prompts/policy-complete-save.md +12 -0
- package/prompts/policy-complete-success.md +7 -0
- package/prompts/policy-created-by.md +1 -0
- package/prompts/policy-description.md +9 -0
- package/prompts/policy-namespace-scope.md +43 -0
- package/prompts/policy-rationale.md +1 -0
- package/prompts/question-generation.md +27 -0
- package/prompts/resource-selection.md +6 -2
- package/shared-prompts/manage-org-data.md +20 -9
- package/dist/core/pattern-creation-session.d.ts +0 -43
- package/dist/core/pattern-creation-session.d.ts.map +0 -1
- package/dist/core/pattern-creation-session.js +0 -312
- package/dist/core/pattern-creation-types.d.ts +0 -30
- package/dist/core/pattern-creation-types.d.ts.map +0 -1
- package/dist/core/pattern-creation-types.js +0 -8
- package/shared-prompts/context-load.md +0 -19
- package/shared-prompts/context-save.md +0 -24
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Policy Vector Service
|
|
4
|
+
*
|
|
5
|
+
* Handles policy intent-specific Vector DB operations
|
|
6
|
+
* Extends BaseVectorService for policy intents
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PolicyVectorService = void 0;
|
|
10
|
+
const base_vector_service_1 = require("./base-vector-service");
|
|
11
|
+
class PolicyVectorService extends base_vector_service_1.BaseVectorService {
|
|
12
|
+
constructor(vectorDB, embeddingService) {
|
|
13
|
+
super('policies', vectorDB, embeddingService);
|
|
14
|
+
}
|
|
15
|
+
// Implement abstract methods from BaseVectorService
|
|
16
|
+
createSearchText(policyIntent) {
|
|
17
|
+
const triggerText = policyIntent.triggers.join(' ');
|
|
18
|
+
return `${policyIntent.description} ${triggerText} ${policyIntent.rationale}`.toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
extractId(policyIntent) {
|
|
21
|
+
return policyIntent.id;
|
|
22
|
+
}
|
|
23
|
+
createPayload(policyIntent) {
|
|
24
|
+
return {
|
|
25
|
+
description: policyIntent.description,
|
|
26
|
+
triggers: policyIntent.triggers.map(t => t.toLowerCase()),
|
|
27
|
+
rationale: policyIntent.rationale,
|
|
28
|
+
createdAt: policyIntent.createdAt,
|
|
29
|
+
createdBy: policyIntent.createdBy,
|
|
30
|
+
deployedPolicies: policyIntent.deployedPolicies || []
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
payloadToData(payload) {
|
|
34
|
+
return {
|
|
35
|
+
id: '', // Will be set from document ID in base class
|
|
36
|
+
description: payload.description,
|
|
37
|
+
triggers: payload.triggers,
|
|
38
|
+
rationale: payload.rationale,
|
|
39
|
+
createdAt: payload.createdAt,
|
|
40
|
+
createdBy: payload.createdBy,
|
|
41
|
+
deployedPolicies: payload.deployedPolicies || []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Public API methods - delegate to base class with appropriate names
|
|
45
|
+
async storePolicyIntent(policyIntent) {
|
|
46
|
+
await this.storeData(policyIntent);
|
|
47
|
+
}
|
|
48
|
+
async searchPolicyIntents(query, options = {}) {
|
|
49
|
+
return await this.searchData(query, options);
|
|
50
|
+
}
|
|
51
|
+
async getPolicyIntent(id) {
|
|
52
|
+
return await this.getData(id);
|
|
53
|
+
}
|
|
54
|
+
async getAllPolicyIntents() {
|
|
55
|
+
return await this.getAllData();
|
|
56
|
+
}
|
|
57
|
+
async deletePolicyIntent(id) {
|
|
58
|
+
await this.deleteData(id);
|
|
59
|
+
}
|
|
60
|
+
async getPolicyIntentsCount() {
|
|
61
|
+
return await this.getDataCount();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.PolicyVectorService = PolicyVectorService;
|
package/dist/core/schema.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface ResourceSchema {
|
|
|
32
32
|
properties: Map<string, SchemaField>;
|
|
33
33
|
required?: string[];
|
|
34
34
|
namespace?: boolean;
|
|
35
|
+
resourceName?: string;
|
|
35
36
|
rawExplanation?: string;
|
|
36
37
|
}
|
|
37
38
|
export interface ValidationResult {
|
|
@@ -153,6 +154,7 @@ export declare class ResourceRecommender {
|
|
|
153
154
|
private config;
|
|
154
155
|
private patternService?;
|
|
155
156
|
private capabilityService?;
|
|
157
|
+
private policyService?;
|
|
156
158
|
constructor(config: AIRankingConfig);
|
|
157
159
|
/**
|
|
158
160
|
* Find the best resource solution(s) for user intent using two-phase analysis
|
|
@@ -228,11 +230,7 @@ export declare class ResourceRecommender {
|
|
|
228
230
|
: 'No organizational patterns found for this request.';
|
|
229
231
|
|
|
230
232
|
|
|
231
|
-
const
|
|
232
|
-
const path = await import('path');
|
|
233
|
-
|
|
234
|
-
const promptPath = path.join(__dirname, '..', '..', 'prompts', 'resource-selection.md');
|
|
235
|
-
const template = fs.readFileSync(promptPath, 'utf8');
|
|
233
|
+
const template = loadPrompt('resource-selection');
|
|
236
234
|
|
|
237
235
|
const selectionPrompt = template
|
|
238
236
|
.replace('{intent}', intent)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":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B,CAAC;IA+C3I;;OAEG;IACH,OAAO,CAAC,uBAAuB;CAWhC;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,cAAc,CAAC,CAAuB;IAC9C,OAAO,CAAC,iBAAiB,CAAC,CAA0B;IACpD,OAAO,CAAC,aAAa,CAAC,CAAsB;gBAEhC,MAAM,EAAE,eAAe;IAmCnC;;OAEG;IACG,iBAAiB,CACrB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,GACnD,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAyE9B;;OAEG;YACW,wBAAwB;IAiBtC;;OAEG;IACH,OAAO,CAAC,2BAA2B;IA+CnC;;OAEG;YACW,0BAA0B;IA6CxC;;OAEG;YACW,0BAA0B;IAuFxC;;OAEG;IACH,OAAO,CAAC,8BAA8B;IAOtC;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAanC;;OAEG;IACH,OAAO,CAAC,4BAA4B;IASpC;;OAEG;IACH,OAAO,CAAC,mCAAmC;IAU3C;;;OAGG;YACW,sBAAsB;IAsBpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8FG;YACW,oBAAoB;IAmDlC;;OAEG;YACW,sBAAsB;IAiEpC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAgCjC;;OAEG;YACW,uBAAuB;CAqItC"}
|
package/dist/core/schema.js
CHANGED
|
@@ -45,6 +45,8 @@ const claude_1 = require("./claude");
|
|
|
45
45
|
const pattern_vector_service_1 = require("./pattern-vector-service");
|
|
46
46
|
const vector_db_service_1 = require("./vector-db-service");
|
|
47
47
|
const capability_vector_service_1 = require("./capability-vector-service");
|
|
48
|
+
const policy_vector_service_1 = require("./policy-vector-service");
|
|
49
|
+
const shared_prompt_loader_1 = require("./shared-prompt-loader");
|
|
48
50
|
/**
|
|
49
51
|
* SchemaParser converts kubectl explain output to structured ResourceSchema
|
|
50
52
|
*/
|
|
@@ -263,6 +265,7 @@ class ResourceRecommender {
|
|
|
263
265
|
config;
|
|
264
266
|
patternService;
|
|
265
267
|
capabilityService;
|
|
268
|
+
policyService;
|
|
266
269
|
constructor(config) {
|
|
267
270
|
this.config = config;
|
|
268
271
|
this.claudeIntegration = new claude_1.ClaudeIntegration(config.claudeApiKey);
|
|
@@ -286,6 +289,16 @@ class ResourceRecommender {
|
|
|
286
289
|
console.warn('⚠️ Vector DB not available, patterns disabled:', error);
|
|
287
290
|
this.patternService = undefined;
|
|
288
291
|
}
|
|
292
|
+
// Initialize policy service only if Vector DB is available
|
|
293
|
+
try {
|
|
294
|
+
const policyVectorDB = new vector_db_service_1.VectorDBService({ collectionName: 'policies' });
|
|
295
|
+
this.policyService = new policy_vector_service_1.PolicyVectorService(policyVectorDB);
|
|
296
|
+
console.log('✅ Policy service initialized with Vector DB');
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
console.warn('⚠️ Vector DB not available, policies disabled:', error);
|
|
300
|
+
this.policyService = undefined;
|
|
301
|
+
}
|
|
289
302
|
}
|
|
290
303
|
/**
|
|
291
304
|
* Find the best resource solution(s) for user intent using two-phase analysis
|
|
@@ -305,14 +318,19 @@ class ResourceRecommender {
|
|
|
305
318
|
`Note: Vector DB is required for capability-based recommendations.`);
|
|
306
319
|
}
|
|
307
320
|
let relevantCapabilities = [];
|
|
308
|
-
|
|
309
|
-
|
|
321
|
+
if (this.capabilityService) {
|
|
322
|
+
try {
|
|
323
|
+
relevantCapabilities = await this.capabilityService.searchCapabilities(intent, { limit: 50 });
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
// Capability search failed - fail fast with clear guidance
|
|
327
|
+
throw new Error(`Capability search failed for intent "${intent}". Please scan your cluster first:\n` +
|
|
328
|
+
`Run: manageOrgData({ dataType: "capabilities", operation: "scan" })\n` +
|
|
329
|
+
`Error: ${error}`);
|
|
330
|
+
}
|
|
310
331
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
throw new Error(`Capability search failed for intent "${intent}". Please scan your cluster first:\n` +
|
|
314
|
-
`Run: manageOrgData({ dataType: "capabilities", operation: "scan" })\n` +
|
|
315
|
-
`Error: ${error}`);
|
|
332
|
+
else {
|
|
333
|
+
console.warn('⚠️ Capability service not available (Vector DB not reachable), proceeding without capabilities');
|
|
316
334
|
}
|
|
317
335
|
if (relevantCapabilities.length === 0) {
|
|
318
336
|
// Fail fast with clear user guidance if no capabilities found
|
|
@@ -335,7 +353,7 @@ class ResourceRecommender {
|
|
|
335
353
|
const solutions = await this.assembleAndRankSolutions(intent, enhancedResources, relevantPatterns);
|
|
336
354
|
// Phase 3: Generate questions for each solution
|
|
337
355
|
for (const solution of solutions) {
|
|
338
|
-
solution.questions = await this.generateQuestionsWithAI(intent, solution);
|
|
356
|
+
solution.questions = await this.generateQuestionsWithAI(intent, solution, _explainResource);
|
|
339
357
|
}
|
|
340
358
|
return solutions;
|
|
341
359
|
}
|
|
@@ -368,6 +386,7 @@ class ResourceRecommender {
|
|
|
368
386
|
kind: resource.kind,
|
|
369
387
|
apiVersion: resource.apiVersion,
|
|
370
388
|
group: resource.group || '',
|
|
389
|
+
resourceName: resource.resourceName, // Preserve resourceName from AI response
|
|
371
390
|
description: `${resource.kind} resource from ${resource.group || 'core'} group`,
|
|
372
391
|
properties: new Map(),
|
|
373
392
|
namespace: true // Default assumption for new architecture
|
|
@@ -398,10 +417,7 @@ class ResourceRecommender {
|
|
|
398
417
|
* Load and format solution assembly prompt from file
|
|
399
418
|
*/
|
|
400
419
|
async loadSolutionAssemblyPrompt(intent, resources, patterns) {
|
|
401
|
-
const
|
|
402
|
-
const path = await Promise.resolve().then(() => __importStar(require('path')));
|
|
403
|
-
const promptPath = path.join(__dirname, '..', '..', 'prompts', 'resource-selection.md');
|
|
404
|
-
const template = fs.readFileSync(promptPath, 'utf8');
|
|
420
|
+
const template = (0, shared_prompt_loader_1.loadPrompt)('resource-selection');
|
|
405
421
|
// Format resources for the prompt with capability information
|
|
406
422
|
const resourcesText = resources.map((resource, index) => {
|
|
407
423
|
return `${index}: ${resource.kind.toUpperCase()} (${resource.apiVersion})
|
|
@@ -589,11 +605,7 @@ class ResourceRecommender {
|
|
|
589
605
|
: 'No organizational patterns found for this request.';
|
|
590
606
|
|
|
591
607
|
|
|
592
|
-
const
|
|
593
|
-
const path = await import('path');
|
|
594
|
-
|
|
595
|
-
const promptPath = path.join(__dirname, '..', '..', 'prompts', 'resource-selection.md');
|
|
596
|
-
const template = fs.readFileSync(promptPath, 'utf8');
|
|
608
|
+
const template = loadPrompt('resource-selection');
|
|
597
609
|
|
|
598
610
|
const selectionPrompt = template
|
|
599
611
|
.replace('{intent}', intent)
|
|
@@ -795,12 +807,51 @@ class ResourceRecommender {
|
|
|
795
807
|
/**
|
|
796
808
|
* Generate contextual questions using AI based on user intent and solution resources
|
|
797
809
|
*/
|
|
798
|
-
async generateQuestionsWithAI(intent, solution) {
|
|
810
|
+
async generateQuestionsWithAI(intent, solution, _explainResource) {
|
|
799
811
|
try {
|
|
800
812
|
// Discover cluster options for dynamic questions
|
|
801
813
|
const clusterOptions = await this.discoverClusterOptions();
|
|
814
|
+
// Search for relevant policy intents based on the selected resources
|
|
815
|
+
let relevantPolicyResults = [];
|
|
816
|
+
if (this.policyService) {
|
|
817
|
+
try {
|
|
818
|
+
const resourceContext = solution.resources.map(r => `${r.kind} ${r.description}`).join(' ');
|
|
819
|
+
const policyResults = await this.policyService.searchPolicyIntents(`${intent} ${resourceContext}`, { limit: 25 });
|
|
820
|
+
relevantPolicyResults = policyResults.map(result => ({
|
|
821
|
+
policy: result.data,
|
|
822
|
+
score: result.score,
|
|
823
|
+
matchType: result.matchType
|
|
824
|
+
}));
|
|
825
|
+
console.log(`🛡️ Found ${relevantPolicyResults.length} relevant policy intents for question generation`);
|
|
826
|
+
}
|
|
827
|
+
catch (error) {
|
|
828
|
+
console.warn('⚠️ Policy search failed during question generation, proceeding without policies:', error);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
else {
|
|
832
|
+
console.log('🛡️ Policy service unavailable, skipping policy search - proceeding without policy guidance');
|
|
833
|
+
}
|
|
834
|
+
// Fetch resource schemas for each resource in the solution
|
|
835
|
+
const resourcesWithSchemas = await Promise.all(solution.resources.map(async (resource) => {
|
|
836
|
+
// Validate that resource has resourceName field for kubectl explain
|
|
837
|
+
if (!resource.resourceName) {
|
|
838
|
+
throw new Error(`Resource ${resource.kind} is missing resourceName field. This indicates a bug in solution construction.`);
|
|
839
|
+
}
|
|
840
|
+
try {
|
|
841
|
+
// Use resourceName for kubectl explain - this should be the plural form like 'pods', 'services', etc.
|
|
842
|
+
const schemaExplanation = await _explainResource(resource.resourceName);
|
|
843
|
+
return {
|
|
844
|
+
...resource,
|
|
845
|
+
rawExplanation: schemaExplanation
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
catch (error) {
|
|
849
|
+
console.warn(`Failed to fetch schema for ${resource.kind}: ${error}`);
|
|
850
|
+
return resource;
|
|
851
|
+
}
|
|
852
|
+
}));
|
|
802
853
|
// Format resource details for the prompt using raw explanation when available
|
|
803
|
-
const resourceDetails =
|
|
854
|
+
const resourceDetails = resourcesWithSchemas.map(resource => {
|
|
804
855
|
if (resource.rawExplanation) {
|
|
805
856
|
// Use raw kubectl explain output for comprehensive field information
|
|
806
857
|
return `${resource.kind} (${resource.apiVersion}):
|
|
@@ -827,16 +878,22 @@ ${properties}`;
|
|
|
827
878
|
Available Storage Classes: ${clusterOptions.storageClasses.length > 0 ? clusterOptions.storageClasses.join(', ') : 'None discovered'}
|
|
828
879
|
Available Ingress Classes: ${clusterOptions.ingressClasses.length > 0 ? clusterOptions.ingressClasses.join(', ') : 'None discovered'}
|
|
829
880
|
Available Node Labels: ${clusterOptions.nodeLabels.length > 0 ? clusterOptions.nodeLabels.slice(0, 10).join(', ') : 'None discovered'}`;
|
|
881
|
+
// Format organizational policies for AI context with relevance scores
|
|
882
|
+
const policyContextText = relevantPolicyResults.length > 0
|
|
883
|
+
? relevantPolicyResults.map(result => `- ID: ${result.policy.id}
|
|
884
|
+
Description: ${result.policy.description}
|
|
885
|
+
Rationale: ${result.policy.rationale}
|
|
886
|
+
Triggers: ${result.policy.triggers?.join(', ') || 'None'}
|
|
887
|
+
Score: ${result.score.toFixed(3)} (${result.matchType})`).join('\n')
|
|
888
|
+
: 'No organizational policies found for this request.';
|
|
830
889
|
// Load and format the question generation prompt
|
|
831
|
-
const
|
|
832
|
-
const path = await Promise.resolve().then(() => __importStar(require('path')));
|
|
833
|
-
const promptPath = path.join(__dirname, '..', '..', 'prompts', 'question-generation.md');
|
|
834
|
-
const template = fs.readFileSync(promptPath, 'utf8');
|
|
890
|
+
const template = (0, shared_prompt_loader_1.loadPrompt)('question-generation');
|
|
835
891
|
const questionPrompt = template
|
|
836
892
|
.replace('{intent}', intent)
|
|
837
893
|
.replace('{solution_description}', solution.description)
|
|
838
894
|
.replace('{resource_details}', resourceDetails)
|
|
839
|
-
.replace('{cluster_options}', clusterOptionsText)
|
|
895
|
+
.replace('{cluster_options}', clusterOptionsText)
|
|
896
|
+
.replace('{policy_context}', policyContextText);
|
|
840
897
|
const response = await this.claudeIntegration.sendMessage(questionPrompt, 'question-generation');
|
|
841
898
|
// Use robust JSON extraction
|
|
842
899
|
const questions = this.extractJsonFromAIResponse(response.content);
|
|
@@ -847,6 +904,10 @@ Available Node Labels: ${clusterOptions.nodeLabels.length > 0 ? clusterOptions.n
|
|
|
847
904
|
return questions;
|
|
848
905
|
}
|
|
849
906
|
catch (error) {
|
|
907
|
+
// Re-throw errors about missing resourceName - these are bugs, not generation failures
|
|
908
|
+
if (error instanceof Error && error.message.includes('missing resourceName field')) {
|
|
909
|
+
throw error;
|
|
910
|
+
}
|
|
850
911
|
console.warn(`Failed to generate AI questions for solution: ${error}`);
|
|
851
912
|
// Fallback to basic open question
|
|
852
913
|
return {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Prompt Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads prompt templates from markdown files and replaces variables
|
|
5
|
+
* Following CLAUDE.md guidelines for file-based prompts
|
|
6
|
+
*
|
|
7
|
+
* Extracted from unified-creation-session.ts to be shared across all creation workflows
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Load prompt template from file and replace variables
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadPrompt(promptName: string, variables?: Record<string, string>): string;
|
|
13
|
+
//# sourceMappingURL=shared-prompt-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-prompt-loader.d.ts","sourceRoot":"","sources":["../../src/core/shared-prompt-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH;;GAEG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,MAAM,CAe7F"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared Prompt Loader
|
|
4
|
+
*
|
|
5
|
+
* Loads prompt templates from markdown files and replaces variables
|
|
6
|
+
* Following CLAUDE.md guidelines for file-based prompts
|
|
7
|
+
*
|
|
8
|
+
* Extracted from unified-creation-session.ts to be shared across all creation workflows
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
+
var ownKeys = function(o) {
|
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
+
var ar = [];
|
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
return ownKeys(o);
|
|
34
|
+
};
|
|
35
|
+
return function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.loadPrompt = loadPrompt;
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
/**
|
|
48
|
+
* Load prompt template from file and replace variables
|
|
49
|
+
*/
|
|
50
|
+
function loadPrompt(promptName, variables = {}) {
|
|
51
|
+
try {
|
|
52
|
+
const promptPath = path.join(process.cwd(), 'prompts', `${promptName}.md`);
|
|
53
|
+
let template = fs.readFileSync(promptPath, 'utf8');
|
|
54
|
+
// Replace template variables
|
|
55
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
56
|
+
template = template.replace(new RegExp(`\\{${key}\\}`, 'g'), value);
|
|
57
|
+
}
|
|
58
|
+
return template;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error(`Failed to load prompt ${promptName}:`, error);
|
|
62
|
+
return `Error loading prompt: ${promptName}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Creation Session Manager
|
|
3
|
+
*
|
|
4
|
+
* Handles step-by-step creation workflow for both patterns and policies
|
|
5
|
+
* with context-aware questions and AI-powered trigger expansion.
|
|
6
|
+
* Loads prompts from markdown files following CLAUDE.md guidelines.
|
|
7
|
+
*/
|
|
8
|
+
import { KubernetesDiscovery } from './discovery';
|
|
9
|
+
import { UnifiedCreationSession, UnifiedWorkflowStepResponse, UnifiedWorkflowCompletionResponse, EntityType } from './unified-creation-types';
|
|
10
|
+
export declare class UnifiedCreationSessionManager {
|
|
11
|
+
private config;
|
|
12
|
+
private discovery;
|
|
13
|
+
constructor(entityType: EntityType, discovery?: KubernetesDiscovery);
|
|
14
|
+
/**
|
|
15
|
+
* Create a new creation session
|
|
16
|
+
*/
|
|
17
|
+
createSession(args: any): UnifiedCreationSession;
|
|
18
|
+
/**
|
|
19
|
+
* Load existing session
|
|
20
|
+
*/
|
|
21
|
+
loadSession(sessionId: string, args: any): UnifiedCreationSession | null;
|
|
22
|
+
/**
|
|
23
|
+
* Process user response and advance session
|
|
24
|
+
*/
|
|
25
|
+
processResponse(sessionId: string, response: string, args: any): UnifiedCreationSession;
|
|
26
|
+
/**
|
|
27
|
+
* Generate next workflow step
|
|
28
|
+
*/
|
|
29
|
+
getNextWorkflowStep(session: UnifiedCreationSession, args?: any): Promise<UnifiedWorkflowStepResponse | UnifiedWorkflowCompletionResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Generate trigger expansion step with AI suggestions
|
|
32
|
+
*/
|
|
33
|
+
private generateTriggerExpansionStep;
|
|
34
|
+
/**
|
|
35
|
+
* Generate trigger expansion using internal AI
|
|
36
|
+
*/
|
|
37
|
+
private generateInternalTriggerExpansion;
|
|
38
|
+
/**
|
|
39
|
+
* Generate review step showing all collected data
|
|
40
|
+
*/
|
|
41
|
+
private generateReviewStep;
|
|
42
|
+
/**
|
|
43
|
+
* Complete the workflow and create the entity
|
|
44
|
+
*/
|
|
45
|
+
private completeWorkflow;
|
|
46
|
+
/**
|
|
47
|
+
* Handle policy deployment choice (apply to cluster or store intent only)
|
|
48
|
+
*/
|
|
49
|
+
private handlePolicyDeploymentChoice;
|
|
50
|
+
/**
|
|
51
|
+
* Validate YAML syntax
|
|
52
|
+
*/
|
|
53
|
+
private validateYamlSyntax;
|
|
54
|
+
/**
|
|
55
|
+
* Validate Kyverno policy using multi-layer approach
|
|
56
|
+
*/
|
|
57
|
+
private validateKyvernoPolicy;
|
|
58
|
+
/**
|
|
59
|
+
* Generate Kyverno policy step - automatically generates policy from intent data with validation loop
|
|
60
|
+
*/
|
|
61
|
+
private generateKyvernoStep;
|
|
62
|
+
/**
|
|
63
|
+
* Retrieve relevant schemas for Kyverno generation using semantic search
|
|
64
|
+
*/
|
|
65
|
+
private retrieveRelevantSchemas;
|
|
66
|
+
/**
|
|
67
|
+
* Format namespace scope for inclusion in the Kyverno generation prompt
|
|
68
|
+
*/
|
|
69
|
+
private formatNamespaceScope;
|
|
70
|
+
/**
|
|
71
|
+
* Format schemas for inclusion in the Kyverno generation prompt
|
|
72
|
+
*/
|
|
73
|
+
private formatSchemasForPrompt;
|
|
74
|
+
/**
|
|
75
|
+
* Save session to file
|
|
76
|
+
*/
|
|
77
|
+
private saveSession;
|
|
78
|
+
/**
|
|
79
|
+
* Generate unique session ID
|
|
80
|
+
*/
|
|
81
|
+
private generateSessionId;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=unified-creation-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified-creation-session.d.ts","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