mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-10 21:36:07 +00:00
refactor: consolidate duplicated plugin state and doctor migration plumbing onto SDK seams (#99850)
* refactor(plugin-sdk): add createPersistentDedupeCache and migrate channel presence caches * refactor(matrix): adopt SDK approval reaction target store * refactor(plugin-sdk): share doctor legacy-state migration fs helpers * refactor(memory-core): dedupe qmd cache entry envelope validation * chore(plugin-sdk): pin surface budgets for shared dedupe and doctor helpers * test(matrix): use future approval expiry fixtures for reaction targets * test(matrix): use future approval expiry fixtures for reaction targets
This commit is contained in:
committed by
GitHub
parent
3d404478b8
commit
eafe2a8d0b
38
src/plugins/doctor-state-migration-fs.ts
Normal file
38
src/plugins/doctor-state-migration-fs.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// Shared filesystem helpers for plugin doctor legacy-state migrations.
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
/** True when the legacy-state path exists and is a regular file. */
|
||||
export async function legacyStateFileExists(filePath: string): Promise<boolean> {
|
||||
try {
|
||||
const stat = await fs.stat(filePath);
|
||||
return stat.isFile();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames a migrated legacy source to `<path>.migrated`, recording the outcome in the
|
||||
* doctor changes/warnings lists. Never throws: a failed archive leaves the source in
|
||||
* place so a later doctor run can retry without losing migrated data.
|
||||
*/
|
||||
export async function archiveLegacyStateSource(params: {
|
||||
filePath: string;
|
||||
label: string;
|
||||
changes: string[];
|
||||
warnings: string[];
|
||||
}): Promise<void> {
|
||||
const archivedPath = `${params.filePath}.migrated`;
|
||||
if (await legacyStateFileExists(archivedPath)) {
|
||||
params.warnings.push(
|
||||
`Left migrated ${params.label} source in place because ${archivedPath} already exists`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await fs.rename(params.filePath, archivedPath);
|
||||
params.changes.push(`Archived ${params.label} legacy source -> ${archivedPath}`);
|
||||
} catch (err) {
|
||||
params.warnings.push(`Failed archiving ${params.label} legacy source: ${String(err)}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user