micro-models-agent 2.11.0 → 2.13.1

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 (356) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/assets/app.js +22 -2
  3. package/dist/assets/index.html +39 -9
  4. package/dist/assets/js/dom.js +15 -0
  5. package/dist/assets/js/feed.js +129 -10
  6. package/dist/assets/js/sidebar.js +512 -0
  7. package/dist/assets/js/tabs.js +30 -5
  8. package/dist/assets/setup.js +267 -8
  9. package/dist/assets/styles.css +168 -3
  10. package/dist/cli/cache-line.js +1 -0
  11. package/dist/cli/command-suggest.js +5 -4
  12. package/dist/cli/commands.js +231 -122
  13. package/dist/cli/completer.js +132 -31
  14. package/dist/cli/index.js +1 -0
  15. package/dist/cli/json-payload.js +4 -4
  16. package/dist/cli/main.js +166 -61
  17. package/dist/cli/onboarding-commands.js +126 -0
  18. package/dist/cli/plugin-commands.js +2 -1
  19. package/dist/cli/relaunch.js +16 -13
  20. package/dist/cli/repl-commands-lsp.js +75 -0
  21. package/dist/cli/repl-commands-skills.js +105 -0
  22. package/dist/cli/repl-commands.js +589 -266
  23. package/dist/cli/repl.js +436 -177
  24. package/dist/cli/run-result.js +5 -6
  25. package/dist/cli/security-commands.js +37 -28
  26. package/dist/cli/setup-order.js +4 -55
  27. package/dist/cli/setup-prompt.js +3 -2
  28. package/dist/cli/setup.js +27 -107
  29. package/dist/cli/web-command.js +98 -0
  30. package/dist/config/budget.js +5 -5
  31. package/dist/config/config.js +103 -96
  32. package/dist/config/defaults.js +38 -8
  33. package/dist/config/domains.js +24 -27
  34. package/dist/config/env.js +46 -0
  35. package/dist/config/experts.js +2 -0
  36. package/dist/config/index.js +1 -0
  37. package/dist/config/paths.js +56 -0
  38. package/dist/config/redact.js +44 -0
  39. package/dist/config/registry-extra.js +334 -0
  40. package/dist/config/registry.js +584 -0
  41. package/dist/config/security.js +35 -36
  42. package/dist/config/timeouts.js +74 -0
  43. package/dist/config/utils.js +16 -15
  44. package/dist/core/agent/artifact-progress.js +59 -0
  45. package/dist/core/agent/artifact-resolve.js +79 -0
  46. package/dist/core/agent/audit-gate.js +7 -3
  47. package/dist/core/agent/compaction.js +2 -2
  48. package/dist/core/agent/constants.js +33 -4
  49. package/dist/core/agent/context-log.js +454 -0
  50. package/dist/core/agent/context-renderer.js +5 -0
  51. package/dist/core/agent/critic-gate.js +132 -0
  52. package/dist/core/agent/hallucination-gate.js +148 -38
  53. package/dist/core/agent/loop-state.js +15 -0
  54. package/dist/core/agent/prefix-monitor.js +1 -1
  55. package/dist/core/agent/reasoning-resolver.js +10 -1
  56. package/dist/core/agent/token-tracker.js +7 -4
  57. package/dist/core/agent/tool-batch.js +93 -18
  58. package/dist/core/agent/tool-images.js +18 -0
  59. package/dist/core/agent/tool-output.js +65 -11
  60. package/dist/core/agent/tool-pairing.js +60 -0
  61. package/dist/core/agent-moe.js +25 -24
  62. package/dist/core/agent.js +429 -108
  63. package/dist/core/bootstrap/agent-phase.js +66 -0
  64. package/dist/core/bootstrap/config-phase.js +86 -0
  65. package/dist/core/bootstrap/modules-phase.js +269 -0
  66. package/dist/core/bootstrap/provider-phase.js +183 -0
  67. package/dist/core/bootstrap/session-phase.js +204 -0
  68. package/dist/core/bootstrap/state.js +94 -0
  69. package/dist/core/bootstrap/workspace-phase.js +115 -0
  70. package/dist/core/bootstrap.js +92 -660
  71. package/dist/core/crash-handler.js +17 -7
  72. package/dist/core/environment.js +37 -12
  73. package/dist/core/host-plan.js +43 -0
  74. package/dist/core/host.js +23 -0
  75. package/dist/core/index.js +1 -0
  76. package/dist/core/prompt-builder.js +17 -1
  77. package/dist/core/prompt-overflow.js +42 -43
  78. package/dist/core/session-logger.js +122 -30
  79. package/dist/core/system-prompt.js +117 -0
  80. package/dist/core/version.js +6 -4
  81. package/dist/core/web-host.js +34 -0
  82. package/dist/core/workspace.js +19 -15
  83. package/dist/i18n/en.json +89 -3
  84. package/dist/i18n/index.js +37 -3
  85. package/dist/i18n/ru.json +89 -3
  86. package/dist/index.js +7 -3
  87. package/dist/llm/image-utils.js +55 -64
  88. package/dist/llm/llm-errors.js +9 -0
  89. package/dist/llm/model-loader.js +10 -32
  90. package/dist/llm/models-dev.js +121 -0
  91. package/dist/llm/openai-compat.js +146 -73
  92. package/dist/llm/orchestrator.js +33 -11
  93. package/dist/llm/provider-budget.js +2 -2
  94. package/dist/llm/provider-context.js +233 -0
  95. package/dist/llm/provider.js +1 -1
  96. package/dist/llm/response.js +5 -0
  97. package/dist/llm/token-counter.js +27 -11
  98. package/dist/logger/app-logger.js +48 -22
  99. package/dist/logger/file-log.js +28 -19
  100. package/dist/logger/index.js +1 -0
  101. package/dist/main.js +888 -139
  102. package/dist/migration/backup.js +14 -3
  103. package/dist/migration/detect.js +12 -3
  104. package/dist/migration/index.js +1 -0
  105. package/dist/modules/artifacts/store.js +9 -8
  106. package/dist/modules/browser/actions.js +6 -0
  107. package/dist/modules/browser/bridge-client.js +14 -12
  108. package/dist/modules/browser/bridge-path.js +4 -4
  109. package/dist/modules/browser/console-buffer.js +37 -0
  110. package/dist/modules/browser/cookie-store.js +5 -0
  111. package/dist/modules/browser/driver-types.js +1 -0
  112. package/dist/modules/browser/driver.js +19 -11
  113. package/dist/modules/browser/index.js +3 -1
  114. package/dist/modules/browser/module.js +2 -1
  115. package/dist/modules/browser/session.js +10 -30
  116. package/dist/modules/browser/snapshot.js +19 -13
  117. package/dist/modules/browser/types.js +1 -0
  118. package/dist/modules/certification/cli.js +28 -20
  119. package/dist/modules/certification/fact-checker.js +9 -1
  120. package/dist/modules/certification/loader.js +9 -2
  121. package/dist/modules/certification/manifest.js +83 -21
  122. package/dist/modules/certification/runner.js +23 -13
  123. package/dist/modules/certification/scenarios.js +20 -20
  124. package/dist/modules/certification/syntax-scenarios.js +1 -2
  125. package/dist/modules/context/chunk-query.js +11 -9
  126. package/dist/modules/context/fact-extractor.js +37 -39
  127. package/dist/modules/context/index.js +1 -0
  128. package/dist/modules/context/manager.js +106 -80
  129. package/dist/modules/critic/client.js +176 -0
  130. package/dist/modules/critic/evidence.js +81 -0
  131. package/dist/modules/critic/provider.js +45 -0
  132. package/dist/modules/critic/tools.js +78 -0
  133. package/dist/modules/critic/types.js +1 -0
  134. package/dist/modules/execution/audit-runners.js +28 -34
  135. package/dist/modules/execution/auditor.js +53 -49
  136. package/dist/modules/execution/execution-plugin.js +142 -102
  137. package/dist/modules/execution/index.js +1 -1
  138. package/dist/modules/execution/input-from.js +37 -13
  139. package/dist/modules/execution/module.js +368 -191
  140. package/dist/modules/execution/moe-executor.js +53 -26
  141. package/dist/modules/execution/plan-actions.js +320 -202
  142. package/dist/modules/execution/plan-checks.js +35 -0
  143. package/dist/modules/execution/plan-coverage.js +36 -33
  144. package/dist/modules/execution/plan-steps.js +11 -3
  145. package/dist/modules/execution/plan-store.js +83 -17
  146. package/dist/modules/execution/plan-tool.js +89 -35
  147. package/dist/modules/execution/plan-validator.js +30 -10
  148. package/dist/modules/execution/planner.js +22 -13
  149. package/dist/modules/execution/stuck-detector.js +196 -93
  150. package/dist/modules/execution/tracker.js +22 -8
  151. package/dist/modules/execution/verifier.js +69 -48
  152. package/dist/modules/execution/windows-commands.js +12 -12
  153. package/dist/modules/hallucination/artifact-claim.js +93 -0
  154. package/dist/modules/hallucination/confidence.js +13 -11
  155. package/dist/modules/hallucination/consistency.js +10 -2
  156. package/dist/modules/hallucination/detector.js +10 -5
  157. package/dist/modules/hallucination/factual.js +43 -26
  158. package/dist/modules/hallucination/index.js +1 -0
  159. package/dist/modules/hallucination/js-identifiers.js +44 -45
  160. package/dist/modules/hallucination/llm-judge.js +17 -12
  161. package/dist/modules/hallucination/success-claim.js +59 -0
  162. package/dist/modules/indexer/cache.js +52 -4
  163. package/dist/modules/indexer/index.js +1 -0
  164. package/dist/modules/indexer/map-command.js +2 -4
  165. package/dist/modules/indexer/map-select.js +16 -16
  166. package/dist/modules/indexer/module.js +47 -12
  167. package/dist/modules/indexer/project-profile.js +8 -7
  168. package/dist/modules/indexer/symbols.js +15 -15
  169. package/dist/modules/indexer/walker.js +159 -29
  170. package/dist/modules/lsp/check-tool.js +7 -5
  171. package/dist/modules/lsp/client.js +39 -39
  172. package/dist/modules/lsp/command.js +17 -24
  173. package/dist/modules/lsp/config.js +12 -11
  174. package/dist/modules/lsp/index.js +1 -0
  175. package/dist/modules/lsp/module.js +48 -46
  176. package/dist/modules/lsp/probe.js +13 -14
  177. package/dist/modules/lsp/project-root.js +14 -17
  178. package/dist/modules/lsp/startup-check.js +18 -16
  179. package/dist/modules/mcp/client.js +59 -62
  180. package/dist/modules/mcp/index.js +1 -0
  181. package/dist/modules/mcp/module.js +66 -37
  182. package/dist/modules/mcp/registry.js +5 -0
  183. package/dist/modules/memory/index.js +1 -0
  184. package/dist/modules/memory/module.js +12 -8
  185. package/dist/modules/memory/search.js +4 -1
  186. package/dist/modules/memory/store.js +40 -2
  187. package/dist/modules/onboarding/init.js +47 -0
  188. package/dist/modules/onboarding/meet.js +30 -0
  189. package/dist/modules/onboarding/mode.js +30 -0
  190. package/dist/modules/onboarding/prompts.js +43 -0
  191. package/dist/modules/pipelines/engine.js +10 -0
  192. package/dist/modules/pipelines/index.js +1 -0
  193. package/dist/modules/pipelines/parser.js +4 -1
  194. package/dist/modules/pipelines/template.js +4 -0
  195. package/dist/modules/plugins/builtin/lint-on-write.js +80 -67
  196. package/dist/modules/plugins/builtin/notify.js +2 -0
  197. package/dist/modules/plugins/index.js +1 -0
  198. package/dist/modules/plugins/loader.js +18 -3
  199. package/dist/modules/plugins/manager.js +37 -17
  200. package/dist/modules/pricing/index.js +10 -11
  201. package/dist/modules/pricing/prices.js +12 -12
  202. package/dist/modules/processes/index.js +1 -0
  203. package/dist/modules/processes/kill-tree.js +27 -31
  204. package/dist/modules/processes/registry.js +44 -25
  205. package/dist/modules/processes/runner.js +4 -4
  206. package/dist/modules/providers/capabilities.js +28 -0
  207. package/dist/modules/providers/create.js +3 -4
  208. package/dist/modules/providers/factory.js +7 -7
  209. package/dist/modules/providers/fallback.js +12 -12
  210. package/dist/modules/providers/health.js +4 -4
  211. package/dist/modules/providers/manager.js +50 -19
  212. package/dist/modules/providers/naming.js +15 -0
  213. package/dist/modules/providers/preflight.js +71 -0
  214. package/dist/modules/providers/presets.js +39 -8
  215. package/dist/modules/providers/registry.js +7 -2
  216. package/dist/modules/reasoning/policy.js +8 -6
  217. package/dist/modules/reasoning/probe.js +30 -25
  218. package/dist/modules/security/audit-log.js +19 -36
  219. package/dist/modules/security/audit-notifier.js +35 -75
  220. package/dist/modules/security/command-validator.js +99 -51
  221. package/dist/modules/security/content-scanner.js +8 -8
  222. package/dist/modules/security/data-sanitizer.js +9 -16
  223. package/dist/modules/security/encryption.js +32 -52
  224. package/dist/modules/security/index.js +2 -1
  225. package/dist/modules/security/network-validator.js +120 -43
  226. package/dist/modules/security/path-validator.js +61 -46
  227. package/dist/modules/security/protected-paths.js +73 -0
  228. package/dist/modules/security/rate-limiter.js +17 -49
  229. package/dist/modules/security/security-policies.js +25 -57
  230. package/dist/modules/security/session-encryption.js +32 -71
  231. package/dist/modules/security/session-isolation.js +15 -28
  232. package/dist/modules/session/auto-name.js +63 -0
  233. package/dist/modules/session/export.js +98 -0
  234. package/dist/modules/session/index.js +1 -0
  235. package/dist/modules/session/manager.js +79 -28
  236. package/dist/modules/session/module.js +4 -3
  237. package/dist/modules/session/store.js +57 -20
  238. package/dist/modules/setup/answers.js +35 -0
  239. package/dist/modules/setup/apply.js +79 -0
  240. package/dist/modules/setup/discovery.js +72 -0
  241. package/dist/modules/skills/index.js +1 -0
  242. package/dist/modules/skills/loader.js +9 -1
  243. package/dist/modules/skills/module.js +11 -0
  244. package/dist/modules/updater/changelog-reader.js +15 -16
  245. package/dist/modules/updater/checker.js +9 -4
  246. package/dist/modules/updater/dev-detect.js +7 -6
  247. package/dist/modules/updater/index.js +1 -0
  248. package/dist/modules/updater/module.js +17 -15
  249. package/dist/modules/user-profile/compressor.js +2 -0
  250. package/dist/modules/user-profile/index.js +1 -0
  251. package/dist/modules/user-profile/profile.js +10 -1
  252. package/dist/modules/webui/answer-api.js +29 -0
  253. package/dist/modules/webui/assets.js +50 -0
  254. package/dist/modules/webui/body.js +21 -0
  255. package/dist/modules/webui/commands-settings.js +209 -0
  256. package/dist/modules/webui/commands-shared.js +60 -0
  257. package/dist/modules/webui/commands.js +174 -0
  258. package/dist/modules/webui/config-api.js +134 -0
  259. package/dist/modules/webui/file-api.js +202 -0
  260. package/dist/modules/webui/forward.js +159 -0
  261. package/dist/modules/webui/history-api.js +112 -0
  262. package/dist/modules/webui/host-state.js +60 -0
  263. package/dist/modules/webui/i18n-api.js +9 -0
  264. package/dist/modules/webui/limits.js +6 -0
  265. package/dist/modules/webui/log-forward.js +20 -0
  266. package/dist/modules/webui/memory-commands.js +64 -0
  267. package/dist/modules/webui/model-cache.js +18 -0
  268. package/dist/modules/webui/module.js +148 -0
  269. package/dist/modules/webui/persist.js +24 -0
  270. package/dist/modules/webui/prompt-io.js +97 -0
  271. package/dist/modules/webui/providers-api.js +337 -0
  272. package/dist/modules/webui/providers-view.js +56 -0
  273. package/dist/modules/webui/reasoning-view.js +15 -0
  274. package/dist/modules/webui/run-agent.js +81 -0
  275. package/dist/modules/webui/server.js +284 -0
  276. package/dist/modules/webui/sessions-api.js +178 -0
  277. package/dist/modules/webui/settings-api.js +561 -0
  278. package/dist/modules/webui/setup-api.js +201 -0
  279. package/dist/modules/webui/state.js +74 -0
  280. package/dist/modules/webui/util.js +261 -0
  281. package/dist/output/bus.js +7 -2
  282. package/dist/output/channel.js +80 -28
  283. package/dist/output/format.js +2 -1
  284. package/dist/output/index.js +1 -0
  285. package/dist/output/json-sink.js +5 -3
  286. package/dist/output/machine.js +4 -3
  287. package/dist/output/session-sink.js +4 -4
  288. package/dist/tools/approve.js +4 -0
  289. package/dist/tools/attach-image.js +5 -4
  290. package/dist/tools/auto-fixer.js +26 -44
  291. package/dist/tools/auto-tags.js +83 -0
  292. package/dist/tools/bash.js +193 -116
  293. package/dist/tools/browser.js +76 -31
  294. package/dist/tools/chunk-query.js +14 -6
  295. package/dist/tools/create-dir.js +9 -5
  296. package/dist/tools/delete-file.js +9 -5
  297. package/dist/tools/download-file.js +32 -7
  298. package/dist/tools/edit-file.js +52 -14
  299. package/dist/tools/enable-tools.js +6 -6
  300. package/dist/tools/executor.js +132 -27
  301. package/dist/tools/file-info.js +3 -1
  302. package/dist/tools/filter-tools.js +3 -3
  303. package/dist/tools/glob-tool.js +4 -1
  304. package/dist/tools/grep-tool.js +13 -10
  305. package/dist/tools/hidden-tools-block.js +6 -6
  306. package/dist/tools/index.js +16 -8
  307. package/dist/tools/list-dir.js +4 -2
  308. package/dist/tools/load-skill.js +7 -0
  309. package/dist/tools/mcp-call.js +15 -4
  310. package/dist/tools/meet-done.js +14 -0
  311. package/dist/tools/move-file.js +14 -7
  312. package/dist/tools/path-utils.js +29 -29
  313. package/dist/tools/pipeline-run.js +29 -7
  314. package/dist/tools/preview.js +1 -1
  315. package/dist/tools/process-ids.js +31 -0
  316. package/dist/tools/process-kill.js +9 -16
  317. package/dist/tools/process-list.js +1 -0
  318. package/dist/tools/process-log.js +11 -16
  319. package/dist/tools/process-wait.js +63 -0
  320. package/dist/tools/prompt-io.js +4 -3
  321. package/dist/tools/question.js +172 -25
  322. package/dist/tools/read-file.js +55 -34
  323. package/dist/tools/recall.js +14 -8
  324. package/dist/tools/registry.js +6 -5
  325. package/dist/tools/remember.js +8 -4
  326. package/dist/tools/scope-request.js +11 -6
  327. package/dist/tools/search-history.js +5 -2
  328. package/dist/tools/session-info.js +2 -0
  329. package/dist/tools/set-thinking.js +8 -4
  330. package/dist/tools/subagent.js +59 -39
  331. package/dist/tools/syntax-validator.js +292 -90
  332. package/dist/tools/user-input.js +22 -18
  333. package/dist/tools/web-browse.js +9 -3
  334. package/dist/tools/web-fetch.js +12 -23
  335. package/dist/tools/web-search.js +7 -5
  336. package/dist/tools/write-file.js +45 -15
  337. package/dist/ui/action-log.js +13 -0
  338. package/dist/ui/box.js +4 -3
  339. package/dist/ui/colors.js +2 -0
  340. package/dist/ui/diff.js +6 -5
  341. package/dist/ui/index.js +1 -0
  342. package/dist/ui/line-editor.js +230 -122
  343. package/dist/ui/line-math.js +10 -2
  344. package/dist/ui/md-formatter.js +57 -37
  345. package/dist/ui/output.js +8 -3
  346. package/dist/ui/plan-view.js +21 -10
  347. package/dist/ui/renderer.js +393 -67
  348. package/dist/ui/spinner.js +16 -5
  349. package/dist/ui/table.js +15 -17
  350. package/dist/ui/theme.js +143 -0
  351. package/dist/utils/child-run.js +20 -0
  352. package/dist/utils/error.js +1 -1
  353. package/dist/utils/index.js +2 -0
  354. package/dist/utils/retry.js +2 -2
  355. package/dist/utils/truncate.js +1 -1
  356. package/package.json +1 -1
