feat: auto-infer course language from user input#384
Draft
Conversation
Replace the manual language selector with LLM-based language inference.
A standalone `/api/generate/language-directive` endpoint infers a
natural-language directive from requirement text, PDF content, user
profile, and app locale. The directive is then consumed by agent profile
generation, outline generation, and downstream content steps.
- Add `LanguageDirective` type (natural-language string)
- Add standalone `inferLanguageDirective()` with dedicated prompt
- Add `/api/generate/language-directive` API endpoint
- Inject directive into outline prompt via `{{languageDirective}}`
- Remove manual language picker from generation toolbar
- Pass app locale (i18n) instead of navigator.language
- Add LLM-as-judge eval test suite (local only, 17 test cases)
- Store `languageDirective` in Stage for persistence
Closes #381
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Propagate languageDirective to SceneOutline and downstream scene generation (interactive HTML now receives the directive) - Replace dead localStorage 'generationLanguage' reads in agent-bar with app locale from useI18n() - Remove orphaned toolbar.languageHint i18n key from all 4 locales - Update UserRequirements.language comment to reflect legacy status Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add locale to useCallback deps in AgentVoicePill and TeacherVoicePill, remove unused locale destructuring from AgentBar. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Eval tests (*.eval.test.ts) require real LLM API keys and are meant for local-only execution. Exclude them from the default vitest glob so CI doesn't fail on missing API credentials. Run locally with: pnpm vitest run tests/generation/language-inference.eval.test.ts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The core issue: languageDirective was generated but not consumed by
most downstream steps, causing mixed-language output when UI locale
differed from requirement language.
Changes:
- Remove language parameter from formatImageDescription/Placeholder
(use English uniformly for LLM-facing metadata)
- Inject {{languageDirective}} into all prompt templates: slide-content,
slide-actions, quiz-content, quiz-actions, interactive-actions,
interactive-html
- Pass outline.languageDirective through every buildPrompt call
- Update scene-content API to propagate languageDirective from stageInfo
- Update prompt-builder.ts to prefer languageDirective over language code
- Persist languageDirective in IndexedDB via StageRecord
- Remove hardcoded zh-CN/en-US branches from quiz-grade API
- Remove all requirements.language consumption in outline generation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The agent profile prompt received the full directive string in a "Names and personas must be in language:" slot, which confused the LLM. Change to inject it as a language directive that the LLM interprets holistically. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The streaming outline route and client were not propagating languageDirective onto individual outline objects. This caused downstream scene-content/actions/quiz generation to have no language instruction, resulting in wrong-language output. - Streaming route: attach languageDirective to each enriched outline - Client: ensure languageDirective on every outline in done event Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Language is a course-level attribute, not per-outline. Remove languageDirective from SceneOutline, store it only on Stage. Pass it as a parameter through generateSceneContent and generateSceneActions instead of reading from outline. - Remove SceneOutline.languageDirective field - Add languageDirective parameter to generateSceneContent/Actions - scene-content API reads from stageInfo.languageDirective - scene-actions API accepts languageDirective in request body - Client passes stage.languageDirective to all API calls - Server pipeline passes languageDirective through all steps Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
apiSuccess spreads data into the top-level response object, so the directive is at ldData.directive, not ldData.data.directive. This caused languageDirective to always be undefined on the client, making all downstream steps fall back to locale instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/api/generate/language-directiveendpoint infers a natural-language directive from requirement text, PDF content, user profile, and app localeChanges
lib/generation/language-inference.ts— standalone inference function with dedicated promptlib/types/language-directive.ts— type definitionapp/api/generate/language-directive/route.ts— API endpointtests/generation/language-inference.eval.test.ts— eval suite with LLM-as-judge{{languageDirective}}into outline prompt (replaces{{language}})navigator.languagefor fallback signalsgenerationLanguagelocalStorage reads, orphaned i18n keysArchitecture
Test plan
pnpm vitest run tests/generation/language-inference.eval.test.ts— 17/17 passing with LLM-as-judgeCloses #381
🤖 Generated with Claude Code