@bolloon/bolloon-agent 0.4.14 → 0.4.15

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 (213) hide show
  1. package/README.md +127 -127
  2. package/bin/bolloon-cli.cjs +183 -183
  3. package/bin/bolloon-daemon.sh +207 -0
  4. package/bin/bolloon.cjs +0 -0
  5. package/dist/agents/constraint-layer.js +19 -19
  6. package/dist/agents/judgment-protocol.js +14 -14
  7. package/dist/agents/pi-sdk-types.js +12 -12
  8. package/dist/agents/pi-sdk.js +101 -101
  9. package/dist/agents/skill-organizer.js +19 -19
  10. package/dist/agents/workflow-pivot-loop.js +2 -2
  11. package/dist/agents/x402/x402Pay.js +4 -0
  12. package/dist/bollharness/src/scripts/deploy-guard.js +8 -8
  13. package/dist/bollharness-integration/context-router-judgment.js +4 -4
  14. package/dist/bollharness-integration/context-router.js +292 -292
  15. package/dist/bollharness-integration/gate-state-machine.js +13 -13
  16. package/dist/bollharness-integration/llm-judgment-engine.js +134 -134
  17. package/dist/bollharness-integration/skill-adapter.js +21 -21
  18. package/dist/bootstrap/chat-archiver.js +14 -14
  19. package/dist/bootstrap/context-os.js +24 -24
  20. package/dist/bootstrap/memory-compressor.js +13 -13
  21. package/dist/cli-entry.js +36 -36
  22. package/dist/constraint-runtime/reference_data/archive_surface_snapshot.json +63 -0
  23. package/dist/constraint-runtime/reference_data/commands_snapshot.json +1037 -0
  24. package/dist/constraint-runtime/reference_data/subsystems/assistant.json +8 -0
  25. package/dist/constraint-runtime/reference_data/subsystems/bootstrap.json +8 -0
  26. package/dist/constraint-runtime/reference_data/subsystems/bridge.json +32 -0
  27. package/dist/constraint-runtime/reference_data/subsystems/buddy.json +13 -0
  28. package/dist/constraint-runtime/reference_data/subsystems/cli.json +26 -0
  29. package/dist/constraint-runtime/reference_data/subsystems/components.json +32 -0
  30. package/dist/constraint-runtime/reference_data/subsystems/constants.json +28 -0
  31. package/dist/constraint-runtime/reference_data/subsystems/coordinator.json +8 -0
  32. package/dist/constraint-runtime/reference_data/subsystems/entrypoints.json +15 -0
  33. package/dist/constraint-runtime/reference_data/subsystems/hooks.json +32 -0
  34. package/dist/constraint-runtime/reference_data/subsystems/keybindings.json +21 -0
  35. package/dist/constraint-runtime/reference_data/subsystems/memdir.json +15 -0
  36. package/dist/constraint-runtime/reference_data/subsystems/migrations.json +18 -0
  37. package/dist/constraint-runtime/reference_data/subsystems/moreright.json +8 -0
  38. package/dist/constraint-runtime/reference_data/subsystems/native_ts.json +11 -0
  39. package/dist/constraint-runtime/reference_data/subsystems/outputStyles.json +8 -0
  40. package/dist/constraint-runtime/reference_data/subsystems/plugins.json +9 -0
  41. package/dist/constraint-runtime/reference_data/subsystems/remote.json +11 -0
  42. package/dist/constraint-runtime/reference_data/subsystems/schemas.json +8 -0
  43. package/dist/constraint-runtime/reference_data/subsystems/screens.json +10 -0
  44. package/dist/constraint-runtime/reference_data/subsystems/server.json +10 -0
  45. package/dist/constraint-runtime/reference_data/subsystems/services.json +32 -0
  46. package/dist/constraint-runtime/reference_data/subsystems/skills.json +27 -0
  47. package/dist/constraint-runtime/reference_data/subsystems/state.json +13 -0
  48. package/dist/constraint-runtime/reference_data/subsystems/types.json +18 -0
  49. package/dist/constraint-runtime/reference_data/subsystems/upstreamproxy.json +9 -0
  50. package/dist/constraint-runtime/reference_data/subsystems/utils.json +32 -0
  51. package/dist/constraint-runtime/reference_data/subsystems/vim.json +12 -0
  52. package/dist/constraint-runtime/reference_data/subsystems/voice.json +8 -0
  53. package/dist/constraint-runtime/reference_data/tools_snapshot.json +922 -0
  54. package/dist/context-compaction/auto-compact.js +7 -7
  55. package/dist/electron/config.js.map +1 -0
  56. package/dist/electron/dialogs.js.map +1 -0
  57. package/dist/electron/first-run.js +54 -54
  58. package/dist/electron/first-run.js.map +1 -0
  59. package/dist/electron/ipc.js.map +1 -0
  60. package/dist/electron/logger.js.map +1 -0
  61. package/dist/electron/main.js.map +1 -0
  62. package/dist/electron/menu.js.map +1 -0
  63. package/dist/electron/paths.js.map +1 -0
  64. package/dist/electron/server.js.map +1 -0
  65. package/dist/electron/tray.js.map +1 -0
  66. package/dist/electron/window.js.map +1 -0
  67. package/dist/electron-build/electron/first-run.js +54 -54
  68. package/dist/electron-preload.js.map +1 -1
  69. package/dist/electron.js.map +1 -1
  70. package/dist/index.js +112 -112
  71. package/dist/llm/llm-judgment-client.js +102 -102
  72. package/dist/llm/pi-ai.js +48 -48
  73. package/dist/llm/system-prompt/layers/channel/human-async.md +41 -41
  74. package/dist/llm/system-prompt/layers/channel/local.md +14 -14
  75. package/dist/llm/system-prompt/layers/channel/p2p-agent.md +18 -18
  76. package/dist/llm/system-prompt/layers/channel/p2p-peer-sync.md +51 -51
  77. package/dist/llm/system-prompt/layers/channel/p2p-proactive.md +43 -43
  78. package/dist/llm/system-prompt/layers/channel/p2p-visitor.md +19 -19
  79. package/dist/llm/system-prompt/layers/channel/session-handoff.md +61 -61
  80. package/dist/llm/system-prompt/layers/core/artifacts_storage.md +89 -89
  81. package/dist/llm/system-prompt/layers/core/evenhandedness.md +21 -21
  82. package/dist/llm/system-prompt/layers/core/external-engagement.md +73 -73
  83. package/dist/llm/system-prompt/layers/core/hibs_reminders.md +15 -15
  84. package/dist/llm/system-prompt/layers/core/identity.md +48 -48
  85. package/dist/llm/system-prompt/layers/core/knowledge.md +17 -17
  86. package/dist/llm/system-prompt/layers/core/memory_system.md +12 -12
  87. package/dist/llm/system-prompt/layers/core/network_filesystem.md +28 -28
  88. package/dist/llm/system-prompt/layers/core/refusal.md +37 -37
  89. package/dist/llm/system-prompt/layers/core/tone.md +31 -31
  90. package/dist/llm/system-prompt/layers/core/tools.thin.md +13 -13
  91. package/dist/llm/system-prompt/layers/core/wellbeing.md +41 -41
  92. package/dist/llm/system-prompt/layers/role/architect.md +20 -20
  93. package/dist/llm/system-prompt/layers/role/expert.md +19 -19
  94. package/dist/llm/system-prompt/layers/role/implementer.md +15 -15
  95. package/dist/llm/system-prompt/layers/role/security.md +15 -15
  96. package/dist/llm/system-prompt/layers/tool/artifacts.md +72 -72
  97. package/dist/llm/system-prompt/layers/tool/bash.md +25 -25
  98. package/dist/llm/system-prompt/layers/tool/goal_handoff.md +77 -77
  99. package/dist/llm/system-prompt/layers/tool/hibs_api.md +171 -171
  100. package/dist/llm/system-prompt/layers/tool/image_search.md +70 -70
  101. package/dist/llm/system-prompt/layers/tool/manifest.md +89 -89
  102. package/dist/llm/system-prompt/layers/tool/mcp_apps.md +53 -53
  103. package/dist/llm/system-prompt/layers/tool/p2p_request.md +61 -61
  104. package/dist/llm/system-prompt/layers/tool/web_search.md +83 -83
  105. package/dist/llm/tool-manifest/ask_user_input.js +1 -1
  106. package/dist/llm/tool-manifest/bash.js +3 -3
  107. package/dist/llm/tool-manifest/create_file.js +4 -4
  108. package/dist/llm/tool-manifest/fetch_sports_data.js +3 -3
  109. package/dist/llm/tool-manifest/image_search.js +2 -2
  110. package/dist/llm/tool-manifest/index.js +59 -0
  111. package/dist/llm/tool-manifest/mcp.js +2 -2
  112. package/dist/llm/tool-manifest/message_compose.js +3 -3
  113. package/dist/llm/tool-manifest/places.js +2 -2
  114. package/dist/llm/tool-manifest/present_files.js +1 -1
  115. package/dist/llm/tool-manifest/recipe.js +2 -2
  116. package/dist/llm/tool-manifest/str_replace.js +5 -5
  117. package/dist/llm/tool-manifest/view.js +3 -3
  118. package/dist/llm/tool-manifest/weather.js +4 -4
  119. package/dist/llm/tool-manifest/web.js +4 -4
  120. package/dist/network/p2p.js +78 -4
  121. package/dist/pi-ecosystem-judgment/causal-judge.js +51 -51
  122. package/dist/pi-ecosystem-judgment/distill-prompt.js +42 -42
  123. package/dist/pi-ecosystem-judgment/distillation.js +14 -14
  124. package/dist/pi-ecosystem-judgment/index.js +1 -1
  125. package/dist/pi-ecosystem-judgment/monitor-gate.js +28 -28
  126. package/dist/pi-ecosystem-judgment/value-injection.js +102 -102
  127. package/dist/security/context-router-tool.js +15 -15
  128. package/dist/utils/auto-update.js.map +1 -0
  129. package/dist/web/a2ui-client.js +1594 -223
  130. package/dist/web/api-config.html +779 -779
  131. package/dist/web/client-hearth.js +10 -10
  132. package/dist/web/client.js.map +7 -0
  133. package/dist/web/components/wallet-viem.mjs +118 -118
  134. package/dist/web/index.html +502 -502
  135. package/dist/web/manifest.json +20 -20
  136. package/dist/web/mobile-agent.js +397 -0
  137. package/dist/web/mobile-core.js +86235 -0
  138. package/dist/web/mobile-data.js +346 -0
  139. package/dist/web/mobile-http-api.js +71 -0
  140. package/dist/web/mobile-p2p.js +250 -0
  141. package/dist/web/mobile-payments.js +80 -0
  142. package/dist/web/mobile-wallet.js +226 -0
  143. package/dist/web/mobile.css +483 -6
  144. package/dist/web/mobile.html +99 -50
  145. package/dist/web/mobile.js +1040 -187
  146. package/dist/web/server.js +13 -13
  147. package/dist/web/style.css +4946 -4946
  148. package/package.json +201 -198
  149. package/scripts/build-cli.js +215 -215
  150. package/scripts/build-web.ts +162 -149
  151. package/scripts/postinstall.js +152 -152
  152. package/bin/bolloon.js +0 -157
  153. package/dist/agents/python-exec.js +0 -115
  154. package/dist/pi-ecosystem-colony/index.js +0 -365
  155. package/dist/social/ant-colony/AdaptiveHeartbeat.js +0 -101
  156. package/dist/social/ant-colony/PheromoneEngine.js +0 -227
  157. package/dist/social/ant-colony/index.js +0 -6
  158. package/dist/social/ant-colony/types.js +0 -24
  159. package/dist/storage/trajectory.js +0 -101
  160. package/dist/test/ai-judgment-test.js +0 -80
  161. package/dist/test/bollharness-integration.test.js +0 -318
  162. package/dist/test/channel-agent-multi-dialogue.js +0 -205
  163. package/dist/test/channel-heartbeat-agent-test.js +0 -201
  164. package/dist/test/constraint-layer.test.js +0 -164
  165. package/dist/test/diap-identity-test.js +0 -172
  166. package/dist/test/diap-quick-test.js +0 -62
  167. package/dist/test/global-shared-context.test.js +0 -315
  168. package/dist/test/harness-judgment-injection.test.js +0 -246
  169. package/dist/test/harness-workflow-integrator-test.js +0 -228
  170. package/dist/test/human-value-store.test.js +0 -243
  171. package/dist/test/hybrid-integration-test.js +0 -118
  172. package/dist/test/hybrid-messenger-verify.js +0 -55
  173. package/dist/test/iroh-bistream-debug.js +0 -38
  174. package/dist/test/iroh-communication.test.js +0 -66
  175. package/dist/test/iroh-debug-test.js +0 -57
  176. package/dist/test/iroh-diap-test.js +0 -71
  177. package/dist/test/iroh-direct-connect.js +0 -55
  178. package/dist/test/iroh-e2e-fixed.js +0 -89
  179. package/dist/test/iroh-e2e-same-process.js +0 -63
  180. package/dist/test/iroh-e2e.js +0 -66
  181. package/dist/test/iroh-final-e2e.js +0 -72
  182. package/dist/test/iroh-relay-test.js +0 -37
  183. package/dist/test/iroh-simple-test.js +0 -41
  184. package/dist/test/iroh-transport-verify.js +0 -54
  185. package/dist/test/iroh-transport.test.js +0 -37
  186. package/dist/test/iroh-two-nodes.js +0 -70
  187. package/dist/test/iroh-verify.js +0 -44
  188. package/dist/test/judgment-decision.test.js +0 -219
  189. package/dist/test/llm-judgment-integration.test.js +0 -220
  190. package/dist/test/p2p-agent-complex-dialogue.js +0 -385
  191. package/dist/test/p2p-agent-dialogue.js +0 -341
  192. package/dist/test/p2p-agent-full-bidirectional.js +0 -510
  193. package/dist/test/p2p-agent-harness-flow.js +0 -437
  194. package/dist/test/p2p-agent-harness-single.js +0 -143
  195. package/dist/test/p2p-ai-dialogue-test.js +0 -318
  196. package/dist/test/p2p-cid-connect-test.js +0 -195
  197. package/dist/test/p2p-connect-receiver.js +0 -69
  198. package/dist/test/p2p-doc-transfer.js +0 -110
  199. package/dist/test/p2p-identity-page-test.js +0 -77
  200. package/dist/test/p2p-iroh-test.js +0 -171
  201. package/dist/test/p2p-minimal-test.js +0 -241
  202. package/dist/test/p2p-node-1.js +0 -148
  203. package/dist/test/p2p-node-2.js +0 -148
  204. package/dist/test/p2p-server.js +0 -281
  205. package/dist/test/p2p-two-nodes-test.js +0 -438
  206. package/dist/test/pi-sdk.test.js +0 -44
  207. package/dist/test/set-persona.js +0 -40
  208. package/dist/test/simple.test.js +0 -9
  209. package/dist/test/storage-integration.test.js +0 -150
  210. package/dist/test/subagent-manager.test.js +0 -276
  211. package/dist/test/test-gate-flow.test.js +0 -81
  212. package/dist/test/workflow-engine.test.js +0 -87
  213. 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
