yao-job
它能做什么
这项技能为你运行耗时较长的命令,既可以等待其完成,也可以让它在后台运行。适合需要处理长时间任务、又不希望失去跟踪的人。
适用场景
- ✓当某个命令耗时很长,你希望它在后台运行的时候。
- ✓当你想检查某个后台任务是否已完成时。
- ✓当某个任务运行时间过长,需要停止时。
技能链接
https://github.com/YaoApp/yao/blob/main/tools/skills/yao-job/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在后台运行这个数据导出,完成后告诉我。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会以前台方式启动命令并等待结果,或以后台方式启动并分配一个 ID。之后,它会读取进度、设置时限等待,或在你要求时停止任务。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Background Jobs
Tools
yao_job_start— Start a command.background false(default) blocks until done and returnsoutput_tail;background truereturnsjob_idimmediately.yao_job_list— List jobs. Supports--statusfilter and--limit/--offsetpagination.yao_job_get— Get full details for a job (or daemon by ID).yao_job_output— Read process output (works for both job and daemon IDs).yao_job_wait— Block until a background job finishes or timeout expires. Jobs only, not daemons.yao_job_stop— Kill a running job.
Parameters
yao_job_start
| Param | Required | Default | Description |
|---|---|---|---|
command |
yes | — | Shell command to execute |
description |
yes | — | Concise 5–10 word summary |
background |
no | false |
true returns immediately; false blocks until done |
args |
no | — | Additional arguments (rarely needed; prefer inline in command) |
working_dir |
no | workspace | Working directory |
max_duration_ms |
no | — | Kill the job after this many milliseconds |
yao_job_list
| Param | Default | Description |
|---|---|---|
status |
all | Filter: running, stopping, completed, failed, cancelled, all |
limit |
20 | Max items per page |
offset |
0 | Skip first N items |
yao_job_output
| Param | Required | Description |
|---|---|---|
job_id |
yes | Job or daemon ID |
offset |
no | Byte offset to read from (0 = beginning) |
Output read behavior:
- Returns all available content from
offsetin a single read (nolimitparameter). - Ring buffer caps at 10 MB; older content beyond this is discarded.
- When content has been discarded,
lossy=truein the response. size= total bytes the process has produced;offset= earliest readable byte position.- Example: a 20 MB output has
size=20000000, offset≈10000000, lossy=true— the first ~10 MB was discarded.
yao_job_wait
| Param | Required | Default | Description |
|---|---|---|---|
job_id |
yes | — | Job ID |
timeout_ms |
no | 60000 | Timeout in milliseconds |
Response Fields
All responses are JSON. Job objects contain:
id, kind, session_id, status, description, background,
command, command_argv, command_line, pid, pgid, user,
started_at, finished_at, duration_ms, exit_code, signal, detail, seq
Foreground start (background=false)
Returns the job object plus output_tail (≤4KB tail of stdout+stderr):
{ "id": "job_...", "status": "completed", "exit_code": 0, ..., "output_tail": "hello world\n" }
List (paginated)
{ "jobs": [...], "total": 130, "offset": 0, "limit": 20, "has_more": true }
Wait
{ "job": { ... }, "timed_out": false }
Stop (already terminal)
{ "job": { ... }, "detail": "already in terminal state (failed); no action taken" }
Errors
Structured JSON with code and message:
{ "error": { "code": "invalid_argument", "message": "job_id is required" } }
Codes: invalid_argument, not_found, internal.
Usage Rules
- Use
background true(not bare--background) for commands expected to run longer than 30 seconds. - Always provide a
description. - Foreground is default — the result and output come back in one call.
- Monitor background output with
yao_job_outputto check progress. - Use
yao_job_waitto block until a background job completes rather than polling.
BackgroundJobReceipt
When a background job finishes, the system delivers a <BackgroundJobReceipt> XML message. Upon receiving it:
- Review the
status,exit_code,cause, andoutput_tail. - If
status=failed, investigate and take corrective action. - If
status=completed, acknowledge and continue the task.
常见问题
任务可以被停止吗?
可以。智能体可以停止正在运行的任务。
任务可以超时吗?
可以。你可以设置最长持续时间,超时后任务会被停止。
我如何查看输出?
智能体会读取任务的输出,并可以在任务完成时显示最后几行。
详情
作者的原始描述
Background job management — start, monitor, wait, stop long-running commands. ALWAYS invoke this skill when the user asks to run background tasks, check job status, read job output, or manage long-running commands.
repo: YaoApp/yao
热度
- GitHub 星标
- 8.3k
- 排名
- #12476
- 许可证
- —
- 更新时间
- 2026/10/19
评论
- …