@commonlyai/cli 0.1.154 → 0.1.156
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 +3 -31
- package/src/lib/digest-frame.js +42 -0
- package/src/lib/poller.js +2 -36
- package/src/lib/spawn-retry.js +47 -1
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
} from '../lib/spawn-credential.js';
|
|
28
28
|
import { getToken, resolveInstanceUrl } from '../lib/config.js';
|
|
29
29
|
import { startPoller, terminalDeliveryAckError } from '../lib/poller.js';
|
|
30
|
+
import { formatDigestFrame } from '../lib/digest-frame.js';
|
|
30
31
|
import { startWebhookServer, forwardToLocalWebhook } from '../lib/webhook-server.js';
|
|
31
32
|
import { getAdapter, listAdapterNames } from '../lib/adapters/index.js';
|
|
32
33
|
import {
|
|
@@ -2027,42 +2028,13 @@ export const performRun = ({
|
|
|
2027
2028
|
return `${prefix}\n${claimContext}${body}`;
|
|
2028
2029
|
});
|
|
2029
2030
|
const rollup = wakeEntries.find((entry) => entry.event.payload?.digestRollup)?.event.payload?.digestRollup;
|
|
2030
|
-
const
|
|
2031
|
-
let knownOlder = 0;
|
|
2032
|
-
for (const conversation of Array.isArray(rollup?.conversations) ? rollup.conversations : []) {
|
|
2033
|
-
if (typeof conversation.label !== 'string' || !Number.isInteger(conversation.count)
|
|
2034
|
-
|| conversation.count < 1) continue;
|
|
2035
|
-
conversationCounts.set(conversation.label,
|
|
2036
|
-
(conversationCounts.get(conversation.label) || 0) + conversation.count);
|
|
2037
|
-
knownOlder += conversation.count;
|
|
2038
|
-
}
|
|
2039
|
-
if (rollup?.unreadCount > knownOlder) {
|
|
2040
|
-
conversationCounts.set('older pod activity', rollup.unreadCount - knownOlder);
|
|
2041
|
-
}
|
|
2042
|
-
const seenDigestSources = new Set();
|
|
2043
|
-
for (const entry of digestEntries) {
|
|
2044
|
-
const { threadRootId, taskId, taskKind, messageId, content } = entry.event.payload || {};
|
|
2045
|
-
const sourceId = messageId != null ? `message:${messageId}`
|
|
2046
|
-
: (typeof taskId === 'string' ? `task:${taskId}:${taskKind || ''}:${content || ''}` : null);
|
|
2047
|
-
if (sourceId && seenDigestSources.has(sourceId)) continue;
|
|
2048
|
-
if (sourceId) seenDigestSources.add(sourceId);
|
|
2049
|
-
const label = Number.isInteger(Number(threadRootId)) && Number(threadRootId) > 0
|
|
2050
|
-
? `thread ${threadRootId}`
|
|
2051
|
-
: (/^TASK-\d+$/.test(String(taskId || '')) ? taskId : 'pod conversation');
|
|
2052
|
-
conversationCounts.set(label, (conversationCounts.get(label) || 0) + 1);
|
|
2053
|
-
}
|
|
2054
|
-
const digestLines = [...conversationCounts].slice(0, 8)
|
|
2055
|
-
.map(([label, count]) => `- ${label}: ${count} unread`);
|
|
2056
|
-
const digestCount = [...conversationCounts.values()].reduce((sum, count) => sum + count, 0);
|
|
2031
|
+
const digestFrame = formatDigestFrame(digestEntries.map((entry) => entry.event), rollup);
|
|
2057
2032
|
const omitted = Math.max(0, inboxCount - entries.length);
|
|
2058
2033
|
return [
|
|
2059
2034
|
`[Inbox batch: ${inboxCount} new event${inboxCount === 1 ? '' : 's'} in this pod. `
|
|
2060
2035
|
+ 'This is one turn: read the included items together, then decide what needs YOU.]',
|
|
2061
2036
|
...bodies,
|
|
2062
|
-
...(
|
|
2063
|
-
`[Since you last looked: ${digestCount} ambient update${digestCount === 1 ? '' : 's'} in ${conversationCounts.size} conversation${conversationCounts.size === 1 ? '' : 's'}; context only, no reply needed.]
|
|
2064
|
-
${digestLines.join('\n')}${conversationCounts.size > 8 ? `\n- ${conversationCounts.size - 8} more conversations omitted` : ''}\nPull relevant messages with commonly_get_messages. On resume, read oldest unread first; at most 8 conversations, 5 messages each, 20 messages total.`,
|
|
2065
|
-
] : []),
|
|
2037
|
+
...(digestFrame ? [digestFrame] : []),
|
|
2066
2038
|
...(omitted > 0
|
|
2067
2039
|
? [`[${omitted} more event${omitted === 1 ? '' : 's'} arrived. Their count is real; pull pod context if needed.]`]
|
|
2068
2040
|
: []),
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// One counts-only frame for both the wrapper run loop and agent connect.
|
|
2
|
+
// Ambient bodies stay in the inbox; waking turns receive conversation counts.
|
|
3
|
+
export const formatDigestFrame = (events, rollup) => {
|
|
4
|
+
if (events.length === 0 && !(rollup?.unreadCount > 0)) return null;
|
|
5
|
+
|
|
6
|
+
const counts = new Map();
|
|
7
|
+
let knownOlder = 0;
|
|
8
|
+
for (const conversation of Array.isArray(rollup?.conversations) ? rollup.conversations : []) {
|
|
9
|
+
if (typeof conversation.label !== 'string' || !Number.isInteger(conversation.count)
|
|
10
|
+
|| conversation.count < 1) continue;
|
|
11
|
+
counts.set(conversation.label, (counts.get(conversation.label) || 0) + conversation.count);
|
|
12
|
+
knownOlder += conversation.count;
|
|
13
|
+
}
|
|
14
|
+
if (rollup?.unreadCount > knownOlder) {
|
|
15
|
+
counts.set('older pod activity',
|
|
16
|
+
(counts.get('older pod activity') || 0) + rollup.unreadCount - knownOlder);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
for (const event of events) {
|
|
21
|
+
const payload = event.payload || {};
|
|
22
|
+
const sourceId = payload.messageId != null ? `message:${payload.messageId}`
|
|
23
|
+
: (typeof payload.taskId === 'string'
|
|
24
|
+
? `task:${payload.taskId}:${String(payload.taskKind || '')}:${String(payload.content || '')}` : null);
|
|
25
|
+
if (sourceId && seen.has(sourceId)) continue;
|
|
26
|
+
if (sourceId) seen.add(sourceId);
|
|
27
|
+
|
|
28
|
+
const thread = payload.threadRootId;
|
|
29
|
+
const task = payload.taskId;
|
|
30
|
+
const validThread = (typeof thread === 'number' && Number.isInteger(thread) && thread > 0)
|
|
31
|
+
|| (typeof thread === 'string' && /^[1-9]\d*$/.test(thread));
|
|
32
|
+
const label = validThread ? `thread ${thread}`
|
|
33
|
+
: (typeof task === 'string' && /^TASK-\d+$/.test(task) ? task : 'pod conversation');
|
|
34
|
+
counts.set(label, (counts.get(label) || 0) + 1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const lines = [...counts].slice(0, 8).map(([label, count]) => `- ${label}: ${count} unread`);
|
|
38
|
+
if (counts.size > 8) lines.push(`- ${counts.size - 8} more conversations omitted`);
|
|
39
|
+
const total = [...counts.values()].reduce((sum, count) => sum + count, 0);
|
|
40
|
+
return `[Since you last looked: ${total} ambient update${total === 1 ? '' : 's'} in ${counts.size} conversation${counts.size === 1 ? '' : 's'}; context only, no reply needed.]\n`
|
|
41
|
+
+ `${lines.join('\n')}\nPull relevant messages with commonly_get_messages. On resume, read oldest unread first; at most 8 conversations, 5 messages each, 20 messages total.`;
|
|
42
|
+
};
|
package/src/lib/poller.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { createClient } from './api.js';
|
|
10
|
+
import { formatDigestFrame } from './digest-frame.js';
|
|
10
11
|
|
|
11
12
|
// Delivery failures that must stop a consumer rather than fall through to the
|
|
12
13
|
// normal at-least-once retry path. A stale delivery belongs to a replacement
|
|
@@ -28,40 +29,6 @@ export const terminalDeliveryAckError = (ackErr, eventId, runner = 'poller') =>
|
|
|
28
29
|
return null;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
const digestFrame = (events, rollup) => {
|
|
32
|
-
const counts = new Map();
|
|
33
|
-
let knownOlder = 0;
|
|
34
|
-
for (const conversation of Array.isArray(rollup?.conversations) ? rollup.conversations : []) {
|
|
35
|
-
if (typeof conversation.label !== 'string' || !Number.isInteger(conversation.count)
|
|
36
|
-
|| conversation.count < 1) continue;
|
|
37
|
-
counts.set(conversation.label, (counts.get(conversation.label) || 0) + conversation.count);
|
|
38
|
-
knownOlder += conversation.count;
|
|
39
|
-
}
|
|
40
|
-
if (rollup?.unreadCount > knownOlder) {
|
|
41
|
-
counts.set('older pod activity',
|
|
42
|
-
(counts.get('older pod activity') || 0) + rollup.unreadCount - knownOlder);
|
|
43
|
-
}
|
|
44
|
-
const seen = new Set();
|
|
45
|
-
for (const event of events) {
|
|
46
|
-
const payload = event.payload || {};
|
|
47
|
-
const sourceId = payload.messageId != null ? `message:${payload.messageId}`
|
|
48
|
-
: (typeof payload.taskId === 'string'
|
|
49
|
-
? `task:${payload.taskId}:${String(payload.taskKind || '')}:${String(payload.content || '')}` : null);
|
|
50
|
-
if (sourceId && seen.has(sourceId)) continue;
|
|
51
|
-
if (sourceId) seen.add(sourceId);
|
|
52
|
-
const thread = payload.threadRootId;
|
|
53
|
-
const task = payload.taskId;
|
|
54
|
-
const label = Number.isInteger(thread) && thread > 0 ? `thread ${thread}`
|
|
55
|
-
: (typeof task === 'string' && /^TASK-\d+$/.test(task) ? task : 'pod conversation');
|
|
56
|
-
counts.set(label, (counts.get(label) || 0) + 1);
|
|
57
|
-
}
|
|
58
|
-
const lines = [...counts].slice(0, 8).map(([label, count]) => `- ${label}: ${count} unread`);
|
|
59
|
-
if (counts.size > 8) lines.push(`- ${counts.size - 8} more conversations omitted`);
|
|
60
|
-
const total = [...counts.values()].reduce((sum, count) => sum + count, 0);
|
|
61
|
-
return `[Since you last looked: ${total} ambient update${total === 1 ? '' : 's'} in ${counts.size} conversation${counts.size === 1 ? '' : 's'}; context only, no reply needed.]\n`
|
|
62
|
-
+ `${lines.join('\n')}\nPull relevant messages with commonly_get_messages. On resume, read oldest unread first; at most 8 conversations, 5 messages each, 20 messages total.`;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
32
|
export const startPoller = ({
|
|
66
33
|
instanceUrl,
|
|
67
34
|
token,
|
|
@@ -97,8 +64,7 @@ export const startPoller = ({
|
|
|
97
64
|
const digestEvents = events.filter((event) => event.deliveryMode === 'digest'
|
|
98
65
|
&& wakeEvents[0] && String(event.podId) === String(wakeEvents[0].podId));
|
|
99
66
|
const rollup = wakeEvents[0]?.payload?.digestRollup;
|
|
100
|
-
const frame = digestEvents
|
|
101
|
-
? digestFrame(digestEvents, rollup) : null;
|
|
67
|
+
const frame = formatDigestFrame(digestEvents, rollup);
|
|
102
68
|
let digestConsumed = false;
|
|
103
69
|
for (const [index, event] of wakeEvents.entries()) {
|
|
104
70
|
const attachedDigest = index === 0 && frame !== null;
|
package/src/lib/spawn-retry.js
CHANGED
|
@@ -27,6 +27,7 @@ export const SPAWN_RETRY_JITTER_MAX_RATIO = 0.2;
|
|
|
27
27
|
// outage has already been misclassified. Twice now:
|
|
28
28
|
// 2026-08-03 codex "Your workspace is out of credits." → `out of credits`
|
|
29
29
|
// 2026-08-18 claude "You've hit your session limit" → `session limit`
|
|
30
|
+
// 2026-08-25 claude "You've hit your weekly limit" → the phrase below
|
|
30
31
|
// The second one is the instructive failure: `usage limit` was already here —
|
|
31
32
|
// it is Claude's OTHER exhaustion wording — so the fleet stalled for an hour on
|
|
32
33
|
// a string one word away from a pattern we had. Both times the miss meant
|
|
@@ -62,7 +63,41 @@ export const SPAWN_RETRY_JITTER_MAX_RATIO = 0.2;
|
|
|
62
63
|
// nothing else until the kernel retired the event. Only the refusal wordings
|
|
63
64
|
// themselves are matched, so an ordinary failure that mentions a flag is not.
|
|
64
65
|
const CONTENT_REFUSED_RE = /(?:flagged for possible cybersecurity risk|this content was flagged|content[_ ]policy[_ ]violation|cyber[_ ]policy)/i;
|
|
65
|
-
|
|
66
|
+
// The third miss is why there is now a PHRASE as well as a word list, and it is
|
|
67
|
+
// a different failure from the first two. Measured across the fleet's logs on
|
|
68
|
+
// 2026-08-25: 283 failures reading "You've hit your weekly limit", 55 reading
|
|
69
|
+
// "You've hit your session limit" (matched), and 6 reading "You've reached your
|
|
70
|
+
// Fable 5 limit" (not matched). Three wordings, one sentence shape, and the list
|
|
71
|
+
// had caught exactly one of them. Enumerating per-wording keeps failing because
|
|
72
|
+
// the variable part is a BILLING PERIOD or a MODEL NAME, both of which the
|
|
73
|
+
// providers keep adding, so a list is structurally one release behind.
|
|
74
|
+
//
|
|
75
|
+
// `QUOTA_POSSESSIVE_RE` matches that shape and nothing looser: the subject must
|
|
76
|
+
// be the caller's own allowance ("you've hit/reached YOUR ... limit"), which is
|
|
77
|
+
// what distinguishes exhaustion from a server-side throttle. The negative
|
|
78
|
+
// lookahead keeps "you've hit your rate limit" out — QUOTA is tested first, and
|
|
79
|
+
// without it that string would take the 15-minute cooldown instead of the
|
|
80
|
+
// 60-second rate-limit backoff. The length bound stops it spanning sentences.
|
|
81
|
+
//
|
|
82
|
+
// The character class admits a dot ONLY when a digit follows it, and that
|
|
83
|
+
// carve-out is load-bearing rather than cosmetic (sprint-review, 2026-08-25):
|
|
84
|
+
// a plain `[^.\n]` reads as "stay inside one sentence" and silently also means
|
|
85
|
+
// "no model names". Every model we run is dotted, so "you've reached your Haiku
|
|
86
|
+
// 4.5 limit" fell through to RUNTIME, the shortest backoff — the class excluded
|
|
87
|
+
// the exact variable part this paragraph says keeps changing.
|
|
88
|
+
//
|
|
89
|
+
// Known limit of `\.(?=\d)`, kept rather than papered over: a period with a
|
|
90
|
+
// digit immediately after it is admitted even at a sentence boundary, so
|
|
91
|
+
// "You've reached your goal.5 things have no limit" classes as QUOTA. The space
|
|
92
|
+
// in ordinary prose ("goal. 5 things") is what terminates the match, and
|
|
93
|
+
// adjacent `.`+digit is rare enough in provider copy to accept. The test below
|
|
94
|
+
// pins what the pattern ACTUALLY has — a space after the period ends the match —
|
|
95
|
+
// rather than the stronger property it does not have.
|
|
96
|
+
const QUOTA_RE = /(?:quota|usage limit|session limit|weekly limit|credit balance|out of credits|billing|insufficient[_ -]?quota|resource exhausted|spending limit)/i;
|
|
97
|
+
const QUOTA_POSSESSIVE_RE = /you'?ve (?:hit|reached) your (?!rate[ -]?limit)(?:[^.\n]|\.(?=\d)){0,40}?limit/i;
|
|
98
|
+
// The status code is not a throttle wording: "429: You've reached your Fable 5
|
|
99
|
+
// limit" is an exhausted allowance that a provider reports as HTTP 429.
|
|
100
|
+
const THROTTLE_WORDING_RE = /(?:rate[ -]?limit|too many requests|overloaded|capacity)/i;
|
|
66
101
|
const RATE_LIMIT_RE = /(?:rate[ -]?limit|too many requests|\b429\b|overloaded|capacity)/i;
|
|
67
102
|
const CONFIGURATION_RE = /(?:ENOENT|command not found|not on PATH|login required|not logged in|invalid api key|authentication failed|unauthori[sz]ed|forbidden|\b40[13]\b)/i;
|
|
68
103
|
|
|
@@ -85,6 +120,17 @@ export const classifySpawnFailure = (error) => {
|
|
|
85
120
|
// Prefer the more specific body/message over the generic status code so a
|
|
86
121
|
// hard quota failure gets the long cooldown rather than a one-minute probe.
|
|
87
122
|
if (QUOTA_RE.test(text)) return SPAWN_FAILURE_CLASS.QUOTA;
|
|
123
|
+
// The possessive shape is deliberately loose about what sits between "your"
|
|
124
|
+
// and "limit", and its `(?!rate[ -]?limit)` lookahead only guards the word
|
|
125
|
+
// IMMEDIATELY after "your" — so "you've hit your API rate limit" walked past
|
|
126
|
+
// it into the 15-minute circuit, where main correctly gives the 60-second
|
|
127
|
+
// rate-limit probe (otto, gate on #2491; it was a regression, not a gap).
|
|
128
|
+
// A throttle wording anywhere in the text therefore wins over the shape.
|
|
129
|
+
// QUOTA_RE is still tested first, so an explicit quota word keeps QUOTA even
|
|
130
|
+
// when the same message also mentions rate limits.
|
|
131
|
+
if (QUOTA_POSSESSIVE_RE.test(text) && !THROTTLE_WORDING_RE.test(text)) {
|
|
132
|
+
return SPAWN_FAILURE_CLASS.QUOTA;
|
|
133
|
+
}
|
|
88
134
|
if (error?.status === 429 || RATE_LIMIT_RE.test(text)) {
|
|
89
135
|
return SPAWN_FAILURE_CLASS.RATE_LIMIT;
|
|
90
136
|
}
|