Skip to content

Commit ac090e3

Browse files
author
Sisyphus Agent
committed
docs: 添加快速上手指南
新增文件: - QUICKSTART.md: 5 分钟快速开始指南 内容: - 5 步快速开始流程 - 避免超时错误的最佳实践 - 常用命令速查 - 环境配置指南 - 问题排查快速参考
1 parent 4e9c0b2 commit ac090e3

1 file changed

Lines changed: 197 additions & 0 deletions

File tree

QUICKSTART.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# oho CLI 快速上手指南
2+
3+
## ⚡ 5 分钟快速开始
4+
5+
### 步骤 1: 设置环境
6+
7+
```bash
8+
# 设置服务器密码(替换为你的实际密码)
9+
export OPENCODE_SERVER_PASSWORD=your-password
10+
11+
# 设置超时时间(推荐 10 分钟,避免长时间任务超时)
12+
export OPENCODE_CLIENT_TIMEOUT=600
13+
```
14+
15+
### 步骤 2: 验证连接
16+
17+
```bash
18+
# 检查服务器连接
19+
oho config get
20+
21+
# 查看可用模型
22+
oho config providers
23+
```
24+
25+
### 步骤 3: 创建会话
26+
27+
```bash
28+
# 创建新会话
29+
SESSION_ID=$(oho session create 2>&1 | grep "ID:" | awk '{print $2}')
30+
echo "创建会话:$SESSION_ID"
31+
```
32+
33+
### 步骤 4: 发送消息
34+
35+
```bash
36+
# 方法 A: 等待响应(适合简单任务)
37+
oho message add -s "$SESSION_ID" "你好,请帮我分析项目结构"
38+
39+
# 方法 B: 不等待响应(适合长时间任务)⭐推荐
40+
oho message add -s "$SESSION_ID" "分析项目结构" --no-reply
41+
42+
# 方法 C: 异步提交(后台处理)
43+
oho message prompt-async -s "$SESSION_ID" "分析项目结构"
44+
```
45+
46+
### 步骤 5: 查看结果
47+
48+
```bash
49+
# 查看消息历史
50+
oho message list -s "$SESSION_ID" --limit 5
51+
52+
# 查看会话状态
53+
oho session status
54+
```
55+
56+
---
57+
58+
## 🎯 避免超时错误的最佳实践
59+
60+
### ✅ 推荐做法
61+
62+
```bash
63+
# 1. 设置足够的超时时间
64+
export OPENCODE_CLIENT_TIMEOUT=600 # 10 分钟
65+
66+
# 2. 使用 --no-reply 发送长时间任务
67+
oho message add -s ses_xxx "复杂任务" --no-reply
68+
69+
# 3. 稍后查看结果
70+
sleep 60
71+
oho message list -s ses_xxx --limit 3
72+
73+
# 4. 或使用异步提交
74+
oho message prompt-async -s ses_xxx "任务"
75+
```
76+
77+
### ❌ 避免做法
78+
79+
```bash
80+
# 不要:不设置超时时间(可能使用默认值)
81+
oho message add -s ses_xxx "复杂分析任务"
82+
83+
# 不要:对长时间任务使用同步模式
84+
oho message add -s ses_xxx "重构整个项目" # 可能超时!
85+
```
86+
87+
---
88+
89+
## 📋 常用命令速查
90+
91+
### 会话操作
92+
93+
```bash
94+
oho session create # 创建会话
95+
oho session list # 列出所有会话
96+
oho session get -s <id> # 查看会话详情
97+
oho session abort -s <id> # 中止会话
98+
oho session delete <id> # 删除会话
99+
```
100+
101+
### 消息操作
102+
103+
```bash
104+
oho message add -s <id> "内容" # 发送消息
105+
oho message add -s <id> "内容" --no-reply # 不等待响应
106+
oho message prompt-async -s <id> "内容" # 异步提交
107+
oho message list -s <id> # 查看历史
108+
oho message get <msg_id> -s <id> # 消息详情
109+
```
110+
111+
### 文件附件
112+
113+
```bash
114+
# 附加单个文件
115+
oho message add -s <id> "分析这个文件" --file /path/to/file.go
116+
117+
# 附加多个文件
118+
oho message add -s <id> "对比这些文件" \
119+
--file file1.go \
120+
--file file2.go
121+
```
122+
123+
---
124+
125+
## 🔧 环境配置(永久)
126+
127+
将以下内容添加到 `~/.bashrc``~/.zshrc`
128+
129+
```bash
130+
# OpenCode oho CLI 配置
131+
export OPENCODE_SERVER_HOST=127.0.0.1
132+
export OPENCODE_SERVER_PORT=4096
133+
export OPENCODE_SERVER_PASSWORD=your-password
134+
export OPENCODE_CLIENT_TIMEOUT=600
135+
136+
# 可选:添加别名
137+
alias oho-session='oho session list'
138+
alias oho-config='oho config get'
139+
```
140+
141+
然后执行:
142+
```bash
143+
source ~/.bashrc # 或 source ~/.zshrc
144+
```
145+
146+
---
147+
148+
## 🐛 遇到问题?
149+
150+
### 超时错误
151+
152+
```bash
153+
# 症状:context deadline exceeded
154+
# 解决:增加超时时间或使用 --no-reply
155+
export OPENCODE_CLIENT_TIMEOUT=600
156+
oho message add -s ses_xxx "任务" --no-reply
157+
```
158+
159+
### 认证失败
160+
161+
```bash
162+
# 症状:API 错误 [401]
163+
# 解决:检查密码
164+
export OPENCODE_SERVER_PASSWORD=correct-password
165+
```
166+
167+
### 连接被拒绝
168+
169+
```bash
170+
# 症状:connection refused
171+
# 解决:启动服务器
172+
opencode serve --port 4096
173+
```
174+
175+
### 运行诊断
176+
177+
```bash
178+
# 完整诊断脚本
179+
export OPENCODE_SERVER_PASSWORD=xxx
180+
./debug_message.sh
181+
182+
# 超时测试
183+
./test_timeout.sh
184+
```
185+
186+
---
187+
188+
## 📚 更多文档
189+
190+
- [完整教程](docs/oho-cli-usage/README.md)
191+
- [问题排查](docs/oho-cli-usage/09-troubleshooting.md)
192+
- [快速参考](docs/oho-cli-usage/QUICK_REFERENCE.md)
193+
- [安装说明](INSTALL_AND_USAGE.md)
194+
195+
---
196+
197+
*最后更新:2026-03-15*

0 commit comments

Comments
 (0)