@commonlyai/cli 0.1.279 → 0.1.280
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 +1 -1
- package/src/commands/agent.js +119 -37
- package/src/lib/enforcement.js +13 -5
- package/src/lib/turn-failure-notice.js +6 -0
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -135,7 +135,7 @@ import {
|
|
|
135
135
|
refusedItemRef,
|
|
136
136
|
sanitizeHandoffAgent,
|
|
137
137
|
} from '../lib/content-refusal.js';
|
|
138
|
-
import { CANT_ANSWER_NOTICE_WINDOW_MS, cantAnswerNotice } from '../lib/turn-failure-notice.js';
|
|
138
|
+
import { CANT_ANSWER_NOTICE_WINDOW_MS, CUT_OFF_NOTICE, cantAnswerNotice } from '../lib/turn-failure-notice.js';
|
|
139
139
|
import {
|
|
140
140
|
ADDRESSED_EVENT_TYPES,
|
|
141
141
|
isPersonMention,
|
|
@@ -766,6 +766,46 @@ 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 first message in `messages` that this seat posted and `earlierIds` doesn't
|
|
770
|
+
// hold. The server stamps each message with `self` when it knows who is asking.
|
|
771
|
+
// Trust that over any local guess: the wrapper cannot derive its own bot username
|
|
772
|
+
// reliably (the server applies LEGACY_AGENT_MAP and an owner-scoped instanceId),
|
|
773
|
+
// and a wrong guess double-posts.
|
|
774
|
+
const findOwnPost = (messages, earlierIds) => {
|
|
775
|
+
const serverKnowsSelf = messages.some((m) => typeof m.self === 'boolean');
|
|
776
|
+
for (const m of messages) {
|
|
777
|
+
// A new human-authored message must NEVER count: it is either a human
|
|
778
|
+
// typing mid-turn, or the agent misusing an operator CLI profile / human
|
|
779
|
+
// token (the 2026-07-22 as-operator attribution incident) — in both cases
|
|
780
|
+
// the wrapper still delivers the reply under the agent's own identity.
|
|
781
|
+
//
|
|
782
|
+
// With `self`, only THIS agent's own post counts. Without it (an older
|
|
783
|
+
// server), fall back to the legacy any-bot test — which drops this agent's
|
|
784
|
+
// reply whenever another agent answers first (#757).
|
|
785
|
+
if (!earlierIds.has(String(m._id || m.id)) && m.isBot && (serverKnowsSelf ? m.self === true : true)) {
|
|
786
|
+
return {
|
|
787
|
+
id: String(m._id || m.id),
|
|
788
|
+
author: m.username || 'unknown',
|
|
789
|
+
basis: serverKnowsSelf ? 'self' : 'legacy-any-bot',
|
|
790
|
+
threadRootId: m.thread_root_id ?? null,
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return null;
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
// This seat's newest post in `tail` that came after the last row `knownIds` holds,
|
|
798
|
+
// or null when that can't be shown. `knownIds` is a 10-message snapshot, so a row
|
|
799
|
+
// missing from it may only be older, and just "not in the set" would count an old
|
|
800
|
+
// post as new. With no known row in the tail, nothing marks where the turn began.
|
|
801
|
+
// An older server has no `self`, so a peer's post can't be told from this seat's.
|
|
802
|
+
const newestOwnPostSince = (tail, knownIds) => {
|
|
803
|
+
const lastKnown = tail.findLastIndex((m) => knownIds.has(String(m._id || m.id)));
|
|
804
|
+
if (lastKnown === -1) return null;
|
|
805
|
+
const ownPost = findOwnPost(tail.slice(lastKnown + 1).reverse(), knownIds);
|
|
806
|
+
return ownPost?.basis === 'self' ? ownPost : null;
|
|
807
|
+
};
|
|
808
|
+
|
|
769
809
|
// How long a fresh seat's greeting waits for a person before it runs alone.
|
|
770
810
|
// One poll lost the race on the 0.1.257 walk (2026-11-05): the mention landed
|
|
771
811
|
// just after the hold, the greeting took the next turn alone, and the answer
|
|
@@ -2480,6 +2520,7 @@ export const performRun = ({
|
|
|
2480
2520
|
return await runTurnBody({ ...args, turn });
|
|
2481
2521
|
} catch (error) {
|
|
2482
2522
|
turn.finish('reply_lost');
|
|
2523
|
+
failedTurn = args;
|
|
2483
2524
|
// codex and claude both keep a refused prompt in the thread, and send it
|
|
2484
2525
|
// again on every resume (measured 2026-11-05 on codex 0.162.1 and claude
|
|
2485
2526
|
// 2.1.318), so one refusal would refuse every later turn in this pod. The
|
|
@@ -2560,6 +2601,60 @@ export const performRun = ({
|
|
|
2560
2601
|
}
|
|
2561
2602
|
};
|
|
2562
2603
|
|
|
2604
|
+
// F256: a turn that threw after it posted, whose event the server no longer
|
|
2605
|
+
// holds. The usual way there is a child that checkpointed after part one of an
|
|
2606
|
+
// answer and was then killed, so nothing will retry it and the person holds a
|
|
2607
|
+
// promise of more. Only `lostEvents` reach here, so a turn that ended cleanly
|
|
2608
|
+
// never does, and neither does one whose event is retried or handed back.
|
|
2609
|
+
// No window of its own: an event is lost once, and in a shared pod the server's
|
|
2610
|
+
// duplicate guard already bounds a fixed line to one per 30 minutes.
|
|
2611
|
+
// A turn only agents woke gets no line: "ask me again" isn't for them, and in
|
|
2612
|
+
// an agent-dm the line would wake the peer into a paid turn.
|
|
2613
|
+
const noticeCutOff = async (lostEvents) => {
|
|
2614
|
+
const turnArgs = failedTurn;
|
|
2615
|
+
failedTurn = null;
|
|
2616
|
+
const waiting = lostEvents.filter((event) => event.deliveryMode !== 'digest'
|
|
2617
|
+
&& (someoneIsWaiting(event) || PERSON_WAITING_EVENT_TYPES.has(event.type)));
|
|
2618
|
+
if (!turnArgs || turnArgs.trigger === 'agent' || waiting.length === 0) return;
|
|
2619
|
+
const { eventPodId } = turnArgs;
|
|
2620
|
+
const target = commentTargetOf(waiting[0]);
|
|
2621
|
+
try {
|
|
2622
|
+
let delivery;
|
|
2623
|
+
if (target) {
|
|
2624
|
+
// The only comment read is capped and carries no `self` stamp, so it can't
|
|
2625
|
+
// prove this seat replied, and this has no own-post check.
|
|
2626
|
+
// It stands on the prompt instead: a person's direct @ isn't offered
|
|
2627
|
+
// silence, so their item checkpoints only after a reply. That holds only
|
|
2628
|
+
// for a known person, which an 'unknown' comment isn't.
|
|
2629
|
+
if (turnArgs.trigger !== 'human') return;
|
|
2630
|
+
delivery = await deliverCommentReply({
|
|
2631
|
+
client, ...target, text: CUT_OFF_NOTICE, onlyIfUnanswered: false,
|
|
2632
|
+
});
|
|
2633
|
+
} else {
|
|
2634
|
+
const tail = turnArgs.preSpawnIds ? await turnArgs.snapshotMessages(50) : null;
|
|
2635
|
+
// Nothing of this seat's in the pod means no half answer to explain: a
|
|
2636
|
+
// deliberate silence checkpoints too, and a requeue takes a row as well.
|
|
2637
|
+
const ownPost = tail && newestOwnPostSince(tail, turnArgs.preSpawnIds);
|
|
2638
|
+
if (!ownPost) return;
|
|
2639
|
+
delivery = await deliverChatReply({
|
|
2640
|
+
client,
|
|
2641
|
+
podId: eventPodId,
|
|
2642
|
+
text: CUT_OFF_NOTICE,
|
|
2643
|
+
limit: chatCharLimit,
|
|
2644
|
+
maxChunks: maxChatChunks,
|
|
2645
|
+
threadRootId: ownPost.threadRootId === null ? null : String(ownPost.threadRootId),
|
|
2646
|
+
log: (line) => log(`[inbox.batch] ${line}`),
|
|
2647
|
+
});
|
|
2648
|
+
}
|
|
2649
|
+
if (delivery.skipped || delivery.refused) {
|
|
2650
|
+
log(`[inbox.batch] pod ${eventPodId} was not told this agent was cut off: `
|
|
2651
|
+
+ `${delivery.reason || 'the notice was not posted'}`);
|
|
2652
|
+
} else log(`[inbox.batch] told pod ${eventPodId} this agent was cut off before it finished`);
|
|
2653
|
+
} catch (noticeError) {
|
|
2654
|
+
log(`[inbox.batch] pod ${eventPodId} was not told this agent was cut off: ${noticeError.message}`);
|
|
2655
|
+
}
|
|
2656
|
+
};
|
|
2657
|
+
|
|
2563
2658
|
const runTurnBody = async ({
|
|
2564
2659
|
event, eventPodId, prompt, preSpawnIds, snapshotMessages, claimKeeper, trigger, turn,
|
|
2565
2660
|
}) => {
|
|
@@ -2901,32 +2996,8 @@ export const performRun = ({
|
|
|
2901
2996
|
if (preSpawnIds) {
|
|
2902
2997
|
const postSpawn = await snapshotMessages();
|
|
2903
2998
|
if (postSpawn) {
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
// its own bot username reliably (the server applies LEGACY_AGENT_MAP
|
|
2907
|
-
// and an owner-scoped instanceId), and a wrong guess double-posts.
|
|
2908
|
-
const serverKnowsSelf = postSpawn.some((m) => typeof m.self === 'boolean');
|
|
2909
|
-
for (const m of postSpawn) {
|
|
2910
|
-
if (preSpawnIds.has(String(m._id || m.id))) continue;
|
|
2911
|
-
// A new human-authored message must NEVER suppress the echo: it is
|
|
2912
|
-
// either a human typing mid-turn, or the agent misusing an operator
|
|
2913
|
-
// CLI profile / human token (the 2026-07-22 as-operator attribution
|
|
2914
|
-
// incident) — in both cases the wrapper still delivers the reply
|
|
2915
|
-
// under the agent's own identity.
|
|
2916
|
-
if (!m.isBot) continue;
|
|
2917
|
-
// With `self`, only THIS agent's own post suppresses. Without it (an
|
|
2918
|
-
// older server), fall back to the legacy any-bot test — which drops
|
|
2919
|
-
// this agent's reply whenever another agent answers first (#757).
|
|
2920
|
-
if (serverKnowsSelf ? m.self === true : true) {
|
|
2921
|
-
agentPostedItself = true;
|
|
2922
|
-
suppressedBy = {
|
|
2923
|
-
id: String(m._id || m.id),
|
|
2924
|
-
author: m.username || 'unknown',
|
|
2925
|
-
basis: serverKnowsSelf ? 'self' : 'legacy-any-bot',
|
|
2926
|
-
};
|
|
2927
|
-
break;
|
|
2928
|
-
}
|
|
2929
|
-
}
|
|
2999
|
+
suppressedBy = findOwnPost(postSpawn, preSpawnIds);
|
|
3000
|
+
agentPostedItself = Boolean(suppressedBy);
|
|
2930
3001
|
}
|
|
2931
3002
|
}
|
|
2932
3003
|
const heartbeatControlReply = (event.type === 'heartbeat' || event.payload?.hasHeartbeat === true)
|
|
@@ -3228,7 +3299,7 @@ export const performRun = ({
|
|
|
3228
3299
|
const channelLine = answersInChannel(entry) ? `\n${ANSWER_IN_CHANNEL}` : '';
|
|
3229
3300
|
const deliveryId = entry.event.payload?.deliveryId;
|
|
3230
3301
|
const checkpoint = typeof deliveryId === 'string' && deliveryId
|
|
3231
|
-
? `\n[After ${answersAPerson(entry) ? '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({
|
|
3302
|
+
? `\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({
|
|
3232
3303
|
eventId: String(entry.event._id), deliveryId,
|
|
3233
3304
|
})}). Checkpoint metadata is private runtime data; never post it in chat.]`
|
|
3234
3305
|
: '';
|
|
@@ -3250,7 +3321,8 @@ export const performRun = ({
|
|
|
3250
3321
|
`After tool-side work is committed (including any reply posted through a tool)${answersPerson ? ',' : ', or an intentional NO_REPLY,'} checkpoint that item with its supplied IDs. `
|
|
3251
3322
|
+ 'Release any held message claim first with the correct completed/declined outcome. '
|
|
3252
3323
|
+ 'Do not checkpoint a reply you are holding for final CLI output: the wrapper must post it before acknowledging that item. '
|
|
3253
|
-
+ 'Never checkpoint unfinished work
|
|
3324
|
+
+ 'Never checkpoint unfinished work: an answer in several posts is finished only after its last post. '
|
|
3325
|
+
+ 'Only a successful checkpoint prevents replay after timeout. '
|
|
3254
3326
|
+ 'If the tool is unavailable, continue normally; completion will acknowledge the batch.',
|
|
3255
3327
|
...bodies,
|
|
3256
3328
|
...(heldBack > 0
|
|
@@ -3382,6 +3454,8 @@ export const performRun = ({
|
|
|
3382
3454
|
// The current batch's items past the cap. Kept out here because the tick needs
|
|
3383
3455
|
// them when the turn throws, and a throw returns no entries.
|
|
3384
3456
|
let pastCapEvents = [];
|
|
3457
|
+
// The arguments of the turn that just threw, for noticeCutOff.
|
|
3458
|
+
let failedTurn = null;
|
|
3385
3459
|
let heldRenewTimer = null;
|
|
3386
3460
|
const clearHeldRenewal = () => {
|
|
3387
3461
|
if (heldRenewTimer !== null) clearIntervalImpl(heldRenewTimer);
|
|
@@ -3472,15 +3546,19 @@ export const performRun = ({
|
|
|
3472
3546
|
+ 'to the server\'s requeue (redelivered in ~10–20 min)',
|
|
3473
3547
|
);
|
|
3474
3548
|
}
|
|
3475
|
-
// A stopping run carries nothing
|
|
3476
|
-
//
|
|
3477
|
-
//
|
|
3478
|
-
//
|
|
3549
|
+
// A stopping run carries nothing, because its carry is handed back to the
|
|
3550
|
+
// server when the tick ends (F189), so the next run answers it on its first
|
|
3551
|
+
// poll. It renews only the failed turn's own events, to learn which of them
|
|
3552
|
+
// it still holds: that hand-back follows at once, so the replacement doesn't
|
|
3553
|
+
// wait on the longer lease.
|
|
3479
3554
|
if (!running) {
|
|
3480
3555
|
heldRetry = [...heldRetry, ...carry];
|
|
3481
3556
|
heldRetryFailures.clear();
|
|
3482
3557
|
pastCapCarries.clear();
|
|
3483
|
-
|
|
3558
|
+
const confirmed = await renewHeldDeliveries(failedEvents);
|
|
3559
|
+
return {
|
|
3560
|
+
held: [], released, handedBack: carry, lost: failedEvents.filter((event) => !stillHeld(event, confirmed)),
|
|
3561
|
+
};
|
|
3484
3562
|
}
|
|
3485
3563
|
const confirmed = carry.length ? await renewHeldDeliveries(carry) : null;
|
|
3486
3564
|
// The stop landed during that renewal, after the limits were applied.
|
|
@@ -3500,7 +3578,9 @@ export const performRun = ({
|
|
|
3500
3578
|
+ '(checkpointed, requeued or retired) — not retried',
|
|
3501
3579
|
);
|
|
3502
3580
|
}
|
|
3503
|
-
return {
|
|
3581
|
+
return {
|
|
3582
|
+
held, released, handedBack: [], lost: dropped.filter((event) => failedEvents.includes(event)),
|
|
3583
|
+
};
|
|
3504
3584
|
};
|
|
3505
3585
|
|
|
3506
3586
|
// F189/F182: hand claimed events this run will never run back to the
|
|
@@ -3609,6 +3689,7 @@ export const performRun = ({
|
|
|
3609
3689
|
|
|
3610
3690
|
const handleEventBatch = async (events, inboxCount = events.length) => {
|
|
3611
3691
|
pastCapEvents = [];
|
|
3692
|
+
failedTurn = null;
|
|
3612
3693
|
const eventPodId = events[0]?.podId || podId;
|
|
3613
3694
|
if (!eventPodId || events.some((event) => (event.podId || podId) !== eventPodId)) {
|
|
3614
3695
|
throw new Error('Inbox batch crossed pod boundaries; refusing to mix private pod context');
|
|
@@ -3660,10 +3741,10 @@ export const performRun = ({
|
|
|
3660
3741
|
// Null until the server says: a failed read or an older server is unknown,
|
|
3661
3742
|
// not "alone" and not "with peers".
|
|
3662
3743
|
let podAttendance = null;
|
|
3663
|
-
const snapshotMessages = async () => {
|
|
3744
|
+
const snapshotMessages = async (limit = 10) => {
|
|
3664
3745
|
try {
|
|
3665
3746
|
const { messages = [], otherAgentsInPod, peopleInPod } = await client.get(
|
|
3666
|
-
`/api/agents/runtime/pods/${eventPodId}/messages`, { limit
|
|
3747
|
+
`/api/agents/runtime/pods/${eventPodId}/messages`, { limit },
|
|
3667
3748
|
);
|
|
3668
3749
|
podAttendance = typeof otherAgentsInPod === 'boolean' ? { otherAgentsInPod, peopleInPod } : null;
|
|
3669
3750
|
return messages;
|
|
@@ -4248,6 +4329,7 @@ export const performRun = ({
|
|
|
4248
4329
|
});
|
|
4249
4330
|
if (onError) onError(wrapped);
|
|
4250
4331
|
else log(`[inbox.batch] ${wrapped.message}`);
|
|
4332
|
+
await noticeCutOff(hold.lost);
|
|
4251
4333
|
await noticeCantAnswer(err, [...failedEvents, ...untriedAfter(groupIndex)]);
|
|
4252
4334
|
};
|
|
4253
4335
|
let batch;
|
package/src/lib/enforcement.js
CHANGED
|
@@ -649,16 +649,19 @@ export const splitForChat = (text, { limit = 400 } = {}) => {
|
|
|
649
649
|
* `onlyIfUnanswered` is how a reply the seat already posted through
|
|
650
650
|
* commonly_post_thread_comment is not posted twice: a pod snapshot can't see a
|
|
651
651
|
* comment, and the server can. A 400, 403 or 404 won't change on a retry, so it
|
|
652
|
-
* is a refusal too; anything else throws, for redelivery.
|
|
652
|
+
* is a refusal too; anything else throws, for redelivery. A line that must land
|
|
653
|
+
* after the seat's own reply passes `onlyIfUnanswered: false`.
|
|
653
654
|
*/
|
|
654
|
-
export const deliverCommentReply = async ({
|
|
655
|
+
export const deliverCommentReply = async ({
|
|
656
|
+
client, postId, commentId, text, onlyIfUnanswered = true,
|
|
657
|
+
}) => {
|
|
655
658
|
const refused = (reason, guidance) => ({
|
|
656
659
|
mode: 'refused', messages: 0, attemptedMessages: 1, refused: true, reason, guidance,
|
|
657
660
|
});
|
|
658
661
|
let response;
|
|
659
662
|
try {
|
|
660
663
|
response = await client.post(`/api/agents/runtime/threads/${encodeURIComponent(postId)}/comments`, {
|
|
661
|
-
content: text, replyToCommentId: commentId, onlyIfUnanswered
|
|
664
|
+
content: text, replyToCommentId: commentId, onlyIfUnanswered,
|
|
662
665
|
});
|
|
663
666
|
} catch (error) {
|
|
664
667
|
if (![400, 403, 404].includes(error?.status)) throw error;
|
|
@@ -726,6 +729,10 @@ export const deliverChatReply = async ({
|
|
|
726
729
|
// D245 item 4: how this reply was made (lib/reply-receipt.js). It rides
|
|
727
730
|
// the first message that actually reaches the pod and no later one.
|
|
728
731
|
receipt = null,
|
|
732
|
+
// Keeps a reply that fits in up to maxChunks messages in that thread. The
|
|
733
|
+
// overflow rungs below start their own thread, so a caller with a long reply
|
|
734
|
+
// doesn't set this.
|
|
735
|
+
threadRootId = null,
|
|
729
736
|
}) => {
|
|
730
737
|
const messagesPath = `/api/agents/runtime/pods/${podId}/messages`;
|
|
731
738
|
const chunks = splitForChat(text, { limit });
|
|
@@ -838,8 +845,9 @@ export const deliverChatReply = async ({
|
|
|
838
845
|
// this check a 659-char fence rode the single/split branches straight past
|
|
839
846
|
// the gate (found by the fleet's implementation audit).
|
|
840
847
|
const hasIndivisibleOversize = chunks.some((c) => c.length > attachThreshold);
|
|
848
|
+
const placement = threadRootId ? { threadRootId } : {};
|
|
841
849
|
if (chunks.length <= 1 && !hasIndivisibleOversize) {
|
|
842
|
-
const response = await postOnce({ content: chunks[0] ?? text });
|
|
850
|
+
const response = await postOnce({ content: chunks[0] ?? text, ...placement });
|
|
843
851
|
if (undelivered(response)) return nonDelivery(response, 0, 1);
|
|
844
852
|
return { mode: 'single', messages: 1 };
|
|
845
853
|
}
|
|
@@ -847,7 +855,7 @@ export const deliverChatReply = async ({
|
|
|
847
855
|
let messages = 0;
|
|
848
856
|
for (const chunk of chunks) {
|
|
849
857
|
// eslint-disable-next-line no-await-in-loop
|
|
850
|
-
const response = await postOnce({ content: chunk }); // in order, so the reply reads top-down
|
|
858
|
+
const response = await postOnce({ content: chunk, ...placement }); // in order, so the reply reads top-down
|
|
851
859
|
if (undelivered(response)) return nonDelivery(response, messages, chunks.length);
|
|
852
860
|
messages += 1;
|
|
853
861
|
}
|
|
@@ -55,6 +55,12 @@ export const WONT_START_NOTICE = 'I can’t answer right now: the tool I run on
|
|
|
55
55
|
export const OUT_OF_ALLOWANCE_NOTICE = 'I can’t answer right now: the AI account I run on has used up its allowance. '
|
|
56
56
|
+ `It needs to reset, or whoever runs me needs to add more. ${AGAIN}`;
|
|
57
57
|
|
|
58
|
+
// A turn that had posted, whose event the server had settled, and that then
|
|
59
|
+
// stopped. The event won't come back, so this is all the person hears. Hedged,
|
|
60
|
+
// because a kill can land after the last word: a checkpoint says the seat
|
|
61
|
+
// finished an item, and part one of an answer has been enough to earn one.
|
|
62
|
+
export const CUT_OFF_NOTICE = 'I got cut off before I could finish that, so please ask me again if anything is missing.';
|
|
63
|
+
|
|
58
64
|
export const codexVersionNotice = (required) => 'I can’t answer right now: the computer I run on needs '
|
|
59
65
|
+ `Codex ${required} or newer. Whoever runs me needs to upgrade it and start me again. ${AGAIN}`;
|
|
60
66
|
|