feat: lock files (#1681)
* Add persistent file locking feature with enhanced UI * Fix file locking to be scoped by chat ID * Add folder locking functionality * Update CHANGES.md to include folder locking functionality * Add early detection of locked files/folders in user prompts * Improve locked files detection with smarter pattern matching and prevent AI from attempting to modify locked files * Add detection for unlocked files to allow AI to continue with modifications in the same chat session * Implement dialog-based Lock Manager with improved styling for dark/light modes * Add remaining files for file locking implementation * refactor(lock-manager): simplify lock management UI and remove scoped lock options Consolidate lock management UI by removing scoped lock options and integrating LockManager directly into the EditorPanel. Simplify the lock management interface by removing the dialog and replacing it with a tab-based view. This improves maintainability and user experience by reducing complexity and streamlining the lock management process. Change Lock & Unlock action to use toast instead of alert. Remove LockManagerDialog as it is now tab based. * Optimize file locking mechanism for better performance - Add in-memory caching to reduce localStorage reads - Implement debounced localStorage writes - Use Map data structures for faster lookups - Add batch operations for locking/unlocking multiple items - Reduce polling frequency and add event-based updates - Add performance monitoring and cross-tab synchronization * refactor(file-locking): simplify file locking mechanism and remove scoped locks This commit removes the scoped locking feature and simplifies the file locking mechanism. The `LockMode` type and related logic have been removed, and all locks are now treated as full locks. The `isLocked` property has been standardized across the codebase, replacing the previous `locked` and `lockMode` properties. Additionally, the `useLockedFilesChecker` hook and `LockAlert` component have been removed as they are no longer needed with the simplified locking system. This gives the LLM a clear understanding of locked files and strict instructions not to make any changes to these files * refactor: remove debug console.log statements --------- Co-authored-by: KevIsDev <zennerd404@gmail.com>
This commit is contained in:
@@ -49,11 +49,11 @@ export class WorkbenchStore {
|
||||
currentView: WritableAtom<WorkbenchViewType> = import.meta.hot?.data.currentView ?? atom('code');
|
||||
unsavedFiles: WritableAtom<Set<string>> = import.meta.hot?.data.unsavedFiles ?? atom(new Set<string>());
|
||||
actionAlert: WritableAtom<ActionAlert | undefined> =
|
||||
import.meta.hot?.data.unsavedFiles ?? atom<ActionAlert | undefined>(undefined);
|
||||
import.meta.hot?.data.actionAlert ?? atom<ActionAlert | undefined>(undefined);
|
||||
supabaseAlert: WritableAtom<SupabaseAlert | undefined> =
|
||||
import.meta.hot?.data.unsavedFiles ?? atom<ActionAlert | undefined>(undefined);
|
||||
import.meta.hot?.data.supabaseAlert ?? atom<SupabaseAlert | undefined>(undefined);
|
||||
deployAlert: WritableAtom<DeployAlert | undefined> =
|
||||
import.meta.hot?.data.unsavedFiles ?? atom<DeployAlert | undefined>(undefined);
|
||||
import.meta.hot?.data.deployAlert ?? atom<DeployAlert | undefined>(undefined);
|
||||
modifiedFiles = new Set<string>();
|
||||
artifactIdList: string[] = [];
|
||||
#globalExecutionQueue = Promise.resolve();
|
||||
@@ -226,6 +226,12 @@ export class WorkbenchStore {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* For scoped locks, we would need to implement diff checking here
|
||||
* to determine if the user is modifying existing code or just adding new code
|
||||
* This is a more complex feature that would be implemented in a future update
|
||||
*/
|
||||
|
||||
await this.#filesStore.saveFile(filePath, document.value);
|
||||
|
||||
const newUnsavedFiles = new Set(this.unsavedFiles.get());
|
||||
@@ -279,6 +285,60 @@ export class WorkbenchStore {
|
||||
this.#filesStore.resetFileModifications();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock a file to prevent edits
|
||||
* @param filePath Path to the file to lock
|
||||
* @returns True if the file was successfully locked
|
||||
*/
|
||||
lockFile(filePath: string) {
|
||||
return this.#filesStore.lockFile(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock a folder and all its contents to prevent edits
|
||||
* @param folderPath Path to the folder to lock
|
||||
* @returns True if the folder was successfully locked
|
||||
*/
|
||||
lockFolder(folderPath: string) {
|
||||
return this.#filesStore.lockFolder(folderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock a file to allow edits
|
||||
* @param filePath Path to the file to unlock
|
||||
* @returns True if the file was successfully unlocked
|
||||
*/
|
||||
unlockFile(filePath: string) {
|
||||
return this.#filesStore.unlockFile(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock a folder and all its contents to allow edits
|
||||
* @param folderPath Path to the folder to unlock
|
||||
* @returns True if the folder was successfully unlocked
|
||||
*/
|
||||
unlockFolder(folderPath: string) {
|
||||
return this.#filesStore.unlockFolder(folderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a file is locked
|
||||
* @param filePath Path to the file to check
|
||||
* @returns Object with locked status, lock mode, and what caused the lock
|
||||
*/
|
||||
isFileLocked(filePath: string) {
|
||||
return this.#filesStore.isFileLocked(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a folder is locked
|
||||
* @param folderPath Path to the folder to check
|
||||
* @returns Object with locked status, lock mode, and what caused the lock
|
||||
*/
|
||||
isFolderLocked(folderPath: string) {
|
||||
return this.#filesStore.isFolderLocked(folderPath);
|
||||
}
|
||||
|
||||
async createFile(filePath: string, content: string | Uint8Array = '') {
|
||||
try {
|
||||
const success = await this.#filesStore.createFile(filePath, content);
|
||||
@@ -497,6 +557,12 @@ export class WorkbenchStore {
|
||||
const wc = await webcontainer;
|
||||
const fullPath = path.join(wc.workdir, data.action.filePath);
|
||||
|
||||
/*
|
||||
* For scoped locks, we would need to implement diff checking here
|
||||
* to determine if the AI is modifying existing code or just adding new code
|
||||
* This is a more complex feature that would be implemented in a future update
|
||||
*/
|
||||
|
||||
if (this.selectedFile.value !== fullPath) {
|
||||
this.setSelectedFile(fullPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user