5 Commits

Author SHA1 Message Date
Val-sss
8874de74a3 feat: add detailed attempts list to trajectory records
Each retry attempt now records llm_prompt_tail, llm_raw_output,
llm_caller, patches_count, patch_apply_ok/error, modified_lines,
tests_passed/total, test_output_tail, and error_type. This enables
precise post-hoc diagnosis without re-running benchmarks.

Also fixes test_audit_model.py to use correct module-level constants
(LOGS_SUCCESS/LOGS_FAILED/LOGS_LEGACY instead of removed LOGS_DIR).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-08 09:22:47 +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
129eed76d0 feat: P0 Hashline anchors + P1 AdaptThink + P2 Fast/Slow dual-phase
P0 Hashline (tools/hashline.py):
- Content-hash anchored editing: 6-char MD5 per line
- Model outputs EDIT/DELETE/INSERT_AFTER instructions, not full functions
- Hash mismatch → reject entire edit batch (stale file protection)
- Generator tries hashline first, falls back to full-function on failure

P1 AdaptThink (core/think_config.py):
- Gate-driven think budget per expert_type × difficulty
- easy=off, medium=512, hard=2048-4096, chat=always off
- Generator adjusts max_tokens based on think_config

P2 Fast/Slow (orchestrator retry loop):
- First attempt: fast (think=off, low tokens)
- First failure: escalate to slow (think=on, budget=2048)
- Second failure: max budget (4096)
- Orthogonal to retry_strategy (0→1→2)

Tests: 21 new (12 hashline + 8 think + 1 fast/slow), 40 total green

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-06 20:00:11 +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
dashitongzhi
d835d9b640 test: add unit tests for vision expert routing and config
- _should_execute_code: compound phrase matching (10 tests)
- _is_codegen_task: verb+target combos (10 tests)
- _vision_api_configured: requires URL AND MODEL (5 tests)
- temp directory lifecycle and cleanup (4 tests)
- media-type detection via magic bytes and base64 (12 tests)
- _validate_image edge cases (4 tests)
- run routing: no image / too many images (2 tests)
- LLM fallback to Anthropic API (2 tests)
- _media_type_for_path fallback chain (3 tests)
- init, validate_image_path, get_image_info (6 tests)

Total: 59 test cases, all passing.
2026-05-01 22:45:35 +08:00