feat(engine): dispatcher handles ambiguous parses with a disambiguation prompt

Sets pendingDisambiguation on state and emits "Which X — A, or B?" using
each candidate item's short text. The existing disambiguation reply path
then re-issues the original verb against the chosen target.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-09 13:58:32 -05:00
parent b318747840
commit ab8c17fdd5
2 changed files with 70 additions and 1 deletions
+14
View File
@@ -86,6 +86,20 @@ export function dispatch(state: GameState, command: ParsedCommand, world: World)
return handleGo(state, command.direction, world)
}
if (command.kind === 'ambiguous') {
const candidateShorts = command.candidates.map((id) => world.items[id]?.short ?? id)
const list =
candidateShorts.length === 2
? `${candidateShorts[0]}, or ${candidateShorts[1]}`
: candidateShorts.slice(0, -1).join(', ') + ', or ' + candidateShorts[candidateShorts.length - 1]
const prompt = `Which ${command.rawNoun}${list}?`
const next: GameState = {
...state,
pendingDisambiguation: { verb: command.verb, candidates: command.candidates, prompt },
}
return narrate(next, [{ kind: 'narration', text: prompt }])
}
if (command.kind === 'verb-only') {
if (command.verb === 'look') return handleLook(state, world)
if (command.verb === 'inventory') return handleInventory(state, world)