@bolloon/bolloon-agent 0.1.34 → 0.1.36

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 (226) hide show
  1. package/.auto-evolve-calls +1 -0
  2. package/.last-auto-evolve-baseline +1 -0
  3. package/.playwright-mcp/page-2026-06-16T07-51-45-706Z.yml +130 -0
  4. package/.playwright-mcp/page-2026-06-16T07-56-44-116Z.yml +131 -0
  5. package/Bolloon.md +144 -0
  6. package/Dive-into/CITATION.cff +17 -0
  7. package/Dive-into/LICENSE +25 -0
  8. package/Dive-into/README.md +598 -0
  9. package/Dive-into/README_zh.md +599 -0
  10. package/Dive-into/assets/context.png +0 -0
  11. package/Dive-into/assets/extensibility.png +0 -0
  12. package/Dive-into/assets/iteration.png +0 -0
  13. package/Dive-into/assets/layered_architecture.png +0 -0
  14. package/Dive-into/assets/main_structure.png +0 -0
  15. package/Dive-into/assets/permission.png +0 -0
  16. package/Dive-into/assets/session_compact.png +0 -0
  17. package/Dive-into/assets/subagent.png +0 -0
  18. package/Dive-into/paper/Dive_into_Claude_Code.pdf +0 -0
  19. package/README.md +1 -1
  20. package/dist/agents/p2p-chat-tools.js +6 -6
  21. package/dist/agents/permission-mode.js +115 -0
  22. package/dist/agents/pi-sdk.js +687 -25
  23. package/dist/agents/pre-tool-validator.js +194 -0
  24. package/dist/agents/workflow-pivot-loop.js +113 -12
  25. package/dist/bollharness/src/scripts/checks/check_doc_freshness.js +1 -1
  26. package/dist/bollharness/src/scripts/checks/check_doc_links.js +1 -1
  27. package/dist/bollharness/src/scripts/context_router.js +1 -1
  28. package/dist/bollharness/src/scripts/deploy-guard.js +1 -1
  29. package/dist/bollharness/src/scripts/guard_router.js +1 -1
  30. package/dist/bollharness/src/scripts/hooks/_hook_output.js +1 -1
  31. package/dist/bollharness/src/scripts/hooks/risk-tracker.js +1 -1
  32. package/dist/bollharness-integration/context-router.js +2 -2
  33. package/dist/bollharness-integration/guard-checker.js +1 -1
  34. package/dist/bootstrap/bootstrap.js +117 -0
  35. package/dist/bootstrap/context-collector.js +312 -0
  36. package/dist/bootstrap/context-hierarchy.js +218 -0
  37. package/dist/bootstrap/lifecycle-hooks.js +171 -0
  38. package/dist/bootstrap/project-context.js +158 -0
  39. package/dist/context-compaction/auto-compact.js +144 -0
  40. package/dist/context-compaction/budget-gate.js +28 -0
  41. package/dist/context-compaction/budget-reduce.js +35 -0
  42. package/dist/context-compaction/context-collapse.js +66 -0
  43. package/dist/context-compaction/index.js +21 -0
  44. package/dist/context-compaction/microcompact.js +51 -0
  45. package/dist/context-compaction/pipeline.js +123 -0
  46. package/dist/context-compaction/snip.js +45 -0
  47. package/dist/context-compaction/token-estimator.js +35 -0
  48. package/dist/context-compaction/types.js +19 -0
  49. package/dist/heartbeat/HealthMonitor.js +3 -2
  50. package/dist/index.js +49 -2
  51. package/dist/llm/llm-judgment-client.js +32 -30
  52. package/dist/llm/pi-ai.js +125 -28
  53. package/dist/llm/system-prompt/health.js +129 -0
  54. package/dist/llm/system-prompt/registry.js +246 -0
  55. package/dist/llm/system-prompt/strip-hibsml.js +51 -0
  56. package/dist/llm/tool-manifest/ask_user_input.js +35 -0
  57. package/dist/llm/tool-manifest/bash.js +23 -0
  58. package/dist/llm/tool-manifest/create_file.js +24 -0
  59. package/dist/llm/tool-manifest/fetch_sports_data.js +26 -0
  60. package/dist/llm/tool-manifest/image_search.js +24 -0
  61. package/dist/llm/tool-manifest/index.js +69 -0
  62. package/dist/llm/tool-manifest/mcp.js +43 -0
  63. package/dist/llm/tool-manifest/message_compose.js +31 -0
  64. package/dist/llm/tool-manifest/places.js +83 -0
  65. package/dist/llm/tool-manifest/present_files.js +21 -0
  66. package/dist/llm/tool-manifest/recipe.js +40 -0
  67. package/dist/llm/tool-manifest/recommend_apps.js +23 -0
  68. package/dist/llm/tool-manifest/str_replace.js +27 -0
  69. package/dist/llm/tool-manifest/types.js +7 -0
  70. package/dist/llm/tool-manifest/view.js +24 -0
  71. package/dist/llm/tool-manifest/weather.js +27 -0
  72. package/dist/llm/tool-manifest/web.js +51 -0
  73. package/dist/network/p2p-direct.js +23 -0
  74. package/dist/network/source-intent-broadcaster.js +203 -0
  75. package/dist/network/source-intent.js +100 -0
  76. package/dist/pi-ecosystem-judgment/adaptive-scan.js +279 -0
  77. package/dist/pi-ecosystem-judgment/causal-judge.js +449 -0
  78. package/dist/pi-ecosystem-judgment/detect-hook.js +168 -0
  79. package/dist/pi-ecosystem-judgment/distill-prompt.js +226 -0
  80. package/dist/pi-ecosystem-judgment/evolve-judgment.js +170 -0
  81. package/dist/pi-ecosystem-judgment/human-value-pipeline.js +21 -0
  82. package/dist/pi-ecosystem-judgment/human-value-store.js +283 -22
  83. package/dist/pi-ecosystem-judgment/injection-gate.js +208 -0
  84. package/dist/pi-ecosystem-judgment/monitor-gate.js +188 -0
  85. package/dist/pi-ecosystem-judgment/value-injection.js +8 -2
  86. package/dist/security/builtin-guards.js +124 -0
  87. package/dist/security/context-router-tool.js +106 -0
  88. package/dist/security/input-scanner.js +223 -0
  89. package/dist/security/react-harness.js +143 -0
  90. package/dist/security/tool-gate.js +235 -0
  91. package/dist/utils/auto-evolve-policy.js +117 -0
  92. package/dist/utils/clamp.js +7 -0
  93. package/dist/utils/double.js +6 -0
  94. package/dist/web/client.js +3810 -3830
  95. package/dist/web/components/p2p/P2PModal.js +188 -0
  96. package/dist/web/components/p2p/index.js +264 -226
  97. package/dist/web/components/p2p/p2p-modal.js +657 -0
  98. package/dist/web/components/p2p/p2p-tools.js +248 -0
  99. package/dist/web/index.html +60 -49
  100. package/dist/web/server.js +827 -124
  101. package/dist/web/style.css +531 -249
  102. package/dist/web/ui/message-renderer.js +463 -0
  103. package/dist/web/ui/step-timeline.js +375 -0
  104. package/lefthook.yml +33 -0
  105. package/package.json +3 -2
  106. package/scripts/auto-evolve-loop.ts +481 -0
  107. package/scripts/auto-evolve-oneshot.sh +155 -0
  108. package/scripts/auto-evolve-snapshot.sh +136 -0
  109. package/scripts/build-web.ts +35 -1
  110. package/scripts/detect-schema-changes.sh +48 -0
  111. package/scripts/diff-reviewer.ts +159 -0
  112. package/scripts/validate-system-prompt.ts +142 -0
  113. package/scripts/weekly-report.ts +364 -0
  114. package/src/agents/p2p-chat-tools.ts +6 -6
  115. package/src/agents/permission-mode.ts +127 -0
  116. package/src/agents/pi-sdk.ts +741 -30
  117. package/src/agents/pre-tool-validator.ts +213 -0
  118. package/src/agents/workflow-pivot-loop.ts +110 -19
  119. package/src/bollharness/CLAUDE.md +1 -1
  120. package/src/bollharness/README.md +2 -2
  121. package/src/bollharness/README.zh-CN.md +2 -2
  122. package/src/bollharness/reference/boll-reference/scripts/hooks/find-boll-root.sh +2 -2
  123. package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +2 -2
  124. package/src/bollharness/scripts/context-fragments/version-sources.md +1 -1
  125. package/src/bollharness/scripts/hooks/find-project-root.sh +4 -4
  126. package/src/bollharness/src/scripts/checks/check_doc_freshness.ts +1 -1
  127. package/src/bollharness/src/scripts/checks/check_doc_links.ts +1 -1
  128. package/src/bollharness/src/scripts/context_router.ts +1 -1
  129. package/src/bollharness/src/scripts/deploy-guard.ts +1 -1
  130. package/src/bollharness/src/scripts/guard_router.ts +1 -1
  131. package/src/bollharness/src/scripts/hooks/_hook_output.ts +1 -1
  132. package/src/bollharness/src/scripts/hooks/risk-tracker.ts +1 -1
  133. package/src/bollharness/templates/scaffold/.gitignore.append +1 -1
  134. package/src/bollharness/templates/scaffold/CLAUDE.md +2 -2
  135. package/src/bollharness-integration/context-router.ts +2 -2
  136. package/src/bollharness-integration/guard-checker.ts +1 -1
  137. package/src/bootstrap/bootstrap.ts +135 -0
  138. package/src/bootstrap/context-collector.ts +371 -0
  139. package/src/bootstrap/context-hierarchy.ts +283 -0
  140. package/src/bootstrap/lifecycle-hooks.ts +289 -0
  141. package/src/bootstrap/project-context.ts +171 -0
  142. package/src/context-compaction/auto-compact.ts +153 -0
  143. package/src/context-compaction/budget-gate.ts +32 -0
  144. package/src/context-compaction/budget-reduce.ts +37 -0
  145. package/src/context-compaction/context-collapse.ts +72 -0
  146. package/src/context-compaction/index.ts +24 -0
  147. package/src/context-compaction/microcompact.ts +54 -0
  148. package/src/context-compaction/pipeline.ts +133 -0
  149. package/src/context-compaction/snip.ts +51 -0
  150. package/src/context-compaction/token-estimator.ts +36 -0
  151. package/src/context-compaction/types.ts +99 -0
  152. package/src/heartbeat/HealthMonitor.ts +3 -2
  153. package/src/index.ts +47 -2
  154. package/src/llm/llm-judgment-client.ts +36 -35
  155. package/src/llm/pi-ai.ts +135 -29
  156. package/src/llm/system-prompt/health.ts +159 -0
  157. package/src/llm/system-prompt/layers/channel/local.md +14 -0
  158. package/src/llm/system-prompt/layers/channel/p2p-agent.md +18 -0
  159. package/src/llm/system-prompt/layers/channel/p2p-visitor.md +19 -0
  160. package/src/llm/system-prompt/layers/core/artifacts_storage.md +89 -0
  161. package/src/llm/system-prompt/layers/core/evenhandedness.md +21 -0
  162. package/src/llm/system-prompt/layers/core/hibs_reminders.md +15 -0
  163. package/src/llm/system-prompt/layers/core/identity.md +37 -0
  164. package/src/llm/system-prompt/layers/core/knowledge.md +17 -0
  165. package/src/llm/system-prompt/layers/core/memory_system.md +12 -0
  166. package/src/llm/system-prompt/layers/core/network_filesystem.md +28 -0
  167. package/src/llm/system-prompt/layers/core/refusal.md +37 -0
  168. package/src/llm/system-prompt/layers/core/tone.md +31 -0
  169. package/src/llm/system-prompt/layers/core/tools.thin.md +13 -0
  170. package/src/llm/system-prompt/layers/core/wellbeing.md +41 -0
  171. package/src/llm/system-prompt/layers/role/architect.md +20 -0
  172. package/src/llm/system-prompt/layers/role/expert.md +19 -0
  173. package/src/llm/system-prompt/layers/role/implementer.md +15 -0
  174. package/src/llm/system-prompt/layers/role/security.md +15 -0
  175. package/src/llm/system-prompt/layers/tool/artifacts.md +72 -0
  176. package/src/llm/system-prompt/layers/tool/bash.md +25 -0
  177. package/src/llm/system-prompt/layers/tool/hibs_api.md +171 -0
  178. package/src/llm/system-prompt/layers/tool/image_search.md +70 -0
  179. package/src/llm/system-prompt/layers/tool/manifest.md +89 -0
  180. package/src/llm/system-prompt/layers/tool/mcp_apps.md +53 -0
  181. package/src/llm/system-prompt/layers/tool/web_search.md +83 -0
  182. package/src/llm/system-prompt/registry.ts +325 -0
  183. package/src/llm/system-prompt/strip-hibsml.ts +52 -0
  184. package/src/llm/tool-manifest/ask_user_input.ts +37 -0
  185. package/src/llm/tool-manifest/bash.ts +25 -0
  186. package/src/llm/tool-manifest/create_file.ts +26 -0
  187. package/src/llm/tool-manifest/fetch_sports_data.ts +28 -0
  188. package/src/llm/tool-manifest/image_search.ts +26 -0
  189. package/src/llm/tool-manifest/index.ts +88 -0
  190. package/src/llm/tool-manifest/mcp.ts +46 -0
  191. package/src/llm/tool-manifest/message_compose.ts +33 -0
  192. package/src/llm/tool-manifest/places.ts +86 -0
  193. package/src/llm/tool-manifest/present_files.ts +23 -0
  194. package/src/llm/tool-manifest/recipe.ts +42 -0
  195. package/src/llm/tool-manifest/recommend_apps.ts +25 -0
  196. package/src/llm/tool-manifest/str_replace.ts +29 -0
  197. package/src/llm/tool-manifest/types.ts +52 -0
  198. package/src/llm/tool-manifest/view.ts +26 -0
  199. package/src/llm/tool-manifest/weather.ts +29 -0
  200. package/src/llm/tool-manifest/web.ts +54 -0
  201. package/src/network/p2p-direct.ts +22 -0
  202. package/src/network/source-intent-broadcaster.ts +242 -0
  203. package/src/network/source-intent.ts +167 -0
  204. package/src/security/builtin-guards.ts +162 -0
  205. package/src/security/context-router-tool.ts +122 -0
  206. package/src/security/input-scanner.ts +287 -0
  207. package/src/security/react-harness.ts +177 -0
  208. package/src/security/tool-gate.ts +294 -0
  209. package/src/utils/auto-evolve-policy.ts +138 -0
  210. package/src/utils/clamp.ts +5 -0
  211. package/src/web/client.js +105 -2187
  212. package/src/web/client.ts +4326 -0
  213. package/src/web/index.html +60 -49
  214. package/src/web/server.ts +894 -148
  215. package/src/web/style.css +531 -249
  216. package/src/web/ui/message-renderer.ts +540 -0
  217. package/src/web/ui/step-timeline.ts +394 -0
  218. package/staging/auto-evolve/clean-001/.review-verdict +9 -0
  219. package/staging/auto-evolve/clean-001/clean-001.patch +14 -0
  220. package/staging/auto-evolve/e2e-001/.patch-id +1 -0
  221. package/staging/auto-evolve/e2e-001/.review-verdict +12 -0
  222. package/staging/auto-evolve/e2e-001/e2e-001.patch +11 -0
  223. package/staging/auto-evolve/test-bad/.review-verdict +12 -0
  224. package/staging/auto-evolve/test-bad/test-bad.patch +11 -0
  225. package/test-results/.last-run.json +6 -0
  226. package/test-results/src-test-web-loop-status-b-5734c-atus-bar-/346/230/276/347/244/272-spinner-/344/270/215/346/230/276/347/244/272/345/276/252/347/216/257/350/256/241/346/225/260/error-context.md +285 -0
