@clagentic/console 1.7.0-beta.1 → 1.7.1-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.
- package/lib/build-sha.json +4 -0
- package/lib/daemon.js +15 -6
- package/lib/memory-shed.js +81 -2
- package/lib/project-connection.js +13 -0
- package/lib/project-loop.js +4 -0
- package/lib/project-sessions.js +9 -3
- package/lib/project.js +3 -2
- package/lib/public/css/diagnostics.css +14 -1
- package/lib/public/css/home-hub.css +10 -0
- package/lib/public/modules/app-home-hub.js +24 -0
- package/lib/public/modules/app-messages.js +29 -8
- package/lib/public/modules/app-rate-limit.js +128 -27
- package/lib/public/modules/input.js +47 -12
- package/lib/public/modules/rate-limit-state.js +133 -0
- package/lib/public/modules/sidebar-mobile.js +8 -3
- package/lib/sdk-bridge.js +22 -0
- package/lib/sdk-message-processor.js +27 -1
- package/lib/server-palette.js +17 -1
- package/lib/session-search.js +20 -5
- package/lib/sessions.js +84 -3
- package/package.json +4 -2
- package/scripts/install-local-test.js +97 -0
- package/scripts/verify-installed-build.js +80 -0
- package/scripts/write-build-sha.js +53 -0
|
@@ -5,6 +5,7 @@ import { checkForMention, showMentionMenu, hideMentionMenu, isMentionMenuVisible
|
|
|
5
5
|
import { initAtAgents, showAgentMenu, hideAgentMenu, isAgentMenuActive, agentMenuKeydown, requestProjectAgents } from './at-agents.js';
|
|
6
6
|
import { store } from './store.js';
|
|
7
7
|
import { sendWsQuiet } from './ws-ref.js';
|
|
8
|
+
import { getScheduleDelayMs, setScheduleDelayMs as setSessionScheduleDelayMs } from './rate-limit-state.js';
|
|
8
9
|
|
|
9
10
|
var ctx;
|
|
10
11
|
|
|
@@ -17,10 +18,18 @@ var slashActiveIdx = -1;
|
|
|
17
18
|
var slashFiltered = [];
|
|
18
19
|
var isComposing = false;
|
|
19
20
|
var isRemoteInput = false;
|
|
20
|
-
|
|
21
|
+
// lr-0827ba: schedule-delay arming is per-session state, owned by
|
|
22
|
+
// rate-limit-state.js and keyed by the currently active session (not a bare
|
|
23
|
+
// module-scoped variable — that was the root cause of arming in one project
|
|
24
|
+
// silently overwriting another project's armed state, since the SPA never
|
|
25
|
+
// reloads the page on project switch).
|
|
21
26
|
var _setScheduleDelayFn = null; // set by initInput
|
|
22
27
|
var slashMenuBound = false;
|
|
23
28
|
|
|
29
|
+
function currentSessionId() {
|
|
30
|
+
return store.get('activeSessionId');
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
export function hasSendableContent() {
|
|
25
34
|
return !!(
|
|
26
35
|
(ctx && ctx.inputEl && ctx.inputEl.value.trim()) ||
|
|
@@ -30,18 +39,39 @@ export function hasSendableContent() {
|
|
|
30
39
|
);
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
// Returns the armed schedule delay for the currently active session (0 = no
|
|
43
|
+
// schedule armed). Pass an explicit sessionId to check a session other than
|
|
44
|
+
// the active one (e.g. redrawing on switch-in).
|
|
45
|
+
export function getScheduleDelay(sessionId) {
|
|
46
|
+
return getScheduleDelayMs(sessionId === undefined ? currentSessionId() : sessionId);
|
|
35
47
|
}
|
|
36
48
|
|
|
49
|
+
// Arms (or disarms, with ms=0) the schedule delay for a specific session.
|
|
50
|
+
// Only touches the visible schedule button when sessionId is the currently
|
|
51
|
+
// focused session — arming a background session (e.g. a rate-limit hit in a
|
|
52
|
+
// project the user isn't looking at) must not repaint the UI for whatever
|
|
53
|
+
// session IS focused (lr-0827ba).
|
|
54
|
+
export function setScheduleDelayForSession(sessionId, ms) {
|
|
55
|
+
setSessionScheduleDelayMs(sessionId, ms);
|
|
56
|
+
if (sessionId === currentSessionId() && _setScheduleDelayFn) _setScheduleDelayFn(ms);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Arms (or disarms, with ms=0) the schedule delay for the currently active
|
|
60
|
+
// session and updates the visible button state.
|
|
37
61
|
export function setScheduleDelayMs(ms) {
|
|
38
|
-
|
|
39
|
-
// Trigger visual update if initInput has been called
|
|
40
|
-
if (_setScheduleDelayFn) _setScheduleDelayFn(ms);
|
|
62
|
+
setScheduleDelayForSession(currentSessionId(), ms);
|
|
41
63
|
}
|
|
42
64
|
|
|
43
|
-
|
|
44
|
-
|
|
65
|
+
// Redraws the schedule button to reflect a session's already-armed delay
|
|
66
|
+
// without re-triggering any arm/disarm side effects — used when switching
|
|
67
|
+
// back into a session that has a background-armed schedule (lr-0827ba).
|
|
68
|
+
export function restoreScheduleDelayUi() {
|
|
69
|
+
if (_setScheduleDelayFn) _setScheduleDelayFn(getScheduleDelay());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function clearScheduleDelayForSession(sessionId) {
|
|
73
|
+
setSessionScheduleDelayMs(sessionId, 0);
|
|
74
|
+
if (sessionId !== currentSessionId()) return;
|
|
45
75
|
var btn = document.getElementById("schedule-btn");
|
|
46
76
|
if (btn) {
|
|
47
77
|
btn.classList.remove("schedule-active", "schedule-expanded");
|
|
@@ -53,6 +83,10 @@ export function clearScheduleDelay() {
|
|
|
53
83
|
}
|
|
54
84
|
}
|
|
55
85
|
|
|
86
|
+
export function clearScheduleDelay() {
|
|
87
|
+
clearScheduleDelayForSession(currentSessionId());
|
|
88
|
+
}
|
|
89
|
+
|
|
56
90
|
export function setScheduleBtnDisabled(disabled) {
|
|
57
91
|
var btn = document.getElementById("schedule-btn");
|
|
58
92
|
if (!btn) return;
|
|
@@ -224,8 +258,9 @@ export function sendMessage() {
|
|
|
224
258
|
}
|
|
225
259
|
|
|
226
260
|
// Scheduled message: queue message with timer delay
|
|
227
|
-
|
|
228
|
-
|
|
261
|
+
var _armedDelayMs = getScheduleDelay();
|
|
262
|
+
if (_armedDelayMs > 0) {
|
|
263
|
+
var resetsAt = Date.now() + _armedDelayMs;
|
|
229
264
|
ctx.ws.send(JSON.stringify({ type: "schedule_message", text: text || "", resetsAt: resetsAt }));
|
|
230
265
|
clearScheduleDelay();
|
|
231
266
|
ctx.inputEl.value = "";
|
|
@@ -870,7 +905,7 @@ export function initInput(_ctx) {
|
|
|
870
905
|
}
|
|
871
906
|
|
|
872
907
|
function setScheduleDelay(ms) {
|
|
873
|
-
|
|
908
|
+
setSessionScheduleDelayMs(currentSessionId(), ms);
|
|
874
909
|
if (!scheduleBtn) return;
|
|
875
910
|
collapseScheduleBtn();
|
|
876
911
|
if (ms > 0) {
|
|
@@ -938,7 +973,7 @@ export function initInput(_ctx) {
|
|
|
938
973
|
if (scheduleBtn) {
|
|
939
974
|
scheduleBtn.addEventListener("click", function (e) {
|
|
940
975
|
e.stopPropagation();
|
|
941
|
-
if (
|
|
976
|
+
if (getScheduleDelayMs(currentSessionId()) > 0) {
|
|
942
977
|
setScheduleDelay(0);
|
|
943
978
|
return;
|
|
944
979
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// rate-limit-state.js - Per-session rate-limit / schedule-message arming state.
|
|
2
|
+
//
|
|
3
|
+
// lr-0827ba: this state was previously a handful of bare module-scoped
|
|
4
|
+
// variables in input.js and app-rate-limit.js (scheduleDelayMs,
|
|
5
|
+
// rateLimitResetsAt, rateLimitResetTimer, rateLimitResetState, scheduled
|
|
6
|
+
// message bubble text/resetsAt). Because the SPA does not reload the page
|
|
7
|
+
// when the user switches projects, all sessions across all projects shared
|
|
8
|
+
// that single set of variables — arming a schedule in a second project
|
|
9
|
+
// silently clobbered the first project's armed state.
|
|
10
|
+
//
|
|
11
|
+
// This module replaces those bare variables with a small state map keyed by
|
|
12
|
+
// session localId (the same id the server uses as its session-map key, see
|
|
13
|
+
// lib/sessions.js and the `id` field on `session_switched`), mirroring the
|
|
14
|
+
// existing sessionDrafts precedent in app-messages.js/app.js. Each session's
|
|
15
|
+
// entry keeps running in the background (including its reset setTimeout)
|
|
16
|
+
// even while a different session is focused, mirroring server-side behavior
|
|
17
|
+
// (session.scheduledMessage in lib/project.js is already correctly
|
|
18
|
+
// per-session).
|
|
19
|
+
//
|
|
20
|
+
// DOM-free by design so it can be imported and unit-tested directly under
|
|
21
|
+
// plain Node (see test/rate-limit-state.test.js), following the same
|
|
22
|
+
// DOM-free-sibling-module convention as sticky-notes-fmt.js.
|
|
23
|
+
|
|
24
|
+
var _bySession = Object.create(null);
|
|
25
|
+
|
|
26
|
+
function emptyEntry() {
|
|
27
|
+
return {
|
|
28
|
+
// Auto-schedule arming (input.js sendMessage() consumes this).
|
|
29
|
+
scheduleDelayMs: 0,
|
|
30
|
+
// Rate-limit-driven auto-schedule bookkeeping (app-rate-limit.js).
|
|
31
|
+
rateLimitResetsAt: null,
|
|
32
|
+
rateLimitResetTimer: null,
|
|
33
|
+
rateLimitResetState: {},
|
|
34
|
+
// Scheduled-message bubble (queued user message awaiting send).
|
|
35
|
+
scheduledMsgText: null,
|
|
36
|
+
scheduledMsgResetsAt: null,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getEntry(sessionId) {
|
|
41
|
+
if (sessionId == null) return emptyEntry();
|
|
42
|
+
if (!_bySession[sessionId]) _bySession[sessionId] = emptyEntry();
|
|
43
|
+
return _bySession[sessionId];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// --- Schedule delay (auto-send arming) ---
|
|
47
|
+
|
|
48
|
+
export function getScheduleDelayMs(sessionId) {
|
|
49
|
+
return getEntry(sessionId).scheduleDelayMs;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function setScheduleDelayMs(sessionId, ms) {
|
|
53
|
+
if (sessionId == null) return;
|
|
54
|
+
getEntry(sessionId).scheduleDelayMs = ms;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// --- Rate-limit reset bookkeeping ---
|
|
58
|
+
|
|
59
|
+
export function getRateLimitResetsAt(sessionId) {
|
|
60
|
+
return getEntry(sessionId).rateLimitResetsAt;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function setRateLimitResetsAt(sessionId, resetsAt) {
|
|
64
|
+
if (sessionId == null) return;
|
|
65
|
+
getEntry(sessionId).rateLimitResetsAt = resetsAt;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getRateLimitResetTimer(sessionId) {
|
|
69
|
+
return getEntry(sessionId).rateLimitResetTimer;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function setRateLimitResetTimer(sessionId, timer) {
|
|
73
|
+
if (sessionId == null) return;
|
|
74
|
+
getEntry(sessionId).rateLimitResetTimer = timer;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getRateLimitResetState(sessionId) {
|
|
78
|
+
return getEntry(sessionId).rateLimitResetState;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// --- Scheduled-message bubble ---
|
|
82
|
+
|
|
83
|
+
export function getScheduledMsg(sessionId) {
|
|
84
|
+
var e = getEntry(sessionId);
|
|
85
|
+
if (e.scheduledMsgText == null) return null;
|
|
86
|
+
return { text: e.scheduledMsgText, resetsAt: e.scheduledMsgResetsAt };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function setScheduledMsg(sessionId, text, resetsAt) {
|
|
90
|
+
if (sessionId == null) return;
|
|
91
|
+
var e = getEntry(sessionId);
|
|
92
|
+
e.scheduledMsgText = text;
|
|
93
|
+
e.scheduledMsgResetsAt = resetsAt;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function clearScheduledMsg(sessionId) {
|
|
97
|
+
if (sessionId == null) return;
|
|
98
|
+
var e = getEntry(sessionId);
|
|
99
|
+
e.scheduledMsgText = null;
|
|
100
|
+
e.scheduledMsgResetsAt = null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// --- Whole-session lifecycle ---
|
|
104
|
+
|
|
105
|
+
// True if this session has any armed/queued state worth restoring on
|
|
106
|
+
// switch-in (used to decide whether a redraw is needed).
|
|
107
|
+
export function hasArmedState(sessionId) {
|
|
108
|
+
if (sessionId == null) return false;
|
|
109
|
+
var e = _bySession[sessionId];
|
|
110
|
+
if (!e) return false;
|
|
111
|
+
return e.scheduleDelayMs > 0 || e.scheduledMsgText != null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Clears a single session's state entirely, including canceling its
|
|
115
|
+
// background reset timer. Call when a session is actually destroyed/closed,
|
|
116
|
+
// NOT on a mere project/session switch (switching away must leave the timer
|
|
117
|
+
// running in the background so it fires even while unfocused).
|
|
118
|
+
export function clearSession(sessionId) {
|
|
119
|
+
if (sessionId == null) return;
|
|
120
|
+
var e = _bySession[sessionId];
|
|
121
|
+
if (e && e.rateLimitResetTimer) clearTimeout(e.rateLimitResetTimer);
|
|
122
|
+
delete _bySession[sessionId];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Test/diagnostic helper: wipes all tracked sessions. Not used in production
|
|
126
|
+
// code paths (there is no "reset everything" client action), only in tests
|
|
127
|
+
// that need isolation between cases.
|
|
128
|
+
export function _resetAllForTest() {
|
|
129
|
+
for (var k in _bySession) {
|
|
130
|
+
if (_bySession[k] && _bySession[k].rateLimitResetTimer) clearTimeout(_bySession[k].rateLimitResetTimer);
|
|
131
|
+
}
|
|
132
|
+
_bySession = Object.create(null);
|
|
133
|
+
}
|
|
@@ -40,7 +40,7 @@ import { getWs } from './ws-ref.js';
|
|
|
40
40
|
import { dismissOverlayPanels, closeSidebar } from './sidebar.js';
|
|
41
41
|
import { switchProject, getCachedProjects, openAddProjectModal } from './app-projects.js';
|
|
42
42
|
import { openDm } from './app-dm.js';
|
|
43
|
-
import { showHomeHub } from './app-home-hub.js';
|
|
43
|
+
import { showHomeHub, hideHomeHub, isHomeHubVisible } from './app-home-hub.js';
|
|
44
44
|
import { openTerminal } from './terminal.js';
|
|
45
45
|
import { loadRootDirectory } from './filebrowser.js';
|
|
46
46
|
import { renderSheetTeam as renderTeamView } from './team-panel.js';
|
|
@@ -1278,8 +1278,13 @@ export function initSidebarMobile() {
|
|
|
1278
1278
|
if (mobileHomeBtn) {
|
|
1279
1279
|
mobileHomeBtn.addEventListener("click", function () {
|
|
1280
1280
|
closeSidebar();
|
|
1281
|
-
|
|
1282
|
-
|
|
1281
|
+
if (isHomeHubVisible()) {
|
|
1282
|
+
hideHomeHub();
|
|
1283
|
+
setMobileTabActive(null);
|
|
1284
|
+
} else {
|
|
1285
|
+
setMobileTabActive("home");
|
|
1286
|
+
showHomeHub();
|
|
1287
|
+
}
|
|
1283
1288
|
});
|
|
1284
1289
|
}
|
|
1285
1290
|
|
package/lib/sdk-bridge.js
CHANGED
|
@@ -324,6 +324,28 @@ function createSDKBridge(opts) {
|
|
|
324
324
|
// have been idle for IDLE_TIMEOUT_MS, allowing processQueryStream's finally
|
|
325
325
|
// block to clean up the child process. Session state on disk is preserved —
|
|
326
326
|
// the next startQuery() call resumes with a fresh process.
|
|
327
|
+
//
|
|
328
|
+
// lr-f36626: that resume-cleanly assumption is true for an idle human but
|
|
329
|
+
// was FALSE for a session correctly WAITING on a live backgrounded Task
|
|
330
|
+
// (Agent-tool dispatch) — isProcessing is false in that state (the parent
|
|
331
|
+
// turn already completed a 'result'), so this loop previously saw no
|
|
332
|
+
// difference between "abandoned" and "waiting on a live child" and reaped
|
|
333
|
+
// both after IDLE_TIMEOUT_MS, orphaning the child's stream. Fixed at the
|
|
334
|
+
// source rather than here: session.lastActivityAt is now also bumped on
|
|
335
|
+
// genuine subagent stream activity (processSubagentMessage and the
|
|
336
|
+
// tool_progress/task_progress/task_updated/task_started branches in
|
|
337
|
+
// sdk-message-processor.js), so a progressing child keeps pushing this
|
|
338
|
+
// loop's idle clock forward for as long as it keeps producing output.
|
|
339
|
+
// Deliberately NOT "never reap if session.activeTaskToolIds is non-empty"
|
|
340
|
+
// — a dead/silent child (crashed, stuck, or simply never checks back in)
|
|
341
|
+
// must still become reapable once IDLE_TIMEOUT_MS genuinely elapses with
|
|
342
|
+
// no activity at all, or a leaked child registration would pin the
|
|
343
|
+
// session (and its process) alive forever. Because that case was never
|
|
344
|
+
// "live" at the moment of reap (no activity for the full timeout window),
|
|
345
|
+
// it emits no notification here — only the pressure path in
|
|
346
|
+
// lib/memory-shed.js, which can reclaim a still-progressing session as a
|
|
347
|
+
// deliberate last resort, notifies both UI surfaces (see its
|
|
348
|
+
// liveChildReclaims handling).
|
|
327
349
|
var IDLE_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes
|
|
328
350
|
var IDLE_CHECK_INTERVAL_MS = 60 * 1000; // check every 60 seconds
|
|
329
351
|
var _idleReaperTimer = null;
|
|
@@ -80,6 +80,19 @@ function attachMessageProcessor(ctx) {
|
|
|
80
80
|
var content = parsed.content;
|
|
81
81
|
if (!Array.isArray(content)) return;
|
|
82
82
|
|
|
83
|
+
// lr-f36626: a backgrounded Task's own stream activity is genuine session
|
|
84
|
+
// activity even though the parent turn's isProcessing is false while the
|
|
85
|
+
// dispatch-loop sits WAITING on the child (root cause: the idle reaper in
|
|
86
|
+
// sdk-bridge.js only ever saw the two top-level turn/query bump sites, so
|
|
87
|
+
// a session correctly waiting on a live child looked identical to an
|
|
88
|
+
// abandoned one and got reaped out from under it). Bumping here — the
|
|
89
|
+
// same field the reaper compares against — means a genuinely progressing
|
|
90
|
+
// child keeps the parent session non-idle for as long as it keeps
|
|
91
|
+
// producing output; a dead/silent child stops bumping and the session
|
|
92
|
+
// still times out and is reaped normally (no blanket "never reap if a
|
|
93
|
+
// child is registered" rule — see startIdleReaper in sdk-bridge.js).
|
|
94
|
+
session.lastActivityAt = Date.now();
|
|
95
|
+
|
|
83
96
|
if (parsed.messageRole === "assistant") {
|
|
84
97
|
// Extract tool_use blocks from sub-agent assistant messages
|
|
85
98
|
for (var i = 0; i < content.length; i++) {
|
|
@@ -654,6 +667,11 @@ function attachMessageProcessor(ctx) {
|
|
|
654
667
|
} else if (parsed.yokeType === "task_started") {
|
|
655
668
|
var parentId = parsed.parentToolId;
|
|
656
669
|
if (parentId) {
|
|
670
|
+
// lr-f36626: genuine backgrounded-Task lifecycle activity — see the
|
|
671
|
+
// matching comment on processSubagentMessage's bump above and on
|
|
672
|
+
// startIdleReaper in sdk-bridge.js for why this keeps a WAITING
|
|
673
|
+
// parent session non-idle for as long as its child keeps reporting in.
|
|
674
|
+
session.lastActivityAt = Date.now();
|
|
657
675
|
if (!session.taskIdMap) session.taskIdMap = {};
|
|
658
676
|
session.taskIdMap[parentId] = parsed.taskId;
|
|
659
677
|
sendAndRecord(session, {
|
|
@@ -667,6 +685,7 @@ function attachMessageProcessor(ctx) {
|
|
|
667
685
|
} else if (parsed.yokeType === "task_progress") {
|
|
668
686
|
var parentId = parsed.parentToolId;
|
|
669
687
|
if (parentId) {
|
|
688
|
+
session.lastActivityAt = Date.now(); // lr-f36626 — see task_started above
|
|
670
689
|
sendAndRecord(session, {
|
|
671
690
|
type: "task_progress",
|
|
672
691
|
parentToolId: parentId,
|
|
@@ -689,6 +708,7 @@ function attachMessageProcessor(ctx) {
|
|
|
689
708
|
}
|
|
690
709
|
}
|
|
691
710
|
if (parentId) {
|
|
711
|
+
session.lastActivityAt = Date.now(); // lr-f36626 — see task_started above
|
|
692
712
|
sendAndRecord(session, {
|
|
693
713
|
type: "task_updated",
|
|
694
714
|
parentToolId: parentId,
|
|
@@ -701,6 +721,7 @@ function attachMessageProcessor(ctx) {
|
|
|
701
721
|
// Sub-agent tool_progress: forward as activity update
|
|
702
722
|
var parentId = parsed.parentToolId;
|
|
703
723
|
if (parentId) {
|
|
724
|
+
session.lastActivityAt = Date.now(); // lr-f36626 — see task_started above
|
|
704
725
|
sendAndRecord(session, {
|
|
705
726
|
type: "subagent_activity",
|
|
706
727
|
parentToolId: parentId,
|
|
@@ -760,13 +781,17 @@ function attachMessageProcessor(ctx) {
|
|
|
760
781
|
var info = parsed.rateLimitInfo;
|
|
761
782
|
console.log("[sdk-bridge] rate_limit_event for session " + session.localId + ": status=" + info.status + " resetsAt=" + info.resetsAt + " isUsingOverage=" + info.isUsingOverage + " isProcessing=" + session.isProcessing);
|
|
762
783
|
|
|
763
|
-
// Broadcast reset time for top-bar usage link
|
|
784
|
+
// Broadcast reset time for top-bar usage link. This is a project-wide
|
|
785
|
+
// broadcast (not sendAndRecord), but still stamp localId so a client
|
|
786
|
+
// with multiple sessions open across tabs can tell which session's
|
|
787
|
+
// query actually triggered this usage update.
|
|
764
788
|
if (info.rateLimitType && info.resetsAt) {
|
|
765
789
|
send({
|
|
766
790
|
type: "rate_limit_usage",
|
|
767
791
|
rateLimitType: info.rateLimitType,
|
|
768
792
|
resetsAt: info.resetsAt * 1000,
|
|
769
793
|
status: info.status,
|
|
794
|
+
localId: session.localId,
|
|
770
795
|
});
|
|
771
796
|
}
|
|
772
797
|
|
|
@@ -780,6 +805,7 @@ function attachMessageProcessor(ctx) {
|
|
|
780
805
|
utilization: info.utilization || null,
|
|
781
806
|
isUsingOverage: info.isUsingOverage || false,
|
|
782
807
|
blocksCurrentModel: bucketBlocksModel(info.rateLimitType, sm && sm.currentModel),
|
|
808
|
+
localId: session.localId,
|
|
783
809
|
});
|
|
784
810
|
// Track rejection for auto-continue / scheduled message support
|
|
785
811
|
if (info.status === "rejected" && info.resetsAt) {
|
package/lib/server-palette.js
CHANGED
|
@@ -52,6 +52,15 @@ function attachPalette(ctx) {
|
|
|
52
52
|
} else {
|
|
53
53
|
// Search mode: BM25 ranked search across all sessions
|
|
54
54
|
var projectSessions = [];
|
|
55
|
+
// lr-a3e175: map each accessible session (by object identity) to its
|
|
56
|
+
// owning sm so searchPalette can stream history from disk
|
|
57
|
+
// (readSessionHistoryFromDisk) instead of reading the possibly-
|
|
58
|
+
// unloaded/trimmed session.history heap array directly — mirrors the
|
|
59
|
+
// lr-2ea2a7 streaming-search precedent in
|
|
60
|
+
// sm.searchSessions/searchSessionContent. Keyed by object identity
|
|
61
|
+
// (not localId) since localId is only unique within a single project's
|
|
62
|
+
// sm and would otherwise collide across projects.
|
|
63
|
+
var smBySession = new Map();
|
|
55
64
|
projects.forEach(function (pCtx, pSlug) {
|
|
56
65
|
var status = pCtx.getStatus();
|
|
57
66
|
if (status.isWorktree) return;
|
|
@@ -66,6 +75,7 @@ function attachPalette(ctx) {
|
|
|
66
75
|
var sAccess = onGetProjectAccess ? onGetProjectAccess(pSlug) : null;
|
|
67
76
|
if (!users.canAccessSession(paletteUser.id, session, sAccess)) return;
|
|
68
77
|
}
|
|
78
|
+
smBySession.set(session, pCtx.sm);
|
|
69
79
|
accessibleSessions.push(session);
|
|
70
80
|
});
|
|
71
81
|
if (accessibleSessions.length > 0) {
|
|
@@ -77,7 +87,13 @@ function attachPalette(ctx) {
|
|
|
77
87
|
});
|
|
78
88
|
}
|
|
79
89
|
});
|
|
80
|
-
pResults = sessionSearch.searchPalette(projectSessions, pQuery, {
|
|
90
|
+
pResults = sessionSearch.searchPalette(projectSessions, pQuery, {
|
|
91
|
+
maxResults: 30,
|
|
92
|
+
getHistory: function (session) {
|
|
93
|
+
var ownerSm = smBySession.get(session);
|
|
94
|
+
return ownerSm ? ownerSm.readSessionHistoryFromDisk(session) : session.history;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
81
97
|
}
|
|
82
98
|
|
|
83
99
|
res.writeHead(200, { "Content-Type": "application/json" });
|
package/lib/session-search.js
CHANGED
|
@@ -220,10 +220,16 @@ function searchIndex(index, query, maxResults) {
|
|
|
220
220
|
* Convert a session's history into searchable documents.
|
|
221
221
|
* Groups consecutive deltas into turns for better context.
|
|
222
222
|
* Each "turn" (user message or assistant response block) becomes one document.
|
|
223
|
+
*
|
|
224
|
+
* lr-a3e175: `history` is passed in explicitly rather than read off
|
|
225
|
+
* session.history so callers can supply a streaming disk-backed read
|
|
226
|
+
* (sm.readSessionHistoryFromDisk) for sessions that are LRU-evicted or never
|
|
227
|
+
* loaded into heap. Falls back to session.history for callers that already
|
|
228
|
+
* have a fully-loaded session (or in tests) and don't pass one.
|
|
223
229
|
*/
|
|
224
|
-
function sessionHistoryToDocs(session) {
|
|
230
|
+
function sessionHistoryToDocs(session, history) {
|
|
225
231
|
var docs = [];
|
|
226
|
-
|
|
232
|
+
history = history || session.history || [];
|
|
227
233
|
var sessionMeta = {
|
|
228
234
|
sessionId: session.localId || session.cliSessionId,
|
|
229
235
|
sessionTitle: session.title || "New Session"
|
|
@@ -291,13 +297,19 @@ function sessionHistoryToDocs(session) {
|
|
|
291
297
|
* @param {Array} projectSessions - [{ projectSlug, projectTitle, projectIcon, isMate, mateId, sessions }]
|
|
292
298
|
* where sessions = [{ localId, title, history, lastActivity, hidden }]
|
|
293
299
|
* @param {string} query
|
|
294
|
-
* @param {object} opts - { maxResults }
|
|
300
|
+
* @param {object} opts - { maxResults, getHistory }
|
|
301
|
+
* getHistory(session) - lr-a3e175: optional per-session history getter. When
|
|
302
|
+
* provided, called instead of reading session.history directly so a caller
|
|
303
|
+
* can supply a streaming disk-backed read (sm.readSessionHistoryFromDisk)
|
|
304
|
+
* for sessions that are LRU-evicted or never loaded into heap. Falls back
|
|
305
|
+
* to session.history when omitted.
|
|
295
306
|
* @returns {Array} [{ projectSlug, projectTitle, projectIcon, sessionId, sessionTitle, lastActivity, matchType, snippet, score, isMate, mateId }]
|
|
296
307
|
*/
|
|
297
308
|
function searchPalette(projectSessions, query, opts) {
|
|
298
309
|
opts = opts || {};
|
|
299
310
|
if (!query || !query.trim()) return [];
|
|
300
311
|
var maxResults = opts.maxResults || 30;
|
|
312
|
+
var getHistory = typeof opts.getHistory === "function" ? opts.getHistory : null;
|
|
301
313
|
|
|
302
314
|
var allDocs = [];
|
|
303
315
|
|
|
@@ -329,8 +341,11 @@ function searchPalette(projectSessions, query, opts) {
|
|
|
329
341
|
}
|
|
330
342
|
});
|
|
331
343
|
|
|
332
|
-
// Content turns as docs
|
|
333
|
-
|
|
344
|
+
// Content turns as docs. lr-a3e175: stream from disk via getHistory
|
|
345
|
+
// when supplied instead of reading the possibly-unloaded/trimmed
|
|
346
|
+
// session.history heap array directly (does not mutate heap/LRU state).
|
|
347
|
+
var sessionHistory = getHistory ? getHistory(session) : session.history;
|
|
348
|
+
var turnDocs = sessionHistoryToDocs(session, sessionHistory);
|
|
334
349
|
for (var td = 0; td < turnDocs.length; td++) {
|
|
335
350
|
var turnDoc = turnDocs[td];
|
|
336
351
|
allDocs.push({
|
package/lib/sessions.js
CHANGED
|
@@ -90,6 +90,16 @@ function createSessionManager(opts) {
|
|
|
90
90
|
if (session.allowedTools && Object.keys(session.allowedTools).length > 0) {
|
|
91
91
|
metaObj.allowedTools = session.allowedTools;
|
|
92
92
|
}
|
|
93
|
+
// lr-f36626: durable AUTO-RESUME marker set by lib/memory-shed.js when a
|
|
94
|
+
// session with a live background child was force-evicted under memory
|
|
95
|
+
// pressure. Persisted (not just in-memory) so the marker survives a
|
|
96
|
+
// daemon restart between the reclaim and the operator's next reconnect —
|
|
97
|
+
// otherwise the "never a silent orphan" guarantee only holds until the
|
|
98
|
+
// next process restart.
|
|
99
|
+
if (session.pendingAutoResume) {
|
|
100
|
+
metaObj.pendingAutoResume = true;
|
|
101
|
+
if (session.pendingAutoResumeReason) metaObj.pendingAutoResumeReason = session.pendingAutoResumeReason;
|
|
102
|
+
}
|
|
93
103
|
return JSON.stringify(metaObj);
|
|
94
104
|
}
|
|
95
105
|
|
|
@@ -376,6 +386,13 @@ function createSessionManager(opts) {
|
|
|
376
386
|
// source of truth) and drop it from the LRU order. Shared by the
|
|
377
387
|
// one-at-a-time post-load eviction (_lruEvictIfNeeded) and the
|
|
378
388
|
// pressure-driven bulk eviction (forceEvictToLimit, lr-5e70).
|
|
389
|
+
//
|
|
390
|
+
// Note: this never touches candidate.queryInstance — an evicted session's
|
|
391
|
+
// live query (if any) keeps running; only its in-heap history window is
|
|
392
|
+
// dropped and reloaded lazily on next access. That is what makes force-
|
|
393
|
+
// eviction of a session with a live background child (lr-f36626) safe on
|
|
394
|
+
// its own — the child process is not killed here. See forceEvictToLimit's
|
|
395
|
+
// header for the escalation this enables.
|
|
379
396
|
function _evictSession(candidate) {
|
|
380
397
|
candidate.history = [];
|
|
381
398
|
candidate._historyLoaded = false;
|
|
@@ -416,11 +433,32 @@ function createSessionManager(opts) {
|
|
|
416
433
|
// active session or an isProcessing session (skip-active-session and
|
|
417
434
|
// skip-processing are both load-bearing invariants, not incidental).
|
|
418
435
|
//
|
|
436
|
+
// lr-f36626: a session with a live registered background child
|
|
437
|
+
// (session.activeTaskToolIds non-empty) is a LAST-RESORT candidate, not an
|
|
438
|
+
// exempt one — under real memory pressure the ceiling (lr-c10f6d) still
|
|
439
|
+
// wins. Pass 1 below only evicts childless candidates; pass 2 falls back to
|
|
440
|
+
// live-child candidates solely when pass 1 could not reach the limit alone.
|
|
441
|
+
// Eviction here never kills the child (_evictSession never touches
|
|
442
|
+
// queryInstance — see its header), so this is not the reap-and-orphan
|
|
443
|
+
// failure mode lr-f36626 diagnosed; it only unloads in-heap history. The
|
|
444
|
+
// caller (lib/memory-shed.js) uses reclaimedLiveChild to durably checkpoint
|
|
445
|
+
// and notify both UI surfaces for each such session, per lr-f36626's
|
|
446
|
+
// "never a silent orphan" requirement.
|
|
447
|
+
//
|
|
419
448
|
// @param {number} limit — target max loaded-session count after this call
|
|
420
|
-
// @returns {
|
|
449
|
+
// @returns {{ evicted: number, reclaimedLiveChild: Array<object> }}
|
|
450
|
+
// reclaimedLiveChild holds the actual session objects (not just ids) that
|
|
451
|
+
// were evicted while carrying a live registered child, in eviction order.
|
|
421
452
|
function forceEvictToLimit(limit) {
|
|
422
453
|
var evicted = 0;
|
|
454
|
+
var reclaimedLiveChild = [];
|
|
423
455
|
var guard = lruOrder.length; // upper bound on loop iterations — no infinite loop
|
|
456
|
+
|
|
457
|
+
function hasLiveChild(candidate) {
|
|
458
|
+
return !!(candidate.activeTaskToolIds && Object.keys(candidate.activeTaskToolIds).length > 0);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// Pass 1: childless candidates only (the normal, non-escalated case).
|
|
424
462
|
while (lruOrder.length > limit && guard-- > 0) {
|
|
425
463
|
var evictedOne = false;
|
|
426
464
|
for (var ei = 0; ei < lruOrder.length; ei++) {
|
|
@@ -428,14 +466,36 @@ function createSessionManager(opts) {
|
|
|
428
466
|
if (candidateId === activeSessionId) continue;
|
|
429
467
|
var candidate = sessions.get(candidateId);
|
|
430
468
|
if (!candidate || candidate.isProcessing) continue;
|
|
469
|
+
if (hasLiveChild(candidate)) continue; // deferred to pass 2
|
|
431
470
|
_evictSession(candidate);
|
|
432
471
|
evicted++;
|
|
433
472
|
evictedOne = true;
|
|
434
473
|
break;
|
|
435
474
|
}
|
|
436
|
-
if (!evictedOne) break; // no further
|
|
475
|
+
if (!evictedOne) break; // no further childless candidate — stop, try pass 2
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Pass 2 (last resort): still over limit and childless candidates are
|
|
479
|
+
// exhausted — fall back to live-child candidates so the memory ceiling
|
|
480
|
+
// is never silently deferred to in favor of a background dispatch.
|
|
481
|
+
guard = lruOrder.length;
|
|
482
|
+
while (lruOrder.length > limit && guard-- > 0) {
|
|
483
|
+
var evictedOne2 = false;
|
|
484
|
+
for (var ej = 0; ej < lruOrder.length; ej++) {
|
|
485
|
+
var candidateId2 = lruOrder[ej];
|
|
486
|
+
if (candidateId2 === activeSessionId) continue;
|
|
487
|
+
var candidate2 = sessions.get(candidateId2);
|
|
488
|
+
if (!candidate2 || candidate2.isProcessing) continue;
|
|
489
|
+
reclaimedLiveChild.push(candidate2);
|
|
490
|
+
_evictSession(candidate2);
|
|
491
|
+
evicted++;
|
|
492
|
+
evictedOne2 = true;
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
if (!evictedOne2) break; // no further evictable candidate at all — stop
|
|
437
496
|
}
|
|
438
|
-
|
|
497
|
+
|
|
498
|
+
return { evicted: evicted, reclaimedLiveChild: reclaimedLiveChild };
|
|
439
499
|
}
|
|
440
500
|
|
|
441
501
|
// Parse every history line in a session's on-disk JSONL file (skipping the
|
|
@@ -623,6 +683,12 @@ function createSessionManager(opts) {
|
|
|
623
683
|
session.sessionVisibility = m.sessionVisibility || "shared";
|
|
624
684
|
session.bookmarked = !!m.bookmarked;
|
|
625
685
|
session.favoriteOrder = typeof m.favoriteOrder === "number" ? m.favoriteOrder : null;
|
|
686
|
+
// lr-f36626: restore the durable AUTO-RESUME marker across a daemon
|
|
687
|
+
// restart — see buildMetaLine's write side for why this must persist.
|
|
688
|
+
if (m.pendingAutoResume) {
|
|
689
|
+
session.pendingAutoResume = true;
|
|
690
|
+
session.pendingAutoResumeReason = m.pendingAutoResumeReason || null;
|
|
691
|
+
}
|
|
626
692
|
sessions.set(localId, session);
|
|
627
693
|
}
|
|
628
694
|
}
|
|
@@ -1011,6 +1077,18 @@ function createSessionManager(opts) {
|
|
|
1011
1077
|
}
|
|
1012
1078
|
}
|
|
1013
1079
|
|
|
1080
|
+
// lr-0827ba (PEACHES follow-up): explicit notification that a session was
|
|
1081
|
+
// deleted, carrying its localId, so the client can prune any per-session
|
|
1082
|
+
// state it tracks (e.g. rate-limit-state.js's armed-schedule map and
|
|
1083
|
+
// background reset timers) instead of leaking it forever. Prior to this,
|
|
1084
|
+
// the only client-observable signal was a fresh session_list broadcast
|
|
1085
|
+
// that simply omitted the deleted id — nothing told the client WHICH id(s)
|
|
1086
|
+
// disappeared, so nothing could target cleanup at them.
|
|
1087
|
+
function broadcastSessionDeleted(localIds) {
|
|
1088
|
+
var ids = Array.isArray(localIds) ? localIds : [localIds];
|
|
1089
|
+
send({ type: "session_deleted", ids: ids });
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1014
1092
|
function deleteSession(localId, targetWs) {
|
|
1015
1093
|
var session = sessions.get(localId);
|
|
1016
1094
|
if (!session) return;
|
|
@@ -1043,6 +1121,7 @@ function createSessionManager(opts) {
|
|
|
1043
1121
|
}
|
|
1044
1122
|
|
|
1045
1123
|
sessions.delete(localId);
|
|
1124
|
+
broadcastSessionDeleted(localId);
|
|
1046
1125
|
|
|
1047
1126
|
if (activeSessionId === localId) {
|
|
1048
1127
|
var remaining = [...sessions.keys()];
|
|
@@ -1105,6 +1184,7 @@ function createSessionManager(opts) {
|
|
|
1105
1184
|
if (ids[j] === activeSessionId) deletedActive = true;
|
|
1106
1185
|
deleteSessionQuiet(ids[j]);
|
|
1107
1186
|
}
|
|
1187
|
+
broadcastSessionDeleted(ids);
|
|
1108
1188
|
|
|
1109
1189
|
if (sessions.size === 0) {
|
|
1110
1190
|
createSession(null, targetWs);
|
|
@@ -1482,6 +1562,7 @@ function createSessionManager(opts) {
|
|
|
1482
1562
|
resumeSession: resumeSession,
|
|
1483
1563
|
mapSessionForClient: mapSessionForClient,
|
|
1484
1564
|
broadcastSessionList: broadcastSessionList,
|
|
1565
|
+
broadcastSessionDeleted: broadcastSessionDeleted,
|
|
1485
1566
|
getTotalUnread: function (ws) {
|
|
1486
1567
|
var unreadMap = (ws && ws._clayUnread) ? ws._clayUnread : {};
|
|
1487
1568
|
var total = 0;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.7.
|
|
6
|
+
"version": "1.7.1-beta.1",
|
|
7
7
|
"description": "Self-hosted console for Claude Code and Codex. Multi-user, browser-based, persistent AI sessions.",
|
|
8
8
|
"bin": {
|
|
9
9
|
"clagentic-console": "./bin/cli.js"
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"dev": "node bin/cli.js --dev",
|
|
13
13
|
"postinstall": "node scripts/postinstall.js",
|
|
14
|
+
"prepack": "node scripts/write-build-sha.js",
|
|
14
15
|
"test": "node --test --test-force-exit test/*.test.js",
|
|
15
|
-
"install:local-test": "
|
|
16
|
+
"install:local-test": "node scripts/install-local-test.js",
|
|
17
|
+
"verify:installed-build": "node scripts/verify-installed-build.js",
|
|
16
18
|
"semantic-release": "semantic-release"
|
|
17
19
|
},
|
|
18
20
|
"files": [
|