@bolloon/bolloon-agent 0.4.3 → 0.4.5

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 (212) hide show
  1. package/README.md +135 -135
  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 +90 -90
  9. package/dist/agents/skill-organizer.js +19 -19
  10. package/dist/agents/workflow-pivot-loop.js +2 -2
  11. package/dist/bollharness/src/scripts/deploy-guard.js +8 -8
  12. package/dist/bollharness-integration/context-router-judgment.js +4 -4
  13. package/dist/bollharness-integration/context-router.js +292 -292
  14. package/dist/bollharness-integration/gate-state-machine.js +13 -13
  15. package/dist/bollharness-integration/llm-judgment-engine.js +134 -134
  16. package/dist/bollharness-integration/skill-adapter.js +21 -21
  17. package/dist/bootstrap/chat-archiver.js +14 -14
  18. package/dist/bootstrap/context-os.js +24 -24
  19. package/dist/bootstrap/memory-compressor.js +13 -13
  20. package/dist/cli-entry.js +36 -36
  21. package/dist/constraint-runtime/reference_data/archive_surface_snapshot.json +63 -0
  22. package/dist/constraint-runtime/reference_data/commands_snapshot.json +1037 -0
  23. package/dist/constraint-runtime/reference_data/subsystems/assistant.json +8 -0
  24. package/dist/constraint-runtime/reference_data/subsystems/bootstrap.json +8 -0
  25. package/dist/constraint-runtime/reference_data/subsystems/bridge.json +32 -0
  26. package/dist/constraint-runtime/reference_data/subsystems/buddy.json +13 -0
  27. package/dist/constraint-runtime/reference_data/subsystems/cli.json +26 -0
  28. package/dist/constraint-runtime/reference_data/subsystems/components.json +32 -0
  29. package/dist/constraint-runtime/reference_data/subsystems/constants.json +28 -0
  30. package/dist/constraint-runtime/reference_data/subsystems/coordinator.json +8 -0
  31. package/dist/constraint-runtime/reference_data/subsystems/entrypoints.json +15 -0
  32. package/dist/constraint-runtime/reference_data/subsystems/hooks.json +32 -0
  33. package/dist/constraint-runtime/reference_data/subsystems/keybindings.json +21 -0
  34. package/dist/constraint-runtime/reference_data/subsystems/memdir.json +15 -0
  35. package/dist/constraint-runtime/reference_data/subsystems/migrations.json +18 -0
  36. package/dist/constraint-runtime/reference_data/subsystems/moreright.json +8 -0
  37. package/dist/constraint-runtime/reference_data/subsystems/native_ts.json +11 -0
  38. package/dist/constraint-runtime/reference_data/subsystems/outputStyles.json +8 -0
  39. package/dist/constraint-runtime/reference_data/subsystems/plugins.json +9 -0
  40. package/dist/constraint-runtime/reference_data/subsystems/remote.json +11 -0
  41. package/dist/constraint-runtime/reference_data/subsystems/schemas.json +8 -0
  42. package/dist/constraint-runtime/reference_data/subsystems/screens.json +10 -0
  43. package/dist/constraint-runtime/reference_data/subsystems/server.json +10 -0
  44. package/dist/constraint-runtime/reference_data/subsystems/services.json +32 -0
  45. package/dist/constraint-runtime/reference_data/subsystems/skills.json +27 -0
  46. package/dist/constraint-runtime/reference_data/subsystems/state.json +13 -0
  47. package/dist/constraint-runtime/reference_data/subsystems/types.json +18 -0
  48. package/dist/constraint-runtime/reference_data/subsystems/upstreamproxy.json +9 -0
  49. package/dist/constraint-runtime/reference_data/subsystems/utils.json +32 -0
  50. package/dist/constraint-runtime/reference_data/subsystems/vim.json +12 -0
  51. package/dist/constraint-runtime/reference_data/subsystems/voice.json +8 -0
  52. package/dist/constraint-runtime/reference_data/tools_snapshot.json +922 -0
  53. package/dist/context-compaction/auto-compact.js +7 -7
  54. package/dist/electron/config.js.map +1 -0
  55. package/dist/electron/dialogs.js.map +1 -0
  56. package/dist/electron/first-run.js +54 -54
  57. package/dist/electron/first-run.js.map +1 -0
  58. package/dist/electron/ipc.js.map +1 -0
  59. package/dist/electron/logger.js.map +1 -0
  60. package/dist/electron/main.js.map +1 -0
  61. package/dist/electron/menu.js.map +1 -0
  62. package/dist/electron/paths.js.map +1 -0
  63. package/dist/electron/server.js.map +1 -0
  64. package/dist/electron/tray.js.map +1 -0
  65. package/dist/electron/window.js.map +1 -0
  66. package/dist/electron-build/electron/config.js.map +1 -1
  67. package/dist/electron-build/electron/dialogs.js.map +1 -1
  68. package/dist/electron-build/electron/first-run.js +54 -54
  69. package/dist/electron-build/electron/first-run.js.map +1 -1
  70. package/dist/electron-build/electron/ipc.js.map +1 -1
  71. package/dist/electron-build/electron/logger.js.map +1 -1
  72. package/dist/electron-build/electron/menu.js.map +1 -1
  73. package/dist/electron-build/electron/paths.js.map +1 -1
  74. package/dist/electron-build/electron/server.js.map +1 -1
  75. package/dist/electron-build/electron/tray.js.map +1 -1
  76. package/dist/electron-build/electron/window.js.map +1 -1
  77. package/dist/electron-build/utils/auto-update.js.map +1 -1
  78. package/dist/electron-preload.js.map +1 -1
  79. package/dist/electron.js.map +1 -1
  80. package/dist/index.js +112 -112
  81. package/dist/llm/llm-judgment-client.js +102 -102
  82. package/dist/llm/pi-ai.js +48 -48
  83. package/dist/llm/system-prompt/layers/channel/human-async.md +41 -41
  84. package/dist/llm/system-prompt/layers/channel/local.md +14 -14
  85. package/dist/llm/system-prompt/layers/channel/p2p-agent.md +18 -18
  86. package/dist/llm/system-prompt/layers/channel/p2p-peer-sync.md +51 -51
  87. package/dist/llm/system-prompt/layers/channel/p2p-proactive.md +43 -43
  88. package/dist/llm/system-prompt/layers/channel/p2p-visitor.md +19 -19
  89. package/dist/llm/system-prompt/layers/channel/session-handoff.md +61 -61
  90. package/dist/llm/system-prompt/layers/core/artifacts_storage.md +89 -89
  91. package/dist/llm/system-prompt/layers/core/evenhandedness.md +21 -21
  92. package/dist/llm/system-prompt/layers/core/external-engagement.md +73 -73
  93. package/dist/llm/system-prompt/layers/core/hibs_reminders.md +15 -15
  94. package/dist/llm/system-prompt/layers/core/identity.md +48 -48
  95. package/dist/llm/system-prompt/layers/core/knowledge.md +17 -17
  96. package/dist/llm/system-prompt/layers/core/memory_system.md +12 -12
  97. package/dist/llm/system-prompt/layers/core/network_filesystem.md +28 -28
  98. package/dist/llm/system-prompt/layers/core/refusal.md +37 -37
  99. package/dist/llm/system-prompt/layers/core/tone.md +31 -31
  100. package/dist/llm/system-prompt/layers/core/tools.thin.md +13 -13
  101. package/dist/llm/system-prompt/layers/core/wellbeing.md +41 -41
  102. package/dist/llm/system-prompt/layers/role/architect.md +20 -20
  103. package/dist/llm/system-prompt/layers/role/expert.md +19 -19
  104. package/dist/llm/system-prompt/layers/role/implementer.md +15 -15
  105. package/dist/llm/system-prompt/layers/role/security.md +15 -15
  106. package/dist/llm/system-prompt/layers/tool/artifacts.md +72 -72
  107. package/dist/llm/system-prompt/layers/tool/bash.md +25 -25
  108. package/dist/llm/system-prompt/layers/tool/goal_handoff.md +77 -77
  109. package/dist/llm/system-prompt/layers/tool/hibs_api.md +171 -171
  110. package/dist/llm/system-prompt/layers/tool/image_search.md +70 -70
  111. package/dist/llm/system-prompt/layers/tool/manifest.md +89 -89
  112. package/dist/llm/system-prompt/layers/tool/mcp_apps.md +53 -53
  113. package/dist/llm/system-prompt/layers/tool/p2p_request.md +61 -61
  114. package/dist/llm/system-prompt/layers/tool/web_search.md +83 -83
  115. package/dist/llm/tool-manifest/ask_user_input.js +1 -1
  116. package/dist/llm/tool-manifest/bash.js +3 -3
  117. package/dist/llm/tool-manifest/create_file.js +4 -4
  118. package/dist/llm/tool-manifest/fetch_sports_data.js +3 -3
  119. package/dist/llm/tool-manifest/image_search.js +2 -2
  120. package/dist/llm/tool-manifest/index.js +59 -0
  121. package/dist/llm/tool-manifest/mcp.js +2 -2
  122. package/dist/llm/tool-manifest/message_compose.js +3 -3
  123. package/dist/llm/tool-manifest/places.js +2 -2
  124. package/dist/llm/tool-manifest/present_files.js +1 -1
  125. package/dist/llm/tool-manifest/recipe.js +2 -2
  126. package/dist/llm/tool-manifest/str_replace.js +5 -5
  127. package/dist/llm/tool-manifest/view.js +3 -3
  128. package/dist/llm/tool-manifest/weather.js +4 -4
  129. package/dist/llm/tool-manifest/web.js +4 -4
  130. package/dist/pi-ecosystem-judgment/causal-judge.js +51 -51
  131. package/dist/pi-ecosystem-judgment/distill-prompt.js +42 -42
  132. package/dist/pi-ecosystem-judgment/distillation.js +14 -14
  133. package/dist/pi-ecosystem-judgment/human-value-store.js +1 -1
  134. package/dist/pi-ecosystem-judgment/monitor-gate.js +28 -28
  135. package/dist/pi-ecosystem-judgment/value-injection.js +102 -102
  136. package/dist/pi-ecosystem-mcp/index.js +146 -5
  137. package/dist/security/context-router-tool.js +15 -15
  138. package/dist/utils/auto-update.js.map +1 -0
  139. package/dist/web/api-config.html +779 -779
  140. package/dist/web/client-hearth.js +10 -10
  141. package/dist/web/client.js.map +7 -0
  142. package/dist/web/components/wallet-viem.mjs +118 -118
  143. package/dist/web/edge-auth-client.js +120 -0
  144. package/dist/web/index.html +472 -472
  145. package/dist/web/manifest.json +20 -20
  146. package/dist/web/server.js +34 -67
  147. package/dist/web/style.css +4946 -4946
  148. package/package.json +195 -195
  149. package/scripts/build-cli.js +215 -215
  150. package/scripts/build-web.ts +130 -130
  151. package/scripts/postinstall.js +152 -152
  152. package/bin/bolloon.js +0 -157
  153. package/dist/pi-ecosystem-colony/index.js +0 -365
  154. package/dist/social/ant-colony/AdaptiveHeartbeat.js +0 -101
  155. package/dist/social/ant-colony/PheromoneEngine.js +0 -227
  156. package/dist/social/ant-colony/index.js +0 -6
  157. package/dist/social/ant-colony/types.js +0 -24
  158. package/dist/storage/trajectory.js +0 -101
  159. package/dist/test/ai-judgment-test.js +0 -80
  160. package/dist/test/bollharness-integration.test.js +0 -318
  161. package/dist/test/channel-agent-multi-dialogue.js +0 -205
  162. package/dist/test/channel-heartbeat-agent-test.js +0 -201
  163. package/dist/test/constraint-layer.test.js +0 -164
  164. package/dist/test/diap-identity-test.js +0 -172
  165. package/dist/test/diap-quick-test.js +0 -62
  166. package/dist/test/global-shared-context.test.js +0 -315
  167. package/dist/test/harness-judgment-injection.test.js +0 -246
  168. package/dist/test/harness-workflow-integrator-test.js +0 -228
  169. package/dist/test/human-value-store.test.js +0 -243
  170. package/dist/test/hybrid-integration-test.js +0 -118
  171. package/dist/test/hybrid-messenger-verify.js +0 -55
  172. package/dist/test/iroh-bistream-debug.js +0 -38
  173. package/dist/test/iroh-communication.test.js +0 -66
  174. package/dist/test/iroh-debug-test.js +0 -57
  175. package/dist/test/iroh-diap-test.js +0 -71
  176. package/dist/test/iroh-direct-connect.js +0 -55
  177. package/dist/test/iroh-e2e-fixed.js +0 -89
  178. package/dist/test/iroh-e2e-same-process.js +0 -63
  179. package/dist/test/iroh-e2e.js +0 -66
  180. package/dist/test/iroh-final-e2e.js +0 -72
  181. package/dist/test/iroh-relay-test.js +0 -37
  182. package/dist/test/iroh-simple-test.js +0 -41
  183. package/dist/test/iroh-transport-verify.js +0 -54
  184. package/dist/test/iroh-transport.test.js +0 -37
  185. package/dist/test/iroh-two-nodes.js +0 -70
  186. package/dist/test/iroh-verify.js +0 -44
  187. package/dist/test/judgment-decision.test.js +0 -219
  188. package/dist/test/llm-judgment-integration.test.js +0 -220
  189. package/dist/test/p2p-agent-complex-dialogue.js +0 -385
  190. package/dist/test/p2p-agent-dialogue.js +0 -341
  191. package/dist/test/p2p-agent-full-bidirectional.js +0 -510
  192. package/dist/test/p2p-agent-harness-flow.js +0 -437
  193. package/dist/test/p2p-agent-harness-single.js +0 -143
  194. package/dist/test/p2p-ai-dialogue-test.js +0 -318
  195. package/dist/test/p2p-cid-connect-test.js +0 -195
  196. package/dist/test/p2p-connect-receiver.js +0 -69
  197. package/dist/test/p2p-doc-transfer.js +0 -110
  198. package/dist/test/p2p-identity-page-test.js +0 -77
  199. package/dist/test/p2p-iroh-test.js +0 -171
  200. package/dist/test/p2p-minimal-test.js +0 -241
  201. package/dist/test/p2p-node-1.js +0 -148
  202. package/dist/test/p2p-node-2.js +0 -148
  203. package/dist/test/p2p-server.js +0 -281
  204. package/dist/test/p2p-two-nodes-test.js +0 -438
  205. package/dist/test/pi-sdk.test.js +0 -44
  206. package/dist/test/set-persona.js +0 -40
  207. package/dist/test/simple.test.js +0 -9
  208. package/dist/test/storage-integration.test.js +0 -150
  209. package/dist/test/subagent-manager.test.js +0 -276
  210. package/dist/test/test-gate-flow.test.js +0 -81
  211. package/dist/test/workflow-engine.test.js +0 -87
  212. 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
  `;
@@ -1042,38 +1042,38 @@ export class PiAgentSession {
1042
1042
  }
1043
1043
  // M2.4: persona 缓存
1044
1044
  if (!this.cachedPersonaSection && this.persona) {
1045
- this.cachedPersonaSection = `
1046
- 角色描述: ${this.persona.description || '无'}
1047
- 性格特点: ${this.persona.personality || '无'}
1048
- 问候语: ${this.persona.greeting || '无'}
1045
+ this.cachedPersonaSection = `
1046
+ 角色描述: ${this.persona.description || '无'}
1047
+ 性格特点: ${this.persona.personality || '无'}
1048
+ 问候语: ${this.persona.greeting || '无'}
1049
1049
  `;