@@ -0,0 +1,512 @@
1
+ // Sidebar tabs (Session / Map / Trace) for `mma web`.
2
+ //
3
+ // Owns: active-tab state (localStorage), the live per-session Trace buffer with
4
+ // master-detail expansion, and the Map tab rendering. Leaf module: imports only
5
+ // dom/i18n/format/store/api — the frontend DAG stays acyclic
6
+ // (app → sidebar → {dom,i18n,format,store,api}).
7
+ // Design: docs/specs/2026-09-30-webui-sidebar-tabs-design.md.
8
+
9
+ import { el, icon } from "./dom.js";
10
+ import { api } from "./api.js";
11
+ import { S } from "./store.js";
12
+ import { t } from "./i18n.js";
13
+ import { labelOf, categoryOf, argText, formatMs, fmtTokens } from "./format.js";
14
+
15
+ const TAB_KEY = "mma-sidebar-tab";
16
+ const TABS = ["session", "map", "trace"];
17
+ const ICON_NAME = { session: "list-checks", map: "map", trace: "activity" };
18
+ const TRACE_CAP = 500;
19
+ const MAX_OUTPUT_CHARS = 20000;
20
+
21
+ let sbEl = null, nameEl = null, nameTextEl = null, mapEl = null, listEl = null, detailEl = null;
22
+ let detailGlyph = null, detailTitle = null, detailBody = null, detailClose = null;
23
+ let active = "session";
24
+ let trace = []; // { id, kind, ts, name, args, output, success, durationMs, phase, text, steps, currentIndex }
25
+ let selected = null; // trace id
26
+ let turn = 0;
27
+ let seq = 0;
28
+ const nodeById = new Map(); // entry id → row node
29
+ const callIndex = new Map(); // toolCallId → entry
30
+ const headerByTurn = new Map(); // turn → header node
31
+ let textEntry = null; // current text row (updated in place)
32
+
33
+ function paneEl(id) { return document.getElementById("pane-" + id); }
34
+
35
+ function mqMobile() {
36
+ return typeof window !== "undefined" && window.matchMedia
37
+ ? window.matchMedia("(max-width: 760px)").matches : false;
38
+ }
39
+
40
+ function readStored() {
41
+ try { return localStorage.getItem(TAB_KEY); } catch { return null; }
42
+ }
43
+ function storeTab(id) {
44
+ try { localStorage.setItem(TAB_KEY, id); } catch { /* private mode */ }
45
+ }
46
+
47
+ export function setSidebarTab(id, persist = true) {
48
+ if (!TABS.includes(id)) id = "session";
49
+ if (persist) storeTab(id);
50
+ const effective = id === "trace" && mqMobile() ? "session" : id;
51
+ active = effective;
52
+ TABS.forEach((name) => {
53
+ const pane = paneEl(name);
54
+ if (pane) pane.hidden = name !== effective;
55
+ const tab = sbEl && sbEl.querySelector('.sb-tab[data-tab="' + name + '"]');
56
+ if (tab) {
57
+ const on = name === effective;
58
+ tab.classList.toggle("on", on);
59
+ tab.setAttribute("aria-selected", on ? "true" : "false");
60
+ }
61
+ });
62
+ if (nameTextEl) nameTextEl.textContent = t("web.sidebar.tab_" + effective);
63
+ const nic = nameEl && nameEl.querySelector(".sb-ico");
64
+ if (nic) { nic.textContent = ""; nic.appendChild(icon(ICON_NAME[effective])); }
65
+ }
66
+
67
+ function collapseDetail() {
68
+ selected = null;
69
+ if (sbEl) sbEl.classList.remove("sb-expanded");
70
+ if (detailEl) detailEl.hidden = true;
71
+ if (listEl) listEl.querySelectorAll(".trc.sel").forEach((n) => n.classList.remove("sel"));
72
+ }
73
+
74
+ function phaseLabel(phase) {
75
+ if (phase === "composing") return t("web.rail.composing");
76
+ if (phase === "tool") return t("web.rail.working");
77
+ if (phase === "thinking") return t("web.action.thinking");
78
+ return String(phase || "");
79
+ }
80
+
81
+ function catClass(kind, name) {
82
+ if (kind === "tool" || kind === "tool_fail") return categoryOf(name);
83
+ if (kind === "phase") return "phase";
84
+ return "meta";
85
+ }
86
+
87
+ function rowLabel(entry) {
88
+ switch (entry.kind) {
89
+ case "phase": return phaseLabel(entry.phase);
90
+ case "plan": return t("web.sidebar.trace_plan");
91
+ case "question": return t("web.sidebar.trace_question");
92
+ case "text": return t("web.sidebar.trace_text", { count: entry.chars || 0 });
93
+ default: return labelOf(entry.name);
94
+ }
95
+ }
96
+
97
+ function rowArgs(entry) {
98
+ if (entry.kind === "text" || entry.kind === "phase") return "";
99
+ if (entry.kind === "plan") {
100
+ const idx = typeof entry.currentIndex === "number" ? entry.currentIndex : 0;
101
+ const total = Array.isArray(entry.steps) ? entry.steps.length : 0;
102
+ if (!total) return "";
103
+ return t("web.rail.step_of", { cur: Math.min(idx + 1, total), total });
104
+ }
105
+ if (entry.kind === "question") return entry.text || "";
106
+ return argText(entry.args);
107
+ }
108
+
109
+ function isWarn(entry) {
110
+ return entry.kind === "tool_fail" || entry.kind === "error";
111
+ }
112
+
113
+ function renderRow(entry) {
114
+ const cls = ["trc", catClass(entry.kind, entry.name)];
115
+ if (isWarn(entry)) cls.push("warn");
116
+ if (selected === entry.id) cls.push("sel");
117
+ const row = el("div", cls.join(" "));
118
+ row.dataset.id = String(entry.id);
119
+ row.appendChild(el("span", "g", isWarn(entry) ? "⚠" : entry.kind === "question" ? "?" : "◇"));
120
+ row.appendChild(el("span", "lab", rowLabel(entry)));
121
+ const args = rowArgs(entry);
122
+ if (args) row.appendChild(el("span", "args", args));
123
+ if (entry.durationMs) row.appendChild(el("span", "t", formatMs(entry.durationMs)));
124
+ row.addEventListener("click", () => {
125
+ if (selected === entry.id) { collapseDetail(); return; }
126
+ if (listEl) listEl.querySelectorAll(".trc.sel").forEach((n) => n.classList.remove("sel"));
127
+ selected = entry.id;
128
+ row.classList.add("sel");
129
+ renderDetail(entry);
130
+ if (sbEl) sbEl.classList.add("sb-expanded");
131
+ });
132
+ return row;
133
+ }
134
+
135
+ function renderList() {
136
+ if (!listEl) return;
137
+ listEl.textContent = "";
138
+ listEl.dataset.lastTurn = "-1";
139
+ nodeById.clear();
140
+ headerByTurn.clear();
141
+ if (selected && !trace.some((e) => e.id === selected)) selected = null;
142
+ if (trace.length === 0) {
143
+ listEl.appendChild(el("div", "trace-turn", t("web.sidebar.trace_empty")));
144
+ return;
145
+ }
146
+ let shownTurn = -1;
147
+ for (const entry of trace) {
148
+ if (entry.turn !== shownTurn) {
149
+ shownTurn = entry.turn;
150
+ const h = el("div", "trace-turn", t("web.sidebar.trace_turn", { n: entry.turn }));
151
+ headerByTurn.set(entry.turn, h);
152
+ listEl.appendChild(h);
153
+ }
154
+ const row = renderRow(entry);
155
+ nodeById.set(entry.id, row);
156
+ listEl.appendChild(row);
157
+ }
158
+ listEl.dataset.lastTurn = String(shownTurn);
159
+ listEl.scrollTop = listEl.scrollHeight;
160
+ }
161
+
162
+ function append(entry) {
163
+ entry.id = ++seq;
164
+ entry.turn = turn;
165
+ entry.ts = Date.now();
166
+ trace.push(entry);
167
+ while (trace.length > TRACE_CAP) {
168
+ const old = trace.shift();
169
+ const node = nodeById.get(old.id);
170
+ if (node) { node.remove(); nodeById.delete(old.id); }
171
+ if (old.toolCallId != null) callIndex.delete(old.toolCallId);
172
+ if (!trace.some((e) => e.turn === old.turn)) {
173
+ const h = headerByTurn.get(old.turn);
174
+ if (h) { h.remove(); headerByTurn.delete(old.turn); }
175
+ }
176
+ }
177
+ return entry;
178
+ }
179
+
180
+ function pushRow(entry) {
181
+ if (!listEl) return;
182
+ const last = listEl.dataset.lastTurn ? Number(listEl.dataset.lastTurn) : -1;
183
+ if (entry.turn !== last) {
184
+ const h = el("div", "trace-turn", t("web.sidebar.trace_turn", { n: entry.turn }));
185
+ headerByTurn.set(entry.turn, h);
186
+ listEl.appendChild(h);
187
+ listEl.dataset.lastTurn = String(entry.turn);
188
+ }
189
+ const row = renderRow(entry);
190
+ nodeById.set(entry.id, row);
191
+ listEl.appendChild(row);
192
+ listEl.scrollTop = listEl.scrollHeight;
193
+ }
194
+
195
+ function replaceRow(entry) {
196
+ const old = nodeById.get(entry.id);
197
+ const next = renderRow(entry);
198
+ nodeById.set(entry.id, next);
199
+ if (old && old.parentNode) old.replaceWith(next);
200
+ else if (listEl) listEl.appendChild(next);
201
+ if (listEl) listEl.scrollTop = listEl.scrollHeight;
202
+ }
203
+
204
+ function updateTextRow(entry) {
205
+ const row = nodeById.get(entry.id);
206
+ if (!row) return;
207
+ row.textContent = "";
208
+ row.appendChild(el("span", "g", "✦"));
209
+ row.appendChild(el("span", "lab", rowLabel(entry)));
210
+ if (listEl) listEl.scrollTop = listEl.scrollHeight;
211
+ }
212
+
213
+ // ---- public API ----
214
+
215
+ export function sidebarSessionChanged(sid) {
216
+ const prev = sbEl && sbEl.dataset.sid;
217
+ if (prev === (sid || "")) return;
218
+ if (sbEl) sbEl.dataset.sid = sid || "";
219
+ trace = [];
220
+ callIndex.clear();
221
+ textEntry = null;
222
+ turn = 0;
223
+ seq = 0;
224
+ collapseDetail();
225
+ renderList();
226
+ }
227
+
228
+ export function sidebarTurnEnd() {
229
+ turn += 1;
230
+ textEntry = null;
231
+ }
232
+
233
+ export function sidebarTraceEvent(kind, data) {
234
+ if (!data) return;
235
+ switch (kind) {
236
+ case "tool_start": {
237
+ const entry = append({ kind: "tool", name: data.name, args: data.args || {}, toolCallId: data.toolCallId });
238
+ if (data.toolCallId != null) callIndex.set(data.toolCallId, entry);
239
+ pushRow(entry);
240
+ break;
241
+ }
242
+ case "tool_end": {
243
+ const entry = data.toolCallId != null ? callIndex.get(data.toolCallId) : undefined;
244
+ if (data.toolCallId != null) callIndex.delete(data.toolCallId);
245
+ if (entry) {
246
+ entry.kind = data.success === false ? "tool_fail" : "tool";
247
+ entry.success = data.success !== false;
248
+ entry.durationMs = data.durationMs;
249
+ entry.output = data.output || "";
250
+ replaceRow(entry);
251
+ } else {
252
+ const e2 = append({
253
+ kind: data.success === false ? "tool_fail" : "tool",
254
+ name: data.name, args: data.args || {}, toolCallId: data.toolCallId,
255
+ success: data.success !== false, durationMs: data.durationMs, output: data.output || "",
256
+ });
257
+ pushRow(e2);
258
+ }
259
+ break;
260
+ }
261
+ case "phase":
262
+ if (data.phase !== "done") pushRow(append({ kind: "phase", phase: data.phase }));
263
+ break;
264
+ case "plan":
265
+ pushRow(append({
266
+ kind: "plan",
267
+ steps: Array.isArray(data.steps) ? data.steps : [],
268
+ currentIndex: typeof data.currentIndex === "number" ? data.currentIndex : 0,
269
+ }));
270
+ break;
271
+ case "question":
272
+ pushRow(append({ kind: "question", text: data.question || data.text || "" }));
273
+ break;
274
+ case "text": {
275
+ if (!textEntry) { textEntry = append({ kind: "text", text: "", chars: 0 }); pushRow(textEntry); }
276
+ const chunk = data.chunk || "";
277
+ textEntry.chars += chunk.length;
278
+ textEntry.text += chunk;
279
+ if (textEntry.text.length > 4000) textEntry.text = textEntry.text.slice(-4000);
280
+ updateTextRow(textEntry);
281
+ break;
282
+ }
283
+ case "error":
284
+ pushRow(append({ kind: "error", message: data.message || data.error || "" }));
285
+ break;
286
+ default:
287
+ break;
288
+ }
289
+ }
290
+
291
+ function detailGroup(title, bodyNode) {
292
+ const g = el("div");
293
+ g.appendChild(el("h5", "", title));
294
+ g.appendChild(bodyNode);
295
+ return g;
296
+ }
297
+ function kv(label, value) {
298
+ const row = el("div", "kv");
299
+ row.appendChild(el("span", "dim", label));
300
+ const b = el("b");
301
+ b.textContent = value;
302
+ row.appendChild(b);
303
+ return row;
304
+ }
305
+ function codeBlock(text) {
306
+ const c = el("div", "code");
307
+ c.textContent = text;
308
+ return c;
309
+ }
310
+ function capOutput(text) {
311
+ if (typeof text !== "string") return "";
312
+ return text.length <= MAX_OUTPUT_CHARS ? text : text.slice(0, MAX_OUTPUT_CHARS) + "\n… [truncated from " + text.length + " chars]";
313
+ }
314
+
315
+ function renderDetail(entry) {
316
+ if (!detailEl) return;
317
+ detailEl.hidden = false;
318
+ const warn = isWarn(entry);
319
+ detailGlyph.textContent = warn ? "⚠" : entry.kind === "question" ? "?" : "◇";
320
+ detailGlyph.style.color = warn ? "var(--yellow)" : "var(--accent)";
321
+ detailTitle.textContent = rowLabel(entry);
322
+ detailBody.textContent = "";
323
+
324
+ const meta = el("div");
325
+ meta.appendChild(el("h5", "", t("web.sidebar.detail_metadata")));
326
+ const d = entry.ts ? new Date(entry.ts) : null;
327
+ if (entry.kind === "tool" || entry.kind === "tool_fail") {
328
+ meta.appendChild(kv(t("web.sidebar.detail_status"), entry.success === false ? t("web.sidebar.detail_fail") : t("web.sidebar.detail_ok")));
329
+ if (entry.durationMs) meta.appendChild(kv(t("web.sidebar.detail_duration"), formatMs(entry.durationMs)));
330
+ }
331
+ if (d) meta.appendChild(kv(t("web.sidebar.detail_time"), d.toLocaleTimeString()));
332
+ if (entry.toolCallId) meta.appendChild(kv(t("web.sidebar.detail_tool_call"), String(entry.toolCallId)));
333
+ if (sbEl && sbEl.dataset.sid) meta.appendChild(kv(t("web.sidebar.detail_session"), sbEl.dataset.sid));
334
+ detailBody.appendChild(meta);
335
+
336
+ if (entry.kind === "tool" || entry.kind === "tool_fail") {
337
+ detailBody.appendChild(detailGroup(t("web.sidebar.detail_arguments"), codeBlock(JSON.stringify(entry.args || {}, null, 2))));
338
+ detailBody.appendChild(detailGroup(t("web.sidebar.detail_output"), codeBlock(capOutput(entry.output))));
339
+ } else if (entry.kind === "text") {
340
+ detailBody.appendChild(detailGroup(t("web.sidebar.detail_text"), codeBlock(entry.text || "")));
341
+ } else if (entry.kind === "plan") {
342
+ const list = el("div");
343
+ (entry.steps || []).forEach((s) => {
344
+ const mark = s.status === "done" ? "✓" : s.status === "failed" ? "✗" : s.status === "in_progress" ? "▸" : "○";
345
+ const cls = s.status === "failed" ? "fail" : s.status === "in_progress" ? "cur" : s.status === "done" ? "done" : "";
346
+ list.appendChild(el("div", ("plan-step " + cls).trim(), mark + " " + s.text));
347
+ });
348
+ detailBody.appendChild(detailGroup(t("web.sidebar.detail_plan"), list));
349
+ } else if (entry.kind === "question") {
350
+ detailBody.appendChild(detailGroup(t("web.sidebar.trace_question"), codeBlock(entry.text || "")));
351
+ } else if (entry.kind === "error") {
352
+ detailBody.appendChild(detailGroup(t("web.sidebar.detail_error"), codeBlock(entry.message || "")));
353
+ }
354
+ }
355
+
356
+ // ---- Map tab ----
357
+
358
+ function fmtUpdated(updatedAt) {
359
+ if (typeof updatedAt !== "number") return t("web.sidebar.map_never");
360
+ const d = new Date(updatedAt);
361
+ const now = new Date();
362
+ const pad = (n) => String(n).padStart(2, "0");
363
+ const time = pad(d.getHours()) + ":" + pad(d.getMinutes());
364
+ if (d.toDateString() === now.toDateString()) return t("web.sidebar.map_today", { time });
365
+ return pad(d.getDate()) + "." + pad(d.getMonth() + 1) + " " + time;
366
+ }
367
+
368
+ function mapKv(label, value, cls) {
369
+ const row = el("div", ("kv" + (cls ? " " + cls : "")).trim());
370
+ row.appendChild(el("span", "dim", label));
371
+ const b = el("b");
372
+ b.textContent = value;
373
+ row.appendChild(b);
374
+ return row;
375
+ }
376
+
377
+ let reindexing = false; // клиентский спиннер до свежего снапшота
378
+ let postResolved = false; // POST вернулся; следующий снапшот снимет спиннер
379
+ let reindexError = false; // последний POST не удался
380
+
381
+ export function sidebarMapState(host) {
382
+ if (!mapEl) return;
383
+ const map = (host && host.projectMap) || { indexed: false, files: 0, symbols: 0, tokens: 0, languages: [] };
384
+ const serverIndexing = !!(map && map.indexing);
385
+ if (postResolved && !serverIndexing) { reindexing = false; postResolved = false; }
386
+ const indexing = serverIndexing || reindexing;
387
+ const num = (v) => (map.indexed ? String(v || 0) : "—");
388
+ mapEl.textContent = "";
389
+ const status = indexing ? t("web.sidebar.map_indexing")
390
+ : !map.indexed ? t("web.sidebar.map_never")
391
+ : (map.watcher ? t("web.sidebar.map_ready") : t("web.sidebar.map_stale"));
392
+ mapEl.appendChild(mapKv(t("web.sidebar.map_status"), status));
393
+ mapEl.appendChild(mapKv(t("web.sidebar.map_updated"), fmtUpdated(map.updatedAt)));
394
+ mapEl.appendChild(mapKv(t("web.sidebar.map_watcher"), map.watcher ? t("web.sidebar.map_on") : t("web.sidebar.map_off")));
395
+ mapEl.appendChild(mapKv(t("web.sidebar.map_files"), num(map.files)));
396
+ mapEl.appendChild(mapKv(t("web.sidebar.map_symbols"), num(map.symbols)));
397
+ mapEl.appendChild(mapKv(t("web.sidebar.map_tokens"), map.indexed ? fmtTokens(map.tokens || 0) : "—"));
398
+ if (host && host.workspace) mapEl.appendChild(mapKv(t("web.sidebar.map_root"), host.workspace));
399
+
400
+ if (Array.isArray(map.languages) && map.languages.length > 0) {
401
+ const head = el("div", "kv");
402
+ head.appendChild(el("span", "dim", t("web.sidebar.map_languages")));
403
+ mapEl.appendChild(head);
404
+ map.languages.forEach((l) => mapEl.appendChild(mapKv(l.language, l.files + " · " + l.symbols)));
405
+ }
406
+ if (reindexError) mapEl.appendChild(mapKv(t("web.sidebar.map_reindex_failed"), "—", "wn"));
407
+
408
+ const btn = el("button", "map-reindex", indexing ? t("web.sidebar.map_reindexing") : t("web.sidebar.map_reindex"));
409
+ btn.type = "button";
410
+ btn.disabled = indexing || !map.indexed;
411
+ btn.addEventListener("click", async () => {
412
+ reindexing = true;
413
+ postResolved = false;
414
+ reindexError = false;
415
+ sidebarMapState(host);
416
+ sidebarMapIndicator(host);
417
+ const r = await api("/api/index", { method: "POST" });
418
+ if (!r.ok) {
419
+ reindexing = false;
420
+ postResolved = false;
421
+ reindexError = true;
422
+ sidebarMapState(host);
423
+ return;
424
+ }
425
+ // Свежий снапшот (поллинг / `state`-broadcast по завершении) снимет спиннер.
426
+ postResolved = true;
427
+ });
428
+ mapEl.appendChild(btn);
429
+ }
430
+
431
+ // ---- indicators ----
432
+
433
+ export function sidebarBusy(on) {
434
+ const tab = sbEl && sbEl.querySelector('.sb-tab[data-tab="trace"]');
435
+ if (tab) tab.dataset.indicator = on ? "live" : "";
436
+ }
437
+ export function sidebarMapIndicator(host) {
438
+ const tab = sbEl && sbEl.querySelector('.sb-tab[data-tab="map"]');
439
+ if (!tab) return;
440
+ const map = (host && host.projectMap) || null;
441
+ const busy = (map && map.indexing) || reindexing;
442
+ const next = busy ? "busy" : map && map.indexed && !map.watcher ? "stale" : "";
443
+ tab.dataset.indicator = next;
444
+ }
445
+
446
+ // ---- init / i18n ----
447
+
448
+ export function applySidebarI18n() {
449
+ if (!sbEl) return;
450
+ TABS.forEach((id) => {
451
+ const tab = sbEl.querySelector('.sb-tab[data-tab="' + id + '"]');
452
+ if (tab) { const label = t("web.sidebar.tab_" + id); tab.title = label; tab.setAttribute("aria-label", label); }
453
+ });
454
+ setSidebarTab(active, false);
455
+ renderList();
456
+ if (selected) {
457
+ const entry = trace.find((x) => x.id === selected);
458
+ if (entry) renderDetail(entry);
459
+ }
460
+ sidebarMapState(S.state.host);
461
+ }
462
+
463
+ export function initSidebar() {
464
+ if (sbEl) return;
465
+ sbEl = document.querySelector(".sb");
466
+ if (!sbEl) return;
467
+ nameEl = document.getElementById("sbName");
468
+ nameTextEl = document.getElementById("sbNameText");
469
+ mapEl = document.getElementById("mapBody");
470
+ listEl = document.getElementById("traceList");
471
+ detailEl = document.getElementById("traceDetail");
472
+ detailGlyph = document.getElementById("detailGlyph");
473
+ detailTitle = document.getElementById("detailTitle");
474
+ detailBody = document.getElementById("detailBody");
475
+ detailClose = document.getElementById("detailClose");
476
+ if (detailClose) detailClose.addEventListener("click", collapseDetail);
477
+
478
+ sbEl.querySelectorAll(".sb-tab .sb-ico").forEach((span) => {
479
+ const id = span.closest(".sb-tab").dataset.tab;
480
+ span.textContent = "";
481
+ span.appendChild(icon(ICON_NAME[id]));
482
+ });
483
+
484
+ sbEl.querySelectorAll(".sb-tab").forEach((tab) => {
485
+ tab.addEventListener("click", () => setSidebarTab(tab.dataset.tab));
486
+ tab.addEventListener("keydown", (e) => {
487
+ if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
488
+ e.preventDefault();
489
+ const i = TABS.indexOf(tab.dataset.tab);
490
+ const next = TABS[(i + (e.key === "ArrowRight" ? 1 : TABS.length - 1)) % TABS.length];
491
+ setSidebarTab(next);
492
+ const focus = sbEl.querySelector('.sb-tab[data-tab="' + next + '"]');
493
+ if (focus) focus.focus();
494
+ });
495
+ });
496
+
497
+ document.addEventListener("keydown", (e) => {
498
+ if (!e.altKey || !["1", "2", "3"].includes(e.key)) return;
499
+ const tag = document.activeElement ? String(document.activeElement.tagName) : "";
500
+ if (tag === "INPUT" || tag === "TEXTAREA") return;
501
+ e.preventDefault();
502
+ setSidebarTab(TABS[Number(e.key) - 1]);
503
+ });
504
+
505
+ document.addEventListener("keydown", (e) => {
506
+ if (e.key === "Escape" && selected) collapseDetail();
507
+ });
508
+
509
+ const stored = readStored();
510
+ setSidebarTab(stored && TABS.includes(stored) ? stored : "session");
511
+ renderList();
512
+ }
@@ -12,10 +12,11 @@ import { relTime, contextLabel } from "./format.js";
12
12
  import {
13
13
  makeFeed, showEmptyFeed, activeFeed, liveFeed, appendTo,
14
14
  clearEmpty, showBusy, clearFeed, finishMd, resetTurnText,
15
- finishThink, feedHasContent, loadHistory, syncUrl,
15
+ finishThink, feedHasContent, loadHistory, syncUrl, renderPlan,
16
+ scrollToBottom,
16
17
  } from "./feed.js";
