Native clone operations for vibe CLI (clonefile on macOS, FICLONE on Linux)
npm install @kexi/vibe-nativeNative Copy-on-Write (CoW) file cloning for Node.js using Rust (napi-rs).
- macOS: Uses clonefile() syscall on APFS filesystems
- Linux: Uses FICLONE ioctl on Btrfs/XFS filesystems
- Zero-copy: Creates instant file clones without copying data
- Async/Sync: Both async and sync APIs available
- Type-safe: Full TypeScript support with auto-generated types
``bash`
npm install @kexi/vibe-nativeor
pnpm add @kexi/vibe-native
| Platform | Architecture | Filesystem |
| -------- | ------------ | ------------------------- |
| macOS | x64, arm64 | APFS |
| Linux | x64, arm64 | Btrfs, XFS (with reflink) |
`typescript
import {
cloneAsync,
cloneSync,
isAvailable,
supportsDirectory,
getPlatform,
} from "@kexi/vibe-native";
// Check if native cloning is available
if (isAvailable()) {
console.log(Platform: ${getPlatform()});Directory cloning: ${supportsDirectory()}
console.log();
// Async cloning (recommended)
await cloneAsync("/path/to/source", "/path/to/dest");
// Sync cloning
cloneSync("/path/to/source", "/path/to/dest");
}
`
Clone a file or directory asynchronously using native Copy-on-Write.
Clone a file or directory synchronously using native Copy-on-Write.
Alias for cloneSync (for backward compatibility).
Check if native clone operations are available on the current platform.
Check if directory cloning is supported:
- macOS (clonefile): trueFICLONE
- Linux (): false (files only)
Get the current platform identifier.
Only regular files and directories are allowed. The following are rejected:
- Symlinks (to prevent path traversal)
- Device files (block/character devices)
- Sockets
- FIFOs (named pipes)
This library does not perform path normalization or validation. Callers should:
- Validate paths before calling clone functions
- Use path.resolve() to normalize relative paths
- Check for symlinks if path traversal is a concern
`typescript
import { resolve, dirname } from "path";
import { realpath } from "fs/promises";
// Example: Safe path handling
async function safeClone(src: string, dest: string, allowedDir: string) {
const resolvedSrc = await realpath(resolve(src));
const resolvedDest = resolve(dest);
// Verify paths are within allowed directory
if (!resolvedSrc.startsWith(allowedDir)) {
throw new Error("Source path outside allowed directory");
}
if (!resolvedDest.startsWith(allowedDir)) {
throw new Error("Destination path outside allowed directory");
}
await cloneAsync(resolvedSrc, resolvedDest);
}
`
Errors include system errno information for debugging:
`typescript`
try {
await cloneAsync("/nonexistent", "/dest");
} catch (error) {
// Error: open source failed: No such file or directory (errno 2)
console.error(error.message);
}
- APFS is required for clonefile() to workENOTSUP
- HFS+ and other filesystems will return
- Btrfs or XFS (with reflink support) is required
- ext4 and other filesystems will return EOPNOTSUPP
`bashInstall dependencies
pnpm install
Apache-2.0