@bolloon/bolloon-agent 0.4.14 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/README.md +127 -127
  2. package/bin/bolloon-cli.cjs +183 -183
  3. package/bin/bolloon-daemon.sh +207 -0
  4. package/bin/bolloon.cjs +0 -0
  5. package/dist/agents/constraint-layer.js +19 -19
  6. package/dist/agents/judgment-protocol.js +14 -14
  7. package/dist/agents/pi-sdk-types.js +12 -12
  8. package/dist/agents/pi-sdk.js +101 -101
  9. package/dist/agents/skill-organizer.js +19 -19
  10. package/dist/agents/workflow-pivot-loop.js +2 -2
  11. package/dist/agents/x402/x402Pay.js +4 -0
  12. package/dist/bollharness/src/scripts/deploy-guard.js +8 -8
  13. package/dist/bollharness-integration/context-router-judgment.js +4 -4
  14. package/dist/bollharness-integration/context-router.js +292 -292
  15. package/dist/bollharness-integration/gate-state-machine.js +13 -13
  16. package/dist/bollharness-integration/llm-judgment-engine.js +134 -134
  17. package/dist/bollharness-integration/skill-adapter.js +21 -21
  18. package/dist/bootstrap/chat-archiver.js +14 -14
  19. package/dist/bootstrap/context-os.js +24 -24
  20. package/dist/bootstrap/memory-compressor.js +13 -13
  21. package/dist/cli-entry.js +36 -36
  22. package/dist/constraint-runtime/reference_data/archive_surface_snapshot.json +63 -0
  23. package/dist/constraint-runtime/reference_data/commands_snapshot.json +1037 -0
  24. package/dist/constraint-runtime/reference_data/subsystems/assistant.json +8 -0
  25. package/dist/constraint-runtime/reference_data/subsystems/bootstrap.json +8 -0
  26. package/dist/constraint-runtime/reference_data/subsystems/bridge.json +32 -0
  27. package/dist/constraint-runtime/reference_data/subsystems/buddy.json +13 -0
  28. package/dist/constraint-runtime/reference_data/subsystems/cli.json +26 -0
  29. package/dist/constraint-runtime/reference_data/subsystems/components.json +32 -0
  30. package/dist/constraint-runtime/reference_data/subsystems/constants.json +28 -0
  31. package/dist/constraint-runtime/reference_data/subsystems/coordinator.json +8 -0
  32. package/dist/constraint-runtime/reference_data/subsystems/entrypoints.json +15 -0
  33. package/dist/constraint-runtime/reference_data/subsystems/hooks.json +32 -0
  34. package/dist/constraint-runtime/reference_data/subsystems/keybindings.json +21 -0
  35. package/dist/constraint-runtime/reference_data/subsystems/memdir.json +15 -0
  36. package/dist/constraint-runtime/reference_data/subsystems/migrations.json +18 -0
  37. package/dist/constraint-runtime/reference_data/subsystems/moreright.json +8 -0
  38. package/dist/constraint-runtime/reference_data/subsystems/native_ts.json +11 -0
  39. package/dist/constraint-runtime/reference_data/subsystems/outputStyles.json +8 -0
  40. package/dist/constraint-runtime/reference_data/subsystems/plugins.json +9 -0
  41. package/dist/constraint-runtime/reference_data/subsystems/remote.json +11 -0
  42. package/dist/constraint-runtime/reference_data/subsystems/schemas.json +8 -0
  43. package/dist/constraint-runtime/reference_data/subsystems/screens.json +10 -0
  44. package/dist/constraint-runtime/reference_data/subsystems/server.json +10 -0
  45. package/dist/constraint-runtime/reference_data/subsystems/services.json +32 -0
  46. package/dist/constraint-runtime/reference_data/subsystems/skills.json +27 -0
  47. package/dist/constraint-runtime/reference_data/subsystems/state.json +13 -0
  48. package/dist/constraint-runtime/reference_data/subsystems/types.json +18 -0
  49. package/dist/constraint-runtime/reference_data/subsystems/upstreamproxy.json +9 -0
  50. package/dist/constraint-runtime/reference_data/subsystems/utils.json +32 -0
  51. package/dist/constraint-runtime/reference_data/subsystems/vim.json +12 -0
  52. package/dist/constraint-runtime/reference_data/subsystems/voice.json +8 -0
  53. package/dist/constraint-runtime/reference_data/tools_snapshot.json +922 -0
  54. package/dist/context-compaction/auto-compact.js +7 -7
  55. package/dist/electron/config.js.map +1 -0
  56. package/dist/electron/dialogs.js.map +1 -0
  57. package/dist/electron/first-run.js +54 -54
  58. package/dist/electron/first-run.js.map +1 -0
  59. package/dist/electron/ipc.js.map +1 -0
  60. package/dist/electron/logger.js.map +1 -0
  61. package/dist/electron/main.js.map +1 -0
  62. package/dist/electron/menu.js.map +1 -0
  63. package/dist/electron/paths.js.map +1 -0
  64. package/dist/electron/server.js.map +1 -0
  65. package/dist/electron/tray.js.map +1 -0
  66. package/dist/electron/window.js.map +1 -0
  67. package/dist/electron-build/electron/first-run.js +54 -54
  68. package/dist/electron-preload.js.map +1 -1
  69. package/dist/electron.js.map +1 -1
  70. package/dist/index.js +112 -112
  71. package/dist/llm/llm-judgment-client.js +102 -102
  72. package/dist/llm/pi-ai.js +48 -48
  73. package/dist/llm/system-prompt/layers/channel/human-async.md +41 -41
  74. package/dist/llm/system-prompt/layers/channel/local.md +14 -14
  75. package/dist/llm/system-prompt/layers/channel/p2p-agent.md +18 -18
  76. package/dist/llm/system-prompt/layers/channel/p2p-peer-sync.md +51 -51
  77. package/dist/llm/system-prompt/layers/channel/p2p-proactive.md +43 -43
  78. package/dist/llm/system-prompt/layers/channel/p2p-visitor.md +19 -19
  79. package/dist/llm/system-prompt/layers/channel/session-handoff.md +61 -61
  80. package/dist/llm/system-prompt/layers/core/artifacts_storage.md +89 -89
  81. package/dist/llm/system-prompt/layers/core/evenhandedness.md +21 -21
  82. package/dist/llm/system-prompt/layers/core/external-engagement.md +73 -73
  83. package/dist/llm/system-prompt/layers/core/hibs_reminders.md +15 -15
  84. package/dist/llm/system-prompt/layers/core/identity.md +48 -48
  85. package/dist/llm/system-prompt/layers/core/knowledge.md +17 -17
  86. package/dist/llm/system-prompt/layers/core/memory_system.md +12 -12
  87. package/dist/llm/system-prompt/layers/core/network_filesystem.md +28 -28
  88. package/dist/llm/system-prompt/layers/core/refusal.md +37 -37
  89. package/dist/llm/system-prompt/layers/core/tone.md +31 -31
  90. package/dist/llm/system-prompt/layers/core/tools.thin.md +13 -13
  91. package/dist/llm/system-prompt/layers/core/wellbeing.md +41 -41
  92. package/dist/llm/system-prompt/layers/role/architect.md +20 -20
  93. package/dist/llm/system-prompt/layers/role/expert.md +19 -19
  94. package/dist/llm/system-prompt/layers/role/implementer.md +15 -15
  95. package/dist/llm/system-prompt/layers/role/security.md +15 -15
  96. package/dist/llm/system-prompt/layers/tool/artifacts.md +72 -72
  97. package/dist/llm/system-prompt/layers/tool/bash.md +25 -25
  98. package/dist/llm/system-prompt/layers/tool/goal_handoff.md +77 -77
  99. package/dist/llm/system-prompt/layers/tool/hibs_api.md +171 -171
  100. package/dist/llm/system-prompt/layers/tool/image_search.md +70 -70
  101. package/dist/llm/system-prompt/layers/tool/manifest.md +89 -89
  102. package/dist/llm/system-prompt/layers/tool/mcp_apps.md +53 -53
  103. package/dist/llm/system-prompt/layers/tool/p2p_request.md +61 -61
  104. package/dist/llm/system-prompt/layers/tool/web_search.md +83 -83
  105. package/dist/llm/tool-manifest/ask_user_input.js +1 -1
  106. package/dist/llm/tool-manifest/bash.js +3 -3
  107. package/dist/llm/tool-manifest/create_file.js +4 -4
  108. package/dist/llm/tool-manifest/fetch_sports_data.js +3 -3
  109. package/dist/llm/tool-manifest/image_search.js +2 -2
  110. package/dist/llm/tool-manifest/index.js +59 -0
  111. package/dist/llm/tool-manifest/mcp.js +2 -2
  112. package/dist/llm/tool-manifest/message_compose.js +3 -3
  113. package/dist/llm/tool-manifest/places.js +2 -2
  114. package/dist/llm/tool-manifest/present_files.js +1 -1
  115. package/dist/llm/tool-manifest/recipe.js +2 -2
  116. package/dist/llm/tool-manifest/str_replace.js +5 -5
  117. package/dist/llm/tool-manifest/view.js +3 -3
  118. package/dist/llm/tool-manifest/weather.js +4 -4
  119. package/dist/llm/tool-manifest/web.js +4 -4
  120. package/dist/network/p2p.js +78 -4
  121. package/dist/pi-ecosystem-judgment/causal-judge.js +51 -51
  122. package/dist/pi-ecosystem-judgment/distill-prompt.js +42 -42
  123. package/dist/pi-ecosystem-judgment/distillation.js +14 -14
  124. package/dist/pi-ecosystem-judgment/index.js +1 -1
  125. package/dist/pi-ecosystem-judgment/monitor-gate.js +28 -28
  126. package/dist/pi-ecosystem-judgment/value-injection.js +102 -102
  127. package/dist/security/context-router-tool.js +15 -15
  128. package/dist/utils/auto-update.js.map +1 -0
  129. package/dist/web/a2ui-client.js +1594 -223
  130. package/dist/web/api-config.html +779 -779
  131. package/dist/web/client-hearth.js +10 -10
  132. package/dist/web/client.js.map +7 -0
  133. package/dist/web/components/wallet-viem.mjs +118 -118
  134. package/dist/web/index.html +502 -502
  135. package/dist/web/manifest.json +20 -20
  136. package/dist/web/mobile-agent.js +397 -0
  137. package/dist/web/mobile-core.js +86235 -0
  138. package/dist/web/mobile-data.js +346 -0
  139. package/dist/web/mobile-http-api.js +71 -0
  140. package/dist/web/mobile-p2p.js +250 -0
  141. package/dist/web/mobile-payments.js +80 -0
  142. package/dist/web/mobile-wallet.js +226 -0
  143. package/dist/web/mobile.css +483 -6
  144. package/dist/web/mobile.html +99 -50
  145. package/dist/web/mobile.js +1040 -187
  146. package/dist/web/server.js +13 -13
  147. package/dist/web/style.css +4946 -4946
  148. package/package.json +201 -198
  149. package/scripts/build-cli.js +215 -215
  150. package/scripts/build-web.ts +162 -149
  151. package/scripts/postinstall.js +152 -152
  152. package/bin/bolloon.js +0 -157
  153. package/dist/agents/python-exec.js +0 -115
  154. package/dist/pi-ecosystem-colony/index.js +0 -365
  155. package/dist/social/ant-colony/AdaptiveHeartbeat.js +0 -101
  156. package/dist/social/ant-colony/PheromoneEngine.js +0 -227
  157. package/dist/social/ant-colony/index.js +0 -6
  158. package/dist/social/ant-colony/types.js +0 -24
  159. package/dist/storage/trajectory.js +0 -101
  160. package/dist/test/ai-judgment-test.js +0 -80
  161. package/dist/test/bollharness-integration.test.js +0 -318
  162. package/dist/test/channel-agent-multi-dialogue.js +0 -205
  163. package/dist/test/channel-heartbeat-agent-test.js +0 -201
  164. package/dist/test/constraint-layer.test.js +0 -164
  165. package/dist/test/diap-identity-test.js +0 -172
  166. package/dist/test/diap-quick-test.js +0 -62
  167. package/dist/test/global-shared-context.test.js +0 -315
  168. package/dist/test/harness-judgment-injection.test.js +0 -246
  169. package/dist/test/harness-workflow-integrator-test.js +0 -228
  170. package/dist/test/human-value-store.test.js +0 -243
  171. package/dist/test/hybrid-integration-test.js +0 -118
  172. package/dist/test/hybrid-messenger-verify.js +0 -55
  173. package/dist/test/iroh-bistream-debug.js +0 -38
  174. package/dist/test/iroh-communication.test.js +0 -66
  175. package/dist/test/iroh-debug-test.js +0 -57
  176. package/dist/test/iroh-diap-test.js +0 -71
  177. package/dist/test/iroh-direct-connect.js +0 -55
  178. package/dist/test/iroh-e2e-fixed.js +0 -89
  179. package/dist/test/iroh-e2e-same-process.js +0 -63
  180. package/dist/test/iroh-e2e.js +0 -66
  181. package/dist/test/iroh-final-e2e.js +0 -72
  182. package/dist/test/iroh-relay-test.js +0 -37
  183. package/dist/test/iroh-simple-test.js +0 -41
  184. package/dist/test/iroh-transport-verify.js +0 -54
  185. package/dist/test/iroh-transport.test.js +0 -37
  186. package/dist/test/iroh-two-nodes.js +0 -70
  187. package/dist/test/iroh-verify.js +0 -44
  188. package/dist/test/judgment-decision.test.js +0 -219
  189. package/dist/test/llm-judgment-integration.test.js +0 -220
  190. package/dist/test/p2p-agent-complex-dialogue.js +0 -385
  191. package/dist/test/p2p-agent-dialogue.js +0 -341
  192. package/dist/test/p2p-agent-full-bidirectional.js +0 -510
  193. package/dist/test/p2p-agent-harness-flow.js +0 -437
  194. package/dist/test/p2p-agent-harness-single.js +0 -143
  195. package/dist/test/p2p-ai-dialogue-test.js +0 -318
  196. package/dist/test/p2p-cid-connect-test.js +0 -195
  197. package/dist/test/p2p-connect-receiver.js +0 -69
  198. package/dist/test/p2p-doc-transfer.js +0 -110
  199. package/dist/test/p2p-identity-page-test.js +0 -77
  200. package/dist/test/p2p-iroh-test.js +0 -171
  201. package/dist/test/p2p-minimal-test.js +0 -241
  202. package/dist/test/p2p-node-1.js +0 -148
  203. package/dist/test/p2p-node-2.js +0 -148
  204. package/dist/test/p2p-server.js +0 -281
  205. package/dist/test/p2p-two-nodes-test.js +0 -438
  206. package/dist/test/pi-sdk.test.js +0 -44
  207. package/dist/test/set-persona.js +0 -40
  208. package/dist/test/simple.test.js +0 -9
  209. package/dist/test/storage-integration.test.js +0 -150
  210. package/dist/test/subagent-manager.test.js +0 -276
  211. package/dist/test/test-gate-flow.test.js +0 -81
  212. package/dist/test/workflow-engine.test.js +0 -87
  213. package/dist/test/workflow-pivot-loop.test.js +0 -246
