@clawling/clawchat-plugin-openclaw 2026.7.8-4 → 2026.7.8-5

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.
@@ -2,11 +2,10 @@
2
2
  * Synthetic envelope builder for the lighter-awareness consolidated note
3
3
  * (friend.added / friend.removed / friend.profile_updated / conversation.*).
4
4
  *
5
- * Like the friend-request turn, the note runs in the owner's direct
6
- * conversation and must be addressed to the conversation id (cnv_…) recorded
7
- * at activation. A usr_… id is not a valid chat_id — member-backend rejects it
8
- * with "invalid conversation id" and msghub silently drops the agent's
9
- * in-turn replies.
5
+ * The note runs in the owner's direct conversation and must be addressed to
6
+ * the conversation id (cnv_…) recorded at activation. A usr_… id is not a
7
+ * valid chat_id — member-backend rejects it with "invalid conversation id"
8
+ * and msghub silently drops the agent's in-turn replies.
10
9
  */
11
10
  import { EVENT } from "./protocol-types.js";
12
11
  export function buildAwarenessNoteEnvelope(params) {
@@ -12,7 +12,7 @@
12
12
  * payload.metadata = {
13
13
  * kind: "permission_result",
14
14
  * operation: "friend.add",
15
- * outcome: "approved" | "denied" | "expired" | "failed",
15
+ * outcome: "approved" | "denied" | "expired" | "failed" | "auto_allowed" | "auto_denied",
16
16
  * reason: "owner_allowed" | …,
17
17
  * request_id: "prq_…",
18
18
  * }
@@ -39,10 +39,18 @@ function buildOutcomeNote(metadata) {
39
39
  ? "denied"
40
40
  : outcome === "expired"
41
41
  ? "expired"
42
- : "failed";
42
+ : outcome === "auto_allowed"
43
+ ? "auto-allowed"
44
+ : outcome === "auto_denied"
45
+ ? "auto-denied"
46
+ : "failed";
43
47
  const resolution = outcome === "approved"
44
48
  ? "The requested action has been completed."
45
- : "No further action was taken.";
49
+ : outcome === "auto_allowed"
50
+ ? "The action was automatically allowed by the owner's policy and has already been completed; no retry is needed."
51
+ : outcome === "auto_denied"
52
+ ? "The action was automatically denied by the owner's policy; do not retry."
53
+ : "No further action was taken.";
46
54
  return [
47
55
  `Permission request for operation "${operation}" has been ${outcomeLabel}.`,
48
56
  `Reason: ${reason}.`,
@@ -53,7 +61,7 @@ function buildOutcomeNote(metadata) {
53
61
  * Builds a synthetic `message.send` envelope that delivers a
54
62
  * `permission_result` context note to the agent.
55
63
  *
56
- * Mirrors the `buildFriendRequestEnvelope` pattern: a synthetic inbound
64
+ * Mirrors the `buildAwarenessNoteEnvelope` pattern: a synthetic inbound
57
65
  * `message.send` targeting the owner's direct conversation, routed through
58
66
  * `handleInboundEnvelope` so the agent can reason about the outcome.
59
67
  */
@@ -95,13 +103,18 @@ export function buildPermissionResultEnvelope(params) {
95
103
  * Handles a `permission_result` receipt. Deduplicates by `request_id`
96
104
  * (idempotent — WS replay on reconnect may deliver the same receipt again).
97
105
  *
106
+ * An empty/falsy `request_id` is never added to the dedup set — two receipts
107
+ * can legitimately share an empty id, and both must still be rendered — but
108
+ * the receipt is otherwise processed normally.
109
+ *
98
110
  * Returns a synthetic context-note {@link Envelope} on a fresh receipt so
99
111
  * the caller can feed it to `handleInboundEnvelope`; returns `null` when
100
112
  * the `request_id` has already been processed.
101
113
  */
102
114
  export function handlePermissionResult(metadata, account) {
103
- if (_seenRequestIds.has(metadata.request_id))
115
+ if (metadata.request_id && _seenRequestIds.has(metadata.request_id))
104
116
  return null;
105
- _seenRequestIds.add(metadata.request_id);
117
+ if (metadata.request_id)
118
+ _seenRequestIds.add(metadata.request_id);
106
119
  return buildPermissionResultEnvelope({ account, metadata });
107
120
  }
@@ -32,7 +32,6 @@ import { createGroupMessageCoalescer } from "./group-message-coalescer.js";
32
32
  import { openclawLlmContextDebug } from "./llm-context-debug.js";
33
33
  import { GroupSettingsCache } from "./group-settings.js";
34
34
  import { PermissionCache } from "./permissions.js";
35
- import { buildFriendRequestEnvelope } from "./friend-request-turn.js";
36
35
  import { buildAwarenessNoteEnvelope } from "./awareness-note-turn.js";
37
36
  import { handlePermissionResult } from "./permission-result.js";
38
37
  const { setRuntime: setOpenclawClawlingRuntime, getRuntime: getOpenclawClawlingRuntime } = createPluginRuntimeStore("clawchat-plugin-openclaw runtime not initialized");
@@ -1985,7 +1984,6 @@ export async function startOpenclawClawlingGateway(params) {
1985
1984
  ? env.payload
1986
1985
  : undefined;
1987
1986
  const type = typeof payload?.type === "string" ? payload.type : "";
1988
- const entityId = typeof payload?.entity_id === "string" ? payload.entity_id : "";
1989
1987
  if (type === "agent.config.changed") {
1990
1988
  log?.info?.(`[${accountId}] clawchat-plugin-openclaw agent.config.changed signal received; re-pulling group settings`);
1991
1989
  pullGroupSettings();
@@ -2003,28 +2001,11 @@ export async function startOpenclawClawlingGateway(params) {
2003
2001
  log?.error?.(`[${accountId}] clawchat-plugin-openclaw skill-update check failed: ${err instanceof Error ? err.message : String(err)}`);
2004
2002
  });
2005
2003
  }
2006
- else if (type === "friend.request") {
2007
- // Dedup is already applied above by notifySignalObserver.observe (the live
2008
- // frame and its reliable-inbox replay share the same event_id and collapse
2009
- // to one observation). Build one synthetic reasoning turn so the agent can
2010
- // act on the pending request; the prompt text varies by policy state.
2011
- const state = permissionCache.stateOf("friend.add");
2012
- // Address the turn to the activation-recorded owner conversation
2013
- // (cnv_…) — a usr_… chat_id is rejected by member-backend, so the
2014
- // agent's in-turn replies would be silently dropped by msghub.
2015
- const ownerConversationId = resolveOwnerDirectConversationId();
2016
- if (!ownerConversationId) {
2017
- log?.info?.(`[${accountId}] clawchat-plugin-openclaw friend.request turn has no activation conversation on record; in-turn replies will not be deliverable`);
2018
- }
2019
- log?.info?.(`[${accountId}] clawchat-plugin-openclaw friend.request signal received; dispatching reasoning turn entity_id=${entityId} policy=${state}`);
2020
- void handleInboundEnvelope(buildFriendRequestEnvelope({ account, state, entityId, ownerConversationId }));
2021
- }
2022
2004
  else if (type === "friend.added" ||
2023
2005
  type === "friend.removed" ||
2024
2006
  type === "friend.profile_updated" ||
2025
2007
  type.startsWith("conversation.")) {
2026
- // Lighter-awareness: log + optional single consolidated note. Never
2027
- // injects a full reasoning turn per event (unlike friend.request).
2008
+ // Lighter-awareness: log + optional single consolidated note.
2028
2009
  log?.info?.(`[${accountId}] clawchat-plugin-openclaw ${type} signal received; lighter-awareness handling`);
2029
2010
  if (account.awarenessNote && !pendingAwarenessNote) {
2030
2011
  pendingAwarenessNote = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawling/clawchat-plugin-openclaw",
3
- "version": "2026.7.8-4",
3
+ "version": "2026.7.8-5",
4
4
  "description": "OpenClaw ClawChat channel plugin",
5
5
  "license": "MIT",
6
6
  "author": "CLAWLING PTE. LTD.",
@@ -2,11 +2,10 @@
2
2
  * Synthetic envelope builder for the lighter-awareness consolidated note
3
3
  * (friend.added / friend.removed / friend.profile_updated / conversation.*).
4
4
  *
5
- * Like the friend-request turn, the note runs in the owner's direct
6
- * conversation and must be addressed to the conversation id (cnv_…) recorded
7
- * at activation. A usr_… id is not a valid chat_id — member-backend rejects it
8
- * with "invalid conversation id" and msghub silently drops the agent's
9
- * in-turn replies.
5
+ * The note runs in the owner's direct conversation and must be addressed to
6
+ * the conversation id (cnv_…) recorded at activation. A usr_… id is not a
7
+ * valid chat_id — member-backend rejects it with "invalid conversation id"
8
+ * and msghub silently drops the agent's in-turn replies.
10
9
  */
11
10
  import { EVENT, type Envelope } from "./protocol-types.ts";
12
11
  import type { ResolvedOpenclawClawlingAccount } from "./config.ts";
@@ -12,7 +12,7 @@
12
12
  * payload.metadata = {
13
13
  * kind: "permission_result",
14
14
  * operation: "friend.add",
15
- * outcome: "approved" | "denied" | "expired" | "failed",
15
+ * outcome: "approved" | "denied" | "expired" | "failed" | "auto_allowed" | "auto_denied",
16
16
  * reason: "owner_allowed" | …,
17
17
  * request_id: "prq_…",
18
18
  * }
@@ -25,7 +25,7 @@ import type { ResolvedOpenclawClawlingAccount } from "./config.ts";
25
25
  export interface PermissionResultMetadata {
26
26
  kind: "permission_result";
27
27
  operation: string;
28
- outcome: "approved" | "denied" | "expired" | "failed";
28
+ outcome: "approved" | "denied" | "expired" | "failed" | "auto_allowed" | "auto_denied";
29
29
  reason: string;
30
30
  request_id: string;
31
31
  }
@@ -52,11 +52,19 @@ function buildOutcomeNote(metadata: PermissionResultMetadata): string {
52
52
  ? "denied"
53
53
  : outcome === "expired"
54
54
  ? "expired"
55
- : "failed";
55
+ : outcome === "auto_allowed"
56
+ ? "auto-allowed"
57
+ : outcome === "auto_denied"
58
+ ? "auto-denied"
59
+ : "failed";
56
60
  const resolution =
57
61
  outcome === "approved"
58
62
  ? "The requested action has been completed."
59
- : "No further action was taken.";
63
+ : outcome === "auto_allowed"
64
+ ? "The action was automatically allowed by the owner's policy and has already been completed; no retry is needed."
65
+ : outcome === "auto_denied"
66
+ ? "The action was automatically denied by the owner's policy; do not retry."
67
+ : "No further action was taken.";
60
68
  return [
61
69
  `Permission request for operation "${operation}" has been ${outcomeLabel}.`,
62
70
  `Reason: ${reason}.`,
@@ -68,7 +76,7 @@ function buildOutcomeNote(metadata: PermissionResultMetadata): string {
68
76
  * Builds a synthetic `message.send` envelope that delivers a
69
77
  * `permission_result` context note to the agent.
70
78
  *
71
- * Mirrors the `buildFriendRequestEnvelope` pattern: a synthetic inbound
79
+ * Mirrors the `buildAwarenessNoteEnvelope` pattern: a synthetic inbound
72
80
  * `message.send` targeting the owner's direct conversation, routed through
73
81
  * `handleInboundEnvelope` so the agent can reason about the outcome.
74
82
  */
@@ -114,6 +122,10 @@ export function buildPermissionResultEnvelope(params: {
114
122
  * Handles a `permission_result` receipt. Deduplicates by `request_id`
115
123
  * (idempotent — WS replay on reconnect may deliver the same receipt again).
116
124
  *
125
+ * An empty/falsy `request_id` is never added to the dedup set — two receipts
126
+ * can legitimately share an empty id, and both must still be rendered — but
127
+ * the receipt is otherwise processed normally.
128
+ *
117
129
  * Returns a synthetic context-note {@link Envelope} on a fresh receipt so
118
130
  * the caller can feed it to `handleInboundEnvelope`; returns `null` when
119
131
  * the `request_id` has already been processed.
@@ -122,7 +134,7 @@ export function handlePermissionResult(
122
134
  metadata: PermissionResultMetadata,
123
135
  account: Pick<ResolvedOpenclawClawlingAccount, "userId" | "ownerUserId">,
124
136
  ): Envelope | null {
125
- if (_seenRequestIds.has(metadata.request_id)) return null;
126
- _seenRequestIds.add(metadata.request_id);
137
+ if (metadata.request_id && _seenRequestIds.has(metadata.request_id)) return null;
138
+ if (metadata.request_id) _seenRequestIds.add(metadata.request_id);
127
139
  return buildPermissionResultEnvelope({ account, metadata });
128
140
  }
package/src/runtime.ts CHANGED
@@ -84,7 +84,6 @@ import { createGroupMessageCoalescer } from "./group-message-coalescer.ts";
84
84
  import { openclawLlmContextDebug } from "./llm-context-debug.ts";
85
85
  import { GroupSettingsCache } from "./group-settings.ts";
86
86
  import { PermissionCache } from "./permissions.ts";
87
- import { buildFriendRequestEnvelope } from "./friend-request-turn.ts";
88
87
  import { buildAwarenessNoteEnvelope } from "./awareness-note-turn.ts";
89
88
  import { handlePermissionResult } from "./permission-result.ts";
90
89
 
@@ -2392,7 +2391,6 @@ export async function startOpenclawClawlingGateway(params: StartGatewayParams):
2392
2391
  ? (env.payload as Record<string, unknown>)
2393
2392
  : undefined;
2394
2393
  const type = typeof payload?.type === "string" ? payload.type : "";
2395
- const entityId = typeof payload?.entity_id === "string" ? payload.entity_id : "";
2396
2394
  if (type === "agent.config.changed") {
2397
2395
  log?.info?.(
2398
2396
  `[${accountId}] clawchat-plugin-openclaw agent.config.changed signal received; re-pulling group settings`,
@@ -2417,35 +2415,13 @@ export async function startOpenclawClawlingGateway(params: StartGatewayParams):
2417
2415
  }`,
2418
2416
  );
2419
2417
  });
2420
- } else if (type === "friend.request") {
2421
- // Dedup is already applied above by notifySignalObserver.observe (the live
2422
- // frame and its reliable-inbox replay share the same event_id and collapse
2423
- // to one observation). Build one synthetic reasoning turn so the agent can
2424
- // act on the pending request; the prompt text varies by policy state.
2425
- const state = permissionCache.stateOf("friend.add");
2426
- // Address the turn to the activation-recorded owner conversation
2427
- // (cnv_…) — a usr_… chat_id is rejected by member-backend, so the
2428
- // agent's in-turn replies would be silently dropped by msghub.
2429
- const ownerConversationId = resolveOwnerDirectConversationId();
2430
- if (!ownerConversationId) {
2431
- log?.info?.(
2432
- `[${accountId}] clawchat-plugin-openclaw friend.request turn has no activation conversation on record; in-turn replies will not be deliverable`,
2433
- );
2434
- }
2435
- log?.info?.(
2436
- `[${accountId}] clawchat-plugin-openclaw friend.request signal received; dispatching reasoning turn entity_id=${entityId} policy=${state}`,
2437
- );
2438
- void handleInboundEnvelope(
2439
- buildFriendRequestEnvelope({ account, state, entityId, ownerConversationId }),
2440
- );
2441
2418
  } else if (
2442
2419
  type === "friend.added" ||
2443
2420
  type === "friend.removed" ||
2444
2421
  type === "friend.profile_updated" ||
2445
2422
  type.startsWith("conversation.")
2446
2423
  ) {
2447
- // Lighter-awareness: log + optional single consolidated note. Never
2448
- // injects a full reasoning turn per event (unlike friend.request).
2424
+ // Lighter-awareness: log + optional single consolidated note.
2449
2425
  log?.info?.(
2450
2426
  `[${accountId}] clawchat-plugin-openclaw ${type} signal received; lighter-awareness handling`,
2451
2427
  );
@@ -1,104 +0,0 @@
1
- /**
2
- * Synthetic reasoning-turn builder for `friend.request` notify.signal events.
3
- *
4
- * When the server fires a `friend.request` signal the runtime dispatches one
5
- * deduped synthetic `message.send` envelope so the agent can reason about the
6
- * pending request. The prompt text varies by the current "friend.add" permission
7
- * policy state: a deny policy yields a decline/inform prompt; ask or allow
8
- * yields a prompt that instructs the agent to review the request via the
9
- * `clawchat_list_friend_requests` tool.
10
- */
11
- import { EVENT, type Envelope } from "./protocol-types.ts";
12
- import type { PermState } from "./permissions.ts";
13
- import type { ResolvedOpenclawClawlingAccount } from "./config.ts";
14
-
15
- /**
16
- * Returns canned prompt text for a friend-request reasoning turn based on the
17
- * current "friend.add" permission policy state.
18
- *
19
- * - `deny` → inform the agent it should decline; no accept instruction.
20
- * - `ask` / `allow` → instruct the agent to review the pending request.
21
- *
22
- * The requester's user id is embedded so the agent does not go looking up the
23
- * synthetic sender ("clawchat-friend-request" is not a real user).
24
- */
25
- export function friendRequestPromptFor(state: PermState, requesterUserId?: string): string {
26
- const arrived = requesterUserId
27
- ? `A new friend request has arrived from user ${requesterUserId}.`
28
- : "A new friend request has arrived.";
29
- if (state === "deny") {
30
- return [
31
- arrived,
32
- "Your current friend-add policy is set to deny.",
33
- "Do not add this contact.",
34
- "You may inform the requester that you cannot add them at this time.",
35
- ].join(" ");
36
- }
37
- return [
38
- arrived,
39
- "Please review the pending request by calling `clawchat_list_friend_requests`",
40
- "and decide whether to accept it.",
41
- ].join(" ");
42
- }
43
-
44
- export interface BuildFriendRequestEnvelopeParams {
45
- account: ResolvedOpenclawClawlingAccount;
46
- /** Current "friend.add" permission policy state. */
47
- state: PermState;
48
- /** entity_id from the notify.signal payload (the requesting user). */
49
- entityId: string;
50
- /**
51
- * The owner's direct conversation id (cnv_…) recorded at activation, or null
52
- * when none is recorded. A usr_… id is not a valid chat_id — member-backend
53
- * rejects it with "invalid conversation id" and the agent's in-turn replies
54
- * are silently dropped by msghub — so the envelope must target this id.
55
- */
56
- ownerConversationId: string | null;
57
- }
58
-
59
- /**
60
- * Builds a synthetic `message.send` envelope that triggers one agent reasoning
61
- * turn for a pending friend request. The envelope shape mirrors the
62
- * activation-bootstrap envelope; it targets the owner's direct conversation so
63
- * the agent has context about who it is reasoning for.
64
- */
65
- export function buildFriendRequestEnvelope(
66
- params: BuildFriendRequestEnvelopeParams,
67
- ): Envelope {
68
- const { account, state, entityId, ownerConversationId } = params;
69
- const text = friendRequestPromptFor(state, entityId);
70
- const now = Date.now();
71
- // Fall back to ownerUserId only when no activation conversation is recorded:
72
- // the turn still runs (the agent can act via tools, e.g. accept the request),
73
- // but its in-chat replies will not be deliverable until activation records
74
- // the owner conversation.
75
- return {
76
- version: "2",
77
- event: EVENT.MESSAGE_SEND,
78
- trace_id: `clawchat-plugin-openclaw-friend-request-${entityId}-${now}`,
79
- emitted_at: now,
80
- chat_id: ownerConversationId ?? account.ownerUserId,
81
- chat_type: "direct",
82
- to: { id: account.userId, type: "direct" },
83
- sender: {
84
- id: "clawchat-friend-request",
85
- type: "direct",
86
- nick_name: "ClawChat",
87
- },
88
- payload: {
89
- message_id: `clawchat-plugin-openclaw-friend-request-${entityId}-${now}`,
90
- message_mode: "normal",
91
- message: {
92
- body: { fragments: [{ kind: "text", text }] },
93
- context: { mentions: [], reply: null },
94
- streaming: {
95
- status: "static",
96
- sequence: 0,
97
- mutation_policy: "sealed",
98
- started_at: null,
99
- completed_at: null,
100
- },
101
- },
102
- },
103
- };
104
- }