@commonlyai/cli 0.1.154 → 0.1.155
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/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;
|