30 Commits

Author SHA1 Message Date
Val-sss
2c4d792baa feat: v1.7.0 KAIJU架构借鉴 — bounded context + sub-task decomposition + DetailedLogger
三个核心改动:
1. Generator bounded context: 只传当前函数代码+相关failing tests,不传完整历史
2. 存根任务sub-task decomposition: 多pass函数逐个独立实现,每个函数独立context
3. DetailedLogger完整流水线日志: 不截断LLM输入输出,记录各节点IO和工程决策

附带修复:
- OpenAI兼容API检测: localhost非标准端口探测/api/tags判断是否Ollama
- LLM Backend on_call钩子: 每次调用自动触发回调记录

513 tests passed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-07 18:24:56 +08:00
Val-sss
ca55970ad8 release: v1.6.2 版本号统一 + README/CHANGELOG/STATUS更新
- 版本号统一到1.6.2(pyproject/__init__/formatters/telemetry/server)
- README: badge 1.6.2, License Apache-2.0, 更新日志加v1.6.2条目
- CHANGELOG: 完整v1.6.2变更记录
- STATUS: 当前版本更新到v1.6.2

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-07 14:42:21 +08:00
Val-sss
fa1390f8a9 release: v1.6.1 版本号统一 + README/STATUS更新 + License Apache-2.0
- pyproject.toml/formatters/telemetry/server/models/__init__ 全部统一到 1.6.1
- README: badge更新、更新日志加v1.6.0/v1.6.1条目
- STATUS: 版本号描述更新

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-07 09:23:19 +08:00
Val-sss
2861177ff0 Revert "feat: Blueprint两步生成流程(LLM施工图→模板填充→LLM fallback)"
This reverts commit a98e95fe61.
2026-05-07 09:12:47 +08:00
Val-sss
a98e95fe61 feat: Blueprint两步生成流程(LLM施工图→模板填充→LLM fallback)
- 新增 blueprint.py: Blueprint dataclass
- 新增 skill_parser.py: 解析SKILL.md模板块
- 新增 skill_executor.py: 确定性模板填充(零LLM)
- 新增 blueprint_collector.py: 成功施工图双写飞轮
- Generator插入两步流程:Step1生成施工图→Step2模板填充→fallback现有逻辑
- Orchestrator._record_blueprints()记录成功blueprint
- CLI: kwcode skill list-templates / promote
- bugfix/SKILL.md追加3个初始模板(null_check/stub_implement/add_return_guard)
- 542 tests green(+29新测试)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-07 09:00:23 +08:00
Val-sss
76fa84da08 feat: wire model_capability into pipeline — tier-adaptive prompts + ctx auto-detect
Model tier detection now active (was orphaned code):
- orchestrator.__init__: detect tier from generator.llm.ollama_model
- ctx.model_tier written at run() start, flows to Generator
- Generator._build_system(): SMALL gets strict format constraints
  (1 function, ≤10 lines, preserve indent, no explanation, ≤15 words between tools)
  LARGE gets minimal constraint; MEDIUM uses base rules as-is
- _get_max_retries() respects model_strategy.max_retries

Context window auto-detection (get_effective_ctx):
- 4-layer probe: llama.cpp /props → vLLM /v1/models → Ollama modelinfo.llama.context_length → tier default
- Passed to LLMBackend n_ctx in build_pipeline
- SMALL=16K, MEDIUM=32K, LARGE=64K defaults; native ctx capped at 64K×0.8

501 tests green, 0 regression.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 20:33:59 +08:00
Val-sss
7b61af7be3 feat: audit log + model cmd + indent alignment fix
Audit log (audit/logger.py):
- Persists task execution trace as human-readable JSON
- Storage: ~/.kaiwu/logs/, max 100, auto-cleanup
- Records: task, gate, experts, files, tests, retries (no code content)
- orchestrator._emit() now instance method, auto-logs to audit
- CLI: kwcode log / log show <id> / log clear

