import type { ChunkOptions } from '../chunking/types'; import type { ICodeAdapter, IEmbeddingService } from '../indexer/interfaces'; import type { CodebaseStats } from '../worker/surreal-adapter'; /** A single file entry from the client, with content already read. */ export interface CodebaseFileInput { /** Repo-relative path (e.g., "src/index.ts") */ path: string; /** UTF-8 file content */ content: string; /** Optional pre-computed sha256 hash of content (server will verify) */ sha256?: string; /** Optional package name detected by the client (e.g., "@epicdm/flowstate-cli") */ packageName?: string; } export interface ProcessBatchInput { codebaseId: string; orgId: string; workspaceId: string; files: CodebaseFileInput[]; } /** Per-file outcome from processBatch. */ export interface ProcessFileResult { path: string; status: 'indexed' | 'unchanged' | 'skipped' | 'error'; chunksCreated: number; contentHash?: string; error?: string; } export interface ProcessBatchResult { results: ProcessFileResult[]; totals: { indexed: number; unchanged: number; skipped: number; errors: number; chunksCreated: number; embeddingMs: number; }; } export interface CleanupInput { codebaseId: string; /** Full set of paths the client knows about. Anything indexed but NOT in this set is stale. */ knownPaths: string[]; } export interface CleanupResult { filesDeleted: number; chunksDeleted: number; stalePaths: string[]; } export interface GetHashesInput { codebaseId: string; paths: string[]; } export interface CodebaseServiceConfig { /** Code adapter (already constructed; service will manage connect/disconnect) */ codeAdapter: ICodeAdapter; /** Embedding service (already constructed) */ embeddingService: IEmbeddingService; /** Chunking options (default: { maxTokens: 512, overlapTokens: 50 }) */ chunking?: ChunkOptions; /** Maximum file size in bytes the server will accept (default: 102400 = 100KB) */ maxFileSizeBytes?: number; } /** * Server-side codebase indexing service. Operates entirely on content * delivered over HTTP — never reads from disk and never touches RxDB. * * The CLI does git scanning, file reading, ragignore filtering, and sha256 * hashing on the client side, then POSTs file batches here. This service * runs the chunking, embedding, and SurrealDB writes inside the document-store * Docker container, where it has internal SurrealDB credentials. * * Data isolation: this service writes only to SurrealDB `rag_documents` rows * with `collection = 'code'`. It does NOT touch any RxDB collection. */ export declare class CodebaseService { private codeAdapter; private embeddingService; private contentExtractor; private chunker; private maxFileSizeBytes; private connected; constructor(config: CodebaseServiceConfig); /** * Ensure the SurrealDB connection is open. Idempotent. * Migrations run with internal credentials so they have DDL permission. */ ensureConnected(): Promise; /** * Close the SurrealDB connection. Used during graceful shutdown. */ close(): Promise; /** * Process a batch of files: hash check → extract → chunk → embed → store. * Files unchanged since their last index are skipped (filesUnchanged). * Files exceeding maxFileSizeBytes are skipped with status='skipped'. * Per-file errors are captured and do NOT abort the rest of the batch. */ processBatch(input: ProcessBatchInput): Promise; /** * Diff the client's known-paths set against everything we have indexed * and delete chunks for stale paths. */ cleanup(input: CleanupInput): Promise; /** * Look up content hashes for a batch of paths so the client can skip * unchanged files before sending content over the wire. * Returns a map of path → contentHash (paths not indexed are omitted). */ getHashes(input: GetHashesInput): Promise>; getStats(codebaseId: string): Promise; purge(codebaseId: string): Promise<{ chunksDeleted: number; }>; private pendingEmbeddingMs; private consumeEmbeddingMs; private processOne; } //# sourceMappingURL=codebase-service.d.ts.map