fix: decode addressed Claude prompt text

This commit is contained in:
Brennan Benson
2026-08-10 04:25:54 -07:00
parent abfb4ac752
commit 0ee46a3024
2 changed files with 13 additions and 3 deletions
@@ -3,6 +3,7 @@ import { agentJournalItemKey } from '../../shared/agent-session-journal-item-key
import { claudeQuestionItems } from './claude-structured-prompt-items'
import {
applyClaudePromptAnswer,
encodeClaudeQuestionOptionId,
type ClaudePendingPrompt
} from './claude-structured-prompt-replies'
@@ -50,7 +51,9 @@ describe('Claude structured question addressing', () => {
}
const answer = 'https://example.test:8443/path'
expect(applyClaudePromptAnswer({ prompt }, answer)).toMatchObject({
expect(
applyClaudePromptAnswer({ prompt }, encodeClaudeQuestionOptionId('q1', answer))
).toMatchObject({
updatedInput: { answers: { [questionId]: answer } }
})
})
@@ -71,7 +74,9 @@ describe('Claude structured question addressing', () => {
}
const answer = 'frontend, backend'
expect(applyClaudePromptAnswer({ prompt, questionId }, answer)).toMatchObject({
expect(
applyClaudePromptAnswer({ prompt, questionId }, encodeClaudeQuestionOptionId('q1', answer))
).toMatchObject({
updatedInput: { answers: { [questionId]: answer } }
})
})
@@ -57,10 +57,15 @@ function questionAnswer(prompt: ClaudePendingPrompt, questionId: string, optionI
if (decoded.questionId === `q${questionIndex + 1}` && label) {
return label
}
if (decoded.questionId === `q${questionIndex + 1}`) {
return decoded.answer
}
const legacyChoice = options.some(
(candidate) => isRecord(candidate) && readString(candidate.label) === decoded.answer
)
return decoded.questionId === questionId && legacyChoice ? decoded.answer : optionId
return decoded.questionId === questionId && (legacyChoice || decoded.answer.trim().length > 0)
? decoded.answer
: optionId
}
function questionId(question: Record<string, unknown>, index: number): string {