@bolloon/bolloon-agent 0.3.44 → 0.3.46
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/README.md +135 -135
- package/bin/bolloon-cli.cjs +183 -183
- package/bin/bolloon-daemon.sh +207 -0
- package/bin/bolloon.cjs +0 -0
- package/dist/agents/agent-identity.js +17 -0
- package/dist/agents/constraint-layer.js +19 -19
- package/dist/agents/judgment-protocol.js +14 -14
- package/dist/agents/loop-review.js +21 -5
- package/dist/agents/pi-sdk-types.js +12 -12
- package/dist/agents/pi-sdk.js +197 -102
- package/dist/agents/skill-writer.js +19 -0
- package/dist/agents/workflow-pivot-loop.js +3 -3
- package/dist/bollharness/src/scripts/deploy-guard.js +8 -8
- package/dist/bollharness-integration/context-router-judgment.js +4 -4
- package/dist/bollharness-integration/context-router.js +292 -292
- package/dist/bollharness-integration/gate-state-machine.js +13 -13
- package/dist/bollharness-integration/llm-judgment-engine.js +134 -134
- package/dist/bollharness-integration/skill-adapter.js +21 -21
- package/dist/bootstrap/chat-archiver.js +14 -14
- package/dist/bootstrap/context-os.js +21 -21
- package/dist/bootstrap/memory-compressor.js +29 -13
- package/dist/cli-entry.js +47 -37
- package/dist/constraint-runtime/reference_data/archive_surface_snapshot.json +63 -0
- package/dist/constraint-runtime/reference_data/commands_snapshot.json +1037 -0
- package/dist/constraint-runtime/reference_data/subsystems/assistant.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/bootstrap.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/bridge.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/buddy.json +13 -0
- package/dist/constraint-runtime/reference_data/subsystems/cli.json +26 -0
- package/dist/constraint-runtime/reference_data/subsystems/components.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/constants.json +28 -0
- package/dist/constraint-runtime/reference_data/subsystems/coordinator.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/entrypoints.json +15 -0
- package/dist/constraint-runtime/reference_data/subsystems/hooks.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/keybindings.json +21 -0
- package/dist/constraint-runtime/reference_data/subsystems/memdir.json +15 -0
- package/dist/constraint-runtime/reference_data/subsystems/migrations.json +18 -0
- package/dist/constraint-runtime/reference_data/subsystems/moreright.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/native_ts.json +11 -0
- package/dist/constraint-runtime/reference_data/subsystems/outputStyles.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/plugins.json +9 -0
- package/dist/constraint-runtime/reference_data/subsystems/remote.json +11 -0
- package/dist/constraint-runtime/reference_data/subsystems/schemas.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/screens.json +10 -0
- package/dist/constraint-runtime/reference_data/subsystems/server.json +10 -0
- package/dist/constraint-runtime/reference_data/subsystems/services.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/skills.json +27 -0
- package/dist/constraint-runtime/reference_data/subsystems/state.json +13 -0
- package/dist/constraint-runtime/reference_data/subsystems/types.json +18 -0
- package/dist/constraint-runtime/reference_data/subsystems/upstreamproxy.json +9 -0
- package/dist/constraint-runtime/reference_data/subsystems/utils.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/vim.json +12 -0
- package/dist/constraint-runtime/reference_data/subsystems/voice.json +8 -0
- package/dist/constraint-runtime/reference_data/tools_snapshot.json +922 -0
- package/dist/constraint-runtime/setup.js +1 -1
- package/dist/constraint-runtime/tools/PolymarketSDK/cancelOrder.d.ts +13 -3
- package/dist/constraint-runtime/tools/PolymarketSDK/cancelOrder.js +16 -4
- package/dist/constraint-runtime/tools/PolymarketSDK/clobShared.d.ts +50 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/clobShared.js +78 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/createOrder.d.ts +24 -3
- package/dist/constraint-runtime/tools/PolymarketSDK/createOrder.js +31 -4
- package/dist/constraint-runtime/tools/PolymarketSDK/getMarket.d.ts +1 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/getMarket.js +14 -3
- package/dist/constraint-runtime/tools/PolymarketSDK/getOrders.d.ts +11 -2
- package/dist/constraint-runtime/tools/PolymarketSDK/getOrders.js +23 -4
- package/dist/constraint-runtime/tools/PolymarketSDK/listMarkets.d.ts +4 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/listMarkets.js +22 -2
- package/dist/context-compaction/auto-compact.js +7 -7
- package/dist/electron/config.js.map +1 -0
- package/dist/electron/dialogs.js.map +1 -0
- package/dist/electron/first-run.js +54 -54
- package/dist/electron/first-run.js.map +1 -0
- package/dist/electron/ipc.js.map +1 -0
- package/dist/electron/logger.js.map +1 -0
- package/dist/electron/main.js.map +1 -0
- package/dist/electron/menu.js.map +1 -0
- package/dist/electron/paths.js.map +1 -0
- package/dist/electron/server.js.map +1 -0
- package/dist/electron/tray.js.map +1 -0
- package/dist/electron/window.js.map +1 -0
- package/dist/electron-build/electron/first-run.js +54 -54
- package/dist/electron-preload.js.map +1 -1
- package/dist/electron.js.map +1 -1
- package/dist/index.js +113 -113
- package/dist/llm/llm-judgment-client.js +102 -102
- package/dist/llm/pi-ai.js +48 -48
- package/dist/llm/system-prompt/layers/channel/human-async.md +41 -41
- package/dist/llm/system-prompt/layers/channel/local.md +14 -14
- package/dist/llm/system-prompt/layers/channel/p2p-agent.md +18 -18
- package/dist/llm/system-prompt/layers/channel/p2p-peer-sync.md +51 -51
- package/dist/llm/system-prompt/layers/channel/p2p-proactive.md +43 -43
- package/dist/llm/system-prompt/layers/channel/p2p-visitor.md +19 -19
- package/dist/llm/system-prompt/layers/channel/session-handoff.md +61 -61
- package/dist/llm/system-prompt/layers/core/artifacts_storage.md +89 -89
- package/dist/llm/system-prompt/layers/core/evenhandedness.md +21 -21
- package/dist/llm/system-prompt/layers/core/external-engagement.md +73 -73
- package/dist/llm/system-prompt/layers/core/hibs_reminders.md +15 -15
- package/dist/llm/system-prompt/layers/core/identity.md +48 -48
- package/dist/llm/system-prompt/layers/core/knowledge.md +17 -17
- package/dist/llm/system-prompt/layers/core/memory_system.md +12 -12
- package/dist/llm/system-prompt/layers/core/network_filesystem.md +28 -28
- package/dist/llm/system-prompt/layers/core/refusal.md +37 -37
- package/dist/llm/system-prompt/layers/core/tone.md +31 -31
- package/dist/llm/system-prompt/layers/core/tools.thin.md +13 -13
- package/dist/llm/system-prompt/layers/core/wellbeing.md +41 -41
- package/dist/llm/system-prompt/layers/role/architect.md +20 -20
- package/dist/llm/system-prompt/layers/role/expert.md +19 -19
- package/dist/llm/system-prompt/layers/role/implementer.md +15 -15
- package/dist/llm/system-prompt/layers/role/security.md +15 -15
- package/dist/llm/system-prompt/layers/tool/artifacts.md +72 -72
- package/dist/llm/system-prompt/layers/tool/bash.md +25 -25
- package/dist/llm/system-prompt/layers/tool/goal_handoff.md +77 -77
- package/dist/llm/system-prompt/layers/tool/hibs_api.md +171 -171
- package/dist/llm/system-prompt/layers/tool/image_search.md +70 -70
- package/dist/llm/system-prompt/layers/tool/manifest.md +89 -89
- package/dist/llm/system-prompt/layers/tool/mcp_apps.md +53 -53
- package/dist/llm/system-prompt/layers/tool/p2p_request.md +61 -61
- package/dist/llm/system-prompt/layers/tool/web_search.md +83 -83
- package/dist/llm/tool-manifest/ask_user_input.js +1 -1
- package/dist/llm/tool-manifest/bash.js +3 -3
- package/dist/llm/tool-manifest/create_file.js +4 -4
- package/dist/llm/tool-manifest/fetch_sports_data.js +3 -3
- package/dist/llm/tool-manifest/image_search.js +2 -2
- package/dist/llm/tool-manifest/index.js +59 -0
- package/dist/llm/tool-manifest/mcp.js +2 -2
- package/dist/llm/tool-manifest/message_compose.js +3 -3
- package/dist/llm/tool-manifest/places.js +2 -2
- package/dist/llm/tool-manifest/present_files.js +1 -1
- package/dist/llm/tool-manifest/recipe.js +2 -2
- package/dist/llm/tool-manifest/str_replace.js +5 -5
- package/dist/llm/tool-manifest/view.js +3 -3
- package/dist/llm/tool-manifest/weather.js +4 -4
- package/dist/llm/tool-manifest/web.js +4 -4
- package/dist/orbitdb/cid-database.js +41 -0
- package/dist/orbitdb/did-catalog-replication.js +199 -0
- package/dist/orbitdb/trajectory-store.js +150 -0
- package/dist/pi-ecosystem-judgment/causal-judge.js +51 -51
- package/dist/pi-ecosystem-judgment/distill-prompt.js +42 -42
- package/dist/pi-ecosystem-judgment/distillation.js +14 -14
- package/dist/pi-ecosystem-judgment/monitor-gate.js +28 -28
- package/dist/pi-ecosystem-judgment/value-injection.js +102 -102
- package/dist/security/context-router-tool.js +15 -15
- package/dist/storage/did-catalog-bridge.js +271 -0
- package/dist/utils/auto-update.js.map +1 -0
- package/dist/web/api-config.html +779 -779
- package/dist/web/client-hearth.js +10 -10
- package/dist/web/client.js +141 -0
- package/dist/web/client.js.map +7 -0
- package/dist/web/components/wallet-viem.mjs +118 -118
- package/dist/web/index.html +472 -424
- package/dist/web/manifest.json +20 -20
- package/dist/web/server.js +290 -13
- package/dist/web/style.css +4946 -4914
- package/package.json +193 -193
- package/scripts/build-cli.js +215 -215
- package/scripts/build-web.ts +130 -130
- package/scripts/postinstall.js +152 -152
- package/bin/bolloon.js +0 -157
- package/dist/pi-ecosystem-colony/index.js +0 -365
- package/dist/social/ant-colony/AdaptiveHeartbeat.js +0 -101
- package/dist/social/ant-colony/PheromoneEngine.js +0 -227
- package/dist/social/ant-colony/index.js +0 -6
- package/dist/social/ant-colony/types.js +0 -24
- package/dist/test/ai-judgment-test.js +0 -80
- package/dist/test/bollharness-integration.test.js +0 -318
- package/dist/test/channel-agent-multi-dialogue.js +0 -205
- package/dist/test/channel-heartbeat-agent-test.js +0 -201
- package/dist/test/constraint-layer.test.js +0 -164
- package/dist/test/diap-identity-test.js +0 -172
- package/dist/test/diap-quick-test.js +0 -62
- package/dist/test/global-shared-context.test.js +0 -315
- package/dist/test/harness-judgment-injection.test.js +0 -246
- package/dist/test/harness-workflow-integrator-test.js +0 -228
- package/dist/test/human-value-store.test.js +0 -243
- package/dist/test/hybrid-integration-test.js +0 -118
- package/dist/test/hybrid-messenger-verify.js +0 -55
- package/dist/test/iroh-bistream-debug.js +0 -38
- package/dist/test/iroh-communication.test.js +0 -66
- package/dist/test/iroh-debug-test.js +0 -57
- package/dist/test/iroh-diap-test.js +0 -71
- package/dist/test/iroh-direct-connect.js +0 -55
- package/dist/test/iroh-e2e-fixed.js +0 -89
- package/dist/test/iroh-e2e-same-process.js +0 -63
- package/dist/test/iroh-e2e.js +0 -66
- package/dist/test/iroh-final-e2e.js +0 -72
- package/dist/test/iroh-relay-test.js +0 -37
- package/dist/test/iroh-simple-test.js +0 -41
- package/dist/test/iroh-transport-verify.js +0 -54
- package/dist/test/iroh-transport.test.js +0 -37
- package/dist/test/iroh-two-nodes.js +0 -70
- package/dist/test/iroh-verify.js +0 -44
- package/dist/test/judgment-decision.test.js +0 -219
- package/dist/test/llm-judgment-integration.test.js +0 -220
- package/dist/test/p2p-agent-complex-dialogue.js +0 -385
- package/dist/test/p2p-agent-dialogue.js +0 -341
- package/dist/test/p2p-agent-full-bidirectional.js +0 -510
- package/dist/test/p2p-agent-harness-flow.js +0 -437
- package/dist/test/p2p-agent-harness-single.js +0 -143
- package/dist/test/p2p-ai-dialogue-test.js +0 -318
- package/dist/test/p2p-cid-connect-test.js +0 -195
- package/dist/test/p2p-connect-receiver.js +0 -69
- package/dist/test/p2p-doc-transfer.js +0 -110
- package/dist/test/p2p-identity-page-test.js +0 -77
- package/dist/test/p2p-iroh-test.js +0 -171
- package/dist/test/p2p-minimal-test.js +0 -241
- package/dist/test/p2p-node-1.js +0 -148
- package/dist/test/p2p-node-2.js +0 -148
- package/dist/test/p2p-server.js +0 -281
- package/dist/test/p2p-two-nodes-test.js +0 -438
- package/dist/test/pi-sdk.test.js +0 -44
- package/dist/test/set-persona.js +0 -40
- package/dist/test/simple.test.js +0 -9
- package/dist/test/storage-integration.test.js +0 -150
- package/dist/test/subagent-manager.test.js +0 -276
- package/dist/test/test-gate-flow.test.js +0 -81
- package/dist/test/workflow-engine.test.js +0 -87
- package/dist/test/workflow-pivot-loop.test.js +0 -246
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Bolloon Daemon - 守护进程启动脚本
|
|
3
|
+
# 支持自动重启、日志轮转、PID 管理
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
APP_NAME="bolloon"
|
|
8
|
+
APP_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
9
|
+
PID_FILE="$HOME/.bolloon/daemon.pid"
|
|
10
|
+
LOG_FILE="$HOME/.bolloon/daemon.log"
|
|
11
|
+
MAX_RESTARTS=5
|
|
12
|
+
RESTART_DELAY=5
|
|
13
|
+
|
|
14
|
+
# 颜色输出
|
|
15
|
+
RED='\033[0;31m'
|
|
16
|
+
GREEN='\033[0;32m'
|
|
17
|
+
YELLOW='\033[1;33m'
|
|
18
|
+
NC='\033[0m' # No Color
|
|
19
|
+
|
|
20
|
+
log() {
|
|
21
|
+
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
warn() {
|
|
25
|
+
echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] WARN:${NC} $1"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
error() {
|
|
29
|
+
echo -e "${RED}[$(date '+%Y-%m-%d %H:%M:%S')] ERROR:${NC} $1"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# 获取 PID
|
|
33
|
+
get_pid() {
|
|
34
|
+
if [ -f "$PID_FILE" ]; then
|
|
35
|
+
cat "$PID_FILE"
|
|
36
|
+
fi
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# 检查进程是否运行
|
|
40
|
+
is_running() {
|
|
41
|
+
local pid=$(get_pid)
|
|
42
|
+
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
|
43
|
+
return 0
|
|
44
|
+
fi
|
|
45
|
+
return 1
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# 启动守护进程
|
|
49
|
+
start() {
|
|
50
|
+
if is_running; then
|
|
51
|
+
log "Bolloon 已在运行 (PID: $(get_pid))"
|
|
52
|
+
return 0
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
log "启动 Bolloon 守护进程..."
|
|
56
|
+
|
|
57
|
+
# 确保日志目录存在
|
|
58
|
+
mkdir -p "$(dirname "$LOG_FILE")"
|
|
59
|
+
|
|
60
|
+
# 启动进程
|
|
61
|
+
cd "$APP_DIR"
|
|
62
|
+
nohup npx tsx src/index.ts >> "$LOG_FILE" 2>&1 &
|
|
63
|
+
local pid=$!
|
|
64
|
+
|
|
65
|
+
# 保存 PID
|
|
66
|
+
echo "$pid" > "$PID_FILE"
|
|
67
|
+
log "Bolloon 已启动 (PID: $pid)"
|
|
68
|
+
log "日志文件: $LOG_FILE"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# 停止守护进程
|
|
72
|
+
stop() {
|
|
73
|
+
local pid=$(get_pid)
|
|
74
|
+
|
|
75
|
+
if [ -z "$pid" ]; then
|
|
76
|
+
warn "Bolloon 未运行"
|
|
77
|
+
return 0
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
log "停止 Bolloon (PID: $pid)..."
|
|
81
|
+
|
|
82
|
+
# 发送 SIGTERM
|
|
83
|
+
kill -TERM "$pid" 2>/dev/null || true
|
|
84
|
+
|
|
85
|
+
# 等待进程退出
|
|
86
|
+
local count=0
|
|
87
|
+
while kill -0 "$pid" 2>/dev/null && [ $count -lt 10 ]; do
|
|
88
|
+
sleep 1
|
|
89
|
+
count=$((count + 1))
|
|
90
|
+
done
|
|
91
|
+
|
|
92
|
+
# 如果还在运行,强制终止
|
|
93
|
+
if kill -0 "$pid" 2>/dev/null; then
|
|
94
|
+
warn "进程未响应,发送 SIGKILL..."
|
|
95
|
+
kill -KILL "$pid" 2>/dev/null || true
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
# 清理 PID 文件
|
|
99
|
+
rm -f "$PID_FILE"
|
|
100
|
+
log "Bolloon 已停止"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# 重启守护进程
|
|
104
|
+
restart() {
|
|
105
|
+
log "重启 Bolloon..."
|
|
106
|
+
stop
|
|
107
|
+
sleep 2
|
|
108
|
+
start
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
# 查看状态
|
|
112
|
+
status() {
|
|
113
|
+
if is_running; then
|
|
114
|
+
log "Bolloon 运行中 (PID: $(get_pid))"
|
|
115
|
+
# 显示资源使用
|
|
116
|
+
local pid=$(get_pid)
|
|
117
|
+
if [ -n "$pid" ]; then
|
|
118
|
+
ps -p "$pid" -o %cpu,%mem,etime 2>/dev/null | tail -1 || true
|
|
119
|
+
fi
|
|
120
|
+
else
|
|
121
|
+
warn "Bolloon 未运行"
|
|
122
|
+
fi
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
# 查看日志
|
|
126
|
+
logs() {
|
|
127
|
+
if [ -f "$LOG_FILE" ]; then
|
|
128
|
+
tail -100 "$LOG_FILE"
|
|
129
|
+
else
|
|
130
|
+
warn "日志文件不存在: $LOG_FILE"
|
|
131
|
+
fi
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# 健康检查
|
|
135
|
+
health() {
|
|
136
|
+
local port=${PORT:-54188}
|
|
137
|
+
local response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$port/api/health" 2>/dev/null || echo "000")
|
|
138
|
+
|
|
139
|
+
if [ "$response" = "200" ]; then
|
|
140
|
+
log "健康检查通过"
|
|
141
|
+
curl -s "http://localhost:$port/api/health" 2>/dev/null | head -5
|
|
142
|
+
else
|
|
143
|
+
error "健康检查失败 (HTTP $response)"
|
|
144
|
+
return 1
|
|
145
|
+
fi
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
# 清理日志
|
|
149
|
+
clean_logs() {
|
|
150
|
+
if [ -f "$LOG_FILE" ]; then
|
|
151
|
+
local size=$(du -h "$LOG_FILE" | cut -f1)
|
|
152
|
+
log "当前日志大小: $size"
|
|
153
|
+
> "$LOG_FILE"
|
|
154
|
+
log "日志已清空"
|
|
155
|
+
fi
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
# 显示帮助
|
|
159
|
+
show_help() {
|
|
160
|
+
echo "Bolloon Daemon 守护进程管理脚本"
|
|
161
|
+
echo ""
|
|
162
|
+
echo "用法: $0 [命令]"
|
|
163
|
+
echo ""
|
|
164
|
+
echo "命令:"
|
|
165
|
+
echo " start 启动 Bolloon 守护进程"
|
|
166
|
+
echo " stop 停止 Bolloon 守护进程"
|
|
167
|
+
echo " restart 重启 Bolloon 守护进程"
|
|
168
|
+
echo " status 查看运行状态"
|
|
169
|
+
echo " logs 查看最近日志"
|
|
170
|
+
echo " health 健康检查"
|
|
171
|
+
echo " clean 清空日志"
|
|
172
|
+
echo " help 显示帮助"
|
|
173
|
+
echo ""
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
# 主逻辑
|
|
177
|
+
case "${1:-help}" in
|
|
178
|
+
start)
|
|
179
|
+
start
|
|
180
|
+
;;
|
|
181
|
+
stop)
|
|
182
|
+
stop
|
|
183
|
+
;;
|
|
184
|
+
restart)
|
|
185
|
+
restart
|
|
186
|
+
;;
|
|
187
|
+
status)
|
|
188
|
+
status
|
|
189
|
+
;;
|
|
190
|
+
logs)
|
|
191
|
+
logs
|
|
192
|
+
;;
|
|
193
|
+
health)
|
|
194
|
+
health
|
|
195
|
+
;;
|
|
196
|
+
clean)
|
|
197
|
+
clean_logs
|
|
198
|
+
;;
|
|
199
|
+
help|--help|-h)
|
|
200
|
+
show_help
|
|
201
|
+
;;
|
|
202
|
+
*)
|
|
203
|
+
error "未知命令: $1"
|
|
204
|
+
show_help
|
|
205
|
+
exit 1
|
|
206
|
+
;;
|
|
207
|
+
esac
|
package/bin/bolloon.cjs
CHANGED
|
File without changes
|
|
@@ -17,6 +17,19 @@ import * as path from 'path';
|
|
|
17
17
|
import * as os from 'os';
|
|
18
18
|
import { KeyManager } from '@diap/sdk';
|
|
19
19
|
const AGENT_KEYS_DIR = path.join(os.homedir(), '.bolloon', 'agent-keys');
|
|
20
|
+
/** 读取用户唯一 DID (与 server loadOrCreateUserIdentity 同源, 归属字段用) */
|
|
21
|
+
export function getUserOwnerDid() {
|
|
22
|
+
try {
|
|
23
|
+
const f = path.join(os.homedir(), '.bolloon', 'identity', 'user.json');
|
|
24
|
+
if (fs.existsSync(f)) {
|
|
25
|
+
const j = JSON.parse(fs.readFileSync(f, 'utf-8'));
|
|
26
|
+
if (j.did)
|
|
27
|
+
return j.did;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch { /* 无 user.json → 无归属 */ }
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
20
33
|
/**
|
|
21
34
|
* 加载或创建 agent 的持久化 diap 身份
|
|
22
35
|
* - 文件存在 → 从私钥重建 keyPair
|
|
@@ -44,6 +57,7 @@ export function loadOrCreateAgentIdentity(agentId) {
|
|
|
44
57
|
did: kp.did,
|
|
45
58
|
createdAt: j.createdAt || 'unknown',
|
|
46
59
|
reused: true,
|
|
60
|
+
ownerDid: j.ownerDid || getUserOwnerDid(),
|
|
47
61
|
};
|
|
48
62
|
}
|
|
49
63
|
}
|
|
@@ -70,6 +84,8 @@ export function loadOrCreateAgentIdentity(agentId) {
|
|
|
70
84
|
lastUsedAt: createdAt,
|
|
71
85
|
agentId,
|
|
72
86
|
version: '1.0',
|
|
87
|
+
// 2026-08-09: 归属用户唯一 DID — DIAP 智能体身份全部归到用户身份下
|
|
88
|
+
ownerDid: getUserOwnerDid(),
|
|
73
89
|
};
|
|
74
90
|
fs.writeFileSync(fp, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
75
91
|
try {
|
|
@@ -83,6 +99,7 @@ export function loadOrCreateAgentIdentity(agentId) {
|
|
|
83
99
|
did: kp.did,
|
|
84
100
|
createdAt,
|
|
85
101
|
reused: false,
|
|
102
|
+
ownerDid: data.ownerDid,
|
|
86
103
|
};
|
|
87
104
|
}
|
|
88
105
|
/**
|
|
@@ -7,25 +7,25 @@ import { ToolPermissionContext, BudgetTracker } from '@bolloon/constraint-runtim
|
|
|
7
7
|
* System prompt for constraint layer
|
|
8
8
|
* Defines boundaries and autonomous permissions
|
|
9
9
|
*/
|
|
10
|
-
export const SYSTEM_PROMPT = `
|
|
11
|
-
你是一个文档处理Agent,在以下规则下运行:
|
|
12
|
-
|
|
13
|
-
【边界规则】
|
|
14
|
-
1. 只处理:txt, md, pdf, docx 格式文档
|
|
15
|
-
2. 不修改原始文件,只输出改进版本
|
|
16
|
-
3. 发送前必须记录操作日志
|
|
17
|
-
|
|
18
|
-
【自主权限】
|
|
19
|
-
- ✅ 自主决定:摘要详细程度、chunk分块策略
|
|
20
|
-
- ✅ 自主决定:重试次数(最多3次)
|
|
21
|
-
- ✅ 自主决定:是否需要补充信息
|
|
22
|
-
- ❌ 必须确认:首次向新对等节点发送文档
|
|
23
|
-
- ❌ 必须确认:删除操作
|
|
24
|
-
|
|
25
|
-
【敏感操作拦截】
|
|
26
|
-
if (操作 === '发送文档' && 对等节点不在已知列表) {
|
|
27
|
-
拦截 → 记录 → 等待确认
|
|
28
|
-
}
|
|
10
|
+
export const SYSTEM_PROMPT = `
|
|
11
|
+
你是一个文档处理Agent,在以下规则下运行:
|
|
12
|
+
|
|
13
|
+
【边界规则】
|
|
14
|
+
1. 只处理:txt, md, pdf, docx 格式文档
|
|
15
|
+
2. 不修改原始文件,只输出改进版本
|
|
16
|
+
3. 发送前必须记录操作日志
|
|
17
|
+
|
|
18
|
+
【自主权限】
|
|
19
|
+
- ✅ 自主决定:摘要详细程度、chunk分块策略
|
|
20
|
+
- ✅ 自主决定:重试次数(最多3次)
|
|
21
|
+
- ✅ 自主决定:是否需要补充信息
|
|
22
|
+
- ❌ 必须确认:首次向新对等节点发送文档
|
|
23
|
+
- ❌ 必须确认:删除操作
|
|
24
|
+
|
|
25
|
+
【敏感操作拦截】
|
|
26
|
+
if (操作 === '发送文档' && 对等节点不在已知列表) {
|
|
27
|
+
拦截 → 记录 → 等待确认
|
|
28
|
+
}
|
|
29
29
|
`;
|
|
30
30
|
/**
|
|
31
31
|
* Actions that can be executed autonomously without confirmation
|
|
@@ -148,20 +148,20 @@ export async function distillDissent(ask) {
|
|
|
148
148
|
.slice(-10)
|
|
149
149
|
.flatMap((j) => j.reasons || [])
|
|
150
150
|
.slice(0, 20);
|
|
151
|
-
const prompt = `你是用户的判断力代理. 用户发起了一个决定: "${ask.decision}"
|
|
152
|
-
${ask.context ? `\n补充: ${ask.context}` : ''}
|
|
153
|
-
|
|
154
|
-
[用户价值画像] ${valueHint}
|
|
155
|
-
[相关历史判断 (${relevant.length} 条)] ${relevant.slice(0, 3).map((j) => j.decision || '').join(' | ').slice(0, 300)}
|
|
156
|
-
[历史理由样本] ${recentReasons.join(' | ').slice(0, 400) || '(无)'}
|
|
157
|
-
|
|
158
|
-
请基于上述判断力, 生成正好 3 个"反方观点" (用户应该考虑但可能忽略的风险/盲点).
|
|
159
|
-
要求:
|
|
160
|
-
- 每个反方 1-2 句, 总长 < 80 字
|
|
161
|
-
- 必须是这个特定决定的"反对声音", 不是通用建议
|
|
162
|
-
- 第 1 个: 历史/经验类风险
|
|
163
|
-
- 第 2 个: 关系/信任类风险
|
|
164
|
-
- 第 3 个: 隐藏代价/时间类风险
|
|
151
|
+
const prompt = `你是用户的判断力代理. 用户发起了一个决定: "${ask.decision}"
|
|
152
|
+
${ask.context ? `\n补充: ${ask.context}` : ''}
|
|
153
|
+
|
|
154
|
+
[用户价值画像] ${valueHint}
|
|
155
|
+
[相关历史判断 (${relevant.length} 条)] ${relevant.slice(0, 3).map((j) => j.decision || '').join(' | ').slice(0, 300)}
|
|
156
|
+
[历史理由样本] ${recentReasons.join(' | ').slice(0, 400) || '(无)'}
|
|
157
|
+
|
|
158
|
+
请基于上述判断力, 生成正好 3 个"反方观点" (用户应该考虑但可能忽略的风险/盲点).
|
|
159
|
+
要求:
|
|
160
|
+
- 每个反方 1-2 句, 总长 < 80 字
|
|
161
|
+
- 必须是这个特定决定的"反对声音", 不是通用建议
|
|
162
|
+
- 第 1 个: 历史/经验类风险
|
|
163
|
+
- 第 2 个: 关系/信任类风险
|
|
164
|
+
- 第 3 个: 隐藏代价/时间类风险
|
|
165
165
|
- 用 JSON 数组返回: ["反方1", "反方2", "反方3"]`;
|
|
166
166
|
// LLM 调用 (OpenAI 兼容, 复用 p2p-chat-tools 的方式)
|
|
167
167
|
let dissents = [];
|
|
@@ -46,11 +46,27 @@ export function decideAfterReview(state, maxReviews = DEFAULT_MAX_REVIEWS) {
|
|
|
46
46
|
export function buildReviewHint(state, maxReviews = DEFAULT_MAX_REVIEWS) {
|
|
47
47
|
const intent = (state.userIntent || '').trim() || '(无)';
|
|
48
48
|
const tools = state.completedTools.length ? state.completedTools.join(', ') : '(尚未执行工具)';
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
// 2026-08-09: 行动日志 — 逐条列出已完成动作 + 结果摘要, 让 LLM 对照目标核查
|
|
50
|
+
// (旧版只有工具名, LLM 容易潦草自查; 带结果才能判断"这一步到底做完了没")
|
|
51
|
+
let actionLines = '';
|
|
52
|
+
if (state.actionLog && state.actionLog.length > 0) {
|
|
53
|
+
actionLines = '\n本轮已执行动作 (逐条):\n' + state.actionLog
|
|
54
|
+
.map((a, i) => {
|
|
55
|
+
const args = a.argsPreview ? `(${a.argsPreview.slice(0, 80)})` : '';
|
|
56
|
+
const res = a.success
|
|
57
|
+
? `✓ ${(a.resultPreview || 'ok').slice(0, 120)}`
|
|
58
|
+
: `✗ ${(a.resultPreview || 'failed').slice(0, 120)}`;
|
|
59
|
+
return ` ${i + 1}. ${a.tool}${args} → ${res}`;
|
|
60
|
+
})
|
|
61
|
+
.join('\n');
|
|
62
|
+
}
|
|
63
|
+
return (`[目标对齐 review ${state.reviewsDone + 1}/${maxReviews}]` +
|
|
64
|
+
`\n用户需求: ${intent.slice(0, 300)}` +
|
|
65
|
+
actionLines +
|
|
66
|
+
`\n已完成工具: ${tools}` +
|
|
67
|
+
`\n请对照需求逐条自查: 上面每一条动作是否真正完成了对应的子目标? 还有未完成/可深挖的子目标 → 继续调用工具推进 (注意: 同一动作已完成就不要重复执行, 直接基于已有结果推进下一步); ` +
|
|
68
|
+
`若已满足用户原始需求 → 直接输出 <final gen> 结束.` +
|
|
69
|
+
`\n[重要] 如果你要结束, 请先逐条对照「用户需求」确认每一项都已完成, 不要因为做了一部分就潦草收尾.`);
|
|
54
70
|
}
|
|
55
71
|
/** 布尔门: 是否该继续 review (测试/消融快速断言) */
|
|
56
72
|
export function shouldReviewAgain(state, maxReviews = DEFAULT_MAX_REVIEWS) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export const TOOL_DEFINITIONS = `
|
|
2
|
-
可用工具:
|
|
3
|
-
1. read_document(path) - 读取文档内容,支持 .txt, .md, .pdf, .docx
|
|
4
|
-
2. summarize_document(path, context?) - 总结文档内容,可选提供上下文
|
|
5
|
-
3. improve_document(path, requirements) - 改进文档,需提供文件路径和改进要求
|
|
6
|
-
4. list_peers() - 列出已连接的对等节点
|
|
7
|
-
5. send_message(peer_id, message) - 向指定对等节点发送消息
|
|
8
|
-
6. broadcast_message(message) - 向所有对等节点广播消息
|
|
9
|
-
7. get_identity() - 获取当前智能体身份信息
|
|
10
|
-
8. set_persona(persona_json) - 更新智能体 persona,包含 name、description、personality、greeting 等
|
|
11
|
-
9. run_workflow(steps) - 执行预定义工作流
|
|
12
|
-
10. get_operation_logs() - 获取操作日志
|
|
1
|
+
export const TOOL_DEFINITIONS = `
|
|
2
|
+
可用工具:
|
|
3
|
+
1. read_document(path) - 读取文档内容,支持 .txt, .md, .pdf, .docx
|
|
4
|
+
2. summarize_document(path, context?) - 总结文档内容,可选提供上下文
|
|
5
|
+
3. improve_document(path, requirements) - 改进文档,需提供文件路径和改进要求
|
|
6
|
+
4. list_peers() - 列出已连接的对等节点
|
|
7
|
+
5. send_message(peer_id, message) - 向指定对等节点发送消息
|
|
8
|
+
6. broadcast_message(message) - 向所有对等节点广播消息
|
|
9
|
+
7. get_identity() - 获取当前智能体身份信息
|
|
10
|
+
8. set_persona(persona_json) - 更新智能体 persona,包含 name、description、personality、greeting 等
|
|
11
|
+
9. run_workflow(steps) - 执行预定义工作流
|
|
12
|
+
10. get_operation_logs() - 获取操作日志
|
|
13
13
|
`;
|