Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:48:52 +08:00
commit 6ec3196ecc
434 changed files with 125248 additions and 0 deletions

View File

@@ -0,0 +1,118 @@
# Sequential Thinking Skill
Agent skill for systematic problem-solving through iterative reasoning with revision and branching capabilities.
## What This Skill Does
Enables Claude to break down complex problems into sequential thought steps, revise conclusions when needed, and explore alternative solution paths—all while maintaining context throughout the reasoning process.
## Installation
This skill requires the Sequential Thinking MCP server to be installed and configured in your Claude Desktop or Claude Code environment.
### Step 1: Install MCP Server
Choose one of the following methods:
#### NPX (Recommended)
Add to your `claude_desktop_config.json` or MCP settings:
```json
{
"mcpServers": {
"sequential-thinking": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-sequential-thinking"]
}
}
}
```
#### Docker
```json
{
"mcpServers": {
"sequentialthinking": {
"command": "docker",
"args": ["run", "--rm", "-i", "mcp/sequentialthinking"]
}
}
}
```
### Step 2: Add Skill to Project
Copy this skill folder to your project's `.claude/skills/` directory:
```bash
cp -r sequential-thinking /path/to/your/project/.claude/skills/
```
### Step 3: Verify Installation
Restart Claude and check that the `mcp__reasoning__sequentialthinking` tool is available.
## Usage
Once installed, Claude will automatically use this skill when:
- Facing complex multi-step problems
- Needing to revise earlier conclusions
- Exploring alternative solution approaches
- Working through uncertain or evolving scopes
You can also explicitly request it:
```
"Let's think through this step-by-step using sequential thinking"
```
## Configuration
### Disable Logging (Optional)
To suppress thought information logging, set environment variable:
```json
{
"mcpServers": {
"sequential-thinking": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-sequential-thinking"],
"env": {
"DISABLE_THOUGHT_LOGGING": "true"
}
}
}
}
```
## Skill Structure
```
sequential-thinking/
├── SKILL.md # Main skill definition
├── README.md # This file
└── references/
├── advanced.md # Revision and branching patterns
└── examples.md # Real-world use cases
```
## When Claude Uses This Skill
The skill activates for:
- **Complex analysis**: Breaking down multi-faceted problems
- **Design decisions**: Exploring and comparing alternatives
- **Debugging**: Systematic investigation with course correction
- **Planning**: Multi-stage project planning with evolving scope
- **Architecture**: Evaluating trade-offs across approaches
## Learn More
- [MCP Sequential Thinking Server](https://github.com/modelcontextprotocol/servers/tree/main/src/sequentialthinking)
- [Model Context Protocol](https://modelcontextprotocol.io/)
- [Agent Skills Documentation](https://docs.claude.com/en/docs/agents-and-tools/agent-skills/overview.md)
## License
MIT

View File

@@ -0,0 +1,93 @@
---
name: sequential-thinking
description: Use when complex problems require systematic step-by-step reasoning with ability to revise thoughts, branch into alternative approaches, or dynamically adjust scope. Ideal for multi-stage analysis, design planning, problem decomposition, or tasks with initially unclear scope.
license: MIT
---
# Sequential Thinking
Enables structured problem-solving through iterative reasoning with revision and branching capabilities.
## Core Capabilities
- **Iterative reasoning**: Break complex problems into sequential thought steps
- **Dynamic scope**: Adjust total thought count as understanding evolves
- **Revision tracking**: Reconsider and modify previous conclusions
- **Branch exploration**: Explore alternative reasoning paths from any point
- **Maintained context**: Keep track of reasoning chain throughout analysis
## When to Use
Use `mcp__reasoning__sequentialthinking` when:
- Problem requires multiple interconnected reasoning steps
- Initial scope or approach is uncertain
- Need to filter through complexity to find core issues
- May need to backtrack or revise earlier conclusions
- Want to explore alternative solution paths
**Don't use for**: Simple queries, direct facts, or single-step tasks.
## Basic Usage
The MCP tool `mcp__reasoning__sequentialthinking` accepts these parameters:
### Required Parameters
- `thought` (string): Current reasoning step
- `nextThoughtNeeded` (boolean): Whether more reasoning is needed
- `thoughtNumber` (integer): Current step number (starts at 1)
- `totalThoughts` (integer): Estimated total steps needed
### Optional Parameters
- `isRevision` (boolean): Indicates this revises previous thinking
- `revisesThought` (integer): Which thought number is being reconsidered
- `branchFromThought` (integer): Thought number to branch from
- `branchId` (string): Identifier for this reasoning branch
## Workflow Pattern
```
1. Start with initial thought (thoughtNumber: 1)
2. For each step:
- Express current reasoning in `thought`
- Estimate remaining work via `totalThoughts` (adjust dynamically)
- Set `nextThoughtNeeded: true` to continue
3. When reaching conclusion, set `nextThoughtNeeded: false`
```
## Simple Example
```typescript
// First thought
{
thought: "Problem involves optimizing database queries. Need to identify bottlenecks first.",
thoughtNumber: 1,
totalThoughts: 5,
nextThoughtNeeded: true
}
// Second thought
{
thought: "Analyzing query patterns reveals N+1 problem in user fetches.",
thoughtNumber: 2,
totalThoughts: 6, // Adjusted scope
nextThoughtNeeded: true
}
// ... continue until done
```
## Advanced Features
For revision patterns, branching strategies, and complex workflows, see:
- [Advanced Usage](references/advanced.md) - Revision and branching patterns
- [Examples](references/examples.md) - Real-world use cases
## Tips
- Start with rough estimate for `totalThoughts`, refine as you progress
- Use revision when assumptions prove incorrect
- Branch when multiple approaches seem viable
- Express uncertainty explicitly in thoughts
- Adjust scope freely - accuracy matters less than progress visibility

View File

@@ -0,0 +1,122 @@
# Advanced Usage: Revision and Branching
## Revising Previous Thoughts
When a thought proves incorrect or incomplete, use revision to correct the reasoning chain:
```typescript
{
thought: "Actually, the N+1 problem isn't the bottleneck—profiling shows the issue is missing indexes on join columns.",
thoughtNumber: 5,
totalThoughts: 7,
isRevision: true,
revisesThought: 2, // References thought #2
nextThoughtNeeded: true
}
```
**When to revise**:
- New evidence contradicts earlier conclusions
- Assumptions prove incorrect
- Scope was misunderstood
- Need to correct factual errors
## Branching Into Alternatives
Explore different solution paths by branching from a specific thought:
```typescript
// Main path (thoughts 1-3)
{
thought: "Could optimize with caching or database indexes.",
thoughtNumber: 3,
totalThoughts: 6,
nextThoughtNeeded: true
}
// Branch A: Explore caching
{
thought: "If we implement Redis caching, we'd need to handle cache invalidation.",
thoughtNumber: 4,
totalThoughts: 6,
branchFromThought: 3,
branchId: "caching-approach",
nextThoughtNeeded: true
}
// Branch B: Explore indexing (alternative from thought 3)
{
thought: "Adding composite index would avoid query overhead entirely.",
thoughtNumber: 4,
totalThoughts: 5,
branchFromThought: 3,
branchId: "indexing-approach",
nextThoughtNeeded: true
}
```
**When to branch**:
- Multiple viable approaches exist
- Need to compare trade-offs
- Exploring contingencies
- Testing hypotheses in parallel
## Combining Revision and Branching
```typescript
// Original branch proves problematic
{
thought: "The caching approach has too many edge cases for our timeline.",
thoughtNumber: 6,
totalThoughts: 8,
branchId: "caching-approach",
isRevision: true,
revisesThought: 4,
nextThoughtNeeded: true
}
// Return to indexing branch
{
thought: "Returning to index optimization—this approach is more reliable.",
thoughtNumber: 7,
totalThoughts: 9,
branchId: "indexing-approach",
nextThoughtNeeded: true
}
```
## Dynamic Scope Adjustment
Freely adjust `totalThoughts` as understanding evolves:
```typescript
// Initial estimate
{ thoughtNumber: 1, totalThoughts: 5, ... }
// Complexity increases
{ thoughtNumber: 3, totalThoughts: 8, ... }
// Actually simpler than expected
{ thoughtNumber: 5, totalThoughts: 6, ... }
```
**Purpose**: Provide progress visibility, not strict planning. The estimate guides pacing but should adapt to reality.
## Session Management
Each reasoning session maintains its own context. The tool tracks:
- All thoughts in sequence
- Revision relationships
- Branch hierarchies
- Current state
You don't need to manually manage state—focus on expressing reasoning clearly.
## Best Practices
1. **Express uncertainty**: "This might be...", "Uncertain if...", "Need to verify..."
2. **Show reasoning**: Not just conclusions, but how you arrived there
3. **Revise freely**: Correcting course is expected and valuable
4. **Branch decisively**: When exploring alternatives, commit to exploring each fully
5. **Adjust scope**: Don't lock into initial estimates
6. **Maintain clarity**: Each thought should be self-contained enough to understand in isolation

View File

@@ -0,0 +1,274 @@
# Sequential Thinking Examples
## Example 1: Database Performance Problem
**Context**: API endpoints timing out, need to diagnose and fix.
```typescript
// Thought 1
{
thought: "API timeout reports indicate database bottleneck. Need to profile queries first.",
thoughtNumber: 1,
totalThoughts: 6,
nextThoughtNeeded: true
}
// Thought 2
{
thought: "Query logs show user profile endpoint makes 50+ queries per request. Classic N+1 pattern.",
thoughtNumber: 2,
totalThoughts: 6,
nextThoughtNeeded: true
}
// Thought 3
{
thought: "Need to implement eager loading for relationships. Checking ORM documentation for optimal approach.",
thoughtNumber: 3,
totalThoughts: 7, // Adjusted scope
nextThoughtNeeded: true
}
// Thought 4
{
thought: "ORM supports `include` for eager loading. Will need to modify 3 endpoints: /profile, /dashboard, /settings.",
thoughtNumber: 4,
totalThoughts: 7,
nextThoughtNeeded: true
}
// Thought 5
{
thought: "Implementation complete. Testing shows queries reduced from 52 to 4 per request. Response time: 2.1s → 180ms.",
thoughtNumber: 5,
totalThoughts: 6, // Fewer steps than expected
nextThoughtNeeded: true
}
// Thought 6
{
thought: "Success. Solution: eager loading eliminated N+1 queries. Next: add query monitoring to catch similar issues early.",
thoughtNumber: 6,
totalThoughts: 6,
nextThoughtNeeded: false // Done
}
```
## Example 2: Architecture Decision with Branching
**Context**: Choosing between microservices and monolith for new project.
```typescript
// Thought 1
{
thought: "Need to decide architecture. Key factors: team size (5 devs), timeline (3 months), expected scale (10k users initially).",
thoughtNumber: 1,
totalThoughts: 8,
nextThoughtNeeded: true
}
// Thought 2
{
thought: "Two viable approaches: monolith for simplicity or microservices for scalability. Need to evaluate both.",
thoughtNumber: 2,
totalThoughts: 10,
nextThoughtNeeded: true
}
// Branch A: Monolith approach
{
thought: "Monolith pros: faster development, simpler deployment, easier debugging. Cons: potential future refactor cost.",
thoughtNumber: 3,
totalThoughts: 6,
branchFromThought: 2,
branchId: "monolith",
nextThoughtNeeded: true
}
{
thought: "For 10k users, single server handles load easily. Deployment: single container, straightforward CI/CD.",
thoughtNumber: 4,
totalThoughts: 6,
branchId: "monolith",
nextThoughtNeeded: true
}
{
thought: "Dev velocity high—team can ship in 3 months. Future scaling: can extract services later if needed.",
thoughtNumber: 5,
totalThoughts: 6,
branchId: "monolith",
nextThoughtNeeded: true
}
// Branch B: Microservices approach
{
thought: "Microservices pros: independent scaling, service isolation. Cons: complexity overhead, distributed systems challenges.",
thoughtNumber: 3,
totalThoughts: 7,
branchFromThought: 2,
branchId: "microservices",
nextThoughtNeeded: true
}
{
thought: "For 5-person team: significant overhead in service coordination, API contracts, infrastructure management.",
thoughtNumber: 4,
totalThoughts: 7,
branchId: "microservices",
nextThoughtNeeded: true
}
{
thought: "Timeline risk: 3 months insufficient for robust microservices implementation. Need distributed tracing, service mesh, etc.",
thoughtNumber: 5,
totalThoughts: 7,
branchId: "microservices",
nextThoughtNeeded: true
}
// Convergence
{
thought: "Comparing branches: monolith clearly better fit. Small team, tight timeline, modest initial scale. Microservices overhead unjustified.",
thoughtNumber: 6,
totalThoughts: 7,
nextThoughtNeeded: true
}
{
thought: "Decision: monolith with modular design. Extract services later if specific components need independent scaling.",
thoughtNumber: 7,
totalThoughts: 7,
nextThoughtNeeded: false
}
```
## Example 3: Debugging with Revision
**Context**: Feature works in dev, fails in production.
```typescript
// Thought 1
{
thought: "Payment processing works locally but fails in prod. Checking error logs.",
thoughtNumber: 1,
totalThoughts: 5,
nextThoughtNeeded: true
}
// Thought 2
{
thought: "Logs show 'Connection refused' to payment API. Likely firewall or network config issue.",
thoughtNumber: 2,
totalThoughts: 5,
nextThoughtNeeded: true
}
// Thought 3
{
thought: "Checked firewall rules—payment API port (443) is open. Must be something else.",
thoughtNumber: 3,
totalThoughts: 6,
nextThoughtNeeded: true
}
// Thought 4 - Revision
{
thought: "Wait—reviewing logs more carefully. Error message includes 'certificate verify failed'. Not firewall, it's SSL/TLS issue.",
thoughtNumber: 4,
totalThoughts: 6,
isRevision: true,
revisesThought: 2,
nextThoughtNeeded: true
}
// Thought 5
{
thought: "Prod environment missing intermediate CA certificates. Dev works because it uses self-signed cert with verification disabled.",
thoughtNumber: 5,
totalThoughts: 6,
nextThoughtNeeded: true
}
// Thought 6
{
thought: "Installed CA bundle on prod server. Payment processing now works. Root cause: incomplete SSL cert chain.",
thoughtNumber: 6,
totalThoughts: 6,
nextThoughtNeeded: false
}
```
## Example 4: Complex Feature Planning
**Context**: Building real-time collaborative editing feature.
```typescript
// Thought 1
{
thought: "Real-time collab editing requires: WebSocket connections, operational transformation or CRDT, conflict resolution, presence tracking.",
thoughtNumber: 1,
totalThoughts: 12,
nextThoughtNeeded: true
}
// Thought 2
{
thought: "Core decision: OT vs CRDT. OT requires central server for transform logic, CRDT enables P2P. For our use case, CRDT better.",
thoughtNumber: 2,
totalThoughts: 12,
nextThoughtNeeded: true
}
// Thought 3
{
thought: "Research CRDT libraries: Yjs (popular, mature), Automerge (good TypeScript support). Yjs has better performance benchmarks.",
thoughtNumber: 3,
totalThoughts: 14, // Scope expanding
nextThoughtNeeded: true
}
// Thought 4
{
thought: "Architecture: Yjs + WebSocket provider + persistence layer. Client-side: Yjs doc syncs via WebSocket. Server: broadcast updates + store snapshots.",
thoughtNumber: 4,
totalThoughts: 14,
nextThoughtNeeded: true
}
// Thought 5
{
thought: "Implementation phases: (1) Basic sync, (2) Presence/cursors, (3) Persistence, (4) Conflict UI. Estimate 4 weeks total.",
thoughtNumber: 5,
totalThoughts: 14,
nextThoughtNeeded: true
}
// ... continues through implementation details
// Final thought
{
thought: "Plan complete. MVP: Yjs + WebSocket + Redis persistence. 4-week timeline. Main risk: scaling WebSocket connections—mitigate with load balancer sticky sessions.",
thoughtNumber: 14,
totalThoughts: 14,
nextThoughtNeeded: false
}
```
## Usage Patterns Summary
| Scenario | Pattern | Key Features |
|----------|---------|--------------|
| Linear problem-solving | Sequential thoughts | Steady progress, scope adjustment |
| Exploring alternatives | Branching | Multiple paths from decision point |
| Correcting mistakes | Revision | Reference earlier thought, update conclusion |
| Complex analysis | Mixed | Combine all features as needed |
## Tips for Effective Use
1. **Start broad, narrow down**: Early thoughts explore problem space, later thoughts dive into specifics
2. **Show your work**: Document reasoning process, not just conclusions
3. **Revise when wrong**: Don't continue down incorrect path—backtrack and correct
4. **Branch at crossroads**: When facing clear alternatives, explore each systematically
5. **Adjust dynamically**: Change `totalThoughts` as understanding evolves
6. **End decisively**: Final thought should summarize conclusion and next actions