agentleFS
naman10parikhnaman10parikh/penny/.claude/skills/heartbeat/SKILL.md

heartbeat

Skill0 starsChanged 28 days agoMITView on GitHub

Implement the HEARTBEAT.md pattern for proactive agent behavior. Agents check for updates, run scheduled tasks, and act without user prompting. Each agent has a HEARTBEAT.md file that defines scheduled tasks: If HEARTBEAT.md is empty or missing, no heartbeat fires (saves API costs).

20 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 15 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If HEARTBEAT.md is empty or missing, no heartbeat fires (saves API costs).

    line 27

“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Skill: Heartbeat System

Implement the HEARTBEAT.md pattern for proactive agent behavior. Agents check for updates, run scheduled tasks, and act without user prompting.

Pattern (From OpenClaw/NanoClaw)

Each agent has a HEARTBEAT.md file that defines scheduled tasks:

# Heartbeat — GiftFinder

## Every 6 hours

- [ ] Check tracked items for price drops
- [ ] Scan wishlists for new additions

## Every 24 hours

- [ ] Review saved preferences for staleness
- [ ] Check for new product launches in tracked categories

## Weekly

- [ ] Generate gift suggestion digest for upcoming events

If HEARTBEAT.md is empty or missing, no heartbeat fires (saves API costs).

Implementation

Task Scheduler (Host Process)

import { CronJob } from "cron-parser";

interface ScheduledTask {
  id: string;
  agentId: string;
  prompt: string;
  scheduleType: "cron" | "interval" | "once";
  scheduleValue: string; // cron expression, ms interval, or ISO date
  nextRun: Date;
  status: "active" | "paused" | "completed";
}

// SQLite schema
const SCHEMA = `
CREATE TABLE IF NOT EXISTS scheduled_tasks (
  id TEXT PRIMARY KEY,
  agent_id TEXT NOT NULL,
  prompt TEXT NOT NULL,
  schedule_type TEXT NOT NULL,
  schedule_value TEXT NOT NULL,
  next_run TEXT NOT NULL,
  status TEXT DEFAULT 'active',
  last_run TEXT,
  created_at TEXT DEFAULT (datetime('now'))
)`;

// Polling loop — check every 30 seconds
async function heartbeatLoop(db: Database): Promise<void> {
  while (true) {
    const due = db
      .prepare(
        `SELECT * FROM scheduled_tasks
       WHERE status = 'active' AND next_run <= datetime('now')
       ORDER BY next_run ASC LIMIT 5`,
      )
      .all() as ScheduledTask[];

    for (const task of due) {
      await executeHeartbeatTask(task);
      updateNextRun(db, task);
    }

    await sleep(30_000);
  }
}

HEARTBEAT.md Parser

function parseHeartbeat(content: string): ScheduledTask[] {
  const tasks: ScheduledTask[] = [];
  let currentSchedule = "";

  for (const line of content.split("\n")) {
    const scheduleMatch = line.match(/^##\s+(.+)/);
    if (scheduleMatch) {
      currentSchedule = scheduleMatch[1].trim();
      continue;
    }

    const taskMatch = line.match(/^-\s+\[[ x]\]\s+(.+)/);
    if (taskMatch && currentSchedule) {
      tasks.push({
        id: crypto.randomUUID(),
        agentId: "", // set by caller
        prompt: taskMatch[1].trim(),
        scheduleType: inferScheduleType(currentSchedule),
        scheduleValue: inferScheduleValue(currentSchedule),
        nextRun: computeNextRun(currentSchedule),
        status: "active",
      });
    }
  }
  return tasks;
}

function inferScheduleValue(schedule: string): string {
  const lower = schedule.toLowerCase();
  if (lower.includes("every 6 hours")) return "0 */6 * * *";
  if (lower.includes("every 24 hours") || lower === "daily") return "0 0 * * *";
  if (lower === "weekly") return "0 0 * * 0";
  if (lower.includes("every")) {
    const match = lower.match(/every (\d+) (minute|hour|day)/);
    if (match) {
      const [, n, unit] = match;
      if (unit === "minute") return `*/${n} * * * *`;
      if (unit === "hour") return `0 */${n} * * *`;
      if (unit === "day") return `0 0 */${n} * *`;
    }
  }
  return "0 0 * * *"; // default: daily
}

Heartbeat Execution

async function executeHeartbeatTask(task: ScheduledTask): Promise<void> {
  // Spawn sandbox with task prompt + agent context
  const prompt = [
    `[HEARTBEAT TASK] ${task.prompt}`,
    `This is an automated scheduled task. Act on it, save results to memory.`,
    `If nothing actionable, reply briefly and exit.`,
  ].join("\n");

  await spawnSandbox({
    agentId: task.agentId,
    prompt,
    isHeartbeat: true, // lower priority in concurrency queue
    maxTurns: 10, // cap heartbeat complexity
  });
}

Key Design Decisions

  • Empty HEARTBEAT.md = no heartbeat (cost control)
  • Heartbeat tasks run at lower priority than user messages
  • Max 10 turns per heartbeat (prevents runaway costs)
  • Results saved to agent memory for user visibility
  • Tasks are idempotent — safe to retry on failure

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.