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
@@ -49,6 +49,7 @@ Clacky.ext = (() => {
49
49
  const _subscribers = {}; // event => [handler]
50
50
  const _slotRenderers = {}; // slot => [{ fn, extId, agents, panel, order, tab }]
51
51
  const _slotTabActivators = {}; // tabbed slot => activate(tabId) from the latest render
52
+ const _slotTabClosers = {}; // tabbed slot => closePanels(ids) from the latest render
52
53
  const _workspaces = {}; // id => { id, title, render, extId }
53
54
  let _currentExtId = null; // set while an extension file is loading
54
55
 
@@ -94,6 +95,7 @@ Clacky.ext = (() => {
94
95
  // _panelAgents[panel] = ["coding", ...] (agents whose profile.yml references the panel)
95
96
  // Resolved by the host before the extension scripts run (see loader markers).
96
97
  const _extAgents = {};
98
+ const _extLayers = {}; // extId => "builtin" | "installed" | "local"
97
99
  const _panelAgents = {};
98
100
  const _agentContributions = {}; // agent id => { panels:[{id,title,title_zh}], skills:[...] }
99
101
  let _currentPanel = null; // set while an official panel file is loading
@@ -182,6 +184,7 @@ Clacky.ext = (() => {
182
184
  render: _guard(render, label, extId),
183
185
  create: create ? _guard(create, `${label}#create`, extId) : null,
184
186
  extId,
187
+ layer: isBuiltin ? "host" : (_extLayers[extId] || null),
185
188
  agents: scoped,
186
189
  panel,
187
190
  order,
@@ -198,11 +201,12 @@ Clacky.ext = (() => {
198
201
  // a list of agent profile names it should appear for. `panel` marks a panel
199
202
  // whose agent scope is resolved separately via registerPanelAgents. Either
200
203
  // may be omitted for a global extension.
201
- function _extBegin(extId, agents, panel) {
204
+ function _extBegin(extId, agents, panel, layer) {
202
205
  if (PURE) return;
203
206
  _currentExtId = extId;
204
207
  if (Array.isArray(agents) && agents.length) _extAgents[extId] = agents;
205
208
  if (panel) _currentPanel = panel;
209
+ if (layer) _extLayers[extId] = String(layer);
206
210
  }
207
211
 
208
212
  function _extEnd() {
@@ -576,27 +580,190 @@ Clacky.ext = (() => {
576
580
  });
577
581
  }
578
582
 
583
+ // ── Aside tab strip ────────────────────────────────────────────────────────
584
+ // Which panels a session shows is the user's call, not the agent profile's.
585
+ // Nothing opens by default: a fresh session lands on the "+" picker (tools
586
+ // and extensions, two groups), and the open set is remembered per session so
587
+ // a session reopens the way the user left it.
588
+ const ASIDE_TAB_STORE_PREFIX = "clacky.aside.tabs."; // + sessionId → { open, active, t }
589
+ const ASIDE_NEW_TAB_ID = "__new__";
590
+ const ASIDE_TAB_STORE_MAX = 200; // sessions kept in localStorage
591
+
592
+ const ASIDE_PLUS_ICON =
593
+ '<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" ' +
594
+ 'stroke-width="1.5" stroke-linecap="round" aria-hidden="true">' +
595
+ '<path d="M8 3.2v9.6M3.2 8h9.6"/></svg>';
596
+ const ASIDE_CLOSE_ICON =
597
+ '<svg viewBox="0 0 16 16" width="10" height="10" fill="none" stroke="currentColor" ' +
598
+ 'stroke-width="1.6" stroke-linecap="round" aria-hidden="true">' +
599
+ '<path d="M4 4l8 8M12 4l-8 8"/></svg>';
600
+ const ASIDE_TAB_MENU_ICONS = {
601
+ close: '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M18 6L6 18M6 6l12 12"/></svg>',
602
+ closeOthers: '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 7h8"/><path d="M3 17h8"/><path d="m20 8-5 5"/><path d="m15 8 5 5"/></svg>',
603
+ closeRight: '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 4v16"/><path d="m20 8-6 6"/><path d="m14 8 6 6"/></svg>',
604
+ closeAll: '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="m9 9 6 6"/><path d="m15 9-6 6"/></svg>',
605
+ };
606
+ // Lucide outlines on a 24 grid, so a column of cards reads as one icon set
607
+ // instead of a stack of identical boxes. Keyed by tab id; panels may also
608
+ // ship their own glyph through `tab.icon` (an SVG string), which wins.
609
+ const ASIDE_GLYPHS = {
610
+ // The picker tab means "open a panel", so it gets a framed plus: a bare
611
+ // one is already the strip's own opener right next to it.
612
+ [ASIDE_NEW_TAB_ID]: '<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M8 12h8"/><path d="M12 8v8"/>',
613
+ files: '<path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/>',
614
+ changes: '<rect x="3" y="3" width="18" height="18" rx="3"/><path d="M12 7.5v4M10 9.5h4M10 16.5h4"/>',
615
+ tm: '<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/>',
616
+ preview: '<circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/>',
617
+ terminal: '<rect x="3" y="3" width="18" height="18" rx="3"/><path d="m8 9.5 2.5 2.5L8 14.5"/><path d="M13 15h4"/>',
618
+ meeting: '<path d="m16 13 5.22 3.06a.5.5 0 0 0 .78-.43V8.37a.5.5 0 0 0-.78-.43L16 11"/><rect x="2" y="6" width="14" height="12" rx="2"/>',
619
+ advisor: '<path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1.3.5 2.6 1.5 3.5.8.8 1.3 1.5 1.5 2.5"/><path d="M9 18h6"/><path d="M10 22h4"/>',
620
+ // Same clipboard as the extension's own logo, minus the two dots on the
621
+ // lines: at 15px they melt into the border and the whole glyph reads as
622
+ // dirt rather than a checklist.
623
+ "secretary-work": '<rect width="8" height="4" x="8" y="2" rx="1" ry="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><path d="M12 11h4"/><path d="M12 16h4"/>',
624
+ "ext-develop": '<path d="M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73Z"/><path d="M12 22V12"/><path d="m3.3 7 7.7 4.4a2 2 0 0 0 2 0L20.7 7"/>',
625
+ knowledge: '<path d="M12 7v14"/><path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z"/>',
626
+ "computer-use": '<path d="M14 4.1 12 6"/><path d="m5.1 8-2.9-.8"/><path d="m6 12-1.9 2"/><path d="M7.2 2.2 8 5.1"/><path d="M9.04 9.69a.5.5 0 0 1 .65-.65l11 4.5a.5.5 0 0 1-.07.95l-4.35 1.04a1 1 0 0 0-.74.74l-1.04 4.35a.5.5 0 0 1-.95.07z"/>'
627
+ };
628
+ function _asideGlyph(panelId) {
629
+ return ASIDE_GLYPHS[String(panelId || "").split("/").pop()] || null;
630
+ }
631
+
632
+ // One wrapper so every glyph shares size and stroke weight. Empty string
633
+ // when the panel has no glyph of its own: one shared placeholder on every
634
+ // extension read as clutter, so those entries render label-only.
635
+ function _asideGlyphSvg(panelId, size) {
636
+ const glyph = _asideGlyph(panelId);
637
+ if (!glyph) return "";
638
+ const px = size || 15;
639
+ return '<svg viewBox="0 0 24 24" width="' + px + '" height="' + px + '" fill="none" ' +
640
+ 'stroke="currentColor" stroke-width="1.7" stroke-linecap="round" ' +
641
+ 'stroke-linejoin="round" aria-hidden="true">' + glyph + "</svg>";
642
+ }
643
+
644
+ // Panel-supplied SVG wins; otherwise the built-in glyph for its id.
645
+ function _asideIconFor(entry, size) {
646
+ const custom = entry && entry.tab && entry.tab.icon;
647
+ if (typeof custom === "string" && custom.trim()) return custom;
648
+ return _asideGlyphSvg(entry && entry.tab && entry.tab.id, size);
649
+ }
650
+
651
+ // Panels this agent may open at all. An extension written for one agent
652
+ // (explicit `agents: [...]`) stays confined to it; everything else is the
653
+ // user's to open, whatever agent they happen to be on.
654
+ function _usableFor(entry, profile) {
655
+ if (!entry.agents || entry.agents.length === 0) return true;
656
+ return !!profile && entry.agents.includes(profile);
657
+ }
658
+
659
+ function _asideTabSessionKey(sessionId) {
660
+ return sessionId != null && sessionId !== "" ? String(sessionId) : "__default__";
661
+ }
662
+
663
+ function _asideTabsGet(sessionKey) {
664
+ try {
665
+ const raw = window.localStorage.getItem(ASIDE_TAB_STORE_PREFIX + sessionKey);
666
+ const v = raw ? JSON.parse(raw) : null;
667
+ if (!v || !Array.isArray(v.open)) return null;
668
+ return {
669
+ open: v.open.filter((id) => typeof id === "string"),
670
+ active: typeof v.active === "string" ? v.active : null,
671
+ };
672
+ } catch (_e) {
673
+ // A corrupt record just means an empty tab strip — rebuilt on next edit.
674
+ return null;
675
+ }
676
+ }
677
+
678
+ // The cap still matters even with one key per session: sessions deleted while
679
+ // the page was closed leave their record behind, so drop the oldest.
680
+ function _asideTabsPrune() {
681
+ try {
682
+ const entries = [];
683
+ for (let i = 0; i < window.localStorage.length; i++) {
684
+ const key = window.localStorage.key(i);
685
+ if (!key || key.indexOf(ASIDE_TAB_STORE_PREFIX) !== 0) continue;
686
+ let t = 0;
687
+ try { t = JSON.parse(window.localStorage.getItem(key) || "{}").t || 0; } catch (_e) { t = 0; }
688
+ entries.push({ key: key, t: t });
689
+ }
690
+ if (entries.length <= ASIDE_TAB_STORE_MAX) return;
691
+ entries.sort((a, b) => a.t - b.t);
692
+ entries.slice(0, entries.length - ASIDE_TAB_STORE_MAX)
693
+ .forEach((e) => window.localStorage.removeItem(e.key));
694
+ } catch (_e) {
695
+ // Quota / private mode: nothing to prune.
696
+ }
697
+ }
698
+
699
+ function _asideTabsSet(sessionKey, value) {
700
+ try {
701
+ window.localStorage.setItem(
702
+ ASIDE_TAB_STORE_PREFIX + sessionKey,
703
+ JSON.stringify({ open: value.open.slice(), active: value.active, t: Date.now() })
704
+ );
705
+ } catch (_e) {
706
+ // Quota / private mode: the strip still works for this page.
707
+ }
708
+ _asideTabsPrune();
709
+ }
710
+
711
+ function _asideTabsForget(sessionId) {
712
+ if (sessionId == null || sessionId === "") return;
713
+ try {
714
+ window.localStorage.removeItem(ASIDE_TAB_STORE_PREFIX + _asideTabSessionKey(sessionId));
715
+ } catch (_e) { /* ignore */ }
716
+ }
717
+
579
718
  // Render a tabbed slot: a tab bar across the top, one body shown at a time.
580
- // Each visible renderer (carrying entry.tab) becomes a tab; its body is
581
- // rendered lazily on first activation and cached for the lifetime of this
582
- // render pass. The host chrome (resize / collapse) lives in the surrounding
583
- // DOM and is not touched here. Re-rendered wholesale on every session switch.
719
+ //
720
+ // Nothing is open until the user opens it. The profile only decides which
721
+ // panels are *reachable* (an extension restricted to one agent stays there);
722
+ // everything else lives behind the "+" picker, which is itself a tab — so
723
+ // closing a tab and adding one read as the same gesture. A tab's body is
724
+ // rendered on first activation and destroyed on close, which releases its
725
+ // subscriptions and keeps a closed panel from fetching anything. The open
726
+ // set is persisted per session.
584
727
  function renderTabbedSlot(slot, container, ctx) {
585
- // Invalidate any activator captured by a previous render of this slot;
586
- // if this pass finds no renderers it must stay invalid.
728
+ // A menu left open points at callbacks of the strip being replaced.
729
+ _closeAsideTabMenu();
730
+ // Invalidate any activator/closer captured by a previous render of this
731
+ // slot; if this pass finds no renderers they must stay invalid.
587
732
  _slotTabActivators[slot] = null;
733
+ _slotTabClosers[slot] = null;
588
734
  const previousTabFrame = container.querySelector(".aside-tabs-frame");
589
- if (previousTabFrame && previousTabFrame._overflowCleanup) previousTabFrame._overflowCleanup();
735
+ if (previousTabFrame) {
736
+ if (previousTabFrame._overflowCleanup) previousTabFrame._overflowCleanup();
737
+ if (previousTabFrame._langCleanup) previousTabFrame._langCleanup();
738
+ }
590
739
  container.replaceChildren();
591
740
  const profile = (ctx && ctx.agentProfile) || context.agentProfile;
592
741
  const renderCtx = Object.assign({}, context, ctx || {});
593
742
 
594
- const renderers = (_slotRenderers[slot] || [])
743
+ const usable = (_slotRenderers[slot] || [])
595
744
  .slice()
596
745
  .sort((a, b) => a.order - b.order)
597
- .filter((e) => e.tab && _visibleFor(e, profile));
746
+ .filter((e) => e.tab && _usableFor(e, profile));
747
+
748
+ if (usable.length === 0) return; // empty slot → host CSS collapses it
598
749
 
599
- if (renderers.length === 0) return; // empty slot → host CSS collapses it
750
+ const sessionKey = _asideTabSessionKey(renderCtx.sessionId);
751
+ const byId = new Map(usable.map((e) => [e.tab.id, e]));
752
+ const saved = _asideTabsGet(sessionKey);
753
+
754
+ const state = {
755
+ open: saved ? saved.open.filter((id) => id === ASIDE_NEW_TAB_ID || byId.has(id)) : [],
756
+ active: null,
757
+ };
758
+ if (state.open.length === 0) {
759
+ state.active = ASIDE_NEW_TAB_ID;
760
+ } else if (saved.active === ASIDE_NEW_TAB_ID) {
761
+ state.active = ASIDE_NEW_TAB_ID;
762
+ } else if (saved.active && state.open.includes(saved.active)) {
763
+ state.active = saved.active;
764
+ } else {
765
+ state.active = state.open[0];
766
+ }
600
767
 
601
768
  const tabFrame = document.createElement("div");
602
769
  tabFrame.className = "aside-tabs-frame";
@@ -605,93 +772,409 @@ Clacky.ext = (() => {
605
772
  tabFrame.appendChild(tabBar);
606
773
  const bodies = document.createElement("div");
607
774
  bodies.className = "aside-bodies";
775
+ container.appendChild(tabFrame);
776
+ container.appendChild(bodies);
608
777
 
609
- // Always default to the first (highest-priority) tab. Tabs may register in
610
- // several async passes; whichever pass runs last simply lands on tab #1.
611
- const ids = renderers.map((e) => e.tab.id);
612
- const active = ids[0];
613
-
614
- const tabBtns = {};
615
- const bodyEls = {};
616
- const rendered = {};
617
-
618
- function activate(id) {
619
- if (!tabBtns[id]) return false;
620
- Object.keys(tabBtns).forEach((k) => tabBtns[k].classList.toggle("active", k === id));
621
- Object.keys(bodyEls).forEach((k) => bodyEls[k].classList.toggle("active", k === id));
622
- if (!rendered[id]) {
623
- rendered[id] = true;
624
- const entry = renderers.find((e) => e.tab.id === id);
625
- const body = bodyEls[id];
626
- const localCtx = Object.assign({}, renderCtx, {
627
- setBadge: (n) => _setTabBadge(tabBtns[id], n),
628
- });
629
- const { node, crashed, reason, extId } = _invokeRender(slot, entry, body, localCtx);
630
- if (crashed) {
631
- body.appendChild(_crashedPlaceholder(extId || entry.extId, reason));
632
- } else if (node != null) {
633
- if (typeof node === "string") body.innerHTML = node;
634
- else body.appendChild(node);
635
- }
778
+ // Parked outside the scrolling strip: however many tabs are open, the way
779
+ // to add another one never scrolls out of reach.
780
+ const addBtn = document.createElement("button");
781
+ addBtn.type = "button";
782
+ addBtn.className = "aside-tab-add";
783
+ addBtn.innerHTML = ASIDE_PLUS_ICON;
784
+ addBtn.setAttribute("aria-label", _asideText("aside.newTab", "New tab"));
785
+ addBtn.setAttribute("data-tooltip", _asideText("aside.newTab", "New tab"));
786
+ addBtn.setAttribute("data-tooltip-pos", "bottom");
787
+ addBtn.addEventListener("click", () => {
788
+ // Already on the picker: the opener has nowhere to go, so acknowledge
789
+ // the click instead of repainting an identical page.
790
+ if (state.active === ASIDE_NEW_TAB_ID) {
791
+ if (newTabBody) newTabBody.scrollTop = 0;
792
+ addBtn.classList.remove("is-nudging");
793
+ void addBtn.offsetWidth;
794
+ addBtn.classList.add("is-nudging");
795
+ return;
796
+ }
797
+ activate(ASIDE_NEW_TAB_ID);
798
+ });
799
+ addBtn.addEventListener("animationend", () => addBtn.classList.remove("is-nudging"));
800
+ tabFrame.appendChild(addBtn);
801
+
802
+ // Strip labels come from the dictionary, so a language switch has to
803
+ // repaint them instead of leaving the previous language behind.
804
+ const refreshStripText = () => {
805
+ const label = _asideText("aside.newTab", "New tab");
806
+ addBtn.setAttribute("aria-label", label);
807
+ addBtn.setAttribute("data-tooltip", label);
808
+ paint();
809
+ };
810
+ document.addEventListener("langchange", refreshStripText);
811
+ tabFrame._langCleanup = () => document.removeEventListener("langchange", refreshStripText);
812
+
813
+ const tabBtns = {}; // id => tab button (rebuilt on every paint)
814
+ const tabBadges = {}; // id => last badge value, so paints keep it
815
+ const bodyEls = {}; // id => body element (survives paints until closed)
816
+ const rendered = {}; // id => true once the panel body has run render
817
+ const attached = {}; // id => true once tab.onAttach has run
818
+ let newTabBody = null;
819
+
820
+ function labelOf(entry) {
821
+ const raw = entry.tab.label;
822
+ const label = typeof raw === "function" ? raw() : raw;
823
+ return label || entry.tab.id;
824
+ }
825
+
826
+ function persist() {
827
+ _asideTabsSet(sessionKey, { open: state.open, active: state.active });
828
+ }
829
+
830
+ function tabCtx(id) {
831
+ return Object.assign({}, renderCtx, {
832
+ setBadge: (n) => {
833
+ tabBadges[id] = n;
834
+ _setTabBadge(tabBtns[id], n);
835
+ },
836
+ });
837
+ }
838
+
839
+ function ensureBody(id) {
840
+ let body = bodyEls[id];
841
+ if (body) return body;
842
+ body = document.createElement("div");
843
+ body.className = "aside-panel";
844
+ body.setAttribute("data-panel", id);
845
+ bodies.appendChild(body);
846
+ bodyEls[id] = body;
847
+ return body;
848
+ }
849
+
850
+ function attachPanel(id) {
851
+ if (attached[id]) return;
852
+ attached[id] = true;
853
+ const entry = byId.get(id);
854
+ if (!entry || typeof entry.tab.onAttach !== "function") return;
855
+ const attachKey = _mountKey(slot, entry) + "::attach";
856
+ let teardown;
857
+ try {
858
+ teardown = entry.tab.onAttach(tabCtx(id));
859
+ } catch (err) {
860
+ console.error(`[Clacky.ext] onAttach for tab "${id}" threw:`, err);
861
+ teardown = null;
862
+ }
863
+ if (typeof teardown === "function" && renderCtx.sessionId) {
864
+ _rememberViewTeardown(renderCtx.sessionId, attachKey, teardown);
865
+ }
866
+ }
867
+
868
+ function renderBody(id) {
869
+ if (rendered[id]) return;
870
+ rendered[id] = true;
871
+ attachPanel(id);
872
+ const body = ensureBody(id);
873
+ const entry = byId.get(id);
874
+ const { node, crashed, reason, extId } = _invokeRender(slot, entry, body, tabCtx(id));
875
+ if (crashed) {
876
+ body.appendChild(_crashedPlaceholder(extId || entry.extId, reason));
877
+ } else if (node != null) {
878
+ if (typeof node === "string") body.innerHTML = node;
879
+ else body.appendChild(node);
880
+ }
881
+ }
882
+
883
+ function disposePanel(id) {
884
+ const entry = byId.get(id);
885
+ if (entry) {
886
+ const key = _mountKey(slot, entry);
887
+ _runViewTeardown(renderCtx.sessionId, key + "::attach");
888
+ _runViewTeardown(renderCtx.sessionId, key);
889
+ }
890
+ if (bodyEls[id]) {
891
+ bodyEls[id].remove();
892
+ delete bodyEls[id];
893
+ }
894
+ // The picker body is kept in its own handle and never lands in bodyEls,
895
+ // so it needs both the node and the handle cleared: leaving the node
896
+ // behind makes the next open paint a second copy next to the old one.
897
+ if (id === ASIDE_NEW_TAB_ID) {
898
+ if (newTabBody) newTabBody.remove();
899
+ newTabBody = null;
900
+ }
901
+ delete rendered[id];
902
+ delete attached[id];
903
+ delete tabBadges[id];
904
+ }
905
+
906
+ function ensureNewTabBody() {
907
+ if (newTabBody) return newTabBody;
908
+ newTabBody = document.createElement("div");
909
+ newTabBody.className = "aside-panel aside-newtab";
910
+ newTabBody.setAttribute("data-panel", ASIDE_NEW_TAB_ID);
911
+ bodies.appendChild(newTabBody);
912
+ return newTabBody;
913
+ }
914
+
915
+ function cardFor(entry) {
916
+ const btn = document.createElement("button");
917
+ btn.type = "button";
918
+ btn.className = "aside-newtab-card";
919
+ btn.setAttribute("data-panel-id", entry.tab.id);
920
+
921
+ const text = document.createElement("span");
922
+ text.className = "aside-newtab-text";
923
+
924
+ const name = document.createElement("span");
925
+ name.className = "aside-newtab-name";
926
+ name.textContent = labelOf(entry);
927
+ text.appendChild(name);
928
+
929
+ const desc = entry.tab && entry.tab.description;
930
+ if (desc) {
931
+ const sub = document.createElement("span");
932
+ sub.className = "aside-newtab-desc";
933
+ sub.textContent = desc;
934
+ text.appendChild(sub);
935
+ }
936
+
937
+ const iconHtml = _asideIconFor(entry);
938
+ if (iconHtml) {
939
+ const icon = document.createElement("span");
940
+ icon.className = "aside-newtab-icon";
941
+ icon.innerHTML = iconHtml;
942
+ btn.appendChild(icon);
943
+ }
944
+ btn.appendChild(text);
945
+ btn.addEventListener("click", () => activate(entry.tab.id, true));
946
+ return btn;
947
+ }
948
+
949
+ function group(titleKey, fallback, entries) {
950
+ if (entries.length === 0) return null;
951
+ const section = document.createElement("div");
952
+ section.className = "aside-newtab-group";
953
+ const heading = document.createElement("div");
954
+ heading.className = "aside-newtab-title";
955
+ heading.textContent = _asideText(titleKey, fallback);
956
+ section.appendChild(heading);
957
+ const grid = document.createElement("div");
958
+ grid.className = "aside-newtab-grid";
959
+ entries.forEach((entry) => grid.appendChild(cardFor(entry)));
960
+ section.appendChild(grid);
961
+ return section;
962
+ }
963
+
964
+ function renderNewTabPage() {
965
+ const body = ensureNewTabBody();
966
+ body.replaceChildren();
967
+
968
+ const closed = usable.filter((e) => !state.open.includes(e.tab.id));
969
+ if (closed.length === 0) {
970
+ const empty = document.createElement("div");
971
+ empty.className = "aside-newtab-empty";
972
+ empty.textContent = _asideText("aside.allOpen", "All panels are already open");
973
+ body.appendChild(empty);
974
+ return;
636
975
  }
976
+ // Split by where the panel comes from: host + official extensions ship
977
+ // with the product, the rest are installed from the market or written
978
+ // locally. Grouping by function would have to guess what a panel "is".
979
+ const official = closed.filter((e) => e.layer === "host" || e.layer === "builtin");
980
+ const mine = closed.filter((e) => e.layer !== "host" && e.layer !== "builtin");
981
+ [group("aside.group.official", "Official", official),
982
+ group("aside.group.mine", "Mine", mine)].forEach((section) => {
983
+ if (section) body.appendChild(section);
984
+ });
985
+ }
986
+
987
+ // `fromPicker` marks a pick made on the picker page: the picker has done
988
+ // its job, so it retires instead of lingering as a tab to close by hand.
989
+ function activate(id, fromPicker) {
990
+ if (id !== ASIDE_NEW_TAB_ID && !byId.has(id)) return false;
991
+ if (fromPicker) {
992
+ const pickerIndex = state.open.indexOf(ASIDE_NEW_TAB_ID);
993
+ if (pickerIndex >= 0) state.open.splice(pickerIndex, 1);
994
+ }
995
+ // Appends, so a newly opened panel always lands right of the others
996
+ // instead of being re-sorted into the extension's declared order. The
997
+ // picker is opened the same way: once the user asks for it, it is a tab
998
+ // that stays put while they look at their panels.
999
+ if (!state.open.includes(id)) state.open.push(id);
1000
+ state.active = id;
1001
+ persist();
1002
+ paint();
637
1003
  return true;
638
1004
  }
639
1005
  _slotTabActivators[slot] = activate;
1006
+ _slotTabClosers[slot] = closePanels;
1007
+
1008
+ // One gesture can close several tabs at once (context menu), so the batch
1009
+ // owns the whole sequence: drop them from the open set, dispose each body,
1010
+ // then repaint once. Closing them one by one would repaint between steps
1011
+ // and let the column collapse on the first tab of a batch.
1012
+ function closePanels(ids) {
1013
+ const doomed = new Set(ids);
1014
+ const closing = state.open.filter((id) => doomed.has(id));
1015
+ const pickerClosed = doomed.has(ASIDE_NEW_TAB_ID);
1016
+ if (closing.length === 0 && !pickerClosed) return;
640
1017
 
641
- renderers.forEach((entry) => {
642
- const id = entry.tab.id;
1018
+ // Where the active tab sat, so a close moves the selection to the same
1019
+ // slot rather than jumping to the front.
1020
+ const anchor = Math.max(state.open.indexOf(state.active), 0);
1021
+ state.open = state.open.filter((id) => !doomed.has(id));
1022
+ closing.forEach(disposePanel);
1023
+ if (pickerClosed) disposePanel(ASIDE_NEW_TAB_ID);
1024
+
1025
+ if (doomed.has(state.active)) {
1026
+ state.active = state.open.length
1027
+ ? state.open[Math.min(anchor, state.open.length - 1)]
1028
+ : ASIDE_NEW_TAB_ID;
1029
+ }
1030
+ persist();
1031
+ paint();
1032
+ // An emptied strip has nothing to show, so the column collapses instead
1033
+ // of silently falling back to the picker. That covers the picker itself
1034
+ // as well as the last real panel: reopening the panel brings the picker
1035
+ // back, which is where a fresh column starts anyway.
1036
+ if (state.open.length === 0 && window.Clacky && Clacky.Aside) {
1037
+ Clacky.Aside.close();
1038
+ }
1039
+ }
1040
+
1041
+ // The picker is visible without being in `open` while the strip is empty,
1042
+ // so "every tab" means the open set plus whatever is on screen right now.
1043
+ function allTabsFor(id) {
1044
+ return state.open.includes(id) ? state.open.slice() : state.open.concat([id]);
1045
+ }
1046
+
1047
+ function closePanel(id) {
1048
+ closePanels([id]);
1049
+ }
1050
+
1051
+ function tabMenu(e, id) {
1052
+ const peers = allTabsFor(id);
1053
+ const index = peers.indexOf(id);
1054
+ _showAsideTabMenu(e, {
1055
+ // "Close to the Right" has nothing to act on for the rightmost tab;
1056
+ // the entry stays in place so the menu does not shift, but is inert.
1057
+ hasTabsToTheRight: index >= 0 && index < peers.length - 1,
1058
+ onClose: (menu) => { _closeAsideTabMenu(menu); closePanel(id); },
1059
+ onCloseOthers: (menu) => { _closeAsideTabMenu(menu); closePanels(peers.filter((x) => x !== id)); },
1060
+ onCloseToRight: (menu) => { _closeAsideTabMenu(menu); closePanels(peers.slice(index + 1)); },
1061
+ onCloseAll: (menu) => { _closeAsideTabMenu(menu); closePanels(peers); },
1062
+ });
1063
+ }
1064
+
1065
+ function tabButton(id, label, entry) {
643
1066
  const btn = document.createElement("button");
644
1067
  btn.className = "aside-tab";
645
1068
  btn.type = "button";
646
1069
  btn.setAttribute("data-tab", id);
647
- const label = document.createElement("span");
648
- label.textContent = (typeof entry.tab.label === "function" ? entry.tab.label() : entry.tab.label) || id;
649
- btn.appendChild(label);
650
- if (entry.tab.badge != null) _setTabBadge(btn, entry.tab.badge);
1070
+ btn.classList.toggle("active", state.active === id);
1071
+
1072
+ const iconHtml = id === ASIDE_NEW_TAB_ID
1073
+ ? _asideGlyphSvg(ASIDE_NEW_TAB_ID, 14)
1074
+ : _asideIconFor(entry, 14);
1075
+ if (iconHtml) {
1076
+ const icon = document.createElement("span");
1077
+ icon.className = "aside-tab-icon";
1078
+ icon.innerHTML = iconHtml;
1079
+ btn.appendChild(icon);
1080
+ }
1081
+
1082
+ const text = document.createElement("span");
1083
+ text.className = "aside-tab-label";
1084
+ text.textContent = label;
1085
+ btn.appendChild(text);
1086
+
1087
+ if (entry && entry.tab.badge != null) _setTabBadge(btn, entry.tab.badge);
1088
+ if (tabBadges[id] != null) _setTabBadge(btn, tabBadges[id]);
1089
+
1090
+ // Every tab can be closed by hand, the picker included. Emptying the
1091
+ // strip this way collapses the whole column, which is the gesture the
1092
+ // user expects from that ×.
1093
+ const close = document.createElement("span");
1094
+ close.className = "aside-tab-close";
1095
+ close.setAttribute("role", "button");
1096
+ close.setAttribute("aria-label", _asideText("aside.closeTab", "Close tab"));
1097
+ close.title = _asideText("aside.closeTab", "Close tab");
1098
+ close.innerHTML = ASIDE_CLOSE_ICON;
1099
+ close.addEventListener("click", (event) => {
1100
+ event.stopPropagation();
1101
+ closePanel(id);
1102
+ });
1103
+ btn.appendChild(close);
1104
+
651
1105
  btn.addEventListener("click", () => activate(id));
1106
+ btn.addEventListener("contextmenu", (event) => {
1107
+ event.preventDefault();
1108
+ tabMenu(event, id);
1109
+ });
652
1110
  tabBtns[id] = btn;
653
1111
  tabBar.appendChild(btn);
1112
+ }
654
1113
 
655
- const body = document.createElement("div");
656
- body.className = "aside-panel";
657
- body.setAttribute("data-panel", id);
658
- bodyEls[id] = body;
659
- bodies.appendChild(body);
1114
+ function paint() {
1115
+ Object.keys(tabBtns).forEach((k) => delete tabBtns[k]);
1116
+ tabBar.replaceChildren();
1117
+ state.open.forEach((id) => {
1118
+ if (id === ASIDE_NEW_TAB_ID) tabButton(id, _asideText("aside.newTab", "New tab"), null);
1119
+ else tabButton(id, labelOf(byId.get(id)), byId.get(id));
1120
+ });
1121
+ if (state.active === ASIDE_NEW_TAB_ID && !state.open.includes(ASIDE_NEW_TAB_ID)) {
1122
+ tabButton(ASIDE_NEW_TAB_ID, _asideText("aside.newTab", "New tab"), null);
1123
+ }
660
1124
 
661
- // Eager init: a tab can run setup (surface a badge, pre-fetch data,
662
- // start a subscription) before the user ever opens it. onAttach runs
663
- // immediately with a ctx carrying sessionId + setBadge; returning a
664
- // function registers it as a teardown run on the next render pass /
665
- // session switch. Any tab may opt in — no per-extension wiring needed.
666
- if (typeof entry.tab.onAttach === "function") {
667
- const attachKey = _mountKey(slot, entry) + "::attach";
668
- // Re-running within the same session (rare, e.g. a host re-render)
669
- // must release the previous teardown first to avoid leaks.
670
- _runViewTeardown(renderCtx.sessionId, attachKey);
671
- const attachCtx = Object.assign({}, renderCtx, {
672
- setBadge: (n) => _setTabBadge(tabBtns[id], n),
673
- });
674
- let teardown;
675
- try {
676
- teardown = entry.tab.onAttach(attachCtx);
677
- } catch (err) {
678
- console.error(`[Clacky.ext] onAttach for tab "${id}" threw:`, err);
679
- teardown = null;
680
- }
681
- if (typeof teardown === "function" && renderCtx.sessionId) {
682
- _rememberViewTeardown(renderCtx.sessionId, attachKey, teardown);
683
- }
1125
+ Object.keys(bodyEls).forEach((id) => {
1126
+ bodyEls[id].classList.toggle("active", state.active === id);
1127
+ });
1128
+
1129
+ if (state.active === ASIDE_NEW_TAB_ID) {
1130
+ if (newTabBody) newTabBody.classList.remove("active");
1131
+ renderNewTabPage();
1132
+ newTabBody.scrollTop = 0;
1133
+ newTabBody.classList.add("active");
1134
+ } else {
1135
+ if (newTabBody) newTabBody.classList.remove("active");
1136
+ renderBody(state.active);
1137
+ ensureBody(state.active).classList.add("active");
684
1138
  }
685
- });
686
1139
 
687
- container.appendChild(tabFrame);
688
- container.appendChild(bodies);
1140
+ revealActiveTab();
1141
+ // Feeds the CSS width formula: every tab shares the strip's free width.
1142
+ tabFrame.style.setProperty("--aside-tab-count", String(tabBar.childElementCount));
1143
+
1144
+ const maxScroll = Math.max(0, tabBar.scrollWidth - tabBar.clientWidth);
1145
+ tabFrame.classList.toggle("can-scroll-left", tabBar.scrollLeft > 1);
1146
+ tabFrame.classList.toggle("can-scroll-right", tabBar.scrollLeft < maxScroll - 1);
1147
+ }
1148
+
1149
+ // A freshly opened tab can land outside the strip; nudge the scroll so the
1150
+ // active item stays readable instead of hiding under the "+" opener.
1151
+ function revealActiveTab() {
1152
+ const btn = tabBtns[state.active];
1153
+ if (!btn) return;
1154
+ const reserve = parseFloat(getComputedStyle(tabBar).paddingRight) || 0;
1155
+ const barRect = tabBar.getBoundingClientRect();
1156
+ const btnRect = btn.getBoundingClientRect();
1157
+ const visibleRight = barRect.right - reserve;
1158
+ if (btnRect.right > visibleRight) {
1159
+ tabBar.scrollLeft += btnRect.right - visibleRight;
1160
+ } else if (btnRect.left < barRect.left) {
1161
+ tabBar.scrollLeft -= barRect.left - btnRect.left;
1162
+ }
1163
+ }
689
1164
 
690
1165
  const syncOverflowCues = () => {
691
1166
  const maxScroll = Math.max(0, tabBar.scrollWidth - tabBar.clientWidth);
692
1167
  tabFrame.classList.toggle("can-scroll-left", tabBar.scrollLeft > 1);
693
1168
  tabFrame.classList.toggle("can-scroll-right", tabBar.scrollLeft < maxScroll - 1);
694
1169
  };
1170
+ // A label too long for its pill is clipped rather than ellipsised, so it
1171
+ // needs a soft edge: flag the ones actually cut and let CSS fade them out.
1172
+ const syncClippedLabels = () => {
1173
+ Object.keys(tabBtns).forEach((id) => {
1174
+ const label = tabBtns[id].querySelector(".aside-tab-label");
1175
+ if (label) tabBtns[id].classList.toggle("is-clipped", label.scrollWidth > label.clientWidth + 1);
1176
+ });
1177
+ };
695
1178
  const scrollTabsWithWheel = (event) => {
696
1179
  // Preserve native horizontal trackpad gestures. A predominantly vertical
697
1180
  // wheel gesture is translated only while the strip can move that way.
@@ -704,22 +1187,103 @@ Clacky.ext = (() => {
704
1187
  event.preventDefault();
705
1188
  tabBar.scrollLeft = nextScroll;
706
1189
  };
1190
+ const onStripResize = () => {
1191
+ syncOverflowCues();
1192
+ syncClippedLabels();
1193
+ };
707
1194
  tabBar.addEventListener("scroll", syncOverflowCues, { passive: true });
708
1195
  tabBar.addEventListener("wheel", scrollTabsWithWheel, { passive: false });
709
- const resizeObserver = window.ResizeObserver ? new ResizeObserver(syncOverflowCues) : null;
710
- const mutationObserver = window.MutationObserver ? new MutationObserver(syncOverflowCues) : null;
1196
+ const resizeObserver = window.ResizeObserver ? new ResizeObserver(onStripResize) : null;
1197
+ const mutationObserver = window.MutationObserver ? new MutationObserver(onStripResize) : null;
711
1198
  if (resizeObserver) resizeObserver.observe(tabBar);
712
1199
  if (mutationObserver) mutationObserver.observe(tabBar, { childList: true, subtree: true, characterData: true });
713
- if (!resizeObserver) window.addEventListener("resize", syncOverflowCues);
1200
+ if (!resizeObserver) window.addEventListener("resize", onStripResize);
714
1201
  tabFrame._overflowCleanup = () => {
715
1202
  tabBar.removeEventListener("scroll", syncOverflowCues);
716
1203
  tabBar.removeEventListener("wheel", scrollTabsWithWheel);
717
1204
  if (resizeObserver) resizeObserver.disconnect();
718
- else window.removeEventListener("resize", syncOverflowCues);
1205
+ else window.removeEventListener("resize", onStripResize);
719
1206
  if (mutationObserver) mutationObserver.disconnect();
720
1207
  };
721
- requestAnimationFrame(syncOverflowCues);
722
- activate(active);
1208
+
1209
+ paint();
1210
+ requestAnimationFrame(onStripResize);
1211
+ }
1212
+
1213
+ // Translate a tab-strip string, falling back when i18n isn't loaded yet.
1214
+ // I18n hangs off Clacky, not window: reading window.I18n would silently pin
1215
+ // every strip label to English.
1216
+ function _asideText(key, fallback) {
1217
+ const i18n = window.Clacky && window.Clacky.I18n;
1218
+ if (!i18n || typeof i18n.t !== "function") return fallback;
1219
+ const value = i18n.t(key);
1220
+ return value && value !== key ? value : fallback;
1221
+ }
1222
+
1223
+ // Right-click on a tab. Mirrors the file viewer's tab menu so the two strips
1224
+ // answer the same gesture the same way; only the entries differ, because an
1225
+ // aside tab has no file behind it.
1226
+ let _asideTabMenuEl = null;
1227
+
1228
+ function _closeAsideTabMenu(menu) {
1229
+ const el = menu || _asideTabMenuEl;
1230
+ if (el) el.remove();
1231
+ if (el === _asideTabMenuEl) _asideTabMenuEl = null;
1232
+ }
1233
+
1234
+ function _showAsideTabMenu(event, handlers) {
1235
+ _closeAsideTabMenu();
1236
+ const icon = ASIDE_TAB_MENU_ICONS;
1237
+ const menu = document.createElement("div");
1238
+ menu.className = "session-context-menu aside-tab-menu";
1239
+ menu.innerHTML = `
1240
+ <div class="session-actions-menu-item" data-action="close">
1241
+ <span class="session-actions-menu-icon">${icon.close}</span>
1242
+ <span class="session-actions-menu-label">${_asideText("aside.close", "Close")}</span>
1243
+ </div>
1244
+ <div class="session-actions-menu-item" data-action="closeOthers">
1245
+ <span class="session-actions-menu-icon">${icon.closeOthers}</span>
1246
+ <span class="session-actions-menu-label">${_asideText("aside.closeOthers", "Close Others")}</span>
1247
+ </div>
1248
+ <div class="session-actions-menu-item${handlers.hasTabsToTheRight ? "" : " session-actions-menu-item--disabled"}" data-action="closeRight">
1249
+ <span class="session-actions-menu-icon">${icon.closeRight}</span>
1250
+ <span class="session-actions-menu-label">${_asideText("aside.closeRight", "Close to the Right")}</span>
1251
+ </div>
1252
+ <div class="session-actions-menu-item" data-action="closeAll">
1253
+ <span class="session-actions-menu-icon">${icon.closeAll}</span>
1254
+ <span class="session-actions-menu-label">${_asideText("aside.closeAll", "Close All")}</span>
1255
+ </div>
1256
+ `;
1257
+ document.body.appendChild(menu);
1258
+ _asideTabMenuEl = menu;
1259
+
1260
+ menu.style.position = "fixed";
1261
+ menu.style.top = event.clientY + "px";
1262
+ menu.style.left = event.clientX + "px";
1263
+ requestAnimationFrame(() => {
1264
+ const r = menu.getBoundingClientRect();
1265
+ if (r.right > window.innerWidth) menu.style.left = (window.innerWidth - r.width - 8) + "px";
1266
+ if (r.bottom > window.innerHeight) menu.style.top = (window.innerHeight - r.height - 8) + "px";
1267
+ });
1268
+
1269
+ menu.addEventListener("click", (ev) => {
1270
+ const item = ev.target.closest(".session-actions-menu-item");
1271
+ if (!item) return;
1272
+ if (item.classList.contains("session-actions-menu-item--disabled")) {
1273
+ _closeAsideTabMenu(menu);
1274
+ return;
1275
+ }
1276
+ const action = item.dataset.action;
1277
+ if (action === "close") handlers.onClose(menu);
1278
+ else if (action === "closeOthers") handlers.onCloseOthers(menu);
1279
+ else if (action === "closeRight") handlers.onCloseToRight(menu);
1280
+ else if (action === "closeAll") handlers.onCloseAll(menu);
1281
+ });
1282
+
1283
+ setTimeout(() => {
1284
+ document.addEventListener("click", () => _closeAsideTabMenu(menu), { once: true });
1285
+ document.addEventListener("contextmenu", () => _closeAsideTabMenu(menu), { once: true });
1286
+ }, 0);
723
1287
  }
724
1288
 
725
1289
  // Set or clear a tab's badge pill. n == null/0 removes it.
@@ -751,6 +1315,17 @@ Clacky.ext = (() => {
751
1315
  return activate ? !!activate(tabId) : false;
752
1316
  }
753
1317
 
1318
+ // Programmatically close a tab in a tabbed slot — the same path as the × on
1319
+ // the tab: the body is disposed and an emptied column collapses. A panel
1320
+ // uses this to retire itself once its work is done (the terminal does it
1321
+ // when its shell exits).
1322
+ function closeTab(slot, tabId) {
1323
+ const closer = _slotTabClosers[slot];
1324
+ if (!closer) return false;
1325
+ closer([tabId]);
1326
+ return true;
1327
+ }
1328
+
754
1329
  // Update the current session context (host calls this on every session
755
1330
  // switch) and re-render all slots so panels match the new agent profile.
756
1331
  // Runs the previous session's view-level teardowns first (event listeners /
@@ -773,6 +1348,7 @@ Clacky.ext = (() => {
773
1348
  if (!sessionId) return;
774
1349
  _runViewTeardowns(sessionId);
775
1350
  _viewTeardowns.delete(sessionId);
1351
+ _asideTabsForget(sessionId);
776
1352
  const bySession = _sessionRuntimes.get(sessionId);
777
1353
  if (!bySession) return;
778
1354
  bySession.forEach((runtime) => {
@@ -814,6 +1390,7 @@ Clacky.ext = (() => {
814
1390
  renderSlot,
815
1391
  slots,
816
1392
  activateTab,
1393
+ closeTab,
817
1394
  // Host-only: look up a registered workspace by id. Returns
818
1395
  // { id, title, render, extId } or undefined. Used by the Router when
819
1396
  // handling the `ext-workspace` view — extensions never call this.