@commonlyai/cli 0.1.286 → 0.1.288

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.286",
3
+ "version": "0.1.288",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -766,6 +766,12 @@ const someoneIsWaiting = (event) => ADDRESSED_EVENT_TYPES.has(event.type)
766
766
  || event.payload?.repliesToYourMessage === true
767
767
  || event.payload?.someoneWaiting === true;
768
768
 
769
+ // The last line of a reply is nothing but the sentinel. An unaddressed person's
770
+ // `message.posted` counts as nobody waiting, on purpose: text closing on the
771
+ // sentinel there is far likelier reasoning about an ambient message than an
772
+ // answer, and the seat's prompt already sends ambient messages to NO_REPLY.
773
+ const CLOSES_ON_BARE_SENTINEL = /(?:^|\n)[ \t]*NO_REPLY[ \t]*$/;
774
+
769
775
  // The first message in `messages` that this seat posted and `earlierIds` doesn't
770
776
  // hold. The server stamps each message with `self` when it knows who is asking.
771
777
  // Trust that over any local guess: the wrapper cannot derive its own bot username
@@ -2526,6 +2532,7 @@ export const performRun = ({
2526
2532
  // settled; anything thrown after a spawn that resolved means the reply never
2527
2533
  // reached the pod. Off, `turn` writes nothing.
2528
2534
  const runTurn = async (args) => {
2535
+ wrapperSpokeInTurn = false;
2529
2536
  const turn = turnRunner.begin({ eventType: args.event.type });
2530
2537
  try {
2531
2538
  return await runTurnBody({ ...args, turn });
@@ -2553,7 +2560,7 @@ export const performRun = ({
2553
2560
  const key = `model-unavailable:${failure.model || 'unknown'}`;
2554
2561
  try {
2555
2562
  if (!noticeDue(agentName, key, MODEL_UNAVAILABLE_HINT_WINDOW_MS)) return;
2556
- const delivery = await deliverChatReply({
2563
+ const delivery = await deliverTurnNotice({
2557
2564
  client,
2558
2565
  podId: hintPodId,
2559
2566
  text: modelUnavailableHint(failure.model),
@@ -2621,10 +2628,22 @@ export const performRun = ({
2621
2628
  // past its duplicate guard, since a second cut-off has no open ask to carry it.
2622
2629
  // A turn only agents woke gets no line: "ask me again" isn't for them, and in
2623
2630
  // an agent-dm the line would wake the peer into a paid turn.
2624
- const noticeCutOff = async (lostEvents) => {
2631
+ // F279: an event let go after three failures counts too, because the server's
2632
+ // retry is 10 to 20 minutes off and the kernel skips its own line once the
2633
+ // agent has posted. `part` is what one of its attempts posted. It may come back
2634
+ // and fail again, so it hears this once.
2635
+ const noteFailedTurnPart = async (failedEvents) => {
2636
+ if (!failedTurn?.preSpawnIds || wrapperSpokeInTurn) return;
2637
+ const tail = await failedTurn.snapshotMessages(50);
2638
+ const ownPost = tail && newestOwnPostSince(tail, failedTurn.preSpawnIds);
2639
+ if (ownPost) failedEvents.forEach((event) => heldRetryParts.set(String(event._id), ownPost));
2640
+ };
2641
+
2642
+ const noticeCutOff = async (lostEvents, { released = [], part = null } = {}) => {
2625
2643
  const turnArgs = failedTurn;
2626
2644
  failedTurn = null;
2627
- const waiting = lostEvents.filter((event) => event.deliveryMode !== 'digest'
2645
+ const waiting = [...lostEvents, ...released].filter((event) => event.deliveryMode !== 'digest'
2646
+ && !cutOffTold.has(String(event._id))
2628
2647
  && (someoneIsWaiting(event) || PERSON_WAITING_EVENT_TYPES.has(event.type)));
2629
2648
  if (!turnArgs || turnArgs.trigger === 'agent' || waiting.length === 0) return;
2630
2649
  const { eventPodId } = turnArgs;
@@ -2636,8 +2655,9 @@ export const performRun = ({
2636
2655
  // prove this seat replied, and this has no own-post check.
2637
2656
  // It stands on the prompt instead: a person's direct @ isn't offered
2638
2657
  // silence, so their item checkpoints only after a reply. That holds only
2639
- // for a known person, which an 'unknown' comment isn't.
2640
- if (turnArgs.trigger !== 'human') return;
2658
+ // for a known person, which an 'unknown' comment isn't, and for an item
2659
+ // that checkpointed, which a released one didn't.
2660
+ if (turnArgs.trigger !== 'human' || !lostEvents.includes(waiting[0])) return;
2641
2661
  delivery = await deliverCommentReply({
2642
2662
  client, ...target, text: CUT_OFF_NOTICE, onlyIfUnanswered: false,
2643
2663
  });
@@ -2645,7 +2665,8 @@ export const performRun = ({
2645
2665
  const tail = turnArgs.preSpawnIds ? await turnArgs.snapshotMessages(50) : null;
2646
2666
  // Nothing of this seat's in the pod means no half answer to explain: a
2647
2667
  // deliberate silence checkpoints too, and a requeue takes a row as well.
2648
- const ownPost = tail && newestOwnPostSince(tail, turnArgs.preSpawnIds);
2668
+ const ownPost = (lostEvents.some((event) => waiting.includes(event))
2669
+ && tail && newestOwnPostSince(tail, turnArgs.preSpawnIds)) || part;
2649
2670
  if (!ownPost) return;
2650
2671
  delivery = await deliverChatReply({
2651
2672
  client,
@@ -2660,7 +2681,12 @@ export const performRun = ({
2660
2681
  if (delivery.skipped || delivery.refused) {
2661
2682
  log(`[inbox.batch] pod ${eventPodId} was not told this agent was cut off: `
2662
2683
  + `${delivery.reason || 'the notice was not posted'}`);
2663
- } else log(`[inbox.batch] told pod ${eventPodId} this agent was cut off before it finished`);
2684
+ } else {
2685
+ waiting.forEach((event) => cutOffTold.add(String(event._id)));
2686
+ // The line covers every part so far, so a sibling let go later has none.
2687
+ heldRetryParts.clear();
2688
+ log(`[inbox.batch] told pod ${eventPodId} this agent was cut off before it finished`);
2689
+ }
2664
2690
  } catch (noticeError) {
2665
2691
  log(`[inbox.batch] pod ${eventPodId} was not told this agent was cut off: ${noticeError.message}`);
2666
2692
  }
@@ -2801,7 +2827,7 @@ export const performRun = ({
2801
2827
  } catch (error) {
2802
2828
  if (error.code === 'seat_model_missing' && eventPodId && !missingModelNotices.has(eventPodId)) {
2803
2829
  try {
2804
- const delivery = await deliverChatReply({
2830
+ const delivery = await deliverTurnNotice({
2805
2831
  client,
2806
2832
  podId: eventPodId,
2807
2833
  text: "This agent has no model set; add environment.model to its configuration.",
@@ -2997,8 +3023,10 @@ export const performRun = ({
2997
3023
  // output would double-post. Two independent signals suppress the echo:
2998
3024
  // 1. Detection — a new message appeared in the pod during the spawn (the
2999
3025
  // agent posted via the tool). Automatic; no agent cooperation needed.
3000
- // 2. NO_REPLY — the agent explicitly asks us to stay silent. Honored only
3001
- // when it's the ENTIRE reply; mixed content still posts verbatim.
3026
+ // 2. NO_REPLY — the agent explicitly asks us to stay silent: the ENTIRE
3027
+ // reply, or (F192) its last line on a turn nobody is waiting on, where
3028
+ // the text above it is reasoning the server would otherwise post.
3029
+ // Other mixed content still posts verbatim.
3002
3030
  // Otherwise (a bare CLI with no posting tools, or an agent that chose to
3003
3031
  // reply via its output) the wrapper delivers the text as before.
3004
3032
  const replyText = (result.text || '').trim();
@@ -3013,7 +3041,9 @@ export const performRun = ({
3013
3041
  }
3014
3042
  const heartbeatControlReply = (event.type === 'heartbeat' || event.payload?.hasHeartbeat === true)
3015
3043
  && /^(HEARTBEAT_OK|HEARTBEAT_NOOP)$/i.test(replyText);
3016
- const silentReply = !replyText || replyText === 'NO_REPLY' || heartbeatControlReply;
3044
+ const declinedInText = event.type !== 'agent.ask' && !someoneIsWaiting(event)
3045
+ && CLOSES_ON_BARE_SENTINEL.test(replyText);
3046
+ const silentReply = !replyText || replyText === 'NO_REPLY' || heartbeatControlReply || declinedInText;
3017
3047
  // A refused model route is not a silent turn. pi reports the refusal on its
3018
3048
  // own JSON stream and exits 0 with no text, so before this the seat log read
3019
3049
  // `no wrapper-post (empty output)` and the cause — a 429 budget message — was
@@ -3058,7 +3088,8 @@ export const performRun = ({
3058
3088
  }
3059
3089
  }
3060
3090
  } else if (silentReply) {
3061
- const reason = heartbeatControlReply ? replyText : (replyText || 'empty output');
3091
+ const reason = heartbeatControlReply ? replyText
3092
+ : declinedInText ? 'NO_REPLY' : (replyText || 'empty output');
3062
3093
  // A turn that posted via tool and THEN ended with the sentinel is not the
3063
3094
  // same event as a turn that produced nothing — but this branch reported
3064
3095
  // both as `no wrapper-post (NO_REPLY)`, because it is evaluated before
@@ -3401,7 +3432,7 @@ export const performRun = ({
3401
3432
  });
3402
3433
  let posted = false;
3403
3434
  try {
3404
- const delivery = await deliverChatReply({
3435
+ const delivery = await deliverTurnNotice({
3405
3436
  client,
3406
3437
  podId: eventPodId,
3407
3438
  text,
@@ -3460,6 +3491,18 @@ export const performRun = ({
3460
3491
  let tickUnsettled = [];
3461
3492
  // eventId → consecutive local failures, for HELD_RETRY_MAX_FAILURES.
3462
3493
  const heldRetryFailures = new Map();
3494
+ // Event id to what a failed attempt on it posted, for noticeCutOff. Read as each
3495
+ // attempt fails, because the attempt's own snapshot then leaves out the notices
3496
+ // the wrapper posted after earlier ones: those aren't part of an answer. A notice
3497
+ // inside the attempt can't be told from a post that way, so that attempt isn't
3498
+ // read, which can only cost the line.
3499
+ const heldRetryParts = new Map();
3500
+ let wrapperSpokeInTurn = false;
3501
+ const deliverTurnNotice = (notice) => {
3502
+ wrapperSpokeInTurn = true;
3503
+ return deliverChatReply(notice);
3504
+ };
3505
+ const cutOffTold = new Set();
3463
3506
  // eventId → turns passed over, for PAST_CAP_MAX_CARRIES.
3464
3507
  const pastCapCarries = new Map();
3465
3508
  // The current batch's items past the cap. Kept out here because the tick needs
@@ -3514,6 +3557,7 @@ export const performRun = ({
3514
3557
  // tick adds to the carry, never replaces it.
3515
3558
  const holdForRetry = async (failedEvents, untriedEvents = [], pastCap = []) => {
3516
3559
  const released = [];
3560
+ let part = null;
3517
3561
  const carry = [];
3518
3562
  const seen = new Set();
3519
3563
  for (const event of failedEvents) {
@@ -3523,8 +3567,10 @@ export const performRun = ({
3523
3567
  const failures = (heldRetryFailures.get(id) || 0) + 1;
3524
3568
  // A stop wins over the local limit: the sweep would make this event
3525
3569
  // wait 10–20 minutes, and the server's ceiling bounds a hand-back.
3526
- if (running && failures >= HELD_RETRY_MAX_FAILURES) released.push(event);
3527
- else {
3570
+ if (running && failures >= HELD_RETRY_MAX_FAILURES) {
3571
+ released.push(event);
3572
+ part = part || heldRetryParts.get(id) || null;
3573
+ } else {
3528
3574
  heldRetryFailures.set(id, failures);
3529
3575
  carry.push(event);
3530
3576
  }
@@ -3565,6 +3611,7 @@ export const performRun = ({
3565
3611
  if (!running) {
3566
3612
  heldRetry = [...heldRetry, ...carry];
3567
3613
  heldRetryFailures.clear();
3614
+ heldRetryParts.clear();
3568
3615
  pastCapCarries.clear();
3569
3616
  const confirmed = await renewHeldDeliveries(failedEvents);
3570
3617
  return {
@@ -3578,7 +3625,7 @@ export const performRun = ({
3578
3625
  const dropped = carry.filter((event) => !stillHeld(event, confirmed));
3579
3626
  heldRetry = [...heldRetry, ...held];
3580
3627
  const heldIds = new Set(heldRetry.map((event) => String(event._id)));
3581
- for (const counts of [heldRetryFailures, pastCapCarries]) {
3628
+ for (const counts of [heldRetryFailures, heldRetryParts, pastCapCarries]) {
3582
3629
  for (const id of [...counts.keys()]) {
3583
3630
  if (!heldIds.has(id)) counts.delete(id);
3584
3631
  }
@@ -3590,7 +3637,7 @@ export const performRun = ({
3590
3637
  );
3591
3638
  }
3592
3639
  return {
3593
- held, released, handedBack: [], lost: dropped.filter((event) => failedEvents.includes(event)),
3640
+ held, released, part, handedBack: [], lost: dropped.filter((event) => failedEvents.includes(event)),
3594
3641
  };
3595
3642
  };
3596
3643
 
@@ -3648,6 +3695,7 @@ export const performRun = ({
3648
3695
  heldGreeting = [];
3649
3696
  tickUnsettled = [];
3650
3697
  heldRetryFailures.clear();
3698
+ heldRetryParts.clear();
3651
3699
  clearHeldRenewal();
3652
3700
  return carry.length ? handBackDeliveries(carry, 'stop') : Promise.resolve([]);
3653
3701
  };
@@ -4303,8 +4351,10 @@ export const performRun = ({
4303
4351
  nextPollDelayMs = retry.delayMs;
4304
4352
  retryScheduled = true;
4305
4353
  tickUnsettled.push(...claimedAfter(groupIndex));
4354
+ const attempted = failedEvents.filter((event) => !pastCapEvents.includes(event));
4355
+ await noteFailedTurnPart(attempted);
4306
4356
  const hold = await holdForRetry(
4307
- failedEvents.filter((event) => !pastCapEvents.includes(event)),
4357
+ attempted,
4308
4358
  untriedAfter(groupIndex),
4309
4359
  pastCapEvents,
4310
4360
  );
@@ -4337,7 +4387,7 @@ export const performRun = ({
4337
4387
  });
4338
4388
  if (onError) onError(wrapped);
4339
4389
  else log(`[inbox.batch] ${wrapped.message}`);
4340
- await noticeCutOff(hold.lost);
4390
+ await noticeCutOff(hold.lost, { released: hold.released, part: hold.part });
4341
4391
  await noticeCantAnswer(err, [...failedEvents, ...untriedAfter(groupIndex)]);
4342
4392
  };
4343
4393
  let batch;