@@ -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 = [];
@@ -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
  `;
@@ -202,13 +202,13 @@ export class PiAgentSession {
202
202
  /** Bootstrap SessionStart 拼的 system prompt 片段 (用完即清) */
203
203
  bootstrapAddition = '';
204
204
  /** 2026-08-12 (Task3 认知卸载): 工具选择与认知卸载指南 — 注入 system prompt, 降低"模型不触发 write/edit/read"率. */
205
- static TOOL_SELECTION_GUIDE = `【工具选择与认知卸载指南 (严格遵循)】
206
- - 写/改文件: 必须用 write_file / edit_file (不要用 terminal 拼字符串写文件).
207
- - 读文件: 用 read_file / read_directory / list_files.
208
- - 跑命令/查状态/装依赖/跑脚本: 用 terminal.
209
- - 执行 git 操作: 用 git_* 专用工具 (git_diff/git_commit/git_push/git_branch/git_log).
210
- - 查看/调用技能: 用 list_skills / use_skill.
211
- - 认知卸载: 当任务对你过大或反复失败时, 不要死磕 — 用 delegate_to_engine 把编码/复杂任务委派给外部引擎 (codex/claude-code/opencode), 或把目标拆小分步完成.
205
+ static TOOL_SELECTION_GUIDE = `【工具选择与认知卸载指南 (严格遵循)】
206
+ - 写/改文件: 必须用 write_file / edit_file (不要用 terminal 拼字符串写文件).
207
+ - 读文件: 用 read_file / read_directory / list_files.
208
+ - 跑命令/查状态/装依赖/跑脚本: 用 terminal.
209
+ - 执行 git 操作: 用 git_* 专用工具 (git_diff/git_commit/git_push/git_branch/git_log).
210
+ - 查看/调用技能: 用 list_skills / use_skill.
211
+ - 认知卸载: 当任务对你过大或反复失败时, 不要死磕 — 用 delegate_to_engine 把编码/复杂任务委派给外部引擎 (codex/claude-code/opencode), 或把目标拆小分步完成.
212
212
  - 每步只选一个最合适的工具, 先读后写, 写完验证 (跑 tsc/vitest 或读回文件).`;
