feat: Complete 9 unified methods with CLI parity and triple-power search

- Add missing add-noun and add-verb CLI commands for full API parity
- Update CLI documentation to showcase triple-power search capabilities
- Add comprehensive type-safe augmentation management system
- Verify search supports vector + metadata + graph traversal in one call
- All 9 unified methods now available via both API and CLI
- Complete documentation accuracy fixes and cleanup
This commit is contained in:
David Snelling 2025-08-15 11:20:13 -07:00
parent 4fdaa7e22c
commit b01e3340f1
9 changed files with 461 additions and 83 deletions

132
src/augmentationManager.ts Normal file
View file

@ -0,0 +1,132 @@
/**
* Type-safe augmentation management system for Brainy
* Provides a clean API for managing augmentations without string literals
*/
import { IAugmentation, AugmentationType } from './types/augmentations.js'
import { augmentationPipeline } from './augmentationPipeline.js'
export interface AugmentationInfo {
name: string
type: string
enabled: boolean
description: string
}
/**
* Type-safe augmentation manager
* Accessed via brain.augmentations for all management operations
*/
export class AugmentationManager {
private pipeline = augmentationPipeline
/**
* List all registered augmentations with their status
* @returns Array of augmentation information
*/
list(): AugmentationInfo[] {
return this.pipeline.listAugmentationsWithStatus()
}
/**
* Get information about a specific augmentation
* @param name The augmentation name
* @returns Augmentation info or undefined if not found
*/
get(name: string): AugmentationInfo | undefined {
const all = this.list()
return all.find(a => a.name === name)
}
/**
* Check if an augmentation is enabled
* @param name The augmentation name
* @returns True if enabled, false otherwise
*/
isEnabled(name: string): boolean {
const aug = this.get(name)
return aug?.enabled ?? false
}
/**
* Enable a specific augmentation
* @param name The augmentation name
* @returns True if successfully enabled
*/
enable(name: string): boolean {
return this.pipeline.enableAugmentation(name)
}
/**
* Disable a specific augmentation
* @param name The augmentation name
* @returns True if successfully disabled
*/
disable(name: string): boolean {
return this.pipeline.disableAugmentation(name)
}
/**
* Remove an augmentation from the pipeline
* @param name The augmentation name
* @returns True if successfully removed
*/
remove(name: string): boolean {
this.pipeline.unregister(name)
return true
}
/**
* Enable all augmentations of a specific type
* @param type The augmentation type
* @returns Number of augmentations enabled
*/
enableType(type: AugmentationType): number {
return this.pipeline.enableAugmentationType(type as any)
}
/**
* Disable all augmentations of a specific type
* @param type The augmentation type
* @returns Number of augmentations disabled
*/
disableType(type: AugmentationType): number {
return this.pipeline.disableAugmentationType(type as any)
}
/**
* Get all augmentations of a specific type
* @param type The augmentation type
* @returns Array of augmentations of that type
*/
listByType(type: AugmentationType): AugmentationInfo[] {
return this.list().filter(a => a.type === type)
}
/**
* Get all enabled augmentations
* @returns Array of enabled augmentations
*/
listEnabled(): AugmentationInfo[] {
return this.list().filter(a => a.enabled)
}
/**
* Get all disabled augmentations
* @returns Array of disabled augmentations
*/
listDisabled(): AugmentationInfo[] {
return this.list().filter(a => !a.enabled)
}
/**
* Register a new augmentation (internal use)
* @param augmentation The augmentation to register
*/
register(augmentation: IAugmentation): void {
this.pipeline.register(augmentation)
}
}
// Export types for external use
export { AugmentationType } from './types/augmentations.js'

View file

