Return question answers in the tool's own input shape

The Claude chat bridge sent the whole AskUserQuestion input back nested
under questions, so Claude Code rejected every answer (questions must be
an array) and the operator's picks were lost. Echo the original input
with answers added; the fake CLI now enforces the schema.
This commit is contained in:
2026-11-12 01:37:59 +00:00
parent 17af656f00
commit 2330f50268
2 changed files with 18 additions and 11 deletions
+12 -10
View File
@@ -611,10 +611,12 @@ func (c *Chat) Answer(ctx context.Context, request protocol.ChatAnswerRequest) e
answers[question] = fmt.Sprint(typed)
}
}
response = map[string]any{
"behavior": "allow",
"updatedInput": map[string]any{"questions": form.rawQuestions, "answers": answers},
}
// The tool's own input comes back unchanged ({"questions": [...]} and
// any other fields) with the answers added.
updated := map[string]any{}
_ = json.Unmarshal(form.rawInput, &updated)
updated["answers"] = answers
response = map[string]any{"behavior": "allow", "updatedInput": updated}
}
s.mu.Lock()
form.answering = true
@@ -704,11 +706,11 @@ type pendingApproval struct {
}
type pendingForm struct {
form protocol.ChatForm
rawQuestions json.RawMessage
questions []string
proc *process
answering bool
form protocol.ChatForm
rawInput json.RawMessage
questions []string
proc *process
answering bool
}
func (s *session) receivePermission(p *process, requestID string, request toolRequest) {
@@ -819,7 +821,7 @@ func (s *session) receiveQuestion(p *process, requestID string, request toolRequ
form.Fields = append(form.Fields, field)
}
s.mu.Lock()
s.forms[requestID] = &pendingForm{form: form, rawQuestions: request.Input, questions: questions, proc: p}
s.forms[requestID] = &pendingForm{form: form, rawInput: request.Input, questions: questions, proc: p}
s.mu.Unlock()
s.emit(protocol.ChatEventFrame{SessionID: s.id, Kind: protocol.ChatEventForm, Form: &form})
}
+6 -1
View File
@@ -269,7 +269,12 @@ def handle(line):
tool_result("Error: " + str(result.get("message") or "denied"), True)
return
if pending["kind"] == "question":
answers = (result.get("updatedInput") or {}).get("answers") or {}
updated = result.get("updatedInput") or {}
# Like Claude Code: updatedInput must still match the tool's schema.
if not isinstance(updated.get("questions"), list):
tool_result("Error: The parameter `questions` type is expected as `array`", True)
return
answers = updated.get("answers") or {}
tool_result("Your questions have been answered: " + json.dumps(answers))
else:
tool_result("File created successfully")