@clagentic/console 1.4.0-beta.2 → 1.4.0-beta.3
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/lib/daemon.js +19 -0
- package/lib/project-sessions.js +19 -1
- package/lib/project.js +8 -0
- package/lib/public/app.js +17 -3
- package/lib/public/css/input.css +5 -0
- package/lib/public/modules/app-header.js +7 -1
- package/lib/public/modules/app-messages.js +10 -5
- package/lib/public/modules/command-palette.js +3 -0
- package/lib/public/modules/input.js +18 -2
- package/lib/public/modules/overlay-history.js +62 -0
- package/lib/public/modules/project-settings.js +3 -0
- package/lib/public/modules/scheduler.js +3 -0
- package/lib/public/modules/server-settings.js +4 -1
- package/lib/public/modules/session-search.js +3 -0
- package/lib/public/modules/sticky-notes.js +3 -0
- package/lib/sdk-bridge.js +72 -13
- package/lib/sdk-message-processor.js +21 -10
- package/lib/sdk-skill-discovery.js +199 -1
- package/lib/sdk-slash-enrichment.js +64 -0
- package/lib/sdk-worker.js +17 -0
- package/lib/sdk-workflow-discovery.js +151 -0
- package/lib/server.js +2 -0
- package/lib/sessions.js +2 -0
- package/lib/yoke/adapters/claude-worker.js +17 -0
- package/lib/yoke/adapters/claude.js +13 -3
- package/lib/yoke/adapters/codex.js +53 -4
- package/package.json +1 -1
package/lib/daemon.js
CHANGED
|
@@ -30,6 +30,7 @@ var { checkAclSupport, grantProjectAccess, revokeProjectAccess, provisionAllUser
|
|
|
30
30
|
var usersModule = require("./users");
|
|
31
31
|
var { createWorktree, removeWorktree, isWorktree } = require("./worktree");
|
|
32
32
|
var { isWorktreeSlug, scanAndRegisterWorktrees, rescanWorktrees, cleanupWorktreesForParent, getFilteredRemovedProjects, registerWorktreeSlug, unregisterWorktreeSlug } = require("./daemon-projects");
|
|
33
|
+
var { DEFAULT_MEM_AVAILABLE_MIN_MB } = require("./sdk-bridge");
|
|
33
34
|
|
|
34
35
|
var daemonVersion = require("../package.json").version;
|
|
35
36
|
var configFile = process.env.CLAGENTIC_CONFIG || process.env.CLAY_CONFIG || require("./config").configPath();
|
|
@@ -845,6 +846,7 @@ var relay = createServer({
|
|
|
845
846
|
lanIp: lanIp || null,
|
|
846
847
|
updateChannel: config.updateChannel || "stable",
|
|
847
848
|
imageRetentionDays: config.imageRetentionDays !== undefined ? config.imageRetentionDays : 7,
|
|
849
|
+
memAvailableMinMB: config.memAvailableMinMB !== undefined ? config.memAvailableMinMB : DEFAULT_MEM_AVAILABLE_MIN_MB,
|
|
848
850
|
};
|
|
849
851
|
},
|
|
850
852
|
onSetImageRetention: function (days) {
|
|
@@ -906,6 +908,14 @@ var relay = createServer({
|
|
|
906
908
|
console.log("[daemon] Auto-continue on rate limit:", want, "(web)");
|
|
907
909
|
return { ok: true, autoContinueOnRateLimit: want };
|
|
908
910
|
},
|
|
911
|
+
onSetMemAvailableThreshold: function (mb) {
|
|
912
|
+
var val = parseInt(mb, 10);
|
|
913
|
+
if (isNaN(val) || val < 0) val = DEFAULT_MEM_AVAILABLE_MIN_MB;
|
|
914
|
+
config.memAvailableMinMB = val;
|
|
915
|
+
saveConfig(config);
|
|
916
|
+
console.log("[daemon] MemAvailable threshold:", val, "MB (web)");
|
|
917
|
+
return { ok: true, memAvailableMinMB: val };
|
|
918
|
+
},
|
|
909
919
|
onGetToolPalettes: function () {
|
|
910
920
|
return config.toolPalettes || {};
|
|
911
921
|
},
|
|
@@ -1282,6 +1292,15 @@ var ipc = createIPCServer(socketPath(), function (msg) {
|
|
|
1282
1292
|
return { ok: true };
|
|
1283
1293
|
}
|
|
1284
1294
|
|
|
1295
|
+
case "set_mem_available_threshold": {
|
|
1296
|
+
var memMB = parseInt(msg.value, 10);
|
|
1297
|
+
if (isNaN(memMB) || memMB < 0) memMB = DEFAULT_MEM_AVAILABLE_MIN_MB;
|
|
1298
|
+
config.memAvailableMinMB = memMB;
|
|
1299
|
+
saveConfig(config);
|
|
1300
|
+
console.log("[daemon] MemAvailable threshold:", memMB, "MB (cli)");
|
|
1301
|
+
return { ok: true, memAvailableMinMB: memMB };
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1285
1304
|
case "enable_recovery": {
|
|
1286
1305
|
if (!msg.urlPath || !msg.password) return { ok: false, error: "missing urlPath or password" };
|
|
1287
1306
|
relay.setRecovery(msg.urlPath, msg.password);
|
package/lib/project-sessions.js
CHANGED
|
@@ -2,6 +2,7 @@ var fs = require("fs");
|
|
|
2
2
|
var path = require("path");
|
|
3
3
|
var { execFileSync } = require("child_process");
|
|
4
4
|
var { CODEX_DEFAULTS, getCodexConfig } = require("./codex-defaults");
|
|
5
|
+
var { readMemAvailableMB } = require("./sdk-bridge");
|
|
5
6
|
var agentsModule = require("./agents");
|
|
6
7
|
var agentsFavorites = require("./agents-favorites");
|
|
7
8
|
var relayClaims = require("./relay-agent-claims");
|
|
@@ -574,6 +575,10 @@ function attachSessions(ctx) {
|
|
|
574
575
|
if (s.isProcessing) processingCount++;
|
|
575
576
|
});
|
|
576
577
|
var mem = process.memoryUsage();
|
|
578
|
+
// lr-2d91: Include memory pressure fields so the admin panel can show
|
|
579
|
+
// pressure building before the MemAvailable gate fires.
|
|
580
|
+
var memStats = (sdk && typeof sdk.getMemoryStats === "function") ? sdk.getMemoryStats() : {};
|
|
581
|
+
var memAvailMB = readMemAvailableMB();
|
|
577
582
|
sendTo(ws, {
|
|
578
583
|
type: "process_stats",
|
|
579
584
|
pid: process.pid,
|
|
@@ -588,6 +593,9 @@ function attachSessions(ctx) {
|
|
|
588
593
|
processing: processingCount,
|
|
589
594
|
clients: clients.size,
|
|
590
595
|
terminals: tm.list().length,
|
|
596
|
+
memAvailableMB: memAvailMB,
|
|
597
|
+
activeLiveCount: memStats.activeLiveCount !== undefined ? memStats.activeLiveCount : null,
|
|
598
|
+
maxConcurrentSessions: memStats.maxConcurrentSessions !== undefined ? memStats.maxConcurrentSessions : null,
|
|
591
599
|
});
|
|
592
600
|
return true;
|
|
593
601
|
}
|
|
@@ -1546,7 +1554,8 @@ function attachSessions(ctx) {
|
|
|
1546
1554
|
|
|
1547
1555
|
// --- Daemon config / server management (admin-only in multi-user mode) ---
|
|
1548
1556
|
if (msg.type === "get_daemon_config" || msg.type === "set_pin" || msg.type === "set_keep_awake" ||
|
|
1549
|
-
msg.type === "set_auto_continue" || msg.type === "set_image_retention" || msg.type === "
|
|
1557
|
+
msg.type === "set_auto_continue" || msg.type === "set_image_retention" || msg.type === "set_mem_available_threshold" ||
|
|
1558
|
+
msg.type === "shutdown_server" || msg.type === "restart_server") {
|
|
1550
1559
|
if (usersModule.isMultiUser()) {
|
|
1551
1560
|
var _wsUser = ws._clayUser;
|
|
1552
1561
|
if (!_wsUser || _wsUser.role !== "admin") {
|
|
@@ -1598,6 +1607,15 @@ function attachSessions(ctx) {
|
|
|
1598
1607
|
return true;
|
|
1599
1608
|
}
|
|
1600
1609
|
|
|
1610
|
+
if (msg.type === "set_mem_available_threshold") {
|
|
1611
|
+
if (typeof opts.onSetMemAvailableThreshold === "function") {
|
|
1612
|
+
var matResult = opts.onSetMemAvailableThreshold(msg.value);
|
|
1613
|
+
sendTo(ws, { type: "set_mem_available_threshold_result", ok: matResult.ok, memAvailableMinMB: matResult.memAvailableMinMB });
|
|
1614
|
+
send({ type: "mem_available_threshold_changed", memAvailableMinMB: matResult.memAvailableMinMB });
|
|
1615
|
+
}
|
|
1616
|
+
return true;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1601
1619
|
if (msg.type === "shutdown_server") {
|
|
1602
1620
|
if (typeof opts.onShutdown === "function") {
|
|
1603
1621
|
sendTo(ws, { type: "shutdown_server_result", ok: true });
|
package/lib/project.js
CHANGED
|
@@ -583,6 +583,14 @@ function createProjectContext(opts) {
|
|
|
583
583
|
}
|
|
584
584
|
return false;
|
|
585
585
|
},
|
|
586
|
+
// lr-2d91: Live config callback so sdk-bridge reads the current threshold on
|
|
587
|
+
// every query — not a stale value cached at bridge creation time.
|
|
588
|
+
getConfig: function () {
|
|
589
|
+
if (typeof opts.onGetDaemonConfig === "function") {
|
|
590
|
+
return opts.onGetDaemonConfig();
|
|
591
|
+
}
|
|
592
|
+
return {};
|
|
593
|
+
},
|
|
586
594
|
});
|
|
587
595
|
|
|
588
596
|
// --- Loop engine (delegated to project-loop.js) ---
|
package/lib/public/app.js
CHANGED
|
@@ -26,8 +26,8 @@ import { initContextSources, updateTerminalList, updateBrowserTabList, handleCon
|
|
|
26
26
|
import { initStickyNotes, handleNotesList, handleNoteCreated, handleNoteUpdated, handleNoteDeleted, openArchive, closeArchive, isArchiveOpen, hideNotes, showNotes, isNotesVisible, createNote } from './modules/sticky-notes.js';
|
|
27
27
|
import { initTheme, getThemeColor, getComputedVar, onThemeChange, getCurrentTheme, getChatLayout } from './modules/theme.js';
|
|
28
28
|
import { initTools, resetToolState, saveToolState, restoreToolState, renderAskUserQuestion, markAskUserAnswered, renderPermissionRequest, markPermissionResolved, markPermissionCancelled, renderElicitationRequest, markElicitationResolved, renderPlanBanner, renderPlanCard, handleTodoWrite, handleTaskCreate, handleTaskUpdate, startThinking, appendThinking, stopThinking, resetThinkingGroup, createToolItem, updateToolExecuting, updateToolResult, markAllToolsDone, addTurnMeta, resetTurnMetaCost, enableMainInput, getTools, getPlanContent, setPlanContent, isPlanFilePath, getTodoTools, updateSubagentActivity, addSubagentToolEntry, markSubagentDone, updateSubagentProgress, initSubagentStop, closeToolGroup, removeToolFromGroup } from './modules/tools.js';
|
|
29
|
-
import { initServerSettings, updateSettingsStats, updateSettingsModels, updateDaemonConfig, handleSetPinResult, handleKeepAwakeChanged, handleAutoContinueChanged, handleRestartResult, handleShutdownResult, handleSharedEnv, handleSharedEnvSaved, handleGlobalClaudeMdRead, handleGlobalClaudeMdWrite } from './modules/server-settings.js';
|
|
30
|
-
import { initProjectSettings, handleInstructionsRead, handleInstructionsWrite, handleProjectEnv, handleProjectEnvSaved, isProjectSettingsOpen, handleProjectSharedEnv, handleProjectSharedEnvSaved, handleProjectOwnerChanged } from './modules/project-settings.js';
|
|
29
|
+
import { initServerSettings, updateSettingsStats, updateSettingsModels, updateDaemonConfig, handleSetPinResult, handleKeepAwakeChanged, handleAutoContinueChanged, handleRestartResult, handleShutdownResult, handleSharedEnv, handleSharedEnvSaved, handleGlobalClaudeMdRead, handleGlobalClaudeMdWrite, isSettingsOpen, closeSettings } from './modules/server-settings.js';
|
|
30
|
+
import { initProjectSettings, handleInstructionsRead, handleInstructionsWrite, handleProjectEnv, handleProjectEnvSaved, isProjectSettingsOpen, closeProjectSettings, handleProjectSharedEnv, handleProjectSharedEnvSaved, handleProjectOwnerChanged } from './modules/project-settings.js';
|
|
31
31
|
import { initSkills, handleSkillInstalled, handleSkillUninstalled } from './modules/skills.js';
|
|
32
32
|
import { initMcp } from './modules/mcp-ui.js';
|
|
33
33
|
import { initScheduler, resetScheduler, handleLoopRegistryUpdated, handleScheduleRunStarted, handleScheduleRunFinished, handleLoopScheduled, openSchedulerToTab, isSchedulerOpen, closeScheduler, enterCraftingMode, exitCraftingMode, handleLoopRegistryFiles, getUpcomingSchedules } from './modules/scheduler.js';
|
|
@@ -41,7 +41,8 @@ import { initProjectSwitcher } from './modules/project-switcher.js';
|
|
|
41
41
|
import { initAdmin, checkAdminAccess } from './modules/admin.js';
|
|
42
42
|
import { initSessionSearch, toggleSearch, closeSearch, isSearchOpen, handleFindInSessionResults, onHistoryPrepended as onSessionSearchHistoryPrepended } from './modules/session-search.js';
|
|
43
43
|
import { initTooltips, registerTooltip } from './modules/tooltip.js';
|
|
44
|
-
import { initCommandPalette, handlePaletteSessionSwitch, setPaletteVersion } from './modules/command-palette.js';
|
|
44
|
+
import { initCommandPalette, handlePaletteSessionSwitch, setPaletteVersion, isCommandPaletteOpen, closeCommandPalette } from './modules/command-palette.js';
|
|
45
|
+
import { consumeOverlayPopstate, hasOverlayState } from './modules/overlay-history.js';
|
|
45
46
|
import { initAgentPicker } from './modules/agent-picker.js';
|
|
46
47
|
import { initLongPress } from './modules/longpress.js';
|
|
47
48
|
import { initConnection, connect as _connConnect, setStatus as _connSetStatus, scheduleReconnect as _connScheduleReconnect, cancelReconnect as _connCancelReconnect } from './modules/app-connection.js';
|
|
@@ -614,6 +615,19 @@ import { initMention, handleMentionStart, handleMentionStream, handleMentionDone
|
|
|
614
615
|
function switchProject(slug) { _projSwitchProject(slug); }
|
|
615
616
|
|
|
616
617
|
window.addEventListener("popstate", function () {
|
|
618
|
+
// Mobile swipe-back / browser back: if an overlay pushed a sentinel history
|
|
619
|
+
// entry, close that overlay and consume the event — do not navigate.
|
|
620
|
+
if (hasOverlayState()) {
|
|
621
|
+
consumeOverlayPopstate();
|
|
622
|
+
// Close whichever overlay is open (priority order: most-modal first).
|
|
623
|
+
if (isCommandPaletteOpen()) { closeCommandPalette(); return; }
|
|
624
|
+
if (isSettingsOpen()) { closeSettings(); return; }
|
|
625
|
+
if (isProjectSettingsOpen()) { closeProjectSettings(); return; }
|
|
626
|
+
if (isSearchOpen()) { closeSearch(); return; }
|
|
627
|
+
if (isArchiveOpen()) { closeArchive(); return; }
|
|
628
|
+
if (isSchedulerOpen()) { closeScheduler(); return; }
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
617
631
|
var m = location.pathname.match(/^\/p\/([a-z0-9_-]+)/);
|
|
618
632
|
var newSlug = m ? m[1] : null;
|
|
619
633
|
if (newSlug && newSlug !== store.get('currentSlug')) {
|
package/lib/public/css/input.css
CHANGED
|
@@ -859,11 +859,16 @@ body.mate-dm-active #input-wrapper,
|
|
|
859
859
|
font-weight: 600;
|
|
860
860
|
font-size: 14px;
|
|
861
861
|
font-family: "Roboto Mono", monospace;
|
|
862
|
+
flex-shrink: 0;
|
|
862
863
|
}
|
|
863
864
|
|
|
864
865
|
.slash-item .slash-desc {
|
|
865
866
|
color: var(--text-muted);
|
|
866
867
|
font-size: 13px;
|
|
868
|
+
overflow: hidden;
|
|
869
|
+
white-space: nowrap;
|
|
870
|
+
text-overflow: ellipsis;
|
|
871
|
+
min-width: 0;
|
|
867
872
|
}
|
|
868
873
|
|
|
869
874
|
/* ==========================================================================
|
|
@@ -90,9 +90,15 @@ export function initHeader() {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
var s = store.snap();
|
|
93
|
+
var vendor = s.currentVendor || "claude";
|
|
93
94
|
if (s.cliSessionId) addRow("Session ID", s.cliSessionId);
|
|
94
95
|
if (s.activeSessionId) addRow("Local ID", s.activeSessionId);
|
|
95
|
-
if (s.cliSessionId)
|
|
96
|
+
if (s.cliSessionId) {
|
|
97
|
+
var resumeCmd = vendor === "codex"
|
|
98
|
+
? "codex resume " + s.cliSessionId
|
|
99
|
+
: "claude --resume " + s.cliSessionId;
|
|
100
|
+
addRow("Resume", resumeCmd);
|
|
101
|
+
}
|
|
96
102
|
|
|
97
103
|
document.body.appendChild(pop);
|
|
98
104
|
sessionInfoPopover = pop;
|
|
@@ -277,14 +277,19 @@ export function processMessage(msg) {
|
|
|
277
277
|
connectOverlay.classList.remove("hidden");
|
|
278
278
|
break;
|
|
279
279
|
|
|
280
|
-
case "slash_commands":
|
|
280
|
+
case "slash_commands": {
|
|
281
|
+
// Backward compat: server sends {name,desc,type}[] since lr-1c7f;
|
|
282
|
+
// older server versions may still send string[].
|
|
281
283
|
var reserved = new Set(builtinCommands.map(function (c) { return c.name; }));
|
|
282
|
-
|
|
283
|
-
return
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
var enriched = (msg.commands || []).map(function (cmd) {
|
|
285
|
+
if (typeof cmd === "string") return { name: cmd, desc: "", type: "skill" };
|
|
286
|
+
return cmd;
|
|
287
|
+
});
|
|
288
|
+
store.set({ slashCommands: enriched.filter(function (cmd) {
|
|
289
|
+
return !reserved.has(cmd.name);
|
|
286
290
|
}) });
|
|
287
291
|
break;
|
|
292
|
+
}
|
|
288
293
|
|
|
289
294
|
case "model_info": {
|
|
290
295
|
// Drop stale model_info from a vendor that doesn't match the active
|
|
@@ -2,6 +2,7 @@ import { userAvatarUrl } from './avatar.js';
|
|
|
2
2
|
import { escapeHtml } from './utils.js';
|
|
3
3
|
import { refreshIcons } from './icons.js';
|
|
4
4
|
import { openSearch as openSessionSearch } from './session-search.js';
|
|
5
|
+
import { pushOverlayState, popOverlayState } from './overlay-history.js';
|
|
5
6
|
|
|
6
7
|
function formatRelativeDate(ts) {
|
|
7
8
|
if (!ts) return "";
|
|
@@ -75,6 +76,7 @@ export function isCommandPaletteOpen() {
|
|
|
75
76
|
|
|
76
77
|
export function openCommandPalette() {
|
|
77
78
|
if (!paletteEl) return;
|
|
79
|
+
pushOverlayState();
|
|
78
80
|
paletteEl.classList.remove("hidden");
|
|
79
81
|
var searchbar = document.getElementById("cmd-palette-btn");
|
|
80
82
|
if (searchbar) searchbar.style.visibility = "hidden";
|
|
@@ -90,6 +92,7 @@ export function openCommandPalette() {
|
|
|
90
92
|
|
|
91
93
|
export function closeCommandPalette() {
|
|
92
94
|
if (!paletteEl) return;
|
|
95
|
+
popOverlayState();
|
|
93
96
|
paletteEl.classList.add("hidden");
|
|
94
97
|
var searchbar = document.getElementById("cmd-palette-btn");
|
|
95
98
|
if (searchbar) searchbar.style.visibility = "";
|
|
@@ -66,11 +66,27 @@ export function setScheduleBtnDisabled(disabled) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export var builtinCommands = [
|
|
69
|
-
|
|
69
|
+
// Core CLI built-in commands (handled by the Claude CLI itself, not user skills)
|
|
70
|
+
{ name: "bug", desc: "Submit a bug report" },
|
|
71
|
+
{ name: "clear", desc: "Clear conversation history and start fresh" },
|
|
72
|
+
{ name: "compact", desc: "Compact conversation with optional summary focus" },
|
|
70
73
|
{ name: "context", desc: "Context window usage" },
|
|
74
|
+
{ name: "doctor", desc: "Check Claude Code installation health" },
|
|
75
|
+
{ name: "help", desc: "Get help and list available commands" },
|
|
76
|
+
{ name: "init", desc: "Initialize a project with a CLAUDE.md guide file" },
|
|
77
|
+
{ name: "login", desc: "Switch Anthropic accounts" },
|
|
78
|
+
{ name: "logout", desc: "Log out from Anthropic account" },
|
|
79
|
+
{ name: "memory", desc: "Edit Claude's memory files" },
|
|
80
|
+
{ name: "review", desc: "Review a pull request" },
|
|
71
81
|
{ name: "rewind", desc: "Toggle rewind mode" },
|
|
72
|
-
{ name: "usage", desc: "Toggle usage panel" },
|
|
73
82
|
{ name: "status", desc: "Process status and resource usage" },
|
|
83
|
+
{ name: "usage", desc: "Show usage statistics and costs" },
|
|
84
|
+
{ name: "vim", desc: "Enter vim mode for input" },
|
|
85
|
+
// Note: skills/workflows shipped with the CLI (code-review, workflow, loop, etc.)
|
|
86
|
+
// are intentionally NOT listed here — they are discovered dynamically via
|
|
87
|
+
// sdk-skill-discovery and sdk-workflow-discovery and will appear with real
|
|
88
|
+
// descriptions through the slash_commands WS message (lr-7d8d, lr-7bd3, lr-1c7f).
|
|
89
|
+
// Adding them here would filter them OUT of the dynamic discovery path.
|
|
74
90
|
];
|
|
75
91
|
|
|
76
92
|
// --- Send ---
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// overlay-history.js — mobile swipe-back / browser-back overlay dismissal
|
|
2
|
+
//
|
|
3
|
+
// Problem: on mobile PWAs, a back swipe fires a browser `popstate` event.
|
|
4
|
+
// If no app-level history entry exists for the open overlay, the browser
|
|
5
|
+
// navigates away (exits the PWA or goes to the previous real page).
|
|
6
|
+
//
|
|
7
|
+
// Pattern:
|
|
8
|
+
// - Each overlay calls pushOverlayState() on open.
|
|
9
|
+
// - Each overlay's close function calls popOverlayState().
|
|
10
|
+
// - The central popstate handler in app.js:
|
|
11
|
+
// 1. Calls consumeOverlayPopstate() — returns true if an overlay entry
|
|
12
|
+
// was active (and suppresses the redundant history.back() in the
|
|
13
|
+
// subsequent popOverlayState() call).
|
|
14
|
+
// 2. If true, calls the appropriate close function and returns.
|
|
15
|
+
// 3. Otherwise falls through to normal project-switch logic.
|
|
16
|
+
//
|
|
17
|
+
// The key invariant: history.back() must be called exactly once per sentinel.
|
|
18
|
+
// When the user closes via UI (X / Escape), popOverlayState() calls
|
|
19
|
+
// history.back() to remove the sentinel. When the browser already did the
|
|
20
|
+
// pop (back swipe), consumeOverlayPopstate() sets a suppress flag so the
|
|
21
|
+
// close function's popOverlayState() call is a no-op.
|
|
22
|
+
|
|
23
|
+
var _depth = 0;
|
|
24
|
+
var _suppressBack = false;
|
|
25
|
+
|
|
26
|
+
// Call when an overlay opens. Pushes a sentinel history entry.
|
|
27
|
+
export function pushOverlayState() {
|
|
28
|
+
_depth++;
|
|
29
|
+
history.pushState({ overlay: true, depth: _depth }, "");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Call when an overlay closes. If the close is user-initiated (not from a
|
|
33
|
+
// popstate callback), calls history.back() to remove the sentinel we pushed.
|
|
34
|
+
// If _suppressBack is set (we're inside the popstate handler), skip the
|
|
35
|
+
// history.back() — it already happened.
|
|
36
|
+
export function popOverlayState() {
|
|
37
|
+
if (_depth > 0) {
|
|
38
|
+
_depth--;
|
|
39
|
+
if (_suppressBack) {
|
|
40
|
+
_suppressBack = false;
|
|
41
|
+
} else {
|
|
42
|
+
history.back();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Returns true if at least one overlay history entry is active.
|
|
48
|
+
export function hasOverlayState() {
|
|
49
|
+
return _depth > 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Called by the popstate handler before invoking the overlay close function.
|
|
53
|
+
// Marks that history.back() should be suppressed in the upcoming
|
|
54
|
+
// popOverlayState() call (since the browser already did the pop).
|
|
55
|
+
// Returns true if an overlay entry was consumed, false if none was active.
|
|
56
|
+
export function consumeOverlayPopstate() {
|
|
57
|
+
if (_depth > 0) {
|
|
58
|
+
_suppressBack = true;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
@@ -3,6 +3,7 @@ import { refreshIcons } from './icons.js';
|
|
|
3
3
|
import { buildEmojiPicker } from './emoji-picker.js';
|
|
4
4
|
import { showToast } from './utils.js';
|
|
5
5
|
import { parseEmojis } from './markdown.js';
|
|
6
|
+
import { pushOverlayState, popOverlayState } from './overlay-history.js';
|
|
6
7
|
import { closeFileViewer } from './filebrowser.js';
|
|
7
8
|
import { renderModelList, renderModeList, renderEffortBar, renderThinkingBar, renderBetaCard } from './settings-defaults.js';
|
|
8
9
|
|
|
@@ -212,12 +213,14 @@ export function openProjectSettings(slug, project) {
|
|
|
212
213
|
closeFileViewer();
|
|
213
214
|
|
|
214
215
|
// Show panel
|
|
216
|
+
pushOverlayState();
|
|
215
217
|
panelEl.classList.remove("hidden");
|
|
216
218
|
refreshIcons();
|
|
217
219
|
}
|
|
218
220
|
|
|
219
221
|
export function closeProjectSettings() {
|
|
220
222
|
if (!panelEl) return;
|
|
223
|
+
popOverlayState();
|
|
221
224
|
panelEl.classList.add("hidden");
|
|
222
225
|
closePsEmojiPicker();
|
|
223
226
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { iconHtml } from './icons.js';
|
|
9
9
|
import { showToast } from './utils.js';
|
|
10
|
+
import { pushOverlayState, popOverlayState } from './overlay-history.js';
|
|
10
11
|
import { renderModelList, renderModeList, renderEffortBar, renderThinkingBar } from './settings-defaults.js';
|
|
11
12
|
import { store } from './store.js';
|
|
12
13
|
import { initSchedulerConfig, setupCreateModal, openCreateModal, openCreateModalWithRecord, closeCreateModal, removePreview, getPreviewEl, showPreviewOnCell, showPreviewOnSlot, showPreviewForCreate, applyDraggedTask, parseCronSimple } from './scheduler-config.js';
|
|
@@ -353,6 +354,7 @@ function updateCraftingHeader() {
|
|
|
353
354
|
function openScheduler() {
|
|
354
355
|
if (panelOpen) return;
|
|
355
356
|
panelOpen = true;
|
|
357
|
+
pushOverlayState();
|
|
356
358
|
ensurePanel();
|
|
357
359
|
if (!panel) return;
|
|
358
360
|
|
|
@@ -393,6 +395,7 @@ function openScheduler() {
|
|
|
393
395
|
export function closeScheduler() {
|
|
394
396
|
if (!panelOpen) return;
|
|
395
397
|
panelOpen = false;
|
|
398
|
+
popOverlayState();
|
|
396
399
|
stopNowLineTimer();
|
|
397
400
|
if (currentMode === "crafting") {
|
|
398
401
|
unparentChat();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// server-settings.js — Full-screen server settings overlay
|
|
2
2
|
import { refreshIcons } from './icons.js';
|
|
3
3
|
import { showToast, copyToClipboard } from './utils.js';
|
|
4
|
+
import { pushOverlayState, popOverlayState } from './overlay-history.js';
|
|
4
5
|
import { parseEnvString, looksLikeEnv } from './project-settings.js';
|
|
5
6
|
import { checkAdminAccess, loadAdminSection } from './admin.js';
|
|
6
7
|
import { closeFileViewer } from './filebrowser.js';
|
|
@@ -475,6 +476,7 @@ function switchSection(sectionName) {
|
|
|
475
476
|
|
|
476
477
|
function openSettings() {
|
|
477
478
|
closeFileViewer();
|
|
479
|
+
pushOverlayState();
|
|
478
480
|
settingsEl.classList.remove("hidden");
|
|
479
481
|
settingsBtn.classList.add("active");
|
|
480
482
|
refreshIcons(settingsEl);
|
|
@@ -513,7 +515,8 @@ function resetShutdownForm() {
|
|
|
513
515
|
if (errorEl) errorEl.classList.add("hidden");
|
|
514
516
|
}
|
|
515
517
|
|
|
516
|
-
function closeSettings() {
|
|
518
|
+
export function closeSettings() {
|
|
519
|
+
popOverlayState();
|
|
517
520
|
settingsEl.classList.add("hidden");
|
|
518
521
|
settingsBtn.classList.remove("active");
|
|
519
522
|
if (statsTimer) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// --- In-session search (Cmd+F / Ctrl+F) ---
|
|
2
2
|
import { escapeHtml } from './utils.js';
|
|
3
3
|
import { iconHtml, refreshIcons } from './icons.js';
|
|
4
|
+
import { pushOverlayState, popOverlayState } from './overlay-history.js';
|
|
4
5
|
|
|
5
6
|
var ctx = null;
|
|
6
7
|
var searchBarEl = null;
|
|
@@ -95,6 +96,7 @@ function isSearchOpen() {
|
|
|
95
96
|
|
|
96
97
|
function openSearch(prefill) {
|
|
97
98
|
if (!searchBarEl) return;
|
|
99
|
+
pushOverlayState();
|
|
98
100
|
searchBarEl.classList.remove("hidden");
|
|
99
101
|
var btn = document.getElementById("find-in-session-btn");
|
|
100
102
|
if (btn) btn.classList.add("active");
|
|
@@ -111,6 +113,7 @@ function openSearch(prefill) {
|
|
|
111
113
|
|
|
112
114
|
function closeSearch() {
|
|
113
115
|
if (!searchBarEl) return;
|
|
116
|
+
popOverlayState();
|
|
114
117
|
searchBarEl.classList.add("hidden");
|
|
115
118
|
var btn = document.getElementById("find-in-session-btn");
|
|
116
119
|
if (btn) btn.classList.remove("active");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { refreshIcons, iconHtml } from './icons.js';
|
|
2
|
+
import { pushOverlayState, popOverlayState } from './overlay-history.js';
|
|
2
3
|
|
|
3
4
|
var ctx;
|
|
4
5
|
var notes = new Map(); // id -> { data, el }
|
|
@@ -1128,6 +1129,7 @@ function renderArchiveCards() {
|
|
|
1128
1129
|
export function openArchive() {
|
|
1129
1130
|
if (archiveOpen) return;
|
|
1130
1131
|
archiveOpen = true;
|
|
1132
|
+
pushOverlayState();
|
|
1131
1133
|
|
|
1132
1134
|
var messagesEl = document.getElementById("messages");
|
|
1133
1135
|
var appEl = document.getElementById("app");
|
|
@@ -1192,6 +1194,7 @@ export function openArchive() {
|
|
|
1192
1194
|
export function closeArchive() {
|
|
1193
1195
|
if (!archiveOpen) return;
|
|
1194
1196
|
archiveOpen = false;
|
|
1197
|
+
popOverlayState();
|
|
1195
1198
|
|
|
1196
1199
|
var archive = document.getElementById("notes-archive");
|
|
1197
1200
|
var messagesEl = document.getElementById("messages");
|
package/lib/sdk-bridge.js
CHANGED
|
@@ -5,10 +5,12 @@ var execSync = require("child_process").execSync;
|
|
|
5
5
|
var execFileSync = require("child_process").execFileSync;
|
|
6
6
|
var usersModule = require("./users");
|
|
7
7
|
var { getCodexConfig } = require("./codex-defaults");
|
|
8
|
-
var { splitShellSegments, attachSkillDiscovery } = require("./sdk-skill-discovery");
|
|
8
|
+
var { splitShellSegments, attachSkillDiscovery, discoverSkillsWithMeta, mergeSkillsWithMeta } = require("./sdk-skill-discovery");
|
|
9
9
|
var { createMessageQueue } = require("./sdk-message-queue");
|
|
10
10
|
var { attachMessageProcessor } = require("./sdk-message-processor");
|
|
11
11
|
var { readAgentToolsFromFile } = require("./agents");
|
|
12
|
+
var { discoverWorkflows } = require("./sdk-workflow-discovery");
|
|
13
|
+
var { buildEnrichedSlashCommands } = require("./sdk-slash-enrichment");
|
|
12
14
|
|
|
13
15
|
// --- lr-29f9: Global concurrent-session ceiling ---
|
|
14
16
|
// Counts queries that are actively running (startQuery entered, processQueryStream
|
|
@@ -18,9 +20,30 @@ var { readAgentToolsFromFile } = require("./agents");
|
|
|
18
20
|
var _activeLiveCount = 0;
|
|
19
21
|
var MAX_CONCURRENT_SESSIONS = (function () {
|
|
20
22
|
var env = parseInt(process.env.CLAGENTIC_MAX_CONCURRENT_SESSIONS, 10);
|
|
21
|
-
return (env > 0) ? env :
|
|
23
|
+
return (env > 0) ? env : 50;
|
|
22
24
|
})();
|
|
23
25
|
|
|
26
|
+
// --- lr-2d91: MemAvailable gate ---
|
|
27
|
+
// Default minimum available memory threshold in MB. Referenced by sdk-bridge
|
|
28
|
+
// and daemon.js — changing this constant is the single place to adjust the default.
|
|
29
|
+
var DEFAULT_MEM_AVAILABLE_MIN_MB = 1024;
|
|
30
|
+
|
|
31
|
+
// Read Linux MemAvailable from /proc/meminfo synchronously.
|
|
32
|
+
// Returns available memory in MB, or null on non-Linux or read failure.
|
|
33
|
+
// Sub-millisecond on Linux; the synchronous read is correct here — this is a
|
|
34
|
+
// pre-launch check, not a hot path, and the async equivalent buys nothing.
|
|
35
|
+
function readMemAvailableMB() {
|
|
36
|
+
if (process.platform !== "linux") return null;
|
|
37
|
+
try {
|
|
38
|
+
var raw = fs.readFileSync("/proc/meminfo", "utf8");
|
|
39
|
+
var match = raw.match(/^MemAvailable:\s+(\d+)\s+kB/m);
|
|
40
|
+
if (!match) return null;
|
|
41
|
+
return Math.floor(parseInt(match[1], 10) / 1024);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
24
47
|
// Extract serializable tool descriptors from MCP server instances.
|
|
25
48
|
// Used for IPC to worker processes (McpSdkServerConfigWithInstance is not serializable).
|
|
26
49
|
function extractMcpDescriptors(mcpServers) {
|
|
@@ -349,6 +372,8 @@ function createSDKBridge(opts) {
|
|
|
349
372
|
opts: opts,
|
|
350
373
|
discoverSkillDirs: discoverSkillDirs,
|
|
351
374
|
mergeSkills: mergeSkills,
|
|
375
|
+
discoverSkillsWithMeta: function(cwdArg) { return discoverSkillsWithMeta(cwdArg); },
|
|
376
|
+
mergeSkillsWithMeta: mergeSkillsWithMeta,
|
|
352
377
|
});
|
|
353
378
|
var processSDKMessage = msgProcessor.processSDKMessage;
|
|
354
379
|
var sendAndRecord = msgProcessor.sendAndRecord;
|
|
@@ -1202,12 +1227,37 @@ function createSDKBridge(opts) {
|
|
|
1202
1227
|
onProcessingChanged();
|
|
1203
1228
|
sendAndRecord(session, {
|
|
1204
1229
|
type: "error",
|
|
1205
|
-
text: "Too many active sessions (" + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + "). Wait for
|
|
1230
|
+
text: "Too many active sessions (" + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + "). Wait for an active session to finish or close unused sessions.",
|
|
1206
1231
|
});
|
|
1207
1232
|
sendAndRecord(session, { type: "done", code: 1 });
|
|
1208
1233
|
sm.broadcastSessionList();
|
|
1209
1234
|
return;
|
|
1210
1235
|
}
|
|
1236
|
+
|
|
1237
|
+
// lr-2d91: MemAvailable gate — check before claiming a slot so a rejected
|
|
1238
|
+
// query never increments the live counter.
|
|
1239
|
+
if (isNewQuery) {
|
|
1240
|
+
var memAvailMB = readMemAvailableMB();
|
|
1241
|
+
var getConfig = opts.getConfig;
|
|
1242
|
+
var memThresholdMB = DEFAULT_MEM_AVAILABLE_MIN_MB;
|
|
1243
|
+
if (typeof getConfig === "function") {
|
|
1244
|
+
var dc = getConfig();
|
|
1245
|
+
if (dc && typeof dc.memAvailableMinMB === "number" && dc.memAvailableMinMB > 0) {
|
|
1246
|
+
memThresholdMB = dc.memAvailableMinMB;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
if (memAvailMB !== null && memAvailMB < memThresholdMB) {
|
|
1250
|
+
console.warn("[sdk-bridge] MemAvailable gate: " + memAvailMB + " MB available, " + memThresholdMB + " MB required — rejecting new query for session " + session.localId);
|
|
1251
|
+
session.isProcessing = false;
|
|
1252
|
+
onProcessingChanged();
|
|
1253
|
+
var memMsg = "Not enough memory to start a new query (" + memAvailMB + " MB available, " + memThresholdMB + " MB required). Wait for an active session to finish or close unused sessions.";
|
|
1254
|
+
sendAndRecord(session, { type: "error", text: memMsg });
|
|
1255
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1256
|
+
send({ type: "toast", level: "warn", message: "Query blocked — not enough memory (" + memAvailMB + " MB available).", duration: 5000 });
|
|
1257
|
+
sm.broadcastSessionList();
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1211
1261
|
// Claim the slot now so concurrent callers see the updated count immediately.
|
|
1212
1262
|
// Set _isCountedLive on the session at the same time so any early-return path
|
|
1213
1263
|
// below (sync throw, createQuery failure) can release it via releaseSlot().
|
|
@@ -1618,16 +1668,15 @@ function createSDKBridge(opts) {
|
|
|
1618
1668
|
|
|
1619
1669
|
var fsSkills = discoverSkillDirs();
|
|
1620
1670
|
sm.skillNames = mergeSkills(result.skills, fsSkills);
|
|
1671
|
+
sm.workflowMeta = discoverWorkflows(cwd);
|
|
1672
|
+
// Enriched skill metadata (lr-7d8d)
|
|
1673
|
+
var fsSkillsMeta = discoverSkillsWithMeta(cwd);
|
|
1674
|
+
sm.skillMeta = mergeSkillsWithMeta(result.skills, fsSkillsMeta);
|
|
1621
1675
|
if (result.slashCommands) {
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
if (!seen.has(all[k])) {
|
|
1627
|
-
seen.add(all[k]);
|
|
1628
|
-
combined.push(all[k]);
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1676
|
+
// Build enriched {name,desc,type}[] using the shared helper (lr-cf84).
|
|
1677
|
+
// Applies skill/workflow priority chain at warmup time, matching the
|
|
1678
|
+
// live-query init path so the UI receives enriched objects on connect.
|
|
1679
|
+
var combined = buildEnrichedSlashCommands(result.slashCommands, cwd);
|
|
1631
1680
|
sm.slashCommands = combined;
|
|
1632
1681
|
sm.setSlashCommandsForVendor(defaultVendor, combined);
|
|
1633
1682
|
send({ type: "slash_commands", commands: combined, vendor: defaultVendor });
|
|
@@ -1912,6 +1961,15 @@ function createSDKBridge(opts) {
|
|
|
1912
1961
|
};
|
|
1913
1962
|
}
|
|
1914
1963
|
|
|
1964
|
+
// lr-2d91: Expose live concurrency stats for process_stats WS response.
|
|
1965
|
+
// Called by project-sessions.js when building the process_stats payload.
|
|
1966
|
+
function getMemoryStats() {
|
|
1967
|
+
return {
|
|
1968
|
+
activeLiveCount: _activeLiveCount,
|
|
1969
|
+
maxConcurrentSessions: MAX_CONCURRENT_SESSIONS,
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1915
1973
|
return {
|
|
1916
1974
|
createMessageQueue: createMessageQueue,
|
|
1917
1975
|
processSDKMessage: processSDKMessage,
|
|
@@ -1937,8 +1995,9 @@ function createSDKBridge(opts) {
|
|
|
1937
1995
|
createMentionSession: createMentionSession,
|
|
1938
1996
|
startIdleReaper: startIdleReaper,
|
|
1939
1997
|
stopIdleReaper: stopIdleReaper,
|
|
1998
|
+
getMemoryStats: getMemoryStats,
|
|
1940
1999
|
};
|
|
1941
2000
|
}
|
|
1942
2001
|
|
|
1943
|
-
module.exports = { createSDKBridge, createMessageQueue };
|
|
2002
|
+
module.exports = { createSDKBridge, createMessageQueue, readMemAvailableMB, DEFAULT_MEM_AVAILABLE_MIN_MB };
|
|
1944
2003
|
|