@skrr-ai/cli 0.1.208 → 0.1.210

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 (105) hide show
  1. package/dist/base-command.js +2 -1
  2. package/dist/commands/agent/message/no-reply.js +1 -1
  3. package/dist/commands/agent/message/react.d.ts +23 -0
  4. package/dist/commands/agent/message/react.js +128 -0
  5. package/dist/commands/agent/message/resolve.js +1 -1
  6. package/dist/commands/agent/message/retract.js +1 -1
  7. package/dist/commands/agent/message/send.d.ts +8 -13
  8. package/dist/commands/agent/message/send.js +60 -28
  9. package/dist/commands/agents/access/approve.js +1 -1
  10. package/dist/commands/agents/access/deny.js +1 -1
  11. package/dist/commands/agents/access/list.js +3 -1
  12. package/dist/commands/agents/access/reach.js +1 -1
  13. package/dist/commands/agents/access/revoke.js +1 -1
  14. package/dist/commands/agents/always-on/recovery-review.d.ts +10 -0
  15. package/dist/commands/agents/always-on/recovery-review.js +45 -0
  16. package/dist/commands/agents/chat.d.ts +22 -0
  17. package/dist/commands/agents/chat.js +400 -90
  18. package/dist/commands/agents/import.js +3 -3
  19. package/dist/commands/agents/manager/status.js +7 -6
  20. package/dist/commands/agents/not-for-task.d.ts +24 -0
  21. package/dist/commands/agents/not-for-task.js +64 -0
  22. package/dist/commands/agents/schedule-overview.d.ts +20 -0
  23. package/dist/commands/agents/schedule-overview.js +35 -2
  24. package/dist/commands/agents/shared-memory.js +1 -1
  25. package/dist/commands/agents/stop.d.ts +23 -0
  26. package/dist/commands/agents/stop.js +61 -0
  27. package/dist/commands/agents/update.d.ts +7 -0
  28. package/dist/commands/agents/update.js +45 -2
  29. package/dist/commands/convos/messages.js +5 -0
  30. package/dist/commands/convos/transcript.js +2 -2
  31. package/dist/commands/daemon/logs.d.ts +3 -1
  32. package/dist/commands/daemon/logs.js +6 -2
  33. package/dist/commands/dm/work.js +38 -9
  34. package/dist/commands/duties/advance-next.js +1 -1
  35. package/dist/commands/duties/preflight.js +17 -13
  36. package/dist/commands/duties/show.js +5 -0
  37. package/dist/commands/followups/watch-pr.js +2 -1
  38. package/dist/commands/harnesses/evaluations/evidence.js +2 -2
  39. package/dist/commands/harnesses/evaluations/grant.js +1 -1
  40. package/dist/commands/harnesses/evaluations/revoke.js +1 -1
  41. package/dist/commands/harnesses/evaluations/show.js +1 -1
  42. package/dist/commands/harnesses/rollouts/grant.js +1 -1
  43. package/dist/commands/harnesses/rollouts/revoke.js +1 -1
  44. package/dist/commands/machines/hosted/identity-evaluations/revoke.js +1 -1
  45. package/dist/commands/machines/hosted/identity-evaluations/show.js +1 -1
  46. package/dist/commands/memory/consolidation/undo.js +1 -0
  47. package/dist/commands/messages/list.js +9 -1
  48. package/dist/commands/slack/mutes.js +1 -1
  49. package/dist/commands/slack/unmute.js +1 -1
  50. package/dist/commands/tasks/actionability.js +1 -0
  51. package/dist/commands/tasks/ask.d.ts +2 -0
  52. package/dist/commands/tasks/ask.js +7 -1
  53. package/dist/commands/tasks/bulk-update.js +12 -0
  54. package/dist/commands/tasks/deliverable/add.d.ts +2 -0
  55. package/dist/commands/tasks/deliverable/add.js +25 -6
  56. package/dist/commands/tasks/input/show.d.ts +2 -0
  57. package/dist/commands/tasks/input/show.js +18 -3
  58. package/dist/commands/tasks/list.d.ts +8 -0
  59. package/dist/commands/tasks/list.js +50 -9
  60. package/dist/commands/tasks/move.d.ts +2 -10
  61. package/dist/commands/tasks/move.js +7 -18
  62. package/dist/commands/tasks/resource/add.d.ts +2 -0
  63. package/dist/commands/tasks/resource/add.js +11 -1
  64. package/dist/commands/tasks/result/show.js +19 -7
  65. package/dist/commands/tasks/show.d.ts +4 -3
  66. package/dist/commands/tasks/show.js +20 -8
  67. package/dist/commands/tasks/start.js +35 -16
  68. package/dist/commands/tasks/update.js +3 -0
  69. package/dist/commands/tasks/wait.js +2 -2
  70. package/dist/generated/agent-guides.json +483 -183
  71. package/dist/lib/agent-proactive-baseline.js +4 -1
  72. package/dist/lib/chat-stop.d.ts +17 -0
  73. package/dist/lib/chat-stop.js +70 -0
  74. package/dist/lib/cloud-reply.d.ts +21 -0
  75. package/dist/lib/cloud-reply.js +52 -0
  76. package/dist/lib/duties.d.ts +10 -0
  77. package/dist/lib/duties.js +111 -7
  78. package/dist/lib/duty-ledgers.js +19 -2
  79. package/dist/lib/file-mime.js +8 -0
  80. package/dist/lib/inbound-messages.d.ts +156 -0
  81. package/dist/lib/inbound-messages.js +375 -0
  82. package/dist/lib/message-intent.d.ts +18 -2
  83. package/dist/lib/message-intent.js +23 -1
  84. package/dist/lib/preflight-copy.d.ts +16 -1
  85. package/dist/lib/preflight-copy.js +33 -1
  86. package/dist/lib/space-resolver.d.ts +9 -0
  87. package/dist/lib/space-resolver.js +13 -0
  88. package/dist/lib/task-operations.d.ts +2 -0
  89. package/dist/lib/task-operations.js +28 -4
  90. package/dist/lib/task-preflight.js +1 -0
  91. package/dist/lib/task-review-notice.d.ts +21 -0
  92. package/dist/lib/task-review-notice.js +46 -0
  93. package/dist/lib/task-version.d.ts +9 -0
  94. package/dist/lib/task-version.js +16 -0
  95. package/dist/lib/task-work.js +5 -0
  96. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/credentialEnvelopeBridge.js +6 -1
  97. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/managedWorkRuntime.d.ts +5 -0
  98. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/managedWorkRuntime.js +21 -4
  99. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/credentialEnvelopeBridge.js +45 -15
  100. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/managedWorkRuntime.d.ts +5 -0
  101. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/managedWorkRuntime.js +31 -5
  102. package/dist/node_modules/@skrr-ai/auth-core/package.json +1 -1
  103. package/dist/node_modules/@skrr-ai/data-provider/index.js +12307 -11838
  104. package/oclif.manifest.json +307 -23
  105. package/package.json +6 -2
