← 返回 Skills 市场
halfdeadcat

Foreman

作者 halfdeadcat · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
71
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install foreman
功能描述
Orchestrate sub-agent workers and shell jobs with progress tracking, cron-based heartbeat monitoring, crash detection, and alerting. Use when spawning sub-ag...
使用说明 (SKILL.md)

Foreman — Work Orchestration

Overview

Foreman provides three orchestration modes:

  1. Agent Tasks — spawn sub-agents via sessions_spawn, track via .foreman/*.json status files. Pair with ClawFlow for durable flow identity.
  2. Shell Jobs — bash scripts/builds/deploys with automatic Slack heartbeats, crash detection, and cron-based monitoring.
  3. Hybrid — agent creates a ClawFlow flow, then spawns a shell job as one of its tasks. Cron monitor catches crashes even if the agent session dies.

Mode 1: Agent Tasks (recommended: pair with ClawFlow)

When to use: sub-agents, ACP sessions, multi-step async work, anything that needs to survive session restarts.

Use ClawFlow for: flow identity, durable state, waiting across sessions.
Foreman adds: exec hygiene conventions, model selection, spawn-time instructions, status files.

Fallback (if ClawFlow unavailable): write .foreman/*.json status files manually (see schema below).

Worker Prompt Template

Include this in every sessions_spawn task. Replace {TASK}, {RUN_ID}, {LABEL}, and {PARENT_SESSION}.

You are a Foreman worker (🤖 {LABEL}).

TASK: {TASK}

RULES:
1. Report progress to the main agent using sessions_send. Use the correct prefix and timeoutSeconds:
   - **Intermediate status:** `sessions_send(sessionKey="{PARENT_SESSION}", message="STATUS: 🤖 [{LABEL}]: what you're doing (60%)", timeoutSeconds=0)` — fire-and-forget, parent relays but does NOT spawn
   - **Errors/failures:** `sessions_send(sessionKey="{PARENT_SESSION}", message="ERROR: 🤖 [{LABEL}]: what failed — details")` — parent may intervene
   - **Completion:** `sessions_send(sessionKey="{PARENT_SESSION}", message="🤖 [{LABEL}]: ✅ done — summary")` — normal (no prefix, no timeoutSeconds override)
2. Send updates when: starting (STATUS:), completing major steps (STATUS:), encountering errors (ERROR:), finishing (no prefix)
3. Write status updates to ~/.openclaw/workspace/.foreman/{RUN_ID}.json using this format:
   {"run_id":"{RUN_ID}","label":"{LABEL}","status":"running","step":"current step description","progress":50,"error":null,"question":null,"updated":"ISO-8601"}
4. Valid status values: "starting", "running", "blocked", "error", "done"
5. Update the status file at each major step and when finishing
6. If you need clarification or hit an unrecoverable error, set status to "blocked" with a "question" field, send a sessions_send (ERROR: prefix) with your question, then STOP and wait for a steer message
7. On completion, set status to "done" with progress 100
8. Do NOT message Discord/Slack directly — always go through sessions_send to the main agent
9. HEARTBEAT: For tasks expected to take >2 minutes, send a STATUS: progress update via sessions_send (timeoutSeconds=0) every 2-3 minutes. Include what you're currently doing and rough % complete.

EXEC HYGIENE (mandatory — context blowup prevention):
- Pipe ALL potentially verbose commands through `tail -20` or `grep -E 'ERROR|WARN|success|done|failed'`
- Examples: `docker build ... 2>&1 | tail -20`, `pip install ... 2>&1 | tail -10`
- Never let raw build logs, install output, or long file listings land unfiltered in context
- If a command produces >50 lines, it must be filtered

Status File Schema

Path: ~/.openclaw/workspace/.foreman/\x3Crun-id>.json

{
  "run_id": "uuid",
  "label": "descriptive-name",
  "status": "starting|running|blocked|error|done",
  "step": "human-readable current step",
  "progress": 0,
  "error": "error message or null",
  "question": "question for foreman or null",
  "updated": "2026-03-05T20:00:00Z"
}

Spawn Steps

1. Generate run ID: $(uuidgen | tr '[:upper:]' '[:lower:]')
2. Create status dir: mkdir -p ~/.openclaw/workspace/.foreman
3. Write initial status file with status "starting"
4. ⚠️  COMPACT PARENT SESSION before spawning (mandatory — prevents context overflow deadlock)
   bash skills/foreman/scripts/compact-before-spawn.sh "\x3Ccurrent-session-key>"
   • Trims parent session to last 8 exchange pairs + synthetic summary
   • Reloads session in gateway so it takes effect immediately
   • Get current session key from runtime metadata (e.g. "agent:main:slack:direct:u0am4blbuuw")
   • Skip only if session is brand new (\x3C20 lines)
5. ⚠️  ACTIVATE AGENT MONITOR (mandatory — catches stale workers):
   crontab -l 2>/dev/null | grep -q agent-monitor || \
     (crontab -l 2>/dev/null; echo '*/2 * * * * /home/swabby/repos/swabby-brain/skills/foreman/scripts/agent-monitor.sh >> /tmp/agent-monitor.log 2>&1') | crontab -
   • Scans .foreman/*.json every 2 min
   • Alerts Slack if any worker stale >10 min
   • Auto-cleans terminal tasks after 60 min
   • MUST be active before any spawn — no exceptions
6. sessions_spawn with worker prompt template above
7. Track childSessionKey for steer/kill

Why compaction matters: When a sub-agent announces completion, the parent session must have enough headroom to receive it. A bloated parent (>30 messages) causes the announce to fail, retrying 4×120s = 8-minute deadlock. Compact first, spawn second.

Handle Blocked Workers

When a worker sets status: "blocked":

  1. Read the question from the status file
  2. Answer it yourself or relay to user
  3. subagents(action=steer, target=\x3Csession>, message=\x3Canswer>) to unblock
  4. Worker updates status back to "running"

Mode 2: Shell Jobs

When to use: bash scripts, builds, deploys, data pipelines — anything running as an OS process.

Lifecycle

job_init "$JOB_ID" "$LABEL"      # Write /tmp/swabby-jobs/\x3Cid>.json + .pid
job_register_cron "$JOB_ID"      # Install 5-min cron heartbeat
job_trap "$JOB_ID"               # Set EXIT trap → ✅/❌ alert + cleanup

job_progress "$JOB_ID" "Phase 2" # Update progress message (call anytime)
  • Heartbeat: monitor.sh sends Slack update every 5 minutes with label + elapsed time
  • Clean exit: trap fires → sends ✅/❌ → removes cron → deletes status files
  • Crash: monitor.sh notices dead PID → sends ⚠️ alert → cleans up

Template

# 1. Copy the template
cp skills/foreman/scripts/template-wrapper.sh scripts/jobs/my-job.sh

# 2. Edit: set JOB_ID, LABEL, replace job logic section
# 3. Test manually first
bash scripts/jobs/my-job.sh

# 4. Run in background when ready
bash scripts/jobs/my-job.sh &

Status Files

Path: /tmp/swabby-jobs/\x3Cjob_id>.json

{
  "job_id": "my-job-1234567890",
  "label": "My Job",
  "pid": 12345,
  "started": 1712345678,
  "progress": "Phase 2 of 3",
  "last_update": 1712345900
}

Mode 3: Hybrid

Agent creates a ClawFlow flow → spawns shell job as one of its tasks.

1. Create ClawFlow flow for identity + state
2. Use job wrapper for the OS-level work
3. Cron monitor catches crashes even if agent session dies
4. Flow completion requires both: agent task done + shell job exit 0

This gives you durable state (ClawFlow), structured output, AND crash-safe monitoring.


Configuration

Env var Default Purpose
FOREMAN_ALERT_TARGET $SLACK_TO Who receives alerts (user ID)
FOREMAN_ALERT_CHANNEL $SLACK_CHANNEL or slack Which channel

Backward compatible: if FOREMAN_ALERT_TARGET is unset, falls back to SLACK_TO. Same for channel.

Set in shell before running a job, or export in ~/.bashrc:

export FOREMAN_ALERT_TARGET="U0AM4BLBUUW"
export FOREMAN_ALERT_CHANNEL="slack"

Context Hygiene (CRITICAL)

See full reference: references/exec-hygiene.md

Short version:

  • Pipe all verbose commands through tail -20 or grep -E 'ERROR|WARN|...'
  • Always set runTimeoutSeconds on workers (never 0)
  • Exec-heavy workers: use model: "anthropic/claude-sonnet-4-6", not inherited Opus


Agent Task Monitor (agent-monitor.sh)

A cron-based monitor that watches ~/.openclaw/workspace/.foreman/*.json for active agent tasks and sends Slack alerts.

What it does:

  • Scans all .foreman/*.json files every 2 minutes
  • Sends status updates to Slack for recently-updated tasks (age \x3C 2 min)
  • Alerts once per task that goes stale (no update > 10 min): ⚠️ [label]: STALE — status - step (progress%) — no update for Nmin
  • Cleans up terminal tasks (done|error|completed) older than 60 minutes
  • Prevents overlapping runs via lock file
  • Deduplicates stale alerts via /tmp/agent-monitor-state.json

Cron install:

# Check current crontab first
crontab -l

# Add (if not already present)
(crontab -l 2>/dev/null; echo '*/2 * * * * /home/swabby/repos/swabby-brain/skills/foreman/scripts/agent-monitor.sh >> /tmp/agent-monitor.log 2>&1') | crontab -

