statecli-mcp-server 0.1.2 → 0.2.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.
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ /**
3
+ * Error Recovery - Integration with error detection
4
+ *
5
+ * Automatically detects errors and suggests rollback actions
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ErrorRecovery = void 0;
9
+ class ErrorRecovery {
10
+ statecli;
11
+ errorHistory = [];
12
+ constructor(statecli) {
13
+ this.statecli = statecli;
14
+ }
15
+ /**
16
+ * Analyze an error and suggest recovery actions
17
+ */
18
+ analyzeError(error, affectedEntities = []) {
19
+ const errorContext = this.createErrorContext(error, affectedEntities);
20
+ this.errorHistory.push(errorContext);
21
+ // Get recent changes for affected entities
22
+ const recentChanges = [];
23
+ for (const entity of affectedEntities) {
24
+ const replay = this.statecli.replay(entity);
25
+ recentChanges.push(...replay.changes.slice(-5)); // Last 5 changes per entity
26
+ }
27
+ // Generate recovery suggestions
28
+ const suggestions = this.generateSuggestions(errorContext, recentChanges);
29
+ // Create summary
30
+ const summary = this.createSummary(errorContext, recentChanges, suggestions);
31
+ return {
32
+ error: errorContext,
33
+ recentChanges,
34
+ suggestions,
35
+ summary
36
+ };
37
+ }
38
+ /**
39
+ * Auto-recover from an error using the best suggestion
40
+ */
41
+ autoRecover(analysis) {
42
+ const bestSuggestion = analysis.suggestions.find(s => s.confidence === 'high');
43
+ if (!bestSuggestion) {
44
+ return {
45
+ success: false,
46
+ action: 'none',
47
+ result: 'No high-confidence recovery suggestion available'
48
+ };
49
+ }
50
+ try {
51
+ switch (bestSuggestion.action) {
52
+ case 'undo':
53
+ const undoResult = this.statecli.undo(bestSuggestion.entity, bestSuggestion.steps || 1);
54
+ return {
55
+ success: true,
56
+ action: 'undo',
57
+ result: undoResult
58
+ };
59
+ case 'restore_checkpoint':
60
+ if (bestSuggestion.checkpointName) {
61
+ const restoreResult = this.statecli.restoreCheckpoint(bestSuggestion.entity, bestSuggestion.checkpointName);
62
+ return {
63
+ success: true,
64
+ action: 'restore_checkpoint',
65
+ result: restoreResult
66
+ };
67
+ }
68
+ break;
69
+ case 'replay_analyze':
70
+ const replay = this.statecli.replay(bestSuggestion.entity);
71
+ return {
72
+ success: true,
73
+ action: 'replay_analyze',
74
+ result: replay
75
+ };
76
+ }
77
+ }
78
+ catch (recoveryError) {
79
+ return {
80
+ success: false,
81
+ action: bestSuggestion.action,
82
+ result: `Recovery failed: ${recoveryError}`
83
+ };
84
+ }
85
+ return {
86
+ success: false,
87
+ action: 'manual',
88
+ result: 'Manual intervention required'
89
+ };
90
+ }
91
+ /**
92
+ * Create checkpoint before risky operation
93
+ */
94
+ safeExecute(entityId, operation, operationName = 'risky-operation') {
95
+ // Create checkpoint before operation
96
+ const checkpointName = `before-${operationName}-${Date.now()}`;
97
+ this.statecli.checkpoint(entityId, checkpointName);
98
+ try {
99
+ const result = operation();
100
+ return { success: true, result };
101
+ }
102
+ catch (error) {
103
+ // Analyze and attempt recovery
104
+ const analysis = this.analyzeError(error instanceof Error ? error : new Error(String(error)), [entityId]);
105
+ // Try to restore checkpoint
106
+ try {
107
+ this.statecli.restoreCheckpoint(entityId, checkpointName);
108
+ return {
109
+ success: false,
110
+ error: error instanceof Error ? error : new Error(String(error)),
111
+ recovered: true
112
+ };
113
+ }
114
+ catch (restoreError) {
115
+ return {
116
+ success: false,
117
+ error: error instanceof Error ? error : new Error(String(error)),
118
+ recovered: false
119
+ };
120
+ }
121
+ }
122
+ }
123
+ /**
124
+ * Get error history
125
+ */
126
+ getErrorHistory() {
127
+ return [...this.errorHistory];
128
+ }
129
+ /**
130
+ * Clear error history
131
+ */
132
+ clearErrorHistory() {
133
+ this.errorHistory = [];
134
+ }
135
+ createErrorContext(error, affectedEntities) {
136
+ const isError = error instanceof Error;
137
+ return {
138
+ errorType: isError ? error.name : 'Unknown',
139
+ errorMessage: isError ? error.message : String(error),
140
+ stackTrace: isError ? error.stack : undefined,
141
+ affectedEntities,
142
+ timestamp: new Date().toISOString()
143
+ };
144
+ }
145
+ generateSuggestions(errorContext, recentChanges) {
146
+ const suggestions = [];
147
+ // If there are recent changes, suggest undo
148
+ if (recentChanges.length > 0) {
149
+ const mostRecentEntity = recentChanges[recentChanges.length - 1].entity || 'unknown';
150
+ suggestions.push({
151
+ action: 'undo',
152
+ entity: mostRecentEntity,
153
+ steps: 1,
154
+ reason: 'Undo the most recent change that may have caused the error',
155
+ confidence: 'medium'
156
+ });
157
+ // If multiple changes, suggest undoing more
158
+ if (recentChanges.length >= 3) {
159
+ suggestions.push({
160
+ action: 'undo',
161
+ entity: mostRecentEntity || 'unknown',
162
+ steps: 3,
163
+ reason: 'Undo the last 3 changes to restore to a known good state',
164
+ confidence: 'low'
165
+ });
166
+ }
167
+ }
168
+ // For each affected entity, suggest replay for analysis
169
+ for (const entity of errorContext.affectedEntities) {
170
+ suggestions.push({
171
+ action: 'replay_analyze',
172
+ entity,
173
+ reason: `Analyze changes to ${entity} to understand what went wrong`,
174
+ confidence: 'high'
175
+ });
176
+ }
177
+ // Check for checkpoints
178
+ for (const entity of errorContext.affectedEntities) {
179
+ // Note: In a real implementation, we'd query for available checkpoints
180
+ suggestions.push({
181
+ action: 'restore_checkpoint',
182
+ entity,
183
+ checkpointName: 'latest',
184
+ reason: 'Restore to the latest checkpoint for this entity',
185
+ confidence: 'medium'
186
+ });
187
+ }
188
+ return suggestions;
189
+ }
190
+ createSummary(errorContext, recentChanges, suggestions) {
191
+ const lines = [];
192
+ lines.push(`Error Analysis Summary`);
193
+ lines.push(`======================`);
194
+ lines.push(`Error: ${errorContext.errorType} - ${errorContext.errorMessage}`);
195
+ lines.push(`Time: ${errorContext.timestamp}`);
196
+ lines.push(`Affected entities: ${errorContext.affectedEntities.join(', ') || 'Unknown'}`);
197
+ lines.push(``);
198
+ lines.push(`Recent changes: ${recentChanges.length}`);
199
+ lines.push(`Recovery suggestions: ${suggestions.length}`);
200
+ const highConfidence = suggestions.filter(s => s.confidence === 'high');
201
+ if (highConfidence.length > 0) {
202
+ lines.push(``);
203
+ lines.push(`Recommended action: ${highConfidence[0].action} on ${highConfidence[0].entity}`);
204
+ lines.push(`Reason: ${highConfidence[0].reason}`);
205
+ }
206
+ return lines.join('\n');
207
+ }
208
+ }
209
+ exports.ErrorRecovery = ErrorRecovery;
210
+ //# sourceMappingURL=error-recovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-recovery.js","sourceRoot":"","sources":["../src/error-recovery.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA6BH,MAAa,aAAa;IAChB,QAAQ,CAAW;IACnB,YAAY,GAAmB,EAAE,CAAC;IAE1C,YAAY,QAAkB;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,YAAY,CACV,KAAqB,EACrB,mBAA6B,EAAE;QAE/B,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;QACtE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAErC,2CAA2C;QAC3C,MAAM,aAAa,GAAmB,EAAE,CAAC;QACzC,KAAK,MAAM,MAAM,IAAI,gBAAgB,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5C,aAAa,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,4BAA4B;QAC/E,CAAC;QAED,gCAAgC;QAChC,MAAM,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAE1E,iBAAiB;QACjB,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;QAE7E,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9E,KAAK,CAAC,IAAI,CAAC,SAAS,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC;QAC9C,KAAK,CAAC,IAAI,CAAC,sBAAsB,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC;QAC1F,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,mBAAmB,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;QACtD,KAAK,CAAC,IAAI,CAAC,yBAAyB,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;QAE1D,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC;QACxE,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,uBAAuB,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YAC7F,KAAK,CAAC,IAAI,CAAC,WAAW,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AA5PD,sCA4PC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * File Tracker - Auto-tracking of file edits
3
+ *
4
+ * Automatically tracks file changes and integrates with StateCLI
5
+ */
6
+ import { StateCLI } from './statecli';
7
+ export interface FileChange {
8
+ filePath: string;
9
+ operation: 'create' | 'modify' | 'delete';
10
+ before: string | null;
11
+ after: string | null;
12
+ diff: string[];
13
+ timestamp: string;
14
+ }
15
+ export interface FileTrackerConfig {
16
+ watchPaths: string[];
17
+ ignorePatterns: string[];
18
+ autoCheckpoint: boolean;
19
+ checkpointThreshold: number;
20
+ }
21
+ export declare class FileTracker {
22
+ private statecli;
23
+ private config;
24
+ private fileHashes;
25
+ private changeCount;
26
+ private watchers;
27
+ constructor(statecli: StateCLI, config?: Partial<FileTrackerConfig>);
28
+ /**
29
+ * Start watching files for changes
30
+ */
31
+ startWatching(): void;
32
+ /**
33
+ * Stop watching files
34
+ */
35
+ stopWatching(): void;
36
+ /**
37
+ * Track a file change manually
38
+ */
39
+ trackFileChange(filePath: string, operation: 'create' | 'modify' | 'delete', beforeContent: string | null, afterContent: string | null, actor?: string): FileChange;
40
+ /**
41
+ * Track a file edit with before/after content
42
+ */
43
+ trackEdit(filePath: string, beforeContent: string, afterContent: string, actor?: string): FileChange;
44
+ /**
45
+ * Track a file creation
46
+ */
47
+ trackCreate(filePath: string, content: string, actor?: string): FileChange;
48
+ /**
49
+ * Track a file deletion
50
+ */
51
+ trackDelete(filePath: string, previousContent: string, actor?: string): FileChange;
52
+ /**
53
+ * Get file change history
54
+ */
55
+ getFileHistory(filePath: string): ReturnType<StateCLI['replay']>;
56
+ /**
57
+ * Compute simple diff between two strings
58
+ */
59
+ private computeDiff;
60
+ /**
61
+ * Create a hash of file content
62
+ */
63
+ private hashContent;
64
+ /**
65
+ * Watch a directory for changes
66
+ */
67
+ private watchDirectory;
68
+ /**
69
+ * Check if a file should be ignored
70
+ */
71
+ private shouldIgnore;
72
+ /**
73
+ * Handle a file system event
74
+ */
75
+ private handleFileEvent;
76
+ /**
77
+ * Create an automatic checkpoint
78
+ */
79
+ private createAutoCheckpoint;
80
+ }
81
+ //# sourceMappingURL=file-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-tracker.d.ts","sourceRoot":"","sources":["../src/file-tracker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,C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EAAE,MAAM,EACvB,KAAK,GAAE,MAAmB,GACzB,UAAU;IAIb;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAIhE;;OAEG;IACH,OAAO,CAAC,WAAW;IAwCnB;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;OAEG;IACH,OAAO,CAAC,YAAY;IAYpB;;OAEG;IACH,OAAO,CAAC,eAAe;IA8BvB;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAK7B"}
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ /**
3
+ * File Tracker - Auto-tracking of file edits
4
+ *
5
+ * Automatically tracks file changes and integrates with StateCLI
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.FileTracker = void 0;
42
+ const fs = __importStar(require("fs"));
43
+ const path = __importStar(require("path"));
44
+ const crypto = __importStar(require("crypto"));
45
+ const DEFAULT_CONFIG = {
46
+ watchPaths: ['.'],
47
+ ignorePatterns: ['node_modules', '.git', 'dist', '*.log', '.statecli'],
48
+ autoCheckpoint: true,
49
+ checkpointThreshold: 10
50
+ };
51
+ class FileTracker {
52
+ statecli;
53
+ config;
54
+ fileHashes = new Map();
55
+ changeCount = 0;
56
+ watchers = [];
57
+ constructor(statecli, config) {
58
+ this.statecli = statecli;
59
+ this.config = { ...DEFAULT_CONFIG, ...config };
60
+ }
61
+ /**
62
+ * Start watching files for changes
63
+ */
64
+ startWatching() {
65
+ for (const watchPath of this.config.watchPaths) {
66
+ this.watchDirectory(watchPath);
67
+ }
68
+ }
69
+ /**
70
+ * Stop watching files
71
+ */
72
+ stopWatching() {
73
+ for (const watcher of this.watchers) {
74
+ watcher.close();
75
+ }
76
+ this.watchers = [];
77
+ }
78
+ /**
79
+ * Track a file change manually
80
+ */
81
+ trackFileChange(filePath, operation, beforeContent, afterContent, actor = 'ai-agent') {
82
+ const diff = this.computeDiff(beforeContent, afterContent);
83
+ const timestamp = new Date().toISOString();
84
+ const change = {
85
+ filePath: path.normalize(filePath),
86
+ operation,
87
+ before: beforeContent,
88
+ after: afterContent,
89
+ diff,
90
+ timestamp
91
+ };
92
+ // Track in StateCLI
93
+ this.statecli.track('file', filePath, {
94
+ operation,
95
+ contentHash: afterContent ? this.hashContent(afterContent) : null,
96
+ lineCount: afterContent ? afterContent.split('\n').length : 0,
97
+ diff: diff.slice(0, 50), // Store first 50 diff lines
98
+ timestamp
99
+ }, actor);
100
+ this.changeCount++;
101
+ // Auto-checkpoint if threshold reached
102
+ if (this.config.autoCheckpoint &&
103
+ this.changeCount >= this.config.checkpointThreshold) {
104
+ this.createAutoCheckpoint();
105
+ }
106
+ return change;
107
+ }
108
+ /**
109
+ * Track a file edit with before/after content
110
+ */
111
+ trackEdit(filePath, beforeContent, afterContent, actor = 'ai-agent') {
112
+ return this.trackFileChange(filePath, 'modify', beforeContent, afterContent, actor);
113
+ }
114
+ /**
115
+ * Track a file creation
116
+ */
117
+ trackCreate(filePath, content, actor = 'ai-agent') {
118
+ return this.trackFileChange(filePath, 'create', null, content, actor);
119
+ }
120
+ /**
121
+ * Track a file deletion
122
+ */
123
+ trackDelete(filePath, previousContent, actor = 'ai-agent') {
124
+ return this.trackFileChange(filePath, 'delete', previousContent, null, actor);
125
+ }
126
+ /**
127
+ * Get file change history
128
+ */
129
+ getFileHistory(filePath) {
130
+ return this.statecli.replay(`file:${path.normalize(filePath)}`);
131
+ }
132
+ /**
133
+ * Compute simple diff between two strings
134
+ */
135
+ computeDiff(before, after) {
136
+ const diff = [];
137
+ if (before === null && after !== null) {
138
+ // New file
139
+ const lines = after.split('\n');
140
+ lines.forEach((line, i) => {
141
+ diff.push(`+${i + 1}: ${line}`);
142
+ });
143
+ }
144
+ else if (before !== null && after === null) {
145
+ // Deleted file
146
+ const lines = before.split('\n');
147
+ lines.forEach((line, i) => {
148
+ diff.push(`-${i + 1}: ${line}`);
149
+ });
150
+ }
151
+ else if (before !== null && after !== null) {
152
+ // Modified file - simple line-by-line diff
153
+ const beforeLines = before.split('\n');
154
+ const afterLines = after.split('\n');
155
+ const maxLines = Math.max(beforeLines.length, afterLines.length);
156
+ for (let i = 0; i < maxLines; i++) {
157
+ const beforeLine = beforeLines[i];
158
+ const afterLine = afterLines[i];
159
+ if (beforeLine !== afterLine) {
160
+ if (beforeLine !== undefined) {
161
+ diff.push(`-${i + 1}: ${beforeLine}`);
162
+ }
163
+ if (afterLine !== undefined) {
164
+ diff.push(`+${i + 1}: ${afterLine}`);
165
+ }
166
+ }
167
+ }
168
+ }
169
+ return diff;
170
+ }
171
+ /**
172
+ * Create a hash of file content
173
+ */
174
+ hashContent(content) {
175
+ return crypto.createHash('md5').update(content).digest('hex');
176
+ }
177
+ /**
178
+ * Watch a directory for changes
179
+ */
180
+ watchDirectory(dirPath) {
181
+ try {
182
+ const watcher = fs.watch(dirPath, { recursive: true }, (eventType, filename) => {
183
+ if (filename && !this.shouldIgnore(filename)) {
184
+ this.handleFileEvent(path.join(dirPath, filename), eventType);
185
+ }
186
+ });
187
+ this.watchers.push(watcher);
188
+ }
189
+ catch (error) {
190
+ console.error(`Failed to watch directory ${dirPath}:`, error);
191
+ }
192
+ }
193
+ /**
194
+ * Check if a file should be ignored
195
+ */
196
+ shouldIgnore(filePath) {
197
+ for (const pattern of this.config.ignorePatterns) {
198
+ if (pattern.includes('*')) {
199
+ const regex = new RegExp(pattern.replace('*', '.*'));
200
+ if (regex.test(filePath))
201
+ return true;
202
+ }
203
+ else {
204
+ if (filePath.includes(pattern))
205
+ return true;
206
+ }
207
+ }
208
+ return false;
209
+ }
210
+ /**
211
+ * Handle a file system event
212
+ */
213
+ handleFileEvent(filePath, eventType) {
214
+ const normalizedPath = path.normalize(filePath);
215
+ const previousHash = this.fileHashes.get(normalizedPath);
216
+ try {
217
+ if (fs.existsSync(filePath)) {
218
+ const content = fs.readFileSync(filePath, 'utf-8');
219
+ const newHash = this.hashContent(content);
220
+ if (previousHash !== newHash) {
221
+ this.fileHashes.set(normalizedPath, newHash);
222
+ if (previousHash === undefined) {
223
+ // New file or first time seeing it
224
+ this.trackCreate(normalizedPath, content);
225
+ }
226
+ else {
227
+ // Modified file
228
+ this.trackEdit(normalizedPath, '', content); // We don't have old content in watch mode
229
+ }
230
+ }
231
+ }
232
+ else if (previousHash !== undefined) {
233
+ // File was deleted
234
+ this.fileHashes.delete(normalizedPath);
235
+ this.trackDelete(normalizedPath, '');
236
+ }
237
+ }
238
+ catch (error) {
239
+ // File might be locked or inaccessible
240
+ }
241
+ }
242
+ /**
243
+ * Create an automatic checkpoint
244
+ */
245
+ createAutoCheckpoint() {
246
+ const checkpointName = `auto-${new Date().toISOString().replace(/[:.]/g, '-')}`;
247
+ this.statecli.checkpoint('session:current', checkpointName);
248
+ this.changeCount = 0;
249
+ }
250
+ }
251
+ exports.FileTracker = FileTracker;
252
+ //# sourceMappingURL=file-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-tracker.js","sourceRoot":"","sources":["../src/file-tracker.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,2CAA6B;AAC7B,+CAAiC;AAmBjC,MAAM,cAAc,GAAsB;IACxC,UAAU,EAAE,CAAC,GAAG,CAAC;IACjB,cAAc,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC;IACtE,cAAc,EAAE,IAAI;IACpB,mBAAmB,EAAE,EAAE;CACxB,CAAC;AAEF,MAAa,WAAW;IACd,QAAQ,CAAW;IACnB,MAAM,CAAoB;IAC1B,UAAU,GAAwB,IAAI,GAAG,EAAE,CAAC;IAC5C,WAAW,GAAW,CAAC,CAAC;IACxB,QAAQ,GAAmB,EAAE,CAAC;IAEtC,YAAY,QAAkB,EAAE,MAAmC;QACjE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,aAAa;QACX,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YAC/C,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,YAAY;QACV,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpC,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;QACD,IAAI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D,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;IACvB,CAAC;CACF;AA5OD,kCA4OC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Git Integration - Track changes between commits
3
+ *
4
+ * Integrates with git to provide commit-level state tracking
5
+ */
6
+ import { StateCLI } from './statecli';
7
+ export interface GitCommit {
8
+ hash: string;
9
+ shortHash: string;
10
+ message: string;
11
+ author: string;
12
+ date: string;
13
+ files: string[];
14
+ }
15
+ export interface GitDiff {
16
+ file: string;
17
+ additions: number;
18
+ deletions: number;
19
+ changes: string[];
20
+ }
21
+ export interface CommitComparison {
22
+ fromCommit: string;
23
+ toCommit: string;
24
+ files: GitDiff[];
25
+ summary: string;
26
+ }
27
+ export declare class GitIntegration {
28
+ private statecli;
29
+ private repoPath;
30
+ constructor(statecli: StateCLI, repoPath?: string);
31
+ /**
32
+ * Check if current directory is a git repository
33
+ */
34
+ isGitRepo(): boolean;
35
+ /**
36
+ * Get current branch name
37
+ */
38
+ getCurrentBranch(): string;
39
+ /**
40
+ * Get current commit hash
41
+ */
42
+ getCurrentCommit(): string;
43
+ /**
44
+ * Get recent commits
45
+ */
46
+ getRecentCommits(count?: number): GitCommit[];
47
+ /**
48
+ * Get files changed in a commit
49
+ */
50
+ getCommitFiles(commitHash: string): string[];
51
+ /**
52
+ * Compare two commits
53
+ */
54
+ compareCommits(fromCommit: string, toCommit: string): CommitComparison;
55
+ /**
56
+ * Get diff for a specific file between commits
57
+ */
58
+ getFileDiff(fromCommit: string, toCommit: string, filePath: string): string[];
59
+ /**
60
+ * Track current git state in StateCLI
61
+ */
62
+ trackGitState(actor?: string): void;
63
+ /**
64
+ * Create a checkpoint at current git state
65
+ */
66
+ createGitCheckpoint(name?: string): {
67
+ checkpointId: string;
68
+ commit: string;
69
+ };
70
+ /**
71
+ * Get what happened between two commits in StateCLI format
72
+ */
73
+ getCommitHistory(fromCommit: string, toCommit: string): {
74
+ commits: GitCommit[];
75
+ comparison: CommitComparison;
76
+ stateChanges: ReturnType<StateCLI['replay']>;
77
+ };
78
+ /**
79
+ * Get commits between two commit hashes
80
+ */
81
+ private getCommitsBetween;
82
+ /**
83
+ * Get uncommitted changes
84
+ */
85
+ getUncommittedChanges(): {
86
+ staged: string[];
87
+ unstaged: string[];
88
+ untracked: string[];
89
+ };
90
+ /**
91
+ * Execute a git command
92
+ */
93
+ private execGit;
94
+ }
95
+ //# sourceMappingURL=git-integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-integration.d.ts","sourceRoot":"","sources":["../src/git-integration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAS;gBAEb,QAAQ,EAAE,QAAQ,EAAE,QAAQ,GAAE,MAAY;IAKtD;;OAEG;IACH,SAAS,IAAI,OAAO;IASpB;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAI1B;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAI1B;;OAEG;IACH,gBAAgB,CA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