clay-server 2.34.0-beta.3 → 2.34.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,6 +89,56 @@ function generateUuid() {
89
89
  return "codex-" + ts + "-" + cnt + "-" + rnd;
90
90
  }
91
91
 
92
+ function waitMs(ms) {
93
+ return new Promise(function(resolve) {
94
+ setTimeout(resolve, ms);
95
+ });
96
+ }
97
+
98
+ function waitForProcessExit(proc, timeoutMs) {
99
+ return new Promise(function(resolve) {
100
+ if (!proc) {
101
+ resolve(true);
102
+ return;
103
+ }
104
+
105
+ if (proc.exitCode !== null || proc.signalCode !== null) {
106
+ resolve(true);
107
+ return;
108
+ }
109
+
110
+ var done = false;
111
+ var timer = null;
112
+
113
+ function cleanup() {
114
+ if (done) return;
115
+ done = true;
116
+ if (timer) clearTimeout(timer);
117
+ proc.removeListener("exit", onDone);
118
+ proc.removeListener("close", onDone);
119
+ }
120
+
121
+ function onDone() {
122
+ cleanup();
123
+ resolve(true);
124
+ }
125
+
126
+ proc.once("exit", onDone);
127
+ proc.once("close", onDone);
128
+
129
+ timer = setTimeout(function() {
130
+ cleanup();
131
+ resolve(false);
132
+ }, timeoutMs || 5000);
133
+ });
134
+ }
135
+
136
+ function createShutdownError() {
137
+ var err = new Error("Codex adapter is shutting down, retry shortly");
138
+ err.code = "CODEX_ADAPTER_SHUTTING_DOWN";
139
+ return err;
140
+ }
141
+
92
142
  function normalizePlanStatus(status) {
93
143
  if (status === "inProgress") return "in_progress";
94
144
  if (status === "completed") return "completed";
@@ -310,16 +360,33 @@ function flattenEvent(notification, state) {
310
360
  state.thinkingBlocks[item.id] = "blk_" + state.blockCounter;
311
361
  events.push({ yokeType: "thinking_start", blockId: "blk_" + state.blockCounter });
312
362
  }
313
- if (item.text) {
363
+ // Codex reasoning items may expose plain text via `text`, a short
364
+ // `summary`, or nested `content` parts. Prefer whichever is present;
365
+ // many turns arrive with only encrypted reasoning and no readable
366
+ // text at all, in which case the UI will hide the expand affordance.
367
+ var reasoningText = "";
368
+ if (typeof item.text === "string" && item.text.length > 0) {
369
+ reasoningText = item.text;
370
+ } else if (typeof item.summary === "string" && item.summary.length > 0) {
371
+ reasoningText = item.summary;
372
+ } else if (Array.isArray(item.content)) {
373
+ var parts = [];
374
+ for (var rpi = 0; rpi < item.content.length; rpi++) {
375
+ var rp = item.content[rpi];
376
+ if (rp && typeof rp.text === "string") parts.push(rp.text);
377
+ }
378
+ reasoningText = parts.join("\n");
379
+ }
380
+ if (reasoningText) {
314
381
  var thinkBlockId = state.thinkingBlocks[item.id];
315
382
  var prevThinkLen = state.thinkingLengths[item.id] || 0;
316
- if (item.text.length > prevThinkLen) {
383
+ if (reasoningText.length > prevThinkLen) {
317
384
  events.push({
318
385
  yokeType: "thinking_delta",
319
386
  blockId: thinkBlockId,
320
- text: item.text.substring(prevThinkLen),
387
+ text: reasoningText.substring(prevThinkLen),
321
388
  });
322
- state.thinkingLengths[item.id] = item.text.length;
389
+ state.thinkingLengths[item.id] = reasoningText.length;
323
390
  }
324
391
  }
325
392
  if (evtPhase === "completed") {
@@ -503,6 +570,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
503
570
  var systemPrompt = queryOpts.systemPrompt || "";
504
571
  var canUseTool = queryOpts.canUseTool || null;
505
572
  var onElicitation = queryOpts.onElicitation || null;
573
+ var onFinished = queryOpts.onFinished || null;
506
574
 
507
575
  // Check if the query was cancelled (either via handle.abort() or direct signal abort)
508
576
  function isCancelled() {
@@ -533,6 +601,19 @@ function createCodexQueryHandle(appServer, queryOpts) {
533
601
  var eventBuffer = [];
534
602
  var eventWaiting = null;
535
603
  var iteratorDone = false;
604
+ var finishedNotified = false;
605
+
606
+ function notifyFinished() {
607
+ if (finishedNotified) return;
608
+ finishedNotified = true;
609
+ if (typeof onFinished === "function") {
610
+ try {
611
+ onFinished();
612
+ } catch (e) {
613
+ console.error("[yoke/codex] onFinished error:", e.message || e);
614
+ }
615
+ }
616
+ }
536
617
 
537
618
  function pushEvent(evt) {
538
619
  if (iteratorDone) return;
@@ -552,6 +633,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
552
633
  eventWaiting = null;
553
634
  resolve({ value: undefined, done: true });
554
635
  }
636
+ notifyFinished();
555
637
  }
556
638
 
557
639
  // Message queue for multi-turn
@@ -936,48 +1018,182 @@ function createCodexQueryHandle(appServer, queryOpts) {
936
1018
 
937
1019
  function createCodexAdapter(opts) {
938
1020
  var _cwd = (opts && opts.cwd) || process.cwd();
1021
+ var _slug = (opts && opts.slug) || "";
1022
+ var _defaultInitOpts = Object.assign({}, opts || {});
939
1023
  var _cachedModels = [];
940
1024
  var _appServer = null;
941
1025
  var _initPromise = null;
942
- var _initOpts = null; // stored for query-time access
1026
+ var _shutdownPromise = null;
1027
+ var _refCount = 0;
1028
+ var _lastActiveAt = Date.now();
1029
+ var _shuttingDown = false;
1030
+ var _activeQueries = [];
1031
+
1032
+ function updateLastActiveAt() {
1033
+ _lastActiveAt = Date.now();
1034
+ }
1035
+
1036
+ function registerActiveQuery(entry) {
1037
+ _activeQueries.push(entry);
1038
+ }
1039
+
1040
+ function removeActiveQuery(entry) {
1041
+ var next = [];
1042
+ for (var i = 0; i < _activeQueries.length; i++) {
1043
+ if (_activeQueries[i] !== entry) next.push(_activeQueries[i]);
1044
+ }
1045
+ _activeQueries = next;
1046
+ }
1047
+
1048
+ function decrementRefCount() {
1049
+ if (_refCount > 0) {
1050
+ _refCount--;
1051
+ } else {
1052
+ console.error("[yoke/codex] refCount negative, bug!");
1053
+ _refCount = 0;
1054
+ }
1055
+ updateLastActiveAt();
1056
+ }
1057
+
1058
+ function buildReadyResponse(skillNames) {
1059
+ return {
1060
+ models: _cachedModels,
1061
+ defaultModel: "gpt-5.4",
1062
+ skills: skillNames || [],
1063
+ slashCommands: skillNames || [],
1064
+ fastModeState: null,
1065
+ capabilities: {
1066
+ thinking: true,
1067
+ betas: false,
1068
+ rewind: false,
1069
+ sessionResume: true,
1070
+ promptSuggestions: true,
1071
+ elicitation: true,
1072
+ fileCheckpointing: false,
1073
+ contextCompacting: false,
1074
+ toolPolicy: ["ask", "allow-all"],
1075
+ },
1076
+ };
1077
+ }
1078
+
1079
+ function clearRuntimeState() {
1080
+ _appServer = null;
1081
+ _initPromise = null;
1082
+ _cachedModels = [];
1083
+ _refCount = 0;
1084
+ _activeQueries = [];
1085
+ updateLastActiveAt();
1086
+ }
1087
+
1088
+ function waitForRefCount(targetCount, timeoutMs) {
1089
+ var deadline = Date.now() + (timeoutMs || 5000);
1090
+ return new Promise(function(resolve) {
1091
+ function tick() {
1092
+ if (_refCount <= targetCount) {
1093
+ resolve(true);
1094
+ return;
1095
+ }
1096
+ if (Date.now() >= deadline) {
1097
+ resolve(false);
1098
+ return;
1099
+ }
1100
+ setTimeout(tick, 50);
1101
+ }
1102
+ tick();
1103
+ });
1104
+ }
1105
+
1106
+ function stopAppServer(deadlineMs) {
1107
+ var proc = _appServer && _appServer.proc ? _appServer.proc : null;
1108
+ if (!_appServer) return Promise.resolve(true);
1109
+ try {
1110
+ _appServer.stop();
1111
+ } catch (e) {
1112
+ console.error("[yoke/codex] App-server stop error:", e.message || e);
1113
+ }
1114
+ if (!proc) return Promise.resolve(true);
1115
+ var remaining = (typeof deadlineMs === "number") ? Math.max(0, deadlineMs - Date.now()) : 5000;
1116
+ return waitForProcessExit(proc, remaining).then(function(exited) {
1117
+ if (!exited) {
1118
+ try {
1119
+ proc.kill("SIGKILL");
1120
+ } catch (e) {}
1121
+ }
1122
+ return exited;
1123
+ });
1124
+ }
1125
+
1126
+ function beginShutdown(force, idleMs) {
1127
+ if (_shutdownPromise) return _shutdownPromise;
1128
+ if (_shuttingDown) return null;
1129
+
1130
+ _shuttingDown = true;
1131
+
1132
+ _shutdownPromise = (async function() {
1133
+ var deadline = Date.now() + 5000;
1134
+ var shouldAbort = !!force;
1135
+
1136
+ if (_initPromise) {
1137
+ try {
1138
+ await Promise.race([
1139
+ _initPromise.catch(function() { return null; }),
1140
+ waitMs(Math.max(0, deadline - Date.now())),
1141
+ ]);
1142
+ } catch (e) {}
1143
+ }
1144
+
1145
+ if (shouldAbort && _activeQueries.length > 0) {
1146
+ var active = _activeQueries.slice();
1147
+ for (var i = 0; i < active.length; i++) {
1148
+ try {
1149
+ if (active[i] && active[i].abort) active[i].abort();
1150
+ } catch (e) {}
1151
+ }
1152
+ await waitForRefCount(0, Math.max(0, deadline - Date.now()));
1153
+ }
1154
+
1155
+ if (_appServer) {
1156
+ await stopAppServer(deadline);
1157
+ }
1158
+
1159
+ clearRuntimeState();
1160
+ _shuttingDown = false;
1161
+ _shutdownPromise = null;
1162
+ return true;
1163
+ })().catch(function(err) {
1164
+ clearRuntimeState();
1165
+ _shuttingDown = false;
1166
+ _shutdownPromise = null;
1167
+ throw err;
1168
+ });
1169
+
1170
+ return _shutdownPromise;
1171
+ }
943
1172
 
944
1173
  var adapter = {
945
1174
  vendor: "codex",
946
1175
 
947
1176
  init: function(initOpts) {
1177
+ if (_shuttingDown) {
1178
+ return Promise.reject(createShutdownError());
1179
+ }
1180
+
1181
+ var effectiveInitOpts = Object.assign({}, _defaultInitOpts, initOpts || {});
1182
+
948
1183
  // Already initialized - return cached result
949
1184
  if (_appServer && _appServer.started && _cachedModels.length > 0) {
950
- return Promise.resolve({
951
- models: _cachedModels,
952
- defaultModel: "gpt-5.4",
953
- skills: [],
954
- slashCommands: [],
955
- fastModeState: null,
956
- capabilities: {
957
- thinking: true,
958
- betas: false,
959
- rewind: false,
960
- sessionResume: true,
961
- promptSuggestions: true,
962
- elicitation: true,
963
- fileCheckpointing: false,
964
- contextCompacting: false,
965
- toolPolicy: ["ask", "allow-all"],
966
- },
967
- });
1185
+ return Promise.resolve(buildReadyResponse([]));
968
1186
  }
969
1187
 
970
1188
  // Deduplicate concurrent init calls
971
1189
  if (_initPromise) return _initPromise;
972
1190
 
973
1191
  _initPromise = (async function() {
974
- _initOpts = initOpts;
975
-
976
1192
  var serverOpts = { cwd: _cwd };
977
1193
 
978
1194
  // Extract adapter options
979
- if (initOpts && initOpts.adapterOptions && initOpts.adapterOptions.CODEX) {
980
- var co = initOpts.adapterOptions.CODEX;
1195
+ if (effectiveInitOpts && effectiveInitOpts.adapterOptions && effectiveInitOpts.adapterOptions.CODEX) {
1196
+ var co = effectiveInitOpts.adapterOptions.CODEX;
981
1197
  if (co.apiKey) serverOpts.env = Object.assign({}, serverOpts.env || {}, { OPENAI_API_KEY: co.apiKey });
982
1198
  if (co.baseUrl) serverOpts.env = Object.assign({}, serverOpts.env || {}, { OPENAI_BASE_URL: co.baseUrl });
983
1199
  if (co.config) serverOpts.config = co.config;
@@ -1005,10 +1221,10 @@ function createCodexAdapter(opts) {
1005
1221
 
1006
1222
  // Track 2: Add clay-tools bridge server for in-app + remote MCP tools.
1007
1223
  var bridgePath = require("path").join(__dirname, "..", "mcp-bridge-server.js");
1008
- var clayPort = (initOpts && initOpts.clayPort) || process.env.CLAY_PORT || 2633;
1009
- var clayTls = (initOpts && initOpts.clayTls) || false;
1010
- var clayAuthToken = (initOpts && initOpts.clayAuthToken) || "";
1011
- var claySlug = (initOpts && initOpts.slug) || "";
1224
+ var clayPort = effectiveInitOpts.clayPort || process.env.CLAY_PORT || 2633;
1225
+ var clayTls = effectiveInitOpts.clayTls || false;
1226
+ var clayAuthToken = effectiveInitOpts.clayAuthToken || "";
1227
+ var claySlug = effectiveInitOpts.slug || _slug || "";
1012
1228
  try {
1013
1229
  if (require("fs").existsSync(bridgePath)) {
1014
1230
  var bridgeArgs = [bridgePath, "--port", String(clayPort), "--slug", claySlug];
@@ -1049,6 +1265,11 @@ function createCodexAdapter(opts) {
1049
1265
  });
1050
1266
  _appServer.notify("initialized", {});
1051
1267
 
1268
+ if (_shuttingDown) {
1269
+ await stopAppServer(Date.now() + 1000);
1270
+ throw createShutdownError();
1271
+ }
1272
+
1052
1273
  console.log("[codex] App-server initialized, models: gpt-5.4, gpt-5.4-mini, gpt-5.3-codex, gpt-5.3-codex-spark, gpt-5.2");
1053
1274
 
1054
1275
  _cachedModels = [
@@ -1097,26 +1318,15 @@ function createCodexAdapter(opts) {
1097
1318
  console.error("[codex] Failed to discover skills:", e.message);
1098
1319
  }
1099
1320
 
1321
+ if (_shuttingDown) {
1322
+ await stopAppServer(Date.now() + 1000);
1323
+ throw createShutdownError();
1324
+ }
1325
+
1100
1326
  _initPromise = null;
1327
+ updateLastActiveAt();
1101
1328
 
1102
- return {
1103
- models: _cachedModels,
1104
- defaultModel: "gpt-5.4",
1105
- skills: skillNames,
1106
- slashCommands: skillNames,
1107
- fastModeState: null,
1108
- capabilities: {
1109
- thinking: true,
1110
- betas: false,
1111
- rewind: false,
1112
- sessionResume: true,
1113
- promptSuggestions: true,
1114
- elicitation: true,
1115
- fileCheckpointing: false,
1116
- contextCompacting: false,
1117
- toolPolicy: ["ask", "allow-all"],
1118
- },
1119
- };
1329
+ return buildReadyResponse(skillNames);
1120
1330
  })();
1121
1331
 
1122
1332
  return _initPromise;
@@ -1134,12 +1344,31 @@ function createCodexAdapter(opts) {
1134
1344
  },
1135
1345
 
1136
1346
  createQuery: async function(queryOpts) {
1347
+ if (_shuttingDown) {
1348
+ throw createShutdownError();
1349
+ }
1350
+
1351
+ if (!_appServer || !_appServer.started) {
1352
+ await adapter.init(queryOpts || {});
1353
+ }
1354
+
1355
+ if (_shuttingDown) {
1356
+ throw createShutdownError();
1357
+ }
1358
+
1137
1359
  if (!_appServer || !_appServer.started) {
1138
1360
  throw new Error("[yoke/codex] Adapter not initialized. Call init() first.");
1139
1361
  }
1140
1362
 
1141
1363
  var model = queryOpts.model || "gpt-5.4";
1142
1364
  var ac = queryOpts.abortController || new AbortController();
1365
+ var activeEntry = {
1366
+ abort: function() {
1367
+ try {
1368
+ ac.abort();
1369
+ } catch (e) {}
1370
+ },
1371
+ };
1143
1372
 
1144
1373
  // Map YOKE options to Codex thread options
1145
1374
  var codexOpts = (queryOpts.adapterOptions && queryOpts.adapterOptions.CODEX) || {};
@@ -1176,7 +1405,33 @@ function createCodexAdapter(opts) {
1176
1405
 
1177
1406
  console.log("[yoke/codex] createQuery: model=" + model + " approval=" + handleOpts.approvalPolicy + " sandbox=" + handleOpts.sandboxMode);
1178
1407
 
1179
- var handle = createCodexQueryHandle(_appServer, handleOpts);
1408
+ _refCount++;
1409
+ registerActiveQuery(activeEntry);
1410
+
1411
+ var handle;
1412
+ try {
1413
+ handleOpts.onFinished = function() {
1414
+ removeActiveQuery(activeEntry);
1415
+ decrementRefCount();
1416
+ };
1417
+ handle = createCodexQueryHandle(_appServer, handleOpts);
1418
+ } catch (e) {
1419
+ removeActiveQuery(activeEntry);
1420
+ decrementRefCount();
1421
+ throw e;
1422
+ }
1423
+
1424
+ activeEntry.handle = handle;
1425
+ activeEntry.abort = function() {
1426
+ try {
1427
+ if (handle && typeof handle.abort === "function") {
1428
+ handle.abort();
1429
+ } else {
1430
+ ac.abort();
1431
+ }
1432
+ } catch (e) {}
1433
+ };
1434
+
1180
1435
  return handle;
1181
1436
  },
1182
1437
 
@@ -1243,10 +1498,19 @@ function createCodexAdapter(opts) {
1243
1498
 
1244
1499
  // Shutdown the app-server process
1245
1500
  shutdown: function() {
1246
- if (_appServer) {
1247
- _appServer.stop();
1248
- _appServer = null;
1249
- }
1501
+ return beginShutdown(true);
1502
+ },
1503
+
1504
+ shutdownIfIdle: function(idleMs) {
1505
+ if (_shuttingDown || _shutdownPromise) return Promise.resolve(false);
1506
+ if (_initPromise) return Promise.resolve(false);
1507
+ if (!_appServer) return Promise.resolve(false);
1508
+ if (_refCount > 0) return Promise.resolve(false);
1509
+ if (Date.now() - _lastActiveAt < (idleMs || 0)) return Promise.resolve(false);
1510
+ return beginShutdown(false).then(function() {
1511
+ console.log("[yoke/codex] Reclaimed idle adapter for project " + (_slug || _cwd));
1512
+ return true;
1513
+ });
1250
1514
  },
1251
1515
  };
1252
1516
 
package/lib/yoke/index.js CHANGED
@@ -19,6 +19,7 @@ function wrapCreateQuery(adapter, defaultCwd) {
19
19
  var originalCreateQuery = adapter.createQuery.bind(adapter);
20
20
 
21
21
  adapter.createQuery = function(queryOpts) {
22
+ queryOpts = queryOpts || {};
22
23
  var projectDir = (queryOpts && queryOpts.cwd) || defaultCwd;
23
24
  var merged = instructions.scanAndMerge(projectDir, adapter.vendor);
24
25
 
@@ -53,7 +54,7 @@ function createAdapter(opts) {
53
54
  throw new Error("[YOKE] Unknown adapter vendor: " + vendor);
54
55
  }
55
56
  iface.validateAdapter(adapter);
56
- wrapCreateQuery(adapter, opts.cwd);
57
+ wrapCreateQuery(adapter, opts && opts.cwd);
57
58
  return adapter;
58
59
  }
59
60
 
@@ -187,8 +188,19 @@ function checkAuth() {
187
188
 
188
189
  /**
189
190
  * Check which vendor binaries are installed (regardless of auth status).
191
+ *
192
+ * Result is cached at module scope because the check runs two execFileSync
193
+ * calls per invocation and is triggered once per project context on daemon
194
+ * startup. With N projects this used to cost ~2N synchronous subprocesses;
195
+ * caching collapses it to two total. The cache is invalidated alongside
196
+ * the auth cache (via invalidateAuthCache) since "just installed" is the
197
+ * same situation as "just logged in" from the daemon's perspective.
190
198
  */
199
+ var _installedCache = null;
200
+
191
201
  function checkInstalled() {
202
+ if (_installedCache) return _installedCache;
203
+
192
204
  var fs = require("fs");
193
205
  var execFileSync = require("child_process").execFileSync;
194
206
  var result = { claude: false, codex: false };
@@ -204,6 +216,7 @@ function checkInstalled() {
204
216
  codexBin = findCodexPath();
205
217
  if (codexBin && fs.existsSync(codexBin)) {
206
218
  result.codex = true;
219
+ _installedCache = result;
207
220
  return result;
208
221
  }
209
222
  } catch (e) {}
@@ -213,27 +226,25 @@ function checkInstalled() {
213
226
  : execFileSync("which", ["codex"], { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
214
227
  if (whichOut.trim()) result.codex = true;
215
228
  } catch (e) {}
229
+ _installedCache = result;
216
230
  return result;
217
231
  }
218
232
 
219
233
  function invalidateAuthCache() {
220
234
  _authCache = null;
235
+ _installedCache = null;
221
236
  }
222
237
 
223
238
  /**
224
239
  * Create adapters for all authenticated vendors.
225
- * Adapters are singletons shared across all projects (they are stateless factories).
226
- * The cwd is passed per-query, not per-adapter.
240
+ * Claude may be shared across projects, but Codex is instantiated per project
241
+ * so its app-server and bridge stay scoped to a single project slug.
227
242
  * Returns { adapters: { vendor: Adapter }, auth: { vendor: boolean } }
228
243
  */
229
- var _sharedAdapters = null;
230
- var _sharedAuth = null;
244
+ var _sharedClaudeAdapter = null;
231
245
 
232
246
  function createAdapters(opts) {
233
- if (_sharedAdapters) {
234
- return { adapters: _sharedAdapters, auth: _sharedAuth };
235
- }
236
-
247
+ opts = opts || {};
237
248
  // Gate adapter creation on binary installation, not OAuth auth status.
238
249
  // Claude Code supports multiple auth modes (OAuth, Bedrock, Vertex, API key)
239
250
  // that `claude auth status` does not always detect. Runtime auth failures are
@@ -241,22 +252,30 @@ function createAdapters(opts) {
241
252
  var installed = checkInstalled();
242
253
  var auth = { claude: false, codex: false };
243
254
  var adapters = {};
244
- var vendors = Object.keys(installed);
245
255
 
246
- for (var i = 0; i < vendors.length; i++) {
247
- var vendor = vendors[i];
248
- if (!installed[vendor]) continue;
256
+ if (installed.claude) {
257
+ try {
258
+ if (!_sharedClaudeAdapter) {
259
+ _sharedClaudeAdapter = createAdapter({ vendor: "claude", cwd: opts.cwd });
260
+ }
261
+ adapters.claude = _sharedClaudeAdapter;
262
+ auth.claude = true;
263
+ console.log("[yoke] Adapter created: claude");
264
+ } catch (e) {
265
+ console.error("[yoke] Failed to create adapter for claude:", e.message);
266
+ }
267
+ }
268
+
269
+ if (installed.codex) {
249
270
  try {
250
- adapters[vendor] = createAdapter({ vendor: vendor, cwd: opts.cwd });
251
- auth[vendor] = true;
252
- console.log("[yoke] Adapter created: " + vendor);
271
+ adapters.codex = createAdapter({ vendor: "codex", cwd: opts.cwd, slug: opts.slug });
272
+ auth.codex = true;
273
+ console.log("[yoke] Adapter created: codex");
253
274
  } catch (e) {
254
- console.error("[yoke] Failed to create adapter for " + vendor + ":", e.message);
275
+ console.error("[yoke] Failed to create adapter for codex:", e.message);
255
276
  }
256
277
  }
257
278
 
258
- _sharedAdapters = adapters;
259
- _sharedAuth = auth;
260
279
  return { adapters: adapters, auth: auth };
261
280
  }
262
281
 
@@ -266,26 +285,19 @@ function createAdapters(opts) {
266
285
  * Returns the adapter or null.
267
286
  */
268
287
  async function lazyCreateAdapter(adapters, vendor, opts) {
269
- if (_sharedAdapters && _sharedAdapters[vendor]) {
270
- adapters[vendor] = _sharedAdapters[vendor];
271
- return adapters[vendor];
272
- }
288
+ opts = opts || {};
273
289
 
274
290
  // Force re-check since user may have logged in after server start
275
291
  invalidateAuthCache();
276
- _sharedAdapters = null;
277
- _sharedAuth = null;
278
292
  var installed = checkInstalled();
279
293
  if (!installed[vendor]) return null;
280
294
 
281
295
  try {
282
- var ad = createAdapter({ vendor: vendor, cwd: opts.cwd });
296
+ var ad = createAdapter({ vendor: vendor, cwd: opts.cwd, slug: opts.slug });
283
297
  if (typeof ad.init === "function") {
284
298
  await ad.init(opts || {});
285
299
  }
286
300
  console.log("[yoke] Lazy adapter created: " + vendor);
287
- if (_sharedAdapters) _sharedAdapters[vendor] = ad;
288
- if (_sharedAuth) _sharedAuth[vendor] = true;
289
301
  adapters[vendor] = ad;
290
302
  return ad;
291
303
  } catch (e) {
@@ -3,7 +3,8 @@
3
3
  // --------------------------------------------------
4
4
  // Codex spawns this as a native MCP server via config.mcp_servers["clay-tools"].
5
5
  // It implements the MCP protocol on stdio (JSON-RPC) and proxies tool
6
- // list/call requests to Clay's HTTP endpoint (/api/mcp-bridge).
6
+ // list/call requests to Clay's project-scoped HTTP endpoint
7
+ // (/p/{slug}/api/mcp-bridge) when a slug is provided.
7
8
  //
8
9
  // Usage: node mcp-bridge-server.js --port 2633 --slug my-project
9
10
  //
@@ -37,8 +38,10 @@ for (var i = 0; i < args.length; i++) {
37
38
  }
38
39
 
39
40
  var CLAY_PROTOCOL = clayTls ? "https" : "http";
40
- // Use global endpoint (not project-scoped) so bridge works regardless of which project was active at init
41
41
  var CLAY_BASE_URL = CLAY_PROTOCOL + "://127.0.0.1:" + clayPort;
42
+ var CLAY_MCP_PATH = claySlug
43
+ ? ("/p/" + claySlug + "/api/mcp-bridge")
44
+ : "/api/mcp-bridge";
42
45
 
43
46
  // --- Auth ---
44
47
  var clayAuthToken = process.env.CLAY_AUTH_TOKEN || "";
@@ -91,8 +94,13 @@ function postJson(urlPath, body) {
91
94
  reject(err);
92
95
  });
93
96
 
94
- // 30s timeout for tool calls
95
- req.setTimeout(30000, function () {
97
+ // 10 min safety ceiling. ask_user_questions is stateless (returns
98
+ // immediately; the user's answer arrives on the next turn as a new
99
+ // user message), so no tool call should legitimately block long.
100
+ // The generous ceiling is just a belt-and-suspenders against slow
101
+ // browser automation or external MCP servers, not the primary
102
+ // mechanism for human-in-the-loop tools.
103
+ req.setTimeout(600000, function () {
96
104
  req.destroy(new Error("Request timed out"));
97
105
  });
98
106
 
@@ -103,7 +111,7 @@ function postJson(urlPath, body) {
103
111
 
104
112
  // --- Fetch tools from Clay ---
105
113
  function fetchTools() {
106
- return postJson("/api/mcp-bridge", { action: "list_tools" }).then(function (resp) {
114
+ return postJson(CLAY_MCP_PATH, { action: "list_tools" }).then(function (resp) {
107
115
  if (resp.error) {
108
116
  log("Failed to fetch tools: " + resp.error);
109
117
  return [];
@@ -124,7 +132,7 @@ function fetchTools() {
124
132
 
125
133
  // --- Call a tool via Clay ---
126
134
  function callTool(serverName, toolName, args) {
127
- return postJson("/api/mcp-bridge", {
135
+ return postJson(CLAY_MCP_PATH, {
128
136
  action: "call_tool",
129
137
  server: serverName,
130
138
  tool: toolName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clay-server",
3
- "version": "2.34.0-beta.3",
3
+ "version": "2.34.0-beta.4",
4
4
  "description": "Self-hosted Claude Code in your browser. Multi-session, multi-user, push notifications.",
5
5
  "bin": {
6
6
  "clay-server": "./bin/cli.js",