Skip to content

Commit 4af2088

Browse files
committed
Resolve merge conflicts with upstream
2 parents 75e8943 + ae4138a commit 4af2088

211 files changed

Lines changed: 21911 additions & 2222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.codex/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[features]
2+
goals = true
3+
collaboration_modes = true

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ANTHROPIC_API_KEY=dummy_anthropic_key
66
FIREWORKS_API_KEY=dummy_fireworks_key
77
CANOPYWAVE_API_KEY=dummy_canopywave_key
88
SILICONFLOW_API_KEY=dummy_siliconflow_key
9+
OPENCODE_API_KEY=dummy_opencode_key
910

1011
# Database & Server
1112
DATABASE_URL=postgresql://manicode_user_local:secretpassword_local@localhost:5432/manicode_db_local
@@ -29,6 +30,7 @@ STRIPE_SUBSCRIPTION_500_PRICE_ID=price_dummy_subscription_500_id
2930
# External Services
3031
LINKUP_API_KEY=dummy_linkup_key
3132
LOOPS_API_KEY=dummy_loops_key
33+
ZEROCLICK_API_KEY=dummy_zeroclick_key
3234

3335
# Discord Integration
3436
DISCORD_PUBLIC_KEY=dummy_discord_public_key
@@ -43,4 +45,4 @@ NEXT_PUBLIC_POSTHOG_API_KEY=phc_dummy_posthog_key
4345
NEXT_PUBLIC_POSTHOG_HOST_URL=https://us.i.posthog.com
4446
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_dummy_publishable
4547
NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL=https://billing.stripe.com/p/login/test_dummy
46-
NEXT_PUBLIC_WEB_PORT=3000
48+
NEXT_PUBLIC_WEB_PORT=3000
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 'Setup Bun Compile Runtime'
2+
description: 'Download and cache a Bun runtime used by bun build --compile-executable-path'
3+
4+
inputs:
5+
target:
6+
description: 'Bun compile target, for example bun-windows-x64'
7+
required: true
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Get Bun version
13+
id: bun-version
14+
shell: bash
15+
run: echo "version=$(bun --version)" >> "$GITHUB_OUTPUT"
16+
17+
- name: Cache Bun compile runtime
18+
uses: actions/cache@v5
19+
with:
20+
path: ${{ runner.temp }}/bun-compile-runtimes/${{ inputs.target }}-v${{ steps.bun-version.outputs.version }}
21+
key: ${{ runner.os }}-bun-compile-runtime-${{ inputs.target }}-v${{ steps.bun-version.outputs.version }}
22+
23+
- name: Prepare Bun compile runtime
24+
shell: pwsh
25+
env:
26+
BUN_COMPILE_TARGET: ${{ inputs.target }}
27+
BUN_VERSION: ${{ steps.bun-version.outputs.version }}
28+
RUNTIME_DIR: ${{ runner.temp }}/bun-compile-runtimes/${{ inputs.target }}-v${{ steps.bun-version.outputs.version }}
29+
run: |
30+
$ErrorActionPreference = 'Stop'
31+
32+
$runtimePath = Join-Path $env:RUNTIME_DIR 'bun.exe'
33+
if (!(Test-Path -LiteralPath $runtimePath)) {
34+
New-Item -ItemType Directory -Force -Path $env:RUNTIME_DIR | Out-Null
35+
36+
$zipPath = Join-Path $env:RUNTIME_DIR "$($env:BUN_COMPILE_TARGET).zip"
37+
$downloadUrl = "https://github.com/oven-sh/bun/releases/download/bun-v$($env:BUN_VERSION)/$($env:BUN_COMPILE_TARGET).zip"
38+
39+
Write-Host "Downloading $($env:BUN_COMPILE_TARGET): $downloadUrl"
40+
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath
41+
Expand-Archive -LiteralPath $zipPath -DestinationPath $env:RUNTIME_DIR -Force
42+
43+
$extractedRuntimePath = Join-Path $env:RUNTIME_DIR "$($env:BUN_COMPILE_TARGET)/bun.exe"
44+
if (!(Test-Path -LiteralPath $extractedRuntimePath)) {
45+
throw "Downloaded $($env:BUN_COMPILE_TARGET), but bun.exe was not found at $extractedRuntimePath"
46+
}
47+
48+
Copy-Item -LiteralPath $extractedRuntimePath -Destination $runtimePath -Force
49+
}
50+
51+
"BUN_COMPILE_EXECUTABLE_PATH=$runtimePath" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8

