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/dist/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
37
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.StateCLIMCPServer = exports.StateCLI = void 0;
|
|
41
|
+
const mcp_server_1 = require("./mcp-server");
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
function loadConfig() {
|
|
45
|
+
const configPaths = [
|
|
46
|
+
path.join(process.cwd(), 'statecli.config.json'),
|
|
47
|
+
path.join(process.cwd(), '.statecli', 'config.json'),
|
|
48
|
+
path.join(process.env.HOME || process.env.USERPROFILE || '', '.statecli', 'config.json')
|
|
49
|
+
];
|
|
50
|
+
for (const configPath of configPaths) {
|
|
51
|
+
try {
|
|
52
|
+
if (fs.existsSync(configPath)) {
|
|
53
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
54
|
+
return JSON.parse(content);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Continue to next config path
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
async function main() {
|
|
64
|
+
const config = loadConfig();
|
|
65
|
+
const server = new mcp_server_1.StateCLIMCPServer(config);
|
|
66
|
+
process.on('SIGINT', () => {
|
|
67
|
+
server.close();
|
|
68
|
+
process.exit(0);
|
|
69
|
+
});
|
|
70
|
+
process.on('SIGTERM', () => {
|
|
71
|
+
server.close();
|
|
72
|
+
process.exit(0);
|
|
73
|
+
});
|
|
74
|
+
await server.run();
|
|
75
|
+
}
|
|
76
|
+
main().catch((error) => {
|
|
77
|
+
console.error('Failed to start StateCLI MCP Server:', error);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
});
|
|
80
|
+
var statecli_1 = require("./statecli");
|
|
81
|
+
Object.defineProperty(exports, "StateCLI", { enumerable: true, get: function () { return statecli_1.StateCLI; } });
|
|
82
|
+
var mcp_server_2 = require("./mcp-server");
|
|
83
|
+
Object.defineProperty(exports, "StateCLIMCPServer", { enumerable: true, get: function () { return mcp_server_2.StateCLIMCPServer; } });
|
|
84
|
+
__exportStar(require("./types"), exports);
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAAiD;AAEjD,uCAAyB;AACzB,2CAA6B;AAE7B,SAAS,UAAU;IACjB,MAAM,WAAW,GAAG;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,sBAAsB,CAAC;QAChD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,aAAa,CAAC;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,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,2CAAiD;AAAxC,+GAAA,iBAAiB,OAAA;AAC1B,0CAAwB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StateCLIConfig } from './types';
|
|
2
|
+
export declare class StateCLIMCPServer {
|
|
3
|
+
private server;
|
|
4
|
+
private statecli;
|
|
5
|
+
constructor(config?: Partial<StateCLIConfig>);
|
|
6
|
+
private setupHandlers;
|
|
7
|
+
private handleReplay;
|
|
8
|
+
private handleUndo;
|
|
9
|
+
private handleCheckpoint;
|
|
10
|
+
private handleLog;
|
|
11
|
+
private handleTrack;
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=mcp-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AA2GzC,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAW;gBAEf,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAkB5C,OAAO,CAAC,aAAa;IA8CrB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,UAAU;IAgBlB,OAAO,CAAC,gBAAgB;IAiBxB,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,WAAW;IA0Bb,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAM1B,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateCLIMCPServer = void 0;
|
|
4
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
5
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
7
|
+
const statecli_1 = require("./statecli");
|
|
8
|
+
const TOOLS = [
|
|
9
|
+
{
|
|
10
|
+
name: 'statecli_replay',
|
|
11
|
+
description: 'Replay state changes for an entity. Shows step-by-step what happened. Use when debugging, understanding past behavior, or finding errors.',
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
entity: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
description: 'Entity identifier (e.g., "order:7421", "user:123", "task:abc")'
|
|
18
|
+
},
|
|
19
|
+
actor: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Optional: filter by actor (e.g., "ai-agent", "system")'
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
required: ['entity']
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'statecli_undo',
|
|
29
|
+
description: 'Undo state changes. Rollback when something went wrong. Use when you made a mistake, need to retry, or want to revert.',
|
|
30
|
+
inputSchema: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
entity: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
description: 'Entity identifier (e.g., "order:7421")'
|
|
36
|
+
},
|
|
37
|
+
steps: {
|
|
38
|
+
type: 'number',
|
|
39
|
+
description: 'Optional: how many steps to undo (default: 1)'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
required: ['entity']
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'statecli_checkpoint',
|
|
47
|
+
description: 'Create named checkpoint before making changes. Use when about to do something risky or want a rollback point.',
|
|
48
|
+
inputSchema: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
entity: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
description: 'Entity identifier (e.g., "order:7421")'
|
|
54
|
+
},
|
|
55
|
+
name: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
description: 'Checkpoint name (e.g., "before-refund", "stable-state")'
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
required: ['entity', 'name']
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'statecli_log',
|
|
65
|
+
description: 'View state change history for an entity. Use when you need to see past actions, audit trail, or understand behavior.',
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
entity: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
description: 'Entity identifier or pattern (e.g., "order:7421", "order:*")'
|
|
72
|
+
},
|
|
73
|
+
since: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
description: 'Optional: time filter (e.g., "1h ago", "24h ago", "7d ago")'
|
|
76
|
+
},
|
|
77
|
+
actor: {
|
|
78
|
+
type: 'string',
|
|
79
|
+
description: 'Optional: filter by actor'
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
required: ['entity']
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'statecli_track',
|
|
87
|
+
description: 'Explicitly track a state change. Use when making important state modifications.',
|
|
88
|
+
inputSchema: {
|
|
89
|
+
type: 'object',
|
|
90
|
+
properties: {
|
|
91
|
+
entity_type: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
description: 'Type of entity (e.g., "order", "user", "task")'
|
|
94
|
+
},
|
|
95
|
+
entity_id: {
|
|
96
|
+
type: 'string',
|
|
97
|
+
description: 'Unique identifier for the entity'
|
|
98
|
+
},
|
|
99
|
+
state: {
|
|
100
|
+
type: 'object',
|
|
101
|
+
description: 'The state to track (any JSON object)'
|
|
102
|
+
},
|
|
103
|
+
actor: {
|
|
104
|
+
type: 'string',
|
|
105
|
+
description: 'Optional: who is making this change (default: "ai-agent")'
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
required: ['entity_type', 'entity_id', 'state']
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
];
|
|
112
|
+
class StateCLIMCPServer {
|
|
113
|
+
server;
|
|
114
|
+
statecli;
|
|
115
|
+
constructor(config) {
|
|
116
|
+
this.statecli = new statecli_1.StateCLI(config);
|
|
117
|
+
this.server = new index_js_1.Server({
|
|
118
|
+
name: 'statecli',
|
|
119
|
+
version: '1.0.0'
|
|
120
|
+
}, {
|
|
121
|
+
capabilities: {
|
|
122
|
+
tools: {}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
this.setupHandlers();
|
|
126
|
+
}
|
|
127
|
+
setupHandlers() {
|
|
128
|
+
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
129
|
+
return { tools: TOOLS };
|
|
130
|
+
});
|
|
131
|
+
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
132
|
+
const { name, arguments: args } = request.params;
|
|
133
|
+
try {
|
|
134
|
+
switch (name) {
|
|
135
|
+
case 'statecli_replay':
|
|
136
|
+
return this.handleReplay(args);
|
|
137
|
+
case 'statecli_undo':
|
|
138
|
+
return this.handleUndo(args);
|
|
139
|
+
case 'statecli_checkpoint':
|
|
140
|
+
return this.handleCheckpoint(args);
|
|
141
|
+
case 'statecli_log':
|
|
142
|
+
return this.handleLog(args);
|
|
143
|
+
case 'statecli_track':
|
|
144
|
+
return this.handleTrack(args);
|
|
145
|
+
default:
|
|
146
|
+
return {
|
|
147
|
+
content: [{ type: 'text', text: `Unknown tool: ${name}` }],
|
|
148
|
+
isError: true
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
154
|
+
return {
|
|
155
|
+
content: [{ type: 'text', text: `Error: ${message}` }],
|
|
156
|
+
isError: true
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
handleReplay(args) {
|
|
162
|
+
const result = this.statecli.replay(args.entity, { actor: args.actor });
|
|
163
|
+
return {
|
|
164
|
+
content: [{
|
|
165
|
+
type: 'text',
|
|
166
|
+
text: JSON.stringify({
|
|
167
|
+
entity: result.entity,
|
|
168
|
+
changes: result.changes,
|
|
169
|
+
summary: result.summary,
|
|
170
|
+
suggested_next_actions: result.suggestedNextActions
|
|
171
|
+
}, null, 2)
|
|
172
|
+
}]
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
handleUndo(args) {
|
|
176
|
+
const result = this.statecli.undo(args.entity, args.steps || 1);
|
|
177
|
+
return {
|
|
178
|
+
content: [{
|
|
179
|
+
type: 'text',
|
|
180
|
+
text: JSON.stringify({
|
|
181
|
+
entity: result.entity,
|
|
182
|
+
steps_undone: result.stepsUndone,
|
|
183
|
+
restored_state: result.restoredState,
|
|
184
|
+
summary: result.summary
|
|
185
|
+
}, null, 2)
|
|
186
|
+
}]
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
handleCheckpoint(args) {
|
|
190
|
+
const result = this.statecli.checkpoint(args.entity, args.name);
|
|
191
|
+
return {
|
|
192
|
+
content: [{
|
|
193
|
+
type: 'text',
|
|
194
|
+
text: JSON.stringify({
|
|
195
|
+
id: result.id,
|
|
196
|
+
entity: result.entity,
|
|
197
|
+
name: result.name,
|
|
198
|
+
timestamp: result.timestamp,
|
|
199
|
+
summary: result.summary
|
|
200
|
+
}, null, 2)
|
|
201
|
+
}]
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
handleLog(args) {
|
|
205
|
+
const result = this.statecli.log(args.entity, {
|
|
206
|
+
since: args.since,
|
|
207
|
+
actor: args.actor
|
|
208
|
+
});
|
|
209
|
+
return {
|
|
210
|
+
content: [{
|
|
211
|
+
type: 'text',
|
|
212
|
+
text: JSON.stringify({
|
|
213
|
+
entity: result.entity,
|
|
214
|
+
changes: result.changes.map(c => ({
|
|
215
|
+
id: c.id,
|
|
216
|
+
timestamp: c.timestamp,
|
|
217
|
+
before: c.before,
|
|
218
|
+
after: c.after,
|
|
219
|
+
actor: c.actor
|
|
220
|
+
})),
|
|
221
|
+
summary: result.summary
|
|
222
|
+
}, null, 2)
|
|
223
|
+
}]
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
handleTrack(args) {
|
|
227
|
+
const result = this.statecli.track(args.entity_type, args.entity_id, args.state, args.actor || 'ai-agent');
|
|
228
|
+
return {
|
|
229
|
+
content: [{
|
|
230
|
+
type: 'text',
|
|
231
|
+
text: JSON.stringify({
|
|
232
|
+
id: result.id,
|
|
233
|
+
entity: result.entity,
|
|
234
|
+
timestamp: result.timestamp,
|
|
235
|
+
summary: result.summary
|
|
236
|
+
}, null, 2)
|
|
237
|
+
}]
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
async run() {
|
|
241
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
242
|
+
await this.server.connect(transport);
|
|
243
|
+
console.error('StateCLI MCP Server running on stdio');
|
|
244
|
+
}
|
|
245
|
+
close() {
|
|
246
|
+
this.statecli.close();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.StateCLIMCPServer = StateCLIMCPServer;
|
|
250
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AACnE,wEAAiF;AACjF,iEAI4C;AAC5C,yCAAsC;AAGtC,MAAM,KAAK,GAAW;IACpB;QACE,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,2IAA2I;QACxJ,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,gEAAgE;iBAC9E;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,WAAW,EAA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M,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACrC,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACxD,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF;AAhLD,8CAgLC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StateCLIConfig, ReplayResult, UndoResult, CheckpointResult, LogResult, TrackResult } from './types';
|
|
2
|
+
export declare class StateCLI {
|
|
3
|
+
private storage;
|
|
4
|
+
constructor(config?: Partial<StateCLIConfig>);
|
|
5
|
+
replay(entity: string, options?: {
|
|
6
|
+
actor?: string;
|
|
7
|
+
}): ReplayResult;
|
|
8
|
+
undo(entity: string, steps?: number): UndoResult;
|
|
9
|
+
checkpoint(entity: string, name: string): CheckpointResult;
|
|
10
|
+
restoreCheckpoint(entity: string, name: string): {
|
|
11
|
+
success: boolean;
|
|
12
|
+
summary: string;
|
|
13
|
+
};
|
|
14
|
+
log(entity: string, options?: {
|
|
15
|
+
since?: string;
|
|
16
|
+
actor?: string;
|
|
17
|
+
limit?: number;
|
|
18
|
+
}): LogResult;
|
|
19
|
+
track(entityType: string, entityId: string, state: Record<string, unknown>, actor?: string): TrackResult;
|
|
20
|
+
getCurrentState(entity: string): Record<string, unknown> | null;
|
|
21
|
+
listEntities(): string[];
|
|
22
|
+
close(): void;
|
|
23
|
+
}
|
|
24
|
+
export declare function getStateCLI(config?: Partial<StateCLIConfig>): StateCLI;
|
|
25
|
+
export declare function resetStateCLI(): void;
|
|
26
|
+
//# sourceMappingURL=statecli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statecli.d.ts","sourceRoot":"","sources":["../src/statecli.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,WAAW,EAEZ,MAAM,SAAS,CAAC;AAEjB,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAe;gBAElB,MAAM,GAAE,OAAO,CAAC,cAAc,CAAM;IAIhD,MAAM,CACJ,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC/B,YAAY;IAgCf,IAAI,CACF,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAAU,GAChB,UAAU;IAab,UAAU,CACR,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,gBAAgB;IAYnB,iBAAiB,CACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAgBxC,GAAG,CACD,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC/D,SAAS;IAgBZ,KAAK,CACH,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,GAAE,MAAiB,GACvB,WAAW;IAWd,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI/D,YAAY,IAAI,MAAM,EAAE;IAIxB,KAAK,IAAI,IAAI;CAGd;AAID,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,QAAQ,CAKtE;AAED,wBAAgB,aAAa,IAAI,IAAI,CAKpC"}
|
package/dist/statecli.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateCLI = void 0;
|
|
4
|
+
exports.getStateCLI = getStateCLI;
|
|
5
|
+
exports.resetStateCLI = resetStateCLI;
|
|
6
|
+
const storage_1 = require("./storage");
|
|
7
|
+
class StateCLI {
|
|
8
|
+
storage;
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
this.storage = new storage_1.StateStorage(config);
|
|
11
|
+
}
|
|
12
|
+
replay(entity, options = {}) {
|
|
13
|
+
const changes = this.storage.getChanges(entity, { actor: options.actor });
|
|
14
|
+
const formattedChanges = changes.map((change, index) => ({
|
|
15
|
+
timestamp: change.timestamp,
|
|
16
|
+
step: index + 1,
|
|
17
|
+
before: change.before,
|
|
18
|
+
after: change.after,
|
|
19
|
+
actor: change.actor,
|
|
20
|
+
checkpointName: change.checkpointName
|
|
21
|
+
}));
|
|
22
|
+
const suggestedNextActions = [];
|
|
23
|
+
if (changes.length === 0) {
|
|
24
|
+
suggestedNextActions.push('track initial state for this entity');
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
suggestedNextActions.push('investigate latest change');
|
|
28
|
+
if (changes.length > 1) {
|
|
29
|
+
suggestedNextActions.push('compare first and last state');
|
|
30
|
+
}
|
|
31
|
+
suggestedNextActions.push('create checkpoint if state is stable');
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
entity,
|
|
35
|
+
changes: formattedChanges,
|
|
36
|
+
summary: `${changes.length} state change${changes.length !== 1 ? 's' : ''} found`,
|
|
37
|
+
suggestedNextActions
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
undo(entity, steps = 1) {
|
|
41
|
+
const { undone, restoredState } = this.storage.undo(entity, steps);
|
|
42
|
+
return {
|
|
43
|
+
entity,
|
|
44
|
+
stepsUndone: undone.length,
|
|
45
|
+
restoredState,
|
|
46
|
+
summary: undone.length > 0
|
|
47
|
+
? `Undid ${undone.length} step${undone.length !== 1 ? 's' : ''}. State restored.`
|
|
48
|
+
: 'No changes to undo.'
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
checkpoint(entity, name) {
|
|
52
|
+
const checkpoint = this.storage.createCheckpoint(entity, name);
|
|
53
|
+
return {
|
|
54
|
+
id: checkpoint.id,
|
|
55
|
+
entity: checkpoint.entity,
|
|
56
|
+
name: checkpoint.name,
|
|
57
|
+
timestamp: checkpoint.timestamp,
|
|
58
|
+
summary: `Checkpoint "${name}" created for ${entity}`
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
restoreCheckpoint(entity, name) {
|
|
62
|
+
const { restored, checkpoint } = this.storage.restoreCheckpoint(entity, name);
|
|
63
|
+
if (restored && checkpoint) {
|
|
64
|
+
return {
|
|
65
|
+
success: true,
|
|
66
|
+
summary: `Restored to checkpoint "${name}" from ${checkpoint.timestamp}`
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
summary: `Checkpoint "${name}" not found for ${entity}`
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
log(entity, options = {}) {
|
|
75
|
+
let changes;
|
|
76
|
+
if (entity.includes('*')) {
|
|
77
|
+
changes = this.storage.getChangesByPattern(entity, options);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
changes = this.storage.getChanges(entity, options);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
entity,
|
|
84
|
+
changes,
|
|
85
|
+
summary: `${changes.length} change${changes.length !== 1 ? 's' : ''} in log`
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
track(entityType, entityId, state, actor = 'system') {
|
|
89
|
+
const change = this.storage.track(entityType, entityId, state, actor);
|
|
90
|
+
return {
|
|
91
|
+
id: change.id,
|
|
92
|
+
entity: change.entity,
|
|
93
|
+
timestamp: change.timestamp,
|
|
94
|
+
summary: `State tracked for ${change.entity}`
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
getCurrentState(entity) {
|
|
98
|
+
return this.storage.getCurrentState(entity);
|
|
99
|
+
}
|
|
100
|
+
listEntities() {
|
|
101
|
+
return this.storage.listEntities();
|
|
102
|
+
}
|
|
103
|
+
close() {
|
|
104
|
+
this.storage.close();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.StateCLI = StateCLI;
|
|
108
|
+
let instance = null;
|
|
109
|
+
function getStateCLI(config) {
|
|
110
|
+
if (!instance) {
|
|
111
|
+
instance = new StateCLI(config);
|
|
112
|
+
}
|
|
113
|
+
return instance;
|
|
114
|
+
}
|
|
115
|
+
function resetStateCLI() {
|
|
116
|
+
if (instance) {
|
|
117
|
+
instance.close();
|
|
118
|
+
instance = null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=statecli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statecli.js","sourceRoot":"","sources":["../src/statecli.ts"],"names":[],"mappings":";;;AAyJA,kCAKC;AAED,sCAKC;AArKD,uCAAyC;AAWzC,MAAa,QAAQ;IACX,OAAO,CAAe;IAE9B,YAAY,SAAkC,EAAE;QAC9C,IAAI,CAAC,OAAO,GAAG,IAAI,sBAAY,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,CACJ,MAAc,EACd,UAA8B,EAAE;QAEhC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAE1E,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YACvD,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,IAAI,EAAE,KAAK,GAAG,CAAC;YACf,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,cAAc,EAAE,MAAM,CAAC,cAAc;SACtC,CAAC,CAAC,CAAC;QAEJ,MAAM,oBAAoB,GAA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MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAEtE,OAAO;YACL,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,OAAO,EAAE,qBAAqB,MAAM,CAAC,MAAM,EAAE;SAC9C,CAAC;IACJ,CAAC;IAED,eAAe,CAAC,MAAc;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;IACrC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF;AA1ID,4BA0IC;AAED,IAAI,QAAQ,GAAoB,IAAI,CAAC;AAErC,SAAgB,WAAW,CAAC,MAAgC;IAC1D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAgB,aAAa;IAC3B,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,CAAC,KAAK,EAAE,CAAC;QACjB,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StateChange, Checkpoint, StateCLIConfig } from './types';
|
|
2
|
+
export declare class StateStorage {
|
|
3
|
+
private db;
|
|
4
|
+
private config;
|
|
5
|
+
constructor(config?: Partial<StateCLIConfig>);
|
|
6
|
+
private initializeSchema;
|
|
7
|
+
track(entityType: string, entityId: string, state: Record<string, unknown>, actor?: string, checkpointName?: string): StateChange;
|
|
8
|
+
private getLastChange;
|
|
9
|
+
private rowToStateChange;
|
|
10
|
+
getChanges(entity: string, options?: {
|
|
11
|
+
actor?: string;
|
|
12
|
+
since?: string;
|
|
13
|
+
limit?: number;
|
|
14
|
+
}): StateChange[];
|
|
15
|
+
getChangesByPattern(pattern: string, options?: {
|
|
16
|
+
actor?: string;
|
|
17
|
+
since?: string;
|
|
18
|
+
limit?: number;
|
|
19
|
+
}): StateChange[];
|
|
20
|
+
private parseSince;
|
|
21
|
+
undo(entity: string, steps?: number): {
|
|
22
|
+
undone: StateChange[];
|
|
23
|
+
restoredState: Record<string, unknown> | null;
|
|
24
|
+
};
|
|
25
|
+
createCheckpoint(entity: string, name: string): Checkpoint;
|
|
26
|
+
getCheckpoint(entity: string, name: string): Checkpoint | null;
|
|
27
|
+
restoreCheckpoint(entity: string, name: string): {
|
|
28
|
+
restored: boolean;
|
|
29
|
+
checkpoint: Checkpoint | null;
|
|
30
|
+
};
|
|
31
|
+
listEntities(): string[];
|
|
32
|
+
private enforceRetention;
|
|
33
|
+
getCurrentState(entity: string): Record<string, unknown> | null;
|
|
34
|
+
close(): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,EACX,UAAU,EACV,cAAc,EAEf,MAAM,SAAS,CAAC;AAEjB,qBAAa,YAAY;IACvB,OAAO,CAAC,EAAE,CAAoB;IAC9B,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,GAAE,OAAO,CAAC,cAAc,CAAM;IAchD,OAAO,CAAC,gBAAgB;IAkCxB,KAAK,CACH,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,GAAE,MAAiB,EACxB,cAAc,CAAC,EAAE,MAAM,GACtB,WAAW;IAwCd,OAAO,CAAC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