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:
parent
876bd3cbb4
commit
ca3f90023b
6 changed files with 74 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ export interface MetricsConfig {
|
|||
trackStorageSizes?: boolean
|
||||
persistMetrics?: boolean
|
||||
metricsInterval?: number
|
||||
silent?: boolean // New: Silent mode support
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -290,9 +290,14 @@ export class UniversalDisplayAugmentation extends BaseAugmentation {
|
|||
*/
|
||||
private createExploreMethod(entity: any) {
|
||||
return async (): Promise<void> => {
|
||||
// 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('')
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue