Skip to content

AskUserQuestion with async: one way to ask the human, waiting or not (7.148.0) - #191

Merged
SSFSKIM merged 29 commits into
mainfrom
ask-async
Oct 14, 2026
Merged

SSFSKIM merged 29 commits into
mainfrom
ask-async

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 13, 2026

Copy link
Copy Markdown
Owner

This replaces the built-in AskUserQuestion with mcp__doperpowers__AskUserQuestion. It takes the built-in's input plus async, and it is asked through Claude Code's own dialog.

  • Blocking ask (async false, the default): the engine's dialog opens at once and the call returns the built-in's own result text. The recorded result is byte-identical to the built-in's.
  • Async ask (async: true): the call returns at once. The questions wait in the human's view, in the call's row and in a band above the prompt, each behind an [ answer ] button. When the human submits, the answer reaches the model one of three ways:
    • beside its next tool result, if a turn is running;
    • as a new prompt, if the session is idle;
    • with the human's next prompt, if they interrupted the turn.
  • Withdrawals: the built-in is withdrawn while the tool exists. The to-human <need-input> mark is retired; an old one now reads as a <message>.

Spec: docs/doperpowers/specs/2026-10-13-ask-async-design.md. Execution report: docs/doperpowers/specs/2026-10-13-ask-async-report.md. Version 7.148.0.

Validation Evidence

