From 27fb3ef90559d785816096159fdd4508a8c14bfd Mon Sep 17 00:00:00 2001 From: David Snelling Date: Tue, 16 Sep 2025 13:18:49 -0700 Subject: [PATCH] feat: add complete silent mode for TUI applications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add silent option to BrainyConfig to suppress ALL console output - Override console methods (log, info, warn, error) when silent=true - Add LogLevel.SILENT to Logger for proper silent mode support - Propagate silent mode to all augmentations automatically - Update augmentation configs to support silent property - Restore console methods properly on brain.close() - Perfect for terminal UI applications that need clean output Usage: ```javascript const brain = new Brainy({ storage: { type: 'filesystem', path: './data' }, silent: true // Complete silence - zero console output }) ``` šŸ¤– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/augmentations/cacheAugmentation.ts | 6 +++ src/augmentations/display/types.ts | 11 +++-- src/augmentations/metricsAugmentation.ts | 1 + .../universalDisplayAugmentation.ts | 9 +++- src/brainy.ts | 49 +++++++++++++++++-- src/utils/logger.ts | 8 ++- 6 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/augmentations/cacheAugmentation.ts b/src/augmentations/cacheAugmentation.ts index ce8cd41f..b1f3096f 100644 --- a/src/augmentations/cacheAugmentation.ts +++ b/src/augmentations/cacheAugmentation.ts @@ -18,6 +18,7 @@ export interface CacheConfig { ttl?: number enabled?: boolean invalidateOnWrite?: boolean + silent?: boolean // Silent mode support } /** @@ -80,6 +81,11 @@ export class CacheAugmentation extends BaseAugmentation { type: 'boolean', default: true, description: 'Automatically invalidate cache on data modifications' + }, + silent: { + type: 'boolean', + default: false, + description: 'Suppress all console output' } }, additionalProperties: false diff --git a/src/augmentations/display/types.ts b/src/augmentations/display/types.ts index da4c4716..a01c7154 100644 --- a/src/augmentations/display/types.ts +++ b/src/augmentations/display/types.ts @@ -12,18 +12,21 @@ import type { VectorDocument, GraphVerb } from '../../coreTypes.js' export interface DisplayConfig { /** Enable/disable the augmentation */ enabled: boolean - + /** LRU cache size for computed display fields */ cacheSize: number - + /** Use lazy computation (recommended for performance) */ lazyComputation: boolean - + /** Batch processing size for multiple requests */ batchSize: number - + /** Minimum confidence threshold for AI type detection */ confidenceThreshold: number + + /** Silent mode - suppress all console output */ + silent?: boolean // No icon configuration needed - clean, minimal approach diff --git a/src/augmentations/metricsAugmentation.ts b/src/augmentations/metricsAugmentation.ts index 7c1569df..f4725594 100644 --- a/src/augmentations/metricsAugmentation.ts +++ b/src/augmentations/metricsAugmentation.ts @@ -28,6 +28,7 @@ export interface MetricsConfig { trackStorageSizes?: boolean persistMetrics?: boolean metricsInterval?: number + silent?: boolean // New: Silent mode support } /** diff --git a/src/augmentations/universalDisplayAugmentation.ts b/src/augmentations/universalDisplayAugmentation.ts index 433b481b..8ff64654 100644 --- a/src/augmentations/universalDisplayAugmentation.ts +++ b/src/augmentations/universalDisplayAugmentation.ts @@ -290,9 +290,14 @@ export class UniversalDisplayAugmentation extends BaseAugmentation { */ private createExploreMethod(entity: any) { return async (): Promise => { + // Respect silent mode + if (this.config.silent) { + return + } + console.log(`\nšŸ“‹ Entity Exploration: ${entity.id || 'unknown'}`) console.log('━'.repeat(50)) - + // Show user data console.log('\nšŸ‘¤ User Data:') const userData = entity.metadata || entity @@ -313,7 +318,7 @@ export class UniversalDisplayAugmentation extends BaseAugmentation { } catch (error) { console.log(` Error computing display fields: ${error}`) } - + console.log('') } } diff --git a/src/brainy.ts b/src/brainy.ts index 3f86657f..eb66e629 100644 --- a/src/brainy.ts +++ b/src/brainy.ts @@ -57,6 +57,14 @@ export class Brainy { private augmentationRegistry: AugmentationRegistry private config: Required + // Silent mode state + private originalConsole?: { + log: typeof console.log + info: typeof console.info + warn: typeof console.warn + error: typeof console.error + } + // Sub-APIs (lazy-loaded) private _neural?: ImprovedNeuralAPI private _nlp?: NaturalLanguageProcessor @@ -109,7 +117,22 @@ export class Brainy { // Configure logging based on config options if (this.config.silent) { - configureLogger({ level: -1 as LogLevel }) // Suppress all logs + // Store original console methods for restoration + this.originalConsole = { + log: console.log, + info: console.info, + warn: console.warn, + error: console.error + } + + // Override all console methods to completely silence output + console.log = () => {} + console.info = () => {} + console.warn = () => {} + console.error = () => {} + + // Also configure logger for silent mode + configureLogger({ level: LogLevel.SILENT }) // Suppress all logs } else if (this.config.verbose) { configureLogger({ level: LogLevel.DEBUG }) // Enable verbose logging } @@ -1739,8 +1762,19 @@ export class Brainy { private setupAugmentations(): AugmentationRegistry { const registry = new AugmentationRegistry() - // Register default augmentations - const defaults = createDefaultAugmentations(this.config.augmentations) + // Register default augmentations with silent mode support + const augmentationConfig = { + ...this.config.augmentations, + // Pass silent mode to all augmentations + ...(this.config.silent && { + cache: this.config.augmentations?.cache !== false ? { ...this.config.augmentations?.cache, silent: true } : false, + metrics: this.config.augmentations?.metrics !== false ? { ...this.config.augmentations?.metrics, silent: true } : false, + display: this.config.augmentations?.display !== false ? { ...this.config.augmentations?.display, silent: true } : false, + monitoring: this.config.augmentations?.monitoring !== false ? { ...this.config.augmentations?.monitoring, silent: true } : false + }) + } + + const defaults = createDefaultAugmentations(augmentationConfig) for (const aug of defaults) { registry.register(aug) } @@ -1830,6 +1864,15 @@ export class Brainy { } } + // Restore console methods if silent mode was enabled + if (this.config.silent && this.originalConsole) { + console.log = this.originalConsole.log as typeof console.log + console.info = this.originalConsole.info as typeof console.info + console.warn = this.originalConsole.warn as typeof console.warn + console.error = this.originalConsole.error as typeof console.error + this.originalConsole = undefined + } + // Storage doesn't have close in current interface // We'll just mark as not initialized this.initialized = false diff --git a/src/utils/logger.ts b/src/utils/logger.ts index edd2a11a..5154d4fd 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -7,6 +7,7 @@ import { isProductionEnvironment, getLogLevel } from './environment.js' export enum LogLevel { + SILENT = -1, // New: Completely silent mode ERROR = 0, WARN = 1, INFO = 2, @@ -66,7 +67,7 @@ class Logger { // Convert environment log level to Logger LogLevel switch (envLogLevel) { case 'silent': - this.config.level = -1 as LogLevel // Below ERROR to silence all logs + this.config.level = LogLevel.SILENT break case 'error': this.config.level = LogLevel.ERROR @@ -106,6 +107,11 @@ class Logger { } private shouldLog(level: LogLevel, module: string): boolean { + // Silent mode - never log anything + if (this.config.level === LogLevel.SILENT) { + return false + } + // Check module-specific level first if (this.config.modules && this.config.modules[module] !== undefined) { return level <= this.config.modules[module]