Provider-neutral CLI coding-agent launcher for Kagura harnesses, with auth hygiene, MCP wiring, verdicts, and doctor primitives
Project description
kagura-brain
kagura-brain is the provider-neutral Python launcher for the CLI coding agents
used as brains by Kagura harnesses. It gives consumers one tested seam for
running Claude Code (claude -p) or Codex CLI (codex exec), keeping provider
credentials, subprocess behavior, MCP wiring, and verdict handling out of each
harness.
from kagura_brain import select
brain = select("claude") # or "codex"
result = brain.invoke("Reply with exactly: PONG")
if not result.ok:
raise RuntimeError(result.detail())
print(result.stdout)
What it provides
- Two CLI adapters: Claude Code and Codex share one subprocess, timeout, output, and result contract.
- Subscription-auth hygiene: inherited provider credentials and endpoint overrides are removed before launch so the CLI's own login wins.
- Explicit alternate backends: callers can opt into a compatible gateway; Codex can also select local Ollama or LM Studio backends.
- Provider-neutral selection:
select()keeps backend dispatch and MCP translation inside the library. - Safe gate semantics: the verdict module normalizes proceed/halt decisions; unknown or missing verdicts halt.
- Preflight primitives: lightweight checks cover binaries, auth commands, endpoints, and aggregate reports.
Backend summary
| Claude Code | Codex CLI | |
|---|---|---|
| Command | claude -p |
codex exec |
| Default auth | Claude subscription login | codex login / ChatGPT subscription |
| Scrubbed child environment | ANTHROPIC_*, CLAUDE_* |
OPENAI_*, CODEX_* |
| MCP | .mcp.json via per-call CLI flags |
.mcp.json translated to per-call mcp_servers.* overrides |
| Confinement | permission mode or explicit bypass | sandbox mode or explicit approval+sandbox bypass |
| Alternate backend | Anthropic-compatible gateway | Responses-compatible gateway, Ollama, or LM Studio |
Neither adapter loosens permissions by default. Full-bypass options are explicit, and the Codex bypass also disables its sandbox. See Provider configuration before using an unattended mode.
Install
pip install kagura-brain
# or
uv add kagura-brain
Requirements:
- Python 3.11+
claudeand/orcodexinstalled and available onPATH- the selected CLI signed in, unless an explicit alternate backend is used
The Python package is stdlib-only at runtime and deliberately has no dependency
on kagura-memory.
For setup, authentication, result handling, and first examples, read Getting started.
Architecture at a glance
Kagura's reusable harness support is split along two independent axes:
kagura-engineer kagura-planner kagura-code-reviewer
\ | /
+---- kagura-brain + kagura-memory ----+
brain axis memory axis
kagura-brain launches the coding agent. kagura-memory supplies durable
context. Keeping them independent avoids the inverted dependency "memory spawns
the agent". The full module and launch-flow description is in
Architecture.
Documentation
| Document | Purpose |
|---|---|
| Documentation index | Map of the available guides and references |
| Getting started | Installation, authentication, first invocation, and results |
| Provider configuration | Claude/Codex options, MCP behavior, gateways, and permission boundaries |
| Architecture | Package boundaries, launch pipeline, modules, and security invariants |
| Exit-code contract | Canonical gate vocabulary and reviewer seam |
| Contributing | Development workflow, quality gates, and release smoke tests |
| Changelog | Release history |
Current release
Version 0.6.1 supports Python 3.11-3.13. The Codex adapter's environment and
configuration assumptions were last audited against Codex CLI 0.145.0; the
subprocess suite remains mocked, so releases also require the documented real-CLI
smoke test.
Development
uv sync --extra dev
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
uv run mypy
uv run pytest tests/ -v
Coverage must remain at or above 90%. See CONTRIBUTING.md for the complete workflow.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kagura_brain-0.6.1.tar.gz.
File metadata
- Download URL: kagura_brain-0.6.1.tar.gz
- Upload date:
- Size: 130.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9560ac231024757fd6cf721e3e26b763a2fd80ee6bbf82a81f18c10466199926
|
|
| MD5 |
bfa38d6aa2294c38b835068f2c5e7dc9
|
|
| BLAKE2b-256 |
bca53635009212e87ffb2b24149fea5df0e555de81f97278a03a4e2fafd97963
|
Provenance
The following attestation bundles were made for kagura_brain-0.6.1.tar.gz:
Publisher:
publish.yml on kagura-ai/kagura-brain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kagura_brain-0.6.1.tar.gz -
Subject digest:
9560ac231024757fd6cf721e3e26b763a2fd80ee6bbf82a81f18c10466199926 - Sigstore transparency entry: 2230816060
- Sigstore integration time:
-
Permalink:
kagura-ai/kagura-brain@1f01ae751ef1f84ecb261e11fff2e59df75aa34f -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/kagura-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1f01ae751ef1f84ecb261e11fff2e59df75aa34f -
Trigger Event:
push
-
Statement type:
File details
Details for the file kagura_brain-0.6.1-py3-none-any.whl.
File metadata
- Download URL: kagura_brain-0.6.1-py3-none-any.whl
- Upload date:
- Size: 35.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0f60703dad0e4f241354dea7112a5c316063db43957c99736aeb4764cba469b
|
|
| MD5 |
b372f6f5b9c38a867efb9c33c1edd07d
|
|
| BLAKE2b-256 |
77dd054b23a1d147a6e81e4ce1da8ba04e5b26fbce7ef4b30fbb0e9b159e2f04
|
Provenance
The following attestation bundles were made for kagura_brain-0.6.1-py3-none-any.whl:
Publisher:
publish.yml on kagura-ai/kagura-brain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kagura_brain-0.6.1-py3-none-any.whl -
Subject digest:
d0f60703dad0e4f241354dea7112a5c316063db43957c99736aeb4764cba469b - Sigstore transparency entry: 2230816681
- Sigstore integration time:
-
Permalink:
kagura-ai/kagura-brain@1f01ae751ef1f84ecb261e11fff2e59df75aa34f -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/kagura-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1f01ae751ef1f84ecb261e11fff2e59df75aa34f -
Trigger Event:
push
-
Statement type: