@clagentic/console 1.12.0 → 1.13.0-beta.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 (243) hide show
  1. package/README.md +7 -1
  2. package/bin/cli.js +18 -15
  3. package/lib/agent-roster-ws.js +38 -13
  4. package/lib/agent-roster.js +111 -12
  5. package/lib/agents.js +68 -33
  6. package/lib/atomic-install.js +334 -0
  7. package/lib/build-changes.js +33 -4
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-offer.js +12 -0
  10. package/lib/chat-width.js +31 -0
  11. package/lib/cli/agent-usage.js +126 -0
  12. package/lib/cli/arg-validation.js +1 -1
  13. package/lib/cli/compact-output.js +69 -0
  14. package/lib/cli/ipc-subcommands.js +92 -67
  15. package/lib/cli/output.js +28 -0
  16. package/lib/cli/restart-verb.js +132 -0
  17. package/lib/cli/schedule-input-subcommands.js +45 -8
  18. package/lib/cli/session-subcommands.js +37 -11
  19. package/lib/cli/settings-subcommands.js +74 -0
  20. package/lib/cli-transcript-title.js +56 -3
  21. package/lib/client-files.js +79 -0
  22. package/lib/daemon.js +100 -28
  23. package/lib/default-avatar-color.js +4 -0
  24. package/lib/drain.js +58 -10
  25. package/lib/mcp-tool-input.js +2 -2
  26. package/lib/model-families.js +49 -1
  27. package/lib/notify/type-registry.js +4 -0
  28. package/lib/notify/types.js +7 -4
  29. package/lib/pages.js +13 -63
  30. package/lib/permission-summary.js +12 -16
  31. package/lib/plan-usage-reader.js +70 -0
  32. package/lib/project-connection.js +4 -2
  33. package/lib/project-filesystem.js +6 -7
  34. package/lib/project-notifications.js +55 -8
  35. package/lib/project-prompt-expiry-settings.js +42 -0
  36. package/lib/project-sessions.js +52 -0
  37. package/lib/project-settings-gate.js +98 -0
  38. package/lib/project-user-mention.js +3 -2
  39. package/lib/project.js +1 -1
  40. package/lib/prompt-expiry-settings.js +49 -0
  41. package/lib/prompt-expiry.js +24 -3
  42. package/lib/prompt-kinds/codecs.js +6 -2
  43. package/lib/public/app.js +36 -36
  44. package/lib/public/css/admin.css +156 -170
  45. package/lib/public/css/agent-messages.css +24 -24
  46. package/lib/public/css/agent-picker.css +90 -38
  47. package/lib/public/css/agent-roster.css +61 -27
  48. package/lib/public/css/at-agents.css +10 -10
  49. package/lib/public/css/base.css +207 -184
  50. package/lib/public/css/chat-layout.css +228 -0
  51. package/lib/public/css/command-palette.css +86 -88
  52. package/lib/public/css/diagnostics.css +78 -204
  53. package/lib/public/css/diff.css +10 -10
  54. package/lib/public/css/filebrowser.css +32 -60
  55. package/lib/public/css/home-hub.css +100 -100
  56. package/lib/public/css/icon-strip.css +195 -238
  57. package/lib/public/css/input.css +191 -212
  58. package/lib/public/css/login-panel.css +16 -16
  59. package/lib/public/css/loop.css +96 -187
  60. package/lib/public/css/mention.css +49 -110
  61. package/lib/public/css/menus.css +162 -169
  62. package/lib/public/css/messages.css +49 -123
  63. package/lib/public/css/mobile-nav.css +207 -264
  64. package/lib/public/css/notifications-center.css +45 -124
  65. package/lib/public/css/overlay.css +269 -0
  66. package/lib/public/css/overlays.css +134 -156
  67. package/lib/public/css/playbook.css +41 -41
  68. package/lib/public/css/profile.css +43 -112
  69. package/lib/public/css/rewind.css +112 -112
  70. package/lib/public/css/scheduler-modal.css +27 -135
  71. package/lib/public/css/scheduler.css +204 -210
  72. package/lib/public/css/server-settings.css +173 -239
  73. package/lib/public/css/session-search.css +20 -20
  74. package/lib/public/css/settings-nav.css +197 -0
  75. package/lib/public/css/sidebar.css +213 -304
  76. package/lib/public/css/skills.css +121 -135
  77. package/lib/public/css/sticky-notes.css +114 -200
  78. package/lib/public/css/stt.css +17 -26
  79. package/lib/public/css/team-panel.css +36 -36
  80. package/lib/public/css/team-view.css +9 -9
  81. package/lib/public/css/title-bar.css +83 -100
  82. package/lib/public/css/tooltip.css +10 -10
  83. package/lib/public/css/user-settings.css +78 -131
  84. package/lib/public/css/user-shell.css +125 -29
  85. package/lib/public/index.html +178 -177
  86. package/lib/public/manifest.json +0 -2
  87. package/lib/public/modules/admin.js +54 -92
  88. package/lib/public/modules/agent-avatar.js +134 -3
  89. package/lib/public/modules/agent-messages.js +2 -1
  90. package/lib/public/modules/agent-picker.js +23 -21
  91. package/lib/public/modules/agent-roster-groups.js +128 -0
  92. package/lib/public/modules/agent-roster.js +40 -11
  93. package/lib/public/modules/app-connection.js +13 -1
  94. package/lib/public/modules/app-cursors.js +9 -9
  95. package/lib/public/modules/app-favicon.js +8 -16
  96. package/lib/public/modules/app-header.js +28 -19
  97. package/lib/public/modules/app-history-replay.js +67 -4
  98. package/lib/public/modules/app-home-hub.js +15 -0
  99. package/lib/public/modules/app-loop-ui.js +41 -47
  100. package/lib/public/modules/app-loop-wizard.js +9 -10
  101. package/lib/public/modules/app-messages.js +32 -36
  102. package/lib/public/modules/app-misc.js +22 -92
  103. package/lib/public/modules/app-modals.js +98 -0
  104. package/lib/public/modules/app-notifications.js +124 -135
  105. package/lib/public/modules/app-panels.js +28 -32
  106. package/lib/public/modules/app-projects.js +30 -40
  107. package/lib/public/modules/app-rate-limit.js +26 -9
  108. package/lib/public/modules/app-rendering.js +128 -110
  109. package/lib/public/modules/app-skills-install.js +6 -4
  110. package/lib/public/modules/assistant-identity.js +55 -0
  111. package/lib/public/modules/at-agents.js +3 -0
  112. package/lib/public/modules/build-guard.js +25 -11
  113. package/lib/public/modules/chat-width-choice.js +75 -0
  114. package/lib/public/modules/chat-width-prefs.js +52 -0
  115. package/lib/public/modules/chat-width.js +102 -0
  116. package/lib/public/modules/collapsible-text.js +36 -4
  117. package/lib/public/modules/command-palette.js +28 -34
  118. package/lib/public/modules/context-sources.js +3 -5
  119. package/lib/public/modules/diagnostics.js +130 -129
  120. package/lib/public/modules/info-panel.js +31 -0
  121. package/lib/public/modules/injected-identity.js +8 -8
  122. package/lib/public/modules/input-list-menu.js +39 -0
  123. package/lib/public/modules/input.js +22 -21
  124. package/lib/public/modules/markdown.js +10 -11
  125. package/lib/public/modules/mcp-ui.js +4 -14
  126. package/lib/public/modules/mention.js +100 -229
  127. package/lib/public/modules/message-header.js +80 -0
  128. package/lib/public/modules/message-participants.js +39 -0
  129. package/lib/public/modules/mobile-action-sheet.js +46 -0
  130. package/lib/public/modules/mobile-nav-sheet.js +104 -0
  131. package/lib/public/modules/model-families.js +41 -4
  132. package/lib/public/modules/note-order.js +39 -0
  133. package/lib/public/modules/notifications.js +35 -52
  134. package/lib/public/modules/overlay-history.js +73 -19
  135. package/lib/public/modules/overlay-menu.js +123 -0
  136. package/lib/public/modules/overlay-modal.js +186 -0
  137. package/lib/public/modules/overlay-registry.js +392 -0
  138. package/lib/public/modules/overlay-stack.js +110 -0
  139. package/lib/public/modules/overlay.js +117 -0
  140. package/lib/public/modules/popover-position.js +18 -2
  141. package/lib/public/modules/preference-sync.js +28 -0
  142. package/lib/public/modules/profile.js +24 -49
  143. package/lib/public/modules/project-settings.js +27 -172
  144. package/lib/public/modules/prompt-expiry-controls.js +46 -0
  145. package/lib/public/modules/prompt-kinds/command-summary.js +149 -0
  146. package/lib/public/modules/prompt-kinds/permission.js +70 -92
  147. package/lib/public/modules/prompts.js +1 -2
  148. package/lib/public/modules/qrcode.js +6 -21
  149. package/lib/public/modules/queued-button.js +15 -2
  150. package/lib/public/modules/rewind.js +9 -3
  151. package/lib/public/modules/schedule-time.js +32 -7
  152. package/lib/public/modules/scheduled-outbox.js +51 -18
  153. package/lib/public/modules/scheduler-config.js +87 -127
  154. package/lib/public/modules/scheduler.js +29 -26
  155. package/lib/public/modules/serialized-save.js +79 -0
  156. package/lib/public/modules/server-settings.js +75 -65
  157. package/lib/public/modules/session-grants.js +16 -19
  158. package/lib/public/modules/session-list-avatars.js +98 -0
  159. package/lib/public/modules/session-vendor-state.js +86 -0
  160. package/lib/public/modules/settings-access.js +35 -0
  161. package/lib/public/modules/settings-hub.js +125 -0
  162. package/lib/public/modules/settings-nav.js +182 -0
  163. package/lib/public/modules/shell-line.js +24 -0
  164. package/lib/public/modules/sidebar-mobile.js +151 -195
  165. package/lib/public/modules/sidebar-projects.js +88 -129
  166. package/lib/public/modules/sidebar-sessions.js +66 -34
  167. package/lib/public/modules/sidebar.js +2 -2
  168. package/lib/public/modules/skills.js +11 -26
  169. package/lib/public/modules/sticky-notes.js +19 -16
  170. package/lib/public/modules/stt.js +9 -23
  171. package/lib/public/modules/terminal.js +86 -90
  172. package/lib/public/modules/theme-choice.js +126 -0
  173. package/lib/public/modules/theme-colors.js +19 -0
  174. package/lib/public/modules/theme-prefs.js +121 -0
  175. package/lib/public/modules/theme.js +227 -605
  176. package/lib/public/modules/tool-palette.js +7 -17
  177. package/lib/public/modules/tools.js +8 -10
  178. package/lib/public/modules/user-settings.js +59 -115
  179. package/lib/public/modules/user-shell.js +9 -2
  180. package/lib/public/modules/utils.js +10 -12
  181. package/lib/public/modules/vendor-picker.js +4 -2
  182. package/lib/public/modules/vendor-registry.js +1 -2
  183. package/lib/public/style.css +3 -1
  184. package/lib/public/sw.js +9 -2
  185. package/lib/public/theme-core.js +411 -0
  186. package/lib/request-body.js +70 -0
  187. package/lib/sdk-bridge.js +227 -88
  188. package/lib/sdk-message-processor.js +44 -16
  189. package/lib/server-admin.js +198 -200
  190. package/lib/server-auth.js +16 -13
  191. package/lib/server-dm.js +4 -3
  192. package/lib/server-settings.js +177 -130
  193. package/lib/server.js +87 -36
  194. package/lib/session-background-tasks.js +79 -0
  195. package/lib/session-directory.js +138 -13
  196. package/lib/session-input-ipc.js +2 -0
  197. package/lib/session-input.js +39 -5
  198. package/lib/session-list-avatars.js +16 -0
  199. package/lib/session-reclaim.js +37 -25
  200. package/lib/session-vendor.js +37 -0
  201. package/lib/sessions.js +99 -34
  202. package/lib/settings-ipc.js +60 -0
  203. package/lib/settings-registry.js +86 -0
  204. package/lib/terminal-manager.js +17 -5
  205. package/lib/theme-files.js +132 -0
  206. package/lib/theme-seed.js +136 -0
  207. package/lib/themes/clagentic-dark.json +13 -6
  208. package/lib/themes/clagentic-light.json +12 -5
  209. package/lib/updater.js +6 -4
  210. package/lib/usage-store.js +97 -10
  211. package/lib/users-preferences.js +118 -19
  212. package/lib/users.js +19 -10
  213. package/lib/vendor-catalog.js +130 -0
  214. package/lib/ws-schema.js +4 -2
  215. package/lib/yoke/adapters/claude.js +81 -1
  216. package/lib/yoke/adapters/codex-user-shell.js +87 -23
  217. package/lib/yoke/adapters/codex.js +89 -5
  218. package/lib/yoke/codex-binary.js +59 -0
  219. package/package.json +1 -1
  220. package/scripts/check-test-count.js +5 -0
  221. package/scripts/install-local-test.js +50 -9
  222. package/scripts/write-build-sha.js +18 -2
  223. package/lib/public/css/channel-layout.css +0 -329
  224. package/lib/themes/ayu-light.json +0 -9
  225. package/lib/themes/catppuccin-latte.json +0 -9
  226. package/lib/themes/catppuccin-mocha.json +0 -9
  227. package/lib/themes/dracula.json +0 -9
  228. package/lib/themes/everforest-light.json +0 -9
  229. package/lib/themes/everforest.json +0 -9
  230. package/lib/themes/github-light.json +0 -9
  231. package/lib/themes/gruvbox-dark.json +0 -9
  232. package/lib/themes/gruvbox-light.json +0 -9
  233. package/lib/themes/monokai.json +0 -9
  234. package/lib/themes/nord-light.json +0 -9
  235. package/lib/themes/nord.json +0 -9
  236. package/lib/themes/one-dark.json +0 -9
  237. package/lib/themes/one-light.json +0 -9
  238. package/lib/themes/rose-pine-dawn.json +0 -9
  239. package/lib/themes/rose-pine.json +0 -9
  240. package/lib/themes/solarized-dark.json +0 -9
  241. package/lib/themes/solarized-light.json +0 -9
  242. package/lib/themes/tokyo-night-light.json +0 -9
  243. package/lib/themes/tokyo-night.json +0 -9
