@clagentic/console 1.9.0-beta.1 → 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/project-connection.js +15 -2
- package/lib/project-loop.js +46 -2
- package/lib/project-sessions.js +31 -3
- package/lib/project-user-message.js +70 -3
- package/lib/project.js +7 -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/messages.css +11 -0
- package/lib/public/css/mobile-nav.css +22 -0
- package/lib/public/css/sidebar.css +15 -0
- package/lib/public/css/title-bar.css +10 -1
- package/lib/public/index.html +1 -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 +86 -2
- package/lib/public/modules/app-messages.js +118 -54
- package/lib/public/modules/app-panels.js +91 -32
- package/lib/public/modules/app-projects.js +28 -8
- package/lib/public/modules/app-rate-limit.js +13 -1
- 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 +11 -39
- package/lib/sdk-bridge.js +301 -22
- package/lib/sdk-message-processor.js +98 -15
- 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 +24 -22
- package/lib/session-activity.js +8 -1
- package/lib/sessions.js +47 -1
- package/lib/smtp.js +10 -1
- package/lib/ws-schema.js +16 -0
- package/lib/yoke/adapters/claude.js +7 -1
- package/lib/yoke/adapters/codex.js +219 -31
- package/package.json +2 -2
- package/scripts/check-test-count.js +397 -0
- package/scripts/test-file-completion-reporter.js +43 -0
- package/lib/model-context-windows.js +0 -74
- package/lib/public/modules/model-context-windows.js +0 -71
|
@@ -23,6 +23,9 @@ function attachMessageProcessor(ctx) {
|
|
|
23
23
|
var mergeSkills = ctx.mergeSkills;
|
|
24
24
|
var discoverSkillsWithMeta = ctx.discoverSkillsWithMeta;
|
|
25
25
|
var mergeSkillsWithMeta = ctx.mergeSkillsWithMeta;
|
|
26
|
+
// lr-3ccc78 — resolves the session owner's home on a shared multi-user
|
|
27
|
+
// daemon; returns null (falls back to REAL_HOME) in single-user mode.
|
|
28
|
+
var resolveSessionHome = ctx.resolveSessionHome || function () { return null; };
|
|
26
29
|
// Allows callers (and tests) to inject a mock; falls back to the real implementation.
|
|
27
30
|
var discoverWorkflowsFn = ctx.discoverWorkflows || discoverWorkflows;
|
|
28
31
|
|
|
@@ -67,9 +70,11 @@ function attachMessageProcessor(ctx) {
|
|
|
67
70
|
// turn-wide isProcessing=true covering ordinary tool activity implicitly --
|
|
68
71
|
// acquiring an explicit token here is how Codex activity becomes visible to
|
|
69
72
|
// the derived isProcessing/picker-dot path at all. Gated on
|
|
70
|
-
// session.vendor === "codex" so Claude's
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
+
// session.vendor === "codex" so this stays independent of Claude's own
|
|
74
|
+
// widened acquisition below (lr-6e20f7, block_stop) -- the two vendors
|
|
75
|
+
// acquire tokens through different yokeType branches (tool_start here vs.
|
|
76
|
+
// block_stop for Claude) and neither path double-acquires the other's
|
|
77
|
+
// tokens.
|
|
73
78
|
//
|
|
74
79
|
// Release happens on tool_result (per-token, matching Claude's tool_result
|
|
75
80
|
// release) OR at the turn's result event, which releases EVERY still-live
|
|
@@ -253,13 +258,16 @@ function attachMessageProcessor(ctx) {
|
|
|
253
258
|
|
|
254
259
|
// Cache slash_commands and model from CLI init message
|
|
255
260
|
if (parsed.yokeType === "init") {
|
|
256
|
-
|
|
261
|
+
// lr-3ccc78 — resolve THIS session's owner's home so skill discovery
|
|
262
|
+
// isn't the daemon's REAL_HOME for every user on a shared daemon.
|
|
263
|
+
var _initHome = resolveSessionHome(session);
|
|
264
|
+
var fsSkills = discoverSkillDirs(_initHome);
|
|
257
265
|
sm.skillNames = mergeSkills(parsed.skills, fsSkills);
|
|
258
266
|
sm.workflowMeta = discoverWorkflowsFn(cwd);
|
|
259
267
|
// Enriched skill metadata (lr-7d8d) — stored alongside skillNames for consumers
|
|
260
268
|
// that need description and type without breaking existing skillNames callers.
|
|
261
269
|
if (typeof discoverSkillsWithMeta === "function" && typeof mergeSkillsWithMeta === "function") {
|
|
262
|
-
var fsSkillsMeta = discoverSkillsWithMeta(cwd);
|
|
270
|
+
var fsSkillsMeta = discoverSkillsWithMeta(cwd, _initHome);
|
|
263
271
|
sm.skillMeta = mergeSkillsWithMeta(parsed.skills, fsSkillsMeta);
|
|
264
272
|
}
|
|
265
273
|
if (parsed.slashCommands) {
|
|
@@ -269,6 +277,7 @@ function attachMessageProcessor(ctx) {
|
|
|
269
277
|
discoverSkillsWithMeta: typeof discoverSkillsWithMeta === "function" ? discoverSkillsWithMeta : undefined,
|
|
270
278
|
mergeSkillsWithMeta: typeof mergeSkillsWithMeta === "function" ? mergeSkillsWithMeta : undefined,
|
|
271
279
|
discoverWorkflows: discoverWorkflowsFn,
|
|
280
|
+
homeOverride: _initHome,
|
|
272
281
|
};
|
|
273
282
|
var combined = buildEnrichedSlashCommands(parsed.slashCommands, cwd, _enrichFns);
|
|
274
283
|
sm.slashCommands = combined;
|
|
@@ -438,14 +447,23 @@ function attachMessageProcessor(ctx) {
|
|
|
438
447
|
try { input = JSON.parse(block.inputJson); } catch (e) {}
|
|
439
448
|
sendAndRecord(session, { type: "tool_executing", id: block.id, name: block.name, input: input });
|
|
440
449
|
|
|
450
|
+
// lr-6e20f7: acquire an activity token for EVERY Claude tool_use
|
|
451
|
+
// block, not only Task. Claude has turn-wide isProcessing coverage
|
|
452
|
+
// for ordinary tools (see the module-header comment), which is
|
|
453
|
+
// sufficient for the LOCAL viewing client's own turn-in-flight
|
|
454
|
+
// signal (store.processing) but not for the SERVER-side registry
|
|
455
|
+
// that drives every OTHER client's picker/sidebar dot — that
|
|
456
|
+
// registry previously only saw a live token for a backgrounded
|
|
457
|
+
// Task, so a plain Bash/Read/Edit call was invisible to it. Released
|
|
458
|
+
// at the same block below (whichever tool ends up there) OR at the
|
|
459
|
+
// 'message' handler's tool_result content-array scan below
|
|
460
|
+
// (releaseActivity is idempotent either way).
|
|
461
|
+
acquireActivity(session, block.id, { source: "tool", label: input.description || block.name || "" });
|
|
462
|
+
|
|
441
463
|
// Track active Task tools for sub-agent done detection
|
|
442
464
|
if (block.name === "Task") {
|
|
443
465
|
if (!session.activeTaskToolIds) session.activeTaskToolIds = {};
|
|
444
466
|
session.activeTaskToolIds[block.id] = true;
|
|
445
|
-
// lr-9bcd7b: acquire an activity token for the lifetime of this
|
|
446
|
-
// backgrounded Task — released at the tool_result / task_notification
|
|
447
|
-
// drain paths below (whichever fires first for this same block.id).
|
|
448
|
-
acquireActivity(session, block.id, { source: "task", label: input.description || "" });
|
|
449
467
|
}
|
|
450
468
|
|
|
451
469
|
if (pushModule && block.name === "AskUserQuestion" && input.questions) {
|
|
@@ -523,10 +541,15 @@ function attachMessageProcessor(ctx) {
|
|
|
523
541
|
});
|
|
524
542
|
delete session.activeTaskToolIds[block.tool_use_id];
|
|
525
543
|
}
|
|
526
|
-
// lr-9bcd7b: release the activity token
|
|
527
|
-
// this tool id, unconditionally --
|
|
528
|
-
// still containing the entry.
|
|
529
|
-
//
|
|
544
|
+
// lr-9bcd7b (widened lr-6e20f7): release the activity token
|
|
545
|
+
// acquired at block_stop for this tool id, unconditionally --
|
|
546
|
+
// NOT gated on activeTaskToolIds still containing the entry.
|
|
547
|
+
// This covers every tool now (lr-6e20f7 widened acquisition
|
|
548
|
+
// beyond Task), not only backgrounded Task tools -- the
|
|
549
|
+
// Task-specific bookkeeping above (activeTaskToolIds,
|
|
550
|
+
// subagent_done) is unrelated to this release and unaffected by
|
|
551
|
+
// the widening. The 'result' handler's pre-existing lr-9d4b
|
|
552
|
+
// cleanup (retainPreservedTaskBookkeeping) already trims
|
|
530
553
|
// activeTaskToolIds down to only Task ids with a preserved
|
|
531
554
|
// permission on EVERY result, so a Task with no pending permission
|
|
532
555
|
// of its own has its activeTaskToolIds entry deleted before this
|
|
@@ -759,8 +782,14 @@ function attachMessageProcessor(ctx) {
|
|
|
759
782
|
session.streamedText = false;
|
|
760
783
|
sm.broadcastSessionList();
|
|
761
784
|
|
|
762
|
-
// Auto-generate title after N turns (skip if loop or already auto-generated)
|
|
763
|
-
|
|
785
|
+
// Auto-generate title after N turns (skip if loop or already auto-generated).
|
|
786
|
+
// lr-62157d: '===' -> '>=' so a session that skips past the exact
|
|
787
|
+
// threshold turn (early return, error path, non-result terminal event,
|
|
788
|
+
// or a turnCount that was never persisted before this fix) still gets
|
|
789
|
+
// titled on a later turn instead of being permanently disqualified.
|
|
790
|
+
// Idempotence comes from !session.titleAutoGenerated, which is now
|
|
791
|
+
// durable (see sessions.js buildMetaLine/loadSessions).
|
|
792
|
+
if (session.turnCount >= AUTO_TITLE_TURN_THRESHOLD
|
|
764
793
|
&& !session.titleAutoGenerated
|
|
765
794
|
&& !session.titleManuallySet
|
|
766
795
|
&& !session.loop
|
|
@@ -768,6 +797,46 @@ function attachMessageProcessor(ctx) {
|
|
|
768
797
|
try { onAutoTitle(session); } catch (e) {
|
|
769
798
|
console.error("[auto-title] onAutoTitle threw:", e.message || e);
|
|
770
799
|
}
|
|
800
|
+
} else {
|
|
801
|
+
// lr-efdab6 (DRUMMER decision, comment #1): the taken branch above
|
|
802
|
+
// already logs on every path (sdk-bridge.js [auto-title] sites) — but
|
|
803
|
+
// logging existed on NOTHING that recorded the gate NOT firing, so
|
|
804
|
+
// silence read identically for "ran fine and logged nothing notable",
|
|
805
|
+
// "never invoked", and "invoked and died before the first log". That
|
|
806
|
+
// ambiguity is exactly what let lr-62157d's dead auto-title feature
|
|
807
|
+
// survive ~3 months / ~160 sessions undetected. This branch makes the
|
|
808
|
+
// negative case unambiguous: every turn where the gate evaluates
|
|
809
|
+
// false gets exactly one line naming why.
|
|
810
|
+
//
|
|
811
|
+
// already_auto_generated is the expected steady-state reason for the
|
|
812
|
+
// overwhelming majority of turns in a mature session (fires every
|
|
813
|
+
// turn after the session's title is set) and is logged at a lower
|
|
814
|
+
// level (console.debug) so a normal journald view isn't dominated by
|
|
815
|
+
// it; every other reason is diagnostic of a gate that should be
|
|
816
|
+
// firing but isn't, and stays at console.log so it is visible by
|
|
817
|
+
// default. Nothing here transmits session content — only flags/counts.
|
|
818
|
+
var _autoTitleReason;
|
|
819
|
+
if (!onAutoTitle) {
|
|
820
|
+
_autoTitleReason = "no_callback";
|
|
821
|
+
} else if (session.loop) {
|
|
822
|
+
_autoTitleReason = "loop_running";
|
|
823
|
+
} else if (session.titleManuallySet) {
|
|
824
|
+
_autoTitleReason = "manually_set";
|
|
825
|
+
} else if (session.titleAutoGenerated) {
|
|
826
|
+
_autoTitleReason = "already_auto_generated";
|
|
827
|
+
} else if (session.turnCount < AUTO_TITLE_TURN_THRESHOLD) {
|
|
828
|
+
_autoTitleReason = "turn_threshold_not_met";
|
|
829
|
+
} else {
|
|
830
|
+
_autoTitleReason = "unknown";
|
|
831
|
+
}
|
|
832
|
+
var _autoTitleLogFn = (_autoTitleReason === "already_auto_generated") ? console.debug : console.log;
|
|
833
|
+
_autoTitleLogFn(
|
|
834
|
+
"[auto-title] gate did not fire: reason=" + _autoTitleReason
|
|
835
|
+
+ " turnCount=" + session.turnCount
|
|
836
|
+
+ " titleAutoGenerated=" + !!session.titleAutoGenerated
|
|
837
|
+
+ " titleManuallySet=" + !!session.titleManuallySet
|
|
838
|
+
+ " loop=" + !!session.loop
|
|
839
|
+
);
|
|
771
840
|
}
|
|
772
841
|
|
|
773
842
|
if (onTurnDone) {
|
|
@@ -779,6 +848,20 @@ function attachMessageProcessor(ctx) {
|
|
|
779
848
|
sendAndRecord(session, { type: "compacting", active: true });
|
|
780
849
|
} else if (session.compacting) {
|
|
781
850
|
sendAndRecord(session, { type: "compacting", active: false });
|
|
851
|
+
// lr-3af675: compaction just finished (session.compacting true ->
|
|
852
|
+
// this transition). Re-read vendor-reported usage now instead of
|
|
853
|
+
// leaving the context meter pinned at its pre-compact figure until
|
|
854
|
+
// the next turn's 'result' event — the provider has already
|
|
855
|
+
// self-corrected its own usage accounting at this point, we just
|
|
856
|
+
// never asked. Fire-and-forget, same pattern as the 'result' handler.
|
|
857
|
+
if (session.queryInstance && typeof session.queryInstance.getContextUsage === "function") {
|
|
858
|
+
session.queryInstance.getContextUsage().then(function(ctxUsage) {
|
|
859
|
+
session.lastContextUsage = ctxUsage;
|
|
860
|
+
sendToSession(session, { type: "context_usage", data: ctxUsage });
|
|
861
|
+
}).catch(function(e) {
|
|
862
|
+
console.error("[sdk-bridge] post-compaction getContextUsage failed (non-fatal):", e.message || e);
|
|
863
|
+
});
|
|
864
|
+
}
|
|
782
865
|
}
|
|
783
866
|
session.compacting = parsed.status === "compacting";
|
|
784
867
|
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
var fs = require("fs");
|
|
2
2
|
var path = require("path");
|
|
3
3
|
|
|
4
|
+
// Two-stage containment check mirroring project.js's safePath: a directory
|
|
5
|
+
// entry name from readdirSync can be a symlink, so a lexical path.resolve
|
|
6
|
+
// check alone (entry.name embedded in a path string that lexically stays
|
|
7
|
+
// under base) is NOT sufficient — the subsequent fs.accessSync/readFileSync
|
|
8
|
+
// on SKILL.md follows the symlink at read time, escaping base entirely.
|
|
9
|
+
// Stage 1 (lexical) rejects a literal ".." style escape before any syscall.
|
|
10
|
+
// Stage 2 (fs.realpathSync) resolves the symlink and re-checks containment
|
|
11
|
+
// against the REAL target, which is the check that actually defeats a
|
|
12
|
+
// symlinked directory entry pointing outside base. Returns the resolved
|
|
13
|
+
// real path on success, or null if entry escapes base or doesn't exist.
|
|
14
|
+
function resolveContainedSkillDir(base, entryName) {
|
|
15
|
+
var resolvedBase = path.resolve(base);
|
|
16
|
+
var lexical = path.resolve(resolvedBase, entryName);
|
|
17
|
+
if (lexical !== resolvedBase && lexical.indexOf(resolvedBase + path.sep) !== 0) return null;
|
|
18
|
+
try {
|
|
19
|
+
var real = fs.realpathSync(lexical);
|
|
20
|
+
if (real !== resolvedBase && real.indexOf(resolvedBase + path.sep) !== 0) return null;
|
|
21
|
+
return real;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
4
27
|
// Split shell command on operators (&&, ||, ;, |) while respecting quotes
|
|
5
28
|
// and parentheses. Returns array of command segments.
|
|
6
29
|
function splitShellSegments(cmd) {
|
|
@@ -197,9 +220,16 @@ function extractSkillDescription(skillDir) {
|
|
|
197
220
|
// skill directories. Reads every SKILL.md to extract a description.
|
|
198
221
|
// Project skills override global skills with the same name (global → project
|
|
199
222
|
// discovery order, last-write wins).
|
|
200
|
-
|
|
223
|
+
//
|
|
224
|
+
// homeOverride: optional. On a shared multi-user daemon, the caller resolves
|
|
225
|
+
// the SESSION OWNER's home (os-users.getLinuxUserHome(linuxUser)) and passes
|
|
226
|
+
// it here so the global skills dir is the invoking user's own ~/.claude/skills,
|
|
227
|
+
// not the daemon process's REAL_HOME (lr-3ccc78). Falls back to REAL_HOME when
|
|
228
|
+
// absent — the single-user / no-OS-isolation case, unchanged behavior.
|
|
229
|
+
function discoverSkillsWithMeta(cwd, homeOverride) {
|
|
230
|
+
var globalHome = homeOverride || require("./config").REAL_HOME;
|
|
201
231
|
var dirs = [
|
|
202
|
-
path.join(
|
|
232
|
+
path.join(globalHome, ".claude", "skills"),
|
|
203
233
|
path.join(cwd, ".claude", "skills"),
|
|
204
234
|
];
|
|
205
235
|
// Ordered map so project skills override global skills
|
|
@@ -215,7 +245,8 @@ function discoverSkillsWithMeta(cwd) {
|
|
|
215
245
|
for (var i = 0; i < entries.length; i++) {
|
|
216
246
|
var entry = entries[i];
|
|
217
247
|
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
218
|
-
var skillDir =
|
|
248
|
+
var skillDir = resolveContainedSkillDir(base, entry.name);
|
|
249
|
+
if (!skillDir) continue;
|
|
219
250
|
var skillMdPath = path.join(skillDir, "SKILL.md");
|
|
220
251
|
try {
|
|
221
252
|
fs.accessSync(skillMdPath, fs.constants.R_OK);
|
|
@@ -271,10 +302,14 @@ function mergeSkillsWithMeta(sdkSkillNames, fsSkillsWithMeta) {
|
|
|
271
302
|
function attachSkillDiscovery(ctx) {
|
|
272
303
|
var cwd = ctx.cwd;
|
|
273
304
|
|
|
274
|
-
|
|
305
|
+
// homeOverride: optional per-call override (see discoverSkillsWithMeta
|
|
306
|
+
// above) so a caller can resolve the session owner's home instead of the
|
|
307
|
+
// daemon's REAL_HOME on a shared multi-user daemon (lr-3ccc78).
|
|
308
|
+
function discoverSkillDirs(homeOverride) {
|
|
275
309
|
var skills = {};
|
|
310
|
+
var globalHome = homeOverride || require("./config").REAL_HOME;
|
|
276
311
|
var dirs = [
|
|
277
|
-
path.join(
|
|
312
|
+
path.join(globalHome, ".claude", "skills"),
|
|
278
313
|
path.join(cwd, ".claude", "skills"),
|
|
279
314
|
];
|
|
280
315
|
for (var d = 0; d < dirs.length; d++) {
|
|
@@ -288,7 +323,8 @@ function attachSkillDiscovery(ctx) {
|
|
|
288
323
|
for (var i = 0; i < entries.length; i++) {
|
|
289
324
|
var entry = entries[i];
|
|
290
325
|
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
291
|
-
var skillDir =
|
|
326
|
+
var skillDir = resolveContainedSkillDir(base, entry.name);
|
|
327
|
+
if (!skillDir) continue;
|
|
292
328
|
var skillMd = path.join(skillDir, "SKILL.md");
|
|
293
329
|
try {
|
|
294
330
|
fs.accessSync(skillMd, fs.constants.R_OK);
|
|
@@ -326,4 +362,8 @@ module.exports = {
|
|
|
326
362
|
extractSkillDescription: extractSkillDescription,
|
|
327
363
|
discoverSkillsWithMeta: discoverSkillsWithMeta,
|
|
328
364
|
mergeSkillsWithMeta: mergeSkillsWithMeta,
|
|
365
|
+
// Exported so other skill-discovery consumers (yoke/adapters/codex.js)
|
|
366
|
+
// reuse the same two-stage (lexical + realpath) containment check instead
|
|
367
|
+
// of approximating it — see the function's own doc comment.
|
|
368
|
+
resolveContainedSkillDir: resolveContainedSkillDir,
|
|
329
369
|
};
|
|
@@ -12,7 +12,9 @@ var _defaultDiscoverWorkflows = require('./sdk-workflow-discovery').discoverWork
|
|
|
12
12
|
//
|
|
13
13
|
// The optional third argument `fns` allows callers to inject alternative
|
|
14
14
|
// discovery functions — used by sdk-message-processor.js to pass its
|
|
15
|
-
// context-injected mocks so tests remain hermetic.
|
|
15
|
+
// context-injected mocks so tests remain hermetic. `fns.homeOverride`
|
|
16
|
+
// (lr-3ccc78) is forwarded to discoverSkillsWithMeta as the global skills
|
|
17
|
+
// home for a shared multi-user daemon — see that function's own doc comment.
|
|
16
18
|
//
|
|
17
19
|
// Both discovery calls are wrapped in try/catch so a missing .claude directory
|
|
18
20
|
// on disk never prevents slash commands from reaching the frontend.
|
|
@@ -20,9 +22,10 @@ function buildEnrichedSlashCommands(cliSlashCommands, cwd, fns) {
|
|
|
20
22
|
var discoverSkillsWithMeta = (fns && fns.discoverSkillsWithMeta) || _defaultDiscoverSkillsWithMeta;
|
|
21
23
|
var mergeSkillsWithMeta = (fns && fns.mergeSkillsWithMeta) || _defaultMergeSkillsWithMeta;
|
|
22
24
|
var discoverWorkflows = (fns && fns.discoverWorkflows) || _defaultDiscoverWorkflows;
|
|
25
|
+
var homeOverride = (fns && fns.homeOverride) || null;
|
|
23
26
|
|
|
24
27
|
var fsSkillsMeta = [];
|
|
25
|
-
try { fsSkillsMeta = discoverSkillsWithMeta(cwd); } catch (e) {}
|
|
28
|
+
try { fsSkillsMeta = discoverSkillsWithMeta(cwd, homeOverride); } catch (e) {}
|
|
26
29
|
var skillMeta = [];
|
|
27
30
|
try { skillMeta = mergeSkillsWithMeta([], fsSkillsMeta); } catch (e) {}
|
|
28
31
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Extracted from lib/server.js's addProject() closure (lr-c4da07 rework) so
|
|
2
|
+
// the Home Hub recent-sessions access filter is directly unit-testable
|
|
3
|
+
// against real code, not a test-file reimplementation of its loop shape.
|
|
4
|
+
// lib/server.js's getAllProjectSessions is now a thin call into
|
|
5
|
+
// computeAllProjectSessions below; both production and test code call this
|
|
6
|
+
// same function.
|
|
7
|
+
|
|
8
|
+
// Gathers every session across every project the given user may access,
|
|
9
|
+
// annotated with project metadata, for the Home Hub recent-sessions list.
|
|
10
|
+
//
|
|
11
|
+
// userId: REQUIRED to filter results to what the viewing user may actually
|
|
12
|
+
// see. Fails CLOSED: no userId (or no onGetProjectAccess) means no sessions
|
|
13
|
+
// are returned. There is no legitimate no-auth caller of this function --
|
|
14
|
+
// the WS upgrade handler in lib/server.js rejects any connection without an
|
|
15
|
+
// authenticated user with 401 before ws._clayUser can ever be set, including
|
|
16
|
+
// in single-user/PIN mode (still a real authenticated user, just one
|
|
17
|
+
// account) -- so failing closed here never breaks a real deployment mode.
|
|
18
|
+
//
|
|
19
|
+
// deps:
|
|
20
|
+
// projects Map<slug, projectCtx> (or anything with .forEach(fn(ctx, slug)))
|
|
21
|
+
// users the users module (canAccessProject / canAccessSession)
|
|
22
|
+
// onGetProjectAccess function(slug) -> access object | {error} | falsy
|
|
23
|
+
// callerSlug the connecting project's own slug (for includeSelf skip)
|
|
24
|
+
// includeSelf when true, callerSlug's own sessions are included too
|
|
25
|
+
// userId the viewing user's id, or null/undefined to fail closed
|
|
26
|
+
function computeAllProjectSessions(deps) {
|
|
27
|
+
var projects = deps.projects;
|
|
28
|
+
var users = deps.users;
|
|
29
|
+
var onGetProjectAccess = deps.onGetProjectAccess;
|
|
30
|
+
var callerSlug = deps.callerSlug;
|
|
31
|
+
var includeSelf = deps.includeSelf;
|
|
32
|
+
var userId = deps.userId;
|
|
33
|
+
|
|
34
|
+
var allSessions = [];
|
|
35
|
+
if (!userId || !onGetProjectAccess) return allSessions;
|
|
36
|
+
|
|
37
|
+
projects.forEach(function (pCtx, pSlug) {
|
|
38
|
+
if (!includeSelf && pSlug === callerSlug) return; // skip self unless asked
|
|
39
|
+
var status = pCtx.getStatus();
|
|
40
|
+
if (status.isWorktree) return;
|
|
41
|
+
var pSm = pCtx.getSessionManager();
|
|
42
|
+
if (!pSm) return;
|
|
43
|
+
// Resolve per-project access ONCE per project (hoisted out of the
|
|
44
|
+
// per-session inner loop below, not re-resolved per session) and skip
|
|
45
|
+
// the whole project up front if the user cannot access it at all --
|
|
46
|
+
// avoids an O(projects * sessions) repeated-resolution pattern for a
|
|
47
|
+
// value that does not vary per session.
|
|
48
|
+
var access = onGetProjectAccess(pSlug);
|
|
49
|
+
if (!access || access.error) return;
|
|
50
|
+
if (!users.canAccessProject(userId, access)) return;
|
|
51
|
+
var projectTitle = status.title || status.project || pSlug;
|
|
52
|
+
var projectIcon = status.icon || null;
|
|
53
|
+
pSm.sessions.forEach(function (s) {
|
|
54
|
+
if (!s.hidden && users.canAccessSession(userId, s, access)) {
|
|
55
|
+
// Push a shallow copy annotated with project metadata rather than
|
|
56
|
+
// mutating the live session object with transient UI fields.
|
|
57
|
+
allSessions.push(Object.assign({}, s, {
|
|
58
|
+
_projectTitle: projectTitle,
|
|
59
|
+
_projectSlug: pSlug,
|
|
60
|
+
_projectIcon: projectIcon,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return allSessions;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
computeAllProjectSessions: computeAllProjectSessions,
|
|
70
|
+
};
|
package/lib/server.js
CHANGED
|
@@ -18,6 +18,7 @@ var { CONFIG_DIR } = require("./config");
|
|
|
18
18
|
var { provisionLinuxUser } = require("./os-users");
|
|
19
19
|
var { detectLite } = require("./lite-detect");
|
|
20
20
|
var { readCappedBody } = require("./utils");
|
|
21
|
+
var { computeAllProjectSessions } = require("./server-hub-sessions");
|
|
21
22
|
|
|
22
23
|
var https = require("https");
|
|
23
24
|
var pkg = require("../package.json");
|
|
@@ -1286,29 +1287,30 @@ function createServer(opts) {
|
|
|
1286
1287
|
// recent-sessions list uses this to gather every project identically —
|
|
1287
1288
|
// matching the palette's behavior — so the global recency sort is honest
|
|
1288
1289
|
// and the currently-connected project doesn't dominate the result.
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1290
|
+
//
|
|
1291
|
+
// userId: REQUIRED to filter results to what the viewing user may
|
|
1292
|
+
// actually see. Unlike getProjectList/broadcastProcessingChange (which
|
|
1293
|
+
// the identical onGetProjectAccess + users.canAccessProject gate above
|
|
1294
|
+
// already protects), this function previously took no userId at all
|
|
1295
|
+
// and filtered only on `!s.hidden` -- it structurally could not
|
|
1296
|
+
// enforce per-project access or private-session visibility, leaking
|
|
1297
|
+
// cross-project and private sessions into the Home Hub recent-sessions
|
|
1298
|
+
// list. Fails CLOSED: no userId (or no onGetProjectAccess wiring) means
|
|
1299
|
+
// no sessions are returned. There is no legitimate no-auth caller of
|
|
1300
|
+
// this function -- the WS upgrade handler above rejects any connection
|
|
1301
|
+
// without an authenticated user (wsAuthedUser) with 401 before
|
|
1302
|
+
// ws._clayUser can ever be set, including in single-user/PIN mode
|
|
1303
|
+
// (still a real authenticated user, just one account) -- so failing
|
|
1304
|
+
// closed here never breaks a real deployment mode.
|
|
1305
|
+
getAllProjectSessions: function (includeSelf, userId) {
|
|
1306
|
+
return computeAllProjectSessions({
|
|
1307
|
+
projects: projects,
|
|
1308
|
+
users: users,
|
|
1309
|
+
onGetProjectAccess: onGetProjectAccess,
|
|
1310
|
+
callerSlug: slug,
|
|
1311
|
+
includeSelf: includeSelf,
|
|
1312
|
+
userId: userId,
|
|
1310
1313
|
});
|
|
1311
|
-
return allSessions;
|
|
1312
1314
|
},
|
|
1313
1315
|
getHubSchedules: function () {
|
|
1314
1316
|
var allSchedules = [];
|
package/lib/session-activity.js
CHANGED
|
@@ -73,7 +73,14 @@
|
|
|
73
73
|
*/
|
|
74
74
|
function createRegistry() {
|
|
75
75
|
return {
|
|
76
|
-
|
|
76
|
+
// lr-66c118 (fold-in, flagged by BOBBIE on 2/4 and 3/4): tokens is
|
|
77
|
+
// written by bracket assignment (registry.tokens[token] = ...) keyed by
|
|
78
|
+
// SDK/Codex-supplied ids with no prototype guard. Object.create(null)
|
|
79
|
+
// removes the Object.prototype chain so a crafted token id (e.g.
|
|
80
|
+
// "__proto__" or "constructor") cannot collide with an inherited
|
|
81
|
+
// property/method. Session-scoped, no demonstrated exploit — cheap
|
|
82
|
+
// hardening, not a response to a live vulnerability.
|
|
83
|
+
tokens: Object.create(null), // token -> { source, label, startedAt, generation }
|
|
77
84
|
generation: 0,
|
|
78
85
|
};
|
|
79
86
|
}
|
package/lib/sessions.js
CHANGED
|
@@ -35,6 +35,26 @@ function effectiveSessionModel(session, sm) {
|
|
|
35
35
|
return (sm && sm.currentModel) || "";
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// Message types whose client-side handler writes the global client-local
|
|
39
|
+
// 'processing'/'sessionIsProcessing' edge latch (app-messages.js's status/
|
|
40
|
+
// done/auth_required handlers). Stamping localId at the shared send choke
|
|
41
|
+
// points (doSendToSession/doSendAndRecord below, and project.js's own
|
|
42
|
+
// sendToSession/sendToSessionOthers which reuse this same list) means every
|
|
43
|
+
// one of the ~15 status/done/auth_required send sites across sessions.js/
|
|
44
|
+
// project.js/project-loop.js/sdk-bridge.js gets session-scoping for free,
|
|
45
|
+
// mirroring the existing scheduled_message_queued/sent localId pattern
|
|
46
|
+
// (project.js), without widening this to every message type — most types
|
|
47
|
+
// are already inherently session-scoped by their own handler logic and
|
|
48
|
+
// don't need it.
|
|
49
|
+
var ACTIVITY_LATCH_TYPES = { status: true, done: true, auth_required: true };
|
|
50
|
+
|
|
51
|
+
function stampActivityLocalId(session, obj) {
|
|
52
|
+
if (ACTIVITY_LATCH_TYPES[obj.type] && obj.localId === undefined) {
|
|
53
|
+
obj.localId = (session && session.localId !== undefined) ? session.localId : session;
|
|
54
|
+
}
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
|
|
38
58
|
function createSessionManager(opts) {
|
|
39
59
|
var cwd = opts.cwd;
|
|
40
60
|
var send = opts.send; // function(obj) - broadcast to all clients
|
|
@@ -130,6 +150,22 @@ function createSessionManager(opts) {
|
|
|
130
150
|
metaObj.pendingAutoResume = true;
|
|
131
151
|
if (session.pendingAutoResumeReason) metaObj.pendingAutoResumeReason = session.pendingAutoResumeReason;
|
|
132
152
|
}
|
|
153
|
+
// lr-62157d: durable auto-title state. Without this, titleAutoGenerated
|
|
154
|
+
// and titleManuallySet lived in memory only — every daemon restart reset
|
|
155
|
+
// both to false, so the "already auto-titled" / "user renamed it" guards
|
|
156
|
+
// at sdk-message-processor.js and sdk-bridge.js were guarding against
|
|
157
|
+
// state that could never actually be true after a restart. turnCount is
|
|
158
|
+
// persisted alongside them because the turn-threshold gate (see the
|
|
159
|
+
// '>=' fix at sdk-message-processor.js) depends on it surviving too —
|
|
160
|
+
// a restarted session that lost its turn count would silently miss the
|
|
161
|
+
// auto-title window forever instead of catching up on a later turn.
|
|
162
|
+
// titleProvisional marks a title set from the raw first-message
|
|
163
|
+
// truncation (project-user-message.js) so autoGenerateTitle knows it is
|
|
164
|
+
// safe to overwrite even though the flags above look "not yet set".
|
|
165
|
+
if (session.titleAutoGenerated) metaObj.titleAutoGenerated = true;
|
|
166
|
+
if (session.titleManuallySet) metaObj.titleManuallySet = true;
|
|
167
|
+
if (session.titleProvisional) metaObj.titleProvisional = true;
|
|
168
|
+
if (typeof session.turnCount === "number" && session.turnCount > 0) metaObj.turnCount = session.turnCount;
|
|
133
169
|
return JSON.stringify(metaObj);
|
|
134
170
|
}
|
|
135
171
|
|
|
@@ -723,6 +759,14 @@ function createSessionManager(opts) {
|
|
|
723
759
|
session.pendingAutoResume = true;
|
|
724
760
|
session.pendingAutoResumeReason = m.pendingAutoResumeReason || null;
|
|
725
761
|
}
|
|
762
|
+
// lr-62157d: restore auto-title state across a daemon restart — see
|
|
763
|
+
// buildMetaLine's write side for why this must persist. Without this,
|
|
764
|
+
// the guards at sdk-message-processor.js/sdk-bridge.js always saw
|
|
765
|
+
// false/0 after a restart no matter what actually happened before it.
|
|
766
|
+
session.titleAutoGenerated = !!m.titleAutoGenerated;
|
|
767
|
+
session.titleManuallySet = !!m.titleManuallySet;
|
|
768
|
+
session.titleProvisional = !!m.titleProvisional;
|
|
769
|
+
session.turnCount = typeof m.turnCount === "number" ? m.turnCount : 0;
|
|
726
770
|
sessions.set(localId, session);
|
|
727
771
|
}
|
|
728
772
|
}
|
|
@@ -1240,6 +1284,7 @@ function createSessionManager(opts) {
|
|
|
1240
1284
|
}
|
|
1241
1285
|
|
|
1242
1286
|
function doSendToSession(session, obj) {
|
|
1287
|
+
stampActivityLocalId(session, obj);
|
|
1243
1288
|
// Send to active clients without recording to history/disk (ephemeral data)
|
|
1244
1289
|
if (sendEach) {
|
|
1245
1290
|
var data = JSON.stringify(obj);
|
|
@@ -1254,6 +1299,7 @@ function createSessionManager(opts) {
|
|
|
1254
1299
|
}
|
|
1255
1300
|
|
|
1256
1301
|
function doSendAndRecord(session, obj) {
|
|
1302
|
+
stampActivityLocalId(session, obj);
|
|
1257
1303
|
// Stamp every recorded message so history replay preserves original times
|
|
1258
1304
|
if (!obj._ts) obj._ts = Date.now();
|
|
1259
1305
|
// If history has not been loaded from disk yet, do not trigger a load just
|
|
@@ -1770,4 +1816,4 @@ function createSessionManager(opts) {
|
|
|
1770
1816
|
return _instance;
|
|
1771
1817
|
}
|
|
1772
1818
|
|
|
1773
|
-
module.exports = { createSessionManager, effectiveSessionModel };
|
|
1819
|
+
module.exports = { createSessionManager, effectiveSessionModel, stampActivityLocalId };
|
package/lib/smtp.js
CHANGED
|
@@ -183,7 +183,15 @@ function sendInviteEmail(email, inviteUrl, inviterName) {
|
|
|
183
183
|
|
|
184
184
|
// --- Cleanup expired OTPs ---
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
// lr-795882: unref()'d — matches the equivalent ws-ticket sweep in
|
|
187
|
+
// server-auth.js (wsTicketSweepInterval). This is a housekeeping sweep, not
|
|
188
|
+
// something that should keep the process alive on its own; leaving it
|
|
189
|
+
// ref'd meant every test that required this module (or re-required it after
|
|
190
|
+
// busting require.cache, as test/ws-ticket-auth-lr-de5fcb.test.js's
|
|
191
|
+
// makeAuth() helper does once per test) left a real, permanently-running
|
|
192
|
+
// setInterval handle on the event loop, blocking `node --test` from ever
|
|
193
|
+
// reaching idle without --test-force-exit.
|
|
194
|
+
var _otpCleanupInterval = setInterval(function () {
|
|
187
195
|
var now = Date.now();
|
|
188
196
|
var keys = Object.keys(otpStore);
|
|
189
197
|
for (var i = 0; i < keys.length; i++) {
|
|
@@ -192,6 +200,7 @@ setInterval(function () {
|
|
|
192
200
|
}
|
|
193
201
|
}
|
|
194
202
|
}, 60000);
|
|
203
|
+
if (_otpCleanupInterval.unref) _otpCleanupInterval.unref();
|
|
195
204
|
|
|
196
205
|
module.exports = {
|
|
197
206
|
getSmtpConfig: getSmtpConfig,
|
package/lib/ws-schema.js
CHANGED
|
@@ -33,6 +33,10 @@ var schema = {
|
|
|
33
33
|
"fork_session": { direction: "c2s", handler: "lib/project-sessions.js", description: "Fork a session from a given message UUID" },
|
|
34
34
|
"input_sync": { direction: "c2s", handler: "lib/project-sessions.js", description: "Sync the current input field text to other clients" },
|
|
35
35
|
|
|
36
|
+
// lr-66c118: session_list items carry isProcessing/unread/ownerId — the
|
|
37
|
+
// exact fields lib/public/modules/activity-state.js's sessionActivity()
|
|
38
|
+
// derives every render surface's dot from. No new wire message type was
|
|
39
|
+
// added for "activity"; it is data already on this existing message.
|
|
36
40
|
"session_list": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Full list of sessions for the sidebar" },
|
|
37
41
|
"session_switched": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Confirmation that active session changed" },
|
|
38
42
|
"session_id": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "CLI session ID assigned to the current session" },
|
|
@@ -68,6 +72,13 @@ var schema = {
|
|
|
68
72
|
"message_uuid": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "UUID assigned to a user or assistant message" },
|
|
69
73
|
"prompt_suggestion": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Suggested follow-up prompt from the assistant" },
|
|
70
74
|
"context_preview": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Preview of context sources included in a query" },
|
|
75
|
+
// lr-66c118 fold-in: found missing from this schema by the new CI
|
|
76
|
+
// absence-invariant (test/activity-state-lr-66c118.test.js) that scans
|
|
77
|
+
// every real sendAndRecord(session, { type: "..." }) call site — these 4
|
|
78
|
+
// were live, sent types with no documentation entry.
|
|
79
|
+
"plan_content": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Plan-mode content for the plan card" },
|
|
80
|
+
"sdk_notification": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Informational notification surfaced from the vendor SDK" },
|
|
81
|
+
"diagnostic": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Session-scoped diagnostic toast (settings preflight, memory shedding, adapter warnings)" },
|
|
71
82
|
|
|
72
83
|
// -----------------------------------------------------------------------
|
|
73
84
|
// Thinking
|
|
@@ -98,6 +109,8 @@ var schema = {
|
|
|
98
109
|
"team_request_state": { direction: "c2s", handler: "lib/project-team.js", description: "Client requests current team snapshot" },
|
|
99
110
|
"task_started": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Background task started" },
|
|
100
111
|
"task_progress": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Background task progress update" },
|
|
112
|
+
// lr-66c118 fold-in: see the plan_content/sdk_notification/diagnostic note above.
|
|
113
|
+
"task_updated": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Background task status/description patch" },
|
|
101
114
|
|
|
102
115
|
// -----------------------------------------------------------------------
|
|
103
116
|
// Permissions
|
|
@@ -450,6 +463,9 @@ var schema = {
|
|
|
450
463
|
"hub_schedules_list": { direction: "c2s", handler: "lib/project-loop.js", description: "Request the hub schedules list" },
|
|
451
464
|
"hub_schedules": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Hub schedules list" },
|
|
452
465
|
"hub_recent_sessions_list": { direction: "c2s", handler: "lib/project-loop.js", description: "Request cross-project recent sessions for hub" },
|
|
466
|
+
// lr-66c118: each session item now also carries ownerId (added alongside
|
|
467
|
+
// isProcessing/unread) so the Home Hub Recent Sessions dot can render the
|
|
468
|
+
// multi-user 'other' tone via activity-state.js, same as session_list.
|
|
453
469
|
"hub_recent_sessions": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Cross-project recent sessions list for hub" },
|
|
454
470
|
"schedule_run_started": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A scheduled run has started" },
|
|
455
471
|
"schedule_run_finished": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A scheduled run has finished" },
|
|
@@ -91,7 +91,13 @@ function flattenEvent(raw) {
|
|
|
91
91
|
base.yokeType = "turn_start";
|
|
92
92
|
if (evt.message && evt.message.usage) {
|
|
93
93
|
var u = evt.message.usage;
|
|
94
|
-
|
|
94
|
+
// lr-3af675: input_tokens, cache_read_input_tokens, and
|
|
95
|
+
// cache_creation_input_tokens are disjoint (Anthropic prompt-caching
|
|
96
|
+
// docs) and all three occupy the context window. The input_tokens +
|
|
97
|
+
// cache_read_input_tokens sum was correct as far as it went;
|
|
98
|
+
// cache_creation_input_tokens was simply omitted, under-reporting
|
|
99
|
+
// context fill on cache-write-heavy turns.
|
|
100
|
+
base.inputTokens = (u.input_tokens || 0) + (u.cache_read_input_tokens || 0) + (u.cache_creation_input_tokens || 0);
|
|
95
101
|
}
|
|
96
102
|
return base;
|
|
97
103
|
}
|