213
213
  /** 当前 prompt 开始时间 (供 Stop hook 计算 durationMs) */
214
214
  promptStartTime = 0;
@@ -1061,40 +1061,40 @@ export class PiAgentSession {
1061
1061
  }
1062
1062
  // M2.4: persona 缓存
1063
1063
  if (!this.cachedPersonaSection && this.persona) {
1064
- this.cachedPersonaSection = `
1065
- 角色描述: ${this.persona.description || '无'}
1066
- 性格特点: ${this.persona.personality || '无'}
1067
- 问候语: ${this.persona.greeting || '无'}
1064
+ this.cachedPersonaSection = `
1065
+ 角色描述: ${this.persona.description || '无'}
1066
+ 性格特点: ${this.persona.personality || '无'}
1067
+ 问候语: ${this.persona.greeting || '无'}
1068
1068
  `;
1069
1069
  }
1070
- const systemPrompt = `${this.bootstrapAddition}你是 ${this.identity.name},基于ReAct (Reasoning + Acting)模式工作。${this.cachedPersonaSection}
1071
- 当前工作目录: ${this.cwd}
1072
- 当前身份: ${this.identity.name} (${this.identity.did})
1073
- ${this.currentIntentHint}
1074
-
1075
- ${this.getToolDefinitions()}
1076
-
1077
- ${PiAgentSession.TOOL_SELECTION_GUIDE}
1078
-
1079
- 工作模式:
1080
- 1. 理解用户自然语言请求
1081
- 2. 分析需要哪些工具来完成
1082
- 3. 按顺序调用工具并观察结果
1083
- 4. 根据观察结果决定下一步
1084
- 5. 最终给出完整回答
1085
-
1086
- 重要 (一次命中要求):
1087
- - 每次只调用一个工具
1088
- - 仔细分析工具返回结果
1089
- - 当任务完成时,必须在回答末尾添加 <final gen> 标记表示结束
1090
- - 如果需要更多信息,继续调用工具
1091
-
1092
- 【工具调用格式 (严格遵守, 否则系统无法解析)】
1093
- - 你只能输出**一个**工具调用, 不要堆叠多个 invoke
1094
- - 工具调用格式: {"name":"<tool_name>","input":{"arg1":"value1"}}
1095
- - 用 markdown json code block 包裹: \`\`\`json\n{"name":"X","input":{...}}\n\`\`\`
1096
- - 工具调用前可以简短思考 (1-2 句话), 但**不要写长篇 thinking** (会撞 max_tokens)
1097
- - 工具调用后必须等结果, 不要在同一个回复里继续输出
1070
+ const systemPrompt = `${this.bootstrapAddition}你是 ${this.identity.name},基于ReAct (Reasoning + Acting)模式工作。${this.cachedPersonaSection}
1071
+ 当前工作目录: ${this.cwd}
1072
+ 当前身份: ${this.identity.name} (${this.identity.did})
1073
+ ${this.currentIntentHint}
1074
+
1075
+ ${this.getToolDefinitions()}
1076
+
1077
+ ${PiAgentSession.TOOL_SELECTION_GUIDE}
1078
+
1079
+ 工作模式:
1080
+ 1. 理解用户自然语言请求
1081
+ 2. 分析需要哪些工具来完成
1082
+ 3. 按顺序调用工具并观察结果
1083
+ 4. 根据观察结果决定下一步
1084
+ 5. 最终给出完整回答
1085
+
1086
+ 重要 (一次命中要求):
1087
+ - 每次只调用一个工具
1088
+ - 仔细分析工具返回结果
1089
+ - 当任务完成时,必须在回答末尾添加 <final gen> 标记表示结束
1090
+ - 如果需要更多信息,继续调用工具
1091
+
1092
+ 【工具调用格式 (严格遵守, 否则系统无法解析)】
1093
+ - 你只能输出**一个**工具调用, 不要堆叠多个 invoke
1094
+ - 工具调用格式: {"name":"<tool_name>","input":{"arg1":"value1"}}
1095
+ - 用 markdown json code block 包裹: \`\`\`json\n{"name":"X","input":{...}}\n\`\`\`
1096
+ - 工具调用前可以简短思考 (1-2 句话), 但**不要写长篇 thinking** (会撞 max_tokens)
1097
+ - 工具调用后必须等结果, 不要在同一个回复里继续输出
1098
1098
  - <final gen> 只在**真完成所有任务**时输出, 不要在工具调用前/中输出${this.judgmentGateAddition}${this.contextHintAddition}`;
1099
1099
  // 2026-06-15: 把 currentOnStream 传给 loop, 让 step-timeline 在 pivot 循环里也能 emit step_start/done
1100
1100
  // 之前 loop.execute() 不接 streamCallback, 导致 step-timeline 只能看到老 runReActLoop 路径
@@ -1286,10 +1286,10 @@ ${PiAgentSession.TOOL_SELECTION_GUIDE}
1286
1286
  }
