Files
Fabric.OpenclawPlugin/openclaw.plugin.json
hzhang 7f96fffca9 feat: create-sub-discussion / close-sub-discussion + per-role guide injection
Adds a host-driven sub-discussion mechanism for short-lived multi-agent
exchanges where one participant (recruitment interviewee, scoped Q&A
target) has no workflow capability of its own — no Meridian state, no
installed skills, no ego identity, possibly just a placeholder Fabric
account. The host stays procedurally in control; the guest just answers
natural-language questions.

The fundamental shift from `create-discussion-channel` is the guide
plumbing: instead of a single shared guide file posted as the channel's
first message (Discord-era model), each role gets its OWN system-prompt
guide, injected at turn time via `before_prompt_build`. The host can
carry the full procedure; the guest sees a tiny orientation tailored to
"answer my questions, don't try to enter workflows you can't enter".

Three new pieces:

1. SubDiscussionStore (src/sub-discussion-store.ts) — in-memory store
   keyed by sub channelId, mirror-persisted to
   ~/.openclaw/fabric-sub-discussion.json so a gateway restart
   mid-interview doesn't strand both parties with no guide. Carries
   host agentId + userId, guest userIds, host guide text, guest guide
   text, callback (parent) channelId / guildNodeId, createdAt.

2. create-sub-discussion tool (src/tools.ts):
   - Creates a discuss-type Fabric channel with guests as members
     (host is creator → auto-included).
   - Persists a store entry indexed by the new channelId.
   - Sleeps FABRIC_SUB_DISCUSSION_GREETING_DELAY_MS (default 500ms,
     env-overridable) for the backend's channel.joined push to land on
     guest sockets, then posts greetingMsg using the host's own Fabric
     account. Turn rotation's activation rule then puts the first guest
     on the spot with wakeup=true — no race where the host posts before
     the guest's socket subs the channel room.

3. close-sub-discussion tool (src/tools.ts):
   - Host-only (rejects non-host callers by agentId match against the
     store).
   - Posts callbackMsg back into the parent channel using the Guild's
     x-fabric-system-key path so the callback lands as a guild/system-
     authored message rather than the host's personal account.
   - Default wakeupHost=true precisely wakes the host on the parent
     channel so the next workflow step (e.g. recruitment onboard) fires
     without waiting for unrelated traffic.
   - Closes the sub channel and drops the store entry.

Plus a `before_prompt_build` hook (src/sub-discussion-hook.ts) the plugin
registers at startup:

  ctx.channelId  → store.find()  → entry
  identity.findByAgentId(ctx.agentId).fabricUserId
  ─ matches entry.hostUserId   → appendSystemContext: entry.hostGuide
  ─ in     entry.guestUserIds  → appendSystemContext: entry.guestGuide
  ─ neither                    → no injection

Fail-closed on unknown agentId / channelId — we never inject the wrong
guide, only the right one or nothing. Provider-gated to messageProvider
in {empty,'fabric'} so non-fabric triggers (HF wake, exec-event) don't
unintentionally pick up an injection.

Wiring in index.ts threads the new store + config into both
registerFabricTools (so close-sub-discussion can read the system key
from channels.fabric.commandsSyncKey) and registerSubDiscussionHook (so
the prompt hook can resolve agentId → fabricUserId via identity).

Manifest update: openclaw.plugin.json lists `create-sub-discussion`
and `close-sub-discussion` in contracts.tools so the registry surfaces
them to the agent.

Backend prereq: Fabric.Backend.Guild commit 340eed8 restores the
x-fabric-system-key bypass on POST /channels/:id/messages with
wakeupUserId support — close-sub-discussion is a no-op without it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 20:52:01 +01:00

3.0 KiB