UNPKG

giga-code

Version:

A personal AI CLI assistant powered by Grok for local development.

202 lines 7.55 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RAGConfigManager = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const DEFAULT_RAG_CONFIG = { enabled: true, embeddingProvider: 'gemini', embeddingModel: 'gemini-embedding-001', searchThreshold: 0.40, maxResults: 5, chunkingStrategy: 'logical', maxFileSizeKB: 500, maxDirectorySizeMB: 50, maxFiles: 1000, includePatterns: [ '**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', '**/*.py', '**/*.java', '**/*.cpp', '**/*.c', '**/*.h', '**/*.go', '**/*.rs', '**/*.php', '**/*.rb', '**/*.swift', '**/*.kt', '**/*.cs', '**/*.scala', '**/*.clj', '**/*.sh', '**/*.yml', '**/*.yaml', '**/*.json', '**/*.md', '**/*.txt' ], excludePatterns: [ '**/node_modules/**', '**/dist/**', '**/build/**', '**/.git/**', '**/coverage/**', '**/target/**', '**/bin/**', '**/obj/**', '**/.next/**', '**/.nuxt/**', '**/vendor/**', '**/__pycache__/**', '**/*.min.js', '**/*.min.css', '**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml' ] }; class RAGConfigManager { static getConfigPath(projectPath = process.cwd()) { return path.join(projectPath, '.giga', 'rag-config.json'); } static getGigaDirPath(projectPath = process.cwd()) { return path.join(projectPath, '.giga'); } static ensureGigaDirectory(projectPath = process.cwd()) { const gigaDir = this.getGigaDirPath(projectPath); if (!fs.existsSync(gigaDir)) { fs.mkdirSync(gigaDir, { recursive: true }); } } static loadConfig(projectPath = process.cwd()) { const configPath = this.getConfigPath(projectPath); try { if (fs.existsSync(configPath)) { const configFile = fs.readFileSync(configPath, 'utf-8'); const userConfig = JSON.parse(configFile); // Merge with defaults to ensure all properties exist return { ...DEFAULT_RAG_CONFIG, ...userConfig, // Ensure arrays are properly merged includePatterns: userConfig.includePatterns || DEFAULT_RAG_CONFIG.includePatterns, excludePatterns: userConfig.excludePatterns || DEFAULT_RAG_CONFIG.excludePatterns }; } } catch (error) { console.warn('Failed to load RAG config, using defaults:', error); } return { ...DEFAULT_RAG_CONFIG }; } static saveConfig(config, projectPath = process.cwd()) { try { this.ensureGigaDirectory(projectPath); const configPath = this.getConfigPath(projectPath); fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8'); } catch (error) { console.error('Failed to save RAG config:', error); throw error; } } static updateConfig(updates, projectPath = process.cwd()) { const currentConfig = this.loadConfig(projectPath); const newConfig = { ...currentConfig, ...updates }; this.saveConfig(newConfig, projectPath); return newConfig; } static getDefaultConfig() { return { ...DEFAULT_RAG_CONFIG }; } static isRAGEnabled(projectPath = process.cwd()) { const config = this.loadConfig(projectPath); return config.enabled; } static enableRAG(projectPath = process.cwd()) { this.updateConfig({ enabled: true }, projectPath); } static disableRAG(projectPath = process.cwd()) { this.updateConfig({ enabled: false }, projectPath); } static hasGigaDirectory(projectPath = process.cwd()) { return fs.existsSync(this.getGigaDirPath(projectPath)); } static hasRAGConfig(projectPath = process.cwd()) { return fs.existsSync(this.getConfigPath(projectPath)); } static initializeProject(projectPath = process.cwd()) { this.ensureGigaDirectory(projectPath); const config = this.loadConfig(projectPath); if (!this.hasRAGConfig(projectPath)) { this.saveConfig(config, projectPath); } return config; } static validateConfig(config) { const errors = []; if (config.embeddingProvider && !['gemini', 'openai'].includes(config.embeddingProvider)) { errors.push('embeddingProvider must be either "gemini" or "openai"'); } if (config.searchThreshold !== undefined && (config.searchThreshold < 0 || config.searchThreshold > 1)) { errors.push('searchThreshold must be between 0 and 1'); } if (config.maxResults !== undefined && (config.maxResults < 1 || config.maxResults > 50)) { errors.push('maxResults must be between 1 and 50'); } if (config.chunkingStrategy && !['logical', 'fixed'].includes(config.chunkingStrategy)) { errors.push('chunkingStrategy must be either "logical" or "fixed"'); } if (config.includePatterns && !Array.isArray(config.includePatterns)) { errors.push('includePatterns must be an array of strings'); } if (config.excludePatterns && !Array.isArray(config.excludePatterns)) { errors.push('excludePatterns must be an array of strings'); } return { valid: errors.length === 0, errors }; } static getConfigSummary(projectPath = process.cwd()) { const config = this.loadConfig(projectPath); const hasConfig = this.hasRAGConfig(projectPath); return `RAG Configuration ${hasConfig ? '(from .giga/rag-config.json)' : '(defaults)'}: • Status: ${config.enabled ? '✅ Enabled' : '❌ Disabled'} • Provider: ${config.embeddingProvider} (${config.embeddingModel}) • Search Threshold: ${config.searchThreshold} • Max Results: ${config.maxResults} • Chunking: ${config.chunkingStrategy} • Include Patterns: ${config.includePatterns.length} patterns • Exclude Patterns: ${config.excludePatterns.length} patterns`; } } exports.RAGConfigManager = RAGConfigManager; //# sourceMappingURL=rag-config.js.map