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
|
[ "-p", T.unpack prompt
|
||||||
, "--output-format", "json"
|
, "--output-format", "json"
|
||||||
, "--max-turns", "1"
|
, "--max-turns", "1"
|
||||||
|
, "--tools", ""
|
||||||
, "--json-schema", reviewJsonSchema
|
, "--json-schema", reviewJsonSchema
|
||||||
] ""
|
] ""
|
||||||
putStrLn $ "Claude stdout: " <> take 2000 stdout
|
putStrLn $ "Claude stdout: " <> take 2000 stdout
|
||||||
@ -84,45 +85,46 @@ invokeClaudeReply prompt = do
|
|||||||
[ "-p", T.unpack prompt
|
[ "-p", T.unpack prompt
|
||||||
, "--output-format", "json"
|
, "--output-format", "json"
|
||||||
, "--max-turns", "1"
|
, "--max-turns", "1"
|
||||||
|
, "--tools", ""
|
||||||
] ""
|
] ""
|
||||||
case exitCode of
|
case exitCode of
|
||||||
ExitSuccess -> pure $ parseClaudeTextOutput stdout
|
ExitSuccess -> pure $ parseClaudeTextOutput stdout
|
||||||
ExitFailure code ->
|
ExitFailure code ->
|
||||||
pure $ Left $ "claude exited with code " <> show code <> ": " <> stderr_
|
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 :: String -> Either String ReviewOutput
|
||||||
parseClaudeJsonOutput raw =
|
parseClaudeJsonOutput raw =
|
||||||
case eitherDecode (strToLBS raw) of
|
case eitherDecode (strToLBS raw) of
|
||||||
Right val ->
|
Right val ->
|
||||||
case parseMaybe extractResult val of
|
case parseMaybe extractField val of
|
||||||
Just (String resultText) ->
|
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)
|
eitherDecode (BL.fromStrict $ TE.encodeUtf8 resultText)
|
||||||
Just resultVal ->
|
Just resultVal ->
|
||||||
-- result is already a JSON object
|
-- structured_output is already a JSON object
|
||||||
case fromJSON resultVal of
|
case fromJSON resultVal of
|
||||||
Success v -> Right v
|
Success v -> Right v
|
||||||
Error e -> Left $ "Failed to parse result object: " <> e
|
Error e -> Left $ "Failed to parse structured_output: " <> e
|
||||||
Nothing -> Left "Missing 'result' field in Claude output"
|
Nothing -> Left "Missing 'structured_output' field in Claude output"
|
||||||
Left err -> Left $ "Failed to parse Claude JSON: " <> err
|
Left err -> Left $ "Failed to parse Claude JSON: " <> err
|
||||||
where
|
where
|
||||||
extractResult :: Value -> Parser Value
|
extractField :: Value -> Parser Value
|
||||||
extractResult = withObject "envelope" (.: "result")
|
extractField = withObject "envelope" (.: "structured_output")
|
||||||
|
|
||||||
-- Parse Claude's JSON envelope for freeform text: { "result": "..." }
|
-- Parse Claude's JSON envelope for freeform text: { "result": "..." }
|
||||||
parseClaudeTextOutput :: String -> Either String Text
|
parseClaudeTextOutput :: String -> Either String Text
|
||||||
parseClaudeTextOutput raw =
|
parseClaudeTextOutput raw =
|
||||||
case eitherDecode (strToLBS raw) of
|
case eitherDecode (strToLBS raw) of
|
||||||
Right val ->
|
Right val ->
|
||||||
case parseMaybe extractResult val of
|
case parseMaybe extractField val of
|
||||||
Just (String resultText) -> Right resultText
|
Just (String resultText) -> Right resultText
|
||||||
Just _ -> Left "Expected string 'result' in Claude output"
|
Just _ -> Left "Expected string 'result' in Claude output"
|
||||||
Nothing -> Left "Missing 'result' field in Claude output"
|
Nothing -> Left "Missing 'result' field in Claude output"
|
||||||
Left err -> Left $ "Failed to parse Claude JSON: " <> err
|
Left err -> Left $ "Failed to parse Claude JSON: " <> err
|
||||||
where
|
where
|
||||||
extractResult :: Value -> Parser Value
|
extractField :: Value -> Parser Value
|
||||||
extractResult = withObject "envelope" (.: "result")
|
extractField = withObject "envelope" (.: "result")
|
||||||
|
|
||||||
strToLBS :: String -> BL.ByteString
|
strToLBS :: String -> BL.ByteString
|
||||||
strToLBS = BL.fromStrict . TE.encodeUtf8 . T.pack
|
strToLBS = BL.fromStrict . TE.encodeUtf8 . T.pack
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user