feat: implement comprehensive type safety system with BrainyTypes API

Major enhancements for type safety and developer experience:

- Add BrainyTypes static API for type management and AI-powered suggestions
- Implement strict type validation for all 31 NounType categories
- Remove dangerous generic add() method that bypassed type safety
- Add intelligent type inference with confidence scoring
- Provide helpful error messages with typo suggestions using Levenshtein distance
- Update all internal code, examples, and documentation to use typed methods
- Enhance CLI with new type management commands (types, suggest, validate)

Breaking changes:
- Remove deprecated add() method - use addNoun() with explicit type parameter
- All addNoun() calls now require explicit type as second parameter

This release significantly improves type safety across the entire system while
maintaining backward compatibility for properly typed method calls.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
David Snelling 2025-09-01 09:37:36 -07:00
parent d7d2d749b6
commit 6c62bc4e9d
40 changed files with 1704 additions and 497 deletions

View file

@ -11,7 +11,7 @@ import { BaseAugmentation, AugmentationContext } from './brainyAugmentation.js'
import { NounType, VerbType } from '../types/graphTypes.js'
import * as fs from '../universal/fs.js'
import * as path from '../universal/path.js'
import { IntelligentTypeMatcher, getTypeMatcher } from './typeMatching/intelligentTypeMatcher.js'
import { BrainyTypes, getBrainyTypes } from './typeMatching/brainyTypes.js'
import { prodLog } from '../utils/logger.js'
// Neural Import Analysis Types
@ -74,7 +74,7 @@ export class NeuralImportAugmentation extends BaseAugmentation {
private config: NeuralImportConfig
private analysisCache = new Map<string, NeuralAnalysisResult>()
private typeMatcher: IntelligentTypeMatcher | null = null
private typeMatcher: BrainyTypes | null = null
constructor(config: Partial<NeuralImportConfig> = {}) {
super()
@ -89,7 +89,7 @@ export class NeuralImportAugmentation extends BaseAugmentation {
protected async onInitialize(): Promise<void> {
try {
this.typeMatcher = await getTypeMatcher()
this.typeMatcher = await getBrainyTypes()
this.log('🧠 Neural Import augmentation initialized with intelligent type matching')
} catch (error) {
this.log('⚠️ Failed to initialize type matcher, falling back to heuristics', 'warn')
@ -460,7 +460,7 @@ export class NeuralImportAugmentation extends BaseAugmentation {
private async inferNounType(obj: any): Promise<string> {
if (!this.typeMatcher) {
// Initialize type matcher if not available
this.typeMatcher = await getTypeMatcher()
this.typeMatcher = await getBrainyTypes()
}
const result = await this.typeMatcher.matchNounType(obj)
@ -516,7 +516,7 @@ export class NeuralImportAugmentation extends BaseAugmentation {
private async inferVerbType(fieldName: string, sourceObj?: any, targetObj?: any): Promise<string> {
if (!this.typeMatcher) {
// Initialize type matcher if not available
this.typeMatcher = await getTypeMatcher()
this.typeMatcher = await getBrainyTypes()
}
const result = await this.typeMatcher.matchVerbType(sourceObj, targetObj, fieldName)