1287
1287
  // M2.4: persona section 缓存 — persona 在 loadPersona() 时一次设定, 此后不变
1288
1288
  if (!this.cachedPersonaSection && this.persona) {
1289
- this.cachedPersonaSection = `
1290
- 角色描述: ${this.persona.description || '无'}
1291
- 性格特点: ${this.persona.personality || '无'}
1292
- 问候语: ${this.persona.greeting || '无'}
1289
+ this.cachedPersonaSection = `
1290
+ 角色描述: ${this.persona.description || '无'}
1291
+ 性格特点: ${this.persona.personality || '无'}
1292
+ 问候语: ${this.persona.greeting || '无'}
1293
1293
  `;
1294
1294
  }
1295
1295
  const personaSection = this.cachedPersonaSection;
@@ -1307,28 +1307,28 @@ ${PiAgentSession.TOOL_SELECTION_GUIDE}
1307
1307
  .join('\n');
1308
1308
  loopProgressSection = `\n【本轮循环进度】你已完成以下 ${loopActionLog.length} 个动作, 这是连续执行的同一轮任务:\n${actionLines}\n请基于已有结果继续推进, 不要重复执行上面已成功的动作. 全部完成后用 <final gen> 结束.\n`;
1309
1309
  }
1310
- const systemPrompt = `${this.bootstrapAddition}你是 ${this.identity.name},基于ReAct (Reasoning + Acting)模式工作。${personaSection}
1311
- 当前工作目录: ${this.cwd}
1312
- 当前身份: ${this.identity.name} (${this.identity.did})
1313
- ${refineContext}
1314
- ${this.currentIntentHint}
1315
- ${loopProgressSection}
1316
-
1317
- ${toolDefs}
1318
-
1319
- ${PiAgentSession.TOOL_SELECTION_GUIDE}
1320
-
1321
- 工作模式:
1322
- 1. 理解用户自然语言请求
1323
- 2. 分析需要哪些工具来完成
1324
- 3. 按顺序调用工具并观察结果
1325
- 4. 根据观察结果决定下一步
1326
- 5. 最终给出完整回答
1327
-
1328
- 重要:
1329
- - 每次只调用一个工具
1330
- - 仔细分析工具返回结果
1331
- - 当任务完成时,必须在回答末尾添加 <final gen> 标记表示结束
1310
+ const systemPrompt = `${this.bootstrapAddition}你是 ${this.identity.name},基于ReAct (Reasoning + Acting)模式工作。${personaSection}
1311
+ 当前工作目录: ${this.cwd}
1312
+ 当前身份: ${this.identity.name} (${this.identity.did})
1313
+ ${refineContext}
1314
+ ${this.currentIntentHint}
1315
+ ${loopProgressSection}
1316
+
1317
+ ${toolDefs}
1318
+
1319
+ ${PiAgentSession.TOOL_SELECTION_GUIDE}
1320
+
1321
+ 工作模式:
1322
+ 1. 理解用户自然语言请求
1323
+ 2. 分析需要哪些工具来完成
1324
+ 3. 按顺序调用工具并观察结果
1325
+ 4. 根据观察结果决定下一步
1326
+ 5. 最终给出完整回答
1327
+
1328
+ 重要:
1329
+ - 每次只调用一个工具
1330
+ - 仔细分析工具返回结果
1331
+ - 当任务完成时,必须在回答末尾添加 <final gen> 标记表示结束
1332
1332
  - 如果需要更多信息,继续调用工具${this.judgmentGateAddition}${this.contextHintAddition}`;
1333
1333
  // 3 个恢复机制 (Claude Code 论文 9-step pipeline 内部):
1334
1334
  // 1. max output token 升级 (最多 3 次, 每次 maxOutputTokens 翻倍)
@@ -2399,37 +2399,37 @@ ${PiAgentSession.TOOL_SELECTION_GUIDE}
2399
2399
  getDefaultResponse(input) {
2400
2400
  const operationsRef = PiAgentSession.getOperationsReference();
2401
2401
  if (operationsRef) {
2402
- return `收到了: "${input}"
2403
-
2404
- 我是一个判断力处理智能体,支持自然语言交互。
2405
-
2406
- 可用操作(直接说出即可):
2407
- ${this.extractOperationsFromRef(operationsRef)}
2408
-
2409
- 示例请求:
2410
- - "读取 src/index.ts 文件"
2411
- - "总结一下 README.md"
2412
- - "查看当前连接了哪些节点"
2402
+ return `收到了: "${input}"
2403
+
2404
+ 我是一个判断力处理智能体,支持自然语言交互。
2405
+
2406
+ 可用操作(直接说出即可):
2407
+ ${this.extractOperationsFromRef(operationsRef)}
2408
+
2409
+ 示例请求:
2410
+ - "读取 src/index.ts 文件"
2411
+ - "总结一下 README.md"
2412
+ - "查看当前连接了哪些节点"
2413
2413
  - "向 QmABC... 发送测试消息"`;
2414
2414
  }
2415
- return `收到了: "${input}"
2416
-
2417
- 我是一个判断力处理智能体,支持自然语言交互。
2418
-
2419
- 可用操作(直接说出即可):
2420
- - "读取 README.md" - 读取并分析文档
2421
- - "总结文档" - 总结文档内容
2422
- - "改进文档,按照X要求" - 改进文档
2423
- - "查看节点" - 查看已连接的对等节点
2424
- - "向X发送消息Y" - 向对等节点发送消息
2425
- - "广播消息X" - 广播消息到所有节点
2426
- - "查看身份" - 查看当前智能体身份
2427
- - "查看日志" - 查看最近操作日志
2428
-
2429
- 示例请求:
2430
- - "读取 src/index.ts 文件"
2431
- - "总结一下 README.md"
2432
- - "查看当前连接了哪些节点"
2415
+ return `收到了: "${input}"
2416
+
2417
+ 我是一个判断力处理智能体,支持自然语言交互。
2418
+
2419
+ 可用操作(直接说出即可):
2420
+ - "读取 README.md" - 读取并分析文档
2421
+ - "总结文档" - 总结文档内容
2422
+ - "改进文档,按照X要求" - 改进文档
2423
+ - "查看节点" - 查看已连接的对等节点
2424
+ - "向X发送消息Y" - 向对等节点发送消息
2425
+ - "广播消息X" - 广播消息到所有节点
2426
+ - "查看身份" - 查看当前智能体身份
2427
+ - "查看日志" - 查看最近操作日志
2428
+
2429
+ 示例请求:
2430
+ - "读取 src/index.ts 文件"
2431
+ - "总结一下 README.md"
2432
+ - "查看当前连接了哪些节点"
2433
2433
  - "向 QmABC... 发送测试消息"`;
2434
2434
  }
2435
2435
  extractOperationsFromRef(ref) {
@@ -2454,13 +2454,13 @@ ${this.extractOperationsFromRef(operationsRef)}
2454
2454
  }
2455
2455
  }
2456
2456
  return operationLines.length > 0 ? operationLines.join('\n') :
2457
- ` - "读取 README.md" - 读取并分析文档
2458
- - "总结文档" - 总结文档内容
2459
- - "改进文档,按照X要求" - 改进文档
2460
- - "查看节点" - 查看已连接的对等节点
2461
- - "向X发送消息Y" - 向对等节点发送消息
2462
- - "广播消息X" - 广播消息到所有节点
2463
- - "查看身份" - 查看当前智能体身份
2457
+ ` - "读取 README.md" - 读取并分析文档
2458
+ - "总结文档" - 总结文档内容
2459
+ - "改进文档,按照X要求" - 改进文档
2460
+ - "查看节点" - 查看已连接的对等节点
2461
+ - "向X发送消息Y" - 向对等节点发送消息
2462
+ - "广播消息X" - 广播消息到所有节点
2463
+ - "查看身份" - 查看当前智能体身份
2464
2464
  - "查看日志" - 查看最近操作日志`;
2465
2465
  }
2466
2466
  async suggestRename(messages) {
@@ -143,25 +143,25 @@ export async function scanLeftoverSkills(opts = {}) {
143
143
  // ───────────────────────── B. 经验进化 (LLM 完整总结) ─────────────────────────
144
144
  /** 把候选的工具调用记录扩写成完整经验 — LLM prompt (结构化 JSON 输出) */
145
145
  export function buildEvolvePrompt(c) {
146
- return `你是经验总结专家。下面是 Bolloon 智能体在一轮运行中连续成功调用的工具记录 (已运行 ${c.runs || 1} 次)。
147
-
148
- 工具记录:
149
- 名称: ${c.name}
150
- 描述: ${c.description}
151
- 原始记录:
152
- ${String(c.body || '').slice(0, 4000)}
153
-
154
- 请把这份"工具调用记录"扩写成一份完整的、可复用的经验文档, 要求:
155
- 1. name: 一个简短的小写英文名 (字母数字连字符, 概括这套操作)
156
- 2. description: 一句话描述 (什么场景用)
157
- 3. body: 完整经验正文, 按以下结构:
158
- ## 背景 — 这套操作在什么场景下用, 解决什么问题
159
- ## 触发条件 — 什么信号/需求出现时应该使用
160
- ## 流程 — 具体步骤 (保留原始工具名), 每步说明目的
161
- ## 注意事项 — 易错点 / 边界情况 / 已知坑
162
- ## 验证 — 怎么确认结果正确
163
-
164
- 只输出一个 JSON 对象, 不要任何其他文字:
146
+ return `你是经验总结专家。下面是 Bolloon 智能体在一轮运行中连续成功调用的工具记录 (已运行 ${c.runs || 1} 次)。
147
+
148
+ 工具记录:
149
+ 名称: ${c.name}
150
+ 描述: ${c.description}
151
+ 原始记录:
152
+ ${String(c.body || '').slice(0, 4000)}
153
+
154
+ 请把这份"工具调用记录"扩写成一份完整的、可复用的经验文档, 要求:
155
+ 1. name: 一个简短的小写英文名 (字母数字连字符, 概括这套操作)
156
+ 2. description: 一句话描述 (什么场景用)
157
+ 3. body: 完整经验正文, 按以下结构:
158
+ ## 背景 — 这套操作在什么场景下用, 解决什么问题
159
+ ## 触发条件 — 什么信号/需求出现时应该使用
160
+ ## 流程 — 具体步骤 (保留原始工具名), 每步说明目的
161
+ ## 注意事项 — 易错点 / 边界情况 / 已知坑
162
+ ## 验证 — 怎么确认结果正确
163
+
164
+ 只输出一个 JSON 对象, 不要任何其他文字:
165
165
  {"name": "...", "description": "...", "body": "..."}`;
166
166
  }
