Periodic consolidation agent — session backfill, episode replay, index refresh, staleness sweep, brain sync. Runs on GitHub Actions cron or manually via /sleep.
From aops-coworknpx claudepluginhub nicsuzor/academicops --plugin aops-coworkThis skill is limited to using the following tools:
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Enables AI agents to execute x402 payments with per-task budgets, spending controls, and non-custodial wallets via MCP tools. Use when agents pay for APIs, services, or other agents.
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
Taxonomy note: This skill orchestrates periodic offline consolidation — transforming write-optimised storage (tasks, session logs) into read-optimised knowledge that agents actually use. See
specs/sleep-cycle.mdfor full design rationale.
The sleep cycle is an agent session, not a script. A Claude agent is launched (via GitHub Actions cron or manually) with a consolidation prompt. The agent works through phases using judgment, calling tools as signals — not deterministic code that makes the decisions.
# Trigger via GitHub Actions (runs in $ACA_DATA repo)
gh workflow run sleep-cycle -R nicsuzor/brain
# Manual invocation as a skill
/sleep
# Focus on a specific area
gh workflow run sleep-cycle -R nicsuzor/brain -f focus="staleness only"
The agent works through these in order, using judgment about what needs attention:
| Phase | Name | What it does |
|---|---|---|
| 0 | Graph Health | Run graph_stats — baseline measurement for this cycle |
| 1 | Session Backfill | Run /session-insights batch for pending transcripts |
| 2 | Episode Replay | Scan recent activity, identify promotion candidates |
| 3 | Index Refresh | Update mechanical framework indices (SKILLS.md, etc.) |
| 4 | Data Quality Reconciliation | Dedup, staleness verification, misclassification |
| 5 | Staleness Sweep | Detect orphans, stale docs, under-specified tasks |
| 5b | Graph Maintenance | Densify, reparent, or connect — pick ONE strategy |
| 6 | Brain Sync | Commit and push $ACA_DATA; re-run graph_stats |
Run graph_stats at the start of every cycle. Record:
flat_tasks — tasks with no parent or childrendisconnected_epics — epics not connected to a projectprojects_without_goal_linkage — projects with no goals: [] field populatedorphan_count — truly disconnected nodesstale_count — tasks not modified in 7+ days while in_progressThis is the baseline. Phase 6 re-runs graph_stats to measure what changed.
Before structural work, fix the data. Structural metrics are meaningless when the graph is inflated with duplicates, stale items, and misclassified content. Data quality MUST run before Graph Maintenance (Phase 5b).
Three activities, run in order. Each is bounded per cycle.
find_duplicates(mode="both") to get clusters by title + semantic similarity.batch_merge. The tool selects the canonical node (most connected, most content).Target: active tasks with age >= 90 days.
For each candidate (up to 20 per cycle):
messages_search)calendar_list_events)complete_task with note explaining evidencecomplete_task with "auto-closed: no activity, deadline long past"Environment guard: Email/calendar tools require local MCP servers (not available on GitHub Actions). When running on CI, skip evidence-based verification entirely — only flag candidates. Staleness verification only runs effectively during manual /sleep invocations on the Mac.
Target patterns:
For matches:
batch_archive with reason, or batch_reclassify to "memory"Time budget: Phase 4 gets 10 minutes max. Exit the phase when time is up.
The agent uses these as signals, not as deterministic verdicts:
mcp__pkb__pkb_orphans()Delegates to the Planner agent's maintain mode. Sleep selects the strategy based on graph_stats; Planner executes it.
Each cycle, pick ONE strategy based on what graph_stats shows needs the most attention:
| Condition | Strategy | Planner Activity |
|---|---|---|
disconnected_epics > 10 | Connect epics | Reparent — find project parents for disconnected epics |
projects_without_goal_linkage > 10 | Link projects | Add goals: [] metadata — link projects to existing goals via metadata field |
flat_tasks > 100 | Reparent flat tasks | Reparent — find epic/project parents for orphans |
orphan_count > 20 | Fix orphans | Reparent — connect or archive disconnected nodes |
| All metrics healthy | Densify edges | Densify — use strategies to add dependency edges |
Type-aware orphan detection: pkb_orphans now reports both missing-parent AND wrong-type-parent orphans (e.g., a task parented directly to a project instead of an epic). Phase 5b should treat wrong-type-parent orphans the same as missing-parent orphans when selecting a reparent strategy.
See aops-core/skills/planner/SKILL.md → maintain mode for full activity reference.
Bounded effort: Process a configurable number of items per cycle (default 100, set via batch_limit workflow input). Use mcp__pkb__bulk_reparent for efficiency when processing multiple items with the same parent. Quality over quantity.
Autonomous vs. flagged:
Measure after: Re-run graph_stats in Phase 6 to confirm the metric improved.
When running via /loop or /active-loop, the sleep cycle follows the active-loop protocol:
templates/github-workflows/sleep-cycle.yml ← workflow template (maintained in $AOPS)
$ACA_DATA/.github/workflows/sleep-cycle.yml ← installed copy (runs the agent)
The workflow uses anthropics/claude-code-action to launch an agent with a consolidation prompt. The agent has access to the brain repo and academicOps tools.