Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: imagination & ideation drills (M55 P3)
Adam Eivy8b61a93622b8
diff --git a/client/src/components/meatspace/post/PostLlmDrillRunner.jsx b/client/src/components/meatspace/post/PostLlmDrillRunner.jsxindex 7b92a529a1..6017ea36dd 100644--- a/client/src/components/meatspace/post/PostLlmDrillRunner.jsx+++ b/client/src/components/meatspace/post/PostLlmDrillRunner.jsx@@ -5,7 +5,12 @@ const DRILL_LABELS = {'story-recall': 'Story Recall','verbal-fluency': 'Verbal Fluency','wit-comeback': 'Wit & Comeback',- 'pun-wordplay': 'Pun & Wordplay'+ 'pun-wordplay': 'Pun & Wordplay',+ 'what-if': 'What If?',+ 'alternative-uses': 'Alternative Uses',+ 'story-prompt': 'Story Prompt',+ 'invention-pitch': 'Invention Pitch',+ 'reframe': 'Reframe',};export default function PostLlmDrillRunner({ drill, timeLimitSec, drillIndex, drillCount, onComplete }) {@@ -247,6 +252,84 @@ export default function PostLlmDrillRunner({ drill, timeLimitSec, drillIndex, drtotalPrompts={totalPrompts}/>)}++ {drillType === 'what-if' && (+ <ImaginationUI+ label="Imagine this scenario"+ prompt={currentPrompt?.prompt}+ badge={currentPrompt?.category}+ badgeColor="bg-cyan-500/20 text-cyan-400"+ placeholder="Describe what would happen..."+ inputValue={inputValue}+ setInputValue={setInputValue}+ onSubmit={handleSubmit}+ inputRef={inputRef}+ questionIndex={questionIndex}+ totalPrompts={totalPrompts}+ />+ )}++ {drillType === 'alternative-uses' && (+ <AlternativeUsesUI+ object={currentPrompt}+ items={items}+ inputValue={inputValue}+ setInputValue={setInputValue}+ onAddItem={handleAddItem}+ onRemoveItem={handleRemoveItem}+ onSubmit={handleSubmit}+ inputRef={inputRef}+ questionIndex={questionIndex}+ totalPrompts={totalPrompts}+ />+ )}++ {drillType === 'story-prompt' && (+ <>+ <div className="text-center py-4">+ <div className="text-sm text-gray-500 mb-3">Write a micro-story using all 3 words:</div>+ <div className="flex justify-center gap-3">+ {(currentPrompt?.words || []).map((w, i) => (+ <span key={i} className="px-3 py-1.5 bg-indigo-500/20 text-indigo-400 rounded-lg text-lg font-medium">{w}</span>+ ))}+ </div>+ </div>+ <TextInput inputRef={inputRef} value={inputValue} onChange={setInputValue} onSubmit={handleSubmit} placeholder="Your micro-story (2-4 sentences)..." buttonLabel="Next" />+ <ProgressBar index={questionIndex} total={totalPrompts} />+ </>+ )}++ {drillType === 'invention-pitch' && (+ <ImaginationUI+ label="Invent a solution"+ prompt={currentPrompt?.problem}+ badge={currentPrompt?.difficulty}+ badgeColor={currentPrompt?.difficulty === 'hard' ? 'bg-port-error/20 text-port-error' : currentPrompt?.difficulty === 'medium' ? 'bg-port-warning/20 text-port-warning' : 'bg-port-success/20 text-port-success'}+ placeholder="Pitch your invention in 2-3 sentences..."+ inputValue={inputValue}+ setInputValue={setInputValue}+ onSubmit={handleSubmit}+ inputRef={inputRef}+ questionIndex={questionIndex}+ totalPrompts={totalPrompts}+ />+ )}++ {drillType === 'reframe' && (+ <ImaginationUI+ label="Reframe positively"+ prompt={currentPrompt?.situation}+ badge={currentPrompt?.severity}+ badgeColor="bg-amber-500/20 text-amber-400"+ placeholder="Find the silver lining..."+ inputValue={inputValue}+ setInputValue={setInputValue}+ onSubmit={handleSubmit}+ inputRef={inputRef}+ questionIndex={questionIndex}+ totalPrompts={totalPrompts}+ />+ )}</div>);}@@ -259,6 +342,11 @@ function getPrompts(drill) {case 'verbal-fluency': return drill.categories || [];case 'wit-comeback': return drill.scenarios || [];case 'pun-wordplay': return drill.challenges || [];+ case 'what-if': return drill.scenarios || [];+ case 'alternative-uses': return drill.objects || [];+ case 'story-prompt': return drill.prompts || [];+ case 'invention-pitch': return drill.problems || [];+ case 'reframe': return drill.situations || [];default: return [];}}@@ -492,3 +580,77 @@ function PunWordplayUI({ challenge, inputValue, setInputValue, onSubmit, inputRe</>);}++function ImaginationUI({ label, prompt, badge, badgeColor, placeholder, inputValue, setInputValue, onSubmit, inputRef, questionIndex, totalPrompts }) {+ return (+ <>+ <div className="bg-port-card border border-port-border rounded-lg p-6 text-center">+ <div className="text-sm text-gray-500 mb-3">+ {badge && <span className={`inline-block px-2 py-0.5 rounded text-xs mr-2 ${badgeColor}`}>{badge}</span>}+ {label}+ </div>+ <p className="text-white text-lg leading-relaxed">{prompt}</p>+ </div>+ <TextInput+ inputRef={inputRef}+ value={inputValue}+ onChange={setInputValue}+ onSubmit={onSubmit}+ placeholder={placeholder}+ buttonLabel="Next"+ />+ <ProgressBar index={questionIndex} total={totalPrompts} />+ </>+ );+}++function AlternativeUsesUI({ object, items, inputValue, setInputValue, onAddItem, onRemoveItem, onSubmit, inputRef, questionIndex, totalPrompts }) {+ return (+ <>+ <div className="text-center py-4">+ <div className="text-sm text-gray-500 mb-2">List creative uses for:</div>+ <div className="text-3xl font-bold text-white">{object?.object}</div>+ {object?.commonUse && <div className="text-sm text-gray-500 mt-2">Common use: {object.commonUse}</div>}+ {object?.minExpected && <div className="text-sm text-gray-500">Target: {object.minExpected}+ uses</div>}+ </div>++ <form onSubmit={onAddItem} className="flex gap-2">+ <input+ ref={inputRef}+ type="text"+ value={inputValue}+ onChange={e => setInputValue(e.target.value)}+ placeholder="Type a creative use and press Enter..."+ autoFocus+ className="flex-1 bg-port-bg border border-port-border rounded-lg px-4 py-2.5 text-white placeholder-gray-600 focus:border-port-accent focus:outline-none"+ />+ <button type="submit" disabled={!inputValue.trim()} className="px-4 py-2.5 bg-port-accent hover:bg-port-accent/80 disabled:opacity-50 text-white font-medium rounded-lg transition-colors">+ Add+ </button>+ </form>++ {items.length > 0 && (+ <div className="bg-port-card border border-port-border rounded-lg p-4">+ <div className="text-sm text-gray-400 mb-2">Uses ({items.length})</div>+ <div className="flex flex-wrap gap-2">+ {items.map((item, i) => (+ <span key={i} className="inline-flex items-center gap-1 px-2 py-1 bg-port-bg border border-port-border rounded text-sm text-white">+ {item}+ <button onClick={() => onRemoveItem(i)} className="text-gray-500 hover:text-port-error ml-1">×</button>+ </span>+ ))}+ </div>+ </div>+ )}++ <button+ onClick={onSubmit}+ disabled={items.length === 0}+ className="w-full px-6 py-2.5 bg-port-success hover:bg-port-success/80 disabled:opacity-50 text-white font-medium rounded-lg transition-colors"+ >+ Done — Submit {items.length} uses+ </button>+ <ProgressBar index={questionIndex} total={totalPrompts} />+ </>+ );+}diff --git a/client/src/components/meatspace/post/PostSessionLauncher.jsx b/client/src/components/meatspace/post/PostSessionLauncher.jsxindex 811e622055..ea72b41427 100644--- a/client/src/components/meatspace/post/PostSessionLauncher.jsx+++ b/client/src/components/meatspace/post/PostSessionLauncher.jsx@@ -15,7 +15,12 @@ const DRILL_LABELS = {'pun-wordplay': 'Pun & Wordplay','memory-fill-blank': 'Memory Fill Blank','memory-sequence': 'Memory Sequence',- 'memory-element-flash': 'Element Flash'+ 'memory-element-flash': 'Element Flash',+ 'what-if': 'What If?',+ 'alternative-uses': 'Alternative Uses',+ 'story-prompt': 'Story Prompt',+ 'invention-pitch': 'Invention Pitch',+ 'reframe': 'Reframe',};export default function PostSessionLauncher({ config, recentSessions, onStart, onViewHistory, onViewConfig, onViewMemory }) {diff --git a/client/src/components/meatspace/post/constants.js b/client/src/components/meatspace/post/constants.jsindex d6314f8b9b..1967a92610 100644--- a/client/src/components/meatspace/post/constants.js+++ b/client/src/components/meatspace/post/constants.js@@ -1,2 +1,2 @@-export const LLM_DRILL_TYPES = ['word-association', 'story-recall', 'verbal-fluency', 'wit-comeback', 'pun-wordplay'];+export const LLM_DRILL_TYPES = ['word-association', 'story-recall', 'verbal-fluency', 'wit-comeback', 'pun-wordplay', 'what-if', 'alternative-uses', 'story-prompt', 'invention-pitch', 'reframe'];export const MEMORY_DRILL_TYPES = ['memory-fill-blank', 'memory-sequence', 'memory-element-flash'];diff --git a/server/lib/postValidation.js b/server/lib/postValidation.jsindex 19abf7bc7d..4ab295ab72 100644--- a/server/lib/postValidation.js+++ b/server/lib/postValidation.js@@ -30,7 +30,7 @@ const llmResponseSchema = z.object({// Drill type configurationconst MATH_DRILL_TYPES = ['doubling-chain', 'serial-subtraction', 'multiplication', 'powers', 'estimation'];-const LLM_DRILL_TYPES = ['word-association', 'story-recall', 'verbal-fluency', 'wit-comeback', 'pun-wordplay'];+const LLM_DRILL_TYPES = ['word-association', 'story-recall', 'verbal-fluency', 'wit-comeback', 'pun-wordplay', 'what-if', 'alternative-uses', 'story-prompt', 'invention-pitch', 'reframe'];const MEMORY_DRILL_TYPES = ['memory-fill-blank', 'memory-sequence', 'memory-element-flash'];const DRILL_TYPES = [...MATH_DRILL_TYPES, ...LLM_DRILL_TYPES, ...MEMORY_DRILL_TYPES];diff --git a/server/services/meatspacePostLlm.js b/server/services/meatspacePostLlm.jsindex 243dad67d2..b417db394f 100644--- a/server/services/meatspacePostLlm.js+++ b/server/services/meatspacePostLlm.js@@ -17,7 +17,12 @@ export const LLM_DRILL_TYPES = ['story-recall','verbal-fluency','wit-comeback',- 'pun-wordplay'+ 'pun-wordplay',+ 'what-if',+ 'alternative-uses',+ 'story-prompt',+ 'invention-pitch',+ 'reframe',];// ─────────────────────────────────────────────────────────────────────────────@@ -227,6 +232,96 @@ Make challenges diverse and fun. The example should be witty but not the only va};}+export async function generateWhatIf(config, providerId, model) {+ const count = config.count || 3;+ const prompt = `Generate ${count} creative "What If" hypothetical scenarios for imagination training.+Each scenario should be absurd, thought-provoking, and fun to reason about.+Mix science, society, nature, and everyday life. Be creative and specific.++Return ONLY valid JSON:+{"scenarios":[{"prompt":"What if gravity reversed for 10 minutes every Tuesday?","category":"physics"}]}`;++ const response = await callAI(prompt, providerId, model);+ const data = parseJsonFromAI(response);+ return {+ type: 'what-if',+ config: { count },+ scenarios: (data.scenarios || []).slice(0, count)+ };+}++export async function generateAlternativeUses(config, providerId, model) {+ const count = config.count || 3;+ const prompt = `Generate ${count} "Alternative Uses" challenges for divergent thinking training.+Each challenge names a common everyday object. The user must list creative, unusual uses for it.+Pick objects that have many possible creative uses.++Return ONLY valid JSON:+{"objects":[{"object":"brick","commonUse":"building material","minExpected":8}]}`;++ const response = await callAI(prompt, providerId, model);+ const data = parseJsonFromAI(response);+ return {+ type: 'alternative-uses',+ config: { count },+ objects: (data.objects || []).slice(0, count)+ };+}++export async function generateStoryPrompt(config, providerId, model) {+ const count = config.count || 3;+ const prompt = `Generate ${count} "Story Prompt" challenges for creative writing training.+Each challenge gives exactly 3 random, unrelated words. The user must write a micro-story (2-4 sentences) connecting all three words.+Choose words that are surprising when combined.++Return ONLY valid JSON:+{"prompts":[{"words":["lighthouse","saxophone","marmalade"]}]}`;++ const response = await callAI(prompt, providerId, model);+ const data = parseJsonFromAI(response);+ return {+ type: 'story-prompt',+ config: { count },+ prompts: (data.prompts || []).slice(0, count)+ };+}++export async function generateInventionPitch(config, providerId, model) {+ const count = config.count || 3;+ const prompt = `Generate ${count} "Invention Pitch" challenges for creative problem-solving training.+Each challenge describes a specific, relatable problem. The user must pitch an inventive solution in 2-3 sentences.+Mix everyday annoyances, workplace challenges, and social problems.++Return ONLY valid JSON:+{"problems":[{"problem":"You always forget where you put your keys","category":"everyday","difficulty":"easy"}]}`;++ const response = await callAI(prompt, providerId, model);+ const data = parseJsonFromAI(response);+ return {+ type: 'invention-pitch',+ config: { count },+ problems: (data.problems || []).slice(0, count)+ };+}++export async function generateReframe(config, providerId, model) {+ const count = config.count || 3;+ const prompt = `Generate ${count} "Reframe" challenges for positive thinking and humor training.+Each challenge describes a frustrating or negative situation. The user must reframe it positively, humorously, or find a silver lining.+Mix minor annoyances with bigger setbacks. Keep them relatable.++Return ONLY valid JSON:+{"situations":[{"situation":"Your flight was delayed by 4 hours","severity":"medium"}]}`;++ const response = await callAI(prompt, providerId, model);+ const data = parseJsonFromAI(response);+ return {+ type: 'reframe',+ config: { count },+ situations: (data.situations || []).slice(0, count)+ };+}+export async function generateLlmDrill(type, config = {}, providerId, model) {switch (type) {case 'word-association':@@ -239,6 +334,16 @@ export async function generateLlmDrill(type, config = {}, providerId, model) {return generateWitComeback(config, providerId, model);case 'pun-wordplay':return generatePunWordplay(config, providerId, model);+ case 'what-if':+ return generateWhatIf(config, providerId, model);+ case 'alternative-uses':+ return generateAlternativeUses(config, providerId, model);+ case 'story-prompt':+ return generateStoryPrompt(config, providerId, model);+ case 'invention-pitch':+ return generateInventionPitch(config, providerId, model);+ case 'reframe':+ return generateReframe(config, providerId, model);default:return null;}@@ -272,6 +377,21 @@ export async function scoreLlmDrill(type, drillData, userResponses, timeLimitMs,case 'pun-wordplay':scorePrompt = buildPunWordplayScorePrompt(drillData, userResponses);break;+ case 'what-if':+ scorePrompt = buildWhatIfScorePrompt(drillData, userResponses);+ break;+ case 'alternative-uses':+ scorePrompt = buildAlternativeUsesScorePrompt(drillData, userResponses);+ break;+ case 'story-prompt':+ scorePrompt = buildStoryPromptScorePrompt(drillData, userResponses);+ break;+ case 'invention-pitch':+ scorePrompt = buildInventionPitchScorePrompt(drillData, userResponses);+ break;+ case 'reframe':+ scorePrompt = buildReframeScorePrompt(drillData, userResponses);+ break;default:return { score: 0, evaluation: null, questions: userResponses };}@@ -374,3 +494,85 @@ ${items}Return ONLY valid JSON:{"overallScore":75,"scores":[{"score":90,"feedback":"Excellent double meaning"}],"summary":"Overall wordplay assessment"}`;}++// ─────────────────────────────────────────────────────────────────────────────+// IMAGINATION DRILL SCORE PROMPTS+// ─────────────────────────────────────────────────────────────────────────────++function buildWhatIfScorePrompt(drillData, responses) {+ const items = responses.map((r, i) => {+ const scenario = drillData.scenarios?.[i];+ return `Scenario: "${scenario?.prompt}"\nUser's response: "${r.response || '(no response)'}"`;+ }).join('\n\n');++ return `Score these "What If" imagination responses on: originality (35%), depth of reasoning (35%), humor/creativity (30%).+Rate each 0-100 and give brief feedback.++${items}++Return ONLY valid JSON:+{"overallScore":75,"scores":[{"score":80,"feedback":"Creative and well-reasoned"}],"summary":"Overall imagination assessment"}`;+}++function buildAlternativeUsesScorePrompt(drillData, responses) {+ const items = responses.map((r, i) => {+ const obj = drillData.objects?.[i];+ return `Object: "${obj?.object}" (common use: ${obj?.commonUse})\nUser's creative uses: ${(r.items || []).join(', ') || '(none)'}`;+ }).join('\n\n');++ return `Score these "Alternative Uses" divergent thinking responses. For each object:+1. Count valid, unique, creative uses (exclude the obvious common use)+2. Rate originality — unusual uses score higher than obvious ones+3. Consider feasibility — completely impossible uses score lower++${items}++Return ONLY valid JSON:+{"overallScore":75,"scores":[{"score":80,"feedback":"8 valid uses, 3 highly original","validCount":8}],"summary":"Overall divergent thinking assessment"}`;+}++function buildStoryPromptScorePrompt(drillData, responses) {+ const items = responses.map((r, i) => {+ const p = drillData.prompts?.[i];+ return `Words: ${(p?.words || []).join(', ')}\nUser's micro-story: "${r.response || '(no response)'}"`;+ }).join('\n\n');++ return `Score these micro-stories on: incorporates all 3 words naturally (30%), creativity/surprise (35%), coherence/quality (35%).+Rate each 0-100. Penalize if any of the 3 words are missing.++${items}++Return ONLY valid JSON:+{"overallScore":75,"scores":[{"score":85,"feedback":"All words used naturally, clever twist"}],"summary":"Overall creative writing assessment"}`;+}++function buildInventionPitchScorePrompt(drillData, responses) {+ const items = responses.map((r, i) => {+ const p = drillData.problems?.[i];+ return `Problem: "${p?.problem}"\nUser's invention pitch: "${r.response || '(no response)'}"`;+ }).join('\n\n');++ return `Score these invention pitches on: addresses the problem (30%), creativity/novelty (40%), feasibility (30%).+Rate each 0-100. A great pitch is both creative AND somewhat plausible.++${items}++Return ONLY valid JSON:+{"overallScore":75,"scores":[{"score":80,"feedback":"Novel approach, reasonably feasible"}],"summary":"Overall invention assessment"}`;+}++function buildReframeScorePrompt(drillData, responses) {+ const items = responses.map((r, i) => {+ const s = drillData.situations?.[i];+ return `Negative situation: "${s?.situation}"\nUser's reframe: "${r.response || '(no response)'}"`;+ }).join('\n\n');++ return `Score these positive reframes on: genuineness (30%), humor (30%), insight/wisdom (40%).+A great reframe finds a real silver lining, not just forced positivity.+Rate each 0-100.++${items}++Return ONLY valid JSON:+{"overallScore":75,"scores":[{"score":85,"feedback":"Genuine insight with humor"}],"summary":"Overall reframing assessment"}`;+}diff --git a/server/services/meatspacePostLlm.test.js b/server/services/meatspacePostLlm.test.jsindex 8e4a1b656a..d14939150f 100644--- a/server/services/meatspacePostLlm.test.js+++ b/server/services/meatspacePostLlm.test.js@@ -50,13 +50,18 @@ beforeEach(() => {// =============================================================================describe('LLM_DRILL_TYPES', () => {- it('exports all 5 drill types', () => {+ it('exports all 10 drill types', () => {expect(LLM_DRILL_TYPES).toEqual(['word-association','story-recall','verbal-fluency','wit-comeback',- 'pun-wordplay'+ 'pun-wordplay',+ 'what-if',+ 'alternative-uses',+ 'story-prompt',+ 'invention-pitch',+ 'reframe',]);});});