@clagentic/console 1.12.0-beta.2 → 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 (127) hide show
  1. package/LICENSES/README.md +5 -0
  2. package/bin/cli.js +4 -2
  3. package/lib/agent-roster-ws.js +84 -0
  4. package/lib/agent-roster.js +312 -0
  5. package/lib/auth-required-notify.js +42 -0
  6. package/lib/build-sha.json +2 -2
  7. package/lib/build-update-notify.js +45 -0
  8. package/lib/build-update-offer.js +3 -4
  9. package/lib/build-update-standing.js +34 -14
  10. package/lib/cli/session-subcommands.js +26 -8
  11. package/lib/client-address.js +44 -0
  12. package/lib/daemon.js +25 -10
  13. package/lib/idle-compaction-setting.js +203 -0
  14. package/lib/mcp-bridge-credential.js +41 -0
  15. package/lib/notification-prefs.js +16 -22
  16. package/lib/notify/core.js +53 -18
  17. package/lib/notify/payload.js +2 -3
  18. package/lib/notify/type-registry.js +17 -0
  19. package/lib/notify/types.js +38 -1
  20. package/lib/outbound-access.js +12 -1
  21. package/lib/outbound-entry.js +8 -1
  22. package/lib/project-connection.js +9 -8
  23. package/lib/project-filesystem.js +23 -0
  24. package/lib/project-loop.js +16 -19
  25. package/lib/project-notifications.js +68 -7
  26. package/lib/project-sessions.js +9 -0
  27. package/lib/project-user-mention.js +22 -34
  28. package/lib/project-user-message.js +208 -4
  29. package/lib/project-user-shell.js +298 -0
  30. package/lib/project.js +26 -4
  31. package/lib/prompt-answer.js +145 -0
  32. package/lib/prompt-expiry.js +50 -0
  33. package/lib/prompt-registry.js +24 -1
  34. package/lib/prompt-source.js +16 -0
  35. package/lib/public/app.js +31 -2
  36. package/lib/public/css/agent-messages.css +96 -0
  37. package/lib/public/css/agent-roster.css +93 -0
  38. package/lib/public/css/diagnostics.css +1 -1
  39. package/lib/public/css/input.css +20 -141
  40. package/lib/public/css/login-panel.css +73 -0
  41. package/lib/public/css/menus.css +2 -2
  42. package/lib/public/css/sidebar.css +11 -0
  43. package/lib/public/css/team-panel.css +1 -6
  44. package/lib/public/css/team-view.css +101 -0
  45. package/lib/public/css/title-bar.css +10 -0
  46. package/lib/public/css/user-shell.css +144 -0
  47. package/lib/public/index.html +41 -7
  48. package/lib/public/modules/agent-avatar-picker.js +162 -0
  49. package/lib/public/modules/agent-avatar.js +153 -0
  50. package/lib/public/modules/agent-messages.js +285 -0
  51. package/lib/public/modules/agent-roster.js +157 -0
  52. package/lib/public/modules/app-connection.js +12 -0
  53. package/lib/public/modules/app-messages.js +55 -16
  54. package/lib/public/modules/app-notifications.js +59 -29
  55. package/lib/public/modules/app-panels.js +26 -3
  56. package/lib/public/modules/app-rate-limit.js +8 -165
  57. package/lib/public/modules/app-rendering.js +22 -7
  58. package/lib/public/modules/collapsible-text.js +33 -18
  59. package/lib/public/modules/compaction-state.js +34 -0
  60. package/lib/public/modules/custom-icons.js +23 -5
  61. package/lib/public/modules/diagnostics.js +52 -55
  62. package/lib/public/modules/injected-identity.js +24 -21
  63. package/lib/public/modules/input.js +176 -15
  64. package/lib/public/modules/login-panel.js +136 -0
  65. package/lib/public/modules/login-parser.js +73 -0
  66. package/lib/public/modules/login-tab.js +66 -0
  67. package/lib/public/modules/notifications.js +9 -1
  68. package/lib/public/modules/notify-client.js +114 -21
  69. package/lib/public/modules/pending-term-request.js +30 -0
  70. package/lib/public/modules/project-icon.js +22 -2
  71. package/lib/public/modules/queued-button.js +11 -0
  72. package/lib/public/modules/scheduled-input-actions.js +12 -4
  73. package/lib/public/modules/scheduled-outbox.js +230 -0
  74. package/lib/public/modules/send-now.js +200 -0
  75. package/lib/public/modules/server-settings.js +47 -1
  76. package/lib/public/modules/shell-card.js +76 -0
  77. package/lib/public/modules/shell-line.js +49 -0
  78. package/lib/public/modules/shell-queue.js +253 -0
  79. package/lib/public/modules/shell-settings-controls.js +76 -0
  80. package/lib/public/modules/sidebar-mobile.js +3 -3
  81. package/lib/public/modules/sidebar-sessions.js +8 -0
  82. package/lib/public/modules/sidebar-users.js +5 -7
  83. package/lib/public/modules/team-panel.js +30 -88
  84. package/lib/public/modules/team-view.js +211 -0
  85. package/lib/public/modules/terminal-links.js +18 -0
  86. package/lib/public/modules/terminal.js +65 -4
  87. package/lib/public/modules/tools.js +19 -0
  88. package/lib/public/modules/user-shell.js +824 -0
  89. package/lib/public/notify-sw-logic.js +35 -83
  90. package/lib/public/notify-target.js +70 -10
  91. package/lib/public/style.css +5 -0
  92. package/lib/public/sw.js +7 -3
  93. package/lib/queued-chat.js +392 -0
  94. package/lib/scheduled-input/ws.js +67 -9
  95. package/lib/sdk-bridge.js +122 -43
  96. package/lib/sdk-message-processor.js +46 -39
  97. package/lib/server-auth.js +6 -4
  98. package/lib/server-dm.js +11 -20
  99. package/lib/server-settings.js +39 -1
  100. package/lib/server.js +83 -19
  101. package/lib/session-directory.js +33 -8
  102. package/lib/session-end.js +97 -0
  103. package/lib/session-input-ipc.js +26 -0
  104. package/lib/session-input.js +176 -9
  105. package/lib/session-resume.js +1 -0
  106. package/lib/session-settings-file.js +53 -0
  107. package/lib/sessions.js +49 -5
  108. package/lib/team-traffic-ws.js +68 -0
  109. package/lib/team-traffic.js +318 -0
  110. package/lib/usage-store.js +7 -0
  111. package/lib/user-shell-settings.js +105 -0
  112. package/lib/ws-schema.js +27 -4
  113. package/lib/yoke/adapters/claude-capabilities.js +2 -0
  114. package/lib/yoke/adapters/claude-vendor.js +6 -0
  115. package/lib/yoke/adapters/claude-worker.js +39 -11
  116. package/lib/yoke/adapters/claude.js +218 -6
  117. package/lib/yoke/adapters/codex-capabilities.js +6 -1
  118. package/lib/yoke/adapters/codex-user-shell.js +265 -0
  119. package/lib/yoke/adapters/codex-vendor.js +7 -0
  120. package/lib/yoke/adapters/codex.js +186 -52
  121. package/lib/yoke/codex-app-server.js +8 -2
  122. package/lib/yoke/interface.js +54 -1
  123. package/lib/yoke/mcp-bridge-server.js +12 -8
  124. package/lib/yoke/registry.js +32 -0
  125. package/lib/yoke/user-shell.js +224 -0
  126. package/package.json +1 -1
  127. 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) {
@@ -380,10 +392,48 @@ function buildUserMessage(text, images, initiator, messageId) {
380
392
  return message;
381
393
  }
382
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
+
383
423
  // --- QueryHandle ---
384
424
  // Wraps a raw SDK query object with the YOKE QueryHandle interface.
385
425
  // Events are flattened via flattenEvent before yielding.
386
- 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
+
387
437
  var handle = {
388
438
  // Opaque adapter state (null for in-process queries)
389
439
  _adapterState: null,
@@ -405,6 +455,29 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
405
455
  messageQueue.push(buildUserMessage(text, images, initiator, messageId));
406
456
  },
407
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
+
408
481
  setModel: function(model) {
409
482
  if (rawQuery && typeof rawQuery.setModel === "function") {
410
483
  return rawQuery.setModel(model);
@@ -461,16 +534,37 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
461
534
  // for a capability nothing needs per-query.
462
535
 
463
536
  abort: function() {
537
+ stopShellRuns();
464
538
  if (abortController) {
465
539
  try { abortController.abort(); } catch (e) {}
466
540
  }
467
541
  },
468
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.
469
549
  close: function() {
470
- try { messageQueue.end(); } catch (e) {}
471
- if (rawQuery && typeof rawQuery.close === "function") {
472
- 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
+ }
473
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
+ });
474
568
  },
475
569
 
476
570
  // End the message queue without closing the raw query
@@ -478,6 +572,42 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
478
572
  try { messageQueue.end(); } catch (e) {}
479
573
  },
