微算力 · API 导航与自营网关
API 接入 EN
未登录登录
✨

Cursor CLI Agent

Cursor CLI Agent · v1.0.0
安全 unknown 级 作者 rare 公开目录收录
1k 下载 0 安装 3.4k 收藏 1 浏览

简介

Cursor CLI Agent

原始描述

Delegate coding tasks to Cursor Agent CLI. Use when: (1) building/creating new features or apps, (2) reviewing PRs (spawn in temp dir), (3) refactoring large...

通过你的 Agent 添加

安装目录:cursor-agent/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/cursor-cli-agent-48968/
Codex CLI~/.codex/skills/cursor-cli-agent-48968/
DeepSeek Harness~/.agents/skills/cursor-cli-agent-48968/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

技能正文


name: cursor-agent description: 'Delegate coding tasks to Cursor Agent CLI. Use when: (1) building/creating new features or apps, (2) reviewing PRs (spawn in temp dir), (3) refactoring large codebases, (4) iterative coding that needs file exploration. NOT for: simple one-liner fixes (just edit), reading code (use read tool), thread-bound ACP harness requests in chat (use sessions_spawn with runtime:"acp"), or any work in ~/clawd workspace (never spawn agents here). Requires a bash tool that supports pty:true.' metadata: { "openclaw": { "emoji": "🎯", "requires": { "anyBins": ["agent"] } }, }

Cursor Agent Skill

使用 Cursor CLI (agent 命令) 执行编程任务。支持多种前沿模型(GPT-5、Claude Opus/Sonnet、Gemini、Grok 等)。

⚠️ PTY Mode Required!

Cursor Agent 是交互式终端应用,需要 PTY 才能正常工作。

# ✅ 正确
bash pty:true command:"agent 'Your prompt'"

# ❌ 错误 - 没有 PTY 会卡住
bash command:"agent 'Your prompt'"

Bash Tool Parameters

Parameter Type Description
command string 要执行的 shell 命令
pty boolean 必须! 为交互式 CLI 分配伪终端
workdir string 工作目录(agent 只能看到这个目录的上下文)
background boolean 后台运行,返回 sessionId 用于监控
timeout number 超时秒数(超时后终止进程)
elevated boolean 在 host 上运行而非 sandbox(如果允许)

Quick Start

# 检查状态和登录
agent status
agent login

# 查看可用模型
agent --list-models

# 快速任务(交互模式)
bash pty:true command:"agent 'Add error handling to the API calls'"

# 指定工作目录
bash pty:true workdir:~/Projects/myproject command:"agent 'Build a snake game'"

The Pattern: workdir + background + pty

长时间任务用后台模式:

# 启动后台任务
bash pty:true workdir:~/project background:true command:"agent --yolo 'Refactor the auth module'"

# 返回 sessionId,用 process 监控
process action:list
process action:log sessionId:XXX
process action:poll sessionId:XXX

# 发送输入
process action:submit sessionId:XXX data:"yes"

# 终止
process action:kill sessionId:XXX

为什么 workdir 重要: Agent 在指定目录醒来,不会乱读其他文件(比如你的 soul.md 😅)。


命令参数速查

参数 说明
prompt 初始提示词
--yolo / --force 自动执行所有操作(危险但快速)
--model <model> 指定模型 (gpt-5, sonnet-4, opus-4, gemini, grok 等)
--workspace <path> 工作目录
-w, --worktree [name] 在隔离的 git worktree 中运行
--print 非交互模式,输出到控制台
--mode <mode> 执行模式: plan (只读规划), ask (问答)
--plan 规划模式(只读,不修改文件)
--cloud 云端模式
--resume 恢复上次会话
--trust 信任工作区(仅 headless 模式)

执行模式详解

交互模式(默认)

bash pty:true workdir:~/project command:"agent 'Build a dark mode toggle'"

自动执行模式(--yolo)

# 自动批准所有操作,快速执行
bash pty:true workdir:~/project command:"agent --yolo 'Refactor the auth module'"

规划模式(--plan)

# 只读模式,生成计划但不执行
bash pty:true workdir:~/project command:"agent --plan 'Analyze the codebase structure'"

问答模式(--mode ask)

# 只回答问题,不修改文件
bash pty:true command:"agent --mode ask 'Explain how the auth flow works'"

非交互模式(--print)⭐ 独特功能

Cursor 独有的 --print 模式,适合脚本化和 CI/CD:

# 非交互执行,输出到控制台
bash pty:true command:"agent --print 'Generate a summary of the codebase'"

# JSON 输出(适合解析)
bash pty:true command:"agent --print --output-format json 'List all API endpoints'"

# 流式 JSON(适合实时处理)
bash pty:true command:"agent --print --output-format stream-json 'Analyze the project'"

