export type PromptLevel = 0 | 1 | 2 | 3 | 4 // Galperin stages mapped to prompt levels export const GALPERIN_STAGES = { HAND: 0, // Concrete: full model, show the answer EXTERNAL_SPEECH: 1, // Prompts the child to say out loud INNER_SPEECH: 2, // Partial prompt, whisper MENTAL: 3, // Verbal cue only MASTERED: 4, // No prompt } as const export interface PromptState { level: PromptLevel consecutiveCorrect: number consecutiveIncorrect: number } export function getInitialState(): PromptState { return { level: 0, consecutiveCorrect: 0, consecutiveIncorrect: 0, } } export function evaluateResponse( state: PromptState, correct: boolean, masterThreshold: number = 3, regressThreshold: number = 2, ): PromptState { if (correct) { const newCorrect = state.consecutiveCorrect + 1 const newLevel = newCorrect >= masterThreshold ? (Math.min(state.level + 1, 4) as PromptLevel) : state.level return { level: newLevel, consecutiveCorrect: newCorrect, consecutiveIncorrect: 0, } } const newIncorrect = state.consecutiveIncorrect + 1 const newLevel = newIncorrect >= regressThreshold ? (Math.max(state.level - 1, 0) as PromptLevel) : state.level return { level: newLevel, consecutiveCorrect: 0, consecutiveIncorrect: newIncorrect, } } export function shouldShowPrompt(level: PromptLevel): boolean { return level < 3 } export function isMastered(level: PromptLevel): boolean { return level >= 4 }