热门话题
#
Bonk 生态迷因币展现强韧势头
#
有消息称 Pump.fun 计划 40 亿估值发币,引发市场猜测
#
Solana 新代币发射平台 Boop.Fun 风头正劲
我刚刚想出了如何通过一些 tmux 的魔法进一步自动化我的代理工作流程。
现在我正在使用我的 mcp 代理邮件项目,让一群代理互相交流实施计划(同时也使用 beads 项目进行任务管理),我仍然需要通过在 codex 中排队一堆消息来“喂养”这些代理,以保持他们忙碌。
这涉及逐个浏览各种 tmux 窗格(每个 codex 实例一个),粘贴一些预设消息或按几次上箭头以重用过去的消息,例如:
“选择下一个你现在可以有效使用的珠子,并立即开始编码;通过代理邮件与其他代理沟通你正在做的事情。”
这样做感觉有点傻且低效,尽管给每个代理足够的指示以保持他们忙碌超过一个小时并不会花太长时间。
但现在我意识到,我可以通过简单地将这段代码复制并粘贴到 tmux 会话外的控制台中,自动在每个相关的 tmux 窗格中排队一堆消息(这在 zsh 中经过测试并且有效):
---
PANES=(${(f)"$(tmux list-panes -a -F '#S:#I.#P' | tail -n +3 | head -n -2)"})
for pane in $PANES; do
tmux send-keys -t $pane -l '选择下一个你现在可以有效使用的珠子,并立即开始编码;通过代理邮件与其他代理沟通你正在做的事情。'
sleep 0.1
tmux send-keys -t $pane Enter
for i in {1..4}; do
tmux send-keys -t $pane -l '继续努力,做有用的工作!并沟通!'
sleep 0.1
tmux send-keys -t $pane Enter
done
tmux send-keys -t $pane -l '很好,现在我希望你仔细阅读你刚刚写的所有新代码和你刚刚修改的其他现有代码,带着“新鲜的眼光”仔细寻找任何明显的错误、问题、困惑等。'
sleep 0.1
tmux send-keys -t $pane Enter
tmux send-keys -t $pane -l '确保查看你的代理邮件,并在需要时及时回复任何消息;然后仔细按照计划进行,系统地完成你所有未完成的任务,并继续在计划文档中、通过 beads 和通过代理邮件消息记录你的进展。不要陷入“沟通炼狱”,让事情停滞不前;主动开始需要完成的任务,但在这样做时通过消息告知你的同事,并在计划文档中记录下来。当你真的不确定该做什么时,选择下一个你可以有效工作上的珠子并开始。'
sleep 0.1
tmux send-keys -t $pane Enter
tmux send-keys -t $pane -l '好的,你现在能否将注意力转向审查你同事编写的代码,并检查任何问题、错误、缺陷、效率低下、安全问题、可靠性问题等,并仔细诊断其根本原因,必要时进行修复或修改?不要仅限于最新的提交,放宽范围,深入挖掘!'
sleep 0.1
tmux send-keys -t $pane Enter
done
---
这个脚本:
获取窗格:查找所有 tmux 窗格,排除前两个和最后两个
向每个选定的窗格发送 8 条消息:
“选择下一个珠子...”
- 告诉代理开始处理下一个任务
“继续努力...” × 4 - 重复鼓励继续工作
“仔细阅读...” - 指示进行新代码审查
“查看代理邮件...” - 关于协调、避免沟通瘫痪、保持生产力的长消息
“审查同事编写的代码...” - 对错误/问题进行同行代码审查
每条消息都以字面意义发送(-l 标志),在 Enter 之前有 0.1 秒的延迟,以确保 Codex CLI 正确处理它们。

Actually, this is a better way to do it, by filtering on the name of the pane (in my case, it's "node" for the codex panes), and it has the initial 0.1 second sleep, without which it skips the first matching pane without sending the messages correctly:
PANES=(${(f)"$(tmux list-panes -a -F '#S:#I.#P #{pane_current_command}' | rg ' node$' | cut -d' ' -f1)"})
for pane in $PANES; do
sleep 0.1 # Initial sleep to ensure pane is ready
tmux send-keys -t $pane -l 'pick the next bead you can actually do usefully now and start coding on it immediately; communicate what you'"'"'re doing to the other agents via agent mail.'
sleep 0.1
tmux send-keys -t $pane Enter
for i in {1..4}; do
tmux send-keys -t $pane -l 'keep going, doing useful work! and communicate!'
sleep 0.1
tmux send-keys -t $pane Enter
done
tmux send-keys -t $pane -l 'great, now I want you to carefully read over all of the new code you just wrote and other existing code you just modified with "fresh eyes" looking super carefully for any obvious bugs, errors, problems, issues, confusion, etc.'
sleep 0.1
tmux send-keys -t $pane Enter
tmux send-keys -t $pane -l 'Be sure to check your agent mail and to promptly respond if needed to any messages; thereafter proceed meticulously with the plan, doing all of your remaining unfinished tasks systematically and continuing to notate your progress in-line in the plan document, via beads, and via agent mail messages. Don'"'"'t get stuck in "communication purgatory" where nothing is getting done; be proactive about starting tasks that need to be done, but inform your fellow agents via messages when you do so and notate that in-line in the plan document. When you'"'"'re really not sure what to do, pick the next bead that you can usefully work on and get started.'
sleep 0.1
tmux send-keys -t $pane Enter
tmux send-keys -t $pane -l 'ok can you now turn your attention to reviewing the code written by your fellow agents and checking for any issues, bugs, errors, problems, inefficiencies, security problems, reliability issues, etc. and carefully diagnose their underlying root causes using first-principle analysis and thereafter fix or revise them if necessary? Dont restrict yourself to the latest commits, cast a wider net and go super deep!'
sleep 0.1
tmux send-keys -t $pane Enter
done
如果你的机器很慢,你可能需要增加睡眠时间。我讨厌这一切是多么挑剔;我打算找到一种更可靠的方法来做到这一点。
25.88K
热门
排行
收藏

