openclacky 1.5.25 → 1.5.26

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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -0
  3. data/lib/clacky/agent/chunk_index.rb +2 -1
  4. data/lib/clacky/agent/message_compressor_helper.rb +20 -2
  5. data/lib/clacky/agent/session_serializer.rb +28 -1
  6. data/lib/clacky/agent/skill_manager.rb +2 -8
  7. data/lib/clacky/agent/time_machine.rb +108 -127
  8. data/lib/clacky/agent/tool_executor.rb +2 -11
  9. data/lib/clacky/agent.rb +15 -19
  10. data/lib/clacky/agent_config.rb +14 -4
  11. data/lib/clacky/billing/media_usage.rb +69 -0
  12. data/lib/clacky/billing/platform_billing.rb +5 -0
  13. data/lib/clacky/brand_config.rb +16 -215
  14. data/lib/clacky/default_extensions/ext-studio/agents/ext-developer/system_prompt.md +2 -80
  15. data/lib/clacky/default_extensions/ext-studio/panels/studio/view.js +1 -1
  16. data/lib/clacky/default_extensions/ext-studio/skills/ext-develop/SKILL.md +10 -96
  17. data/lib/clacky/default_extensions/git/panels/git/view.js +208 -69
  18. data/lib/clacky/default_extensions/knowledge/README.md +1 -1
  19. data/lib/clacky/default_extensions/knowledge/README.zh.md +1 -1
  20. data/lib/clacky/default_extensions/knowledge/lib/importer.rb +1 -1
  21. data/lib/clacky/default_extensions/knowledge/panels/kb/view.js +3 -3
  22. data/lib/clacky/default_extensions/meeting/api/handler.rb +23 -2
  23. data/lib/clacky/default_extensions/meeting/panels/meeting/view.js +194 -36
  24. data/lib/clacky/default_extensions/preview/icon.svg +3 -2
  25. data/lib/clacky/default_extensions/secretary/panels/work/view.js +108 -33
  26. data/lib/clacky/default_extensions/side-chat/README.md +40 -0
  27. data/lib/clacky/default_extensions/side-chat/README.zh.md +40 -0
  28. data/lib/clacky/default_extensions/side-chat/api/handler.rb +90 -0
  29. data/lib/clacky/default_extensions/side-chat/api/runtime.rb +411 -0
  30. data/lib/clacky/default_extensions/side-chat/ext.yml +16 -0
  31. data/lib/clacky/default_extensions/side-chat/icon.svg +14 -0
  32. data/lib/clacky/default_extensions/side-chat/panels/side-chat/view.js +779 -0
  33. data/lib/clacky/default_extensions/terminal/README.md +36 -0
  34. data/lib/clacky/default_extensions/terminal/README.zh.md +36 -0
  35. data/lib/clacky/default_extensions/terminal/api/handler.rb +121 -0
  36. data/lib/clacky/default_extensions/terminal/api/runtime.rb +397 -0
  37. data/lib/clacky/default_extensions/terminal/ext.yml +16 -0
  38. data/lib/clacky/default_extensions/terminal/icon.svg +13 -0
  39. data/lib/clacky/default_extensions/terminal/panels/terminal/view.js +351 -0
  40. data/lib/clacky/default_extensions/terminal/vendor/LICENSE +21 -0
  41. data/lib/clacky/default_extensions/terminal/vendor/addon-fit.js +2 -0
  42. data/lib/clacky/default_extensions/terminal/vendor/xterm.css +218 -0
  43. data/lib/clacky/default_extensions/terminal/vendor/xterm.js +2 -0
  44. data/lib/clacky/default_skills/media-gen/SKILL.md +30 -9
  45. data/lib/clacky/extension/api_extension.rb +12 -0
  46. data/lib/clacky/locales/en.rb +14 -11
  47. data/lib/clacky/locales/i18n.rb +25 -0
  48. data/lib/clacky/locales/zh.rb +14 -11
  49. data/lib/clacky/media/base.rb +11 -1
  50. data/lib/clacky/media/openai_compat.rb +271 -3
  51. data/lib/clacky/message_format/open_ai.rb +17 -0
  52. data/lib/clacky/prompts/base.md +3 -0
  53. data/lib/clacky/providers.rb +33 -20
  54. data/lib/clacky/reasoning_levels.rb +75 -0
  55. data/lib/clacky/server/channel/channel_ui_controller.rb +12 -5
  56. data/lib/clacky/server/git_panel.rb +40 -18
  57. data/lib/clacky/server/http_server.rb +62 -71
  58. data/lib/clacky/server/session_registry.rb +3 -0
  59. data/lib/clacky/ui2/markdown_renderer.rb +153 -0
  60. data/lib/clacky/ui2/strings_cjk_patch.rb +134 -124
  61. data/lib/clacky/utils/file_link_normalizer.rb +30 -3
  62. data/lib/clacky/utils/frontmatter.rb +63 -0
  63. data/lib/clacky/utils/model_pricing.rb +67 -9
  64. data/lib/clacky/version.rb +1 -1
  65. data/lib/clacky/web/app.css +722 -274
  66. data/lib/clacky/web/app.js +2 -0
  67. data/lib/clacky/web/components/chat-composer.js +504 -0
  68. data/lib/clacky/web/components/chat-navigator.js +1 -1
  69. data/lib/clacky/web/components/model-picker.js +319 -20
  70. data/lib/clacky/web/components/quote-select.js +97 -39
  71. data/lib/clacky/web/core/aside.js +137 -27
  72. data/lib/clacky/web/core/ext.js +658 -81
  73. data/lib/clacky/web/features/brand/store.js +0 -4
  74. data/lib/clacky/web/features/brand/view.js +2 -99
  75. data/lib/clacky/web/features/extensions/store.js +3 -1
  76. data/lib/clacky/web/features/extensions/view.js +14 -15
  77. data/lib/clacky/web/features/new-session/store.js +4 -0
  78. data/lib/clacky/web/features/new-session/view.js +27 -4
  79. data/lib/clacky/web/features/skills/store.js +7 -5
  80. data/lib/clacky/web/features/skills/view.js +65 -16
  81. data/lib/clacky/web/features/version/view.js +1 -1
  82. data/lib/clacky/web/features/workspace/store.js +7 -3
  83. data/lib/clacky/web/features/workspace/view.js +46 -5
  84. data/lib/clacky/web/i18n.js +104 -58
  85. data/lib/clacky/web/index.html +21 -22
  86. data/lib/clacky/web/lib/box-diagram.js +239 -0
  87. data/lib/clacky/web/sessions.js +117 -151
  88. data/lib/clacky/web/settings.js +23 -16
  89. data/lib/clacky/web/ws-dispatcher.js +4 -1
  90. data/lib/clacky.rb +2 -0
  91. metadata +24 -1
