@clagentic/console 1.12.0-beta.1 → 1.12.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 (161) hide show
  1. package/LICENSES/README.md +5 -0
  2. package/README.md +1 -0
  3. package/bin/cli.js +5 -2
  4. package/lib/agent-roster-ws.js +84 -0
  5. package/lib/agent-roster.js +312 -0
  6. package/lib/auth-required-notify.js +42 -0
  7. package/lib/build-changes.js +8 -2
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-notify.js +45 -0
  10. package/lib/build-update-offer.js +34 -11
  11. package/lib/build-update-standing.js +34 -14
  12. package/lib/claude-settings-env.js +142 -0
  13. package/lib/cli/duration.js +27 -0
  14. package/lib/cli/schedule-input-subcommands.js +1 -22
  15. package/lib/cli/session-subcommands.js +60 -11
  16. package/lib/client-address.js +44 -0
  17. package/lib/daemon.js +31 -10
  18. package/lib/idle-compaction-setting.js +203 -0
  19. package/lib/mcp-bridge-credential.js +41 -0
  20. package/lib/notification-prefs.js +18 -22
  21. package/lib/notify/core.js +210 -0
  22. package/lib/notify/index.js +31 -0
  23. package/lib/notify/live-prompts.js +36 -0
  24. package/lib/notify/payload.js +62 -0
  25. package/lib/notify/target.js +5 -0
  26. package/lib/notify/type-registry.js +81 -0
  27. package/lib/notify/types.js +57 -0
  28. package/lib/open-sockets.js +27 -0
  29. package/lib/outbound-access.js +85 -0
  30. package/lib/outbound-entry.js +116 -0
  31. package/lib/outbound-ledger.js +306 -0
  32. package/lib/outbound-query.js +153 -0
  33. package/lib/pending-prompts.js +31 -16
  34. package/lib/project-connection.js +48 -8
  35. package/lib/project-filesystem.js +43 -5
  36. package/lib/project-http.js +9 -1
  37. package/lib/project-loop.js +38 -26
  38. package/lib/project-notifications.js +122 -39
  39. package/lib/project-prompt-responses.js +1 -1
  40. package/lib/project-sessions.js +11 -1
  41. package/lib/project-user-mention.js +22 -34
  42. package/lib/project-user-message.js +208 -4
  43. package/lib/project-user-shell.js +298 -0
  44. package/lib/project.js +41 -5
  45. package/lib/prompt-answer.js +145 -0
  46. package/lib/prompt-expiry.js +50 -0
  47. package/lib/prompt-registry.js +98 -25
  48. package/lib/prompt-reminders.js +38 -33
  49. package/lib/prompt-source.js +59 -8
  50. package/lib/public/app.js +32 -2
  51. package/lib/public/css/agent-messages.css +96 -0
  52. package/lib/public/css/agent-roster.css +93 -0
  53. package/lib/public/css/diagnostics.css +29 -1
  54. package/lib/public/css/home-hub.css +12 -0
  55. package/lib/public/css/icon-strip.css +9 -0
  56. package/lib/public/css/input.css +20 -141
  57. package/lib/public/css/login-panel.css +73 -0
  58. package/lib/public/css/menus.css +2 -2
  59. package/lib/public/css/mobile-nav.css +11 -0
  60. package/lib/public/css/sidebar.css +18 -0
  61. package/lib/public/css/team-panel.css +1 -6
  62. package/lib/public/css/team-view.css +101 -0
  63. package/lib/public/css/title-bar.css +10 -0
  64. package/lib/public/css/user-shell.css +144 -0
  65. package/lib/public/index.html +44 -7
  66. package/lib/public/modules/activity-state.js +20 -4
  67. package/lib/public/modules/agent-avatar-picker.js +162 -0
  68. package/lib/public/modules/agent-avatar.js +153 -0
  69. package/lib/public/modules/agent-messages.js +285 -0
  70. package/lib/public/modules/agent-roster.js +157 -0
  71. package/lib/public/modules/app-connection.js +34 -5
  72. package/lib/public/modules/app-messages.js +55 -16
  73. package/lib/public/modules/app-notifications.js +104 -75
  74. package/lib/public/modules/app-panels.js +26 -3
  75. package/lib/public/modules/app-projects.js +3 -1
  76. package/lib/public/modules/app-rate-limit.js +8 -165
  77. package/lib/public/modules/app-rendering.js +32 -7
  78. package/lib/public/modules/build-update-sessions.js +81 -0
  79. package/lib/public/modules/collapsible-text.js +33 -18
  80. package/lib/public/modules/compaction-state.js +34 -0
  81. package/lib/public/modules/custom-icons.js +23 -5
  82. package/lib/public/modules/diagnostics.js +61 -57
  83. package/lib/public/modules/env-shadow-notice.js +34 -0
  84. package/lib/public/modules/injected-identity.js +24 -21
  85. package/lib/public/modules/input.js +176 -15
  86. package/lib/public/modules/login-panel.js +136 -0
  87. package/lib/public/modules/login-parser.js +73 -0
  88. package/lib/public/modules/login-tab.js +66 -0
  89. package/lib/public/modules/notifications.js +9 -1
  90. package/lib/public/modules/notify-client.js +246 -0
  91. package/lib/public/modules/pending-term-request.js +30 -0
  92. package/lib/public/modules/project-icon.js +22 -2
  93. package/lib/public/modules/project-settings.js +5 -0
  94. package/lib/public/modules/prompt-state.js +3 -3
  95. package/lib/public/modules/prompts.js +1 -1
  96. package/lib/public/modules/queued-button.js +11 -0
  97. package/lib/public/modules/scheduled-input-actions.js +12 -4
  98. package/lib/public/modules/scheduled-outbox.js +230 -0
  99. package/lib/public/modules/send-now.js +200 -0
  100. package/lib/public/modules/server-settings.js +50 -1
  101. package/lib/public/modules/shell-card.js +76 -0
  102. package/lib/public/modules/shell-line.js +49 -0
  103. package/lib/public/modules/shell-queue.js +253 -0
  104. package/lib/public/modules/shell-settings-controls.js +76 -0
  105. package/lib/public/modules/sidebar-mobile.js +3 -3
  106. package/lib/public/modules/sidebar-sessions.js +8 -0
  107. package/lib/public/modules/sidebar-users.js +5 -7
  108. package/lib/public/modules/team-panel.js +30 -88
  109. package/lib/public/modules/team-view.js +211 -0
  110. package/lib/public/modules/terminal-links.js +193 -0
  111. package/lib/public/modules/terminal.js +84 -107
  112. package/lib/public/modules/tools.js +19 -0
  113. package/lib/public/modules/user-shell.js +824 -0
  114. package/lib/public/notify-sw-logic.js +252 -0
  115. package/lib/public/notify-target.js +157 -0
  116. package/lib/public/style.css +5 -0
  117. package/lib/public/sw.js +20 -69
  118. package/lib/push.js +63 -19
  119. package/lib/queued-chat.js +392 -0
  120. package/lib/runtime-env.js +1 -0
  121. package/lib/scheduled-input/ws.js +67 -9
  122. package/lib/sdk-bridge.js +184 -73
  123. package/lib/sdk-message-processor.js +124 -76
  124. package/lib/server-auth.js +6 -4
  125. package/lib/server-dm.js +11 -20
  126. package/lib/server-settings.js +39 -1
  127. package/lib/server.js +112 -16
  128. package/lib/session-directory.js +39 -12
  129. package/lib/session-end.js +97 -0
  130. package/lib/session-input-ipc.js +37 -1
  131. package/lib/session-input.js +263 -21
  132. package/lib/session-liveness.js +53 -0
  133. package/lib/session-reclaim.js +37 -2
  134. package/lib/session-resume.js +1 -0
  135. package/lib/session-settings-file.js +53 -0
  136. package/lib/sessions.js +80 -9
  137. package/lib/team-traffic-ws.js +68 -0
  138. package/lib/team-traffic.js +318 -0
  139. package/lib/usage-store.js +36 -7
  140. package/lib/user-shell-settings.js +105 -0
  141. package/lib/vendor-auth.js +33 -2
  142. package/lib/ws-schema.js +33 -5
  143. package/lib/yoke/adapters/claude-capabilities.js +2 -0
  144. package/lib/yoke/adapters/claude-vendor.js +17 -1
  145. package/lib/yoke/adapters/claude-worker.js +39 -11
  146. package/lib/yoke/adapters/claude.js +225 -6
  147. package/lib/yoke/adapters/codex-capabilities.js +6 -1
  148. package/lib/yoke/adapters/codex-user-shell.js +265 -0
  149. package/lib/yoke/adapters/codex-vendor.js +7 -0
  150. package/lib/yoke/adapters/codex.js +186 -52
  151. package/lib/yoke/auth-checks.js +17 -2
  152. package/lib/yoke/codex-app-server.js +8 -2
  153. package/lib/yoke/index.js +21 -3
  154. package/lib/yoke/interface.js +54 -1
  155. package/lib/yoke/mcp-bridge-server.js +12 -8
  156. package/lib/yoke/provider-credentials.js +24 -0
  157. package/lib/yoke/registry.js +40 -1
  158. package/lib/yoke/user-shell.js +224 -0
  159. package/package.json +2 -2
  160. package/scripts/check-test-count.js +14 -0
  161. package/lib/public/modules/build-notice-gate.js +0 -73
