cancel
Cancel any active OMQ mode (autopilot, ralph, ultrawork, ultraqa, swarm, ultrapilot, pipeline, team)
来源信息
- 仓库
- spring-ai-alibaba/oh-my-qoder
- 最近来源活动
- 2026年7月1日 04:36
- 检测到的 SKILL.md 语言
- 英语
- 星标
- 4
- 分支
- 1
安装方式
默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。
检查来源文件
决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。
正在显示 SKILL.md
SKILL.md
来源说明 · 只读预览- name
- cancel
- aliases
- ["cancel-ralph"]
- description
- Cancel any active OMQ mode (autopilot, ralph, ultrawork, ultraqa, swarm, ultrapilot, pipeline, team)
- argument-hint
- [--force|--all]
- level
- 2
# Cancel Skill
Intelligent cancellation that detects and cancels the active OMQ mode.
**The cancel skill is the standard way to complete and exit any OMQ mode.**
When the stop hook detects work is complete, it instructs the LLM to invoke
this skill for proper state cleanup. If cancel fails or is interrupted,
retry with `--force` flag, or wait for the 2-hour staleness timeout as
a last resort.
## What It Does
Automatically detects which mode is active and cancels it:
- **Autopilot**: Stops workflow, preserves progress for resume
- **Ralph**: Stops persistence loop, clears linked ultrawork if applicable
- **Ultrawork**: Stops parallel execution (standalone or linked)
- **UltraQA**: Stops QA cycling workflow
- **Swarm**: Stops coordinated agent swarm, releases claimed tasks
- **Ultrapilot**: Stops parallel autopilot workers
- **Pipeline**: Stops sequential agent pipeline
- **Team**: Sends shutdown_request to all teammates, waits for responses, calls TeamDelete, clears linked ralph if present
- **Team+Ralph (linked)**: Cancels team first (graceful shutdown), then clears ralph state. Cancelling ralph when linked also cancels team first.
## Usage
```
/oh-my-qoder:cancel
```
Or say: "cancelomq", "stopomq"
## Critical: Deferred Tool Handling
The state management tools (`state_clear`, `state_read`, `state_write`, `state_list_active`,
`state_get_status`) may be registered as **deferred tools** by Qoder CLI. Before calling
any state tool, you MUST first load all of them via `ToolSearch`:
```
ToolSearch(query="select:mcp__plugin_oh-my-qoder_t__state_clear,mcp__plugin_oh-my-qoder_t__state_read,mcp__plugin_oh-my-qoder_t__state_write,mcp__plugin_oh-my-qoder_t__state_list_active,mcp__plugin_oh-my-qoder_t__state_get_status")
```
If `state_clear` is unavailable or fails, use this **bash fallback** as an **emergency
escape from the stop hook loop**. This is NOT a full replacement for the cancel flow —
it only removes state files to unblock the session. Linked modes (e.g. ralph→ultrawork,
autopilot→ralph/ultraqa) must be cleared separately by running the fallback once per mode.
Replace `MODE` with the specific mode (e.g. `ralplan`, `ralph`, `ultrawork`, `ultraqa`).
**WARNING:** Do NOT use this fallback for `autopilot` or `omq-teams`. Autopilot requires
`state_write(active=false)` to preserve resume data. omq-teams requires tmux session
cleanup that cannot be done via file deletion alone.
```bash
# Fallback: direct file removal when state_clear MCP tool is unavailable
SESSION_ID="${CLAUDE_SESSION_ID:-${CLAUDECODE_SESSION_ID:-}}"
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || { d="$PWD"; while [ "$d" != "/" ] && [ ! -d "$d/.omq" ]; do d="$(dirname "$d")"; done; echo "$d"; })"
# Cross-platform SHA-256 (macOS: shasum, Linux: sha256sum)
sha256portable() { printf '%s' "$1" | (sha256sum 2>/dev/null || shasum -a 256) | cut -c1-16; }
# Resolve state directory (supports OMQ_STATE_DIR centralized storage)
if [ -n "${OMQ_STATE_DIR:-}" ]; then
# Mirror getProjectIdentifier() from worktree-paths.ts
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')"
OMQ_STATE="$OMQ_STATE_DIR/${DIR_NAME}-${HASH}/state"
[ ! -d "$OMQ_STATE" ] && { echo "ERROR: State dir not found at $OMQ_STATE" >&2; exit 1; }
elif [ "$REPO_ROOT" != "/" ] && [ -d "$REPO_ROOT/.omq" ]; then
OMQ_STATE="$REPO_ROOT/.omq/state"
else
echo "ERROR: Could not locate .omq state directory" >&2
exit 1
fi
MODE="ralplan" # <-- replace with the target mode
# Clear session-scoped state for the specific mode
if [ -n "$SESSION_ID" ] && [ -d "$OMQ_STATE/sessions/$SESSION_ID" ]; then
rm -f "$OMQ_STATE/sessions/$SESSION_ID/${MODE}-state.json"
rm -f "$OMQ_STATE/sessions/$SESSION_ID/${MODE}-stop-breaker.json"
rm -f "$OMQ_STATE/sessions/$SESSION_ID/skill-active-state.json"
# Write cancel signal so stop hook detects cancellation in progress
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" > "$OMQ_STATE/sessions/$SESSION_ID/cancel-signal-state.json"
fi
# Clear legacy state only if no session ID (avoid clearing another session's state)
if [ -z "$SESSION_ID" ]; then
rm -f "$OMQ_STATE/${MODE}-state.json"
fi
```
## Auto-Detection
`/oh-my-qoder:cancel` follows the session-aware state contract:
- By default the command inspects the current session via `state_list_active` and `state_get_status`, navigating `.omq/state/sessions/{sessionId}/…` to discover which mode is active.
- When a session id is provided or already known, that session-scoped path is authoritative. Legacy files in `.omq/state/*.json` are consulted only as a compatibility fallback if the session id is missing or empty.
- Swarm is a shared SQLite/marker mode (`.omq/state/swarm.db` / `.omq/state/swarm-active.marker`) and is not session-scoped.
- The default cleanup flow calls `state_clear` with the session id to remove only the matching session files; modes stay bound to their originating session.
Active modes are still cancelled in dependency order:
1. Autopilot (includes linked ralph/ultraqa/ cleanup)
2. Ralph (cleans its linked ultrawork or )
3. Ultrawork (standalone)
4. UltraQA (standalone)
5. Swarm (standalone)
6. Ultrapilot (standalone)
7. Pipeline (standalone)
8. Team (Qoder CLI native)
9. OMQ Teams (tmux CLI workers)
10. Plan Consensus (standalone)
11. Self-Improve (standalone — clear state, clean orphaned worktrees, preserve iteration_state for resume, set status: "user_stopped" in the resolved `<self-improve-root>/state/agent-settings.json`; new runs use `.omq/self-improve/topics/<topic-slug>/`, with flat `.omq/self-improve/` retained only for legacy single-track resumes)
## Force Clear All
Use `--force` or `--all` when you need to erase every session plus legacy artifacts, e.g., to reset the workspace entirely.
```
/oh-my-qoder:cancel --force
```
```
/oh-my-qoder:cancel --all
```
Steps under the hood:
1. `state_list_active` enumerates `.omq/state/sessions/{sessionId}/…` to find every known session.
2. `state_clear` runs once per session to drop that session’s files.
3. A global `state_clear` without `session_id` removes legacy files under `.omq/state/*.json`, `.omq/state/swarm*.db`, and compatibility artifacts (see list).
4. Team artifacts (`~/.qoder/teams/*/`, `~/.qoder/tasks/*/`, `.omq/state/team-state.json`) are best-effort cleared as part of the legacy fallback.
- Cancel for native team does NOT affect omq-teams state, and vice versa.
Every `state_clear` command honors the `session_id` argument, so even force mode still uses the session-aware paths first before deleting legacy files.
Legacy compatibility list (removed only under `--force`/`--all`):
- `.omq/state/autopilot-state.json`
- `.omq/state/ralph-state.json`
- `.omq/state/ralph-plan-state.json`
- `.omq/state/ralph-verification.json`
- `.omq/state/ultrawork-state.json`
- `.omq/state/ultraqa-state.json`
- `.omq/state/swarm.db`
- `.omq/state/swarm.db-wal`
- `.omq/state/swarm.db-shm`
- `.omq/state/swarm-active.marker`
- `.omq/state/swarm-tasks.db`
- `.omq/state/ultrapilot-state.json`
- `.omq/state/ultrapilot-ownership.json`
- `.omq/state/pipeline-state.json`
- `.omq/state/omq-teams-state.json`
- `.omq/state/plan-consensus.json`
- `.omq/state/ralplan-state.json`
- `.omq/state/boulder.json`
- `.omq/state/hud-state.json`
- `.omq/state/subagent-tracking.json`
- `.omq/state/subagent-tracker.lock`
- `.omq/state/rate-limit-daemon.pid`
- `.omq/state/rate-limit-daemon.log`
- `.omq/state/checkpoints/` (directory)
- `.omq/state/sessions/` (empty directory cleanup after clearing sessions)
## Implementation Steps
When you invoke this skill:
### 1. Parse Arguments
```bash
# Check for --force or --all flags
FORCE_MODE=false
if [[ "$*" == *"--force"* ]] || [[ "$*" == *"--all"* ]]; then
FORCE_MODE=true
fi
```
### 2. Detect Active Modes
The skill now relies on the session-aware state contract rather than hard-coded file paths:
1. Call `state_list_active` to enumerate `.omq/state/sessions/{sessionId}/…` and discover every active session.
2. For each session id, call `state_get_status` to learn which mode is running (`autopilot`, `ralph`, `ultrawork`, etc.) and whether dependent modes exist.
3. If a `session_id` was supplied to `/oh-my-qoder:cancel`, skip legacy fallback entirely and operate solely within that session path; otherwise, consult legacy files in `.omq/state/*.json` only if the state tools report no active session. Swarm remains a shared SQLite/marker mode outside session scoping.
4. Any cancellation logic in this doc mirrors the dependency order discovered via state tools (autopilot → ralph → …).
### 3A. Force Mode (if --force or --all)
Use force mode to clear every session plus legacy artifacts via `state_clear`. Direct file removal is reserved for legacy cleanup when the state tools report no active sessions.
### 3B. Smart Cancellation (default)
#### If Team Active (Qoder CLI native)
Teams are detected by checking for config files in `${CLAUDE_CONFIG_DIR:-~/.qoder}/teams/`:
```bash
# Check for active teams
TEAM_CONFIGS=$(find "${CLAUDE_CONFIG_DIR:-$HOME/.qoder}"/teams -name config.json -maxdepth 2 2>/dev/null)
```
**Two-pass cancellation protocol:**
**Pass 1: Graceful Shutdown**
```
For each team found in ${CLAUDE_CONFIG_DIR:-~/.qoder}/teams/:
1. Read config.json to get team_name and members list
2. For each non-lead member:
a. Send shutdown_request via SendMessage
b. Wait up to 15 seconds for shutdown_response
c. If response received: member terminates and is auto-removed
d. If timeout: mark member as unresponsive, continue to next
3. Log: "Graceful pass: X/Y members responded"
```
**Pass 2: Reconciliation**
```
After graceful pass:
1. Re-read config.json to check remaining members
2. If only lead remains (or config is empty): proceed to TeamDelete
3. If unresponsive members remain:
a. Wait 5 more seconds (they may still be processing)
b. Re-read config.json again
c. If still stuck: attempt TeamDelete anyway
d. If TeamDelete fails: report manual cleanup path
```
**TeamDelete + Cleanup:**
```
1. Call TeamDelete() — removes ~/.qoder/teams/{name}/ and ~/.qoder/tasks/{name}/
2. Clear team state: state_clear(mode="team")
3. Check for linked ralph: state_read(mode="ralph") — if linked_team is true:
a. Clear ralph state: state_clear(mode="ralph")
b. Clear linked ultrawork if present: state_clear(mode="ultrawork")
4. Run orphan scan (see below)
5. Emit structured cancel report
```
**Orphan Detection (Post-Cleanup):**
After TeamDelete, verify no agent processes remain:
```bash
node "${QODER_PLUGIN_ROOT}/scripts/cleanup-orphans.mjs" --team-name "{team_name}"
```
The orphan scanner:
1. Checks `ps aux` (Unix) or `tasklist` (Windows) for processes with `--team-name` matching the deleted team
2. For each orphan whose team config no longer exists: sends SIGTERM, waits 5s, sends SIGKILL if still alive
3. Reports cleanup results as JSON
Use `--dry-run` to inspect without killing. The scanner is safe to run multiple times.
**Structured Cancel Report:**
```
Team "{team_name}" cancelled:
- Members signaled: N
- Responses received: M
- Unresponsive: K (list names if any)
- TeamDelete: success/failed
- Manual cleanup needed: yes/no
Path: ~/.qoder/teams/{name}/ and ~/.qoder/tasks/{name}/
```
在 GitHub 查看这个 SKILL.md 很大,SkillsMP 这里只预览前一段内容。 在 GitHub 查看