qmd/src/maintenance.ts
Tobi Lutke c68904fe08
refactor: move CLI and MCP to subdirectories, MCP consumes SDK
Move frontends into src/cli/ and src/mcp/ to separate them from the
core library. The MCP server is fully rewritten to import only from
the SDK (src/index.ts) — zero direct store.ts/collections.ts/llm.ts
access.

- src/qmd.ts → src/cli/qmd.ts
- src/formatter.ts → src/cli/formatter.ts
- src/mcp.ts → src/mcp/server.ts (rewritten to use QMDStore SDK)
- New src/maintenance.ts: Maintenance class for CLI housekeeping
- SDK gains: getDocumentBody(), getDefaultCollectionNames(),
  extractSnippet/addLineNumbers/DEFAULT_MULTI_GET_MAX_BYTES exports,
  getDefaultDbPath re-export, InternalStore type export
- package.json bin/scripts updated for new paths
- All 692 tests pass
2026-03-10 11:39:55 -04:00

55 lines
1.4 KiB
TypeScript

/**
* Maintenance - Database cleanup operations for QMD.
*
* Wraps low-level store operations that the CLI needs for housekeeping.
* Takes an internal Store in the constructor — allowed to access DB directly.
*/
import type { Store } from "./store.js";
import {
vacuumDatabase,
cleanupOrphanedContent,
cleanupOrphanedVectors,
deleteLLMCache,
deleteInactiveDocuments,
clearAllEmbeddings,
} from "./store.js";
export class Maintenance {
private store: Store;
constructor(store: Store) {
this.store = store;
}
/** Run VACUUM on the SQLite database to reclaim space */
vacuum(): void {
vacuumDatabase(this.store.db);
}
/** Remove content rows that are no longer referenced by any document */
cleanupOrphanedContent(): number {
return cleanupOrphanedContent(this.store.db);
}
/** Remove vector embeddings for content that no longer exists */
cleanupOrphanedVectors(): number {
return cleanupOrphanedVectors(this.store.db);
}
/** Clear the LLM response cache (query expansion, reranking) */
clearLLMCache(): number {
return deleteLLMCache(this.store.db);
}
/** Delete documents marked as inactive (removed from filesystem) */
deleteInactiveDocs(): number {
return deleteInactiveDocuments(this.store.db);
}
/** Clear all vector embeddings (forces re-embedding) */
clearEmbeddings(): void {
clearAllEmbeddings(this.store.db);
}
}