Get the FREE Ultimate OpenClaw Setup Guide →

context-preservation

npx machina-cli add skill a5c-ai/babysitter/context-preservation --openclaw
Files (1)
SKILL.md
2.0 KB

context-preservation

You are context-preservation -- the state preservation skill for Pilot Shell.

Overview

This skill manages context window state across compactions, ensuring seamless continuation of work when context is refreshed. It implements the PreCompact and post_compact_restore patterns from Pilot Shell.

Capabilities

1. State Capture (PreCompact)

  • Serialize current spec state (tasks, statuses, acceptance criteria)
  • Capture quality pipeline state (last lint/format/typecheck results)
  • Save TDD progress (current phase, iteration count, scores)
  • Store context monitor metrics
  • Write to .pilot-shell/state.json

2. State Restore (SessionStart / post_compact_restore)

  • Read .pilot-shell/state.json on session start
  • Restore spec task tracking state
  • Restore quality baseline
  • Resume TDD from last known position
  • Log restoration summary

3. Threshold Monitoring

  • Track context usage percentage (default threshold: 70%)
  • Trigger preservation when threshold approached
  • Calculate optimal preservation timing

State Schema

{
  "version": "1.0.0",
  "timestamp": "2026-03-02T12:00:00Z",
  "spec": {
    "title": "...",
    "taskStatuses": [{ "id": "...", "status": "COMPLETE" }],
    "currentPhase": "implement"
  },
  "quality": {
    "lastScore": 87,
    "lint": { "passed": true },
    "format": { "passed": true },
    "typecheck": { "passed": true }
  },
  "tdd": {
    "iteration": 2,
    "score": 92,
    "compliant": true
  },
  "context": {
    "usagePercent": 72,
    "preservedAt": "2026-03-02T12:00:00Z"
  }
}

Source

git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/methodologies/pilot-shell/skills/context-preservation/SKILL.mdView on GitHub

Overview

Context-preservation saves and restores state across context window compactions to enable seamless continuation. It captures spec tasks, quality results, and TDD progress, and uses usage thresholds to trigger timely preservation.

How This Skill Works

Before compaction, the skill serializes the current spec (tasks, statuses, acceptance criteria), quality pipeline results, and TDD progress to .pilot-shell/state.json. On session start or after a restore, it reads that file to rehydrate task tracking, restore the quality baseline, and resume TDD from the last known position.

When to Use It

  • When editing long-running projects with many tasks and acceptance criteria that risk being truncated by the context window
  • Before planned context compaction or window trimming to preserve continuity
  • After an interruption or tool restart to resume from the saved state
  • When context usage approaches the 70% default threshold and preservation should be triggered
  • During session re-entry to restore previous spec, quality, and TDD progress

Quick Start

  1. Step 1: Monitor context usage and trigger a PreCompact capture when the threshold nears (default ~70%).
  2. Step 2: Serialize spec, quality, and TDD progress to .pilot-shell/state.json.
  3. Step 3: On session start, read the state.json to restore task tracking, quality baseline, and TDD position.

Best Practices

  • Serialize only essential fields: spec, quality, and TDD progress to keep state.json lean
  • Verify .pilot-shell/state.json integrity after every capture
  • Test restore end-to-end: simulate session restart to confirm accurate recovery
  • Adjust the threshold thoughtfully based on workflow and window size
  • Log a concise restoration summary for auditing and debugging

Example Use Cases

  • A developer working across multiple tasks saves the state before a heavy refactor, ensuring tasks, lint results, and TDD scores restore correctly after compaction
  • A long-running data-cleaning task hits the context window limit and triggers preservation so the pipeline can resume without losing progress
  • On session restart, the bot reads state.json to rehydrate spec task tracking and continue from the last iteration
  • Quality checks (lint/format/typecheck) are preserved, allowing a seamless resumption of the pipeline after restoration
  • The system logs a restoration summary so operators can verify what was recovered and what progressed

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers