@iyulab/oops
Version:
Core SDK for Oops - Safe text file editing with automatic backup
153 lines (104 loc) • 3.71 kB
Markdown
Core SDK for Oops - Safe text file editing with automatic backup and simple undo.
```bash
npm install @iyulab/oops
```
```typescript
import { Oops } from '@iyulab/oops';
const oops = new Oops();
// Initialize workspace
await oops.initWorkspace();
// Start tracking a file
await oops.begin('/path/to/file.txt');
// Check for changes
const hasChanges = await oops.hasChanges('/path/to/file.txt');
// Get diff
const diff = await oops.diff('/path/to/file.txt');
// Apply changes
await oops.keep('/path/to/file.txt');
// Or undo changes
await oops.undo('/path/to/file.txt');
```
- 🔒 **Safe file editing** with automatic backup
- 📝 **Simple undo** functionality
- 🗂️ **Workspace management** with temporary or local storage
- 🔄 **Batch operations** for multiple files
- 📊 **File validation** and health checks
- ⚙️ **Configurable** safety options
Initialize a new workspace for tracking files.
Start tracking a file by creating a backup.
Check if a tracked file has changes.
Generate diff information for a tracked file.
Apply changes and stop tracking the file.
Revert file to backup and stop tracking.
Stop tracking without reverting changes.
Apply changes to all tracked files.
Revert all tracked files to their backups.
Stop tracking all files without reverting.
Get information about the current workspace.
Check if the workspace is in a healthy state.
Clean up the workspace and all tracking data.
Get workspace size information.
Get current configuration.
Set configuration values (supports nested keys like 'safety.confirmKeep').
## Configuration Options
```typescript
interface OopsConfig {
workspace: {
useTemp: boolean; // Use temporary directory
path: string | null; // Custom workspace path
};
safety: {
confirmKeep: boolean; // Confirm before applying changes
confirmUndo: boolean; // Confirm before undoing
autoBackup: boolean; // Automatic backup creation
};
diff: {
tool: string; // External diff tool ('auto', 'code', 'vimdiff', etc.)
context: number; // Number of context lines in diff
};
}
```
Create an instance with a temporary workspace.
Create an instance with a local workspace.
The SDK provides specific error types for better error handling:
- `FileNotFoundError`
- `FileAlreadyTrackedError`
- `FileNotTrackedError`
- `WorkspaceNotInitializedError`
- `WorkspaceCorruptedError`
- `GitOperationError`
This package is written in TypeScript and includes complete type definitions.
MIT - see [LICENSE](./LICENSE) for details.
[](https://github.com/iyulab/oops)