@bolloon/bolloon-agent 0.1.35 → 0.1.37

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 (502) hide show
  1. package/README.md +1 -1
  2. package/dist/agents/p2p-chat-tools.js +6 -6
  3. package/dist/agents/permission-mode.js +115 -0
  4. package/dist/agents/pi-sdk.js +435 -25
  5. package/dist/agents/pre-tool-validator.js +194 -0
  6. package/dist/agents/workflow-pivot-loop.js +113 -12
  7. package/dist/bollharness-integration/context-router.js +2 -2
  8. package/dist/bollharness-integration/guard-checker.js +1 -1
  9. package/dist/bootstrap/bootstrap.js +3 -0
  10. package/dist/bootstrap/context-collector.js +17 -1
  11. package/dist/bootstrap/context-hierarchy.js +218 -0
  12. package/dist/bootstrap/lifecycle-hooks.js +86 -24
  13. package/dist/bootstrap/project-context.js +10 -3
  14. package/dist/context-compaction/auto-compact.js +144 -0
  15. package/dist/context-compaction/budget-gate.js +28 -0
  16. package/dist/context-compaction/budget-reduce.js +35 -0
  17. package/dist/context-compaction/context-collapse.js +66 -0
  18. package/dist/context-compaction/index.js +21 -0
  19. package/dist/context-compaction/microcompact.js +51 -0
  20. package/dist/context-compaction/pipeline.js +123 -0
  21. package/dist/context-compaction/snip.js +45 -0
  22. package/dist/context-compaction/token-estimator.js +35 -0
  23. package/dist/context-compaction/types.js +19 -0
  24. package/dist/heartbeat/HealthMonitor.js +3 -2
  25. package/dist/index.js +38 -2
  26. package/dist/llm/llm-judgment-client.js +32 -30
  27. package/dist/llm/pi-ai.js +103 -16
  28. package/dist/llm/system-prompt/health.js +129 -0
  29. package/dist/llm/system-prompt/registry.js +246 -0
  30. package/dist/llm/system-prompt/strip-hibsml.js +51 -0
  31. package/dist/llm/tool-manifest/ask_user_input.js +35 -0
  32. package/dist/llm/tool-manifest/bash.js +23 -0
  33. package/dist/llm/tool-manifest/create_file.js +24 -0
  34. package/dist/llm/tool-manifest/fetch_sports_data.js +26 -0
  35. package/dist/llm/tool-manifest/image_search.js +24 -0
  36. package/dist/llm/tool-manifest/index.js +69 -0
  37. package/dist/llm/tool-manifest/mcp.js +43 -0
  38. package/dist/llm/tool-manifest/message_compose.js +31 -0
  39. package/dist/llm/tool-manifest/places.js +83 -0
  40. package/dist/llm/tool-manifest/present_files.js +21 -0
  41. package/dist/llm/tool-manifest/recipe.js +40 -0
  42. package/dist/llm/tool-manifest/recommend_apps.js +23 -0
  43. package/dist/llm/tool-manifest/str_replace.js +27 -0
  44. package/dist/llm/tool-manifest/types.js +7 -0
  45. package/dist/llm/tool-manifest/view.js +24 -0
  46. package/dist/llm/tool-manifest/weather.js +27 -0
  47. package/dist/llm/tool-manifest/web.js +51 -0
  48. package/dist/network/p2p-direct.js +23 -0
  49. package/dist/network/source-intent-broadcaster.js +203 -0
  50. package/dist/network/source-intent.js +100 -0
  51. package/dist/pi-ecosystem-judgment/adaptive-scan.js +48 -0
  52. package/dist/pi-ecosystem-judgment/injection-gate.js +54 -12
  53. package/dist/pi-ecosystem-judgment/value-injection.js +8 -2
  54. package/dist/security/context-router-tool.js +1 -1
  55. package/dist/security/input-scanner.js +223 -0
  56. package/dist/web/client.js +3089 -4458
  57. package/dist/web/index.html +58 -67
  58. package/dist/web/server.js +299 -117
  59. package/dist/web/style.css +531 -249
  60. package/dist/web/ui/message-renderer.js +352 -0
  61. package/dist/web/ui/step-timeline.js +279 -0
  62. package/package.json +2 -2
  63. package/.auto-evolve-calls +0 -1
  64. package/.last-auto-evolve-baseline +0 -1
  65. package/Bolloon.md +0 -103
  66. package/dist/agents/constraint-layer.js.map +0 -1
  67. package/dist/agents/pi-sdk.js.map +0 -1
  68. package/dist/agents/workflow-engine.js.map +0 -1
  69. package/dist/bollharness/src/index.js +0 -5
  70. package/dist/bollharness/src/scripts/checks/check_adr_plan_numbering.js +0 -6
  71. package/dist/bollharness/src/scripts/checks/check_api_types.js +0 -45
  72. package/dist/bollharness/src/scripts/checks/check_artifact_link.js +0 -146
  73. package/dist/bollharness/src/scripts/checks/check_bridge_deps.js +0 -6
  74. package/dist/bollharness/src/scripts/checks/check_bugfix_binding.js +0 -6
  75. package/dist/bollharness/src/scripts/checks/check_bugfix_binding_ci.js +0 -6
  76. package/dist/bollharness/src/scripts/checks/check_doc_file_references.js +0 -6
  77. package/dist/bollharness/src/scripts/checks/check_doc_freshness.js +0 -135
  78. package/dist/bollharness/src/scripts/checks/check_doc_links.js +0 -31
  79. package/dist/bollharness/src/scripts/checks/check_file_existence_claims.js +0 -6
  80. package/dist/bollharness/src/scripts/checks/check_fragment_integrity.js +0 -34
  81. package/dist/bollharness/src/scripts/checks/check_hook_installed.js +0 -63
  82. package/dist/bollharness/src/scripts/checks/check_issue_closure.js +0 -41
  83. package/dist/bollharness/src/scripts/checks/check_mcp_parity.js +0 -6
  84. package/dist/bollharness/src/scripts/checks/check_security.js +0 -48
  85. package/dist/bollharness/src/scripts/checks/check_skill_parity.js +0 -6
  86. package/dist/bollharness/src/scripts/checks/check_versions.js +0 -6
  87. package/dist/bollharness/src/scripts/checks/finding.js +0 -13
  88. package/dist/bollharness/src/scripts/checks/next_decision_number.js +0 -20
  89. package/dist/bollharness/src/scripts/checks/regenerate_magic_docs.js +0 -6
  90. package/dist/bollharness/src/scripts/ci/detect_rebaseline_triggers.js +0 -8
  91. package/dist/bollharness/src/scripts/ci/scan_subprocess_cfg.js +0 -8
  92. package/dist/bollharness/src/scripts/ci/scan_verify_artifacts.js +0 -8
  93. package/dist/bollharness/src/scripts/ci/scan_yaml_schema.js +0 -8
  94. package/dist/bollharness/src/scripts/context_router.js +0 -67
  95. package/dist/bollharness/src/scripts/deploy-guard.js +0 -157
  96. package/dist/bollharness/src/scripts/guard-feedback.js +0 -192
  97. package/dist/bollharness/src/scripts/guard_router.js +0 -158
  98. package/dist/bollharness/src/scripts/hooks/_hook_output.js +0 -6
  99. package/dist/bollharness/src/scripts/hooks/auto-python3.js +0 -6
  100. package/dist/bollharness/src/scripts/hooks/deploy-progress-on-session-end.js +0 -6
  101. package/dist/bollharness/src/scripts/hooks/failure-analyzer.js +0 -6
  102. package/dist/bollharness/src/scripts/hooks/gate-judgment-inject.js +0 -92
  103. package/dist/bollharness/src/scripts/hooks/gate-transition-judgment.js +0 -63
  104. package/dist/bollharness/src/scripts/hooks/inbox-ack.js +0 -6
  105. package/dist/bollharness/src/scripts/hooks/inbox-inject-on-start.js +0 -6
  106. package/dist/bollharness/src/scripts/hooks/inbox-validate.js +0 -6
  107. package/dist/bollharness/src/scripts/hooks/inbox-write-ledger.js +0 -6
  108. package/dist/bollharness/src/scripts/hooks/initializer-agent.js +0 -6
  109. package/dist/bollharness/src/scripts/hooks/loop-detection.js +0 -73
  110. package/dist/bollharness/src/scripts/hooks/owner-guard.js +0 -6
  111. package/dist/bollharness/src/scripts/hooks/precompact.js +0 -6
  112. package/dist/bollharness/src/scripts/hooks/review-agent-gatekeeper.js +0 -6
  113. package/dist/bollharness/src/scripts/hooks/risk-tracker.js +0 -108
  114. package/dist/bollharness/src/scripts/hooks/sanitize-on-read.js +0 -6
  115. package/dist/bollharness/src/scripts/hooks/session-reflection.js +0 -7
  116. package/dist/bollharness/src/scripts/hooks/session-start-magic-docs.js +0 -7
  117. package/dist/bollharness/src/scripts/hooks/session-start-reset-risk.js +0 -7
  118. package/dist/bollharness/src/scripts/hooks/session-start-toolkit-reminder.js +0 -7
  119. package/dist/bollharness/src/scripts/hooks/stop-evaluator.js +0 -157
  120. package/dist/bollharness/src/scripts/hooks/tool-call-counter.js +0 -6
  121. package/dist/bollharness/src/scripts/hooks/trace-analyzer.js +0 -10
  122. package/dist/bollharness/src/scripts/install/install-trust-token.js +0 -7
  123. package/dist/bollharness/src/scripts/install/multi_project_registry.js +0 -9
  124. package/dist/bollharness/src/scripts/install/phase2_auto.js +0 -21
  125. package/dist/bollharness/src/scripts/install/pre_commit_installer.js +0 -6
  126. package/dist/bollharness/src/scripts/install/tier_selector.js +0 -7
  127. package/dist/bollharness/src/scripts/install/transcript_miner.js +0 -7
  128. package/dist/bollharness/src/scripts/lib/claim_patterns.js +0 -10
  129. package/dist/bollharness/src/scripts/lib/sanitize_patterns.js +0 -12
  130. package/dist/bollharness/src/scripts/sanitize.js +0 -6
  131. package/dist/bollharness-integration/context-router-judgment.js.map +0 -1
  132. package/dist/bollharness-integration/context-router.js.map +0 -1
  133. package/dist/bollharness-integration/gate-state-machine.js.map +0 -1
  134. package/dist/bollharness-integration/gate-transition-hooks.js.map +0 -1
  135. package/dist/bollharness-integration/guard-checker.js.map +0 -1
  136. package/dist/bollharness-integration/index.js.map +0 -1
  137. package/dist/bollharness-integration/integration.js.map +0 -1
  138. package/dist/bollharness-integration/llm/pi-ai.d.ts +0 -60
  139. package/dist/bollharness-integration/pi-ecosystem-colony/index.d.ts +0 -153
  140. package/dist/bollharness-integration/pi-ecosystem-goals/index.d.ts +0 -136
  141. package/dist/bollharness-integration/pi-ecosystem-judgment/decision.d.ts +0 -117
  142. package/dist/bollharness-integration/pi-ecosystem-judgment/distillation.d.ts +0 -78
  143. package/dist/bollharness-integration/pi-ecosystem-judgment/index.d.ts +0 -139
  144. package/dist/bollharness-integration/pi-ecosystem-mcp/index.d.ts +0 -127
  145. package/dist/bollharness-integration/pi-ecosystem-subagents/index.d.ts +0 -95
  146. package/dist/bollharness-integration/skill-adapter.js.map +0 -1
  147. package/dist/constraint-runtime/src/_archive_helper.js +0 -9
  148. package/dist/constraint-runtime/src/agent/coordinator.js +0 -48
  149. package/dist/constraint-runtime/src/agent/index.js +0 -1
  150. package/dist/constraint-runtime/src/assistant/index.js +0 -12
  151. package/dist/constraint-runtime/src/bootstrap/index.js +0 -12
  152. package/dist/constraint-runtime/src/bootstrap_graph.js +0 -13
  153. package/dist/constraint-runtime/src/bridge/index.js +0 -12
  154. package/dist/constraint-runtime/src/buddy/index.js +0 -12
  155. package/dist/constraint-runtime/src/cli/index.js +0 -12
  156. package/dist/constraint-runtime/src/command_graph.js +0 -10
  157. package/dist/constraint-runtime/src/commands.js +0 -60
  158. package/dist/constraint-runtime/src/components/index.js +0 -12
  159. package/dist/constraint-runtime/src/constants/index.js +0 -12
  160. package/dist/constraint-runtime/src/constraint/budget.js +0 -22
  161. package/dist/constraint-runtime/src/constraint/budget.js.map +0 -1
  162. package/dist/constraint-runtime/src/constraint/index.js +0 -2
  163. package/dist/constraint-runtime/src/constraint/permission.js +0 -20
  164. package/dist/constraint-runtime/src/constraint/permission.js.map +0 -1
  165. package/dist/constraint-runtime/src/context.js +0 -30
  166. package/dist/constraint-runtime/src/coordinator/index.js +0 -12
  167. package/dist/constraint-runtime/src/cost_hook.js +0 -4
  168. package/dist/constraint-runtime/src/cost_tracker.js +0 -8
  169. package/dist/constraint-runtime/src/deferred_init.js +0 -10
  170. package/dist/constraint-runtime/src/direct_modes.js +0 -6
  171. package/dist/constraint-runtime/src/dynamic-tool-loader.js +0 -85
  172. package/dist/constraint-runtime/src/entrypoints/index.js +0 -12
  173. package/dist/constraint-runtime/src/execution_registry.js +0 -44
  174. package/dist/constraint-runtime/src/history.js +0 -9
  175. package/dist/constraint-runtime/src/hooks/index.js +0 -12
  176. package/dist/constraint-runtime/src/index.js +0 -26
  177. package/dist/constraint-runtime/src/ink.js +0 -4
  178. package/dist/constraint-runtime/src/keybindings/index.js +0 -12
  179. package/dist/constraint-runtime/src/memdir/index.js +0 -12
  180. package/dist/constraint-runtime/src/migrations/index.js +0 -12
  181. package/dist/constraint-runtime/src/models.js +0 -1
  182. package/dist/constraint-runtime/src/models.js.map +0 -1
  183. package/dist/constraint-runtime/src/moreright/index.js +0 -12
  184. package/dist/constraint-runtime/src/native_ts/index.js +0 -12
  185. package/dist/constraint-runtime/src/output_styles/index.js +0 -12
  186. package/dist/constraint-runtime/src/parity_audit.js +0 -12
  187. package/dist/constraint-runtime/src/plugins/index.js +0 -12
  188. package/dist/constraint-runtime/src/port_manifest.js +0 -11
  189. package/dist/constraint-runtime/src/prefetch.js +0 -9
  190. package/dist/constraint-runtime/src/query.js +0 -1
  191. package/dist/constraint-runtime/src/remote/index.js +0 -12
  192. package/dist/constraint-runtime/src/remote_runtime.js +0 -9
  193. package/dist/constraint-runtime/src/runtime/index.js +0 -1
  194. package/dist/constraint-runtime/src/runtime/session.js +0 -35
  195. package/dist/constraint-runtime/src/schemas/index.js +0 -12
  196. package/dist/constraint-runtime/src/screens/index.js +0 -12
  197. package/dist/constraint-runtime/src/server/index.js +0 -12
  198. package/dist/constraint-runtime/src/services/index.js +0 -12
  199. package/dist/constraint-runtime/src/session_store.js +0 -22
  200. package/dist/constraint-runtime/src/setup.js +0 -30
  201. package/dist/constraint-runtime/src/skills/index.js +0 -1
  202. package/dist/constraint-runtime/src/skills/skill-registry.js +0 -28
  203. package/dist/constraint-runtime/src/state/index.js +0 -12
  204. package/dist/constraint-runtime/src/system_init.js +0 -20
  205. package/dist/constraint-runtime/src/thinking/engine.js +0 -42
  206. package/dist/constraint-runtime/src/thinking/index.js +0 -1
  207. package/dist/constraint-runtime/src/tool_pool.js +0 -8
  208. package/dist/constraint-runtime/src/tools/OpenCLI/execAdapter.js +0 -7
  209. package/dist/constraint-runtime/src/tools/OpenCLI/listAdapters.js +0 -7
  210. package/dist/constraint-runtime/src/tools/OpenCLI/runCommand.js +0 -7
  211. package/dist/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.js +0 -6
  212. package/dist/constraint-runtime/src/tools/PolymarketSDK/createOrder.js +0 -6
  213. package/dist/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +0 -5
  214. package/dist/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +0 -6
  215. package/dist/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +0 -4
  216. package/dist/constraint-runtime/src/tools/SafeSDK/confirmTransaction.js +0 -6
  217. package/dist/constraint-runtime/src/tools/SafeSDK/createTransaction.js +0 -8
  218. package/dist/constraint-runtime/src/tools/SafeSDK/deploySafe.js +0 -6
  219. package/dist/constraint-runtime/src/tools/SafeSDK/executeTransaction.js +0 -6
  220. package/dist/constraint-runtime/src/tools/SafeSDK/getBalance.js +0 -6
  221. package/dist/constraint-runtime/src/tools/SafeSDK/getPendingTransactions.js +0 -6
  222. package/dist/constraint-runtime/src/tools/SafeSDK/proposeTransaction.js +0 -6
  223. package/dist/constraint-runtime/src/tools/WalletTools/autoPay.js +0 -29
  224. package/dist/constraint-runtime/src/tools/WalletTools/createWallet.js +0 -10
  225. package/dist/constraint-runtime/src/tools/WalletTools/getBalance.js +0 -13
  226. package/dist/constraint-runtime/src/tools/WalletTools/importWallet.js +0 -22
  227. package/dist/constraint-runtime/src/tools/WalletTools/sendTransaction.js +0 -25
  228. package/dist/constraint-runtime/src/tools/WalletTools/signMessage.js +0 -10
  229. package/dist/constraint-runtime/src/tools/WalletTools/transferToken.js +0 -25
  230. package/dist/constraint-runtime/src/tools.js +0 -80
  231. package/dist/constraint-runtime/src/transcript.js +0 -19
  232. package/dist/constraint-runtime/src/types/index.js +0 -12
  233. package/dist/constraint-runtime/src/upstream_proxy/index.js +0 -12
  234. package/dist/constraint-runtime/src/utils/index.js +0 -12
  235. package/dist/constraint-runtime/src/vim/index.js +0 -12
  236. package/dist/constraint-runtime/src/voice/index.js +0 -12
  237. package/dist/constraints/index.js.map +0 -1
  238. package/dist/documents/reader.js.map +0 -1
  239. package/dist/llm/config-store.js.map +0 -1
  240. package/dist/llm/pi-ai.js.map +0 -1
  241. package/dist/network/agent-network.js.map +0 -1
  242. package/dist/network/iroh-integration.js.map +0 -1
  243. package/dist/network/iroh-transport.js.map +0 -1
  244. package/dist/network/p2p.js.map +0 -1
  245. package/dist/network/storage/adapters/json-adapter.js.map +0 -1
  246. package/dist/pi-ecosystem-colony/index.js.map +0 -1
  247. package/dist/pi-ecosystem-goals/index.js.map +0 -1
  248. package/dist/pi-ecosystem-judgment/decision.js.map +0 -1
  249. package/dist/pi-ecosystem-judgment/distillation.js.map +0 -1
  250. package/dist/pi-ecosystem-judgment/human-value-store.js.map +0 -1
  251. package/dist/pi-ecosystem-judgment/index.js.map +0 -1
  252. package/dist/pi-ecosystem-judgment/value-injection.js.map +0 -1
  253. package/dist/pi-ecosystem-mcp/index.js.map +0 -1
  254. package/dist/pi-ecosystem-subagents/index.js.map +0 -1
  255. package/dist/social/ant-colony/AdaptiveHeartbeat.js.map +0 -1
  256. package/dist/social/ant-colony/PheromoneEngine.js.map +0 -1
  257. package/dist/social/ant-colony/types.js.map +0 -1
  258. package/dist/social/channels/ChannelManager.js.map +0 -1
  259. package/dist/social/channels/DiapChannelBridge.js.map +0 -1
  260. package/dist/social/channels/InterestMatcher.js.map +0 -1
  261. package/dist/social/channels/types.js.map +0 -1
  262. package/dist/social/global-shared-context.js.map +0 -1
  263. package/dist/social/heartbeat.js.map +0 -1
  264. package/lefthook.yml +0 -29
  265. package/scripts/auto-evolve-loop.ts +0 -376
  266. package/scripts/auto-evolve-oneshot.sh +0 -155
  267. package/scripts/auto-evolve-snapshot.sh +0 -136
  268. package/scripts/build-cli.js +0 -216
  269. package/scripts/build-web.ts +0 -82
  270. package/scripts/detect-schema-changes.sh +0 -48
  271. package/scripts/diff-reviewer.ts +0 -159
  272. package/scripts/postinstall.js +0 -153
  273. package/scripts/weekly-report.ts +0 -364
  274. package/src/agents/agent-manifest-protocol.ts +0 -117
  275. package/src/agents/constraint-layer.ts +0 -309
  276. package/src/agents/iroh-secret.ts +0 -32
  277. package/src/agents/p2p-chat-tools.ts +0 -383
  278. package/src/agents/p2p-document-tools.ts +0 -347
  279. package/src/agents/pi-sdk.ts +0 -2462
  280. package/src/agents/protocol.ts +0 -398
  281. package/src/agents/shell-guard.ts +0 -417
  282. package/src/agents/shell-tool.ts +0 -103
  283. package/src/agents/skill-loader.ts +0 -202
  284. package/src/agents/subagent-manager.ts +0 -553
  285. package/src/agents/workflow-engine.ts +0 -332
  286. package/src/agents/workflow-pivot-loop.ts +0 -675
  287. package/src/bollharness/.sanitize-report.json +0 -13
  288. package/src/bollharness/CLAUDE.md +0 -73
  289. package/src/bollharness/LICENSE +0 -21
  290. package/src/bollharness/README.md +0 -143
  291. package/src/bollharness/README.zh-CN.md +0 -131
  292. package/src/bollharness/package.json +0 -20
  293. package/src/bollharness/reference/SOURCE-COMMIT.txt +0 -3
  294. package/src/bollharness/reference/boll-reference/scripts/hooks/.sanitize-report.json +0 -12
  295. package/src/bollharness/reference/boll-reference/scripts/hooks/find-boll-root.sh +0 -27
  296. package/src/bollharness/reference/boll-reference/scripts/hooks/precompact.sh +0 -57
  297. package/src/bollharness/reference/boll-reference/scripts/hooks/stop-evaluator.md +0 -57
  298. package/src/bollharness/schemas/metrics-jsonl-allowlist.json +0 -67
  299. package/src/bollharness/scripts/checks/next_decision_number.sh +0 -48
  300. package/src/bollharness/scripts/ci/count-components.sh +0 -65
  301. package/src/bollharness/scripts/context-fragments/artifact-linkage.md +0 -14
  302. package/src/bollharness/scripts/context-fragments/auth-consumers.md +0 -17
  303. package/src/bollharness/scripts/context-fragments/bridge-constitution.md +0 -13
  304. package/src/bollharness/scripts/context-fragments/catalyst-distributed.md +0 -18
  305. package/src/bollharness/scripts/context-fragments/closure-checklist.md +0 -13
  306. package/src/bollharness/scripts/context-fragments/contract-consumers.md +0 -15
  307. package/src/bollharness/scripts/context-fragments/db-shared-structures.md +0 -15
  308. package/src/bollharness/scripts/context-fragments/fixed-three-layers.md +0 -19
  309. package/src/bollharness/scripts/context-fragments/general-dev-principles.md +0 -11
  310. package/src/bollharness/scripts/context-fragments/issue-first.md +0 -8
  311. package/src/bollharness/scripts/context-fragments/mcp-parity.md +0 -16
  312. package/src/bollharness/scripts/context-fragments/pi-agent-operations.md +0 -108
  313. package/src/bollharness/scripts/context-fragments/protocol-consumers.md +0 -15
  314. package/src/bollharness/scripts/context-fragments/run-events-consumers.md +0 -15
  315. package/src/bollharness/scripts/context-fragments/scene-fidelity.md +0 -13
  316. package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +0 -15
  317. package/src/bollharness/scripts/context-fragments/two-language.md +0 -15
  318. package/src/bollharness/scripts/context-fragments/version-sources.md +0 -14
  319. package/src/bollharness/scripts/hooks/find-project-root.sh +0 -47
  320. package/src/bollharness/scripts/hooks/inbox-poll.sh +0 -78
  321. package/src/bollharness/scripts/hooks/precompact.sh +0 -56
  322. package/src/bollharness/scripts/hooks/stop-evaluator.md +0 -83
  323. package/src/bollharness/scripts/sync-from-upstream.sh +0 -281
  324. package/src/bollharness/src/index.ts +0 -5
  325. package/src/bollharness/src/scripts/checks/check_adr_plan_numbering.ts +0 -11
  326. package/src/bollharness/src/scripts/checks/check_api_types.ts +0 -52
  327. package/src/bollharness/src/scripts/checks/check_artifact_link.ts +0 -156
  328. package/src/bollharness/src/scripts/checks/check_bridge_deps.ts +0 -11
  329. package/src/bollharness/src/scripts/checks/check_bugfix_binding.ts +0 -11
  330. package/src/bollharness/src/scripts/checks/check_bugfix_binding_ci.ts +0 -11
  331. package/src/bollharness/src/scripts/checks/check_doc_file_references.ts +0 -11
  332. package/src/bollharness/src/scripts/checks/check_doc_freshness.ts +0 -141
  333. package/src/bollharness/src/scripts/checks/check_doc_links.ts +0 -36
  334. package/src/bollharness/src/scripts/checks/check_file_existence_claims.ts +0 -11
  335. package/src/bollharness/src/scripts/checks/check_fragment_integrity.ts +0 -40
  336. package/src/bollharness/src/scripts/checks/check_hook_installed.ts +0 -70
  337. package/src/bollharness/src/scripts/checks/check_issue_closure.ts +0 -51
  338. package/src/bollharness/src/scripts/checks/check_mcp_parity.ts +0 -11
  339. package/src/bollharness/src/scripts/checks/check_security.ts +0 -54
  340. package/src/bollharness/src/scripts/checks/check_skill_parity.ts +0 -11
  341. package/src/bollharness/src/scripts/checks/check_versions.ts +0 -11
  342. package/src/bollharness/src/scripts/checks/finding.ts +0 -35
  343. package/src/bollharness/src/scripts/checks/next_decision_number.ts +0 -24
  344. package/src/bollharness/src/scripts/checks/regenerate_magic_docs.ts +0 -11
  345. package/src/bollharness/src/scripts/ci/detect_rebaseline_triggers.ts +0 -14
  346. package/src/bollharness/src/scripts/ci/scan_subprocess_cfg.ts +0 -14
  347. package/src/bollharness/src/scripts/ci/scan_verify_artifacts.ts +0 -14
  348. package/src/bollharness/src/scripts/ci/scan_yaml_schema.ts +0 -14
  349. package/src/bollharness/src/scripts/context_router.ts +0 -76
  350. package/src/bollharness/src/scripts/deploy-guard.ts +0 -182
  351. package/src/bollharness/src/scripts/guard-feedback.ts +0 -215
  352. package/src/bollharness/src/scripts/guard_router.ts +0 -194
  353. package/src/bollharness/src/scripts/hooks/_hook_output.js +0 -3
  354. package/src/bollharness/src/scripts/hooks/_hook_output.ts +0 -11
  355. package/src/bollharness/src/scripts/hooks/auto-python3.ts +0 -10
  356. package/src/bollharness/src/scripts/hooks/deploy-progress-on-session-end.ts +0 -10
  357. package/src/bollharness/src/scripts/hooks/failure-analyzer.ts +0 -10
  358. package/src/bollharness/src/scripts/hooks/gate-judgment-inject.ts +0 -111
  359. package/src/bollharness/src/scripts/hooks/gate-transition-judgment.ts +0 -74
  360. package/src/bollharness/src/scripts/hooks/inbox-ack.ts +0 -10
  361. package/src/bollharness/src/scripts/hooks/inbox-inject-on-start.ts +0 -10
  362. package/src/bollharness/src/scripts/hooks/inbox-validate.ts +0 -10
  363. package/src/bollharness/src/scripts/hooks/inbox-write-ledger.ts +0 -10
  364. package/src/bollharness/src/scripts/hooks/initializer-agent.ts +0 -10
  365. package/src/bollharness/src/scripts/hooks/loop-detection.ts +0 -83
  366. package/src/bollharness/src/scripts/hooks/owner-guard.ts +0 -10
  367. package/src/bollharness/src/scripts/hooks/precompact.ts +0 -10
  368. package/src/bollharness/src/scripts/hooks/review-agent-gatekeeper.ts +0 -10
  369. package/src/bollharness/src/scripts/hooks/risk-tracker.ts +0 -121
  370. package/src/bollharness/src/scripts/hooks/sanitize-on-read.ts +0 -10
  371. package/src/bollharness/src/scripts/hooks/session-reflection.ts +0 -12
  372. package/src/bollharness/src/scripts/hooks/session-start-magic-docs.ts +0 -12
  373. package/src/bollharness/src/scripts/hooks/session-start-reset-risk.ts +0 -12
  374. package/src/bollharness/src/scripts/hooks/session-start-toolkit-reminder.ts +0 -12
  375. package/src/bollharness/src/scripts/hooks/stop-evaluator.ts +0 -164
  376. package/src/bollharness/src/scripts/hooks/tool-call-counter.ts +0 -10
  377. package/src/bollharness/src/scripts/hooks/trace-analyzer.ts +0 -14
  378. package/src/bollharness/src/scripts/install/install-trust-token.ts +0 -13
  379. package/src/bollharness/src/scripts/install/multi_project_registry.ts +0 -13
  380. package/src/bollharness/src/scripts/install/phase2_auto.ts +0 -28
  381. package/src/bollharness/src/scripts/install/pre_commit_installer.ts +0 -10
  382. package/src/bollharness/src/scripts/install/tier_selector.ts +0 -10
  383. package/src/bollharness/src/scripts/install/transcript_miner.ts +0 -13
  384. package/src/bollharness/src/scripts/lib/claim_patterns.ts +0 -11
  385. package/src/bollharness/src/scripts/lib/sanitize_patterns.ts +0 -13
  386. package/src/bollharness/src/scripts/sanitize.ts +0 -9
  387. package/src/bollharness/templates/persona/default.json +0 -19
  388. package/src/bollharness/templates/scaffold/.gitignore.append +0 -16
  389. package/src/bollharness/templates/scaffold/CLAUDE.md +0 -89
  390. package/src/bollharness-integration/channel-judgment-engine.ts +0 -634
  391. package/src/bollharness-integration/context-chain-router.ts +0 -474
  392. package/src/bollharness-integration/context-router-judgment.ts +0 -339
  393. package/src/bollharness-integration/context-router.ts +0 -583
  394. package/src/bollharness-integration/gate-state-machine.ts +0 -444
  395. package/src/bollharness-integration/gate-transition-hooks.ts +0 -137
  396. package/src/bollharness-integration/guard-checker.ts +0 -451
  397. package/src/bollharness-integration/index.ts +0 -195
  398. package/src/bollharness-integration/integration.ts +0 -538
  399. package/src/bollharness-integration/judgment-prompts.yaml +0 -535
  400. package/src/bollharness-integration/llm-judgment-engine.ts +0 -712
  401. package/src/bollharness-integration/skill-adapter.ts +0 -646
  402. package/src/bootstrap/bootstrap.ts +0 -132
  403. package/src/bootstrap/context-collector.ts +0 -342
  404. package/src/bootstrap/lifecycle-hooks.ts +0 -176
  405. package/src/bootstrap/project-context.ts +0 -163
  406. package/src/cli/interface.ts +0 -211
  407. package/src/cli-entry.ts +0 -304
  408. package/src/constraints/index.ts +0 -6
  409. package/src/documents/reader.ts +0 -85
  410. package/src/documents/store.ts +0 -252
  411. package/src/electron-preload.ts +0 -25
  412. package/src/electron.ts +0 -200
  413. package/src/heartbeat/DaemonManager.ts +0 -283
  414. package/src/heartbeat/HealthMonitor.ts +0 -316
  415. package/src/heartbeat/StartupVerifier.ts +0 -223
  416. package/src/heartbeat/Watchdog.ts +0 -208
  417. package/src/heartbeat/index.ts +0 -109
  418. package/src/heartbeat/self-improve-bus.ts +0 -110
  419. package/src/heartbeat/types.ts +0 -82
  420. package/src/index.ts +0 -1690
  421. package/src/llm/audio-config-store.ts +0 -246
  422. package/src/llm/config-store.ts +0 -400
  423. package/src/llm/llm-judgment-client.ts +0 -470
  424. package/src/llm/pi-ai.ts +0 -558
  425. package/src/llm/video-config-store.ts +0 -257
  426. package/src/network/agent-network.ts +0 -800
  427. package/src/network/hybrid-messenger.ts +0 -199
  428. package/src/network/iroh-bootstrap.ts +0 -57
  429. package/src/network/iroh-discovery.ts +0 -208
  430. package/src/network/iroh-integration.ts +0 -158
  431. package/src/network/iroh-transport.ts +0 -637
  432. package/src/network/known-peers.ts +0 -102
  433. package/src/network/p2p-direct.ts +0 -240
  434. package/src/network/p2p-secret.ts +0 -153
  435. package/src/network/p2p.ts +0 -964
  436. package/src/network/storage/adapters/json-adapter.ts +0 -454
  437. package/src/network/storage/index.ts +0 -203
  438. package/src/network/storage/types.ts +0 -166
  439. package/src/security/builtin-guards.ts +0 -162
  440. package/src/security/context-router-tool.ts +0 -122
  441. package/src/security/react-harness.ts +0 -177
  442. package/src/security/tool-gate.ts +0 -294
  443. package/src/social/ant-colony/index.js +0 -19
  444. package/src/social/channels/ChannelManager.ts +0 -485
  445. package/src/social/channels/DiapChannelBridge.ts +0 -501
  446. package/src/social/channels/InterestMatcher.ts +0 -189
  447. package/src/social/channels/agent-workflow-config.json +0 -214
  448. package/src/social/channels/agent-workflow-config.yaml +0 -334
  449. package/src/social/channels/channel-agent-session.ts +0 -407
  450. package/src/social/channels/channel-heartbeat-agent.ts +0 -622
  451. package/src/social/channels/diap-doc-parser.ts +0 -282
  452. package/src/social/channels/harness-workflow-integrator.ts +0 -594
  453. package/src/social/channels/index.ts +0 -22
  454. package/src/social/channels/types.ts +0 -115
  455. package/src/social/global-shared-context.ts +0 -506
  456. package/src/social/heartbeat.ts +0 -1057
  457. package/src/social/persona/enhanced-persona.ts +0 -359
  458. package/src/types.d.ts +0 -12
  459. package/src/utils/auto-evolve-policy.ts +0 -138
  460. package/src/utils/auto-update.ts +0 -482
  461. package/src/utils/clamp.ts +0 -5
  462. package/src/web/agent-delegate-server.ts +0 -148
  463. package/src/web/api-config.html +0 -520
  464. package/src/web/client.js +0 -4898
  465. package/src/web/components/p2p/P2PModal.tsx +0 -416
  466. package/src/web/components/p2p/index.ts +0 -566
  467. package/src/web/components/p2p/index.tsx +0 -297
  468. package/src/web/components/p2p/p2p-connection.ts +0 -338
  469. package/src/web/components/p2p/p2p-identity.ts +0 -92
  470. package/src/web/components/p2p/p2p-manager.ts +0 -147
  471. package/src/web/components/p2p/p2p-messages.ts +0 -219
  472. package/src/web/components/p2p/p2p-modal.ts +0 -685
  473. package/src/web/components/p2p/p2p-store-memory.ts +0 -162
  474. package/src/web/components/p2p/p2p-tools.ts +0 -315
  475. package/src/web/components/p2p/types.ts +0 -170
  476. package/src/web/components/wallet-viem.mjs +0 -118
  477. package/src/web/design.md +0 -99
  478. package/src/web/icons/apple-touch-icon.png +0 -0
  479. package/src/web/icons/favicon-16x16.png +0 -0
  480. package/src/web/icons/favicon-192x192.png +0 -0
  481. package/src/web/icons/favicon-32x32.png +0 -0
  482. package/src/web/icons/favicon-48x48.png +0 -0
  483. package/src/web/icons/favicon-512x512.png +0 -0
  484. package/src/web/icons/favicon.icns +0 -0
  485. package/src/web/icons/favicon.ico +0 -0
  486. package/src/web/icons/icon.png +0 -0
  487. package/src/web/icons/image.png +0 -0
  488. package/src/web/index.html +0 -382
  489. package/src/web/iroh-delegate-transport.ts +0 -139
  490. package/src/web/manifest.json +0 -21
  491. package/src/web/server.ts +0 -5571
  492. package/src/web/style.css +0 -4455
  493. package/staging/auto-evolve/clean-001/.review-verdict +0 -9
  494. package/staging/auto-evolve/clean-001/clean-001.patch +0 -14
  495. package/staging/auto-evolve/e2e-001/.patch-id +0 -1
  496. package/staging/auto-evolve/e2e-001/.review-verdict +0 -12
  497. package/staging/auto-evolve/e2e-001/e2e-001.patch +0 -11
  498. package/staging/auto-evolve/test-bad/.review-verdict +0 -12
  499. package/staging/auto-evolve/test-bad/test-bad.patch +0 -11
  500. package/tsconfig.cli.json +0 -16
  501. package/tsconfig.electron.json +0 -20
  502. package/tsconfig.json +0 -18
