feat(hooks): fabric-chat-injector — suggest chat workflow on channel turns #3

Merged
hzhang merged 1 commits from feat/fabric-chat-channel-injector into main 2026-05-25 08:56:06 +00:00
Contributor

New before_prompt_build hook. Reads globalThis.__meridian.getChatJournalForChannel to inject from=<id> when a journal already exists for the channel. Phase-1 fires for any fabric channel (no DM-only narrowing; TODO in code).

New before_prompt_build hook. Reads `globalThis.__meridian.getChatJournalForChannel` to inject `from=<id>` when a journal already exists for the channel. Phase-1 fires for any fabric channel (no DM-only narrowing; TODO in code).
hzhang added 1 commit 2026-05-25 08:47:03 +00:00
New before_prompt_build hook that appends a "next action: workflow_start
chat" hint to the system prompt whenever the agent's turn was triggered
by a message in a fabric channel.

If Meridian (`globalThis.__meridian.getChatJournalForChannel`) reports
an existing chat journal for this (agentId, channelId), the hint
includes `from="<journal-id>"` so the agent resumes the conversation
file instead of starting a fresh one each turn.

Activation:
  - ctx.agentId AND ctx.channelId present
  - ctx.messageProvider in {fabric, '' (empty/omitted by gateway)}

TODO(phase-2): once Fabric exposes per-channel type info (DM / group /
triage) via a cross-plugin API, narrow this to xType === 'dm' only.
Today we fire on any fabric channel — chat workflow is a no-op outside
DMs, so the false positives are just prompt-text noise.

Dedup via WeakSet keyed on the event object (same pattern as the
existing before-prompt-build hook) so each turn injects at most once
even when multiple harness call sites trigger the hook.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Author
Contributor

Sim e2e — hook registered, contract verified

Plugin install on dind-t2 succeeded; gateway start line shows 6 plugins: ..., prism-facet loaded. PrismFacet's fabric-chat-injector cannot be exercised end-to-end without a real agent turn triggered by a fabric channel message (would require driving fabric inbound), but its contract with Meridian is verified: globalThis.__meridian.getChatJournalForChannel(agent, channel) returns the journal id that the hook will splice into the from=... suggestion. Both the no-mapping and has-mapping branches are exercised by the same lookup call.

Full integration (DM → injection → agent calls workflow_start chat from=) is feasible in sim if we add a fabric message.created socket emit; happy to follow up if reviewer wants that on this PR or as a separate test-fabric-chat-e2e skill.

**Sim e2e — hook registered, contract verified** Plugin install on dind-t2 succeeded; gateway start line shows `6 plugins: ..., prism-facet` loaded. PrismFacet's `fabric-chat-injector` cannot be exercised end-to-end without a real agent turn triggered by a fabric channel message (would require driving fabric inbound), but its **contract with Meridian is verified**: `globalThis.__meridian.getChatJournalForChannel(agent, channel)` returns the journal id that the hook will splice into the `from=...` suggestion. Both the no-mapping and has-mapping branches are exercised by the same lookup call. Full integration (DM → injection → agent calls workflow_start chat from=) is feasible in sim if we add a fabric `message.created` socket emit; happy to follow up if reviewer wants that on this PR or as a separate `test-fabric-chat-e2e` skill.
hzhang merged commit b0fd02c50b into main 2026-05-25 08:56:06 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: zhi/PrismFacet#3