@bolloon/bolloon-agent 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/bin/bolloon-cli.cjs +157 -0
  2. package/bin/bolloon-daemon.sh +207 -0
  3. package/bin/bolloon.cmd +11 -0
  4. package/dist/agents/constraint-layer.js +10 -15
  5. package/dist/agents/pi-sdk.js +433 -106
  6. package/dist/agents/protocol.js +82 -1
  7. package/dist/agents/subagent-manager.js +2 -2
  8. package/dist/agents/workflow-engine.js +15 -20
  9. package/dist/agents/workflow-pivot-loop.js +541 -0
  10. package/dist/bollharness/src/index.js +5 -0
  11. package/dist/bollharness/src/scripts/checks/check_adr_plan_numbering.js +6 -0
  12. package/dist/bollharness/src/scripts/checks/check_api_types.js +45 -0
  13. package/dist/bollharness/src/scripts/checks/check_artifact_link.js +146 -0
  14. package/dist/bollharness/src/scripts/checks/check_bridge_deps.js +6 -0
  15. package/dist/bollharness/src/scripts/checks/check_bugfix_binding.js +6 -0
  16. package/dist/bollharness/src/scripts/checks/check_bugfix_binding_ci.js +6 -0
  17. package/dist/bollharness/src/scripts/checks/check_doc_file_references.js +6 -0
  18. package/dist/bollharness/src/scripts/checks/check_doc_freshness.js +135 -0
  19. package/dist/bollharness/src/scripts/checks/check_doc_links.js +31 -0
  20. package/dist/bollharness/src/scripts/checks/check_file_existence_claims.js +6 -0
  21. package/dist/bollharness/src/scripts/checks/check_fragment_integrity.js +34 -0
  22. package/dist/bollharness/src/scripts/checks/check_hook_installed.js +63 -0
  23. package/dist/bollharness/src/scripts/checks/check_issue_closure.js +41 -0
  24. package/dist/bollharness/src/scripts/checks/check_mcp_parity.js +6 -0
  25. package/dist/bollharness/src/scripts/checks/check_security.js +48 -0
  26. package/dist/bollharness/src/scripts/checks/check_skill_parity.js +6 -0
  27. package/dist/bollharness/src/scripts/checks/check_versions.js +6 -0
  28. package/dist/bollharness/src/scripts/checks/finding.js +13 -0
  29. package/dist/bollharness/src/scripts/checks/next_decision_number.js +20 -0
  30. package/dist/bollharness/src/scripts/checks/regenerate_magic_docs.js +6 -0
  31. package/dist/bollharness/src/scripts/ci/detect_rebaseline_triggers.js +8 -0
  32. package/dist/bollharness/src/scripts/ci/scan_subprocess_cfg.js +8 -0
  33. package/dist/bollharness/src/scripts/ci/scan_verify_artifacts.js +8 -0
  34. package/dist/bollharness/src/scripts/ci/scan_yaml_schema.js +8 -0
  35. package/dist/bollharness/src/scripts/context_router.js +67 -0
  36. package/dist/bollharness/src/scripts/deploy-guard.js +157 -0
  37. package/dist/bollharness/src/scripts/guard-feedback.js +192 -0
  38. package/dist/bollharness/src/scripts/guard_router.js +158 -0
  39. package/dist/bollharness/src/scripts/hooks/_hook_output.js +6 -0
  40. package/dist/bollharness/src/scripts/hooks/auto-python3.js +6 -0
  41. package/dist/bollharness/src/scripts/hooks/deploy-progress-on-session-end.js +6 -0
  42. package/dist/bollharness/src/scripts/hooks/failure-analyzer.js +6 -0
  43. package/dist/bollharness/src/scripts/hooks/gate-judgment-inject.js +92 -0
  44. package/dist/bollharness/src/scripts/hooks/gate-transition-judgment.js +63 -0
  45. package/dist/bollharness/src/scripts/hooks/inbox-ack.js +6 -0
  46. package/dist/bollharness/src/scripts/hooks/inbox-inject-on-start.js +6 -0
  47. package/dist/bollharness/src/scripts/hooks/inbox-validate.js +6 -0
  48. package/dist/bollharness/src/scripts/hooks/inbox-write-ledger.js +6 -0
  49. package/dist/bollharness/src/scripts/hooks/initializer-agent.js +6 -0
  50. package/dist/bollharness/src/scripts/hooks/loop-detection.js +73 -0
  51. package/dist/bollharness/src/scripts/hooks/owner-guard.js +6 -0
  52. package/dist/bollharness/src/scripts/hooks/precompact.js +6 -0
  53. package/dist/bollharness/src/scripts/hooks/review-agent-gatekeeper.js +6 -0
  54. package/dist/bollharness/src/scripts/hooks/risk-tracker.js +108 -0
  55. package/dist/bollharness/src/scripts/hooks/sanitize-on-read.js +6 -0
  56. package/dist/bollharness/src/scripts/hooks/session-reflection.js +7 -0
  57. package/dist/bollharness/src/scripts/hooks/session-start-magic-docs.js +7 -0
  58. package/dist/bollharness/src/scripts/hooks/session-start-reset-risk.js +7 -0
  59. package/dist/bollharness/src/scripts/hooks/session-start-toolkit-reminder.js +7 -0
  60. package/dist/bollharness/src/scripts/hooks/stop-evaluator.js +157 -0
  61. package/dist/bollharness/src/scripts/hooks/tool-call-counter.js +6 -0
  62. package/dist/bollharness/src/scripts/hooks/trace-analyzer.js +10 -0
  63. package/dist/bollharness/src/scripts/install/install-trust-token.js +7 -0
  64. package/dist/bollharness/src/scripts/install/multi_project_registry.js +9 -0
  65. package/dist/bollharness/src/scripts/install/phase2_auto.js +21 -0
  66. package/dist/bollharness/src/scripts/install/pre_commit_installer.js +6 -0
  67. package/dist/bollharness/src/scripts/install/tier_selector.js +7 -0
  68. package/dist/bollharness/src/scripts/install/transcript_miner.js +7 -0
  69. package/dist/bollharness/src/scripts/lib/claim_patterns.js +10 -0
  70. package/dist/bollharness/src/scripts/lib/sanitize_patterns.js +12 -0
  71. package/dist/bollharness/src/scripts/sanitize.js +6 -0
  72. package/dist/bollharness-integration/channel-judgment-engine.js +530 -0
  73. package/dist/bollharness-integration/context-chain-router.js +383 -0
  74. package/dist/bollharness-integration/context-router-judgment.js +13 -21
  75. package/dist/bollharness-integration/context-router.js +22 -64
  76. package/dist/bollharness-integration/gate-state-machine.js +14 -19
  77. package/dist/bollharness-integration/gate-transition-hooks.js +16 -61
  78. package/dist/bollharness-integration/guard-checker.js +21 -68
  79. package/dist/bollharness-integration/index.js +14 -124
  80. package/dist/bollharness-integration/integration.js +13 -20
  81. package/dist/bollharness-integration/llm-judgment-engine.js +569 -0
  82. package/dist/bollharness-integration/skill-adapter.js +18 -64
  83. package/dist/cli-entry.js +261 -0
  84. package/dist/constraint-runtime/src/commands.js +17 -7
  85. package/dist/constraint-runtime/src/constraint/budget.js +1 -6
  86. package/dist/constraint-runtime/src/constraint/permission.js +1 -6
  87. package/dist/constraint-runtime/src/models.js +1 -3
  88. package/dist/constraint-runtime/src/tools.js +17 -7
  89. package/dist/constraints/index.js +1 -7
  90. package/dist/documents/reader.js +8 -49
  91. package/dist/heartbeat/DaemonManager.js +242 -0
  92. package/dist/heartbeat/HealthMonitor.js +285 -0
  93. package/dist/heartbeat/StartupVerifier.js +205 -0
  94. package/dist/heartbeat/Watchdog.js +168 -0
  95. package/dist/heartbeat/index.js +84 -0
  96. package/dist/heartbeat/types.js +5 -0
  97. package/dist/index.js +381 -28
  98. package/dist/llm/config-store.js +31 -57
  99. package/dist/llm/llm-judgment-client.js +389 -0
  100. package/dist/llm/pi-ai.js +9 -52
  101. package/dist/network/agent-network.js +46 -90
  102. package/dist/network/hybrid-messenger.js +125 -0
  103. package/dist/network/iroh-bootstrap.js +38 -0
  104. package/dist/network/iroh-discovery.js +145 -0
  105. package/dist/network/iroh-integration.js +9 -16
  106. package/dist/network/iroh-transport.js +10 -48
  107. package/dist/network/p2p.js +23 -62
  108. package/dist/network/storage/adapters/json-adapter.js +4 -42
  109. package/dist/network/storage/index.js +147 -0
  110. package/dist/network/storage/types.js +14 -0
  111. package/dist/pi-ecosystem/index.js +233 -0
  112. package/dist/pi-ecosystem-colony/index.js +29 -90
  113. package/dist/pi-ecosystem-goals/index.js +20 -74
  114. package/dist/pi-ecosystem-judgment/decision.js +29 -47
  115. package/dist/pi-ecosystem-judgment/distillation.js +16 -29
  116. package/dist/pi-ecosystem-judgment/human-value-store.js +13 -60
  117. package/dist/pi-ecosystem-judgment/index.js +21 -74
  118. package/dist/pi-ecosystem-judgment/value-injection.js +26 -72
  119. package/dist/pi-ecosystem-mcp/index.js +24 -78
  120. package/dist/pi-ecosystem-subagents/index.js +20 -69
  121. package/dist/social/ant-colony/AdaptiveHeartbeat.js +3 -8
  122. package/dist/social/ant-colony/PheromoneEngine.js +11 -49
  123. package/dist/social/ant-colony/index.js +6 -0
  124. package/dist/social/ant-colony/types.js +4 -8
  125. package/dist/social/channels/ChannelManager.js +8 -46
  126. package/dist/social/channels/DiapChannelBridge.js +9 -47
  127. package/dist/social/channels/InterestMatcher.js +2 -7
  128. package/dist/social/channels/channel-agent-session.js +309 -0
  129. package/dist/social/channels/channel-heartbeat-agent.js +494 -0
  130. package/dist/social/channels/diap-doc-parser.js +204 -0
  131. package/dist/social/channels/harness-workflow-integrator.js +446 -0
  132. package/dist/social/channels/index.js +9 -0
  133. package/dist/social/channels/types.js +3 -7
  134. package/dist/social/global-shared-context.js +6 -47
  135. package/dist/social/heartbeat.js +29 -72
  136. package/dist/social/persona/enhanced-persona.js +299 -0
  137. package/dist/web/client.js +302 -136
  138. package/dist/web/components/p2p/index.js +159 -9
  139. package/dist/web/components/p2p/p2p-connection.js +136 -0
  140. package/dist/web/components/p2p/p2p-manager.js +24 -0
  141. package/dist/web/components/p2p/p2p-store-memory.js +1 -1
  142. package/dist/web/components/p2p/types.js +7 -0
  143. package/dist/web/index.html +5 -0
  144. package/dist/web/style.css +118 -0
  145. package/package.json +12 -6
  146. package/scripts/build-cli.js +206 -0
  147. package/scripts/postinstall.js +153 -0
  148. package/src/agents/pi-sdk.ts +347 -28
  149. package/src/agents/protocol.ts +95 -1
  150. package/src/agents/workflow-pivot-loop.ts +674 -0
  151. package/src/bollharness/CLAUDE.md +73 -0
  152. package/src/bollharness/README.md +143 -0
  153. package/src/bollharness/README.zh-CN.md +131 -0
  154. package/src/bollharness/reference/boll-reference/scripts/hooks/stop-evaluator.md +57 -0
  155. package/src/bollharness/scripts/context-fragments/artifact-linkage.md +14 -0
  156. package/src/bollharness/scripts/context-fragments/auth-consumers.md +17 -0
  157. package/src/bollharness/scripts/context-fragments/bridge-constitution.md +13 -0
  158. package/src/bollharness/scripts/context-fragments/catalyst-distributed.md +18 -0
  159. package/src/bollharness/scripts/context-fragments/closure-checklist.md +13 -0
  160. package/src/bollharness/scripts/context-fragments/contract-consumers.md +15 -0
  161. package/src/bollharness/scripts/context-fragments/db-shared-structures.md +15 -0
  162. package/src/bollharness/scripts/context-fragments/fixed-three-layers.md +19 -0
  163. package/src/bollharness/scripts/context-fragments/general-dev-principles.md +11 -0
  164. package/src/bollharness/scripts/context-fragments/issue-first.md +8 -0
  165. package/src/bollharness/scripts/context-fragments/mcp-parity.md +16 -0
  166. package/src/bollharness/scripts/context-fragments/pi-agent-operations.md +108 -0
  167. package/src/bollharness/scripts/context-fragments/protocol-consumers.md +15 -0
  168. package/src/bollharness/scripts/context-fragments/run-events-consumers.md +15 -0
  169. package/src/bollharness/scripts/context-fragments/scene-fidelity.md +13 -0
  170. package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +15 -0
  171. package/src/bollharness/scripts/context-fragments/two-language.md +15 -0
  172. package/src/bollharness/scripts/context-fragments/version-sources.md +14 -0
  173. package/src/bollharness/scripts/hooks/stop-evaluator.md +83 -0
  174. package/src/bollharness/templates/scaffold/CLAUDE.md +89 -0
  175. package/src/cli-entry.ts +304 -0
  176. package/src/heartbeat/DaemonManager.ts +283 -0
  177. package/src/heartbeat/HealthMonitor.ts +316 -0
  178. package/src/heartbeat/StartupVerifier.ts +223 -0
  179. package/src/heartbeat/Watchdog.ts +198 -0
  180. package/src/heartbeat/index.ts +108 -0
  181. package/src/heartbeat/types.ts +82 -0
  182. package/src/llm/config-store.ts +23 -5
  183. package/src/network/iroh-transport.ts +3 -3
  184. package/src/web/client.js +302 -136
  185. package/src/web/components/p2p/P2PModal.tsx +91 -3
  186. package/src/web/components/p2p/index.ts +171 -9
  187. package/src/web/components/p2p/p2p-connection.ts +153 -1
  188. package/src/web/components/p2p/p2p-manager.ts +39 -1
  189. package/src/web/components/p2p/p2p-store-memory.ts +1 -1
  190. package/src/web/components/p2p/p2p-tools.ts +315 -0
  191. package/src/web/components/p2p/types.ts +58 -0
  192. package/src/web/design.md +99 -0
  193. package/src/web/index.html +5 -0
  194. package/src/web/server.ts +353 -36
  195. package/src/web/style.css +118 -0
  196. package/tsconfig.cli.json +16 -0
  197. package/tsconfig.electron.json +1 -1
  198. package/tsconfig.json +1 -2
  199. package/dist/web/server.js +0 -1647
  200. package/dist/web/server.js.map +0 -1
