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

@ -1,5 +1,5 @@
/**
* Intelligent Type Matcher - Uses embeddings for semantic type detection
* BrainyTypes - Intelligent type detection using semantic embeddings
*
* This module uses our existing TransformerEmbedding and similarity functions
* to intelligently match data to our 31 noun types and 40 verb types.
@ -139,9 +139,9 @@ export interface TypeMatchResult {
}
/**
* Intelligent Type Matcher using semantic embeddings
* BrainyTypes - Intelligent type detection for nouns and verbs
*/
export class IntelligentTypeMatcher {
export class BrainyTypes {
private embedder: TransformerEmbedding
private nounEmbeddings: Map<string, Vector> = new Map()
private verbEmbeddings: Map<string, Vector> = new Map()
@ -520,15 +520,15 @@ export class IntelligentTypeMatcher {
/**
* Singleton instance for efficient reuse
*/
let globalMatcher: IntelligentTypeMatcher | null = null
let globalInstance: BrainyTypes | null = null
/**
* Get or create the global type matcher instance
* Get or create the global BrainyTypes instance
*/
export async function getTypeMatcher(): Promise<IntelligentTypeMatcher> {
if (!globalMatcher) {
globalMatcher = new IntelligentTypeMatcher()
await globalMatcher.init()
export async function getBrainyTypes(): Promise<BrainyTypes> {
if (!globalInstance) {
globalInstance = new BrainyTypes()
await globalInstance.init()
}
return globalMatcher
return globalInstance
}