Configuration:

Env var Default Purpose
FOREMAN_ALERT_TARGET U0AM4BLBUUW Slack user ID to alert
FOREMAN_ALERT_CHANNEL slack Channel for alerts
STALE_THRESHOLD_MIN 10 Minutes before stale alert
CLEANUP_THRESHOLD_MIN 60 Minutes after terminal to delete

Monitoring:

tail -f /tmp/agent-monitor.log
cat /tmp/agent-monitor-state.json  # stale alert dedup state

Quick Reference

Action Tool/Command
Spawn agent worker sessions_spawn with worker template above
Check agent status exec: cat ~/.openclaw/workspace/.foreman/\x3Cid>.json
Check all status exec: bash skills/foreman/scripts/foreman-status.sh
Steer worker subagents(action=steer, target=\x3Ckey>, message=...)
Kill worker subagents(action=kill, target=\x3Ckey>)
List agent sessions subagents(action=list)
Clean agent tasks exec: bash skills/foreman/scripts/foreman-cleanup.sh
New shell job Copy skills/foreman/scripts/template-wrapper.sh
Update job progress job_progress "$JOB_ID" "message"
Check shell jobs ls /tmp/swabby-jobs/*.json
Monitor agent tasks bash skills/foreman/scripts/agent-monitor.sh
Agent monitor log tail -f /tmp/agent-monitor.log
Model selection Sonnet for exec, inherit for reasoning
Timeout guidance See references/exec-hygiene.md
安全使用建议
This skill appears to implement orchestration features you might want, but it performs sensitive actions that are not declared: it reads local OpenClaw gateway/session files (including tokens), calls a local gateway API, writes persistent status files, and will by default send alerts to a hard-coded Slack target (U0AM4BLBUUW) unless you override it. Before installing or running: - Inspect and, if necessary, remove or change the default FOREMAN_ALERT_TARGET and FOREMAN_ALERT_CHANNEL in the scripts so alerts go only where you expect. Do not leave the hard-coded Slack ID. - Verify the openclaw CLI behavior (openclaw message send) and confirm it will not forward sensitive logs to external parties. - Confirm you trust the referenced transcript-trim.py and the absolute paths (/home/swabby/*). Replace author-specific paths with your own trusted tooling. - Backup your crontab, then run the scripts in a controlled test environment first to observe what cron entries are added/removed. - If you do not want the skill to access gateway tokens or session transcripts, do not grant it filesystem access to ~/.openclaw*; modify compact-before-spawn to avoid reading tokens or to require explicit env vars. Because of the hard-coded alert target and silent token access, treat this skill as suspicious until you remove or explicitly vet those behaviors.
功能分析
Type: OpenClaw Skill Name: foreman Version: 1.0.0 The 'foreman' skill bundle is a comprehensive orchestration framework designed to manage sub-agents and background shell jobs. It provides robust features for progress tracking, crash detection via cron-based heartbeats (scripts/monitor.sh), and automated session maintenance (scripts/compact-before-spawn.sh) to prevent context window overflow. While the bundle performs high-privilege operations—such as modifying the user's crontab for monitoring and accessing local gateway tokens to reload sessions—these actions are transparently documented and strictly aligned with the stated purpose of ensuring task durability and execution hygiene. No evidence of data exfiltration, unauthorized persistence, or malicious prompt injection was found.
能力评估
Purpose & Capability
Foreman’s scripts and SKILL.md align with an orchestration/monitoring purpose: spawning agents, writing status files, registering crons, and sending heartbeats. However, some actions (reading gateway tokens from ~/.openclaw-*/openclaw.json and calling a local chat-completions endpoint) access sensitive local gateway credentials and session transcripts. Those accesses can be justified for 'session compaction + reload', but they are sensitive and not declared in metadata.
Instruction Scope
SKILL.md and the scripts instruct the agent to read session JSONL files, load tokens from user config files, call a local HTTP gateway, and run an external transcript-trim.py at an absolute author-specific path (/home/swabby/bin/transcript-trim.py). The instructions therefore access file system locations and credentials beyond simple orchestration (session tokens, transcripts), and they require the agent to run code that modifies user crontab and session state. These steps broaden scope and require explicit user acknowledgement.
Install Mechanism
This is instruction+script-only with no install spec. Nothing is downloaded or installed by the registry. Risk from install mechanism itself is low. That said, included scripts reference author-specific files and assume a particular environment, which may silently fail or behave unexpectedly.
Credentials
The skill declares no required env/config but silently reads local gateway tokens and session files. More importantly, agent-monitor.sh sets a default FOREMAN_ALERT_TARGET of 'U0AM4BLBUUW' (looks like a Slack user ID). If not overridden, job statuses/alerts may be sent to that ID by default. That default destination is a high-risk surprise (potential data exfiltration) and is not justified in the description or requires fields.
Persistence & Privilege
Foreman registers cron jobs (modifying the user's crontab) and writes state files under ~/.openclaw and /tmp; that persistence is consistent with the stated need to monitor long-running jobs. It's not marked always:true, but it does change persistent user state (crontab and files), so users should expect lasting side-effects and review crontab changes.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install foreman
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /foreman 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Foreman 1.0.0 — Initial Release - Orchestrates sub-agent workers and shell jobs with progress tracking, crash detection, and alerting. - Supports three modes: Agent Tasks (with `.foreman/*.json` status files), Shell Jobs (with cron-based monitoring), and Hybrid (agent+shell job with ClawFlow). - Includes session compaction to prevent context blowup and deadlocks. - Crash and heartbeat monitoring via cron; sends Slack alerts for stale or failed jobs. - Provides strict exec/context hygiene guidelines for reliable multi-agent orchestration. - Adds agent task monitoring script (`agent-monitor.sh`) for status tracking and alerting.
元数据
Slug foreman
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Foreman 是什么?

Orchestrate sub-agent workers and shell jobs with progress tracking, cron-based heartbeat monitoring, crash detection, and alerting. Use when spawning sub-ag... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 71 次。

如何安装 Foreman?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install foreman」即可一键安装,无需额外配置。

Foreman 是免费的吗?

是的,Foreman 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Foreman 支持哪些平台?

Foreman 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Foreman?

由 halfdeadcat(@halfdeadcat)开发并维护,当前版本 v1.0.0。

💬 留言讨论