Files
coucou/scripts/test-ask-question.sh
T
LouisandClaude Sonnet 4.6 c767db9249 Answer Claude questions from the notch (#165)
* feat: answer AskUserQuestion from the notch (issue #94)

Parse AskUserQuestion PermissionRequests into a Foundation-only AskQuestion
model (1–4 questions, 2–4 options each, single- or multi-select). The question
card shows options as buttons (single-select: click = answer; multi-select:
toggles + Send), a free-text Other… field, a 1/N counter for multi-question
flows, and a "Reply in terminal" fallback. nb-hook.py emits allow +
updatedInput when decision is "answer". 21 parsing and answer-construction
tests, CI step added.

Idea from issue #94 by @Vega8991

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: answer AskUserQuestion via PreToolUse --ask hook (Claude Code 2.1.85+)

- nb-hook.py --ask mode: guards tool_name == AskUserQuestion, injects
  coucou_kind, holds socket 125 s; on answer emits PreToolUse hookSpecificOutput
  with updatedInput {questions, answers} so Claude Code receives the replies
- HookServer: dedicated AskUserQuestion PreToolUse hook entry (130 s timeout)
  added to both buildHooksData() variants; hooksNeedUpdate() returns true when
  that entry is absent; banner updated accordingly
- handleClient routes coucou_kind == ask_user_question to processQuestionRequest;
  PermissionRequest for AskUserQuestion replies ask immediately; PreToolUse
  general event skips state update for AskUserQuestion
- AskQuestion.buildAnswers now returns [String: Any]: single-select → String,
  multi-select → [String] array (Claude Code 2.1.136+)
- QuestionView: ChipFlowLayout for option chips (shared with ModelPickerView),
  header shows 1/N counter + Reply-in-terminal link, Send/Next only for
  multi-select (disabled until a choice is made), single-select auto-advances
- Tests, docs updated; both schemes build clean

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: question card never appeared — treat .question as alert in expandIfNeeded

Added .question to the isAlert set so it force-expands when the island is
collapsed/hidden, and made it an always-wins view (alongside .approval) so it
replaces whatever is showing when the island is already open.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: question card UX — compact Other field, auto-release fd, header label

- Other… mode: field + Send capsule + ✕ now on one line (no extra row),
  field has rounded background (white 7%, r8), Send capsule dims when empty,
  Escape key resets to options, multi-select Send button hidden while Other
  field is open
- releaseQuestionFD(): sends "ask" immediately when QuestionView disappears
  without an explicit answer (collapse, view change, another alert taking over),
  does not touch state.view — called via QuestionView.onDisappear
- Header label: "Claude Code is asking" (static, not project-name-dependent)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-10-03 04:11:40 +02:00

9 lines
310 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
TEST_DIR="$(mktemp -d "${TMPDIR:-/tmp}/coucou-ask-question.XXXXXX")"
trap 'rm -rf "$TEST_DIR"' EXIT
swiftc NotchBuddy/Sources/App/AskQuestion.swift \
tests/AskQuestionTests.swift -o "$TEST_DIR/ask-question-tests"
"$TEST_DIR/ask-question-tests"