@bolloon/bolloon-agent 0.2.2 → 0.2.3
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.
- package/bin/ipfs +0 -0
- package/dist/agents/parse-tool-call.js +304 -0
- package/dist/agents/pi-sdk.js +190 -286
- package/dist/agents/react-loop.js +86 -0
- package/dist/agents/session-store.js +157 -0
- package/dist/agents/tool-registry.js +136 -0
- package/dist/agents/workflow-pivot-loop.js +40 -0
- package/dist/bollharness/src/index.js +5 -0
- package/dist/bollharness/src/scripts/checks/check_adr_plan_numbering.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_api_types.js +45 -0
- package/dist/bollharness/src/scripts/checks/check_artifact_link.js +146 -0
- package/dist/bollharness/src/scripts/checks/check_bridge_deps.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_bugfix_binding.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_bugfix_binding_ci.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_doc_file_references.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_doc_freshness.js +135 -0
- package/dist/bollharness/src/scripts/checks/check_doc_links.js +31 -0
- package/dist/bollharness/src/scripts/checks/check_file_existence_claims.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_fragment_integrity.js +34 -0
- package/dist/bollharness/src/scripts/checks/check_hook_installed.js +63 -0
- package/dist/bollharness/src/scripts/checks/check_issue_closure.js +41 -0
- package/dist/bollharness/src/scripts/checks/check_mcp_parity.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_security.js +48 -0
- package/dist/bollharness/src/scripts/checks/check_skill_parity.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_versions.js +6 -0
- package/dist/bollharness/src/scripts/checks/finding.js +13 -0
- package/dist/bollharness/src/scripts/checks/next_decision_number.js +20 -0
- package/dist/bollharness/src/scripts/checks/regenerate_magic_docs.js +6 -0
- package/dist/bollharness/src/scripts/ci/detect_rebaseline_triggers.js +8 -0
- package/dist/bollharness/src/scripts/ci/scan_subprocess_cfg.js +8 -0
- package/dist/bollharness/src/scripts/ci/scan_verify_artifacts.js +8 -0
- package/dist/bollharness/src/scripts/ci/scan_yaml_schema.js +8 -0
- package/dist/bollharness/src/scripts/context_router.js +67 -0
- package/dist/bollharness/src/scripts/deploy-guard.js +157 -0
- package/dist/bollharness/src/scripts/guard-feedback.js +192 -0
- package/dist/bollharness/src/scripts/guard_router.js +158 -0
- package/dist/bollharness/src/scripts/hooks/_hook_output.js +6 -0
- package/dist/bollharness/src/scripts/hooks/auto-python3.js +6 -0
- package/dist/bollharness/src/scripts/hooks/deploy-progress-on-session-end.js +6 -0
- package/dist/bollharness/src/scripts/hooks/failure-analyzer.js +6 -0
- package/dist/bollharness/src/scripts/hooks/gate-judgment-inject.js +92 -0
- package/dist/bollharness/src/scripts/hooks/gate-transition-judgment.js +63 -0
- package/dist/bollharness/src/scripts/hooks/inbox-ack.js +6 -0
- package/dist/bollharness/src/scripts/hooks/inbox-inject-on-start.js +6 -0
- package/dist/bollharness/src/scripts/hooks/inbox-validate.js +6 -0
- package/dist/bollharness/src/scripts/hooks/inbox-write-ledger.js +6 -0
- package/dist/bollharness/src/scripts/hooks/initializer-agent.js +6 -0
- package/dist/bollharness/src/scripts/hooks/loop-detection.js +73 -0
- package/dist/bollharness/src/scripts/hooks/owner-guard.js +6 -0
- package/dist/bollharness/src/scripts/hooks/precompact.js +6 -0
- package/dist/bollharness/src/scripts/hooks/review-agent-gatekeeper.js +6 -0
- package/dist/bollharness/src/scripts/hooks/risk-tracker.js +108 -0
- package/dist/bollharness/src/scripts/hooks/sanitize-on-read.js +6 -0
- package/dist/bollharness/src/scripts/hooks/session-reflection.js +7 -0
- package/dist/bollharness/src/scripts/hooks/session-start-magic-docs.js +7 -0
- package/dist/bollharness/src/scripts/hooks/session-start-reset-risk.js +7 -0
- package/dist/bollharness/src/scripts/hooks/session-start-toolkit-reminder.js +7 -0
- package/dist/bollharness/src/scripts/hooks/stop-evaluator.js +157 -0
- package/dist/bollharness/src/scripts/hooks/tool-call-counter.js +6 -0
- package/dist/bollharness/src/scripts/hooks/trace-analyzer.js +10 -0
- package/dist/bollharness/src/scripts/install/install-trust-token.js +7 -0
- package/dist/bollharness/src/scripts/install/multi_project_registry.js +9 -0
- package/dist/bollharness/src/scripts/install/phase2_auto.js +21 -0
- package/dist/bollharness/src/scripts/install/pre_commit_installer.js +6 -0
- package/dist/bollharness/src/scripts/install/tier_selector.js +7 -0
- package/dist/bollharness/src/scripts/install/transcript_miner.js +7 -0
- package/dist/bollharness/src/scripts/lib/claim_patterns.js +10 -0
- package/dist/bollharness/src/scripts/lib/sanitize_patterns.js +12 -0
- package/dist/bollharness/src/scripts/sanitize.js +6 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.js +6 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/createOrder.js +6 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +5 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +6 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +4 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/deploySafe.js +6 -0
- package/dist/constraint-runtime/src/tools/WalletTools/autoPay.js +29 -0
- package/dist/constraint-runtime/src/tools/WalletTools/createWallet.js +10 -0
- package/dist/constraint-runtime/src/tools/WalletTools/getBalance.js +13 -0
- package/dist/constraint-runtime/src/tools/WalletTools/importWallet.js +22 -0
- package/dist/constraint-runtime/src/tools/WalletTools/sendTransaction.js +25 -0
- package/dist/constraint-runtime/src/tools/WalletTools/signMessage.js +10 -0
- package/dist/constraint-runtime/src/tools/WalletTools/transferToken.js +25 -0
- package/dist/electron/config.js.map +1 -0
- package/dist/electron/dialogs.js.map +1 -0
- package/dist/electron/first-run.js.map +1 -0
- package/dist/electron/ipc.js.map +1 -0
- package/dist/electron/logger.js.map +1 -0
- package/dist/electron/main.js.map +1 -0
- package/dist/electron/menu.js.map +1 -0
- package/dist/electron/paths.js.map +1 -0
- package/dist/electron/server.js.map +1 -0
- package/dist/electron/tray.js.map +1 -0
- package/dist/electron/window.js.map +1 -0
- package/dist/electron-preload.js +29 -0
- package/dist/electron-preload.js.map +1 -0
- package/dist/electron.js +5 -0
- package/dist/electron.js.map +1 -0
- package/dist/llm/config-store.js +24 -8
- package/dist/llm/pi-ai.js +33 -19
- package/dist/workflows/collaboration.js +374 -0
- package/dist/workflows/index.js +54 -0
- package/package.json +12 -3
- package/CLAUDE.md +0 -3
- package/build/icon.icns +0 -0
- package/build/icon.ico +0 -0
- package/build/icon.png +0 -0
- package/build/tray.png +0 -0
- package/build/trayTemplate.png +0 -0
- package/ios/App/App/AppDelegate.swift +0 -49
- package/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-512@2x.png +0 -0
- package/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -14
- package/ios/App/App/Assets.xcassets/Contents.json +0 -6
- package/ios/App/App/Assets.xcassets/Splash.imageset/Contents.json +0 -23
- package/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-1.png +0 -0
- package/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-2.png +0 -0
- package/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732.png +0 -0
- package/ios/App/App/Base.lproj/LaunchScreen.storyboard +0 -32
- package/ios/App/App/Base.lproj/Main.storyboard +0 -19
- package/ios/App/App/Info.plist +0 -88
- package/ios/App/App.xcodeproj/project.pbxproj +0 -376
- package/ios/App/App.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/App/CapApp-SPM/Package.swift +0 -25
- package/ios/App/CapApp-SPM/README.md +0 -5
- package/ios/App/CapApp-SPM/Sources/CapApp-SPM/CapApp-SPM.swift +0 -1
- package/ios/debug.xcconfig +0 -1
- package/scripts/auto-evolve-oneshot.sh +0 -155
- package/scripts/auto-evolve-snapshot.sh +0 -136
- package/scripts/build-app-bundle.cjs +0 -170
- package/scripts/build-cli.js +0 -216
- package/scripts/detect-schema-changes.sh +0 -48
- package/scripts/lefthook-helper.sh +0 -69
- package/scripts/postinstall.js +0 -153
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Agent Collaboration Workflow
|
|
3
|
+
*
|
|
4
|
+
* 工作流设计:
|
|
5
|
+
* 1. 命令解析 - 理解用户意图
|
|
6
|
+
* 2. DID查询 - 从IPNS/IPFS查找已注册智能体
|
|
7
|
+
* 3. 协作判断 - 分析是否需要多智能体协作
|
|
8
|
+
* 4. 任务分发 - 发送文档给其他智能体
|
|
9
|
+
* 5. 结果汇总 - 收集并整合协作结果
|
|
10
|
+
*/
|
|
11
|
+
import { AgentProtocol } from '../agents/protocol.js';
|
|
12
|
+
import { p2pNetwork } from '../network/p2p.js';
|
|
13
|
+
import { documentReader } from '../documents/reader.js';
|
|
14
|
+
import { getMinimax } from '../constraints/index.js';
|
|
15
|
+
import { IpfsClient } from '@diap/sdk';
|
|
16
|
+
/**
|
|
17
|
+
* 命令解析器 - 将用户输入解析为结构化意图
|
|
18
|
+
*/
|
|
19
|
+
export class CommandParser {
|
|
20
|
+
collaborationKeywords = ['协作', '合作', '其他', '帮忙', '请教', '团队', '分享', '交给'];
|
|
21
|
+
improvementKeywords = ['改进', '优化', '修改', '完善', '润色', '修正'];
|
|
22
|
+
queryKeywords = ['查看', '列表', '查询', '有哪些', '谁在线'];
|
|
23
|
+
parse(input, context) {
|
|
24
|
+
const lowerInput = input.toLowerCase();
|
|
25
|
+
// 检测是否需要协作
|
|
26
|
+
const needCollaboration = this.collaborationKeywords.some(k => lowerInput.includes(k));
|
|
27
|
+
// 解析动作
|
|
28
|
+
let action = 'query';
|
|
29
|
+
if (lowerInput.includes('改进') || lowerInput.includes('优化') || lowerInput.includes('修改')) {
|
|
30
|
+
action = 'improve';
|
|
31
|
+
}
|
|
32
|
+
else if (lowerInput.includes('总结') || lowerInput.includes('摘要')) {
|
|
33
|
+
action = 'summarize';
|
|
34
|
+
}
|
|
35
|
+
else if (lowerInput.includes('读取') || lowerInput.includes('阅读')) {
|
|
36
|
+
action = 'read';
|
|
37
|
+
}
|
|
38
|
+
else if (lowerInput.includes('汇报') || lowerInput.includes('报告')) {
|
|
39
|
+
action = 'report';
|
|
40
|
+
}
|
|
41
|
+
else if (this.queryKeywords.some(k => lowerInput.includes(k))) {
|
|
42
|
+
action = 'query';
|
|
43
|
+
}
|
|
44
|
+
// 提取目标文件/主题
|
|
45
|
+
const targetMatch = input.match(/[\w\.\/]+\.(md|txt|pdf|docx)/i);
|
|
46
|
+
const target = targetMatch ? targetMatch[0] : undefined;
|
|
47
|
+
// 提取需求描述
|
|
48
|
+
const requirements = this.extractRequirements(input);
|
|
49
|
+
// 识别建议的智能体(如果有)
|
|
50
|
+
const suggestedAgents = this.extractAgentNames(input);
|
|
51
|
+
return {
|
|
52
|
+
action,
|
|
53
|
+
target,
|
|
54
|
+
requirements,
|
|
55
|
+
context: context || input,
|
|
56
|
+
needCollaboration,
|
|
57
|
+
suggestedAgents
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
extractRequirements(input) {
|
|
61
|
+
// 查找引号内的内容或特定模式
|
|
62
|
+
const quotes = input.match(/["'""]([^""']+)[""'"]/);
|
|
63
|
+
if (quotes)
|
|
64
|
+
return quotes[1];
|
|
65
|
+
const afterKeywords = input.match(/(?:改进|优化|修改|要求|需要)[::]\s*(.+)/i);
|
|
66
|
+
if (afterKeywords)
|
|
67
|
+
return afterKeywords[1];
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
extractAgentNames(input) {
|
|
71
|
+
const names = input.match(/[@@]\w+/g);
|
|
72
|
+
return names ? names.map(n => n.substring(1)) : undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* DID注册表 - 管理已知智能体的DID信息
|
|
77
|
+
*/
|
|
78
|
+
export class DIDRegistry {
|
|
79
|
+
agents = new Map();
|
|
80
|
+
ipfsClient;
|
|
81
|
+
constructor(ipfsApiUrl = 'http://127.0.0.1:5001') {
|
|
82
|
+
this.ipfsClient = new IpfsClient(ipfsApiUrl, null);
|
|
83
|
+
}
|
|
84
|
+
async registerAgent(agent) {
|
|
85
|
+
this.agents.set(agent.did, {
|
|
86
|
+
...agent,
|
|
87
|
+
lastSeen: Date.now()
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
async unregisterAgent(did) {
|
|
91
|
+
this.agents.delete(did);
|
|
92
|
+
}
|
|
93
|
+
getAgent(did) {
|
|
94
|
+
return this.agents.get(did);
|
|
95
|
+
}
|
|
96
|
+
getAllAgents() {
|
|
97
|
+
return Array.from(this.agents.values());
|
|
98
|
+
}
|
|
99
|
+
getOnlineAgents() {
|
|
100
|
+
const now = Date.now();
|
|
101
|
+
const timeout = 5 * 60 * 1000; // 5分钟超时
|
|
102
|
+
return this.getAllAgents().filter(a => a.lastSeen && (now - a.lastSeen) < timeout);
|
|
103
|
+
}
|
|
104
|
+
async resolveDIDFromIPNS(ipnsName) {
|
|
105
|
+
try {
|
|
106
|
+
const cid = await this.ipfsClient.resolveIpns(ipnsName);
|
|
107
|
+
const content = await this.ipfsClient.get(cid);
|
|
108
|
+
const doc = JSON.parse(content);
|
|
109
|
+
return {
|
|
110
|
+
did: doc.id,
|
|
111
|
+
name: doc.name || doc.id,
|
|
112
|
+
ipnsName
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error(`Failed to resolve DID from IPNS ${ipnsName}:`, error);
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async discoverAgents() {
|
|
121
|
+
const discovered = [];
|
|
122
|
+
const peers = p2pNetwork.getPeers();
|
|
123
|
+
for (const peerId of peers) {
|
|
124
|
+
// 尝试从已知IPNS名称列表中解析
|
|
125
|
+
// 实际实现中应该通过某种服务发现机制
|
|
126
|
+
const agent = this.getAgentByPeerId(peerId);
|
|
127
|
+
if (agent) {
|
|
128
|
+
discovered.push(agent);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return discovered;
|
|
132
|
+
}
|
|
133
|
+
getAgentByPeerId(peerId) {
|
|
134
|
+
for (const agent of this.agents.values()) {
|
|
135
|
+
if (agent.peerId === peerId) {
|
|
136
|
+
return agent;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 协作决策器 - 判断是否需要多智能体协作
|
|
144
|
+
*/
|
|
145
|
+
export class CollaborationDecider {
|
|
146
|
+
threshold = 0.7;
|
|
147
|
+
async shouldCollaborate(intent, qualityScore) {
|
|
148
|
+
// 明确要求协作
|
|
149
|
+
if (intent.needCollaboration)
|
|
150
|
+
return true;
|
|
151
|
+
// 质量问题,建议协作改进
|
|
152
|
+
if (qualityScore && qualityScore < this.threshold)
|
|
153
|
+
return true;
|
|
154
|
+
// 复杂任务建议协作
|
|
155
|
+
if (intent.action === 'improve' && intent.requirements) {
|
|
156
|
+
if (intent.requirements.length > 200)
|
|
157
|
+
return true; // 复杂需求
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
selectAgentsForTask(intent, availableAgents) {
|
|
162
|
+
if (!availableAgents.length)
|
|
163
|
+
return [];
|
|
164
|
+
// 如果用户指定了智能体
|
|
165
|
+
if (intent.suggestedAgents?.length) {
|
|
166
|
+
return availableAgents.filter(a => intent.suggestedAgents.some(name => a.name.includes(name) || a.did.includes(name)));
|
|
167
|
+
}
|
|
168
|
+
// 根据任务类型选择
|
|
169
|
+
switch (intent.action) {
|
|
170
|
+
case 'improve':
|
|
171
|
+
// 改进任务可以选多个智能体并行处理
|
|
172
|
+
return availableAgents.slice(0, 3);
|
|
173
|
+
case 'summarize':
|
|
174
|
+
// 摘要任务选一个即可
|
|
175
|
+
return [availableAgents[0]];
|
|
176
|
+
default:
|
|
177
|
+
return availableAgents.slice(0, 2);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 任务分发器 - 管理多智能体任务分发和结果收集
|
|
183
|
+
*/
|
|
184
|
+
export class TaskDispatcher {
|
|
185
|
+
protocol;
|
|
186
|
+
pendingTasks = new Map();
|
|
187
|
+
constructor(protocol) {
|
|
188
|
+
this.protocol = protocol;
|
|
189
|
+
}
|
|
190
|
+
async dispatchSummarize(intent, target, agents) {
|
|
191
|
+
const taskId = `summarize-${Date.now()}`;
|
|
192
|
+
this.pendingTasks.set(taskId, { intent, agents });
|
|
193
|
+
// 广播任务给选定的智能体
|
|
194
|
+
for (const agent of agents) {
|
|
195
|
+
const task = {
|
|
196
|
+
taskId,
|
|
197
|
+
action: 'summarize',
|
|
198
|
+
target,
|
|
199
|
+
context: intent.context
|
|
200
|
+
};
|
|
201
|
+
await this.protocol.sendTask(task, agent.peerId || agent.did);
|
|
202
|
+
}
|
|
203
|
+
return taskId;
|
|
204
|
+
}
|
|
205
|
+
async dispatchImprove(intent, target, agents) {
|
|
206
|
+
const taskId = `improve-${Date.now()}`;
|
|
207
|
+
this.pendingTasks.set(taskId, { intent, agents });
|
|
208
|
+
// 向每个智能体发送改进请求
|
|
209
|
+
for (const agent of agents) {
|
|
210
|
+
await this.protocol.requestImprove(target, intent.requirements || '', agent.peerId);
|
|
211
|
+
}
|
|
212
|
+
return taskId;
|
|
213
|
+
}
|
|
214
|
+
cancelTask(taskId) {
|
|
215
|
+
this.pendingTasks.delete(taskId);
|
|
216
|
+
}
|
|
217
|
+
getPendingTasks() {
|
|
218
|
+
return Array.from(this.pendingTasks.keys());
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* 多智能体协作工作流 - 主协调器
|
|
223
|
+
*/
|
|
224
|
+
export class MultiAgentWorkflow {
|
|
225
|
+
parser;
|
|
226
|
+
registry;
|
|
227
|
+
decider;
|
|
228
|
+
dispatcher;
|
|
229
|
+
protocol;
|
|
230
|
+
constructor() {
|
|
231
|
+
this.parser = new CommandParser();
|
|
232
|
+
this.registry = new DIDRegistry();
|
|
233
|
+
this.decider = new CollaborationDecider();
|
|
234
|
+
this.protocol = new AgentProtocol('local', 'coordinator');
|
|
235
|
+
this.dispatcher = new TaskDispatcher(this.protocol);
|
|
236
|
+
this.setupResultHandlers();
|
|
237
|
+
}
|
|
238
|
+
setupResultHandlers() {
|
|
239
|
+
// 处理返回结果
|
|
240
|
+
p2pNetwork.onMessage('result', async (data, from) => {
|
|
241
|
+
const msg = JSON.parse(new TextDecoder().decode(data));
|
|
242
|
+
const result = JSON.parse(msg.payload);
|
|
243
|
+
console.log(`\n📥 收到来自 ${from} 的结果:`);
|
|
244
|
+
console.log(` 质量: ${(result.qualityScore * 10).toFixed(1)}/10`);
|
|
245
|
+
console.log(` 摘要: ${result.result?.substring(0, 100)}...`);
|
|
246
|
+
});
|
|
247
|
+
// 处理改进结果
|
|
248
|
+
p2pNetwork.onMessage('improved', async (data, from) => {
|
|
249
|
+
const msg = JSON.parse(new TextDecoder().decode(data));
|
|
250
|
+
const result = JSON.parse(msg.payload);
|
|
251
|
+
console.log(`\n✨ 收到来自 ${from} 的改进结果:`);
|
|
252
|
+
console.log(` 质量: ${(result.qualityScore * 10).toFixed(1)}/10`);
|
|
253
|
+
console.log(` 自动发送: ${result.shouldAutoSend ? '是' : '否'}`);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 处理用户输入的完整流程
|
|
258
|
+
*/
|
|
259
|
+
async process(input, context) {
|
|
260
|
+
// 1. 命令解析
|
|
261
|
+
const intent = this.parser.parse(input, context);
|
|
262
|
+
console.log(`\n🔍 解析命令:`, intent);
|
|
263
|
+
// 2. 发现可用的智能体
|
|
264
|
+
const agents = await this.registry.discoverAgents();
|
|
265
|
+
console.log(`\n👥 发现 ${agents.length} 个在线智能体`);
|
|
266
|
+
// 3. 协作决策
|
|
267
|
+
const shouldCollaborate = await this.decider.shouldCollaborate(intent);
|
|
268
|
+
console.log(`\n🤔 协作决策: ${shouldCollaborate ? '需要协作' : '独立完成'}`);
|
|
269
|
+
if (!shouldCollaborate) {
|
|
270
|
+
// 独立执行
|
|
271
|
+
return this.executeIndependently(intent);
|
|
272
|
+
}
|
|
273
|
+
// 4. 选择执行智能体
|
|
274
|
+
const selectedAgents = this.decider.selectAgentsForTask(intent, agents);
|
|
275
|
+
console.log(`\n🎯 选中 ${selectedAgents.length} 个智能体执行`);
|
|
276
|
+
if (selectedAgents.length === 0) {
|
|
277
|
+
// 没有可用智能体,降级为独立执行
|
|
278
|
+
console.log(`\n⚠️ 没有可用智能体,降级为独立执行`);
|
|
279
|
+
return this.executeIndependently(intent);
|
|
280
|
+
}
|
|
281
|
+
// 5. 分发任务
|
|
282
|
+
return this.dispatchToAgents(intent, selectedAgents);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* 独立执行(无需协作)
|
|
286
|
+
*/
|
|
287
|
+
async executeIndependently(intent) {
|
|
288
|
+
try {
|
|
289
|
+
let result;
|
|
290
|
+
let qualityScore = 0.5;
|
|
291
|
+
if (intent.action === 'read' || intent.action === 'summarize') {
|
|
292
|
+
if (!intent.target) {
|
|
293
|
+
return { success: false, collaborated: false, agents: [], error: '缺少目标文件' };
|
|
294
|
+
}
|
|
295
|
+
const content = await documentReader.read(intent.target);
|
|
296
|
+
const llm = getMinimax();
|
|
297
|
+
const summarizeResult = await llm.summarize(content.text, intent.context);
|
|
298
|
+
result = summarizeResult.summary;
|
|
299
|
+
qualityScore = summarizeResult.qualityScore;
|
|
300
|
+
}
|
|
301
|
+
else if (intent.action === 'improve' && intent.target) {
|
|
302
|
+
const content = await documentReader.read(intent.target);
|
|
303
|
+
const llm = getMinimax();
|
|
304
|
+
result = await llm.improveContent(content.text, intent.requirements || '', intent.context);
|
|
305
|
+
qualityScore = llm.estimateQuality(content.text, result);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
return { success: false, collaborated: false, agents: [], error: '未知动作' };
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
success: true,
|
|
312
|
+
collaborated: false,
|
|
313
|
+
agents: [],
|
|
314
|
+
result,
|
|
315
|
+
qualityScore
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
return {
|
|
320
|
+
success: false,
|
|
321
|
+
collaborated: false,
|
|
322
|
+
agents: [],
|
|
323
|
+
error: String(error)
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* 分发给多个智能体协作执行
|
|
329
|
+
*/
|
|
330
|
+
async dispatchToAgents(intent, agents) {
|
|
331
|
+
try {
|
|
332
|
+
if (!intent.target) {
|
|
333
|
+
return { success: false, collaborated: true, agents, error: '缺少目标文件' };
|
|
334
|
+
}
|
|
335
|
+
let taskId;
|
|
336
|
+
if (intent.action === 'summarize' || intent.action === 'read') {
|
|
337
|
+
taskId = await this.dispatcher.dispatchSummarize(intent, intent.target, agents);
|
|
338
|
+
}
|
|
339
|
+
else if (intent.action === 'improve') {
|
|
340
|
+
taskId = await this.dispatcher.dispatchImprove(intent, intent.target, agents);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
return { success: false, collaborated: true, agents, error: '不支持的协作动作' };
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
success: true,
|
|
347
|
+
collaborated: true,
|
|
348
|
+
agents,
|
|
349
|
+
taskId,
|
|
350
|
+
result: `任务已分发,等待结果...`
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
return {
|
|
355
|
+
success: false,
|
|
356
|
+
collaborated: true,
|
|
357
|
+
agents,
|
|
358
|
+
error: String(error)
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* 查询当前在线的智能体
|
|
364
|
+
*/
|
|
365
|
+
async listAgents() {
|
|
366
|
+
return this.registry.discoverAgents();
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* 注册一个新智能体
|
|
370
|
+
*/
|
|
371
|
+
async registerAgent(agent) {
|
|
372
|
+
await this.registry.registerAgent(agent);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Agent Collaboration Workflows
|
|
3
|
+
*
|
|
4
|
+
* 工作流设计文档:
|
|
5
|
+
*
|
|
6
|
+
* ┌─────────────────────────────────────────────────────────────┐
|
|
7
|
+
* │ 用户输入 │
|
|
8
|
+
* └─────────────────────────────────────────────────────────────┘
|
|
9
|
+
* │
|
|
10
|
+
* ▼
|
|
11
|
+
* ┌─────────────────────────────────────────────────────────────┐
|
|
12
|
+
* │ 命令解析器 (CommandParser) │
|
|
13
|
+
* │ - 识别动作: read/summarize/improve/query/collaborate │
|
|
14
|
+
* │ - 提取目标文件、需求描述 │
|
|
15
|
+
* │ - 检测协作关键词 │
|
|
16
|
+
* └─────────────────────────────────────────────────────────────┘
|
|
17
|
+
* │
|
|
18
|
+
* ▼
|
|
19
|
+
* ┌─────────────────────────────────────────────────────────────┐
|
|
20
|
+
* │ DID注册表 (DIDRegistry) │
|
|
21
|
+
* │ - 管理已知智能体的DID信息 │
|
|
22
|
+
* │ - 从IPNS解析其他智能体DID文档 │
|
|
23
|
+
* │ - 追踪在线状态 │
|
|
24
|
+
* └─────────────────────────────────────────────────────────────┘
|
|
25
|
+
* │
|
|
26
|
+
* ▼
|
|
27
|
+
* ┌─────────────────────────────────────────────────────────────┐
|
|
28
|
+
* │ 协作决策器 (CollaborationDecider) │
|
|
29
|
+
* │ - 基于任务复杂度、关键词、质量评分决策 │
|
|
30
|
+
* │ - 选择合适的执行智能体 │
|
|
31
|
+
* └─────────────────────────────────────────────────────────────┘
|
|
32
|
+
* │
|
|
33
|
+
* ┌─────────────┴─────────────┐
|
|
34
|
+
* │ │
|
|
35
|
+
* ▼ ▼
|
|
36
|
+
* ┌─────────────────┐ ┌─────────────────┐
|
|
37
|
+
* │ 独立执行 │ │ 多智能体协作 │
|
|
38
|
+
* │ - 直接处理 │ │ │
|
|
39
|
+
* │ - 返回结果 │ │ - 分发任务 │
|
|
40
|
+
* └─────────────────┘ │ - 收集结果 │
|
|
41
|
+
* │ - 汇总汇报 │
|
|
42
|
+
* └─────────────────┘
|
|
43
|
+
* │
|
|
44
|
+
* ▼
|
|
45
|
+
* ┌─────────────────┐
|
|
46
|
+
* │ 任务分发器 │
|
|
47
|
+
* │ (TaskDispatcher) │
|
|
48
|
+
* │ │
|
|
49
|
+
* │ - Protocol发送 │
|
|
50
|
+
* │ - 任务追踪 │
|
|
51
|
+
* │ - 结果收集 │
|
|
52
|
+
* └─────────────────┘
|
|
53
|
+
*/
|
|
54
|
+
export { CommandParser, DIDRegistry, CollaborationDecider, TaskDispatcher, MultiAgentWorkflow } from './collaboration.js';
|
package/package.json
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolloon/bolloon-agent",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "P2P AI Document Agent - 全局安装后执行 `bolloon` 启动产品",
|
|
6
|
-
"main": "dist/cli.js",
|
|
7
|
-
"author": "Bolloon
|
|
6
|
+
"main": "dist/cli-entry.js",
|
|
7
|
+
"author": "Bolloon Leo",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/logos-42/bolloon.git"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"bin"
|
|
16
|
+
],
|
|
8
17
|
"bin": {
|
|
9
18
|
"bolloon": "./bin/bolloon-cli.cjs"
|
|
10
19
|
},
|
package/CLAUDE.md
DELETED
package/build/icon.icns
DELETED
|
Binary file
|
package/build/icon.ico
DELETED
|
Binary file
|
package/build/icon.png
DELETED
|
Binary file
|
package/build/tray.png
DELETED
|
Binary file
|
package/build/trayTemplate.png
DELETED
|
Binary file
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import UIKit
|
|
2
|
-
import Capacitor
|
|
3
|
-
|
|
4
|
-
@UIApplicationMain
|
|
5
|
-
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
6
|
-
|
|
7
|
-
var window: UIWindow?
|
|
8
|
-
|
|
9
|
-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
10
|
-
// Override point for customization after application launch.
|
|
11
|
-
return true
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
func applicationWillResignActive(_ application: UIApplication) {
|
|
15
|
-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
|
16
|
-
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
func applicationDidEnterBackground(_ application: UIApplication) {
|
|
20
|
-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
|
21
|
-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func applicationWillEnterForeground(_ application: UIApplication) {
|
|
25
|
-
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
func applicationDidBecomeActive(_ application: UIApplication) {
|
|
29
|
-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
func applicationWillTerminate(_ application: UIApplication) {
|
|
33
|
-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
|
37
|
-
// Called when the app was launched with a url. Feel free to add additional processing here,
|
|
38
|
-
// but if you want the App API to support tracking app url opens, make sure to keep this call
|
|
39
|
-
return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
|
|
43
|
-
// Called when the app was launched with an activity, including Universal Links.
|
|
44
|
-
// Feel free to add additional processing here, but if you want the App API to support
|
|
45
|
-
// tracking app url opens, make sure to keep this call
|
|
46
|
-
return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
}
|
|
Binary file
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"images" : [
|
|
3
|
-
{
|
|
4
|
-
"idiom" : "universal",
|
|
5
|
-
"filename" : "splash-2732x2732-2.png",
|
|
6
|
-
"scale" : "1x"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"idiom" : "universal",
|
|
10
|
-
"filename" : "splash-2732x2732-1.png",
|
|
11
|
-
"scale" : "2x"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"idiom" : "universal",
|
|
15
|
-
"filename" : "splash-2732x2732.png",
|
|
16
|
-
"scale" : "3x"
|
|
17
|
-
}
|
|
18
|
-
],
|
|
19
|
-
"info" : {
|
|
20
|
-
"version" : 1,
|
|
21
|
-
"author" : "xcode"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17132" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
|
3
|
-
<device id="retina4_7" orientation="portrait" appearance="light"/>
|
|
4
|
-
<dependencies>
|
|
5
|
-
<deployment identifier="iOS"/>
|
|
6
|
-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17105"/>
|
|
7
|
-
<capability name="System colors in document resources" minToolsVersion="11.0"/>
|
|
8
|
-
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
|
9
|
-
</dependencies>
|
|
10
|
-
<scenes>
|
|
11
|
-
<!--View Controller-->
|
|
12
|
-
<scene sceneID="EHf-IW-A2E">
|
|
13
|
-
<objects>
|
|
14
|
-
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
|
15
|
-
<imageView key="view" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Splash" id="snD-IY-ifK">
|
|
16
|
-
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
|
17
|
-
<autoresizingMask key="autoresizingMask"/>
|
|
18
|
-
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
|
19
|
-
</imageView>
|
|
20
|
-
</viewController>
|
|
21
|
-
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
|
22
|
-
</objects>
|
|
23
|
-
<point key="canvasLocation" x="53" y="375"/>
|
|
24
|
-
</scene>
|
|
25
|
-
</scenes>
|
|
26
|
-
<resources>
|
|
27
|
-
<image name="Splash" width="1366" height="1366"/>
|
|
28
|
-
<systemColor name="systemBackgroundColor">
|
|
29
|
-
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
|
30
|
-
</systemColor>
|
|
31
|
-
</resources>
|
|
32
|
-
</document>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14111" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
|
3
|
-
<device id="retina4_7" orientation="portrait">
|
|
4
|
-
<adaptation id="fullscreen"/>
|
|
5
|
-
</device>
|
|
6
|
-
<dependencies>
|
|
7
|
-
<deployment identifier="iOS"/>
|
|
8
|
-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
|
|
9
|
-
</dependencies>
|
|
10
|
-
<scenes>
|
|
11
|
-
<!--Bridge View Controller-->
|
|
12
|
-
<scene sceneID="tne-QT-ifu">
|
|
13
|
-
<objects>
|
|
14
|
-
<viewController id="BYZ-38-t0r" customClass="CAPBridgeViewController" customModule="Capacitor" sceneMemberID="viewController"/>
|
|
15
|
-
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
|
16
|
-
</objects>
|
|
17
|
-
</scene>
|
|
18
|
-
</scenes>
|
|
19
|
-
</document>
|