Skip to content

fix(cmd465): HF3 diff feedback retry + AST-based fence count (Q2=A + Q3=A)#217

Merged
halsk merged 4 commits into
mainfrom
feat/cmd465-hf3-diff-feedback
May 11, 2026
Merged

fix(cmd465): HF3 diff feedback retry + AST-based fence count (Q2=A + Q3=A)#217
halsk merged 4 commits into
mainfrom
feat/cmd465-hf3-diff-feedback

Conversation

@halsk

@halsk halsk commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Part B (Q2=A): HF3 retry prompt を diff feedback 方式に変更
    • 旧: You MUST preserve exactly N code fences. (generic)
    • 新: Your previous translation added X unwanted code fence(s) at (translated lines): [line N: '```yaml', ...] (具体的な行位置を LLM に提示)
  • Part C (Q3=A): HF3 fence count を line-start regex から remark AST code node カウントに置換
    • remark, remark-gfm, unist-util-visit を dependencies に追加
    • countCodeBlocks(): AST で code node 数をカウント (インデント/blockquote 対応)
  • テスト: AST セマンティクスに合わせて validateCodeBlocks テスト 2件を更新

Context

  • cmd_465: yuuhitsu 0.3.2 hotfix の一部 (Part B/C)
  • Part A (temperature=0) は geolonia/yuuhitsu PR#94 に分離

Test plan

  • pnpm test 全 PASS (201 tests)
  • npx tsc --noEmit PASS
  • CI PASS
  • CodeRabbit reviewThreads=0

Closes #213

Summary by CodeRabbit

リリースノート

  • 改善

    • Markdown構造に基づくコードブロック検証でより正確になりました
    • コード不一致エラー時の再試行メッセージを差分ベースで詳報するよう改善
  • テスト

    • コードブロック検証の仕様に合わせてユニットテストを更新
  • その他

    • 内部依存関係を追加

Review Change Stack

Hal Seki added 3 commits May 11, 2026 21:29
…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 テストを更新
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 01d40bdb-5cb2-4fde-9824-01fb152d46a7

📥 Commits

Reviewing files that changed from the base of the PR and between 74180a9 and a579fdf.

📒 Files selected for processing (2)
  • .code-review-done
  • scripts/translate-protected.ts
✅ Files skipped from review due to trivial changes (1)
  • .code-review-done
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/translate-protected.ts

📝 Walkthrough

Walkthrough

マークダウン翻訳パイプラインのコードフェンス検証を AST ベースのコードブロック数カウントへ切替。フェンス不一致時の HF3 再試行ヒントを、翻訳側の行番号を含む差分ベースの詳細メッセージに強化。関連ユニットテストと依存を更新。

Changes

AST ベースのコードブロック検証

Layer / File(s) Summary
依存関係追加
package.json
remarkremark-gfmunist-util-visit をランタイム依存に追加。
AST 解析ロジック
scripts/translate-pipeline-validators.ts
remarkremark-gfmvisit をインポート。countCodeBlocks(markdown) ヘルパーを追加し、AST の code ノード数をカウントする実装を追加。
検証関数リファクタリング
scripts/translate-pipeline-validators.ts
validateCodeBlocks() が従来の正規表現による ``` フェンス数カウントから countCodeBlocks() を使う AST ベースカウントへ変更。失敗理由フォーマット `original=, translated=` は保持。
再試行ヒント生成
scripts/translate-protected.ts
buildFenceDiffHint() を追加。フェンス差分を解析し、追加された翻訳側フェンスの位置(翻訳内行番号)や不足フェンスの指示を含む詳細ヒントを生成するロジックを導入。
ヒント統合
scripts/translate-protected.ts
HF3 バリデーション失敗時に reason が original=<n>, translated=<m> とマッチすると buildFenceDiffHint() を呼んで hf3RetryHint を生成するように変更。既存のリトライ/エラーフローは維持。
ユニットテスト更新
tests/unit/translate-pipeline-validators.test.ts
「ブロック数が少ない/多い」ケースを完全なコードブロック数で検証するように更新し、期待される original=2, translated=1 および original=1, translated=2 をアサート。
レビューメタデータ
.code-review-done
コードレビュー完了マークのハッシュを更新。

Sequence Diagram

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • geolonia/geonicdb-docs#215: 同様に HF3 フェンスカウント再試行ヒントの改善を扱う変更が含まれており関連性が高い。

Poem

正規表現の鎖を解き、
AST の樹を辿る旅へ。
remark が数え、visit が導く、
行番号の灯で迷子を救い、
翻訳はまた一歩、確かに前へ。

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning PR の主要な変更(HF3 retry フィードバック改善とコードフェンスの AST ベースカウント)は cmd_465 対応であり、リンク issue #213(cmd_447)の MAPPING_TABLE 追加や sidebar 設定などの目的には対応していません。 #213 の受入基準(MAPPING_TABLE 4 ファイル追加、sidebar 設定、SaaS-rewrite 対応)の実装が本 PR には含まれていません。別 PR として分離するか、スコープを明確にしてください。
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは HF3 差分フィードバック retry と AST ベースのフェンスカウント機能を明確に説明しており、変更内容と完全に関連しています。
Out of Scope Changes check ✅ Passed package.json への remark 関連依存追加、translate-pipeline-validators.ts での AST ベース実装、translate-protected.ts での diff hint 生成、テスト更新はすべて cmd_465 HF3 改善スコープ内です。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cmd465-hf3-diff-feedback

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unit/translate-pipeline-validators.test.ts (1)

413-433: ⚡ Quick win

AST化の意図に対して、回帰防止テストをもう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

📥 Commits

Reviewing files that changed from the base of the PR and between 341ea29 and 74180a9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .code-review-done
  • package.json
  • scripts/translate-pipeline-validators.ts
  • scripts/translate-protected.ts
  • tests/unit/translate-pipeline-validators.test.ts

Comment thread scripts/translate-protected.ts Outdated
@halsk
halsk merged commit 15af830 into main May 11, 2026
4 checks passed
@halsk
halsk deleted the feat/cmd465-hf3-diff-feedback branch May 11, 2026 13:02
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.

cmd_447: 未マッピング 4 ファイル MAPPING_TABLE 追加 + sync workflow 設定 (cmd_446 Phase 1.1)

1 participant