Model commands (cli/commands/model_cmd.py):
- kwcode model: show current config + tier
- kwcode model set <name>: switch model (writes config.yaml)
- kwcode model probe: detect family/params/quant/reasoning via Ollama API

Indent alignment fix (Generator._align_indentation):
- Fixes systematic bug: LLM returns class methods at 0-indent,
  apply_patch replaces 4-indent original → method escapes class
- Aligns modified base indent to match original before apply_patch

Tests: 10 new (audit 4 + indent 5 + hashline prompt 1), 50 total green

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 20:13:26 +08:00
Val-sss
17b6076945 fix: unify version to 1.5.1 from single source (pyproject.toml)
- pyproject.toml: 1.4.0 → 1.5.1 (single source of truth)
- formatters.py: hardcoded 0.9.0 → importlib.metadata
- telemetry/client.py: hardcoded 1.5.0 → importlib.metadata
- server/models.py + app.py: hardcoded 1.5.0 → importlib.metadata
- All fallback to "1.5.1" if package not installed in editable mode

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 19:47:24 +08:00
Val-sss
53c08a4e28 feat: three flywheels + anonymous telemetry + prompt quantification
Flywheel system (all local):
- strategy_stats.py: error strategy effectiveness tracking per error_type
- user_pattern_memory.py: cross-project user error pattern warnings
- skill_drafter.py: auto-generate SKILL.md drafts from stats

Anonymous telemetry (opt-in, default off):
- telemetry/client.py: HMAC-signed fire-and-forget upload
- Only sends: error_type, retry_count, success, model
- Never sends: code, paths, descriptions, user identity
- onboarding asks opt-in, kwcode telemetry enable/disable

CLI commands:
- kwcode telemetry status/enable/disable
- kwcode skill review/accept/discard
- kwcode stats: enhanced with flywheel + telemetry status

Prompt quantification (CC-style):
- GENERATOR_BASE_SYSTEM: "only do what's asked" → "≤2 functions, ≤30 lines"
- RETRY_STRATEGIES hints: quantified line limits per error type
- CHAT_SYSTEM: "short friendly" → "≤100 chars, ≤3 sentences"

Server deployed: https://llmbbs.com (nginx → uvicorn:9753, 3 SQLite tables)

Tests: 19 new, 0 regression

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 19:39:17 +08:00
Val-sss
0a386f5fae refactor: split CLI main.py (1861→173 lines) + expert EventBus emit
CLI restructure:
- kaiwu/cli/main.py: only app registration + entry point (173 lines)
- kaiwu/cli/commands/task.py: run/chat/vision/multi-task commands
- kaiwu/cli/commands/expert.py: expert list/info/export/install/remove
- kaiwu/cli/commands/config.py: init/api/model/setup-search/serve
- kaiwu/cli/formatters.py: Rich output formatting (spinner, summary, header)

Expert-level EventBus emit:
- locator.py: emit file reads and method type
- event_bus.py: singleton get_instance() for expert access
- orchestrator.py: pass bus to experts for fine-grained events

451/451 tests green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 17:45:09 +08:00
Val-sss
a502c9db63 feat: v1.4.0 多语言AST + FastAPI Server + Textual TUI + VSCode插件
三个模块按顺序实施,424测试全绿:

模块A - 多语言支持:
- ast-grep预定义模板查询(LLM只填参数不写pattern)
- TreeSitterParser扩展支持JS/TS/Go/Rust/Java(可选依赖)
- 多语言Verifier(jest/go test/cargo test/mvn test)
- 4个新SKILL.md(golang/typescript/rust/java)

模块B - Server + TUI:
- FastAPI + SSE事件流,端口7355
- kwcode serve命令 + kwcode --tui选项
- Textual TUI(文件树+事件流+输入框)
- pipeline_factory共享构建

