clay-server 4.7.0-beta.1 → 4.7.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/lib/project-connection.js +0 -14
  2. package/lib/project-sessions.js +0 -18
  3. package/lib/public/app.js +16 -14
  4. package/lib/public/css/input.css +27 -0
  5. package/lib/public/css/pane.css +0 -1
  6. package/lib/public/css/projects-hub.css +75 -0
  7. package/lib/public/css/tui-attention.css +0 -407
  8. package/lib/public/index.html +6 -14
  9. package/lib/public/modules/app-connection.js +23 -2
  10. package/lib/public/modules/app-favicon.js +1 -0
  11. package/lib/public/modules/app-home-hub.js +8 -3
  12. package/lib/public/modules/app-messages.js +2 -16
  13. package/lib/public/modules/app-projects.js +16 -11
  14. package/lib/public/modules/app-rendering.js +16 -10
  15. package/lib/public/modules/generation-stop.js +24 -0
  16. package/lib/public/modules/home-surface-boot.js +10 -3
  17. package/lib/public/modules/home-surface.js +13 -1
  18. package/lib/public/modules/projects-hub-view.js +62 -0
  19. package/lib/public/modules/projects-hub.js +105 -0
  20. package/lib/public/style.css +2 -0
  21. package/lib/sdk-bridge.js +17 -3
  22. package/lib/server.js +1 -1
  23. package/lib/sessions.js +2 -0
  24. package/lib/users-home-surface-preferences.js +4 -2
  25. package/lib/users-preferences.js +0 -36
  26. package/lib/users.js +0 -4
  27. package/lib/ws-schema.js +0 -3
  28. package/lib/yoke/acp-process-manager.js +25 -15
  29. package/lib/yoke/acp-query-handle.js +52 -40
  30. package/lib/yoke/adapters/antigravity.js +25 -1
  31. package/lib/yoke/adapters/claude.js +25 -7
  32. package/lib/yoke/adapters/codex.js +55 -24
  33. package/lib/yoke/adapters/kiro.js +30 -19
  34. package/lib/yoke/codex-turn-events.js +32 -0
  35. package/lib/yoke/codex-turn-stop.js +59 -0
  36. package/lib/yoke/query-abort.js +40 -0
  37. package/lib/yoke/user-input-guidance.js +11 -0
  38. package/lib/yoke/user-input.js +1 -1
  39. package/package.json +1 -1
  40. package/lib/public/modules/whats-new-article.js +0 -70
  41. package/lib/public/modules/whats-new.js +0 -264
  42. package/lib/whats-new-content.js +0 -84
  43. package/lib/whats-new.js +0 -57
@@ -1,3 +1,4 @@
1
+ var bindAbort = require("../query-abort").bindAbort;
1
2
  var childProcess = require("child_process");
2
3
  var readline = require("readline");
3
4
  var skillDiscovery = require("../skill-discovery");
