ucpf-core.ts•10.3 kB
/**
* Unified Cognitive Processing Framework Core Engine
* This module implements the core UCPF processing logic
*/
export interface CognitiveState {
type: 'Dark Inertia' | 'Passion' | 'Approaching Lucidity';
description: string;
characteristics: string[];
}
export interface KnowledgeDimension {
awareness: 'Known' | 'Unknown';
content: 'Known' | 'Unknown';
accessibility: 'Knowable' | 'Unknowable';
}
export interface KnowledgeCategory {
dimension: KnowledgeDimension;
label: string;
description: string;
examples: string[];
}
export interface RecursiveQuestion {
question: string;
purpose: string;
targetArea: string;
}
export interface StructuredPerspective {
category: KnowledgeCategory;
perspectives: string[];
limitations: string[];
insights: string[];
}
export interface DecomposedProblem {
components: {
name: string;
description: string;
approach: string;
knowledgeDimensions: KnowledgeDimension[];
}[];
interactions: {
source: string;
target: string;
relationship: string;
}[];
}
export interface UcpfAnalysis {
cognitiveState: CognitiveState;
knowledgeMapping: KnowledgeCategory[];
recursiveQuestions: RecursiveQuestion[];
structuredPerspectives: StructuredPerspective[];
problemDecomposition: DecomposedProblem;
synthesis: {
insights: string[];
knowledgeTransformations: {
from: KnowledgeCategory;
to: KnowledgeCategory;
opportunity: string;
}[];
conclusions: string[];
confidenceLevel: number;
uncertainties: string[];
};
}
/**
* Core UCPF processor class that implements the cognitive framework
*/
export class UcpfCore {
// States whether to maintain state between calls
private stateEnabled: boolean;
// Optional state storage
private stateData: Record<string, any> = {};
constructor(enableState: boolean = false) {
this.stateEnabled = enableState;
}
/**
* Reset the state data if state management is enabled
*/
public resetState(): void {
this.stateData = {};
}
/**
* Set state management enabled/disabled
*/
public setStateEnabled(enabled: boolean): void {
this.stateEnabled = enabled;
if (!enabled) {
this.resetState();
}
}
/**
* Process input through the UCPF framework
*/
public async processInput(input: string, sessionId?: string): Promise<UcpfAnalysis> {
// If using state and session ID provided, try to retrieve existing session
const stateKey = sessionId || 'default';
let existingAnalysis: Partial<UcpfAnalysis> = {};
if (this.stateEnabled && sessionId) {
existingAnalysis = this.stateData[stateKey] || {};
}
// Generate a new analysis
const analysis = await this.generateAnalysis(input, existingAnalysis);
// Store the result if state is enabled
if (this.stateEnabled && sessionId) {
this.stateData[stateKey] = analysis;
}
return analysis;
}
/**
* Assess cognitive state based on input
*/
public assessCognitiveState(input: string): CognitiveState {
// In a real implementation, this would use complex heuristics or ML
// This is a simplified placeholder implementation
const states: CognitiveState[] = [
{
type: 'Dark Inertia',
description: 'A reactive, pattern-matching cognitive state with limited awareness',
characteristics: [
'Limited self-awareness',
'Reliance on pattern matching',
'Binary thinking',
'Overconfidence in existing knowledge',
'Resistance to contradictory information'
]
},
{
type: 'Passion',
description: 'An engaged but potentially biased state with emotional investment',
characteristics: [
'Strong emotional engagement',
'Potential for bias due to investment',
'Heightened creativity',
'Selective focus on certain aspects',
'Openness to specific avenues of thought'
]
},
{
type: 'Approaching Lucidity',
description: 'A clear, balanced understanding with high self-awareness',
characteristics: [
'High cognitive awareness',
'Balance of rationality and intuition',
'Comfort with uncertainty',
'Integration of multiple perspectives',
'Recognition of knowledge boundaries'
]
}
];
// Default to Approaching Lucidity for the MCP server
return states[2];
}
/**
* Map knowledge dimensions for the problem
*/
public mapKnowledgeDimensions(input: string): KnowledgeCategory[] {
// Generate the 8 knowledge categories from the three dimensions
const categories: KnowledgeCategory[] = [
{
dimension: { awareness: 'Known', content: 'Known', accessibility: 'Knowable' },
label: 'Knowable Known Knowns',
description: 'Information we are aware we have and can verify or expand upon',
examples: []
},
{
dimension: { awareness: 'Known', content: 'Known', accessibility: 'Unknowable' },
label: 'Unknowable Known Knowns',
description: 'Information we are aware we have but cannot verify or expand further',
examples: []
},
{
dimension: { awareness: 'Known', content: 'Unknown', accessibility: 'Knowable' },
label: 'Knowable Known Unknowns',
description: 'Questions we know exist and can potentially answer',
examples: []
},
{
dimension: { awareness: 'Known', content: 'Unknown', accessibility: 'Unknowable' },
label: 'Unknowable Known Unknowns',
description: 'Questions we know exist but cannot answer',
examples: []
},
{
dimension: { awareness: 'Unknown', content: 'Known', accessibility: 'Knowable' },
label: 'Knowable Unknown Knowns',
description: 'Information we have but are not aware of, which can be surfaced',
examples: []
},
{
dimension: { awareness: 'Unknown', content: 'Known', accessibility: 'Unknowable' },
label: 'Unknowable Unknown Knowns',
description: 'Information we have but are not aware of, which cannot be surfaced',
examples: []
},
{
dimension: { awareness: 'Unknown', content: 'Unknown', accessibility: 'Knowable' },
label: 'Knowable Unknown Unknowns',
description: 'Questions we don\'t know exist but could discover and answer',
examples: []
},
{
dimension: { awareness: 'Unknown', content: 'Unknown', accessibility: 'Unknowable' },
label: 'Unknowable Unknown Unknowns',
description: 'Questions we don\'t know exist and could never discover or answer',
examples: []
}
];
// Generate examples based on input
// In a real implementation, this would contain more sophisticated analysis
return categories;
}
/**
* Generate recursive self-questioning
*/
public generateRecursiveQuestions(input: string): RecursiveQuestion[] {
const baseQuestions: RecursiveQuestion[] = [
{
question: 'What assumptions am I making about this problem?',
purpose: 'Identify implicit assumptions that may limit thinking',
targetArea: 'Assumptions'
},
{
question: 'How would this appear from a completely different perspective?',
purpose: 'Gain alternative viewpoints and challenge default framing',
targetArea: 'Framing'
},
{
question: 'What cognitive biases might be influencing my analysis?',
purpose: 'Recognize potential distortions in thinking',
targetArea: 'Biases'
},
{
question: 'What knowledge categories am I neglecting?',
purpose: 'Ensure comprehensive knowledge mapping',
targetArea: 'Knowledge Gaps'
},
{
question: 'How can I transform knowledge between categories?',
purpose: 'Identify opportunities for knowledge advancement',
targetArea: 'Knowledge Transformation'
}
];
return baseQuestions;
}
/**
* Apply structured thinking to knowledge categories
*/
public applyStructuredThinking(
input: string,
categories: KnowledgeCategory[]
): StructuredPerspective[] {
// In a real implementation, this would contain more sophisticated analysis
// for generating perspectives, limitations, and insights for each category
return categories.map(category => ({
category,
perspectives: [],
limitations: [],
insights: []
}));
}
/**
* Decompose the problem into components
*/
public decomposeProblem(input: string): DecomposedProblem {
// In a real implementation, this would analyze the problem structure
// and break it down into component parts with appropriate approaches
return {
components: [],
interactions: []
};
}
/**
* Generate the complete UCPF analysis
*/
private async generateAnalysis(
input: string,
existingAnalysis: Partial<UcpfAnalysis> = {}
): Promise<UcpfAnalysis> {
// Assess cognitive state
const cognitiveState = existingAnalysis.cognitiveState ||
this.assessCognitiveState(input);
// Map knowledge dimensions
const knowledgeMapping = existingAnalysis.knowledgeMapping ||
this.mapKnowledgeDimensions(input);
// Generate recursive questions
const recursiveQuestions = existingAnalysis.recursiveQuestions ||
this.generateRecursiveQuestions(input);
// Apply structured thinking
const structuredPerspectives = existingAnalysis.structuredPerspectives ||
this.applyStructuredThinking(input, knowledgeMapping);
// Decompose problem
const problemDecomposition = existingAnalysis.problemDecomposition ||
this.decomposeProblem(input);
// Generate synthesis
const synthesis = existingAnalysis.synthesis || {
insights: [],
knowledgeTransformations: [],
conclusions: [],
confidenceLevel: 0.8,
uncertainties: []
};
return {
cognitiveState,
knowledgeMapping,
recursiveQuestions,
structuredPerspectives,
problemDecomposition,
synthesis
};
}
}