Communitygithub.com

取消

取消任何活躍的 OMC 模式(autopilot、ralph、ultragoal、swarm、ultrapilot、pipeline、team)並清理已退役的舊有狀態。

取消 是什麼?

此技能提供一個統一的標準方式來完成與退出任何 OMC(Oh My Claude Code)模式,包括 Autopilot、Ralph、Ultragoal、Swarm、Ultrapilot、Pipeline 以及 Team 模式。當停止鉤子(stop hook)偵測到工作完成時,它會指示 LLM 調用此技能,以確保所有相關的運行時狀態、檔案和遺留的舊有工件都被正確清理。它會根據目前啟用的模式自動偵測並執行最適當的取消流程。例如,對於 Autopilot,它會暫停工作流程但保留進度以供後續恢復;對於 Team,它會協調一個雙階段(優雅關閉 + 協調)的通訊協定,向所有活躍的團隊成員發送訊息請求關閉。如果標準的 `state_clear` MCP 工具不可用或因故失敗,該技能也提供了一個基於 Bash 的緊急後備方案,可以直接刪除狀態檔案。請注意,這個後備方案並非完整替代方案,對於 Autopilot 或 omc-teams 等模式不應使用,因為它們需要特定的 `state_write` 操作或 tmux session 清理。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Yeachan-Heo/oh-my-claudecode/tree/main/skills/cancel

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

取消技能

智慧型取消功能,可自動偵測並取消活躍的 OMC 模式。

取消技能是完成並退出任何 OMC 模式的標準方式。 當停止鉤子偵測到工作完成時,它會指示 LLM 調用此技能以進行適當的狀態清理。如果取消失敗或中斷,請使用 --force 標誌重試,或等待 2 小時的過時逾時作為最後手段。

功能說明

自動偵測目前哪個模式正在啟用並將其取消:

  • Autopilot:停止工作流程,保留進度以便恢復
  • Ralph:停止持續性循環
  • Legacy Ultrawork 狀態:僅針對升級安裝進行清理移除;非活躍工作流程
  • UltraQA(已退役):無殘留的工作流程;若存在則清除陳舊的 5.0.0 以前版本的 ultraqa-state.json
  • Ultragoal:清除 session 範圍內的 ultragoal 運行時防護檔案(.omc/state/.../ultragoal-state.json),以便釋放 PreToolUse /goal 強制檢查與 Stop 強化機制。保留持久性的 .omc/ultragoal/ 計劃/帳本工件。
  • Swarm:停止協調式 Agent 群體,釋放已認領的任務
  • Ultrapilot:停止並行的 Autopilot 工作者
  • Pipeline:停止順序式 Agent 流程
  • Team:透過活躍的團隊/對話介面向所有團隊成員請求關閉,等待回應/超時,清除 OMC 團隊狀態,若存在則清除連結的 Ralph。Claude Code 2.1.178+ 無 TeamDelete 功能。
  • Team+Ralph(已連結):先取消團隊(優雅關閉),然後清除 Ralph 狀態。當已連結時取消 Ralph 也會先取消團隊。

使用方法

/oh-my-claudecode:cancel

或者說:「cancelomc」、「stopomc」

關鍵:延遲工具處理

狀態管理工具(state_clear、state_read、state_write、state_list_active、state_get_status)可能被 Claude Code 註冊為延遲工具。在呼叫任何狀態工具之前,您必須先透過 ToolSearch 載入所有這些工具:

ToolSearch(query="select:mcp__plugin_oh-my-claudecode_t__state_clear,mcp__plugin_oh-my-claudecode_t__state_read,mcp__plugin_oh-my-claudecode_t__state_write,mcp__plugin_oh-my-claudecode_t__state_list_active,mcp__plugin_oh-my-claudecode_t__state_get_status")

如果 state_clear 不可用或失敗,請使用此 bash 後備方案作為停止鉤子循環的緊急逃脫出口。這不是取消流程的完整替代方案——它僅移除狀態檔案以解除 session 的封鎖。已連結的活躍模式(例如 autopilot→ralph)必須透過為每個模式各執行一次後備方案來分別清除。

