brainy/src/augmentations
David Snelling 93d2d70a44 fix: resolve VFS tree corruption from blob errors (v5.8.0)
CRITICAL FIX: Single blob read error no longer corrupts entire VFS tree

Root Causes Fixed:
1. Uncaught blob errors in readFile() triggered VFS re-initialization
2. Race conditions in initializeRoot() created duplicate roots
3. Wrong root selection algorithm (oldest vs most children)

Architectural Solution:
- **Error Isolation**: Blob errors caught and re-thrown as VFSError
  VFS tree structure completely isolated from file content errors
  (src/vfs/VirtualFileSystem.ts:288-321)

- **Singleton Promise Pattern**: Prevents duplicate root creation
  Concurrent init() calls wait for same initialization promise
  Acts as automatic mutex without custom lock class
  (src/vfs/VirtualFileSystem.ts:180-199)

- **Smart Root Selection**: Selects root with MOST children (not oldest)
  Auto-heals existing duplicates on init()
  Logs cleanup suggestions for empty roots
  (src/vfs/VirtualFileSystem.ts:283-334)

Production Impact:
- Workshop production: 5 duplicate roots, 1,836 files orphaned
- After fix: Zero duplicate roots possible, auto-healing
- All 100 VFS tests pass 

Additional Fix: Remove Sharp native dependency (v5.8.0)

ImageHandler rewritten using pure JavaScript:
- exifr (already installed) for EXIF extraction
- probe-image-size for image dimensions/format
- Zero native dependencies (removed 10MB of native binaries)
- All 25 image handler tests pass 
- No more test crashes from Sharp/libvips worker thread issues

Test Results:
- VFS tests: 100/100 pass 
- Image handler tests: 25/25 pass 
- Overall: 1157/1200 tests pass (18 pre-existing timeout issues)
- Build: Successful, zero TypeScript errors 

Features Complete (TIER 1 - v5.8.0):
- Transaction system (36 unit + 35 integration tests)
- Duplicate check optimization (O(n) → O(log n))
- GraphIndex pagination
- Comprehensive filter documentation
2025-11-14 11:27:35 -08:00
..
discovery feat: add browser environment compatibility support 2025-09-17 15:48:02 -07:00
display fix: update all Stage 2 references to Stage 3 CANONICAL type counts 2025-11-06 09:40:33 -08:00
intelligentImport fix: resolve VFS tree corruption from blob errors (v5.8.0) 2025-11-14 11:27:35 -08:00
typeMatching fix: update tests for Stage 3 CANONICAL taxonomy (42 nouns, 127 verbs) 2025-11-11 10:09:01 -08:00
apiServerAugmentation.ts feat: remove legacy ImportManager, standardize getStats() API 2025-10-09 11:40:31 -07:00
auditLogAugmentation.ts feat: add browser environment compatibility support 2025-09-17 15:48:02 -07:00
AugmentationMetadataContract.ts feat: comprehensive metadata namespace architecture and cleanup system 2025-08-27 15:38:48 -07:00
batchProcessingAugmentation.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
brainyAugmentation.ts feat: add COW infrastructure exports and augmentation helpers for v5.0.0 2025-11-01 11:55:47 -07:00
cacheAugmentation.ts fix: critical bug fixes for v5.1.0 release 2025-11-02 11:26:13 -08:00
conduitAugmentations.ts feat: modernize API architecture and deprecation handling 2025-09-17 11:54:20 -07:00
configResolver.ts feat: add browser environment compatibility support 2025-09-17 14:53:54 -07:00
connectionPoolAugmentation.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
defaultAugmentations.ts feat: add intelligent import for CSV, Excel, and PDF files 2025-10-01 16:51:03 -07:00
discovery.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
entityRegistryAugmentation.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
indexAugmentation.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
intelligentVerbScoringAugmentation.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
manifest.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
metadataEnforcer.ts feat: comprehensive metadata namespace architecture and cleanup system 2025-08-27 15:38:48 -07:00
metricsAugmentation.ts feat: add complete silent mode for TUI applications 2025-09-16 13:18:49 -07:00
monitoringAugmentation.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
neuralImport.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
rateLimitAugmentation.ts feat: add distributed scaling and enterprise features for v3 2025-09-08 14:26:09 -07:00
README.md feat: add intelligent import for CSV, Excel, and PDF files 2025-10-01 16:51:03 -07:00
requestDeduplicatorAugmentation.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
storageAugmentation.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
storageAugmentations.ts feat(v4.0.0): Complete metadata/vector separation architecture with Azure support 2025-10-17 12:29:27 -07:00
synapseAugmentation.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
universalDisplayAugmentation.ts fix: update all Stage 2 references to Stage 3 CANONICAL type counts 2025-11-06 09:40:33 -08:00
versioningAugmentation.ts feat: add entity versioning system with critical bug fixes (v5.3.0) 2025-11-04 11:19:02 -08:00

