/** * GitFileSystem * * A high-performance git-backed file system that: * - Reads files directly from git object storage (`git cat-file --batch`) * - Provides export-level metadata and history for public APIs * - Supports cloning remote repos into a local cache (including sparse checkouts) * - Avoids loading file contents during module resolution (extension/index probing) * - Reuses parsed exports by blob SHA to avoid repeat parsing */ import type { AnalysisOptions } from '../analysis/types.ts'; import { type JavaScriptLikeExtension } from '../utils/is-javascript-like-extension.ts'; import type { TypeFilter } from '../utils/resolve-type.ts'; import type { ResolvedTypeAtLocationResult } from '../utils/resolve-type-at-location.ts'; import type { ResolvedFileExportsResult } from '../utils/resolve-file-exports.ts'; import type { SyntaxKind } from '../utils/ts-morph.ts'; import { BaseFileSystem, type FileReadableStream, type FileSystemOptions, type FileSystemWriteFileContent, type FileWritableStream, type AsyncFileSystem, type SyncFileSystem, type WritableFileSystem } from './FileSystem.ts'; import type { DirectoryEntry, GitMetadata, GitExportMetadata, GitFileMetadata, GitModuleMetadata, GitPathMetadata, ExportHistoryOptions, ExportHistoryGenerator } from './types.ts'; import type { Cache } from './Cache.ts'; export interface GitFileSystemOptions extends FileSystemOptions { /** * Repository source - remote URL or local path. * Only pass values you control. * If an attacker can choose this value, they can decide which repository the * server opens: * - local paths and `file://` URLs can make the server read another local repo * - remote URLs can make the server fetch or clone an attacker-chosen repo * This is a repository-selection trust boundary, not a shell-execution path. */ repository: string; /** The Git reference to use. */ ref?: string; /** Sparse checkout directories for large repositories. */ sparse?: string[]; /** Shallow clone depth (undefined = full history). */ depth?: number; /** The directory to use for cached clones and metadata. */ cacheDirectory?: string; /** The transport to use for cloning. */ transport?: 'https' | 'ssh'; /** Whether to automatically fetch the repository. */ autoFetch?: boolean; /** The remote to fetch from. */ fetchRemote?: string; /** Whether to print verbose output. */ verbose?: boolean; /** The maximum number of bytes to buffer for Git commands. */ maxBufferBytes?: number; /** The maximum depth to traverse for export history. */ maxDepth?: number; /** Optional cache provider for this filesystem's internal caches. */ cache?: Cache; } interface PrepareRepoOptions { spec: string; cacheDirectory: string; scopeDirectories?: string[]; transport?: 'https' | 'ssh'; depth?: number; verbose?: boolean; } /** * Ensures a local cached git clone exists for a remote spec (owner/repo or URL). * Clones if missing and returns the repo root. */ export declare function ensureCacheClone(options: PrepareRepoOptions): Promise; export declare function ensureCacheCloneSync(options: PrepareRepoOptions): string; export declare class GitFileSystem extends BaseFileSystem implements AsyncFileSystem, SyncFileSystem, WritableFileSystem { #private; readonly repository: string; readonly cloneDepth?: number; readonly repositoryIsRemote: boolean; repoRoot: string; readonly ref: string; readonly cacheDirectory: string; readonly verbose: boolean; readonly maxBufferBytes: number; readonly maxDepth: number; readonly autoPrepare: boolean; readonly prepareScopeDirectories: string[]; readonly prepareTransport: 'https' | 'ssh'; readonly autoFetch: boolean; readonly fetchRemote: string; constructor(options: GitFileSystemOptions); usesPersistentCacheByDefault(): boolean; supportsServerManagedReferenceArtifacts(): boolean; usesDirectoryMtimeSnapshotDependencies(): boolean; validatesPersistedFileDependenciesByDefault(): boolean; getAnalysisScopeId(): string | undefined; getAnalysisCacheMetadata(): AnalysisOptions; prepareAnalysis(filePath: string): Promise<{ filePath: string; analysisOptions: AnalysisOptions; }>; getFileExports(filePath: string): Promise; resolveFileExportsWithDependencies(filePath: string, filter?: TypeFilter): Promise; getFileExportMetadata(name: string, filePath: string, position: number, kind: SyntaxKind): Promise; getFileExportText(filePath: string, position: number, kind: SyntaxKind, includeDependencies?: boolean): Promise; getOutlineRanges(filePath: string): Promise; getFileExportStaticValue(filePath: string, position: number, kind: SyntaxKind): Promise; resolveTypeAtLocationWithDependencies(filePath: string, position: number, kind: SyntaxKind, filter?: TypeFilter): Promise; resolveTypeAtLocation(filePath: string, position: number, kind: SyntaxKind, filter?: TypeFilter): Promise; getGitFileMetadata(path: string): Promise; getGitExportMetadata(path: string, _startLine: number, _endLine: number): Promise; getAbsolutePath(path: string): string; getRelativePathToWorkspace(path: string): string; getWorkspaceChangeToken(rootPath: string): Promise; getWorkspaceChangedPathsSinceToken(rootPath: string, previousToken: string): Promise; readDirectorySync(path?: string): DirectoryEntry[]; readDirectory(path?: string): Promise; readFileSync(path: string): string; readFile(path: string): Promise; readFileBinarySync(path: string): Uint8Array; readFileBinary(path: string): Promise; readFileStream(path: string): FileReadableStream; getFileByteLengthSync(path: string): number | undefined; getFileByteLength(path: string): Promise; getContentId(path: string): Promise; writeFileSync(path: string, content: FileSystemWriteFileContent): void; writeFile(path: string, content: FileSystemWriteFileContent): Promise; writeFileStream(path: string): FileWritableStream; fileExistsSync(path: string): boolean; fileExists(path: string): Promise; getFileLastModifiedMsSync(path: string): number | undefined; getFileLastModifiedMs(path: string): Promise; deleteFileSync(path: string): void; deleteFile(path: string): Promise; createDirectory(path: string): Promise; rename(source: string, target: string, options?: { overwrite?: boolean; }): Promise; copy(source: string, target: string, options?: { overwrite?: boolean; }): Promise; isFilePathGitIgnored(filePath: string): boolean; close(): void; [Symbol.dispose](): void; /** Get the export history of a repository based on a set of entry files. */ getExportHistory(options?: ExportHistoryOptions): ExportHistoryGenerator; /** Get metadata for a file or module. */ getMetadata( /** The path to the file or module. */ filePath: Path): Promise>; /** Get metadata for a file. */ getFileMetadata(filePath: string): Promise; /** Get metadata for a JavaScript module file (exports at current ref only). */ getModuleMetadata(filePath: string, options?: { includeAuthors?: boolean; }): Promise; } type MetadataForPath

= string extends P ? GitPathMetadata : P extends `${string}.${JavaScriptLikeExtension}` ? GitModuleMetadata : GitFileMetadata; export {};