@skrr-ai/cli 0.1.202 → 0.1.204

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 (63) hide show
  1. package/dist/base-command.js +1 -1
  2. package/dist/commands/agent/message/context.d.ts +3 -0
  3. package/dist/commands/agent/message/context.js +33 -1
  4. package/dist/commands/agent/message/no-reply.d.ts +17 -0
  5. package/dist/commands/agent/message/no-reply.js +54 -0
  6. package/dist/commands/agent/message/retract.d.ts +24 -0
  7. package/dist/commands/agent/message/retract.js +167 -0
  8. package/dist/commands/agent/message/send.d.ts +47 -3
  9. package/dist/commands/agent/message/send.js +135 -4
  10. package/dist/commands/agents/chat.d.ts +12 -0
  11. package/dist/commands/agents/chat.js +258 -25
  12. package/dist/commands/agents/manager/status.d.ts +9 -0
  13. package/dist/commands/agents/manager/status.js +84 -0
  14. package/dist/commands/agents/queue/clear.d.ts +13 -0
  15. package/dist/commands/agents/queue/clear.js +31 -0
  16. package/dist/commands/agents/queue/list.d.ts +10 -0
  17. package/dist/commands/agents/queue/list.js +34 -0
  18. package/dist/commands/agents/queue/move.d.ts +16 -0
  19. package/dist/commands/agents/queue/move.js +33 -0
  20. package/dist/commands/agents/queue/pause.d.ts +7 -0
  21. package/dist/commands/agents/queue/pause.js +24 -0
  22. package/dist/commands/agents/queue/resume.d.ts +7 -0
  23. package/dist/commands/agents/queue/resume.js +24 -0
  24. package/dist/commands/agents/queue/steer.d.ts +14 -0
  25. package/dist/commands/agents/queue/steer.js +38 -0
  26. package/dist/commands/agents/queue/withdraw.d.ts +10 -0
  27. package/dist/commands/agents/queue/withdraw.js +27 -0
  28. package/dist/commands/agents/supervision.d.ts +1 -0
  29. package/dist/commands/agents/supervision.js +28 -9
  30. package/dist/commands/duties/advance-next.d.ts +17 -0
  31. package/dist/commands/duties/advance-next.js +122 -0
  32. package/dist/commands/duties/pack/plan.js +45 -0
  33. package/dist/commands/duties/preflight.d.ts +1 -0
  34. package/dist/commands/duties/preflight.js +18 -2
  35. package/dist/commands/spaces/auto-executor/preview.js +6 -2
  36. package/dist/commands/spaces/charter/revise.d.ts +16 -0
  37. package/dist/commands/spaces/charter/revise.js +84 -0
  38. package/dist/commands/spaces/skills/propose.d.ts +1 -0
  39. package/dist/commands/spaces/skills/propose.js +5 -0
  40. package/dist/commands/tasks/create.js +16 -1
  41. package/dist/commands/tasks/result/show.js +6 -3
  42. package/dist/commands/tasks/start.d.ts +3 -0
  43. package/dist/commands/tasks/start.js +12 -1
  44. package/dist/commands/triggers/capabilities.js +14 -4
  45. package/dist/generated/agent-guides.json +258 -24
  46. package/dist/lib/agent-chat-queue-command.d.ts +29 -0
  47. package/dist/lib/agent-chat-queue-command.js +75 -0
  48. package/dist/lib/agent-chat-queue.d.ts +77 -0
  49. package/dist/lib/agent-chat-queue.js +245 -0
  50. package/dist/lib/agent-chat-start.d.ts +101 -0
  51. package/dist/lib/agent-chat-start.js +151 -6
  52. package/dist/lib/duties.d.ts +5 -1
  53. package/dist/lib/duties.js +16 -5
  54. package/dist/lib/duty-product.js +6 -0
  55. package/dist/lib/input-queue.d.ts +18 -0
  56. package/dist/lib/input-queue.js +59 -0
  57. package/dist/lib/message-intent.d.ts +26 -3
  58. package/dist/lib/message-intent.js +7 -1
  59. package/dist/lib/task-runtime-headers.d.ts +5 -0
  60. package/dist/lib/task-runtime-headers.js +28 -8
  61. package/dist/node_modules/@skrr-ai/data-provider/index.js +10464 -10221
  62. package/oclif.manifest.json +1956 -765
  63. package/package.json +6 -3
@@ -46,6 +46,9 @@ exports.generateIdempotencyKey = generateIdempotencyKey;
46
46
  exports.buildEnvelope = buildEnvelope;
47
47
  exports.withAppliedAttention = withAppliedAttention;
48
48
  exports.formatEnvelope = formatEnvelope;