用途:

  • CI/CD 集成
  • 自动化脚本
  • 批量任务
  • 结果需要解析的场景

Git Worktree 隔离

用于并行处理多个独立任务:

# 在隔离的 worktree 中运行
bash pty:true workdir:~/project command:"agent -w fix-issue-78 'Fix the login bug'"

# 指定 base 分支
bash pty:true workdir:~/project command:"agent -w feature-x --worktree-base develop 'Add feature X'"

Parallel Issue Fixing(并行修复)

使用 git worktrees 同时修复多个 issue:

# 1. 为每个 issue 创建 worktree
git worktree add -b fix/issue-78 /tmp/issue-78 main
git worktree add -b fix/issue-99 /tmp/issue-99 main

# 2. 在每个 worktree 中启动 agent(后台 + PTY)
bash pty:true workdir:/tmp/issue-78 background:true command:"agent --yolo 'Fix issue #78: login bug. Commit and push.'"
bash pty:true workdir:/tmp/issue-99 background:true command:"agent --yolo 'Fix issue #99: API timeout. Commit and push.'"

# 3. 监控进度
process action:list
process action:log sessionId:XXX

# 4. 创建 PR
cd /tmp/issue-78 && git push -u origin fix/issue-78
gh pr create --repo user/repo --head fix/issue-78 --title "fix: ..." --body "..."

# 5. 清理
git worktree remove /tmp/issue-78
git worktree remove /tmp/issue-99

Batch PR Reviews(批量 PR Review)

⚠️ 永远不要在 OpenClaw 自己的项目目录中执行 PR review!

# 克隆到临时目录
REVIEW_DIR=$(mktemp -d)
git clone https://github.com/user/repo.git $REVIEW_DIR
cd $REVIEW_DIR && gh pr checkout 130

# 规划模式 review(只读)
bash pty:true workdir:$REVIEW_DIR command:"agent --plan 'Review this PR for security issues and code quality'"

# 清理
trash $REVIEW_DIR

批量 Review 多个 PR

# 获取所有 PR refs
git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*'

# 启动多个 agent 并行 review
bash pty:true workdir:~/project background:true command:"agent --plan 'Review PR #86. git diff origin/main...origin/pr/86'"
bash pty:true workdir:~/project background:true command:"agent --plan 'Review PR #87. git diff origin/main...origin/pr/87'"

# 监控
process action:list

# 发布结果到 GitHub
gh pr comment 86 --body "<review content>"

Process 工具(后台任务管理)

Action 说明
list 列出所有运行中的会话
poll 检查会话是否还在运行
log 获取会话输出(支持 offset/limit)
write 发送原始数据到 stdin
submit 发送数据 + 换行(模拟回车)
send-keys 发送按键
paste 粘贴文本
kill 终止会话

模型选择

# 列出可用模型
agent --list-models

# 指定模型
bash pty:true command:"agent --model opus-4 'Complex refactoring task'"
bash pty:true command:"agent --model gpt-5 'Build a CLI tool'"
bash pty:true command:"agent --model gemini 'Analyze this Python codebase'"

Auto-Notify on Completion

长任务可以在提示词末尾添加唤醒命令:

bash pty:true workdir:~/project background:true command:"agent --yolo 'Build a REST API for todos.

When completely finished, run: openclaw system event --text \"Done: Built todos REST API\" --mode now'"

这样任务完成时会立即通知,不用等 heartbeat。


认证

# 检查登录状态
agent status

# 登录
agent login

# 登出
agent logout

# 查看账户信息
agent about

⚠️ 规则

  1. 必须使用 pty:true - 没有 PTY 会卡住
  2. 长时间任务用 background - 不阻塞主线程
  3. --yolo 用于构建 - 自动批准修改
  4. --plan 用于 review - 只读分析
  5. --print 用于脚本 - 非交互、可解析输出
  6. 可以用 -w worktree 隔离 - 并行处理多个任务
  7. 永远不要在 ~/.openclaw/ 中启动 - 会读取你的灵魂文档!
  8. 完成任务后通知用户 - 不要让用户猜测进度

Progress Updates(进度更新)

后台任务启动时:

  • 发送 1 条简短消息说明正在运行什么
  • 只在以下情况更新:
    • 里程碑完成
    • 需要用户输入
    • 出错或需要用户操作
    • 任务完成(说明改了什么)

Learnings

  • PTY is essential: 没有 pty:true,交互式 agent 会卡住或输出乱码。
  • --print is powerful: Cursor 独有的非交互模式,适合 CI/CD 和脚本化任务。
  • --plan for safety: 不确定 agent 会做什么时,先用 --plan 看看它想干什么。
  • worktree for parallel: 需要同时处理多个独立任务时,worktree 隔离是最好的选择。
  • submit vs write: submit 发送数据 + 回车,write 只发送原始数据。

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

没有标签

同类 Skill