Skip to content

fix(mothership): thinking and subagent text#3613

Open
Sg312 wants to merge 3 commits intostagingfrom
fix/mothership-thinking
Open

fix(mothership): thinking and subagent text#3613
Sg312 wants to merge 3 commits intostagingfrom
fix/mothership-thinking

Conversation

@Sg312
Copy link
Collaborator

@Sg312 Sg312 commented Mar 16, 2026

Summary

Brief description of what this PR does and why.

Fixes #(issue)

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

How has this been tested? What should reviewers focus on?

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link

vercel bot commented Mar 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 16, 2026 11:28pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 16, 2026

Greptile Summary

This PR adds two related display fixes for the mothership chat UI: it visually distinguishes subagent-emitted text by rendering it in a styled card (instead of a plain paragraph), and introduces first-class support for <thinking> special tags so that model reasoning traces are parsed and rendered separately from regular text content.

Key changes:

  • agent-group.tsx: Swaps <p> for a styled <div> to render subagent text inside a bordered card, but inadvertently drops whitespace-pre-wrap, which would cause multi-line text content to render as a single line.
  • special-tags.tsx: Adds thinking to the SPECIAL_TAG_NAMES list and ContentSegment union, adds non-JSON parsing for the tag body, and renders it in a styled div — but the renderer carries a TODO: FIX THINKING BLOCK RENDERING comment, the JSDoc for parseSpecialTags is not updated to mention <thinking>, and the same class string is duplicated verbatim from agent-group.tsx.
  • use-chat.ts: Cleanly extends ensureTextBlock with a subagent parameter to produce subagent_text blocks when streaming content arrives while a subagent is active.

Confidence Score: 3/5

  • Safe to merge with minor fixes — the missing whitespace-pre-wrap is the most impactful regression; the thinking TODO signals incomplete UI work.
  • The hook change in use-chat.ts is clean and low-risk. The visual changes in agent-group.tsx and special-tags.tsx introduce a whitespace regression and ship a placeholder renderer with an explicit TODO, which lowers confidence slightly.
  • agent-group.tsx (missing whitespace-pre-wrap) and special-tags.tsx (TODO comment + duplicated styles)

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/agent-group.tsx Changed text rendering from <p> to <div> with updated styles, but accidentally dropped whitespace-pre-wrap, which causes newlines in subagent text content to collapse.
apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/special-tags/special-tags.tsx Adds thinking as a first-class ContentSegment type and handles it in both the parser and renderer; the renderer has an acknowledged TODO, is missing whitespace-pre-wrap, and duplicates the same class string used in agent-group.tsx.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Extends ensureTextBlock with a subagent flag to produce subagent_text blocks (rather than text) when streaming content inside an active subagent context; change is clean and well-scoped.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[SSE content event received] --> B{activeSubagent set?}
    B -- Yes --> C[ensureTextBlock with subagent=true\nCreates subagent_text block]
    B -- No --> D[ensureTextBlock with subagent=false\nCreates text block]
    C --> E[Append chunk to block content and flush]
    D --> E

    F[Raw SSE content string] --> G[parseSpecialTags]
    G --> H{Tag detected?}
    H -- thinking --> I[Segment type = thinking\nRaw body stored as content]
    H -- options or credential or usage_upgrade --> J[Segment: JSON-parsed data]
    H -- none --> K[Segment type = text]

    I --> L[SpecialTags: thinking case\nStyled italic bordered div]
    J --> M[SpecialTags: options / credential / upgrade display]
    K --> N[Plain text render]

    C --> O[AgentGroup text item\nStyled italic bordered div]
Loading

Comments Outside Diff (1)

  1. apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/special-tags/special-tags.tsx, line 42-50 (link)

    Stale JSDoc comment after adding <thinking> support

    The function's JSDoc still lists only <options> and <usage_upgrade> as handled tags (Parses inline special tags (\`, `<usage_upgrade>`)). Now that ` is also parsed, the comment should be updated to include it, keeping the documentation accurate for future contributors.

Last reviewed commit: dee790d

Comment on lines +147 to +153
/** TODO: FIX THINKING BLOCK RENDERING*/
case 'thinking':
return (
<div className='rounded-lg border border-[var(--divider)] bg-[var(--surface-4)] px-3 py-2 text-[13px] text-[var(--text-tertiary)] italic'>
{segment.content.trim()}
</div>
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comment signals incomplete implementation

The /** TODO: FIX THINKING BLOCK RENDERING*/ comment was introduced alongside the actual rendering code, signalling that the current output is a known placeholder rather than the intended design. Shipping a TODO in production code alongside the feature itself makes it easy to lose track of the intended follow-up work. Consider either completing the rendering before merging, or tracking the remaining work in an issue and removing the comment from the source.

Comment on lines +149 to +153
return (
<div className='rounded-lg border border-[var(--divider)] bg-[var(--surface-4)] px-3 py-2 text-[13px] text-[var(--text-tertiary)] italic'>
{segment.content.trim()}
</div>
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing whitespace-pre-wrap on thinking block

The thinking content rendered here follows the same pattern as the agent-group.tsx text div. If the thinking text contains newlines (very common for reasoning traces), they will be collapsed without whitespace-pre-wrap. The same concern applies here as in agent-group.tsx.

Additionally, the identical class string 'rounded-lg border border-[var(--divider)] bg-[var(--surface-4)] px-3 py-2 text-[13px] text-[var(--text-tertiary)] italic' is duplicated verbatim in both files. Consider extracting it into a shared Tailwind class or small presentational component to avoid drift.

Suggested change
return (
<div className='rounded-lg border border-[var(--divider)] bg-[var(--surface-4)] px-3 py-2 text-[13px] text-[var(--text-tertiary)] italic'>
{segment.content.trim()}
</div>
)
<div className='whitespace-pre-wrap rounded-lg border border-[var(--divider)] bg-[var(--surface-4)] px-3 py-2 text-[13px] text-[var(--text-tertiary)] italic'>
{segment.content.trim()}
</div>

Comment on lines +103 to +108
<div
key={`text-${idx}`}
className='whitespace-pre-wrap pl-[24px] font-base text-[13px] text-[var(--text-secondary)]'
className='ml-[24px] rounded-lg border border-[var(--divider)] bg-[var(--surface-4)] px-3 py-2 text-[13px] text-[var(--text-tertiary)] italic'
>
{item.content.trim()}
</p>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing whitespace-pre-wrap causes newlines to collapse

The original <p> element had the Tailwind class whitespace-pre-wrap, which preserves both whitespace sequences and newlines in the rendered output. The replacement <div> drops this class entirely, so any multi-line subagent text (e.g. step-by-step explanations or prose with explicit line breaks) will now be collapsed into a single run of text with no visible line breaks.

Add whitespace-pre-wrap back to the new <div>'s className to restore the previous behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant