@clagentic/console 1.8.0-beta.2 → 1.9.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/lib/build-sha.json +2 -2
  2. package/lib/generated/claude-model-catalog.json +180 -0
  3. package/lib/model-catalog.js +202 -0
  4. package/lib/model-context-windows.js +9 -0
  5. package/lib/model-families.js +243 -0
  6. package/lib/project-connection.js +16 -4
  7. package/lib/project-sessions.js +102 -18
  8. package/lib/project.js +4 -0
  9. package/lib/public/css/menus.css +67 -0
  10. package/lib/public/css/server-settings.css +72 -0
  11. package/lib/public/index.html +3 -0
  12. package/lib/public/modules/app-loop-ui.js +4 -0
  13. package/lib/public/modules/app-messages.js +29 -4
  14. package/lib/public/modules/app-panels.js +93 -24
  15. package/lib/public/modules/app-rate-limit.js +1 -1
  16. package/lib/public/modules/model-context-windows.js +9 -0
  17. package/lib/public/modules/model-families.js +230 -0
  18. package/lib/public/modules/project-settings.js +1 -0
  19. package/lib/public/modules/scheduler.js +5 -0
  20. package/lib/public/modules/server-settings.js +14 -12
  21. package/lib/public/modules/settings-defaults.js +151 -41
  22. package/lib/public/modules/tools.js +38 -0
  23. package/lib/sdk-bridge.js +88 -13
  24. package/lib/sdk-message-processor.js +128 -3
  25. package/lib/server.js +55 -0
  26. package/lib/session-activity.js +282 -0
  27. package/lib/sessions.js +58 -3
  28. package/lib/terminal-manager.js +40 -0
  29. package/lib/utils.js +44 -0
  30. package/lib/ws-schema.js +1 -0
  31. package/lib/yoke/adapters/claude-worker.js +6 -2
  32. package/lib/yoke/adapters/claude.js +377 -87
  33. package/lib/yoke/adapters/codex.js +20 -0
  34. package/package.json +1 -1
  35. package/scripts/generate-model-catalog.js +337 -0
package/lib/sessions.js CHANGED
@@ -19,6 +19,22 @@ var { isVisibleHistoryEvent } = require("./history-visibility");
19
19
  var HISTORY_INMEM_MAX_DEFAULT = 1000;
20
20
  var HISTORY_INMEM_TRIM_TO_DEFAULT = 800;
21
21
 
