@clagentic/console 1.5.0-beta.2 → 1.5.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/bin/cli.js +1 -0
- package/lib/config.js +80 -6
- package/lib/daemon-projects.js +1 -1
- package/lib/daemon.js +70 -2
- package/lib/project-external-trigger.js +62 -7
- package/lib/project-http.js +17 -1
- package/lib/project-loop.js +2 -1
- package/lib/project-sessions.js +49 -1
- package/lib/project-team.js +417 -0
- package/lib/project.js +14 -1
- package/lib/public/app.js +2 -0
- package/lib/public/css/home-hub.css +36 -0
- package/lib/public/css/icon-strip.css +28 -126
- package/lib/public/css/menus.css +2 -2
- package/lib/public/css/team-panel.css +149 -0
- package/lib/public/index.html +72 -15
- package/lib/public/modules/app-home-hub.js +12 -0
- package/lib/public/modules/app-messages.js +15 -2
- package/lib/public/modules/server-settings.js +74 -5
- package/lib/public/modules/sidebar-mobile.js +9 -88
- package/lib/public/modules/sidebar-sessions.js +4 -0
- package/lib/public/modules/sidebar-users.js +47 -307
- package/lib/public/modules/team-panel.js +331 -0
- package/lib/public/modules/tools.js +3 -0
- package/lib/public/style.css +1 -0
- package/lib/sdk-bridge.js +74 -1
- package/lib/sdk-message-processor.js +36 -0
- package/lib/sdk-worker.js +2 -2
- package/lib/server.js +12 -0
- package/lib/ws-schema.js +12 -0
- package/package.json +1 -1
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// team-panel.js - Live team-activity panel (desktop + mobile)
|
|
2
|
+
// Handles team_state, team_member_update, team_task_update, team_message,
|
|
3
|
+
// team_gone WS messages. Renders desktop #team-panel and mobile team sheet.
|
|
4
|
+
|
|
5
|
+
import { store } from './store.js';
|
|
6
|
+
import { getWs } from './ws-ref.js';
|
|
7
|
+
import { escapeHtml } from './utils.js';
|
|
8
|
+
import { refreshIcons } from './icons.js';
|
|
9
|
+
|
|
10
|
+
// --- Module state ---
|
|
11
|
+
var currentTeam = null;
|
|
12
|
+
var teamMessages = [];
|
|
13
|
+
var panelOpen = false;
|
|
14
|
+
|
|
15
|
+
// --- Helpers ---
|
|
16
|
+
|
|
17
|
+
function sendWs(msg) {
|
|
18
|
+
var ws = getWs();
|
|
19
|
+
if (ws && ws.readyState === 1) ws.send(JSON.stringify(msg));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function statusClass(status) {
|
|
23
|
+
if (status === "alive") return "alive";
|
|
24
|
+
if (status === "idle") return "idle";
|
|
25
|
+
if (status === "gone") return "gone";
|
|
26
|
+
return "unknown";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function agentId(m) {
|
|
30
|
+
if (typeof m === "string") return m;
|
|
31
|
+
return m.id || m.agentId || "";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function agentName(m) {
|
|
35
|
+
if (typeof m === "string") return m;
|
|
36
|
+
return m.name || m.id || m.agentId || "unknown";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// --- Render helpers ---
|
|
40
|
+
|
|
41
|
+
function renderMembersSection(container, members, memberStatuses, memberActivities) {
|
|
42
|
+
var header = document.createElement("div");
|
|
43
|
+
header.className = "team-section-header";
|
|
44
|
+
header.textContent = "Members";
|
|
45
|
+
container.appendChild(header);
|
|
46
|
+
|
|
47
|
+
if (!members || members.length === 0) {
|
|
48
|
+
var empty = document.createElement("div");
|
|
49
|
+
empty.className = "team-member-row";
|
|
50
|
+
empty.style.color = "var(--text-dimmer)";
|
|
51
|
+
empty.textContent = "No members";
|
|
52
|
+
container.appendChild(empty);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
for (var i = 0; i < members.length; i++) {
|
|
57
|
+
var m = members[i];
|
|
58
|
+
var id = agentId(m);
|
|
59
|
+
var name = agentName(m);
|
|
60
|
+
var status = (memberStatuses && memberStatuses[id]) || "unknown";
|
|
61
|
+
var activity = (memberActivities && memberActivities[id]) || "";
|
|
62
|
+
|
|
63
|
+
var row = document.createElement("div");
|
|
64
|
+
row.className = "team-member-row";
|
|
65
|
+
|
|
66
|
+
var dot = document.createElement("span");
|
|
67
|
+
dot.className = "team-member-status-dot " + statusClass(status);
|
|
68
|
+
row.appendChild(dot);
|
|
69
|
+
|
|
70
|
+
var nameEl = document.createElement("span");
|
|
71
|
+
nameEl.className = "team-member-name";
|
|
72
|
+
nameEl.textContent = name;
|
|
73
|
+
row.appendChild(nameEl);
|
|
74
|
+
|
|
75
|
+
if (activity) {
|
|
76
|
+
var actEl = document.createElement("span");
|
|
77
|
+
actEl.className = "team-member-activity";
|
|
78
|
+
actEl.textContent = activity;
|
|
79
|
+
row.appendChild(actEl);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
container.appendChild(row);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function taskStatusLabel(status) {
|
|
87
|
+
if (status === "completed") return "completed";
|
|
88
|
+
if (status === "in_progress") return "in_progress";
|
|
89
|
+
if (status === "blocked") return "blocked";
|
|
90
|
+
return "pending";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function taskCheckmark(status) {
|
|
94
|
+
if (status === "completed") return "✓";
|
|
95
|
+
return "☐";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function renderTasksSection(container, tasks) {
|
|
99
|
+
var header = document.createElement("div");
|
|
100
|
+
header.className = "team-section-header";
|
|
101
|
+
header.textContent = "Tasks";
|
|
102
|
+
container.appendChild(header);
|
|
103
|
+
|
|
104
|
+
if (!tasks || tasks.length === 0) {
|
|
105
|
+
var empty = document.createElement("div");
|
|
106
|
+
empty.className = "team-task-item";
|
|
107
|
+
empty.style.color = "var(--text-dimmer)";
|
|
108
|
+
empty.textContent = "No tasks";
|
|
109
|
+
container.appendChild(empty);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (var i = 0; i < tasks.length; i++) {
|
|
114
|
+
var t = tasks[i];
|
|
115
|
+
var status = taskStatusLabel(t.status);
|
|
116
|
+
|
|
117
|
+
var item = document.createElement("div");
|
|
118
|
+
item.className = "team-task-item";
|
|
119
|
+
|
|
120
|
+
var check = document.createElement("span");
|
|
121
|
+
check.textContent = taskCheckmark(t.status);
|
|
122
|
+
check.style.marginRight = "6px";
|
|
123
|
+
check.style.flexShrink = "0";
|
|
124
|
+
item.appendChild(check);
|
|
125
|
+
|
|
126
|
+
var title = document.createElement("span");
|
|
127
|
+
title.style.flex = "1";
|
|
128
|
+
title.textContent = t.title || t.description || t.id || "Task";
|
|
129
|
+
item.appendChild(title);
|
|
130
|
+
|
|
131
|
+
var pill = document.createElement("span");
|
|
132
|
+
pill.className = "team-task-status " + status;
|
|
133
|
+
pill.textContent = status.replace("_", " ");
|
|
134
|
+
item.appendChild(pill);
|
|
135
|
+
|
|
136
|
+
container.appendChild(item);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function renderMessagesSection(container, messages) {
|
|
141
|
+
var header = document.createElement("div");
|
|
142
|
+
header.className = "team-section-header";
|
|
143
|
+
header.textContent = "Messages";
|
|
144
|
+
container.appendChild(header);
|
|
145
|
+
|
|
146
|
+
var recent = messages.slice(-10);
|
|
147
|
+
if (recent.length === 0) {
|
|
148
|
+
var empty = document.createElement("div");
|
|
149
|
+
empty.className = "team-message-item";
|
|
150
|
+
empty.style.color = "var(--text-dimmer)";
|
|
151
|
+
empty.textContent = "No messages yet";
|
|
152
|
+
container.appendChild(empty);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
for (var i = 0; i < recent.length; i++) {
|
|
157
|
+
var msg = recent[i];
|
|
158
|
+
var item = document.createElement("div");
|
|
159
|
+
item.className = "team-message-item";
|
|
160
|
+
|
|
161
|
+
var from = document.createElement("div");
|
|
162
|
+
from.className = "team-message-from";
|
|
163
|
+
from.textContent = escapeHtml(msg.fromAgentId || "?") + " → " + escapeHtml(msg.toAgentId || "?") + ":";
|
|
164
|
+
item.appendChild(from);
|
|
165
|
+
|
|
166
|
+
var body = document.createElement("div");
|
|
167
|
+
body.className = "team-message-body";
|
|
168
|
+
body.textContent = msg.summary || msg.body || "";
|
|
169
|
+
item.appendChild(body);
|
|
170
|
+
|
|
171
|
+
container.appendChild(item);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function renderTeamPanelBody() {
|
|
176
|
+
var bodyEl = document.getElementById("team-panel-body");
|
|
177
|
+
if (!bodyEl) return;
|
|
178
|
+
bodyEl.innerHTML = "";
|
|
179
|
+
|
|
180
|
+
if (!currentTeam) {
|
|
181
|
+
bodyEl.innerHTML =
|
|
182
|
+
'<div class="team-empty-state">' +
|
|
183
|
+
'<p>No active team</p>' +
|
|
184
|
+
'<p class="team-empty-hint">Start a session with Agent Teams enabled to see live activity here.</p>' +
|
|
185
|
+
'</div>';
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
renderMembersSection(bodyEl, currentTeam.members, currentTeam._memberStatuses, currentTeam._memberActivities);
|
|
190
|
+
|
|
191
|
+
var divider1 = document.createElement("hr");
|
|
192
|
+
divider1.className = "mobile-sheet-divider";
|
|
193
|
+
bodyEl.appendChild(divider1);
|
|
194
|
+
|
|
195
|
+
renderTasksSection(bodyEl, currentTeam.tasks);
|
|
196
|
+
|
|
197
|
+
var divider2 = document.createElement("hr");
|
|
198
|
+
divider2.className = "mobile-sheet-divider";
|
|
199
|
+
bodyEl.appendChild(divider2);
|
|
200
|
+
|
|
201
|
+
renderMessagesSection(bodyEl, teamMessages);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// --- Exports ---
|
|
205
|
+
|
|
206
|
+
export function initTeamPanel() {
|
|
207
|
+
// Wire close button
|
|
208
|
+
var closeBtn = document.getElementById("team-panel-close");
|
|
209
|
+
if (closeBtn) {
|
|
210
|
+
closeBtn.addEventListener("click", function () {
|
|
211
|
+
toggleTeamPanel();
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Send team_request_state when WS connects
|
|
216
|
+
store.subscribe(["connected"], function (state, prev) {
|
|
217
|
+
if (state.connected && !prev.connected) {
|
|
218
|
+
sendWs({ type: "team_request_state" });
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function handleTeamState(msg) {
|
|
224
|
+
currentTeam = msg.team || null;
|
|
225
|
+
if (currentTeam) {
|
|
226
|
+
currentTeam._memberStatuses = currentTeam._memberStatuses || {};
|
|
227
|
+
currentTeam._memberActivities = currentTeam._memberActivities || {};
|
|
228
|
+
}
|
|
229
|
+
teamMessages = msg.messages || [];
|
|
230
|
+
|
|
231
|
+
var panel = document.getElementById("team-panel");
|
|
232
|
+
if (panel) {
|
|
233
|
+
if (currentTeam) {
|
|
234
|
+
panel.classList.remove("hidden");
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
renderTeamPanelBody();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function handleTeamMemberUpdate(msg) {
|
|
242
|
+
if (!currentTeam) return;
|
|
243
|
+
|
|
244
|
+
// Full member list replacement
|
|
245
|
+
if (msg.members) {
|
|
246
|
+
currentTeam.members = msg.members;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Single member status/activity update
|
|
250
|
+
if (msg.agentId) {
|
|
251
|
+
currentTeam._memberStatuses = currentTeam._memberStatuses || {};
|
|
252
|
+
currentTeam._memberActivities = currentTeam._memberActivities || {};
|
|
253
|
+
if (msg.status) {
|
|
254
|
+
currentTeam._memberStatuses[msg.agentId] = msg.status;
|
|
255
|
+
}
|
|
256
|
+
if (msg.currentActivity) {
|
|
257
|
+
currentTeam._memberActivities[msg.agentId] = msg.currentActivity;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
renderTeamPanelBody();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function handleTeamTaskUpdate(msg) {
|
|
265
|
+
if (!currentTeam) return;
|
|
266
|
+
if (msg.tasks) {
|
|
267
|
+
currentTeam.tasks = msg.tasks;
|
|
268
|
+
}
|
|
269
|
+
renderTeamPanelBody();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function handleTeamMessage(msg) {
|
|
273
|
+
if (msg.message) {
|
|
274
|
+
teamMessages.push(msg.message);
|
|
275
|
+
if (teamMessages.length > 50) teamMessages.shift();
|
|
276
|
+
}
|
|
277
|
+
renderTeamPanelBody();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function handleTeamGone() {
|
|
281
|
+
currentTeam = null;
|
|
282
|
+
teamMessages = [];
|
|
283
|
+
panelOpen = false;
|
|
284
|
+
|
|
285
|
+
var panel = document.getElementById("team-panel");
|
|
286
|
+
if (panel) panel.classList.add("hidden");
|
|
287
|
+
|
|
288
|
+
renderTeamPanelBody();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function renderSheetTeam(listEl) {
|
|
292
|
+
if (!currentTeam) {
|
|
293
|
+
var empty = document.createElement("div");
|
|
294
|
+
empty.className = "team-empty-state";
|
|
295
|
+
empty.innerHTML =
|
|
296
|
+
'<p>No active team</p>' +
|
|
297
|
+
'<p class="team-empty-hint">Start a session with Agent Teams enabled to see live activity here.</p>';
|
|
298
|
+
listEl.appendChild(empty);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
renderMembersSection(listEl, currentTeam.members, currentTeam._memberStatuses, currentTeam._memberActivities);
|
|
303
|
+
|
|
304
|
+
var d1 = document.createElement("hr");
|
|
305
|
+
d1.className = "mobile-sheet-divider";
|
|
306
|
+
listEl.appendChild(d1);
|
|
307
|
+
|
|
308
|
+
renderTasksSection(listEl, currentTeam.tasks);
|
|
309
|
+
|
|
310
|
+
var d2 = document.createElement("hr");
|
|
311
|
+
d2.className = "mobile-sheet-divider";
|
|
312
|
+
listEl.appendChild(d2);
|
|
313
|
+
|
|
314
|
+
renderMessagesSection(listEl, teamMessages);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export function toggleTeamPanel() {
|
|
318
|
+
var panel = document.getElementById("team-panel");
|
|
319
|
+
if (!panel) return;
|
|
320
|
+
panelOpen = !panelOpen;
|
|
321
|
+
if (panelOpen) {
|
|
322
|
+
panel.classList.remove("hidden");
|
|
323
|
+
renderTeamPanelBody();
|
|
324
|
+
} else {
|
|
325
|
+
panel.classList.add("hidden");
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export function hasActiveTeam() {
|
|
330
|
+
return !!currentTeam;
|
|
331
|
+
}
|
|
@@ -480,6 +480,9 @@ function permissionInputSummary(toolName, input) {
|
|
|
480
480
|
|
|
481
481
|
export function renderPermissionRequest(requestId, toolName, toolInput, decisionReason, mateId, vendor) {
|
|
482
482
|
if (pendingPermissions[requestId]) return;
|
|
483
|
+
// On WS reconnect the DOM node may survive a pendingPermissions reset.
|
|
484
|
+
// Guard against duplicating the card in that case.
|
|
485
|
+
if (ctx && ctx.messagesEl && ctx.messagesEl.querySelector('[data-request-id="' + requestId + '"]')) return;
|
|
483
486
|
ctx.finalizeAssistantBlock();
|
|
484
487
|
stopThinking();
|
|
485
488
|
closeToolGroup();
|
package/lib/public/style.css
CHANGED
package/lib/sdk-bridge.js
CHANGED
|
@@ -28,6 +28,11 @@ var MAX_CONCURRENT_SESSIONS = (function () {
|
|
|
28
28
|
// and daemon.js — changing this constant is the single place to adjust the default.
|
|
29
29
|
var DEFAULT_MEM_AVAILABLE_MIN_MB = 1024;
|
|
30
30
|
|
|
31
|
+
// --- lr-2d91: cgroup context token guard ---
|
|
32
|
+
// Empirical calibration: claude-opus-4 at 1M context peaks at ~15 GB RSS,
|
|
33
|
+
// yielding approximately 67 tokens per MB of headroom consumed.
|
|
34
|
+
var DEFAULT_TOKENS_PER_MB_HEADROOM = 67;
|
|
35
|
+
|
|
31
36
|
// Read Linux MemAvailable from /proc/meminfo synchronously.
|
|
32
37
|
// Returns available memory in MB, or null on non-Linux or read failure.
|
|
33
38
|
// Sub-millisecond on Linux; the synchronous read is correct here — this is a
|
|
@@ -44,6 +49,38 @@ function readMemAvailableMB() {
|
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
|
|
52
|
+
// Read cgroup memory headroom in MB.
|
|
53
|
+
// Tries cgroup v2 (system.slice/clagentic-console.service) first, then cgroup v1.
|
|
54
|
+
// Returns null if neither is readable, the limit is "max" (unlimited), or on
|
|
55
|
+
// any read error — the caller must treat null as "no limit enforceable".
|
|
56
|
+
function readCgroupHeadroomMB() {
|
|
57
|
+
if (process.platform !== "linux") return null;
|
|
58
|
+
try {
|
|
59
|
+
// cgroup v2
|
|
60
|
+
var cgV2Dir = "/sys/fs/cgroup/system.slice/clagentic-console.service";
|
|
61
|
+
var currentRaw = fs.readFileSync(cgV2Dir + "/memory.current", "utf8").trim();
|
|
62
|
+
var maxRaw = fs.readFileSync(cgV2Dir + "/memory.max", "utf8").trim();
|
|
63
|
+
if (maxRaw === "max") return null;
|
|
64
|
+
var current = parseInt(currentRaw, 10);
|
|
65
|
+
var max = parseInt(maxRaw, 10);
|
|
66
|
+
if (isNaN(current) || isNaN(max) || max <= 0) return null;
|
|
67
|
+
return Math.floor((max - current) / 1024 / 1024);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
// fall through to v1
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
// cgroup v1
|
|
73
|
+
var current1 = parseInt(fs.readFileSync("/sys/fs/cgroup/memory/memory.usage_in_bytes", "utf8").trim(), 10);
|
|
74
|
+
var max1 = parseInt(fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "utf8").trim(), 10);
|
|
75
|
+
if (isNaN(current1) || isNaN(max1) || max1 <= 0) return null;
|
|
76
|
+
// Typical sentinel for "no limit" in cgroup v1 is a very large value (near INT64_MAX)
|
|
77
|
+
if (max1 > 9e18) return null;
|
|
78
|
+
return Math.floor((max1 - current1) / 1024 / 1024);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
47
84
|
// Extract serializable tool descriptors from MCP server instances.
|
|
48
85
|
// Used for IPC to worker processes (McpSdkServerConfigWithInstance is not serializable).
|
|
49
86
|
function extractMcpDescriptors(mcpServers) {
|
|
@@ -369,6 +406,8 @@ function createSDKBridge(opts) {
|
|
|
369
406
|
onProcessingChanged: onProcessingChanged,
|
|
370
407
|
onTurnDone: onTurnDone,
|
|
371
408
|
onAutoTitle: function (session) { autoGenerateTitle(session); },
|
|
409
|
+
onTeamCreate: opts.onTeamCreate || null,
|
|
410
|
+
onTeamDelete: opts.onTeamDelete || null,
|
|
372
411
|
opts: opts,
|
|
373
412
|
discoverSkillDirs: discoverSkillDirs,
|
|
374
413
|
mergeSkills: mergeSkills,
|
|
@@ -1258,6 +1297,40 @@ function createSDKBridge(opts) {
|
|
|
1258
1297
|
return;
|
|
1259
1298
|
}
|
|
1260
1299
|
}
|
|
1300
|
+
// lr-2d91: cgroup context token guard — applies to ALL turns because long-running
|
|
1301
|
+
// sessions accumulate context across turns and each new turn will load the full
|
|
1302
|
+
// accumulated context into memory. Placed after the memAvailableMinMB gate and
|
|
1303
|
+
// before the slot is claimed so a rejected query never increments the live counter.
|
|
1304
|
+
var contextTokens = session.lastStreamInputTokens || 0;
|
|
1305
|
+
if (contextTokens > 0) {
|
|
1306
|
+
var cgHeadroomMB = readCgroupHeadroomMB();
|
|
1307
|
+
if (cgHeadroomMB !== null) {
|
|
1308
|
+
var tokensPerMb = DEFAULT_TOKENS_PER_MB_HEADROOM;
|
|
1309
|
+
var _getConfig = opts.getConfig;
|
|
1310
|
+
if (typeof _getConfig === "function") {
|
|
1311
|
+
var _cgCfg = _getConfig();
|
|
1312
|
+
if (_cgCfg && typeof _cgCfg.tokensPerMbHeadroom === "number" && _cgCfg.tokensPerMbHeadroom > 0) {
|
|
1313
|
+
tokensPerMb = _cgCfg.tokensPerMbHeadroom;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
var allowedTokens = cgHeadroomMB * tokensPerMb;
|
|
1317
|
+
var warnTokens = Math.floor(allowedTokens * 0.8);
|
|
1318
|
+
if (contextTokens >= allowedTokens) {
|
|
1319
|
+
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);
|
|
1320
|
+
session.isProcessing = false;
|
|
1321
|
+
onProcessingChanged();
|
|
1322
|
+
var blockMsg = "Session context too large for available memory (" + Math.round(contextTokens / 1000) + "K tokens, " + cgHeadroomMB + " MB headroom). Start a new session or wait for other sessions to complete.";
|
|
1323
|
+
sendAndRecord(session, { type: "error", text: blockMsg });
|
|
1324
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1325
|
+
send({ type: "toast", level: "error", message: "Session blocked — context too large for available memory.", duration: 7000 });
|
|
1326
|
+
sm.broadcastSessionList();
|
|
1327
|
+
return;
|
|
1328
|
+
} else if (contextTokens >= warnTokens) {
|
|
1329
|
+
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 });
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1261
1334
|
// Claim the slot now so concurrent callers see the updated count immediately.
|
|
1262
1335
|
// Set _isCountedLive on the session at the same time so any early-return path
|
|
1263
1336
|
// below (sync throw, createQuery failure) can release it via releaseSlot().
|
|
@@ -2002,5 +2075,5 @@ function createSDKBridge(opts) {
|
|
|
2002
2075
|
};
|
|
2003
2076
|
}
|
|
2004
2077
|
|
|
2005
|
-
module.exports = { createSDKBridge, createMessageQueue, readMemAvailableMB, DEFAULT_MEM_AVAILABLE_MIN_MB };
|
|
2078
|
+
module.exports = { createSDKBridge, createMessageQueue, readMemAvailableMB, readCgroupHeadroomMB, DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM };
|
|
2006
2079
|
|
|
@@ -14,6 +14,8 @@ function attachMessageProcessor(ctx) {
|
|
|
14
14
|
var onProcessingChanged = ctx.onProcessingChanged;
|
|
15
15
|
var onTurnDone = ctx.onTurnDone;
|
|
16
16
|
var onAutoTitle = ctx.onAutoTitle;
|
|
17
|
+
var onTeamCreate = ctx.onTeamCreate || null;
|
|
18
|
+
var onTeamDelete = ctx.onTeamDelete || null;
|
|
17
19
|
var opts = ctx.opts;
|
|
18
20
|
var discoverSkillDirs = ctx.discoverSkillDirs;
|
|
19
21
|
var mergeSkills = ctx.mergeSkills;
|
|
@@ -233,6 +235,20 @@ function attachMessageProcessor(ctx) {
|
|
|
233
235
|
input: parsed.input || {},
|
|
234
236
|
});
|
|
235
237
|
|
|
238
|
+
// TeamCreate: record pending so we can extract the teamId from tool_result
|
|
239
|
+
if (parsed.toolName === "TeamCreate" && onTeamCreate) {
|
|
240
|
+
if (!session._pendingTeamCreates) session._pendingTeamCreates = {};
|
|
241
|
+
session._pendingTeamCreates[parsed.toolId] = {
|
|
242
|
+
cliSessionId: session.cliSessionId || null,
|
|
243
|
+
cwd: cwd,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// TeamDelete: fire immediately on execution
|
|
248
|
+
if (parsed.toolName === "TeamDelete" && onTeamDelete) {
|
|
249
|
+
try { onTeamDelete(); } catch (e) {}
|
|
250
|
+
}
|
|
251
|
+
|
|
236
252
|
} else if (parsed.yokeType === "tool_result") {
|
|
237
253
|
sendAndRecord(session, {
|
|
238
254
|
type: "tool_result",
|
|
@@ -241,6 +257,26 @@ function attachMessageProcessor(ctx) {
|
|
|
241
257
|
is_error: !!parsed.isError,
|
|
242
258
|
});
|
|
243
259
|
|
|
260
|
+
// TeamCreate result: extract team ID from result text and activate
|
|
261
|
+
if (onTeamCreate && session._pendingTeamCreates && session._pendingTeamCreates[parsed.toolId]) {
|
|
262
|
+
var pending = session._pendingTeamCreates[parsed.toolId];
|
|
263
|
+
delete session._pendingTeamCreates[parsed.toolId];
|
|
264
|
+
if (!parsed.isError) {
|
|
265
|
+
// Extract UUID from result text (e.g. "Created team abc123...")
|
|
266
|
+
var resultText = typeof parsed.content === "string" ? parsed.content : "";
|
|
267
|
+
var uuidMatch = resultText.match(/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i);
|
|
268
|
+
var shortMatch = uuidMatch ? null : resultText.match(/team\s+([a-z0-9_-]{4,})/i);
|
|
269
|
+
var teamId = (uuidMatch && uuidMatch[1]) || (shortMatch && shortMatch[1]) || null;
|
|
270
|
+
if (teamId) {
|
|
271
|
+
try {
|
|
272
|
+
onTeamCreate(teamId, session.cliSessionId || pending.cliSessionId, pending.cwd);
|
|
273
|
+
} catch (e) {
|
|
274
|
+
console.error("[sdk-message-processor] onTeamCreate threw:", e && e.message ? e.message : e);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
244
280
|
} else if (parsed.yokeType === "plan_updated") {
|
|
245
281
|
var todos = Array.isArray(parsed.plan) ? parsed.plan.map(function(step, idx) {
|
|
246
282
|
var todo = {
|
package/lib/sdk-worker.js
CHANGED
|
@@ -523,10 +523,10 @@ async function handleQueryStart(msg) {
|
|
|
523
523
|
try { pendingMcpCalls[k].reject(new Error("Worker shutting down")); } catch(e) {}
|
|
524
524
|
}
|
|
525
525
|
for (var k in pendingAskUser) {
|
|
526
|
-
try { pendingAskUser[k](
|
|
526
|
+
try { pendingAskUser[k]({ behavior: "deny", message: "Worker shutting down" }); } catch(e) {}
|
|
527
527
|
}
|
|
528
528
|
for (var k in pendingElicitations) {
|
|
529
|
-
try { pendingElicitations[k](
|
|
529
|
+
try { pendingElicitations[k]({ action: "reject" }); } catch(e) {}
|
|
530
530
|
}
|
|
531
531
|
queryInstance = null;
|
|
532
532
|
messageQueue = null;
|
package/lib/server.js
CHANGED
|
@@ -438,6 +438,18 @@ function createServer(opts) {
|
|
|
438
438
|
heapTotal: mem.heapTotal,
|
|
439
439
|
};
|
|
440
440
|
health.pid = process.pid;
|
|
441
|
+
// Cheap probe: if the process holds deleted inodes, its on-disk code was replaced
|
|
442
|
+
// by a newer npm install while this daemon was still running.
|
|
443
|
+
var staleInodes = false;
|
|
444
|
+
if (process.platform === 'linux') {
|
|
445
|
+
try {
|
|
446
|
+
var mapsContent = fs.readFileSync('/proc/self/maps', 'utf8');
|
|
447
|
+
staleInodes = mapsContent.split('\n').some(function(line) {
|
|
448
|
+
return line.includes(' (deleted)');
|
|
449
|
+
});
|
|
450
|
+
} catch (_) {}
|
|
451
|
+
}
|
|
452
|
+
health.stale = staleInodes;
|
|
441
453
|
}
|
|
442
454
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
443
455
|
res.end(JSON.stringify(health));
|
package/lib/ws-schema.js
CHANGED
|
@@ -89,6 +89,12 @@ var schema = {
|
|
|
89
89
|
"subagent_activity": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Activity indicator for a subagent" },
|
|
90
90
|
"subagent_tool": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Subagent tool use event" },
|
|
91
91
|
"subagent_done": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Subagent task completed" },
|
|
92
|
+
"team_state": { direction: "s2c", handler: "lib/public/modules/team-panel.js", description: "Full team snapshot: members, tasks, state" },
|
|
93
|
+
"team_member_update": { direction: "s2c", handler: "lib/public/modules/team-panel.js", description: "Single teammate liveness/activity change" },
|
|
94
|
+
"team_task_update": { direction: "s2c", handler: "lib/public/modules/team-panel.js", description: "Shared task state change" },
|
|
95
|
+
"team_message": { direction: "s2c", handler: "lib/public/modules/team-panel.js", description: "Teammate SendMessage event (peer DM)" },
|
|
96
|
+
"team_gone": { direction: "s2c", handler: "lib/public/modules/team-panel.js", description: "Team was deleted/cleaned up" },
|
|
97
|
+
"team_request_state": { direction: "c2s", handler: "lib/project-team.js", description: "Client requests current team snapshot" },
|
|
92
98
|
"task_started": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Background task started" },
|
|
93
99
|
"task_progress": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Background task progress update" },
|
|
94
100
|
|
|
@@ -222,6 +228,12 @@ var schema = {
|
|
|
222
228
|
"auto_continue_changed": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Broadcast: auto-continue state changed" },
|
|
223
229
|
"set_image_retention": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set image retention period in days" },
|
|
224
230
|
"set_image_retention_result": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Image retention setting result" },
|
|
231
|
+
"set_mem_available_threshold": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set the minimum available memory threshold (MB) for new queries" },
|
|
232
|
+
"set_mem_available_threshold_result": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "MemAvailable threshold setting result" },
|
|
233
|
+
"mem_available_threshold_changed": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Broadcast: MemAvailable threshold changed" },
|
|
234
|
+
"set_tokens_per_mb_headroom": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set the context token density per MB of cgroup headroom" },
|
|
235
|
+
"set_tokens_per_mb_headroom_result": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Tokens per MB headroom setting result" },
|
|
236
|
+
"tokens_per_mb_headroom_changed": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Broadcast: tokens per MB headroom setting changed" },
|
|
225
237
|
"shutdown_server": { direction: "c2s", handler: "lib/project-sessions.js", description: "Request server shutdown" },
|
|
226
238
|
"shutdown_server_result": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Shutdown request result" },
|
|
227
239
|
"restart_server": { direction: "c2s", handler: "lib/project-sessions.js", description: "Request server restart" },
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.5.0-beta.
|
|
6
|
+
"version": "1.5.0-beta.3",
|
|
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"
|