將 MODE 替換為特定模式(例如 ralplan、ralph、ultrawork、ultragoal)。

警告: 請勿對 autopilot 或 omc-teams 使用此後備方案。Autopilot 需要 state_write(active=false) 來保留恢復資料。omc-teams 需要 tmux session 清理,無法僅透過檔案刪除來完成。

# 後備方案:當 state_clear MCP 工具不可用時,直接刪除檔案
SESSION_ID="${CLAUDE_SESSION_ID:-${CLAUDECODE_SESSION_ID:-}}"
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || { d="$PWD"; while [ "$d" != "/" ] && [ ! -d "$d/.omc" ]; do d="$(dirname "$d")"; done; echo "$d"; })"

# 跨平台 SHA-256(macOS:shasum,Linux:sha256sum)
sha256portable() { printf '%s' "$1" | (sha256sum 2>/dev/null || shasum -a 256) | cut -c1-16; }

# 解析狀態目錄(支援 OMC_STATE_DIR 集中式儲存)
if [ -n "${OMC_STATE_DIR:-}" ]; then
  # 鏡像 worktree-paths.ts 中的 getProjectIdentifier()
  SOURCE="$(git remote get-url origin 2>/dev/null || echo "$REPO_ROOT")"
  HASH="$(sha256portable "$SOURCE")"
  DIR_NAME="$(basename "$REPO_ROOT" | sed 's/[^a-zA-Z0-9_-]/_/g')"
  OMC_STATE="$OMC_STATE_DIR/${DIR_NAME}-${HASH}/state"
  [ ! -d "$OMC_STATE" ] && { echo "ERROR: State dir not found at $OMC_STATE" >&2; exit 1; }
elif [ "$REPO_ROOT" != "/" ] && [ -d "$REPO_ROOT/.omc" ]; then
  OMC_STATE="$REPO_ROOT/.omc/state"
else
  echo "ERROR: Could not locate .omc state directory" >&2
  exit 1
fi
MODE="ralplan"  # <-- 替換為目標模式

# 清除特定模式的 session 範圍狀態
if [ -n "$SESSION_ID" ] && [ -d "$OMC_STATE/sessions/$SESSION_ID" ]; then
  rm -f "$OMC_STATE/sessions/$SESSION_ID/${MODE}-state.json"
  rm -f "$OMC_STATE/sessions/$SESSION_ID/${MODE}-stop-breaker.json"
  rm -f "$OMC_STATE/sessions/$SESSION_ID/skill-active-state.json"
  # 寫入取消訊號,以便停止鉤子偵測到正在進行的取消
  NOW_ISO="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
  EXPIRES_ISO="$(date -u -d "+30 seconds" +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null || python3 - <<'PY'\nfrom datetime import datetime, timedelta, timezone\nprint((datetime.now(timezone.utc) + timedelta(seconds=30)).strftime('%Y-%m-%dT%H:%M:%SZ'))\nPY\n)"
  printf '{"active":true,"requested_at":"%s","expires_at":"%s","mode":"%s","source":"bash_fallback"}' \
    "$NOW_ISO" "$EXPIRES_ISO" "$MODE" > "$OMC_STATE/sessions/$SESSION_ID/cancel-signal-state.json"
fi

# 僅在沒有 session ID 時清除舊有狀態(避免清除其他 session 的狀態)
if [ -z "$SESSION_ID" ]; then
  rm -f "$OMC_STATE/${MODE}-state.json"
fi

自動偵測

