Skip to content

Commit 5e477af

Browse files
obviyusclaude
andauthored
feat(status): render /status as a native rich card and declutter the plain body (#120167)
* feat(status): render /status as native rich tables on channels that support them * feat(status): tighten rich /status layout into a titled native table card * feat(status): trim rich /status tail to one clock-and-uptime context line * feat(status): context meter, hot-window warning, and default-noise trim in rich card * test(status): satisfy SessionEntry sessionId in meter fixture * fix(telegram): gate rich table islands off legacy HTML sends and cover payload sends * test(telegram): split outbound-adapter presentation tests to satisfy max-lines * fix(outbound): make presentation capability resolution formatting-aware * fix(telegram): defer presentation canonicalization on rich accounts until send * feat(status): one fact per line in the plain status body * feat(status): group the plain status body into blank-line sections * feat(status): lead the rich status card with the version title --------- Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
1 parent a23444f commit 5e477af

27 files changed

Lines changed: 1253 additions & 322 deletions

‎docs/plugins/message-presentation.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,25 @@ const adapter: ChannelOutboundAdapter = {
431431
};
432432
```
433433

434+
When a capability depends on per-account configuration or the delivery's text
435+
funnel — for example Telegram only renders native tables on `richMessages`
436+
accounts and only on the markdown path — declare the optional
437+
`resolvePresentationCapabilities({ cfg, accountId, formatting })` hook next to
438+
the static object. Core resolves capabilities once per delivery and the hook
439+
takes precedence over the static declaration; keep the static object as the
440+
account-independent baseline.
441+
442+
```ts
443+
const adapter: ChannelOutboundAdapter = {
444+
presentationCapabilities: BASE_CAPABILITIES,
445+
resolvePresentationCapabilities: ({ cfg, accountId, formatting }) => ({
446+
...BASE_CAPABILITIES,
447+
tables: isRichAccount(cfg, accountId) && formatting?.parseMode !== "HTML",
448+
}),
449+
// ...
450+
};
451+
```
452+
434453
Capability booleans describe what the renderer can make interactive. Optional
435454
`limits` describe the generic envelope core can adapt before calling the
436455
renderer:
@@ -505,6 +524,12 @@ plugins own native rendering and interaction handling.
505524

506525
Presentation must be safe to send on limited channels.
507526

527+
Producers that hand-author the plain rendering of the same facts can mark it
528+
with `presentationTextMode: "fallback"` on the reply payload. Channels that
529+
render the presentation's data blocks natively drop that text; when every
530+
`table` and `chart` block degrades and no interactive block remains, the
531+
authored text ships verbatim instead of the generic flatten below.
532+
508533
Fallback text includes:
509534

510535
- `title` as the first line

‎extensions/telegram/src/bot-message-dispatch-delivery.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,21 @@ export function createTelegramDeliveryController(params: {
565565
delete payloadForPlan.isReasoning;
566566
}
567567
const normalized = projectPayloadForDelivery(payloadForPlan);
568-
return normalized
569-
? canonicalizeTelegramPresentationPayload(normalized, {
570-
allowWebAppButtons: resolveTelegramTargetChatType(String(context.chatId)) === "direct",
571-
})
572-
: undefined;
568+
if (!normalized) {
569+
return undefined;
570+
}
571+
// Retained finals can still select HTML at send time, and HTML bypasses
572+
// rich blocks. Converting a presentation here would strip it while the
573+
// final funnel is still undecided, so rich accounts defer canonicalization
574+
// to the sender (deliverReplies / the outbound adapter) which knows the
575+
// text mode. Plain accounts always flatten, so deciding early is safe.
576+
if (params.telegramCfg.richMessages === true && normalized.presentation) {
577+
return normalized;
578+
}
579+
return canonicalizeTelegramPresentationPayload(normalized, {
580+
allowWebAppButtons: resolveTelegramTargetChatType(String(context.chatId)) === "direct",
581+
richTables: false,
582+
});
573583
},
574584
sendPayload,
575585
snapshot: deliveryState.snapshot,

‎extensions/telegram/src/bot/delivery.replies.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ export async function deliverReplies(params: {
759759
thread?: TelegramThreadSpec | null;
760760
tableMode?: MarkdownTableMode;
761761
chunkMode?: ChunkMode;
762-
/** Opt into Telegram Bot API 10.1 rich text delivery. */
762+
/** Opt into Telegram Bot API 10.2 rich text delivery. */
763763
richMessages?: boolean;
764764
/** Callback invoked before sending a voice message to switch typing indicator. */
765765
onVoiceRecording?: () => Promise<void> | void;
@@ -829,6 +829,9 @@ export async function deliverReplies(params: {
829829
for (const originalReply of normalizedReplies) {
830830
let reply = canonicalizeTelegramPresentationPayload(originalReply, {
831831
allowWebAppButtons: resolveTelegramTargetChatType(params.chatId) === "direct",
832+
// HTML-mode text bypasses the markdown -> rich-block converter, so native
833+
// table rendering only applies to the rich markdown funnel.
834+
richTables: params.richMessages === true && params.textMode !== "html",
832835
});
833836
const mediaList = reply?.mediaUrls?.length
834837
? reply.mediaUrls

‎extensions/telegram/src/bot/delivery.test.ts‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,120 @@ describe("deliverReplies", () => {
18851885
expect(mockCallArg(sendRichMessage, 1, 0)).not.toHaveProperty("reply_to_message_id");
18861886
});
18871887

1888+
it("delivers presentation table blocks as native rich tables on rich accounts", async () => {
1889+
const runtime = createRuntime();
1890+
const sendMessage = vi.fn().mockResolvedValue({
1891+
message_id: 11,
1892+
chat: { id: "123" },
1893+
});
1894+
const bot = createBot({ sendMessage });
1895+
1896+
await deliverWith({
1897+
replies: [
1898+
{
1899+
text: "plain fallback body",
1900+
presentationTextMode: "fallback",
1901+
presentation: {
1902+
title: "🦞 OpenClaw 2026.7.2",
1903+
blocks: [
1904+
{
1905+
type: "table",
1906+
caption: "Session status",
1907+
headers: ["Item", "Value"],
1908+
rows: [["🧠 Model", "anthropic/claude-haiku-4-5"]],
1909+
},
1910+
],
1911+
},
1912+
},
1913+
],
1914+
runtime,
1915+
bot,
1916+
richMessages: true,
1917+
});
1918+
1919+
const raw = bot.api.raw as unknown as { sendRichMessage: ReturnType<typeof vi.fn> };
1920+
expect(raw.sendRichMessage).toHaveBeenCalledTimes(1);
1921+
const richMessage = firstMockCallArg(raw.sendRichMessage, 0).rich_message as {
1922+
blocks: Array<{ type: string; cells?: unknown[][] }>;
1923+
};
1924+
const tableBlock = richMessage.blocks.find((block) => block.type === "table");
1925+
expect(tableBlock).toBeDefined();
1926+
expect(tableBlock?.cells?.length).toBe(2);
1927+
const flattened = JSON.stringify(richMessage.blocks);
1928+
expect(flattened).toContain("OpenClaw 2026.7.2");
1929+
expect(flattened).not.toContain("plain fallback body");
1930+
});
1931+
1932+
it("keeps the authored fallback text for HTML sends on rich accounts", async () => {
1933+
const runtime = createRuntime();
1934+
const sendMessage = vi.fn().mockResolvedValue({ message_id: 13, chat: { id: "123" } });
1935+
const bot = createBot({ sendMessage });
1936+
1937+
await deliverWith({
1938+
replies: [
1939+
{
1940+
text: "plain fallback body",
1941+
presentationTextMode: "fallback",
1942+
presentation: {
1943+
blocks: [
1944+
{
1945+
type: "table",
1946+
caption: "Session status",
1947+
headers: ["Item", "Value"],
1948+
rows: [["🧠 Model", "anthropic/claude-haiku-4-5"]],
1949+
},
1950+
],
1951+
},
1952+
},
1953+
],
1954+
runtime,
1955+
bot,
1956+
richMessages: true,
1957+
textMode: "html",
1958+
});
1959+
1960+
// HTML deliberately bypasses rich blocks, so a rich account must still ship
1961+
// the authored fallback body rather than a generated legacy table.
1962+
const raw = bot.api.raw as unknown as { sendRichMessage: ReturnType<typeof vi.fn> };
1963+
expect(raw.sendRichMessage).not.toHaveBeenCalled();
1964+
expect(sendMessage).toHaveBeenCalledTimes(1);
1965+
expect(String(mockCallArg(sendMessage, 0, 1))).toContain("plain fallback body");
1966+
expect(String(mockCallArg(sendMessage, 0, 1))).not.toContain("<table");
1967+
});
1968+
1969+
it("keeps the authored fallback text for presentation tables on plain accounts", async () => {
1970+
const runtime = createRuntime();
1971+
const sendMessage = vi.fn().mockResolvedValue({
1972+
message_id: 12,
1973+
chat: { id: "123" },
1974+
});
1975+
const bot = createBot({ sendMessage });
1976+
1977+
await deliverWith({
1978+
replies: [
1979+
{
1980+
text: "plain fallback body",
1981+
presentationTextMode: "fallback",
1982+
presentation: {
1983+
blocks: [
1984+
{
1985+
type: "table",
1986+
caption: "Session status",
1987+
headers: ["Item", "Value"],
1988+
rows: [["🧠 Model", "anthropic/claude-haiku-4-5"]],
1989+
},
1990+
],
1991+
},
1992+
},
1993+
],
1994+
runtime,
1995+
bot,
1996+
});
1997+
1998+
expect(sendMessage).toHaveBeenCalledTimes(1);
1999+
expect(mockCallArg(sendMessage, 0, 1)).toBe("plain fallback body");
2000+
});
2001+
18882002
it("skips rich entity detection for reply text with provider-prefixed email addresses", async () => {
18892003
const runtime = createRuntime();
18902004
const sendMessage = vi.fn().mockResolvedValue({

‎extensions/telegram/src/config-ui-hints.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const telegramChannelConfigUiHints = {
4747
}),
4848
richMessages: {
4949
label: "Telegram Rich Messages",
50-
help: "Opt into Bot API 10.1 rich text sends and edits, including native tables and rich media. Default: false because some current Telegram clients render these messages as unsupported.",
50+
help: "Opt into Bot API 10.2 rich text sends and edits, including native tables and rich media. Default: false because some current Telegram clients render these messages as unsupported.",
5151
},
5252
"network.autoSelectFamily": {
5353
label: "Telegram autoSelectFamily",

‎extensions/telegram/src/interactive-fallback.test.ts‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,101 @@ describe("canonicalizeTelegramPresentationPayload", () => {
392392

393393
expect(second.text).toBe(first.text);
394394
});
395+
396+
it("renders table blocks as native table islands for rich accounts", () => {
397+
const result = canonicalizeTelegramPresentationPayload(
398+
{
399+
text: "Summary",
400+
presentation: {
401+
title: "FY25 outlook",
402+
blocks: [
403+
{
404+
type: "table",
405+
caption: "Pipeline",
406+
headers: ["Account", "Stage"],
407+
rows: [
408+
["Acme", "Won"],
409+
["Cells & <tags>", "Review"],
410+
],
411+
rowHeaderColumnIndex: 0,
412+
},
413+
{ type: "buttons", buttons: [{ label: "Refresh", value: "refresh" }] },
414+
],
415+
},
416+
},
417+
{ richTables: true },
418+
);
419+
420+
const text = result.text ?? "";
421+
expect(text).toContain("**FY25 outlook**");
422+
expect(text).toContain("<caption>Pipeline</caption>");
423+
expect(text).toContain("<thead><tr><th>Account</th><th>Stage</th></tr></thead>");
424+
expect(text).toContain("<tr><th>Acme</th><td>Won</td></tr>");
425+
expect(text).toContain("<tr><th>Cells &amp; &lt;tags&gt;</th><td>Review</td></tr>");
426+
expect(text).not.toContain("Pipeline (table)");
427+
expect(result.channelData?.telegram).toMatchObject({
428+
buttons: [[{ text: "Refresh", callback_data: expect.any(String) }]],
429+
});
430+
});
431+
432+
it("renders context blocks in italics for rich accounts", () => {
433+
const result = canonicalizeTelegramPresentationPayload(
434+
{
435+
presentation: {
436+
blocks: [
437+
{ type: "context", text: "Uptime: gateway 12s" },
438+
{ type: "context", text: "already _emphasized_ line" },
439+
],
440+
},
441+
},
442+
{ richTables: true },
443+
);
444+
445+
expect(result.text).toContain("_Uptime: gateway 12s_");
446+
expect(result.text).toContain("already _emphasized_ line");
447+
});
448+
449+
it("replaces authored fallback text with the rich rendering when text is marked fallback", () => {
450+
const result = canonicalizeTelegramPresentationPayload(
451+
{
452+
text: "Plain fallback body",
453+
presentationTextMode: "fallback",
454+
presentation: {
455+
blocks: [
456+
{
457+
type: "table",
458+
caption: "Pipeline",
459+
headers: ["Account"],
460+
rows: [["Acme"]],
461+
},
462+
],
463+
},
464+
},
465+
{ richTables: true },
466+
);
467+
468+
expect(result.text).toContain("<th>Account</th>");
469+
expect(result.text).not.toContain("Plain fallback body");
470+
expect(result.presentationTextMode).toBeUndefined();
471+
});
472+
473+
it("keeps authored fallback text on plain accounts instead of the generic flatten", () => {
474+
const result = canonicalizeTelegramPresentationPayload({
475+
text: "Plain fallback body",
476+
presentationTextMode: "fallback",
477+
presentation: {
478+
blocks: [
479+
{
480+
type: "table",
481+
caption: "Pipeline",
482+
headers: ["Account"],
483+
rows: [["Acme"]],
484+
},
485+
],
486+
},
487+
});
488+
489+
expect(result.text).toBe("Plain fallback body");
490+
expect(result.presentation).toBeUndefined();
491+
});
395492
});

0 commit comments

Comments
 (0)