feat(routing): route replies to originating channel

Implement reply routing based on OriginatingChannel/OriginatingTo fields.
This ensures replies go back to the provider where the message originated
instead of using the session's lastChannel.

Changes:
- Add OriginatingChannel/OriginatingTo fields to MsgContext (templating.ts)
- Add originatingChannel/originatingTo fields to FollowupRun (queue.ts)
- Create route-reply.ts with provider-agnostic router
- Update all providers (Telegram, Slack, Discord, Signal, iMessage)
  to pass originating channel info
- Update reply.ts to pass originating channel to followupRun
- Update followup-runner.ts to use route-reply for originating channels

This addresses the issue where messages from one provider (e.g., Slack)
would receive replies on a different provider (e.g., Telegram) because
the queue used the last active dispatcher instead of the originating one.
This commit is contained in:
Josh Lehman
2026-01-06 10:58:45 -08:00
committed by Peter Steinberger
parent 514fcfe77e
commit 9d50ebad7d
10 changed files with 238 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ import { parseDurationMs } from "../../cli/parse-duration.js";
import type { ClawdbotConfig } from "../../config/config.js";
import type { SessionEntry } from "../../config/sessions.js";
import { defaultRuntime } from "../../runtime.js";
import type { OriginatingChannelType } from "../templating.js";
import type { ElevatedLevel, ThinkLevel, VerboseLevel } from "./directives.js";
export type QueueMode =
| "steer"
@@ -22,6 +23,17 @@ export type FollowupRun = {
prompt: string;
summaryLine?: string;
enqueuedAt: number;
/**
* Originating channel for reply routing.
* When set, replies should be routed back to this provider
* instead of using the session's lastChannel.
*/
originatingChannel?: OriginatingChannelType;
/**
* Originating destination for reply routing.
* The chat/channel/user ID where the reply should be sent.
*/
originatingTo?: string;
run: {
agentId: string;
agentDir: string;