Doctor 技能
注意:本指南中所有 ~/.claude/... 路徑皆會遵循 CLAUDE_CONFIG_DIR 環境變數(若有設定)。
任務:執行安裝診斷
您是 OMC Doctor —— 負責診斷並修復安裝問題。
步驟 1:檢查外掛版本
# 取得已安裝版本與最新版本(跨平台)
node -e "const p=require('path'),f=require('fs'),h=require('os').homedir(),d=process.env.CLAUDE_CONFIG_DIR||p.join(h,'.claude'),b=p.join(d,'plugins','cache','omc','oh-my-claudecode');try{const v=f.readdirSync(b).filter(x=>/^\d/.test(x)).sort((a,c)=>a.localeCompare(c,void 0,{numeric:true}));console.log('Installed:',v.length?v[v.length-1]:'(none)')}catch{console.log('Installed: (none)')}"
npm view oh-my-claude-sisyphus version 2>/dev/null || echo "Latest: (unavailable)"
診斷結果:
- 若無任何版本安裝:嚴重 —— 外掛未安裝
- 若 INSTALLED != LATEST:警告 —— 外掛過期
- 若存在多個版本:警告 —— 快取內容過舊
步驟 2:檢查 settings.json 中的舊版鉤子
讀取 ${CLAUDE_CONFIG_DIR:-~/.claude}/settings.json(個人層級)和 ./.claude/settings.json(專案層級),檢查是否有 "hooks" 鍵且內容包含:
bash ${CLAUDE_CONFIG_DIR:-$HOME/.claude}/hooks/keyword-detector.shbash ${CLAUDE_CONFIG_DIR:-$HOME/.claude}/hooks/persistent-mode.shbash ${CLAUDE_CONFIG_DIR:-$HOME/.claude}/hooks/session-start.sh
診斷結果:
- 若找到:嚴重 —— 舊版鉤子造成重複
步驟 3:檢查舊版 Bash 鉤子腳本
ls -la "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/hooks/*.sh 2>/dev/null
診斷結果:
- 若
keyword-detector.sh、persistent-mode.sh、session-start.sh或stop-continuation.sh存在:警告 —— 舊版腳本(可能造成混淆)
步驟 4:檢查 CLAUDE.md
# 檢查 CLAUDE.md 是否存在
ls -la "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/CLAUDE.md 2>/dev/null
# 檢查是否有 OMC 標記(標準標記為 <!-- OMC:START -->)
grep -q "<!-- OMC:START -->" "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/CLAUDE.md" 2>/dev/null && echo "Has OMC config" || echo "Missing OMC config in CLAUDE.md"
# 檢查 CLAUDE.md(或確定性伴隨檔案)的版本標記,並與最新安裝的快取版本比對
node -e "const p=require('path'),f=require('fs'),h=require('os').homedir(),d=process.env.CLAUDE_CONFIG_DIR||p.join(h,'.claude');const base=p.join(d,'CLAUDE.md');let baseContent='';try{baseContent=f.readFileSync(base,'utf8')}catch{};let candidates=[base];let referenced='';const importMatch=baseContent.match(/CLAUDE-[^ )]*\\.md/);if(importMatch){referenced=p.join(d,importMatch[0]);candidates.push(referenced)}else{const defaultCompanion=p.join(d,'CLAUDE-omc.md');if(f.existsSync(defaultCompanion))candidates.push(defaultCompanion);try{const others=f.readdirSync(d).filter(n=>/^CLAUDE-.*\\.md$/i.test(n)).sort().map(n=>p.join(d,n));for(const o of others){if(candidates.includes(o)===false)candidates.push(o)}}catch{}};let claudeV='(missing)';let claudeSource='(none)';for(const file of candidates){try{const c=f.readFileSync(file,'utf8');const m=c.match(/<!--\\s*OMC:VERSION:([^\\s]+)\\s*-->/i);if(m){claudeV=m[1];claudeSource=file;break}}catch{}};if(claudeV==='(missing)'&&candidates.length>0){claudeV='(missing marker)';claudeSource='scanned deterministic CLAUDE sources';};let pluginV='(none)';try{const b=p.join(d,'plugins','cache','omc','oh-my-claudecode');const v=f.readdirSync(b).filter(x=>/^\\d/.test(x)).sort((a,c)=>a.localeCompare(c,void 0,{numeric:true}));pluginV=v.length?v[v.length-1]:'(none)';}catch{};console.log('CLAUDE.md OMC version:',claudeV);console.log('OMC version source:',claudeSource);console.log('Latest cached plugin version:',pluginV);if(claudeV==='(missing)'||claudeV==='(missing marker)'||pluginV==='(none)'){console.log('VERSION CHECK SKIPPED: missing CLAUDE marker or plugin cache')}else if(claudeV===pluginV){console.log('VERSION MATCH: CLAUDE and plugin cache are aligned')}else{console.log('VERSION DRIFT: CLAUDE.md and plugin versions differ')}"
# 檢查檔案分割模式的伴隨檔案(例如 CLAUDE-omc.md)
find "${CLAUDE_CONFIG_DIR:-$HOME/.claude}" -maxdepth 1 -type f -name 'CLAUDE-*.md' -print 2>/dev/null
while IFS= read -r f; do
grep -q "<!-- OMC:START -->" "$f" 2>/dev/null && echo "Has OMC config in companion: $f"
done < <(find "${CLAUDE_CONFIG_DIR:-$HOME/.claude}" -maxdepth 1 -type f -name 'CLAUDE-*.md' -print 2>/dev/null)
# 檢查 CLAUDE.md 是否引用了伴隨檔案
grep -o "CLAUDE-[^ )]*\.md" "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/CLAUDE.md" 2>/dev/null
診斷結果:
- 若 CLAUDE.md 不存在:嚴重 —— CLAUDE.md 未設定
- 若在 CLAUDE.md 中找到
<!-- OMC:START -->:正常 - 若在伴隨檔案(例如
CLAUDE-omc.md)中找到<!-- OMC:START -->:正常 —— 偵測到檔案分割模式 - 若在 CLAUDE.md 或任何伴隨檔案中皆無 OMC 標記:警告 —— CLAUDE.md 過期
- 若在確定性 CLAUDE 來源掃描(基礎檔案 + 引用的伴隨檔案)中缺少
OMC:VERSION標記:警告 —— 無法驗證 CLAUDE.md 時效性 - 若
CLAUDE.md OMC version!=Latest cached plugin version:警告 —— 版本偏移(請執行omc update或omc setup)
步驟 5:檢查 Ralph 執行階段必要條件
Ralph 是由代理驅動的持續運作循環,並非編譯程式:其唯一硬性執行階段必要條件是 Node 執行環境(用於執行 OMC 的鉤子腳本 persistent-mode.mjs、keyword-detector.mjs)以及一個可寫入的設定目錄,用於存放 .omc/state/ 狀態檔案(例如 ralph-state.json)。
node --version || echo "Node for Ralph: MISSING"
mkdir -p "${CLAUDE_CONFIG_DIR:-$HOME/.claude}" 2>/dev/null
touch "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.omc-write-probe" 2>/dev/null && rm -f "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.omc-write-probe" && echo "Config dir writable" || echo "Config dir NOT writable"
診斷結果:
- 若 Node 可執行並顯示版本:正常 —— Ralph 執行階段必要條件已滿足
- 若缺少
node或執行失敗:嚴重 —— 若無 Node,OMC 鉤子與 Ralph 無法執行(請參閱 https://nodejs.org 下載安裝程式;使用 nvm/fnm 的使用者需確保 Node 在非互動式 shell 的 PATH 中) - 若設定目錄不可寫入:警告 —— Ralph 狀態持久化將失敗,直到目錄可寫入為止
步驟 6:檢查過時的快取
# 計算快取中的版本數量(跨平台)
node -e "const p=require('path'),f=require('fs'),h=require('os').homedir(),d=process.env.CLAUDE_CONFIG_DIR||p.join(h,'.claude'),b=p.join(d,'plugins','cache','omc','oh-my-claudecode');try{const v=f.readdirSync(b).filter(x=>/^\d/.test(x));console.log(v.length+' version(s):',v.join(', '))}catch{console.log('0 versions')}"
診斷結果:
- 若超過 1 個版本:警告 —— 快取中有多個版本(建議清理)
步驟 7:檢查舊版 Curl 安裝內容
檢查透過 curl (在外掛系統之前)安裝的舊版 agents、commands 與 skills。 重要:僅標記檔案名稱與外掛實際提供名稱相符的檔案。請勿標記用戶自訂且與 OMC 無關的 agents/commands/skills。
# 檢查舊版 agents 目錄
ls -la "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/agents/ 2>/dev/null
# 檢查舊版 commands 目錄
ls -la "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/commands/ 2>/dev/null
# 檢查舊版 skills 目錄
ls -la "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/skills/ 2>/dev/null
診斷結果:
- 若
~/.claude/agents/存在且包含與外掛 agent 名稱相符的檔案:警告 —— 舊版 agents(現由外掛提供) - 若
~/.claude/commands/存在且包含與外掛 command 名稱相符的檔案:警告 —— 舊版 commands(現由外掛提供) - 若
~/.claude/skills/存在且包含與外掛 skill 名稱相符的檔案:警告 —— 舊版 skills(現由外掛提供) - 若存在與外掛名稱不符的自訂檔案:正常 —— 這是用戶自訂內容,請勿標記
已知外掛 agent 名稱(檢查 agents/ 中是否有這些):
architect.md, document-specialist.md, explore.md, executor.md, debugger.md, planner.md, analyst.md, critic.md, verifier.md, test-engineer.md, designer.md, writer.md, qa-tester.md, scientist.md, security-reviewer.md, code-reviewer.md, git-master.md, code-simplifier.md
已知外掛 skill 名稱(檢查 skills/ 中是否有這些):
ai-slop-cleaner, ask, autopilot, cancel, configure-notifications, deep-interview, deepinit, external-context, hud, omc-doctor, omc-setup, plan, project-session-manager, ralph, ralplan, release, skill, team, visual-verdict, wiki
已知外掛 command 名稱(檢查 commands/ 中是否有這些):
deepsearch.md
報告格式
執行所有檢查後,產生一份報告:
## OMC Doctor 報告
### 摘要
[健康 / 發現問題]
### 檢查
| 檢查項目 | 狀態 | 詳細說明 |
|----------|------|----------|
| 外掛版本 | 正常/警告/嚴重 | ... |
| 舊版鉤子(settings.json) | 正常/嚴重 | ... |
| 舊版腳本(~/.claude/hooks/) | 正常/警告 | ... |
| CLAUDE.md | 正常/警告/嚴重 | ... |
| Ralph 執行階段必要條件(Node、config 目錄) | 正常/嚴重 | ... |
| 外掛快取 | 正常/警告 | ... |
| 舊版 Agents(~/.claude/agents/) | 正常/警告 | ... |
| 舊版 Commands(~/.claude/commands/) | 正常/警告 | ... |
| 舊版 Skills(~/.claude/skills/) | 正常/警告 | ... |
### 發現的問題
1. [問題描述]
2. [問題描述]
### 建議的修復
[根據問題列出修復方式]
自動修復(若用戶確認)
若發現問題,詢問用戶:「是否要我自動修復這些問題?」
若是,則套用修復:
修復:settings.json 中的舊版鉤子
從 ${CLAUDE_CONFIG_DIR:-~/.claude}/settings.json 中移除 "hooks" 區段(保留其他設定不變)
修復:舊版 Bash 腳本
rm -f "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/hooks/keyword-detector.sh
rm -f "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/hooks/persistent-mode.sh
rm -f "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/hooks/session-start.sh
rm -f "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/hooks/stop-continuation.sh
修復:過期的外掛
# 清除外掛快取(跨平台)
node -e "const p=require('path'),f=require('fs'),d=process.env.CLAUDE_CONFIG_DIR||p.join(require('os').homedir(),'.claude'),b=p.join(d,'plugins','cache','omc','oh-my-claudecode');try{f.rmSync(b,{recursive:true,force:true});console.log('Plugin cache cleared. Restart Claude Code to fetch latest version.')}catch{console.log('No plugin cache found')}"
修復:過時的快取(多個版本)
# 僅保留最新版本(跨平台)
node -e "const p=require('path'),f=require('fs'),h=require('os').homedir(),d=process.env.CLAUDE_CONFIG_DIR||p.join(h,'.claude'),b=p.join(d,'plugins','cache','omc','oh-my-claudecode');try{const v=f.readdirSync(b).filter(x=>/^\d/.test(x)).sort((a,c)=>a.localeCompare(c,void 0,{numeric:true}));v.slice(0,-1).forEach(x=>f.rmSync(p.join(b,x),{recursive:true,force:true}));console.log('Removed',v.length-1,'old version(s)')}catch(e){console.log('No cache to clean')}"
修復:遺失/過期的 CLAUDE.md
從 GitHub 取得最新版本並寫入 ${CLAUDE_CONFIG_DIR:-~/.claude}/CLAUDE.md:
WebFetch(url: "https://raw.githubusercontent.com/Yeachan-Heo/oh-my-claudecode/main/docs/CLAUDE.md", prompt: "Return the complete raw markdown content exactly as-is")
修復:舊版 Curl 安裝內容
移除由 curl 安裝的舊版 agents、commands 與 skills 目錄(現由外掛提供):
# 可選:先備份(詢問用戶)
# mv "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/agents "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/agents.bak
# mv "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/commands "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/commands.bak
# mv "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/skills "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/skills.bak
# 或直接刪除
rm -rf "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/agents
rm -rf "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/commands
rm -rf "${CLAUDE_CONFIG_DIR:-$HOME/.claude}"/skills
注意:僅在這些目錄包含 oh-my-claudecode 相關檔案時才移除。若用戶有自訂的 agents/commands/skills,請先警告並在移除前詢問。
修復後
套用修復後,告知用戶:
已套用修復。請重新啟動 Claude Code 以使變更生效。