agentleFS
marcusgollmarcusgoll/Spec-Flow/.claude/skills/session-boundary/SKILL.md

session-boundary

Skill94 starsChanged 7 months agoMITView on GitHub

Detect and handle session boundaries for multi-context autopilot workflows. Manage smooth transitions across context windows by: 1. Detecting when context is about to be compacted 2. Generating comprehensive handoff documents 3. Restoring state after context restoration 4. Tracking session metrics for workflow optimization Critical: Never keep state only in conversation memory. Always persist immediately. Added to state.yaml (schema v2.2.0): Located at: {workflow_dir}/sessions/handoff-{timestamp}.md bash /{workflow_type} continue

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Critical: Never keep state only in conversation memory.

    line 25
  2. Distinctive:

    Check for and display handoff documents

    line 176
  3. Distinctive:

    Start a new session for tracking

    line 177
  4. Very specific:

    Stop hook can return {"decision": "block"} to continue execution

    line 201
  5. Distinctive:

    Only blocks on actual failures (CI, tests, deployment)

    line 204

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Session Boundary Skill

Detect and handle session boundaries for multi-context autopilot workflows.

Purpose

Manage smooth transitions across context windows by:

  1. Detecting when context is about to be compacted
  2. Generating comprehensive handoff documents
  3. Restoring state after context restoration
  4. Tracking session metrics for workflow optimization

When to Invoke

  • Automatically via SessionStart hook (startup, resume, compact triggers)
  • Automatically via PreCompact hook (before context compaction)
  • Automatically via Stop hook (session end)
  • Manually via /context next or /context status
  • During /feature continue or /epic continue

Core Concepts

Write-Through State Pattern

Critical: Never keep state only in conversation memory. Always persist immediately.

# Good: Write to state.yaml immediately
session:
  id: "session-20251204-143000"
  started_at: "2025-12-04T14:30:00Z"
  phase_at_start: "implement"
  decisions_made: ["Redis for token blacklist"]

# Bad: Keeping state only in conversation
# "I decided to use Redis..." (lost on compaction)

Session Lifecycle

┌──────────────┐    ┌──────────────┐    ┌──────────────┐
│ SessionStart │───▶│   Working    │───▶│     Stop     │
│   (restore)  │    │   (track)    │    │ (checkpoint) │
└──────────────┘    └──────────────┘    └──────────────┘
                           │
                           ▼
                    ┌──────────────┐
                    │  PreCompact  │
                    │  (handoff)   │
                    └──────────────┘
                           │
                           ▼
                    ┌──────────────┐
                    │ SessionStart │
                    │  (restore)   │
                    └──────────────┘

Hook Integration

HookTriggerPurpose
SessionStartstartup, resume, compactRestore workflow context
PreCompactauto, manualGenerate handoff before context loss
Stopsession endCheckpoint current state

Session Manager Commands

# Start new session (with optional autopilot)
bash .spec-flow/scripts/bash/session-manager.sh start --autopilot

# View current status
bash .spec-flow/scripts/bash/session-manager.sh status

# Record important decision
bash .spec-flow/scripts/bash/session-manager.sh decision "Using Redis for caching"

# Generate handoff manually
bash .spec-flow/scripts/bash/session-manager.sh handoff

# End session with summary
bash .spec-flow/scripts/bash/session-manager.sh end --summary "Completed auth implementation"

# Control autopilot mode
bash .spec-flow/scripts/bash/session-manager.sh autopilot on|off|status

# View session history
bash .spec-flow/scripts/bash/session-manager.sh history

State Schema (session block)

Added to state.yaml (schema v2.2.0):

session:
  id: "session-20251204-143000"
  started_at: "2025-12-04T14:30:00Z"
  ended_at: null
  last_activity: "2025-12-04T16:45:00Z"
  phase_at_start: "implement"
  tasks_at_start: 12
  tasks_completed_this_session: 4
  decisions_made:
    - "Redis for token blacklist"
    - "JWT expiry 15min"
  handoffs:
    - id: "handoff-20251204-163000"
      at: "2025-12-04T16:30:00Z"
  last_handoff_id: "handoff-20251204-163000"
  last_handoff_at: "2025-12-04T16:30:00Z"
  autopilot_enabled: false
  duration_seconds: null
  summary: null

Handoff Document Structure

Located at: {workflow_dir}/sessions/handoff-{timestamp}.md

# Session Handoff: {slug}

> Generated: {timestamp}
> Trigger: {context compaction | manual | session end}
> Phase: {current_phase}
> Status: {current_status}

## Quick Resume

```bash
/{workflow_type} continue

Current State

MetricValue
Workflow Typefeature/epic
Slug{slug}
Current Phase{phase}
Phase Status{status}
Tasks Progress{completed} / {total}

Next Task

{next_uncompleted_task}

Recent Decisions

{list_of_recent_decisions}

Key Artifacts

  • State: state.yaml
  • Tasks: tasks.md
  • Notes: NOTES.md ...

Context for Next Session

  1. Read state.yaml for complete workflow state
  2. Check tasks.md for task completion status
  3. Review NOTES.md for recent decisions and blockers
  4. Use /context next for detailed next steps

## Integration Points

### /feature continue and /epic continue

Both commands now:
1. Display session status before resuming
2. Check for and display handoff documents
3. Start a new session for tracking

### /context Command

- `/context status` - Shows session and workflow status
- `/context next` - Generates handoff document
- `/context add` - Records item to backlog

### NOTES.md Session Markers

Session boundaries are recorded in NOTES.md:

```markdown
---

## Session Boundary: 2025-12-04T16:30:00Z

*Context compaction occurred. Handoff saved to: sessions/handoff-20251204-163000.md*

Autopilot Mode

When autopilot_enabled: true:

  1. Stop hook can return {"decision": "block"} to continue execution
  2. Workflow continues through context compaction automatically
  3. Session boundaries are transparent to the workflow
  4. Only blocks on actual failures (CI, tests, deployment)

Enable via:

bash .spec-flow/scripts/bash/session-manager.sh autopilot on

Or during session start:

bash .spec-flow/scripts/bash/session-manager.sh start --autopilot

Metrics Tracked

  • Session duration
  • Tasks completed per session
  • Decisions made per session
  • Handoffs generated
  • Phase transitions within session

Used for:

  • Workflow optimization
  • Velocity analysis
  • Context usage patterns

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.