模块C - VSCode插件:
- 薄客户端连接kwcode server
- SSE事件流 + Webview面板
- 文件保存触发RIG刷新

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 14:57:16 +08:00
Val-sss
0f3c9e6e61 feat: v1.3.0 架构升级 — EventBus/ToolGateway/错误策略路由/认知门控/渐进压缩/Wink自修复/SearchRouter
10个模块实现:
- EventBus 统一事件总线(append-only日志+replay)
- ToolGateway 专家权限隔离(deny-first+文件缓存)
- 错误策略路由(按error_type切换重试序列+import_fixer确定性修复)
- CognitiveGate 认知门控(patch行数递减检测边际收益递减)
- GraduatedCompactor 3层渐进压缩(70%/85%/95%)
- Plan自动触发(hard任务自动生成计划)
- Worktree隔离(/multi并行任务文件隔离)
- Speculative Prefetch(Locator后台预读文件)
- SearchRouter意图感知搜索(arxiv/S2/GitHub/PyPI/Open-Meteo零key)
- Wink自修复监控(偏离检测+课程纠正)

搜索层网络保护:
- DDG为主SearXNG可选,不自动拉Docker
- search_enabled开关,内网用户可完全禁用网络请求
- 所有搜索异常静默处理不阻塞流水线

357/357 tests passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 13:39:00 +08:00
Val-sss
d3d85c804c feat: P2 watchdog + gate accuracy report; remove .bak file
- P2-1: Task-level watchdog (300s timeout via threading.Timer, auto-abort stuck tasks)
- P2-2: Gate routing accuracy report (/stats command, per-expert_type success rate)
- Remove vision_expert.py.bak (keep vision_expert.py as intended feature)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 11:54:18 +08:00
Val-sss
ce8646f57e feat: P0+P1 optimization — circuit breaker, gate confidence, experience replay, session state
- P0-1: Verifier structured error output (error_type/file/line/message extraction)
- P0-2: Circuit breaker + scope narrowing (syntax/import fast-break, 3x same-error hard-break, auto-narrow on 2nd failure)
- P0-3: Gate confidence estimation (keyword signal scoring, low-confidence retry reduction)
- P1-1: Experience Replay via BM25 trajectory similarity search
- P1-2: SessionState multi-turn coherence + attention decay countermeasure
- P1-3: Locator minimal context extraction (function boundary detection, comment stripping, 60-line cap)
- Add CONTRIBUTING.md with architecture red lines and PR standards
- Update README contributing section with quick reference

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 11:39:45 +08:00
dashitongzhi
a3a133df2a merge: sync with upstream/master 2026-05-01 22:40:47 +08:00
YonghaoZhao722
0ee3d989a4 feat: improve error handling user experience
Enhanced 4 critical error messages with better context and actionable solutions:

1. Model call failure:
   - Add detailed error context
   - Provide 4 solution steps (check model, switch model, verify API, check network)
   - Include specific commands for each solution

2. Execution exception:
   - Add debugging suggestions
   - Show log file path (~/.kwcode/kwcode.log)
   - Include full stack trace for troubleshooting
   - Suggest /plan mode and GitHub issue reporting

3. Directory not found:
   - Show attempted path
   - Provide path checking tips
   - Display current directory for reference
   - Include usage example

4. API configuration error:
   - Show complete usage with examples
   - List common API endpoints (Ollama, DeepSeek, SiliconFlow)
   - Clarify temp vs default commands

