feihong-code 0.2.3 → 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.
- package/.github/FUNDING.yml +4 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +37 -37
- package/.github/ISSUE_TEMPLATE/config.yml +14 -14
- package/.github/ISSUE_TEMPLATE/feature_request.md +28 -28
- package/.github/PULL_REQUEST_TEMPLATE.md +46 -46
- package/.github/SECURITY.md +67 -67
- package/.github/dependabot.yml +16 -0
- package/.github/workflows/ci.yml +1 -1
- package/AGENT-GUIDE.md +382 -237
- package/CHANGELOG.md +405 -73
- package/CODE_OF_CONDUCT.md +56 -56
- package/CONTRIBUTING.md +68 -68
- package/LICENSE +22 -22
- package/README.md +527 -522
- package/README.self-evolve.md +274 -0
- package/dist/agent/code-review.js +2 -0
- package/dist/agent/code-review.js.map +1 -1
- package/dist/agent/code-writer.js +70 -17
- package/dist/agent/code-writer.js.map +1 -1
- package/dist/agent/context-compactor.js +13 -4
- package/dist/agent/context-compactor.js.map +1 -1
- package/dist/agent/experience.js +262 -62
- package/dist/agent/experience.js.map +1 -1
- package/dist/agent/orchestrator.js +148 -68
- package/dist/agent/orchestrator.js.map +1 -1
- package/dist/agent/quality-gate.js +10 -4
- package/dist/agent/quality-gate.js.map +1 -1
- package/dist/agent/repo-context.js +181 -0
- package/dist/agent/repo-context.js.map +1 -0
- package/dist/agent/repo-reader.js +92 -99
- package/dist/agent/repo-reader.js.map +1 -1
- package/dist/agent/self-heal.js +38 -48
- package/dist/agent/self-heal.js.map +1 -1
- package/dist/agent/self-improver.js +65 -61
- package/dist/agent/self-improver.js.map +1 -1
- package/dist/agent/subagent-summary.js +31 -0
- package/dist/agent/subagent-summary.js.map +1 -0
- package/dist/agent/subagent.js +52 -2
- package/dist/agent/subagent.js.map +1 -1
- package/dist/agent/symbol-index.js +160 -0
- package/dist/agent/symbol-index.js.map +1 -0
- package/dist/agent/team.js +193 -0
- package/dist/agent/team.js.map +1 -0
- package/dist/cli/commands.js +124 -143
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/index.js +113 -106
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/repl.js +82 -7
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/run.js +601 -95
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/tui.js +145 -0
- package/dist/cli/tui.js.map +1 -0
- package/dist/cli/version.js +1 -1
- package/dist/enterprise/audit.js +75 -12
- package/dist/enterprise/audit.js.map +1 -1
- package/dist/enterprise/index.js +14 -11
- package/dist/enterprise/index.js.map +1 -1
- package/dist/enterprise/policy.js +22 -10
- package/dist/enterprise/policy.js.map +1 -1
- package/dist/harness/executor.js +127 -0
- package/dist/harness/executor.js.map +1 -0
- package/dist/harness/harness.js +87 -0
- package/dist/harness/harness.js.map +1 -0
- package/dist/harness/index.js +31 -0
- package/dist/harness/index.js.map +1 -0
- package/dist/harness/loader.js +138 -0
- package/dist/harness/loader.js.map +1 -0
- package/dist/harness/reporter.js +34 -0
- package/dist/harness/reporter.js.map +1 -0
- package/dist/harness/types.js +10 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/verifier.js +48 -0
- package/dist/harness/verifier.js.map +1 -0
- package/dist/hello.js +14 -0
- package/dist/hello.js.map +1 -0
- package/dist/memory/auto-summarize.js +208 -0
- package/dist/memory/auto-summarize.js.map +1 -0
- package/dist/memory/index.js +228 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/models/model-router.js +23 -10
- package/dist/models/model-router.js.map +1 -1
- package/dist/plugins/plugin-loader.js +179 -0
- package/dist/plugins/plugin-loader.js.map +1 -0
- package/dist/runtime/event-log.js.map +1 -1
- package/dist/runtime/hooks.js +80 -0
- package/dist/runtime/hooks.js.map +1 -0
- package/dist/self-evolve/hook.js +60 -0
- package/dist/self-evolve/hook.js.map +1 -0
- package/dist/shared/config.js +35 -3
- package/dist/shared/config.js.map +1 -1
- package/dist/shared/i18n.js +535 -0
- package/dist/shared/i18n.js.map +1 -0
- package/dist/skills/grill.js +2 -1
- package/dist/skills/grill.js.map +1 -1
- package/dist/skills/self-heal.js +73 -0
- package/dist/skills/self-heal.js.map +1 -0
- package/dist/skills/skill-loader.js +131 -0
- package/dist/skills/skill-loader.js.map +1 -0
- package/dist/skills/skill-market.js +195 -0
- package/dist/skills/skill-market.js.map +1 -0
- package/dist/tools/analysis/code-analyzer.js +45 -18
- package/dist/tools/analysis/code-analyzer.js.map +1 -1
- package/dist/tools/index.js +5 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/mcp/index.js +84 -0
- package/dist/tools/mcp/index.js.map +1 -0
- package/dist/tools/mcp/mcp-client.js +172 -0
- package/dist/tools/mcp/mcp-client.js.map +1 -0
- package/dist/tools/sandbox.js +126 -0
- package/dist/tools/sandbox.js.map +1 -0
- package/dist/tools/shell/exec.js +25 -0
- package/dist/tools/shell/exec.js.map +1 -1
- package/dist/tools/shell/run-shell.tool.js +4 -1
- package/dist/tools/shell/run-shell.tool.js.map +1 -1
- package/dist/tools/skills/load-skill.tool.js +36 -0
- package/dist/tools/skills/load-skill.tool.js.map +1 -0
- package/dist/tools/tool.interface.js.map +1 -1
- package/dist/tools/tool.registry.js +37 -1
- package/dist/tools/tool.registry.js.map +1 -1
- package/dist/tools/web/web.tool.js +139 -0
- package/dist/tools/web/web.tool.js.map +1 -0
- package/dist/web/auth.js +42 -3
- package/dist/web/auth.js.map +1 -1
- package/dist/web/channels.js +171 -0
- package/dist/web/channels.js.map +1 -0
- package/dist/web/public/index.html +3253 -39
- package/dist/web/public/index.html.tmp +3117 -0
- package/dist/web/public/index_new.html +3196 -0
- package/dist/web/server.js +790 -11
- package/dist/web/server.js.map +1 -1
- package/dist/web/task-queue.js +352 -0
- package/dist/web/task-queue.js.map +1 -0
- package/dist/web/web-config.js +143 -0
- package/dist/web/web-config.js.map +1 -0
- package/docs/Deployment_Guide_EN.md +288 -0
- package/docs/Technical_Manual_EN.md +216 -0
- package/docs/User_Manual_EN.md +314 -0
- package/docs/self-evolve-implementation.md +165 -0
- package/docs/self-evolve.md +166 -0
- package/docs//344/272/247/345/223/201/345/274/200/345/217/221/346/226/207/346/241/243.md +614 -614
- 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
- package/docs//344/275/277/347/224/250/350/257/264/346/230/216/344/271/246.md +318 -358
- 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
- package/docs//346/212/200/346/234/257/350/257/264/346/230/216/344/271/246.md +216 -303
- package/docs//346/236/266/346/236/204/344/270/216API.md +238 -238
- package/docs//347/224/250/346/210/267/346/211/213/345/206/214.md +196 -196
- package/docs//351/203/250/347/275/262/346/214/207/345/215/227.md +165 -165
- package/docs//351/203/250/347/275/262/350/257/264/346/230/216/344/271/246.md +288 -0
- package/docs//351/205/215/347/275/256/345/217/202/350/200/203.md +127 -127
- package/package.json +114 -109
- package/tool-schema.json +127 -127
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
# Feihong Code (fhcode) — Deployment Guide
|
|
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. Deployment Shapes
|
|
11
|
+
|
|
12
|
+
| Shape | Scenario | Components |
|
|
13
|
+
|-------|----------|------------|
|
|
14
|
+
| Standalone CLI | Personal dev / intranet terminal | fhcode CLI (Node.js) |
|
|
15
|
+
| Web service | Team sharing / cloud execution | fhcode serve + task queue |
|
|
16
|
+
| Docker | Containerized / private deployment | Dockerfile + docker-compose |
|
|
17
|
+
| Enterprise private | Multi-tenant / audit / quota | Enterprise mode (FH_ENTERPRISE) |
|
|
18
|
+
| IDE integration | In-editor usage | VSCode extension (thin shell) |
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 2. Requirements
|
|
23
|
+
|
|
24
|
+
| Item | Requirement | Notes |
|
|
25
|
+
|------|-------------|-------|
|
|
26
|
+
| Node.js | ≥ 18 (20/22 recommended) | Runtime |
|
|
27
|
+
| npm | ≥ 9 | Package manager |
|
|
28
|
+
| git | Recommended | diff/rollback/parallel worktrees |
|
|
29
|
+
| Docker | Optional | `FH_SANDBOX_MODE=container` and Docker deployment |
|
|
30
|
+
| Network | Optional | Real model APIs / skills marketplace / HF datasets (offline mode needs no internet) |
|
|
31
|
+
|
|
32
|
+
**Offline deployment notes**: without a model configured, offline mode (Mock-driven) is used automatically with zero external dependencies; model access can point to an intranet Ollama or a private OpenAI-compatible gateway.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 3. Installation & Deployment
|
|
37
|
+
|
|
38
|
+
### 3.1 npm Global Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install -g feihong-code
|
|
42
|
+
fhcode --version
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 3.2 From Source
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/wch887292/feihong-code.git
|
|
49
|
+
cd feihong-code
|
|
50
|
+
npm install
|
|
51
|
+
npm run build # tsc + Web static asset copy
|
|
52
|
+
npm test # 164 unit tests self-check
|
|
53
|
+
node scripts/eval.mjs # local benchmark self-check (10/10)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 3.3 Docker Deployment (Web service)
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# build image
|
|
60
|
+
docker build -t feihong-code .
|
|
61
|
+
|
|
62
|
+
# run the Web console (with task queue)
|
|
63
|
+
docker run -d --name fhcode \
|
|
64
|
+
-p 8080:8080 \
|
|
65
|
+
-e FH_WEB_TOKEN=<your-token> \
|
|
66
|
+
-e FH_PROVIDERS='[{"name":"deepseek","type":"openai-compatible","baseUrl":"https://api.deepseek.com/v1","apiKey":"sk-...","tags":["code-gen"]}]' \
|
|
67
|
+
-v fhcode-data:/root/.feihong-code \
|
|
68
|
+
feihong-code
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 3.4 docker-compose (recommended)
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
# docker-compose.yml
|
|
75
|
+
services:
|
|
76
|
+
fhcode:
|
|
77
|
+
build: .
|
|
78
|
+
ports: ["8080:8080"]
|
|
79
|
+
environment:
|
|
80
|
+
FH_WEB_TOKEN: ${FH_WEB_TOKEN}
|
|
81
|
+
FH_PROVIDERS: ${FH_PROVIDERS} # model config
|
|
82
|
+
FH_TASK_CONCURRENCY: "2" # task concurrency cap
|
|
83
|
+
FH_TASK_PERSIST_DIR: /data/tasks # task persistence (resume after restart)
|
|
84
|
+
FH_ENTERPRISE: "true" # enterprise mode
|
|
85
|
+
volumes:
|
|
86
|
+
- fhcode-data:/data
|
|
87
|
+
- fhcode-home:/root/.feihong-code
|
|
88
|
+
volumes:
|
|
89
|
+
fhcode-data:
|
|
90
|
+
fhcode-home:
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 4. Environment Variable Reference (full)
|
|
96
|
+
|
|
97
|
+
### 4.1 App & Paths
|
|
98
|
+
|
|
99
|
+
| Variable | Default | Description |
|
|
100
|
+
|----------|---------|-------------|
|
|
101
|
+
| `FH_HOME` | `~/.feihong-code` | Home dir (sessions/audit/experience/stats/cache) |
|
|
102
|
+
| `FH_LOG_DIR` | `$FH_HOME/sessions` | Session log dir (`~` expansion supported) |
|
|
103
|
+
| `FH_CONFIG` | — | Config file path (fhcode.config.json) |
|
|
104
|
+
| `FHCODE_LANG` | system locale | UI language zh/en |
|
|
105
|
+
|
|
106
|
+
### 4.2 Model Routing
|
|
107
|
+
|
|
108
|
+
| Variable | Description |
|
|
109
|
+
|----------|-------------|
|
|
110
|
+
| `FH_PROVIDERS` | JSON array (highest priority): `{name,type,baseURL,apiKey,tags[],costPer1k}` |
|
|
111
|
+
| `FH_MODEL_NAME/TYPE/BASE_URL/API_KEY/TAGS/COST_PER_1K` | Quick single-var setup |
|
|
112
|
+
| `FH_MODEL_STRATEGY` | cost/capability/latency |
|
|
113
|
+
| `FH_BUDGET_USD` | Per-task cost cap (circuit breaker) |
|
|
114
|
+
| `FH_TENANT_BUDGET_USD` | Tenant daily cost cap (overrides policy) |
|
|
115
|
+
|
|
116
|
+
### 4.3 Security
|
|
117
|
+
|
|
118
|
+
| Variable | Description |
|
|
119
|
+
|----------|-------------|
|
|
120
|
+
| `FH_SANDBOX_MODE` | read-only / workspace-write / danger-full-access / container |
|
|
121
|
+
| `FH_SANDBOX_IMAGE` | container mode image (default node:22-alpine) |
|
|
122
|
+
| `FH_SHELL_ALLOW` | Shell allowlist (comma-separated) |
|
|
123
|
+
| `FH_REQUIRE_APPROVAL` | Approval switch (default true) |
|
|
124
|
+
| `FH_NETWORK_ALLOW/DENY` | Network domain rules (deny effective in all modes) |
|
|
125
|
+
| `FH_HOOKS` | Hooks JSON array (PreToolUse/PostToolUse/PostEdit) |
|
|
126
|
+
| `FH_POLICY` | Inline policy JSON (RBAC/blacklists, tighten-only) |
|
|
127
|
+
|
|
128
|
+
### 4.4 Enterprise Mode
|
|
129
|
+
|
|
130
|
+
| Variable | Description |
|
|
131
|
+
|----------|-------------|
|
|
132
|
+
| `FH_ENTERPRISE` | On by default (false reverts to community mode) |
|
|
133
|
+
| `FH_TENANT` | Tenant id (default: default) |
|
|
134
|
+
| `FH_USER` | User id |
|
|
135
|
+
| `FH_ROLE` | viewer/developer/operator/admin |
|
|
136
|
+
|
|
137
|
+
### 4.5 Web / Cloud Execution
|
|
138
|
+
|
|
139
|
+
| Variable | Description |
|
|
140
|
+
|----------|-------------|
|
|
141
|
+
| `FH_WEB_TOKEN` | Web console access token (auto-generated if unset) |
|
|
142
|
+
| `FH_WEB_PORT` | Port (default 8080) |
|
|
143
|
+
| `FH_TASK_CONCURRENCY` | Task concurrency cap (default 2) |
|
|
144
|
+
| `FH_TASK_PERSIST_DIR` | Task persistence dir (default `$FH_HOME/tasks`) |
|
|
145
|
+
| `FH_TASK_WEBHOOK_URL` | Task-status webhook (dynamically registrable) |
|
|
146
|
+
|
|
147
|
+
### 4.6 Message Channels
|
|
148
|
+
|
|
149
|
+
| Variable | Description |
|
|
150
|
+
|----------|-------------|
|
|
151
|
+
| `FH_CHANNEL_TELEGRAM_BOT_TOKEN/CHAT_ID` | Telegram notifications |
|
|
152
|
+
| `FH_CHANNEL_WECOM_KEY` | WeCom bot keys (comma-separated, multiple) |
|
|
153
|
+
| `FH_CHANNEL_ALLOW` | Outbound channel allowlist |
|
|
154
|
+
|
|
155
|
+
### 4.7 Marketplace / Benchmark
|
|
156
|
+
|
|
157
|
+
| Variable | Description |
|
|
158
|
+
|----------|-------------|
|
|
159
|
+
| `FH_SKILL_MARKET` | Skills marketplace source (default agentskills.io) |
|
|
160
|
+
| `FH_SWEBENCH_DATA_URL` | SWE-bench data mirror/offline JSON (intranet-friendly) |
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 5. Enterprise Private Deployment
|
|
165
|
+
|
|
166
|
+
### 5.1 Directory Layout (tenant isolation)
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
$FH_HOME/
|
|
170
|
+
├── tenants/<tenantId>/
|
|
171
|
+
│ ├── sessions/ # session checkpoints
|
|
172
|
+
│ ├── audit/ # audit hash chain (audit-YYYY-MM.jsonl)
|
|
173
|
+
│ └── goals/ # goal files
|
|
174
|
+
├── policy.json # global policy (RBAC/blacklists)
|
|
175
|
+
├── experiences/ # experience library
|
|
176
|
+
├── model-stats.jsonl # model stats
|
|
177
|
+
├── skills/ # user-level skills
|
|
178
|
+
├── plugins/ # user-level plugins
|
|
179
|
+
└── bench/ # eval/SWE-bench cache & baselines
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 5.2 Production Recommendations
|
|
183
|
+
|
|
184
|
+
1. **Token management**: always set `FH_WEB_TOKEN` explicitly (auto-generated is session-only); inject via a secrets manager
|
|
185
|
+
2. **Audit compliance**: run `fhcode audit verify` periodically to validate hash-chain integrity; audit files are monthly-sharded for archiving
|
|
186
|
+
3. **Quota governance**: set `FH_TENANT_BUDGET_USD` for tenant daily budgets; tasks are fail-fast rejected when exceeded
|
|
187
|
+
4. **Backups**: back up `$FH_HOME` (sessions/audit/experience) daily; keep `FH_TASK_PERSIST_DIR` on a separate volume
|
|
188
|
+
5. **Multi-instance**: the task queue persists per file; instances sharing the persist dir cross-recover (queued re-enqueues, running zombies marked failed)
|
|
189
|
+
6. **Intranet models**: point `FH_PROVIDERS` at an intranet Ollama/private gateway to run fully offline
|
|
190
|
+
|
|
191
|
+
### 5.3 Security Baseline (production must)
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
export FH_REQUIRE_APPROVAL=true
|
|
195
|
+
export FH_SANDBOX_MODE=workspace-write # or container
|
|
196
|
+
export FH_NETWORK_DENY=... # as needed
|
|
197
|
+
export FH_ENTERPRISE=true
|
|
198
|
+
export FH_CHANNEL_ALLOW=telegram,wecom # channel allowlist (optional)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## 6. Web Service Operations
|
|
204
|
+
|
|
205
|
+
### 6.1 Start & Health Check
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
fhcode serve --port 8080
|
|
209
|
+
curl http://localhost:8080/api/health # unauthenticated health check
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### 6.2 Task Queue API (Bearer auth)
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
TOKEN=$FH_WEB_TOKEN
|
|
216
|
+
# submit / list / query / webhook register
|
|
217
|
+
curl -X POST http://localhost:8080/api/tasks -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{"goal":"..."}'
|
|
218
|
+
curl http://localhost:8080/api/tasks -H "Authorization: Bearer $TOKEN"
|
|
219
|
+
curl http://localhost:8080/api/tasks/<id> -H "Authorization: Bearer $TOKEN"
|
|
220
|
+
curl -X POST http://localhost:8080/api/webhook -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{"url":"https://ci.example.com/hook"}'
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 6.3 Restart Recovery
|
|
224
|
+
|
|
225
|
+
- Tasks persist to `$FH_HOME/tasks/<id>.json` (atomic writes)
|
|
226
|
+
- After restart: queued tasks re-enqueue, running zombies are marked failed, terminal states remain queryable
|
|
227
|
+
- webhook/channel notifications re-fire on the queued node during recovery
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## 7. CI/CD Integration (regression gate)
|
|
232
|
+
|
|
233
|
+
```yaml
|
|
234
|
+
# .github/workflows/ci.yml excerpt
|
|
235
|
+
- name: Build & test
|
|
236
|
+
run: |
|
|
237
|
+
npm ci
|
|
238
|
+
npm run typecheck
|
|
239
|
+
npm test
|
|
240
|
+
npm run build
|
|
241
|
+
|
|
242
|
+
- name: eval regression gate (baseline compare)
|
|
243
|
+
run: |
|
|
244
|
+
npm run build
|
|
245
|
+
node scripts/eval.mjs --baseline bench/eval-baseline.json
|
|
246
|
+
# fails when current pass is below baseline
|
|
247
|
+
|
|
248
|
+
- name: Update baseline (main branch)
|
|
249
|
+
if: github.ref == 'refs/heads/main'
|
|
250
|
+
run: node scripts/eval.mjs --save-baseline bench/eval-baseline.json
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### SWE-bench harness (optional)
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
node scripts/eval-swebench.mjs --split lite --limit 20 --run --report report.md
|
|
257
|
+
# offline/intranet: point FH_SWEBENCH_DATA_URL at a mirror JSON
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## 8. Upgrades & Rollback
|
|
263
|
+
|
|
264
|
+
| Action | Command |
|
|
265
|
+
|--------|---------|
|
|
266
|
+
| Upgrade npm package | `npm install -g feihong-code@latest` |
|
|
267
|
+
| Upgrade from source | `git pull && npm install && npm run build` |
|
|
268
|
+
| Check version | `fhcode --version` / `fhcode doctor` |
|
|
269
|
+
| Rollback | npm install a previous version / git checkout an old tag (data dir is compatible and does not roll back with code) |
|
|
270
|
+
|
|
271
|
+
> Data compatibility: session checkpoints/audit/experience are JSON/JSONL text formats, backward compatible across minor versions; back up `$FH_HOME` before upgrading.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 9. Troubleshooting
|
|
276
|
+
|
|
277
|
+
| Symptom | Diagnosis |
|
|
278
|
+
|---------|-----------|
|
|
279
|
+
| 401 after service start | `FH_WEB_TOKEN` unset or mismatched with the caller (Bearer header) |
|
|
280
|
+
| Tasks stuck queued | Concurrency full (`FH_TASK_CONCURRENCY`) or persist dir not writable |
|
|
281
|
+
| Model calls fail | Run `fhcode doctor` to check network reachability and provider config |
|
|
282
|
+
| Shell fails inside Docker | Confirm `FH_SANDBOX_MODE`/image; `FH_SANDBOX_IMAGE` must include required tools |
|
|
283
|
+
| Abnormal task states after restart | Running zombies are marked failed (expected); queued tasks auto-resume |
|
|
284
|
+
| Marketplace/dataset fetch fails | Use a mirror on intranet: `FH_SKILL_MARKET` / `FH_SWEBENCH_DATA_URL` |
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
*Full configuration: see Configuration Reference; error codes and detailed troubleshooting: see FAQ & Troubleshooting.*
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# Feihong Code (fhcode) — Technical 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. Product Overview
|
|
11
|
+
|
|
12
|
+
Feihong Code (fhcode) is an AI coding agent that runs across terminal / Web / IDE surfaces, centered on the "natural language → code loop". It supports multi-model routing, enterprise-grade security, fully autonomous software engineering and self-improvement. It has zero third-party runtime dependencies (only express + zod), works offline, and can be privately deployed.
|
|
13
|
+
|
|
14
|
+
**Capability matrix (v0.5.0)**:
|
|
15
|
+
|
|
16
|
+
| Area | Capabilities |
|
|
17
|
+
|------|--------------|
|
|
18
|
+
| Orchestration | ReAct loop, planner, context compaction, checkpoint resume, cost circuit breaker, self-healing loop |
|
|
19
|
+
| Models | Multi-model routing (cost/capability/latency strategies + fallback + stats-based ranking), OpenAI-compatible / Ollama / Mock |
|
|
20
|
+
| Tools | File read/write/edit, search, managed shell, build check, test run, web retrieval, skill loading |
|
|
21
|
+
| Self-improvement | Experience library (RL-style upsert/recall), reflector feedback loop, self-healing, eval benchmark, SWE-bench harness |
|
|
22
|
+
| Security | Four-tier sandbox, network domain rules, deterministic hooks, RBAC, audit hash chain, quota circuit breaker, redaction, inbound signature verification |
|
|
23
|
+
| Ecosystem | SKILL.md skill standard, Skills marketplace (agentskills.io), MCP, plugin distribution, Agent teams |
|
|
24
|
+
| Delivery | CLI/TUI, Web console (task panel), VSCode extension, cross-process task queue, message channels |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 2. System Architecture
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
32
|
+
│ Access Layer │
|
|
33
|
+
│ CLI (index/run/repl/TUI) · Web (server/task-queue) · IDE ext │
|
|
34
|
+
└──────────────────────────────┬──────────────────────────────┘
|
|
35
|
+
│
|
|
36
|
+
┌──────────────────────────────▼──────────────────────────────┐
|
|
37
|
+
│ Orchestration agent/ │
|
|
38
|
+
│ Orchestrator(ReAct) · planner · repo-reader · swe-agent │
|
|
39
|
+
│ subagent(nested) · team(message bus) · self-heal · experience│
|
|
40
|
+
│ quality-gate · code-writer · repo-context · symbol-index │
|
|
41
|
+
└──────────────┬───────────────────────────────┬──────────────┘
|
|
42
|
+
│ │
|
|
43
|
+
┌──────────────▼──────────────┐ ┌─────────────▼──────────────┐
|
|
44
|
+
│ Model Layer models/ │ │ Tool Layer tools/ │
|
|
45
|
+
│ ModelRouter(strategy+stats) │ │ file/search/shell/verify │
|
|
46
|
+
│ OpenAICompatible/Ollama/Mock│ │ web(MCP) / skills(load) │
|
|
47
|
+
│ sandbox(4 tiers+net rules) │ │ tool.registry(zod+guard) │
|
|
48
|
+
└──────────────┬──────────────┘ └─────────────┬──────────────┘
|
|
49
|
+
│ │
|
|
50
|
+
┌──────────────▼───────────────────────────────▼──────────────┐
|
|
51
|
+
│ Security enterprise/ + runtime/hooks │
|
|
52
|
+
│ tenant(multi-tenant) · policy(RBAC) · audit(hash chain) │
|
|
53
|
+
│ guard · hooks(PreToolUse/PostEdit) · channels │
|
|
54
|
+
└──────────────────────────────┬──────────────────────────────┘
|
|
55
|
+
│
|
|
56
|
+
┌──────────────────────────────▼──────────────────────────────┐
|
|
57
|
+
│ Infrastructure shared/ + runtime/ │
|
|
58
|
+
│ config(env-first) · i18n(zh/en) · logger(redacting JSON) │
|
|
59
|
+
│ event-log(JSONL) · session-persist · git · worktree │
|
|
60
|
+
└─────────────────────────────────────────────────────────────┘
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Module layout** (`src/`):
|
|
64
|
+
|
|
65
|
+
| Directory | Responsibility |
|
|
66
|
+
|-----------|----------------|
|
|
67
|
+
| `cli/` | Arg parsing, command dispatch, run assembly, REPL/TUI, version |
|
|
68
|
+
| `agent/` | Orchestrator, planner, SWE, subagents, teams, self-heal, experience, symbol index, repo context |
|
|
69
|
+
| `models/` | Model router, providers (OpenAI-compatible/Ollama/Mock), cost estimation, DTO validation |
|
|
70
|
+
| `tools/` | Tool system: file/search/shell/verify/web/MCP/skill loading/sandbox |
|
|
71
|
+
| `enterprise/` | Multi-tenancy, RBAC policy, audit chain, quota, guard |
|
|
72
|
+
| `runtime/` | Event log, session persistence, git helpers, worktree, hooks |
|
|
73
|
+
| `shared/` | Config, i18n, logger (redacting), error hierarchy, types |
|
|
74
|
+
| `skills/` | Skill standard (SKILL.md loading), skill marketplace (agentskills.io), /plan /grill /goal |
|
|
75
|
+
| `plugins/` | Plugin distribution (plugin.json packaging skills+hooks+MCP) |
|
|
76
|
+
| `web/` | Web console, task queue, message channels, inbound signature verification |
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 3. Core Modules
|
|
81
|
+
|
|
82
|
+
### 3.1 Orchestrator (agent/orchestrator.ts)
|
|
83
|
+
|
|
84
|
+
ReAct main loop `run(goal, resume?)`, per iteration:
|
|
85
|
+
1. `router.chat()` calls the model (with capability-tag routing)
|
|
86
|
+
2. No tool calls → task complete; otherwise `executeToolRound()` executes tools and feeds back tool messages
|
|
87
|
+
3. Error detection: `roundErrors > 0` → `handleRecovery()` (classify → inject reflection → retry, cap `maxRetryErrors`)
|
|
88
|
+
4. Context compaction: when `shouldCompact()` triggers, the system instruction is preserved (H4 fix)
|
|
89
|
+
5. Checkpoint persistence (`persist` callback) + event stream (`onEvent`, P0-1 streaming output)
|
|
90
|
+
|
|
91
|
+
**Event stream (P0-1)**: `OrchestratorEvent` discriminated union — model.response / tool.call / tool.result / self-heal / context.compact / session.end. The CLI stream renderer, TUI header driver and eval counters all consume the same event source.
|
|
92
|
+
|
|
93
|
+
**Cost circuit breaker (M4)**: `cost >= maxCostUsd` aborts immediately with a `resume` hint; `maxCostUsd=0` means unlimited.
|
|
94
|
+
|
|
95
|
+
**Experience feedback (M6)**: at session end, `extractExperience()` (table-driven EXTRACTORS) → `upsertExperience` (stable id merge, sessionCount accumulation, success-rate weighted average); self-healed sessions additionally persist `extractFixPattern`.
|
|
96
|
+
|
|
97
|
+
### 3.2 Model Router (models/model-router.ts)
|
|
98
|
+
|
|
99
|
+
- Strategies: `cost` (by costPer1k) / `latency` (local-first) / `capability` (tag-weighted)
|
|
100
|
+
- Ranking: `rank(tags)` capability filter + historical success-rate weight (≥3 calls, up to +0.3)
|
|
101
|
+
- Fallback: try in order; failures recorded under `p.model` (fix: no empty model-name entries); throw last error if all fail
|
|
102
|
+
- Stats: `updateStat()` auto-persists (`statsHomeDir`, P5 loop-closure fix); `model-stats` command reads them
|
|
103
|
+
- Sub-task split (P1-1): `tags: ['code-gen','cheap']` routes sub-tasks to low-cost models
|
|
104
|
+
|
|
105
|
+
### 3.3 Tool System (tools/)
|
|
106
|
+
|
|
107
|
+
- `ToolRegistry`: register/find/execute, zod argument validation, errors normalized to `ToolResult`
|
|
108
|
+
- Execution chain (defense in depth): **sandbox → PreToolUse hook → RBAC guard → tool → PostToolUse/PostEdit hook**
|
|
109
|
+
- Four-tier sandbox (P0-2/P5-4): `read-only` / `workspace-write` / `danger-full-access` / `container` (Docker-mount workspace for shell)
|
|
110
|
+
- Network domain rules: `FH_NETWORK_ALLOW/DENY` apply to run_shell command URLs and web tool URLs alike
|
|
111
|
+
- Hooks (P2-1): `FH_HOOKS` JSON array; PreToolUse non-zero exit blocks, PostEdit fires after edits; placeholders `{cwd}{tool}{path}{runId}{ok}`
|
|
112
|
+
|
|
113
|
+
### 3.4 SWE Agent (agent/swe-agent.ts + swe-planner + swe-verifier)
|
|
114
|
+
|
|
115
|
+
Repository read (`repo-reader`, throttled/ignored rules) → task decomposition (`planSweTask`) → per-task "implement (runSubTask) + verify (build/test) + self-heal retry" → report. Supports `--plan-only` / `--verify-only` / `--max-tasks` / `--max-retries`.
|
|
116
|
+
|
|
117
|
+
**Subagents (P3-4)**: `runSubAgent` depth control (default 3 levels); decomposable goals recursively spawn subagents (sub-directory isolation) when depth is not exhausted, with per-level summarized results (`summarizeSubTaskAnswer`, P2-2).
|
|
118
|
+
|
|
119
|
+
### 3.5 Agent Teams (agent/team.ts, P4-2)
|
|
120
|
+
|
|
121
|
+
- `TeamBus`: message bus (send/receive/broadcast, directed and fan-out)
|
|
122
|
+
- `TaskBoard`: shared task list (atomic claim to prevent duplicates, status+owner double check)
|
|
123
|
+
- `runTeam`: multiple agents claim and execute concurrently; `ok=false` marks failed (fix); produces a team report
|
|
124
|
+
|
|
125
|
+
### 3.6 Enterprise Security (enterprise/)
|
|
126
|
+
|
|
127
|
+
| Module | Mechanism |
|
|
128
|
+
|--------|-----------|
|
|
129
|
+
| tenant | Tenant-isolated directories (`tenants/<id>/{sessions,audit,goals}`) |
|
|
130
|
+
| policy | RBAC: role-tool matrix (viewer/developer/operator/admin) + denyShell blacklist + denyPaths sensitive paths, deny-first |
|
|
131
|
+
| audit | Hash chain (SHA-256, seq/prevHash linkage), cross-process file lock + exponential backoff, redaction before write, `audit verify` |
|
|
132
|
+
| quota | Tenant daily cost budget (`FH_TENANT_BUDGET_USD`), fail-fast live re-check before start (M14 fix) |
|
|
133
|
+
| guard | "Policy → approval → audit" pre-tool hook; audit failure = deny |
|
|
134
|
+
|
|
135
|
+
### 3.7 Skills & Marketplace (skills/)
|
|
136
|
+
|
|
137
|
+
- **SKILL.md standard (P1-2)**: frontmatter (name/description) + body; progressive disclosure — index (≤8KB) resident in system prompt, body loaded on demand via `load_skill` tool (Tier-2)
|
|
138
|
+
- Discovery: repo `.agents/skills` / `.claude/skills` upward walk + bundled `skills/` + user `~/.feihong-code/skills` + plugin skill dirs
|
|
139
|
+
- **Marketplace (P6)**: agentskills.io discovery spec (`/.well-known/agent-skills/index.json`); `skill-market search/install/list`; RFC 3986 URL resolution, sha256 digest verification, tar.gz unpack (zero-dep hand-written, path-traversal protected)
|
|
140
|
+
- **Plugins (P3-3)**: `plugin.json` packaging skills+hooks+MCP; user/project two-level discovery; `plugin install` (local dir/git clone)
|
|
141
|
+
|
|
142
|
+
### 3.8 Web & Cloud Execution (web/)
|
|
143
|
+
|
|
144
|
+
| Endpoint | Description |
|
|
145
|
+
|----------|-------------|
|
|
146
|
+
| `GET /api/health` | Public health check (unauthenticated) |
|
|
147
|
+
| `POST/GET /api/tasks`, `GET /api/tasks/:id` | Task queue (Bearer auth, P4-1) |
|
|
148
|
+
| `POST/GET /api/webhook` | Webhook scheduling registration/query (P5-2) |
|
|
149
|
+
| other `/api/...` | Require `FH_WEB_TOKEN` Bearer (fail-closed, timing-safe comparison) |
|
|
150
|
+
|
|
151
|
+
**Task queue (P4-1/P6-4)**: state machine queued→running→done|failed; concurrency cap (`FH_TASK_CONCURRENCY`); cross-process persistence (`FH_TASK_PERSIST_DIR`, one file per task with atomic writes; on restart queued tasks re-enqueue, running zombies marked failed); webhook status callbacks (status snapshot, fixing the lost-queued race).
|
|
152
|
+
|
|
153
|
+
**Message channels (P5-6/O6)**: Telegram (`FH_CHANNEL_TELEGRAM_BOT_TOKEN`+`CHAT_ID`) and WeCom (`FH_CHANNEL_WECOM_KEY`, multiple keys) outbound push; outbound allowlist `FH_CHANNEL_ALLOW`; inbound signature tools `verifyHmacSignature` (HMAC-SHA256 timing-safe) / `verifyWecomSignature` (WeCom SHA1 sort).
|
|
154
|
+
|
|
155
|
+
### 3.9 IDE Extension (vscode-extension/)
|
|
156
|
+
|
|
157
|
+
Thin-shell design (all logic in the CLI): `fhcode.run` (selection context injection `<selection>`), `fhcode.review` (`review --json` → editor inline diagnostics via DiagnosticCollection + CodeAction suggestions), `fhcode.diff` (native diff editor HEAD↔workspace via `fhcode-head` scheme), `fhcode.output`; settings `binaryPath` / `offline` / `reviewOnSave`.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 4. Protocols & Standards
|
|
162
|
+
|
|
163
|
+
| Protocol | Description |
|
|
164
|
+
|----------|-------------|
|
|
165
|
+
| Tool-call contract | OpenAI-style `tool_calls` (name/arguments JSON); results fed back as role=tool messages (toolCallId matched) |
|
|
166
|
+
| MCP | stdio transport (NDJSON JSON-RPC 2.0): initialize → notifications/initialized → tools/list → tools/call; tools registered as `<server>_<tool>` |
|
|
167
|
+
| SKILL.md | open agent skills compatible (frontmatter name/description + body, progressive disclosure) |
|
|
168
|
+
| agentskills.io | discovery index 0.2.0: `$schema` validation, skill-md/archive, digest `sha256:<hex>` |
|
|
169
|
+
| webhook | `POST {url}` JSON: `{event:'task.status', task:{...}, ts}` (status snapshot) |
|
|
170
|
+
| inbound signature | HMAC-SHA256 (`sha256=<hex>` header) or WeCom SHA1 sort |
|
|
171
|
+
| checkpoint | `<runId>.session.json` (full dialogue/iterations/cost/touchedFiles), resume continues |
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 5. Security Design
|
|
176
|
+
|
|
177
|
+
1. **Defense in depth**: sandbox (technical boundary) → hooks (deterministic control) → RBAC policy (permission) → audit (trace) → quota (cost)
|
|
178
|
+
2. **Sandbox**: four tiers + network domain rules (deny effective in all modes, allow blocks non-matching in workspace-write); `container` tier Docker isolation
|
|
179
|
+
3. **Command protection**: run_shell injection metacharacter blocking (`[;&|`$(){}<>!]` etc.); managed commands (run_tests/build_check) allow only package-manager scripts
|
|
180
|
+
4. **Path safety**: `safeJoin` (lexical + realpath symlink validation); policy denyPaths sensitive-path blacklist (.env/.git/config/keys etc.)
|
|
181
|
+
5. **Audit**: tamper-evident hash chain (`verifyAudit` checks seq/prevHash/hash); redaction before write (SECRET_RE/Bearer/JWT/sk-)
|
|
182
|
+
6. **Log redaction**: sensitive keys masked whole-value + value patterns (sk-/JWT/long tokens)
|
|
183
|
+
7. **Web auth**: Bearer token timing-safe comparison, fail-closed; 1MB body limit
|
|
184
|
+
8. **Inbound security**: webhook signature verification (HMAC/WeCom), channel allowlist
|
|
185
|
+
9. **Skill security**: marketplace digest verification against tampering, tar.gz path-traversal protection, mandatory name frontmatter
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## 6. Performance & Quality Baseline (measured at v0.5.0-b)
|
|
190
|
+
|
|
191
|
+
| Metric | Value |
|
|
192
|
+
|--------|-------|
|
|
193
|
+
| Unit tests | 164/164 green (16 modules + 10 feature areas) |
|
|
194
|
+
| Milestone assertions | M4 41 · M6 29 · M7 12 · M8 27 · M9 25 = 134 green |
|
|
195
|
+
| eval benchmark | 10/10 (5 scenarios + 5 acceptance, real-artifact verification, 100% pass) |
|
|
196
|
+
| SWE-bench loader | HF datasets-server / mirror / cache, mock execution + report |
|
|
197
|
+
| Complexity | 676 functions, 52 hotspots with cc≥10 (core decision functions kept; rule-based ones table-driven) |
|
|
198
|
+
| Dependencies | Runtime only express + zod (no other runtime deps, offline-capable) |
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 7. Configuration Model (iron rule: all config from env, validated at startup, fail-fast)
|
|
203
|
+
|
|
204
|
+
Priority: `FH_PROVIDERS` (JSON) > `fhcode.config.json` > single env vars `FH_MODEL_*`; security lists (deny blacklists) are unions that can only be tightened. Full reference: see Configuration Reference and Deployment Guide.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## 8. Versioning & Roadmap
|
|
209
|
+
|
|
210
|
+
- v0.4.0: P0-P5 full capabilities (streaming/sandbox/MCP/Skills/plugins/cloud queue/channels/symbol index)
|
|
211
|
+
- v0.5.0 (released 2026-08-17): consolidates IDE deep integration first round (review --json + inline review + context input), SWE-bench harness integration (dataset loading + mock execution + report), eval regression gate, O6 inbound signature verification & security hardening
|
|
212
|
+
- Planned v0.5.0-c/d: containerized SWE execution + real-model benchmark; inbound channel scheduling (see planning doc)
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
*This manual is updated with each release; capabilities are authoritative in the source code and `fhcode --help`.*
|