167
167
  /** 解析 LLM 返回的 JSON (容错: 剥 markdown 代码块, 取第一个 {...}) */
@@ -876,8 +876,8 @@ export class WorkflowPivotLoop {
876
876
  // 完整重装只在 iter=1 和 compact 之后两次
877
877
  const lines = fullSystemPrompt.split('\n');
878
878
  const identityLine = lines.find((l) => l.includes('你是') && !l.includes('(续)')) ?? '';
879
- return `[continuation] 你的 persona + tools + judgments 已在首轮 messageHistory 中.
880
- ${identityLine ? identityLine + '\n' : ''}当前 step 别再读 persona 全文, 继续推进任务即可.
879
+ return `[continuation] 你的 persona + tools + judgments 已在首轮 messageHistory 中.
880
+ ${identityLine ? identityLine + '\n' : ''}当前 step 别再读 persona 全文, 继续推进任务即可.
881
881
  > <final gen> 只在真完成时输出.`;
882
882
  }
883
883
  /**
@@ -216,6 +216,10 @@ export async function createX402PaymentFetch(params) {
216
216
  client.register(info.caip2, new ExactEvmScheme(signer));
217
217
  client.registerV1(info.v1, new ExactEvmScheme(signer));
218
218
  }
219
+ // @x402 2.25+ 新增 spendControls 默认白名单 (只放行各网络 default asset), 会拒掉
220
+ // USDC 等非默认代币的支付要求 → 关掉资产门禁, 恢复 2.21 语义 (额度上限仍由
221
+ // 上面的 registerPolicy / maxPaymentAmount 控制, 资产种类信任服务端 402 头声明)
222
+ client.setSpendControls(false);
219
223
  return wrapFetchWithPayment(params.fetchImpl || fetch, client);
220
224
  }
221
225
  function parseHumanTokenAmount(amount, decimals) {
@@ -104,17 +104,17 @@ function checkRsync(cmd) {
104
104
  function block(reason, host = null) {
105
105
  let guidance;
106
106
  if (host === PROD_IP) {
107
- guidance = `请使用标准部署流程:
108
- 后端: bash scripts/deploy.sh --yes
109
- Demo 正式: bash scripts/deploy-demo.sh <name> --channel prod --yes
110
- Demo 内测: bash scripts/deploy-demo.sh <name> --channel preview --yes
111
- Edge/Nginx: bash scripts/deploy-edge.sh --yes
107
+ guidance = `请使用标准部署流程:
108
+ 后端: bash scripts/deploy.sh --yes
109
+ Demo 正式: bash scripts/deploy-demo.sh <name> --channel prod --yes
110
+ Demo 内测: bash scripts/deploy-demo.sh <name> --channel preview --yes
111
+ Edge/Nginx: bash scripts/deploy-edge.sh --yes
112
112
  详见 Bolloon.md Development Commands。`;
113
113
  }
114
114
  else if (BRIDGE_VPS_HOSTS.includes(host ?? "")) {
115
- guidance = `Bridge VPS 必须走 git pull 更新路径:
116
- ssh root@${host} 'sudo -u boll git -C /opt/boll pull --ff-only'
117
- scp/rsync 直传会重新制造 orphan worktree。
115
+ guidance = `Bridge VPS 必须走 git pull 更新路径:
116
+ ssh root@${host} 'sudo -u boll git -C /opt/boll pull --ff-only'
117
+ scp/rsync 直传会重新制造 orphan worktree。
118
118
  详见 docs/issues/guard-20260408-0445-bridge-vps-orphan-worktree.md。`;
119
119
  }
120
120
  else {