home / skills / toonight / get-shit-done-for-antigravity / context-health-monitor

context-health-monitor skill

/.agent/skills/context-health-monitor

This skill monitors session context health, detects repeats and uncertainty, and auto-saves state to prevent context rot.

npx playbooks add skill toonight/get-shit-done-for-antigravity --skill context-health-monitor

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.0 KB
---
name: Context Health Monitor
description: Monitors context complexity and triggers state dumps before quality degrades
---

# Context Health Monitor

## Purpose

Prevent "Context Rot" — the quality degradation that occurs as the agent processes more information in a single session.

## When This Skill Activates

The agent should self-monitor for these warning signs:

### Warning Signs

| Signal | Threshold | Action |
|--------|-----------|--------|
| Repeated debugging | 3+ failed attempts | Trigger state dump |
| Going in circles | Same approach tried twice | Stop and reassess |
| Confusion indicators | "I'm not sure", backtracking | Document uncertainty |
| Session length | Extended back-and-forth | Recommend `/pause` |

## Behavior Rules

### Rule 1: The 3-Strike Rule

If debugging the same issue fails 3 times:

1. **STOP** attempting fixes
2. **Document** in `.gsd/STATE.md`:
   - What was tried
   - What errors occurred
   - Current hypothesis
3. **Recommend** user start fresh session
4. **Do NOT** continue with more attempts

### Rule 2: Circular Detection

If the same approach is being tried again:

1. **Acknowledge** the repetition
2. **List** what has already been tried
3. **Propose** a fundamentally different approach
4. **Or** recommend `/pause` for fresh perspective

### Rule 3: Uncertainty Logging

When uncertain about an approach:

1. **State** the uncertainty clearly
2. **Document** in `.gsd/DECISIONS.md`:
   - The uncertain decision
   - Why it's uncertain
   - Alternatives considered
3. **Ask** user for guidance rather than guessing

## State Dump Format

When triggered, write to `.gsd/STATE.md`:

```markdown
## Context Health: State Dump

**Triggered**: [date/time]
**Reason**: [3 failures / circular / uncertainty]

### What Was Attempted
1. [Approach 1] — Result: [outcome]
2. [Approach 2] — Result: [outcome]
3. [Approach 3] — Result: [outcome]

### Current Hypothesis
[Best guess at root cause]

### Recommended Next Steps
1. [Fresh perspective action]
2. [Alternative approach to try]

### Files Involved
- [file1.ext] — [what state it's in]
- [file2.ext] — [what state it's in]
```

## Auto-Save Protocol

**Critical:** When any warning signal triggers, the agent must save state BEFORE recommending `/pause` to the user. This ensures state persists even if the session hard-terminates.

### Steps

1. **Write** a state snapshot to `.gsd/STATE.md` immediately when a threshold is hit
2. **Include** at minimum: current phase, current task, last action, next step
3. **Then** inform the user of the situation and recommend `/pause`

### Why

Sessions can terminate abruptly (usage limits, context limits, network errors). If the agent waits for the user to type `/pause`, it may never get the chance. By saving first and recommending second, state is always preserved.

## Integration

This skill integrates with:
- `/pause` — Triggers proper session handoff (includes proactive auto-save)
- `/resume` — Loads the state dump context
- Rule 3 in `GEMINI.md` — Context Hygiene enforcement

Overview

This skill monitors an agent's conversational context for signs of degradation and proactively saves state before quality drops. It detects repeated failures, circular behavior, and explicit uncertainty, then writes concise state dumps and recommends pausing or changing course. The goal is to preserve useful context and avoid wasted effort when sessions become unreliable.

How this skill works

The monitor observes agent signals like repeated debugging attempts, identical approaches tried twice, phrases that indicate confusion, and long back-and-forth sessions. When thresholds are reached it immediately writes a structured state snapshot to .gsd/STATE.md (and uncertainty notes to .gsd/DECISIONS.md) and then notifies the user with a recommendation to pause or try a new approach. It enforces a 3-strike stop rule, circular-detection flow, and explicit uncertainty logging.

When to use it

  • During long interactive sessions where context may drift or accumulate noise
  • When the same fix or debugging step has failed multiple times
  • If the agent repeats approaches or cycles through the same logic
  • When the agent expresses uncertainty or backtracking language
  • Before recommending a session pause or handoff to preserve state

Best practices

  • Always auto-save state immediately on hitting a warning threshold before prompting the user
  • Record what was attempted, outcomes, current hypothesis, and recommended next steps in the state dump
  • Acknowledge repetition and present a clearly different alternative rather than repeating the same steps
  • Ask the user for guidance when uncertain instead of guessing
  • Keep state files concise and machine-parseable to support automated resume

Example use cases

  • A debugging loop hits the same error three times: the skill saves a state dump and recommends starting a fresh session
  • The agent cycles between two strategies: the skill lists tried approaches and proposes a fundamentally different plan
  • The agent says 'I'm not sure' about a migration step: the skill logs the uncertainty and requests user direction
  • During an extended design conversation the skill recommends /pause and writes the current phase, last action, and next step to state
  • Automated handoffs where /resume will reload the precise saved context for a new session

FAQ

Will the skill stop work completely after three failures?

It stops further repeated attempts on that issue, documents the attempts and hypothesis, and recommends a fresh session or different approach.

What gets saved in the state dump?

A timestamped summary of attempts, results, current hypothesis, recommended next steps, and involved files with their states.