fix: permission-prompt-tool response format and scaffold .claude/settings.json
- Return { behavior: "allow", updatedInput: <input> } from prompt_permission
to match the Claude Code SDK expected format (was returning just
{ behavior: "allow" } which failed validation)
- Scaffold .claude/settings.json with sensible permission defaults (Edit,
Write, common Bash commands, mcp__story-kit__*) so fresh projects don't
trigger constant permission prompts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1816,7 +1816,7 @@ async fn tool_prompt_permission(args: &Value, ctx: &AppContext) -> Result<String
|
||||
.send(crate::http::context::PermissionForward {
|
||||
request_id: request_id.clone(),
|
||||
tool_name: tool_name.clone(),
|
||||
tool_input,
|
||||
tool_input: tool_input.clone(),
|
||||
response_tx,
|
||||
})
|
||||
.map_err(|_| "No active WebSocket session to receive permission request".to_string())?;
|
||||
@@ -1834,11 +1834,10 @@ async fn tool_prompt_permission(args: &Value, ctx: &AppContext) -> Result<String
|
||||
.map_err(|_| "Permission response channel closed unexpectedly".to_string())?;
|
||||
|
||||
if approved {
|
||||
// Claude Code SDK validates the response as a union:
|
||||
// { behavior: "allow" } | { behavior: "deny", message: string }
|
||||
// Previously we returned {"updatedInput": ...} which didn't match
|
||||
// either variant, causing intermittent `invalid_union` errors.
|
||||
Ok(json!({"behavior": "allow"}).to_string())
|
||||
// Claude Code SDK expects:
|
||||
// Allow: { behavior: "allow", updatedInput: <record> }
|
||||
// Deny: { behavior: "deny", message: string }
|
||||
Ok(json!({"behavior": "allow", "updatedInput": tool_input}).to_string())
|
||||
} else {
|
||||
slog_warn!("[permission] User denied permission for '{tool_name}'");
|
||||
Ok(json!({
|
||||
@@ -3374,7 +3373,7 @@ stage = "coder"
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn tool_prompt_permission_approved_returns_allow_behavior() {
|
||||
async fn tool_prompt_permission_approved_returns_updated_input() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
|
||||
@@ -3397,7 +3396,11 @@ stage = "coder"
|
||||
let parsed: Value = serde_json::from_str(&result).expect("result should be valid JSON");
|
||||
assert_eq!(
|
||||
parsed["behavior"], "allow",
|
||||
"approved must return behavior:allow for Claude Code SDK compatibility"
|
||||
"approved must return behavior:allow"
|
||||
);
|
||||
assert_eq!(
|
||||
parsed["updatedInput"]["command"], "echo hello",
|
||||
"approved must return updatedInput with original tool input for Claude Code SDK compatibility"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user