Disable tools and change JSON expectation
This commit is contained in:
parent
bd07e05691
commit
5837275581
@ -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": <structured output> }
|
||||
-- Parse Claude's JSON envelope: { "structured_output": <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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user