From 5837275581de33141721af37c36cdfea21657323 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Sun, 15 Feb 2026 23:48:11 +1100 Subject: [PATCH] Disable tools and change JSON expectation --- src/Bot/Claude.hs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Bot/Claude.hs b/src/Bot/Claude.hs index 0150ffd..a42bf42 100644 --- a/src/Bot/Claude.hs +++ b/src/Bot/Claude.hs @@ -69,6 +69,7 @@ invokeClaudeReview prompt = do [ "-p", T.unpack prompt , "--output-format", "json" , "--max-turns", "1" + , "--tools", "" , "--json-schema", reviewJsonSchema ] "" putStrLn $ "Claude stdout: " <> take 2000 stdout @@ -84,45 +85,46 @@ invokeClaudeReply prompt = do [ "-p", T.unpack prompt , "--output-format", "json" , "--max-turns", "1" + , "--tools", "" ] "" case exitCode of ExitSuccess -> pure $ parseClaudeTextOutput stdout ExitFailure code -> pure $ Left $ "claude exited with code " <> show code <> ": " <> stderr_ --- Parse Claude's JSON envelope: { "result": } +-- Parse Claude's JSON envelope: { "structured_output": } parseClaudeJsonOutput :: String -> Either String ReviewOutput parseClaudeJsonOutput raw = case eitherDecode (strToLBS raw) of Right val -> - case parseMaybe extractResult val of + case parseMaybe extractField val of Just (String resultText) -> - -- result is a JSON string that needs to be parsed again + -- structured_output is a JSON string that needs to be parsed again eitherDecode (BL.fromStrict $ TE.encodeUtf8 resultText) Just resultVal -> - -- result is already a JSON object + -- structured_output is already a JSON object case fromJSON resultVal of Success v -> Right v - Error e -> Left $ "Failed to parse result object: " <> e - Nothing -> Left "Missing 'result' field in Claude output" + Error e -> Left $ "Failed to parse structured_output: " <> e + Nothing -> Left "Missing 'structured_output' field in Claude output" Left err -> Left $ "Failed to parse Claude JSON: " <> err where - extractResult :: Value -> Parser Value - extractResult = withObject "envelope" (.: "result") + extractField :: Value -> Parser Value + extractField = withObject "envelope" (.: "structured_output") -- Parse Claude's JSON envelope for freeform text: { "result": "..." } parseClaudeTextOutput :: String -> Either String Text parseClaudeTextOutput raw = case eitherDecode (strToLBS raw) of Right val -> - case parseMaybe extractResult val of + case parseMaybe extractField val of Just (String resultText) -> Right resultText Just _ -> Left "Expected string 'result' in Claude output" Nothing -> Left "Missing 'result' field in Claude output" Left err -> Left $ "Failed to parse Claude JSON: " <> err where - extractResult :: Value -> Parser Value - extractResult = withObject "envelope" (.: "result") + extractField :: Value -> Parser Value + extractField = withObject "envelope" (.: "result") strToLBS :: String -> BL.ByteString strToLBS = BL.fromStrict . TE.encodeUtf8 . T.pack