mcpField
L
long-agent

long-agent

github.com/johnlindquistAgent 工作流2644 次安装45 周前更新
代码仓库

关于 long-agent

long-agent 通过会话日志、检查点和上下文笔记,帮助开发者管理较长的 Agent 会话。它适用于跨多个会话或数日的任务,可记录进度、恢复上下文并准备交接。

主要功能

  1. 01会话日志与进度跟踪
  2. 02检查点与里程碑清单
  3. 03保存并恢复上下文
  4. 04任务状态与进度摘要
  5. 05会话交接文档

适用场景

  1. 01恢复长期编码任务
  2. 02跨会话跟踪里程碑
  3. 03将进行中的任务交给后续会话

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/johnlindquist/claude --skill long-agent

安装后在 Claude Code 中输入/long-agent确认已加载。

详细介绍

长 Agent 会话

通过进度跟踪和上下文管理来管理长时间运行的 Agent 会话。

会话管理

初始化会话
# Create session file
SESSION_ID=$(date +%Y%m%d-%H%M%S)
SESSION_FILE=~/.claude/sessions/$SESSION_ID.md

mkdir -p ~/.claude/sessions

cat > $SESSION_FILE << EOF
# Session: $SESSION_ID
Started: $(date)
Task: [Describe task]

## Progress
- [ ] Step 1
- [ ] Step 2
- [ ] Step 3

## Context
[Important context to remember]

## Notes
[Running notes]
EOF

echo "Session: $SESSION_FILE"
跟踪进度
# Update progress
echo "- [x] Completed: [description]" >> $SESSION_FILE

# Add note
echo "### $(date +%H:%M) - [title]" >> $SESSION_FILE
echo "[notes]" >> $SESSION_FILE
恢复会话
# List recent sessions
ls -lt ~/.claude/sessions/ | head -10

# View session
cat ~/.claude/sessions/SESSION_ID.md

# Continue from last checkpoint
tail -50 ~/.claude/sessions/SESSION_ID.md

进度模式

检查点系统
#!/bin/bash
# checkpoint.sh SESSION_ID DESCRIPTION

SESSION_FILE=~/.claude/sessions/$1.md
CHECKPOINT=$2

echo "" >> $SESSION_FILE
echo "## Checkpoint: $(date +%H:%M)" >> $SESSION_FILE
echo "Status: $CHECKPOINT" >> $SESSION_FILE
echo "Can resume from here." >> $SESSION_FILE
里程碑跟踪
# Session Progress

## Milestones
- [x] M1: Environment setup
- [x] M2: Core implementation
- [ ] M3: Testing
- [ ] M4: Documentation

## Current: M3 - Testing

### Completed
- Unit tests for auth module
- Integration test setup

### In Progress
- API endpoint tests

### Blocked
- Need test fixtures for edge cases

上下文管理

保存重要上下文
#!/bin/bash
# save-context.sh SESSION_ID

SESSION_FILE=~/.claude/sessions/$1.md

cat >> $SESSION_FILE << 'CONTEXT'

## Critical Context (Don't Lose)

### File Locations
- Main entry: src/index.ts
- Config: src/config.ts
- Tests: tests/

### Key Decisions
- Using JWT for auth (not sessions)
- PostgreSQL for persistence
- Redis for caching

### Current State
- Auth module: complete
- API routes: 80% done
- Tests: 40% coverage
CONTEXT
上下文恢复
# Get context for resumption
CONTEXT=$(grep -A 50 "## Critical Context" ~/.claude/sessions/$SESSION_ID.md)

gemini -m pro -o text -e "" "I'm resuming a long coding session. Here's the context:

$CONTEXT

Help me remember:
1. Where was I?
2. What's the next step?
3. Any gotchas to remember?"

方位检查

确定你的方位
#!/bin/bash
# bearings.sh - Where am I in this task?

echo "=== Current Session Status ==="
echo ""

# Git status
echo "### Git Status"
git status --short

echo ""
echo "### Recent Commits"
git log --oneline -5

echo ""
echo "### Modified Files"
git diff --stat HEAD~3

echo ""
echo "### TODO Items"
grep -r "TODO\|FIXME" src/ --include="*.ts" | head -10
进度摘要
# Generate progress summary
gemini -m pro -o text -e "" "Summarize progress on this session:

Session log:
$(tail -100 ~/.claude/sessions/$SESSION_ID.md)

Git activity:
$(git log --oneline -10)

Provide:
1. What's been accomplished
2. Current status
3. Remaining work
4. Estimated completion"

长任务模式

多日任务
# Multi-Day Task: [Name]

## Day 1 - [Date]
### Accomplished
- [items]

### Blocked
- [items]

### Tomorrow
- [items]

---

## Day 2 - [Date]
### Context from Yesterday
[summary]

### Accomplished
- [items]
交接文档

当交接给另一个会话或 Agent 时:

# Task Handoff

## What This Is
[Brief description]

## Current State
- [Bullet points of where things stand]

## What's Working
- [Completed items]

## What's Not Working
- [Issues/blockers]

## Next Steps
1. [Specific step]
2. [Specific step]

## Key Files
- `src/main.ts` - Entry point
- `src/auth/` - Auth module (done)
- `src/api/` - API routes (in progress)

## Commands to Know
```bash
npm run dev    # Start development
npm test       # Run tests
npm run build  # Build for production

注意事项

  • [可能让你出错的地方]

## Session Templates

### Feature Development

```bash
cat > ~/.claude/sessions/feature-template.md << 'EOF'
# Feature: [Name]

## Requirements
- [ ] Requirement 1
- [ ] Requirement 2

## Design
[Architecture notes]

## Implementation Progress
- [ ] Step 1
- [ ] Step 2
- [ ] Step 3

## Testing
- [ ] Unit tests
- [ ] Integration tests
- [ ] Manual testing

## Documentation
- [ ] Code comments
- [ ] README update
- [ ] API docs
EOF
缺陷修复
cat > ~/.claude/sessions/bugfix-template.md << 'EOF'
# Bug Fix: [Issue ID/Description]

## Symptom
[What's happening]

## Expected
[What should happen]

## Investigation
- [ ] Reproduced locally
- [ ] Found root cause
- [ ] Identified fix

## Fix
[Description of fix]

## Verification
- [ ] Fix works
- [ ] No regressions
- [ ] Tests added
EOF

最佳实践

  1. 频繁记录 - 经常更新进度
  2. 保存上下文 - 恢复时需要什么?
  3. 创建检查点 - 标记安全的恢复点
  4. 休息前总结 - 记录当前思路状态
  5. 使用模板 - 一致的结构有帮助
  6. 跟踪阻塞项 - 记录正在等待什么
  7. 干净交接 - 假设下次是全新的上下文

评论

支持 Markdown