@clagentic/console 1.10.0-beta.1 → 1.10.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/cli.js +10 -0
- package/lib/activity-clock.js +23 -0
- package/lib/agent-dispatch-tool.js +20 -0
- package/lib/build-changes.js +79 -0
- package/lib/build-identity.js +192 -0
- package/lib/build-monitor.js +125 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +141 -0
- package/lib/build-update-restart.js +142 -0
- package/lib/build-update-standing.js +184 -0
- package/lib/cli/daemon-launch.js +8 -5
- package/lib/cli/ipc-subcommands.js +6 -0
- package/lib/cli/session-subcommands.js +122 -0
- package/lib/cli-sessions.js +8 -1
- package/lib/cli-transcript-title.js +131 -0
- package/lib/codex-defaults.js +8 -2
- package/lib/daemon-projects.js +19 -0
- package/lib/daemon.js +166 -127
- package/lib/debug-log.js +17 -0
- package/lib/exit-flush.js +44 -0
- package/lib/grant-keys.js +179 -0
- package/lib/log-field.js +34 -0
- package/lib/memory-shed.js +13 -32
- package/lib/project-connection.js +14 -0
- package/lib/project-external-trigger.js +91 -123
- package/lib/project-http.js +2 -0
- package/lib/project-loop.js +5 -4
- package/lib/project-notifications.js +4 -0
- package/lib/project-prompt-responses.js +7 -5
- package/lib/project-session-grants.js +73 -0
- package/lib/project-sessions.js +55 -68
- package/lib/project-user-message.js +13 -25
- package/lib/project.js +25 -5
- package/lib/prompt-kinds/permission.js +18 -0
- package/lib/prompt-label.js +60 -0
- package/lib/prompt-registry.js +123 -13
- package/lib/prompt-source.js +65 -0
- package/lib/public/css/diagnostics.css +30 -0
- package/lib/public/css/notifications-center.css +15 -0
- package/lib/public/css/overlays.css +18 -0
- package/lib/public/css/rewind.css +8 -0
- package/lib/public/modules/agent-dispatch-tool.js +9 -0
- package/lib/public/modules/app-messages.js +10 -2
- package/lib/public/modules/app-notifications.js +9 -1
- package/lib/public/modules/app-panels.js +0 -1
- package/lib/public/modules/build-update-detail.js +54 -0
- package/lib/public/modules/diagnostics.js +126 -20
- package/lib/public/modules/prompt-banner.js +12 -0
- package/lib/public/modules/prompt-kinds/permission-choices.js +6 -1
- package/lib/public/modules/prompt-kinds/permission.js +15 -0
- 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/public/modules/tools.js +14 -2
- package/lib/public/modules/vendor-picker.js +2 -2
- package/lib/public/modules/vendor-registry.js +11 -2
- package/lib/runtime-env.js +1 -1
- package/lib/sdk-bridge.js +114 -115
- package/lib/sdk-message-processor.js +25 -87
- package/lib/sdk-skill-discovery.js +65 -60
- package/lib/server.js +15 -2
- package/lib/session-ai-title.js +80 -0
- package/lib/session-id.js +33 -0
- package/lib/session-input-ipc.js +32 -0
- package/lib/session-input.js +409 -0
- package/lib/session-reclaim.js +284 -0
- package/lib/session-resume.js +172 -0
- package/lib/sessions.js +31 -21
- package/lib/supervisor.js +39 -0
- package/lib/turn-initiator.js +108 -0
- package/lib/utils.js +9 -47
- package/lib/vendor-registry-message.js +1 -0
- package/lib/ws-schema.js +9 -4
- package/lib/yoke/adapters/claude-vendor.js +0 -1
- package/lib/yoke/adapters/claude-worker.js +6 -4
- package/lib/yoke/adapters/claude.js +29 -86
- package/lib/yoke/adapters/codex-capabilities.js +9 -6
- package/lib/yoke/adapters/codex-vendor.js +15 -15
- package/lib/yoke/adapters/codex.js +125 -136
- package/lib/yoke/auth-checks.js +8 -21
- package/lib/yoke/codex-app-server.js +27 -71
- package/lib/yoke/codex-binary.js +254 -0
- package/lib/yoke/codex-command.js +122 -0
- package/lib/yoke/codex-protocol.js +96 -0
- package/lib/yoke/codex-version.js +135 -0
- package/lib/yoke/index.js +20 -4
- package/lib/yoke/install-probe.js +21 -6
- package/lib/yoke/interface.js +14 -12
- package/lib/yoke/registry.js +41 -4
- package/package.json +1 -2
- package/scripts/verify-installed-build.js +59 -17
- package/lib/lore-attestation.js +0 -73
package/lib/sdk-bridge.js
CHANGED
|
@@ -14,6 +14,9 @@ var { runPreflight } = require("./settings-preflight");
|
|
|
14
14
|
var { promptsFor } = require("./prompt-registry");
|
|
15
15
|
var { toolApprovalKind } = require("./prompt-kinds");
|
|
16
16
|
var sessionActivity = require("./session-activity");
|
|
17
|
+
var sessionReclaim = require("./session-reclaim");
|
|
18
|
+
var { withPromptLabel } = require("./prompt-label");
|
|
19
|
+
var { isAgentDispatchTool } = require("./agent-dispatch-tool");
|
|
17
20
|
var { getNewWorkRefusal } = require("./new-work-gate");
|
|
18
21
|
var runtimeEnv = require("./runtime-env");
|
|
19
22
|
var mcpToolSchema = require("./mcp-tool-schema");
|
|
@@ -21,6 +24,9 @@ var { registry: yokeRegistry } = require("./yoke");
|
|
|
21
24
|
var sessionCapabilities = require("./session-capabilities");
|
|
22
25
|
var { buildVendorRegistryMessage, recordInstallState } = require("./vendor-registry-message");
|
|
23
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");
|
|
24
30
|
|
|
25
31
|
// --- lr-29f9: Global concurrent-session ceiling ---
|
|
26
32
|
// Counts queries that are actively running (startQuery entered, processQueryStream
|
|
@@ -383,6 +389,9 @@ function createSDKBridge(opts) {
|
|
|
383
389
|
var adapter = opts.adapter;
|
|
384
390
|
var adapters = opts.adapters || {};
|
|
385
391
|
var dangerouslySkipPermissions = opts.dangerouslySkipPermissions || false;
|
|
392
|
+
// Whether the daemon isolates users at the OS level. An agent that does not
|
|
393
|
+
// support that (Codex) is disabled then: never created, never started.
|
|
394
|
+
var osUsersMode = !!opts.osUsers;
|
|
386
395
|
// mcpServers may be either a static object or a getter function. The
|
|
387
396
|
// getter form lets callers gate individual servers at call time (e.g.
|
|
388
397
|
// clay-browser is only exposed while the Chrome extension is connected).
|
|
@@ -596,10 +605,14 @@ function createSDKBridge(opts) {
|
|
|
596
605
|
// no activity at all, or a leaked child registration would pin the
|
|
597
606
|
// session (and its process) alive forever. Because that case was never
|
|
598
607
|
// "live" at the moment of reap (no activity for the full timeout window),
|
|
599
|
-
// it
|
|
600
|
-
// lib/
|
|
601
|
-
//
|
|
602
|
-
//
|
|
608
|
+
// it is reaped; the reap and the pressure path in lib/memory-shed.js both
|
|
609
|
+
// announce it through lib/session-reclaim.js.
|
|
610
|
+
//
|
|
611
|
+
// A session with ANY open operator prompt is never reaped (see the
|
|
612
|
+
// pendingCount check in startIdleReaper): a background agent blocked on a
|
|
613
|
+
// permission prompt emits nothing, so its silence is the operator's to
|
|
614
|
+
// break, not evidence that it died. When a silent child IS reaped, the
|
|
615
|
+
// operator is told which agents were interrupted.
|
|
603
616
|
var IDLE_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes
|
|
604
617
|
var IDLE_CHECK_INTERVAL_MS = 60 * 1000; // check every 60 seconds
|
|
605
618
|
// lr-5450ef: BACKSTOP staleness window for the activity registry's leak
|
|
@@ -616,6 +629,7 @@ function createSDKBridge(opts) {
|
|
|
616
629
|
if (_idleReaperTimer) return;
|
|
617
630
|
_idleReaperTimer = setInterval(function () {
|
|
618
631
|
var now = Date.now();
|
|
632
|
+
var skippedForPrompt = [];
|
|
619
633
|
sm.sessions.forEach(function (session) {
|
|
620
634
|
if (session.destroying) return;
|
|
621
635
|
|
|
@@ -656,11 +670,35 @@ function createSDKBridge(opts) {
|
|
|
656
670
|
if (!session.queryInstance) return;
|
|
657
671
|
if (session.singleTurn) return;
|
|
658
672
|
|
|
673
|
+
// A session with an open prompt (its own, or a background agent's) is
|
|
674
|
+
// waiting on the operator, not idle: an agent blocked on a prompt
|
|
675
|
+
// emits no stream events, so the activity clock cannot tell. Ending
|
|
676
|
+
// it would abort the pending tool call and destroy the agent's work.
|
|
677
|
+
// Memory pressure is handled by lib/memory-shed.js, not this timer.
|
|
678
|
+
var openPrompts = promptsFor(sm).pendingCount(session);
|
|
679
|
+
if (openPrompts > 0) {
|
|
680
|
+
skippedForPrompt.push(logField(session.localId) + ":prompts=" + openPrompts
|
|
681
|
+
+ ":idle=" + Math.round((now - (session.lastActivityAt || 0)) / 60000) + "min");
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
|
|
659
685
|
var lastActivity = session.lastActivityAt || 0;
|
|
660
686
|
if (now - lastActivity > IDLE_TIMEOUT_MS) {
|
|
661
687
|
console.log("[sdk-bridge] Reaping idle session " + session.localId +
|
|
662
688
|
" (idle " + Math.round((now - lastActivity) / 60000) + "min)" +
|
|
663
689
|
(session.title ? " title=" + JSON.stringify(session.title) : ""));
|
|
690
|
+
// Never silent when background agents are still registered: name
|
|
691
|
+
// them and mark the session as expected to resume.
|
|
692
|
+
sessionReclaim.announceLiveAgentReclaim({
|
|
693
|
+
session: session,
|
|
694
|
+
sm: sm,
|
|
695
|
+
send: send,
|
|
696
|
+
slug: slug,
|
|
697
|
+
reason: "idle_reap",
|
|
698
|
+
source: "idle-reap",
|
|
699
|
+
cause: "Clagentic: Console ended this session after " + Math.round(IDLE_TIMEOUT_MS / 60000)
|
|
700
|
+
+ " minutes without activity.",
|
|
701
|
+
});
|
|
664
702
|
// End the query so the for-await loop in processQueryStream
|
|
665
703
|
// exits naturally, triggering the finally block cleanup.
|
|
666
704
|
// Works for both in-process (messageQueue.end) and worker (handle.close) paths.
|
|
@@ -671,6 +709,13 @@ function createSDKBridge(opts) {
|
|
|
671
709
|
}
|
|
672
710
|
}
|
|
673
711
|
});
|
|
712
|
+
// One line per sweep, so "a session with an open prompt is never reaped"
|
|
713
|
+
// can be read from the journal rather than inferred from its absence.
|
|
714
|
+
if (skippedForPrompt.length) {
|
|
715
|
+
console.log("[sdk-bridge] Idle reaper: skipped " + skippedForPrompt.length
|
|
716
|
+
+ " session(s) with an open prompt: project=" + logField(slug)
|
|
717
|
+
+ " sessions=" + skippedForPrompt.join(","));
|
|
718
|
+
}
|
|
674
719
|
}, IDLE_CHECK_INTERVAL_MS);
|
|
675
720
|
// Don't prevent process exit
|
|
676
721
|
if (_idleReaperTimer.unref) _idleReaperTimer.unref();
|
|
@@ -689,82 +734,26 @@ function createSDKBridge(opts) {
|
|
|
689
734
|
var mergeSkills = skills.mergeSkills;
|
|
690
735
|
|
|
691
736
|
// --- Message processing (extracted to sdk-message-processor.js) ---
|
|
692
|
-
//
|
|
693
|
-
//
|
|
694
|
-
//
|
|
695
|
-
//
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
// user messages, fall back to a disk-backed full scan via
|
|
703
|
-
// loadFullSessionHistory + retrimHistory rather than silently under-titling
|
|
704
|
-
// with whatever partial set the trimmed heap happened to retain. The full
|
|
705
|
-
// load is never left resident — retrimHistory() re-applies the cap
|
|
706
|
-
// immediately after this function reads what it needs.
|
|
707
|
-
function autoGenerateTitle(session) {
|
|
708
|
-
var sessionAdapter = getAdapterForSession(session);
|
|
709
|
-
if (typeof sessionAdapter.generateTitle !== "function") {
|
|
710
|
-
console.log("[auto-title] adapter.generateTitle not available for vendor=" + sessionAdapter.vendor);
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
function collectUserMessages(history) {
|
|
714
|
-
var out = [];
|
|
715
|
-
for (var i = 0; i < history.length; i++) {
|
|
716
|
-
var entry = history[i];
|
|
717
|
-
if (entry.type === "user_message" && entry.text) {
|
|
718
|
-
out.push(entry.text.substring(0, 200));
|
|
719
|
-
if (out.length >= 5) break;
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
return out;
|
|
723
|
-
}
|
|
724
|
-
var userMessages = collectUserMessages(session.history);
|
|
725
|
-
if (userMessages.length < 5 && (session._historyBaseIndex || 0) > 0) {
|
|
726
|
-
sm.loadFullSessionHistory(session);
|
|
727
|
-
userMessages = collectUserMessages(session.history);
|
|
728
|
-
sm.retrimHistory(session);
|
|
729
|
-
}
|
|
730
|
-
if (userMessages.length === 0) {
|
|
731
|
-
console.log("[auto-title] No user messages found in session " + session.localId);
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
console.log("[auto-title] Calling adapter.generateTitle with " + userMessages.length + " messages for session " + session.localId);
|
|
735
|
-
|
|
736
|
-
// lr-62157d: returns the promise chain (previously fire-and-forget) so
|
|
737
|
-
// this is directly awaitable in tests via _test_autoGenerateTitle; the
|
|
738
|
-
// real onAutoTitle callers (sdk-message-processor.js) call this
|
|
739
|
-
// fire-and-forget already and are unaffected by a function now
|
|
740
|
-
// returning a value they don't use.
|
|
741
|
-
return sessionAdapter.generateTitle(userMessages, withRuntimeEnv({ cwd: cwd }, session)).then(function(title) {
|
|
742
|
-
if (!title || title.length < 2) return;
|
|
743
|
-
title = title.substring(0, 100);
|
|
744
|
-
// lr-62157d: overwrite whenever the current title is provisional (the
|
|
745
|
-
// raw first-message truncation from project-user-message.js, or no
|
|
746
|
-
// title at all) and the user hasn't manually renamed the session.
|
|
747
|
-
// Before titleProvisional existed, the first-message fallback looked
|
|
748
|
-
// exactly like a real title, so this guard had nothing that let it
|
|
749
|
-
// tell "already properly titled" apart from "still carrying the raw
|
|
750
|
-
// 50-char truncation" — this is what actually lets a real LLM title
|
|
751
|
-
// replace that truncation.
|
|
752
|
-
if ((session.titleProvisional || !session.title) && !session.titleManuallySet) {
|
|
753
|
-
session.title = title;
|
|
754
|
-
session.titleAutoGenerated = true;
|
|
755
|
-
session.titleProvisional = false;
|
|
756
|
-
sm.saveSessionFile(session);
|
|
757
|
-
sm.broadcastSessionList();
|
|
758
|
-
if (session.cliSessionId && typeof adapter.renameSession === "function") {
|
|
759
|
-
adapter.renameSession(session.cliSessionId, title, { dir: cwd }).catch(function () {});
|
|
760
|
-
}
|
|
761
|
-
console.log("[auto-title] Generated title for session " + session.localId + ": " + title);
|
|
762
|
-
}
|
|
763
|
-
}).catch(function(e) {
|
|
764
|
-
console.error("[auto-title] Failed:", e.message || e);
|
|
765
|
-
});
|
|
737
|
+
// The session title is the one the vendor CLI wrote into the session's
|
|
738
|
+
// transcript; no query is ever started to produce one (session-ai-title.js).
|
|
739
|
+
// The home is the session owner's on a shared multi-user daemon, null for the
|
|
740
|
+
// daemon's own.
|
|
741
|
+
function resolveOwnerHome(session) {
|
|
742
|
+
var ownerId = session && session.ownerId;
|
|
743
|
+
if (!ownerId) return null;
|
|
744
|
+
var owner = usersModule.findUserById(ownerId);
|
|
745
|
+
var ownerLinuxUser = owner && owner.linuxUser ? owner.linuxUser : null;
|
|
746
|
+
return resolveEffectiveHome(ownerLinuxUser);
|
|
766
747
|
}
|
|
767
748
|
|
|
749
|
+
var refreshAiTitle = createAiTitleRefresher({
|
|
750
|
+
sm: sm,
|
|
751
|
+
cwd: cwd,
|
|
752
|
+
resolveHome: resolveOwnerHome,
|
|
753
|
+
getRuntimeEnvOverlay: getRuntimeEnvOverlay,
|
|
754
|
+
daemonHome: require("./config").REAL_HOME || require("os").homedir(),
|
|
755
|
+
});
|
|
756
|
+
|
|
768
757
|
var msgProcessor = attachMessageProcessor({
|
|
769
758
|
sm: sm,
|
|
770
759
|
send: send,
|
|
@@ -775,7 +764,7 @@ function createSDKBridge(opts) {
|
|
|
775
764
|
adapter: adapter,
|
|
776
765
|
onProcessingChanged: onProcessingChanged,
|
|
777
766
|
onTurnDone: onTurnDone,
|
|
778
|
-
|
|
767
|
+
refreshAiTitle: refreshAiTitle,
|
|
779
768
|
onTeamCreate: opts.onTeamCreate || null,
|
|
780
769
|
onTeamDelete: opts.onTeamDelete || null,
|
|
781
770
|
opts: opts,
|
|
@@ -786,13 +775,7 @@ function createSDKBridge(opts) {
|
|
|
786
775
|
// lr-3ccc78 — session-owner home resolution for skill/agent discovery on
|
|
787
776
|
// a shared multi-user daemon. usersModule.findUserById(session.ownerId)
|
|
788
777
|
// is the same pattern already used elsewhere in this file (getFreshAuthState).
|
|
789
|
-
resolveSessionHome:
|
|
790
|
-
var ownerId = session && session.ownerId;
|
|
791
|
-
if (!ownerId) return null;
|
|
792
|
-
var owner = usersModule.findUserById(ownerId);
|
|
793
|
-
var ownerLinuxUser = owner && owner.linuxUser ? owner.linuxUser : null;
|
|
794
|
-
return resolveEffectiveHome(ownerLinuxUser);
|
|
795
|
-
},
|
|
778
|
+
resolveSessionHome: resolveOwnerHome,
|
|
796
779
|
});
|
|
797
780
|
var processSDKMessage = msgProcessor.processSDKMessage;
|
|
798
781
|
var sendAndRecord = msgProcessor.sendAndRecord;
|
|
@@ -814,7 +797,7 @@ function createSDKBridge(opts) {
|
|
|
814
797
|
type: "elicitation",
|
|
815
798
|
slug: slug,
|
|
816
799
|
title: (request.serverName || "MCP Server") + " needs input",
|
|
817
|
-
body: request.message || "Waiting for your response",
|
|
800
|
+
body: withPromptLabel(opened.label, request.message || "Waiting for your response"),
|
|
818
801
|
tag: "claude-elicitation",
|
|
819
802
|
};
|
|
820
803
|
// Route to session owner only — body carries MCP message text.
|
|
@@ -1124,10 +1107,17 @@ function createSDKBridge(opts) {
|
|
|
1124
1107
|
// configurable) rather than copying the worker's blanket 30s.
|
|
1125
1108
|
// The registry creates the notification and dismisses it when the
|
|
1126
1109
|
// prompt settles.
|
|
1110
|
+
// A prompt raised by a background agent says so, on the card, the banner
|
|
1111
|
+
// and the push: otherwise it reads as the parent's own call and is easy
|
|
1112
|
+
// to miss while the parent sits idle.
|
|
1113
|
+
var agentLabel = sessionReclaim.ownerLabelOfTool(session, prompts, opts.toolUseID);
|
|
1114
|
+
var agentPrefix = agentLabel ? 'Background agent "' + agentLabel + '": ' : "";
|
|
1127
1115
|
var opened = prompts.open(session, kind, {
|
|
1128
1116
|
toolName: toolName,
|
|
1129
1117
|
toolInput: input,
|
|
1130
|
-
decisionReason:
|
|
1118
|
+
decisionReason: agentLabel
|
|
1119
|
+
? 'Requested by background agent "' + agentLabel + '". ' + (opts.decisionReason || "")
|
|
1120
|
+
: (opts.decisionReason || ""),
|
|
1131
1121
|
vendor: session.vendor || (adapter && adapter.vendor) || "claude",
|
|
1132
1122
|
suppressAlwaysAllowRule: opts.suppressAlwaysAllowRule,
|
|
1133
1123
|
defaultToNo: opts.defaultToNo,
|
|
@@ -1136,7 +1126,7 @@ function createSDKBridge(opts) {
|
|
|
1136
1126
|
toolUseId: opts.toolUseID,
|
|
1137
1127
|
signal: opts.signal,
|
|
1138
1128
|
notification: {
|
|
1139
|
-
title: permissionPushTitle(toolName, input),
|
|
1129
|
+
title: agentPrefix + permissionPushTitle(toolName, input),
|
|
1140
1130
|
body: permissionPushBody(toolName, input),
|
|
1141
1131
|
slug: slug,
|
|
1142
1132
|
sessionId: session.localId,
|
|
@@ -1152,8 +1142,8 @@ function createSDKBridge(opts) {
|
|
|
1152
1142
|
type: "permission_request",
|
|
1153
1143
|
slug: slug,
|
|
1154
1144
|
requestId: opened.requestId,
|
|
1155
|
-
title: permissionPushTitle(toolName, input),
|
|
1156
|
-
body: permissionPushBody(toolName, input),
|
|
1145
|
+
title: agentPrefix + permissionPushTitle(toolName, input),
|
|
1146
|
+
body: withPromptLabel(opened.label, permissionPushBody(toolName, input)),
|
|
1157
1147
|
};
|
|
1158
1148
|
// Route to session owner only — body carries tool name and input (may contain paths/code).
|
|
1159
1149
|
if (session.ownerId && pushModule.sendPushToUser) {
|
|
@@ -1444,7 +1434,7 @@ function createSDKBridge(opts) {
|
|
|
1444
1434
|
if (session._isCountedLive) {
|
|
1445
1435
|
session._isCountedLive = false;
|
|
1446
1436
|
_activeLiveCount = Math.max(0, _activeLiveCount - 1);
|
|
1447
|
-
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (session " + session.localId + " done)");
|
|
1437
|
+
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (project " + slug + " session " + session.localId + " done)");
|
|
1448
1438
|
}
|
|
1449
1439
|
session.taskStopRequested = false;
|
|
1450
1440
|
// lr-8355: A rewind (or any other replacement) may have already started
|
|
@@ -1615,7 +1605,10 @@ function createSDKBridge(opts) {
|
|
|
1615
1605
|
return { sessionId: result.sessionId, useLocalHistory: false };
|
|
1616
1606
|
}
|
|
1617
1607
|
|
|
1618
|
-
|
|
1608
|
+
// `initiator` (turn-initiator.js INITIATORS) is who started this turn. It is
|
|
1609
|
+
// per turn: it stamps the first message and decides the new process's
|
|
1610
|
+
// environment, and says nothing about later turns of the session.
|
|
1611
|
+
async function startQuery(session, text, images, linuxUser, initiator) {
|
|
1619
1612
|
async function ensureVendorReady(vendor) {
|
|
1620
1613
|
if (!vendor) return null;
|
|
1621
1614
|
// What the adapter's live session advertises narrows its declaration; the
|
|
@@ -1633,6 +1626,7 @@ function createSDKBridge(opts) {
|
|
|
1633
1626
|
// session's own server is started for it when its query begins.
|
|
1634
1627
|
vendorAdapter = await yoke.lazyCreateAdapter(adapters, vendor, withRuntimeEnv({
|
|
1635
1628
|
cwd: cwd,
|
|
1629
|
+
osUsers: osUsersMode,
|
|
1636
1630
|
dangerouslySkipPermissions: dangerouslySkipPermissions,
|
|
1637
1631
|
linuxUser: linuxUser || undefined,
|
|
1638
1632
|
clayPort: clayPort,
|
|
@@ -1668,6 +1662,13 @@ function createSDKBridge(opts) {
|
|
|
1668
1662
|
sendAndRecord(session, { type: "done", code: 1 });
|
|
1669
1663
|
return;
|
|
1670
1664
|
}
|
|
1665
|
+
// An agent that per-user OS isolation rules out is refused with its reason,
|
|
1666
|
+
// not offered a login, and nothing of it is started.
|
|
1667
|
+
if (session.vendor && yokeRegistry.disabledByOsUsers(session.vendor, osUsersMode)) {
|
|
1668
|
+
sendAndRecord(session, { type: "error", text: yokeRegistry.osUsersReasonFor(session.vendor) });
|
|
1669
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1671
1672
|
// If vendor is set but adapter not ready, try lazy creation (user may have logged in)
|
|
1672
1673
|
if (session.vendor && !adapters[session.vendor]) {
|
|
1673
1674
|
var lazyAdapter = await ensureVendorReady(session.vendor);
|
|
@@ -1729,7 +1730,9 @@ function createSDKBridge(opts) {
|
|
|
1729
1730
|
}
|
|
1730
1731
|
// Select adapter based on session vendor (fallback to default)
|
|
1731
1732
|
var sessionAdapter = (session.vendor && adapters[session.vendor]) || adapter;
|
|
1732
|
-
|
|
1733
|
+
// Console session ids repeat across projects, so the line names the project.
|
|
1734
|
+
// The prompt text is not logged.
|
|
1735
|
+
console.log("[sdk-bridge] startQuery: project=" + slug + " vendor=" + sessionAdapter.vendor + " session=" + session.localId);
|
|
1733
1736
|
// Remember linuxUser for auto-continue after rate limit
|
|
1734
1737
|
session.lastLinuxUser = linuxUser || null;
|
|
1735
1738
|
|
|
@@ -1740,7 +1743,7 @@ function createSDKBridge(opts) {
|
|
|
1740
1743
|
// Multi-turn pushes to an existing query are not new processes — don't gate them.
|
|
1741
1744
|
var isNewQuery = !session.queryInstance;
|
|
1742
1745
|
if (isNewQuery && _activeLiveCount >= MAX_CONCURRENT_SESSIONS) {
|
|
1743
|
-
console.warn("[sdk-bridge] Concurrent session ceiling hit (" + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + ") — rejecting new query for session " + session.localId);
|
|
1746
|
+
console.warn("[sdk-bridge] Concurrent session ceiling hit (" + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + ") — rejecting new query for project " + slug + " session " + session.localId);
|
|
1744
1747
|
session.isProcessing = false;
|
|
1745
1748
|
onProcessingChanged();
|
|
1746
1749
|
sendAndRecord(session, {
|
|
@@ -1757,7 +1760,7 @@ function createSDKBridge(opts) {
|
|
|
1757
1760
|
// slot is claimed so a refusal never increments the live counter.
|
|
1758
1761
|
var newWorkRefusal = isNewQuery ? getNewWorkRefusal() : null;
|
|
1759
1762
|
if (newWorkRefusal) {
|
|
1760
|
-
console.warn("[sdk-bridge] New-work gate closed — refusing new query for session " + session.localId);
|
|
1763
|
+
console.warn("[sdk-bridge] New-work gate closed — refusing new query for project " + slug + " session " + session.localId);
|
|
1761
1764
|
session.isProcessing = false;
|
|
1762
1765
|
onProcessingChanged();
|
|
1763
1766
|
sendAndRecord(session, { type: "error", text: newWorkRefusal });
|
|
@@ -1773,7 +1776,7 @@ function createSDKBridge(opts) {
|
|
|
1773
1776
|
var getConfig = opts.getConfig;
|
|
1774
1777
|
var memThresholdMB = resolveMemAvailableThresholdMB(typeof getConfig === "function" ? getConfig() : null);
|
|
1775
1778
|
if (memAvailMB !== null && memAvailMB < memThresholdMB) {
|
|
1776
|
-
console.warn("[sdk-bridge] MemAvailable gate: " + memAvailMB + " MB available, " + memThresholdMB + " MB required — rejecting new query for session " + session.localId);
|
|
1779
|
+
console.warn("[sdk-bridge] MemAvailable gate: " + memAvailMB + " MB available, " + memThresholdMB + " MB required — rejecting new query for project " + slug + " session " + session.localId);
|
|
1777
1780
|
session.isProcessing = false;
|
|
1778
1781
|
onProcessingChanged();
|
|
1779
1782
|
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.";
|
|
@@ -1881,13 +1884,13 @@ function createSDKBridge(opts) {
|
|
|
1881
1884
|
if (session._isCountedLive) {
|
|
1882
1885
|
session._isCountedLive = false;
|
|
1883
1886
|
_activeLiveCount = Math.max(0, _activeLiveCount - 1);
|
|
1884
|
-
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (session " + session.localId + " slot released)");
|
|
1887
|
+
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (project " + slug + " session " + session.localId + " slot released)");
|
|
1885
1888
|
}
|
|
1886
1889
|
}
|
|
1887
1890
|
if (isNewQuery) {
|
|
1888
1891
|
_activeLiveCount++;
|
|
1889
1892
|
session._isCountedLive = true;
|
|
1890
|
-
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (session " + session.localId + " starting)");
|
|
1893
|
+
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (project " + slug + " session " + session.localId + " starting)");
|
|
1891
1894
|
}
|
|
1892
1895
|
|
|
1893
1896
|
// Guard the rest of startQuery so any unexpected synchronous throw releases
|
|
@@ -2109,6 +2112,7 @@ function createSDKBridge(opts) {
|
|
|
2109
2112
|
var mergedMcpServers = mergeMcpServers(getMcpServers(), getRemoteMcpServers) || undefined;
|
|
2110
2113
|
var queryOpts = {
|
|
2111
2114
|
cwd: cwd,
|
|
2115
|
+
initiator: initiator,
|
|
2112
2116
|
model: queryModel,
|
|
2113
2117
|
effort: ls.effort || sm.currentEffort || undefined,
|
|
2114
2118
|
toolServers: mergedMcpServers,
|
|
@@ -2198,15 +2202,15 @@ function createSDKBridge(opts) {
|
|
|
2198
2202
|
|
|
2199
2203
|
// Push initial user message through the QueryHandle
|
|
2200
2204
|
console.log("[sdk-bridge] pushing initial message via handle.pushMessage...");
|
|
2201
|
-
handle.pushMessage(text, images);
|
|
2205
|
+
handle.pushMessage(text, images, initiator);
|
|
2202
2206
|
|
|
2203
2207
|
// lr-b61b: Flush any messages that arrived between turns (after the previous
|
|
2204
2208
|
// finally block nulled queryInstance and before this startQuery call).
|
|
2205
2209
|
if (session.pendingMessages && session.pendingMessages.length > 0) {
|
|
2206
|
-
console.log("[sdk-bridge] startQuery: flushing " + session.pendingMessages.length + " buffered pending message(s) for session " + session.localId);
|
|
2210
|
+
console.log("[sdk-bridge] startQuery: flushing " + session.pendingMessages.length + " buffered pending message(s) for project " + slug + " session " + session.localId);
|
|
2207
2211
|
for (var pi = 0; pi < session.pendingMessages.length; pi++) {
|
|
2208
2212
|
var pm = session.pendingMessages[pi];
|
|
2209
|
-
handle.pushMessage(pm.text, pm.images);
|
|
2213
|
+
handle.pushMessage(pm.text, pm.images, pm.initiator);
|
|
2210
2214
|
}
|
|
2211
2215
|
session.pendingMessages = [];
|
|
2212
2216
|
}
|
|
@@ -2221,7 +2225,7 @@ function createSDKBridge(opts) {
|
|
|
2221
2225
|
handle.endInput();
|
|
2222
2226
|
}
|
|
2223
2227
|
|
|
2224
|
-
session
|
|
2228
|
+
bumpLastActivity(session, "query-start", slug);
|
|
2225
2229
|
session.streamPromise = processQueryStream(session).catch(function(err) {
|
|
2226
2230
|
console.error("[sdk-bridge] Unhandled stream error for session " + session.localId + ":", err && err.message || err);
|
|
2227
2231
|
sendToSession(session, { type: "error", text: "Stream error: " + (err && err.message || String(err)) });
|
|
@@ -2244,11 +2248,11 @@ function createSDKBridge(opts) {
|
|
|
2244
2248
|
}
|
|
2245
2249
|
}
|
|
2246
2250
|
|
|
2247
|
-
function pushMessage(session, text, images) {
|
|
2248
|
-
session
|
|
2251
|
+
function pushMessage(session, text, images, initiator) {
|
|
2252
|
+
bumpLastActivity(session, "push-message", slug);
|
|
2249
2253
|
// Route through QueryHandle (works for both in-process and worker paths)
|
|
2250
2254
|
if (session.queryInstance && typeof session.queryInstance.pushMessage === "function") {
|
|
2251
|
-
session.queryInstance.pushMessage(text, images);
|
|
2255
|
+
session.queryInstance.pushMessage(text, images, initiator);
|
|
2252
2256
|
} else {
|
|
2253
2257
|
// lr-b61b: queryInstance is null between turns (finally block has run but
|
|
2254
2258
|
// startQuery has not been called yet). Buffer the message so it is not
|
|
@@ -2264,7 +2268,7 @@ function createSDKBridge(opts) {
|
|
|
2264
2268
|
// so any candidate cause that lands a message here is visible.
|
|
2265
2269
|
var wasFull = session.pendingMessages.length >= MAX_PENDING_MESSAGES;
|
|
2266
2270
|
if (wasFull) session.pendingMessages.shift();
|
|
2267
|
-
session.pendingMessages.push({ text: text, images: images });
|
|
2271
|
+
session.pendingMessages.push({ text: text, images: images, initiator: initiator });
|
|
2268
2272
|
console.log("[sdk-bridge] pushMessage: queryInstance null, buffered message for session " + session.localId + " (pending=" + session.pendingMessages.length + ")");
|
|
2269
2273
|
sendAndRecord(session, {
|
|
2270
2274
|
type: "diagnostic",
|
|
@@ -2280,6 +2284,7 @@ function createSDKBridge(opts) {
|
|
|
2280
2284
|
function permissionPushTitle(toolName, input) {
|
|
2281
2285
|
if (!input) return "Claude wants to use " + toolName;
|
|
2282
2286
|
var file = input.file_path ? input.file_path.split(/[/\\]/).pop() : "";
|
|
2287
|
+
if (isAgentDispatchTool(toolName)) return "Claude wants to launch an agent";
|
|
2283
2288
|
switch (toolName) {
|
|
2284
2289
|
case "Bash": return "Claude wants to run a command";
|
|
2285
2290
|
case "Edit": return "Claude wants to edit " + (file || "a file");
|
|
@@ -2289,7 +2294,6 @@ function createSDKBridge(opts) {
|
|
|
2289
2294
|
case "Glob": return "Claude wants to find files";
|
|
2290
2295
|
case "WebFetch": return "Claude wants to fetch a URL";
|
|
2291
2296
|
case "WebSearch": return "Claude wants to search the web";
|
|
2292
|
-
case "Task": return "Claude wants to launch an agent";
|
|
2293
2297
|
default: return "Claude wants to use " + toolName;
|
|
2294
2298
|
}
|
|
2295
2299
|
}
|
|
@@ -2325,7 +2329,7 @@ function createSDKBridge(opts) {
|
|
|
2325
2329
|
// a null user is the daemon's own account.
|
|
2326
2330
|
function detectInstalledVendors(linuxUser) {
|
|
2327
2331
|
// The registry owns the probes and the allowlist of executable names.
|
|
2328
|
-
var state = require("./yoke").detectVendorInstallState(linuxUser || null);
|
|
2332
|
+
var state = require("./yoke").detectVendorInstallState(linuxUser || null, { osUsers: osUsersMode });
|
|
2329
2333
|
recordInstallState(sm, linuxUser || null, state);
|
|
2330
2334
|
return state.installed;
|
|
2331
2335
|
}
|
|
@@ -2593,12 +2597,7 @@ function createSDKBridge(opts) {
|
|
|
2593
2597
|
stopIdleReaper: stopIdleReaper,
|
|
2594
2598
|
getRuntimeEnvOverlay: getRuntimeEnvOverlay,
|
|
2595
2599
|
getMemoryStats: getMemoryStats,
|
|
2596
|
-
|
|
2597
|
-
// overwrite guard, following the _test_-prefixed exposure convention
|
|
2598
|
-
// already used by lib/yoke/adapters/codex.js's resolveTitleModel. Not
|
|
2599
|
-
// part of the bridge's real call surface (project.js never calls it by
|
|
2600
|
-
// this name) — it is the same closure onAutoTitle wraps internally.
|
|
2601
|
-
_test_autoGenerateTitle: autoGenerateTitle,
|
|
2600
|
+
refreshAiTitle: refreshAiTitle,
|
|
2602
2601
|
};
|
|
2603
2602
|
}
|
|
2604
2603
|
|