@ -64,6 +64,7 @@ import {
import { SearchCache, SearchCacheConfig } from './utils/searchCache.js'
import { CacheAutoConfigurator } from './utils/cacheAutoConfig.js'
import { StatisticsCollector } from './utils/statisticsCollector.js'
import { AugmentationManager } from './augmentationManager.js'
export interface BrainyDataConfig {
/**
@ -470,6 +471,12 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
private loggingConfig: BrainyDataConfig['logging'] = { verbose: true }
private defaultService: string = 'default'
private searchCache: SearchCache<T>
/**
* Type-safe augmentation management
* Access all augmentation operations through this property
*/
public readonly augmentations: AugmentationManager
private cacheAutoConfigurator: CacheAutoConfigurator
// Timeout and retry configuration
@ -691,6 +698,9 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
// Initialize search cache with final configuration
this.searchCache = new SearchCache<T>(finalSearchCacheConfig)
// Initialize augmentation manager
this.augmentations = new AugmentationManager()
// Initialize intelligent verb scoring if enabled
if (config.intelligentVerbScoring?.enabled) {
@ -7269,83 +7279,71 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
// ===== Augmentation Control Methods =====
/**
* UNIFIED API METHOD #8: Augment - Complete augmentation management
* Register, enable, disable, list, and manage augmentations
* UNIFIED API METHOD #9: Augment - Register new augmentations
*
* @param action The action to perform or augmentation to register
* @param options Additional options for the action
* @returns Various return types based on action
* For registration: brain.augment(new MyAugmentation())
* For management: Use brain.augmentations.enable(), .disable(), .list() etc.
*
* @param action The augmentation to register OR legacy string command
* @param options Legacy options for string commands (deprecated)
* @returns this for chaining when registering, various for legacy commands
*
* @deprecated String-based commands are deprecated. Use brain.augmentations.* instead
*/
augment(
action: IAugmentation | 'list' | 'enable' | 'disable' | 'unregister' | 'enable-type' | 'disable-type',
options?: string | { name?: string; type?: string }
): this | any {
// If it's an augmentation object, register it
if (typeof action === 'object' && 'name' in action && 'type' in action) {
augmentationPipeline.register(action as IAugmentation)
// PRIMARY USE: Register new augmentation
if (typeof action === 'object' && 'name' in action) {
this.augmentations.register(action as IAugmentation)
return this
}
// Handle string actions
// LEGACY: Handle string actions (deprecated - use brain.augmentations instead)
console.warn(`Deprecated: brain.augment('${action}') - Use brain.augmentations.${action}() instead`)
switch (action) {
case 'list':
// Return list of all augmentations with status
return this.listAugmentations()
return this.augmentations.list()
case 'enable':
// Enable specific augmentation by name
if (typeof options === 'string') {
this.enableAugmentation(options)
this.augmentations.enable(options)
} else if (options?.name) {
this.enableAugmentation(options.name)
this.augmentations.enable(options.name)
}
return this
case 'disable':
// Disable specific augmentation by name
if (typeof options === 'string') {
this.disableAugmentation(options)
this.augmentations.disable(options)
} else if (options?.name) {
this.disableAugmentation(options.name)
this.augmentations.disable(options.name)
}
return this
case 'unregister':
// Remove augmentation from pipeline
if (typeof options === 'string') {
this.unregister(options)
this.augmentations.remove(options)
} else if (options?.name) {
this.unregister(options.name)
this.augmentations.remove(options.name)
}
return this
case 'enable-type':
// Enable all augmentations of a type
if (typeof options === 'string') {
const validTypes = ['sense', 'conduit', 'cognition', 'memory', 'perception', 'dialog', 'activation', 'webSocket'] as const
if (validTypes.includes(options as any)) {
return this.enableAugmentationType(options as any)
}
return this.augmentations.enableType(options as any)
} else if (options?.type) {
const validTypes = ['sense', 'conduit', 'cognition', 'memory', 'perception', 'dialog', 'activation', 'webSocket'] as const
if (validTypes.includes(options.type as any)) {
return this.enableAugmentationType(options.type as any)
}
return this.augmentations.enableType(options.type as any)
}
throw new Error('Invalid augmentation type')
case 'disable-type':
// Disable all augmentations of a type
if (typeof options === 'string') {
const validTypes = ['sense', 'conduit', 'cognition', 'memory', 'perception', 'dialog', 'activation', 'webSocket'] as const
if (validTypes.includes(options as any)) {
return this.disableAugmentationType(options as any)
}
return this.augmentations.disableType(options as any)
} else if (options?.type) {
const validTypes = ['sense', 'conduit', 'cognition', 'memory', 'perception', 'dialog', 'activation', 'webSocket'] as const
if (validTypes.includes(options.type as any)) {
return this.disableAugmentationType(options.type as any)
}
return this.augmentations.disableType(options.type as any)
}
throw new Error('Invalid augmentation type')

View file

@ -339,6 +339,9 @@ import type {
} from './types/augmentations.js'
import { AugmentationType, BrainyAugmentations } from './types/augmentations.js'
// Export augmentation manager for type-safe augmentation management
export { AugmentationManager, type AugmentationInfo } from './augmentationManager.js'
export type { IAugmentation, AugmentationResponse, IWebSocketSupport }
export {
AugmentationType,