BREAKING CHANGE(core): Migrate filesystem to smartfs (async) and add Elasticsearch service support; refactor format/commit/meta modules

This commit is contained in:
2025-11-27 21:32:34 +00:00
parent 2f3d67f9e3
commit e1d28bc10a
30 changed files with 2217 additions and 995 deletions

View File

@@ -25,7 +25,7 @@ export class ChangeCache {
}
async initialize(): Promise<void> {
await plugins.smartfile.fs.ensureDir(this.cacheDir);
await plugins.smartfs.directory(this.cacheDir).recursive().create();
}
async getManifest(): Promise<ICacheManifest> {
@@ -35,13 +35,16 @@ export class ChangeCache {
files: [],
};
const exists = await plugins.smartfile.fs.fileExists(this.manifestPath);
const exists = await plugins.smartfs.file(this.manifestPath).exists();
if (!exists) {
return defaultManifest;
}
try {
const content = plugins.smartfile.fs.toStringSync(this.manifestPath);
const content = (await plugins.smartfs
.file(this.manifestPath)
.encoding('utf8')
.read()) as string;
const manifest = JSON.parse(content);
// Validate the manifest structure
@@ -57,7 +60,7 @@ export class ChangeCache {
);
// Try to delete the corrupted file
try {
await plugins.smartfile.fs.remove(this.manifestPath);
await plugins.smartfs.file(this.manifestPath).delete();
} catch (removeError) {
// Ignore removal errors
}
@@ -72,11 +75,14 @@ export class ChangeCache {
}
// Ensure directory exists
await plugins.smartfile.fs.ensureDir(this.cacheDir);
await plugins.smartfs.directory(this.cacheDir).recursive().create();
// Write directly with proper JSON stringification
const jsonContent = JSON.stringify(manifest, null, 2);
await plugins.smartfile.memory.toFs(jsonContent, this.manifestPath);
await plugins.smartfs
.file(this.manifestPath)
.encoding('utf8')
.write(jsonContent);
}
async hasFileChanged(filePath: string): Promise<boolean> {
@@ -85,20 +91,23 @@ export class ChangeCache {
: plugins.path.join(paths.cwd, filePath);
// Check if file exists
const exists = await plugins.smartfile.fs.fileExists(absolutePath);
const exists = await plugins.smartfs.file(absolutePath).exists();
if (!exists) {
return true; // File doesn't exist, so it's "changed" (will be created)
}
// Get current file stats
const stats = await plugins.smartfile.fs.stat(absolutePath);
const stats = await plugins.smartfs.file(absolutePath).stat();
// Skip directories
if (stats.isDirectory()) {
if (stats.isDirectory) {
return false; // Directories are not processed
}
const content = plugins.smartfile.fs.toStringSync(absolutePath);
const content = (await plugins.smartfs
.file(absolutePath)
.encoding('utf8')
.read()) as string;
const currentChecksum = this.calculateChecksum(content);
// Get cached info
@@ -113,7 +122,7 @@ export class ChangeCache {
return (
cachedFile.checksum !== currentChecksum ||
cachedFile.size !== stats.size ||
cachedFile.modified !== stats.mtimeMs
cachedFile.modified !== stats.mtime.getTime()
);
}
@@ -123,14 +132,17 @@ export class ChangeCache {
: plugins.path.join(paths.cwd, filePath);
// Get current file stats
const stats = await plugins.smartfile.fs.stat(absolutePath);
const stats = await plugins.smartfs.file(absolutePath).stat();
// Skip directories
if (stats.isDirectory()) {
if (stats.isDirectory) {
return; // Don't cache directories
}
const content = plugins.smartfile.fs.toStringSync(absolutePath);
const content = (await plugins.smartfs
.file(absolutePath)
.encoding('utf8')
.read()) as string;
const checksum = this.calculateChecksum(content);
// Update manifest
@@ -140,7 +152,7 @@ export class ChangeCache {
const cacheEntry: IFileCache = {
path: filePath,
checksum,
modified: stats.mtimeMs,
modified: stats.mtime.getTime(),
size: stats.size,
};
@@ -176,7 +188,7 @@ export class ChangeCache {
? file.path
: plugins.path.join(paths.cwd, file.path);
if (await plugins.smartfile.fs.fileExists(absolutePath)) {
if (await plugins.smartfs.file(absolutePath).exists()) {
validFiles.push(file);
}
}