@clagentic/console 1.10.0-beta.2 → 1.10.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/activity-clock.js +23 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +29 -0
- package/lib/cli-transcript-title.js +131 -0
- package/lib/daemon.js +5 -9
- package/lib/debug-log.js +17 -0
- package/lib/exit-flush.js +44 -0
- package/lib/grant-keys.js +66 -0
- package/lib/identity/config.js +118 -0
- package/lib/identity/contract.js +61 -0
- package/lib/identity/delivery.js +224 -0
- package/lib/identity/holder.js +87 -0
- package/lib/identity/index.js +229 -0
- package/lib/identity/jose.js +13 -0
- package/lib/identity/origin.js +28 -0
- package/lib/identity/owner.js +30 -0
- package/lib/identity/providers/gatekeeper.js +91 -0
- package/lib/identity/providers/jwks-self.js +85 -0
- package/lib/identity/providers/module.js +98 -0
- package/lib/identity/providers/signing-key.js +118 -0
- package/lib/identity/record.js +23 -0
- package/lib/identity/unavailable.js +29 -0
- package/lib/log-field.js +34 -0
- package/lib/project-http.js +2 -0
- package/lib/project-notifications.js +3 -0
- package/lib/project-prompt-responses.js +2 -1
- package/lib/project-session-grants.js +73 -0
- package/lib/project-sessions.js +12 -0
- package/lib/project-user-message.js +6 -5
- package/lib/project.js +2 -0
- package/lib/prompt-label.js +60 -0
- package/lib/prompt-registry.js +105 -10
- package/lib/prompt-source.js +65 -0
- package/lib/public/css/notifications-center.css +9 -0
- package/lib/public/css/overlays.css +18 -0
- package/lib/public/css/rewind.css +7 -0
- package/lib/public/modules/app-messages.js +3 -0
- package/lib/public/modules/app-notifications.js +5 -0
- package/lib/public/modules/build-notice-gate.js +73 -0
- package/lib/public/modules/diagnostics.js +43 -1
- package/lib/public/modules/prompt-label.js +44 -0
- package/lib/public/modules/prompts.js +9 -0
- package/lib/public/modules/session-grants.js +131 -0
- package/lib/public/modules/sidebar-sessions.js +11 -0
- package/lib/runtime-env.js +1 -1
- package/lib/sdk-bridge.js +135 -104
- package/lib/sdk-message-processor.js +14 -67
- package/lib/session-ai-title.js +80 -0
- package/lib/session-input.js +32 -2
- package/lib/sessions.js +21 -18
- package/lib/turn-initiator.js +29 -14
- package/lib/utils.js +5 -46
- package/lib/ws-schema.js +6 -3
- package/lib/yoke/adapters/claude-worker.js +5 -5
- package/lib/yoke/adapters/claude.js +5 -62
- package/lib/yoke/adapters/codex.js +4 -75
- package/lib/yoke/interface.js +3 -7
- package/package.json +3 -1
- package/scripts/vendor-identity-vectors.js +52 -0
package/lib/sdk-bridge.js
CHANGED
|
@@ -15,6 +15,7 @@ var { promptsFor } = require("./prompt-registry");
|
|
|
15
15
|
var { toolApprovalKind } = require("./prompt-kinds");
|
|
16
16
|
var sessionActivity = require("./session-activity");
|
|
17
17
|
var sessionReclaim = require("./session-reclaim");
|
|
18
|
+
var { withPromptLabel } = require("./prompt-label");
|
|
18
19
|
var { isAgentDispatchTool } = require("./agent-dispatch-tool");
|
|
19
20
|
var { getNewWorkRefusal } = require("./new-work-gate");
|
|
20
21
|
var runtimeEnv = require("./runtime-env");
|
|
@@ -23,6 +24,9 @@ var { registry: yokeRegistry } = require("./yoke");
|
|
|
23
24
|
var sessionCapabilities = require("./session-capabilities");
|
|
24
25
|
var { buildVendorRegistryMessage, recordInstallState } = require("./vendor-registry-message");
|
|
25
26
|
var { authRequiredFacts } = require("./vendor-auth");
|
|
27
|
+
var { bumpLastActivity } = require("./activity-clock");
|
|
28
|
+
var { logField } = require("./log-field");
|
|
29
|
+
var { createAiTitleRefresher } = require("./session-ai-title");
|
|
26
30
|
|
|
27
31
|
// --- lr-29f9: Global concurrent-session ceiling ---
|
|
28
32
|
// Counts queries that are actively running (startQuery entered, processQueryStream
|
|
@@ -429,6 +433,64 @@ function createSDKBridge(opts) {
|
|
|
429
433
|
return queryOptions;
|
|
430
434
|
}
|
|
431
435
|
|
|
436
|
+
// --- Identity surface (lib/identity) ---
|
|
437
|
+
// Everything here is inert unless the daemon configuration has an `identity`
|
|
438
|
+
// block: no module is loaded, no provider is asked, no file is made, and the
|
|
439
|
+
// query options carry no identity member.
|
|
440
|
+
var _identity = null;
|
|
441
|
+
function identityConfig() {
|
|
442
|
+
var cfg = typeof opts.getConfig === "function" ? opts.getConfig() : null;
|
|
443
|
+
return cfg ? cfg.identity : undefined;
|
|
444
|
+
}
|
|
445
|
+
function getIdentity() {
|
|
446
|
+
if (!_identity) {
|
|
447
|
+
_identity = require("./identity").createIdentity({
|
|
448
|
+
getConfig: identityConfig,
|
|
449
|
+
configDir: require("./config").CONFIG_DIR,
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return _identity;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// The identity lease of one agent process, or null when no provider is
|
|
456
|
+
// configured. `agent` is the persona agent the process runs as, if any.
|
|
457
|
+
async function beginIdentity(vendorId, agent, linuxUser, initiator) {
|
|
458
|
+
var identity = getIdentity();
|
|
459
|
+
if (!identity.isEnabled()) return null;
|
|
460
|
+
var owner = null;
|
|
461
|
+
if (linuxUser) {
|
|
462
|
+
var resolved = require("./identity/owner").resolveOwner(linuxUser, require("./os-users").resolveOsUserInfo, console.warn);
|
|
463
|
+
if (resolved.unresolved) {
|
|
464
|
+
return identity.declared(initiator, "owner_unresolved", "the session's OS user could not be looked up");
|
|
465
|
+
}
|
|
466
|
+
owner = resolved.owner;
|
|
467
|
+
}
|
|
468
|
+
return identity.begin({
|
|
469
|
+
definition: (agent && slugifyAgentName(agent)) || null,
|
|
470
|
+
initiator: initiator,
|
|
471
|
+
rt: vendorId === "claude" ? "claude-code" : vendorId,
|
|
472
|
+
owner: owner,
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// Puts the lease's record on the session and tells the person once when the
|
|
477
|
+
// provider could not supply an identity (not on every start that fails alike).
|
|
478
|
+
function recordIdentity(session, lease) {
|
|
479
|
+
var previous = session.identity || null;
|
|
480
|
+
session.identity = lease.record;
|
|
481
|
+
var unchanged = !!previous && JSON.stringify(previous) === JSON.stringify(lease.record);
|
|
482
|
+
if (lease.notice && !(previous && previous.unavailable === lease.record.unavailable)) {
|
|
483
|
+
sendAndRecord(session, { type: "diagnostic", severity: "warning", source: "identity", message: lease.notice });
|
|
484
|
+
}
|
|
485
|
+
if (!unchanged) sm.saveSessionFile(session);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function clearIdentityRecord(session) {
|
|
489
|
+
if (!session.identity) return;
|
|
490
|
+
delete session.identity;
|
|
491
|
+
sm.saveSessionFile(session);
|
|
492
|
+
}
|
|
493
|
+
|
|
432
494
|
// Tells each connected client the agent registry again, after something
|
|
433
495
|
// changed what it holds (a vendor's live capabilities were recorded). Install
|
|
434
496
|
// state is per OS identity, so the project supplies a sender that gives every
|
|
@@ -625,6 +687,7 @@ function createSDKBridge(opts) {
|
|
|
625
687
|
if (_idleReaperTimer) return;
|
|
626
688
|
_idleReaperTimer = setInterval(function () {
|
|
627
689
|
var now = Date.now();
|
|
690
|
+
var skippedForPrompt = [];
|
|
628
691
|
sm.sessions.forEach(function (session) {
|
|
629
692
|
if (session.destroying) return;
|
|
630
693
|
|
|
@@ -670,7 +733,12 @@ function createSDKBridge(opts) {
|
|
|
670
733
|
// emits no stream events, so the activity clock cannot tell. Ending
|
|
671
734
|
// it would abort the pending tool call and destroy the agent's work.
|
|
672
735
|
// Memory pressure is handled by lib/memory-shed.js, not this timer.
|
|
673
|
-
|
|
736
|
+
var openPrompts = promptsFor(sm).pendingCount(session);
|
|
737
|
+
if (openPrompts > 0) {
|
|
738
|
+
skippedForPrompt.push(logField(session.localId) + ":prompts=" + openPrompts
|
|
739
|
+
+ ":idle=" + Math.round((now - (session.lastActivityAt || 0)) / 60000) + "min");
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
674
742
|
|
|
675
743
|
var lastActivity = session.lastActivityAt || 0;
|
|
676
744
|
if (now - lastActivity > IDLE_TIMEOUT_MS) {
|
|
@@ -699,6 +767,13 @@ function createSDKBridge(opts) {
|
|
|
699
767
|
}
|
|
700
768
|
}
|
|
701
769
|
});
|
|
770
|
+
// One line per sweep, so "a session with an open prompt is never reaped"
|
|
771
|
+
// can be read from the journal rather than inferred from its absence.
|
|
772
|
+
if (skippedForPrompt.length) {
|
|
773
|
+
console.log("[sdk-bridge] Idle reaper: skipped " + skippedForPrompt.length
|
|
774
|
+
+ " session(s) with an open prompt: project=" + logField(slug)
|
|
775
|
+
+ " sessions=" + skippedForPrompt.join(","));
|
|
776
|
+
}
|
|
702
777
|
}, IDLE_CHECK_INTERVAL_MS);
|
|
703
778
|
// Don't prevent process exit
|
|
704
779
|
if (_idleReaperTimer.unref) _idleReaperTimer.unref();
|
|
@@ -717,82 +792,26 @@ function createSDKBridge(opts) {
|
|
|
717
792
|
var mergeSkills = skills.mergeSkills;
|
|
718
793
|
|
|
719
794
|
// --- Message processing (extracted to sdk-message-processor.js) ---
|
|
720
|
-
//
|
|
721
|
-
//
|
|
722
|
-
//
|
|
723
|
-
//
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
// user messages, fall back to a disk-backed full scan via
|
|
731
|
-
// loadFullSessionHistory + retrimHistory rather than silently under-titling
|
|
732
|
-
// with whatever partial set the trimmed heap happened to retain. The full
|
|
733
|
-
// load is never left resident — retrimHistory() re-applies the cap
|
|
734
|
-
// immediately after this function reads what it needs.
|
|
735
|
-
function autoGenerateTitle(session) {
|
|
736
|
-
var sessionAdapter = getAdapterForSession(session);
|
|
737
|
-
if (typeof sessionAdapter.generateTitle !== "function") {
|
|
738
|
-
console.log("[auto-title] adapter.generateTitle not available for vendor=" + sessionAdapter.vendor);
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
function collectUserMessages(history) {
|
|
742
|
-
var out = [];
|
|
743
|
-
for (var i = 0; i < history.length; i++) {
|
|
744
|
-
var entry = history[i];
|
|
745
|
-
if (entry.type === "user_message" && entry.text) {
|
|
746
|
-
out.push(entry.text.substring(0, 200));
|
|
747
|
-
if (out.length >= 5) break;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return out;
|
|
751
|
-
}
|
|
752
|
-
var userMessages = collectUserMessages(session.history);
|
|
753
|
-
if (userMessages.length < 5 && (session._historyBaseIndex || 0) > 0) {
|
|
754
|
-
sm.loadFullSessionHistory(session);
|
|
755
|
-
userMessages = collectUserMessages(session.history);
|
|
756
|
-
sm.retrimHistory(session);
|
|
757
|
-
}
|
|
758
|
-
if (userMessages.length === 0) {
|
|
759
|
-
console.log("[auto-title] No user messages found in session " + session.localId);
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
console.log("[auto-title] Calling adapter.generateTitle with " + userMessages.length + " messages for session " + session.localId);
|
|
763
|
-
|
|
764
|
-
// lr-62157d: returns the promise chain (previously fire-and-forget) so
|
|
765
|
-
// this is directly awaitable in tests via _test_autoGenerateTitle; the
|
|
766
|
-
// real onAutoTitle callers (sdk-message-processor.js) call this
|
|
767
|
-
// fire-and-forget already and are unaffected by a function now
|
|
768
|
-
// returning a value they don't use.
|
|
769
|
-
return sessionAdapter.generateTitle(userMessages, withRuntimeEnv({ cwd: cwd }, session)).then(function(title) {
|
|
770
|
-
if (!title || title.length < 2) return;
|
|
771
|
-
title = title.substring(0, 100);
|
|
772
|
-
// lr-62157d: overwrite whenever the current title is provisional (the
|
|
773
|
-
// raw first-message truncation from project-user-message.js, or no
|
|
774
|
-
// title at all) and the user hasn't manually renamed the session.
|
|
775
|
-
// Before titleProvisional existed, the first-message fallback looked
|
|
776
|
-
// exactly like a real title, so this guard had nothing that let it
|
|
777
|
-
// tell "already properly titled" apart from "still carrying the raw
|
|
778
|
-
// 50-char truncation" — this is what actually lets a real LLM title
|
|
779
|
-
// replace that truncation.
|
|
780
|
-
if ((session.titleProvisional || !session.title) && !session.titleManuallySet) {
|
|
781
|
-
session.title = title;
|
|
782
|
-
session.titleAutoGenerated = true;
|
|
783
|
-
session.titleProvisional = false;
|
|
784
|
-
sm.saveSessionFile(session);
|
|
785
|
-
sm.broadcastSessionList();
|
|
786
|
-
if (session.cliSessionId && typeof adapter.renameSession === "function") {
|
|
787
|
-
adapter.renameSession(session.cliSessionId, title, { dir: cwd }).catch(function () {});
|
|
788
|
-
}
|
|
789
|
-
console.log("[auto-title] Generated title for session " + session.localId + ": " + title);
|
|
790
|
-
}
|
|
791
|
-
}).catch(function(e) {
|
|
792
|
-
console.error("[auto-title] Failed:", e.message || e);
|
|
793
|
-
});
|
|
795
|
+
// The session title is the one the vendor CLI wrote into the session's
|
|
796
|
+
// transcript; no query is ever started to produce one (session-ai-title.js).
|
|
797
|
+
// The home is the session owner's on a shared multi-user daemon, null for the
|
|
798
|
+
// daemon's own.
|
|
799
|
+
function resolveOwnerHome(session) {
|
|
800
|
+
var ownerId = session && session.ownerId;
|
|
801
|
+
if (!ownerId) return null;
|
|
802
|
+
var owner = usersModule.findUserById(ownerId);
|
|
803
|
+
var ownerLinuxUser = owner && owner.linuxUser ? owner.linuxUser : null;
|
|
804
|
+
return resolveEffectiveHome(ownerLinuxUser);
|
|
794
805
|
}
|
|
795
806
|
|
|
807
|
+
var refreshAiTitle = createAiTitleRefresher({
|
|
808
|
+
sm: sm,
|
|
809
|
+
cwd: cwd,
|
|
810
|
+
resolveHome: resolveOwnerHome,
|
|
811
|
+
getRuntimeEnvOverlay: getRuntimeEnvOverlay,
|
|
812
|
+
daemonHome: require("./config").REAL_HOME || require("os").homedir(),
|
|
813
|
+
});
|
|
814
|
+
|
|
796
815
|
var msgProcessor = attachMessageProcessor({
|
|
797
816
|
sm: sm,
|
|
798
817
|
send: send,
|
|
@@ -803,7 +822,7 @@ function createSDKBridge(opts) {
|
|
|
803
822
|
adapter: adapter,
|
|
804
823
|
onProcessingChanged: onProcessingChanged,
|
|
805
824
|
onTurnDone: onTurnDone,
|
|
806
|
-
|
|
825
|
+
refreshAiTitle: refreshAiTitle,
|
|
807
826
|
onTeamCreate: opts.onTeamCreate || null,
|
|
808
827
|
onTeamDelete: opts.onTeamDelete || null,
|
|
809
828
|
opts: opts,
|
|
@@ -814,13 +833,7 @@ function createSDKBridge(opts) {
|
|
|
814
833
|
// lr-3ccc78 — session-owner home resolution for skill/agent discovery on
|
|
815
834
|
// a shared multi-user daemon. usersModule.findUserById(session.ownerId)
|
|
816
835
|
// is the same pattern already used elsewhere in this file (getFreshAuthState).
|
|
817
|
-
resolveSessionHome:
|
|
818
|
-
var ownerId = session && session.ownerId;
|
|
819
|
-
if (!ownerId) return null;
|
|
820
|
-
var owner = usersModule.findUserById(ownerId);
|
|
821
|
-
var ownerLinuxUser = owner && owner.linuxUser ? owner.linuxUser : null;
|
|
822
|
-
return resolveEffectiveHome(ownerLinuxUser);
|
|
823
|
-
},
|
|
836
|
+
resolveSessionHome: resolveOwnerHome,
|
|
824
837
|
});
|
|
825
838
|
var processSDKMessage = msgProcessor.processSDKMessage;
|
|
826
839
|
var sendAndRecord = msgProcessor.sendAndRecord;
|
|
@@ -842,7 +855,7 @@ function createSDKBridge(opts) {
|
|
|
842
855
|
type: "elicitation",
|
|
843
856
|
slug: slug,
|
|
844
857
|
title: (request.serverName || "MCP Server") + " needs input",
|
|
845
|
-
body: request.message || "Waiting for your response",
|
|
858
|
+
body: withPromptLabel(opened.label, request.message || "Waiting for your response"),
|
|
846
859
|
tag: "claude-elicitation",
|
|
847
860
|
};
|
|
848
861
|
// Route to session owner only — body carries MCP message text.
|
|
@@ -1188,7 +1201,7 @@ function createSDKBridge(opts) {
|
|
|
1188
1201
|
slug: slug,
|
|
1189
1202
|
requestId: opened.requestId,
|
|
1190
1203
|
title: agentPrefix + permissionPushTitle(toolName, input),
|
|
1191
|
-
body: permissionPushBody(toolName, input),
|
|
1204
|
+
body: withPromptLabel(opened.label, permissionPushBody(toolName, input)),
|
|
1192
1205
|
};
|
|
1193
1206
|
// Route to session owner only — body carries tool name and input (may contain paths/code).
|
|
1194
1207
|
if (session.ownerId && pushModule.sendPushToUser) {
|
|
@@ -1265,6 +1278,8 @@ function createSDKBridge(opts) {
|
|
|
1265
1278
|
// not resources from a newer query that may have been created after an abort.
|
|
1266
1279
|
var myQueryInstance = session.queryInstance;
|
|
1267
1280
|
var myAbortController = session.abortController;
|
|
1281
|
+
var myIdentityLease = session._identityLease || null;
|
|
1282
|
+
if (myIdentityLease) session._identityLease = null;
|
|
1268
1283
|
console.log("[sdk-bridge] processQueryStream: starting for-await loop, vendor=" + (session.vendor || adapter.vendor));
|
|
1269
1284
|
try {
|
|
1270
1285
|
for await (var msg of myQueryInstance) {
|
|
@@ -1454,6 +1469,8 @@ function createSDKBridge(opts) {
|
|
|
1454
1469
|
}
|
|
1455
1470
|
session.messageQueue = null;
|
|
1456
1471
|
if (session.abortController === myAbortController) session.abortController = null;
|
|
1472
|
+
// The query's process is ended above; its identity directory goes with it.
|
|
1473
|
+
if (myIdentityLease) myIdentityLease.release();
|
|
1457
1474
|
|
|
1458
1475
|
// lr-29f9: Reap the worker process immediately on query completion.
|
|
1459
1476
|
// The worker is kept alive between turns by _adapterWorkerState reuse, but
|
|
@@ -1479,7 +1496,7 @@ function createSDKBridge(opts) {
|
|
|
1479
1496
|
if (session._isCountedLive) {
|
|
1480
1497
|
session._isCountedLive = false;
|
|
1481
1498
|
_activeLiveCount = Math.max(0, _activeLiveCount - 1);
|
|
1482
|
-
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (session " + session.localId + " done)");
|
|
1499
|
+
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (project " + slug + " session " + session.localId + " done)");
|
|
1483
1500
|
}
|
|
1484
1501
|
session.taskStopRequested = false;
|
|
1485
1502
|
// lr-8355: A rewind (or any other replacement) may have already started
|
|
@@ -1651,8 +1668,8 @@ function createSDKBridge(opts) {
|
|
|
1651
1668
|
}
|
|
1652
1669
|
|
|
1653
1670
|
// `initiator` (turn-initiator.js INITIATORS) is who started this turn. It is
|
|
1654
|
-
// per turn: it stamps the first message and
|
|
1655
|
-
//
|
|
1671
|
+
// per turn: it stamps the first message and says nothing about later turns
|
|
1672
|
+
// of the session or about the process's environment.
|
|
1656
1673
|
async function startQuery(session, text, images, linuxUser, initiator) {
|
|
1657
1674
|
async function ensureVendorReady(vendor) {
|
|
1658
1675
|
if (!vendor) return null;
|
|
@@ -1775,7 +1792,9 @@ function createSDKBridge(opts) {
|
|
|
1775
1792
|
}
|
|
1776
1793
|
// Select adapter based on session vendor (fallback to default)
|
|
1777
1794
|
var sessionAdapter = (session.vendor && adapters[session.vendor]) || adapter;
|
|
1778
|
-
|
|
1795
|
+
// Console session ids repeat across projects, so the line names the project.
|
|
1796
|
+
// The prompt text is not logged.
|
|
1797
|
+
console.log("[sdk-bridge] startQuery: project=" + slug + " vendor=" + sessionAdapter.vendor + " session=" + session.localId);
|
|
1779
1798
|
// Remember linuxUser for auto-continue after rate limit
|
|
1780
1799
|
session.lastLinuxUser = linuxUser || null;
|
|
1781
1800
|
|
|
@@ -1786,7 +1805,7 @@ function createSDKBridge(opts) {
|
|
|
1786
1805
|
// Multi-turn pushes to an existing query are not new processes — don't gate them.
|
|
1787
1806
|
var isNewQuery = !session.queryInstance;
|
|
1788
1807
|
if (isNewQuery && _activeLiveCount >= MAX_CONCURRENT_SESSIONS) {
|
|
1789
|
-
console.warn("[sdk-bridge] Concurrent session ceiling hit (" + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + ") — rejecting new query for session " + session.localId);
|
|
1808
|
+
console.warn("[sdk-bridge] Concurrent session ceiling hit (" + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + ") — rejecting new query for project " + slug + " session " + session.localId);
|
|
1790
1809
|
session.isProcessing = false;
|
|
1791
1810
|
onProcessingChanged();
|
|
1792
1811
|
sendAndRecord(session, {
|
|
@@ -1803,7 +1822,7 @@ function createSDKBridge(opts) {
|
|
|
1803
1822
|
// slot is claimed so a refusal never increments the live counter.
|
|
1804
1823
|
var newWorkRefusal = isNewQuery ? getNewWorkRefusal() : null;
|
|
1805
1824
|
if (newWorkRefusal) {
|
|
1806
|
-
console.warn("[sdk-bridge] New-work gate closed — refusing new query for session " + session.localId);
|
|
1825
|
+
console.warn("[sdk-bridge] New-work gate closed — refusing new query for project " + slug + " session " + session.localId);
|
|
1807
1826
|
session.isProcessing = false;
|
|
1808
1827
|
onProcessingChanged();
|
|
1809
1828
|
sendAndRecord(session, { type: "error", text: newWorkRefusal });
|
|
@@ -1819,7 +1838,7 @@ function createSDKBridge(opts) {
|
|
|
1819
1838
|
var getConfig = opts.getConfig;
|
|
1820
1839
|
var memThresholdMB = resolveMemAvailableThresholdMB(typeof getConfig === "function" ? getConfig() : null);
|
|
1821
1840
|
if (memAvailMB !== null && memAvailMB < memThresholdMB) {
|
|
1822
|
-
console.warn("[sdk-bridge] MemAvailable gate: " + memAvailMB + " MB available, " + memThresholdMB + " MB required — rejecting new query for session " + session.localId);
|
|
1841
|
+
console.warn("[sdk-bridge] MemAvailable gate: " + memAvailMB + " MB available, " + memThresholdMB + " MB required — rejecting new query for project " + slug + " session " + session.localId);
|
|
1823
1842
|
session.isProcessing = false;
|
|
1824
1843
|
onProcessingChanged();
|
|
1825
1844
|
var memMsg = "Not enough memory to start a new query (" + memAvailMB + " MB available, " + memThresholdMB + " MB required). Wait for an active session to finish or close unused sessions.";
|
|
@@ -1927,13 +1946,13 @@ function createSDKBridge(opts) {
|
|
|
1927
1946
|
if (session._isCountedLive) {
|
|
1928
1947
|
session._isCountedLive = false;
|
|
1929
1948
|
_activeLiveCount = Math.max(0, _activeLiveCount - 1);
|
|
1930
|
-
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (session " + session.localId + " slot released)");
|
|
1949
|
+
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (project " + slug + " session " + session.localId + " slot released)");
|
|
1931
1950
|
}
|
|
1932
1951
|
}
|
|
1933
1952
|
if (isNewQuery) {
|
|
1934
1953
|
_activeLiveCount++;
|
|
1935
1954
|
session._isCountedLive = true;
|
|
1936
|
-
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (session " + session.localId + " starting)");
|
|
1955
|
+
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (project " + slug + " session " + session.localId + " starting)");
|
|
1937
1956
|
}
|
|
1938
1957
|
|
|
1939
1958
|
// Guard the rest of startQuery so any unexpected synchronous throw releases
|
|
@@ -2155,7 +2174,6 @@ function createSDKBridge(opts) {
|
|
|
2155
2174
|
var mergedMcpServers = mergeMcpServers(getMcpServers(), getRemoteMcpServers) || undefined;
|
|
2156
2175
|
var queryOpts = {
|
|
2157
2176
|
cwd: cwd,
|
|
2158
|
-
initiator: initiator,
|
|
2159
2177
|
model: queryModel,
|
|
2160
2178
|
effort: ls.effort || sm.currentEffort || undefined,
|
|
2161
2179
|
toolServers: mergedMcpServers,
|
|
@@ -2201,12 +2219,28 @@ function createSDKBridge(opts) {
|
|
|
2201
2219
|
// The variables Settings add to this runtime's environment, as of now.
|
|
2202
2220
|
withRuntimeEnv(queryOpts, session);
|
|
2203
2221
|
|
|
2222
|
+
// The identity of this agent process, when a provider is configured. Its
|
|
2223
|
+
// directory is delivered in the process's environment and removed when the
|
|
2224
|
+
// query ends (processQueryStream) or fails to start (below).
|
|
2225
|
+
var identityLease = identityConfig() == null
|
|
2226
|
+
? null
|
|
2227
|
+
: await beginIdentity(sessionAdapter.vendor, claudeOpts.agent, linuxUser, initiator);
|
|
2228
|
+
if (identityLease) {
|
|
2229
|
+
recordIdentity(session, identityLease);
|
|
2230
|
+
queryOpts.identity = { dir: identityLease.dir };
|
|
2231
|
+
} else {
|
|
2232
|
+
// No identity is issued for this start (none configured any more): a record
|
|
2233
|
+
// an earlier start left must not stay on the session as if this one had it.
|
|
2234
|
+
clearIdentityRecord(session);
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2204
2237
|
var handle;
|
|
2205
2238
|
console.log("[sdk-bridge] calling adapter.createQuery... vendor=" + sessionAdapter.vendor);
|
|
2206
2239
|
try {
|
|
2207
2240
|
handle = await sessionAdapter.createQuery(queryOpts);
|
|
2208
2241
|
console.log("[sdk-bridge] createQuery returned handle, vendor=" + sessionAdapter.vendor);
|
|
2209
2242
|
} catch (e) {
|
|
2243
|
+
if (identityLease) identityLease.release();
|
|
2210
2244
|
console.error("[sdk-bridge] Failed to create query for session " + session.localId + ":", e.message || e);
|
|
2211
2245
|
console.error("[sdk-bridge] cliSessionId:", session.cliSessionId, "resume:", !!session.cliSessionId);
|
|
2212
2246
|
console.error("[sdk-bridge] Stack:", e.stack || "(no stack)");
|
|
@@ -2242,6 +2276,7 @@ function createSDKBridge(opts) {
|
|
|
2242
2276
|
|
|
2243
2277
|
// Store QueryHandle on session for iteration and control.
|
|
2244
2278
|
session.queryInstance = handle;
|
|
2279
|
+
if (identityLease) session._identityLease = identityLease;
|
|
2245
2280
|
|
|
2246
2281
|
// Push initial user message through the QueryHandle
|
|
2247
2282
|
console.log("[sdk-bridge] pushing initial message via handle.pushMessage...");
|
|
@@ -2250,7 +2285,7 @@ function createSDKBridge(opts) {
|
|
|
2250
2285
|
// lr-b61b: Flush any messages that arrived between turns (after the previous
|
|
2251
2286
|
// finally block nulled queryInstance and before this startQuery call).
|
|
2252
2287
|
if (session.pendingMessages && session.pendingMessages.length > 0) {
|
|
2253
|
-
console.log("[sdk-bridge] startQuery: flushing " + session.pendingMessages.length + " buffered pending message(s) for session " + session.localId);
|
|
2288
|
+
console.log("[sdk-bridge] startQuery: flushing " + session.pendingMessages.length + " buffered pending message(s) for project " + slug + " session " + session.localId);
|
|
2254
2289
|
for (var pi = 0; pi < session.pendingMessages.length; pi++) {
|
|
2255
2290
|
var pm = session.pendingMessages[pi];
|
|
2256
2291
|
handle.pushMessage(pm.text, pm.images, pm.initiator);
|
|
@@ -2268,7 +2303,7 @@ function createSDKBridge(opts) {
|
|
|
2268
2303
|
handle.endInput();
|
|
2269
2304
|
}
|
|
2270
2305
|
|
|
2271
|
-
session
|
|
2306
|
+
bumpLastActivity(session, "query-start", slug);
|
|
2272
2307
|
session.streamPromise = processQueryStream(session).catch(function(err) {
|
|
2273
2308
|
console.error("[sdk-bridge] Unhandled stream error for session " + session.localId + ":", err && err.message || err);
|
|
2274
2309
|
sendToSession(session, { type: "error", text: "Stream error: " + (err && err.message || String(err)) });
|
|
@@ -2279,6 +2314,7 @@ function createSDKBridge(opts) {
|
|
|
2279
2314
|
// Unexpected synchronous throw anywhere in the post-slot-claim body.
|
|
2280
2315
|
// Release the slot and surface the error so the UI does not spin forever.
|
|
2281
2316
|
releaseSlot();
|
|
2317
|
+
if (identityLease) identityLease.release();
|
|
2282
2318
|
session.isProcessing = false;
|
|
2283
2319
|
onProcessingChanged();
|
|
2284
2320
|
session.queryInstance = null;
|
|
@@ -2292,7 +2328,7 @@ function createSDKBridge(opts) {
|
|
|
2292
2328
|
}
|
|
2293
2329
|
|
|
2294
2330
|
function pushMessage(session, text, images, initiator) {
|
|
2295
|
-
session
|
|
2331
|
+
bumpLastActivity(session, "push-message", slug);
|
|
2296
2332
|
// Route through QueryHandle (works for both in-process and worker paths)
|
|
2297
2333
|
if (session.queryInstance && typeof session.queryInstance.pushMessage === "function") {
|
|
2298
2334
|
session.queryInstance.pushMessage(text, images, initiator);
|
|
@@ -2640,12 +2676,7 @@ function createSDKBridge(opts) {
|
|
|
2640
2676
|
stopIdleReaper: stopIdleReaper,
|
|
2641
2677
|
getRuntimeEnvOverlay: getRuntimeEnvOverlay,
|
|
2642
2678
|
getMemoryStats: getMemoryStats,
|
|
2643
|
-
|
|
2644
|
-
// overwrite guard, following the _test_-prefixed exposure convention
|
|
2645
|
-
// already used by lib/yoke/adapters/codex.js's resolveTitleModel. Not
|
|
2646
|
-
// part of the bridge's real call surface (project.js never calls it by
|
|
2647
|
-
// this name) — it is the same closure onAutoTitle wraps internally.
|
|
2648
|
-
_test_autoGenerateTitle: autoGenerateTitle,
|
|
2679
|
+
refreshAiTitle: refreshAiTitle,
|
|
2649
2680
|
};
|
|
2650
2681
|
}
|
|
2651
2682
|
|
|
@@ -6,7 +6,9 @@ var sessionActivity = require("./session-activity");
|
|
|
6
6
|
var yokeRegistry = require("./yoke").registry;
|
|
7
7
|
var { authRequiredFacts } = require("./vendor-auth");
|
|
8
8
|
var sessionReclaim = require("./session-reclaim");
|
|
9
|
+
var { withPromptLabel } = require("./prompt-label");
|
|
9
10
|
var { isAgentDispatchTool } = require("./agent-dispatch-tool");
|
|
11
|
+
var { bumpLastActivity } = require("./activity-clock");
|
|
10
12
|
|
|
11
13
|
// Source names of the activity tokens an agent with the activityTokens
|
|
12
14
|
// trait holds for its own tool and thinking blocks.
|
|
@@ -31,7 +33,7 @@ function attachMessageProcessor(ctx) {
|
|
|
31
33
|
var cwd = ctx.cwd;
|
|
32
34
|
var onProcessingChanged = ctx.onProcessingChanged;
|
|
33
35
|
var onTurnDone = ctx.onTurnDone;
|
|
34
|
-
var
|
|
36
|
+
var refreshAiTitle = ctx.refreshAiTitle || null;
|
|
35
37
|
var onTeamCreate = ctx.onTeamCreate || null;
|
|
36
38
|
var onTeamDelete = ctx.onTeamDelete || null;
|
|
37
39
|
var opts = ctx.opts;
|
|
@@ -45,8 +47,6 @@ function attachMessageProcessor(ctx) {
|
|
|
45
47
|
// Allows callers (and tests) to inject a mock; falls back to the real implementation.
|
|
46
48
|
var discoverWorkflowsFn = ctx.discoverWorkflows || discoverWorkflows;
|
|
47
49
|
|
|
48
|
-
var AUTO_TITLE_TURN_THRESHOLD = 2;
|
|
49
|
-
|
|
50
50
|
function sendAndRecord(session, obj) {
|
|
51
51
|
sm.sendAndRecord(session, obj);
|
|
52
52
|
}
|
|
@@ -198,7 +198,7 @@ function attachMessageProcessor(ctx) {
|
|
|
198
198
|
// producing output; a dead/silent child stops bumping and the session
|
|
199
199
|
// still times out and is reaped normally (no blanket "never reap if a
|
|
200
200
|
// child is registered" rule — see startIdleReaper in sdk-bridge.js).
|
|
201
|
-
session
|
|
201
|
+
bumpLastActivity(session, "subagent-stream", slug);
|
|
202
202
|
|
|
203
203
|
if (parsed.messageRole === "assistant") {
|
|
204
204
|
// Extract tool_use blocks from sub-agent assistant messages
|
|
@@ -501,7 +501,7 @@ function attachMessageProcessor(ctx) {
|
|
|
501
501
|
type: "ask_user",
|
|
502
502
|
slug: slug,
|
|
503
503
|
title: "Claude has a question",
|
|
504
|
-
body: q ? q.question : "Waiting for your response",
|
|
504
|
+
body: withPromptLabel(promptsFor(sm).labelFor(session, block.id), q ? q.question : "Waiting for your response"),
|
|
505
505
|
tag: "claude-ask",
|
|
506
506
|
};
|
|
507
507
|
// Route to session owner only — content carries prompt text.
|
|
@@ -642,7 +642,7 @@ function attachMessageProcessor(ctx) {
|
|
|
642
642
|
if (parsed.cost && parsed.cost > 0) {
|
|
643
643
|
session.rateLimitResetsAt = null;
|
|
644
644
|
}
|
|
645
|
-
console.log("[sdk-bridge] result handler: session " + session.localId + " cost=" + parsed.cost + " rateLimitResetsAt=" + session.rateLimitResetsAt);
|
|
645
|
+
console.log("[sdk-bridge] result handler: project " + slug + " session " + session.localId + " cost=" + parsed.cost + " rateLimitResetsAt=" + session.rateLimitResetsAt);
|
|
646
646
|
|
|
647
647
|
// Handle SDK execution errors: show the error to the user instead of
|
|
648
648
|
// silently swallowing it. These have subtype "error_during_execution".
|
|
@@ -761,69 +761,16 @@ function attachMessageProcessor(ctx) {
|
|
|
761
761
|
});
|
|
762
762
|
}
|
|
763
763
|
// Reset for next turn in the same query
|
|
764
|
-
session
|
|
764
|
+
bumpLastActivity(session, "turn-result", slug);
|
|
765
765
|
session.turnCount = (session.turnCount || 0) + 1;
|
|
766
766
|
var donePreview = session.responsePreview || "";
|
|
767
767
|
session.responsePreview = "";
|
|
768
768
|
session.streamedText = false;
|
|
769
769
|
sm.broadcastSessionList();
|
|
770
770
|
|
|
771
|
-
//
|
|
772
|
-
//
|
|
773
|
-
|
|
774
|
-
// or a turnCount that was never persisted before this fix) still gets
|
|
775
|
-
// titled on a later turn instead of being permanently disqualified.
|
|
776
|
-
// Idempotence comes from !session.titleAutoGenerated, which is now
|
|
777
|
-
// durable (see sessions.js buildMetaLine/loadSessions).
|
|
778
|
-
if (session.turnCount >= AUTO_TITLE_TURN_THRESHOLD
|
|
779
|
-
&& !session.titleAutoGenerated
|
|
780
|
-
&& !session.titleManuallySet
|
|
781
|
-
&& !session.loop
|
|
782
|
-
&& onAutoTitle) {
|
|
783
|
-
try { onAutoTitle(session); } catch (e) {
|
|
784
|
-
console.error("[auto-title] onAutoTitle threw:", e.message || e);
|
|
785
|
-
}
|
|
786
|
-
} else {
|
|
787
|
-
// lr-efdab6 (DRUMMER decision, comment #1): the taken branch above
|
|
788
|
-
// already logs on every path (sdk-bridge.js [auto-title] sites) — but
|
|
789
|
-
// logging existed on NOTHING that recorded the gate NOT firing, so
|
|
790
|
-
// silence read identically for "ran fine and logged nothing notable",
|
|
791
|
-
// "never invoked", and "invoked and died before the first log". That
|
|
792
|
-
// ambiguity is exactly what let lr-62157d's dead auto-title feature
|
|
793
|
-
// survive ~3 months / ~160 sessions undetected. This branch makes the
|
|
794
|
-
// negative case unambiguous: every turn where the gate evaluates
|
|
795
|
-
// false gets exactly one line naming why.
|
|
796
|
-
//
|
|
797
|
-
// already_auto_generated is the expected steady-state reason for the
|
|
798
|
-
// overwhelming majority of turns in a mature session (fires every
|
|
799
|
-
// turn after the session's title is set) and is logged at a lower
|
|
800
|
-
// level (console.debug) so a normal journald view isn't dominated by
|
|
801
|
-
// it; every other reason is diagnostic of a gate that should be
|
|
802
|
-
// firing but isn't, and stays at console.log so it is visible by
|
|
803
|
-
// default. Nothing here transmits session content — only flags/counts.
|
|
804
|
-
var _autoTitleReason;
|
|
805
|
-
if (!onAutoTitle) {
|
|
806
|
-
_autoTitleReason = "no_callback";
|
|
807
|
-
} else if (session.loop) {
|
|
808
|
-
_autoTitleReason = "loop_running";
|
|
809
|
-
} else if (session.titleManuallySet) {
|
|
810
|
-
_autoTitleReason = "manually_set";
|
|
811
|
-
} else if (session.titleAutoGenerated) {
|
|
812
|
-
_autoTitleReason = "already_auto_generated";
|
|
813
|
-
} else if (session.turnCount < AUTO_TITLE_TURN_THRESHOLD) {
|
|
814
|
-
_autoTitleReason = "turn_threshold_not_met";
|
|
815
|
-
} else {
|
|
816
|
-
_autoTitleReason = "unknown";
|
|
817
|
-
}
|
|
818
|
-
var _autoTitleLogFn = (_autoTitleReason === "already_auto_generated") ? console.debug : console.log;
|
|
819
|
-
_autoTitleLogFn(
|
|
820
|
-
"[auto-title] gate did not fire: reason=" + _autoTitleReason
|
|
821
|
-
+ " turnCount=" + session.turnCount
|
|
822
|
-
+ " titleAutoGenerated=" + !!session.titleAutoGenerated
|
|
823
|
-
+ " titleManuallySet=" + !!session.titleManuallySet
|
|
824
|
-
+ " loop=" + !!session.loop
|
|
825
|
-
);
|
|
826
|
-
}
|
|
771
|
+
// The CLI may have written a newer title into the transcript during
|
|
772
|
+
// this turn; every turn picks up the latest. Never rejects.
|
|
773
|
+
if (refreshAiTitle) refreshAiTitle(session);
|
|
827
774
|
|
|
828
775
|
if (onTurnDone) {
|
|
829
776
|
try { onTurnDone(session, donePreview); } catch (e) {}
|
|
@@ -858,7 +805,7 @@ function attachMessageProcessor(ctx) {
|
|
|
858
805
|
// matching comment on processSubagentMessage's bump above and on
|
|
859
806
|
// startIdleReaper in sdk-bridge.js for why this keeps a WAITING
|
|
860
807
|
// parent session non-idle for as long as its child keeps reporting in.
|
|
861
|
-
session
|
|
808
|
+
bumpLastActivity(session, "task_started", slug);
|
|
862
809
|
if (!session.taskIdMap) session.taskIdMap = {};
|
|
863
810
|
session.taskIdMap[parentId] = parsed.taskId;
|
|
864
811
|
sendAndRecord(session, {
|
|
@@ -872,7 +819,7 @@ function attachMessageProcessor(ctx) {
|
|
|
872
819
|
} else if (parsed.yokeType === "task_progress") {
|
|
873
820
|
var parentId = parsed.parentToolId;
|
|
874
821
|
if (parentId) {
|
|
875
|
-
session
|
|
822
|
+
bumpLastActivity(session, "task_progress", slug); // see task_started above
|
|
876
823
|
sendAndRecord(session, {
|
|
877
824
|
type: "task_progress",
|
|
878
825
|
parentToolId: parentId,
|
|
@@ -895,7 +842,7 @@ function attachMessageProcessor(ctx) {
|
|
|
895
842
|
}
|
|
896
843
|
}
|
|
897
844
|
if (parentId) {
|
|
898
|
-
session
|
|
845
|
+
bumpLastActivity(session, "task_updated", slug); // see task_started above
|
|
899
846
|
sendAndRecord(session, {
|
|
900
847
|
type: "task_updated",
|
|
901
848
|
parentToolId: parentId,
|
|
@@ -908,7 +855,7 @@ function attachMessageProcessor(ctx) {
|
|
|
908
855
|
// Sub-agent tool_progress: forward as activity update
|
|
909
856
|
var parentId = parsed.parentToolId;
|
|
910
857
|
if (parentId) {
|
|
911
|
-
session
|
|
858
|
+
bumpLastActivity(session, "tool_progress", slug); // see task_started above
|
|
912
859
|
sendAndRecord(session, {
|
|
913
860
|
type: "subagent_activity",
|
|
914
861
|
parentToolId: parentId,
|