9.0 KiB
KWCode Project Status
Path: D:\program\codeagent2604\kwcode GitHub: https://github.com/val1813/kwcode Started: 2026-04-26 Goal: Local-model coding agent — maximize task completion rate via deterministic expert pipeline
Current: v1.5.0 (2026-05-06)
451/451 tests green. Architecture upgrade: isolated search + cross-file contracts + PENCIL compression.
v1.5.0 — Isolated Search + Cross-File Contracts
Theory: WarpGrep (isolated search subagent) + CGM (graph-injected attention) + PENCIL (erase intermediate state) + SWE-ContextBench (context quality > model size)
SearchSubagent (experts/search_subagent.py)
- Independent context window — search noise never enters Generator
- Parallel file reads: ThreadPoolExecutor, 8 concurrent
- Returns only precise {file, start_line, end_line, content}
- Shadow TaskContext: Locator writes to shadow, main ctx stays clean
UpstreamManifest (core/upstream_manifest.py)
- Deterministic AST extraction: Python ast module, regex fallback for others
- Tracks: function signatures, constants, import dependencies
- get_constraints_for_file() → injected into Generator prompt
- check_consistency() → Verifier pre-check, catches arg count / constant mismatches
- Zero LLM calls
PENCIL Compression + Contract Verification
- task_compiler: _compact_subtask_result() keeps only signatures/constants/paths/test_status
- orchestrator: locator step uses SearchSubagent, verifier pre-checks contracts
- contract_violation error type triggers re-locate retry strategy
- Generator prompt receives upstream_constraints + retry_hint
Code Quality (this release)
- orchestrator.py run() split into 5 private methods (410→253 lines)
- Full type annotations: Optional[DebugSubagent], Callable[[str,str],None]
- all added to 7 core modules
- pyproject.toml: license fixed, ruff + mypy configured
- TUI: 30+ event icons added (contract_violation, ab_test, replay, etc.)
- Server: /api/manifest endpoint, version 1.5.0
v1.4.0 — Multi-Language + TUI + IDE
Theory: XRAY MCP Server + OpenCode + CodeCompass
- 7-language AST (Python/JS/TS/Go/Rust/Java/C#)
- ast-grep with QUERY_TEMPLATES (LLM never writes patterns)
- FastAPI server (port 7355) + SSE streaming
- Textual TUI (file tree + event log + input)
- VSCode extension (thin client, all logic server-side)
v1.3.0 — EventBus + Error Strategy + Cognitive Gate
Theory: Dive into Claude Code + Wink + ARCS + SpecEyes + OPENDEV + Turn-Control
- EventBus: append-only log, replay, wildcard listeners
- ToolGateway: per-expert permissions, file cache with dirty tracking
- Error strategy routing: 6 error types → different retry sequences
- CognitiveGate: diminishing returns detection → auto-stop
- GraduatedCompactor: 3-layer progressive context compression
- Plan auto-trigger for hard tasks
- Worktree isolation (git worktree / tempdir fallback)
- Speculative Prefetch: background file pre-read
- SearchRouter: intent-aware routing (arXiv/S2/GitHub/PyPI/Open-Meteo)
- Wink self-repair: scope_creep / repetitive_fix / patch_miss / empty_output
v1.2.0 — RIG Project Map
Theory: RIG + FastCode + CodeCompass
- export_rig(): full project index (exports/imports/routes/test coverage)
- upstream_summary structured dict for multi-task context passing
- ConsistencyChecker: deterministic frontend/backend API mismatch detection
- Gate/Locator prompt explicitly guided to query rig.json
v1.1.0 — P0+P1+P2 Optimizations
- Verifier structured output (_classify_error: 5 error types)
- Circuit breakers (syntax 1x, import immediate, same-type 3x streak)
- Gate confidence scoring (0.92/0.75/0.55)
- Experience Replay (BM25 similar trajectory lookup)
- Session continuity (SessionState, 5-turn KWCODE.md re-injection)
- Locator minimal context (function boundaries, 60-line cap, gap markers)
- Watchdog 300s timeout
- Gate accuracy stats (/stats command)
v0.9.0 — DAG Compiler + Debug Subagent
- TaskCompiler: DAG scheduler, ThreadPoolExecutor + Kahn topological sort
- Debug Subagent: sys.settrace variable capture on failure
- Prompt Optimizer: trajectory → experience rules → YAML system_prompt
- Cross-Encoder search reranking
Core Pipeline (v0.5.0–v0.8.0)
- Gate → 6 pipeline routes (locator_repair/codegen/refactor/doc/office/chat)
- BM25+AST call graph two-phase location (zero LLM, milliseconds)
- Generator: original from file, LLM only generates modified
- Verifier: syntax check + pytest
- 3-stage retry + Reflection root cause analysis
- 5 deterministic tools (read_file/write_file/run_bash/list_dir/git)
- KWCODE.md project rules + /plan + Checkpoint + DocReader
- Model capability tiers (SMALL/MEDIUM/LARGE)
- Expert flywheel (trajectory → pattern → backtest → AB test → production)
- 3-layer memory (PROJECT.md/EXPERT.md/PATTERN.md)
- Office document generation (Excel/PPT/Word)
- MCP Router, context compression, CJK BM25
Test Summary
| Category | Count | Status |
|---|---|---|
| Core unit tests | 38 | PASS |
| Regression tests | 173 | PASS |
| P1 feature tests | 33 | PASS |
| P2 feature tests | 21 | PASS |
| Search refactor | 19 | PASS |
| Intent search | 19 | PASS |
| E2E real model | 17 | PASS |
| RIG modules | 29 | PASS |
| TaskCompiler | 12 | PASS |
| Multi-language | 51 | PASS |
| Server/TUI | 16 | PASS |
| SearchSubagent+Manifest | 27 | PASS |
| Total | 451 | All green |
File Structure
kwcode/
├── pyproject.toml
├── README.md / README_zh.md
├── STATUS.md
└── kaiwu/
├── cli/
│ ├── main.py # REPL + EventBus rendering + spinner + summary
│ ├── status_bar.py # Status bar (4-tier adaptive)
│ └── onboarding.py # First-run onboarding
├── core/
│ ├── event_bus.py # Unified event bus (append-only + replay)
│ ├── cognitive_gate.py # Diminishing returns detection
│ ├── wink.py # Self-repair monitor
│ ├── gate.py # LLM task classification → expert routing
│ ├── orchestrator.py # Deterministic pipeline + error strategy routing
│ ├── context.py # TaskContext dataclass
│ ├── task_compiler.py # DAG scheduler + WorktreeManager
│ ├── upstream_manifest.py # [v1.5] Cross-file contract tracking (zero LLM)
│ ├── planner.py # /plan mode + risk assessment
│ ├── checkpoint.py # File snapshot (git stash / file copy)
│ ├── kwcode_md.py # KWCODE.md segmented loading
│ ├── model_capability.py # Model tier detection (SMALL/MEDIUM/LARGE)
│ ├── context_pruner.py # Context compression + GraduatedCompactor
│ ├── network.py # Network detection + proxy config
│ └── sysinfo.py # System info + VRAM monitoring
├── experts/
│ ├── locator.py # BM25+graph location + DocReader + Prefetch
│ ├── search_subagent.py # [v1.5] Isolated search (independent context)
│ ├── generator.py # Code generation (original from file, LLM writes modified)
│ ├── verifier.py # Syntax + pytest + cross-file contract check
│ ├── search_augmentor.py # Search augmentation + BM25 rerank
│ ├── consistency_checker.py # Frontend/backend API consistency (deterministic)
│ ├── chat_expert.py # Chat (search gating)
│ └── office_handler.py # Office document generation
├── search/ # Intent-aware search routing
├── knowledge/ # PDF/Word/MD reader + CJK BM25
├── flywheel/ # Trajectory → pattern → generation → AB test
├── registry/ # Expert registry + .kwx packaging
├── notification/ # Flywheel notifications
├── stats/ # Value tracking (SQLite)
├── memory/ # 3-layer memory system
├── ast_engine/ # tree-sitter AST + call graph
├── server/ # FastAPI + SSE (port 7355)
├── tui/ # Textual TUI
├── mcp/ # MCP Router
├── llm/ # Ollama + llama.cpp backends
├── tools/ # 5 deterministic tools + ToolGateway
└── tests/ # 451 tests
TODO
CLI refactor: split main.py (1861 lines) into cli/commands/✅ v1.5.0Comments: unify to Chinese across all modules✅ v1.5.0Expert-level EventBus emit (file reads, function locations, test results)✅ v1.5.0- SQLite cross-session queries
- Full expert benchmark (12 presets)
- pip publish to PyPI
- install.ps1 / install.sh one-click install
Known Issues
- qwen3-vl:8b outputs in thinking field, content empty (thinking extraction added)
- Reasoning models slow on Gate (8x multiplier)
- SearXNG requires Docker Desktop, degrades to DDG without it