Agent Swarm Orchestrator
Multi-project coding automation: Obsidian task intake → Claude Code → Codex review → GitLab MR → merge + sync.
Architecture
CODEBLOCK0
Core Paths
| Path | Purpose |
|---|
| INLINECODE0 | Control plane (scripts, registry, tasks) |
| INLINECODE1 |
Project configs (repo, paths, branch) |
|
~/agent-swarm/tasks.json | Task state machine |
|
~/GitLab/repos/ | Local repos |
|
~/GitLab/worktrees/ | Per-task worktrees |
|
~/Documents/Obsidian Vault/agent-swarm/ | Task intake notes |
Scripts
| Script | Purpose |
|---|
| INLINECODE6 | Create worktree + prompt + tmux → run-agent |
| INLINECODE7 |
claude -p → check commits → trigger review |
|
review-and-push.sh | Codex review → graded fix → push → MR |
|
check-agents.sh | Cron + post-merge: detect done/stuck, mark done, send notification |
|
scan-obsidian.sh | Parse Obsidian notes, spawn
status: ready tasks |
|
send-notifications.sh | Send
.notification files via OpenClaw CLI |
|
merge-and-sync.sh | Merge MR + sync local main |
|
sync-project-main.sh | Fast-forward local repo to origin/main |
|
new-project.sh | Initialize project (GitLab + registry + context + Obsidian) |
|
cleanup.sh | Daily archive old tasks, clean worktrees/logs |
Usage
Spawn task
CODEBLOCK1
Monitor
CODEBLOCK2
Merge and sync
CODEBLOCK3
New project
CODEBLOCK4
Task Lifecycle
CODEBLOCK5
Prerequisites
Claude Code CLI
- - Authenticated via OAuth (
~/.claude.json oauthAccount) - INLINECODE20 : INLINECODE21
- INLINECODE22 projects: trust
~/GitLab/worktrees and ~/GitLab/repos (hasTrustDialogAccepted: true) - No
ANTHROPIC_* env vars leaking into tmux (causes proxy conflicts)
Tools
- -
claude CLI (Claude Code) - INLINECODE28 CLI (OpenAI Codex, for review)
- INLINECODE29 CLI (GitLab)
- INLINECODE30 ,
python3, INLINECODE32
Cron
CODEBLOCK6
Notifications
Configure in ~/agent-swarm/registry.json:
CODEBLOCK7
INLINECODE34 in config.sh reads these values and calls:
CODEBLOCK8
⚠️ Do NOT use >/dev/null 2>&1 in swarm_notify — errors must be visible so failed sends are not silently marked as sent.
Prompt Template
Each task gets a prompt file with:
- 1. Project name, task description, priority
- Working directory and branch
- Project context (from
context.md) - Standard instructions (commit, push, MR, update context.md if architectural changes)
Obsidian Integration
- - Frontmatter
status: active | stop controls project scanning - Task block:
### Task Name + status: ready + INLINECODE42 - INLINECODE43 +
status: ready triggers INLINECODE45 - Dedup: sha1(project+name+desc)[:12], flagged in logs
- Debounce: skip files modified within last 1 minute
Review Policy
- - Coding: Claude Code (
-p mode, auto-exit) - Review: Codex (
codex exec review) - CRITICAL/HIGH: auto-fix retry (max 2), then INLINECODE48
- MEDIUM: auto-fix (non-blocking), skip for docs-only
- LOW: notes in MR description only
- Docs-only: downgrade CRITICAL/HIGH to MEDIUM
Portable Install
CODEBLOCK9
Then: register projects in registry.json, set cron, configure notifications.
Intent → Action Mapping
When a user message matches one of these intents, take the corresponding action immediately without asking for confirmation:
| User says | Context | Action |
|---|
| "合并" / "merge" / "merge it" | Replied to a PR_READY notification | Extract <project> and <mr-iid> from the notification, run INLINECODE52 |
| "起任务" / "spawn" / "新任务" |
With a task description | Run
spawn-agent.sh <project> "<desc>" |
| "查状态" / "check status" | Any | Run
check-agents.sh and summarize output |
| "新项目" / "new project" | With a project name | Run
new-project.sh <project-name> |
Extracting MR info from PR_READY notifications
PR_READY notifications follow this format:
CODEBLOCK10
Extract Project → <project>, and the number at the end of the MR URL → <mr-iid>.
Guardrails
You are the dispatcher, not the analyst
When a user reports an issue or requests a change to project code:
- - ❌ Do NOT read project source code to analyze
- ❌ Do NOT diagnose root causes yourself
- ❌ Do NOT design technical solutions
- ✅ Understand the user's intent and translate it into a clear task description
- ✅ Pass user feedback verbatim to the agent (e.g. "tiles didn't get bigger")
- ✅ Spawn the task, monitor progress, merge MRs, maintain the swarm system
The coding agent runs in a full worktree with complete project context — it is better positioned to read code, diagnose issues, and implement fixes than you are from a chat session.
Other rules
- - Do not edit project code directly — always go through spawn-agent
- Push-first + cron-fallback notification design
- State names:
done, ready_to_merge, review-error, INLINECODE62 - Context.md auto-update for new features, gameplay changes, and architectural changes (skip trivial config/formatting)
Agent Swarm Orchestrator
多项目编码自动化:Obsidian任务接收 → Claude Code → Codex审查 → GitLab MR → 合并+同步。
架构
Obsidian笔记 (状态: ready)
→ scan-obsidian.sh (cron 5分钟)
→ spawn-agent.sh
├── git工作树 + 分支
├── 提示文件 (任务 + context.md)
└── tmux会话 → run-agent.sh
├── claude -p $PROMPT | tee log
└── review-and-push.sh
├── codex审查 (分级)
├── push + glab mr create --yes
└── 通知 → Telegram
merge-and-sync.sh (手动触发)
├── glab mr merge
├── sync-project-main.sh (快进本地主分支)
└── check-agents.sh (后台) → 标记完成 + 发送通知
check-agents.sh (cron 3分钟 / 由merge-and-sync调用)
├── 已终止的tmux + 提交 → 触发审查
├── >60分钟 → 超时通知
└── MR已合并 → 在tasks.json中标记完成 + .notification → Telegram
核心路径
| 路径 | 用途 |
|---|
| ~/agent-swarm/ | 控制平面 (脚本、注册表、任务) |
| ~/agent-swarm/registry.json |
项目配置 (仓库、路径、分支) |
| ~/agent-swarm/tasks.json | 任务状态机 |
| ~/GitLab/repos/ | 本地仓库 |
| ~/GitLab/worktrees/ | 每个任务的工作树 |
| ~/Documents/Obsidian Vault/agent-swarm/ | 任务接收笔记 |
脚本
| 脚本 | 用途 |
|---|
| spawn-agent.sh | 创建工作树 + 提示 + tmux → run-agent |
| run-agent.sh |
claude -p → 检查提交 → 触发审查 |
| review-and-push.sh | Codex审查 → 分级修复 → push → MR |
| check-agents.sh | Cron + 合并后:检测完成/卡住,标记完成,发送通知 |
| scan-obsidian.sh | 解析Obsidian笔记,生成status: ready任务 |
| send-notifications.sh | 通过OpenClaw CLI发送.notification文件 |
| merge-and-sync.sh | 合并MR + 同步本地主分支 |
| sync-project-main.sh | 将本地仓库快进到origin/main |
| new-project.sh | 初始化项目 (GitLab + 注册表 + 上下文 + Obsidian) |
| cleanup.sh | 每日归档旧任务,清理工作树/日志 |
使用方法
生成任务
bash
~/agent-swarm/scripts/spawn-agent.sh <项目> <任务描述>
监控
bash
tmux attach -t agent-<任务-id> # 实时输出
tail -f ~/agent-swarm/logs/<任务-id>.log # 日志文件
合并和同步
bash
~/agent-swarm/scripts/merge-and-sync.sh <项目>
新项目
bash
~/agent-swarm/scripts/new-project.sh <项目名称>
任务生命周期
starting → running → [no-output | reviewing]
reviewing → [readytomerge | review-error | needs-manual-fix | fixing]
fixing → reviewing (重试,最多2次)
readytomerge → done (MR合并后自动完成)
前提条件
Claude Code CLI
- - 通过OAuth认证 (~/.claude.json oauthAccount)
- ~/.claude/settings.json: skipDangerousModePermissionPrompt: true
- ~/.claude.json projects: 信任 ~/GitLab/worktrees 和 ~/GitLab/repos (hasTrustDialogAccepted: true)
- 不要在tmux中泄漏ANTHROPIC_*环境变量 (会导致代理冲突)
工具
- - claude CLI (Claude Code)
- codex CLI (OpenAI Codex, 用于审查)
- glab CLI (GitLab)
- jq, python3, tmux
Cron
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
/3 * ~/agent-swarm/scripts/check-agents.sh
/5 * ~/agent-swarm/scripts/scan-obsidian.sh
0 3 * ~/agent-swarm/scripts/cleanup.sh
通知
在 ~/agent-swarm/registry.json 中配置:
json
{
notifyMethod: openclaw,
notifyChannel: telegram,
notifyTarget:
}
config.sh 中的 swarm_notify() 读取这些值并调用:
bash
openclaw message send --channel telegram --target --message ...
⚠️ 不要在 swarm_notify 中使用 >/dev/null 2>&1 — 错误必须可见,这样失败的发送就不会被静默标记为已发送。
提示模板
每个任务都会获得一个包含以下内容的提示文件:
- 1. 项目名称、任务描述、优先级
- 工作目录和分支
- 项目上下文 (来自 context.md)
- 标准指令 (提交、推送、MR、如果架构变更则更新context.md)
Obsidian集成
- - 前置元数据 status: active | stop 控制项目扫描
- 任务块:### 任务名称 + status: ready + > 描述
- ### INIT_PROJECT + status: ready 触发 new-project.sh
- 去重:sha1(项目+名称+描述)[:12],在日志中标记
- 防抖:跳过最近1分钟内修改的文件
审查策略
- - 编码:Claude Code (-p 模式,自动退出)
- 审查:Codex (codex exec review)
- CRITICAL/HIGH:自动修复重试 (最多2次),然后 needs-manual-fix
- MEDIUM:自动修复 (非阻塞),仅文档变更跳过
- LOW:仅在MR描述中添加注释
- 仅文档:将CRITICAL/HIGH降级为MEDIUM
便携安装
bash
mkdir -p ~/agent-swarm/{scripts,logs,projects}
cp -f /scripts/*.sh ~/agent-swarm/scripts/
chmod +x ~/agent-swarm/scripts/*.sh
echo {projects:{}} > ~/agent-swarm/registry.json
echo {tasks:[]} > ~/agent-swarm/tasks.json
然后:在 registry.json 中注册项目,设置cron,配置通知。
意图 → 动作映射
当用户消息匹配以下任一意图时,立即执行相应操作,无需确认:
| 用户说 | 上下文 | 动作 |
|---|
| 合并 / merge / merge it | 回复了PR_READY通知 | 从通知中提取 <project> 和 <mr-iid>,运行 merge-and-sync.sh <project> <mr-iid> |
| 起任务 / spawn / 新任务 |
带有任务描述 | 运行 spawn-agent.sh |
| 查状态 / check status | 任意 | 运行 check-agents.sh 并总结输出 |
| 新项目 / new project | 带有项目名称 | 运行 new-project.sh |
从PR_READY通知中提取MR信息
PR_READY通知遵循以下格式:
✅ PR_READY
Project:
Task:
Task ID:
Branch:
MR: https://gitlab.com/.../-/merge_requests/ | Review ...
提取 Project → ,以及MR URL末尾的数字 → 。
护栏
你是调度员,不是分析师
当用户报告问题或请求更改项目代码时:
- - ❌ 不要阅读项目源代码进行分析
- ❌ 不要自行诊断根本原因
- ❌ 不要设计技术解决方案
- ✅ 理解用户的意图并将其转化为清晰的任务描述
- ✅ 将用户反馈逐字传递给代理 (例如 瓷砖没有变大)
- ✅ 生成任务、监控进度、合并MR、维护集群系统
编码代理在完整的工作树中运行,拥有完整的项目上下文 — 它比你在聊天会话中更适合阅读代码、