480
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
+
481
611
  // Claude SDK specific: rewind files to a previous state
482
612
  rewindFiles: function(uuid, opts) {
483
613
  if (rawQuery && typeof rawQuery.rewindFiles === "function") {
@@ -814,6 +944,10 @@ function serializeWorkerValue(value, seen) {
814
944
  // Wraps worker IPC into the same async iterable + control interface as the
815
945
  // in-process QueryHandle. This allows processQueryStream to iterate a worker
816
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.
817
951
 
818
952
  function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool) {
819
953
  // Async iterable state
@@ -829,6 +963,29 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
829
963
  // no prototype to answer for "constructor" or "__proto__".
830
964
  var pendingRewinds = Object.create(null);
831
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
+
832
989
  // lr-f22787: same correlation pattern as pendingRewinds, for setModel.
833
990
  // Without this, an invalid/unentitled model ID sent to a worker session
834
991
  // failed silently — the worker-side handleSetModel() (claude-worker.js)
@@ -948,7 +1105,9 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
948
1105
  break;
949
1106
 
950
1107
  // The worker stopped waiting for a prompt; ending it daemon-side keeps
951
- // 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.
952
1111
  case "permission_expired":
953
1112
  abortPrompt("permission:" + msg.requestId, "expired");
954
1113
  break;
@@ -1047,6 +1206,26 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
1047
1206
  }
1048
1207
  break;
1049
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
+
1050
1229
  case "rewind_files_response": {
1051
1230
  var rp = pendingRewinds[msg.requestId];
1052
1231
  if (rp) {
@@ -1063,6 +1242,8 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
1063
1242
  // The worker's query is over; nothing in it waits for an answer.
1064
1243
  abortAllPrompts();
1065
1244
  failPendingEfforts();
1245
+ failPendingCancels();
1246
+ failPendingInterrupts();
1066
1247
  endIter();
1067
1248
  break;
1068
1249
 
@@ -1073,6 +1254,7 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
1073
1254
  worker._queryEnded = true;
1074
1255
  abortAllPrompts();
1075
1256
  failPendingEfforts();
1257
+ failPendingCancels();
1076
1258
  var err = new Error(msg.error || "Worker query error");
1077
1259
  err.exitCode = msg.exitCode;
1078
1260
  err.stderr = msg.stderr;
@@ -1129,6 +1311,35 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
1129
1311
  worker.send({ type: "push_message", content: buildUserMessage(text, images, initiator, messageId) });
1130
1312
  },
1131
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
+
1132
1343
  // lr-f22787: correlated by requestId (mirrors rewindFiles below) so the
1133
1344
  // returned promise reflects the worker's real outcome — a rejected
1134
1345
  // model ID rejects this promise instead of resolving immediately
@@ -1673,7 +1884,7 @@ function createClaudeAdapter(opts) {
1673
1884
  sdkOptions.env = turnInitiator.claudeProcessEnv(process.env, queryOpts.runtimeEnv, queryOpts.identity, queryOpts.sessionRef);
1674
1885
 
1675
1886
  var rawQuery = sdk.query({ prompt: mq, options: sdkOptions });
1676
- return createQueryHandle(rawQuery, mq, ac);
1887
+ return createQueryHandle(rawQuery, mq, ac, sdkOptions.env);
1677
1888
  },
1678
1889
 
1679
1890
  // --- Session management ---
@@ -1962,5 +2173,6 @@ module.exports = {
1962
2173
  // the worker IPC relay over a fake worker.
1963
2174
  _test_createQueryHandle: createQueryHandle,
1964
2175
  _test_createWorkerQueryHandle: createWorkerQueryHandle,
2176
+ _test_buildShellTranscriptMessage: buildShellTranscriptMessage,
1965
2177
  };
1966
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); },