@@ -0,0 +1,108 @@
1
+ ---
2
+ paths:
3
+ - "src/agents/**"
4
+ ---
5
+
6
+ # Pi Agent 操作与工具定义
7
+
8
+ > 来源: pi-sdk.ts TOOL_DEFINITIONS + getDefaultResponse
9
+ > 关联: src/agents/constraint-layer.ts(工具注册)
10
+
11
+ ---
12
+
13
+ ## 核心操作
14
+
15
+ | 操作 | 描述 | 方法签名 |
16
+ |------|------|----------|
17
+ | 读取文档 | 读取并分析文档内容,支持 .txt, .md, .pdf, .docx | `read_document(path)` |
18
+ | 总结文档 | 总结文档内容,可选提供上下文 | `summarize_document(path, context?)` |
19
+ | 改进文档 | 改进文档,需提供文件路径和改进要求 | `improve_document(path, requirements)` |
20
+ | 查看节点 | 查看已连接的对等节点 | `list_peers()` |
21
+ | 发送消息 | 向指定对等节点发送消息 | `send_message(peer_id, message)` |
22
+ | 广播消息 | 广播消息到所有节点 | `broadcast_message(message)` |
23
+ | 查看身份 | 查看当前智能体身份 | `get_identity()` |
24
+ | 设置 Persona | 更新智能体 persona 信息 | `set_persona(persona_json)` |
25
+ | 执行工作流 | 执行预定义工作流 | `run_workflow(steps)` |
26
+ | 查看日志 | 查看最近操作日志 | `get_operation_logs()` |
27
+ | 列出文件 | 列出目录中的文件 | `list_files(path?)` |
28
+ | 读取目录 | 读取目录内容,返回文件列表和目录结构 | `read_directory(path?)` |
29
+
30
+ ---
31
+
32
+ ## 自主循环机制
33
+
34
+ 智能体基于 ReAct (Reasoning + Acting) 模式工作,具备自动评估质量和错误恢复能力:
35
+
36
+ ### 质量评估与自动改进
37
+ - **质量阈值**: `0.6` (6/10)
38
+ - **最大改进次数**: `3` 次
39
+ - 当回复或工具执行结果质量低于阈值时,自动触发改进循环
40
+ - 改进时在 system prompt 中添加质量提示,让 LLM 重新生成更优回答
41
+
42
+ ### 错误处理与自动恢复
43
+ - **连续错误上限**: `3` 次
44
+ - 工具执行失败时增加错误计数
45
+ - 达到连续错误上限时,添加错误上下文让 LLM 换一种方式处理
46
+ - 工具执行异常会被捕获并记录,不中断循环
47
+
48
+ ### 循环继续条件
49
+ 当 LLM 返回不是 tool call 格式时,判断是否需要继续循环:
50
+ 1. 包含错误/失败信息(不存在、找不到、错误、failed 等)
51
+ 2. 回复太短(<100 字符且无换行),可能是中间回复
52
+ 3. 包含问号,可能是需要更多信息
53
+ 4. 不包含明确结论(完成、结果、答案等)
54
+
55
+ 满足以上任一条件且循环未达上限,则继续处理。
56
+
57
+ ### 重试机制
58
+ - 工具调用失败时重试(最多 3 次)
59
+ - 汇报发送失败时重试(最多 2 次,指数退避)
60
+ - 失败的汇报会进入待重试队列
61
+
62
+ ---
63
+
64
+ ## 示例请求格式
65
+
66
+ ### 文档操作
67
+ ```
68
+ "读取 README.md"
69
+ "总结一下 src/index.ts"
70
+ "改进文档,按照更清晰的错误处理要求"
71
+ ```
72
+
73
+ ### P2P 网络操作
74
+ ```
75
+ "查看当前连接了哪些节点"
76
+ "向 QmABC... 发送测试消息"
77
+ "广播消息:系统将在 10 分钟后维护"
78
+ ```
79
+
80
+ ### 身份与状态
81
+ ```
82
+ "查看身份"
83
+ "查看日志"
84
+ ```
85
+
86
+ ---
87
+
88
+ ## 工具注册位置
89
+
90
+ 工具在 `pi-sdk.ts` 的 `PiAgent` 类构造函数中注册,映射到:
91
+ - `src/agents/constraint-layer.ts` — ConstraintLayer 基类提供的基础能力
92
+ - `src/network/p2p.ts` — P2P 网络模块
93
+ - `src/documents/reader.ts` — 文档读取模块
94
+
95
+ ---
96
+
97
+ ## 自然语言指令映射
98
+
99
+ | 自然语言指令 | 解析关键词 | 执行方法 |
100
+ |-------------|-----------|----------|
101
+ | 读取 X | `读取`、`read_document`、`read` | `readDocument(path)` |
102
+ | 总结文档 | `总结`、`summarize_document` | `summarizeDocument(path, context?)` |
103
+ | 改进文档 | `改进`、`improve_document` | `improveDocument(request)` |
104
+ | 查看节点 | `查看节点`、`list_peers` | `listPeers()` |
105
+ | 发送消息 | `向 X 发送消息`、`send_message` | `sendMessage(peerId, message)` |
106
+ | 广播消息 | `广播消息`、`broadcast_message` | `broadcast(message)` |
107
+ | 查看身份 | `查看身份`、`get_identity` | `getIdentity()` |
108
+ | 查看日志 | `查看日志`、`get_operation_logs` | `getOperationLogs()` |
@@ -0,0 +1,15 @@
1
+ ## Protocol API 消费方
2
+
3
+ 你正在编辑 /protocol/ 相关代码。以下是 Protocol API 的消费方列表:
4
+
5
+ | 消费方 | 入口 | 认证方式 |
6
+ |--------|------|----------|
7
+ | MCP Server (Python) | `mcp-server/boll_mcp/client.py` | session token |
8
+ | MCP Server (Node) | `mcp-server-node/src/client.ts` | session token |
9
+ | 前端 website | `website/` fetch 调用 | session token (cookie) |
10
+ | Bridge Agent | `bridge_agent/` | bridge API key |
11
+ | 外部 A2A 调用方 | federation endpoint | DID 签名 |
12
+
13
+ **行为约束**: 修改任何 /protocol/ 路由的请求/响应结构时,必须检查上述所有消费方是否兼容。
14
+ 不得在不更新消费方的情况下修改返回字段名或删除字段。
15
+ 新增字段必须是 optional,避免破坏现有消费方。
@@ -0,0 +1,15 @@
1
+ ## run_events 消费方(共享结构)
2
+
3
+ 你正在编辑 run_events 相关代码。此表有 6 个消费方,各自角色不同:
4
+
5
+ | 消费方 | 读/写 | 用途 | 关键依赖 |
6
+ |--------|-------|------|----------|
7
+ | Bridge events 路由 | 写 | 接收 worker 上报的事件 | event_type 枚举 |
8
+ | Catalyst coordinator | 写 | 记录协商轮次事件 | round_number, role |
9
+ | Run status API | 读 | 前端展示进度 | 按 run_id 查询 + 时间排序 |
10
+ | Run result API | 读 | 提取最终产物 | artifact 类型过滤 |
11
+ | Admin event log | 读 | 运维审计 | 全字段 |
12
+ | WebSocket hub | 读 | 实时推送 | 增量查询(last_id) |
13
+
14
+ **行为约束**: 修改 run_events 表结构或写入逻辑时,必须逐一确认 6 个消费方不受影响。
15
+ 不得假设"只有一个地方读"。读模型截断会导致长 run 状态不正确。
@@ -0,0 +1,13 @@
1
+ ## 场景保真度分级
2
+
3
+ 你正在编辑场景相关代码。每个场景有明确的保真度等级:
4
+
5
+ | 等级 | 含义 | 数据来源 | 示例 |
6
+ |------|------|----------|------|
7
+ | **real** | 接真实 Protocol API | 生产后端 | startup-hub |
8
+ | **demo** | 有独立后端但非协议链路 | demo 专用 API | ai-gig-market |
9
+ | **shell** | 纯前端展示,无后端 | 静态/mock 数据 | 其他展示页 |
10
+
11
+ **行为约束**: 文档和代码中声明的保真度必须与运行时实际行为一致。
12
+ 不得在文档中声称"真实协议"而代码跑 demo fallback(承诺 vs 现实漂移)。
13
+ 修改场景接入方式时,必须同步更新场景配置中的 fidelity 字段。
@@ -0,0 +1,15 @@
1
+ ## 真相源优先级
2
+
3
+ 你正在编辑核心文档。boll 的真相源有明确的优先级:
4
+
5
+ | 优先级 | 来源 | 说明 |
6
+ |--------|------|------|
7
+ | 1 | 运行中的代码 | 实际行为是最终真相 |
8
+ | 2 | 数据库 schema + 测试 | 可执行的约束 |
9
+ | 3 | ADR / TECH / PLAN 文档 | 设计决策记录 |
10
+ | 4 | CLAUDE.md | 开发指导(派生自上层) |
11
+ | 5 | MEMORY.md | 会话间记忆(最易过期) |
12
+
13
+ **行为约束**: 当不同层级的信息冲突时,必须以高优先级来源为准并修正低优先级来源。
14
+ CLAUDE.md 中的信息必须可以从代码或 ADR 中验证——不得包含无法溯源的断言。
15
+ 修改真相源文件时,必须检查下游是否需要同步更新。
@@ -0,0 +1,15 @@
1
+ ## 两套语言体系
2
+
3
+ 你正在编辑面向用户的代码。协议术语和用户语言必须严格分离:
4
+
5
+ **协议层**(仅开发者/文档可见):
6
+ formulation, crystallization, catalyst, nomination, intent field, operator, resonance
7
+
8
+ **用户层**(UI/文案/帮助文本):
9
+ 需求澄清, 多方协商, 协调, 推荐, 能力匹配
10
+
11
+ **行为约束**: 前端 UI、用户提示、错误消息中不得出现协议内部术语。
12
+ 用户永远不需要知道"结晶"是什么——他们只知道"多方协商"。
13
+ 比喻:酒店管家不会跟客人说"我现在执行 housekeeping protocol"。
14
+
15
+ 禁词(用户可见文本): "播种意图"、"共振"、"场域"、"结晶"等诗意表达。
@@ -0,0 +1,14 @@
1
+ ## 版本号来源清单
2
+
3
+ 你正在编辑版本相关文件。一个事实只允许有一个定义:
4
+
5
+ | 版本号 | 权威来源 | 必须同步的位置 |
6
+ |--------|----------|----------------|
7
+ | MCP Python | `mcp-server/pyproject.toml` | CLAUDE.md 引用 |
8
+ | MCP Node | `mcp-server-node/package.json` | 必须与 Python 版本一致 |
9
+ | 后端 API | `backend/product/protocol/service.py` | /protocol 元数据返回 |
10
+ | 前端 | `website/package.json` | 部署产物 BUILD_ID |
11
+
12
+ **行为约束**: 修改任何版本号时,必须同步所有关联位置。
13
+ Python MCP 和 Node MCP 版本号必须完全一致,不得出现 0.x.y vs 0.x.z 的漂移。
14
+ "一个事实一个定义"——如果两个地方都写死版本号,其中一个必须是自动派生的。
@@ -0,0 +1,83 @@
1
+ # Stop Hook: Completion Proposal + Independent Review (ADR-044 §3.4 L3+L4)
2
+
3
+ 你**不是** Evaluator。你是被评估的一方。你的工作是:
4
+ 1. 写出你做了什么(proposal)
5
+ 2. 请一个独立 agent 来评你
6
+
7
+ **禁止自己给自己打分。** 自评有结构性利益冲突(Anthropic: "Agents consistently overpraise their own work")。
8
+
9
+ ## Step 1: 写 Completion Proposal
10
+
11
+ 将以下 JSON 写入 `.boll/state/completion-proposal.json`:
12
+
13
+ ```json
14
+ {
15
+ "session_id": "<当前 session 标识>",
16
+ "timestamp": "<ISO 8601>",
17
+ "summary": "<1-3 句话描述本 session 做了什么>",
18
+ "files_changed": ["<从 git diff 或 risk-snapshot 获取>"],
19
+ "evidence": {
20
+ "tests_run": "<运行了哪些测试,结果如何>",
21
+ "verification_commands": ["<实际执行的验证命令>"],
22
+ "commits": ["<本 session 的 commit hash + message>"]
23
+ },
24
+ "known_limitations": ["<诚实列出已知的未完成项或风险>"],
25
+ "task_reference": "<TASK.md 路径或用户原始指令摘要>"
26
+ }
27
+ ```
28
+
29
+ **要求**:
30
+ - `files_changed` 必须从 `git diff` 或 risk-snapshot 的 `files_touched` 取,**不得凭记忆列举**
31
+ - `evidence` 中的测试结果必须是实际运行输出,不是"应该通过"
32
+ - `known_limitations` 必须诚实 — 这是给 reviewer 的线索,不是给自己开脱
33
+
34
+ ## Step 2: Spawn 独立 Reviewer
35
+
36
+ 写完 proposal 后,**必须** spawn 一个独立审查 agent:
37
+
38
+ ```
39
+ Agent({
40
+ subagent_type: "review-readonly",
41
+ description: "Completion review",
42
+ prompt: `你是独立的 Completion Reviewer(ADR-044 L4)。
43
+ 你的任务是验证 agent 的 completion proposal 是否与实际代码变更一致。
44
+
45
+ 读取 .boll/state/completion-proposal.json,然后:
46
+
47
+ 1. **Proposal vs Reality**:git diff 的实际变更是否与 proposal.files_changed 一致?有遗漏吗?
48
+ 2. **Evidence 可信度**:proposal.evidence 中声称的测试/验证,结果是否真实?
49
+ 3. **半成品检查**:变更文件中有没有 TODO/FIXME/HACK?有没有 dead code?
50
+ 4. **契约一致性**:如果改了 API/config/路由,所有引用处是否同步更新?
51
+ 5. **已知限制诚实度**:proposal.known_limitations 是否遗漏了明显风险?
52
+
53
+ 评分(每维 1-5,任何维 < 3 = FAIL):
54
+ - Completeness: proposal 是否覆盖所有实际变更
55
+ - Honesty: evidence 和 limitations 是否真实
56
+ - Quality: 代码变更本身的质量
57
+ - Consistency: 跨文件/跨层的一致性
58
+
59
+ 输出格式:
60
+ ## Verdict: PASS / FAIL
61
+ ## Scores: Completeness X/5, Honesty X/5, Quality X/5, Consistency X/5
62
+ ## Findings: [具体发现列表]
63
+ ## Recommendation: [如果 FAIL,具体要修什么]`
64
+ })
65
+ ```
66
+
67
+ ## Step 3: 根据 Reviewer 裁决行动
68
+
69
+ - **Reviewer 说 PASS** → 你可以 Stop
70
+ - **Reviewer 说 FAIL** → 按 Recommendation 修复,修复后再尝试 Stop
71
+ - **Reviewer spawn 失败**(超时/权限等)→ 降级为 PreCompletionChecklist 自检(下方),但必须在输出中声明 "独立审查未执行,以下为自检降级"
72
+
73
+ ## 降级 Fallback: PreCompletionChecklist(仅当 reviewer 不可用时)
74
+
75
+ 如果因环境限制无法 spawn reviewer,执行以下自检:
76
+
77
+ 1. **Git 状态**: 所有新文件是否已 `git add`?是否有未保存的变更?
78
+ 2. **测试**: 如果有代码变更,相关测试是否通过?
79
+ 3. **文档一致性**: 代码变更是否需要更新文档?
80
+ 4. **无半成品**: 是否有 TODO/FIXME/HACK 被遗留?
81
+ 5. **契约一致性**: API 类型、路由路径、配置 key 是否在所有引用处一致?
82
+
83
+ **但必须标注**:这是自检降级,不是独立审查。
@@ -0,0 +1,89 @@
1
+ # CLAUDE.md
2
+
3
+ <!--
4
+ Auto-generated by bollharness installer.
5
+ This file is the primary instruction source for Claude Code sessions.
6
+ Edit freely — the installer will NOT overwrite an existing CLAUDE.md.
7
+ -->
8
+
9
+ ## Project Overview
10
+
11
+ <!-- TODO: 描述你的项目 — 做什么、技术栈、部署方式 -->
12
+
13
+ ## Governance System (bollharness)
14
+
15
+ This project is managed by [bollharness](https://github.com/anthropics/bollharness) — an AI agent session governance framework. The following hooks and guards run automatically during Claude Code sessions.
16
+
17
+ ### Hook Lifecycle
18
+
19
+ | Stage | Hook | What it does |
20
+ |-------|------|-------------|
21
+ | SessionStart | `session-start-reset-risk.ts` | Reset risk snapshot for new session |
22
+ | SessionStart | `session-start-magic-docs.ts` | Load project-specific context documents |
23
+ | SessionStart | `session-start-toolkit-reminder.ts` | Surface available skills and tools |
24
+ | PreToolUse * | `tool-call-counter.ts` | Track tool call frequency for observability |
25
+ | PreToolUse Bash | `deploy-guard.ts` | Block unauthorized deployments |
26
+ | PreToolUse Bash | `auto-python3.ts` | Intercept bare `python` → `python3` |
27
+ | PreToolUse Task | `review-agent-gatekeeper.ts` | Enforce read-only isolation on review agents |
28
+ | PreToolUse Read\|Bash | `sanitize-on-read.ts` | Sanitize sensitive data in read output |
29
+ | PostToolUse Edit\|Write | `guard-feedback.ts` | Context routing + guard checks (ADR-030) |
30
+ | PostToolUse Edit\|Write | `loop-detection.ts` | Detect edit-undo-edit loops |
31
+ | PostToolUse Edit\|Write | `risk-tracker.ts` | Update risk snapshot on file changes |
32
+ | PreCompact | `precompact.sh` | Preserve critical context before compaction |
33
+ | Stop | `stop-evaluator.ts` | Completion proposal + independent review |
34
+ | SessionEnd | `session-reflection.ts` | Session summary and learnings |
35
+ | SessionEnd | `trace-analyzer.ts` | Aggregate trace data for harness optimization |
36
+ | SessionEnd | `deploy-progress-on-session-end.ts` | Persist deployment progress metrics |
37
+ | PostToolUseFailure | `failure-analyzer.ts` | Diagnose tool call failures |
38
+
39
+ ### Runtime Directories
40
+
41
+ ```
42
+ .boll/
43
+ ├── state/ # Risk snapshots, session state (gitignored)
44
+ ├── guard/ # Guard flags, injection dedup (gitignored)
45
+ └── metrics/ # Observability data — JSONL event logs (gitignored)
46
+ ```
47
+
48
+ These directories are **runtime-only** and gitignored. They are created automatically by hooks.
49
+
50
+ ## AI Behavioral Constraints
51
+
52
+ ### Language
53
+ - All user-facing output in **simplified Chinese**; technical identifiers stay original
54
+ - All commit messages **bilingual** (English title + Chinese summary)
55
+ - Co-Authored-By header: `Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>`
56
+
57
+ ### Code Quality
58
+ - All commands use `npx ts-node`, never bare `python`
59
+ - Subagent model: review/audit/evaluator agents must use `claude-opus-4-6`
60
+ - Review agents: tool whitelist must be schema-level isolated (no Edit/Write/Bash)
61
+
62
+ ### Workflow
63
+ - **Issue-first**: create `docs/issues/guard-*.md` before fixing any guardian finding
64
+ - **Verification honesty**: partial test pass ≠ full pass; closure needs evidence
65
+ - **No half-finished work**: no TODO/FIXME left behind without tracking
66
+
67
+ ## Guardian Issue Workflow
68
+
69
+ Guardian/red-team findings go to `docs/issues/*.md` with YAML frontmatter:
70
+
71
+ ```yaml
72
+ ---
73
+ status: open # open | fixed | wont_fix
74
+ prevention_status: open # open | closed
75
+ mechanism_layer: guard # guard | test | type | convention
76
+ severity: P1 # P0 | P1 | P2 | P3
77
+ component: path/to/affected/file
78
+ ---
79
+ ```
80
+
81
+ Rules:
82
+ - Never fix guardian issues directly on `main` — use a dedicated branch
83
+ - Close only after verification is recorded with evidence
84
+
85
+ ## Path-Scoped Rules
86
+
87
+ Path-scoped rules in `.boll/rules/*.md` auto-load when Claude reads files matching their trigger patterns. No manual loading needed.
88
+
89
+ <!-- TODO: 列出你的 path-scoped rules 及触发路径 -->
@@ -0,0 +1,304 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Bolloon CLI 入口
4
+ *
5
+ * 使用方式:
6
+ * bolloon # 启动 GUI(Electron 或 Web)
7
+ * bolloon --cli # 启动命令行界面
8
+ * bolloon --read <file> # 读取文档
9
+ * bolloon --summarize <file> # 总结文档
10
+ * bolloon --web # 启动 Web UI
11
+ * bolloon --version # 显示版本
12
+ */
13
+
14
+ import { spawn } from 'child_process';
15
+ import * as path from 'path';
16
+ import * as fs from 'fs';
17
+
18
+ const isWindows = process.platform === 'win32';
19
+
20
+ // ANSI 颜色
21
+ const RESET = '\x1b[0m';
22
+ const BOLD = '\x1b[1m';
23
+ const CYAN = '\x1b[36m';
24
+ const YELLOW = '\x1b[33m';
25
+ const GREEN = '\x1b[32m';
26
+ const MAGENTA = '\x1b[35m';
27
+
28
+ // 版本信息
29
+ const VERSION = '0.1.1';
30
+
31
+ function log(msg: string, color: string = RESET) {
32
+ console.log(`${color}${msg}${RESET}`);
33
+ }
34
+
35
+ function printBanner() {
36
+ console.log(`
37
+ ${CYAN}${BOLD}
38
+ ╔═══════════════════════════════════════════╗
39
+ ║ 🤖 Bolloon Agent ${VERSION} ║
40
+ ║ P2P AI Document Processor ║
41
+ ╚═══════════════════════════════════════════╝${RESET}
42
+ `);
43
+ }
44
+
45
+ function printHelp() {
46
+ console.log(`
47
+ ${BOLD}用法:${RESET}
48
+ bolloon [选项] [命令] [参数]
49
+
50
+ ${BOLD}选项:${RESET}
51
+ --gui, -g 启动图形界面 (Electron)
52
+ --web, -w 启动 Web UI (浏览器)
53
+ --cli, -c 启动命令行界面
54
+ --version, -v 显示版本信息
55
+ --help, -h 显示帮助信息
56
+
57
+ ${BOLD}命令:${RESET}
58
+ bolloon --read <file> 读取文档
59
+ bolloon --summarize <file> 总结文档
60
+ bolloon --improve <file> <req> 改进文档
61
+
62
+ ${BOLD}示例:${RESET}
63
+ bolloon # 启动图形界面
64
+ bolloon --web # 启动 Web UI
65
+ bolloon --read 想法.md # 读取文档
66
+ bolloon --cli # 命令行模式
67
+
68
+ ${BOLD}环境变量:${RESET}
69
+ MINIMAX_API_KEY MiniMax API 密钥
70
+ OPENAI_API_KEY OpenAI API 密钥
71
+ ANTHROPIC_API_KEY Anthropic API 密钥
72
+ PORT Web 服务端口 (默认 54188)
73
+ `);
74
+ }
75
+
76
+ function getDistDir(): string {
77
+ // 对于打包后的应用,__dirname 是 dist 目录
78
+ return __dirname;
79
+ }
80
+
81
+ function getMainScript(): string {
82
+ const distDir = getDistDir();
83
+
84
+ // 检查 dist/index.js 是否存在
85
+ const indexPath = path.join(distDir, 'index.js');
86
+ if (fs.existsSync(indexPath)) {
87
+ return indexPath;
88
+ }
89
+
90
+ // 回退到源目录
91
+ const srcPath = path.join(process.cwd(), 'src', 'index.ts');
92
+ if (fs.existsSync(srcPath)) {
93
+ return path.join(process.cwd(), 'src', 'index.ts');
94
+ }
95
+
96
+ throw new Error('找不到入口脚本,请确保已执行 npm run build');
97
+ }
98
+
99
+ function getElectronPath(): string {
100
+ // 获取 electron 可执行文件路径
101
+ const electronPath = require('electron');
102
+ return electronPath;
103
+ }
104
+
105
+ // 解析命令行参数
106
+ function parseArgs(): { mode: string; args: string[] } {
107
+ const args = process.argv.slice(2);
108
+
109
+ if (args.length === 0) {
110
+ return { mode: 'gui', args: [] };
111
+ }
112
+
113
+ const mode = args[0];
114
+
115
+ // 处理简写选项
116
+ switch (mode) {
117
+ case '-v':
118
+ case '--version':
119
+ return { mode: 'version', args: [] };
120
+ case '-h':
121
+ case '--help':
122
+ return { mode: 'help', args: [] };
123
+ case '-g':
124
+ case '--gui':
125
+ return { mode: 'gui', args: args.slice(1) };
126
+ case '-w':
127
+ case '--web':
128
+ return { mode: 'web', args: args.slice(1) };
129
+ case '-c':
130
+ case '--cli':
131
+ return { mode: 'cli', args: args.slice(1) };
132
+ default:
133
+ // 传递所有参数给主程序
134
+ return { mode: 'passthrough', args };
135
+ }
136
+ }
137
+
138
+ // 执行 Node.js 脚本
139
+ async function runNodeScript(scriptPath: string, additionalArgs: string[]) {
140
+ return new Promise<void>((resolve, reject) => {
141
+ const child = spawn(process.execPath, [scriptPath, ...additionalArgs], {
142
+ stdio: 'inherit',
143
+ env: { ...process.env }
144
+ });
145
+
146
+ child.on('error', reject);
147
+ child.on('exit', (code) => {
148
+ if (code === 0) {
149
+ resolve();
150
+ } else {
151
+ reject(new Error(`进程退出,代码: ${code}`));
152
+ }
153
+ });
154
+ });
155
+ }
156
+
157
+ // 启动 Electron
158
+ async function startElectron(additionalArgs: string[]) {
159
+ const electronPath = getElectronPath();
160
+ const distDir = getDistDir();
161
+
162
+ // 确定主进程入口
163
+ let mainPath = path.join(distDir, 'electron.js');
164
+ if (!fs.existsSync(mainPath)) {
165
+ mainPath = path.join(distDir, '..', 'src', 'electron.js');
166
+ }
167
+
168
+ if (!fs.existsSync(mainPath)) {
169
+ // 回退到开发模式
170
+ mainPath = path.join(process.cwd(), 'src', 'electron.ts');
171
+ }
172
+
173
+ log('启动 Electron...', CYAN);
174
+
175
+ const child = spawn(electronPath, [mainPath, ...additionalArgs], {
176
+ stdio: 'inherit',
177
+ env: { ...process.env, NODE_ENV: 'development' }
178
+ });
179
+
180
+ child.on('error', (err) => {
181
+ log(`Electron 启动失败: ${err.message}`, MAGENTA);
182
+ process.exit(1);
183
+ });
184
+
185
+ child.on('exit', (code) => {
186
+ process.exit(code || 0);
187
+ });
188
+ }
189
+
190
+ // 启动 Web 服务
191
+ async function startWebServer(additionalArgs: string[]) {
192
+ log('启动 Web 服务...', CYAN);
193
+
194
+ try {
195
+ const mainPath = getMainScript();
196
+ const webArgs = ['--web', ...additionalArgs];
197
+
198
+ const child = spawn(process.execPath, [mainPath, ...webArgs], {
199
+ stdio: 'inherit',
200
+ env: { ...process.env }
201
+ });
202
+
203
+ child.on('error', (err) => {
204
+ log(`Web 服务启动失败: ${err.message}`, MAGENTA);
205
+ process.exit(1);
206
+ });
207
+
208
+ child.on('exit', (code) => {
209
+ process.exit(code || 0);
210
+ });
211
+ } catch (err: any) {
212
+ log(`启动失败: ${err.message}`, MAGENTA);
213
+ process.exit(1);
214
+ }
215
+ }
216
+
217
+ // 启动 CLI
218
+ async function startCLI(additionalArgs: string[]) {
219
+ log('启动命令行界面...', CYAN);
220
+
221
+ try {
222
+ const mainPath = getMainScript();
223
+ const cliArgs = [...additionalArgs];
224
+
225
+ const child = spawn(process.execPath, [mainPath, ...cliArgs], {
226
+ stdio: 'inherit',
227
+ env: { ...process.env }
228
+ });
229
+
230
+ child.on('error', (err) => {
231
+ log(`CLI 启动失败: ${err.message}`, MAGENTA);
232
+ process.exit(1);
233
+ });
234
+
235
+ child.on('exit', (code) => {
236
+ process.exit(code || 0);
237
+ });
238
+ } catch (err: any) {
239
+ log(`启动失败: ${err.message}`, MAGENTA);
240
+ process.exit(1);
241
+ }
242
+ }
243
+
244
+ // 主入口
245
+ async function main() {
246
+ const { mode, args } = parseArgs();
247
+
248
+ switch (mode) {
249
+ case 'version':
250
+ console.log(`Bolloon Agent v${VERSION}`);
251
+ break;
252
+
253
+ case 'help':
254
+ printHelp();
255
+ break;
256
+
257
+ case 'gui':
258
+ printBanner();
259
+ await startElectron(args);
260
+ break;
261
+
262
+ case 'web':
263
+ printBanner();
264
+ await startWebServer(args);
265
+ break;
266
+
267
+ case 'cli':
268
+ await startCLI(args);
269
+ break;
270
+
271
+ case 'passthrough':
272
+ // 传递所有参数给主程序
273
+ try {
274
+ const mainPath = getMainScript();
275
+ const child = spawn(process.execPath, [mainPath, ...args], {
276
+ stdio: 'inherit',
277
+ env: { ...process.env }
278
+ });
279
+
280
+ child.on('error', (err) => {
281
+ log(`执行失败: ${err.message}`, MAGENTA);
282
+ process.exit(1);
283
+ });
284
+
285
+ child.on('exit', (code) => {
286
+ process.exit(code || 0);
287
+ });
288
+ } catch (err: any) {
289
+ log(`执行失败: ${err.message}`, MAGENTA);
290
+ process.exit(1);
291
+ }
292
+ break;
293
+
294
+ default:
295
+ log(`未知模式: ${mode}`, MAGENTA);
296
+ printHelp();
297
+ process.exit(1);
298
+ }
299
+ }
300
+
301
+ main().catch((err) => {
302
+ console.error('Fatal error:', err);
303
+ process.exit(1);
304
+ });