Implement Config File Loader, Ignore Parser, and Context Loader#25
Merged
Conversation
…t loader
- Load codingbuddy.config.{js,mjs,json} with validation
- Parse .codingignore files with gitignore-style patterns
- Load .codingbuddy/ directory files (context, prompts, agents)
- Add NestJS ConfigService integrating all loaders
- Add comprehensive test coverage
close #20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement Config File Loader, Ignore Parser, and Context Loader
📋 Summary
Implements the file loading infrastructure for CodingBuddy's user configuration system. Adds automatic detection and loading of
codingbuddy.config.{js,mjs,json}files,.codingignoreparsing with gitignore-style patterns, and.codingbuddy/directory context file loading. All components are integrated into a NestJS service for use by the MCP server.Closes #20
✨ Solution
1. Config File Loader (
config.loader.ts)Features:
codingbuddy.config.js→.mjs→.jsonimport()with file:// URL conversionconfig.schema.tsConfigLoadResultwith config, source path, and warningsConfigLoadErrorwith file path and cause for better debuggingKey Functions:
findConfigFile(projectRoot): Finds first available config fileloadConfig(projectRoot): Loads and validates config (returns empty config if not found)loadJsConfig(filePath): Dynamic import for JS/ESM filesloadJsonConfig(filePath): JSON parsing with error handlingvalidateAndTransform(raw, filePath): Zod validation with detailed errors2. Ignore Parser (
ignore.parser.ts)Features:
*,**,?), negation (!), directory-only (/)/dist/matches only at root)!important.logto include despite*.log)Key Functions:
loadIgnoreFile(projectRoot): Loads.codingignorefileparseIgnoreContent(content): Parses ignore file contentpatternToRegex(pattern): Converts gitignore pattern to RegExpshouldIgnore(path, patterns): Checks if path matches ignore patternsfilterIgnored(paths, patterns): Filters array of pathsgetDefaultIgnorePatterns(): Returns common ignore patternsPattern Examples:
node_modules/- Matches node_modules directory anywhere*.log- Matches .log files anywhere/dist/- Matches dist directory only at root**/*.test.ts- Matches .test.ts files at any depth!important.log- Negates previous patterns3. Context Loader (
context.loader.ts)Features:
.codingbuddy/directorycontext/→ Project context filesprompts/→ Custom promptsagents/→ Custom agent configurations.md,.txt,.json,.yaml,.js,.ts,.jsx,.tsxKey Functions:
loadContextFiles(projectRoot): Loads all context filesgetContextFileType(relativePath): Determines file type from pathisLoadableFile(filePath): Checks if file extension is supportedformatContextForAI(files): Formats files into markdown for AIgetFilesByType(files, type): Filters files by typeDirectory Structure:
4. Config Service (
config.service.ts)Features:
ProjectConfiginterface:settings: Main config fromcodingbuddy.config.jsignorePatterns: Combined default + user ignore patternscontextFiles: All loaded context filessources: Metadata about loaded file pathsCODINGBUDDY_PROJECT_ROOTenv var)Key Methods:
loadProjectConfig(): Loads all configuration (called on module init)getProjectConfig(): Returns cached config or loads if not loadedgetSettings(): Returns main config settingsgetIgnorePatterns(): Returns all ignore patternsshouldIgnorePath(path): Checks if path should be ignoredgetContextFiles(): Returns all context filesgetFormattedContext(): Returns formatted context for AIreload(): Forces reload from disk5. NestJS Module (
config.module.ts)ConfigServiceto NestJS dependency injectionConfigServicefor use in other modules🧪 Testing
Test Coverage
Total: 47 tests, all passing ✅
Test Scenarios
Config Loader:
Ignore Parser:
node_modules/)*.log,**/*.test.ts)/dist/)!important.log)Context Loader:
🎯 Benefits
1. Automatic Configuration Discovery
Users don't need to manually specify config file paths. The system automatically finds and loads configuration.
2. Multiple Format Support
Supports JavaScript (for dynamic config) and JSON (for static config), giving users flexibility.
3. Gitignore-Style Ignore Patterns
Familiar syntax that developers already know, reducing learning curve.
4. Rich Context Loading
Allows users to provide additional project context beyond the main config file.
5. Unified Service Interface
Single
ConfigServiceprovides all configuration data, simplifying MCP server integration.📖 Usage Example
✅ Acceptance Criteria
.codingbuddy/