baikai-agent 0.2.0.4 → 0.3.0.0
raw patch · 4 files changed
+265/−21 lines, 4 filesdep ~baikaidep ~baikai-openaiPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: baikai, baikai-openai
API changes (from Hackage documentation)
+ Baikai.Agent.Cli: AgentReviewCodexHooks :: !FilePath -> AgentCliCommand
+ Baikai.Agent.Run: missingEnvironment :: [Text] -> IO [Text]
Files
- CHANGELOG.md +144/−0
- baikai-agent.cabal +3/−3
- src/Baikai/Agent/Cli.hs +117/−18
- src/Baikai/Agent/Run.hs +1/−0
CHANGELOG.md view
@@ -7,6 +7,150 @@ ## [Unreleased] +## [baikai 0.11.0.0] - 2026-11-23++### Added++- Add `anthropic_claude_fable_5_2` on Claude Messages with adaptive thinking,+ client function tools, and structured output for eligible organizations.+ Standard rates per million tokens are $8 input, $40 output, $0.20 cache+ read, $10 five-minute cache write, and $16 one-hour cache write. Fast mode+ doubles those rates.+- Add `openai_gpt_6_2_astra` and `openai_gpt_6_2_sol` on OpenAI Responses+ with structured output, function tools, and Standard pricing for both+ cache durations and long-context requests.+- Add `openai_gpt_6_1_terra` on OpenAI Responses with explicit reasoning+ and cache compatibility, 30-minute and 12-hour cache-write prices, and+ whole-request pricing above 272,000 input tokens.++### Changed (breaking)++- `AssistantContent` changes its `Generic` representation to carry original+ Responses items. `AssistantText` and `AssistantToolCall` are bundled pattern+ synonyms. Existing persisted content still decodes.++### Fixed++- Apply the published long-context tier for GPT-5.6 Sol, its `gpt-5.6`+ alias, GPT-5.6 Terra, and GPT-5.6 Luna. Use the published one-hour write+ rates for eight Claude bindings that used the five-minute rate.++## [baikai-claude 0.7.3.1] - 2026-11-23++### Changed++- Use `claude-hs 0.1.0.0` for the Messages transport and require+ `baikai ^>=0.11.0.0`. Fable 5.2 tool continuations preserve signed+ thinking, including empty signed blocks.++### Fixed++- Reject unsupported assistant prefills before dispatch. Claude 4.5 accepts+ prefills with effective thinking off. Normal tool-result continuations+ preserve prior assistant history.++## [baikai-openai 0.7.4.0] - 2026-11-23++### Added++- Expose `Baikai.Provider.OpenAI.HookEvidence` for Codex app-server clients+ to verify a reviewed pre-tool handler and decode its completion outcome.+- Add scoped Codex batch completion with reviewed PreToolUse hooks and+ native denial evidence.++### Changed++- Require `baikai ^>=0.11.0.0` for persisted Responses replay.++### Fixed++- Preserve completed Responses message and function-call items in stateless+ history. GPT-6.2 keeps reusable system prompts at the head of the input+ across tool turns.++## [baikai-typesafe 0.1.0.2] - 2026-11-23++### Changed++- Build against `baikai ^>=0.11.0.0`.++## [baikai-trace-otel 0.4.1.2] - 2026-11-23++### Changed++- Build against `baikai ^>=0.11.0.0`.++## [baikai-effectful 0.5.0.1] - 2026-11-23++### Changed++- Build against `baikai ^>=0.11.0.0`.++## [baikai-kit 0.4.0.4] - 2026-11-23++### Changed++- Build against `baikai ^>=0.11.0.0`.++## [baikai-agent 0.3.0.0] - 2026-11-23++### Added++- `baikai agent review-codex-hooks` presents exact native declarations for+ approval. `baikai agent run --codex-hooks` reports denials from the+ checked app-server thread in the JSON result.++### Changed (breaking)++- `AgentCliCommand` gains `AgentReviewCodexHooks`. Add that case to+ exhaustive matches. The runner requires `baikai ^>=0.11.0.0` and+ `baikai-openai ^>=0.7.4.0`.++## [baikai-openai 0.7.3.1] - 2026-11-14++### Fixed++- Require `baikai ^>=0.10.1.1` in library and tests so new adapter consumers+ receive the Codex final-message correction.++## [baikai 0.10.1.1] - 2026-11-14++### Fixed++- `baikai`: the Codex batch parser returns the last completed agent message+ instead of concatenating complete messages, preserving structured JSON after+ intermediate commentary. Started and updated items cannot replace the final+ answer; usage and thread observations still cover the whole run ([BUG-2](docs/bug-reports/codex-concatenates-complete-agent-messages.md)).++## [baikai 0.10.1.0] - 2026-11-03++### Added++- `Baikai.Trace.withTraceFold` and `withTraceFoldWith` own tracing across the+ entire consumer fold; `withTraceList` and `withTraceListWith` collect events.+ A healthy sink receives abort evidence before cancellation propagates,+ including cancellation between stream steps.++### Fixed++- `withTrace`, `withTraceWith`, and the traced call in `runRequestWith` and+ `runRequestWithRegistry` now finalize synchronously on cancellation. Cleanup+ resumes an interrupted terminal drain within the same one-second budget,+ preserves the original exception, and never duplicates terminal evidence.+ General-stream abandonment keeps its garbage-collection-eventual contract.++## [baikai-effectful 0.5.0.0] - 2026-11-03++### Added++- `streamCollectTraced` delegates traced event collection to core with bounded+ cleanup on cancellation. Re-export `TraceSink` for operation signatures.++### Changed (breaking)++- `Baikai` gains `StreamCollectTraced`. Third-party interpreters must handle+ this constructor. The binding requires `baikai ^>=0.10.1`.+ ## [baikai 0.10.0.0] - 2026-10-25 ### Added
baikai-agent.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.4 name: baikai-agent-version: 0.2.0.4+version: 0.3.0.0 synopsis: Unattended coding-agent runs for the Baikai abstraction description: Runs a local coding-agent command-line tool with no terminal and no@@ -66,9 +66,9 @@ build-depends: aeson ^>=2.2,- baikai ^>=0.10.0,+ baikai ^>=0.11.0.0, baikai-claude ^>=0.7.3,- baikai-openai ^>=0.7.3,+ baikai-openai ^>=0.7.4.0, base >=4.20 && <5, bytestring ^>=0.12, containers ^>=0.7,
src/Baikai/Agent/Cli.hs view
@@ -33,7 +33,8 @@ jsonOutput, evidenceFile, runId,- requiredEvidence+ requiredEvidence,+ codexHooks ), agentCliOptions, agentCliParser,@@ -94,7 +95,7 @@ repositoryScopeViolations, resolveAgentJob, )-import Baikai.Agent.Run (runAgentCommand)+import Baikai.Agent.Run (missingEnvironment, runAgentCommand, timeoutMicros) import Baikai.Evidence ( EvidenceRequest (..), EvidenceStrength (..),@@ -113,7 +114,15 @@ ( CodexAgentConfig, codexAgentCommand, defaultCodexAgentConfig,+ runCodexAgentWithHooks, )+import Baikai.Provider.OpenAI.HookEvidence (CodexPreToolUse (..))+import Baikai.Provider.OpenAI.ReviewedHooks+ ( CodexHookTurn (..),+ CodexHooks,+ parseCodexHooks,+ reviewCodexHooksInTerminal,+ ) import Control.Applicative ((<|>)) import Control.Exception (IOException, bracketOnError, displayException, try) import Control.Lens ((&), (.~), (^.))@@ -146,6 +155,7 @@ import System.Directory ( doesFileExist, getCurrentDirectory,+ makeAbsolute, removeFile, renameFile, )@@ -158,8 +168,9 @@ (</>), ) import System.IO (hClose, openBinaryTempFileWithDefaultPermissions, stdin)+import System.Timeout (timeout) --- | Which of the three commands was asked for.+-- | Which command was requested. data AgentCliCommand = -- | Run a named job, taking the prompt from the given source. AgentRun !Text !PromptSource@@ -167,6 +178,7 @@ AgentShow !Text | -- | Enumerate the configured jobs. AgentList+ | AgentReviewCodexHooks !FilePath deriving stock (Eq, Show, Generic) -- | Where the prompt comes from. The three are mutually exclusive on@@ -206,7 +218,9 @@ -- @--require-evidence@. Setting it turns recording on and makes the -- run refuse rather than start when the configuration cannot -- produce it.- requiredEvidence :: !(Maybe EvidenceStrength)+ requiredEvidence :: !(Maybe EvidenceStrength),+ -- | Invocation-only Codex policy selected by the operator.+ codexHooks :: !(Maybe FilePath) } deriving stock (Generic) @@ -286,7 +300,8 @@ jsonOutput = False, evidenceFile = Nothing, runId = Nothing,- requiredEvidence = Nothing+ requiredEvidence = Nothing,+ codexHooks = Nothing } -- | A run result carrying an exit code and no output on either stream.@@ -332,6 +347,12 @@ listOptionsParser (Options.progDesc "List the configured jobs and the scope each came from") )+ <> Options.command+ "review-codex-hooks"+ ( Options.info+ (agentCliOptions . AgentReviewCodexHooks <$> Options.strArgument (Options.metavar "FILE"))+ (Options.progDesc "Review the native Codex PreToolUse commands in FILE")+ ) ) runOptionsParser :: Parser AgentCliOptions@@ -346,6 +367,8 @@ <*> Options.optional evidenceFileOption <*> Options.optional runIdOption <*> Options.optional requireEvidenceOption+ <*> Options.optional+ (Options.strOption (Options.long "codex-hooks" <> Options.metavar "FILE" <> Options.help "Use reviewed Codex PreToolUse hooks for this run")) where assemble jobName@@ -356,7 +379,8 @@ jsonOutput evidenceFile runId- requiredEvidence =+ requiredEvidence+ codexHooks = AgentCliOptions { command = AgentRun jobName promptSource, overrides,@@ -365,7 +389,8 @@ jsonOutput, evidenceFile, runId,- requiredEvidence+ requiredEvidence,+ codexHooks } showOptionsParser :: Parser AgentCliOptions@@ -386,7 +411,8 @@ jsonOutput, evidenceFile = Nothing, runId = Nothing,- requiredEvidence = Nothing+ requiredEvidence = Nothing,+ codexHooks = Nothing } listOptionsParser :: Parser AgentCliOptions@@ -405,7 +431,8 @@ jsonOutput, evidenceFile = Nothing, runId = Nothing,- requiredEvidence = Nothing+ requiredEvidence = Nothing,+ codexHooks = Nothing } jobArgument :: Parser Text@@ -600,10 +627,30 @@ AgentConfigPaths -> EnvSnapshot -> AgentCliOptions -> IO AgentCliRun runAgentCliWithPaths paths snapshot options = case options ^. #command of AgentList -> listCommand paths options+ AgentReviewCodexHooks path -> reviewCodexHooksCommand path AgentShow jobName -> showCommand paths snapshot options jobName AgentRun jobName promptSource -> runCommand paths snapshot options jobName promptSource +-- The terminal confirmation is deliberately separate from policy-bearing runs.+reviewCodexHooksCommand :: FilePath -> IO AgentCliRun+reviewCodexHooksCommand path = do+ cwd <- getCurrentDirectory+ result <- reviewCodexHooksInTerminal "codex" cwd path+ pure $ case result of+ Left err -> failedRun refusedExitCode (err <> "\n")+ Right False -> failedRun refusedExitCode "Codex hook review cancelled.\n"+ Right True -> successfulRun "Codex has reviewed the current hook declarations.\n" ""++readCodexHooksFile :: FilePath -> IO (Either Text (BS.ByteString, CodexHooks))+readCodexHooksFile path = do+ bytes <- try @IOException $ do+ exists <- doesFileExist path+ if exists then BS.readFile path else ioError (userError "expected a file")+ pure $ do+ original <- either (const (Left ("Cannot read Codex hooks file " <> "'" <> Text.replace "'" "'\\''" (Text.pack path) <> "'."))) Right bytes+ (original,) <$> parseCodexHooks original+ -- | Discovery, with explicit paths winning per scope. When both scopes -- are explicit nothing is discovered at all, so a fully specified -- invocation never reads @HOME@ or @XDG_CONFIG_HOME@.@@ -1122,32 +1169,83 @@ execute options staged promptBody = case prepared of Left refusal -> pure (refusedRun (renderAgentRenderError refusal))- Right (request, command, translation) -> do- ran <- runAgentCommand (evidenceRequestFor options) translation request command- written <- writeEvidenceFile (options ^. #evidenceFile) (ran ^. #evidence)- pure (interpret options staged request (ran ^. #outcome) (ran ^. #evidence) written)+ Right (request, command, translation) -> case options ^. #codexHooks of+ Just path+ | request ^. #provider /= AgentCodex ->+ pure (refusedRun "--codex-hooks requires a Codex job.")+ | isJust (evidenceRequestFor options) ->+ pure (refusedRun "Reviewed Codex runs provide hook evidence through --json. Omit --evidence-file, --run-id and --require-evidence.")+ | otherwise -> reviewedRun request command path+ Nothing -> do+ ran <- runAgentCommand (evidenceRequestFor options) translation request command+ written <- writeEvidenceFile (options ^. #evidenceFile) (ran ^. #evidence)+ pure (interpret options staged request (ran ^. #outcome) (ran ^. #evidence) written) where request0 = agentJobRequest (staged ^. #job) promptBody prepared = do ceilingGuard staged request0 (command, translation) <- renderJobCommand (staged ^. #job) request0 pure (request0, command, translation)- refusedRun message+ reviewedRun request command path = do+ missing <- missingEnvironment (request ^. #envRequires)+ if not (null missing)+ then pure (refusedRun ("Required environment variables are missing: " <> Text.intercalate ", " missing))+ else do+ absolute <- makeAbsolute path+ readCodexHooksFile absolute >>= \case+ Left err -> pure (reviewedFailure "failed" configExitCode err)+ Right (_, hooks) -> do+ let cfg = defaultCodexAgentConfig & #executable .~ (command ^. #executable)+ launch = runCodexAgentWithHooks cfg request hooks+ result <- maybe (Just <$> launch) (\limit -> timeout limit launch) (timeoutMicros (request ^. #timeout))+ case result of+ Nothing -> pure (reviewedFailure "failed" timeoutExitCode "Reviewed Codex run timed out. Inspect the workspace before retrying.")+ Just (Left err)+ | err == "Codex requires review for the current hooks." ->+ pure (refusedRun (err <> " In the job workspace, run baikai agent review-codex-hooks " <> "'" <> Text.replace "'" "'\\''" (Text.pack absolute) <> "'."))+ | otherwise -> pure (refusedRun err)+ Just (Right turn) -> do+ let answerBytes = Text.encodeUtf8 (answer turn <> "\n")+ retained = maybe answerBytes (\limit -> BS.take limit answerBytes) (request ^. #outputLimit)+ rendered = Text.decodeUtf8Lenient retained+ denied = blockedHooks turn+ truncation = if BS.length retained < BS.length answerBytes then "Codex output exceeded the configured limit.\n" else ""+ warnings =+ staged ^. #warnings+ <> Text.concat ["Codex PreToolUse blocked a call (" <> runIdOf blocked <> ").\n" | blocked <- denied]+ <> truncation+ reviewedJson =+ Aeson.object+ [ "outcome" Aeson..= ("completed" :: Text),+ "exitCode" Aeson..= (0 :: Int),+ "stdout" Aeson..= rendered,+ "blockedHooks" Aeson..= map hookJson denied+ ]+ pure (successfulRun (if options ^. #jsonOutput then encodeEnvelope reviewedJson else rendered) warnings)+ runIdOf = \CodexPreToolUse {runId = identifier} -> identifier+ hookJson event =+ Aeson.object+ [ "threadId" Aeson..= threadId event,+ "turnId" Aeson..= turnId event,+ "runId" Aeson..= runIdOf event+ ]+ refusedRun message = reviewedFailure "refused" refusedExitCode message+ reviewedFailure status code message | options ^. #jsonOutput = AgentCliRun- { exitCode = refusedExitCode,+ { exitCode = code, standardOutput = encodeEnvelope ( Aeson.object- [ "outcome" Aeson..= ("refused" :: Text),- "exitCode" Aeson..= refusedExitCode,+ [ "outcome" Aeson..= (status :: Text),+ "exitCode" Aeson..= code, "message" Aeson..= message ] ), standardError = staged ^. #warnings } | otherwise =- failedRun refusedExitCode (staged ^. #warnings <> "refused: " <> message <> "\n")+ failedRun code (staged ^. #warnings <> status <> ": " <> message <> "\n") interpret :: AgentCliOptions ->@@ -1289,6 +1387,7 @@ AgentRun name _ -> name AgentShow name -> name AgentList -> "agent"+ AgentReviewCodexHooks _ -> "agent review-codex-hooks" -- | Write one evidence record to the operator's chosen path, returning -- whatever went wrong.
src/Baikai/Agent/Run.hs view
@@ -18,6 +18,7 @@ -- happened\"; a coding agent that attempts its task and fails has run. module Baikai.Agent.Run ( runAgentCommand,+ missingEnvironment, -- * Evidence envelopes agentRequestEnvelope,