49
+ exports.describeMessageOperation = describeMessageOperation;
50
+ exports.resolveSendOperation = resolveSendOperation;
51
+ exports.sendOperationUnsupported = sendOperationUnsupported;
49
52
  const crypto = __importStar(require("node:crypto"));
50
53
  const core_1 = require("@oclif/core");
51
54
  const data_provider_1 = require("@skrr-ai/data-provider");
@@ -137,6 +140,8 @@ class AgentMessageSend extends base_command_1.BaseCommand {
137
140
  // for all time — a bare `checkpoint:verify` collides on the next run.
138
141
  '<%= config.bin %> agent message send --agent <agent-id> --kind milestone --idempotency-key <task-id>:verify --text "Implementation is complete." --part "Verification is in progress." --json',
139
142
  '<%= config.bin %> agent message send --agent <agent-id> --destination slack_channel --channel C123 --text "Update" --json',
143
+ '<%= config.bin %> agent message send --supersedes <message-id> --text "Correction: the deploy is at 15:00, not 14:00." --json',
144
+ '<%= config.bin %> agent message send --status-key build --text "Build 2 of 3 passed." --json',
140
145
  ];
141
146
  static args = {
142
147
  agent: core_1.Args.string({
@@ -186,6 +191,12 @@ class AgentMessageSend extends base_command_1.BaseCommand {
186
191
  'from-json': core_1.Flags.string({
187
192
  description: 'Path to a canonical intent JSON payload, or "-" for stdin',
188
193
  }),
194
+ supersedes: core_1.Flags.string({
195
+ description: 'The messageId of a message this Agent sent earlier that this one corrects (app_owner_dm, inside an Agent session). The earlier message is shown as replaced.',
196
+ }),
197
+ 'status-key': core_1.Flags.string({
198
+ description: 'A key for a status this Agent keeps current, such as build (app_owner_dm, inside an Agent session). Each send with the same key replaces the previous one.',
199
+ }),
189
200
  'idempotency-key': core_1.Flags.string({
190
201
  description: 'Stable retry key; overrides the key in --from-json, or is auto-derived when neither is supplied',
191
202
  }),
@@ -289,6 +300,29 @@ class AgentMessageSend extends base_command_1.BaseCommand {
289
300
  retryable: false,
290
301
  });
291
302
  }
303
+ const operationChoice = resolveSendOperation({
304
+ supersedes: flags.supersedes,
305
+ statusKey: flags['status-key'],
306
+ jsonOperation: jsonBody.operation,
307
+ });
308
+ if ('error' in operationChoice) {
309
+ this.failWithCliError({
310
+ message: operationChoice.error,
311
+ code: 'INVALID_MESSAGE_OPERATION',
312
+ exit: 1,
313
+ retryable: false,
314
+ });
315
+ }
316
+ const operation = operationChoice.operation;
317
+ if (operation) {
318
+ const unsupported = sendOperationUnsupported({
319
+ destinationKind: payload.destination.kind,
320
+ inSession: Boolean(sessionContext),
321
+ partCount: (flags.part || []).length,
322
+ });
323
+ if (unsupported)
324
+ this.failWithCliError({ ...unsupported, retryable: false });
325
+ }
292
326
  // Manual task context accepts the same titles and references as task
293
327
  // commands. Managed sessions must leave the claim-derived context alone.
294
328
  if (!sessionContext &&
@@ -328,7 +362,7 @@ class AgentMessageSend extends base_command_1.BaseCommand {
328
362
  }
329
363
  throw error;
330
364
  }
331
- const idempotencyKey = payload.idempotencyKey || generateIdempotencyKey(agentId, payload);
365
+ const idempotencyKey = payload.idempotencyKey || generateIdempotencyKey(agentId, payload, operation);
332
366
  const request_ = canonicalIntentFromDestination({
333
367
  agentId,
334
368
  idempotencyKey,
@@ -339,6 +373,7 @@ class AgentMessageSend extends base_command_1.BaseCommand {
339
373
  context: payload.context,
340
374
  threadRootMessageId: payload.threadRootMessageId,
341
375
  embeds,
376
+ operation,
342
377
  });
343
378
  let requests;
344
379
  try {
@@ -490,6 +525,10 @@ class AgentMessageSend extends base_command_1.BaseCommand {
490
525
  notificationPolicy: request.notificationPolicy,
491
526
  embeds: request.embeds,
492
527
  embedRejections: result.embedRejections,
528
+ messageId: typeof result.messageId === 'string' ? result.messageId : undefined,
529
+ operation: request.operation
530
+ ? { ...request.operation, ...(result.operation ? { outcome: result.operation } : {}) }
531
+ : undefined,
493
532
  intent: {
494
533
  id: result.intentId ?? null,
495
534
  status: result.status || 'submitted',
@@ -1080,7 +1119,7 @@ function booleanFlagInput(argv, name, parsedValue) {
1080
1119
  void parsedValue;
1081
1120
  return undefined;
1082
1121
  }
1083
- function canonicalIntentFromDestination({ agentId, idempotencyKey, destination, text, presentation, notificationPolicy, context, threadRootMessageId, embeds, }) {
1122
+ function canonicalIntentFromDestination({ agentId, idempotencyKey, destination, text, presentation, notificationPolicy, context, threadRootMessageId, embeds, operation, }) {
1084
1123
  switch (destination.kind) {
1085
1124
  case 'agent_email':
1086
1125
  return {
@@ -1101,6 +1140,7 @@ function canonicalIntentFromDestination({ agentId, idempotencyKey, destination,
1101
1140
  notificationPolicy,
1102
1141
  threadRootMessageId,
1103
1142
  embeds,
1143
+ operation,
1104
1144
  ...context,
1105
1145
  });
1106
1146
  case 'slack_owner_dm':
@@ -1159,7 +1199,7 @@ function optionalIdempotencyKey(value) {
1159
1199
  }
1160
1200
  return normalized;
1161
1201
  }
1162
- function generateIdempotencyKey(agentId, payload) {
1202
+ function generateIdempotencyKey(agentId, payload, operation) {
1163
1203
  const requestId = optionalString(process.env.OVERSKY_SESSION_REQUEST_ID) ||
1164
1204
  optionalString(process.env.OVERSKY_REQUEST_ID);
1165
1205
  const digest = crypto
@@ -1171,6 +1211,9 @@ function generateIdempotencyKey(agentId, payload) {
1171
1211
  presentation: payload.presentation,
1172
1212
  context: payload.context,
1173
1213
  threadRootMessageId: payload.threadRootMessageId,
1214
+ // The same words correcting another message are another send. Absent for an ordinary
1215
+ // send, so its key is the one it had before C10.
1216
+ ...(operation ? { operation } : {}),
1174
1217
  }))
1175
1218
  .digest('hex')
1176
1219
  .slice(0, 32);
@@ -1218,6 +1261,8 @@ function buildEnvelope(input) {
1218
1261
  ...(input.embedRejections && input.embedRejections.length > 0
1219
1262
  ? { embedRejections: input.embedRejections }
1220
1263
  : {}),
1264
+ ...(input.messageId ? { messageId: input.messageId } : {}),
1265
+ ...(input.operation ? { operation: input.operation } : {}),
1221
1266
  intent: input.intent,
1222
1267
  };
1223
1268
  }
@@ -1252,7 +1297,93 @@ function formatEnvelope(envelope) {
1252
1297
  : '';
1253
1298
  const consequence = (envelope.intent.reason && REASON_CONSEQUENCE[envelope.intent.reason]) ||
1254
1299
  STATUS_CONSEQUENCE[status];
1255
- return `Agent message intent for ${envelope.agent.id} → ${destination}: ${status}${suffix}.${presentation}${describeOneVoice(envelope.intent.oneVoice)}${consequence ? ` ${consequence}` : ''}${describePersonSender(envelope)}`;
1300
+ return `Agent message intent for ${envelope.agent.id} → ${destination}: ${status}${suffix}.${presentation}${describeOneVoice(envelope.intent.oneVoice)}${consequence ? ` ${consequence}` : ''}${describePersonSender(envelope)}${describeMessageOperation(envelope)}`;
1301
+ }
1302
+ /**
1303
+ * The message id a later correction names, and what this send did to an earlier message (C10).
1304
+ * A send whose mark did not land is said to have gone out WITHOUT replacing anything: the exit
1305
+ * code cannot say it, because the message itself was delivered.
1306
+ */
1307
+ function describeMessageOperation(envelope) {
1308
+ const id = envelope.messageId ? ` Message id: ${envelope.messageId}.` : '';
1309
+ const operation = envelope.operation;
1310
+ const outcome = operation?.outcome;
1311
+ if (!operation || !outcome)
1312
+ return id;
1313
+ if (operation.kind === 'supersede') {
1314
+ return outcome.applied
1315
+ ? `${id} It replaces ${outcome.targetMessageId || operation.targetMessageId}.`
1316
+ : `${id} It was sent, but ${operation.targetMessageId} was not marked as replaced (${outcome.reason || 'unknown'}).`;
1317
+ }
1318
+ if (operation.kind === 'status') {
1319
+ if (outcome.applied && outcome.targetMessageId) {
1320
+ return `${id} It replaces the earlier "${operation.key}" status ${outcome.targetMessageId}.`;
1321
+ }
1322
+ if (outcome.reason === 'first_status')
1323
+ return `${id} It is the first "${operation.key}" status.`;
1324
+ return `${id} It was sent, but the earlier "${operation.key}" status was not replaced (${outcome.reason || 'unknown'}).`;
1325
+ }
1326
+ return id;
1327
+ }
1328
+ /**
1329
+ * The operation a send asks for, from `--supersedes`, `--status-key` or a JSON body's
1330
+ * `operation`. One source only: two that disagree are refused rather than one silently winning.
1331
+ * A retraction is not a send (`agent message retract`).
1332
+ */
1333
+ function resolveSendOperation({ supersedes, statusKey, jsonOperation, }) {
1334
+ const sources = [supersedes !== undefined, statusKey !== undefined, jsonOperation !== undefined];
1335
+ if (sources.filter(Boolean).length > 1) {
1336
+ return {
1337
+ error: 'Give one of --supersedes, --status-key or a JSON operation: a message either corrects another or keeps a status.',
1338
+ };
1339
+ }
1340
+ let raw;
1341
+ if (supersedes !== undefined)
1342
+ raw = { kind: 'supersede', targetMessageId: supersedes };
1343
+ else if (statusKey !== undefined)
1344
+ raw = { kind: 'status', key: statusKey };
1345
+ else if (jsonOperation !== undefined)
1346
+ raw = jsonOperation;
1347
+ else
1348
+ return {};
1349
+ const parsed = (0, data_provider_1.parseMessageOperation)(raw);
1350
+ if (!parsed.ok)
1351
+ return { error: parsed.reason };
1352
+ if (parsed.value.kind === 'retract') {
1353
+ return {
1354
+ error: 'A retraction sends no message. Use `agent message retract <message-id>` to withdraw one.',
1355
+ };
1356
+ }
1357
+ return { operation: parsed.value };
1358
+ }
1359
+ /**
1360
+ * Why a send cannot carry an operation here, or null. Only an Agent's own session can name its
1361
+ * own message (the server proves it through the session), only an owner DM can be named, and a
1362
+ * sequence would leave unclear which part replaces the earlier message.
1363
+ */
1364
+ function sendOperationUnsupported({ destinationKind, inSession, partCount, }) {
1365
+ if (destinationKind !== 'app_owner_dm') {
1366
+ return {
1367
+ message: 'Only a message in the owner’s chat (app_owner_dm) can be corrected or kept as a status.',
1368
+ code: 'MESSAGE_OPERATION_DESTINATION_UNSUPPORTED',
1369
+ exit: 1,
1370
+ };
1371
+ }
1372
+ if (!inSession) {
1373
+ return {
1374
+ message: 'Correcting or keeping a status of an Agent’s message works only inside that Agent’s session: a message you send from your own terminal goes out as you.',
1375
+ code: 'MESSAGE_OPERATION_REQUIRES_SESSION',
1376
+ exit: 2,
1377
+ };
1378
+ }
1379
+ if (partCount > 0) {
1380
+ return {
1381
+ message: '--supersedes and --status-key send one message. Drop --part, or send the correction on its own.',
1382
+ code: 'MESSAGE_OPERATION_SEQUENCE_UNSUPPORTED',
1383
+ exit: 1,
1384
+ };
1385
+ }
1386
+ return null;
1256
1387
  }
1257
1388
  /**
1258
1389
  * A message a PERSON sends at a terminal goes out as that person, not through the agent's session, so the agent's
@@ -283,6 +283,11 @@ export default class AgentsChat extends BaseCommand {
283
283
  jsonl: import("@oclif/core/interfaces").BooleanFlag<boolean>;
284
284
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
285
285
  'idempotency-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
286
+ 'wait-for-idle': import("@oclif/core/interfaces").BooleanFlag<boolean>;
287
+ 'wait-timeout': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
288
+ 'when-busy': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
289
+ detach: import("@oclif/core/interfaces").BooleanFlag<boolean>;
290
+ 'queue-timeout': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
286
291
  'repair-wait': import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
287
292
  'approve-tools': import("@oclif/core/interfaces").BooleanFlag<boolean>;
288
293
  'permission-mode': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -309,6 +314,13 @@ export default class AgentsChat extends BaseCommand {
309
314
  * would only move the same error later (OSK-9478).
310
315
  */
311
316
  private resolveLocalSkills;
317
+ /**
318
+ * G7 — the conversation is busy and the caller asked for the turn to be queued (or steered)
319
+ * instead of refused. Returns the coordinates of the turn once it is started, so the caller
320
+ * attaches to it exactly as after a direct start, or `null` when there is nothing to stream (the
321
+ * message joined the running turn, or `--detach`).
322
+ */
323
+ private startThroughQueue;
312
324
  run(): Promise<void>;
313
325
  }
314
326
  export {};
@@ -28,6 +28,7 @@ const agent_chat_start_1 = require("../../lib/agent-chat-start");
28
28
  const agent_home_workspace_1 = require("../../lib/agent-home-workspace");
29
29
  const agentic_stream_1 = require("../../lib/agentic-stream");
30
30
  const web_url_1 = require("../../lib/web-url");
31
+ const agent_chat_queue_1 = require("../../lib/agent-chat-queue");
31
32
  const local_skills_1 = require("../../lib/local-skills");
32
33
  /**
33
34
  * Exit code for a run the USER stopped watching, by pressing Ctrl-C.
@@ -144,7 +145,9 @@ function jsonlTextForm(flags) {
144
145
  */
145
146
  function cancelledRunMessage(input) {
146
147
  return (`Run ${input.sessionId} cancelled: the server confirmed it ended.` +
147
- (input.conversationId ? ` Continue the conversation with --conversation ${input.conversationId}.` : ''));
148
+ (input.conversationId
149
+ ? ` Continue the conversation with --conversation ${input.conversationId}.`
150
+ : ''));
148
151
  }
149
152
  /**
150
153
  * What the durable record says about a turn, read from its messages.
@@ -165,8 +168,11 @@ function reconcileTerminalFromMessages(messages, responseMessageId) {
165
168
  if (!row)
166
169
  return null;
167
170
  const projection = row.metadata && typeof row.metadata === 'object'
168
- ? row.metadata.publicProjection : undefined;
169
- const publicProjection = (0, data_provider_1.isDecodedPublicProjection)(projection) ? { publicProjection: projection } : {};
171
+ ? row.metadata.publicProjection
172
+ : undefined;
173
+ const publicProjection = (0, data_provider_1.isDecodedPublicProjection)(projection)
174
+ ? { publicProjection: projection }
175
+ : {};
170
176
  const failure = (0, data_provider_1.resolveMessageFailure)(row);
171
177
  if (failure) {
172
178
  return {
@@ -225,8 +231,11 @@ function handoverStateFromMessages(messages, responseMessageId) {
225
231
  if (!row)
226
232
  return { state: 'pending' };
227
233
  const projection = row.metadata && typeof row.metadata === 'object'
228
- ? row.metadata.publicProjection : undefined;
229
- const publicProjection = (0, data_provider_1.isDecodedPublicProjection)(projection) ? { publicProjection: projection } : {};
234
+ ? row.metadata.publicProjection
235
+ : undefined;
236
+ const publicProjection = (0, data_provider_1.isDecodedPublicProjection)(projection)
237
+ ? { publicProjection: projection }
238
+ : {};
230
239
  const failure = (0, data_provider_1.resolveMessageFailure)(row);
231
240
  if (failure) {
232
241
  if (agenticErrorSubtype(row) === agentic_stream_1.DAEMON_HANDOVER_REASON)
@@ -337,7 +346,8 @@ function admittedRouting(runtime) {
337
346
  const routing = {
338
347
  ...(typeof selectedKind === 'string' && selectedKind ? { selectedKind } : {}),
339
348
  ...(typeof selectedExecutionSelector === 'string' && selectedExecutionSelector
340
- ? { selectedExecutionSelector } : {}),
349
+ ? { selectedExecutionSelector }
350
+ : {}),
341
351
  ...(typeof fallbackUsed === 'boolean' ? { fallbackUsed } : {}),
342
352
  };
343
353
  return Object.keys(routing).length ? routing : undefined;
@@ -455,7 +465,10 @@ class AgentsChat extends base_command_1.BaseCommand {
455
465
  static flags = {
456
466
  prompt: core_1.Flags.string({ description: 'Prompt to send to the agent', required: true }),
457
467
  context: core_1.Flags.string({ description: 'Additional context for the turn' }),
458
- conversation: core_1.Flags.string({ description: 'Existing conversation ID; defaults to a new turn' }),
468
+ conversation: core_1.Flags.string({
469
+ description: 'Existing conversation ID. A normal turn without a chat target opens a standalone conversation. ' +
470
+ 'For Main Chat, use agentChat.activeConversationId from `skrr dm show <agent-id> --json`.',
471
+ }),
459
472
  'thread-root': core_1.Flags.string({
460
473
  description: 'Open/reply in the Agent Chat Thread rooted at this main-message ID. Mutually exclusive with --conversation.',
461
474
  }),
@@ -525,7 +538,8 @@ class AgentsChat extends base_command_1.BaseCommand {
525
538
  'the machine finished; `run.failed` with `handover.outcome: "machine_failed"` and the ' +
526
539
  'machine\'s reason when it did not; or `run.failed` with `handover.outcome: "expired"` ' +
527
540
  'and the original failure when --repair-wait ran out (exit 1 for both). Ctrl-C during ' +
528
- 'the wait emits `run.detached` with `handedOver: true` and exits 130. Whenever a run ' +
541
+ 'the wait emits `run.detached` with `handedOver: true` and exits 130. A confirmed ' +
542
+ 'Ctrl-C cancellation emits `run.result` with `status: "aborted"` and exits 130. Whenever a run ' +
529
543
  'fails, `run.failed` carries `message`, the reason in words as the platform gave it (the ' +
530
544
  'same sentence a terminal prints after `Error:`), beside the short `reason`.',
531
545
  }),
@@ -533,12 +547,45 @@ class AgentsChat extends base_command_1.BaseCommand {
533
547
  description: 'Emit the final one-shot response as JSON (use with --no-stream)',
534
548
  }),
535
549
  'idempotency-key': core_1.Flags.string({
536
- description: 'Name this start (' + agent_chat_start_1.START_KEY_RULE + '). The CLI already names every start and, when ' +
550
+ description: 'Name this start (' +
551
+ agent_chat_start_1.START_KEY_RULE +
552
+ '). The CLI already names every start and, when ' +
537
553
  'the server does not confirm one (a 502, 503 or 504, or a dropped connection), sends the ' +
538
554
  'same request again so the server returns the turn it accepted instead of starting a ' +
539
555
  'second one. Pass your own key to re-attach to a start from another process: the same ' +
540
556
  'key and prompt return the original turn; a different prompt under it is refused.',
541
557
  }),
558
+ '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.',
563
+ }),
564
+ '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.`,
567
+ min: 1,
568
+ dependsOn: ['wait-for-idle'],
569
+ }),
570
+ '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.',
576
+ options: [...agent_chat_queue_1.WHEN_BUSY_MODES],
577
+ }),
578
+ 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'],
582
+ }),
583
+ '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.`,
586
+ min: 1,
587
+ dependsOn: ['when-busy'],
588
+ }),
542
589
  'repair-wait': core_1.Flags.integer({
543
590
  description: 'Seconds to keep waiting when a platform update restarts the server relaying a turn ' +
544
591
  'your machine is still running. The server repairs the reply onto the conversation ' +
@@ -645,9 +692,144 @@ class AgentsChat extends base_command_1.BaseCommand {
645
692
  }
646
693
  return { daemonId, refs };
647
694
  }
695
+ /**
696
+ * G7 — the conversation is busy and the caller asked for the turn to be queued (or steered)
697
+ * instead of refused. Returns the coordinates of the turn once it is started, so the caller
698
+ * attaches to it exactly as after a direct start, or `null` when there is nothing to stream (the
699
+ * message joined the running turn, or `--detach`).
700
+ */
701
+ async startThroughQueue(input) {
702
+ const fail = (err) => {
703
+ const refusal = (0, agent_chat_queue_1.queueErrorOf)(err);
704
+ if (!refusal)
705
+ this.handleApiError(err);
706
+ return this.failWithCliError({
707
+ message: refusal.message,
708
+ code: refusal.code,
709
+ status: refusal.status,
710
+ exit: 1,
711
+ retryable: refusal.retryable,
712
+ details: { conversationId: input.conversationId },
713
+ });
714
+ };
715
+ const emit = (record, line) => {
716
+ if (input.json)
717
+ (0, agentic_stream_1.writeJsonLine)(process.stdout, record);
718
+ else
719
+ this.warn(line);
720
+ };
721
+ let queued;
722
+ try {
723
+ queued = await (0, agent_chat_queue_1.queueAgentChatTurn)(input.params, { clientInputId: input.startKey });
724
+ }
725
+ catch (err) {
726
+ return fail(err);
727
+ }
728
+ const { submitted } = queued;
729
+ if (submitted.outcome === 'started' && submitted.start) {
730
+ // The running turn ended between the refusal and the submit: this turn started now.
731
+ return submitted.start;
732
+ }
733
+ const startedHere = {
734
+ sessionId: queued.sessionId,
735
+ conversationId: input.conversationId,
736
+ responseMessageId: queued.responseMessageId,
737
+ };
738
+ emit({
739
+ type: 'input.queued',
740
+ conversationId: input.conversationId,
741
+ cardId: submitted.cardId,
742
+ position: submitted.position,
743
+ sessionId: queued.sessionId,
744
+ }, `The conversation has a turn running, so this message was queued on the server ` +
745
+ `(card ${submitted.cardId}, position ${(submitted.position ?? 0) + 1}). It is sent when ` +
746
+ 'that turn ends.');
747
+ if (input.whenBusy === 'steer') {
748
+ try {
749
+ const steered = await (0, agent_chat_queue_1.steerCard)(input.conversationId, submitted.cardId);
750
+ emit({ type: 'input.steer', outcome: steered.outcome, cardId: submitted.cardId }, (0, agent_chat_queue_1.steerOutcomeSentence)(steered.outcome));
751
+ if (steered.outcome === 'sent')
752
+ return null;
753
+ if (steered.outcome === 'next_turn')
754
+ return startedHere;
755
+ }
756
+ catch (err) {
757
+ const refusal = (0, agent_chat_queue_1.queueErrorOf)(err);
758
+ // The card stays queued: say why it could not steer and keep following it.
759
+ if (!refusal)
760
+ return fail(err);
761
+ emit({ type: 'input.steer', outcome: 'refused', code: refusal.code, cardId: submitted.cardId }, refusal.message);
762
+ }
763
+ }
764
+ if (input.detach)
765
+ return null;
766
+ let waited;
767
+ try {
768
+ waited = await (0, agent_chat_queue_1.waitForQueuedTurn)(queued, {
769
+ timeoutMs: input.timeoutMs,
770
+ onPaused: (sentence) => emit({ type: 'input.paused', message: sentence }, sentence),
771
+ });
772
+ }
773
+ catch (err) {
774
+ return fail(err);
775
+ }
776
+ const listHint = `${this.config.bin} agents queue list --conversation ${input.conversationId}`;
777
+ switch (waited.outcome) {
778
+ case 'sent':
779
+ return startedHere;
780
+ case 'held':
781
+ return this.failWithCliError({
782
+ message: `The queued message could not be sent: ${waited.reason}${waited.card.holdMessage ? ` ${waited.card.holdMessage}` : ''} It is held in the queue; see it with \`${listHint}\`.`,
783
+ code: 'INPUT_QUEUE_HELD',
784
+ status: 409,
785
+ exit: 1,
786
+ retryable: false,
787
+ details: {
788
+ conversationId: input.conversationId,
789
+ cardId: waited.card.cardId,
790
+ holdReason: waited.card.holdReason ?? null,
791
+ holdCode: waited.card.holdCode ?? null,
792
+ },
793
+ });
794
+ case 'not_sent':
795
+ return this.failWithCliError({
796
+ message: 'The queued message left the queue without being sent; it was probably withdrawn ' +
797
+ 'from another screen.',
798
+ code: 'INPUT_QUEUE_NOT_SENT',
799
+ status: 409,
800
+ exit: 1,
801
+ retryable: false,
802
+ details: { conversationId: input.conversationId, cardId: submitted.cardId },
803
+ });
804
+ default:
805
+ return this.failWithCliError({
806
+ message: `The running turn had not finished after ${Math.round(input.timeoutMs / 1000)}s. ` +
807
+ `The message is still queued and will be sent when it does; see it with \`${listHint}\`.`,
808
+ code: 'INPUT_QUEUE_WAIT_TIMEOUT',
809
+ status: 408,
810
+ exit: 1,
811
+ retryable: true,
812
+ details: { conversationId: input.conversationId, cardId: submitted.cardId },
813
+ });
814
+ }
815
+ }
648
816
  async run() {
649
817
  this.requireAuth();
650
818
  const { args, flags } = await this.parse(AgentsChat);
819
+ const whenBusy = flags['when-busy'] ?? 'fail';
820
+ if (whenBusy !== 'fail' && flags['wait-for-idle']) {
821
+ this.error('--when-busy and --wait-for-idle are two answers to the same question; pass one.', {
822
+ exit: 2,
823
+ });
824
+ }
825
+ if (whenBusy !== 'fail' && !flags.conversation && !flags['thread-root']) {
826
+ this.error('--when-busy needs --conversation: a new conversation is never busy.', {
827
+ exit: 2,
828
+ });
829
+ }
830
+ if (whenBusy !== 'fail' && flags.quick) {
831
+ this.error('--when-busy needs a runtime turn; remove --quick.', { exit: 2 });
832
+ }
651
833
  if (flags.quick && flags.task)
652
834
  this.error('--task requires a runtime session; remove --quick to bind this turn.', {
653
835
  exit: 2,
@@ -836,20 +1018,69 @@ class AgentsChat extends base_command_1.BaseCommand {
836
1018
  onReplay: ({ attempt, of, waitMs }) => this.warn(`The server did not confirm the start; sending the same request again in ` +
837
1019
  `${Math.round(waitMs / 1000)}s (${attempt}/${of}). It returns the turn it ` +
838
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
+ : {}),
839
1029
  });
840
1030
  }
841
1031
  catch (err) {
842
- if (err instanceof agent_chat_start_1.StartNotConfirmed) {
843
- this.warn((0, agent_chat_start_1.startNotConfirmedHint)(startKey, err.attempts));
844
- this.handleApiError(err.lastError);
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,
1040
+ 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),
1054
+ });
1055
+ if (!queued)
1056
+ return;
1057
+ started = queued;
1058
+ }
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,
1068
+ });
1069
+ }
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);
1073
+ }
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);
845
1080
  }
