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:
@@ -152,7 +152,7 @@ export const FileTree = memo(
|
||||
key={fileOrFolder.id}
|
||||
selected={selectedFile === fileOrFolder.fullPath}
|
||||
file={fileOrFolder}
|
||||
unsavedChanges={unsavedFiles?.has(fileOrFolder.fullPath)}
|
||||
unsavedChanges={unsavedFiles instanceof Set && unsavedFiles.has(fileOrFolder.fullPath)}
|
||||
fileHistory={fileHistory}
|
||||
onCopyPath={() => {
|
||||
onCopyPath(fileOrFolder);
|
||||
@@ -402,6 +402,86 @@ function FileContextMenu({
|
||||
}
|
||||
};
|
||||
|
||||
// Handler for locking a file with full lock
|
||||
const handleLockFile = () => {
|
||||
try {
|
||||
if (isFolder) {
|
||||
return;
|
||||
}
|
||||
|
||||
const success = workbenchStore.lockFile(fullPath);
|
||||
|
||||
if (success) {
|
||||
toast.success(`File locked successfully`);
|
||||
} else {
|
||||
toast.error(`Failed to lock file`);
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(`Error locking file`);
|
||||
logger.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Handler for unlocking a file
|
||||
const handleUnlockFile = () => {
|
||||
try {
|
||||
if (isFolder) {
|
||||
return;
|
||||
}
|
||||
|
||||
const success = workbenchStore.unlockFile(fullPath);
|
||||
|
||||
if (success) {
|
||||
toast.success(`File unlocked successfully`);
|
||||
} else {
|
||||
toast.error(`Failed to unlock file`);
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(`Error unlocking file`);
|
||||
logger.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Handler for locking a folder with full lock
|
||||
const handleLockFolder = () => {
|
||||
try {
|
||||
if (!isFolder) {
|
||||
return;
|
||||
}
|
||||
|
||||
const success = workbenchStore.lockFolder(fullPath);
|
||||
|
||||
if (success) {
|
||||
toast.success(`Folder locked successfully`);
|
||||
} else {
|
||||
toast.error(`Failed to lock folder`);
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(`Error locking folder`);
|
||||
logger.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Handler for unlocking a folder
|
||||
const handleUnlockFolder = () => {
|
||||
try {
|
||||
if (!isFolder) {
|
||||
return;
|
||||
}
|
||||
|
||||
const success = workbenchStore.unlockFolder(fullPath);
|
||||
|
||||
if (success) {
|
||||
toast.success(`Folder unlocked successfully`);
|
||||
} else {
|
||||
toast.error(`Failed to unlock folder`);
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(`Error unlocking folder`);
|
||||
logger.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContextMenu.Root>
|
||||
@@ -441,6 +521,40 @@ function FileContextMenu({
|
||||
<ContextMenuItem onSelect={onCopyPath}>Copy path</ContextMenuItem>
|
||||
<ContextMenuItem onSelect={onCopyRelativePath}>Copy relative path</ContextMenuItem>
|
||||
</ContextMenu.Group>
|
||||
{/* Add lock/unlock options for files and folders */}
|
||||
<ContextMenu.Group className="p-1 border-t-px border-solid border-bolt-elements-borderColor">
|
||||
{!isFolder ? (
|
||||
<>
|
||||
<ContextMenuItem onSelect={handleLockFile}>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="i-ph:lock-simple" />
|
||||
Lock File
|
||||
</div>
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onSelect={handleUnlockFile}>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="i-ph:lock-key-open" />
|
||||
Unlock File
|
||||
</div>
|
||||
</ContextMenuItem>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ContextMenuItem onSelect={handleLockFolder}>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="i-ph:lock-simple" />
|
||||
Lock Folder
|
||||
</div>
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onSelect={handleUnlockFolder}>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="i-ph:lock-key-open" />
|
||||
Unlock Folder
|
||||
</div>
|
||||
</ContextMenuItem>
|
||||
</>
|
||||
)}
|
||||
</ContextMenu.Group>
|
||||
{/* Add delete option in a new group */}
|
||||
<ContextMenu.Group className="p-1 border-t-px border-solid border-bolt-elements-borderColor">
|
||||
<ContextMenuItem onSelect={handleDelete}>
|
||||
@@ -474,6 +588,9 @@ function FileContextMenu({
|
||||
}
|
||||
|
||||
function Folder({ folder, collapsed, selected = false, onCopyPath, onCopyRelativePath, onClick }: FolderProps) {
|
||||
// Check if the folder is locked
|
||||
const { isLocked } = workbenchStore.isFolderLocked(folder.fullPath);
|
||||
|
||||
return (
|
||||
<FileContextMenu onCopyPath={onCopyPath} onCopyRelativePath={onCopyRelativePath} fullPath={folder.fullPath}>
|
||||
<NodeButton
|
||||
@@ -489,7 +606,15 @@ function Folder({ folder, collapsed, selected = false, onCopyPath, onCopyRelativ
|
||||
})}
|
||||
onClick={onClick}
|
||||
>
|
||||
{folder.name}
|
||||
<div className="flex items-center w-full">
|
||||
<div className="flex-1 truncate pr-2">{folder.name}</div>
|
||||
{isLocked && (
|
||||
<span
|
||||
className={classNames('shrink-0', 'i-ph:lock-simple scale-80 text-red-500')}
|
||||
title={'Folder is locked'}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</NodeButton>
|
||||
</FileContextMenu>
|
||||
);
|
||||
@@ -516,6 +641,9 @@ function File({
|
||||
}: FileProps) {
|
||||
const { depth, name, fullPath } = file;
|
||||
|
||||
// Check if the file is locked
|
||||
const { locked } = workbenchStore.isFileLocked(fullPath);
|
||||
|
||||
const fileModifications = fileHistory[fullPath];
|
||||
|
||||
const { additions, deletions } = useMemo(() => {
|
||||
@@ -582,6 +710,12 @@ function File({
|
||||
{deletions > 0 && <span className="text-red-500">-{deletions}</span>}
|
||||
</div>
|
||||
)}
|
||||
{locked && (
|
||||
<span
|
||||
className={classNames('shrink-0', 'i-ph:lock-simple scale-80 text-red-500')}
|
||||
title={'File is locked'}
|
||||
/>
|
||||
)}
|
||||
{unsavedChanges && <span className="i-ph:circle-fill scale-68 shrink-0 text-orange-500" />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user