@vfarcic/dot-ai 1.23.1 → 1.24.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/index.d.ts +0 -5
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -11
- package/dist/core/knowledge-migration.d.ts +30 -0
- package/dist/core/knowledge-migration.d.ts.map +1 -0
- package/dist/core/knowledge-migration.js +289 -0
- package/dist/core/knowledge-service.d.ts +46 -0
- package/dist/core/knowledge-service.d.ts.map +1 -0
- package/dist/core/knowledge-service.js +185 -0
- package/dist/core/knowledge-types.d.ts +14 -0
- package/dist/core/knowledge-types.d.ts.map +1 -1
- package/dist/core/schema.d.ts +13 -12
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +105 -170
- package/dist/core/user-prompts-loader.d.ts.map +1 -1
- package/dist/core/user-prompts-loader.js +13 -6
- package/dist/interfaces/rest-api.d.ts.map +1 -1
- package/dist/interfaces/rest-api.js +7 -6
- package/dist/mcp/server.js +12 -0
- package/dist/tools/manage-knowledge.d.ts +0 -22
- package/dist/tools/manage-knowledge.d.ts.map +1 -1
- package/dist/tools/manage-knowledge.js +71 -131
- package/dist/tools/operate-analysis.d.ts.map +1 -1
- package/dist/tools/operate-analysis.js +7 -6
- package/dist/tools/operate.d.ts +23 -11
- package/dist/tools/operate.d.ts.map +1 -1
- package/dist/tools/operate.js +40 -58
- package/dist/tools/organizational-data.d.ts +5 -8
- package/dist/tools/organizational-data.d.ts.map +1 -1
- package/dist/tools/organizational-data.js +19 -74
- package/dist/tools/query.d.ts +17 -0
- package/dist/tools/query.d.ts.map +1 -1
- package/dist/tools/query.js +36 -1
- package/dist/tools/version.d.ts +1 -12
- package/dist/tools/version.d.ts.map +1 -1
- package/dist/tools/version.js +10 -19
- package/package.json +2 -2
- package/prompts/knowledge-classification.md +24 -0
- package/prompts/operate-user.md +7 -8
- package/dist/core/organizational-types.d.ts +0 -43
- package/dist/core/organizational-types.d.ts.map +0 -1
- package/dist/core/organizational-types.js +0 -8
- package/dist/core/pattern-operations.d.ts +0 -50
- package/dist/core/pattern-operations.d.ts.map +0 -1
- package/dist/core/pattern-operations.js +0 -445
- package/dist/core/pattern-types.d.ts +0 -8
- package/dist/core/pattern-types.d.ts.map +0 -1
- package/dist/core/pattern-types.js +0 -8
- package/dist/core/pattern-vector-service.d.ts +0 -27
- package/dist/core/pattern-vector-service.d.ts.map +0 -1
- package/dist/core/pattern-vector-service.js +0 -65
- package/dist/core/policy-operations.d.ts +0 -136
- package/dist/core/policy-operations.d.ts.map +0 -1
- package/dist/core/policy-operations.js +0 -623
- package/dist/core/policy-vector-service.d.ts +0 -27
- package/dist/core/policy-vector-service.d.ts.map +0 -1
- package/dist/core/policy-vector-service.js +0 -64
- package/dist/core/unified-creation-session.d.ts +0 -88
- package/dist/core/unified-creation-session.d.ts.map +0 -1
- package/dist/core/unified-creation-session.js +0 -948
- package/dist/core/unified-creation-types.d.ts +0 -68
- package/dist/core/unified-creation-types.d.ts.map +0 -1
- package/dist/core/unified-creation-types.js +0 -61
|
@@ -1,623 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Core Policy Operations
|
|
4
|
-
*
|
|
5
|
-
* Handles policy intent management operations including CRUD operations
|
|
6
|
-
* and Kyverno cluster policy cleanup
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getPolicyService = getPolicyService;
|
|
10
|
-
exports.findKyvernoPoliciesByPolicyId = findKyvernoPoliciesByPolicyId;
|
|
11
|
-
exports.findAllKyvernoPoliciesForPolicyIntents = findAllKyvernoPoliciesForPolicyIntents;
|
|
12
|
-
exports.deleteKyvernoPoliciesByPolicyId = deleteKyvernoPoliciesByPolicyId;
|
|
13
|
-
exports.deleteAllKyvernoPoliciesForPolicyIntents = deleteAllKyvernoPoliciesForPolicyIntents;
|
|
14
|
-
exports.handlePolicyDelete = handlePolicyDelete;
|
|
15
|
-
exports.handlePolicyDeleteAll = handlePolicyDeleteAll;
|
|
16
|
-
exports.handlePolicyOperation = handlePolicyOperation;
|
|
17
|
-
const error_handling_1 = require("./error-handling");
|
|
18
|
-
const policy_vector_service_1 = require("./policy-vector-service");
|
|
19
|
-
const unified_creation_session_1 = require("./unified-creation-session");
|
|
20
|
-
const plugin_registry_1 = require("./plugin-registry");
|
|
21
|
-
const validation_1 = require("./constants/validation");
|
|
22
|
-
const constants_1 = require("./constants");
|
|
23
|
-
/**
|
|
24
|
-
* Get initialized policy service
|
|
25
|
-
*/
|
|
26
|
-
async function getPolicyService() {
|
|
27
|
-
const policyService = new policy_vector_service_1.PolicyVectorService();
|
|
28
|
-
// Always ensure proper collection initialization
|
|
29
|
-
try {
|
|
30
|
-
await policyService.initialize();
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
// If initialization fails, try to provide helpful error context
|
|
34
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
35
|
-
throw new Error(`Vector DB collection initialization failed: ${errorMessage}. This may be due to dimension mismatch or collection configuration issues.`, { cause: error });
|
|
36
|
-
}
|
|
37
|
-
return policyService;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Execute kubectl command via plugin
|
|
41
|
-
* PRD #343: All kubectl operations go through plugin
|
|
42
|
-
* PRD #359: Uses unified plugin registry
|
|
43
|
-
*/
|
|
44
|
-
async function executeKubectlViaPlugin(args) {
|
|
45
|
-
const response = await (0, plugin_registry_1.invokePluginTool)('agentic-tools', 'kubectl_exec_command', { args });
|
|
46
|
-
if (response.success) {
|
|
47
|
-
if (typeof response.result === 'object' && response.result !== null) {
|
|
48
|
-
const result = response.result;
|
|
49
|
-
// Check for nested error - plugin wraps kubectl errors in { success: false, error: "..." }
|
|
50
|
-
if (result.success === false) {
|
|
51
|
-
throw new Error(result.error || result.message || 'kubectl command failed');
|
|
52
|
-
}
|
|
53
|
-
// Return only the data field - never pass JSON wrapper to consumers
|
|
54
|
-
if (result.data !== undefined) {
|
|
55
|
-
return String(result.data);
|
|
56
|
-
}
|
|
57
|
-
if (typeof result === 'string') {
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
throw new Error('Plugin returned unexpected response format - missing data field');
|
|
61
|
-
}
|
|
62
|
-
return String(response.result || '');
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
throw new Error(response.error?.message || 'kubectl command failed via plugin');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Find Kyverno policies by policy intent ID using label selector
|
|
70
|
-
* PRD #359: Uses unified plugin registry
|
|
71
|
-
*/
|
|
72
|
-
async function findKyvernoPoliciesByPolicyId(policyId, logger, requestId) {
|
|
73
|
-
try {
|
|
74
|
-
logger.info('Searching for Kyverno policies by policy ID', {
|
|
75
|
-
requestId,
|
|
76
|
-
policyId,
|
|
77
|
-
});
|
|
78
|
-
const output = await executeKubectlViaPlugin([
|
|
79
|
-
'get',
|
|
80
|
-
'clusterpolicy',
|
|
81
|
-
'-l',
|
|
82
|
-
`policy-intent/id=${policyId}`,
|
|
83
|
-
'-o',
|
|
84
|
-
'json',
|
|
85
|
-
]);
|
|
86
|
-
const parsedOutput = JSON.parse(output || '{"items": []}');
|
|
87
|
-
const policies = parsedOutput.items || [];
|
|
88
|
-
logger.info('Found Kyverno policies for policy intent', {
|
|
89
|
-
requestId,
|
|
90
|
-
policyId,
|
|
91
|
-
policyCount: policies.length,
|
|
92
|
-
policyNames: policies.map((p) => p.metadata?.name),
|
|
93
|
-
});
|
|
94
|
-
return policies.map((p) => ({
|
|
95
|
-
name: p.metadata?.name || '',
|
|
96
|
-
labels: p.metadata?.labels,
|
|
97
|
-
creationTimestamp: p.metadata?.creationTimestamp,
|
|
98
|
-
}));
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
logger.warn('Failed to query Kyverno policies (cluster may not have Kyverno or no policies found)', {
|
|
102
|
-
requestId,
|
|
103
|
-
policyId,
|
|
104
|
-
error: error instanceof Error ? error.message : String(error),
|
|
105
|
-
});
|
|
106
|
-
return [];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Find all Kyverno policies that have policy-intent/id labels
|
|
111
|
-
* PRD #359: Uses unified plugin registry
|
|
112
|
-
*/
|
|
113
|
-
async function findAllKyvernoPoliciesForPolicyIntents(logger, requestId) {
|
|
114
|
-
try {
|
|
115
|
-
logger.info('Searching for all Kyverno policies with policy-intent labels', {
|
|
116
|
-
requestId,
|
|
117
|
-
});
|
|
118
|
-
const output = await executeKubectlViaPlugin([
|
|
119
|
-
'get',
|
|
120
|
-
'clusterpolicy',
|
|
121
|
-
'-l',
|
|
122
|
-
'policy-intent/id',
|
|
123
|
-
'-o',
|
|
124
|
-
'json',
|
|
125
|
-
]);
|
|
126
|
-
const parsedOutput = JSON.parse(output || '{"items": []}');
|
|
127
|
-
const policies = parsedOutput.items || [];
|
|
128
|
-
logger.info('Found all Kyverno policies for policy intents', {
|
|
129
|
-
requestId,
|
|
130
|
-
policyCount: policies.length,
|
|
131
|
-
policyNames: policies.map((p) => p.metadata?.name),
|
|
132
|
-
});
|
|
133
|
-
return policies.map((p) => ({
|
|
134
|
-
name: p.metadata?.name || '',
|
|
135
|
-
policyId: p.metadata?.labels?.['policy-intent/id'],
|
|
136
|
-
labels: p.metadata?.labels,
|
|
137
|
-
creationTimestamp: p.metadata?.creationTimestamp,
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
logger.warn('Failed to query all Kyverno policies (cluster may not have Kyverno or no policies found)', {
|
|
142
|
-
requestId,
|
|
143
|
-
error: error instanceof Error ? error.message : String(error),
|
|
144
|
-
});
|
|
145
|
-
return [];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Delete Kyverno policies by policy intent ID using label selector
|
|
150
|
-
* PRD #359: Uses unified plugin registry
|
|
151
|
-
*/
|
|
152
|
-
async function deleteKyvernoPoliciesByPolicyId(policyId, logger, requestId) {
|
|
153
|
-
try {
|
|
154
|
-
logger.info('Deleting Kyverno policies by policy ID', {
|
|
155
|
-
requestId,
|
|
156
|
-
policyId,
|
|
157
|
-
});
|
|
158
|
-
const output = await executeKubectlViaPlugin([
|
|
159
|
-
'delete',
|
|
160
|
-
'clusterpolicy',
|
|
161
|
-
'-l',
|
|
162
|
-
`policy-intent/id=${policyId}`,
|
|
163
|
-
]);
|
|
164
|
-
logger.info('Kyverno policies deleted successfully', {
|
|
165
|
-
requestId,
|
|
166
|
-
policyId,
|
|
167
|
-
output,
|
|
168
|
-
});
|
|
169
|
-
return {
|
|
170
|
-
successful: [{ policyId, deletedAt: new Date().toISOString() }],
|
|
171
|
-
failed: [],
|
|
172
|
-
total: 1,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
logger.error('Failed to delete Kyverno policies', error, {
|
|
177
|
-
requestId,
|
|
178
|
-
policyId,
|
|
179
|
-
error: error instanceof Error ? error.message : String(error),
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
successful: [],
|
|
183
|
-
failed: [
|
|
184
|
-
{
|
|
185
|
-
policyId,
|
|
186
|
-
error: error instanceof Error ? error.message : String(error),
|
|
187
|
-
},
|
|
188
|
-
],
|
|
189
|
-
total: 1,
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Delete all Kyverno policies that have policy-intent/id labels
|
|
195
|
-
* PRD #359: Uses unified plugin registry
|
|
196
|
-
*/
|
|
197
|
-
async function deleteAllKyvernoPoliciesForPolicyIntents(logger, requestId) {
|
|
198
|
-
try {
|
|
199
|
-
logger.info('Deleting all Kyverno policies with policy-intent labels', {
|
|
200
|
-
requestId,
|
|
201
|
-
});
|
|
202
|
-
const output = await executeKubectlViaPlugin([
|
|
203
|
-
'delete',
|
|
204
|
-
'clusterpolicy',
|
|
205
|
-
'-l',
|
|
206
|
-
'policy-intent/id',
|
|
207
|
-
]);
|
|
208
|
-
logger.info('All Kyverno policies deleted successfully', {
|
|
209
|
-
requestId,
|
|
210
|
-
output,
|
|
211
|
-
});
|
|
212
|
-
return {
|
|
213
|
-
successful: [{ deletedAt: new Date().toISOString() }],
|
|
214
|
-
failed: [],
|
|
215
|
-
total: 1,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
logger.error('Failed to delete all Kyverno policies', error, {
|
|
220
|
-
requestId,
|
|
221
|
-
error: error instanceof Error ? error.message : String(error),
|
|
222
|
-
});
|
|
223
|
-
return {
|
|
224
|
-
successful: [],
|
|
225
|
-
failed: [
|
|
226
|
-
{ error: error instanceof Error ? error.message : String(error) },
|
|
227
|
-
],
|
|
228
|
-
total: 1,
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Handle individual policy delete with Kyverno cleanup
|
|
234
|
-
* PRD #359: Uses unified plugin registry
|
|
235
|
-
*/
|
|
236
|
-
async function handlePolicyDelete(policyId, policyService, args, logger, requestId) {
|
|
237
|
-
try {
|
|
238
|
-
// Check if policy intent exists
|
|
239
|
-
const existingPolicyIntent = await policyService.getPolicyIntent(policyId);
|
|
240
|
-
if (!existingPolicyIntent) {
|
|
241
|
-
return {
|
|
242
|
-
success: false,
|
|
243
|
-
operation: 'delete',
|
|
244
|
-
dataType: 'policy',
|
|
245
|
-
message: `Policy intent not found: ${policyId}`,
|
|
246
|
-
error: 'Policy intent not found',
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
// Check if there are deployed Kyverno policies with this policy ID
|
|
250
|
-
const kyvernoPolicies = await findKyvernoPoliciesByPolicyId(policyId, logger, requestId);
|
|
251
|
-
if (kyvernoPolicies.length > 0 && !args.response) {
|
|
252
|
-
// Show confirmation prompt for Kyverno cleanup
|
|
253
|
-
return {
|
|
254
|
-
success: true,
|
|
255
|
-
operation: 'delete',
|
|
256
|
-
dataType: 'policy',
|
|
257
|
-
requiresConfirmation: true,
|
|
258
|
-
message: 'Policy intent has deployed Kyverno policies that need cleanup decision',
|
|
259
|
-
confirmation: {
|
|
260
|
-
question: `Policy intent "${existingPolicyIntent.description.substring(0, 60)}..." has ${kyvernoPolicies.length} deployed Kyverno policies in your cluster: ${kyvernoPolicies.map(p => p.name).join(', ')}\n\n**Choose what to do:**\n\n1. **Delete everything** - Remove policy intent AND delete Kyverno policies from cluster\n2. **Keep Kyverno policies** - Remove policy intent only, preserve cluster policies\n\n⚠️ **Warning**: Option 1 will remove active policy enforcement from your cluster.\n\n**What would you like to do?**`,
|
|
261
|
-
options: ['Delete everything', 'Keep Kyverno policies'],
|
|
262
|
-
},
|
|
263
|
-
policyIntent: existingPolicyIntent,
|
|
264
|
-
kyvernoPolicies: kyvernoPolicies,
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
// Process user's response or proceed with direct deletion
|
|
268
|
-
let kyvernoCleanupResults = null;
|
|
269
|
-
if (kyvernoPolicies.length > 0 && args.response) {
|
|
270
|
-
const response = args.response.trim();
|
|
271
|
-
if (response === '1' ||
|
|
272
|
-
response.toLowerCase().includes('delete everything')) {
|
|
273
|
-
// Delete Kyverno policies from cluster
|
|
274
|
-
kyvernoCleanupResults = await deleteKyvernoPoliciesByPolicyId(policyId, logger, requestId);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
// Always delete the policy intent from Vector DB
|
|
278
|
-
await policyService.deletePolicyIntent(policyId);
|
|
279
|
-
const cleanupMessage = kyvernoCleanupResults
|
|
280
|
-
? `with Kyverno cleanup (${kyvernoCleanupResults.successful.length} deleted, ${kyvernoCleanupResults.failed.length} failed)`
|
|
281
|
-
: kyvernoPolicies.length > 0
|
|
282
|
-
? '(Kyverno policies preserved in cluster)'
|
|
283
|
-
: '(no Kyverno policies to cleanup)';
|
|
284
|
-
return {
|
|
285
|
-
success: true,
|
|
286
|
-
operation: 'delete',
|
|
287
|
-
dataType: 'policy',
|
|
288
|
-
message: `Policy intent deleted successfully ${cleanupMessage}`,
|
|
289
|
-
deletedPolicyIntent: existingPolicyIntent,
|
|
290
|
-
kyvernoCleanup: kyvernoCleanupResults || { preserved: true },
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
catch (error) {
|
|
294
|
-
logger.error('Failed to delete policy intent', error, {
|
|
295
|
-
requestId,
|
|
296
|
-
policyId,
|
|
297
|
-
});
|
|
298
|
-
return {
|
|
299
|
-
success: false,
|
|
300
|
-
operation: 'delete',
|
|
301
|
-
dataType: 'policy',
|
|
302
|
-
message: 'Failed to delete policy intent',
|
|
303
|
-
error: error instanceof Error ? error.message : String(error),
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Handle deleteAll policies with batch Kyverno cleanup
|
|
309
|
-
* PRD #359: Uses unified plugin registry
|
|
310
|
-
*/
|
|
311
|
-
async function handlePolicyDeleteAll(policyService, args, logger, requestId) {
|
|
312
|
-
try {
|
|
313
|
-
// Get all policy intents
|
|
314
|
-
const allPolicyIntents = await policyService.getAllPolicyIntents();
|
|
315
|
-
if (!allPolicyIntents || allPolicyIntents.length === 0) {
|
|
316
|
-
return {
|
|
317
|
-
success: true,
|
|
318
|
-
operation: 'deleteAll',
|
|
319
|
-
dataType: 'policy',
|
|
320
|
-
message: 'No policy intents found to delete',
|
|
321
|
-
deletedCount: 0,
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
// Find all deployed Kyverno policies for all policy intents
|
|
325
|
-
const allKyvernoPolicies = await findAllKyvernoPoliciesForPolicyIntents(logger, requestId);
|
|
326
|
-
if (allKyvernoPolicies.length > 0 && !args.response) {
|
|
327
|
-
// Show confirmation prompt for batch Kyverno cleanup
|
|
328
|
-
return {
|
|
329
|
-
success: true,
|
|
330
|
-
operation: 'deleteAll',
|
|
331
|
-
dataType: 'policy',
|
|
332
|
-
requiresConfirmation: true,
|
|
333
|
-
message: 'Found policy intents with deployed Kyverno policies that need cleanup decision',
|
|
334
|
-
confirmation: {
|
|
335
|
-
question: `Deleting ${allPolicyIntents.length} policy intents. Found ${allKyvernoPolicies.length} deployed Kyverno policies in your cluster: ${allKyvernoPolicies.map(p => p.name).join(', ')}\n\n**Choose what to do:**\n\n1. **Delete everything** - Remove all policy intents AND delete all Kyverno policies from cluster\n2. **Keep Kyverno policies** - Remove all policy intents only, preserve all cluster policies\n\n⚠️ **Warning**: Option 1 will remove ALL active policy enforcement from your cluster.\n\n**What would you like to do?**`,
|
|
336
|
-
options: ['Delete everything', 'Keep Kyverno policies'],
|
|
337
|
-
},
|
|
338
|
-
policyIntents: allPolicyIntents,
|
|
339
|
-
kyvernoPolicies: allKyvernoPolicies,
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
// Process user's response or proceed with direct deletion
|
|
343
|
-
let kyvernoCleanupResults = null;
|
|
344
|
-
if (allKyvernoPolicies.length > 0 && args.response) {
|
|
345
|
-
const response = args.response.trim();
|
|
346
|
-
if (response === '1' ||
|
|
347
|
-
response.toLowerCase().includes('delete everything')) {
|
|
348
|
-
// Delete all Kyverno policies from cluster
|
|
349
|
-
kyvernoCleanupResults = await deleteAllKyvernoPoliciesForPolicyIntents(logger, requestId);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
// Always delete all policy intents from Vector DB
|
|
353
|
-
for (const policyIntent of allPolicyIntents) {
|
|
354
|
-
await policyService.deletePolicyIntent(policyIntent.id);
|
|
355
|
-
}
|
|
356
|
-
const cleanupMessage = kyvernoCleanupResults
|
|
357
|
-
? `with Kyverno cleanup (${kyvernoCleanupResults.successful.length} deleted, ${kyvernoCleanupResults.failed.length} failed)`
|
|
358
|
-
: allKyvernoPolicies.length > 0
|
|
359
|
-
? '(Kyverno policies preserved in cluster)'
|
|
360
|
-
: '(no Kyverno policies to cleanup)';
|
|
361
|
-
return {
|
|
362
|
-
success: true,
|
|
363
|
-
operation: 'deleteAll',
|
|
364
|
-
dataType: 'policy',
|
|
365
|
-
message: `All ${allPolicyIntents.length} policy intents deleted successfully ${cleanupMessage}`,
|
|
366
|
-
deletedCount: allPolicyIntents.length,
|
|
367
|
-
deletedPolicyIntents: allPolicyIntents,
|
|
368
|
-
kyvernoCleanup: kyvernoCleanupResults || { preserved: true },
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
catch (error) {
|
|
372
|
-
logger.error('Failed to delete all policy intents', error, {
|
|
373
|
-
requestId,
|
|
374
|
-
});
|
|
375
|
-
return {
|
|
376
|
-
success: false,
|
|
377
|
-
operation: 'deleteAll',
|
|
378
|
-
dataType: 'policy',
|
|
379
|
-
message: 'Failed to delete all policy intents',
|
|
380
|
-
error: error instanceof Error ? error.message : String(error),
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Main policy operations handler - delegates to specific operation functions
|
|
386
|
-
* Requires shared validation utilities to be passed as parameters to avoid circular imports
|
|
387
|
-
* PRD #359: Uses unified plugin registry for kubectl operations
|
|
388
|
-
*/
|
|
389
|
-
async function handlePolicyOperation(operation, args, logger, requestId, validateVectorDBConnection, validateEmbeddingService) {
|
|
390
|
-
// Get policy service and validate Vector DB connection
|
|
391
|
-
const policyService = await getPolicyService();
|
|
392
|
-
const connectionCheck = await validateVectorDBConnection(policyService, logger, requestId);
|
|
393
|
-
if (!connectionCheck.success) {
|
|
394
|
-
return {
|
|
395
|
-
success: false,
|
|
396
|
-
operation,
|
|
397
|
-
dataType: 'policy',
|
|
398
|
-
error: connectionCheck.error,
|
|
399
|
-
message: 'Vector DB connection required for policy management',
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
// Validate embedding service and fail if unavailable (except for delete operations)
|
|
403
|
-
const operationsRequiringEmbedding = ['create', 'search'];
|
|
404
|
-
if (operationsRequiringEmbedding.includes(operation)) {
|
|
405
|
-
const embeddingCheck = await validateEmbeddingService(logger, requestId);
|
|
406
|
-
if (!embeddingCheck.success) {
|
|
407
|
-
return {
|
|
408
|
-
success: false,
|
|
409
|
-
operation,
|
|
410
|
-
dataType: 'policy',
|
|
411
|
-
error: embeddingCheck.error,
|
|
412
|
-
message: constants_1.AI_SERVICE_ERROR_TEMPLATES.OPENAI_KEY_REQUIRED('policy management'),
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
const sessionManager = new unified_creation_session_1.UnifiedCreationSessionManager('policy');
|
|
417
|
-
switch (operation) {
|
|
418
|
-
case 'create': {
|
|
419
|
-
let workflowStep;
|
|
420
|
-
if (args.sessionId) {
|
|
421
|
-
// Continue existing session
|
|
422
|
-
logger.info('Continuing policy creation workflow', {
|
|
423
|
-
requestId,
|
|
424
|
-
sessionId: args.sessionId,
|
|
425
|
-
});
|
|
426
|
-
if (args.response) {
|
|
427
|
-
// Process user response and move to next step
|
|
428
|
-
const updatedSession = sessionManager.processResponse(args.sessionId, args.response);
|
|
429
|
-
workflowStep = await sessionManager.getNextWorkflowStep(updatedSession, args);
|
|
430
|
-
}
|
|
431
|
-
else {
|
|
432
|
-
// Just get current step without processing response
|
|
433
|
-
const session = sessionManager.loadSession(args.sessionId);
|
|
434
|
-
if (!session) {
|
|
435
|
-
throw error_handling_1.ErrorHandler.createError(error_handling_1.ErrorCategory.VALIDATION, error_handling_1.ErrorSeverity.HIGH, `Session not found: ${args.sessionId}`, {
|
|
436
|
-
operation: 'policy_workflow_continue',
|
|
437
|
-
component: 'OrganizationalDataTool',
|
|
438
|
-
requestId,
|
|
439
|
-
input: { sessionId: args.sessionId },
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
workflowStep = await sessionManager.getNextWorkflowStep(session, args);
|
|
443
|
-
}
|
|
444
|
-
if (!workflowStep) {
|
|
445
|
-
throw error_handling_1.ErrorHandler.createError(error_handling_1.ErrorCategory.VALIDATION, error_handling_1.ErrorSeverity.HIGH, `Session not found or workflow failed`, {
|
|
446
|
-
operation: 'policy_workflow_continue',
|
|
447
|
-
component: 'OrganizationalDataTool',
|
|
448
|
-
requestId,
|
|
449
|
-
input: { sessionId: args.sessionId },
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
// Start new workflow session
|
|
455
|
-
logger.info('Starting new policy creation workflow', { requestId });
|
|
456
|
-
const session = sessionManager.createSession(args);
|
|
457
|
-
workflowStep = await sessionManager.getNextWorkflowStep(session, args);
|
|
458
|
-
if (!workflowStep) {
|
|
459
|
-
throw error_handling_1.ErrorHandler.createError(error_handling_1.ErrorCategory.OPERATION, error_handling_1.ErrorSeverity.HIGH, 'Failed to initialize policy creation workflow', {
|
|
460
|
-
operation: 'policy_workflow_start',
|
|
461
|
-
component: 'OrganizationalDataTool',
|
|
462
|
-
requestId,
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
// Always check if workflow is complete and store policy in Vector DB
|
|
467
|
-
let storageInfo = {};
|
|
468
|
-
const isComplete = !('nextStep' in workflowStep) || !workflowStep.nextStep; // Complete when no next step
|
|
469
|
-
const workflowData = workflowStep.data;
|
|
470
|
-
const hasPolicy = !!workflowData?.policy;
|
|
471
|
-
logger.info('Checking workflow completion', {
|
|
472
|
-
requestId,
|
|
473
|
-
nextStep: 'nextStep' in workflowStep ? workflowStep.nextStep : 'complete',
|
|
474
|
-
hasPolicy,
|
|
475
|
-
policyId: workflowData?.policy?.id,
|
|
476
|
-
});
|
|
477
|
-
if (isComplete && hasPolicy) {
|
|
478
|
-
try {
|
|
479
|
-
await policyService.storePolicyIntent(workflowData.policy);
|
|
480
|
-
storageInfo = {
|
|
481
|
-
stored: true,
|
|
482
|
-
collectionName: 'policies',
|
|
483
|
-
policyId: workflowData.policy.id,
|
|
484
|
-
};
|
|
485
|
-
logger.info('Policy stored in Vector DB successfully', {
|
|
486
|
-
requestId,
|
|
487
|
-
policyId: workflowData.policy.id,
|
|
488
|
-
description: workflowData.policy.description.substring(0, 50) +
|
|
489
|
-
(workflowData.policy.description.length > 50 ? '...' : ''),
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
catch (error) {
|
|
493
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
494
|
-
storageInfo = {
|
|
495
|
-
stored: false,
|
|
496
|
-
error: errorMessage,
|
|
497
|
-
policyId: workflowData.policy.id,
|
|
498
|
-
};
|
|
499
|
-
logger.error('Failed to store policy in Vector DB', error instanceof Error ? error : new Error(String(error)), {
|
|
500
|
-
requestId,
|
|
501
|
-
policyId: workflowData.policy.id,
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
// For completed policies, storage failure means creation failure
|
|
506
|
-
const storageSucceeded = storageInfo.stored === true;
|
|
507
|
-
const operationSucceeded = !isComplete || storageSucceeded;
|
|
508
|
-
return {
|
|
509
|
-
success: operationSucceeded,
|
|
510
|
-
operation: 'create',
|
|
511
|
-
dataType: 'policy',
|
|
512
|
-
workflow: workflowStep,
|
|
513
|
-
storage: storageInfo,
|
|
514
|
-
message: isComplete
|
|
515
|
-
? storageSucceeded
|
|
516
|
-
? `Policy created and stored successfully`
|
|
517
|
-
: 'Policy creation failed - storage error'
|
|
518
|
-
: 'Workflow step ready',
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
case 'list': {
|
|
522
|
-
const limit = args.limit || 10;
|
|
523
|
-
const policyIntents = await policyService.getAllPolicyIntents();
|
|
524
|
-
const totalCount = await policyService.getPolicyIntentsCount();
|
|
525
|
-
const limitedPolicyIntents = policyIntents.slice(0, limit);
|
|
526
|
-
return {
|
|
527
|
-
success: true,
|
|
528
|
-
operation,
|
|
529
|
-
dataType: 'policy',
|
|
530
|
-
message: `Found ${totalCount} policy intents (showing ${limitedPolicyIntents.length})`,
|
|
531
|
-
policyIntents: limitedPolicyIntents,
|
|
532
|
-
totalCount,
|
|
533
|
-
note: totalCount > limit
|
|
534
|
-
? `Showing first ${limit} of ${totalCount} policy intents. Use limit parameter to see more.`
|
|
535
|
-
: undefined,
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
case 'get': {
|
|
539
|
-
if (!args.id) {
|
|
540
|
-
return {
|
|
541
|
-
success: false,
|
|
542
|
-
operation,
|
|
543
|
-
dataType: 'policy',
|
|
544
|
-
message: 'Policy intent ID is required for get operation',
|
|
545
|
-
error: validation_1.VALIDATION_MESSAGES.MISSING_PARAMETER('id'),
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
const policyIntent = await policyService.getPolicyIntent(args.id);
|
|
549
|
-
if (!policyIntent) {
|
|
550
|
-
return {
|
|
551
|
-
success: false,
|
|
552
|
-
operation,
|
|
553
|
-
dataType: 'policy',
|
|
554
|
-
message: `Policy intent not found: ${args.id}`,
|
|
555
|
-
error: 'Policy intent not found',
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
return {
|
|
559
|
-
success: true,
|
|
560
|
-
operation,
|
|
561
|
-
dataType: 'policy',
|
|
562
|
-
message: 'Policy intent retrieved successfully',
|
|
563
|
-
policyIntent,
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
case 'search': {
|
|
567
|
-
if (!args.id) {
|
|
568
|
-
// For search, 'id' parameter contains the search query
|
|
569
|
-
return {
|
|
570
|
-
success: false,
|
|
571
|
-
operation,
|
|
572
|
-
dataType: 'policy',
|
|
573
|
-
message: 'Search query is required (use id parameter)',
|
|
574
|
-
error: validation_1.VALIDATION_MESSAGES.MISSING_PARAMETER_WITH_CONTEXT('id', 'search query'),
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
const limit = args.limit || 10;
|
|
578
|
-
const searchResults = await policyService.searchPolicyIntents(args.id, {
|
|
579
|
-
limit,
|
|
580
|
-
});
|
|
581
|
-
return {
|
|
582
|
-
success: true,
|
|
583
|
-
operation,
|
|
584
|
-
dataType: 'policy',
|
|
585
|
-
message: `Found ${searchResults.length} policy intents matching "${args.id}"`,
|
|
586
|
-
policyIntents: searchResults.map(result => result.data),
|
|
587
|
-
searchResults: searchResults.map(result => ({
|
|
588
|
-
policyIntent: result.data,
|
|
589
|
-
score: result.score,
|
|
590
|
-
})),
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
case 'delete': {
|
|
594
|
-
if (!args.id) {
|
|
595
|
-
return {
|
|
596
|
-
success: false,
|
|
597
|
-
operation,
|
|
598
|
-
dataType: 'policy',
|
|
599
|
-
message: 'Policy intent ID is required for delete operation',
|
|
600
|
-
error: validation_1.VALIDATION_MESSAGES.MISSING_PARAMETER('id'),
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
if (!(0, plugin_registry_1.isPluginInitialized)()) {
|
|
604
|
-
throw new Error('Plugin system not available. Policy delete requires agentic-tools plugin for kubectl operations.');
|
|
605
|
-
}
|
|
606
|
-
return await handlePolicyDelete(args.id, policyService, args, logger, requestId);
|
|
607
|
-
}
|
|
608
|
-
case 'deleteAll': {
|
|
609
|
-
if (!(0, plugin_registry_1.isPluginInitialized)()) {
|
|
610
|
-
throw new Error('Plugin system not available. Policy deleteAll requires agentic-tools plugin for kubectl operations.');
|
|
611
|
-
}
|
|
612
|
-
return await handlePolicyDeleteAll(policyService, args, logger, requestId);
|
|
613
|
-
}
|
|
614
|
-
default:
|
|
615
|
-
return {
|
|
616
|
-
success: false,
|
|
617
|
-
operation,
|
|
618
|
-
dataType: 'policy',
|
|
619
|
-
message: `Unsupported operation: ${operation}. Supported operations: create, list, get, search, delete, deleteAll`,
|
|
620
|
-
error: 'Unsupported operation',
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Policy Vector Service
|
|
3
|
-
*
|
|
4
|
-
* Handles policy intent-specific Vector DB operations
|
|
5
|
-
* Extends BaseVectorService for policy intents
|
|
6
|
-
*/
|
|
7
|
-
import { PolicyIntent } from './organizational-types';
|
|
8
|
-
import { EmbeddingService } from './embedding-service';
|
|
9
|
-
import { BaseVectorService, BaseSearchOptions, BaseSearchResult } from './base-vector-service';
|
|
10
|
-
export interface PolicySearchOptions extends BaseSearchOptions {
|
|
11
|
-
}
|
|
12
|
-
export interface PolicySearchResult extends BaseSearchResult<PolicyIntent> {
|
|
13
|
-
}
|
|
14
|
-
export declare class PolicyVectorService extends BaseVectorService<PolicyIntent> {
|
|
15
|
-
constructor(embeddingService?: EmbeddingService);
|
|
16
|
-
protected createSearchText(policyIntent: PolicyIntent): string;
|
|
17
|
-
protected extractId(policyIntent: PolicyIntent): string;
|
|
18
|
-
protected createPayload(policyIntent: PolicyIntent): Record<string, unknown>;
|
|
19
|
-
protected payloadToData(payload: Record<string, unknown>): PolicyIntent;
|
|
20
|
-
storePolicyIntent(policyIntent: PolicyIntent): Promise<void>;
|
|
21
|
-
searchPolicyIntents(query: string, options?: PolicySearchOptions): Promise<PolicySearchResult[]>;
|
|
22
|
-
getPolicyIntent(id: string): Promise<PolicyIntent | null>;
|
|
23
|
-
getAllPolicyIntents(): Promise<PolicyIntent[]>;
|
|
24
|
-
deletePolicyIntent(id: string): Promise<void>;
|
|
25
|
-
getPolicyIntentsCount(): Promise<number>;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=policy-vector-service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"policy-vector-service.d.ts","sourceRoot":"","sources":["../../src/core/policy-vector-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAA2B,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG/F,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;CAAG;AAEjE,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB,CAAC,YAAY,CAAC;CAAG;AAE7E,qBAAa,mBAAoB,SAAQ,iBAAiB,CAAC,YAAY,CAAC;gBAC1D,gBAAgB,CAAC,EAAE,gBAAgB;IAK/C,SAAS,CAAC,gBAAgB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM;IAM9D,SAAS,CAAC,SAAS,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM;IAIvD,SAAS,CAAC,aAAa,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAW5E,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;IAajE,iBAAiB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAIpG,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAIzD,mBAAmB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAI9C,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC;CAG/C"}
|