@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
@@ -17,6 +17,7 @@ var permissionRelay = require("./permission-relay");
17
17
  var effortControl = require("./effort-control");
18
18
  var runtimeEnv = require("../../runtime-env");
19
19
  var turnInitiator = require("../../turn-initiator");
20
+ var userShell = require("../user-shell");
20
21
  var claudeCapabilities = require("./claude-capabilities").claudeCapabilities;
21
22
 
22
23
  // --- SDK loading ---
@@ -87,6 +88,17 @@ function flattenEvent(raw) {
87
88
  base.messageType = raw.type; // "user" or "assistant"
88
89
  base.parentToolUseId = raw.parent_tool_use_id || null;
89
90
  }
91
+ // The client uuids of the user messages the CLI has taken into the turn so
92
+ // far (sdk.d.ts SDKAssistantMessage.user_message_uuids), which is how a
93
+ // sender learns its message was delivered. An older CLI sends only the single
94
+ // user_message_uuid, so that is the fallback. Readers that do not know the
95
+ // field ignore it.
96
+ var consumed = Array.isArray(raw.user_message_uuids) ? raw.user_message_uuids
97
+ : (typeof raw.user_message_uuid === "string" ? [raw.user_message_uuid] : null);
98
+ if (consumed) {
99
+ var consumedIds = consumed.filter(function (id) { return typeof id === "string" && id; });
100
+ if (consumedIds.length > 0) base.userMessageUuids = consumedIds;
101
+ }
90
102
 
91
103
  // --- stream_event with nested event ---