@@ -15,6 +15,8 @@ exports.inspectTurnCommand = inspectTurnCommand;
15
15
  exports.noOutputFailureMessage = noOutputFailureMessage;
16
16
  exports.agentRunFailureMessage = agentRunFailureMessage;
17
17
  exports.admittedRouting = admittedRouting;
18
+ exports.interactionUnavailableFrom = interactionUnavailableFrom;
19
+ exports.interactionUnavailableWarning = interactionUnavailableWarning;
18
20
  exports.noStreamJsonPayload = noStreamJsonPayload;
19
21
  exports.chatStreamHeaderLines = chatStreamHeaderLines;
20
22
  exports.daemonPinFields = daemonPinFields;
@@ -29,6 +31,8 @@ const agent_home_workspace_1 = require("../../lib/agent-home-workspace");
29
31
  const agentic_stream_1 = require("../../lib/agentic-stream");
30
32
  const web_url_1 = require("../../lib/web-url");
31
33
  const agent_chat_queue_1 = require("../../lib/agent-chat-queue");
34
+ const inbound_messages_1 = require("../../lib/inbound-messages");
35
+ const cloud_reply_1 = require("../../lib/cloud-reply");
32
36
  const local_skills_1 = require("../../lib/local-skills");
33
37
  /**
34
38
  * Exit code for a run the USER stopped watching, by pressing Ctrl-C.
@@ -352,9 +356,30 @@ function admittedRouting(runtime) {
352
356
  };
353
357
  return Object.keys(routing).length ? routing : undefined;
354
358
  }
359
+ function interactionUnavailableFrom(event) {
360
+ if (!event || typeof event !== 'object')
361
+ return undefined;
362
+ const raw = event.interactionUnavailable;
363
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
364
+ return undefined;
365
+ const notice = {};
366
+ for (const key of ['capability', 'reason', 'message', 'provider']) {
367
+ const value = raw[key];
368
+ if (typeof value === 'string' && value.trim())
369
+ notice[key] = value.trim();
370
+ }
371
+ return notice.reason || notice.message ? notice : undefined;
372
+ }
373
+ /** The line a person reads under the answer. The server's own sentence says what to change. */
374
+ function interactionUnavailableWarning(notice) {
375
+ return notice.message
376
+ ? `This turn ran without its managed Task tools. ${notice.message}`
377
+ : `This turn ran without its managed Task tools (${notice.reason}).`;
378
+ }
355
379
  function noStreamJsonPayload(input) {
356
380
  const { result, conversationId, agentId, baseURL, threadRootMessageId } = input;
357
381
  const routing = admittedRouting(input.admittedRuntime);
382
+ const interactionUnavailable = interactionUnavailableFrom(result.lastEvent);
358
383
  return {
359
384
  mode: 'no-stream',
360
385
  executed: true,
@@ -385,6 +410,7 @@ function noStreamJsonPayload(input) {
385
410
  ...(typeof result.lastEvent?.harnessModel === 'string' && result.lastEvent.harnessModel
386
411
  ? { harnessModel: result.lastEvent.harnessModel }
387
412
  : {}),
413
+ ...(interactionUnavailable ? { interactionUnavailable } : {}),
388
414
  ...(result.status === 'failed'
389
415
  ? {
390
416
  failureReason: result.lastEvent?.reason ??
@@ -555,36 +581,43 @@ class AgentsChat extends base_command_1.BaseCommand {
555
581
  'second one. Pass your own key to re-attach to a start from another process: the same ' +
556
582
  'key and prompt return the original turn; a different prompt under it is refused.',
557
583
  }),
584
+ 'after-current': core_1.Flags.boolean({
585
+ description: 'Send this message for after the agent finishes what it is doing, instead of letting ' +
586
+ 'it reach the work in progress. The message is kept on the server at once and starts ' +
587
+ 'its own turn when the running one ends. Needs --conversation or --thread-root.',
588
+ }),
558
589
  'wait-for-idle': core_1.Flags.boolean({
559
- description: 'When the conversation already has a turn running, wait for it to end and then send ' +
560
- 'this turn, instead of failing at once. The CLI asks again every few seconds (at most ' +
561
- 'every 15) under the same --idempotency-key, so it never starts this turn twice. ' +
562
- 'Gives up after --wait-timeout.',
590
+ description: 'The same as --after-current: when the conversation already has a turn running, this ' +
591
+ 'message waits for it to end and then starts its own turn. The CLI follows it until ' +
592
+ 'then and streams the reply, for up to --wait-timeout. Against a server that cannot ' +
593
+ 'keep the message, the CLI asks again every few seconds under the same ' +
594
+ '--idempotency-key instead.',
563
595
  }),
564
596
  'wait-timeout': core_1.Flags.integer({
565
- description: 'Seconds --wait-for-idle waits for the running turn before giving up ' +
566
- `(default ${agent_chat_start_1.DEFAULT_WAIT_FOR_IDLE_TIMEOUT_MS / 1000}). Nothing is sent when it runs out.`,
597
+ description: 'Seconds --wait-for-idle follows the message before giving up ' +
598
+ `(default ${agent_chat_start_1.DEFAULT_WAIT_FOR_IDLE_TIMEOUT_MS / 1000}). The message stays on the server ` +
599
+ 'and is still sent when the running turn ends.',
567
600
  min: 1,
568
601
  dependsOn: ['wait-for-idle'],
569
602
  }),
570
603
  'when-busy': core_1.Flags.string({
571
- description: 'What to do when the conversation already has a turn running: fail (the default), ' +
572
- 'queue the turn on the server so it is sent when the running turn ends, or steer it ' +
573
- 'into the running turn (it waits in the queue when the turn takes no input, and a ' +
574
- 'command never steers). Needs --conversation. A queued turn is followed until it is ' +
575
- 'sent and its reply is streamed, unless --detach.',
604
+ description: 'In an existing conversation a message is never refused because the agent is busy: ' +
605
+ 'the server keeps it and decides how the agent sees it (it reaches the work in ' +
606
+ 'progress, the agent reads it while it works, or it waits for its own turn). ' +
607
+ '`queue` is --after-current; `steer` is the default; `fail` refuses the message when a ' +
608
+ 'turn is running, as older versions did. Needs --conversation or --thread-root.',
576
609
  options: [...agent_chat_queue_1.WHEN_BUSY_MODES],
577
610
  }),
578
611
  detach: core_1.Flags.boolean({
579
- description: 'With --when-busy queue or steer, return once the message is in the queue instead of ' +
580
- 'waiting for it to be sent. See it with `agents queue list --conversation <id>`.',
581
- dependsOn: ['when-busy'],
612
+ description: 'In an existing conversation, return once the server has the message instead of ' +
613
+ 'following it: no wait for its turn to start, nor for what the agent decided while it ' +
614
+ 'worked. See what became of it with `agents queue list --conversation <id>` or in the chat.',
582
615
  }),
583
616
  'queue-timeout': core_1.Flags.integer({
584
- description: 'Seconds --when-busy waits for a queued message to be sent before giving up ' +
585
- `(default ${agent_chat_queue_1.DEFAULT_QUEUE_WAIT_SECONDS}). The message stays queued when it runs out.`,
617
+ description: 'Seconds the CLI follows a message that waits for its own turn before giving up ' +
618
+ `(default ${agent_chat_queue_1.DEFAULT_QUEUE_WAIT_SECONDS}). The message stays on the server when it runs ` +
619
+ 'out and is still sent.',
586
620
  min: 1,
587
- dependsOn: ['when-busy'],
588
621
  }),
589
622
  'repair-wait': core_1.Flags.integer({
590
623
  description: 'Seconds to keep waiting when a platform update restarts the server relaying a turn ' +
@@ -813,10 +846,234 @@ class AgentsChat extends base_command_1.BaseCommand {
813
846
  });
814
847
  }
815
848
  }
849
+ /**
850
+ * Inbound messages: in an existing conversation the message goes to the server's ingress, which
851
+ * keeps it at once and decides how the agent sees it, so a busy agent is never a refusal.
852
+ * Returns the turn to stream, `null` when there is nothing to stream (the message reached the
853
+ * agent another way, or `--detach`), or `'legacy'` when this server has no ingress.
854
+ */
855
+ async sendThroughIngress(input) {
856
+ const conversationId = input.params.conversationId;
857
+ let sent;
858
+ try {
859
+ sent = await (0, agent_chat_start_1.startWithReplay)(() => (0, inbound_messages_1.sendInboundMessage)(input.params, {
860
+ messageId: (0, inbound_messages_1.inboundMessageIdFor)(input.startKey),
861
+ intent: input.intent,
862
+ }), {
863
+ onReplay: ({ attempt, of, waitMs }) => this.warn(`The server did not confirm the message; sending it again in ` +
864
+ `${Math.round(waitMs / 1000)}s (${attempt}/${of}). It keeps the one it already ` +
865
+ `has rather than a second copy.`),
866
+ });
867
+ }
868
+ catch (err) {
869
+ if ((0, inbound_messages_1.ingressMissing)(err))
870
+ return 'legacy';
871
+ if (err instanceof agent_chat_start_1.StartNotConfirmed) {
872
+ this.warn((0, agent_chat_start_1.startNotConfirmedHint)(input.startKey, err.attempts));
873
+ this.handleApiError(err.lastError);
874
+ }
875
+ this.handleApiError(err);
876
+ }
877
+ const { answer } = sent;
878
+ const messageId = answer.message?.messageId ?? sent.messageId;
879
+ const record = {
880
+ messageId,
881
+ conversationId,
882
+ route: answer.route,
883
+ state: answer.delivery?.state ?? null,
884
+ ...(answer.idempotentReplay ? { replayed: true } : {}),
885
+ };
886
+ const sentence = (0, inbound_messages_1.deliverySentence)(answer.delivery) ?? inbound_messages_1.ROUTE_COPY.hold;
887
+ if (input.jsonl)
888
+ (0, agentic_stream_1.writeJsonLine)(process.stdout, { type: 'message.sent', ...record, sentence });
889
+ // A notice on the way, never on stdout unless it is a JSONL event.
890
+ const notice = (type, line, extra = {}) => {
891
+ if (input.jsonl)
892
+ (0, agentic_stream_1.writeJsonLine)(process.stdout, { type, messageId, ...extra, message: line });
893
+ else
894
+ this.warn(line);
895
+ };
896
+ // The command's answer when there is no reply to stream.
897
+ const finish = (extra, lines) => {
898
+ if (input.json) {
899
+ this.printJsonResult({ ...record, delivery: answer.delivery, ...extra });
900
+ }
901
+ else if (!input.jsonl) {
902
+ for (const line of lines)
903
+ this.log(line);
904
+ }
905
+ return null;
906
+ };
907
+ const next = (0, inbound_messages_1.nextAfterSend)(answer);
908
+ switch (next.kind) {
909
+ case 'turn':
910
+ return {
911
+ sessionId: next.sessionId,
912
+ conversationId,
913
+ responseMessageId: next.responseMessageId,
914
+ };
915
+ case 'delivered': {
916
+ const handling = answer.delivery?.handling;
917
+ const hint = (0, inbound_messages_1.notForTaskHint)(this.config.bin, conversationId, messageId, handling?.[handling.length - 1]);
918
+ return finish({ sentence, ...(hint ? { hint } : {}) }, hint ? [sentence, hint] : [sentence]);
919
+ }
920
+ case 'failed':
921
+ return this.failWithCliError({
922
+ message: sentence,
923
+ code: 'MESSAGE_NOT_DELIVERED',
924
+ exit: 1,
925
+ retryable: answer.delivery?.failed?.reason === 'usage_limit',
926
+ details: { ...record, reason: answer.delivery?.failed?.reason ?? null },
927
+ });
928
+ case 'glance': {
929
+ if (input.detach)
930
+ return finish({ sentence }, [sentence]);
931
+ if (!input.json && !input.jsonl)
932
+ this.warn(sentence);
933
+ const outcome = await (0, inbound_messages_1.waitForGlance)(conversationId, messageId);
934
+ const handled = outcome.handling
935
+ ? (0, inbound_messages_1.handlingSentence)(outcome.handling)
936
+ : 'Your agent has not decided about this yet. It has the message; its answer will be ' +
937
+ 'in the chat.';
938
+ if (input.jsonl) {
939
+ (0, agentic_stream_1.writeJsonLine)(process.stdout, {
940
+ type: 'message.handled',
941
+ messageId,
942
+ handling: outcome.handling,
943
+ reply: outcome.reply,
944
+ message: handled,
945
+ });
946
+ }
947
+ // A reply from the cloud says so before its words: it could not see the machine's files.
948
+ const label = outcome.reply?.cloudReply
949
+ ? (0, cloud_reply_1.cloudReplyLine)({ communication: { cloudReply: outcome.reply.cloudReply } })
950
+ : null;
951
+ const taskHint = (0, inbound_messages_1.notForTaskHint)(this.config.bin, conversationId, messageId, outcome.handling);
952
+ return finish({
953
+ handling: outcome.handling,
954
+ reply: outcome.reply,
955
+ sentence: handled,
956
+ ...(taskHint ? { hint: taskHint } : {}),
957
+ }, [label, outcome.reply?.text, handled, taskHint].filter((line) => !!line));
958
+ }
959
+ case 'wait':
960
+ break;
961
+ }
962
+ // The message waits for a turn of its own. Follow it until that turn starts, then stream it,
963
+ // when the caller asked to wait or the turn is only starting. Otherwise say why it waits and
964
+ // return: a script is never held for half an hour it did not ask for (decision 6.6).
965
+ notice('message.held', sentence);
966
+ const listHint = `${this.config.bin} agents queue list --conversation ${conversationId}`;
967
+ const starting = answer.route === 'new_turn';
968
+ if (input.detach || (!input.follow && !starting)) {
969
+ const where = `The message is kept and is sent by itself; see it with \`${listHint}\`, or pass ` +
970
+ '--wait-for-idle to follow it and stream the reply.';
971
+ return finish({ sentence, hint: where }, input.detach ? [] : [where]);
972
+ }
973
+ let waited;
974
+ try {
975
+ waited = await (0, agent_chat_queue_1.waitForQueuedTurn)({
976
+ conversationId,
977
+ clientInputId: messageId,
978
+ sessionId: sent.sessionId,
979
+ responseMessageId: sent.responseMessageId,
980
+ }, {
981
+ timeoutMs: input.timeoutMs,
982
+ onPaused: (line) => notice('message.paused', line),
983
+ });
984
+ }
985
+ catch (err) {
986
+ this.handleApiError(err);
987
+ }
988
+ switch (waited.outcome) {
989
+ case 'sent':
990
+ return {
991
+ sessionId: sent.sessionId,
992
+ conversationId,
993
+ responseMessageId: sent.responseMessageId,
994
+ };
995
+ case 'held':
996
+ return this.failWithCliError({
997
+ message: `Your message is kept but not sent: ${waited.reason}${waited.card.holdMessage ? ` ${waited.card.holdMessage}` : ''} See it with \`${listHint}\`.`,
998
+ code: 'INPUT_QUEUE_HELD',
999
+ status: 409,
1000
+ exit: 1,
1001
+ retryable: false,
1002
+ details: {
1003
+ ...record,
1004
+ cardId: waited.card.cardId,
1005
+ holdReason: waited.card.holdReason ?? null,
1006
+ holdCode: waited.card.holdCode ?? null,
1007
+ },
1008
+ });
1009
+ case 'not_sent': {
1010
+ // It left the queue without a turn of its own: read what became of it.
1011
+ let now;
1012
+ try {
1013
+ now = await (0, inbound_messages_1.readMessageDelivery)(conversationId, messageId);
1014
+ }
1015
+ catch (err) {
1016
+ this.handleApiError(err);
1017
+ }
1018
+ if (!now) {
1019
+ return this.failWithCliError({
1020
+ message: 'The message was taken back from another screen, so it was not sent.',
1021
+ code: 'MESSAGE_WITHDRAWN',
1022
+ status: 409,
1023
+ exit: 1,
1024
+ retryable: false,
1025
+ details: record,
1026
+ });
1027
+ }
1028
+ if (now.delivery?.state === 'failed') {
1029
+ return this.failWithCliError({
1030
+ message: (0, inbound_messages_1.deliverySentence)(now.delivery) ?? inbound_messages_1.FAILED_COPY.refused,
1031
+ code: 'MESSAGE_NOT_DELIVERED',
1032
+ exit: 1,
1033
+ retryable: now.delivery.failed?.reason === 'usage_limit',
1034
+ details: { ...record, reason: now.delivery.failed?.reason ?? null },
1035
+ });
1036
+ }
1037
+ const line = (0, inbound_messages_1.deliverySentence)(now.delivery) ?? 'Your agent has the message.';
1038
+ return finish({ delivery: now.delivery, sentence: line }, [line]);
1039
+ }
1040
+ default:
1041
+ return this.failWithCliError({
1042
+ message: `Your agent was still working after ${Math.round(input.timeoutMs / 1000)}s. ` +
1043
+ `Your message is kept and is sent when it finishes; see it with \`${listHint}\`.`,
1044
+ code: 'INPUT_QUEUE_WAIT_TIMEOUT',
1045
+ status: 408,
1046
+ exit: 1,
1047
+ retryable: true,
1048
+ details: record,
1049
+ });
1050
+ }
1051
+ }
816
1052
  async run() {
817
1053
  this.requireAuth();
818
1054
  const { args, flags } = await this.parse(AgentsChat);
819
- const whenBusy = flags['when-busy'] ?? 'fail';
1055
+ const explicitWhenBusy = flags['when-busy'];
1056
+ // An older server without the ingress: `--after-current` falls back to its queue (below).
1057
+ let whenBusy = explicitWhenBusy ?? 'fail';
1058
+ const inConversation = Boolean(flags.conversation || flags['thread-root']);
1059
+ if (flags['after-current']) {
1060
+ if (!inConversation) {
1061
+ this.error('--after-current needs --conversation or --thread-root: a new conversation has ' +
1062
+ 'nothing running to wait for.', { exit: 2 });
1063
+ }
1064
+ if (explicitWhenBusy === 'fail' || explicitWhenBusy === 'steer') {
1065
+ this.error(`--after-current and --when-busy ${explicitWhenBusy} ask for different things; pass one.`, { exit: 2 });
1066
+ }
1067
+ if (flags.quick)
1068
+ this.error('--after-current needs a runtime turn; remove --quick.', { exit: 2 });
1069
+ }
1070
+ if ((flags.detach || flags['queue-timeout'] !== undefined) && !inConversation) {
1071
+ this.error('--detach and --queue-timeout need --conversation or --thread-root: they follow a ' +
1072
+ 'message the server keeps in an existing conversation.', { exit: 2 });
1073
+ }
1074
+ if (flags.detach && explicitWhenBusy === 'fail') {
1075
+ this.error('--detach has nothing to follow with --when-busy fail; pass one.', { exit: 2 });
1076
+ }
820
1077
  if (whenBusy !== 'fail' && flags['wait-for-idle']) {
821
1078
  this.error('--when-busy and --wait-for-idle are two answers to the same question; pass one.', {
822
1079
  exit: 2,
@@ -998,85 +1255,125 @@ class AgentsChat extends base_command_1.BaseCommand {
998
1255
  this.error(`--idempotency-key must be ${agent_chat_start_1.START_KEY_RULE}.`, { exit: 2 });
999
1256
  }
1000
1257
  const startKey = suppliedStartKey ?? (0, agent_chat_start_1.newStartKey)();
1258
+ const turnText = contextParts ? `${contextParts}\n\n${prompt}` : prompt;
1001
1259
  let started;
1002
- try {
1003
- started = await (0, agent_chat_start_1.startWithReplay)(() => data_provider_1.dataService.startAgenticChat({
1004
- agentId: args.agentId,
1005
- taskId: boundTaskId,
1006
- text: contextParts ? `${contextParts}\n\n${prompt}` : prompt,
1007
- conversationId: threadConversationId,
1008
- workspaceId: process.env.OVERSKY_WORKSPACE_ID,
1009
- clientRequestId: startKey,
1010
- // The server resolves each ref against the session's daemon, so the
1011
- // turn is asked to run on the machine that listed them. An agent whose
1012
- // execution policy places it elsewhere keeps that placement, and the
1013
- // run fails saying why rather than running without the skill.
1014
- ...daemonPinFields(localSkills, flags.daemon),
1015
- ...permissionModeFields(flags['permission-mode']),
1016
- }), {
1017
- // stderr, so stdout and --json/--jsonl stay parseable.
1018
- onReplay: ({ attempt, of, waitMs }) => this.warn(`The server did not confirm the start; sending the same request again in ` +
1019
- `${Math.round(waitMs / 1000)}s (${attempt}/${of}). It returns the turn it ` +
1020
- `already accepted rather than starting a second one.`),
1021
- ...(flags['wait-for-idle']
1022
- ? {
1023
- waitForIdle: {
1024
- timeoutMs: (flags['wait-timeout'] ?? agent_chat_start_1.DEFAULT_WAIT_FOR_IDLE_TIMEOUT_MS / 1000) * 1000,
1025
- onBusy: (info) => this.warn((0, agent_chat_start_1.busyWaitNotice)(info, threadConversationId)),
1026
- },
1027
- }
1028
- : {}),
1260
+ // Inbound messages: a message to an existing conversation goes to the ingress, which keeps it
1261
+ // and decides how the agent sees it. `--when-busy fail` asks for the older refusal instead.
1262
+ let viaIngress = false;
1263
+ if (threadConversationId && explicitWhenBusy !== 'fail') {
1264
+ const sent = await this.sendThroughIngress({
1265
+ params: {
1266
+ agentId: args.agentId,
1267
+ taskId: boundTaskId,
1268
+ text: turnText,
1269
+ conversationId: threadConversationId,
1270
+ workspaceId: process.env.OVERSKY_WORKSPACE_ID,
1271
+ ...daemonPinFields(localSkills, flags.daemon),
1272
+ ...permissionModeFields(flags['permission-mode']),
1273
+ },
1274
+ startKey,
1275
+ intent: flags['after-current'] || flags['wait-for-idle'] || whenBusy === 'queue'
1276
+ ? 'after_current'
1277
+ : 'now',
1278
+ detach: Boolean(flags.detach),
1279
+ follow: Boolean(flags['after-current'] || flags['wait-for-idle'] || explicitWhenBusy),
1280
+ timeoutMs: flags['wait-for-idle']
1281
+ ? (flags['wait-timeout'] ?? agent_chat_start_1.DEFAULT_WAIT_FOR_IDLE_TIMEOUT_MS / 1000) * 1000
1282
+ : (flags['queue-timeout'] ?? agent_chat_queue_1.DEFAULT_QUEUE_WAIT_SECONDS) * 1000,
1283
+ json: Boolean(flags.json),
1284
+ jsonl: Boolean(flags.jsonl),
1029
1285
  });
1286
+ if (sent === null)
1287
+ return;
1288
+ if (sent === 'legacy') {
1289
+ if (flags['after-current'] && whenBusy === 'fail')
1290
+ whenBusy = 'queue';
1291
+ }
1292
+ else {
1293
+ started = sent;
1294
+ viaIngress = true;
1295
+ }
1030
1296
  }
1031
- catch (err) {
1032
- // OSK-32920 — a conversation that already has a turn running answers
1033
- // `429 conversation_busy`. Read by the generic path it printed the server's
1034
- // "Please wait." with no word on whether anything was sent or how to wait.
1035
- const busy = (0, agent_chat_start_1.busyStartFailure)(err, threadConversationId);
1036
- // G7 — or the turn is queued on the server (or steered into the running one).
1037
- if (busy && whenBusy !== 'fail' && threadConversationId) {
1038
- const queued = await this.startThroughQueue({
1039
- whenBusy,
1297
+ if (!viaIngress) {
1298
+ try {
1299
+ started = await (0, agent_chat_start_1.startWithReplay)(() => data_provider_1.dataService.startAgenticChat({
1300
+ agentId: args.agentId,
1301
+ taskId: boundTaskId,
1302
+ text: turnText,
1040
1303
  conversationId: threadConversationId,
1041
- startKey,
1042
- params: {
1043
- agentId: args.agentId,
1044
- taskId: boundTaskId,
1045
- text: contextParts ? `${contextParts}\n\n${prompt}` : prompt,
1046
- conversationId: threadConversationId,
1047
- workspaceId: process.env.OVERSKY_WORKSPACE_ID,
1048
- ...daemonPinFields(localSkills, flags.daemon),
1049
- ...permissionModeFields(flags['permission-mode']),
1050
- },
1051
- detach: Boolean(flags.detach),
1052
- timeoutMs: (flags['queue-timeout'] ?? agent_chat_queue_1.DEFAULT_QUEUE_WAIT_SECONDS) * 1000,
1053
- json: Boolean(flags.json || flags.jsonl),
1304
+ workspaceId: process.env.OVERSKY_WORKSPACE_ID,
1305
+ clientRequestId: startKey,
1306
+ // The server resolves each ref against the session's daemon, so the
1307
+ // turn is asked to run on the machine that listed them. An agent whose
1308
+ // execution policy places it elsewhere keeps that placement, and the
1309
+ // run fails saying why rather than running without the skill.
1310
+ ...daemonPinFields(localSkills, flags.daemon),
1311
+ ...permissionModeFields(flags['permission-mode']),
1312
+ }), {
1313
+ // stderr, so stdout and --json/--jsonl stay parseable.
1314
+ onReplay: ({ attempt, of, waitMs }) => this.warn(`The server did not confirm the start; sending the same request again in ` +
1315
+ `${Math.round(waitMs / 1000)}s (${attempt}/${of}). It returns the turn it ` +
1316
+ `already accepted rather than starting a second one.`),
1317
+ ...(flags['wait-for-idle']
1318
+ ? {
1319
+ waitForIdle: {
1320
+ timeoutMs: (flags['wait-timeout'] ?? agent_chat_start_1.DEFAULT_WAIT_FOR_IDLE_TIMEOUT_MS / 1000) * 1000,
1321
+ onBusy: (info) => this.warn((0, agent_chat_start_1.busyWaitNotice)(info, threadConversationId)),
1322
+ },
1323
+ }
1324
+ : {}),
1054
1325
  });
1055
- if (!queued)
1056
- return;
1057
- started = queued;
1058
1326
  }
1059
- else {
1060
- if (busy) {
1061
- this.failWithCliError({
1062
- message: busy.message,
1063
- code: busy.code,
1064
- status: busy.status,
1065
- exit: 1,
1066
- retryable: busy.retryable,
1067
- details: busy.details,
1327
+ catch (err) {
1328
+ // OSK-32920 — a conversation that already has a turn running answers
1329
+ // `429 conversation_busy`. Read by the generic path it printed the server's
1330
+ // "Please wait." with no word on whether anything was sent or how to wait.
1331
+ const busy = (0, agent_chat_start_1.busyStartFailure)(err, threadConversationId);
1332
+ // G7 — or the turn is queued on the server (or steered into the running one).
1333
+ if (busy && whenBusy !== 'fail' && threadConversationId) {
1334
+ const queued = await this.startThroughQueue({
1335
+ whenBusy,
1336
+ conversationId: threadConversationId,
1337
+ startKey,
1338
+ params: {
1339
+ agentId: args.agentId,
1340
+ taskId: boundTaskId,
1341
+ text: turnText,
1342
+ conversationId: threadConversationId,
1343
+ workspaceId: process.env.OVERSKY_WORKSPACE_ID,
1344
+ ...daemonPinFields(localSkills, flags.daemon),
1345
+ ...permissionModeFields(flags['permission-mode']),
1346
+ },
1347
+ detach: Boolean(flags.detach),
1348
+ timeoutMs: (flags['queue-timeout'] ?? agent_chat_queue_1.DEFAULT_QUEUE_WAIT_SECONDS) * 1000,
1349
+ json: Boolean(flags.json || flags.jsonl),
1068
1350
  });
1351
+ if (!queued)
1352
+ return;
1353
+ started = queued;
1069
1354
  }
1070
- if (err instanceof agent_chat_start_1.StartNotConfirmed) {
1071
- this.warn((0, agent_chat_start_1.startNotConfirmedHint)(startKey, err.attempts));
1072
- this.handleApiError(err.lastError);
1355
+ else {
1356
+ if (busy) {
1357
+ this.failWithCliError({
1358
+ message: busy.message,
1359
+ code: busy.code,
1360
+ status: busy.status,
1361
+ exit: 1,
1362
+ retryable: busy.retryable,
1363
+ details: busy.details,
1364
+ });
1365
+ }
1366
+ if (err instanceof agent_chat_start_1.StartNotConfirmed) {
1367
+ this.warn((0, agent_chat_start_1.startNotConfirmedHint)(startKey, err.attempts));
1368
+ this.handleApiError(err.lastError);
1369
+ }
1370
+ // A refused start was the one API error on this command that escaped
1371
+ // `handleApiError`: it fell through to the generic catch, which printed
1372
+ // `HTTP 400 Bad Request — POST …/api/agentic/chat` under the code
1373
+ // CLI_PARSE_ERROR and dropped the body that said WHY ("The configured
1374
+ // model is not supported."). The reader had to guess (OSK-4897).
1375
+ this.handleApiError(err);
1073
1376
  }
1074
- // A refused start was the one API error on this command that escaped
1075
- // `handleApiError`: it fell through to the generic catch, which printed
1076
- // `HTTP 400 Bad Request — POST …/api/agentic/chat` under the code
1077
- // CLI_PARSE_ERROR and dropped the body that said WHY ("The configured
1078
- // model is not supported."). The reader had to guess (OSK-4897).
1079
- this.handleApiError(err);
1080
1377
  }
1081
1378
  }
1082
1379
  if (!started)
@@ -1087,12 +1384,18 @@ class AgentsChat extends base_command_1.BaseCommand {
1087
1384
  // answer used to be adopted; a workspace the caller chose still wins, and
1088
1385
  // an autonomous process still never takes one. It also tells us whether
1089
1386
  // this server chooses the workspace itself, for the next turn.
1090
- const workspaceDefault = (0, agent_home_workspace_1.recordAgentHomeDefaultObservation)(this.config?.cacheDir, this.cliConfig.baseURL, started);
1387
+ // A message to the ingress answers with no workspace of its own: the conversation already
1388
+ // has one, so there is nothing to observe or adopt.
1389
+ const workspaceDefault = viaIngress
1390
+ ? null
1391
+ : (0, agent_home_workspace_1.recordAgentHomeDefaultObservation)(this.config?.cacheDir, this.cliConfig.baseURL, started);
1091
1392
  if (serverChoosesWorkspace && workspaceDefault === 'unsupported') {
1092
1393
  this.warn('This server no longer chooses the agent’s home workspace, so this turn ran without ' +
1093
1394
  'one. The next turn will select it again; pass --workspace to choose one now.');
1094
1395
  }
1095
- (0, agent_home_workspace_1.commitAgentHomeWorkspaceDefault)(typeof started.workspaceId === 'string' && started.workspaceId ? started.workspaceId : null);
1396
+ if (!viaIngress) {
1397
+ (0, agent_home_workspace_1.commitAgentHomeWorkspaceDefault)(typeof started.workspaceId === 'string' && started.workspaceId ? started.workspaceId : null);
1398
+ }
1096
1399
  if (!started.sessionId) {
1097
1400
  this.error('Agentic chat was accepted without a session ID; cannot attach the stream.', {
1098
1401
  exit: 1,
@@ -1389,6 +1692,13 @@ class AgentsChat extends base_command_1.BaseCommand {
1389
1692
  // (Not after SIGHUP: the terminal that would show it is gone.)
1390
1693
  this.log(`\n${cancelledRunMessage({ sessionId: started.sessionId, conversationId: started.conversationId })}`);
1391
1694
  }
1695
+ // Human modes say it under the answer, on stderr. `--jsonl` carries it on `run.completed`
1696
+ // and `run.result`, `--json` in its payload (OSK-33192).
1697
+ const downgraded = !flags.jsonl && !(quiet && flags.json) && result.status === 'completed'
1698
+ ? interactionUnavailableFrom(result.lastEvent)
1699
+ : undefined;
1700
+ if (downgraded)
1701
+ this.warn(interactionUnavailableWarning(downgraded));
1392
1702
  // If completion wins the Ctrl-C race, preserve the completed run's exit status.
1393
1703
  if (cancelledBy || interruptedBy === 'SIGTERM' || interruptedBy === 'SIGHUP') {
1394
1704
  process.exitCode = interruptExitCode(interruptedBy);
@@ -216,7 +216,7 @@ class AgentsImport extends base_command_1.BaseCommand {
216
216
  });
217
217
  }
218
218
  if (flags.json) {
219
- this.log(JSON.stringify({ output: flags.output, document, dropped }, null, 2));
219
+ this.printJsonResult({ output: flags.output, document, dropped });
220
220
  return;
221
221
  }
222
222
  this.log(`Wrote ${Object.keys(document.spec).length} field(s) to ${flags.output}.`);
@@ -275,7 +275,7 @@ class AgentsImport extends base_command_1.BaseCommand {
275
275
  this.handleApiError(err, { subject: `skill ${skill.name}` });
276
276
  }
277
277
  if (flags.json) {
278
- this.log(JSON.stringify({ skill: created, attachedTo: flags.agent ?? null, dropped }, null, 2));
278
+ this.printJsonResult({ skill: created, attachedTo: flags.agent ?? null, dropped });
279
279
  return;
280
280
  }
281
281
  this.log(flags.agent
@@ -352,7 +352,7 @@ class AgentsImport extends base_command_1.BaseCommand {
352
352
  };
353
353
  if (!flags.agent) {
354
354
  if (flags.json) {
355
- this.log(JSON.stringify({ applied: false, ...(0, plan_1.planForOutput)(plan) }, null, 2));
355
+ this.printJsonResult({ applied: false, ...(0, plan_1.planForOutput)(plan) });
356
356
  return;
357
357
  }
358
358
  showPlan();
@@ -19,13 +19,14 @@ class AgentsManagerStatus extends base_command_1.BaseCommand {
19
19
  this.requireAuth();
20
20
  const { flags } = await this.parse(AgentsManagerStatus);
21
21
  try {
22
- const { workspaceId, agent: manager, duty: staffingDuty } = await data_provider_1.dataService.getAgentManagerStatus();
22
+ const { workspaceId, agent: manager, duty: staffingDuty, } = await data_provider_1.dataService.getAgentManagerStatus();
23
23
  const agent = manager && (0, web_url_1.withAgentUrl)(this.cliConfig.baseURL, manager);
24
24
  const detail = staffingDuty ? await duties_1.dutyApi.get(staffingDuty.id) : null;
25
- const duty = staffingDuty && (0, web_url_1.withDutyUrl)(this.cliConfig.baseURL, {
26
- ...staffingDuty,
27
- status: detail?.duty?.status ?? staffingDuty.status,
28
- });
25
+ const duty = staffingDuty &&
26
+ (0, web_url_1.withDutyUrl)(this.cliConfig.baseURL, {
27
+ ...staffingDuty,
28
+ status: detail?.duty?.status ?? staffingDuty.status,
29
+ });
29
30
  const historyAvailable = detail ? (0, duty_history_source_1.hasVerifiedDutyHistorySource)(detail) : null;
30
31
  const operatingTrigger = historyAvailable ? detail?.operatingState?.trigger : null;
31
32
  const trigger = operatingTrigger
@@ -43,7 +44,7 @@ class AgentsManagerStatus extends base_command_1.BaseCommand {
43
44
  }
44
45
  : null;
45
46
  if (flags.json) {
46
- this.log(JSON.stringify({ workspaceId, agent, duty, trigger, historyAvailable, latestCheck }, null, 2));
47
+ this.printJsonResult({ workspaceId, agent, duty, trigger, historyAvailable, latestCheck });
47
48
  return;
48
49
  }
49
50
  if (!agent) {