@commonlyai/cli 0.1.301 → 0.1.302

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.301",
3
+ "version": "0.1.302",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -857,6 +857,7 @@ const findOwnPost = (messages, earlierIds) => {
857
857
  author: m.username || 'unknown',
858
858
  basis: serverKnowsSelf ? 'self' : 'legacy-any-bot',
859
859
  threadRootId: m.thread_root_id ?? null,
860
+ content: typeof m.content === 'string' ? m.content : '',
860
861
  };
861
862
  }
862
863
  }
@@ -1840,6 +1841,28 @@ const FINAL_TEXT_ANSWERS_A_PERSON = 'Your final text is posted to the pod unless
1840
1841
  + 'Use NO_REPLY alone only after you posted your answer through a tool, with no summary. '
1841
1842
  + FAILURE_IN_PLAIN_WORDS;
1842
1843
 
1844
+ // F335: a turn that posted through a tool and then failed is retried with the
1845
+ // same prompt, often in a fresh session, so nothing tells the retry its answer
1846
+ // is already up. It names that post, so the retry adds what's missing or stays
1847
+ // silent instead of answering the person a second time. A batch's attempt can't
1848
+ // say which item its post answered, so in a batch the line says so.
1849
+ const EARLIER_ATTEMPT_EXCERPT = 300;
1850
+ export const earlierAttemptPosted = (part, { batch = false } = {}) => {
1851
+ const text = String(part?.content || '').replace(/\s+/g, ' ').trim();
1852
+ const cut = text.length > EARLIER_ATTEMPT_EXCERPT;
1853
+ const excerpt = cut ? `${text.slice(0, EARLIER_ATTEMPT_EXCERPT)}…` : text;
1854
+ return `[An earlier attempt at ${batch ? 'this batch' : 'this item'} failed after it posted in this pod (message ${part.id})`
1855
+ + `${excerpt ? `, beginning ${JSON.stringify(excerpt)}` : ''}. That post is already there: don't post it again. `
1856
+ + (batch ? 'It may answer this item or another one here. ' : '')
1857
+ + (cut ? 'Read that message in full before you decide. ' : '')
1858
+ + 'Add only what this item still lacks, then checkpoint. '
1859
+ + (batch
1860
+ ? 'If it already answers this item, checkpoint this item and go on to the others here; '
1861
+ + 'end with NO_REPLY only once every item is handled.]'
1862
+ : 'If it already answers this item, checkpoint it and end with NO_REPLY. '
1863
+ + 'An acknowledgement such as "on it" does not answer it.]');
1864
+ };
1865
+
1843
1866
  export const answersAPerson = (entry) => (
1844
1867
  entry?.trigger === 'human' && ADDRESSED_EVENT_TYPES.has(entry.event?.type) && !entry.peerFrame
1845
1868
  && !entry.event.payload?.adjacentReply && !entry.event.payload?.welcomeWake
@@ -2559,12 +2582,17 @@ export const performRun = ({
2559
2582
  }
2560
2583
  }
2561
2584
 
2585
+ // A private item (an agent.ask.response turn may post a pod update) is
2586
+ // retried here, not in a batch, so it hears what its attempt posted here
2587
+ // too. A comment is answered in its thread, so it is not.
2588
+ const earlierPart = isCommentWake(event) ? null : heldRetryParts.get(String(event._id));
2589
+ const earlierLine = earlierPart ? `\n\n${earlierAttemptPosted(earlierPart)}` : '';
2562
2590
  let turnResult;
2563
2591
  try {
2564
2592
  turnResult = await runTurn({
2565
2593
  event,
2566
2594
  eventPodId,
2567
- prompt: peerFrame ? `${peerFrame}\n\n${prompt}` : prompt,
2595
+ prompt: `${peerFrame ? `${peerFrame}\n\n` : ''}${prompt}${earlierLine}`,
2568
2596
  preSpawnIds,
2569
2597
  snapshotMessages,
2570
2598
  claimKeeper,
@@ -2700,7 +2728,10 @@ export const performRun = ({
2700
2728
  if (!failedTurn?.preSpawnIds || wrapperSpokeInTurn) return;
2701
2729
  const tail = await failedTurn.snapshotMessages(50);
2702
2730
  const ownPost = tail && newestOwnPostSince(tail, failedTurn.preSpawnIds);
2703
- if (ownPost) failedEvents.forEach((event) => heldRetryParts.set(String(event._id), ownPost));
2731
+ // `solo`: the attempt carried only this item, so its post can only be this
2732
+ // item's. A batch's post may answer any item in it.
2733
+ const solo = failedEvents.length === 1;
2734
+ if (ownPost) failedEvents.forEach((event) => heldRetryParts.set(String(event._id), { ...ownPost, solo }));
2704
2735
  };
2705
2736
 
2706
2737
  const noticeCutOff = async (lostEvents, { released = [], part = null } = {}) => {
@@ -3417,13 +3448,20 @@ export const performRun = ({
3417
3448
  const body = entry.prompt || '[No usable prompt was delivered for this item.]';
3418
3449
  const personLine = answersAPerson(entry) ? `\n${PERSON_ADDRESSED}` : '';
3419
3450
  const channelLine = answersInChannel(entry) ? `\n${ANSWER_IN_CHANNEL}` : '';
3451
+ // A peer's item is read-only, and a comment is answered in its thread, not
3452
+ // by a pod post: neither is told to stop at what the attempt posted.
3453
+ const earlierPart = entry.readOnly || isCommentWake(entry.event)
3454
+ ? null : heldRetryParts.get(String(entry.event._id));
3455
+ const earlierLine = earlierPart
3456
+ ? `\n${earlierAttemptPosted(earlierPart, { batch: shownEntries.length > 1 })}`
3457
+ : '';
3420
3458
  const deliveryId = entry.event.payload?.deliveryId;
3421
3459
  const checkpoint = typeof deliveryId === 'string' && deliveryId
3422
3460
  ? `\n[After ${answersAPerson(entry) ? 'all of your answer is posted through a tool' : 'completed tool-side work or intentional NO_REPLY'} for only this item, call commonly_checkpoint_event(${JSON.stringify({
3423
3461
  eventId: String(entry.event._id), deliveryId,
3424
3462
  })}). Checkpoint metadata is private runtime data; never post it in chat.]`
3425
3463
  : '';
3426
- return `${prefix}\n${claimContext}${body}${personLine}${channelLine}${checkpoint}`;
3464
+ return `${prefix}\n${claimContext}${body}${personLine}${channelLine}${earlierLine}${checkpoint}`;
3427
3465
  });
3428
3466
  const rollup = wakeEntries.find((entry) => entry.event.payload?.digestRollup)?.event.payload?.digestRollup;
3429
3467
  const digestEvents = digestEntries.map((entry) => entry.event);
@@ -4175,6 +4213,15 @@ export const performRun = ({
4175
4213
  // An item left without a result (a failure during isolation)
4176
4214
  // releases with no outcome, for redelivery, as a thrown turn does.
4177
4215
  const release = claimReleaseFor(entry.event, entry.result || turnResult);
4216
+ // A retry that chose NO_REPLY because its single-item attempt already
4217
+ // posted the answer answered the person, so it closes, never handed
4218
+ // to another listener. A retry that printed nothing chose nothing,
4219
+ // and a batch's post may be another item's: both still decline, so a
4220
+ // batch whose post answered every item can be handed on (a known
4221
+ // limit; telling which item a post answered needs a signal we lack).
4222
+ if (release.outcome === 'declined' && actionEntries.length === 1
4223
+ && (entry.result || turnResult)?.reason !== EMPTY_OUTPUT
4224
+ && heldRetryParts.get(String(entry.event._id))?.solo) release.outcome = 'completed';
4178
4225
  await entry.claimKeeper.release(release.outcome, {
4179
4226
  reason: release.reason, status: release.status,
4180
4227
  });
@@ -4563,6 +4610,10 @@ export const performRun = ({
4563
4610
  // Carried to the retry like a failed batch: the event is claimed,
4564
4611
  // so the next poll would not return it.
4565
4612
  tickUnsettled.push(...claimedAfter(groupIndex));
4613
+ // Only this event's own turn: a throw before its spawn leaves an
4614
+ // earlier turn's arguments, possibly another pod's, in failedTurn.
4615
+ // eslint-disable-next-line no-await-in-loop
4616
+ if (failedTurn?.event === event) await noteFailedTurnPart([event]);
4566
4617
  // eslint-disable-next-line no-await-in-loop
4567
4618
  const hold = await holdForRetry([event], untriedAfter(groupIndex));
4568
4619
  keepHeldLeases(retry.delayMs);