@commonlyai/cli 0.1.285 → 0.1.287
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 +21 -13
- package/src/lib/enforcement.js +14 -16
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -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
|
|
@@ -873,7 +879,7 @@ const HELD_RETRY_MAX_FAILURES = 3;
|
|
|
873
879
|
const PAST_CAP_MAX_CARRIES = 5;
|
|
874
880
|
|
|
875
881
|
// Who gets a slot when a batch is past the cap. 'unknown' counts as a person:
|
|
876
|
-
//
|
|
882
|
+
// only a row the snapshot and the kernel's stamp both can't place reads so, and
|
|
877
883
|
// a wrong guess costs an ambient item one turn. Within a rank the older row
|
|
878
884
|
// wins, and carried rows lead the page, so new arrivals can't overtake them.
|
|
879
885
|
const capRank = (entry) => {
|
|
@@ -1760,7 +1766,7 @@ export const answersInChannel = (entry) => {
|
|
|
1760
1766
|
// line offered silence on every turn. A turn that answers a person drops that
|
|
1761
1767
|
// exit: NO_REPLY stays only as the way to end after a reply posted through a
|
|
1762
1768
|
// tool, so the wrapper doesn't post a second one. It needs the sender known to
|
|
1763
|
-
// be human, so an agent's @ and a message
|
|
1769
|
+
// be human, so an agent's @ and a message nobody can place keep the old line. A
|
|
1764
1770
|
// seat whose peer holds the claim keeps it too: the peer is answering them. So
|
|
1765
1771
|
// do two chat.mention wakes where nobody typed the seat's name: an adjacent
|
|
1766
1772
|
// reply and a new member's welcome, whose kernel frames offer NO_REPLY.
|
|
@@ -2997,8 +3003,10 @@ export const performRun = ({
|
|
|
2997
3003
|
// output would double-post. Two independent signals suppress the echo:
|
|
2998
3004
|
// 1. Detection — a new message appeared in the pod during the spawn (the
|
|
2999
3005
|
// agent posted via the tool). Automatic; no agent cooperation needed.
|
|
3000
|
-
// 2. NO_REPLY — the agent explicitly asks us to stay silent
|
|
3001
|
-
//
|
|
3006
|
+
// 2. NO_REPLY — the agent explicitly asks us to stay silent: the ENTIRE
|
|
3007
|
+
// reply, or (F192) its last line on a turn nobody is waiting on, where
|
|
3008
|
+
// the text above it is reasoning the server would otherwise post.
|
|
3009
|
+
// Other mixed content still posts verbatim.
|
|
3002
3010
|
// Otherwise (a bare CLI with no posting tools, or an agent that chose to
|
|
3003
3011
|
// reply via its output) the wrapper delivers the text as before.
|
|
3004
3012
|
const replyText = (result.text || '').trim();
|
|
@@ -3013,7 +3021,9 @@ export const performRun = ({
|
|
|
3013
3021
|
}
|
|
3014
3022
|
const heartbeatControlReply = (event.type === 'heartbeat' || event.payload?.hasHeartbeat === true)
|
|
3015
3023
|
&& /^(HEARTBEAT_OK|HEARTBEAT_NOOP)$/i.test(replyText);
|
|
3016
|
-
const
|
|
3024
|
+
const declinedInText = event.type !== 'agent.ask' && !someoneIsWaiting(event)
|
|
3025
|
+
&& CLOSES_ON_BARE_SENTINEL.test(replyText);
|
|
3026
|
+
const silentReply = !replyText || replyText === 'NO_REPLY' || heartbeatControlReply || declinedInText;
|
|
3017
3027
|
// A refused model route is not a silent turn. pi reports the refusal on its
|
|
3018
3028
|
// own JSON stream and exits 0 with no text, so before this the seat log read
|
|
3019
3029
|
// `no wrapper-post (empty output)` and the cause — a 429 budget message — was
|
|
@@ -3058,7 +3068,8 @@ export const performRun = ({
|
|
|
3058
3068
|
}
|
|
3059
3069
|
}
|
|
3060
3070
|
} else if (silentReply) {
|
|
3061
|
-
const reason = heartbeatControlReply ? replyText
|
|
3071
|
+
const reason = heartbeatControlReply ? replyText
|
|
3072
|
+
: declinedInText ? 'NO_REPLY' : (replyText || 'empty output');
|
|
3062
3073
|
// A turn that posted via tool and THEN ended with the sentinel is not the
|
|
3063
3074
|
// same event as a turn that produced nothing — but this branch reported
|
|
3064
3075
|
// both as `no wrapper-post (NO_REPLY)`, because it is evaluated before
|
|
@@ -3817,14 +3828,11 @@ export const performRun = ({
|
|
|
3817
3828
|
);
|
|
3818
3829
|
if (!admission.allowed) {
|
|
3819
3830
|
// An agent row refuses the page, and that shouldn't cost a row nobody
|
|
3820
|
-
// can place:
|
|
3821
|
-
//
|
|
3822
|
-
//
|
|
3823
|
-
// stamped as an agent's is placed, so it stays refused, or it would walk
|
|
3824
|
-
// past this brake. A legacy row has no stamp, and still carries.
|
|
3831
|
+
// can place: one past the snapshot with no stamp reads `unknown`. It is
|
|
3832
|
+
// carried, past-cap bound included, and alone in its next page it can't
|
|
3833
|
+
// be refused, because only 'agent' ever is.
|
|
3825
3834
|
for (const entry of wakingEntries) {
|
|
3826
|
-
if (entry.trigger === 'unknown' && entry.event.payload?.messageId
|
|
3827
|
-
&& entry.event.payload?.senderIsHuman !== false) entry.pastCap = true;
|
|
3835
|
+
if (entry.trigger === 'unknown' && entry.event.payload?.messageId) entry.pastCap = true;
|
|
3828
3836
|
else entry.result = batchAdmissionResult(entry.event, admission);
|
|
3829
3837
|
}
|
|
3830
3838
|
carryPastCap();
|
package/src/lib/enforcement.js
CHANGED
|
@@ -49,23 +49,21 @@ export const frameDecisionForkRule = (prompt) => `${DECISION_FORK_FRAME}\n\n${pr
|
|
|
49
49
|
/**
|
|
50
50
|
* Who authored the message that woke us — 'agent', 'human', or 'unknown'?
|
|
51
51
|
*
|
|
52
|
-
*
|
|
52
|
+
* Three signals, in order:
|
|
53
53
|
* 1. payload.dmKind — the kernel stamps DM wakes 'agent-agent'/'user-agent'.
|
|
54
54
|
* 2. The trigger message's isBot flag, looked up by payload.messageId in the
|
|
55
55
|
* pre-spawn snapshot the run loop already fetches for echo suppression.
|
|
56
|
+
* 3. payload.senderIsHuman, for what no snapshot can name. A page holds more
|
|
57
|
+
* wakes than the snapshot holds messages, so without this a full page of
|
|
58
|
+
* agent wakes reads as all unknown and walks past the cascade cap. A post
|
|
59
|
+
* comment isn't a pod message at all (F225).
|
|
56
60
|
*
|
|
57
61
|
* 'unknown' is the fail-open verdict: it neither counts toward the cascade
|
|
58
|
-
* cap nor resets it.
|
|
59
|
-
*
|
|
60
|
-
* that has already scrolled out of the window is not cascade tempo.
|
|
62
|
+
* cap nor resets it. It's what's left when the kernel couldn't say either: an
|
|
63
|
+
* older server, or a sender it couldn't read.
|
|
61
64
|
*/
|
|
62
65
|
export const classifyTrigger = (event, recentMessages) => {
|
|
63
66
|
const p = event?.payload || {};
|
|
64
|
-
// A post comment is not a pod message, so a snapshot can never name its
|
|
65
|
-
// author (F225). The kernel stamps it; an older server leaves it 'unknown'.
|
|
66
|
-
if (event?.type === 'thread.mention' && typeof p.senderIsHuman === 'boolean') {
|
|
67
|
-
return p.senderIsHuman ? 'human' : 'agent';
|
|
68
|
-
}
|
|
69
67
|
// The third pricing branch (#1044, fable 55845). Kernel-found work is not
|
|
70
68
|
// agent churn and must not price as it: counted as 'agent' it eats cascade
|
|
71
69
|
// budget exactly when the board is busiest; counted as 'human' it CLEARS the
|
|
@@ -76,12 +74,12 @@ export const classifyTrigger = (event, recentMessages) => {
|
|
|
76
74
|
if (p.triggerAuthor === 'kernel') return 'kernel';
|
|
77
75
|
if (p.dmKind === 'agent-agent') return 'agent';
|
|
78
76
|
if (p.dmKind === 'user-agent') return 'human';
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
if (
|
|
84
|
-
return
|
|
77
|
+
const trigger = p.messageId && Array.isArray(recentMessages)
|
|
78
|
+
? recentMessages.find((m) => String(m._id || m.id) === String(p.messageId))
|
|
79
|
+
: undefined;
|
|
80
|
+
if (typeof trigger?.isBot === 'boolean') return trigger.isBot ? 'agent' : 'human';
|
|
81
|
+
if (typeof p.senderIsHuman === 'boolean') return p.senderIsHuman ? 'human' : 'agent';
|
|
82
|
+
return 'unknown';
|
|
85
83
|
};
|
|
86
84
|
|
|
87
85
|
// Direct-address event types: the seat was NAMED (explicit @, implicit human
|
|
@@ -94,7 +92,7 @@ export const ADDRESSED_EVENT_TYPES = new Set(['chat.mention', 'thread.mention',
|
|
|
94
92
|
/**
|
|
95
93
|
* A person @-mentioned this seat in a pod (ADR-018 D9.2): the one wake that
|
|
96
94
|
* carries unread message bodies. `trigger` is classifyTrigger's verdict, so an
|
|
97
|
-
* agent's mention, a kernel wake and an author
|
|
95
|
+
* agent's mention, a kernel wake and an author nobody can name are all
|
|
98
96
|
* out. A DM wake is not a mention, whichever type it rides, and neither is a
|
|
99
97
|
* broadcast. Nor are three `chat.mention` wakes where nobody typed the seat's
|
|
100
98
|
* name: a welcome, an adjacent reply and a reply to the seat's own message.
|