Implementation:23blocks OS Ai maestro Question State
| Knowledge Sources | |
|---|---|
| Domains | Chat, UI |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete tool for determining whether an agent question is still live and has been answered, using transcript markers and hook state, used by both chat renderers, provided by AI Maestro's `lib/question-state.mjs`.
Description
The question-state module provides one implementation of the question live/answered logic, used by both `ChatView` and `MobileChatView`. `askUserQuestionIn` extracts the `AskUserQuestion` tool_use block from a message. `isQuestionAnswered` checks the `tool_result_marker` (emitted by `parseJsonlLines`, survives reload) and a local set — the marker is the record, the local set is a nicety. `isQuestionCurrent` checks that it is the LAST question and nothing has been said since (once the agent speaks, the question is settled — clicking a stale option sends a keystroke to a menu no longer on screen). Hook status alone is not sufficient: `idle_prompt` is indistinguishable from waiting on a menu.
Usage
Call `askUserQuestionIn(message)` to find a question. Call `isQuestionAnswered(messages, toolUseId, locallyAnswered)` and `isQuestionCurrent(messages, toolUseId, hookState)` to check state.
Code Reference
Source Location
- Repository: ai-maestro
- File: lib/question-state.mjs
- Lines: L1-L159
Signature
export function askUserQuestionIn(message): object | null
export function isQuestionAnswered(messages, toolUseId, locallyAnswered): boolean
export function isQuestionCurrent(messages, toolUseId, hookState): boolean
Import
import { askUserQuestionIn, isQuestionAnswered, isQuestionCurrent } from '@/lib/question-state.mjs'
I/O Contract
| Name | Type | Description |
|---|---|---|
| askUserQuestionIn() returns | null | The AskUserQuestion tool_use block |
| isQuestionAnswered() returns | boolean | True if a tool_result exists for this id |
| isQuestionCurrent() returns | boolean | True if this is the last question and still live |
Usage Examples
import { askUserQuestionIn, isQuestionAnswered, isQuestionCurrent } from '@/lib/question-state.mjs'
const question = askUserQuestionIn(lastMessage)
if (question && !isQuestionAnswered(messages, question.id, localSet) && isQuestionCurrent(messages, question.id, hookState)) {
renderQuestionCard(question)
}