1050
1050
  }
1051
- const systemPrompt = `${this.bootstrapAddition}你是 ${this.identity.name},基于ReAct (Reasoning + Acting)模式工作。${this.cachedPersonaSection}
1052
- 当前工作目录: ${this.cwd}
1053
- 当前身份: ${this.identity.name} (${this.identity.did})
1054
- ${this.currentIntentHint}
1055
-
1056
- ${this.getToolDefinitions()}
1057
-
1058
- 工作模式:
1059
- 1. 理解用户自然语言请求
1060
- 2. 分析需要哪些工具来完成
1061
- 3. 按顺序调用工具并观察结果
1062
- 4. 根据观察结果决定下一步
1063
- 5. 最终给出完整回答
1064
-
1065
- 重要 (一次命中要求):
1066
- - 每次只调用一个工具
1067
- - 仔细分析工具返回结果
1068
- - 当任务完成时,必须在回答末尾添加 <final gen> 标记表示结束
1069
- - 如果需要更多信息,继续调用工具
1070
-
1071
- 【工具调用格式 (严格遵守, 否则系统无法解析)】
1072
- - 你只能输出**一个**工具调用, 不要堆叠多个 invoke
1073
- - 工具调用格式: {"name":"<tool_name>","input":{"arg1":"value1"}}
1074
- - 用 markdown json code block 包裹: \`\`\`json\n{"name":"X","input":{...}}\n\`\`\`
1075
- - 工具调用前可以简短思考 (1-2 句话), 但**不要写长篇 thinking** (会撞 max_tokens)
1076
- - 工具调用后必须等结果, 不要在同一个回复里继续输出
1051
+ const systemPrompt = `${this.bootstrapAddition}你是 ${this.identity.name},基于ReAct (Reasoning + Acting)模式工作。${this.cachedPersonaSection}
1052
+ 当前工作目录: ${this.cwd}
1053
+ 当前身份: ${this.identity.name} (${this.identity.did})
1054
+ ${this.currentIntentHint}
1055
+
1056
+ ${this.getToolDefinitions()}
1057
+
1058
+ 工作模式:
1059
+ 1. 理解用户自然语言请求
1060
+ 2. 分析需要哪些工具来完成
1061
+ 3. 按顺序调用工具并观察结果
1062
+ 4. 根据观察结果决定下一步
1063
+ 5. 最终给出完整回答
1064
+
1065
+ 重要 (一次命中要求):
1066
+ - 每次只调用一个工具
1067
+ - 仔细分析工具返回结果
1068
+ - 当任务完成时,必须在回答末尾添加 <final gen> 标记表示结束
1069
+ - 如果需要更多信息,继续调用工具
1070
+
1071
+ 【工具调用格式 (严格遵守, 否则系统无法解析)】
1072
+ - 你只能输出**一个**工具调用, 不要堆叠多个 invoke
1073
+ - 工具调用格式: {"name":"<tool_name>","input":{"arg1":"value1"}}
1074
+ - 用 markdown json code block 包裹: \`\`\`json\n{"name":"X","input":{...}}\n\`\`\`
1075
+ - 工具调用前可以简短思考 (1-2 句话), 但**不要写长篇 thinking** (会撞 max_tokens)
1076
+ - 工具调用后必须等结果, 不要在同一个回复里继续输出
1077
1077
  - <final gen> 只在**真完成所有任务**时输出, 不要在工具调用前/中输出${this.judgmentGateAddition}${this.contextHintAddition}`;
