Phase 3: Check my work, follow-ups and turn-into-deck

Check my work (third homework mode)
- One model call with its own system prompt marks the student's own
  attempt: verdict, what's right, each issue with why + fix, and the
  corrected version that keeps everything the student got right.
  Unasked-for extras are never errors. The attempt is typed/pasted
  (photos of handwriting are documented as unsupported) and stored in
  the record so Redo re-checks the same work.
- Server: mode "check" + solution on POST /api/homework (zod, 400
  server.needSolution without one) and the same NDJSON stream; new
  checkHomework() pipeline with repair-once validation.

Follow-ups
- New POST /api/homework/refine (plain JSON, RATE_LIMIT_REFINE, zod,
  auth before body): shorter / more detail / explain, plain text back,
  language preserved.
- Shorter + More detail + Original rewrite the finished answer and the
  corrected version in place (FollowUpBar); every guide step has
  Explain step N differently; failed calls say so without losing text.

Turn into a study deck
- Any result hands its content (answer, corrected version or assembled
  guide) to New deck through a one-shot sessionStorage seed with the
  options step pre-filled.

UI
- Phone step 2 gains the third card: tapping it reveals the solution
  field + submit; desktop has three cards and the solution field shows
  with the mode. Homework history labels and share/card previews cover
  the new mode.

Verified: new phase-3 suite 20/20 against a stub Ollama (check payload,
missing-solution 400, refine validation, phone + desktop check flows,
shorter follow-up with restore, guide explain, deck hand-off) plus
regression 74/74, mobile 52/52, declutter 116/116, wizard 80/80,
animation 8/8, native 35/35, phase1 38/38, phase2 43/43, i18n 25/25.
Key parity 734/734. Lint + build clean. SW freezmo-v27.
This commit is contained in:
Martin Dvořák 2026-10-10 14:36:04 +00:00
commit 4513364019
22 changed files with 947 additions and 56 deletions

View file

@ -139,9 +139,27 @@ export const gradeResultSchema = z.object({
/* Make my homework */
/* ------------------------------------------------------------------ */
export const homeworkModeSchema = z.enum(["make", "guide"]);
export const homeworkModeSchema = z.enum(["make", "guide", "check"]);
export type HomeworkMode = z.infer<typeof homeworkModeSchema>;
export const checkIssueSchema = z.object({
issue: z.string().min(1).max(600),
why: z.string().min(1).max(600),
fix: z.string().max(600).default(""),
});
export type CheckIssue = z.infer<typeof checkIssueSchema>;
/** Mode 3: feedback on the student's own solution. */
export const homeworkCheckSchema = z.object({
title: z.string().min(1).max(200),
language: z.string().max(60).optional(),
verdict: z.string().min(1).max(600),
correct: z.array(z.string().max(600)).max(12).default([]),
wrong: z.array(checkIssueSchema).max(12).default([]),
corrected: z.string().min(1).max(20_000),
});
export type HomeworkCheck = z.infer<typeof homeworkCheckSchema>;
/** Mode 1 — the finished homework, nothing else. */
export const homeworkMakeSchema = z.object({
title: z.string().min(1).max(200),
@ -219,10 +237,21 @@ export const homeworkRecordSchema = z.discriminatedUnion("mode", [
mode: z.literal("guide"),
steps: z.array(homeworkStepStoredSchema).min(2).max(10),
}),
z.object({
...homeworkBaseFields,
mode: z.literal("check"),
verdict: z.string().min(1).max(600),
correct: z.array(z.string().max(600)).max(12),
wrong: z.array(checkIssueSchema).max(12),
corrected: z.string().min(1).max(20_000),
/** The student's own attempt, so "Redo" can re-check the same work. */
attempt: z.string().max(20_000).optional(),
}),
]);
export type HomeworkRecord = z.infer<typeof homeworkRecordSchema>;
export type HomeworkMakeRecord = Extract<HomeworkRecord, { mode: "make" }>;
export type HomeworkGuideRecord = Extract<HomeworkRecord, { mode: "guide" }>;
export type HomeworkCheckRecord = Extract<HomeworkRecord, { mode: "check" }>;
/* ------------------------------------------------------------------ */
/* Client-side deck types (activity + id/xp, plus storage metadata) */