@@ -1,8 +1,10 @@
1
1
  import { iconHtml, refreshIcons } from './icons.js';
2
2
  import { escapeHtml, copyToClipboard, showToast } from './utils.js';
3
3
  import { store } from './store.js';
4
+ import { showOverlay } from './overlay.js';
4
5
 
5
6
  var modal;
7
+ var modalHandle = null;
6
8
  var contentEl;
7
9
  var activeTab = "all";
8
10
  var currentView = "list"; // "list" or "detail"
@@ -19,9 +21,7 @@ export function initSkills() {
19
21
  modal = document.getElementById("skills-modal");
20
22
  contentEl = document.getElementById("skills-content");
21
23
  var btn = document.getElementById("skills-btn");
22
- var closeBtn = document.getElementById("skills-modal-close");
23
24
  var backBtn = document.getElementById("skills-back-btn");
24
- var backdrop = modal ? modal.querySelector(".confirm-backdrop") : null;
25
25
 
26
26
  if (btn) {
27
27
  btn.addEventListener("click", function () {
@@ -29,18 +29,10 @@ export function initSkills() {
29
29
  });
30
30
  }
31
31
 
32
- if (closeBtn) {
33
- closeBtn.addEventListener("click", closeSkillsModal);
34
- }
35
-
36
32
  if (backBtn) {
37
33
  backBtn.addEventListener("click", showListView);
38
34
  }
39
35
 
40
- if (backdrop) {
41
- backdrop.addEventListener("click", closeSkillsModal);
42
- }
43
-
44
36
  // Search input
45
37
  var searchInput = document.getElementById("skills-search-input");
46
38
  var searchHint = document.getElementById("skills-search-hint");
@@ -120,16 +112,14 @@ export function initSkills() {
120
112
  })(tabs[i]);
121
113
  }
