diff --git a/doc/PRODUCT.md b/doc/PRODUCT.md index 0edb2caa397..1fc39453687 100644 --- a/doc/PRODUCT.md +++ b/doc/PRODUCT.md @@ -454,6 +454,12 @@ takes the reader to the owning task's detail page with its task breadcrumb. The breadcrumb uses the short UUID for conversation-backed tasks without a task number. +### Slack task requests + +Slack requests retain full hyperlink destinations beside their display labels. +This also applies to thread replies and message edits, so agents can use links +whose Slack labels show shortened paths. Bare URLs remain unchanged. + ### Slack task progress Slack threads reuse one editable progress message for each active run. Native diff --git a/server/src/__tests__/chat-channels.integration.test.ts b/server/src/__tests__/chat-channels.integration.test.ts index 6c1ccaca8ee..61c95385a6f 100644 --- a/server/src/__tests__/chat-channels.integration.test.ts +++ b/server/src/__tests__/chat-channels.integration.test.ts @@ -1,3 +1,4 @@ +import { PaperclipSlackAdapter } from "../services/chat-channels/slack/adapter.js"; import { releaseAbandonedNativeOwners } from "../services/native-runtime/native-failed-run-owner-release.js"; import { guardSlackFixtureNetwork } from "./helpers/slack-cloud/transport.js"; import { chatHistoryActionBlocks } from "./helpers/chat-history-proof.js"; @@ -61498,6 +61499,48 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => { }, ); + it("persists full Slack link destinations in task requests, replies, edits and wake comments", async () => { + const fixture = await seedCompany(); + const { callbacks, endpoint, service, wakeup } = await configuredSlackEndpoint(fixture); + const channel = makeThread({ channelId: "C-LINKS", id: "slack:C-LINKS:1740000001.100000" }); + const adapter = new PaperclipSlackAdapter({ botToken: "xoxb-synthetic", signingSecret: "synthetic", userName: "test-bot" }); + const parse = (id: string, url: string) => adapter.parseMessage({ + type: "message", channel: "C-LINKS", ts: id, thread_ts: "1740000001.100000", + user: "U-EXTERNAL", username: "alex", text: `Review <${url.replaceAll("&", "&")}|example.com/…>`, + }); + const replay = "https://example.com/project/123/replay/abc?from=recording&return_to=%2Fhome"; + const chat = "https://example.com/REP/chats/abc"; + try { + const original = parse("1740000001.100000", replay); + await deliverMessage({ callbacks, endpointId: endpoint.id, thread: channel.thread, message: original, trigger: "mention" }); + await qualifySetupRoundTrip(service, endpoint.id); + await service.test(endpoint.id); + const reply = parse("1740000002.100000", chat); + await deliverMessage({ callbacks, endpointId: endpoint.id, thread: channel.thread, message: reply, trigger: "subscribed_message" }); + // Same label and timestamp, different destinations must remain distinct edits. + for (const url of [chat + "?revision=1", chat + "?revision=2"]) { + const edited = parse(reply.id, url); + edited.metadata.edited = true; + edited.metadata.editedAt = new Date("2026-09-04T10:01:00.000Z"); + await callbacks.onMessageUpdated!({ endpointId: endpoint.id, provider: "slack", thread: channel.thread, message: edited, previousMessage: reply }); + } + const [conversation] = await readChatConversationsByEndpointId(endpoint.id); + const deliveries = await readChatDeliveriesByEndpointId(endpoint.id); + const comments = await readIssueCommentsByIssueId(conversation.issueId); + for (const url of [replay, chat, chat + "?revision=1", chat + "?revision=2"]) { + expect(deliveries.some(row => JSON.stringify(row.normalizedEvent).includes(url))).toBe(true); + expect(comments.some(row => row.body.includes(url))).toBe(true); + } + const requestComment = comments.find(row => row.body.includes(replay))!; + const replyComment = comments.find(row => row.body.includes(chat) && !row.body.includes("revision="))!; + expect(wakeup.mock.calls.some(([, opts]) => JSON.stringify(opts).includes(requestComment.id))).toBe(true); + expect(wakeup.mock.calls.some(([, opts]) => JSON.stringify(opts).includes(replyComment.id))).toBe(true); + expect(comments.filter(row => row.body.includes("revision="))).toHaveLength(2); + } finally { + await retirePublicationFixture(service, endpoint.id); + } + }); + it("records message edits and deletes durably and deduplicates lifecycle callbacks", async () => { const fixture = await seedCompany(); const { callbacks, endpoint, service, wakeup } = diff --git a/server/src/services/chat-channels/slack/adapter.test.ts b/server/src/services/chat-channels/slack/adapter.test.ts index 6520f910816..ac450ad6406 100644 --- a/server/src/services/chat-channels/slack/adapter.test.ts +++ b/server/src/services/chat-channels/slack/adapter.test.ts @@ -22,7 +22,7 @@ describe("Slack inbound link latency", () => { } as SlackEvent; const config = { botToken: "xoxb-synthetic", signingSecret: "synthetic", userName: "test-bot", logger: new ConsoleLogger("silent") }; const received = await new Candidate(config).parse(event); - expect(received.text).toBe("Review this link"); + expect(received.text).toBe("Review this link (https://example.com/review)"); expect(received.links).toMatchObject([{ url: "https://example.com/review" }]); expect(received.attachments).toMatchObject([{ name: "notes.txt", fetchData: expect.any(Function) }]); expect(state.get).not.toHaveBeenCalled(); @@ -34,8 +34,30 @@ describe("Slack inbound link latency", () => { expect(state.get).toHaveBeenCalledWith("slack:unfurls:1740000001.1"); await vi.runAllTimersAsync(); const original = await baseline; - expect(received.text).toBe(original.text); + expect(original.text).toBe("Review this link"); expect(received.formatted).toEqual(original.formatted); expect(received.links).toEqual(original.links); }); }); + +describe("Slack inbound link destinations", () => { + const config = { botToken: "xoxb-synthetic", signingSecret: "synthetic", userName: "test-bot", logger: new ConsoleLogger("silent") }; + class Candidate extends PaperclipSlackAdapter { + parse(event: SlackEvent) { return this.parseSlackMessage(event, "slack:C123:1740000001.1"); } + } + it.each([ + ["Review ", "Review example.com/project/…/… (https://example.com/project/123/replay/abc?from=recording&return_to=%2Fhome)"], + ["Bug ", "Bug example.com/REP/chats/… (https://example.com/REP/chats/abc)"], + ["", "https://example.com/full"], + ["", "https://example.com/bare"], + ["plain *bold* and `code`", "plain bold and code"], + ["``", "[literal](https://example.com/code)"], + ["<@U123> <#C123|general> & <words>", "@U123 #general (C123) & "], + [" ", "same (https://example.com/a) same (https://example.com/b)"], + ])("preserves author links for async and sync parsing: %s", async (text, expected) => { + const adapter = new Candidate(config); + const event = { type: "message", channel: "C123", ts: "1740000001.1", username: "Test sender", text } as SlackEvent; + expect((await adapter.parse(event)).text).toBe(expected); + expect(adapter.parseMessage(event).text).toBe(expected); + }); +}); diff --git a/server/src/services/chat-channels/slack/adapter.ts b/server/src/services/chat-channels/slack/adapter.ts index 1238473468c..a7619eadd07 100644 --- a/server/src/services/chat-channels/slack/adapter.ts +++ b/server/src/services/chat-channels/slack/adapter.ts @@ -3,11 +3,37 @@ import type { ModalElement } from "chat"; import { slackDeferredCallbackActive } from "./cloud-callback.js"; import { slackFormOpenContext } from "./cloud-forms.js"; import { SlackCloudReceiptError } from "./cloud-event.js"; -import { SlackAdapter } from "@chat-adapter/slack"; +import { SlackAdapter, type SlackEvent } from "@chat-adapter/slack"; +import { toPlainText, walkAst, type Message } from "chat"; import type { AdapterPostableMessage, LinkPreview, RawMessage } from "chat"; import { slackSelectionMessage } from "./cards.js"; +function preserveLinkDestinations(message: Message): Message { + // Intake persists text, whereas the SDK's plain-text projection keeps only + // link labels. Use author content, never unfurl/preview metadata, and leave + // the original formatted AST intact for other SDK consumers. + const formatted = walkAst(structuredClone(message.formatted), (node) => { + if (node.type !== "link") return node; + const label = toPlainText({ type: "root", children: [node] }); + return { type: "text", value: label === node.url ? label : `${label} (${node.url})` }; + }); + message.text = toPlainText(formatted); + return message; +} + export class PaperclipSlackAdapter extends SlackAdapter { + protected override async parseSlackMessage( + event: SlackEvent, + threadId: string, + options?: { skipSelfMention?: boolean }, + ): Promise { + return preserveLinkDestinations(await super.parseSlackMessage(event, threadId, options)); + } + + protected override parseSlackMessageSync(event: SlackEvent, threadId: string): Message { + return preserveLinkDestinations(super.parseSlackMessageSync(event, threadId)); + } + override async openModal(triggerId: string, modal: ModalElement, contextId?: string): Promise<{ viewId: string }> { const current = slackFormOpenContext(); if (!current) {