@@ -6,6 +6,7 @@
6
6
  var path = require("path");
7
7
  var fs = require("fs");
8
8
  var { CodexAppServer } = require("../codex-app-server");
9
+ var mcpBridgeCredential = require("../../mcp-bridge-credential");
9
10
  var { discoverWorkflows } = require("../../sdk-workflow-discovery");
10
11
  var { discoverSkillsWithMeta, collectSkillDirs } = require("../../sdk-skill-discovery");
11
12
  var codexLocalImage = require("../codex-local-image");
@@ -13,6 +14,10 @@ var runtimeEnv = require("../../runtime-env");
13
14
  var codexCapabilities = require("./codex-capabilities").codexCapabilities;
14
15
  var codexProtocol = require("../codex-protocol");
15
16
  var codexVersion = require("../codex-version");
17
+ var userShellModule = require("./codex-user-shell");
18
+ var createUserShellRunner = userShellModule.createUserShellRunner;
19
+ var refusedResult = userShellModule.refusedResult;
20
+ var OTHER_DIRECTORY = "Not run: this Codex session runs commands only in its own working directory.";
16
21
 
17
22
  // --- Skill discovery ---
18
23
  // Finds the skills of both agents: the user's and the project's .claude/skills
@@ -199,6 +204,8 @@ function flattenEvent(notification, state) {
199
204
  // The app-server's own id for the turn, and the console's id for the message
200
205
  // that started it: together they join a message to the Codex rollout.
201
206
  var startedTurn = params.turn && params.turn.id ? params.turn.id : params.turnId;
207
+ // The turn a steer must name (turn/steer's expectedTurnId); cleared when it ends.
208
+ state.activeTurnId = startedTurn ? String(startedTurn) : null;
202
209
  if (startedTurn && state.currentMessageId) {
203
210
  turnStart.turnId = String(startedTurn);
204
211
  turnStart.messageId = state.currentMessageId;
@@ -208,6 +215,7 @@ function flattenEvent(notification, state) {
208
215
  }
209
216
 
210
217
  if (method === "turn/completed") {
218
+ state.activeTurnId = null;
211
219
  // lr-872f94 — schema-verified (`codex app-server generate-json-schema`,
212
220
  // codex-cli 0.124.0): TurnCompletedNotification is { threadId, turn },
213
221
  // and Turn carries no usage field at all. params.usage/params.status
@@ -278,6 +286,7 @@ function flattenEvent(notification, state) {
278
286
  }
279
287
 
280
288
  if (method === "turn/failed") {
289
+ state.activeTurnId = null;
281
290
  events.push({
282
291
  yokeType: "error",
283
292
  text: params.error ? params.error.message : "Turn failed",
@@ -708,12 +717,23 @@ function createCodexQueryHandle(appServer, queryOpts) {
708
717
  // on the next approval request even though the underlying thread was
709
718
  // started with a different approvalPolicy.
710
719
  toolPolicy: queryOpts.toolPolicy || null,
711
- // lr-de04 — absolute paths of localImage temp files written for the turn
712
- // currently in flight. Cleared (and files deleted) once that turn's
713
- // input has been sent, since the app-server has read the file by then.
714
- pendingImagePaths: [],
720
+ // Temp image files belong to the input that carries them (a queued entry
721
+ // holds its own list). These two lists hold the files of steered inputs:
722
+ // a steer the app-server took lives as long as the running turn; one whose
723
+ // outcome is unknown is never queued again, so it lives to the loop end.
724
+ steeredImagePaths: [],
725
+ unconfirmedImagePaths: [],
715
726
  };
716
727
 
728
+ // Commands the person typed (runUserShellCommand): the runner also decides,
729
+ // by turn id, which notifications are theirs.
730
+ var userShellRunner = createUserShellRunner({
731
+ send: function(method, params, timeoutMs) { return appServer.send(method, params, timeoutMs); },
732
+ isReady: function() { return !!appServer.started; },
733
+ threadId: function() { return state.threadId; },
734
+ activeTurnId: function() { return state.activeTurnId || null; },
735
+ });
736
+
717
737
  // Internal event buffer for async iterator
718
738
  var eventBuffer = [];
719
739
  var eventWaiting = null;
@@ -769,7 +789,11 @@ function createCodexQueryHandle(appServer, queryOpts) {
769
789
  var messageQueueEnded = false;
770
790
 
771
791
  function pushMessageToQueue(msg) {
772
- if (messageQueueEnded) return;
792
+ // A message that can no longer run must not leave its image files behind.
793
+ if (messageQueueEnded || state.done) {
794
+ codexLocalImage.removeTempImages(msg.imagePaths || []);
795
+ return;
796
+ }
773
797
  if (messageWaiting) {
774
798
  var resolve = messageWaiting;
775
799
  messageWaiting = null;
@@ -821,6 +845,10 @@ function createCodexQueryHandle(appServer, queryOpts) {
821
845
  if (cleared) cleared.abort();
822
846
  }
823
847
 
848
+ // A command the person typed keeps its notifications to itself, an abort
849
+ // included: the abort is what settles it.
850
+ if (userShellRunner.consume(method, params)) return;
851
+
824
852
  // After abort, only let turn-ending events through
825
853
  if (isCancelled() && method !== "turn/completed" && method !== "turn/failed" && method !== "serverRequest/resolved" && method !== "thread/status/changed") return;
826
854
 
@@ -975,7 +1003,8 @@ function createCodexQueryHandle(appServer, queryOpts) {
975
1003
  }
976
1004
 
977
1005
  // --- Main query loop ---
978
- async function runQueryLoop(initialMessage, initialInitiator, initialMessageId) {
1006
+ async function runQueryLoop(initialMessage, initialInitiator, initialMessageId, initialImagePaths) {
1007
+ var currentImagePaths = initialImagePaths || [];
979
1008
  // Who started the turn being sent, per turn (turn-initiator.js).
980
1009
  var currentInitiator = initialInitiator;
981
1010
  var currentMessageId = initialMessageId;
@@ -1163,10 +1192,10 @@ function createCodexQueryHandle(appServer, queryOpts) {
1163
1192
  // lr-de04 — the app-server has finished reading any localImage temp
1164
1193
  // files for this turn (whether it completed or failed), so they can
1165
1194
  // be removed now rather than lingering until process exit.
1166
- if (state.pendingImagePaths.length > 0) {
1167
- codexLocalImage.removeTempImages(state.pendingImagePaths);
1168
- state.pendingImagePaths = [];
1169
- }
1195
+ codexLocalImage.removeTempImages(currentImagePaths);
1196
+ codexLocalImage.removeTempImages(state.steeredImagePaths);
1197
+ currentImagePaths = [];
1198
+ state.steeredImagePaths = [];
1170
1199
 
1171
1200
  if (isCancelled()) break;
1172
1201
 
@@ -1176,6 +1205,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1176
1205
  currentMessage = nextMsg.input;
1177
1206
  currentInitiator = nextMsg.initiator;
1178
1207
  currentMessageId = nextMsg.messageId;
1208
+ currentImagePaths = nextMsg.imagePaths || [];
1179
1209
  }
1180
1210
  } catch (e) {
1181
1211
  // Suppress AbortError when the user stopped the query.
@@ -1191,11 +1221,17 @@ function createCodexQueryHandle(appServer, queryOpts) {
1191
1221
  // Always deregister this query's handler so it doesn't receive stale events
1192
1222
  // from a future query on the same app-server thread ID.
1193
1223
  appServer.removeEventHandler(_handlerEntry);
1194
- // lr-de04 — catch-all for images belonging to a turn that never
1195
- // reached the post-turnPromise cleanup above (abort/error mid-turn).
1196
- if (state.pendingImagePaths.length > 0) {
1197
- codexLocalImage.removeTempImages(state.pendingImagePaths);
1198
- state.pendingImagePaths = [];
1224
+ // Files of a turn that never reached the cleanup above (abort or error
1225
+ // mid-turn), of messages still queued that will never run, and of
1226
+ // steers that were not confirmed.
1227
+ codexLocalImage.removeTempImages(currentImagePaths);
1228
+ codexLocalImage.removeTempImages(state.steeredImagePaths);
1229
+ codexLocalImage.removeTempImages(state.unconfirmedImagePaths);
1230
+ currentImagePaths = [];
1231
+ state.steeredImagePaths = [];
1232
+ state.unconfirmedImagePaths = [];
1233
+ while (messageQueue.length > 0) {
1234
+ codexLocalImage.removeTempImages(messageQueue.shift().imagePaths || []);
1199
1235
  }
1200
1236
  }
1201
1237
 
@@ -1203,6 +1239,44 @@ function createCodexQueryHandle(appServer, queryOpts) {
1203
1239
  endIterator();
1204
1240
  }
1205
1241
 
1242
+ // Turn input for one message: plain text, or localImage items plus the text.
1243
+ // An image that cannot be written is reported, never dropped silently.
1244
+ // Returns { input, imagePaths }: the temp files travel with the input that
1245
+ // references them, so each turn cleans only its own.
1246
+ function buildTurnInput(text, images) {
1247
+ var input;
1248
+ var imagePaths = [];
1249
+ if (images && images.length > 0) {
1250
+ input = [];
1251
+ var failedCount = 0;
1252
+ for (var i = 0; i < images.length; i++) {
1253
+ var img = images[i];
1254
+ var imgPath = codexLocalImage.writeTempImage(img.mediaType, img.data);
1255
+ if (imgPath) {
1256
+ imagePaths.push(imgPath);
1257
+ input.push({ type: "localImage", path: imgPath });
1258
+ } else {
1259
+ failedCount++;
1260
+ }
1261
+ }
1262
+ if (failedCount > 0) {
1263
+ // Acceptance criterion (lr-de04): an image must never be dropped
1264
+ // silently. Surface a visible error event so the UI shows it,
1265
+ // matching the shape flattenEvent already produces for turn/failed.
1266
+ pushEvent({
1267
+ yokeType: "error",
1268
+ text: failedCount === 1
1269
+ ? "1 image could not be sent to Codex (failed to write temp file) and was not included in this message."
1270
+ : failedCount + " images could not be sent to Codex (failed to write temp file) and were not included in this message.",
1271
+ });
1272
+ }
1273
+ input.push({ type: "text", text: text || "" });
1274
+ } else {
1275
+ input = text || "";
1276
+ }
1277
+ return { input: input, imagePaths: imagePaths };
1278
+ }
1279
+
1206
1280
  var handle = {
1207
1281
  [Symbol.asyncIterator]: function() {
1208
1282
  return {
@@ -1219,44 +1293,58 @@ function createCodexQueryHandle(appServer, queryOpts) {
1219
1293
  },
1220
1294
 
1221
1295
  pushMessage: function(text, images, initiator, messageId) {
1222
- var input;
1223
- if (images && images.length > 0) {
1224
- input = [];
1225
- var failedCount = 0;
1226
- for (var i = 0; i < images.length; i++) {
1227
- var img = images[i];
1228
- var imgPath = codexLocalImage.writeTempImage(img.mediaType, img.data);
1229
- if (imgPath) {
1230
- state.pendingImagePaths.push(imgPath);
1231
- input.push({ type: "localImage", path: imgPath });
1232
- } else {
1233
- failedCount++;
1234
- }
1235
- }
1236
- if (failedCount > 0) {
1237
- // Acceptance criterion (lr-de04): an image must never be dropped
1238
- // silently. Surface a visible error event so the UI shows it,
1239
- // matching the shape flattenEvent already produces for turn/failed.
1240
- pushEvent({
1241
- yokeType: "error",
1242
- text: failedCount === 1
1243
- ? "1 image could not be sent to Codex (failed to write temp file) and was not included in this message."
1244
- : failedCount + " images could not be sent to Codex (failed to write temp file) and were not included in this message.",
1245
- });
1246
- }
1247
- input.push({ type: "text", text: text || "" });
1248
- } else {
1249
- input = text || "";
1250
- }
1296
+ var built = buildTurnInput(text, images);
1251
1297
 
1252
1298
  if (!state.loopStarted) {
1253
1299
  state.loopStarted = true;
1254
- runQueryLoop(input, initiator, messageId);
1300
+ runQueryLoop(built.input, initiator, messageId, built.imagePaths);
1255
1301
  } else {
1256
- pushMessageToQueue({ input: input, initiator: initiator, messageId: messageId });
1302
+ pushMessageToQueue({ input: built.input, imagePaths: built.imagePaths, initiator: initiator, messageId: messageId });
1257
1303
  }
1258
1304
  },
1259
1305
 
1306
+ // Delivers a message into the turn that is running (turn/steer). Resolves
1307
+ // { steered: true } when the app-server took it. When no turn is running, or
1308
+ // the turn ended before the steer landed (expectedTurnId no longer matches,
1309
+ // or any other refusal), the message goes to the queue for the next turn and
1310
+ // resolves { steered: false, reason }: it is never dropped. A transport
1311
+ // failure (timeout, dead process) is different: the server may have taken the
1312
+ // message, so it is NOT queued again (that could run a second turn); it
1313
+ // resolves { steered: false, reason: "unconfirmed" } and the caller tells the
1314
+ // user.
1315
+ steerMessage: function(text, images, initiator, messageId) {
1316
+ var turnId = state.activeTurnId;
1317
+ if (!state.loopStarted || !turnId || !state.threadId) {
1318
+ handle.pushMessage(text, images, initiator, messageId);
1319
+ return Promise.resolve({ steered: false, reason: "no-running-turn" });
1320
+ }
1321
+ // Built once: a refused steer queues this same prepared input, so temp
1322
+ // image files are written a single time and none is dropped on the retry.
1323
+ var built = buildTurnInput(text, images);
1324
+ var prepared = built.input;
1325
+ var input = typeof prepared === "string" ? [{ type: "text", text: prepared }] : prepared;
1326
+ var params = { threadId: state.threadId, expectedTurnId: turnId, input: input };
1327
+ if (typeof messageId === "string" && messageId) params.clientUserMessageId = messageId;
1328
+ // The response can arrive after runQueryLoop's finally has drained the
1329
+ // per-loop path lists; nothing drains them again, so a settle that finds
1330
+ // the loop done removes its files itself.
1331
+ return appServer.send("turn/steer", params, 10000).then(function() {
1332
+ if (state.done) codexLocalImage.removeTempImages(built.imagePaths);
1333
+ else state.steeredImagePaths = state.steeredImagePaths.concat(built.imagePaths);
1334
+ return { steered: true };
1335
+ }, function(err) {
1336
+ if (!err || typeof err.rpcCode !== "number") {
1337
+ console.warn("[yoke/codex] turn/steer outcome unknown, not queueing again: " + (err && err.message || err));
1338
+ if (state.done) codexLocalImage.removeTempImages(built.imagePaths);
1339
+ else state.unconfirmedImagePaths = state.unconfirmedImagePaths.concat(built.imagePaths);
1340
+ return { steered: false, reason: "unconfirmed" };
1341
+ }
1342
+ console.warn("[yoke/codex] turn/steer refused, queueing for the next turn: " + (err && err.message || err));
1343
+ pushMessageToQueue({ input: prepared, imagePaths: built.imagePaths, initiator: initiator, messageId: messageId });
1344
+ return { steered: false, reason: "turn-ended" };
1345
+ });
1346
+ },
1347
+
1260
1348
  setModel: function(model) {
1261
1349
  // lr-79ee — genuinely live: turn/start (see runQueryLoop above) sends
1262
1350
  // state.model on every turn, so this takes effect starting with the
@@ -1305,9 +1393,24 @@ function createCodexQueryHandle(appServer, queryOpts) {
1305
1393
  return Promise.resolve(null);
1306
1394
  },
1307
1395
 
1396
+ // Runs a command the person typed, on the thread, through the app-server's
1397
+ // thread/shellCommand with the console's timeout. thread/shellCommand runs
1398
+ // where the thread runs and takes no directory, so a command asked for in
1399
+ // any other directory is refused with a result that says why; it is never run
1400
+ // elsewhere and the directory is never ignored. runOpts.signal interrupts it.
1401
+ // Resolves with the result (YOKE interface 0.6.0); rejects when the
1402
+ // app-server refuses the request.
1403
+ runUserShellCommand: function(command, cwd, timeoutMs, maxOutputBytes, runOpts) {
1404
+ var signal = runOpts && runOpts.signal;
1405
+ var elsewhere = cwd && (!queryOpts.cwd || path.resolve(cwd) !== path.resolve(queryOpts.cwd));
1406
+ if (elsewhere) return Promise.resolve(refusedResult(OTHER_DIRECTORY));
1407
+ return userShellRunner.run(command, timeoutMs, maxOutputBytes, signal);
1408
+ },
1409
+
1308
1410
  abort: function() {
1309
1411
  console.log("[yoke/codex] handle.abort() called, threadId=" + state.threadId + " already aborted=" + state.aborted);
1310
1412
  state.aborted = true;
1413
+ userShellRunner.interruptRunning();
1311
1414
  // Send turn/interrupt to stop the server-side turn
1312
1415
  if (state.threadId && appServer.started) {
1313
1416
  appServer.send("turn/interrupt", { threadId: state.threadId }, 5000).catch(function() {});
@@ -1324,6 +1427,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1324
1427
  },
1325
1428
 
1326
1429
  close: function() {
1430
+ userShellRunner.interruptRunning();
1327
1431
  messageQueueEnded = true;
1328
1432
  if (messageWaiting) {
1329
1433
  var resolve = messageWaiting;
@@ -1443,6 +1547,26 @@ function mergeConfig(base, over) {
1443
1547
  // reports, else what the binary reported when it was resolved. initialize has
1444
1548
  // no version field of its own, so a userAgent that cannot be read is no reason
1445
1549
  // to refuse a server whose binary reported one.
1550
+ // Whether the running app-server has turn/steer, found by calling it with ids
1551
+ // that name nothing. A server that has the method answers with a refusal about
1552
+ // the thread; one that lacks it answers with JSON-RPC -32601. Any other
1553
+ // outcome (a timeout, a dead process) proves nothing, so steering stays off.
1554
+ async function probeTurnSteer(server) {
1555
+ try {
1556
+ await server.send("turn/steer", {
1557
+ threadId: "00000000-0000-0000-0000-000000000000",
1558
+ expectedTurnId: "probe",
1559
+ input: [{ type: "text", text: "" }],
1560
+ }, 8000);
1561
+ return true;
1562
+ } catch (e) {
1563
+ // Only a structured JSON-RPC refusal proves the server parsed the call:
1564
+ // -32601 is "method not found", any other code is a refusal of this call.
1565
+ if (!e || typeof e.rpcCode !== "number") return false;
1566
+ return e.rpcCode !== -32601;
1567
+ }
1568
+ }
1569
+
1446
1570
  function settleRunningVersion(binaryVersion, initializeResult) {
1447
1571
  var reported = codexVersion.versionFromUserAgent(initializeResult && initializeResult.userAgent);
1448
1572
  var binary = codexVersion.parseVersion(typeof binaryVersion === "string" ? binaryVersion : "");
@@ -1610,7 +1734,7 @@ function createCodexAdapter(opts) {
1610
1734
  skills: skillNames || [],
1611
1735
  slashCommands: buildEnrichedSlashCommands(skillNames, cwd, homeOverride),
1612
1736
  fastModeState: null,
1613
- capabilities: codexCapabilities(),
1737
+ capabilities: Object.assign(codexCapabilities(), { steering: inst.steer === true }),
1614
1738
  };
1615
1739
  }
1616
1740
 
@@ -1847,18 +1971,26 @@ function createCodexAdapter(opts) {
1847
1971
  var bridgePath = require("path").join(__dirname, "..", "mcp-bridge-server.js");
1848
1972
  var clayPort = effectiveInitOpts.clayPort || process.env.CLAY_PORT || 2633;
1849
1973
  var clayTls = effectiveInitOpts.clayTls || false;
1850
- var clayAuthToken = effectiveInitOpts.clayAuthToken || "";
1851
1974
  var claySlug = effectiveInitOpts.slug || _slug || "";
1852
1975
  try {
1853
- if (require("fs").existsSync(bridgePath)) {
1976
+ // The daemon serves the bridge only under /p/{slug}, so without a
1977
+ // slug there is nothing for the bridge to reach and no credential
1978
+ // to issue.
1979
+ if (claySlug && require("fs").existsSync(bridgePath)) {
1854
1980
  var bridgeArgs = [bridgePath, "--port", String(clayPort), "--slug", claySlug];
1855
1981
  if (clayTls) bridgeArgs.push("--tls");
1856
- var bridgeEnv = {};
1857
- if (clayAuthToken) bridgeEnv.CLAY_AUTH_TOKEN = clayAuthToken;
1982
+ // mcp_servers config is serialized into --config argv of the
1983
+ // app-server process (and logged), so the credential must not
1984
+ // travel in it. It rides in the app-server's own environment
1985
+ // (secretEnv) and the config names the variable, which Codex
1986
+ // forwards to the bridge child.
1858
1987
  mcpServerConfig["clay-tools"] = {
1859
1988
  command: process.execPath,
1860
1989
  args: bridgeArgs,
1861
- env: Object.keys(bridgeEnv).length > 0 ? bridgeEnv : undefined,
1990
+ env_vars: [mcpBridgeCredential.ENV_NAME],
1991
+ };
1992
+ serverOpts.secretEnv = {
1993
+ [mcpBridgeCredential.ENV_NAME]: mcpBridgeCredential.credentialFor(claySlug),
1862
1994
  };
1863
1995
  }
1864
1996
  } catch (e) {
@@ -1902,6 +2034,7 @@ function createCodexAdapter(opts) {
1902
2034
  throw codexError("CODEX_TOO_OLD", "Codex " + running.text + " is too old; Clagentic: Console needs " + codexVersion.MIN_CODEX_VERSION + " or newer");
1903
2035
  }
1904
2036
  inst.version = running ? running.text : null;
2037
+ inst.steer = await probeTurnSteer(server);
1905
2038
  inst.features = codexProtocol.protocolFeatures(running);
1906
2039
  if (JSON.stringify(inst.features) !== JSON.stringify(spawnFeatures)) {
1907
2040
  console.warn("[codex] the running app-server (" + inst.version + ") differs from the binary that was resolved (" + binaryVersion + "); its config was set for the binary");
@@ -2199,4 +2332,5 @@ module.exports = {
2199
2332
  // indirectly through a full query/init round trip.
2200
2333
  _test_discoverClaudeSkills: discoverSkillFiles,
2201
2334
  _test_mergeConfig: mergeConfig,
2335
+ _test_probeTurnSteer: probeTurnSteer,
2202
2336
  };
@@ -4,6 +4,8 @@
4
4
  var execSync = require("child_process").execSync;
5
5
  var codexCommand = require("./codex-command");
6
6
  var providerCredentials = require("./provider-credentials");
7
+ var runtimeEnv = require("../runtime-env");
8
+ var claudeSettingsEnv = require("../claude-settings-env");
7
9
 
8
10
  function parseClaudeAuthStatusJson(out) {
9
11
  if (!out) return null;
@@ -35,8 +37,21 @@ function hasThirdPartyProviderAuth(env) {
35
37
  return null;
36
38
  }
37
39
 
38
- function checkClaudeAuth() {
39
- var provider = hasThirdPartyProviderAuth();
40
+ /**
41
+ * @param {?object} overlay the Settings variables a Claude runtime is started
42
+ * with (sdk-bridge getRuntimeEnvOverlay), or null. The probe reads the same
43
+ * composed environment the spawn gets, never the daemon's alone.
44
+ * @param {boolean} [osUsers] os-users mode: no settings file is read
45
+ */
46
+ function checkClaudeAuth(overlay, osUsers) {
47
+ var env = runtimeEnv.composeRuntimeEnv(process.env, overlay);
48
+ // Claude applies the user settings file's env block over the environment it
49
+ // is handed, so the provider is decided from that, not from the composed
50
+ // environment alone. The probe below runs with the daemon's own environment
51
+ // as before: it only reports whether the daemon user is signed in, and
52
+ // handing it project or shared text would let that text steer which account
53
+ // it asks about.
54
+ var provider = hasThirdPartyProviderAuth(claudeSettingsEnv.applyUserSettingsEnv(env, { osUsers: !!osUsers }));
40
55
  if (provider) {
41
56
  console.log("[yoke] Claude auth via third-party provider: " + provider);
42
57
  return true;
@@ -60,6 +60,7 @@ function toTomlValue(val) {
60
60
  //
61
61
  // opts: { cwd, env, config }
62
62
  // env the environment laid over the daemon's own
63
+ // secretEnv variables laid over that last, for values that must stay out of config
63
64
  function CodexAppServer(executablePath, opts) {
64
65
  this.proc = null;
65
66
  this.rl = null;
@@ -88,7 +89,8 @@ CodexAppServer.prototype.start = function() {
88
89
  return new Promise(function(resolve, reject) {
89
90
  try {
90
91
  var args = ["app-server"];
91
- var env = Object.assign({}, process.env, self.opts.env || {});
92
+ // secretEnv is laid last and never reaches argv or the log line below.
93
+ var env = Object.assign({}, process.env, self.opts.env || {}, self.opts.secretEnv || {});
92
94
 
93
95
  // Pass config overrides via --config key=value flags
94
96
  if (self.opts.config) {
@@ -170,7 +172,11 @@ CodexAppServer.prototype._handleMessage = function(msg) {
170
172
  delete this.pendingRequests[msg.id];
171
173
  if (pending.timer) clearTimeout(pending.timer);
172
174
  if (msg.error) {
173
- pending.reject(new Error(msg.error.message || JSON.stringify(msg.error)));
175
+ // The numeric JSON-RPC code rides on the error so a caller can tell a
176
+ // server's explicit refusal from a transport failure (which has none).
177
+ var rpcErr = new Error(msg.error.message || JSON.stringify(msg.error));
178
+ if (typeof msg.error.code === "number") rpcErr.rpcCode = msg.error.code;
179
+ pending.reject(rpcErr);
174
180
  } else {
175
181
  pending.resolve(msg.result);
176
182
  }
package/lib/yoke/index.js CHANGED
@@ -6,6 +6,9 @@ var instructions = require("./instructions");
6
6
  var registry = require("./registry");
7
7
  var installProbe = require("./install-probe");
8
8
  var capabilities = require("./capabilities");
9
+ var providerCredentials = require("./provider-credentials");
10
+ var runtimeEnv = require("../runtime-env");
11
+ var claudeSettingsEnv = require("../claude-settings-env");
9
12
  // Requiring the vendor modules registers the shipped agents. They are light on
10
13
  // purpose: the adapters themselves are loaded when one is created.
11
14
  require("./adapters/claude-vendor");
@@ -86,14 +89,28 @@ function logAuthCheck(auth) {
86
89
  console.log("[yoke] Auth check: " + Object.keys(auth).map(function(id) { return id + "=" + auth[id]; }).join(" "));
87
90
  }
88
91
 
89
- function checkAuth() {
90
- if (_authCache) return _authCache;
92
+ // The answer depends on the Settings environment a runtime starts with, so the
93
+ // cache holds one answer for one overlay and a different overlay recomputes.
94
+ var _authCacheSig = null;
95
+
96
+ /**
97
+ * @param {?object} [overlay] the Settings variables of the runtime the answer
98
+ * is for (null: the daemon's own environment)
99
+ * @param {boolean} [osUsers] os-users mode: no settings file is read for it
100
+ */
101
+ function checkAuth(overlay, osUsers) {
102
+ // The same overlay answers differently when the settings file is not read,
103
+ // and when the file the classification reads is edited.
104
+ var sig = runtimeEnv.envSignature(overlay) + "\0" + (osUsers ? "os" : "") +
105
+ "\0" + claudeSettingsEnv.settingsFileStamp({ osUsers: !!osUsers });
106
+ if (_authCache && _authCacheSig === sig) return _authCache;
91
107
 
92
108
  var result = {};
93
109
  registry.list().forEach(function(vendor) {
94
- result[vendor.id] = !!vendor.checkAuth();
110
+ result[vendor.id] = !!vendor.checkAuth(overlay || null, !!osUsers);
95
111
  });
96
112
  _authCache = result;
113
+ _authCacheSig = sig;
97
114
  logAuthCheck(_authCache);
98
115
  return _authCache;
99
116
  }
@@ -212,6 +229,7 @@ async function lazyCreateAdapter(adapters, vendor, opts, onInit) {
212
229
  module.exports = {
213
230
  isKnownVendor: isKnownVendor,
214
231
  registry: registry,
232
+ providerCredentials: providerCredentials,
215
233
  resolveCapabilities: capabilities.resolveCapabilities,
216
234
  completeCapabilities: iface.completeCapabilities,
217
235
  detectInstalledVendors: installProbe.detectInstalledVendors,
@@ -38,6 +38,26 @@
38
38
  // ignores it.
39
39
  // Removed: the attestsHumanSessions trait. Provenance is per turn and carried
40
40
  // by the turn itself, not declared per adapter.
41
+ //
42
+ // 0.5.0 → 0.6.0 (2026-11, additive)
43
+ // Added: QueryHandle.runUserShellCommand(command, cwd, timeoutMs,
44
+ // maxOutputBytes, { signal }), an optional method for a shell command the
45
+ // person typed for themselves. It resolves with { exitCode, durationMs,
46
+ // output, truncated, timedOut, interrupted }, and the command ends up in the
47
+ // agent's conversation without a model turn. Nothing else changes: an adapter
48
+ // without the method is detectable (typeof handle.runUserShellCommand !==
49
+ // "function") and is simply offered no such command, so no existing adapter or
50
+ // caller has to change.
51
+ // Migration for an adapter author: implement the method only if the agent can
52
+ // record a user-run command without answering it. An adapter may refuse a cwd
53
+ // it cannot honour; the refusal is a resolved result (exitCode null, output
54
+ // naming the reason), never a throw, and the command is not run elsewhere.
55
+ // Honour signal by stopping
56
+ // the command, and report interrupted: true only once it has stopped. Cut the
57
+ // output at maxOutputBytes on a character boundary, counting any failure text
58
+ // you add. Never run the command as another user than the console process.
59
+ // In an adapter that identifies a command's notifications by turn id, match
60
+ // every one of them (start, items, end, late end) on that id.
41
61
 
42
62
  /**
43
63
  * YOKE contract version. Bumped on every additive or breaking change.
@@ -51,8 +71,9 @@
51
71
  * 0.3.0 — capability ledger, vendor registry, reconciled method lists
52
72
  * 0.4.0 — adapter traits split out of the capability ledger
53
73
  * 0.5.0 — per-turn initiator on pushMessage; attestsHumanSessions removed
74
+ * 0.6.0 — optional QueryHandle.runUserShellCommand
54
75
  */
55
- var INTERFACE_VERSION = "0.5.0";
76
+ var INTERFACE_VERSION = "0.6.0";
56
77
 
57
78
  var TOOL_POLICIES = ["ask", "allow-all"];
58
79
 
@@ -134,10 +155,40 @@ var QUERY_HANDLE_METHODS = [
134
155
  * (or the method) first; absence is not an error.
135
156
  * .setPermissionMode(mode) - capability permissionModes
136
157
  * .rewindFiles(uuid, opts) - capability rewind
158
+ * .cancelQueuedMessage(messageId) - capability queuedMessageCancel (the caller
159
+ * checks the capability, not the list above); withdraws
160
+ * a message pushed with that messageId that the
161
+ * agent has not yet taken into a turn. Resolves
162
+ * true when it was withdrawn (it will never be
163
+ * delivered) and false when it was already taken
164
+ * or is unknown; rejects when the agent cannot say.
165
+ * .interruptKeepingQueued() - capability queuedMessageCancel; interrupts the
166
+ * running turn and keeps every message already
167
+ * pushed, so a queued one runs as the next input at
168
+ * once. Resolves { stillQueued }: the message ids the
169
+ * agent still holds after the interrupt (they run),
170
+ * or null when the agent gave no receipt; rejects when
171
+ * the agent cannot interrupt.
172
+ * .runUserShellCommand(command, cwd, timeoutMs, maxOutputBytes, { signal })
173
+ * - runs a shell command the person typed for
174
+ * themselves, kills it at timeoutMs, keeps at most
175
+ * maxOutputBytes of its output (cut on a character
176
+ * boundary; the result says when it cut) and puts it
177
+ * in the conversation with no model turn. signal (an
178
+ * AbortSignal) interrupts it. Resolves { exitCode,
179
+ * durationMs, output, truncated, timedOut,
180
+ * interrupted }; interrupted is true only once the
181
+ * command has stopped. An adapter may refuse a cwd it
182
+ * cannot honour: the refusal is a result whose output
183
+ * names the reason, not a throw. The caller has already passed
184
+ * whatever gate applies; the method never asks.
185
+ * Absent where the agent cannot take it (the
186
+ * OS-user worker handle): test for the method.
137
187
  */
138
188
  var QUERY_HANDLE_OPTIONAL_METHODS = [
139
189
  "setPermissionMode",
140
190
  "rewindFiles",
191
+ "runUserShellCommand",
141
192
  ];
142
193
 
143
194
  /**
@@ -195,9 +246,11 @@ var CAPABILITIES = {
195
246
  backgroundTasks: { kind: "flag", reason: "This agent has no background tasks." },
196
247
  steering: { kind: "flag", reason: "This agent cannot take a message while it is working." },
197
248
  agentInjection: { kind: "flag", reason: "This agent cannot take on a named agent identity." },
249
+ queuedMessageCancel: { kind: "flag", reason: "This agent cannot withdraw a message that is waiting to be delivered." },
198
250
  executionPolicy: { kind: "flag", reason: "This agent has no approval, sandbox or web search settings." },
199
251
  toolPolicy: { kind: "list", reason: "This agent has no tool approval policy." },
200
252
  permissionModes: { kind: "list", reason: "This agent has no permission modes." },
253
+ additiveSettings: { kind: "flag", reason: "This agent cannot take an extra settings file for a session." },
201
254
  };
202
255
 
203
256
  var CAPABILITY_KEYS = Object.keys(CAPABILITIES);
@@ -4,7 +4,7 @@
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
6
  // list/call requests to the project-scoped HTTP endpoint
7
- // (/p/{slug}/api/mcp-bridge) when a slug is provided.
7
+ // (/p/{slug}/api/mcp-bridge). A slug is required.
8
8
  //
9
9
  // Usage: node mcp-bridge-server.js --port 2633 --slug my-project
10
10
  //
@@ -18,6 +18,7 @@
18
18
 
19
19
  var http = require("http");
20
20
  var https = require("https");
21
+ var bridgeCredential = require("../mcp-bridge-credential");
21
22
 
22
23
  // --- Parse CLI args ---
23
24
  var args = process.argv.slice(2);
@@ -37,14 +38,18 @@ for (var i = 0; i < args.length; i++) {
37
38
  }
38
39
  }
39
40
 
41
+ if (!claySlug) {
42
+ process.stderr.write("mcp-bridge-server: --slug is required\n");
43
+ process.exit(1);
44
+ }
45
+
40
46
  var CLAY_PROTOCOL = clayTls ? "https" : "http";
41
47
  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";
48
+ var CLAY_MCP_PATH = "/p/" + claySlug + "/api/mcp-bridge";
45
49
 
46
50
  // --- Auth ---
47
- var clayAuthToken = process.env.CLAY_AUTH_TOKEN || "";
51
+ // The per-project bridge credential, handed over in the environment only.
52
+ var bridgeToken = process.env[bridgeCredential.ENV_NAME] || "";
48
53
 
49
54
  // --- Tool cache ---
50
55
  var _tools = []; // [{ server, name, description, inputSchema }]
@@ -62,9 +67,8 @@ function postJson(urlPath, body) {
62
67
  "Content-Type": "application/json",
63
68
  "Content-Length": Buffer.byteLength(data),
64
69
  };
65
- // Include auth cookie if available (required for authenticated servers)
66
- if (clayAuthToken) {
67
- headers["Cookie"] = "relay_auth=" + clayAuthToken;
70
+ if (bridgeToken) {
71
+ headers[bridgeCredential.HEADER_NAME] = bridgeToken;
68
72
  }
69
73
 
70
74
  var reqOpts = {