statecli-mcp-server 0.1.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/LICENSE +21 -0
- package/README.md +415 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +203 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server.d.ts +15 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +250 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/statecli.d.ts +26 -0
- package/dist/statecli.d.ts.map +1 -0
- package/dist/statecli.js +121 -0
- package/dist/statecli.js.map +1 -0
- package/dist/storage.d.ts +36 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +306 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 StateCLI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
# StateCLI - MCP Server for State Replay & Self-Debugging
|
|
2
|
+
|
|
3
|
+
> **For AI Agents:** Memory, replay, and undo capability for your actions.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/statecli-mcp-server)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
**MCP Server** | **State Management** | **Agent Self-Debugging** | **Rollback Capability**
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx statecli-mcp-server
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## MCP Client Configuration
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"mcpServers": {
|
|
23
|
+
"statecli": {
|
|
24
|
+
"command": "npx",
|
|
25
|
+
"args": ["-y", "statecli-mcp-server"]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Available Tools
|
|
34
|
+
|
|
35
|
+
| Tool | Description | Use When |
|
|
36
|
+
|------|-------------|----------|
|
|
37
|
+
| `statecli_replay` | See what you just did | Debugging, understanding past behavior |
|
|
38
|
+
| `statecli_undo` | Rollback mistakes | Made an error, need to retry |
|
|
39
|
+
| `statecli_checkpoint` | Save state before risky ops | About to do something risky |
|
|
40
|
+
| `statecli_log` | View action history | Need audit trail |
|
|
41
|
+
| `statecli_track` | Track state changes | Making important modifications |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Quick Example
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
// Checkpoint before risky operation
|
|
49
|
+
await statecli_checkpoint({ entity: "order:123", name: "before-refund" });
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
await processOrder(order);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
// Replay to see what went wrong
|
|
55
|
+
const replay = await statecli_replay({ entity: "order:123" });
|
|
56
|
+
|
|
57
|
+
// Undo if needed
|
|
58
|
+
await statecli_undo({ entity: "order:123" });
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Why AI Agents Need This
|
|
65
|
+
|
|
66
|
+
| Problem | Solution |
|
|
67
|
+
|---------|----------|
|
|
68
|
+
| "I changed something but don't know what" | `statecli_replay(entity)` |
|
|
69
|
+
| "I broke something and need to undo" | `statecli_undo(entity)` |
|
|
70
|
+
| "I want to try something risky" | `statecli_checkpoint(entity)` |
|
|
71
|
+
| "I need to understand my past behavior" | `statecli_log(entity)` |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Tool Reference
|
|
76
|
+
|
|
77
|
+
### `statecli_replay`
|
|
78
|
+
|
|
79
|
+
Replay state changes for an entity. Shows step-by-step what happened.
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"entity": "order:7421",
|
|
84
|
+
"actor": "ai-agent"
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### `statecli_undo`
|
|
89
|
+
|
|
90
|
+
Undo state changes. Rollback when something went wrong.
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"entity": "order:7421",
|
|
95
|
+
"steps": 3
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### `statecli_checkpoint`
|
|
100
|
+
|
|
101
|
+
Create named checkpoint before making changes.
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"entity": "order:7421",
|
|
106
|
+
"name": "before-refund"
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### `statecli_log`
|
|
111
|
+
|
|
112
|
+
View state change history for an entity.
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"entity": "order:7421",
|
|
117
|
+
"since": "1h ago",
|
|
118
|
+
"actor": "ai-agent"
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### `statecli_track`
|
|
123
|
+
|
|
124
|
+
Explicitly track a state change.
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"entity_type": "order",
|
|
129
|
+
"entity_id": "7421",
|
|
130
|
+
"state": { "status": "paid", "amount": 49.99 }
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Agent Self-Debugging Pattern
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
try {
|
|
140
|
+
await agent.run(task);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
// Get replay of what just happened
|
|
143
|
+
const replay = await mcp.call("statecli_replay", {
|
|
144
|
+
entity: `task:${task.id}`,
|
|
145
|
+
actor: "ai-agent"
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Analyze what went wrong
|
|
149
|
+
const analysis = await llm.analyze({
|
|
150
|
+
replay: replay.result,
|
|
151
|
+
error: error.message,
|
|
152
|
+
prompt: "What went wrong in this sequence?"
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Undo if fixable
|
|
156
|
+
if (analysis.canRetry) {
|
|
157
|
+
await mcp.call("statecli_undo", {
|
|
158
|
+
entity: `task:${task.id}`,
|
|
159
|
+
steps: 1
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Retry with fix
|
|
163
|
+
await agent.runWithFix(task, analysis.fix);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## MCP Configuration Examples
|
|
171
|
+
|
|
172
|
+
### Claude Desktop
|
|
173
|
+
|
|
174
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{
|
|
178
|
+
"mcpServers": {
|
|
179
|
+
"statecli": {
|
|
180
|
+
"command": "npx",
|
|
181
|
+
"args": ["-y", "statecli-mcp-server"]
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Cursor
|
|
188
|
+
|
|
189
|
+
Add to `.cursor/mcp.json`:
|
|
190
|
+
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"mcpServers": {
|
|
194
|
+
"statecli": {
|
|
195
|
+
"command": "npx",
|
|
196
|
+
"args": ["-y", "statecli-mcp-server"]
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Windsurf
|
|
203
|
+
|
|
204
|
+
Add to MCP settings:
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"mcpServers": {
|
|
209
|
+
"statecli": {
|
|
210
|
+
"command": "npx",
|
|
211
|
+
"args": ["-y", "statecli-mcp-server"]
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## CLI Usage
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# Initialize configuration
|
|
223
|
+
statecli init
|
|
224
|
+
|
|
225
|
+
# Track a state change
|
|
226
|
+
statecli track order 7421 -d '{"status": "pending"}'
|
|
227
|
+
|
|
228
|
+
# Replay changes
|
|
229
|
+
statecli replay order:7421
|
|
230
|
+
|
|
231
|
+
# View log
|
|
232
|
+
statecli log order:7421 --since "1h ago"
|
|
233
|
+
|
|
234
|
+
# Create checkpoint
|
|
235
|
+
statecli checkpoint order:7421 before-payment
|
|
236
|
+
|
|
237
|
+
# Undo last change
|
|
238
|
+
statecli undo order:7421
|
|
239
|
+
|
|
240
|
+
# Get current state
|
|
241
|
+
statecli state order:7421
|
|
242
|
+
|
|
243
|
+
# List all entities
|
|
244
|
+
statecli list
|
|
245
|
+
|
|
246
|
+
# Start MCP server
|
|
247
|
+
statecli serve
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Programmatic Usage
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { StateCLI } from 'statecli-mcp-server';
|
|
256
|
+
|
|
257
|
+
const cli = new StateCLI();
|
|
258
|
+
|
|
259
|
+
// Track state
|
|
260
|
+
cli.track('order', '7421', { status: 'pending' }, 'ai-agent');
|
|
261
|
+
|
|
262
|
+
// Replay
|
|
263
|
+
const replay = cli.replay('order:7421');
|
|
264
|
+
|
|
265
|
+
// Checkpoint
|
|
266
|
+
cli.checkpoint('order:7421', 'before-payment');
|
|
267
|
+
|
|
268
|
+
// Undo
|
|
269
|
+
cli.undo('order:7421', 1);
|
|
270
|
+
|
|
271
|
+
// Log with wildcards
|
|
272
|
+
const log = cli.log('order:*', { since: '1h ago' });
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## Integration Examples
|
|
278
|
+
|
|
279
|
+
### LangChain
|
|
280
|
+
|
|
281
|
+
```javascript
|
|
282
|
+
import { AgentExecutor } from "langchain/agents";
|
|
283
|
+
|
|
284
|
+
const executor = AgentExecutor.fromAgentAndTools({
|
|
285
|
+
agent,
|
|
286
|
+
tools: [...tools, statecliMCPTools],
|
|
287
|
+
callbacks: [{
|
|
288
|
+
handleToolEnd: async (tool, output) => {
|
|
289
|
+
await statecli_track({
|
|
290
|
+
entity_type: "agent-task",
|
|
291
|
+
entity_id: taskId,
|
|
292
|
+
state: { tool, output }
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}]
|
|
296
|
+
});
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### AutoGPT
|
|
300
|
+
|
|
301
|
+
```python
|
|
302
|
+
from statecli import StateCLI
|
|
303
|
+
|
|
304
|
+
class SelfDebuggingAgent:
|
|
305
|
+
def __init__(self):
|
|
306
|
+
self.statecli = StateCLI()
|
|
307
|
+
|
|
308
|
+
async def execute(self, task):
|
|
309
|
+
checkpoint = await self.statecli.checkpoint(f"task:{task.id}")
|
|
310
|
+
try:
|
|
311
|
+
await self.run_task(task)
|
|
312
|
+
except Exception as e:
|
|
313
|
+
replay = await self.statecli.replay(f"task:{task.id}")
|
|
314
|
+
await self.statecli.undo(f"task:{task.id}")
|
|
315
|
+
await self.retry_with_context(task, replay)
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### CrewAI
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
from crewai import Agent, Task
|
|
322
|
+
from statecli import statecli_mcp_tool
|
|
323
|
+
|
|
324
|
+
agent = Agent(
|
|
325
|
+
role="Developer",
|
|
326
|
+
tools=[statecli_mcp_tool],
|
|
327
|
+
allow_delegation=True
|
|
328
|
+
)
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## Output Format
|
|
334
|
+
|
|
335
|
+
All outputs are JSON-stable:
|
|
336
|
+
|
|
337
|
+
```json
|
|
338
|
+
{
|
|
339
|
+
"entity": "order:7421",
|
|
340
|
+
"changes": [
|
|
341
|
+
{
|
|
342
|
+
"timestamp": "2025-01-07T10:23:45Z",
|
|
343
|
+
"step": 1,
|
|
344
|
+
"before": { "status": null },
|
|
345
|
+
"after": { "status": "pending" },
|
|
346
|
+
"actor": "ai-agent"
|
|
347
|
+
}
|
|
348
|
+
],
|
|
349
|
+
"summary": "1 state change found",
|
|
350
|
+
"suggested_next_actions": ["investigate latest change"]
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Performance
|
|
357
|
+
|
|
358
|
+
- **Write latency:** < 1ms (async, non-blocking)
|
|
359
|
+
- **Read latency:** < 5ms (local SQLite)
|
|
360
|
+
- **Storage:** ~100 bytes per state change
|
|
361
|
+
- **Overhead:** Negligible for production use
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## Configuration
|
|
366
|
+
|
|
367
|
+
Create `.statecli/config.json`:
|
|
368
|
+
|
|
369
|
+
```json
|
|
370
|
+
{
|
|
371
|
+
"storage": {
|
|
372
|
+
"type": "local",
|
|
373
|
+
"path": ".statecli/state.db"
|
|
374
|
+
},
|
|
375
|
+
"autoTrack": {
|
|
376
|
+
"enabled": true,
|
|
377
|
+
"patterns": ["order:*", "user:*", "task:*"]
|
|
378
|
+
},
|
|
379
|
+
"retention": {
|
|
380
|
+
"days": 30,
|
|
381
|
+
"maxChangesPerEntity": 1000
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## Development
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
npm install
|
|
392
|
+
npm run build
|
|
393
|
+
npm test
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
## Links
|
|
399
|
+
|
|
400
|
+
- **GitHub:** https://github.com/statecli/mcp-server
|
|
401
|
+
- **NPM:** https://www.npmjs.com/package/statecli-mcp-server
|
|
402
|
+
- **Examples:** https://github.com/statecli/examples
|
|
403
|
+
- **Issues:** https://github.com/statecli/mcp-server/issues
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## License
|
|
408
|
+
|
|
409
|
+
MIT - Free for all use including commercial AI agents
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## Keywords
|
|
414
|
+
|
|
415
|
+
state-management, mcp-server, ai-agent-tools, debugging, replay, undo, rollback, agent-memory, self-debugging, autonomous-agents, model-context-protocol, time-travel-debugging, checkpoint, agent-introspection, state-tracking, langchain-tools, autogpt-plugins, crewai-tools
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const commander_1 = require("commander");
|
|
38
|
+
const statecli_1 = require("./statecli");
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
function loadConfig() {
|
|
42
|
+
const configPaths = [
|
|
43
|
+
path.join(process.cwd(), 'statecli.config.json'),
|
|
44
|
+
path.join(process.cwd(), '.statecli', 'config.json'),
|
|
45
|
+
path.join(process.env.HOME || process.env.USERPROFILE || '', '.statecli', 'config.json')
|
|
46
|
+
];
|
|
47
|
+
for (const configPath of configPaths) {
|
|
48
|
+
try {
|
|
49
|
+
if (fs.existsSync(configPath)) {
|
|
50
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
51
|
+
return JSON.parse(content);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Continue to next config path
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
const config = loadConfig();
|
|
61
|
+
const statecli = new statecli_1.StateCLI(config);
|
|
62
|
+
const program = new commander_1.Command();
|
|
63
|
+
program
|
|
64
|
+
.name('statecli')
|
|
65
|
+
.description('State Replay & Self-Debugging CLI for AI Agents')
|
|
66
|
+
.version('1.0.0');
|
|
67
|
+
program
|
|
68
|
+
.command('replay <entity>')
|
|
69
|
+
.description('Replay state changes for an entity')
|
|
70
|
+
.option('-a, --actor <actor>', 'Filter by actor')
|
|
71
|
+
.action((entity, options) => {
|
|
72
|
+
const result = statecli.replay(entity, { actor: options.actor });
|
|
73
|
+
console.log(JSON.stringify(result, null, 2));
|
|
74
|
+
statecli.close();
|
|
75
|
+
});
|
|
76
|
+
program
|
|
77
|
+
.command('undo <entity>')
|
|
78
|
+
.description('Undo state changes for an entity')
|
|
79
|
+
.option('-s, --steps <steps>', 'Number of steps to undo', '1')
|
|
80
|
+
.action((entity, options) => {
|
|
81
|
+
const result = statecli.undo(entity, parseInt(options.steps, 10));
|
|
82
|
+
console.log(JSON.stringify(result, null, 2));
|
|
83
|
+
statecli.close();
|
|
84
|
+
});
|
|
85
|
+
program
|
|
86
|
+
.command('checkpoint <entity> <name>')
|
|
87
|
+
.description('Create a named checkpoint for an entity')
|
|
88
|
+
.action((entity, name) => {
|
|
89
|
+
const result = statecli.checkpoint(entity, name);
|
|
90
|
+
console.log(JSON.stringify(result, null, 2));
|
|
91
|
+
statecli.close();
|
|
92
|
+
});
|
|
93
|
+
program
|
|
94
|
+
.command('restore <entity> <name>')
|
|
95
|
+
.description('Restore to a named checkpoint')
|
|
96
|
+
.action((entity, name) => {
|
|
97
|
+
const result = statecli.restoreCheckpoint(entity, name);
|
|
98
|
+
console.log(JSON.stringify(result, null, 2));
|
|
99
|
+
statecli.close();
|
|
100
|
+
});
|
|
101
|
+
program
|
|
102
|
+
.command('log <entity>')
|
|
103
|
+
.description('View state change history for an entity')
|
|
104
|
+
.option('-s, --since <since>', 'Time filter (e.g., "1h ago", "24h ago")')
|
|
105
|
+
.option('-a, --actor <actor>', 'Filter by actor')
|
|
106
|
+
.option('-l, --limit <limit>', 'Maximum number of entries')
|
|
107
|
+
.action((entity, options) => {
|
|
108
|
+
const result = statecli.log(entity, {
|
|
109
|
+
since: options.since,
|
|
110
|
+
actor: options.actor,
|
|
111
|
+
limit: options.limit ? parseInt(options.limit, 10) : undefined
|
|
112
|
+
});
|
|
113
|
+
console.log(JSON.stringify(result, null, 2));
|
|
114
|
+
statecli.close();
|
|
115
|
+
});
|
|
116
|
+
program
|
|
117
|
+
.command('track <entityType> <entityId>')
|
|
118
|
+
.description('Track a state change')
|
|
119
|
+
.requiredOption('-d, --data <json>', 'State data as JSON string')
|
|
120
|
+
.option('-a, --actor <actor>', 'Actor making the change', 'cli')
|
|
121
|
+
.action((entityType, entityId, options) => {
|
|
122
|
+
try {
|
|
123
|
+
const state = JSON.parse(options.data);
|
|
124
|
+
const result = statecli.track(entityType, entityId, state, options.actor);
|
|
125
|
+
console.log(JSON.stringify(result, null, 2));
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('Error: Invalid JSON data');
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
statecli.close();
|
|
132
|
+
});
|
|
133
|
+
program
|
|
134
|
+
.command('state <entity>')
|
|
135
|
+
.description('Get current state of an entity')
|
|
136
|
+
.action((entity) => {
|
|
137
|
+
const state = statecli.getCurrentState(entity);
|
|
138
|
+
if (state) {
|
|
139
|
+
console.log(JSON.stringify({ entity, state }, null, 2));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
console.log(JSON.stringify({ entity, state: null, message: 'No state found' }, null, 2));
|
|
143
|
+
}
|
|
144
|
+
statecli.close();
|
|
145
|
+
});
|
|
146
|
+
program
|
|
147
|
+
.command('list')
|
|
148
|
+
.description('List all tracked entities')
|
|
149
|
+
.action(() => {
|
|
150
|
+
const entities = statecli.listEntities();
|
|
151
|
+
console.log(JSON.stringify({ entities, count: entities.length }, null, 2));
|
|
152
|
+
statecli.close();
|
|
153
|
+
});
|
|
154
|
+
program
|
|
155
|
+
.command('serve')
|
|
156
|
+
.description('Start the MCP server')
|
|
157
|
+
.action(async () => {
|
|
158
|
+
const { StateCLIMCPServer } = await Promise.resolve().then(() => __importStar(require('./mcp-server')));
|
|
159
|
+
const server = new StateCLIMCPServer(config);
|
|
160
|
+
process.on('SIGINT', () => {
|
|
161
|
+
server.close();
|
|
162
|
+
process.exit(0);
|
|
163
|
+
});
|
|
164
|
+
process.on('SIGTERM', () => {
|
|
165
|
+
server.close();
|
|
166
|
+
process.exit(0);
|
|
167
|
+
});
|
|
168
|
+
await server.run();
|
|
169
|
+
});
|
|
170
|
+
program
|
|
171
|
+
.command('init')
|
|
172
|
+
.description('Initialize StateCLI configuration')
|
|
173
|
+
.action(() => {
|
|
174
|
+
const configDir = path.join(process.cwd(), '.statecli');
|
|
175
|
+
const configFile = path.join(configDir, 'config.json');
|
|
176
|
+
if (!fs.existsSync(configDir)) {
|
|
177
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
178
|
+
}
|
|
179
|
+
if (fs.existsSync(configFile)) {
|
|
180
|
+
console.log('Configuration already exists at', configFile);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const defaultConfig = {
|
|
184
|
+
storage: {
|
|
185
|
+
type: 'local',
|
|
186
|
+
path: '.statecli/state.db'
|
|
187
|
+
},
|
|
188
|
+
autoTrack: {
|
|
189
|
+
enabled: true,
|
|
190
|
+
patterns: ['*']
|
|
191
|
+
},
|
|
192
|
+
retention: {
|
|
193
|
+
days: 30,
|
|
194
|
+
maxChangesPerEntity: 1000
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
fs.writeFileSync(configFile, JSON.stringify(defaultConfig, null, 2));
|
|
198
|
+
console.log('Created configuration at', configFile);
|
|
199
|
+
}
|
|
200
|
+
statecli.close();
|
|
201
|
+
});
|
|
202
|
+
program.parse();
|
|
203
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,yCAAsC;AAEtC,u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