Skip to content

feat: Korean summary generation with fail-closed provider contract — closes #10, #4 - #21

Merged
mikim merged 1 commit into
mainfrom
feat/summary
Jul 14, 2026
Merged

feat: Korean summary generation with fail-closed provider contract — closes #10, #4#21
mikim merged 1 commit into
mainfrom
feat/summary

Conversation

@mikim

@mikim mikim commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What

Implements the summary generation interface (#10) and the first Korean-first summary flow (#4) as a new @study-os/summary package + demo API route.

Closes #10
Closes #4

Design

Contract (#10)SummaryProvider: study unit in → Korean summary card out (shortSummary, keyConcepts, confusionPoints, tonePreset) plus GenerationRun provenance: provider, model, prompt version, SHA-256 hash of the exact grounded content, token usage. Every card stays attributable and reproducible — this is the same provenance shape the M2 ErrorEpisode model (#2) will persist.

Implementation (#4) — two providers behind the one contract:

  • AnthropicSummaryProvider: claude-opus-4-8, adaptive thinking, structured outputs (JSON schema, additionalProperties: false). The Korean grounding prompt wraps source material in <자료> tags and instructs the model to treat it as untrusted data, never instructions (per the repo's AI safety gates).
  • MockSummaryProvider: deterministic, offline, derived verbatim from the source. Default when ANTHROPIC_API_KEY is absent — dev/CI never need a key or network.

Fail-closed on every path (a fabricated summary is never returned):

Condition Result
Empty / too-short content SummaryValidationError (400 at the API)
Model judges evidence insufficient (evidence_sufficient: false in schema) throw
stop_reason: refusal / max_tokens throw
Malformed JSON / out-of-bounds card (0 concepts, >10 items, empty summary) throw

API: POST /api/demo/summary — demonstrates the flow end to end; 400 invalid input, 502 generation failure.

Verified

  • 15 new tests: mock determinism + tone presets + validation; Anthropic provider via injected fake client (request shape assertions: model/thinking/structured-output + all fail-closed paths); API route incl. fail-closed 400.
  • 52 tests total, lint/typecheck/build/API smoke all green locally.

🤖 Generated with Claude Code

Implements the summary generation interface (#10) and the first
Korean-first summary flow (#4).

New @study-os/summary package:
- SummaryProvider contract: study unit in, Korean summary card out
  (shortSummary, keyConcepts, confusionPoints, tonePreset) plus
  GenerationRun provenance (provider, model, prompt version, SHA-256
  input hash, token usage) so every card stays attributable
- AnthropicSummaryProvider: claude-opus-4-8 with adaptive thinking and
  structured outputs (JSON schema, additionalProperties: false);
  Korean grounding prompt that treats source material as untrusted
  data, never as instructions
- Fail-closed everywhere: empty/too-short content, model-judged
  insufficient evidence (evidence_sufficient=false), refusal stop
  reason, truncation, malformed JSON, and out-of-bounds cards all
  throw — a fabricated summary is never returned
- MockSummaryProvider: deterministic, offline, derived verbatim from
  the source; default when ANTHROPIC_API_KEY is absent so dev/CI never
  need network or a key
- Tone presets: teacher / tutor / concise-exam

API: POST /api/demo/summary demonstrates the flow end to end
(400 on invalid input, 502 on generation failure).

15 new tests (provider contract, fail-closed paths via injected fake
client, API route); 52 total.

Closes #10
Closes #4

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mikim
mikim merged commit 25020ae into main Jul 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define summary generation interface Generate Korean summary from a study unit

1 participant