Commit 35cbae1
committed
feat: Enhanced file locking and diff improvements for conflict prevention
This commit implements comprehensive enhancements to the file locking system
and diff generation to provide better conflict prevention and tracking.
## Key Improvements
### 1. File Version Tracking
- Added version number, lastModified timestamp, and modifiedBy fields to File interface
- Automatically increment version on every file modification
- Track modification source (user, AI, or external)
- Foundation for future optimistic locking and conflict detection
### 2. Lock Timeout & Expiration
- Added timestamp tracking for when locks are acquired (lockedAt)
- Implemented configurable lock timeout (default: 30 minutes)
- Automatic cleanup of expired locks every 5 minutes
- Prevents stale locks from persisting indefinitely
- Expired locks are automatically removed when checked
### 3. Enhanced Diff Metadata
- Diffs now include timestamp, modification source, and version information
- Better context for conflict resolution and change tracking
- Helps AI understand when and how files were modified
### 4. Automatic Lock Acquisition
- Files are automatically locked when user starts editing
- 2-second debounce prevents locking files being briefly viewed
- Auto-locks are clearly marked for distinction from manual locks
- Reduces manual lock management burden
### 5. Lock Validation in ActionRunner
- ActionRunner now validates locks before writing files
- AI cannot modify locked files
- Clear error messages indicate which file/folder caused the lock
- User alerts notify of lock conflicts
### 6. Improved Lock Checking
- Lock expiration checked on every lock status query
- Expired locks automatically removed inline
- Parent folder lock checking includes expiration validation
## Files Modified
- app/lib/stores/files.ts: Added version tracking to File interface and file operations
- app/lib/persistence/lockedFiles.ts: Implemented lock timeouts and expiration
- app/lib/stores/editor.ts: Added automatic lock acquisition on edit
- app/lib/runtime/action-runner.ts: Added lock validation before file writes
- app/utils/diff.ts: Enhanced diff metadata with timestamps and version info
## Future Enhancements
- Version-based conflict detection in ActionRunner (requires FilesStore access)
- Conflict resolution UI for handling version mismatches
- Three-way merge capabilities for conflicting changes
- Lock renewal for long-running edit sessions
## Benefits
- ✅ Prevents AI from overwriting user changes (via lock validation)
- ✅ Prevents stale locks from blocking work indefinitely (via expiration)
- ✅ Reduces manual lock management (via auto-locking)
- ✅ Better change tracking and context (via version + metadata)
- ✅ Foundation for optimistic locking (via version numbers)1 parent 3f6050b commit 35cbae1
File tree
5 files changed
+207
-10
lines changed- app
- lib
- persistence
- runtime
- stores
- utils
5 files changed
+207
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
8 | 14 | | |
9 | 15 | | |
10 | 16 | | |
11 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
12 | 21 | | |
13 | 22 | | |
14 | 23 | | |
| |||
133 | 142 | | |
134 | 143 | | |
135 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
136 | 180 | | |
137 | 181 | | |
138 | 182 | | |
139 | 183 | | |
140 | 184 | | |
| 185 | + | |
141 | 186 | | |
142 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
143 | 193 | | |
144 | 194 | | |
145 | 195 | | |
146 | | - | |
147 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
148 | 205 | | |
149 | 206 | | |
150 | 207 | | |
| |||
157 | 214 | | |
158 | 215 | | |
159 | 216 | | |
160 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
161 | 220 | | |
162 | 221 | | |
163 | 222 | | |
| |||
255 | 314 | | |
256 | 315 | | |
257 | 316 | | |
258 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
259 | 324 | | |
260 | 325 | | |
261 | 326 | | |
| |||
281 | 346 | | |
282 | 347 | | |
283 | 348 | | |
284 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
285 | 356 | | |
286 | 357 | | |
287 | 358 | | |
| |||
312 | 383 | | |
313 | 384 | | |
314 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
315 | 393 | | |
316 | 394 | | |
317 | 395 | | |
| |||
451 | 529 | | |
452 | 530 | | |
453 | 531 | | |
454 | | - | |
| 532 | + | |
| 533 | + | |
455 | 534 | | |
456 | 535 | | |
457 | 536 | | |
458 | 537 | | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
459 | 541 | | |
460 | 542 | | |
461 | 543 | | |
| |||
497 | 579 | | |
498 | 580 | | |
499 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
500 | 598 | | |
501 | 599 | | |
502 | 600 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
316 | 317 | | |
317 | 318 | | |
318 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
319 | 348 | | |
320 | 349 | | |
321 | 350 | | |
| |||
335 | 364 | | |
336 | 365 | | |
337 | 366 | | |
| 367 | + | |
338 | 368 | | |
339 | 369 | | |
340 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
35 | 76 | | |
36 | 77 | | |
37 | 78 | | |
| |||
104 | 145 | | |
105 | 146 | | |
106 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
107 | 151 | | |
108 | 152 | | |
109 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| |||
569 | 572 | | |
570 | 573 | | |
571 | 574 | | |
572 | | - | |
| 575 | + | |
573 | 576 | | |
574 | 577 | | |
| 578 | + | |
| 579 | + | |
575 | 580 | | |
576 | 581 | | |
577 | 582 | | |
578 | 583 | | |
579 | 584 | | |
580 | 585 | | |
581 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
582 | 591 | | |
583 | 592 | | |
584 | 593 | | |
| |||
794 | 803 | | |
795 | 804 | | |
796 | 805 | | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
797 | 809 | | |
798 | 810 | | |
799 | 811 | | |
| |||
806 | 818 | | |
807 | 819 | | |
808 | 820 | | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
809 | 824 | | |
810 | 825 | | |
811 | 826 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
38 | 48 | | |
39 | 49 | | |
40 | | - | |
| 50 | + | |
41 | 51 | | |
42 | 52 | | |
43 | | - | |
| 53 | + | |
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
| |||
0 commit comments