@@ -75,6 +76,9 @@ function toolName(name) {
75
76
 
76
77
  function createAntigravityQueryHandle(binaryPath, queryOpts, onFinished) {
77
78
  var processHandle = null;
79
+ var removeAbort = function () {};
80
+ var killTimer = null;
81
+ var processExited = false;
78
82
  var outputReader = null;
79
83
  var events = [];
80
84
  var eventWaiter = null;
@@ -115,6 +119,7 @@ function createAntigravityQueryHandle(binaryPath, queryOpts, onFinished) {
115
119
  function endEvents() {
116
120
  if (ended) return;
117
121
  ended = true;
122
+ removeAbort();
118
123
  if (eventWaiter) {
119
124
  var resolve = eventWaiter;
120
125
  eventWaiter = null;
@@ -252,6 +257,8 @@ function createAntigravityQueryHandle(binaryPath, queryOpts, onFinished) {
252
257
  endEvents();
253
258
  });
254
259
  processHandle.on("exit", function(code, signal) {
260
+ processExited = true;
261
+ if (killTimer) clearTimeout(killTimer);
255
262
  if (!ended && activeTurn) {
256
263
  var message = stderr.trim() || "Antigravity CLI exited before completing the turn";
257
264
  pushEvent(isAuthError(message)
@@ -309,8 +316,24 @@ function createAntigravityQueryHandle(binaryPath, queryOpts, onFinished) {
309
316
  },
310
317
  abort: function() {
311
318
  if (ended) return;
319
+ inputEnded = true;
320
+ messages = [];
312
321
  pushEvent({ yokeType: "interrupted" });
313
- if (processHandle) processHandle.kill("SIGINT");
322
+ if (processHandle && !processExited) {
323
+ try { processHandle.kill("SIGINT"); } catch (error) {
324
+ pushEvent({ yokeType: "error", text: "Could not interrupt Antigravity: " + error.message });
325
+ }
326
+ if (!processExited) {
327
+ killTimer = setTimeout(function () {
328
+ if (!processExited) {
329
+ try { processHandle.kill("SIGKILL"); } catch (error) {
330
+ console.error("[yoke/antigravity] Could not terminate stopped query:", error.message);
331
+ }
332
+ }
333
+ }, 5000);
334
+ killTimer.unref();
335
+ }
336
+ }
314
337
  endEvents();
315
338
  },
316
339
  close: function() {
@@ -319,6 +342,7 @@ function createAntigravityQueryHandle(binaryPath, queryOpts, onFinished) {
319
342
  endEvents();
320
343
  },
321
344
  };
345
+ removeAbort = bindAbort(queryOpts.abortController, function () { handle.abort(); });
322
346
  return handle;
323
347
  }
324
348
 
@@ -4,6 +4,7 @@
4
4
  // This is the ONLY file (besides claude-worker.js) that imports the SDK.
5
5
  // Also manages worker processes for OS-level user isolation.
6
6
 
7
+ var bindQueryAbort = require("../query-abort").bindAbort;
7
8
  var path = require("path");
8
9
  var fs = require("fs");
9
10
  var os = require("os");
@@ -576,6 +577,7 @@ function normalizeBackgroundTasks(tasks) {
576
577
  function createQueryHandle(rawQuery, messageQueue, abortController) {
577
578
  var correlation = claudeCorrelation.createCorrelation();
578
579
  var closed = false;
580
+ var removeAbort = function () {};
579
581
  var handle = {
580
582
  // Opaque adapter state (null for in-process queries)
581
583
  _adapterState: null,
@@ -586,11 +588,12 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
586
588
  return {
587
589
  next: function() {
588
590
  return rawIter.next().then(function(result) {
589
- if (result.done) closed = true;
591
+ if (result.done) { closed = true; removeAbort(); }
590
592
  if (result.done) return result;
591
593
  return { value: correlation.result(result.value, flattenEvent(result.value)), done: false };
592
594
  }, function(err) {
593
595
  closed = true;
596
+ removeAbort();
594
597
  throw err;
595
598
  });
596
599
  },
@@ -684,6 +687,7 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
684
687
 
685
688
  abort: function() {
686
689
  closed = true;
690
+ try { messageQueue.end(); } catch (e) {}
687
691
  if (abortController) {
688
692
  try { abortController.abort(); } catch (e) {}
689
693
  }
@@ -691,6 +695,7 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
691
695
 
692
696
  close: function() {
693
697
  closed = true;
698
+ removeAbort();
694
699
  try { messageQueue.end(); } catch (e) {}
695
700
  if (rawQuery && typeof rawQuery.close === "function") {
696
701
  try { rawQuery.close(); } catch (e) {}
@@ -712,6 +717,10 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
712
717
  },
713
718
  };
714
719
 
720
+ removeAbort = bindQueryAbort(abortController, function () {
721
+ closed = true;
722
+ try { messageQueue.end(); } catch (e) {}
723
+ });
715
724
  return handle;
716
725
  }
717
726
 
@@ -1043,6 +1052,7 @@ function serializeWorkerValue(value, seen) {
1043
1052
  // query identically to an in-process query.
1044
1053
 
1045
1054
  function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool, onUserDialog, onUserInputRequest, onModelSwitch, preToolUsePolicy) {
1055
+ var interactionAbort = new AbortController();
1046
1056
  var contextRequests = claudeContextUsage.createRequests(worker);
1047
1057
  var correlation = claudeCorrelation.createCorrelation();
1048
1058
  // Async iterable state
@@ -1085,6 +1095,7 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool,
1085
1095
  }
1086
1096
 
1087
1097
  function endIter() {
1098
+ interactionAbort.abort();
1088
1099
  contextRequests.close();
1089
1100
  if (iterEnded) return;
1090
1101
  iterEnded = true;
@@ -1096,6 +1107,7 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool,
1096
1107
  }
1097
1108
 
1098
1109
  function errorIter(err) {
1110
+ interactionAbort.abort();
1099
1111
  contextRequests.close();
1100
1112
  if (iterEnded) return;
1101
1113
  iterEnded = true;
@@ -1122,8 +1134,9 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool,
1122
1134
  decisionReason: msg.decisionReason,
1123
1135
  defaultToNo: msg.defaultToNo === true,
1124
1136
  suppressAlwaysAllowRule: msg.suppressAlwaysAllowRule === true,
1125
- signal: { addEventListener: function() {} },
1137
+ signal: interactionAbort.signal,
1126
1138
  }).then(function(result) {
1139
+ if (interactionAbort.signal.aborted) result = { behavior: "deny", message: "Query cancelled" };
1127
1140
  worker.send({ type: "permission_response", requestId: msg.requestId, result: result });
1128
1141
  }).catch(function(e) {
1129
1142
  console.error("[yoke/claude] permission_response send failed:", e.message || e);
@@ -1149,8 +1162,9 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool,
1149
1162
  if (onUserInputRequest) {
1150
1163
  claudeUserInput.ask(onUserInputRequest, msg.input, {
1151
1164
  toolUseID: msg.toolUseId,
1152
- signal: { addEventListener: function() {} },
1165
+ signal: interactionAbort.signal,
1153
1166
  }).then(function(result) {
1167
+ if (interactionAbort.signal.aborted) return;
1154
1168
  worker.send({ type: "ask_user_response", toolUseId: msg.toolUseId, result: result });
1155
1169
  }).catch(function(e) {
1156
1170
  console.error("[yoke/claude] ask_user_response send failed:", e.message || e);
@@ -1171,12 +1185,13 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool,
1171
1185
  var workerElicitation = onUserInputRequest
1172
1186
  ? claudeUserInput.elicitation(onUserInputRequest, workerElicitationRequest, {
1173
1187
  requestId: msg.requestId,
1174
- signal: { addEventListener: function() {} },
1188
+ signal: interactionAbort.signal,
1175
1189
  })
1176
1190
  : onElicitation(workerElicitationRequest, {
1177
- signal: { addEventListener: function() {} },
1191
+ signal: interactionAbort.signal,
1178
1192
  });
1179
1193
  workerElicitation.then(function(result) {
1194
+ if (interactionAbort.signal.aborted) return;
1180
1195
  worker.send({ type: "elicitation_response", requestId: msg.requestId, result: result });
1181
1196
  }).catch(function(e) {
1182
1197
  console.error("[yoke/claude] elicitation_response send failed:", e.message || e);
@@ -1191,8 +1206,9 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool,
1191
1206
  payload: msg.payload || {},
1192
1207
  toolUseID: msg.toolUseId || undefined,
1193
1208
  }, {
1194
- signal: { addEventListener: function() {} },
1209
+ signal: interactionAbort.signal,
1195
1210
  }).then(function(result) {
1211
+ if (interactionAbort.signal.aborted) return;
1196
1212
  worker.send({ type: "user_dialog_response", requestId: msg.requestId, result: result });
1197
1213
  }).catch(function(e) {
1198
1214
  console.error("[yoke/claude] user_dialog_response send failed:", e.message || e);
@@ -1327,7 +1343,7 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool,
1327
1343
  getSubmittedMessageCount: correlation.submitted,
1328
1344
 
1329
1345
  pushMessage: function(text, images) {
1330
- if (iterEnded || (worker.process && (worker.process.killed || worker.process.exitCode != null))) return false;
1346
+ if (iterEnded || worker._abortSent || (worker.process && (worker.process.killed || worker.process.exitCode != null))) return false;
1331
1347
  var content = [];
1332
1348
  if (images && images.length > 0) {
1333
1349
  for (var i = 0; i < images.length; i++) {
@@ -1417,8 +1433,10 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool,
1417
1433
  },
1418
1434
 
1419
1435
  abort: function() {
1436
+ if (iterEnded || worker._abortSent) return;
1420
1437
  console.log("[yoke/claude] ABORT sent to worker pid=" + (worker.process ? worker.process.pid : "?"));
1421
1438
  worker._abortSent = true;
1439
+ interactionAbort.abort();
1422
1440
  try { worker.send({ type: "abort" }); } catch (e) {}
1423
1441
  // If the worker doesn't finish within 5s (e.g. subagent stuck), force-kill it.
1424
1442
  // The worker exit handler will dispatch a fallback query_error and send done.
@@ -3,6 +3,8 @@
3
3
  // Implements the YOKE interface using codex app-server protocol.
4
4
  // Bidirectional JSON-RPC over stdin/stdout enables interactive approval flows.
5
5
 
6
+ var createTurnEvents = require("../codex-turn-events").createTurnEvents;
7
+ var bindQueryAbort = require("../query-abort").bindAbort;
6
8
  var path = require("path");
7
9
  var fs = require("fs");
8
10
  var { CodexAppServer } = require("../codex-app-server");
@@ -11,6 +13,7 @@ var skillDiscovery = require("../skill-discovery");
11
13
  var { resolveOsUserInfo } = require("../../os-users");
12
14
  var backgroundTasks = require("../codex-background-tasks");
13
15
  var codexUserInput = require("../codex-user-input");
16
+ var createTurnStop = require("../codex-turn-stop").createTurnStop;
14
17
 
15
18
  // --- Reasoning defaults ---
16
19
  // Reasoning summaries are the only readable thinking channel Codex offers:
@@ -812,6 +815,7 @@ function createEventState(model) {
812
815
 
813
816
  function createCodexQueryHandle(appServer, queryOpts) {
814
817
  var abortController = queryOpts.abortController;
818
+ var removeAbort = function () {};
815
819
  var promptParts = [queryOpts.systemPrompt, queryOpts.appendSystemPrompt].filter(function (part) { return !!part; });
816
820
  var systemPrompt = promptParts.join("\n\n");
817
821
  var canUseTool = queryOpts.canUseTool || null;
@@ -826,6 +830,11 @@ function createCodexQueryHandle(appServer, queryOpts) {
826
830
  }
827
831
 
828
832
  var state = createEventState(queryOpts.model);
833
+ var turnEvents = createTurnEvents(handleServerEvent);
834
+ var turnStop = createTurnStop(appServer, function (error) {
835
+ console.error("[yoke/codex] turn interrupt failed:", error.message || error);
836
+ pushEvent({ yokeType: "error", text: "Codex cancellation could not be confirmed. The remote turn may still be running." });
837
+ });
829
838
 
830
839
  // Internal event buffer for async iterator
831
840
  var eventBuffer = [];
@@ -864,6 +873,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
864
873
  }
865
874
 
866
875
  function endIterator() {
876
+ removeAbort();
867
877
  iteratorDone = true;
868
878
  if (eventWaiting) {
869
879
  var resolve = eventWaiting;
@@ -912,6 +922,13 @@ function createCodexQueryHandle(appServer, queryOpts) {
912
922
  // Ignore events from other threads (app-server is shared across sessions)
913
923
  if (params.threadId && state.threadId && params.threadId !== state.threadId) return;
914
924
 
925
+ if (!turnEvents.accept(msg)) return;
926
+
927
+ // Capture cancellation identity even if Stop arrived before turn/start replied.
928
+ var eventTurnId = params.turnId || params.turn_id || (params.turn && params.turn.id);
929
+ if (method === "turn/started") turnStop.started(eventTurnId);
930
+ if (method === "turn/completed" || method === "turn/failed") turnStop.completed(eventTurnId);
931
+
915
932
  // After abort, only let turn-ending events through
916
933
  if (isCancelled() && method !== "turn/completed" && method !== "turn/failed" && method !== "serverRequest/resolved" && method !== "thread/status/changed") return;
917
934
 
@@ -1089,6 +1106,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1089
1106
 
1090
1107
  // Resolve turn promise when turn ends
1091
1108
  if (method === "turn/completed" || method === "turn/failed") {
1109
+ turnEvents.finish();
1092
1110
  if (turnResolve) {
1093
1111
  var resolve = turnResolve;
1094
1112
  turnResolve = null;
@@ -1204,6 +1222,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1204
1222
  while (!isCancelled()) {
1205
1223
  // Reset per-turn state
1206
1224
  state.turnStarted = false;
1225
+ state.currentTurnId = null;
1207
1226
  state.textBlocks = {};
1208
1227
  state.textLengths = {};
1209
1228
  state.thinkingBlocks = {};
@@ -1243,11 +1262,22 @@ function createCodexQueryHandle(appServer, queryOpts) {
1243
1262
  input = input.concat(skillItemsToInject);
1244
1263
  }
1245
1264
 
1246
- await appServer.send("turn/start", {
1247
- threadId: state.threadId,
1248
- input: input,
1249
- model: state.model,
1250
- }, 60000);
1265
+ turnStop.begin(state.threadId);
1266
+ turnEvents.begin();
1267
+ try {
1268
+ var turnResult = await appServer.send("turn/start", {
1269
+ threadId: state.threadId,
1270
+ input: input,
1271
+ model: state.model,
1272
+ }, 60000);
1273
+ var startedTurnId = turnResult && turnResult.turn && turnResult.turn.id;
1274
+ turnStop.startSettled(startedTurnId);
1275
+ turnEvents.ready(startedTurnId);
1276
+ } catch (startError) {
1277
+ turnEvents.finish();
1278
+ turnStop.startSettled(null);
1279
+ throw startError;
1280
+ }
1251
1281
 
1252
1282
  // Wait for turn to complete
1253
1283
  await turnPromise;
@@ -1348,19 +1378,23 @@ function createCodexQueryHandle(appServer, queryOpts) {
1348
1378
  abort: function() {
1349
1379
  console.log("[yoke/codex] handle.abort() called, threadId=" + state.threadId + " already aborted=" + state.aborted);
1350
1380
  state.aborted = true;
1351
- // Send turn/interrupt to stop the server-side turn
1352
- if (state.threadId && appServer.started) {
1353
- appServer.send("turn/interrupt", { threadId: state.threadId }, 5000).catch(function() {});
1354
- }
1355
- // End iterator immediately. sdk-bridge's post-loop code checks
1356
- // session.taskStopRequested and sends the interrupted message + done.
1357
- // This matches Claude's abort pattern.
1358
- if (turnResolve) {
1359
- var resolve = turnResolve;
1360
- turnResolve = null;
1361
- resolve();
1362
- }
1363
- endIterator();
1381
+ messageQueueEnded = true;
1382
+ messageQueue = [];
1383
+ if (messageWaiting) {
1384
+ var releaseMessage = messageWaiting;
1385
+ messageWaiting = null;
1386
+ releaseMessage(null);
1387
+ }
1388
+ // Keep the iterator alive until the exact interrupt settles so failures
1389
+ // reach the transcript instead of being silently reported as a stop.
1390
+ return turnStop.abort().then(function () {
1391
+ if (turnResolve) {
1392
+ var resolve = turnResolve;
1393
+ turnResolve = null;
1394
+ resolve();
1395
+ }
1396
+ endIterator();
1397
+ });
1364
1398
  },
1365
1399
 
1366
1400
  close: function() {
@@ -1383,12 +1417,9 @@ function createCodexQueryHandle(appServer, queryOpts) {
1383
1417
  },
1384
1418
  };
1385
1419
 
1386
- // Listen for external abort (sdk-bridge's stopTask calls session.abortController.abort())
1387
- if (abortController && abortController.signal) {
1388
- abortController.signal.addEventListener("abort", function() {
1389
- if (!state.aborted) handle.abort();
1390
- }, { once: true });
1391
- }
1420
+ removeAbort = bindQueryAbort(abortController, function () {
1421
+ if (!state.aborted) handle.abort();
1422
+ });
1392
1423
 
1393
1424
  return handle;
1394
1425
  }
@@ -12,6 +12,7 @@
12
12
  // session/request_permission requests for tool approvals.
13
13
  // session/cancel (notif) -> interrupt the active turn
14
14
 
15
+ var queryAbort = require("../query-abort");
15
16
  var { execFile } = require("child_process");
16
17
  var { KiroAcpServer, findKiroPath } = require("../kiro-acp-server");
17
18
  var INITIALIZE_TIMEOUT_MS = require("../interface").INITIALIZE_TIMEOUT_MS;
@@ -398,6 +399,12 @@ function createEventState(opts) {
398
399
 
399
400
  function createKiroQueryHandle(acp, queryOpts) {
400
401
  var abortController = queryOpts.abortController;
402
+ var cancellation = queryAbort.createAbortScope();
403
+ var removeAbort = function () {};
404
+ function send(method, params, timeout) {
405
+ cancellation.check();
406
+ return cancellation.wait(acp.send(method, params, timeout, cancellation.signal));
407
+ }
401
408
  var promptParts = [queryOpts.systemPrompt, queryOpts.appendSystemPrompt].filter(function (part) { return !!part; });
402
409
  var systemPrompt = promptParts.join("\n\n");
403
410
  var canUseTool = queryOpts.canUseTool || null;
@@ -436,6 +443,7 @@ function createKiroQueryHandle(acp, queryOpts) {
436
443
 
437
444
  function endIterator() {
438
445
  iteratorDone = true;
446
+ removeAbort();
439
447
  if (eventWaiting) {
440
448
  var resolve = eventWaiting;
441
449
  eventWaiting = null;
@@ -506,9 +514,10 @@ function createKiroQueryHandle(acp, queryOpts) {
506
514
  var meta = (tc.toolCallId && state.toolMeta[tc.toolCallId]) || {};
507
515
  var toolName = toolNameForKind(tc.kind || meta.kind, tc.title || meta.title);
508
516
  var toolInput = tc.rawInput || meta.rawInput || { title: tc.title || meta.title };
509
- canUseTool(toolName, toolInput, {}).then(function(decision) {
510
- acp.respond(msg.id, { outcome: { outcome: "selected", optionId: isApproved(decision) ? allowId : rejectId } });
517
+ cancellation.wait(Promise.resolve().then(function () { cancellation.check(); return canUseTool(toolName, toolInput, { signal: cancellation.signal }); })).then(function(decision) {
518
+ acp.respond(msg.id, isCancelled() ? { outcome: { outcome: "cancelled" } } : { outcome: { outcome: "selected", optionId: isApproved(decision) ? allowId : rejectId } });
511
519
  }).catch(function(err) {
520
+ if (isCancelled()) { acp.respond(msg.id, { outcome: { outcome: "cancelled" } }); return; }
512
521
  console.error("[yoke/kiro] canUseTool error:", err.message);
513
522
  acp.respond(msg.id, { outcome: { outcome: "selected", optionId: rejectId } });
514
523
  });
@@ -592,13 +601,13 @@ function createKiroQueryHandle(acp, queryOpts) {
592
601
  function setSessionModel(model) {
593
602
  if (!state.sessionId || !acp.started) return Promise.resolve();
594
603
  if (state.engine === "v3") {
595
- return acp.send("session/set_config_option", {
604
+ return send("session/set_config_option", {
596
605
  sessionId: state.sessionId,
597
606
  configId: "model",
598
607
  value: model,
599
608
  }, 15000);
600
609
  }
601
- return acp.send("session/set_model", { sessionId: state.sessionId, modelId: model }, 15000);
610
+ return send("session/set_model", { sessionId: state.sessionId, modelId: model }, 15000);
602
611
  }
603
612
 
604
613
  // --- Main query loop ---
@@ -638,12 +647,13 @@ function createKiroQueryHandle(acp, queryOpts) {
638
647
  handlerEntry.sessionId = state.sessionId;
639
648
  state.loadingSession = true;
640
649
  try {
641
- await acp.send("session/load", {
650
+ await send("session/load", {
642
651
  sessionId: state.sessionId,
643
652
  cwd: queryOpts.cwd,
644
653
  mcpServers: queryOpts.mcpServers || [],
645
654
  }, 60000);
646
655
  } catch (e) {
656
+ if (isCancelled()) throw e;
647
657
  // If load fails (unknown session), fall back to a fresh session.
648
658
  console.warn("[yoke/kiro] session/load failed, starting fresh:", e.message);
649
659
  state.sessionId = null;
@@ -653,7 +663,7 @@ function createKiroQueryHandle(acp, queryOpts) {
653
663
  }
654
664
  }
655
665
  if (!state.sessionId) {
656
- var newResult = await acp.send("session/new", {
666
+ var newResult = await send("session/new", {
657
667
  cwd: queryOpts.cwd,
658
668
  mcpServers: queryOpts.mcpServers || [],
659
669
  }, 60000);
@@ -664,7 +674,7 @@ function createKiroQueryHandle(acp, queryOpts) {
664
674
  // Kiro v3 defaults to autopilot, which bypasses permission requests.
665
675
  // Supervised mode is mandatory so every tool call reaches canUseTool.
666
676
  if (state.engine === "v3") {
667
- await acp.send("session/set_config_option", {
677
+ await send("session/set_config_option", {
668
678
  sessionId: state.sessionId,
669
679
  configId: "autopilot",
670
680
  value: "off",
@@ -676,7 +686,7 @@ function createKiroQueryHandle(acp, queryOpts) {
676
686
  await setSessionModel(queryOpts.model).catch(function() {});
677
687
  }
678
688
  if (queryOpts.mode) {
679
- await acp.send("session/set_mode", { sessionId: state.sessionId, modeId: queryOpts.mode }, 15000).catch(function() {});
689
+ await send("session/set_mode", { sessionId: state.sessionId, modeId: queryOpts.mode }, 15000).catch(function() {});
680
690
  }
681
691
 
682
692
  while (!isCancelled()) {
@@ -690,7 +700,7 @@ function createKiroQueryHandle(acp, queryOpts) {
690
700
  // Emit turn_start so the UI records a user turn boundary.
691
701
  pushEvent({ yokeType: "turn_start", uuid: generateUuid(), messageType: "user" });
692
702
 
693
- var promptResult = await acp.send("session/prompt", {
703
+ var promptResult = await send("session/prompt", {
694
704
  sessionId: state.sessionId,
695
705
  prompt: input,
696
706
  }, 30 * 60 * 1000);
@@ -779,11 +789,17 @@ function createKiroQueryHandle(acp, queryOpts) {
779
789
 
780
790
  abort: function() {
781
791
  console.log("[yoke/kiro] handle.abort() sessionId=" + state.sessionId + " already=" + state.aborted);
792
+ if (state.aborted || iteratorDone) return;
782
793
  state.aborted = true;
783
- if (state.sessionId && acp.started) {
784
- // ACP cancellation is a notification; the in-flight session/prompt will
785
- // resolve with stopReason "cancelled".
786
- acp.notify("session/cancel", { sessionId: state.sessionId });
794
+ cancellation.stop();
795
+ handle.endInput();
796
+ messageQueue = [];
797
+ try {
798
+ if (state.sessionId && (!acp.started || acp.notify("session/cancel", { sessionId: state.sessionId }) === false)) {
799
+ throw new Error("ACP transport is disconnected");
800
+ }
801
+ } catch (error) {
802
+ pushEvent({ yokeType: "error", text: "Kiro cancellation could not be delivered: " + error.message });
787
803
  }
788
804
  endIterator();
789
805
  },
@@ -808,12 +824,7 @@ function createKiroQueryHandle(acp, queryOpts) {
808
824
  },
809
825
  };
810
826
 
811
- if (abortController && abortController.signal) {
812
- abortController.signal.addEventListener("abort", function() {
813
- if (!state.aborted) handle.abort();
814
- }, { once: true });
815
- }
816
-
827
+ removeAbort = queryAbort.bindAbort(abortController, function () { handle.abort(); });
817
828
  return handle;
818
829
  }
819
830
 
@@ -0,0 +1,32 @@
1
+ // A resumed thread can still deliver notifications from its previous turn.
2
+ // Only turn/start's response authorizes tagged output for this query's turn.
3
+ function createTurnEvents(deliver) {
4
+ var active = false;
5
+ var starting = false;
6
+ var turnId = null;
7
+ var pending = [];
8
+ function idOf(message) {
9
+ var params = message.params || {};
10
+ return params.turnId || params.turn_id || (params.turn && params.turn.id) || null;
11
+ }
12
+ return {
13
+ begin: function () { active = true; starting = true; turnId = null; pending = []; },
14
+ accept: function (message) {
15
+ var id = idOf(message);
16
+ var scoped = id || /^(turn\/|item\/)/.test(message.method || '');
17
+ if (!scoped) return true;
18
+ if (!active) return false;
19
+ if (starting && id) { pending.push(message); return false; }
20
+ return !id || !turnId || id === turnId;
21
+ },
22
+ ready: function (id) {
23
+ turnId = id;
24
+ starting = false;
25
+ var buffered = pending;
26
+ pending = [];
27
+ buffered.forEach(function (message) { deliver(message); });
28
+ },
29
+ finish: function () { active = false; starting = false; pending = []; },
30
+ };
31
+ }
32
+ module.exports = { createTurnEvents: createTurnEvents };
@@ -0,0 +1,59 @@
1
+ // Stop only the turn owned by this query, including an in-flight turn/start.
2
+ function createTurnStop(server, onError) {
3
+ var turnId = null;
4
+ var threadId = null;
5
+ var starting = false;
6
+ var completed = false;
7
+ var stopped = false;
8
+ var sent = false;
9
+ var resolveStop = null;
10
+ var stopPromise = null;
11
+
12
+ function settle() {
13
+ if (resolveStop) { var resolve = resolveStop; resolveStop = null; resolve(); }
14
+ }
15
+
16
+ function interrupt() {
17
+ if (!stopped || sent) return;
18
+ if (!turnId) { if (!starting) settle(); return; }
19
+ sent = true;
20
+ var target = { threadId: threadId, turnId: turnId };
21
+ Promise.resolve().then(function () {
22
+ if (!server.started) throw new Error('Codex is disconnected; cancellation could not be confirmed.');
23
+ return server.send('turn/interrupt', target, 5000);
24
+ }).catch(function (error) {
25
+ onError(error);
26
+ }).finally(settle);
27
+ }
28
+
29
+ return {
30
+ begin: function (id) { threadId = id; turnId = null; starting = true; completed = false; sent = false; },
31
+ started: function (id) {
32
+ if (!id || turnId || completed) return;
33
+ turnId = id;
34
+ starting = false;
35
+ interrupt();
36
+ },
37
+ startSettled: function (id) {
38
+ starting = false;
39
+ if (id && !turnId && !completed) turnId = id;
40
+ interrupt();
41
+ },
42
+ completed: function (id) {
43
+ if (id && turnId && id !== turnId) return;
44
+ turnId = null;
45
+ completed = true;
46
+ starting = false;
47
+ if (!sent) settle();
48
+ },
49
+ abort: function () {
50
+ if (stopPromise) return stopPromise;
51
+ stopped = true;
52
+ stopPromise = new Promise(function (resolve) { resolveStop = resolve; });
53
+ interrupt();
54
+ return stopPromise;
55
+ },
56
+ };
57
+ }
58
+
59
+ module.exports = { createTurnStop: createTurnStop };
@@ -0,0 +1,40 @@
1
+ // Query-local cancellation. Never terminates a shared provider process.
2
+ function bindAbort(controller, abort) {
3
+ var signal = controller && controller.signal;
4
+ if (!signal) return function () {};
5
+ if (signal.aborted) { abort(); return function () {}; }
6
+ signal.addEventListener('abort', abort, { once: true });
7
+ return function () { signal.removeEventListener('abort', abort); };
8
+ }
9
+
10
+ function createAbortScope() {
11
+ var stopped = false;
12
+ var controller = new AbortController();
13
+ var waiting = new Set();
14
+ function error() { var err = new Error('Query cancelled'); err.name = 'AbortError'; return err; }
15
+ return {
16
+ signal: controller.signal,
17
+ stopped: function () { return stopped; },
18
+ wait: function (promise) {
19
+ return new Promise(function (resolve, reject) {
20
+ function cancel() { reject(error()); }
21
+ if (stopped) cancel();
22
+ else waiting.add(cancel);
23
+ Promise.resolve(promise).then(function (value) {
24
+ waiting.delete(cancel);
25
+ if (stopped) cancel(); else resolve(value);
26
+ }, function (err) { waiting.delete(cancel); reject(err); });
27
+ });
28
+ },
29
+ stop: function () {
30
+ if (stopped) return;
31
+ stopped = true;
32
+ controller.abort();
33
+ waiting.forEach(function (cancel) { cancel(); });
34
+ waiting.clear();
35
+ },
36
+ check: function () { if (stopped) throw error(); },
37
+ };
38
+ }
39
+
40
+ module.exports = { bindAbort: bindAbort, createAbortScope: createAbortScope };
@@ -0,0 +1,11 @@
1
+ // Required decisions use Clay's blocking question lifecycle in every Codex mode.
2
+ function codexQuestionGuidance() {
3
+ return [
4
+ "When clarification materially changes task scope, targets, or intended behavior, use Clay's ask_user_questions tool (or its available MCP-qualified equivalent).",
5
+ "Present the question as a structured input card, not a question followed by bullet choices in ordinary chat. Await the tool result before work that depends on the answer.",
6
+ "Call the blocking question tool by itself; do not batch dependent actions alongside it or detach it into background work. request_user_input may be unavailable outside Plan mode, so use ask_user_questions in that case.",
7
+ "A cancelled, skipped, empty, or failed question is not an answer or approval. Do not infer a choice; leave dependent work pending and explain what answer is needed.",
8
+ "Do not ask again when the user has already answered or authorized the work. This question tool does not replace tool-permission enforcement."
9
+ ].join(" ");
10
+ }
11
+ module.exports = { codexQuestionGuidance: codexQuestionGuidance };
@@ -219,7 +219,7 @@ function fallbackToolDefs(handler, options) {
219
219
  queryBound: true,
220
220
  description: initialLimit === 1
221
221
  ? "Ask the user exactly one structured question, wait for the answer, then call again if another question is needed. Use zero options for freeform or 2-6 options for choices; never one option."
222
- : "Ask the user 1-3 structured questions. Use zero options for freeform or 2-6 options for choices; never one option.",
222
+ : "Ask the user 1-3 structured questions and wait for their answers before continuing dependent work. Use this for scope or target decisions; do not substitute prose questions or asynchronous notifications. A cancelled or skipped question is not an answer. Use zero options for freeform or 2-6 options for choices; never one option.",
223
223
  inputSchema: buildQuestionShape(initialLimit),
224
224
  handler: function (input) {
225
225
  if (questionLimit(options) === 1 && input && Array.isArray(input.questions) && input.questions.length !== 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clay-server",
3
- "version": "4.7.0-beta.1",
3
+ "version": "4.7.0-beta.3",
4
4
  "description": "Self-hosted team workspace for Claude Code and Codex. Multi-user, browser-based, with persistent AI mates.",
5
5
  "bin": {
6
6
  "clay-server": "./bin/cli.js"