Slack: implement replyToMode threading for tool path

- Add shared hasRepliedRef state between auto-reply and tool paths
- Extract buildSlackThreadingContext helper in agent-runner.ts
- Extract resolveThreadTsFromContext helper in slack-actions.ts
- Update docs with clear replyToMode table (off/first/all)
- Add tests for first mode behavior across multiple messages
This commit is contained in:
Austin Mudd
2026-01-08 16:04:52 -08:00
committed by Peter Steinberger
parent 29e6f13b29
commit b4663ed11c
11 changed files with 475 additions and 12 deletions

View File

@@ -122,9 +122,194 @@ describe("handleSlackAction", () => {
},
cfg,
);
expect(sendSlackMessage).toHaveBeenCalledWith("channel:C123", "Hello thread", {
expect(sendSlackMessage).toHaveBeenCalledWith(
"channel:C123",
"Hello thread",
{
mediaUrl: undefined,
threadTs: "1234567890.123456",
},
);
});
it("auto-injects threadTs from context when replyToMode=all", async () => {
const cfg = { slack: { botToken: "tok" } } as ClawdbotConfig;
sendSlackMessage.mockClear();
await handleSlackAction(
{
action: "sendMessage",
to: "channel:C123",
content: "Auto-threaded",
},
cfg,
{
currentChannelId: "C123",
currentThreadTs: "1111111111.111111",
replyToMode: "all",
},
);
expect(sendSlackMessage).toHaveBeenCalledWith(
"channel:C123",
"Auto-threaded",
{
mediaUrl: undefined,
threadTs: "1111111111.111111",
},
);
});
it("replyToMode=first threads first message then stops", async () => {
const cfg = { slack: { botToken: "tok" } } as ClawdbotConfig;
sendSlackMessage.mockClear();
const hasRepliedRef = { value: false };
const context = {
currentChannelId: "C123",
currentThreadTs: "1111111111.111111",
replyToMode: "first" as const,
hasRepliedRef,
};
// First message should be threaded
await handleSlackAction(
{ action: "sendMessage", to: "channel:C123", content: "First" },
cfg,
context,
);
expect(sendSlackMessage).toHaveBeenLastCalledWith("channel:C123", "First", {
mediaUrl: undefined,
threadTs: "1234567890.123456",
threadTs: "1111111111.111111",
});
expect(hasRepliedRef.value).toBe(true);
// Second message should NOT be threaded
await handleSlackAction(
{ action: "sendMessage", to: "channel:C123", content: "Second" },
cfg,
context,
);
expect(sendSlackMessage).toHaveBeenLastCalledWith(
"channel:C123",
"Second",
{
mediaUrl: undefined,
threadTs: undefined,
},
);
});
it("replyToMode=first without hasRepliedRef does not thread", async () => {
const cfg = { slack: { botToken: "tok" } } as ClawdbotConfig;
sendSlackMessage.mockClear();
await handleSlackAction(
{ action: "sendMessage", to: "channel:C123", content: "No ref" },
cfg,
{
currentChannelId: "C123",
currentThreadTs: "1111111111.111111",
replyToMode: "first",
// no hasRepliedRef
},
);
expect(sendSlackMessage).toHaveBeenCalledWith("channel:C123", "No ref", {
mediaUrl: undefined,
threadTs: undefined,
});
});
it("does not auto-inject threadTs when replyToMode=off", async () => {
const cfg = { slack: { botToken: "tok" } } as ClawdbotConfig;
sendSlackMessage.mockClear();
await handleSlackAction(
{
action: "sendMessage",
to: "channel:C123",
content: "Off mode",
},
cfg,
{
currentChannelId: "C123",
currentThreadTs: "1111111111.111111",
replyToMode: "off",
},
);
expect(sendSlackMessage).toHaveBeenCalledWith("channel:C123", "Off mode", {
mediaUrl: undefined,
threadTs: undefined,
});
});
it("does not auto-inject threadTs when sending to different channel", async () => {
const cfg = { slack: { botToken: "tok" } } as ClawdbotConfig;
sendSlackMessage.mockClear();
await handleSlackAction(
{
action: "sendMessage",
to: "channel:C999",
content: "Different channel",
},
cfg,
{
currentChannelId: "C123",
currentThreadTs: "1111111111.111111",
replyToMode: "all",
},
);
expect(sendSlackMessage).toHaveBeenCalledWith(
"channel:C999",
"Different channel",
{
mediaUrl: undefined,
threadTs: undefined,
},
);
});
it("explicit threadTs overrides context threadTs", async () => {
const cfg = { slack: { botToken: "tok" } } as ClawdbotConfig;
sendSlackMessage.mockClear();
await handleSlackAction(
{
action: "sendMessage",
to: "channel:C123",
content: "Explicit thread",
threadTs: "2222222222.222222",
},
cfg,
{
currentChannelId: "C123",
currentThreadTs: "1111111111.111111",
replyToMode: "all",
},
);
expect(sendSlackMessage).toHaveBeenCalledWith(
"channel:C123",
"Explicit thread",
{
mediaUrl: undefined,
threadTs: "2222222222.222222",
},
);
});
it("handles channel target without prefix when replyToMode=all", async () => {
const cfg = { slack: { botToken: "tok" } } as ClawdbotConfig;
sendSlackMessage.mockClear();
await handleSlackAction(
{
action: "sendMessage",
to: "C123",
content: "No prefix",
},
cfg,
{
currentChannelId: "C123",
currentThreadTs: "1111111111.111111",
replyToMode: "all",
},
);
expect(sendSlackMessage).toHaveBeenCalledWith("C123", "No prefix", {
mediaUrl: undefined,
threadTs: "1111111111.111111",
});
});
});