How youngyangyang04/kamaclaude works
Purpose and deployment shape
KamaClaude is a local, daemon-backed coding-agent runtime: clients submit goals, while the Core executes multi-step LLM/tool workflows and exposes execution as durable and live event streams. Python entry points separate the daemon, CLI, and TUI:
• src/kama_claude/core/__main__.py
• src/kama_claude/cli/__main__.py
• src/kama_claude/tui/__main__.py
Client–daemon protocol boundary
CLI commands and the TUI are IPC clients rather than agent hosts. The daemon exposes typed commands/events over socket transport; the wire contract is JSON-RPC 2.0 over NDJSON. This permits multiple clients, ongoing task execution after a client exits, and future alternate front ends.
• src/kama_claude/cli/main.py
• src/kama_claude/core/transport/socket_server.py
• src/kama_claude/core/bus/envelope.py
• WIRE_PROTOCOL.md
Core application and run orchestration
The Core application assembles runtime services and dispatches incoming commands. A runner creates/continues runs, coordinates session state, and invokes the agent loop. The loop implements the ReAct-like cycle: construct context, call an LLM, execute requested tools, feed results back, and stop on a final response or failure.
• src/kama_claude/core/app.py
• src/kama_claude/core/runner.py
• src/kama_claude/core/loop.py
• src/kama_claude/core/runs.py
LLM, tools, and safety gate
The LLM provider layer isolates model integrations behind common request/response types. Tool calls are resolved through a registry and invocation boundary; local filesystem/shell and task-management tools are built in. Permission management is a hard control boundary before sensitive execution, supporting policy, storage, approval, error classification, and retry-oriented handling.
• src/kama_claude/core/llm/provider.py
• src/kama_claude/core/tools/registry.py
• src/kama_claude/core/tools/invocation.py
• src/kama_claude/core/permissions/manager.py
Events, persistence, and observability
Execution is externalized through an event bus. Events serve both real-time subscribers—via IPC broadcasting—and persistent run records; trace providers/writers capture cross-layer timelines for IPC, event, and LLM diagnosis/replay. The TUI consumes this observable execution state rather than directly driving internals.
• src/kama_claude/core/events/bus.py
• src/kama_claude/core/events/writer.py
• src/kama_claude/core/transport/ipc_broadcaster.py
• src/kama_claude/core/trace/writer.py
Stateful context lifecycle
Sessions preserve multi-turn interaction using models, management, and storage. Context construction combines thread/history and notes/memory; budget and compactor stages govern long-running conversations by detecting pressure, trimming tool results, and compacting context rather than blindly growing prompts.
• src/kama_claude/core/session/manager.py
• src/kama_claude/core/context.py
• src/kama_claude/core/compact/compactor.py
• src/kama_claude/core/memory/loader.py
Extensibility and agent composition
Built-in agent profiles and Markdown skills provide role/workflow instructions. Subagents expose delegated work through the tool system, while MCP client/server/tool modules integrate externally supplied tools into the same invocation, permission, event, and context pipeline.
• src/kama_claude/core/agents/loader.py
• src/kama_claude/core/skills/loader.py
• src/kama_claude/core/subagent/tool.py
• src/kama_claude/core/mcp/client.py
Main entry points: loop.py Agent loop · registry.py Tool registry · bus.py Event bus · socket_server.py Socket server
Components 21
Clients
Independent IPC front ends.
Daemon boundary
Long-lived command and event service.
- JSON-RPC / NDJSON · Typed commands and events over socket transport.
WIRE_PROTOCOL.md - Socket server
src/kama_claude/core/transport/socket_server.py - Core application · Assembles services and dispatches commands.
src/kama_claude/core/app.py - IPC broadcaster
src/kama_claude/core/transport/ipc_broadcaster.py
Agent execution
Run orchestration and ReAct workflow.
- Runner · Creates or resumes runs and coordinates sessions.
src/kama_claude/core/runner.py - Agent loop · Builds context, calls the model, executes tools, and terminates runs.
src/kama_claude/core/loop.py
Capabilities
Models, tools, safety, and delegated integrations.
- LLM provider · Common model request and response boundary.
src/kama_claude/core/llm/provider.py - Tool registry · Includes local filesystem, shell, and task tools.
src/kama_claude/core/tools/registry.py - Tool invocation
src/kama_claude/core/tools/invocation.py - Permission manager · Policy, approval, classification, and retry control before sensitive execution.
src/kama_claude/core/permissions/manager.py - Agents and skills · Loads built-in profiles and Markdown workflow instructions.
src/kama_claude/core/agents/loader.py - Subagent tool · Exposes delegated work through the tool system.
src/kama_claude/core/subagent/tool.py - MCP integration · Adapts externally supplied tools into the common pipeline.
src/kama_claude/core/mcp/client.py
Durable state
Session context, events, and diagnostic records.
- Session manager · Preserves multi-turn interaction.
src/kama_claude/core/session/manager.py - Context lifecycle · Combines history and memory; manages budget pressure.
src/kama_claude/core/context.py - Context compactor · Trims tool results and compacts long conversations.
src/kama_claude/core/compact/compactor.py - Event bus · Externalizes live execution events.
src/kama_claude/core/events/bus.py - Run event writer
src/kama_claude/core/events/writer.py - Trace writer · Captures IPC, event, and LLM timelines for diagnosis and replay.
src/kama_claude/core/trace/writer.py
Connections 23
- CLI → JSON-RPC / NDJSON: commands
- TUI → JSON-RPC / NDJSON: commands and events
- JSON-RPC / NDJSON → Socket server: implemented by
- Socket server → Core application: dispatches commands
- Core application → Runner: starts or resumes run
- Runner → Session manager: coordinates session
- Runner → Agent loop: invokes
- Agent loop → Context lifecycle: constructs prompt context
- Context lifecycle → Context compactor: compacts under budget pressure
- Agent loop → LLM provider: model request
- Agent loop → Tool registry: resolves requested tool
- Tool registry → Tool invocation: selected tool
- Tool invocation → Permission manager: authorization before execution
- Tool registry → Subagent tool: delegated capability
- Tool registry → MCP integration: external capability
- Agents and skills → Context lifecycle: instructions
- Agent loop → Event bus: execution events
- Event bus → Run event writer: persists run events
- Event bus → IPC broadcaster: broadcasts live events
- IPC broadcaster → TUI: observable state
- Socket server → Trace writer: IPC traces
- Event bus → Trace writer: event traces
- LLM provider → Trace writer: LLM traces