@clagentic/console 1.11.0 → 1.12.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/README.md +1 -0
- package/bin/cli.js +14 -2
- package/lib/build-changes.js +8 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +31 -7
- package/lib/claude-settings-env.js +142 -0
- package/lib/cli/arg-validation.js +1 -1
- package/lib/cli/duration.js +27 -0
- package/lib/cli/ipc-subcommands.js +26 -0
- package/lib/cli/schedule-input-subcommands.js +1 -22
- package/lib/cli/session-subcommands.js +38 -7
- package/lib/daemon.js +26 -0
- package/lib/notification-prefs.js +257 -0
- package/lib/notify/core.js +175 -0
- package/lib/notify/index.js +31 -0
- package/lib/notify/live-prompts.js +36 -0
- package/lib/notify/payload.js +63 -0
- package/lib/notify/target.js +5 -0
- package/lib/notify/type-registry.js +64 -0
- package/lib/notify/types.js +20 -0
- package/lib/open-sockets.js +27 -0
- package/lib/outbound-access.js +74 -0
- package/lib/outbound-entry.js +109 -0
- package/lib/outbound-ledger.js +306 -0
- package/lib/outbound-query.js +153 -0
- package/lib/pending-prompts.js +31 -16
- package/lib/project-connection.js +40 -1
- package/lib/project-filesystem.js +20 -5
- package/lib/project-http.js +9 -1
- package/lib/project-loop.js +25 -13
- package/lib/project-notifications.js +206 -42
- package/lib/project-prompt-responses.js +1 -1
- package/lib/project-sessions.js +30 -1
- package/lib/project.js +15 -1
- package/lib/prompt-registry.js +92 -24
- package/lib/prompt-reminders.js +282 -0
- package/lib/prompt-source.js +43 -8
- package/lib/public/app.js +1 -0
- package/lib/public/css/diagnostics.css +28 -0
- package/lib/public/css/home-hub.css +12 -0
- package/lib/public/css/icon-strip.css +9 -0
- package/lib/public/css/input.css +93 -0
- package/lib/public/css/menus.css +22 -0
- package/lib/public/css/mobile-nav.css +11 -0
- package/lib/public/css/server-settings.css +24 -0
- package/lib/public/css/sidebar.css +24 -0
- package/lib/public/index.html +6 -0
- package/lib/public/modules/activity-state.js +20 -4
- package/lib/public/modules/app-connection.js +22 -5
- package/lib/public/modules/app-header.js +2 -0
- package/lib/public/modules/app-messages.js +6 -2
- package/lib/public/modules/app-notifications.js +65 -40
- package/lib/public/modules/app-projects.js +3 -1
- package/lib/public/modules/app-rate-limit.js +12 -6
- package/lib/public/modules/app-rendering.js +26 -3
- package/lib/public/modules/build-update-sessions.js +81 -0
- package/lib/public/modules/collapsible-text.js +77 -0
- package/lib/public/modules/diagnostics.js +9 -2
- package/lib/public/modules/env-shadow-notice.js +34 -0
- package/lib/public/modules/keep-alive.js +66 -0
- package/lib/public/modules/notification-prefs.js +151 -0
- package/lib/public/modules/notify-client.js +153 -0
- package/lib/public/modules/project-settings.js +5 -0
- package/lib/public/modules/prompt-reminders-setting.js +13 -0
- package/lib/public/modules/prompt-state.js +3 -3
- package/lib/public/modules/prompts.js +1 -1
- package/lib/public/modules/server-settings.js +3 -0
- package/lib/public/modules/sidebar-mobile.js +8 -0
- package/lib/public/modules/sidebar-sessions.js +27 -0
- package/lib/public/modules/terminal-links.js +175 -0
- package/lib/public/modules/terminal.js +19 -103
- package/lib/public/notify-sw-logic.js +300 -0
- package/lib/public/notify-target.js +97 -0
- package/lib/public/sw.js +15 -62
- package/lib/push-audience.js +84 -0
- package/lib/push.js +87 -20
- package/lib/runtime-env.js +1 -0
- package/lib/sdk-bridge.js +83 -36
- package/lib/sdk-message-processor.js +148 -49
- package/lib/sender-ref.js +3 -0
- package/lib/server.js +80 -4
- package/lib/session-directory.js +6 -4
- package/lib/session-input-ipc.js +11 -1
- package/lib/session-input.js +95 -14
- package/lib/session-liveness.js +53 -0
- package/lib/session-reclaim.js +37 -2
- package/lib/sessions.js +58 -4
- package/lib/usage-store.js +403 -0
- package/lib/vendor-auth.js +33 -2
- package/lib/ws-schema.js +13 -2
- package/lib/yoke/adapters/claude-vendor.js +11 -1
- package/lib/yoke/adapters/claude.js +17 -0
- package/lib/yoke/adapters/codex.js +5 -1
- package/lib/yoke/auth-checks.js +17 -2
- package/lib/yoke/index.js +21 -3
- package/lib/yoke/provider-credentials.js +24 -0
- package/lib/yoke/registry.js +8 -1
- package/package.json +2 -2
- package/scripts/check-test-count.js +14 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Who a session's push notification (and its in-app reminder) goes to. The one
|
|
4
|
+
// rule behind every session-scoped push (permission request, elicitation,
|
|
5
|
+
// ask_user, response done, loop done, prompt reminders):
|
|
6
|
+
// - an owned session pushes to its owner only;
|
|
7
|
+
// - an ownerless session in single-user mode broadcasts (there is one person);
|
|
8
|
+
// - an ownerless session in multi-user mode pushes to the admins only. An
|
|
9
|
+
// admin can already read every ownerless session (canAccessSession admits
|
|
10
|
+
// only admins to one), so tool input in the payload crosses no visibility
|
|
11
|
+
// boundary. It is never a broadcast to every subscriber, and a session
|
|
12
|
+
// opened from a console session inherits that session's owner instead
|
|
13
|
+
// (lib/session-input.js), so it is rarely ownerless at all;
|
|
14
|
+
// - a mode that cannot be read counts as multi-user, the stricter mode.
|
|
15
|
+
|
|
16
|
+
var usersModule = require("./users");
|
|
17
|
+
|
|
18
|
+
function multiUserMode(isMultiUser) {
|
|
19
|
+
try {
|
|
20
|
+
return isMultiUser() !== false;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function defaultListAdmins() {
|
|
27
|
+
return usersModule.getAllUsers().filter(function (u) {
|
|
28
|
+
return u.role === "admin";
|
|
29
|
+
}).map(function (u) {
|
|
30
|
+
return u.id;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// The admin ids, or [] when the user store cannot be read: no audience beats a
|
|
35
|
+
// wider one.
|
|
36
|
+
function adminIds(listAdmins) {
|
|
37
|
+
try {
|
|
38
|
+
return (listAdmins || defaultListAdmins)() || [];
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {?string} ownerId the session's owner, if any.
|
|
46
|
+
* @param {function(): boolean} [isMultiUser] the daemon's mode; defaults to the
|
|
47
|
+
* users store.
|
|
48
|
+
* @param {function(): string[]} [listAdmins] the admin user ids; defaults to
|
|
49
|
+
* the users store.
|
|
50
|
+
* @returns {{kind: "owner"|"admins"|"broadcast", userIds: string[]}} kind
|
|
51
|
+
* "broadcast" has no ids: it means every subscriber (single-user mode).
|
|
52
|
+
* "admins" with no ids reaches no one.
|
|
53
|
+
*/
|
|
54
|
+
function audienceFor(ownerId, isMultiUser, listAdmins) {
|
|
55
|
+
if (ownerId) return { kind: "owner", userIds: [ownerId] };
|
|
56
|
+
if (multiUserMode(isMultiUser || usersModule.isMultiUser)) {
|
|
57
|
+
return { kind: "admins", userIds: adminIds(listAdmins) };
|
|
58
|
+
}
|
|
59
|
+
return { kind: "broadcast", userIds: [] };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {?object} pushModule the push module (sendPush, sendPushToUser).
|
|
64
|
+
* @param {?string} ownerId the session's owner, if any.
|
|
65
|
+
* @param {object} payload the push payload.
|
|
66
|
+
* @param {function(): boolean} [isMultiUser] see audienceFor.
|
|
67
|
+
* @param {function(): string[]} [listAdmins] see audienceFor.
|
|
68
|
+
* @returns {"owner"|"admins"|"broadcast"|"none"} where the push went.
|
|
69
|
+
*/
|
|
70
|
+
function pushForSession(pushModule, ownerId, payload, isMultiUser, listAdmins) {
|
|
71
|
+
if (!pushModule) return "none";
|
|
72
|
+
var audience = audienceFor(ownerId, isMultiUser, listAdmins);
|
|
73
|
+
if (audience.kind === "broadcast") {
|
|
74
|
+
pushModule.sendPush(payload);
|
|
75
|
+
return "broadcast";
|
|
76
|
+
}
|
|
77
|
+
if (typeof pushModule.sendPushToUser !== "function" || !audience.userIds.length) return "none";
|
|
78
|
+
audience.userIds.forEach(function (id) {
|
|
79
|
+
pushModule.sendPushToUser(id, payload);
|
|
80
|
+
});
|
|
81
|
+
return audience.kind;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = { audienceFor: audienceFor, pushForSession: pushForSession };
|
package/lib/push.js
CHANGED
|
@@ -3,6 +3,18 @@ var fs = require("fs");
|
|
|
3
3
|
var path = require("path");
|
|
4
4
|
var config = require("./config");
|
|
5
5
|
var store = require("./store");
|
|
6
|
+
var { categoryOfPush } = require("./notification-prefs");
|
|
7
|
+
var usersModule = require("./users");
|
|
8
|
+
|
|
9
|
+
// The daemon's mode; a mode that cannot be read counts as multi-user, the
|
|
10
|
+
// stricter one (same rule as lib/push-audience.js).
|
|
11
|
+
function multiUserMode(isMultiUser) {
|
|
12
|
+
try {
|
|
13
|
+
return isMultiUser() !== false;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
6
18
|
|
|
7
19
|
function loadOrCreateVapidKeys() {
|
|
8
20
|
var dir = config.CONFIG_DIR;
|
|
@@ -23,7 +35,21 @@ function loadOrCreateVapidKeys() {
|
|
|
23
35
|
return keys;
|
|
24
36
|
}
|
|
25
37
|
|
|
26
|
-
|
|
38
|
+
/**
|
|
39
|
+
* @param {object} [opts]
|
|
40
|
+
* @param {{allows: function(?string, string, ?string): boolean}} [opts.prefs]
|
|
41
|
+
* the per-user notification preferences (lib/notification-prefs.js). A push a
|
|
42
|
+
* user has muted is not sent to that user's subscriptions; this is the one
|
|
43
|
+
* place push is filtered, so a muted type never reaches the phone whichever
|
|
44
|
+
* caller raised it.
|
|
45
|
+
* @param {function(): boolean} [opts.isMultiUser] the daemon's mode; defaults to
|
|
46
|
+
* the users store. In multi-user mode a subscription with no user is neither
|
|
47
|
+
* stored nor sent to: nobody can say whose device it is.
|
|
48
|
+
*/
|
|
49
|
+
function initPush(opts) {
|
|
50
|
+
var prefs = opts && opts.prefs ? opts.prefs : null;
|
|
51
|
+
var isMultiUser = opts && opts.isMultiUser ? opts.isMultiUser : usersModule.isMultiUser;
|
|
52
|
+
|
|
27
53
|
var keys = loadOrCreateVapidKeys();
|
|
28
54
|
|
|
29
55
|
var vapidDetails = {
|
|
@@ -78,8 +104,16 @@ function initPush() {
|
|
|
78
104
|
})(startupEndpoints[si]);
|
|
79
105
|
}
|
|
80
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @returns {boolean} false when the subscription was refused: it has no
|
|
109
|
+
* endpoint, or it has no user in multi-user mode.
|
|
110
|
+
*/
|
|
81
111
|
function addSubscription(sub, replaceEndpoint, userId) {
|
|
82
|
-
if (!sub || !sub.endpoint) return;
|
|
112
|
+
if (!sub || !sub.endpoint) return false;
|
|
113
|
+
if (!userId && multiUserMode(isMultiUser)) {
|
|
114
|
+
console.log("[push] refused anonymous subscription in multi-user mode");
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
83
117
|
// Remove previous subscription from the same client if endpoint changed.
|
|
84
118
|
// Only delete replaceEndpoint if it belongs to the same caller — prevents an
|
|
85
119
|
// unauthenticated request from unsubscribing arbitrary known endpoints.
|
|
@@ -95,8 +129,14 @@ function initPush() {
|
|
|
95
129
|
subscriptions.delete(replaceEndpoint);
|
|
96
130
|
}
|
|
97
131
|
}
|
|
98
|
-
// Attach userId for per-user targeting
|
|
99
|
-
|
|
132
|
+
// Attach userId for per-user targeting. An authenticated re-register of an
|
|
133
|
+
// endpoint stored without a user claims it, so a device subscribed before
|
|
134
|
+
// the user was recorded recovers when its client re-sends the subscription.
|
|
135
|
+
if (userId) {
|
|
136
|
+
var stored = subscriptions.get(sub.endpoint);
|
|
137
|
+
if (stored && !stored._userId) console.log("[push] claimed anonymous subscription user=" + userId);
|
|
138
|
+
sub._userId = userId;
|
|
139
|
+
}
|
|
100
140
|
// Store immediately, then validate async. Invalid subs get cleaned on first sendPush.
|
|
101
141
|
subscriptions.set(sub.endpoint, sub);
|
|
102
142
|
save();
|
|
@@ -116,34 +156,60 @@ function initPush() {
|
|
|
116
156
|
save();
|
|
117
157
|
}
|
|
118
158
|
|
|
159
|
+
// One journal line per decision: identifiers and the type only, never the
|
|
160
|
+
// title or body (they carry tool input and response text).
|
|
161
|
+
function wanted(sub, payload) {
|
|
162
|
+
var category = categoryOfPush(payload);
|
|
163
|
+
var userId = sub._userId || null;
|
|
164
|
+
var allowed = !prefs || prefs.allows(userId, "push", category);
|
|
165
|
+
console.log("[push] " + (allowed ? "sending" : "muted") + " type=" + payload.type + " category=" + (category || "none") + " user=" + (userId || "default"));
|
|
166
|
+
return allowed;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Sends still on the wire, so a shutdown can wait for them (flush).
|
|
170
|
+
var inflight = new Set();
|
|
171
|
+
|
|
172
|
+
function sendTo(sub, endpoint, json) {
|
|
173
|
+
var sent = webpush.sendNotification(sub, json, { vapidDetails: vapidDetails })
|
|
174
|
+
.then(function () {})
|
|
175
|
+
.catch(function (err) {
|
|
176
|
+
if (err.statusCode === 410 || err.statusCode === 404 || err.statusCode === 403) {
|
|
177
|
+
subscriptions.delete(endpoint);
|
|
178
|
+
save();
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
.then(function () { inflight.delete(sent); });
|
|
182
|
+
inflight.add(sent);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Resolves once every push sent so far has been handed to the push service. */
|
|
186
|
+
function flush() {
|
|
187
|
+
return Promise.all(Array.from(inflight));
|
|
188
|
+
}
|
|
189
|
+
|
|
119
190
|
function sendPush(payload) {
|
|
120
191
|
var json = JSON.stringify(payload);
|
|
192
|
+
var multi = multiUserMode(isMultiUser);
|
|
121
193
|
subscriptions.forEach(function (sub, endpoint) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
save();
|
|
128
|
-
}
|
|
129
|
-
});
|
|
194
|
+
// A subscription stored before users were recorded has no owner; in
|
|
195
|
+
// multi-user mode a broadcast must not reach a device nobody can name.
|
|
196
|
+
if (multi && !sub._userId) return;
|
|
197
|
+
if (!wanted(sub, payload)) return;
|
|
198
|
+
sendTo(sub, endpoint, json);
|
|
130
199
|
});
|
|
131
200
|
}
|
|
132
201
|
|
|
133
202
|
function sendPushToUser(userId, payload) {
|
|
134
203
|
if (!userId) return;
|
|
135
204
|
var json = JSON.stringify(payload);
|
|
205
|
+
var matched = 0;
|
|
136
206
|
subscriptions.forEach(function (sub, endpoint) {
|
|
137
207
|
if (sub._userId !== userId) return;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (err.statusCode === 410 || err.statusCode === 404 || err.statusCode === 403) {
|
|
142
|
-
subscriptions.delete(endpoint);
|
|
143
|
-
save();
|
|
144
|
-
}
|
|
145
|
-
});
|
|
208
|
+
matched++;
|
|
209
|
+
if (!wanted(sub, payload)) return;
|
|
210
|
+
sendTo(sub, endpoint, json);
|
|
146
211
|
});
|
|
212
|
+
if (!matched) console.log("[push] no-subscription user=" + userId + " type=" + payload.type);
|
|
147
213
|
}
|
|
148
214
|
|
|
149
215
|
return {
|
|
@@ -152,6 +218,7 @@ function initPush() {
|
|
|
152
218
|
removeSubscription: removeSubscription,
|
|
153
219
|
sendPush: sendPush,
|
|
154
220
|
sendPushToUser: sendPushToUser,
|
|
221
|
+
flush: flush,
|
|
155
222
|
};
|
|
156
223
|
}
|
|
157
224
|
|
package/lib/runtime-env.js
CHANGED
package/lib/sdk-bridge.js
CHANGED
|
@@ -3,6 +3,8 @@ var path = require("path");
|
|
|
3
3
|
var execSync = require("child_process").execSync;
|
|
4
4
|
var execFileSync = require("child_process").execFileSync;
|
|
5
5
|
var usersModule = require("./users");
|
|
6
|
+
var openSockets = require("./open-sockets");
|
|
7
|
+
var { notifyFor } = require("./notify");
|
|
6
8
|
var { getCodexConfig } = require("./codex-defaults");
|
|
7
9
|
var { isAutoApprovableSegment } = require("./bash-auto-approve");
|
|
8
10
|
var { splitShellSegments, hasUnapprovableShellSyntax, attachSkillDiscovery, discoverSkillsWithMeta, mergeSkillsWithMeta } = require("./sdk-skill-discovery");
|
|
@@ -16,6 +18,7 @@ var { promptsFor } = require("./prompt-registry");
|
|
|
16
18
|
var { toolApprovalKind } = require("./prompt-kinds");
|
|
17
19
|
var sessionActivity = require("./session-activity");
|
|
18
20
|
var sessionReclaim = require("./session-reclaim");
|
|
21
|
+
var usageStore = require("./usage-store");
|
|
19
22
|
var { withPromptLabel } = require("./prompt-label");
|
|
20
23
|
var { isAgentDispatchTool } = require("./agent-dispatch-tool");
|
|
21
24
|
var permissionSummary = require("./permission-summary");
|
|
@@ -25,9 +28,10 @@ var mcpToolSchema = require("./mcp-tool-schema");
|
|
|
25
28
|
var { registry: yokeRegistry } = require("./yoke");
|
|
26
29
|
var sessionCapabilities = require("./session-capabilities");
|
|
27
30
|
var { buildVendorRegistryMessage, recordInstallState } = require("./vendor-registry-message");
|
|
28
|
-
var { authRequiredFacts } = require("./vendor-auth");
|
|
31
|
+
var { authRequiredFacts, providerAuthFailure } = require("./vendor-auth");
|
|
29
32
|
var { bumpLastActivity } = require("./activity-clock");
|
|
30
33
|
var { logField } = require("./log-field");
|
|
34
|
+
var { debugLog } = require("./debug-log");
|
|
31
35
|
var { checkPermissionMode } = require("./permission-mode-policy");
|
|
32
36
|
var { reserveNameOnRevival } = require("./session-name-holder");
|
|
33
37
|
var { createAiTitleRefresher } = require("./session-ai-title");
|
|
@@ -166,6 +170,7 @@ function buildActivityDiagnosticsResponse() {
|
|
|
166
170
|
activeLiveCount: getActiveLiveCount(),
|
|
167
171
|
activityDivergenceCount: divergence.count,
|
|
168
172
|
activityDivergenceRecentSamples: divergence.recentSamples,
|
|
173
|
+
openSockets: openSockets.snapshot(),
|
|
169
174
|
};
|
|
170
175
|
}
|
|
171
176
|
|
|
@@ -522,18 +527,37 @@ function createSDKBridge(opts) {
|
|
|
522
527
|
var _cachedFreshAuthState = null;
|
|
523
528
|
var _cachedFreshAuthAt = 0;
|
|
524
529
|
|
|
525
|
-
|
|
530
|
+
var _cachedFreshAuthSig = null;
|
|
531
|
+
|
|
532
|
+
// The auth probes read the environment the session's runtime starts with
|
|
533
|
+
// (Settings over the daemon's), so a provider chosen in Settings counts.
|
|
534
|
+
function getFreshAuthState(force, session) {
|
|
526
535
|
var yoke = require("./yoke");
|
|
527
536
|
var now = Date.now();
|
|
528
|
-
|
|
537
|
+
var overlay = getRuntimeEnvOverlay(session);
|
|
538
|
+
var sig = runtimeEnv.envSignature(overlay) + "\0" + (osUsersMode ? "os" : "");
|
|
539
|
+
if (!force && _cachedFreshAuthState && _cachedFreshAuthSig === sig && now - _cachedFreshAuthAt < 15000) {
|
|
529
540
|
return _cachedFreshAuthState;
|
|
530
541
|
}
|
|
531
542
|
if (force) yoke.invalidateAuthCache();
|
|
532
|
-
_cachedFreshAuthState = yoke.checkAuth();
|
|
543
|
+
_cachedFreshAuthState = yoke.checkAuth(overlay, osUsersMode);
|
|
544
|
+
_cachedFreshAuthSig = sig;
|
|
533
545
|
_cachedFreshAuthAt = now;
|
|
534
546
|
return _cachedFreshAuthState;
|
|
535
547
|
}
|
|
536
548
|
|
|
549
|
+
// The environment a session's runtime is started with: the daemon's own,
|
|
550
|
+
// then the Settings variables. The same composition the spawn performs.
|
|
551
|
+
function getEffectiveRuntimeEnv(session) {
|
|
552
|
+
return runtimeEnv.composeRuntimeEnv(process.env, getRuntimeEnvOverlay(session));
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// The message that replaces "not logged in" when the session's agent talks
|
|
556
|
+
// to a configured cloud provider, or null.
|
|
557
|
+
function providerFailureFor(session, vendorId) {
|
|
558
|
+
return providerAuthFailure(vendorId, getEffectiveRuntimeEnv(session), osUsersMode);
|
|
559
|
+
}
|
|
560
|
+
|
|
537
561
|
function isAuthErrorMessage(errDetail) {
|
|
538
562
|
if (!errDetail) return false;
|
|
539
563
|
var errLower = String(errDetail).toLowerCase();
|
|
@@ -704,6 +728,7 @@ function createSDKBridge(opts) {
|
|
|
704
728
|
_idleReaperTimer = setInterval(function () {
|
|
705
729
|
var now = Date.now();
|
|
706
730
|
var skippedForPrompt = [];
|
|
731
|
+
var skippedForKeepAlive = [];
|
|
707
732
|
sm.sessions.forEach(function (session) {
|
|
708
733
|
if (session.destroying) return;
|
|
709
734
|
|
|
@@ -740,10 +765,23 @@ function createSDKBridge(opts) {
|
|
|
740
765
|
|
|
741
766
|
// Skip sessions that are actively processing, have no query,
|
|
742
767
|
// or are single-turn (Ralph Loop — managed by onQueryComplete).
|
|
743
|
-
|
|
768
|
+
// A session busy only through background agents is waiting on them,
|
|
769
|
+
// not running a turn: it stays reapable, so a silent agent is named
|
|
770
|
+
// in the reclaim notice instead of pinning the session forever.
|
|
771
|
+
if (session.isProcessing && !sessionReclaim.onlyBackgroundAgentsActive(session)) return;
|
|
744
772
|
if (!session.queryInstance) return;
|
|
745
773
|
if (session.singleTurn) return;
|
|
746
774
|
|
|
775
|
+
// Operator-set keep-alive: a coordinator that idles waiting on other
|
|
776
|
+
// sessions' messages emits nothing, so its silence is not evidence it
|
|
777
|
+
// is abandoned. Only the operator unpinning it (or memory pressure,
|
|
778
|
+
// lib/memory-shed.js, which does not read this flag) ends it.
|
|
779
|
+
if (session.keepAlive) {
|
|
780
|
+
skippedForKeepAlive.push(logField(session.localId)
|
|
781
|
+
+ ":idle=" + Math.round((now - (session.lastActivityAt || 0)) / 60000) + "min");
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
|
|
747
785
|
// A session with an open prompt (its own, or a background agent's) is
|
|
748
786
|
// waiting on the operator, not idle: an agent blocked on a prompt
|
|
749
787
|
// emits no stream events, so the activity clock cannot tell. Ending
|
|
@@ -783,6 +821,11 @@ function createSDKBridge(opts) {
|
|
|
783
821
|
}
|
|
784
822
|
}
|
|
785
823
|
});
|
|
824
|
+
if (skippedForKeepAlive.length) {
|
|
825
|
+
debugLog("[sdk-bridge] Idle reaper: skipped " + skippedForKeepAlive.length
|
|
826
|
+
+ " keep-alive session(s): project=" + logField(slug)
|
|
827
|
+
+ " sessions=" + skippedForKeepAlive.join(","));
|
|
828
|
+
}
|
|
786
829
|
// One line per sweep, so "a session with an open prompt is never reaped"
|
|
787
830
|
// can be read from the journal rather than inferred from its absence.
|
|
788
831
|
if (skippedForPrompt.length) {
|
|
@@ -850,6 +893,7 @@ function createSDKBridge(opts) {
|
|
|
850
893
|
// a shared multi-user daemon. usersModule.findUserById(session.ownerId)
|
|
851
894
|
// is the same pattern already used elsewhere in this file (getFreshAuthState).
|
|
852
895
|
resolveSessionHome: resolveOwnerHome,
|
|
896
|
+
providerFailureFor: providerFailureFor,
|
|
853
897
|
});
|
|
854
898
|
var processSDKMessage = msgProcessor.processSDKMessage;
|
|
855
899
|
var sendAndRecord = msgProcessor.sendAndRecord;
|
|
@@ -867,19 +911,15 @@ function createSDKBridge(opts) {
|
|
|
867
911
|
|
|
868
912
|
// No push for a prompt that ended at once (its signal was already aborted).
|
|
869
913
|
if (pushModule && opened.pending) {
|
|
870
|
-
|
|
871
|
-
|
|
914
|
+
// Body carries MCP message text: owner only, never a blind broadcast.
|
|
915
|
+
notifyFor(pushModule).notify("elicitation", {
|
|
872
916
|
slug: slug,
|
|
917
|
+
sessionId: session.localId,
|
|
918
|
+
requestId: opened.requestId,
|
|
919
|
+
}, {
|
|
873
920
|
title: (request.serverName || "MCP Server") + " needs input",
|
|
874
921
|
body: withPromptLabel(opened.label, request.message || "Waiting for your response"),
|
|
875
|
-
|
|
876
|
-
};
|
|
877
|
-
// Route to session owner only — body carries MCP message text.
|
|
878
|
-
if (session.ownerId && pushModule.sendPushToUser) {
|
|
879
|
-
pushModule.sendPushToUser(session.ownerId, _elicitPayload);
|
|
880
|
-
} else {
|
|
881
|
-
pushModule.sendPush(_elicitPayload);
|
|
882
|
-
}
|
|
922
|
+
}, { ownerId: session.ownerId });
|
|
883
923
|
}
|
|
884
924
|
|
|
885
925
|
return opened.answer;
|
|
@@ -1168,31 +1208,16 @@ function createSDKBridge(opts) {
|
|
|
1168
1208
|
notification: {
|
|
1169
1209
|
title: agentPrefix + permissionPushTitle(toolName, input),
|
|
1170
1210
|
body: permissionPushBody(toolName, input),
|
|
1211
|
+
// Body carries tool name and input (may contain paths/code); the core
|
|
1212
|
+
// sends it to the session's owner only, never as a blind broadcast.
|
|
1213
|
+
push: { title: agentPrefix + permissionPushTitle(toolName, input), body: permissionPushBody(toolName, input) },
|
|
1171
1214
|
slug: slug,
|
|
1172
1215
|
sessionId: session.localId,
|
|
1173
|
-
ownerId: session.ownerId || null,
|
|
1174
1216
|
toolName: toolName,
|
|
1175
1217
|
toolInput: input,
|
|
1176
1218
|
},
|
|
1177
1219
|
});
|
|
1178
1220
|
|
|
1179
|
-
// No push for a prompt that ended at once (its signal was already aborted).
|
|
1180
|
-
if (pushModule && opened.pending) {
|
|
1181
|
-
var _permPayload = {
|
|
1182
|
-
type: "permission_request",
|
|
1183
|
-
slug: slug,
|
|
1184
|
-
requestId: opened.requestId,
|
|
1185
|
-
title: agentPrefix + permissionPushTitle(toolName, input),
|
|
1186
|
-
body: withPromptLabel(opened.label, permissionPushBody(toolName, input)),
|
|
1187
|
-
};
|
|
1188
|
-
// Route to session owner only — body carries tool name and input (may contain paths/code).
|
|
1189
|
-
if (session.ownerId && pushModule.sendPushToUser) {
|
|
1190
|
-
pushModule.sendPushToUser(session.ownerId, _permPayload);
|
|
1191
|
-
} else {
|
|
1192
|
-
pushModule.sendPush(_permPayload);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
1221
|
return opened.answer;
|
|
1197
1222
|
}
|
|
1198
1223
|
|
|
@@ -1385,13 +1410,19 @@ function createSDKBridge(opts) {
|
|
|
1385
1410
|
|| errLower.indexOf("context_length") !== -1
|
|
1386
1411
|
|| errLower.indexOf("maximum context length") !== -1;
|
|
1387
1412
|
var isAuthError = isAuthErrorMessage(errDetail);
|
|
1413
|
+
var providerFail = null;
|
|
1388
1414
|
if (isContextOverflow) {
|
|
1389
1415
|
sendAndRecord(session, {
|
|
1390
1416
|
type: "context_overflow",
|
|
1391
1417
|
text: "Conversation too long to continue.",
|
|
1392
1418
|
});
|
|
1419
|
+
} else if (isAuthError && (providerFail = providerFailureFor(session, sessionVendorId(session)))) {
|
|
1420
|
+
sendAndRecord(session, { type: "error", text: providerFail.message });
|
|
1421
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1422
|
+
sm.broadcastSessionList();
|
|
1423
|
+
return;
|
|
1393
1424
|
} else if (isAuthError) {
|
|
1394
|
-
var freshAuth = getFreshAuthState();
|
|
1425
|
+
var freshAuth = getFreshAuthState(false, session);
|
|
1395
1426
|
logAuthDecision("catch-auth-error", session, errDetail, freshAuth);
|
|
1396
1427
|
if (freshAuth[session.vendor]) {
|
|
1397
1428
|
sendAndRecord(session, {
|
|
@@ -1435,6 +1466,9 @@ function createSDKBridge(opts) {
|
|
|
1435
1466
|
sm.broadcastSessionList();
|
|
1436
1467
|
}
|
|
1437
1468
|
} finally {
|
|
1469
|
+
// Unguarded on purpose: our process is gone even if a newer query replaced it,
|
|
1470
|
+
// so this session can no longer confirm account usage.
|
|
1471
|
+
usageStore.endProcess(usageStore.usageVendorFor(session, adapter), session.localId, myQueryInstance);
|
|
1438
1472
|
// Close the SDK query to terminate the underlying claude child process.
|
|
1439
1473
|
// Without this, the process stays alive indefinitely (single-user mode).
|
|
1440
1474
|
// Only clean up if the session still references OUR resources.
|
|
@@ -1512,6 +1546,10 @@ function createSDKBridge(opts) {
|
|
|
1512
1546
|
promptsFor(sm).endQuery(session, myQueryInstance, ownsSession);
|
|
1513
1547
|
if (ownsSession) {
|
|
1514
1548
|
msgProcessor.retainTaskIdMap(session);
|
|
1549
|
+
// The query's end took its background agents down; only a Task still
|
|
1550
|
+
// owning an open prompt stays tracked, so every other token (a
|
|
1551
|
+
// launched agent's included) is released here.
|
|
1552
|
+
msgProcessor.releaseTurnActivity(session);
|
|
1515
1553
|
|
|
1516
1554
|
// Auto-continue on rate limit (scheduler sessions, or user setting)
|
|
1517
1555
|
// Mark session as done processing so the late rate_limit_event handler
|
|
@@ -1757,7 +1795,7 @@ function createSDKBridge(opts) {
|
|
|
1757
1795
|
await ensureVendorReady(session.vendor);
|
|
1758
1796
|
}
|
|
1759
1797
|
if (session.vendor && !adapters[session.vendor]) {
|
|
1760
|
-
var freshAuth = getFreshAuthState();
|
|
1798
|
+
var freshAuth = getFreshAuthState(false, session);
|
|
1761
1799
|
logAuthDecision("pre-auth-required", session, null, freshAuth);
|
|
1762
1800
|
if (freshAuth[session.vendor]) {
|
|
1763
1801
|
var recoveredAdapter = await ensureVendorReady(session.vendor);
|
|
@@ -1774,7 +1812,7 @@ function createSDKBridge(opts) {
|
|
|
1774
1812
|
var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
|
|
1775
1813
|
var canAutoLogin = !!authLinuxUser
|
|
1776
1814
|
|| (authUser && authUser.role === "admin");
|
|
1777
|
-
var authState = getFreshAuthState();
|
|
1815
|
+
var authState = getFreshAuthState(false, session);
|
|
1778
1816
|
logAuthDecision("emit-auth-required", session, "missing adapter", authState);
|
|
1779
1817
|
if (authState[session.vendor]) {
|
|
1780
1818
|
sendAndRecord(session, {
|
|
@@ -1784,6 +1822,14 @@ function createSDKBridge(opts) {
|
|
|
1784
1822
|
sendAndRecord(session, { type: "done", code: 1 });
|
|
1785
1823
|
return;
|
|
1786
1824
|
}
|
|
1825
|
+
// A provider selected in the environment whose credential set is
|
|
1826
|
+
// incomplete: naming the provider, not offering a sign-in.
|
|
1827
|
+
var providerFailure = providerFailureFor(session, session.vendor);
|
|
1828
|
+
if (providerFailure) {
|
|
1829
|
+
sendAndRecord(session, { type: "error", text: providerFailure.message });
|
|
1830
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1787
1833
|
var authMsg2 = {
|
|
1788
1834
|
type: "auth_required",
|
|
1789
1835
|
text: authFacts2.title,
|
|
@@ -2694,6 +2740,7 @@ function createSDKBridge(opts) {
|
|
|
2694
2740
|
startIdleReaper: startIdleReaper,
|
|
2695
2741
|
stopIdleReaper: stopIdleReaper,
|
|
2696
2742
|
getRuntimeEnvOverlay: getRuntimeEnvOverlay,
|
|
2743
|
+
providerFailureFor: providerFailureFor,
|
|
2697
2744
|
getMemoryStats: getMemoryStats,
|
|
2698
2745
|
refreshAiTitle: refreshAiTitle,
|
|
2699
2746
|
};
|