122
114
 
123
- // Esc key
124
- document.addEventListener("keydown", function (e) {
125
- if (e.key === "Escape" && modal && !modal.classList.contains("hidden")) {
126
- if (currentView === "detail") {
127
- showListView();
128
- } else {
129
- closeSkillsModal();
130
- }
131
- }
132
- });
115
+ }
116
+
117
+ // Escape steps back from a skill's detail to the list; from the list it closes the
118
+ // modal (the shared overlay component does that).
119
+ function onSkillsEscape() {
120
+ if (currentView !== "detail") return false;
121
+ showListView();
122
+ return true;
133
123
  }
134
124
 
135
125
  function fetchInstalledSkills() {
@@ -155,7 +145,7 @@ function scopeLabel(scope) {
155
145
 
156
146
  function openSkillsModal() {
157
147
  if (!modal) return;
158
- modal.classList.remove("hidden");
148
+ modalHandle = showOverlay({ kind: "modal", el: modal, onEscape: onSkillsEscape });
159
149
  refreshIcons(modal);
160
150
  currentView = "list";
161
151
  var backBtn = document.getElementById("skills-back-btn");
@@ -172,11 +162,6 @@ function openSkillsModal() {
172
162
  });
173
163
  }
174
164
 
175
- function closeSkillsModal() {
176
- if (!modal) return;
177
- modal.classList.add("hidden");
178
- }
179
-
180
165
  function updateTabUI() {
181
166
  var tabs = modal.querySelectorAll(".skills-tab");
182
167
  for (var i = 0; i < tabs.length; i++) {
@@ -1,6 +1,7 @@
1
1
  import { refreshIcons, iconHtml } from './icons.js';
2
2
  import { pushOverlayState, popOverlayState } from './overlay-history.js';
3
- import { positionPopover } from './popover-position.js';
3
+ import { showOverlay } from './overlay.js';
4
+ import { noteLayerOrders } from './note-order.js';
4
5
 
5
6
  var ctx;
6
7
  var notes = new Map(); // id -> { data, el }
@@ -258,6 +259,19 @@ function extractMdFromRendered(rendered) {
258
259
 
259
260
  // --- Note rendering ---
260
261
 
262
+ // The note's order joins --z-note in css/sticky-notes.css. note-order.js ranks it against
263
+ // the other open notes, so a change here can move the others' orders too: all are rewritten.
264
+ function setNoteOrder(el, zIndex) {
265
+ var items = [{ el: el, zIndex: zIndex }];
266
+ notes.forEach(function (entry) {
267
+ if (entry.el !== el) items.push({ el: entry.el, zIndex: entry.data.zIndex });
268
+ });
269
+ var orders = noteLayerOrders(items.map(function (it) { return it.zIndex; }));
270
+ items.forEach(function (it, i) {
271
+ it.el.style.setProperty("--note-order", String(orders[i]));
272
+ });
273
+ }
274
+
261
275
  function renderNote(data) {
262
276
  var el = document.createElement("div");
263
277
  el.className = "sticky-note";
@@ -267,7 +281,7 @@ function renderNote(data) {
267
281
  el.style.top = clamped.y + "px";
268
282
  el.style.width = data.w + "px";
269
283
  el.style.height = data.h + "px";
270
- el.style.zIndex = 100 + (data.zIndex || 0);
284
+ setNoteOrder(el, data.zIndex);
271
285
  el.dataset.color = data.color || "yellow";
272
286
 
273
287
  if (data.minimized) el.classList.add("minimized");
@@ -800,7 +814,7 @@ function setupTextEdit(textarea, rendered, noteId, mdBtn) {
800
814
 
801
815
  function closeColorPicker() {
802
816
  if (colorPickerEl) {
803
- colorPickerEl.remove();
817
+ colorPickerEl.close();
804
818
  colorPickerEl = null;
805
819
  }
806
820
  }
@@ -834,20 +848,9 @@ function showColorPicker(anchor, noteEl, noteId) {
834
848
  })(NOTE_COLORS[i]);
835
849
  }
836
850
 
837
- document.body.appendChild(picker);
838
- colorPickerEl = picker;
839
-
840
851
  // Position relative to anchor, clamped to the viewport on all four edges
841
852
  // (lr-a10a: this popover previously had no clamp at all).
842
- positionPopover(picker, anchor, { placement: "below", gap: 4 });
843
-
844
- // Close on outside click
845
- setTimeout(function () {
846
- document.addEventListener("click", function closeHandler() {
847
- closeColorPicker();
848
- document.removeEventListener("click", closeHandler);
849
- });
850
- }, 0);
853
+ colorPickerEl = showOverlay({ kind: "popover", el: picker, anchor: anchor, placement: "below", gap: 4 });
851
854
  }
852
855
 
853
856
  // --- Minimize ---
@@ -949,7 +952,7 @@ export function handleNoteUpdated(msg) {
949
952
  entry.el.style.top = msg.note.y + "px";
950
953
  entry.el.style.width = msg.note.w + "px";
951
954
  entry.el.style.height = msg.note.h + "px";
952
- entry.el.style.zIndex = 100 + (msg.note.zIndex || 0);
955
+ setNoteOrder(entry.el, msg.note.zIndex);
953
956
  entry.el.dataset.color = msg.note.color || "yellow";
954
957
 
955
958
  // Update text only if not actively editing (check rendered or textarea focus)
@@ -5,6 +5,7 @@ import { iconHtml, refreshIcons } from './icons.js';
5
5
  import { autoResize } from './input.js';
6
6
  import { store } from './store.js';
7
7
  import { VENDOR_NAMES } from './app-rendering.js';
8
+ import { showOverlay } from './overlay.js';
8
9
 
9
10
  var ctx;
10
11
 
@@ -80,9 +81,6 @@ function showLangPopover() {
80
81
  return;
81
82
  }
82
83
 
83
- langPopover = document.createElement('div');
84
- langPopover.className = 'stt-lang-popover';
85
-
86
84
  var html = '<div class="stt-lang-title">Voice Input Language</div>';
87
85
  for (var i = 0; i < LANGUAGES.length; i++) {
88
86
  var l = LANGUAGES[i];
@@ -91,34 +89,22 @@ function showLangPopover() {
91
89
  '<span class="stt-lang-name">' + l.name + '</span>' +
92
90
  '</button>';
93
91
  }
94
- langPopover.innerHTML = html;
92
+ // Hung above the composer; outside click and Escape are the registry's.
93
+ langPopover = showOverlay({
94
+ kind: 'popover', className: 'stt-lang-popover', content: html,
95
+ anchor: document.getElementById('input-wrapper'), placement: 'above', gap: 8, opener: sttBtn,
96
+ onRemove: function() { langPopover = null; },
97
+ });
95
98
 
96
- langPopover.querySelectorAll('.stt-lang-option').forEach(function(btn) {
99
+ langPopover.el.querySelectorAll('.stt-lang-option').forEach(function(btn) {
97
100
  btn.addEventListener('click', function() {
98
101
  onLangSelected(btn.dataset.lang);
99
102
  });
100
103
  });
101
-
102
- var wrapper = document.getElementById('input-wrapper');
103
- wrapper.appendChild(langPopover);
104
-
105
- setTimeout(function() {
106
- document.addEventListener('click', closeLangOnOutside);
107
- }, 0);
108
- }
109
-
110
- function closeLangOnOutside(e) {
111
- if (langPopover && !langPopover.contains(e.target) && e.target !== sttBtn && !sttBtn.contains(e.target)) {
112
- hideLangPopover();
113
- }
114
104
  }
115
105
 
116
106
  function hideLangPopover() {
117
- if (langPopover) {
118
- langPopover.remove();
119
- langPopover = null;
120
- }
121
- document.removeEventListener('click', closeLangOnOutside);
107
+ if (langPopover) langPopover.close();
122
108
  }
123
109
 
124
110
  function onLangSelected(code) {
@@ -3,7 +3,7 @@ import { closeSidebar } from './sidebar.js';
3
3
  import { closeFileViewer } from './filebrowser.js';
4
4
  import { copyToClipboard } from './utils.js';
5
5
  import { getTerminalTheme } from './theme.js';
6
- import { positionAtPoint } from './popover-position.js';
6
+ import { showOverlay } from './overlay.js';
7
7
  import { createMultiLineLinkProvider, copyTextForSelection } from './terminal-links.js';
8
8
  import { store } from './store.js';
9
9
  import { vendorEntry } from './vendor-registry.js';
@@ -73,6 +73,7 @@ function disposeTab(tab) {
73
73
  tab.xterm.dispose();
74
74
  tab.xterm = null;
75
75
  }
76
+ tab._replaying = null;
76
77
  tab.fitAddon = null;
77
78
  if (tab.bodyEl && tab.bodyEl.parentNode) {
78
79
  tab.bodyEl.parentNode.removeChild(tab.bodyEl);
@@ -292,6 +293,19 @@ function activateTab(termId) {
292
293
  renderTabBar();
293
294
  }
294
295
 
296
+ // Replies xterm generates to terminal queries: OSC (colour), DCS (DECRQSS),
297
+ // CSI cursor-position/device-attribute/status/mode/window reports.
298
+ var QUERY_REPLY_RE = new RegExp(
299
+ "\\x1b\\][^\\x07\\x1b]*(?:\\x07|\\x1b\\\\)" +
300
+ "|\\x1bP[^\\x1b]*\\x1b\\\\" +
301
+ "|\\x1b\\[[?>=]?[0-9;:]*(?:\\$y|[Rcnt])",
302
+ "g"
303
+ );
304
+
305
+ function stripQueryReplies(data) {
306
+ return data.replace(QUERY_REPLY_RE, "");
307
+ }
308
+
295
309
  // --- Create xterm.js instance for a tab ---
296
310
  function createXtermForTab(tab) {
297
311
  if (typeof Terminal === "undefined") return;
@@ -343,45 +357,23 @@ function createXtermForTab(tab) {
343
357
  }
344
358
  }
345
359
 
346
- // Route input to server
360
+ // Route input to server. While scrollback is being replayed, xterm answers
361
+ // the queries inside it (OSC 11 colour, DSR cursor position); those answers
362
+ // belong to programs that already exited, so they must not reach the shell.
347
363
  xterm.onData(function (data) {
364
+ // Only the replies are dropped; keys and pastes typed during a long replay
365
+ // still reach the shell.
366
+ if (tab._replaying) data = stripQueryReplies(data);
367
+ if (!data) return;
348
368
  if (ctx.ws && ctx.connected) {
349
369
  ctx.ws.send(JSON.stringify({ type: "term_input", id: tab.id, data: data }));
350
370
  }
351
371
  });
352
372
 
353
- // Cmd/Ctrl+C copy and Cmd/Ctrl+V paste: intercept before xterm swallows the event
354
- xterm.attachCustomKeyEventHandler(function (e) {
355
- if (e.type !== "keydown") return true;
356
- // Cmd/Ctrl+C: copy selection if any, otherwise send SIGINT
357
- if ((e.ctrlKey || e.metaKey) && e.key === "c") {
358
- var sel = copyTextForSelection(xterm, xterm.getSelection());
359
- if (sel) {
360
- if (navigator.clipboard && navigator.clipboard.writeText) {
361
- navigator.clipboard.writeText(sel).catch(function () {});
362
- }
363
- return false; // prevent xterm from handling
364
- }
365
- // No selection on macOS Cmd+C: do nothing (not SIGINT)
366
- if (e.metaKey) return false;
367
- }
368
- // Cmd/Ctrl+V: let browser handle paste event
369
- if ((e.ctrlKey || e.metaKey) && e.key === "v") {
370
- return false; // let browser fire paste event
371
- }
372
- return true;
373
- });
374
-
375
- // Handle paste via browser paste event (works for Cmd+V, Ctrl+V, right-click paste)
376
- bodyEl.addEventListener("paste", function (e) {
377
- var text = (e.clipboardData || window.clipboardData).getData("text");
378
- if (text) {
379
- e.preventDefault();
380
- if (ctx.ws && ctx.connected) {
381
- ctx.ws.send(JSON.stringify({ type: "term_input", id: tab.id, data: text }));
382
- }
383
- }
384
- });
373
+ // Keyboard paste is left to xterm's own paste listener (the key handler lets
374
+ // the browser event through), so there is no separate body listener that
375
+ // would send raw clipboard text.
376
+ xterm.attachCustomKeyEventHandler(createKeyHandler(tab, xterm));
385
377
 
386
378
  // Right-click context menu
387
379
  bodyEl.addEventListener("contextmenu", function (e) {
@@ -497,9 +489,6 @@ function renderTabBar() {
497
489
 
498
490
  // --- Tab context menu (three-dot) ---
499
491
  function showTabContextMenu(e, tab, labelEl) {
500
- var existing = document.querySelector(".terminal-tab-ctx");
501
- if (existing) existing.remove();
502
-
503
492
  var menu = document.createElement("div");
504
493
  menu.className = "terminal-tab-ctx";
505
494
 
@@ -507,7 +496,7 @@ function showTabContextMenu(e, tab, labelEl) {
507
496
  renameItem.className = "terminal-tab-ctx-item";
508
497
  renameItem.innerHTML = '<i data-lucide="pencil" style="width:13px;height:13px"></i> Rename';
509
498
  renameItem.addEventListener("click", function () {
510
- menu.remove();
499
+ closeTermCtxMenu();
511
500
  startRenameTab(tab, labelEl);
512
501
  });
513
502
  menu.appendChild(renameItem);
@@ -516,29 +505,13 @@ function showTabContextMenu(e, tab, labelEl) {
516
505
  closeItem.className = "terminal-tab-ctx-item terminal-tab-ctx-danger";
517
506
  closeItem.innerHTML = '<i data-lucide="trash-2" style="width:13px;height:13px"></i> Close';
518
507
  closeItem.addEventListener("click", function () {
519
- menu.remove();
508
+ closeTermCtxMenu();
520
509
  closeTab(tab.id);
521
510
  });
522
511
  menu.appendChild(closeItem);
523
512
 
524
- document.body.appendChild(menu);
525
- refreshIcons();
526
-
527
- // Position near the button
528
- var rect = e.currentTarget.getBoundingClientRect();
529
- menu.style.top = (rect.bottom + 4) + "px";
530
- menu.style.left = rect.left + "px";
531
-
532
- // Dismiss on outside click
533
- function dismiss(ev) {
534
- if (!menu.contains(ev.target)) {
535
- menu.remove();
536
- document.removeEventListener("mousedown", dismiss, true);
537
- }
538
- }
539
- setTimeout(function () {
540
- document.addEventListener("mousedown", dismiss, true);
541
- }, 0);
513
+ // Below the button, 4px gap as before; flipped and clamped to the viewport.
514
+ termCtxMenu = showOverlay({ kind: "menu", el: menu, anchor: e.currentTarget, placement: "below", gap: 4 });
542
515
  }
543
516
 
544
517
  // --- Rename tab inline ---
@@ -682,7 +655,20 @@ export function handleTermOutput(msg) {
682
655
  var tab = tabs.get(msg.id);
683
656
  if (tab && tab.xterm && msg.data) {
684
657
  var login = loginTabs.get(msg.id);
685
- if (login) {
658
+ if (msg.replay) {
659
+ // The replay is the whole scrollback: start from a clean screen so a live
660
+ // xterm does not show its old output twice. Replies stay suppressed until
661
+ // xterm has parsed the chunk (its write callback), which is when it emits them.
662
+ // A token (not a counter) so a write whose callback never fires cannot
663
+ // leave the tab suppressed: the next replay replaces it.
664
+ tab.xterm.reset();
665
+ var token = {};
666
+ tab._replaying = token;
667
+ tab.xterm.write(msg.data, function () {
668
+ if (tab._replaying === token) tab._replaying = null;
669
+ if (login) login.feed(tab.xterm);
670
+ });
671
+ } else if (login) {
686
672
  // Read the buffer once xterm has parsed this chunk, not the raw bytes.
687
673
  tab.xterm.write(msg.data, function () { login.feed(tab.xterm); });
688
674
  } else {
@@ -771,7 +757,7 @@ export function setTerminalTheme(xtermTheme) {
771
757
  // --- Terminal context menu ---
772
758
  function closeTermCtxMenu() {
773
759
  if (termCtxMenu) {
774
- termCtxMenu.remove();
760
+ termCtxMenu.close();
775
761
  termCtxMenu = null;
776
762
  }
777
763
  }
@@ -835,9 +821,9 @@ function showTermCtxMenu(e, tab) {
835
821
  if (!tab.xterm) return;
836
822
  if (navigator.clipboard && navigator.clipboard.readText) {
837
823
  navigator.clipboard.readText().then(function (text) {
838
- if (text && ctx.ws && ctx.connected) {
839
- ctx.ws.send(JSON.stringify({ type: "term_input", id: tab.id, data: text }));
840
- }
824
+ // xterm.paste() normalises line endings to CR and adds the
825
+ // bracketed-paste markers; its onData then sends the bytes.
826
+ if (text && tab.xterm) tab.xterm.paste(text);
841
827
  }).catch(function () { /* permission denied or not available */ });
842
828
  }
843
829
  });
@@ -858,16 +844,7 @@ function showTermCtxMenu(e, tab) {
858
844
  // Position at mouse cursor, clamped to viewport on all four edges
859
845
  // (lr-a10a: mobile's synthetic contextmenu can fire from a low/edge
860
846
  // touch point, so a right/bottom-only clamp isn't enough).
861
- document.body.appendChild(menu);
862
- positionAtPoint(menu, { x: e.clientX, y: e.clientY });
863
-
864
- termCtxMenu = menu;
865
- refreshIcons();
866
-
867
- // Close on outside click (next tick to avoid immediate trigger)
868
- setTimeout(function () {
869
- document.addEventListener("click", closeTermCtxMenu, { once: true });
870
- }, 0);
847
+ termCtxMenu = showOverlay({ kind: "menu", el: menu, anchor: { x: e.clientX, y: e.clientY } });
871
848
  }
872
849
 
873
850
  // --- Mobile toolbar ---
@@ -933,25 +910,44 @@ function initToolbar(toolbar) {
933
910
  }
934
911
  });
935
912
  }
913
+ }
914
+
915
+ // One key handler per xterm. xterm keeps a single custom handler, so the
916
+ // toolbar's virtual Ctrl and the Cmd/Ctrl+C / Cmd/Ctrl+V handling must live in
917
+ // the same function or the later registration silently drops the earlier one.
918
+ function createKeyHandler(tab, xterm) {
919
+ return function (e) {
920
+ if (e.type !== "keydown") return true;
921
+
922
+ // Toolbar Ctrl armed: turn the next letter into its control character.
923
+ if (ctrlActive && e.key && e.key.length === 1) {
924
+ var charCode = e.key.toUpperCase().charCodeAt(0);
925
+ if (charCode >= 65 && charCode <= 90) {
926
+ sendTerminalInput(tab.id, String.fromCharCode(charCode - 64));
927
+ ctrlActive = false;
928
+ var ctrlBtn = document.querySelector("#terminal-toolbar [data-key='ctrl']");
929
+ if (ctrlBtn) ctrlBtn.classList.remove("active");
930
+ return false;
931
+ }
932
+ }
936
933
 
937
- // Attach Ctrl handler to active terminal
938
- var tab = activeTabId ? tabs.get(activeTabId) : null;
939
- if (tab && tab.xterm) {
940
- tab.xterm.attachCustomKeyEventHandler(function (ev) {
941
- if (ctrlActive && ev.type === "keydown" && ev.key.length === 1) {
942
- var charCode = ev.key.toUpperCase().charCodeAt(0);
943
- if (charCode >= 65 && charCode <= 90) {
944
- var ctrlChar = String.fromCharCode(charCode - 64);
945
- if (ctx.ws && ctx.connected) {
946
- ctx.ws.send(JSON.stringify({ type: "term_input", id: activeTabId, data: ctrlChar }));
947
- }
948
- ctrlActive = false;
949
- var ctrlBtn = document.querySelector("#terminal-toolbar [data-key='ctrl']");
950
- if (ctrlBtn) ctrlBtn.classList.remove("active");
951
- return false;
934
+ // Cmd/Ctrl+C: copy selection if any, otherwise send SIGINT
935
+ if ((e.ctrlKey || e.metaKey) && e.key === "c") {
936
+ var sel = copyTextForSelection(xterm, xterm.getSelection());
937
+ if (sel) {
938
+ if (navigator.clipboard && navigator.clipboard.writeText) {
939
+ navigator.clipboard.writeText(sel).catch(function () {});
952
940
  }
941
+ return false; // prevent xterm from handling
953
942
  }
954
- return true;
955
- });
956
- }
943
+ // No selection on macOS Cmd+C: do nothing (not SIGINT)
944
+ if (e.metaKey) return false;
945
+ }
946
+ // Cmd/Ctrl+V: the browser fires a paste event that xterm turns into
947
+ // xterm.paste(), which normalises line endings and adds bracketed-paste markers.
948
+ if ((e.ctrlKey || e.metaKey) && e.key === "v") {
949
+ return false;
950
+ }
951
+ return true;
952
+ };
957
953
  }
@@ -0,0 +1,126 @@
1
+ // The Appearance theme choice, one component for every surface that offers it.
2
+ //
3
+ // mountThemeChoice(container, { layout, showDescriptions, onChange })
4
+ //
5
+ // It offers Dark, Light, Follow system and any valid custom theme from the
6
+ // console's themes folder, marks the current choice, and keeps itself current
7
+ // when the choice changes anywhere (another surface, another device's saved
8
+ // choice arriving with the profile) or the custom theme list loads. Choosing
9
+ // goes through theme.js, which applies the theme and saves it on the server.
10
+ //
11
+ // Per-use options, so a surface adapts the shape and never forks it:
12
+ // layout "cards" (User Settings: .layout-option cards inside a
13
+ // .layout-switcher container) or "rows" (phone More sheet:
14
+ // .mobile-more-item rows)
15
+ // showDescriptions show each option's one-line description (default: cards
16
+ // yes, rows no)
17
+ // onChange called with the chosen option after it is applied
18
+ //
19
+ // Names come from user-supplied files, so every label is set as text.
20
+
21
+ import { buildThemeOptions, selectionKey } from './theme-prefs.js';
22
+ import { getCustomThemes, getThemeSelection, setThemeMode, setCustomTheme, onThemeChange } from './theme.js';
23
+ import { refreshIcons } from './icons.js';
24
+
25
+ function iconEl(name) {
26
+ var i = document.createElement("i");
27
+ i.setAttribute("data-lucide", name);
28
+ return i;
29
+ }
30
+
31
+ function swatchesEl(colors) {
32
+ var wrap = document.createElement("span");
33
+ wrap.className = "theme-swatches";
34
+ for (var i = 0; i < colors.length; i++) {
35
+ var dot = document.createElement("span");
36
+ dot.className = "theme-swatch";
37
+ dot.style.background = colors[i];
38
+ wrap.appendChild(dot);
39
+ }
40
+ return wrap;
41
+ }
42
+
43
+ function textEl(className, text) {
44
+ var span = document.createElement("span");
45
+ span.className = className;
46
+ span.textContent = text;
47
+ return span;
48
+ }
49
+
50
+ function buildCard(option, selected, showDescriptions) {
51
+ var btn = document.createElement("button");
52
+ btn.type = "button";
53
+ btn.className = "layout-option" + (selected ? " selected" : "");
54
+ var icon = document.createElement("span");
55
+ icon.className = "layout-option-icon";
56
+ icon.appendChild(option.kind === "custom" ? swatchesEl(option.swatches) : iconEl(option.icon));
57
+ btn.appendChild(icon);
58
+ btn.appendChild(textEl("layout-option-label", option.label));
59
+ if (showDescriptions) btn.appendChild(textEl("layout-option-desc", option.description));
60
+ return btn;
61
+ }
62
+
63
+ function buildRow(option, selected, showDescriptions) {
64
+ var btn = document.createElement("button");
65
+ btn.type = "button";
66
+ btn.className = "mobile-more-item mobile-more-inline-row";
67
+ if (option.kind === "custom") {
68
+ btn.appendChild(swatchesEl(option.swatches));
69
+ } else {
70
+ btn.appendChild(iconEl(option.icon));
71
+ }
72
+ btn.appendChild(textEl("mobile-more-item-label", option.label));
73
+ if (showDescriptions) btn.appendChild(textEl("mobile-more-inline-value", option.description));
74
+ var mark = document.createElement("span");
75
+ mark.className = "mobile-more-inline-value";
76
+ if (selected) mark.appendChild(iconEl("check"));
77
+ btn.appendChild(mark);
78
+ return btn;
79
+ }
80
+
81
+ /**
82
+ * Renders the choice into `container` and keeps it current. Returns a function
83
+ * that stops updating it; the component also stops by itself once `container`
84
+ * has left the document.
85
+ */
86
+ export function mountThemeChoice(container, options) {
87
+ var opts = options || {};
88
+ var layout = opts.layout === "rows" ? "rows" : "cards";
89
+ var showDescriptions = opts.showDescriptions !== undefined ? !!opts.showDescriptions : layout === "cards";
90
+ var unsubscribe = null;
91
+
92
+ container.setAttribute("role", "radiogroup");
93
+ container.setAttribute("aria-label", "Theme");
94
+
95
+ function render() {
96
+ if (unsubscribe && !container.isConnected) {
97
+ unsubscribe();
98
+ unsubscribe = null;
99
+ return;
100
+ }
101
+ var themeOptions = buildThemeOptions(getCustomThemes());
102
+ var selected = selectionKey(getThemeSelection());
103
+ container.textContent = "";
104
+ themeOptions.forEach(function (option) {
105
+ var isSelected = option.key === selected;
106
+ var el = layout === "rows" ? buildRow(option, isSelected, showDescriptions) : buildCard(option, isSelected, showDescriptions);
107
+ el.setAttribute("role", "radio");
108
+ el.setAttribute("aria-checked", isSelected ? "true" : "false");
109
+ el.dataset.themeOption = option.key;
110
+ el.addEventListener("click", function () {
111
+ if (option.kind === "custom") setCustomTheme(option.id);
112
+ else setThemeMode(option.mode);
113
+ if (opts.onChange) opts.onChange(option);
114
+ });
115
+ container.appendChild(el);
116
+ });
117
+ refreshIcons(container);
118
+ }
119
+
120
+ render();
121
+ unsubscribe = onThemeChange(render);
122
+ return function () {
123
+ if (unsubscribe) unsubscribe();
124
+ unsubscribe = null;
125
+ };
126
+ }
@@ -0,0 +1,19 @@
1
+ // The browser's handle on the colour derivation. The derivation itself is
2
+ // ../theme-core.js, a plain script the server also loads, so there is one copy.
3
+ // Importing it here runs it and leaves it on globalThis.ClagenticThemeCore.
4
+ import "../theme-core.js";
5
+
6
+ var core = globalThis.ClagenticThemeCore;
7
+ if (!core) throw new Error("theme-core.js did not load");
8
+
9
+ export var deriveVars = core.deriveVars;
10
+ export var deriveTerminalTheme = core.deriveTerminalTheme;
11
+ export var deriveMermaidVars = core.deriveMermaidVars;
12
+ export var inferVariant = core.inferVariant;
13
+ export var readTokens = core.readTokens;
14
+
15
+ // The two built-in palettes, from lib/themes: the server appends them to the
16
+ // script it serves, and under Node the script reads the files.
17
+ if (!core.builtin) throw new Error("theme-core.js carried no built-in palettes");
18
+ export var CLAGENTIC_DARK = core.builtin.dark;
19
+ export var CLAGENTIC_LIGHT = core.builtin.light;