@@ -25,6 +25,17 @@
25
25
  // can mean 900 files; laying all of them out at once locks the tab up, so
26
26
  // files past the budget render a one-line placeholder that loads on click.
27
27
  const VIEW_BUDGET_LINES = 3000;
28
+ // The budget above caps rendered lines, not blocks: a 500-file branch still
29
+ // built 500 sections (each with a sticky header) and every sidebar drag had
30
+ // to lay all of them out. Sections mount in batches instead, and the next
31
+ // one arrives once the stream is within BATCH_AHEAD_PX of its end.
32
+ const VIEW_BATCH_FILES = 60;
33
+ const BATCH_AHEAD_PX = 600;
34
+ // Mounting in batches bounds the first paint, not the per-frame cost: every
35
+ // mounted file keeps its rows in layout, so a sidebar drag had to lay out all
36
+ // of them on each frame. Sections further than this from the viewport keep
37
+ // their slot at the measured height but drop their rows from layout.
38
+ const PARK_AHEAD_PX = 600;
28
39
  const SIDE_WIDTH_KEY = "clacky.git.sideWidth";
29
40
  const LAYOUT_KEY = "clacky.git.diffLayout";
30
41
  const TREE_KEY = "clacky.git.treeVisible";
@@ -99,7 +110,7 @@
99
110
  style.id = "changes-panel-style";
