Skip to content

fix(#287): promptCheck再検証失敗時のフォールバック不備修正#290

Merged
Kewton merged 5 commits intodevelopfrom
feature/287-worktree
Feb 16, 2026
Merged

fix(#287): promptCheck再検証失敗時のフォールバック不備修正#290
Kewton merged 5 commits intodevelopfrom
feature/287-worktree

Conversation

@Kewton
Copy link
Owner

@Kewton Kewton commented Feb 16, 2026

Summary

  • promptCheck再検証が失敗(promptCheck=null)した場合でも、リクエストボディのpromptType/defaultOptionNumberを使用してカーソルキーナビゲーションにフォールバックする仕組みを追加
  • buildPromptResponseBody() 共通ユーティリティを抽出し、useAutoYes/WorktreeDetailRefactoredのリクエストボディ構築ロジックをDRY化
  • Bug1修正: isClaudeMultiChoice のフォールバック条件を拡張。promptCheck === null のみだった条件を bodyPromptType === 'multiple_choice' に簡略化し、promptCheckが非nullでもタイプ不一致時にフォールバックが発動するよう修正

Bug1 修正詳細

根本原因: captureSessionOutput() が成功しても detectPrompt() がタイミングやターミナル出力の部分レンダリングにより multiple_choice 以外のタイプを返す場合、promptCheck が非nullのためフォールバックが発動しなかった。

変更前 (route.ts L125):

|| (promptCheck === null && bodyPromptType === 'multiple_choice'))

変更後:

|| bodyPromptType === 'multiple_choice')

Changes

  • src/app/api/worktrees/[id]/prompt-response/route.ts: フォールバック条件拡張、buildNavigationKeys()/CHECKBOX_OPTION_PATTERN抽出
  • src/lib/prompt-response-body-builder.ts: リクエストボディ構築の共通ユーティリティ(新規)
  • src/components/worktree/WorktreeDetailRefactored.tsx: handlePromptRespondでpromptType/defaultOptionNumberを送信
  • src/hooks/useAutoYes.ts: Auto-YesパスでpromptType/defaultOptionNumberを送信
  • tests/unit/api/prompt-response-verification.test.ts: Bug1テストケース追加(21テスト全パス)

Test plan

  • promptCheck非null + type mismatch時のカーソルキーナビゲーション動作確認
  • promptCheck=null時のカーソルキーナビゲーション動作確認
  • Yes/Noプロンプトの既存動作に影響なし
  • Codexの既存動作に影響なし
  • defaultOptionNumber=undefinedでフォールバック値1が使用される
  • 後方互換性(promptType/defaultOptionNumber未送信時)
  • 全3419ユニットテスト合格
  • ESLint/TypeScriptエラー0件
  • ビルド成功
  • カバレッジ: Statements 100%, Lines 100%

Closes #287

🤖 Generated with Claude Code

Kewton and others added 5 commits February 16, 2026 15:16
…ponse API

When promptCheck re-verification fails (capture error), the API now falls
back to body.promptType and body.defaultOptionNumber to determine whether
cursor-key navigation should be used for Claude Code multiple-choice prompts.
This prevents the bug where a failed re-verification causes multiple_choice
prompts to be sent as plain text instead of cursor keys.

- route.ts: Accept optional promptType/defaultOptionNumber in request body;
  use as fallback when promptCheck is null
- WorktreeDetailRefactored.tsx: Include promptType and defaultOptionNumber
  in handlePromptRespond request body from state.prompt.data
- useAutoYes.ts: Include promptType and defaultOptionNumber in auto-response
  request body to prevent same bug in auto-yes path
- Tests: Add 6 unit tests for fallback behavior, 6 tests for useAutoYes hook,
  and 2 integration tests for request body validation

Resolves #287

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ve coverage

Extract duplicated prompt-response request body construction logic
from useAutoYes hook and WorktreeDetailRefactored into shared
buildPromptResponseBody() utility (DRY principle).

Extract buildNavigationKeys() helper in route.ts to eliminate
duplicated cursor offset-to-direction-keys logic between
multi-select and single-select code paths.

Add CHECKBOX_OPTION_PATTERN constant to replace inline regex
duplication for checkbox-style option detection.

Add comprehensive tests for previously uncovered paths:
- Session not running error (400)
- Multi-select checkbox prompt navigation
- sendKeys/sendSpecialKeys error handling (500)
- Malformed JSON body (outer catch)
- Non-Error thrown from sendKeys

Quality Metrics:
- route.ts Lines: 73.84% -> 100%
- route.ts Branches: 69.04% -> 92.1%
- route.ts Functions: 80% -> 100%
- ESLint errors: 0 -> 0
- TypeScript errors: 0 -> 0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…orts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The fallback condition `(promptCheck === null && bodyPromptType === 'multiple_choice')`
only covered the case when promptCheck was null. When promptCheck was non-null but
its type was not 'multiple_choice' (e.g., 'yes_no'), the fallback did not activate,
causing cursor-key navigation to be skipped. Simplified the condition to
`|| bodyPromptType === 'multiple_choice'` which correctly falls back in all cases
where promptCheck does not provide multiple_choice data. Added 2 new test cases
for the type mismatch and undefined promptData scenarios.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Kewton Kewton merged commit a098513 into develop Feb 16, 2026
5 checks passed
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.

1 participant