hyp context.md - maoxiaoyue/hypgo GitHub Wiki
hyp context — 生成專案 Manifest
生成機器可讀的專案描述(YAML/JSON),讓 AI 用最少 token 掌握專案全貌。
用法
hyp context # YAML 到 stdout
hyp context -f json # JSON 格式
hyp context -o .hyp/manifest.yaml # 儲存到檔案
hyp context -o manifest.json -f json # JSON 儲存到檔案
Flags
| Flag | 說明 | 預設值 |
|---|---|---|
-o, --output |
輸出檔案路徑 | stdout |
-f, --format |
輸出格式:yaml 或 json |
yaml |
輸出內容
version: "1.0"
framework: HypGo
generated_at: "2026-04-03T14:30:00+08:00"
server:
addr: ":8080"
protocol: http2
tls: true
routes:
- method: POST
path: /api/users
handler_names: [controllers.CreateUser]
summary: "Create user"
tags: [users]
input_type: CreateUserReq
output_type: UserResp
responses:
201: "User created"
database:
driver: postgres
has_replicas: true
什麼時候執行
| 時機 | 原因 |
|---|---|
| 專案建立後 | 產出初始 manifest |
| 新增/修改 Schema 路由後 | 更新路由資訊 |
執行 hyp ai-rules 前 |
讓 AI 配置檔包含路由表 |
自動同步
Server.Start() 啟動時會自動呼叫 autosync.SyncSafe(),將 manifest 寫入 .hyp/context.yaml。手動執行 hyp context 適合在開發時預覽或指定不同格式。
Token 效率
| 場景 | 傳統框架 | HypGo Manifest |
|---|---|---|
| AI 理解 API 結構 | 讀 handler 原始碼(~5,000 tokens) | 讀 manifest(~500 tokens) |
安全
Manifest 不包含:密碼、DSN、token、API key。只包含路由路徑、型別名稱、server 設定。
LLM 智慧增強(--llm)
v0.8.5+--llmflag 為 v0.8.5 新增功能,v0.8.1 不支援。
# 指定 LLM 配置檔(自動偵測 config/llm.yaml 或 .hyp/llm.yaml)
hyp context --llm config/llm.yaml
# 結合其他選項
hyp context --llm config/llm.yaml -o .hyp/manifest.yaml
啟用後,Manifest 的 Summary、Tags 等欄位會由 LLM 自動補齊(Ollama / OpenAI / RAG 三種模式)。詳見 manifest.md。
相關命令
- hyp ai-rules — 讀取 manifest 並注入 AI 配置檔
- hyp generate — 生成程式碼(Schema 路由會出現在 manifest 中)