Periodic consolidation agent — session backfill, transcript mining, knowledge consolidation, quality review, staleness sweep, brain sync. Runs on GitHub Actions cron or manually via /sleep.
From aops-corenpx claudepluginhub nicsuzor/aopsThis 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 mirrors biological memory consolidation. Complementary Learning Systems theory (McClelland et al. 1995) shows that the hippocampus rapidly stores episodes while the neocortex gradually extracts patterns through offline replay during sleep. Semanticization (Baddeley 1988) confirms that episodic memories lose temporal context through repeated retrieval and integration, becoming decontextualized semantic knowledge. This is a feature, not a bug — decontextualized knowledge is more retrievable.
Implications for this system:
These principles govern all consolidation work — manual /sleep invocations and CI workflows alike.
consolidated: YYYY-MM-DD to their frontmatter.provisional to established without additional evidence from independent sources.seedling (single source, provisional) → budding (corroborated by 2+ sources) → evergreen (reviewed, stable, established). Maturity progresses through evidence, not time.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 |
| 1b | Transcript Mining | Extract unsaved insights from session transcripts |
| 2 | Episode Replay | Scan recent activity, identify promotion candidates |
| 2b | Knowledge Consolidation | Transform episodic content into semantic knowledge |
| 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 |
| 5a | Refile Processing | Re-parent user-flagged tasks via /planner, remove flag |
| 5b | Graph Maintenance | Densify, reparent, or connect — pick ONE strategy |
| 5c | PKB Quality Review | Qualitative assessment of knowledge note quality |
| 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.
Extract insights from session transcripts that agents may not have saved during the session.
Input: Session transcripts in $AOPS_SESSIONS/ (JSONL files)
Output: Knowledge notes created via /remember skill
.mined marker files or mined_transcripts.json manifestaops-core/scripts/transcript.py to convert if needed)
b. Identify extractable insights: decisions made, patterns observed, facts learned, problems solved
c. For each insight: search PKB first (mcp__pkb__search) to avoid duplicates
d. Create knowledge notes via /remember skill with proper provenance:
sources: ["Session transcript <session-id> <date>"]confidence: provisional (single source)
e. Mark transcript as minedTranscript mining requires access to $AOPS_SESSIONS. On GitHub Actions, this directory may be mounted or cloned separately. Skip this phase if transcripts are not accessible.
Process up to 5 transcripts per cycle. Each transcript may yield 0-10 insights. Time budget: 5 minutes.
Transform episodic memory into durable semantic knowledge. This is the core of the sleep cycle's value — it mirrors the cognitive process of semanticization, where temporal memories are decontextualized into lasting understanding.
Daily notes / Meeting notes / Task bodies (episodic)
↓ extract observations
Atomic observations with provenance
↓ detect patterns across 3+ observations
Synthesis notes (semantic knowledge)
↓ accumulate related synthesis
Maps of Content (navigational hubs)
Identify consolidation candidates: Find episodic content older than 7 days that hasn't been consolidated:
consolidated: YYYY-MM-DD in frontmatterconsolidated: YYYY-MM-DDExtract observations: For each candidate (up to 10 per cycle):
a. Read the episodic content carefully
b. Identify atomic facts, decisions, patterns, and insights
c. Search PKB for existing knowledge notes on the same topics
d. Either augment existing knowledge notes or create new ones
e. Use observation notation format (see /remember skill)
f. Always include provenance: sources: ["[[source-note]]"]
g. Mark the episodic source as consolidated: YYYY-MM-DD in its frontmatter (but DO NOT modify the content — episodic notes are preserved as-is)
Detect synthesis opportunities: When 3+ observations exist on the same topic:
a. Create or update a synthesis note that integrates the observations
b. Synthesis note frontmatter includes all source observations
c. confidence level based on evidence strength:
established: 3+ independent sources agreeprovisional: pattern emerging but limited evidencespeculative: single inference, needs verificationGenerate MOCs: When a topic area has 5+ related knowledge notes: a. Check if a MOC already exists for that topic b. If not, create one with curated links and brief annotations c. If yes, update with new entries
consolidated: YYYY-MM-DD to their frontmatter.Before creating new knowledge notes, check for overlapping existing notes. When two notes cover substantially the same topic:
superseded_by or wikilink referencesThis is distinct from Phase 4's task dedup — it operates on knowledge/ files by reading and comparing content qualitatively, not by title/embedding similarity.
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()Process tasks the user has explicitly flagged for refiling via the dashboard's REFILE button. These are user-initiated reparent requests and take priority over automated graph maintenance.
refile: true across $ACA_DATA/tasks//planner in maintain mode (reparent activity) for each flagged task — the planner reads the task's context and finds an appropriate parentrefile key from the task's YAML frontmatterrefile: true and add needs_triage: true to prevent re-processingDelegates 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.
A 2-minute sanity check of THIS cycle's own output. This is NOT a quality review — the real quality gate is the /qa review on the consolidation PR (see "Output" section below).
For each knowledge note created or modified in this cycle:
sources: in frontmatter?If any check fails: log the issue in the cycle summary and flag it in the PR description. Do not try to fix content quality problems — that's the QA reviewer's job.
Quality findings from this cycle and from /qa reviews should feed back into improving the consolidation process. When a pattern of quality issues is detected (same issue appearing across 3+ cycles):
mcp__pkb__create_task or gh issue create)consolidate.md or quality-exemplars.md would prevent recurrenceThis closes the loop: consolidation → QA review → quality findings → procedure improvements → better consolidation.
When running via /loop or /active-loop, the sleep cycle follows the active-loop protocol:
/qa review on each consolidation PR tests this hypothesis. If quality review reveals persistent problems, escalate enforcement — don't just trust harder.Knowledge creation (Phases 1b, 2b) produces output of uncertain quality. This output MUST go through a QA gate before reaching the main branch. The sleep cycle creates a PR — it never commits knowledge directly to main.
sleep/consolidation-YYYY-MM-DD-HHMM/qa skill reviews the PR for fitness-for-purpose (triggered by PR creation or manual invocation)./qa agent reviews, human reviews QA decisions/qa auto-approves, human reviews only rejectionsEach transition requires evidence from the previous level (P#22 corollary on graduated trust).
templates/github-workflows/sleep-cycle.yml ← workflow template (maintained in $AOPS)
$ACA_DATA/.github/workflows/sleep-cycle.yml ← installed copy (runs the agent)
Install via: scripts/install-brain-workflows.sh <brain-repo-path>
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. In CI, the agent works directly with markdown files — no PKB MCP server is available. Changes sync to PKB consumers via git push.