feihong-code 0.2.2 → 0.5.1

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.
Files changed (152) hide show
  1. package/.github/FUNDING.yml +4 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +37 -37
  3. package/.github/ISSUE_TEMPLATE/config.yml +14 -14
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +28 -28
  5. package/.github/PULL_REQUEST_TEMPLATE.md +46 -46
  6. package/.github/SECURITY.md +67 -67
  7. package/.github/dependabot.yml +16 -0
  8. package/.github/workflows/ci.yml +1 -1
  9. package/AGENT-GUIDE.md +382 -237
  10. package/CHANGELOG.md +405 -73
  11. package/CODE_OF_CONDUCT.md +56 -56
  12. package/CONTRIBUTING.md +68 -68
  13. package/LICENSE +22 -22
  14. package/README.md +31 -25
  15. package/README.self-evolve.md +274 -0
  16. package/dist/agent/code-review.js +2 -0
  17. package/dist/agent/code-review.js.map +1 -1
  18. package/dist/agent/code-writer.js +70 -17
  19. package/dist/agent/code-writer.js.map +1 -1
  20. package/dist/agent/context-compactor.js +13 -4
  21. package/dist/agent/context-compactor.js.map +1 -1
  22. package/dist/agent/experience.js +262 -62
  23. package/dist/agent/experience.js.map +1 -1
  24. package/dist/agent/orchestrator.js +148 -68
  25. package/dist/agent/orchestrator.js.map +1 -1
  26. package/dist/agent/quality-gate.js +10 -4
  27. package/dist/agent/quality-gate.js.map +1 -1
  28. package/dist/agent/repo-context.js +181 -0
  29. package/dist/agent/repo-context.js.map +1 -0
  30. package/dist/agent/repo-reader.js +92 -99
  31. package/dist/agent/repo-reader.js.map +1 -1
  32. package/dist/agent/self-heal.js +38 -48
  33. package/dist/agent/self-heal.js.map +1 -1
  34. package/dist/agent/self-improver.js +65 -61
  35. package/dist/agent/self-improver.js.map +1 -1
  36. package/dist/agent/subagent-summary.js +31 -0
  37. package/dist/agent/subagent-summary.js.map +1 -0
  38. package/dist/agent/subagent.js +52 -2
  39. package/dist/agent/subagent.js.map +1 -1
  40. package/dist/agent/symbol-index.js +160 -0
  41. package/dist/agent/symbol-index.js.map +1 -0
  42. package/dist/agent/team.js +193 -0
  43. package/dist/agent/team.js.map +1 -0
  44. package/dist/cli/commands.js +124 -143
  45. package/dist/cli/commands.js.map +1 -1
  46. package/dist/cli/index.js +113 -106
  47. package/dist/cli/index.js.map +1 -1
  48. package/dist/cli/repl.js +82 -7
  49. package/dist/cli/repl.js.map +1 -1
  50. package/dist/cli/run.js +601 -95
  51. package/dist/cli/run.js.map +1 -1
  52. package/dist/cli/tui.js +145 -0
  53. package/dist/cli/tui.js.map +1 -0
  54. package/dist/cli/version.js +1 -1
  55. package/dist/enterprise/audit.js +75 -12
  56. package/dist/enterprise/audit.js.map +1 -1
  57. package/dist/enterprise/index.js +14 -11
  58. package/dist/enterprise/index.js.map +1 -1
  59. package/dist/enterprise/policy.js +22 -10
  60. package/dist/enterprise/policy.js.map +1 -1
  61. package/dist/harness/executor.js +127 -0
  62. package/dist/harness/executor.js.map +1 -0
  63. package/dist/harness/harness.js +87 -0
  64. package/dist/harness/harness.js.map +1 -0
  65. package/dist/harness/index.js +31 -0
  66. package/dist/harness/index.js.map +1 -0
  67. package/dist/harness/loader.js +138 -0
  68. package/dist/harness/loader.js.map +1 -0
  69. package/dist/harness/reporter.js +34 -0
  70. package/dist/harness/reporter.js.map +1 -0
  71. package/dist/harness/types.js +10 -0
  72. package/dist/harness/types.js.map +1 -0
  73. package/dist/harness/verifier.js +48 -0
  74. package/dist/harness/verifier.js.map +1 -0
  75. package/dist/hello.js +14 -0
  76. package/dist/hello.js.map +1 -0
  77. package/dist/memory/auto-summarize.js +208 -0
  78. package/dist/memory/auto-summarize.js.map +1 -0
  79. package/dist/memory/index.js +228 -0
  80. package/dist/memory/index.js.map +1 -0
  81. package/dist/models/model-router.js +23 -10
  82. package/dist/models/model-router.js.map +1 -1
  83. package/dist/plugins/plugin-loader.js +179 -0
  84. package/dist/plugins/plugin-loader.js.map +1 -0
  85. package/dist/runtime/event-log.js.map +1 -1
  86. package/dist/runtime/hooks.js +80 -0
  87. package/dist/runtime/hooks.js.map +1 -0
  88. package/dist/self-evolve/hook.js +60 -0
  89. package/dist/self-evolve/hook.js.map +1 -0
  90. package/dist/shared/config.js +35 -3
  91. package/dist/shared/config.js.map +1 -1
  92. package/dist/shared/i18n.js +535 -0
  93. package/dist/shared/i18n.js.map +1 -0
  94. package/dist/skills/grill.js +2 -1
  95. package/dist/skills/grill.js.map +1 -1
  96. package/dist/skills/self-heal.js +73 -0
  97. package/dist/skills/self-heal.js.map +1 -0
  98. package/dist/skills/skill-loader.js +131 -0
  99. package/dist/skills/skill-loader.js.map +1 -0
  100. package/dist/skills/skill-market.js +195 -0
  101. package/dist/skills/skill-market.js.map +1 -0
  102. package/dist/tools/analysis/code-analyzer.js +45 -18
  103. package/dist/tools/analysis/code-analyzer.js.map +1 -1
  104. package/dist/tools/index.js +5 -0
  105. package/dist/tools/index.js.map +1 -1
  106. package/dist/tools/mcp/index.js +84 -0
  107. package/dist/tools/mcp/index.js.map +1 -0
  108. package/dist/tools/mcp/mcp-client.js +172 -0
  109. package/dist/tools/mcp/mcp-client.js.map +1 -0
  110. package/dist/tools/sandbox.js +126 -0
  111. package/dist/tools/sandbox.js.map +1 -0
  112. package/dist/tools/shell/exec.js +25 -0
  113. package/dist/tools/shell/exec.js.map +1 -1
  114. package/dist/tools/shell/run-shell.tool.js +4 -1
  115. package/dist/tools/shell/run-shell.tool.js.map +1 -1
  116. package/dist/tools/skills/load-skill.tool.js +36 -0
  117. package/dist/tools/skills/load-skill.tool.js.map +1 -0
  118. package/dist/tools/tool.interface.js.map +1 -1
  119. package/dist/tools/tool.registry.js +37 -1
  120. package/dist/tools/tool.registry.js.map +1 -1
  121. package/dist/tools/web/web.tool.js +139 -0
  122. package/dist/tools/web/web.tool.js.map +1 -0
  123. package/dist/web/auth.js +42 -3
  124. package/dist/web/auth.js.map +1 -1
  125. package/dist/web/channels.js +171 -0
  126. package/dist/web/channels.js.map +1 -0
  127. package/dist/web/public/index.html +3253 -39
  128. package/dist/web/public/index.html.tmp +3117 -0
  129. package/dist/web/public/index_new.html +3196 -0
  130. package/dist/web/server.js +790 -11
  131. package/dist/web/server.js.map +1 -1
  132. package/dist/web/task-queue.js +352 -0
  133. package/dist/web/task-queue.js.map +1 -0
  134. package/dist/web/web-config.js +143 -0
  135. package/dist/web/web-config.js.map +1 -0
  136. package/docs/Deployment_Guide_EN.md +288 -0
  137. package/docs/Technical_Manual_EN.md +216 -0
  138. package/docs/User_Manual_EN.md +314 -0
  139. package/docs/self-evolve-implementation.md +165 -0
  140. package/docs/self-evolve.md +166 -0
  141. package/docs//344/272/247/345/223/201/345/274/200/345/217/221/346/226/207/346/241/243.md +614 -614
  142. package/docs//344/274/201/344/270/232/351/203/250/347/275/262/344/270/216/345/220/210/350/247/204.md +267 -267
  143. package/docs//344/275/277/347/224/250/350/257/264/346/230/216/344/271/246.md +318 -358
  144. package/docs//345/270/270/350/247/201/351/227/256/351/242/230/344/270/216/346/225/205/351/232/234/346/216/222/346/237/245.md +130 -130
  145. package/docs//346/212/200/346/234/257/350/257/264/346/230/216/344/271/246.md +216 -303
  146. package/docs//346/236/266/346/236/204/344/270/216API.md +238 -238
  147. package/docs//347/224/250/346/210/267/346/211/213/345/206/214.md +196 -196
  148. package/docs//351/203/250/347/275/262/346/214/207/345/215/227.md +165 -165
  149. package/docs//351/203/250/347/275/262/350/257/264/346/230/216/344/271/246.md +288 -0
  150. package/docs//351/205/215/347/275/256/345/217/202/350/200/203.md +127 -127
  151. package/package.json +114 -109
  152. package/tool-schema.json +127 -127
