generalize continuity plugin engine and generic adapter

This commit is contained in:
Eve
2026-04-24 19:28:20 +08:00
parent ed4fe3ea6c
commit 1fe6474009
13 changed files with 679 additions and 153 deletions

View File

@@ -394,14 +394,37 @@ const continuityAdapterModuleCache = new Map<string, Promise<ForceRecallContinui
async function loadForceRecallContinuityAdapterModule(workspaceDir: string): Promise<ForceRecallContinuityAdapterModule | null> {
const adapterPath = path.join(workspaceDir, "plugins", "continuity", "src", "index.mjs");
let modulePromise = continuityAdapterModuleCache.get(adapterPath);
if (!modulePromise) {
modulePromise = import(pathToFileURL(adapterPath).href).catch(() => null);
continuityAdapterModuleCache.set(adapterPath, modulePromise);
try {
const stat = await fs.stat(adapterPath);
const cacheKey = `${adapterPath}?mtimeMs=${stat.mtimeMs}`;
let modulePromise = continuityAdapterModuleCache.get(cacheKey);
if (!modulePromise) {
modulePromise = import(pathToFileURL(adapterPath).href + `?mtimeMs=${stat.mtimeMs}`).catch(() => null);
continuityAdapterModuleCache.set(cacheKey, modulePromise);
}
return modulePromise;
} catch {
return null;
}
}
return modulePromise;
async function readContinuityPluginConfigOverrides(workspaceDir: string): Promise<Record<string, unknown>> {
const defaultsPath = path.join(workspaceDir, "plugins", "continuity", "src", "config", "defaults.mjs");
const source = await safeReadText(defaultsPath);
if (!source) return {};
const forceRecallLabel = source.match(/forceRecall:\s*\{[\s\S]*?injectBlockLabel:\s*['"]([^'"]+)['"]/);
const genericPreflightLabel = source.match(/genericPreflight:\s*\{[\s\S]*?injectBlockLabel:\s*['"]([^'"]+)['"]/);
return {
adapter: {
forceRecall: forceRecallLabel ? { injectBlockLabel: forceRecallLabel[1] } : {},
genericPreflight: genericPreflightLabel ? { injectBlockLabel: genericPreflightLabel[1] } : {},
},
};
}
async function evaluateApprovedPlanContinuityViaPlugin(workspaceDir: string, wrapperResult: any, autoChainPlanResult: AutoChainPlanResult | null): Promise<{ input: Record<string, unknown> | null; result: ApprovedPlanContinuityResult | null; block: string; } | null> {
@@ -409,10 +432,27 @@ async function evaluateApprovedPlanContinuityViaPlugin(workspaceDir: string, wra
const runAdapter = adapterModule?.runForceRecallContinuityAdapter;
if (typeof runAdapter !== "function") return null;
const configOverrides = await readContinuityPluginConfigOverrides(workspaceDir);
return runAdapter({
wrapperResult,
autoChainPlanResult,
config: adapterModule?.defaultConfig ?? {},
config: {
...(adapterModule?.defaultConfig ?? {}),
...configOverrides,
adapter: {
...(((adapterModule?.defaultConfig ?? {}) as any)?.adapter ?? {}),
...((configOverrides as any)?.adapter ?? {}),
forceRecall: {
...((((adapterModule?.defaultConfig ?? {}) as any)?.adapter?.forceRecall) ?? {}),
...(((configOverrides as any)?.adapter?.forceRecall) ?? {}),
},
genericPreflight: {
...((((adapterModule?.defaultConfig ?? {}) as any)?.adapter?.genericPreflight) ?? {}),
...(((configOverrides as any)?.adapter?.genericPreflight) ?? {}),
},
},
},
});
}