autoresearch-hooks
它能做什么
这项技能帮助你的 AI 编写可选脚本,在 autoresearch 会话的每次实验开始和结束时运行。适合希望在循环前后加入通知、保存笔记或额外步骤的人。
适用场景
- ✓当你希望每次实验结束后发送 Slack 或 webhook 消息时。
- ✓当你希望循环在开始新一轮迭代之前保存经验或获取研究资料时。
- ✓当实验循环似乎停滞,你想加入一个额外步骤来改变其方向时。
技能链接
https://github.com/davebcn87/pi-autoresearch/blob/main/skills/autoresearch-hooks/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请添加一个钩子,在每次实验结束后给我发送一条消息。”
每周 5 个新技能,1 分钟读完。
工作原理
钩子脚本会以文字形式接收上一次运行的简短摘要,并可以保存文件或发送笔记。未标记为可执行的脚本会被忽略。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
autoresearch-hooks
Optional scripts that run at iteration boundaries in an autoresearch session. Two hooks, both transparent to the loop-running agent — their effect is a file on disk or a steer message.
.auto/hooks/
before.sh # fires before each iteration (prospective)
after.sh # fires after each log_experiment (retrospective)
Both files are optional. Files without the executable bit are silently ignored.
Contract
Stdin — before.sh
One JSON line. Parse with jq. Realistic example:
{
"event": "before",
"cwd": "/path/to/workdir",
"next_run": 6,
"last_run": {
"run": 5,
"status": "discard",
"metric": 42.1,
"description": "Simplified to sorted(arr) — copy cost dominates",
"asi": {
"hypothesis": "Built-in sort avoids Python overhead",
"next_focus": "list copy avoidance"
}
},
"session": {
"metric_name": "total_ms",
"metric_unit": "ms",
"direction": "lower",
"baseline_metric": 40.7,
"best_metric": 33.5,
"run_count": 5,
"goal": "optimize sort speed"
}
}
| Field | Notes |
|---|---|
last_run |
The most recent run entry. null on a fresh session. |
session.direction |
"lower" or "higher" — which end of the scale wins. |
session.baseline_metric |
First run of the current segment. null until one run exists. |
session.best_metric |
Optimal metric across kept runs only. null until one is kept. |
session.goal |
The session name set by init_experiment. |
session.run_count |
Total runs logged so far (any status). |
Stdin — after.sh
{
"event": "after",
"cwd": "/path/to/workdir",
"run_entry": {
"run": 6,
"status": "discard",
"metric": 38.9,
"description": "Timsort hybrid slower on random",
"asi": {
"hypothesis": "Partial-sort heuristic on input distribution",
"learned": "Overhead dominates on random arrays"
}
},
"session": {
"metric_name": "total_ms",
"metric_unit": "ms",
"direction": "lower",
"baseline_metric": 40.7,
"best_metric": 33.5,
"run_count": 6,
"goal": "optimize sort speed"
}
}
| Field | Notes |
|---|---|
run_entry |
The run just logged. Always present. |
session |
Same shape as in before.sh, reflecting state after the run. |
Output
- Stdout (up to 8 KB) — delivered to the agent as a steer message on the next turn. Empty = silent.
- Stderr + non-zero exit — surfaced as an error steer.
- Timeout — 30 s hard kill; flagged in the observability entry.
Preservation
.auto/** survives the auto-revert — the entire .auto/ folder is preserved. (Legacy autoresearch.* paths are still preserved too, for in-flight sessions.)
Examples
Runnable reference scripts live in this skill's examples/ directory — one file per pattern. Paths are resolved against the skill directory (parent of SKILL.md). Browse them for inspiration; they're not policy.
examples/before/— external search, qmd document search, anti-thrash, idea rotator, hypothesis reflection, context rotationexamples/after/— learnings journal, macOS notification on new best, auto-tag winning commits
Each example is a complete, self-contained script with named constants, short helper functions, guard clauses, and intention-revealing names. Read the header comment for its purpose, copy to .auto/hooks/<stage>.sh, adapt.
Steps to add a hook
Understand the session. Read
.auto/prompt.mdfor the objective and metric; glance at.auto/measure.shfor the workload. Your hook should complement the loop, not duplicate it.Clarify the user's intent. What should happen, at which boundary? Research before / log after / notify on wins / intervene on thrash / etc.
Start from an example in
examples/that's closest to the intent (resolve against the skill directory). If nothing fits, write from scratch following the same style (named constants, short functions, guard clauses, JSON stdin par
常见问题
这些脚本什么时候运行?
前置脚本在每次迭代之前运行,后置脚本在每次记录的实验之后运行。
脚本会收到哪些信息?
它会收到一份简短的 JSON 摘要,包含上一次运行、下一次运行的编号以及会话详情。
钩子是必需的吗?
不是。两个钩子文件都是可选的。
详情
作者的原始描述
Author pre/post-iteration hooks for an autoresearch session. Use when the user asks to add research fetching, Slack/webhook notifications, persistent learnings, auto-tagging, anti-thrash intervention, idea rotation, or any side effect around iterations.
热度
- GitHub 星标
- 8.2k
- 排名
- #12524
- 许可证
- MIT
- 更新时间
- 2026/10/7
评论
- …