/** * Smart Environment Variable Tool * * Features: * - Parse and validate .env files * - Detect missing required variables * - Cache env configs with 1-hour TTL * - Environment-specific suggestions (dev/staging/prod) * - Security issue detection (exposed secrets, weak configs) * - File hash-based invalidation */ import { CacheEngine } from '../../core/cache-engine.js'; import type { TokenCounter } from '../../core/token-counter.js'; import type { MetricsCollector } from '../../core/metrics.js'; export interface SmartEnvOptions { envFile?: string; envContent?: string; checkSecurity?: boolean; suggestMissing?: boolean; environment?: 'development' | 'staging' | 'production'; requiredVars?: string[]; includeLocations?: boolean; force?: boolean; ttl?: number; } export interface EnvVariable { key: string; /** * INTERNAL ONLY. Present while parsing, because the security checks genuinely * need it -- weak-password detection, localhost URLs, unquoted whitespace -- * but the response carries no value field at all. See {@link tabulate}. */ value: string; line: number; hasQuotes: boolean; isEmpty: boolean; } /** * The fields a row holds when the caller asked where each variable is. */ export declare const ENV_LOCATED_COLUMNS: readonly ["key", "line", "length"]; /** * The fields a row holds by default: the name, and nothing else. * * MEASURED, AND IT IS WHY THIS TOOL USED TO LOSE ON EVERY FIXTURE. On the * 48-variable fixture the two extra numbers were 242 of 538 tokens -- 45% of * the report -- and they moved the reading from +39.0% against the file to * -10.9%, a tool that cost more than reading the thing it summarised. Both * numbers answer "where is it", which is a question about editing the file, * not about what is configured in it; the caller that is about to edit asks * for them with `includeLocations` and pays for them then. */ export declare const ENV_KEY_COLUMNS: readonly ["key"]; export type EnvVariableColumn = (typeof ENV_LOCATED_COLUMNS)[number]; /** * One variable: its name alone, or its name with the line it is on and the * characters its value had. The width is the caller's choice, so it is read * from `columns` rather than assumed. */ export type EnvVariableRow = [string] | [string, number, number]; /** * The variables, as a table rather than a list of objects. * * An array of objects repeats every field name once per variable. On the * 48-variable fixture that was 48 copies of "key", "line", "length", * "hasQuotes", "isEmpty" and "value" -- 157 tokens of field names, and 48 * copies of the same "[redacted]" placeholder, for 48 rows of data. Naming each * field once costs the same information a third as much, so the report gets * smaller without anything being dropped from it. * * `quoted` and `empty` name only the variables the flag is TRUE of, which in a * real .env is almost none of them. An absent list means no variable has that * property. */ export interface EnvVariableTable { columns: EnvVariableColumn[]; rows: EnvVariableRow[]; quoted?: string[]; empty?: string[]; } export interface SecurityIssue { severity: 'critical' | 'high' | 'medium' | 'low'; variable: string; issue: string; recommendation: string; line?: number; } export interface MissingVariable { name: string; description: string; defaultValue?: string; required: boolean; } export interface SmartEnvResult { success: boolean; environment: string; variables: { total: number; loaded: number; empty: number; commented: number; }; parsed?: EnvVariableTable; missing?: MissingVariable[]; security?: { score: number; issues: SecurityIssue[]; hasSecrets: boolean; }; suggestions?: string[]; metadata: { /** The file's sha256, shortened by {@link shortHash}. */ fileHash?: string; filePath?: string; cached: boolean; }; } export declare class SmartEnv { private cache; private metrics; constructor(cache: CacheEngine, _tokenCounter: TokenCounter, metrics: MetricsCollector); /** * Main entry point for environment analysis */ run(options: SmartEnvOptions): Promise; /** * Get environment content from file or direct input */ private getEnvContent; /** * Parse .env file content into structured variables */ private parseEnvContent; /** * Analyze environment variables and generate insights */ private analyzeEnvironment; /** * Detect environment type from variable names */ private detectEnvironment; /** * Detect missing required variables */ private detectMissingVariables; /** * Get common variables for environment type */ private getCommonVariables; /** * Analyze security issues in environment variables */ private analyzeSecurityIssues; /** * Generate helpful suggestions */ private generateSuggestions; /** * Generate cache key */ private generateCacheKey; /** * Get cached result */ private getCached; /** * Cache result */ private cacheResult; } export declare function getSmartEnv(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartEnv; export declare function runSmartEnv(options: SmartEnvOptions): Promise; export declare const SMART_ENV_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: "object"; properties: { envFile: { type: string; description: string; }; envContent: { type: string; description: string; }; checkSecurity: { type: string; description: string; default: boolean; }; suggestMissing: { type: string; description: string; default: boolean; }; environment: { type: string; enum: string[]; description: string; }; requiredVars: { type: string; items: { type: string; }; description: string; }; includeLocations: { type: string; description: string; default: boolean; }; force: { type: string; description: string; default: boolean; }; ttl: { type: string; description: string; default: number; }; }; }; }; //# sourceMappingURL=smart-env.d.ts.map