17
18
  import { openConfirm, setIndicator } from "./dialog.js";
18
- import { setBusy } from "./rail.js";
19
+ import { setBusy, setPlan as railSetPlan } from "./rail.js";
19
20
 
20
21
  let sessionsErrTimer = null;
21
22
 
@@ -122,7 +123,7 @@ export function openTab(id, name, kind, server) {
122
123
  msgs.replaceChildren(tab.feed);
123
124
  renderTabstrip();
124
125
  renderSessionsDropdown();
125
- msgs.scrollTop = msgs.scrollHeight;
126
+ scrollToBottom();
126
127
  if (tab.kind === "session" && !server) {
127
128
  // Auto-opened live session: SSE fills the feed, no transcript fetch.
128
129
  tab.historyLoaded = true;
@@ -132,7 +133,18 @@ export function openTab(id, name, kind, server) {
132
133
  // it is opened from the server afterward we must actually fetch the
133
134
  // transcript, or a reload of the active session shows an empty feed.
134
135
  if (!feedHasContent(tab.feed)) tab.historyLoaded = false;
135
- api("/api/sessions/activate", { method: "POST", body: { id } }).then(() => loadSessions());
136
+ // План следует за сессией: сервер уже переключил трекер на activate,
137
+ // сразу тянем свежий план в сайдбар (не ждём 2с-полла `/api/state`).
138
+ api("/api/sessions/activate", { method: "POST", body: { id } }).then(() => {
139
+ loadSessions();
140
+ api("/api/state").then((r) => {
141
+ if (!r.ok || !r.data) return;
142
+ S.state.host = r.data.state || {};
143
+ S.state.busy = !!r.data.busy;
144
+ renderPlan(S.state.host.plan);
145
+ railSetPlan(S.state.busy && r.data.state ? r.data.state.plan : null);
146
+ });
147
+ });
136
148
  loadHistory(tab);
137
149
  }
138
150
  syncUrl();
@@ -148,6 +160,7 @@ function closeTab(id) {
148
160
  S.activeTabId = next.id;
149
161
  S.liveTabId = next.id;
150
162
  msgs.replaceChildren(next.feed);
163
+ scrollToBottom();
151
164
  } else {
152
165
  S.activeTabId = null;
153
166
  S.liveTabId = null;
@@ -165,6 +178,14 @@ async function newChatTab() {
165
178
  const meta = r.data.session;
166
179
  openTab(meta.id, meta.name || String(meta.id), "session", false);
167
180
  await loadSessions();
181
+ // Новая сессия — без плана: сервер уже сбросил трекер, сразу чистим сайдбар.
182
+ const st = await api("/api/state");
183
+ if (st.ok && st.data) {
184
+ S.state.host = st.data.state || {};
185
+ S.state.busy = !!st.data.busy;
186
+ renderPlan(S.state.host.plan);
187
+ railSetPlan(S.state.busy && st.data.state ? st.data.state.plan : null);
188
+ }
168
189
  return;
169
190
  }
170
191
  // Server-side creation failed (no manager / offline): keep a local-only tab
@@ -617,6 +638,7 @@ async function send() {
617
638
  finishThink();
618
639
  if (text.startsWith("/")) {
619
640
  appendTo(feed, el("div", "u", text));
641
+ scrollToBottom();
620
642
  clearInput();
621
643
  const name = text.slice(1).split(/\s+/)[0].toLowerCase();
622
644
  // `/clear` and `/new` never reach the server: both are pure browser-side
@@ -644,6 +666,7 @@ async function send() {
644
666
  feed.insertBefore(banner, feed.firstChild);
645
667
  }
646
668
  appendTo(feed, userMessageNode(text, images));
669
+ scrollToBottom();
647
670
  clearInput();
648
671
  const body = { text };
649
672
  if (images.length) body.images = images;
@@ -653,7 +676,9 @@ async function send() {
653
676
  appendTo(feed, el("div", "warnline", "⚠ " + msg));
654
677
  } else {
655
678
  if (images.length) clearAttachments();
656
- showBusy(feed);
679
+ // Delay the spinner so fast first tokens never flash it: `showBusy`
680
+ // itself skips when a stream/think block already started.
681
+ window.setTimeout(() => showBusy(feed), 180);
657
682
  }
658
683
  }
659
684