mirror of
https://github.com/cexll/myclaude.git
synced 2026-02-05 02:30:26 +08:00
remove docs
This commit is contained in:
@@ -1,502 +0,0 @@
|
||||
# System Architecture
|
||||
|
||||
## Overview
|
||||
|
||||
Multi-agent AI development system with Claude Code as orchestrator and pluggable execution backends.
|
||||
|
||||
## High-Level Architecture
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ User │
|
||||
└──────────────────┬──────────────────────────────────────────┘
|
||||
│
|
||||
│ /dev, /gh-implement, etc.
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ Claude Code (Orchestrator) │
|
||||
│ ┌─────────────────────────────────────────────────────────┐│
|
||||
│ │ - Planning & context gathering ││
|
||||
│ │ - Requirements clarification ││
|
||||
│ │ - Task breakdown ││
|
||||
│ │ - Verification & reporting ││
|
||||
│ └─────────────────────────────────────────────────────────┘│
|
||||
└──────────────────┬──────────────────────────────────────────┘
|
||||
│
|
||||
│ via codeagent-wrapper
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ Codeagent-Wrapper (Execution Layer) │
|
||||
│ ┌──────────────────────────────────────────────────────────┤
|
||||
│ │ Backend Interface │
|
||||
│ ├──────────────┬──────────────┬──────────────┐ │
|
||||
│ │ Codex │ Claude │ Gemini │ │
|
||||
│ │ Backend │ Backend │ Backend │ │
|
||||
│ └──────────────┴──────────────┴──────────────┘ │
|
||||
│ │
|
||||
│ ┌──────────────────────────────────────────────────────────┤
|
||||
│ │ Features: │
|
||||
│ │ - Multi-backend execution │
|
||||
│ │ - JSON stream parsing │
|
||||
│ │ - Session management │
|
||||
│ │ - Parallel task execution │
|
||||
│ │ - Timeout handling │
|
||||
│ └──────────────────────────────────────────────────────────┘
|
||||
└──────────────────┬──────────────────────────────────────────┘
|
||||
│
|
||||
│ CLI invocations
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ AI CLI Backends │
|
||||
│ ┌──────────────┬──────────────┬──────────────┐ │
|
||||
│ │ Codex CLI │ Claude CLI │ Gemini CLI │ │
|
||||
│ │ │ │ │ │
|
||||
│ │ Code editing │ Reasoning │ Fast proto │ │
|
||||
│ └──────────────┴──────────────┴──────────────┘ │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## Component Architecture
|
||||
|
||||
### 1. Orchestrator Layer (Claude Code)
|
||||
|
||||
**Responsibilities:**
|
||||
- User interaction and requirements gathering
|
||||
- Context analysis and exploration
|
||||
- Task planning and breakdown
|
||||
- Workflow coordination
|
||||
- Verification and reporting
|
||||
|
||||
**Key Workflows:**
|
||||
```
|
||||
/dev
|
||||
├── Requirements clarification (AskUserQuestion)
|
||||
├── Codex analysis (Task tool → Explore agent)
|
||||
├── Dev plan generation (Task tool → dev-plan-generator)
|
||||
├── Parallel execution (codeagent-wrapper --parallel)
|
||||
├── Coverage validation (≥90%)
|
||||
└── Completion summary
|
||||
|
||||
/gh-implement <issue>
|
||||
├── Issue analysis (gh issue view)
|
||||
├── Clarification (if needed)
|
||||
├── Development (codeagent-wrapper or /dev)
|
||||
├── Progress updates (gh issue comment)
|
||||
└── PR creation (gh pr create)
|
||||
```
|
||||
|
||||
### 2. Execution Layer (Codeagent-Wrapper)
|
||||
|
||||
**Architecture:**
|
||||
|
||||
```go
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ Main Entry Point │
|
||||
│ - Parse CLI arguments │
|
||||
│ - Detect mode (new/resume/parallel) │
|
||||
│ - Select backend │
|
||||
└──────────────────┬──────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ Backend Selection │
|
||||
│ func SelectBackend(name string) Backend │
|
||||
│ ┌──────────────┬──────────────┬──────────────┐ │
|
||||
│ │ CodexBackend │ ClaudeBackend│ GeminiBackend│ │
|
||||
│ └──────────────┴──────────────┴──────────────┘ │
|
||||
└──────────────────┬──────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ Executor │
|
||||
│ func RunCodexTask(cfg *Config) (string, error) │
|
||||
│ ┌──────────────────────────────────────────────────────┤
|
||||
│ │ 1. Build command args via Backend.BuildArgs() │
|
||||
│ │ 2. Start process with timeout │
|
||||
│ │ 3. Stream stdout/stderr │
|
||||
│ │ 4. Parse JSON stream via ParseJSONStream() │
|
||||
│ │ 5. Extract session ID │
|
||||
│ │ 6. Handle signals (SIGINT, SIGTERM) │
|
||||
│ └──────────────────────────────────────────────────────┘
|
||||
└──────────────────┬──────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ Parser │
|
||||
│ func ParseJSONStream(r io.Reader) (string, string) │
|
||||
│ ┌──────────────────────────────────────────────────────┤
|
||||
│ │ Detects format: │
|
||||
│ │ - Codex: {"type":"thread.started","thread_id":...} │
|
||||
│ │ - Claude: {"type":"...","subtype":"result"} │
|
||||
│ │ - Gemini: {"type":"...","role":"assistant"} │
|
||||
│ │ │
|
||||
│ │ Extracts: │
|
||||
│ │ - Agent messages │
|
||||
│ │ - Session IDs │
|
||||
│ └──────────────────────────────────────────────────────┘
|
||||
└─────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
**Backend Interface:**
|
||||
|
||||
```go
|
||||
type Backend interface {
|
||||
Name() string
|
||||
Command() string
|
||||
BuildArgs(cfg *Config, targetArg string) []string
|
||||
}
|
||||
|
||||
// Codex: codex e --skip-git-repo-check -C <workdir> --json <task>
|
||||
// Claude: claude -p --dangerously-skip-permissions --output-format stream-json --verbose <task>
|
||||
// Gemini: gemini -o stream-json -y -p <task>
|
||||
```
|
||||
|
||||
**Key Files:**
|
||||
- `main.go` - Entry point and orchestration
|
||||
- `config.go` - CLI argument parsing
|
||||
- `backend.go` - Backend interface and implementations
|
||||
- `executor.go` - Process execution and stream handling
|
||||
- `parser.go` - JSON stream parsing (multi-format)
|
||||
- `logger.go` - Async logging with ring buffer
|
||||
- `utils.go` - Helper functions
|
||||
|
||||
### 3. Hooks System
|
||||
|
||||
**Architecture:**
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ Claude Code Events │
|
||||
│ UserPromptSubmit │ PostToolUse │ Stop │
|
||||
└──────────────────┬──────────────────────────────────────┘
|
||||
│
|
||||
│ reads
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ .claude/settings.json │
|
||||
│ { │
|
||||
│ "hooks": { │
|
||||
│ "UserPromptSubmit": [ │
|
||||
│ { │
|
||||
│ "hooks": [ │
|
||||
│ { │
|
||||
│ "type": "command", │
|
||||
│ "command": "$CLAUDE_PROJECT_DIR/hooks/..." │
|
||||
│ } │
|
||||
│ ] │
|
||||
│ } │
|
||||
│ ] │
|
||||
│ } │
|
||||
│ } │
|
||||
└──────────────────┬──────────────────────────────────────┘
|
||||
│
|
||||
│ executes
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ Hook Scripts │
|
||||
│ ┌────────────────────────────────────────────────────┐ │
|
||||
│ │ skill-activation-prompt.sh │ │
|
||||
│ │ - Reads skills/skill-rules.json │ │
|
||||
│ │ - Matches user prompt against triggers │ │
|
||||
│ │ - Injects skill suggestions │ │
|
||||
│ └────────────────────────────────────────────────────┘ │
|
||||
│ ┌────────────────────────────────────────────────────┐ │
|
||||
│ │ pre-commit.sh │ │
|
||||
│ │ - Validates staged files │ │
|
||||
│ │ - Runs tests │ │
|
||||
│ │ - Formats code │ │
|
||||
│ └────────────────────────────────────────────────────┘ │
|
||||
└─────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 4. Skills System
|
||||
|
||||
**Structure:**
|
||||
|
||||
```
|
||||
skills/
|
||||
├── codex/
|
||||
│ └── SKILL.md # Codex CLI integration
|
||||
├── codeagent/
|
||||
│ └── SKILL.md # Multi-backend wrapper
|
||||
├── gemini/
|
||||
│ └── SKILL.md # Gemini CLI integration
|
||||
└── skill-rules.json # Auto-activation rules
|
||||
```
|
||||
|
||||
**skill-rules.json Format:**
|
||||
|
||||
```json
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"trigger": {
|
||||
"pattern": "implement|build|create feature",
|
||||
"type": "regex"
|
||||
},
|
||||
"skill": "codeagent",
|
||||
"priority": 1,
|
||||
"suggestion": "Use codeagent skill for code implementation"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Data Flow
|
||||
|
||||
### Example: /dev Workflow
|
||||
|
||||
```
|
||||
1. User: /dev "add user authentication"
|
||||
│
|
||||
▼
|
||||
2. Claude Code:
|
||||
│ ├─ Clarifies requirements (AskUserQuestion)
|
||||
│ ├─ Analyzes codebase (Explore agent)
|
||||
│ └─ Generates dev-plan.md
|
||||
│
|
||||
▼
|
||||
3. Claude Code invokes: codeagent-wrapper --parallel <<EOF
|
||||
---TASK---
|
||||
id: auth_backend_1701234567
|
||||
workdir: /project/backend
|
||||
---CONTENT---
|
||||
implement JWT authentication in @src/auth
|
||||
|
||||
---TASK---
|
||||
id: auth_frontend_1701234568
|
||||
workdir: /project/frontend
|
||||
dependencies: auth_backend_1701234567
|
||||
---CONTENT---
|
||||
implement login form consuming /api/auth
|
||||
|
||||
---TASK---
|
||||
id: auth_tests_1701234569
|
||||
workdir: /project
|
||||
dependencies: auth_backend_1701234567, auth_frontend_1701234568
|
||||
---CONTENT---
|
||||
add integration tests for auth flow
|
||||
EOF
|
||||
│
|
||||
▼
|
||||
4. Codeagent-Wrapper:
|
||||
│ ├─ Parses parallel config
|
||||
│ ├─ Topological sort (resolves dependencies)
|
||||
│ ├─ Executes tasks concurrently:
|
||||
│ │ ├─ Task 1: codex e --json "implement JWT..."
|
||||
│ │ ├─ Task 2: waits for Task 1, then codex e --json "implement login..."
|
||||
│ │ └─ Task 3: waits for Tasks 1&2, then codex e --json "add tests..."
|
||||
│ └─ Aggregates results
|
||||
│
|
||||
▼
|
||||
5. Claude Code:
|
||||
│ ├─ Validates coverage (≥90%)
|
||||
│ ├─ Runs final tests
|
||||
│ └─ Reports summary
|
||||
│
|
||||
▼
|
||||
6. User receives:
|
||||
✅ Authentication implemented
|
||||
📊 Coverage: 92%
|
||||
📁 Files modified: 8
|
||||
🧪 Tests: 24 passed
|
||||
```
|
||||
|
||||
## Module System
|
||||
|
||||
Installation system uses modular architecture:
|
||||
|
||||
```
|
||||
config.json
|
||||
├── dev module (enabled)
|
||||
│ ├── merge_dir: dev-workflow → ~/.claude
|
||||
│ ├── copy_file: memorys/CLAUDE.md
|
||||
│ ├── copy_file: skills/codex/SKILL.md
|
||||
│ └── run_command: install codeagent-wrapper binary
|
||||
│
|
||||
├── gh module (enabled)
|
||||
│ ├── merge_dir: github-workflow → ~/.claude
|
||||
│ ├── copy_file: skills/codeagent/SKILL.md
|
||||
│ ├── copy_dir: hooks → ~/.claude/hooks
|
||||
│ └── merge_json: hooks-config.json → settings.json
|
||||
│
|
||||
└── essentials module (enabled)
|
||||
└── merge_dir: development-essentials → ~/.claude
|
||||
```
|
||||
|
||||
**Installation Flow:**
|
||||
|
||||
```bash
|
||||
python3 install.py --module dev,gh
|
||||
|
||||
1. Load config.json
|
||||
2. Validate against config.schema.json
|
||||
3. Select modules: dev, gh
|
||||
4. Execute operations:
|
||||
├─ dev:
|
||||
│ ├─ Merge dev-workflow/commands → ~/.claude/commands
|
||||
│ ├─ Copy CLAUDE.md → ~/.claude/CLAUDE.md
|
||||
│ ├─ Copy codex skill → ~/.claude/skills/codex/
|
||||
│ └─ Run install.sh (compile codeagent-wrapper)
|
||||
│
|
||||
└─ gh:
|
||||
├─ Merge github-workflow/commands → ~/.claude/commands
|
||||
├─ Copy codeagent skill → ~/.claude/skills/codeagent/
|
||||
├─ Copy hooks → ~/.claude/hooks
|
||||
└─ Merge hooks-config.json → ~/.claude/settings.json
|
||||
5. Write installed_modules.json
|
||||
6. Log to install.log
|
||||
```
|
||||
|
||||
## Parallel Execution Engine
|
||||
|
||||
**Algorithm:**
|
||||
|
||||
```
|
||||
1. Parse task config (---TASK--- delimited format)
|
||||
2. Build dependency graph
|
||||
3. Topological sort (detect cycles)
|
||||
4. Execute in layers:
|
||||
Layer 0: Tasks with no dependencies
|
||||
Layer 1: Tasks depending only on Layer 0
|
||||
Layer 2: Tasks depending on Layers 0-1
|
||||
...
|
||||
5. Within each layer: unlimited concurrency
|
||||
6. On failure: skip dependent tasks, continue others
|
||||
7. Aggregate results
|
||||
```
|
||||
|
||||
**Example:**
|
||||
|
||||
```
|
||||
Tasks:
|
||||
A (no deps)
|
||||
B (no deps)
|
||||
C (depends on A)
|
||||
D (depends on A, B)
|
||||
E (depends on D)
|
||||
|
||||
Execution:
|
||||
Layer 0: A, B (parallel)
|
||||
Layer 1: C (waits for A), D (waits for A, B)
|
||||
Layer 2: E (waits for D)
|
||||
|
||||
Timeline:
|
||||
t=0: Start A, B
|
||||
t=1: A completes
|
||||
t=2: B completes, start C, D
|
||||
t=3: C completes
|
||||
t=4: D completes, start E
|
||||
t=5: E completes
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
|
||||
1. **No credential storage** - Uses existing CLI auth
|
||||
2. **Sandbox execution** - Tasks run in specified workdir
|
||||
3. **Timeout enforcement** - Prevents runaway processes
|
||||
4. **Signal handling** - Graceful shutdown on Ctrl+C
|
||||
5. **Input validation** - Sanitizes task configs
|
||||
|
||||
## Performance Characteristics
|
||||
|
||||
| Operation | Complexity | Notes |
|
||||
|-----------|------------|-------|
|
||||
| Backend selection | O(1) | Map lookup |
|
||||
| Task parsing | O(n) | Linear scan |
|
||||
| Topological sort | O(V+E) | Kahn's algorithm |
|
||||
| Parallel execution | O(depth) | Depth of dependency graph |
|
||||
| JSON parsing | O(n) | Streaming parser |
|
||||
|
||||
## Extensibility
|
||||
|
||||
### Adding New Backend
|
||||
|
||||
1. Implement `Backend` interface:
|
||||
```go
|
||||
type NewBackend struct{}
|
||||
|
||||
func (NewBackend) Name() string { return "new" }
|
||||
func (NewBackend) Command() string { return "new-cli" }
|
||||
func (NewBackend) BuildArgs(cfg *Config, targetArg string) []string {
|
||||
return []string{"--json", targetArg}
|
||||
}
|
||||
```
|
||||
|
||||
2. Register in `config.go`:
|
||||
```go
|
||||
backendRegistry = map[string]Backend{
|
||||
"codex": CodexBackend{},
|
||||
"claude": ClaudeBackend{},
|
||||
"gemini": GeminiBackend{},
|
||||
"new": NewBackend{},
|
||||
}
|
||||
```
|
||||
|
||||
3. Add JSON format detection in `parser.go`:
|
||||
```go
|
||||
if hasKey(obj, "new_specific_field") {
|
||||
// Parse new backend format
|
||||
}
|
||||
```
|
||||
|
||||
### Adding New Hook
|
||||
|
||||
1. Create script in `hooks/`:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# hooks/my-custom-hook.sh
|
||||
echo "Hook executed"
|
||||
```
|
||||
|
||||
2. Register in `.claude/settings.json`:
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"UserPromptSubmit": [
|
||||
{
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "$CLAUDE_PROJECT_DIR/hooks/my-custom-hook.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Adding New Skill
|
||||
|
||||
1. Create `skills/my-skill/SKILL.md`:
|
||||
```markdown
|
||||
---
|
||||
name: my-skill
|
||||
description: My custom skill
|
||||
---
|
||||
|
||||
# My Custom Skill
|
||||
|
||||
Usage instructions...
|
||||
```
|
||||
|
||||
2. Add activation rule in `skills/skill-rules.json`:
|
||||
```json
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"trigger": {"pattern": "my keyword", "type": "regex"},
|
||||
"skill": "my-skill",
|
||||
"priority": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Further Reading
|
||||
|
||||
- [Codeagent-Wrapper Guide](./CODEAGENT-WRAPPER.md)
|
||||
- [GitHub Workflow Guide](./GITHUB-WORKFLOW.md)
|
||||
- [Hooks Documentation](./HOOKS.md)
|
||||
- [README](../README.md)
|
||||
@@ -1,445 +0,0 @@
|
||||
# 企业级 Claude Code 工作流方案
|
||||
|
||||
基于 Anthropic 官方最佳实践、GitHub Copilot 企业级功能、以及 showcase 项目的研究整理。
|
||||
|
||||
## 实施状态
|
||||
- ✅ codeagent-wrapper multi-backend
|
||||
- ✅ /gh-create-issue command
|
||||
- ✅ /gh-implement command
|
||||
- ✅ Hooks + Skills activation
|
||||
|
||||
## 核心工作流矩阵
|
||||
|
||||
| 工作流 | 触发方式 | 核心能力 | 企业应用场景 |
|
||||
|--------|----------|----------|--------------|
|
||||
| `/gh-create-issue` | Command | 多轮对话 → 结构化 Issue | 需求澄清、Bug 报告标准化 |
|
||||
| `/gh-implement` | Command | Issue → 开发 → PR | 自动化开发闭环 |
|
||||
| `/code-review` | Hook (PR) | AI 审查 + 人工确认 | 代码质量把控 |
|
||||
| `/incident-debug` | Command | 日志分析 → 根因定位 | 生产问题排查 |
|
||||
| `/migration` | Command | 批量代码迁移 | 技术债务清理 |
|
||||
| `/security-audit` | Hook/Scheduled | 安全扫描 + 修复建议 | 安全合规 |
|
||||
| `/onboarding` | Command | 代码库问答 | 新人培训 |
|
||||
|
||||
---
|
||||
|
||||
## 1. GitHub Issue 全生命周期工作流
|
||||
|
||||
### 1.1 `/gh-create-issue` - 需求创建
|
||||
|
||||
```
|
||||
用户输入 → 多轮澄清 → 结构化 Issue → gh issue create
|
||||
```
|
||||
|
||||
**流程设计:**
|
||||
```markdown
|
||||
---
|
||||
description: Create structured GitHub issue through multi-round dialogue
|
||||
argument-hint: Brief description of what you need (e.g., "user authentication feature")
|
||||
---
|
||||
|
||||
You are a Requirements Analyst. Help create a well-structured GitHub issue.
|
||||
|
||||
## Phase 1: Initial Understanding
|
||||
Ask 2-3 targeted questions to understand:
|
||||
- What problem does this solve? (Why)
|
||||
- Who benefits from this? (Who)
|
||||
- What's the expected outcome? (What)
|
||||
|
||||
## Phase 2: Technical Scoping
|
||||
Based on answers, clarify:
|
||||
- Acceptance criteria (testable conditions)
|
||||
- Technical constraints
|
||||
- Dependencies on other features/teams
|
||||
- Priority and urgency
|
||||
|
||||
## Phase 3: Issue Generation
|
||||
Generate issue with structure:
|
||||
- **Title**: [Type] Brief description
|
||||
- **Problem Statement**: Why this matters
|
||||
- **Proposed Solution**: High-level approach
|
||||
- **Acceptance Criteria**: Checkbox list
|
||||
- **Technical Notes**: Implementation hints
|
||||
- **Labels**: auto-suggest based on content
|
||||
|
||||
## Phase 4: Confirmation & Creation
|
||||
Show preview → User confirms → `gh issue create`
|
||||
```
|
||||
|
||||
### 1.2 `/gh-implement` - Issue 实现
|
||||
|
||||
```
|
||||
gh issue view → 理解 + 沟通 → /dev 开发 → gh issue comment → gh pr create
|
||||
```
|
||||
|
||||
**流程设计:**
|
||||
```markdown
|
||||
---
|
||||
description: Implement GitHub issue with full development lifecycle
|
||||
argument-hint: Issue number (e.g., "123")
|
||||
---
|
||||
|
||||
## Phase 1: Issue Analysis
|
||||
1. `gh issue view $ARGUMENTS --json title,body,labels,comments`
|
||||
2. Parse requirements and acceptance criteria
|
||||
3. Identify affected files via codebase exploration
|
||||
|
||||
## Phase 2: Clarification (if needed)
|
||||
If ambiguous, use AskUserQuestion to clarify:
|
||||
- Implementation approach choices
|
||||
- Scope boundaries
|
||||
- Testing requirements
|
||||
|
||||
## Phase 3: Development
|
||||
Invoke /dev workflow with parsed requirements:
|
||||
- Codex analysis
|
||||
- Task breakdown
|
||||
- Parallel execution
|
||||
- Coverage validation (≥90%)
|
||||
|
||||
## Phase 4: Progress Updates
|
||||
After each milestone:
|
||||
`gh issue comment $ARGUMENTS --body "✅ Completed: [milestone]"`
|
||||
|
||||
## Phase 5: PR Creation
|
||||
`gh pr create --title "[#$ARGUMENTS] ..." --body "Closes #$ARGUMENTS\n\n..."`
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. 代码审查工作流
|
||||
|
||||
### 2.1 PR 自动审查 Hook
|
||||
|
||||
**触发点:** PR 创建或更新时
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "Bash(gh pr create:*)",
|
||||
"hooks": [{
|
||||
"type": "command",
|
||||
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/auto-review.sh"
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**审查维度(参考 Anthropic 博客):**
|
||||
- 代码风格一致性
|
||||
- 潜在 bug 和边界条件
|
||||
- 安全漏洞(OWASP Top 10)
|
||||
- 性能影响
|
||||
- 文档完整性
|
||||
- 测试覆盖率
|
||||
|
||||
### 2.2 `/review-pr` Command
|
||||
|
||||
```markdown
|
||||
---
|
||||
description: Comprehensive PR review with actionable feedback
|
||||
argument-hint: PR number or URL
|
||||
---
|
||||
|
||||
1. Fetch PR details: `gh pr view $ARGUMENTS --json files,commits,body`
|
||||
2. Read changed files with context (±50 lines)
|
||||
3. Analyze against:
|
||||
- Repository coding standards (CLAUDE.md)
|
||||
- Security best practices
|
||||
- Performance implications
|
||||
- Test coverage
|
||||
4. Generate review with:
|
||||
- Summary of changes
|
||||
- 🟢 Approved / 🟡 Changes Requested / 🔴 Blocked
|
||||
- Specific line comments
|
||||
- Suggested improvements
|
||||
5. Post review: `gh pr review $ARGUMENTS --body "..." [--approve|--request-changes]`
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. 生产问题排查工作流
|
||||
|
||||
### 3.1 `/incident-debug`
|
||||
|
||||
```markdown
|
||||
---
|
||||
description: Debug production incidents from logs and traces
|
||||
argument-hint: Error message, log file path, or incident ID
|
||||
---
|
||||
|
||||
## Phase 1: Context Gathering
|
||||
- Parse provided logs/error messages
|
||||
- Search codebase for related code paths
|
||||
- Check recent deployments: `gh release list --limit 5`
|
||||
|
||||
## Phase 2: Root Cause Analysis
|
||||
Use Codex for deep analysis:
|
||||
- Stack trace interpretation
|
||||
- Data flow tracing
|
||||
- Dependency chain analysis
|
||||
|
||||
## Phase 3: Solution Proposal
|
||||
- Immediate mitigation steps
|
||||
- Long-term fix plan
|
||||
- Regression test suggestions
|
||||
|
||||
## Phase 4: Documentation
|
||||
Generate incident report:
|
||||
- Timeline
|
||||
- Root cause
|
||||
- Impact assessment
|
||||
- Resolution steps
|
||||
- Prevention measures
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. 大规模迁移工作流
|
||||
|
||||
### 4.1 `/migration` - 批量代码迁移
|
||||
|
||||
**适用场景:**
|
||||
- 框架升级(React 17→18, Vue 2→3)
|
||||
- API 版本迁移
|
||||
- 依赖库替换
|
||||
- 代码模式重构
|
||||
|
||||
```markdown
|
||||
---
|
||||
description: Batch code migration with validation
|
||||
argument-hint: Migration type and scope (e.g., "React class to hooks in src/components")
|
||||
---
|
||||
|
||||
## Phase 1: Scope Analysis
|
||||
1. Use Codex to identify all affected files
|
||||
2. Generate migration task list (file by file)
|
||||
3. Estimate complexity per file
|
||||
|
||||
## Phase 2: Parallel Execution (Headless Mode)
|
||||
For each file, run:
|
||||
```bash
|
||||
claude -p "Migrate $FILE from [old] to [new]. Verify with tests." \
|
||||
--allowedTools Edit Bash(npm test:*)
|
||||
```
|
||||
|
||||
## Phase 3: Validation
|
||||
- Run full test suite
|
||||
- Type checking
|
||||
- Lint verification
|
||||
|
||||
## Phase 4: Report
|
||||
- Success/failure per file
|
||||
- Manual review required files
|
||||
- Rollback instructions
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 安全审计工作流
|
||||
|
||||
### 5.1 `/security-audit`
|
||||
|
||||
```markdown
|
||||
---
|
||||
description: Security vulnerability scanning and remediation
|
||||
---
|
||||
|
||||
## Scan Categories
|
||||
1. **Dependency vulnerabilities**: `npm audit` / `pip-audit`
|
||||
2. **SAST**: Code pattern analysis for OWASP Top 10
|
||||
3. **Secrets detection**: Hardcoded credentials
|
||||
4. **Configuration**: Insecure defaults
|
||||
|
||||
## Output Format
|
||||
- Severity: Critical/High/Medium/Low
|
||||
- Location: File:Line
|
||||
- Description: What's wrong
|
||||
- Remediation: How to fix
|
||||
- Auto-fix available: Yes/No
|
||||
|
||||
## Auto-remediation
|
||||
For auto-fixable issues:
|
||||
1. Generate fix via Codex
|
||||
2. Run tests
|
||||
3. Create PR with security label
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. 新人培训工作流
|
||||
|
||||
### 6.1 Codebase Q&A(Anthropic 推荐)
|
||||
|
||||
直接使用 Claude Code 进行代码库问答,无需特殊配置:
|
||||
|
||||
**常见问题类型:**
|
||||
- "这个项目的架构是什么?"
|
||||
- "如何添加新的 API 端点?"
|
||||
- "日志系统是怎么工作的?"
|
||||
- "这个函数为什么这样设计?"(结合 git history)
|
||||
|
||||
### 6.2 `/onboarding` Command
|
||||
|
||||
```markdown
|
||||
---
|
||||
description: Interactive codebase onboarding for new team members
|
||||
---
|
||||
|
||||
## Phase 1: Overview
|
||||
- Read README, CLAUDE.md, package.json
|
||||
- Summarize tech stack and architecture
|
||||
|
||||
## Phase 2: Key Flows
|
||||
For each major feature:
|
||||
- Entry point
|
||||
- Data flow
|
||||
- Key files
|
||||
|
||||
## Phase 3: Development Setup
|
||||
- Environment setup steps
|
||||
- Common commands
|
||||
- Testing workflow
|
||||
|
||||
## Phase 4: Q&A Mode
|
||||
"Ask me anything about this codebase!"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. codeagent-wrapper 多后端架构
|
||||
|
||||
### 设计方案
|
||||
|
||||
```go
|
||||
// codeagent-wrapper architecture
|
||||
type AgentBackend interface {
|
||||
Name() string
|
||||
Execute(ctx context.Context, task TaskSpec, timeout int) TaskResult
|
||||
HealthCheck() error
|
||||
}
|
||||
|
||||
type CodexBackend struct{} // OpenAI Codex
|
||||
type ClaudeBackend struct{} // Claude CLI (claude -p)
|
||||
type GeminiBackend struct{} // Gemini API
|
||||
|
||||
// 命令行接口
|
||||
// codeagent-wrapper [--backend=codex|claude|gemini] "task" [workdir]
|
||||
// codeagent-wrapper --parallel --backend=claude < tasks.txt
|
||||
```
|
||||
|
||||
### 后端选择策略
|
||||
|
||||
| 任务类型 | 推荐后端 | 原因 |
|
||||
|----------|----------|------|
|
||||
| 代码生成/重构 | Codex | 代码专精 |
|
||||
| 复杂推理/规划 | Claude | 推理能力强 |
|
||||
| 快速原型 | Gemini | 速度快、成本低 |
|
||||
| 并行批量任务 | 混合 | 负载均衡 |
|
||||
|
||||
---
|
||||
|
||||
## 8. Hooks + Skills 协作模式
|
||||
|
||||
### 推荐配置
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"UserPromptSubmit": [
|
||||
{
|
||||
"hooks": [{
|
||||
"type": "command",
|
||||
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/skill-activation-prompt.sh"
|
||||
}]
|
||||
}
|
||||
],
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "Edit|MultiEdit|Write",
|
||||
"hooks": [{
|
||||
"type": "command",
|
||||
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/post-tool-tracker.sh"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"matcher": "Bash(gh pr create:*)",
|
||||
"hooks": [{
|
||||
"type": "command",
|
||||
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/auto-review-trigger.sh"
|
||||
}]
|
||||
}
|
||||
],
|
||||
"Stop": [
|
||||
{
|
||||
"hooks": [
|
||||
{"type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/test-runner.sh"},
|
||||
{"type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/coverage-check.sh"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### skill-rules.json 扩展
|
||||
|
||||
```json
|
||||
{
|
||||
"skills": {
|
||||
"gh-workflow": {
|
||||
"type": "domain",
|
||||
"enforcement": "suggest",
|
||||
"priority": "high",
|
||||
"promptTriggers": {
|
||||
"keywords": ["issue", "pr", "pull request", "github", "gh"],
|
||||
"intentPatterns": ["(create|implement|review).*?(issue|pr|pull)"]
|
||||
}
|
||||
},
|
||||
"incident-response": {
|
||||
"type": "domain",
|
||||
"enforcement": "suggest",
|
||||
"priority": "critical",
|
||||
"promptTriggers": {
|
||||
"keywords": ["error", "bug", "incident", "production", "debug", "crash"],
|
||||
"intentPatterns": ["(fix|debug|investigate).*?(error|bug|issue)"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9. 实施优先级建议
|
||||
|
||||
### Phase 1: 基础设施(1-2 周)
|
||||
1. ✅ codeagent-wrapper 已完成
|
||||
2. 🔄 codeagent-wrapper 多后端改造
|
||||
3. 🆕 基础 hooks 配置
|
||||
|
||||
### Phase 2: 核心工作流(2-3 周)
|
||||
1. `/gh-create-issue` command
|
||||
2. `/gh-implement` command
|
||||
3. `/code-review` command
|
||||
|
||||
### Phase 3: 高级功能(3-4 周)
|
||||
1. skill-rules.json + activation hook
|
||||
2. `/migration` 批量迁移
|
||||
3. `/security-audit` 安全审计
|
||||
|
||||
### Phase 4: 企业级增强
|
||||
1. 多 Claude 实例协作
|
||||
2. CI/CD 集成(headless mode)
|
||||
3. 监控和分析仪表板
|
||||
|
||||
---
|
||||
|
||||
## 参考资料
|
||||
|
||||
- [Anthropic Claude Code Best Practices](https://www.anthropic.com/engineering/claude-code-best-practices)
|
||||
- [GitHub Copilot Coding Agent](https://docs.github.com/en/copilot/using-github-copilot/using-copilot-coding-agent-to-work-on-tasks)
|
||||
- [claude-code-infrastructure-showcase](https://github.com/hellogithub/claude-code-infrastructure-showcase)
|
||||
Reference in New Issue
Block a user