/science-compute:run-monitor [start|status|list|tail] [任务名]from science-compute
当用户有耗时较长的本地任务需要后台执行,说"后台跑一下""这个任务要跑很久""帮我盯着这个任务""任务跑完了吗""看看日志"时使用。本技能定义长任务 Run 抽象(核心设计:不让人机等任务、轮询不耗 token):run 目录 runs/<run_id>/{run.json, stdout.log, stderr.log},run.json 记录 {id, cmd, cwd, pid, started, status, exit_code};配套纯标准库脚本 run_task.py 提供 start(detached 后台启动,Windows/POSIX 跨平台)、status(pid 存活检查 + 退出码)、list、tail 四个子命令。同义触发场景:长任务、后台运行、任务监控、看进度、训练还没跑完、批处理脚本。
Ships in science-compute. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
本地长任务(模型训练、大批量数据处理、长时间仿真)最容易犯两个错:让人机会话空等任务结束(浪费上下文与时间),或者反复"看看好了没"轮询刷屏(每次都把日志灌进对话)。本技能的 Run 抽象解决这两点:
running | exited | failed,配合退出码,一眼可判。本技能配套纯标准库脚本 scripts/run_task.py(Windows/POSIX 跨平台),任何能跑 Python 3 的机器都能用。远程任务的管理见 remote-compute / hpc-slurm,本技能只管本地进程。
./runs/<run_id>/,换目录启动等于另一套记录。-_.),同一时刻同名 run 只能有一个在 running。--out output/...):后台任务脱离会话上下文,事后靠 run.json 的 cmd 字段追溯"它当时往哪写",路径不明的命令先补参数再启动。runs/
└── <run_id>/
├── run.json # 状态文件(唯一事实来源)
├── stdout.log # 标准输出(每次 start 截断重写)
└── stderr.log # 标准错误
run.json 字段如下(tags、note 仅在 start 带 --tag/--note 时写入):
| 字段 | 含义 |
|---|---|
| id | run 名(即目录名) |
| cmd | 执行的命令行 |
| cwd | 启动时的工作目录 |
| pid | 后台进程 pid(用于存活检查) |
| started | 启动时间,ISO 8601 带时区 |
| status | running / exited(退出码 0)/ failed(非零或被强杀) |
| exit_code | 退出码;running 或异常死亡时为 null |
| tags | 可选:--tag 重复给出的标签数组(如 ["slurm", "gpu01"]),list 输出含 TAGS 列 |
| note | 可选:--note 给的自由文本备注 |
python <插件路径>/skills/run-monitor/scripts/run_task.py \
start --name cycle-fit --cmd "python scripts/analyze_cycle.py --seed 42"
start_new_session=True(脱离控制终端),Windows 用 DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP;stdout/stderr 重定向到日志文件。--tag(可重复)与 --note 把标签与备注写进 run.json:跨项目、跨机器筛选用 tag(如 --tag slurm --tag gpu01,登记远程作业的模式见 hpc-slurm 第 6 节),背景说明用 note。python <插件路径>/.../run_task.py status --name cycle-fit # 单个 run 的状态
python <插件路径>/.../run_task.py list # 全部 run 一览
python <插件路径>/.../run_task.py tail --name cycle-fit --lines 20
os.kill(pid, 0),Windows OpenProcess + GetExitCodeProcess),pid 已死但没落终态(被强杀)则判 failed。tail --lines N 取末尾 N 行,不要整份 cat 进对话(日志可能上万行)。exited:确认产物符合预期,按产物性质归位(output/<skill>/<slug>/ 契约),然后 record_run 登记,note 写 run_id、cmd、时长;failed:tail stderr.log 定位原因,失败也要登记 provenance(paths 指向日志,note 写失败摘要)——失败的运行同样是研究历史;一次本地长任务的闭环(虚构示例):
# 1. 启动(立即返回,会话不阻塞)
python <插件路径>/skills/run-monitor/scripts/run_task.py \
start --name cycle-fit --cmd "python scripts/analyze_cycle.py --seed 42"
# → started run 'cycle-fit' (pid 37516) -> runs/cycle-fit/
# 2. 交还控制权;过一阵子在自然节点查询
python <插件路径>/skills/run-monitor/scripts/run_task.py status --name cycle-fit
# → status: running(继续干别的,不写 sleep 循环)
# 3. 再次查询:status: exited, exit_code: 0
python <插件路径>/skills/run-monitor/scripts/run_task.py tail --name cycle-fit --lines 10
# 4. 产物归位 + provenance 登记(record_run 的 note 写 run_id 与 cmd)
python <science-core 插件路径>/skills/provenance-record/scripts/record_run.py \
--path output/python-analysis/<slug>/latest/ \
--tool "run cycle-fit: python scripts/analyze_cycle.py --seed 42" \
--note "run-monitor 后台执行,runs/cycle-fit/,exit 0"
失败时第 3 步显示 status: failed, exit_code: <n>,第 4 步的登记照常进行,paths 指向 runs/cycle-fit/stderr.log,note 写失败摘要——失败同样是研究历史。
## 后台任务已启动
- run_id:<name>(pid <pid>)
- 状态文件:runs/<name>/run.json;日志:runs/<name>/{stdout,stderr}.log
- 查询:run_task.py status --name <name>(结束时我再查,或随时问我)
## 任务 <name> 已结束(<status>,exit_code=<n>)
- 关键输出:<tail 摘要,一两行>
- 产物归位:<路径>;provenance:已登记(note:…)
list 一览全局;任务多到一个屏幕放不下时,说明该上集群了——转 hpc-slurm。What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub hylouis233/openscience --plugin science-compute5 skills in this plugin
/hpc-slurm当用户需要向 Slurm 集群提交计算作业,说"提交集群任务""写个 sbatch 脚本""作业还在排队吗""批量跑一组参数""作业超时被杀了""GPU 作业怎么交"时使用。本技能规定 Slurm 集群的统一操作规程:sbatch 脚本模板(分区/时长/内存/GPU 指令 + set -euo pipefail + 环境导出 + 结束自动 rsync 产物)、squeue/sacct 状态查询口径、数组任务批量提交、超时与重排队策略、产物抓回与 record_run 登记。同义触发场景:Slurm、HPC、集群、超算、排队、批处理、job array、机时。连接与主机认知纪律沿用 remote-compute(别名、画像合同),本技能只规定作业生命周期。/python-analysis当用户使用 Python 做科研数据分析、统计建模、机器学习实验或批量数据处理,说"用 Python 跑一下分析""做个统计""清洗数据""画结果图""跑个脚本"时使用。本技能规定本地 Python 分析的统一操作规程:环境优先 uv/venv 隔离、依赖写入 requirements.txt 并通过 record_run 记录环境指纹、随机种子固定并登记、原始数据只读(清洗另存新文件)、产物落盘 output/<skill>/<slug>/latest/、图表 PNG+PDF 双格式 300dpi,并附 stats_integrity_check.py 对报告数字做确定性体检。同义触发场景:Python 分析、跑数据、统计分析、数据处理、画图、pandas、matplotlib、分析环境怎么配。/