chore: recovery checkpoint - v3.0 API successfully recovered

CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB

Recovery Status:
- Successfully recovered brainy.ts from compiled JavaScript
- All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.)
- Neural subsystem intact (562KB embedded patterns, NLP working)
- Augmentation pipeline operational (20+ augmentations)
- HNSW clustering system complete
- Triple Intelligence compiled (needs constructor fix)
- Test suite validates functionality

Changes preserved:
- 898 files with changes from last 3 days
- 144,475 insertions
- All augmentation improvements
- All test coverage enhancements
- Complete v3.0 feature set

This is a LOCAL checkpoint only - contains recovered work after corruption incident.
Created backup in .backups/brainy-full-20250910-151314.tar.gz

Branch: recovery-checkpoint-20250910-151433
Date: Wed Sep 10 03:18:04 PM PDT 2025
This commit is contained in:
David Snelling 2025-09-10 15:18:04 -07:00
parent f65455fb22
commit 8ff382ca3b
895 changed files with 143654 additions and 28268 deletions

View file

@ -0,0 +1,247 @@
/**
* Local Augmentation Discovery
*
* Discovers augmentations installed locally in node_modules
* and built-in augmentations that ship with Brainy
*/
import { existsSync, readdirSync, readFileSync } from 'fs';
import { join } from 'path';
/**
* Discovers augmentations installed locally
*/
export class LocalAugmentationDiscovery {
constructor(options = {}) {
this.options = options;
this.builtInAugmentations = new Map();
this.installedAugmentations = new Map();
this.options = {
brainyPath: this.options.brainyPath || this.findBrainyPath(),
projectPath: this.options.projectPath || process.cwd(),
scanNodeModules: this.options.scanNodeModules ?? true
};
// Register built-in augmentations
this.registerBuiltIn();
}
/**
* Register built-in augmentations that ship with Brainy
*/
registerBuiltIn() {
const builtIn = [
{ id: 'wal', name: 'Write-Ahead Log', path: 'walAugmentation' },
{ id: 'cache', name: 'Cache', path: 'cacheAugmentation' },
{ id: 'batch', name: 'Batch Processing', path: 'batchProcessingAugmentation' },
{ id: 'entity-registry', name: 'Entity Registry', path: 'entityRegistryAugmentation' },
{ id: 'index', name: 'Index', path: 'indexAugmentation' },
{ id: 'metrics', name: 'Metrics', path: 'metricsAugmentation' },
{ id: 'monitoring', name: 'Monitoring', path: 'monitoringAugmentation' },
{ id: 'connection-pool', name: 'Connection Pool', path: 'connectionPoolAugmentation' },
{ id: 'request-deduplicator', name: 'Request Deduplicator', path: 'requestDeduplicatorAugmentation' },
{ id: 'api-server', name: 'API Server', path: 'apiServerAugmentation' },
{ id: 'neural-import', name: 'Neural Import', path: 'neuralImport' },
{ id: 'intelligent-verb-scoring', name: 'Intelligent Verb Scoring', path: 'intelligentVerbScoringAugmentation' },
{ id: 'universal-display', name: 'Universal Display', path: 'universalDisplayAugmentation' },
// Storage augmentations
{ id: 'memory-storage', name: 'Memory Storage', path: 'storageAugmentations', export: 'MemoryStorageAugmentation' },
{ id: 'filesystem-storage', name: 'FileSystem Storage', path: 'storageAugmentations', export: 'FileSystemStorageAugmentation' },
{ id: 'opfs-storage', name: 'OPFS Storage', path: 'storageAugmentations', export: 'OPFSStorageAugmentation' },
{ id: 's3-storage', name: 'S3 Storage', path: 'storageAugmentations', export: 'S3StorageAugmentation' },
];
for (const aug of builtIn) {
this.builtInAugmentations.set(aug.id, {
id: aug.id,
name: aug.name,
source: 'builtin',
path: `@soulcraft/brainy/augmentations/${aug.path}`,
package: {
name: '@soulcraft/brainy',
version: 'builtin',
description: `Built-in ${aug.name} augmentation`
}
});
}
}
/**
* Find Brainy installation path
*/
findBrainyPath() {
// Try to find brainy in node_modules
const possiblePaths = [
join(process.cwd(), 'node_modules', '@soulcraft', 'brainy'),
join(process.cwd(), 'node_modules', 'brainy'),
join(process.cwd(), '..', 'node_modules', '@soulcraft', 'brainy'),
];
for (const path of possiblePaths) {
if (existsSync(path)) {
return path;
}
}
// Fallback to current directory
return process.cwd();
}
/**
* Discover all augmentations
*/
async discoverAll() {
const augmentations = [];
// Add built-in augmentations
augmentations.push(...this.builtInAugmentations.values());
// Scan node_modules if enabled
if (this.options.scanNodeModules) {
const installed = await this.scanNodeModules();
augmentations.push(...installed);
}
// Scan local project
const local = await this.scanLocalProject();
augmentations.push(...local);
return augmentations;
}
/**
* Scan node_modules for installed augmentations
*/
async scanNodeModules() {
const augmentations = [];
const nodeModulesPath = join(this.options.projectPath, 'node_modules');
if (!existsSync(nodeModulesPath)) {
return augmentations;
}
// Scan @brainy/* packages
const brainyPath = join(nodeModulesPath, '@brainy');
if (existsSync(brainyPath)) {
const packages = readdirSync(brainyPath);
for (const pkg of packages) {
const augmentation = await this.loadPackageAugmentation(join(brainyPath, pkg));
if (augmentation) {
augmentations.push(augmentation);
}
}
}
// Scan packages with brainy-augmentation keyword
const packages = readdirSync(nodeModulesPath);
for (const pkg of packages) {
if (pkg.startsWith('@') || pkg.startsWith('.'))
continue;
const pkgPath = join(nodeModulesPath, pkg);
const packageJson = this.loadPackageJson(pkgPath);
if (packageJson?.keywords?.includes('brainy-augmentation')) {
const augmentation = await this.loadPackageAugmentation(pkgPath);
if (augmentation) {
augmentations.push(augmentation);
}
}
}
return augmentations;
}
/**
* Scan local project for augmentations
*/
async scanLocalProject() {
const augmentations = [];
// Check for augmentations directory
const augPath = join(this.options.projectPath, 'augmentations');
if (existsSync(augPath)) {
const files = readdirSync(augPath);
for (const file of files) {
if (file.endsWith('.ts') || file.endsWith('.js')) {
const name = file.replace(/\.(ts|js)$/, '');
augmentations.push({
id: name,
name: this.humanizeName(name),
source: 'local',
path: join(augPath, file)
});
}
}
}
return augmentations;
}
/**
* Load augmentation from package
*/
async loadPackageAugmentation(pkgPath) {
const packageJson = this.loadPackageJson(pkgPath);
if (!packageJson)
return null;
// Check if it's a brainy augmentation
const isBrainyAug = packageJson.keywords?.includes('brainy-augmentation') ||
packageJson.brainy?.type === 'augmentation';
if (!isBrainyAug)
return null;
const manifest = packageJson.brainy?.manifest || null;
return {
id: packageJson.brainy?.id || packageJson.name.replace('@brainy/', ''),
name: packageJson.brainy?.name || packageJson.name,
source: 'npm',
path: pkgPath,
manifest,
package: {
name: packageJson.name,
version: packageJson.version,
description: packageJson.description
}
};
}
/**
* Load package.json
*/
loadPackageJson(pkgPath) {
const packageJsonPath = join(pkgPath, 'package.json');
if (!existsSync(packageJsonPath))
return null;
try {
return JSON.parse(readFileSync(packageJsonPath, 'utf8'));
}
catch {
return null;
}
}
/**
* Convert name to human-readable format
*/
humanizeName(name) {
return name
.replace(/[-_]/g, ' ')
.replace(/augmentation/gi, '')
.replace(/\b\w/g, l => l.toUpperCase())
.trim();
}
/**
* Get built-in augmentations
*/
getBuiltIn() {
return Array.from(this.builtInAugmentations.values());
}
/**
* Get installed augmentations
*/
getInstalled() {
return Array.from(this.installedAugmentations.values());
}
/**
* Check if augmentation is installed
*/
isInstalled(id) {
return this.builtInAugmentations.has(id) ||
this.installedAugmentations.has(id);
}
/**
* Get import path for augmentation
*/
getImportPath(id) {
const aug = this.builtInAugmentations.get(id) ||
this.installedAugmentations.get(id);
return aug?.path || null;
}
/**
* Load augmentation module dynamically
*/
async loadAugmentation(id) {
const path = this.getImportPath(id);
if (!path) {
throw new Error(`Augmentation ${id} not found`);
}
// Dynamic import
const module = await import(path);
return module.default || module;
}
}
//# sourceMappingURL=localDiscovery.js.map