@clagentic/console 1.8.0 → 1.9.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +12 -1
- package/lib/agents.js +13 -3
- package/lib/build-sha.json +2 -2
- package/lib/cli/ipc-subcommands.js +40 -4
- package/lib/daemon.js +25 -1
- package/lib/generated/claude-model-catalog.json +180 -0
- package/lib/model-catalog.js +202 -0
- package/lib/model-families.js +243 -0
- package/lib/project-connection.js +30 -5
- package/lib/project-loop.js +46 -2
- package/lib/project-sessions.js +133 -21
- package/lib/project-user-message.js +70 -3
- package/lib/project.js +11 -1
- package/lib/public/app.js +14 -4
- package/lib/public/css/base.css +14 -0
- package/lib/public/css/home-hub.css +28 -8
- package/lib/public/css/icon-strip.css +17 -0
- package/lib/public/css/menus.css +67 -0
- package/lib/public/css/messages.css +11 -0
- package/lib/public/css/mobile-nav.css +22 -0
- package/lib/public/css/server-settings.css +72 -0
- package/lib/public/css/sidebar.css +15 -0
- package/lib/public/css/title-bar.css +10 -1
- package/lib/public/index.html +4 -0
- package/lib/public/modules/activity-latch.js +159 -0
- package/lib/public/modules/activity-state.js +157 -0
- package/lib/public/modules/app-connection.js +10 -4
- package/lib/public/modules/app-favicon.js +88 -1
- package/lib/public/modules/app-home-hub.js +14 -11
- package/lib/public/modules/app-loop-ui.js +90 -2
- package/lib/public/modules/app-messages.js +117 -28
- package/lib/public/modules/app-panels.js +184 -56
- package/lib/public/modules/app-projects.js +28 -8
- package/lib/public/modules/app-rate-limit.js +14 -2
- package/lib/public/modules/model-families.js +230 -0
- package/lib/public/modules/project-settings.js +1 -0
- package/lib/public/modules/scheduler.js +5 -0
- package/lib/public/modules/server-settings.js +14 -12
- package/lib/public/modules/settings-defaults.js +151 -41
- package/lib/public/modules/sidebar-mobile.js +32 -22
- package/lib/public/modules/sidebar-projects.js +42 -14
- package/lib/public/modules/sidebar-sessions.js +168 -48
- package/lib/public/modules/tools.js +22 -12
- package/lib/sdk-bridge.js +389 -35
- package/lib/sdk-message-processor.js +215 -7
- package/lib/sdk-skill-discovery.js +46 -6
- package/lib/sdk-slash-enrichment.js +5 -2
- package/lib/server-hub-sessions.js +70 -0
- package/lib/server.js +79 -22
- package/lib/session-activity.js +289 -0
- package/lib/sessions.js +104 -3
- package/lib/smtp.js +10 -1
- package/lib/terminal-manager.js +40 -0
- package/lib/utils.js +44 -0
- package/lib/ws-schema.js +17 -0
- package/lib/yoke/adapters/claude-worker.js +6 -2
- package/lib/yoke/adapters/claude.js +384 -88
- package/lib/yoke/adapters/codex.js +239 -31
- package/package.json +2 -2
- package/scripts/check-test-count.js +397 -0
- package/scripts/generate-model-catalog.js +337 -0
- package/scripts/test-file-completion-reporter.js +43 -0
- package/lib/model-context-windows.js +0 -65
- package/lib/public/modules/model-context-windows.js +0 -62
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* model-families.js — shared source of truth for Claude model family/version
|
|
3
|
+
* parsing, derived display names, and capability heuristics. (lr-d91ecf)
|
|
4
|
+
*
|
|
5
|
+
* This is the CJS backend copy, consumed by lib/yoke/adapters/claude.js.
|
|
6
|
+
* The ES module (browser) copy lives at lib/public/modules/model-families.js
|
|
7
|
+
* and is consumed by settings-defaults.js and app-panels.js. A CI test
|
|
8
|
+
* (test/model-families-parity.test.js) asserts both files produce identical
|
|
9
|
+
* results so they cannot silently drift — same discipline as the existing
|
|
10
|
+
* lib/model-context-windows.js / lib/public/modules/model-context-windows.js
|
|
11
|
+
* pair (lr-336f).
|
|
12
|
+
*
|
|
13
|
+
* Before this module existed, family/version detection was duplicated three
|
|
14
|
+
* ways: lib/yoke/adapters/claude.js (parseClaudeModelVersion etc., added by
|
|
15
|
+
* lr-e03635), lib/public/modules/settings-defaults.js (isSonnetModel/
|
|
16
|
+
* isOpusModel/isHaikuModel), and lib/public/modules/app-panels.js (its own
|
|
17
|
+
* private isSonnetModel copy). This is the single shared location — do not
|
|
18
|
+
* add a fourth copy elsewhere.
|
|
19
|
+
*
|
|
20
|
+
* No hardcoded model IDs or display-name tables: everything here is derived
|
|
21
|
+
* from the ID string's family substring + numeric version ordering, so a
|
|
22
|
+
* model release the code has never seen gets a sane display name and correct
|
|
23
|
+
* latest/older tiering with zero code changes.
|
|
24
|
+
*
|
|
25
|
+
* Keep this module dependency-light: no project imports, no Node built-ins.
|
|
26
|
+
* That constraint is what lets it stay close to the browser copy.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
var CLAUDE_MODEL_FAMILIES = ["opus", "sonnet", "haiku", "fable"];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* True if the given model ID string belongs to the given family (substring
|
|
33
|
+
* match on the lowercased ID). Generic helper backing isSonnetModel/
|
|
34
|
+
* isOpusModel/isHaikuModel below.
|
|
35
|
+
*/
|
|
36
|
+
function isClaudeFamily(model, family) {
|
|
37
|
+
if (!model) return false;
|
|
38
|
+
var str = typeof model === "string" ? model : (model.value || "");
|
|
39
|
+
return str.toLowerCase().indexOf(family) !== -1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isSonnetModel(model) { return isClaudeFamily(model, "sonnet"); }
|
|
43
|
+
function isOpusModel(model) { return isClaudeFamily(model, "opus"); }
|
|
44
|
+
function isHaikuModel(model) { return isClaudeFamily(model, "haiku"); }
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Parse a single ID/description-style string into { family, version } (or
|
|
48
|
+
* null). Shared core behind parseClaudeModelVersion below — no family
|
|
49
|
+
* resolution fallback, just the raw substring + numeric-segment extraction.
|
|
50
|
+
*/
|
|
51
|
+
function parseClaudeFamilyVersion(str) {
|
|
52
|
+
var lower = (str || "").toLowerCase();
|
|
53
|
+
// Strip pinned-version/beta suffix like "[1m]" before parsing.
|
|
54
|
+
var clean = lower.replace(/\[.*?\]$/, "").trim();
|
|
55
|
+
|
|
56
|
+
var family = null;
|
|
57
|
+
for (var i = 0; i < CLAUDE_MODEL_FAMILIES.length; i++) {
|
|
58
|
+
if (clean.indexOf(CLAUDE_MODEL_FAMILIES[i]) !== -1) { family = CLAUDE_MODEL_FAMILIES[i]; break; }
|
|
59
|
+
}
|
|
60
|
+
if (!family) return null;
|
|
61
|
+
|
|
62
|
+
// Numeric segments after the family name, stopping before a trailing date
|
|
63
|
+
// stamp (8 digits, e.g. "-20250929") which is a release date, not a version.
|
|
64
|
+
var afterFamily = clean.slice(clean.indexOf(family) + family.length);
|
|
65
|
+
var withoutDate = afterFamily.replace(/-?\d{8}\b/, "");
|
|
66
|
+
var nums = withoutDate.match(/\d+/g);
|
|
67
|
+
var version = nums ? nums.map(function(n) { return parseInt(n, 10); }) : [];
|
|
68
|
+
|
|
69
|
+
return { family: family, version: version };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Extract ONLY the leading dotted-number run immediately following the
|
|
74
|
+
* family name in free-text description prose (e.g. "Opus 4.8 with 1M
|
|
75
|
+
* context" -> [4, 8], stopping before the unrelated "1" in "1M"). Unlike
|
|
76
|
+
* parseClaudeFamilyVersion (which scans the entire remainder of a tight ID
|
|
77
|
+
* string), description text can contain trailing prose with unrelated
|
|
78
|
+
* digits, so only a contiguous number immediately after the family name
|
|
79
|
+
* (allowing a single separator character, e.g. the space in "Opus 4.8") is
|
|
80
|
+
* trusted as the version.
|
|
81
|
+
*/
|
|
82
|
+
function parseClaudeFamilyVersionFromDescription(str) {
|
|
83
|
+
var lower = (str || "").toLowerCase();
|
|
84
|
+
var family = null;
|
|
85
|
+
for (var i = 0; i < CLAUDE_MODEL_FAMILIES.length; i++) {
|
|
86
|
+
if (lower.indexOf(CLAUDE_MODEL_FAMILIES[i]) !== -1) { family = CLAUDE_MODEL_FAMILIES[i]; break; }
|
|
87
|
+
}
|
|
88
|
+
if (!family) return null;
|
|
89
|
+
|
|
90
|
+
var afterFamily = lower.slice(lower.indexOf(family) + family.length);
|
|
91
|
+
var m = afterFamily.match(/^[\s-]?(\d+(?:\.\d+)*)/);
|
|
92
|
+
var version = m ? m[1].split(".").map(function(n) { return parseInt(n, 10); }) : [];
|
|
93
|
+
|
|
94
|
+
return { family: family, version: version };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Parse a raw Claude model ID into { family, version } for ordering.
|
|
99
|
+
* version is an array of numeric segments (e.g. "claude-opus-4-6" -> [4, 6]),
|
|
100
|
+
* so comparison is lexicographic-numeric (4.6 > 4.5 > 4 > 3.7 > 3.5 > 3).
|
|
101
|
+
* Returns null when the ID doesn't match a known family (e.g. an ID with no
|
|
102
|
+
* family substring at all) — such entries are excluded from the tiering
|
|
103
|
+
* comparison entirely and default to isLatest: true (never hidden behind a
|
|
104
|
+
* disclosure we can't reason about).
|
|
105
|
+
*
|
|
106
|
+
* Live Claude runtimes report an alias for `modelId` (e.g. "opus", "sonnet",
|
|
107
|
+
* "fable") with NO version digits at all — the family resolves but the
|
|
108
|
+
* version array comes back empty. When the caller also has the vendor's
|
|
109
|
+
* `description` string (e.g. "Opus 4.8 with 1M context", "Sonnet 4.6"), pass
|
|
110
|
+
* it as the optional second argument: if the alias itself carried no version
|
|
111
|
+
* digits, ONLY the leading number immediately after the family name in the
|
|
112
|
+
* description is trusted (see parseClaudeFamilyVersionFromDescription) —
|
|
113
|
+
* trailing prose digits (e.g. the "1" in "1M context") are never picked up.
|
|
114
|
+
* This is what lets an alias-only model list still surface real version
|
|
115
|
+
* numbers (lr-5c07ce) without ever hardcoding a model ID.
|
|
116
|
+
*/
|
|
117
|
+
function parseClaudeModelVersion(modelId, description) {
|
|
118
|
+
var parsed = parseClaudeFamilyVersion(modelId);
|
|
119
|
+
if (!parsed) return null;
|
|
120
|
+
if (parsed.version.length === 0 && description) {
|
|
121
|
+
var fromDesc = parseClaudeFamilyVersionFromDescription(description);
|
|
122
|
+
if (fromDesc && fromDesc.family === parsed.family && fromDesc.version.length > 0) {
|
|
123
|
+
return { family: parsed.family, version: fromDesc.version };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return parsed;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Compare two version arrays lexicographically (missing segments treated as 0).
|
|
131
|
+
* Returns >0 if a > b, <0 if a < b, 0 if equal.
|
|
132
|
+
*/
|
|
133
|
+
function compareClaudeVersions(a, b) {
|
|
134
|
+
var len = Math.max(a.length, b.length);
|
|
135
|
+
for (var i = 0; i < len; i++) {
|
|
136
|
+
var av = a[i] || 0;
|
|
137
|
+
var bv = b[i] || 0;
|
|
138
|
+
if (av !== bv) return av - bv;
|
|
139
|
+
}
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Given the full list of raw model IDs (or rich objects) reported by the
|
|
145
|
+
* vendor, compute isLatest per model: true iff it holds the max version
|
|
146
|
+
* within its own family, or its ID doesn't parse into a known family at all
|
|
147
|
+
* (unparseable entries are never hidden).
|
|
148
|
+
*
|
|
149
|
+
* When an entry is a rich object with a `description` field, it feeds
|
|
150
|
+
* parseClaudeModelVersion's optional second argument (see its doc comment) —
|
|
151
|
+
* this is what lets a live alias-only list (value: "opus"/"sonnet"/"haiku",
|
|
152
|
+
* no version digits) still tier correctly against a real versioned ID that
|
|
153
|
+
* might appear alongside it, using the version embedded in the vendor's
|
|
154
|
+
* description text instead of a hardcoded table (lr-5c07ce).
|
|
155
|
+
* @returns {Object<string, boolean>} map of raw model value -> isLatest
|
|
156
|
+
*/
|
|
157
|
+
function deriveClaudeLatestTiers(models) {
|
|
158
|
+
var parsed = models.map(function(m) {
|
|
159
|
+
var value = (m && typeof m === "object") ? (m.value || "") : String(m || "");
|
|
160
|
+
var description = (m && typeof m === "object") ? m.description : null;
|
|
161
|
+
return { value: value, parsed: parseClaudeModelVersion(value, description) };
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
var maxVersionByFamily = {};
|
|
165
|
+
for (var i = 0; i < parsed.length; i++) {
|
|
166
|
+
var p = parsed[i].parsed;
|
|
167
|
+
if (!p) continue;
|
|
168
|
+
var current = maxVersionByFamily[p.family];
|
|
169
|
+
if (!current || compareClaudeVersions(p.version, current) > 0) {
|
|
170
|
+
maxVersionByFamily[p.family] = p.version;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
var result = {};
|
|
175
|
+
for (var j = 0; j < parsed.length; j++) {
|
|
176
|
+
var entry = parsed[j];
|
|
177
|
+
if (!entry.parsed) {
|
|
178
|
+
result[entry.value] = true; // unparseable — never hidden
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
var maxV = maxVersionByFamily[entry.parsed.family];
|
|
182
|
+
result[entry.value] = compareClaudeVersions(entry.parsed.version, maxV) === 0;
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Title-case a family name for display (e.g. "opus" -> "Opus").
|
|
188
|
+
function titleCaseFamily(family) {
|
|
189
|
+
return family.charAt(0).toUpperCase() + family.slice(1);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Derive a human-readable display name purely from the parsed family +
|
|
194
|
+
* version — no lookup table, so an ID the code has never seen still gets a
|
|
195
|
+
* sane label with zero code changes (e.g. "claude-opus-4-6" -> "Opus 4.6").
|
|
196
|
+
* Falls back to stripping the "claude-" prefix for IDs with no recognized
|
|
197
|
+
* family substring at all (e.g. "default" -> "Default").
|
|
198
|
+
*
|
|
199
|
+
* @param {string} modelId
|
|
200
|
+
* @param {string} [description] - optional vendor description string (e.g.
|
|
201
|
+
* "Opus 4.8 with 1M context"). When modelId is a bare alias with no
|
|
202
|
+
* version digits (the live runtime shape for opus/sonnet/haiku/fable —
|
|
203
|
+
* lr-5c07ce), the version embedded in description is used instead, so
|
|
204
|
+
* "Opus" (alias) displays as "Opus 4.8" rather than just "Opus".
|
|
205
|
+
*/
|
|
206
|
+
function claudeDisplayName(modelId, description) {
|
|
207
|
+
var parsed = parseClaudeModelVersion(modelId, description);
|
|
208
|
+
if (parsed) {
|
|
209
|
+
var label = titleCaseFamily(parsed.family);
|
|
210
|
+
if (parsed.version.length > 0) {
|
|
211
|
+
label += " " + parsed.version.join(".");
|
|
212
|
+
}
|
|
213
|
+
return label;
|
|
214
|
+
}
|
|
215
|
+
// Fallback: strip "claude-" prefix, title-case remainder
|
|
216
|
+
var stripped = (modelId || "").replace(/^claude-/i, "");
|
|
217
|
+
return stripped;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Haiku models do not support extended thinking.
|
|
221
|
+
function claudeModelSupportsThinking(modelId) {
|
|
222
|
+
return !isHaikuModel(modelId);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Models known to support effort control. Currently all Claude 4.x opus/sonnet
|
|
226
|
+
// models support effort; haiku does not (no reasoning). Defaults to true for
|
|
227
|
+
// unknown models so new releases are not accidentally silenced.
|
|
228
|
+
function claudeModelSupportsEffort(modelId) {
|
|
229
|
+
return !isHaikuModel(modelId);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
module.exports = {
|
|
233
|
+
CLAUDE_MODEL_FAMILIES: CLAUDE_MODEL_FAMILIES,
|
|
234
|
+
isSonnetModel: isSonnetModel,
|
|
235
|
+
isOpusModel: isOpusModel,
|
|
236
|
+
isHaikuModel: isHaikuModel,
|
|
237
|
+
parseClaudeModelVersion: parseClaudeModelVersion,
|
|
238
|
+
compareClaudeVersions: compareClaudeVersions,
|
|
239
|
+
deriveClaudeLatestTiers: deriveClaudeLatestTiers,
|
|
240
|
+
claudeDisplayName: claudeDisplayName,
|
|
241
|
+
claudeModelSupportsThinking: claudeModelSupportsThinking,
|
|
242
|
+
claudeModelSupportsEffort: claudeModelSupportsEffort,
|
|
243
|
+
};
|
|
@@ -144,10 +144,19 @@ function attachConnection(ctx) {
|
|
|
144
144
|
if (sm.slashCommands) {
|
|
145
145
|
sendTo(ws, { type: "slash_commands", commands: sm.slashCommands });
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
// lr-041af8: hydrate from the session this client is about to restore
|
|
148
|
+
// into (restoredActive, resolved above), not the shared project/global
|
|
149
|
+
// default. Every reconnect/page-load previously hydrated the chip from
|
|
150
|
+
// sm.currentModel regardless of which model the restored session had
|
|
151
|
+
// actually persisted (sessions.js's buildMetaLine/loadSessions round-trip
|
|
152
|
+
// it correctly to disk — only this display path never consulted it) —
|
|
153
|
+
// the root cause of "picked opus 4.7, session ran on it, chip still says
|
|
154
|
+
// sonnet after a reconnect." See effectiveSessionModel() in sessions.js.
|
|
155
|
+
var _initialModel = sm.effectiveSessionModel(restoredActive);
|
|
156
|
+
if (_initialModel) {
|
|
157
|
+
sendTo(ws, { type: "model_info", model: _initialModel, models: initialModels, vendor: initialVendor, availableVendors: sm.availableVendors || [], installedVendors: sm.installedVendors || [] });
|
|
149
158
|
}
|
|
150
|
-
sendTo(ws, { type: "config_state", model:
|
|
159
|
+
sendTo(ws, { type: "config_state", model: _initialModel, mode: sm.currentPermissionMode || "default", effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
|
|
151
160
|
sendTo(ws, Object.assign({ type: "codex_config" }, getCodexConfig(sm)));
|
|
152
161
|
sendTo(ws, { type: "term_list", terminals: tm.list(ws) });
|
|
153
162
|
// Context sources sent after session is resolved (per-session storage)
|
|
@@ -217,7 +226,20 @@ function attachConnection(ctx) {
|
|
|
217
226
|
// matches how every other index/count in the wire contract is derived
|
|
218
227
|
// post-lr-2ea2a7.
|
|
219
228
|
var _hasHistory = ((active._historyBaseIndex || 0) + active.history.length) > 0;
|
|
220
|
-
|
|
229
|
+
// lr-041af8: carry the restored session's own effective model — see
|
|
230
|
+
// effectiveSessionModel() in sessions.js and the model_info/config_state
|
|
231
|
+
// fix above in this same connect handler.
|
|
232
|
+
// This hydration send previously omitted isProcessing — sessions.js's
|
|
233
|
+
// switchSession() send DOES carry it, but a client that hydrates via
|
|
234
|
+
// THIS path (fresh connect / reconnect) never got the authoritative
|
|
235
|
+
// reconciled value here, only via the separate status:"processing"
|
|
236
|
+
// send below (guarded by active.isProcessing) — and that separate
|
|
237
|
+
// message carried no session-scoping (see localId note below), so a
|
|
238
|
+
// client's derived 'sessionIsProcessing' could lag or desync from
|
|
239
|
+
// server truth across a reconnect. Carrying it directly on
|
|
240
|
+
// session_switched matches switchSession() and gives the client a
|
|
241
|
+
// single authoritative snapshot value to reconcile the footer against.
|
|
242
|
+
sendTo(ws, { type: "session_switched", id: active.localId, cliSessionId: active.cliSessionId || null, loop: active.loop || null, vendor: active.vendor || null, model: sm.effectiveSessionModel(active), hasHistory: _hasHistory, capabilities: _vendorCaps, isProcessing: !!active.isProcessing, agentName: active.agentName || null });
|
|
221
243
|
// Send per-session context sources
|
|
222
244
|
var sessionSources = loadContextSources(slug, active.localId);
|
|
223
245
|
sendTo(ws, { type: "context_sources_state", active: sessionSources });
|
|
@@ -227,7 +249,10 @@ function attachConnection(ctx) {
|
|
|
227
249
|
sm.replayHistory(active, undefined, ws, hydrateImageRefs);
|
|
228
250
|
|
|
229
251
|
if (active.isProcessing) {
|
|
230
|
-
|
|
252
|
+
// Carry localId so the client can session-scope this edge (matching
|
|
253
|
+
// the scheduled_message_* pattern) instead of writing the global
|
|
254
|
+
// 'processing' latch blind to which session it belongs to.
|
|
255
|
+
sendTo(ws, { type: "status", status: "processing", localId: active.localId });
|
|
231
256
|
}
|
|
232
257
|
var pendingIds = Object.keys(active.pendingPermissions);
|
|
233
258
|
for (var pi = 0; pi < pendingIds.length; pi++) {
|
package/lib/project-loop.js
CHANGED
|
@@ -769,11 +769,31 @@ function attachLoop(ctx) {
|
|
|
769
769
|
var lastCoderSession = sm.sessions.get(loopState.currentSessionId);
|
|
770
770
|
if (lastCoderSession) {
|
|
771
771
|
lastCoderSession.singleTurn = false;
|
|
772
|
-
lastCoderSession.loop.active = false;
|
|
773
772
|
_loopOwnerUserId = lastCoderSession.ownerId || null;
|
|
774
773
|
}
|
|
775
774
|
}
|
|
776
775
|
|
|
776
|
+
// lr-fd38ac: clear the stale-resumability marker on EVERY session that
|
|
777
|
+
// belongs to this loop run, not just the last coder session. Four
|
|
778
|
+
// writers set `session.loop.active = true` (coder at runNextIteration(),
|
|
779
|
+
// judge at runJudge(), crafting at the two wizard-crafting sites) — every
|
|
780
|
+
// judge session and every prior iteration's coder session was left
|
|
781
|
+
// permanently orphaned at active:true, and the one session this used to
|
|
782
|
+
// fix reverted across a daemon restart because the clear was never
|
|
783
|
+
// persisted (sessions.js:109 writes session.loop into the on-disk meta
|
|
784
|
+
// line; sessions.js:711 rehydrates it — an in-memory-only clear never
|
|
785
|
+
// reaches either). Persist the clear on each session so it survives a
|
|
786
|
+
// restart and so switching into ANY finished loop session (coder, judge,
|
|
787
|
+
// any iteration) is resumable, not just the last one.
|
|
788
|
+
if (loopState.loopId) {
|
|
789
|
+
sm.sessions.forEach(function (s) {
|
|
790
|
+
if (s && s.loop && s.loop.loopId === loopState.loopId && s.loop.active) {
|
|
791
|
+
s.loop.active = false;
|
|
792
|
+
sm.saveSessionFile(s);
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
|
|
777
797
|
loopState.active = false;
|
|
778
798
|
loopState.phase = "done";
|
|
779
799
|
loopState.stopping = false;
|
|
@@ -956,6 +976,23 @@ function attachLoop(ctx) {
|
|
|
956
976
|
// lr-e31b: Queue a human message for delivery at the next iteration
|
|
957
977
|
// boundary. See the comment in runNextIteration() for why this is
|
|
958
978
|
// boundary-delivered rather than injected into the live iteration.
|
|
979
|
+
//
|
|
980
|
+
// lr-6fe5fc: this gate and the client's queue-mode UI gate
|
|
981
|
+
// (isLoopQueueSession() in app-loop-ui.js) are intentionally NOT the
|
|
982
|
+
// same predicate. This one answers "does the project have a running
|
|
983
|
+
// loop that will accept a queued message at all" — loopState.active
|
|
984
|
+
// alone, since pendingUserMessages is a single project-wide queue
|
|
985
|
+
// delivered at the next iteration boundary regardless of which session
|
|
986
|
+
// sent the WS message (loop_message carries no sessionId — see
|
|
987
|
+
// input.js). The client's gate additionally requires the loop's
|
|
988
|
+
// current session to be the one actually being viewed, which is a UX
|
|
989
|
+
// constraint (don't claim "queued for the next iteration" on a session
|
|
990
|
+
// that has nothing to do with that queue) this server-side accept
|
|
991
|
+
// check has no need to enforce, since it is already correctly scoped
|
|
992
|
+
// to the one loop this project can run at a time. Collapsing these
|
|
993
|
+
// into one shared function would misrepresent one of the two questions
|
|
994
|
+
// as the other; each stays the single authority for what it actually
|
|
995
|
+
// answers.
|
|
959
996
|
if (msg.type === "loop_message") {
|
|
960
997
|
if (!loopState.active) {
|
|
961
998
|
sendTo(ws, { type: "loop_message_error", text: "No loop is currently running." });
|
|
@@ -1365,7 +1402,8 @@ function attachLoop(ctx) {
|
|
|
1365
1402
|
// connected (most-recently-active) project crowded out the genuinely most
|
|
1366
1403
|
// recent sessions overall. getAllProjectSessions returns annotated shallow
|
|
1367
1404
|
// copies carrying _projectSlug/_projectTitle/_projectIcon for every project.
|
|
1368
|
-
var
|
|
1405
|
+
var hubUserId = ws._clayUser ? ws._clayUser.id : null;
|
|
1406
|
+
var allSessions = getAllProjectSessions ? getAllProjectSessions(true, hubUserId) : [];
|
|
1369
1407
|
// Sort newest-first by lastActivity
|
|
1370
1408
|
allSessions.sort(function (a, b) {
|
|
1371
1409
|
return (b.lastActivity || b.createdAt || 0) - (a.lastActivity || a.createdAt || 0);
|
|
@@ -1393,6 +1431,12 @@ function attachLoop(ctx) {
|
|
|
1393
1431
|
// state on this field so only the actually-notifying session's
|
|
1394
1432
|
// row lights up, not every sibling row in the same project.
|
|
1395
1433
|
unread: getSessionUnread(ws, sessProjectSlug, s.localId),
|
|
1434
|
+
// lr-66c118: multi-user activity tone. ownerId was already on the
|
|
1435
|
+
// session object (createSession) but never projected onto this
|
|
1436
|
+
// wire shape — the frontend derivation module (activity-state.js)
|
|
1437
|
+
// needs it to distinguish "my activity" from "another user's
|
|
1438
|
+
// activity" the same way session_list already does.
|
|
1439
|
+
ownerId: s.ownerId || null,
|
|
1396
1440
|
};
|
|
1397
1441
|
});
|
|
1398
1442
|
sendTo(ws, { type: "hub_recent_sessions", sessions: mapped });
|
package/lib/project-sessions.js
CHANGED
|
@@ -7,12 +7,29 @@ var liteDetect = require("./lite-detect");
|
|
|
7
7
|
var { readMemAvailableMB } = require("./sdk-bridge");
|
|
8
8
|
var agentsModule = require("./agents");
|
|
9
9
|
var agentsFavorites = require("./agents-favorites");
|
|
10
|
+
var sessionActivity = require("./session-activity");
|
|
10
11
|
// Kick off SDK agent discovery in the background at module load.
|
|
11
12
|
// Errors are swallowed inside refresh(); the cache starts empty and fills
|
|
12
13
|
// when the SDK subprocess completes initialization (~9s on this box).
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
//
|
|
15
|
+
// lr-795882: skipped under `node --test` (NODE_TEST_CONTEXT is set natively
|
|
16
|
+
// by the test runner itself — not a project-invented flag). This module is
|
|
17
|
+
// required, directly or transitively via lib/project.js, by ~18 test files;
|
|
18
|
+
// none of them exercise agent discovery, so this was spawning a real
|
|
19
|
+
// @anthropic-ai/claude-agent-sdk subprocess purely as an unrequested
|
|
20
|
+
// module-load side effect on every full suite run. refresh()'s SDK session
|
|
21
|
+
// is aborted in a finally block (lib/agents.js) but the underlying process
|
|
22
|
+
// exit is deferred by the SDK's own internal debounce, so the spawned
|
|
23
|
+
// subprocess could still be alive — holding the event loop open — well
|
|
24
|
+
// after the module that triggered it finished loading. This was the root
|
|
25
|
+
// cause package.json's --test-force-exit was added to paper over (see
|
|
26
|
+
// 5c17b6d) and was never actually fixed, only masked. Tests that need real
|
|
27
|
+
// agent discovery call agentsModule.refresh() themselves explicitly.
|
|
28
|
+
if (!process.env.NODE_TEST_CONTEXT) {
|
|
29
|
+
agentsModule.refresh().catch(function (e) {
|
|
30
|
+
console.error("[project-sessions] initial agent refresh failed:", e && e.message ? e.message : e);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
16
33
|
|
|
17
34
|
// Format a user's answer to an ask_user_questions card as a plain user
|
|
18
35
|
// message so the MCP path can feed it back to the agent on the next turn.
|
|
@@ -174,10 +191,17 @@ function attachSessions(ctx) {
|
|
|
174
191
|
catch (e) { /* recents are best-effort */ }
|
|
175
192
|
}
|
|
176
193
|
var newSess = sm.createSession(sessionOpts, ws);
|
|
177
|
-
// Seed per-session model/mode from
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
|
|
194
|
+
// Seed per-session model/mode from the project/global DEFAULT
|
|
195
|
+
// (sm._savedDefaultModel / sm._savedDefaultMode, populated at project
|
|
196
|
+
// startup from onGetProjectDefaultModel/onGetServerDefaultModel — see
|
|
197
|
+
// lib/project.js) so the first query uses the right values even before
|
|
198
|
+
// the user changes anything. Seeding from sm.currentModel/
|
|
199
|
+
// sm.currentPermissionMode directly is wrong (lr-db0437): those two
|
|
200
|
+
// fields also mirror whatever model/mode the CURRENTLY ACTIVE session
|
|
201
|
+
// happens to be using, so a brand-new session would inherit another
|
|
202
|
+
// session's in-progress choice instead of the actual saved default.
|
|
203
|
+
newSess.model = sm._savedDefaultModel || null;
|
|
204
|
+
newSess.permissionMode = sm._savedDefaultMode || null;
|
|
181
205
|
ws._clayActiveSession = newSess.localId;
|
|
182
206
|
// Apply project-level email defaults to new session
|
|
183
207
|
if (typeof ctx._email === "object" && ctx._email.getEmailDefaults) {
|
|
@@ -348,6 +372,21 @@ function attachSessions(ctx) {
|
|
|
348
372
|
return true;
|
|
349
373
|
}
|
|
350
374
|
|
|
375
|
+
// lr-13c047 (Badge A non-switch clear path): let a client dismiss the
|
|
376
|
+
// Projects-tab cross-project unread badge for a specific project without
|
|
377
|
+
// requiring a full switch/connect to that project — previously the only
|
|
378
|
+
// clear path was connect-time (lib/server.js onConnection) or the
|
|
379
|
+
// same-project switchSession zeroing. slug is validated against the
|
|
380
|
+
// live project registry indirectly: markCrossProjectRead only mutates
|
|
381
|
+
// this ws's own crossProjectUnread map, so an invalid/unknown slug is
|
|
382
|
+
// harmless (its prefix simply matches nothing).
|
|
383
|
+
if (msg.type === "mark_cross_project_read") {
|
|
384
|
+
if (opts && typeof opts.markCrossProjectRead === "function" && typeof msg.slug === "string" && msg.slug) {
|
|
385
|
+
opts.markCrossProjectRead(ws, msg.slug);
|
|
386
|
+
}
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
|
|
351
390
|
if (msg.type === "bulk_delete_sessions") {
|
|
352
391
|
if (!Array.isArray(msg.sessionIds) || msg.sessionIds.length === 0) return true;
|
|
353
392
|
var deletableIds = [];
|
|
@@ -536,8 +575,13 @@ function attachSessions(ctx) {
|
|
|
536
575
|
// Re-sync chip state to the incoming session's own model/mode.
|
|
537
576
|
// Sessions track their own model/permissionMode so the chip shows
|
|
538
577
|
// per-session values rather than the shared project state.
|
|
578
|
+
// lr-041af8: routed through the shared effectiveSessionModel() helper
|
|
579
|
+
// (sessions.js) instead of re-deriving the same session-model-first
|
|
580
|
+
// fallback here — this was the one sender that already had the
|
|
581
|
+
// precedence right; sharing it prevents a future sender from
|
|
582
|
+
// reintroducing the sm.currentModel-only bug this task fixes.
|
|
539
583
|
var _swSess = sm.sessions.get(msg.id);
|
|
540
|
-
var _swModel = (_swSess
|
|
584
|
+
var _swModel = sm.effectiveSessionModel(_swSess);
|
|
541
585
|
var _swMode = (_swSess && _swSess.permissionMode) || sm.currentPermissionMode || "default";
|
|
542
586
|
sendTo(ws, { type: "config_state", model: _swModel, mode: _swMode, effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
|
|
543
587
|
var swPresKey = ws._clayUser ? ws._clayUser.id : "_default";
|
|
@@ -649,6 +693,18 @@ function attachSessions(ctx) {
|
|
|
649
693
|
memAvailableMB: memAvailMB,
|
|
650
694
|
activeLiveCount: memStats.activeLiveCount !== undefined ? memStats.activeLiveCount : null,
|
|
651
695
|
maxConcurrentSessions: memStats.maxConcurrentSessions !== undefined ? memStats.maxConcurrentSessions : null,
|
|
696
|
+
// lr-58c813: baseline instrumentation for the lr-5edd64 redesign —
|
|
697
|
+
// count of session.isProcessing !== sessionActivity.isSessionActive(session)
|
|
698
|
+
// divergences observed since daemon start, plus a bounded ring
|
|
699
|
+
// buffer of the most recent occurrences. Read-only counter; does not
|
|
700
|
+
// reflect or affect what any renderer displays. Samples carry no
|
|
701
|
+
// session identifier (BOBBIE finding): this handler has no
|
|
702
|
+
// admin/role gate, unlike its update_now/kill_process siblings, so
|
|
703
|
+
// any authenticated client on a shared project could otherwise read
|
|
704
|
+
// another user's session id through it. Fixing that pre-existing
|
|
705
|
+
// gate gap is out of scope for this instrumentation-only PR.
|
|
706
|
+
activityDivergenceCount: memStats.activityDivergenceCount !== undefined ? memStats.activityDivergenceCount : null,
|
|
707
|
+
activityDivergenceRecentSamples: memStats.activityDivergenceRecentSamples || [],
|
|
652
708
|
});
|
|
653
709
|
return true;
|
|
654
710
|
}
|
|
@@ -703,9 +759,30 @@ function attachSessions(ctx) {
|
|
|
703
759
|
if (msg.type === "set_model" && msg.model) {
|
|
704
760
|
var session = getSessionForWs(ws);
|
|
705
761
|
if (session) {
|
|
706
|
-
sdk.setModel(session, msg.model).then(function () {
|
|
762
|
+
sdk.setModel(session, msg.model).then(function (result) {
|
|
763
|
+
// lr-f22787: sdk.setModel now reports { ok, error } instead of
|
|
764
|
+
// always resolving as if the switch succeeded (it used to swallow
|
|
765
|
+
// an invalid/unentitled model ID with no signal back to the
|
|
766
|
+
// requesting client — see sdk-bridge.js's setModel). A missing
|
|
767
|
+
// `result` (older/no-op session-not-active branch) is still ok.
|
|
768
|
+
if (result && result.ok === false) {
|
|
769
|
+
sendTo(ws, { type: "error", text: "Failed to switch model: " + result.error });
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
// lr-db0437: persist session.model to disk (meta line) so a
|
|
773
|
+
// daemon restart resumes with the same model instead of falling
|
|
774
|
+
// back to the project/global default (acceptance criterion:
|
|
775
|
+
// "session picked model X, daemon restarts, session still uses X").
|
|
776
|
+
sm.saveSessionFile(session);
|
|
707
777
|
// Targeted reply — only this client's chip updates, not all sessions.
|
|
708
|
-
|
|
778
|
+
// lr-041af8: shared helper (see switch_session above and
|
|
779
|
+
// effectiveSessionModel() in sessions.js).
|
|
780
|
+
sendTo(ws, { type: "config_state", model: sm.effectiveSessionModel(session), mode: session.permissionMode || sm.currentPermissionMode || "default", effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
|
|
781
|
+
}).catch(function (e) {
|
|
782
|
+
// Defensive: setModel is not expected to reject (its own try/catch
|
|
783
|
+
// returns { ok: false } instead), but a rejection must still reach
|
|
784
|
+
// the client rather than vanish silently.
|
|
785
|
+
sendTo(ws, { type: "error", text: "Failed to switch model: " + (e.message || e) });
|
|
709
786
|
});
|
|
710
787
|
}
|
|
711
788
|
return true;
|
|
@@ -724,6 +801,13 @@ function attachSessions(ctx) {
|
|
|
724
801
|
" is bound to '" + vendorSession.vendor + "', refused rebind to '" + msg.vendor + "'");
|
|
725
802
|
} else {
|
|
726
803
|
vendorSession.vendor = msg.vendor;
|
|
804
|
+
// lr-041af8: clear THIS session's own model too, not just the
|
|
805
|
+
// shared sm.currentModel below — the old model belongs to the old
|
|
806
|
+
// vendor and must not survive the rebind on the session itself
|
|
807
|
+
// (previously only sm.currentModel was cleared, so a session with
|
|
808
|
+
// its own persisted .model kept showing a foreign-vendor model ID
|
|
809
|
+
// after switching vendor).
|
|
810
|
+
vendorSession.model = null;
|
|
727
811
|
// Clear the shared model so the next query uses the vendor's default
|
|
728
812
|
// instead of leaking the previous vendor's model into a fresh session.
|
|
729
813
|
if (sm.currentModel) {
|
|
@@ -752,7 +836,15 @@ function attachSessions(ctx) {
|
|
|
752
836
|
availableVendors: sm.availableVendors || [],
|
|
753
837
|
installedVendors: sm.installedVendors || [],
|
|
754
838
|
});
|
|
755
|
-
|
|
839
|
+
// lr-041af8: targeted, not broadcast — set_vendor acts on the
|
|
840
|
+
// requesting client's own session (vendorSession above); broadcasting
|
|
841
|
+
// this reply to every connected client via send() previously stomped
|
|
842
|
+
// on every OTHER session's displayed model with this session's
|
|
843
|
+
// (now-cleared) model, the same cross-session bleed class this task
|
|
844
|
+
// fixes elsewhere. vendorSession may be null (no active session for
|
|
845
|
+
// this ws yet) — effectiveSessionModel handles that by falling back
|
|
846
|
+
// to the shared default, same as every other targeted sender.
|
|
847
|
+
sendTo(ws, { type: "config_state", model: sm.effectiveSessionModel(vendorSession), mode: sm.currentPermissionMode || "default", effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
|
|
756
848
|
}
|
|
757
849
|
return true;
|
|
758
850
|
}
|
|
@@ -761,10 +853,16 @@ function attachSessions(ctx) {
|
|
|
761
853
|
if (typeof opts.onSetServerDefaultModel === "function") {
|
|
762
854
|
opts.onSetServerDefaultModel(msg.model);
|
|
763
855
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
856
|
+
// lr-db0437: update the DEFAULT only — never the live session's model.
|
|
857
|
+
// A running session's model is set-in-stone until the user explicitly
|
|
858
|
+
// changes it via set_model; changing the server default must not
|
|
859
|
+
// silently retarget whatever session happens to be focused (that was
|
|
860
|
+
// the "reverse bleed" root cause this task fixes). sm.currentModel is
|
|
861
|
+
// consulted by new_session (this file) and by startQuery's fallback
|
|
862
|
+
// (sdk-bridge.js) as the project/global default.
|
|
863
|
+
sm.currentModel = msg.model;
|
|
864
|
+
sm._savedDefaultModel = msg.model;
|
|
865
|
+
send({ type: "config_state", model: sm.currentModel || "", mode: sm.currentPermissionMode || "default", effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
|
|
768
866
|
return true;
|
|
769
867
|
}
|
|
770
868
|
|
|
@@ -772,10 +870,10 @@ function attachSessions(ctx) {
|
|
|
772
870
|
if (typeof opts.onSetProjectDefaultModel === "function") {
|
|
773
871
|
opts.onSetProjectDefaultModel(slug, msg.model);
|
|
774
872
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
}
|
|
873
|
+
// lr-db0437: same as set_server_default_model above — default-only write.
|
|
874
|
+
sm.currentModel = msg.model;
|
|
875
|
+
sm._savedDefaultModel = msg.model;
|
|
876
|
+
send({ type: "config_state", model: sm.currentModel || "", mode: sm.currentPermissionMode || "default", effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
|
|
779
877
|
return true;
|
|
780
878
|
}
|
|
781
879
|
|
|
@@ -784,7 +882,8 @@ function attachSessions(ctx) {
|
|
|
784
882
|
if (session) {
|
|
785
883
|
sdk.setPermissionMode(session, msg.mode).then(function () {
|
|
786
884
|
// Targeted reply — only update the requesting client's chip.
|
|
787
|
-
|
|
885
|
+
// lr-041af8: shared helper (see effectiveSessionModel() in sessions.js).
|
|
886
|
+
sendTo(ws, { type: "config_state", model: sm.effectiveSessionModel(session), mode: session.permissionMode || "default", effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
|
|
788
887
|
});
|
|
789
888
|
}
|
|
790
889
|
return true;
|
|
@@ -1006,6 +1105,16 @@ function attachSessions(ctx) {
|
|
|
1006
1105
|
session.sentToolResults = {};
|
|
1007
1106
|
session.pendingPermissions = {};
|
|
1008
1107
|
session.pendingAskUser = {};
|
|
1108
|
+
// lr-9bcd7b: a rewind destroys the in-flight query outright (the
|
|
1109
|
+
// queryInstance null-out above), so nothing can genuinely still be
|
|
1110
|
+
// running for this session afterward. Unlike the reconciliation
|
|
1111
|
+
// sites in sdk-message-processor.js/sdk-bridge.js, isProcessing:false
|
|
1112
|
+
// here is correct even without consulting the registry -- but the
|
|
1113
|
+
// registry itself must still be reset wholesale (leak-resistance
|
|
1114
|
+
// layer 4: never merge stale pre-rewind tokens into the post-rewind
|
|
1115
|
+
// session), or a Task token acquired before the rewind would
|
|
1116
|
+
// linger and make a LATER query look active for the wrong reason.
|
|
1117
|
+
sessionActivity.replaceRegistry(session);
|
|
1009
1118
|
session.isProcessing = false;
|
|
1010
1119
|
onProcessingChanged();
|
|
1011
1120
|
|
|
@@ -1324,7 +1433,10 @@ function attachSessions(ctx) {
|
|
|
1324
1433
|
if (decision === "allow" || decision === "allow_always") {
|
|
1325
1434
|
if (decision === "allow_always") {
|
|
1326
1435
|
if (!session.allowedTools) session.allowedTools = {};
|
|
1327
|
-
|
|
1436
|
+
// lr-f969dc: keyed on toolName + input discriminator (not bare
|
|
1437
|
+
// toolName) so a Skill grant scopes to the specific skill that was
|
|
1438
|
+
// actually approved rather than silently authorizing every skill.
|
|
1439
|
+
session.allowedTools[utils.permissionGrantKey(pending.toolName, pending.toolInput)] = true;
|
|
1328
1440
|
// Flush immediately (lr-8b2e) so the grant survives daemon restart /
|
|
1329
1441
|
// resume-by-cliSessionId rehydration even without a later save
|
|
1330
1442
|
// trigger — previously this lived only in the in-memory session
|