Brainy Logo

Brainy Augmentations

This directory contains the augmentation implementations for Brainy. Augmentations are pluggable components that extend Brainy's functionality in various ways.

Available Augmentations

Core Augmentations

IntelligentImportAugmentation

Automatically detects and processes CSV, Excel, and PDF files with intelligent extraction. This augmentation is enabled by default and provides:

  • CSV Support: Auto-detection of encoding, delimiters, and field types
  • Excel Support: Multi-sheet extraction with metadata preservation
  • PDF Support: Text extraction, table detection, and metadata extraction
  • Type Inference: Automatically infers data types (string, number, boolean, date)
  • Neural Integration: Seamlessly integrates with entity extraction and relationship detection
import { Brainy } from '@soulcraft/brainy'

const brain = new Brainy({
  intelligentImport: {
    enableCSV: true,
    enableExcel: true,
    enablePDF: true,
    maxFileSize: 100 * 1024 * 1024  // 100MB
  }
})
await brain.init()

// Import CSV with auto-detection
await brain.import('customers.csv')

// Import Excel with specific sheets
await brain.import('sales-data.xlsx', {
  excelSheets: ['Q1', 'Q2']
})

// Import PDF with table extraction
await brain.import('report.pdf', {
  pdfExtractTables: true
})

See: Import Anything Guide | Example

Conduit Augmentations

Conduit augmentations provide data synchronization between Brainy instances.

WebSocketConduitAugmentation

A conduit augmentation that syncs Brainy instances using WebSockets. This is used for syncing between browsers and servers, or between servers.

import { createConduitAugmentation, augmentationPipeline } from '@soulcraft/brainy'

// Create a WebSocket conduit augmentation
const wsConduit = await createConduitAugmentation('websocket', 'my-websocket-sync')

// Register the augmentation with the pipeline
augmentationPipeline.register(wsConduit)

// Connect to another Brainy instance
const connectionResult = await wsConduit.establishConnection(
  'wss://your-websocket-server.com/brainy-sync',
  { protocols: 'brainy-sync' }
)

WebRTCConduitAugmentation

A conduit augmentation that syncs Brainy instances using WebRTC. This is used for direct peer-to-peer syncing between browsers.

import { createConduitAugmentation, augmentationPipeline } from '@soulcraft/brainy'

// Create a WebRTC conduit augmentation
const webrtcConduit = await createConduitAugmentation('webrtc', 'my-webrtc-sync')

// Register the augmentation with the pipeline
augmentationPipeline.register(webrtcConduit)

// Connect to a peer
const connectionResult = await webrtcConduit.establishConnection(
  'peer-id-to-connect-to',
  {
    signalServerUrl: 'wss://your-signal-server.com',
    localPeerId: 'my-peer-id',
    iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
  }
)

ServerSearchConduitAugmentation

A specialized conduit augmentation that provides functionality for searching a server-hosted Brainy instance and storing results locally. This allows you to:

  • Search a server-hosted Brainy instance from a browser
  • Store the search results in a local Brainy instance
  • Perform further searches against the local instance without needing to query the server again
  • Add data to both local and server instances
import {
  ServerSearchConduitAugmentation,
  createServerSearchAugmentations,
  augmentationPipeline
} from '@soulcraft/brainy'