.github/workflows/cli-release-build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ jobs:
315315
echo "$ENV_OVERRIDES" | jq -r 'to_entries | .[] | .key + "=" + .value' >> $GITHUB_ENV
316316
fi
317317
318+
- name: Prepare Windows Bun compile runtime
319+
uses: ./.github/actions/setup-bun-compile-runtime
320+
with:
321+
target: bun-windows-x64
322+
318323
- name: Build binary
319324
run: bun run scripts/build-binary.ts ${{ inputs.binary-name }} ${{ inputs.new-version }}
320325
working-directory: cli

.github/workflows/freebuff-e2e.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ jobs:
162162
echo "NEXT_PUBLIC_CB_ENVIRONMENT=prod" >> $GITHUB_ENV
163163
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
164164
165+
- name: Prepare Windows Bun compile runtime
166+
uses: ./.github/actions/setup-bun-compile-runtime
167+
with:
168+
target: bun-windows-x64
169+
165170
- name: Build Freebuff binary
166171
run: bun freebuff/cli/build.ts 0.0.0-e2e
167172
shell: bash

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Codebuff & Freebuff
22

3+
English | [简体中文](./README.zh-CN.md)
4+
35
**[Codebuff](https://codebuff.com)** is an open-source AI coding assistant that edits your codebase through natural language instructions. **[Freebuff](https://www.npmjs.com/package/freebuff)** is the free, ad-supported version — no subscription, no credits, no configuration.
46

57
Instead of using one model for everything, Codebuff coordinates specialized agents that work together to understand your project and make precise changes.

README.zh-CN.md

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
# Codebuff & Freebuff
2+
3+
[English](./README.md) | 简体中文
4+
5+
**[Codebuff](https://codebuff.com)** 是一款开源的 AI 编程助手,能根据自然语言指令直接修改你的代码库。**[Freebuff](https://www.npmjs.com/package/freebuff)** 是它的免费、广告支持版本——无需订阅、无需积分、零配置。
6+
7+
与那种"一个模型干所有事"的工具不同,Codebuff 会协调多个专业化的智能体(agent)协同工作,理解你的项目并做出精准的改动。
8+
9+
<div align="center">
10+
<img src="./assets/codebuff-vs-claude-code.png" alt="Codebuff vs Claude Code" width="400">
11+
</div>
12+
13+
在我们的[评测](evals/README.md)中,Codebuff 在 175+ 个真实开源仓库的编码任务上以 61% 对 53% 的成绩领先 Claude Code。
14+
15+
16+
## 工作原理
17+
18+
当你让 Codebuff "给我的 API 加上身份验证"时,它可能会调用:
19+
20+
1. **File Picker Agent** —— 扫描代码库、理解架构、找出相关文件
21+
2. **Planner Agent** —— 规划哪些文件需要改、按什么顺序改
22+
3. **Editor Agent** —— 执行精确的修改
23+
4. **Reviewer Agent** —— 校验改动是否正确
24+
25+
<div align="center">
26+
<img src="./assets/multi-agents.png" alt="Codebuff Multi-Agents" width="250">
27+
</div>
28+
29+
相比单模型工具,这种多智能体方案能带来更准的上下文理解、更精确的修改,以及更少的错误。
30+
31+
## CLI:装好就能写代码
32+
33+
安装:
34+
35+
```bash
36+
npm install -g codebuff
37+
```
38+
39+
运行:
40+
41+
```bash
42+
cd your-project
43+
codebuff
44+
```
45+
46+
然后直接告诉 Codebuff 你想做什么,剩下的它自己搞定:
47+
48+
- "修掉用户注册里的 SQL 注入漏洞"
49+
- "给所有 API 端点加上限流"
50+
- "重构数据库连接代码,提升性能"
51+
52+
Codebuff 会找到对应的文件,跨多个文件做改动,并跑测试确认没有破坏现有功能。
53+
54+
## 创建自定义智能体
55+
56+
要开始构建自己的智能体,先启动 Codebuff 然后执行 `/init`
57+
58+
```bash
59+
codebuff
60+
```
61+
62+
进入 CLI 后:
63+
64+
```
65+
/init
66+
```
67+
68+
这会生成:
69+
```
70+
knowledge.md # Codebuff 用的项目上下文
71+
.agents/
72+
└── types/ # TypeScript 类型定义
73+
├── agent-definition.ts
74+
├── tools.ts
75+
└── util-types.ts
76+
```
77+
78+
通过编写智能体定义文件,你可以最大程度地控制智能体的行为。
79+
80+
通过指定工具、可派生的子智能体和提示词来实现自己的工作流。我们还提供了 TypeScript 生成器,方便你以更程序化的方式控制流程。
81+
82+
下面是一个 `git-committer` 智能体的例子,它会基于当前的 git 状态生成提交。注意它先跑 `git diff``git log` 分析改动,然后再把决策权交给 LLM,让它撰写有意义的 commit message 并完成实际提交。
83+
84+
```typescript
85+
export default {
86+
id: 'git-committer',
87+
displayName: 'Git Committer',
88+
model: 'openai/gpt-5-nano',
89+
toolNames: ['read_files', 'run_terminal_command', 'end_turn'],
90+
91+
instructionsPrompt:
92+
'You create meaningful git commits by analyzing changes, reading relevant files for context, and crafting clear commit messages that explain the "why" behind changes.',
93+
94+
async *handleSteps() {
95+
// 分析改动
96+
yield { tool: 'run_terminal_command', command: 'git diff' }
97+
yield { tool: 'run_terminal_command', command: 'git log --oneline -5' }
98+
99+
// 暂存文件,并用合适的 message 生成提交
100+
yield 'STEP_ALL'
101+
},
102+
}
103+
```
104+
105+
## SDK:在生产环境里跑智能体
106+
107+
安装 [SDK 包](https://www.npmjs.com/package/@codebuff/sdk)——注意这跟 CLI 用的 codebuff 包是两个不同的包。
108+
109+
```bash
110+
npm install @codebuff/sdk
111+
```
112+
113+
引入 client,开始跑智能体:
114+
115+
```typescript
116+
import { CodebuffClient } from '@codebuff/sdk'
117+
118+
// 1. 初始化 client
119+
const client = new CodebuffClient({
120+
apiKey: 'your-api-key',
121+
cwd: '/path/to/your/project',
122+
onError: (error) => console.error('Codebuff error:', error.message),
123+
})
124+
125+
// 2. 跑一个编码任务……
126+
const result = await client.run({
127+
agent: 'base', // Codebuff 默认的基础编码智能体
128+
prompt: 'Add error handling to all API endpoints',
129+
handleEvent: (event) => {
130+
console.log('Progress', event)
131+
},
132+
})
133+
134+
// 3. 也可以跑自定义智能体!
135+
const myCustomAgent: AgentDefinition = {
136+
id: 'greeter',
137+
displayName: 'Greeter',
138+
model: 'openai/gpt-5.1',
139+
instructionsPrompt: 'Say hello!',
140+
}
141+
await client.run({
142+
agent: 'greeter',
143+
agentDefinitions: [myCustomAgent],
144+
prompt: 'My name is Bob.',
145+
customToolDefinitions: [], // 也可以加自定义工具!
146+
handleEvent: (event) => {
147+
console.log('Progress', event)
148+
},
149+
})
150+
```
151+
152+
更多 SDK 用法请看[这里](https://www.npmjs.com/package/@codebuff/sdk)
153+
154+
## Freebuff:免费的编程智能体
155+
156+
不想订阅?**[Freebuff](https://www.npmjs.com/package/freebuff)** 是 Codebuff 的免费版本——无需订阅、无需积分、零配置,装上就能用。
157+
158+
```bash
159+
npm install -g freebuff
160+
cd your-project
161+
freebuff
162+
```
163+
164+
Freebuff 由广告支持,使用经过优化、兼顾速度与质量的模型。内置网页检索、浏览器使用等能力。详情见 [Freebuff README](./freebuff/README.md)
165+
166+
## 为什么选 Codebuff
167+
168+
**自定义工作流**:用 TypeScript 生成器把 AI 生成和程序化控制混着用。智能体可以派生子智能体、按条件分支、跑多步流程。
169+
170+
**OpenRouter 上的任何模型**:Claude Code 把你锁死在 Anthropic 的模型上,Codebuff 不一样——它支持 [OpenRouter](https://openrouter.ai/models) 上的所有模型,从 Claude、GPT 到 Qwen、DeepSeek 这类专用模型都行。可以按任务切换模型,也能随时用上最新发布的模型,不必等平台跟进。
171+
172+
**复用已发布的智能体**:把社区[已发布的智能体](https://www.codebuff.com/store)拼起来用,少走弯路。Codebuff 智能体就是新一代的 MCP!
173+
174+
**SDK**:把 Codebuff 嵌进你自己的应用里。可以创建自定义工具、对接 CI/CD,或把编码能力内嵌进你的产品。
175+
176+
## 进阶用法
177+
178+
### 自定义智能体工作流
179+
180+
`/init` 命令创建带专门工作流的智能体:
181+
182+
```bash
183+
codebuff
184+
/init
185+
```
186+
187+
这会在 `.agents/` 下生成一套可自定义的智能体结构。
188+
189+
## 参与贡献
190+
191+
我们 ❤️ 来自社区的贡献——无论是修 bug、调整智能体、还是改进文档。
192+
193+
**想参与?** 看一眼[贡献指南](./CONTRIBUTING.md) 就能上手。
194+
195+
### 运行测试
196+
197+
跑测试套件:
198+
199+
```bash
200+
cd cli
201+
bun test
202+
```
203+
204+
**交互式端到端测试**需要 tmux:
205+
206+
```bash
207+
# macOS
208+
brew install tmux
209+
210+
# Ubuntu/Debian
211+
sudo apt-get install tmux
212+
213+
# Windows(通过 WSL)
214+
wsl --install
215+
sudo apt-get install tmux
216+
```
217+
218+
更完整的测试文档见 [cli/src/__tests__/README.md](cli/src/__tests__/README.md)
219+
220+
可以帮忙的方向:
221+
222+
- 🐛 **修 bug** 或新增功能
223+
- 🤖 **打造专用智能体**并发布到 Agent Store
224+
- 📚 **完善文档**或撰写教程
225+
- 💡 **分享想法**:在 [GitHub Issues](https://github.com/CodebuffAI/codebuff/issues) 留言
226+
227+
## 开始使用
228+
229+
### 安装
230+
231+
**CLI**`npm install -g codebuff`
232+
233+
**SDK**`npm install @codebuff/sdk`
234+
235+
**Freebuff(免费版)**`npm install -g freebuff`
236+
237+
### 资源
238+
239+
**文档**[codebuff.com/docs](https://codebuff.com/docs)
240+
241+
**社区**[Discord](https://codebuff.com/discord)
242+
243+
**Issue 与想法**[GitHub Issues](https://github.com/CodebuffAI/codebuff/issues)
244+
245+
**贡献指南**[CONTRIBUTING.md](./CONTRIBUTING.md) ——想贡献从这里开始!
246+
247+
**支持**[support@codebuff.com](mailto:support@codebuff.com)
248+
249+
## Star 历史
250+
251+
[![Star History Chart](https://api.star-history.com/svg?repos=CodebuffAI/codebuff&type=Date)](https://www.star-history.com/#CodebuffAI/codebuff&Date)

agents/__tests__/base2.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, expect, test } from 'bun:test'
2+
3+
import {
4+
FREEBUFF_DEEPSEEK_V4_FLASH_MODEL_ID,
5+
FREEBUFF_DEEPSEEK_V4_PRO_MODEL_ID,
6+
FREEBUFF_KIMI_MODEL_ID,
7+
FREEBUFF_MINIMAX_MODEL_ID,
8+
} from '@codebuff/common/constants/freebuff-models'
9+
10+
import { createBase2 } from '../base2/base2'
11+
12+
describe('base2 reviewer selection', () => {
13+
test.each([
14+
[FREEBUFF_MINIMAX_MODEL_ID, 'code-reviewer-minimax'],
15+
[FREEBUFF_KIMI_MODEL_ID, 'code-reviewer-kimi'],
16+
[FREEBUFF_DEEPSEEK_V4_PRO_MODEL_ID, 'code-reviewer-deepseek'],
17+
[FREEBUFF_DEEPSEEK_V4_FLASH_MODEL_ID, 'code-reviewer-deepseek-flash'],
18+
])('uses matching reviewer for model %p', (model, expectedReviewer) => {
19+
const base2 = createBase2('free', { model })
20+
21+
expect(base2.spawnableAgents).toContain(expectedReviewer)
22+
expect(base2.instructionsPrompt).toContain(`Spawn a ${expectedReviewer}`)
23+
expect(base2.stepPrompt).toContain(`spawn a ${expectedReviewer}`)
24+
})
25+
})

0 commit comments

Comments
 (0)