oh-my-opencode (oMo) 全程配置与实战手册

🚀 oh-my-opencode (oMo) 全程配置与实战手册

一、 核心安装 (Installation)

首先安装 oMo 插件并初始化项目环境。

1. 插件安装

bash 复制代码
npm install -g oh-my-opencode

2. 项目初始化

在你的代码项目根目录下运行:

bash 复制代码
oh-my-opencode install
  • 建议选项 :在提示是否开启 LSP auto-fix 和创建 AGENTS.md 时选 Yes

二、 基础环境依赖 (Dependencies)

解决 doctor 诊断中的警告,赋予 AI 读写代码和纠错的能力。

1. 代码结构分析:AST-Grep

bash 复制代码
npm install -g @ast-grep/cli

2. 代码"眼睛":LSP Servers

必须安装对应语言的服务,AI 才能捕捉语法错误。

  • TypeScript/JS: npm install -g typescript-language-server typescript
  • Python: pip install pyright

3. OpenCode 核心更新

确保底层核心处于 1.1.41 或以上版本:

bash 复制代码
npm install -g @opencode/cli@latest

三、 模型与 Agent 配置 (oh-my-opencode.json)

针对我拥有的 MiniMaxGLMGemini 模型进行最优分工。

文件路径: ~/.config/opencode/oh-my-opencode.json

json 复制代码
{
  "$schema": "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",
  "agents": {
    "sisyphus": { 
      "model": "nvidia/minimaxai/minimax-m2.1", 
      "description": "执行官:利用长上下文进行循环纠错" 
    },
    "oracle": { 
      "model": "nvidia/z-ai/glm-4.7", 
      "description": "咨询官:处理深度逻辑与架构建议" 
    },
    "librarian": { 
      "model": "nvidia/z-ai/glm-4.7", 
      "description": "管理员:负责 RAG 和文件索引" 
    },
    "explore": { 
      "model": "google/gemini-2.5-flash", 
      "description": "探索者:快速扫描项目结构" 
    },
    "prometheus": { 
      "model": "nvidia/z-ai/glm-4.7", 
      "description": "规划者:任务拆解与计划生成" 
    }
  },
  "categories": {
    "visual-engineering": { "model": "google/gemini-2.5-flash" },
    "ultrabrain": { "model": "nvidia/z-ai/glm-4.7" },
    "artistry": { "model": "nvidia/minimaxai/minimax-m2.1" },
    "quick": { "model": "google/gemini-2.5-flash" },
    "unspecified-low": { "model": "google/gemini-2.5-flash" },
    "unspecified-high": { "model": "nvidia/z-ai/glm-4.7" },
    "writing": { "model": "nvidia/minimaxai/minimax-m2.1" }
  }
}

四、 身份认证与环境变量 (Authentication)

由于 OpenCode 1.1.41 的 auth login google 存在 fetch() URL is invalid 的 Bug,必须通过环境变量手动注入 API Key。

~/.zshrc~/.bashrc 中添加:

bash 复制代码
# Gemini Key
export GOOGLE_API_KEY='你的_GEMINI_API_KEY'
# NVIDIA 系列 (MiniMax/GLM) Key
export NVIDIA_API_KEY='你的_NVIDIA_API_KEY'

执行 source ~/.zshrc 生效。


五、 核心修复:参数转发包装器 (The Wrapper)

1. 故障表现

运行命令时提示:Error: Failed to change directory to /Users/xxx/prompt_content
原因:OpenCode 1.1.41 误将 Prompt 文字识别为了文件夹路径。

2. 解决方案:创建自定义包装脚本

拦截 oMo 发出的错误指令并重组。

bash 复制代码
# 1. 创建脚本
cat << 'EOF' > /usr/local/bin/opencode-fix
#!/bin/bash
ARGS=()
MODEL=""
PROMPT=""

while [[ $# -gt 0 ]]; do
  case $1 in
    --model) MODEL="$2"; shift 2 ;;
    *) PROMPT="$1"; shift ;;
  esac
done

# 重新组装为 1.1.41 唯一支持的显式格式
exec /usr/local/bin/opencode --model "$MODEL" --prompt "$PROMPT"
EOF

# 2. 赋予执行权限
chmod +x /usr/local/bin/opencode-fix

# 3. 在 ~/.zshrc 中设置别名
alias opencode='/usr/local/bin/opencode-fix'

六、 验证与日常维护

1. 最终诊断

执行 oh-my-opencode doctor,确保:

  • AST-Grep CLILSP Servers
  • Summary 显示 10 passed 或更多。

2. 常用操作指令

  • 清理死掉的任务 (当出现无尽的 toast.show 时):
bash 复制代码
pkill -f opencode && rm -rf ~/.local/share/opencode/sessions/*
  • 实战测试
bash 复制代码
oh-my-opencode run "用 Gemini 简单解释一下当前目录下的 opencode.json 是干什么的"

这套方案已经完美避开了 1.1.41 版本的所有已知坑点。您现在运行最后的实战测试,应该能看到 AI 正常的输出结果了。

相关推荐
青啊青斯2 天前
OpenCode环境搭建及常用操作
opencode
Hehuyi_In2 天前
opencode + skills 漏洞复盘分析试用
ai·skills·opencode
hallo1283 天前
opencode执行/start-work出现错误:Model not found: opencode/glm-4.7-free.
opencode
夜魔0093 天前
OpenCode、OpenClaw、Claude Code skill tool失败问题解决
ripgrep·fetch·error·skill·rg·opencode
feasibility.4 天前
AI自动化的陷阱:2026年开年ai爆发潮下的冷思考
人工智能·经验分享·自动化·程序员创富·vibe coding·opencode·openclaw
谷新龙0016 天前
opencode入门
opencode
烁烁闪闪烁烁7 天前
【weelinking系列Claude教程】 04 - Claude Code 安装与配置
人工智能·chatgpt·ai编程·claude·cursor·claude code·opencode
鸿乃江边鸟8 天前
oh-my-opencode 实践--用户授权登陆Spring Boot项目
大模型·opencode·oh my opencode
五蕴非空8 天前
AI工具实践日记(二):在 OpenClaw 中调用 OpenCode 进行开发任务
ai助手·openspec·opencode·openclaw
骤跌9 天前
04-智能体协同工作架构设计
架构设计·opencode