@@ -0,0 +1,285 @@
1
+ # Instructions
2
+
3
+ - Following Playwright test failed.
4
+ - Explain why, be concise, respect Playwright best practices.
5
+ - Provide a snippet of code with the fix, if possible.
6
+
7
+ # Test info
8
+
9
+ - Name: src/test/web-loop-status-bar.spec.ts >> loop-status-bar 三态机 >> 1. loading 态: status bar 显示 spinner, 不显示循环计数
10
+ - Location: src/test/web-loop-status-bar.spec.ts:149:3
11
+
12
+ # Error details
13
+
14
+ ```
15
+ Error: expect(locator).toBeVisible() failed
16
+
17
+ Locator: locator('#loop-status-bar')
18
+ Expected: visible
19
+ Received: hidden
20
+ Timeout: 5000ms
21
+
22
+ Call log:
23
+ - Expect "toBeVisible" with timeout 5000ms
24
+ - waiting for locator('#loop-status-bar')
25
+ 14 × locator resolved to <div hidden="" id="loop-status-bar" data-state="loading" class="loop-status-bar">…</div>
26
+ - unexpected value "hidden"
27
+
28
+ ```
29
+
30
+ ```yaml
31
+ - complementary:
32
+ - button "收起侧边栏":
33
+ - img
34
+ - text: ◈ Bolloon 智能体
35
+ - button "新建智能体":
36
+ - img
37
+ - text: 新建智能体
38
+ - list:
39
+ - listitem:
40
+ - img
41
+ - text: 💬 Loop Bar Channel
42
+ - button "配置智能体 (钱包 / 工具)":
43
+ - img
44
+ - button "×"
45
+ - list
46
+ - text: ▼ P2P 好友
47
+ - button "⊞ 展开"
48
+ - button "我的 ID"
49
+ - button "+ 好友"
50
+ - list:
51
+ - listitem: (暂无好友, 点 + 添加)
52
+ - text: 已连接
53
+ - main:
54
+ - heading "Loop Bar Channel" [level=1]
55
+ - button "切换主题":
56
+ - img
57
+ - button "API 配置":
58
+ - img
59
+ - button "钱包管理":
60
+ - img
61
+ - button "我的判断":
62
+ - img
63
+ - text: 你好!我是 Bolloon Agent。有什么我可以帮你的吗? 执行步骤 ▾
64
+ - list
65
+ - button "复制":
66
+ - img
67
+ - text: 复制
68
+ - button "蒸馏为判断":
69
+ - img
70
+ - text: 蒸馏为判断
71
+ - button "重新回答":
72
+ - img
73
+ - text: 重新回答
74
+ - text: 16:53
75
+ - textbox "输入消息..."
76
+ - button "发送 (Enter)":
77
+ - img
78
+ ```
79
+
80
+ # Test source
81
+
82
+ ```ts
83
+ 69 | const safePath = pathname === '/' ? '/index.html' : pathname;
84
+ 70 | const filePath = path.join(WEB_ROOT, safePath);
85
+ 71 | if (!filePath.startsWith(WEB_ROOT)) {
86
+ 72 | res.writeHead(403);
87
+ 73 | res.end('Forbidden');
88
+ 74 | return;
89
+ 75 | }
90
+ 76 | try {
91
+ 77 | const body = await readFile(filePath);
92
+ 78 | const ext = path.extname(filePath);
93
+ 79 | res.writeHead(200, { 'Content-Type': contentTypes[ext] || 'application/octet-stream' });
94
+ 80 | res.end(body);
95
+ 81 | } catch {
96
+ 82 | res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
97
+ 83 | res.end('Not found');
98
+ 84 | }
99
+ 85 | }
100
+ 86 |
101
+ 87 | type MockServer = { server: ReturnType<typeof createServer>; clients: Set<SseClient>; port: number };
102
+ 88 |
103
+ 89 | function startMockServer(extraSetup?: (clients: Set<SseClient>) => void): Promise<MockServer> {
104
+ 90 | const clients = new Set<SseClient>();
105
+ 91 | const server = createServer(async (req, res) => {
106
+ 92 | const url = new URL(req.url || '/', `http://localhost`);
107
+ 93 | const pathname = url.pathname;
108
+ 94 |
109
+ 95 | if (pathname === '/events' || pathname.startsWith('/events')) {
110
+ 96 | const channelId = url.searchParams.get('channelId') || CHANNEL_ID;
111
+ 97 | sse(res);
112
+ 98 | const client: SseClient = { channelId, res };
113
+ 99 | clients.add(client);
114
+ 100 | req.on('close', () => clients.delete(client));
115
+ 101 | setTimeout(() => writeEvent(client, { type: 'ping' }), 100);
116
+ 102 | return;
117
+ 103 | }
118
+ 104 |
119
+ 105 | if (pathname === '/channels') return json(res, [defaultChannel]);
120
+ 106 | if (pathname === `/channels/${CHANNEL_ID}/sessions`) {
121
+ 107 | return json(res, { session: { id: 'sess-1' }, currentSessionId: 'sess-1' });
122
+ 108 | }
123
+ 109 | if (pathname === '/theme') return json(res, { theme: 'dark', agentId: 'agent_loop' });
124
+ 110 | if (pathname === '/api/remote-channels') return json(res, { peers: [] });
125
+ 111 | if (pathname.startsWith('/sessions/')) {
126
+ 112 | res.writeHead(200, { 'Content-Type': 'application/json' });
127
+ 113 | return res.end(JSON.stringify({ ok: true }));
128
+ 114 | }
129
+ 115 | if (pathname === '/api/loop/inspect') {
130
+ 116 | return json(res, {
131
+ 117 | summary: 'loop 完成 (mock): 跑了 3 个步骤',
132
+ 118 | steps: [
133
+ 119 | { name: 'shell_exec: echo 1', status: 'ok', durationMs: 320, output: '1' },
134
+ 120 | { name: 'shell_exec: echo 2', status: 'ok', durationMs: 280, output: '2' },
135
+ 121 | { name: 'shell_exec: echo 3', status: 'ok', durationMs: 250, output: '3' },
136
+ 122 | ],
137
+ 123 | finalReply: '已完成 3 步',
138
+ 124 | tokens: { input: 1200, output: 80 },
139
+ 125 | });
140
+ 126 | }
141
+ 127 | if (pathname === '/message' && req.method === 'POST') {
142
+ 128 | let body = '';
143
+ 129 | req.on('data', (chunk) => { body += chunk; });
144
+ 130 | req.on('end', () => json(res, { ok: true, reply: 'mock' }));
145
+ 131 | return;
146
+ 132 | }
147
+ 133 |
148
+ 134 | return serveStatic(res, pathname);
149
+ 135 | });
150
+ 136 |
151
+ 137 | if (extraSetup) extraSetup(clients);
152
+ 138 |
153
+ 139 | return new Promise<MockServer>((resolve) => {
154
+ 140 | server.listen(0, '127.0.0.1', () => {
155
+ 141 | const addr = server.address();
156
+ 142 | const port = typeof addr === 'object' && addr ? addr.port : 0;
157
+ 143 | resolve({ server, clients, port });
158
+ 144 | });
159
+ 145 | });
160
+ 146 | }
161
+ 147 |
162
+ 148 | test.describe.serial('loop-status-bar 三态机', () => {
163
+ 149 | test('1. loading 态: status bar 显示 spinner, 不显示循环计数', async () => {
164
+ 150 | const { server, port } = await startMockServer((clients) => {
165
+ 151 | setTimeout(() => {
166
+ 152 | const ch = [...clients].find((c) => c.channelId === CHANNEL_ID);
167
+ 153 | if (!ch) return;
168
+ 154 | writeEvent(ch, { channelId: CHANNEL_ID, type: 'status', tool: 'system', content: '🔄 开始 ReAct 循环...' });
169
+ 155 | }, 500);
170
+ 156 | });
171
+ 157 | try {
172
+ 158 | const { chromium } = await import('@playwright/test');
173
+ 159 | const ctx = await chromium.launch();
174
+ 160 | const page = await ctx.newPage();
175
+ 161 | page.on('console', (msg) => {
176
+ 162 | if (msg.type() === 'error') console.log('[test1 console err]', msg.text());
177
+ 163 | });
178
+ 164 | await page.goto(`http://127.0.0.1:${port}/`);
179
+ 165 | await page.waitForSelector('#input', { timeout: 5000 }).catch(() => {});
180
+ 166 | await page.waitForTimeout(2500);
181
+ 167 |
182
+ 168 | const bar = page.locator('#loop-status-bar');
183
+ > 169 | await expect(bar).toBeVisible();
184
+ | ^ Error: expect(locator).toBeVisible() failed
185
+ 170 | await expect(bar).toHaveAttribute('data-state', 'loading');
186
+ 171 | const text = await bar.textContent();
187
+ 172 | expect(text).not.toMatch(/\d+\/\d+/);
188
+ 173 | await ctx.close();
189
+ 174 | } finally {
190
+ 175 | server.close();
191
+ 176 | }
192
+ 177 | });
193
+ 178 |
194
+ 179 | test('2. retrying 态: 自动重试徽章出现, 无重试按钮', async () => {
195
+ 180 | const { server, port } = await startMockServer((clients) => {
196
+ 181 | setTimeout(() => {
197
+ 182 | const ch = [...clients].find((c) => c.channelId === CHANNEL_ID);
198
+ 183 | if (!ch) return;
199
+ 184 | writeEvent(ch, { channelId: CHANNEL_ID, type: 'status', tool: 'system', content: '↻ 自动重试 loop 1/3 (1s 后)' });
200
+ 185 | }, 800);
201
+ 186 | });
202
+ 187 | try {
203
+ 188 | const { chromium } = await import('@playwright/test');
204
+ 189 | const ctx = await chromium.launch();
205
+ 190 | const page = await ctx.newPage();
206
+ 191 | page.on('console', (msg) => {
207
+ 192 | if (msg.type() === 'error') console.log('[test2 console err]', msg.text());
208
+ 193 | });
209
+ 194 | await page.goto(`http://127.0.0.1:${port}/`);
210
+ 195 | await page.waitForSelector('#input', { timeout: 5000 }).catch(() => {});
211
+ 196 | await page.waitForTimeout(2500);
212
+ 197 |
213
+ 198 | const bar = page.locator('#loop-status-bar');
214
+ 199 | await expect(bar).toHaveAttribute('data-state', 'retrying');
215
+ 200 |
216
+ 201 | const retry = page.locator('#loop-status-retry');
217
+ 202 | await expect(retry).toBeVisible();
218
+ 203 | const retryText = await retry.textContent();
219
+ 204 | expect(retryText).toMatch(/自动重试\s+1\/3/);
220
+ 205 |
221
+ 206 | const tagName = await retry.evaluate((el) => el.tagName.toLowerCase());
222
+ 207 | expect(tagName).toBe('span');
223
+ 208 | await ctx.close();
224
+ 209 | } finally {
225
+ 210 | server.close();
226
+ 211 | }
227
+ 212 | });
228
+ 213 |
229
+ 214 | test('3. done 态: 检查按钮出现, 重试徽章隐藏', async () => {
230
+ 215 | const { server, port } = await startMockServer((clients) => {
231
+ 216 | setTimeout(() => {
232
+ 217 | const ch = [...clients].find((c) => c.channelId === CHANNEL_ID);
233
+ 218 | if (!ch) return;
234
+ 219 | writeEvent(ch, { channelId: CHANNEL_ID, type: 'status', tool: 'system', content: '🔄 循环中' });
235
+ 220 | setTimeout(() => {
236
+ 221 | writeEvent(ch, { channelId: CHANNEL_ID, type: 'done', content: '' });
237
+ 222 | }, 600);
238
+ 223 | }, 800);
239
+ 224 | });
240
+ 225 | try {
241
+ 226 | const { chromium } = await import('@playwright/test');
242
+ 227 | const ctx = await chromium.launch();
243
+ 228 | const page = await ctx.newPage();
244
+ 229 | page.on('console', (msg) => {
245
+ 230 | if (msg.type() === 'error') console.log('[test3 console err]', msg.text());
246
+ 231 | });
247
+ 232 | await page.goto(`http://127.0.0.1:${port}/`);
248
+ 233 | await page.waitForSelector('#input', { timeout: 5000 }).catch(() => {});
249
+ 234 | await page.waitForTimeout(2500);
250
+ 235 |
251
+ 236 | const bar = page.locator('#loop-status-bar');
252
+ 237 | await expect(bar).toHaveAttribute('data-state', 'done');
253
+ 238 |
254
+ 239 | const checkBtn = page.locator('#loop-status-check');
255
+ 240 | await expect(checkBtn).toBeVisible();
256
+ 241 | await expect(checkBtn).toHaveText(/检查/);
257
+ 242 |
258
+ 243 | const retry = page.locator('#loop-status-retry');
259
+ 244 | await expect(retry).toBeHidden();
260
+ 245 | await ctx.close();
261
+ 246 | } finally {
262
+ 247 | server.close();
263
+ 248 | }
264
+ 249 | });
265
+ 250 |
266
+ 251 | test('4. 点检查按钮 → 弹 modal 列出 step 输出', async () => {
267
+ 252 | const { server, port } = await startMockServer((clients) => {
268
+ 253 | setTimeout(() => {
269
+ 254 | const ch = [...clients].find((c) => c.channelId === CHANNEL_ID);
270
+ 255 | if (!ch) return;
271
+ 256 | writeEvent(ch, { channelId: CHANNEL_ID, type: 'status', tool: 'system', content: '🔄 循环中' });
272
+ 257 | setTimeout(() => {
273
+ 258 | writeEvent(ch, { channelId: CHANNEL_ID, type: 'done', content: '' });
274
+ 259 | }, 600);
275
+ 260 | }, 800);
276
+ 261 | });
277
+ 262 | try {
278
+ 263 | const { chromium } = await import('@playwright/test');
279
+ 264 | const ctx = await chromium.launch();
280
+ 265 | const page = await ctx.newPage();
281
+ 266 | page.on('console', (msg) => {
282
+ 267 | if (msg.type() === 'error') console.log('[test4 console err]', msg.text());
283
+ 268 | });
284
+ 269 | await page.goto(`http://127.0.0.1:${port}/`);
285
+ ```