@@ -0,0 +1,314 @@
1
+ # Feihong Code (fhcode) — User Manual
2
+
3
+ **Version**: v0.5.0-b
4
+ **Date**: 2026-08-16
5
+ **Product**: Feihong Code (feihong-code) — a terminal AI coding agent (a Muse Code reimplementation)
6
+ **Attribution**: Jinjiang Feihongzhi Tech Enterprise Management Co., Ltd. · Feiyang Qiyuan R&D Center · Lead: Wu Cihong
7
+
8
+ ---
9
+
10
+ ## 1. Quick Start
11
+
12
+ ### 1.1 Requirements
13
+
14
+ - Node.js ≥ 18 (20/22 recommended)
15
+ - npm ≥ 9
16
+ - git (needed for diff/rollback/parallel worktrees)
17
+ - Docker (only for `FH_SANDBOX_MODE=container`)
18
+
19
+ ### 1.2 Installation
20
+
21
+ ```bash
22
+ # Option A: build from source (recommended)
23
+ git clone https://github.com/wch887292/feihong-code.git
24
+ cd feihong-code
25
+ npm install
26
+ npm run build
27
+
28
+ # Option B: npm global install
29
+ npm install -g feihong-code
30
+ fhcode --version # verify
31
+ ```
32
+
33
+ ### 1.3 Up and Running in Seconds
34
+
35
+ ```bash
36
+ # Without a model configured, offline mode (Mock-driven loop) is used automatically
37
+ fhcode "write a hello.ts"
38
+
39
+ # Configure a real model (DeepSeek example) to go live
40
+ export FH_PROVIDERS='[{"name":"deepseek","type":"openai-compatible","baseUrl":"https://api.deepseek.com/v1","apiKey":"sk-...","tags":["code-gen","reasoning"],"priority":1}]'
41
+ fhcode "fix the token validation bug in src/auth.ts"
42
+ ```
43
+
44
+ ---
45
+
46
+ ## 2. Command Reference
47
+
48
+ ```bash
49
+ # Basics
50
+ fhcode Enter interactive REPL (TUI enabled on TTY)
51
+ fhcode "<request>" Run a single request
52
+ fhcode --stream "<request>" Stream output (live task progress)
53
+ fhcode --yes "<request>" Skip approvals (use with care)
54
+ fhcode --lang zh|en Set UI language
55
+
56
+ # Read-only skills
57
+ fhcode /plan "<goal>" Generate an implementation plan
58
+ fhcode /grill [path] Red-team code review (text)
59
+ fhcode review [path] [--json] Structured code review (--json for IDE/CI)
60
+ fhcode /goal "<goal>" Decompose and save a high-level goal
61
+
62
+ # Session management (M3)
63
+ fhcode sessions List historical sessions
64
+ fhcode resume <id> Resume from checkpoint
65
+ fhcode diff [id] Show session/workspace diff
66
+ fhcode rollback <id> --yes Roll back session changes (destructive)
67
+
68
+ # Enterprise (M4)
69
+ fhcode whoami Current tenant/user/role/quota
70
+ fhcode policy Show active RBAC policy
71
+ fhcode audit [verify] Audit records / hash-chain verification
72
+ fhcode tenants Tenant usage summary
73
+
74
+ # Self-evolution (M6/M8/M9)
75
+ fhcode model-stats Model performance stats
76
+ fhcode experiences [path] Experience library
77
+ fhcode code-write "<goal>" Autonomous coding
78
+ fhcode quality-gate [path] Quality-gate review
79
+ fhcode self-improve Self-improvement stats
80
+ fhcode swe "<goal>" Fully autonomous SWE agent
81
+ fhcode team "<goal>" Multi-agent collaboration (shared board + message bus)
82
+
83
+ # Ecosystem
84
+ fhcode skill-market search "<keyword>" Search the skills marketplace (agentskills.io)
85
+ fhcode skill-market install <name> Install a skill
86
+ fhcode skill-market list List local skills
87
+ fhcode plugin install <dir|git-url> Install a plugin
88
+ fhcode plugin list List plugins
89
+ fhcode doctor Environment self-check
90
+ ```
91
+
92
+ **Useful flags**: `--parallel` (parallel worktrees) / `--repo` (swe target repo / marketplace source) / `--context-file <path>` (attach a file as context) / `--max-iterations N` / `--max-retries N` / `--plan-only` / `--verify-only` / `--json`.
93
+
94
+ ---
95
+
96
+ ## 3. Model Configuration
97
+
98
+ ### 3.1 Priority
99
+
100
+ 1. `FH_PROVIDERS` (JSON array, highest priority)
101
+ 2. `fhcode.config.json` (project config `models.providers`)
102
+ 3. Single env vars `FH_MODEL_*`
103
+
104
+ ### 3.2 Local Ollama
105
+
106
+ ```bash
107
+ export FH_MODEL_NAME=qwen3:8b
108
+ export FH_MODEL_TYPE=ollama
109
+ export FH_MODEL_BASE_URL=http://localhost:11434
110
+ export FH_MODEL_TAGS=code-gen,reasoning,local
111
+ ```
112
+
113
+ ### 3.3 DeepSeek / Qwen
114
+
115
+ ```bash
116
+ # DeepSeek
117
+ export FH_PROVIDERS='[{"name":"deepseek","type":"openai-compatible","baseUrl":"https://api.deepseek.com/v1","apiKey":"sk-...","tags":["code-gen","reasoning"],"costPer1k":0.0001}]'
118
+ # Qwen (Alibaba)
119
+ export FH_PROVIDERS='[{"name":"qwen","type":"openai-compatible","baseUrl":"https://dashscope.aliyuncs.com/compatible-mode/v1","apiKey":"...","tags":["code-gen","long-context"]}]'
120
+ ```
121
+
122
+ ### 3.4 Routing Strategy
123
+
124
+ ```bash
125
+ export FH_MODEL_STRATEGY=cost # cost | capability | latency
126
+ export FH_BUDGET_USD=0.5 # per-task cost cap (circuit breaker)
127
+ ```
128
+ Providers tagged `cheap` are preferred for `swe`/parallel sub-tasks (P1-1 model split).
129
+
130
+ ---
131
+
132
+ ## 4. Typical Workflows
133
+
134
+ ### 4.1 Single Task
135
+
136
+ ```bash
137
+ fhcode "implement an HTTP server listening on port 3000"
138
+ # Streaming + attach a file as context
139
+ fhcode --stream --context-file src/auth.ts "review and fix the security issues in this file"
140
+ ```
141
+
142
+ ### 4.2 Fully Autonomous SWE (swe)
143
+
144
+ ```bash
145
+ fhcode swe "fix the add function bug in src/calc.ts so tests/calc.test.ts passes" \
146
+ --repo /path/to/project \
147
+ --max-tasks 3 --max-iterations 5
148
+ # --plan-only / --verify-only / --max-retries N (self-heal retries)
149
+ ```
150
+
151
+ ### 4.3 Multi-Agent Collaboration (team)
152
+
153
+ ```bash
154
+ fhcode team "implement a login module and a user management module and write integration tests"
155
+ # Goal auto-decomposed → agents claim concurrently → message bus reports → team report
156
+ ```
157
+
158
+ ### 4.4 Skills Marketplace & Plugins
159
+
160
+ ```bash
161
+ fhcode skill-market search "code review"
162
+ fhcode skill-market install code-review # auto-discovered in tasks after install
163
+ fhcode plugin install ./my-plugin # packages skills+hooks+MCP
164
+ ```
165
+
166
+ ### 4.5 Session Resume & Rollback
167
+
168
+ ```bash
169
+ fhcode sessions # find the session id
170
+ fhcode resume <id> # continue after interruption
171
+ fhcode diff <id> # inspect changes
172
+ fhcode rollback <id> --yes # roll back (destructive)
173
+ ```
174
+
175
+ ### 4.6 Environment Self-Check
176
+
177
+ ```bash
178
+ fhcode doctor
179
+ # ✅ Node version / git / model config / network / home dir / sandbox mode
180
+ ```
181
+
182
+ ---
183
+
184
+ ## 5. REPL / TUI
185
+
186
+ ```bash
187
+ fhcode # interactive mode (TUI enabled automatically on TTY)
188
+ ```
189
+ - TUI: sticky header shows mode/runId/iterations/cost/state; content scrolls; wheel to scroll back
190
+ - Type a request and press Enter; `exit`/`quit`/Ctrl+D to leave
191
+ - Slash skills supported: `/plan` `/grill` `/goal`
192
+
193
+ ---
194
+
195
+ ## 6. VSCode Extension
196
+
197
+ Package in `vscode-extension/` (`npx @vscode/vsce package`) or load via F5:
198
+
199
+ | Command | Description |
200
+ |---------|-------------|
201
+ | `fhcode: Run task (with selection context)` | Selected code auto-injected as `<selection>` context |
202
+ | `fhcode: Inline review current file` | `review --json` → inline diagnostics (red/yellow/blue) |
203
+ | `fhcode: View workspace diff` | Native diff editor HEAD↔workspace |
204
+ | `fhcode: Show recent task output` | Focus the Output Channel |
205
+
206
+ Settings: `fhcode.binaryPath` / `fhcode.offline` / `fhcode.reviewOnSave` (auto-review on save, default on).
207
+
208
+ ---
209
+
210
+ ## 7. Web Console (Cloud Execution)
211
+
212
+ ```bash
213
+ fhcode serve --port 8080
214
+ # open http://localhost:8080 in a browser
215
+ ```
216
+
217
+ **Task panel**: enter the token (printed by the terminal as `FH_WEB_TOKEN`) → submit a goal → poll status → expand result details.
218
+
219
+ **API usage** (Bearer auth):
220
+
221
+ ```bash
222
+ TOKEN=$(echo $FH_WEB_TOKEN)
223
+ # submit a task
224
+ curl -X POST http://localhost:8080/api/tasks \
225
+ -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
226
+ -d '{"goal":"write a hello.ts"}'
227
+ # query
228
+ curl http://localhost:8080/api/tasks -H "Authorization: Bearer $TOKEN"
229
+ curl http://localhost:8080/api/tasks/<id> -H "Authorization: Bearer $TOKEN"
230
+ # register a webhook (task-status callback, schedulable by CI)
231
+ curl -X POST http://localhost:8080/api/webhook \
232
+ -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
233
+ -d '{"url":"https://your-ci.example.com/hook"}'
234
+ ```
235
+
236
+ ---
237
+
238
+ ## 8. Message Channels
239
+
240
+ ```bash
241
+ # Telegram notifications (task status changes)
242
+ export FH_CHANNEL_TELEGRAM_BOT_TOKEN=bot:xxx
243
+ export FH_CHANNEL_TELEGRAM_CHAT_ID=12345
244
+ # WeCom group bot (multiple keys)
245
+ export FH_CHANNEL_WECOM_KEY=key1,key2
246
+ # Outbound allowlist (optional; once set, only allowlisted channels may send)
247
+ export FH_CHANNEL_ALLOW=telegram,wecom
248
+ ```
249
+
250
+ ---
251
+
252
+ ## 9. Sandbox & Safe Usage
253
+
254
+ ```bash
255
+ export FH_SANDBOX_MODE=workspace-write # default
256
+ export FH_SANDBOX_MODE=read-only # read-only survey (no writes/exec)
257
+ export FH_SANDBOX_MODE=danger-full-access # full access (dangerous commands still blocked)
258
+ export FH_SANDBOX_MODE=container # run shell inside a Docker container
259
+ export FH_SANDBOX_IMAGE=node:22-alpine # container image
260
+
261
+ # Network domain rules
262
+ export FH_NETWORK_DENY=evil.example.com
263
+ # export FH_NETWORK_ALLOW=api.example.com
264
+
265
+ # Deterministic hooks (PreToolUse non-zero exit blocks)
266
+ export FH_HOOKS='[{"event":"PreToolUse","command":"node scripts/guard.js","tools":["run_shell"]}]'
267
+ ```
268
+
269
+ ---
270
+
271
+ ## 10. eval Benchmark & Regression Gate
272
+
273
+ ```bash
274
+ # Local benchmark (5 scenarios + 5 acceptance tasks, real-artifact verification)
275
+ npm run build && npm run eval
276
+
277
+ # Save baseline + compare gate (fails when below baseline; CI-ready)
278
+ node scripts/eval.mjs --save-baseline bench/eval-baseline.json
279
+ node scripts/eval.mjs --baseline bench/eval-baseline.json
280
+
281
+ # SWE-bench dataset loading (HF or mirror)
282
+ node scripts/eval-swebench.mjs --split lite --limit 5
283
+ node scripts/eval-swebench.mjs --split lite --limit 5 --run --report report.md
284
+ FH_SWEBENCH_DATA_URL=https://mirror.example/swebench.json node scripts/eval-swebench.mjs --limit 3
285
+ ```
286
+
287
+ ---
288
+
289
+ ## 11. FAQ
290
+
291
+ | Problem | Solution |
292
+ |---------|----------|
293
+ | Real mode wanted without model config | Set `FH_PROVIDERS` or `FH_MODEL_NAME` to leave offline mode |
294
+ | Task aborted by cost cap | Raise `FH_BUDGET_USD` or role `maxCostUsd`, resume with `fhcode resume` |
295
+ | Quota rejected (QUOTA_EXCEEDED) | Adjust `FH_TENANT_BUDGET_USD` or policy `tenantDailyBudgetUsd` |
296
+ | review returns empty | Confirm the path is a file/dir with supported extensions (ts/js/tsx/jsx/json/md/py/go/java) |
297
+ | Marketplace fetch fails | Check network or set `FH_SWEBENCH_DATA_URL` / `--repo` mirror |
298
+ | Switch language | `fhcode --lang en` or `FHCODE_LANG=en` |
299
+
300
+ ---
301
+
302
+ ## 12. Troubleshooting & Logs
303
+
304
+ ```bash
305
+ export FH_LOG_LEVEL=debug # verbose logs
306
+ fhcode doctor # environment self-check
307
+ fhcode audit verify # audit chain integrity
308
+ # Event logs: ~/.feihong-code/sessions/<runId>.jsonl
309
+ # Checkpoints: ~/.feihong-code/sessions/<runId>.session.json
310
+ ```
311
+
312
+ ---
313
+
314
+ *Full configuration reference: see Configuration Reference and Deployment Guide; error codes: see FAQ & Troubleshooting.*
@@ -0,0 +1,165 @@
1
+ # Self-Evolve 实现指南
2
+
3
+ ## 核心架构
4
+
5
+ ```
6
+ ┌─────────────────────────────────────────────────────────────┐
7
+ │ Self-Evolve Manager │
8
+ ├─────────────────────────────────────────────────────────────┤
9
+ │ • failures.json - 失败记录存储 │
10
+ │ • skills-index.json - 技能索引 │
11
+ │ • history.json - 操作历史 │
12
+ │ • config.json - 配置参数 │
13
+ └─────────────────────────────────────────────────────────────┘
14
+
15
+
16
+ ┌─────────────────────────────────────────────────────────────┐
17
+ │ Hook System │
18
+ ├─────────────────────────────────────────────────────────────┤
19
+ │ • onToolFailure() - 工具调用失败时触发 │
20
+ │ • onTaskComplete() - 任务完成时触发 │
21
+ │ • dailyReview() - 每日自动复盘 │
22
+ └─────────────────────────────────────────────────────────────┘
23
+
24
+
25
+ ┌─────────────────────────────────────────────────────────────┐
26
+ │ CLI Interface │
27
+ ├─────────────────────────────────────────────────────────────┤
28
+ │ • self-evolve init - 初始化系统 │
29
+ │ • self-evolve status - 查看状态 │
30
+ │ • self-evolve failures - 管理失败记录 │
31
+ │ • self-evolve skills - 管理技能库 │
32
+ │ • self-evolve review - 定期复盘 │
33
+ │ • self-evolve analyze - 分析错误模式 │
34
+ │ • self-evolve create-skill - 创建新技能 │
35
+ └─────────────────────────────────────────────────────────────┘
36
+ ```
37
+
38
+ ## 数据模型
39
+
40
+ ### 失败记录 (failure.json)
41
+ ```json
42
+ {
43
+ "id": "uuid",
44
+ "timestamp": "ISO时间",
45
+ "task": "任务描述",
46
+ "error_type": "错误类型",
47
+ "error_message": "错误信息",
48
+ "attempted_solutions": [],
49
+ "root_cause": "根本原因",
50
+ "solution": "解决方案",
51
+ "created_skill": false,
52
+ "skill_name": null,
53
+ "status": "pending|resolved|manual"
54
+ }
55
+ ```
56
+
57
+ ### 技能索引 (skills-index.json)
58
+ ```json
59
+ {
60
+ "name": "技能名称",
61
+ "description": "技能描述",
62
+ "triggers": ["触发词"],
63
+ "error_pattern": "错误模式",
64
+ "solution": "解决方案",
65
+ "created_at": "创建时间",
66
+ "usage_count": 0,
67
+ "version": "1.0.0"
68
+ }
69
+ ```
70
+
71
+ ## 集成到主流程
72
+
73
+ ### 1. 在工具调用链中添加 Hook
74
+
75
+ 在 `src/tools/` 下的工具调用失败时:
76
+
77
+ ```typescript
78
+ // 示例:在 shell 工具中
79
+ try {
80
+ const result = await executeCommand(command);
81
+ // 成功处理
82
+ } catch (error) {
83
+ // 记录失败
84
+ selfEvolveHook.onToolFailure({
85
+ tool: 'shell',
86
+ input: { command },
87
+ error: error.message,
88
+ attemptedSolutions: []
89
+ });
90
+ throw error;
91
+ }
92
+ ```
93
+
94
+ ### 2. 在任务完成时检查
95
+
96
+ ```typescript
97
+ // 在任务完成后
98
+ selfEvolveHook.onTaskComplete({
99
+ success: isSuccess,
100
+ task: taskDescription,
101
+ error: error?.message
102
+ });
103
+ ```
104
+
105
+ ### 3. 定期复盘
106
+
107
+ 可以设置 cron job 或定时任务:
108
+
109
+ ```bash
110
+ # 每天凌晨2点复盘
111
+ 0 2 * * * fhcode self-evolve review --daily
112
+ ```
113
+
114
+ ## 扩展开发
115
+
116
+ ### 添加新的错误类型
117
+
118
+ 在 `manager.js` 的 `categorizeError` 方法中添加:
119
+
120
+ ```javascript
121
+ if (msg.includes('新的错误关键词')) {
122
+ return 'new-error-type';
123
+ }
124
+ ```
125
+
126
+ ### 创建自定义 Hook
127
+
128
+ ```typescript
129
+ class CustomHook {
130
+ onToolFailure(context) {
131
+ // 自定义逻辑
132
+ this.manager.recordFailure(...);
133
+ }
134
+ }
135
+ ```
136
+
137
+ ## 最佳实践
138
+
139
+ 1. **及时记录**:失败后立即记录,不要延迟
140
+ 2. **详细上下文**:记录完整的错误信息和复现步骤
141
+ 3. **尝试多种方案**:记录所有尝试过的解决方案
142
+ 4. **定期复盘**:每天至少一次复盘分析
143
+ 5. **渐进改进**:每次只优化一个方面
144
+
145
+ ## 故障排除
146
+
147
+ ### 数据丢失
148
+ - 检查 `~/.feihong-code/self-evolve/` 目录权限
149
+ - 确保有写入权限
150
+
151
+ ### 技能未生效
152
+ - 检查技能索引是否正确更新
153
+ - 确认 SKILL.md 文件格式正确
154
+ - 重启系统重新加载技能
155
+
156
+ ### 复盘失败
157
+ - 检查配置文件是否存在
158
+ - 确认磁盘空间充足
159
+ - 查看日志文件获取详细错误
160
+
161
+ ## 版本兼容性
162
+
163
+ - Node.js >= 18.0.0
164
+ - TypeScript >= 5.0
165
+ - 飞虹 Code >= 0.5.0
@@ -0,0 +1,166 @@
1
+ # Self-Evolve 自我迭代系统
2
+
3
+ ## 概述
4
+
5
+ Self-Evolve 是飞虹 Code 的自我学习与迭代升级系统,能够:
6
+ - 自动记录任务执行中的失败
7
+ - 分析错误模式并提取经验教训
8
+ - 当遇到无法解决的问题时,自动生成新技能
9
+ - 定期复盘优化系统行为
10
+
11
+ ## 快速开始
12
+
13
+ ### 1. 初始化系统
14
+
15
+ ```bash
16
+ # 运行初始化脚本
17
+ bash scripts/self-evolve-setup.sh
18
+
19
+ # 或使用 CLI
20
+ fhcode self-evolve init
21
+ ```
22
+
23
+ ### 2. 查看状态
24
+
25
+ ```bash
26
+ fhcode self-evolve status
27
+ ```
28
+
29
+ 输出示例:
30
+ ```
31
+ 📊 自我迭代系统状态
32
+ ========================================
33
+ 总失败记录: 15
34
+ 已解决: 12
35
+ 待处理: 3
36
+ 解决率: 80.0%
37
+ 技能库: 5 个技能
38
+ ```
39
+
40
+ ### 3. 列出失败记录
41
+
42
+ ```bash
43
+ # 列出所有失败
44
+ fhcode self-evolve failures list
45
+
46
+ # 按类型过滤
47
+ fhcode self-evolve failures list --type compile-error
48
+
49
+ # 最近7天
50
+ fhcode self-evolve failures list --days 7
51
+ ```
52
+
53
+ ### 4. 查看技能库
54
+
55
+ ```bash
56
+ fhcode self-evolve skills list
57
+ ```
58
+
59
+ ### 5. 每日复盘
60
+
61
+ ```bash
62
+ fhcode self-evolve review --daily
63
+ ```
64
+
65
+ ### 6. 分析错误模式
66
+
67
+ ```bash
68
+ # 分析最近7天
69
+ fhcode self-evolve analyze
70
+
71
+ # 分析最近30天
72
+ fhcode self-evolve analyze --days 30
73
+ ```
74
+
75
+ ### 7. 创建新技能
76
+
77
+ 当遇到新的错误模式时:
78
+
79
+ ```bash
80
+ fhcode self-evolve create-skill \
81
+ --name path-traversal-handler \
82
+ --description "处理路径穿越错误" \
83
+ --pattern path-error \
84
+ --solution "检查路径安全性,确保在workspace范围内" \
85
+ --triggers "path traversal, outside workspace, EACCES"
86
+ ```
87
+
88
+ ## 数据存储
89
+
90
+ 所有数据存储在 `~/.feihong-code/self-evolve/` 目录:
91
+
92
+ ```
93
+ ~/.feihong-code/self-evolve/
94
+ ├── config.json # 配置文件
95
+ ├── failures.json # 失败记录
96
+ ├── skills-index.json # 技能索引
97
+ ├── history.json # 操作历史
98
+ ├── version.txt # 版本信息
99
+ └── report-YYYY-MM-DD.json # 每日报告
100
+ ```
101
+
102
+ 技能文件存储在 `~/.feihong-code/skills/<skill-name>/SKILL.md`
103
+
104
+ ## 工作原理
105
+
106
+ ### 失败记录流程
107
+
108
+ 1. 任务执行失败 → 自动记录到 failures.json
109
+ 2. 搜索已知解决方案 → 找到则应用
110
+ 3. 未找到 → 标记为待处理
111
+ 4. 用户手动解决或系统自动创建技能
112
+ 5. 定期复盘优化
113
+
114
+ ### 技能创建流程
115
+
116
+ 1. 检测新的错误模式
117
+ 2. 分析根因
118
+ 3. 生成解决方案
119
+ 4. 创建 SKILL.md 文件
120
+ 5. 更新技能索引
121
+ 6. 验证效果
122
+
123
+ ## 扩展开发
124
+
125
+ ### 添加自定义 Hook
126
+
127
+ 在 `src/self-evolve/hook.ts` 中扩展:
128
+
129
+ ```typescript
130
+ export class SelfEvolveHook {
131
+ onToolFailure(context) { /* 自定义逻辑 */ }
132
+ onTaskComplete(context) { /* 自定义逻辑 */ }
133
+ }
134
+ ```
135
+
136
+ ### 集成到主流程
137
+
138
+ 在工具调用链中添加钩子:
139
+
140
+ ```typescript
141
+ // 在工具调用失败时
142
+ selfEvolveHook.onToolFailure({
143
+ tool: 'shell',
144
+ input: { command: 'npm test' },
145
+ error: new Error('test failed')
146
+ });
147
+ ```
148
+
149
+ ## 纪律
150
+
151
+ - 诚实记录失败,不伪造成功
152
+ - 每日至少一次复盘
153
+ - 新技能必须经过验证
154
+ - 所有变更可追溯
155
+
156
+ ## 与现有系统集成
157
+
158
+ Self-Evolve 可以与以下技能配合:
159
+
160
+ - `/self-heal`:自动创建修复技能
161
+ - `/plan`:计划时参考历史失败
162
+ - `/goal`:目标设定参考迭代进度
163
+
164
+ ## 版本历史
165
+
166
+ - v1.0.0 (2026-08-16): 初始版本,基础功能完成