lcode-cli 0.49.1__py3-none-any.whl → 0.51.0__py3-none-any.whl
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.
- lcode/__init__.py +1 -1
- lcode/acp.py +1 -1
- lcode/agent.py +4 -0
- lcode/assistant.py +6 -2
- lcode/docs/agents.md +147 -0
- lcode/docs/automation.md +198 -0
- lcode/docs/bench.md +244 -0
- lcode/docs/commands.md +132 -0
- lcode/docs/configuration.md +130 -0
- lcode/docs/editors.md +85 -0
- lcode/docs/git.md +98 -0
- lcode/docs/hooks.md +134 -0
- lcode/docs/how-it-works.md +206 -0
- lcode/docs/index.md +118 -0
- lcode/docs/installation.md +196 -0
- lcode/docs/lsp.md +75 -0
- lcode/docs/mcp.md +275 -0
- lcode/docs/memory.md +128 -0
- lcode/docs/models.md +344 -0
- lcode/docs/modes.md +511 -0
- lcode/docs/quickstart.md +94 -0
- lcode/docs/sandbox.md +79 -0
- lcode/docs/search.md +85 -0
- lcode/docs/servers.md +136 -0
- lcode/docs/troubleshooting.md +121 -0
- lcode/docs/usage.md +760 -0
- lcode/imageopts.py +2 -1
- lcode/manual.py +604 -0
- lcode/media.py +194 -11
- lcode/media_cloud.py +3 -0
- lcode/planning.py +1 -0
- lcode/repeats.py +1 -0
- lcode/repl.py +68 -4
- lcode/tools.py +15 -0
- lcode/update.py +43 -17
- {lcode_cli-0.49.1.dist-info → lcode_cli-0.51.0.dist-info}/METADATA +5 -1
- {lcode_cli-0.49.1.dist-info → lcode_cli-0.51.0.dist-info}/RECORD +40 -17
- {lcode_cli-0.49.1.dist-info → lcode_cli-0.51.0.dist-info}/WHEEL +0 -0
- {lcode_cli-0.49.1.dist-info → lcode_cli-0.51.0.dist-info}/entry_points.txt +0 -0
- {lcode_cli-0.49.1.dist-info → lcode_cli-0.51.0.dist-info}/licenses/LICENSE +0 -0
lcode/__init__.py
CHANGED
lcode/acp.py
CHANGED
|
@@ -44,7 +44,7 @@ MODES = [
|
|
|
44
44
|
]
|
|
45
45
|
KINDS = {
|
|
46
46
|
"read_file": "read", "view_image": "read", "list_dir": "search", "glob": "search", "grep": "search",
|
|
47
|
-
"repo_map": "search", "search_code": "search", "lsp": "search", "edit_file": "edit", "write_file": "edit", "apply_patch": "edit",
|
|
47
|
+
"repo_map": "search", "search_code": "search", "lcode_help": "search", "lsp": "search", "edit_file": "edit", "write_file": "edit", "apply_patch": "edit",
|
|
48
48
|
"bash": "execute", "web_search": "fetch", "web_fetch": "fetch", "agent": "think", "todo_write": "think",
|
|
49
49
|
"present_plan": "switch_mode", "bash_output": "read", "bash_stop": "execute",
|
|
50
50
|
} # fmt: skip
|
lcode/agent.py
CHANGED
|
@@ -32,6 +32,7 @@ from lcode import (
|
|
|
32
32
|
escalate,
|
|
33
33
|
extensions,
|
|
34
34
|
limits,
|
|
35
|
+
manual,
|
|
35
36
|
notify,
|
|
36
37
|
planning,
|
|
37
38
|
repomap,
|
|
@@ -56,6 +57,7 @@ from lcode.repeats import Circles, Repeats
|
|
|
56
57
|
from lcode.sandbox import Sandbox, SandboxError, project_root
|
|
57
58
|
from lcode.steer import NOTE_INTRO, Steering
|
|
58
59
|
from lcode.tools import (
|
|
60
|
+
LCODE_HELP_SCHEMA,
|
|
59
61
|
LSP_SCHEMA,
|
|
60
62
|
MEMORY_SCHEMA,
|
|
61
63
|
PRESENT_PLAN_SCHEMA,
|
|
@@ -547,6 +549,8 @@ class Agent:
|
|
|
547
549
|
|
|
548
550
|
def tool_schemas(self) -> list[dict]:
|
|
549
551
|
schemas = list(SCHEMAS)
|
|
552
|
+
if manual.folder() is not None:
|
|
553
|
+
schemas.append(LCODE_HELP_SCHEMA)
|
|
550
554
|
if self.settings.web != "off":
|
|
551
555
|
schemas += [*([WEB_SEARCH_SCHEMA] if self.search_backend() else []), WEB_FETCH_SCHEMA]
|
|
552
556
|
if self.vision_model():
|
lcode/assistant.py
CHANGED
|
@@ -97,12 +97,16 @@ class Assistant:
|
|
|
97
97
|
message: dict = {"role": "user", "content": user}
|
|
98
98
|
if images:
|
|
99
99
|
message["images"] = [base64.b64encode(p.read_bytes()).decode() for p in images]
|
|
100
|
+
return self.converse([{"role": "system", "content": system}, message], json_answer=json_answer)
|
|
101
|
+
|
|
102
|
+
def converse(self, messages: list[dict], json_answer: bool = False, num_ctx: int = 4096) -> str:
|
|
103
|
+
"""The model's answer to a conversation (lcode.manual's answers use a longer one)."""
|
|
100
104
|
payload = {
|
|
101
105
|
"model": self.model,
|
|
102
|
-
"messages":
|
|
106
|
+
"messages": messages,
|
|
103
107
|
"think": False,
|
|
104
108
|
"keep_alive": 0, # unloaded right after: the image or video model needs the GPU
|
|
105
|
-
"options": {"temperature": 0.4, "num_ctx":
|
|
109
|
+
"options": {"temperature": 0.4, "num_ctx": num_ctx},
|
|
106
110
|
}
|
|
107
111
|
if json_answer:
|
|
108
112
|
payload["format"] = "json"
|
lcode/docs/agents.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Subagents
|
|
2
|
+
|
|
3
|
+
A single conversation used to do everything. Exploring a large codebase, reading logs or comparing
|
|
4
|
+
approaches fills the context window with material that's only needed for a moment, and that hurts
|
|
5
|
+
most at 32K to 128K.
|
|
6
|
+
|
|
7
|
+
Now the model can hand a task to a **subagent**: a fresh agent with its own empty context that
|
|
8
|
+
works on the task alone and returns only its report. The main conversation keeps the answer, not
|
|
9
|
+
the 40 files the subagent read to find it.
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
❯ how do the payment webhooks get verified, and where would I add retries?
|
|
13
|
+
✓ ↳ explore: find webhook verification · 9 tools · 41s
|
|
14
|
+
✓ ↳ plan: retries for webhook handlers · 6 tools · 38s
|
|
15
|
+
Webhooks are verified in `payments/webhooks.py:88` …
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Agent types
|
|
19
|
+
|
|
20
|
+
| Type | Does | Tools |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `explore` | Finds code and answers questions about the codebase | Read-only: reading and searching files, read-only shell commands, the web |
|
|
23
|
+
| `plan` | Works out a step-by-step plan for a change, without making it | Read-only, like explore |
|
|
24
|
+
| `worker` | Makes a self-contained change and verifies it | All of lcode's tools |
|
|
25
|
+
|
|
26
|
+
The model picks the type and writes the task. A subagent can't see the conversation, so the model
|
|
27
|
+
is told to describe the task completely. Subagents can't start subagents of their own, and they
|
|
28
|
+
don't save [memory](memory.md) notes; they do see the notes and `AGENTS.md`.
|
|
29
|
+
|
|
30
|
+
To ask for a specific agent yourself, mention it: `@plan add a dark mode toggle` (or
|
|
31
|
+
`@agent-plan …`).
|
|
32
|
+
|
|
33
|
+
## What you see
|
|
34
|
+
|
|
35
|
+
Each subagent gets one progress line with its current action, its tool count and its time. When it
|
|
36
|
+
finishes, the line stays as a summary. `/agents` lists the agent types and the subagents of this
|
|
37
|
+
session; `/agents 2` shows what the second one did, call by call.
|
|
38
|
+
|
|
39
|
+
Ctrl+C stops the subagents and the request.
|
|
40
|
+
|
|
41
|
+
## Safety
|
|
42
|
+
|
|
43
|
+
Subagents work under the session's rules:
|
|
44
|
+
|
|
45
|
+
- **Permissions.** They use the session's permission mode. Every prompt names the agent
|
|
46
|
+
(`worker agent › Run command`) and is asked in the main terminal, one at a time, even when
|
|
47
|
+
several agents run at once.
|
|
48
|
+
- **Read-only agents** (`explore`, `plan`) can't edit files, and lcode refuses any shell command that
|
|
49
|
+
isn't on the read-only list.
|
|
50
|
+
- **Undo.** A worker's changes are part of your request's checkpoint, so `/undo` takes them back.
|
|
51
|
+
- **Sandbox.** With the [sandbox](sandbox.md) on, their commands run in it too.
|
|
52
|
+
|
|
53
|
+
## Several at once
|
|
54
|
+
|
|
55
|
+
When the model calls several agents in one response, lcode can run them at the same time. Whether
|
|
56
|
+
that helps depends on Ollama:
|
|
57
|
+
|
|
58
|
+
- By default **Ollama runs one request at a time**. Two agents would take turns, and each turn would
|
|
59
|
+
push the other's conversation out of Ollama's prompt cache, which makes both slower. So lcode
|
|
60
|
+
runs subagents one after another by default (`max_parallel_agents = 1`).
|
|
61
|
+
- Ollama runs several requests at once when its server is started with `OLLAMA_NUM_PARALLEL`. Each
|
|
62
|
+
parallel request gets **its own context cache**, so memory use grows with every slot.
|
|
63
|
+
|
|
64
|
+
To run two at once:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
OLLAMA_NUM_PARALLEL=2 ollama serve
|
|
68
|
+
lcode config set max_parallel_agents 2
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`lcode doctor` estimates how many fit with your model and context window:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
✓ Agents subagents one at a time
|
|
75
|
+
! 2 could run at once here (2 × 256K context fits): set OLLAMA_NUM_PARALLEL=2 on the
|
|
76
|
+
Ollama server and max_parallel_agents 2
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### On a 12 GB GPU
|
|
80
|
+
|
|
81
|
+
Subagents use **the session's model and context window**. A different window, or a different
|
|
82
|
+
model, would make Ollama reload the model, and on one GPU that costs more than the subagent saves.
|
|
83
|
+
Some guidance:
|
|
84
|
+
|
|
85
|
+
- With one slot (the default), a subagent's requests push the main conversation out of Ollama's
|
|
86
|
+
cache, so the main model reads its whole context again afterwards. qwen3.6-35b reads about 850
|
|
87
|
+
tokens a second on a 12 GB laptop GPU: ~35 s for a 30K-token conversation. Delegating pays off when the subagent
|
|
88
|
+
would otherwise add much more than that to the main context.
|
|
89
|
+
- Two slots keep the main conversation cached while a subagent works. qwen3.6-35b's context cache
|
|
90
|
+
is small, so two slots of 128K fit in 12 GB of VRAM plus system RAM, but the extra cache sits in
|
|
91
|
+
system RAM and slows the model down.
|
|
92
|
+
- Smaller context windows leave room for more slots: `/context 64k` with
|
|
93
|
+
`OLLAMA_NUM_PARALLEL=3`.
|
|
94
|
+
|
|
95
|
+
## Workers that run together
|
|
96
|
+
|
|
97
|
+
A worker edits your working tree directly. When **two or more workers** (or other agents that can
|
|
98
|
+
change files) run at the same time, each gets its own **git worktree** instead, created from your
|
|
99
|
+
working tree as it is now, uncommitted and untracked files included. When a worker finishes,
|
|
100
|
+
lcode shows its changes as a diff and asks before applying them to your working tree. The diff is
|
|
101
|
+
applied automatically in `auto-edit` and `yolo` mode. If the diff doesn't apply cleanly, lcode
|
|
102
|
+
saves it as a patch file and tells the model where.
|
|
103
|
+
|
|
104
|
+
Worktrees live in `.git/lcode-worktrees/` and are removed when the worker is done. Outside a git
|
|
105
|
+
repository, or before the first commit, workers run one after another in the working tree.
|
|
106
|
+
|
|
107
|
+
## Custom agents
|
|
108
|
+
|
|
109
|
+
Define your own agent types as markdown files: the frontmatter describes the agent, and the body is
|
|
110
|
+
its instructions.
|
|
111
|
+
|
|
112
|
+
```markdown
|
|
113
|
+
---
|
|
114
|
+
description: reviews a change for bugs and missing tests (read-only)
|
|
115
|
+
tools: read-only
|
|
116
|
+
max_steps: 30
|
|
117
|
+
---
|
|
118
|
+
Review the change described in the task. Read the changed code and its callers.
|
|
119
|
+
Report bugs first, with `path:line`, then missing tests, then style. Don't fix anything.
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
| Key | Meaning |
|
|
123
|
+
|---|---|
|
|
124
|
+
| `description` | What it does; the main model reads this to decide when to use it (required) |
|
|
125
|
+
| `tools` | `all` (default), `read-only`, or a list such as `read_file, grep, bash` |
|
|
126
|
+
| `read_only` | `true` to allow only read-only shell commands (set by `tools: read-only`) |
|
|
127
|
+
| `max_steps` | Tool-calling steps before it must report (default 60, at most 200) |
|
|
128
|
+
| `model` | Another Ollama model for this agent. Only worth it if both fit in memory at once |
|
|
129
|
+
| `isolation` | `auto` (default: a worktree only when running with other editing agents), `worktree` (always) or `none` |
|
|
130
|
+
|
|
131
|
+
| Folder | Agents |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `.lcode/agents/<name>.md` in the repository | For this repository; commit them to share them |
|
|
134
|
+
| `~/.config/lcode/agents/<name>.md` | For every repository |
|
|
135
|
+
|
|
136
|
+
The file name is the agent's name. A repository's agent overrides one of yours with the same name,
|
|
137
|
+
and both override the built-in types. A repository's agents are used only after you
|
|
138
|
+
[approve them](commands.md#approving-a-repositorys-commands-skills-and-agents), together with its
|
|
139
|
+
commands and skills. `/agents` and `lcode doctor` point out files that couldn't be
|
|
140
|
+
read.
|
|
141
|
+
|
|
142
|
+
## Settings
|
|
143
|
+
|
|
144
|
+
| Setting | Default | |
|
|
145
|
+
|---|---|---|
|
|
146
|
+
| `subagents` | `true` | Let the model use the `agent` tool |
|
|
147
|
+
| `max_parallel_agents` | `1` | How many subagents run at the same time (see [Several at once](#several-at-once)) |
|
lcode/docs/automation.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Automation
|
|
2
|
+
|
|
3
|
+
lcode can also run without a person at the keyboard:
|
|
4
|
+
- **Scripts and CI** get structured results from `lcode -p`.
|
|
5
|
+
- **Programs** use it from Python.
|
|
6
|
+
- **A GitHub Action** answers `@lcode` in issues and pull requests on your own GPU machine.
|
|
7
|
+
|
|
8
|
+
In all three, nothing waits for an answer: anything that would need your permission is refused,
|
|
9
|
+
unless the permission mode, a [permission rule](hooks.md#permission-rules) or your program allows it.
|
|
10
|
+
|
|
11
|
+
## Structured output
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
lcode -p "Fix the failing test in tests/test_parser.py" --auto-edit --output json
|
|
15
|
+
lcode -p "Explain the retry logic" --output stream-json --max-steps 20
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
| Option | |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `--output json` | One JSON object when the request is done |
|
|
21
|
+
| `--output stream-json` | One JSON event per line as the request runs, ending with the same result object |
|
|
22
|
+
| `--max-steps N` | Stop after N model steps (status `max_steps`) |
|
|
23
|
+
| `--allowed-tools LIST` | Only these tools, e.g. `"read_file,grep,glob,bash"` |
|
|
24
|
+
|
|
25
|
+
lcode's usual output goes to stderr, so stdout holds only the JSON. The exit code says how it
|
|
26
|
+
went: `0` success, `1` an error, `3` stopped at `--max-steps`, `4` stopped because the model
|
|
27
|
+
[kept repeating itself](how-it-works.md#when-the-model-repeats-itself), `130` interrupted.
|
|
28
|
+
|
|
29
|
+
### The result
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"type": "result",
|
|
34
|
+
"schema": 1,
|
|
35
|
+
"lcode": "0.18.0",
|
|
36
|
+
"status": "success",
|
|
37
|
+
"text": "Two bugs fixed in `calc.py`: …",
|
|
38
|
+
"session_id": "20261006-101503-7f3a",
|
|
39
|
+
"model": "lcode-qwen3.6-35b",
|
|
40
|
+
"tool_calls": [
|
|
41
|
+
{"id": "call_ab9fmzq1", "name": "read_file", "arguments": {"path": "calc.py"}, "error": false, "output": "…"},
|
|
42
|
+
{"id": "call_lhhyt2jn", "name": "bash", "arguments": {"command": "pytest -q"}, "error": true, "output": "This needs the user's permission, …"}
|
|
43
|
+
],
|
|
44
|
+
"files_changed": [{"status": "M", "path": "calc.py"}],
|
|
45
|
+
"usage": {"requests": 6, "prompt_tokens": 35092, "output_tokens": 942},
|
|
46
|
+
"seconds": 30.67,
|
|
47
|
+
"error": ""
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
| Field | |
|
|
52
|
+
|---|---|
|
|
53
|
+
| `status` | `success`, `error`, `max_steps`, `loop` (the model kept repeating the same call, or its replies went nowhere), `blocked` (a site it needed couldn't be reached) or `interrupted` |
|
|
54
|
+
| `text` | The model's final answer |
|
|
55
|
+
| `tool_calls` | Every tool call, with its arguments and output (the first 4,000 characters). `error` is true when the call failed or wasn't allowed |
|
|
56
|
+
| `files_changed` | Files the request added (`A`), modified (`M`) or deleted (`D`), shell commands included |
|
|
57
|
+
| `usage` | Model requests and tokens; `prompt_tokens` includes tokens served from the prompt cache |
|
|
58
|
+
| `review` | What the [review](usage.md#a-review-before-the-answer) sent back to the model (`[]` when it found nothing; `null` when no review ran) |
|
|
59
|
+
| `checks` | The [checks](usage.md#checks-before-done) that ran after the change: `command`, `exit_code` (`null` when they weren't allowed to run) and `by` (`lcode`, or `model` when the model ran them itself) |
|
|
60
|
+
| `error` | What went wrong, when `status` is `error` |
|
|
61
|
+
| `session_id` | Continue the conversation later with `lcode --resume <id>` |
|
|
62
|
+
|
|
63
|
+
A failure before the request starts (no model server, an unknown model) prints
|
|
64
|
+
`{"type": "result", "status": "error", "error": "…"}` and exits with `1`.
|
|
65
|
+
|
|
66
|
+
### The events (stream-json)
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{"type": "start", "schema": 1, "lcode": "0.18.0", "session_id": "…", "model": "lcode-qwen3.6-35b", "cwd": "/src/app"}
|
|
70
|
+
{"type": "assistant", "text": "", "tool_calls": [{"id": "call_1", "name": "read_file", "arguments": {"path": "calc.py"}}]}
|
|
71
|
+
{"type": "tool_result", "id": "call_1", "name": "read_file", "error": false, "output": "…"}
|
|
72
|
+
{"type": "assistant", "text": "The bug is in clamp(): …", "tool_calls": []}
|
|
73
|
+
{"type": "result", "status": "success", …}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
An `assistant` event comes after each model step; a `tool_result` follows each of its calls, with
|
|
77
|
+
the same `id`.
|
|
78
|
+
|
|
79
|
+
## Python
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from lcode import Session
|
|
83
|
+
|
|
84
|
+
with Session("path/to/repo", permission_mode="auto-edit") as session:
|
|
85
|
+
result = session.run("Fix the failing test in tests/test_parser.py")
|
|
86
|
+
print(result.status, result.text)
|
|
87
|
+
for change in result.files_changed:
|
|
88
|
+
print(change["status"], change["path"])
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- **A session is one conversation:** each `run` continues it.
|
|
92
|
+
- **Events while it runs:** `session.stream(prompt)` yields the events above, ending with the result.
|
|
93
|
+
- **Permissions:** pass `approve` to decide permission requests. It gets
|
|
94
|
+
`{"kind": "bash", "title": "…", "target": "pytest -q"}`; without it, every request is refused.
|
|
95
|
+
A `git commit` or `git push` that would add [what looks like a secret](usage.md#secrets-in-commits)
|
|
96
|
+
comes as `{"kind": "secret", …}` in `ask` mode, and doesn't run in the other modes.
|
|
97
|
+
- **Options:** `model`, `context`, `permission_mode`, `allowed_tools`, `max_steps`, `think`,
|
|
98
|
+
`web`, `memory`, `mcp` and `sandbox`. Leave one out to use your
|
|
99
|
+
[configuration](configuration.md).
|
|
100
|
+
- **lcode's own output:** `verbose=True` shows it on stderr.
|
|
101
|
+
- **When lcode can't start** (no model server, a missing model): `lcode.SetupError`.
|
|
102
|
+
|
|
103
|
+
[`examples/api/fix_tests.py`](https://github.com/nasser1941/lcode/blob/main/examples/api/fix_tests.py)
|
|
104
|
+
runs a repository's tests, lets the model fix what fails and approves only the test command:
|
|
105
|
+
|
|
106
|
+
```text
|
|
107
|
+
$ python examples/api/fix_tests.py ~/src/calc
|
|
108
|
+
✓ read_file: 1 def average(values):
|
|
109
|
+
✓ bash: ============================= test session starts ==============================
|
|
110
|
+
✓ edit_file: Edited calc.py (1 replacement(s)). Result:
|
|
111
|
+
✓ edit_file: Edited calc.py (1 replacement(s)). Result:
|
|
112
|
+
✓ bash: ============================= test session starts ==============================
|
|
113
|
+
|
|
114
|
+
success in 22s, 5 model requests
|
|
115
|
+
M calc.py
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## GitHub Action
|
|
119
|
+
|
|
120
|
+
The action runs lcode on a **self-hosted runner**, a machine of yours with a GPU and Ollama (or
|
|
121
|
+
[another model server](servers.md)). The code and the model stay on that machine; only the
|
|
122
|
+
replies and the commits go to GitHub.
|
|
123
|
+
|
|
124
|
+
- **Someone comments `@lcode …`** on an issue or a pull request. lcode reacts with 👀, does what
|
|
125
|
+
they ask and replies.
|
|
126
|
+
- When it changed files on an **issue**, it commits them to a new branch and opens a pull
|
|
127
|
+
request that closes the issue.
|
|
128
|
+
- On a **pull request**, it pushes the commit to that pull request's branch.
|
|
129
|
+
- **With `review: true`**, every new or updated pull request gets a review as a comment.
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
# .github/workflows/lcode.yml
|
|
133
|
+
name: lcode
|
|
134
|
+
on:
|
|
135
|
+
issue_comment:
|
|
136
|
+
types: [created]
|
|
137
|
+
pull_request:
|
|
138
|
+
types: [opened, synchronize]
|
|
139
|
+
|
|
140
|
+
permissions:
|
|
141
|
+
contents: write
|
|
142
|
+
issues: write
|
|
143
|
+
pull-requests: write
|
|
144
|
+
|
|
145
|
+
jobs:
|
|
146
|
+
lcode:
|
|
147
|
+
if: github.event_name == 'pull_request' || contains(github.event.comment.body, '@lcode')
|
|
148
|
+
runs-on: [self-hosted, gpu]
|
|
149
|
+
steps:
|
|
150
|
+
- uses: actions/checkout@v5
|
|
151
|
+
with:
|
|
152
|
+
fetch-depth: 0
|
|
153
|
+
- uses: nasser1941/lcode@v0.18.0
|
|
154
|
+
with:
|
|
155
|
+
review: true
|
|
156
|
+
allow-commands: "pytest*, npm test"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| Input | Default | |
|
|
160
|
+
|---|---|---|
|
|
161
|
+
| `model` | the runner's config | The model to use |
|
|
162
|
+
| `trigger` | `@lcode` | The word that calls lcode in a comment |
|
|
163
|
+
| `review` | `false` | Review pull requests when they're opened or updated |
|
|
164
|
+
| `review-forks` | `false` | Also review pull requests from forks |
|
|
165
|
+
| `author-associations` | `OWNER,MEMBER,COLLABORATOR` | Who can call lcode |
|
|
166
|
+
| `permission-mode` | `auto-edit` | `auto-edit`: file changes, and only the shell commands in `allow-commands`. `yolo`: anything |
|
|
167
|
+
| `allow-commands` | | Shell commands the model may run, with `*` wildcards |
|
|
168
|
+
| `max-steps` | `60` | Model steps per request |
|
|
169
|
+
| `lcode-version` | the action's | The lcode version to run |
|
|
170
|
+
|
|
171
|
+
### Setting up the runner
|
|
172
|
+
|
|
173
|
+
1. [Add a self-hosted runner](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners)
|
|
174
|
+
to the repository, and give it a label such as `gpu`.
|
|
175
|
+
2. On that machine, as the runner's user, install lcode and a model:
|
|
176
|
+
`curl -fsSL https://nasser1941.github.io/lcode/install.sh | bash`. The action runs lcode with
|
|
177
|
+
[uv](https://docs.astral.sh/uv/) when it's there, otherwise with the `lcode` it finds, otherwise
|
|
178
|
+
it installs lcode with pip.
|
|
179
|
+
3. Settings and [permission rules](hooks.md#permission-rules) for the action go in that user's
|
|
180
|
+
`~/.config/lcode/config.toml`. A repository's own `.lcode/settings.toml` isn't used, because
|
|
181
|
+
nobody approved it on the runner.
|
|
182
|
+
|
|
183
|
+
### Safety
|
|
184
|
+
|
|
185
|
+
- **Who can trigger it.** Only people with an owner, member or collaborator association, and
|
|
186
|
+
never bots.
|
|
187
|
+
- **Other people's text.** The issue's description and the code may have been written by anyone.
|
|
188
|
+
lcode tells the model to treat instructions in them as information, but a model can still be
|
|
189
|
+
talked into things. Keep `permission-mode: auto-edit` with a short `allow-commands` list,
|
|
190
|
+
unless the runner is isolated and disposable.
|
|
191
|
+
- **Forks.** Pull requests from forks aren't reviewed unless you set `review-forks`: their code
|
|
192
|
+
would run through lcode's tools on your machine.
|
|
193
|
+
- **Git.** lcode does the git steps itself: the model can't commit, push or switch branches, and
|
|
194
|
+
commits are made as `lcode`.
|
|
195
|
+
- **Public repositories.** GitHub
|
|
196
|
+
[advises against](https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#hardening-for-self-hosted-runners)
|
|
197
|
+
self-hosted runners for public repositories, since anyone can open a pull request. Use the
|
|
198
|
+
action on private repositories, or on a runner you can afford to lose.
|
lcode/docs/bench.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Benchmarking models
|
|
2
|
+
|
|
3
|
+
`lcode bench` answers the most common question about local models: *which one works best for
|
|
4
|
+
coding on my machine?* It runs a fixed set of small coding tasks against one or more models and
|
|
5
|
+
reports how many they solved, how fast they ran and how much memory they used.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
lcode bench # the configured model
|
|
9
|
+
lcode bench qwen3.6-35b qwen3.5-9b # compare models
|
|
10
|
+
lcode bench --tasks fix-bug,rename # run some of the tasks
|
|
11
|
+
lcode bench --json results.json # also save machine-readable results
|
|
12
|
+
lcode bench --markdown # also print a table to paste into a test report
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`lcode bench` also runs against [other model servers](servers.md), such as llama-server or LM
|
|
16
|
+
Studio: `LCODE_BACKEND=llama.cpp lcode bench`. The server keeps the model loaded and doesn't report
|
|
17
|
+
its memory use, so those columns stay empty.
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
lcode bench · NVIDIA GeForce RTX 4080 Laptop GPU (12 GB VRAM), 31 GB RAM · Ollama 0.32.15
|
|
21
|
+
|
|
22
|
+
lcode-qwen3.6-35b · 32K context · reasoning on · 8 tasks
|
|
23
|
+
Loaded in 16s · 22.3 GB, 45% on the GPU · reads prompts at 855 tok/s
|
|
24
|
+
✓ fix-bug Fix a bug so the tests pass 22s the tests pass
|
|
25
|
+
✓ find-code Answer with file:line 9s next_wait at backoff.py:13
|
|
26
|
+
✓ write-script Write a script from a spec 13s correct output, also on data it hadn't seen
|
|
27
|
+
✓ rename Rename a function across files 26s its tests and extra checks pass
|
|
28
|
+
✓ precise-edit One-line edit in a long file 10s changed only service_087's timeout
|
|
29
|
+
✓ recover Recover from failing commands 30s used --source and dropped the invalid line
|
|
30
|
+
✓ spec-fix Fix a function to match its spec 55s follows the whole docstring
|
|
31
|
+
✓ feature Add a feature across files 71s priorities work, including old todos
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
At the end it prints a table comparing the models (see [results](#results-on-a-12-gb-laptop) below).
|
|
35
|
+
|
|
36
|
+
A model usually takes 4 to 12 minutes; each task stops after 5 minutes (`--timeout`).
|
|
37
|
+
|
|
38
|
+
### More tasks and features
|
|
39
|
+
|
|
40
|
+
`--tasks find-concept` adds a task in a larger repository: 40 files of a small backend where the
|
|
41
|
+
model has to find a function by what it does. `--tasks runtime-bug` adds a bug that shows only
|
|
42
|
+
when the code runs: a camera wall's window grows taller with every video frame and can't be made
|
|
43
|
+
smaller again. Reading the code suggests band-aids that fail the hidden test; running it shows the
|
|
44
|
+
cause. Neither is in the default set, so results stay comparable with earlier versions. `--repo-map` gives the model the [repository map](search.md) and
|
|
45
|
+
`--code-search` indexes each task's folder for [semantic search](search.md#semantic-code-search);
|
|
46
|
+
both are off in `lcode bench` by default, for the same reason.
|
|
47
|
+
|
|
48
|
+
### A second try, and a stronger model
|
|
49
|
+
|
|
50
|
+
`--retry` gives a failed task one more try, as a user would ask: "That didn't fix it: it still
|
|
51
|
+
doesn't work right. Look again." `--escalate MODEL` sets a [stronger model](usage.md#a-stronger-model-when-stuck)
|
|
52
|
+
that's asked when the model is stuck and, with `--retry`, before the second try, as `/escalate`
|
|
53
|
+
would: no questions asked, since the flag is your OK. Comparing the two shows what the stronger
|
|
54
|
+
model's advice adds to the same second chance:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
lcode bench --tasks runtime-bug --retry --rounds 3
|
|
58
|
+
lcode bench --tasks runtime-bug --retry --rounds 3 --escalate ollama/qwen3.8-27b
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The JSON report has, for each task, `first_passed` (with `--retry`, whether the first try passed)
|
|
62
|
+
and `escalations`.
|
|
63
|
+
|
|
64
|
+
### Long sessions
|
|
65
|
+
|
|
66
|
+
Each task normally starts a new conversation. `--session` runs them all in **one** conversation
|
|
67
|
+
instead, as a long working session would, so the context fills up and lcode's
|
|
68
|
+
[context management](how-it-works.md#context-management) has to work: the summary shows how often
|
|
69
|
+
it removed old tool output and how often it summarized the conversation. `--no-prune` turns the
|
|
70
|
+
removal off, to compare, and `--compact-at` sets the ceiling (`--compact-at 0`: only at 85%).
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
lcode bench --context 32k --session --rounds 3
|
|
74
|
+
lcode bench --context 32k --session --rounds 3 --no-prune
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`--rounds 3` runs the tasks three times, 24 in one conversation, which fills a 32K window several
|
|
78
|
+
times over. With qwen3.6-35b on a 12 GB laptop (two runs each; runs vary a lot from one to the
|
|
79
|
+
next):
|
|
80
|
+
|
|
81
|
+
| | Removing old tool output first | Summarizing only (`--no-prune`) |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| Conversation summarized | 1 and 2 times | 1 and 3 times |
|
|
84
|
+
| Old tool output removed | 3 times in each run | — |
|
|
85
|
+
| Tasks solved | 21 and 22 of 24 | 23 and 21 of 24 |
|
|
86
|
+
| Time | 26 and 28 min | 21 and 30 min |
|
|
87
|
+
|
|
88
|
+
Removing old tool output means fewer summaries, so more of the conversation stays word for word,
|
|
89
|
+
at no measurable cost in tasks solved or time. The bench tasks are independent of each other,
|
|
90
|
+
which is where summaries hurt least; in a real session, where later requests build on earlier
|
|
91
|
+
ones, keeping the conversation intact matters more.
|
|
92
|
+
|
|
93
|
+
With a large window, `compact_at` decides when lcode makes room. In a 128K window, 24 tasks in one
|
|
94
|
+
conversation reach about 40K tokens, so the default ceiling of 64K never comes into play. Making
|
|
95
|
+
room earlier than needed doesn't cost tasks:
|
|
96
|
+
|
|
97
|
+
| 128K window, 24 tasks | No room made (peak ~40K) | `--compact-at 32k` |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| Conversation summarized | 0 times | 1 time (old tool output removed once) |
|
|
100
|
+
| Tasks solved | 21 of 24 | 21 of 24 |
|
|
101
|
+
| Time | 33 min | 27.5 min |
|
|
102
|
+
| Average prompt | 22.9K tokens | 16.6K tokens |
|
|
103
|
+
|
|
104
|
+
## The tasks
|
|
105
|
+
|
|
106
|
+
Every task runs in a new temporary folder, with every permission granted (`yolo` mode) and web
|
|
107
|
+
access off, and ends with an automatic check. The folders are deleted afterwards unless you pass
|
|
108
|
+
`--keep`, which also keeps each task's transcript (`lcode-bench.log`).
|
|
109
|
+
|
|
110
|
+
| Task | The model has to | Passes when |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `fix-bug` | Find and fix a bug so the failing unit tests pass | The tests pass and the test file is unchanged |
|
|
113
|
+
| `find-code` | Answer a question about a small codebase | It names the right function and cites its `file:line` |
|
|
114
|
+
| `write-script` | Write a script from a spec and run it | The script prints the right output, also for data it never saw |
|
|
115
|
+
| `rename` | Rename a function across several files and tests | The old name is gone and extra hidden tests pass |
|
|
116
|
+
| `precise-edit` | Change one value in a 900-line file of near-identical entries | Exactly that one line changed |
|
|
117
|
+
| `recover` | Run a command that fails twice (a removed option, a bad input line) and work around it | The report is correct and only the bad line was dropped |
|
|
118
|
+
| `spec-fix` | Fix a function from a one-line bug report so it does everything its docstring says | Hidden tests of every rule in the docstring pass, edge cases included |
|
|
119
|
+
| `feature` | Add priorities to a small todo app (a new option, sorting, a marker in the output) | Its tests pass, and a scripted session gives the exact expected output, including for todos saved before the change |
|
|
120
|
+
|
|
121
|
+
The first six tasks are everyday work that good models get right; the last two need careful
|
|
122
|
+
reading and are where smaller models tend to slip. The checks are deterministic and can't be passed
|
|
123
|
+
by hard-coding: for example, `write-script` reruns the script on new data, and `rename`, `spec-fix`
|
|
124
|
+
and `feature` are checked with tests the model never saw.
|
|
125
|
+
|
|
126
|
+
## What's measured
|
|
127
|
+
|
|
128
|
+
| | |
|
|
129
|
+
|---|---|
|
|
130
|
+
| **Passed** | Tasks solved within the time limit |
|
|
131
|
+
| **Time** | Total time for the tasks (loading the model is reported separately) |
|
|
132
|
+
| **Generation** | Output tokens per second, across all the model's responses |
|
|
133
|
+
| **Prompt reading** | Prompt tokens per second: how fast the model reads files and tool output. Measured per model with fresh 4,000-token prompts (the faster of two readings, since the first one after loading includes warm-up), because during the tasks Ollama serves most of each request from its prompt cache |
|
|
134
|
+
| **Tool-call errors** | Tool calls that failed (wrong arguments, editing without reading first, unmatched edits) or that the model wrote as invalid JSON |
|
|
135
|
+
| **Memory** | The model's memory use and how much of it is on the GPU, from Ollama |
|
|
136
|
+
|
|
137
|
+
Results depend on the context window, so `lcode bench` uses **32K** by default on every machine,
|
|
138
|
+
which makes results comparable. When comparing models, each one is unloaded before the next starts
|
|
139
|
+
so every model gets the whole GPU; lcode warns if other models are already loaded. Use `--context 128k` to measure a larger window, and `--no-think`
|
|
140
|
+
to measure a model without reasoning.
|
|
141
|
+
|
|
142
|
+
## Results on a 12 GB laptop
|
|
143
|
+
|
|
144
|
+
RTX 4080 Laptop GPU (12 GB) with 31 GB of RAM, Ollama 0.32.15, 32K context, reasoning on:
|
|
145
|
+
|
|
146
|
+
| | `qwen3.6-35b` | `qwen3.5-9b` | `qwen3.5-4b` |
|
|
147
|
+
|---|---|---|---|
|
|
148
|
+
| fix-bug | ✓ 22s | ✓ 16s | ✓ 11s |
|
|
149
|
+
| find-code | ✓ 9s | ✓ 6s | ✓ 5s |
|
|
150
|
+
| write-script | ✓ 13s | ✓ 44s | ✗ 18s |
|
|
151
|
+
| rename | ✓ 26s | ✓ 28s | ✓ 30s |
|
|
152
|
+
| precise-edit | ✓ 10s | ✓ 12s | ✓ 8s |
|
|
153
|
+
| recover | ✓ 30s | ✗ 29s | ✓ 24s |
|
|
154
|
+
| spec-fix | ✓ 55s | ✓ 4m 40s | ✗ 2m 57s |
|
|
155
|
+
| feature | ✓ 1m 11s | ✗ 5m 00s | ✓ 47s |
|
|
156
|
+
| **Passed** | **8/8** | **6/8** | **6/8** |
|
|
157
|
+
| Time | 3m 57s | 11m 55s | 5m 20s |
|
|
158
|
+
| Generation | 71.4 tok/s | 60.1 tok/s | 91.3 tok/s |
|
|
159
|
+
| Prompt reading | 855 tok/s | 3,507 tok/s | 5,186 tok/s |
|
|
160
|
+
| Tool-call errors | 0 | 9 | 1 |
|
|
161
|
+
| Memory | 22.3 GB, 45% on GPU | 6.6 GB, 100% on GPU | 4.2 GB, 100% on GPU |
|
|
162
|
+
|
|
163
|
+
The small models fit entirely on the GPU and read prompts much faster, but the larger mixture-of-
|
|
164
|
+
experts model solves more and needs fewer attempts. The small models' failures were real mistakes:
|
|
165
|
+
copying `read_file`'s line numbers into a data file, ignoring negative numbers, missing an edge case
|
|
166
|
+
of the spec, and running out of time.
|
|
167
|
+
|
|
168
|
+
Models sample their answers, so a task near the edge of a model's ability can pass in one run and
|
|
169
|
+
fail in the next (`qwen3.6-35b` scored 7/8 in an earlier run). Compare totals rather than single
|
|
170
|
+
tasks, and run twice before drawing conclusions.
|
|
171
|
+
|
|
172
|
+
## Sharing results
|
|
173
|
+
|
|
174
|
+
Results from other machines, especially Apple Silicon Macs and other GPUs, decide which models lcode
|
|
175
|
+
recommends. Run
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
lcode bench qwen3.6-35b --markdown
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
and paste the table into a
|
|
182
|
+
[model test report](https://github.com/nasser1941/lcode/issues/new?template=model_request.yml).
|
|
183
|
+
|
|
184
|
+
## JSON format
|
|
185
|
+
|
|
186
|
+
`--json FILE` writes one document per run. The schema is versioned: fields may be added, but
|
|
187
|
+
existing fields keep their meaning until `schema` changes.
|
|
188
|
+
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"schema": 1,
|
|
192
|
+
"lcode": "0.3.1",
|
|
193
|
+
"ollama": "0.32.15",
|
|
194
|
+
"server": "Ollama 0.32.15",
|
|
195
|
+
"date": "2026-09-30T19:09:09+02:00",
|
|
196
|
+
"hardware": {
|
|
197
|
+
"os": "linux", "cpu": "13th Gen Intel(R) Core(TM) i9-13980HX", "ram_gib": 30.96,
|
|
198
|
+
"gpu": "NVIDIA GeForce RTX 4080 Laptop GPU", "vram_gib": 11.99, "unified": false,
|
|
199
|
+
"description": "NVIDIA GeForce RTX 4080 Laptop GPU (12 GB VRAM), 31 GB RAM"
|
|
200
|
+
},
|
|
201
|
+
"tasks": [{"id": "fix-bug", "title": "Fix a bug so the tests pass"}, …],
|
|
202
|
+
"runs": [
|
|
203
|
+
{
|
|
204
|
+
"model": "qwen3.6-35b",
|
|
205
|
+
"ollama_model": "lcode-qwen3.6-35b",
|
|
206
|
+
"context": 32768,
|
|
207
|
+
"num_batch": null,
|
|
208
|
+
"think": true,
|
|
209
|
+
"load_seconds": 16.2,
|
|
210
|
+
"prompt_tps": 854.6,
|
|
211
|
+
"memory_gb": 22.3,
|
|
212
|
+
"gpu_percent": 45,
|
|
213
|
+
"passed": 8,
|
|
214
|
+
"total": 8,
|
|
215
|
+
"seconds": 237.3,
|
|
216
|
+
"generation_tps": 71.4,
|
|
217
|
+
"tool_errors": 0,
|
|
218
|
+
"usage": {"requests": 56, "prompt_tokens": 221522, "prompt_ns": 73377987000,
|
|
219
|
+
"output_tokens": 11490, "output_ns": 161017657999},
|
|
220
|
+
"tasks": [
|
|
221
|
+
{"id": "fix-bug", "passed": true, "seconds": 21.9, "detail": "the tests pass",
|
|
222
|
+
"steps": 5, "tool_errors": 0, "error": null},
|
|
223
|
+
…
|
|
224
|
+
],
|
|
225
|
+
"error": null,
|
|
226
|
+
"interrupted": false
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
| Field | Meaning |
|
|
233
|
+
|---|---|
|
|
234
|
+
| `ollama`, `server` | The Ollama version, or `null` with [another model server](servers.md); `server` names the server either way |
|
|
235
|
+
| `runs[].model` | The name you gave (catalog key or Ollama tag); `ollama_model` is the model that ran |
|
|
236
|
+
| `runs[].context`, `num_batch`, `think` | The settings used. lcode lowers the batch size or context if the GPU runs out of memory, and reports what it ended up using |
|
|
237
|
+
| `runs[].memory_gb`, `gpu_percent` | From Ollama's `/api/ps`; `null` if unavailable |
|
|
238
|
+
| `runs[].generation_tps` | Output tokens per second across the tasks; `null` if Ollama reported no timings |
|
|
239
|
+
| `runs[].prompt_tps` | Prompt tokens per second for a fresh 4,000-token prompt (the faster of two readings); `null` if it couldn't be measured |
|
|
240
|
+
| `runs[].usage` | Totals over the tasks as Ollama reports them. `prompt_tokens` includes tokens served from the prompt cache |
|
|
241
|
+
| `runs[].tasks[].steps` | Model responses in the task |
|
|
242
|
+
| `runs[].tasks[].error` | Why the task stopped early (`timed out after 300s`, an Ollama error), otherwise `null` |
|
|
243
|
+
| `runs[].error` | Why the model didn't run at all (for example, not installed), otherwise `null` |
|
|
244
|
+
| `runs[].interrupted` | You pressed ++ctrl+c++; the results cover the tasks that finished |
|