92
104
  if (raw.type === "stream_event" && raw.event) {
@@ -281,6 +293,13 @@ function flattenEvent(raw) {
281
293
  base.yokeType = "message";
282
294
  base.messageRole = raw.type;
283
295
  base.content = raw.message ? raw.message.content : null;
296
+ // The immediate acknowledgement of a run_in_background Agent call is a
297
+ // launch, not an end: the SDK marks it with the structured tool output
298
+ // (status "async_launched"), so the host never has to read the result text.
299
+ var launch = raw.type === "user" ? raw.tool_use_result : null;
300
+ if (launch && typeof launch === "object" && launch.status === "async_launched") {
301
+ base.asyncLaunch = { agentId: typeof launch.agentId === "string" ? launch.agentId : null };
302
+ }
284
303
  return base;
285
304
  }
286
305
 
@@ -373,10 +392,48 @@ function buildUserMessage(text, images, initiator, messageId) {
373
392
  return message;
374
393
  }
375
394
 
395
+ // The transcript entry for a command the person typed: a user message the CLI
396
+ // records without starting a model turn (shouldQuery: false), attributed to the
397
+ // person like any message they type. Its text is the console's record of the
398
+ // command's output, so it is marked client-composed: the CLI keeps it as
399
+ // written (no @path expansion, no slash-command dispatch inside program output).
400
+ function buildShellTranscriptMessage(command, result) {
401
+ var message = {
402
+ type: "user",
403
+ message: { role: "user", content: [{ type: "text", text: userShell.formatTranscriptText(command, result) }] },
404
+ parent_tool_use_id: null,
405
+ shouldQuery: false,
406
+ };
407
+ turnInitiator.stampClaudeUserMessage(message, turnInitiator.INITIATORS.HUMAN);
408
+ message.client_composed = true;
409
+ return message;
410
+ }
411
+
412
+ // How long close() waits for an interrupted command to be recorded before it
413
+ // ends the query anyway.
414
+ var SHELL_RECORD_WAIT_MS = 3000;
415
+
416
+ // The interrupt receipt as the console reads it: the uuids that survive the
417
+ // interrupt, or null when the CLI sent none (an older CLI answers undefined).
418
+ function receiptOf(receipt) {
419
+ if (!receipt || !Array.isArray(receipt.still_queued)) return { stillQueued: null };
420
+ return { stillQueued: receipt.still_queued.filter(function (id) { return typeof id === "string"; }) };
421
+ }
422
+
376
423
  // --- QueryHandle ---
377
424
  // Wraps a raw SDK query object with the YOKE QueryHandle interface.
378
425
  // Events are flattened via flattenEvent before yielding.
379
- function createQueryHandle(rawQuery, messageQueue, abortController) {
426
+ // userShellEnv is the environment the query's CLI process runs with, so a
427
+ // command the person types sees what the agent's own commands see.
428
+ function createQueryHandle(rawQuery, messageQueue, abortController, userShellEnv) {
429
+ // The commands the person typed that are still running: controller to the
430
+ // promise that settles once the command's transcript entry is recorded.
431
+ var shellRuns = new Map();
432
+ var closed = false;
433
+ function stopShellRuns() {
434
+ shellRuns.forEach(function (recorded, ac) { ac.abort(); });
435
+ }
436
+
380
437
  var handle = {
381
438
  // Opaque adapter state (null for in-process queries)
382
439
  _adapterState: null,
@@ -398,6 +455,29 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
398
455
  messageQueue.push(buildUserMessage(text, images, initiator, messageId));
399
456
  },
400
457
 
458
+ // Withdraws a pushed message the CLI has not yet taken into a turn
459
+ // (control request cancel_async_message). Resolves true when it was dropped
460
+ // from the queue, false when it was already taken or is unknown. The method
461
+ // is on the SDK's Query at run time but not in its published typings, so
462
+ // its absence is tested for and reported, never assumed.
463
+ cancelQueuedMessage: function(messageId) {
464
+ if (!rawQuery || typeof rawQuery.cancelAsyncMessage !== "function") {
465
+ return Promise.reject(new Error("The installed Claude SDK cannot cancel a queued message."));
466
+ }
467
+ return Promise.resolve(rawQuery.cancelAsyncMessage(messageId)).then(function (cancelled) { return cancelled === true; });
468
+ },
469
+
470
+ // Interrupts the running turn and keeps the SDK's queue (Query.interrupt()
471
+ // without cancelQueued), so a pushed message the CLI has not taken runs as
472
+ // the next input. Resolves { stillQueued }: the uuids the interrupt receipt
473
+ // lists as surviving, or null when the CLI sent no receipt.
474
+ interruptKeepingQueued: function() {
475
+ if (!rawQuery || typeof rawQuery.interrupt !== "function") {
476
+ return Promise.reject(new Error("The installed Claude SDK cannot interrupt a query."));
477
+ }
478
+ return Promise.resolve(rawQuery.interrupt()).then(receiptOf);
479
+ },
480
+
401
481
  setModel: function(model) {
402
482
  if (rawQuery && typeof rawQuery.setModel === "function") {
403
483
  return rawQuery.setModel(model);
@@ -454,16 +534,37 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
454
534
  // for a capability nothing needs per-query.
455
535
 
456
536
  abort: function() {
537
+ stopShellRuns();
457
538
  if (abortController) {
458
539
  try { abortController.abort(); } catch (e) {}
459
540
  }
460
541
  },
461
542
 
543
+ // Stops a command still running and records its interrupted transcript entry
544
+ // BEFORE the message queue ends: an entry pushed after end() is dropped, and
545
+ // the conversation would then lack a command the person saw run.
546
+ // Never rejects: its callers call it synchronously and ignore the result, and
547
+ // everything it waits on is held by this handle, not by session state they
548
+ // clear right after.
462
549
  close: function() {
463
- try { messageQueue.end(); } catch (e) {}
464
- if (rawQuery && typeof rawQuery.close === "function") {
465
- try { rawQuery.close(); } catch (e) {}
550
+ closed = true;
551
+ var recorded = Array.from(shellRuns.values());
552
+ stopShellRuns();
553
+ function finish() {
554
+ try { messageQueue.end(); } catch (e) {}
555
+ if (rawQuery && typeof rawQuery.close === "function") {
556
+ try { rawQuery.close(); } catch (e) {}
557
+ }
466
558
  }
559
+ if (recorded.length === 0) { finish(); return Promise.resolve(); }
560
+ var timer;
561
+ var gaveUp = new Promise(function (resolve) { timer = setTimeout(resolve, SHELL_RECORD_WAIT_MS); });
562
+ return Promise.race([Promise.all(recorded), gaveUp]).catch(function (err) {
563
+ console.warn("[yoke/claude] close() could not wait for the interrupted command's record:", err && err.message || err);
564
+ }).then(function () {
565
+ clearTimeout(timer);
566
+ finish();
567
+ });
467
568
  },
468
569
 
469
570
  // End the message queue without closing the raw query
@@ -471,6 +572,42 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
471
572
  try { messageQueue.end(); } catch (e) {}
472
573
  },
473
574
 
575
+ // Runs a command the person typed, in the console, under the console
576
+ // process's identity, then records it in the conversation without a model
577
+ // turn. runOpts.signal stops the command. Resolves with the result (YOKE
578
+ // interface 0.6.0); the transcript entry is appended whether the command
579
+ // finished, timed out or was interrupted.
580
+ runUserShellCommand: function(command, cwd, timeoutMs, maxOutputBytes, runOpts) {
581
+ if (closed) return Promise.reject(new Error("The query is closed."));
582
+ var ac = new AbortController();
583
+ var outer = runOpts && runOpts.signal;
584
+ if (outer) {
585
+ if (outer.aborted) ac.abort();
586
+ else outer.addEventListener("abort", function () { ac.abort(); }, { once: true });
587
+ }
588
+ var recorded = userShell.runShellCommand({
589
+ command: command,
590
+ cwd: cwd,
591
+ timeoutMs: timeoutMs,
592
+ maxOutputBytes: maxOutputBytes,
593
+ env: userShellEnv,
594
+ signal: ac.signal,
595
+ }).then(function (result) {
596
+ // The command ran whatever happens to its record, so a failed append is
597
+ // logged and the result still returned; close() waits on this step.
598
+ try {
599
+ messageQueue.push(buildShellTranscriptMessage(command, result));
600
+ } catch (err) {
601
+ console.warn("[yoke/claude] could not record the command in the conversation:", err && err.message || err);
602
+ }
603
+ return result;
604
+ }).finally(function () {
605
+ shellRuns.delete(ac);
606
+ });
607
+ shellRuns.set(ac, recorded.catch(function () {}));
608
+ return recorded;
609
+ },
610
+
474
611
  // Claude SDK specific: rewind files to a previous state
475
612
  rewindFiles: function(uuid, opts) {
476
613
  if (rawQuery && typeof rawQuery.rewindFiles === "function") {
@@ -807,6 +944,10 @@ function serializeWorkerValue(value, seen) {
807
944
  // Wraps worker IPC into the same async iterable + control interface as the
808
945
  // in-process QueryHandle. This allows processQueryStream to iterate a worker
809
946
  // query identically to an in-process query.
947
+ //
948
+ // It has no runUserShellCommand: a worker exists only in OS-user mode, where a
949
+ // command the person typed must not run as the daemon's user, so the method stays
950
+ // absent and a caller sees an adapter without it.
810
951
 
811
952
  function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool) {
812
953
  // Async iterable state
@@ -822,6 +963,29 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
822
963
  // no prototype to answer for "constructor" or "__proto__".
823
964
  var pendingRewinds = Object.create(null);
824
965
 
966
+ // Same correlation for cancelQueuedMessage. A query that ends first leaves
967
+ // nothing to cancel, so its pending requests reject (failPendingCancels).
968
+ var pendingCancels = Object.create(null);
969
+
970
+ function failPendingCancels() {
971
+ Object.keys(pendingCancels).forEach(function (requestId) {
972
+ var pending = pendingCancels[requestId];
973
+ delete pendingCancels[requestId];
974
+ pending.reject(new Error("The Claude query ended before the message could be cancelled"));
975
+ });
976
+ }
977
+
978
+ // Same correlation for interruptKeepingQueued.
979
+ var pendingInterrupts = Object.create(null);
980
+
981
+ function failPendingInterrupts() {
982
+ Object.keys(pendingInterrupts).forEach(function (requestId) {
983
+ var pending = pendingInterrupts[requestId];
984
+ delete pendingInterrupts[requestId];
985
+ pending.reject(new Error("The Claude query ended before the interrupt was answered"));
986
+ });
987
+ }
988
+
825
989
  // lr-f22787: same correlation pattern as pendingRewinds, for setModel.
826
990
  // Without this, an invalid/unentitled model ID sent to a worker session
827
991
  // failed silently — the worker-side handleSetModel() (claude-worker.js)
@@ -941,7 +1105,9 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
941
1105
  break;
942
1106
 
943
1107
  // The worker stopped waiting for a prompt; ending it daemon-side keeps
944
- // a card from offering an answer that can no longer take effect.
1108
+ // a card from offering an answer that can no longer take effect. The
1109
+ // worker no longer sends this on its own (the prompt registry bounds
1110
+ // an unanswered prompt); the mapping stays for a worker that does.
945
1111
  case "permission_expired":
946
1112
  abortPrompt("permission:" + msg.requestId, "expired");
947
1113
  break;
@@ -1040,6 +1206,26 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
1040
1206
  }
1041
1207
  break;
1042
1208
 
1209
+ case "cancel_message_response": {
1210
+ var cp = pendingCancels[msg.requestId];
1211
+ if (cp) {
1212
+ delete pendingCancels[msg.requestId];
1213
+ if (msg.error) cp.reject(new Error(msg.error));
1214
+ else cp.resolve(msg.cancelled === true);
1215
+ }
1216
+ break;
1217
+ }
1218
+
1219
+ case "interrupt_response": {
1220
+ var ip = pendingInterrupts[msg.requestId];
1221
+ if (ip) {
1222
+ delete pendingInterrupts[msg.requestId];
1223
+ if (msg.error) ip.reject(new Error(msg.error));
1224
+ else ip.resolve(receiptOf(msg.receipt));
1225
+ }
1226
+ break;
1227
+ }
1228
+
1043
1229
  case "rewind_files_response": {
1044
1230
  var rp = pendingRewinds[msg.requestId];
1045
1231
  if (rp) {
@@ -1056,6 +1242,8 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
1056
1242
  // The worker's query is over; nothing in it waits for an answer.
1057
1243
  abortAllPrompts();
1058
1244
  failPendingEfforts();
1245
+ failPendingCancels();
1246
+ failPendingInterrupts();
1059
1247
  endIter();
1060
1248
  break;
1061
1249
 
@@ -1066,6 +1254,7 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
1066
1254
  worker._queryEnded = true;
1067
1255
  abortAllPrompts();
1068
1256
  failPendingEfforts();
1257
+ failPendingCancels();
1069
1258
  var err = new Error(msg.error || "Worker query error");
1070
1259
  err.exitCode = msg.exitCode;
1071
1260
  err.stderr = msg.stderr;
@@ -1122,6 +1311,35 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
1122
1311
  worker.send({ type: "push_message", content: buildUserMessage(text, images, initiator, messageId) });
1123
1312
  },
1124
1313
 
1314
+ // Same contract as the in-process handle, answered by the worker, which
1315
+ // holds the SDK query. Correlated by requestId like rewindFiles.
1316
+ cancelQueuedMessage: function(messageId) {
1317
+ var requestId = crypto.randomUUID();
1318
+ return new Promise(function(resolve, reject) {
1319
+ pendingCancels[requestId] = { resolve: resolve, reject: reject };
1320
+ try {
1321
+ worker.send({ type: "cancel_message", requestId: requestId, messageId: messageId });
1322
+ } catch (e) {
1323
+ delete pendingCancels[requestId];
1324
+ reject(e);
1325
+ }
1326
+ });
1327
+ },
1328
+
1329
+ // Same contract as the in-process handle, answered by the worker.
1330
+ interruptKeepingQueued: function() {
1331
+ var requestId = crypto.randomUUID();
1332
+ return new Promise(function(resolve, reject) {
1333
+ pendingInterrupts[requestId] = { resolve: resolve, reject: reject };
1334
+ try {
1335
+ worker.send({ type: "interrupt_query", requestId: requestId });
1336
+ } catch (e) {
1337
+ delete pendingInterrupts[requestId];
1338
+ reject(e);
1339
+ }
1340
+ });
1341
+ },
1342
+
1125
1343
  // lr-f22787: correlated by requestId (mirrors rewindFiles below) so the
1126
1344
  // returned promise reflects the worker's real outcome — a rejected
1127
1345
  // model ID rejects this promise instead of resolving immediately
@@ -1666,7 +1884,7 @@ function createClaudeAdapter(opts) {
1666
1884
  sdkOptions.env = turnInitiator.claudeProcessEnv(process.env, queryOpts.runtimeEnv, queryOpts.identity, queryOpts.sessionRef);
1667
1885
 
1668
1886
  var rawQuery = sdk.query({ prompt: mq, options: sdkOptions });
1669
- return createQueryHandle(rawQuery, mq, ac);
1887
+ return createQueryHandle(rawQuery, mq, ac, sdkOptions.env);
1670
1888
  },
1671
1889
 
1672
1890
  // --- Session management ---
@@ -1955,5 +2173,6 @@ module.exports = {
1955
2173
  // the worker IPC relay over a fake worker.
1956
2174
  _test_createQueryHandle: createQueryHandle,
1957
2175
  _test_createWorkerQueryHandle: createWorkerQueryHandle,
2176
+ _test_buildShellTranscriptMessage: buildShellTranscriptMessage,
1958
2177
  };
1959
2178
 
@@ -7,6 +7,9 @@
7
7
  // beta switches or subagents, and no permission modes beyond the approval
8
8
  // policy Codex owns, so those are declared off and the UI shows them disabled.
9
9
  //
10
+ // steering is declared on and narrowed by the adapter's init to what the running
11
+ // app-server answers to a probe of turn/steer (never to its version).
12
+ //
10
13
  // Rewinding a thread in place (rewind, rollback) is not offered: the app-server
11
14
  // call the console used was removed from the supported releases, and its
12
15
  // replacement cannot be made safe against a turn appended while it runs.
@@ -29,11 +32,13 @@ function codexCapabilities() {
29
32
  contextCompacting: false,
30
33
  mcpPanel: true,
31
34
  backgroundTasks: false,
32
- steering: false,
35
+ steering: true,
33
36
  agentInjection: false,
37
+ queuedMessageCancel: false,
34
38
  executionPolicy: true,
35
39
  toolPolicy: ["ask", "allow-all"],
36
40
  permissionModes: [],
41
+ additiveSettings: false,
37
42
  };
38
43
  }
39
44
 
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+
3
+ // A command the person typed, run through the app-server's thread/shellCommand.
4
+ //
5
+ // The app-server runs it as a turn of its own on the thread (a standalone one
6
+ // when the thread is idle) and reports it only as turn and item notifications;
7
+ // the request itself answers {}. The console shows the command as its own result
8
+ // and keeps those notifications out of the event stream, so this module decides,
9
+ // for every notification, whether it belongs to the command. The rule is one:
10
+ // a notification is the command's only when its turn id is the command's turn
11
+ // id. A model turn's start, items and end carry another id and always go on to
12
+ // the stream; the end of an earlier command's turn that arrives late is matched
13
+ // by its id too, never by how many are expected.
14
+
15
+ var userShell = require("../user-shell");
16
+
17
+ // How long to wait for the command's turn to end after its item completed, and
18
+ // for the turn an interrupt was asked of to end, before giving up.
19
+ var TURN_GRACE_MS = 3000;
20
+ // How far past its timeout a command whose turn never started is given up on.
21
+ var WATCHDOG_GRACE_MS = 20000;
22
+ // How long a settled command's late turn ending is still taken as its own.
23
+ var LATE_END_WINDOW_MS = 30000;
24
+
25
+ var MODEL_TURN_RUNNING = "Not run: the agent is working. Try again when its turn has ended.";
26
+
27
+ function refusedResult(message) {
28
+ return { exitCode: null, durationMs: 0, output: message, truncated: false, timedOut: false, interrupted: false };
29
+ }
30
+
31
+ function turnIdOf(params) {
32
+ var id = (params.turn && params.turn.id) || params.turnId;
33
+ return id ? String(id) : null;
34
+ }
35
+
36
+ function isCommandItem(item) {
37
+ return !!item && (item.type === "commandExecution" || item.type === "command_execution");
38
+ }
39
+
40
+ function itemOutput(item) {
41
+ var text = item.aggregatedOutput != null ? item.aggregatedOutput
42
+ : item.aggregated_output != null ? item.aggregated_output
43
+ : item.output != null ? item.output : "";
44
+ return typeof text === "string" ? text : "";
45
+ }
46
+
47
+ /**
48
+ * @param {object} deps
49
+ * @param {function(string, object, number): Promise} deps.send JSON-RPC request to the app-server
50
+ * @param {function(): boolean} deps.isReady the app-server is running
51
+ * @param {function(): ?string} deps.threadId
52
+ * @param {function(): ?string} deps.activeTurnId the model turn running now, if any
53
+ */
54
+ function createUserShellRunner(deps) {
55
+ var current = null;
56
+ // Turn id of a settled command's turn whose ending is still to arrive -> the
57
+ // time after which it is no longer waited for.
58
+ var lateEnds = {};
59
+
60
+ function sweepLateEnds() {
61
+ var now = Date.now();
62
+ Object.keys(lateEnds).forEach(function (id) {
63
+ if (lateEnds[id] < now) delete lateEnds[id];
64
+ });
65
+ }
66
+
67
+ function clearTimers(run) {
68
+ clearTimeout(run.watchdog);
69
+ clearTimeout(run.graceTimer);
70
+ clearTimeout(run.interruptTimer);
71
+ if (run.signal) run.signal.removeEventListener("abort", run.onAbort);
72
+ }
73
+
74
+ function sendInterrupt() {
75
+ if (!deps.threadId() || !deps.isReady()) return;
76
+ deps.send("turn/interrupt", { threadId: deps.threadId() }, 5000).catch(function (err) {
77
+ console.warn("[yoke/codex] turn/interrupt for a shell command failed:", err && err.message || err);
78
+ });
79
+ }
80
+
81
+ function settle(run, how) {
82
+ if (current !== run || run.settled) return;
83
+ run.settled = true;
84
+ current = null;
85
+ clearTimers(run);
86
+ // A standalone turn that started and has not ended will still end, and that
87
+ // ending is this command's.
88
+ if (run.turnId && !run.turnEnded) lateEnds[run.turnId] = Date.now() + LATE_END_WINDOW_MS;
89
+ sweepLateEnds();
90
+ var elapsed = Date.now() - run.startedAt;
91
+ var text = run.output;
92
+ if (how.failure) text = (text ? text + "\n" : "") + how.failure;
93
+ var capped = userShell.capText(text, run.maxBytes);
94
+ var timedOut = !!how.timedOut ||
95
+ (run.itemStatus === "failed" && run.exitCode === null && !run.interruptSent && elapsed >= run.timeoutMs - 2000);
96
+ run.resolve({
97
+ exitCode: run.exitCode,
98
+ durationMs: typeof run.durationMs === "number" ? run.durationMs : elapsed,
99
+ output: capped.output,
100
+ truncated: capped.truncated,
101
+ timedOut: timedOut,
102
+ interrupted: !!how.interrupted,
103
+ });
104
+ }
105
+
106
+ // turn/interrupt only reaches a turn that has started, and only the turn the
107
+ // command is in can be named, so before its id is known the request is held.
108
+ function interruptNow(run) {
109
+ run.interruptSent = true;
110
+ sendInterrupt();
111
+ // Reported as interrupted only when the turn is then seen to end; if it
112
+ // does not, the command may still be running and the result says so.
113
+ clearTimeout(run.interruptTimer);
114
+ run.interruptTimer = setTimeout(function () { settle(run, { interrupted: false }); }, TURN_GRACE_MS);
115
+ }
116
+
117
+ function requestInterrupt(run) {
118
+ if (run.settled || run.abortRequested) return;
119
+ run.abortRequested = true;
120
+ // Before the turn starts the request is held, with no timer: it is sent when
121
+ // this run's turn/started arrives, or the run settles timed out.
122
+ if (run.turnId) interruptNow(run);
123
+ }
124
+
125
+ function consumeLateEnd(params) {
126
+ sweepLateEnds();
127
+ var id = turnIdOf(params);
128
+ if (!id || lateEnds[id] === undefined) return false;
129
+ var until = lateEnds[id];
130
+ delete lateEnds[id];
131
+ return Date.now() <= until;
132
+ }
133
+
134
+ function consumeItem(run, method, params) {
135
+ if (!run.turnId) return false;
136
+ var item = params.item;
137
+ var itemTurn = turnIdOf(params);
138
+ if (itemTurn !== null && itemTurn !== run.turnId) return false;
139
+ if (isCommandItem(item)) {
140
+ if (!run.itemId) run.itemId = item.id;
141
+ if (item.id !== run.itemId) return true;
142
+ var seen = itemOutput(item);
143
+ if (seen) run.output = seen;
144
+ if (method === "item/completed") {
145
+ run.itemStatus = item.status || null;
146
+ var code = item.exitCode != null ? item.exitCode : item.exit_code;
147
+ run.exitCode = typeof code === "number" ? code : null;
148
+ var ms = item.durationMs != null ? item.durationMs : item.duration_ms;
149
+ if (typeof ms === "number") run.durationMs = ms;
150
+ // The turn ends right after its command; if that ending never comes,
151
+ // the command's result is still known.
152
+ run.graceTimer = setTimeout(function () { settle(run, { interrupted: run.interruptSent }); }, TURN_GRACE_MS);
153
+ }
154
+ return true;
155
+ }
156
+ return true;
157
+ }
158
+
159
+ /**
160
+ * True when the notification belongs to the running command (or to a settled
161
+ * one's late turn ending) and must not reach the event stream.
162
+ */
163
+ function consume(method, params) {
164
+ var isEnd = method === "turn/completed" || method === "turn/failed";
165
+ if (isEnd && consumeLateEnd(params)) return true;
166
+ var run = current;
167
+
168
+ if (method === "turn/started") {
169
+ var startedId = turnIdOf(params);
170
+ if (!run) return false;
171
+ // Another turn starting once the command's is known is not the command's.
172
+ if (run.turnId || !startedId) return false;
173
+ // The first turn to start after the request is bound as the command's.
174
+ // That holds because the console starts a model turn only from its own
175
+ // sends, and the busy state that gates this method (refuses a command while
176
+ // a turn runs, holds chat while one runs) leaves no other turn able to start
177
+ // in this window.
178
+ run.turnId = startedId;
179
+ if (run.abortRequested) interruptNow(run);
180
+ return true;
181
+ }
182
+
183
+ if (!run) return false;
184
+
185
+ if (isEnd) {
186
+ // Only the command's own turn ending settles it; a model turn's end has
187
+ // another id and is delivered.
188
+ if (!run.turnId || turnIdOf(params) !== run.turnId) return false;
189
+ run.turnEnded = true;
190
+ var status = params.turn && params.turn.status;
191
+ var failure = method === "turn/failed" ? ((params.error && params.error.message) || "The command's turn failed") : null;
192
+ settle(run, { interrupted: run.interruptSent || status === "interrupted", failure: failure });
193
+ return true;
194
+ }
195
+
196
+ if (method.indexOf("item/") !== 0) return false;
197
+ return consumeItem(run, method, params);
198
+ }
199
+
200
+ /**
201
+ * Sends the command and resolves with its result. Rejects when the app-server
202
+ * refuses the request.
203
+ */
204
+ function run(command, timeoutMs, maxOutputBytes, signal) {
205
+ if (!deps.threadId() || !deps.isReady()) {
206
+ return Promise.reject(new Error("There is no running Codex thread to run the command in."));
207
+ }
208
+ if (current) return Promise.reject(new Error("A shell command is already running in this thread."));
209
+ // The app-server would run the command inside the model's turn, where it
210
+ // cannot be told from the model's own commands or stopped without stopping
211
+ // the turn, so it is refused while a model turn runs.
212
+ if (deps.activeTurnId()) return Promise.resolve(refusedResult(MODEL_TURN_RUNNING));
213
+ return new Promise(function (resolve, reject) {
214
+ var r = {
215
+ resolve: resolve,
216
+ command: command,
217
+ startedAt: Date.now(),
218
+ timeoutMs: timeoutMs,
219
+ maxBytes: maxOutputBytes,
220
+ signal: signal || null,
221
+ turnId: null,
222
+ itemId: null,
223
+ itemStatus: null,
224
+ output: "",
225
+ exitCode: null,
226
+ durationMs: null,
227
+ turnEnded: false,
228
+ interruptSent: false,
229
+ abortRequested: false,
230
+ settled: false,
231
+ watchdog: null,
232
+ graceTimer: null,
233
+ interruptTimer: null,
234
+ onAbort: null,
235
+ };
236
+ current = r;
237
+ r.watchdog = setTimeout(function () {
238
+ sendInterrupt();
239
+ settle(r, { timedOut: true });
240
+ }, timeoutMs + WATCHDOG_GRACE_MS);
241
+ r.onAbort = function () { requestInterrupt(r); };
242
+ if (r.signal) {
243
+ if (r.signal.aborted) r.onAbort();
244
+ else r.signal.addEventListener("abort", r.onAbort, { once: true });
245
+ }
246
+ deps.send("thread/shellCommand", { threadId: deps.threadId(), command: command, timeoutMs: timeoutMs }, 15000).catch(function (err) {
247
+ if (current !== r || r.settled) return;
248
+ r.settled = true;
249
+ current = null;
250
+ clearTimers(r);
251
+ reject(err);
252
+ });
253
+ });
254
+ }
255
+
256
+ return {
257
+ run: run,
258
+ consume: consume,
259
+ isRunning: function () { return !!current; },
260
+ // The query is being aborted or closed: stop the running command.
261
+ interruptRunning: function () { if (current) requestInterrupt(current); },
262
+ };
263
+ }
264
+
265
+ module.exports = { createUserShellRunner: createUserShellRunner, refusedResult: refusedResult };
@@ -26,6 +26,12 @@ registry.register({
26
26
  checkAuth: authChecks.checkCodexAuth,
27
27
  installHint: "Install the Codex CLI (npm install -g @openai/codex), then sign in.",
28
28
  loginCommand: "codex login --device-auth",
29
+ // Device authorization: a short URL, and a one-time code the agent displays
30
+ // for the user to type on that page. Nothing is pasted back into the terminal.
31
+ loginPatterns: {
32
+ url: "https:\\/\\/[^\\s'\"\\]>)}{]+",
33
+ userCode: "one-time code[\\s\\S]{0,160}?\\s+([A-Z0-9]{4,}(?:-[A-Z0-9]{3,})+)",
34
+ },
29
35
  // The app-server is not started per OS user, so under per-user isolation the
30
36
  // agent is disabled (yoke/index.js, install-probe.js) and never started.
31
37
  osUsersSupported: false,
@@ -40,6 +46,7 @@ registry.register({
40
46
  capabilityReasons: {
41
47
  rewind: "Rewind is not available for Codex sessions yet",
42
48
  rollback: "Rewind is not available for Codex sessions yet",
49
+ steering: "This Codex cannot take a message while it is working",
43
50
  },
44
51
  capabilities: codexCapabilities(),
45
52
  createAdapter: function(opts) { return require("./codex").createCodexAdapter(opts); },