100
111
  style.textContent = `
101
112
  .changes-root { container-type: inline-size; --cg-swatch-add: #6dcf90; --cg-swatch-del: #f28f95; display: flex; flex-direction: column; flex: 1; min-height: 0; background: var(--color-bg-primary); }
102
- .cg-bar { flex: none; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 12px; height: 40px; border-bottom: 1px solid var(--color-border-primary); }
113
+ .cg-bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 8px 0 12px; height: 40px; border-bottom: 1px solid var(--color-border-primary); }
103
114
  .cg-bar-stats { display: flex; align-items: center; gap: 7px; min-width: 0; font-family: ui-monospace, monospace; font-size: 12px; font-weight: 600; }
104
115
  .cg-bar-add { color: var(--color-success, #2f9e44); }
105
116
  .cg-bar-del { color: var(--color-error, #c92a2a); }
@@ -112,7 +123,8 @@
112
123
  .cg-scope-subject { flex: 0 1 auto; min-width: 0; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--color-text-tertiary); font-weight: 400; }
113
124
  .cg-scope > .cg-bar-add, .cg-scope > .cg-bar-del { flex: none; }
114
125
  .cg-compare { flex: 0 1 auto; min-width: 0; font-size: 12.5px; }
115
- .cg-compare .cg-scope-head, .cg-compare .cg-scope-base { min-width: 0; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
126
+ .cg-compare .cg-scope-head, .cg-compare .cg-scope-base { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
127
+ .cg-compare .cg-scope-head { flex: none; max-width: 150px; }
116
128
  .cg-compare .cg-compare-arrow { display: inline-flex; color: var(--color-text-tertiary); opacity: 0.8; }
117
129
  .cg-scope-menu { position: fixed; z-index: 1000; min-width: 196px; padding: 7px; border: 1px solid var(--color-border-primary); border-radius: 12px; background: var(--color-bg-primary); box-shadow: 0 14px 38px rgba(0, 0, 0, 0.16), 0 2px 6px rgba(0, 0, 0, 0.06); }
118
130
  .cg-scope-item { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px; border-radius: 7px; font-size: 13px; color: var(--color-text-primary); cursor: pointer; white-space: nowrap; }
@@ -152,7 +164,6 @@
152
164
  .cg-find-name { flex: none; max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
153
165
  .cg-find-dir { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--color-text-tertiary); font-family: ui-monospace, monospace; font-size: 11.5px; }
154
166
  .cg-find-empty { padding: 10px; font-size: 12px; color: var(--color-text-tertiary); }
155
- .cg-bar-spacer { flex: 1; }
156
167
  .cg-tools { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 2px; border: 1px solid var(--color-border-primary); border-radius: var(--radius-pill); }
157
168
  .cg-icon-btn { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0; border: none; border-radius: var(--radius-sm); background: transparent; color: var(--color-text-tertiary); cursor: pointer; }
158
169
  .cg-icon-btn:hover { background: var(--color-bg-hover); color: var(--color-text-primary); }
@@ -217,6 +228,10 @@
217
228
  .cg-fh-caret { flex: none; display: inline-flex; color: var(--color-text-tertiary); transform: rotate(90deg); transition: transform 0.12s ease; }
218
229
  .cg-file.is-collapsed .cg-fh-caret { transform: none; }
219
230
  .changes-root .cg-file.is-collapsed .cg-lines { display: none; }
231
+ /* Off-screen sections keep the height they measured before parking, so
232
+ the scroll box and the row offsets stay put (see parkFarSections). */
233
+ .changes-root .cg-file.is-parked { overflow: hidden; }
234
+ .changes-root .cg-file.is-parked > * { display: none; }
220
235
  .cg-lines { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; line-height: 1.55; padding-bottom: 2px; }
221
236
  /* The add/del wash rides on a gradient rather than a background colour:
222
237
  the unwrapped and pane rules below set an opaque background-color with
@@ -293,7 +308,7 @@
293
308
  .cg-side { width: 220px; }
294
309
  .cg-scope-label { max-width: 110px; }
295
310
  .cg-scope-subject { max-width: 170px; }
296
- .cg-compare .cg-scope-head, .cg-compare .cg-scope-base { max-width: 96px; }
311
+ .cg-compare .cg-scope-head { max-width: 96px; }
297
312
  }
298
313
  @container (max-width: 700px) {
299
314
  .cg-side { width: 190px; }
@@ -305,15 +320,22 @@
305
320
  }
306
321
  @container (max-width: 520px) {
307
322
  .cg-side { width: 156px; }
308
- .cg-compare .cg-scope-head, .cg-compare .cg-scope-base { max-width: 84px; }
323
+ .cg-compare .cg-scope-head { max-width: 84px; }
309
324
  }
310
325
  @container (max-width: 460px) {
311
326
  /* The bar wraps only when the pills and the tools no longer fit side
312
- by side. The spacer keeps its slot so the tools drop to the next
313
- line flush left instead of being pushed to the right edge. */
327
+ by side. space-between parks a lone item at the start of its line,
328
+ so the tools row lands flush left however wide the pills are - a
329
+ flexible spacer would follow them onto the second row and push
330
+ them back to the right edge. */
314
331
  .cg-bar { height: auto; min-height: 38px; flex-wrap: wrap; padding-block: 6px; row-gap: 6px; }
315
- .cg-scope-subject { max-width: 180px; }
316
- .cg-compare .cg-scope-head, .cg-compare .cg-scope-base { max-width: 62px; }
332
+ /* Wrapped, the pills no longer share their row with the tools, so the
333
+ caps tuned for a shared row cut names this row has room for. Let a
334
+ pill shrink to the row's real width instead: it stays whole while
335
+ the row fits it and still ellipsises once the row is narrower. */
336
+ .cg-scope-subject { max-width: none; }
337
+ .cg-compare .cg-scope-head { flex: none; max-width: 84px; }
338
+ .cg-compare .cg-scope-base { max-width: none; }
317
339
  }
318
340
  `;
319
341
  document.head.appendChild(style);
@@ -441,8 +463,8 @@
441
463
 
