AgentSkillsCN

context-keeper

跨领域技能——在整个工作流程中管理会话状态。在会话开始时、每次提交之后、决策作出后,以及在Git(结束时)触发。通过会话账本与研究缓存,持续优化上下文环境。

SKILL.md
--- frontmatter
name: context-keeper
description: >
  TRANSVERSAL SKILL - Manages session state throughout the entire workflow.
  Invoked at START, after each commit, after decisions, and at GIT (end).
  Maintains session ledger and research cache for context optimization.

Context Keeper (Transversal)

Role: Maintain session state and optimize context across the entire workflow.

This is NOT a phase-specific skill. It runs at multiple points during the workflow.

When to Invoke

TriggerAction
START phaseInitialize session ledger
After each commitUpdate progress
After important decisionsRecord decision
After review attemptRecord attempt + feedback
GIT phase (end)Finalize session
Before external researchCheck research cache
After external researchUpdate research cache

Session Ledger

Purpose

  1. Traceability - Record what happened during the session
  2. Context optimization - Quick reference without re-reading all code
  3. Recovery - If session interrupted, resume from ledger state
  4. Review tracking - Track attempts and feedback

Location

code
.claude/ledger/sessions/{TICKET-ID}.md

Initialize (START phase)

Create from template:

bash
cp .claude/ledger/sessions/_TEMPLATE.md .claude/ledger/sessions/TTV-XXX.md

Fill initial data:

markdown
# Session: TTV-XXX

## Ticket
**ID:** TTV-XXX
**Title:** {from Jira}
**Type:** Feature / Fix / Task

## Status
phase: start
blocked: false
review_attempts: 0/3

## Timeline
- {timestamp} Session initialized
- {timestamp} Branch created: feat/TTV-XXX

## Technologies
- Prisma 7
- NestJS 11
- {others identified}

## Decisions
{empty initially}

## Files Changed
{empty initially}

## Notes
{empty initially}

Update After Commit

After each commit checkpoint:

markdown
## Timeline
- {timestamp} Session initialized
- {timestamp} Branch created: feat/TTV-XXX
- {timestamp} Entity created: Event.entity.ts
- {timestamp} Commit: feat(events): [TTV-XXX] add Event entity

## Files Changed
- src/modules/events/domain/entities/event.entity.ts (created)
- src/modules/events/domain/value-objects/event-status.vo.ts (created)

Update After Decision

When a technical decision is made:

markdown
## Decisions
- Used UUID for entity ID (consistent with other entities)
- Placed validation in factory method, not constructor
- Used AppException.businessRule for date validation

Update After Review Attempt

markdown
## Status
phase: review-rejected
review_attempts: 2/3

## Review History
### Attempt 1
**Result:** Rejected
**Issues:**
- Missing Mapper class
- Inline mapping in repository

### Attempt 2
**Result:** Rejected
**Issues:**
- Mapper created but not used in one method

Finalize (GIT phase)

markdown
## Status
phase: completed
review_attempts: 1/3

## Timeline
- {timestamp} Session initialized
- {timestamp} Branch created
- ...
- {timestamp} Review passed
- {timestamp} PR created: #42
- {timestamp} Session finalized

## Summary
Implemented Event entity with CQRS pattern. Created CreateEventCommand
with full validation. Repository uses dedicated EventMapper.

## PR
https://github.com/user/repo/pull/42

Research Cache

Purpose

Avoid repeated Context7 queries. Store findings locally.

Location

code
.claude/ledger/research/{technology}.md

Check Before Research

Before invoking skill:research-external:

bash
# Check if cache exists
cat .claude/ledger/research/prisma.md

# If exists, check if sufficient for current need
# If not exists or outdated → proceed with research

Cache Structure

markdown
# {Technology} Research Cache

**Version:** 7.x
**Updated:** 2026-02-03
**Source:** Context7 MCP

## Key APIs

### Schema Definition
```typescript
model User {
  id String @id @default(uuid())
  // ... example from docs
}

Notes:

  • Use @db.Uuid for PostgreSQL UUID
  • @map for snake_case in DB

Client Usage

typescript
const user = await prisma.user.create({
  data: { ... }
});

Gotchas

  1. Prisma 7 requires output in generator
  2. Migrations need prisma migrate dev not deploy locally

Integration with NestJS

  • PrismaService extends PrismaClient
  • Use onModuleInit for connection
code

## Update Rules

### Session Ledger
- **State only** - No code snippets (reference files instead)
- **Max ~50 lines** - Keep it scannable
- **Overwrite sections** - Don't append infinitely
- **Update, don't duplicate** - Modify existing entries

### Research Cache
- **Facts only** - No implementation details
- **Include version** - APIs change between versions
- **Include gotchas** - Save debugging time
- **Include examples** - Copy-paste ready

## Quick Reference

### Initialize Session
```bash
# Create session file
cp .claude/ledger/sessions/_TEMPLATE.md .claude/ledger/sessions/TTV-XXX.md

# Edit with initial data
# Set phase: start
# Add ticket info

Update Progress

bash
# After commit, update:
# - Timeline section (add entry)
# - Files Changed section (add/update)
# - Status phase if changed

Check Research

bash
# Before Context7 query
ls .claude/ledger/research/
cat .claude/ledger/research/{tech}.md

# Decide: use cache or research fresh

Finalize

bash
# At end:
# - Status phase: completed
# - Add PR link
# - Add summary