@clagentic/console 1.5.0 → 1.6.0-beta.2
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.
- package/README.md +23 -4
- package/bin/cli.js +15 -82
- package/lib/agents-favorites.js +21 -6
- package/lib/config.js +1 -1
- package/lib/daemon.js +153 -22
- package/lib/drain.js +213 -0
- package/lib/lite-detect.js +6 -5
- package/lib/loop-handoff.js +282 -0
- package/lib/mcp-local.js +18 -2
- package/lib/memory-limits.js +436 -0
- package/lib/model-context-windows.js +65 -0
- package/lib/project-loop.js +31 -3
- package/lib/project-sessions.js +26 -0
- package/lib/project-team.js +4 -1
- package/lib/project.js +8 -0
- package/lib/public/app.js +4 -0
- package/lib/public/css/base.css +18 -0
- package/lib/public/css/diagnostics.css +279 -0
- package/lib/public/css/icon-strip.css +201 -0
- package/lib/public/css/menus.css +2 -2
- package/lib/public/css/mobile-nav.css +24 -0
- package/lib/public/css/server-settings.css +100 -0
- package/lib/public/index.html +26 -0
- package/lib/public/modules/app-header.js +4 -7
- package/lib/public/modules/app-home-hub.js +31 -7
- package/lib/public/modules/app-messages.js +13 -0
- package/lib/public/modules/app-notifications.js +5 -1
- package/lib/public/modules/app-panels.js +11 -21
- package/lib/public/modules/app-projects.js +10 -5
- package/lib/public/modules/command-palette.js +16 -5
- package/lib/public/modules/custom-icons-settings.js +399 -0
- package/lib/public/modules/custom-icons.js +114 -0
- package/lib/public/modules/diagnostic-format.js +34 -0
- package/lib/public/modules/diagnostics.js +297 -0
- package/lib/public/modules/emoji-picker.js +253 -6
- package/lib/public/modules/model-context-windows.js +62 -0
- package/lib/public/modules/popover-position.js +192 -0
- package/lib/public/modules/project-icon.js +113 -0
- package/lib/public/modules/project-settings.js +2 -2
- package/lib/public/modules/project-switcher.js +2 -1
- package/lib/public/modules/scheduler-config.js +5 -8
- package/lib/public/modules/scheduler.js +5 -6
- package/lib/public/modules/server-settings.js +6 -0
- package/lib/public/modules/sidebar-mobile.js +4 -6
- package/lib/public/modules/sidebar-projects.js +35 -90
- package/lib/public/modules/sidebar-sessions.js +6 -20
- package/lib/public/modules/sticky-notes.js +4 -4
- package/lib/public/modules/terminal.js +5 -12
- package/lib/public/style.css +1 -0
- package/lib/sdk-bridge.js +75 -10
- package/lib/sdk-message-processor.js +12 -0
- package/lib/sdk-worker.js +4 -1
- package/lib/server-settings.js +221 -1
- package/lib/server.js +30 -1
- package/lib/sessions.js +27 -11
- package/lib/settings-preflight.js +212 -0
- package/lib/ws-schema.js +2 -0
- package/lib/yoke/adapters/claude-worker.js +14 -2
- package/lib/yoke/adapters/claude.js +16 -0
- package/lib/yoke/adapters/diagnostic-patterns.js +120 -0
- package/lib/yoke/index.js +4 -0
- package/lib/yoke/interface.js +99 -0
- package/package.json +2 -1
- package/scripts/postinstall.js +41 -0
- package/lib/certs/fullchain.pem +0 -47
- package/lib/certs/privkey.pem +0 -5
|
@@ -7,6 +7,8 @@ import { openProjectSettings } from './project-settings.js';
|
|
|
7
7
|
import { triggerShare } from './qrcode.js';
|
|
8
8
|
import { parseEmojis } from './markdown.js';
|
|
9
9
|
import { buildEmojiPicker } from './emoji-picker.js';
|
|
10
|
+
import { renderProjectIcon, projectIconHtml } from './project-icon.js';
|
|
11
|
+
import { positionPopover } from './popover-position.js';
|
|
10
12
|
import { store } from './store.js';
|
|
11
13
|
import { getWs } from './ws-ref.js';
|
|
12
14
|
import { closeSidebar } from './sidebar.js';
|
|
@@ -190,18 +192,8 @@ function showProjectAccessPopover(anchorEl, slug) {
|
|
|
190
192
|
projectAccessPopover = popover;
|
|
191
193
|
|
|
192
194
|
requestAnimationFrame(function () {
|
|
193
|
-
|
|
194
|
-
popover.style.position = "fixed";
|
|
195
|
-
popover.style.left = (rect.right + 8) + "px";
|
|
196
|
-
popover.style.top = rect.top + "px";
|
|
195
|
+
positionPopover(popover, anchorEl, { placement: "right", gap: 8 });
|
|
197
196
|
popover.style.zIndex = "9999";
|
|
198
|
-
var popRect = popover.getBoundingClientRect();
|
|
199
|
-
if (popRect.right > window.innerWidth - 8) {
|
|
200
|
-
popover.style.left = (rect.left - popRect.width - 8) + "px";
|
|
201
|
-
}
|
|
202
|
-
if (popRect.bottom > window.innerHeight - 8) {
|
|
203
|
-
popover.style.top = (window.innerHeight - popRect.height - 8) + "px";
|
|
204
|
-
}
|
|
205
197
|
});
|
|
206
198
|
|
|
207
199
|
setTimeout(function () {
|
|
@@ -380,17 +372,7 @@ function showIconCtxMenu(anchorEl, slug, name) {
|
|
|
380
372
|
refreshIcons();
|
|
381
373
|
|
|
382
374
|
requestAnimationFrame(function () {
|
|
383
|
-
|
|
384
|
-
menu.style.position = "fixed";
|
|
385
|
-
menu.style.left = (rect.right + 6) + "px";
|
|
386
|
-
menu.style.top = rect.top + "px";
|
|
387
|
-
var menuRect = menu.getBoundingClientRect();
|
|
388
|
-
if (menuRect.right > window.innerWidth - 8) {
|
|
389
|
-
menu.style.left = (rect.left - menuRect.width - 6) + "px";
|
|
390
|
-
}
|
|
391
|
-
if (menuRect.bottom > window.innerHeight - 8) {
|
|
392
|
-
menu.style.top = (window.innerHeight - menuRect.height - 8) + "px";
|
|
393
|
-
}
|
|
375
|
+
positionPopover(menu, anchorEl, { placement: "right" });
|
|
394
376
|
});
|
|
395
377
|
}
|
|
396
378
|
|
|
@@ -599,27 +581,24 @@ function showProjectCtxMenu(anchorEl, slug, name, icon, position) {
|
|
|
599
581
|
refreshIcons();
|
|
600
582
|
|
|
601
583
|
requestAnimationFrame(function () {
|
|
602
|
-
|
|
603
|
-
menu
|
|
604
|
-
if (position === "below") {
|
|
605
|
-
menu.style.left = rect.left + "px";
|
|
606
|
-
menu.style.top = (rect.bottom + 4) + "px";
|
|
607
|
-
} else {
|
|
608
|
-
menu.style.left = (rect.right + 6) + "px";
|
|
609
|
-
menu.style.top = rect.top + "px";
|
|
610
|
-
}
|
|
611
|
-
var menuRect = menu.getBoundingClientRect();
|
|
612
|
-
if (menuRect.right > window.innerWidth - 8) {
|
|
613
|
-
menu.style.left = (rect.left - menuRect.width - 6) + "px";
|
|
614
|
-
}
|
|
615
|
-
if (menuRect.bottom > window.innerHeight - 8) {
|
|
616
|
-
menu.style.top = (window.innerHeight - menuRect.height - 8) + "px";
|
|
617
|
-
}
|
|
584
|
+
// "below" kept its original 4px gap; "right" keeps the shared default (6px).
|
|
585
|
+
positionPopover(menu, anchorEl, position === "below" ? { placement: "below", gap: 4 } : { placement: "right" });
|
|
618
586
|
});
|
|
619
587
|
}
|
|
620
588
|
|
|
621
589
|
// --- Emoji picker ---
|
|
622
590
|
|
|
591
|
+
// Position an emoji-picker popover relative to an anchor element, keeping it
|
|
592
|
+
// fully on-screen. Delegates to the shared viewport-clamp util (lr-a10a,
|
|
593
|
+
// generalized from the original lr-149e fix here): desktop is
|
|
594
|
+
// anchor-relative (right of the anchor, flipped left + four-edge clamped);
|
|
595
|
+
// mobile centers the picker in the viewport and clamps both axes — this is
|
|
596
|
+
// what icon-strip.css's mobile block expects (it no longer sets left/right
|
|
597
|
+
// itself, so there is nothing for these inline styles to fight).
|
|
598
|
+
function positionEmojiPicker(picker, anchorEl) {
|
|
599
|
+
positionPopover(picker, anchorEl, { placement: "right" });
|
|
600
|
+
}
|
|
601
|
+
|
|
623
602
|
function closeEmojiPicker() {
|
|
624
603
|
if (emojiPickerEl) {
|
|
625
604
|
emojiPickerEl.remove();
|
|
@@ -649,16 +628,7 @@ function showEmojiPicker(slug, anchorEl) {
|
|
|
649
628
|
emojiPickerEl = picker;
|
|
650
629
|
|
|
651
630
|
requestAnimationFrame(function () {
|
|
652
|
-
|
|
653
|
-
picker.style.left = (rect.right + 6) + "px";
|
|
654
|
-
picker.style.top = rect.top + "px";
|
|
655
|
-
var pRect = picker.getBoundingClientRect();
|
|
656
|
-
if (pRect.right > window.innerWidth - 8) {
|
|
657
|
-
picker.style.left = (rect.left - pRect.width - 6) + "px";
|
|
658
|
-
}
|
|
659
|
-
if (pRect.bottom > window.innerHeight - 8) {
|
|
660
|
-
picker.style.top = (window.innerHeight - pRect.height - 8) + "px";
|
|
661
|
-
}
|
|
631
|
+
positionEmojiPicker(picker, anchorEl);
|
|
662
632
|
});
|
|
663
633
|
}
|
|
664
634
|
|
|
@@ -685,16 +655,7 @@ function showFolderEmojiPicker(folderName, anchorEl) {
|
|
|
685
655
|
emojiPickerEl = picker;
|
|
686
656
|
|
|
687
657
|
requestAnimationFrame(function () {
|
|
688
|
-
|
|
689
|
-
picker.style.left = (rect.right + 6) + "px";
|
|
690
|
-
picker.style.top = rect.top + "px";
|
|
691
|
-
var pRect = picker.getBoundingClientRect();
|
|
692
|
-
if (pRect.right > window.innerWidth - 8) {
|
|
693
|
-
picker.style.left = (rect.left - pRect.width - 6) + "px";
|
|
694
|
-
}
|
|
695
|
-
if (pRect.bottom > window.innerHeight - 8) {
|
|
696
|
-
picker.style.top = (window.innerHeight - pRect.height - 8) + "px";
|
|
697
|
-
}
|
|
658
|
+
positionEmojiPicker(picker, anchorEl);
|
|
698
659
|
});
|
|
699
660
|
}
|
|
700
661
|
|
|
@@ -753,17 +714,7 @@ function showFolderCtxMenu(anchorEl, folderName) {
|
|
|
753
714
|
refreshIcons();
|
|
754
715
|
|
|
755
716
|
requestAnimationFrame(function () {
|
|
756
|
-
|
|
757
|
-
menu.style.position = "fixed";
|
|
758
|
-
menu.style.left = (rect.right + 6) + "px";
|
|
759
|
-
menu.style.top = rect.top + "px";
|
|
760
|
-
var menuRect = menu.getBoundingClientRect();
|
|
761
|
-
if (menuRect.right > window.innerWidth - 8) {
|
|
762
|
-
menu.style.left = (rect.left - menuRect.width - 6) + "px";
|
|
763
|
-
}
|
|
764
|
-
if (menuRect.bottom > window.innerHeight - 8) {
|
|
765
|
-
menu.style.top = (window.innerHeight - menuRect.height - 8) + "px";
|
|
766
|
-
}
|
|
717
|
+
positionPopover(menu, anchorEl, { placement: "right" });
|
|
767
718
|
});
|
|
768
719
|
}
|
|
769
720
|
|
|
@@ -778,7 +729,11 @@ function showMoveFolderMenu(anchorEl, slug, folders, position) {
|
|
|
778
729
|
var item = document.createElement("button");
|
|
779
730
|
item.className = "project-ctx-item";
|
|
780
731
|
var fmeta2 = cachedFolderMeta[fn] || {};
|
|
781
|
-
|
|
732
|
+
// LOCKED SCOPE (Andy, lr-a6da): folder icons support custom :slug: images
|
|
733
|
+
// at parity with project icons. projectIconHtml() routes custom icons to
|
|
734
|
+
// a safe <img> tag and emoji to escaped text; the prior raw fmeta2.icon
|
|
735
|
+
// interpolation showed ':slug:' as literal text.
|
|
736
|
+
var ficon = fmeta2.icon ? ('<span style="margin-right:4px">' + projectIconHtml(fmeta2.icon) + '</span>') : (iconHtml("folder") + " ");
|
|
782
737
|
item.innerHTML = ficon + "<span>" + escapeHtml(fn) + "</span>";
|
|
783
738
|
item.addEventListener("click", function (e) {
|
|
784
739
|
e.stopPropagation();
|
|
@@ -797,18 +752,8 @@ function showMoveFolderMenu(anchorEl, slug, folders, position) {
|
|
|
797
752
|
refreshIcons();
|
|
798
753
|
|
|
799
754
|
requestAnimationFrame(function () {
|
|
800
|
-
|
|
801
|
-
menu
|
|
802
|
-
if (position === "below") {
|
|
803
|
-
menu.style.left = rect.left + "px";
|
|
804
|
-
menu.style.top = (rect.bottom + 4) + "px";
|
|
805
|
-
} else {
|
|
806
|
-
menu.style.left = (rect.right + 6) + "px";
|
|
807
|
-
menu.style.top = rect.top + "px";
|
|
808
|
-
}
|
|
809
|
-
var menuRect = menu.getBoundingClientRect();
|
|
810
|
-
if (menuRect.right > window.innerWidth - 8) menu.style.left = (rect.left - menuRect.width - 6) + "px";
|
|
811
|
-
if (menuRect.bottom > window.innerHeight - 8) menu.style.top = (window.innerHeight - menuRect.height - 8) + "px";
|
|
755
|
+
// "below" kept its original 4px gap; "right" keeps the shared default (6px).
|
|
756
|
+
positionPopover(menu, anchorEl, position === "below" ? { placement: "below", gap: 4 } : { placement: "right" });
|
|
812
757
|
});
|
|
813
758
|
}
|
|
814
759
|
|
|
@@ -1353,8 +1298,7 @@ function createIconItem(p, currentSlug) {
|
|
|
1353
1298
|
if (p.icon) {
|
|
1354
1299
|
var emojiSpan = document.createElement("span");
|
|
1355
1300
|
emojiSpan.className = "project-emoji";
|
|
1356
|
-
|
|
1357
|
-
parseEmojis(emojiSpan);
|
|
1301
|
+
renderProjectIcon(p.icon, emojiSpan, parseEmojis);
|
|
1358
1302
|
el.appendChild(emojiSpan);
|
|
1359
1303
|
} else {
|
|
1360
1304
|
el.appendChild(document.createTextNode(getProjectAbbrev(p.name)));
|
|
@@ -1635,10 +1579,13 @@ function renderUserFolder(unit, wtByParent, currentSlug, currentDmUserId) {
|
|
|
1635
1579
|
var iconBox = document.createElement("span");
|
|
1636
1580
|
iconBox.className = "icon-strip-folder-icon-box";
|
|
1637
1581
|
if (fmeta.icon) {
|
|
1638
|
-
//
|
|
1582
|
+
// LOCKED SCOPE (Andy, lr-a6da): folder icons support custom :slug: images
|
|
1583
|
+
// at parity with project icons. renderProjectIcon() routes custom icons to
|
|
1584
|
+
// <img> and emoji to text; the prior plain textContent assignment showed
|
|
1585
|
+
// ':slug:' as literal text.
|
|
1639
1586
|
var emojiSpan = document.createElement("span");
|
|
1640
1587
|
emojiSpan.className = "icon-strip-folder-emoji-main";
|
|
1641
|
-
|
|
1588
|
+
renderProjectIcon(fmeta.icon, emojiSpan, parseEmojis);
|
|
1642
1589
|
iconBox.appendChild(emojiSpan);
|
|
1643
1590
|
} else {
|
|
1644
1591
|
// Fallback: folder SVG icon
|
|
@@ -1861,8 +1808,7 @@ function renderWorktreeGroup(p, worktrees, currentSlug, currentDmUserId) {
|
|
|
1861
1808
|
if (wt.icon) {
|
|
1862
1809
|
var wtEmoji = document.createElement("span");
|
|
1863
1810
|
wtEmoji.className = "wt-branch-abbrev project-emoji";
|
|
1864
|
-
|
|
1865
|
-
parseEmojis(wtEmoji);
|
|
1811
|
+
renderProjectIcon(wt.icon, wtEmoji, parseEmojis);
|
|
1866
1812
|
wtEl.appendChild(wtEmoji);
|
|
1867
1813
|
} else {
|
|
1868
1814
|
var abbrev = document.createElement("span");
|
|
@@ -1998,8 +1944,7 @@ function createMobileProjectItem(p, currentSlug, isWorktree) {
|
|
|
1998
1944
|
var abbrev = document.createElement("span");
|
|
1999
1945
|
abbrev.className = "mobile-project-abbrev";
|
|
2000
1946
|
if (p.icon) {
|
|
2001
|
-
|
|
2002
|
-
parseEmojis(abbrev);
|
|
1947
|
+
renderProjectIcon(p.icon, abbrev, parseEmojis);
|
|
2003
1948
|
} else {
|
|
2004
1949
|
abbrev.textContent = getProjectAbbrev(p.name);
|
|
2005
1950
|
}
|
|
@@ -14,6 +14,7 @@ import { getUpcomingSchedules } from './scheduler.js';
|
|
|
14
14
|
import { refreshMobileChatSheet } from './sidebar-mobile.js';
|
|
15
15
|
import { openAgentPicker, openAgentPickerForPreferred } from './agent-picker.js';
|
|
16
16
|
import { getCachedProjects } from './app-projects.js';
|
|
17
|
+
import { positionPopover } from './popover-position.js';
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
// --- Session state ---
|
|
@@ -682,18 +683,11 @@ function showSessionCtxMenu(anchorBtn, sessionId, title, cliSid, sessionData) {
|
|
|
682
683
|
sessionCtxMenu = menu;
|
|
683
684
|
refreshIcons();
|
|
684
685
|
|
|
685
|
-
// Position: fixed relative to the anchor button
|
|
686
|
+
// Position: fixed relative to the anchor button, right-edge aligned,
|
|
687
|
+
// flip-then-clamp on all four edges (lr-a10a: the prior bottom-flip-only
|
|
688
|
+
// logic could leave the flipped menu with top < 0 on a short viewport).
|
|
686
689
|
requestAnimationFrame(function () {
|
|
687
|
-
|
|
688
|
-
menu.style.position = "fixed";
|
|
689
|
-
menu.style.top = (btnRect.bottom + 2) + "px";
|
|
690
|
-
menu.style.right = (window.innerWidth - btnRect.right) + "px";
|
|
691
|
-
menu.style.left = "auto";
|
|
692
|
-
// If menu overflows below viewport, flip up
|
|
693
|
-
var menuRect = menu.getBoundingClientRect();
|
|
694
|
-
if (menuRect.bottom > window.innerHeight - 8) {
|
|
695
|
-
menu.style.top = (btnRect.top - menuRect.height - 2) + "px";
|
|
696
|
-
}
|
|
690
|
+
positionPopover(menu, anchorBtn, { placement: "below-right-aligned", gap: 2 });
|
|
697
691
|
});
|
|
698
692
|
}
|
|
699
693
|
|
|
@@ -737,15 +731,7 @@ function showLoopCtxMenu(anchorBtn, loopId, loopName, childCount) {
|
|
|
737
731
|
refreshIcons();
|
|
738
732
|
|
|
739
733
|
requestAnimationFrame(function () {
|
|
740
|
-
|
|
741
|
-
menu.style.position = "fixed";
|
|
742
|
-
menu.style.top = (btnRect.bottom + 2) + "px";
|
|
743
|
-
menu.style.right = (window.innerWidth - btnRect.right) + "px";
|
|
744
|
-
menu.style.left = "auto";
|
|
745
|
-
var menuRect = menu.getBoundingClientRect();
|
|
746
|
-
if (menuRect.bottom > window.innerHeight - 8) {
|
|
747
|
-
menu.style.top = (btnRect.top - menuRect.height - 2) + "px";
|
|
748
|
-
}
|
|
734
|
+
positionPopover(menu, anchorBtn, { placement: "below-right-aligned", gap: 2 });
|
|
749
735
|
});
|
|
750
736
|
}
|
|
751
737
|
|
|
@@ -1,5 +1,6 @@
|
|
|
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
4
|
|
|
4
5
|
var ctx;
|
|
5
6
|
var notes = new Map(); // id -> { data, el }
|
|
@@ -835,10 +836,9 @@ function showColorPicker(anchor, noteEl, noteId) {
|
|
|
835
836
|
document.body.appendChild(picker);
|
|
836
837
|
colorPickerEl = picker;
|
|
837
838
|
|
|
838
|
-
// Position relative to anchor
|
|
839
|
-
|
|
840
|
-
picker
|
|
841
|
-
picker.style.top = (rect.bottom + 4) + "px";
|
|
839
|
+
// Position relative to anchor, clamped to the viewport on all four edges
|
|
840
|
+
// (lr-a10a: this popover previously had no clamp at all).
|
|
841
|
+
positionPopover(picker, anchor, { placement: "below", gap: 4 });
|
|
842
842
|
|
|
843
843
|
// Close on outside click
|
|
844
844
|
setTimeout(function () {
|
|
@@ -3,6 +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
7
|
|
|
7
8
|
var ctx;
|
|
8
9
|
var tabs = new Map(); // termId -> { id, title, exited, xterm, fitAddon, bodyEl }
|
|
@@ -877,19 +878,11 @@ function showTermCtxMenu(e, tab) {
|
|
|
877
878
|
});
|
|
878
879
|
menu.appendChild(clearItem);
|
|
879
880
|
|
|
880
|
-
// Position at mouse cursor
|
|
881
|
-
|
|
882
|
-
|
|
881
|
+
// Position at mouse cursor, clamped to viewport on all four edges
|
|
882
|
+
// (lr-a10a: mobile's synthetic contextmenu can fire from a low/edge
|
|
883
|
+
// touch point, so a right/bottom-only clamp isn't enough).
|
|
883
884
|
document.body.appendChild(menu);
|
|
884
|
-
|
|
885
|
-
// Clamp to viewport
|
|
886
|
-
var rect = menu.getBoundingClientRect();
|
|
887
|
-
if (rect.right > window.innerWidth) {
|
|
888
|
-
menu.style.left = (window.innerWidth - rect.width - 4) + "px";
|
|
889
|
-
}
|
|
890
|
-
if (rect.bottom > window.innerHeight) {
|
|
891
|
-
menu.style.top = (window.innerHeight - rect.height - 4) + "px";
|
|
892
|
-
}
|
|
885
|
+
positionAtPoint(menu, { x: e.clientX, y: e.clientY });
|
|
893
886
|
|
|
894
887
|
termCtxMenu = menu;
|
|
895
888
|
refreshIcons();
|
package/lib/public/style.css
CHANGED
package/lib/sdk-bridge.js
CHANGED
|
@@ -11,6 +11,8 @@ var { attachMessageProcessor } = require("./sdk-message-processor");
|
|
|
11
11
|
var { readAgentToolsFromFile, parseFrontmatter, slugifyAgentName, AGENTS_SOURCE_DIR } = require("./agents");
|
|
12
12
|
var { discoverWorkflows } = require("./sdk-workflow-discovery");
|
|
13
13
|
var { buildEnrichedSlashCommands } = require("./sdk-slash-enrichment");
|
|
14
|
+
var { KNOWN_CONTEXT_WINDOWS: _BACKEND_KNOWN_CONTEXT_WINDOWS, resolveModelContextWindow } = require("./model-context-windows");
|
|
15
|
+
var { runPreflight } = require("./settings-preflight");
|
|
14
16
|
|
|
15
17
|
// --- lr-29f9: Global concurrent-session ceiling ---
|
|
16
18
|
// Counts queries that are actively running (startQuery entered, processQueryStream
|
|
@@ -33,6 +35,21 @@ var DEFAULT_MEM_AVAILABLE_MIN_MB = 1024;
|
|
|
33
35
|
// yielding approximately 67 tokens per MB of headroom consumed.
|
|
34
36
|
var DEFAULT_TOKENS_PER_MB_HEADROOM = 67;
|
|
35
37
|
|
|
38
|
+
// Configurable warn fractions for context guards (lr-1f7e).
|
|
39
|
+
// cgroupWarnFraction: warn when context tokens exceed this fraction of the
|
|
40
|
+
// cgroup-headroom-derived ceiling (configurable via getConfig().cgroupWarnFraction).
|
|
41
|
+
// contextWindowWarnFraction: proactively warn when context tokens exceed this
|
|
42
|
+
// fraction of the model's context window (configurable via
|
|
43
|
+
// getConfig().contextWindowWarnFraction). 0/null → skip window-based warn.
|
|
44
|
+
var DEFAULT_CGROUP_WARN_FRACTION = 0.8;
|
|
45
|
+
var DEFAULT_CONTEXT_WINDOW_WARN_FRACTION = 0.8;
|
|
46
|
+
|
|
47
|
+
// Known context windows for models the backend may encounter (lr-1f7e, lr-336f).
|
|
48
|
+
// Imported from lib/model-context-windows.js — shared source of truth with the frontend.
|
|
49
|
+
// The alias preserves backward compatibility for any callers that reference this name.
|
|
50
|
+
var BACKEND_KNOWN_CONTEXT_WINDOWS = _BACKEND_KNOWN_CONTEXT_WINDOWS;
|
|
51
|
+
// resolveModelContextWindow imported from lib/model-context-windows.js above.
|
|
52
|
+
|
|
36
53
|
// Read Linux MemAvailable from /proc/meminfo synchronously.
|
|
37
54
|
// Returns available memory in MB, or null on non-Linux or read failure.
|
|
38
55
|
// Sub-millisecond on Linux; the synchronous read is correct here — this is a
|
|
@@ -1295,24 +1312,51 @@ function createSDKBridge(opts) {
|
|
|
1295
1312
|
return;
|
|
1296
1313
|
}
|
|
1297
1314
|
}
|
|
1298
|
-
// lr-2d91:
|
|
1315
|
+
// lr-2d91 / lr-1f7e: context token guards — apply to ALL turns because long-running
|
|
1299
1316
|
// sessions accumulate context across turns and each new turn will load the full
|
|
1300
1317
|
// accumulated context into memory. Placed after the memAvailableMinMB gate and
|
|
1301
1318
|
// before the slot is claimed so a rejected query never increments the live counter.
|
|
1302
1319
|
var contextTokens = session.lastStreamInputTokens || 0;
|
|
1303
1320
|
if (contextTokens > 0) {
|
|
1321
|
+
// Read configurable fractions once so they are available to both checks below.
|
|
1322
|
+
var _guardCfg = typeof opts.getConfig === "function" ? opts.getConfig() : null;
|
|
1323
|
+
var cgWarnFraction = DEFAULT_CGROUP_WARN_FRACTION;
|
|
1324
|
+
var ctxWinWarnFraction = DEFAULT_CONTEXT_WINDOW_WARN_FRACTION;
|
|
1325
|
+
if (_guardCfg) {
|
|
1326
|
+
if (typeof _guardCfg.cgroupWarnFraction === "number" && _guardCfg.cgroupWarnFraction >= 0) {
|
|
1327
|
+
// 0 is a valid value meaning "disabled" — allow it to override the default
|
|
1328
|
+
cgWarnFraction = _guardCfg.cgroupWarnFraction;
|
|
1329
|
+
}
|
|
1330
|
+
if (typeof _guardCfg.contextWindowWarnFraction === "number" && _guardCfg.contextWindowWarnFraction >= 0) {
|
|
1331
|
+
// 0 is a valid value meaning "disabled" — allow it to override the default
|
|
1332
|
+
ctxWinWarnFraction = _guardCfg.contextWindowWarnFraction;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// lr-1f7e: proactive model context-window warn.
|
|
1337
|
+
// Fires before the cgroup hard gate so the user gets an early signal.
|
|
1338
|
+
// Degrades cleanly when the model window is unknown (resolveModelContextWindow returns 0)
|
|
1339
|
+
// or when ctxWinWarnFraction is 0 (disabled via config).
|
|
1340
|
+
// Pass sm.currentBetas so context-1m beta is respected (mirrors app-panels.js logic).
|
|
1341
|
+
var _sessionModel = session.model || sm.currentModel || null;
|
|
1342
|
+
var _modelWindow = resolveModelContextWindow(_sessionModel, sm.currentBetas || []);
|
|
1343
|
+
if (_modelWindow > 0 && ctxWinWarnFraction > 0) {
|
|
1344
|
+
var _winWarnTokens = Math.floor(_modelWindow * ctxWinWarnFraction);
|
|
1345
|
+
if (contextTokens >= _winWarnTokens) {
|
|
1346
|
+
console.warn("[sdk-bridge] context-window warn: " + Math.round(contextTokens / 1000) + "K tokens >= " + Math.round(_winWarnTokens / 1000) + "K (" + Math.round(ctxWinWarnFraction * 100) + "% of " + Math.round(_modelWindow / 1000) + "K window) for session " + session.localId);
|
|
1347
|
+
send({ type: "toast", level: "warn", message: "Session context is " + Math.round((contextTokens / _modelWindow) * 100) + "% full (" + Math.round(contextTokens / 1000) + "K / " + Math.round(_modelWindow / 1000) + "K tokens). Consider starting a new session.", duration: 8000 });
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
// lr-2d91: cgroup hard gate — block the query if context exceeds headroom.
|
|
1304
1352
|
var cgHeadroomMB = readCgroupHeadroomMB();
|
|
1305
1353
|
if (cgHeadroomMB !== null) {
|
|
1306
1354
|
var tokensPerMb = DEFAULT_TOKENS_PER_MB_HEADROOM;
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
var _cgCfg = _getConfig();
|
|
1310
|
-
if (_cgCfg && typeof _cgCfg.tokensPerMbHeadroom === "number" && _cgCfg.tokensPerMbHeadroom > 0) {
|
|
1311
|
-
tokensPerMb = _cgCfg.tokensPerMbHeadroom;
|
|
1312
|
-
}
|
|
1355
|
+
if (_guardCfg && typeof _guardCfg.tokensPerMbHeadroom === "number" && _guardCfg.tokensPerMbHeadroom > 0) {
|
|
1356
|
+
tokensPerMb = _guardCfg.tokensPerMbHeadroom;
|
|
1313
1357
|
}
|
|
1314
1358
|
var allowedTokens = cgHeadroomMB * tokensPerMb;
|
|
1315
|
-
var warnTokens = Math.floor(allowedTokens *
|
|
1359
|
+
var warnTokens = Math.floor(allowedTokens * cgWarnFraction);
|
|
1316
1360
|
if (contextTokens >= allowedTokens) {
|
|
1317
1361
|
console.warn("[sdk-bridge] cgroup context guard: " + Math.round(contextTokens / 1000) + "K tokens >= " + Math.round(allowedTokens / 1000) + "K allowed (" + cgHeadroomMB + " MB headroom) — blocking session " + session.localId);
|
|
1318
1362
|
session.isProcessing = false;
|
|
@@ -1323,7 +1367,8 @@ function createSDKBridge(opts) {
|
|
|
1323
1367
|
send({ type: "toast", level: "error", message: "Session blocked — context too large for available memory.", duration: 7000 });
|
|
1324
1368
|
sm.broadcastSessionList();
|
|
1325
1369
|
return;
|
|
1326
|
-
} else if (contextTokens >= warnTokens) {
|
|
1370
|
+
} else if (cgWarnFraction > 0 && contextTokens >= warnTokens) {
|
|
1371
|
+
// cgWarnFraction === 0 means the warn is disabled; skip it.
|
|
1327
1372
|
send({ type: "toast", level: "warn", message: "Large session context (" + Math.round(contextTokens / 1000) + "K tokens). Consider starting a new session to avoid memory pressure.", duration: 8000 });
|
|
1328
1373
|
}
|
|
1329
1374
|
}
|
|
@@ -1803,6 +1848,20 @@ function createSDKBridge(opts) {
|
|
|
1803
1848
|
sm.modelsByVendor[defaultVendor] = result.models || [];
|
|
1804
1849
|
sm.capabilitiesByVendor = sm.capabilitiesByVendor || {};
|
|
1805
1850
|
sm.capabilitiesByVendor[defaultVendor] = result.capabilities || {};
|
|
1851
|
+
|
|
1852
|
+
// lr-1a26: Console-side settings preflight (epic lr-1a52 stage 5/5).
|
|
1853
|
+
// Non-blocking: runs after warmup succeeds, errors are swallowed so
|
|
1854
|
+
// preflight never blocks or fails the init path. Results are sent as
|
|
1855
|
+
// diagnostic events through the same pipeline stages 2-4 established.
|
|
1856
|
+
try {
|
|
1857
|
+
var preflightDiags = runPreflight({ projectDir: cwd });
|
|
1858
|
+
for (var _pi = 0; _pi < preflightDiags.length; _pi++) {
|
|
1859
|
+
send(preflightDiags[_pi]);
|
|
1860
|
+
}
|
|
1861
|
+
} catch (preflightErr) {
|
|
1862
|
+
// Swallow all preflight errors — preflight must never affect init.
|
|
1863
|
+
console.warn("[sdk-bridge] settings preflight failed (non-fatal):", preflightErr && preflightErr.message || preflightErr);
|
|
1864
|
+
}
|
|
1806
1865
|
} catch (e) {
|
|
1807
1866
|
if (e && e.name !== "AbortError" && !(e.message && e.message.indexOf("aborted") !== -1)) {
|
|
1808
1867
|
send({ type: "error", text: "Failed to load " + defaultVendor + " SDK: " + (e.message || e) });
|
|
@@ -2115,5 +2174,11 @@ function createSDKBridge(opts) {
|
|
|
2115
2174
|
};
|
|
2116
2175
|
}
|
|
2117
2176
|
|
|
2118
|
-
|
|
2177
|
+
// Return the current number of active live queries across ALL bridge instances.
|
|
2178
|
+
// Used by the drain controller (lr-6b30) to decide when it is safe to exit.
|
|
2179
|
+
function getActiveLiveCount() {
|
|
2180
|
+
return _activeLiveCount;
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
module.exports = { createSDKBridge, createMessageQueue, readMemAvailableMB, readCgroupHeadroomMB, resolveModelContextWindow, DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount };
|
|
2119
2184
|
|
|
@@ -769,6 +769,18 @@ function attachMessageProcessor(ctx) {
|
|
|
769
769
|
var retryText = parsed.message || parsed.error || "Retrying API request...";
|
|
770
770
|
sendToSession(session, { type: "system_info", text: retryText });
|
|
771
771
|
|
|
772
|
+
} else if (parsed.yokeType === "diagnostic") {
|
|
773
|
+
// Diagnostic events captured from CLI stderr (stage 3/5, lr-0868, epic lr-1a52).
|
|
774
|
+
// These are NOT errors — they are informational/warning signals from the CLI
|
|
775
|
+
// (e.g. unknown hook events, settings warnings, deprecation notices).
|
|
776
|
+
// Stage 4/5 (lr-8294) renders this message as a toast + Diagnostics panel entry.
|
|
777
|
+
sendAndRecord(session, {
|
|
778
|
+
type: "diagnostic",
|
|
779
|
+
severity: parsed.severity,
|
|
780
|
+
source: parsed.source,
|
|
781
|
+
message: parsed.message,
|
|
782
|
+
});
|
|
783
|
+
|
|
772
784
|
} else if (parsed.yokeType === "system") {
|
|
773
785
|
// Catch-all for unhandled system subtypes (e.g. hook-block errors).
|
|
774
786
|
// Extract any error text and surface it in the UI.
|
package/lib/sdk-worker.js
CHANGED
|
@@ -370,7 +370,10 @@ async function handleQueryStart(msg) {
|
|
|
370
370
|
if (_mcpServers) options.mcpServers = _mcpServers;
|
|
371
371
|
options.abortController = abortController;
|
|
372
372
|
if (process.env.CLAGENTIC_DEBUG === "1") {
|
|
373
|
-
|
|
373
|
+
// worker-logs lives under CONFIG_DIR (= ~/.clagentic/console/); old path was ~/.clagentic/worker-logs/.
|
|
374
|
+
// No migration needed — these are ephemeral debug logs, not persistent data.
|
|
375
|
+
var _configDir = process.env.CLAGENTIC_HOME ? path.join(process.env.CLAGENTIC_HOME, "console") : path.join(os.homedir(), ".clagentic", "console");
|
|
376
|
+
var _logDir = path.join(_configDir, "worker-logs");
|
|
374
377
|
fs.mkdirSync(_logDir, { recursive: true, mode: 0o700 });
|
|
375
378
|
var _logFile = path.join(_logDir, process.pid + ".log");
|
|
376
379
|
// Create with 0o600 before passing to the SDK so the file is never world-readable
|