fix(cmd465): HF3 diff feedback retry + AST-based fence count (Q2=A + Q3=A)#217
Conversation
…Q3=A) - Part B (Q2=A): HF3 retry prompt を diff feedback 方式に変更 (extra fence の具体的 line/snippet を LLM に passing) - Part C (Q3=A): HF3 fence count を line-start regex から remark AST 'code' node カウントに置換 - remark/remark-gfm/unist-util-visit を dependencies に追加 - テスト: AST セマンティクスに合わせて validateCodeBlocks テストを更新
|
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 (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughマークダウン翻訳パイプラインのコードフェンス検証を AST ベースのコードブロック数カウントへ切替。フェンス不一致時の HF3 再試行ヒントを、翻訳側の行番号を含む差分ベースの詳細メッセージに強化。関連ユニットテストと依存を更新。 ChangesAST ベースのコードブロック検証
Sequence DiagramsequenceDiagram
participant Original as Original Markdown
participant Translated as Translated Markdown
participant RemarkParser as remark (parser)
participant countCodeBlocks as countCodeBlocks()
participant validateCodeBlocks as validateCodeBlocks()
participant buildFenceDiffHint as buildFenceDiffHint()
participant RetryHint as Retry Hint
Original->>countCodeBlocks: pass markdown text
countCodeBlocks->>RemarkParser: parse with remark().use(remarkGfm)
RemarkParser-->>countCodeBlocks: AST
countCodeBlocks->>countCodeBlocks: visit() count 'code' nodes
countCodeBlocks-->>validateCodeBlocks: originalFences count
Translated->>countCodeBlocks: pass markdown text
countCodeBlocks->>RemarkParser: parse with remark().use(remarkGfm)
RemarkParser-->>countCodeBlocks: AST
countCodeBlocks->>countCodeBlocks: visit() count 'code' nodes
countCodeBlocks-->>validateCodeBlocks: translatedFences count
validateCodeBlocks->>validateCodeBlocks: compare counts
alt counts mismatch
validateCodeBlocks-->>buildFenceDiffHint: original=n, translated=m
buildFenceDiffHint->>buildFenceDiffHint: detect missing/extra fences & collect translated line numbers
buildFenceDiffHint-->>RetryHint: detailed diff-based hint
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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: 1
🧹 Nitpick comments (1)
tests/unit/translate-pipeline-validators.test.ts (1)
413-433: ⚡ Quick winAST化の意図に対して、回帰防止テストをもう1段追加したいです。
今回の価値(インデント付き/blockquote 内コードブロック対応)を固定化するため、該当ケースを1〜2件追加すると将来の後退を防ぎやすいです。
🤖 Prompt for 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. In `@tests/unit/translate-pipeline-validators.test.ts` around lines 413 - 433, Add 1–2 regression tests to tests/unit/translate-pipeline-validators.test.ts that exercise validateCodeBlocks with code fences in edge contexts: (1) a code block inside a blockquote (e.g. "> ```ts\n...```") and (2) an indented code block (leading 4-space fenced code). For each case create original/translated pairs where the AST-based code fence counts differ (both fewer and more scenarios as in the existing tests), call validateCodeBlocks(original, translated), and assert result.ok is false and result.reason contains "Code fence count mismatch" plus the appropriate original=*/translated=* counts; use the same test structure and expectation style as the existing tests to ensure these cases prevent regressions in blockquote/indented handling.
🤖 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 63-69: The fence-detection is too strict (using /^```/ on the raw
line) causing leading-space or blockquote fences to be missed; update the loop
that builds transFenceLines (currently using transFenceLines.push inside the
anonymous caller) to iterate transLines.forEach((line, i) => { const trimmed =
line.trimStart(); if (/^```/.test(trimmed) || /^>\s*```/.test(trimmed))
transFenceLines.push({ lineNum: i + 1, content: line }) }); so fences with
leading whitespace or blockquote markers are captured and the extra fence hint
(computed from translatedCount/originalCount) has correct line positions.
---
Nitpick comments:
In `@tests/unit/translate-pipeline-validators.test.ts`:
- Around line 413-433: Add 1–2 regression tests to
tests/unit/translate-pipeline-validators.test.ts that exercise
validateCodeBlocks with code fences in edge contexts: (1) a code block inside a
blockquote (e.g. "> ```ts\n...```") and (2) an indented code block (leading
4-space fenced code). For each case create original/translated pairs where the
AST-based code fence counts differ (both fewer and more scenarios as in the
existing tests), call validateCodeBlocks(original, translated), and assert
result.ok is false and result.reason contains "Code fence count mismatch" plus
the appropriate original=*/translated=* counts; use the same test structure and
expectation style as the existing tests to ensure these cases prevent
regressions in blockquote/indented handling.
🪄 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: 609579be-d128-43fb-90c9-123f2a999079
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (5)
.code-review-donepackage.jsonscripts/translate-pipeline-validators.tsscripts/translate-protected.tstests/unit/translate-pipeline-validators.test.ts
Summary
You MUST preserve exactly N code fences.(generic)Your previous translation added X unwanted code fence(s) at (translated lines): [line N: '```yaml', ...](具体的な行位置を LLM に提示)codenode カウントに置換remark,remark-gfm,unist-util-visitを dependencies に追加countCodeBlocks(): AST でcodenode 数をカウント (インデント/blockquote 対応)Context
Test plan
Closes #213
Summary by CodeRabbit
リリースノート
改善
テスト
その他