@bolloon/bolloon-agent 0.1.1 → 0.1.2
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/bolloon-cli.cjs +157 -0
- package/bin/bolloon-daemon.sh +207 -0
- package/bin/bolloon.cmd +11 -0
- package/dist/agents/constraint-layer.js +10 -15
- package/dist/agents/pi-sdk.js +433 -106
- package/dist/agents/protocol.js +82 -1
- package/dist/agents/subagent-manager.js +2 -2
- package/dist/agents/workflow-engine.js +15 -20
- package/dist/agents/workflow-pivot-loop.js +541 -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/bollharness-integration/channel-judgment-engine.js +530 -0
- package/dist/bollharness-integration/context-chain-router.js +383 -0
- package/dist/bollharness-integration/context-router-judgment.js +13 -21
- package/dist/bollharness-integration/context-router.js +22 -64
- package/dist/bollharness-integration/gate-state-machine.js +14 -19
- package/dist/bollharness-integration/gate-transition-hooks.js +16 -61
- package/dist/bollharness-integration/guard-checker.js +21 -68
- package/dist/bollharness-integration/index.js +14 -124
- package/dist/bollharness-integration/integration.js +13 -20
- package/dist/bollharness-integration/llm-judgment-engine.js +569 -0
- package/dist/bollharness-integration/skill-adapter.js +18 -64
- package/dist/cli-entry.js +261 -0
- package/dist/constraint-runtime/src/commands.js +17 -7
- package/dist/constraint-runtime/src/constraint/budget.js +1 -6
- package/dist/constraint-runtime/src/constraint/permission.js +1 -6
- package/dist/constraint-runtime/src/models.js +1 -3
- package/dist/constraint-runtime/src/tools.js +17 -7
- package/dist/constraints/index.js +1 -7
- package/dist/documents/reader.js +8 -49
- package/dist/heartbeat/DaemonManager.js +242 -0
- package/dist/heartbeat/HealthMonitor.js +285 -0
- package/dist/heartbeat/StartupVerifier.js +205 -0
- package/dist/heartbeat/Watchdog.js +168 -0
- package/dist/heartbeat/index.js +84 -0
- package/dist/heartbeat/types.js +5 -0
- package/dist/index.js +381 -28
- package/dist/llm/config-store.js +31 -57
- package/dist/llm/llm-judgment-client.js +389 -0
- package/dist/llm/pi-ai.js +9 -52
- package/dist/network/agent-network.js +46 -90
- package/dist/network/hybrid-messenger.js +125 -0
- package/dist/network/iroh-bootstrap.js +38 -0
- package/dist/network/iroh-discovery.js +145 -0
- package/dist/network/iroh-integration.js +9 -16
- package/dist/network/iroh-transport.js +10 -48
- package/dist/network/p2p.js +23 -62
- package/dist/network/storage/adapters/json-adapter.js +4 -42
- package/dist/network/storage/index.js +147 -0
- package/dist/network/storage/types.js +14 -0
- package/dist/pi-ecosystem/index.js +233 -0
- package/dist/pi-ecosystem-colony/index.js +29 -90
- package/dist/pi-ecosystem-goals/index.js +20 -74
- package/dist/pi-ecosystem-judgment/decision.js +29 -47
- package/dist/pi-ecosystem-judgment/distillation.js +16 -29
- package/dist/pi-ecosystem-judgment/human-value-store.js +13 -60
- package/dist/pi-ecosystem-judgment/index.js +21 -74
- package/dist/pi-ecosystem-judgment/value-injection.js +26 -72
- package/dist/pi-ecosystem-mcp/index.js +24 -78
- package/dist/pi-ecosystem-subagents/index.js +20 -69
- package/dist/social/ant-colony/AdaptiveHeartbeat.js +3 -8
- package/dist/social/ant-colony/PheromoneEngine.js +11 -49
- package/dist/social/ant-colony/index.js +6 -0
- package/dist/social/ant-colony/types.js +4 -8
- package/dist/social/channels/ChannelManager.js +8 -46
- package/dist/social/channels/DiapChannelBridge.js +9 -47
- package/dist/social/channels/InterestMatcher.js +2 -7
- package/dist/social/channels/channel-agent-session.js +309 -0
- package/dist/social/channels/channel-heartbeat-agent.js +494 -0
- package/dist/social/channels/diap-doc-parser.js +204 -0
- package/dist/social/channels/harness-workflow-integrator.js +446 -0
- package/dist/social/channels/index.js +9 -0
- package/dist/social/channels/types.js +3 -7
- package/dist/social/global-shared-context.js +6 -47
- package/dist/social/heartbeat.js +29 -72
- package/dist/social/persona/enhanced-persona.js +299 -0
- package/dist/web/client.js +302 -136
- package/dist/web/components/p2p/index.js +159 -9
- package/dist/web/components/p2p/p2p-connection.js +136 -0
- package/dist/web/components/p2p/p2p-manager.js +24 -0
- package/dist/web/components/p2p/p2p-store-memory.js +1 -1
- package/dist/web/components/p2p/types.js +7 -0
- package/dist/web/index.html +5 -0
- package/dist/web/style.css +118 -0
- package/package.json +12 -6
- package/scripts/build-cli.js +206 -0
- package/scripts/postinstall.js +153 -0
- package/src/agents/pi-sdk.ts +347 -28
- package/src/agents/protocol.ts +95 -1
- package/src/agents/workflow-pivot-loop.ts +674 -0
- package/src/bollharness/CLAUDE.md +73 -0
- package/src/bollharness/README.md +143 -0
- package/src/bollharness/README.zh-CN.md +131 -0
- package/src/bollharness/reference/boll-reference/scripts/hooks/stop-evaluator.md +57 -0
- package/src/bollharness/scripts/context-fragments/artifact-linkage.md +14 -0
- package/src/bollharness/scripts/context-fragments/auth-consumers.md +17 -0
- package/src/bollharness/scripts/context-fragments/bridge-constitution.md +13 -0
- package/src/bollharness/scripts/context-fragments/catalyst-distributed.md +18 -0
- package/src/bollharness/scripts/context-fragments/closure-checklist.md +13 -0
- package/src/bollharness/scripts/context-fragments/contract-consumers.md +15 -0
- package/src/bollharness/scripts/context-fragments/db-shared-structures.md +15 -0
- package/src/bollharness/scripts/context-fragments/fixed-three-layers.md +19 -0
- package/src/bollharness/scripts/context-fragments/general-dev-principles.md +11 -0
- package/src/bollharness/scripts/context-fragments/issue-first.md +8 -0
- package/src/bollharness/scripts/context-fragments/mcp-parity.md +16 -0
- package/src/bollharness/scripts/context-fragments/pi-agent-operations.md +108 -0
- package/src/bollharness/scripts/context-fragments/protocol-consumers.md +15 -0
- package/src/bollharness/scripts/context-fragments/run-events-consumers.md +15 -0
- package/src/bollharness/scripts/context-fragments/scene-fidelity.md +13 -0
- package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +15 -0
- package/src/bollharness/scripts/context-fragments/two-language.md +15 -0
- package/src/bollharness/scripts/context-fragments/version-sources.md +14 -0
- package/src/bollharness/scripts/hooks/stop-evaluator.md +83 -0
- package/src/bollharness/templates/scaffold/CLAUDE.md +89 -0
- package/src/cli-entry.ts +304 -0
- package/src/heartbeat/DaemonManager.ts +283 -0
- package/src/heartbeat/HealthMonitor.ts +316 -0
- package/src/heartbeat/StartupVerifier.ts +223 -0
- package/src/heartbeat/Watchdog.ts +198 -0
- package/src/heartbeat/index.ts +108 -0
- package/src/heartbeat/types.ts +82 -0
- package/src/llm/config-store.ts +23 -5
- package/src/network/iroh-transport.ts +3 -3
- package/src/web/client.js +302 -136
- package/src/web/components/p2p/P2PModal.tsx +91 -3
- package/src/web/components/p2p/index.ts +171 -9
- package/src/web/components/p2p/p2p-connection.ts +153 -1
- package/src/web/components/p2p/p2p-manager.ts +39 -1
- package/src/web/components/p2p/p2p-store-memory.ts +1 -1
- package/src/web/components/p2p/p2p-tools.ts +315 -0
- package/src/web/components/p2p/types.ts +58 -0
- package/src/web/design.md +99 -0
- package/src/web/index.html +5 -0
- package/src/web/server.ts +353 -36
- package/src/web/style.css +118 -0
- package/tsconfig.cli.json +16 -0
- package/tsconfig.electron.json +1 -1
- package/tsconfig.json +1 -2
- package/dist/web/server.js +0 -1647
- package/dist/web/server.js.map +0 -1
|
@@ -1,51 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* ChannelManager - 频道管理器
|
|
4
3
|
*
|
|
5
4
|
* 管理本地频道,与 Diap 桥接协同工作
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.ChannelManager = void 0;
|
|
42
|
-
const fs = __importStar(require("fs/promises"));
|
|
43
|
-
const path = __importStar(require("path"));
|
|
44
|
-
const types_js_1 = require("./types.js");
|
|
45
|
-
const types_js_2 = require("./types.js");
|
|
6
|
+
import * as fs from 'fs/promises';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { ChannelType } from './types.js';
|
|
9
|
+
import { DEFAULT_CHANNEL_CONFIG } from './types.js';
|
|
46
10
|
const CHANNELS_PATH = path.join(process.env.HOME || '/tmp', '.bolloon', 'channels', 'my-channels.json');
|
|
47
11
|
const DISCOVERED_PATH = path.join(process.env.HOME || '/tmp', '.bolloon', 'channels', 'discovered.json');
|
|
48
|
-
class ChannelManager {
|
|
12
|
+
export class ChannelManager {
|
|
49
13
|
channels = new Map();
|
|
50
14
|
discoveredChannels = new Map();
|
|
51
15
|
ownChannelId = null;
|
|
@@ -120,7 +84,7 @@ class ChannelManager {
|
|
|
120
84
|
if (ownChannel) {
|
|
121
85
|
this.broadcastChannel(ownChannel).catch(console.error);
|
|
122
86
|
}
|
|
123
|
-
},
|
|
87
|
+
}, DEFAULT_CHANNEL_CONFIG.broadcastInterval);
|
|
124
88
|
}
|
|
125
89
|
/**
|
|
126
90
|
* 创建新频道
|
|
@@ -188,7 +152,7 @@ class ChannelManager {
|
|
|
188
152
|
// 创建本地记录(不包含成员详情)
|
|
189
153
|
const discoveredChannel = {
|
|
190
154
|
id: channelId,
|
|
191
|
-
type:
|
|
155
|
+
type: ChannelType.CAPABILITY,
|
|
192
156
|
name: channelName,
|
|
193
157
|
topic: channelTopic,
|
|
194
158
|
requiredCapabilities: channelCapabilities,
|
|
@@ -321,7 +285,7 @@ class ChannelManager {
|
|
|
321
285
|
* 广播频道存在
|
|
322
286
|
*/
|
|
323
287
|
async broadcastChannel(channel) {
|
|
324
|
-
const { p2pNetwork } = await
|
|
288
|
+
const { p2pNetwork } = await import('../../network/p2p.js');
|
|
325
289
|
const announcement = {
|
|
326
290
|
type: 'channel_announce',
|
|
327
291
|
channelId: channel.id,
|
|
@@ -440,5 +404,3 @@ class ChannelManager {
|
|
|
440
404
|
return did;
|
|
441
405
|
}
|
|
442
406
|
}
|
|
443
|
-
exports.ChannelManager = ChannelManager;
|
|
444
|
-
//# sourceMappingURL=ChannelManager.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* DiapChannelBridge - 基于 Diap 去中心化协议的对外社交频道系统
|
|
4
3
|
*
|
|
@@ -7,47 +6,12 @@
|
|
|
7
6
|
* 2. 通过 Diap 发现具有特定能力的外部智能体
|
|
8
7
|
* 3. 跨频道智能体消息路由和通信
|
|
9
8
|
*/
|
|
10
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(o, k2, desc);
|
|
17
|
-
}) : (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
o[k2] = m[k];
|
|
20
|
-
}));
|
|
21
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
-
}) : function(o, v) {
|
|
24
|
-
o["default"] = v;
|
|
25
|
-
});
|
|
26
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
-
var ownKeys = function(o) {
|
|
28
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
-
var ar = [];
|
|
30
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
return ownKeys(o);
|
|
34
|
-
};
|
|
35
|
-
return function (mod) {
|
|
36
|
-
if (mod && mod.__esModule) return mod;
|
|
37
|
-
var result = {};
|
|
38
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
-
__setModuleDefault(result, mod);
|
|
40
|
-
return result;
|
|
41
|
-
};
|
|
42
|
-
})();
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.DiapChannelBridge = void 0;
|
|
45
9
|
const DEFAULT_CONFIG = {
|
|
46
10
|
discoveryInterval: 60 * 1000,
|
|
47
11
|
broadcastInterval: 30 * 1000,
|
|
48
12
|
maxDiscoveredAgents: 100
|
|
49
13
|
};
|
|
50
|
-
class DiapChannelBridge {
|
|
14
|
+
export class DiapChannelBridge {
|
|
51
15
|
agentAuthManager = null;
|
|
52
16
|
keyPair = null;
|
|
53
17
|
sessionProvider;
|
|
@@ -78,7 +42,7 @@ class DiapChannelBridge {
|
|
|
78
42
|
}
|
|
79
43
|
async registerMessageHandlers() {
|
|
80
44
|
try {
|
|
81
|
-
const { p2pNetwork } = await
|
|
45
|
+
const { p2pNetwork } = await import('../../network/p2p.js');
|
|
82
46
|
// 处理频道公告
|
|
83
47
|
p2pNetwork.onMessage('channel_announce', async (data, from) => {
|
|
84
48
|
try {
|
|
@@ -168,7 +132,7 @@ class DiapChannelBridge {
|
|
|
168
132
|
return [];
|
|
169
133
|
try {
|
|
170
134
|
// 通过 P2P 网络发送发现请求
|
|
171
|
-
const { p2pNetwork } = await
|
|
135
|
+
const { p2pNetwork } = await import('../../network/p2p.js');
|
|
172
136
|
const request = {
|
|
173
137
|
type: 'discovery_request',
|
|
174
138
|
requesterDid: this.getOwnDid(),
|
|
@@ -236,7 +200,7 @@ class DiapChannelBridge {
|
|
|
236
200
|
if (!hasMatch)
|
|
237
201
|
return;
|
|
238
202
|
// 发送响应
|
|
239
|
-
const { p2pNetwork } = await
|
|
203
|
+
const { p2pNetwork } = await import('../../network/p2p.js');
|
|
240
204
|
const response = {
|
|
241
205
|
type: 'discovery_response',
|
|
242
206
|
responderDid: this.getOwnDid(),
|
|
@@ -290,7 +254,7 @@ class DiapChannelBridge {
|
|
|
290
254
|
* 广播频道
|
|
291
255
|
*/
|
|
292
256
|
async broadcastChannel(channel) {
|
|
293
|
-
const { p2pNetwork } = await
|
|
257
|
+
const { p2pNetwork } = await import('../../network/p2p.js');
|
|
294
258
|
const announcement = {
|
|
295
259
|
type: 'channel_announce',
|
|
296
260
|
channelId: channel.id,
|
|
@@ -320,7 +284,7 @@ class DiapChannelBridge {
|
|
|
320
284
|
return false;
|
|
321
285
|
}
|
|
322
286
|
try {
|
|
323
|
-
const { p2pNetwork } = await
|
|
287
|
+
const { p2pNetwork } = await import('../../network/p2p.js');
|
|
324
288
|
await p2pNetwork.sendMessage(agent.peerId, type, payload);
|
|
325
289
|
return true;
|
|
326
290
|
}
|
|
@@ -351,7 +315,7 @@ class DiapChannelBridge {
|
|
|
351
315
|
return false;
|
|
352
316
|
}
|
|
353
317
|
try {
|
|
354
|
-
const { p2pNetwork } = await
|
|
318
|
+
const { p2pNetwork } = await import('../../network/p2p.js');
|
|
355
319
|
await p2pNetwork.sendMessage(agent.peerId, type, payload);
|
|
356
320
|
return true;
|
|
357
321
|
}
|
|
@@ -368,7 +332,7 @@ class DiapChannelBridge {
|
|
|
368
332
|
for (const agent of this.discoveredAgents.values()) {
|
|
369
333
|
if (agent.peerId) {
|
|
370
334
|
try {
|
|
371
|
-
const { p2pNetwork } = await
|
|
335
|
+
const { p2pNetwork } = await import('../../network/p2p.js');
|
|
372
336
|
await p2pNetwork.sendMessage(agent.peerId, type, payload);
|
|
373
337
|
successCount++;
|
|
374
338
|
}
|
|
@@ -390,7 +354,7 @@ class DiapChannelBridge {
|
|
|
390
354
|
myCap.toLowerCase().includes(reqCap.toLowerCase())));
|
|
391
355
|
if (hasMatch && agent.peerId) {
|
|
392
356
|
try {
|
|
393
|
-
const { p2pNetwork } = await
|
|
357
|
+
const { p2pNetwork } = await import('../../network/p2p.js');
|
|
394
358
|
await p2pNetwork.sendMessage(agent.peerId, type, payload);
|
|
395
359
|
successCount++;
|
|
396
360
|
}
|
|
@@ -447,5 +411,3 @@ class DiapChannelBridge {
|
|
|
447
411
|
console.log('[DiapBridge] Shutdown');
|
|
448
412
|
}
|
|
449
413
|
}
|
|
450
|
-
exports.DiapChannelBridge = DiapChannelBridge;
|
|
451
|
-
//# sourceMappingURL=DiapChannelBridge.js.map
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* InterestMatcher - 兴趣/能力匹配算法
|
|
4
3
|
*
|
|
5
4
|
* 计算智能体与频道的匹配度,用于自动加入决策
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
exports.interestMatcher = exports.InterestMatcher = void 0;
|
|
9
|
-
class InterestMatcher {
|
|
6
|
+
export class InterestMatcher {
|
|
10
7
|
/**
|
|
11
8
|
* 计算智能体与频道的匹配度 (0-1)
|
|
12
9
|
*/
|
|
@@ -130,6 +127,4 @@ class InterestMatcher {
|
|
|
130
127
|
return score >= threshold;
|
|
131
128
|
}
|
|
132
129
|
}
|
|
133
|
-
|
|
134
|
-
exports.interestMatcher = new InterestMatcher();
|
|
135
|
-
//# sourceMappingURL=InterestMatcher.js.map
|
|
130
|
+
export const interestMatcher = new InterestMatcher();
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Channel Agent Session - 整合 Channel、Judgment Engine 和 Persona 的智能会话
|
|
3
|
+
*
|
|
4
|
+
* 提供完整的 Channel 智能体功能:
|
|
5
|
+
* 1. P2P 多轮对话
|
|
6
|
+
* 2. Harness 判断力决策
|
|
7
|
+
* 3. 动态 Persona 设计
|
|
8
|
+
*/
|
|
9
|
+
import crypto from 'crypto';
|
|
10
|
+
import express from 'express';
|
|
11
|
+
import { createServer } from 'http';
|
|
12
|
+
import { createChannelJudgmentEngine } from '../../bollharness-integration/channel-judgment-engine.js';
|
|
13
|
+
import { createPersonaDesignEngine } from '../persona/enhanced-persona.js';
|
|
14
|
+
export class ChannelAgent {
|
|
15
|
+
id;
|
|
16
|
+
name;
|
|
17
|
+
port;
|
|
18
|
+
domain;
|
|
19
|
+
capabilities;
|
|
20
|
+
server = null;
|
|
21
|
+
judgmentEngine;
|
|
22
|
+
personaEngine;
|
|
23
|
+
dialogHistory = [];
|
|
24
|
+
responseIndex = 0;
|
|
25
|
+
ownDid;
|
|
26
|
+
// Gate responses by gate number
|
|
27
|
+
gateResponses = {
|
|
28
|
+
1: [
|
|
29
|
+
'关于架构设计,Harness 分析建议采用分层架构,将表现层、业务逻辑和数据访问层分离。这样可以提高代码的可维护性和可测试性。',
|
|
30
|
+
'Harness Gate 1 分析完成。建议使用依赖注入来降低模块间的耦合,这样更利于单元测试。',
|
|
31
|
+
],
|
|
32
|
+
2: [
|
|
33
|
+
'代码审查完成,Harness 建议添加输入验证和错误边界处理。特别是 API 接口,需要统一错误响应格式。',
|
|
34
|
+
'Gate 2 审查结果:建议为每个函数添加 JSDoc 注释,并使用 ESLint 统一代码风格。',
|
|
35
|
+
],
|
|
36
|
+
4: [
|
|
37
|
+
'安全检查完成。建议实现 JWT token 的过期机制和刷新策略,同时添加 IP 白名单功能。',
|
|
38
|
+
'Harness Gate 4 建议:使用 HTTPS 加密传输,对敏感操作添加二次验证。',
|
|
39
|
+
],
|
|
40
|
+
5: [
|
|
41
|
+
'任务已分解为 4 个子任务:\n1. 用户登录模块 (优先级:高)\n2. 用户注册模块 (优先级:高)\n3. 权限管理 (优先级:中)\n4. 集成测试 (优先级:中)\n建议按顺序执行。',
|
|
42
|
+
'Harness Gate 5 分解完成。每个子任务都有明确的完成标准和验收条件。',
|
|
43
|
+
],
|
|
44
|
+
7: [
|
|
45
|
+
'代码实现中,Harness 建议使用策略模式重构条件判断逻辑,这样更容易扩展新的验证规则。',
|
|
46
|
+
'Gate 7 分析:建议在服务层添加缓存机制,提高响应速度。',
|
|
47
|
+
],
|
|
48
|
+
8: [
|
|
49
|
+
'测试策略制定完成。目标覆盖率 80%,优先测试核心业务逻辑和边界情况。',
|
|
50
|
+
'Harness Gate 8:建议先写单元测试,再写集成测试,最后进行 E2E 测试。',
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.id = crypto.randomUUID();
|
|
55
|
+
this.name = config.name;
|
|
56
|
+
this.port = config.port;
|
|
57
|
+
this.domain = config.domain || '通用';
|
|
58
|
+
this.capabilities = config.capabilities || ['对话', '分析'];
|
|
59
|
+
this.ownDid = `did:local:${this.id.substring(0, 8)}`;
|
|
60
|
+
// Initialize judgment engine
|
|
61
|
+
this.judgmentEngine = createChannelJudgmentEngine();
|
|
62
|
+
// Initialize persona engine
|
|
63
|
+
this.personaEngine = createPersonaDesignEngine(config.persona);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Start the agent server
|
|
67
|
+
*/
|
|
68
|
+
async start() {
|
|
69
|
+
const app = express();
|
|
70
|
+
app.use(express.json());
|
|
71
|
+
// Health check
|
|
72
|
+
app.get('/health', (req, res) => {
|
|
73
|
+
res.json({
|
|
74
|
+
id: this.id,
|
|
75
|
+
name: this.name,
|
|
76
|
+
port: this.port,
|
|
77
|
+
domain: this.domain,
|
|
78
|
+
capabilities: this.capabilities,
|
|
79
|
+
dialogCount: this.dialogHistory.length,
|
|
80
|
+
lastGate: this.getLastGate(),
|
|
81
|
+
persona: this.personaEngine.getPersona()
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
// Discovery endpoint
|
|
85
|
+
app.get('/discovery', (req, res) => {
|
|
86
|
+
res.json({
|
|
87
|
+
id: this.id,
|
|
88
|
+
name: this.name,
|
|
89
|
+
did: this.ownDid,
|
|
90
|
+
port: this.port,
|
|
91
|
+
domain: this.domain,
|
|
92
|
+
capabilities: this.capabilities
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
// Dialog history
|
|
96
|
+
app.get('/history', (req, res) => {
|
|
97
|
+
res.json(this.dialogHistory);
|
|
98
|
+
});
|
|
99
|
+
// Persona info
|
|
100
|
+
app.get('/persona', (req, res) => {
|
|
101
|
+
res.json(this.personaEngine.getPersona());
|
|
102
|
+
});
|
|
103
|
+
// Receive message
|
|
104
|
+
app.post('/receive', async (req, res) => {
|
|
105
|
+
const { fromName, content } = req.body;
|
|
106
|
+
const result = await this.receiveMessage(fromName, content);
|
|
107
|
+
res.json(result);
|
|
108
|
+
});
|
|
109
|
+
// Send to agent (HTTP fallback for testing)
|
|
110
|
+
app.post('/send', async (req, res) => {
|
|
111
|
+
const { targetDid, targetPort, content } = req.body;
|
|
112
|
+
try {
|
|
113
|
+
const resp = await fetch(`http://localhost:${targetPort}/receive`, {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
headers: { 'Content-Type': 'application/json' },
|
|
116
|
+
body: JSON.stringify({ fromName: this.name, content })
|
|
117
|
+
});
|
|
118
|
+
const result = await resp.json();
|
|
119
|
+
res.json({ ok: true, result });
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
res.status(500).json({ ok: false, error: String(err) });
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
// Design persona
|
|
126
|
+
app.post('/design-persona', (req, res) => {
|
|
127
|
+
try {
|
|
128
|
+
const request = req.body;
|
|
129
|
+
const persona = this.designPersona(request);
|
|
130
|
+
res.json({ ok: true, persona });
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
res.status(400).json({ ok: false, error: String(err) });
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
this.server = createServer(app);
|
|
138
|
+
this.server.listen(this.port, () => {
|
|
139
|
+
console.log(`✓ [${this.name}] Channel Agent listening on port ${this.port}`);
|
|
140
|
+
resolve();
|
|
141
|
+
});
|
|
142
|
+
this.server.on('error', reject);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Receive and process a message
|
|
147
|
+
*/
|
|
148
|
+
async receiveMessage(fromName, content) {
|
|
149
|
+
console.log(`\n📨 [${this.name}] 收到 [${fromName}]: "${content.substring(0, 50)}..."`);
|
|
150
|
+
// Build judgment context
|
|
151
|
+
const context = {
|
|
152
|
+
conversationHistory: this.dialogHistory.slice(-10).map(d => d.message),
|
|
153
|
+
currentMessage: content,
|
|
154
|
+
senderName: fromName
|
|
155
|
+
};
|
|
156
|
+
// Decide whether to call Harness
|
|
157
|
+
const decision = await this.judgmentEngine.decide(context);
|
|
158
|
+
let response;
|
|
159
|
+
if (decision.shouldCall) {
|
|
160
|
+
console.log(`🧠 [${this.name}] 调用 Harness: Gate ${decision.gate}`);
|
|
161
|
+
console.log(` Skills: ${decision.skills.join(', ')}`);
|
|
162
|
+
console.log(` ${decision.result}`);
|
|
163
|
+
response = this.generateHarnessResponse(decision, fromName);
|
|
164
|
+
// Record with Harness call
|
|
165
|
+
this.dialogHistory.push({
|
|
166
|
+
id: crypto.randomUUID(),
|
|
167
|
+
speaker: fromName,
|
|
168
|
+
message: content,
|
|
169
|
+
timestamp: Date.now(),
|
|
170
|
+
harnessCalled: true,
|
|
171
|
+
gate: decision.gate,
|
|
172
|
+
skills: decision.skills
|
|
173
|
+
});
|
|
174
|
+
this.dialogHistory.push({
|
|
175
|
+
id: crypto.randomUUID(),
|
|
176
|
+
speaker: this.name,
|
|
177
|
+
message: response,
|
|
178
|
+
timestamp: Date.now(),
|
|
179
|
+
harnessCalled: true,
|
|
180
|
+
gate: decision.gate,
|
|
181
|
+
skills: decision.skills
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
console.log(`🧠 [${this.name}] 普通回复 (无需 Harness)`);
|
|
186
|
+
response = this.generateNaturalResponse();
|
|
187
|
+
// Record without Harness
|
|
188
|
+
this.dialogHistory.push({
|
|
189
|
+
id: crypto.randomUUID(),
|
|
190
|
+
speaker: fromName,
|
|
191
|
+
message: content,
|
|
192
|
+
timestamp: Date.now(),
|
|
193
|
+
harnessCalled: false
|
|
194
|
+
});
|
|
195
|
+
this.dialogHistory.push({
|
|
196
|
+
id: crypto.randomUUID(),
|
|
197
|
+
speaker: this.name,
|
|
198
|
+
message: response,
|
|
199
|
+
timestamp: Date.now(),
|
|
200
|
+
harnessCalled: false
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
console.log(`📤 [${this.name}] 回复: "${response.substring(0, 50)}..."`);
|
|
204
|
+
return {
|
|
205
|
+
response,
|
|
206
|
+
harnessCalled: decision.shouldCall,
|
|
207
|
+
gate: decision.shouldCall ? decision.gate : undefined,
|
|
208
|
+
skills: decision.shouldCall ? decision.skills : undefined
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Generate response for Harness call
|
|
213
|
+
*/
|
|
214
|
+
generateHarnessResponse(decision, fromName) {
|
|
215
|
+
const gateResponses = this.gateResponses[decision.gate] || [decision.result];
|
|
216
|
+
return gateResponses[this.responseIndex++ % gateResponses.length];
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Generate natural response for non-Harness messages
|
|
220
|
+
*/
|
|
221
|
+
generateNaturalResponse() {
|
|
222
|
+
const responses = this.judgmentEngine.generateNaturalResponse();
|
|
223
|
+
return responses[this.responseIndex++ % responses.length];
|
|
224
|
+
}
|
|
225
|
+
// ==================== Interface Implementation ====================
|
|
226
|
+
getDid() {
|
|
227
|
+
return this.ownDid;
|
|
228
|
+
}
|
|
229
|
+
getPersona() {
|
|
230
|
+
return this.personaEngine.getPersona();
|
|
231
|
+
}
|
|
232
|
+
getDialogHistory() {
|
|
233
|
+
return [...this.dialogHistory];
|
|
234
|
+
}
|
|
235
|
+
getLastGate() {
|
|
236
|
+
return this.judgmentEngine.getLastGate();
|
|
237
|
+
}
|
|
238
|
+
async sendToAgent(targetDid, content) {
|
|
239
|
+
// For now, this is a placeholder for P2P integration
|
|
240
|
+
// In production, this would use DiapChannelBridge
|
|
241
|
+
console.log(`[${this.name}] Would send to ${targetDid}: ${content}`);
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
async broadcastMessage(content) {
|
|
245
|
+
console.log(`[${this.name}] Broadcasting: ${content}`);
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
designPersona(request) {
|
|
249
|
+
return this.personaEngine.designPersona(request);
|
|
250
|
+
}
|
|
251
|
+
updatePersona(updates) {
|
|
252
|
+
this.personaEngine.updatePersona(updates);
|
|
253
|
+
}
|
|
254
|
+
shutdown() {
|
|
255
|
+
if (this.server) {
|
|
256
|
+
this.server.close();
|
|
257
|
+
this.server = null;
|
|
258
|
+
}
|
|
259
|
+
this.dialogHistory = [];
|
|
260
|
+
this.judgmentEngine.reset();
|
|
261
|
+
console.log(`[${this.name}] Channel Agent shutdown`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Factory function
|
|
265
|
+
export function createChannelAgent(config) {
|
|
266
|
+
return new ChannelAgent(config);
|
|
267
|
+
}
|
|
268
|
+
// Channel Agent Registry for managing multiple agents
|
|
269
|
+
export class ChannelAgentRegistry {
|
|
270
|
+
agents = new Map();
|
|
271
|
+
register(agent) {
|
|
272
|
+
this.agents.set(agent.id, agent);
|
|
273
|
+
}
|
|
274
|
+
unregister(agentId) {
|
|
275
|
+
const agent = this.agents.get(agentId);
|
|
276
|
+
if (agent) {
|
|
277
|
+
agent.shutdown();
|
|
278
|
+
this.agents.delete(agentId);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
get(agentId) {
|
|
282
|
+
return this.agents.get(agentId);
|
|
283
|
+
}
|
|
284
|
+
getByName(name) {
|
|
285
|
+
for (const agent of this.agents.values()) {
|
|
286
|
+
if (agent.name === name) {
|
|
287
|
+
return agent;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
getByDid(did) {
|
|
293
|
+
for (const agent of this.agents.values()) {
|
|
294
|
+
if (agent.getDid() === did) {
|
|
295
|
+
return agent;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
list() {
|
|
301
|
+
return Array.from(this.agents.values());
|
|
302
|
+
}
|
|
303
|
+
clear() {
|
|
304
|
+
for (const agent of this.agents.values()) {
|
|
305
|
+
agent.shutdown();
|
|
306
|
+
}
|
|
307
|
+
this.agents.clear();
|
|
308
|
+
}
|
|
309
|
+
}
|