refactor: low-regret cleanup across core, engine, dashboard

- core: extract ai-engine-loader.ts to share @fusion/engine dynamic-import
  boilerplate between ai-summarize and memory-compaction (incl. AgentMessage
  type); collapse getInbox/getOutbox, listInsights/countInsights,
  listRuns/countRuns, and three hasProjectDb* variants behind shared helpers.
- core: drop unused pluginLoaderLog export; tighten two `any` casts
  (db.walCheckpoint row, plugin-loader error.code).
- engine: extract resolveRoleFallback helper from buildSessionSkillContext/Sync;
  remove 22 stale `eslint-disable no-explicit-any` directives across
  project-engine, self-healing, triage, worktree-pool.
- dashboard: apply ESLint autofix (let→const, empty `interface extends`→type).

All three packages: typecheck clean, full test suites pass (14,414 tests),
builds clean. Net lint: -31 warnings. No public behavior changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-19 13:33:19 -07:00
parent a93f0f2ef9
commit 3f8161a90a
18 changed files with 174 additions and 266 deletions

View File

@@ -0,0 +1,45 @@
/**
* Shared lazy loader for `@fusion/engine`'s `createKbAgent`.
*
* @fusion/engine must be imported dynamically (not statically) so that:
* - core can be consumed in test environments where engine isn't resolvable
* - a missing engine package fails soft instead of breaking module load
*
* Using a variable module specifier also prevents bundlers (Vite) from
* statically analysing and trying to resolve the import at build time.
*/
// Engine exports a function type we intentionally don't pull in here — importing
// the type would reintroduce the static resolution this module is designed to avoid.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type CreateKbAgent = any;
let createKbAgent: CreateKbAgent | undefined;
async function initEngine(): Promise<void> {
try {
const engineModule = "@fusion/engine";
const engine = await import(/* @vite-ignore */ engineModule);
createKbAgent = engine.createKbAgent;
} catch {
createKbAgent = undefined;
}
}
/** Shape of a message in an agent session's state. */
export interface AgentMessage {
role: string;
content?: string | Array<{ type: string; text: string }>;
}
/** Promise that resolves once the initial load attempt has completed. */
const engineReady: Promise<void> = initEngine();
/**
* Returns `createKbAgent` from `@fusion/engine`, or `undefined` if the engine
* could not be loaded (typical in tests or when engine isn't installed).
*/
export async function getKbAgent(): Promise<CreateKbAgent> {
await engineReady;
return createKbAgent;
}