Address first round of feedback

- Flashcards: whole card flips on click (both sides), 3D turn, swipe-away on grading,
  streak chip and flame bursts, bigger cards on desktop, arrow keys for everything
- Review and browse keep the sidebar on desktop
- Quizzes: live practice score, partial-credit explanation, time limit for shared exams
- Class page: items grouped by type inside each folder
- Import: copyable, editable instructions for outside chatbots
- Assistant: reads notes and links to library items

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-11 18:30:07 -07:00
parent c59591ccb9
commit aed14cd04f
13 changed files with 769 additions and 216 deletions

View file

@ -144,7 +144,11 @@ const TOOLS: ToolSpec[] = [
const documents = q<Record<string, any>>(`SELECT id, title, kind, status, page_count AS pages, token_count AS approx_tokens, folder_id FROM documents WHERE class_id = ? ORDER BY sort_order`);
const notes = q<Record<string, any>>(`SELECT id, title, folder_id FROM notes WHERE class_id = ? ORDER BY sort_order`);
const folders = q<Record<string, any>>(`SELECT id, name FROM folders WHERE class_id = ? ORDER BY sort_order`);
return { output: { class: { id: cls.id, name: cls.name }, folders, quizzes, decks, documents, notes }, summary: `${quizzes.length + decks.length + documents.length + notes.length} items in ${cls.name}` };
const withUrl = (rows: Record<string, any>[], base: string) => rows.map((x) => ({ ...x, url: `/${base}/${x.id}` }));
return {
output: { class: { id: cls.id, name: cls.name, url: `/classes/${cls.id}` }, folders, quizzes: withUrl(quizzes, 'quizzes'), decks: withUrl(decks, 'decks'), documents: withUrl(documents, 'documents'), notes: withUrl(notes, 'notes') },
summary: `${quizzes.length + decks.length + documents.length + notes.length} items in ${cls.name}`,
};
},
},
{
@ -217,7 +221,7 @@ const TOOLS: ToolSpec[] = [
{
def: {
name: 'search_library',
description: 'Search quiz questions, flashcards and titles by keyword. Use to find existing material on a topic.',
description: 'Search quiz questions, flashcards, notes and titles by keyword. Use to find existing material on a topic. Every result has a url you can link to.',
parameters: obj({ query: S, class_id: S }, ['query']),
},
label: (i) => `Searching your library for "${clip(String(i.query ?? ''), 50)}"`,
@ -239,14 +243,28 @@ const TOOLS: ToolSpec[] = [
like,
...p,
);
const URL_BASE: Record<string, string> = { quiz: 'quizzes', deck: 'decks', note: 'notes', document: 'documents' };
const titles = [
...db.all<Record<string, any>>(`SELECT 'quiz' AS kind, z.id, z.title FROM quizzes z WHERE z.title LIKE ? ESCAPE '\\' ${cls} LIMIT 8`, like, ...p),
...db.all<Record<string, any>>(`SELECT 'deck' AS kind, z.id, z.title FROM decks z WHERE z.title LIKE ? ESCAPE '\\' ${cls} LIMIT 8`, like, ...p),
...db.all<Record<string, any>>(`SELECT 'note' AS kind, z.id, z.title FROM notes z WHERE z.title LIKE ? ESCAPE '\\' ${cls} LIMIT 8`, like, ...p),
];
...db.all<Record<string, any>>(`SELECT 'document' AS kind, z.id, z.title FROM documents z WHERE z.title LIKE ? ESCAPE '\\' ${cls} LIMIT 8`, like, ...p),
].map((x) => ({ ...x, url: `/${URL_BASE[x.kind]}/${x.id}` }));
const notes = db
.all<Record<string, any>>(`SELECT z.id, z.title, z.content FROM notes z WHERE z.content LIKE ? ESCAPE '\\' ${cls} LIMIT 6`, like, ...p)
.map((n) => {
const at = Math.max(0, String(n.content).toLowerCase().indexOf(String(input.query ?? '').toLowerCase()) - 120);
return { id: n.id, title: n.title, url: `/notes/${n.id}`, excerpt: clip(String(n.content).slice(at), 400) };
});
return {
output: { titles, questions: questions.map((q) => ({ ...q, stem: clip(q.stem, 300) })), cards: cards.map((c) => ({ ...c, front: clip(c.front, 200), back: clip(c.back, 300) })) },
summary: `${titles.length + questions.length + cards.length} matches`,
output: {
titles,
questions: questions.map((q) => ({ ...q, stem: clip(q.stem, 300), url: `/quizzes/${q.quiz_id}?q=${q.id}` })),
cards: cards.map((c) => ({ ...c, front: clip(c.front, 200), back: clip(c.back, 300), url: `/decks/${c.deck_id}?card=${c.id}` })),
notes,
note: 'For passages inside uploaded documents, use search_documents.',
},
summary: `${titles.length + questions.length + cards.length + notes.length} matches`,
};
},
},
@ -262,6 +280,7 @@ const TOOLS: ToolSpec[] = [
output: {
id: quiz.id,
title: quiz.title,
url: `/quizzes/${quiz.id}`,
class_id: quiz.class_id,
total_questions: all.length,
questions: all.slice(offset, offset + limit).map((q) => ({
@ -286,11 +305,20 @@ const TOOLS: ToolSpec[] = [
const offset = Math.max(0, Number(input.offset) || 0);
const limit = Math.max(1, Math.min(150, Number(input.limit) || 60));
return {
output: { id: deck.id, title: deck.title, class_id: deck.class_id, total_cards: all.length, cards: all.slice(offset, offset + limit).map((c) => ({ id: c.id, front: clip(c.front, 300), back: clip(c.back, 500) })) },
output: { id: deck.id, title: deck.title, url: `/decks/${deck.id}`, class_id: deck.class_id, total_cards: all.length, cards: all.slice(offset, offset + limit).map((c) => ({ id: c.id, front: clip(c.front, 300), back: clip(c.back, 500) })) },
summary: `${deck.title} (${all.length} cards)`,
};
},
},
{
def: { name: 'read_note', description: 'Read one of the user\'s notes or study guides (Markdown).', parameters: obj({ note_id: S }, ['note_id']) },
label: () => 'Reading a note',
run: (input, { app }) => {
const note = app.db.get<{ id: string; title: string; content: string; class_id: string }>('SELECT id, title, content, class_id FROM notes WHERE id = ?', String(input.note_id));
if (!note) throw notFound('Note');
return { output: { id: note.id, title: note.title, url: `/notes/${note.id}`, class_id: note.class_id, content: clip(note.content, 24000) }, summary: note.title };
},
},
{
def: {
name: 'get_performance',
@ -832,6 +860,8 @@ function systemPrompt(app: AppContext, context: AssistantContext): string {
`How to work:
- Use tools instead of guessing. To answer questions about their material, search or read the documents first and base the answer on what you find.
- Cite document passages inline with the ref id in square brackets right after the claim, exactly as given, e.g. [c42]. Only cite refs that a tool returned in this conversation. If the documents do not cover something, say so, then answer from general knowledge and label it as such.
- You can browse everything: list_materials and search_library for quizzes, flashcards and notes; get_quiz, get_deck and read_note to open them; search_documents and read_document for uploaded files.
- When you mention a specific quiz, deck, note or document, link it with Markdown using the url the tool gave you, for example [Cardiac drug cards](/decks/abc123). Never invent a url.
- To create study material, call generate_quiz, generate_flashcards or write_study_guide. They read the source documents themselves, so pass ids and a topic rather than text. Do not search first unless you need to work out which documents are relevant.
- Everything you create is a DRAFT shown as a preview card. Never say it was saved or added; tell the user to review and save it.
- Deleting, moving and renaming require propose_changes and the user's confirmation. Never claim a change was made before a system note confirms it.