/oh-my-claudecode:cancel 遵循 session 感知狀態合約:

  • 預設情況下,該命令透過 state_list_active 和 state_get_status 檢查目前 session,導航 .omc/state/sessions/{sessionId}/… 以發現哪個模式處於啟用狀態。
  • 當提供了 session ID 或已知時,該 session 範圍路徑即為權威路徑。僅當 session ID 缺失或為空時,才將 .omc/state/*.json 中的舊有檔案作為相容性後備方案進行查詢。
  • Swarm 是一種共享的 SQLite/標記模式(.omc/state/swarm.db / .omc/state/swarm-active.marker),不在 session 範圍內。
  • 預設的清理流程會呼叫帶有 session ID 的 state_clear,以僅移除相符的 session 檔案;模式保持綁定到其原始 session。

活躍模式仍按依賴順序取消:

  1. Autopilot(包括已連結的 Ralph 和退役狀態清理)
  2. Ralph
  3. 舊有 Ultrawork/UltraQA 狀態清理
  4. Ultragoal(獨立運行時防護 — state_clear(mode="ultragoal");保留持久性的 .omc/ultragoal/ 工件)
  5. Swarm(獨立)
  6. Ultrapilot(獨立)
  7. Pipeline(獨立)
  8. Team(Claude Code 原生)
  9. OMC Teams(tmux CLI 工作者)
  10. Plan Consensus(獨立)
  11. Self-Improve(獨立 — 清除狀態,清理孤立工作樹,保留迭代狀態以供恢復,在已解析的 <self-improve-root>/state/agent-settings.json 中設定狀態為 "user_stopped";新的執行使用 .omc/self-improve/topics/<topic-slug>/,扁平 .omc/self-improve/ 僅保留用於舊有單一軌道恢復)

強制清除所有

當您需要刪除所有 session 及舊有工件,例如完全重設工作區時,請使用 --force 或 --all。

/oh-my-claudecode:cancel --force
/oh-my-claudecode:cancel --all

底層步驟:

  1. state_list_active 列舉 .omc/state/sessions/{sessionId}/… 以找到每個已知的 session。
  2. state_clear 為每個 session 執行一次,以刪除該 session 的檔案。
  3. 全域性的 state_clear(不帶 session_id)會移除 .omc/state/*.json、.omc/state/swarm*.db 和相容性工件(見清單)下的舊有檔案。
  4. Team 工件(~/.claude/teams/*/、~/.claude/tasks/*/、.omc/state/team-state.json)作為舊有後備方案的一部分,以盡力而為的方式清除。
    • 取消原生 team 不會影響 omc-teams 狀態,反之亦然。

每個 state_clear 命令都遵循 session_id 參數,因此即使是強制模式,也會在刪除舊有檔案之前先使用 session 感知路徑。

舊有相容性清單(僅在 --force/--all 下移除):

  • .omc/state/autopilot-state.json
  • .omc/state/ralph-state.json
  • .omc/state/ralph-plan-state.json
  • .omc/state/ralph-verification.json
  • .omc/state/ultrawork-state.json
  • .omc/state/ultraqa-state.json
  • .omc/state/swarm.db
  • .omc/state/swarm.db-wal
  • .omc/state/swarm.db-shm
  • .omc/state/swarm-active.marker
  • .omc/state/swarm-tasks.db
  • .omc/state/ultrapilot-state.json
  • .omc/state/ultrapilot-ownership.json
  • .omc/state/pipeline-state.json
  • .omc/state/omc-teams-state.json
  • .omc/state/plan-consensus.json
  • .omc/state/ralplan-state.json
  • .omc/state/boulder.json
  • .omc/state/hud-state.json
  • .omc/state/subagent-tracking.json
  • .omc/state/subagent-tracker.lock
  • .omc/state/rate-limit-daemon.pid
  • .omc/state/rate-limit-daemon.log
  • .omc/state/checkpoints/(目錄)
  • .omc/state/sessions/(清理 session 後的空目錄清理)

實作步驟

當您調用此技能時:

1. 解析參數

# 檢查 --force 或 --all 標誌
FORCE_MODE=false
if [[ "$*" == *"--force"* ]] || [[ "$*" == *"--all"* ]]; then
  FORCE_MODE=true
fi

2. 偵測活躍模式

該技能現在依賴 session 感知狀態合約,而非硬編碼的檔案路徑:

  1. 呼叫 state_list_active 以列舉 .omc/state/sessions/{sessionId}/… 並發現每個活躍的 session。
  2. 對於每個 session ID,呼叫 state_get_status 以了解哪個活躍模式正在運行以及是否存在依賴模式;將任何 Ultrawork 記錄僅視為退役清理的輸入。
  3. 如果提供了 session_id 給 /oh-my-claudecode:cancel,則完全跳過舊有後備方案,僅在該 session 路徑內操作;否則,僅在狀態工具報告無活躍 session 時才查詢 .omc/state/*.json 中的舊有檔案。Swarm 仍然是 session 範圍之外的共享 SQLite/標記模式。
  4. 本文檔中的任何取消邏輯都反映了透過狀態工具發現的依賴順序(autopilot → ralph → …)。

3A. 強制模式(如果使用 --force 或 --all)

使用強制模式透過 state_clear 清除所有 session 及舊有工件。當狀態工具報告無活躍 session 時,直接刪除檔案的操作保留用於舊有清理。

3B. 智慧取消(預設)

如果 Team 活躍(Claude Code 隱式團隊)

團隊是透過 OMC 團隊狀態偵測的,而不是透過已移除的 Claude Code ~/.claude/teams 設定目錄:

# 檢查活躍的 OMC 團隊狀態
state_read(mode="team")

雙階段取消協定:

階段 1:優雅關閉

針對活躍的 OMC 團隊狀態:
  1. 從 OMC 狀態/交接/任務帳本中讀取 team_name 和工作標籤
  2. 對於每個活躍的團隊成員:
     a. 透過活躍的對話/團隊訊息介面向具名團隊成員提問或通知
     b. 最多等待 15 秒以獲得 shutdown_response
     c. 如果收到回應:將該成員標記為已確認
     d. 如果逾時:將該成員標記為無回應,繼續處理下一個
  3. 記錄:「優雅處理階段:X/Y 位成員已回應」

階段 2:協調

在優雅處理階段之後:
  1. 再等待 5 秒,以便可能仍在處理中的無回應團隊成員
  2. 在取消報告中記錄任何剩餘的無回應團隊成員
  3. 不要呼叫 TeamDelete;Claude Code 2.1.178+ 移除了每個團隊的原生清理功能

OMC 狀態清理:

  1. 清除團隊狀態:state_clear(mode="team")
  2. 檢查已連結的 ralph:state_read(mode="ralph") — 如果 linked_team 為 true:
     a. 清除 ralph 狀態:state_clear(mode="ralph")
  3. 僅對舊有 `omc team` / `/omc-teams` 工作者執行 OMC tmux/CLI 孤立進程掃描(見下文)
  4. 發出結構化取消報告

孤立進程偵測(清理後):

對於舊有 OMC tmux/CLI 工作者執行,請驗證沒有工作者程序殘留:

node "${CLAUDE_PLUGIN_ROOT}/scripts/cleanup-orphans.mjs" --team-name "{team_name}"

孤立進程掃描器:

  1. 檢查 ps aux(Unix)或 tasklist(Windows)中帶有 --team-name 且符合已清理團隊的 OMC 工作者程序
  2. 發送 SIGTERM,等待 5 秒,如果程序仍然存活則發送 SIGKILL
  3. 以 JSON 格式報告清理結果

使用 --dry-run 來檢查而不終止程序。掃描器可以安全地多次執行。

結構化取消報告:

團隊「{team_name}」已取消:
  - 已通知的成員數:N
  - 收到的回應數:M
  - 無回應:K(如果有,列出名稱)
  - OMC 狀態已清除:是/否
  - 是否需要手動清理:是/否
    路徑:OMC 團隊狀態 / tmux 工作者程序(如果有的話)

**實作注意事項:**取消技能由 LLM 執行,而非 bash 腳本。當您偵測到活躍的團隊時:

  1. 讀取 state_read(mode="team") 以找到活躍的 OMC 團隊
  2. 從狀態、交接或任務帳本中識別活躍的具名團隊成員
  3. 對於每個團隊成員,透過活躍的對話/團隊訊息介面向其提問或通知
  4. 短暫等待關閉回應(每個成員逾時 15 秒)
  5. 在協調等待後記錄無回應的團隊成員
  6. 清除團隊狀態:state_clear(mode="team", session_id)
  7. 向使用者報告結構化摘要

如果 Autopilot 活躍

Autopilot 處理其自己的主要優先清理:命名工作流程會額外僅移除其 session 擁有的巢狀 ralplan 強制狀態,然後才進行已連結的 ralph 和退役的 ultraqa 清理。

  1. 透過 state_read(mode="autopilot", session_id) 讀取 autopilot 狀態,以捕捉確切的目前執行,包括 workflowRunId(如果存在)。
  2. 使用精確的變異操作 state_write(mode="autopilot", session_id, active=false, state={workflowRunId: "<exact run id>"}) 暫停該確切執行。請不要重播或複製狀態回讀。在 Linux 上使用 flock,該工具會在其變異鎖定下重新驗證所持有的執行和工作流程完整性,然後才將 active 變更為 false;它會保留工作流程、流程追蹤和任務身份。target_state_sha256 可能僅在它是目前序列化狀態的確切 SHA-256 時才包含。
    • 如果此寫入失敗,請立即停止。不要清除巢狀的 ralplan、已連結的狀態、取消訊號或運行時工件。
  3. 對於命名工作流程,僅清除由相同 session_id 擁有的 ralplan 狀態;絕對不要清除另一個 session 的獨立 ralplan 狀態。記錄失敗,但保持已暫停的主要任務可恢復。
  4. 僅在主要暫停提交之後,檢查已連結的 ralph 狀態(透過 state_read(mode="...")) …

[後續內容已截斷以利翻譯]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

agent-doc-discipline

Writing-time discipline for documents agents consume (the five surfaces, specs, tickets, .omc/skills/) — every rule checkable and carrying a why, steps before reference, one meaning in one home, no restating what the environment already says. Mandatory at drydock seed generation and the launch C5 sediment pass; opt-in for any other agent-facing doc edit. The companion of minimal-code-discipline: that one disciplines code, this one disciplines papers.

ai-slop-cleaner

Clean AI-generated code slop with a regression-safe, deletion-first workflow and optional reviewer-only mode

ask

Process-first advisor routing for Claude, Codex, Gemini, Antigravity, Grok, or Cursor via `omc ask`, with artifact capture and no raw CLI assembly

ask-navigator

Shipyard

autopilot

Full autonomous execution from idea to working code

autoresearch

Stateful single-mission improvement loop with strict evaluator contract, markdown decision logs, and max-runtime stop behavior

configure-notifications

Configure notification integrations (Telegram, Discord, Slack) via natural language

debug

Diagnose the current OMC session or repo state using logs, traces, state, and focused reproduction

deepinit

Deep codebase initialization with hierarchical AGENTS.md documentation

deep-interview

Socratic deep interview with mathematical ambiguity gating before explicit execution approval

drydock

Lay the keel of the shipyard harness in any repo — the 4-pillar shared environment (Context, Rules, Tools, Standards) across 5 surfaces (CLAUDE.md, skills, design-system, mcp/cli, shared context) so that every human and agent inherits the same design language and anyone can ship. Run once per repo; re-run with --check to audit drift.

execute

Carry an approved task through to working, verified code

external-context

Invoke parallel document-specialist agents for external web searches and documentation lookup

graph

Deterministic orchestration graph runtime - declarative DAG pipelines with journal-based crash recovery

harbor

Harbor intake for external work — the captain only handles unresolved decisions. Sweeps incoming issues and PRs, verifies every claim before disposition, reuses every decision already made, and hands the maintainer a docket whose pending items each carry one question with options, recommendation, impact and evidence. Agent-autonomous for facts and for actions covered by standing authorization; signed for every new judgment. Never merges.

hud

Configure HUD display options (layout, presets, display elements)

launch

Shipyard

loft

Loft the shape before cutting steel — answer a design question that prose cannot settle by building a throwaway artifact: a pure logic module in a clickable shell, or structurally different UI variants behind one route. The captain reacts to the artifact; the answer folds into the decision; the artifact never docks. Use when a design question stalls in words, when a navigator map carries a loft ticket, or when a spec discussion reaches

minimal-code-discipline

YAGNI-ladder coding discipline for writing changes — existence-first, reuse before writing, dependency ladder, shortest correct diff, with non-negotiables that must never be minimized away

omc-doctor

Diagnose and fix oh-my-claudecode installation issues

相關技能