feat: add complete silent mode for TUI applications

- 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 <noreply@anthropic.com>
This commit is contained in:
David Snelling 2025-09-16 13:18:49 -07:00
parent 4d3e21a0f7
commit 27fb3ef905
6 changed files with 74 additions and 10 deletions

View file

@ -57,6 +57,14 @@ export class Brainy<T = any> {
private augmentationRegistry: AugmentationRegistry
private config: Required<BrainyConfig>
// 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<T = any> {
// 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<T = any> {
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<T = any> {
}
}
// 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