statecli-mcp-server 0.1.2 → 0.3.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 +334 -153
- package/dist/cross-file-impact.d.ts +85 -0
- package/dist/cross-file-impact.d.ts.map +1 -0
- package/dist/cross-file-impact.js +338 -0
- package/dist/cross-file-impact.js.map +1 -0
- package/dist/dependency-tracker.d.ts +78 -0
- package/dist/dependency-tracker.d.ts.map +1 -0
- package/dist/dependency-tracker.js +334 -0
- package/dist/dependency-tracker.js.map +1 -0
- package/dist/enhanced-mcp-server.d.ts +50 -0
- package/dist/enhanced-mcp-server.d.ts.map +1 -0
- package/dist/enhanced-mcp-server.js +664 -0
- package/dist/enhanced-mcp-server.js.map +1 -0
- package/dist/error-recovery.d.ts +66 -0
- package/dist/error-recovery.d.ts.map +1 -0
- package/dist/error-recovery.js +210 -0
- package/dist/error-recovery.js.map +1 -0
- package/dist/file-tracker.d.ts +81 -0
- package/dist/file-tracker.d.ts.map +1 -0
- package/dist/file-tracker.js +252 -0
- package/dist/file-tracker.js.map +1 -0
- package/dist/git-integration.d.ts +95 -0
- package/dist/git-integration.d.ts.map +1 -0
- package/dist/git-integration.js +219 -0
- package/dist/git-integration.js.map +1 -0
- package/dist/index-enhanced.d.ts +12 -0
- package/dist/index-enhanced.d.ts.map +1 -0
- package/dist/index-enhanced.js +27 -0
- package/dist/index-enhanced.js.map +1 -0
- package/dist/rollback-preview.d.ts +77 -0
- package/dist/rollback-preview.d.ts.map +1 -0
- package/dist/rollback-preview.js +244 -0
- package/dist/rollback-preview.js.map +1 -0
- package/dist/session-memory.d.ts +85 -0
- package/dist/session-memory.d.ts.map +1 -0
- package/dist/session-memory.js +325 -0
- package/dist/session-memory.js.map +1 -0
- package/dist/test-awareness.d.ts +85 -0
- package/dist/test-awareness.d.ts.map +1 -0
- package/dist/test-awareness.js +329 -0
- package/dist/test-awareness.js.map +1 -0
- package/dist/types.d.ts +11 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced MCP Server - All advanced StateCLI tools
|
|
4
|
+
*
|
|
5
|
+
* Includes: file tracking, error recovery, session memory, git integration
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.EnhancedStateCLIMCPServer = void 0;
|
|
9
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
10
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
11
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
12
|
+
const statecli_1 = require("./statecli");
|
|
13
|
+
const file_tracker_1 = require("./file-tracker");
|
|
14
|
+
const error_recovery_1 = require("./error-recovery");
|
|
15
|
+
const session_memory_1 = require("./session-memory");
|
|
16
|
+
const git_integration_1 = require("./git-integration");
|
|
17
|
+
const test_awareness_1 = require("./test-awareness");
|
|
18
|
+
const dependency_tracker_1 = require("./dependency-tracker");
|
|
19
|
+
const rollback_preview_1 = require("./rollback-preview");
|
|
20
|
+
const cross_file_impact_1 = require("./cross-file-impact");
|
|
21
|
+
const ENHANCED_TOOLS = [
|
|
22
|
+
// Original tools
|
|
23
|
+
{
|
|
24
|
+
name: 'statecli_replay',
|
|
25
|
+
description: 'Replay state changes for an entity. Shows step-by-step what happened with diffs.',
|
|
26
|
+
inputSchema: {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
entity: { type: 'string', description: 'Entity identifier (e.g., "order:7421", "file:src/index.ts")' },
|
|
30
|
+
actor: { type: 'string', description: 'Optional: filter by actor' }
|
|
31
|
+
},
|
|
32
|
+
required: ['entity']
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'statecli_undo',
|
|
37
|
+
description: 'Undo state changes. Rollback when something went wrong.',
|
|
38
|
+
inputSchema: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
properties: {
|
|
41
|
+
entity: { type: 'string', description: 'Entity identifier' },
|
|
42
|
+
steps: { type: 'number', description: 'How many steps to undo (default: 1)' }
|
|
43
|
+
},
|
|
44
|
+
required: ['entity']
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'statecli_checkpoint',
|
|
49
|
+
description: 'Create named checkpoint before making changes. Use before risky operations.',
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
entity: { type: 'string', description: 'Entity identifier' },
|
|
54
|
+
name: { type: 'string', description: 'Checkpoint name' }
|
|
55
|
+
},
|
|
56
|
+
required: ['entity', 'name']
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'statecli_log',
|
|
61
|
+
description: 'View state change history for an entity.',
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
entity: { type: 'string', description: 'Entity identifier or pattern (e.g., "order:*")' },
|
|
66
|
+
since: { type: 'string', description: 'Time filter (e.g., "1h ago", "24h ago")' },
|
|
67
|
+
actor: { type: 'string', description: 'Filter by actor' }
|
|
68
|
+
},
|
|
69
|
+
required: ['entity']
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'statecli_track',
|
|
74
|
+
description: 'Explicitly track a state change.',
|
|
75
|
+
inputSchema: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties: {
|
|
78
|
+
entity_type: { type: 'string', description: 'Type of entity' },
|
|
79
|
+
entity_id: { type: 'string', description: 'Entity ID' },
|
|
80
|
+
state: { type: 'object', description: 'State to track' },
|
|
81
|
+
actor: { type: 'string', description: 'Who is making this change' }
|
|
82
|
+
},
|
|
83
|
+
required: ['entity_type', 'entity_id', 'state']
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
// NEW: File tracking tools
|
|
87
|
+
{
|
|
88
|
+
name: 'statecli_track_file',
|
|
89
|
+
description: 'Track a file edit with before/after content. Auto-generates diff.',
|
|
90
|
+
inputSchema: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
properties: {
|
|
93
|
+
file_path: { type: 'string', description: 'Path to the file' },
|
|
94
|
+
before_content: { type: 'string', description: 'Content before edit' },
|
|
95
|
+
after_content: { type: 'string', description: 'Content after edit' },
|
|
96
|
+
actor: { type: 'string', description: 'Who made the edit' }
|
|
97
|
+
},
|
|
98
|
+
required: ['file_path', 'before_content', 'after_content']
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'statecli_file_history',
|
|
103
|
+
description: 'Get change history for a specific file.',
|
|
104
|
+
inputSchema: {
|
|
105
|
+
type: 'object',
|
|
106
|
+
properties: {
|
|
107
|
+
file_path: { type: 'string', description: 'Path to the file' }
|
|
108
|
+
},
|
|
109
|
+
required: ['file_path']
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
// NEW: Error recovery tools
|
|
113
|
+
{
|
|
114
|
+
name: 'statecli_analyze_error',
|
|
115
|
+
description: 'Analyze an error and get recovery suggestions. Use when something goes wrong.',
|
|
116
|
+
inputSchema: {
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: {
|
|
119
|
+
error_message: { type: 'string', description: 'The error message' },
|
|
120
|
+
error_type: { type: 'string', description: 'Type of error (optional)' },
|
|
121
|
+
affected_entities: {
|
|
122
|
+
type: 'array',
|
|
123
|
+
items: { type: 'string' },
|
|
124
|
+
description: 'Entities that might be affected'
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
required: ['error_message']
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'statecli_auto_recover',
|
|
132
|
+
description: 'Automatically recover from an error using the best suggestion.',
|
|
133
|
+
inputSchema: {
|
|
134
|
+
type: 'object',
|
|
135
|
+
properties: {
|
|
136
|
+
error_message: { type: 'string', description: 'The error message' },
|
|
137
|
+
affected_entities: {
|
|
138
|
+
type: 'array',
|
|
139
|
+
items: { type: 'string' },
|
|
140
|
+
description: 'Entities that might be affected'
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
required: ['error_message']
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'statecli_safe_execute',
|
|
148
|
+
description: 'Create checkpoint, execute operation, auto-rollback on error.',
|
|
149
|
+
inputSchema: {
|
|
150
|
+
type: 'object',
|
|
151
|
+
properties: {
|
|
152
|
+
entity: { type: 'string', description: 'Entity to checkpoint' },
|
|
153
|
+
operation_name: { type: 'string', description: 'Name of the operation' }
|
|
154
|
+
},
|
|
155
|
+
required: ['entity', 'operation_name']
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
// NEW: Session memory tools
|
|
159
|
+
{
|
|
160
|
+
name: 'statecli_memory_query',
|
|
161
|
+
description: 'Query memory across sessions. Ask about past actions.',
|
|
162
|
+
inputSchema: {
|
|
163
|
+
type: 'object',
|
|
164
|
+
properties: {
|
|
165
|
+
question: { type: 'string', description: 'Natural language question (e.g., "What did I change yesterday?")' },
|
|
166
|
+
entity_pattern: { type: 'string', description: 'Entity pattern to filter' },
|
|
167
|
+
hours_ago: { type: 'number', description: 'Look back this many hours' }
|
|
168
|
+
},
|
|
169
|
+
required: []
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'statecli_recent_activity',
|
|
174
|
+
description: 'Get summary of recent activity.',
|
|
175
|
+
inputSchema: {
|
|
176
|
+
type: 'object',
|
|
177
|
+
properties: {
|
|
178
|
+
hours: { type: 'number', description: 'How many hours to look back (default: 24)' }
|
|
179
|
+
},
|
|
180
|
+
required: []
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: 'statecli_session_info',
|
|
185
|
+
description: 'Get information about current and past sessions.',
|
|
186
|
+
inputSchema: {
|
|
187
|
+
type: 'object',
|
|
188
|
+
properties: {
|
|
189
|
+
session_id: { type: 'string', description: 'Specific session ID (optional)' }
|
|
190
|
+
},
|
|
191
|
+
required: []
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
// NEW: Git integration tools
|
|
195
|
+
{
|
|
196
|
+
name: 'statecli_git_status',
|
|
197
|
+
description: 'Get current git status and track it.',
|
|
198
|
+
inputSchema: {
|
|
199
|
+
type: 'object',
|
|
200
|
+
properties: {},
|
|
201
|
+
required: []
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: 'statecli_git_history',
|
|
206
|
+
description: 'Compare changes between two commits.',
|
|
207
|
+
inputSchema: {
|
|
208
|
+
type: 'object',
|
|
209
|
+
properties: {
|
|
210
|
+
from_commit: { type: 'string', description: 'Starting commit hash' },
|
|
211
|
+
to_commit: { type: 'string', description: 'Ending commit hash (default: HEAD)' }
|
|
212
|
+
},
|
|
213
|
+
required: ['from_commit']
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: 'statecli_git_checkpoint',
|
|
218
|
+
description: 'Create a checkpoint at current git state.',
|
|
219
|
+
inputSchema: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
properties: {
|
|
222
|
+
name: { type: 'string', description: 'Checkpoint name' }
|
|
223
|
+
},
|
|
224
|
+
required: []
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
// NEW v0.3.0: Test awareness tools
|
|
228
|
+
{
|
|
229
|
+
name: 'statecli_run_tests',
|
|
230
|
+
description: 'Run tests and track results. Correlates with recent code changes.',
|
|
231
|
+
inputSchema: {
|
|
232
|
+
type: 'object',
|
|
233
|
+
properties: {
|
|
234
|
+
files: { type: 'array', items: { type: 'string' }, description: 'Specific test files to run' },
|
|
235
|
+
grep: { type: 'string', description: 'Filter tests by pattern' }
|
|
236
|
+
},
|
|
237
|
+
required: []
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'statecli_test_impact',
|
|
242
|
+
description: 'Analyze which tests are affected by a changed file.',
|
|
243
|
+
inputSchema: {
|
|
244
|
+
type: 'object',
|
|
245
|
+
properties: {
|
|
246
|
+
file: { type: 'string', description: 'Changed file path' }
|
|
247
|
+
},
|
|
248
|
+
required: ['file']
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: 'statecli_suggest_tests',
|
|
253
|
+
description: 'Suggest which tests to run based on recent changes.',
|
|
254
|
+
inputSchema: {
|
|
255
|
+
type: 'object',
|
|
256
|
+
properties: {},
|
|
257
|
+
required: []
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
// NEW v0.3.0: Dependency tracking tools
|
|
261
|
+
{
|
|
262
|
+
name: 'statecli_analyze_dependencies',
|
|
263
|
+
description: 'Analyze what files depend on a given file. Shows impact of changes.',
|
|
264
|
+
inputSchema: {
|
|
265
|
+
type: 'object',
|
|
266
|
+
properties: {
|
|
267
|
+
file: { type: 'string', description: 'File to analyze' }
|
|
268
|
+
},
|
|
269
|
+
required: ['file']
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: 'statecli_dependency_tree',
|
|
274
|
+
description: 'Get dependency tree for a file.',
|
|
275
|
+
inputSchema: {
|
|
276
|
+
type: 'object',
|
|
277
|
+
properties: {
|
|
278
|
+
file: { type: 'string', description: 'File path' },
|
|
279
|
+
depth: { type: 'number', description: 'Max depth (default: 3)' }
|
|
280
|
+
},
|
|
281
|
+
required: ['file']
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: 'statecli_find_circular',
|
|
286
|
+
description: 'Find circular dependencies in the project.',
|
|
287
|
+
inputSchema: {
|
|
288
|
+
type: 'object',
|
|
289
|
+
properties: {},
|
|
290
|
+
required: []
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
// NEW v0.3.0: Rollback preview tools
|
|
294
|
+
{
|
|
295
|
+
name: 'statecli_preview_undo',
|
|
296
|
+
description: 'Preview what will happen if you undo N steps. Shows diff before executing.',
|
|
297
|
+
inputSchema: {
|
|
298
|
+
type: 'object',
|
|
299
|
+
properties: {
|
|
300
|
+
entity: { type: 'string', description: 'Entity identifier' },
|
|
301
|
+
steps: { type: 'number', description: 'Steps to preview undoing (default: 1)' }
|
|
302
|
+
},
|
|
303
|
+
required: ['entity']
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: 'statecli_simulate_undo',
|
|
308
|
+
description: 'Simulate undo without executing. Shows resulting state and side effects.',
|
|
309
|
+
inputSchema: {
|
|
310
|
+
type: 'object',
|
|
311
|
+
properties: {
|
|
312
|
+
entity: { type: 'string', description: 'Entity identifier' },
|
|
313
|
+
steps: { type: 'number', description: 'Steps to simulate (default: 1)' }
|
|
314
|
+
},
|
|
315
|
+
required: ['entity']
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
// NEW v0.3.0: Cross-file impact tools
|
|
319
|
+
{
|
|
320
|
+
name: 'statecli_predict_impact',
|
|
321
|
+
description: 'Predict impact of a proposed change. Shows affected files and breaking changes.',
|
|
322
|
+
inputSchema: {
|
|
323
|
+
type: 'object',
|
|
324
|
+
properties: {
|
|
325
|
+
file: { type: 'string', description: 'File to change' },
|
|
326
|
+
change_type: { type: 'string', enum: ['modify', 'rename', 'delete', 'move'], description: 'Type of change' },
|
|
327
|
+
symbol: { type: 'string', description: 'Specific symbol being changed (optional)' },
|
|
328
|
+
new_name: { type: 'string', description: 'New name if renaming (optional)' }
|
|
329
|
+
},
|
|
330
|
+
required: ['file', 'change_type']
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
name: 'statecli_is_safe',
|
|
335
|
+
description: 'Check if a proposed change is safe to make.',
|
|
336
|
+
inputSchema: {
|
|
337
|
+
type: 'object',
|
|
338
|
+
properties: {
|
|
339
|
+
file: { type: 'string', description: 'File to change' },
|
|
340
|
+
change_type: { type: 'string', enum: ['modify', 'rename', 'delete', 'move'], description: 'Type of change' },
|
|
341
|
+
symbol: { type: 'string', description: 'Specific symbol (optional)' }
|
|
342
|
+
},
|
|
343
|
+
required: ['file', 'change_type']
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: 'statecli_safe_change_order',
|
|
348
|
+
description: 'Get recommended order for changing multiple files safely.',
|
|
349
|
+
inputSchema: {
|
|
350
|
+
type: 'object',
|
|
351
|
+
properties: {
|
|
352
|
+
files: { type: 'array', items: { type: 'string' }, description: 'Files to change' }
|
|
353
|
+
},
|
|
354
|
+
required: ['files']
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
];
|
|
358
|
+
class EnhancedStateCLIMCPServer {
|
|
359
|
+
server;
|
|
360
|
+
statecli;
|
|
361
|
+
fileTracker;
|
|
362
|
+
errorRecovery;
|
|
363
|
+
sessionMemory;
|
|
364
|
+
gitIntegration;
|
|
365
|
+
testAwareness;
|
|
366
|
+
dependencyTracker;
|
|
367
|
+
rollbackPreview;
|
|
368
|
+
crossFileImpact;
|
|
369
|
+
constructor(config) {
|
|
370
|
+
this.statecli = new statecli_1.StateCLI(config);
|
|
371
|
+
this.fileTracker = new file_tracker_1.FileTracker(this.statecli);
|
|
372
|
+
this.errorRecovery = new error_recovery_1.ErrorRecovery(this.statecli);
|
|
373
|
+
this.sessionMemory = new session_memory_1.SessionMemory(this.statecli);
|
|
374
|
+
this.gitIntegration = new git_integration_1.GitIntegration(this.statecli);
|
|
375
|
+
this.testAwareness = new test_awareness_1.TestAwareness(this.statecli);
|
|
376
|
+
this.dependencyTracker = new dependency_tracker_1.DependencyTracker(this.statecli);
|
|
377
|
+
this.rollbackPreview = new rollback_preview_1.RollbackPreview(this.statecli);
|
|
378
|
+
this.crossFileImpact = new cross_file_impact_1.CrossFileImpact(this.statecli);
|
|
379
|
+
this.server = new index_js_1.Server({ name: 'statecli-enhanced', version: '3.0.0' }, { capabilities: { tools: {} } });
|
|
380
|
+
this.setupHandlers();
|
|
381
|
+
}
|
|
382
|
+
setupHandlers() {
|
|
383
|
+
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
384
|
+
return { tools: ENHANCED_TOOLS };
|
|
385
|
+
});
|
|
386
|
+
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
387
|
+
const { name, arguments: args } = request.params;
|
|
388
|
+
try {
|
|
389
|
+
switch (name) {
|
|
390
|
+
// Original tools
|
|
391
|
+
case 'statecli_replay':
|
|
392
|
+
return this.handleReplay(args);
|
|
393
|
+
case 'statecli_undo':
|
|
394
|
+
return this.handleUndo(args);
|
|
395
|
+
case 'statecli_checkpoint':
|
|
396
|
+
return this.handleCheckpoint(args);
|
|
397
|
+
case 'statecli_log':
|
|
398
|
+
return this.handleLog(args);
|
|
399
|
+
case 'statecli_track':
|
|
400
|
+
return this.handleTrack(args);
|
|
401
|
+
// File tracking
|
|
402
|
+
case 'statecli_track_file':
|
|
403
|
+
return this.handleTrackFile(args);
|
|
404
|
+
case 'statecli_file_history':
|
|
405
|
+
return this.handleFileHistory(args);
|
|
406
|
+
// Error recovery
|
|
407
|
+
case 'statecli_analyze_error':
|
|
408
|
+
return this.handleAnalyzeError(args);
|
|
409
|
+
case 'statecli_auto_recover':
|
|
410
|
+
return this.handleAutoRecover(args);
|
|
411
|
+
case 'statecli_safe_execute':
|
|
412
|
+
return this.handleSafeExecute(args);
|
|
413
|
+
// Session memory
|
|
414
|
+
case 'statecli_memory_query':
|
|
415
|
+
return this.handleMemoryQuery(args);
|
|
416
|
+
case 'statecli_recent_activity':
|
|
417
|
+
return this.handleRecentActivity(args);
|
|
418
|
+
case 'statecli_session_info':
|
|
419
|
+
return this.handleSessionInfo(args);
|
|
420
|
+
// Git integration
|
|
421
|
+
case 'statecli_git_status':
|
|
422
|
+
return this.handleGitStatus();
|
|
423
|
+
case 'statecli_git_history':
|
|
424
|
+
return this.handleGitHistory(args);
|
|
425
|
+
case 'statecli_git_checkpoint':
|
|
426
|
+
return this.handleGitCheckpoint(args);
|
|
427
|
+
// Test awareness (v0.3.0)
|
|
428
|
+
case 'statecli_run_tests':
|
|
429
|
+
return this.handleRunTests(args);
|
|
430
|
+
case 'statecli_test_impact':
|
|
431
|
+
return this.handleTestImpact(args);
|
|
432
|
+
case 'statecli_suggest_tests':
|
|
433
|
+
return this.handleSuggestTests();
|
|
434
|
+
// Dependency tracking (v0.3.0)
|
|
435
|
+
case 'statecli_analyze_dependencies':
|
|
436
|
+
return this.handleAnalyzeDependencies(args);
|
|
437
|
+
case 'statecli_dependency_tree':
|
|
438
|
+
return this.handleDependencyTree(args);
|
|
439
|
+
case 'statecli_find_circular':
|
|
440
|
+
return this.handleFindCircular();
|
|
441
|
+
// Rollback preview (v0.3.0)
|
|
442
|
+
case 'statecli_preview_undo':
|
|
443
|
+
return this.handlePreviewUndo(args);
|
|
444
|
+
case 'statecli_simulate_undo':
|
|
445
|
+
return this.handleSimulateUndo(args);
|
|
446
|
+
// Cross-file impact (v0.3.0)
|
|
447
|
+
case 'statecli_predict_impact':
|
|
448
|
+
return this.handlePredictImpact(args);
|
|
449
|
+
case 'statecli_is_safe':
|
|
450
|
+
return this.handleIsSafe(args);
|
|
451
|
+
case 'statecli_safe_change_order':
|
|
452
|
+
return this.handleSafeChangeOrder(args);
|
|
453
|
+
default:
|
|
454
|
+
return { content: [{ type: 'text', text: `Unknown tool: ${name}` }], isError: true };
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
459
|
+
return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true };
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
// Original tool handlers
|
|
464
|
+
handleReplay(args) {
|
|
465
|
+
const result = this.statecli.replay(args.entity, { actor: args.actor });
|
|
466
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
467
|
+
}
|
|
468
|
+
handleUndo(args) {
|
|
469
|
+
const result = this.statecli.undo(args.entity, args.steps || 1);
|
|
470
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
471
|
+
}
|
|
472
|
+
handleCheckpoint(args) {
|
|
473
|
+
const result = this.statecli.checkpoint(args.entity, args.name);
|
|
474
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
475
|
+
}
|
|
476
|
+
handleLog(args) {
|
|
477
|
+
const result = this.statecli.log(args.entity, { since: args.since, actor: args.actor });
|
|
478
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
479
|
+
}
|
|
480
|
+
handleTrack(args) {
|
|
481
|
+
const result = this.statecli.track(args.entity_type, args.entity_id, args.state, args.actor || 'ai-agent');
|
|
482
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
483
|
+
}
|
|
484
|
+
// File tracking handlers
|
|
485
|
+
handleTrackFile(args) {
|
|
486
|
+
const result = this.fileTracker.trackEdit(args.file_path, args.before_content, args.after_content, args.actor);
|
|
487
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
488
|
+
}
|
|
489
|
+
handleFileHistory(args) {
|
|
490
|
+
const result = this.fileTracker.getFileHistory(args.file_path);
|
|
491
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
492
|
+
}
|
|
493
|
+
// Error recovery handlers
|
|
494
|
+
handleAnalyzeError(args) {
|
|
495
|
+
const error = new Error(args.error_message);
|
|
496
|
+
if (args.error_type)
|
|
497
|
+
error.name = args.error_type;
|
|
498
|
+
const result = this.errorRecovery.analyzeError(error, args.affected_entities || []);
|
|
499
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
500
|
+
}
|
|
501
|
+
handleAutoRecover(args) {
|
|
502
|
+
const analysis = this.errorRecovery.analyzeError(new Error(args.error_message), args.affected_entities || []);
|
|
503
|
+
const result = this.errorRecovery.autoRecover(analysis);
|
|
504
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
505
|
+
}
|
|
506
|
+
handleSafeExecute(args) {
|
|
507
|
+
// Create checkpoint - the actual execution would be done by the caller
|
|
508
|
+
const checkpoint = this.statecli.checkpoint(args.entity, `before-${args.operation_name}`);
|
|
509
|
+
return {
|
|
510
|
+
content: [{
|
|
511
|
+
type: 'text',
|
|
512
|
+
text: JSON.stringify({
|
|
513
|
+
checkpoint_created: true,
|
|
514
|
+
checkpoint_id: checkpoint.id,
|
|
515
|
+
entity: args.entity,
|
|
516
|
+
operation: args.operation_name,
|
|
517
|
+
message: `Checkpoint created. Proceed with ${args.operation_name}. Call statecli_undo if it fails.`
|
|
518
|
+
}, null, 2)
|
|
519
|
+
}]
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
// Session memory handlers
|
|
523
|
+
handleMemoryQuery(args) {
|
|
524
|
+
let result;
|
|
525
|
+
if (args.question) {
|
|
526
|
+
result = this.sessionMemory.ask(args.question);
|
|
527
|
+
}
|
|
528
|
+
else if (args.hours_ago) {
|
|
529
|
+
result = this.sessionMemory.getRecentActivity(args.hours_ago);
|
|
530
|
+
}
|
|
531
|
+
else if (args.entity_pattern) {
|
|
532
|
+
result = this.sessionMemory.getEntityHistory(args.entity_pattern);
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
result = this.sessionMemory.getRecentActivity(24);
|
|
536
|
+
}
|
|
537
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
538
|
+
}
|
|
539
|
+
handleRecentActivity(args) {
|
|
540
|
+
const result = this.sessionMemory.getRecentActivity(args.hours || 24);
|
|
541
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
542
|
+
}
|
|
543
|
+
handleSessionInfo(args) {
|
|
544
|
+
if (args.session_id) {
|
|
545
|
+
const result = this.sessionMemory.getSession(args.session_id);
|
|
546
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
const sessions = this.sessionMemory.getSessions();
|
|
550
|
+
const currentId = this.sessionMemory.getSessionId();
|
|
551
|
+
return {
|
|
552
|
+
content: [{
|
|
553
|
+
type: 'text',
|
|
554
|
+
text: JSON.stringify({ currentSession: currentId, recentSessions: sessions.slice(0, 10) }, null, 2)
|
|
555
|
+
}]
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
// Git integration handlers
|
|
560
|
+
handleGitStatus() {
|
|
561
|
+
if (!this.gitIntegration.isGitRepo()) {
|
|
562
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: 'Not a git repository' }) }] };
|
|
563
|
+
}
|
|
564
|
+
const status = {
|
|
565
|
+
branch: this.gitIntegration.getCurrentBranch(),
|
|
566
|
+
commit: this.gitIntegration.getCurrentCommit(),
|
|
567
|
+
uncommittedChanges: this.gitIntegration.getUncommittedChanges(),
|
|
568
|
+
recentCommits: this.gitIntegration.getRecentCommits(5)
|
|
569
|
+
};
|
|
570
|
+
this.gitIntegration.trackGitState();
|
|
571
|
+
return { content: [{ type: 'text', text: JSON.stringify(status, null, 2) }] };
|
|
572
|
+
}
|
|
573
|
+
handleGitHistory(args) {
|
|
574
|
+
const toCommit = args.to_commit || 'HEAD';
|
|
575
|
+
const result = this.gitIntegration.getCommitHistory(args.from_commit, toCommit);
|
|
576
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
577
|
+
}
|
|
578
|
+
handleGitCheckpoint(args) {
|
|
579
|
+
const result = this.gitIntegration.createGitCheckpoint(args.name);
|
|
580
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
581
|
+
}
|
|
582
|
+
// Test awareness handlers (v0.3.0)
|
|
583
|
+
handleRunTests(args) {
|
|
584
|
+
const result = this.testAwareness.runTests({ files: args.files, grep: args.grep, trackChanges: true });
|
|
585
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
586
|
+
}
|
|
587
|
+
handleTestImpact(args) {
|
|
588
|
+
const result = this.testAwareness.analyzeTestImpact(args.file);
|
|
589
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
590
|
+
}
|
|
591
|
+
handleSuggestTests() {
|
|
592
|
+
const result = this.testAwareness.suggestTests();
|
|
593
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
594
|
+
}
|
|
595
|
+
// Dependency tracking handlers (v0.3.0)
|
|
596
|
+
handleAnalyzeDependencies(args) {
|
|
597
|
+
this.dependencyTracker.buildGraph();
|
|
598
|
+
const result = this.dependencyTracker.analyzeImpact(args.file);
|
|
599
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
600
|
+
}
|
|
601
|
+
handleDependencyTree(args) {
|
|
602
|
+
this.dependencyTracker.buildGraph();
|
|
603
|
+
const result = this.dependencyTracker.getDependencyTree(args.file, args.depth || 3);
|
|
604
|
+
return { content: [{ type: 'text', text: result }] };
|
|
605
|
+
}
|
|
606
|
+
handleFindCircular() {
|
|
607
|
+
this.dependencyTracker.buildGraph();
|
|
608
|
+
const cycles = this.dependencyTracker.findCircularDependencies();
|
|
609
|
+
return {
|
|
610
|
+
content: [{
|
|
611
|
+
type: 'text',
|
|
612
|
+
text: JSON.stringify({
|
|
613
|
+
found: cycles.length,
|
|
614
|
+
cycles: cycles.slice(0, 10)
|
|
615
|
+
}, null, 2)
|
|
616
|
+
}]
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
// Rollback preview handlers (v0.3.0)
|
|
620
|
+
handlePreviewUndo(args) {
|
|
621
|
+
const result = this.rollbackPreview.previewUndo(args.entity, args.steps || 1);
|
|
622
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
623
|
+
}
|
|
624
|
+
handleSimulateUndo(args) {
|
|
625
|
+
const result = this.rollbackPreview.simulateUndo(args.entity, args.steps || 1);
|
|
626
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
627
|
+
}
|
|
628
|
+
// Cross-file impact handlers (v0.3.0)
|
|
629
|
+
handlePredictImpact(args) {
|
|
630
|
+
this.crossFileImpact.buildIndex();
|
|
631
|
+
const result = this.crossFileImpact.predictImpact({
|
|
632
|
+
file: args.file,
|
|
633
|
+
changeType: args.change_type,
|
|
634
|
+
symbol: args.symbol,
|
|
635
|
+
newValue: args.new_name
|
|
636
|
+
});
|
|
637
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
638
|
+
}
|
|
639
|
+
handleIsSafe(args) {
|
|
640
|
+
this.crossFileImpact.buildIndex();
|
|
641
|
+
const result = this.crossFileImpact.isChangeSafe({
|
|
642
|
+
file: args.file,
|
|
643
|
+
changeType: args.change_type,
|
|
644
|
+
symbol: args.symbol
|
|
645
|
+
});
|
|
646
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
647
|
+
}
|
|
648
|
+
handleSafeChangeOrder(args) {
|
|
649
|
+
this.dependencyTracker.buildGraph();
|
|
650
|
+
const result = this.crossFileImpact.getSafeChangeOrder(args.files);
|
|
651
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
652
|
+
}
|
|
653
|
+
async run() {
|
|
654
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
655
|
+
await this.server.connect(transport);
|
|
656
|
+
console.error('StateCLI Enhanced MCP Server running on stdio');
|
|
657
|
+
}
|
|
658
|
+
close() {
|
|
659
|
+
this.sessionMemory.endSession();
|
|
660
|
+
this.statecli.close();
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
exports.EnhancedStateCLIMCPServer = EnhancedStateCLIMCPServer;
|
|
664
|
+
//# sourceMappingURL=enhanced-mcp-server.js.map
|