一键导入
moai-alfred-session-state
Session state management, runtime state tracking, session handoff protocols, and context continuity for Alfred workflows
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Session state management, runtime state tracking, session handoff protocols, and context continuity for Alfred workflows
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
19-agent team structure, decision trees for agent selection, Haiku vs Sonnet model selection, and agent collaboration principles. Use when deciding which sub-agent to invoke, understanding team responsibilities, or learning multi-agent orchestration.
Guide Alfred sub-agents to actively invoke AskUserQuestion for ambiguous decisions.
Master-Clone pattern implementation guide for complex multi-step tasks with full project context
Systematic code review guidance and automation. Apply TRUST 5 principles, check code quality, validate SOLID principles, identify security issues, and ensure maintainability. Use when conducting code reviews, setting review standards, or implementing review automation.
.moai/config.json official schema documentation, structure validation, project metadata, language settings, and configuration migration guide. Use when setting up project configuration or understanding config.json structure.
Claude Code context window optimization strategies, JIT retrieval, progressive loading, memory file patterns, and cleanup practices. Use when optimizing context usage, managing large projects, or implementing efficient workflows.
| name | moai-alfred-session-state |
| version | 1.1.0 |
| created | "2025-11-05T00:00:00.000Z" |
| updated | "2025-11-05T00:00:00.000Z" |
| status | active |
| description | Session state management, runtime state tracking, session handoff protocols, and context continuity for Alfred workflows |
| keywords | ["session","state","handoff","context","continuity","tracking"] |
| allowed-tools | ["Read","Bash","TodoWrite"] |
| Field | Value |
|---|---|
| Skill Name | moai-alfred-session-state |
| Version | 1.1.0 (2025-11-05) |
| Status | Active |
| Tier | Alfred |
| Purpose | Manage session state and ensure context continuity |
Provides comprehensive session state management, runtime tracking, and handoff protocols to maintain context continuity across Alfred workflows and session boundaries.
Key capabilities:
Automatic triggers:
Manual reference:
Session State Stack:
├── L1: Active Context (current task, variables, scope)
├── L2: Session History (recent actions, decisions, outcomes)
├── L3: Project State (SPEC progress, milestones, blockers)
├── L4: User Context (preferences, expertise level, language)
└── L5: System State (tool availability, permissions, environment)
Active State (session-state.json):
{
"session_id": "uuid-v4",
"user_id": "user-context",
"current_task": {
"type": "alfred_command",
"command": "/alfred:2-run",
"spec_id": "SPEC-001",
"status": "in_progress",
"start_time": "2025-11-05T15:30:00Z"
},
"context_stack": [...],
"memory_refs": [...],
"agent_chain": [...]
}
Task Lifecycle States:
pending - Queued but not startedin_progress - Currently executingblocked - Waiting for dependenciescompleted - Finished successfullyfailed - Error occurredcancelled - User requested stopState Transition Rules:
def update_task_state(task_id, new_state, context):
"""Update task state with validation"""
# Validate transition
if not is_valid_transition(current_state, new_state):
raise InvalidStateTransition(f"Cannot transition from {current_state} to {new_state}")
# Update task
task = get_task(task_id)
task.state = new_state
task.updated_at = timestamp()
task.state_history.append({
'from': current_state,
'to': new_state,
'timestamp': task.updated_at,
'context': context
})
# Trigger side effects
trigger_state_change_hooks(task, context)
Context Preservation Rules:
Critical Context - Always preserve across handoffs
Secondary Context - Preserve when space allows
Temporary Context - Discard when not needed
Handoff Package Structure:
{
"handoff_id": "uuid-v4",
"from_agent": "spec-builder",
"to_agent": "tdd-implementer",
"timestamp": "2025-11-05T15:30:00Z",
"session_context": {
"user_language": "ko",
"expertise_level": "intermediate",
"current_project": "MoAI-ADK",
"active_spec": "SPEC-001"
},
"task_context": {
"current_phase": "implementation",
"completed_steps": ["spec_complete", "architecture_defined"],
"next_step": "write_tests",
"constraints": ["must_use_pytest", "coverage_85"]
},
"state_snapshot": {...}
}
Handoff Validation:
def validate_handoff(handoff_package):
"""Ensure handoff contains required context"""
required_fields = [
'handoff_id', 'from_agent', 'to_agent',
'session_context', 'task_context'
]
for field in required_fields:
if field not in handoff_package:
raise HandoffError(f"Missing required field: {field}")
# Validate agent compatibility
if not can_agents_cooperate(handoff_package.from_agent, handoff_package.to_agent):
raise AgentCompatibilityError("Agents cannot cooperate")
return True
Recovery Checkpoints:
Recovery Process:
Memory File States:
session-summary.md - Current session overviewactive-tasks.md - TodoWrite task trackingcontext-cache.json - Cached context for performanceagent-notes.md - Agent-specific observationsSynchronization Protocol:
def sync_memory_files(session_state):
"""Ensure memory files reflect current session state"""
# Update session summary
update_session_summary(session_state)
# Sync TodoWrite tasks
sync_todowrite_tasks(session_state.active_tasks)
# Update context cache
update_context_cache(session_state.context_stack)
# Archive old context
archive_old_context(session_state.context_history)
✅ DO:
❌ DON'T:
Session State Viewer:
# View current session state
/alfred:debug --show-session-state
# Check context stack
/alfred:debug --show-context-stack
# Validate memory file consistency
/alfred:debug --check-memory-sync
Common Issues and Solutions:
| Issue | Symptoms | Solution |
|---|---|---|
| Lost context on handoff | Agent asks redundant questions | Verify handoff package completeness |
| Memory file drift | Inconsistent information across files | Run memory synchronization |
| State corruption | Tasks show wrong status | Restore from last checkpoint |
| Context overflow | Session performance degradation | Archive old context and clean memory |
Optimization Strategies:
Monitoring Metrics:
Learn more in reference.md for detailed implementation guides, recovery procedures, and advanced coordination patterns.
Related Skills:
moai-alfred-context-budget - Context optimization strategiesmoai-alfred-agent-guide - Multi-agent coordinationmoai-alfred-workflow - Session workflow managementmoai-foundation-trust - State validation principles