snow-flow 2.0.2 → 2.0.3
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/{.claude/mcp-config.json → .mcp.json} +13 -12
- package/.releaserc.json +47 -0
- package/README.md +6 -0
- package/package.json +1 -1
- package/.claude/claude-settings.json +0 -15
- package/.claude/commands/analysis/README.md +0 -9
- package/.claude/commands/automation/README.md +0 -9
- package/.claude/commands/github/README.md +0 -11
- package/.claude/commands/helpers/standard-checkpoint-hooks.sh +0 -179
- package/.claude/commands/hooks/README.md +0 -11
- package/.claude/commands/monitoring/README.md +0 -9
- package/.claude/commands/optimization/README.md +0 -9
- package/.claude/commands/training/README.md +0 -9
- package/.claude/commands/workflows/README.md +0 -9
- package/.claude/config.json +0 -36
- package/.claude/helpers/github-setup.sh +0 -28
- package/.claude/helpers/quick-start.sh +0 -19
- package/.claude/helpers/setup-mcp.sh +0 -18
- package/.claude/settings.json +0 -114
- package/.claude/settings.local.json +0 -33
- package/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude-flow/metrics/performance.json +0 -9
- package/.claude-flow/metrics/system-metrics.json +0 -15986
- package/.claude-flow/metrics/task-metrics.json +0 -10
- package/.roo/README.md +0 -402
- package/.roo/mcp-list.txt +0 -257
- package/.roo/mcp.json +0 -32
- package/.roo/workflows/basic-tdd.json +0 -32
- package/.roomodes +0 -201
- package/CLAUDE.md +0 -393
- package/bin/snow-flow.js +0 -3
- package/dist/cli.js.bak +0 -2052
- package/dist/config/snow-flow-config.d.ts +0 -1492
- package/dist/config/snow-flow-config.js +0 -938
- package/scripts/create-env.js +0 -91
- package/scripts/postinstall.js +0 -30
- package/scripts/register-mcp-servers.js +0 -210
- package/scripts/reset-mcp-servers.js +0 -246
- package/scripts/setup-mcp.js +0 -106
- package/scripts/update-version.js +0 -31
- package/src/agents/README.md +0 -192
- package/src/agents/base-agent.ts +0 -251
- package/src/agents/coordinator.ts +0 -971
- package/src/agents/index.ts +0 -18
- package/src/agents/queen-403-handler.ts +0 -230
- package/src/agents/queen-agent.ts +0 -1399
- package/src/agents/script-writer-agent.ts +0 -769
- package/src/agents/security-agent.ts +0 -726
- package/src/agents/widget-creator-agent.ts +0 -568
- package/src/api/error-handling.ts +0 -1758
- package/src/api/natural-language-mapper.ts +0 -630
- package/src/api/performance-optimizer.ts +0 -891
- package/src/api/transaction-manager.ts +0 -754
- package/src/cli/deploy-artifact.ts +0 -304
- package/src/cli/snow-flow-cli-integration.ts +0 -434
- package/src/cli.ts +0 -4455
- package/src/cli.ts.bak +0 -5616
- package/src/compliance/advanced-compliance-system.ts +0 -1268
- package/src/compliance/index.ts +0 -19
- package/src/config/snow-flow-config.ts +0 -1019
- package/src/documentation/index.ts +0 -16
- package/src/documentation/self-documenting-system.ts +0 -1421
- package/src/dynamic-version.ts +0 -44
- package/src/healing/index.ts +0 -20
- package/src/healing/self-healing-system.ts +0 -1435
- package/src/health/README.md +0 -161
- package/src/health/system-health.ts +0 -995
- package/src/index.ts +0 -60
- package/src/intelligence/acl-analyzer.ts +0 -377
- package/src/intelligence/auto-resolution-engine.ts +0 -643
- package/src/intelligence/gap-analysis-engine.ts +0 -488
- package/src/intelligence/manual-instructions-generator.ts +0 -744
- package/src/intelligence/mcp-coverage-analyzer.ts +0 -708
- package/src/intelligence/multi-pass-requirements-analyzer.ts +0 -603
- package/src/intelligence/performance-recommendations-engine.ts +0 -1223
- package/src/intelligence/requirements-analyzer.ts +0 -1148
- package/src/intelligence/task-analyzer.ts +0 -628
- package/src/managers/scope-manager.ts +0 -555
- package/src/mcp/advanced/servicenow-advanced-features-mcp.ts +0 -16110
- package/src/mcp/base-mcp-server.ts +0 -660
- package/src/mcp/http-transport-wrapper.ts +0 -426
- package/src/mcp/service-discovery-client.ts +0 -312
- package/src/mcp/servicenow-automation-mcp-refactored.ts +0 -678
- package/src/mcp/servicenow-automation-mcp.ts +0 -838
- package/src/mcp/servicenow-deployment-mcp-refactored.ts +0 -1292
- package/src/mcp/servicenow-deployment-mcp.ts +0 -7244
- package/src/mcp/servicenow-graph-memory-mcp-refactored.ts +0 -721
- package/src/mcp/servicenow-graph-memory-mcp.ts +0 -832
- package/src/mcp/servicenow-integration-mcp-refactored.ts +0 -655
- package/src/mcp/servicenow-integration-mcp.ts +0 -819
- package/src/mcp/servicenow-intelligent-mcp-refactored.ts +0 -977
- package/src/mcp/servicenow-intelligent-mcp.ts +0 -4638
- package/src/mcp/servicenow-mcp-server.ts +0 -728
- package/src/mcp/servicenow-memory-mcp.ts +0 -474
- package/src/mcp/servicenow-operations-mcp-refactored.ts +0 -1995
- package/src/mcp/servicenow-operations-mcp.ts +0 -3384
- package/src/mcp/servicenow-platform-development-mcp-refactored.ts +0 -611
- package/src/mcp/servicenow-platform-development-mcp.ts +0 -970
- package/src/mcp/servicenow-progressive-indexer.ts +0 -370
- package/src/mcp/servicenow-reporting-analytics-mcp-refactored.ts +0 -695
- package/src/mcp/servicenow-reporting-analytics-mcp.ts +0 -1123
- package/src/mcp/servicenow-security-compliance-mcp-refactored.ts +0 -642
- package/src/mcp/servicenow-security-compliance-mcp.ts +0 -1157
- package/src/mcp/servicenow-update-set-mcp-refactored.ts +0 -751
- package/src/mcp/servicenow-update-set-mcp.ts +0 -811
- package/src/mcp/shared/agent-context-provider.ts +0 -365
- package/src/mcp/shared/base-mcp-server.ts +0 -2463
- package/src/mcp/shared/mcp-memory-manager.ts +0 -540
- package/src/mcp/shared/mcp-resource-manager.ts +0 -367
- package/src/mcp/snow-flow-mcp.ts +0 -911
- package/src/mcp/start-all-mcp-servers.ts +0 -102
- package/src/mcp/start-servicenow-mcp.ts +0 -67
- package/src/monitoring/enhanced-monitoring-system.ts +0 -1345
- package/src/monitoring/performance-tracker.ts +0 -777
- package/src/optimization/cost-optimization-engine.ts +0 -1125
- package/src/optimization/index.ts +0 -10
- package/src/queen/README.md +0 -403
- package/src/queen/agent-factory.ts +0 -574
- package/src/queen/index.ts +0 -94
- package/src/queen/mcp-execution-bridge.ts +0 -681
- package/src/queen/neural-learning.ts +0 -319
- package/src/queen/parallel-agent-engine.ts +0 -848
- package/src/queen/queen-memory-system.ts +0 -490
- package/src/queen/queen-memory.ts +0 -456
- package/src/queen/servicenow-queen.ts +0 -1029
- package/src/queen/types.ts +0 -87
- package/src/rollback/smart-rollback-system.ts +0 -866
- package/src/schemas/deployment.schema.json +0 -58
- package/src/schemas/flow.schema.json +0 -79
- package/src/schemas/widget.schema.json +0 -72
- package/src/snow-flow-system.ts +0 -541
- package/src/sparc/sparc-help.ts +0 -49
- package/src/sparc/team-sparc.ts +0 -88
- package/src/strategies/global-scope-strategy.ts +0 -736
- package/src/templates/base/application.template.json +0 -45
- package/src/templates/base/business_rule.template.json +0 -33
- package/src/templates/base/script_include.template.json +0 -18
- package/src/templates/base/table.template.json +0 -64
- package/src/templates/base/widget.template.json +0 -25
- package/src/templates/patterns/composite.incident-management.template.json +0 -140
- package/src/templates/patterns/widget.dashboard.template.json +0 -238
- package/src/templates/patterns/widget.datatable.template.json +0 -292
- package/src/testing/integration-test-suite.ts +0 -1276
- package/src/types/index.ts +0 -183
- package/src/types/neo4j-driver.d.ts +0 -23
- package/src/types/servicenow.types.ts +0 -307
- package/src/types/snow-flow.types.ts +0 -186
- package/src/types/todo.types.ts +0 -70
- package/src/utils/action-type-cache.ts +0 -286
- package/src/utils/agent-detector.ts +0 -573
- package/src/utils/artifact-tracker.ts +0 -379
- package/src/utils/dependency-detector.ts +0 -233
- package/src/utils/deployment-metadata-handler.ts +0 -518
- package/src/utils/error-recovery.ts +0 -680
- package/src/utils/logger.ts +0 -60
- package/src/utils/mcp-auth-middleware.ts +0 -262
- package/src/utils/mcp-config-manager.ts +0 -270
- package/src/utils/mcp-server-manager.ts +0 -446
- package/src/utils/mcp-tool-registry.ts +0 -298
- package/src/utils/migrate-snow-flow.ts +0 -98
- package/src/utils/oauth-html-templates.ts +0 -188
- package/src/utils/scope-utils.ts +0 -443
- package/src/utils/servicenow-client.ts +0 -3321
- package/src/utils/servicenow-id-generator.ts +0 -181
- package/src/utils/snow-memory-manager.ts +0 -605
- package/src/utils/snow-oauth.ts +0 -797
- package/src/utils/template-engine.ts +0 -463
- package/src/utils/theme-manager.ts +0 -295
- package/src/utils/unified-auth-store.ts +0 -222
- package/src/utils/update-set-importer.ts +0 -422
- package/src/utils/update-set-xml-packager.ts +0 -371
- package/src/utils/widget-template-generator.ts +0 -1744
- package/src/version.ts +0 -1950
|
@@ -1,540 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Memory Manager
|
|
3
|
-
* Shared memory integration for all MCP servers to coordinate with agents
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import Database from 'better-sqlite3';
|
|
7
|
-
import * as path from 'path';
|
|
8
|
-
import * as fs from 'fs';
|
|
9
|
-
import { Logger } from '../../utils/logger.js';
|
|
10
|
-
|
|
11
|
-
export interface AgentContext {
|
|
12
|
-
session_id: string;
|
|
13
|
-
agent_id: string;
|
|
14
|
-
agent_type: string;
|
|
15
|
-
required_scopes?: string[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface ArtifactRecord {
|
|
19
|
-
sys_id: string;
|
|
20
|
-
artifact_type: string;
|
|
21
|
-
name: string;
|
|
22
|
-
description?: string;
|
|
23
|
-
created_by_agent: string;
|
|
24
|
-
session_id: string;
|
|
25
|
-
deployment_status: string;
|
|
26
|
-
update_set_id?: string;
|
|
27
|
-
dependencies?: string;
|
|
28
|
-
metadata?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface AgentCoordination {
|
|
32
|
-
session_id: string;
|
|
33
|
-
agent_id: string;
|
|
34
|
-
agent_type: string;
|
|
35
|
-
status: 'spawned' | 'active' | 'blocked' | 'completed';
|
|
36
|
-
assigned_tasks?: string;
|
|
37
|
-
progress_percentage: number;
|
|
38
|
-
last_activity: Date;
|
|
39
|
-
current_tool?: string;
|
|
40
|
-
error_state?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface SharedContext {
|
|
44
|
-
session_id: string;
|
|
45
|
-
context_key: string;
|
|
46
|
-
context_value: string;
|
|
47
|
-
created_by_agent: string;
|
|
48
|
-
expires_at?: Date;
|
|
49
|
-
access_permissions?: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface AgentMessage {
|
|
53
|
-
id: string;
|
|
54
|
-
session_id: string;
|
|
55
|
-
from_agent: string;
|
|
56
|
-
to_agent: string;
|
|
57
|
-
message_type: 'handoff' | 'dependency_ready' | 'error' | 'status_update';
|
|
58
|
-
content: string;
|
|
59
|
-
artifact_reference?: string;
|
|
60
|
-
timestamp: Date;
|
|
61
|
-
processed: boolean;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface PerformanceMetric {
|
|
65
|
-
session_id: string;
|
|
66
|
-
agent_id: string;
|
|
67
|
-
operation_name: string;
|
|
68
|
-
duration_ms: number;
|
|
69
|
-
success: boolean;
|
|
70
|
-
error_message?: string;
|
|
71
|
-
timestamp: Date;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export class MCPMemoryManager {
|
|
75
|
-
private db: Database.Database;
|
|
76
|
-
private logger: Logger;
|
|
77
|
-
private static instance: MCPMemoryManager;
|
|
78
|
-
|
|
79
|
-
private constructor() {
|
|
80
|
-
this.logger = new Logger('MCPMemoryManager');
|
|
81
|
-
|
|
82
|
-
// Create memory directory if it doesn't exist
|
|
83
|
-
const memoryDir = path.join(process.cwd(), '.snow-flow', 'memory');
|
|
84
|
-
if (!fs.existsSync(memoryDir)) {
|
|
85
|
-
fs.mkdirSync(memoryDir, { recursive: true });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Initialize database
|
|
89
|
-
this.db = new Database(path.join(memoryDir, 'mcp-coordination.db'));
|
|
90
|
-
this.initializeDatabase();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
static getInstance(): MCPMemoryManager {
|
|
94
|
-
if (!MCPMemoryManager.instance) {
|
|
95
|
-
MCPMemoryManager.instance = new MCPMemoryManager();
|
|
96
|
-
}
|
|
97
|
-
return MCPMemoryManager.instance;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private initializeDatabase(): void {
|
|
101
|
-
this.logger.info('Initializing MCP coordination database');
|
|
102
|
-
|
|
103
|
-
this.db.exec(`
|
|
104
|
-
-- Agent coordination and communication
|
|
105
|
-
CREATE TABLE IF NOT EXISTS agent_coordination (
|
|
106
|
-
session_id TEXT NOT NULL,
|
|
107
|
-
agent_id TEXT NOT NULL,
|
|
108
|
-
agent_type TEXT NOT NULL,
|
|
109
|
-
status TEXT NOT NULL,
|
|
110
|
-
assigned_tasks TEXT,
|
|
111
|
-
progress_percentage INTEGER DEFAULT 0,
|
|
112
|
-
last_activity TEXT NOT NULL,
|
|
113
|
-
current_tool TEXT,
|
|
114
|
-
error_state TEXT,
|
|
115
|
-
PRIMARY KEY (session_id, agent_id)
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
-- ServiceNow artifact tracking
|
|
119
|
-
CREATE TABLE IF NOT EXISTS servicenow_artifacts (
|
|
120
|
-
sys_id TEXT PRIMARY KEY,
|
|
121
|
-
artifact_type TEXT NOT NULL,
|
|
122
|
-
name TEXT NOT NULL,
|
|
123
|
-
description TEXT,
|
|
124
|
-
created_by_agent TEXT NOT NULL,
|
|
125
|
-
session_id TEXT NOT NULL,
|
|
126
|
-
deployment_status TEXT NOT NULL,
|
|
127
|
-
update_set_id TEXT,
|
|
128
|
-
dependencies TEXT,
|
|
129
|
-
metadata TEXT,
|
|
130
|
-
created_at TEXT DEFAULT (datetime('now'))
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
-- Inter-agent communication
|
|
134
|
-
CREATE TABLE IF NOT EXISTS agent_messages (
|
|
135
|
-
id TEXT PRIMARY KEY,
|
|
136
|
-
session_id TEXT NOT NULL,
|
|
137
|
-
from_agent TEXT NOT NULL,
|
|
138
|
-
to_agent TEXT NOT NULL,
|
|
139
|
-
message_type TEXT NOT NULL,
|
|
140
|
-
content TEXT NOT NULL,
|
|
141
|
-
artifact_reference TEXT,
|
|
142
|
-
timestamp TEXT NOT NULL,
|
|
143
|
-
processed INTEGER DEFAULT 0
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
-- Shared context between agents
|
|
147
|
-
CREATE TABLE IF NOT EXISTS shared_context (
|
|
148
|
-
session_id TEXT NOT NULL,
|
|
149
|
-
context_key TEXT NOT NULL,
|
|
150
|
-
context_value TEXT NOT NULL,
|
|
151
|
-
created_by_agent TEXT NOT NULL,
|
|
152
|
-
expires_at TEXT,
|
|
153
|
-
access_permissions TEXT,
|
|
154
|
-
created_at TEXT DEFAULT (datetime('now')),
|
|
155
|
-
PRIMARY KEY (session_id, context_key)
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
-- Deployment tracking
|
|
159
|
-
CREATE TABLE IF NOT EXISTS deployment_history (
|
|
160
|
-
id TEXT PRIMARY KEY,
|
|
161
|
-
session_id TEXT NOT NULL,
|
|
162
|
-
artifact_sys_id TEXT NOT NULL,
|
|
163
|
-
deployment_type TEXT NOT NULL,
|
|
164
|
-
success INTEGER NOT NULL,
|
|
165
|
-
deployment_time TEXT NOT NULL,
|
|
166
|
-
agent_id TEXT NOT NULL,
|
|
167
|
-
error_details TEXT,
|
|
168
|
-
rollback_available INTEGER DEFAULT 0
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
-- Agent dependencies and handoffs
|
|
172
|
-
CREATE TABLE IF NOT EXISTS agent_dependencies (
|
|
173
|
-
session_id TEXT NOT NULL,
|
|
174
|
-
agent_id TEXT NOT NULL,
|
|
175
|
-
depends_on_agent TEXT NOT NULL,
|
|
176
|
-
dependency_type TEXT NOT NULL,
|
|
177
|
-
artifact_reference TEXT,
|
|
178
|
-
status TEXT NOT NULL,
|
|
179
|
-
created_at TEXT DEFAULT (datetime('now')),
|
|
180
|
-
satisfied_at TEXT,
|
|
181
|
-
PRIMARY KEY (session_id, agent_id, depends_on_agent)
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
-- Performance metrics
|
|
185
|
-
CREATE TABLE IF NOT EXISTS performance_metrics (
|
|
186
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
187
|
-
session_id TEXT NOT NULL,
|
|
188
|
-
agent_id TEXT NOT NULL,
|
|
189
|
-
operation_name TEXT NOT NULL,
|
|
190
|
-
duration_ms INTEGER NOT NULL,
|
|
191
|
-
success INTEGER NOT NULL,
|
|
192
|
-
error_message TEXT,
|
|
193
|
-
timestamp TEXT NOT NULL
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
-- Create indexes for better performance
|
|
197
|
-
CREATE INDEX IF NOT EXISTS idx_artifacts_session ON servicenow_artifacts(session_id);
|
|
198
|
-
CREATE INDEX IF NOT EXISTS idx_coordination_session ON agent_coordination(session_id);
|
|
199
|
-
CREATE INDEX IF NOT EXISTS idx_messages_session ON agent_messages(session_id);
|
|
200
|
-
CREATE INDEX IF NOT EXISTS idx_context_session ON shared_context(session_id);
|
|
201
|
-
`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Read session context
|
|
205
|
-
async getSessionContext(session_id: string): Promise<any> {
|
|
206
|
-
try {
|
|
207
|
-
const contexts = this.db.prepare(`
|
|
208
|
-
SELECT * FROM shared_context
|
|
209
|
-
WHERE session_id = ?
|
|
210
|
-
AND (expires_at IS NULL OR expires_at > datetime('now'))
|
|
211
|
-
`).all(session_id);
|
|
212
|
-
|
|
213
|
-
const result: Record<string, any> = {};
|
|
214
|
-
for (const context of contexts as SharedContext[]) {
|
|
215
|
-
try {
|
|
216
|
-
result[context.context_key] = JSON.parse(context.context_value);
|
|
217
|
-
} catch {
|
|
218
|
-
result[context.context_key] = context.context_value;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return result;
|
|
223
|
-
} catch (error) {
|
|
224
|
-
this.logger.error('Failed to get session context', error);
|
|
225
|
-
return {};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Get active agents for session
|
|
230
|
-
async getActiveAgents(session_id: string): Promise<AgentCoordination[]> {
|
|
231
|
-
try {
|
|
232
|
-
const agents = this.db.prepare(`
|
|
233
|
-
SELECT * FROM agent_coordination
|
|
234
|
-
WHERE session_id = ? AND status IN ('active', 'spawned')
|
|
235
|
-
`).all(session_id);
|
|
236
|
-
|
|
237
|
-
return agents as AgentCoordination[];
|
|
238
|
-
} catch (error) {
|
|
239
|
-
this.logger.error('Failed to get active agents', error);
|
|
240
|
-
return [];
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Store artifact information
|
|
245
|
-
async storeArtifact(artifact: ArtifactRecord): Promise<void> {
|
|
246
|
-
try {
|
|
247
|
-
const stmt = this.db.prepare(`
|
|
248
|
-
INSERT OR REPLACE INTO servicenow_artifacts
|
|
249
|
-
(sys_id, artifact_type, name, description, created_by_agent, session_id,
|
|
250
|
-
deployment_status, update_set_id, dependencies, metadata)
|
|
251
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
252
|
-
`);
|
|
253
|
-
|
|
254
|
-
stmt.run(
|
|
255
|
-
artifact.sys_id,
|
|
256
|
-
artifact.artifact_type,
|
|
257
|
-
artifact.name,
|
|
258
|
-
artifact.description || null,
|
|
259
|
-
artifact.created_by_agent,
|
|
260
|
-
artifact.session_id,
|
|
261
|
-
artifact.deployment_status,
|
|
262
|
-
artifact.update_set_id || null,
|
|
263
|
-
artifact.dependencies || null,
|
|
264
|
-
artifact.metadata || null
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
this.logger.debug(`Stored artifact ${artifact.name} (${artifact.sys_id})`);
|
|
268
|
-
} catch (error) {
|
|
269
|
-
this.logger.error('Failed to store artifact', error);
|
|
270
|
-
throw error;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Update shared context
|
|
275
|
-
async updateSharedContext(context: SharedContext): Promise<void> {
|
|
276
|
-
try {
|
|
277
|
-
const stmt = this.db.prepare(`
|
|
278
|
-
INSERT OR REPLACE INTO shared_context
|
|
279
|
-
(session_id, context_key, context_value, created_by_agent, expires_at, access_permissions)
|
|
280
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
281
|
-
`);
|
|
282
|
-
|
|
283
|
-
stmt.run(
|
|
284
|
-
context.session_id,
|
|
285
|
-
context.context_key,
|
|
286
|
-
context.context_value,
|
|
287
|
-
context.created_by_agent,
|
|
288
|
-
context.expires_at ? context.expires_at.toISOString() : null,
|
|
289
|
-
context.access_permissions || null
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
this.logger.debug(`Updated shared context: ${context.context_key}`);
|
|
293
|
-
} catch (error) {
|
|
294
|
-
this.logger.error('Failed to update shared context', error);
|
|
295
|
-
throw error;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Update agent coordination status
|
|
300
|
-
async updateAgentCoordination(coordination: Partial<AgentCoordination> & { agent_id: string; session_id: string }): Promise<void> {
|
|
301
|
-
try {
|
|
302
|
-
// Build dynamic update query based on provided fields
|
|
303
|
-
const updates: string[] = [];
|
|
304
|
-
const values: any[] = [];
|
|
305
|
-
|
|
306
|
-
if (coordination.status !== undefined) {
|
|
307
|
-
updates.push('status = ?');
|
|
308
|
-
values.push(coordination.status);
|
|
309
|
-
}
|
|
310
|
-
if (coordination.progress_percentage !== undefined) {
|
|
311
|
-
updates.push('progress_percentage = ?');
|
|
312
|
-
values.push(coordination.progress_percentage);
|
|
313
|
-
}
|
|
314
|
-
if (coordination.current_tool !== undefined) {
|
|
315
|
-
updates.push('current_tool = ?');
|
|
316
|
-
values.push(coordination.current_tool);
|
|
317
|
-
}
|
|
318
|
-
if (coordination.error_state !== undefined) {
|
|
319
|
-
updates.push('error_state = ?');
|
|
320
|
-
values.push(coordination.error_state);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Always update last_activity
|
|
324
|
-
updates.push('last_activity = datetime("now")');
|
|
325
|
-
|
|
326
|
-
// Add WHERE clause values
|
|
327
|
-
values.push(coordination.agent_id, coordination.session_id);
|
|
328
|
-
|
|
329
|
-
const stmt = this.db.prepare(`
|
|
330
|
-
UPDATE agent_coordination
|
|
331
|
-
SET ${updates.join(', ')}
|
|
332
|
-
WHERE agent_id = ? AND session_id = ?
|
|
333
|
-
`);
|
|
334
|
-
|
|
335
|
-
const result = stmt.run(...values);
|
|
336
|
-
|
|
337
|
-
// If no rows updated, create new record
|
|
338
|
-
if (result.changes === 0) {
|
|
339
|
-
const insertStmt = this.db.prepare(`
|
|
340
|
-
INSERT INTO agent_coordination
|
|
341
|
-
(session_id, agent_id, agent_type, status, progress_percentage, last_activity)
|
|
342
|
-
VALUES (?, ?, ?, ?, ?, datetime('now'))
|
|
343
|
-
`);
|
|
344
|
-
|
|
345
|
-
insertStmt.run(
|
|
346
|
-
coordination.session_id,
|
|
347
|
-
coordination.agent_id,
|
|
348
|
-
coordination.agent_type || 'unknown',
|
|
349
|
-
coordination.status || 'active',
|
|
350
|
-
coordination.progress_percentage || 0
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
this.logger.debug(`Updated agent coordination for ${coordination.agent_id}`);
|
|
355
|
-
} catch (error) {
|
|
356
|
-
this.logger.error('Failed to update agent coordination', error);
|
|
357
|
-
throw error;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// Send message between agents
|
|
362
|
-
async sendAgentMessage(message: Omit<AgentMessage, 'id' | 'timestamp' | 'processed'>): Promise<void> {
|
|
363
|
-
try {
|
|
364
|
-
const id = `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
365
|
-
|
|
366
|
-
const stmt = this.db.prepare(`
|
|
367
|
-
INSERT INTO agent_messages
|
|
368
|
-
(id, session_id, from_agent, to_agent, message_type, content, artifact_reference, timestamp, processed)
|
|
369
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'), 0)
|
|
370
|
-
`);
|
|
371
|
-
|
|
372
|
-
stmt.run(
|
|
373
|
-
id,
|
|
374
|
-
message.session_id,
|
|
375
|
-
message.from_agent,
|
|
376
|
-
message.to_agent,
|
|
377
|
-
message.message_type,
|
|
378
|
-
message.content,
|
|
379
|
-
message.artifact_reference || null
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
this.logger.debug(`Sent message from ${message.from_agent} to ${message.to_agent}`);
|
|
383
|
-
} catch (error) {
|
|
384
|
-
this.logger.error('Failed to send agent message', error);
|
|
385
|
-
throw error;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// Check for pending messages
|
|
390
|
-
async checkForMessages(agent_id: string, session_id: string): Promise<AgentMessage[]> {
|
|
391
|
-
try {
|
|
392
|
-
const messages = this.db.prepare(`
|
|
393
|
-
SELECT * FROM agent_messages
|
|
394
|
-
WHERE session_id = ? AND to_agent = ? AND processed = 0
|
|
395
|
-
ORDER BY timestamp ASC
|
|
396
|
-
`).all(session_id, agent_id);
|
|
397
|
-
|
|
398
|
-
// Mark messages as processed
|
|
399
|
-
if (messages.length > 0) {
|
|
400
|
-
const ids = messages.map((m: any) => m.id);
|
|
401
|
-
const placeholders = ids.map(() => '?').join(',');
|
|
402
|
-
this.db.prepare(`
|
|
403
|
-
UPDATE agent_messages
|
|
404
|
-
SET processed = 1
|
|
405
|
-
WHERE id IN (${placeholders})
|
|
406
|
-
`).run(...ids);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return messages as AgentMessage[];
|
|
410
|
-
} catch (error) {
|
|
411
|
-
this.logger.error('Failed to check for messages', error);
|
|
412
|
-
return [];
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// Track performance metrics
|
|
417
|
-
async trackPerformance(metric: Omit<PerformanceMetric, 'timestamp'>): Promise<void> {
|
|
418
|
-
try {
|
|
419
|
-
const stmt = this.db.prepare(`
|
|
420
|
-
INSERT INTO performance_metrics
|
|
421
|
-
(session_id, agent_id, operation_name, duration_ms, success, error_message, timestamp)
|
|
422
|
-
VALUES (?, ?, ?, ?, ?, ?, datetime('now'))
|
|
423
|
-
`);
|
|
424
|
-
|
|
425
|
-
stmt.run(
|
|
426
|
-
metric.session_id,
|
|
427
|
-
metric.agent_id,
|
|
428
|
-
metric.operation_name,
|
|
429
|
-
metric.duration_ms,
|
|
430
|
-
metric.success ? 1 : 0,
|
|
431
|
-
metric.error_message || null
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
this.logger.debug(`Tracked performance: ${metric.operation_name} (${metric.duration_ms}ms)`);
|
|
435
|
-
} catch (error) {
|
|
436
|
-
this.logger.error('Failed to track performance', error);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// Record deployment
|
|
441
|
-
async recordDeployment(
|
|
442
|
-
session_id: string,
|
|
443
|
-
artifact_sys_id: string,
|
|
444
|
-
deployment_type: string,
|
|
445
|
-
success: boolean,
|
|
446
|
-
agent_id: string,
|
|
447
|
-
error_details?: string
|
|
448
|
-
): Promise<void> {
|
|
449
|
-
try {
|
|
450
|
-
const id = `deploy_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
451
|
-
|
|
452
|
-
const stmt = this.db.prepare(`
|
|
453
|
-
INSERT INTO deployment_history
|
|
454
|
-
(id, session_id, artifact_sys_id, deployment_type, success, deployment_time, agent_id, error_details, rollback_available)
|
|
455
|
-
VALUES (?, ?, ?, ?, ?, datetime('now'), ?, ?, ?)
|
|
456
|
-
`);
|
|
457
|
-
|
|
458
|
-
stmt.run(
|
|
459
|
-
id,
|
|
460
|
-
session_id,
|
|
461
|
-
artifact_sys_id,
|
|
462
|
-
deployment_type,
|
|
463
|
-
success ? 1 : 0,
|
|
464
|
-
agent_id,
|
|
465
|
-
error_details || null,
|
|
466
|
-
success ? 1 : 0
|
|
467
|
-
);
|
|
468
|
-
|
|
469
|
-
this.logger.debug(`Recorded deployment: ${deployment_type} for ${artifact_sys_id}`);
|
|
470
|
-
} catch (error) {
|
|
471
|
-
this.logger.error('Failed to record deployment', error);
|
|
472
|
-
throw error;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
// Get artifact by sys_id
|
|
477
|
-
async getArtifact(sys_id: string): Promise<ArtifactRecord | null> {
|
|
478
|
-
try {
|
|
479
|
-
const artifact = this.db.prepare(`
|
|
480
|
-
SELECT * FROM servicenow_artifacts WHERE sys_id = ?
|
|
481
|
-
`).get(sys_id);
|
|
482
|
-
|
|
483
|
-
return artifact as ArtifactRecord | null;
|
|
484
|
-
} catch (error) {
|
|
485
|
-
this.logger.error('Failed to get artifact', error);
|
|
486
|
-
return null;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// Get all artifacts for session
|
|
491
|
-
async getSessionArtifacts(session_id: string): Promise<ArtifactRecord[]> {
|
|
492
|
-
try {
|
|
493
|
-
const artifacts = this.db.prepare(`
|
|
494
|
-
SELECT * FROM servicenow_artifacts
|
|
495
|
-
WHERE session_id = ?
|
|
496
|
-
ORDER BY created_at DESC
|
|
497
|
-
`).all(session_id);
|
|
498
|
-
|
|
499
|
-
return artifacts as ArtifactRecord[];
|
|
500
|
-
} catch (error) {
|
|
501
|
-
this.logger.error('Failed to get session artifacts', error);
|
|
502
|
-
return [];
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
// Clear session data (for cleanup)
|
|
507
|
-
async clearSession(session_id: string): Promise<void> {
|
|
508
|
-
try {
|
|
509
|
-
this.logger.info(`Clearing session data for ${session_id}`);
|
|
510
|
-
|
|
511
|
-
// Clear all session-related data
|
|
512
|
-
this.db.prepare('DELETE FROM agent_coordination WHERE session_id = ?').run(session_id);
|
|
513
|
-
this.db.prepare('DELETE FROM agent_messages WHERE session_id = ?').run(session_id);
|
|
514
|
-
this.db.prepare('DELETE FROM shared_context WHERE session_id = ?').run(session_id);
|
|
515
|
-
this.db.prepare('DELETE FROM agent_dependencies WHERE session_id = ?').run(session_id);
|
|
516
|
-
this.db.prepare('DELETE FROM performance_metrics WHERE session_id = ?').run(session_id);
|
|
517
|
-
|
|
518
|
-
this.logger.info(`Cleared session data for ${session_id}`);
|
|
519
|
-
} catch (error) {
|
|
520
|
-
this.logger.error('Failed to clear session', error);
|
|
521
|
-
throw error;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// Generic query method for custom queries
|
|
526
|
-
async query(sql: string, params: any[] = []): Promise<any[]> {
|
|
527
|
-
try {
|
|
528
|
-
const stmt = this.db.prepare(sql);
|
|
529
|
-
return stmt.all(...params);
|
|
530
|
-
} catch (error) {
|
|
531
|
-
this.logger.error('Query failed', { sql, error });
|
|
532
|
-
throw error;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
// Close database connection
|
|
537
|
-
close(): void {
|
|
538
|
-
this.db.close();
|
|
539
|
-
}
|
|
540
|
-
}
|