packages feed

baikai-claude 0.3.0.2 → 0.4.0.0

raw patch · 3 files changed

+65/−6 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Baikai.Provider.Claude.Cli: claudeCliCommand :: ClaudeCliConfig -> Model -> Context -> (FilePath, [String])
+ Baikai.Provider.Claude.Cli: claudeCliCommand :: ClaudeCliConfig -> Model -> Context -> Options -> (FilePath, [String])

Files

baikai-claude.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.4 name:          baikai-claude-version:       0.3.0.2+version:       0.4.0.0 synopsis:      Anthropic Claude providers for the baikai abstraction description:   Wraps the claude Haskell package as a Baikai Provider for both the Anthropic API and the
src/Baikai/Provider/Claude/Cli.hs view
@@ -45,6 +45,7 @@ import Baikai.Response qualified as Resp import Baikai.StopReason (StopReason (..)) import Baikai.Stream (liftCompleteToStream)+import Baikai.ThinkingLevel (ThinkingLevel (ThinkingMinimal), renderThinkingLevel) import Baikai.Usage (zeroUsage) import Control.Exception (SomeAsyncException (..), SomeException, displayException, fromException, throwIO, try) import Control.Lens ((^.))@@ -138,17 +139,30 @@ -- | Render the executable and arguments for a @claude -p@ batch call. -- The prompt is preceded by @--@ so dash-leading prompts and variadic -- flags in 'extraArgs' cannot be parsed as options.-claudeCliCommand :: ClaudeCliConfig -> Model -> Context -> (FilePath, [String])-claudeCliCommand cfg m ctx =+claudeCliCommand :: ClaudeCliConfig -> Model -> Context -> Options -> (FilePath, [String])+claudeCliCommand cfg m ctx opts =   ( cfg ^. #executable,     ["-p"]       <> modelArgs m       <> ["--output-format", "json", "--no-session-persistence"]       <> systemPromptArgs ctx+      <> effortArgs opts       <> fmap Text.unpack (cfg ^. #extraArgs)       <> ["--", Text.unpack (Internal.renderPrompt ctx)]   ) +-- | Render @--effort@ from 'Options.thinking'. Claude's @--effort@ has+-- no @minimal@, so the lowest Baikai level collapses to @low@; when+-- 'thinking' is unset, no effort flag is emitted.+effortArgs :: Options -> [String]+effortArgs opts = case opts ^. #thinking of+  Nothing -> []+  Just lvl -> ["--effort", Text.unpack (claudeEffortValue lvl)]++claudeEffortValue :: ThinkingLevel -> Text+claudeEffortValue ThinkingMinimal = "low"+claudeEffortValue lvl = renderThinkingLevel lvl+ -- | The shape of @claude -p --output-format json@ stdout. data ClaudeCliResult = ClaudeCliResult   { result :: !Text,@@ -190,8 +204,8 @@     isResult _ = False  runClaudeCli :: ClaudeCliConfig -> Model -> Context -> Options -> IO Resp.Response-runClaudeCli cfg m ctx _opts = do-  let (exe, args) = claudeCliCommand cfg m ctx+runClaudeCli cfg m ctx opts = do+  let (exe, args) = claudeCliCommand cfg m ctx opts   start <- getCurrentTime   executed <-     trySync $
test/Main.hs view
@@ -34,6 +34,7 @@       [ commandRenderingTest,         effortRenderingTests,         batchCommandRenderingTest,+        batchEffortRenderingTests,         stderrFloodTest,         compatDetectionTest,         rejectsImageToolResultsTest,@@ -174,7 +175,7 @@           emptyContext             & #systemPrompt .~ Just "Be terse."             & #messages .~ Vector.singleton (user "-begin with a dash")-    ClaudeCli.claudeCliCommand cfg model ctx+    ClaudeCli.claudeCliCommand cfg model ctx emptyOptions       @?= ( "/bin/claude",             [ "-p",               "--model",@@ -190,6 +191,50 @@               "-begin with a dash"             ]           )++batchEffortRenderingTests :: TestTree+batchEffortRenderingTests =+  testGroup+    "claude -p argv renders reasoning effort between the system prompt and extra args"+    [ testCase name $ do+        let cfg =+              ClaudeCli.defaultClaudeCliConfig+                { ClaudeCli.executable = "/bin/claude",+                  ClaudeCli.extraArgs = ["--allowedTools", "Read"]+                }+            model =+              emptyModel+                & #modelId .~ "sonnet"+                & #api .~ AnthropicMessagesCli+                & #provider .~ "anthropic"+            ctx =+              emptyContext+                & #systemPrompt .~ Just "Be terse."+                & #messages .~ Vector.singleton (user "ping")+            opts = emptyOptions & #thinking .~ Just level+        ClaudeCli.claudeCliCommand cfg model ctx opts+          @?= ( "/bin/claude",+                [ "-p",+                  "--model",+                  "sonnet",+                  "--output-format",+                  "json",+                  "--no-session-persistence",+                  "--system-prompt",+                  "Be terse.",+                  "--effort",+                  expected,+                  "--allowedTools",+                  "Read",+                  "--",+                  "ping"+                ]+              )+    | (name, level, expected) <-+        [ ("minimal as low", ThinkingMinimal, "low"),+          ("max", ThinkingMax, "max")+        ]+    ]  stderrFloodTest :: TestTree stderrFloodTest =