feat(ai-translation): add writer → reviewer → editor pipeline#2739
Merged
Conversation
Adds a three-step translation pipeline (writer → reviewer → editor) that
critiques the writer's initial translation and revises flagged segments
to read natively. Reviewer is critique-only with an independent runtime;
editor returns segment patches that are merged into the result before a
single DB write.
Highlights:
- Drop lexical writer batching (single-call now); keep incremental
block reuse and meta hash diffing
- New TranslationReviewerService with structured-output + text-mode
fallback; sanitizes issues against ALLOWED_IDS
- Markdown patches go through a fence-aware paragraph splitter so
patches target paragraph IDs, not the whole text field
- Reviewer / editor system prompts moved to .md files imported via
Vite raw + {{var}} template renderer
- PipelineMetrics out-param exposes per-stage timing, score, issue
IDs, patch keys, and before/after samples for tests and observability
- Independent reviewer model config (AIFeatureKey.TranslationReview,
enableTranslationReview, translationReviewModel,
translationReviewScoreThreshold) — falls back to translator model
- Live OpenRouter / LM Studio e2e (RUN_LIVE_TESTS=1) writes a markdown
quality report covering writer output, revise step, post-edit
quality probe, and structural fidelity. Default 'pnpm test' does
not invoke it.
- bench-translation-prompt.ts rewritten to drive real strategies +
runtimes for A/B prompt comparison
Spec: docs/superpowers/specs/2026-05-27-translation-review-pipeline-design.md
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
- Switch tsx → vite-node so Vite's ?raw imports (translation-reviewer.system.md, translation-editor.system.md) load correctly inside ai.prompts.ts - Inject TranslationReviewerService into LexicalTranslationStrategy constructor to satisfy the new pipeline signature; review/edit stays inert when no reviewer runtime is passed to translate(...) Verified vite-node starts the bench against openrouter and exercises LexicalTranslationStrategy end-to-end (streamed translations include real .md system prompt content).
- Move every AI system prompt out of ai.prompts.ts into prompts/*.md (loaded via Vite ?raw)
- Render dynamic interpolations through renderPromptTemplate placeholders
({{MAX_WORDS}}, {{GENRE_LIST}}, {{TARGET_LANGUAGE}})
- Split optional sections (Japanese ruby, stream reminders, input/output format) into .partial.md fragments concatenated by buildXxxSystem helpers
- ai.prompts.ts shrinks from ~440 lines of string literals to declarative composition
…ategies Hoist DEFAULT_REVIEW_SCORE_THRESHOLD, emptyReviewerMetrics, emptyEditorMetrics, and buildReviewerMetrics into the base strategy so lexical and markdown translation strategies share one source of truth. Simplifies metrics bookkeeping in runReviewAndEdit and editor patch application.
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
Three-step translation pipeline (writer → reviewer → editor) that critiques the initial translation and revises flagged segments to read natively. Reviewer is critique-only with an independent runtime; editor returns segment patches merged into the result before a single DB write.
Changes
Spec
`docs/superpowers/specs/2026-05-27-translation-review-pipeline-design.md`
Test plan