846
- // A refused start was the one API error on this command that escaped
847
- // `handleApiError`: it fell through to the generic catch, which printed
848
- // `HTTP 400 Bad Request — POST …/api/agentic/chat` under the code
849
- // CLI_PARSE_ERROR and dropped the body that said WHY ("The configured
850
- // model is not supported."). The reader had to guess (OSK-4897).
851
- this.handleApiError(err);
852
1081
  }
1082
+ if (!started)
1083
+ return;
853
1084
  // OSK-13599 — the acceptance names the workspace the turn runs in. Adopt it
854
1085
  // for the rest of this turn (the stream's header, the message reads that
855
1086
  // reconcile its end, envelope replay) exactly as the pre-flight read's
@@ -879,7 +1110,9 @@ class AgentsChat extends base_command_1.BaseCommand {
879
1110
  conversationId: started.conversationId,
880
1111
  ...(flags['thread-root'] ? { threadRootMessageId: flags['thread-root'] } : {}),
881
1112
  responseMessageId: started.responseMessageId,
882
- ...(admittedRouting(started.runtime) ? { admittedRouting: admittedRouting(started.runtime) } : {}),
1113
+ ...(admittedRouting(started.runtime)
1114
+ ? { admittedRouting: admittedRouting(started.runtime) }
1115
+ : {}),
883
1116
  // OSK-13599 — where the turn runs and who chose it, when the server
884
1117
  // says (`request` | `agent_home`); absent against an older server.
885
1118
  ...(workspaceDefault === 'supported'
@@ -1115,6 +1348,7 @@ class AgentsChat extends base_command_1.BaseCommand {
1115
1348
  this.error(message, { exit });
1116
1349
  }
1117
1350
  const result = reconciled ?? outcome;
1351
+ const cancelledBy = result.status === 'aborted' ? interruptedBy : null;
1118
1352
  if (flags.jsonl) {
1119
1353
  // The event stream already contains the terminal event. This summary
1120
1354
  // makes shell consumers able to find the final text without replaying
@@ -1145,19 +1379,18 @@ class AgentsChat extends base_command_1.BaseCommand {
1145
1379
  text: result.text,
1146
1380
  conversationId: started.conversationId,
1147
1381
  });
1148
- if (noOutput)
1382
+ if (noOutput && !cancelledBy)
1149
1383
  this.error(noOutput, { exit: 1 });
1150
- this.log(result.text);
1384
+ if (!noOutput)
1385
+ this.log(result.text);
1151
1386
  }
1152
1387
  else if (result.status === 'aborted' && interruptedBy !== 'SIGHUP') {
1153
1388
  // Streaming human mode: say the cancel took, rather than leave the keypress warning last.
1154
1389
  // (Not after SIGHUP: the terminal that would show it is gone.)
1155
1390
  this.log(`\n${cancelledRunMessage({ sessionId: started.sessionId, conversationId: started.conversationId })}`);
1156
1391
  }
1157
- // A run stopped by SIGTERM or SIGHUP ends the way a shell reports a process the signal killed,
1158
- // so a script can tell a cancelled run from one that finished. Ctrl-C keeps its existing status
1159
- // (a cancel that took is a success, a detach is 130).
1160
- if (interruptedBy === 'SIGTERM' || interruptedBy === 'SIGHUP') {
1392
+ // If completion wins the Ctrl-C race, preserve the completed run's exit status.
1393
+ if (cancelledBy || interruptedBy === 'SIGTERM' || interruptedBy === 'SIGHUP') {
1161
1394
  process.exitCode = interruptExitCode(interruptedBy);
1162
1395
  }
1163
1396
  }
@@ -0,0 +1,9 @@
1
+ import { BaseCommand } from '../../../base-command';
2
+ export default class AgentsManagerStatus extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
+ };
8
+ run(): Promise<void>;
9
+ }