442
464
  function scopeQuery() {
443
465
  const parts = [`scope=${encodeURIComponent(state.scope)}`];
444
- if (state.scope === "branch" && state.base) {
445
- parts.push(`base=${encodeURIComponent(state.base)}`);
466
+ if (state.scope === "branch" && state.target) {
467
+ parts.push(`target=${encodeURIComponent(state.target)}`);
446
468
  } else if (state.scope === "committed" && state.commit) {
447
469
  parts.push(`base=${encodeURIComponent(state.commit)}`);
448
470
  }
@@ -533,15 +555,18 @@
533
555
  activePath: null,
534
556
  renderTruncated: 0,
535
557
  budget: 0,
536
- // Which slice of history the panel shows. `branch` compares the current
537
- // HEAD against a branch the user picked in the compare pill; `committed`
538
- // compares it against a commit picked from the menu. Both start out on the
539
- // server's default base (the upstream) and keep their pick separately, so
540
- // switching scopes never loses the other one.
558
+ // How many entries of `files` have a section in the stream; the rest are
559
+ // mounted in batches as the user scrolls.
560
+ mounted: 0,
561
+ // Coalesces the park pass to one per frame burst, like `spanTimer`.
562
+ parkTimer: null,
563
+ // Which slice of history the panel shows. `branch` reviews the branch the
564
+ // user picked in the compare pill, measured from the default branch up to
565
+ // it; `committed` reviews a commit picked from the menu. Both keep their
566
+ // pick separately, so switching scopes never loses the other one.
541
567
  scope: "worktree",
542
- base: "",
568
+ target: "",
543
569
  commit: "",
544
- branch: "",
545
570
  branches: null,
546
571
  commits: null,
547
572
  note: null,
@@ -1117,6 +1142,7 @@
1117
1142
  state.reflow = false;
1118
1143
  applyLayoutButton();
1119
1144
  scheduleSpan();
1145
+ schedulePark();
1120
1146
  }
1121
1147
 
1122
1148
  // Measured after layout so strips and rows can span the real scroll width. A
@@ -1174,6 +1200,10 @@
1174
1200
  if (state.els && state.els.root) state.els.root.classList.toggle("is-wrap", state.wrap);
1175
1201
  try { localStorage.setItem(WRAP_KEY, state.wrap ? "1" : "0"); } catch (_e) { /* private mode */ }
1176
1202
  applyWrapButton();
1203
+ // A parked height was measured unwrapped, so turning wrapping on has to
1204
+ // hand every section back to layout before it rewraps.
1205
+ if (state.wrap) unparkAllSections();
1206
+ else schedulePark();
1177
1207
  // Side-by-side swaps between paired rows and scrolling panes, so the
1178
1208
  // bodies have to be rebuilt rather than restyled.
1179
1209
  if (effectiveLayout() === "split") reflowBodies();
@@ -1376,6 +1406,8 @@
1376
1406
 
1377
1407
  lines.appendChild(frag);
1378
1408
  if (panes && oldCol && newCol) syncPaneScroll([oldCol, newCol]);
1409
+ // Fresh rows make the height a parked section measured obsolete.
1410
+ unparkSection(section);
1379
1411
  scheduleSpan();
1380
1412
  if (!full && !record.loaded && !state.reflow) state.budget -= rendered;
1381
1413
  if (rendered > 0) record.shown = true;
@@ -1392,8 +1424,8 @@
1392
1424
  const canLoad = state.scope !== "lastTurn" || !!(record.raw && record.raw.trim());
1393
1425
  const box = el("div", { class: `cg-lazy${canLoad ? "" : " is-static"}`,
1394
1426
  text: canLoad
1395
- ? t("changes.diff.lazy", "改动较大,点按加载此文件的差异")
1396
- : t("changes.diff.skipped", "差异过大,未在此处显示") });
1427
+ ? t("changes.diff.lazy", "点击加载此文件的差异")
1428
+ : t("changes.diff.skipped", "此文件的差异未在此处显示") });
1397
1429
  if (canLoad) {
1398
1430
  box.addEventListener("click", (e) => {
1399
1431
  e.stopPropagation();
@@ -1442,7 +1474,12 @@
1442
1474
  unstaged: () => t("changes.scope.emptyUnstaged", "工作区没有未暂存的改动。"),
1443
1475
  staged: () => t("changes.scope.emptyStaged", "暂存区没有改动。"),
1444
1476
  committed: () => t("changes.scope.emptyCommitted", "当前分支相对基线没有提交。"),
1445
- branch: () => t("changes.scope.emptyCommitted", "当前分支相对基线没有提交。"),
1477
+ branch: () => t("changes.scope.emptyBranch", "这条分支相对基线没有改动。"),
1478
+ };
1479
+
1480
+ const NOTE_BY_SCOPE = {
1481
+ noBase: () => t("changes.scope.noBase", "没有可比较的基线分支。"),
1482
+ noTarget: () => t("changes.scope.noTarget", "找不到这条分支。"),
1446
1483
  };
1447
1484
 
1448
1485
  function renderStream() {
@@ -1451,25 +1488,111 @@
1451
1488
  state.records = new Map();
1452
1489
  state.renderTruncated = 0;
1453
1490
  state.budget = VIEW_BUDGET_LINES;
1491
+ state.mounted = 0;
1454
1492
  if (!state.files.length) {
1455
- const text = state.note === "noBase"
1456
- ? t("changes.scope.noBase", "没有可比较的基线分支。")
1457
- : (EMPTY_BY_SCOPE[state.scope] || EMPTY_BY_SCOPE.worktree)();
1493
+ const text = (NOTE_BY_SCOPE[state.note] || EMPTY_BY_SCOPE[state.scope] || EMPTY_BY_SCOPE.worktree)();
1458
1494
  stream.appendChild(el("div", { class: "cg-empty", text }));
1459
1495
  return;
1460
1496
  }
1497
+ mountNextBatch();
1498
+ fillViewport();
1499
+ schedulePark();
1500
+ }
1501
+
1502
+ function mountNextBatch() {
1503
+ const stream = state.els.stream;
1504
+ const batch = state.files.slice(state.mounted, state.mounted + VIEW_BATCH_FILES);
1505
+ if (!batch.length) return;
1461
1506
  const frag = document.createDocumentFragment();
1462
- state.files.forEach((file) => {
1507
+ batch.forEach((file) => {
1463
1508
  state.records.set(file.path, { file: file, full: false, raw: file.diff,
1464
1509
  lazyPending: !!file.lazy });
1465
1510
  frag.appendChild(buildFileSection(file));
1466
1511
  });
1467
1512
  stream.appendChild(frag);
1513
+ state.mounted += batch.length;
1468
1514
  updateActiveRow();
1469
1515
  }
1470
1516
 
1517
+ // One batch of short files (placeholders are a single line) may not fill the
1518
+ // pane, and a stream that never overflows scrolls nowhere - so the scroll
1519
+ // listener would never ask for the rest. Top up until it can.
1520
+ function fillViewport() {
1521
+ const stream = state.els.stream;
1522
+ while (state.mounted < state.files.length
1523
+ && stream.scrollTop + stream.clientHeight >= stream.scrollHeight - BATCH_AHEAD_PX) {
1524
+ mountNextBatch();
1525
+ }
1526
+ }
1527
+
1528
+ function parkSection(section, height) {
1529
+ section.style.height = height + "px";
1530
+ section.classList.add("is-parked");
1531
+ }
1532
+
1533
+ function unparkSection(section) {
1534
+ if (!section.classList.contains("is-parked")) return;
1535
+ section.style.height = "";
1536
+ section.classList.remove("is-parked");
1537
+ }
1538
+
1539
+ function unparkAllSections() {
1540
+ const stream = state.els && state.els.stream;
1541
+ if (!stream) return;
1542
+ const parked = stream.querySelectorAll("section.cg-file.is-parked");
1543
+ for (let i = 0; i < parked.length; i++) unparkSection(parked[i]);
1544
+ }
1545
+
1546
+ // Drops the rows of every far-off section from layout while keeping its slot.
1547
+ // The heights are read before anything is written: interleaving the two would
1548
+ // force a fresh layout per section and make this quadratic.
1549
+ function parkFarSections() {
1550
+ const stream = state.els && state.els.stream;
1551
+ // Wrapping rewraps at every width, so a height measured here goes stale the
1552
+ // moment the pane changes; that mode keeps the full layout instead.
1553
+ if (!stream || state.wrap) return;
1554
+ const top = stream.scrollTop;
1555
+ const bottom = top + stream.clientHeight;
1556
+ const sections = stream.querySelectorAll("section.cg-file");
1557
+ const park = [];
1558
+ const wake = [];
1559
+ for (let i = 0; i < sections.length; i++) {
1560
+ const section = sections[i];
1561
+ const start = section.offsetTop;
1562
+ const height = section.getBoundingClientRect().height;
1563
+ const parked = section.classList.contains("is-parked");
1564
+ const near = start + height >= top - PARK_AHEAD_PX && start <= bottom + PARK_AHEAD_PX;
1565
+ if (near) {
1566
+ if (parked) wake.push(section);
1567
+ } else if (!parked) {
1568
+ park.push([section, height]);
1569
+ }
1570
+ }
1571
+ // Wake the sections that scrolled back before measuring nothing else: their
1572
+ // restored rows only matter for the next pass.
1573
+ for (let i = 0; i < wake.length; i++) unparkSection(wake[i]);
1574
+ for (let i = 0; i < park.length; i++) parkSection(park[i][0], park[i][1]);
1575
+ }
1576
+
1577
+ function schedulePark() {
1578
+ if (state.parkTimer) return;
1579
+ state.parkTimer = setTimeout(() => {
1580
+ state.parkTimer = null;
1581
+ parkFarSections();
1582
+ }, 0);
1583
+ }
1584
+
1471
1585
  function focusFile(path) {
1472
- const section = state.els.stream.querySelector(`section.cg-file[data-path="${CSS.escape(path)}"]`);
1586
+ const selector = `section.cg-file[data-path="${CSS.escape(path)}"]`;
1587
+ let section = state.els.stream.querySelector(selector);
1588
+ if (!section) {
1589
+ // The row lives past the mounted batches: mount up to it, then retry.
1590
+ const index = state.files.findIndex((f) => f.path === path);
1591
+ while (index >= 0 && state.mounted <= index && state.mounted < state.files.length) {
1592
+ mountNextBatch();
1593
+ }
1594
+ section = state.els.stream.querySelector(selector);
1595
+ }
1473
1596
  state.activePath = path;
1474
1597
  if (section) {
1475
1598
  setFileCollapsed(path, false);
@@ -1480,6 +1603,7 @@
1480
1603
  if (section.querySelector(".cg-lazy")) loadFileDiff(path);
1481
1604
  }
1482
1605
  highlightTreeRow();
1606
+ schedulePark();
1483
1607
  }
1484
1608
 
1485
1609
  function highlightTreeRow() {
@@ -1565,7 +1689,11 @@
1565
1689
  if (next === !!record.collapsed) return;
1566
1690
  record.collapsed = next;
1567
1691
  const section = state.els.stream.querySelector(`section.cg-file[data-path="${CSS.escape(path)}"]`);
1568
- if (section) section.classList.toggle("is-collapsed", next);
1692
+ if (section) {
1693
+ // Collapsing changes the height a parked section was holding.
1694
+ unparkSection(section);
1695
+ section.classList.toggle("is-collapsed", next);
1696
+ }
1569
1697
  }
1570
1698
 
1571
1699
  function collapseAll() {
@@ -1675,12 +1803,11 @@
1675
1803
  state.sessionId = sessionId;
1676
1804
  state.files = sortFiles(data.files || []);
1677
1805
  state.note = data.note || null;
1678
- state.branch = data.branch || "";
1679
- // A fresh "branch" scope has no pick yet: adopt the base the server
1680
- // resolved (upstream / origin/main) so the compare pill shows a real name
1806
+ // A fresh "branch" scope has no pick yet: adopt the branch the server
1807
+ // resolved (the current one) so the compare pill shows a real name
1681
1808
  // instead of a placeholder. "committed" never does this - its base is the
1682
1809
  // upstream, not one of the commits listed in the menu.
1683
- if (state.scope === "branch" && !state.base && data.base) state.base = data.base;
1810
+ if (state.scope === "branch" && !state.target && data.target) state.target = data.target;
1684
1811
  if (ctx && ctx.setBadge) ctx.setBadge(state.files.length || null);
1685
1812
 
1686
1813
  renderStats(data);
@@ -1772,20 +1899,20 @@
1772
1899
  if (compare) stats.appendChild(compare);
1773
1900
  }
1774
1901
 
1775
- // `head → base`: which pair of branches is on screen. Only the right-hand
1776
- // side is a picker - the left one is whatever HEAD points at, so it stays
1777
- // plain text rather than pretending to be selectable.
1902
+ // `base → target`: which pair of branches is on screen. Only the right-hand
1903
+ // side is a picker - the left one is the repository's default branch, so it
1904
+ // stays plain text rather than pretending to be selectable.
1778
1905
  function comparePill(data) {
1779
1906
  if (state.scope !== "branch") return null;
1780
- const head = state.branch || "HEAD";
1781
- const base = state.base || data.base || t("changes.compare.unset", "选择对比分支");
1907
+ const base = data.base || t("changes.compare.unset", "选择对比分支");
1908
+ const target = state.target || data.target || t("changes.compare.unset", "选择对比分支");
1782
1909
  const btn = el("button", { class: "cg-scope cg-compare", type: "button",
1783
- title: t("changes.compare.title", "选择对比分支") });
1784
- btn.appendChild(el("span", { class: "cg-scope-head", text: head }));
1910
+ title: t("changes.compare.title", "选择要查看的分支") });
1911
+ btn.appendChild(el("span", { class: "cg-scope-head", text: base }));
1785
1912
  const arrow = el("span", { class: "cg-compare-arrow" });
1786
1913
  arrow.innerHTML = ICON_ARROW_RIGHT;
1787
1914
  btn.appendChild(arrow);
1788
- btn.appendChild(el("span", { class: "cg-scope-base", text: base }));
1915
+ btn.appendChild(el("span", { class: "cg-scope-base", text: target }));
1789
1916
  const caret = el("span", { class: "cg-caret" });
1790
1917
  caret.innerHTML = ICON_CARET_DOWN;
1791
1918
  btn.appendChild(caret);
@@ -1800,7 +1927,7 @@
1800
1927
  // The pill above the file tree switches which slice of history is on screen.
1801
1928
  // "已提交" opens a second-level list of commits (the comparison base defaults
1802
1929
  // to the upstream); "分支" is a plain row - picking it swaps the toolbar to
1803
- // the `head → base` compare pill, where the base is chosen.
1930
+ // the `base → target` compare pill, where the branch under review is chosen.
1804
1931
  let scopeMenuEl = null;
1805
1932
  let refMenuEl = null;
1806
1933
  let refAnchor = null;
@@ -1952,25 +2079,40 @@
1952
2079
  listEl.appendChild(el("div", { class: "cg-scope-empty", text: text }));
1953
2080
  return;
1954
2081
  }
1955
- rows.forEach((item) => {
1956
- if (kind === "branches") {
1957
- const checked = state.scope === "branch" && state.base === item.name;
1958
- const row = el("div", { class: "cg-scope-branch" + (checked ? " is-checked" : ""), "data-branch": item.name });
1959
- const icon = el("span", {});
1960
- icon.innerHTML = ICON_BRANCH;
1961
- row.appendChild(icon);
1962
- row.appendChild(el("span", { class: "cg-scope-name", text: item.name }));
1963
- const check = el("span", { class: "cg-scope-check" });
1964
- check.innerHTML = ICON_CHECK;
1965
- row.appendChild(check);
1966
- row.addEventListener("click", (ev) => {
1967
- ev.stopPropagation();
1968
- onPick(item.name);
2082
+ if (kind === "branches") {
2083
+ // The server hands back both kinds newest-first, so `origin/x` lands next
2084
+ // to `x`. Split them the way VS Code's ref picker does - local group on
2085
+ // top - and keep the newest-first order inside each group.
2086
+ const groups = [
2087
+ { remote: false, label: t("changes.scope.localBranches", "本地分支") },
2088
+ { remote: true, label: t("changes.scope.remoteBranches", "远程分支") },
2089
+ ];
2090
+ groups.forEach((group) => {
2091
+ const members = rows.filter((item) => Boolean(item.remote) === group.remote);
2092
+ if (!members.length) return;
2093
+ listEl.appendChild(el("div", { class: "cg-scope-group", text: group.label }));
2094
+ members.forEach((item) => {
2095
+ const checked = state.scope === "branch" && state.target === item.name;
2096
+ const row = el("div", { class: "cg-scope-branch" + (checked ? " is-checked" : ""), "data-branch": item.name });
2097
+ const icon = el("span", {});
2098
+ icon.innerHTML = ICON_BRANCH;
2099
+ row.appendChild(icon);
2100
+ row.appendChild(el("span", { class: "cg-scope-name", text: item.name }));
2101
+ const check = el("span", { class: "cg-scope-check" });
2102
+ check.innerHTML = ICON_CHECK;
2103
+ row.appendChild(check);
2104
+ row.addEventListener("click", (ev) => {
2105
+ ev.stopPropagation();
2106
+ onPick(item.name);
2107
+ });
2108
+ listEl.appendChild(row);
1969
2109
  });
1970
- listEl.appendChild(row);
1971
- return;
1972
- }
2110
+ });
2111
+ return;
2112
+ }
1973
2113
 
2114
+ listEl.appendChild(el("div", { class: "cg-scope-group", text: t("changes.scope.unpushedCommits", "未推送的提交") }));
2115
+ rows.forEach((item) => {
1974
2116
  // Every row reviews that commit on its own: the panel answers "what did
1975
2117
  // this commit change", which is what picking a commit in the list means.
1976
2118
  const checked = state.commit === item.hash;
@@ -2007,11 +2149,7 @@
2007
2149
  const input = el("input", { type: "search", placeholder: placeholder });
2008
2150
  searchWrap.appendChild(input);
2009
2151
  const list = el("div", { class: "cg-scope-list" });
2010
- const group = kind === "branches"
2011
- ? t("changes.scope.branch", "分支")
2012
- : t("changes.scope.unpushedCommits", "未推送的提交");
2013
2152
  sub.appendChild(searchWrap);
2014
- sub.appendChild(el("div", { class: "cg-scope-group", text: group }));
2015
2153
  sub.appendChild(list);
2016
2154
  sub.addEventListener("click", (ev) => ev.stopPropagation());
2017
2155
  document.body.appendChild(sub);
@@ -2047,8 +2185,11 @@
2047
2185
 
2048
2186
  function applyScope(scope, value) {
2049
2187
  state.scope = scope;
2050
- if (scope === "branch") state.base = value || "";
2051
- else if (scope === "committed") state.commit = value || "";
2188
+ // Switching scope must not throw the branch under review away; only picking
2189
+ // a branch from the compare pill changes it.
2190
+ if (scope === "branch") {
2191
+ if (value) state.target = value;
2192
+ } else if (scope === "committed") state.commit = value || "";
2052
2193
  state.note = null;
2053
2194
  closeScopeMenu();
2054
2195
  // Picking a scope does not change the repo, so the cached ref lists stay.
@@ -2119,10 +2260,7 @@
2119
2260
  const tools = el("div", { class: "cg-tools" },
2120
2261
  layoutBtn, wrapBtn, expandBtn, treeBtn, findBtn, refreshBtn);
2121
2262
 
2122
- const bar = el("div", { class: "cg-bar" },
2123
- stats,
2124
- el("span", { class: "cg-bar-spacer" }),
2125
- tools);
2263
+ const bar = el("div", { class: "cg-bar" }, stats, tools);
2126
2264
 
2127
2265
  const filter = el("input", { class: "cg-filter", type: "search",
2128
2266
  placeholder: t("changes.filter", "筛选文件…") });
@@ -2145,9 +2283,8 @@
2145
2283
 
2146
2284
  if (state.sessionId && state.sessionId !== ctx.sessionId) {
2147
2285
  state.scope = "worktree";
2148
- state.base = "";
2286
+ state.target = "";
2149
2287
  state.commit = "";
2150
- state.branch = "";
2151
2288
  state.branches = null;
2152
2289
  state.commits = null;
2153
2290
  }
@@ -2189,6 +2326,8 @@
2189
2326
  if (scrollRaf) return;
2190
2327
  scrollRaf = requestAnimationFrame(() => {
2191
2328
  scrollRaf = null;
2329
+ fillViewport();
2330
+ parkFarSections();
2192
2331
  updateActiveRow();
2193
2332
  });
2194
2333
  });
@@ -36,7 +36,7 @@ Switch the session agent to **Knowledge Base** and ask. How it works:
36
36
 
37
37
  ### Titles and sources
38
38
 
39
- Uploaded md files may start with a small block that sets the title and source shown with the passage; without it the file name is used and the source stays empty:
39
+ Uploaded md / txt files may start with a small block that sets the title and source shown with the passage; without it the file name is used for both:
40
40
 
41
41
  ```markdown
42
42
  ---
@@ -36,7 +36,7 @@
36
36
 
37
37
  ### 资料的标题和出处
38
38
 
39
- 上传 md 文件时,可以在正文前加一小段说明,自定义标题和出处;不写就用文件名,出处留空:
39
+ 上传 md / txt 文件时,可以在正文前加一小段说明,自定义标题和出处;不写就用文件名当标题,出处也用文件名:
40
40
 
41
41
  ```markdown
42
42
  ---
@@ -35,7 +35,7 @@ module Clacky
35
35
  title = File.basename(filename, File.extname(filename))
36
36
  if TEXT_EXTS.include?(ext)
37
37
  meta, body = @store.parse_markdown(File.read(path, encoding: "UTF-8").scrub(""))
38
- { title: (meta["title"] || title).to_s, source: meta["source"], body: body, parsed: false }
38
+ { title: (meta["title"] || title).to_s, source: meta["source"] || filename, body: body, parsed: false }
39
39
  else
40
40
  { title: title, source: filename, body: parse_document(path), parsed: true }
41
41
  end
@@ -1,5 +1,5 @@
1
- // Knowledge Base - full-page workspace mounted from the sidebar (below
2
- // Creator Center). Opens at #ext/knowledge:
1
+ // Knowledge Base - full-page workspace mounted from the sidebar (end of the
2
+ // More group). Opens at #ext/knowledge:
3
3
  // • root folders on the left (a book, a project…); the right side shows
4
4
  // the selected root with sub-folders of any depth and a breadcrumb
5
5
  // • "Add data source" → upload one file into the current folder (converted,
@@ -1174,7 +1174,7 @@
1174
1174
  document.addEventListener("langchange", () => { if (root && root.isConnected) renderPage(); });
1175
1175
 
1176
1176
  Clacky.ext.ui.registerWorkspace(WS_ID, { title: t("ws.title"), render });
1177
- // order 110: right below Creator Center (default order 100).
1177
+ // Lands at the end of the More group, after profile / data / billing.
1178
1178
  Clacky.ext.ui.mount("sidebar.nav.bottom", navRow, { workspace: WS_ID, order: 110 });
1179
1179
 
1180
1180
  const ACCENT = "var(--color-accent-primary)";
@@ -135,16 +135,28 @@ class MeetingExt < Clacky::ApiExtension
135
135
 
136
136
  if result["success"]
137
137
  text = result["text"].to_s.strip
138
+ record_stt_usage(result, sid)
138
139
  transcript_path = File.join(dir, "transcript.jsonl")
139
140
  if !text.empty? && !hallucinated_transcript?(text, vocabulary, transcript_path)
140
141
  entry = { ts: Time.now.utc.iso8601, text: text }
141
- File.open(transcript_path, "a") { |f| f.puts(JSON.generate(entry)) }
142
+ begin
143
+ File.open(transcript_path, "a") { |f| f.puts(JSON.generate(entry)) }
144
+ rescue Errno::ENOENT
145
+ # /cancel can move the meeting into .trash while STT is still running.
146
+ error!("meeting not found", status: 404)
147
+ end
142
148
  json(text: text)
143
149
  else
144
150
  json(text: "")
145
151
  end
146
152
  else
147
- error!(result["error"] || "STT failed", status: 502)
153
+ # Missing STT is a settings gap, not a service failure — the panel turns
154
+ # this type into a message with a jump to that settings row.
155
+ if result["error_type"] == "not_configured"
156
+ error!("No speech-to-text model is configured.", status: 422, error_type: "stt_not_configured")
157
+ else
158
+ error!(result["error"] || "STT failed", status: 502)
159
+ end
148
160
  end
149
161
  end
150
162
 
@@ -403,4 +415,13 @@ class MeetingExt < Clacky::ApiExtension
403
415
  logger.error("STT call failed: #{e.message}")
404
416
  { "success" => false, "text" => nil, "error" => e.message }
405
417
  end
418
+
419
+ # Every transcribed chunk costs money upstream, including the ones whose
420
+ # text is thrown away, so the ledger row is written before that decision.
421
+ private def record_stt_usage(result, session_id)
422
+ require_relative "../../../billing/media_usage"
423
+ Clacky::Billing::MediaUsage.record(result, session_id: session_id, kind: "stt")
424
+ rescue StandardError => e
425
+ logger.warn("STT billing record failed: #{e.message}")
426
+ end
406
427
  end