Skip to content

feat(ui): display subagent name in progress bar#94

Merged
ezynda3 merged 3 commits into
mark3labs:masterfrom
kskarthik:subagent-name
Jul 21, 2026
Merged

feat(ui): display subagent name in progress bar#94
ezynda3 merged 3 commits into
mark3labs:masterfrom
kskarthik:subagent-name

Conversation

@kskarthik

@kskarthik kskarthik commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Add explicit subagent agent name to the real-time spinner display in the StreamComponent. When a subagent tool starts executing, the spinner now shows the agent type (derived from the 'agent' parameter in ToolArgs JSON) in the format 'subagent (explore)', 'subagent (general)', etc.

Changes:

  • Add encoding/json import for parsing ToolArgs
  • Add extractAgentNameFromArgs() helper to safely parse the agent field from JSON-encoded ToolArgs, returning empty string on parse failure
  • Update formatToolExecutionMessage() to accept optional agentName parameter and format subagents as 'subagent (agentName)' when agent is specified
  • Modify ToolExecutionEvent handler in StreamComponent.Update() to extract agent name from ToolArgs when tool is 'subagent' and pass it through

This improves user visibility into which subagent type is running without requiring additional event fields or architectural changes. Falls back gracefully to 'subagent' if agent field is missing or JSON parsing fails.

No functional changes to non-subagent tools or existing behavior. All existing tests pass.

Visual Impact

Before:
▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ subagent
After (with agent type):
▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ subagent (explore)

Summary by CodeRabbit

  • Enhancements
    • Spinner messages now include the subagent subtype when it’s provided, parsed, and safe to display.
    • If the subtype is missing or can’t be interpreted safely, spinner labels automatically fall back to the general tool name.

Add explicit subagent agent name to the real-time spinner display in the
StreamComponent. When a subagent tool starts executing, the spinner now shows
the agent type (derived from the 'agent' parameter in ToolArgs JSON) in the
format 'subagent (explore)', 'subagent (general)', etc.

Changes:
- Add encoding/json import for parsing ToolArgs
- Add extractAgentNameFromArgs() helper to safely parse the agent field
  from JSON-encoded ToolArgs, returning empty string on parse failure
- Update formatToolExecutionMessage() to accept optional agentName parameter
  and format subagents as 'subagent (agentName)' when agent is specified
- Modify ToolExecutionEvent handler in StreamComponent.Update() to extract
  agent name from ToolArgs when tool is 'subagent' and pass it through

This improves user visibility into which subagent type is running without
requiring additional event fields or architectural changes. Falls back
gracefully to 'subagent' if agent field is missing or JSON parsing fails.

No functional changes to non-subagent tools or existing behavior.
All existing tests pass.
@mark-iii-labs-huly

Copy link
Copy Markdown

Connected to Huly®: KIT-95

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The stream UI extracts and sanitizes an optional agent value from subagent tool arguments, then includes it in spinner labels when valid. Invalid or unavailable values preserve the existing tool name display.

Changes

Subagent spinner labels

Layer / File(s) Summary
Extract and display subagent names
internal/ui/stream.go
The tool execution start path parses subagent arguments, validates the optional agent name, and formats labels as subagent (<agentName>) when valid; otherwise it displays the tool name unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: showing the subagent name in the UI progress bar.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/ui/stream.go (1)

593-612: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add focused tests for the new fallback behavior.

Cover valid agent names, missing/empty fields, malformed JSON, non-string values, and non-subagent formatting so future changes preserve the existing fallback to the tool name.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ui/stream.go` around lines 593 - 612, The new helper behavior lacks
focused test coverage. Add tests for extractAgentNameFromArgs covering valid,
missing, empty, malformed, and non-string agent fields, plus
formatToolExecutionMessage cases for subagents with and without valid agent
names and non-subagent tool names; verify fallback returns the tool name or
empty string as appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/ui/stream.go`:
- Around line 600-601: Sanitize the agent value in the agent-selection logic
before returning it for spinner rendering: allow only supported agent names, or
strip ANSI/control characters, reject embedded newlines, and enforce a
reasonable length limit. Preserve the existing fallback behavior when the value
is invalid or empty.

