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
|
ttl?: number
|
||||||
enabled?: boolean
|
enabled?: boolean
|
||||||
invalidateOnWrite?: boolean
|
invalidateOnWrite?: boolean
|
||||||
|
silent?: boolean // Silent mode support
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -80,6 +81,11 @@ export class CacheAugmentation extends BaseAugmentation {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: true,
|
default: true,
|
||||||
description: 'Automatically invalidate cache on data modifications'
|
description: 'Automatically invalidate cache on data modifications'
|
||||||
|
},
|
||||||
|
silent: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'Suppress all console output'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,21 @@ import type { VectorDocument, GraphVerb } from '../../coreTypes.js'
|
||||||
export interface DisplayConfig {
|
export interface DisplayConfig {
|
||||||
/** Enable/disable the augmentation */
|
/** Enable/disable the augmentation */
|
||||||
enabled: boolean
|
enabled: boolean
|
||||||
|
|
||||||
/** LRU cache size for computed display fields */
|
/** LRU cache size for computed display fields */
|
||||||
cacheSize: number
|
cacheSize: number
|
||||||
|
|
||||||
/** Use lazy computation (recommended for performance) */
|
/** Use lazy computation (recommended for performance) */
|
||||||
lazyComputation: boolean
|
lazyComputation: boolean
|
||||||
|
|
||||||
/** Batch processing size for multiple requests */
|
/** Batch processing size for multiple requests */
|
||||||
batchSize: number
|
batchSize: number
|
||||||
|
|
||||||
/** Minimum confidence threshold for AI type detection */
|
/** Minimum confidence threshold for AI type detection */
|
||||||
confidenceThreshold: number
|
confidenceThreshold: number
|
||||||
|
|
||||||
|
/** Silent mode - suppress all console output */
|
||||||
|
silent?: boolean
|
||||||
|
|
||||||
// No icon configuration needed - clean, minimal approach
|
// No icon configuration needed - clean, minimal approach
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ export interface MetricsConfig {
|
||||||
trackStorageSizes?: boolean
|
trackStorageSizes?: boolean
|
||||||
persistMetrics?: boolean
|
persistMetrics?: boolean
|
||||||
metricsInterval?: number
|
metricsInterval?: number
|
||||||
|
silent?: boolean // New: Silent mode support
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -290,9 +290,14 @@ export class UniversalDisplayAugmentation extends BaseAugmentation {
|
||||||
*/
|
*/
|
||||||
private createExploreMethod(entity: any) {
|
private createExploreMethod(entity: any) {
|
||||||
return async (): Promise<void> => {
|
return async (): Promise<void> => {
|
||||||
|
// Respect silent mode
|
||||||
|
if (this.config.silent) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`\n📋 Entity Exploration: ${entity.id || 'unknown'}`)
|
console.log(`\n📋 Entity Exploration: ${entity.id || 'unknown'}`)
|
||||||
console.log('━'.repeat(50))
|
console.log('━'.repeat(50))
|
||||||
|
|
||||||
// Show user data
|
// Show user data
|
||||||
console.log('\n👤 User Data:')
|
console.log('\n👤 User Data:')
|
||||||
const userData = entity.metadata || entity
|
const userData = entity.metadata || entity
|
||||||
|
|
@ -313,7 +318,7 @@ export class UniversalDisplayAugmentation extends BaseAugmentation {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(` Error computing display fields: ${error}`)
|
console.log(` Error computing display fields: ${error}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('')
|
console.log('')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,14 @@ export class Brainy<T = any> {
|
||||||
private augmentationRegistry: AugmentationRegistry
|
private augmentationRegistry: AugmentationRegistry
|
||||||
private config: Required<BrainyConfig>
|
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)
|
// Sub-APIs (lazy-loaded)
|
||||||
private _neural?: ImprovedNeuralAPI
|
private _neural?: ImprovedNeuralAPI
|
||||||
private _nlp?: NaturalLanguageProcessor
|
private _nlp?: NaturalLanguageProcessor
|
||||||
|
|
@ -109,7 +117,22 @@ export class Brainy<T = any> {
|
||||||
|
|
||||||
// Configure logging based on config options
|
// Configure logging based on config options
|
||||||
if (this.config.silent) {
|
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) {
|
} else if (this.config.verbose) {
|
||||||
configureLogger({ level: LogLevel.DEBUG }) // Enable verbose logging
|
configureLogger({ level: LogLevel.DEBUG }) // Enable verbose logging
|
||||||
}
|
}
|
||||||
|
|
@ -1739,8 +1762,19 @@ export class Brainy<T = any> {
|
||||||
private setupAugmentations(): AugmentationRegistry {
|
private setupAugmentations(): AugmentationRegistry {
|
||||||
const registry = new AugmentationRegistry()
|
const registry = new AugmentationRegistry()
|
||||||
|
|
||||||
// Register default augmentations
|
// Register default augmentations with silent mode support
|
||||||
const defaults = createDefaultAugmentations(this.config.augmentations)
|
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) {
|
for (const aug of defaults) {
|
||||||
registry.register(aug)
|
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
|
// Storage doesn't have close in current interface
|
||||||
// We'll just mark as not initialized
|
// We'll just mark as not initialized
|
||||||
this.initialized = false
|
this.initialized = false
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
import { isProductionEnvironment, getLogLevel } from './environment.js'
|
import { isProductionEnvironment, getLogLevel } from './environment.js'
|
||||||
|
|
||||||
export enum LogLevel {
|
export enum LogLevel {
|
||||||
|
SILENT = -1, // New: Completely silent mode
|
||||||
ERROR = 0,
|
ERROR = 0,
|
||||||
WARN = 1,
|
WARN = 1,
|
||||||
INFO = 2,
|
INFO = 2,
|
||||||
|
|
@ -66,7 +67,7 @@ class Logger {
|
||||||
// Convert environment log level to Logger LogLevel
|
// Convert environment log level to Logger LogLevel
|
||||||
switch (envLogLevel) {
|
switch (envLogLevel) {
|
||||||
case 'silent':
|
case 'silent':
|
||||||
this.config.level = -1 as LogLevel // Below ERROR to silence all logs
|
this.config.level = LogLevel.SILENT
|
||||||
break
|
break
|
||||||
case 'error':
|
case 'error':
|
||||||
this.config.level = LogLevel.ERROR
|
this.config.level = LogLevel.ERROR
|
||||||
|
|
@ -106,6 +107,11 @@ class Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
private shouldLog(level: LogLevel, module: string): boolean {
|
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
|
// Check module-specific level first
|
||||||
if (this.config.modules && this.config.modules[module] !== undefined) {
|
if (this.config.modules && this.config.modules[module] !== undefined) {
|
||||||
return level <= this.config.modules[module]
|
return level <= this.config.modules[module]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue