mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
* 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>
97 lines
2.9 KiB
TypeScript
97 lines
2.9 KiB
TypeScript
import {
|
|
getLockedItems,
|
|
isFileLocked as isFileLockedInternal,
|
|
isFolderLocked as isFolderLockedInternal,
|
|
isPathInLockedFolder,
|
|
} from '~/lib/persistence/lockedFiles';
|
|
import { createScopedLogger } from './logger';
|
|
|
|
const logger = createScopedLogger('FileLocks');
|
|
|
|
/**
|
|
* Get the current chat ID from the URL
|
|
* @returns The current chat ID or a default value if not found
|
|
*/
|
|
export function getCurrentChatId(): string {
|
|
try {
|
|
if (typeof window !== 'undefined') {
|
|
// Extract chat ID from URL (format: /chat/123)
|
|
const match = window.location.pathname.match(/\/chat\/([^/]+)/);
|
|
|
|
if (match && match[1]) {
|
|
return match[1];
|
|
}
|
|
}
|
|
|
|
// Return a default chat ID if none is found
|
|
return 'default';
|
|
} catch (error) {
|
|
logger.error('Failed to get current chat ID', error);
|
|
return 'default';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if a file is locked directly from localStorage
|
|
* This avoids circular dependencies between components and stores
|
|
* @param filePath The path of the file to check
|
|
* @param chatId Optional chat ID (will be extracted from URL if not provided)
|
|
*/
|
|
export function isFileLocked(filePath: string, chatId?: string): { locked: boolean; lockedBy?: string } {
|
|
try {
|
|
const currentChatId = chatId || getCurrentChatId();
|
|
|
|
// Use the internal function from lockedFiles.ts
|
|
const result = isFileLockedInternal(currentChatId, filePath);
|
|
|
|
// If the file itself is not locked, check if it's in a locked folder
|
|
if (!result.locked) {
|
|
const folderLockResult = isPathInLockedFolder(currentChatId, filePath);
|
|
|
|
if (folderLockResult.locked) {
|
|
return folderLockResult;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
} catch (error) {
|
|
logger.error('Failed to check if file is locked', error);
|
|
return { locked: false };
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if a folder is locked directly from localStorage
|
|
* This avoids circular dependencies between components and stores
|
|
* @param folderPath The path of the folder to check
|
|
* @param chatId Optional chat ID (will be extracted from URL if not provided)
|
|
*/
|
|
export function isFolderLocked(folderPath: string, chatId?: string): { locked: boolean; lockedBy?: string } {
|
|
try {
|
|
const currentChatId = chatId || getCurrentChatId();
|
|
|
|
// Use the internal function from lockedFiles.ts
|
|
return isFolderLockedInternal(currentChatId, folderPath);
|
|
} catch (error) {
|
|
logger.error('Failed to check if folder is locked', error);
|
|
return { locked: false };
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if any files are locked in the current chat
|
|
* @param chatId Optional chat ID (will be extracted from URL if not provided)
|
|
* @returns True if any files or folders are locked
|
|
*/
|
|
export function hasLockedItems(chatId?: string): boolean {
|
|
try {
|
|
const currentChatId = chatId || getCurrentChatId();
|
|
const lockedItems = getLockedItems();
|
|
|
|
return lockedItems.some((item) => item.chatId === currentChatId);
|
|
} catch (error) {
|
|
logger.error('Failed to check for locked items', error);
|
|
return false;
|
|
}
|
|
}
|