2025-08-26 12:32:21 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* 🧠 Neural Similarity API Commands
|
|
|
|
|
|
*
|
|
|
|
|
|
* CLI interface for semantic similarity, clustering, and neural operations
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
import inquirer from 'inquirer'
|
|
|
|
|
|
import chalk from 'chalk'
|
|
|
|
|
|
import ora from 'ora'
|
|
|
|
|
|
import fs from 'node:fs'
|
|
|
|
|
|
import path from 'node:path'
|
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'
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
interface CommandArguments {
|
|
|
|
|
|
action?: string;
|
|
|
|
|
|
id?: string;
|
|
|
|
|
|
query?: string;
|
|
|
|
|
|
threshold?: number;
|
|
|
|
|
|
format?: string;
|
|
|
|
|
|
output?: string;
|
|
|
|
|
|
limit?: number;
|
|
|
|
|
|
algorithm?: string;
|
|
|
|
|
|
dimensions?: number;
|
|
|
|
|
|
explain?: boolean;
|
|
|
|
|
|
_: string[];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const neuralCommand = {
|
|
|
|
|
|
command: 'neural [action]',
|
|
|
|
|
|
describe: '🧠 Neural similarity and clustering operations',
|
|
|
|
|
|
|
|
|
|
|
|
builder: (yargs: any) => {
|
|
|
|
|
|
return yargs
|
|
|
|
|
|
.positional('action', {
|
|
|
|
|
|
describe: 'Neural operation to perform',
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
choices: ['similar', 'clusters', 'hierarchy', 'neighbors', 'path', 'outliers', 'visualize']
|
|
|
|
|
|
})
|
|
|
|
|
|
.option('id', {
|
|
|
|
|
|
describe: 'Item ID for similarity operations',
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
alias: 'i'
|
|
|
|
|
|
})
|
|
|
|
|
|
.option('query', {
|
|
|
|
|
|
describe: 'Query text for similarity search',
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
alias: 'q'
|
|
|
|
|
|
})
|
|
|
|
|
|
.option('threshold', {
|
|
|
|
|
|
describe: 'Similarity threshold (0-1)',
|
|
|
|
|
|
type: 'number',
|
|
|
|
|
|
default: 0.7,
|
|
|
|
|
|
alias: 't'
|
|
|
|
|
|
})
|
|
|
|
|
|
.option('format', {
|
|
|
|
|
|
describe: 'Output format',
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
choices: ['json', 'table', 'tree', 'graph'],
|
|
|
|
|
|
default: 'table',
|
|
|
|
|
|
alias: 'f'
|
|
|
|
|
|
})
|
|
|
|
|
|
.option('output', {
|
|
|
|
|
|
describe: 'Output file path',
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
alias: 'o'
|
|
|
|
|
|
})
|
|
|
|
|
|
.option('limit', {
|
|
|
|
|
|
describe: 'Maximum number of results',
|
|
|
|
|
|
type: 'number',
|
|
|
|
|
|
default: 10,
|
|
|
|
|
|
alias: 'l'
|
|
|
|
|
|
})
|
|
|
|
|
|
.option('algorithm', {
|
|
|
|
|
|
describe: 'Clustering algorithm',
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
choices: ['hierarchical', 'kmeans', 'dbscan', 'auto'],
|
|
|
|
|
|
default: 'auto',
|
|
|
|
|
|
alias: 'a'
|
|
|
|
|
|
})
|
|
|
|
|
|
.option('dimensions', {
|
|
|
|
|
|
describe: 'Visualization dimensions (2 or 3)',
|
|
|
|
|
|
type: 'number',
|
|
|
|
|
|
choices: [2, 3],
|
|
|
|
|
|
default: 2,
|
|
|
|
|
|
alias: 'd'
|
|
|
|
|
|
})
|
|
|
|
|
|
.option('explain', {
|
|
|
|
|
|
describe: 'Include detailed explanations',
|
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
|
default: false,
|
|
|
|
|
|
alias: 'e'
|
2025-09-29 09:50:59 -07:00
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
handler: async (argv: CommandArguments) => {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(chalk.cyan('\n🧠 NEURAL SIMILARITY API'))
|
|
|
|
|
|
console.log(chalk.gray('━'.repeat(50)))
|
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
|
|
|
|
// Initialize Brainy and Neural API
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const brain = new Brainy()
|
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
|
|
|
|
|
|
|
|
|
|
try {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const action = argv.action || await promptForAction()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
|
case 'similar':
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await handleSimilarCommand(neural, argv)
|
|
|
|
|
|
break
|
2025-08-26 12:32:21 -07:00
|
|
|
|
case 'clusters':
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await handleClustersCommand(neural, argv)
|
|
|
|
|
|
break
|
2025-08-26 12:32:21 -07:00
|
|
|
|
case 'hierarchy':
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await handleHierarchyCommand(neural, argv)
|
|
|
|
|
|
break
|
2025-08-26 12:32:21 -07:00
|
|
|
|
case 'neighbors':
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await handleNeighborsCommand(neural, argv)
|
|
|
|
|
|
break
|
2025-08-26 12:32:21 -07:00
|
|
|
|
case 'path':
|
2026-01-27 15:38:21 -08:00
|
|
|
|
console.log(chalk.yellow('\n⚠️ Semantic path finding 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('This feature requires implementing graph traversal algorithms'))
|
|
|
|
|
|
console.log(chalk.dim('Use "neighbors" and "hierarchy" commands to explore connections'))
|
2025-09-29 09:50:59 -07:00
|
|
|
|
break
|
2025-08-26 12:32:21 -07:00
|
|
|
|
case 'outliers':
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await handleOutliersCommand(neural, argv)
|
|
|
|
|
|
break
|
2025-08-26 12:32:21 -07:00
|
|
|
|
case 'visualize':
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await handleVisualizeCommand(neural, argv)
|
|
|
|
|
|
break
|
2025-08-26 12:32:21 -07:00
|
|
|
|
default:
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(chalk.red(`❌ Unknown action: ${action}`))
|
|
|
|
|
|
showHelp()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.error(chalk.red('💥 Error:'), error instanceof Error ? error.message : error)
|
|
|
|
|
|
process.exit(1)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-29 09:50:59 -07:00
|
|
|
|
}
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
async function promptForAction(): Promise<string> {
|
|
|
|
|
|
const answer = await inquirer.prompt([{
|
|
|
|
|
|
type: 'list',
|
|
|
|
|
|
name: 'action',
|
|
|
|
|
|
message: 'Choose a neural operation:',
|
|
|
|
|
|
choices: [
|
|
|
|
|
|
{ name: '🔗 Calculate similarity between items', value: 'similar' },
|
|
|
|
|
|
{ name: '🎯 Find semantic clusters', value: 'clusters' },
|
|
|
|
|
|
{ name: '🌳 Show item hierarchy', value: 'hierarchy' },
|
|
|
|
|
|
{ name: '🕸️ Find semantic neighbors', value: 'neighbors' },
|
2026-01-27 15:38:21 -08:00
|
|
|
|
{ name: '🛣️ Find semantic path between items (coming soon)', value: 'path', disabled: true },
|
2025-08-26 12:32:21 -07:00
|
|
|
|
{ name: '🚨 Detect outliers', value: 'outliers' },
|
|
|
|
|
|
{ name: '📊 Generate visualization data', value: 'visualize' }
|
|
|
|
|
|
]
|
2025-09-29 09:50:59 -07:00
|
|
|
|
}])
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
return answer.action
|
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
|
|
|
|
async function handleSimilarCommand(neural: any, argv: CommandArguments): Promise<void> {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const spinner = ora('🧠 Calculating semantic similarity...').start()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
let itemA: string, itemB: string
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (argv.id && argv.query) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
itemA = argv.id
|
|
|
|
|
|
itemB = argv.query
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else if (argv._ && argv._.length >= 3) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
itemA = argv._[1]
|
|
|
|
|
|
itemB = argv._[2]
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.stop()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
const answers = await inquirer.prompt([
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
name: 'itemA',
|
|
|
|
|
|
message: 'First item (ID or text):',
|
|
|
|
|
|
validate: (input: string) => input.length > 0
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
name: 'itemB',
|
|
|
|
|
|
message: 'Second item (ID or text):',
|
|
|
|
|
|
validate: (input: string) => input.length > 0
|
|
|
|
|
|
}
|
2025-09-29 09:50:59 -07:00
|
|
|
|
])
|
|
|
|
|
|
itemA = answers.itemA
|
|
|
|
|
|
itemB = answers.itemB
|
|
|
|
|
|
spinner.start()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const result = await neural.similar(itemA, itemB, {
|
|
|
|
|
|
explain: argv.explain,
|
|
|
|
|
|
includeBreakdown: argv.explain
|
2025-09-29 09:50:59 -07:00
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.succeed('✅ Similarity calculated')
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (typeof result === 'number') {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n🔗 Similarity: ${chalk.cyan((result * 100).toFixed(1))}%`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n🔗 Similarity: ${chalk.cyan((result.score * 100).toFixed(1))}%`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
if (result.explanation) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`💭 Explanation: ${result.explanation}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (result.breakdown) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log('\n📊 Breakdown:')
|
|
|
|
|
|
console.log(` Semantic: ${chalk.yellow((result.breakdown.semantic! * 100).toFixed(1))}%`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
if (result.breakdown.taxonomic !== undefined) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(` Taxonomic: ${chalk.yellow((result.breakdown.taxonomic * 100).toFixed(1))}%`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (result.breakdown.contextual !== undefined) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(` Contextual: ${chalk.yellow((result.breakdown.contextual * 100).toFixed(1))}%`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (result.hierarchy) {
|
|
|
|
|
|
console.log(`\n🌳 Hierarchy: ${result.hierarchy.sharedParent ?
|
|
|
|
|
|
`Shared parent at distance ${result.hierarchy.distance}` :
|
2025-09-29 09:50:59 -07:00
|
|
|
|
'No shared parent found'}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argv.output) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await saveToFile(argv.output, result, argv.format!)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.fail('💥 Failed to calculate similarity')
|
|
|
|
|
|
throw error
|
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
|
|
|
|
async function handleClustersCommand(neural: any, argv: CommandArguments): Promise<void> {
|
2025-10-17 14:47:53 -07:00
|
|
|
|
let spinner: any = null
|
2025-08-26 12:32:21 -07:00
|
|
|
|
try {
|
2025-10-17 14:47:53 -07:00
|
|
|
|
let options: any = {
|
2025-08-26 12:32:21 -07:00
|
|
|
|
algorithm: argv.algorithm as any,
|
|
|
|
|
|
threshold: argv.threshold,
|
|
|
|
|
|
maxClusters: argv.limit
|
2025-09-29 09:50:59 -07:00
|
|
|
|
}
|
2025-10-17 14:47:53 -07:00
|
|
|
|
|
|
|
|
|
|
// Interactive mode if no algorithm specified or using defaults
|
|
|
|
|
|
if (!argv.algorithm || argv.algorithm === 'hierarchical') {
|
|
|
|
|
|
const answers = await inquirer.prompt([
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'list',
|
|
|
|
|
|
name: 'algorithm',
|
|
|
|
|
|
message: 'Choose clustering algorithm:',
|
|
|
|
|
|
default: argv.algorithm || 'hierarchical',
|
|
|
|
|
|
choices: [
|
|
|
|
|
|
{ name: '🌳 Hierarchical (Tree-based, best for natural grouping)', value: 'hierarchical' },
|
|
|
|
|
|
{ name: '📊 K-Means (Fixed number of clusters)', value: 'kmeans' },
|
|
|
|
|
|
{ name: '🎯 DBSCAN (Density-based, finds arbitrary shapes)', value: 'dbscan' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'number',
|
|
|
|
|
|
name: 'maxClusters',
|
|
|
|
|
|
message: 'Maximum number of clusters:',
|
|
|
|
|
|
default: argv.limit || 5,
|
|
|
|
|
|
when: (answers: any) => answers.algorithm === 'kmeans'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'number',
|
|
|
|
|
|
name: 'threshold',
|
|
|
|
|
|
message: 'Similarity threshold (0-1):',
|
|
|
|
|
|
default: argv.threshold || 0.7,
|
|
|
|
|
|
validate: (input: number) => (input >= 0 && input <= 1) || 'Must be between 0 and 1'
|
|
|
|
|
|
}
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
algorithm: answers.algorithm,
|
|
|
|
|
|
threshold: answers.threshold,
|
|
|
|
|
|
maxClusters: answers.maxClusters || options.maxClusters
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const spinner = ora('🎯 Finding semantic clusters...').start()
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const clusters = await neural.clusters(argv.query || options)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.succeed(`✅ Found ${clusters.length} clusters`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (argv.format === 'json') {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(JSON.stringify(clusters, null, 2))
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n🎯 ${chalk.cyan(clusters.length)} Semantic Clusters:\n`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
clusters.forEach((cluster, index) => {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`${chalk.yellow(`Cluster ${index + 1}:`)} ${cluster.label || cluster.id}`)
|
|
|
|
|
|
console.log(` 📊 Confidence: ${chalk.green((cluster.confidence * 100).toFixed(1))}%`)
|
|
|
|
|
|
console.log(` 👥 Members: ${cluster.members.length}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
if (cluster.members.length <= 5) {
|
|
|
|
|
|
cluster.members.forEach(member => {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(` • ${member}`)
|
|
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
|
|
|
|
|
cluster.members.slice(0, 3).forEach(member => {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(` • ${member}`)
|
|
|
|
|
|
})
|
|
|
|
|
|
console.log(` ... and ${cluster.members.length - 3} more`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log()
|
|
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argv.output) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await saveToFile(argv.output, clusters, argv.format!)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
2025-10-17 14:47:53 -07:00
|
|
|
|
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} catch (error) {
|
2025-10-17 14:47:53 -07:00
|
|
|
|
if (spinner) spinner.fail('💥 Failed to find clusters')
|
2025-09-29 09:50:59 -07:00
|
|
|
|
throw error
|
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
|
|
|
|
async function handleHierarchyCommand(neural: any, argv: CommandArguments): Promise<void> {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const spinner = ora('🌳 Building semantic hierarchy...').start()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const id = argv.id || argv._[1]
|
2025-08-26 12:32:21 -07:00
|
|
|
|
if (!id) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.stop()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
const answer = await inquirer.prompt([{
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
name: 'id',
|
|
|
|
|
|
message: 'Enter item ID:',
|
|
|
|
|
|
validate: (input: string) => input.length > 0
|
2025-09-29 09:50:59 -07:00
|
|
|
|
}])
|
|
|
|
|
|
spinner.start()
|
|
|
|
|
|
const hierarchy = await neural.hierarchy(answer.id)
|
|
|
|
|
|
displayHierarchy(hierarchy)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const hierarchy = await neural.hierarchy(id)
|
|
|
|
|
|
spinner.succeed('✅ Hierarchy built')
|
|
|
|
|
|
displayHierarchy(hierarchy)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argv.output) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const hierarchy = await neural.hierarchy(id || argv._[1])
|
|
|
|
|
|
await saveToFile(argv.output, hierarchy, argv.format!)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.fail('💥 Failed to build hierarchy')
|
|
|
|
|
|
throw error
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function displayHierarchy(hierarchy: any): void {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n🌳 Semantic Hierarchy for ${chalk.cyan(hierarchy.self.id)}:`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (hierarchy.root) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`🔝 Root: ${hierarchy.root.id} (${(hierarchy.root.similarity * 100).toFixed(1)}%)`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (hierarchy.grandparent) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`👴 Grandparent: ${hierarchy.grandparent.id} (${(hierarchy.grandparent.similarity * 100).toFixed(1)}%)`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (hierarchy.parent) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`👨 Parent: ${hierarchy.parent.id} (${(hierarchy.parent.similarity * 100).toFixed(1)}%)`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`🎯 ${chalk.bold('Self:')} ${hierarchy.self.id}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (hierarchy.siblings && hierarchy.siblings.length > 0) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`👥 Siblings: ${hierarchy.siblings.length}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
hierarchy.siblings.forEach((sibling: any) => {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(` • ${sibling.id} (${(sibling.similarity * 100).toFixed(1)}%)`)
|
|
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (hierarchy.children && hierarchy.children.length > 0) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`👶 Children: ${hierarchy.children.length}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
hierarchy.children.forEach((child: any) => {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(` • ${child.id} (${(child.similarity * 100).toFixed(1)}%)`)
|
|
|
|
|
|
})
|
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
|
|
|
|
async function handleNeighborsCommand(neural: any, argv: CommandArguments): Promise<void> {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const spinner = ora('🕸️ Finding semantic neighbors...').start()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const id = argv.id || argv._[1]
|
2025-08-26 12:32:21 -07:00
|
|
|
|
if (!id) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.stop()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
const answer = await inquirer.prompt([{
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
name: 'id',
|
|
|
|
|
|
message: 'Enter item ID:',
|
|
|
|
|
|
validate: (input: string) => input.length > 0
|
2025-09-29 09:50:59 -07:00
|
|
|
|
}])
|
|
|
|
|
|
spinner.start()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const targetId = id || (await inquirer.prompt([{
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
name: 'id',
|
|
|
|
|
|
message: 'Enter item ID:',
|
|
|
|
|
|
validate: (input: string) => input.length > 0
|
2025-09-29 09:50:59 -07:00
|
|
|
|
}])).id
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
const graph = await neural.neighbors(targetId, {
|
|
|
|
|
|
limit: argv.limit,
|
|
|
|
|
|
includeEdges: true
|
2025-09-29 09:50:59 -07:00
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.succeed(`✅ Found ${graph.neighbors.length} neighbors`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n🕸️ Neighbors of ${chalk.cyan(graph.center)}:`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
graph.neighbors.forEach((neighbor, index) => {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`${index + 1}. ${neighbor.id} (${(neighbor.similarity * 100).toFixed(1)}%)`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
if (neighbor.type) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(` Type: ${neighbor.type}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (neighbor.connections) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(` Connections: ${neighbor.connections}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
2025-09-29 09:50:59 -07:00
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (graph.edges && graph.edges.length > 0) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n🔗 ${graph.edges.length} semantic connections found`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argv.output) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await saveToFile(argv.output, graph, argv.format!)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.fail('💥 Failed to find neighbors')
|
|
|
|
|
|
throw error
|
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
|
|
|
|
async function handlePathCommand(neural: any, argv: CommandArguments): Promise<void> {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const spinner = ora('🛣️ Finding semantic path...').start()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
let fromId: string, toId: string
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (argv._ && argv._.length >= 3) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
fromId = argv._[1]
|
|
|
|
|
|
toId = argv._[2]
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.stop()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
const answers = await inquirer.prompt([
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
name: 'from',
|
|
|
|
|
|
message: 'From item ID:',
|
|
|
|
|
|
validate: (input: string) => input.length > 0
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
name: 'to',
|
|
|
|
|
|
message: 'To item ID:',
|
|
|
|
|
|
validate: (input: string) => input.length > 0
|
|
|
|
|
|
}
|
2025-09-29 09:50:59 -07:00
|
|
|
|
])
|
|
|
|
|
|
fromId = answers.from
|
|
|
|
|
|
toId = answers.to
|
|
|
|
|
|
spinner.start()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const path = await neural.semanticPath(fromId, toId)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (path.length === 0) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.warn('🚫 No semantic path found')
|
|
|
|
|
|
console.log(`No path found between ${chalk.cyan(fromId)} and ${chalk.cyan(toId)}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.succeed(`✅ Found path with ${path.length} hops`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n🛣️ Semantic Path from ${chalk.cyan(fromId)} to ${chalk.cyan(toId)}:`)
|
|
|
|
|
|
console.log(`${chalk.cyan(fromId)} (start)`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
path.forEach((hop, index) => {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`${' '.repeat(index + 1)}↓ ${(hop.similarity * 100).toFixed(1)}%`)
|
|
|
|
|
|
console.log(`${' '.repeat(index + 1)}${hop.id} (hop ${hop.hop})`)
|
|
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argv.output) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await saveToFile(argv.output, path, argv.format!)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.fail('💥 Failed to find path')
|
|
|
|
|
|
throw error
|
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
|
|
|
|
async function handleOutliersCommand(neural: any, argv: CommandArguments): Promise<void> {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const spinner = ora('🚨 Detecting semantic outliers...').start()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const outliers = await neural.outliers(argv.threshold)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.succeed(`✅ Found ${outliers.length} outliers`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (outliers.length === 0) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log('\n🎉 No outliers detected - all items are well connected!')
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n🚨 ${chalk.red(outliers.length)} Semantic Outliers:`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
outliers.forEach((outlier, index) => {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`${index + 1}. ${outlier}`)
|
|
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n💡 These items have similarity < ${argv.threshold} to their nearest neighbors`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argv.output) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await saveToFile(argv.output, outliers, argv.format!)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.fail('💥 Failed to detect outliers')
|
|
|
|
|
|
throw error
|
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
|
|
|
|
async function handleVisualizeCommand(neural: any, argv: CommandArguments): Promise<void> {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const spinner = ora('📊 Generating visualization data...').start()
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const vizData = await neural.visualize({
|
|
|
|
|
|
dimensions: argv.dimensions as 2 | 3,
|
|
|
|
|
|
maxNodes: argv.limit
|
2025-09-29 09:50:59 -07:00
|
|
|
|
})
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.succeed('✅ Visualization data generated')
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n📊 Visualization Data (${vizData.format} layout):`)
|
|
|
|
|
|
console.log(`📍 Nodes: ${vizData.nodes.length}`)
|
|
|
|
|
|
console.log(`🔗 Edges: ${vizData.edges.length}`)
|
|
|
|
|
|
console.log(`🎯 Clusters: ${vizData.clusters?.length || 0}`)
|
|
|
|
|
|
console.log(`📐 Dimensions: ${vizData.layout?.dimensions}D`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
|
|
if (argv.format === 'json') {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log('\nData:')
|
|
|
|
|
|
console.log(JSON.stringify(vizData, null, 2))
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log('\n🎨 Style Settings:')
|
|
|
|
|
|
console.log(` Node Colors: ${vizData.style?.nodeColors}`)
|
|
|
|
|
|
console.log(` Edge Width: ${vizData.style?.edgeWidth}`)
|
|
|
|
|
|
console.log(` Labels: ${vizData.style?.labels}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argv.output) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
await saveToFile(argv.output, vizData, 'json')
|
|
|
|
|
|
console.log(`\n💾 Visualization data saved to: ${chalk.green(argv.output)}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
} else {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log(`\n💡 Use --output to save visualization data for external tools`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
spinner.fail('💥 Failed to generate visualization')
|
|
|
|
|
|
throw error
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function saveToFile(filepath: string, data: any, format: string): Promise<void> {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
const dir = path.dirname(filepath)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
if (!fs.existsSync(dir)) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
fs.mkdirSync(dir, { recursive: true })
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
let output: string
|
2025-08-26 12:32:21 -07:00
|
|
|
|
switch (format) {
|
|
|
|
|
|
case 'json':
|
2025-09-29 09:50:59 -07:00
|
|
|
|
output = JSON.stringify(data, null, 2)
|
|
|
|
|
|
break
|
2025-08-26 12:32:21 -07:00
|
|
|
|
case 'table':
|
2025-09-29 09:50:59 -07:00
|
|
|
|
output = formatAsTable(data)
|
|
|
|
|
|
break
|
2025-08-26 12:32:21 -07:00
|
|
|
|
default:
|
2025-09-29 09:50:59 -07:00
|
|
|
|
output = JSON.stringify(data, null, 2)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-29 09:50:59 -07:00
|
|
|
|
fs.writeFileSync(filepath, output, 'utf8')
|
|
|
|
|
|
console.log(`💾 Saved to: ${chalk.green(filepath)}`)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatAsTable(data: any): string {
|
|
|
|
|
|
// Simple table formatting - could be enhanced with a table library
|
|
|
|
|
|
if (Array.isArray(data)) {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
return data.map((item, index) => `${index + 1}. ${JSON.stringify(item)}`).join('\n')
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
2025-09-29 09:50:59 -07:00
|
|
|
|
return JSON.stringify(data, null, 2)
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function showHelp(): void {
|
2025-09-29 09:50:59 -07:00
|
|
|
|
console.log('\n🧠 Neural Similarity API Commands:')
|
|
|
|
|
|
console.log('')
|
|
|
|
|
|
console.log(' brainy neural similar <item1> <item2> Calculate similarity')
|
|
|
|
|
|
console.log(' brainy neural clusters Find semantic clusters')
|
|
|
|
|
|
console.log(' brainy neural hierarchy <id> Show item hierarchy')
|
|
|
|
|
|
console.log(' brainy neural neighbors <id> Find semantic neighbors')
|
|
|
|
|
|
console.log(' brainy neural path <from> <to> Find semantic path')
|
|
|
|
|
|
console.log(' brainy neural outliers Detect outliers')
|
|
|
|
|
|
console.log(' brainy neural visualize Generate visualization data')
|
|
|
|
|
|
console.log('')
|
|
|
|
|
|
console.log('Options:')
|
|
|
|
|
|
console.log(' --threshold, -t Similarity threshold (0-1)')
|
|
|
|
|
|
console.log(' --format, -f Output format (json|table|tree|graph)')
|
|
|
|
|
|
console.log(' --output, -o Save to file')
|
|
|
|
|
|
console.log(' --limit, -l Maximum results')
|
|
|
|
|
|
console.log(' --explain, -e Include explanations')
|
|
|
|
|
|
console.log('')
|
2025-08-26 12:32:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-17 14:47:53 -07:00
|
|
|
|
// Commander-compatible wrappers
|
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
|
|
|
|
export const neuralCommands = {
|
2025-10-17 14:47:53 -07:00
|
|
|
|
async similar(a?: string, b?: string, options?: any) {
|
|
|
|
|
|
const brain = new Brainy()
|
|
|
|
|
|
const neural = brain.neural()
|
|
|
|
|
|
|
|
|
|
|
|
// Build argv-style object for handler
|
|
|
|
|
|
const argv: CommandArguments = {
|
|
|
|
|
|
_: ['neural', 'similar', a || '', b || ''].filter(x => x),
|
|
|
|
|
|
id: a,
|
|
|
|
|
|
query: b,
|
|
|
|
|
|
explain: options?.explain,
|
|
|
|
|
|
...options
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await handleSimilarCommand(neural, argv)
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async cluster(options?: any) {
|
|
|
|
|
|
const brain = new Brainy()
|
|
|
|
|
|
const neural = brain.neural()
|
|
|
|
|
|
|
|
|
|
|
|
const argv: CommandArguments = {
|
|
|
|
|
|
_: ['neural', 'cluster'],
|
|
|
|
|
|
algorithm: options?.algorithm || 'hierarchical',
|
|
|
|
|
|
threshold: options?.threshold ? parseFloat(options.threshold) : 0.7,
|
|
|
|
|
|
limit: options?.maxClusters ? parseInt(options.maxClusters) : 10,
|
|
|
|
|
|
query: options?.near,
|
|
|
|
|
|
...options
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await handleClustersCommand(neural, argv)
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async hierarchy(id?: string, options?: any) {
|
|
|
|
|
|
const brain = new Brainy()
|
|
|
|
|
|
const neural = brain.neural()
|
|
|
|
|
|
|
|
|
|
|
|
const argv: CommandArguments = {
|
|
|
|
|
|
_: ['neural', 'hierarchy', id || ''].filter(x => x),
|
|
|
|
|
|
id,
|
|
|
|
|
|
...options
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await handleHierarchyCommand(neural, argv)
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async related(id?: string, options?: any) {
|
|
|
|
|
|
const brain = new Brainy()
|
|
|
|
|
|
const neural = brain.neural()
|
|
|
|
|
|
|
|
|
|
|
|
const argv: CommandArguments = {
|
|
|
|
|
|
_: ['neural', 'related', id || ''].filter(x => x),
|
|
|
|
|
|
id,
|
|
|
|
|
|
limit: options?.limit ? parseInt(options.limit) : 10,
|
|
|
|
|
|
threshold: options?.radius ? parseFloat(options.radius) : 0.3,
|
|
|
|
|
|
...options
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await handleNeighborsCommand(neural, argv)
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async outliers(options?: any) {
|
|
|
|
|
|
const brain = new Brainy()
|
|
|
|
|
|
const neural = brain.neural()
|
|
|
|
|
|
|
|
|
|
|
|
const argv: CommandArguments = {
|
|
|
|
|
|
_: ['neural', 'outliers'],
|
|
|
|
|
|
threshold: options?.threshold ? parseFloat(options.threshold) : 0.3,
|
|
|
|
|
|
explain: options?.explain,
|
|
|
|
|
|
...options
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await handleOutliersCommand(neural, argv)
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async visualize(options?: any) {
|
|
|
|
|
|
const brain = new Brainy()
|
|
|
|
|
|
const neural = brain.neural()
|
|
|
|
|
|
|
|
|
|
|
|
const argv: CommandArguments = {
|
|
|
|
|
|
_: ['neural', 'visualize'],
|
|
|
|
|
|
format: options?.format || 'json',
|
|
|
|
|
|
dimensions: options?.dimensions ? parseInt(options.dimensions) : 2,
|
|
|
|
|
|
limit: options?.maxNodes ? parseInt(options.maxNodes) : 500,
|
|
|
|
|
|
output: options?.output,
|
|
|
|
|
|
...options
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await handleVisualizeCommand(neural, argv)
|
|
|
|
|
|
}
|
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-09-29 09:50:59 -07:00
|
|
|
|
export default neuralCommand
|