Skip to content

Commit 5420c5c

Browse files
authored
feat(clickclack): session discussions — bound channels, side agent, lifecycle sync (#111503)
* feat(clickclack): add session discussions * chore: remove release-owned changelog entry * refactor(clickclack): split discussion service workflows * fix(clickclack): satisfy plugin surface gates * fix: narrow routing peer in inbound test and refresh docs map
1 parent c45e3dd commit 5420c5c

45 files changed

Lines changed: 5851 additions & 537 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/channels/clickclack.md‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ id (`wsp_...`), slug, or name; the gateway resolves it to the id at startup.
118118
| `model`, `systemPrompt` | none | Used by `replyMode: "model"` completions. |
119119
| `commandMenu` | `true` | Publish native commands to ClickClack composer autocomplete. |
120120
| `reconnectMs` | `1500` | Realtime reconnect delay (100 to 60000). |
121+
| `discussions` | disabled | Managed per-session channel settings; see [Session discussions](#session-discussions). |
121122

122123
If `plugins.allow` is a non-empty restrictive list, explicitly selecting
123124
ClickClack in channel setup or running `openclaw plugins enable clickclack`
@@ -157,6 +158,105 @@ Each account opens its own ClickClack realtime connection and uses its own bot t
157158
}
158159
```
159160

161+
## Session discussions
162+
163+
Enable discussions on one ClickClack account to give each OpenClaw session a
164+
dedicated ClickClack channel. The account token must include
165+
`channels:write` (the `bot:admin` bundle includes it); the normal `bot:write`
166+
setup token cannot create or synchronize channels.
167+
168+
```json5
169+
{
170+
channels: {
171+
clickclack: {
172+
enabled: true,
173+
baseUrl: "https://clickclack.example.com",
174+
token: { source: "env", provider: "default", id: "CLICKCLACK_BOT_TOKEN" },
175+
workspace: "default",
176+
discussions: {
177+
enabled: true,
178+
workspace: "default",
179+
controlUrlBase: "https://team.openclaw.ai",
180+
section: "Sessions",
181+
},
182+
},
183+
},
184+
}
185+
```
186+
187+
`discussions.workspace` accepts the same workspace id, slug, or display name
188+
as the account-level `workspace` and defaults to that value. `section` controls
189+
the ClickClack sidebar section and defaults to `Sessions`. When
190+
`controlUrlBase` is set, the managed channel links back to the real Control UI
191+
session route, `/chat?session=<encoded-session-key>`.
192+
193+
Enable discussions on exactly one ClickClack account. The gateway provider has
194+
no account selector, so multiple enabled discussion accounts are rejected
195+
rather than choosing one by configuration order.
196+
197+
Opening a discussion creates a public ClickClack channel marked as externally
198+
managed. The plugin keeps the session label, category, and archive state in
199+
sync. Restoring a session restores its channel; clearing the session category
200+
moves the channel back to the configured default section. Deleting an
201+
OpenClaw session archives the ClickClack channel instead of deleting it, so its
202+
history remains available. The plugin reconciles bindings when discussion RPCs
203+
are used and approximately once per minute while any bindings exist.
204+
205+
Inbound messages in a managed channel use a deterministic side session under
206+
the same agent id as the attached main session. The side agent is told which
207+
main session to observe and can use `sessions_history` and `session_status`
208+
(`changesSince` is useful for incremental checks). It uses `sessions_send` only
209+
when people in the discussion ask it to relay or steer the main session.
210+
The binding, managed ownership reference, and side-session peer identity include
211+
the concrete OpenClaw session id along with the pinned ClickClack server and
212+
channel. Resetting a reusable session key or retargeting an account revokes the
213+
old channel locally, archives it when the old credential remains usable, and
214+
cannot reuse its side transcript. Messages arriving through an
215+
archived, reset, disabled, or retargeted binding are dropped instead of falling
216+
back to the account's normal channel routing. Released bindings leave a durable
217+
revoked-channel marker so delayed realtime events remain fail-closed. Remote
218+
ownership is keyed by ClickClack server and channel id, so renaming the local
219+
account cannot turn a managed channel into an ordinary one.
220+
221+
Keep `tools.sessions.visibility` at its safer default `tree`. The plugin
222+
installs a host-scoped grant only between each side session and its attached
223+
main session, plus a tool-policy hook that blocks session discovery and
224+
cross-session targets. It allows `sessions_history`, `session_status`, and
225+
`sessions_send` only for the attached main session and prevents the status call
226+
from changing that session's model. Those tools must still be present in the
227+
agent's effective tool allowlist. The system prompt is guidance; the host grant
228+
and hook are the authorization boundary.
229+
230+
The ClickClack server must support managed-channel fields (`external_managed`,
231+
`external_ref`, `external_url`, and `sidebar_section`) on channel creation and
232+
updates and return them in channel responses. OpenClaw verifies that contract
233+
before persisting a binding. If a create response is lost, the next open adopts
234+
the channel by its server-enforced `external_ref` instead of creating another.
235+
Until that outcome is reconciled, the pending reservation quarantines
236+
otherwise-unbound events in the destination workspace. The coarse reconciler
237+
adopts the channel when the same session is still live or archives it after a
238+
reset; it clears the reservation when no remote channel was created.
239+
That reference contains a durable per-OpenClaw-installation namespace plus a
240+
hash of the session key, concrete session id, ClickClack destination, and durable
241+
binding generation. Separate gateways cannot adopt each other's channels,
242+
reset sessions cannot inherit old channel history, and an account or workspace
243+
round trip cannot re-adopt a previous channel. Bindings are also pinned to the
244+
configured ClickClack server URL and are invalidated if the account is
245+
retargeted. Changing or removing `controlUrlBase` updates or clears the managed
246+
channel link on the next reconciliation pass. Changing
247+
`discussions.workspace` archives and releases the old binding before a channel
248+
can be opened in the new workspace when the old workspace credential remains
249+
configured. If the token was replaced with a workspace-scoped credential that
250+
cannot access the old workspace, OpenClaw records the old channel as revoked and
251+
releases the binding without trying the replacement token; archive that leftover
252+
channel from ClickClack.
253+
254+
The attached main session also receives a pull-only `discussion` tool. It reads
255+
the latest messages and recent thread replies as one escaped, attributed record
256+
per message, and has no write or lifecycle side effects. Channel-root and thread
257+
lookups have fixed request budgets; the result explicitly warns when that
258+
safety bound can omit an older active thread.
259+
160260
## Reply modes
161261

162262
- `replyMode: "agent"` (default) dispatches inbound messages through the normal agent pipeline, including session recording and tool policy.

‎docs/docs_map.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
319319
- H3: JSON5 reference
320320
- H3: Account config keys
321321
- H2: Multiple bots
322+
- H2: Session discussions
322323
- H2: Reply modes
323324
- H2: Command menu
324325
- H2: Durable media delivery

‎docs/plugins/reference/clickclack.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Adds the Clickclack channel surface for sending and receiving OpenClaw messages.
1818

1919
channels: `clickclack`
2020

21+
The plugin can optionally create a lifecycle-synchronized ClickClack channel
22+
for each OpenClaw session. Managed discussion channels use a same-agent side
23+
session for observation and relay, while the attached main session receives a
24+
pull-only `discussion` tool. See [ClickClack session discussions](/channels/clickclack#session-discussions)
25+
for configuration and session-tool visibility requirements.
26+
2127
## Related docs
2228

2329
- [clickclack](/channels/clickclack)

‎extensions/clickclack/README.md‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,89 @@ Set `commandMenu: false` on an account to disable menu sync. Sync failures do
3535
not prevent the gateway from starting, so older tokens and ClickClack servers
3636
continue to work without a menu.
3737

38+
## Discussions
39+
40+
ClickClack can create one managed channel for each OpenClaw session:
41+
42+
The account token needs `channels:write`, which is included in `bot:admin` but
43+
not in the normal `bot:write` setup token. The ClickClack server must also
44+
support and return the managed-channel fields used by this integration.
45+
46+
```json5
47+
{
48+
channels: {
49+
clickclack: {
50+
baseUrl: "https://clickclack.example.com",
51+
token: { source: "env", provider: "default", id: "CLICKCLACK_BOT_TOKEN" },
52+
workspace: "default",
53+
discussions: {
54+
enabled: true,
55+
workspace: "default",
56+
controlUrlBase: "https://team.openclaw.ai",
57+
section: "Sessions",
58+
},
59+
},
60+
},
61+
}
62+
```
63+
64+
Opening a session discussion creates a public, externally managed channel and
65+
stores its binding in the ClickClack plugin's SQLite state. Session archive,
66+
restore, label, category, and deletion changes are reflected in the channel;
67+
deletion archives the channel and never deletes its messages. `workspace`
68+
defaults to the account workspace, and `section` defaults to `Sessions`.
69+
`controlUrlBase` adds a link back to `/chat?session=<session-key>` in the
70+
OpenClaw Control UI.
71+
72+
Enable discussions on exactly one ClickClack account. Multiple enabled
73+
discussion accounts are rejected because the session discussion provider does
74+
not have an account selector.
75+
76+
Messages in the managed channel run in a stable side session under the same
77+
agent id as the attached main session. The plugin installs a scoped host grant
78+
for `sessions_history`, `session_status`, and `sessions_send` between that side
79+
session and its attached main session, so `tools.sessions.visibility` can stay
80+
at its safer default `tree`. A second host-side policy blocks session discovery
81+
and alternate targets; the side-agent prompt is not the authorization boundary.
82+
The agent still needs those three tools in its effective tool allowlist.
83+
84+
The binding, managed ownership reference, and side-session identity include the
85+
concrete OpenClaw session id as well as the pinned server and channel. Resetting
86+
a reusable session key, replacing a binding, or retargeting it therefore revokes
87+
the old channel locally, archives it when the old credential remains usable, and
88+
starts a fresh channel and side transcript.
89+
Messages arriving through an archived, reset, disabled, or retargeted managed
90+
binding are dropped instead of falling back to the account's normal channel
91+
routing. Released bindings leave a durable revoked-channel marker so delayed
92+
realtime events remain fail-closed. Remote ownership is keyed by ClickClack
93+
server and channel id, so renaming the local account cannot turn a managed
94+
channel into an ordinary one.
95+
96+
Managed-channel ownership references include a durable per-installation id, so
97+
two OpenClaw gateways using the same ClickClack workspace do not adopt each
98+
other's discussion channels. They also include the destination and a durable
99+
binding generation, so an account or workspace round trip cannot re-adopt a
100+
previous channel. Changing or removing `controlUrlBase` is reflected on the next
101+
lifecycle reconciliation pass.
102+
103+
If a channel-create response is lost, the pending ownership reservation
104+
temporarily quarantines otherwise-unbound events in that workspace. The same
105+
coarse reconciler then adopts the created channel or clears/archives the
106+
ambiguous attempt; a reset cannot make the old channel fall through to ordinary
107+
routing.
108+
109+
When a workspace move keeps the original workspace credential configured, the
110+
plugin archives the old channel before release. If the token is replaced with a
111+
workspace-scoped credential that cannot access the old workspace, OpenClaw
112+
releases the binding into the revoked-channel marker without trying the new token
113+
against the old channel; archive that leftover channel from ClickClack.
114+
115+
The main session gets a read-only `discussion` tool that pulls the latest
116+
channel messages, including recent thread replies. The pull uses bounded
117+
history and thread-request budgets; its output says when older active threads
118+
may have been omitted. It never posts, archives, renames, or otherwise mutates
119+
the discussion.
120+
38121
## Docs
39122

40123
See `docs/channels/clickclack.md` in the OpenClaw repository, or the published docs at `https://docs.openclaw.ai/channels/clickclack`.

‎extensions/clickclack/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Bundled channel entry metadata for the ClickClack plugin.
33
*/
44
import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract";
5+
import { registerClickClackDiscussions } from "./runtime-api.js";
56

67
export default defineBundledChannelEntry({
78
id: "clickclack",
@@ -16,4 +17,5 @@ export default defineBundledChannelEntry({
1617
specifier: "./api.js",
1718
exportName: "setClickClackRuntime",
1819
},
20+
registerFull: registerClickClackDiscussions,
1921
});

‎extensions/clickclack/openclaw.plugin.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"onStartup": false
55
},
66
"channels": ["clickclack"],
7+
"contracts": {
8+
"tools": ["discussion"]
9+
},
710
"configSchema": {
811
"type": "object",
912
"additionalProperties": false,

‎extensions/clickclack/runtime-api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export {
1212
resolveClickClackAccount,
1313
setClickClackRuntime,
1414
} from "./api.js";
15+
export { registerClickClackDiscussions } from "./src/discussions/register.js";

‎extensions/clickclack/src/accounts.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ describe("ClickClack account resolution", () => {
115115
enabled: true,
116116
agentActivity: false,
117117
commandMenu: true,
118+
discussions: {
119+
enabled: false,
120+
workspace: "wsp_1",
121+
section: "Sessions",
122+
},
118123
model: undefined,
119124
name: undefined,
120125
reconnectMs: 1_500,
@@ -215,6 +220,11 @@ describe("ClickClack account resolution", () => {
215220
enabled: true,
216221
agentActivity: false,
217222
commandMenu: true,
223+
discussions: {
224+
enabled: false,
225+
workspace: "wsp_1",
226+
section: "Sessions",
227+
},
218228
model: "openai/gpt-5.4-mini",
219229
name: undefined,
220230
reconnectMs: 1_500,
@@ -248,6 +258,42 @@ describe("ClickClack account resolution", () => {
248258
expect(resolveClickClackAccount({ cfg, accountId: "bridge" }).agentActivity).toBe(true);
249259
});
250260

261+
it("normalizes per-account discussion settings and defaults", () => {
262+
const cfg = {
263+
channels: {
264+
clickclack: {
265+
enabled: true,
266+
baseUrl: "https://app.clickclack.chat",
267+
token: "test-token",
268+
workspace: "default",
269+
discussions: {
270+
enabled: true,
271+
controlUrlBase: "https://team.openclaw.ai/",
272+
},
273+
accounts: {
274+
support: {
275+
workspace: "support",
276+
discussions: { enabled: true, workspace: "operations", section: "Live work" },
277+
},
278+
},
279+
},
280+
},
281+
} satisfies CoreConfig;
282+
283+
expect(resolveClickClackAccount({ cfg }).discussions).toEqual({
284+
enabled: true,
285+
workspace: "default",
286+
controlUrlBase: "https://team.openclaw.ai/",
287+
section: "Sessions",
288+
});
289+
expect(resolveClickClackAccount({ cfg, accountId: "support" }).discussions).toEqual({
290+
enabled: true,
291+
workspace: "operations",
292+
controlUrlBase: "https://team.openclaw.ai/",
293+
section: "Live work",
294+
});
295+
});
296+
251297
it("enables command menus unless the resolved account explicitly disables them", () => {
252298
const cfg = {
253299
channels: {

‎extensions/clickclack/src/accounts.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type { ClickClackAccountConfig, CoreConfig, ResolvedClickClackAccount } f
2323
const DEFAULT_RECONNECT_MS = 1_500;
2424
const MIN_RECONNECT_MS = 100;
2525
const MAX_RECONNECT_MS = 60_000;
26+
const DEFAULT_DISCUSSIONS_SECTION = "Sessions";
2627

2728
const {
2829
listAccountIds: listClickClackAccountIds,
@@ -53,6 +54,7 @@ export function resolveClickClackAccountConfig(
5354
accounts: channel?.accounts,
5455
accountId,
5556
omitKeys: ["defaultAccount"],
57+
nestedObjectKeys: ["discussions"],
5658
normalizeAccountId,
5759
});
5860
const account = resolveNormalizedAccountEntry(channel?.accounts, accountId, normalizeAccountId);
@@ -161,6 +163,8 @@ export function resolveClickClackAccount(params: {
161163
env: params.env,
162164
});
163165
const workspace = merged.workspace?.trim() ?? "";
166+
const discussionsWorkspace = merged.discussions?.workspace?.trim() || workspace;
167+
const controlUrlBase = merged.discussions?.controlUrlBase?.trim();
164168
return {
165169
accountId,
166170
enabled,
@@ -188,6 +192,12 @@ export function resolveClickClackAccount(params: {
188192
// Command-menu sync is best effort and current bot:write tokens include
189193
// commands:write, so resolved accounts default on unless explicitly disabled.
190194
commandMenu: merged.commandMenu !== false,
195+
discussions: {
196+
enabled: merged.discussions?.enabled === true,
197+
workspace: discussionsWorkspace,
198+
...(controlUrlBase ? { controlUrlBase } : {}),
199+
section: merged.discussions?.section?.trim() || DEFAULT_DISCUSSIONS_SECTION,
200+
},
191201
config: {
192202
...merged,
193203
allowFrom: merged.allowFrom ?? ["*"],

‎extensions/clickclack/src/config-schema.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ const ClickClackAccountConfigSchema = z
2727
reconnectMs: z.number().int().min(100).max(60_000).optional(),
2828
agentActivity: z.boolean().optional(),
2929
commandMenu: z.boolean().optional(),
30+
discussions: z
31+
.object({
32+
enabled: z.boolean().optional(),
33+
workspace: z.string().optional(),
34+
controlUrlBase: z.string().url().optional(),
35+
section: z.string().optional(),
36+
})
37+
.strict()
38+
.optional(),
3039
})
3140
.strict();
3241

0 commit comments

Comments
 (0)