code-graph-context 2.5.3 → 2.5.4
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.
|
@@ -4,7 +4,7 @@ import { getTimeoutConfig } from '../config/timeouts.js';
|
|
|
4
4
|
export class NaturalLanguageToCypherService {
|
|
5
5
|
assistantId;
|
|
6
6
|
openai;
|
|
7
|
-
MODEL = 'gpt-4o
|
|
7
|
+
MODEL = 'gpt-4o'; // GPT-4o for better Cypher generation accuracy
|
|
8
8
|
schemaPath = null;
|
|
9
9
|
cachedSemanticTypes = null;
|
|
10
10
|
messageInstructions = `
|
|
@@ -9,7 +9,7 @@ import { createErrorResponse, createSuccessResponse, resolveProjectIdOrError, de
|
|
|
9
9
|
/**
|
|
10
10
|
* Neo4j query to delete pheromones by swarm ID
|
|
11
11
|
*/
|
|
12
|
-
const
|
|
12
|
+
const CLEANUP_PHEROMONES_BY_SWARM_QUERY = `
|
|
13
13
|
MATCH (p:Pheromone)
|
|
14
14
|
WHERE p.projectId = $projectId
|
|
15
15
|
AND p.swarmId = $swarmId
|
|
@@ -18,6 +18,17 @@ const CLEANUP_BY_SWARM_QUERY = `
|
|
|
18
18
|
DETACH DELETE p
|
|
19
19
|
RETURN count(p) as deleted, collect(DISTINCT agentId) as agents, collect(DISTINCT type) as types
|
|
20
20
|
`;
|
|
21
|
+
/**
|
|
22
|
+
* Neo4j query to delete SwarmTask nodes by swarm ID
|
|
23
|
+
*/
|
|
24
|
+
const CLEANUP_TASKS_BY_SWARM_QUERY = `
|
|
25
|
+
MATCH (t:SwarmTask)
|
|
26
|
+
WHERE t.projectId = $projectId
|
|
27
|
+
AND t.swarmId = $swarmId
|
|
28
|
+
WITH t, t.status as status
|
|
29
|
+
DETACH DELETE t
|
|
30
|
+
RETURN count(t) as deleted, collect(DISTINCT status) as statuses
|
|
31
|
+
`;
|
|
21
32
|
/**
|
|
22
33
|
* Neo4j query to delete pheromones by agent ID
|
|
23
34
|
*/
|
|
@@ -44,11 +55,16 @@ const CLEANUP_ALL_QUERY = `
|
|
|
44
55
|
/**
|
|
45
56
|
* Count queries for dry run
|
|
46
57
|
*/
|
|
47
|
-
const
|
|
58
|
+
const COUNT_PHEROMONES_BY_SWARM_QUERY = `
|
|
48
59
|
MATCH (p:Pheromone)
|
|
49
60
|
WHERE p.projectId = $projectId AND p.swarmId = $swarmId AND NOT p.type IN $keepTypes
|
|
50
61
|
RETURN count(p) as count, collect(DISTINCT p.agentId) as agents, collect(DISTINCT p.type) as types
|
|
51
62
|
`;
|
|
63
|
+
const COUNT_TASKS_BY_SWARM_QUERY = `
|
|
64
|
+
MATCH (t:SwarmTask)
|
|
65
|
+
WHERE t.projectId = $projectId AND t.swarmId = $swarmId
|
|
66
|
+
RETURN count(t) as count, collect(DISTINCT t.status) as statuses
|
|
67
|
+
`;
|
|
52
68
|
const COUNT_BY_AGENT_QUERY = `
|
|
53
69
|
MATCH (p:Pheromone)
|
|
54
70
|
WHERE p.projectId = $projectId AND p.agentId = $agentId AND NOT p.type IN $keepTypes
|
|
@@ -65,9 +81,14 @@ export const createSwarmCleanupTool = (server) => {
|
|
|
65
81
|
description: TOOL_METADATA[TOOL_NAMES.swarmCleanup].description,
|
|
66
82
|
inputSchema: {
|
|
67
83
|
projectId: z.string().describe('Project ID, name, or path'),
|
|
68
|
-
swarmId: z.string().optional().describe('Delete all pheromones from this swarm'),
|
|
84
|
+
swarmId: z.string().optional().describe('Delete all pheromones and tasks from this swarm'),
|
|
69
85
|
agentId: z.string().optional().describe('Delete all pheromones from this agent'),
|
|
70
86
|
all: z.boolean().optional().default(false).describe('Delete ALL pheromones in project (use with caution)'),
|
|
87
|
+
includeTasks: z
|
|
88
|
+
.boolean()
|
|
89
|
+
.optional()
|
|
90
|
+
.default(true)
|
|
91
|
+
.describe('Also delete SwarmTask nodes (default: true, only applies when swarmId is provided)'),
|
|
71
92
|
keepTypes: z
|
|
72
93
|
.array(z.string())
|
|
73
94
|
.optional()
|
|
@@ -75,7 +96,7 @@ export const createSwarmCleanupTool = (server) => {
|
|
|
75
96
|
.describe('Pheromone types to preserve (default: ["warning"])'),
|
|
76
97
|
dryRun: z.boolean().optional().default(false).describe('Preview what would be deleted without deleting'),
|
|
77
98
|
},
|
|
78
|
-
}, async ({ projectId, swarmId, agentId, all = false, keepTypes = ['warning'], dryRun = false }) => {
|
|
99
|
+
}, async ({ projectId, swarmId, agentId, all = false, includeTasks = true, keepTypes = ['warning'], dryRun = false }) => {
|
|
79
100
|
const neo4jService = new Neo4jService();
|
|
80
101
|
// Resolve project ID
|
|
81
102
|
const projectResult = await resolveProjectIdOrError(projectId, neo4jService);
|
|
@@ -98,52 +119,83 @@ export const createSwarmCleanupTool = (server) => {
|
|
|
98
119
|
dryRun,
|
|
99
120
|
});
|
|
100
121
|
const params = { projectId: resolvedProjectId, keepTypes };
|
|
101
|
-
let
|
|
102
|
-
let
|
|
122
|
+
let pheromoneDeleteQuery;
|
|
123
|
+
let pheromoneCountQuery;
|
|
103
124
|
let mode;
|
|
104
125
|
if (swarmId) {
|
|
105
126
|
params.swarmId = swarmId;
|
|
106
|
-
|
|
107
|
-
|
|
127
|
+
pheromoneDeleteQuery = CLEANUP_PHEROMONES_BY_SWARM_QUERY;
|
|
128
|
+
pheromoneCountQuery = COUNT_PHEROMONES_BY_SWARM_QUERY;
|
|
108
129
|
mode = 'swarm';
|
|
109
130
|
}
|
|
110
131
|
else if (agentId) {
|
|
111
132
|
params.agentId = agentId;
|
|
112
|
-
|
|
113
|
-
|
|
133
|
+
pheromoneDeleteQuery = CLEANUP_BY_AGENT_QUERY;
|
|
134
|
+
pheromoneCountQuery = COUNT_BY_AGENT_QUERY;
|
|
114
135
|
mode = 'agent';
|
|
115
136
|
}
|
|
116
137
|
else {
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
pheromoneDeleteQuery = CLEANUP_ALL_QUERY;
|
|
139
|
+
pheromoneCountQuery = COUNT_ALL_QUERY;
|
|
119
140
|
mode = 'all';
|
|
120
141
|
}
|
|
121
142
|
if (dryRun) {
|
|
122
|
-
const
|
|
123
|
-
const
|
|
143
|
+
const pheromoneResult = await neo4jService.run(pheromoneCountQuery, params);
|
|
144
|
+
const pheromoneCount = pheromoneResult[0]?.count ?? 0;
|
|
145
|
+
let taskCount = 0;
|
|
146
|
+
let taskStatuses = [];
|
|
147
|
+
if (swarmId && includeTasks) {
|
|
148
|
+
const taskResult = await neo4jService.run(COUNT_TASKS_BY_SWARM_QUERY, params);
|
|
149
|
+
taskCount = taskResult[0]?.count ?? 0;
|
|
150
|
+
taskCount = typeof taskCount === 'object' && 'toNumber' in taskCount ? taskCount.toNumber() : taskCount;
|
|
151
|
+
taskStatuses = taskResult[0]?.statuses ?? [];
|
|
152
|
+
}
|
|
124
153
|
return createSuccessResponse(JSON.stringify({
|
|
125
154
|
success: true,
|
|
126
155
|
dryRun: true,
|
|
127
156
|
mode,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
157
|
+
pheromones: {
|
|
158
|
+
wouldDelete: typeof pheromoneCount === 'object' && 'toNumber' in pheromoneCount ? pheromoneCount.toNumber() : pheromoneCount,
|
|
159
|
+
agents: pheromoneResult[0]?.agents ?? [],
|
|
160
|
+
types: pheromoneResult[0]?.types ?? [],
|
|
161
|
+
},
|
|
162
|
+
tasks: swarmId && includeTasks ? {
|
|
163
|
+
wouldDelete: taskCount,
|
|
164
|
+
statuses: taskStatuses,
|
|
165
|
+
} : null,
|
|
132
166
|
keepTypes,
|
|
133
167
|
projectId: resolvedProjectId,
|
|
134
168
|
}));
|
|
135
169
|
}
|
|
136
|
-
|
|
137
|
-
const
|
|
170
|
+
// Delete pheromones
|
|
171
|
+
const pheromoneResult = await neo4jService.run(pheromoneDeleteQuery, params);
|
|
172
|
+
const pheromonesDeleted = pheromoneResult[0]?.deleted ?? 0;
|
|
173
|
+
// Delete tasks if swarmId provided and includeTasks is true
|
|
174
|
+
let tasksDeleted = 0;
|
|
175
|
+
let taskStatuses = [];
|
|
176
|
+
if (swarmId && includeTasks) {
|
|
177
|
+
const taskResult = await neo4jService.run(CLEANUP_TASKS_BY_SWARM_QUERY, params);
|
|
178
|
+
tasksDeleted = taskResult[0]?.deleted ?? 0;
|
|
179
|
+
tasksDeleted = typeof tasksDeleted === 'object' && 'toNumber' in tasksDeleted ? tasksDeleted.toNumber() : tasksDeleted;
|
|
180
|
+
taskStatuses = taskResult[0]?.statuses ?? [];
|
|
181
|
+
}
|
|
138
182
|
return createSuccessResponse(JSON.stringify({
|
|
139
183
|
success: true,
|
|
140
184
|
mode,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
185
|
+
pheromones: {
|
|
186
|
+
deleted: typeof pheromonesDeleted === 'object' && 'toNumber' in pheromonesDeleted ? pheromonesDeleted.toNumber() : pheromonesDeleted,
|
|
187
|
+
agents: pheromoneResult[0]?.agents ?? [],
|
|
188
|
+
types: pheromoneResult[0]?.types ?? [],
|
|
189
|
+
},
|
|
190
|
+
tasks: swarmId && includeTasks ? {
|
|
191
|
+
deleted: tasksDeleted,
|
|
192
|
+
statuses: taskStatuses,
|
|
193
|
+
} : null,
|
|
145
194
|
keepTypes,
|
|
146
195
|
projectId: resolvedProjectId,
|
|
196
|
+
message: swarmId && includeTasks
|
|
197
|
+
? `Cleaned up ${pheromonesDeleted} pheromones and ${tasksDeleted} tasks`
|
|
198
|
+
: `Cleaned up ${pheromonesDeleted} pheromones`,
|
|
147
199
|
}));
|
|
148
200
|
}
|
|
149
201
|
catch (error) {
|
package/package.json
CHANGED