wrencode 0.1.5__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,438 @@
1
+ Metadata-Version: 2.5
2
+ Name: wrencode
3
+ Version: 0.3.0
4
+ Summary: A minimal agent harness for coding, in a single Python file
5
+ Project-URL: Homepage, https://github.com/almostly/wrencode
6
+ Project-URL: Repository, https://github.com/almostly/wrencode
7
+ Project-URL: Issues, https://github.com/almostly/wrencode/issues
8
+ Author: Almostly
9
+ License-Expression: MIT
10
+ Keywords: agent,ai,anthropic,cli,coding-assistant,llm,mlx,ollama,openai
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Software Development :: Code Generators
16
+ Requires-Python: >=3.9
17
+ Provides-Extra: agent-sdk
18
+ Requires-Dist: claude-agent-sdk; (python_version >= '3.10') and extra == 'agent-sdk'
19
+ Provides-Extra: mlx
20
+ Requires-Dist: mlx-lm; extra == 'mlx'
21
+ Provides-Extra: transformers
22
+ Requires-Dist: torch; extra == 'transformers'
23
+ Requires-Dist: transformers; extra == 'transformers'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # 🐦 WrenCode
27
+
28
+ A minimal agent harness for coding, in a single Python file.
29
+
30
+ Named after Harold Wren - the alias of a genius who built a superintelligent AI and operated quietly in the background.
31
+
32
+ -----
33
+
34
+ ## What it is
35
+
36
+ WrenCode is a coding agent harness: everything around the model that turns it into an agent. It runs the tool-calling loop, executes tools, builds the system prompt, and manages context, locally or via API, giving an LLM the ability to read, write, and edit files, search codebases, and run shell commands - enough to autonomously navigate and modify a real project.
37
+
38
+ Where Claude Code is the batteries-included harness, WrenCode is the **"understand and own your agent" harness**: the entire agent loop fits in one readable file, runs against local or hosted models, and is yours to hack.
39
+
40
+ ## Backends
41
+
42
+ On first run WrenCode asks you to pick a backend and saves the choice to
43
+ `~/.wrencode/config.json`. Run `wrencode --configure` any time to change it.
44
+ Set `BACKEND` (and the matching API key) in the environment to override the
45
+ saved choice, e.g. for CI.
46
+
47
+ |Backend |Description |Availability |
48
+ |--------------|----------------------------------------|----------------------|
49
+ |`anthropic` |Claude via Anthropic API |binary + source |
50
+ |`claude-agent-sdk`|Claude Code's agent loop and tools via the Claude Agent SDK|source install, Python 3.10+|
51
+ |`openai` |GPT models via OpenAI API |binary + source |
52
+ |`openrouter` |Any model via OpenRouter |binary + source |
53
+ |`nanogpt` |Any model via NanoGPT |binary + source |
54
+ |`ollama` |Local models via a running `ollama serve`|binary + source |
55
+ |`openai-compatible`|vLLM, llama.cpp, Hugging Face, any OpenAI-compatible server|binary + source|
56
+ |`local` |Local proxy via Anthropic-compatible API|binary + source |
57
+ |`transformers`|HuggingFace Transformers (CPU/MPS/GPU) |source install only |
58
+ |`mlx` |Apple Silicon via MLX |source install, macOS |
59
+
60
+ The standalone binary can't bundle the heavy ML stack, so the local-weights
61
+ backends (`mlx`, `transformers`) are only offered when running from source.
62
+
63
+ The default local models are
64
+ [`deburky/gpt-oss-claude-code`](https://huggingface.co/deburky/gpt-oss-claude-code)
65
+ (transformers) and
66
+ [`deburky/gpt-oss-claude-mlx`](https://huggingface.co/deburky/gpt-oss-claude-mlx)
67
+ (MLX) — override either with `MODEL=...`.
68
+
69
+ ### Claude Agent SDK
70
+
71
+ The `claude-agent-sdk` backend hands each prompt to the
72
+ [Claude Agent SDK](https://code.claude.com/docs/en/agent-sdk/overview), which
73
+ runs Claude Code's own agent loop, tools and subagents. WrenCode shows the
74
+ stream, asks before edits and commands, and prints the cost of each turn.
75
+ Install the extra, then pick the backend in `/configure`:
76
+
77
+ ```bash
78
+ pip install 'wrencode[agent-sdk]' # or: pip install claude-agent-sdk
79
+ ```
80
+
81
+ It always authenticates with `ANTHROPIC_API_KEY`, so usage bills to your
82
+ Console credits, including the monthly API credits that come with Max and Team
83
+ plans. Subscription logins are never used. Multi-workspace keys need
84
+ `ANTHROPIC_WORKSPACE_ID`. The conversation resumes per project across restarts;
85
+ `/clear` starts a new one. Your `~/.claude` hooks, plugins and MCP servers are
86
+ not loaded; project instructions come from `AGENTS.md` / `CLAUDE.md`.
87
+
88
+ To run several prompts in parallel, each as its own agent with a fresh
89
+ context, see `examples/agent_sdk_swarm.py`. It prints every answer and the
90
+ total cost.
91
+
92
+ ### OpenAI-compatible servers
93
+
94
+ `openai-compatible` talks to any server that implements OpenAI chat completions,
95
+ using native tool calls. Point it at the server with `OPENAI_COMPATIBLE_BASE_URL`
96
+ (default `http://localhost:8000/v1`). If the server serves exactly one model,
97
+ WrenCode uses it; otherwise set `MODEL`.
98
+
99
+ ```bash
100
+ # vLLM (tool calling needs these flags; pick the parser for your model)
101
+ vllm serve Qwen/Qwen2.5-Coder-7B-Instruct --enable-auto-tool-choice --tool-call-parser hermes
102
+ BACKEND=openai-compatible wrencode
103
+
104
+ # llama.cpp (--jinja enables tool calling)
105
+ llama-server -m qwen2.5-coder-7b-instruct-q4_k_m.gguf --jinja --port 8080
106
+ BACKEND=openai-compatible OPENAI_COMPATIBLE_BASE_URL=http://localhost:8080/v1 wrencode
107
+
108
+ # Hugging Face Inference Providers
109
+ BACKEND=openai-compatible OPENAI_COMPATIBLE_BASE_URL=https://router.huggingface.co/v1 \
110
+ OPENAI_COMPATIBLE_API_KEY=$HF_TOKEN MODEL=Qwen/Qwen2.5-Coder-32B-Instruct wrencode
111
+ ```
112
+
113
+ ## Tools
114
+
115
+ The agent has access to seven tools:
116
+
117
+ - **read** - read a file with line numbers, or list a directory
118
+ - **write** - write content to a file
119
+ - **edit** - replace a unique string in a file. If the text only matches with
120
+ its indentation shifted by a consistent amount (a common slip when quoting a
121
+ method), the edit is applied with the replacement shifted to match; otherwise
122
+ the error shows the closest lines in the file
123
+ - **glob** - find files by pattern, sorted by modification time
124
+ - **grep** - search files for a regex pattern using `rg` when available, falling back to `grep`
125
+ - **bash** - run a shell command with timeout and streaming output
126
+ - **task** - delegate a self-contained subtask to a fresh subagent (its own context, same tools) that returns only its final result
127
+
128
+ All file operations are sandboxed to the workspace root by default.
129
+
130
+ ### Subagents
131
+
132
+ The `task` tool runs a nested agent loop on a fresh message history, so the
133
+ parent's context only grows by the returned summary — useful for context-heavy
134
+ subtasks.
135
+
136
+ Task calls made in the same reply run in parallel, up to
137
+ `WRENCODE_MAX_PARALLEL_SUBAGENTS` at a time (default 4), on every backend
138
+ except the in-process `mlx` and `transformers` ones. Ask for it in the prompt,
139
+ for example "analyze each file in docs/ with its own subagent, in parallel".
140
+ Each subagent's output is tagged `[1]`, `[2]`, and so on; approval prompts
141
+ take turns and pause the other agents' output until you answer. Escape stops
142
+ the whole batch. Recursion is capped by `WRENCODE_MAX_SUBAGENT_DEPTH` (default 2), and
143
+ each subagent round is bounded. For autonomous subagent runs, enable
144
+ `--yes` / `WRENCODE_AUTO_APPROVE` so sub-tool calls don't block on confirmation.
145
+
146
+ ## Project instructions (AGENTS.md)
147
+
148
+ WrenCode reads [`AGENTS.md`](https://agents.md) files and adds them to the
149
+ system prompt, so conventions you've written for other agents apply here too.
150
+ It looks in `~/.wrencode/`, then in every directory from the git root down to
151
+ the workspace (outside a git repo, only the workspace). A directory without an
152
+ `AGENTS.md` falls back to `CLAUDE.md`. Files closer to the workspace come later
153
+ and take precedence. The total is capped at 32,000 characters, and the files
154
+ loaded are listed at startup.
155
+
156
+ ## Headless mode
157
+
158
+ `-p` / `--print` runs a single prompt without the interactive UI, for scripts,
159
+ CI, and evals:
160
+
161
+ ```bash
162
+ wrencode -p "Why is test_parse failing?"
163
+ git diff | wrencode -p "Review this diff" # prompt from stdin
164
+ wrencode --yes -p "Fix the lint errors" --max-turns 20
165
+ wrencode -p "List the TODOs" --output-format json | jq -r .result
166
+ wrencode --yes -p "Make the tests pass" --verify "python3 -m unittest -q"
167
+ ```
168
+
169
+ - stdout carries only the final answer (or one JSON object with
170
+ `--output-format json`: `result`, `is_error`, `stop_reason`, `num_turns`,
171
+ `backend`, `model`); progress and tool output go to stderr.
172
+ - Each run starts from a fresh history and doesn't touch the saved one.
173
+ - Without `--yes`, writes and shell commands are declined (the model is told
174
+ why) instead of waiting for approval. Read-only tools always work.
175
+ - The exit code is `0` when the agent finishes, `1` if it errors, hits
176
+ `--max-turns`, or stops on repeated tool errors, and `2` for bad arguments.
177
+ - `--verify CMD` checks the agent's claim of being done: WrenCode runs `CMD`
178
+ in the workspace when the agent finishes, and if it fails, sends the output
179
+ back and lets the agent continue (up to 3 attempts in all). The result says
180
+ `verified: true/false`, and a final failure exits `1` with
181
+ `stop_reason: "verify_failed"`. `--max-turns` applies to each attempt.
182
+
183
+ ### Structured output
184
+
185
+ `--json-schema` makes the answer a JSON value that matches a schema, given as
186
+ a file or inline:
187
+
188
+ ```bash
189
+ wrencode -p "Review this repo for bugs" --json-schema bugs.schema.json
190
+ wrencode -p "Is the build green?" --json-schema '{"type": "object", "properties": {"green": {"type": "boolean"}}, "required": ["green"]}'
191
+ ```
192
+
193
+ The agent gets a `respond` tool whose arguments are your schema, and the run
194
+ ends when it calls `respond` with a valid answer. If the answer doesn't match,
195
+ the validation errors go back to the model so it can fix them; if it never
196
+ calls `respond`, the run fails with `stop_reason: "no_structured_output"`.
197
+ stdout is the JSON value (or, with `--output-format json`, the usual object
198
+ with a `structured_output` field). Validation is built in and covers the
199
+ common keywords: `type`, `enum`, `const`, `properties`, `required`,
200
+ `additionalProperties`, `items`, length and numeric bounds, `pattern`, and
201
+ `anyOf`/`oneOf`/`allOf`.
202
+
203
+ ## Context management
204
+
205
+ Long sessions are compacted automatically. Before each model call WrenCode
206
+ estimates the prompt size (about 4 characters per token), and once it passes
207
+ `WRENCODE_COMPACT_AT` (default 75%) of `WRENCODE_CONTEXT_TOKENS` (default
208
+ 128,000) it has the model summarize the older messages: the request, files
209
+ touched, commands and results, decisions, and what's left to do. The most recent
210
+ messages, about a quarter of the window, are kept verbatim, along with the
211
+ user's latest request, so it works mid-task, between tool calls. If a request still
212
+ fails with a context-length error, WrenCode compacts and retries once.
213
+
214
+ Set `WRENCODE_CONTEXT_TOKENS` to your model's window, especially for local
215
+ models with small ones. `/compact` summarizes on demand.
216
+
217
+ ## Installation
218
+
219
+ ### Option 1: Standalone binary (recommended)
220
+
221
+ Run the guided installer:
222
+
223
+ ```bash
224
+ curl -fsSL https://raw.githubusercontent.com/almostly/wrencode/main/install.sh | sh
225
+ ```
226
+
227
+ It detects your OS/arch, downloads the matching binary from the latest GitHub
228
+ Release, and installs it to `~/.local/bin` (no sudo). Override the location with
229
+ `WRENCODE_INSTALL_DIR`, or pin a release with `WRENCODE_VERSION`:
230
+
231
+ ```bash
232
+ curl -fsSL https://raw.githubusercontent.com/almostly/wrencode/main/install.sh \
233
+ | WRENCODE_INSTALL_DIR=/usr/local/bin WRENCODE_VERSION=0.1.3 sh
234
+ ```
235
+
236
+ Or download and run it locally:
237
+
238
+ ```bash
239
+ curl -fsSL https://raw.githubusercontent.com/almostly/wrencode/main/install.sh -o install.sh
240
+ chmod +x install.sh
241
+ ./install.sh
242
+ ```
243
+
244
+ Manual install (fallback): download the right binary from GitHub Releases, make it executable, and move it into your `PATH`.
245
+
246
+ macOS Apple Silicon:
247
+
248
+ ```bash
249
+ curl -L https://github.com/almostly/wrencode/releases/latest/download/wrencode-macos-arm64 -o wrencode
250
+ chmod +x wrencode
251
+ sudo mv wrencode /usr/local/bin/wrencode
252
+ ```
253
+
254
+ macOS Intel:
255
+
256
+ ```bash
257
+ curl -L https://github.com/almostly/wrencode/releases/latest/download/wrencode-macos-x64 -o wrencode
258
+ chmod +x wrencode
259
+ sudo mv wrencode /usr/local/bin/wrencode
260
+ ```
261
+
262
+ Linux x64:
263
+
264
+ ```bash
265
+ curl -L https://github.com/almostly/wrencode/releases/latest/download/wrencode-linux-x64 -o wrencode
266
+ chmod +x wrencode
267
+ sudo mv wrencode /usr/local/bin/wrencode
268
+ ```
269
+
270
+ ### Option 2: Run from source
271
+
272
+ Single file, standard library only (except the backend you choose).
273
+
274
+ ```bash
275
+ git clone https://github.com/almostly/wrencode
276
+ cd wrencode
277
+ ```
278
+
279
+ For MLX (Mac Silicon):
280
+
281
+ ```bash
282
+ pip install mlx-lm
283
+ ```
284
+
285
+ For Anthropic:
286
+
287
+ ```bash
288
+ pip install anthropic # not required - uses urllib directly
289
+ export ANTHROPIC_API_KEY=your_key
290
+ ```
291
+
292
+ For OpenAI:
293
+
294
+ ```bash
295
+ export OPENAI_API_KEY=your_key
296
+ ```
297
+
298
+ For OpenRouter:
299
+
300
+ ```bash
301
+ export OPENROUTER_API_KEY=your_key
302
+ ```
303
+
304
+ For NanoGPT:
305
+
306
+ ```bash
307
+ export NANOGPT_API_KEY=your_key
308
+ ```
309
+
310
+ For HuggingFace Transformers:
311
+
312
+ ```bash
313
+ pip install transformers torch
314
+ ```
315
+
316
+ ## Usage
317
+
318
+ ```bash
319
+ # Standalone binary — prompts for a backend on first run
320
+ wrencode
321
+
322
+ # Re-pick the backend at any time
323
+ wrencode --configure
324
+
325
+ # Or from source — also prompts on first run
326
+ python3 wrencode.py
327
+
328
+ # Anthropic Claude (model list is fetched live from the API during /configure)
329
+ BACKEND=anthropic python3 wrencode.py
330
+ # Multi-workspace Anthropic keys also need a workspace id:
331
+ # ANTHROPIC_WORKSPACE_ID=wrkspc_... BACKEND=anthropic python3 wrencode.py
332
+
333
+ # OpenAI (model list fetched live from the API during /configure)
334
+ BACKEND=openai MODEL=gpt-4o python3 wrencode.py
335
+
336
+ # OpenRouter
337
+ BACKEND=openrouter MODEL=anthropic/claude-3-haiku python3 wrencode.py
338
+
339
+ # NanoGPT
340
+ BACKEND=nanogpt MODEL=z-ai/glm-5.3-flash-uncensored python3 wrencode.py
341
+
342
+ # Ollama (needs `ollama serve` running and the model pulled)
343
+ BACKEND=ollama MODEL=llama3.2 python3 wrencode.py
344
+
345
+ # HuggingFace model
346
+ BACKEND=transformers MODEL=deburky/gpt-oss-claude-code python3 wrencode.py
347
+
348
+ # Local proxy
349
+ BACKEND=local LOCAL_PORT=8082 python3 wrencode.py
350
+ ```
351
+
352
+ ## Releasing
353
+
354
+ Versions and [`CHANGELOG.md`](CHANGELOG.md) are managed with
355
+ [commitizen](https://commitizen-tools.github.io/commitizen/), so write commit
356
+ messages as [conventional commits](https://www.conventionalcommits.org/)
357
+ (`feat: ...`, `fix(edit): ...`, `refactor: ...`). To cut a release:
358
+
359
+ ```bash
360
+ uvx --from commitizen cz bump # bumps WRENCODE_VERSION, updates CHANGELOG.md, tags
361
+ git push origin main --tags
362
+ ```
363
+
364
+ Preview the next changelog entry with `uvx --from commitizen cz changelog --dry-run`.
365
+
366
+ Binaries are built automatically by GitHub Actions when a version tag is pushed.
367
+
368
+ This publishes release assets:
369
+ - `wrencode-linux-x64`
370
+ - `wrencode-macos-x64`
371
+ - `wrencode-macos-arm64`
372
+
373
+ ## Slash Commands
374
+
375
+ |Command |Description |
376
+ |--------------|----------------------------------------------|
377
+ |`/help` |Show available commands |
378
+ |`/model` |Switch model, or `/model <id>` to set it directly|
379
+ |`/backend`, `/configure`|Switch backend, model and API key |
380
+ |`/clear` or `/c`|Clear conversation history |
381
+ |`/compact` |Summarize history to reduce context |
382
+ |`/quit`, `/q` or `/exit`|Quit |
383
+
384
+ Type `/` to see matching commands: ↑↓ pick, Tab completes, Enter runs.
385
+
386
+ ## Environment Variables
387
+
388
+ |Variable |Default |Description |
389
+ |-----------------------------|-----------------------|----------------------------------|
390
+ |`BACKEND` |chooser/saved config |Override the saved inference backend|
391
+ |`MODEL` |backend-dependent |Model path or ID |
392
+ |`WRENCODE_CONFIG_DIR` |`~/.wrencode` |Dir for `config.json` (saved backend/key)|
393
+ |`WRENCODE_WORKSPACE` |cwd |Root directory for file operations|
394
+ |`WRENCODE_HISTORY_FILE` |`~/.wrencode/history.json`|Conversation history file path |
395
+ |`WRENCODE_UNRESTRICTED_PATHS`|`0` |Allow paths outside workspace |
396
+ |`WRENCODE_AUTO_APPROVE` |`0` |Skip y/N confirmation for writes/commands (headless; also `--yes`)|
397
+ |`WRENCODE_MAX_SUBAGENT_DEPTH`|`2` |Max nested subagent recursion depth (`task` tool)|
398
+ |`WRENCODE_MAX_PARALLEL_SUBAGENTS`|`4` |Subagents run at once from one reply; `1` runs them in order|
399
+ |`MAX_TOKENS` |`8192`, `16000` for Claude|Max tokens per response |
400
+ |`WRENCODE_EFFORT` |- |Claude reasoning effort: `low`, `medium`, `high`, `xhigh`, `max`|
401
+ |`WRENCODE_HTTP_TIMEOUT` |`600` |Seconds to wait for a model response|
402
+ |`WRENCODE_HTTP_RETRIES` |`2` |Retries on HTTP 429/5xx and network errors, with backoff|
403
+ |`WRENCODE_CONTEXT_TOKENS` |`128000` |Model context window, for auto-compaction|
404
+ |`WRENCODE_COMPACT_AT` |`0.75` |Compact at this fraction of the window (`0` disables)|
405
+ |`MAX_READ_BYTES` |`4MB` |Max file size to read |
406
+ |`MAX_READ_LINES` |`800` |Max lines returned per read |
407
+ |`GREP_MAX_MATCHES` |`80` |Max grep results |
408
+ |`BASH_TIMEOUT` |`120` |Shell command timeout in seconds |
409
+ |`MAX_TOOL_OUTPUT_CHARS` |`48000` |Max tool output before truncation |
410
+ |`GLOB_SKIP_DIRS` |`.git,node_modules,...`|Directories to skip in glob |
411
+ |`OPENROUTER_API_KEY` |- |OpenRouter API key |
412
+ |`NANOGPT_API_KEY` |- |NanoGPT API key |
413
+ |`OPENAI_API_KEY` |- |OpenAI API key |
414
+ |`ANTHROPIC_API_KEY` |- |Anthropic API key |
415
+ |`ANTHROPIC_WORKSPACE_ID` |- |Anthropic workspace id (`wrkspc_…`); required for multi-workspace keys|
416
+ |`LOCAL_API_KEY` |`local` |Local proxy API key |
417
+ |`LOCAL_PORT` |`8082` |Local proxy port |
418
+ |`OLLAMA_HOST` |`http://localhost:11434`|Ollama server base URL |
419
+ |`OPENAI_COMPATIBLE_BASE_URL` |`http://localhost:8000/v1`|OpenAI-compatible server base URL|
420
+ |`OPENAI_COMPATIBLE_API_KEY` |- |Key for that server, if it needs one|
421
+
422
+ ## History
423
+
424
+ Conversation history is persisted to `~/.wrencode/history.json` by default. It is restored automatically on next launch.
425
+
426
+ To override the history file location, set `WRENCODE_HISTORY_FILE` to a custom path.
427
+
428
+ To clear history: use `/c` in the session, or delete `~/.wrencode/history.json` (or your override path).
429
+
430
+ ## License
431
+
432
+ MIT - Copyright 2026 Almostly.
433
+
434
+ -----
435
+
436
+ <p align="center">
437
+ <img src="assets/almostly-badge.svg" alt="Almostly" />
438
+ </p>