22
+ // lr-041af8: single source of truth for "what model should THIS session's
23
+ // clients see right now" — a session's own persisted/live choice always
24
+ // wins, falling back to the project/global default (sm.currentModel) only
25
+ // when the session has never picked one of its own (e.g. brand new, or a
26
+ // pre-lr-db0437 session file with no persisted model). This is the same
27
+ // precedence every per-session config_state sender already used ad hoc
28
+ // (project-sessions.js's switch_session/set_model targeted replies); lifted
29
+ // out here so the connect/hydration path and every other sender can share
30
+ // it instead of re-deriving it (and risking a third divergence — see
31
+ // lr-db0437, which fixed the WRITE side of this same shared-mutable-state
32
+ // class but never enumerated the SENDERS, which is what lr-041af8 fixes).
33
+ function effectiveSessionModel(session, sm) {
34
+ if (session && session.model) return session.model;
35
+ return (sm && sm.currentModel) || "";
36
+ }
37
+
22
38
  function createSessionManager(opts) {
23
39
  var cwd = opts.cwd;
24
40
  var send = opts.send; // function(obj) - broadcast to all clients
@@ -26,6 +42,14 @@ function createSessionManager(opts) {
26
42
  var sendEach = opts.sendEach || null; // function(fn) - call fn(ws) for each connected client
27
43
  var sendAndRecord = null; // set after init via setSendAndRecord
28
44
  var onSessionDone = opts.onSessionDone || function () {};
45
+ // lr-13c047: fired whenever a session is permanently removed (single or
46
+ // bulk delete) so the server's cross-project unread map (keyed
47
+ // "slug::localId", lib/server.js) can prune the entry for this session
48
+ // instead of leaking it forever — the "prune-on-session-delete" half of
49
+ // Badge A's fix. No-op default keeps this opt-in for callers that don't
50
+ // wire cross-project unread tracking (e.g. tests constructing a bare
51
+ // SessionManager).
52
+ var onSessionDeleted = opts.onSessionDeleted || function () {};
29
53
 
30
54
  // daemon.json knob `historyInMemMax` (lr-2ea2a7): operators may override the
31
55
  // in-heap tail cap. TRIM_TO is derived as 80% of the configured max so the
@@ -83,6 +107,12 @@ function createSessionManager(opts) {
83
107
  if (session.lastRewindUuid) metaObj.lastRewindUuid = session.lastRewindUuid;
84
108
  if (session.agentName) metaObj.agentName = session.agentName;
85
109
  if (session.loop) metaObj.loop = session.loop;
110
+ // lr-db0437: persist the session's own model choice so it survives a
111
+ // daemon restart / resume. Without this, session.model only ever lived
112
+ // in memory — a restart silently reset every session back to whatever
113
+ // the project/global default happened to be, indistinguishable from the
114
+ // user never having picked a model at all.
115
+ if (session.model) metaObj.model = session.model;
86
116
  // Persist per-session "allow for session" tool grants (lr-8b2e) so they
87
117
  // survive daemon restart / resume-by-cliSessionId rehydration instead of
88
118
  // silently re-prompting. Only written when non-empty — grants that were
@@ -679,6 +709,10 @@ function createSessionManager(opts) {
679
709
  if (m.vendor) session.vendor = m.vendor;
680
710
  if (m.agentName) session.agentName = m.agentName;
681
711
  if (m.loop) session.loop = m.loop;
712
+ // lr-db0437: restore the session's own model choice across a daemon
713
+ // restart — see buildMetaLine's write side above for why this must
714
+ // persist (session.model, not the project/global default).
715
+ if (m.model) session.model = m.model;
682
716
  if (m.ownerId) session.ownerId = m.ownerId;
683
717
  session.sessionVisibility = m.sessionVisibility || "shared";
684
718
  session.bookmarked = !!m.bookmarked;
@@ -1036,7 +1070,11 @@ function createSessionManager(opts) {
1036
1070
  var _capsByVendor = capabilitiesByVendor || {};
1037
1071
  var _sessionVendor = session.vendor || defaultVendor || "claude";
1038
1072
  var _vendorCaps = _capsByVendor[_sessionVendor] || {};
1039
- _send({ type: "session_switched", id: localId, cliSessionId: session.cliSessionId || null, loop: session.loop || null, vendor: session.vendor || null, hasHistory: (session._historyLoaded ? session.history.length > 0 : !!session.cliSessionId), capabilities: _vendorCaps, isProcessing: !!session.isProcessing, agentName: session.agentName || null });
1073
+ // lr-041af8: carry the session's own effective model on the wire so a
1074
+ // client hydrating from session_switched alone (no separate config_state
1075
+ // round-trip needed) never has to fall back to guessing the shared
1076
+ // project/global default — see effectiveSessionModel() above.
1077
+ _send({ type: "session_switched", id: localId, cliSessionId: session.cliSessionId || null, loop: session.loop || null, vendor: session.vendor || null, model: effectiveSessionModel(session, _instance), hasHistory: (session._historyLoaded ? session.history.length > 0 : !!session.cliSessionId), capabilities: _vendorCaps, isProcessing: !!session.isProcessing, agentName: session.agentName || null });
1040
1078
  // Send vendor-specific slash commands
1041
1079
  var _vendorCmds = slashCommandsByVendor[_sessionVendor] || slashCommands || [];
1042
1080
  _send({ type: "slash_commands", commands: _vendorCmds, vendor: _sessionVendor });
@@ -1122,6 +1160,7 @@ function createSessionManager(opts) {
1122
1160
 
1123
1161
  sessions.delete(localId);
1124
1162
  broadcastSessionDeleted(localId);
1163
+ onSessionDeleted(localId);
1125
1164
 
1126
1165
  if (activeSessionId === localId) {
1127
1166
  var remaining = [...sessions.keys()];
@@ -1164,6 +1203,7 @@ function createSessionManager(opts) {
1164
1203
  try { fs.unlinkSync(sessionFilePath(session.cliSessionId)); } catch(e) {}
1165
1204
  }
1166
1205
  sessions.delete(localId);
1206
+ onSessionDeleted(localId);
1167
1207
  }
1168
1208
 
1169
1209
  function deleteSessionsBulk(localIds, targetWs) {
@@ -1530,7 +1570,15 @@ function createSessionManager(opts) {
1530
1570
  }).catch(function() {});
1531
1571
  }
1532
1572
 
1533
- return {
1573
+ // lr-041af8: captured once so internal functions (e.g. switchSession, which
1574
+ // may be invoked either as sm.switchSession(...) or directly by another
1575
+ // internal function like createSession — `this` is not reliably bound in
1576
+ // the latter case) can read ad hoc properties external callers set directly
1577
+ // on the returned instance (sm.currentModel, sm.modelsByVendor, etc.) that
1578
+ // were never declared as closure variables in this file.
1579
+ var _instance;
1580
+
1581
+ _instance = {
1534
1582
  get activeSessionId() { return activeSessionId; },
1535
1583
  get nextLocalId() { return nextLocalId; },
1536
1584
  // slashCommands and slashCommandsByVendor store {name, desc, type}[] (lr-1c7f).
@@ -1706,6 +1754,12 @@ function createSessionManager(opts) {
1706
1754
  return { ok: true };
1707
1755
  },
1708
1756
  permissionRequestIndex: permissionRequestIndex,
1757
+ // lr-041af8: exposed on the instance too (in addition to the module
1758
+ // export) so every existing `sm.<method>` call-site convention in
1759
+ // project-sessions.js / project-connection.js can call
1760
+ // `sm.effectiveSessionModel(session)` without importing this module
1761
+ // separately.
1762
+ effectiveSessionModel: function (session) { return effectiveSessionModel(session, _instance); },
1709
1763
  // Remove the process-level exit listener registered above.
1710
1764
  // Must be called when the project owning this session manager is destroyed
1711
1765
  // so listeners do not accumulate across project open/close cycles (lr-daca).
@@ -1713,6 +1767,7 @@ function createSessionManager(opts) {
1713
1767
  process.removeListener("exit", _onProcessExit);
1714
1768
  },
1715
1769
  };
1770
+ return _instance;
1716
1771
  }
1717
1772
 
1718
- module.exports = { createSessionManager };
1773
+ module.exports = { createSessionManager, effectiveSessionModel };
@@ -15,6 +15,17 @@ var SCROLLBACK_MAX = 50 * 1024; // 50 KB per terminal
15
15
  * filtered to the requesting user's own terminals; admins see all with an
16
16
  * ownerUserId field attached.
17
17
  */
18
+ // lr-13c047: grace window between a PTY exiting and its terminal session
19
+ // being auto-pruned from the server-side `terminals` Map. Before this, an
20
+ // exited session had no automatic removal path at all — only an explicit
21
+ // term_close (user action) ever called terminals.delete(id), so a dead tab
22
+ // could linger indefinitely as a phantom entry in term_list/list() until
23
+ // someone manually closed it. The grace window keeps the "[Process exited]"
24
+ // tab (and its scrollback) visible/reviewable for a short period — matching
25
+ // the existing UI affordance of a greyed-out exited tab — before it's
26
+ // reconciled away automatically.
27
+ var EXITED_AUTOCLOSE_MS = 30000;
28
+
18
29
  function createTerminalManager(opts) {
19
30
  var cwd = opts.cwd;
20
31
  var send = opts.send;
@@ -97,6 +108,20 @@ function createTerminalManager(opts) {
97
108
  } else {
98
109
  send({ type: "term_list", terminals: list() });
99
110
  }
111
+
112
+ // lr-13c047: auto-prune this session after a grace window instead of
113
+ // leaving it in `terminals` forever. Without this, a dead PTY tab was
114
+ // reconciled correctly on the client at exit time (badge count is
115
+ // right immediately), but the ghost session itself never left the
116
+ // server's Map — every subsequent reconnect/term_list still listed it,
117
+ // and a user had to notice and manually term_close a tab that had
118
+ // already finished. close() below already guards on terminals.get(id)
119
+ // still resolving to THIS session, so a manual close (or a brand new
120
+ // terminal reusing this same id after nextId wraps — it can't, nextId
121
+ // only increments) in the meantime is harmless.
122
+ session._autoCloseTimer = setTimeout(function () {
123
+ close(id, null);
124
+ }, EXITED_AUTOCLOSE_MS);
100
125
  });
101
126
 
102
127
  terminals.set(id, session);
@@ -179,6 +204,14 @@ function createTerminalManager(opts) {
179
204
  if (!session) return;
180
205
  if (!isAuthorized(session, callerWs)) return;
181
206
 
207
+ // lr-13c047: cancel the exited-session auto-close timer (see pty.onExit)
208
+ // so an earlier manual close doesn't leave a stray timer that later
209
+ // fires close(id, null) with no matching session left to act on.
210
+ if (session._autoCloseTimer) {
211
+ clearTimeout(session._autoCloseTimer);
212
+ session._autoCloseTimer = null;
213
+ }
214
+
182
215
  if (session.pty) {
183
216
  try { session.pty.kill(); } catch (e) {}
184
217
  session.pty = null;
@@ -240,6 +273,13 @@ function createTerminalManager(opts) {
240
273
  try { session.pty.kill(); } catch (e) {}
241
274
  session.pty = null;
242
275
  }
276
+ // lr-13c047: cancel any pending auto-close timer so it doesn't fire
277
+ // close(id, null) after this manager (and its `terminals` Map) has
278
+ // already been torn down.
279
+ if (session._autoCloseTimer) {
280
+ clearTimeout(session._autoCloseTimer);
281
+ session._autoCloseTimer = null;
282
+ }
243
283
  }
244
284
  terminals.clear();
245
285
  }
package/lib/utils.js CHANGED
@@ -79,6 +79,49 @@ function sanitizeAllowedTools(value) {
79
79
  return out;
80
80
  }
81
81
 
82
+ /**
83
+ * Compute the key used to index a session's "allow for session" grant map
84
+ * (session.allowedTools) for a given tool call (lr-f969dc).
85
+ *
86
+ * Most tools are correctly discriminated by bare tool name alone — MCP tools
87
+ * already fold server + tool identity into the name itself (e.g.
88
+ * "mcp__browser__navigate" vs "mcp__browser__screenshot" are already
89
+ * distinct keys), so approving one MCP tool must not silently approve a
90
+ * different one, and bare-name keying already gives that.
91
+ *
92
+ * The Claude `Skill` tool is the one exception found so far: every distinct
93
+ * skill invocation arrives as the SAME toolName "Skill" with a different
94
+ * `input.skill` discriminator. Keying on bare "Skill" means granting one
95
+ * skill silently authorizes every other skill for the rest of the session —
96
+ * a security regression, not the "doesn't stick" fix the grant was meant to
97
+ * provide. Fold the discriminator into the key so a grant is scoped to the
98
+ * specific skill that was actually approved.
99
+ *
100
+ * This repo is vendor-agnostic via the YOKE adapter layer (lib/yoke/), so a
101
+ * bare "Skill" literal here is a deliberate, checked exception, not a
102
+ * default pattern for future tools. Verified (lr-f969dc): Codex's approval
103
+ * RPCs (exec/file/MCP, lib/yoke/adapters/codex.js) route through this same
104
+ * function via the identical vendor-neutral canUseTool wiring, and all of
105
+ * them already send correctly-flat tool names — Codex has no tool today
106
+ * whose identity fans out under one shared name the way Skill does, so no
107
+ * generalization is needed for vendor parity right now. If a second vendor
108
+ * or a renamed/restructured tool introduces another input-discriminated
109
+ * tool, extend this with another explicit branch (or a small declarative
110
+ * toolName -> discriminator-field table if a third case appears) rather
111
+ * than reaching for a config knob nobody would otherwise set.
112
+ *
113
+ * Falls back to the bare tool name when the expected discriminator is
114
+ * missing or not a string (fails closed to the pre-existing per-tool grant
115
+ * rather than throwing or producing an unstable key). Never hardcodes an
116
+ * individual skill name — only the shared "Skill" tool identifier.
117
+ */
118
+ function permissionGrantKey(toolName, input) {
119
+ if (toolName === "Skill" && input && typeof input.skill === "string" && input.skill) {
120
+ return "Skill:" + input.skill;
121
+ }
122
+ return toolName;
123
+ }
124
+
82
125
  /**
83
126
  * Default hard cap for readCappedBody() call sites that don't pass their own
84
127
  * maxBytes: these are small JSON-only pre-auth endpoints (login, PIN
@@ -138,6 +181,7 @@ module.exports = {
138
181
  resolveEncodedDir: resolveEncodedDir,
139
182
  resolveEncodedFile: resolveEncodedFile,
140
183
  sanitizeAllowedTools: sanitizeAllowedTools,
184
+ permissionGrantKey: permissionGrantKey,
141
185
  readCappedBody: readCappedBody,
142
186
  DEFAULT_BODY_CAP_BYTES: DEFAULT_BODY_CAP_BYTES,
143
187
  };
package/lib/ws-schema.js CHANGED
@@ -23,6 +23,7 @@ var schema = {
23
23
  "set_session_bookmark": { direction: "c2s", handler: "lib/project-sessions.js", description: "Bookmark or unbookmark a session in the sidebar" },
24
24
  "reorder_session_bookmarks": { direction: "c2s", handler: "lib/project-sessions.js", description: "Reorder favorited sessions within the favorites area" },
25
25
  "bulk_delete_sessions": { direction: "c2s", handler: "lib/project-sessions.js", description: "Delete a group of sessions at once" },
26
+ "mark_cross_project_read": { direction: "c2s", handler: "lib/project-sessions.js", description: "Clear the cross-project unread badge for a project slug without switching to it (lr-13c047)" },
26
27
  "resume_session": { direction: "c2s", handler: "lib/project-sessions.js", description: "Resume a CLI session by its CLI session ID" },
27
28
  "set_session_visibility": { direction: "c2s", handler: "lib/project-sessions.js", description: "Show or hide a session in the sidebar" },
28
29
  "search_sessions": { direction: "c2s", handler: "lib/project-sessions.js", description: "Search session titles" },
@@ -623,9 +623,13 @@ async function handleSetModel(msg) {
623
623
  if (!queryInstance) return;
624
624
  try {
625
625
  await queryInstance.setModel(msg.model);
626
- sendToDaemon({ type: "model_changed", model: msg.model });
626
+ // lr-f22787: echo requestId so the daemon-side setModel() promise
627
+ // (claude.js pendingSetModel) can be correlated and resolved — without
628
+ // it, the daemon has no way to distinguish this reply from any other
629
+ // model_changed broadcast.
630
+ sendToDaemon({ type: "model_changed", model: msg.model, requestId: msg.requestId });
627
631
  } catch (e) {
628
- sendToDaemon({ type: "worker_error", error: "Failed to set model: " + (e.message || e) });
632
+ sendToDaemon({ type: "worker_error", error: "Failed to set model: " + (e.message || e), requestId: msg.requestId });
629
633
  }
630
634
  }
631
635