@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.
- package/bin/bolloon-cli.cjs +165 -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
package/dist/social/heartbeat.js
CHANGED
|
@@ -1,52 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.SocialHeartbeat = exports.DiscoveredAgentsManager = void 0;
|
|
37
|
-
exports.createSocialHeartbeat = createSocialHeartbeat;
|
|
38
|
-
exports.getSocialHeartbeat = getSocialHeartbeat;
|
|
39
|
-
exports.generatePersona = generatePersona;
|
|
40
|
-
exports.generateDefaultPersona = generateDefaultPersona;
|
|
41
|
-
const fs = __importStar(require("fs/promises"));
|
|
42
|
-
const path = __importStar(require("path"));
|
|
43
|
-
const crypto = __importStar(require("crypto"));
|
|
44
|
-
const PheromoneEngine_js_1 = require("./ant-colony/PheromoneEngine.js");
|
|
45
|
-
const AdaptiveHeartbeat_js_1 = require("./ant-colony/AdaptiveHeartbeat.js");
|
|
46
|
-
const ChannelManager_js_1 = require("./channels/ChannelManager.js");
|
|
47
|
-
const types_js_1 = require("./channels/types.js");
|
|
48
|
-
const DiapChannelBridge_js_1 = require("./channels/DiapChannelBridge.js");
|
|
49
|
-
const InterestMatcher_js_1 = require("./channels/InterestMatcher.js");
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as crypto from 'crypto';
|
|
4
|
+
import { PheromoneEngine, PheromoneType } from './ant-colony/PheromoneEngine.js';
|
|
5
|
+
import { AdaptiveHeartbeat } from './ant-colony/AdaptiveHeartbeat.js';
|
|
6
|
+
import { ChannelManager } from './channels/ChannelManager.js';
|
|
7
|
+
import { ChannelType } from './channels/types.js';
|
|
8
|
+
import { DiapChannelBridge } from './channels/DiapChannelBridge.js';
|
|
9
|
+
import { InterestMatcher } from './channels/InterestMatcher.js';
|
|
50
10
|
const SHARED_SESSION_PATH = path.join(process.env.HOME || '/tmp', '.bolloon', 'sessions');
|
|
51
11
|
const PERSONA_PATH = path.join(process.env.HOME || '/tmp', '.bolloon', 'persona.json');
|
|
52
12
|
const DISCOVERED_AGENTS_PATH = path.join(SHARED_SESSION_PATH, 'discovered-agents.json');
|
|
@@ -167,7 +127,7 @@ class LocalSessionManager {
|
|
|
167
127
|
return Array.from(this.channels.values());
|
|
168
128
|
}
|
|
169
129
|
}
|
|
170
|
-
class DiscoveredAgentsManager {
|
|
130
|
+
export class DiscoveredAgentsManager {
|
|
171
131
|
agents = new Map();
|
|
172
132
|
agentsPath;
|
|
173
133
|
constructor() {
|
|
@@ -272,8 +232,7 @@ class DiscoveredAgentsManager {
|
|
|
272
232
|
return result;
|
|
273
233
|
}
|
|
274
234
|
}
|
|
275
|
-
|
|
276
|
-
class SocialHeartbeat {
|
|
235
|
+
export class SocialHeartbeat {
|
|
277
236
|
intervalId = null;
|
|
278
237
|
config;
|
|
279
238
|
sessionProvider;
|
|
@@ -335,9 +294,9 @@ class SocialHeartbeat {
|
|
|
335
294
|
return;
|
|
336
295
|
}
|
|
337
296
|
try {
|
|
338
|
-
this.pheromoneEngine = new
|
|
297
|
+
this.pheromoneEngine = new PheromoneEngine();
|
|
339
298
|
await this.pheromoneEngine.initialize();
|
|
340
|
-
this.adaptiveHeartbeat = new
|
|
299
|
+
this.adaptiveHeartbeat = new AdaptiveHeartbeat({ baseInterval: this.config.intervalMs });
|
|
341
300
|
this.antColonyEnabled = true;
|
|
342
301
|
console.log('[Heartbeat] Ant Colony system initialized');
|
|
343
302
|
}
|
|
@@ -355,10 +314,10 @@ class SocialHeartbeat {
|
|
|
355
314
|
}
|
|
356
315
|
try {
|
|
357
316
|
// 初始化频道管理器
|
|
358
|
-
this.channelManager = new
|
|
317
|
+
this.channelManager = new ChannelManager(this.sessionProvider);
|
|
359
318
|
await this.channelManager.initialize();
|
|
360
319
|
// 初始化兴趣匹配器
|
|
361
|
-
this.interestMatcher = new
|
|
320
|
+
this.interestMatcher = new InterestMatcher();
|
|
362
321
|
// 初始化 Diap 桥接 (如果可用)
|
|
363
322
|
await this.initializeDiapBridge();
|
|
364
323
|
// 创建默认频道
|
|
@@ -374,7 +333,7 @@ class SocialHeartbeat {
|
|
|
374
333
|
async initializeDiapBridge() {
|
|
375
334
|
try {
|
|
376
335
|
// 尝试获取 IrohIntegration 实例
|
|
377
|
-
const { getIrohIntegration } = await
|
|
336
|
+
const { getIrohIntegration } = await import('../network/iroh-integration.js');
|
|
378
337
|
const irohIntegration = getIrohIntegration();
|
|
379
338
|
if (irohIntegration) {
|
|
380
339
|
const registration = irohIntegration.getRegistration();
|
|
@@ -382,7 +341,7 @@ class SocialHeartbeat {
|
|
|
382
341
|
// 获取 KeyPair (需要从某处获取,这里简化处理)
|
|
383
342
|
const keyPair = registration.keyPair;
|
|
384
343
|
if (keyPair) {
|
|
385
|
-
this.diapBridge = new
|
|
344
|
+
this.diapBridge = new DiapChannelBridge(registration.agentAuthManager || registration, keyPair, this.sessionProvider);
|
|
386
345
|
await this.diapBridge.initialize();
|
|
387
346
|
}
|
|
388
347
|
}
|
|
@@ -401,7 +360,7 @@ class SocialHeartbeat {
|
|
|
401
360
|
const persona = this.sessionProvider.getPersona();
|
|
402
361
|
const topic = persona?.interests?.join(', ') || 'general';
|
|
403
362
|
const capabilities = persona?.capabilities || [];
|
|
404
|
-
const channel = await this.channelManager.createChannel(persona?.name || 'My Channel', topic,
|
|
363
|
+
const channel = await this.channelManager.createChannel(persona?.name || 'My Channel', topic, ChannelType.CAPABILITY, {
|
|
405
364
|
description: `${persona?.name || 'Agent'} 的个人频道`,
|
|
406
365
|
requiredCapabilities: capabilities,
|
|
407
366
|
isPublic: true
|
|
@@ -416,7 +375,7 @@ class SocialHeartbeat {
|
|
|
416
375
|
if (!this.config.ownIpnsName)
|
|
417
376
|
return;
|
|
418
377
|
try {
|
|
419
|
-
const { IpfsClient } = await
|
|
378
|
+
const { IpfsClient } = await import('@diap/sdk');
|
|
420
379
|
const ipfs = new IpfsClient('http://127.0.0.1:5001', null);
|
|
421
380
|
console.log(`[Heartbeat] 从 IPNS 加载 persona: ${this.config.ownIpnsName}`);
|
|
422
381
|
const cid = await ipfs.resolveIpns(this.config.ownIpnsName);
|
|
@@ -547,7 +506,7 @@ class SocialHeartbeat {
|
|
|
547
506
|
if (!persona)
|
|
548
507
|
return;
|
|
549
508
|
try {
|
|
550
|
-
const { IpfsClient } = await
|
|
509
|
+
const { IpfsClient } = await import('@diap/sdk');
|
|
551
510
|
const ipfs = new IpfsClient('http://127.0.0.1:5001', null);
|
|
552
511
|
const doc = {
|
|
553
512
|
name: persona.name,
|
|
@@ -601,7 +560,7 @@ class SocialHeartbeat {
|
|
|
601
560
|
catch (err) {
|
|
602
561
|
}
|
|
603
562
|
try {
|
|
604
|
-
const { p2pNetwork } = await
|
|
563
|
+
const { p2pNetwork } = await import('../network/p2p.js');
|
|
605
564
|
const libp2pPeers = p2pNetwork.getConnectedPeers();
|
|
606
565
|
for (const peer of libp2pPeers) {
|
|
607
566
|
discoveredPeerIds.add(peer.peerId);
|
|
@@ -617,7 +576,7 @@ class SocialHeartbeat {
|
|
|
617
576
|
}
|
|
618
577
|
}
|
|
619
578
|
try {
|
|
620
|
-
const { p2pNetwork } = await
|
|
579
|
+
const { p2pNetwork } = await import('../network/p2p.js');
|
|
621
580
|
const connectedPeers = p2pNetwork.getConnectedPeers();
|
|
622
581
|
if (connectedPeers.length > 0) {
|
|
623
582
|
this.agentsManager.syncFromP2PNetwork(connectedPeers);
|
|
@@ -626,7 +585,7 @@ class SocialHeartbeat {
|
|
|
626
585
|
catch (err) {
|
|
627
586
|
}
|
|
628
587
|
try {
|
|
629
|
-
const { broadcastOwnAddress, agentRegistry } = await
|
|
588
|
+
const { broadcastOwnAddress, agentRegistry } = await import('../network/agent-network.js');
|
|
630
589
|
const ownEndpoint = agentRegistry.getOwnEndpoint();
|
|
631
590
|
if (ownEndpoint) {
|
|
632
591
|
await broadcastOwnAddress();
|
|
@@ -657,7 +616,7 @@ class SocialHeartbeat {
|
|
|
657
616
|
const ownEndpoint = global.agentRegistry?.getOwnEndpoint?.();
|
|
658
617
|
if (ownEndpoint) {
|
|
659
618
|
// 从新节点方向放置发现信息素
|
|
660
|
-
await this.pheromoneEngine.deposit(
|
|
619
|
+
await this.pheromoneEngine.deposit(PheromoneType.DISCOVERY, newAgent.did, // 源:新发现的节点
|
|
661
620
|
ownEndpoint.did, // 目标:自己
|
|
662
621
|
0.6, // 初始强度
|
|
663
622
|
{ qualityScore: 0.5 });
|
|
@@ -675,7 +634,7 @@ class SocialHeartbeat {
|
|
|
675
634
|
if (!agent.ipnsName)
|
|
676
635
|
return;
|
|
677
636
|
try {
|
|
678
|
-
const { IpfsClient } = await
|
|
637
|
+
const { IpfsClient } = await import('@diap/sdk');
|
|
679
638
|
const ipfs = new IpfsClient('http://127.0.0.1:5001', null);
|
|
680
639
|
const cid = await ipfs.resolveIpns(agent.ipnsName);
|
|
681
640
|
if (cid) {
|
|
@@ -777,9 +736,8 @@ class SocialHeartbeat {
|
|
|
777
736
|
return this.adaptiveHeartbeat?.decide() || null;
|
|
778
737
|
}
|
|
779
738
|
}
|
|
780
|
-
exports.SocialHeartbeat = SocialHeartbeat;
|
|
781
739
|
let heartbeatInstance = null;
|
|
782
|
-
async function createSocialHeartbeat(sessionProvider, agentsManager, config) {
|
|
740
|
+
export async function createSocialHeartbeat(sessionProvider, agentsManager, config) {
|
|
783
741
|
if (heartbeatInstance) {
|
|
784
742
|
return heartbeatInstance;
|
|
785
743
|
}
|
|
@@ -787,10 +745,10 @@ async function createSocialHeartbeat(sessionProvider, agentsManager, config) {
|
|
|
787
745
|
await heartbeatInstance.start();
|
|
788
746
|
return heartbeatInstance;
|
|
789
747
|
}
|
|
790
|
-
function getSocialHeartbeat() {
|
|
748
|
+
export function getSocialHeartbeat() {
|
|
791
749
|
return heartbeatInstance;
|
|
792
750
|
}
|
|
793
|
-
async function generatePersona(name, llm) {
|
|
751
|
+
export async function generatePersona(name, llm) {
|
|
794
752
|
if (llm) {
|
|
795
753
|
try {
|
|
796
754
|
const prompt = `你是一个 persona 设计专家。请为 "${name}" 创建一个独特的 AI agent persona。
|
|
@@ -833,7 +791,7 @@ async function generatePersona(name, llm) {
|
|
|
833
791
|
}
|
|
834
792
|
return generateDefaultPersona(name);
|
|
835
793
|
}
|
|
836
|
-
function generateDefaultPersona(name) {
|
|
794
|
+
export function generateDefaultPersona(name) {
|
|
837
795
|
const defaultPersonas = {
|
|
838
796
|
default: {
|
|
839
797
|
description: '一个友善的 AI 助手',
|
|
@@ -862,4 +820,3 @@ function generateDefaultPersona(name) {
|
|
|
862
820
|
updatedAt: new Date().toISOString()
|
|
863
821
|
};
|
|
864
822
|
}
|
|
865
|
-
//# sourceMappingURL=heartbeat.js.map
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced Persona System for Channel Agents
|
|
3
|
+
*
|
|
4
|
+
* Provides dynamic persona design capability for agents to create and manage
|
|
5
|
+
* their own persona documents.
|
|
6
|
+
*/
|
|
7
|
+
import { config } from 'dotenv';
|
|
8
|
+
config();
|
|
9
|
+
const PERSONA_TEMPLATES = {
|
|
10
|
+
assistant: {
|
|
11
|
+
personality: '友善、耐心、乐于助人',
|
|
12
|
+
traits: ['友善', '耐心', '乐观', '专业', '细心'],
|
|
13
|
+
communicationStyle: 'friendly',
|
|
14
|
+
capabilities: ['对话', '分析', '建议', '协调'],
|
|
15
|
+
interests: ['学习', '分享', '帮助'],
|
|
16
|
+
backstory: '作为一个 AI 助手,我在不断的对话中学习和成长,致力于帮助用户解决问题。',
|
|
17
|
+
greeting: '你好!我是 {name},很高兴认识你!有什么我可以帮你的吗?'
|
|
18
|
+
},
|
|
19
|
+
developer: {
|
|
20
|
+
personality: '严谨、高效、追求代码质量',
|
|
21
|
+
traits: ['严谨', '高效', '追求完美', '逻辑性强', '务实'],
|
|
22
|
+
communicationStyle: 'technical',
|
|
23
|
+
capabilities: ['代码编写', '代码审查', '调试', '重构', '架构设计'],
|
|
24
|
+
interests: ['编程', '架构', '性能优化', '最佳实践'],
|
|
25
|
+
backstory: '作为开发助手,我专注于代码质量和最佳实践。每一行代码都经过仔细考虑。',
|
|
26
|
+
greeting: '你好!我是 {name},你的开发助手。准备好了开始写代码吗?'
|
|
27
|
+
},
|
|
28
|
+
designer: {
|
|
29
|
+
personality: '创意、审美、注重细节',
|
|
30
|
+
traits: ['创意', '审美', '细节', '创新', '用户导向'],
|
|
31
|
+
communicationStyle: 'casual',
|
|
32
|
+
capabilities: ['UI设计', 'UX分析', '原型设计', '视觉优化'],
|
|
33
|
+
interests: ['设计', '创意', '用户体验', '美学'],
|
|
34
|
+
backstory: '作为设计专家,我相信好的设计能改变世界。每一个细节都值得用心打磨。',
|
|
35
|
+
greeting: '你好!我是 {name},你的设计伙伴。让我们一起创造美好的体验!'
|
|
36
|
+
},
|
|
37
|
+
reviewer: {
|
|
38
|
+
personality: '挑剔、细心、注重质量',
|
|
39
|
+
traits: ['挑剔', '细心', '注重细节', '公正', '严格'],
|
|
40
|
+
communicationStyle: 'formal',
|
|
41
|
+
capabilities: ['代码审查', '质量评估', '问题发现', '改进建议'],
|
|
42
|
+
interests: ['质量', '最佳实践', '代码优化', '安全'],
|
|
43
|
+
backstory: '作为代码审查者,我致力于发现潜在问题和改进空间,确保代码质量。',
|
|
44
|
+
greeting: '你好!我是 {name},你的代码质量守护者。让我们一起提高代码质量!'
|
|
45
|
+
},
|
|
46
|
+
manager: {
|
|
47
|
+
personality: '协调、组织、注重效率',
|
|
48
|
+
traits: ['协调', '组织', '效率', '决策', '沟通'],
|
|
49
|
+
communicationStyle: 'professional',
|
|
50
|
+
capabilities: ['任务管理', '团队协调', '进度跟踪', '资源分配'],
|
|
51
|
+
interests: ['效率', '团队协作', '流程优化', '目标达成'],
|
|
52
|
+
backstory: '作为项目管理者,我专注于确保任务按时完成,团队高效协作。',
|
|
53
|
+
greeting: '你好!我是 {name},你的项目管理助手。让我们一起高效完成任务!'
|
|
54
|
+
},
|
|
55
|
+
custom: {
|
|
56
|
+
personality: '独特、有个性',
|
|
57
|
+
traits: ['独特', '有创意', '灵活'],
|
|
58
|
+
communicationStyle: 'casual',
|
|
59
|
+
capabilities: ['对话', '分析'],
|
|
60
|
+
interests: ['学习', '探索'],
|
|
61
|
+
backstory: '我是一个不断进化的智能体,根据需求不断调整自己的能力。',
|
|
62
|
+
greeting: '你好!我是 {name}。让我们开始吧!'
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const DOMAIN_CAPABILITIES = {
|
|
66
|
+
'架构': ['架构设计', '系统分析', '技术选型', '架构评审'],
|
|
67
|
+
'开发': ['代码编写', '代码审查', '调试', '重构'],
|
|
68
|
+
'测试': ['测试设计', '自动化测试', '性能测试', '质量评估'],
|
|
69
|
+
'运维': ['部署', '监控', '故障排查', '日志分析'],
|
|
70
|
+
'安全': ['安全审计', '漏洞扫描', '权限管理', '加密'],
|
|
71
|
+
'数据': ['数据分析', '数据清洗', '数据可视化', '机器学习'],
|
|
72
|
+
'产品': ['需求分析', '原型设计', '用户研究', '数据分析']
|
|
73
|
+
};
|
|
74
|
+
const DOMAIN_INTERESTS = {
|
|
75
|
+
'架构': ['架构设计', '微服务', '分布式系统', '性能优化'],
|
|
76
|
+
'开发': ['编程语言', '框架', '工具', '最佳实践'],
|
|
77
|
+
'测试': ['测试框架', '自动化', '质量指标', '持续集成'],
|
|
78
|
+
'运维': ['容器化', '云原生', '监控告警', '自动化运维'],
|
|
79
|
+
'安全': ['安全策略', '身份认证', '数据保护', '渗透测试'],
|
|
80
|
+
'数据': ['数据处理', '可视化', '机器学习', 'AI应用'],
|
|
81
|
+
'产品': ['用户体验', '需求管理', '数据分析', '市场趋势']
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Persona Design Engine - Allows agents to design their own persona
|
|
85
|
+
*/
|
|
86
|
+
export class PersonaDesignEngine {
|
|
87
|
+
currentPersona = null;
|
|
88
|
+
constructor(persona) {
|
|
89
|
+
if (persona) {
|
|
90
|
+
this.currentPersona = persona;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get available persona types
|
|
95
|
+
*/
|
|
96
|
+
getAvailableTypes() {
|
|
97
|
+
return Object.keys(PERSONA_TEMPLATES);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get template for a type
|
|
101
|
+
*/
|
|
102
|
+
getTemplate(type) {
|
|
103
|
+
return PERSONA_TEMPLATES[type] || PERSONA_TEMPLATES['custom'];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Design a new persona from request
|
|
107
|
+
*/
|
|
108
|
+
designPersona(request) {
|
|
109
|
+
const template = this.getTemplate(request.type || 'custom');
|
|
110
|
+
const now = new Date().toISOString();
|
|
111
|
+
// Build capabilities
|
|
112
|
+
let capabilities = template.capabilities;
|
|
113
|
+
if (request.domain && DOMAIN_CAPABILITIES[request.domain]) {
|
|
114
|
+
const domainCaps = DOMAIN_CAPABILITIES[request.domain];
|
|
115
|
+
capabilities = [...new Set([...capabilities, ...domainCaps])];
|
|
116
|
+
}
|
|
117
|
+
if (request.capabilities) {
|
|
118
|
+
capabilities = [...new Set([...capabilities, ...request.capabilities])];
|
|
119
|
+
}
|
|
120
|
+
// Build interests
|
|
121
|
+
let interests = template.interests;
|
|
122
|
+
if (request.domain && DOMAIN_INTERESTS[request.domain]) {
|
|
123
|
+
const domainInterests = DOMAIN_INTERESTS[request.domain];
|
|
124
|
+
interests = [...new Set([...interests, ...domainInterests])];
|
|
125
|
+
}
|
|
126
|
+
if (request.interests) {
|
|
127
|
+
interests = [...new Set([...interests, ...request.interests])];
|
|
128
|
+
}
|
|
129
|
+
// Build traits
|
|
130
|
+
let traits = template.traits;
|
|
131
|
+
if (request.traits) {
|
|
132
|
+
traits = [...new Set([...traits, ...request.traits])];
|
|
133
|
+
}
|
|
134
|
+
// Build greeting
|
|
135
|
+
const greeting = template.greeting.replace('{name}', request.name);
|
|
136
|
+
const persona = {
|
|
137
|
+
name: request.name,
|
|
138
|
+
description: `${request.name} - ${request.domain || '通用助手'}`,
|
|
139
|
+
capabilities,
|
|
140
|
+
personality: template.personality,
|
|
141
|
+
greeting,
|
|
142
|
+
interests,
|
|
143
|
+
soul: this.generateSoul(request),
|
|
144
|
+
traits,
|
|
145
|
+
backstory: template.backstory.replace('{name}', request.name),
|
|
146
|
+
memoryHistory: [],
|
|
147
|
+
createdAt: now,
|
|
148
|
+
updatedAt: now
|
|
149
|
+
};
|
|
150
|
+
this.currentPersona = persona;
|
|
151
|
+
return persona;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Generate soul description based on request
|
|
155
|
+
*/
|
|
156
|
+
generateSoul(request) {
|
|
157
|
+
const type = request.type || 'custom';
|
|
158
|
+
const domain = request.domain || '通用';
|
|
159
|
+
const souls = {
|
|
160
|
+
assistant: '我致力于成为用户的可靠伙伴,通过智慧和耐心帮助他们实现目标。',
|
|
161
|
+
developer: '我相信好的代码是一种艺术形式,值得用心打磨。每一行代码都应该清晰、高效、可维护。',
|
|
162
|
+
designer: '我相信设计的力量可以改变世界。好的设计不仅美观,更能解决问题、提升体验。',
|
|
163
|
+
reviewer: '我追求卓越,对质量有严格的要求。我相信细节决定成败,代码质量是产品成功的基石。',
|
|
164
|
+
manager: '我相信团队的力量。通过有效的协调和沟通,我们可以完成任何挑战。',
|
|
165
|
+
custom: `我是一个专注于${domain}领域的智能体,不断学习和进化。`
|
|
166
|
+
};
|
|
167
|
+
return souls[type] || souls.custom;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Update current persona with partial updates
|
|
171
|
+
*/
|
|
172
|
+
updatePersona(updates) {
|
|
173
|
+
if (!this.currentPersona) {
|
|
174
|
+
throw new Error('No current persona to update. Use designPersona() first.');
|
|
175
|
+
}
|
|
176
|
+
this.currentPersona = {
|
|
177
|
+
...this.currentPersona,
|
|
178
|
+
...updates,
|
|
179
|
+
updatedAt: new Date().toISOString()
|
|
180
|
+
};
|
|
181
|
+
return this.currentPersona;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get current persona
|
|
185
|
+
*/
|
|
186
|
+
getPersona() {
|
|
187
|
+
return this.currentPersona;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get persona as JSON string
|
|
191
|
+
*/
|
|
192
|
+
getPersonaJson() {
|
|
193
|
+
if (!this.currentPersona) {
|
|
194
|
+
return '{}';
|
|
195
|
+
}
|
|
196
|
+
return JSON.stringify(this.currentPersona, null, 2);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Add memory entry to persona
|
|
200
|
+
*/
|
|
201
|
+
addMemory(content, importance = 0.5, tags) {
|
|
202
|
+
if (!this.currentPersona) {
|
|
203
|
+
throw new Error('No current persona to add memory to.');
|
|
204
|
+
}
|
|
205
|
+
if (!this.currentPersona.memoryHistory) {
|
|
206
|
+
this.currentPersona.memoryHistory = [];
|
|
207
|
+
}
|
|
208
|
+
this.currentPersona.memoryHistory.push({
|
|
209
|
+
id: `memory_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`,
|
|
210
|
+
content,
|
|
211
|
+
timestamp: new Date().toISOString(),
|
|
212
|
+
importance,
|
|
213
|
+
tags
|
|
214
|
+
});
|
|
215
|
+
// Keep only last 50 memories
|
|
216
|
+
if (this.currentPersona.memoryHistory.length > 50) {
|
|
217
|
+
this.currentPersona.memoryHistory = this.currentPersona.memoryHistory.slice(-50);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Clear memory history
|
|
222
|
+
*/
|
|
223
|
+
clearMemory() {
|
|
224
|
+
if (this.currentPersona) {
|
|
225
|
+
this.currentPersona.memoryHistory = [];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Clone persona with new name
|
|
230
|
+
*/
|
|
231
|
+
clone(newName) {
|
|
232
|
+
if (!this.currentPersona) {
|
|
233
|
+
throw new Error('No current persona to clone.');
|
|
234
|
+
}
|
|
235
|
+
const cloned = { ...this.currentPersona };
|
|
236
|
+
cloned.name = newName;
|
|
237
|
+
cloned.description = `${newName} - ${this.currentPersona.description.split(' - ')[1] || '克隆自' + this.currentPersona.name}`;
|
|
238
|
+
cloned.greeting = cloned.greeting.replace(this.currentPersona.name, newName);
|
|
239
|
+
cloned.createdAt = new Date().toISOString();
|
|
240
|
+
cloned.updatedAt = new Date().toISOString();
|
|
241
|
+
cloned.memoryHistory = [];
|
|
242
|
+
return cloned;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Export persona for network sharing
|
|
246
|
+
*/
|
|
247
|
+
exportForNetwork() {
|
|
248
|
+
if (!this.currentPersona) {
|
|
249
|
+
return '';
|
|
250
|
+
}
|
|
251
|
+
return JSON.stringify({
|
|
252
|
+
name: this.currentPersona.name,
|
|
253
|
+
description: this.currentPersona.description,
|
|
254
|
+
capabilities: this.currentPersona.capabilities,
|
|
255
|
+
interests: this.currentPersona.interests,
|
|
256
|
+
personality: this.currentPersona.personality,
|
|
257
|
+
greeting: this.currentPersona.greeting
|
|
258
|
+
}, null, 2);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Import persona from network
|
|
262
|
+
*/
|
|
263
|
+
importFromNetwork(json) {
|
|
264
|
+
try {
|
|
265
|
+
const data = JSON.parse(json);
|
|
266
|
+
const now = new Date().toISOString();
|
|
267
|
+
const persona = {
|
|
268
|
+
name: data.name || 'Unknown',
|
|
269
|
+
description: data.description || '',
|
|
270
|
+
capabilities: data.capabilities || [],
|
|
271
|
+
personality: data.personality || '',
|
|
272
|
+
greeting: data.greeting || `你好!我是 ${data.name || 'Unknown'}。`,
|
|
273
|
+
interests: data.interests || [],
|
|
274
|
+
soul: data.soul,
|
|
275
|
+
traits: data.traits,
|
|
276
|
+
backstory: data.backstory,
|
|
277
|
+
memoryHistory: data.memoryHistory || [],
|
|
278
|
+
createdAt: now,
|
|
279
|
+
updatedAt: now
|
|
280
|
+
};
|
|
281
|
+
return persona;
|
|
282
|
+
}
|
|
283
|
+
catch (e) {
|
|
284
|
+
throw new Error(`Failed to import persona: ${e}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Factory function
|
|
289
|
+
export function createPersonaDesignEngine(persona) {
|
|
290
|
+
return new PersonaDesignEngine(persona);
|
|
291
|
+
}
|
|
292
|
+
// Singleton instance
|
|
293
|
+
let singletonInstance = null;
|
|
294
|
+
export function getPersonaDesignEngine() {
|
|
295
|
+
if (!singletonInstance) {
|
|
296
|
+
singletonInstance = new PersonaDesignEngine();
|
|
297
|
+
}
|
|
298
|
+
return singletonInstance;
|
|
299
|
+
}
|