Skip to content

Conversation

@kiloconnect
Copy link
Contributor

@kiloconnect kiloconnect bot commented Dec 31, 2025

Problem

This PR fixes CLI formatting issues identified in the analysis where unknown message types and JSON content were not being properly handled in both CI mode and interactive terminal mode. Specifically code search (see screenshots)

Before:

image

After:

image

- Add robust JSON parsing in CI mode with proper error handling
- Distinguish between JSON objects/arrays (metadata) and plain text (content)
- Enhance unknown message type handling in interactive mode
- Add comprehensive test coverage (80+ test cases)
- Handle edge cases: malformed JSON, empty values, nested structures
- Ensure backward compatibility with existing message types
@changeset-bot
Copy link

changeset-bot bot commented Dec 31, 2025

🦋 Changeset detected

Latest commit: 091b736

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kilocode/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

// Try to parse JSON content for better display
let displayContent = message.text || `Unknown say type: ${message.say}`

// If text looks like JSON, try to format it nicely
Copy link
Contributor Author

Choose a reason for hiding this comment

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

⚠️ WARNING: Operator precedence issue - missing parentheses

This condition is inconsistent with AskMessageRouter.tsx line 34 which correctly uses parentheses. Due to operator precedence (&& binds tighter than ||), this evaluates as (message.text && message.text.trim().startsWith("{")) || message.text?.trim().startsWith("[") which happens to work but is harder to read and maintain.

Suggested change
// If text looks like JSON, try to format it nicely
if (message.text && (message.text.trim().startsWith("{") || message.text.trim().startsWith("["))) {

@kiloconnect
Copy link
Contributor Author

kiloconnect bot commented Dec 31, 2025

✅ Previous Issues Addressed

The operator precedence issue from my previous review has been resolved. The code has been refactored to use the formatUnknownMessageContent utility function, which properly handles JSON detection logic without the operator precedence concerns.

16 files reviewed | Confidence: 95% | Recommendation: Merge

Review Details

Files Reviewed:

  • .changeset/cli-formatting-fix.md - New changeset (appropriate)
  • cli/src/ui/messages/extension/utils.ts - New formatUnknownMessageContent function
  • cli/src/ui/messages/extension/SayMessageRouter.tsx - Uses new utility function
  • cli/src/ui/messages/extension/AskMessageRouter.tsx - Uses new utility function
  • cli/src/ui/messages/extension/ExtensionMessageRow.tsx - Improved unknown type handling
  • cli/src/ui/messages/extension/say/SayCodebaseSearchResultMessage.tsx - Updated payload structure
  • cli/src/ui/utils/jsonOutput.ts - Improved JSON parsing logic
  • cli/src/ui/messages/extension/__tests__/UnknownMessageType.test.tsx - New test file
  • cli/src/ui/utils/__tests__/jsonOutput.test.ts - New test file
  • cli/src/ui/messages/extension/__tests__/utils.test.ts - Extended tests

Changes Summary:

  1. ✅ New formatUnknownMessageContent utility properly handles JSON detection with correct operator precedence
  2. ✅ Codebase search results now match extension payload format (filePath, startLine, endLine, codeChunk)
  3. ✅ JSON output formatting improved with proper primitive vs object/array handling
  4. ✅ Comprehensive test coverage added for new functionality
  5. ✅ Formatting improvements (multi-line conditions) improve readability

Checked: Security, bugs, performance, error handling - no issues found

@marius-kilocode marius-kilocode self-assigned this Jan 5, 2026
- Added formatUnknownMessageContent() to utils.ts for formatting unknown message content
- Updated AskMessageRouter.tsx and SayMessageRouter.tsx to use the shared utility
- Added 20 comprehensive unit tests for the new utility function
- Reduces code duplication and improves testability
# Conflicts:
#	cli/src/ui/components/__tests__/ThinkingAnimation.test.tsx
@marius-kilocode marius-kilocode enabled auto-merge (squash) January 5, 2026 17:44
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.

3 participants