ai-battle 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +240 -0
  3. package/ai-battle.sh +1728 -0
  4. package/package.json +29 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alfons
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,240 @@
1
+ # ai-battle 🎯
2
+
3
+ > 让多个 AI Agent 对同一问题进行结构化圆桌讨论,自动管理轮次、检测共识、保存全部记录。
4
+
5
+ ![Bash](https://img.shields.io/badge/Bash-4%2B-green?logo=gnubash&logoColor=white)
6
+ ![License](https://img.shields.io/badge/License-MIT-blue)
7
+ ![jq](https://img.shields.io/badge/Dep-jq-orange)
8
+
9
+ ## ✨ 特性
10
+
11
+ - 🤖 **多 Agent 圆桌** — 支持 Claude / Codex / Gemini,可自由组合
12
+ - 🔁 **同类自辩** — 同一 Agent 可参加多席位(如 `gemini,gemini`)
13
+ - 🔨 **裁判模式** — 独立裁判每轮总结差异、自动检测共识、生成最终报告
14
+ - 👁️ **上帝视角** — 每轮结束后可人工注入补充信息引导讨论方向
15
+ - 💾 **Session 录制** — 保存 Agent CLI 原始输出(stream-json/json/raw)
16
+ - 🔄 **断点续讨** — 中断后自动恢复到上次轮次继续讨论
17
+ - 🔌 **可扩展** — 实现 3 个函数 + 注册即可接入新 Agent
18
+
19
+ ## 🚀 快速开始
20
+
21
+ ```bash
22
+ # 1. 创建讨论目录
23
+ mkdir my-topic && cd my-topic
24
+
25
+ # 2. 写入问题
26
+ echo "微服务 vs 单体架构的优缺点?" > problem.md
27
+
28
+ # 3. 启动讨论(自动拉取最新版)
29
+ npx ai-battle --agents claude,gemini --rounds 8
30
+ ```
31
+
32
+ ## 📦 安装
33
+
34
+ **无需安装,直接使用 npx(推荐):**
35
+
36
+ ```bash
37
+ npx ai-battle --agents claude,gemini --rounds 5
38
+ ```
39
+
40
+ > npx 每次执行自动拉取最新版本,无需手动更新。
41
+
42
+ **全局安装:**
43
+
44
+ ```bash
45
+ npm install -g ai-battle
46
+ ```
47
+
48
+ ## 📖 用法
49
+
50
+ ```text
51
+ ai-battle [options]
52
+ ai-battle help
53
+ ```
54
+
55
+ | 参数 | 说明 |
56
+ |------|------|
57
+ | `--agents, -a <a1,a2>` | 选择参与的 Agent(默认: `claude,codex`),支持同类: `--agents gemini,gemini` |
58
+ | `--rounds, -r <N>` | 最大讨论轮次(默认: 10) |
59
+ | `--god, -g` | 开启上帝视角(每轮结束后可注入补充信息) |
60
+ | `--referee [agent]` | 开启裁判模式(每轮总结差异/检测共识,结束时生成 SUMMARY.md) |
61
+
62
+ ## 💡 使用示例
63
+
64
+ ```bash
65
+ # 同类 Agent 自我辩论
66
+ ai-battle --agents gemini,gemini
67
+
68
+ # 三方圆桌讨论
69
+ ai-battle --agents claude,codex,gemini --rounds 5
70
+
71
+ # 裁判模式(每轮总结 + 结束时生成 SUMMARY.md)
72
+ ai-battle --agents claude,codex,gemini --referee --rounds 5
73
+
74
+ # 指定 claude 做裁判
75
+ ai-battle --agents codex,gemini --referee claude --rounds 5
76
+
77
+ # 上帝视角 + 裁判
78
+ ai-battle --agents claude,codex --referee --god
79
+ ```
80
+
81
+ ## 🔄 工作流程
82
+
83
+ ```mermaid
84
+ sequenceDiagram
85
+ participant U as 👤 User
86
+ participant S as 📜 ai-battle
87
+ participant A as 🤖 Agent A
88
+ participant B as 🤖 Agent B
89
+ participant R as 🔨 Referee
90
+
91
+ U->>S: ai-battle --agents A,B --referee
92
+
93
+ rect rgb(40, 40, 60)
94
+ Note over S: 阶段 1: 初始化
95
+ S->>S: 加载 .env / 检查 problem.md
96
+ S->>A: check_A() 可用性检查
97
+ S->>B: check_B() 可用性检查
98
+ S->>S: 生成指令文件 / 初始化配置
99
+ end
100
+
101
+ rect rgb(30, 50, 40)
102
+ Note over S: Round 1: 并发独立思考
103
+ par
104
+ S->>A: call_A(problem)
105
+ A-->>S: 回复 A
106
+ and
107
+ S->>B: call_B(problem)
108
+ B-->>S: 回复 B
109
+ end
110
+ S->>S: 保存至 rounds/ 和 .sessions/
111
+ end
112
+
113
+ rect rgb(40, 40, 60)
114
+ Note over S: Round 2+: 顺序交互
115
+ loop 每个 Agent 依次发言
116
+ S->>A: call_A(B 的上轮回复)
117
+ A-->>S: 回复 A
118
+ S->>B: call_B(A 的最新回复)
119
+ B-->>S: 回复 B
120
+ end
121
+
122
+ opt --referee 模式
123
+ S->>R: call_referee(所有回复)
124
+ R-->>S: 裁判总结 / CONSENSUS 判定
125
+ end
126
+
127
+ opt --god 模式
128
+ S->>U: 请输入补充信息
129
+ U-->>S: 上帝视角注入
130
+ end
131
+ end
132
+
133
+ alt 达成共识
134
+ S->>S: 保存 consensus.md
135
+ opt 裁判模式
136
+ S->>R: generate_final_summary()
137
+ R-->>S: SUMMARY.md
138
+ end
139
+ S->>U: 🎉 达成共识!
140
+ else 未达成
141
+ S->>U: 是否追加轮次?
142
+ alt 追加
143
+ U-->>S: 追加 N 轮
144
+ Note over S: 继续 Round 循环
145
+ else 结束
146
+ opt 裁判模式
147
+ S->>R: generate_final_summary()
148
+ R-->>S: SUMMARY.md
149
+ end
150
+ S->>U: 讨论结束
151
+ end
152
+ end
153
+ ```
154
+
155
+ ## 🤖 内置 Agent
156
+
157
+ | Agent | 后端 | 检查方式 |
158
+ |-------|------|----------|
159
+ | **claude** | Claude CLI | `claude -p "hello"` |
160
+ | **codex** | Codex CLI | `codex exec "hello"` |
161
+ | **gemini** | Gemini CLI | `gemini -p "hello"` |
162
+
163
+ ## 📁 产出文件
164
+
165
+ ```text
166
+ ./
167
+ ├── problem.md # 讨论问题(用户创建)
168
+ ├── rounds/ # 讨论轮次
169
+ │ ├── round_1_claude.md
170
+ │ ├── round_1_gemini.md
171
+ │ ├── referee_round_2.md # 裁判总结(--referee)
172
+ │ ├── god_round_1.md # 上帝注入(--god)
173
+ │ └── ...
174
+ ├── .sessions/ # Agent CLI 原始输出
175
+ ├── consensus.md # 共识结论(如达成)
176
+ ├── SUMMARY.md # 最终总结(裁判自动生成)
177
+ ├── .debate.json # 配置/状态
178
+ └── .debate.log # 运行日志(tail -f 实时查看)
179
+ ```
180
+
181
+ ## ⚙️ 配置文件
182
+
183
+ | 文件 | 说明 |
184
+ |------|------|
185
+ | `.env` | 自动加载环境变量(启动时) |
186
+ | `referee.md` | 裁判自定义提示词(开启 `--referee` 时) |
187
+
188
+ ## 🔌 扩展 Agent
189
+
190
+ ```bash
191
+ # 1. 实现三个函数
192
+ check_myagent() { ... } # 可用性检查,返回 0/1
193
+ call_myagent() { ... } # 调用 Agent,$1=system_prompt $2=user_msg $3=session_tag
194
+ generate_myagent_md() { ... } # 生成指令文件,$1=max_rounds $2=problem
195
+
196
+ # 2. 注册
197
+ register_agent "myagent"
198
+ ```
199
+
200
+ ## 🔑 环境变量
201
+
202
+ <details>
203
+ <summary><b>Claude</b></summary>
204
+
205
+ ```bash
206
+ export ANTHROPIC_BASE_URL="https://open.bigmodel.cn/api/anthropic"
207
+ export ANTHROPIC_AUTH_TOKEN="your-token"
208
+ export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-4.7"
209
+ export API_TIMEOUT_MS=600000
210
+ ```
211
+
212
+ </details>
213
+
214
+ <details>
215
+ <summary><b>Codex</b></summary>
216
+
217
+ | 变量 | 说明 | 默认值 |
218
+ |------|------|--------|
219
+ | `CODEX_MODEL` | Codex 模型 | `gpt-5.3-codex` |
220
+
221
+ </details>
222
+
223
+ <details>
224
+ <summary><b>Gemini</b></summary>
225
+
226
+ | 变量 | 说明 |
227
+ |------|------|
228
+ | `GEMINI_API_KEY` | API Key(如需自定义) |
229
+
230
+ </details>
231
+
232
+ ## 📦 依赖
233
+
234
+ - `bash` 4+
235
+ - `jq`
236
+ - Agent CLI 工具:`claude` / `codex` / `gemini`(至少安装 2 个)
237
+
238
+ ## 📄 License
239
+
240
+ [MIT](LICENSE)