diff --git a/README.md b/README.md index 31afe63..09044a9 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,133 @@ -# Claw Code Agent -
-
+
+ A Python reimplementation of the Claude Code agent architecture โ local models, full control. +
-## Status + -The Python runtime is working, but it is not full feature parity with the npm implementation yet. +--- -Implemented now: +## ๐ About -- Python CLI agent loop -- OpenAI-compatible local model backend -- Qwen3-Coder support through `vLLM` -- core tools: file read/write/edit, glob, grep, shell -- context building and `/context`-style usage reporting -- local slash commands such as `/help`, `/context`, `/tools`, `/memory`, `/status` -- unit tests for the Python runtime +This repository reimplements the [Claude Code](https://docs.anthropic.com/en/docs/claude-code) npm agent architecture **entirely in Python**, designed to run with **local open-source models** via an OpenAI-compatible API server. -Not complete yet: +Built on the public porting workspace from [instructkr/claw-code](https://github.com/instructkr/claw-code), the active development lives at [HarnessLab/claw-code-agent](https://github.com/HarnessLab/claw-code-agent). -- full plugin and MCP parity -- complete slash-command parity -- full interactive REPL/session persistence parity -- tokenizer-accurate context accounting +> **Goal:** Not to ship the original npm source, but to reimplement the full agent flow in Python โ prompt assembly, context building, slash commands, tool calling, session persistence, and local model execution. -## Repository Layout +--- + +## โจ Key Features + +| Feature | Description | +|---------|-------------| +| ๐ค **Agent Loop** | Full agentic coding loop with tool calling and iterative reasoning | +| ๐งฐ **Core Tools** | File read / write / edit, glob search, grep search, shell execution | +| ๐ฌ **Slash Commands** | Local commands: `/help`, `/context`, `/tools`, `/memory`, `/status`, `/model`, and more | +| ๐ง **Context Engine** | Automatic context building with CLAUDE.md discovery and usage reporting | +| ๐ **Session Persistence** | Save and resume agent sessions across runs | +| ๐ **Permission System** | Granular control: `--allow-write`, `--allow-shell`, `--unsafe` | +| ๐๏ธ **OpenAI-Compatible** | Works with any OpenAI-compatible model server (vLLM, Ollama, etc.) | +| ๐ **Qwen3-Coder** | First-class support for `Qwen3-Coder-30B-A3B-Instruct` via vLLM | + +--- + +## ๐ Roadmap + +### Done + +- [x] Python CLI agent loop +- [x] OpenAI-compatible local model backend +- [x] Qwen3-Coder support through vLLM with `qwen3_xml` tool parser +- [x] Core tools: `list_dir`, `read_file`, `write_file`, `edit_file`, `glob_search`, `grep_search`, `bash` +- [x] Context building and `/context`-style usage reporting +- [x] Slash commands: `/help`, `/context`, `/context-raw`, `/prompt`, `/permissions`, `/model`, `/tools`, `/memory`, `/status`, `/clear` +- [x] Session persistence and `agent-resume` flow +- [x] Permission system (read-only, write, shell, unsafe tiers) +- [x] Unit tests for the Python runtime +- [x] `pyproject.toml` packaging with `setuptools` + +### In Progress + +- [ ] Full plugin and MCP server parity +- [ ] Complete slash-command parity with npm runtime +- [ ] Full interactive REPL / session persistence parity +- [ ] Tokenizer-accurate context accounting +- [ ] Remote runtime modes (SSH, teleport, deep-link) +- [ ] Voice and VIM modes +- [ ] Hooks system +- [ ] Cost tracking and budget limits + +--- + +## ๐๏ธ Architecture ```text claw-code/ โโโ README.md +โโโ pyproject.toml โโโ .gitignore -โโโ src/ -โโโ tests/ +โโโ images/ +โ โโโ logo.png +โโโ src/ # Python implementation +โ โโโ main.py # CLI entry point & argument parsing +โ โโโ agent_runtime.py # Core agent loop (LocalCodingAgent) +โ โโโ agent_tools.py # Tool definitions & execution engine +โ โโโ agent_prompting.py # System prompt assembly +โ โโโ agent_context.py # Context building & CLAUDE.md discovery +โ โโโ agent_context_usage.py # Context usage estimation & reporting +โ โโโ agent_session.py # Session state management +โ โโโ agent_slash_commands.py # Local slash command processing +โ โโโ agent_types.py # Shared dataclasses & type definitions +โ โโโ openai_compat.py # OpenAI-compatible API client +โ โโโ session_store.py # Session serialization & persistence +โ โโโ permissions.py # Tool permission filtering +โ โโโ tools.py # Mirrored tool inventory +โ โโโ commands.py # Mirrored command inventory +โ โโโ ... # 75+ modules across 30+ packages +โ โโโ plugins/ # Plugin subsystem (WIP) +โ โโโ hooks/ # Hook system (WIP) +โ โโโ remote/ # Remote runtime modes (WIP) +โ โโโ voice/ # Voice mode (WIP) +โ โโโ vim/ # VIM mode (WIP) +โโโ tests/ # Unit tests + โโโ test_agent_runtime.py + โโโ test_agent_context.py + โโโ test_agent_context_usage.py + โโโ test_agent_prompting.py + โโโ test_agent_slash_commands.py + โโโ test_porting_workspace.py ``` -`src/` contains the Python implementation. +--- -`tests/` contains the unit tests for the Python runtime. +## ๐ฆ Requirements -## Requirements +| Requirement | Details | +|-------------|---------| +| ๐ Python | `3.10` or higher | +| ๐ฅ๏ธ Model Server | Any OpenAI-compatible server (vLLM recommended) | +| ๐ง Model | [`Qwen/Qwen3-Coder-30B-A3B-Instruct`](https://huggingface.co/Qwen/Qwen3-Coder-30B-A3B-Instruct) (recommended) | -- Python 3.10+ -- a local OpenAI-compatible model server -- recommended model: `Qwen/Qwen3-Coder-30B-A3B-Instruct` +--- -## Start `vLLM` With Qwen3-Coder +## ๐ Quick Start -For Qwen3-Coder tool calling, `vLLM` must be started with automatic tool choice enabled. The official `vLLM` tool-calling docs describe `--enable-auto-tool-choice` and `--tool-call-parser`, and Qwen3-Coder should use the `qwen3_xml` parser: +### 1. Start vLLM with Qwen3-Coder -- https://docs.vllm.ai/en/v0.13.0/features/tool_calling/ -- https://docs.vllm.ai/en/v0.13.0/serving/openai_compatible_server.html - -Example: +vLLM must be started with automatic tool choice enabled. Use the `qwen3_xml` parser for Qwen3-Coder tool calling: ```bash python -m vllm.entrypoints.openai.api_server \ @@ -67,15 +138,15 @@ python -m vllm.entrypoints.openai.api_server \ --tool-call-parser qwen3_xml ``` -Check that the server is up: +Verify the server is running: ```bash curl http://127.0.0.1:8000/v1/models ``` -## Environment Setup +> ๐ **References:** [vLLM Tool Calling Docs](https://docs.vllm.ai/en/v0.13.0/features/tool_calling/) ยท [OpenAI-Compatible Server](https://docs.vllm.ai/en/v0.13.0/serving/openai_compatible_server.html) -From the `claw-code/` directory: +### 2. Configure Environment ```bash export OPENAI_BASE_URL=http://127.0.0.1:8000/v1 @@ -83,143 +154,141 @@ export OPENAI_API_KEY=local-token export OPENAI_MODEL=Qwen/Qwen3-Coder-30B-A3B-Instruct ``` -## How To Run - -Show the agent system prompt: - -```bash -python3 -m src.main agent-prompt --cwd . -``` - -Show estimated context usage: - -```bash -python3 -m src.main agent-context --cwd . -``` - -Show the raw context snapshot: - -```bash -python3 -m src.main agent-context-raw --cwd . -``` - -Run a read-only repo question: +### 3. Run the Agent ```bash +# Read-only question python3 -m src.main agent \ "Read src/agent_runtime.py and summarize how the loop works." \ --cwd . -``` -Run a write-enabled task: - -```bash +# Write-enabled task python3 -m src.main agent \ "Create TEST_QWEN_AGENT.md with one line: test ok" \ - --cwd . \ - --allow-write -``` + --cwd . --allow-write -Run a shell-enabled task: - -```bash +# Shell-enabled task python3 -m src.main agent \ "Run pwd and ls src, then summarize the result." \ - --cwd . \ - --allow-shell + --cwd . --allow-shell ``` -Show the full transcript: +--- + +## ๐ ๏ธ Usage + +### Agent Commands + +| Command | Description | +|---------|-------------| +| `agent+ Built with ๐ Python ยท Powered by ๐ HarnessLab Team. +