// Using the factory function (recommended)
const { conduit, activation, connection } = await createServerSearchAugmentations(
  'wss://your-brainy-server.com/ws',
  { protocols: 'brainy-sync' }
)

// Register the augmentations with the pipeline
augmentationPipeline.register(conduit)
augmentationPipeline.register(activation)

// Search the server and store results locally
const serverSearchResult = await conduit.searchServer(
  connection.connectionId,
  'your search query',
  5 // limit
)

// Search the local instance
const localSearchResult = await conduit.searchLocal('your search query', 5)

// Perform a combined search (local first, then server if needed)
const combinedSearchResult = await conduit.searchCombined(
  connection.connectionId,
  'your search query',
  5
)

// Add data to both local and server
const addResult = await conduit.addToBoth(
  connection.connectionId,
  'Text to add',
  { /* metadata */ }
)

Activation Augmentations

Activation augmentations dictate how Brainy initiates actions, responses, or data manipulations.

ServerSearchActivationAugmentation

An activation augmentation that provides actions for server search functionality. This works in conjunction with the ServerSearchConduitAugmentation to provide a complete solution for browser-server search.

import {
  ServerSearchActivationAugmentation,
  createServerSearchAugmentations,
  augmentationPipeline
} from '@soulcraft/brainy'

// Using the factory function (recommended)
const { conduit, activation, connection } = await createServerSearchAugmentations(
  'wss://your-brainy-server.com/ws',
  { protocols: 'brainy-sync' }
)

// Register the augmentations with the pipeline
augmentationPipeline.register(conduit)
augmentationPipeline.register(activation)

// Use the activation augmentation to search the server
const serverSearchAction = activation.triggerAction('searchServer', {
  connectionId: connection.connectionId,
  query: 'your search query',
  limit: 5
})

if (serverSearchAction.success) {
  // The data property contains a promise that will resolve to the search results
  const serverSearchResult = await serverSearchAction.data
  console.log('Server search results:', serverSearchResult)
}

// Other available actions:
// - 'connectToServer': Connect to a server
// - 'searchLocal': Search the local instance
// - 'searchCombined': Search both local and server
// - 'addToBoth': Add data to both local and server

Using the Augmentation Pipeline

The augmentation pipeline provides a way to execute augmentations based on their type.

import { augmentationPipeline } from '@soulcraft/brainy'

// Execute a conduit augmentation
const conduitResults = await augmentationPipeline.executeConduitPipeline(
  'methodName',
  [arg1, arg2, ...],
  { /* options */ }
)

// Execute an activation augmentation
const activationResults = await augmentationPipeline.executeActivationPipeline(
  'methodName',
  [arg1, arg2, ...],
  { /* options */ }
)

Creating Custom Augmentations

To create a custom augmentation, implement one of the augmentation interfaces:

  • ISenseAugmentation: For processing raw data
  • IConduitAugmentation: For data synchronization
  • ICognitionAugmentation: For reasoning and inference
  • IMemoryAugmentation: For data storage
  • IPerceptionAugmentation: For data interpretation and visualization
  • IDialogAugmentation: For natural language processing
  • IActivationAugmentation: For triggering actions

Example:

import { AugmentationType, IActivationAugmentation } from '@soulcraft/brainy'

class MyCustomActivation implements IActivationAugmentation {
  readonly
  name = 'my-custom-activation'
  readonly
  description = 'My custom activation augmentation'
  enabled = true

  getType(): AugmentationType {
    return AugmentationType.ACTIVATION
  }

  async initialize(): Promise<void> {
    // Initialization code
  }

  async shutDown(): Promise<void> {
    // Cleanup code
  }

  async getStatus(): Promise<'active' | 'inactive' | 'error'> {
    return 'active'
  }

  triggerAction(actionName: string, parameters

?:

  Record<string, unknown>

):

  AugmentationResponse<unknown> {
    // Implementation
  }

  generateOutput(knowledgeId: string, format: string): AugmentationResponse<string | Record<string, unknown

>> {
  // Implementation
}

interactExternal(systemId
:
string, payload
:
Record < string, unknown >
):
AugmentationResponse < unknown > {
  // Implementation
}
}