@clagentic/console 1.0.0-beta.1
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/CREDITS.md +3 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/bin/cli.js +2812 -0
- package/lib/agents-favorites.js +164 -0
- package/lib/agents.js +282 -0
- package/lib/ask-user-mcp-server.js +120 -0
- package/lib/browser-mcp-server.js +484 -0
- package/lib/build-user-env.js +63 -0
- package/lib/certs/fullchain.pem +47 -0
- package/lib/certs/privkey.pem +5 -0
- package/lib/cli-sessions.js +265 -0
- package/lib/codex-defaults.js +18 -0
- package/lib/config.js +332 -0
- package/lib/crisis-safety.js +60 -0
- package/lib/daemon-projects.js +164 -0
- package/lib/daemon.js +1602 -0
- package/lib/dm.js +128 -0
- package/lib/ipc.js +125 -0
- package/lib/ipv4-only.js +39 -0
- package/lib/mcp-local.js +385 -0
- package/lib/notes.js +141 -0
- package/lib/os-users.js +529 -0
- package/lib/pages.js +1325 -0
- package/lib/project-connection.js +302 -0
- package/lib/project-external-trigger.js +236 -0
- package/lib/project-file-watch.js +120 -0
- package/lib/project-filesystem.js +528 -0
- package/lib/project-http.js +753 -0
- package/lib/project-image.js +95 -0
- package/lib/project-knowledge.js +88 -0
- package/lib/project-loop.js +1304 -0
- package/lib/project-mcp.js +374 -0
- package/lib/project-memory.js +39 -0
- package/lib/project-notifications.js +262 -0
- package/lib/project-sessions.js +1581 -0
- package/lib/project-user-mention.js +193 -0
- package/lib/project-user-message.js +628 -0
- package/lib/project.js +1303 -0
- package/lib/public/app.js +1031 -0
- package/lib/public/apple-touch-icon.png +0 -0
- package/lib/public/claude-code-avatar.png +0 -0
- package/lib/public/codex-avatar.png +0 -0
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/admin.css +736 -0
- package/lib/public/css/agent-picker.css +119 -0
- package/lib/public/css/base.css +235 -0
- package/lib/public/css/channel-layout.css +441 -0
- package/lib/public/css/command-palette.css +559 -0
- package/lib/public/css/debate.css +1609 -0
- package/lib/public/css/diff.css +139 -0
- package/lib/public/css/filebrowser.css +1976 -0
- package/lib/public/css/highlight.css +144 -0
- package/lib/public/css/home-hub.css +545 -0
- package/lib/public/css/icon-strip.css +1856 -0
- package/lib/public/css/input.css +1349 -0
- package/lib/public/css/loop.css +1248 -0
- package/lib/public/css/mention.css +317 -0
- package/lib/public/css/menus.css +857 -0
- package/lib/public/css/messages.css +1833 -0
- package/lib/public/css/mobile-nav.css +1332 -0
- package/lib/public/css/notifications-center.css +296 -0
- package/lib/public/css/overlays.css +1273 -0
- package/lib/public/css/playbook.css +264 -0
- package/lib/public/css/profile.css +397 -0
- package/lib/public/css/rewind.css +671 -0
- package/lib/public/css/scheduler-modal.css +1495 -0
- package/lib/public/css/scheduler.css +1420 -0
- package/lib/public/css/server-settings.css +909 -0
- package/lib/public/css/session-search.css +159 -0
- package/lib/public/css/sidebar.css +2012 -0
- package/lib/public/css/skills.css +789 -0
- package/lib/public/css/sticky-notes.css +854 -0
- package/lib/public/css/stt.css +155 -0
- package/lib/public/css/title-bar.css +674 -0
- package/lib/public/css/tooltip.css +67 -0
- package/lib/public/css/user-settings.css +702 -0
- package/lib/public/emoji-data.json +1 -0
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-banded.png +0 -0
- package/lib/public/favicon-dark.svg +32 -0
- package/lib/public/favicon.svg +32 -0
- package/lib/public/icon-192.png +0 -0
- package/lib/public/icon-512.png +0 -0
- package/lib/public/icon-banded-76.png +0 -0
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icon-mono.svg +25 -0
- package/lib/public/icons/email/gmail.svg +7 -0
- package/lib/public/icons/email/outlook.svg +35 -0
- package/lib/public/icons/email/yahoo.svg +1 -0
- package/lib/public/index.html +1946 -0
- package/lib/public/manifest.json +27 -0
- package/lib/public/markdown-worker.js +43 -0
- package/lib/public/marked.min.js +6 -0
- package/lib/public/modules/admin.js +954 -0
- package/lib/public/modules/agent-picker.js +429 -0
- package/lib/public/modules/app-connection.js +216 -0
- package/lib/public/modules/app-cursors.js +492 -0
- package/lib/public/modules/app-dm.js +265 -0
- package/lib/public/modules/app-favicon.js +231 -0
- package/lib/public/modules/app-header.js +242 -0
- package/lib/public/modules/app-home-hub.js +432 -0
- package/lib/public/modules/app-loop-ui.js +691 -0
- package/lib/public/modules/app-loop-wizard.js +439 -0
- package/lib/public/modules/app-messages.js +1415 -0
- package/lib/public/modules/app-misc.js +463 -0
- package/lib/public/modules/app-notifications.js +651 -0
- package/lib/public/modules/app-panels.js +1061 -0
- package/lib/public/modules/app-projects.js +875 -0
- package/lib/public/modules/app-rate-limit.js +529 -0
- package/lib/public/modules/app-rendering.js +739 -0
- package/lib/public/modules/app-skills-install.js +285 -0
- package/lib/public/modules/avatar.js +36 -0
- package/lib/public/modules/command-palette.js +491 -0
- package/lib/public/modules/console-logo.js +162 -0
- package/lib/public/modules/context-sources.js +365 -0
- package/lib/public/modules/diff.js +412 -0
- package/lib/public/modules/dom-refs.js +21 -0
- package/lib/public/modules/emoji-picker.js +222 -0
- package/lib/public/modules/events.js +21 -0
- package/lib/public/modules/filebrowser.js +1966 -0
- package/lib/public/modules/fileicons.js +172 -0
- package/lib/public/modules/icons.js +80 -0
- package/lib/public/modules/input.js +1102 -0
- package/lib/public/modules/longpress.js +74 -0
- package/lib/public/modules/markdown.js +486 -0
- package/lib/public/modules/mcp-ui.js +295 -0
- package/lib/public/modules/mention.js +1093 -0
- package/lib/public/modules/notifications.js +613 -0
- package/lib/public/modules/playbook.js +578 -0
- package/lib/public/modules/profile.js +594 -0
- package/lib/public/modules/project-settings.js +849 -0
- package/lib/public/modules/project-switcher.js +375 -0
- package/lib/public/modules/qrcode.js +87 -0
- package/lib/public/modules/rewind.js +381 -0
- package/lib/public/modules/scheduler-config.js +1611 -0
- package/lib/public/modules/scheduler-history.js +131 -0
- package/lib/public/modules/scheduler.js +1689 -0
- package/lib/public/modules/server-settings.js +842 -0
- package/lib/public/modules/session-search.js +456 -0
- package/lib/public/modules/settings-defaults.js +253 -0
- package/lib/public/modules/sidebar-mobile.js +1425 -0
- package/lib/public/modules/sidebar-projects.js +2022 -0
- package/lib/public/modules/sidebar-sessions.js +1548 -0
- package/lib/public/modules/sidebar-users.js +449 -0
- package/lib/public/modules/sidebar.js +348 -0
- package/lib/public/modules/skills.js +793 -0
- package/lib/public/modules/state.js +3 -0
- package/lib/public/modules/sticky-notes.js +1221 -0
- package/lib/public/modules/store.js +34 -0
- package/lib/public/modules/stt.js +266 -0
- package/lib/public/modules/terminal.js +987 -0
- package/lib/public/modules/theme.js +812 -0
- package/lib/public/modules/tool-palette.js +562 -0
- package/lib/public/modules/tools.js +2285 -0
- package/lib/public/modules/tooltip.js +150 -0
- package/lib/public/modules/user-settings.js +544 -0
- package/lib/public/modules/utils.js +56 -0
- package/lib/public/modules/ws-ref.js +26 -0
- package/lib/public/style.css +34 -0
- package/lib/public/sw.js +159 -0
- package/lib/push.js +149 -0
- package/lib/scheduler.js +471 -0
- package/lib/sdk-bridge.js +1792 -0
- package/lib/sdk-message-processor.js +740 -0
- package/lib/sdk-message-queue.js +42 -0
- package/lib/sdk-skill-discovery.js +131 -0
- package/lib/sdk-worker.js +677 -0
- package/lib/server-admin.js +712 -0
- package/lib/server-auth.js +737 -0
- package/lib/server-dm.js +170 -0
- package/lib/server-palette.js +104 -0
- package/lib/server-settings.js +553 -0
- package/lib/server-skills.js +280 -0
- package/lib/server.js +1390 -0
- package/lib/session-search.js +693 -0
- package/lib/sessions.js +946 -0
- package/lib/smtp.js +221 -0
- package/lib/terminal-manager.js +219 -0
- package/lib/terminal.js +39 -0
- package/lib/themes/ayu-light.json +9 -0
- package/lib/themes/catppuccin-latte.json +9 -0
- package/lib/themes/catppuccin-mocha.json +9 -0
- package/lib/themes/clagentic-dark.json +10 -0
- package/lib/themes/clagentic-light.json +10 -0
- package/lib/themes/dracula.json +9 -0
- package/lib/themes/everforest-light.json +9 -0
- package/lib/themes/everforest.json +9 -0
- package/lib/themes/github-light.json +9 -0
- package/lib/themes/gruvbox-dark.json +9 -0
- package/lib/themes/gruvbox-light.json +9 -0
- package/lib/themes/monokai.json +9 -0
- package/lib/themes/nord-light.json +9 -0
- package/lib/themes/nord.json +9 -0
- package/lib/themes/one-dark.json +9 -0
- package/lib/themes/one-light.json +9 -0
- package/lib/themes/rose-pine-dawn.json +9 -0
- package/lib/themes/rose-pine.json +9 -0
- package/lib/themes/solarized-dark.json +9 -0
- package/lib/themes/solarized-light.json +9 -0
- package/lib/themes/tokyo-night-light.json +9 -0
- package/lib/themes/tokyo-night.json +9 -0
- package/lib/updater.js +124 -0
- package/lib/user-presence.js +92 -0
- package/lib/users-auth.js +146 -0
- package/lib/users-permissions.js +118 -0
- package/lib/users-preferences.js +254 -0
- package/lib/users.js +465 -0
- package/lib/utils.js +64 -0
- package/lib/worktree.js +134 -0
- package/lib/ws-schema.js +464 -0
- package/lib/yoke/adapters/claude-worker.js +759 -0
- package/lib/yoke/adapters/claude.js +1599 -0
- package/lib/yoke/adapters/codex.js +1559 -0
- package/lib/yoke/codex-app-server.js +352 -0
- package/lib/yoke/index.js +319 -0
- package/lib/yoke/instructions.js +61 -0
- package/lib/yoke/interface.js +98 -0
- package/lib/yoke/mcp-bridge-server.js +302 -0
- package/lib/yoke/package.json +7 -0
- package/package.json +72 -0
|
@@ -0,0 +1,1792 @@
|
|
|
1
|
+
const crypto = require("crypto");
|
|
2
|
+
var fs = require("fs");
|
|
3
|
+
var path = require("path");
|
|
4
|
+
var execSync = require("child_process").execSync;
|
|
5
|
+
var execFileSync = require("child_process").execFileSync;
|
|
6
|
+
var usersModule = require("./users");
|
|
7
|
+
var { getCodexConfig } = require("./codex-defaults");
|
|
8
|
+
var { splitShellSegments, attachSkillDiscovery } = require("./sdk-skill-discovery");
|
|
9
|
+
var { createMessageQueue } = require("./sdk-message-queue");
|
|
10
|
+
var { attachMessageProcessor } = require("./sdk-message-processor");
|
|
11
|
+
var agentsModule = require("./agents");
|
|
12
|
+
|
|
13
|
+
// Extract serializable tool descriptors from MCP server instances.
|
|
14
|
+
// Used for IPC to worker processes (McpSdkServerConfigWithInstance is not serializable).
|
|
15
|
+
function extractMcpDescriptors(mcpServers) {
|
|
16
|
+
if (!mcpServers) return null;
|
|
17
|
+
var toJSONSchema;
|
|
18
|
+
try { toJSONSchema = require("zod").toJSONSchema; } catch (e) { return null; }
|
|
19
|
+
var descriptors = [];
|
|
20
|
+
var names = Object.keys(mcpServers);
|
|
21
|
+
for (var i = 0; i < names.length; i++) {
|
|
22
|
+
var serverName = names[i];
|
|
23
|
+
var server = mcpServers[serverName];
|
|
24
|
+
if (!server || !server.instance || !server.instance._registeredTools) continue;
|
|
25
|
+
var tools = [];
|
|
26
|
+
var toolNames = Object.keys(server.instance._registeredTools);
|
|
27
|
+
for (var j = 0; j < toolNames.length; j++) {
|
|
28
|
+
var toolName = toolNames[j];
|
|
29
|
+
var toolDef = server.instance._registeredTools[toolName];
|
|
30
|
+
var inputSchema = { type: "object", properties: {} };
|
|
31
|
+
try {
|
|
32
|
+
if (toolDef.inputSchema) inputSchema = toJSONSchema(toolDef.inputSchema);
|
|
33
|
+
} catch (e) { /* fallback to empty schema */ }
|
|
34
|
+
tools.push({
|
|
35
|
+
name: toolName,
|
|
36
|
+
description: toolDef.description || toolName,
|
|
37
|
+
inputSchema: inputSchema,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (tools.length > 0) descriptors.push({ serverName: serverName, tools: tools });
|
|
41
|
+
}
|
|
42
|
+
return descriptors.length > 0 ? descriptors : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Call an MCP tool handler by server name and tool name.
|
|
46
|
+
// Returns a promise that resolves with the tool result.
|
|
47
|
+
function callMcpToolHandler(mcpServers, serverName, toolName, args) {
|
|
48
|
+
if (!mcpServers || !mcpServers[serverName]) {
|
|
49
|
+
return Promise.reject(new Error("MCP server not found: " + serverName));
|
|
50
|
+
}
|
|
51
|
+
var server = mcpServers[serverName];
|
|
52
|
+
if (!server.instance || !server.instance._registeredTools || !server.instance._registeredTools[toolName]) {
|
|
53
|
+
return Promise.reject(new Error("MCP tool not found: " + serverName + "/" + toolName));
|
|
54
|
+
}
|
|
55
|
+
var handler = server.instance._registeredTools[toolName].handler;
|
|
56
|
+
if (typeof handler !== "function") {
|
|
57
|
+
return Promise.reject(new Error("MCP tool handler not a function: " + serverName + "/" + toolName));
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return Promise.resolve(handler(args));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return Promise.reject(e);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Merge in-process MCP servers with remote (extension-bridged) MCP servers.
|
|
67
|
+
// Returns the merged object, or null if no servers exist.
|
|
68
|
+
function mergeMcpServers(localServers, getRemoteFn) {
|
|
69
|
+
var merged = {};
|
|
70
|
+
var hasAny = false;
|
|
71
|
+
if (localServers) {
|
|
72
|
+
var lk = Object.keys(localServers);
|
|
73
|
+
for (var i = 0; i < lk.length; i++) {
|
|
74
|
+
merged[lk[i]] = localServers[lk[i]];
|
|
75
|
+
hasAny = true;
|
|
76
|
+
}
|
|
77
|
+
console.log("[mergeMcpServers] local servers:", lk.join(", ") || "(none)");
|
|
78
|
+
} else {
|
|
79
|
+
console.log("[mergeMcpServers] local servers: null");
|
|
80
|
+
}
|
|
81
|
+
if (typeof getRemoteFn === "function") {
|
|
82
|
+
var remote = getRemoteFn();
|
|
83
|
+
if (remote) {
|
|
84
|
+
var rk = Object.keys(remote);
|
|
85
|
+
console.log("[mergeMcpServers] remote servers:", rk.join(", ") || "(none)");
|
|
86
|
+
for (var j = 0; j < rk.length; j++) {
|
|
87
|
+
merged[rk[j]] = remote[rk[j]];
|
|
88
|
+
hasAny = true;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
console.log("[mergeMcpServers] remote servers: null/empty");
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
console.log("[mergeMcpServers] getRemoteFn not a function");
|
|
95
|
+
}
|
|
96
|
+
console.log("[mergeMcpServers] merged result:", Object.keys(merged).join(", ") || "(none)");
|
|
97
|
+
return hasAny ? merged : null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function createSDKBridge(opts) {
|
|
101
|
+
var cwd = opts.cwd;
|
|
102
|
+
var slug = opts.slug || "";
|
|
103
|
+
var sm = opts.sessionManager; // session manager instance
|
|
104
|
+
var send = opts.send; // broadcast to all clients
|
|
105
|
+
var pushModule = opts.pushModule;
|
|
106
|
+
var getNotificationsModule = opts.getNotificationsModule || function () { return null; };
|
|
107
|
+
var adapter = opts.adapter;
|
|
108
|
+
var adapters = opts.adapters || {};
|
|
109
|
+
var dangerouslySkipPermissions = opts.dangerouslySkipPermissions || false;
|
|
110
|
+
// mcpServers may be either a static object or a getter function. The
|
|
111
|
+
// getter form lets callers gate individual servers at call time (e.g.
|
|
112
|
+
// clay-browser is only exposed while the Chrome extension is connected).
|
|
113
|
+
var _mcpServersSrc = opts.mcpServers || null;
|
|
114
|
+
function getMcpServers() {
|
|
115
|
+
if (typeof _mcpServersSrc === "function") return _mcpServersSrc() || null;
|
|
116
|
+
return _mcpServersSrc;
|
|
117
|
+
}
|
|
118
|
+
var getRemoteMcpServers = opts.getRemoteMcpServers || null;
|
|
119
|
+
var clayPort = opts.clayPort || 2633;
|
|
120
|
+
var clayTls = opts.clayTls || false;
|
|
121
|
+
var clayAuthToken = opts.clayAuthToken || null;
|
|
122
|
+
var onProcessingChanged = opts.onProcessingChanged || function () {};
|
|
123
|
+
var _cachedFreshAuthState = null;
|
|
124
|
+
var _cachedFreshAuthAt = 0;
|
|
125
|
+
|
|
126
|
+
function getFreshAuthState(force) {
|
|
127
|
+
var yoke = require("./yoke");
|
|
128
|
+
var now = Date.now();
|
|
129
|
+
if (!force && _cachedFreshAuthState && now - _cachedFreshAuthAt < 15000) {
|
|
130
|
+
return _cachedFreshAuthState;
|
|
131
|
+
}
|
|
132
|
+
if (force) yoke.invalidateAuthCache();
|
|
133
|
+
_cachedFreshAuthState = yoke.checkAuth();
|
|
134
|
+
_cachedFreshAuthAt = now;
|
|
135
|
+
return _cachedFreshAuthState;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function isAuthErrorMessage(errDetail) {
|
|
139
|
+
if (!errDetail) return false;
|
|
140
|
+
var errLower = String(errDetail).toLowerCase();
|
|
141
|
+
return errLower.indexOf("not logged in") !== -1
|
|
142
|
+
|| errLower.indexOf("unauthenticated") !== -1
|
|
143
|
+
|| errLower.indexOf("authentication") !== -1
|
|
144
|
+
|| errLower.indexOf("sign in") !== -1
|
|
145
|
+
|| errLower.indexOf("log in") !== -1
|
|
146
|
+
|| errLower.indexOf("please login") !== -1;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function getLoginCommand(vendor) {
|
|
150
|
+
if (vendor === "codex") return "codex login --device-auth";
|
|
151
|
+
if (vendor === "claude") return "claude login";
|
|
152
|
+
return (vendor || "claude") + " login";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function notifyAuthRequired(session, title, body, authLinuxUser, canAutoLogin, loginCommand) {
|
|
156
|
+
var _nm = getNotificationsModule();
|
|
157
|
+
if (!_nm) return false;
|
|
158
|
+
_nm.notify("auth_required", {
|
|
159
|
+
title: title,
|
|
160
|
+
body: body,
|
|
161
|
+
slug: slug,
|
|
162
|
+
sessionId: session.localId,
|
|
163
|
+
ownerId: session.ownerId || null,
|
|
164
|
+
vendor: session.vendor || (adapter && adapter.vendor) || "claude",
|
|
165
|
+
loginCommand: loginCommand,
|
|
166
|
+
linuxUser: authLinuxUser,
|
|
167
|
+
canAutoLogin: canAutoLogin,
|
|
168
|
+
});
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function logAuthDecision(stage, session, errDetail, authState) {
|
|
173
|
+
var vendor = session && session.vendor ? session.vendor : "(none)";
|
|
174
|
+
var errSnippet = errDetail ? String(errDetail).replace(/\s+/g, " ").slice(0, 180) : "";
|
|
175
|
+
var authSummary = authState ? JSON.stringify(authState) : "(none)";
|
|
176
|
+
console.warn("[sdk-bridge] auth decision [" + stage + "] vendor=" + vendor + " auth=" + authSummary + (errSnippet ? " err=" + errSnippet : ""));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function getModelsForVendor(vendor) {
|
|
180
|
+
if (vendor && sm.modelsByVendor && sm.modelsByVendor[vendor]) return sm.modelsByVendor[vendor];
|
|
181
|
+
return sm.availableModels || [];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Model list entries may be plain strings (Codex) or { value, displayName }
|
|
185
|
+
// objects (Claude SDK). Normalize to the identifier string.
|
|
186
|
+
function modelEntryValue(entry) {
|
|
187
|
+
if (!entry) return "";
|
|
188
|
+
if (typeof entry === "string") return entry;
|
|
189
|
+
return entry.value || entry.id || "";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function modelListContains(list, modelId) {
|
|
193
|
+
if (!list || !modelId) return false;
|
|
194
|
+
for (var mi = 0; mi < list.length; mi++) {
|
|
195
|
+
if (modelEntryValue(list[mi]) === modelId) return true;
|
|
196
|
+
}
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Resolve a shorthand model name (e.g. "opus[1m]") to its full ID
|
|
201
|
+
// in the vendor model list (e.g. "claude-opus-4.6[1m]").
|
|
202
|
+
function resolveModelInList(list, modelId) {
|
|
203
|
+
if (!list || !modelId) return null;
|
|
204
|
+
var lc = modelId.toLowerCase();
|
|
205
|
+
for (var mi = 0; mi < list.length; mi++) {
|
|
206
|
+
var val = modelEntryValue(list[mi]);
|
|
207
|
+
if (val === modelId) return val;
|
|
208
|
+
}
|
|
209
|
+
for (var mi = 0; mi < list.length; mi++) {
|
|
210
|
+
var val = modelEntryValue(list[mi]);
|
|
211
|
+
if (!val || val === "default") continue;
|
|
212
|
+
var vlc = val.toLowerCase();
|
|
213
|
+
if (vlc.indexOf(lc) !== -1 || lc.indexOf(vlc) !== -1) return val;
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function sendModelInfoForVendor(vendor, model) {
|
|
219
|
+
send({
|
|
220
|
+
type: "model_info",
|
|
221
|
+
model: model || "",
|
|
222
|
+
models: getModelsForVendor(vendor),
|
|
223
|
+
vendor: vendor || (adapter && adapter.vendor) || "claude",
|
|
224
|
+
availableVendors: sm.availableVendors || [],
|
|
225
|
+
installedVendors: sm.installedVendors || [],
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
var onTurnDone = opts.onTurnDone || null;
|
|
229
|
+
|
|
230
|
+
// --- Idle session reaper ---
|
|
231
|
+
// In single-user (in-process) mode, each session's Claude child process stays
|
|
232
|
+
// alive between turns because the messageQueue push-stream is never ended.
|
|
233
|
+
// Without a reaper, processes accumulate indefinitely as users switch between
|
|
234
|
+
// sessions and projects. This reaper ends the messageQueue for sessions that
|
|
235
|
+
// have been idle for IDLE_TIMEOUT_MS, allowing processQueryStream's finally
|
|
236
|
+
// block to clean up the child process. Session state on disk is preserved —
|
|
237
|
+
// the next startQuery() call resumes with a fresh process.
|
|
238
|
+
var IDLE_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes
|
|
239
|
+
var IDLE_CHECK_INTERVAL_MS = 60 * 1000; // check every 60 seconds
|
|
240
|
+
var _idleReaperTimer = null;
|
|
241
|
+
|
|
242
|
+
function startIdleReaper() {
|
|
243
|
+
if (_idleReaperTimer) return;
|
|
244
|
+
_idleReaperTimer = setInterval(function () {
|
|
245
|
+
var now = Date.now();
|
|
246
|
+
sm.sessions.forEach(function (session) {
|
|
247
|
+
// Skip sessions that are actively processing, have no query,
|
|
248
|
+
// or are single-turn (Ralph Loop — managed by onQueryComplete).
|
|
249
|
+
if (session.isProcessing) return;
|
|
250
|
+
if (!session.queryInstance) return;
|
|
251
|
+
if (session.singleTurn) return;
|
|
252
|
+
if (session.destroying) return;
|
|
253
|
+
|
|
254
|
+
var lastActivity = session.lastActivityAt || 0;
|
|
255
|
+
if (now - lastActivity > IDLE_TIMEOUT_MS) {
|
|
256
|
+
console.log("[sdk-bridge] Reaping idle session " + session.localId +
|
|
257
|
+
" (idle " + Math.round((now - lastActivity) / 60000) + "min)" +
|
|
258
|
+
(session.title ? " title=" + JSON.stringify(session.title) : ""));
|
|
259
|
+
// End the query so the for-await loop in processQueryStream
|
|
260
|
+
// exits naturally, triggering the finally block cleanup.
|
|
261
|
+
// Works for both in-process (messageQueue.end) and worker (handle.close) paths.
|
|
262
|
+
if (session.queryInstance && typeof session.queryInstance.close === "function") {
|
|
263
|
+
try { session.queryInstance.close(); } catch (e) {}
|
|
264
|
+
} else if (session.messageQueue && typeof session.messageQueue.end === "function") {
|
|
265
|
+
try { session.messageQueue.end(); } catch (e) {}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}, IDLE_CHECK_INTERVAL_MS);
|
|
270
|
+
// Don't prevent process exit
|
|
271
|
+
if (_idleReaperTimer.unref) _idleReaperTimer.unref();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function stopIdleReaper() {
|
|
275
|
+
if (_idleReaperTimer) {
|
|
276
|
+
clearInterval(_idleReaperTimer);
|
|
277
|
+
_idleReaperTimer = null;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// --- Skill discovery (extracted to sdk-skill-discovery.js) ---
|
|
282
|
+
var skills = attachSkillDiscovery({ cwd: cwd });
|
|
283
|
+
var discoverSkillDirs = skills.discoverSkillDirs;
|
|
284
|
+
var mergeSkills = skills.mergeSkills;
|
|
285
|
+
|
|
286
|
+
// --- Message processing (extracted to sdk-message-processor.js) ---
|
|
287
|
+
// Auto-generate a session title via YOKE adapter.generateTitle().
|
|
288
|
+
// Triggered by sdk-message-processor after AUTO_TITLE_TURN_THRESHOLD turns.
|
|
289
|
+
function autoGenerateTitle(session) {
|
|
290
|
+
var sessionAdapter = getAdapterForSession(session);
|
|
291
|
+
if (typeof sessionAdapter.generateTitle !== "function") {
|
|
292
|
+
console.log("[auto-title] adapter.generateTitle not available for vendor=" + sessionAdapter.vendor);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
var userMessages = [];
|
|
296
|
+
for (var i = 0; i < session.history.length; i++) {
|
|
297
|
+
var entry = session.history[i];
|
|
298
|
+
if (entry.type === "user_message" && entry.text) {
|
|
299
|
+
userMessages.push(entry.text.substring(0, 200));
|
|
300
|
+
if (userMessages.length >= 5) break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (userMessages.length === 0) {
|
|
304
|
+
console.log("[auto-title] No user messages found in session " + session.localId);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
console.log("[auto-title] Calling adapter.generateTitle with " + userMessages.length + " messages for session " + session.localId);
|
|
308
|
+
|
|
309
|
+
sessionAdapter.generateTitle(userMessages, { cwd: cwd }).then(function(title) {
|
|
310
|
+
if (!title || title.length < 2) return;
|
|
311
|
+
title = title.substring(0, 100);
|
|
312
|
+
if (!session.titleManuallySet) {
|
|
313
|
+
session.title = title;
|
|
314
|
+
session.titleAutoGenerated = true;
|
|
315
|
+
sm.saveSessionFile(session);
|
|
316
|
+
sm.broadcastSessionList();
|
|
317
|
+
if (session.cliSessionId && typeof adapter.renameSession === "function") {
|
|
318
|
+
adapter.renameSession(session.cliSessionId, title, { dir: cwd }).catch(function () {});
|
|
319
|
+
}
|
|
320
|
+
console.log("[auto-title] Generated title for session " + session.localId + ": " + title);
|
|
321
|
+
}
|
|
322
|
+
}).catch(function(e) {
|
|
323
|
+
console.error("[auto-title] Failed:", e.message || e);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
var msgProcessor = attachMessageProcessor({
|
|
328
|
+
sm: sm,
|
|
329
|
+
send: send,
|
|
330
|
+
slug: slug,
|
|
331
|
+
cwd: cwd,
|
|
332
|
+
pushModule: pushModule,
|
|
333
|
+
getNotificationsModule: getNotificationsModule,
|
|
334
|
+
adapter: adapter,
|
|
335
|
+
onProcessingChanged: onProcessingChanged,
|
|
336
|
+
onTurnDone: onTurnDone,
|
|
337
|
+
onAutoTitle: function (session) { autoGenerateTitle(session); },
|
|
338
|
+
opts: opts,
|
|
339
|
+
discoverSkillDirs: discoverSkillDirs,
|
|
340
|
+
mergeSkills: mergeSkills,
|
|
341
|
+
});
|
|
342
|
+
var processSDKMessage = msgProcessor.processSDKMessage;
|
|
343
|
+
var sendAndRecord = msgProcessor.sendAndRecord;
|
|
344
|
+
var sendToSession = msgProcessor.sendToSession;
|
|
345
|
+
|
|
346
|
+
// --- MCP elicitation ---
|
|
347
|
+
|
|
348
|
+
function handleElicitation(session, request, opts) {
|
|
349
|
+
// Ralph Loop: auto-reject elicitation in autonomous mode
|
|
350
|
+
if (session.loop && session.loop.active && session.loop.role !== "crafting") {
|
|
351
|
+
return Promise.resolve({ action: "reject" });
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return new Promise(function(resolve) {
|
|
355
|
+
var requestId = crypto.randomUUID();
|
|
356
|
+
if (!session.pendingElicitations) session.pendingElicitations = {};
|
|
357
|
+
session.pendingElicitations[requestId] = {
|
|
358
|
+
resolve: resolve,
|
|
359
|
+
request: request,
|
|
360
|
+
};
|
|
361
|
+
sendAndRecord(session, {
|
|
362
|
+
type: "elicitation_request",
|
|
363
|
+
requestId: requestId,
|
|
364
|
+
serverName: request.serverName,
|
|
365
|
+
message: request.message,
|
|
366
|
+
mode: request.mode || "form",
|
|
367
|
+
url: request.url || null,
|
|
368
|
+
elicitationId: request.elicitationId || null,
|
|
369
|
+
requestedSchema: request.requestedSchema || null,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
if (pushModule) {
|
|
373
|
+
pushModule.sendPush({
|
|
374
|
+
type: "elicitation",
|
|
375
|
+
slug: slug,
|
|
376
|
+
title: (request.serverName || "MCP Server") + " needs input",
|
|
377
|
+
body: request.message || "Waiting for your response",
|
|
378
|
+
tag: "claude-elicitation",
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (opts.signal) {
|
|
383
|
+
opts.signal.addEventListener("abort", function() {
|
|
384
|
+
delete session.pendingElicitations[requestId];
|
|
385
|
+
resolve({ action: "reject" });
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
// --- Linux user project directory setup ---
|
|
393
|
+
// Ensures the linux user's .claude project directory exists and is writable,
|
|
394
|
+
// then pre-copies CLI session file if needed. Called before starting a query
|
|
395
|
+
// so the worker can resume from the correct session file.
|
|
396
|
+
function ensureLinuxUserProjectDir(linuxUser, session) {
|
|
397
|
+
try {
|
|
398
|
+
var configMod = require("./config");
|
|
399
|
+
var osUsersMod = require("./os-users");
|
|
400
|
+
var originalHome = configMod.REAL_HOME || require("os").homedir();
|
|
401
|
+
var linuxUserHome = osUsersMod.getLinuxUserHome(linuxUser);
|
|
402
|
+
var uid = osUsersMod.getLinuxUserUid(linuxUser);
|
|
403
|
+
if (originalHome !== linuxUserHome && uid != null) {
|
|
404
|
+
var projectSlug = (cwd || "").replace(/\//g, "-");
|
|
405
|
+
var dstDir = path.join(linuxUserHome, ".claude", "projects", projectSlug);
|
|
406
|
+
// Create and chown the project directory once
|
|
407
|
+
if (!fs.existsSync(dstDir)) {
|
|
408
|
+
fs.mkdirSync(dstDir, { recursive: true });
|
|
409
|
+
try { execFileSync("chown", ["-R", String(uid), path.join(linuxUserHome, ".claude")]); } catch (e2) {}
|
|
410
|
+
} else {
|
|
411
|
+
try {
|
|
412
|
+
var dirStat = fs.statSync(dstDir);
|
|
413
|
+
if (dirStat.uid !== uid) {
|
|
414
|
+
execFileSync("chown", [String(uid), dstDir]);
|
|
415
|
+
}
|
|
416
|
+
} catch (e2) {}
|
|
417
|
+
}
|
|
418
|
+
// Pre-copy CLI session file so the worker can resume the conversation
|
|
419
|
+
if (session.cliSessionId) {
|
|
420
|
+
var sessionFileName = session.cliSessionId + ".jsonl";
|
|
421
|
+
var srcFile = path.join(originalHome, ".claude", "projects", projectSlug, sessionFileName);
|
|
422
|
+
var dstFile = path.join(dstDir, sessionFileName);
|
|
423
|
+
if (fs.existsSync(srcFile) && !fs.existsSync(dstFile)) {
|
|
424
|
+
fs.copyFileSync(srcFile, dstFile);
|
|
425
|
+
try { execFileSync("chown", [String(uid), dstFile]); } catch (e2) {}
|
|
426
|
+
console.log("[sdk-bridge] Pre-copied CLI session " + session.cliSessionId + " to " + linuxUser);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
} catch (copyErr) {
|
|
431
|
+
console.log("[sdk-bridge] Dir setup / session pre-copy skipped:", copyErr.message);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// --- SDK query lifecycle ---
|
|
436
|
+
|
|
437
|
+
// Check if a tool should be auto-approved based on whitelist rules.
|
|
438
|
+
// Returns { behavior: "allow", updatedInput } if whitelisted, or null if not.
|
|
439
|
+
// Shared by handleCanUseTool and mate mention canUseTool handlers.
|
|
440
|
+
function checkToolWhitelist(toolName, input) {
|
|
441
|
+
// Auto-approve read-only tools for ALL sessions.
|
|
442
|
+
// These tools only inspect files and fetch data — no side effects.
|
|
443
|
+
var readOnlyTools = { Read: true, Glob: true, Grep: true, WebFetch: true, WebSearch: true };
|
|
444
|
+
if (readOnlyTools[toolName]) {
|
|
445
|
+
return { behavior: "allow", updatedInput: input };
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Auto-approve safe browser MCP tools.
|
|
449
|
+
// Only watch/unwatch: user explicitly chose which tab to share.
|
|
450
|
+
// Everything else (screenshot, read_page, list_tabs, etc.) can expose
|
|
451
|
+
// content from tabs the user didn't intend to share, so require approval.
|
|
452
|
+
var safeBrowserTools = { browser_watch_tab: true, browser_unwatch_tab: true };
|
|
453
|
+
if (toolName.indexOf("mcp__") === 0 && toolName.indexOf("__browser_") !== -1) {
|
|
454
|
+
var mcpToolName = toolName.substring(toolName.lastIndexOf("__") + 2);
|
|
455
|
+
if (safeBrowserTools[mcpToolName]) {
|
|
456
|
+
return { behavior: "allow", updatedInput: input };
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Auto-approve Mate datastore tools. These are scoped to the active Mate
|
|
461
|
+
// project and already enforce SQL policy server-side.
|
|
462
|
+
if (toolName.indexOf("mcp__clay-datastore__") === 0) {
|
|
463
|
+
return { behavior: "allow", updatedInput: input };
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Auto-approve remote MCP tools that the user explicitly enabled in project settings.
|
|
467
|
+
// These are user-owned local MCP servers, so no additional permission prompt needed.
|
|
468
|
+
if (toolName.indexOf("mcp__") === 0 && getRemoteMcpServers) {
|
|
469
|
+
var _rmcp = getRemoteMcpServers();
|
|
470
|
+
if (_rmcp) {
|
|
471
|
+
var _mcpParts = toolName.split("__");
|
|
472
|
+
var _mcpServerName = _mcpParts.length >= 2 ? _mcpParts[1] : "";
|
|
473
|
+
if (_rmcp[_mcpServerName]) {
|
|
474
|
+
return { behavior: "allow", updatedInput: input };
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Auto-approve safe Bash commands (read-only, non-destructive)
|
|
480
|
+
// Applies to ALL sessions (mates and regular projects alike).
|
|
481
|
+
// These are purely read-only commands that cannot modify files, install
|
|
482
|
+
// packages, or change system state. Functionally equivalent to the
|
|
483
|
+
// Read/Glob/Grep built-in tools which are already auto-approved.
|
|
484
|
+
if (toolName === "Bash" && input && input.command) {
|
|
485
|
+
var cmd = input.command.trim();
|
|
486
|
+
var safeBashCommands = {
|
|
487
|
+
// Navigation (harmless on its own, checked in compound commands below)
|
|
488
|
+
cd: true, pushd: true, popd: true,
|
|
489
|
+
// File/dir inspection
|
|
490
|
+
ls: true, cat: true, head: true, tail: true, wc: true, file: true,
|
|
491
|
+
stat: true, find: true, tree: true, du: true, df: true,
|
|
492
|
+
readlink: true, realpath: true, basename: true, dirname: true,
|
|
493
|
+
// Search
|
|
494
|
+
grep: true, rg: true, ag: true, ack: true, fgrep: true, egrep: true,
|
|
495
|
+
// Lookup
|
|
496
|
+
which: true, type: true, whereis: true, command: true, hash: true,
|
|
497
|
+
// Environment/system info
|
|
498
|
+
echo: true, printf: true, env: true, printenv: true, pwd: true,
|
|
499
|
+
whoami: true, id: true, groups: true,
|
|
500
|
+
date: true, uname: true, hostname: true, uptime: true, arch: true,
|
|
501
|
+
nproc: true, free: true, lsb_release: true, sw_vers: true,
|
|
502
|
+
locale: true, timedatectl: true,
|
|
503
|
+
// Version checks (--version only, but first-word check is sufficient
|
|
504
|
+
// since these never take destructive subcommands as first arg)
|
|
505
|
+
git: true, node: true, npm: true, npx: true, python: true, python3: true, pip: true,
|
|
506
|
+
dotnet: true, ruby: true, java: true, javac: true,
|
|
507
|
+
rustc: true, cargo: true, gcc: true, clang: true, cmake: true,
|
|
508
|
+
go: true, deno: true, bun: true,
|
|
509
|
+
// Text processing (pure stdin/stdout, no side effects)
|
|
510
|
+
jq: true, yq: true, sort: true, uniq: true, cut: true, tr: true,
|
|
511
|
+
awk: true, sed: true, paste: true, column: true, fold: true,
|
|
512
|
+
rev: true, tac: true, nl: true, expand: true, unexpand: true,
|
|
513
|
+
fmt: true, pr: true, csplit: true, comm: true, join: true,
|
|
514
|
+
// Comparison/hashing
|
|
515
|
+
diff: true, cmp: true, md5sum: true, sha256sum: true, sha1sum: true,
|
|
516
|
+
shasum: true, cksum: true, sum: true, b2sum: true, base64: true,
|
|
517
|
+
xxd: true, od: true, hexdump: true,
|
|
518
|
+
// Misc read-only
|
|
519
|
+
test: true, true: true, false: true, seq: true, yes: true,
|
|
520
|
+
sleep: true, tee: true, xargs: true, time: true,
|
|
521
|
+
man: true, help: true, info: true, apropos: true,
|
|
522
|
+
cal: true, bc: true, expr: true, factor: true,
|
|
523
|
+
lsof: true, ps: true, top: true, htop: true, pgrep: true,
|
|
524
|
+
netstat: true, ss: true, ifconfig: true, ip: true, dig: true,
|
|
525
|
+
nslookup: true, host: true, ping: true, traceroute: true,
|
|
526
|
+
curl: true, wget: true, http: true,
|
|
527
|
+
};
|
|
528
|
+
// Split compound commands on operators (&&, ||, ;, |) while respecting
|
|
529
|
+
// quoted strings and subshells so that e.g. grep -E "(a|b)" is not split
|
|
530
|
+
var segments = splitShellSegments(cmd);
|
|
531
|
+
var allSafe = true;
|
|
532
|
+
for (var si = 0; si < segments.length; si++) {
|
|
533
|
+
var seg = segments[si].trim();
|
|
534
|
+
if (!seg) continue;
|
|
535
|
+
// Strip leading env assignments (FOO=bar cmd) and sudo
|
|
536
|
+
var firstWord = seg.replace(/^(?:\w+=\S*\s+)*/, "").split(/\s/)[0];
|
|
537
|
+
if (firstWord === "sudo") {
|
|
538
|
+
firstWord = seg.replace(/^(?:\w+=\S*\s+)*sudo\s+(?:-\S+\s+)*/, "").split(/\s/)[0];
|
|
539
|
+
}
|
|
540
|
+
if (!safeBashCommands[firstWord]) { allSafe = false; break; }
|
|
541
|
+
}
|
|
542
|
+
if (allSafe) {
|
|
543
|
+
return { behavior: "allow", updatedInput: input };
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return null; // Not whitelisted
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function handleCanUseTool(session, toolName, input, opts) {
|
|
551
|
+
// Full-auto mode: auto-approve everything except AskUserQuestion
|
|
552
|
+
// (which still needs to go through the user interaction flow).
|
|
553
|
+
if (sm.currentPermissionMode === "bypassPermissions" && toolName !== "AskUserQuestion") {
|
|
554
|
+
return Promise.resolve({ behavior: "allow", updatedInput: input });
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Ralph Loop execution: auto-approve all tools, deny interactive ones.
|
|
558
|
+
// Crafting sessions are interactive — user and Claude collaborate to build PROMPT.md / JUDGE.md.
|
|
559
|
+
if (session.loop && session.loop.active && session.loop.role !== "crafting") {
|
|
560
|
+
if (toolName === "AskUserQuestion") {
|
|
561
|
+
return Promise.resolve({ behavior: "deny", message: "Autonomous mode. Make your own decision." });
|
|
562
|
+
}
|
|
563
|
+
if (toolName === "EnterPlanMode") {
|
|
564
|
+
return Promise.resolve({ behavior: "deny", message: "Do not enter plan mode. Execute directly." });
|
|
565
|
+
}
|
|
566
|
+
return Promise.resolve({ behavior: "allow", updatedInput: input });
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// Check shared whitelist (read-only tools, safe browser tools, safe bash commands)
|
|
570
|
+
var whitelisted = checkToolWhitelist(toolName, input);
|
|
571
|
+
if (whitelisted) {
|
|
572
|
+
return Promise.resolve(whitelisted);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// AskUserQuestion: wait for user answers via WebSocket
|
|
576
|
+
if (toolName === "AskUserQuestion") {
|
|
577
|
+
return new Promise(function(resolve) {
|
|
578
|
+
session.pendingAskUser[opts.toolUseID] = {
|
|
579
|
+
resolve: resolve,
|
|
580
|
+
input: input,
|
|
581
|
+
};
|
|
582
|
+
if (opts.signal) {
|
|
583
|
+
opts.signal.addEventListener("abort", function() {
|
|
584
|
+
delete session.pendingAskUser[opts.toolUseID];
|
|
585
|
+
sendAndRecord(session, { type: "ask_user_answered", toolId: opts.toolUseID });
|
|
586
|
+
resolve({ behavior: "deny", message: "Cancelled" });
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// Auto-approve if tool was previously allowed for session
|
|
593
|
+
if (session.allowedTools && session.allowedTools[toolName]) {
|
|
594
|
+
return Promise.resolve({ behavior: "allow", updatedInput: input });
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// Regular tool permission request: send to client and wait
|
|
598
|
+
return new Promise(function(resolve) {
|
|
599
|
+
var requestId = crypto.randomUUID();
|
|
600
|
+
sm.permissionRequestIndex[requestId] = session.localId;
|
|
601
|
+
session.pendingPermissions[requestId] = {
|
|
602
|
+
resolve: resolve,
|
|
603
|
+
requestId: requestId,
|
|
604
|
+
toolName: toolName,
|
|
605
|
+
toolInput: input,
|
|
606
|
+
toolUseId: opts.toolUseID,
|
|
607
|
+
decisionReason: opts.decisionReason || "",
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
var permMsg = {
|
|
611
|
+
type: "permission_request",
|
|
612
|
+
requestId: requestId,
|
|
613
|
+
toolName: toolName,
|
|
614
|
+
toolInput: input,
|
|
615
|
+
toolUseId: opts.toolUseID,
|
|
616
|
+
decisionReason: opts.decisionReason || "",
|
|
617
|
+
vendor: session.vendor || (adapter && adapter.vendor) || "claude",
|
|
618
|
+
};
|
|
619
|
+
sendAndRecord(session, permMsg);
|
|
620
|
+
onProcessingChanged(); // update cross-project permission badge
|
|
621
|
+
|
|
622
|
+
if (pushModule) {
|
|
623
|
+
pushModule.sendPush({
|
|
624
|
+
type: "permission_request",
|
|
625
|
+
slug: slug,
|
|
626
|
+
requestId: requestId,
|
|
627
|
+
title: permissionPushTitle(toolName, input),
|
|
628
|
+
body: permissionPushBody(toolName, input),
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
var _nm = getNotificationsModule();
|
|
633
|
+
if (_nm) {
|
|
634
|
+
_nm.notify("permission_request", {
|
|
635
|
+
title: permissionPushTitle(toolName, input),
|
|
636
|
+
body: permissionPushBody(toolName, input),
|
|
637
|
+
slug: slug,
|
|
638
|
+
sessionId: session.localId,
|
|
639
|
+
ownerId: session.ownerId || null,
|
|
640
|
+
requestId: requestId,
|
|
641
|
+
toolName: toolName,
|
|
642
|
+
toolInput: input,
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (opts.signal) {
|
|
647
|
+
opts.signal.addEventListener("abort", function() {
|
|
648
|
+
delete session.pendingPermissions[requestId];
|
|
649
|
+
delete sm.permissionRequestIndex[requestId];
|
|
650
|
+
sendAndRecord(session, { type: "permission_cancel", requestId: requestId });
|
|
651
|
+
onProcessingChanged(); // update cross-project permission badge
|
|
652
|
+
resolve({ behavior: "deny", message: "Request cancelled" });
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Detect running Claude Code CLI processes that may conflict with our SDK queries.
|
|
660
|
+
* Only returns processes whose cwd matches our project directory.
|
|
661
|
+
* Returns an array of { pid, command } for each conflicting process found.
|
|
662
|
+
*/
|
|
663
|
+
function findConflictingClaude() {
|
|
664
|
+
try {
|
|
665
|
+
var output = execFileSync("ps", ["ax", "-o", "pid,command"], { encoding: "utf8", timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
|
|
666
|
+
var lines = output.trim().split("\n");
|
|
667
|
+
var candidates = [];
|
|
668
|
+
for (var i = 1; i < lines.length; i++) { // skip header
|
|
669
|
+
var line = lines[i].trim();
|
|
670
|
+
var m = line.match(/^(\d+)\s+(.+)/);
|
|
671
|
+
if (!m) continue;
|
|
672
|
+
var pid = parseInt(m[1], 10);
|
|
673
|
+
var cmd = m[2];
|
|
674
|
+
// Skip our own process
|
|
675
|
+
if (pid === process.pid) continue;
|
|
676
|
+
// Skip node processes (our daemon, dev watchers, etc.)
|
|
677
|
+
if (/\bnode\b/.test(cmd.split(/\s/)[0])) continue;
|
|
678
|
+
// Match actual claude binary (e.g. /Users/x/.claude/local/claude, /usr/local/bin/claude)
|
|
679
|
+
if (/\/claude(\s|$)/.test(cmd) || /^claude(\s|$)/.test(cmd)) {
|
|
680
|
+
candidates.push({ pid: pid, command: cmd.substring(0, 200) });
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// Filter to only processes whose cwd matches our project
|
|
685
|
+
var results = [];
|
|
686
|
+
for (var j = 0; j < candidates.length; j++) {
|
|
687
|
+
var c = candidates[j];
|
|
688
|
+
try {
|
|
689
|
+
// Use /proc/<pid>/cwd symlink (always available on Linux, no lsof dependency)
|
|
690
|
+
var procCwd = fs.readlinkSync("/proc/" + c.pid + "/cwd");
|
|
691
|
+
if (procCwd === cwd) {
|
|
692
|
+
results.push(c);
|
|
693
|
+
}
|
|
694
|
+
} catch (e) {
|
|
695
|
+
// /proc read failed — include as candidate anyway (conservative)
|
|
696
|
+
results.push(c);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return results;
|
|
700
|
+
} catch (e) {
|
|
701
|
+
return [];
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Verify that a PID is actually a claude binary process (not arbitrary).
|
|
707
|
+
*/
|
|
708
|
+
function isClaudeProcess(pid) {
|
|
709
|
+
try {
|
|
710
|
+
var output = execFileSync("ps", ["-p", String(pid), "-o", "command="], { encoding: "utf8", timeout: 3000, stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
711
|
+
return /\/claude(\s|$)/.test(output) || /^claude(\s|$)/.test(output);
|
|
712
|
+
} catch (e) {
|
|
713
|
+
return false;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
async function processQueryStream(session) {
|
|
718
|
+
// Capture references at start so we only clean up OUR resources in finally,
|
|
719
|
+
// not resources from a newer query that may have been created after an abort.
|
|
720
|
+
var myQueryInstance = session.queryInstance;
|
|
721
|
+
var myAbortController = session.abortController;
|
|
722
|
+
console.log("[sdk-bridge] processQueryStream: starting for-await loop, vendor=" + (session.vendor || adapter.vendor));
|
|
723
|
+
try {
|
|
724
|
+
for await (var msg of myQueryInstance) {
|
|
725
|
+
if (msg && msg.yokeType !== "text_delta" && msg.yokeType !== "thinking_delta" && msg.yokeType !== "tool_input_delta") {
|
|
726
|
+
console.log("[sdk-bridge] processQueryStream: received event yokeType=" + msg.yokeType);
|
|
727
|
+
}
|
|
728
|
+
// Handle worker meta events (context_usage, model_changed, etc.)
|
|
729
|
+
if (msg && msg.type === "_worker_meta") {
|
|
730
|
+
var metaData = msg.data || {};
|
|
731
|
+
switch (msg.subtype) {
|
|
732
|
+
case "context_usage":
|
|
733
|
+
session.lastContextUsage = metaData.data;
|
|
734
|
+
sendToSession(session, { type: "context_usage", data: metaData.data });
|
|
735
|
+
break;
|
|
736
|
+
case "model_changed":
|
|
737
|
+
sm.currentModel = metaData.model;
|
|
738
|
+
sendModelInfoForVendor(session.vendor || (adapter && adapter.vendor) || "claude", metaData.model);
|
|
739
|
+
send({ type: "config_state", model: sm.currentModel, mode: sm.currentPermissionMode || "default", effort: sm.currentEffort || "medium", betas: sm.currentBetas || [] });
|
|
740
|
+
break;
|
|
741
|
+
case "effort_changed":
|
|
742
|
+
sm.currentEffort = metaData.effort;
|
|
743
|
+
send({ type: "config_state", model: sm.currentModel || "", mode: sm.currentPermissionMode || "default", effort: sm.currentEffort, betas: sm.currentBetas || [] });
|
|
744
|
+
break;
|
|
745
|
+
case "permission_mode_changed":
|
|
746
|
+
sm.currentPermissionMode = metaData.mode;
|
|
747
|
+
send({ type: "config_state", model: sm.currentModel || "", mode: sm.currentPermissionMode, effort: sm.currentEffort || "medium", betas: sm.currentBetas || [] });
|
|
748
|
+
break;
|
|
749
|
+
case "worker_error":
|
|
750
|
+
send({ type: "error", text: metaData.error });
|
|
751
|
+
break;
|
|
752
|
+
}
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
processSDKMessage(session, msg);
|
|
756
|
+
}
|
|
757
|
+
// (getContextUsage moved to processSDKMessage result handler -- fire-and-forget)
|
|
758
|
+
// Stream ended normally after a task stop — no "result" message was sent,
|
|
759
|
+
// so the session is still marked as processing. Send interrupted feedback.
|
|
760
|
+
console.log("[sdk-bridge] processQueryStream ended: isProcessing=" + session.isProcessing + " taskStopRequested=" + session.taskStopRequested);
|
|
761
|
+
if (session.isProcessing && session.taskStopRequested) {
|
|
762
|
+
session.isProcessing = false;
|
|
763
|
+
onProcessingChanged();
|
|
764
|
+
send({ type: "status", processing: false });
|
|
765
|
+
sendAndRecord(session, { type: "thinking_stop" });
|
|
766
|
+
var interruptMsg = (session.vendor === "codex")
|
|
767
|
+
? "\u25a0 Conversation interrupted - tell the model what to do differently."
|
|
768
|
+
: "Interrupted \u00b7 What should Claude do instead?";
|
|
769
|
+
sendAndRecord(session, { type: "info", text: interruptMsg });
|
|
770
|
+
sendAndRecord(session, { type: "done", code: 0 });
|
|
771
|
+
sm.broadcastSessionList();
|
|
772
|
+
}
|
|
773
|
+
} catch (err) {
|
|
774
|
+
if (session.isProcessing) {
|
|
775
|
+
session.isProcessing = false;
|
|
776
|
+
onProcessingChanged();
|
|
777
|
+
if (err.name === "AbortError" || (myAbortController && myAbortController.signal.aborted) || session.taskStopRequested) {
|
|
778
|
+
if (!session.destroying) {
|
|
779
|
+
sendAndRecord(session, { type: "thinking_stop" });
|
|
780
|
+
var interruptMsg2 = (session.vendor === "codex")
|
|
781
|
+
? "\u25a0 Conversation interrupted - tell the model what to do differently."
|
|
782
|
+
: "Interrupted \u00b7 What should Claude do instead?";
|
|
783
|
+
sendAndRecord(session, { type: "info", text: interruptMsg2 });
|
|
784
|
+
sendAndRecord(session, { type: "done", code: 0 });
|
|
785
|
+
}
|
|
786
|
+
} else if (session.destroying) {
|
|
787
|
+
// Suppress error messages during shutdown
|
|
788
|
+
console.log("[sdk-bridge] Suppressing stream error during shutdown for session " + session.localId);
|
|
789
|
+
} else {
|
|
790
|
+
var errDetail = err.message || String(err);
|
|
791
|
+
if (err.stderr) errDetail += "\nstderr: " + err.stderr;
|
|
792
|
+
if (err.exitCode != null) errDetail += " (exitCode: " + err.exitCode + ")";
|
|
793
|
+
console.error("[sdk-bridge] Query stream error for session " + session.localId + ":", errDetail);
|
|
794
|
+
console.error("[sdk-bridge] Stack:", err.stack || "(no stack)");
|
|
795
|
+
|
|
796
|
+
// Check for conflicting Claude processes only on exit code 1
|
|
797
|
+
var isExitCode1 = err.exitCode === 1 || (err.message && err.message.indexOf("exited with code 1") !== -1);
|
|
798
|
+
var conflicts = isExitCode1 ? findConflictingClaude() : [];
|
|
799
|
+
if (conflicts.length > 0) {
|
|
800
|
+
console.error("[sdk-bridge] Found " + conflicts.length + " conflicting Claude process(es):", conflicts.map(function(c) { return "PID " + c.pid; }).join(", "));
|
|
801
|
+
sendAndRecord(session, {
|
|
802
|
+
type: "process_conflict",
|
|
803
|
+
text: "Another Claude Code process is already running in this project.",
|
|
804
|
+
processes: conflicts,
|
|
805
|
+
});
|
|
806
|
+
} else {
|
|
807
|
+
var errLower = errDetail.toLowerCase();
|
|
808
|
+
var isContextOverflow = errLower.indexOf("prompt is too long") !== -1
|
|
809
|
+
|| errLower.indexOf("context_length") !== -1
|
|
810
|
+
|| errLower.indexOf("maximum context length") !== -1;
|
|
811
|
+
var isAuthError = isAuthErrorMessage(errDetail);
|
|
812
|
+
if (isContextOverflow) {
|
|
813
|
+
sendAndRecord(session, {
|
|
814
|
+
type: "context_overflow",
|
|
815
|
+
text: "Conversation too long to continue.",
|
|
816
|
+
});
|
|
817
|
+
} else if (isAuthError) {
|
|
818
|
+
var freshAuth = getFreshAuthState();
|
|
819
|
+
logAuthDecision("catch-auth-error", session, errDetail, freshAuth);
|
|
820
|
+
if (freshAuth[session.vendor]) {
|
|
821
|
+
sendAndRecord(session, {
|
|
822
|
+
type: "error",
|
|
823
|
+
text: "Authentication looked fine, but " + (session.vendor || "the vendor") + " returned an auth-like error.",
|
|
824
|
+
});
|
|
825
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
826
|
+
sm.broadcastSessionList();
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
var authUser = session.ownerId ? usersModule.findUserById(session.ownerId) : null;
|
|
830
|
+
var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
|
|
831
|
+
var canAutoLogin = !usersModule.isMultiUser()
|
|
832
|
+
|| !!authLinuxUser
|
|
833
|
+
|| (authUser && authUser.role === "admin");
|
|
834
|
+
var authTitle = (session.vendor === "codex" ? "Codex" : "Claude Code") + " is not logged in.";
|
|
835
|
+
var authMsg = {
|
|
836
|
+
type: "auth_required",
|
|
837
|
+
text: authTitle,
|
|
838
|
+
vendor: session.vendor || (adapter && adapter.vendor) || "claude",
|
|
839
|
+
loginCommand: getLoginCommand(session.vendor || (adapter && adapter.vendor) || "claude"),
|
|
840
|
+
linuxUser: authLinuxUser,
|
|
841
|
+
canAutoLogin: canAutoLogin,
|
|
842
|
+
};
|
|
843
|
+
sendAndRecord(session, authMsg);
|
|
844
|
+
if (!notifyAuthRequired(
|
|
845
|
+
session,
|
|
846
|
+
authTitle,
|
|
847
|
+
"Open a terminal, then click the URL and follow the instructions.",
|
|
848
|
+
authLinuxUser,
|
|
849
|
+
canAutoLogin,
|
|
850
|
+
getLoginCommand(session.vendor || (adapter && adapter.vendor) || "claude")
|
|
851
|
+
)) {
|
|
852
|
+
// chat message already sent above
|
|
853
|
+
}
|
|
854
|
+
} else {
|
|
855
|
+
sendAndRecord(session, { type: "error", text: "Claude process error: " + err.message });
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
859
|
+
}
|
|
860
|
+
sm.broadcastSessionList();
|
|
861
|
+
}
|
|
862
|
+
} finally {
|
|
863
|
+
// Close the SDK query to terminate the underlying claude child process.
|
|
864
|
+
// Without this, the process stays alive indefinitely (single-user mode).
|
|
865
|
+
// Only clean up if the session still references OUR resources.
|
|
866
|
+
// A rewind + new startQuery may have already replaced these with
|
|
867
|
+
// a newer query — clobbering them would kill the new query.
|
|
868
|
+
if (session.queryInstance === myQueryInstance) {
|
|
869
|
+
try {
|
|
870
|
+
if (typeof session.queryInstance.close === "function") {
|
|
871
|
+
session.queryInstance.close();
|
|
872
|
+
}
|
|
873
|
+
} catch (e) {}
|
|
874
|
+
session.queryInstance = null;
|
|
875
|
+
}
|
|
876
|
+
session.messageQueue = null;
|
|
877
|
+
if (session.abortController === myAbortController) session.abortController = null;
|
|
878
|
+
session.taskStopRequested = false;
|
|
879
|
+
session.pendingPermissions = {};
|
|
880
|
+
session.pendingAskUser = {};
|
|
881
|
+
session.pendingElicitations = {};
|
|
882
|
+
|
|
883
|
+
// Auto-continue on rate limit (scheduler sessions, or user setting)
|
|
884
|
+
// Mark session as done processing so the late rate_limit_event handler
|
|
885
|
+
// can detect the race condition and schedule auto-continue itself.
|
|
886
|
+
session.isProcessing = false;
|
|
887
|
+
|
|
888
|
+
var didScheduleAutoContinue = false;
|
|
889
|
+
var acEnabled = session.onQueryComplete || (typeof opts.getAutoContinueSetting === "function" && opts.getAutoContinueSetting(session));
|
|
890
|
+
if (session.rateLimitResetsAt && session.rateLimitResetsAt > Date.now()
|
|
891
|
+
&& acEnabled && !session.destroying) {
|
|
892
|
+
var acResetsAt = session.rateLimitResetsAt;
|
|
893
|
+
session.rateLimitResetsAt = null;
|
|
894
|
+
session.rateLimitAutoContinuePending = true;
|
|
895
|
+
didScheduleAutoContinue = true;
|
|
896
|
+
console.log("[sdk-bridge] Rate limited, scheduling auto-continue via scheduleMessage for session " + session.localId);
|
|
897
|
+
if (typeof opts.scheduleMessage === "function") {
|
|
898
|
+
opts.scheduleMessage(session, "continue", acResetsAt);
|
|
899
|
+
}
|
|
900
|
+
} else if (acEnabled && !session.destroying) {
|
|
901
|
+
// Log why auto-continue was not scheduled (for debugging)
|
|
902
|
+
console.log("[sdk-bridge] Query done, auto-continue enabled but not scheduled: rateLimitResetsAt=" +
|
|
903
|
+
session.rateLimitResetsAt + " (will rely on late rate_limit_event handler)");
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// Ralph Loop: notify completion so loop orchestrator can proceed
|
|
907
|
+
if (session.onQueryComplete && !didScheduleAutoContinue) {
|
|
908
|
+
console.log("[sdk-bridge] Calling onQueryComplete for session " + session.localId + " (title: " + (session.title || "?") + ")");
|
|
909
|
+
try {
|
|
910
|
+
session.onQueryComplete(session);
|
|
911
|
+
} catch (err) {
|
|
912
|
+
console.error("[sdk-bridge] onQueryComplete error:", err.message || err);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
async function getOrCreateRewindQuery(session) {
|
|
919
|
+
if (session.queryInstance) return { query: session.queryInstance, isTemp: false, cleanup: function() {} };
|
|
920
|
+
|
|
921
|
+
var handle;
|
|
922
|
+
try {
|
|
923
|
+
handle = await adapter.createQuery({
|
|
924
|
+
cwd: cwd,
|
|
925
|
+
resumeSessionId: session.cliSessionId,
|
|
926
|
+
adapterOptions: {
|
|
927
|
+
CLAUDE: {
|
|
928
|
+
settingSources: ["user", "project", "local"],
|
|
929
|
+
enableFileCheckpointing: true,
|
|
930
|
+
},
|
|
931
|
+
},
|
|
932
|
+
});
|
|
933
|
+
} catch (e) {
|
|
934
|
+
sendAndRecord(session, { type: "error", text: "Failed to load Claude SDK: " + (e.message || e) });
|
|
935
|
+
throw e;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// Drain messages in background (stream stays alive until close)
|
|
939
|
+
(async function() {
|
|
940
|
+
try { for await (var msg of handle) {} } catch(e) {}
|
|
941
|
+
})();
|
|
942
|
+
|
|
943
|
+
return {
|
|
944
|
+
query: handle,
|
|
945
|
+
isTemp: true,
|
|
946
|
+
cleanup: function() { try { handle.close(); } catch(e) {} },
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// --- Unified rewind/fork interface (adapter-agnostic) ---
|
|
951
|
+
|
|
952
|
+
async function rewindPreview(session, uuid) {
|
|
953
|
+
var sessionAdapter = getAdapterForSession(session);
|
|
954
|
+
// Adapters with rollbackThread (e.g. Codex) do chat-only rewind, no file diffs
|
|
955
|
+
if (sessionAdapter && typeof sessionAdapter.rollbackThread === "function") {
|
|
956
|
+
return { preview: { filesChanged: [] }, diffs: {}, chatOnly: true };
|
|
957
|
+
}
|
|
958
|
+
// Claude path: use rewindFiles with dryRun
|
|
959
|
+
var result = await getOrCreateRewindQuery(session);
|
|
960
|
+
try {
|
|
961
|
+
var preview = await result.query.rewindFiles(uuid, { dryRun: true });
|
|
962
|
+
var diffs = {};
|
|
963
|
+
var changedFiles = preview.filesChanged || [];
|
|
964
|
+
for (var f = 0; f < changedFiles.length; f++) {
|
|
965
|
+
try {
|
|
966
|
+
diffs[changedFiles[f]] = require("child_process").execFileSync(
|
|
967
|
+
"git", ["diff", "HEAD", "--", changedFiles[f]],
|
|
968
|
+
{ cwd: cwd, encoding: "utf8", timeout: 5000 }
|
|
969
|
+
) || "";
|
|
970
|
+
} catch (e) { diffs[changedFiles[f]] = ""; }
|
|
971
|
+
}
|
|
972
|
+
return { preview: preview, diffs: diffs, chatOnly: false };
|
|
973
|
+
} finally {
|
|
974
|
+
if (result.isTemp) result.cleanup();
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
async function rewindExecuteFiles(session, uuid) {
|
|
979
|
+
var sessionAdapter = getAdapterForSession(session);
|
|
980
|
+
// Adapters with rollbackThread skip file restoration
|
|
981
|
+
if (sessionAdapter && typeof sessionAdapter.rollbackThread === "function") return;
|
|
982
|
+
// Claude path: restore files
|
|
983
|
+
var result = await getOrCreateRewindQuery(session);
|
|
984
|
+
try {
|
|
985
|
+
await result.query.rewindFiles(uuid, { dryRun: false });
|
|
986
|
+
} finally {
|
|
987
|
+
if (result.isTemp) result.cleanup();
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
async function rollbackConversation(session, numTurns) {
|
|
992
|
+
var sessionAdapter = getAdapterForSession(session);
|
|
993
|
+
if (sessionAdapter && typeof sessionAdapter.rollbackThread === "function") {
|
|
994
|
+
await sessionAdapter.rollbackThread(session.cliSessionId, numTurns);
|
|
995
|
+
}
|
|
996
|
+
// Claude: conversation rollback is handled by rewindFiles + local history trim
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
function getAdapterForSession(session) {
|
|
1000
|
+
var vendor = session.vendor || sm.defaultVendor || "claude";
|
|
1001
|
+
return adapters[vendor] || adapter;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
async function forkSessionUnified(session, uuid) {
|
|
1005
|
+
var sessionAdapter = getAdapterForSession(session);
|
|
1006
|
+
var result = await sessionAdapter.forkSession(session.cliSessionId, { upToMessageId: uuid, dir: cwd });
|
|
1007
|
+
if (!result || !result.sessionId) throw new Error("Fork returned no session id");
|
|
1008
|
+
|
|
1009
|
+
// Adapters with rollbackThread (e.g. Codex) use local history copy
|
|
1010
|
+
if (typeof sessionAdapter.rollbackThread === "function") {
|
|
1011
|
+
return { sessionId: result.sessionId, useLocalHistory: true };
|
|
1012
|
+
}
|
|
1013
|
+
// Claude: read history from CLI session files
|
|
1014
|
+
return { sessionId: result.sessionId, useLocalHistory: false };
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
async function startQuery(session, text, images, linuxUser) {
|
|
1018
|
+
async function ensureVendorReady(vendor) {
|
|
1019
|
+
if (!vendor) return null;
|
|
1020
|
+
var vendorAdapter = adapters[vendor] || null;
|
|
1021
|
+
if (!vendorAdapter) {
|
|
1022
|
+
var yoke = require("./yoke");
|
|
1023
|
+
vendorAdapter = await yoke.lazyCreateAdapter(adapters, vendor, {
|
|
1024
|
+
cwd: cwd,
|
|
1025
|
+
dangerouslySkipPermissions: dangerouslySkipPermissions,
|
|
1026
|
+
linuxUser: linuxUser || undefined,
|
|
1027
|
+
clayPort: clayPort,
|
|
1028
|
+
clayTls: clayTls,
|
|
1029
|
+
clayAuthToken: clayAuthToken,
|
|
1030
|
+
slug: slug,
|
|
1031
|
+
});
|
|
1032
|
+
} else if ((!sm.modelsByVendor || !sm.modelsByVendor[vendor]) && typeof vendorAdapter.init === "function") {
|
|
1033
|
+
await vendorAdapter.init({
|
|
1034
|
+
cwd: cwd,
|
|
1035
|
+
dangerouslySkipPermissions: dangerouslySkipPermissions,
|
|
1036
|
+
linuxUser: linuxUser || undefined,
|
|
1037
|
+
clayPort: clayPort,
|
|
1038
|
+
clayTls: clayTls,
|
|
1039
|
+
clayAuthToken: clayAuthToken,
|
|
1040
|
+
slug: slug,
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
if (vendorAdapter) {
|
|
1044
|
+
sm.availableVendors = Object.keys(adapters);
|
|
1045
|
+
sm.modelsByVendor = sm.modelsByVendor || {};
|
|
1046
|
+
if (!sm.modelsByVendor[vendor] && typeof vendorAdapter.supportedModels === "function") {
|
|
1047
|
+
sm.modelsByVendor[vendor] = await vendorAdapter.supportedModels();
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
return vendorAdapter;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// If vendor is set but adapter not ready, try lazy creation (user may have logged in)
|
|
1054
|
+
if (session.vendor && !adapters[session.vendor]) {
|
|
1055
|
+
var lazyAdapter = await ensureVendorReady(session.vendor);
|
|
1056
|
+
if (lazyAdapter) {
|
|
1057
|
+
console.log("[sdk-bridge] Lazy adapter created for " + session.vendor);
|
|
1058
|
+
}
|
|
1059
|
+
} else if (session.vendor) {
|
|
1060
|
+
await ensureVendorReady(session.vendor);
|
|
1061
|
+
}
|
|
1062
|
+
if (session.vendor && !adapters[session.vendor]) {
|
|
1063
|
+
var freshAuth = getFreshAuthState();
|
|
1064
|
+
logAuthDecision("pre-auth-required", session, null, freshAuth);
|
|
1065
|
+
if (freshAuth[session.vendor]) {
|
|
1066
|
+
var recoveredAdapter = await ensureVendorReady(session.vendor);
|
|
1067
|
+
if (recoveredAdapter) {
|
|
1068
|
+
console.log("[sdk-bridge] Auth recheck recovered adapter for " + session.vendor);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
// If still not available after lazy check, send auth_required
|
|
1073
|
+
if (session.vendor && !adapters[session.vendor]) {
|
|
1074
|
+
var vendorName = session.vendor.charAt(0).toUpperCase() + session.vendor.slice(1);
|
|
1075
|
+
var authUser = session.ownerId ? usersModule.findUserById(session.ownerId) : null;
|
|
1076
|
+
var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
|
|
1077
|
+
var canAutoLogin = !usersModule.isMultiUser()
|
|
1078
|
+
|| !!authLinuxUser
|
|
1079
|
+
|| (authUser && authUser.role === "admin");
|
|
1080
|
+
var authState = getFreshAuthState();
|
|
1081
|
+
logAuthDecision("emit-auth-required", session, "missing adapter", authState);
|
|
1082
|
+
if (authState[session.vendor]) {
|
|
1083
|
+
sendAndRecord(session, {
|
|
1084
|
+
type: "error",
|
|
1085
|
+
text: vendorName + " auth is available, but the adapter could not be initialized.",
|
|
1086
|
+
});
|
|
1087
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
var authMsg2 = {
|
|
1091
|
+
type: "auth_required",
|
|
1092
|
+
text: vendorName + " is not logged in.",
|
|
1093
|
+
vendor: session.vendor,
|
|
1094
|
+
loginCommand: getLoginCommand(session.vendor),
|
|
1095
|
+
linuxUser: authLinuxUser,
|
|
1096
|
+
canAutoLogin: canAutoLogin,
|
|
1097
|
+
};
|
|
1098
|
+
sendAndRecord(session, authMsg2);
|
|
1099
|
+
if (!notifyAuthRequired(
|
|
1100
|
+
session,
|
|
1101
|
+
vendorName + " is not logged in.",
|
|
1102
|
+
"Open a terminal, then click the URL and follow the instructions.",
|
|
1103
|
+
authLinuxUser,
|
|
1104
|
+
canAutoLogin,
|
|
1105
|
+
getLoginCommand(session.vendor)
|
|
1106
|
+
)) {
|
|
1107
|
+
// chat message already sent above
|
|
1108
|
+
}
|
|
1109
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1112
|
+
// Select adapter based on session vendor (fallback to default)
|
|
1113
|
+
var sessionAdapter = (session.vendor && adapters[session.vendor]) || adapter;
|
|
1114
|
+
console.log("[sdk-bridge] startQuery: vendor=" + sessionAdapter.vendor + " session=" + session.localId + " text=" + (text || "").substring(0, 50));
|
|
1115
|
+
// Remember linuxUser for auto-continue after rate limit
|
|
1116
|
+
session.lastLinuxUser = linuxUser || null;
|
|
1117
|
+
|
|
1118
|
+
var t0 = session._queryStartTs || Date.now();
|
|
1119
|
+
|
|
1120
|
+
// Wait for previous worker to fully exit before spawning a new one.
|
|
1121
|
+
// Without this, the new worker may try to resume the SDK session file
|
|
1122
|
+
// while the old worker is still flushing it to disk, causing
|
|
1123
|
+
// "no conversation found" and losing all prior context.
|
|
1124
|
+
// Harmless if null (no previous worker).
|
|
1125
|
+
if (session._workerExitPromise) {
|
|
1126
|
+
var exitWait = session._workerExitPromise;
|
|
1127
|
+
session._workerExitPromise = null;
|
|
1128
|
+
await Promise.race([
|
|
1129
|
+
exitWait,
|
|
1130
|
+
new Promise(function(resolve) { setTimeout(resolve, 3000); }),
|
|
1131
|
+
]);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
// Ensure Linux user project directory exists (runs in parallel with worker boot)
|
|
1135
|
+
if (linuxUser) {
|
|
1136
|
+
ensureLinuxUserProjectDir(linuxUser, session);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
session.blocks = {};
|
|
1140
|
+
session.sentToolResults = {};
|
|
1141
|
+
session.activeTaskToolIds = {};
|
|
1142
|
+
session.pendingElicitations = {};
|
|
1143
|
+
session.streamedText = false;
|
|
1144
|
+
session.responsePreview = "";
|
|
1145
|
+
|
|
1146
|
+
// For in-process path, create AbortController. For worker path, the adapter
|
|
1147
|
+
// handles abort internally and exposes it via handle.abort().
|
|
1148
|
+
if (!linuxUser) {
|
|
1149
|
+
session.abortController = new AbortController();
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// Build Claude-specific adapter options
|
|
1153
|
+
var claudeOpts = {
|
|
1154
|
+
settingSources: ["user", "project", "local"],
|
|
1155
|
+
includePartialMessages: true,
|
|
1156
|
+
enableFileCheckpointing: true,
|
|
1157
|
+
extraArgs: { "replay-user-messages": null },
|
|
1158
|
+
promptSuggestions: true,
|
|
1159
|
+
agentProgressSummaries: true,
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
// lr-7db0 — surface per-session agent identity into the SDK `agent` option.
|
|
1163
|
+
// When set, the Claude SDK applies the named agent's system prompt, tool
|
|
1164
|
+
// restrictions, and model for the main thread of this session. The session
|
|
1165
|
+
// still belongs to the project at `cwd`; only identity is shifted.
|
|
1166
|
+
//
|
|
1167
|
+
// The SDK only resolves `agent` against in-band `agents:{}` (or settings),
|
|
1168
|
+
// not file/plugin discovery — so we materialize the discovered agent's
|
|
1169
|
+
// definition and pass it alongside the name. If the agent can't be
|
|
1170
|
+
// resolved (renamed, missing, parse failure) we fall through silently;
|
|
1171
|
+
// the badge stays on the session for diagnosability but the session uses
|
|
1172
|
+
// default identity.
|
|
1173
|
+
if (session.agentName) {
|
|
1174
|
+
var agentDef = null;
|
|
1175
|
+
try { agentDef = agentsModule.getAgentDefinition(session.agentName); }
|
|
1176
|
+
catch (e) {
|
|
1177
|
+
console.error("[sdk-bridge] getAgentDefinition failed for " + session.agentName + ":", e.message);
|
|
1178
|
+
}
|
|
1179
|
+
if (agentDef) {
|
|
1180
|
+
claudeOpts.agent = session.agentName;
|
|
1181
|
+
var agentsMap = {};
|
|
1182
|
+
agentsMap[session.agentName] = agentDef;
|
|
1183
|
+
claudeOpts.agents = agentsMap;
|
|
1184
|
+
} else {
|
|
1185
|
+
console.warn("[sdk-bridge] session.agentName=" + session.agentName + " unresolved; not applying SDK agent option");
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
// Per-loop settings override global defaults when present
|
|
1190
|
+
var ls = session.loopSettings || {};
|
|
1191
|
+
|
|
1192
|
+
if (sm.currentBetas && sm.currentBetas.length > 0) {
|
|
1193
|
+
claudeOpts.betas = sm.currentBetas;
|
|
1194
|
+
}
|
|
1195
|
+
var thinkingMode = ls.thinking || sm.currentThinking;
|
|
1196
|
+
if (thinkingMode === "disabled") {
|
|
1197
|
+
claudeOpts.thinking = { type: "disabled" };
|
|
1198
|
+
} else if (thinkingMode === "budget") {
|
|
1199
|
+
var budgetTokens = ls.thinkingBudget || sm.currentThinkingBudget;
|
|
1200
|
+
if (budgetTokens) claudeOpts.thinking = { type: "enabled", budgetTokens: budgetTokens };
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
if (ls.permissionMode) {
|
|
1204
|
+
session._loopPermissionMode = ls.permissionMode;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// Pass through any extra SDK settings from LOOP.json
|
|
1208
|
+
if (ls.disableAllHooks !== undefined) {
|
|
1209
|
+
claudeOpts.settings = Object.assign({}, claudeOpts.settings || {}, { disableAllHooks: ls.disableAllHooks });
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
if (dangerouslySkipPermissions) {
|
|
1213
|
+
claudeOpts.allowDangerouslySkipPermissions = true;
|
|
1214
|
+
claudeOpts.permissionMode = "bypassPermissions";
|
|
1215
|
+
} else {
|
|
1216
|
+
var globalMode = session.permissionMode || sm.currentPermissionMode || "default";
|
|
1217
|
+
var effectiveDefault;
|
|
1218
|
+
if (globalMode === "bypassPermissions") effectiveDefault = "bypassPermissions";
|
|
1219
|
+
else if (session.acceptEditsAfterStart) effectiveDefault = "acceptEdits";
|
|
1220
|
+
else effectiveDefault = globalMode;
|
|
1221
|
+
var modeToApply = session._loopPermissionMode || effectiveDefault;
|
|
1222
|
+
if (modeToApply && modeToApply !== "default") {
|
|
1223
|
+
claudeOpts.permissionMode = modeToApply;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
// Clear one-shot acceptEditsAfterStart regardless of which branch ran above,
|
|
1227
|
+
// so the flag does not linger into subsequent turns.
|
|
1228
|
+
if (session.acceptEditsAfterStart) delete session.acceptEditsAfterStart;
|
|
1229
|
+
if (session.cliSessionId && session.lastRewindUuid) {
|
|
1230
|
+
claudeOpts.resumeSessionAt = session.lastRewindUuid;
|
|
1231
|
+
delete session.lastRewindUuid;
|
|
1232
|
+
sm.saveSessionFile(session);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// Pass linuxUser to adapter for worker-based queries
|
|
1236
|
+
if (linuxUser) {
|
|
1237
|
+
claudeOpts.linuxUser = linuxUser;
|
|
1238
|
+
claudeOpts.singleTurn = !!session.singleTurn;
|
|
1239
|
+
claudeOpts.originalHome = require("./config").REAL_HOME || null;
|
|
1240
|
+
claudeOpts.projectPath = session.cwd || null;
|
|
1241
|
+
claudeOpts._perfT0 = t0;
|
|
1242
|
+
// Pass previous worker state for reuse
|
|
1243
|
+
if (session._adapterWorkerState) {
|
|
1244
|
+
claudeOpts._workerState = session._adapterWorkerState;
|
|
1245
|
+
session._adapterWorkerState = null;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
// Pick a model that belongs to the session's vendor. sm.currentModel is
|
|
1250
|
+
// shared project-wide, so a Codex session that last set it to
|
|
1251
|
+
// "gpt-5.4-mini" would otherwise leak into a Claude session in the same
|
|
1252
|
+
// project (or in another session that switches vendor to claude) and
|
|
1253
|
+
// Claude would reject the unknown model. We validate against the
|
|
1254
|
+
// session vendor's model list regardless of which vendor happens to be
|
|
1255
|
+
// the project's default adapter.
|
|
1256
|
+
var queryModel = (ls.model && ls.model !== "default" ? ls.model : null) || session.model || sm.currentModel || undefined;
|
|
1257
|
+
var sessionVendor = session.vendor || (adapter && adapter.vendor) || null;
|
|
1258
|
+
if (sessionVendor) {
|
|
1259
|
+
var vendorModels = (sm.modelsByVendor && sm.modelsByVendor[sessionVendor]) || [];
|
|
1260
|
+
if (vendorModels.length > 0 && queryModel && !modelListContains(vendorModels, queryModel)) {
|
|
1261
|
+
var resolved = resolveModelInList(vendorModels, queryModel);
|
|
1262
|
+
queryModel = resolved || modelEntryValue(vendorModels[0]);
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
// Guard against anything upstream having set queryModel to an object
|
|
1266
|
+
// (e.g. a cached ModelInfo leaked through). Always coerce to string id.
|
|
1267
|
+
if (queryModel && typeof queryModel !== "string") {
|
|
1268
|
+
queryModel = modelEntryValue(queryModel) || undefined;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
var codexConfig = getCodexConfig(sm);
|
|
1272
|
+
var mergedMcpServers = mergeMcpServers(getMcpServers(), getRemoteMcpServers) || undefined;
|
|
1273
|
+
var queryOpts = {
|
|
1274
|
+
cwd: cwd,
|
|
1275
|
+
model: queryModel,
|
|
1276
|
+
effort: ls.effort || sm.currentEffort || undefined,
|
|
1277
|
+
toolServers: mergedMcpServers,
|
|
1278
|
+
toolServerDescriptors: extractMcpDescriptors(mergedMcpServers) || undefined,
|
|
1279
|
+
resumeSessionId: session.cliSessionId || undefined,
|
|
1280
|
+
abortController: linuxUser ? undefined : session.abortController,
|
|
1281
|
+
canUseTool: function(toolName, input, toolOpts) {
|
|
1282
|
+
return handleCanUseTool(session, toolName, input, toolOpts);
|
|
1283
|
+
},
|
|
1284
|
+
onElicitation: function(request, elicitOpts) {
|
|
1285
|
+
return handleElicitation(session, request, elicitOpts);
|
|
1286
|
+
},
|
|
1287
|
+
callMcpTool: function(serverName, toolName, args) {
|
|
1288
|
+
return callMcpToolHandler(mergedMcpServers, serverName, toolName, args);
|
|
1289
|
+
},
|
|
1290
|
+
adapterOptions: {
|
|
1291
|
+
CLAUDE: claudeOpts,
|
|
1292
|
+
CODEX: {
|
|
1293
|
+
// Always use "never" (auto-approve) because Clay handles tool
|
|
1294
|
+
// permissions via its own UI (checkToolWhitelist + handleCanUseTool).
|
|
1295
|
+
// Codex's native approval prompts are terminal-based and cannot be
|
|
1296
|
+
// relayed through Clay's web UI, causing MCP tool calls to hang.
|
|
1297
|
+
approvalPolicy: "never",
|
|
1298
|
+
sandboxMode: codexConfig.sandbox,
|
|
1299
|
+
webSearchMode: codexConfig.webSearch,
|
|
1300
|
+
},
|
|
1301
|
+
},
|
|
1302
|
+
};
|
|
1303
|
+
|
|
1304
|
+
var handle;
|
|
1305
|
+
console.log("[sdk-bridge] calling adapter.createQuery... vendor=" + sessionAdapter.vendor);
|
|
1306
|
+
try {
|
|
1307
|
+
handle = await sessionAdapter.createQuery(queryOpts);
|
|
1308
|
+
console.log("[sdk-bridge] createQuery returned handle, vendor=" + sessionAdapter.vendor);
|
|
1309
|
+
} catch (e) {
|
|
1310
|
+
console.error("[sdk-bridge] Failed to create query for session " + session.localId + ":", e.message || e);
|
|
1311
|
+
console.error("[sdk-bridge] cliSessionId:", session.cliSessionId, "resume:", !!session.cliSessionId);
|
|
1312
|
+
console.error("[sdk-bridge] Stack:", e.stack || "(no stack)");
|
|
1313
|
+
session.isProcessing = false;
|
|
1314
|
+
onProcessingChanged();
|
|
1315
|
+
session.queryInstance = null;
|
|
1316
|
+
session.messageQueue = null;
|
|
1317
|
+
session.abortController = null;
|
|
1318
|
+
sendAndRecord(session, { type: "error", text: "Failed to start query: " + (e.message || e) });
|
|
1319
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1320
|
+
sm.broadcastSessionList();
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// Store adapter worker state for reuse on next query
|
|
1325
|
+
if (handle._adapterState) {
|
|
1326
|
+
session._adapterWorkerState = handle._adapterState;
|
|
1327
|
+
// Keep session.worker reference for external code (sessions.js, project.js)
|
|
1328
|
+
// that needs to kill the worker on session destroy.
|
|
1329
|
+
if (handle._adapterState.worker) {
|
|
1330
|
+
session.worker = handle._adapterState.worker;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
// For worker path, create an abortController wrapper that delegates to handle.abort()
|
|
1335
|
+
if (linuxUser) {
|
|
1336
|
+
session.abortController = {
|
|
1337
|
+
abort: function() { handle.abort(); },
|
|
1338
|
+
signal: { aborted: false, addEventListener: function() {} },
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// Store QueryHandle on session for iteration and control.
|
|
1343
|
+
session.queryInstance = handle;
|
|
1344
|
+
|
|
1345
|
+
// Push initial user message through the QueryHandle
|
|
1346
|
+
console.log("[sdk-bridge] pushing initial message via handle.pushMessage...");
|
|
1347
|
+
handle.pushMessage(text, images);
|
|
1348
|
+
console.log("[sdk-bridge] pushMessage done, starting processQueryStream...");
|
|
1349
|
+
|
|
1350
|
+
// For single-turn sessions (Ralph Loop), end the message queue so the SDK
|
|
1351
|
+
// query finishes after processing the one message. Without this, the query
|
|
1352
|
+
// stream stays open forever waiting for more messages, and onQueryComplete
|
|
1353
|
+
// never fires.
|
|
1354
|
+
if (session.singleTurn) {
|
|
1355
|
+
handle.endInput();
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
session.lastActivityAt = Date.now();
|
|
1359
|
+
session.streamPromise = processQueryStream(session).catch(function(err) {
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
function pushMessage(session, text, images) {
|
|
1364
|
+
session.lastActivityAt = Date.now();
|
|
1365
|
+
// Route through QueryHandle (works for both in-process and worker paths)
|
|
1366
|
+
if (session.queryInstance && typeof session.queryInstance.pushMessage === "function") {
|
|
1367
|
+
session.queryInstance.pushMessage(text, images);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
function permissionPushTitle(toolName, input) {
|
|
1372
|
+
if (!input) return "Claude wants to use " + toolName;
|
|
1373
|
+
var file = input.file_path ? input.file_path.split(/[/\\]/).pop() : "";
|
|
1374
|
+
switch (toolName) {
|
|
1375
|
+
case "Bash": return "Claude wants to run a command";
|
|
1376
|
+
case "Edit": return "Claude wants to edit " + (file || "a file");
|
|
1377
|
+
case "Write": return "Claude wants to write " + (file || "a file");
|
|
1378
|
+
case "Read": return "Claude wants to read " + (file || "a file");
|
|
1379
|
+
case "Grep": return "Claude wants to search files";
|
|
1380
|
+
case "Glob": return "Claude wants to find files";
|
|
1381
|
+
case "WebFetch": return "Claude wants to fetch a URL";
|
|
1382
|
+
case "WebSearch": return "Claude wants to search the web";
|
|
1383
|
+
case "Task": return "Claude wants to launch an agent";
|
|
1384
|
+
default: return "Claude wants to use " + toolName;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
function permissionPushBody(toolName, input) {
|
|
1389
|
+
if (!input) return "";
|
|
1390
|
+
var text = "";
|
|
1391
|
+
if (toolName === "Bash" && input.command) {
|
|
1392
|
+
text = input.command;
|
|
1393
|
+
} else if (toolName === "Edit" && input.file_path) {
|
|
1394
|
+
text = input.file_path.split(/[/\\]/).pop() + ": " + (input.old_string || "").substring(0, 40) + " \u2192 " + (input.new_string || "").substring(0, 40);
|
|
1395
|
+
} else if (toolName === "Write" && input.file_path) {
|
|
1396
|
+
text = input.file_path;
|
|
1397
|
+
} else if (input.file_path) {
|
|
1398
|
+
text = input.file_path;
|
|
1399
|
+
} else if (input.command) {
|
|
1400
|
+
text = input.command;
|
|
1401
|
+
} else if (input.url) {
|
|
1402
|
+
text = input.url;
|
|
1403
|
+
} else if (input.query) {
|
|
1404
|
+
text = input.query;
|
|
1405
|
+
} else if (input.pattern) {
|
|
1406
|
+
text = input.pattern;
|
|
1407
|
+
} else if (input.description) {
|
|
1408
|
+
text = input.description;
|
|
1409
|
+
}
|
|
1410
|
+
if (text.length > 120) text = text.substring(0, 120) + "...";
|
|
1411
|
+
return text;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
// Detect which vendor binaries are installed for this user.
|
|
1415
|
+
// In multi-user mode, runs checks as the specific Linux user.
|
|
1416
|
+
function detectInstalledVendors(linuxUser) {
|
|
1417
|
+
var execFileSync = require("child_process").execFileSync;
|
|
1418
|
+
var fs = require("fs");
|
|
1419
|
+
var result = [];
|
|
1420
|
+
|
|
1421
|
+
function tryLookup(name) {
|
|
1422
|
+
try {
|
|
1423
|
+
if (linuxUser) {
|
|
1424
|
+
execFileSync("su", ["-", linuxUser, "-c", "which " + name], { timeout: 3000, stdio: ["pipe", "pipe", "pipe"] });
|
|
1425
|
+
} else {
|
|
1426
|
+
if (process.platform === "win32") execFileSync("where", [name], { timeout: 3000, stdio: ["pipe", "pipe", "pipe"] });
|
|
1427
|
+
else execFileSync("which", [name], { timeout: 3000, stdio: ["pipe", "pipe", "pipe"] });
|
|
1428
|
+
}
|
|
1429
|
+
return true;
|
|
1430
|
+
} catch (e) {
|
|
1431
|
+
return false;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// Claude: check if binary is in PATH
|
|
1436
|
+
if (tryLookup("claude")) result.push("claude");
|
|
1437
|
+
|
|
1438
|
+
// Codex: check bundled binary or PATH
|
|
1439
|
+
var codexBin = null;
|
|
1440
|
+
try {
|
|
1441
|
+
codexBin = require("./yoke/codex-app-server").findCodexPath();
|
|
1442
|
+
} catch (e) {}
|
|
1443
|
+
if ((codexBin && fs.existsSync(codexBin)) || tryLookup("codex")) result.push("codex");
|
|
1444
|
+
|
|
1445
|
+
return result;
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
// SDK warmup: initialize all available adapters and collect models.
|
|
1449
|
+
// The default adapter is initialized first for slash_commands and skills.
|
|
1450
|
+
// Passes linuxUser to adapter for worker-based warmup when OS isolation is needed.
|
|
1451
|
+
async function warmup(linuxUser) {
|
|
1452
|
+
var defaultVendor = adapter ? adapter.vendor : "claude";
|
|
1453
|
+
sm.defaultVendor = defaultVendor;
|
|
1454
|
+
|
|
1455
|
+
// Initialize default adapter first (provides skills, slash commands, etc.)
|
|
1456
|
+
if (adapter) {
|
|
1457
|
+
try {
|
|
1458
|
+
var result = await adapter.init({
|
|
1459
|
+
cwd: cwd,
|
|
1460
|
+
dangerouslySkipPermissions: dangerouslySkipPermissions,
|
|
1461
|
+
linuxUser: linuxUser || undefined,
|
|
1462
|
+
clayPort: clayPort,
|
|
1463
|
+
clayTls: clayTls,
|
|
1464
|
+
clayAuthToken: clayAuthToken,
|
|
1465
|
+
slug: slug,
|
|
1466
|
+
});
|
|
1467
|
+
|
|
1468
|
+
var fsSkills = discoverSkillDirs();
|
|
1469
|
+
sm.skillNames = mergeSkills(result.skills, fsSkills);
|
|
1470
|
+
if (result.slashCommands) {
|
|
1471
|
+
var seen = new Set();
|
|
1472
|
+
var combined = [];
|
|
1473
|
+
var all = result.slashCommands.concat(Array.from(sm.skillNames));
|
|
1474
|
+
for (var k = 0; k < all.length; k++) {
|
|
1475
|
+
if (!seen.has(all[k])) {
|
|
1476
|
+
seen.add(all[k]);
|
|
1477
|
+
combined.push(all[k]);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
sm.slashCommands = combined;
|
|
1481
|
+
sm.setSlashCommandsForVendor(defaultVendor, combined);
|
|
1482
|
+
send({ type: "slash_commands", commands: combined, vendor: defaultVendor });
|
|
1483
|
+
}
|
|
1484
|
+
if (result.defaultModel) {
|
|
1485
|
+
sm.currentModel = sm.currentModel || sm._savedDefaultModel || result.defaultModel;
|
|
1486
|
+
}
|
|
1487
|
+
sm.availableModels = result.models || [];
|
|
1488
|
+
// Store per-vendor models and capabilities
|
|
1489
|
+
sm.modelsByVendor = sm.modelsByVendor || {};
|
|
1490
|
+
sm.modelsByVendor[defaultVendor] = result.models || [];
|
|
1491
|
+
sm.capabilitiesByVendor = sm.capabilitiesByVendor || {};
|
|
1492
|
+
sm.capabilitiesByVendor[defaultVendor] = result.capabilities || {};
|
|
1493
|
+
} catch (e) {
|
|
1494
|
+
if (e && e.name !== "AbortError" && !(e.message && e.message.indexOf("aborted") !== -1)) {
|
|
1495
|
+
send({ type: "error", text: "Failed to load " + defaultVendor + " SDK: " + (e.message || e) });
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
// Non-default adapters are NOT eagerly initialized here. Doing so used
|
|
1501
|
+
// to spawn a CodexAppServer and an mcp-bridge child per project even
|
|
1502
|
+
// when the user never touched that vendor. Lazy paths cover the gap:
|
|
1503
|
+
// - get_vendor_models (project.js) inits a vendor when the user
|
|
1504
|
+
// opens its model picker.
|
|
1505
|
+
// - ensureVendorReady (this file) inits a vendor when a session
|
|
1506
|
+
// actually issues a query with it.
|
|
1507
|
+
sm.modelsByVendor = sm.modelsByVendor || {};
|
|
1508
|
+
|
|
1509
|
+
// Detect installed vendors per-user (binary existence check)
|
|
1510
|
+
sm.installedVendors = detectInstalledVendors(linuxUser);
|
|
1511
|
+
sm.availableVendors = Object.keys(adapters);
|
|
1512
|
+
|
|
1513
|
+
// Send initial state to client
|
|
1514
|
+
send({
|
|
1515
|
+
type: "model_info",
|
|
1516
|
+
model: sm.currentModel || "",
|
|
1517
|
+
models: getModelsForVendor(defaultVendor),
|
|
1518
|
+
vendor: defaultVendor,
|
|
1519
|
+
availableVendors: sm.availableVendors,
|
|
1520
|
+
installedVendors: sm.installedVendors,
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
async function setModel(session, model) {
|
|
1525
|
+
// Normalize to string id in case a { value, displayName } object slips in
|
|
1526
|
+
if (model && typeof model !== "string") {
|
|
1527
|
+
model = modelEntryValue(model);
|
|
1528
|
+
}
|
|
1529
|
+
if (!session.queryInstance) {
|
|
1530
|
+
// No active query — store on session and shared state for next startQuery
|
|
1531
|
+
session.model = model;
|
|
1532
|
+
sm.currentModel = model;
|
|
1533
|
+
// Don't send vendor here: session vendor not yet bound, let client keep its selection
|
|
1534
|
+
sendModelInfoForVendor(null, model);
|
|
1535
|
+
// config_state is sent targeted by the caller (project-sessions.js) to
|
|
1536
|
+
// avoid broadcasting this session's model to all other open sessions.
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
try {
|
|
1540
|
+
await session.queryInstance.setModel(model);
|
|
1541
|
+
session.model = model;
|
|
1542
|
+
sm.currentModel = model;
|
|
1543
|
+
var sessionVendor = session.vendor || (adapter && adapter.vendor) || "claude";
|
|
1544
|
+
sendModelInfoForVendor(sessionVendor, model);
|
|
1545
|
+
// config_state sent targeted by caller — no broadcast here.
|
|
1546
|
+
} catch (e) {
|
|
1547
|
+
send({ type: "error", text: "Failed to switch model: " + (e.message || e) });
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
async function setEffort(session, effort) {
|
|
1552
|
+
if (!session.queryInstance) {
|
|
1553
|
+
sm.currentEffort = effort;
|
|
1554
|
+
send({ type: "config_state", model: sm.currentModel || "", mode: sm.currentPermissionMode || "default", effort: sm.currentEffort, betas: sm.currentBetas || [] });
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
// Route through QueryHandle (works for both in-process and worker paths)
|
|
1558
|
+
if (typeof session.queryInstance.setEffort === "function") {
|
|
1559
|
+
await session.queryInstance.setEffort(effort);
|
|
1560
|
+
}
|
|
1561
|
+
sm.currentEffort = effort;
|
|
1562
|
+
send({ type: "config_state", model: sm.currentModel || "", mode: sm.currentPermissionMode || "default", effort: sm.currentEffort, betas: sm.currentBetas || [] });
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
async function setPermissionMode(session, mode) {
|
|
1566
|
+
if (!session.queryInstance) {
|
|
1567
|
+
// No active query — store on session only (not sm — that's for project defaults).
|
|
1568
|
+
// config_state sent targeted by caller (project-sessions.js).
|
|
1569
|
+
session.permissionMode = mode;
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
try {
|
|
1573
|
+
// Route through QueryHandle (works for both in-process and worker paths)
|
|
1574
|
+
await session.queryInstance.setPermissionMode(mode);
|
|
1575
|
+
session.permissionMode = mode;
|
|
1576
|
+
// config_state sent targeted by caller — no broadcast here.
|
|
1577
|
+
} catch (e) {
|
|
1578
|
+
send({ type: "error", text: "Failed to set permission mode: " + (e.message || e) });
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
async function stopTask(taskId) {
|
|
1583
|
+
var session = sm.getActiveSession();
|
|
1584
|
+
if (!session) return;
|
|
1585
|
+
session.taskStopRequested = true;
|
|
1586
|
+
if (!session.queryInstance) return;
|
|
1587
|
+
try {
|
|
1588
|
+
// Route through QueryHandle (works for both in-process and worker paths)
|
|
1589
|
+
await session.queryInstance.stopTask(taskId);
|
|
1590
|
+
} catch (e) {
|
|
1591
|
+
console.error("[sdk-bridge] stopTask error:", e.message);
|
|
1592
|
+
}
|
|
1593
|
+
// SDK stopTask doesn't reliably stop the sub-agent, so abort the entire
|
|
1594
|
+
// session as a fallback to ensure the process actually stops.
|
|
1595
|
+
if (session.abortController) {
|
|
1596
|
+
session.abortController.abort();
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
// --- @Mention: persistent read-only session for a mentioned Mate ---
|
|
1601
|
+
// Creates a mention session that can be reused across multiple mentions
|
|
1602
|
+
// within a conversation flow (session continuity).
|
|
1603
|
+
async function createMentionSession(opts) {
|
|
1604
|
+
// opts: { vendor, claudeMd, initialContext, initialMessage, onDelta, onDone, onError, onActivity }
|
|
1605
|
+
var abortController = new AbortController();
|
|
1606
|
+
|
|
1607
|
+
// Current response callbacks (swapped on each pushMessage)
|
|
1608
|
+
var currentOnDelta = opts.onDelta;
|
|
1609
|
+
var currentOnDone = opts.onDone;
|
|
1610
|
+
var currentOnError = opts.onError;
|
|
1611
|
+
var currentOnActivity = opts.onActivity || null;
|
|
1612
|
+
var responseFullText = "";
|
|
1613
|
+
var responseStreamedText = false;
|
|
1614
|
+
var mentionBlocks = {};
|
|
1615
|
+
var alive = true;
|
|
1616
|
+
|
|
1617
|
+
// Use the mate's vendor adapter if specified, otherwise default
|
|
1618
|
+
var mentionAdapter = (opts.vendor && adapters[opts.vendor]) || adapter;
|
|
1619
|
+
|
|
1620
|
+
var handle;
|
|
1621
|
+
try {
|
|
1622
|
+
handle = await mentionAdapter.createQuery({
|
|
1623
|
+
cwd: cwd,
|
|
1624
|
+
systemPrompt: opts.claudeMd,
|
|
1625
|
+
model: opts.model || undefined,
|
|
1626
|
+
toolServers: opts.includeMcpServers ? (mergeMcpServers(getMcpServers(), getRemoteMcpServers) || undefined) : undefined,
|
|
1627
|
+
abortController: abortController,
|
|
1628
|
+
canUseTool: opts.canUseTool || function (toolName, input) {
|
|
1629
|
+
var whitelisted = checkToolWhitelist(toolName, input);
|
|
1630
|
+
if (whitelisted) {
|
|
1631
|
+
return Promise.resolve(whitelisted);
|
|
1632
|
+
}
|
|
1633
|
+
return Promise.resolve({
|
|
1634
|
+
behavior: "deny",
|
|
1635
|
+
message: "Read-only access. You cannot make changes via @mention.",
|
|
1636
|
+
});
|
|
1637
|
+
},
|
|
1638
|
+
adapterOptions: {
|
|
1639
|
+
CLAUDE: {
|
|
1640
|
+
settingSources: ["user"],
|
|
1641
|
+
includePartialMessages: true,
|
|
1642
|
+
},
|
|
1643
|
+
},
|
|
1644
|
+
});
|
|
1645
|
+
} catch (e) {
|
|
1646
|
+
opts.onError("Failed to create mention query: " + (e.message || e));
|
|
1647
|
+
return null;
|
|
1648
|
+
}
|
|
1649
|
+
var query = handle;
|
|
1650
|
+
|
|
1651
|
+
// Push the initial message (context + question, with optional images)
|
|
1652
|
+
var initialPrompt = opts.initialContext + "\n\n" + opts.initialMessage;
|
|
1653
|
+
handle.pushMessage(initialPrompt, opts.initialImages || null);
|
|
1654
|
+
|
|
1655
|
+
// Background stream processing loop (consumes flattened yokeType events)
|
|
1656
|
+
(async function () {
|
|
1657
|
+
try {
|
|
1658
|
+
for await (var msg of query) {
|
|
1659
|
+
// Track content blocks for activity reporting
|
|
1660
|
+
if (msg.yokeType === "thinking_start") {
|
|
1661
|
+
mentionBlocks[msg.blockId] = { type: "thinking" };
|
|
1662
|
+
if (currentOnActivity) currentOnActivity("thinking");
|
|
1663
|
+
} else if (msg.yokeType === "tool_start") {
|
|
1664
|
+
mentionBlocks[msg.blockId] = { type: "tool_use", name: msg.toolName, inputJson: "" };
|
|
1665
|
+
var toolLabel = msg.toolName;
|
|
1666
|
+
if (toolLabel === "Read") toolLabel = "Reading file...";
|
|
1667
|
+
else if (toolLabel === "Grep") toolLabel = "Searching code...";
|
|
1668
|
+
else if (toolLabel === "Glob") toolLabel = "Finding files...";
|
|
1669
|
+
if (currentOnActivity) currentOnActivity(toolLabel);
|
|
1670
|
+
} else if (msg.yokeType === "text_start") {
|
|
1671
|
+
mentionBlocks[msg.blockId] = { type: "text" };
|
|
1672
|
+
|
|
1673
|
+
} else if (msg.yokeType === "text_delta" && typeof msg.text === "string") {
|
|
1674
|
+
responseStreamedText = true;
|
|
1675
|
+
responseFullText += msg.text;
|
|
1676
|
+
if (currentOnActivity) currentOnActivity(null);
|
|
1677
|
+
if (currentOnDelta) currentOnDelta(msg.text);
|
|
1678
|
+
} else if (msg.yokeType === "tool_input_delta" && mentionBlocks[msg.blockId]) {
|
|
1679
|
+
mentionBlocks[msg.blockId].inputJson += msg.partialJson;
|
|
1680
|
+
|
|
1681
|
+
} else if (msg.yokeType === "block_stop") {
|
|
1682
|
+
var blk = mentionBlocks[msg.blockId];
|
|
1683
|
+
if (blk && blk.type === "tool_use") {
|
|
1684
|
+
var toolInput = {};
|
|
1685
|
+
try { toolInput = JSON.parse(blk.inputJson); } catch (e) {}
|
|
1686
|
+
if (blk.name === "Read" && toolInput.file_path) {
|
|
1687
|
+
var fname = toolInput.file_path.split(/[/\\]/).pop();
|
|
1688
|
+
if (currentOnActivity) currentOnActivity("Reading " + fname + "...");
|
|
1689
|
+
} else if (blk.name === "Grep" && toolInput.pattern) {
|
|
1690
|
+
if (currentOnActivity) currentOnActivity("Searching: " + toolInput.pattern.substring(0, 30) + "...");
|
|
1691
|
+
} else if (blk.name === "Glob" && toolInput.pattern) {
|
|
1692
|
+
if (currentOnActivity) currentOnActivity("Finding: " + toolInput.pattern.substring(0, 30) + "...");
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
delete mentionBlocks[msg.blockId];
|
|
1696
|
+
|
|
1697
|
+
} else if (msg.yokeType === "message" && msg.messageRole === "assistant" && !responseStreamedText && msg.content) {
|
|
1698
|
+
// Fallback: if text was not streamed via deltas, extract from assistant message
|
|
1699
|
+
var content = msg.content;
|
|
1700
|
+
if (Array.isArray(content)) {
|
|
1701
|
+
for (var ci = 0; ci < content.length; ci++) {
|
|
1702
|
+
if (content[ci].type === "text" && content[ci].text) {
|
|
1703
|
+
responseFullText += content[ci].text;
|
|
1704
|
+
if (currentOnDelta) currentOnDelta(content[ci].text);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
} else if (msg.yokeType === "result") {
|
|
1710
|
+
// One response complete. Signal done and reset for next message.
|
|
1711
|
+
if (currentOnActivity) currentOnActivity(null);
|
|
1712
|
+
var doneRef = currentOnDone;
|
|
1713
|
+
if (doneRef) {
|
|
1714
|
+
doneRef(responseFullText);
|
|
1715
|
+
}
|
|
1716
|
+
// Only reset if pushMessage was not called during onDone
|
|
1717
|
+
// (pushMessage swaps callbacks and resets state itself)
|
|
1718
|
+
if (currentOnDone === doneRef) {
|
|
1719
|
+
currentOnDelta = null;
|
|
1720
|
+
currentOnDone = null;
|
|
1721
|
+
currentOnError = null;
|
|
1722
|
+
currentOnActivity = null;
|
|
1723
|
+
mentionBlocks = {};
|
|
1724
|
+
responseFullText = "";
|
|
1725
|
+
responseStreamedText = false;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
} catch (err) {
|
|
1730
|
+
if (currentOnError) {
|
|
1731
|
+
if (err.name === "AbortError" || (abortController && abortController.signal.aborted)) {
|
|
1732
|
+
currentOnError("Mention query was cancelled.");
|
|
1733
|
+
} else {
|
|
1734
|
+
currentOnError(err.message || String(err));
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
alive = false;
|
|
1739
|
+
})();
|
|
1740
|
+
|
|
1741
|
+
return {
|
|
1742
|
+
// Push a follow-up message to the existing mention session
|
|
1743
|
+
pushMessage: function (text, callbacks, images) {
|
|
1744
|
+
currentOnDelta = callbacks.onDelta;
|
|
1745
|
+
currentOnDone = callbacks.onDone;
|
|
1746
|
+
currentOnError = callbacks.onError;
|
|
1747
|
+
currentOnActivity = callbacks.onActivity || null;
|
|
1748
|
+
mentionBlocks = {};
|
|
1749
|
+
responseFullText = "";
|
|
1750
|
+
responseStreamedText = false;
|
|
1751
|
+
handle.pushMessage(text, images || null);
|
|
1752
|
+
},
|
|
1753
|
+
abort: function () {
|
|
1754
|
+
try { abortController.abort(); } catch (e) {}
|
|
1755
|
+
},
|
|
1756
|
+
close: function () {
|
|
1757
|
+
alive = false;
|
|
1758
|
+
try { handle.close(); } catch (e) {}
|
|
1759
|
+
},
|
|
1760
|
+
isAlive: function () { return alive; },
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
return {
|
|
1765
|
+
createMessageQueue: createMessageQueue,
|
|
1766
|
+
processSDKMessage: processSDKMessage,
|
|
1767
|
+
checkToolWhitelist: checkToolWhitelist,
|
|
1768
|
+
handleCanUseTool: handleCanUseTool,
|
|
1769
|
+
handleElicitation: handleElicitation,
|
|
1770
|
+
processQueryStream: processQueryStream,
|
|
1771
|
+
getOrCreateRewindQuery: getOrCreateRewindQuery,
|
|
1772
|
+
rewindPreview: rewindPreview,
|
|
1773
|
+
rewindExecuteFiles: rewindExecuteFiles,
|
|
1774
|
+
rollbackConversation: rollbackConversation,
|
|
1775
|
+
forkSession: forkSessionUnified,
|
|
1776
|
+
startQuery: startQuery,
|
|
1777
|
+
pushMessage: pushMessage,
|
|
1778
|
+
setModel: setModel,
|
|
1779
|
+
setEffort: setEffort,
|
|
1780
|
+
setPermissionMode: setPermissionMode,
|
|
1781
|
+
isClaudeProcess: isClaudeProcess,
|
|
1782
|
+
permissionPushTitle: permissionPushTitle,
|
|
1783
|
+
permissionPushBody: permissionPushBody,
|
|
1784
|
+
warmup: warmup,
|
|
1785
|
+
stopTask: stopTask,
|
|
1786
|
+
createMentionSession: createMentionSession,
|
|
1787
|
+
startIdleReaper: startIdleReaper,
|
|
1788
|
+
stopIdleReaper: stopIdleReaper,
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
module.exports = { createSDKBridge, createMessageQueue };
|