Claim Command / check Output
Mod unit tests pass tests/mods/run-mods-tests.sh 167 pass / 0 fail, then ask search: all checks passed
Streaming hook still correct tests/claude-code/test-to-human-stream-hook.sh to-human-stream hook: all checks passed
Types check npx -p typescript@5 tsc -p hooks/mods/tsconfig.json exit 0
Plugin manifest valid claude plugin validate .claude-plugin/plugin.json ✔ Validation passed with warnings. The warnings are main's baseline, compared in a detached worktree of main. The gating-hook notes drop from 9 to 8.
Hooks module loads live --debug-file hooks module doperpowers@inline loaded (worker, environment 1, tier user), with no refusal and no HooksError
Blocking parity, byte for byte (acceptance 1) fixed payload, same keys, then compare the recorded tool_result in the two transcripts IDENTICAL: `"The user answered: "Which backend?"="SQLite" selected preview:\n+--------+\n
Async answer delivered mid-turn, idle, and after a stop (acceptance 2, 3, 4b) live tmux sessions mid-turn: a hook_additional_context attachment with hookName: tool.call; idle: The doperpowers plugin sent a message:\nThe human responded to your async AskUserQuestion (call toolu_…); after an interrupt: no new turn starts, and the next prompt carries it (hookName: prompt.submit)
Esc keeps an async ask open; two asks are each delivered once (acceptance 4, 4a) live nothing is delivered and the row keeps [ answer ]; each (call <id>) appears ×1 in the attachment rows
Built-in withdrawn; subagents refused (acceptance 5, 6) live <tool_use_error>Withdrawn in this session: ask through mcp__doperpowers__AskUserQuestion, which takes this tool's input plus async.</tool_use_error>; subagent: AskUserQuestion is for the main conversation: report what you need to the agent that dispatched you.
Resume rebuilds asks (acceptance 7) /exit, then claude --resume the open ask shows [ answer ] with 1 open question above the prompt; the answered ask draws its answers; the call refused by validation is not an ask
<need-input> retired (acceptance 8) grep the style; resume a before-arm transcript 0 marks in output-styles/to-human.md; an old mark draws as a message, with <choice> as text and no buttons
Blocking refusals (acceptance 9) live after Esc, the queued Write gets Not run: the human declined the question asked in this turn., no x.txt is written, and no assistant row follows; after "Chat about this", the turn goes on (echo after-ask → after-ask)
Pasted images (acceptance 12, 13) live paste of a PNG; the clipboard was saved and restored blocking: the result is [text, image/png block] and the model describes the image; async: the delivery ends [Image source: /private/tmp/claude-501/…/images/1.png] and the model Reads it

Eval (acceptance 11; behavior change). claude-opus-5-5 with the to-human style, 3 runs per cell, interactive sessions in tmux, scored from the transcripts:

Scenario Before (main) After (this branch)
S1: independent work plus a needed preference 1/3 a <need-input> mark; 2/3 no question (the model referred to a question it never wrote) 3/3 async ask, with todo.py written in the same turn
S2: a decision everything depends on 3/3 the built-in, blocking 3/3 the new tool, blocking
S3: no question warranted 3/3 no ask, task done 3/3 no ask, task done
Marks / built-in calls 1 / 3 0 / 0

The first style round missed the bar twice: one run asked async and then waited, and another recommended an answer instead of asking. The second round revised only the style paragraph and restored the old style's guard sentence. The table shows round 2.

Reviews. Each milestone got a task review (sol/xhigh), and each review's findings were fixed and re-reviewed. The whole-branch review at the high rung (doperpowers:reviewer-high) found two issues, then a regression in the first fix; all are fixed, and the final verdict is correct.

Unresolved Review Findings

  • hooks/mods/ask.tsx is about 1,250 lines. Its pure helpers (validation, row and delivery text, transcript rebuild) could move to a sibling .ts that ask.tsx re-exports. Left as is because the spec's Interfaces section places these exports in ask.tsx, and the file has one responsibility. (M2 task review, Minor.)

  • The resume search for transcripts over 4 MiB (ask.tsx, searchArgs) has three gaps:

    • Its filtered output is capped at 4 MiB. When that ceiling is hit, the search rebuilds nothing and logs a debug line.
    • It cannot follow rewind ancestry.
    • It is unit-tested and checked against one real transcript, but not live.

    It was left because the case is rare, the limits are documented in hooks/mods/README.md, and streaming through $.process.spawn would be the next step. (M2 task review and branch review, Minor.)

  • The eval scorer does not enforce S1's same-turn requirement (.doperpowers/sde/…/m3-eval/bin/score.py, a gitignored eval artifact). The recorded S1 runs were each checked by hand to finish in one turn. (M3 task review, Minor.)

  • A pasted picture the human removed can still be sent if their own answer ends with the literal text (Image attached). No hook-reachable signal names which attachments the human kept, so the mod counts the engine's marks. Recorded as a known limit in the README; the design session accepted it. (M1 task review.)

Residue

  • User agent definitions. ~/.claude/agents/astra.md and sol-xhigh.md withhold the compact tools but not mcp__doperpowers__AskUserQuestion. The hook still refuses a subagent's call; only the schema rides in their context. This is user config, and the design session updates it after merge.
  • MAWS has to learn the tool. Under MAWS_NATIVE_TO_HUMAN, MAWS draws the report itself. The engine writes a plugin tool's tool_use row to the transcript only after the call resolves, so a transcript watcher cannot see an open blocking ask of this tool.
  • The smns project-log spec has a stale source. docs/doperpowers/specs/2026-10-13-smns-project-log-design.md still sources its need-input event from the retired mark. Its source is now an async ask: text is the questions, choices the option labels, src the call. That spec's owner takes this.
  • A rewind inside a running session. No hook-visible rewind event exists, so the abandoned branch's open asks stay in the band until a resume rebuilds them. Closing this needs an engine event or a cheap signal.

SSFSKIM and others added 29 commits October 13, 2026 08:54
…or not

The engine's own dialog, widened inside doperpowers from $.ui.ask's one
question to the full set; blocking returns the engine's text, async returns
at once and delivers the answer beside the next tool result or as a new
prompt; the built-in withdrawn; <need-input> retired. Engine facts probed
on 2.1.296.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…acts from the bundle; Esc ends a blocking turn, Chat about this is delivered

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… queue, origin-bound claims and delivery, stops not undone, accepted-only resume, fixed-payload parity, eval fixtures

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rt the selections, preview and note

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…al, reserved delivery with put-back, token-correlated claims

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e built-in (M1)

The tool takes the built-in's input plus async, opens Claude Code's own
dialog through $.ui.ask widened to the whole question set by a token
claim on this plugin's origin, and returns the engine's result text
byte for byte; pasted pictures come back as image blocks from the
session's pasted-image store. The built-in is withdrawn behind tool
search from the start of an interactive session and refused when
called. Validation reproduces the built-in's error text. A declined
ask latches the turn: later model calls are refused and the next model
request is aborted unsent (turn.step + $.turn.abort, chosen over
PostToolBatch preventContinuation, which draws a stop line). Subagents
are refused and the agent definitions withhold the tool.
…s them; catch policies on the gating hooks

The pasted-image store keeps a paste the dialog's Delete removed, so the
engine's '(Image attached)' marks decide: when the marked answers account
for every new file, all were kept and go as image blocks; otherwise none
goes (debug line). 'Chat about this' keeps its text refusal and appends
one [Image: source: <realpath>] line per kept picture. The four gating
hooks ask.tsx adds get a .catch: the withdrawal fails closed for the
model, the tool's own failure is a refusal naming it, re-entry passes on.
…age source: <path>], from one exported helper
… resume (M2)

An async ask returns at once and stands open in its transcript row and above
the prompt behind [ answer ]; a press raises the engine dialog from the
ui.press dispatch. Esc leaves it open; an answer or "Chat about this" is
delivered: submitted at once while idle, else held for the next model-made
main-loop result (never a plugin's call, a deny, or a call the human's
interrupt cut), the turn's answered end, or the human's next prompt as
context. Failed submissions put their answers back in front. Every ask's row
draws as the built-in's (the engine's own row is out of reach: probed). A
resumed session rebuilds accepted asks from the rows the model read.
…gin's framed rows; a cut search rebuilds nothing

The prompt.submit route puts its reserved answers back when the pass beneath
rejects, before the fail-open policy lets the prompt through. Resume counts a
user row as a delivery only when it carries the engine's plugin framing, so a
human quoting a delivery head does not close an ask. The large-transcript
search narrows to the stored forms resume reads (no prompt-snapshot rows),
tells no match (exit 1) from failure, and rebuilds nothing, with a debug
line, when its output was cut at 4 MiB. $.fs.read takes no offset/limit, so
the search stays.
…ontext

Both delivery routes append to a context list that may already hold another
hook's entries, so a stored attachment can carry the delivery head in a later
entry; the search matched only a head opening the list, and such an ask was
rebuilt open. A later entry is now matched too (`","<head>`). A shell check
runs the real grep with the mod's own arguments (searchArgs) over a fixture
transcript and compares its rebuild with the full read's; the mods runner
runs it after the mods' tests, which cannot reach a process.
…uestion with async; the mark reads as a message

The style's need-input paragraph becomes one on AskUserQuestion and its
async flag (maws-to-human-contract 3). The view and the streaming hook read
<need-input> as an alias of <message>, its <choice> lines as text; the
choice grammar, question buttons, answer prompt form and the prompt.submit
hook that settled questions are gone.
…sage; a question the turn ends on is blocking (eval round 2)
…bout this" reads a whole answer for its image mark

Resume rebuilt asks from every row of the transcript, so after a rewind the
abandoned branch's accepted asks came back open and its deliveries closed
asks still open on the resumed branch. It now reads only the conversation
the engine resumes: back from the leaf (the last row written, or the leaf a
rewind's explicit last-prompt record names, none when it went back past the
first prompt), parent by parent, across a compaction by the boundary's
logicalParentUuid. A search of a transcript over 4 MiB has no ancestry and
keeps every line found; that and a rewind inside a running session (no event
a hook sees) are recorded as known limits.

The "Chat about this" refusal lists each answer as the human typed it,
newlines included; the parser took only the first line, so a multiline answer
lost its (Image attached) mark and the kept picture was dropped. It now reads
the whole answer, up to the question's notes, the next question, or the end.
…ound one is rebuilt as the engine restores it

0fac448 walked the parentUuid chain on every resume, but one model response
is a row per block and each tool result is parented to its own call's row,
so an async ask's acceptance beside a later call in the same response fell
off the chain and the ask was not rebuilt: a regression in a normal session.

Without a rewind record the whole file is the conversation again, as before.
With one, the chain is rebuilt as the engine's i1r restores it: each response
on the chain brings its rows (same message.id), the results of its calls (by
parent, sourceToolAssistantUUID, or call id), and the runs of side rows under
them that neither fork nor rejoin the chain (Vae), so a context attachment
carrying a delivery on such a result comes with it.
@SSFSKIM
SSFSKIM merged commit d3c9448 into main Oct 14, 2026
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