All error messages now include:
- Clear context (what happened)
- Actionable solutions (what to do)
- Specific examples (how to do it)
- Visual improvements (icons and colors)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 19:23:26 +08:00
dashitongzhi
1488834e71 fix: vision expert improvements from code review
- Multi-image support: iterate all images, track failures per image
- Media type detection: suffix-based with base64 fallback
- Ollama native vision support (images field)
- URLError/TimeoutError handling in API calls
- Shell injection prevention (shlex.quote)
- Path validation: expanduser + is_file checks
- Gate: explicit [图片:] marker routing to vision
- Context: image_paths/image_path fields on TaskContext
- CLI: vision spinner, skip decompose/plan/search for vision
- CLI: resolve relative image paths against project root
- CLI: fix no_search propagation in REPL
2026-04-30 11:56:44 +08:00
dashitongzhi
b2e9d33164 feat: add multimodal vision expert for image analysis and code generation
- VisionExpert class: image analysis + code generation from images
- Anthropic Messages API integration (mimo-v2-omni model)
- Gate classifier: new 'vision' expert type
- Orchestrator: vision pipeline with image_paths support
- CLI: /paste (clipboard) and /image (file) commands
- Optional deps: pip install kwcode[multimodal] (Pillow + pyperclip)
- Architecture diagram in docs/
2026-04-30 11:46:49 +08:00
Val-sss
e32a43982b fix: wire up 4 remaining walkthrough issues
1. TrajectoryCollector.get_by_expert() — method was missing, ab_tester
   called it on expert graduation. Added to trajectory_collector.py.

2. auto_decompose integrated into _run_task() — hard tasks now auto-split
   via Planner.auto_decompose() + _handle_multi_with_tasks() helper.

3. Pre-search (P1-B) wired into _run_task() — Gate needs_search=true
   triggers QueryGenerator + ddg_search before orchestrator.run(),
   results passed via pre_search_results parameter.

4. session_md.save_session() wired into REPL exit — SESSION.md now
   written on vram_watcher.stop() with recent task summaries.

All 4 issues from WALKTHROUGH_REPORT.md resolved.
311 tests passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-30 03:52:33 +08:00
Val-sss
723574cb34 fix: resolve 8 code review issues (dead code, race conditions, data errors)
Issues fixed:
1. DebugSubagent now instantiated and injected into orchestrator (was dead code)
2. PromptOptimizer now triggered on expert graduation (was never called)
3. Reranker: already gracefully degrades, no change needed (documented)
4. Checkpoint race condition: skip_checkpoint=True in multi-task mode
5. Hard tasks: TaskPlanner already exists, needs CLI integration (next step)
6. force_plan_mode: now overridable (no_search flag disables it)
7. conversation_history: stores real LLM output instead of user_input
8. Multi-language AST: already correctly scoped to Python-only (no false claims)

Also: mock_run signature updated in test_task_compiler.py for skip_checkpoint param.

311 tests passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-30 02:55:49 +08:00
Val-sss
c0ec272925 fix: LLMBackend auto-detect OpenAI-compatible API vs Ollama
Problem: user configures base_url as https://api.deepseek.com during
onboarding, but LLMBackend hardcodes /api/chat (Ollama endpoint),
resulting in 404 errors on cloud APIs.

Solution: auto-detect based on URL pattern:
  - localhost:11434 → Ollama (/api/chat)
  - Cloud domains (deepseek/siliconflow/openai/groq/etc) → OpenAI compat (/v1/chat/completions)
  - Remote non-localhost → OpenAI compat
  - URL containing /v1 → OpenAI compat

Also:
  - Pass api_key from config to LLMBackend
  - New _chat_openai_compat() method handles OpenAI format (Authorization header, standard payload)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-29 19:44:08 +08:00
Val-sss
1266591951 feat: add /multi command for serial+parallel multi-task execution
Usage:
  /multi task1 ; task2 ; task3     — parallel (semicolons)
  /multi task1 -> task2 -> task3   — serial chain (arrows)
  /multi                           — interactive mode (> prefix = depends on previous)

Interactive mode example:
  + add comments to func_a        (parallel)
  + add comments to func_b        (parallel)
  + >write tests for both         (serial, depends on t1+t2)

