Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 96 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,107 @@ see [UniAST Specification](docs/uniast-zh.md)


## Tips:

- You can add more repo ASTs into the AST directory without restarting abcoder MCP server.

- Try to use [the recommended prompt](llm/prompt/analyzer.md) and combine planning/memory tools like [sequential-thinking](https://github.com/modelcontextprotocol/servers/tree/main/src/sequentialthinking) in your AI agent.


## Claude Code Integration

ABCoder provides deep integration with [Claude Code](https://claude.ai/code) through the AST-Driven Coding workflow, enabling hallucination-free code analysis and precise execution.

### Setup

1. **Install ABCoder Claude Configuration**

Copy [`docs/.claude/`](docs/.claude/) to your home directory or project root:

```bash
cp -r docs/.claude ~/
```

2. **Configure ABCoder MCP Server**

Configure in Claude Code's `~/.claude.json` (the hook uses `abcoder parse go/ts . -o ~/.asts/repo.json` for the default AST folder):

```json
{
"mcpServers": {
"abcoder": {
"command": "abcoder",
"args": ["mcp", "~/.asts"]
}
}
}
```

3. **Configure Hooks**

Claude Code will automatically read hooks from [`~/.claude/settings.json`](docs/.claude/settings.json) to enable:
- Auto-detect language and generate AST before calling `mcp__abcoder` tools
- Display ABCoder workflow SOP to Claude after `list_repos`
- Remind to call `get_ast_node` recursively

### AST-Driven Coding Workflow

[`.claude/hooks`](docs/.claude/hooks) provide a 4-layer analysis chain from repository to node details:

```
list_repos → get_repo_structure → get_package_structure → get_file_structure → get_ast_node
│ │ │ │ │
└── repo_name └── mod/pkg list └── file list └── node list └── dependencies/references
```

### Claude Code Slash Commands

[`.claude/commands`](docs/.claude/commands) provide three custom slash commands to streamline development:

| Command | Function | Description |
|---------|----------|-------------|
| [`/abcoder:schd`](docs/.claude/commands/abcoder:schd.md) | Design implementation | Analyze codebase using ABCoder, design technical solution |
| [`/abcoder:task <name>`](docs/.claude/commands/abcoder:task.md) | Create coding task | Generate standardized CODE_TASK document |
| [`/abcoder:recheck <task>`](docs/.claude/commands/abcoder:recheck.md) | Verify solution | Critically check CODE_TASK feasibility, useful when a CODE_TASK contains external dependencies |

### Workflow

```
User Request
/abcoder:schd ──────────→ Design Solution (ABCoder Analysis)
│ │
▼ ▼
/abcoder:task ─────────→ CODE_TASK (with Technical Specs, including accurate `get_ast_node` call args)
│ │
▼ ▼
/abcoder:recheck ────→ Verify Solution (ABCoder Validation. After `/abcoder:task` Claude Code will tell you what the external dependencies CODE_TASK contains, use `/abcoder:recheck` to analyze external ast_node and technical detail with ABCoder)
│ │
▼ ▼
sub-agent ─────────→ Execute Implementation
```

### Configuration Files

| File | Purpose |
|------|---------|
| [`CLAUDE.md`](docs/.claude/CLAUDE.md) | Core AST-Driven Coder role definition |
| [`settings.json`](docs/.claude/settings.json) | Hooks and permissions configuration |
| [`hooks/`](docs/.claude/hooks/) | Automation scripts (parse/prompt/reminder) |
| [`commands/`](docs/.claude/commands/) | Slash command definitions (abcoder:task/abcoder:schd/abcoder:recheck) |
| [`tmpls/CODE_TASK.md`](docs/.claude/tmpls/CODE_TASK.md) | Coding task template |

### Dependencies

- Claude Code CLI
- abcoder MCP server (provides `mcp__abcoder` tools)
- sequential-thinking MCP server (provides `mcp__sequential_thinking` tools, optional)

> For detailed configuration, see [docs/.claude/README.md](docs/.claude/README.md)

> Watch the demo video [here](https://github.com/cloudwego/abcoder/pull/141)


## Use ABCoder as an Agent (WIP)

You can also use ABCoder as a command-line Agent like:
Expand Down
76 changes: 76 additions & 0 deletions docs/.claude/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# AST-Driven Coding

你是 AST-Driven Coder,通过整合 `mcp__abcoder` 和 `mcp__sequential_thinking`,为用户提供无幻觉上下文、模糊需求质询、诚实推理和精确执行。

## MCP 工具使用体系

### 工具优先级决策
**代码分析优先级**: `mcp__abcoder` > Read/Search

| 工具 | 适用场景 | 核心价值 |
|------|----------|----------|
| `mcp__abcoder` | 本地代码深度分析 | UniAST + LSP无幻觉理解代码结构、类型信息、调用链。优于Read/Search |
| `mcp__sequential_thinking` | 复杂问题分解 | 多步骤问题的系统化思考 |

## ABCoder SOP
1. 问题分析:
- 基于用户问题分析相关关键词
- MUST 使用 `list_repos` 确认`repo_name`

2. 代码定位 (repo→package→node→ast node relationship):
- 2.1 定位package: 基于 `get_repo_structure` 返回的package list选择目标package
- 2.2 定位node: 通过 `get_package_structure` 返回的file信息,确认目标node;无法确认时,调用 `get_files_structure`
- 2.3 确认ast node relationship: 递归调用 `get_ast_node` 获取node详细(dependencies, references, inheritance, implementation, grouping)

### 开发中的 abcoder 使用
- 编写前:使用 `get_package_structure` 分析相似代码模式,`get_ast_node` 学习项目最佳实践

## 分阶段开发理念

IMPORTANT: 开发前,MUST 与用户对齐CODE_TASK需求;对于CODE_TASK中不明确的任务(例如任务需要的SDK Method定义、返回值的JSON/IDL),质询用户
IMPORTANT: 开始开发前,阐述此次CODE_TASK的调用链路、相关SDK Method定义、cURL JSON定义
### 开发阶段
1. MVP阶段:核心功能可工作,基本类型安全
2. 完善阶段:错误处理、边界情况、测试覆盖
3. 优化阶段:性能优化、代码重构、文档完善

## 代码质量标准

### 实现要求(按优先级)
MUST:
- Never 使用简化/Mock实现,使用真实SDK/cURL
- 类型安全:核心逻辑必须有明确类型定义
- 基本错误处理:处理可预见的异常情况

SHOULD:
- 完整的边界条件处理
- 性能敏感场景的优化
- 复杂逻辑的注释说明

COULD:
- 100%遵循SOLID编码规范
- 极致的性能优化

### 验证标准
- 关键路径和边界条件 MUST 有测试
- 通过 linter 和类型检查
- 手动验证主要用户场景

## 用户协作模式

| 用户行为 | 响应策略 |
|----------|----------|
| 模糊需求 | 使用 `mcp__sequential_thinking` 澄清,提供具体选项 |
| BUG修复 | 使用 `mcp__abcoder__get_ast_node` 详细分析,根本解决 |
| 重构替换 | 使用 `semgrep` 和 `comby` 结构化搜索替换 |
| 代码分析请求 | MUST 使用 `mcp__abcoder` SOP |

## 执行要求

1. 绝不假设 - 任何不确定代码,MUST 通过`mcp__abcoder__get_ast_node`工具验证
2. 工具链整合 - 充分利用ABCoder等工具提升效率
3. 质量内建 - 代码质量要求融入每个环节
4. 渐进交付 - 复杂任务分解为可验证的小步骤

- **使用SubAgent时提醒使用ABCoder** - 当需要使用subAgent(如@agent-Explore、@agent-coding-executor)进行代码分析时,应该提醒SubAgent使用`mcp__abcoder__get_ast_node`以获得更准确的分析结果
- **Never 说英语**:MUST 使用中文
127 changes: 127 additions & 0 deletions docs/.claude/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# AST-Driven Coding 配置

Claude Code 的 AST 驱动开发配置,通过 MCP 工具、钩子和斜杠命令实现无幻觉的代码分析和精确执行。

## 目录结构

```
.claude/
├── CLAUDE.md # 核心指令:AST-Driven Coder 角色定义
├── settings.json # 钩子配置:PreToolUse/PostToolUse
├── hooks/ # 钩子脚本
│ ├── parse.sh # 自动检测语言并生成 AST
│ ├── prompt.sh # 显示工作流程 SOP
│ └── reminder.sh # 提醒递归调用 get_ast_node
├── commands/ # 斜杠命令定义
│ ├── abcoder:task.md # /abcoder:task - 创建编码任务
│ ├── abcoder:schd.md # /abcoder:schd - 设计实现方案
│ └── abcoder:recheck.md # /abcoder:recheck - 技术方案核对
└── tmpls/ # 文档模板
└── CODE_TASK.md # 编码任务模板
```

## 核心理念

**AST-Driven Coding**: 基于 UniAST + LSP 的无幻觉代码分析

| 原则 | 说明 |
|------|------|
| 绝不假设 | 不确定代码 MUST 通过 `mcp__abcoder__get_ast_node` 验证 |
| 代码分析优先级 | `mcp__abcoder` > Read/Search |
| 直接使用原则 | 预先分析提供完整上下文,SubAgent 直接执行无需重分析 |
| 分阶段开发 | MVP → 完善 → 优化 |

## MCP 工具

### mcp__abcoder

本地代码深度分析工具,提供四层 AST 结构:

```
list_repos → get_repo_structure → get_package_structure → get_file_structure → get_ast_node
│ │ │ │ │
└── repo_name └── mod/pkg list └── file list └── node list └── dependencies/references/inheritance
```

**SOP 流程**:
1. 问题分析 → `list_repos` 确认 repo_name
2. 定位 package → `get_repo_structure` 选择目标 package
3. 定位 node → `get_package_structure` 确认目标 node
4. 获取关系 → `get_ast_node` 递归获取完整信息

### mcp__sequential_thinking

多步骤问题的系统化思考工具,用于复杂问题分解和模糊需求质询。

## 钩子系统

| 钩子 | 事件 | 匹配工具 | 作用 |
|------|------|----------|------|
| parse.sh | PreToolUse | get_repo_structure, get_file_structure, get_package_structure, get_ast_node | 自动检测语言并生成 AST 到 `~/.asts/` 目录 |
| prompt.sh | PostToolUse | list_repos | 显示 ABCoder 工作流程 SOP |
| reminder.sh | PostToolUse | get_repo_structure, get_package_structure, get_file_structure | 提醒递归调用 get_ast_node |

## 斜杠命令

### /abcoder:task <名称>

创建 CODE_TASK 文档,生成 `./task/{{MMDD}}/{{NAME}}__CODE_TASK.md`

**格式要求**:
- action: create/modify/delete
- 涉及 SDK: 指定 Package/Method 名称
- 涉及 curl: 提供完整命令和响应结构
- 提供具体验证方法

### /abcoder:schd

使用 mcp__abcoder 设计实现方案

**Guardrails**:
- 最大化复用已有功能
- 优先最小改动
- 禁止编写代码、禁止使用 agent

### /abcoder:recheck <任务>

批判性检查 CODE_TASK 技术可行性

**检查项**:
- 方案可实现性
- 技术风险
- 代码复用和改动最小化

## 工作流

```
用户需求
/abcoder:schd ──────────────→ 设计方案(abcoder分析)
│ │
▼ ▼
/abcoder:task ────────→ CODE_TASK(含技术规格)
│ │
▼ ▼
/abcoder:recheck ─────→ 方案核对(abcoder验证)
│ │
▼ ▼
coding-executor ──────→ 执行实现
```

## 安装

1. 复制 `.claude/` 目录到项目根目录或用户主目录
2. 确保 `settings.json` 中的钩子路径正确
3. 确保 `~/.claude/tmpls/` 目录存在且包含模板文件

## 依赖

- Claude Code CLI
- abcoder MCP 服务器(提供 mcp__abcoder 工具)
- sequential-thinking MCP 服务器(提供 mcp__sequential_thinking 工具)

## 相关文档

- [hooks/README.md](hooks/README.md) - 钩子系统详解
- [commands/README.md](commands/README.md) - 斜杠命令详解
Loading
Loading