@@ -0,0 +1,246 @@
1
+ /**
2
+ * registry.ts — system prompt 层注册 + 装配器
3
+ *
4
+ * 设计原则:
5
+ * - 每个 layer 独立文件, 可单独更新/审查/回滚
6
+ * - 装配器按 channel + role + tool 过滤, 输出最终 system prompt
7
+ * - 字符预算按"层级"硬限, 避免腐烂
8
+ * - 远程 P2P layer (function source) 可被远程智能体覆盖本地 layer
9
+ *
10
+ * 装配顺序 (低 priority 先, 高 priority 后):
11
+ * core/identity < core/knowledge < core/tools < channel/* < role/* < tool/* < dynamic/*
12
+ */
13
+ import * as fs from 'fs/promises';
14
+ import * as path from 'path';
15
+ import { fileURLToPath } from 'url';
16
+ import { stripHibsml } from './strip-hibsml.js';
17
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
+ const LAYERS_DIR = path.join(__dirname, 'layers');
19
+ /** 解析 .md frontmatter (手写 3 行 regex, 不引 yaml 依赖) */
20
+ function parseFrontmatter(raw) {
21
+ const m = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
22
+ if (!m)
23
+ return { meta: null, body: raw };
24
+ const block = m[1];
25
+ const body = m[2];
26
+ const get = (key) => {
27
+ const re = new RegExp(`^${key}:\\s*(.+)$`, 'm');
28
+ const found = block.match(re);
29
+ return found ? found[1].trim() : undefined;
30
+ };
31
+ const addedAt = get('added_at');
32
+ const lastReviewedAt = get('last_reviewed_at');
33
+ const ttlDaysStr = get('ttl_days');
34
+ const author = get('author');
35
+ const notes = get('notes');
36
+ if (!addedAt || !lastReviewedAt || !ttlDaysStr || !author) {
37
+ // frontmatter 不完整 → 视为无 metadata (health 会标 missing-frontmatter)
38
+ return { meta: null, body: raw };
39
+ }
40
+ const ttlDays = parseInt(ttlDaysStr, 10);
41
+ if (isNaN(ttlDays) || ttlDays <= 0) {
42
+ return { meta: null, body: raw };
43
+ }
44
+ return {
45
+ meta: { addedAt, lastReviewedAt, ttlDays, author, notes },
46
+ body,
47
+ };
48
+ }
49
+ /**
50
+ * 静态 layer 注册表 — 一个 layer 一个文件
51
+ * 这里只声明 metadata, 内容从 .md 读
52
+ *
53
+ * P-Action 2: meta 默认值, 跟分层 TTL 决策一致
54
+ * safety (refusal / hibs_reminders / tools.thin) = 90
55
+ * channel (local / p2p-* persona) = 180
56
+ * role (expert / architect / implementer / security) = 180
57
+ * tool (bash / search / artifacts / etc) = 270
58
+ * knowledge (knowledge / tone / wellbeing / etc) = 365
59
+ * author = yuanjie (可被 .md frontmatter 覆盖)
60
+ */
61
+ const DEFAULT_META_AUTHOR = 'yuanjie';
62
+ const DEFAULT_ADDED_AT = '2026-06-15';
63
+ const DEFAULT_REVIEWED_AT = '2026-06-15';
64
+ const TTL_SAFETY = 90;
65
+ const TTL_CHANNEL = 180;
66
+ const TTL_ROLE = 180;
67
+ const TTL_TOOL = 270;
68
+ const TTL_KNOWLEDGE = 365;
69
+ const DEFAULT_META = (ttlDays) => ({
70
+ addedAt: DEFAULT_ADDED_AT,
71
+ lastReviewedAt: DEFAULT_REVIEWED_AT,
72
+ ttlDays,
73
+ author: DEFAULT_META_AUTHOR,
74
+ });
75
+ /**
76
+ * P-Action 4 (2026-06-15): 单 layer maxChars 全面收紧, 6 个 layer 停用.
77
+ * 阶段 0 不再对齐 Claude.ai 完整版 (hibs_api / artifacts / mcp_apps / image_search /
78
+ * hibs_reminders / network_filesystem 全是 Claude.ai 平台 runtime, 本地 bolloon 用不到).
79
+ * 停用方法: appliesTo 加 'never' (matchesContext 永远 false), 文件保留可回滚.
80
+ */
81
+ const STATIC_LAYERS = [
82
+ // ── core/ ──
83
+ { id: 'core.identity', version: '1.0.0', priority: 50, appliesTo: ['all'], source: 'static-md', maxChars: 800, meta: DEFAULT_META(TTL_KNOWLEDGE) },
84
+ { id: 'core.knowledge', version: '1.0.0', priority: 60, appliesTo: ['all'], source: 'static-md', maxChars: 600, meta: DEFAULT_META(TTL_KNOWLEDGE) },
85
+ { id: 'core.tools.thin', version: '1.0.0', priority: 70, appliesTo: ['all'], source: 'static-md', maxChars: 400, meta: DEFAULT_META(TTL_SAFETY) },
86
+ { id: 'core.hibs_reminders', version: '1.0.0', priority: 80, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_SAFETY) },
87
+ { id: 'core.refusal', version: '1.0.0', priority: 100, appliesTo: ['all'], source: 'static-md', maxChars: 800, meta: DEFAULT_META(TTL_SAFETY) },
88
+ { id: 'core.tone', version: '1.0.0', priority: 110, appliesTo: ['all'], source: 'static-md', maxChars: 500, meta: DEFAULT_META(TTL_KNOWLEDGE) },
89
+ { id: 'core.wellbeing', version: '1.0.0', priority: 120, appliesTo: ['all'], source: 'static-md', maxChars: 600, meta: DEFAULT_META(TTL_KNOWLEDGE) },
90
+ { id: 'core.evenhandedness', version: '1.0.0', priority: 130, appliesTo: ['all'], source: 'static-md', maxChars: 300, meta: DEFAULT_META(TTL_KNOWLEDGE) },
91
+ { id: 'core.memory_system', version: '1.0.0', priority: 140, appliesTo: ['all'], source: 'static-md', maxChars: 200, meta: DEFAULT_META(TTL_KNOWLEDGE) },
92
+ { id: 'core.artifacts_storage', version: '1.0.0', priority: 145, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_KNOWLEDGE) },
93
+ { id: 'core.network_filesystem', version: '1.0.0', priority: 148, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_KNOWLEDGE) },
94
+ // ── role/ ── 阶段 0 只用 expert, 其他 3 个停用 (节省 + 阶段 0 不分 role)
95
+ { id: 'role.expert', version: '1.0.0', priority: 200, appliesTo: ['all', 'role:expert'], source: 'static-md', maxChars: 500, meta: DEFAULT_META(TTL_ROLE) },
96
+ { id: 'role.architect', version: '1.0.0', priority: 200, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_ROLE) },
97
+ { id: 'role.implementer', version: '1.0.0', priority: 200, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_ROLE) },
98
+ { id: 'role.security', version: '1.0.0', priority: 200, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_ROLE) },
99
+ // ── channel/ ──
100
+ { id: 'channel.local', version: '1.0.0', priority: 150, appliesTo: ['local'], source: 'static-md', maxChars: 500, meta: DEFAULT_META(TTL_CHANNEL) },
101
+ { id: 'channel.p2p-visitor', version: '1.0.0', priority: 150, appliesTo: ['p2p-visitor'], source: 'static-md', maxChars: 700 },
102
+ { id: 'channel.p2p-agent', version: '1.0.0', priority: 150, appliesTo: ['p2p-agent'], source: 'static-md', maxChars: 700 },
103
+ // ── tool/ (按工具调用嵌对应 layer) ──
104
+ { id: 'tool.bash', version: '1.0.0', priority: 250, appliesTo: ['tool:bash'], source: 'static-md', maxChars: 600, meta: DEFAULT_META(TTL_TOOL) },
105
+ { id: 'tool.web_search', version: '1.0.0', priority: 250, appliesTo: ['tool:web_search'], source: 'static-md', maxChars: 600, meta: DEFAULT_META(TTL_TOOL) },
106
+ { id: 'tool.mcp_apps', version: '1.0.0', priority: 250, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_TOOL) },
107
+ { id: 'tool.hibs_api', version: '1.0.0', priority: 250, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_TOOL) },
108
+ { id: 'tool.image_search', version: '1.0.0', priority: 250, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_TOOL) },
109
+ { id: 'tool.artifacts', version: '1.0.0', priority: 250, appliesTo: ['never'], source: 'static-md', maxChars: 0, meta: DEFAULT_META(TTL_TOOL) },
110
+ { id: 'tool.manifest', version: '1.0.0', priority: 250, appliesTo: ['tool:manifest'], source: 'static-md', maxChars: 500, meta: DEFAULT_META(TTL_TOOL) },
111
+ ];
112
+ /**
113
+ * 动态 layer (运行时计算, 例如 project context, judgment 注入)
114
+ * 接入现有 project-context.ts + value-injection.ts, 不重复实现
115
+ */
116
+ const DYNAMIC_LAYERS = [
117
+ {
118
+ id: 'dynamic.project-context',
119
+ version: '1.0.0',
120
+ priority: 300,
121
+ appliesTo: ['all'],
122
+ source: 'function',
123
+ maxChars: 2000, // 4000 → 2000 (P-Action 4), 跟 4 级层次合并上限对齐
124
+ resolver: async () => {
125
+ try {
126
+ const { getCachedBolloonContext } = await import('../../pi-ecosystem-judgment/human-value-pipeline.js');
127
+ const { formatContextForSystemPrompt } = await import('../../bootstrap/project-context.js');
128
+ const ctx = await getCachedBolloonContext({ cwd: process.cwd() });
129
+ return formatContextForSystemPrompt(ctx, { maxChars: 4000 });
130
+ }
131
+ catch {
132
+ return '';
133
+ }
134
+ },
135
+ },
136
+ ];
137
+ /**
138
+ * P-Action 4 (2026-06-15): 总字符上限 15000 → 4500.
139
+ * 阶段 0 单次 system prompt 控制在 ≤ 4.5KB (≈ 1125 tokens).
140
+ * 配合单 layer maxChars 收紧 + 6 layer 停用, 每轮 chat 节省 ≈ 2625 tokens.
141
+ */
142
+ const TOTAL_BUDGET = 4500;
143
+ export async function assembleSystemPrompt(ctx) {
144
+ // 1. 收集所有 layer
145
+ const allLayers = [];
146
+ for (const meta of STATIC_LAYERS) {
147
+ const { content, meta: sectionMeta } = await loadStaticLayer(meta.id);
148
+ allLayers.push({ ...meta, content, meta: sectionMeta ?? meta.meta });
149
+ }
150
+ for (const dyn of DYNAMIC_LAYERS) {
151
+ allLayers.push({ ...dyn, meta: dyn.meta });
152
+ }
153
+ // 2. 过滤
154
+ const matched = allLayers.filter((l) => matchesContext(l, ctx));
155
+ // 3. 排序 (priority 低 → 高, 同 priority 按 id 字母)
156
+ matched.sort((a, b) => a.priority - b.priority || a.id.localeCompare(b.id));
157
+ // 4. 装配 + 截断
158
+ const parts = [];
159
+ const used = [];
160
+ const truncated = [];
161
+ let usedChars = 0;
162
+ for (const layer of matched) {
163
+ if (usedChars >= TOTAL_BUDGET) {
164
+ truncated.push(layer.id);
165
+ continue;
166
+ }
167
+ let content = '';
168
+ if (layer.source === 'function' && layer.resolver) {
169
+ try {
170
+ content = await layer.resolver();
171
+ }
172
+ catch {
173
+ content = '';
174
+ }
175
+ }
176
+ else {
177
+ content = layer.content || '';
178
+ }
179
+ if (content.length > layer.maxChars) {
180
+ content = content.slice(0, layer.maxChars) + '\n[… 已截断]';
181
+ truncated.push(layer.id);
182
+ }
183
+ if (usedChars + content.length > TOTAL_BUDGET) {
184
+ const remain = TOTAL_BUDGET - usedChars;
185
+ if (remain > 100) {
186
+ content = content.slice(0, remain) + '\n[… 预算截断]';
187
+ }
188
+ else {
189
+ truncated.push(layer.id);
190
+ continue;
191
+ }
192
+ }
193
+ parts.push(`<!-- ${layer.id}@${layer.version} -->\n${content}`);
194
+ used.push(layer.id);
195
+ usedChars += content.length;
196
+ }
197
+ return {
198
+ text: stripHibsml(parts.join('\n\n')),
199
+ layerIds: used,
200
+ totalChars: usedChars,
201
+ truncated,
202
+ layers: matched, // P-Action 2: 把 meta 也带回, 供 health 端点
203
+ };
204
+ }
205
+ function matchesContext(layer, ctx) {
206
+ if (layer.appliesTo.includes('all'))
207
+ return true;
208
+ for (const a of layer.appliesTo) {
209
+ if (a === ctx.channel)
210
+ return true;
211
+ if (a.startsWith('role:') && a.slice(5) === ctx.role)
212
+ return true;
213
+ if (a.startsWith('tool:') && a.slice(5) === ctx.tool)
214
+ return true;
215
+ }
216
+ return false;
217
+ }
218
+ async function loadStaticLayer(id) {
219
+ const path2md = idToPath(id);
220
+ try {
221
+ const raw = await fs.readFile(path2md, 'utf-8');
222
+ const { meta, body } = parseFrontmatter(raw);
223
+ return { content: body, meta };
224
+ }
225
+ catch (err) {
226
+ console.warn(`[system-prompt] layer ${id} 读失败: ${err.message?.slice(0, 100)}`);
227
+ return { content: `<!-- ${id}: 文件丢失 -->`, meta: null };
228
+ }
229
+ }
230
+ function idToPath(id) {
231
+ // core.refusal → layers/core/refusal.md
232
+ // tool.bash → layers/tool/bash.md
233
+ // channel.p2p-visitor → layers/channel/p2p-visitor.md
234
+ // core.tools.thin → layers/core/tools.thin.md (注意: 第一段是 group, 后面整段是文件名)
235
+ const [group, ...rest] = id.split('.');
236
+ return path.join(LAYERS_DIR, group, `${rest.join('.')}.md`);
237
+ }
238
+ /** 列所有 layer, 供调试 / reviewer 看 */
239
+ export function listLayers() {
240
+ return [...STATIC_LAYERS, ...DYNAMIC_LAYERS.map((l) => {
241
+ const { resolver, ...rest } = l;
242
+ return rest;
243
+ })];
244
+ }
245
+ /** 整体版本号 — 跟 hibs 1 对齐 */
246
+ export const SYSTEM_PROMPT_VERSION = 'hibs-1.v1.0.0';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * strip-hibsml.ts — 把 hibsml 协议标签转成 bolloon 标记
3
+ *
4
+ * hibsml 是 hibs 的协议: {hibsml:cite} {hibsml:invoke} {hibsml:thinking_mode}
5
+ * bolloon 不解析这些, 但传给 LLM 之前要"金脱除":
6
+ * - cite → [CITE:index]
7
+ * - invoke → 简化
8
+ * - thinking_mode → 注释形式保留
9
+ * - 其他标签 → 整段脱除
10
+ *
11
+ * 不脱除 hibsml 标签会让 LLM 看到原文标记 (raw XML) 误以为是工具调用.
12
+ */
13
+ const HIBML_REPLACEMENTS = [
14
+ // {hibsml:cite index="0-1,3-5"}...{/hibsml:cite} → [CITE:0-1,3-5] ... [ENDCITE]
15
+ [
16
+ /\{hibsml:cite\s+index="([^"]+)"\}/g,
17
+ (_m, idx) => `[CITE:${idx}]`,
18
+ ],
19
+ [/\{\/hibsml:cite\}/g, '[ENDCITE]'],
20
+ // {hibsml:invoke name="X"} ... {/hibsml:invoke} → [TOOL:X] ... [ENDTOOL]
21
+ [
22
+ /\{hibsml:invoke\s+name="([^"]+)"\}/g,
23
+ (_m, name) => `[TOOL:${name}]`,
24
+ ],
25
+ [/\{\/hibsml:invoke\}/g, '[ENDTOOL]'],
26
+ // {hibsml:parameter name="X"}val{/hibsml:parameter} → [P:X]val[/P]
27
+ [
28
+ /\{hibsml:parameter\s+name="([^"]+)"\}/g,
29
+ (_m, name) => `[P:${name}]`,
30
+ ],
31
+ [/\{\/hibsml:parameter\}/g, '[/P]'],
32
+ // {hibsml:thinking_mode}auto{/hibsml:thinking_mode} → [THINKING:auto] (保留)
33
+ [
34
+ /\{hibsml:thinking_mode\}(\w+)\{\/hibsml:thinking_mode\}/g,
35
+ (_m, mode) => `[THINKING:${mode}]`,
36
+ ],
37
+ // 脱除 voice_note (hibs 1 明确说永远不用)
38
+ [/<details><summary>.*?<\/summary>.*?<\/details>/gs, ''],
39
+ // 任何其他 hibsml:* 标签
40
+ [/\{hibsml:[a-z_]+\}/g, ''],
41
+ [/\{\/hibsml:[a-z_]+\}/g, ''],
42
+ ];
43
+ export function stripHibsml(text) {
44
+ let out = text;
45
+ for (const [re, rep] of HIBML_REPLACEMENTS) {
46
+ out = out.replace(re, rep);
47
+ }
48
+ // 收尾: 多个空行合并
49
+ out = out.replace(/\n{3,}/g, '\n\n');
50
+ return out.trim();
51
+ }
@@ -0,0 +1,35 @@
1
+ export const ask_user_input_v0 = {
2
+ id: 'ask_user_input_v0',
3
+ name: 'ask_user_input_v0',
4
+ oneLine: '在提供建议前展示可点击的选项以收集用户偏好 (移动端友好).',
5
+ description: '此工具显示交互式按钮, 用户可以点击按钮来回答, 在移动端比键入要容易得多. 用于引出信息 (ELICITATION) — 当你需要了解用户的偏好、约束或目标以提供有用建议时.',
6
+ whenToUse: [
7
+ '需要了解用户的偏好/约束/目标以提供有用建议',
8
+ '示例: 帮我制定锻炼计划 → 询问目标(力量/有氧/减重)、可用时间、设备访问',
9
+ '示例: 帮我为朋友挑礼物 → 询问场合、预算、朋友的兴趣',
10
+ ],
11
+ whenNotToUse: [
12
+ '用户问 A 还是 B (想要分析, 不是按钮)',
13
+ '用户在发泄或处理情绪',
14
+ '用户询问观点',
15
+ '事实问题 (直接回答)',
16
+ '用户需要散文形式反馈',
17
+ ],
18
+ parameters: [
19
+ { name: 'questions', type: 'array', required: true, description: '1-3 个问题', items: {
20
+ name: 'question', type: 'object', required: true, description: '单个问题', properties: [
21
+ { name: 'question', type: 'string', required: true, description: '向用户显示的问题' },
22
+ { name: 'type', type: 'enum', required: false, description: 'single_select | multi-select | rank_priorities', enumValues: ['single_select', 'multi_select', 'rank_priorities'], default: 'single_select' },
23
+ { name: 'options', type: 'array', required: true, description: '2-4 个带短标签的选项', minItems: 2, maxItems: 4, items: {
24
+ name: 'option', type: 'object', required: true, description: '选项', properties: [
25
+ { name: 'label', type: 'string', required: true, description: '短标签' },
26
+ { name: 'description', type: 'string', required: false, description: '选项描述' },
27
+ ],
28
+ } },
29
+ ],
30
+ } },
31
+ ],
32
+ callExample: `[TOOL:ask_user_input_v0]
33
+ [P:questions]${'${'}JSON.stringify([{"question":"你的预算?","options":[{"label":"<500"},{"label":"500-2000"}]}])[ENDTOOL]`,
34
+ layerId: 'tool.manifest',
35
+ };
@@ -0,0 +1,23 @@
1
+ export const bash_tool = {
2
+ id: 'bash_tool',
3
+ name: 'bash_tool',
4
+ oneLine: '在容器中运行 bash 命令.',
5
+ description: '在容器中运行 bash 命令. 必须用 description 参数说明为什么跑.',
6
+ whenToUse: [
7
+ '需要执行 shell 命令 (ls, mkdir, npm, git 等)',
8
+ '需要跑构建/测试/脚本',
9
+ ],
10
+ whenNotToUse: [
11
+ '读取文件 (用 view)',
12
+ '编辑文件 (用 str_replace 或 create_file)',
13
+ ],
14
+ parameters: [
15
+ { name: 'command', type: 'string', required: true, description: '要运行的 bash 命令' },
16
+ { name: 'description', type: 'string', required: true, description: '为什么我要运行此命令' },
17
+ ],
18
+ callExample: `[TOOL:bash_tool]
19
+ [P:command]ls -la /tmp
20
+ [P:description]列出 /tmp 目录内容
21
+ [ENDTOOL]`,
22
+ layerId: 'tool.bash',
23
+ };
@@ -0,0 +1,24 @@
1
+ export const create_file = {
2
+ id: 'create_file',
3
+ name: 'create_file',
4
+ oneLine: '在容器中创建带有内容的新文件.',
5
+ description: '如果路径已存在则失败 — 使用 str_replace 编辑现有文件, 或使用 bash_tool (cat > path << EOF) 覆盖.',
6
+ whenToUse: [
7
+ '创建新文件',
8
+ '需要写完整的文件内容',
9
+ ],
10
+ whenNotToUse: [
11
+ '编辑已有文件 (用 str_replace)',
12
+ ],
13
+ parameters: [
14
+ { name: 'description', type: 'string', required: true, description: '为什么我要创建此文件' },
15
+ { name: 'file_text', type: 'string', required: true, description: '要写入的文件内容' },
16
+ { name: 'path', type: 'string', required: true, description: '要创建的文件路径' },
17
+ ],
18
+ callExample: `[TOOL:create_file]
19
+ [P:description]新建 README
20
+ [P:file_text]# Project\n\nHello world
21
+ [P:path]/home/bolloon/README.md
22
+ [ENDTOOL]`,
23
+ layerId: 'tool.manifest',
24
+ };
@@ -0,0 +1,26 @@
1
+ export const fetch_sports_data = {
2
+ id: 'fetch_sports_data',
3
+ name: 'fetch_sports_data',
4
+ oneLine: '获取当前/即将进行/最近的体育数据 (比分/积分榜/比赛统计).',
5
+ description: '对于最近和即将进行的比赛的数据、比分、统计, 优先使用此工具而非 Web 搜索. 工作流: 1) 获取比分 2) 根据比赛 ID 获取统计 3) 然后才回复用户.',
6
+ whenToUse: [
7
+ '用户对某场比赛的比分感兴趣',
8
+ '广泛查询 (最近的 NBA 结果等)',
9
+ '需要详细比赛统计',
10
+ ],
11
+ whenNotToUse: [
12
+ '历史比赛 (很久以前)',
13
+ '非体育数据',
14
+ ],
15
+ parameters: [
16
+ { name: 'data_type', type: 'enum', required: true, description: 'scores | standings | game_stats', enumValues: ['scores', 'standings', 'game_stats'] },
17
+ { name: 'game_id', type: 'string', required: false, description: 'SportRadar 比赛 ID (data_type=game_stats 时必需)' },
18
+ { name: 'league', type: 'enum', required: true, description: 'nfl/nba/nhl/mlb/wnba/ncaafb/ncaamb/ncaawb/epl/la_liga/serie_a/bundesliga/ligue_1/mls/champions_league/tennis/golf/nascar/cricket/mma', enumValues: ['nfl', 'nba', 'nhl', 'mlb', 'wnba', 'ncaafb', 'ncaamb', 'ncaawb', 'epl', 'la_liga', 'serie_a', 'bundesliga', 'ligue_1', 'mls', 'champions_league', 'tennis', 'golf', 'nascar', 'cricket', 'mma'] },
19
+ { name: 'team', type: 'string', required: false, description: '可选的球队名称' },
20
+ ],
21
+ callExample: `[TOOL:fetch_sports_data]
22
+ [P:data_type]scores
23
+ [P:league]nba
24
+ [ENDTOOL]`,
25
+ layerId: 'tool.manifest',
26
+ };
@@ -0,0 +1,24 @@
1
+ export const image_search = {
2
+ id: 'image_search',
3
+ name: 'image_search',
4
+ oneLine: '在 Web 上查找图像并连同尺寸返回 (3-4 张/次).',
5
+ description: '对于视觉内容可增强用户理解的任何查询, 默认使用图像搜索. 当交付物主要是文本时跳过.',
6
+ whenToUse: [
7
+ '地点、动物、食物、人物、产品、风格、图表、历史照片、练习',
8
+ '关于视觉事物的简单事实 ("埃菲尔铁塔是哪一年造的?" → 展示它)',
9
+ '多项目内容 (指南、列表、比较、时间线、步骤) — 交错图像',
10
+ ],
11
+ whenNotToUse: [
12
+ '文本输出 (撰写邮件、代码、文章)',
13
+ '数字/数据、编码查询、技术支持、分步说明',
14
+ '关于非视觉主题的分析',
15
+ ],
16
+ parameters: [
17
+ { name: 'max_results', type: 'integer', required: false, description: '返回图片数 (默认 3, 最少 3, 最多 5)', minimum: 3, maximum: 5, default: 3 },
18
+ { name: 'query', type: 'string', required: true, description: '搜索查询 (3-6 词具体)' },
19
+ ],
20
+ callExample: `[TOOL:image_search]
21
+ [P:query]Eiffel Tower Paris
22
+ [ENDTOOL]`,
23
+ layerId: 'tool.image_search',
24
+ };
@@ -0,0 +1,69 @@
1
+ import { ask_user_input_v0 } from './ask_user_input.js';
2
+ import { bash_tool } from './bash.js';
3
+ import { create_file } from './create_file.js';
4
+ import { fetch_sports_data } from './fetch_sports_data.js';
5
+ import { image_search } from './image_search.js';
6
+ import { message_compose_v1 } from './message_compose.js';
7
+ import { places_search, places_map_display_v0 } from './places.js';
8
+ import { present_files } from './present_files.js';
9
+ import { recipe_display_v0 } from './recipe.js';
10
+ import { recommend_bolloon_apps } from './recommend_apps.js';
11
+ import { search_mcp_registry, suggest_connectors } from './mcp.js';
12
+ import { str_replace } from './str_replace.js';
13
+ import { view } from './view.js';
14
+ import { web_search, web_fetch } from './web.js';
15
+ import { weather_fetch } from './weather.js';
16
+ const ALL = [
17
+ ask_user_input_v0,
18
+ bash_tool,
19
+ create_file,
20
+ fetch_sports_data,
21
+ image_search,
22
+ message_compose_v1,
23
+ places_search,
24
+ places_map_display_v0,
25
+ present_files,
26
+ recipe_display_v0,
27
+ recommend_bolloon_apps,
28
+ search_mcp_registry,
29
+ suggest_connectors,
30
+ str_replace,
31
+ view,
32
+ web_search,
33
+ web_fetch,
34
+ weather_fetch,
35
+ ];
36
+ export function listTools() {
37
+ return ALL;
38
+ }
39
+ export function getToolManifest(id) {
40
+ return ALL.find((t) => t.id === id);
41
+ }
42
+ export function getToolsByLayer(layerId) {
43
+ return ALL.filter((t) => t.layerId === layerId);
44
+ }
45
+ /**
46
+ * 缩到 1-3KB 装进 system prompt
47
+ * 包含: 名字 + 一句话 + whenToUse(2) + whenNotToUse(1) + 1 行示例
48
+ *
49
+ * 不包含: 完整 parameters schema (那是 PiAI 客户端在调用时读)
50
+ */
51
+ export function formatForPrompt(tools) {
52
+ const list = tools ?? ALL;
53
+ const lines = [
54
+ `## 工具清单 (${list.length} 个, 详细 schema 在 src/llm/tool-manifest/, 调用时由 PiAI 客户端解析)`,
55
+ '',
56
+ ];
57
+ for (const t of list) {
58
+ lines.push(`### ${t.id}`);
59
+ lines.push(`- **用途**: ${t.oneLine}`);
60
+ lines.push(`- **何时用**: ${t.whenToUse[0] ?? ''}`);
61
+ if (t.whenToUse.length > 1) {
62
+ lines.push(` - 也: ${t.whenToUse.slice(1, 3).join(' / ')}`);
63
+ }
64
+ lines.push(`- **何时不用**: ${t.whenNotToUse[0] ?? ''}`);
65
+ lines.push(`- **示例**: ${t.callExample.replace(/\n/g, ' ')}`);
66
+ lines.push('');
67
+ }
68
+ return lines.join('\n');
69
+ }
@@ -0,0 +1,43 @@
1
+ export const search_mcp_registry = {
2
+ id: 'search_mcp_registry',
3
+ name: 'search_mcp_registry',
4
+ oneLine: '在 MCP 注册表中搜索可用连接器.',
5
+ description: '当连接新的 MCP 可能有助于解决用户查询时, 无论他们是否指名了特定产品, 请调用此工具. 如果结果相关, 调用 suggest_connectors 呈现选项. 如果没有任何匹配任务的内容, 不要调用 suggest_connectors.',
6
+ whenToUse: [
7
+ '用户隐含读取个人数据 (邮件、日历、任务、文件、工单)',
8
+ '需要连接外部服务 (Asana/Jira/Slack/Calendar)',
9
+ '用户指名了特定连接器 (即使未连接)',
10
+ ],
11
+ whenNotToUse: [
12
+ '知识问答/购物建议/一般性建议',
13
+ '用户已指名了已连接的特定服务 (直接用)',
14
+ ],
15
+ parameters: [
16
+ { name: 'keywords', type: 'array', required: true, description: '搜索关键词', minItems: 1, items: { name: 'kw', type: 'string', required: true, description: '关键词' } }
17
+ ],
18
+ callExample: `[TOOL:search_mcp_registry]
19
+ [P:keywords]${'${'}JSON.stringify(["calendar","schedule"])[ENDTOOL]`,
20
+ layerId: 'tool.mcp_apps',
21
+ };
22
+ export const suggest_connectors = {
23
+ id: 'suggest_connectors',
24
+ name: 'suggest_connectors',
25
+ oneLine: '向用户展示连接器选项, 让用户选择.',
26
+ description: '每个选项都会渲染一个连接或使用按钮, 以及一个"以上都不是"选项. 调用后用一句简短的引导语结束你的回合.',
27
+ whenToUse: [
28
+ 'search_mcp_registry 找到了相关选项',
29
+ '用户未明确指名连接器',
30
+ '工具调用因身份验证/凭据错误失败 (重认证)',
31
+ ],
32
+ whenNotToUse: [
33
+ 'search_mcp_registry 未返回相关内容',
34
+ '用户已指名了特定的已连接服务 (直接用)',
35
+ '没有 search_mcp_registry 上下文',
36
+ ],
37
+ parameters: [
38
+ { name: 'uuids', type: 'array', required: true, description: '从 search_mcp_registry 结果的 directoryUuid 复制', minItems: 1, items: { name: 'u', type: 'string', required: true, description: 'uuid' } }
39
+ ],
40
+ callExample: `[TOOL:suggest_connectors]
41
+ [P:uuids]${'${'}JSON.stringify(["uuid-from-search-result"])[ENDTOOL]`,
42
+ layerId: 'tool.mcp_apps',
43
+ };
@@ -0,0 +1,31 @@
1
+ export const message_compose_v1 = {
2
+ id: 'message_compose_v1',
3
+ name: 'message_compose_v1',
4
+ oneLine: '起草目标导向的消息 (email/textMessage/other).',
5
+ description: '分析情境类型 (工作分歧、谈判、跟进、传达坏消息、请求某事、设定边界、道歉、拒绝、提供反馈、冷启动接触、回应反馈、澄清误解、委派、庆祝) 并识别竞争目标. 多种方法 (高风险/模糊) 生成 2-3 种策略.',
6
+ whenToUse: [
7
+ '用户要你起草一封邮件/消息',
8
+ '高风险沟通 (谈判、道歉、设定边界)',
9
+ '需要适配渠道 (邮件 vs Slack vs 短信)',
10
+ ],
11
+ whenNotToUse: [
12
+ '用户只是要写笔记/便签',
13
+ '对话中直接回复',
14
+ ],
15
+ parameters: [
16
+ { name: 'kind', type: 'enum', required: true, description: 'email | textMessage | other', enumValues: ['email', 'textMessage', 'other'] },
17
+ { name: 'summary_title', type: 'string', required: true, description: '消息的摘要标题' },
18
+ { name: 'variants', type: 'array', required: true, description: '至少 1 个变体', minItems: 1, items: {
19
+ name: 'variant', type: 'object', required: true, description: '变体', properties: [
20
+ { name: 'label', type: 'string', required: true, description: '变体标签' },
21
+ { name: 'body', type: 'string', required: true, description: '消息内容' },
22
+ { name: 'subject', type: 'string', required: false, description: '邮件主题 (仅 email)' },
23
+ ],
24
+ } },
25
+ ],
26
+ callExample: `[TOOL:message_compose_v1]
27
+ [P:kind]email
28
+ [P:summary_title]Follow-up on Q3 review
29
+ [P:variants]${'${'}JSON.stringify([{"label":"direct","subject":"Quick follow-up","body":"..."}])[ENDTOOL]`,
30
+ layerId: 'tool.manifest',
31
+ };