Integrates TaskCompiler DAG scheduler into CLI with:
- Rich spinner progress during execution
- Per-task result summary (files modified / errors)
- Parallel/serial count display before execution

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-29 13:49:08 +08:00
Val-sss
c6197d0316 v0.7.0: P1+P2+搜索重构+UI全面优化
P1: KWCODE.md规则注入、/plan风险评估、Checkpoint快照、DocReader
P2: 模型能力自适应、飞轮通知、价值量化仪表盘
搜索: 四级提取管道、并行搜索+BM25重排、意图感知、ChatExpert门控
UI: spinner动画、结果摘要、静默日志、重影大字Header
新增: kwcode setup-search 一键安装SearXNG
测试: 282/282 PASS (含17个E2E真实模型测试)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-28 17:52:59 +08:00
Val-sss
8660e26b1a Rename CLI command kaiwu → kwqode
- Entry point: kwqode = "kaiwu.cli.main:app"
- Display name: KwQode (banners, help, REPL prompt)
- MCP tool: kwqode_execute
- Python package name kaiwu/ and imports unchanged
- .kaiwu/ config dir and KAIWU.md unchanged

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-27 10:01:04 +08:00
Val-sss
5e6a4096a8 China network optimization: proxy, Bing fallback, ModelScope auto-switch
Three-layer China network support:
1. Model download: auto-detect HuggingFace connectivity, switch to
   ModelScope when unreachable. MODELSCOPE_MODELS mapping added.
2. Search: DDG primary, auto-fallback to cn.bing.com HTML scraping
   when DDG fails (SEARCH-RED-5 revised). Zero API keys.
3. Fetch: all httpx calls now support KAIWU_PROXY/HTTPS_PROXY env var
   and ~/.kaiwu/config.yaml proxy field.

New module: kaiwu/core/network.py — unified network detection + proxy config.
CLI shows network status hint on startup when China network detected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-27 09:48:49 +08:00
Val-sss
8b9b1b8bec Add --no-search flag and memory reset command
- CLI: --no-search disables search augmentation on retries
- CLI: kaiwu memory --reset clears .kaiwu/ directory
- Orchestrator: no_search parameter skips SearchAugmentor

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-27 01:12:36 +08:00
Val-sss
5668419bdf Kaiwu v0.4: expert registry, flywheel, 3-layer memory, MCP router
Major additions:
- Expert registry with 12 builtin experts (keyword matching, lifecycle)
- 3-layer memory system (PROJECT.md / EXPERT.md / PATTERN.md)
- Expert flywheel (trajectory → pattern → generate → 3-gate → lifecycle)
- Expert packaging (.kwx import/export)
- KaiwuMCP Router (single kaiwu_execute tool)
- CLI subcommands: expert list/info/export/install/remove/create, status, serve-mcp
- V5/V6 validation script frameworks
- Install scripts (install.ps1 + install.sh) with Chinese mirror support
- README_zh.md Chinese documentation

Verified: 24/24 tests pass, E2E fibonacci bug fix (gemma3:4b, 22.4s),
10/10 CORE red line constraints satisfied, Windows cmd native OK.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-27 00:18:04 +08:00
Val-sss
bccd0bb81f Fix Windows GBK console encoding in CLI entry point
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-26 22:23:09 +08:00
Val-sss
67ab00e48a Add interactive REPL mode: kaiwu with no args enters shell
- No args → REPL with prompt, slash commands, persistent pipeline
- /model, /cd, /plan, /memory, /init, /help, /exit
- Single task mode (kaiwu "fix bug") unchanged
- Status callback always shown in REPL for better UX

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-26 20:50:25 +08:00
Val-sss
363d5dce36 Kaiwu v3 MVP: deterministic expert pipeline for local-model coding agent
Gate(JSON routing) → Locator → Generator → Verifier → KAIWU.md memory.
E2E validated with gemma3:4b (5.7s, 5/5 tests passed).
V1 Gate: 100% JSON parse rate. V3 Locator: 90% file accuracy.
Reasoning model compat (deepseek-r1): stop param + token budget fixes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-26 12:47:34 +08:00