feihong-code 0.2.3 → 0.6.0
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 +392 -0
- package/CODE_OF_CONDUCT.md +56 -56
- package/CONTRIBUTING.md +68 -68
- package/LICENSE +22 -22
- package/README.md +586 -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 +74 -18
- 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 +319 -84
- package/dist/agent/experience.js.map +1 -1
- package/dist/agent/orchestrator.js +233 -71
- package/dist/agent/orchestrator.js.map +1 -1
- package/dist/agent/planner.js +30 -7
- package/dist/agent/planner.js.map +1 -1
- package/dist/agent/prompts.js +9 -0
- package/dist/agent/prompts.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 +80 -60
- 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 +600 -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 +145 -23
- 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 +100 -27
- package/dist/models/model-router.js.map +1 -1
- package/dist/models/model.dto.js +25 -3
- package/dist/models/model.dto.js.map +1 -1
- package/dist/models/providers/ollama.provider.js +12 -0
- package/dist/models/providers/ollama.provider.js.map +1 -1
- package/dist/models/providers/openai-compatible.provider.js +14 -1
- package/dist/models/providers/openai-compatible.provider.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/self-evolve/hook.ts +80 -0
- package/dist/self-evolve/manager.d.ts +8 -0
- package/dist/self-evolve/manager.js +401 -0
- package/dist/shared/config.js +35 -3
- package/dist/shared/config.js.map +1 -1
- package/dist/shared/errors.js +6 -2
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/i18n.js +535 -0
- package/dist/shared/i18n.js.map +1 -0
- package/dist/shared/secure-store.js +117 -0
- package/dist/shared/secure-store.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 +194 -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 +72 -3
- package/dist/tools/shell/exec.js.map +1 -1
- package/dist/tools/shell/run-shell.tool.js +37 -7
- 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 +69 -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 +178 -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/css/style.css +1546 -0
- package/dist/web/public/index.html +804 -37
- package/dist/web/public/js/api.js +309 -0
- package/dist/web/public/js/app.js +1472 -0
- package/dist/web/public/js/ui.js +832 -0
- package/dist/web/public/js/utils.js +170 -0
- package/dist/web/server.js +937 -11
- package/dist/web/server.js.map +1 -1
- package/dist/web/task-queue.js +470 -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/App/344/275/277/347/224/250/350/257/264/346/230/216/344/271/246.md +299 -0
- package/docs/App/346/212/200/346/234/257/350/257/264/346/230/216/344/271/246.md +554 -0
- package/docs/Deployment_Guide_EN.md +288 -0
- package/docs/SELF-EVOLVE-GUIDE.md +313 -0
- package/docs/Technical_Manual_EN.md +216 -0
- package/docs/User_Manual_EN.md +314 -0
- package/docs/error-codes.md +198 -0
- package/docs/screenshots/cli-demo.png +0 -0
- package/docs/screenshots/feature-comparison.png +0 -0
- package/docs/screenshots/web-console.png +0 -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/docs//351/241/265/351/235/242/345/212/237/350/203/275/345/244/215/347/233/230/344/270/216/345/206/222/347/203/237/346/265/213/350/257/225/346/212/245/345/221/212.html +117 -0
- package/package.json +108 -109
- package/tool-schema.json +117 -46
|
@@ -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`.*
|
|
@@ -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.*
|