1078
1078
  // 2026-06-15: 把 currentOnStream 传给 loop, 让 step-timeline 在 pivot 循环里也能 emit step_start/done
1079
1079
  // 之前 loop.execute() 不接 streamCallback, 导致 step-timeline 只能看到老 runReActLoop 路径
@@ -1265,10 +1265,10 @@ ${this.getToolDefinitions()}
1265
1265
  }
1266
1266
  // M2.4: persona section 缓存 — persona 在 loadPersona() 时一次设定, 此后不变
1267
1267
  if (!this.cachedPersonaSection && this.persona) {
1268
- this.cachedPersonaSection = `
1269
- 角色描述: ${this.persona.description || '无'}
1270
- 性格特点: ${this.persona.personality || '无'}
1271
- 问候语: ${this.persona.greeting || '无'}
1268
+ this.cachedPersonaSection = `
1269
+ 角色描述: ${this.persona.description || '无'}
1270
+ 性格特点: ${this.persona.personality || '无'}
1271
+ 问候语: ${this.persona.greeting || '无'}
1272
1272
  `;
1273
1273
  }
1274
1274
  const personaSection = this.cachedPersonaSection;
@@ -1286,26 +1286,26 @@ ${this.getToolDefinitions()}
1286
1286
  .join('\n');
1287
1287
  loopProgressSection = `\n【本轮循环进度】你已完成以下 ${loopActionLog.length} 个动作, 这是连续执行的同一轮任务:\n${actionLines}\n请基于已有结果继续推进, 不要重复执行上面已成功的动作. 全部完成后用 <final gen> 结束.\n`;
1288
1288
  }
1289
- const systemPrompt = `${this.bootstrapAddition}你是 ${this.identity.name},基于ReAct (Reasoning + Acting)模式工作。${personaSection}
1290
- 当前工作目录: ${this.cwd}
1291
- 当前身份: ${this.identity.name} (${this.identity.did})
1292
- ${refineContext}
1293
- ${this.currentIntentHint}
1294
- ${loopProgressSection}
1295
-
1296
- ${toolDefs}
1297
-
1298
- 工作模式:
1299
- 1. 理解用户自然语言请求
1300
- 2. 分析需要哪些工具来完成
1301
- 3. 按顺序调用工具并观察结果
1302
- 4. 根据观察结果决定下一步
1303
- 5. 最终给出完整回答
1304
-
1305
- 重要:
1306
- - 每次只调用一个工具
1307
- - 仔细分析工具返回结果
1308
- - 当任务完成时,必须在回答末尾添加 <final gen> 标记表示结束
1289
+ const systemPrompt = `${this.bootstrapAddition}你是 ${this.identity.name},基于ReAct (Reasoning + Acting)模式工作。${personaSection}
1290
+ 当前工作目录: ${this.cwd}
1291
+ 当前身份: ${this.identity.name} (${this.identity.did})
1292
+ ${refineContext}
1293
+ ${this.currentIntentHint}
1294
+ ${loopProgressSection}
1295
+
1296
+ ${toolDefs}
1297
+
1298
+ 工作模式:
1299
+ 1. 理解用户自然语言请求
1300
+ 2. 分析需要哪些工具来完成
1301
+ 3. 按顺序调用工具并观察结果
1302
+ 4. 根据观察结果决定下一步
1303
+ 5. 最终给出完整回答
1304
+
1305
+ 重要:
1306
+ - 每次只调用一个工具
1307
+ - 仔细分析工具返回结果
1308
+ - 当任务完成时,必须在回答末尾添加 <final gen> 标记表示结束
1309
1309
  - 如果需要更多信息,继续调用工具${this.judgmentGateAddition}${this.contextHintAddition}`;
1310
1310
  // 3 个恢复机制 (Claude Code 论文 9-step pipeline 内部):
1311
1311
  // 1. max output token 升级 (最多 3 次, 每次 maxOutputTokens 翻倍)
@@ -2376,37 +2376,37 @@ ${toolDefs}
2376
2376
  getDefaultResponse(input) {
2377
2377
  const operationsRef = PiAgentSession.getOperationsReference();
2378
2378
  if (operationsRef) {
2379
- return `收到了: "${input}"
2380
-
2381
- 我是一个判断力处理智能体,支持自然语言交互。
2382
-
2383
- 可用操作(直接说出即可):
2384
- ${this.extractOperationsFromRef(operationsRef)}
2385
-
2386
- 示例请求:
2387
- - "读取 src/index.ts 文件"
2388
- - "总结一下 README.md"
2389
- - "查看当前连接了哪些节点"
2379
+ return `收到了: "${input}"
2380
+
2381
+ 我是一个判断力处理智能体,支持自然语言交互。
2382
+
2383
+ 可用操作(直接说出即可):
2384
+ ${this.extractOperationsFromRef(operationsRef)}
2385
+
2386
+ 示例请求:
2387
+ - "读取 src/index.ts 文件"
2388
+ - "总结一下 README.md"
2389
+ - "查看当前连接了哪些节点"
2390
2390
  - "向 QmABC... 发送测试消息"`;
2391
2391
  }
2392
- return `收到了: "${input}"
2393
-
2394
- 我是一个判断力处理智能体,支持自然语言交互。
2395
-
2396
- 可用操作(直接说出即可):
2397
- - "读取 README.md" - 读取并分析文档
2398
- - "总结文档" - 总结文档内容
2399
- - "改进文档,按照X要求" - 改进文档
2400
- - "查看节点" - 查看已连接的对等节点
2401
- - "向X发送消息Y" - 向对等节点发送消息
2402
- - "广播消息X" - 广播消息到所有节点
2403
- - "查看身份" - 查看当前智能体身份
2404
- - "查看日志" - 查看最近操作日志
2405
-
2406
- 示例请求:
2407
- - "读取 src/index.ts 文件"
2408
- - "总结一下 README.md"
2409
- - "查看当前连接了哪些节点"
2392
+ return `收到了: "${input}"
2393
+
2394
+ 我是一个判断力处理智能体,支持自然语言交互。
2395
+
2396
+ 可用操作(直接说出即可):
2397
+ - "读取 README.md" - 读取并分析文档
2398
+ - "总结文档" - 总结文档内容
2399
+ - "改进文档,按照X要求" - 改进文档
2400
+ - "查看节点" - 查看已连接的对等节点
2401
+ - "向X发送消息Y" - 向对等节点发送消息
2402
+ - "广播消息X" - 广播消息到所有节点
2403
+ - "查看身份" - 查看当前智能体身份
2404
+ - "查看日志" - 查看最近操作日志
2405
+
2406
+ 示例请求:
2407
+ - "读取 src/index.ts 文件"
2408
+ - "总结一下 README.md"
2409
+ - "查看当前连接了哪些节点"
2410
2410
  - "向 QmABC... 发送测试消息"`;
2411
2411
  }
2412
2412
  extractOperationsFromRef(ref) {
@@ -2431,13 +2431,13 @@ ${this.extractOperationsFromRef(operationsRef)}
2431
2431
  }
2432
2432
  }
2433
2433
  return operationLines.length > 0 ? operationLines.join('\n') :
2434
- ` - "读取 README.md" - 读取并分析文档
2435
- - "总结文档" - 总结文档内容
2436
- - "改进文档,按照X要求" - 改进文档
2437
- - "查看节点" - 查看已连接的对等节点
2438
- - "向X发送消息Y" - 向对等节点发送消息
2439
- - "广播消息X" - 广播消息到所有节点
2440
- - "查看身份" - 查看当前智能体身份
2434
+ ` - "读取 README.md" - 读取并分析文档
2435
+ - "总结文档" - 总结文档内容
2436
+ - "改进文档,按照X要求" - 改进文档
2437
+ - "查看节点" - 查看已连接的对等节点
2438
+ - "向X发送消息Y" - 向对等节点发送消息
2439
+ - "广播消息X" - 广播消息到所有节点
2440
+ - "查看身份" - 查看当前智能体身份
2441
2441
  - "查看日志" - 查看最近操作日志`;
2442
2442
  }
2443
2443
  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 代码块, 取第一个 {...}) */
@@ -866,8 +866,8 @@ export class WorkflowPivotLoop {
866
866
  // 完整重装只在 iter=1 和 compact 之后两次
867
867
  const lines = fullSystemPrompt.split('\n');
868
868
  const identityLine = lines.find((l) => l.includes('你是') && !l.includes('(续)')) ?? '';
869
- return `[continuation] 你的 persona + tools + judgments 已在首轮 messageHistory 中.
870
- ${identityLine ? identityLine + '\n' : ''}当前 step 别再读 persona 全文, 继续推进任务即可.
869
+ return `[continuation] 你的 persona + tools + judgments 已在首轮 messageHistory 中.
870
+ ${identityLine ? identityLine + '\n' : ''}当前 step 别再读 persona 全文, 继续推进任务即可.
871
871
  > <final gen> 只在真完成时输出.`;
872
872
  }
873
873
  /**
@@ -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 {
@@ -253,9 +253,9 @@ export async function generateJudgmentInjection(filePath, gate, options = {}) {
253
253
  const header = gate === 3
254
254
  ? '# Plan Freeze - Decision Principles'
255
255
  : `# Gate ${gate} - Active Judgments`;
256
- return `${header}
257
- # Path: ${filePath}
258
- # Confidence: ${(result.confidence * 100).toFixed(0)}%
259
-
256
+ return `${header}
257
+ # Path: ${filePath}
258
+ # Confidence: ${(result.confidence * 100).toFixed(0)}%
259
+
260
260
  ${result.contextYaml}`;
261
261
  }