2025-08-26 12:32:21 -07:00
/ * *
* Utility CLI Commands - TypeScript Implementation
*
* Database maintenance , statistics , and benchmarking
* /
import chalk from 'chalk'
import ora from 'ora'
import Table from 'cli-table3'
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
import { Brainy } from '../../brainy.js'
import { NounType } from '../../types/graphTypes.js'
2025-08-26 12:32:21 -07:00
interface UtilityOptions {
verbose? : boolean
json? : boolean
pretty? : boolean
}
interface StatsOptions extends UtilityOptions {
byService? : boolean
detailed? : boolean
}
interface CleanOptions extends UtilityOptions {
removeOrphans? : boolean
rebuildIndex? : boolean
}
interface BenchmarkOptions extends UtilityOptions {
operations? : string
iterations? : string
}
2025-09-11 16:23:32 -07:00
let brainyInstance : Brainy | null = null
2025-08-26 12:32:21 -07:00
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
const getBrainy = ( ) : Brainy = > {
2025-08-26 12:32:21 -07:00
if ( ! brainyInstance ) {
2025-09-11 16:23:32 -07:00
brainyInstance = new Brainy ( )
2025-08-26 12:32:21 -07:00
}
return brainyInstance
}
const formatBytes = ( bytes : number ) : string = > {
if ( bytes === 0 ) return '0 B'
const k = 1024
const sizes = [ 'B' , 'KB' , 'MB' , 'GB' ]
const i = Math . floor ( Math . log ( bytes ) / Math . log ( k ) )
return parseFloat ( ( bytes / Math . pow ( k , i ) ) . toFixed ( 2 ) ) + ' ' + sizes [ i ]
}
const formatOutput = ( data : any , options : UtilityOptions ) : void = > {
if ( options . json ) {
console . log ( options . pretty ? JSON . stringify ( data , null , 2 ) : JSON . stringify ( data ) )
}
}
export const utilityCommands = {
/ * *
* Show database statistics
* /
async stats ( options : StatsOptions ) {
const spinner = ora ( 'Gathering statistics...' ) . start ( )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
try {
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
const brain = getBrainy ( )
const nounCount = await brain . getNounCount ( )
const verbCount = await brain . getVerbCount ( )
2025-08-26 12:32:21 -07:00
const memUsage = process . memoryUsage ( )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
spinner . succeed ( 'Statistics gathered' )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
const stats = {
nounCount ,
verbCount ,
totalItems : nounCount + verbCount
}
2025-08-26 12:32:21 -07:00
if ( options . json ) {
formatOutput ( stats , options )
return
}
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
console . log ( chalk . cyan ( '\n📊 Database Statistics\n' ) )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
// Core stats table
const coreTable = new Table ( {
head : [ chalk . cyan ( 'Metric' ) , chalk . cyan ( 'Value' ) ] ,
style : { head : [ ] , border : [ ] }
} )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
coreTable . push (
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
[ 'Total Items' , chalk . green ( stats . totalItems ) ] ,
[ 'Nouns' , chalk . green ( stats . nounCount ) ] ,
[ 'Verbs (Relationships)' , chalk . green ( stats . verbCount ) ]
2025-08-26 12:32:21 -07:00
)
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
console . log ( coreTable . toString ( ) )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
// Memory usage
console . log ( chalk . cyan ( '\n🧠 Memory Usage\n' ) )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
const memTable = new Table ( {
head : [ chalk . cyan ( 'Type' ) , chalk . cyan ( 'Size' ) ] ,
style : { head : [ ] , border : [ ] }
} )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
memTable . push (
[ 'Heap Used' , formatBytes ( memUsage . heapUsed ) ] ,
[ 'Heap Total' , formatBytes ( memUsage . heapTotal ) ] ,
[ 'RSS' , formatBytes ( memUsage . rss ) ] ,
[ 'External' , formatBytes ( memUsage . external ) ]
)
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
console . log ( memTable . toString ( ) )
} catch ( error : any ) {
spinner . fail ( 'Failed to gather statistics' )
console . error ( chalk . red ( error . message ) )
process . exit ( 1 )
}
} ,
/ * *
* Clean and optimize database
* /
async clean ( options : CleanOptions ) {
const spinner = ora ( 'Cleaning database...' ) . start ( )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
try {
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
const brain = getBrainy ( )
// For now, only support full clear
// removeOrphans and rebuildIndex would require new Brainy APIs
if ( options . removeOrphans || options . rebuildIndex ) {
spinner . warn ( 'Advanced cleanup options not yet implemented' )
2026-01-27 15:38:21 -08:00
console . log ( chalk . yellow ( '\n⚠️ Advanced cleanup features coming soon:' ) )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
console . log ( chalk . dim ( ' • --remove-orphans: Remove disconnected items' ) )
console . log ( chalk . dim ( ' • --rebuild-index: Rebuild vector index' ) )
console . log ( chalk . dim ( '\nUse "brainy clean" without options to clear the database' ) )
return
2025-08-26 12:32:21 -07:00
}
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
// Show warning before clearing
console . log ( chalk . yellow ( '\n⚠️ WARNING: This will permanently delete ALL data!' ) )
const dataApi = await brain . data ( )
// Clear all data
spinner . text = 'Clearing all data...'
await dataApi . clear ( { entities : true , relations : true } )
spinner . succeed ( 'Database cleared' )
2025-08-26 12:32:21 -07:00
if ( ! options . json ) {
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
console . log ( chalk . green ( '\n✓ Database cleared successfully' ) )
console . log ( chalk . dim ( ' All nouns, verbs, and metadata have been removed' ) )
2025-08-26 12:32:21 -07:00
} else {
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
formatOutput ( { cleared : true , success : true } , options )
2025-08-26 12:32:21 -07:00
}
} catch ( error : any ) {
spinner . fail ( 'Cleanup failed' )
console . error ( chalk . red ( error . message ) )
process . exit ( 1 )
}
} ,
/ * *
* Run performance benchmarks
* /
async benchmark ( options : BenchmarkOptions ) {
const operations = options . operations || 'all'
const iterations = parseInt ( options . iterations || '100' )
console . log ( chalk . cyan ( ` \ n🚀 Running Benchmarks ( ${ iterations } iterations) \ n ` ) )
const results : any = {
operations : { } ,
summary : { }
}
try {
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
const brain = getBrainy ( )
2025-08-26 12:32:21 -07:00
// Benchmark different operations
const benchmarks = [
{ name : 'add' , enabled : operations === 'all' || operations . includes ( 'add' ) } ,
{ name : 'search' , enabled : operations === 'all' || operations . includes ( 'search' ) } ,
{ name : 'similarity' , enabled : operations === 'all' || operations . includes ( 'similarity' ) } ,
{ name : 'cluster' , enabled : operations === 'all' || operations . includes ( 'cluster' ) }
]
for ( const bench of benchmarks ) {
if ( ! bench . enabled ) continue
const spinner = ora ( ` Benchmarking ${ bench . name } ... ` ) . start ( )
const times : number [ ] = [ ]
for ( let i = 0 ; i < iterations ; i ++ ) {
const start = Date . now ( )
switch ( bench . name ) {
case 'add' :
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
await brain . add ( { data : ` Test item ${ i } ` , type : NounType . Thing , metadata : { benchmark : true } } )
2025-08-26 12:32:21 -07:00
break
case 'search' :
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
await brain . find ( { query : 'test' , limit : 10 } )
2025-08-26 12:32:21 -07:00
break
case 'similarity' :
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
const neural = brain . neural ( )
2025-08-26 12:32:21 -07:00
await neural . similar ( 'test1' , 'test2' )
break
case 'cluster' :
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
const neuralApi = brain . neural ( )
2025-08-26 12:32:21 -07:00
await neuralApi . clusters ( )
break
}
times . push ( Date . now ( ) - start )
}
// Calculate statistics
const avg = times . reduce ( ( a , b ) = > a + b , 0 ) / times . length
const min = Math . min ( . . . times )
const max = Math . max ( . . . times )
const median = times . sort ( ( a , b ) = > a - b ) [ Math . floor ( times . length / 2 ) ]
results . operations [ bench . name ] = {
avg : avg.toFixed ( 2 ) ,
min ,
max ,
median ,
ops : ( 1000 / avg ) . toFixed ( 2 )
}
spinner . succeed ( ` ${ bench . name } : ${ avg . toFixed ( 2 ) } ms avg ( ${ ( 1000 / avg ) . toFixed ( 2 ) } ops/sec) ` )
}
// Calculate summary
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
const totalOps : number = ( Object . values ( results . operations ) as any [ ] ) . reduce ( ( sum : number , op : any ) = >
2025-08-26 12:32:21 -07:00
sum + parseFloat ( op . ops ) , 0 )
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
2025-08-26 12:32:21 -07:00
results . summary = {
totalOperations : Object.keys ( results . operations ) . length ,
feat: complete CLI with VFS, data management, and Triple Intelligence search
Comprehensive CLI enhancements bringing full Brainy functionality to command line:
- Add complete VFS operations (read, write, ls, stat, mkdir, rm, search, similar, tree)
- Migrate VFS to clean subcommand pattern (brainy vfs read vs brainy vfs-read)
- Add backward compatibility with deprecation warnings for vfs-* commands
- Expose full Triple Intelligence™ search capabilities (vector + graph + field)
- Add simple "find" command mirroring code usage: brain.find("query")
- Add data management commands (backup, restore, detailed stats)
- Remove all fake/mock/stub code from CLI commands
- Fix VFS initialization (add await vfs.init() to all commands)
- Fix utility clean() to use real DataAPI.clear()
- Mark semantic path finding as coming in v3.21.0
CLI now covers 75%+ of Brainy capabilities with production-ready implementations.
2025-09-29 16:57:14 -07:00
averageOpsPerSec : totalOps > 0 ? ( totalOps / Object . keys ( results . operations ) . length ) . toFixed ( 2 ) : '0'
2025-08-26 12:32:21 -07:00
}
if ( ! options . json ) {
// Display results table
console . log ( chalk . cyan ( '\n📊 Benchmark Results\n' ) )
const table = new Table ( {
head : [
chalk . cyan ( 'Operation' ) ,
chalk . cyan ( 'Avg (ms)' ) ,
chalk . cyan ( 'Min (ms)' ) ,
chalk . cyan ( 'Max (ms)' ) ,
chalk . cyan ( 'Median (ms)' ) ,
chalk . cyan ( 'Ops/sec' )
] ,
style : { head : [ ] , border : [ ] }
} )
Object . entries ( results . operations ) . forEach ( ( [ op , stats ] : [ string , any ] ) = > {
table . push ( [
op ,
stats . avg ,
stats . min ,
stats . max ,
stats . median ,
chalk . green ( stats . ops )
] )
} )
console . log ( table . toString ( ) )
console . log ( chalk . cyan ( '\n📈 Summary' ) )
console . log ( ` Operations tested: ${ results . summary . totalOperations } ` )
console . log ( ` Average throughput: ${ chalk . green ( results . summary . averageOpsPerSec ) } ops/sec ` )
} else {
formatOutput ( results , options )
}
} catch ( error : any ) {
console . error ( chalk . red ( 'Benchmark failed:' ) , error . message )
process . exit ( 1 )
}
}
}