import React, { useState } from 'react'; import { CognitionAnalysisEvent } from '../utils/metaCognitionEventProcessor'; import type { SerializedCognitionState } from '@just-every/task'; import type { TaskState } from '../hooks/useTaskState'; import { formatDuration } from '../utils/formatters'; import './style.scss'; import './CognitionView.scss'; import { NoContent } from './NoContent'; export interface CognitionViewProps { taskState: TaskState; className?: string; } export const CognitionView: React.FC = ({ taskState, className = '' }) => { const [activeTab, setActiveTab] = useState<'events' | 'state'>('events'); const renderAnalysisEvent = (event: CognitionAnalysisEvent) => (
{event.isRunning ? ( <>⟳ Running ) : ( <>✓ Completed )} {new Date(event.startedAt).toLocaleTimeString()} {event.processingTime && ( {formatDuration(event.processingTime)} )}
Request #{event.requestCount}
{event.adjustments && event.adjustments.length > 0 && (
Adjustments ({event.adjustments.length})
    {event.adjustments.map((adj, i) => (
  • {adj}
  • ))}
)} {event.injectedThoughts && event.injectedThoughts.length > 0 && (
Injected Thoughts ({event.injectedThoughts.length})
{event.injectedThoughts.map((thought, i) => (
💭
{thought}
))}
)}
); const renderState = (state: SerializedCognitionState) => (
Frequency
{state.frequency || 'Default'}
Thought Delay
{state.thoughtDelay || 0}s
Processing
{state.processing ? 'Yes' : 'No'}
{state.disabledModels && state.disabledModels.length > 0 && (
Disabled Models
    {state.disabledModels.map((model: string) => (
  • {model}
  • ))}
)} {state.modelScores && Object.keys(state.modelScores).length > 0 && (
Model Scores
{Object.entries(state.modelScores).map(([model, score]) => (
{model} {score as number}
))}
)}
); return (

Meta-Cognition

{taskState.cognitionData.stats.totalAnalyses} Total
{taskState.cognitionData.stats.completedAnalyses} Completed
{taskState.cognitionData.stats.totalAdjustments} Adjustments
{taskState.cognitionData.stats.totalInjectedThoughts} Thoughts
{taskState.cognitionData.stats.averageProcessingTime > 0 && (
{formatDuration(taskState.cognitionData.stats.averageProcessingTime)} Avg Time
)}
{activeTab === 'events' && (<> {taskState.cognitionData.analysisEvents.length > 0 ? (
{taskState.cognitionData.analysisEvents .sort((a, b) => b.startedAt - a.startedAt) .map(renderAnalysisEvent)}
) : ( )} )} {activeTab === 'state' && (<> {taskState.cognitionData.currentState ? (
{renderState(taskState.cognitionData.currentState)}
) : ( )} )}
); };