@@ -1,149 +1,162 @@
1
- /**
2
- * Web 构建脚本
3
- */
4
- import * as fs from 'fs/promises';
5
- import * as path from 'path';
6
- import { execSync } from 'child_process';
7
- import * as esbuild from 'esbuild';
8
-
9
- const ROOT = path.resolve(import.meta.dirname, '..');
10
- const DIST_WEB = path.join(ROOT, 'dist', 'web');
11
-
12
- async function main() {
13
- console.log('[build-web] 开始构建...');
14
-
15
- // 重要: 不能 rm -rf 整个 dist/web/, 否则会删掉 build:main 编译出来的
16
- // dist/web/server.js. 只清理 web 静态资源, 保留 server.js.
17
- for (const f of ['index.html', 'api-config.html', 'style.css', 'client.js', 'mobile.html', 'mobile.css', 'mobile.js', 'components']) {
18
- await fs.rm(path.join(DIST_WEB, f), { recursive: true, force: true });
19
- }
20
- await fs.mkdir(DIST_WEB, { recursive: true });
21
- await fs.mkdir(path.join(DIST_WEB, 'components', 'p2p'), { recursive: true });
22
-
23
- // 编译 TypeScript 模块
24
- console.log('[build-web] 编译 TypeScript 模块...');
25
- const moduleFiles = [
26
- 'src/web/components/p2p/types.ts',
27
- 'src/web/components/p2p/p2p-store-memory.ts',
28
- 'src/web/components/p2p/p2p-identity.ts',
29
- 'src/web/components/p2p/p2p-connection.ts',
30
- 'src/web/components/p2p/p2p-messages.ts',
31
- 'src/web/components/p2p/p2p-manager.ts',
32
- ];
33
-
34
- try {
35
- execSync(`npx tsc --ignoreConfig --outDir dist/web/components/p2p --declaration false --skipLibCheck --target ES2022 --module ESNext --moduleResolution bundler ${moduleFiles.join(' ')}`, {
36
- cwd: ROOT,
37
- stdio: 'inherit'
38
- });
39
- } catch {
40
- console.log('[build-web] TypeScript 编译有警告,继续...');
41
- }
42
-
43
- // 编译 P2P Modal UI(esbuild)
44
- console.log('[build-web] 编译 P2P Modal UI...');
45
- await esbuild.build({
46
- entryPoints: [path.join(ROOT, 'src/web/components/p2p/index.ts')],
47
- outfile: path.join(DIST_WEB, 'components/p2p/index.js'),
48
- format: 'esm',
49
- target: 'es2022',
50
- platform: 'browser',
51
- minify: false,
52
- });
53
-
54
- // 2026-06-15: 编译 message-renderer.ts (对话显示 UI 模块)
55
- // esbuild 编译 .ts → dist/web/ui/message-renderer.js (ESM, 浏览器侧 <script type="module"> 加载)
56
- console.log('[build-web] 编译 message-renderer.ts...');
57
- await fs.mkdir(path.join(DIST_WEB, 'ui'), { recursive: true });
58
- await esbuild.build({
59
- entryPoints: [path.join(ROOT, 'src/web/ui/message-renderer.ts')],
60
- outfile: path.join(DIST_WEB, 'ui/message-renderer.js'),
61
- format: 'esm',
62
- target: 'es2022',
63
- platform: 'browser',
64
- minify: false,
65
- });
66
-
67
- // 2026-06-15: 编译 step-timeline.ts (气泡内 4 状态步骤条)
68
- console.log('[build-web] 编译 step-timeline.ts...');
69
- await esbuild.build({
70
- entryPoints: [path.join(ROOT, 'src/web/ui/step-timeline.ts')],
71
- outfile: path.join(DIST_WEB, 'ui/step-timeline.js'),
72
- format: 'esm',
73
- target: 'es2022',
74
- platform: 'browser',
75
- minify: false,
76
- });
77
-
78
- // 编译主客户端入口 (classic script, 非 module; 由 index.html 以 /client.js 加载)
79
- // 2026-07-06: client.ts 加了 import { safeChannelName } from './util/safe-name.js'.
80
- // 不开 bundle 的话, esbuild 把 require("./util/safe-name.js") 内联到 IIFE 顶层
81
- // → 浏览器无 require → ReferenceError → init() 没跑 → UI 全空 (channels 不显示).
82
- // 开 bundle=true 让 esbuild 把 safe-name 全部 inline 进 client.js (1.8KB, 无影响).
83
- console.log('[build-web] 编译 client.ts...');
84
- await esbuild.build({
85
- entryPoints: [path.join(ROOT, 'src/web/client.ts')],
86
- outfile: path.join(DIST_WEB, 'client.js'),
87
- format: 'iife',
88
- target: 'es2022',
89
- platform: 'browser',
90
- minify: false,
91
- bundle: true,
92
- });
93
-
94
- // 2026-08-12: 编译 A2UI 前端渲染器 (a2ui-client.tsxa2ui-client.js)
95
- // react + @a2ui/react + @a2ui/web_core 全部打包进 bundle (手机端 webview CDN)
96
- console.log('[build-web] 编译 a2ui-client.tsx...');
97
- await esbuild.build({
98
- entryPoints: [path.join(ROOT, 'src/web/a2ui-client.tsx')],
99
- outfile: path.join(DIST_WEB, 'a2ui-client.js'),
100
- format: 'iife',
101
- target: 'es2022',
102
- platform: 'browser',
103
- minify: false,
104
- bundle: true,
105
- jsx: 'automatic',
106
- loader: { '.tsx': 'tsx' },
107
- });
108
-
109
- // 复制静态文件
110
- console.log('[build-web] 复制静态文件...');
111
- await fs.copyFile(path.join(ROOT, 'src/web/index.html'), path.join(DIST_WEB, 'index.html'));
112
- await fs.copyFile(path.join(ROOT, 'src/web/api-config.html'), path.join(DIST_WEB, 'api-config.html'));
113
- await fs.copyFile(path.join(ROOT, 'src/web/style.css'), path.join(DIST_WEB, 'style.css'));
114
- // 2026-08-12: 手机端 UI (微信风格, Capacitor webview 加载) — 纯静态复制
115
- await fs.copyFile(path.join(ROOT, 'src/web/mobile.html'), path.join(DIST_WEB, 'mobile.html'));
116
- await fs.copyFile(path.join(ROOT, 'src/web/mobile.css'), path.join(DIST_WEB, 'mobile.css'));
117
- await fs.copyFile(path.join(ROOT, 'src/web/mobile.js'), path.join(DIST_WEB, 'mobile.js'));
118
- // 复制 PWA manifest (index.html 里有 <link rel="manifest">, 否则浏览器会 404)
119
- await fs.copyFile(path.join(ROOT, 'src/web/manifest.json'), path.join(DIST_WEB, 'manifest.json'));
120
- // 复制 icons 目录 (manifest.json 里引用了 favicon 等)
121
- await fs.cp(path.join(ROOT, 'src/web/icons'), path.join(DIST_WEB, 'icons'), { recursive: true });
122
-
123
- // 复制 system-prompt layer .md 文件到 dist/llm/system-prompt/layers/
124
- // 原因: tsc 不复制 .md, src/llm/system-prompt/layers/{core,role,channel,tool}/*.md
125
- // 在 dist 里完全不存在, registry.ts 用 __dirname + 'layers' 读它们时 100% ENOENT.
126
- // 这里全量复制 25 个 .md, 不过滤 'never' — registry.matchesContext 已做过滤.
127
- const srcLayers = path.join(ROOT, 'src/llm/system-prompt/layers');
128
- const dstLayers = path.join(ROOT, 'dist/llm/system-prompt/layers');
129
- await fs.cp(srcLayers, dstLayers, { recursive: true });
130
- console.log('[build-web] system-prompt layers copied →', path.relative(ROOT, dstLayers));
131
-
132
- // 复制 components/ 下的独立 ESM 模块 ( p2p 那些, 已被 esbuild 单独编译)
133
- // 例如 wallet-viem.mjs: 浏览器侧 viem 封装, index.html 引用
134
- const extraComponentsDir = path.join(ROOT, 'src/web/components');
135
- for (const entry of await fs.readdir(extraComponentsDir)) {
136
- if (entry === 'p2p') continue;
137
- const src = path.join(extraComponentsDir, entry);
138
- const dest = path.join(DIST_WEB, 'components', entry);
139
- const stat = await fs.stat(src);
140
- if (stat.isFile()) {
141
- await fs.mkdir(path.dirname(dest), { recursive: true });
142
- await fs.copyFile(src, dest);
143
- }
144
- }
145
-
146
- console.log('[build-web] 完成!');
147
- }
148
-
149
- main().catch(console.error);
1
+ /**
2
+ * Web 构建脚本
3
+ */
4
+ import * as fs from 'fs/promises';
5
+ import * as path from 'path';
6
+ import { execSync } from 'child_process';
7
+ import * as esbuild from 'esbuild';
8
+
9
+ const ROOT = path.resolve(import.meta.dirname, '..');
10
+ const DIST_WEB = path.join(ROOT, 'dist', 'web');
11
+
12
+ async function main() {
13
+ console.log('[build-web] 开始构建...');
14
+
15
+ // 重要: 不能 rm -rf 整个 dist/web/, 否则会删掉 build:main 编译出来的
16
+ // dist/web/server.js. 只清理 web 静态资源, 保留 server.js.
17
+ for (const f of ['index.html', 'api-config.html', 'style.css', 'client.js', 'mobile.html', 'mobile.css', 'mobile.js', 'mobile-core.js', 'components']) {
18
+ await fs.rm(path.join(DIST_WEB, f), { recursive: true, force: true });
19
+ }
20
+ await fs.mkdir(DIST_WEB, { recursive: true });
21
+ await fs.mkdir(path.join(DIST_WEB, 'components', 'p2p'), { recursive: true });
22
+
23
+ // 编译 TypeScript 模块
24
+ console.log('[build-web] 编译 TypeScript 模块...');
25
+ const moduleFiles = [
26
+ 'src/web/components/p2p/types.ts',
27
+ 'src/web/components/p2p/p2p-store-memory.ts',
28
+ 'src/web/components/p2p/p2p-identity.ts',
29
+ 'src/web/components/p2p/p2p-connection.ts',
30
+ 'src/web/components/p2p/p2p-messages.ts',
31
+ 'src/web/components/p2p/p2p-manager.ts',
32
+ ];
33
+
34
+ try {
35
+ execSync(`npx tsc --ignoreConfig --outDir dist/web/components/p2p --declaration false --skipLibCheck --target ES2022 --module ESNext --moduleResolution bundler ${moduleFiles.join(' ')}`, {
36
+ cwd: ROOT,
37
+ stdio: 'inherit'
38
+ });
39
+ } catch {
40
+ console.log('[build-web] TypeScript 编译有警告,继续...');
41
+ }
42
+
43
+ // 编译 P2P Modal UI(esbuild)
44
+ console.log('[build-web] 编译 P2P Modal UI...');
45
+ await esbuild.build({
46
+ entryPoints: [path.join(ROOT, 'src/web/components/p2p/index.ts')],
47
+ outfile: path.join(DIST_WEB, 'components/p2p/index.js'),
48
+ format: 'esm',
49
+ target: 'es2022',
50
+ platform: 'browser',
51
+ minify: false,
52
+ });
53
+
54
+ // 2026-06-15: 编译 message-renderer.ts (对话显示 UI 模块)
55
+ // esbuild 编译 .ts → dist/web/ui/message-renderer.js (ESM, 浏览器侧 <script type="module"> 加载)
56
+ console.log('[build-web] 编译 message-renderer.ts...');
57
+ await fs.mkdir(path.join(DIST_WEB, 'ui'), { recursive: true });
58
+ await esbuild.build({
59
+ entryPoints: [path.join(ROOT, 'src/web/ui/message-renderer.ts')],
60
+ outfile: path.join(DIST_WEB, 'ui/message-renderer.js'),
61
+ format: 'esm',
62
+ target: 'es2022',
63
+ platform: 'browser',
64
+ minify: false,
65
+ });
66
+
67
+ // 2026-06-15: 编译 step-timeline.ts (气泡内 4 状态步骤条)
68
+ console.log('[build-web] 编译 step-timeline.ts...');
69
+ await esbuild.build({
70
+ entryPoints: [path.join(ROOT, 'src/web/ui/step-timeline.ts')],
71
+ outfile: path.join(DIST_WEB, 'ui/step-timeline.js'),
72
+ format: 'esm',
73
+ target: 'es2022',
74
+ platform: 'browser',
75
+ minify: false,
76
+ });
77
+
78
+ // 编译主客户端入口 (classic script, 非 module; 由 index.html 以 /client.js 加载)
79
+ // 2026-07-06: client.ts 加了 import { safeChannelName } from './util/safe-name.js'.
80
+ // 不开 bundle 的话, esbuild 把 require("./util/safe-name.js") 内联到 IIFE 顶层
81
+ // → 浏览器无 require → ReferenceError → init() 没跑 → UI 全空 (channels 不显示).
82
+ // 开 bundle=true 让 esbuild 把 safe-name 全部 inline 进 client.js (1.8KB, 无影响).
83
+ console.log('[build-web] 编译 client.ts...');
84
+ await esbuild.build({
85
+ entryPoints: [path.join(ROOT, 'src/web/client.ts')],
86
+ outfile: path.join(DIST_WEB, 'client.js'),
87
+ format: 'iife',
88
+ target: 'es2022',
89
+ platform: 'browser',
90
+ minify: false,
91
+ bundle: true,
92
+ });
93
+
94
+ // 2026-08-14: 编译 mobile-core.ts (手机端内化内核 mobile-core.js)
95
+ // IIFE + bundle: WebView module 解析, 必须全内联 (IndexedDB/WebCrypto 为浏览器原生, 无需 polyfill)
96
+ console.log('[build-web] 编译 mobile-core.ts...');
97
+ await esbuild.build({
98
+ entryPoints: [path.join(ROOT, 'src/web/mobile-core.ts')],
99
+ outfile: path.join(DIST_WEB, 'mobile-core.js'),
100
+ format: 'iife',
101
+ target: 'es2022',
102
+ platform: 'browser',
103
+ minify: false,
104
+ bundle: true,
105
+ });
106
+
107
+ // 2026-08-12: 编译 A2UI 前端渲染器 (a2ui-client.tsx → a2ui-client.js)
108
+ // react + @a2ui/react + @a2ui/web_core 全部打包进 bundle (手机端 webview 无 CDN)
109
+ console.log('[build-web] 编译 a2ui-client.tsx...');
110
+ await esbuild.build({
111
+ entryPoints: [path.join(ROOT, 'src/web/a2ui-client.tsx')],
112
+ outfile: path.join(DIST_WEB, 'a2ui-client.js'),
113
+ format: 'iife',
114
+ target: 'es2022',
115
+ platform: 'browser',
116
+ minify: false,
117
+ bundle: true,
118
+ jsx: 'automatic',
119
+ loader: { '.tsx': 'tsx' },
120
+ });
121
+
122
+ // 复制静态文件
123
+ console.log('[build-web] 复制静态文件...');
124
+ await fs.copyFile(path.join(ROOT, 'src/web/index.html'), path.join(DIST_WEB, 'index.html'));
125
+ await fs.copyFile(path.join(ROOT, 'src/web/api-config.html'), path.join(DIST_WEB, 'api-config.html'));
126
+ await fs.copyFile(path.join(ROOT, 'src/web/style.css'), path.join(DIST_WEB, 'style.css'));
127
+ // 2026-08-12: 手机端 UI (微信风格, Capacitor webview 加载) — 纯静态复制
128
+ await fs.copyFile(path.join(ROOT, 'src/web/mobile.html'), path.join(DIST_WEB, 'mobile.html'));
129
+ await fs.copyFile(path.join(ROOT, 'src/web/mobile.css'), path.join(DIST_WEB, 'mobile.css'));
130
+ await fs.copyFile(path.join(ROOT, 'src/web/mobile.js'), path.join(DIST_WEB, 'mobile.js'));
131
+ // 复制 PWA manifest (index.html 里有 <link rel="manifest">, 否则浏览器会 404)
132
+ await fs.copyFile(path.join(ROOT, 'src/web/manifest.json'), path.join(DIST_WEB, 'manifest.json'));
133
+ // 复制 icons 目录 (manifest.json 里引用了 favicon 等)
134
+ await fs.cp(path.join(ROOT, 'src/web/icons'), path.join(DIST_WEB, 'icons'), { recursive: true });
135
+
136
+ // 复制 system-prompt layer .md 文件到 dist/llm/system-prompt/layers/
137
+ // 原因: tsc 不复制 .md, src/llm/system-prompt/layers/{core,role,channel,tool}/*.md
138
+ // 在 dist 里完全不存在, registry.ts 用 __dirname + 'layers' 读它们时 100% ENOENT.
139
+ // 这里全量复制 25 .md, 不过滤 'never' 层 — registry.matchesContext 已做过滤.
140
+ const srcLayers = path.join(ROOT, 'src/llm/system-prompt/layers');
141
+ const dstLayers = path.join(ROOT, 'dist/llm/system-prompt/layers');
142
+ await fs.cp(srcLayers, dstLayers, { recursive: true });
143
+ console.log('[build-web] system-prompt layers copied →', path.relative(ROOT, dstLayers));
144
+
145
+ // 复制 components/ 下的独立 ESM 模块 (非 p2p 那些, 已被 esbuild 单独编译)
146
+ // 例如 wallet-viem.mjs: 浏览器侧 viem 封装, 被 index.html 引用
147
+ const extraComponentsDir = path.join(ROOT, 'src/web/components');
148
+ for (const entry of await fs.readdir(extraComponentsDir)) {
149
+ if (entry === 'p2p') continue;
150
+ const src = path.join(extraComponentsDir, entry);
151
+ const dest = path.join(DIST_WEB, 'components', entry);
152
+ const stat = await fs.stat(src);
153
+ if (stat.isFile()) {
154
+ await fs.mkdir(path.dirname(dest), { recursive: true });
155
+ await fs.copyFile(src, dest);
156
+ }
157
+ }
158
+
159
+ console.log('[build-web] 完成!');
160
+ }
161
+
162
+ main().catch(console.error);
@@ -1,153 +1,153 @@
1
- /**
2
- * Postinstall 脚本
3
- * npm 安装后自动执行
4
- *
5
- * 主要任务:
6
- * 1. 确保 bin 目录存在且可执行
7
- * 2. 初始化本地配置
8
- * 3. 检查依赖完整性
9
- */
10
-
11
- import * as fs from 'fs';
12
- import * as path from 'path';
13
- import { fileURLToPath } from 'url';
14
-
15
- const __filename = fileURLToPath(import.meta.url);
16
- const __dirname = path.dirname(__filename);
17
- const rootDir = path.join(__dirname, '..');
18
-
19
- const RESET = '\x1b[0m';
20
- const GREEN = '\x1b[32m';
21
- const YELLOW = '\x1b[33m';
22
- const CYAN = '\x1b[36m';
23
-
24
- function log(msg, color = RESET) {
25
- console.log(color + msg + RESET);
26
- }
27
-
28
- function initUserDirs() {
29
- // 创建用户数据目录
30
- const home = process.env.HOME || process.env.USERPROFILE || '/tmp';
31
- const bolloonDir = path.join(home, '.bolloon');
32
-
33
- const dirs = [
34
- bolloonDir,
35
- path.join(bolloonDir, 'sessions'),
36
- path.join(bolloonDir, 'peer-store'),
37
- ];
38
-
39
- for (const dir of dirs) {
40
- if (!fs.existsSync(dir)) {
41
- fs.mkdirSync(dir, { recursive: true });
42
- log(` ✓ 创建目录: ${dir}`, GREEN);
43
- }
44
- }
45
-
46
- // 初始化配置文件
47
- const configPath = path.join(bolloonDir, 'config.json');
48
- if (!fs.existsSync(configPath)) {
49
- const defaultConfig = {
50
- version: '0.1.12',
51
- initializedAt: new Date().toISOString(),
52
- defaults: {
53
- port: 54188,
54
- theme: 'dark',
55
- autoConnect: true,
56
- },
57
- providers: {
58
- minimax: { enabled: false },
59
- openai: { enabled: false },
60
- anthropic: { enabled: false },
61
- }
62
- };
63
- fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
64
- log(` ✓ 创建配置: ${configPath}`, GREEN);
65
- }
66
-
67
- return bolloonDir;
68
- }
69
-
70
- function checkNativeDeps() {
71
- // 检查必要的原生依赖
72
- const nativeDeps = [
73
- 'libp2p',
74
- '@diap/sdk',
75
- ];
76
-
77
- let allOk = true;
78
-
79
- for (const dep of nativeDeps) {
80
- const depPath = path.join(rootDir, 'node_modules', dep);
81
- if (!fs.existsSync(depPath)) {
82
- log(` ⚠ 缺少依赖: ${dep}`, YELLOW);
83
- allOk = false;
84
- }
85
- }
86
-
87
- return allOk;
88
- }
89
-
90
- function setupPlatform() {
91
- const platform = process.platform;
92
-
93
- log(`\n 平台: ${platform}`, CYAN);
94
-
95
- if (platform === 'win32') {
96
- // Windows: 确保 .cmd 文件存在
97
- const binDir = path.join(rootDir, 'bin');
98
- const cmdPath = path.join(binDir, 'bolloon.cmd');
99
-
100
- if (fs.existsSync(binDir) && !fs.existsSync(cmdPath)) {
101
- const cmdContent = `@echo off
102
- node "%~dp0..\\dist\\cli.js" %*
103
- `;
104
- fs.writeFileSync(cmdPath, cmdContent);
105
- log(' ✓ Windows 入口已创建', GREEN);
106
- }
107
- } else {
108
- // Unix/Linux/Mac: 确保 bin 文件可执行
109
- const binDir = path.join(rootDir, 'bin');
110
- const binPath = path.join(binDir, 'bolloon.js');
111
-
112
- if (fs.existsSync(binPath)) {
113
- try {
114
- fs.chmodSync(binPath, 0o755);
115
- log(' ✓ bin/bolloon.js 已设为可执行', GREEN);
116
- } catch (err) {
117
- log(` ⚠ 无法设置执行权限: ${err.message}`, YELLOW);
118
- }
119
- }
120
- }
121
- }
122
-
123
- function main() {
124
- console.log('\n📦 Bolloon 安装后处理...\n');
125
-
126
- try {
127
- // 1. 初始化用户目录
128
- const bolloonDir = initUserDirs();
129
- log(` ✓ 用户数据目录: ${bolloonDir}`, GREEN);
130
-
131
- // 2. 检查依赖
132
- const depsOk = checkNativeDeps();
133
- if (!depsOk) {
134
- log('\n ⚠ 部分依赖缺失,建议运行: npm install', YELLOW);
135
- }
136
-
137
- // 3. 平台特定设置
138
- setupPlatform();
139
-
140
- console.log('\n✅ 安装完成!\n');
141
- console.log(' 使用方式:');
142
- console.log(' bolloon # 启动 GUI');
143
- console.log(' bolloon --web # 启动 Web UI');
144
- console.log(' bolloon --cli # 命令行模式');
145
- console.log(' bolloon --help # 显示帮助\n');
146
- console.log(` 配置文件: ${path.join(bolloonDir, 'config.json')}\n`);
147
- } catch (err) {
148
- console.error('\n❌ 安装后处理失败:', err.message);
149
- console.error(' 这通常不影响基本功能,继续安装...\n');
150
- }
151
- }
152
-
1
+ /**
2
+ * Postinstall 脚本
3
+ * npm 安装后自动执行
4
+ *
5
+ * 主要任务:
6
+ * 1. 确保 bin 目录存在且可执行
7
+ * 2. 初始化本地配置
8
+ * 3. 检查依赖完整性
9
+ */
10
+
11
+ import * as fs from 'fs';
12
+ import * as path from 'path';
13
+ import { fileURLToPath } from 'url';
14
+
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = path.dirname(__filename);
17
+ const rootDir = path.join(__dirname, '..');
18
+
19
+ const RESET = '\x1b[0m';
20
+ const GREEN = '\x1b[32m';
21
+ const YELLOW = '\x1b[33m';
22
+ const CYAN = '\x1b[36m';
23
+
24
+ function log(msg, color = RESET) {
25
+ console.log(color + msg + RESET);
26
+ }
27
+
28
+ function initUserDirs() {
29
+ // 创建用户数据目录
30
+ const home = process.env.HOME || process.env.USERPROFILE || '/tmp';
31
+ const bolloonDir = path.join(home, '.bolloon');
32
+
33
+ const dirs = [
34
+ bolloonDir,
35
+ path.join(bolloonDir, 'sessions'),
36
+ path.join(bolloonDir, 'peer-store'),
37
+ ];
38
+
39
+ for (const dir of dirs) {
40
+ if (!fs.existsSync(dir)) {
41
+ fs.mkdirSync(dir, { recursive: true });
42
+ log(` ✓ 创建目录: ${dir}`, GREEN);
43
+ }
44
+ }
45
+
46
+ // 初始化配置文件
47
+ const configPath = path.join(bolloonDir, 'config.json');
48
+ if (!fs.existsSync(configPath)) {
49
+ const defaultConfig = {
50
+ version: '0.1.12',
51
+ initializedAt: new Date().toISOString(),
52
+ defaults: {
53
+ port: 54188,
54
+ theme: 'dark',
55
+ autoConnect: true,
56
+ },
57
+ providers: {
58
+ minimax: { enabled: false },
59
+ openai: { enabled: false },
60
+ anthropic: { enabled: false },
61
+ }
62
+ };
63
+ fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
64
+ log(` ✓ 创建配置: ${configPath}`, GREEN);
65
+ }
66
+
67
+ return bolloonDir;
68
+ }
69
+
70
+ function checkNativeDeps() {
71
+ // 检查必要的原生依赖
72
+ const nativeDeps = [
73
+ 'libp2p',
74
+ '@diap/sdk',
75
+ ];
76
+
77
+ let allOk = true;
78
+
79
+ for (const dep of nativeDeps) {
80
+ const depPath = path.join(rootDir, 'node_modules', dep);
81
+ if (!fs.existsSync(depPath)) {
82
+ log(` ⚠ 缺少依赖: ${dep}`, YELLOW);
83
+ allOk = false;
84
+ }
85
+ }
86
+
87
+ return allOk;
88
+ }
89
+
90
+ function setupPlatform() {
91
+ const platform = process.platform;
92
+
93
+ log(`\n 平台: ${platform}`, CYAN);
94
+
95
+ if (platform === 'win32') {
96
+ // Windows: 确保 .cmd 文件存在
97
+ const binDir = path.join(rootDir, 'bin');
98
+ const cmdPath = path.join(binDir, 'bolloon.cmd');
99
+
100
+ if (fs.existsSync(binDir) && !fs.existsSync(cmdPath)) {
101
+ const cmdContent = `@echo off
102
+ node "%~dp0..\\dist\\cli.js" %*
103
+ `;
104
+ fs.writeFileSync(cmdPath, cmdContent);
105
+ log(' ✓ Windows 入口已创建', GREEN);
106
+ }
107
+ } else {
108
+ // Unix/Linux/Mac: 确保 bin 文件可执行
109
+ const binDir = path.join(rootDir, 'bin');
110
+ const binPath = path.join(binDir, 'bolloon.js');
111
+
112
+ if (fs.existsSync(binPath)) {
113
+ try {
114
+ fs.chmodSync(binPath, 0o755);
115
+ log(' ✓ bin/bolloon.js 已设为可执行', GREEN);
116
+ } catch (err) {
117
+ log(` ⚠ 无法设置执行权限: ${err.message}`, YELLOW);
118
+ }
119
+ }
120
+ }
121
+ }
122
+
123
+ function main() {
124
+ console.log('\n📦 Bolloon 安装后处理...\n');
125
+
126
+ try {
127
+ // 1. 初始化用户目录
128
+ const bolloonDir = initUserDirs();
129
+ log(` ✓ 用户数据目录: ${bolloonDir}`, GREEN);
130
+
131
+ // 2. 检查依赖
132
+ const depsOk = checkNativeDeps();
133
+ if (!depsOk) {
134
+ log('\n ⚠ 部分依赖缺失,建议运行: npm install', YELLOW);
135
+ }
136
+
137
+ // 3. 平台特定设置
138
+ setupPlatform();
139
+
140
+ console.log('\n✅ 安装完成!\n');
141
+ console.log(' 使用方式:');
142
+ console.log(' bolloon # 启动 GUI');
143
+ console.log(' bolloon --web # 启动 Web UI');
144
+ console.log(' bolloon --cli # 命令行模式');
145
+ console.log(' bolloon --help # 显示帮助\n');
146
+ console.log(` 配置文件: ${path.join(bolloonDir, 'config.json')}\n`);
147
+ } catch (err) {
148
+ console.error('\n❌ 安装后处理失败:', err.message);
149
+ console.error(' 这通常不影响基本功能,继续安装...\n');
150
+ }
151
+ }
152
+
153
153
  main();