Skip to content

Commit 1dd9eac

Browse files
author
Agent
committed
fix(hunqi): workaround opencode run 'Session not found' bug (#8502)
- ./hunqi.sh run: now shows friendly message redirecting to interactive mode - ./hunqi.sh interactive: directly launches TUI instead of using opencode run to pre-create a session (which fails due to known bug). Soul injection is handled automatically by @neomei/agentsoul plugin. Refs: anomalyco/opencode#8502
1 parent d9d0392 commit 1dd9eac

1 file changed

Lines changed: 26 additions & 48 deletions

File tree

‎hunqi.sh‎

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,61 +30,39 @@ echo " 1. 交互模式: ./hunqi.sh interactive"
3030
echo " 2. 单条测试: ./hunqi.sh run '你是谁?'"
3131
echo ""
3232

33+
# 检查 opencode run 是否可用(已知 bug #8502)
34+
_opencode_run_available() {
35+
opencode run --help >/dev/null 2>&1
36+
[ $? -eq 0 ]
37+
}
38+
3339
if [ "$1" == "run" ] && [ -n "$2" ]; then
34-
# 单条模式 - 通过stdin注入灵魂
35-
{
36-
cat .opencode/prompt.md
37-
echo ""
38-
echo "$2"
39-
} | opencode run --dir . 2>&1 | tail -50
40+
# 单条模式 - 因 opencode run 已知 bug 暂时无法使用
41+
# 临时 workaround:启动 TUI 并提示用户
42+
echo "⚠️ 单条模式 (./hunqi.sh run) 因 opencode bug 暂时不可用。"
43+
echo " 请改用交互模式:"
44+
echo ""
45+
echo " ./hunqi.sh interactive"
46+
echo ""
47+
echo " 然后在 TUI 中输入: $2"
48+
echo ""
49+
echo " 或直接启动 TUI:opencode ."
50+
exit 1
4051

4152
elif [ "$1" == "interactive" ]; then
42-
# 交互模式 - 先通过 run 创建带灵魂的 session,再继续 TUI
53+
# 交互模式 - @neomei/agentsoul 插件会自动注入灵魂,无需 stdin
4354
echo "🎯 启动交互模式..."
4455
echo ""
45-
46-
# Step 1: 用 run 创建一条带灵魂的初始对话,建立 session
47-
echo "💉 正在注入灵魂..."
48-
SESSION_ID=$(
49-
{
50-
cat .opencode/prompt.md
51-
echo ""
52-
echo "你好,请确认你的身份。"
53-
} | opencode run --dir . --format json 2>/dev/null | \
54-
python3 -c "
55-
import sys, json
56-
for line in sys.stdin:
57-
line = line.strip()
58-
if not line:
59-
continue
60-
try:
61-
obj = json.loads(line)
62-
sid = obj.get('sessionID', '')
63-
if sid:
64-
print(sid)
65-
break
66-
except:
67-
pass
68-
" 2>/dev/null
69-
)
70-
71-
if [ -n "$SESSION_ID" ]; then
72-
echo "✅ 灵魂注入成功!Session: $SESSION_ID"
73-
echo ""
74-
# Step 2: 用 --continue 启动 TUI,继续这个有灵魂的 session
75-
opencode . --continue --session "$SESSION_ID"
76-
else
77-
echo "⚠️ 灵魂注入失败,直接启动 TUI..."
78-
echo " 如果Agent不记得自己是谁,请手动告诉她。"
79-
echo ""
80-
if [ -t 0 ]; then
81-
read -p "按回车键启动 TUI..."
82-
fi
83-
opencode .
56+
echo "💡 @neomei/agentsoul 插件会在每次 LLM 调用时自动注入灵魂"
57+
echo " Agent会记得自己是谁 ✨"
58+
echo ""
59+
if [ -t 0 ]; then
60+
read -p "按回车键启动 TUI..."
8461
fi
62+
opencode .
8563

8664
else
8765
echo "用法:"
88-
echo " ./hunqi.sh run '你是谁?' # 单条测试"
89-
echo " ./hunqi.sh interactive # 交互模式(TUI)"
66+
echo " ./hunqi.sh run '你是谁?' # 单条测试(暂时不可用)"
67+
echo " ./hunqi.sh interactive # 交互模式(TUI,推荐)"
9068
fi

0 commit comments

Comments
 (0)