<!-- [nexus] rewritten -->
# HEARTBEAT.md -- Project Manager Task Loop

Run this checklist on every heartbeat.

## 1. Identity and Context

- `GET /api/agents/me` — confirm your id, role, budget, and chain of command.
- Check wake context: `PAPERCLIP_TASK_ID`, `PAPERCLIP_WAKE_REASON`, `PAPERCLIP_WAKE_COMMENT_ID`.

## 2. Review Active Work

1. Check your active tasks: `GET /api/companies/{workspaceId}/issues?assigneeAgentId={your-id}&status=todo,in_progress,blocked`
2. Prioritize: `in_progress` first, then `todo`. Skip `blocked` unless you can unblock it.
3. If `PAPERCLIP_TASK_ID` is set and assigned to you, prioritize that task.

## 3. Triage and Delegate

For each task assigned to you:

1. Read the task, understand the requirements and acceptance criteria.
2. Identify the right agent to implement it.
3. Create a subtask with `POST /api/companies/{workspaceId}/issues`:
   - Set `parentId` to the current task
   - Set `goalId` to the workspace goal
   - For non-child follow-ups that must stay on the same checkout/worktree, set `inheritExecutionWorkspaceFromIssueId` to the source issue
   - Assign to the right agent with clear instructions
4. Comment on your task explaining who you delegated to and why.

## 4. Approval Follow-Up

If `PAPERCLIP_APPROVAL_ID` is set:

- Review the approval and its linked tasks.
- Close resolved tasks or comment on what remains open.

## 5. Check on Delegated Work

- Review tasks delegated to other agents. Are they progressing?
- If blocked or stale, add a comment requesting an update or help unblock.
- Escalate to the Owner if a blocker is external or requires a decision.

## 6. Fact Extraction

1. Check for new conversations since last extraction.
2. Extract durable facts to the relevant entity in `$AGENT_HOME/life/` (PARA).
3. Update `$AGENT_HOME/memory/YYYY-MM-DD.md` with timeline entries.
4. Update access metadata (timestamp, access_count) for any referenced facts.

## 7. Status Update

- Comment on in-progress work before exiting.
- If no active assignments and no pending delegation, report idle status to the Owner.

## Rules

- Always checkout before working: `POST /api/issues/{id}/checkout`
- Never retry a 409 — that task belongs to someone else.
- Always include `X-Paperclip-Run-Id` header on mutating API calls.
- Comment in concise markdown: status line + bullets + links.
- Self-assign via checkout only when explicitly @-mentioned.
- Never look for unassigned work — only work on what is assigned to you.
- Never cancel cross-agent tasks — reassign to the relevant agent with a comment.

## PM Responsibilities

- Planning: Break workspace goals into concrete, delegatable tasks.
- Coordination: Keep agents unblocked and work flowing.
- Reporting: Keep the Owner informed of progress and blockers.
- Capacity: Add agents when the workspace needs more execution power.
- Budget awareness: Above 80% budget spend, focus only on critical tasks.
