All files / core config.ts

32% Statements 8/25
100% Branches 0/0
26.08% Functions 6/23
32% Lines 8/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 1131x     1x   20x       4x                       4x                                                                                                                       4x       4x       4x                                              
import * as vscode from 'vscode';
import { MananKanchuConfig } from './interfaces';
 
export class MananKanchuConfigManager {
  private get cfg() {
    return vscode.workspace.getConfiguration('manan-kanchu');
  }
 
  get preferredProvider(): string {
    return this.cfg.get<string>('preferredProvider', 'auto');
  }
 
  get maxTokens(): number {
    return this.cfg.get<number>('maxTokens', 4096);
  }
 
  get temperature(): number {
    return this.cfg.get<number>('temperature', 0.1);
  }
 
  get requestTimeout(): number {
    return this.cfg.get<number>('requestTimeout', 120000);
  }
 
  get detectionThreshold(): number {
    return this.cfg.get<number>('detection.threshold', 0.65);
  }
 
  get heuristicWeight(): number {
    return this.cfg.get<number>('detection.heuristicWeight', 0.4);
  }
 
  get aiWeight(): number {
    return this.cfg.get<number>('detection.aiWeight', 0.6);
  }
 
  get excludePatterns(): string[] {
    return this.cfg.get<string[]>('scan.excludePatterns', [
      'node_modules', 'dist', 'out', '.git', '*.min.js', '*.min.css'
    ]);
  }
 
  get maxFileSizeKB(): number {
    return this.cfg.get<number>('scan.maxFileSizeKB', 512);
  }
 
  get activePolicies(): string[] {
    return this.cfg.get<string[]>('policies', [
      'no-hardcoded-secrets', 'no-eval', 'no-innerHTML', 'license-compliance'
    ]);
  }
 
  get privacyTelemetry(): boolean {
    return this.cfg.get<boolean>('privacy.telemetry', false);
  }
 
  get anthropicModel(): string {
    return this.cfg.get<string>('anthropic.model', 'claude-sonnet-4-6');
  }
 
  get anthropicBaseUrl(): string {
    return this.cfg.get<string>('anthropic.baseUrl', 'https://api.anthropic.com/v1');
  }
 
  get openaiModel(): string {
    return this.cfg.get<string>('openai.model', 'gpt-4o');
  }
 
  get openaiBaseUrl(): string {
    return this.cfg.get<string>('openai.baseUrl', 'https://api.openai.com/v1');
  }
 
  get geminiModel(): string {
    return this.cfg.get<string>('gemini.model', 'gemini-1.5-pro');
  }
 
  get geminiBaseUrl(): string {
    return this.cfg.get<string>('gemini.baseUrl', 'https://generativelanguage.googleapis.com/v1beta');
  }
 
  get ollamaEndpoint(): string {
    return this.cfg.get<string>('ollama.endpoint', 'http://localhost:11434');
  }
 
  get ollamaModel(): string {
    return this.cfg.get<string>('ollama.model', 'codellama');
  }
 
  get lmstudioEndpoint(): string {
    return this.cfg.get<string>('lmstudio.endpoint', 'http://localhost:1234');
  }
 
  toConfig(): MananKanchuConfig {
    return {
      preferredProvider: this.preferredProvider,
      maxTokens: this.maxTokens,
      temperature: this.temperature,
      requestTimeout: this.requestTimeout,
      detectionThreshold: this.detectionThreshold,
      heuristicWeight: this.heuristicWeight,
      aiWeight: this.aiWeight,
      excludePatterns: this.excludePatterns,
      maxFileSizeKB: this.maxFileSizeKB,
      activePolicies: this.activePolicies,
      privacyTelemetry: this.privacyTelemetry,
    };
  }
 
  async updateSetting(key: string, value: unknown): Promise<void> {
    await this.cfg.update(key, value, vscode.ConfigurationTarget.Global);
  }
}