skills/kwcode-local-coding-agent/SKILL.md
KWCode (天工开物) — a CLI coding agent optimized for local open-source models (8B-30B), featuring deterministic expert pipelines, BM25+AST code location, runtime debugging, and a self-improving flywheel — all running fully offline.
npx skillsauth add aradotso/trending-skills kwcode-local-coding-agentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Skill by ara.so — Daily 2026 Skills collection.
KWCode is a CLI coding agent designed specifically for local open-source models (8B–30B parameters). Unlike cloud-first agents (Claude Code, Cursor), KWCode uses a deterministic expert pipeline where the LLM only classifies and generates — all routing, validation, and decision-making is handled by deterministic code. This lets small models succeed where they would otherwise hallucinate or loop.
# Standard install
pip install kwcode
# China mirror (faster in mainland)
pip install kwcode -i https://pypi.tuna.tsinghua.edu.cn/simple
# Optional: Cross-Encoder search reranking
pip install "kwcode[rerank]"
Requirements: Python 3.10+, any OpenAI-compatible API (local or cloud).
# Launch interactive REPL
kwcode
On first launch, KWCode runs a setup wizard to configure your model connection.
# Inside kwcode REPL or as a slash command:
/api default http://localhost:11434/v1 ollama qwen3:8b
/api default https://api.deepseek.com $DEEPSEEK_API_KEY deepseek-coder
/api default https://api.siliconflow.cn/v1 $SILICONFLOW_API_KEY Qwen/Qwen3-8B
export KWCODE_API_BASE=http://localhost:11434/v1
export KWCODE_API_KEY=ollama
export KWCODE_MODEL=qwen3:8b
kwcode
| VRAM | Model |
|------|-------|
| 4 GB | gemma3:4b |
| 8 GB | qwen3:8b |
| 16 GB | qwen3:14b |
| 24 GB+ | qwen3:30b-a3b |
All commands are entered inside the kwcode REPL (> prompt).
> <natural language task description>
> 修复登录验证失败的问题
> write a FastAPI login endpoint with JWT auth
> refactor calculate_price into smaller functions
> /plan <task description>
Shows execution steps and risk level (High / Medium / Low) before touching any file. Requires confirmation.
> /checkpoint
Manually snapshot current project state. KWCode also auto-snapshots before each task.
> /rollback
Restore to the last checkpoint if a task goes wrong.
> /multi task1 ; task2 ; task3 # all parallel
> /multi task1 -> task2 -> task3 # serial chain
> /multi # interactive builder
Interactive multi-task example:
> /multi
+ add docstring to function `add` (parallel)
+ add docstring to function `sub` (parallel)
+ >write tests for the modified code (serial, depends on above two)
# Install SearXNG (requires Docker Desktop running)
kwcode setup-search
> /search <query> # explicit search inside REPL
Without Docker, KWCode falls back to DuckDuckGo automatically.
kwcode stats # CLI command (outside REPL)
Shows tasks completed, estimated time saved, and flywheel expert promotions.
> /api list # show configured endpoints
> /api default <base_url> <key> [model] # set default endpoint
> /api add <name> <base_url> <key> # add named endpoint
> /api use <name> # switch active endpoint
KWCode looks for these files in your project root and injects them as context:
| File | Purpose |
|------|---------|
| KWCODE.md | Project-level rules, conventions, coding standards. Injected per task type. |
| PROJECT.md | Auto-maintained project summary (Layer 1 memory). |
| EXPERT.md | Domain expert knowledge accumulated by the flywheel (Layer 2). |
| PATTERN.md | Recurring code patterns learned from your project (Layer 3). |
| REFLECTION.md | Structured log of past failures and lessons (auto-updated). |
KWCODE.md# Project Rules
## bugfix
- Always run `pytest tests/` after any fix
- Never modify migration files directly
## codegen
- Use `async def` for all new route handlers
- Import order: stdlib → third-party → local
## general
- Line length: 88 (black default)
- All new functions must have type hints
Every user input flows through five deterministic stages:
Input
└─► Gate — classifies task, routes to skill, matches domain knowledge
└─► Locator — BM25 keyword recall + AST call-graph expansion (no LLM)
└─► Generator — generates only the changed diff, injects SKILL.md
└─► Verifier — syntax check + pytest (deterministic)
└─► Debugger — sys.settrace captures live variable values
└─► Reviewer — LLM checks intent vs actual change
The LLM is only called at Generator and Reviewer stages. Everything else is deterministic Python.
# KWCode detects "bug", "fix", "error", "失败" → routes to BugFix expert
# Inside REPL:
# > fix the KeyError in user_service.py when email is missing
KWCode will:
user_service.py + trace call graph for hidden dependenciespytest automaticallysys.settrace and retry> generate pytest tests for the PaymentProcessor class
KWCode injects the TestGen SKILL.md, locates PaymentProcessor via AST, generates tests, and verifies they pass.
from kwcode import KWCodeAgent
agent = KWCodeAgent(
api_base="http://localhost:11434/v1",
api_key="ollama",
model="qwen3:8b",
project_dir="/path/to/your/project",
)
result = agent.run("fix the login validation bug")
print(result.status) # "success" | "failed" | "rolled_back"
print(result.files_changed) # list of modified file paths
print(result.patch) # unified diff string
from kwcode import KWCodeAgent, TaskGraph
agent = KWCodeAgent(model="qwen3:14b", project_dir=".")
graph = TaskGraph()
t1 = graph.add("add type hints to utils.py")
t2 = graph.add("add type hints to models.py")
t3 = graph.add("write tests for typed functions", depends_on=[t1, t2])
results = agent.run_graph(graph)
for task_id, result in results.items():
print(f"{task_id}: {result.status}")
When Verifier fails, KWCode does not repeat the same attempt:
| Attempt | Strategy |
|---------|----------|
| 1st | Normal task description sent to Generator |
| 2nd | Error message + sys.settrace runtime variable dump injected; LLM reflects on why attempt 1 failed |
| 3rd | Minimal-change constraint enforced; Debug Subagent provides full pytest --tb=long trace |
After 3 failures, task is marked failed and rolled back to checkpoint.
/api default <your_base_url> <key> <model> # re-confirm model name matches server
Check that your local inference engine is running:
curl http://localhost:11434/v1/models # Ollama
curl http://localhost:8080/v1/models # llama.cpp / LM Studio
BM25 needs indexed content. If your project is new:
> /index # force re-index project files
If the file uses an unusual extension, add it to KWCODE.md:
## index
- include: ["*.pyx", "*.pxd", "*.proto"]
> /config verifier.test_cmd "python -m pytest tests/ -x"
Or set in KWCODE.md:
## verifier
- test_cmd: python -m pytest tests/ -x --tb=short
# Install local SearXNG (requires Docker)
kwcode setup-search
# Verify it's running
curl http://localhost:8080/search?q=test&format=json
KWCode auto-compresses context when it approaches the limit, but you can tune aggressiveness:
> /config context.compression_ratio 0.6 # keep 60% of mid-conversation history
> /config locator.max_files 3 # limit files sent to Generator
Promotion requires: ≥5 successes of the same task type → backtest pass rate ≥ baseline → 10-run A/B test with >10% improvement. Check flywheel status:
kwcode stats --flywheel
KWCode ships with 15 built-in domain skills injected at Generator stage:
| Skill | Triggers |
|-------|---------|
| BugFix | fix, bug, error, crash, 修复 |
| FastAPI | fastapi, route, endpoint, async |
| TestGen | test, pytest, unittest, 测试 |
| API | api, rest, http, request |
| DeepSeekAPI | deepseek, r1, v3 |
| Docstring | docstring, document, 注释 |
| MyBatis | mybatis, mapper, xml, sql |
| Office | excel, word, ppt, spreadsheet |
| Refactor | refactor, clean, extract, 重构 |
| SpringBoot | spring, springboot, java |
| SQLOpt | sql, query, optimize, index |
| TypeHint | type hint, annotation, mypy |
| UniApp | uniapp, vue, miniprogram |
Custom skills can be added by placing a SKILL_<name>.md file in your project root or ~/.kwcode/skills/.
~/.kwcode/stats.db (SQLite, local only).development
```markdown --- name: compose-performance-skills description: Install and use the skydoves/compose-performance-skills agent skill library to diagnose and fix Jetpack Compose performance issues including stability, recomposition, lazy layouts, modifiers, side effects, and build configuration. triggers: - "my composable recomposes too often" - "LazyColumn drops frames during scroll" - "diagnose Compose stability issues" - "fix unnecessary recomposition in Jetpack Compose" - "optimize Com
development
Headless iOS Simulator manager with host-side HID input injection, 60fps streaming, and device farm web UI for iOS 26
development
```markdown --- name: claude-code-game-studios description: Turn Claude Code into a full 49-agent game dev studio with 72 workflow skills, automated hooks, and a real studio hierarchy for Godot, Unity, and Unreal projects. triggers: - "set up claude code game studios" - "use ai agents for game development" - "set up game dev studio with claude" - "add game studio agents to my project" - "how do I use claude code for game dev" - "set up godot unity unreal ai workflow" - "49 agents g
development
```markdown --- name: xq-py-quantum-vm description: Python implementation of the Quip Network's quantum virtual machine (xqvm) triggers: - quantum virtual machine python - xqvm quip network - quantum circuit simulation python - xq-py quantum vm - quip network quantum python - simulate quantum gates python - quantum vm xqvm - xqvm-py quantum circuit --- # xq-py Quantum Virtual Machine > Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection. `xqvm-py` is a Python impl