/** * Worker-safe configuration utilities * No file system operations, only in-memory config handling */ interface CodefetchConfig$1 { format: "markdown" | "json"; extensions: string[]; excludeFiles: string[]; includeFiles: string[]; excludeDirs: string[]; includeDirs: string[]; verbose: number; projectTree: number; projectTreeSkipIgnoreFiles?: boolean; dryRun: boolean; maxTokens: number; tokenEncoder: string; disableLineNumbers: boolean; defaultIgnore: boolean; gitignore: boolean; tokenLimiter: string; tokenCountOnly: boolean; noSummary?: boolean; promptFile?: string; prompt?: string; templateVars: Record; } /** * Get default configuration for Workers */ declare function getDefaultConfig(): CodefetchConfig$1; /** * Resolve configuration in Workers (no file system) */ declare function resolveCodefetchConfig(cwd?: string, overrides?: Partial): Promise; /** * Merge configuration with CLI arguments */ declare function mergeWithCliArgs(config: CodefetchConfig$1, args: any): CodefetchConfig$1; /** * Runtime environment detection for Cloudflare Workers */ /** * Detect if code is running in a Cloudflare Worker environment * Workers have WebSocketPair but no __dirname in globalThis */ declare const isCloudflareWorker: boolean; /** * Get environment-specific cache size limit in bytes */ declare const getCacheSizeLimit: () => number; type TokenEncoder = "simple" | "p50k" | "o200k" | "cl100k"; type TokenLimiter = "sequential" | "truncated"; interface FileNode { name: string; path: string; type: "file" | "directory"; content?: string; language?: string; size?: number; tokens?: number; lastModified?: Date; children?: FileNode[]; } interface PerformanceMetrics { fetchDuration: number; parseFiles: number; tokenCountDuration: number; totalDuration: number; memoryUsed?: number; } interface FetchMetadata { totalFiles: number; totalSize: number; totalTokens: number; fetchedAt: Date; source: string; gitProvider?: string; gitOwner?: string; gitRepo?: string; gitRef?: string; metrics?: PerformanceMetrics; } interface FetchResult { root: FileNode; metadata: FetchMetadata; } type OutputFormat = "markdown" | "json"; /** * Worker-safe type definitions * These types are duplicated here to avoid importing from modules with Node.js dependencies */ type CacheStrategy$1 = "auto" | "force" | "bypass" | "refresh" | "validate"; interface FetchOptions$1 extends Partial { source?: string; format?: OutputFormat; cache?: boolean | CacheStrategy$1; cacheKey?: string; cacheTTL?: number; cacheNamespace?: string; cacheBaseUrl?: string; noCache?: boolean; } declare class FetchResultImpl { root: FileNode; metadata: FetchMetadata; constructor(root: FileNode, metadata: FetchMetadata); /** * Get a file node by its path */ getFileByPath(path: string): FileNode | null; /** * Get all files as a flat array */ getAllFiles(): FileNode[]; /** * Convert to markdown format */ toMarkdown(): string; /** * Build tree string representation */ private buildTreeString; } /** * Cloudflare Worker-compatible web fetch implementation * Works with in-memory content instead of file system operations */ /** * Fetch web content in a Worker-compatible way */ declare function fetchFromWebWorker(url: string, options?: FetchOptions$1): Promise; /** * Worker-compatible markdown generation from file content objects */ interface FileContent { path: string; content: string; language?: string; mimeType?: string; size?: number; tokens?: number; encoding?: string; } interface MarkdownFromContentOptions { maxTokens?: number; includeTreeStructure?: boolean; tokenEncoder?: TokenEncoder; disableLineNumbers?: boolean; } /** * Generate markdown from file content objects (Worker-compatible) * This function doesn't require filesystem access */ declare function generateMarkdownFromContent(files: FileContent[], options?: MarkdownFromContentOptions): Promise; /** * Streaming API support for handling large repositories efficiently */ interface StreamOptions { maxTokens?: number; tokenEncoder?: TokenEncoder; extensions?: string[]; excludeDirs?: string[]; includeTreeStructure?: boolean; } declare function streamGitHubFiles$1(owner: string, repo: string, options?: StreamOptions & { branch?: string; token?: string; }): AsyncGenerator; /** * Create a ReadableStream that generates markdown from files * This allows streaming markdown generation for large codebases */ declare function createMarkdownStream(files: AsyncIterable, options?: MarkdownFromContentOptions): ReadableStream; /** * Stream processing with transform - allows processing files as they stream */ declare function createTransformStream(transform: (file: FileContent) => Promise | T): TransformStream; /** * Helper to collect streamed files into an array */ declare function collectStream(stream: AsyncIterable): Promise; /** * Stream filter - only pass through files that match predicate */ declare function filterStream(stream: AsyncIterable, predicate: (item: T) => boolean | Promise): AsyncGenerator; /** * Stream map - transform each item in the stream */ declare function mapStream(stream: AsyncIterable, mapper: (item: T) => U | Promise): AsyncGenerator; /** * GitHub tarball streaming for Cloudflare Workers * Uses native DecompressionStream and lightweight tar parsing */ /** * Stream and process GitHub tarball, yielding files one by one. */ declare function streamGitHubFiles(owner: string, repo: string, ref?: string, options?: { token?: string; extensions?: string[]; excludeDirs?: string[]; maxFiles?: number; onProgress?: (processed: number) => void; }): AsyncGenerator; /** * GitLab tarball streaming for Cloudflare Workers * Uses native DecompressionStream and lightweight tar parsing */ /** * Stream files from a GitLab repository tarball. */ declare function streamGitLabFiles(owner: string, repo: string, ref?: string, options?: { token?: string; extensions?: string[]; excludeDirs?: string[]; maxFiles?: number; onProgress?: (processed: number) => void; }): AsyncGenerator; /** * Browser-compatible HTML to Markdown converter * Designed for Cloudflare Workers without external dependencies */ interface HtmlToMarkdownOptions { /** Whether to include link URLs inline */ includeUrls?: boolean; /** Whether to preserve whitespace */ preserveWhitespace?: boolean; /** Custom replacements */ customReplacements?: Array<{ pattern: RegExp; replacement: string; }>; } /** * Convert HTML string to Markdown format * This is a lightweight implementation suitable for Worker environments */ declare function htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions): string; declare const countTokens: (text: string, encoder: TokenEncoder) => Promise; declare const VALID_PROMPTS: Set; declare const VALID_ENCODERS: Set; declare const VALID_LIMITERS: Set; declare const _default$3: "You are a senior developer. You produce optimized, maintainable code that follows best practices. \n\nYour task is to write code according to my instructions for the current codebase.\n\ninstructions:\n\n{{MESSAGE}}\n\n\nRules:\n- Keep your suggestions concise and focused. Avoid unnecessary explanations or fluff. \n- Your output should be a series of specific, actionable changes.\n\nWhen approaching this task:\n1. Carefully review the provided code.\n2. Identify the area thats raising this issue or error and provide a fix.\n3. Consider best practices for the specific programming language used.\n\nFor each suggested change, provide:\n1. A short description of the change (one line maximum).\n2. The modified code block.\n\nUse the following format for your output:\n\n[Short Description]\n```[language]:[path/to/file]\n[code block]\n```\n\nBegin fixing the codebase provide your solutions.\n\nMy current codebase:\n\n{{CURRENT_CODEBASE}}\n\n"; declare const _default$2: "You are a senior developer. You produce optimized, maintainable code that follows best practices. \n\nYour task is to review the current codebase and fix the current issues.\n\nCurrent Issue:\n\n{{MESSAGE}}\n\n\nRules:\n- Keep your suggestions concise and focused. Avoid unnecessary explanations or fluff. \n- Your output should be a series of specific, actionable changes.\n\nWhen approaching this task:\n1. Carefully review the provided code.\n2. Identify the area thats raising this issue or error and provide a fix.\n3. Consider best practices for the specific programming language used.\n\nFor each suggested change, provide:\n1. A short description of the change (one line maximum).\n2. The modified code block.\n\nUse the following format for your output:\n\n[Short Description]\n```[language]:[path/to/file]\n[code block]\n```\n\nBegin fixing the codebase provide your solutions.\n\nMy current codebase:\n\n{{CURRENT_CODEBASE}}\n\n"; declare const _default$1: "You are a senior software architect. You produce optimized, maintainable code that follows best practices. \n\nYour task is to review the current codebase and suggest improvements or optimizations.\n\nRules:\n- Keep your suggestions concise and focused. Avoid unnecessary explanations or fluff. \n- Your output should be a series of specific, actionable changes.\n\nWhen approaching this task:\n1. Carefully review the provided code.\n2. Identify areas that could be improved in terms of efficiency, readability, or maintainability.\n3. Consider best practices for the specific programming language used.\n4. Think about potential optimizations that could enhance performance.\n5. Look for opportunities to refactor or restructure the code for better organization.\n\nFor each suggested change, provide:\n1. A short description of the change (one line maximum).\n2. The modified code block.\n\nUse the following format for your output:\n\n[Short Description]\n```[language]:[path/to/file]\n[code block]\n```\n\nBegin your analysis and provide your suggestions now.\n\nMy current codebase:\n\n{{CURRENT_CODEBASE}}\n\n"; declare const _default: "You are a senior test developer. You produce optimized, maintainable code that follows best practices. \n\nYour task is to review the current codebase and create and improve missing tests for the codebase.\n\nAdditional instructions:\n\n{{MESSAGE}}\n\n\nRules:\n- Keep your suggestions concise and focused. Avoid unnecessary explanations or fluff. \n- Your output should be a series of specific, actionable changes.\n\nWhen approaching this task:\n1. Carefully review the provided code.\n2. Identify the area thats raising this issue or error and provide a fix.\n3. Consider best practices for the specific programming language used.\n\nFor each suggested change, provide:\n1. A short description of the change (one line maximum).\n2. The modified code block.\n\nUse the following format for your output:\n\n[Short Description]\n```[language]:[path/to/file]\n[code block]\n```\n\nBegin fixing the codebase provide your solutions.\n\nMy current codebase:\n\n{{CURRENT_CODEBASE}}\n\n"; declare const prompts: { codegen: string; fix: string; improve: string; testgen: string; }; declare const index_prompts: typeof prompts; declare namespace index { export { _default$3 as codegenPrompt, prompts as default, _default$2 as fixPrompt, _default$1 as improvePrompt, index_prompts as prompts, _default as testgenPrompt }; } interface CodefetchConfig { outputFile: string; outputPath: string; maxTokens: number; includeFiles?: string[]; excludeFiles?: string[]; includeDirs?: string[]; excludeDirs?: string[]; verbose: number; extensions?: string[]; defaultIgnore: boolean; gitignore: boolean; projectTree: number; projectTreeSkipIgnoreFiles: boolean; tokenEncoder: TokenEncoder; tokenLimiter: TokenLimiter; trackedModels?: string[]; dryRun?: boolean; disableLineNumbers?: boolean; tokenCountOnly?: boolean; noSummary?: boolean; defaultPromptFile: string; inlinePrompt?: string; defaultChat?: string; templateVars?: Record; format?: OutputFormat; excludeMarkdown?: boolean; } type CacheStrategy = "auto" | "force" | "bypass" | "refresh" | "validate"; interface FetchOptions extends Partial { source?: string; format?: OutputFormat; cache?: boolean | CacheStrategy; cacheKey?: string; cacheTTL?: number; cacheNamespace?: string; cacheBaseUrl?: string; noCache?: boolean; excludeMarkdown?: boolean; } /** * Enhanced cache integration for Cloudflare Workers * Supports both Cache API and KV namespaces */ interface CacheOptions { cacheKey?: string; ttl?: number; cacheBehavior?: "force-cache" | "no-cache" | "default"; namespace?: string; } interface CacheStorage { type: "cache-api" | "kv"; instance: Cache | KVNamespace; } /** * Fetch from web with caching support */ declare function fetchFromWebCached(source: string, options?: FetchOptions & { cache?: CacheOptions; }, cacheStorage?: CacheStorage): Promise; /** * Delete a specific cache entry */ declare function deleteFromCache(cacheStorage: CacheStorage, key: string): Promise; /** * Clear all cache entries matching a pattern */ declare function clearCache(cacheStorage: CacheStorage, pattern?: string): Promise; /** * Helper to create cache storage from Cloudflare bindings */ declare function createCacheStorage(cacheOrKV: Cache | KVNamespace): CacheStorage; /** * Decorator to add caching to any async function */ declare function withCache Promise>(fn: T, getCacheKey: (...args: Parameters) => string, ttl?: number): T; /** * Browser-safe utility functions * These functions do not depend on any Node.js APIs */ declare const detectLanguage: (fileName: string) => string; /** * Type guards and branded types for improved type safety */ type GitHubToken = string & { __brand: "GitHubToken"; }; type RepoPath = `${string}/${string}` & { __brand: "RepoPath"; }; type GitHubUrl = `https://github.com/${RepoPath}` & { __brand: "GitHubUrl"; }; type SemVer = `${number}.${number}.${number}` & { __brand: "SemVer"; }; /** * Type guard to check if a string is a valid GitHub URL */ declare function isValidGitHubUrl(url: string): url is GitHubUrl; /** * Type guard to check if a string is a valid repository path */ declare function isValidRepoPath(path: string): path is RepoPath; /** * Type guard to check if a token is a valid GitHub token format */ declare function isValidGitHubToken(token: string): token is GitHubToken; /** * Type guard to check if a string is a valid semantic version */ declare function isValidSemVer(version: string): version is SemVer; /** * Create a branded GitHub token (with validation) */ declare function createGitHubToken(token: string): GitHubToken; /** * Create a branded repo path (with validation) */ declare function createRepoPath(owner: string, repo: string): RepoPath; /** * Create a branded GitHub URL (with validation) */ declare function createGitHubUrl(owner: string, repo: string): GitHubUrl; /** * Type guard for non-nullable values */ declare function isNotNull(value: T | null | undefined): value is T; /** * Type guard for arrays */ declare function isArray(value: unknown): value is T[]; /** * Type guard for objects */ declare function isObject(value: unknown): value is Record; /** * Type guard for strings */ declare function isString(value: unknown): value is string; /** * Type guard for numbers */ declare function isNumber(value: unknown): value is number; /** * Assert that a value is defined (throws if not) */ declare function assertDefined(value: T | null | undefined, message?: string): asserts value is T; /** * Assert that a condition is true (throws if not) */ declare function assert(condition: unknown, message?: string): asserts condition; /** * Exhaustive check for switch statements */ declare function exhaustiveCheck(value: never): never; /** * Custom error classes for better error handling and debugging */ /** * Base error class for all Codefetch errors */ declare class CodefetchError extends Error { code: string; constructor(message: string, code: string); } /** * Error thrown when GitHub API requests fail */ declare class GitHubError extends CodefetchError { status: number; rateLimitRemaining?: number | undefined; rateLimitReset?: Date | undefined; constructor(message: string, status: number, rateLimitRemaining?: number | undefined, rateLimitReset?: Date | undefined); } /** * Error thrown when token limit is exceeded */ declare class TokenLimitError extends CodefetchError { limit: number; used: number; files: string[]; constructor(limit: number, used: number, files: string[]); } /** * Error thrown when parsing files or content fails */ declare class ParseError extends CodefetchError { filePath: string; line?: number | undefined; column?: number | undefined; constructor(message: string, filePath: string, line?: number | undefined, column?: number | undefined); } /** * Error thrown when network requests fail */ declare class NetworkError extends CodefetchError { url: string; cause?: Error | undefined; constructor(message: string, url: string, cause?: Error | undefined); } /** * Error thrown when configuration is invalid */ declare class ConfigError extends CodefetchError { configPath?: string | undefined; invalidField?: string | undefined; constructor(message: string, configPath?: string | undefined, invalidField?: string | undefined); } /** * Error thrown when cache operations fail */ declare class CacheError extends CodefetchError { operation: "read" | "write" | "delete"; key?: string | undefined; constructor(message: string, operation: "read" | "write" | "delete", key?: string | undefined); } /** * Error thrown when URL validation fails */ declare class URLValidationError extends CodefetchError { url: string; reason: string; constructor(message: string, url: string, reason: string); } /** * Type guard to check if an error is a CodefetchError */ declare function isCodefetchError(error: unknown): error is CodefetchError; /** * Type guard to check if an error is a GitHubError */ declare function isGitHubError(error: unknown): error is GitHubError; /** * Type guard to check if an error is a TokenLimitError */ declare function isTokenLimitError(error: unknown): error is TokenLimitError; /** * Helper to wrap unknown errors in a CodefetchError */ declare function wrapError(error: unknown, code?: string): CodefetchError; export { CacheError, type CodefetchConfig$1 as CodefetchConfig, CodefetchError, ConfigError, type FetchMetadata, type FetchResult, FetchResultImpl, type FileContent, type FileNode, GitHubError, NetworkError, ParseError, TokenLimitError, URLValidationError, VALID_ENCODERS, VALID_LIMITERS, VALID_PROMPTS, assert, assertDefined, clearCache, _default$3 as codegenPrompt, collectStream, countTokens, createCacheStorage, createGitHubToken, createGitHubUrl, createMarkdownStream, createRepoPath, createTransformStream, deleteFromCache, detectLanguage, exhaustiveCheck, fetchFromWebWorker as fetch, fetchFromWebWorker as fetchFromWeb, fetchFromWebCached, filterStream, _default$2 as fixPrompt, generateMarkdownFromContent, getCacheSizeLimit, getDefaultConfig, htmlToMarkdown, _default$1 as improvePrompt, isArray, isCloudflareWorker, isCodefetchError, isGitHubError, isNotNull, isNumber, isObject, isString, isTokenLimitError, isValidGitHubToken, isValidGitHubUrl, isValidRepoPath, isValidSemVer, mapStream, mergeWithCliArgs, index as prompts, resolveCodefetchConfig, streamGitHubFiles$1 as streamGitHubFiles, streamGitHubFiles as streamGitHubTarball, streamGitLabFiles, _default as testgenPrompt, withCache, wrapError };