---

Nitpick comments:
In `@internal/ui/stream.go`:
- Around line 593-612: The new helper behavior lacks focused test coverage. Add
tests for extractAgentNameFromArgs covering valid, missing, empty, malformed,
and non-string agent fields, plus formatToolExecutionMessage cases for subagents
with and without valid agent names and non-subagent tool names; verify fallback
returns the tool name or empty string as appropriate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 47382b82-3af2-44f7-9aef-15abe0e6a6d6

📥 Commits

Reviewing files that changed from the base of the PR and between fa0dc48 and c378ee6.

📒 Files selected for processing (1)
  • internal/ui/stream.go

Comment thread internal/ui/stream.go Outdated
Add sanitizeAgentName() validation function to prevent injection attacks and
rendering issues when displaying the subagent type in the StreamComponent spinner.

Sanitization enforces:
- Maximum length of 50 characters (prevents layout overflow)
- No embedded newlines or carriage returns (prevents layout corruption)
- No ANSI escape sequences (prevents terminal escape injection)
- No control characters (0x00-0x1F, 0x7F) (prevents terminal control injection)
- Only alphanumeric, hyphens, underscores, and dots (safe character set)

The function gracefully returns empty string for invalid inputs, maintaining
existing fallback behavior where the spinner shows just 'subagent' when the
agent name is missing or invalid.

Updated extractAgentNameFromArgs() to call sanitizeAgentName() before returning,
ensuring all agent names are validated regardless of source.

Valid examples that pass sanitization:
- 'explore', 'general' (standard agents)
- 'custom-agent', 'agent_v2', 'agent.prod' (extended naming)

Invalid examples that are rejected:
- 'agent\ngeneral' (newlines)
- 'explore\x1b[31m' (ANSI escapes)
- 'agent@attack' (special characters)
- 'a' * 51 (exceeds length limit)

This maintains the full fallback behavior: invalid agent names result in
displaying just 'subagent' with no agent type suffix.

No functional changes to existing behavior. All tests pass.
@kskarthik kskarthik changed the title feat(ui): display subagent type in progress bar feat(ui): display subagent name in progress bar Jul 21, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/ui/stream.go`:
- Around line 594-638: Move the `^[a-zA-Z0-9_.-]+$` expression used by
`sanitizeAgentName` into a package-level compiled regexp variable, then reuse it
inside the function. Remove the now-redundant newline, ANSI escape, and
control-character checks while preserving the existing empty-string, length, and
invalid-pattern behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 519c2474-8e68-4262-9014-cef89a90499f

📥 Commits

Reviewing files that changed from the base of the PR and between c378ee6 and e201c19.

📒 Files selected for processing (1)
  • internal/ui/stream.go

Comment thread internal/ui/stream.go Outdated
Move the agent name validation pattern to package-level compiled variable
(agentNamePattern) to eliminate per-call regexp recompilation overhead.

Remove redundant character checks (newline, ANSI escape, control character
detection) since the regex pattern [a-zA-Z0-9_.-] inherently rejects all
of them and is the single source of truth for character validation.

This optimization:
- Compiles the regex once at package init, not on every sanitizeAgentName() call
- Simplifies the function with fewer branches (no loop for control char checks)
- Reduces code lines from 45 to 18 (40% reduction)
- Maintains identical behavior: same valid/invalid inputs, same security
- Preserves efficient early returns for empty string and length limit

The regex pattern [a-zA-Z0-9_.-] inherently rejects:
  - Control characters (0x00-0x1F, 0x7F)
  - Newlines and carriage returns (0x0A, 0x0D)
  - ANSI escape sequences (0x1B)
  - Any other special characters

Verified with 16 test cases: 5 valid + 11 invalid (including newlines,
ANSI escapes, control chars, special chars, and length overflow).

No functional changes. All tests pass.
@ezynda3

ezynda3 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ezynda3
ezynda3 merged commit 6e0a3af into mark3labs:master Jul 21, 2026
3 checks passed
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.

2 participants