From e74d1f0836e51fa1b709da5f5d807dfb1a464b88 Mon Sep 17 00:00:00 2001 From: unraid Date: Fri, 3 Apr 2026 17:16:16 +0800 Subject: [PATCH] fix(buddy): address second round CodeRabbit findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - buddy.ts:105: remove unsafe (context as any).messages cast. ToolUseContext already declares messages: Message[] at Tool.ts:250, so context.messages is properly typed. Other commands (feedback, copy, export) access it the same way without cast. - companionReact.ts:154: wrap resp.json() in try/catch for defensive JSON parsing. Malformed 200 responses now return null instead of propagating to the outer catch. Rate-limit timing (set before API call) kept as-is — matches official ZUK pattern: prevents retry-storm on transient failures. src/ path alias suggestions dismissed — project uses relative paths. Auto-unmute on /buddy view kept — matches official behavior. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/buddy/companionReact.ts | 8 ++++++-- src/commands/buddy/buddy.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/buddy/companionReact.ts b/src/buddy/companionReact.ts index fb2e803e3..021167e0d 100644 --- a/src/buddy/companionReact.ts +++ b/src/buddy/companionReact.ts @@ -151,6 +151,10 @@ async function callBuddyReactAPI( if (!resp.ok) return null - const data = (await resp.json()) as { reaction?: string } - return data.reaction?.trim() || null + try { + const data = (await resp.json()) as { reaction?: string } + return data.reaction?.trim() || null + } catch { + return null + } } diff --git a/src/commands/buddy/buddy.ts b/src/commands/buddy/buddy.ts index e28826ef1..8d14ab4e6 100644 --- a/src/commands/buddy/buddy.ts +++ b/src/commands/buddy/buddy.ts @@ -102,7 +102,7 @@ export async function call( setState?.(prev => ({ ...prev, companionPetAt: Date.now() })) // Trigger a post-pet reaction - triggerCompanionReaction((context as any).messages ?? [], reaction => + triggerCompanionReaction(context.messages ?? [], reaction => setState?.(prev => prev.companionReaction === reaction ? prev