fix(cmd462): HF3 contextual retry — fence count diff フィードバック (Q2=A)#215
Conversation
…Q2=A)
translate-protected.ts の HF3 retry を単純 retry から contextual retry に強化。
fence count mismatch 検出時に原文・翻訳のフェンス数差分を system prompt suffix として
yuuhitsu translate --system-prompt-suffix に渡し、LLM が前回エラーから学習して修正できるようにする。
runYuuhitsu に extraArgs: string[] = [] パラメータを追加。
HF3 mismatch 時: hf3RetryHint に "FENCE COUNT CORRECTION: previous had X fences, original has Y..." を設定し、
次の attempt で --system-prompt-suffix として渡す。
NOTE: yuuhitsu 0.3.1 (PR#91) の --system-prompt-suffix オプションが必要。
yuuhitsu 0.3.1 publish 後 + geonicdb-docs version bump (^0.3.1) 後に merge すること。
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthroughウォークスルー翻訳スクリプトに HF3 コードフェンス不一致への文脈的リトライ機能を追加。ヘルパー関数が CLI 引数をサポートし、バリデーション失敗時にフェンス数を抽出・解析して次の試行に指示を渡す。加えて 変更内容HF3 リトライ最適化
Sequence Diagram(s)sequenceDiagram
participant TranslateScript as translate-protected.ts
participant Runner as runYuuhitsu
participant Validator as validateCodeBlocks
TranslateScript->>Runner: invoke with args + extraArgs ( --system-prompt-suffix )
Runner->>Validator: return translated output for validation
Validator-->>TranslateScript: code block check result (reason)
TranslateScript->>TranslateScript: parse reason -> hf3RetryHint
TranslateScript->>Runner: retry with hf3RetryHint in extraArgs
推定レビュー工数🎯 2 (Simple) | ⏱️ ~12 分 詩
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/translate-protected.ts`:
- Around line 395-399: The current logic builds hf3RetryHint using
originalFences/translatedFences even when fenceMatch is null, producing "exactly
?" which degrades retries; change the branch so that if fenceMatch is truthy you
set originalFences/translatedFences and the strict hf3RetryHint, but if
fenceMatch is falsy do NOT build an "exactly ?" hint—instead set hf3RetryHint to
a fallback instruction derived from codeBlockCheck.reason (a general "preserve
code fences as in the original" guidance) and keep the console.warn with
codeBlockCheck.reason and attempt; update handling around fenceMatch,
originalFences, translatedFences, hf3RetryHint, and codeBlockCheck.reason
accordingly.
- Around line 301-302: The script unconditionally pushes
'--system-prompt-suffix' into extraArgs (see extraArgs and hf3RetryHint in
translate-protected.ts) but `@geolonia/yuuhitsu` pinned at 0.2.4 may not support
that option; either update package.json to a version that supports the flag
(e.g., bump `@geolonia/yuuhitsu` to ^0.3.1 and lock) or add a runtime guard that
checks the installed yuuhitsu version before pushing the flag (query
package.json or run `yuuhitsu --version` at startup, parse and compare to the
minimum supported version, and only push '--system-prompt-suffix' when the
version meets the requirement) so the retry logic won’t fail with an
unknown-option error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1a25e409-82f3-4b3f-bf6f-dabc09a409f3
📒 Files selected for processing (2)
.code-review-donescripts/translate-protected.ts
fenceMatch が null の場合でも '?' の代わりに codeBlockCheck.reason を そのままフォールバックとして使用するよう修正。
Summary
translate-protected.tsの HF3 retry を単純 retry から contextual retry に強化(Q2=A)--system-prompt-suffixとして yuuhitsu translate に渡すContext
Changes
runYuuhitsu()にextraArgs: string[] = []パラメータ追加hf3RetryHintを設定し、次の attempt で--system-prompt-suffixとして渡す"FENCE COUNT CORRECTION: The previous translation had X code fences, but the original has Y. You MUST preserve exactly Y code fences."このPRは yuuhitsu 0.3.1 (PR#91) の
--system-prompt-suffixオプションが必要です。マージ順序:
^0.3.1に bumpTest plan
pnpm run docs:buildPASS/code-review-expert --autoP0: 0 / P1: 0 確認Summary by CodeRabbit
リリースノート
改善点
その他