You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parent epic:#1446 (Amicus — AI Study Partner v1) Phase: 4 · Size: M · Depends on:#1450 (proxy), #1452 (profile)
Generate one proactive "Amicus noticed..." prompt per user per day. Runs on app open (not background — no battery tax); cached 24h keyed on profile hash + date.
{
prompt_text: string;// e.g., "Amicus noticed you've been deep in Jeremiah..."
seed_query: string;// what happens when user taps the card
cached_until: string;// ISO timestamp}
System prompt for Haiku:
Generate a brief "Amicus noticed..." proactive study prompt for this user based on their recent reading pattern. It should reference something specific they've been studying and suggest a direction they haven't explored yet. Length: 2 sentences. Warm tone, never preachy. End with a question they can tap to explore.
User profile: {profile_summary}
Recent chapters: {last_5_chapters}
Cost: ~$0.002 per generation (Haiku + prompt caching on the system prompt). One call per user per day.
Cache schema (migration in userDatabase.ts)
CREATETABLEIF NOT EXISTS amicus_daily_prompt_cache (
id INTEGERPRIMARY KEYCHECK (id =1), -- singletondateTEXTNOT NULL, -- 'YYYY-MM-DD' (user local)
profile_hash TEXTNOT NULL,
prompt_text TEXTNOT NULL,
seed_query TEXTNOT NULL,
generated_at TEXTNOT NULL
);
Parent epic: #1446 (Amicus — AI Study Partner v1)
Phase: 4 · Size: M · Depends on: #1450 (proxy), #1452 (profile)
Generate one proactive "Amicus noticed..." prompt per user per day. Runs on app open (not background — no battery tax); cached 24h keyed on profile hash + date.
Architecture decision: where does this run?
Client-triggered, server-generated, client-cached.
/ai/daily-promptwhich generates via Haikuuser.dbRationale:
Files to create
ai-proxy/src/dailyPrompt.ts— new endpoint in the Cloudflare Workerapp/src/services/amicus/dailyPrompt.ts— client service that checks cache, calls proxy if neededapp/src/hooks/useDailyPrompt.ts— hook for HomeScreen to consumeapp/src/services/amicus/__tests__/dailyPrompt.test.tsFiles to modify
ai-proxy/src/index.ts— routePOST /ai/daily-prompt→dailyPrompt.handlerapp/src/db/userDatabase.ts— migration addsamicus_daily_prompt_cachetableapp/src/db/userQueries.ts/userMutations.ts— add read/write for the cacheServer-side endpoint (
/ai/daily-prompt)Request:
Response:
System prompt for Haiku:
Cost: ~$0.002 per generation (Haiku + prompt caching on the system prompt). One call per user per day.
Cache schema (migration in userDatabase.ts)
Client service
Flow:
date == todayANDprofile_hash == current_hash, return cached/ai/daily-promptwith profile + recent chaptersGraceful degradation:
nullif no cache at all (no UI for ai-partner: home screen card component #1466 to render)Profile hash
Deterministic hash of the compressed profile prose. Cache invalidates when user's study behavior shifts enough to change the profile prose.
Performance
Acceptance criteria
/ai/daily-promptgenerates valid Haiku responseprompt_text,seed_query,cached_untilanytypes; lint cleanOut of scope