Skip to content

feat(discord): migrate to extmsg fabric for thread management#2

Open
julianknutsen wants to merge 6 commits intomainfrom
feat/extmsg-discord
Open

feat(discord): migrate to extmsg fabric for thread management#2
julianknutsen wants to merge 6 commits intomainfrom
feat/extmsg-discord

Conversation

@julianknutsen
Copy link
Copy Markdown
Collaborator

Summary

  • Gateway normalizes Discord MESSAGE_CREATE to extmsg inbound messages
  • Room @mentions create Discord threads + extmsg groups + agent sessions (sequential)
  • Thread @mentions add new participants with dedup against existing bindings
  • Thread detection via Discord API channel type lookup (cached)
  • NL agent name matching for explicit_target in threads
  • reply-current rewritten to post directly via Discord API with --conversation-id flag
  • Scope discovery cache skips caching failures to prevent port 9443 fallback
  • normalize_to_extmsg_message includes correct parent_id for thread messages

Companion PR: gastownhall/gascity#116

Test plan

  • End-to-end: human @mentions agents in Discord room → thread created → agents respond
  • Follow-up messages in thread notify all members via extmsg
  • Dedup prevents duplicate sessions for existing thread participants

🤖 Generated with Claude Code

julianknutsen and others added 5 commits March 25, 2026 07:47
Rewrite CLI scripts to use the Gas City extmsg fabric instead of
pack-local JSON state files:

- bind-dm/bind-room: POST /v0/extmsg/bindings + transcript membership
- enable-room-launch: POST /v0/extmsg/groups
- publish: POST /v0/extmsg/outbound (peer notification via transcript)
- reply-current: GET transcript context + POST /v0/extmsg/outbound

Update prompt template:
- Add shared conversation etiquette (respond only when YOU have
  something to add; silence is fine)
- Remove peer fanout instructions and @@handle syntax
- Remove exit code 2 peer delivery semantics

Remove retry-peer-fanout command from pack.toml (no longer needed —
transcript is the shared state, peers read it directly).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add normalize_to_extmsg_message() helper that converts Discord
MESSAGE_CREATE events to extmsg ExternalInboundMessage format.

Add _fuzzy_match_handle() for natural language participant targeting
(replaces @@handle syntax with word-boundary matching against known
participant names).

Add deliver_to_extmsg() helper for posting normalized messages to
the extmsg inbound API.

Gateway now records inbound messages in extmsg transcript (best-effort)
alongside existing session delivery. This dual-path allows incremental
migration — extmsg transcript gets populated while existing routing
continues to work.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Delete discord_chat_retry_peer_fanout.py entirely
- Remove retry-peer-fanout.sh command wrapper and help text
- Remove _apply_peer_fanout() call from publish_binding_message()

The ~900 lines of peer fanout engine code (budget tracking, target
resolution, delivery state machine, retry logic) remain in
discord_intake_common.py as unreachable code for now. These functions
are no longer called from any code path. A follow-up cleanup pass can
remove them once the extmsg transcript-based peer awareness model is
validated in production.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Room messages with @mentions now launch new Discord threads:
1. Parse @mentions from message text
2. Resolve each against managed sessions (by alias) then agent
   templates (by name)
3. Create Discord thread from the source message
4. Create extmsg group for the thread
5. For templates: create new session from template
6. Add each target as group participant with transcript membership
7. Deliver the original message into the thread transcript

Update prompt template:
- Template identity awareness ("you were created from the X template")
- Natural chat room judgment model (named = strong signal, unnamed
  but relevant = still respond, irrelevant = listen)
- Agent-to-agent: use @name for clarity
- Remove all peer fanout and @@handle syntax references

Add resolve_at_mentions(), resolve_mention_targets(), and
launch_thread_for_mentions() to common library.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add resolve_nl_agent_mentions() for natural language agent matching
  (no @ prefix required)
- Fix _create_session_from_template to use async API (non-blocking)
- Fix resolve_mention_targets: template match takes priority over
  session alias (always create new session for template agents)
- Add scope discovery cache (60s TTL) to avoid per-call HTTP lookup
- Add error logging to launch_thread_for_mentions for Discord API
  and GC API failures
- Fix GC_API_BASE_URL handling to skip scope prefix when explicit
- Debug logging for extmsg routing in gateway

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…saging

Replace pack-local state management with extmsg API calls for Discord
thread creation, agent session spawning, and message delivery.

Key changes:
- Gateway normalizes MESSAGE_CREATE to extmsg inbound messages
- Thread detection via Discord API channel type lookup (cached)
- Room @mentions create threads + extmsg groups + agent sessions
- Thread @mentions add new participants with dedup
- NL agent name matching for explicit_target in threads
- reply-current rewritten to post directly via Discord API
- Scope discovery cache skips caching failures (port 9443 fallback fix)
- Sequential session creation to avoid prompt resolution races
- normalize_to_extmsg_message with correct parent_id for threads

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant