From 01b60cab5ffc1a6dcf38e0553c2e2c701c8a7806 Mon Sep 17 00:00:00 2001
From: Ting-Wai To <40179554+tingwai@users.noreply.github.com>
Date: Tue, 9 Sep 2025 13:11:27 -0700
Subject: [PATCH] feat: parse for thinking tags and grey them
---
.../src/ui/MarkdownRenderer.thinking.test.tsx | 36 +++++++++++++++++++
extensions/cli/src/ui/MarkdownRenderer.tsx | 17 ++++++---
2 files changed, 48 insertions(+), 5 deletions(-)
create mode 100644 extensions/cli/src/ui/MarkdownRenderer.thinking.test.tsx
diff --git a/extensions/cli/src/ui/MarkdownRenderer.thinking.test.tsx b/extensions/cli/src/ui/MarkdownRenderer.thinking.test.tsx
new file mode 100644
index 000000000..b8af07bca
--- /dev/null
+++ b/extensions/cli/src/ui/MarkdownRenderer.thinking.test.tsx
@@ -0,0 +1,36 @@
+import { render } from "ink-testing-library";
+import React from "react";
+
+import { MarkdownRenderer } from "./MarkdownRenderer.js";
+
+describe("MarkdownRenderer - thinking tags", () => {
+ it("handles multiple thinking tags", () => {
+ const content =
+ "Text First thought middle Second thought end";
+ const { lastFrame } = render();
+
+ expect(lastFrame()).toContain("First thought");
+ expect(lastFrame()).toContain("Second thought");
+ });
+
+ it("handles thinking tags with multiline content", () => {
+ const content = `
+ This is a multiline
+ thinking block
+ `;
+ const { lastFrame } = render();
+
+ expect(lastFrame()).toContain("This is a multiline");
+ expect(lastFrame()).toContain("thinking block");
+ });
+
+ it("ignores thinking tags inside code blocks", () => {
+ const content = "```\nThis should not be processed\n```";
+ const { lastFrame } = render();
+
+ // The thinking tag should appear as literal text within the code block
+ expect(lastFrame()).toContain(
+ "This should not be processed",
+ );
+ });
+});
diff --git a/extensions/cli/src/ui/MarkdownRenderer.tsx b/extensions/cli/src/ui/MarkdownRenderer.tsx
index 12d4d17bc..5498172b2 100644
--- a/extensions/cli/src/ui/MarkdownRenderer.tsx
+++ b/extensions/cli/src/ui/MarkdownRenderer.tsx
@@ -2,10 +2,10 @@ import { Text } from "ink";
import React from "react";
import {
- highlightCode,
- detectLanguage,
- SyntaxHighlighterTheme,
defaultTheme,
+ detectLanguage,
+ highlightCode,
+ SyntaxHighlighterTheme,
} from "./SyntaxHighlighter.js";
interface MarkdownRendererProps {
@@ -28,6 +28,14 @@ const MarkdownRenderer: React.FC = React.memo(
return null; // This will be handled separately
},
},
+ {
+ regex: /([\s\S]*?)<\/think>/g,
+ render: (content, key) => (
+
+ {content.trim()}
+
+ ),
+ },
{
regex: /^(#{1,6})\s+(.+)$/gm,
render: (content, key) => (
@@ -225,6 +233,5 @@ const MarkdownRenderer: React.FC = React.memo(
MarkdownRenderer.displayName = "MarkdownRenderer";
-export { MarkdownRenderer };
+export { defaultTheme, MarkdownRenderer };
export type { SyntaxHighlighterTheme };
-export { defaultTheme };