@bolloon/bolloon-agent 0.1.1 → 0.1.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.
Files changed (200) hide show
  1. package/bin/bolloon-cli.cjs +165 -0
  2. package/bin/bolloon-daemon.sh +207 -0
  3. package/bin/bolloon.cmd +11 -0
  4. package/dist/agents/constraint-layer.js +10 -15
  5. package/dist/agents/pi-sdk.js +433 -106
  6. package/dist/agents/protocol.js +82 -1
  7. package/dist/agents/subagent-manager.js +2 -2
  8. package/dist/agents/workflow-engine.js +15 -20
  9. package/dist/agents/workflow-pivot-loop.js +541 -0
  10. package/dist/bollharness/src/index.js +5 -0
  11. package/dist/bollharness/src/scripts/checks/check_adr_plan_numbering.js +6 -0
  12. package/dist/bollharness/src/scripts/checks/check_api_types.js +45 -0
  13. package/dist/bollharness/src/scripts/checks/check_artifact_link.js +146 -0
  14. package/dist/bollharness/src/scripts/checks/check_bridge_deps.js +6 -0
  15. package/dist/bollharness/src/scripts/checks/check_bugfix_binding.js +6 -0
  16. package/dist/bollharness/src/scripts/checks/check_bugfix_binding_ci.js +6 -0
  17. package/dist/bollharness/src/scripts/checks/check_doc_file_references.js +6 -0
  18. package/dist/bollharness/src/scripts/checks/check_doc_freshness.js +135 -0
  19. package/dist/bollharness/src/scripts/checks/check_doc_links.js +31 -0
  20. package/dist/bollharness/src/scripts/checks/check_file_existence_claims.js +6 -0
  21. package/dist/bollharness/src/scripts/checks/check_fragment_integrity.js +34 -0
  22. package/dist/bollharness/src/scripts/checks/check_hook_installed.js +63 -0
  23. package/dist/bollharness/src/scripts/checks/check_issue_closure.js +41 -0
  24. package/dist/bollharness/src/scripts/checks/check_mcp_parity.js +6 -0
  25. package/dist/bollharness/src/scripts/checks/check_security.js +48 -0
  26. package/dist/bollharness/src/scripts/checks/check_skill_parity.js +6 -0
  27. package/dist/bollharness/src/scripts/checks/check_versions.js +6 -0
  28. package/dist/bollharness/src/scripts/checks/finding.js +13 -0
  29. package/dist/bollharness/src/scripts/checks/next_decision_number.js +20 -0
  30. package/dist/bollharness/src/scripts/checks/regenerate_magic_docs.js +6 -0
  31. package/dist/bollharness/src/scripts/ci/detect_rebaseline_triggers.js +8 -0
  32. package/dist/bollharness/src/scripts/ci/scan_subprocess_cfg.js +8 -0
  33. package/dist/bollharness/src/scripts/ci/scan_verify_artifacts.js +8 -0
  34. package/dist/bollharness/src/scripts/ci/scan_yaml_schema.js +8 -0
  35. package/dist/bollharness/src/scripts/context_router.js +67 -0
  36. package/dist/bollharness/src/scripts/deploy-guard.js +157 -0
  37. package/dist/bollharness/src/scripts/guard-feedback.js +192 -0
  38. package/dist/bollharness/src/scripts/guard_router.js +158 -0
  39. package/dist/bollharness/src/scripts/hooks/_hook_output.js +6 -0
  40. package/dist/bollharness/src/scripts/hooks/auto-python3.js +6 -0
  41. package/dist/bollharness/src/scripts/hooks/deploy-progress-on-session-end.js +6 -0
  42. package/dist/bollharness/src/scripts/hooks/failure-analyzer.js +6 -0
  43. package/dist/bollharness/src/scripts/hooks/gate-judgment-inject.js +92 -0
  44. package/dist/bollharness/src/scripts/hooks/gate-transition-judgment.js +63 -0
  45. package/dist/bollharness/src/scripts/hooks/inbox-ack.js +6 -0
  46. package/dist/bollharness/src/scripts/hooks/inbox-inject-on-start.js +6 -0
  47. package/dist/bollharness/src/scripts/hooks/inbox-validate.js +6 -0
  48. package/dist/bollharness/src/scripts/hooks/inbox-write-ledger.js +6 -0
  49. package/dist/bollharness/src/scripts/hooks/initializer-agent.js +6 -0
  50. package/dist/bollharness/src/scripts/hooks/loop-detection.js +73 -0
  51. package/dist/bollharness/src/scripts/hooks/owner-guard.js +6 -0
  52. package/dist/bollharness/src/scripts/hooks/precompact.js +6 -0
  53. package/dist/bollharness/src/scripts/hooks/review-agent-gatekeeper.js +6 -0
  54. package/dist/bollharness/src/scripts/hooks/risk-tracker.js +108 -0
  55. package/dist/bollharness/src/scripts/hooks/sanitize-on-read.js +6 -0
  56. package/dist/bollharness/src/scripts/hooks/session-reflection.js +7 -0
  57. package/dist/bollharness/src/scripts/hooks/session-start-magic-docs.js +7 -0
  58. package/dist/bollharness/src/scripts/hooks/session-start-reset-risk.js +7 -0
  59. package/dist/bollharness/src/scripts/hooks/session-start-toolkit-reminder.js +7 -0
  60. package/dist/bollharness/src/scripts/hooks/stop-evaluator.js +157 -0
  61. package/dist/bollharness/src/scripts/hooks/tool-call-counter.js +6 -0
  62. package/dist/bollharness/src/scripts/hooks/trace-analyzer.js +10 -0
  63. package/dist/bollharness/src/scripts/install/install-trust-token.js +7 -0
  64. package/dist/bollharness/src/scripts/install/multi_project_registry.js +9 -0
  65. package/dist/bollharness/src/scripts/install/phase2_auto.js +21 -0
  66. package/dist/bollharness/src/scripts/install/pre_commit_installer.js +6 -0
  67. package/dist/bollharness/src/scripts/install/tier_selector.js +7 -0
  68. package/dist/bollharness/src/scripts/install/transcript_miner.js +7 -0
  69. package/dist/bollharness/src/scripts/lib/claim_patterns.js +10 -0
  70. package/dist/bollharness/src/scripts/lib/sanitize_patterns.js +12 -0
  71. package/dist/bollharness/src/scripts/sanitize.js +6 -0
  72. package/dist/bollharness-integration/channel-judgment-engine.js +530 -0
  73. package/dist/bollharness-integration/context-chain-router.js +383 -0
  74. package/dist/bollharness-integration/context-router-judgment.js +13 -21
  75. package/dist/bollharness-integration/context-router.js +22 -64
  76. package/dist/bollharness-integration/gate-state-machine.js +14 -19
  77. package/dist/bollharness-integration/gate-transition-hooks.js +16 -61
  78. package/dist/bollharness-integration/guard-checker.js +21 -68
  79. package/dist/bollharness-integration/index.js +14 -124
  80. package/dist/bollharness-integration/integration.js +13 -20
  81. package/dist/bollharness-integration/llm-judgment-engine.js +569 -0
  82. package/dist/bollharness-integration/skill-adapter.js +18 -64
  83. package/dist/cli-entry.js +261 -0
  84. package/dist/constraint-runtime/src/commands.js +17 -7
  85. package/dist/constraint-runtime/src/constraint/budget.js +1 -6
  86. package/dist/constraint-runtime/src/constraint/permission.js +1 -6
  87. package/dist/constraint-runtime/src/models.js +1 -3
  88. package/dist/constraint-runtime/src/tools.js +17 -7
  89. package/dist/constraints/index.js +1 -7
  90. package/dist/documents/reader.js +8 -49
  91. package/dist/heartbeat/DaemonManager.js +242 -0
  92. package/dist/heartbeat/HealthMonitor.js +285 -0
  93. package/dist/heartbeat/StartupVerifier.js +205 -0
  94. package/dist/heartbeat/Watchdog.js +168 -0
  95. package/dist/heartbeat/index.js +84 -0
  96. package/dist/heartbeat/types.js +5 -0
  97. package/dist/index.js +381 -28
  98. package/dist/llm/config-store.js +31 -57
  99. package/dist/llm/llm-judgment-client.js +389 -0
  100. package/dist/llm/pi-ai.js +9 -52
  101. package/dist/network/agent-network.js +46 -90
  102. package/dist/network/hybrid-messenger.js +125 -0
  103. package/dist/network/iroh-bootstrap.js +38 -0
  104. package/dist/network/iroh-discovery.js +145 -0
  105. package/dist/network/iroh-integration.js +9 -16
  106. package/dist/network/iroh-transport.js +10 -48
  107. package/dist/network/p2p.js +23 -62
  108. package/dist/network/storage/adapters/json-adapter.js +4 -42
  109. package/dist/network/storage/index.js +147 -0
  110. package/dist/network/storage/types.js +14 -0
  111. package/dist/pi-ecosystem/index.js +233 -0
  112. package/dist/pi-ecosystem-colony/index.js +29 -90
  113. package/dist/pi-ecosystem-goals/index.js +20 -74
  114. package/dist/pi-ecosystem-judgment/decision.js +29 -47
  115. package/dist/pi-ecosystem-judgment/distillation.js +16 -29
  116. package/dist/pi-ecosystem-judgment/human-value-store.js +13 -60
  117. package/dist/pi-ecosystem-judgment/index.js +21 -74
  118. package/dist/pi-ecosystem-judgment/value-injection.js +26 -72
  119. package/dist/pi-ecosystem-mcp/index.js +24 -78
  120. package/dist/pi-ecosystem-subagents/index.js +20 -69
  121. package/dist/social/ant-colony/AdaptiveHeartbeat.js +3 -8
  122. package/dist/social/ant-colony/PheromoneEngine.js +11 -49
  123. package/dist/social/ant-colony/index.js +6 -0
  124. package/dist/social/ant-colony/types.js +4 -8
  125. package/dist/social/channels/ChannelManager.js +8 -46
  126. package/dist/social/channels/DiapChannelBridge.js +9 -47
  127. package/dist/social/channels/InterestMatcher.js +2 -7
  128. package/dist/social/channels/channel-agent-session.js +309 -0
  129. package/dist/social/channels/channel-heartbeat-agent.js +494 -0
  130. package/dist/social/channels/diap-doc-parser.js +204 -0
  131. package/dist/social/channels/harness-workflow-integrator.js +446 -0
  132. package/dist/social/channels/index.js +9 -0
  133. package/dist/social/channels/types.js +3 -7
  134. package/dist/social/global-shared-context.js +6 -47
  135. package/dist/social/heartbeat.js +29 -72
  136. package/dist/social/persona/enhanced-persona.js +299 -0
  137. package/dist/web/client.js +302 -136
  138. package/dist/web/components/p2p/index.js +159 -9
  139. package/dist/web/components/p2p/p2p-connection.js +136 -0
  140. package/dist/web/components/p2p/p2p-manager.js +24 -0
  141. package/dist/web/components/p2p/p2p-store-memory.js +1 -1
  142. package/dist/web/components/p2p/types.js +7 -0
  143. package/dist/web/index.html +5 -0
  144. package/dist/web/style.css +118 -0
  145. package/package.json +12 -6
  146. package/scripts/build-cli.js +206 -0
  147. package/scripts/postinstall.js +153 -0
  148. package/src/agents/pi-sdk.ts +347 -28
  149. package/src/agents/protocol.ts +95 -1
  150. package/src/agents/workflow-pivot-loop.ts +674 -0
  151. package/src/bollharness/CLAUDE.md +73 -0
  152. package/src/bollharness/README.md +143 -0
  153. package/src/bollharness/README.zh-CN.md +131 -0
  154. package/src/bollharness/reference/boll-reference/scripts/hooks/stop-evaluator.md +57 -0
  155. package/src/bollharness/scripts/context-fragments/artifact-linkage.md +14 -0
  156. package/src/bollharness/scripts/context-fragments/auth-consumers.md +17 -0
  157. package/src/bollharness/scripts/context-fragments/bridge-constitution.md +13 -0
  158. package/src/bollharness/scripts/context-fragments/catalyst-distributed.md +18 -0
  159. package/src/bollharness/scripts/context-fragments/closure-checklist.md +13 -0
  160. package/src/bollharness/scripts/context-fragments/contract-consumers.md +15 -0
  161. package/src/bollharness/scripts/context-fragments/db-shared-structures.md +15 -0
  162. package/src/bollharness/scripts/context-fragments/fixed-three-layers.md +19 -0
  163. package/src/bollharness/scripts/context-fragments/general-dev-principles.md +11 -0
  164. package/src/bollharness/scripts/context-fragments/issue-first.md +8 -0
  165. package/src/bollharness/scripts/context-fragments/mcp-parity.md +16 -0
  166. package/src/bollharness/scripts/context-fragments/pi-agent-operations.md +108 -0
  167. package/src/bollharness/scripts/context-fragments/protocol-consumers.md +15 -0
  168. package/src/bollharness/scripts/context-fragments/run-events-consumers.md +15 -0
  169. package/src/bollharness/scripts/context-fragments/scene-fidelity.md +13 -0
  170. package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +15 -0
  171. package/src/bollharness/scripts/context-fragments/two-language.md +15 -0
  172. package/src/bollharness/scripts/context-fragments/version-sources.md +14 -0
  173. package/src/bollharness/scripts/hooks/stop-evaluator.md +83 -0
  174. package/src/bollharness/templates/scaffold/CLAUDE.md +89 -0
  175. package/src/cli-entry.ts +304 -0
  176. package/src/heartbeat/DaemonManager.ts +283 -0
  177. package/src/heartbeat/HealthMonitor.ts +316 -0
  178. package/src/heartbeat/StartupVerifier.ts +223 -0
  179. package/src/heartbeat/Watchdog.ts +198 -0
  180. package/src/heartbeat/index.ts +108 -0
  181. package/src/heartbeat/types.ts +82 -0
  182. package/src/llm/config-store.ts +23 -5
  183. package/src/network/iroh-transport.ts +3 -3
  184. package/src/web/client.js +302 -136
  185. package/src/web/components/p2p/P2PModal.tsx +91 -3
  186. package/src/web/components/p2p/index.ts +171 -9
  187. package/src/web/components/p2p/p2p-connection.ts +153 -1
  188. package/src/web/components/p2p/p2p-manager.ts +39 -1
  189. package/src/web/components/p2p/p2p-store-memory.ts +1 -1
  190. package/src/web/components/p2p/p2p-tools.ts +315 -0
  191. package/src/web/components/p2p/types.ts +58 -0
  192. package/src/web/design.md +99 -0
  193. package/src/web/index.html +5 -0
  194. package/src/web/server.ts +353 -36
  195. package/src/web/style.css +118 -0
  196. package/tsconfig.cli.json +16 -0
  197. package/tsconfig.electron.json +1 -1
  198. package/tsconfig.json +1 -2
  199. package/dist/web/server.js +0 -1647
  200. 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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
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
- }, types_js_2.DEFAULT_CHANNEL_CONFIG.broadcastInterval);
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: types_js_1.ChannelType.CAPABILITY,
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 Promise.resolve().then(() => __importStar(require('../../network/p2p.js')));
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 Promise.resolve().then(() => __importStar(require('../../network/p2p.js')));
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 Promise.resolve().then(() => __importStar(require('../../network/p2p.js')));
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 Promise.resolve().then(() => __importStar(require('../../network/p2p.js')));
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 Promise.resolve().then(() => __importStar(require('../../network/p2p.js')));
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 Promise.resolve().then(() => __importStar(require('../../network/p2p.js')));
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 Promise.resolve().then(() => __importStar(require('../../network/p2p.js')));
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 Promise.resolve().then(() => __importStar(require('../../network/p2p.js')));
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 Promise.resolve().then(() => __importStar(require('../../network/p2p.js')));
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
- Object.defineProperty(exports, "__esModule", { value: true });
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
- exports.InterestMatcher = InterestMatcher;
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
+ }