mcpField
S
stop

stop

github.com/terrylicaAgent 工作流286 次安装1 天前更新
代码仓库

关于 stop

stop 是用于终止自修订循环的技能,会在契约中记录完成原因、通知最终状态并停止后续唤醒。它还可卸载循环、清理状态目录,并提供保留取证文件的选项。

主要功能

  1. 01在契约中追加 DONE 标记
  2. 02发送最终状态通知
  3. 03卸载并注销循环
  4. 04归档并清理状态目录
  5. 05支持保留取证文件

适用场景

  1. 01目标达成后结束循环
  2. 02外部依赖阻塞时停止
  3. 03停止后检查心跳和修订日志

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/terrylica/cc-skills --skill stop

安装后在 Claude Code 中输入/stop确认已加载。

详细介绍

autoloop:停止

干净地终止自我修订循环。追加一个包含时间戳和原因的 ## DONE 部分,发送总结最终状态的 PushNotification,并停止安排新的唤醒。下一次 /loop 触发时会看到 DONE 标记并直接退出,不执行任何操作。

自我演进技能:此技能会在使用过程中不断改进。如果指令有误、参数发生偏移,或需要采用变通方法,请立即修复此文件,不要拖延。仅针对真实、可复现的问题进行更新。

参数

  • 位置参数(可选):原因字符串。默认为 "user-requested stop"。
  • --keep-forensics(标志,可选):停止后保留状态目录,而不是将其归档并删除。Wave 2 起的默认行为是创建清理压缩包,并对 <state_dir> 执行 rm -rf。如果停止后需要检查 heartbeat.json 或 revision-log/,请传入此标志。

步骤 1:定位契约

CONTRACT_PATH="${CONTRACT_PATH:-./LOOP_CONTRACT.md}"
if [ ! -f "$CONTRACT_PATH" ]; then
  echo "No contract at $CONTRACT_PATH — nothing to stop."
  exit 0
fi

如果用户未指定使用哪个契约,且当前工作目录下存在多个 LOOP_CONTRACT.md 文件,请使用 AskUserQuestion 让用户选择。

步骤 2:确认停止原因

使用 AskUserQuestion 选择停止原因:

  • Research saturation — 连续 3 次触发均未能恢复
  • Goal achieved — 已满足完成标准
  • User request — 手动终止
  • Blocked on external dependency — 无法在不进行干预的情况下继续

将所选原因以及用户提供的自由文本备注(如有)记录到 DONE 部分。

步骤 3:追加 DONE 部分

将以下内容块追加到契约中(使用 Edit 或 Bash cat >>):

---

## DONE

- **Stopped at**: <ISO 8601 UTC>
- **Iteration**: <current value from frontmatter>
- **Reason**: <chosen reason>
- **User note**: <free-text if any>
- **Final state summary**:
  <one-paragraph synthesis of the Current State section at time of stop>

The next /loop firing will observe this section and exit without further action.

步骤 4:发送 PushNotification

如果 PushNotification 尚未加载,请通过 ToolSearch 加载,然后发送:

<loop-name> stopped at iter <N>. Reason: <reason>. Final state: <one-line summary>.

请控制在 200 个字符以内。

步骤 5:卸载 launchd plist

取消注册前,先卸载 launchd plist:

# Source the launchd library
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$HOME/.claude/plugins/marketplaces/cc-skills/plugins/autoloop}"
source "$PLUGIN_ROOT/scripts/launchd-lib.sh"
source "$PLUGIN_ROOT/scripts/state-lib.sh"

# Derive loop_id and state_dir
loop_id=$(derive_loop_id "$CONTRACT_PATH")
state_dir=$(state_dir_path "$loop_id" "$CONTRACT_PATH")

# Unload plist (idempotent; no-op on non-macOS)
if ! unload_plist "$loop_id" "$state_dir" 2>/dev/null; then
  echo "WARNING: Failed to unload launchd plist" >&2
fi

步骤 6:从机器注册表注销循环

卸载 plist 后,清理机器注册表条目:

# Source the registry library
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$HOME/.claude/plugins/marketplaces/cc-skills/plugins/autoloop}"
source "$PLUGIN_ROOT/scripts/registry-lib.sh"

# Derive loop_id from contract path
loop_id=$(derive_loop_id "$CONTRACT_PATH")

# Unregister from machine registry (idempotent; no error if already absent)
if ! unregister_loop "$loop_id"; then
  echo "WARNING: Failed to unregister loop from machine registry" >&2
fi

步骤 7:清理状态目录(Wave 2)

注销后,归档并删除循环的状态目录,避免留下孤立文件。压缩包会创建在该目录旁边(其父目录中),然后对目录本身执行 rm -rf:

# state_dir was already computed in Step 5 via state_dir_path()
if [ -n "$state_dir" ]; then
  # Pass --keep-forensics if the user requested it (e.g. they want to inspect
  # heartbeat.json or revision-log/<session>.jsonl after stop).
  KEEP_FLAG=""
  for arg in "$@"; do
    [ "$arg" = "--keep-forensics" ] && KEEP_FLAG="--keep-forensics"
  done
  cleanup_state_dir "$state_dir" $KEEP_FLAG
fi

cleanup_state_dir 由 state-lib.sh 导出。如果路径位于 $HOME 之外,它会拒绝操作(安全防护)。压缩包创建失败不会中止流程——它会发出警告并继续执行 rm。

步骤 8:更新 frontmatter

编辑 YAML frontmatter 中的 exit_condition 字段,将 DONE 纳入其中,以便下一次触发时无需扫描正文即可立即检测到。

步骤 9:建议最终提交

打印一条建议的提交信息:

git add "$CONTRACT_PATH"
git commit -m "$(cat <<'EOF'
loop(stop): <loop-name> complete — <reason>

Final iteration: <N>
Last action: <summary from Current State>
EOF
)"

反模式

  • 不要在此技能中对任何正在运行的进程执行 kill -9——这超出本技能的范围。本技能只会向循环发送信号;其他技能(如 ru:stop 或 pueue kill)负责终止进程。
  • 不要重写 Revision Log——它只能追加。请改为添加 DONE 部分。
  • 如果用户当前正在使用(留意最近 60 秒内是否有用户发言),不要发送 PushNotification,以免打扰用户。如有疑问,请跳过推送。

故障排除

症状解决方法
PushNotification 工具尚未加载在步骤 4 前使用查询 select:PushNotification 调用 ToolSearch
DONE 部分已存在循环已停止;打印确认信息并退出
DONE 后循环仍持续触发下一次 /loop 读取契约时应会直接退出——请确认指针触发条件正确

执行后复盘

  1. 确认位置。 — 编辑前确认此 SKILL.md 是规范文件。
  2. 哪里失败了? — 修复导致失败的指令。
  3. 哪里偏离了? — 如有需要,更新 DONE 部分模板。
  4. 记录。 — 添加演进日志条目。

评论

支持 Markdown